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 <vld.h>
//#include "DanBiasServerAPI.h"
#include "DanBiasGame.h"
#include "DanBiasServerAPI.h"
//#include "DanBiasGame.h"
int WINAPI WinMain( HINSTANCE hinst, HINSTANCE prevInst, PSTR cmdLine, int cmdShow)

View File

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

View File

@ -21,11 +21,13 @@ namespace GameLogic
~Object(void);
OBJECT_TYPE GetType();
int GetID();
Oyster::Physics::ICustomBody* GetRigidBody();
private:
OBJECT_TYPE type;
int objectID;
protected:
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" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\Game\GameLogic\GID.h" />
<ClInclude Include="IQueue.h" />
<ClInclude Include="PostBox\IPostBox.h" />
<ClInclude Include="PostBox\PostBox.h" />

View File

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