예제 #1
0
        public override void Update(GameTime gameTime)
        {
            // send data to clients based on the difference between this snapshot and the previous one
            ServerSnapshot snapshot = ServerSnapshot.Snapshot(world);

            foreach (var playerKV in snapshot.playersData)
            {
                PlayerData d;
                if (previousSnapshot.playersData.TryGetValue(playerKV.Key, out d))
                {
                    // check if the player data changed. if yes, notify all the clients
                    if (d != playerKV.Value)
                    {
                        SendMessage(MessageContentType.PlayerUpdate, playerKV.Key, playerKV.Value);
                    }
                }
            }
            for (int i = 0; i < snapshot.entitiesData.Count; i++)
            {
                if (previousSnapshot.entitiesData[i] != snapshot.entitiesData[i])
                {
                    SendMessage(MessageContentType.EntityData, -1, snapshot.entitiesData[i]);
                }
            }
            // read if theres new data in each of the clients sockets
            foreach (Connection client in clients)
            {
                if (client.Connected)
                {
                    client.Update();
                }
            }
        }
예제 #2
0
 public override void SnapShot()
 {
     previousSnapshot = ServerSnapshot.Snapshot(world);
 }