GL - handle if the model dose not exist

This commit is contained in:
lindaandersson 2014-02-14 15:07:55 +01:00
parent 68dfd2e324
commit bfb9864be9
12 changed files with 89 additions and 50 deletions

View File

@ -1,14 +1,31 @@
#include "C_Object.h" #include "C_Object.h"
using namespace DanBias::Client; 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; position = modelInit.position;
rotation = modelInit.rotation; rotation = modelInit.rotation;
scale = modelInit.scale; scale = modelInit.scale;
id = modelInit.id; id = modelInit.id;
model = Oyster::Graphics::API::CreateModel(modelInit.modelPath); model = Oyster::Graphics::API::CreateModel(modelInit.modelPath);
if(model == NULL)
return false;
model->Visible = modelInit.visible; model->Visible = modelInit.visible;
updateWorld(); updateWorld();
return true;
} }
void C_Object::updateWorld() void C_Object::updateWorld()
{ {

View File

@ -29,8 +29,9 @@ private:
protected: protected:
Oyster::Graphics::Model::Model *model; Oyster::Graphics::Model::Model *model;
public: public:
C_Object();
virtual void Init(ModelInitData modelInit); virtual ~C_Object();
virtual bool Init(ModelInitData modelInit);
void setWorld(Oyster::Math::Float4x4 world); void setWorld(Oyster::Math::Float4x4 world);
Oyster::Math::Float4x4 getWorld() const; Oyster::Math::Float4x4 getWorld() const;

View File

@ -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);
} }

View File

@ -11,7 +11,7 @@ private:
public: public:
C_DynamicObj(void); C_DynamicObj(void);
virtual ~C_DynamicObj(void); virtual ~C_DynamicObj(void);
void Init(ModelInitData modelInit); bool Init(ModelInitData modelInit);
};};}; };};};
#endif #endif

View File

@ -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); return C_Object::Init(modelInit);
Oyster::Graphics::API::PlayAnimation(model, L"movement"); }
//Oyster::Graphics::API::Update(0.002f); void C_Player::playAnimation(std::wstring animation, bool loop)
{
if(model)
Oyster::Graphics::API::PlayAnimation(model, L"movement", loop);
} }

View File

@ -11,7 +11,8 @@ private:
public: public:
C_Player(void); C_Player(void);
virtual ~C_Player(void); virtual ~C_Player(void);
void Init(ModelInitData modelInit); bool Init(ModelInitData modelInit);
void playAnimation(std::wstring animation, bool loop);
};};}; };};};
#endif #endif

View File

@ -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);
} }

View File

@ -11,7 +11,7 @@ private:
public: public:
C_StaticObj(void); C_StaticObj(void);
virtual ~C_StaticObj(void); virtual ~C_StaticObj(void);
void Init(ModelInitData modelInit); bool Init(ModelInitData modelInit);
};};}; };};};
#endif #endif

View File

@ -10,7 +10,7 @@ C_UIobject::C_UIobject(void)
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);
} }

View File

@ -12,7 +12,7 @@ namespace DanBias
public: public:
C_UIobject(void); C_UIobject(void);
virtual ~C_UIobject(void); virtual ~C_UIobject(void);
void Init(ModelInitData modelInit); bool Init(ModelInitData modelInit);
void setPos(Oyster::Math::Float4x4 world); void setPos(Oyster::Math::Float4x4 world);
};};}; };};};
#endif #endif

View File

@ -195,7 +195,12 @@ bool GameState::LoadModels(std::string mapFile)
modelData.id = modelId++; modelData.id = modelId++;
this->staticObjects.Push(new C_StaticObj()); 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; break;
case GameLogic::ObjectType::ObjectType_Dynamic: case GameLogic::ObjectType::ObjectType_Dynamic:
@ -209,7 +214,12 @@ bool GameState::LoadModels(std::string mapFile)
modelData.id = modelId++; modelData.id = modelId++;
this->dynamicObjects.Push(new C_DynamicObj()); 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; break;
case GameLogic::ObjectType::ObjectType_Light: case GameLogic::ObjectType::ObjectType_Light:
@ -241,40 +251,44 @@ bool GameState::LoadModels(std::string mapFile)
modelData.rotation = first; modelData.rotation = first;
modelData.scale = Oyster::Math::Float3(1,1,1); modelData.scale = Oyster::Math::Float3(1,1,1);
modelData.modelPath = L"char_still_sizeref.dan"; modelData.modelPath = L"char_still_sizeref.dan";
modelData.id = myId; modelData.id = modelId;
this->staticObjects.Push(new C_StaticObj()); 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; //this->staticObjects.Push(new C_StaticObj());
modelData.position = Oyster::Math::Float3(22, 127,0); //this->staticObjects[this->staticObjects.Size() -1 ]->Init(modelData);
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()); //modelData.visible = true;
this->staticObjects[this->staticObjects.Size() -1 ]->Init(modelData); //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; //this->staticObjects.Push(new C_StaticObj());
modelData.position = Oyster::Math::Float3(24, 127,0); //this->staticObjects[this->staticObjects.Size() -1 ]->Init(modelData);
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()); //modelData.visible = true;
this->staticObjects[this->staticObjects.Size() -1 ]->Init(modelData); //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; //this->staticObjects.Push(new C_StaticObj());
modelData.position = Oyster::Math::Float3(26, 127,0); //this->staticObjects[this->staticObjects.Size() -1 ]->Init(modelData);
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);
return true; 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.position = Oyster::Math::Float3(world[12], world[13], world[14]);
modelData.rotation = Oyster::Math::Quaternion(Oyster::Math::Float3(0,0,0), 1); modelData.rotation = Oyster::Math::Quaternion(Oyster::Math::Float3(0,0,0), 1);
modelData.scale = Oyster::Math::Float3(1,1,1); modelData.scale = Oyster::Math::Float3(1,1,1);
modelData.modelPath = modelName; modelData.modelPath = L"crate_generic.dan"; // modelName;
modelData.id = myId; modelData.id = myId;
obj = new C_Player(); obj = new C_Player();
this->dynamicObjects.Push(obj); 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 right = Oyster::Math::Float3(world[0], world[1], world[2]);
Oyster::Math::Float3 up = Oyster::Math::Float3(world[4], world[5], world[6]); Oyster::Math::Float3 up = Oyster::Math::Float3(world[4], world[5], world[6]);

View File

@ -170,7 +170,7 @@ namespace Utility
template <typename T> void DynamicArray<T>::Remove(unsigned int index) template <typename T> void DynamicArray<T>::Remove(unsigned int index)
{ {
assert(index > (unsigned int) this->size); assert(index < (unsigned int) this->size);
T* temp = new T[this->capacity - 1]; T* temp = new T[this->capacity - 1];