void CSimulation2Impl::Interpolate(float frameLength, float frameOffset) { m_LastFrameOffset = frameOffset; CMessageInterpolate msg(frameLength, frameOffset); m_ComponentManager.BroadcastMessage(msg); // Clean up any entities destroyed during interpolate (e.g. local corpses) m_ComponentManager.FlushDestroyedComponents(); }
bool CSimulation2Impl::Update(int turnLength, const std::vector<SimulationCommand>& commands) { fixed turnLengthFixed = fixed::FromInt(turnLength) / 1000; // TODO: the update process is pretty ugly, with lots of messages and dependencies // between different components. Ought to work out a nicer way to do this. CMessageTurnStart msgTurnStart; m_ComponentManager.BroadcastMessage(msgTurnStart); CmpPtr<ICmpPathfinder> cmpPathfinder(m_SimContext, SYSTEM_ENTITY); if (!cmpPathfinder.null()) cmpPathfinder->FinishAsyncRequests(); // Push AI commands onto the queue before we use them CmpPtr<ICmpAIManager> cmpAIManager(m_SimContext, SYSTEM_ENTITY); if (!cmpAIManager.null()) cmpAIManager->PushCommands(); CmpPtr<ICmpCommandQueue> cmpCommandQueue(m_SimContext, SYSTEM_ENTITY); if (!cmpCommandQueue.null()) cmpCommandQueue->FlushTurn(commands); // Process newly generated move commands so the UI feels snappy if (!cmpPathfinder.null()) cmpPathfinder->ProcessSameTurnMoves(); // Send all the update phases { CMessageUpdate msgUpdate(turnLengthFixed); m_ComponentManager.BroadcastMessage(msgUpdate); } { CMessageUpdate_MotionFormation msgUpdate(turnLengthFixed); m_ComponentManager.BroadcastMessage(msgUpdate); } // Process move commands for formations (group proxy) if (!cmpPathfinder.null()) cmpPathfinder->ProcessSameTurnMoves(); { CMessageUpdate_MotionUnit msgUpdate(turnLengthFixed); m_ComponentManager.BroadcastMessage(msgUpdate); } { CMessageUpdate_Final msgUpdate(turnLengthFixed); m_ComponentManager.BroadcastMessage(msgUpdate); } // Process moves resulting from group proxy movement (unit needs to catch up or realign) and any others if (!cmpPathfinder.null()) cmpPathfinder->ProcessSameTurnMoves(); // Clean up any entities destroyed during the simulation update m_ComponentManager.FlushDestroyedComponents(); // if (m_TurnNumber == 0) // m_ComponentManager.GetScriptInterface().DumpHeap(); // Run the GC occasionally // (TODO: we ought to schedule this for a frame where we're not // running the sim update, to spread the load) if (m_TurnNumber % 10 == 0) m_ComponentManager.GetScriptInterface().MaybeGC(); if (m_EnableOOSLog) DumpState(); // Start computing AI for the next turn if (!cmpAIManager.null()) cmpAIManager->StartComputation(); ++m_TurnNumber; return true; // TODO: don't bother with bool return }
void CComponentManager::Script_FlushDestroyedEntities(ScriptInterface::CxPrivate *pCxPrivate) { CComponentManager* componentManager = static_cast<CComponentManager*> (pCxPrivate->pCBData); componentManager->FlushDestroyedComponents(); }