int CSimulation2Impl::ProgressiveLoad() { // yield after this time is reached. balances increased progress bar // smoothness vs. slowing down loading. const double end_time = timer_Time() + 200e-3; int ret; do { bool progressed = false; int total = 0; int progress = 0; CMessageProgressiveLoad msg(&progressed, &total, &progress); m_ComponentManager.BroadcastMessage(msg); if (!progressed || total == 0) return 0; // we have nothing left to load ret = Clamp(100*progress / total, 1, 100); } while (timer_Time() < end_time); return ret; }
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(); }
void CComponentManager::Script_BroadcastMessage(void* cbdata, int mtid, CScriptVal data) { CComponentManager* componentManager = static_cast<CComponentManager*> (cbdata); CMessage* msg = componentManager->ConstructMessage(mtid, data); if (!msg) return; // error componentManager->BroadcastMessage(*msg); delete msg; }
void CComponentManager::Script_BroadcastMessage(ScriptInterface::CxPrivate* pCxPrivate, int mtid, CScriptVal data) { CComponentManager* componentManager = static_cast<CComponentManager*> (pCxPrivate->pCBData); CMessage* msg = componentManager->ConstructMessage(mtid, data); if (!msg) return; // error componentManager->BroadcastMessage(*msg); delete msg; }
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 }