private void OnDestroy() { m_serializer = null; if (m_gState != null) { m_gState.SetValue("LocalGameServer.m_replay", null); } if (m_players != null) { m_players.Remove(m_neutralPlayer.Id); } if (m_room != null) { m_room.Players.Remove(m_neutralPlayer.Id); } if (m_bots != null) { for (int i = 0; i < m_bots.Length; ++i) { IBotController bot = m_bots[i]; if (bot != null) { MatchFactory.DestroyBotController(bot); } } } if (m_engine != null) { MatchFactory.DestroyMatchEngine(m_engine); } }
public void Destroy() { enabled = false; int index = m_room.Players.IndexOf(m_neutralPlayer.Id); if (index >= 0) { m_room.Players.RemoveAt(index); m_clientIds.RemoveAt(index); } if (m_engine != null) { m_engine.OnSubmitted -= OnEngineCommandSubmitted; MatchFactory.DestroyMatchEngine(m_engine); m_engine = null; } }
private void InitEngine(Guid clientId, ServerEventHandler callback) { if (m_engine != null) { MatchFactory.DestroyMatchEngine(m_engine); } m_engine = null; DownloadMapData(m_room.MapInfo.Id, (error, mapData) => { if (HasError(error)) { if (callback != null) { callback(error); } } else { m_job.Submit(() => { ProtobufSerializer serializer = null; MapRoot mapRoot = null; try { var pool = Dependencies.Serializer; if (pool != null) { serializer = pool.Acquire(); mapRoot = serializer.Deserialize <MapRoot>(mapData.Bytes); } } finally { if (serializer != null) { var pool = Dependencies.Serializer; if (pool != null) { pool.Release(serializer); } } } return(mapRoot); }, result => { MapRoot mapRoot = (MapRoot)result; IMatchEngine engine = MatchFactory.CreateMatchEngine(mapRoot, m_room.Players.Count); Dictionary <int, VoxelAbilities>[] allAbilities = new Dictionary <int, VoxelAbilities> [m_room.Players.Count]; for (int i = 0; i < m_room.Players.Count; ++i) { allAbilities[i] = m_abilities[m_room.Players[i]].ToDictionary(a => a.Type); } if (m_replay == null) { m_replay = MatchFactory.CreateReplayRecorder(); } //Zero is neutral for (int i = 0; i < m_room.Players.Count; ++i) { Guid playerGuid = m_room.Players[i]; engine.RegisterPlayer(m_room.Players[i], i, allAbilities); } engine.CompletePlayerRegistration(); m_prevTickTime = Time.realtimeSinceStartup; m_engine = engine; if (callback != null) { callback(error); } m_pingTimer.Ping(clientId); if (Ping != null) { Ping(new Error(StatusCode.OK), new RTTInfo()); } }); } }); }