예제 #1
0
 /// <summary>
 /// Create a new instance of game server.
 /// </summary>
 /// <param name="durationBetweenTwoTicks">The duration between two game tick (in milliseconds).</param>
 /// <param name="timeElapsedPerTick">The game time elapsed per tick (in seconds).</param>
 public GameInstance(byte id, uint durationBetweenTwoTicks, ulong timeElapsedPerTick = 1UL)
 {
     Debug.Assert(timeElapsedPerTick >= 1);
     this.Id = id;
     this.DurationBetweenTwoTicks = (int)durationBetweenTwoTicks;
     this.Game       = new Game.Game(timeElapsedPerTick);
     this.Game.Id    = id;
     this.gameThread = new Thread(this.GameLoop);
 }
예제 #2
0
        public static void WriteGame(this BinaryWriter stream, Simulation.Game.Game game)
        {
            var isNull = game == null;

            stream.Write(isNull);
            if (isNull)
            {
                return;
            }

            game.Serialize(stream);
        }
예제 #3
0
        public static void ParseGame(this BinaryReader stream, out Simulation.Game.Game game)
        {
            var isNull = stream.ReadBoolean();

            if (isNull)
            {
                game = null;
                return;
            }

            game = new Simulation.Game.Game();
            game.Deserialize(stream);
        }
예제 #4
0
        protected override bool TryGetGame(byte gameId, out Simulation.Game.Game game)
        {
            var gamesCount = this.hostedGames.Count;

            for (int index = 0; index < gamesCount; index++)
            {
                if (this.hostedGames[index].Id == gameId)
                {
                    game = this.hostedGames[index].Game;
                    return(true);
                }
            }

            game = null;
            return(false);
        }
예제 #5
0
 public static void WriteJoinGameOrder(this BinaryWriter stream, byte gameInstanceId, byte clientId, ulong timeElapsedPerTick, ulong durationBetweenTwoTicks, byte playerId, Simulation.Game.Game game)
 {
     stream.Write(gameInstanceId);
     stream.Write(clientId);
     stream.Write(timeElapsedPerTick);
     stream.Write(durationBetweenTwoTicks);
     stream.Write(playerId);
     stream.WriteGame(game);
 }
예제 #6
0
 protected override bool TryGetGame(byte gameId, out Simulation.Game.Game game)
 {
     game = this.Game;
     return(game != null && game.Id == gameId);
 }
예제 #7
0
 public static void ReadJoinGameOrder(this BinaryReader stream, out byte gameInstanceId, out byte clientId, out ulong timeElapsedPerTick, out ulong durationBetweenTwoTicks, out byte playerId, out Simulation.Game.Game game)
 {
     gameInstanceId          = stream.ReadByte();
     clientId                = stream.ReadByte();
     timeElapsedPerTick      = stream.ReadUInt64();
     durationBetweenTwoTicks = stream.ReadUInt64();
     playerId                = stream.ReadByte();
     stream.ParseGame(out game);
 }
예제 #8
0
 protected abstract bool TryGetGame(byte gameId, out Simulation.Game.Game game);