public void RecieveEnvelope(FrameCommands envelope) { _logic.ProcessCommands(envelope.Commands); //_recievedEnvelopes.Add(new RecievedCmdEnvelope() //{ // Envelope = envelope, // RecievedTimestamp = _sim.GetTimestamp() //}); }
public void Update() { var isAuthority = Role.IsInRole(EntityRole.AUTHORITY); var delta = _sim.GetDeltaTime(); if (_lastSentSnapshot == null && Role.IsInRole(EntityRole.AUTHORITY)) { _lastSentSnapshot = _logic.TakeSnapshot(); } if (!isAuthority) { var currentFrameCommands = new FrameCommands() { Commands = new List <object>(), SentDelta = delta, SentTimestamp = _sim.GetTimestamp() }; if (Role.IsInRole(EntityRole.CONTROLLER)) { //Console.WriteLine($"Delta is: {delta}"); var commands = _logic.GenerateCommands(); currentFrameCommands.Commands.Add(commands); if (!Role.IsInRole(EntityRole.AUTHORITY)) { _logic.ProcessCommands(currentFrameCommands.Commands); //Console.WriteLine($"Processing Commands:"); //foreach (var command in currentFrameCommands.Commands) //{ // Console.WriteLine($"{command}"); //} } _authorityEntity.SendFrameRecord(currentFrameCommands); } _recordedFrameCommands.Add(currentFrameCommands); } //if (Role.IsInRole(EntityRole.AUTHORITY)) //{ // _logic.ProcessCommands(_recievedEnvelopes.SelectMany(e => e.Envelope.Commands)); // _recievedEnvelopes.Clear(); //} _logic.Simulate(delta); if (Role.IsInRole(EntityRole.AUTHORITY)) { var timestamp = _sim.GetTimestamp(); var newSnapshot = _logic.TakeSnapshot(); _recordedFrameSnapshots.Add(new FrameSnapshot() { Snapshot = newSnapshot, RecordedTimestamp = timestamp }); _timeSinceLastUpdate += delta; if (_timeSinceLastUpdate > UpdatePeriod) { _timeSinceLastUpdate = 0; var env = new DeltaEnvelope() { Deltas = _logic.CalculateDeltas(_lastSentSnapshot, newSnapshot), SentTimestamp = timestamp }; foreach (var client in _clientEntities) { client.SendDeltaEnvelope(env); } _controllerEntity?.SendDeltaEnvelope(env); _lastSentSnapshot = newSnapshot; } _recordedFrameSnapshots = _recordedFrameSnapshots.Where(r => r.RecordedTimestamp > timestamp - 1000).ToList(); } }
public void SendFrameRecord(FrameCommands envelope) { RecieveEnvelope(envelope); }
public void SendFrameRecord(FrameCommands envelope) { _sim.SendMessage(new EntityMessage <FrameCommands>(Id, envelope)); }