public void OnUpdateRemotableActor(ref UpdateRemotableActor p) { p.Pos = Transform.Pos; p.Speed = Speed.Xy; p.AnimState = (currentTransitionState != AnimState.Idle ? currentTransitionState : currentAnimationState); p.AnimTime = (renderer.Active ? renderer.AnimTime : -1); p.IsFacingLeft = IsFacingLeft; }
protected override void OnFixedUpdate(float timeMult) { base.OnFixedUpdate(timeMult); if (isStillLoading > 0) { isStillLoading--; if (isStillLoading <= 0) { net.Send(new LevelReady { Index = localPlayerIndex }, 2, NetDeliveryMethod.ReliableUnordered, PacketChannels.Main); } } #if DEBUG Hud.ShowDebugText("- Local Player Index: " + localPlayerIndex); Hud.ShowDebugText("- RTT: " + (int)(net.AverageRoundtripTime * 1000) + " ms / Up: " + net.Up + " / Down: " + net.Down); Hud.ShowDebugText("- Last Server Update: " + lastServerUpdateTime); Hud.ShowDebugText("- Remote Objects: " + localRemotableActors.Count + " / " + remoteActors.Count); #endif if (players.Count > 0) { lastUpdate += timeMult; if (lastUpdate < 1.4f) { return; } lastUpdate = 0f; long updateTime = (long)(NetTime.Now * 1000); UpdateSelf updateSelfPacket = players[0].CreateUpdatePacket(); updateSelfPacket.Index = localPlayerIndex; updateSelfPacket.UpdateTime = updateTime; net.Send(updateSelfPacket, 29, NetDeliveryMethod.Unreliable, PacketChannels.Main); foreach (KeyValuePair <int, IRemotableActor> pair in localRemotableActors) { UpdateRemotableActor p = new UpdateRemotableActor(); pair.Value.OnUpdateRemotableActor(ref p); p.Index = pair.Key; p.UpdateTime = updateTime; net.Send(p, 32, NetDeliveryMethod.Unreliable, PacketChannels.Main); } } }
private void OnUpdateRemotableActor(ref UpdateRemotableActor p) { int index = p.Index; Player player; lock (sync) { if (!players.TryGetValue(p.SenderConnection, out player)) { return; } if (player.Index != (index & 0xff)) { return; } RemotableActor remotableActor; if (!remotableActors.TryGetValue(index, out remotableActor)) { return; } if (remotableActor.LastUpdateTime > p.UpdateTime) { return; } remotableActor.LastUpdateTime = p.UpdateTime; float rtt = p.SenderConnection.AverageRoundtripTime; Vector3 pos = p.Pos; pos.X += p.Speed.X * rtt; pos.Y += p.Speed.Y * rtt; remotableActor.Pos = pos; remotableActor.Speed = p.Speed; remotableActor.AnimState = p.AnimState; remotableActor.AnimTime = p.AnimTime; remotableActor.IsFacingLeft = p.IsFacingLeft; //remotableObject.AABB = new AABB(remotableObject.Pos.Xy, 30, 30); //collisions.AddProxy(remotableObject); } }