Changeset View
Changeset View
Standalone View
Standalone View
source/simulation2/Simulation2.cpp
/* Copyright (C) 2021 Wildfire Games. | /* Copyright (C) 2022 Wildfire Games. | ||||
* This file is part of 0 A.D. | * This file is part of 0 A.D. | ||||
* | * | ||||
* 0 A.D. is free software: you can redistribute it and/or modify | * 0 A.D. is free software: you can redistribute it and/or modify | ||||
* it under the terms of the GNU General Public License as published by | * it under the terms of the GNU General Public License as published by | ||||
* the Free Software Foundation, either version 2 of the License, or | * the Free Software Foundation, either version 2 of the License, or | ||||
* (at your option) any later version. | * (at your option) any later version. | ||||
* | * | ||||
* 0 A.D. is distributed in the hope that it will be useful, | * 0 A.D. is distributed in the hope that it will be useful, | ||||
▲ Show 20 Lines • Show All 495 Lines • ▼ Show 20 Lines | void CSimulation2Impl::Update(int turnLength, const std::vector<SimulationCommand>& commands) | ||||
if (m_TurnNumber % 500 == 0) | if (m_TurnNumber % 500 == 0) | ||||
scriptInterface.GetContext()->ShrinkingGC(); | scriptInterface.GetContext()->ShrinkingGC(); | ||||
else | else | ||||
scriptInterface.GetContext()->MaybeIncrementalGC(0.0f); | scriptInterface.GetContext()->MaybeIncrementalGC(0.0f); | ||||
if (m_EnableOOSLog) | if (m_EnableOOSLog) | ||||
DumpState(); | DumpState(); | ||||
// Start computing AI for the next turn | |||||
CmpPtr<ICmpAIManager> cmpAIManager(m_SimContext, SYSTEM_ENTITY); | |||||
if (cmpAIManager) | |||||
cmpAIManager->StartComputation(); | |||||
++m_TurnNumber; | ++m_TurnNumber; | ||||
} | } | ||||
void CSimulation2Impl::UpdateComponents(CSimContext& simContext, fixed turnLengthFixed, const std::vector<SimulationCommand>& commands) | void CSimulation2Impl::UpdateComponents(CSimContext& simContext, fixed turnLengthFixed, const std::vector<SimulationCommand>& commands) | ||||
{ | { | ||||
// TODO: the update process is pretty ugly, with lots of messages and dependencies | // 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. | // between different components. Ought to work out a nicer way to do this. | ||||
CComponentManager& componentManager = simContext.GetComponentManager(); | CComponentManager& componentManager = simContext.GetComponentManager(); | ||||
CmpPtr<ICmpPathfinder> cmpPathfinder(simContext, SYSTEM_ENTITY); | CmpPtr<ICmpPathfinder> cmpPathfinder(simContext, SYSTEM_ENTITY); | ||||
if (cmpPathfinder) | if (cmpPathfinder) | ||||
cmpPathfinder->SendRequestedPaths(); | cmpPathfinder->SendRequestedPaths(); | ||||
{ | { | ||||
PROFILE2("Sim - Update Start"); | PROFILE2("Sim - Update Start"); | ||||
CMessageTurnStart msgTurnStart; | CMessageTurnStart msgTurnStart; | ||||
componentManager.BroadcastMessage(msgTurnStart); | componentManager.BroadcastMessage(msgTurnStart); | ||||
} | } | ||||
// Push AI commands onto the queue before we use them | |||||
CmpPtr<ICmpAIManager> cmpAIManager(simContext, SYSTEM_ENTITY); | |||||
if (cmpAIManager) | |||||
cmpAIManager->PushCommands(); | |||||
CmpPtr<ICmpCommandQueue> cmpCommandQueue(simContext, SYSTEM_ENTITY); | CmpPtr<ICmpCommandQueue> cmpCommandQueue(simContext, SYSTEM_ENTITY); | ||||
if (cmpCommandQueue) | if (cmpCommandQueue) | ||||
cmpCommandQueue->FlushTurn(commands); | cmpCommandQueue->FlushTurn(commands); | ||||
// Process newly generated move commands so the UI feels snappy | // Process newly generated move commands so the UI feels snappy | ||||
if (cmpPathfinder) | if (cmpPathfinder) | ||||
{ | { | ||||
Show All 28 Lines | if (cmpPathfinder) | ||||
PROFILE2("Sim - Update Final"); | PROFILE2("Sim - Update Final"); | ||||
CMessageUpdate_Final msgUpdate(turnLengthFixed); | CMessageUpdate_Final msgUpdate(turnLengthFixed); | ||||
componentManager.BroadcastMessage(msgUpdate); | componentManager.BroadcastMessage(msgUpdate); | ||||
} | } | ||||
// Clean up any entities destroyed during the simulation update | // Clean up any entities destroyed during the simulation update | ||||
componentManager.FlushDestroyedComponents(); | componentManager.FlushDestroyedComponents(); | ||||
// Compute AI immediately at turn's end. | |||||
CmpPtr<ICmpAIManager> cmpAIManager(simContext, SYSTEM_ENTITY); | |||||
if (cmpAIManager) | |||||
{ | |||||
cmpAIManager->StartComputation(); | |||||
cmpAIManager->PushCommands(); | |||||
} | |||||
// Process all remaining moves | // Process all remaining moves | ||||
if (cmpPathfinder) | if (cmpPathfinder) | ||||
{ | { | ||||
cmpPathfinder->UpdateGrid(); | cmpPathfinder->UpdateGrid(); | ||||
cmpPathfinder->StartProcessingMoves(false); | cmpPathfinder->StartProcessingMoves(false); | ||||
} | } | ||||
} | } | ||||
▲ Show 20 Lines • Show All 409 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator