/// <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); }
public static void WriteGame(this BinaryWriter stream, Simulation.Game.Game game) { var isNull = game == null; stream.Write(isNull); if (isNull) { return; } game.Serialize(stream); }
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); }
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); }
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); }
protected override bool TryGetGame(byte gameId, out Simulation.Game.Game game) { game = this.Game; return(game != null && game.Id == gameId); }
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); }
protected abstract bool TryGetGame(byte gameId, out Simulation.Game.Game game);