diff --git a/Code/Game/DanBiasGame/GameClientState/GameState.cpp b/Code/Game/DanBiasGame/GameClientState/GameState.cpp index 9f65910b..e7c2bfc0 100644 --- a/Code/Game/DanBiasGame/GameClientState/GameState.cpp +++ b/Code/Game/DanBiasGame/GameClientState/GameState.cpp @@ -87,12 +87,10 @@ bool GameState::LoadModels(std::wstring mapFile) // open file // read file // init models - - int nrOfBoxex = 5; + int nrOfBoxex = 20; int id = 100; + // add world model - - ModelInitData modelData; Oyster::Math3D::Float4x4 translate; C_Object* obj; @@ -108,7 +106,7 @@ bool GameState::LoadModels(std::wstring mapFile) /* // add box model modelData.world = Oyster::Math3D::Float4x4::identity; - modelData.modelPath = L"box.dan"; + modelData.modelPath = L"crate_colonists.dan"; for(int i =0; i< nrOfBoxex; i ++) @@ -125,7 +123,7 @@ bool GameState::LoadModels(std::wstring mapFile) // add crystal model 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.visible = true; @@ -138,10 +136,11 @@ bool GameState::LoadModels(std::wstring mapFile) // add house model modelData.world = Oyster::Math3D::Float4x4::identity; - translate = Oyster::Math3D::TranslationMatrix(Oyster::Math::Float3(50, 300, 0)); - //Oyster::Math3D::RotationMatrix_AxisZ() - modelData.world = modelData.world * translate; - modelData.visible = false; + translate = Oyster::Math3D::TranslationMatrix(Oyster::Math::Float3(-50, 290, 0)); + Oyster::Math3D::Float4x4 rot = Oyster::Math3D::RotationMatrix(Oyster::Math::Float3(0 ,Utility::Value::Radian(90.0f), 0)); + + modelData.world = modelData.world * translate * rot; + modelData.visible = true; modelData.modelPath = L"building_corporation.dan"; modelData.id = id++; // load models @@ -150,6 +149,35 @@ bool GameState::LoadModels(std::wstring mapFile) 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; } bool GameState::InitCamera(Oyster::Math::Float3 startPos) @@ -475,8 +503,8 @@ void GameState::Protocol( ObjPos* pos ) camera->setUp(up); camera->setLook(objForward); - up *= 2; - objForward *= -3; + up *= 1; + objForward *= -2; Oyster::Math::Float3 cameraPos = up + pos + objForward; camera->SetPosition(cameraPos); diff --git a/Code/Game/DanBiasGame/GameClientState/LoginState.cpp b/Code/Game/DanBiasGame/GameClientState/LoginState.cpp index 9608cd48..4a244a8b 100644 --- a/Code/Game/DanBiasGame/GameClientState/LoginState.cpp +++ b/Code/Game/DanBiasGame/GameClientState/LoginState.cpp @@ -41,7 +41,7 @@ bool LoginState::Init(Oyster::Network::NetworkClient* nwClient) bool LoginState::LoadModels(std::wstring file) { 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.Radius = 100; plight.Bright = 1; @@ -55,14 +55,22 @@ bool LoginState::LoadModels(std::wstring file) modelData.world = Oyster::Math3D::Float4x4::identity; modelData.visible = true; - modelData.modelPath = L"box_2.dan"; + modelData.modelPath = L"identityPlane.dan"; // 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]->Init(modelData); - translate = Oyster::Math3D::TranslationMatrix(Oyster::Math::Float3(-2,-2,-2)); - modelData.world = modelData.world * translate; + translate = Oyster::Math3D::TranslationMatrix(Oyster::Math::Float3(0,0,-2)); + modelData.world = translate ;//* rot; privData->object[1] = new C_DynamicObj(); privData->object[1]->Init(modelData); @@ -97,7 +105,7 @@ GameClientState::ClientState LoginState::Update(float deltaTime, InputClass* Key DanBias::GameServerAPI::ServerInitiate(desc); DanBias::GameServerAPI::ServerStart(); // my ip - nwClient->Connect(15152, "127.0.0.1"); + nwClient->Connect(15151, "127.0.0.1"); if (!nwClient->IsConnected()) { @@ -110,8 +118,7 @@ GameClientState::ClientState LoginState::Update(float deltaTime, InputClass* Key if( KeyInput->IsKeyPressed(DIK_J)) { // game ip - nwClient->Connect(15152, "127.0.0.1"); - //nwClient->Connect(15152, "193.11.187.187"); + nwClient->Connect(15151, "127.0.0.1"); if (!nwClient->IsConnected()) { @@ -128,7 +135,6 @@ bool LoginState::Render() Oyster::Graphics::API::SetView(privData->view); Oyster::Graphics::API::SetProjection( privData->proj); - Oyster::Graphics::API::NewFrame(); // render objects for (int i = 0; i < privData->modelCount; i++) diff --git a/Code/Game/GameLogic/AttatchmentMassDriver.cpp b/Code/Game/GameLogic/AttatchmentMassDriver.cpp index e0ca6c0f..59be4542 100644 --- a/Code/Game/GameLogic/AttatchmentMassDriver.cpp +++ b/Code/Game/GameLogic/AttatchmentMassDriver.cpp @@ -63,8 +63,10 @@ void AttatchmentMassDriver::Update(float dt) Oyster::Physics::ICustomBody::State state; state = heldObject->GetState(); Oyster::Math::Float3 ownerPos = owner->GetPosition(); - ownerPos.y += 2; - Oyster::Math::Float3 pos = ownerPos + owner->GetLookDir().GetNormalized()*2; + Oyster::Physics::ICustomBody::State ownerState = owner->GetRigidBody()->GetState(); + Oyster::Math::Float3 up = -ownerState.GetGravityNormal(); + up *= -0.3; + Oyster::Math::Float3 pos = ownerPos + up + (owner->GetLookDir().GetNormalized()*5); state.SetCenterPosition(pos); @@ -84,7 +86,7 @@ void AttatchmentMassDriver::ForcePush(const GameLogic::WEAPON_FIRE &usage, float if(hasObject) { 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(); state.ApplyLinearImpulse((Oyster::Math::Float3)pushForce); 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 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 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)); forcePushData args; args.pushForce = pushForce; diff --git a/Code/Game/GameLogic/Game_PlayerData.cpp b/Code/Game/GameLogic/Game_PlayerData.cpp index 5667ab15..61c36dd1 100644 --- a/Code/Game/GameLogic/Game_PlayerData.cpp +++ b/Code/Game/GameLogic/Game_PlayerData.cpp @@ -7,14 +7,13 @@ Game::PlayerData::PlayerData() { //set some stats that are appropriate to a player 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.restitutionCoeff = 0.5f; - sbDesc.frictionCoeff_Static = 0.4f; - sbDesc.frictionCoeff_Dynamic = 0.3f; - sbDesc.rotation = Oyster::Math::Float3(0.0f, Oyster::Math::pi, 0.0f); + sbDesc.size = Oyster::Math::Float3(0.5f,2,1); + sbDesc.mass = 70; + sbDesc.restitutionCoeff = 0.5; + sbDesc.frictionCoeff_Static = 0.4; + sbDesc.frictionCoeff_Dynamic = 0.3; + sbDesc.rotation = Oyster::Math::Float3(0, Oyster::Math::pi, 0); //create rigid body Oyster::Physics::ICustomBody *rigidBody = Oyster::Physics::API::Instance().CreateRigidBody(sbDesc).Release(); @@ -22,6 +21,11 @@ Game::PlayerData::PlayerData() //create player with this rigid body this->player = new Player(rigidBody,Player::PlayerCollisionBefore, Player::PlayerCollision, OBJECT_TYPE::OBJECT_TYPE_PLAYER); 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) { diff --git a/Code/Game/GameLogic/Level.cpp b/Code/Game/GameLogic/Level.cpp index 6a964840..c3903cfc 100644 --- a/Code/Game/GameLogic/Level.cpp +++ b/Code/Game/GameLogic/Level.cpp @@ -87,9 +87,10 @@ void Level::InitiateLevel(float radius) ICustomBody* rigidBody_TestBox; int nrOfBoxex = 5; + int offset = 0; 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->SetSubscription(Level::PhysicsOnMoveLevel); @@ -98,6 +99,36 @@ void Level::InitiateLevel(float radius) this->dynamicObjects.Push(box); 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 API::SimpleBodyDescription sbDesc_Crystal; @@ -116,22 +147,23 @@ void Level::InitiateLevel(float radius) // add 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.rotation = Oyster::Math::Float3(0 ,Utility::Value::Radian(90.0f), 0); 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(); rigidBody_House->SetSubscription(Level::PhysicsOnMoveLevel); - StaticObject* house = new StaticObject(rigidBody_House,Object::DefaultCollisionBefore, Object::DefaultCollisionAfter, OBJECT_TYPE::OBJECT_TYPE_GENERIC); - house->objectID = idCount++; - this->staticObjects.Push(house); + this->staticObjects.Push(new StaticObject(rigidBody_House,Object::DefaultCollisionBefore, Object::DefaultCollisionAfter, OBJECT_TYPE::OBJECT_TYPE_GENERIC)); rigidBody_House->SetCustomTag(this->staticObjects[0]); -*/ + rigidBody_House->GetState(state); + Oyster::Math::Float4x4 world = state.GetOrientation(); -// add gravitation + + // add gravitation API::Gravity gravityWell; gravityWell.gravityType = API::Gravity::GravityType_Well; gravityWell.well.mass = 1e17f; diff --git a/Code/Game/GameLogic/LevelLoader/LevelLoader.cpp b/Code/Game/GameLogic/LevelLoader/LevelLoader.cpp index 5bb916ab..55a39725 100644 --- a/Code/Game/GameLogic/LevelLoader/LevelLoader.cpp +++ b/Code/Game/GameLogic/LevelLoader/LevelLoader.cpp @@ -4,17 +4,20 @@ #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() diff --git a/Code/Game/GameLogic/LevelLoader/LevelParser.cpp b/Code/Game/GameLogic/LevelLoader/LevelParser.cpp index 088c3916..33567cc9 100644 --- a/Code/Game/GameLogic/LevelLoader/LevelParser.cpp +++ b/Code/Game/GameLogic/LevelLoader/LevelParser.cpp @@ -1,3 +1,7 @@ +///////////////////////////////////// +// Created by Pontus Fransson 2013 // +///////////////////////////////////// + #include "LevelParser.h" #include "Loader.h" @@ -9,7 +13,7 @@ using namespace Utility::DynamicMemory; LevelParser::LevelParser() { - formatVersion.formatVersionMajor = 1; + formatVersion.formatVersionMajor = 2; formatVersion.formatVersionMinor = 0; } @@ -29,35 +33,100 @@ std::vector> LevelParser::Parse(std::string filen char* buffer = (char*)loader.LoadFile(filename.c_str(), bufferSize); //Read format version - FormatVersion levelFormatVersion; + LevelLoaderInternal::FormatVersion levelFormatVersion; ParseObject(&buffer[counter], &levelFormatVersion, sizeof(levelFormatVersion)); counter += sizeof(levelFormatVersion); if(this->formatVersion != levelFormatVersion) { //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) { //Get typeID - ObjectTypeHeader typeID; + ObjectType typeID; ParseObject(&buffer[counter], &typeID, sizeof(typeID)); - switch((int)typeID.typeID) + switch((int)typeID) { case ObjectType_LevelMetaData: { - LevelMetaData* header = new LevelMetaData; - ParseLevelMetaData(&buffer[counter], *header, counter); + SmartPointer header = new LevelMetaData; + ParseLevelMetaData(&buffer[counter], *(LevelMetaData*)header.Get(), counter); objects.push_back(header); 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: { - ObjectHeader* header = new ObjectHeader; - ParseObject(&buffer[counter], *header, counter); - objects.push_back(header); + //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; + ParseObject(&buffer[counter], *header, counter); + 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; } @@ -68,7 +137,12 @@ std::vector> LevelParser::Parse(std::string filen //Get Light type 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: { @@ -98,7 +172,7 @@ std::vector> LevelParser::Parse(std::string filen //Undefined LightType. break; } - break; + break;*/ } default: //Couldn't find typeID. FAIL!!!!!! @@ -123,21 +197,25 @@ LevelMetaData LevelParser::ParseHeader(std::string filename) char* buffer = (char*)loader.LoadFile(filename.c_str(), bufferSize); //Read format version - FormatVersion levelFormatVersion; + LevelLoaderInternal::FormatVersion levelFormatVersion; ParseObject(&buffer[counter], &levelFormatVersion, sizeof(formatVersion)); counter += sizeof(levelFormatVersion); if(this->formatVersion != levelFormatVersion) { //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. while(counter < bufferSize) { - ObjectTypeHeader typeID; + ObjectType typeID; ParseObject(&buffer[counter], &typeID, sizeof(typeID)); - switch(typeID.typeID) + switch(typeID) { case ObjectType_LevelMetaData: ParseLevelMetaData(&buffer[counter], levelHeader, counter); @@ -149,6 +227,24 @@ LevelMetaData LevelParser::ParseHeader(std::string filename) { ObjectHeader header; 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; } @@ -157,6 +253,9 @@ LevelMetaData LevelParser::ParseHeader(std::string filename) LightType lightType; ParseObject(&buffer[counter+4], &lightType, sizeof(lightType)); + //We only support pointlight for now. + counter += sizeof(BasicLight); + /* switch(lightType) { case LightType_PointLight: @@ -177,7 +276,7 @@ LevelMetaData LevelParser::ParseHeader(std::string filename) default: //Undefined LightType. break; - } + }*/ } default: diff --git a/Code/Game/GameLogic/LevelLoader/LevelParser.h b/Code/Game/GameLogic/LevelLoader/LevelParser.h index 9ad30642..346b75b5 100644 --- a/Code/Game/GameLogic/LevelLoader/LevelParser.h +++ b/Code/Game/GameLogic/LevelLoader/LevelParser.h @@ -23,7 +23,7 @@ namespace GameLogic LevelMetaData ParseHeader(std::string filename); private: - FormatVersion formatVersion; + LevelLoaderInternal::FormatVersion formatVersion; }; } diff --git a/Code/Game/GameLogic/LevelLoader/ObjectDefines.h b/Code/Game/GameLogic/LevelLoader/ObjectDefines.h index 7c924976..d87e42b2 100644 --- a/Code/Game/GameLogic/LevelLoader/ObjectDefines.h +++ b/Code/Game/GameLogic/LevelLoader/ObjectDefines.h @@ -9,7 +9,7 @@ namespace GameLogic /************************************ Enums *************************************/ - + enum ObjectType { ObjectType_LevelMetaData, @@ -23,6 +23,21 @@ namespace GameLogic 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 { UsePhysics_UseFullPhysics, @@ -34,11 +49,22 @@ namespace GameLogic UsePhysics_Unknown = -1 }; + enum CollisionGeometryType + { + CollisionGeometryType_Box, + CollisionGeometryType_Sphere, + CollisionGeometryType_Cylinder, + + CollisionGeometryType_Count, + CollisionGeometryType_Unknown = -1 + }; + + //Only supports Pointlight right now. enum LightType { LightType_PointLight, - LightType_DirectionalLight, - LightType_SpotLight, + //LightType_DirectionalLight, + //LightType_SpotLight, LightType_Count, LightType_Unknown = -1 @@ -55,67 +81,161 @@ namespace GameLogic GameMode_Unknown = -1 }; + enum WorldSize + { + WorldSize_Tiny, + WorldSize_Small, + WorldSize_Medium, + WorldSize_Big, + WorldSize_Humongous, + + WorldSize_Count, + WorldSize_Unknown = -1 + }; + /************************************ Structs *************************************/ - - struct FormatVersion + namespace LevelLoaderInternal { - int formatVersionMajor; - int formatVersionMinor; - - bool operator ==(const FormatVersion& obj) + struct FormatVersion { - return (this->formatVersionMajor != obj.formatVersionMajor && this->formatVersionMinor != obj.formatVersionMinor); - } + unsigned int formatVersionMajor; + unsigned int formatVersionMinor; + + FormatVersion() + : formatVersionMajor(0), formatVersionMinor(0) + {} - bool operator !=(const FormatVersion& obj) - { - return !(*this == obj); - } - }; + FormatVersion(unsigned int major, unsigned int minor) + : formatVersionMajor(major), formatVersionMinor(minor) + {} + + 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; + + //Unless this is here the object destructor wont be called. + virtual ~ObjectTypeHeader(){} }; - struct PhysicsObject + namespace LevelLoaderInternal { - UsePhysics usePhysics; - float mass; - float inertiaMagnitude[3]; - float inertiaRotation[3]; - float frictionCoeffStatic; - float frictionCoeffDynamic; - - }; + const FormatVersion boundingVolumeVersion(1, 0); - struct LevelMetaData : ObjectTypeHeader + 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 + { + UsePhysics usePhysics; + float mass; + float inertiaMagnitude[3]; + float inertiaRotation[3]; + float frictionCoeffStatic; + float frictionCoeffDynamic; + float restitutionCoeff; + BoundingVolume boundingVolume; + }; + } + + struct LevelMetaData : public ObjectTypeHeader { std::string levelName; - int levelVersion; + unsigned int levelVersion; std::string levelDescription; std::string levelAuthor; - int maxNumberOfPlayer; - int worldSize; + unsigned int maxNumberOfPlayer; + WorldSize worldSize; std::string overviewPicturePath; std::vector 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, std::string ModelFile; //Position float position[3]; //Rotation float rotation[3]; + float angle; //Scale 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 @@ -123,12 +243,13 @@ namespace GameLogic struct BasicLight : public ObjectTypeHeader { - LightType lightType; - float ambientColor[3]; - float diffuseColor[3]; - float specularColor[3]; + LightType lightType; //Is not used right now + float color[3]; + float position[3]; + float raduis; + float intensity; }; - + /* We only support pointlight right now. struct PointLight : public BasicLight { float position[3]; @@ -144,7 +265,7 @@ namespace GameLogic float direction[3]; float range; float attenuation[3]; - }; + };*/ } #endif \ No newline at end of file diff --git a/Code/Game/GameLogic/LevelLoader/ParseFunctions.cpp b/Code/Game/GameLogic/LevelLoader/ParseFunctions.cpp index 68631bf0..e8c055b3 100644 --- a/Code/Game/GameLogic/LevelLoader/ParseFunctions.cpp +++ b/Code/Game/GameLogic/LevelLoader/ParseFunctions.cpp @@ -4,6 +4,7 @@ #include "ParseFunctions.h" #include "../../../Misc/Packing/Packing.h" +#include "Loader.h" #include using namespace Oyster::Packing; @@ -23,12 +24,15 @@ namespace GameLogic void ParseObject(char* buffer, ObjectHeader& header, int& size) { char tempName[128]; - int tempSize = 0; + unsigned int tempSize = 0; int start = 0; memcpy(&header.typeID, &buffer[start], 4); start += 4; + memcpy(&header.specialTypeID, &buffer[start], 4); + start += 4; + memcpy(&tempSize, &buffer[start], 4); start += 4; @@ -36,8 +40,18 @@ namespace GameLogic header.ModelFile.assign(&tempName[0], &tempName[tempSize]); start += tempSize; - memcpy(&header.position, &buffer[start], 36); - start += 36; + //The reset of the object struct + //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; } @@ -45,7 +59,7 @@ namespace GameLogic void ParseLevelMetaData(char* buffer, LevelMetaData &header, int &size) { int start = 0; - int tempSize; + unsigned int tempSize; char tempName[128]; memcpy(&header.typeID, &buffer[start], 4); @@ -102,5 +116,55 @@ namespace GameLogic 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; + } } } \ No newline at end of file diff --git a/Code/Game/GameLogic/LevelLoader/ParseFunctions.h b/Code/Game/GameLogic/LevelLoader/ParseFunctions.h index f68a9289..f66351b4 100644 --- a/Code/Game/GameLogic/LevelLoader/ParseFunctions.h +++ b/Code/Game/GameLogic/LevelLoader/ParseFunctions.h @@ -21,6 +21,7 @@ namespace GameLogic void ParseObject(char* buffer, void *header, int size); void ParseObject(char* buffer, ObjectHeader& header, int& size); void ParseLevelMetaData(char* buffer, LevelMetaData &header, int &size); + void ParseBoundingVolume(char* buffer, LevelLoaderInternal::BoundingVolume& volume, int &size); } } diff --git a/Code/Game/GameServer/Implementation/GameSession_Gameplay.cpp b/Code/Game/GameServer/Implementation/GameSession_Gameplay.cpp index 2af45391..b7d11e42 100644 --- a/Code/Game/GameServer/Implementation/GameSession_Gameplay.cpp +++ b/Code/Game/GameServer/Implementation/GameSession_Gameplay.cpp @@ -218,10 +218,11 @@ namespace DanBias } 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.utilityPressed) c->GetPlayer()->UseWeapon(GameLogic::WEAPON_USE_UTILLITY_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); } void GameSession::Gameplay_PlayerJump ( Protocol_PlayerJump& p, DanBias::GameClient* c ) {