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()); } }); } }); }
private void InitEngine(ServerEventHandler callback) { m_initializationStarted = true; DownloadMapData((Error error, MapData mapData) => { m_initializationStarted = false; if (HasError(error)) { if (callback != null) { callback(error); } } else { MapRoot mapRoot = m_serializer.Deserialize <MapRoot>(mapData.Bytes); 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(); if (m_engine != null) { m_engine.OnSubmitted -= OnEngineCommandSubmitted; } m_engine = engine; m_engine.OnSubmitted += OnEngineCommandSubmitted; if (callback != null) { callback(error); } if (m_room.Mode != GameMode.Replay) { m_pingTimer.PingAll(); if (Ping != null) { m_pingArgs.Arg = new RTTInfo(); m_pingArgs.Except = Guid.Empty; Ping(new Error(StatusCode.OK), m_pingArgs); } } else { OnPingPongCompleted(new Error(StatusCode.OK), m_room.CreatorClientId); } } }); }