1
0
forked from 0ad/0ad

Some cleanup - renamed CBaseEntity to CEntityTemplate, and removed JSInterface_BaseEntity.h and JSInterface_Entity.h (which were unused).

This was SVN commit r4091.
This commit is contained in:
Matei 2006-07-13 03:29:33 +00:00
parent eb467745b3
commit a56ec5bdcd
29 changed files with 174 additions and 240 deletions

View File

@ -7,8 +7,8 @@
#include "ps/Game.h" #include "ps/Game.h"
#include "ObjectManager.h" #include "ObjectManager.h"
#include "simulation/Entity.h" #include "simulation/Entity.h"
#include "simulation/BaseEntity.h" #include "simulation/EntityTemplate.h"
#include "simulation/BaseEntityCollection.h" #include "simulation/EntityTemplateCollection.h"
#include "simulation/EntityManager.h" #include "simulation/EntityManager.h"
#include "ps/CLogger.h" #include "ps/CLogger.h"
#include "maths/MathUtil.h" #include "maths/MathUtil.h"
@ -533,7 +533,7 @@ int CXMLReader::ReadEntities(XMBElement parent, double end_time)
debug_warn("Invalid map XML data"); debug_warn("Invalid map XML data");
} }
CBaseEntity* base = g_EntityTemplateCollection.getTemplate( TemplateName, g_Game->GetPlayer(PlayerID) ); CEntityTemplate* base = g_EntityTemplateCollection.getTemplate( TemplateName, g_Game->GetPlayer(PlayerID) );
if (! base) if (! base)
LOG(ERROR, LOG_CATEGORY, "Failed to load entity template '%ls'", TemplateName.c_str()); LOG(ERROR, LOG_CATEGORY, "Failed to load entity template '%ls'", TemplateName.c_str());
else else

View File

@ -24,8 +24,8 @@
#include "ps/XML/XMLWriter.h" #include "ps/XML/XMLWriter.h"
#include "renderer/SkyManager.h" #include "renderer/SkyManager.h"
#include "renderer/WaterManager.h" #include "renderer/WaterManager.h"
#include "simulation/BaseEntity.h" #include "simulation/EntityTemplate.h"
#include "simulation/BaseEntityCollection.h" #include "simulation/EntityTemplateCollection.h"
#include "simulation/Entity.h" #include "simulation/Entity.h"
/////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////

View File

@ -10,7 +10,7 @@
#include "ObjectEntry.h" #include "ObjectEntry.h"
#include "simulation/Entity.h" #include "simulation/Entity.h"
#include "simulation/EntityManager.h" #include "simulation/EntityManager.h"
#include "simulation/BaseEntity.h" #include "simulation/EntityTemplate.h"
#include "ps/Game.h" #include "ps/Game.h"
#include "Model.h" #include "Model.h"
#include "Unit.h" #include "Unit.h"

View File

@ -8,7 +8,7 @@
#include "ObjectBase.h" #include "ObjectBase.h"
class CObjectEntry; class CObjectEntry;
class CBaseEntity; class CEntityTemplate;
class CMatrix3D; class CMatrix3D;
// access to sole CObjectManager object // access to sole CObjectManager object

View File

@ -46,7 +46,7 @@
#include "renderer/VertexBufferManager.h" #include "renderer/VertexBufferManager.h"
#include "maths/MathUtil.h" #include "maths/MathUtil.h"
#include "simulation/BaseEntityCollection.h" #include "simulation/EntityTemplateCollection.h"
#include "simulation/FormationCollection.h" #include "simulation/FormationCollection.h"
#include "simulation/TechnologyCollection.h" #include "simulation/TechnologyCollection.h"
#include "simulation/Entity.h" #include "simulation/Entity.h"
@ -59,8 +59,6 @@
#include "scripting/ScriptingHost.h" #include "scripting/ScriptingHost.h"
#include "scripting/GameEvents.h" #include "scripting/GameEvents.h"
#include "simulation/scripting/JSInterface_Entity.h"
#include "simulation/scripting/JSInterface_BaseEntity.h"
#include "maths/scripting/JSInterface_Vector3D.h" #include "maths/scripting/JSInterface_Vector3D.h"
#include "graphics/scripting/JSInterface_Camera.h" #include "graphics/scripting/JSInterface_Camera.h"
#include "ps/scripting/JSInterface_Selection.h" #include "ps/scripting/JSInterface_Selection.h"
@ -489,7 +487,7 @@ static void InitScripting()
// Register the JavaScript interfaces with the runtime // Register the JavaScript interfaces with the runtime
CEntity::ScriptingInit(); CEntity::ScriptingInit();
CBaseEntity::ScriptingInit(); CEntityTemplate::ScriptingInit();
JSI_Sound::ScriptingInit(); JSI_Sound::ScriptingInit();
CProfileNode::ScriptingInit(); CProfileNode::ScriptingInit();
@ -1011,7 +1009,7 @@ void Init(int argc, char* argv[], uint flags)
{ {
TIMER("Init_entitiessection"); TIMER("Init_entitiessection");
// This needs to be done after the renderer has loaded all its actors... // This needs to be done after the renderer has loaded all its actors...
new CBaseEntityCollection; new CEntityTemplateCollection;
new CFormationCollection; new CFormationCollection;
new CTechnologyCollection; new CTechnologyCollection;
g_EntityFormationCollection.loadTemplates(); g_EntityFormationCollection.loadTemplates();

View File

@ -25,7 +25,7 @@
#include "ps/World.h" #include "ps/World.h"
#include "renderer/Renderer.h" #include "renderer/Renderer.h"
#include "scripting/GameEvents.h" #include "scripting/GameEvents.h"
#include "simulation/BaseEntityCollection.h" #include "simulation/EntityTemplateCollection.h"
#include "simulation/BoundingObjects.h" #include "simulation/BoundingObjects.h"
#include "simulation/Collision.h" #include "simulation/Collision.h"
#include "simulation/Entity.h" #include "simulation/Entity.h"
@ -1276,7 +1276,7 @@ bool isMouseoverType( CEntity* ev, void* UNUSED(userdata) )
std::vector<SMouseoverFader>::iterator it; std::vector<SMouseoverFader>::iterator it;
for( it = g_Mouseover.m_mouseover.begin(); it < g_Mouseover.m_mouseover.end(); it++ ) for( it = g_Mouseover.m_mouseover.begin(); it < g_Mouseover.m_mouseover.end(); it++ )
{ {
if( it->isActive && ( (CBaseEntity*)it->entity->m_base == (CBaseEntity*)ev->m_base ) if( it->isActive && ( (CEntityTemplate*)it->entity->m_base == (CEntityTemplate*)ev->m_base )
&& ( it->entity->GetPlayer() == ev->GetPlayer() ) ) && ( it->entity->GetPlayer() == ev->GetPlayer() ) )
return( true ); return( true );
} }

View File

@ -16,7 +16,7 @@
class CVector3D; class CVector3D;
class CUnit; class CUnit;
class CBaseEntity; class CEntityTemplate;
class CBoundingObject; class CBoundingObject;
#define MAX_BOOKMARKS 10 #define MAX_BOOKMARKS 10
@ -155,7 +155,7 @@ struct CBuildingPlacer : public Singleton<CBuildingPlacer>
} }
CStrW m_templateName; CStrW m_templateName;
CBaseEntity* m_template; CEntityTemplate* m_template;
bool m_active; bool m_active;
bool m_clicked; bool m_clicked;
bool m_dragged; bool m_dragged;

View File

@ -17,7 +17,7 @@
#include "ps/LoaderThunks.h" #include "ps/LoaderThunks.h"
#include "ps/World.h" #include "ps/World.h"
#include "renderer/Renderer.h" #include "renderer/Renderer.h"
#include "simulation/BaseEntityCollection.h" #include "simulation/EntityTemplateCollection.h"
#include "simulation/EntityManager.h" #include "simulation/EntityManager.h"
#include "simulation/EntityManager.h" #include "simulation/EntityManager.h"
#include "simulation/LOSManager.h" #include "simulation/LOSManager.h"
@ -44,7 +44,7 @@ CWorld::CWorld(CGame *pGame):
void CWorld::Initialize(CGameAttributes *pAttribs) void CWorld::Initialize(CGameAttributes *pAttribs)
{ {
// TODO: Find a better way of handling these global things // TODO: Find a better way of handling these global things
ONCE(RegMemFun(CBaseEntityCollection::GetSingletonPtr(), &CBaseEntityCollection::loadTemplates, L"LoadTemplates", 15)); ONCE(RegMemFun(CEntityTemplateCollection::GetSingletonPtr(), &CEntityTemplateCollection::loadTemplates, L"LoadTemplates", 15));
// Load the map, if one was specified // Load the map, if one was specified
if (pAttribs->m_MapFile.Length()) if (pAttribs->m_MapFile.Length())

View File

@ -48,7 +48,7 @@ public:
before = obj; before = obj;
} }
// Set target that will receive each event after it is processed. // Set target that will receive each event after it is processed.
// used by Entity and BaseEntity. // used by Entity and EntityTemplate.
inline void SetNextObject( IEventTarget* obj ) inline void SetNextObject( IEventTarget* obj )
{ {
after = obj; after = obj;

View File

@ -5,7 +5,7 @@
#include "maths/scripting/JSInterface_Vector3D.h" #include "maths/scripting/JSInterface_Vector3D.h"
#include "ps/Parser.h" #include "ps/Parser.h"
#include "ps/Player.h" #include "ps/Player.h"
#include "simulation/BaseEntity.h" #include "simulation/EntityTemplate.h"
#include "lib/sysdep/sysdep.h" // finite #include "lib/sysdep/sysdep.h" // finite
#include <cfloat> #include <cfloat>
@ -38,20 +38,20 @@ template<> JSObject* ToScript<CPlayer*>( CPlayer** Native )
return( ToScript<CPlayer>( *Native ) ); return( ToScript<CPlayer>( *Native ) );
} }
// CBaseEntity* // CEntityTemplate*
template<> bool ToPrimitive<CBaseEntity*>( JSContext* cx, jsval v, CBaseEntity*& Storage ) template<> bool ToPrimitive<CEntityTemplate*>( JSContext* cx, jsval v, CEntityTemplate*& Storage )
{ {
if( !JSVAL_IS_OBJECT( v ) || ( v == JSVAL_NULL ) ) return( false ); if( !JSVAL_IS_OBJECT( v ) || ( v == JSVAL_NULL ) ) return( false );
CBaseEntity* Data = (CBaseEntity*)JS_GetInstancePrivate( cx, JSVAL_TO_OBJECT( v ), &CBaseEntity::JSI_class, NULL ); CEntityTemplate* Data = (CEntityTemplate*)JS_GetInstancePrivate( cx, JSVAL_TO_OBJECT( v ), &CEntityTemplate::JSI_class, NULL );
if( !Data ) return( false ); if( !Data ) return( false );
Storage = Data; Storage = Data;
return( true ); return( true );
} }
template<> JSObject* ToScript<CBaseEntity*>( CBaseEntity** Native ) template<> JSObject* ToScript<CEntityTemplate*>( CEntityTemplate** Native )
{ {
return( ToScript<CBaseEntity>( *Native ) ); return( ToScript<CEntityTemplate>( *Native ) );
} }
// CVector3D // CVector3D

View File

@ -8,7 +8,7 @@
class CEntity; class CEntity;
class HEntity; class HEntity;
class CBaseEntity; class CEntityTemplate;
class CStrW; class CStrW;
class CScriptObject; class CScriptObject;
class CObjectEntry; class CObjectEntry;
@ -95,9 +95,9 @@ template<> CVector3D* ToNative<CVector3D>( JSContext* cx, JSObject* obj );
template<> JSObject* ToScript<CVector3D>( CVector3D* Native ); template<> JSObject* ToScript<CVector3D>( CVector3D* Native );
template<> jsval ToJSVal<CVector3D>( const CVector3D& Native ); template<> jsval ToJSVal<CVector3D>( const CVector3D& Native );
// CBaseEntity // CEntityTemplate
template<> bool ToPrimitive<CBaseEntity*>( JSContext* cx, jsval v, CBaseEntity*& Storage ); template<> bool ToPrimitive<CEntityTemplate*>( JSContext* cx, jsval v, CEntityTemplate*& Storage );
template<> JSObject* ToScript<CBaseEntity*>( CBaseEntity** Native ); template<> JSObject* ToScript<CEntityTemplate*>( CEntityTemplate** Native );
// CObjectEntry // CObjectEntry
template<> bool ToPrimitive<CObjectEntry>( JSContext* cx, jsval v, CObjectEntry*& Storage ); template<> bool ToPrimitive<CObjectEntry>( JSContext* cx, jsval v, CObjectEntry*& Storage );

View File

@ -33,7 +33,7 @@
#include "renderer/Renderer.h" #include "renderer/Renderer.h"
#include "renderer/SkyManager.h" #include "renderer/SkyManager.h"
#include "renderer/WaterManager.h" #include "renderer/WaterManager.h"
#include "simulation/BaseEntityCollection.h" #include "simulation/EntityTemplateCollection.h"
#include "simulation/TechnologyCollection.h" #include "simulation/TechnologyCollection.h"
#include "simulation/Entity.h" #include "simulation/Entity.h"
#include "simulation/EntityFormation.h" #include "simulation/EntityFormation.h"
@ -43,8 +43,6 @@
#include "simulation/LOSManager.h" #include "simulation/LOSManager.h"
#include "simulation/Scheduler.h" #include "simulation/Scheduler.h"
#include "simulation/Simulation.h" #include "simulation/Simulation.h"
#include "simulation/scripting/JSInterface_BaseEntity.h"
#include "simulation/scripting/JSInterface_Entity.h"
#ifndef NO_GUI #ifndef NO_GUI
# include "gui/scripting/JSInterface_IGUIObject.h" # include "gui/scripting/JSInterface_IGUIObject.h"
@ -192,7 +190,7 @@ JSBool getEntityTemplate( JSContext* cx, JSObject*, uint argc, jsval* argv, jsva
return( JS_TRUE ); return( JS_TRUE );
} }
CBaseEntity* v = g_EntityTemplateCollection.getTemplate( templateName, player ); CEntityTemplate* v = g_EntityTemplateCollection.getTemplate( templateName, player );
if( !v ) if( !v )
{ {
JS_ReportError( cx, "No such template: %s", CStr8(templateName).c_str() ); JS_ReportError( cx, "No such template: %s", CStr8(templateName).c_str() );

View File

@ -6,7 +6,7 @@
#include "Entity.h" #include "Entity.h"
#include "EntityManager.h" #include "EntityManager.h"
#include "BaseEntityCollection.h" #include "EntityTemplateCollection.h"
#include "graphics/Unit.h" #include "graphics/Unit.h"
#include "Aura.h" #include "Aura.h"
#include "ProductionQueue.h" #include "ProductionQueue.h"
@ -35,7 +35,7 @@ extern int g_xres, g_yres;
#include <algorithm> #include <algorithm>
using namespace std; using namespace std;
CEntity::CEntity( CBaseEntity* base, CVector3D position, float orientation, const std::set<CStrW>& actorSelections, CStrW building ) CEntity::CEntity( CEntityTemplate* base, CVector3D position, float orientation, const std::set<CStrW>& actorSelections, CStrW building )
{ {
ent_flags = 0; ent_flags = 0;
@ -1395,9 +1395,9 @@ void CEntity::ScriptingInit()
AddMethod<jsval, &CEntity::GetRallyPoint>("getRallyPoint", 0 ); AddMethod<jsval, &CEntity::GetRallyPoint>("getRallyPoint", 0 );
AddClassProperty( L"traits.id.classes", (GetFn)&CEntity::getClassSet, (SetFn)&CEntity::setClassSet ); AddClassProperty( L"traits.id.classes", (GetFn)&CEntity::getClassSet, (SetFn)&CEntity::setClassSet );
AddClassProperty( L"template", (CBaseEntity* CEntity::*)&CEntity::m_base, false, (NotifyFn)&CEntity::loadBase ); AddClassProperty( L"template", (CEntityTemplate* CEntity::*)&CEntity::m_base, false, (NotifyFn)&CEntity::loadBase );
/* Anything inherited property MUST be added to BaseEntity.cpp as well */ /* Anything inherited property MUST be added to EntityTemplate.cpp as well */
AddClassProperty( L"actions.move.speed_curr", &CEntity::m_speed ); AddClassProperty( L"actions.move.speed_curr", &CEntity::m_speed );
AddClassProperty( L"actions.move.run.speed", &CEntity::m_runSpeed ); AddClassProperty( L"actions.move.run.speed", &CEntity::m_runSpeed );
@ -1468,14 +1468,14 @@ JSBool CEntity::Construct( JSContext* cx, JSObject* UNUSED(obj), uint argc, jsva
CVector3D position; CVector3D position;
float orientation = (float)( PI * ( (double)( rand() & 0x7fff ) / (double)0x4000 ) ); float orientation = (float)( PI * ( (double)( rand() & 0x7fff ) / (double)0x4000 ) );
JSObject* jsBaseEntity = JSVAL_TO_OBJECT( argv[0] ); JSObject* jsEntityTemplate = JSVAL_TO_OBJECT( argv[0] );
CStrW templateName; CStrW templateName;
CPlayer* player = g_Game->GetPlayer( 0 ); CPlayer* player = g_Game->GetPlayer( 0 );
CBaseEntity* baseEntity = NULL; CEntityTemplate* baseEntity = NULL;
if( JSVAL_IS_OBJECT( argv[0] ) ) // only set baseEntity if jsBaseEntity is a valid object if( JSVAL_IS_OBJECT( argv[0] ) ) // only set baseEntity if jsEntityTemplate is a valid object
baseEntity = ToNative<CBaseEntity>( cx, jsBaseEntity ); baseEntity = ToNative<CEntityTemplate>( cx, jsEntityTemplate );
if( !baseEntity ) if( !baseEntity )
{ {
@ -1719,7 +1719,7 @@ jsval CEntity::GetSpawnPoint( JSContext* UNUSED(cx), uintN argc, jsval* argv )
float spawn_clearance = 2.0f; float spawn_clearance = 2.0f;
if( argc >= 1 ) if( argc >= 1 )
{ {
CBaseEntity* be = ToNative<CBaseEntity>( argv[0] ); CEntityTemplate* be = ToNative<CEntityTemplate>( argv[0] );
if( be ) if( be )
{ {
switch( be->m_bound_type ) switch( be->m_bound_type )

View File

@ -37,13 +37,13 @@
#include "EntitySupport.h" #include "EntitySupport.h"
#include "scripting/DOMEvent.h" #include "scripting/DOMEvent.h"
// JW: must be pulled in because CEntity no longer mirrors CBaseEntity exactly. // JW: must be pulled in because CEntity no longer mirrors CEntityTemplate exactly.
// some fields have been moved out of CEntity and are accessed via m_base, // some fields have been moved out of CEntity and are accessed via m_base,
// so CBaseEntity must be fully defined. // so CEntityTemplate must be fully defined.
#include "BaseEntity.h" #include "EntityTemplate.h"
class CAura; class CAura;
//class CBaseEntity; // see comment above //class CEntityTemplate; // see comment above
class CBoundingObject; class CBoundingObject;
class CPlayer; class CPlayer;
class CProductionQueue; class CProductionQueue;
@ -94,7 +94,7 @@ public:
CPlayer* m_player; CPlayer* m_player;
// Intrinsic properties // Intrinsic properties
CBaseEntity* m_base; CEntityTemplate* m_base;
// The class types this entity has // The class types this entity has
SClassSet m_classes; SClassSet m_classes;
@ -234,7 +234,7 @@ public:
std::vector<bool> m_sectorValues; std::vector<bool> m_sectorValues;
/* JW: these have all been 'moved' (1) into BaseEntity: /* JW: these have all been 'moved' (1) into EntityTemplate:
1: were already present there, just removed from here 1: were already present there, just removed from here
int m_sectorDivs; int m_sectorDivs;
@ -274,7 +274,7 @@ public:
private: private:
CEntity( CBaseEntity* base, CVector3D position, float orientation, const std::set<CStrW>& actorSelections, CStrW building = L"" ); CEntity( CEntityTemplate* base, CVector3D position, float orientation, const std::set<CStrW>& actorSelections, CStrW building = L"" );
uint processGotoHelper( CEntityOrder* current, size_t timestep_milli, HEntity& collide ); uint processGotoHelper( CEntityOrder* current, size_t timestep_milli, HEntity& collide );

View File

@ -2,7 +2,7 @@
#include "precompiled.h" #include "precompiled.h"
#include "EntityManager.h" #include "EntityManager.h"
#include "BaseEntityCollection.h" #include "EntityTemplateCollection.h"
#include "ps/ConfigDB.h" #include "ps/ConfigDB.h"
#include "ps/Profile.h" #include "ps/Profile.h"
#include "graphics/Terrain.h" #include "graphics/Terrain.h"
@ -70,7 +70,7 @@ void CEntityManager::deleteAll()
m_extant = true; m_extant = true;
} }
HEntity CEntityManager::create( CBaseEntity* base, CVector3D position, float orientation, const std::set<CStrW>& actorSelections ) HEntity CEntityManager::create( CEntityTemplate* base, CVector3D position, float orientation, const std::set<CStrW>& actorSelections )
{ {
debug_assert( base ); debug_assert( base );
if( !base ) if( !base )
@ -95,7 +95,7 @@ HEntity CEntityManager::create( CBaseEntity* base, CVector3D position, float ori
HEntity CEntityManager::create( CStrW templateName, CPlayer* player, CVector3D position, float orientation ) HEntity CEntityManager::create( CStrW templateName, CPlayer* player, CVector3D position, float orientation )
{ {
CBaseEntity* base = g_EntityTemplateCollection.getTemplate( templateName, player ); CEntityTemplate* base = g_EntityTemplateCollection.getTemplate( templateName, player );
debug_assert( base ); debug_assert( base );
if( !base ) if( !base )
return HEntity(); return HEntity();
@ -107,7 +107,7 @@ HEntity CEntityManager::create( CStrW templateName, CPlayer* player, CVector3D p
HEntity CEntityManager::createFoundation( CStrW templateName, CPlayer* player, CVector3D position, float orientation ) HEntity CEntityManager::createFoundation( CStrW templateName, CPlayer* player, CVector3D position, float orientation )
{ {
CBaseEntity* base = g_EntityTemplateCollection.getTemplate( templateName, player ); CEntityTemplate* base = g_EntityTemplateCollection.getTemplate( templateName, player );
debug_assert( base ); debug_assert( base );
if( !base ) if( !base )
return HEntity(); return HEntity();
@ -117,7 +117,7 @@ HEntity CEntityManager::createFoundation( CStrW templateName, CPlayer* player, C
if( base->m_foundation == L"" ) if( base->m_foundation == L"" )
return create( base, position, orientation, selections ); // Entity has no foundation, so just create it return create( base, position, orientation, selections ); // Entity has no foundation, so just create it
CBaseEntity* foundation = g_EntityTemplateCollection.getTemplate( base->m_foundation ); CEntityTemplate* foundation = g_EntityTemplateCollection.getTemplate( base->m_foundation );
debug_assert( foundation ); debug_assert( foundation );
if( !foundation ) if( !foundation )
return HEntity(); return HEntity();

View File

@ -27,7 +27,7 @@
#include "ps/CStr.h" #include "ps/CStr.h"
#include "maths/Vector3D.h" #include "maths/Vector3D.h"
class CBaseEntity; class CEntityTemplate;
#define MAX_HANDLES 4096 #define MAX_HANDLES 4096
@ -53,7 +53,7 @@ public:
CEntityManager(); CEntityManager();
~CEntityManager(); ~CEntityManager();
HEntity create( CBaseEntity* base, CVector3D position, float orientation, HEntity create( CEntityTemplate* base, CVector3D position, float orientation,
const std::set<CStrW>& actorSelections ); const std::set<CStrW>& actorSelections );
HEntity create( CStrW templateName, CPlayer* player, CVector3D position, HEntity create( CStrW templateName, CPlayer* player, CVector3D position,

View File

@ -2,8 +2,8 @@
/* /*
#include "EntityProperties.h" #include "EntityProperties.h"
#include "BaseEntityCollection.h" #include "EntityTemplateCollection.h"
#include "simulation/scripting/JSInterface_BaseEntity.h" #include "simulation/scripting/JSInterface_EntityTemplate.h"
#undef new // to avoid confusing warnings #undef new // to avoid confusing warnings
@ -180,20 +180,20 @@ jsval CBoundObjectProperty<CScriptObject>::tojsval()
//-- //--
void CBoundProperty<CBaseEntity*>::set( const jsval value ) void CBoundProperty<CEntityTemplate*>::set( const jsval value )
{ {
JSObject* baseEntity = JSVAL_TO_OBJECT( value ); JSObject* baseEntity = JSVAL_TO_OBJECT( value );
CBaseEntity* base = NULL; CEntityTemplate* base = NULL;
if( JSVAL_IS_OBJECT( value ) && ( base = ToNative<CBaseEntity>( g_ScriptingHost.GetContext(), baseEntity ) ) ) if( JSVAL_IS_OBJECT( value ) && ( base = ToNative<CEntityTemplate>( g_ScriptingHost.GetContext(), baseEntity ) ) )
{ {
m_data = base; m_data = base;
} }
else else
JS_ReportError( g_ScriptingHost.getContext(), "[BaseEntity] Invalid reference" ); JS_ReportError( g_ScriptingHost.getContext(), "[EntityTemplate] Invalid reference" );
} }
jsval CBoundProperty<CBaseEntity*>::tojsval() jsval CBoundProperty<CEntityTemplate*>::tojsval()
{ {
JSObject* baseEntity = m_data->GetScript(); JSObject* baseEntity = m_data->GetScript();
return( OBJECT_TO_JSVAL( baseEntity ) ); return( OBJECT_TO_JSVAL( baseEntity ) );

View File

@ -4,7 +4,7 @@
// //
// Extended properties table, primarily intended for data-inheritable properties and those defined by JavaScript functions. // Extended properties table, primarily intended for data-inheritable properties and those defined by JavaScript functions.
// //
// Usage: These properties are accessed via functions in CEntity/CBaseEntity // Usage: These properties are accessed via functions in CEntity/CEntityTemplate
// //
// TODO: Fix the silent failures of the conversion functions: need to work out what to do in these cases. // TODO: Fix the silent failures of the conversion functions: need to work out what to do in these cases.
@ -27,7 +27,7 @@
class IBoundPropertyOwner; class IBoundPropertyOwner;
class CBaseEntity; class CEntityTemplate;
// Property interface // Property interface
@ -125,28 +125,28 @@ public:
// And an explicit one: // And an explicit one:
template<> class CBoundProperty<CBaseEntity*> : public IBoundProperty template<> class CBoundProperty<CEntityTemplate*> : public IBoundProperty
{ {
CBaseEntity* m_data; CEntityTemplate* m_data;
public: public:
CBoundProperty() { m_data = NULL; } CBoundProperty() { m_data = NULL; }
CBoundProperty( CBaseEntity* copy ) { m_data = copy; } CBoundProperty( CEntityTemplate* copy ) { m_data = copy; }
operator CBaseEntity*&() { return( m_data ); } operator CEntityTemplate*&() { return( m_data ); }
operator CBaseEntity*() const { return( m_data ); } operator CEntityTemplate*() const { return( m_data ); }
CBaseEntity*& operator=( CBaseEntity* copy ) { return( m_data = copy ); } CEntityTemplate*& operator=( CEntityTemplate* copy ) { return( m_data = copy ); }
// Standard pointerish things // Standard pointerish things
CBaseEntity& operator*() { return( *m_data ); } CEntityTemplate& operator*() { return( *m_data ); }
CBaseEntity* operator->() { return( m_data ); } CEntityTemplate* operator->() { return( m_data ); }
void set( const jsval value ); void set( const jsval value );
jsval tojsval(); jsval tojsval();
bool rebuild( IBoundProperty* parent, bool triggerFn = true ) bool rebuild( IBoundProperty* parent, bool triggerFn = true )
{ {
return( false ); // Can't inherit a CBaseEntity* return( false ); // Can't inherit a CEntityTemplate*
} }
}; };

View File

@ -3,7 +3,7 @@
#include "precompiled.h" #include "precompiled.h"
#include "Entity.h" #include "Entity.h"
#include "BaseEntity.h" #include "EntityTemplate.h"
#include "graphics/Model.h" #include "graphics/Model.h"
#include "graphics/ObjectEntry.h" #include "graphics/ObjectEntry.h"
#include "graphics/SkeletonAnim.h" #include "graphics/SkeletonAnim.h"

View File

@ -1,7 +1,7 @@
#include "precompiled.h" #include "precompiled.h"
#include "BaseEntity.h" #include "EntityTemplate.h"
#include "BaseEntityCollection.h" #include "EntityTemplateCollection.h"
#include "graphics/ObjectManager.h" #include "graphics/ObjectManager.h"
#include "ps/CStr.h" #include "ps/CStr.h"
#include "ps/Player.h" #include "ps/Player.h"
@ -11,9 +11,9 @@
#include "ps/CLogger.h" #include "ps/CLogger.h"
#define LOG_CATEGORY "entity" #define LOG_CATEGORY "entity"
STL_HASH_SET<CStr, CStr_hash_compare> CBaseEntity::scriptsLoaded; STL_HASH_SET<CStr, CStr_hash_compare> CEntityTemplate::scriptsLoaded;
CBaseEntity::CBaseEntity( CPlayer* player ) CEntityTemplate::CEntityTemplate( CPlayer* player )
{ {
m_player = player; m_player = player;
m_base = NULL; m_base = NULL;
@ -48,7 +48,7 @@ CBaseEntity::CBaseEntity( CPlayer* player )
m_bound_box = NULL; m_bound_box = NULL;
} }
CBaseEntity::~CBaseEntity() CEntityTemplate::~CEntityTemplate()
{ {
if( m_bound_box ) if( m_bound_box )
delete( m_bound_box ); delete( m_bound_box );
@ -56,7 +56,7 @@ CBaseEntity::~CBaseEntity()
delete( m_bound_circle ); delete( m_bound_circle );
} }
void CBaseEntity::loadBase() void CEntityTemplate::loadBase()
{ {
// Don't bother if we're providing a replacement. // Don't bother if we're providing a replacement.
if( m_bound_type == CBoundingObject::BOUND_NONE ) if( m_bound_type == CBoundingObject::BOUND_NONE )
@ -81,7 +81,7 @@ void CBaseEntity::loadBase()
SetNextObject( m_base ); SetNextObject( m_base );
} }
jsval CBaseEntity::getClassSet() jsval CEntityTemplate::getClassSet()
{ {
STL_HASH_SET<CStrW, CStrW_hash_compare>::iterator it; STL_HASH_SET<CStrW, CStrW_hash_compare>::iterator it;
it = m_classes.m_Set.begin(); it = m_classes.m_Set.begin();
@ -91,7 +91,7 @@ jsval CBaseEntity::getClassSet()
return( ToJSVal( result ) ); return( ToJSVal( result ) );
} }
void CBaseEntity::setClassSet( jsval value ) void CEntityTemplate::setClassSet( jsval value )
{ {
// Get the set that was passed in. // Get the set that was passed in.
CStr temp = ToPrimitive<CStrW>( value ); CStr temp = ToPrimitive<CStrW>( value );
@ -139,7 +139,7 @@ void CBaseEntity::setClassSet( jsval value )
rebuildClassSet(); rebuildClassSet();
} }
void CBaseEntity::rebuildClassSet() void CEntityTemplate::rebuildClassSet()
{ {
m_classes.Rebuild(); m_classes.Rebuild();
InheritorsList::iterator it; InheritorsList::iterator it;
@ -147,7 +147,7 @@ void CBaseEntity::rebuildClassSet()
(*it)->rebuildClassSet(); (*it)->rebuildClassSet();
} }
bool CBaseEntity::loadXML( CStr filename ) bool CEntityTemplate::loadXML( CStr filename )
{ {
CXeromyces XeroFile; CXeromyces XeroFile;
if (XeroFile.Load(filename) != PSRETURN_OK) if (XeroFile.Load(filename) != PSRETURN_OK)
@ -178,7 +178,7 @@ bool CBaseEntity::loadXML( CStr filename )
if( Root.getNodeName() != el_entity ) if( Root.getNodeName() != el_entity )
{ {
LOG( ERROR, LOG_CATEGORY, "CBaseEntity::LoadXML: XML root was not \"Entity\" in file %s. Load failed.", filename.c_str() ); LOG( ERROR, LOG_CATEGORY, "CEntityTemplate::LoadXML: XML root was not \"Entity\" in file %s. Load failed.", filename.c_str() );
return( false ); return( false );
} }
@ -191,7 +191,7 @@ bool CBaseEntity::loadXML( CStr filename )
// Load our parent, if we have one // Load our parent, if we have one
if( m_Base_Name.Length() ) if( m_Base_Name.Length() )
{ {
CBaseEntity* base = g_EntityTemplateCollection.getTemplate( m_Base_Name, m_player ); CEntityTemplate* base = g_EntityTemplateCollection.getTemplate( m_Base_Name, m_player );
if( base ) if( base )
{ {
m_base = base; m_base = base;
@ -307,7 +307,7 @@ bool CBaseEntity::loadXML( CStr filename )
JSFunction* fn = JS_ValueToFunction( g_ScriptingHost.GetContext(), fnval ); JSFunction* fn = JS_ValueToFunction( g_ScriptingHost.GetContext(), fnval );
if( !fn ) if( !fn )
{ {
LOG( ERROR, LOG_CATEGORY, "CBaseEntity::LoadXML: Function does not exist for event %hs in file %s. Load failed.", EventName.c_str(), filename.c_str() ); LOG( ERROR, LOG_CATEGORY, "CEntityTemplate::LoadXML: Function does not exist for event %hs in file %s. Load failed.", EventName.c_str(), filename.c_str() );
break; break;
} }
m_EventHandlers[eventID].SetFunction( fn ); m_EventHandlers[eventID].SetFunction( fn );
@ -338,7 +338,7 @@ bool CBaseEntity::loadXML( CStr filename )
return true; return true;
} }
void CBaseEntity::XMLLoadProperty( const CXeromyces& XeroFile, const XMBElement& Source, CStrW BasePropertyName ) void CEntityTemplate::XMLLoadProperty( const CXeromyces& XeroFile, const XMBElement& Source, CStrW BasePropertyName )
{ {
// Add a property, put the node text into it. // Add a property, put the node text into it.
CStrW PropertyName = BasePropertyName + CStr8( XeroFile.getElementString( Source.getNodeName() ) ); CStrW PropertyName = BasePropertyName + CStr8( XeroFile.getElementString( Source.getNodeName() ) );
@ -347,7 +347,7 @@ void CBaseEntity::XMLLoadProperty( const CXeromyces& XeroFile, const XMBElement&
if( Existing ) if( Existing )
{ {
if( !Existing->m_Intrinsic ) if( !Existing->m_Intrinsic )
LOG( WARNING, LOG_CATEGORY, "CBaseEntity::XMLAddProperty: %ls already defined for %ls. Property trees will be merged.", PropertyName.c_str(), m_Tag.c_str() ); LOG( WARNING, LOG_CATEGORY, "CEntityTemplate::XMLAddProperty: %ls already defined for %ls. Property trees will be merged.", PropertyName.c_str(), m_Tag.c_str() );
Existing->Set( this, JSParseString( Source.getText() ) ); Existing->Set( this, JSParseString( Source.getText() ) );
//Existing->m_Inherited = false; //Existing->m_Inherited = false;
} }
@ -401,72 +401,72 @@ void CBaseEntity::XMLLoadProperty( const CXeromyces& XeroFile, const XMBElement&
// Scripting initialization // Scripting initialization
void CBaseEntity::ScriptingInit() void CEntityTemplate::ScriptingInit()
{ {
AddMethod<jsval, &CBaseEntity::ToString>( "toString", 0 ); AddMethod<jsval, &CEntityTemplate::ToString>( "toString", 0 );
AddClassProperty( L"traits.id.classes", (GetFn)&CBaseEntity::getClassSet, (SetFn)&CBaseEntity::setClassSet ); AddClassProperty( L"traits.id.classes", (GetFn)&CEntityTemplate::getClassSet, (SetFn)&CEntityTemplate::setClassSet );
AddClassProperty( L"actions.move.speed_curr", &CBaseEntity::m_speed ); AddClassProperty( L"actions.move.speed_curr", &CEntityTemplate::m_speed );
AddClassProperty( L"actions.move.turningradius", &CBaseEntity::m_turningRadius ); AddClassProperty( L"actions.move.turningradius", &CEntityTemplate::m_turningRadius );
AddClassProperty( L"actions.move.run.speed", &CBaseEntity::m_runSpeed ); AddClassProperty( L"actions.move.run.speed", &CEntityTemplate::m_runSpeed );
AddClassProperty( L"actions.move.run.rangemin", &CBaseEntity::m_runMinRange ); AddClassProperty( L"actions.move.run.rangemin", &CEntityTemplate::m_runMinRange );
AddClassProperty( L"actions.move.run.range", &CBaseEntity::m_runMaxRange ); AddClassProperty( L"actions.move.run.range", &CEntityTemplate::m_runMaxRange );
AddClassProperty( L"actions.move.run.regen_rate", &CBaseEntity::m_runRegenRate ); AddClassProperty( L"actions.move.run.regen_rate", &CEntityTemplate::m_runRegenRate );
AddClassProperty( L"actions.move.run.decay_rate", &CBaseEntity::m_runDecayRate ); AddClassProperty( L"actions.move.run.decay_rate", &CEntityTemplate::m_runDecayRate );
AddClassProperty( L"actions.move.pass_through_allies", &CBaseEntity::m_passThroughAllies ); AddClassProperty( L"actions.move.pass_through_allies", &CEntityTemplate::m_passThroughAllies );
AddClassProperty( L"actor", &CBaseEntity::m_actorName ); AddClassProperty( L"actor", &CEntityTemplate::m_actorName );
AddClassProperty( L"traits.health.curr", &CBaseEntity::m_healthCurr ); AddClassProperty( L"traits.health.curr", &CEntityTemplate::m_healthCurr );
AddClassProperty( L"traits.health.max", &CBaseEntity::m_healthMax ); AddClassProperty( L"traits.health.max", &CEntityTemplate::m_healthMax );
AddClassProperty( L"traits.health.bar_height", &CBaseEntity::m_healthBarHeight ); AddClassProperty( L"traits.health.bar_height", &CEntityTemplate::m_healthBarHeight );
AddClassProperty( L"traits.health.bar_size", &CBaseEntity::m_healthBarSize ); AddClassProperty( L"traits.health.bar_size", &CEntityTemplate::m_healthBarSize );
AddClassProperty( L"traits.health.bar_width", &CBaseEntity::m_healthBarWidth ); AddClassProperty( L"traits.health.bar_width", &CEntityTemplate::m_healthBarWidth );
AddClassProperty( L"traits.health.border_height", &CBaseEntity::m_healthBorderHeight); AddClassProperty( L"traits.health.border_height", &CEntityTemplate::m_healthBorderHeight);
AddClassProperty( L"traits.health.border_width", &CBaseEntity::m_healthBorderWidth ); AddClassProperty( L"traits.health.border_width", &CEntityTemplate::m_healthBorderWidth );
AddClassProperty( L"traits.health.border_name", &CBaseEntity::m_healthBorderName ); AddClassProperty( L"traits.health.border_name", &CEntityTemplate::m_healthBorderName );
AddClassProperty( L"traits.health.regen_rate", &CBaseEntity::m_healthRegenRate ); AddClassProperty( L"traits.health.regen_rate", &CEntityTemplate::m_healthRegenRate );
AddClassProperty( L"traits.health.regen_start", &CBaseEntity::m_healthRegenStart ); AddClassProperty( L"traits.health.regen_start", &CEntityTemplate::m_healthRegenStart );
AddClassProperty( L"traits.health.decay_rate", &CBaseEntity::m_healthDecayRate ); AddClassProperty( L"traits.health.decay_rate", &CEntityTemplate::m_healthDecayRate );
AddClassProperty( L"traits.stamina.curr", &CBaseEntity::m_staminaCurr ); AddClassProperty( L"traits.stamina.curr", &CEntityTemplate::m_staminaCurr );
AddClassProperty( L"traits.stamina.max", &CBaseEntity::m_staminaMax ); AddClassProperty( L"traits.stamina.max", &CEntityTemplate::m_staminaMax );
AddClassProperty( L"traits.stamina.bar_height", &CBaseEntity::m_staminaBarHeight ); AddClassProperty( L"traits.stamina.bar_height", &CEntityTemplate::m_staminaBarHeight );
AddClassProperty( L"traits.stamina.bar_size", &CBaseEntity::m_staminaBarSize ); AddClassProperty( L"traits.stamina.bar_size", &CEntityTemplate::m_staminaBarSize );
AddClassProperty( L"traits.stamina.bar_width", &CBaseEntity::m_staminaBarWidth ); AddClassProperty( L"traits.stamina.bar_width", &CEntityTemplate::m_staminaBarWidth );
AddClassProperty( L"traits.stamina.border_height", &CBaseEntity::m_staminaBorderHeight); AddClassProperty( L"traits.stamina.border_height", &CEntityTemplate::m_staminaBorderHeight);
AddClassProperty( L"traits.stamina.border_width", &CBaseEntity::m_staminaBorderWidth ); AddClassProperty( L"traits.stamina.border_width", &CEntityTemplate::m_staminaBorderWidth );
AddClassProperty( L"traits.stamina.border_name", &CBaseEntity::m_staminaBorderName ); AddClassProperty( L"traits.stamina.border_name", &CEntityTemplate::m_staminaBorderName );
AddClassProperty( L"traits.rally.name", &CBaseEntity::m_rallyName ); AddClassProperty( L"traits.rally.name", &CEntityTemplate::m_rallyName );
AddClassProperty( L"traits.rally.width", &CBaseEntity::m_rallyWidth ); AddClassProperty( L"traits.rally.width", &CEntityTemplate::m_rallyWidth );
AddClassProperty( L"traits.rally.height", &CBaseEntity::m_rallyHeight ); AddClassProperty( L"traits.rally.height", &CEntityTemplate::m_rallyHeight );
AddClassProperty( L"traits.flank_penalty.sectors", &CBaseEntity::m_sectorDivs ); AddClassProperty( L"traits.flank_penalty.sectors", &CEntityTemplate::m_sectorDivs );
AddClassProperty( L"traits.pitch.sectors", &CBaseEntity::m_pitchDivs ); AddClassProperty( L"traits.pitch.sectors", &CEntityTemplate::m_pitchDivs );
AddClassProperty( L"traits.rank.width", &CBaseEntity::m_rankWidth ); AddClassProperty( L"traits.rank.width", &CEntityTemplate::m_rankWidth );
AddClassProperty( L"traits.rank.height", &CBaseEntity::m_rankHeight ); AddClassProperty( L"traits.rank.height", &CEntityTemplate::m_rankHeight );
AddClassProperty( L"traits.rank.name", &CBaseEntity::m_rankName ); AddClassProperty( L"traits.rank.name", &CEntityTemplate::m_rankName );
AddClassProperty( L"traits.minimap.type", &CBaseEntity::m_minimapType ); AddClassProperty( L"traits.minimap.type", &CEntityTemplate::m_minimapType );
AddClassProperty( L"traits.minimap.red", &CBaseEntity::m_minimapR ); AddClassProperty( L"traits.minimap.red", &CEntityTemplate::m_minimapR );
AddClassProperty( L"traits.minimap.green", &CBaseEntity::m_minimapG ); AddClassProperty( L"traits.minimap.green", &CEntityTemplate::m_minimapG );
AddClassProperty( L"traits.minimap.blue", &CBaseEntity::m_minimapB ); AddClassProperty( L"traits.minimap.blue", &CEntityTemplate::m_minimapB );
AddClassProperty( L"traits.anchor.type", &CBaseEntity::m_anchorType ); AddClassProperty( L"traits.anchor.type", &CEntityTemplate::m_anchorType );
AddClassProperty( L"traits.anchor.conformx", &CBaseEntity::m_anchorConformX ); AddClassProperty( L"traits.anchor.conformx", &CEntityTemplate::m_anchorConformX );
AddClassProperty( L"traits.anchor.conformz", &CBaseEntity::m_anchorConformZ ); AddClassProperty( L"traits.anchor.conformz", &CEntityTemplate::m_anchorConformZ );
AddClassProperty( L"traits.vision.los", &CBaseEntity::m_los ); AddClassProperty( L"traits.vision.los", &CEntityTemplate::m_los );
AddClassProperty( L"traits.vision.permanent", &CBaseEntity::m_permanent ); AddClassProperty( L"traits.vision.permanent", &CEntityTemplate::m_permanent );
AddClassProperty( L"traits.is_territory_centre", &CBaseEntity::m_isTerritoryCentre ); AddClassProperty( L"traits.is_territory_centre", &CEntityTemplate::m_isTerritoryCentre );
AddClassProperty( L"traits.foundation", &CBaseEntity::m_foundation ); AddClassProperty( L"traits.foundation", &CEntityTemplate::m_foundation );
AddClassProperty( L"traits.socket", &CBaseEntity::m_socket ); AddClassProperty( L"traits.socket", &CEntityTemplate::m_socket );
CJSComplex<CBaseEntity>::ScriptingInit( "EntityTemplate" ); CJSComplex<CEntityTemplate>::ScriptingInit( "EntityTemplate" );
} }
// Script-bound functions // Script-bound functions
JSObject* CBaseEntity::GetScriptExecContext( IEventTarget* target ) JSObject* CEntityTemplate::GetScriptExecContext( IEventTarget* target )
{ {
return( target->GetScriptExecContext( target ) ); return( target->GetScriptExecContext( target ) );
} }
jsval CBaseEntity::ToString( JSContext* cx, uintN UNUSED(argc), jsval* UNUSED(argv) ) jsval CEntityTemplate::ToString( JSContext* cx, uintN UNUSED(argc), jsval* UNUSED(argv) )
{ {
wchar_t buffer[256]; wchar_t buffer[256];
if( m_player == 0 ) if( m_player == 0 )

View File

@ -1,4 +1,4 @@
// BaseEntity.h // EntityTemplate.h
// //
// Mark Thompson mot20@cam.ac.uk / mark@wildfiregames.com // Mark Thompson mot20@cam.ac.uk / mark@wildfiregames.com
// //
@ -29,25 +29,25 @@
class CPlayer; class CPlayer;
class CBaseEntity : public CJSComplex<CBaseEntity>, public IEventTarget class CEntityTemplate : public CJSComplex<CEntityTemplate>, public IEventTarget
{ {
public: public:
CPlayer* m_player; // Which player this template is for, or null for the no-player template CPlayer* m_player; // Which player this template is for, or null for the no-player template
// used to read unmodified values for upgrades and such. // used to read unmodified values for upgrades and such.
CBaseEntity( CPlayer* player ); CEntityTemplate( CPlayer* player );
~CBaseEntity(); ~CEntityTemplate();
// Load from XML // Load from XML
bool loadXML( CStr filename ); bool loadXML( CStr filename );
// Load a tree of properties from an XML (XMB) node. // Load a tree of properties from an XML (XMB) node.
void XMLLoadProperty( const CXeromyces& XeroFile, const XMBElement& Source, CStrW BasePropertyName ); void XMLLoadProperty( const CXeromyces& XeroFile, const XMBElement& Source, CStrW BasePropertyName );
// Base stats // Base stats
CBaseEntity* m_base; CEntityTemplate* m_base;
//bool m_extant; //bool m_extant;
// The unmodified, no-player version of this template // The unmodified, no-player version of this template
CBaseEntity* m_unmodified; CEntityTemplate* m_unmodified;
// The class types this entity has // The class types this entity has
SClassSet m_classes; SClassSet m_classes;
@ -152,8 +152,8 @@ public:
private: private:
// squelch "unable to generate" warnings // squelch "unable to generate" warnings
CBaseEntity(const CBaseEntity& rhs); CEntityTemplate(const CEntityTemplate& rhs);
const CBaseEntity& operator=(const CBaseEntity& rhs); const CEntityTemplate& operator=(const CEntityTemplate& rhs);
static STL_HASH_SET<CStr, CStr_hash_compare> scriptsLoaded; static STL_HASH_SET<CStr, CStr_hash_compare> scriptsLoaded;
}; };

View File

@ -1,6 +1,6 @@
#include "precompiled.h" #include "precompiled.h"
#include "BaseEntityCollection.h" #include "EntityTemplateCollection.h"
#include "graphics/ObjectManager.h" #include "graphics/ObjectManager.h"
#include "graphics/Model.h" #include "graphics/Model.h"
#include "ps/CLogger.h" #include "ps/CLogger.h"
@ -9,7 +9,7 @@
#define LOG_CATEGORY "entity" #define LOG_CATEGORY "entity"
void CBaseEntityCollection::LoadFile( const char* path ) void CEntityTemplateCollection::LoadFile( const char* path )
{ {
// Build the entity name -> filename mapping. This is done so that // Build the entity name -> filename mapping. This is done so that
// the entity 'x' can be in units/x.xml, structures/x.xml, etc, and // the entity 'x' can be in units/x.xml, structures/x.xml, etc, and
@ -23,11 +23,11 @@ void CBaseEntityCollection::LoadFile( const char* path )
static void LoadFileThunk( const char* path, const DirEnt* UNUSED(ent), void* context ) static void LoadFileThunk( const char* path, const DirEnt* UNUSED(ent), void* context )
{ {
CBaseEntityCollection* this_ = (CBaseEntityCollection*)context; CEntityTemplateCollection* this_ = (CEntityTemplateCollection*)context;
this_->LoadFile(path); this_->LoadFile(path);
} }
int CBaseEntityCollection::loadTemplates() int CEntityTemplateCollection::loadTemplates()
{ {
// Load all files in entities/ and its subdirectories. // Load all files in entities/ and its subdirectories.
THROW_ERR( vfs_dir_enum( "entities/", VFS_DIR_RECURSIVE, "*.xml", THROW_ERR( vfs_dir_enum( "entities/", VFS_DIR_RECURSIVE, "*.xml",
@ -35,7 +35,7 @@ int CBaseEntityCollection::loadTemplates()
return 0; return 0;
} }
CBaseEntity* CBaseEntityCollection::getTemplate( CStrW name, CPlayer* player ) CEntityTemplate* CEntityTemplateCollection::getTemplate( CStrW name, CPlayer* player )
{ {
// Find player ID // Find player ID
int id = ( player == 0 ? NULL_PLAYER : player->GetPlayerID() ); int id = ( player == 0 ? NULL_PLAYER : player->GetPlayerID() );
@ -53,28 +53,28 @@ CBaseEntity* CBaseEntityCollection::getTemplate( CStrW name, CPlayer* player )
CStr path( filename_it->second ); CStr path( filename_it->second );
// Try to load to the entity // Try to load to the entity
CBaseEntity* newTemplate = new CBaseEntity( player ); CEntityTemplate* newTemplate = new CEntityTemplate( player );
if( !newTemplate->loadXML( path ) ) if( !newTemplate->loadXML( path ) )
{ {
LOG(ERROR, LOG_CATEGORY, "CBaseEntityCollection::loadTemplates(): Couldn't load template \"%s\"", path.c_str()); LOG(ERROR, LOG_CATEGORY, "CEntityTemplateCollection::loadTemplates(): Couldn't load template \"%s\"", path.c_str());
delete newTemplate; delete newTemplate;
return( NULL ); return( NULL );
} }
LOG(NORMAL, LOG_CATEGORY, "CBaseEntityCollection::loadTemplates(): Loaded template \"%s\"", path.c_str()); LOG(NORMAL, LOG_CATEGORY, "CEntityTemplateCollection::loadTemplates(): Loaded template \"%s\"", path.c_str());
m_templates[id][name] = newTemplate; m_templates[id][name] = newTemplate;
return newTemplate; return newTemplate;
} }
void CBaseEntityCollection::getBaseEntityNames( std::vector<CStrW>& names ) void CEntityTemplateCollection::getEntityTemplateNames( std::vector<CStrW>& names )
{ {
for( templateFilenameMap::iterator it = m_templateFilenames.begin(); it != m_templateFilenames.end(); ++it ) for( templateFilenameMap::iterator it = m_templateFilenames.begin(); it != m_templateFilenames.end(); ++it )
if( ! (it->first.Length() > 8 && it->first.Left(8) == L"template")) if( ! (it->first.Length() > 8 && it->first.Left(8) == L"template"))
names.push_back( it->first ); names.push_back( it->first );
} }
CBaseEntityCollection::~CBaseEntityCollection() CEntityTemplateCollection::~CEntityTemplateCollection()
{ {
for( int id = 0; id < PS_MAX_PLAYERS + 2; id++ ) for( int id = 0; id < PS_MAX_PLAYERS + 2; id++ )
for( templateMap::iterator it = m_templates[id].begin(); it != m_templates[id].end(); ++it ) for( templateMap::iterator it = m_templates[id].begin(); it != m_templates[id].end(); ++it )

View File

@ -1,4 +1,4 @@
// BaseEntityCollection.h // EntityTemplateCollection.h
// //
// Mark Thompson mot20@cam.ac.uk / mark@wildfiregames.com // Mark Thompson mot20@cam.ac.uk / mark@wildfiregames.com
// //
@ -23,30 +23,30 @@
#include "ps/CStr.h" #include "ps/CStr.h"
#include "ps/Singleton.h" #include "ps/Singleton.h"
#include "graphics/ObjectEntry.h" #include "graphics/ObjectEntry.h"
#include "BaseEntity.h" #include "EntityTemplate.h"
#include "ps/Game.h" #include "ps/Game.h"
#define g_EntityTemplateCollection CBaseEntityCollection::GetSingleton() #define g_EntityTemplateCollection CEntityTemplateCollection::GetSingleton()
#define NULL_PLAYER (PS_MAX_PLAYERS+1) #define NULL_PLAYER (PS_MAX_PLAYERS+1)
class CPlayer; class CPlayer;
class CBaseEntityCollection : public Singleton<CBaseEntityCollection> class CEntityTemplateCollection : public Singleton<CEntityTemplateCollection>
{ {
typedef STL_HASH_MAP<CStrW, CBaseEntity*, CStrW_hash_compare> templateMap; typedef STL_HASH_MAP<CStrW, CEntityTemplate*, CStrW_hash_compare> templateMap;
typedef STL_HASH_MAP<CStrW, CStr, CStrW_hash_compare> templateFilenameMap; typedef STL_HASH_MAP<CStrW, CStr, CStrW_hash_compare> templateFilenameMap;
templateMap m_templates[PS_MAX_PLAYERS + 2]; templateMap m_templates[PS_MAX_PLAYERS + 2];
templateFilenameMap m_templateFilenames; templateFilenameMap m_templateFilenames;
public: public:
~CBaseEntityCollection(); ~CEntityTemplateCollection();
CBaseEntity* getTemplate( CStrW entityType, CPlayer* player = 0 ); CEntityTemplate* getTemplate( CStrW entityType, CPlayer* player = 0 );
int loadTemplates(); int loadTemplates();
void LoadFile( const char* path ); void LoadFile( const char* path );
// Create a list of the names of all base entities, excluding template_*, // Create a list of the names of all base entities, excluding template_*,
// for display in ScEd's entity-selection box. // for display in ScEd's entity-selection box.
void getBaseEntityNames( std::vector<CStrW>& names ); void getEntityTemplateNames( std::vector<CStrW>& names );
}; };
#endif #endif

View File

@ -1,7 +1,7 @@
//FormationCollection.h //FormationCollection.h
//Andrew aka pyrolink: ajdecker1022@msn.com //Andrew aka pyrolink: ajdecker1022@msn.com
//Nearly identical to BaseEntityCollection and associates i.e. BaseEntity, Entity. //Nearly identical to EntityTemplateCollection and associates i.e. EntityTemplate, Entity.
//This is the manager of the entity formation "templates" //This is the manager of the entity formation "templates"

View File

@ -7,7 +7,7 @@
#include "scripting/ScriptingHost.h" #include "scripting/ScriptingHost.h"
#include "ps/XML/Xeromyces.h" #include "ps/XML/Xeromyces.h"
#include "ps/XML/XeroXMB.h" #include "ps/XML/XeroXMB.h"
#include "BaseEntity.h" #include "EntityTemplate.h"
#include "Entity.h" #include "Entity.h"
#include "ps/Player.h" #include "ps/Player.h"

View File

@ -1,5 +1,5 @@
//Andrew aka pyrolink - ajdecker1022@msn.com //Andrew aka pyrolink - ajdecker1022@msn.com
//Manages the tech templates. More detail: see CFormation and CBaseEntity (collections) //Manages the tech templates. More detail: see CFormation and CEntityTemplate (collections)
#ifndef TECHNOLOGY_COLLECTION_INCLUDED #ifndef TECHNOLOGY_COLLECTION_INCLUDED

View File

@ -1,30 +0,0 @@
// JSInterface_BaseEntity.h
//
// An interface between CBaseEntity and the JavaScript class EntityTemplate
//
// Usage: Used when manipulating objects of class 'EntityTemplate' in JavaScript.
//
// Mark Thompson mot20@cam.ac.uk / mark@wildfiregames.com
#include "scripting/ScriptingHost.h"
#ifndef JSI_BASEENTITY_INCLUDED
#define JSI_BASEENTITY_INCLUDED
/*
namespace JSI_BaseEntity
{
JSBool toString( JSContext* cx, JSObject* obj, uintN argc, jsval* argv, jsval* rval );
extern JSClass JSI_class;
extern JSPropertySpec JSI_props[];
extern JSFunctionSpec JSI_methods[];
JSBool addProperty( JSContext* cx, JSObject* obj, jsval id, jsval* vp );
JSBool delProperty( JSContext* cx, JSObject* obj, jsval id, jsval* vp );
JSBool getProperty( JSContext* cx, JSObject* obj, jsval id, jsval* vp );
JSBool setProperty( JSContext* cx, JSObject* obj, jsval id, jsval* vp );
void finalize( JSContext* cx, JSObject* obj );
void init();
}
*/
#endif

View File

@ -1,32 +0,0 @@
// JSInterface_Entity.h
//
// The interface layer between JavaScript code and the actual CEntity object.
//
// Usage: Used when manipulating objects of class 'Entity' in JavaScript.
//
// Mark Thompson mot20@cam.ac.uk / mark@wildfiregames.com
#include "scripting/ScriptingHost.h"
#ifndef JSI_ENTITY_INCLUDED
#define JSI_ENTITY_INCLUDED
/*
namespace JSI_Entity
{
JSBool toString( JSContext* cx, JSObject* obj, uintN argc, jsval* argv, jsval* rval );
JSBool order( JSContext* cx, JSObject* obj, uintN argc, jsval* argv, jsval* rval, bool queueOrder );
JSBool orderSingle( JSContext* cx, JSObject* obj, uintN argc, jsval* argv, jsval* rval );
JSBool orderQueued( JSContext* cx, JSObject* obj, uintN argc, jsval* argv, jsval* rval );
extern JSClass JSI_class;
extern JSPropertySpec JSI_props[];
extern JSFunctionSpec JSI_methods[];
JSBool getProperty( JSContext* cx, JSObject* obj, jsval id, jsval* vp );
JSBool setProperty( JSContext* cx, JSObject* obj, jsval id, jsval* vp );
JSBool construct( JSContext* cx, JSObject* obj, uint argc, jsval* argv, jsval* rval );
void finalize( JSContext* cx, JSObject* obj );
void init();
}
*/
#endif

View File

@ -17,7 +17,7 @@
#include "ps/CLogger.h" #include "ps/CLogger.h"
#include "ps/Game.h" #include "ps/Game.h"
#include "ps/World.h" #include "ps/World.h"
#include "simulation/BaseEntityCollection.h" #include "simulation/EntityTemplateCollection.h"
#include "simulation/Entity.h" #include "simulation/Entity.h"
#include "simulation/EntityManager.h" #include "simulation/EntityManager.h"
@ -35,10 +35,10 @@ QUERYHANDLER(GetObjectsList)
std::vector<sObjectsListItem> objects; std::vector<sObjectsListItem> objects;
{ {
std::vector<CStrW> names; std::vector<CStrW> names;
g_EntityTemplateCollection.getBaseEntityNames(names); g_EntityTemplateCollection.getEntityTemplateNames(names);
for (std::vector<CStrW>::iterator it = names.begin(); it != names.end(); ++it) for (std::vector<CStrW>::iterator it = names.begin(); it != names.end(); ++it)
{ {
//CBaseEntity* baseent = g_EntityTemplateCollection.getTemplate(*it); //CEntityTemplate* baseent = g_EntityTemplateCollection.getTemplate(*it);
sObjectsListItem e; sObjectsListItem e;
e.id = L"(e) " + *it; e.id = L"(e) " + *it;
e.name = *it; //baseent->m_Tag e.name = *it; //baseent->m_Tag
@ -267,7 +267,7 @@ MESSAGEHANDLER(ObjectPreview)
// Create new unit // Create new unit
if (isEntity) if (isEntity)
{ {
CBaseEntity* base = g_EntityTemplateCollection.getTemplate(name); CEntityTemplate* base = g_EntityTemplateCollection.getTemplate(name);
if (base) // (ignore errors) if (base) // (ignore errors)
{ {
g_PreviewUnit = g_UnitMan.CreateUnit(base->m_actorName, NULL, selections); g_PreviewUnit = g_UnitMan.CreateUnit(base->m_actorName, NULL, selections);
@ -364,7 +364,7 @@ BEGIN_COMMAND(CreateObject)
if (isEntity) if (isEntity)
{ {
CBaseEntity* base = g_EntityTemplateCollection.getTemplate(name); CEntityTemplate* base = g_EntityTemplateCollection.getTemplate(name);
if (! base) if (! base)
LOG(ERROR, LOG_CATEGORY, "Failed to load entity template '%ls'", name.c_str()); LOG(ERROR, LOG_CATEGORY, "Failed to load entity template '%ls'", name.c_str());
else else