diff --git a/Code/Game/DanBiasGame/GameClientState/C_Object.cpp b/Code/Game/DanBiasGame/GameClientState/C_Object.cpp index 3f9e08c1..d44d9201 100644 --- a/Code/Game/DanBiasGame/GameClientState/C_Object.cpp +++ b/Code/Game/DanBiasGame/GameClientState/C_Object.cpp @@ -1,14 +1,31 @@ #include "C_Object.h" using namespace DanBias::Client; -void C_Object::Init(ModelInitData modelInit) +C_Object::C_Object() +{ + world = Oyster::Math::Float4x4::identity; + position = Oyster::Math::Float3::null; + rotation = Oyster::Math::Quaternion::identity; + scale = Oyster::Math::Float3::null; + + id = 0; + model = NULL; +} +C_Object::~C_Object() +{ + +} +bool C_Object::Init(ModelInitData modelInit) { position = modelInit.position; rotation = modelInit.rotation; scale = modelInit.scale; id = modelInit.id; model = Oyster::Graphics::API::CreateModel(modelInit.modelPath); + if(model == NULL) + return false; model->Visible = modelInit.visible; updateWorld(); + return true; } void C_Object::updateWorld() { diff --git a/Code/Game/DanBiasGame/GameClientState/C_Object.h b/Code/Game/DanBiasGame/GameClientState/C_Object.h index f926a08a..ae9dc3a5 100644 --- a/Code/Game/DanBiasGame/GameClientState/C_Object.h +++ b/Code/Game/DanBiasGame/GameClientState/C_Object.h @@ -29,8 +29,9 @@ private: protected: Oyster::Graphics::Model::Model *model; public: - - virtual void Init(ModelInitData modelInit); + C_Object(); + virtual ~C_Object(); + virtual bool Init(ModelInitData modelInit); void setWorld(Oyster::Math::Float4x4 world); Oyster::Math::Float4x4 getWorld() const; diff --git a/Code/Game/DanBiasGame/GameClientState/C_obj/C_DynamicObj.cpp b/Code/Game/DanBiasGame/GameClientState/C_obj/C_DynamicObj.cpp index e654348f..73dd20b5 100644 --- a/Code/Game/DanBiasGame/GameClientState/C_obj/C_DynamicObj.cpp +++ b/Code/Game/DanBiasGame/GameClientState/C_obj/C_DynamicObj.cpp @@ -11,7 +11,7 @@ C_DynamicObj::~C_DynamicObj(void) { } -void C_DynamicObj::Init(ModelInitData modelInit) +bool C_DynamicObj::Init(ModelInitData modelInit) { - C_Object::Init(modelInit); + return C_Object::Init(modelInit); } diff --git a/Code/Game/DanBiasGame/GameClientState/C_obj/C_DynamicObj.h b/Code/Game/DanBiasGame/GameClientState/C_obj/C_DynamicObj.h index ecb874d1..3f5a9dd1 100644 --- a/Code/Game/DanBiasGame/GameClientState/C_obj/C_DynamicObj.h +++ b/Code/Game/DanBiasGame/GameClientState/C_obj/C_DynamicObj.h @@ -11,7 +11,7 @@ private: public: C_DynamicObj(void); virtual ~C_DynamicObj(void); - void Init(ModelInitData modelInit); + bool Init(ModelInitData modelInit); };};}; #endif \ No newline at end of file diff --git a/Code/Game/DanBiasGame/GameClientState/C_obj/C_Player.cpp b/Code/Game/DanBiasGame/GameClientState/C_obj/C_Player.cpp index a75785a6..b6420f53 100644 --- a/Code/Game/DanBiasGame/GameClientState/C_obj/C_Player.cpp +++ b/Code/Game/DanBiasGame/GameClientState/C_obj/C_Player.cpp @@ -13,9 +13,12 @@ C_Player::~C_Player(void) } -void C_Player::Init(ModelInitData modelInit) +bool C_Player::Init(ModelInitData modelInit) { - C_Object::Init(modelInit); - Oyster::Graphics::API::PlayAnimation(model, L"movement"); - //Oyster::Graphics::API::Update(0.002f); + return C_Object::Init(modelInit); } +void C_Player::playAnimation(std::wstring animation, bool loop) +{ + if(model) + Oyster::Graphics::API::PlayAnimation(model, L"movement", loop); +} \ No newline at end of file diff --git a/Code/Game/DanBiasGame/GameClientState/C_obj/C_Player.h b/Code/Game/DanBiasGame/GameClientState/C_obj/C_Player.h index 9d7c3de0..3ef96702 100644 --- a/Code/Game/DanBiasGame/GameClientState/C_obj/C_Player.h +++ b/Code/Game/DanBiasGame/GameClientState/C_obj/C_Player.h @@ -11,7 +11,8 @@ private: public: C_Player(void); virtual ~C_Player(void); - void Init(ModelInitData modelInit); + bool Init(ModelInitData modelInit); + void playAnimation(std::wstring animation, bool loop); };};}; #endif diff --git a/Code/Game/DanBiasGame/GameClientState/C_obj/C_StaticObj.cpp b/Code/Game/DanBiasGame/GameClientState/C_obj/C_StaticObj.cpp index a61768e4..42a12acd 100644 --- a/Code/Game/DanBiasGame/GameClientState/C_obj/C_StaticObj.cpp +++ b/Code/Game/DanBiasGame/GameClientState/C_obj/C_StaticObj.cpp @@ -10,7 +10,7 @@ C_StaticObj::~C_StaticObj(void) { } -void C_StaticObj::Init(ModelInitData modelInit) +bool C_StaticObj::Init(ModelInitData modelInit) { - C_Object::Init(modelInit); + return C_Object::Init(modelInit); } diff --git a/Code/Game/DanBiasGame/GameClientState/C_obj/C_StaticObj.h b/Code/Game/DanBiasGame/GameClientState/C_obj/C_StaticObj.h index d2bcb2a9..60b09046 100644 --- a/Code/Game/DanBiasGame/GameClientState/C_obj/C_StaticObj.h +++ b/Code/Game/DanBiasGame/GameClientState/C_obj/C_StaticObj.h @@ -11,7 +11,7 @@ private: public: C_StaticObj(void); virtual ~C_StaticObj(void); - void Init(ModelInitData modelInit); + bool Init(ModelInitData modelInit); };};}; #endif \ No newline at end of file diff --git a/Code/Game/DanBiasGame/GameClientState/C_obj/C_UIobject.cpp b/Code/Game/DanBiasGame/GameClientState/C_obj/C_UIobject.cpp index 570fa22f..4cc57a98 100644 --- a/Code/Game/DanBiasGame/GameClientState/C_obj/C_UIobject.cpp +++ b/Code/Game/DanBiasGame/GameClientState/C_obj/C_UIobject.cpp @@ -10,7 +10,7 @@ C_UIobject::C_UIobject(void) C_UIobject::~C_UIobject(void) { } -void C_UIobject::Init(ModelInitData modelInit) +bool C_UIobject::Init(ModelInitData modelInit) { - C_Object::Init(modelInit); + return C_Object::Init(modelInit); } diff --git a/Code/Game/DanBiasGame/GameClientState/C_obj/C_UIobject.h b/Code/Game/DanBiasGame/GameClientState/C_obj/C_UIobject.h index f002fcb2..fe4b68d0 100644 --- a/Code/Game/DanBiasGame/GameClientState/C_obj/C_UIobject.h +++ b/Code/Game/DanBiasGame/GameClientState/C_obj/C_UIobject.h @@ -12,7 +12,7 @@ namespace DanBias public: C_UIobject(void); virtual ~C_UIobject(void); - void Init(ModelInitData modelInit); + bool Init(ModelInitData modelInit); void setPos(Oyster::Math::Float4x4 world); };};}; #endif \ No newline at end of file diff --git a/Code/Game/DanBiasGame/GameClientState/GameState.cpp b/Code/Game/DanBiasGame/GameClientState/GameState.cpp index c4da14bb..c86d599d 100644 --- a/Code/Game/DanBiasGame/GameClientState/GameState.cpp +++ b/Code/Game/DanBiasGame/GameClientState/GameState.cpp @@ -195,7 +195,12 @@ bool GameState::LoadModels(std::string mapFile) modelData.id = modelId++; this->staticObjects.Push(new C_StaticObj()); - this->staticObjects[this->staticObjects.Size() -1 ]->Init(modelData); + if(!this->staticObjects[this->staticObjects.Size() -1 ]->Init(modelData)) + { + // the model don't exist + this->staticObjects.Remove(this->staticObjects.Size() -1 ); + modelId--; + } } break; case GameLogic::ObjectType::ObjectType_Dynamic: @@ -209,7 +214,12 @@ bool GameState::LoadModels(std::string mapFile) modelData.id = modelId++; this->dynamicObjects.Push(new C_DynamicObj()); - this->dynamicObjects[this->dynamicObjects.Size() -1 ]->Init(modelData); + if(!this->dynamicObjects[this->dynamicObjects.Size() -1 ]->Init(modelData)) + { + // the model don't exist + this->dynamicObjects.Remove(this->dynamicObjects.Size() -1 ); + modelId--; + } } break; case GameLogic::ObjectType::ObjectType_Light: @@ -241,40 +251,44 @@ bool GameState::LoadModels(std::string mapFile) modelData.rotation = first; modelData.scale = Oyster::Math::Float3(1,1,1); modelData.modelPath = L"char_still_sizeref.dan"; - modelData.id = myId; + modelData.id = modelId; this->staticObjects.Push(new C_StaticObj()); - this->staticObjects[this->staticObjects.Size() -1 ]->Init(modelData); + if(!this->staticObjects[this->staticObjects.Size() -1 ]->Init(modelData)) + { + // the model don't exist + this->staticObjects.Remove(this->staticObjects.Size() -1 ); + modelId--; + } + //modelData.visible = true; + //modelData.position = Oyster::Math::Float3(22, 127,0); + //modelData.rotation = second; + //modelData.scale = Oyster::Math::Float3(1,1,1); + //modelData.modelPath = L"char_still_sizeref.dan"; + //modelData.id = myId; - modelData.visible = true; - modelData.position = Oyster::Math::Float3(22, 127,0); - modelData.rotation = second; - modelData.scale = Oyster::Math::Float3(1,1,1); - modelData.modelPath = L"char_still_sizeref.dan"; - modelData.id = myId; + //this->staticObjects.Push(new C_StaticObj()); + //this->staticObjects[this->staticObjects.Size() -1 ]->Init(modelData); - this->staticObjects.Push(new C_StaticObj()); - this->staticObjects[this->staticObjects.Size() -1 ]->Init(modelData); + //modelData.visible = true; + //modelData.position = Oyster::Math::Float3(24, 127,0); + //modelData.rotation = result; + //modelData.scale = Oyster::Math::Float3(1,1,1); + //modelData.modelPath = L"char_still_sizeref.dan"; + //modelData.id = myId; - modelData.visible = true; - modelData.position = Oyster::Math::Float3(24, 127,0); - modelData.rotation = result; - modelData.scale = Oyster::Math::Float3(1,1,1); - modelData.modelPath = L"char_still_sizeref.dan"; - modelData.id = myId; + //this->staticObjects.Push(new C_StaticObj()); + //this->staticObjects[this->staticObjects.Size() -1 ]->Init(modelData); - this->staticObjects.Push(new C_StaticObj()); - this->staticObjects[this->staticObjects.Size() -1 ]->Init(modelData); + //modelData.visible = true; + //modelData.position = Oyster::Math::Float3(26, 127,0); + //modelData.rotation = total; + //modelData.scale = Oyster::Math::Float3(1,1,1); + //modelData.modelPath = L"char_still_sizeref.dan"; + //modelData.id = myId; - modelData.visible = true; - modelData.position = Oyster::Math::Float3(26, 127,0); - modelData.rotation = total; - modelData.scale = Oyster::Math::Float3(1,1,1); - modelData.modelPath = L"char_still_sizeref.dan"; - modelData.id = myId; - - this->staticObjects.Push(new C_StaticObj()); - this->staticObjects[this->staticObjects.Size() -1 ]->Init(modelData); + //this->staticObjects.Push(new C_StaticObj()); + //this->staticObjects[this->staticObjects.Size() -1 ]->Init(modelData); return true; @@ -302,13 +316,16 @@ void GameState::InitiatePlayer(int id, std::wstring modelName, Oyster::Math::Flo modelData.position = Oyster::Math::Float3(world[12], world[13], world[14]); modelData.rotation = Oyster::Math::Quaternion(Oyster::Math::Float3(0,0,0), 1); modelData.scale = Oyster::Math::Float3(1,1,1); - modelData.modelPath = modelName; + modelData.modelPath = L"crate_generic.dan"; // modelName; modelData.id = myId; obj = new C_Player(); this->dynamicObjects.Push(obj); - this->dynamicObjects[this->dynamicObjects.Size() -1 ]->Init(modelData); - + if(!this->dynamicObjects[this->dynamicObjects.Size() -1 ]->Init(modelData)) + { + // the model don't exist + this->dynamicObjects.Remove(this->dynamicObjects.Size() -1 ); + } Oyster::Math::Float3 right = Oyster::Math::Float3(world[0], world[1], world[2]); Oyster::Math::Float3 up = Oyster::Math::Float3(world[4], world[5], world[6]); diff --git a/Code/Misc/DynamicArray.h b/Code/Misc/DynamicArray.h index 8b4c98da..9d7bbc30 100644 --- a/Code/Misc/DynamicArray.h +++ b/Code/Misc/DynamicArray.h @@ -170,7 +170,7 @@ namespace Utility template void DynamicArray::Remove(unsigned int index) { - assert(index > (unsigned int) this->size); + assert(index < (unsigned int) this->size); T* temp = new T[this->capacity - 1];