diff --git a/Code/Code.rar b/Code/Code.rar new file mode 100644 index 00000000..e048199d Binary files /dev/null and b/Code/Code.rar differ diff --git a/Code/Game/DanBiasGame/DanBiasGame.vcxproj b/Code/Game/DanBiasGame/DanBiasGame.vcxproj index 01a92481..83806118 100644 --- a/Code/Game/DanBiasGame/DanBiasGame.vcxproj +++ b/Code/Game/DanBiasGame/DanBiasGame.vcxproj @@ -205,6 +205,10 @@ + + + + @@ -219,6 +223,11 @@ + + + + + diff --git a/Code/Game/DanBiasGame/GameClientState/C_Object.cpp b/Code/Game/DanBiasGame/GameClientState/C_Object.cpp index 840e6267..11d4dd7d 100644 --- a/Code/Game/DanBiasGame/GameClientState/C_Object.cpp +++ b/Code/Game/DanBiasGame/GameClientState/C_Object.cpp @@ -1,4 +1,71 @@ #include "C_Object.h" using namespace DanBias::Client; +void C_Object::Init(ModelInitData modelInit) +{ + position = modelInit.position; + rotation = modelInit.rotation; + scale = modelInit.scale; + updateWorld(); +} +void C_Object::updateWorld() +{ + Oyster::Math3D::Float4x4 translation = Oyster::Math3D::TranslationMatrix(this->position); + Oyster::Math3D::Float4x4 rot = Oyster::Math3D::RotationMatrix(this->rotation); + //Oyster::Math3D::Float4x4 scale = Oyster::Math3D::; + Oyster::Math3D::Float4x4 scale = Oyster::Math3D::Matrix::identity; + scale.v[0].x = this->scale[0]; + scale.v[1].y = this->scale[1]; + scale.v[2].z = this->scale[2]; + world = translation * rot * scale; +} +void C_Object::setWorld(Oyster::Math::Float4x4 world) +{ +} +Oyster::Math::Float4x4 C_Object::getWorld() const +{ + return world; +} +void C_Object::setPos(Oyster::Math::Float3 newPos) +{ + this->position = newPos; + updateWorld(); +} +void C_Object::addPos(Oyster::Math::Float3 deltaPos) +{ + this->position += deltaPos; + updateWorld(); +} +Oyster::Math::Float3 C_Object::getPos() const +{ + return this->position; +} +void C_Object::setRot(Oyster::Math::Quaternion newRot) +{ + this->rotation = newRot; + updateWorld(); +} +void C_Object::addRot(Oyster::Math::Quaternion deltaRot) +{ + this->rotation += deltaRot; + updateWorld(); +} +Oyster::Math::Quaternion C_Object::getRotation() const +{ + return this->rotation; +} +void C_Object::setScale(Oyster::Math::Float3 newScale) +{ + this->scale = newScale; + updateWorld(); +} +void C_Object::addScale(Oyster::Math::Float3 deltaScale) +{ + this->scale += deltaScale; + updateWorld(); +} +Oyster::Math::Float3 C_Object::getScale() const +{ + return this->scale; +} diff --git a/Code/Game/DanBiasGame/GameClientState/C_Object.h b/Code/Game/DanBiasGame/GameClientState/C_Object.h index 1b87174b..4782270c 100644 --- a/Code/Game/DanBiasGame/GameClientState/C_Object.h +++ b/Code/Game/DanBiasGame/GameClientState/C_Object.h @@ -10,21 +10,38 @@ namespace DanBias { int id; std::wstring modelPath; - Oyster::Math::Float4x4 world; + Oyster::Math::Float3 position; + Oyster::Math::Quaternion rotation; + Oyster::Math::Float3 scale; bool visible; }; class C_Object { private: - + Oyster::Math::Float4x4 world; + Oyster::Math::Float3 position; + Oyster::Math::Quaternion rotation; + Oyster::Math::Float3 scale; + void updateWorld(); public: - virtual void Init(ModelInitData modelInit) = 0; - virtual void setPos(Oyster::Math::Float4x4 world) = 0; + virtual void Init(ModelInitData modelInit); + + void setWorld(Oyster::Math::Float4x4 world); + Oyster::Math::Float4x4 getWorld() const; + void setPos(Oyster::Math::Float3 newPos); + Oyster::Math::Float3 getPos() const; + void addPos(Oyster::Math::Float3 deltaPos); + void setRot(Oyster::Math::Quaternion newRot); + Oyster::Math::Quaternion getRotation() const; + void addRot(Oyster::Math::Quaternion deltaRot); + void setScale(Oyster::Math::Float3 newScale); + void addScale(Oyster::Math::Float3 deltaScale); + Oyster::Math::Float3 getScale() const; virtual void Render() = 0; virtual void Release() = 0; - virtual int GetId() = 0; + int GetId(); };};}; #endif diff --git a/Code/Game/DanBiasGame/GameClientState/C_obj/C_DynamicObj.cpp b/Code/Game/DanBiasGame/GameClientState/C_obj/C_DynamicObj.cpp index 3df74e40..71c46f4a 100644 --- a/Code/Game/DanBiasGame/GameClientState/C_obj/C_DynamicObj.cpp +++ b/Code/Game/DanBiasGame/GameClientState/C_obj/C_DynamicObj.cpp @@ -21,17 +21,14 @@ C_DynamicObj::~C_DynamicObj(void) } void C_DynamicObj::Init(ModelInitData modelInit) { + C_Object::Init(modelInit); // load models privData = new myData(); privData->model = Oyster::Graphics::API::CreateModel(modelInit.modelPath); - privData->model->WorldMatrix = modelInit.world; privData->model->Visible = modelInit.visible; + privData->model->WorldMatrix = getWorld(); privData->ID = modelInit.id; } -void C_DynamicObj::setPos(Oyster::Math::Float4x4 world) -{ - privData->model->WorldMatrix = world; -} void C_DynamicObj::Render() { diff --git a/Code/Game/DanBiasGame/GameClientState/C_obj/C_DynamicObj.h b/Code/Game/DanBiasGame/GameClientState/C_obj/C_DynamicObj.h index ee25a992..d8e7023a 100644 --- a/Code/Game/DanBiasGame/GameClientState/C_obj/C_DynamicObj.h +++ b/Code/Game/DanBiasGame/GameClientState/C_obj/C_DynamicObj.h @@ -14,7 +14,6 @@ public: C_DynamicObj(void); virtual ~C_DynamicObj(void); void Init(ModelInitData modelInit); - void setPos(Oyster::Math::Float4x4 world); void Render(); void Release(); diff --git a/Code/Game/DanBiasGame/GameClientState/C_obj/C_Player.cpp b/Code/Game/DanBiasGame/GameClientState/C_obj/C_Player.cpp index 49c450b5..5e5525e9 100644 --- a/Code/Game/DanBiasGame/GameClientState/C_obj/C_Player.cpp +++ b/Code/Game/DanBiasGame/GameClientState/C_obj/C_Player.cpp @@ -13,6 +13,7 @@ struct C_Player::myData }privData; C_Player::C_Player(void) + :C_DynamicObj() { } @@ -24,18 +25,16 @@ C_Player::~C_Player(void) void C_Player::Init(ModelInitData modelInit) { + C_Object::Init(modelInit); // load models privData = new myData(); privData->model = Oyster::Graphics::API::CreateModel(modelInit.modelPath); - privData->model->WorldMatrix = modelInit.world; privData->model->Visible = modelInit.visible; + privData->model->WorldMatrix = getWorld(); privData->ID = modelInit.id; privData->lookDir = Oyster::Math3D::Float4 (0,0,1,0); } -void C_Player::setPos(Oyster::Math::Float4x4 world) -{ - privData->model->WorldMatrix = world; -} + void C_Player::Render() { diff --git a/Code/Game/DanBiasGame/GameClientState/C_obj/C_Player.h b/Code/Game/DanBiasGame/GameClientState/C_obj/C_Player.h index 794bf51a..556fd6dc 100644 --- a/Code/Game/DanBiasGame/GameClientState/C_obj/C_Player.h +++ b/Code/Game/DanBiasGame/GameClientState/C_obj/C_Player.h @@ -1,21 +1,20 @@ #ifndef DANBIAS_CLIENT_CPLAYER_H #define DANBIAS_CLIENT_CPLAYER_H -#include "../C_Object.h" +#include "C_DynamicObj.h" namespace DanBias { namespace Client { -class C_Player : public C_Object +class C_Player : public C_DynamicObj { private: struct myData; myData* privData; - //Oyster::Graphics:: LIght + public: C_Player(void); - ~C_Player(void); + virtual ~C_Player(void); void Init(ModelInitData modelInit); - void setPos(Oyster::Math::Float4x4 world); void Render(); void Release(); diff --git a/Code/Game/DanBiasGame/GameClientState/C_obj/C_StaticObj.cpp b/Code/Game/DanBiasGame/GameClientState/C_obj/C_StaticObj.cpp index 177b032b..6e7a20e9 100644 --- a/Code/Game/DanBiasGame/GameClientState/C_obj/C_StaticObj.cpp +++ b/Code/Game/DanBiasGame/GameClientState/C_obj/C_StaticObj.cpp @@ -8,9 +8,7 @@ struct C_StaticObj::myData myData(){} Oyster::Graphics::Model::Model *model; int ID; - // light - // sound - // effect + }privData; C_StaticObj::C_StaticObj(void) { @@ -23,18 +21,16 @@ C_StaticObj::~C_StaticObj(void) } void C_StaticObj::Init(ModelInitData modelInit) { + C_Object::Init(modelInit); // load models privData = new myData(); privData->model = Oyster::Graphics::API::CreateModel(modelInit.modelPath); - privData->model->WorldMatrix = modelInit.world; privData->model->Visible = modelInit.visible; + privData->model->WorldMatrix = getWorld(); privData->ID = modelInit.id; } -void C_StaticObj::setPos(Oyster::Math::Float4x4 world) -{ - privData->model->WorldMatrix = world; -} + void C_StaticObj::Render() { diff --git a/Code/Game/DanBiasGame/GameClientState/C_obj/C_StaticObj.h b/Code/Game/DanBiasGame/GameClientState/C_obj/C_StaticObj.h index 799c0982..3bae1961 100644 --- a/Code/Game/DanBiasGame/GameClientState/C_obj/C_StaticObj.h +++ b/Code/Game/DanBiasGame/GameClientState/C_obj/C_StaticObj.h @@ -14,7 +14,6 @@ public: C_StaticObj(void); virtual ~C_StaticObj(void); void Init(ModelInitData modelInit); - void setPos(Oyster::Math::Float4x4 world); void Render(); void Release(); diff --git a/Code/Game/DanBiasGame/GameClientState/C_obj/C_UIobject.cpp b/Code/Game/DanBiasGame/GameClientState/C_obj/C_UIobject.cpp index fa5dff04..fc9c7d53 100644 --- a/Code/Game/DanBiasGame/GameClientState/C_obj/C_UIobject.cpp +++ b/Code/Game/DanBiasGame/GameClientState/C_obj/C_UIobject.cpp @@ -19,11 +19,12 @@ C_UIobject::~C_UIobject(void) } void C_UIobject::Init(ModelInitData modelInit) { + C_Object::Init(modelInit); // load models privData = new myData(); privData->model = Oyster::Graphics::API::CreateModel(modelInit.modelPath); - privData->model->WorldMatrix = modelInit.world; privData->model->Visible = modelInit.visible; + privData->model->WorldMatrix = getWorld(); privData->ID = modelInit.id; } diff --git a/Code/Game/DanBiasGame/GameClientState/GameState.cpp b/Code/Game/DanBiasGame/GameClientState/GameState.cpp index d8547943..8dfd99f5 100644 --- a/Code/Game/DanBiasGame/GameClientState/GameState.cpp +++ b/Code/Game/DanBiasGame/GameClientState/GameState.cpp @@ -1,20 +1,16 @@ #include "GameState.h" #include "DllInterfaces/GFXAPI.h" -#include "C_obj/C_Player.h" -#include "C_obj/C_DynamicObj.h" #include #include "NetworkClient.h" #include "Camera.h" #include using namespace DanBias::Client; - +using namespace Oyster::Math; struct GameState::myData { myData(){} - Oyster::Math3D::Float4x4 view; - Oyster::Math3D::Float4x4 proj; - std::vector object; + //std::vector object; int modelCount; Oyster::Network::NetworkClient* nwClient; gameStateState state; @@ -49,39 +45,123 @@ bool GameState::Init(Oyster::Network::NetworkClient* nwClient) GameState::gameStateState GameState::LoadGame() { Oyster::Graphics::Definitions::Pointlight plight; - plight.Pos = Oyster::Math::Float3(315, 0 ,5); - plight.Color = Oyster::Math::Float3(0.9,0.7,0.2); + plight.Pos = Float3(315, 0 ,5); + plight.Color = Float3(0.9f,0.7f,0.2f); plight.Radius = 100; - plight.Bright = 0.9; + plight.Bright = 0.9f; Oyster::Graphics::API::AddLight(plight); - plight.Pos = Oyster::Math::Float3(10,350,5); - plight.Color = Oyster::Math::Float3(0.9,0.7,0.3); + plight.Pos = Float3(10,350,5); + plight.Color = Float3(0.9f,0.7f,0.3f); plight.Radius = 200; - plight.Bright = 0.7; + plight.Bright = 0.7f; Oyster::Graphics::API::AddLight(plight); - plight.Pos = Oyster::Math::Float3(350,350,5); - plight.Color = Oyster::Math::Float3(0.9,0.7,0.3); + plight.Pos = Float3(350,350,5); + plight.Color = Float3(0.9f,0.7f,0.3f); plight.Radius = 200; - plight.Bright = 0.7; + plight.Bright = 0.7f; Oyster::Graphics::API::AddLight(plight); - plight.Pos = Oyster::Math::Float3(10,350,350); - plight.Color = Oyster::Math::Float3(0.9,0.7,0.3); + plight.Pos = Float3(10,350,350); + plight.Color = Float3(0.9f,0.7f,0.3f); plight.Radius = 200; - plight.Bright = 0.7; + plight.Bright = 0.7f; Oyster::Graphics::API::AddLight(plight); - plight.Pos = Oyster::Math::Float3(10,-15,5); - plight.Color = Oyster::Math::Float3(0,0,1); + plight.Pos = Float3(10,-15,5); + plight.Color = Float3(0,0,1); plight.Radius = 50; plight.Bright = 2; Oyster::Graphics::API::AddLight(plight); - LoadModels(L"map"); - InitCamera(Oyster::Math::Float3(0,0,20.0f)); + LoadModels("3bana.bias"); + Float3 startPos = Float3(0,0,20.0f); + InitCamera(startPos); return gameStateState_playing; } -bool GameState::LoadModels(std::wstring mapFile) +bool GameState::LoadModels(std::string mapFile) { - // open file + GameLogic::LevelLoader levelLoader; + std::vector> objects; + objects = levelLoader.LoadLevel(mapFile); + + int objCount = objects.size(); + int modelId = 0; + ModelInitData modelData; + for (int i = 0; i < objCount; i++) + { + GameLogic::ObjectTypeHeader* obj = objects.at(i); + + switch (obj->typeID) + { + case GameLogic::ObjectType::ObjectType_LevelMetaData: + + break; + case GameLogic::ObjectType::ObjectType_Static: + { + GameLogic::ObjectHeader* staticObjData = ((GameLogic::ObjectHeader*)obj); + + modelData.modelPath.assign(staticObjData->ModelFile.begin(), staticObjData->ModelFile.end()); + modelData.visible = true; + //modelData.position = ; + //modelData.rotation = Oyster::Math::Quaternion(Oyster::Math::Float3(2,2,-2), 1); + //modelData.scale = Oyster::Math::Float3(2,2,2); + modelData.id = modelId++; + + this->staticObjects.Push(new C_StaticObj()); + this->staticObjects[this->staticObjects.Size() -1 ]->Init(modelData); + } + break; + case GameLogic::ObjectType::ObjectType_Dynamic: + { + GameLogic::ObjectHeader* dynamicObjData = ((GameLogic::ObjectHeader*)obj); + //modelData.position = ; + //modelData.rotation = Oyster::Math::Quaternion(Oyster::Math::Float3(2,2,-2), 1); + //modelData.scale = Oyster::Math::Float3(2,2,2); + modelData.modelPath.assign(dynamicObjData->ModelFile.begin(), dynamicObjData->ModelFile.end()); + modelData.visible = true; + modelData.id = modelId++; + + this->dynamicObjects.Push(new C_DynamicObj()); + this->dynamicObjects[this->dynamicObjects.Size() -1 ]->Init(modelData); + } + break; + case GameLogic::ObjectType::ObjectType_Light: + { + GameLogic::BasicLight* lightData = ((GameLogic::BasicLight*)obj); + + if(lightData->lightType == GameLogic::LightType_PointLight) + { + Oyster::Graphics::Definitions::Pointlight plight; + plight.Pos = ((GameLogic::PointLight*)lightData)->position; + plight.Color = lightData->diffuseColor; + plight.Radius = 100; + plight.Bright = 0.9f; + Oyster::Graphics::API::AddLight(plight); + } + } + break; + default: + break; + } + } + myId += modelId++; + // add player model + //modelData.position = ; + //modelData.rotation = Oyster::Math::Quaternion(Oyster::Math::Float3(2,2,-2), 1); + //modelData.scale = Oyster::Math::Float3(2,2,2); + + + modelData.visible = true; + modelData.modelPath = L"char_still_sizeref.dan"; + modelData.id = myId; + // load models + this->dynamicObjects.Push(new C_DynamicObj()); + this->dynamicObjects[this->dynamicObjects.Size() -1 ]->Init(modelData); + + /*C_Player* obj = new C_Player(); + privData->object.push_back(obj); + privData->object[privData->object.size() -1 ]->Init(modelData); + */ + return true; + /*// open file // read file // init models int nrOfBoxex = 20; @@ -199,27 +279,18 @@ bool GameState::LoadModels(std::wstring mapFile) // load models obj = new C_Player(); privData->object.push_back(obj); - privData->object[privData->object.size() -1 ]->Init(modelData); - - return true; + privData->object[privData->object.size() -1 ]->Init(modelData); */ } -bool GameState::InitCamera(Oyster::Math::Float3 startPos) +bool GameState::InitCamera(Float3 startPos) { - Oyster::Math::Float3 dir = Oyster::Math::Float3(0,0,1); - Oyster::Math::Float3 up =Oyster::Math::Float3(0,1,0); - Oyster::Math::Float3 pos = Oyster::Math::Float3(0, 0, 20); - + Float3 dir = Float3(0,0,1); + Float3 up = Float3(0,1,0); + Float3 pos = Float3(0, 0, 20); camera->LookAt(pos, dir, up); - camera->SetLens(3.14f/2, 1024/768, 1, 1000); - - privData->proj = Oyster::Math3D::ProjectionMatrix_Perspective(Oyster::Math::pi/4,1024.0f/768.0f,.1f,1000); - //privData->proj = Oyster::Math3D::ProjectionMatrix_Orthographic(1024, 768, 1, 1000); - Oyster::Graphics::API::SetProjection(privData->proj); + camera->SetLens(pi/4, 1024/768, 1, 1000); camera->UpdateViewMatrix(); - privData->view = camera->View(); - privData->view = Oyster::Math3D::ViewMatrix_LookAtDirection(Oyster::Math::Float3(0,0,-1),Oyster::Math::Float3(0,1,0),startPos); - privData->view = Oyster::Math3D::OrientationMatrix_LookAtDirection(Oyster::Math::Float3(0,0,-1),Oyster::Math::Float3(0,1,0),startPos); - privData->view = Oyster::Math3D::InverseOrientationMatrix(privData->view); + Oyster::Graphics::API::SetProjection(camera->Proj()); + return true; } void GameState::setClientId(int id) @@ -263,25 +334,28 @@ GameClientState::ClientState GameState::Update(float deltaTime, InputClass* KeyI bool GameState::Render() { Oyster::Graphics::API::SetView(camera->View()); - //Oyster::Graphics::API::SetProjection(camera->Proj()); - //Oyster::Graphics::API::SetView(privData->view); - Oyster::Graphics::API::SetProjection(privData->proj); + Oyster::Graphics::API::NewFrame(); - for (unsigned int i = 0; i < privData->object.size(); i++) + for (unsigned int i = 0; i < staticObjects.Size(); i++) { - privData->object[i]->Render(); + staticObjects[i]->Render(); } + for (unsigned int i = 0; i < dynamicObjects.Size(); i++) + { + dynamicObjects[i]->Render(); + } + Oyster::Graphics::API::EndFrame(); return true; } bool GameState::Release() { - for (unsigned int i = 0; i < privData->object.size(); i++) + /*for (unsigned int i = 0; i < privData->object.size(); i++) { - privData->object[i]->Release(); - delete privData->object[i]; - privData->object[i] = NULL; - } + privData->object[i]->Release(); + delete privData->object[i]; + privData->object[i] = NULL; + }*/ delete privData; privData = NULL; @@ -440,13 +514,17 @@ void GameState::Protocol(ProtocolStruct* pos) void GameState::Protocol( PlayerPos* pos ) { - Oyster::Math::Float4x4 world, translate; + //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 = world * translate; - privData->object[0]->setPos( world ); + //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 = world * translate; + ////privData->object[0]->setPos( world ); + //for (unsigned int i = 0; i < dynamicObjects.Size(); i++) + //{ + // dynamicObjects[i]->Render(); + //} } void GameState::Protocol( ObjPos* pos ) @@ -457,21 +535,21 @@ void GameState::Protocol( ObjPos* pos ) world[i] = pos->worldPos[i]; } //printf("pos for obj %d, ",pos->object_ID ); - for (unsigned int i = 0; i < privData->object.size(); i++) + for (unsigned int i = 0; i < dynamicObjects.Size(); i++) { - if(privData->object[i]->GetId() == pos->object_ID) + if(dynamicObjects[i]->GetId() == pos->object_ID) { - privData->object[i]->setPos(world); + dynamicObjects[i]->setWorld(world); - if(i == myId) // playerobj + if(dynamicObjects[i]->GetId() == myId) // playerobj { - 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 objForward = (Oyster::Math::Float3(world[8], world[9], world[10])); - Oyster::Math::Float3 pos = Oyster::Math::Float3(world[12], world[13], world[14]); + Float3 right = Float3(world[0], world[1], world[2]); + Float3 up = Float3(world[4], world[5], world[6]); + Float3 objForward = Float3(world[8], world[9], world[10]); + Float3 pos = Float3(world[12], world[13], world[14]); - Oyster::Math::Float3 cameraLook = camera->GetLook(); - Oyster::Math::Float3 cameraUp = camera->GetUp(); + Float3 cameraLook = camera->GetLook(); + Float3 cameraUp = camera->GetUp(); @@ -506,28 +584,29 @@ void GameState::Protocol( NewObj* newObj ) } ModelInitData modelData; - modelData.world = world; + //modelData.world = world; modelData.visible = true; modelData.id = newObj->object_ID; //not sure if this is good parsing rom char* to wstring const char* path = newObj->path; modelData.modelPath = std::wstring(path, path + strlen(path)); // load models - C_Object* player = new C_Player(); + C_DynamicObj* player = new C_DynamicObj(); player->Init(modelData); - privData->object.push_back(player); + dynamicObjects.Push(player); } void DanBias::Client::GameState::Protocol( RemoveObj* obj ) { - for (unsigned int i = 0; i < privData->object.size(); i++) + for (unsigned int i = 0; i < dynamicObjects.Size(); i++) { - if(privData->object[i]->GetId() == obj->object_ID) + if(dynamicObjects[i]->GetId() == obj->object_ID) { - privData->object.at(i)->Release(); - privData->object.erase(privData->object.begin() + i ); + //dynamicObjects[i]->Release(); + dynamicObjects[i].Release(); + //dynamicObjects.erase(privData->object.begin() + i ); } } //privData->object[obj->object_ID]->Release( ); diff --git a/Code/Game/DanBiasGame/GameClientState/GameState.h b/Code/Game/DanBiasGame/GameClientState/GameState.h index d555134c..425fb2be 100644 --- a/Code/Game/DanBiasGame/GameClientState/GameState.h +++ b/Code/Game/DanBiasGame/GameClientState/GameState.h @@ -4,6 +4,11 @@ #include "OysterMath.h" #include #include "Camera.h" +#include "LevelLoader/LevelLoader.h" +#include "C_obj/C_Player.h" +#include "C_obj/C_DynamicObj.h" +#include "C_obj/C_StaticObj.h" +#include "DynamicArray.h" namespace DanBias { namespace Client @@ -30,12 +35,15 @@ private: float pitch; struct myData; myData* privData; + Utility::DynamicMemory::DynamicArray> staticObjects; + Utility::DynamicMemory::DynamicArray> dynamicObjects; + Utility::DynamicMemory::DynamicArray> playObjects; public: GameState(void); ~GameState(void); bool Init(Oyster::Network::NetworkClient* nwClient); GameClientState::ClientState Update(float deltaTime, InputClass* KeyInput) override; - bool LoadModels(std::wstring mapFile) ; + bool LoadModels(std::string mapFile) ; bool InitCamera(Oyster::Math::Float3 startPos) ; gameStateState LoadGame(); void setClientId(int id); diff --git a/Code/Game/DanBiasGame/GameClientState/LanMenuState.cpp b/Code/Game/DanBiasGame/GameClientState/LanMenuState.cpp index 8df39bfa..092307af 100644 --- a/Code/Game/DanBiasGame/GameClientState/LanMenuState.cpp +++ b/Code/Game/DanBiasGame/GameClientState/LanMenuState.cpp @@ -64,15 +64,16 @@ bool LanMenuState::LoadModels(std::wstring file) ModelInitData modelData; - modelData.world = Oyster::Math3D::Float4x4::identity; + modelData.position = Oyster::Math::Float3(0,0,0); + modelData.rotation = Oyster::Math::Quaternion::identity; + modelData.scale = Oyster::Math::Float3(1,1,1); modelData.visible = true; modelData.modelPath = L"..\\Content\\Models\\box_2.dan"; // load models privData->object[0] = new C_StaticObj(); privData->object[0]->Init(modelData); - Oyster::Math3D::Float4x4 translate = Oyster::Math3D::TranslationMatrix(Oyster::Math::Float3(-2,-2,-2)); - modelData.world = modelData.world * translate; + modelData.position = Oyster::Math::Float3(-2, -2, -2); privData->object[1] = new C_DynamicObj(); privData->object[1]->Init(modelData); diff --git a/Code/Game/DanBiasGame/GameClientState/LevelLoader/LevelLoader.cpp b/Code/Game/DanBiasGame/GameClientState/LevelLoader/LevelLoader.cpp new file mode 100644 index 00000000..55a39725 --- /dev/null +++ b/Code/Game/DanBiasGame/GameClientState/LevelLoader/LevelLoader.cpp @@ -0,0 +1,35 @@ +////////////////////////////////// +// Created by Sam Svensson 2013 // +////////////////////////////////// + +#include "LevelLoader.h" +#include "LevelParser.h" + +using namespace GameLogic; +using namespace GameLogic::LevelFileLoader; + +struct LevelLoader::PrivData +{ + LevelParser parser; + std::string folderPath; +}; + +LevelLoader::LevelLoader() + : pData(new PrivData) +{ + pData->folderPath = "Standard path"; +} + +LevelLoader::~LevelLoader() +{ +} + +std::vector> LevelLoader::LoadLevel(std::string fileName) +{ + return pData->parser.Parse(fileName); +} + +LevelMetaData LevelLoader::LoadLevelHeader(std::string fileName) +{ + return pData->parser.ParseHeader(fileName); +} \ No newline at end of file diff --git a/Code/Game/DanBiasGame/GameClientState/LevelLoader/LevelLoader.h b/Code/Game/DanBiasGame/GameClientState/LevelLoader/LevelLoader.h new file mode 100644 index 00000000..bcd6e587 --- /dev/null +++ b/Code/Game/DanBiasGame/GameClientState/LevelLoader/LevelLoader.h @@ -0,0 +1,42 @@ +////////////////////////////////// +// Created by Sam Svensson 2013 // +////////////////////////////////// + +#ifndef LEVELLOADER_H +#define LEVELLOADER_H + +#include +#include +#include "../Misc/Utilities.h" +#include "ObjectDefines.h" + +namespace GameLogic +{ + class LevelLoader + { + + public: + LevelLoader(); + ~LevelLoader(); + + /******************************************************** + * Loads the level and objects from file. + * @param fileName: Path to the level-file that you want to load. + * @return: Returns all structs with objects and information about the level. + ********************************************************/ + std::vector> LoadLevel(std::string fileName); + + /******************************************************** + * Just for fast access for the meta information about the level. + * @param fileName: Path to the level-file that you want to load. + * @return: Returns the meta information about the level. + ********************************************************/ + LevelMetaData LoadLevelHeader(std::string fileName); //. + + private: + struct PrivData; + Utility::DynamicMemory::SmartPointer pData; + }; +} + +#endif \ No newline at end of file diff --git a/Code/Game/DanBiasGame/GameClientState/LevelLoader/LevelParser.cpp b/Code/Game/DanBiasGame/GameClientState/LevelLoader/LevelParser.cpp new file mode 100644 index 00000000..088c3916 --- /dev/null +++ b/Code/Game/DanBiasGame/GameClientState/LevelLoader/LevelParser.cpp @@ -0,0 +1,190 @@ +#include "LevelParser.h" + +#include "Loader.h" +#include "ParseFunctions.h" + +using namespace GameLogic; +using namespace ::LevelFileLoader; +using namespace Utility::DynamicMemory; + +LevelParser::LevelParser() +{ + formatVersion.formatVersionMajor = 1; + formatVersion.formatVersionMinor = 0; +} + +LevelParser::~LevelParser() +{ +} + +std::vector> LevelParser::Parse(std::string filename) +{ + int bufferSize = 0; + int counter = 0; + + std::vector> objects; + + //Read entire level file. + Loader loader; + char* buffer = (char*)loader.LoadFile(filename.c_str(), bufferSize); + + //Read format version + FormatVersion levelFormatVersion; + ParseObject(&buffer[counter], &levelFormatVersion, sizeof(levelFormatVersion)); + counter += sizeof(levelFormatVersion); + if(this->formatVersion != levelFormatVersion) + { + //Do something if it's not the same version + } + + while(counter < bufferSize) + { + //Get typeID + ObjectTypeHeader typeID; + ParseObject(&buffer[counter], &typeID, sizeof(typeID)); + switch((int)typeID.typeID) + { + case ObjectType_LevelMetaData: + { + LevelMetaData* header = new LevelMetaData; + ParseLevelMetaData(&buffer[counter], *header, counter); + objects.push_back(header); + break; + } + + //This is by design, static and dynamic is using the same converter. Do not add anything inbetween them. + case ObjectType_Static: case ObjectType_Dynamic: + { + ObjectHeader* header = new ObjectHeader; + ParseObject(&buffer[counter], *header, counter); + objects.push_back(header); + break; + } + + case ObjectType_Light: + { + LightType lightType; + + //Get Light type + ParseObject(&buffer[counter+4], &lightType, sizeof(lightType)); + + switch(lightType) + { + case LightType_PointLight: + { + PointLight* header = new PointLight; + ParseObject(&buffer[counter], header, sizeof(*header)); + counter += sizeof(*header); + objects.push_back(header); + break; + } + case LightType_DirectionalLight: + { + DirectionalLight* header = new DirectionalLight; + ParseObject(&buffer[counter], header, sizeof(*header)); + counter += sizeof(*header); + objects.push_back(header); + break; + } + case LightType_SpotLight: + { + SpotLight* header = new SpotLight; + ParseObject(&buffer[counter], header, sizeof(*header)); + counter += sizeof(*header); + objects.push_back(header); + break; + } + default: + //Undefined LightType. + break; + } + break; + } + default: + //Couldn't find typeID. FAIL!!!!!! + break; + } + } + + return objects; +} + +//för meta information om leveln. +LevelMetaData LevelParser::ParseHeader(std::string filename) +{ + int bufferSize = 0; + int counter = 0; + + LevelMetaData levelHeader; + levelHeader.typeID = ObjectType::ObjectType_Unknown; + + //Read entire level file. + Loader loader; + char* buffer = (char*)loader.LoadFile(filename.c_str(), bufferSize); + + //Read format version + FormatVersion levelFormatVersion; + ParseObject(&buffer[counter], &levelFormatVersion, sizeof(formatVersion)); + counter += sizeof(levelFormatVersion); + if(this->formatVersion != levelFormatVersion) + { + //Do something if it's not the same version + } + + //Find the header in the returned string. + while(counter < bufferSize) + { + ObjectTypeHeader typeID; + ParseObject(&buffer[counter], &typeID, sizeof(typeID)); + + switch(typeID.typeID) + { + case ObjectType_LevelMetaData: + ParseLevelMetaData(&buffer[counter], levelHeader, counter); + return levelHeader; + break; + + //This is by design, static and dynamic is using the same converter. Do not add anything inbetween them. + case ObjectType_Static: case ObjectType_Dynamic: + { + ObjectHeader header; + ParseObject(&buffer[counter], header, counter); + break; + } + + case ObjectType_Light: + { + LightType lightType; + ParseObject(&buffer[counter+4], &lightType, sizeof(lightType)); + + switch(lightType) + { + case LightType_PointLight: + { + counter += sizeof(PointLight); + break; + } + case LightType_DirectionalLight: + { + counter += sizeof(DirectionalLight); + break; + } + case LightType_SpotLight: + { + counter += sizeof(SpotLight); + break; + } + default: + //Undefined LightType. + break; + } + } + + default: + //Couldn't find typeID. FAIL!!!!!! + break; + } + } + + return levelHeader; +} \ No newline at end of file diff --git a/Code/Game/DanBiasGame/GameClientState/LevelLoader/LevelParser.h b/Code/Game/DanBiasGame/GameClientState/LevelLoader/LevelParser.h new file mode 100644 index 00000000..9ad30642 --- /dev/null +++ b/Code/Game/DanBiasGame/GameClientState/LevelLoader/LevelParser.h @@ -0,0 +1,31 @@ +#ifndef LEVEL_PARSER_H +#define LEVEL_PARSER_H + +#include +#include +#include "ObjectDefines.h" +#include "../Misc/Utilities.h" + +namespace GameLogic +{ + namespace LevelFileLoader + { + class LevelParser + { + public: + LevelParser(); + ~LevelParser(); + + // + std::vector> Parse(std::string filename); + + // + LevelMetaData ParseHeader(std::string filename); + + private: + FormatVersion formatVersion; + + }; + } +} +#endif \ No newline at end of file diff --git a/Code/Game/DanBiasGame/GameClientState/LevelLoader/Loader.cpp b/Code/Game/DanBiasGame/GameClientState/LevelLoader/Loader.cpp new file mode 100644 index 00000000..3e15315c --- /dev/null +++ b/Code/Game/DanBiasGame/GameClientState/LevelLoader/Loader.cpp @@ -0,0 +1,22 @@ +////////////////////////////////// +// Created by Sam Svensson 2013 // +////////////////////////////////// + +#include "Loader.h" +#include + +using namespace GameLogic::LevelFileLoader; +using namespace Oyster::Resource; +using namespace std; + +char* Loader::LoadFile(std::string fileName, int &size) +{ + //convert from string to wstring + std::wstring temp(fileName.begin(), fileName.end()); + + //convert from wstring to wchar then loads the file + char* buffer = (char*)OysterResource::LoadResource(temp.c_str(), Oyster::Resource::ResourceType::ResourceType_Byte_Raw, -1 , false); + + size = OysterResource::GetResourceSize(buffer); + return buffer; +} \ No newline at end of file diff --git a/Code/Game/DanBiasGame/GameClientState/LevelLoader/Loader.h b/Code/Game/DanBiasGame/GameClientState/LevelLoader/Loader.h new file mode 100644 index 00000000..198c2a87 --- /dev/null +++ b/Code/Game/DanBiasGame/GameClientState/LevelLoader/Loader.h @@ -0,0 +1,28 @@ +////////////////////////////////// +// Created by Sam Svensson 2013 // +////////////////////////////////// + +#ifndef LOADER_H +#define LOADER_H + +#include "..\Misc\Resource\OysterResource.h" +#include + +namespace GameLogic +{ + namespace LevelFileLoader + { + class Loader + { + public: + Loader (){}; + ~Loader(){}; + char* LoadFile(std::string fileName, int &size); + + //TODO: + //Add functionality to load physicsObjects (hitboxes) + }; + } +} + +#endif; \ No newline at end of file diff --git a/Code/Game/DanBiasGame/GameClientState/LevelLoader/ObjectDefines.h b/Code/Game/DanBiasGame/GameClientState/LevelLoader/ObjectDefines.h new file mode 100644 index 00000000..8287dafb --- /dev/null +++ b/Code/Game/DanBiasGame/GameClientState/LevelLoader/ObjectDefines.h @@ -0,0 +1,172 @@ +#ifndef OBJECT_DEFINES_H +#define OBJECT_DEFINES_H + +#include +#include + +namespace GameLogic +{ + /************************************ + Enums + *************************************/ + + enum ObjectType + { + ObjectType_LevelMetaData, + ObjectType_Static, + ObjectType_Dynamic, + ObjectType_Light, + //Etc + + ObjectType_NUM_OF_TYPES, + + ObjectType_Unknown = -1 + }; + + enum UsePhysics + { + UsePhysics_UseFullPhysics, + UsePhysics_IgnoreGravity, + UsePhysics_IgnorePhysics, + UsePhysics_IgnoreCollision, + + UsePhysics_Count, + UsePhysics_Unknown = -1 + }; + + enum CollisionGeometryType + { + CollisionGeometryType_Box, + CollisionGeometryType_Sphere, + + CollisionGeometryType_Count, + CollisionGeometryType_Unknown = -1 + }; + + enum LightType + { + LightType_PointLight, + LightType_DirectionalLight, + LightType_SpotLight, + + LightType_Count, + LightType_Unknown = -1 + }; + + //Should this be moved somewhere else? + enum GameMode + { + GameMode_FreeForAll, + GameMode_TeamDeathMatch, + //Etc + + GameMode_Count, + GameMode_Unknown = -1 + }; + + enum WorldSize + { + WorldSize_Tiny, + WorldSize_Small, + WorldSize_Medium, + WorldSize_Big, + WorldSize_Humongous, + + WorldSize_Count, + WorldSize_Unknown = -1 + }; + + + /************************************ + Structs + *************************************/ + + struct FormatVersion + { + unsigned int formatVersionMajor; + unsigned int formatVersionMinor; + + bool operator ==(const FormatVersion& obj) + { + return (this->formatVersionMajor != obj.formatVersionMajor && this->formatVersionMinor != obj.formatVersionMinor); + } + + bool operator !=(const FormatVersion& obj) + { + return !(*this == obj); + } + }; + + struct ObjectTypeHeader + { + ObjectType typeID; + }; + + struct PhysicsObject + { + UsePhysics usePhysics; + float mass; + float inertiaMagnitude[3]; + float inertiaRotation[3]; + float frictionCoeffStatic; + float frictionCoeffDynamic; + CollisionGeometryType geometryType; + }; + + struct LevelMetaData : public ObjectTypeHeader + { + std::string levelName; + unsigned int levelVersion; + std::string levelDescription; + std::string levelAuthor; + unsigned int maxNumberOfPlayer; + WorldSize worldSize; + std::string overviewPicturePath; + std::vector gameModesSupported; + }; + + struct ObjectHeader : public ObjectTypeHeader, public PhysicsObject + { + //Model, + std::string ModelFile; + //Position + float position[3]; + //Rotation + float rotation[3]; + float angle; + //Scale + float scale[3]; + }; + + + /************************************ + Lights + *************************************/ + + struct BasicLight : public ObjectTypeHeader + { + LightType lightType; + float ambientColor[3]; + float diffuseColor[3]; + float specularColor[3]; + }; + + struct PointLight : public BasicLight + { + float position[3]; + }; + + struct DirectionalLight : public BasicLight + { + float direction[3]; + }; + + struct SpotLight : public BasicLight + { + float direction[3]; + float range; + float attenuation[3]; + }; +} + +#endif \ No newline at end of file diff --git a/Code/Game/DanBiasGame/GameClientState/LevelLoader/ParseFunctions.cpp b/Code/Game/DanBiasGame/GameClientState/LevelLoader/ParseFunctions.cpp new file mode 100644 index 00000000..08823d3d --- /dev/null +++ b/Code/Game/DanBiasGame/GameClientState/LevelLoader/ParseFunctions.cpp @@ -0,0 +1,111 @@ +////////////////////////////////// +// Created by Sam Svensson 2013 // +////////////////////////////////// + +#include "ParseFunctions.h" +#include "../../../../Misc/Packing/Packing.h" +#include + +using namespace Oyster::Packing; +using namespace GameLogic::LevelFileLoader; +using namespace GameLogic; +using namespace std; + +namespace GameLogic +{ + namespace LevelFileLoader + { + void ParseObject(char* buffer, void *header, int size) + { + memcpy(header, buffer, size); + } + + void ParseObject(char* buffer, ObjectHeader& header, int& size) + { + char tempName[128]; + unsigned int tempSize = 0; + int start = 0; + + memcpy(&header.typeID, &buffer[start], 4); + start += 4; + + memcpy(&tempSize, &buffer[start], 4); + start += 4; + + memcpy(&tempName, &buffer[start], tempSize); + header.ModelFile.assign(&tempName[0], &tempName[tempSize]); + start += tempSize; + + //3 float[3], 1 float + memcpy(&header.position, &buffer[start], 40); + start += 40; + + //2 float[3], 3 float, 2 uint + memcpy(&header.usePhysics, &buffer[start], 44); + start += 44; + + size += start; + } + + void ParseLevelMetaData(char* buffer, LevelMetaData &header, int &size) + { + int start = 0; + unsigned int tempSize; + char tempName[128]; + + memcpy(&header.typeID, &buffer[start], 4); + start += 4; + + memcpy(&tempSize , &buffer[start], 4); + start += 4; + + memcpy(&tempName, &buffer[start], tempSize); + header.levelName.assign(&tempName[0], &tempName[tempSize]); + start += tempSize; + + memcpy(&header.levelVersion, &buffer[start], 4); + start += 4; + + memcpy(&tempSize, &buffer[start], 4); + start +=4; + + memcpy(&tempName, &buffer[start], tempSize); + header.levelDescription.assign(&tempName[0], &tempName[tempSize]); + start += tempSize; + + memcpy(&tempSize, &buffer[start], 4); + start += 4; + + memcpy(&tempName, &buffer[start], tempSize); + header.levelAuthor.assign(&tempName[0], &tempName[tempSize]); + start += tempSize; + + memcpy(&header.maxNumberOfPlayer, &buffer[start], 4); + start += 4; + + memcpy(&header.worldSize, &buffer[start], 4); + start += 4; + + memcpy(&tempSize, &buffer[start], 4); + start += 4; + + memcpy(&tempName, &buffer[start], tempSize); + header.overviewPicturePath.assign(&tempName[0], &tempName[tempSize]); + start += tempSize; + + memcpy(&tempSize, &buffer[start], 4); + start += 4; + + int temp; + + for(int i = 0; i < tempSize; i++) + { + memcpy(&temp, &buffer[start], 4); + start += 4; + header.gameModesSupported.push_back((GameMode)temp); + } + + size += start; + } + } +} \ No newline at end of file diff --git a/Code/Game/DanBiasGame/GameClientState/LevelLoader/ParseFunctions.h b/Code/Game/DanBiasGame/GameClientState/LevelLoader/ParseFunctions.h new file mode 100644 index 00000000..f68a9289 --- /dev/null +++ b/Code/Game/DanBiasGame/GameClientState/LevelLoader/ParseFunctions.h @@ -0,0 +1,28 @@ +////////////////////////////////// +// Created by Sam Svensson 2013 // +////////////////////////////////// + +#ifndef PARSERFUNCTIONS_H +#define PARSERFUNCTIONS_H +#include "ObjectDefines.h" + +namespace GameLogic +{ + namespace LevelFileLoader + { + /* + These functions will copy data from where the buffer pointer points. + header is the destination where the data will be copied. + size is either the size of the data to be copied (if it is NOT sent by reference). + Or the current index that is being used to parse the entire file (if it is sent by reference) this means you have to increase size with the appropiate size after you have copied. + + */ + + void ParseObject(char* buffer, void *header, int size); + void ParseObject(char* buffer, ObjectHeader& header, int& size); + void ParseLevelMetaData(char* buffer, LevelMetaData &header, int &size); + } +} + + +#endif \ No newline at end of file diff --git a/Code/Game/DanBiasGame/GameClientState/LobbyState.cpp b/Code/Game/DanBiasGame/GameClientState/LobbyState.cpp index 538408c5..07bf8d42 100644 --- a/Code/Game/DanBiasGame/GameClientState/LobbyState.cpp +++ b/Code/Game/DanBiasGame/GameClientState/LobbyState.cpp @@ -53,17 +53,18 @@ bool LobbyState::LoadModels(std::wstring file) ModelInitData modelData; - modelData.world = Oyster::Math3D::Float4x4::identity; + modelData.position = Oyster::Math::Float3(0,0,0); + modelData.rotation = Oyster::Math::Quaternion::identity; + modelData.scale = Oyster::Math::Float3(1,1,1); modelData.visible = true; modelData.modelPath = L"..\\Content\\Models\\box_2.dan"; // load models privData->object[0] = new C_StaticObj(); privData->object[0]->Init(modelData); - Oyster::Math3D::Float4x4 translate = Oyster::Math3D::TranslationMatrix(Oyster::Math::Float3(2,2,2)); - modelData.world = modelData.world * translate; + modelData.position = Oyster::Math::Float3(2,2,2); - privData->object[1] = new C_DynamicObj(); + privData->object[1] = new C_StaticObj(); privData->object[1]->Init(modelData); return true; } diff --git a/Code/Game/DanBiasGame/GameClientState/LoginState.cpp b/Code/Game/DanBiasGame/GameClientState/LoginState.cpp index 4a244a8b..1bc3af72 100644 --- a/Code/Game/DanBiasGame/GameClientState/LoginState.cpp +++ b/Code/Game/DanBiasGame/GameClientState/LoginState.cpp @@ -53,26 +53,18 @@ bool LoginState::LoadModels(std::wstring file) ModelInitData modelData; - modelData.world = Oyster::Math3D::Float4x4::identity; + modelData.rotation = Oyster::Math::Quaternion::identity; + modelData.scale = Oyster::Math::Float3(1,1,1); modelData.visible = true; modelData.modelPath = L"identityPlane.dan"; - // load models - Oyster::Math3D::Float4x4 translate = Oyster::Math3D::TranslationMatrix(Oyster::Math::Float3(2,2,-2)); - Oyster::Math3D::Float4x4 rot = Oyster::Math3D::RotationMatrix(Oyster::Math::Float3(0 ,Utility::Value::Radian(90.0f), 0)); - Oyster::Math3D::Float4x4 scale = Oyster::Math3D::Float4x4::identity; - int scaling = 2; - scale.v[0].x = scaling; - scale.v[1].y = scaling; - scale.v[2].z = scaling; + - modelData.world = translate; //scale * translate * rot; - privData->object[0] = new C_DynamicObj(); + modelData.position = Oyster::Math::Float3(2,2,2); + privData->object[0] = new C_StaticObj(); privData->object[0]->Init(modelData); - translate = Oyster::Math3D::TranslationMatrix(Oyster::Math::Float3(0,0,-2)); - modelData.world = translate ;//* rot; - - privData->object[1] = new C_DynamicObj(); + modelData.position = Oyster::Math::Float3(0,0,-2); + privData->object[1] = new C_StaticObj(); privData->object[1]->Init(modelData); return true; } diff --git a/Code/Game/GameLogic/Game.cpp b/Code/Game/GameLogic/Game.cpp index 6aecc900..8077c6bf 100644 --- a/Code/Game/GameLogic/Game.cpp +++ b/Code/Game/GameLogic/Game.cpp @@ -81,7 +81,8 @@ Game::LevelData* Game::CreateLevel() if(this->level) return this->level; this->level = new LevelData(); - this->level->level->InitiateLevel(1000); + //this->level->level->InitiateLevel(1000); + this->level->level->InitiateLevel("3bana.bias"); return this->level; } diff --git a/Code/Game/GameLogic/GameLogic.vcxproj b/Code/Game/GameLogic/GameLogic.vcxproj index 674773bf..7ae78fac 100644 --- a/Code/Game/GameLogic/GameLogic.vcxproj +++ b/Code/Game/GameLogic/GameLogic.vcxproj @@ -181,7 +181,7 @@ - + @@ -203,7 +203,7 @@ - + diff --git a/Code/Game/GameLogic/GameMode.cpp b/Code/Game/GameLogic/GameMode.cpp deleted file mode 100644 index ba240fca..00000000 --- a/Code/Game/GameLogic/GameMode.cpp +++ /dev/null @@ -1,15 +0,0 @@ -#include "GameMode.h" - -using namespace GameLogic; - - -GameMode::GameMode() -{ - -} - - -GameMode::~GameMode(void) -{ - -} diff --git a/Code/Game/GameLogic/GameModeType.cpp b/Code/Game/GameLogic/GameModeType.cpp new file mode 100644 index 00000000..b48fd475 --- /dev/null +++ b/Code/Game/GameLogic/GameModeType.cpp @@ -0,0 +1,15 @@ +#include "GameModeType.h" + +using namespace GameLogic; + + +GameModeType::GameModeType() +{ + +} + + +GameModeType::~GameModeType(void) +{ + +} diff --git a/Code/Game/GameLogic/GameMode.h b/Code/Game/GameLogic/GameModeType.h similarity index 63% rename from Code/Game/GameLogic/GameMode.h rename to Code/Game/GameLogic/GameModeType.h index d910c78c..8cc9fa37 100644 --- a/Code/Game/GameLogic/GameMode.h +++ b/Code/Game/GameLogic/GameModeType.h @@ -3,16 +3,16 @@ ////////////////////////////////////////////////// -#ifndef GAMEMODE_H -#define GAMEMODE_H +#ifndef GAMEMODETYPE_H +#define GAMEMODETYPE_H namespace GameLogic { - class GameMode + class GameModeType { public: - GameMode(void); - ~GameMode(void); + GameModeType(void); + ~GameModeType(void); private: diff --git a/Code/Game/GameLogic/Game_PlayerData.cpp b/Code/Game/GameLogic/Game_PlayerData.cpp index ee535868..d4657998 100644 --- a/Code/Game/GameLogic/Game_PlayerData.cpp +++ b/Code/Game/GameLogic/Game_PlayerData.cpp @@ -19,7 +19,7 @@ Game::PlayerData::PlayerData() Oyster::Physics::ICustomBody *rigidBody = Oyster::Physics::API::Instance().CreateRigidBody(sbDesc).Release(); //create player with this rigid body - this->player = new Player(rigidBody,Player::DefaultCollisionAfter, Player::PlayerCollision, OBJECT_TYPE::OBJECT_TYPE_PLAYER); + this->player = new Player(rigidBody,Level::LevelCollisionBefore, Player::PlayerCollision, OBJECT_TYPE::OBJECT_TYPE_PLAYER); this->player->GetRigidBody()->SetCustomTag(this); /*Oyster::Physics::ICustomBody::State state; this->player->GetRigidBody()->GetState(state); diff --git a/Code/Game/GameLogic/Level.cpp b/Code/Game/GameLogic/Level.cpp index 81c71de6..a954e11b 100644 --- a/Code/Game/GameLogic/Level.cpp +++ b/Code/Game/GameLogic/Level.cpp @@ -13,10 +13,183 @@ Level::Level(void) Level::~Level(void) { } +void Level::parseObjectType(ObjectTypeHeader* obj) +{ + /*switch (obj->objectTypeID) + { + case skySphere: + // save the skysphere to be able to rotate it + break; + case jumppad: + // save direction + break; + case portal: + // save portal destination + break; + case world: + // add gravitation well here + // add outer limit of the world + case spawn: + // save spawnpoint pos + break; + default: + break; + }*/ +} +void Level::parsePhysicsObj(PhysicsObject* obj) +{ + // offset physObj med modelObj +} void Level::InitiateLevel(std::string levelPath) { + LevelLoader ll; + std::vector> objects; + objects = ll.LoadLevel(levelPath); + int objCount = objects.size(); + int modelCount = 0; + for (int i = 0; i < objCount; i++) + { + ObjectTypeHeader* obj = objects.at(i); + int id = obj->typeID; + switch (obj->typeID) + { + case ObjectType::ObjectType_LevelMetaData: + { + LevelMetaData* LevelObjData = ((LevelMetaData*)obj); + std::string levelName = LevelObjData->levelName; + // LevelObjData->worldSize; + } + break; + case ObjectType::ObjectType_Static: + { + + ObjectHeader* staticObjData = ((ObjectHeader*)obj); + PhysicsObject* staticObjPhysicData = ((ObjectHeader*)obj); + staticObjData->ModelFile; + ICustomBody* rigidBody_Static; + if( staticObjPhysicData->geometryType = CollisionGeometryType_Box) + { + API::SimpleBodyDescription sbDesc_Static; + + sbDesc_Static.centerPosition = staticObjData->position; + sbDesc_Static.ignoreGravity = false; // because it is static + sbDesc_Static.rotation = Oyster::Math::Float3(staticObjData->rotation[0], staticObjData->rotation[1],staticObjData->rotation[2]);//Oyster::Math::Float3(0 ,Utility::Value::Radian(90.0f), 0); + + + //sbDesc_Static.inertiaTensor.Cuboid(staticObjPhysicData->mass); + sbDesc_Static.mass = staticObjPhysicData->mass; + sbDesc_Static.frictionCoeff_Static = staticObjPhysicData->frictionCoeffStatic; + sbDesc_Static.frictionCoeff_Dynamic = staticObjPhysicData->frictionCoeffDynamic; + //sbDesc_Static.restitutionCoeff = + sbDesc_Static.size = Oyster::Math::Float3(40,40,40); + rigidBody_Static = API::Instance().CreateRigidBody(sbDesc_Static).Release(); + if(rigidBody_Static) + { + this->staticObjects.Push(new StaticObject(rigidBody_Static,Object::DefaultCollisionBefore, Object::DefaultCollisionAfter, OBJECT_TYPE::OBJECT_TYPE_GENERIC)); + int id = this->staticObjects.Size()-1; + rigidBody_Static->SetCustomTag(this->staticObjects[this->staticObjects.Size()-1]); + } + } + if( staticObjPhysicData->geometryType = CollisionGeometryType_Sphere) + { + API::SphericalBodyDescription sbDesc_Static; + + sbDesc_Static.centerPosition = staticObjData->position; + sbDesc_Static.ignoreGravity = true; // because it is static + sbDesc_Static.rotation = Oyster::Math::Float3(staticObjData->rotation[0], staticObjData->rotation[1],staticObjData->rotation[2]);//Oyster::Math::Float3(0 ,Utility::Value::Radian(90.0f), 0); + + //sbDesc_Static.inertiaTensor.Sphere(staticObjPhysicData->mass); + + sbDesc_Static.mass = staticObjPhysicData->mass; + sbDesc_Static.frictionCoeff_Static = staticObjPhysicData->frictionCoeffStatic; + sbDesc_Static.frictionCoeff_Dynamic = staticObjPhysicData->frictionCoeffDynamic; + //sbDesc_Static.restitutionCoeff = + //sbDesc_Static.radius = + rigidBody_Static = API::Instance().CreateRigidBody(sbDesc_Static).Release(); + if(rigidBody_Static) + { + this->staticObjects.Push(new StaticObject(rigidBody_Static,Object::DefaultCollisionBefore, Object::DefaultCollisionAfter, OBJECT_TYPE::OBJECT_TYPE_GENERIC)); + int id = this->staticObjects.Size()-1; + rigidBody_Static->SetCustomTag(this->staticObjects[this->staticObjects.Size()-1]); + } + + if (OBJECT_TYPE::OBJECT_TYPE_WORLD) + { + API::Gravity gravityWell; + gravityWell.gravityType = API::Gravity::GravityType_Well; + gravityWell.well.mass = 1e17f; + gravityWell.well.position = Oyster::Math::Float4(0,0,0,1); + API::Instance().AddGravity(gravityWell); + } + } + } + break; + case ObjectType::ObjectType_Dynamic: + { + ObjectHeader* staticObjData = ((ObjectHeader*)obj); + PhysicsObject* staticObjPhysicData = ((ObjectHeader*)obj); + staticObjData->ModelFile; + + ICustomBody* rigidBody_Dynamic; + if( staticObjPhysicData->geometryType = CollisionGeometryType_Box) + { + API::SimpleBodyDescription sbDesc_Dynamic; + + sbDesc_Dynamic.centerPosition = staticObjData->position; + sbDesc_Dynamic.ignoreGravity = false; // because it is static + sbDesc_Dynamic.rotation = Oyster::Math::Float3(staticObjData->rotation[0], staticObjData->rotation[1],staticObjData->rotation[2]);//Oyster::Math::Float3(0 ,Utility::Value::Radian(90.0f), 0); + + + //sbDesc_Static.inertiaTensor.Cuboid(staticObjPhysicData->mass); + sbDesc_Dynamic.mass = staticObjPhysicData->mass; + sbDesc_Dynamic.frictionCoeff_Static = staticObjPhysicData->frictionCoeffStatic; + sbDesc_Dynamic.frictionCoeff_Dynamic = staticObjPhysicData->frictionCoeffDynamic; + //sbDesc_Static.restitutionCoeff = + sbDesc_Dynamic.size = Oyster::Math::Float3(40,40,40); + rigidBody_Dynamic = API::Instance().CreateRigidBody(sbDesc_Dynamic).Release(); + if(rigidBody_Dynamic) + { + rigidBody_Dynamic->SetSubscription(Level::PhysicsOnMoveLevel); + this->dynamicObjects.Push(new DynamicObject(rigidBody_Dynamic,Object::DefaultCollisionBefore, Object::DefaultCollisionAfter, OBJECT_TYPE::OBJECT_TYPE_GENERIC)); + int id = this->dynamicObjects.Size()-1; + rigidBody_Dynamic->SetCustomTag(this->dynamicObjects[this->dynamicObjects.Size()-1]); + } + } + if( staticObjPhysicData->geometryType = CollisionGeometryType_Sphere) + { + API::SphericalBodyDescription sbDesc_Dynamic; + + sbDesc_Dynamic.centerPosition = staticObjData->position; + sbDesc_Dynamic.ignoreGravity = false; // use gravity on dynamic obj + sbDesc_Dynamic.rotation = Oyster::Math::Float3(staticObjData->rotation[0], staticObjData->rotation[1],staticObjData->rotation[2]);//Oyster::Math::Float3(0 ,Utility::Value::Radian(90.0f), 0); + + //sbDesc_Static.inertiaTensor.Sphere(staticObjPhysicData->mass); + + sbDesc_Dynamic.mass = staticObjPhysicData->mass; + sbDesc_Dynamic.frictionCoeff_Static = staticObjPhysicData->frictionCoeffStatic; + sbDesc_Dynamic.frictionCoeff_Dynamic = staticObjPhysicData->frictionCoeffDynamic; + //sbDesc_Static.restitutionCoeff = + //sbDesc_Static.radius = + rigidBody_Dynamic = API::Instance().CreateRigidBody(sbDesc_Dynamic).Release(); + if(rigidBody_Dynamic) + { + rigidBody_Dynamic->SetSubscription(Level::PhysicsOnMoveLevel); + this->dynamicObjects.Push(new DynamicObject(rigidBody_Dynamic,Object::DefaultCollisionBefore, Object::DefaultCollisionAfter, OBJECT_TYPE::OBJECT_TYPE_GENERIC)); + int id = this->dynamicObjects.Size()-1; + rigidBody_Dynamic->SetCustomTag(this->dynamicObjects[this->dynamicObjects.Size()-1]); + } + } + } + break; + case ObjectType::ObjectType_Light: + // read on client + break; + default: + break; + } + } } void Level::InitiateLevel(float radius) { diff --git a/Code/Game/GameLogic/Level.h b/Code/Game/GameLogic/Level.h index cc34408b..64b09f5c 100644 --- a/Code/Game/GameLogic/Level.h +++ b/Code/Game/GameLogic/Level.h @@ -8,11 +8,12 @@ #include "Player.h" #include "StaticObject.h" #include "DynamicObject.h" -#include "GameMode.h" +#include "GameModeType.h" #include "Player.h" #include "PhysicsAPI.h" #include "TeamManager.h" #include "DynamicArray.h" +#include "LevelLoader/LevelLoader.h" namespace GameLogic { @@ -29,8 +30,10 @@ namespace GameLogic * @param levelPath: Path to a file that contains all information on the level ********************************************************/ void InitiateLevel(std::string levelPath); - void Level::InitiateLevel(float radius); + void InitiateLevel(float radius); + void parseObjectType(ObjectTypeHeader* obj); + void parsePhysicsObj(PhysicsObject* obj); /******************************************************** * Creates a team in the level * @param teamSize: The size of the team you want to create @@ -69,7 +72,7 @@ namespace GameLogic TeamManager teamManager; Utility::DynamicMemory::DynamicArray> staticObjects; Utility::DynamicMemory::DynamicArray> dynamicObjects; - GameMode gameMode; + GameModeType gameMode; Utility::DynamicMemory::SmartPointer rigidBodyLevel; StaticObject *levelObj; diff --git a/Code/Game/GameLogic/Object.cpp b/Code/Game/GameLogic/Object.cpp index ebd5c275..1a1f7338 100644 --- a/Code/Game/GameLogic/Object.cpp +++ b/Code/Game/GameLogic/Object.cpp @@ -178,13 +178,13 @@ void Object::EndFrame() //300, 0,0, //1,0,0 - /*if( pos.GetLength() < 303.5f) + if( pos.GetLength() < 303.5f) { Oyster::Math::Float moveUp = 303.5 - pos.GetLength(); up *= moveUp; currPhysicsState.SetCenterPosition(pos + up); - }*/ + } if(currPhysicsState.GetLinearMomentum() !=currPhysicsState.GetLinearMomentum()) diff --git a/Code/Game/GameLogic/Object.h b/Code/Game/GameLogic/Object.h index c484701c..91559734 100644 --- a/Code/Game/GameLogic/Object.h +++ b/Code/Game/GameLogic/Object.h @@ -27,6 +27,7 @@ namespace GameLogic // API overrides OBJECT_TYPE GetObjectType() const; + void setID(int id); int GetID() const; Oyster::Math::Float3 GetPosition(); Oyster::Math::Float4x4 GetOrientation(); diff --git a/Code/OysterPhysics3D/RigidBody.cpp b/Code/OysterPhysics3D/RigidBody.cpp index d9f2f69d..f7a5646e 100644 --- a/Code/OysterPhysics3D/RigidBody.cpp +++ b/Code/OysterPhysics3D/RigidBody.cpp @@ -51,8 +51,8 @@ void RigidBody::Update_LeapFrog( Float updateFrameLength ) // updating the linear //Decrease momentum with 1% as "fall-off" //! HACK: @todo Add real solution with fluid drag - //this->momentum_Linear = this->momentum_Linear*0.99f; - //this->momentum_Angular = this->momentum_Angular*0.99f; + this->momentum_Linear = this->momentum_Linear*0.99f; + this->momentum_Angular = this->momentum_Angular*0.99f; // ds = dt * Formula::LinearVelocity( m, avg_G ) = dt * avg_G / m = (dt / m) * avg_G Float3 delta = AverageWithDelta( this->momentum_Linear, this->impulse_Linear );