diff --git a/Code/Game/DanBiasGame/GameClientState/Buttons/ButtonEllipse.h b/Code/Game/DanBiasGame/GameClientState/Buttons/ButtonEllipse.h index 291bf07d..5570fb2f 100644 --- a/Code/Game/DanBiasGame/GameClientState/Buttons/ButtonEllipse.h +++ b/Code/Game/DanBiasGame/GameClientState/Buttons/ButtonEllipse.h @@ -37,16 +37,10 @@ namespace DanBias {} //Circle vs point collision - bool Collision(InputClass* inputObject) + bool Collision(Oyster::Event::MouseInput& input) { - POINT p; - RECT r; - GetCursorPos(&p); - ScreenToClient(WindowShell::GetHWND(), &p); - GetClientRect(WindowShell::GetHWND(), &r); - //Should come from the InputClass - float xMouse = (float)p.x / (float)r.right, yMouse = (float)p.y / (float)r.bottom; + float xMouse = input.x, yMouse = input.y; double normx = (xMouse - xPos) / width; double normy = (yMouse - yPos) / height; diff --git a/Code/Game/DanBiasGame/GameClientState/Buttons/ButtonRectangle.h b/Code/Game/DanBiasGame/GameClientState/Buttons/ButtonRectangle.h index a1aac005..711afdf8 100644 --- a/Code/Game/DanBiasGame/GameClientState/Buttons/ButtonRectangle.h +++ b/Code/Game/DanBiasGame/GameClientState/Buttons/ButtonRectangle.h @@ -37,16 +37,10 @@ namespace DanBias {} //Circle vs point collision - bool Collision(InputClass* inputObject) + bool Collision(Oyster::Event::MouseInput& input) { - POINT p; - RECT r; - GetCursorPos(&p); - ScreenToClient(WindowShell::GetHWND(), &p); - GetClientRect(WindowShell::GetHWND(), &r); - //Should come from the InputClass - float xMouse = (float)p.x / (float)r.right, yMouse = (float)p.y / (float)r.bottom; + float xMouse = input.x, yMouse = input.y; float widthTemp = xPos - width * 0.5f; float widthTemp2 = xPos + width * 0.5f; 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/AttatchmentMassDriver.cpp b/Code/Game/GameLogic/AttatchmentMassDriver.cpp index bb7a30f8..1e5d0640 100644 --- a/Code/Game/GameLogic/AttatchmentMassDriver.cpp +++ b/Code/Game/GameLogic/AttatchmentMassDriver.cpp @@ -60,17 +60,18 @@ void AttatchmentMassDriver::Update(float dt) //update position of heldObject if there is an object being held if(hasObject) { - Oyster::Physics::ICustomBody::State state; - state = heldObject->GetState(); + //Oyster::Physics::ICustomBody::State state; + //state = heldObject->GetState(); Oyster::Math::Float3 ownerPos = owner->GetPosition(); Oyster::Physics::ICustomBody::State ownerState = owner->GetRigidBody()->GetState(); Oyster::Math::Float3 up = -ownerState.GetOrientation().v[2]; up *= -0.3; - Oyster::Math::Float3 pos = ownerPos + up + (owner->GetLookDir().GetNormalized()*10); + Oyster::Math::Float3 pos = ownerPos + (owner->GetLookDir().GetNormalized()*5); - state.centerPos = pos; + //state.centerPos = pos; + heldObject->SetPosition(pos); - heldObject->SetState(state); + //heldObject->SetState(state); } } @@ -86,10 +87,8 @@ void AttatchmentMassDriver::ForcePush(const GameLogic::WEAPON_FIRE &usage, float if(hasObject) { Oyster::Physics::API::Instance().ReleaseFromLimbo(heldObject); - pushForce = Oyster::Math::Float4(this->owner->GetLookDir()) * (700); - Oyster::Physics::ICustomBody::State state = heldObject->GetState(); - //state.ApplyLinearImpulse((Oyster::Math::Float3)pushForce); - heldObject->SetState(state); + pushForce = Oyster::Math::Float4(this->owner->GetLookDir()) * (400); + heldObject->ApplyImpulse((Oyster::Math::Float3)pushForce); hasObject = false; heldObject = NULL; @@ -101,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 0ef2a204..9aef6b6c 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,25 +47,21 @@ 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; } } 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); } @@ -115,7 +106,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,9 +129,9 @@ 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); +// Oyster::Physics::API::Instance().MoveToLimbo(obj); weapon->heldObject = obj; //weapon now holds the object weapon->hasObject = true; 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..d52acb45 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), ObjectSpecialType 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..4fad54e4 100644 --- a/Code/Game/GameLogic/JumpPad.h +++ b/Code/Game/GameLogic/JumpPad.h @@ -9,8 +9,9 @@ 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) - ,OBJECT_TYPE type, Oyster::Math::Float3 pushForce); + ,void (*collisionFuncAfter)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss) + ,ObjectSpecialType type, Oyster::Math::Float3 pushForce); + ~JumpPad(void); diff --git a/Code/Game/GameLogic/Level.cpp b/Code/Game/GameLogic/Level.cpp index 04324fcc..3cdab709 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,9 +286,16 @@ 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++; + + // add jumppad + 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, JumpPad::JumpPadActivated, ObjectSpecialType_JumpPad, Oyster::Math::Float3(0,2000,0))); + rigidBody_Jumppad->SetCustomTag(this->staticObjects[1]); + this->staticObjects[1]->objectID = idCount++; } void Level::AddPlayerToTeam(Player *player, int teamID) @@ -202,7 +319,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/Level.h b/Code/Game/GameLogic/Level.h index 15f4a832..b8c3f744 100644 --- a/Code/Game/GameLogic/Level.h +++ b/Code/Game/GameLogic/Level.h @@ -9,6 +9,7 @@ #include "StaticObject.h" #include "DynamicObject.h" #include "GameModeType.h" +#include "JumpPad.h" #include "Player.h" #include "PhysicsAPI.h" #include "TeamManager.h" 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: 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())); diff --git a/Code/GamePhysics/Implementation/SimpleRigidBody.cpp b/Code/GamePhysics/Implementation/SimpleRigidBody.cpp index 7cd2f2b6..5670d32b 100644 --- a/Code/GamePhysics/Implementation/SimpleRigidBody.cpp +++ b/Code/GamePhysics/Implementation/SimpleRigidBody.cpp @@ -106,36 +106,36 @@ void SimpleRigidBody::SetLinearVelocity(Float3 velocity) void SimpleRigidBody::SetPosition(::Oyster::Math::Float3 position) { btTransform trans; - this->motionState->getWorldTransform(trans); + trans = this->rigidBody->getWorldTransform(); trans.setOrigin(btVector3(position.x, position.y, position.z)); - this->motionState->setWorldTransform(trans); + this->rigidBody->setWorldTransform(trans); this->state.centerPos = position; } void SimpleRigidBody::SetRotation(Float4 quaternion) { btTransform trans; - this->motionState->getWorldTransform(trans); + trans = this->rigidBody->getWorldTransform(); trans.setRotation(btQuaternion(quaternion.x, quaternion.y, quaternion.z, quaternion.w)); - this->motionState->setWorldTransform(trans); + this->rigidBody->setWorldTransform(trans); this->state.quaternion = Quaternion(quaternion.xyz, quaternion.w); } void SimpleRigidBody::SetRotation(::Oyster::Math::Quaternion quaternion) { btTransform trans; - this->motionState->getWorldTransform(trans); + trans = this->rigidBody->getWorldTransform(); trans.setRotation(btQuaternion(quaternion.imaginary.x, quaternion.imaginary.y, quaternion.imaginary.z, quaternion.real)); - this->motionState->setWorldTransform(trans); + this->rigidBody->setWorldTransform(trans); this->state.quaternion = quaternion; } void SimpleRigidBody::SetRotation(Float3 eulerAngles) { btTransform trans; - this->motionState->getWorldTransform(trans); + trans = this->rigidBody->getWorldTransform(); trans.setRotation(btQuaternion(eulerAngles.x, eulerAngles.y, eulerAngles.z)); - this->motionState->setWorldTransform(trans); + this->rigidBody->setWorldTransform(trans); this->state.quaternion = Quaternion(Float3(trans.getRotation().x(), trans.getRotation().y(), trans.getRotation().z()), trans.getRotation().w()); } diff --git a/Code/Misc/EventHandler/EventButton.h b/Code/Misc/EventHandler/EventButton.h index b891889d..0f197ffc 100644 --- a/Code/Misc/EventHandler/EventButton.h +++ b/Code/Misc/EventHandler/EventButton.h @@ -46,7 +46,7 @@ namespace Oyster private: //Implement this in the inherited classes for collision against that shape. - virtual bool Collision(InputClass *input) = 0; + virtual bool Collision(MouseInput& input) = 0; public: EventButton(); @@ -56,7 +56,7 @@ namespace Oyster EventButton(EventFunc func, Owner owner, void* userData); virtual ~EventButton(); - void Update(InputClass *input); + void Update(MouseInput& input); //Send event to callback function void SendEvent(ButtonState state); @@ -135,16 +135,18 @@ namespace Oyster //Checks for collision and template - void EventButton::Update(InputClass *input) + void EventButton::Update(MouseInput& input) { if(this->privData.enabled) { ButtonState currentState = ButtonState_None; static bool outside = false; static bool clicked = false; + + //Check for collision against the button. if(Collision(input)) { - if(input->IsMousePressed()) + if(input.mouseButtonPressed) { //Change state when the mouse button is pressed switch(this->privData.previousState) diff --git a/Code/Misc/EventHandler/EventButtonCollection.cpp b/Code/Misc/EventHandler/EventButtonCollection.cpp index 2bd5f09a..9e52805e 100644 --- a/Code/Misc/EventHandler/EventButtonCollection.cpp +++ b/Code/Misc/EventHandler/EventButtonCollection.cpp @@ -20,6 +20,7 @@ EventButtonCollection::~EventButtonCollection() if(EventHandler::Instance().collections.at(i) == this) { EventHandler::Instance().collections.erase(EventHandler::Instance().collections.begin() + i); + break; } } @@ -31,13 +32,13 @@ EventButtonCollection::~EventButtonCollection() } } -void EventButtonCollection::Update(InputClass* inputObject) +void EventButtonCollection::Update(MouseInput& input) { if(this->collectionState == EventCollectionState_Enabled) { for(int i = 0; i < (int)buttons.size(); i++) { - buttons[i]->Update(inputObject); + buttons[i]->Update(input); } } } diff --git a/Code/Misc/EventHandler/EventButtonCollection.h b/Code/Misc/EventHandler/EventButtonCollection.h index 5bcd044a..3cb3c891 100644 --- a/Code/Misc/EventHandler/EventButtonCollection.h +++ b/Code/Misc/EventHandler/EventButtonCollection.h @@ -36,7 +36,7 @@ namespace Oyster EventButtonCollection(EventCollectionState state = EventCollectionState_Enabled); ~EventButtonCollection(); - void Update(InputClass* inputObject); + void Update(MouseInput& input); void Render(); /*Add a button to the collection when a button is added to the collection you are not allowed to delete it. diff --git a/Code/Misc/EventHandler/EventHandler.cpp b/Code/Misc/EventHandler/EventHandler.cpp index 4b623714..558b776c 100644 --- a/Code/Misc/EventHandler/EventHandler.cpp +++ b/Code/Misc/EventHandler/EventHandler.cpp @@ -19,30 +19,19 @@ EventHandler::EventHandler() EventHandler::~EventHandler() { - int size = collections.size(); - for(int i = 0; i < size; i++) - { - delete collections[i]; - collections[i] = NULL; - } + Clean(); } void EventHandler::Clean() { - int size = collections.size(); - for(int i = 0; i < size; i++) - { - delete collections[i]; - collections[i] = NULL; - } collections.clear(); } -void EventHandler::Update(InputClass* inputObject) +void EventHandler::Update(MouseInput& input) { for(int i = 0; i < (int)collections.size(); i++) { - collections.at(i)->Update(inputObject); + collections.at(i)->Update(input); } } @@ -65,14 +54,12 @@ void EventHandler::AddCollection(EventButtonCollection* collection) collections.push_back(collection); } -void EventHandler::DeleteCollection(EventButtonCollection* collection) +void EventHandler::ReleaseCollection(EventButtonCollection* collection) { for(int i = 0; i < collections.size(); i++) { if(collections.at(i) == collection) { - delete collection; - collection = NULL; collections.erase(collections.begin() + i); break; } diff --git a/Code/Misc/EventHandler/EventHandler.h b/Code/Misc/EventHandler/EventHandler.h index 71a35ecd..79196afb 100644 --- a/Code/Misc/EventHandler/EventHandler.h +++ b/Code/Misc/EventHandler/EventHandler.h @@ -26,14 +26,15 @@ namespace Oyster void Clean(); - void Update(InputClass* inputObject); + void Update(MouseInput& input); void Render(); /*Add a collection to the EventHandler will only add collections not already present in the list. */ void AddCollection(EventButtonCollection* collection); - void DeleteCollection(EventButtonCollection* collection); + + void ReleaseCollection(EventButtonCollection* collection); private: //Can't copy this class. @@ -43,7 +44,7 @@ namespace Oyster private: std::vector collections; - //EventButtonCollection is a firend so it can delete it self. + //EventButtonCollection is a friend so it can delete it self. friend class EventButtonCollection; }; } diff --git a/Code/Misc/EventHandler/IEventButton.h b/Code/Misc/EventHandler/IEventButton.h index 13e6f21b..62044eb2 100644 --- a/Code/Misc/EventHandler/IEventButton.h +++ b/Code/Misc/EventHandler/IEventButton.h @@ -19,6 +19,14 @@ namespace Oyster ButtonState_Down, ButtonState_Released, }; + + //Takes normalized device coordinates + struct MouseInput + { + //Normalized device coordinates + float x, y; + bool mouseButtonPressed; + }; class IEventButton { @@ -26,7 +34,8 @@ namespace Oyster virtual ~IEventButton(){} virtual void Render() = 0; - virtual void Update(InputClass *input) = 0; + + virtual void Update(MouseInput& input) = 0; virtual void SendEvent(ButtonState state) = 0;