using a global id in object

This commit is contained in:
Erik Persson 2013-12-18 13:01:13 +01:00
parent 0c98e2847d
commit f5490bf111
6 changed files with 45 additions and 2 deletions

View File

@ -5,8 +5,8 @@
#include <Windows.h> #include <Windows.h>
#include <vld.h> #include <vld.h>
//#include "DanBiasServerAPI.h" #include "DanBiasServerAPI.h"
#include "DanBiasGame.h" //#include "DanBiasGame.h"
int WINAPI WinMain( HINSTANCE hinst, HINSTANCE prevInst, PSTR cmdLine, int cmdShow) int WINAPI WinMain( HINSTANCE hinst, HINSTANCE prevInst, PSTR cmdLine, int cmdShow)

View File

@ -1,6 +1,7 @@
#include "Object.h" #include "Object.h"
#include "OysterMath.h" #include "OysterMath.h"
#include "CollisionManager.h" #include "CollisionManager.h"
#include "GID.h"
using namespace GameLogic; using namespace GameLogic;
@ -18,6 +19,7 @@ Object::Object()
rigidBody->gameObjectRef = this; rigidBody->gameObjectRef = this;
this->objectID = GID();
this->type = OBJECT_TYPE_UNKNOWN; this->type = OBJECT_TYPE_UNKNOWN;
} }
@ -34,6 +36,8 @@ Object::Object(void* collisionFunc, OBJECT_TYPE type)
rigidBody->gameObjectRef = this; rigidBody->gameObjectRef = this;
this->objectID = GID();
this->type = type; this->type = type;
} }
@ -48,6 +52,10 @@ OBJECT_TYPE Object::GetType()
{ {
return this->type; return this->type;
} }
int Object::GetID()
{
return this->objectID;
}
Oyster::Physics::ICustomBody* Object::GetRigidBody() Oyster::Physics::ICustomBody* Object::GetRigidBody()
{ {

View File

@ -21,11 +21,13 @@ namespace GameLogic
~Object(void); ~Object(void);
OBJECT_TYPE GetType(); OBJECT_TYPE GetType();
int GetID();
Oyster::Physics::ICustomBody* GetRigidBody(); Oyster::Physics::ICustomBody* GetRigidBody();
private: private:
OBJECT_TYPE type; OBJECT_TYPE type;
int objectID;
protected: protected:
Oyster::Physics::ICustomBody *rigidBody; Oyster::Physics::ICustomBody *rigidBody;
}; };

29
Code/Misc/GID.h Normal file
View File

@ -0,0 +1,29 @@
#ifndef GID_H
#define GID_H
#include <vector>
/**
* This class only purpos is to generate a uniqe global id, nothing else..
*/
class GID
{
private:
int id;
int usft() { static int ID = 0; return ID++; }
public:
GID::GID() { this->id = usft(); }
GID::~GID() { }
GID(const GID& o) { this->id = usft(); }
const GID& operator=(const GID& o) { this->id = usft(); return *this; }
operator int() const { return this->id; }
bool operator == (const GID& object) const { return (this->id == object.id); }
bool operator == (const int& id) const { return (this->id == id); }
int get() const { return this->id; }
};
#endif

View File

@ -156,6 +156,7 @@
<ClCompile Include="WinTimer.cpp" /> <ClCompile Include="WinTimer.cpp" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClInclude Include="..\Game\GameLogic\GID.h" />
<ClInclude Include="IQueue.h" /> <ClInclude Include="IQueue.h" />
<ClInclude Include="PostBox\IPostBox.h" /> <ClInclude Include="PostBox\IPostBox.h" />
<ClInclude Include="PostBox\PostBox.h" /> <ClInclude Include="PostBox\PostBox.h" />

View File

@ -92,5 +92,8 @@
<ClInclude Include="PostBox\IPostBox.h"> <ClInclude Include="PostBox\IPostBox.h">
<Filter>Header Files</Filter> <Filter>Header Files</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="..\Game\GameLogic\GID.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup> </ItemGroup>
</Project> </Project>