From 5e1bc2264ca415052ad0a93fd2f7fe40afd1238c Mon Sep 17 00:00:00 2001 From: Robin Engman Date: Wed, 12 Feb 2014 14:10:17 +0100 Subject: [PATCH 1/5] Fixed set position --- Code/GamePhysics/Implementation/PhysicsAPI_Impl.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Code/GamePhysics/Implementation/PhysicsAPI_Impl.cpp b/Code/GamePhysics/Implementation/PhysicsAPI_Impl.cpp index 3b4fc74d..26da0998 100644 --- a/Code/GamePhysics/Implementation/PhysicsAPI_Impl.cpp +++ b/Code/GamePhysics/Implementation/PhysicsAPI_Impl.cpp @@ -201,7 +201,7 @@ void API_Impl::UpdateWorld() { SimpleRigidBody* simpleBody = dynamic_cast(this->customBodies[i]); btTransform trans; - simpleBody->GetMotionState()->getWorldTransform(trans); + trans = simpleBody->GetRigidBody()->getWorldTransform(); this->customBodies[i]->SetPosition(Float3(trans.getOrigin().x(), trans.getOrigin().y(), trans.getOrigin().z())); this->customBodies[i]->SetRotation(Quaternion(Float3(trans.getRotation().x(), trans.getRotation().y(), trans.getRotation().z()), trans.getRotation().w())); From 7c44e8ba17cf0a9ff7c5e64240b34d803dbeac22 Mon Sep 17 00:00:00 2001 From: lindaandersson Date: Wed, 12 Feb 2014 13:37:21 +0100 Subject: [PATCH 2/5] GL - added jumppad model and rigidbody --- Code/Game/GameLogic/CollisionManager.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Code/Game/GameLogic/CollisionManager.cpp b/Code/Game/GameLogic/CollisionManager.cpp index e39de067..afa1a09e 100644 --- a/Code/Game/GameLogic/CollisionManager.cpp +++ b/Code/Game/GameLogic/CollisionManager.cpp @@ -40,6 +40,10 @@ using namespace GameLogic; PlayerVObject(*player,*realObj, kineticEnergyLoss); //player->playerState = PLAYER_STATE::PLAYER_STATE_WALKING; break; + case OBJECT_TYPE::OBJECT_TYPE_JUMPPAD: + int i = 0; + // JUMP + break; } //return Physics::ICustomBody::SubscriptMessage_none; From 14d492f22ea238b47cb9507a83587d259bfe5f2f Mon Sep 17 00:00:00 2001 From: Erik Persson Date: Wed, 12 Feb 2014 14:00:53 +0100 Subject: [PATCH 3/5] changes in massdriver --- Code/Game/GameLogic/CollisionManager.cpp | 4 ---- 1 file changed, 4 deletions(-) diff --git a/Code/Game/GameLogic/CollisionManager.cpp b/Code/Game/GameLogic/CollisionManager.cpp index afa1a09e..e39de067 100644 --- a/Code/Game/GameLogic/CollisionManager.cpp +++ b/Code/Game/GameLogic/CollisionManager.cpp @@ -40,10 +40,6 @@ using namespace GameLogic; PlayerVObject(*player,*realObj, kineticEnergyLoss); //player->playerState = PLAYER_STATE::PLAYER_STATE_WALKING; break; - case OBJECT_TYPE::OBJECT_TYPE_JUMPPAD: - int i = 0; - // JUMP - break; } //return Physics::ICustomBody::SubscriptMessage_none; From 6cbec3e2ac144cc3ab69806784f3b0e8b095ac75 Mon Sep 17 00:00:00 2001 From: Erik Persson Date: Wed, 12 Feb 2014 14:45:10 +0100 Subject: [PATCH 4/5] GL - jumppad testing --- Code/Game/GameLogic/AttatchmentMassDriver.cpp | 4 ++-- Code/Game/GameLogic/CollisionManager.cpp | 6 +----- Code/Game/GameLogic/JumpPad.cpp | 4 ++-- Code/Game/GameLogic/JumpPad.h | 2 +- Code/Game/GameLogic/Level.cpp | 4 ++-- 5 files changed, 8 insertions(+), 12 deletions(-) diff --git a/Code/Game/GameLogic/AttatchmentMassDriver.cpp b/Code/Game/GameLogic/AttatchmentMassDriver.cpp index 3f74bc1b..1e5d0640 100644 --- a/Code/Game/GameLogic/AttatchmentMassDriver.cpp +++ b/Code/Game/GameLogic/AttatchmentMassDriver.cpp @@ -87,7 +87,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()) * (100); + pushForce = Oyster::Math::Float4(this->owner->GetLookDir()) * (400); heldObject->ApplyImpulse((Oyster::Math::Float3)pushForce); hasObject = false; @@ -100,7 +100,7 @@ void AttatchmentMassDriver::ForcePush(const GameLogic::WEAPON_FIRE &usage, float Oyster::Math::Float lenght = 10; Oyster::Math::Float3 pos = owner->GetRigidBody()->GetState().centerPos; - pushForce = Oyster::Math::Float4(this->owner->GetLookDir()) * (100); + pushForce = Oyster::Math::Float4(this->owner->GetLookDir()) * (400); Oyster::Collision3D::Cone *hitCone = new Oyster::Collision3D::Cone(lenght,pos,(Oyster::Math::Float4)owner->GetRigidBody()->GetState().quaternion,radius); diff --git a/Code/Game/GameLogic/CollisionManager.cpp b/Code/Game/GameLogic/CollisionManager.cpp index e39de067..80513fd5 100644 --- a/Code/Game/GameLogic/CollisionManager.cpp +++ b/Code/Game/GameLogic/CollisionManager.cpp @@ -66,11 +66,7 @@ using namespace GameLogic; void SendObjectFlying(Oyster::Physics::ICustomBody &obj, Oyster::Math::Float3 force) { - Oyster::Physics::ICustomBody::State state; - - state = obj.GetState(); - //state.ApplyLinearImpulse(force); - obj.SetState(state); + obj.ApplyImpulse(force); } diff --git a/Code/Game/GameLogic/JumpPad.cpp b/Code/Game/GameLogic/JumpPad.cpp index 15b80dc8..b716c710 100644 --- a/Code/Game/GameLogic/JumpPad.cpp +++ b/Code/Game/GameLogic/JumpPad.cpp @@ -8,10 +8,10 @@ JumpPad::JumpPad(void) { } -JumpPad::JumpPad(Oyster::Physics::ICustomBody *rigidBody, Oyster::Physics::ICustomBody::SubscriptMessage (*collisionFuncAfter)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), OBJECT_TYPE type, Oyster::Math::Float3 pushForce) +JumpPad::JumpPad(Oyster::Physics::ICustomBody *rigidBody, void (*collisionFuncAfter)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), OBJECT_TYPE type, Oyster::Math::Float3 pushForce) :StaticObject(rigidBody, collisionFuncAfter, type) { - + this->pushForce = pushForce; } diff --git a/Code/Game/GameLogic/JumpPad.h b/Code/Game/GameLogic/JumpPad.h index 8d645a00..918ea0c1 100644 --- a/Code/Game/GameLogic/JumpPad.h +++ b/Code/Game/GameLogic/JumpPad.h @@ -9,7 +9,7 @@ namespace GameLogic JumpPad(void); JumpPad(Oyster::Physics::ICustomBody *rigidBody - ,Oyster::Physics::ICustomBody::SubscriptMessage (*collisionFuncAfter)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss) + ,void (*collisionFuncAfter)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss) ,OBJECT_TYPE type, Oyster::Math::Float3 pushForce); ~JumpPad(void); diff --git a/Code/Game/GameLogic/Level.cpp b/Code/Game/GameLogic/Level.cpp index 57b39c92..15d855c3 100644 --- a/Code/Game/GameLogic/Level.cpp +++ b/Code/Game/GameLogic/Level.cpp @@ -181,9 +181,9 @@ void Level::InitiateLevel(float radius) this->staticObjects[0]->objectID = idCount++; // add jumppad - ICustomBody* rigidBody_Jumppad = API::Instance().AddCollisionBox(Oyster::Math::Float3(0.5f, 0.5f, 0.5f), Oyster::Math::Float4(0, 0, 0, 1), Oyster::Math::Float3(4, 600.3, 0), 5, 0.5f, 0.8f, 0.6f); + ICustomBody* rigidBody_Jumppad = API::Instance().AddCollisionBox(Oyster::Math::Float3(1, 1, 1), Oyster::Math::Float4(0, 0, 0, 1), Oyster::Math::Float3(4, 600.3, 0), 5, 0.5f, 0.8f, 0.6f); - this->staticObjects.Push(new JumpPad(rigidBody_Jumppad, Object::DefaultCollisionAfter, OBJECT_TYPE::OBJECT_TYPE_JUMPPAD, Oyster::Math::Float3(0,1,0))); + this->staticObjects.Push(new JumpPad(rigidBody_Jumppad, JumpPad::JumpPadActivated, OBJECT_TYPE::OBJECT_TYPE_JUMPPAD, Oyster::Math::Float3(0,2000,0))); rigidBody_Jumppad->SetCustomTag(this->staticObjects[1]); this->staticObjects[1]->objectID = idCount++; } From 64b2d688bd41fe5be16ba1e7863fe0c2cf9c9282 Mon Sep 17 00:00:00 2001 From: Sam Mario Svensson Date: Wed, 12 Feb 2014 14:48:58 +0100 Subject: [PATCH 5/5] =?UTF-8?q?F=C3=B6rs=C3=B6k=20till=20merge=20men=20det?= =?UTF-8?q?=20=C3=A4r=20cp?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DanBiasGame/GameClientState/GameState.cpp | 21 +- .../LevelLoader/LevelLoader.cpp | 23 ++- .../GameClientState/LevelLoader/LevelLoader.h | 18 +- .../LevelLoader/LevelParser.cpp | 147 ++++++++++++-- .../GameClientState/LevelLoader/LevelParser.h | 2 +- .../LevelLoader/ObjectDefines.h | 180 ++++++++++++++---- .../LevelLoader/ParseFunctions.cpp | 83 +++++++- .../LevelLoader/ParseFunctions.h | 4 +- Code/Game/GameLogic/CollisionManager.cpp | 23 +-- Code/Game/GameLogic/DynamicObject.cpp | 10 +- Code/Game/GameLogic/DynamicObject.h | 12 +- Code/Game/GameLogic/Game.cpp | 4 +- Code/Game/GameLogic/Game.h | 6 +- Code/Game/GameLogic/GameAPI.h | 3 +- Code/Game/GameLogic/GameLogicStates.h | 9 - Code/Game/GameLogic/Game_LevelData.cpp | 2 +- Code/Game/GameLogic/Game_PlayerData.cpp | 9 +- Code/Game/GameLogic/JumpPad.cpp | 3 +- Code/Game/GameLogic/JumpPad.h | 2 +- Code/Game/GameLogic/Level.cpp | 146 ++++++++++++-- .../GameLogic/LevelLoader/LevelParser.cpp | 56 +++--- .../GameLogic/LevelLoader/ObjectDefines.h | 28 ++- .../GameLogic/LevelLoader/ParseFunctions.cpp | 29 ++- .../GameLogic/LevelLoader/ParseFunctions.h | 3 +- Code/Game/GameLogic/Object.cpp | 16 +- Code/Game/GameLogic/Object.h | 24 ++- Code/Game/GameLogic/Player.cpp | 11 +- Code/Game/GameLogic/Player.h | 11 +- Code/Game/GameLogic/StaticObject.cpp | 10 +- Code/Game/GameLogic/StaticObject.h | 12 +- 30 files changed, 676 insertions(+), 231 deletions(-) diff --git a/Code/Game/DanBiasGame/GameClientState/GameState.cpp b/Code/Game/DanBiasGame/GameClientState/GameState.cpp index 4c2899e1..556ee28d 100644 --- a/Code/Game/DanBiasGame/GameClientState/GameState.cpp +++ b/Code/Game/DanBiasGame/GameClientState/GameState.cpp @@ -4,7 +4,9 @@ #include "NetworkClient.h" #include "Camera.h" #include +#include "LevelLoader\ObjectDefines.h" +using namespace GameLogic; using namespace DanBias::Client; using namespace Oyster::Math; struct GameState::myData @@ -78,7 +80,7 @@ GameState::gameStateState GameState::LoadGame() //LoadModels("3bana.bias"); // hardcoded objects - LoadModels(); + LoadModels("C:/Users/Sam/Documents/GitHub/Danbias/Bin/Content/worlds/ccc.bias"); Float3 startPos = Float3(0,0,20.0f); InitCamera(startPos); return gameStateState_playing; @@ -199,9 +201,9 @@ bool GameState::LoadModels(std::string mapFile) 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.position = staticObjData->position; + modelData.rotation = Oyster::Math::Quaternion(Oyster::Math::Float3(staticObjData->rotation), staticObjData->rotation[3]); + modelData.scale = staticObjData->scale; modelData.id = modelId++; this->staticObjects.Push(new C_StaticObj()); @@ -211,11 +213,11 @@ bool GameState::LoadModels(std::string mapFile) 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.position = dynamicObjData->position; + modelData.rotation = Oyster::Math::Quaternion(Oyster::Math::Float3(dynamicObjData->rotation), dynamicObjData->rotation[3]); + modelData.scale = dynamicObjData->scale; modelData.id = modelId++; this->dynamicObjects.Push(new C_DynamicObj()); @@ -229,8 +231,8 @@ bool GameState::LoadModels(std::string mapFile) if(lightData->lightType == GameLogic::LightType_PointLight) { Oyster::Graphics::Definitions::Pointlight plight; - plight.Pos = ((GameLogic::PointLight*)lightData)->position; - plight.Color = lightData->diffuseColor; + plight.Pos = ((GameLogic::BasicLight*)lightData)->position; + plight.Color = lightData->color; plight.Radius = 100; plight.Bright = 0.9f; Oyster::Graphics::API::AddLight(plight); @@ -560,6 +562,7 @@ void GameState::Protocol( ObjPos* pos ) if(dynamicObjects[i]->GetId() == myId) // playerobj { + Float3 pos = dynamicObjects[i]->getPos(); Float3 up = dynamicObjects[i]->getWorld().v[1]; Float3 objForward = dynamicObjects[i]->getWorld().v[2]; diff --git a/Code/Game/DanBiasGame/GameClientState/LevelLoader/LevelLoader.cpp b/Code/Game/DanBiasGame/GameClientState/LevelLoader/LevelLoader.cpp index 55a39725..8fe880f3 100644 --- a/Code/Game/DanBiasGame/GameClientState/LevelLoader/LevelLoader.cpp +++ b/Code/Game/DanBiasGame/GameClientState/LevelLoader/LevelLoader.cpp @@ -17,7 +17,14 @@ struct LevelLoader::PrivData LevelLoader::LevelLoader() : pData(new PrivData) { - pData->folderPath = "Standard path"; + //standard path + pData->folderPath = ""; +} + +LevelLoader::LevelLoader(std::string folderPath) + : pData(new PrivData) +{ + pData->folderPath = folderPath; } LevelLoader::~LevelLoader() @@ -26,10 +33,20 @@ LevelLoader::~LevelLoader() std::vector> LevelLoader::LoadLevel(std::string fileName) { - return pData->parser.Parse(fileName); + return pData->parser.Parse(pData->folderPath + fileName); } LevelMetaData LevelLoader::LoadLevelHeader(std::string fileName) { - return pData->parser.ParseHeader(fileName); + return pData->parser.ParseHeader(pData->folderPath + fileName); +} + +std::string LevelLoader::GetFolderPath() +{ + return this->pData->folderPath; +} + +void LevelLoader::SetFolderPath(std::string folderPath) +{ + } \ No newline at end of file diff --git a/Code/Game/DanBiasGame/GameClientState/LevelLoader/LevelLoader.h b/Code/Game/DanBiasGame/GameClientState/LevelLoader/LevelLoader.h index bcd6e587..184a7005 100644 --- a/Code/Game/DanBiasGame/GameClientState/LevelLoader/LevelLoader.h +++ b/Code/Game/DanBiasGame/GameClientState/LevelLoader/LevelLoader.h @@ -17,11 +17,15 @@ namespace GameLogic public: LevelLoader(); + /*********************************************************** + * Lets you set the standard folderpath for the levels + ********************************************************/ + LevelLoader(std::string folderPath); ~LevelLoader(); /******************************************************** * Loads the level and objects from file. - * @param fileName: Path to the level-file that you want to load. + * @param fileName: Path/name to the level-file that you want to load. * @return: Returns all structs with objects and information about the level. ********************************************************/ std::vector> LoadLevel(std::string fileName); @@ -33,10 +37,20 @@ namespace GameLogic ********************************************************/ LevelMetaData LoadLevelHeader(std::string fileName); //. + /*********************************************************** + * @return: Returns the current standard folder path + ********************************************************/ + std::string GetFolderPath(); + + /*********************************************************** + * Sets the standard folder path + ********************************************************/ + void SetFolderPath(std::string folderPath); + private: struct PrivData; Utility::DynamicMemory::SmartPointer pData; - }; + }; } #endif \ No newline at end of file diff --git a/Code/Game/DanBiasGame/GameClientState/LevelLoader/LevelParser.cpp b/Code/Game/DanBiasGame/GameClientState/LevelLoader/LevelParser.cpp index 088c3916..c5dfa8cc 100644 --- a/Code/Game/DanBiasGame/GameClientState/LevelLoader/LevelParser.cpp +++ b/Code/Game/DanBiasGame/GameClientState/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 = 3; formatVersion.formatVersionMinor = 0; } @@ -21,6 +25,7 @@ std::vector> LevelParser::Parse(std::string filen { int bufferSize = 0; int counter = 0; + bool loadCgf; std::vector> objects; @@ -29,35 +34,117 @@ 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) { + loadCgf = true; //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) + { + //there is no difference when parsing these specialTypes. + case ObjectSpecialType_CrystalShard: + case ObjectSpecialType_CrystalFormation: + case ObjectSpecialType_Spike: + case ObjectSpecialType_SpikeBox: + case ObjectSpecialType_RedExplosiveBox: + case ObjectSpecialType_StandarsBox: + case ObjectSpecialType_Stone: + case ObjectSpecialType_Building: + { + ObjectHeader* header = new ObjectHeader; + ParseObject(&buffer[counter], *header, counter, loadCgf); + objects.push_back(header); + + break; + } + + case ObjectSpecialType_JumpPad: + { + JumpPadAttributes* header = new JumpPadAttributes; + ParseObject(&buffer[counter], *header, counter, loadCgf); + + //Read the spec + ParseObject(&buffer[counter], header->direction, 16); + counter += 16; + objects.push_back(header); + + break; + } + + case ObjectSpecialType_Portal: + { + PortalAttributes* header = new PortalAttributes; + ParseObject(&buffer[counter], *header, counter, loadCgf); + + ParseObject(&buffer[counter], header->destination, 12); + counter += 12; + objects.push_back(header); + + break; + } + + case ObjectSpecialType_World: + { + WorldAttributes* header = new WorldAttributes; + ParseObject(&buffer[counter], *header, counter, loadCgf); + + ParseObject(&buffer[counter], &header->worldSize, 8); + counter += 8; + objects.push_back(header); + break; + } + + case ObjectSpecialType_Sky: + { + loadCgf = false; + SkyAttributes* header = new SkyAttributes; + ParseObject(&buffer[counter], *header, counter, loadCgf); + + ParseObject(&buffer[counter], &header->skySize, 4); + counter += 4; + objects.push_back(header); + break; + } + + case ObjectSpecialType_SpawnPoint: + { + loadCgf = false; + ObjectHeader* header = new ObjectHeader; + ParseObject(&buffer[counter], *header, counter, loadCgf); + } + + default: + //Couldn't find specialType + break; + } break; } @@ -68,7 +155,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 +190,7 @@ std::vector> LevelParser::Parse(std::string filen //Undefined LightType. break; } - break; + break;*/ } default: //Couldn't find typeID. FAIL!!!!!! @@ -123,21 +215,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); @@ -148,7 +244,19 @@ LevelMetaData LevelParser::ParseHeader(std::string filename) case ObjectType_Static: case ObjectType_Dynamic: { ObjectHeader header; - ParseObject(&buffer[counter], header, counter); + ParseObject(&buffer[counter], &header, counter); + + switch(header.specialTypeID) + { + case ObjectSpecialType_JumpPad: + counter += sizeof(16); + break; + case ObjectSpecialType_Portal: + counter += sizeof(12); + break; + default: + break; + } break; } @@ -157,6 +265,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 +288,7 @@ LevelMetaData LevelParser::ParseHeader(std::string filename) default: //Undefined LightType. break; - } + }*/ } default: diff --git a/Code/Game/DanBiasGame/GameClientState/LevelLoader/LevelParser.h b/Code/Game/DanBiasGame/GameClientState/LevelLoader/LevelParser.h index 9ad30642..346b75b5 100644 --- a/Code/Game/DanBiasGame/GameClientState/LevelLoader/LevelParser.h +++ b/Code/Game/DanBiasGame/GameClientState/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/DanBiasGame/GameClientState/LevelLoader/ObjectDefines.h b/Code/Game/DanBiasGame/GameClientState/LevelLoader/ObjectDefines.h index 8287dafb..09556cdc 100644 --- a/Code/Game/DanBiasGame/GameClientState/LevelLoader/ObjectDefines.h +++ b/Code/Game/DanBiasGame/GameClientState/LevelLoader/ObjectDefines.h @@ -9,7 +9,7 @@ namespace GameLogic /************************************ Enums *************************************/ - + enum ObjectType { ObjectType_LevelMetaData, @@ -23,31 +23,45 @@ namespace GameLogic ObjectType_Unknown = -1 }; - enum UsePhysics + enum ObjectSpecialType { - UsePhysics_UseFullPhysics, - UsePhysics_IgnoreGravity, - UsePhysics_IgnorePhysics, - UsePhysics_IgnoreCollision, + ObjectSpecialType_None, + ObjectSpecialType_Sky, + ObjectSpecialType_World, //Always the main celestial body + ObjectSpecialType_Building, + ObjectSpecialType_Stone, + ObjectSpecialType_StandarsBox, + ObjectSpecialType_RedExplosiveBox, + ObjectSpecialType_SpikeBox, + ObjectSpecialType_Spike, + ObjectSpecialType_CrystalFormation, + ObjectSpecialType_CrystalShard, + ObjectSpecialType_JumpPad, + ObjectSpecialType_Portal, + ObjectSpecialType_SpawnPoint, + ObjectSpecialType_Player, + - UsePhysics_Count, - UsePhysics_Unknown = -1 + ObjectSpecialType_Count, + ObjectSpecialType_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 @@ -80,38 +94,84 @@ namespace GameLogic /************************************ Structs *************************************/ - - struct FormatVersion + namespace LevelLoaderInternal { - unsigned int formatVersionMajor; - unsigned 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; - CollisionGeometryType geometryType; - }; + const FormatVersion boundingVolumeVersion(2, 0); + + struct BoundingVolumeBase + { + CollisionGeometryType geoType; + float position[3]; + float rotation[4]; + float frictionCoeffStatic; + float frictionCoeffDynamic; + float restitutionCoeff; + float mass; + }; + + struct BoundingVolumeBox : public BoundingVolumeBase + { + float size[3]; + }; + + struct BoundingVolumeSphere : public BoundingVolumeBase + { + float radius; + }; + + struct BoundingVolumeCylinder : public BoundingVolumeBase + { + float length; + float radius; + }; + + struct BoundingVolume + { + CollisionGeometryType geoType; + union + { + LevelLoaderInternal::BoundingVolumeBox box; + LevelLoaderInternal::BoundingVolumeSphere sphere; + LevelLoaderInternal::BoundingVolumeCylinder cylinder; + }; + }; + + } struct LevelMetaData : public ObjectTypeHeader { @@ -123,21 +183,56 @@ namespace GameLogic WorldSize worldSize; std::string overviewPicturePath; std::vector gameModesSupported; + + virtual ~LevelMetaData(){} + }; - struct ObjectHeader : public ObjectTypeHeader, public PhysicsObject + struct ObjectHeader : public ObjectTypeHeader { + //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; + //Rotation Quaternion + float rotation[4]; //Scale float scale[3]; + + ::GameLogic::LevelLoaderInternal::BoundingVolume boundingVolume; + + virtual ~ObjectHeader(){} }; + /************************************ + Special objects + *************************************/ + + struct JumpPadAttributes : public ObjectHeader + { + float direction[3]; + float power; + }; + + struct PortalAttributes : public ObjectHeader + { + float destination[3]; + }; + + struct WorldAttributes : public ObjectHeader + { + float worldSize; + float atmoSphereSize; + }; + + struct SkyAttributes : public ObjectHeader + { + float skySize; + }; + + /************************************ Lights @@ -145,12 +240,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]; @@ -166,7 +262,7 @@ namespace GameLogic float direction[3]; float range; float attenuation[3]; - }; + };*/ } #endif \ No newline at end of file diff --git a/Code/Game/DanBiasGame/GameClientState/LevelLoader/ParseFunctions.cpp b/Code/Game/DanBiasGame/GameClientState/LevelLoader/ParseFunctions.cpp index 08823d3d..7f5550d7 100644 --- a/Code/Game/DanBiasGame/GameClientState/LevelLoader/ParseFunctions.cpp +++ b/Code/Game/DanBiasGame/GameClientState/LevelLoader/ParseFunctions.cpp @@ -3,10 +3,9 @@ ////////////////////////////////// #include "ParseFunctions.h" -#include "../../../../Misc/Packing/Packing.h" +#include "Loader.h" #include -using namespace Oyster::Packing; using namespace GameLogic::LevelFileLoader; using namespace GameLogic; using namespace std; @@ -15,12 +14,13 @@ namespace GameLogic { namespace LevelFileLoader { + //can parse any struct if the struct doesnt contain strings or char[] void ParseObject(char* buffer, void *header, int size) { memcpy(header, buffer, size); } - void ParseObject(char* buffer, ObjectHeader& header, int& size) + void ParseObject(char* buffer, ObjectHeader& header, int& size, bool loadCgf) { char tempName[128]; unsigned int tempSize = 0; @@ -29,6 +29,9 @@ namespace GameLogic memcpy(&header.typeID, &buffer[start], 4); start += 4; + memcpy(&header.specialTypeID, &buffer[start], 4); + start += 4; + memcpy(&tempSize, &buffer[start], 4); start += 4; @@ -36,13 +39,29 @@ namespace GameLogic header.ModelFile.assign(&tempName[0], &tempName[tempSize]); start += tempSize; + //The reset of the object struct //3 float[3], 1 float memcpy(&header.position, &buffer[start], 40); start += 40; + + //if loadCgf : Read path for bounding volume + if(loadCgf) + { + ParseBoundingVolume(&buffer[start], header.boundingVolume, start); + } - //2 float[3], 3 float, 2 uint - memcpy(&header.usePhysics, &buffer[start], 44); - start += 44; + //else make sure the counter counts the name so we can jump over the string in the buffer. + else + { + memcpy(&tempSize, &buffer[start], 4); + start += 4; + + memcpy(&tempName, &buffer[start], tempSize); + + string fileName; + fileName.assign(&tempName[0], &tempName[tempSize]); + start += tempSize; + } size += start; } @@ -107,5 +126,57 @@ 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; + + size += start; + + //Läs in filen. + int fileLength = 0; + Loader loader; + char* buf = loader.LoadFile("C:/Users/Sam/Documents/GitHub/Danbias/Bin/Content/worlds/cgf/"+ fileName, fileLength); + + start = 0; + LevelLoaderInternal::FormatVersion version; + memcpy(&version, &buf[0], sizeof(version)); + start += 4; + + memcpy(&volume.geoType, &buf[start], sizeof(volume.geoType)); + start += sizeof(volume.geoType); + + switch(volume.geoType) + { + case CollisionGeometryType_Box: + memcpy(&volume.box, &buf[start], sizeof(volume.box)); + start += sizeof(volume.box); + break; + + case CollisionGeometryType_Sphere: + memcpy(&volume.sphere, &buf[start], sizeof(volume.sphere)); + start += sizeof(volume.sphere); + break; + + case CollisionGeometryType_Cylinder: + memcpy(&volume.cylinder, &buf[start], sizeof(volume.cylinder)); + start += sizeof(volume.cylinder); + break; + + default: + break; + } + } } } \ No newline at end of file diff --git a/Code/Game/DanBiasGame/GameClientState/LevelLoader/ParseFunctions.h b/Code/Game/DanBiasGame/GameClientState/LevelLoader/ParseFunctions.h index f68a9289..0fc6dbc6 100644 --- a/Code/Game/DanBiasGame/GameClientState/LevelLoader/ParseFunctions.h +++ b/Code/Game/DanBiasGame/GameClientState/LevelLoader/ParseFunctions.h @@ -17,10 +17,10 @@ namespace GameLogic 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 ParseObject(char* buffer, ObjectHeader& header, int& size , bool loadCgf); void ParseLevelMetaData(char* buffer, LevelMetaData &header, int &size); + void ParseBoundingVolume(char* buffer, LevelLoaderInternal::BoundingVolume& volume, int &size); } } diff --git a/Code/Game/GameLogic/CollisionManager.cpp b/Code/Game/GameLogic/CollisionManager.cpp index 0ef2a204..a0d768a3 100644 --- a/Code/Game/GameLogic/CollisionManager.cpp +++ b/Code/Game/GameLogic/CollisionManager.cpp @@ -24,19 +24,14 @@ using namespace GameLogic; switch (realObj->GetObjectType()) { - case OBJECT_TYPE::OBJECT_TYPE_GENERIC: + case ObjectSpecialType_StandarsBox: PlayerVObject(*player,*realObj, kineticEnergyLoss); //return Physics::ICustomBody::SubscriptMessage_none; break; - - case OBJECT_TYPE::OBJECT_TYPE_BOX: - PlayerVObject(*player,*realObj, kineticEnergyLoss); + case ObjectSpecialType_Player: //return Physics::ICustomBody::SubscriptMessage_none; break; - case OBJECT_TYPE::OBJECT_TYPE_PLAYER: - //return Physics::ICustomBody::SubscriptMessage_none; - break; - case OBJECT_TYPE::OBJECT_TYPE_WORLD: + case ObjectSpecialType_World: PlayerVObject(*player,*realObj, kineticEnergyLoss); //player->playerState = PLAYER_STATE::PLAYER_STATE_WALKING; break; @@ -52,14 +47,14 @@ using namespace GameLogic; switch (realObj->GetObjectType()) { - case OBJECT_TYPE::OBJECT_TYPE_GENERIC: + case ObjectSpecialType_Generic: break; - case OBJECT_TYPE::OBJECT_TYPE_BOX: + case ObjectSpecialType_StandarsBox: break; - case OBJECT_TYPE::OBJECT_TYPE_PLAYER: + case ObjectSpecialType_Player: SendObjectFlying(*obj, jumpPad->pushForce); break; - case OBJECT_TYPE::OBJECT_TYPE_WORLD: + case ObjectSpecialType_World: break; } } @@ -115,7 +110,7 @@ using namespace GameLogic; Object *realObj = (Object*)obj->GetCustomTag(); - if(realObj->GetObjectType() == OBJECT_TYPE_PLAYER || realObj->GetObjectType() == OBJECT_TYPE_WORLD) + if(realObj->GetObjectType() == ObjectSpecialType_Player || realObj->GetObjectType() == ObjectSpecialType_World) return; obj->ApplyImpulse(((forcePushData*)(args))->pushForce); @@ -138,7 +133,7 @@ using namespace GameLogic; switch(realObj->GetObjectType()) { - case OBJECT_TYPE::OBJECT_TYPE_BOX: + case ObjectSpecialType_StandarsBox: //move obj to limbo in physics to make sure it wont collide with anything Oyster::Physics::API::Instance().MoveToLimbo(obj); weapon->heldObject = obj; //weapon now holds the object diff --git a/Code/Game/GameLogic/DynamicObject.cpp b/Code/Game/GameLogic/DynamicObject.cpp index 05a4138d..b6193f30 100644 --- a/Code/Game/GameLogic/DynamicObject.cpp +++ b/Code/Game/GameLogic/DynamicObject.cpp @@ -9,28 +9,28 @@ DynamicObject::DynamicObject() { } -DynamicObject::DynamicObject(OBJECT_TYPE type) +DynamicObject::DynamicObject(ObjectSpecialType type) :Object(type) { } -DynamicObject::DynamicObject(Oyster::Physics::ICustomBody *rigidBody, OBJECT_TYPE type) +DynamicObject::DynamicObject(Oyster::Physics::ICustomBody *rigidBody, ObjectSpecialType type) :Object(rigidBody,type) { } -DynamicObject::DynamicObject( void* collisionFuncAfter, OBJECT_TYPE type) +DynamicObject::DynamicObject( void* collisionFuncAfter, ObjectSpecialType type) :Object(collisionFuncAfter,type) { } -DynamicObject::DynamicObject(Oyster::Physics::ICustomBody *rigidBody , void* collisionFuncAfter, OBJECT_TYPE type) +DynamicObject::DynamicObject(Oyster::Physics::ICustomBody *rigidBody , void* collisionFuncAfter, ObjectSpecialType type) :Object(rigidBody, collisionFuncAfter, type) { } -DynamicObject::DynamicObject(Oyster::Physics::ICustomBody *rigidBody , Oyster::Physics::ICustomBody::SubscriptMessage (*collisionFuncAfter)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), OBJECT_TYPE type) +DynamicObject::DynamicObject(Oyster::Physics::ICustomBody *rigidBody , Oyster::Physics::ICustomBody::SubscriptMessage (*collisionFuncAfter)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), ObjectSpecialType type) :Object(rigidBody, collisionFuncAfter, type) { diff --git a/Code/Game/GameLogic/DynamicObject.h b/Code/Game/GameLogic/DynamicObject.h index 815875b3..e8aa25ce 100644 --- a/Code/Game/GameLogic/DynamicObject.h +++ b/Code/Game/GameLogic/DynamicObject.h @@ -14,11 +14,13 @@ namespace GameLogic public: DynamicObject(); - DynamicObject(OBJECT_TYPE type); - DynamicObject(Oyster::Physics::ICustomBody *rigidBody, OBJECT_TYPE type); - DynamicObject( void* collisionFuncAfter, OBJECT_TYPE type); - DynamicObject(Oyster::Physics::ICustomBody *rigidBody , void* collisionFuncAfter, OBJECT_TYPE type); - DynamicObject(Oyster::Physics::ICustomBody *rigidBody , Oyster::Physics::ICustomBody::SubscriptMessage (*collisionFuncAfter)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), OBJECT_TYPE type); + + DynamicObject(ObjectSpecialType type); + DynamicObject(Oyster::Physics::ICustomBody *rigidBody, ObjectSpecialType type); + DynamicObject( void* collisionFuncAfter, ObjectSpecialType type); + DynamicObject(Oyster::Physics::ICustomBody *rigidBody , void* collisionFuncAfter, ObjectSpecialType type); + DynamicObject(Oyster::Physics::ICustomBody *rigidBody , Oyster::Physics::ICustomBody::SubscriptMessage (*collisionFuncAfter)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), ObjectSpecialType type); + ~DynamicObject(void); diff --git a/Code/Game/GameLogic/Game.cpp b/Code/Game/GameLogic/Game.cpp index c78abb09..8be3f7a8 100644 --- a/Code/Game/GameLogic/Game.cpp +++ b/Code/Game/GameLogic/Game.cpp @@ -81,8 +81,8 @@ Game::LevelData* Game::CreateLevel() if(this->level) return this->level; this->level = new LevelData(); - this->level->level->InitiateLevel(1000); - //this->level->level->InitiateLevel("3bana.bias"); + //this->level->level->InitiateLevel(1000); + this->level->level->InitiateLevel("C:/Users/Sam/Documents/GitHub/Danbias/Bin/Content/worlds/ccc.bias"); return this->level; } diff --git a/Code/Game/GameLogic/Game.h b/Code/Game/GameLogic/Game.h index d88ddd7b..93e130f5 100644 --- a/Code/Game/GameLogic/Game.h +++ b/Code/Game/GameLogic/Game.h @@ -40,8 +40,10 @@ namespace GameLogic Oyster::Math::Float3 GetScale() override; Oyster::Math::Float4x4 GetOrientation() override; int GetID() const override; - OBJECT_TYPE GetObjectType() const override; void Rotate(const Oyster::Math3D::Float3 lookDir, const Oyster::Math3D::Float3 right) override; + ObjectSpecialType GetObjectType() const override; + + Player *player; }; @@ -56,7 +58,7 @@ namespace GameLogic Oyster::Math::Float3 GetScale() override; Oyster::Math::Float4x4 GetOrientation() override; int GetID() const override; - OBJECT_TYPE GetObjectType() const override; + ObjectSpecialType GetObjectType() const override; int getNrOfDynamicObj()const override; IObjectData* GetObjectAt(int ID) const override; Level *level; diff --git a/Code/Game/GameLogic/GameAPI.h b/Code/Game/GameLogic/GameAPI.h index 79656878..30e86e8c 100644 --- a/Code/Game/GameLogic/GameAPI.h +++ b/Code/Game/GameLogic/GameAPI.h @@ -12,6 +12,7 @@ #include "GameLogicDef.h" #include "GameLogicStates.h" #include +#include "LevelLoader\ObjectDefines.h" namespace GameLogic @@ -66,7 +67,7 @@ namespace GameLogic /** Get the type of the object * @return The OBJECT_TYPE of the object is returned */ - virtual OBJECT_TYPE GetObjectType() const = 0; + virtual ObjectSpecialType GetObjectType() const = 0; }; class IPlayerData :public IObjectData diff --git a/Code/Game/GameLogic/GameLogicStates.h b/Code/Game/GameLogic/GameLogicStates.h index 00c2e7ff..9ae0d482 100644 --- a/Code/Game/GameLogic/GameLogicStates.h +++ b/Code/Game/GameLogic/GameLogicStates.h @@ -21,15 +21,6 @@ namespace GameLogic PLAYER_STATE_INVALID = 8, }; - enum OBJECT_TYPE - { - OBJECT_TYPE_PLAYER = 0, - OBJECT_TYPE_BOX = 1, - OBJECT_TYPE_WORLD = 2, - OBJECT_TYPE_GENERIC = 4, - OBJECT_TYPE_UNKNOWN = -1, - }; - enum WEAPON_FIRE { WEAPON_USE_PRIMARY_PRESS = 0, diff --git a/Code/Game/GameLogic/Game_LevelData.cpp b/Code/Game/GameLogic/Game_LevelData.cpp index b8006af3..b007ce01 100644 --- a/Code/Game/GameLogic/Game_LevelData.cpp +++ b/Code/Game/GameLogic/Game_LevelData.cpp @@ -38,7 +38,7 @@ int Game::LevelData::GetID() const { return ((IObjectData*)this->level)->GetID(); } -OBJECT_TYPE Game::LevelData::GetObjectType() const +ObjectSpecialType Game::LevelData::GetObjectType() const { return ((IObjectData*)this->level)->GetObjectType(); //return OBJECT_TYPE_UNKNOWN; diff --git a/Code/Game/GameLogic/Game_PlayerData.cpp b/Code/Game/GameLogic/Game_PlayerData.cpp index 56df13c4..efeab2ee 100644 --- a/Code/Game/GameLogic/Game_PlayerData.cpp +++ b/Code/Game/GameLogic/Game_PlayerData.cpp @@ -6,7 +6,9 @@ using namespace GameLogic; Game::PlayerData::PlayerData() { //set some stats that are appropriate to a player - Oyster::Math::Float3 centerPosition = Oyster::Math::Float3(0,603,0); + + Oyster::Math::Float3 centerPosition = Oyster::Math::Float3(0,400,0); + Oyster::Math::Float3 size = Oyster::Math::Float3(0.25f,1.0f,0.5f); Oyster::Math::Float mass = 60; Oyster::Math::Float restitutionCoeff = 0.5; @@ -18,7 +20,8 @@ Game::PlayerData::PlayerData() Oyster::Physics::ICustomBody* rigidBody = Oyster::Physics::API::Instance().AddCollisionBox(size, Oyster::Math::Float4(0, 0, 0, 1), centerPosition, mass, 0.5f, 0.8f, 0.6f ); rigidBody->SetAngularFactor(0.0f); //create player with this rigid body - this->player = new Player(rigidBody, Player::PlayerCollision, OBJECT_TYPE::OBJECT_TYPE_PLAYER); + this->player = new Player(rigidBody, Player::PlayerCollision, ObjectSpecialType_Player); + this->player->GetRigidBody()->SetCustomTag(this); player->EndFrame(); } @@ -68,7 +71,7 @@ int Game::PlayerData::GetTeamID() const return this->player->GetTeamID(); } -OBJECT_TYPE Game::PlayerData::GetObjectType() const +ObjectSpecialType Game::PlayerData::GetObjectType() const { return this->player->GetObjectType(); } diff --git a/Code/Game/GameLogic/JumpPad.cpp b/Code/Game/GameLogic/JumpPad.cpp index 15b80dc8..2a7d7043 100644 --- a/Code/Game/GameLogic/JumpPad.cpp +++ b/Code/Game/GameLogic/JumpPad.cpp @@ -8,7 +8,8 @@ JumpPad::JumpPad(void) { } -JumpPad::JumpPad(Oyster::Physics::ICustomBody *rigidBody, Oyster::Physics::ICustomBody::SubscriptMessage (*collisionFuncAfter)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), OBJECT_TYPE type, Oyster::Math::Float3 pushForce) + +JumpPad::JumpPad(Oyster::Physics::ICustomBody *rigidBody, Oyster::Physics::ICustomBody::SubscriptMessage (*collisionFuncAfter)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), ObjectSpecialType type, Oyster::Math::Float3 pushForce) :StaticObject(rigidBody, collisionFuncAfter, type) { diff --git a/Code/Game/GameLogic/JumpPad.h b/Code/Game/GameLogic/JumpPad.h index 8d645a00..23601849 100644 --- a/Code/Game/GameLogic/JumpPad.h +++ b/Code/Game/GameLogic/JumpPad.h @@ -10,7 +10,7 @@ namespace GameLogic JumpPad(Oyster::Physics::ICustomBody *rigidBody ,Oyster::Physics::ICustomBody::SubscriptMessage (*collisionFuncAfter)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss) - ,OBJECT_TYPE type, Oyster::Math::Float3 pushForce); + ,ObjectSpecialType type, Oyster::Math::Float3 pushForce); ~JumpPad(void); diff --git a/Code/Game/GameLogic/Level.cpp b/Code/Game/GameLogic/Level.cpp index 04324fcc..6ccf6c5d 100644 --- a/Code/Game/GameLogic/Level.cpp +++ b/Code/Game/GameLogic/Level.cpp @@ -53,6 +53,11 @@ void Level::InitiateLevel(std::string levelPath) int modelCount = 0; int staticObjCount = 0; int dynamicObjCount = 0; + Oyster::Math::Float3 rigidWorldPos; + Oyster::Math::Float4 rigidWorldRotation; + float rigidBodyMass; + float rigidBodyRadius; + Oyster::Math::Float3 rigidBodySize; for (int i = 0; i < objCount; i++) { ObjectTypeHeader* obj = objects.at(i); @@ -73,33 +78,135 @@ void Level::InitiateLevel(std::string levelPath) //LevelLoaderInternal::BoundingVolumeBase* staticObjPhysicData = ((ObjectHeader*)obj); staticObjData->ModelFile; - ICustomBody* rigidBody_Static; + ICustomBody* rigidBody_Static = NULL; + // collision shape // radius, rotation in world, position in world, mass, restitution, static and dynamic friction - ICustomBody* rigidBody = API::Instance().AddCollisionSphere(599.2f, Oyster::Math::Float4(0, 0, 0, 1), Oyster::Math::Float3(0, 0, 0), 0, 0.5f, 0.8f, 0.6f); - + if(staticObjData->boundingVolume.geoType == CollisionGeometryType_Sphere) + { + //offset the rigidPosition from modelspace to worldspace; + rigidWorldPos = (Oyster::Math::Float3)staticObjData->position + (Oyster::Math::Float3)staticObjData->boundingVolume.sphere.position; + //scales the position so the collision geomentry is in the right place + rigidWorldPos = rigidWorldPos * staticObjData->scale; + + //offset the rigidRotation from modelspace to worldspace; + rigidWorldRotation = (Oyster::Math::Float4)staticObjData->rotation + (Oyster::Math::Float4)staticObjData->boundingVolume.sphere.rotation; + + //mass scaled + rigidBodyMass = staticObjData->scale[0] * staticObjData->scale[1] * staticObjData->scale[2] * staticObjData->boundingVolume.sphere.mass; + + //Radius scaled + rigidBodyRadius = (staticObjData->scale[0] * staticObjData->scale[1] * staticObjData->scale[2] / 3) * staticObjData->boundingVolume.sphere.radius; + + //create the rigid body + rigidBody_Static = API::Instance().AddCollisionSphere( rigidBodyRadius , rigidWorldRotation , rigidWorldPos , rigidBodyMass, staticObjData->boundingVolume.sphere.restitutionCoeff , staticObjData->boundingVolume.sphere.frictionCoeffStatic , staticObjData->boundingVolume.sphere.frictionCoeffDynamic); + } + + else if(staticObjData->boundingVolume.geoType == CollisionGeometryType_Box) + { + //offset the rigidPosition from modelspace to worldspace; + rigidWorldPos = (Oyster::Math::Float3)staticObjData->position + (Oyster::Math::Float3)staticObjData->boundingVolume.box.position; + //scales the position so the collision geomentry is in the right place + rigidWorldPos = rigidWorldPos * staticObjData->scale; + + //offset the rigidRotation from modelspace to worldspace; + rigidWorldRotation = (Oyster::Math::Float4)staticObjData->rotation + (Oyster::Math::Float4)staticObjData->boundingVolume.box.rotation; + + //mass scaled + rigidBodyMass = staticObjData->scale[0] * staticObjData->scale[1] * staticObjData->scale[2] * staticObjData->boundingVolume.box.mass; + + //size scaled + rigidBodySize = (Oyster::Math::Float3)staticObjData->boundingVolume.box.size * (Oyster::Math::Float3)staticObjData->scale; + + //create the rigid body + rigidBody_Static = API::Instance().AddCollisionBox(rigidBodySize , rigidWorldRotation , rigidWorldPos , rigidBodyMass, staticObjData->boundingVolume.box.restitutionCoeff , staticObjData->boundingVolume.box.frictionCoeffStatic , staticObjData->boundingVolume.box.frictionCoeffDynamic); + } + + else if(staticObjData->boundingVolume.geoType == CollisionGeometryType_Cylinder) + { + + } + + // add rigidbody to the logical obj // Object::DefaultCollisionBefore, Object::DefaultCollisionAfter for now, gamelogic will take care of this // set object_type to objID - this->staticObjects.Push(new StaticObject(rigidBody, Object::DefaultCollisionAfter, OBJECT_TYPE::OBJECT_TYPE_BOX)); - this->staticObjects[staticObjCount]->objectID = modelCount++; - rigidBody->SetCustomTag(this->staticObjects[staticObjCount]); + if(rigidBody_Static != NULL) + { + this->staticObjects.Push(new StaticObject(rigidBody_Static, Object::DefaultCollisionAfter, (ObjectSpecialType)staticObjData->specialTypeID)); + this->staticObjects[staticObjCount]->objectID = modelCount++; + rigidBody_Static->SetCustomTag(this->staticObjects[staticObjCount]); + } + } break; case ObjectType::ObjectType_Dynamic: { - ObjectHeader* staticObjData = ((ObjectHeader*)obj); - staticObjData->ModelFile; + ObjectHeader* dynamicObjData = ((ObjectHeader*)obj); + dynamicObjData->ModelFile; - ICustomBody* rigidBody_Dynamic; + ICustomBody* rigidBody_Dynamic = NULL; - rigidBody_Dynamic = API::Instance().AddCollisionBox(Oyster::Math::Float3(0.5f, 0.5f, 0.5f), Oyster::Math::Float4(0, 0, 0, 1), Oyster::Math::Float3(0, 605 + i*5, 10), 5, 0.5f, 0.8f, 0.6f); + // collision shape + // radius, rotation in world, position in world, mass, restitution, static and dynamic friction + if(dynamicObjData->boundingVolume.geoType == CollisionGeometryType_Sphere) + { + //offset the rigidPosition from modelspace to worldspace; + rigidWorldPos = (Oyster::Math::Float3)dynamicObjData->position + (Oyster::Math::Float3)dynamicObjData->boundingVolume.sphere.position; + //scales the position so the collision geomentry is in the right place + rigidWorldPos = rigidWorldPos * dynamicObjData->scale; + + //offset the rigidRotation from modelspace to worldspace; + rigidWorldRotation = (Oyster::Math::Float4)dynamicObjData->rotation + (Oyster::Math::Float4)dynamicObjData->boundingVolume.sphere.rotation; + + //mass scaled + rigidBodyMass = dynamicObjData->scale[0] * dynamicObjData->scale[1] * dynamicObjData->scale[2] * dynamicObjData->boundingVolume.sphere.mass; + + //size scaled + rigidBodyRadius = (dynamicObjData->scale[0] * dynamicObjData->scale[1] * dynamicObjData->scale[2] / 3) * dynamicObjData->boundingVolume.sphere.radius; + + //create the rigid body + rigidBody_Dynamic = API::Instance().AddCollisionBox(rigidBodyRadius , rigidWorldRotation , rigidWorldPos , rigidBodyMass, dynamicObjData->boundingVolume.sphere.restitutionCoeff , dynamicObjData->boundingVolume.sphere.frictionCoeffStatic , dynamicObjData->boundingVolume.sphere.frictionCoeffDynamic); + } + + else if(dynamicObjData->boundingVolume.geoType == CollisionGeometryType_Box) + { + //offset the rigidPosition from modelspace to worldspace; + rigidWorldPos = (Oyster::Math::Float3)dynamicObjData->position + (Oyster::Math::Float3)dynamicObjData->boundingVolume.box.position; + //scales the position so the collision geomentry is in the right place + rigidWorldPos = rigidWorldPos * dynamicObjData->scale; + + //offset the rigidRotation from modelspace to worldspace; + rigidWorldRotation = (Oyster::Math::Float4)dynamicObjData->rotation + (Oyster::Math::Float4)dynamicObjData->boundingVolume.box.rotation; + + //mass scaled + rigidBodyMass = dynamicObjData->scale[0] * dynamicObjData->scale[1] * dynamicObjData->scale[2] * dynamicObjData->boundingVolume.box.mass; + + //size scaled + rigidBodySize = (Oyster::Math::Float3)dynamicObjData->boundingVolume.box.size * (Oyster::Math::Float3)dynamicObjData->scale; + + //create the rigid body + rigidBody_Dynamic = API::Instance().AddCollisionBox(rigidBodySize , rigidWorldRotation , rigidWorldPos , rigidBodyMass, dynamicObjData->boundingVolume.box.restitutionCoeff , dynamicObjData->boundingVolume.box.frictionCoeffStatic , dynamicObjData->boundingVolume.box.frictionCoeffDynamic); + } + + else if(dynamicObjData->boundingVolume.geoType == CollisionGeometryType_Cylinder) + { + + } + + + // add rigidbody to the logical obj + // Object::DefaultCollisionBefore, Object::DefaultCollisionAfter for now, gamelogic will take care of this + // set object_type to objID + if(rigidBody_Dynamic != NULL) + { + this->dynamicObjects.Push(new DynamicObject(rigidBody_Dynamic , Object::DefaultCollisionAfter, (ObjectSpecialType)dynamicObjData->specialTypeID)); + this->dynamicObjects[dynamicObjCount]->objectID = modelCount++; + rigidBody_Dynamic->SetCustomTag(this->dynamicObjects[dynamicObjCount]); + } - this->dynamicObjects.Push(new DynamicObject(rigidBody_Dynamic, Object::DefaultCollisionAfter, OBJECT_TYPE::OBJECT_TYPE_BOX)); - this->dynamicObjects[dynamicObjCount]->objectID = modelCount++; - rigidBody_Dynamic->SetCustomTag(this->dynamicObjects[dynamicObjCount]); } break; case ObjectType::ObjectType_Light: @@ -117,7 +224,9 @@ void Level::InitiateLevel(float radius) int idCount = 100; // add level sphere ICustomBody* rigidBody = API::Instance().AddCollisionSphere(599.2f, Oyster::Math::Float4(0, 0, 0, 1), Oyster::Math::Float3(0, 0, 0), 0, 0.5f, 0.8f, 0.6f); - levelObj = new StaticObject(rigidBody, LevelCollisionAfter, OBJECT_TYPE::OBJECT_TYPE_WORLD); + + levelObj = new StaticObject(rigidBody, LevelCollisionAfter, ObjectSpecialType_World); + this->levelObj->objectID = idCount++; rigidBody->SetCustomTag(levelObj); @@ -130,7 +239,8 @@ void Level::InitiateLevel(float radius) { rigidBody_TestBox = API::Instance().AddCollisionBox(Oyster::Math::Float3(0.5f, 0.5f, 0.5f), Oyster::Math::Float4(0, 0, 0, 1), Oyster::Math::Float3(0, 605 + i*5, 10), 5, 0.5f, 0.8f, 0.6f); - this->dynamicObjects.Push(new DynamicObject(rigidBody_TestBox, Object::DefaultCollisionAfter, OBJECT_TYPE::OBJECT_TYPE_BOX)); + this->dynamicObjects.Push(new DynamicObject(rigidBody_TestBox, Object::DefaultCollisionAfter, ObjectSpecialType_StandarsBox)); + this->dynamicObjects[i]->objectID = idCount++; rigidBody_TestBox->SetCustomTag(this->dynamicObjects[i]); } @@ -168,7 +278,7 @@ void Level::InitiateLevel(float radius) // add crystal ICustomBody* rigidBody_Crystal = API::Instance().AddCollisionBox(Oyster::Math::Float3(0.5f, 0.5f, 0.5f), Oyster::Math::Float4(0, 0, 0, 1), Oyster::Math::Float3(10, 605, 0), 5, 0.5f, 0.8f, 0.6f); - this->dynamicObjects.Push(new DynamicObject(rigidBody_Crystal, Object::DefaultCollisionAfter, OBJECT_TYPE::OBJECT_TYPE_BOX)); + this->dynamicObjects.Push(new DynamicObject(rigidBody_Crystal, Object::DefaultCollisionAfter, ObjectSpecialType_StandarsBox)); rigidBody_Crystal->SetCustomTag(this->dynamicObjects[nrOfBoxex]); this->dynamicObjects[nrOfBoxex]->objectID = idCount++; @@ -176,7 +286,7 @@ void Level::InitiateLevel(float radius) // add house ICustomBody* rigidBody_House =API::Instance().AddCollisionBox(Oyster::Math::Float3(20, 20, 20), Oyster::Math::Float4(0, 0, 0, 1), Oyster::Math::Float3(-50, 590, 0), 0, 0.5f, 0.8f, 0.6f); - this->staticObjects.Push(new StaticObject(rigidBody_House, Object::DefaultCollisionAfter, OBJECT_TYPE::OBJECT_TYPE_GENERIC)); + this->staticObjects.Push(new StaticObject(rigidBody_House, Object::DefaultCollisionAfter, ObjectSpecialType_Generic)); rigidBody_House->SetCustomTag(this->staticObjects[0]); this->staticObjects[0]->objectID = idCount++; } @@ -202,7 +312,7 @@ int Level::getNrOfDynamicObj() } Object* Level::GetObj( int ID) const { - for (int i = 0; i< this->dynamicObjects.Size(); i++) + for (int i = 0; i < this->dynamicObjects.Size(); i++) { if(this->dynamicObjects[i]->GetID() == ID) return this->dynamicObjects[i]; diff --git a/Code/Game/GameLogic/LevelLoader/LevelParser.cpp b/Code/Game/GameLogic/LevelLoader/LevelParser.cpp index f66fbe08..c5dfa8cc 100644 --- a/Code/Game/GameLogic/LevelLoader/LevelParser.cpp +++ b/Code/Game/GameLogic/LevelLoader/LevelParser.cpp @@ -25,6 +25,7 @@ std::vector> LevelParser::Parse(std::string filen { int bufferSize = 0; int counter = 0; + bool loadCgf; std::vector> objects; @@ -38,14 +39,13 @@ std::vector> LevelParser::Parse(std::string filen 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) { + loadCgf = true; //Get typeID ObjectType typeID; ParseObject(&buffer[counter], &typeID, sizeof(typeID)); @@ -69,45 +69,43 @@ std::vector> LevelParser::Parse(std::string filen switch(specialType) { - //These three does not have any specail variables at this time. - //There for they are using the same 'parser'. + //there is no difference when parsing these specialTypes. + case ObjectSpecialType_CrystalShard: + case ObjectSpecialType_CrystalFormation: + case ObjectSpecialType_Spike: + case ObjectSpecialType_SpikeBox: + case ObjectSpecialType_RedExplosiveBox: + case ObjectSpecialType_StandarsBox: + case ObjectSpecialType_Stone: case ObjectSpecialType_Building: - case ObjectSpecialType_Damaging: - case ObjectSpecialType_Explosive: { ObjectHeader* header = new ObjectHeader; - ParseObject(&buffer[counter], *header, counter); + ParseObject(&buffer[counter], *header, counter, loadCgf); objects.push_back(header); break; } + case ObjectSpecialType_JumpPad: { JumpPadAttributes* header = new JumpPadAttributes; - ParseObject(&buffer[counter], *header, counter); + ParseObject(&buffer[counter], *header, counter, loadCgf); //Read the spec ParseObject(&buffer[counter], header->direction, 16); + counter += 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, counter, loadCgf); ParseObject(&buffer[counter], header->destination, 12); + counter += 12; objects.push_back(header); break; @@ -116,22 +114,33 @@ std::vector> LevelParser::Parse(std::string filen case ObjectSpecialType_World: { WorldAttributes* header = new WorldAttributes; - ParseObject(&buffer[counter], *header, counter); + ParseObject(&buffer[counter], *header, counter, loadCgf); ParseObject(&buffer[counter], &header->worldSize, 8); + counter += 8; objects.push_back(header); break; } case ObjectSpecialType_Sky: { + loadCgf = false; SkyAttributes* header = new SkyAttributes; - ParseObject(&buffer[counter], *header, counter); + ParseObject(&buffer[counter], *header, counter, loadCgf); ParseObject(&buffer[counter], &header->skySize, 4); + counter += 4; objects.push_back(header); break; } + + case ObjectSpecialType_SpawnPoint: + { + loadCgf = false; + ObjectHeader* header = new ObjectHeader; + ParseObject(&buffer[counter], *header, counter, loadCgf); + } + default: //Couldn't find specialType break; @@ -235,16 +244,13 @@ LevelMetaData LevelParser::ParseHeader(std::string filename) case ObjectType_Static: case ObjectType_Dynamic: { 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; diff --git a/Code/Game/GameLogic/LevelLoader/ObjectDefines.h b/Code/Game/GameLogic/LevelLoader/ObjectDefines.h index 05d09714..4cf34366 100644 --- a/Code/Game/GameLogic/LevelLoader/ObjectDefines.h +++ b/Code/Game/GameLogic/LevelLoader/ObjectDefines.h @@ -25,30 +25,28 @@ namespace GameLogic enum ObjectSpecialType { + ObjectSpecialType_None, + ObjectSpecialType_Sky, ObjectSpecialType_World, //Always the main celestial body ObjectSpecialType_Building, - ObjectSpecialType_Damaging, - ObjectSpecialType_Explosive, + ObjectSpecialType_Stone, + ObjectSpecialType_StandarsBox, + ObjectSpecialType_RedExplosiveBox, + ObjectSpecialType_SpikeBox, + ObjectSpecialType_Spike, + ObjectSpecialType_CrystalFormation, + ObjectSpecialType_CrystalShard, ObjectSpecialType_JumpPad, - ObjectSpecialType_BoostPad, ObjectSpecialType_Portal, - ObjectSpecialType_Sky, + ObjectSpecialType_SpawnPoint, + ObjectSpecialType_Player, + ObjectSpecialType_Generic, + ObjectSpecialType_Count, ObjectSpecialType_Unknown = -1 }; - enum UsePhysics - { - UsePhysics_UseFullPhysics, - UsePhysics_IgnoreGravity, - UsePhysics_IgnorePhysics, - UsePhysics_IgnoreCollision, - - UsePhysics_Count, - UsePhysics_Unknown = -1 - }; - enum CollisionGeometryType { CollisionGeometryType_Box, diff --git a/Code/Game/GameLogic/LevelLoader/ParseFunctions.cpp b/Code/Game/GameLogic/LevelLoader/ParseFunctions.cpp index d917a146..54c41b12 100644 --- a/Code/Game/GameLogic/LevelLoader/ParseFunctions.cpp +++ b/Code/Game/GameLogic/LevelLoader/ParseFunctions.cpp @@ -16,13 +16,13 @@ namespace GameLogic { namespace LevelFileLoader { - //can parse any struct without strings or char[] + //can parse any struct if the struct doesnt contain strings or char[] void ParseObject(char* buffer, void *header, int size) { memcpy(header, buffer, size); } - void ParseObject(char* buffer, ObjectHeader& header, int& size) + void ParseObject(char* buffer, ObjectHeader& header, int& size, bool loadCgf) { char tempName[128]; unsigned int tempSize = 0; @@ -46,8 +46,24 @@ namespace GameLogic memcpy(&header.position, &buffer[start], 40); start += 40; - //Read path for bounding volume - ParseBoundingVolume(&buffer[start], header.boundingVolume, start); + //if loadCgf : Read path for bounding volume + if(loadCgf) + { + ParseBoundingVolume(&buffer[start], header.boundingVolume, start); + } + + //else make sure the counter counts the name so we can jump over the string in the buffer. + else + { + memcpy(&tempSize, &buffer[start], 4); + start += 4; + + memcpy(&tempName, &buffer[start], tempSize); + + string fileName; + fileName.assign(&tempName[0], &tempName[tempSize]); + start += tempSize; + } size += start; } @@ -133,15 +149,14 @@ namespace GameLogic //Läs in filen. int fileLength = 0; Loader loader; - char* buf = loader.LoadFile("E:\\Dropbox\\Programming\\Github\\Danbias\\Bin\\Content\\Worlds\\cgf\\"+ fileName, fileLength); + char* buf = loader.LoadFile("C:/Users/Sam/Documents/GitHub/Danbias/Bin/Content/worlds/cgf/"+ fileName, fileLength); start = 0; LevelLoaderInternal::FormatVersion version; memcpy(&version, &buf[0], sizeof(version)); - start += 4; + start += 8; memcpy(&volume.geoType, &buf[start], sizeof(volume.geoType)); - start += sizeof(volume.geoType); switch(volume.geoType) { diff --git a/Code/Game/GameLogic/LevelLoader/ParseFunctions.h b/Code/Game/GameLogic/LevelLoader/ParseFunctions.h index f66351b4..0fc6dbc6 100644 --- a/Code/Game/GameLogic/LevelLoader/ParseFunctions.h +++ b/Code/Game/GameLogic/LevelLoader/ParseFunctions.h @@ -17,9 +17,8 @@ namespace GameLogic 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 ParseObject(char* buffer, ObjectHeader& header, int& size , bool loadCgf); void ParseLevelMetaData(char* buffer, LevelMetaData &header, int &size); void ParseBoundingVolume(char* buffer, LevelLoaderInternal::BoundingVolume& volume, int &size); } diff --git a/Code/Game/GameLogic/Object.cpp b/Code/Game/GameLogic/Object.cpp index 631ae1b7..80ff0ad6 100644 --- a/Code/Game/GameLogic/Object.cpp +++ b/Code/Game/GameLogic/Object.cpp @@ -18,25 +18,26 @@ Object::Object() this->rigidBody = API::Instance().AddCollisionBox(Oyster::Math::Float3(0.0f, 0.0f, 0.0f), Oyster::Math::Float4(0, 0, 0, 1), Oyster::Math::Float3(0, 0, 0), 0, 0.5f, 0.8f, 0.6f); - this->type = OBJECT_TYPE::OBJECT_TYPE_UNKNOWN; + this->type = ObjectSpecialType_Unknown; this->objectID = GID(); } -Object::Object(OBJECT_TYPE type) +Object::Object(ObjectSpecialType type) { this->rigidBody = API::Instance().AddCollisionBox(Oyster::Math::Float3(0.0f, 0.0f, 0.0f), Oyster::Math::Float4(0, 0, 0, 1), Oyster::Math::Float3(0, 0, 0), 0, 0.5f, 0.8f, 0.6f); this->type = type; this->objectID = GID(); } -Object::Object(Oyster::Physics::ICustomBody *rigidBody, OBJECT_TYPE type) +Object::Object(Oyster::Physics::ICustomBody *rigidBody, ObjectSpecialType type) { this->rigidBody = rigidBody; this->type = type; this->objectID = GID(); } -Object::Object( void* collisionFuncAfter, OBJECT_TYPE type) +Object::Object( void* collisionFuncAfter, ObjectSpecialType type) + { this->rigidBody = API::Instance().AddCollisionBox(Oyster::Math::Float3(0.0f, 0.0f, 0.0f), Oyster::Math::Float4(0, 0, 0, 1), Oyster::Math::Float3(0, 0, 0), 0, 0.5f, 0.8f, 0.6f); @@ -44,7 +45,7 @@ Object::Object( void* collisionFuncAfter, OBJECT_TYPE type) this->objectID = GID(); } -Object::Object(Oyster::Physics::ICustomBody *rigidBody, void* collisionFuncAfter, OBJECT_TYPE type) +Object::Object(Oyster::Physics::ICustomBody *rigidBody, void* collisionFuncAfter, ObjectSpecialType type) { this->rigidBody = rigidBody; this->rigidBody->SetSubscription((Oyster::Physics::ICustomBody::EventAction_AfterCollisionResponse)(collisionFuncAfter)); @@ -52,7 +53,8 @@ Object::Object(Oyster::Physics::ICustomBody *rigidBody, void* collisionFuncAfter this->objectID = GID(); } -Object::Object(Oyster::Physics::ICustomBody *rigidBody , Oyster::Physics::ICustomBody::SubscriptMessage (*collisionFuncAfter)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), OBJECT_TYPE type) + +Object::Object(Oyster::Physics::ICustomBody *rigidBody , Oyster::Physics::ICustomBody::SubscriptMessage (*collisionFuncAfter)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), ObjectSpecialType type) { this->rigidBody = rigidBody; this->rigidBody->SetSubscription((Oyster::Physics::ICustomBody::EventAction_AfterCollisionResponse)(collisionFuncAfter)); @@ -71,7 +73,7 @@ Object::~Object(void) } -OBJECT_TYPE Object::GetObjectType() const +ObjectSpecialType Object::GetObjectType() const { return this->type; } diff --git a/Code/Game/GameLogic/Object.h b/Code/Game/GameLogic/Object.h index 677aef13..83e12277 100644 --- a/Code/Game/GameLogic/Object.h +++ b/Code/Game/GameLogic/Object.h @@ -18,21 +18,24 @@ namespace GameLogic { public: Object(); - Object(OBJECT_TYPE type); - Object(Oyster::Physics::ICustomBody *rigidBody, OBJECT_TYPE type); - Object(void* collisionFuncAfter, OBJECT_TYPE type); - Object(Oyster::Physics::ICustomBody *rigidBody, void* collisionFuncAfter, OBJECT_TYPE type); - Object(Oyster::Physics::ICustomBody *rigidBody, Oyster::Physics::ICustomBody::SubscriptMessage (*collisionFuncAfter)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), OBJECT_TYPE type); + Object(ObjectSpecialType type); + Object(Oyster::Physics::ICustomBody *rigidBody, ObjectSpecialType type); + Object(void* collisionFuncAfter, ObjectSpecialType type); + Object(Oyster::Physics::ICustomBody *rigidBody, void* collisionFuncAfter, ObjectSpecialType type); + Object(Oyster::Physics::ICustomBody *rigidBody, Oyster::Physics::ICustomBody::SubscriptMessage (*collisionFuncAfter)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), ObjectSpecialType type); ~Object(void); - OBJECT_TYPE GetObjectType() const override; - int GetID() const override; + ObjectSpecialType GetObjectType() const override; + int GetID() const override; + void setID(int id); Oyster::Math::Float3 GetPosition() override; Oyster::Math::Quaternion GetRotation() override; Oyster::Math::Float3 GetScale() override; Oyster::Math::Float4x4 GetOrientation() override; - void setID(int id); + // API overrides + + Oyster::Physics::ICustomBody* GetRigidBody(); void ApplyLinearImpulse(Oyster::Math::Float3 force); @@ -45,8 +48,9 @@ namespace GameLogic static Oyster::Physics::ICustomBody::SubscriptMessage DefaultCollisionAfter(Oyster::Physics::ICustomBody *rigidBodyLevel, Oyster::Physics::ICustomBody *obj, Oyster::Math::Float kineticEnergyLoss); - public: //HACK: This should be private when level is dynamic - OBJECT_TYPE type; + + public: //TODO: Hax This should be private when level is dynamic + ObjectSpecialType type; int objectID; protected: diff --git a/Code/Game/GameLogic/Player.cpp b/Code/Game/GameLogic/Player.cpp index 90f2c66b..f6dddb85 100644 --- a/Code/Game/GameLogic/Player.cpp +++ b/Code/Game/GameLogic/Player.cpp @@ -13,27 +13,28 @@ Player::Player() { } -Player::Player(OBJECT_TYPE type) +Player::Player(ObjectSpecialType type) :DynamicObject(type) { InitPlayer(); } -Player::Player(Oyster::Physics::ICustomBody *rigidBody, OBJECT_TYPE type) +Player::Player(Oyster::Physics::ICustomBody *rigidBody, ObjectSpecialType type) :DynamicObject(rigidBody,type) { InitPlayer(); } -Player::Player( void* collisionFuncAfter, OBJECT_TYPE type) + +Player::Player( void* collisionFuncAfter, ObjectSpecialType type) :DynamicObject(collisionFuncAfter,type) { InitPlayer(); } -Player::Player(Oyster::Physics::ICustomBody *rigidBody, void* collisionFuncAfter, OBJECT_TYPE type) +Player::Player(Oyster::Physics::ICustomBody *rigidBody, void* collisionFuncAfter, ObjectSpecialType type) :DynamicObject(rigidBody, collisionFuncAfter, type) { InitPlayer(); } -Player::Player(Oyster::Physics::ICustomBody *rigidBody, Oyster::Physics::ICustomBody::SubscriptMessage (*collisionFuncAfter)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), OBJECT_TYPE type) +Player::Player(Oyster::Physics::ICustomBody *rigidBody, Oyster::Physics::ICustomBody::SubscriptMessage (*collisionFuncAfter)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), ObjectSpecialType type) :DynamicObject(rigidBody, collisionFuncAfter, type) { InitPlayer(); diff --git a/Code/Game/GameLogic/Player.h b/Code/Game/GameLogic/Player.h index d2adb4be..b10d1114 100644 --- a/Code/Game/GameLogic/Player.h +++ b/Code/Game/GameLogic/Player.h @@ -16,11 +16,12 @@ namespace GameLogic { public: Player(void); - Player(OBJECT_TYPE type); - Player(Oyster::Physics::ICustomBody *rigidBody, OBJECT_TYPE type); - Player( void* collisionFuncAfter, OBJECT_TYPE type); - Player(Oyster::Physics::ICustomBody *rigidBody, void* collisionFuncAfter, OBJECT_TYPE type); - Player(Oyster::Physics::ICustomBody *rigidBody, Oyster::Physics::ICustomBody::SubscriptMessage (*collisionFuncAfter)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), OBJECT_TYPE type); + Player(ObjectSpecialType type); + Player(Oyster::Physics::ICustomBody *rigidBody, ObjectSpecialType type); + Player( void* collisionFuncAfter, ObjectSpecialType type); + Player(Oyster::Physics::ICustomBody *rigidBody, void* collisionFuncAfter, ObjectSpecialType type); + Player(Oyster::Physics::ICustomBody *rigidBody, Oyster::Physics::ICustomBody::SubscriptMessage (*collisionFuncAfter)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), ObjectSpecialType type); + ~Player(void); void InitPlayer(); diff --git a/Code/Game/GameLogic/StaticObject.cpp b/Code/Game/GameLogic/StaticObject.cpp index 12725595..f9156e3c 100644 --- a/Code/Game/GameLogic/StaticObject.cpp +++ b/Code/Game/GameLogic/StaticObject.cpp @@ -10,29 +10,29 @@ StaticObject::StaticObject() { } -StaticObject::StaticObject(OBJECT_TYPE type) +StaticObject::StaticObject(ObjectSpecialType type) :Object(type) { } -StaticObject::StaticObject(Oyster::Physics::ICustomBody *rigidBody, OBJECT_TYPE type) +StaticObject::StaticObject(Oyster::Physics::ICustomBody *rigidBody, ObjectSpecialType type) :Object(rigidBody,type) { //this->rigidBody->SetGravity(true); //this->rigidBody->SetSubscription((Oyster::Physics::ICustomBody::EventAction_BeforeCollisionResponse)(CollisionManager::IgnoreCollision)); } -StaticObject::StaticObject( void* collisionFuncAfter, OBJECT_TYPE type) +StaticObject::StaticObject( void* collisionFuncAfter, ObjectSpecialType type) :Object(collisionFuncAfter,type) { } -StaticObject::StaticObject(Oyster::Physics::ICustomBody *rigidBody , void* collisionFuncAfter, OBJECT_TYPE type) +StaticObject::StaticObject(Oyster::Physics::ICustomBody *rigidBody , void* collisionFuncAfter, ObjectSpecialType type) :Object(rigidBody, collisionFuncAfter, type) { } -StaticObject::StaticObject(Oyster::Physics::ICustomBody *rigidBody , Oyster::Physics::ICustomBody::SubscriptMessage (*collisionFuncAfter)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), OBJECT_TYPE type) +StaticObject::StaticObject(Oyster::Physics::ICustomBody *rigidBody , Oyster::Physics::ICustomBody::SubscriptMessage (*collisionFuncAfter)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), ObjectSpecialType type) :Object(rigidBody, collisionFuncAfter, type) { diff --git a/Code/Game/GameLogic/StaticObject.h b/Code/Game/GameLogic/StaticObject.h index 585594e6..4e655808 100644 --- a/Code/Game/GameLogic/StaticObject.h +++ b/Code/Game/GameLogic/StaticObject.h @@ -8,6 +8,7 @@ #include "Object.h" + namespace GameLogic { @@ -16,12 +17,13 @@ namespace GameLogic public: StaticObject(); - StaticObject(OBJECT_TYPE type); - StaticObject(Oyster::Physics::ICustomBody *rigidBody, OBJECT_TYPE type); - StaticObject( void* collisionFuncAfter, OBJECT_TYPE type); - StaticObject(Oyster::Physics::ICustomBody *rigidBody , void* collisionFuncAfter, OBJECT_TYPE type); - StaticObject(Oyster::Physics::ICustomBody *rigidBody , Oyster::Physics::ICustomBody::SubscriptMessage (*collisionFuncAfter)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), OBJECT_TYPE type); + StaticObject(ObjectSpecialType type); + StaticObject(Oyster::Physics::ICustomBody *rigidBody, ObjectSpecialType type); + StaticObject( void* collisionFuncAfter, ObjectSpecialType type); + StaticObject(Oyster::Physics::ICustomBody *rigidBody , void* collisionFuncAfter, ObjectSpecialType type); + StaticObject(Oyster::Physics::ICustomBody *rigidBody , Oyster::Physics::ICustomBody::SubscriptMessage (*collisionFuncAfter)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), ObjectSpecialType type); + ~StaticObject(void); private: