Commit 34fa9427 authored by Maxime POULAIN's avatar Maxime POULAIN
Browse files

add linear interpolation to remote

parent 46d24ae2
using System.Collections.Generic;
using Urho;
using Urho.Actions;
using Urho.Urho2D;
using ZZZZZZ.Utils;
......@@ -9,6 +10,7 @@ namespace ZZZZZZ.Entities.Character
{
public int CharacterID { get; set; }
public bool Online { get; set; }
public float ServerDelta { get; set; }
public (bool X, bool Y) Flip
{
......@@ -21,6 +23,7 @@ namespace ZZZZZZ.Entities.Character
public RemoteCharacter(int id = -1)
{
ServerDelta = 16 / 1000;
CharacterID = id;
Online = false;
Node.Scale *= 10;
......@@ -40,7 +43,7 @@ namespace ZZZZZZ.Entities.Character
public void Move(Vector2 position)
{
Node.SetPosition2D(position);
Node.RunActionsAsync(new MoveTo(ServerDelta, new Vector3(position)));
}
public override void Update(UpdateEventArgs obj)
{
......
using System.Diagnostics;
using System;
using System.Diagnostics;
using System.Net.Http;
using System.Threading.Tasks;
using Urho.Network;
......@@ -49,7 +50,8 @@ namespace ZZZZZZ
{
Task.Run(() =>
{
API = new WebAPI("https://localhost:5000/");
//API = new WebAPI("https://localhost:5000/");
API = new WebAPI();
if (string.IsNullOrEmpty(gamecode))
{
API.CreateGame();
......@@ -84,19 +86,29 @@ namespace ZZZZZZ
{
Task.Run(() =>
{
while (true)
while (API.Running)
{
DateTime before = DateTime.Now;
API.UpdateLocal(LocalPlayerManager.Character as LocalCharacter);
Task.Delay(16).Wait();
DateTime after = DateTime.Now;
TimeSpan delta = after - before;
var waiting = Math.Max(16 - delta.TotalMilliseconds, 0);
Task.Delay((int)waiting).Wait();
}
});
Task.Run(() =>
{
while (true)
while (API.Running)
{
DateTime before = DateTime.Now;
API.UpdateRemote(RemotePlayerManager.Character as RemoteCharacter);
Task.Delay(16).Wait();
DateTime after = DateTime.Now;
TimeSpan delta = after - before;
var waiting = Math.Max(16 - delta.TotalMilliseconds, 0);
(RemotePlayerManager.Character as RemoteCharacter).ServerDelta = (float)delta.TotalSeconds;
Task.Delay((int)waiting).Wait();
}
});
});
......
......@@ -9,6 +9,7 @@ namespace ZZZZZZ.WebAPIs
{
string Code { get; set; }
bool Running { get; set; }
HttpClient Client { get; }
bool CreateGame();
......
......@@ -15,11 +15,13 @@ namespace ZZZZZZ.WebAPIs
public class WebAPI : IWebAPI
{
public string Code { get; set; }
public bool Running { get; set; }
public string Hook { get; }
public HttpClient Client { get; }
public WebAPI(string hook = "http://91.170.211.147:50000/")
{
Running = true;
Hook = hook;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;
var handler = new HttpClientHandler();
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment