18 #ifndef INCLUDED_COMPONENTTEST 19 #define INCLUDED_COMPONENTTEST 59 m_Context(), m_ComponentManager(m_Context, scriptContext), m_Cmp(NULL)
80 TS_ASSERT(m_Cmp == NULL);
85 if (!m_isSystemEntityInit)
88 m_isSystemEntityInit =
true;
99 m_Cmp = m_ComponentManager.
QueryInterface(ent, T::GetInterfaceId());
100 TS_ASSERT(m_Cmp != NULL);
101 return static_cast<T*
> (
m_Cmp);
109 if (!m_isSystemEntityInit)
112 m_isSystemEntityInit =
true;
135 std::stringstream dbgstr1;
140 std::cout <<
"--------\n" << dbgstr1.str() <<
"--------\n";
145 std::stringstream stdstr1;
160 TS_ASSERT(stdstr1.peek() == EOF);
162 std::stringstream dbgstr2;
164 cmp2->Serialize(dbg2);
167 std::cout <<
"--------\n" << dbgstr2.str() <<
"--------\n";
170 cmp2->Serialize(hash2);
172 std::stringstream stdstr2;
174 cmp2->Serialize(std2);
176 TS_ASSERT_EQUALS(dbgstr1.str(), dbgstr2.str());
178 TS_ASSERT_EQUALS(hash1.
GetHashLength(), hash2.GetHashLength());
181 TS_ASSERT_EQUALS(stdstr1.str(), stdstr2.str());
196 bool IsLoaded()
const override 250 #endif // INCLUDED_COMPONENTTEST
An entity initialisation parameter node.
Definition: ParamNode.h:150
Definition: IComponent.h:32
A simple fixed-point number class.
Definition: Fixed.h:119
EComponentTypeId
Definition: Components.h:50
#define UNUSED(param)
mark a function parameter as unused and avoid the corresponding compiler warning. ...
Definition: code_annotation.h:38
entity_pos_t GetGroundLevel(entity_pos_t x, entity_pos_t z) const override
Definition: ComponentTest.h:211
CParamNode m_Param
Definition: ComponentTest.h:52
void AddMockComponent(CEntityHandle ent, InterfaceId iid, IComponent &component)
Adds an externally-created component, so that it is returned by QueryInterface but does not get destr...
Definition: ComponentManager.cpp:776
void Roundtrip(bool verbose=false)
Checks that the object roundtrips through its serialize/deserialize functions correctly.
Definition: ComponentTest.h:133
u16 GetTilesPerSide() const override
Returns number of tiles per side on the terrain.
Definition: ComponentTest.h:221
const ssize_t TERRAIN_TILE_SIZE
metres [world space units] per tile in x and z
Definition: Terrain.h:40
u32 GetMapSize() const override
Returns the map size in metres (world space units).
Definition: ComponentTest.h:226
const PSRETURN PSRETURN_OK
Definition: Errors.h:103
uint16_t u16
Definition: types.h:38
virtual void Serialize(ISerializer &serialize)=0
Object wrapping an entity_id_t, with a SEntityComponentCache to support fast QueryInterface() / CmpPt...
Definition: Entity.h:79
CComponentManager m_ComponentManager
Definition: ComponentTest.h:51
float GetExactGroundLevel(float x, float z) const override
Definition: ComponentTest.h:216
ScriptInterface & GetScriptInterface()
Definition: ComponentManager.h:272
Definition: Vector3D.h:30
T * Add(EComponentTypeId cid, const std::string &xml, entity_id_t ent=10)
Call this once to initialise the test helper with a component.
Definition: ComponentTest.h:78
IComponent * QueryInterface(entity_id_t ent, InterfaceId iid) const
Definition: ComponentManager.cpp:941
Serialize to a human-readable YAML-like format.
Definition: DebugSerializer.h:26
const ScriptInterface & GetScriptInterface()
Definition: ComponentTest.h:64
void MakeDirty(i32 i0, i32 j0, i32 i1, i32 j1) override
Indicate that terrain tiles within the given region (inclusive lower bound, exclusive upper bound) ha...
Definition: ComponentTest.h:241
Contains pointers to various 'global' objects that are needed by the simulation code, to allow easy access without using real (evil) global variables.
Definition: SimContext.h:32
void LoadComponentTypes()
Definition: ComponentManager.cpp:123
void ReloadTerrain(bool ReloadWater) override
Call when the underlying CTerrain has been modified behind our backs.
Definition: ComponentTest.h:245
Definition: HashSerializer.h:45
u16 GetVerticesPerSide() const override
Returns number of vertices per side on the terrain.
Definition: ComponentTest.h:231
CTerrain * GetCTerrain() override
Definition: ComponentTest.h:236
const entity_id_t SYSTEM_ENTITY
Entity ID for singleton 'system' components.
Definition: Entity.h:43
CEntityHandle LookupEntityHandle(entity_id_t ent, bool allowCreate=false)
Returns a CEntityHandle with id ent.
Definition: ComponentManager.cpp:807
void AddMock(entity_id_t ent, EInterfaceId iid, IComponent &component)
Definition: ComponentTest.h:104
uint32_t u32
Definition: types.h:39
Simple terrain implementation with constant height of 50.
Definition: ComponentTest.h:191
#define DEFAULT_MOCK_COMPONENT()
Definition: Component.h:47
Definition: ComponentManager.h:39
static PSRETURN LoadXMLString(CParamNode &ret, const char *xml, const wchar_t *sourceIdentifier=NULL)
See LoadXML, but parses the XML string xml.
Definition: ParamNode.cpp:57
Definition: FixedVector3D.h:24
#define T(string_literal)
Definition: secure_crt.cpp:77
void InitSystemEntity()
Set up an empty SYSTEM_ENTITY.
Definition: ComponentManager.cpp:822
CVector3D CalcExactNormal(float x, float z) const override
Definition: ComponentTest.h:206
int32_t i32
Definition: types.h:34
CSimContext m_Context
Definition: ComponentTest.h:50
virtual void Deserialize(const CParamNode ¶mNode, IDeserializer &deserialize)=0
ComponentTestHelper(std::shared_ptr< ScriptContext > scriptContext)
Definition: ComponentTest.h:58
bool AddComponent(CEntityHandle ent, ComponentTypeId cid, const CParamNode ¶mNode)
Constructs a component of type 'cid', initialised with data 'paramNode', and attaches it to entity 'e...
Definition: ComponentManager.cpp:678
size_t GetHashLength()
Definition: HashSerializer.cpp:27
IComponent * ConstructComponent(CEntityHandle ent, ComponentTypeId cid)
Allocates a component object of type 'cid', and attaches it to entity 'ent'.
Definition: ComponentManager.cpp:716
IComponent * m_Cmp
Definition: ComponentTest.h:53
void SetSystemEntity(CEntityHandle ent)
Definition: SimContext.h:48
bool m_isSystemEntityInit
Definition: ComponentTest.h:55
virtual void HandleMessage(const CMessage &msg, bool global)
Definition: IComponent.cpp:46
EComponentTypeId m_Cid
Definition: ComponentTest.h:54
CEntityHandle GetSystemEntity()
Returns a CEntityHandle with id SYSTEM_ENTITY.
Definition: ComponentManager.h:149
Abstraction around a SpiderMonkey JS::Realm.
Definition: ScriptInterface.h:71
void HandleMessage(IComponent *cmp, const CMessage &msg, bool global)
Definition: ComponentTest.h:123
CFixedVector3D CalcNormal(entity_pos_t x, entity_pos_t z) const override
Definition: ComponentTest.h:201
CSimContext & GetSimContext()
Definition: ComponentTest.h:69
static constexpr CFixed FromInt(int n)
Definition: Fixed.h:140
Class to test a single component.
Definition: ComponentTest.h:48
u32 entity_id_t
Entity ID type.
Definition: Entity.h:23
def xml
Definition: tests.py:121
Definition: StdDeserializer.h:26
const u8 * ComputeHash()
Definition: HashSerializer.cpp:32
Definition: StdSerializer.h:59
const CParamNode & GetChild(const char *name) const
Returns the (unique) child node with the given name, or a node with IsOk() == false if there is none...
Definition: ParamNode.cpp:253
EInterfaceId
Definition: Components.h:39
Definition: ICmpTerrain.h:30