Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Index: CCmpAIManager.cpp
- ===================================================================
- --- CCmpAIManager.cpp (revision 10297)
- +++ CCmpAIManager.cpp (working copy)
- @@ -34,6 +34,7 @@
- #include "simulation2/components/ICmpObstructionManager.h"
- #include "simulation2/components/ICmpRangeManager.h"
- #include "simulation2/components/ICmpTemplateManager.h"
- +#include "simulation2/components/ICmpTerritoryManager.h"
- #include "simulation2/helpers/Grid.h"
- #include "simulation2/serialization/DebugSerializer.h"
- #include "simulation2/serialization/StdDeserializer.h"
- @@ -286,7 +287,7 @@
- return true;
- }
- - void StartComputation(const shared_ptr<ScriptInterface::StructuredClone>& gameState, const Grid<u16>& map)
- + void StartComputation(const shared_ptr<ScriptInterface::StructuredClone>& gameState, const Grid<u16>& map, const Grid<u8>& territoryMap)
- {
- ENSURE(m_CommandsComputed);
- @@ -300,6 +301,25 @@
- m_GameStateMapVal = CScriptValRooted(cx, ScriptInterface::ToJSVal(cx, m_GameStateMap));
- }
- + if (true) //territoryMap.m_DirtyID != m_TerritoryMap.m_DirtyID) couldn't manage to get this working the ID's always matched
- + {
- + PROFILE("territoryMap");
- + m_TerritoryMap = territoryMap;
- +
- + // The ToJSVal function can't take Grid<u8> so convert.
- + Grid<u16>* tmp = new Grid<u16>(territoryMap.m_W, territoryMap.m_H);
- +
- + for (u16 i = 0; i < tmp->m_W; i++){
- + for (u16 j = 0; j < tmp->m_W; j++){
- + tmp->set(i,j, u16(territoryMap.get(i,j)));
- + }
- + }
- +
- + JSContext* cx = m_ScriptInterface.GetContext();
- + m_TerritoryMapVal = CScriptValRooted(cx, ScriptInterface::ToJSVal(cx, *tmp));
- + }
- +
- +
- m_CommandsComputed = false;
- }
- @@ -427,12 +447,14 @@
- void PerformComputation()
- {
- +
- // Deserialize the game state, to pass to the AI's HandleMessage
- CScriptVal state;
- {
- PROFILE("AI compute read state");
- state = m_ScriptInterface.ReadStructuredClone(m_GameState);
- m_ScriptInterface.SetProperty(state.get(), "map", m_GameStateMapVal, true);
- + m_ScriptInterface.SetProperty(state.get(), "territoryMap", m_TerritoryMapVal, true);
- }
- // It would be nice to do
- @@ -469,6 +491,8 @@
- shared_ptr<ScriptInterface::StructuredClone> m_GameState;
- Grid<u16> m_GameStateMap;
- CScriptValRooted m_GameStateMapVal;
- + Grid<u8> m_TerritoryMap;
- + CScriptValRooted m_TerritoryMapVal;
- bool m_CommandsComputed;
- };
- @@ -575,9 +599,15 @@
- if (!cmpPathfinder.null())
- map = &cmpPathfinder->GetPassabilityGrid();
- + Grid<u8> dummyGrid2;
- + const Grid<u8>* territoryMap = &dummyGrid2;
- + CmpPtr<ICmpTerritoryManager> cmpTerritoryManager(GetSimContext(), SYSTEM_ENTITY);
- + if (!cmpTerritoryManager.null())// || !cmpTerritoryManager->NeedUpdate(&m_TerritoriesDirtyID)) - Don't think this is appropriate here so have ignored it
- + territoryMap = &cmpTerritoryManager->GetTerritoryGrid();
- +
- LoadPathfinderClasses(state);
- - m_Worker.StartComputation(scriptInterface.WriteStructuredClone(state.get()), *map);
- + m_Worker.StartComputation(scriptInterface.WriteStructuredClone(state.get()), *map, *territoryMap);
- }
- virtual void PushCommands()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement