1
0
forked from 0ad/0ad

- Changed actor selection sets to CStr8 rather than CStrW.

- Added more comments in ScriptableComplex.h/inl explaining how they are
split up and when to #include the inl.

This was SVN commit r4180.
This commit is contained in:
Matei 2006-07-29 22:02:11 +00:00
parent efb9c3d7dd
commit 554b9e537e
20 changed files with 84 additions and 60 deletions

View File

@ -215,7 +215,7 @@ int CMapReader::ApplyData()
// loaded on demand)
}
std::set<CStrW> selections; // TODO: read from file
std::set<CStr8> 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<CStrW> selections; // TODO: read from file
std::set<CStr8> 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<CStrW> selections; // TODO: read from file
std::set<CStr8> selections; // TODO: read from file
CUnit* unit = g_UnitMan.CreateUnit(ActorName, NULL, selections);

View File

@ -214,7 +214,7 @@ bool CObjectBase::Load(const char* filename)
return true;
}
std::vector<u8> CObjectBase::CalculateVariationKey(const std::vector<std::set<CStrW> >& selections)
std::vector<u8> CObjectBase::CalculateVariationKey(const std::vector<std::set<CStr8> >& selections)
{
// (TODO: see CObjectManager::FindObjectVariation for an opportunity to
// call this function a bit less frequently)
@ -252,7 +252,7 @@ std::vector<u8> CObjectBase::CalculateVariationKey(const std::vector<std::set<CS
// Determine the first variant that matches the provided strings,
// starting with the highest priority selections set:
for (std::vector<std::set<CStrW> >::const_iterator selset = selections.begin(); selset < selections.end(); ++selset)
for (std::vector<std::set<CStr8> >::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<u8>&
return variation;
}
std::set<CStrW> CObjectBase::CalculateRandomVariation(const std::set<CStrW>& initialSelections)
std::set<CStr8> CObjectBase::CalculateRandomVariation(const std::set<CStr8>& initialSelections)
{
std::set<CStrW> selections = initialSelections;
std::set<CStr8> selections = initialSelections;
std::map<CStr, CStr> chosenProps;
@ -471,9 +471,9 @@ std::set<CStrW> CObjectBase::CalculateRandomVariation(const std::set<CStrW>& ini
CObjectBase* prop = g_ObjMan.FindObjectBase(it->second);
if (prop)
{
std::set<CStrW> propSelections = prop->CalculateRandomVariation(selections);
std::set<CStr8> propSelections = prop->CalculateRandomVariation(selections);
// selections = union(propSelections, selections)
std::set<CStrW> newSelections;
std::set<CStr8> newSelections;
std::set_union(propSelections.begin(), propSelections.end(),
selections.begin(), selections.end(),
std::inserter(newSelections, newSelections.begin()));
@ -484,9 +484,9 @@ std::set<CStrW> CObjectBase::CalculateRandomVariation(const std::set<CStrW>& ini
return selections;
}
std::vector<std::vector<CStrW> > CObjectBase::GetVariantGroups() const
std::vector<std::vector<CStr8> > CObjectBase::GetVariantGroups() const
{
std::vector<std::vector<CStrW> > groups;
std::vector<std::vector<CStr8> > groups;
// Queue of objects (main actor plus props (recursively)) to be processed
std::queue<const CObjectBase*> objectsQueue;
@ -509,7 +509,7 @@ std::vector<std::vector<CStrW> > 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<CStrW> group;
std::vector<CStr8> 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);

View File

@ -62,7 +62,7 @@ public:
// Get the variation key (indices of chosen variants from each group)
// based on the selection strings
std::vector<u8> CalculateVariationKey(const std::vector<std::set<CStrW> >& selections);
std::vector<u8> CalculateVariationKey(const std::vector<std::set<CStr8> >& selections);
// Get the final actor data, combining all selected variants
const Variation BuildVariation(const std::vector<u8>& 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<CStrW> CalculateRandomVariation(const std::set<CStrW>& initialSelections);
std::set<CStr8> CalculateRandomVariation(const std::set<CStr8>& 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<std::vector<CStrW> > GetVariantGroups() const;
std::vector<std::vector<CStr8> > GetVariantGroups() const;
bool Load(const char* filename);

View File

@ -38,7 +38,7 @@ CObjectEntry::~CObjectEntry()
}
bool CObjectEntry::BuildVariation(const std::vector<std::set<CStrW> >& selections, const std::vector<u8>& variationKey)
bool CObjectEntry::BuildVariation(const std::vector<std::set<CStr8> >& selections, const std::vector<u8>& variationKey)
{
CObjectBase::Variation variation = m_Base->BuildVariation(variationKey);

View File

@ -19,7 +19,7 @@ public:
~CObjectEntry();
// Construct this actor, using the specified variation selections
bool BuildVariation(const std::vector<std::set<CStrW> >& selections, const std::vector<u8>& variationKey);
bool BuildVariation(const std::vector<std::set<CStr8> >& selections, const std::vector<u8>& variationKey);
// Base actor. Contains all the things that don't change between
// different variations of the actor.

View File

@ -80,11 +80,11 @@ CObjectBase* CObjectManager::FindObjectBase(const char* objectname)
CObjectEntry* CObjectManager::FindObject(const char* objname)
{
std::vector<std::set<CStrW> > selections; // TODO - should this really be empty?
std::vector<std::set<CStr8> > selections; // TODO - should this really be empty?
return FindObjectVariation(objname, selections);
}
CObjectEntry* CObjectManager::FindObjectVariation(const char* objname, const std::vector<std::set<CStrW> >& selections)
CObjectEntry* CObjectManager::FindObjectVariation(const char* objname, const std::vector<std::set<CStr8> >& 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<std::set<CStrW> >& selections)
CObjectEntry* CObjectManager::FindObjectVariation(CObjectBase* base, const std::vector<std::set<CStr8> >& selections)
{
PROFILE( "object variation loading" );

View File

@ -68,8 +68,8 @@ public:
CObjectBase* FindObjectBase(const char* objname);
CObjectEntry* FindObjectVariation(const char* objname, const std::vector<std::set<CStrW> >& selections);
CObjectEntry* FindObjectVariation(CObjectBase* base, const std::vector<std::set<CStrW> >& selections);
CObjectEntry* FindObjectVariation(const char* objname, const std::vector<std::set<CStr8> >& selections);
CObjectEntry* FindObjectVariation(CObjectBase* base, const std::vector<std::set<CStr8> >& selections);
// Get all names, quite slowly. (Intended only for ScEd.)
void GetAllObjectNames(std::vector<CStr>& names);

View File

@ -7,7 +7,7 @@
#include "SkeletonAnim.h"
#include "SkeletonAnimDef.h"
CUnit::CUnit(CObjectEntry* object, CEntity* entity, const std::set<CStrW>& actorSelections)
CUnit::CUnit(CObjectEntry* object, CEntity* entity, const std::set<CStr8>& 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<CStrW>& selections)
void CUnit::SetActorSelections(const std::set<CStr8>& selections)
{
m_ActorSelections = selections;
ReloadObject();
@ -138,7 +138,7 @@ void CUnit::SetActorSelections(const std::set<CStrW>& selections)
void CUnit::ReloadObject()
{
std::vector<std::set<CStrW> > selections;
std::vector<std::set<CStr8> > selections;
// TODO: push world selections (seasons, etc) (and reload whenever they're changed)
selections.push_back(m_EntitySelections);
selections.push_back(m_ActorSelections);

View File

@ -15,7 +15,7 @@ class CStrW;
class CUnit
{
public:
CUnit(CObjectEntry* object, CEntity* entity, const std::set<CStrW>& actorSelections);
CUnit(CObjectEntry* object, CEntity* entity, const std::set<CStr8>& actorSelections);
// destructor
~CUnit();
@ -57,9 +57,9 @@ public:
int GetID() const { return m_ID; }
void SetID(int id) { m_ID = id; }
const std::set<CStrW>& GetActorSelections() const { return m_ActorSelections; }
const std::set<CStr8>& GetActorSelections() const { return m_ActorSelections; }
void SetActorSelections(const std::set<CStrW>& selections);
void SetActorSelections(const std::set<CStr8>& selections);
private:
// object from which unit was created
@ -76,9 +76,9 @@ private:
int m_ID;
// actor-level selections for this unit
std::set<CStrW> m_ActorSelections;
std::set<CStr8> m_ActorSelections;
// entity-level selections for this unit
std::set<CStrW> m_EntitySelections;
std::set<CStr8> m_EntitySelections;
void ReloadObject();
};

View File

@ -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<CStrW>& selections)
CUnit* CUnitManager::CreateUnit(const CStr& actorName, CEntity* entity, const std::set<CStr8>& selections)
{
CObjectBase* base = g_ObjMan.FindObjectBase(actorName);
if (! base)
return NULL;
std::set<CStrW> actorSelections = base->CalculateRandomVariation(selections);
std::set<CStr8> actorSelections = base->CalculateRandomVariation(selections);
std::vector<std::set<CStrW> > selectionsVec;
std::vector<std::set<CStr8> > selectionsVec;
selectionsVec.push_back(actorSelections);
CObjectEntry* obj = g_ObjMan.FindObjectVariation(base, selectionsVec);

View File

@ -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<CStrW>& selections);
CUnit* CreateUnit(const CStr& actorName, CEntity* entity, const std::set<CStr8>& selections);
// return the units
const std::vector<CUnit*>& GetUnits() const { return m_Units; }

View File

@ -1348,7 +1348,7 @@ bool CBuildingPlacer::activate(CStrW& templateName)
// m_actor
CStr actorName ( m_template->m_actorName ); // convert CStrW->CStr8
std::set<CStrW> selections;
std::set<CStr8> selections;
m_actor = g_UnitMan.CreateUnit( actorName, 0, selections );
m_actor->SetPlayerID(g_Game->GetLocalPlayer()->GetPlayerID());

View File

@ -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"

View File

@ -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

View File

@ -37,7 +37,7 @@ extern int g_xres, g_yres;
#include <algorithm>
using namespace std;
CEntity::CEntity( CEntityTemplate* base, CVector3D position, float orientation, const std::set<CStrW>& actorSelections, const CStrW* building )
CEntity::CEntity( CEntityTemplate* base, CVector3D position, float orientation, const std::set<CStr8>& actorSelections, const CStrW* building )
{
ent_flags = 0;
@ -1588,7 +1588,7 @@ JSBool CEntity::Construct( JSContext* cx, JSObject* UNUSED(obj), uint argc, jsva
}
}
std::set<CStrW> selections; // TODO: let scripts specify selections?
std::set<CStr8> selections; // TODO: let scripts specify selections?
HEntity handle = g_EntityManager.create( baseEntity, position, orientation, selections );
handle->SetPlayer( player );
handle->Initialize();

View File

@ -215,7 +215,7 @@ public:
CScriptObject m_EventHandlers[EVENT_LAST];
CUnit* m_actor;
std::set<CStrW> m_actorSelections;
std::set<CStr8> 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<CStrW>& actorSelections, const CStrW* building = 0 );
CEntity( CEntityTemplate* base, CVector3D position, float orientation, const std::set<CStr8>& actorSelections, const CStrW* building = 0 );
uint processGotoHelper( CEntityOrder* current, size_t timestep_milli, HEntity& collide );

View File

@ -75,7 +75,7 @@ void CEntityManager::deleteAll()
m_extant = true;
}
HEntity CEntityManager::create( CEntityTemplate* base, CVector3D position, float orientation, const std::set<CStrW>& actorSelections,
HEntity CEntityManager::create( CEntityTemplate* base, CVector3D position, float orientation, const std::set<CStr8>& 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<CStrW> selections;
std::set<CStr8> 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<CStrW> selections;
std::set<CStr8> selections;
if( base->m_foundation == L"" )
return create( base, position, orientation, selections ); // Entity has no foundation, so just create it

View File

@ -56,7 +56,7 @@ public:
~CEntityManager();
HEntity create( CEntityTemplate* base, CVector3D position, float orientation,
const std::set<CStrW>& actorSelections, const CStrW* building = 0 );
const std::set<CStr8>& actorSelections, const CStrW* building = 0 );
HEntity create( const CStrW& templateName, CPlayer* player, CVector3D position,
float orientation, const CStrW* building = 0 );

View File

@ -114,18 +114,18 @@ QUERYHANDLER(GetObjectSettings)
settings.player = unit->GetPlayerID();
// Get the unit's possible variants and selected variants
std::vector<std::vector<CStrW> > groups = unit->GetObject()->m_Base->GetVariantGroups();
const std::set<CStrW>& selections = unit->GetActorSelections();
std::vector<std::vector<CStr8> > groups = unit->GetObject()->m_Base->GetVariantGroups();
const std::set<CStr8>& selections = unit->GetActorSelections();
// Iterate over variant groups
std::vector<std::vector<std::wstring> > variantgroups;
std::set<std::wstring> selections_set;
std::vector<std::vector<std::string> > variantgroups;
std::set<std::string> selections_set;
variantgroups.reserve(groups.size());
for (size_t i = 0; i < groups.size(); ++i)
{
// Copy variants into output structure
std::vector<std::wstring> group;
std::vector<std::string> group;
group.reserve(groups[i].size());
int choice = -1;
@ -149,14 +149,14 @@ QUERYHANDLER(GetObjectSettings)
}
settings.variantgroups = variantgroups;
settings.selections = std::vector<std::wstring> (selections_set.begin(), selections_set.end()); // convert set->vector
settings.selections = std::vector<std::string> (selections_set.begin(), selections_set.end()); // convert set->vector
msg->settings = settings;
}
BEGIN_COMMAND(SetObjectSettings)
{
int m_PlayerOld, m_PlayerNew;
std::set<CStrW> m_SelectionsOld, m_SelectionsNew;
std::set<CStr8> m_SelectionsOld, m_SelectionsNew;
void Do()
{
@ -170,9 +170,9 @@ BEGIN_COMMAND(SetObjectSettings)
m_SelectionsOld = unit->GetActorSelections();
std::vector<std::wstring> selections = *settings.selections;
std::vector<std::string> selections = *settings.selections;
copy(selections.begin(), selections.end(),
std::insert_iterator<std::set<CStrW> >(m_SelectionsNew, m_SelectionsNew.begin()));
std::insert_iterator<std::set<CStr8> >(m_SelectionsNew, m_SelectionsNew.begin()));
Redo();
}
@ -262,7 +262,7 @@ MESSAGEHANDLER(ObjectPreview)
CStrW name;
if (ParseObjectName(*msg->id, isEntity, name))
{
std::set<CStrW> selections; // TODO: get selections from user
std::set<CStr8> 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<CStrW> selections;
std::set<CStr8> selections;
if (isEntity)
{

View File

@ -114,12 +114,12 @@ QUERY(GetObjectsList,
struct sObjectSettings
{
Shareable<int> player;
Shareable<std::vector<std::wstring> > selections;
Shareable<std::vector<std::string> > selections;
// Some settings are immutable and therefore are ignored (and should be left
// empty) when passed from the editor to the game:
Shareable<std::vector<std::vector<std::wstring> > > variantgroups;
Shareable<std::vector<std::vector<std::string> > > variantgroups;
};
SHAREABLE_STRUCT(sObjectSettings);