Merged with GameLogic and fixed merging errors, some minor justifications may be needed later on due to merging errors..

This commit is contained in:
Dennis Andersen 2014-02-09 18:58:07 +01:00
commit 4abfdd70fe
12 changed files with 464 additions and 103 deletions

View File

@ -87,12 +87,10 @@ bool GameState::LoadModels(std::wstring mapFile)
// open file // open file
// read file // read file
// init models // init models
int nrOfBoxex = 20;
int nrOfBoxex = 5;
int id = 100; int id = 100;
// add world model // add world model
ModelInitData modelData; ModelInitData modelData;
Oyster::Math3D::Float4x4 translate; Oyster::Math3D::Float4x4 translate;
C_Object* obj; C_Object* obj;
@ -108,7 +106,7 @@ bool GameState::LoadModels(std::wstring mapFile)
/* /*
// add box model // add box model
modelData.world = Oyster::Math3D::Float4x4::identity; modelData.world = Oyster::Math3D::Float4x4::identity;
modelData.modelPath = L"box.dan"; modelData.modelPath = L"crate_colonists.dan";
for(int i =0; i< nrOfBoxex; i ++) for(int i =0; i< nrOfBoxex; i ++)
@ -125,7 +123,7 @@ bool GameState::LoadModels(std::wstring mapFile)
// add crystal model // add crystal model
modelData.world = Oyster::Math3D::Float4x4::identity; modelData.world = Oyster::Math3D::Float4x4::identity;
translate = Oyster::Math3D::TranslationMatrix(Oyster::Math::Float3(10, 305, 0)); translate = Oyster::Math3D::TranslationMatrix(Oyster::Math::Float3(10, 301, 0));
modelData.world = modelData.world * translate; modelData.world = modelData.world * translate;
modelData.visible = true; modelData.visible = true;
@ -138,10 +136,11 @@ bool GameState::LoadModels(std::wstring mapFile)
// add house model // add house model
modelData.world = Oyster::Math3D::Float4x4::identity; modelData.world = Oyster::Math3D::Float4x4::identity;
translate = Oyster::Math3D::TranslationMatrix(Oyster::Math::Float3(50, 300, 0)); translate = Oyster::Math3D::TranslationMatrix(Oyster::Math::Float3(-50, 290, 0));
//Oyster::Math3D::RotationMatrix_AxisZ() Oyster::Math3D::Float4x4 rot = Oyster::Math3D::RotationMatrix(Oyster::Math::Float3(0 ,Utility::Value::Radian(90.0f), 0));
modelData.world = modelData.world * translate;
modelData.visible = false; modelData.world = modelData.world * translate * rot;
modelData.visible = true;
modelData.modelPath = L"building_corporation.dan"; modelData.modelPath = L"building_corporation.dan";
modelData.id = id++; modelData.id = id++;
// load models // load models
@ -150,6 +149,35 @@ bool GameState::LoadModels(std::wstring mapFile)
privData->object[privData->object.size() -1 ]->Init(modelData); privData->object[privData->object.size() -1 ]->Init(modelData);
*/ */
// add jumppad
modelData.world = Oyster::Math3D::Float4x4::identity;
translate = Oyster::Math3D::TranslationMatrix(Oyster::Math::Float3(4, 300.3, 0));
//Oyster::Math3D::RotationMatrix_AxisZ()
modelData.world = modelData.world * translate;
modelData.visible = true;
modelData.modelPath = L"jumppad_round.dan";
modelData.id = id++;
// load models
obj = new C_Player();
privData->object.push_back(obj);
privData->object[privData->object.size() -1 ]->Init(modelData);
// add sky sphere
modelData.world = Oyster::Math3D::Float4x4::identity;
translate = Oyster::Math3D::TranslationMatrix(Oyster::Math::Float3(0, 0, 0));
//Oyster::Math3D::RotationMatrix_AxisZ()
modelData.world = modelData.world * translate;
modelData.world.v[0].x = 800;
modelData.world.v[1].y = 800;
modelData.world.v[2].z = 800;
modelData.visible = true;
modelData.modelPath = L"skysphere.dan";
modelData.id = id++;
// load models
obj = new C_Player();
privData->object.push_back(obj);
privData->object[privData->object.size() -1 ]->Init(modelData);
return true; return true;
} }
bool GameState::InitCamera(Oyster::Math::Float3 startPos) bool GameState::InitCamera(Oyster::Math::Float3 startPos)
@ -475,8 +503,8 @@ void GameState::Protocol( ObjPos* pos )
camera->setUp(up); camera->setUp(up);
camera->setLook(objForward); camera->setLook(objForward);
up *= 2; up *= 1;
objForward *= -3; objForward *= -2;
Oyster::Math::Float3 cameraPos = up + pos + objForward; Oyster::Math::Float3 cameraPos = up + pos + objForward;
camera->SetPosition(cameraPos); camera->SetPosition(cameraPos);

View File

@ -41,7 +41,7 @@ bool LoginState::Init(Oyster::Network::NetworkClient* nwClient)
bool LoginState::LoadModels(std::wstring file) bool LoginState::LoadModels(std::wstring file)
{ {
Oyster::Graphics::Definitions::Pointlight plight; Oyster::Graphics::Definitions::Pointlight plight;
plight.Pos = Oyster::Math::Float3(0,0,5.4f); plight.Pos = Oyster::Math::Float3(0,0,5);
plight.Color = Oyster::Math::Float3(1,1,1); plight.Color = Oyster::Math::Float3(1,1,1);
plight.Radius = 100; plight.Radius = 100;
plight.Bright = 1; plight.Bright = 1;
@ -55,14 +55,22 @@ bool LoginState::LoadModels(std::wstring file)
modelData.world = Oyster::Math3D::Float4x4::identity; modelData.world = Oyster::Math3D::Float4x4::identity;
modelData.visible = true; modelData.visible = true;
modelData.modelPath = L"box_2.dan"; modelData.modelPath = L"identityPlane.dan";
// load models // load models
Oyster::Math3D::Float4x4 translate = Oyster::Math3D::TranslationMatrix(Oyster::Math::Float3(2,2,2)); 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(); privData->object[0] = new C_DynamicObj();
privData->object[0]->Init(modelData); privData->object[0]->Init(modelData);
translate = Oyster::Math3D::TranslationMatrix(Oyster::Math::Float3(-2,-2,-2)); translate = Oyster::Math3D::TranslationMatrix(Oyster::Math::Float3(0,0,-2));
modelData.world = modelData.world * translate; modelData.world = translate ;//* rot;
privData->object[1] = new C_DynamicObj(); privData->object[1] = new C_DynamicObj();
privData->object[1]->Init(modelData); privData->object[1]->Init(modelData);
@ -97,7 +105,7 @@ GameClientState::ClientState LoginState::Update(float deltaTime, InputClass* Key
DanBias::GameServerAPI::ServerInitiate(desc); DanBias::GameServerAPI::ServerInitiate(desc);
DanBias::GameServerAPI::ServerStart(); DanBias::GameServerAPI::ServerStart();
// my ip // my ip
nwClient->Connect(15152, "127.0.0.1"); nwClient->Connect(15151, "127.0.0.1");
if (!nwClient->IsConnected()) if (!nwClient->IsConnected())
{ {
@ -110,8 +118,7 @@ GameClientState::ClientState LoginState::Update(float deltaTime, InputClass* Key
if( KeyInput->IsKeyPressed(DIK_J)) if( KeyInput->IsKeyPressed(DIK_J))
{ {
// game ip // game ip
nwClient->Connect(15152, "127.0.0.1"); nwClient->Connect(15151, "127.0.0.1");
//nwClient->Connect(15152, "193.11.187.187");
if (!nwClient->IsConnected()) if (!nwClient->IsConnected())
{ {
@ -128,7 +135,6 @@ bool LoginState::Render()
Oyster::Graphics::API::SetView(privData->view); Oyster::Graphics::API::SetView(privData->view);
Oyster::Graphics::API::SetProjection( privData->proj); Oyster::Graphics::API::SetProjection( privData->proj);
Oyster::Graphics::API::NewFrame(); Oyster::Graphics::API::NewFrame();
// render objects // render objects
for (int i = 0; i < privData->modelCount; i++) for (int i = 0; i < privData->modelCount; i++)

View File

@ -63,8 +63,10 @@ void AttatchmentMassDriver::Update(float dt)
Oyster::Physics::ICustomBody::State state; Oyster::Physics::ICustomBody::State state;
state = heldObject->GetState(); state = heldObject->GetState();
Oyster::Math::Float3 ownerPos = owner->GetPosition(); Oyster::Math::Float3 ownerPos = owner->GetPosition();
ownerPos.y += 2; Oyster::Physics::ICustomBody::State ownerState = owner->GetRigidBody()->GetState();
Oyster::Math::Float3 pos = ownerPos + owner->GetLookDir().GetNormalized()*2; Oyster::Math::Float3 up = -ownerState.GetGravityNormal();
up *= -0.3;
Oyster::Math::Float3 pos = ownerPos + up + (owner->GetLookDir().GetNormalized()*5);
state.SetCenterPosition(pos); state.SetCenterPosition(pos);
@ -84,7 +86,7 @@ void AttatchmentMassDriver::ForcePush(const GameLogic::WEAPON_FIRE &usage, float
if(hasObject) if(hasObject)
{ {
Oyster::Physics::API::Instance().ReleaseFromLimbo(heldObject); Oyster::Physics::API::Instance().ReleaseFromLimbo(heldObject);
pushForce = Oyster::Math::Float4(this->owner->GetLookDir()) * (2000); pushForce = Oyster::Math::Float4(this->owner->GetLookDir()) * (700);
Oyster::Physics::ICustomBody::State state = heldObject->GetState(); Oyster::Physics::ICustomBody::State state = heldObject->GetState();
state.ApplyLinearImpulse((Oyster::Math::Float3)pushForce); state.ApplyLinearImpulse((Oyster::Math::Float3)pushForce);
heldObject->SetState(state); heldObject->SetState(state);
@ -97,10 +99,10 @@ void AttatchmentMassDriver::ForcePush(const GameLogic::WEAPON_FIRE &usage, float
Oyster::Math::Float3 look = owner->GetLookDir(); Oyster::Math::Float3 look = owner->GetLookDir();
Oyster::Math::Float3 pos = owner->GetPosition(); Oyster::Math::Float3 pos = owner->GetPosition();
pushForce = Oyster::Math::Float4(this->owner->GetLookDir()) * (50000 * dt); pushForce = Oyster::Math::Float4(this->owner->GetLookDir()) * (20000 * dt);
Oyster::Math::Float4x4 aim = Oyster::Math3D::ViewMatrix_LookAtDirection(look, up, pos); Oyster::Math::Float4x4 aim = Oyster::Math3D::ViewMatrix_LookAtDirection(look, up, pos);
Oyster::Math::Float4x4 hitSpace = Oyster::Math3D::ProjectionMatrix_Perspective(Oyster::Math::pi/8,1,1,5); Oyster::Math::Float4x4 hitSpace = Oyster::Math3D::ProjectionMatrix_Perspective(Oyster::Math::pi/8,1,1,50);
Oyster::Collision3D::Frustrum hitFrustum = Oyster::Collision3D::Frustrum(Oyster::Math3D::ViewProjectionMatrix(aim,hitSpace)); Oyster::Collision3D::Frustrum hitFrustum = Oyster::Collision3D::Frustrum(Oyster::Math3D::ViewProjectionMatrix(aim,hitSpace));
forcePushData args; forcePushData args;
args.pushForce = pushForce; args.pushForce = pushForce;

View File

@ -7,14 +7,13 @@ Game::PlayerData::PlayerData()
{ {
//set some stats that are appropriate to a player //set some stats that are appropriate to a player
Oyster::Physics::API::SimpleBodyDescription sbDesc; Oyster::Physics::API::SimpleBodyDescription sbDesc;
sbDesc.size = Oyster::Math::Float3(4.0f ,4.0f,4.0f);
sbDesc.mass = 70;
sbDesc.centerPosition = Oyster::Math::Float3(0,308,0); sbDesc.centerPosition = Oyster::Math::Float3(0,308,0);
sbDesc.restitutionCoeff = 0.5f; sbDesc.size = Oyster::Math::Float3(0.5f,2,1);
sbDesc.frictionCoeff_Static = 0.4f; sbDesc.mass = 70;
sbDesc.frictionCoeff_Dynamic = 0.3f; sbDesc.restitutionCoeff = 0.5;
sbDesc.rotation = Oyster::Math::Float3(0.0f, Oyster::Math::pi, 0.0f); sbDesc.frictionCoeff_Static = 0.4;
sbDesc.frictionCoeff_Dynamic = 0.3;
sbDesc.rotation = Oyster::Math::Float3(0, Oyster::Math::pi, 0);
//create rigid body //create rigid body
Oyster::Physics::ICustomBody *rigidBody = Oyster::Physics::API::Instance().CreateRigidBody(sbDesc).Release(); Oyster::Physics::ICustomBody *rigidBody = Oyster::Physics::API::Instance().CreateRigidBody(sbDesc).Release();
@ -22,6 +21,11 @@ Game::PlayerData::PlayerData()
//create player with this rigid body //create player with this rigid body
this->player = new Player(rigidBody,Player::PlayerCollisionBefore, Player::PlayerCollision, OBJECT_TYPE::OBJECT_TYPE_PLAYER); this->player = new Player(rigidBody,Player::PlayerCollisionBefore, Player::PlayerCollision, OBJECT_TYPE::OBJECT_TYPE_PLAYER);
this->player->GetRigidBody()->SetCustomTag(this); this->player->GetRigidBody()->SetCustomTag(this);
/*Oyster::Physics::ICustomBody::State state;
this->player->GetRigidBody()->GetState(state);
state.SetRotation(Oyster::Math::Float3(0, Oyster::Math::pi, 0));
this->player->GetRigidBody()->SetState(state);
player->EndFrame();*/
} }
Game::PlayerData::PlayerData(int playerID,int teamID) Game::PlayerData::PlayerData(int playerID,int teamID)
{ {

View File

@ -87,9 +87,10 @@ void Level::InitiateLevel(float radius)
ICustomBody* rigidBody_TestBox; ICustomBody* rigidBody_TestBox;
int nrOfBoxex = 5; int nrOfBoxex = 5;
int offset = 0;
for(int i =0; i< nrOfBoxex; i ++) for(int i =0; i< nrOfBoxex; i ++)
{ {
sbDesc_TestBox.centerPosition = Oyster::Math::Float4(20 ,320,0 + ( i*7),0); sbDesc_TestBox.centerPosition = Oyster::Math::Float4(-20 +( i*7) ,320,20,0);
rigidBody_TestBox = API::Instance().CreateRigidBody(sbDesc_TestBox).Release(); rigidBody_TestBox = API::Instance().CreateRigidBody(sbDesc_TestBox).Release();
rigidBody_TestBox->SetSubscription(Level::PhysicsOnMoveLevel); rigidBody_TestBox->SetSubscription(Level::PhysicsOnMoveLevel);
@ -98,6 +99,36 @@ void Level::InitiateLevel(float radius)
this->dynamicObjects.Push(box); this->dynamicObjects.Push(box);
rigidBody_TestBox->SetCustomTag(this->dynamicObjects[i]); rigidBody_TestBox->SetCustomTag(this->dynamicObjects[i]);
} }
offset += nrOfBoxex;
for(int i =0; i< nrOfBoxex; i ++)
{
sbDesc_TestBox.centerPosition = Oyster::Math::Float4(-20,320, -20 +( i*7),0);
rigidBody_TestBox = API::Instance().CreateRigidBody(sbDesc_TestBox).Release();
rigidBody_TestBox->SetSubscription(Level::PhysicsOnMoveLevel);
this->dynamicObjects.Push(new DynamicObject(rigidBody_TestBox,Object::DefaultCollisionBefore, Object::DefaultCollisionAfter, OBJECT_TYPE::OBJECT_TYPE_BOX));
rigidBody_TestBox->SetCustomTag(this->dynamicObjects[i+offset]);
}
offset += nrOfBoxex;
for(int i =0; i< nrOfBoxex; i ++)
{
sbDesc_TestBox.centerPosition = Oyster::Math::Float4(20,320,-20 + ( i*7),0);
rigidBody_TestBox = API::Instance().CreateRigidBody(sbDesc_TestBox).Release();
rigidBody_TestBox->SetSubscription(Level::PhysicsOnMoveLevel);
this->dynamicObjects.Push(new DynamicObject(rigidBody_TestBox,Object::DefaultCollisionBefore, Object::DefaultCollisionAfter, OBJECT_TYPE::OBJECT_TYPE_BOX));
rigidBody_TestBox->SetCustomTag(this->dynamicObjects[i+offset]);
}
offset += nrOfBoxex;
for(int i =0; i< nrOfBoxex; i ++)
{
sbDesc_TestBox.centerPosition = Oyster::Math::Float4(-20 +( i*7) ,320,-20,0);
rigidBody_TestBox = API::Instance().CreateRigidBody(sbDesc_TestBox).Release();
rigidBody_TestBox->SetSubscription(Level::PhysicsOnMoveLevel);
this->dynamicObjects.Push(new DynamicObject(rigidBody_TestBox,Object::DefaultCollisionBefore, Object::DefaultCollisionAfter, OBJECT_TYPE::OBJECT_TYPE_BOX));
rigidBody_TestBox->SetCustomTag(this->dynamicObjects[i+offset]);
}
// add crystal // add crystal
API::SimpleBodyDescription sbDesc_Crystal; API::SimpleBodyDescription sbDesc_Crystal;
@ -116,22 +147,23 @@ void Level::InitiateLevel(float radius)
// add house // add house
API::SimpleBodyDescription sbDesc_House; API::SimpleBodyDescription sbDesc_House;
sbDesc_House.centerPosition = Oyster::Math::Float4(50, 300, 0, 0); //sbDesc_House.centerPosition = Oyster::Math::Float4(212, 212, 0, 0);
sbDesc_House.centerPosition = Oyster::Math::Float4(-50, 290, 0, 0);
sbDesc_House.ignoreGravity = false; sbDesc_House.ignoreGravity = false;
sbDesc_House.rotation = Oyster::Math::Float3(0 ,Utility::Value::Radian(90.0f), 0);
sbDesc_House.mass = 70; sbDesc_House.mass = 70;
sbDesc_House.size = Oyster::Math::Float4(2,3,2,0); sbDesc_House.size = Oyster::Math::Float4(40,40,40,0);
ICustomBody* rigidBody_House = API::Instance().CreateRigidBody(sbDesc_House).Release(); ICustomBody* rigidBody_House = API::Instance().CreateRigidBody(sbDesc_House).Release();
rigidBody_House->SetSubscription(Level::PhysicsOnMoveLevel); rigidBody_House->SetSubscription(Level::PhysicsOnMoveLevel);
StaticObject* house = new StaticObject(rigidBody_House,Object::DefaultCollisionBefore, Object::DefaultCollisionAfter, OBJECT_TYPE::OBJECT_TYPE_GENERIC); this->staticObjects.Push(new StaticObject(rigidBody_House,Object::DefaultCollisionBefore, Object::DefaultCollisionAfter, OBJECT_TYPE::OBJECT_TYPE_GENERIC));
house->objectID = idCount++;
this->staticObjects.Push(house);
rigidBody_House->SetCustomTag(this->staticObjects[0]); rigidBody_House->SetCustomTag(this->staticObjects[0]);
*/ rigidBody_House->GetState(state);
Oyster::Math::Float4x4 world = state.GetOrientation();
// add gravitation
// add gravitation
API::Gravity gravityWell; API::Gravity gravityWell;
gravityWell.gravityType = API::Gravity::GravityType_Well; gravityWell.gravityType = API::Gravity::GravityType_Well;
gravityWell.well.mass = 1e17f; gravityWell.well.mass = 1e17f;

View File

@ -4,17 +4,20 @@
#include "LevelLoader.h" #include "LevelLoader.h"
#include "LevelParser.h" #include "LevelParser.h"
using namespace GameLogic; using namespace GameLogic;
using namespace GameLogic::LevelFileLoader; using namespace GameLogic::LevelFileLoader;
struct LevelLoader::PrivData struct LevelLoader::PrivData
{ {
LevelParser parser; LevelParser parser;
std::string folderPath;
}; };
LevelLoader::LevelLoader() LevelLoader::LevelLoader()
: pData(new PrivData) : pData(new PrivData)
{ {
pData->folderPath = "Standard path";
} }
LevelLoader::~LevelLoader() LevelLoader::~LevelLoader()

View File

@ -1,3 +1,7 @@
/////////////////////////////////////
// Created by Pontus Fransson 2013 //
/////////////////////////////////////
#include "LevelParser.h" #include "LevelParser.h"
#include "Loader.h" #include "Loader.h"
@ -9,7 +13,7 @@ using namespace Utility::DynamicMemory;
LevelParser::LevelParser() LevelParser::LevelParser()
{ {
formatVersion.formatVersionMajor = 1; formatVersion.formatVersionMajor = 2;
formatVersion.formatVersionMinor = 0; formatVersion.formatVersionMinor = 0;
} }
@ -29,35 +33,100 @@ std::vector<SmartPointer<ObjectTypeHeader>> LevelParser::Parse(std::string filen
char* buffer = (char*)loader.LoadFile(filename.c_str(), bufferSize); char* buffer = (char*)loader.LoadFile(filename.c_str(), bufferSize);
//Read format version //Read format version
FormatVersion levelFormatVersion; LevelLoaderInternal::FormatVersion levelFormatVersion;
ParseObject(&buffer[counter], &levelFormatVersion, sizeof(levelFormatVersion)); ParseObject(&buffer[counter], &levelFormatVersion, sizeof(levelFormatVersion));
counter += sizeof(levelFormatVersion); counter += sizeof(levelFormatVersion);
if(this->formatVersion != levelFormatVersion) if(this->formatVersion != levelFormatVersion)
{ {
//Do something if it's not the same version //Do something if it's not the same version
//Returns an empty vector, because it will most likely fail to read the level format.
return objects;
} }
while(counter < bufferSize) while(counter < bufferSize)
{ {
//Get typeID //Get typeID
ObjectTypeHeader typeID; ObjectType typeID;
ParseObject(&buffer[counter], &typeID, sizeof(typeID)); ParseObject(&buffer[counter], &typeID, sizeof(typeID));
switch((int)typeID.typeID) switch((int)typeID)
{ {
case ObjectType_LevelMetaData: case ObjectType_LevelMetaData:
{ {
LevelMetaData* header = new LevelMetaData; SmartPointer<ObjectTypeHeader> header = new LevelMetaData;
ParseLevelMetaData(&buffer[counter], *header, counter); ParseLevelMetaData(&buffer[counter], *(LevelMetaData*)header.Get(), counter);
objects.push_back(header); objects.push_back(header);
break; break;
} }
//This is by design, static and dynamic is using the same converter. Do not add anything inbetween them. //This is by design, static and dynamic is using the same converter. Do not add anything inbetween them.
//Unless they are changed to not be the same.
case ObjectType_Static: case ObjectType_Dynamic: case ObjectType_Static: case ObjectType_Dynamic:
{
//Get specialType.
ObjectSpecialType specialType;
ParseObject(&buffer[counter+4], &specialType, sizeof(typeID));
switch(specialType)
{
//These three does not have any specail variables at this time.
//There for they are using the same 'parser'.
case ObjectSpecialType_World:
case ObjectSpecialType_Building:
case ObjectSpecialType_Damaging:
case ObjectSpecialType_Explosive:
{ {
ObjectHeader* header = new ObjectHeader; ObjectHeader* header = new ObjectHeader;
ParseObject(&buffer[counter], *header, counter); ParseObject(&buffer[counter], *header, counter);
objects.push_back(header); objects.push_back(header);
break;
}
case ObjectSpecialType_JumpPad:
{
JumpPadAttributes* header = new JumpPadAttributes;
ParseObject(&buffer[counter], *header, counter);
//Read the spec
ParseObject(&buffer[counter], header->direction, 16);
objects.push_back(header);
break;
}
case ObjectSpecialType_BoostPad:
{
JumpPadAttributes* header = new JumpPadAttributes;
ParseObject(&buffer[counter], *header, counter);
ParseObject(&buffer[counter], header->direction, 16);
objects.push_back(header);
break;
}
case ObjectSpecialType_Portal:
{
PortalAttributes* header = new PortalAttributes;
ParseObject(&buffer[counter], *header, counter);
ParseObject(&buffer[counter], header->destination, 12);
objects.push_back(header);
break;
}
case ObjectSpecialType_SpawnPoint:
{
SpawnPointAttributes* header = new SpawnPointAttributes;
ParseObject(&buffer[counter], *header, counter);
ParseObject(&buffer[counter], header->spawnPosition, 12);
objects.push_back(header);
break;
}
default:
//Couldn't find specialType
break;
}
break; break;
} }
@ -68,7 +137,12 @@ std::vector<SmartPointer<ObjectTypeHeader>> LevelParser::Parse(std::string filen
//Get Light type //Get Light type
ParseObject(&buffer[counter+4], &lightType, sizeof(lightType)); ParseObject(&buffer[counter+4], &lightType, sizeof(lightType));
switch(lightType) //We only support PointLight for now.
BasicLight* header = new BasicLight;
ParseObject(&buffer[counter], header, sizeof(*header));
counter += sizeof(*header);
objects.push_back(header);
/*switch(lightType)
{ {
case LightType_PointLight: case LightType_PointLight:
{ {
@ -98,7 +172,7 @@ std::vector<SmartPointer<ObjectTypeHeader>> LevelParser::Parse(std::string filen
//Undefined LightType. //Undefined LightType.
break; break;
} }
break; break;*/
} }
default: default:
//Couldn't find typeID. FAIL!!!!!! //Couldn't find typeID. FAIL!!!!!!
@ -123,21 +197,25 @@ LevelMetaData LevelParser::ParseHeader(std::string filename)
char* buffer = (char*)loader.LoadFile(filename.c_str(), bufferSize); char* buffer = (char*)loader.LoadFile(filename.c_str(), bufferSize);
//Read format version //Read format version
FormatVersion levelFormatVersion; LevelLoaderInternal::FormatVersion levelFormatVersion;
ParseObject(&buffer[counter], &levelFormatVersion, sizeof(formatVersion)); ParseObject(&buffer[counter], &levelFormatVersion, sizeof(formatVersion));
counter += sizeof(levelFormatVersion); counter += sizeof(levelFormatVersion);
if(this->formatVersion != levelFormatVersion) if(this->formatVersion != levelFormatVersion)
{ {
//Do something if it's not the same version //Do something if it's not the same version
//Returns an empty levelHeader with ObjectType_Unknown.
//Because it will not be able to read another version of the level format.
return levelHeader;
} }
//Find the header in the returned string. //Find the header in the returned string.
while(counter < bufferSize) while(counter < bufferSize)
{ {
ObjectTypeHeader typeID; ObjectType typeID;
ParseObject(&buffer[counter], &typeID, sizeof(typeID)); ParseObject(&buffer[counter], &typeID, sizeof(typeID));
switch(typeID.typeID) switch(typeID)
{ {
case ObjectType_LevelMetaData: case ObjectType_LevelMetaData:
ParseLevelMetaData(&buffer[counter], levelHeader, counter); ParseLevelMetaData(&buffer[counter], levelHeader, counter);
@ -149,6 +227,24 @@ LevelMetaData LevelParser::ParseHeader(std::string filename)
{ {
ObjectHeader header; ObjectHeader header;
ParseObject(&buffer[counter], header, counter); ParseObject(&buffer[counter], header, counter);
switch(header.specialTypeID)
{
case ObjectSpecialType_JumpPad:
counter += sizeof(16);
break;
case ObjectSpecialType_BoostPad:
counter += sizeof(16);
break;
case ObjectSpecialType_Portal:
counter += sizeof(12);
break;
case ObjectSpecialType_SpawnPoint:
counter += sizeof(12);
break;
default:
break;
}
break; break;
} }
@ -157,6 +253,9 @@ LevelMetaData LevelParser::ParseHeader(std::string filename)
LightType lightType; LightType lightType;
ParseObject(&buffer[counter+4], &lightType, sizeof(lightType)); ParseObject(&buffer[counter+4], &lightType, sizeof(lightType));
//We only support pointlight for now.
counter += sizeof(BasicLight);
/*
switch(lightType) switch(lightType)
{ {
case LightType_PointLight: case LightType_PointLight:
@ -177,7 +276,7 @@ LevelMetaData LevelParser::ParseHeader(std::string filename)
default: default:
//Undefined LightType. //Undefined LightType.
break; break;
} }*/
} }
default: default:

View File

@ -23,7 +23,7 @@ namespace GameLogic
LevelMetaData ParseHeader(std::string filename); LevelMetaData ParseHeader(std::string filename);
private: private:
FormatVersion formatVersion; LevelLoaderInternal::FormatVersion formatVersion;
}; };
} }

View File

@ -23,6 +23,21 @@ namespace GameLogic
ObjectType_Unknown = -1 ObjectType_Unknown = -1
}; };
enum ObjectSpecialType
{
ObjectSpecialType_World, //Always the main celestial body
ObjectSpecialType_Building,
ObjectSpecialType_Damaging,
ObjectSpecialType_Explosive,
ObjectSpecialType_JumpPad,
ObjectSpecialType_BoostPad,
ObjectSpecialType_Portal,
ObjectSpecialType_SpawnPoint,
ObjectSpecialType_Count,
ObjectSpecialType_Unknown = -1
};
enum UsePhysics enum UsePhysics
{ {
UsePhysics_UseFullPhysics, UsePhysics_UseFullPhysics,
@ -34,11 +49,22 @@ namespace GameLogic
UsePhysics_Unknown = -1 UsePhysics_Unknown = -1
}; };
enum CollisionGeometryType
{
CollisionGeometryType_Box,
CollisionGeometryType_Sphere,
CollisionGeometryType_Cylinder,
CollisionGeometryType_Count,
CollisionGeometryType_Unknown = -1
};
//Only supports Pointlight right now.
enum LightType enum LightType
{ {
LightType_PointLight, LightType_PointLight,
LightType_DirectionalLight, //LightType_DirectionalLight,
LightType_SpotLight, //LightType_SpotLight,
LightType_Count, LightType_Count,
LightType_Unknown = -1 LightType_Unknown = -1
@ -55,19 +81,40 @@ namespace GameLogic
GameMode_Unknown = -1 GameMode_Unknown = -1
}; };
enum WorldSize
{
WorldSize_Tiny,
WorldSize_Small,
WorldSize_Medium,
WorldSize_Big,
WorldSize_Humongous,
WorldSize_Count,
WorldSize_Unknown = -1
};
/************************************ /************************************
Structs Structs
*************************************/ *************************************/
namespace LevelLoaderInternal
{
struct FormatVersion struct FormatVersion
{ {
int formatVersionMajor; unsigned int formatVersionMajor;
int formatVersionMinor; unsigned int formatVersionMinor;
FormatVersion()
: formatVersionMajor(0), formatVersionMinor(0)
{}
FormatVersion(unsigned int major, unsigned int minor)
: formatVersionMajor(major), formatVersionMinor(minor)
{}
bool operator ==(const FormatVersion& obj) bool operator ==(const FormatVersion& obj)
{ {
return (this->formatVersionMajor != obj.formatVersionMajor && this->formatVersionMinor != obj.formatVersionMinor); return (this->formatVersionMajor == obj.formatVersionMajor && this->formatVersionMinor == obj.formatVersionMinor);
} }
bool operator !=(const FormatVersion& obj) bool operator !=(const FormatVersion& obj)
@ -75,10 +122,54 @@ namespace GameLogic
return !(*this == obj); return !(*this == obj);
} }
}; };
}
struct ObjectTypeHeader struct ObjectTypeHeader
{ {
ObjectType typeID; ObjectType typeID;
//Unless this is here the object destructor wont be called.
virtual ~ObjectTypeHeader(){}
};
namespace LevelLoaderInternal
{
const FormatVersion boundingVolumeVersion(1, 0);
struct BoundingVolumeBase
{
float position[3];
};
struct BoundingVolumeBox : public BoundingVolumeBase
{
float size[3];
float angularAxis[3];
float angle;
};
struct BoundingVolumeSphere : public BoundingVolumeBase
{
float radius;
};
struct BoundingVolumeCylinder : public BoundingVolumeBase
{
float length;
float angularAxis[3];
float angle;
float radius;
};
struct BoundingVolume
{
CollisionGeometryType geoType;
union
{
LevelLoaderInternal::BoundingVolumeBox box;
LevelLoaderInternal::BoundingVolumeSphere sphere;
LevelLoaderInternal::BoundingVolumeCylinder cylinder;
};
}; };
struct PhysicsObject struct PhysicsObject
@ -89,33 +180,62 @@ namespace GameLogic
float inertiaRotation[3]; float inertiaRotation[3];
float frictionCoeffStatic; float frictionCoeffStatic;
float frictionCoeffDynamic; float frictionCoeffDynamic;
float restitutionCoeff;
BoundingVolume boundingVolume;
}; };
}
struct LevelMetaData : ObjectTypeHeader struct LevelMetaData : public ObjectTypeHeader
{ {
std::string levelName; std::string levelName;
int levelVersion; unsigned int levelVersion;
std::string levelDescription; std::string levelDescription;
std::string levelAuthor; std::string levelAuthor;
int maxNumberOfPlayer; unsigned int maxNumberOfPlayer;
int worldSize; WorldSize worldSize;
std::string overviewPicturePath; std::string overviewPicturePath;
std::vector<GameMode> gameModesSupported; std::vector<GameMode> gameModesSupported;
virtual ~LevelMetaData(){}
}; };
struct ObjectHeader : public ObjectTypeHeader struct ObjectHeader : public ObjectTypeHeader, public LevelLoaderInternal::PhysicsObject
{ {
//Special type id for special objects: portal, jumppad, exploding objects, etc.
ObjectSpecialType specialTypeID;
//Model, //Model,
std::string ModelFile; std::string ModelFile;
//Position //Position
float position[3]; float position[3];
//Rotation //Rotation
float rotation[3]; float rotation[3];
float angle;
//Scale //Scale
float scale[3]; float scale[3];
virtual ~ObjectHeader(){}
}; };
/************************************
Special objects
*************************************/
struct JumpPadAttributes : public ObjectHeader
{
float direction[3];
float power;
};
struct PortalAttributes : public ObjectHeader
{
float destination[3];
};
struct SpawnPointAttributes : public ObjectHeader
{
float spawnPosition[3];
};
/************************************ /************************************
Lights Lights
@ -123,12 +243,13 @@ namespace GameLogic
struct BasicLight : public ObjectTypeHeader struct BasicLight : public ObjectTypeHeader
{ {
LightType lightType; LightType lightType; //Is not used right now
float ambientColor[3]; float color[3];
float diffuseColor[3]; float position[3];
float specularColor[3]; float raduis;
float intensity;
}; };
/* We only support pointlight right now.
struct PointLight : public BasicLight struct PointLight : public BasicLight
{ {
float position[3]; float position[3];
@ -144,7 +265,7 @@ namespace GameLogic
float direction[3]; float direction[3];
float range; float range;
float attenuation[3]; float attenuation[3];
}; };*/
} }
#endif #endif

View File

@ -4,6 +4,7 @@
#include "ParseFunctions.h" #include "ParseFunctions.h"
#include "../../../Misc/Packing/Packing.h" #include "../../../Misc/Packing/Packing.h"
#include "Loader.h"
#include <string> #include <string>
using namespace Oyster::Packing; using namespace Oyster::Packing;
@ -23,12 +24,15 @@ namespace GameLogic
void ParseObject(char* buffer, ObjectHeader& header, int& size) void ParseObject(char* buffer, ObjectHeader& header, int& size)
{ {
char tempName[128]; char tempName[128];
int tempSize = 0; unsigned int tempSize = 0;
int start = 0; int start = 0;
memcpy(&header.typeID, &buffer[start], 4); memcpy(&header.typeID, &buffer[start], 4);
start += 4; start += 4;
memcpy(&header.specialTypeID, &buffer[start], 4);
start += 4;
memcpy(&tempSize, &buffer[start], 4); memcpy(&tempSize, &buffer[start], 4);
start += 4; start += 4;
@ -36,8 +40,18 @@ namespace GameLogic
header.ModelFile.assign(&tempName[0], &tempName[tempSize]); header.ModelFile.assign(&tempName[0], &tempName[tempSize]);
start += tempSize; start += tempSize;
memcpy(&header.position, &buffer[start], 36); //The reset of the object struct
start += 36; //3 float[3], 1 float
memcpy(&header.position, &buffer[start], 40);
start += 40;
//Physics struct
//2 float[3], 4 float, 1 uint
memcpy(&header.usePhysics, &buffer[start], 44);
start += 44;
//Read path for bounding volume
ParseBoundingVolume(&buffer[start], header.boundingVolume, start);
size += start; size += start;
} }
@ -45,7 +59,7 @@ namespace GameLogic
void ParseLevelMetaData(char* buffer, LevelMetaData &header, int &size) void ParseLevelMetaData(char* buffer, LevelMetaData &header, int &size)
{ {
int start = 0; int start = 0;
int tempSize; unsigned int tempSize;
char tempName[128]; char tempName[128];
memcpy(&header.typeID, &buffer[start], 4); memcpy(&header.typeID, &buffer[start], 4);
@ -102,5 +116,55 @@ namespace GameLogic
size += start; size += start;
} }
void ParseBoundingVolume(char* buffer, LevelLoaderInternal::BoundingVolume& volume, int &size)
{
int start = 0;
int tempSize = 0;
char tempName[128];
memcpy(&tempSize, &buffer[start], 4);
start += 4;
memcpy(&tempName, &buffer[start], tempSize);
string fileName;
fileName.assign(&tempName[0], &tempName[tempSize]);
start += tempSize;
//Läs in filen.
int fileLength = 0;
Loader loader;
char* buf = loader.LoadFile("E:\\Dropbox\\Programming\\Github\\Danbias\\Bin\\Content\\Worlds\\cgf\\"+ fileName, fileLength);
LevelLoaderInternal::FormatVersion version;
memcpy(&version, &buffer[0], sizeof(version));
memcpy(&volume.geoType, &buf[8], sizeof(volume.geoType));
//start += sizeof(volume.geoType);
switch(volume.geoType)
{
case CollisionGeometryType_Box:
memcpy(&volume.box, &buf[12], sizeof(volume.box));
//start += sizeof(volume.box);
break;
case CollisionGeometryType_Sphere:
memcpy(&volume.sphere, &buf[12], sizeof(volume.sphere));
//start += sizeof(volume.sphere);
break;
case CollisionGeometryType_Cylinder:
memcpy(&volume.cylinder, &buf[12], sizeof(volume.cylinder));
//start += sizeof(volume.cylinder);
break;
default:
break;
}
size += start;
}
} }
} }

View File

@ -21,6 +21,7 @@ namespace GameLogic
void ParseObject(char* buffer, void *header, int size); void ParseObject(char* buffer, void *header, int size);
void ParseObject(char* buffer, ObjectHeader& header, int& size); void ParseObject(char* buffer, ObjectHeader& header, int& size);
void ParseLevelMetaData(char* buffer, LevelMetaData &header, int &size); void ParseLevelMetaData(char* buffer, LevelMetaData &header, int &size);
void ParseBoundingVolume(char* buffer, LevelLoaderInternal::BoundingVolume& volume, int &size);
} }
} }

View File

@ -219,8 +219,9 @@ namespace DanBias
} }
void GameSession::Gameplay_PlayerShot ( Protocol_PlayerShot& p, DanBias::GameClient* c ) void GameSession::Gameplay_PlayerShot ( Protocol_PlayerShot& p, DanBias::GameClient* c )
{ {
if(p.primaryPressed) c->GetPlayer()->UseWeapon(GameLogic::WEAPON_USE_PRIMARY_PRESS);
if(p.secondaryPressed) c->GetPlayer()->UseWeapon(GameLogic::WEAPON_USE_SECONDARY_PRESS); if(p.secondaryPressed) c->GetPlayer()->UseWeapon(GameLogic::WEAPON_USE_SECONDARY_PRESS);
if(p.primaryPressed) c->GetPlayer()->UseWeapon(GameLogic::WEAPON_USE_PRIMARY_PRESS);
if(p.utilityPressed) c->GetPlayer()->UseWeapon(GameLogic::WEAPON_USE_UTILLITY_PRESS); if(p.utilityPressed) c->GetPlayer()->UseWeapon(GameLogic::WEAPON_USE_UTILLITY_PRESS);
} }
void GameSession::Gameplay_PlayerJump ( Protocol_PlayerJump& p, DanBias::GameClient* c ) void GameSession::Gameplay_PlayerJump ( Protocol_PlayerJump& p, DanBias::GameClient* c )