From f5490bf111b4b3f0f8da2858e1fdc68d9fa0bf89 Mon Sep 17 00:00:00 2001 From: Erik Persson Date: Wed, 18 Dec 2013 13:01:13 +0100 Subject: [PATCH] using a global id in object --- Code/Game/DanBiasLauncher/Launcher.cpp | 4 ++-- Code/Game/GameLogic/Object.cpp | 8 +++++++ Code/Game/GameLogic/Object.h | 2 ++ Code/Misc/GID.h | 29 ++++++++++++++++++++++++++ Code/Misc/Misc.vcxproj | 1 + Code/Misc/Misc.vcxproj.filters | 3 +++ 6 files changed, 45 insertions(+), 2 deletions(-) create mode 100644 Code/Misc/GID.h diff --git a/Code/Game/DanBiasLauncher/Launcher.cpp b/Code/Game/DanBiasLauncher/Launcher.cpp index b126e5e7..6b82da2a 100644 --- a/Code/Game/DanBiasLauncher/Launcher.cpp +++ b/Code/Game/DanBiasLauncher/Launcher.cpp @@ -5,8 +5,8 @@ #include #include -//#include "DanBiasServerAPI.h" -#include "DanBiasGame.h" +#include "DanBiasServerAPI.h" +//#include "DanBiasGame.h" int WINAPI WinMain( HINSTANCE hinst, HINSTANCE prevInst, PSTR cmdLine, int cmdShow) diff --git a/Code/Game/GameLogic/Object.cpp b/Code/Game/GameLogic/Object.cpp index dcd32bf1..c9d1e476 100644 --- a/Code/Game/GameLogic/Object.cpp +++ b/Code/Game/GameLogic/Object.cpp @@ -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() { diff --git a/Code/Game/GameLogic/Object.h b/Code/Game/GameLogic/Object.h index 01864515..a6ba2b27 100644 --- a/Code/Game/GameLogic/Object.h +++ b/Code/Game/GameLogic/Object.h @@ -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; }; diff --git a/Code/Misc/GID.h b/Code/Misc/GID.h new file mode 100644 index 00000000..9e96a0a8 --- /dev/null +++ b/Code/Misc/GID.h @@ -0,0 +1,29 @@ +#ifndef GID_H +#define GID_H + +#include + +/** +* 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 + diff --git a/Code/Misc/Misc.vcxproj b/Code/Misc/Misc.vcxproj index 7d3074d3..16839062 100644 --- a/Code/Misc/Misc.vcxproj +++ b/Code/Misc/Misc.vcxproj @@ -156,6 +156,7 @@ + diff --git a/Code/Misc/Misc.vcxproj.filters b/Code/Misc/Misc.vcxproj.filters index d6fea6e9..0959e88b 100644 --- a/Code/Misc/Misc.vcxproj.filters +++ b/Code/Misc/Misc.vcxproj.filters @@ -92,5 +92,8 @@ Header Files + + Header Files + \ No newline at end of file