Ejemplo n.º 1
0
 private void HandleGobCreationMessage(GobCreationMessage message, int framesAgo)
 {
     if (message.ArenaID != DataEngine.Arena.ID) return;
     var updatedGobs = new Dictionary<int, Arena.GobUpdateData>();
     message.ReadGobs(framesAgo,
         (typeName, layerIndex) =>
         {
             if (layerIndex < 0 || layerIndex >= DataEngine.Arena.Layers.Count) return null;
             var gob = (Gob)Clonable.Instantiate(this, typeName);
             gob.Game = this;
             gob.Layer = DataEngine.Arena.Layers[layerIndex];
             gob.BirthTime = DataEngine.ArenaTotalTime - TargetElapsedTime.Multiply(framesAgo);
             return gob;
         },
         gob =>
         {
             DataEngine.Arena.Gobs.Add(gob);
             updatedGobs.Add(gob.ID, new Arena.GobUpdateData(gob, framesAgo));
         });
     DataEngine.Arena.FinalizeGobUpdatesOnClient(updatedGobs, framesAgo);
 }
Ejemplo n.º 2
0
 private void SendGobCreationMessageOnServer()
 {
     if (ArenaLoadTask.TaskRunning) return; // wait for arena load completion
     if (DataEngine.Arena == null) return; // happens if gobs are created on the frame the arena ends
     foreach (var conn in NetworkEngine.GameClientConnections)
     {
         var gobsToSend = DataEngine.Arena.GobsInRelevantLayers.Where(gob => gob.IsRelevant && !gob.ClientStatus[1 << conn.ID]);
         if (!gobsToSend.Any()) continue;
         var message = new GobCreationMessage { ArenaID = DataEngine.Arena.ID };
         foreach (var gob in gobsToSend.Take(10)) // Avoid sending lots of gobs in one frame.
         {
             message.AddGob(gob);
             gob.ClientStatus[1 << conn.ID] = true;
         }
         conn.Send(message);
     }
 }
Ejemplo n.º 3
0
 public void GobCreationMessageReceived(GobCreationMessage message, int framesAgo)
 {
     lock (_gobCreationMessages) _gobCreationMessages.Add(Tuple.Create(message, framesAgo));
 }