GL - added id in object, vector

This commit is contained in:
Linda Andersson 2013-12-19 11:58:42 +01:00
parent 057dce0aca
commit ba6f7114b5
12 changed files with 56 additions and 44 deletions

View File

@ -8,6 +8,7 @@ namespace DanBias
struct ModelInitData
{
int id;
std::wstring modelPath;
Oyster::Math::Float4x4 world;
bool visible;
@ -24,5 +25,6 @@ public:
virtual void Render() = 0;
virtual void Release() = 0;
virtual int GetId() = 0;
};};};
#endif

View File

@ -5,6 +5,7 @@ struct C_DynamicObj::myData
{
myData(){}
Oyster::Graphics::Model::Model *model;
int ID;
// light
// sound
// effect
@ -40,3 +41,7 @@ void C_DynamicObj::Release()
Oyster::Graphics::API::DeleteModel(privData->model);
delete privData;
}
int C_DynamicObj::GetId()
{
return privData->ID;
}

View File

@ -18,5 +18,6 @@ public:
void Render();
void Release();
int GetId();
};};};
#endif

View File

@ -8,6 +8,7 @@ struct C_Player::myData
Oyster::Math3D::Float4x4 view;
Oyster::Math3D::Float4x4 proj;
Oyster::Graphics::Model::Model *model;
int ID;
}privData;
C_Player::C_Player(void)
@ -44,3 +45,7 @@ void C_Player::Release()
Oyster::Graphics::API::DeleteModel(privData->model);
delete privData;
}
int C_Player::GetId()
{
return privData->ID;
}

View File

@ -19,6 +19,7 @@ public:
void Render();
void Release();
int GetId();
};};};
#endif

View File

@ -7,6 +7,7 @@ struct C_StaticObj::myData
{
myData(){}
Oyster::Graphics::Model::Model *model;
int ID;
// light
// sound
// effect
@ -43,3 +44,7 @@ void C_StaticObj::Release()
Oyster::Graphics::API::DeleteModel(privData->model);
delete privData;
}
int C_StaticObj::GetId()
{
return privData->ID;
}

View File

@ -18,5 +18,6 @@ public:
void Render();
void Release();
int GetId();
};};};
#endif

View File

@ -5,9 +5,8 @@ using namespace DanBias::Client;
struct C_UIobject::myData
{
myData(){}
Oyster::Math3D::Float4x4 view;
Oyster::Math3D::Float4x4 proj;
Oyster::Graphics::Model::Model *model;
int ID;
}privData;
C_UIobject::C_UIobject(void)
@ -41,3 +40,7 @@ void C_UIobject::Release()
Oyster::Graphics::API::DeleteModel(privData->model);
delete privData;
}
int C_UIobject::GetId()
{
return privData->ID;
}

View File

@ -18,5 +18,6 @@ namespace DanBias
void Render();
void Release();
int GetId();
};};};
#endif

View File

@ -15,7 +15,7 @@ struct GameState::myData
myData(){}
Oyster::Math3D::Float4x4 view;
Oyster::Math3D::Float4x4 proj;
C_Object* object[3];
std::vector<C_Object*> object;
int modelCount;
Oyster::Network::NetworkClient* nwClient;
gameStateState state;
@ -59,15 +59,17 @@ bool GameState::LoadModels(std::wstring mapFile)
modelData.visible = true;
modelData.modelPath = L"worldDummy";
// load models
privData->object[0] = new C_Player();
privData->object[0]->Init(modelData);
C_Object* obj = new C_Player();
privData->object.push_back(obj);
privData->object[privData->object.size() -1 ]->Init(modelData);
Oyster::Math3D::Float4x4 translate = Oyster::Math3D::TranslationMatrix(Oyster::Math::Float3(2,2,2));
modelData.world = modelData.world * translate;
modelData.modelPath = L"crate";
privData->object[1] = new C_DynamicObj();
privData->object[1]->Init(modelData);
obj = new C_DynamicObj();
privData->object.push_back(obj);
privData->object[privData->object.size() -1 ]->Init(modelData);
return true;
}
bool GameState::InitCamera(Oyster::Math::Float3 startPos)
@ -174,7 +176,7 @@ bool GameState::Render()
}
bool GameState::Release()
{
for (int i = 0; i < privData->modelCount; i++)
for (int i = 0; i < privData->object.size(); i++)
{
privData->object[i]->Release();
delete privData->object[i];
@ -209,7 +211,11 @@ void GameState::Protocol( ObjPos* pos )
{
world[i] = pos->worldPos[i];
}
privData->object[pos->object_ID]->setPos(world);
for (int i = 0; i < privData->object.size(); i++)
{
if(privData->object[i]->GetId() == pos->object_ID)
privData->object[i]->setPos(world);
}
}
void GameState::Protocol( NewObj* pos )
@ -224,45 +230,29 @@ void GameState::Protocol( NewObj* pos )
modelData.world = world;
modelData.visible = true;
modelData.id = pos->object_ID;
//not sure if this is good parsing rom char* to wstring
const char* path = pos->path;
modelData.modelPath = std::wstring(path, path + strlen(path));
// load models
privData->object[pos->object_ID] = new C_Player();
privData->object[pos->object_ID]->Init(modelData);
}
C_Object* player = new C_Player();
player->Init(modelData);
privData->object.push_back(player);
void GameState::Protocol( KeyInput* pos )
{
bool key = false;
for (int i = 0; i < 6; i++)
{
key = pos->key[i];
}
}
void DanBias::Client::GameState::Protocol( RemoveObj* obj )
{
privData->object[obj->object_ID]->Release( );
for (int i = 0; i < privData->object.size(); i++)
{
if(privData->object[i]->GetId() == obj->object_ID)
{
privData->object.at(i)->Release();
privData->object.erase(privData->object.begin() + i );
}
}
//privData->object[obj->object_ID]->Release( );
}
void GameState::PlayerPosProtocol(PlayerPos* pos)
{
Oyster::Math::Float4x4 world, translate;
world = Oyster::Math::Float4x4::identity;
translate = Oyster::Math::Float4x4::identity;
translate = Oyster::Math3D::TranslationMatrix(Oyster::Math::Float3(pos->playerPos[0],pos->playerPos[1],pos->playerPos[2] ));
world = translate;
privData->object[0]->setPos( world );
}
void GameState::ObjectPosProtocol(ObjPos* pos)
{
Oyster::Math::Float4x4 world;
for(int i = 0; i<16; i++)
{
world[i] = pos->worldPos[i];
}
privData->object[1]->setPos(world);
}
//void GameState::Protocol(LightPos pos);

View File

@ -34,11 +34,8 @@ public:
void Protocol(ProtocolStruct* pos)override;
void Protocol(PlayerPos* pos);
void Protocol(ObjPos* pos);
void Protocol(KeyInput* pos);
void Protocol( NewObj* pos );
void Protocol(RemoveObj* obj);
void PlayerPosProtocol(PlayerPos* pos);
void ObjectPosProtocol(ObjPos* pos);
//void Protocol(LightPos pos);
};
};

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)
@ -29,7 +29,8 @@ int WINAPI WinMain( HINSTANCE hinst, HINSTANCE prevInst, PSTR cmdLine, int cmdSh
// Game client starter code goes here
DanBias::DanBiasGameDesc gameDesc;
gameDesc.port = 15151;
gameDesc.IP = "193.11.184.196";
//gameDesc.IP = "193.11.184.196"; //Erik
gameDesc.IP = "193.11.186.101";
gameDesc.hinst = hinst;
gameDesc.nCmdShow = cmdShow;