Ticket #3060: aimanager2.diff
File aimanager2.diff, 2.5 KB (added by , 9 years ago) |
---|
-
source/simulation2/components/CCmpAIManager.cpp
1 /* Copyright (C) 201 4Wildfire Games.1 /* Copyright (C) 2015 Wildfire Games. 2 2 * This file is part of 0 A.D. 3 3 * 4 4 * 0 A.D. is free software: you can redistribute it and/or modify … … 558 558 { 559 559 JSContext* cx = m_ScriptInterface->GetContext(); 560 560 JSAutoRequest rq(cx); 561 561 562 562 std::stringstream rngStream; 563 563 rngStream << m_RNG; 564 564 serializer.StringASCII("rng", rngStream.str(), 0, 32); 565 565 566 566 serializer.NumberU32_Unbounded("turn", m_TurnNum); 567 567 568 serializer.NumberU32_Unbounded("num ais", (u32)m_Players.size());569 570 568 serializer.Bool("useSharedScript", m_HasSharedComponent); 571 569 if (m_HasSharedComponent) 572 570 { … … 606 604 } 607 605 } 608 606 609 void Deserialize(std::istream& stream )607 void Deserialize(std::istream& stream, uint32_t numAis) 610 608 { 611 609 JSContext* cx = m_ScriptInterface->GetContext(); 612 610 JSAutoRequest rq(cx); 613 611 614 612 ENSURE(m_CommandsComputed); // deserializing while we're still actively computing would be bad 615 613 616 614 CStdDeserializer deserializer(*m_ScriptInterface, stream); … … 626 624 627 625 deserializer.NumberU32_Unbounded("turn", m_TurnNum); 628 626 629 uint32_t numAis;630 deserializer.NumberU32_Unbounded("num ais", numAis);631 632 627 deserializer.Bool("useSharedScript", m_HasSharedComponent); 633 TryLoadSharedComponent(false);634 628 if (m_HasSharedComponent) 635 629 { 630 TryLoadSharedComponent(false); 631 636 632 JS::RootedValue sharedData(cx); 637 633 JS::RootedValue tmpSharedAIObj(cx, m_SharedAIObj.get()); // TODO: Check if this temporary root can be removed after SpiderMonkey 31 638 634 deserializer.ScriptVal("sharedData", &sharedData); … … 841 837 842 838 virtual void Serialize(ISerializer& serialize) 843 839 { 840 serialize.NumberU32_Unbounded("num ais", m_Worker.getPlayerSize()); 841 844 842 // Because the AI worker uses its own ScriptInterface, we can't use the 845 843 // ISerializer (which was initialised with the simulation ScriptInterface) 846 844 // directly. So we'll just grab the ISerializer's stream and write to it … … 853 851 { 854 852 Init(paramNode); 855 853 856 ForceLoadEntityTemplates(); 854 uint32_t numAis; 855 deserialize.NumberU32_Unbounded("num ais", numAis); 856 if (numAis > 0) 857 ForceLoadEntityTemplates(); 857 858 858 m_Worker.Deserialize(deserialize.GetStream() );859 m_Worker.Deserialize(deserialize.GetStream(), numAis); 859 860 860 861 m_JustDeserialized = true; 861 862 }