Changeset View
Changeset View
Standalone View
Standalone View
source/simulation2/Simulation2.cpp
/* Copyright (C) 2021 Wildfire Games. | /* Copyright (C) 2021 Wildfire Games. | ||||
Stan: Bump year.
@Itms: D404 seem to work as expected :) | |||||
Not Done Inline ActionsYear :) Stan: Year :) | |||||
* 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 All 11 Lines | |||||
#include "scriptinterface/ScriptContext.h" | #include "scriptinterface/ScriptContext.h" | ||||
#include "scriptinterface/ScriptInterface.h" | #include "scriptinterface/ScriptInterface.h" | ||||
#include "simulation2/MessageTypes.h" | #include "simulation2/MessageTypes.h" | ||||
#include "simulation2/system/ComponentManager.h" | #include "simulation2/system/ComponentManager.h" | ||||
#include "simulation2/system/ParamNode.h" | #include "simulation2/system/ParamNode.h" | ||||
#include "simulation2/system/SimContext.h" | #include "simulation2/system/SimContext.h" | ||||
#include "simulation2/system/SimSynchronization.h" | |||||
#include "simulation2/components/ICmpAIManager.h" | #include "simulation2/components/ICmpAIManager.h" | ||||
#include "simulation2/components/ICmpCommandQueue.h" | #include "simulation2/components/ICmpCommandQueue.h" | ||||
#include "simulation2/components/ICmpTemplateManager.h" | #include "simulation2/components/ICmpTemplateManager.h" | ||||
#include "graphics/MapReader.h" | #include "graphics/MapReader.h" | ||||
#include "graphics/Terrain.h" | #include "graphics/Terrain.h" | ||||
#include "lib/timer.h" | #include "lib/timer.h" | ||||
#include "lib/file/vfs/vfs_util.h" | #include "lib/file/vfs/vfs_util.h" | ||||
Show All 14 Lines | |||||
{ | { | ||||
public: | public: | ||||
CSimulation2Impl(CUnitManager* unitManager, shared_ptr<ScriptContext> cx, CTerrain* terrain) : | CSimulation2Impl(CUnitManager* unitManager, shared_ptr<ScriptContext> cx, CTerrain* terrain) : | ||||
m_SimContext(), m_ComponentManager(m_SimContext, cx), | m_SimContext(), m_ComponentManager(m_SimContext, cx), | ||||
m_EnableOOSLog(false), m_EnableSerializationTest(false), m_RejoinTestTurn(-1), m_TestingRejoin(false), | m_EnableOOSLog(false), m_EnableSerializationTest(false), m_RejoinTestTurn(-1), m_TestingRejoin(false), | ||||
m_SecondaryTerrain(nullptr), m_SecondaryContext(nullptr), m_SecondaryComponentManager(nullptr), m_SecondaryLoadedScripts(nullptr), | m_SecondaryTerrain(nullptr), m_SecondaryContext(nullptr), m_SecondaryComponentManager(nullptr), m_SecondaryLoadedScripts(nullptr), | ||||
m_MapSettings(cx->GetGeneralJSContext()), m_InitAttributes(cx->GetGeneralJSContext()) | m_MapSettings(cx->GetGeneralJSContext()), m_InitAttributes(cx->GetGeneralJSContext()) | ||||
{ | { | ||||
m_SimContext.m_SynchronizationData = &m_SynchronizationData; | |||||
m_SimContext.m_UnitManager = unitManager; | m_SimContext.m_UnitManager = unitManager; | ||||
m_SimContext.m_Terrain = terrain; | m_SimContext.m_Terrain = terrain; | ||||
m_ComponentManager.LoadComponentTypes(); | m_ComponentManager.LoadComponentTypes(); | ||||
RegisterFileReloadFunc(ReloadChangedFileCB, this); | RegisterFileReloadFunc(ReloadChangedFileCB, this); | ||||
// Tests won't have config initialised | // Tests won't have config initialised | ||||
if (CConfigDB::IsInitialised()) | if (CConfigDB::IsInitialised()) | ||||
▲ Show 20 Lines • Show All 54 Lines • ▼ Show 20 Lines | public: | ||||
void DumpState(); | void DumpState(); | ||||
CSimContext m_SimContext; | CSimContext m_SimContext; | ||||
CComponentManager m_ComponentManager; | CComponentManager m_ComponentManager; | ||||
double m_DeltaTime; | double m_DeltaTime; | ||||
float m_LastFrameOffset; | float m_LastFrameOffset; | ||||
SSimSynchronization m_SynchronizationData; | |||||
std::string m_StartupScript; | std::string m_StartupScript; | ||||
JS::PersistentRootedValue m_InitAttributes; | JS::PersistentRootedValue m_InitAttributes; | ||||
JS::PersistentRootedValue m_MapSettings; | JS::PersistentRootedValue m_MapSettings; | ||||
std::set<VfsPath> m_LoadedScripts; | std::set<VfsPath> m_LoadedScripts; | ||||
uint32_t m_TurnNumber; | uint32_t m_TurnNumber; | ||||
▲ Show 20 Lines • Show All 395 Lines • ▼ Show 20 Lines | if (cmpPathfinder) | ||||
cmpPathfinder->FetchAsyncResultsAndSendMessages(); | cmpPathfinder->FetchAsyncResultsAndSendMessages(); | ||||
{ | { | ||||
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 | // Push AI commands onto the queue before we use them | ||||
Done Inline ActionsPut before the grid update because we need to make sure the state isn't changed from last turn. wraitii: Put before the grid update because we need to make sure the state isn't changed from last turn. | |||||
Not Done Inline ActionsMaybe it deserves a comment ? Stan: Maybe it deserves a comment ? | |||||
CmpPtr<ICmpAIManager> cmpAIManager(simContext, SYSTEM_ENTITY); | CmpPtr<ICmpAIManager> cmpAIManager(simContext, SYSTEM_ENTITY); | ||||
if (cmpAIManager) | if (cmpAIManager) | ||||
cmpAIManager->PushCommands(); | 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) | ||||
{ | { | ||||
Not Done Inline Actions(This is a requirement, so it should be checked in the requirements phase of development, i.e. before the design or implementation stage). elexis: (This is a requirement, so it should be checked in the requirements phase of development, i.e. | |||||
Done Inline ActionsThis comment is outdated since below I call "FetchAsyncResultsAndSendMessages", which actually waits for all paths to be computed, so we aren't running this "during update". It could probably be run during update but I haven't checked and it'd be trickier. wraitii: This comment is outdated since below I call "FetchAsyncResultsAndSendMessages", which actually… | |||||
cmpPathfinder->StartProcessingMoves(true); | cmpPathfinder->StartProcessingMoves(true); | ||||
cmpPathfinder->FetchAsyncResultsAndSendMessages(); | cmpPathfinder->FetchAsyncResultsAndSendMessages(); | ||||
} | } | ||||
// Send all the update phases | // Send all the update phases | ||||
{ | { | ||||
PROFILE2("Sim - Update"); | PROFILE2("Sim - Update"); | ||||
CMessageUpdate msgUpdate(turnLengthFixed); | CMessageUpdate msgUpdate(turnLengthFixed); | ||||
componentManager.BroadcastMessage(msgUpdate); | componentManager.BroadcastMessage(msgUpdate); | ||||
} | } | ||||
Not Done Inline ActionsNuke Stan: Nuke | |||||
Not Done Inline ActionsStill accurate. Stan: Still accurate. | |||||
{ | { | ||||
CMessageUpdate_MotionFormation msgUpdate(turnLengthFixed); | CMessageUpdate_MotionFormation msgUpdate(turnLengthFixed); | ||||
componentManager.BroadcastMessage(msgUpdate); | componentManager.BroadcastMessage(msgUpdate); | ||||
} | } | ||||
// Process move commands for formations (group proxy) | // Process move commands for formations (group proxy) | ||||
if (cmpPathfinder) | if (cmpPathfinder) | ||||
{ | { | ||||
cmpPathfinder->StartProcessingMoves(true); | cmpPathfinder->StartProcessingMoves(true); | ||||
cmpPathfinder->FetchAsyncResultsAndSendMessages(); | cmpPathfinder->FetchAsyncResultsAndSendMessages(); | ||||
} | } | ||||
{ | { | ||||
PROFILE2("Sim - Motion Unit"); | PROFILE2("Sim - Motion Unit"); | ||||
CMessageUpdate_MotionUnit msgUpdate(turnLengthFixed); | CMessageUpdate_MotionUnit msgUpdate(turnLengthFixed); | ||||
componentManager.BroadcastMessage(msgUpdate); | componentManager.BroadcastMessage(msgUpdate); | ||||
} | } | ||||
{ | { | ||||
Not Done Inline ActionsNuke. Stan: Nuke. | |||||
Not Done Inline ActionsHaving blank lines here actually makes sense. If 574 can be blank then why wouldn't there be other blank lines? Kuba386: Having blank lines here actually makes sense. If 574 can be blank then why wouldn't there be… | |||||
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(); | ||||
// Process all remaining moves | // Process all remaining moves | ||||
Done Inline ActionsComment should be changed to something like "Start processing moves in the background". wraitii: Comment should be changed to something like "Start processing moves in the background". | |||||
if (cmpPathfinder) | if (cmpPathfinder) | ||||
{ | { | ||||
cmpPathfinder->UpdateGrid(); | cmpPathfinder->UpdateGrid(); | ||||
cmpPathfinder->StartProcessingMoves(false); | cmpPathfinder->StartProcessingMoves(false); | ||||
} | } | ||||
} | } | ||||
void CSimulation2Impl::Interpolate(float simFrameLength, float frameOffset, float realFrameLength) | void CSimulation2Impl::Interpolate(float simFrameLength, float frameOffset, float realFrameLength) | ||||
▲ Show 20 Lines • Show All 294 Lines • ▼ Show 20 Lines | |||||
bool CSimulation2::SerializeState(std::ostream& stream) | bool CSimulation2::SerializeState(std::ostream& stream) | ||||
{ | { | ||||
return m->m_ComponentManager.SerializeState(stream); | return m->m_ComponentManager.SerializeState(stream); | ||||
} | } | ||||
bool CSimulation2::DeserializeState(std::istream& stream) | bool CSimulation2::DeserializeState(std::istream& stream) | ||||
{ | { | ||||
m->m_SynchronizationData.Reset(); | |||||
// TODO: need to make sure the required SYSTEM_ENTITY components get constructed | // TODO: need to make sure the required SYSTEM_ENTITY components get constructed | ||||
return m->m_ComponentManager.DeserializeState(stream); | return m->m_ComponentManager.DeserializeState(stream); | ||||
} | } | ||||
void CSimulation2::ActivateRejoinTest(int turn) | void CSimulation2::ActivateRejoinTest(int turn) | ||||
{ | { | ||||
if (m->m_RejoinTestTurn != -1) | if (m->m_RejoinTestTurn != -1) | ||||
return; | return; | ||||
▲ Show 20 Lines • Show All 98 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator
Bump year.
@Itms: D404 seem to work as expected :)