GL - started using the lvl format. Objects on client have pos, rot and scale (not verified)
This commit is contained in:
parent
f372d3e05b
commit
c87bab8808
Binary file not shown.
|
@ -205,6 +205,10 @@
|
||||||
<ClCompile Include="GameClientState\GameClientState.cpp" />
|
<ClCompile Include="GameClientState\GameClientState.cpp" />
|
||||||
<ClCompile Include="GameClientState\GameState.cpp" />
|
<ClCompile Include="GameClientState\GameState.cpp" />
|
||||||
<ClCompile Include="GameClientState\LanMenuState.cpp" />
|
<ClCompile Include="GameClientState\LanMenuState.cpp" />
|
||||||
|
<ClCompile Include="GameClientState\LevelLoader\LevelLoader.cpp" />
|
||||||
|
<ClCompile Include="GameClientState\LevelLoader\LevelParser.cpp" />
|
||||||
|
<ClCompile Include="GameClientState\LevelLoader\Loader.cpp" />
|
||||||
|
<ClCompile Include="GameClientState\LevelLoader\ParseFunctions.cpp" />
|
||||||
<ClCompile Include="GameClientState\LobbyState.cpp" />
|
<ClCompile Include="GameClientState\LobbyState.cpp" />
|
||||||
<ClCompile Include="GameClientState\C_Object.cpp" />
|
<ClCompile Include="GameClientState\C_Object.cpp" />
|
||||||
<ClCompile Include="GameClientState\LoginState.cpp" />
|
<ClCompile Include="GameClientState\LoginState.cpp" />
|
||||||
|
@ -219,6 +223,11 @@
|
||||||
<ClInclude Include="GameClientState\GameClientState.h" />
|
<ClInclude Include="GameClientState\GameClientState.h" />
|
||||||
<ClInclude Include="GameClientState\GameState.h" />
|
<ClInclude Include="GameClientState\GameState.h" />
|
||||||
<ClInclude Include="GameClientState\LanMenuState.h" />
|
<ClInclude Include="GameClientState\LanMenuState.h" />
|
||||||
|
<ClInclude Include="GameClientState\LevelLoader\LevelLoader.h" />
|
||||||
|
<ClInclude Include="GameClientState\LevelLoader\LevelParser.h" />
|
||||||
|
<ClInclude Include="GameClientState\LevelLoader\Loader.h" />
|
||||||
|
<ClInclude Include="GameClientState\LevelLoader\ObjectDefines.h" />
|
||||||
|
<ClInclude Include="GameClientState\LevelLoader\ParseFunctions.h" />
|
||||||
<ClInclude Include="GameClientState\LoginState.h" />
|
<ClInclude Include="GameClientState\LoginState.h" />
|
||||||
<ClInclude Include="Include\DanBiasGame.h" />
|
<ClInclude Include="Include\DanBiasGame.h" />
|
||||||
<ClInclude Include="GameClientState\LobbyState.h" />
|
<ClInclude Include="GameClientState\LobbyState.h" />
|
||||||
|
|
|
@ -1,4 +1,71 @@
|
||||||
#include "C_Object.h"
|
#include "C_Object.h"
|
||||||
using namespace DanBias::Client;
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -10,21 +10,38 @@ namespace DanBias
|
||||||
{
|
{
|
||||||
int id;
|
int id;
|
||||||
std::wstring modelPath;
|
std::wstring modelPath;
|
||||||
Oyster::Math::Float4x4 world;
|
Oyster::Math::Float3 position;
|
||||||
|
Oyster::Math::Quaternion rotation;
|
||||||
|
Oyster::Math::Float3 scale;
|
||||||
bool visible;
|
bool visible;
|
||||||
};
|
};
|
||||||
|
|
||||||
class C_Object
|
class C_Object
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
|
Oyster::Math::Float4x4 world;
|
||||||
|
Oyster::Math::Float3 position;
|
||||||
|
Oyster::Math::Quaternion rotation;
|
||||||
|
Oyster::Math::Float3 scale;
|
||||||
|
void updateWorld();
|
||||||
public:
|
public:
|
||||||
|
|
||||||
virtual void Init(ModelInitData modelInit) = 0;
|
virtual void Init(ModelInitData modelInit);
|
||||||
virtual void setPos(Oyster::Math::Float4x4 world) = 0;
|
|
||||||
|
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 Render() = 0;
|
||||||
virtual void Release() = 0;
|
virtual void Release() = 0;
|
||||||
virtual int GetId() = 0;
|
int GetId();
|
||||||
};};};
|
};};};
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -21,17 +21,14 @@ C_DynamicObj::~C_DynamicObj(void)
|
||||||
}
|
}
|
||||||
void C_DynamicObj::Init(ModelInitData modelInit)
|
void C_DynamicObj::Init(ModelInitData modelInit)
|
||||||
{
|
{
|
||||||
|
C_Object::Init(modelInit);
|
||||||
// load models
|
// load models
|
||||||
privData = new myData();
|
privData = new myData();
|
||||||
privData->model = Oyster::Graphics::API::CreateModel(modelInit.modelPath);
|
privData->model = Oyster::Graphics::API::CreateModel(modelInit.modelPath);
|
||||||
privData->model->WorldMatrix = modelInit.world;
|
|
||||||
privData->model->Visible = modelInit.visible;
|
privData->model->Visible = modelInit.visible;
|
||||||
|
privData->model->WorldMatrix = getWorld();
|
||||||
privData->ID = modelInit.id;
|
privData->ID = modelInit.id;
|
||||||
}
|
}
|
||||||
void C_DynamicObj::setPos(Oyster::Math::Float4x4 world)
|
|
||||||
{
|
|
||||||
privData->model->WorldMatrix = world;
|
|
||||||
}
|
|
||||||
|
|
||||||
void C_DynamicObj::Render()
|
void C_DynamicObj::Render()
|
||||||
{
|
{
|
||||||
|
|
|
@ -14,7 +14,6 @@ public:
|
||||||
C_DynamicObj(void);
|
C_DynamicObj(void);
|
||||||
virtual ~C_DynamicObj(void);
|
virtual ~C_DynamicObj(void);
|
||||||
void Init(ModelInitData modelInit);
|
void Init(ModelInitData modelInit);
|
||||||
void setPos(Oyster::Math::Float4x4 world);
|
|
||||||
|
|
||||||
void Render();
|
void Render();
|
||||||
void Release();
|
void Release();
|
||||||
|
|
|
@ -13,6 +13,7 @@ struct C_Player::myData
|
||||||
}privData;
|
}privData;
|
||||||
|
|
||||||
C_Player::C_Player(void)
|
C_Player::C_Player(void)
|
||||||
|
:C_DynamicObj()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,18 +25,16 @@ C_Player::~C_Player(void)
|
||||||
|
|
||||||
void C_Player::Init(ModelInitData modelInit)
|
void C_Player::Init(ModelInitData modelInit)
|
||||||
{
|
{
|
||||||
|
C_Object::Init(modelInit);
|
||||||
// load models
|
// load models
|
||||||
privData = new myData();
|
privData = new myData();
|
||||||
privData->model = Oyster::Graphics::API::CreateModel(modelInit.modelPath);
|
privData->model = Oyster::Graphics::API::CreateModel(modelInit.modelPath);
|
||||||
privData->model->WorldMatrix = modelInit.world;
|
|
||||||
privData->model->Visible = modelInit.visible;
|
privData->model->Visible = modelInit.visible;
|
||||||
|
privData->model->WorldMatrix = getWorld();
|
||||||
privData->ID = modelInit.id;
|
privData->ID = modelInit.id;
|
||||||
privData->lookDir = Oyster::Math3D::Float4 (0,0,1,0);
|
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()
|
void C_Player::Render()
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,21 +1,20 @@
|
||||||
#ifndef DANBIAS_CLIENT_CPLAYER_H
|
#ifndef DANBIAS_CLIENT_CPLAYER_H
|
||||||
#define DANBIAS_CLIENT_CPLAYER_H
|
#define DANBIAS_CLIENT_CPLAYER_H
|
||||||
#include "../C_Object.h"
|
#include "C_DynamicObj.h"
|
||||||
namespace DanBias
|
namespace DanBias
|
||||||
{
|
{
|
||||||
namespace Client
|
namespace Client
|
||||||
{
|
{
|
||||||
class C_Player : public C_Object
|
class C_Player : public C_DynamicObj
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
struct myData;
|
struct myData;
|
||||||
myData* privData;
|
myData* privData;
|
||||||
//Oyster::Graphics:: LIght
|
|
||||||
public:
|
public:
|
||||||
C_Player(void);
|
C_Player(void);
|
||||||
~C_Player(void);
|
virtual ~C_Player(void);
|
||||||
void Init(ModelInitData modelInit);
|
void Init(ModelInitData modelInit);
|
||||||
void setPos(Oyster::Math::Float4x4 world);
|
|
||||||
|
|
||||||
void Render();
|
void Render();
|
||||||
void Release();
|
void Release();
|
||||||
|
|
|
@ -8,9 +8,7 @@ struct C_StaticObj::myData
|
||||||
myData(){}
|
myData(){}
|
||||||
Oyster::Graphics::Model::Model *model;
|
Oyster::Graphics::Model::Model *model;
|
||||||
int ID;
|
int ID;
|
||||||
// light
|
|
||||||
// sound
|
|
||||||
// effect
|
|
||||||
}privData;
|
}privData;
|
||||||
C_StaticObj::C_StaticObj(void)
|
C_StaticObj::C_StaticObj(void)
|
||||||
{
|
{
|
||||||
|
@ -23,18 +21,16 @@ C_StaticObj::~C_StaticObj(void)
|
||||||
}
|
}
|
||||||
void C_StaticObj::Init(ModelInitData modelInit)
|
void C_StaticObj::Init(ModelInitData modelInit)
|
||||||
{
|
{
|
||||||
|
C_Object::Init(modelInit);
|
||||||
// load models
|
// load models
|
||||||
privData = new myData();
|
privData = new myData();
|
||||||
privData->model = Oyster::Graphics::API::CreateModel(modelInit.modelPath);
|
privData->model = Oyster::Graphics::API::CreateModel(modelInit.modelPath);
|
||||||
privData->model->WorldMatrix = modelInit.world;
|
|
||||||
privData->model->Visible = modelInit.visible;
|
privData->model->Visible = modelInit.visible;
|
||||||
|
privData->model->WorldMatrix = getWorld();
|
||||||
privData->ID = modelInit.id;
|
privData->ID = modelInit.id;
|
||||||
|
|
||||||
}
|
}
|
||||||
void C_StaticObj::setPos(Oyster::Math::Float4x4 world)
|
|
||||||
{
|
|
||||||
privData->model->WorldMatrix = world;
|
|
||||||
}
|
|
||||||
|
|
||||||
void C_StaticObj::Render()
|
void C_StaticObj::Render()
|
||||||
{
|
{
|
||||||
|
|
|
@ -14,7 +14,6 @@ public:
|
||||||
C_StaticObj(void);
|
C_StaticObj(void);
|
||||||
virtual ~C_StaticObj(void);
|
virtual ~C_StaticObj(void);
|
||||||
void Init(ModelInitData modelInit);
|
void Init(ModelInitData modelInit);
|
||||||
void setPos(Oyster::Math::Float4x4 world);
|
|
||||||
|
|
||||||
void Render();
|
void Render();
|
||||||
void Release();
|
void Release();
|
||||||
|
|
|
@ -19,11 +19,12 @@ C_UIobject::~C_UIobject(void)
|
||||||
}
|
}
|
||||||
void C_UIobject::Init(ModelInitData modelInit)
|
void C_UIobject::Init(ModelInitData modelInit)
|
||||||
{
|
{
|
||||||
|
C_Object::Init(modelInit);
|
||||||
// load models
|
// load models
|
||||||
privData = new myData();
|
privData = new myData();
|
||||||
privData->model = Oyster::Graphics::API::CreateModel(modelInit.modelPath);
|
privData->model = Oyster::Graphics::API::CreateModel(modelInit.modelPath);
|
||||||
privData->model->WorldMatrix = modelInit.world;
|
|
||||||
privData->model->Visible = modelInit.visible;
|
privData->model->Visible = modelInit.visible;
|
||||||
|
privData->model->WorldMatrix = getWorld();
|
||||||
privData->ID = modelInit.id;
|
privData->ID = modelInit.id;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,20 +1,16 @@
|
||||||
#include "GameState.h"
|
#include "GameState.h"
|
||||||
#include "DllInterfaces/GFXAPI.h"
|
#include "DllInterfaces/GFXAPI.h"
|
||||||
#include "C_obj/C_Player.h"
|
|
||||||
#include "C_obj/C_DynamicObj.h"
|
|
||||||
#include <Protocols.h>
|
#include <Protocols.h>
|
||||||
#include "NetworkClient.h"
|
#include "NetworkClient.h"
|
||||||
#include "Camera.h"
|
#include "Camera.h"
|
||||||
#include <GameServerAPI.h>
|
#include <GameServerAPI.h>
|
||||||
|
|
||||||
using namespace DanBias::Client;
|
using namespace DanBias::Client;
|
||||||
|
using namespace Oyster::Math;
|
||||||
struct GameState::myData
|
struct GameState::myData
|
||||||
{
|
{
|
||||||
myData(){}
|
myData(){}
|
||||||
Oyster::Math3D::Float4x4 view;
|
//std::vector<C_Object*> object;
|
||||||
Oyster::Math3D::Float4x4 proj;
|
|
||||||
std::vector<C_Object*> object;
|
|
||||||
int modelCount;
|
int modelCount;
|
||||||
Oyster::Network::NetworkClient* nwClient;
|
Oyster::Network::NetworkClient* nwClient;
|
||||||
gameStateState state;
|
gameStateState state;
|
||||||
|
@ -49,39 +45,123 @@ bool GameState::Init(Oyster::Network::NetworkClient* nwClient)
|
||||||
GameState::gameStateState GameState::LoadGame()
|
GameState::gameStateState GameState::LoadGame()
|
||||||
{
|
{
|
||||||
Oyster::Graphics::Definitions::Pointlight plight;
|
Oyster::Graphics::Definitions::Pointlight plight;
|
||||||
plight.Pos = Oyster::Math::Float3(315, 0 ,5);
|
plight.Pos = Float3(315, 0 ,5);
|
||||||
plight.Color = Oyster::Math::Float3(0.9,0.7,0.2);
|
plight.Color = Float3(0.9f,0.7f,0.2f);
|
||||||
plight.Radius = 100;
|
plight.Radius = 100;
|
||||||
plight.Bright = 0.9;
|
plight.Bright = 0.9f;
|
||||||
Oyster::Graphics::API::AddLight(plight);
|
Oyster::Graphics::API::AddLight(plight);
|
||||||
plight.Pos = Oyster::Math::Float3(10,350,5);
|
plight.Pos = Float3(10,350,5);
|
||||||
plight.Color = Oyster::Math::Float3(0.9,0.7,0.3);
|
plight.Color = Float3(0.9f,0.7f,0.3f);
|
||||||
plight.Radius = 200;
|
plight.Radius = 200;
|
||||||
plight.Bright = 0.7;
|
plight.Bright = 0.7f;
|
||||||
Oyster::Graphics::API::AddLight(plight);
|
Oyster::Graphics::API::AddLight(plight);
|
||||||
plight.Pos = Oyster::Math::Float3(350,350,5);
|
plight.Pos = Float3(350,350,5);
|
||||||
plight.Color = Oyster::Math::Float3(0.9,0.7,0.3);
|
plight.Color = Float3(0.9f,0.7f,0.3f);
|
||||||
plight.Radius = 200;
|
plight.Radius = 200;
|
||||||
plight.Bright = 0.7;
|
plight.Bright = 0.7f;
|
||||||
Oyster::Graphics::API::AddLight(plight);
|
Oyster::Graphics::API::AddLight(plight);
|
||||||
plight.Pos = Oyster::Math::Float3(10,350,350);
|
plight.Pos = Float3(10,350,350);
|
||||||
plight.Color = Oyster::Math::Float3(0.9,0.7,0.3);
|
plight.Color = Float3(0.9f,0.7f,0.3f);
|
||||||
plight.Radius = 200;
|
plight.Radius = 200;
|
||||||
plight.Bright = 0.7;
|
plight.Bright = 0.7f;
|
||||||
Oyster::Graphics::API::AddLight(plight);
|
Oyster::Graphics::API::AddLight(plight);
|
||||||
plight.Pos = Oyster::Math::Float3(10,-15,5);
|
plight.Pos = Float3(10,-15,5);
|
||||||
plight.Color = Oyster::Math::Float3(0,0,1);
|
plight.Color = Float3(0,0,1);
|
||||||
plight.Radius = 50;
|
plight.Radius = 50;
|
||||||
plight.Bright = 2;
|
plight.Bright = 2;
|
||||||
|
|
||||||
Oyster::Graphics::API::AddLight(plight);
|
Oyster::Graphics::API::AddLight(plight);
|
||||||
LoadModels(L"map");
|
LoadModels("3bana.bias");
|
||||||
InitCamera(Oyster::Math::Float3(0,0,20.0f));
|
Float3 startPos = Float3(0,0,20.0f);
|
||||||
|
InitCamera(startPos);
|
||||||
return gameStateState_playing;
|
return gameStateState_playing;
|
||||||
}
|
}
|
||||||
bool GameState::LoadModels(std::wstring mapFile)
|
bool GameState::LoadModels(std::string mapFile)
|
||||||
{
|
{
|
||||||
// open file
|
GameLogic::LevelLoader levelLoader;
|
||||||
|
std::vector<Utility::DynamicMemory::SmartPointer<GameLogic::ObjectTypeHeader>> 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
|
// read file
|
||||||
// init models
|
// init models
|
||||||
int nrOfBoxex = 20;
|
int nrOfBoxex = 20;
|
||||||
|
@ -199,27 +279,18 @@ bool GameState::LoadModels(std::wstring mapFile)
|
||||||
// load models
|
// load models
|
||||||
obj = new C_Player();
|
obj = new C_Player();
|
||||||
privData->object.push_back(obj);
|
privData->object.push_back(obj);
|
||||||
privData->object[privData->object.size() -1 ]->Init(modelData);
|
privData->object[privData->object.size() -1 ]->Init(modelData); */
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
bool GameState::InitCamera(Oyster::Math::Float3 startPos)
|
bool GameState::InitCamera(Float3 startPos)
|
||||||
{
|
{
|
||||||
Oyster::Math::Float3 dir = Oyster::Math::Float3(0,0,1);
|
Float3 dir = Float3(0,0,1);
|
||||||
Oyster::Math::Float3 up =Oyster::Math::Float3(0,1,0);
|
Float3 up = Float3(0,1,0);
|
||||||
Oyster::Math::Float3 pos = Oyster::Math::Float3(0, 0, 20);
|
Float3 pos = Float3(0, 0, 20);
|
||||||
|
|
||||||
camera->LookAt(pos, dir, up);
|
camera->LookAt(pos, dir, up);
|
||||||
camera->SetLens(3.14f/2, 1024/768, 1, 1000);
|
camera->SetLens(pi/4, 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->UpdateViewMatrix();
|
camera->UpdateViewMatrix();
|
||||||
privData->view = camera->View();
|
Oyster::Graphics::API::SetProjection(camera->Proj());
|
||||||
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);
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
void GameState::setClientId(int id)
|
void GameState::setClientId(int id)
|
||||||
|
@ -263,25 +334,28 @@ GameClientState::ClientState GameState::Update(float deltaTime, InputClass* KeyI
|
||||||
bool GameState::Render()
|
bool GameState::Render()
|
||||||
{
|
{
|
||||||
Oyster::Graphics::API::SetView(camera->View());
|
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();
|
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();
|
Oyster::Graphics::API::EndFrame();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
bool GameState::Release()
|
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();
|
privData->object[i]->Release();
|
||||||
delete privData->object[i];
|
delete privData->object[i];
|
||||||
privData->object[i] = NULL;
|
privData->object[i] = NULL;
|
||||||
}
|
}*/
|
||||||
|
|
||||||
delete privData;
|
delete privData;
|
||||||
privData = NULL;
|
privData = NULL;
|
||||||
|
@ -440,13 +514,17 @@ void GameState::Protocol(ProtocolStruct* pos)
|
||||||
|
|
||||||
void GameState::Protocol( PlayerPos* pos )
|
void GameState::Protocol( PlayerPos* pos )
|
||||||
{
|
{
|
||||||
Oyster::Math::Float4x4 world, translate;
|
//Oyster::Math::Float4x4 world, translate;
|
||||||
|
|
||||||
world = Oyster::Math::Float4x4::identity;
|
//world = Oyster::Math::Float4x4::identity;
|
||||||
translate = 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]));
|
//translate = Oyster::Math3D::TranslationMatrix(Oyster::Math::Float3(pos->playerPos[0],pos->playerPos[1],pos->playerPos[2]));
|
||||||
world = world * translate;
|
//world = world * translate;
|
||||||
privData->object[0]->setPos( world );
|
////privData->object[0]->setPos( world );
|
||||||
|
//for (unsigned int i = 0; i < dynamicObjects.Size(); i++)
|
||||||
|
//{
|
||||||
|
// dynamicObjects[i]->Render();
|
||||||
|
//}
|
||||||
}
|
}
|
||||||
|
|
||||||
void GameState::Protocol( ObjPos* pos )
|
void GameState::Protocol( ObjPos* pos )
|
||||||
|
@ -457,21 +535,21 @@ void GameState::Protocol( ObjPos* pos )
|
||||||
world[i] = pos->worldPos[i];
|
world[i] = pos->worldPos[i];
|
||||||
}
|
}
|
||||||
//printf("pos for obj %d, ",pos->object_ID );
|
//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]);
|
Float3 right = Float3(world[0], world[1], world[2]);
|
||||||
Oyster::Math::Float3 up = Oyster::Math::Float3(world[4], world[5], world[6]);
|
Float3 up = Float3(world[4], world[5], world[6]);
|
||||||
Oyster::Math::Float3 objForward = (Oyster::Math::Float3(world[8], world[9], world[10]));
|
Float3 objForward = Float3(world[8], world[9], world[10]);
|
||||||
Oyster::Math::Float3 pos = Oyster::Math::Float3(world[12], world[13], world[14]);
|
Float3 pos = Float3(world[12], world[13], world[14]);
|
||||||
|
|
||||||
Oyster::Math::Float3 cameraLook = camera->GetLook();
|
Float3 cameraLook = camera->GetLook();
|
||||||
Oyster::Math::Float3 cameraUp = camera->GetUp();
|
Float3 cameraUp = camera->GetUp();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -506,28 +584,29 @@ void GameState::Protocol( NewObj* newObj )
|
||||||
}
|
}
|
||||||
ModelInitData modelData;
|
ModelInitData modelData;
|
||||||
|
|
||||||
modelData.world = world;
|
//modelData.world = world;
|
||||||
modelData.visible = true;
|
modelData.visible = true;
|
||||||
modelData.id = newObj->object_ID;
|
modelData.id = newObj->object_ID;
|
||||||
//not sure if this is good parsing rom char* to wstring
|
//not sure if this is good parsing rom char* to wstring
|
||||||
const char* path = newObj->path;
|
const char* path = newObj->path;
|
||||||
modelData.modelPath = std::wstring(path, path + strlen(path));
|
modelData.modelPath = std::wstring(path, path + strlen(path));
|
||||||
// load models
|
// load models
|
||||||
C_Object* player = new C_Player();
|
C_DynamicObj* player = new C_DynamicObj();
|
||||||
player->Init(modelData);
|
player->Init(modelData);
|
||||||
|
|
||||||
privData->object.push_back(player);
|
dynamicObjects.Push(player);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void DanBias::Client::GameState::Protocol( RemoveObj* obj )
|
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();
|
//dynamicObjects[i]->Release();
|
||||||
privData->object.erase(privData->object.begin() + i );
|
dynamicObjects[i].Release();
|
||||||
|
//dynamicObjects.erase(privData->object.begin() + i );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//privData->object[obj->object_ID]->Release( );
|
//privData->object[obj->object_ID]->Release( );
|
||||||
|
|
|
@ -4,6 +4,11 @@
|
||||||
#include "OysterMath.h"
|
#include "OysterMath.h"
|
||||||
#include <string>
|
#include <string>
|
||||||
#include "Camera.h"
|
#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 DanBias
|
||||||
{
|
{
|
||||||
namespace Client
|
namespace Client
|
||||||
|
@ -30,12 +35,15 @@ private:
|
||||||
float pitch;
|
float pitch;
|
||||||
struct myData;
|
struct myData;
|
||||||
myData* privData;
|
myData* privData;
|
||||||
|
Utility::DynamicMemory::DynamicArray<Utility::DynamicMemory::SmartPointer<C_StaticObj>> staticObjects;
|
||||||
|
Utility::DynamicMemory::DynamicArray<Utility::DynamicMemory::SmartPointer<C_DynamicObj>> dynamicObjects;
|
||||||
|
Utility::DynamicMemory::DynamicArray<Utility::DynamicMemory::SmartPointer<C_DynamicObj>> playObjects;
|
||||||
public:
|
public:
|
||||||
GameState(void);
|
GameState(void);
|
||||||
~GameState(void);
|
~GameState(void);
|
||||||
bool Init(Oyster::Network::NetworkClient* nwClient);
|
bool Init(Oyster::Network::NetworkClient* nwClient);
|
||||||
GameClientState::ClientState Update(float deltaTime, InputClass* KeyInput) override;
|
GameClientState::ClientState Update(float deltaTime, InputClass* KeyInput) override;
|
||||||
bool LoadModels(std::wstring mapFile) ;
|
bool LoadModels(std::string mapFile) ;
|
||||||
bool InitCamera(Oyster::Math::Float3 startPos) ;
|
bool InitCamera(Oyster::Math::Float3 startPos) ;
|
||||||
gameStateState LoadGame();
|
gameStateState LoadGame();
|
||||||
void setClientId(int id);
|
void setClientId(int id);
|
||||||
|
|
|
@ -64,15 +64,16 @@ bool LanMenuState::LoadModels(std::wstring file)
|
||||||
|
|
||||||
ModelInitData modelData;
|
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.visible = true;
|
||||||
modelData.modelPath = L"..\\Content\\Models\\box_2.dan";
|
modelData.modelPath = L"..\\Content\\Models\\box_2.dan";
|
||||||
// load models
|
// load models
|
||||||
privData->object[0] = new C_StaticObj();
|
privData->object[0] = new C_StaticObj();
|
||||||
privData->object[0]->Init(modelData);
|
privData->object[0]->Init(modelData);
|
||||||
|
|
||||||
Oyster::Math3D::Float4x4 translate = Oyster::Math3D::TranslationMatrix(Oyster::Math::Float3(-2,-2,-2));
|
modelData.position = Oyster::Math::Float3(-2, -2, -2);
|
||||||
modelData.world = modelData.world * translate;
|
|
||||||
|
|
||||||
privData->object[1] = new C_DynamicObj();
|
privData->object[1] = new C_DynamicObj();
|
||||||
privData->object[1]->Init(modelData);
|
privData->object[1]->Init(modelData);
|
||||||
|
|
|
@ -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<Utility::DynamicMemory::SmartPointer<ObjectTypeHeader>> LevelLoader::LoadLevel(std::string fileName)
|
||||||
|
{
|
||||||
|
return pData->parser.Parse(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
LevelMetaData LevelLoader::LoadLevelHeader(std::string fileName)
|
||||||
|
{
|
||||||
|
return pData->parser.ParseHeader(fileName);
|
||||||
|
}
|
|
@ -0,0 +1,42 @@
|
||||||
|
//////////////////////////////////
|
||||||
|
// Created by Sam Svensson 2013 //
|
||||||
|
//////////////////////////////////
|
||||||
|
|
||||||
|
#ifndef LEVELLOADER_H
|
||||||
|
#define LEVELLOADER_H
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
#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<Utility::DynamicMemory::SmartPointer<ObjectTypeHeader>> 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<PrivData> pData;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
|
@ -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<SmartPointer<ObjectTypeHeader>> LevelParser::Parse(std::string filename)
|
||||||
|
{
|
||||||
|
int bufferSize = 0;
|
||||||
|
int counter = 0;
|
||||||
|
|
||||||
|
std::vector<SmartPointer<ObjectTypeHeader>> 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;
|
||||||
|
}
|
|
@ -0,0 +1,31 @@
|
||||||
|
#ifndef LEVEL_PARSER_H
|
||||||
|
#define LEVEL_PARSER_H
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
#include "ObjectDefines.h"
|
||||||
|
#include "../Misc/Utilities.h"
|
||||||
|
|
||||||
|
namespace GameLogic
|
||||||
|
{
|
||||||
|
namespace LevelFileLoader
|
||||||
|
{
|
||||||
|
class LevelParser
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
LevelParser();
|
||||||
|
~LevelParser();
|
||||||
|
|
||||||
|
//
|
||||||
|
std::vector<Utility::DynamicMemory::SmartPointer<ObjectTypeHeader>> Parse(std::string filename);
|
||||||
|
|
||||||
|
//
|
||||||
|
LevelMetaData ParseHeader(std::string filename);
|
||||||
|
|
||||||
|
private:
|
||||||
|
FormatVersion formatVersion;
|
||||||
|
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
|
@ -0,0 +1,22 @@
|
||||||
|
//////////////////////////////////
|
||||||
|
// Created by Sam Svensson 2013 //
|
||||||
|
//////////////////////////////////
|
||||||
|
|
||||||
|
#include "Loader.h"
|
||||||
|
#include <fstream>
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
|
@ -0,0 +1,28 @@
|
||||||
|
//////////////////////////////////
|
||||||
|
// Created by Sam Svensson 2013 //
|
||||||
|
//////////////////////////////////
|
||||||
|
|
||||||
|
#ifndef LOADER_H
|
||||||
|
#define LOADER_H
|
||||||
|
|
||||||
|
#include "..\Misc\Resource\OysterResource.h"
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
namespace GameLogic
|
||||||
|
{
|
||||||
|
namespace LevelFileLoader
|
||||||
|
{
|
||||||
|
class Loader
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
Loader (){};
|
||||||
|
~Loader(){};
|
||||||
|
char* LoadFile(std::string fileName, int &size);
|
||||||
|
|
||||||
|
//TODO:
|
||||||
|
//Add functionality to load physicsObjects (hitboxes)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif;
|
|
@ -0,0 +1,172 @@
|
||||||
|
#ifndef OBJECT_DEFINES_H
|
||||||
|
#define OBJECT_DEFINES_H
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
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<GameMode> 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
|
|
@ -0,0 +1,111 @@
|
||||||
|
//////////////////////////////////
|
||||||
|
// Created by Sam Svensson 2013 //
|
||||||
|
//////////////////////////////////
|
||||||
|
|
||||||
|
#include "ParseFunctions.h"
|
||||||
|
#include "../../../../Misc/Packing/Packing.h"
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -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
|
|
@ -53,17 +53,18 @@ bool LobbyState::LoadModels(std::wstring file)
|
||||||
|
|
||||||
ModelInitData modelData;
|
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.visible = true;
|
||||||
modelData.modelPath = L"..\\Content\\Models\\box_2.dan";
|
modelData.modelPath = L"..\\Content\\Models\\box_2.dan";
|
||||||
// load models
|
// load models
|
||||||
privData->object[0] = new C_StaticObj();
|
privData->object[0] = new C_StaticObj();
|
||||||
privData->object[0]->Init(modelData);
|
privData->object[0]->Init(modelData);
|
||||||
|
|
||||||
Oyster::Math3D::Float4x4 translate = Oyster::Math3D::TranslationMatrix(Oyster::Math::Float3(2,2,2));
|
modelData.position = Oyster::Math::Float3(2,2,2);
|
||||||
modelData.world = modelData.world * translate;
|
|
||||||
|
|
||||||
privData->object[1] = new C_DynamicObj();
|
privData->object[1] = new C_StaticObj();
|
||||||
privData->object[1]->Init(modelData);
|
privData->object[1]->Init(modelData);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -53,26 +53,18 @@ bool LoginState::LoadModels(std::wstring file)
|
||||||
|
|
||||||
ModelInitData modelData;
|
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.visible = true;
|
||||||
modelData.modelPath = L"identityPlane.dan";
|
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);
|
privData->object[0]->Init(modelData);
|
||||||
|
|
||||||
translate = Oyster::Math3D::TranslationMatrix(Oyster::Math::Float3(0,0,-2));
|
modelData.position = Oyster::Math::Float3(0,0,-2);
|
||||||
modelData.world = translate ;//* rot;
|
privData->object[1] = new C_StaticObj();
|
||||||
|
|
||||||
privData->object[1] = new C_DynamicObj();
|
|
||||||
privData->object[1]->Init(modelData);
|
privData->object[1]->Init(modelData);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -81,7 +81,8 @@ Game::LevelData* Game::CreateLevel()
|
||||||
if(this->level) return this->level;
|
if(this->level) return this->level;
|
||||||
|
|
||||||
this->level = new LevelData();
|
this->level = new LevelData();
|
||||||
this->level->level->InitiateLevel(1000);
|
//this->level->level->InitiateLevel(1000);
|
||||||
|
this->level->level->InitiateLevel("3bana.bias");
|
||||||
|
|
||||||
return this->level;
|
return this->level;
|
||||||
}
|
}
|
||||||
|
|
|
@ -181,7 +181,7 @@
|
||||||
<ClInclude Include="GameAPI.h" />
|
<ClInclude Include="GameAPI.h" />
|
||||||
<ClInclude Include="GameLogicDef.h" />
|
<ClInclude Include="GameLogicDef.h" />
|
||||||
<ClInclude Include="GameLogicStates.h" />
|
<ClInclude Include="GameLogicStates.h" />
|
||||||
<ClInclude Include="GameMode.h" />
|
<ClInclude Include="GameModeType.h" />
|
||||||
<ClInclude Include="IAttatchment.h" />
|
<ClInclude Include="IAttatchment.h" />
|
||||||
<ClInclude Include="JumpPad.h" />
|
<ClInclude Include="JumpPad.h" />
|
||||||
<ClInclude Include="Level.h" />
|
<ClInclude Include="Level.h" />
|
||||||
|
@ -203,7 +203,7 @@
|
||||||
<ClCompile Include="CollisionManager.cpp" />
|
<ClCompile Include="CollisionManager.cpp" />
|
||||||
<ClCompile Include="DynamicObject.cpp" />
|
<ClCompile Include="DynamicObject.cpp" />
|
||||||
<ClCompile Include="Game.cpp" />
|
<ClCompile Include="Game.cpp" />
|
||||||
<ClCompile Include="GameMode.cpp" />
|
<ClCompile Include="GameModeType.cpp" />
|
||||||
<ClCompile Include="Game_LevelData.cpp" />
|
<ClCompile Include="Game_LevelData.cpp" />
|
||||||
<ClCompile Include="Game_PlayerData.cpp" />
|
<ClCompile Include="Game_PlayerData.cpp" />
|
||||||
<ClCompile Include="IAttatchment.cpp" />
|
<ClCompile Include="IAttatchment.cpp" />
|
||||||
|
|
|
@ -1,15 +0,0 @@
|
||||||
#include "GameMode.h"
|
|
||||||
|
|
||||||
using namespace GameLogic;
|
|
||||||
|
|
||||||
|
|
||||||
GameMode::GameMode()
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
GameMode::~GameMode(void)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
|
@ -0,0 +1,15 @@
|
||||||
|
#include "GameModeType.h"
|
||||||
|
|
||||||
|
using namespace GameLogic;
|
||||||
|
|
||||||
|
|
||||||
|
GameModeType::GameModeType()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
GameModeType::~GameModeType(void)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
|
@ -3,16 +3,16 @@
|
||||||
//////////////////////////////////////////////////
|
//////////////////////////////////////////////////
|
||||||
|
|
||||||
|
|
||||||
#ifndef GAMEMODE_H
|
#ifndef GAMEMODETYPE_H
|
||||||
#define GAMEMODE_H
|
#define GAMEMODETYPE_H
|
||||||
|
|
||||||
namespace GameLogic
|
namespace GameLogic
|
||||||
{
|
{
|
||||||
class GameMode
|
class GameModeType
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
GameMode(void);
|
GameModeType(void);
|
||||||
~GameMode(void);
|
~GameModeType(void);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -19,7 +19,7 @@ Game::PlayerData::PlayerData()
|
||||||
Oyster::Physics::ICustomBody *rigidBody = Oyster::Physics::API::Instance().CreateRigidBody(sbDesc).Release();
|
Oyster::Physics::ICustomBody *rigidBody = Oyster::Physics::API::Instance().CreateRigidBody(sbDesc).Release();
|
||||||
|
|
||||||
//create player with this rigid body
|
//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);
|
this->player->GetRigidBody()->SetCustomTag(this);
|
||||||
/*Oyster::Physics::ICustomBody::State state;
|
/*Oyster::Physics::ICustomBody::State state;
|
||||||
this->player->GetRigidBody()->GetState(state);
|
this->player->GetRigidBody()->GetState(state);
|
||||||
|
|
|
@ -13,10 +13,183 @@ Level::Level(void)
|
||||||
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)
|
void Level::InitiateLevel(std::string levelPath)
|
||||||
{
|
{
|
||||||
|
LevelLoader ll;
|
||||||
|
std::vector<Utility::DynamicMemory::SmartPointer<ObjectTypeHeader>> 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)
|
void Level::InitiateLevel(float radius)
|
||||||
{
|
{
|
||||||
|
|
|
@ -8,11 +8,12 @@
|
||||||
#include "Player.h"
|
#include "Player.h"
|
||||||
#include "StaticObject.h"
|
#include "StaticObject.h"
|
||||||
#include "DynamicObject.h"
|
#include "DynamicObject.h"
|
||||||
#include "GameMode.h"
|
#include "GameModeType.h"
|
||||||
#include "Player.h"
|
#include "Player.h"
|
||||||
#include "PhysicsAPI.h"
|
#include "PhysicsAPI.h"
|
||||||
#include "TeamManager.h"
|
#include "TeamManager.h"
|
||||||
#include "DynamicArray.h"
|
#include "DynamicArray.h"
|
||||||
|
#include "LevelLoader/LevelLoader.h"
|
||||||
|
|
||||||
namespace GameLogic
|
namespace GameLogic
|
||||||
{
|
{
|
||||||
|
@ -29,8 +30,10 @@ namespace GameLogic
|
||||||
* @param levelPath: Path to a file that contains all information on the level
|
* @param levelPath: Path to a file that contains all information on the level
|
||||||
********************************************************/
|
********************************************************/
|
||||||
void InitiateLevel(std::string levelPath);
|
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
|
* Creates a team in the level
|
||||||
* @param teamSize: The size of the team you want to create
|
* @param teamSize: The size of the team you want to create
|
||||||
|
@ -69,7 +72,7 @@ namespace GameLogic
|
||||||
TeamManager teamManager;
|
TeamManager teamManager;
|
||||||
Utility::DynamicMemory::DynamicArray<Utility::DynamicMemory::SmartPointer<StaticObject>> staticObjects;
|
Utility::DynamicMemory::DynamicArray<Utility::DynamicMemory::SmartPointer<StaticObject>> staticObjects;
|
||||||
Utility::DynamicMemory::DynamicArray<Utility::DynamicMemory::SmartPointer<DynamicObject>> dynamicObjects;
|
Utility::DynamicMemory::DynamicArray<Utility::DynamicMemory::SmartPointer<DynamicObject>> dynamicObjects;
|
||||||
GameMode gameMode;
|
GameModeType gameMode;
|
||||||
Utility::DynamicMemory::SmartPointer<Oyster::Physics::ICustomBody> rigidBodyLevel;
|
Utility::DynamicMemory::SmartPointer<Oyster::Physics::ICustomBody> rigidBodyLevel;
|
||||||
StaticObject *levelObj;
|
StaticObject *levelObj;
|
||||||
|
|
||||||
|
|
|
@ -178,13 +178,13 @@ void Object::EndFrame()
|
||||||
//300, 0,0,
|
//300, 0,0,
|
||||||
//1,0,0
|
//1,0,0
|
||||||
|
|
||||||
/*if( pos.GetLength() < 303.5f)
|
if( pos.GetLength() < 303.5f)
|
||||||
{
|
{
|
||||||
Oyster::Math::Float moveUp = 303.5 - pos.GetLength();
|
Oyster::Math::Float moveUp = 303.5 - pos.GetLength();
|
||||||
up *= moveUp;
|
up *= moveUp;
|
||||||
|
|
||||||
currPhysicsState.SetCenterPosition(pos + up);
|
currPhysicsState.SetCenterPosition(pos + up);
|
||||||
}*/
|
}
|
||||||
|
|
||||||
|
|
||||||
if(currPhysicsState.GetLinearMomentum() !=currPhysicsState.GetLinearMomentum())
|
if(currPhysicsState.GetLinearMomentum() !=currPhysicsState.GetLinearMomentum())
|
||||||
|
|
|
@ -27,6 +27,7 @@ namespace GameLogic
|
||||||
|
|
||||||
// API overrides
|
// API overrides
|
||||||
OBJECT_TYPE GetObjectType() const;
|
OBJECT_TYPE GetObjectType() const;
|
||||||
|
void setID(int id);
|
||||||
int GetID() const;
|
int GetID() const;
|
||||||
Oyster::Math::Float3 GetPosition();
|
Oyster::Math::Float3 GetPosition();
|
||||||
Oyster::Math::Float4x4 GetOrientation();
|
Oyster::Math::Float4x4 GetOrientation();
|
||||||
|
|
|
@ -51,8 +51,8 @@ void RigidBody::Update_LeapFrog( Float updateFrameLength )
|
||||||
// updating the linear
|
// updating the linear
|
||||||
//Decrease momentum with 1% as "fall-off"
|
//Decrease momentum with 1% as "fall-off"
|
||||||
//! HACK: @todo Add real solution with fluid drag
|
//! HACK: @todo Add real solution with fluid drag
|
||||||
//this->momentum_Linear = this->momentum_Linear*0.99f;
|
this->momentum_Linear = this->momentum_Linear*0.99f;
|
||||||
//this->momentum_Angular = this->momentum_Angular*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
|
// ds = dt * Formula::LinearVelocity( m, avg_G ) = dt * avg_G / m = (dt / m) * avg_G
|
||||||
Float3 delta = AverageWithDelta( this->momentum_Linear, this->impulse_Linear );
|
Float3 delta = AverageWithDelta( this->momentum_Linear, this->impulse_Linear );
|
||||||
|
|
Loading…
Reference in New Issue