diff --git a/source/graphics/MapReader.cpp b/source/graphics/MapReader.cpp index 4080fedb56..b5a2b89800 100644 --- a/source/graphics/MapReader.cpp +++ b/source/graphics/MapReader.cpp @@ -215,7 +215,7 @@ int CMapReader::ApplyData() // loaded on demand) } - std::set selections; // TODO: read from file + std::set selections; // TODO: read from file CUnit* unit = g_UnitMan.CreateUnit(m_ObjectTypes.at(m_Objects[i].m_ObjectIndex), NULL, selections); if (unit) @@ -536,7 +536,7 @@ int CXMLReader::ReadEntities(XMBElement parent, double end_time) LOG(ERROR, LOG_CATEGORY, "Failed to load entity template '%ls'", TemplateName.c_str()); else { - std::set selections; // TODO: read from file + std::set selections; // TODO: read from file HEntity ent = g_EntityManager.create(base, Position, Orientation, selections); @@ -602,7 +602,7 @@ int CXMLReader::ReadNonEntities(XMBElement parent, double end_time) debug_warn("Invalid map XML data"); } - std::set selections; // TODO: read from file + std::set selections; // TODO: read from file CUnit* unit = g_UnitMan.CreateUnit(ActorName, NULL, selections); diff --git a/source/graphics/ObjectBase.cpp b/source/graphics/ObjectBase.cpp index aa734c324c..547a5a4a90 100644 --- a/source/graphics/ObjectBase.cpp +++ b/source/graphics/ObjectBase.cpp @@ -214,7 +214,7 @@ bool CObjectBase::Load(const char* filename) return true; } -std::vector CObjectBase::CalculateVariationKey(const std::vector >& selections) +std::vector CObjectBase::CalculateVariationKey(const std::vector >& selections) { // (TODO: see CObjectManager::FindObjectVariation for an opportunity to // call this function a bit less frequently) @@ -252,7 +252,7 @@ std::vector CObjectBase::CalculateVariationKey(const std::vector >::const_iterator selset = selections.begin(); selset < selections.end(); ++selset) + for (std::vector >::const_iterator selset = selections.begin(); selset < selections.end(); ++selset) { debug_assert(grp->size() < 256); // else they won't fit in 'choices' @@ -367,9 +367,9 @@ const CObjectBase::Variation CObjectBase::BuildVariation(const std::vector& return variation; } -std::set CObjectBase::CalculateRandomVariation(const std::set& initialSelections) +std::set CObjectBase::CalculateRandomVariation(const std::set& initialSelections) { - std::set selections = initialSelections; + std::set selections = initialSelections; std::map chosenProps; @@ -471,9 +471,9 @@ std::set CObjectBase::CalculateRandomVariation(const std::set& ini CObjectBase* prop = g_ObjMan.FindObjectBase(it->second); if (prop) { - std::set propSelections = prop->CalculateRandomVariation(selections); + std::set propSelections = prop->CalculateRandomVariation(selections); // selections = union(propSelections, selections) - std::set newSelections; + std::set newSelections; std::set_union(propSelections.begin(), propSelections.end(), selections.begin(), selections.end(), std::inserter(newSelections, newSelections.begin())); @@ -484,9 +484,9 @@ std::set CObjectBase::CalculateRandomVariation(const std::set& ini return selections; } -std::vector > CObjectBase::GetVariantGroups() const +std::vector > CObjectBase::GetVariantGroups() const { - std::vector > groups; + std::vector > groups; // Queue of objects (main actor plus props (recursively)) to be processed std::queue objectsQueue; @@ -509,7 +509,7 @@ std::vector > CObjectBase::GetVariantGroups() const for (size_t i = 0; i < obj->m_VariantGroups.size(); ++i) { // Copy the group's variant names into a new vector - std::vector group; + std::vector group; group.reserve(obj->m_VariantGroups[i].size()); for (size_t j = 0; j < obj->m_VariantGroups[i].size(); ++j) group.push_back(obj->m_VariantGroups[i][j].m_VariantName); diff --git a/source/graphics/ObjectBase.h b/source/graphics/ObjectBase.h index 7f5cd78a7f..c79e86d62f 100644 --- a/source/graphics/ObjectBase.h +++ b/source/graphics/ObjectBase.h @@ -62,7 +62,7 @@ public: // Get the variation key (indices of chosen variants from each group) // based on the selection strings - std::vector CalculateVariationKey(const std::vector >& selections); + std::vector CalculateVariationKey(const std::vector >& selections); // Get the final actor data, combining all selected variants const Variation BuildVariation(const std::vector& variationKey); @@ -70,12 +70,12 @@ public: // Get a set of selection strings that are complete enough to specify an // exact variation of the actor, using the initial selections wherever possible // and choosing randomly where a choice is necessary. - std::set CalculateRandomVariation(const std::set& initialSelections); + std::set CalculateRandomVariation(const std::set& initialSelections); // Get a list of variant groups for this object, plus for all possible // props. Duplicated groups are removed, if several props share the same // variant names. - std::vector > GetVariantGroups() const; + std::vector > GetVariantGroups() const; bool Load(const char* filename); diff --git a/source/graphics/ObjectEntry.cpp b/source/graphics/ObjectEntry.cpp index a9e7c9b80d..8538ccd0ff 100644 --- a/source/graphics/ObjectEntry.cpp +++ b/source/graphics/ObjectEntry.cpp @@ -38,7 +38,7 @@ CObjectEntry::~CObjectEntry() } -bool CObjectEntry::BuildVariation(const std::vector >& selections, const std::vector& variationKey) +bool CObjectEntry::BuildVariation(const std::vector >& selections, const std::vector& variationKey) { CObjectBase::Variation variation = m_Base->BuildVariation(variationKey); diff --git a/source/graphics/ObjectEntry.h b/source/graphics/ObjectEntry.h index 5f8b9a0427..8b1bbe7329 100644 --- a/source/graphics/ObjectEntry.h +++ b/source/graphics/ObjectEntry.h @@ -19,7 +19,7 @@ public: ~CObjectEntry(); // Construct this actor, using the specified variation selections - bool BuildVariation(const std::vector >& selections, const std::vector& variationKey); + bool BuildVariation(const std::vector >& selections, const std::vector& variationKey); // Base actor. Contains all the things that don't change between // different variations of the actor. diff --git a/source/graphics/ObjectManager.cpp b/source/graphics/ObjectManager.cpp index 7afc9b3045..d49f895833 100644 --- a/source/graphics/ObjectManager.cpp +++ b/source/graphics/ObjectManager.cpp @@ -80,11 +80,11 @@ CObjectBase* CObjectManager::FindObjectBase(const char* objectname) CObjectEntry* CObjectManager::FindObject(const char* objname) { - std::vector > selections; // TODO - should this really be empty? + std::vector > selections; // TODO - should this really be empty? return FindObjectVariation(objname, selections); } -CObjectEntry* CObjectManager::FindObjectVariation(const char* objname, const std::vector >& selections) +CObjectEntry* CObjectManager::FindObjectVariation(const char* objname, const std::vector >& selections) { CObjectBase* base = FindObjectBase(objname); @@ -94,7 +94,7 @@ CObjectEntry* CObjectManager::FindObjectVariation(const char* objname, const std return FindObjectVariation(base, selections); } -CObjectEntry* CObjectManager::FindObjectVariation(CObjectBase* base, const std::vector >& selections) +CObjectEntry* CObjectManager::FindObjectVariation(CObjectBase* base, const std::vector >& selections) { PROFILE( "object variation loading" ); diff --git a/source/graphics/ObjectManager.h b/source/graphics/ObjectManager.h index 16d3ea6c30..d3121b2079 100644 --- a/source/graphics/ObjectManager.h +++ b/source/graphics/ObjectManager.h @@ -68,8 +68,8 @@ public: CObjectBase* FindObjectBase(const char* objname); - CObjectEntry* FindObjectVariation(const char* objname, const std::vector >& selections); - CObjectEntry* FindObjectVariation(CObjectBase* base, const std::vector >& selections); + CObjectEntry* FindObjectVariation(const char* objname, const std::vector >& selections); + CObjectEntry* FindObjectVariation(CObjectBase* base, const std::vector >& selections); // Get all names, quite slowly. (Intended only for ScEd.) void GetAllObjectNames(std::vector& names); diff --git a/source/graphics/Unit.cpp b/source/graphics/Unit.cpp index 395755d21d..1286d524d7 100644 --- a/source/graphics/Unit.cpp +++ b/source/graphics/Unit.cpp @@ -7,7 +7,7 @@ #include "SkeletonAnim.h" #include "SkeletonAnimDef.h" -CUnit::CUnit(CObjectEntry* object, CEntity* entity, const std::set& actorSelections) +CUnit::CUnit(CObjectEntry* object, CEntity* entity, const std::set& actorSelections) : m_Object(object), m_Model(object->m_Model->Clone()), m_Entity(entity), m_ID(-1), m_ActorSelections(actorSelections) { @@ -130,7 +130,7 @@ void CUnit::SetEntitySelection(const CStrW& selection) ReloadObject(); } -void CUnit::SetActorSelections(const std::set& selections) +void CUnit::SetActorSelections(const std::set& selections) { m_ActorSelections = selections; ReloadObject(); @@ -138,7 +138,7 @@ void CUnit::SetActorSelections(const std::set& selections) void CUnit::ReloadObject() { - std::vector > selections; + std::vector > selections; // TODO: push world selections (seasons, etc) (and reload whenever they're changed) selections.push_back(m_EntitySelections); selections.push_back(m_ActorSelections); diff --git a/source/graphics/Unit.h b/source/graphics/Unit.h index bd66522a11..a6be5fb065 100644 --- a/source/graphics/Unit.h +++ b/source/graphics/Unit.h @@ -15,7 +15,7 @@ class CStrW; class CUnit { public: - CUnit(CObjectEntry* object, CEntity* entity, const std::set& actorSelections); + CUnit(CObjectEntry* object, CEntity* entity, const std::set& actorSelections); // destructor ~CUnit(); @@ -57,9 +57,9 @@ public: int GetID() const { return m_ID; } void SetID(int id) { m_ID = id; } - const std::set& GetActorSelections() const { return m_ActorSelections; } + const std::set& GetActorSelections() const { return m_ActorSelections; } - void SetActorSelections(const std::set& selections); + void SetActorSelections(const std::set& selections); private: // object from which unit was created @@ -76,9 +76,9 @@ private: int m_ID; // actor-level selections for this unit - std::set m_ActorSelections; + std::set m_ActorSelections; // entity-level selections for this unit - std::set m_EntitySelections; + std::set m_EntitySelections; void ReloadObject(); }; diff --git a/source/graphics/UnitManager.cpp b/source/graphics/UnitManager.cpp index 874ba003ab..26305c4144 100644 --- a/source/graphics/UnitManager.cpp +++ b/source/graphics/UnitManager.cpp @@ -125,16 +125,16 @@ CUnit* CUnitManager::PickUnit(const CVector3D& origin, const CVector3D& dir) con /////////////////////////////////////////////////////////////////////////////// // CreateUnit: create a new unit and add it to the world -CUnit* CUnitManager::CreateUnit(const CStr& actorName, CEntity* entity, const std::set& selections) +CUnit* CUnitManager::CreateUnit(const CStr& actorName, CEntity* entity, const std::set& selections) { CObjectBase* base = g_ObjMan.FindObjectBase(actorName); if (! base) return NULL; - std::set actorSelections = base->CalculateRandomVariation(selections); + std::set actorSelections = base->CalculateRandomVariation(selections); - std::vector > selectionsVec; + std::vector > selectionsVec; selectionsVec.push_back(actorSelections); CObjectEntry* obj = g_ObjMan.FindObjectVariation(base, selectionsVec); diff --git a/source/graphics/UnitManager.h b/source/graphics/UnitManager.h index aff2bdc5ec..c110e47cb2 100644 --- a/source/graphics/UnitManager.h +++ b/source/graphics/UnitManager.h @@ -41,7 +41,7 @@ public: void DeleteAll(); // creates a new unit and adds it to the world - CUnit* CreateUnit(const CStr& actorName, CEntity* entity, const std::set& selections); + CUnit* CreateUnit(const CStr& actorName, CEntity* entity, const std::set& selections); // return the units const std::vector& GetUnits() const { return m_Units; } diff --git a/source/ps/Interact.cpp b/source/ps/Interact.cpp index 0f4166e28c..3cf730b3d4 100644 --- a/source/ps/Interact.cpp +++ b/source/ps/Interact.cpp @@ -1348,7 +1348,7 @@ bool CBuildingPlacer::activate(CStrW& templateName) // m_actor CStr actorName ( m_template->m_actorName ); // convert CStrW->CStr8 - std::set selections; + std::set selections; m_actor = g_UnitMan.CreateUnit( actorName, 0, selections ); m_actor->SetPlayerID(g_Game->GetLocalPlayer()->GetPlayerID()); diff --git a/source/scripting/ScriptableComplex.h b/source/scripting/ScriptableComplex.h index 62468a09c3..140684715f 100644 --- a/source/scripting/ScriptableComplex.h +++ b/source/scripting/ScriptableComplex.h @@ -1,7 +1,18 @@ -// ScriptableComplex.h -// -// The version of CJSObject<> that retains the ability to use inheritance -// in its objects. Shouldn't be used any more for anything but entity code. +/* +ScriptableComplex.h + +The version of CJSObject<> that retains the ability to use inheritance +in its objects. Shouldn't be used any more for anything but entity code. + +This file contains only declarations of class CJSComplex and its methods. +Their implementations are in ScriptableComplex.inl. Because CJSComplex is +a templated class, any source file that uses these methods directly must +#include ScritpableComplex.inl to link to them. However, files that +only need to know that something is a CJSComplex need not do this. This +was done to speed up compile times after modifying CJSComplex's internals: +before, 30+ files had to be recompiled because they #included Entity.j +which #includes ScriptableComplex.h. +*/ #include "scripting/ScriptingHost.h" #include "simulation/ScriptObject.h" diff --git a/source/scripting/ScriptableComplex.inl b/source/scripting/ScriptableComplex.inl index a0f70f147a..1df09e1ec4 100644 --- a/source/scripting/ScriptableComplex.inl +++ b/source/scripting/ScriptableComplex.inl @@ -1,4 +1,8 @@ /* +Implementation of CJSComplex's functions and related helper functions and classes. +This file must be #included in any CPP file that accesses these functions directly, +but may be omitted in those that don't. + rationale: we are changing CJSComplex often for purposes of optimization. this triggers close to a full rebuild, which is unacceptable. @@ -34,6 +38,15 @@ several workarounds have been investigated. potentially be trouble with ToJSVal, since we no longer derive from CJSComplex. this is not deemed worth the effort due to steps taken in #1. + +We decided to split off the implementation of CJSComplex as well as many of its +helper classes into a separate header, ScriptableComplex.inl. This way, +ScriptableComplex.h does not need to be modified unless we change the API, +but the implementations of CJSComplex's methods can be changed. However, this +also means that this header (ScriptableComplex.inl) must be #included in any +CPP file that directly accesses ScriptableComplex's methods - otherwise, the +linker won't find the definitions of these functions. Right now this is only +5 files, which results in much faster rebuilds after modifying this code. */ #ifndef SCRIPTABLE_COMPLEX_INL_INCLUDED diff --git a/source/simulation/Entity.cpp b/source/simulation/Entity.cpp index 808a288f81..325559d9d1 100644 --- a/source/simulation/Entity.cpp +++ b/source/simulation/Entity.cpp @@ -37,7 +37,7 @@ extern int g_xres, g_yres; #include using namespace std; -CEntity::CEntity( CEntityTemplate* base, CVector3D position, float orientation, const std::set& actorSelections, const CStrW* building ) +CEntity::CEntity( CEntityTemplate* base, CVector3D position, float orientation, const std::set& actorSelections, const CStrW* building ) { ent_flags = 0; @@ -1588,7 +1588,7 @@ JSBool CEntity::Construct( JSContext* cx, JSObject* UNUSED(obj), uint argc, jsva } } - std::set selections; // TODO: let scripts specify selections? + std::set selections; // TODO: let scripts specify selections? HEntity handle = g_EntityManager.create( baseEntity, position, orientation, selections ); handle->SetPlayer( player ); handle->Initialize(); diff --git a/source/simulation/Entity.h b/source/simulation/Entity.h index 61238f052d..e69cc22420 100644 --- a/source/simulation/Entity.h +++ b/source/simulation/Entity.h @@ -215,7 +215,7 @@ public: CScriptObject m_EventHandlers[EVENT_LAST]; CUnit* m_actor; - std::set m_actorSelections; + std::set m_actorSelections; int m_lastState; // used in animation FSM @@ -275,7 +275,7 @@ public: private: - CEntity( CEntityTemplate* base, CVector3D position, float orientation, const std::set& actorSelections, const CStrW* building = 0 ); + CEntity( CEntityTemplate* base, CVector3D position, float orientation, const std::set& actorSelections, const CStrW* building = 0 ); uint processGotoHelper( CEntityOrder* current, size_t timestep_milli, HEntity& collide ); diff --git a/source/simulation/EntityManager.cpp b/source/simulation/EntityManager.cpp index 85d96405f3..04db53e3c7 100644 --- a/source/simulation/EntityManager.cpp +++ b/source/simulation/EntityManager.cpp @@ -75,7 +75,7 @@ void CEntityManager::deleteAll() m_extant = true; } -HEntity CEntityManager::create( CEntityTemplate* base, CVector3D position, float orientation, const std::set& actorSelections, +HEntity CEntityManager::create( CEntityTemplate* base, CVector3D position, float orientation, const std::set& actorSelections, const CStrW* building) { debug_assert( base ); @@ -106,7 +106,7 @@ HEntity CEntityManager::create( const CStrW& templateName, CPlayer* player, CVec if( !base ) return HEntity(); - std::set selections; + std::set selections; return create( base, position, orientation, selections, building ); } @@ -118,7 +118,7 @@ HEntity CEntityManager::createFoundation( const CStrW& templateName, CPlayer* pl if( !base ) return HEntity(); - std::set selections; + std::set selections; if( base->m_foundation == L"" ) return create( base, position, orientation, selections ); // Entity has no foundation, so just create it diff --git a/source/simulation/EntityManager.h b/source/simulation/EntityManager.h index f6b7ab51a3..c8795697cc 100644 --- a/source/simulation/EntityManager.h +++ b/source/simulation/EntityManager.h @@ -56,7 +56,7 @@ public: ~CEntityManager(); HEntity create( CEntityTemplate* base, CVector3D position, float orientation, - const std::set& actorSelections, const CStrW* building = 0 ); + const std::set& actorSelections, const CStrW* building = 0 ); HEntity create( const CStrW& templateName, CPlayer* player, CVector3D position, float orientation, const CStrW* building = 0 ); diff --git a/source/tools/atlas/GameInterface/Handlers/ObjectHandlers.cpp b/source/tools/atlas/GameInterface/Handlers/ObjectHandlers.cpp index fd42d71ac7..8ee34b3905 100644 --- a/source/tools/atlas/GameInterface/Handlers/ObjectHandlers.cpp +++ b/source/tools/atlas/GameInterface/Handlers/ObjectHandlers.cpp @@ -114,18 +114,18 @@ QUERYHANDLER(GetObjectSettings) settings.player = unit->GetPlayerID(); // Get the unit's possible variants and selected variants - std::vector > groups = unit->GetObject()->m_Base->GetVariantGroups(); - const std::set& selections = unit->GetActorSelections(); + std::vector > groups = unit->GetObject()->m_Base->GetVariantGroups(); + const std::set& selections = unit->GetActorSelections(); // Iterate over variant groups - std::vector > variantgroups; - std::set selections_set; + std::vector > variantgroups; + std::set selections_set; variantgroups.reserve(groups.size()); for (size_t i = 0; i < groups.size(); ++i) { // Copy variants into output structure - std::vector group; + std::vector group; group.reserve(groups[i].size()); int choice = -1; @@ -149,14 +149,14 @@ QUERYHANDLER(GetObjectSettings) } settings.variantgroups = variantgroups; - settings.selections = std::vector (selections_set.begin(), selections_set.end()); // convert set->vector + settings.selections = std::vector (selections_set.begin(), selections_set.end()); // convert set->vector msg->settings = settings; } BEGIN_COMMAND(SetObjectSettings) { int m_PlayerOld, m_PlayerNew; - std::set m_SelectionsOld, m_SelectionsNew; + std::set m_SelectionsOld, m_SelectionsNew; void Do() { @@ -170,9 +170,9 @@ BEGIN_COMMAND(SetObjectSettings) m_SelectionsOld = unit->GetActorSelections(); - std::vector selections = *settings.selections; + std::vector selections = *settings.selections; copy(selections.begin(), selections.end(), - std::insert_iterator >(m_SelectionsNew, m_SelectionsNew.begin())); + std::insert_iterator >(m_SelectionsNew, m_SelectionsNew.begin())); Redo(); } @@ -262,7 +262,7 @@ MESSAGEHANDLER(ObjectPreview) CStrW name; if (ParseObjectName(*msg->id, isEntity, name)) { - std::set selections; // TODO: get selections from user + std::set selections; // TODO: get selections from user // Create new unit if (isEntity) @@ -360,7 +360,7 @@ BEGIN_COMMAND(CreateObject) CStrW name; if (ParseObjectName(*msg->id, isEntity, name)) { - std::set selections; + std::set selections; if (isEntity) { diff --git a/source/tools/atlas/GameInterface/Messages.h b/source/tools/atlas/GameInterface/Messages.h index 002031e362..1be3c824cf 100644 --- a/source/tools/atlas/GameInterface/Messages.h +++ b/source/tools/atlas/GameInterface/Messages.h @@ -114,12 +114,12 @@ QUERY(GetObjectsList, struct sObjectSettings { Shareable player; - Shareable > selections; + Shareable > selections; // Some settings are immutable and therefore are ignored (and should be left // empty) when passed from the editor to the game: - Shareable > > variantgroups; + Shareable > > variantgroups; }; SHAREABLE_STRUCT(sObjectSettings);