diff --git a/Code/DanBias.sln b/Code/DanBias.sln index 80a76dea..e14d2c37 100644 --- a/Code/DanBias.sln +++ b/Code/DanBias.sln @@ -45,6 +45,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "GameClient", "Game\GameClie EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Utilities", "Misc\Utilities\Utilities.vcxproj", "{2EC4DDED-8F75-4C86-A10B-E1E8EB29F3EE}" EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "LevelLoader", "Game\LevelLoader\LevelLoader.vcxproj", "{6391E709-D9FA-4FEF-A3B9-4343DB5A0C63}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -679,6 +681,40 @@ Global {2EC4DDED-8F75-4C86-A10B-E1E8EB29F3EE}.RelWithDebInfo|x64.Build.0 = Release|x64 {2EC4DDED-8F75-4C86-A10B-E1E8EB29F3EE}.RelWithDebInfo|x86.ActiveCfg = Release|Win32 {2EC4DDED-8F75-4C86-A10B-E1E8EB29F3EE}.RelWithDebInfo|x86.Build.0 = Release|Win32 + {6391E709-D9FA-4FEF-A3B9-4343DB5A0C63}.Debug|Any CPU.ActiveCfg = Debug|Win32 + {6391E709-D9FA-4FEF-A3B9-4343DB5A0C63}.Debug|Mixed Platforms.ActiveCfg = Debug|Win32 + {6391E709-D9FA-4FEF-A3B9-4343DB5A0C63}.Debug|Mixed Platforms.Build.0 = Debug|Win32 + {6391E709-D9FA-4FEF-A3B9-4343DB5A0C63}.Debug|Win32.ActiveCfg = Debug|Win32 + {6391E709-D9FA-4FEF-A3B9-4343DB5A0C63}.Debug|Win32.Build.0 = Debug|Win32 + {6391E709-D9FA-4FEF-A3B9-4343DB5A0C63}.Debug|x64.ActiveCfg = Debug|x64 + {6391E709-D9FA-4FEF-A3B9-4343DB5A0C63}.Debug|x64.Build.0 = Debug|x64 + {6391E709-D9FA-4FEF-A3B9-4343DB5A0C63}.Debug|x86.ActiveCfg = Debug|Win32 + {6391E709-D9FA-4FEF-A3B9-4343DB5A0C63}.Debug|x86.Build.0 = Debug|Win32 + {6391E709-D9FA-4FEF-A3B9-4343DB5A0C63}.MinSizeRel|Any CPU.ActiveCfg = Release|Win32 + {6391E709-D9FA-4FEF-A3B9-4343DB5A0C63}.MinSizeRel|Mixed Platforms.ActiveCfg = Release|Win32 + {6391E709-D9FA-4FEF-A3B9-4343DB5A0C63}.MinSizeRel|Mixed Platforms.Build.0 = Release|Win32 + {6391E709-D9FA-4FEF-A3B9-4343DB5A0C63}.MinSizeRel|Win32.ActiveCfg = Release|Win32 + {6391E709-D9FA-4FEF-A3B9-4343DB5A0C63}.MinSizeRel|Win32.Build.0 = Release|Win32 + {6391E709-D9FA-4FEF-A3B9-4343DB5A0C63}.MinSizeRel|x64.ActiveCfg = Release|Win32 + {6391E709-D9FA-4FEF-A3B9-4343DB5A0C63}.MinSizeRel|x86.ActiveCfg = Release|Win32 + {6391E709-D9FA-4FEF-A3B9-4343DB5A0C63}.MinSizeRel|x86.Build.0 = Release|Win32 + {6391E709-D9FA-4FEF-A3B9-4343DB5A0C63}.Release|Any CPU.ActiveCfg = Release|Win32 + {6391E709-D9FA-4FEF-A3B9-4343DB5A0C63}.Release|Mixed Platforms.ActiveCfg = Release|Win32 + {6391E709-D9FA-4FEF-A3B9-4343DB5A0C63}.Release|Mixed Platforms.Build.0 = Release|Win32 + {6391E709-D9FA-4FEF-A3B9-4343DB5A0C63}.Release|Win32.ActiveCfg = Release|Win32 + {6391E709-D9FA-4FEF-A3B9-4343DB5A0C63}.Release|Win32.Build.0 = Release|Win32 + {6391E709-D9FA-4FEF-A3B9-4343DB5A0C63}.Release|x64.ActiveCfg = Release|x64 + {6391E709-D9FA-4FEF-A3B9-4343DB5A0C63}.Release|x64.Build.0 = Release|x64 + {6391E709-D9FA-4FEF-A3B9-4343DB5A0C63}.Release|x86.ActiveCfg = Release|Win32 + {6391E709-D9FA-4FEF-A3B9-4343DB5A0C63}.Release|x86.Build.0 = Release|Win32 + {6391E709-D9FA-4FEF-A3B9-4343DB5A0C63}.RelWithDebInfo|Any CPU.ActiveCfg = Release|Win32 + {6391E709-D9FA-4FEF-A3B9-4343DB5A0C63}.RelWithDebInfo|Mixed Platforms.ActiveCfg = Release|Win32 + {6391E709-D9FA-4FEF-A3B9-4343DB5A0C63}.RelWithDebInfo|Mixed Platforms.Build.0 = Release|Win32 + {6391E709-D9FA-4FEF-A3B9-4343DB5A0C63}.RelWithDebInfo|Win32.ActiveCfg = Release|Win32 + {6391E709-D9FA-4FEF-A3B9-4343DB5A0C63}.RelWithDebInfo|Win32.Build.0 = Release|Win32 + {6391E709-D9FA-4FEF-A3B9-4343DB5A0C63}.RelWithDebInfo|x64.ActiveCfg = Release|Win32 + {6391E709-D9FA-4FEF-A3B9-4343DB5A0C63}.RelWithDebInfo|x86.ActiveCfg = Release|Win32 + {6391E709-D9FA-4FEF-A3B9-4343DB5A0C63}.RelWithDebInfo|x86.Build.0 = Release|Win32 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -692,6 +728,7 @@ Global {C83A6FAD-E71F-4B1E-9D63-E93E61DDC012} = {20720CA7-795C-45AD-A302-9383A6DD503A} {8690FDDF-C5B7-4C42-A337-BD5243F29B85} = {20720CA7-795C-45AD-A302-9383A6DD503A} {2A1BC987-AF42-4500-802D-89CD32FC1309} = {20720CA7-795C-45AD-A302-9383A6DD503A} + {6391E709-D9FA-4FEF-A3B9-4343DB5A0C63} = {20720CA7-795C-45AD-A302-9383A6DD503A} {C4C76A8D-44C5-4452-9F61-39C7E01CBDB4} = {F156EEBC-0195-4020-8700-4433208DE12B} {3EA5F14D-2A71-4588-A69D-87C4571C580F} = {F156EEBC-0195-4020-8700-4433208DE12B} {7E3990D2-3D94-465C-B58D-64A74B3ECF9B} = {1322B12B-5E37-448A-AAAF-F637460DCB23} diff --git a/Code/Game/GameClient/GameClient.vcxproj b/Code/Game/GameClient/GameClient.vcxproj index 349a88ec..c084532d 100644 --- a/Code/Game/GameClient/GameClient.vcxproj +++ b/Code/Game/GameClient/GameClient.vcxproj @@ -106,7 +106,7 @@ Disabled DANBIAS_GAME_DLL_EXPORT;WIN32;_DEBUG;_WINDOWS;%(PreprocessorDefinitions) true - $(SolutionDir)Misc\OysterMath;$(SolutionDir)Misc\Input;$(SolutionDir)OysterGraphics;$(SolutionDir)Misc\Utilities;%(AdditionalIncludeDirectories) + $(SolutionDir)Misc\OysterMath;$(SolutionDir)Misc\Input;$(SolutionDir)OysterGraphics;$(SolutionDir)Misc\Utilities;$(SolutionDir)Game\LevelLoader Windows @@ -123,7 +123,7 @@ Disabled DANBIAS_GAME_DLL_EXPORT;WIN32;_DEBUG;_WINDOWS;%(PreprocessorDefinitions) true - $(SolutionDir)Misc\OysterMath;$(SolutionDir)Misc\Input;$(SolutionDir)OysterGraphics;$(SolutionDir)Misc\Utilities;%(AdditionalIncludeDirectories) + $(SolutionDir)Misc\OysterMath;$(SolutionDir)Misc\Input;$(SolutionDir)OysterGraphics;$(SolutionDir)Misc\Utilities;$(SolutionDir)Game\LevelLoader Windows @@ -142,7 +142,7 @@ true DANBIAS_GAME_DLL_EXPORT;WIN32;NDEBUG;_WINDOWS;%(PreprocessorDefinitions) true - $(SolutionDir)Misc\OysterMath;$(SolutionDir)Misc\Input;$(SolutionDir)OysterGraphics;$(SolutionDir)Misc\Utilities;%(AdditionalIncludeDirectories) + $(SolutionDir)Misc\OysterMath;$(SolutionDir)Misc\Input;$(SolutionDir)OysterGraphics;$(SolutionDir)Misc\Utilities;$(SolutionDir)Game\LevelLoader Windows @@ -163,7 +163,7 @@ true DANBIAS_GAME_DLL_EXPORT;WIN32;NDEBUG;_WINDOWS;%(PreprocessorDefinitions) true - $(SolutionDir)Misc\OysterMath;$(SolutionDir)Misc\Input;$(SolutionDir)OysterGraphics;$(SolutionDir)Misc\Utilities;%(AdditionalIncludeDirectories) + $(SolutionDir)Misc\OysterMath;$(SolutionDir)Misc\Input;$(SolutionDir)OysterGraphics;$(SolutionDir)Misc\Utilities;$(SolutionDir)Game\LevelLoader Windows @@ -196,6 +196,9 @@ {143bd516-20a1-4890-a3e4-f8bfd02220e7} + + {6391e709-d9fa-4fef-a3b9-4343db5a0c63} + @@ -204,6 +207,7 @@ + @@ -211,16 +215,15 @@ + + - - - - + @@ -231,21 +234,20 @@ + + + - - - - - + diff --git a/Code/Game/GameClient/GameClientRecieverFunc.h b/Code/Game/GameClient/GameClientRecieverFunc.h deleted file mode 100644 index 673cbdd1..00000000 --- a/Code/Game/GameClient/GameClientRecieverFunc.h +++ /dev/null @@ -1,192 +0,0 @@ -#ifndef DANBIAS_CLIENTRECIEVEROBJECT_H -#define DANBIAS_CLIENTRECIEVEROBJECT_H - -//WTF!? No headers included??? -#include "../DanBiasGame/Include/DanBiasGame.h" -#include "../GameProtocols/GeneralProtocols.h" -#include "../GameProtocols/Protocols.h" -#include "../Network/NetworkAPI/NetworkClient.h" -#include "GameClientState\GameClientState.h" -#include "GameClientState\GameState.h" - -#include - -namespace DanBias -{ - struct GameRecieverObject : public Oyster::Network::NetworkClient - { - Client::GameClientState* gameClientState; - - // receiver function for server messages - // parsing protocols and sending it to the gameState - //void NetworkCallback(Oyster::Network::CustomNetProtocol& p) override - void GameRecieverObject::DataRecieved( Oyster::Network::NetEvent e ) override - { - Oyster::Network::CustomNetProtocol p = e.args.data.protocol; - int pType = p[0].value.netInt; - - //printf("Message(%i) arrived at client(%i)\n", pType, this->GetID()); - - - switch (pType) - { - case protocol_General_Status: - { - GameLogic::Protocol_General_Status::States state; - state = (GameLogic::Protocol_General_Status::States)p[1].value.netShort; - if( state == GameLogic::Protocol_General_Status::States_disconected) - { - // server disconnected - DanBiasGame::Release(); - } - } - break; - case protocol_Gameplay_ObjectCreate: - { - Client::GameClientState::NewObj protocolData;// = new Client::GameClientState::NewObj; - protocolData.object_ID = p[1].value.netInt; - protocolData.path = p[2].value.netCharPtr; - for(int i = 0; i< 16; i++) - { - protocolData.worldPos[i] = p[i+3].value.netFloat; - } - - if(dynamic_cast(gameClientState)) - ((Client::GameState*)gameClientState)->Protocol(&protocolData); - - //delete p[2].value.netCharPtr; //delete char array - //delete protocolData; - //protocolData = NULL; - } - break; - case protocol_Gameplay_ObjectDisabled: - { - Client::GameClientState::RemoveObj* protocolData = new Client::GameClientState::RemoveObj; - protocolData->object_ID = p[1].value.netInt; - - if(dynamic_cast(gameClientState)) - ((Client::GameState*)gameClientState)->Protocol(protocolData); - - delete protocolData; - protocolData = NULL; - } - break; - case protocol_Gameplay_ObjectPosition: - { - // 0: reserved - // 1: objectID - // 2,3,4: position - // 5,6,7,8: rotation quaternion - - GameLogic::Protocol_ObjectPosition data(p); - - Client::GameClientState::ObjPos protocolData; - protocolData.object_ID = data.object_ID; - //protocolData.object_ID = p[1].value.netInt; - - for( int i = 0; i < 3; ++i ) - { - protocolData.position[i] = data.position[i]; - } - - //for(int i = 0; i< 16; i++) - //{ - // protocolData.worldPos[i] = p[i+2].value.netFloat; - //} - - if(dynamic_cast(gameClientState)) - ((Client::GameState*)gameClientState)->Protocol(&protocolData); - } - break; - case protocol_Gameplay_ObjectPositionRotation: - { - - Client::GameClientState::ObjPos protocolData; - protocolData.object_ID = p[1].value.netInt; - for(int i = 0; i< 16; i++) - { - protocolData.worldPos[i] = p[i+2].value.netFloat; - } - - if(dynamic_cast(gameClientState)) - ((Client::GameState*)gameClientState)->Protocol(&protocolData); - } - break; - case protocol_Lobby_Create: - { - if(dynamic_cast(gameClientState)) - { - int id = p.Get(1).value.netInt; - std::string name = p.Get(19).value.netCharPtr; - Oyster::Math::Float4x4 w; - for(int i = 0; i< 16; i++) - { - w[i] = p[i+2].value.netFloat; - } - - gameClientState->Release(); - delete gameClientState; - - gameClientState = new Client::GameState(); - gameClientState->Init(this); - std::wstring temp; - Utility::String::StringToWstring(name, temp); - ((Client::GameState*)gameClientState)->InitiatePlayer(id, temp, w); - - //Do some wait state? - } - } - break; - case protocol_Lobby_Start: - { - if(dynamic_cast(gameClientState)) - { - //Game state should start in n seconds - GameLogic::Protocol_LobbyStartGame p(p); - p.seconds; - - //Sleep((int)(p.seconds * 1000)); - } - } - break; - - default: - break; - } - - if(ProtocolIsLobby(p[0].value.netInt)) ParseLobbyProtocol(p); - } - - void ParseLobbyProtocol(Oyster::Network::CustomNetProtocol& p) - { - switch (p[0].value.netShort) - { - case protocol_General_Status: //this->GeneralStatus (Protocol_General_Status (p), c); - break; - case protocol_General_Text: //this->GeneralText (Protocol_General_Text (p), c); - break; - //case protocol_Lobby_Create: this->LobbyCreateGame (Protocol_LobbyCreateGame (p), c); - //break; - case protocol_Lobby_Start: //this->LobbyStartGame (Protocol_LobbyStartGame (p), c); - break; - //case protocol_Lobby_Join: this->LobbyJoin (Protocol_LobbyJoin (p), c); - //break; - case protocol_Lobby_Login: //this->LobbyLogin (Protocol_LobbyLogin (p), c); - break; - case protocol_Lobby_Refresh: //this->LobbyRefresh (Protocol_LobbyRefresh (p), c); - break; - case protocol_Lobby_GameData: //this->LobbyGameData (Protocol_LobbyGameData (p), c); - { - //GameLogic::Protocol_LobbyGameData temp(p); - //printf("%s, %i.%i\n", temp.mapName.c_str(), temp.majorVersion, temp.minorVersion); - } - break; - case protocol_Lobby_ClientData: //this->LobbyMainData (Protocol_LobbyClientData (p), c); - break; - //case protocol_Lobby_GameData: this->LobbyGameData (Protocol_LobbyGameData (p), c); - //break; - } - } - }; -} -#endif \ No newline at end of file diff --git a/Code/Game/GameClient/GameClientState/C_Light.cpp b/Code/Game/GameClient/GameClientState/C_Light.cpp new file mode 100644 index 00000000..17016ae5 --- /dev/null +++ b/Code/Game/GameClient/GameClientState/C_Light.cpp @@ -0,0 +1,37 @@ +#include "C_Light.h" +using namespace DanBias::Client; +C_Light::C_Light( Oyster::Graphics::Definitions::Pointlight pointLightDesc, int id ) +{ + this->pointLightDesc = pointLightDesc; + this->id = id; +} +C_Light::~C_Light() +{ + +} +Oyster::Graphics::Definitions::Pointlight C_Light::getLightDesc() const +{ + return this->pointLightDesc; +} +void C_Light::setLightDesc( Oyster::Graphics::Definitions::Pointlight pointLightDesc ) +{ + this->pointLightDesc = pointLightDesc; +} +Oyster::Math::Float3 C_Light::getPos() const +{ + return this->pointLightDesc.Pos; +} +void C_Light::setPos( Oyster::Math::Float3 newPos) +{ + this->pointLightDesc.Pos = newPos; +} + +int C_Light::GetId() const +{ + return this->id; +} +void C_Light::Render() +{ + // will be changed to new API + Oyster::Graphics::API::AddLight(pointLightDesc); +} diff --git a/Code/Game/GameClient/GameClientState/C_Light.h b/Code/Game/GameClient/GameClientState/C_Light.h new file mode 100644 index 00000000..4802339d --- /dev/null +++ b/Code/Game/GameClient/GameClientState/C_Light.h @@ -0,0 +1,29 @@ +#ifndef DANBIAS_CLIENT_CLIGHT_H +#define DANBIAS_CLIENT_CLIGHT_H +#include "DllInterfaces/GFXAPI.h" +namespace DanBias +{ + namespace Client + { + class C_Light + { + private: + Oyster::Graphics::Definitions::Pointlight pointLightDesc; + int id; + + public: + C_Light( Oyster::Graphics::Definitions::Pointlight pointLightDesc, int id ); + virtual ~C_Light(); + + Oyster::Graphics::Definitions::Pointlight getLightDesc() const; + void setLightDesc( Oyster::Graphics::Definitions::Pointlight pointLightDesc ); + + Oyster::Math::Float3 getPos() const; + void setPos( Oyster::Math::Float3 newPos); + void Render(); + int GetId() const; + }; + } +} + +#endif diff --git a/Code/Game/GameClient/GameClientState/C_Object.cpp b/Code/Game/GameClient/GameClientState/C_Object.cpp index 92b55c53..ccea9a86 100644 --- a/Code/Game/GameClient/GameClientState/C_Object.cpp +++ b/Code/Game/GameClient/GameClientState/C_Object.cpp @@ -9,6 +9,10 @@ C_Object::C_Object() id = 0; model = NULL; + + // RB DEBUG + type = RB_Type_None; + // !RB DEBUG } C_Object::~C_Object() { @@ -31,32 +35,27 @@ void C_Object::updateWorld() { Oyster::Math3D::Float4x4 translation = Oyster::Math3D::TranslationMatrix(this->position); Oyster::Math3D::Float4x4 rot = Oyster::Math3D::RotationMatrix(this->rotation); - //Oyster::Math3D::Float4x4 scale = Oyster::Math3D::; - Oyster::Math3D::Float4x4 scale = Oyster::Math3D::Matrix::identity; - scale.v[0].x = this->scale[0]; - scale.v[1].y = this->scale[1]; - scale.v[2].z = this->scale[2]; + Oyster::Math3D::Float4x4 scale = Oyster::Math3D::ScalingMatrix(this->scale); world = translation * rot * scale; model->WorldMatrix = world; } -void C_Object::setWorld(Oyster::Math::Float4x4 world) -{ - model->WorldMatrix = world; -} Oyster::Math::Float4x4 C_Object::getWorld() const { + Oyster::Math3D::Float4x4 translation = Oyster::Math3D::TranslationMatrix(this->position); + Oyster::Math3D::Float4x4 rot = Oyster::Math3D::RotationMatrix(this->rotation); + Oyster::Math3D::Float4x4 scale = Oyster::Math3D::ScalingMatrix(this->scale); + Oyster::Math3D::Float4x4 world = translation * rot * scale; + return world; } void C_Object::setPos(Oyster::Math::Float3 newPos) { this->position = newPos; - updateWorld(); } void C_Object::addPos(Oyster::Math::Float3 deltaPos) { this->position += deltaPos; - updateWorld(); } Oyster::Math::Float3 C_Object::getPos() const { @@ -65,12 +64,6 @@ Oyster::Math::Float3 C_Object::getPos() const void C_Object::setRot(Oyster::Math::Quaternion newRot) { this->rotation = newRot; - updateWorld(); -} -void C_Object::addRot(Oyster::Math::Quaternion deltaRot) -{ - this->rotation += deltaRot; - updateWorld(); } Oyster::Math::Quaternion C_Object::getRotation() const { @@ -79,12 +72,10 @@ Oyster::Math::Quaternion C_Object::getRotation() const void C_Object::setScale(Oyster::Math::Float3 newScale) { this->scale = newScale; - updateWorld(); } void C_Object::addScale(Oyster::Math::Float3 deltaScale) { this->scale += deltaScale; - updateWorld(); } Oyster::Math::Float3 C_Object::getScale() const { @@ -105,4 +96,56 @@ void C_Object::Release() Oyster::Graphics::API::DeleteModel(model); this->model = nullptr; } -} \ No newline at end of file +} + + + +//////////////////////////////////////////////// +// RB DEBUG +//////////////////////////////////////////////// +bool C_Object::InitRB(RBInitData RBInit) +{ + RBposition = RBInit.position; + RBrotation = RBInit.rotation; + RBscale = RBInit.scale; + type = RBInit.type; + return true; +} +Oyster::Math::Float4x4 C_Object::getRBWorld() const +{ + Oyster::Math3D::Float4x4 translation = Oyster::Math3D::TranslationMatrix(this->RBposition); + Oyster::Math3D::Float4x4 rot = Oyster::Math3D::RotationMatrix(this->RBrotation); + Oyster::Math3D::Float4x4 scale = Oyster::Math3D::ScalingMatrix(this->RBscale); + Oyster::Math3D::Float4x4 world = translation * rot * scale; + + return world; +} +void C_Object::setRBPos(Oyster::Math::Float3 newPos) +{ + this->RBposition = newPos; +} +Oyster::Math::Float3 C_Object::getRBPos() const +{ + return this->RBposition; +} +void C_Object::setRBRot(Oyster::Math::Quaternion newRot) +{ + this->RBrotation = newRot; +} +Oyster::Math::Quaternion C_Object::getRBRotation() const +{ + return this->RBrotation; +} +void C_Object::setRBScale(Oyster::Math::Float3 newScale) +{ + this->RBscale = newScale; +} +Oyster::Math::Float3 C_Object::getRBScale() const +{ + return this->RBscale; +} +RB_Type C_Object::getBRtype()const +{ + return this->type; +} +// !RB DEBUG \ No newline at end of file diff --git a/Code/Game/GameClient/GameClientState/C_Object.h b/Code/Game/GameClient/GameClientState/C_Object.h index 20e0eb60..dcc2731c 100644 --- a/Code/Game/GameClient/GameClientState/C_Object.h +++ b/Code/Game/GameClient/GameClientState/C_Object.h @@ -5,6 +5,21 @@ namespace DanBias { namespace Client { + // RB DEBUG + enum RB_Type + { + RB_Type_Cube, + RB_Type_Sphere, + RB_Type_None, + }; + struct RBInitData + { + Oyster::Math::Float3 position; + Oyster::Math::Quaternion rotation; + Oyster::Math::Float3 scale; + RB_Type type; + }; + // !RB DEBUG struct ModelInitData { @@ -23,28 +38,46 @@ namespace DanBias Oyster::Math::Float3 position; Oyster::Math::Quaternion rotation; Oyster::Math::Float3 scale; - + + // RB DEBUG + Oyster::Math::Float3 RBposition; + Oyster::Math::Quaternion RBrotation; + Oyster::Math::Float3 RBscale; + RB_Type type; + // !RB DEBUG + int id; - void updateWorld(); + protected: Oyster::Graphics::Model::Model *model; public: C_Object(); virtual ~C_Object(); virtual bool Init(ModelInitData modelInit); - - void setWorld(Oyster::Math::Float4x4 world); + void updateWorld(); + //void setWorld(Oyster::Math::Float4x4 world); Oyster::Math::Float4x4 getWorld() const; void setPos(Oyster::Math::Float3 newPos); Oyster::Math::Float3 getPos() const; void addPos(Oyster::Math::Float3 deltaPos); void setRot(Oyster::Math::Quaternion newRot); Oyster::Math::Quaternion getRotation() const; - void addRot(Oyster::Math::Quaternion deltaRot); void setScale(Oyster::Math::Float3 newScale); void addScale(Oyster::Math::Float3 deltaScale); Oyster::Math::Float3 getScale() const; + // RB DEBUG + bool InitRB(RBInitData modelInit); + Oyster::Math::Float4x4 getRBWorld() const; + void setRBPos(Oyster::Math::Float3 newPos); + Oyster::Math::Float3 getRBPos() const; + void setRBRot(Oyster::Math::Quaternion newRot); + Oyster::Math::Quaternion getRBRotation() const; + void setRBScale(Oyster::Math::Float3 newScale); + Oyster::Math::Float3 getRBScale() const; + RB_Type getBRtype()const; + // !RB DEBUG + virtual void Render(); virtual void Release(); virtual int GetId() const; diff --git a/Code/Game/GameClient/GameClientState/Camera_FPSV2.cpp b/Code/Game/GameClient/GameClientState/Camera_FPSV2.cpp index 12506d3c..f2f3c1ad 100644 --- a/Code/Game/GameClient/GameClientState/Camera_FPSV2.cpp +++ b/Code/Game/GameClient/GameClientState/Camera_FPSV2.cpp @@ -10,6 +10,7 @@ Camera_FPSV2::Camera_FPSV2() this->headOffset = this->body.translation = Float3::null; this->body.rotation = Quaternion::identity; + this->pitchHaveChanged = false; } Camera_FPSV2::~Camera_FPSV2() {} @@ -21,6 +22,7 @@ Camera_FPSV2 & Camera_FPSV2::operator = ( const Camera_FPSV2 &camera ) this->headOffset = camera.headOffset; this->body.translation = camera.body.translation; this->body.rotation = camera.body.rotation; + this->pitchHaveChanged = camera.pitchHaveChanged; return *this; } @@ -38,8 +40,14 @@ void Camera_FPSV2::SetPosition( const Float3 &translation ) void Camera_FPSV2::SetRotation( const Quaternion &rotation ) { + if( !Within(rotation.GetNorm(), .99f, 1.01f) ) + { // HACK: bug trap + const char *breakPoint = "Caught an invalid rotation!"; + } + this->body.rotation = rotation; - this->head.SetRotation( rotation * Rotation(this->pitchUp, this->GetNormalOf(Float3::standard_unit_x) ) ); + this->head.SetRotation( rotation * Rotation(this->pitchUp, WorldAxisOf(rotation, Float3::standard_unit_x) ) ); + this->pitchHaveChanged = false; } void Camera_FPSV2::SetAngular( const Float3 &axis ) @@ -64,6 +72,12 @@ void Camera_FPSV2::SetPerspectiveProjection( Float verticalFoV, Float aspectRati void Camera_FPSV2::UpdateOrientation() { + if( this->pitchHaveChanged ) + { + this->head.SetRotation( this->body.rotation * Rotation(this->pitchUp, WorldAxisOf(this->body.rotation, Float3::standard_unit_x) ) ); + this->pitchHaveChanged = false; + } + Float4x4 orientation; OrientationMatrix( this->body.rotation, this->body.translation, orientation ); @@ -73,7 +87,8 @@ void Camera_FPSV2::UpdateOrientation() void Camera_FPSV2::SnapUpToNormal( const Float3 &normal ) { this->body.rotation = Rotation( SnapAngularAxis(AngularAxis(this->body.rotation), WorldAxisOf(this->body.rotation, Float3::standard_unit_y), normal) ); - this->head.SetRotation( this->body.rotation * Rotation(this->pitchUp * Float3::standard_unit_x) ); + this->head.SetRotation( this->body.rotation * Rotation(this->pitchUp, WorldAxisOf(this->body.rotation, Float3::standard_unit_x) ) ); + this->pitchHaveChanged = false; } void Camera_FPSV2::Move( const Float3 &deltaPosition ) @@ -84,8 +99,8 @@ void Camera_FPSV2::Move( const Float3 &deltaPosition ) void Camera_FPSV2::Rotate( const Quaternion &deltaRotation ) { - this->head.Rotate( deltaRotation ); this->body.rotation *= deltaRotation; + this->pitchHaveChanged = true; } void Camera_FPSV2::Rotate( const Float3 &deltaAngularAxis ) @@ -116,7 +131,7 @@ void Camera_FPSV2::StrafeLeft( Float distance ) void Camera_FPSV2::PitchUp( Float radian ) { this->pitchUp = Clamp( this->pitchUp + radian, -0.48f * pi, 0.48f * pi ); - this->head.SetRotation( this->body.rotation * Rotation(this->pitchUp, Float3::standard_unit_x) ); + this->pitchHaveChanged = true; } void Camera_FPSV2::PitchDown( Float radian ) @@ -147,6 +162,12 @@ const Float3 & Camera_FPSV2::GetPosition() const Float4x4 & Camera_FPSV2::GetViewMatrix( Float4x4 &targetMem ) const { + if( this->pitchHaveChanged ) + { + this->head.SetRotation( this->body.rotation * Rotation(this->pitchUp, WorldAxisOf(this->body.rotation, Float3::standard_unit_x) ) ); + this->pitchHaveChanged = false; + } + return this->head.GetViewMatrix( targetMem ); } @@ -157,11 +178,23 @@ const Float4x4 & Camera_FPSV2::GetProjectionMatrix() const Float4x4 & Camera_FPSV2::GetViewsProjMatrix( Float4x4 &targetMem ) const { + if( this->pitchHaveChanged ) + { + this->head.SetRotation( this->body.rotation * Rotation(this->pitchUp, WorldAxisOf(this->body.rotation, Float3::standard_unit_x) ) ); + this->pitchHaveChanged = false; + } + return this->head.GetViewsProjMatrix( targetMem ); } Float3 Camera_FPSV2::GetNormalOf( const Float3 &axis ) const { + if( this->pitchHaveChanged ) + { + this->head.SetRotation( this->body.rotation * Rotation(this->pitchUp, WorldAxisOf(this->body.rotation, Float3::standard_unit_x) ) ); + this->pitchHaveChanged = false; + } + return this->head.GetNormalOf( axis ); } @@ -177,6 +210,12 @@ Float3 Camera_FPSV2::GetUp() const Float3 Camera_FPSV2::GetLook() const { + if( this->pitchHaveChanged ) + { + this->head.SetRotation( this->body.rotation * Rotation(this->pitchUp, WorldAxisOf(this->body.rotation, Float3::standard_unit_x) ) ); + this->pitchHaveChanged = false; + } + return this->head.GetNormalOf( -Float3::standard_unit_z ); } diff --git a/Code/Game/GameClient/GameClientState/Camera_FPSV2.h b/Code/Game/GameClient/GameClientState/Camera_FPSV2.h index 7f66b185..210c9707 100644 --- a/Code/Game/GameClient/GameClientState/Camera_FPSV2.h +++ b/Code/Game/GameClient/GameClientState/Camera_FPSV2.h @@ -50,7 +50,7 @@ public: ::Oyster::Math::Float3 GetForward() const; private: - Camera_BasicV2 head; + mutable Camera_BasicV2 head; ::Oyster::Math::Float pitchUp; ::Oyster::Math::Float3 headOffset; struct @@ -58,6 +58,7 @@ private: ::Oyster::Math::Float3 translation; ::Oyster::Math::Quaternion rotation; } body; + mutable bool pitchHaveChanged; }; #endif \ No newline at end of file diff --git a/Code/Game/GameClient/GameClientState/GameClientState.h b/Code/Game/GameClient/GameClientState/GameClientState.h index 9891a16c..d336e196 100644 --- a/Code/Game/GameClient/GameClientState/GameClientState.h +++ b/Code/Game/GameClient/GameClientState/GameClientState.h @@ -35,7 +35,7 @@ namespace DanBias { namespace Client /****************************************************************** * @param message of the event - * @return message or GameClientState::event_processed. + * @return message or a reference to GameClientState::event_processed. ******************************************************************/ virtual const NetEvent & DataRecieved( const NetEvent &message ); }; diff --git a/Code/Game/GameClient/GameClientState/GameState.cpp b/Code/Game/GameClient/GameClientState/GameState.cpp index bfd15532..3d9ced8d 100644 --- a/Code/Game/GameClient/GameClientState/GameState.cpp +++ b/Code/Game/GameClient/GameClientState/GameState.cpp @@ -4,7 +4,7 @@ #include "NetworkClient.h" #include "Camera_FPSV2.h" #include - +#include "C_Light.h" #include "C_obj/C_Player.h" #include "C_obj/C_DynamicObj.h" #include "C_obj/C_StaticObj.h" @@ -28,6 +28,7 @@ struct GameState::MyData ::std::map> *staticObjects; ::std::map> *dynamicObjects; + ::std::map> *lights; bool key_forward; bool key_backward; @@ -36,7 +37,11 @@ struct GameState::MyData bool key_Shoot; bool key_Jump; + // DEGUG KEYS bool key_Reload_Shaders; + bool key_Wireframe_Toggle; + bool renderWhireframe; + // !DEGUG KEYS C_Player player; Camera_FPSV2 camera; @@ -78,15 +83,28 @@ bool GameState::Init( SharedStateContent &shared ) this->privData->input = shared.input; this->privData->staticObjects = &shared.staticObjects; this->privData->dynamicObjects = &shared.dynamicObjects; + this->privData->lights = &shared.lights; Graphics::API::Option gfxOp = Graphics::API::GetOption(); Float aspectRatio = gfxOp.Resolution.x / gfxOp.Resolution.y; - this->privData->camera.SetPerspectiveProjection( Radian(90.0f), aspectRatio, 0.1f, 1000.0f ); + this->privData->camera.SetPerspectiveProjection( Utility::Value::Radian(90.0f), aspectRatio, 0.1f, 1000.0f ); Graphics::API::SetProjection( this->privData->camera.GetProjectionMatrix() ); //tell server ready this->privData->nwClient->Send( Protocol_General_Status(Protocol_General_Status::States_ready) ); + // DEGUG KEYS + this->privData->key_Reload_Shaders = false; + this->privData->key_Wireframe_Toggle = false; + this->privData->renderWhireframe = false; + // !DEGUG KEYS + + auto light = this->privData->lights->begin(); + for( ; light != this->privData->lights->end(); ++light ) + { + light->second->Render(); + } + return true; } @@ -100,10 +118,20 @@ void GameState::InitiatePlayer( int id, const std::string &modelName, const floa StringToWstring( modelName, modelData.modelPath ); modelData.id = id; + // RB DEBUG + RBInitData RBData; + RBData.position = position; + RBData.rotation = ArrayToQuaternion( rotation ); + RBData.scale = scale; + // !RB DEBUG if( isMyPlayer ) { if( this->privData->player.Init(modelData) ) { + // RB DEBUG + this->privData->player.InitRB( RBData ); + // !RB DEBUG + this->privData->myId = id; this->privData->camera.SetPosition( this->privData->player.getPos() ); Float3 offset = Float3( 0.0f ); @@ -117,6 +145,10 @@ void GameState::InitiatePlayer( int id, const std::string &modelName, const floa C_DynamicObj *p = new C_DynamicObj(); if( p->Init(modelData) ) { + // RB DEBUG + this->privData->player.InitRB( RBData ); + // !RB DEBUG + (*this->privData->dynamicObjects)[id] = p; } } @@ -150,6 +182,55 @@ bool GameState::Render() dynamicObject->second->Render(); } + + /*auto light = this->privData->lights->begin(); + for( ; light != this->privData->lights->end(); ++light ) + { + light->second->Render(); + }*/ + + // RB DEBUG render wire frame + //if(this->privData->renderWhireframe) + //{ + // Oyster::Graphics::API::StartRenderWireFrame(); + // + // Oyster::Math3D::Float4x4 translation = Oyster::Math3D::TranslationMatrix(Float3( 0,132, 20)); + // Oyster::Math3D::Float4x4 scale = Oyster::Math3D::ScalingMatrix(Float3( 0.5f, 0.5f, 0.5f)); + // Oyster::Math3D::Float4x4 world = translation * scale; + // Oyster::Graphics::API::RenderDebugCube( world ); + // Oyster::Graphics::API::RenderDebugCube(this->privData->player.getRBWorld()); + // + // staticObject = this->privData->staticObjects->begin(); + // for( ; staticObject != this->privData->staticObjects->end(); ++staticObject ) + // { + // if( staticObject->second->getBRtype() == RB_Type_Cube) + // { + // Oyster::Graphics::API::RenderDebugCube( staticObject->second->getRBWorld()); + // } + // if( staticObject->second->getBRtype() == RB_Type_Sphere) + // { + // Oyster::Graphics::API::RenderDebugSphere( staticObject->second->getRBWorld()); + // } + // } + // + // dynamicObject = this->privData->dynamicObjects->begin(); + // for( ; dynamicObject != this->privData->dynamicObjects->end(); ++dynamicObject ) + // { + // if( dynamicObject->second ) + // { + // if( dynamicObject->second->getBRtype() == RB_Type_Cube) + // { + // Oyster::Graphics::API::RenderDebugCube( dynamicObject->second->getRBWorld()); + // } + // if( dynamicObject->second->getBRtype() == RB_Type_Sphere) + // { + // Oyster::Graphics::API::RenderDebugSphere( dynamicObject->second->getRBWorld()); + // } + // } + // } + //} + // !RB DEBUG + Oyster::Graphics::API::EndFrame(); return true; } @@ -170,8 +251,15 @@ bool GameState::Release() dynamicObject->second = nullptr; } + auto light = this->privData->lights->begin(); + for( ; light != this->privData->lights->end(); ++light ) + { + light->second->Render(); + } + this->privData->staticObjects->clear(); this->privData->dynamicObjects->clear(); + this->privData->lights->clear(); privData = NULL; } @@ -187,7 +275,7 @@ void GameState::ReadKeyInput() { if( this->privData->input->IsKeyPressed(DIK_W) ) { - if(!this->privData->key_forward) + //if(!this->privData->key_forward) { this->privData->nwClient->Send( Protocol_PlayerMovementForward() ); this->privData->key_forward = true; @@ -198,7 +286,7 @@ void GameState::ReadKeyInput() if( this->privData->input->IsKeyPressed(DIK_S) ) { - if( !this->privData->key_backward ) + //if( !this->privData->key_backward ) { this->privData->nwClient->Send( Protocol_PlayerMovementBackward() ); this->privData->key_backward = true; @@ -209,7 +297,7 @@ void GameState::ReadKeyInput() if( this->privData->input->IsKeyPressed(DIK_A) ) { - if( !this->privData->key_strafeLeft ) + //if( !this->privData->key_strafeLeft ) { this->privData->nwClient->Send( Protocol_PlayerMovementLeft() ); this->privData->key_strafeLeft = true; @@ -220,7 +308,7 @@ void GameState::ReadKeyInput() if( this->privData->input->IsKeyPressed(DIK_D) ) { - if( !this->privData->key_strafeRight ) + //if( !this->privData->key_strafeRight ) { this->privData->nwClient->Send( Protocol_PlayerMovementRight() ); this->privData->key_strafeRight = true; @@ -229,28 +317,11 @@ void GameState::ReadKeyInput() else this->privData->key_strafeRight = false; - if( this->privData->input->IsKeyPressed(DIK_R) ) - { - if( !this->privData->key_Reload_Shaders ) - { - //this->privData->nwClient->Send( Protocol_PlayerMovementRight() ); -#ifdef _DEBUG - Graphics::API::ReloadShaders(); -#endif - this->privData->key_Reload_Shaders = true; - } - } - else - this->privData->key_Reload_Shaders = false; - - //send delta mouse movement { - this->privData->camera.YawRight( this->privData->input->GetYaw() * 0.017f ); - this->privData->camera.PitchDown( this->privData->input->GetPitch() * 0.017f ); - this->privData->camera.UpdateOrientation(); - - privData->nwClient->Send( Protocol_PlayerLook(this->privData->camera.GetLook(), this->privData->camera.GetRight()) ); + static const float mouseSensitivity = Radian( 1.0f ); + this->privData->camera.PitchDown( this->privData->input->GetPitch() * mouseSensitivity ); + this->privData->nwClient->Send( Protocol_PlayerLeftTurn(this->privData->input->GetYaw() * mouseSensitivity) ); } // shoot @@ -309,6 +380,35 @@ void GameState::ReadKeyInput() else this->privData->key_Jump = false; + + // DEGUG KEYS + + // Reload shaders + if( this->privData->input->IsKeyPressed(DIK_R) ) + { + if( !this->privData->key_Reload_Shaders ) + { +#ifdef _DEBUG + Graphics::API::ReloadShaders(); +#endif + this->privData->key_Reload_Shaders = true; + } + } + else + this->privData->key_Reload_Shaders = false; + + // toggle wire frame render + if( this->privData->input->IsKeyPressed(DIK_T) ) + { + if( !this->privData->key_Wireframe_Toggle ) + { + this->privData->renderWhireframe = !this->privData->renderWhireframe; + this->privData->key_Wireframe_Toggle = true; + } + } + else + this->privData->key_Wireframe_Toggle = false; + // !DEGUG KEYS // TODO: implement sub-menu } @@ -342,12 +442,18 @@ const GameClientState::NetEvent & GameState::DataRecieved( const GameClientState this->privData->camera.SetPosition( decoded.position ); (*this->privData->dynamicObjects)[decoded.object_ID]->setPos( decoded.position ); + // RB DEBUG + (*this->privData->dynamicObjects)[decoded.object_ID]->setRBPos ( decoded.position ); + // !RB DEBUG } return GameClientState::event_processed; case protocol_Gameplay_ObjectScale: { Protocol_ObjectScale decoded(data); (*this->privData->dynamicObjects)[decoded.object_ID]->setScale( decoded.scale ); + // RB DEBUG + (*this->privData->dynamicObjects)[decoded.object_ID]->setRBScale ( decoded.scale ); + // !RB DEBUG } return GameClientState::event_processed; case protocol_Gameplay_ObjectRotation: @@ -360,6 +466,9 @@ const GameClientState::NetEvent & GameState::DataRecieved( const GameClientState this->privData->camera.SetRotation( rotation ); (*this->privData->dynamicObjects)[decoded.object_ID]->setRot( rotation ); + // RB DEBUG + (*this->privData->dynamicObjects)[decoded.object_ID]->setRBRot ( rotation ); + // !RB DEBUG } return GameClientState::event_processed; case protocol_Gameplay_ObjectPositionRotation: @@ -373,13 +482,20 @@ const GameClientState::NetEvent & GameState::DataRecieved( const GameClientState { this->privData->camera.SetPosition( position ); this->privData->camera.SetRotation( rotation ); + this->privData->player.setPos( position ); + this->privData->player.setRot( rotation ); } C_DynamicObj *object = (*this->privData->dynamicObjects)[decoded.object_ID]; + if( object ) { object->setPos( position ); object->setRot( rotation ); + // RB DEBUG + object->setRBPos ( position ); + object->setRBRot ( rotation ); + // !RB DEBUG } } return GameClientState::event_processed; @@ -404,7 +520,7 @@ const GameClientState::NetEvent & GameState::DataRecieved( const GameClientState ModelInitData modelData; { modelData.position = Float3( decoded.position ); - modelData.rotation = Quaternion( Float3(decoded.rotationQ), decoded.rotationQ[3] ); + modelData.rotation = Quaternion( Float3(decoded.position), decoded.rotationQ[3] ); modelData.scale = Float3( decoded.scale ); modelData.visible = true; modelData.id = decoded.object_ID; @@ -412,6 +528,15 @@ const GameClientState::NetEvent & GameState::DataRecieved( const GameClientState ::Utility::String::StringToWstring( decoded.name, modelData.modelPath ); } object->Init(modelData); + // RB DEBUG + // Is just using the model position since the rigid body data should never be sent to the client + RBInitData RBData; + RBData.position = decoded.position; + RBData.rotation = ArrayToQuaternion( decoded.position ); + RBData.scale = Float3( decoded.scale ); + + this->privData->player.InitRB( RBData ); + // !RB DEBUG (*this->privData->dynamicObjects)[decoded.object_ID] = object; diff --git a/Code/Game/GameClient/GameClientState/GameStateUI.cpp b/Code/Game/GameClient/GameClientState/GameStateUI.cpp new file mode 100644 index 00000000..6b8b7ed5 --- /dev/null +++ b/Code/Game/GameClient/GameClientState/GameStateUI.cpp @@ -0,0 +1,17 @@ +#include "GameStateUI.h" + +using namespace ::DanBias::Client; +using namespace ::Oyster::Network; + +GameStateUI::GameStateUI() +{ + this->nextState = GameStateUI::UIState_same; +} + +GameStateUI::~GameStateUI() { /* Do nothing */ } + +const GameStateUI::NetEvent & GameStateUI::DataRecieved( const GameStateUI::NetEvent &message ) +{ + /* Do nothing */ + return message; +} \ No newline at end of file diff --git a/Code/Game/GameClient/GameClientState/GameStateUI.h b/Code/Game/GameClient/GameClientState/GameStateUI.h new file mode 100644 index 00000000..40350211 --- /dev/null +++ b/Code/Game/GameClient/GameClientState/GameStateUI.h @@ -0,0 +1,58 @@ +#ifndef DANBIAS_CLIENT_GAMECLIENTSTATE_H +#define DANBIAS_CLIENT_GAMECLIENTSTATE_H + +#include "Utilities.h" +#include "NetworkClient.h" + +namespace DanBias { namespace Client +{ + class GameStateUI + { + public: + enum UIState + { + UIState_same, + UIState_gaming, + + + UIState_main_menu, + UIState_shut_down + }; + + typedef ::Oyster::Network::NetEvent<::Oyster::Network::NetworkClient*, ::Oyster::Network::NetworkClient::ClientEventArgs> NetEvent; + static const NetEvent event_processed; + + GameStateUI(); + virtual ~GameStateUI(); + virtual UIState Update( float deltaTime ) = 0; + virtual bool HaveGUIRender() const = 0; + virtual bool HaveTextRender() const = 0; + virtual void RenderGUI() const = 0; + virtual void RenderText() const = 0; + virtual bool Release() = 0; + + /****************************************************************** + * @param message of the event + * @return message or a reference to GameStateUI::event_processed. + ******************************************************************/ + virtual const NetEvent & DataRecieved( const NetEvent &message ); + + protected: + UIState nextState; + }; +} } + +namespace Utility { namespace DynamicMemory +{ // template specializationto allowuse of dynamicmemory tools + template<> + inline void SafeDeleteInstance( ::DanBias::Client::GameStateUI *dynamicInstance ) + { + if( dynamicInstance ) + { + dynamicInstance->Release(); + delete dynamicInstance; + } + } +} } + +#endif \ No newline at end of file diff --git a/Code/Game/GameClient/GameClientState/GamingUI.cpp b/Code/Game/GameClient/GameClientState/GamingUI.cpp new file mode 100644 index 00000000..8ff43d88 --- /dev/null +++ b/Code/Game/GameClient/GameClientState/GamingUI.cpp @@ -0,0 +1,153 @@ +#include "GamingUI.h" +#include +#include "Utilities.h" + +using namespace ::DanBias::Client; +using namespace ::Oyster::Network; +using namespace ::GameLogic; +using namespace ::Utility::Value; + +GamingUI::GamingUI() : + GameStateUI() +{ + /* Should never be called! */ + this->input = nullptr; + this->netClient = nullptr; + this->camera = nullptr; +} + +GamingUI::GamingUI( InputClass *input, NetworkClient *connection, Camera_FPSV2 *camera ) : + GameStateUI() +{ + this->input = input; + this->netClient = connection; + this->camera = camera; +} + +GamingUI::~GamingUI() { /* Do nothing */ } + +GameStateUI::UIState GamingUI::Update( float deltaTime ) +{ + return this->nextState; +} + +bool GamingUI::HaveGUIRender() const +{ + return false; // TODO: change to true when we want UI elements like a crosshair +} + +bool GamingUI::HaveTextRender() const +{ + return false; // TODO: change to true when we want UI elements like a chat window +} + +void GamingUI::RenderGUI() const +{ + // TODO: Render crosshairs and such here. Don't forget to adjust GamingUI::HaveGUIRender +} + +void GamingUI::RenderText() const +{ + // TODO: Render chattext and such here. Don't forget to adjust GamingUI::HaveGUIRender +} + +bool GamingUI::Release() +{ + // TODO: Release UI components here. + return true; +} + +void GamingUI::ReadKeyInput() +{ + if( this->input->IsKeyPressed(DIK_W) ) + { + this->netClient->Send( Protocol_PlayerMovementForward() ); + } + + if( this->input->IsKeyPressed(DIK_S) ) + { + this->netClient->Send( Protocol_PlayerMovementBackward() ); + } + + if( this->input->IsKeyPressed(DIK_A) ) + { + this->netClient->Send( Protocol_PlayerMovementLeft() ); + } + + if( this->input->IsKeyPressed(DIK_D) ) + { + this->netClient->Send( Protocol_PlayerMovementRight() ); + } + +// if( this->input->IsKeyPressed(DIK_R) ) +// { +// if( !this->key_Reload_Shaders ) +// { +//#ifdef _DEBUG +// Graphics::API::ReloadShaders(); +//#endif +// this->key_Reload_Shaders = true; +// } +// } +// else +// this->key_Reload_Shaders = false; + + //send delta mouse movement + { + static const float mouseSensitivity = Radian( 1.0f ); + this->camera->PitchDown( this->input->GetPitch() * mouseSensitivity ); + this->netClient->Send( Protocol_PlayerLeftTurn(this->input->GetYaw() * mouseSensitivity) ); + } + + // shoot + //if( this->input->IsKeyPressed(DIK_Z) ) + //{ + // if( !this->key_Shoot ) + // { + // Protocol_PlayerShot playerShot; + // playerShot.primaryPressed = true; + // playerShot.secondaryPressed = false; + // playerShot.utilityPressed = false; + // this->netClient->Send( playerShot ); + // this->key_Shoot = true; + // } + //} + //else + // this->key_Shoot = false; + + //if( this->input->IsKeyPressed(DIK_X) ) + //{ + // if( !this->key_Shoot ) + // { + // Protocol_PlayerShot playerShot; + // playerShot.primaryPressed = false; + // playerShot.secondaryPressed = true; + // playerShot.utilityPressed = false; + // this->netClient->Send( playerShot ); + // this->key_Shoot = true; + // } + //} + //else + // this->key_Shoot = false; + + //if( this->input->IsKeyPressed(DIK_C) ) + //{ + // if( !this->key_Shoot ) + // { + // Protocol_PlayerShot playerShot; + // playerShot.primaryPressed = false; + // playerShot.secondaryPressed = false; + // playerShot.utilityPressed = true; + // this->netClient->Send( playerShot ); + // this->key_Shoot = true; + // } + //} + //else + // this->key_Shoot = false; + + // jump + if( this->input->IsKeyPressed(DIK_SPACE) ) + { + this->netClient->Send( Protocol_PlayerJump() ); + } +} \ No newline at end of file diff --git a/Code/Game/GameClient/GameClientState/GamingUI.h b/Code/Game/GameClient/GameClientState/GamingUI.h new file mode 100644 index 00000000..9f93674b --- /dev/null +++ b/Code/Game/GameClient/GameClientState/GamingUI.h @@ -0,0 +1,33 @@ +#ifndef DANBIAS_CLIENT_GAMING_UI_H +#define DANBIAS_CLIENT_GAMING_UI_H + +#include "GameStateUI.h" +#include "L_inputClass.h" +#include "Camera_FPSV2.h" + +namespace DanBias { namespace Client +{ + class GamingUI : public GameStateUI + { + public: + GamingUI( InputClass *input, ::Oyster::Network::NetworkClient *connection, Camera_FPSV2 *camera ); + virtual ~GamingUI(); + + UIState Update( float deltaTime ); + bool HaveGUIRender() const; + bool HaveTextRender() const; + void RenderGUI() const; + void RenderText() const; + bool Release(); + + private: + InputClass *input; + ::Oyster::Network::NetworkClient *netClient; + Camera_FPSV2 *camera; + + GamingUI(); + void ReadKeyInput(); + }; +} } + +#endif \ No newline at end of file diff --git a/Code/Game/GameClient/GameClientState/LevelLoader/LevelParser.cpp b/Code/Game/GameClient/GameClientState/LevelLoader/LevelParser.cpp deleted file mode 100644 index 39d2f625..00000000 --- a/Code/Game/GameClient/GameClientState/LevelLoader/LevelParser.cpp +++ /dev/null @@ -1,317 +0,0 @@ -///////////////////////////////////// -// Created by Pontus Fransson 2013 // -///////////////////////////////////// - -#include "LevelParser.h" - -#include "Loader.h" -#include "ParseFunctions.h" - -using namespace GameLogic; -using namespace ::LevelFileLoader; -using namespace Utility::DynamicMemory; - -LevelParser::LevelParser() -{ - formatVersion.formatVersionMajor = 3; - formatVersion.formatVersionMinor = 0; -} - -LevelParser::~LevelParser() -{ -} - -std::vector> LevelParser::Parse(std::string filename) -{ - int bufferSize = 0; - int counter = 0; - bool loadCgf; - - std::vector> objects; - - //Read entire level file. - Loader loader; - char* buffer = (char*)loader.LoadFile(filename.c_str(), bufferSize); - - //Read format version - LevelLoaderInternal::FormatVersion levelFormatVersion; - ParseObject(&buffer[counter], &levelFormatVersion, sizeof(levelFormatVersion)); - counter += sizeof(levelFormatVersion); - if(this->formatVersion != levelFormatVersion) - { - //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)); - switch((int)typeID) - { - case ObjectType_LevelMetaData: - { - SmartPointer header = new LevelMetaData; - ParseLevelMetaData(&buffer[counter], *(LevelMetaData*)header.Get(), counter); - objects.push_back(header); - break; - } - - case ObjectType_SpawnPoint: - { - loadCgf = false; - ObjectHeader* header = new ObjectHeader; - ParseObject(&buffer[counter], *header, counter, loadCgf); - - SpawnPointAttributes* spawn = new SpawnPointAttributes; - - spawn->typeID = header->typeID; - - for(int i = 0; i < 3; i++) - { - spawn->position[i] = header->position[i]; - } - - delete header; - //objects.push_back(header); - objects.push_back(spawn); - break; - } - - //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: - { - //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; - } - //this is a hotfix, fix so you only load the relevant data when the file is updated - - - default: - //Couldn't find specialType - break; - } - break; - } - - case ObjectType_Light: - { - LightType lightType; - - //Get Light type - ParseObject(&buffer[counter+4], &lightType, sizeof(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: - { - PointLight* header = new PointLight; - ParseObject(&buffer[counter], header, sizeof(*header)); - counter += sizeof(*header); - objects.push_back(header); - break; - } - case LightType_DirectionalLight: - { - DirectionalLight* header = new DirectionalLight; - ParseObject(&buffer[counter], header, sizeof(*header)); - counter += sizeof(*header); - objects.push_back(header); - break; - } - case LightType_SpotLight: - { - SpotLight* header = new SpotLight; - ParseObject(&buffer[counter], header, sizeof(*header)); - counter += sizeof(*header); - objects.push_back(header); - break; - } - default: - //Undefined LightType. - break; - } - break;*/ - } - default: - //Couldn't find typeID. FAIL!!!!!! - break; - } - } - - return objects; -} - -//för meta information om leveln. -LevelMetaData LevelParser::ParseHeader(std::string filename) -{ - int bufferSize = 0; - int counter = 0; - - LevelMetaData levelHeader; - levelHeader.typeID = ObjectType::ObjectType_Unknown; - - //Read entire level file. - Loader loader; - char* buffer = (char*)loader.LoadFile(filename.c_str(), bufferSize); - - //Read format version - 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) - { - ObjectType typeID; - ParseObject(&buffer[counter], &typeID, sizeof(typeID)); - - switch(typeID) - { - case ObjectType_LevelMetaData: - ParseLevelMetaData(&buffer[counter], levelHeader, counter); - return levelHeader; - break; - - //This is by design, static and dynamic is using the same converter. Do not add anything inbetween them. - case ObjectType_Static: case ObjectType_Dynamic: - { - ObjectHeader header; - ParseObject(&buffer[counter], &header, counter); - - switch(header.specialTypeID) - { - case ObjectSpecialType_JumpPad: - counter += sizeof(16); - break; - case ObjectSpecialType_Portal: - counter += sizeof(12); - break; - default: - break; - } - break; - } - - case ObjectType_Light: - { - LightType lightType; - ParseObject(&buffer[counter+4], &lightType, sizeof(lightType)); - - //We only support pointlight for now. - counter += sizeof(BasicLight); - /* - switch(lightType) - { - case LightType_PointLight: - { - counter += sizeof(PointLight); - break; - } - case LightType_DirectionalLight: - { - counter += sizeof(DirectionalLight); - break; - } - case LightType_SpotLight: - { - counter += sizeof(SpotLight); - break; - } - default: - //Undefined LightType. - break; - }*/ - } - - default: - //Couldn't find typeID. FAIL!!!!!! - break; - } - } - - return levelHeader; -} \ No newline at end of file diff --git a/Code/Game/GameClient/GameClientState/NetLoadState.cpp b/Code/Game/GameClient/GameClientState/NetLoadState.cpp index 29906d77..b2475cc6 100644 --- a/Code/Game/GameClient/GameClientState/NetLoadState.cpp +++ b/Code/Game/GameClient/GameClientState/NetLoadState.cpp @@ -2,10 +2,11 @@ #include "NetworkClient.h" #include "OysterMath.h" #include "Protocols.h" -#include "LevelLoader\LevelLoader.h" +#include "LevelLoader.h" #include "Utilities.h" #include "C_obj\C_StaticObj.h" #include "C_obj\C_DynamicObj.h" +#include "C_Light.h" using namespace ::DanBias::Client; using namespace ::Oyster; @@ -23,6 +24,7 @@ struct NetLoadState::MyData Graphics::API::Texture background; ::std::map> *staticObjects; ::std::map> *dynamicObjects; + ::std::map> *lights; bool loading; }; @@ -49,6 +51,7 @@ bool NetLoadState::Init( SharedStateContent &shared ) this->privData->background = Graphics::API::CreateTexture( L"grass_md.png" ); this->privData->dynamicObjects = &shared.dynamicObjects; this->privData->staticObjects = &shared.staticObjects; + this->privData->lights = &shared.lights; this->privData->loading = false; @@ -140,10 +143,32 @@ void NetLoadState::LoadGame( const ::std::string &fileName ) desc.rotation = ArrayToQuaternion( oh->rotation ); desc.scale = oh->scale; desc.visible = true; - + C_StaticObj *staticObject = new C_StaticObj(); if( staticObject->Init( desc ) ) { + + // RB DEBUG + RBInitData RBData; + if(oh->boundingVolume.geoType == CollisionGeometryType_Box) + { + RBData.position = (Float3)oh->position + (Float3)oh->boundingVolume.box.position; + RBData.rotation = ArrayToQuaternion( oh->rotation ); // Only model rotation + RBData.scale = (Float3)oh->scale * (Float3)oh->boundingVolume.box.size; + RBData.type = RB_Type_Cube; + staticObject->InitRB( RBData ); + } + + if(oh->boundingVolume.geoType == CollisionGeometryType_Sphere) + { + RBData.position = (Float3)oh->position + (Float3)oh->boundingVolume.sphere.position; + RBData.rotation = ArrayToQuaternion( oh->rotation ); // Only model rotation + RBData.scale = (Float3)oh->scale * oh->boundingVolume.sphere.radius; + RBData.type = RB_Type_Sphere; + staticObject->InitRB( RBData ); + } + // !RB DEBUG + (*this->privData->staticObjects)[objectID] = staticObject; } else @@ -167,6 +192,27 @@ void NetLoadState::LoadGame( const ::std::string &fileName ) C_DynamicObj *dynamicObject = new C_DynamicObj(); if( dynamicObject->Init( desc ) ) { + // RB DEBUG + RBInitData RBData; + if(oh->boundingVolume.geoType == CollisionGeometryType_Box) + { + RBData.position = (Float3)oh->position + (Float3)oh->boundingVolume.box.position; + RBData.rotation = ArrayToQuaternion( oh->rotation ); // Only model rotation + RBData.scale = (Float3)oh->scale * (Float3)oh->boundingVolume.box.size; + RBData.type = RB_Type_Cube; + dynamicObject->InitRB( RBData ); + } + + if(oh->boundingVolume.geoType == CollisionGeometryType_Sphere) + { + RBData.position = (Float3)oh->position + (Float3)oh->boundingVolume.sphere.position; + RBData.rotation = ArrayToQuaternion( oh->rotation ); // Only model rotation + RBData.scale = (Float3)oh->scale * oh->boundingVolume.sphere.radius; + RBData.type = RB_Type_Sphere; + dynamicObject->InitRB( RBData ); + } + // !RB DEBUG + (*this->privData->dynamicObjects)[objectID] = dynamicObject; } else @@ -177,7 +223,17 @@ void NetLoadState::LoadGame( const ::std::string &fileName ) break; case ObjectType::ObjectType_Light: { - /* TODO: implement light into the leveformat */ + BasicLight *light = (BasicLight*)oth; + Graphics::Definitions::Pointlight pointLight; + + pointLight.Color = light->color; + pointLight.Pos = light->position; + pointLight.Bright = light->intensity; + pointLight.Radius = light->raduis; + + C_Light *newLight = new C_Light( pointLight, objectID ); + + (*this->privData->lights)[objectID] = newLight; } break; default: break; diff --git a/Code/Game/GameClient/GameClientState/RespawnUI.cpp b/Code/Game/GameClient/GameClientState/RespawnUI.cpp new file mode 100644 index 00000000..4588d367 --- /dev/null +++ b/Code/Game/GameClient/GameClientState/RespawnUI.cpp @@ -0,0 +1,58 @@ +#include "RespawnUI.h" + +using namespace ::DanBias::Client; +using namespace ::Oyster::Network; +using namespace ::Utility::Value; + +RespawnUI::RespawnUI() : + GameStateUI() +{ + /* Should never be called! */ + this->netClient = nullptr; + this->countDown = 0.0f; +} + +RespawnUI::RespawnUI( NetworkClient *connection, float delay ) : + GameStateUI() +{ + this->netClient = connection; + this->countDown = delay; +} + +RespawnUI::~RespawnUI() { /* Do nothing */ } + +GameStateUI::UIState RespawnUI::Update( float deltaTime ) +{ + this->countDown = Max( this->countDown - deltaTime, 0.0f ); + return this->nextState; +} + +bool RespawnUI::HaveGUIRender() const +{ + return false; // TODO: change to true when we want UI elements like a crosshair +} + +bool RespawnUI::HaveTextRender() const +{ + return false; // TODO: change to true when we want UI elements like a chat window +} + +void RespawnUI::RenderGUI() const +{ + // TODO: We need? +} + +void RespawnUI::RenderText() const +{ + // TODO: Text countdown somewhere on screen would be nice +} + +bool RespawnUI::Release() +{ + // TODO: Release UI components here. + return true; +} + + + + diff --git a/Code/Game/GameClient/GameClientState/RespawnUI.h b/Code/Game/GameClient/GameClientState/RespawnUI.h new file mode 100644 index 00000000..c45616b7 --- /dev/null +++ b/Code/Game/GameClient/GameClientState/RespawnUI.h @@ -0,0 +1,29 @@ +#ifndef DANBIAS_CLIENT_RESPAWN_UI_H +#define DANBIAS_CLIENT_RESPAWN_UI_H + +#include "GameStateUI.h" + +namespace DanBias { namespace Client +{ + class RespawnUI : public GameStateUI + { + public: + RespawnUI( ::Oyster::Network::NetworkClient *connection, float delay ); + virtual ~RespawnUI(); + + UIState Update( float deltaTime ); + bool HaveGUIRender() const; + bool HaveTextRender() const; + void RenderGUI() const; + void RenderText() const; + bool Release(); + + private: + ::Oyster::Network::NetworkClient *netClient; + float countDown; + + RespawnUI(); + }; +} } + +#endif \ No newline at end of file diff --git a/Code/Game/GameClient/GameClientState/SharedStateContent.h b/Code/Game/GameClient/GameClientState/SharedStateContent.h index da9dc759..49d01775 100644 --- a/Code/Game/GameClient/GameClientState/SharedStateContent.h +++ b/Code/Game/GameClient/GameClientState/SharedStateContent.h @@ -13,6 +13,7 @@ #include "C_Object.h" #include "C_obj\C_StaticObj.h" #include "C_obj\C_DynamicObj.h" +#include "C_Light.h" #include "NetworkClient.h" #include "L_inputClass.h" @@ -23,6 +24,7 @@ namespace DanBias { namespace Client public: ::std::map> staticObjects; ::std::map> dynamicObjects; + ::std::map> lights; ::Oyster::Network::NetworkClient *network; InputClass* input; }; diff --git a/Code/Game/GameLogic/CollisionManager.cpp b/Code/Game/GameLogic/CollisionManager.cpp index 5d1a95ec..4c21fc8a 100644 --- a/Code/Game/GameLogic/CollisionManager.cpp +++ b/Code/Game/GameLogic/CollisionManager.cpp @@ -23,7 +23,7 @@ using namespace GameLogic; void Player::PlayerCollision(Oyster::Physics::ICustomBody *rigidBodyPlayer, Oyster::Physics::ICustomBody *obj, Oyster::Math::Float kineticEnergyLoss) { - Player *player = ((Game::PlayerData*)(rigidBodyPlayer->GetCustomTag()))->player; + Player *player = ((Player*)(rigidBodyPlayer->GetCustomTag())); Object *realObj = (Object*)obj->GetCustomTag(); //needs to be changed? switch (realObj->GetObjectType()) @@ -46,7 +46,7 @@ using namespace GameLogic; break; case ObjectSpecialType::ObjectSpecialType_CrystalFormation: - PlayerVLethalObject(*player,*realObj, kineticEnergyLoss,realObj->getExtraDamageOnCollision()); + PlayerVLethalObject(*player,*realObj, kineticEnergyLoss,realObj->GetExtraDamageOnCollision()); //player->playerState = PLAYER_STATE::PLAYER_STATE_WALKING; break; } @@ -181,7 +181,7 @@ using namespace GameLogic; } } - Oyster::Physics::ICustomBody::SubscriptMessage Object::DefaultCollisionAfter(Oyster::Physics::ICustomBody *rigidBodyLevel, Oyster::Physics::ICustomBody *obj, Oyster::Math::Float kineticEnergyLoss) + Oyster::Physics::ICustomBody::SubscriptMessage Object::DefaultOnCollision(Oyster::Physics::ICustomBody *rigidBodyObject, Oyster::Physics::ICustomBody *obj, Oyster::Math::Float kineticEnergyLoss) { return Physics::ICustomBody::SubscriptMessage_none; } diff --git a/Code/Game/GameLogic/Game.cpp b/Code/Game/GameLogic/Game.cpp index fc5567f0..9edd2e86 100644 --- a/Code/Game/GameLogic/Game.cpp +++ b/Code/Game/GameLogic/Game.cpp @@ -68,13 +68,33 @@ void Game::GetAllPlayerPositions() const Game::PlayerData* Game::CreatePlayer() { // Find a free space in array or insert at end - - PlayerData *temp = new PlayerData(); - temp->player->GetRigidBody()->SetSubscription(Game::PhysicsOnMove); + int insert = InsertObject(this->players, (PlayerData*)0); + int freeID = 0; + bool found = false; - int i = InsertObject(this->players, temp); + for(int i = 0; i < 100; i++) + { + found = true; + freeID = i; - return temp; + for(int j = 0; j < players.Size(); j++) + { + + if(this->players[j] && this->players[j]->GetID() == freeID) + { + found = false; + } + + if(!found) break; + } + + if(found) break; + } + + this->players[insert] = new PlayerData(freeID, 0); // user constructor with objectID and teamID + this->players[insert]->player->GetRigidBody()->SetSubscription(Game::PhysicsOnMove); + + return this->players[insert]; } Game::LevelData* Game::CreateLevel(const wchar_t mapName[255]) diff --git a/Code/Game/GameLogic/Game.h b/Code/Game/GameLogic/Game.h index 6623756f..5ab19ba2 100644 --- a/Code/Game/GameLogic/Game.h +++ b/Code/Game/GameLogic/Game.h @@ -31,17 +31,18 @@ namespace GameLogic PlayerData(int playerID,int teamID); ~PlayerData(); - void Move(const PLAYER_MOVEMENT &movement) override; - void UseWeapon(const WEAPON_FIRE &usage) override; - int GetTeamID() const override; - PLAYER_STATE GetState() const override; - Oyster::Math::Float3 GetPosition() override; - Oyster::Math::Quaternion GetRotation() override; - Oyster::Math::Float3 GetScale() override; - Oyster::Math::Float4x4 GetOrientation() override; - int GetID() const override; - void Rotate(const Oyster::Math3D::Float3 lookDir, const Oyster::Math3D::Float3 right) override; - ObjectSpecialType GetObjectType() const override; + void Move(const PLAYER_MOVEMENT &movement) override; + void UseWeapon(const WEAPON_FIRE &usage) override; + int GetTeamID() const override; + PLAYER_STATE GetState() const override; + Oyster::Math::Float3 GetPosition() override; + Oyster::Math::Quaternion GetRotation() override; + Oyster::Math::Float3 GetScale() override; + Oyster::Math::Float4x4 GetOrientation() override; + int GetID() const override; + void Rotate(const Oyster::Math3D::Float3& lookDir, const Oyster::Math3D::Float3& right) override; + void TurnLeft(Oyster::Math3D::Float deltaLeftRadians ) override; + ObjectSpecialType GetObjectType() const override; diff --git a/Code/Game/GameLogic/GameAPI.h b/Code/Game/GameLogic/GameAPI.h index 65d606d8..66cf5ea2 100644 --- a/Code/Game/GameLogic/GameAPI.h +++ b/Code/Game/GameLogic/GameAPI.h @@ -12,7 +12,7 @@ #include "GameLogicDef.h" #include "GameLogicStates.h" #include -#include "LevelLoader\ObjectDefines.h" +#include "..\LevelLoader\ObjectDefines.h" #include "DynamicArray.h" @@ -85,7 +85,12 @@ namespace GameLogic * @param x: The relative x axis * @param y: The relative y axis **/ - virtual void Rotate(const Oyster::Math3D::Float3 lookDir, const Oyster::Math3D::Float3 right) = 0; + virtual void Rotate(const Oyster::Math3D::Float3& lookDir, const Oyster::Math3D::Float3& right) = 0; + + /** Relative rotation around given axis + * @param leftRadians: The relative amount of radians to turn + **/ + virtual void TurnLeft(Oyster::Math3D::Float deltaLeftRadians ) = 0; /******************************************************** * Uses the chosen players weapon based on input diff --git a/Code/Game/GameLogic/GameLogic.vcxproj b/Code/Game/GameLogic/GameLogic.vcxproj index ad129c3b..52b7722b 100644 --- a/Code/Game/GameLogic/GameLogic.vcxproj +++ b/Code/Game/GameLogic/GameLogic.vcxproj @@ -99,7 +99,7 @@ Level3 Disabled true - $(SolutionDir)Misc\Utilities;$(SolutionDir)Misc\OysterMath;$(SolutionDir)Physics\OysterPhysics3D;$(SolutionDir)Physics\GamePhysics;%(AdditionalIncludeDirectories) + $(SolutionDir)Misc\Utilities;$(SolutionDir)Misc\OysterMath;$(SolutionDir)Physics\OysterPhysics3D;$(SolutionDir)Physics\GamePhysics;$(SolutionDir)Game\LevelLoader DANBIAS_GAMELOGIC_DLL_EXPORT;_WINDLL;%(PreprocessorDefinitions) @@ -113,7 +113,7 @@ Level3 Disabled true - $(SolutionDir)Misc\Utilities;$(SolutionDir)Misc\OysterMath;$(SolutionDir)Physics\OysterPhysics3D;$(SolutionDir)Physics\GamePhysics;%(AdditionalIncludeDirectories) + $(SolutionDir)Misc\Utilities;$(SolutionDir)Misc\OysterMath;$(SolutionDir)Physics\OysterPhysics3D;$(SolutionDir)Physics\GamePhysics;$(SolutionDir)Game\LevelLoader DANBIAS_GAMELOGIC_DLL_EXPORT;_WINDLL;%(PreprocessorDefinitions) @@ -129,7 +129,7 @@ true true true - $(SolutionDir)Misc\Utilities;$(SolutionDir)Misc\OysterMath;$(SolutionDir)Physics\OysterPhysics3D;$(SolutionDir)Physics\GamePhysics;%(AdditionalIncludeDirectories) + $(SolutionDir)Misc\Utilities;$(SolutionDir)Misc\OysterMath;$(SolutionDir)Physics\OysterPhysics3D;$(SolutionDir)Physics\GamePhysics;$(SolutionDir)Game\LevelLoader DANBIAS_GAMELOGIC_DLL_EXPORT;_WINDLL;%(PreprocessorDefinitions) @@ -147,7 +147,7 @@ true true true - $(SolutionDir)Misc\Utilities;$(SolutionDir)Misc\OysterMath;$(SolutionDir)Physics\OysterPhysics3D;$(SolutionDir)Physics\GamePhysics;%(AdditionalIncludeDirectories) + $(SolutionDir)Misc\Utilities;$(SolutionDir)Misc\OysterMath;$(SolutionDir)Physics\OysterPhysics3D;$(SolutionDir)Physics\GamePhysics;$(SolutionDir)Game\LevelLoader DANBIAS_GAMELOGIC_DLL_EXPORT;_WINDLL;%(PreprocessorDefinitions) @@ -172,12 +172,7 @@ - - - - - @@ -198,11 +193,7 @@ - - - - @@ -223,6 +214,9 @@ {3ea5f14d-2a71-4588-a69d-87c4571c580f} + + {6391e709-d9fa-4fef-a3b9-4343db5a0c63} + diff --git a/Code/Game/GameLogic/GameLogic.vcxproj.user b/Code/Game/GameLogic/GameLogic.vcxproj.user index 4b847ee6..2e28d6f7 100644 --- a/Code/Game/GameLogic/GameLogic.vcxproj.user +++ b/Code/Game/GameLogic/GameLogic.vcxproj.user @@ -1,7 +1,7 @@ ďťż - false + true $(OutDir) diff --git a/Code/Game/GameLogic/Game_PlayerData.cpp b/Code/Game/GameLogic/Game_PlayerData.cpp index f34cf95f..8b3daae2 100644 --- a/Code/Game/GameLogic/Game_PlayerData.cpp +++ b/Code/Game/GameLogic/Game_PlayerData.cpp @@ -85,7 +85,11 @@ ObjectSpecialType Game::PlayerData::GetObjectType() const { return this->player->GetObjectType(); } -void Game::PlayerData::Rotate(const Oyster::Math3D::Float3 lookDir, const Oyster::Math3D::Float3 right) +void Game::PlayerData::Rotate(const Oyster::Math3D::Float3& lookDir, const Oyster::Math3D::Float3& right) { this->player->Rotate(lookDir, right); +} +void Game::PlayerData::TurnLeft(Oyster::Math3D::Float deltaLeftRadians ) +{ + this->player->TurnLeft(deltaLeftRadians); } \ No newline at end of file diff --git a/Code/Game/GameLogic/Level.cpp b/Code/Game/GameLogic/Level.cpp index 4106dabf..b3a8b101 100644 --- a/Code/Game/GameLogic/Level.cpp +++ b/Code/Game/GameLogic/Level.cpp @@ -4,6 +4,10 @@ #include "JumpPad.h" #include "ExplosiveCrate.h" #include "Portal.h" + +//Conversion from wstring to string +#include + using namespace GameLogic; using namespace Utility::DynamicMemory; using namespace Oyster::Physics; @@ -26,14 +30,14 @@ Object* Level::createGameObj(ObjectHeader* obj, ICustomBody* rigidBody) { case ObjectSpecialType_None: { - gameObj = new StaticObject(rigidBody, Object::DefaultCollisionAfter, (ObjectSpecialType)obj->specialTypeID, objID++); + gameObj = new StaticObject(rigidBody, Object::DefaultOnCollision, (ObjectSpecialType)obj->specialTypeID, objID); } break; case ObjectSpecialType_Sky: { float skySize = ((SkyAttributes*)obj)->skySize; - //gameObj = new StaticObject(rigidBody, Object::DefaultCollisionAfter, (ObjectSpecialType)obj->specialTypeID, objID++); + //gameObj = new StaticObject(rigidBody, Object::DefaultOnCollision, (ObjectSpecialType)obj->specialTypeID, objID); } break; case ObjectSpecialType_World: @@ -44,21 +48,21 @@ Object* Level::createGameObj(ObjectHeader* obj, ICustomBody* rigidBody) float worldSize = ((WorldAttributes*)obj)->worldSize; float atmosphereSize = ((WorldAttributes*)obj)->atmoSphereSize; - gameObj = new StaticObject(rigidBody, Object::DefaultCollisionAfter, (ObjectSpecialType)obj->specialTypeID, objID++); + gameObj = new StaticObject(rigidBody, Object::DefaultOnCollision, (ObjectSpecialType)obj->specialTypeID, objID); } break; case ObjectSpecialType_Building: { - gameObj = new StaticObject(rigidBody, Object::DefaultCollisionAfter, (ObjectSpecialType)obj->specialTypeID, objID++); + gameObj = new StaticObject(rigidBody, Object::DefaultOnCollision, (ObjectSpecialType)obj->specialTypeID, objID); } case ObjectSpecialType_Stone: { - gameObj = new DynamicObject(rigidBody, Object::DefaultCollisionAfter, (ObjectSpecialType)obj->specialTypeID, objID++); + gameObj = new DynamicObject(rigidBody, Object::DefaultOnCollision, (ObjectSpecialType)obj->specialTypeID, objID); } break; case ObjectSpecialType_StandardBox: { - gameObj = new DynamicObject(rigidBody, Object::DefaultCollisionAfter, (ObjectSpecialType)obj->specialTypeID, objID++); + gameObj = new DynamicObject(rigidBody, Object::DefaultOnCollision, (ObjectSpecialType)obj->specialTypeID, objID); } break; case ObjectSpecialType_RedExplosiveBox: @@ -75,24 +79,24 @@ Object* Level::createGameObj(ObjectHeader* obj, ICustomBody* rigidBody) // break; case ObjectSpecialType_SpikeBox: { - gameObj = new DynamicObject(rigidBody, Object::DefaultCollisionAfter, (ObjectSpecialType)obj->specialTypeID, objID++); + gameObj = new DynamicObject(rigidBody, Object::DefaultOnCollision, (ObjectSpecialType)obj->specialTypeID, objID); } break; case ObjectSpecialType_Spike: { - gameObj = new DynamicObject(rigidBody, Object::DefaultCollisionAfter, (ObjectSpecialType)obj->specialTypeID, objID++); + gameObj = new DynamicObject(rigidBody, Object::DefaultOnCollision, (ObjectSpecialType)obj->specialTypeID, objID); } break; case ObjectSpecialType_CrystalFormation: { int dmg = 50; //gameObj = new Crystal(rigidBody); - gameObj = new StaticObject(rigidBody, Object::DefaultCollisionAfter, (ObjectSpecialType)obj->specialTypeID, objID++); + gameObj = new StaticObject(rigidBody, Object::DefaultOnCollision, (ObjectSpecialType)obj->specialTypeID, objID); } break; case ObjectSpecialType_CrystalShard: { - gameObj = new DynamicObject(rigidBody, Object::DefaultCollisionAfter, (ObjectSpecialType)obj->specialTypeID, objID++); + gameObj = new DynamicObject(rigidBody, Object::DefaultOnCollision, (ObjectSpecialType)obj->specialTypeID, objID); } break; case ObjectSpecialType_JumpPad: @@ -100,13 +104,13 @@ Object* Level::createGameObj(ObjectHeader* obj, ICustomBody* rigidBody) float power = 500; //((JumpPadAttributes*)obj)->power; Oyster::Math::Float3 dir = ((JumpPadAttributes*)obj)->direction; Oyster::Math::Float3 pushForce = dir * power; - gameObj = new JumpPad(rigidBody, (ObjectSpecialType)obj->specialTypeID, objID++ , pushForce); + gameObj = new JumpPad(rigidBody, (ObjectSpecialType)obj->specialTypeID, objID , pushForce); } break; case ObjectSpecialType_Portal: { Oyster::Math::Float3 destination = ((PortalAttributes*)obj)->destination; - gameObj = new Portal(rigidBody, (ObjectSpecialType)obj->specialTypeID, objID++, destination); + gameObj = new Portal(rigidBody, (ObjectSpecialType)obj->specialTypeID, objID, destination); } break; //case ObjectSpecialType_SpawnPoint: @@ -122,12 +126,12 @@ Object* Level::createGameObj(ObjectHeader* obj, ICustomBody* rigidBody) break; case ObjectSpecialType_Generic: { - gameObj = new StaticObject(rigidBody, Object::DefaultCollisionAfter, (ObjectSpecialType)obj->specialTypeID, objID++); + gameObj = new StaticObject(rigidBody, Object::DefaultOnCollision, (ObjectSpecialType)obj->specialTypeID, objID); } break; default: { - gameObj = new StaticObject(rigidBody, Object::DefaultCollisionAfter, (ObjectSpecialType)obj->specialTypeID, objID++); + gameObj = new StaticObject(rigidBody, Object::DefaultOnCollision, (ObjectSpecialType)obj->specialTypeID, objID); } break; } @@ -200,9 +204,16 @@ ICustomBody* Level::InitRigidBodySphere( const ObjectHeader* obj) bool Level::InitiateLevel(std::wstring levelPath) { LevelLoader ll; - ll.SetFolderPath(L"..\\Content\\Worlds\\"); + ll.SetFolderPath("..\\Content\\Worlds\\"); std::vector> objects; - objects = ll.LoadLevel(levelPath); + + //Convert from wstring to string + typedef std::codecvt_utf8 convert_typeX; + std::wstring_convert converterX; + + std::string convertedLevelPath = converterX.to_bytes(levelPath); + objects = ll.LoadLevel(convertedLevelPath); + if(objects.size() == 0) return false; @@ -213,6 +224,7 @@ bool Level::InitiateLevel(std::wstring levelPath) for (int i = 0; i < objCount; i++) { + ++this->objID; ObjectTypeHeader* obj = objects.at(i); switch (obj->typeID) { @@ -229,39 +241,9 @@ bool Level::InitiateLevel(std::wstring levelPath) staticObjData->ModelFile; ICustomBody* rigidBody_Static = NULL; - if((ObjectSpecialType)staticObjData->specialTypeID == ObjectSpecialType_Sky) - { - - } - if((ObjectSpecialType)staticObjData->specialTypeID == ObjectSpecialType_World) - { - - Oyster::Math::Float3 rigidWorldPos; - Oyster::Math::Float4 rigidWorldRotation; - float rigidBodyMass; - float rigidBodyRadius; - //offset the rigidPosition from modelspace to worldspace; - rigidWorldPos = Oyster::Math::Float3(0,0,0); - //scales the position so the collision geomentry is in the right place - - //offset the rigidRotation from modelspace to worldspace; - - rigidWorldRotation = Oyster::Math::Float4(0,0,0,1); - - - //mass scaled - rigidBodyMass = 100; - - //Radius scaled - rigidBodyRadius = 150; - - //create the rigid body - rigidBody_Static = API::Instance().AddCollisionSphere( rigidBodyRadius , rigidWorldRotation , rigidWorldPos , rigidBodyMass, 1,1,1); - - } // collision shape - else if(staticObjData->boundingVolume.geoType == CollisionGeometryType_Sphere) + if(staticObjData->boundingVolume.geoType == CollisionGeometryType_Sphere) { rigidBody_Static = InitRigidBodySphere(staticObjData); } @@ -360,14 +342,14 @@ bool Level::InitiateLevel(float radius) { rigidBody_TestBox = API::Instance().AddCollisionBox(Oyster::Math::Float3(0.5f, 0.5f, 0.5f), Oyster::Math::Float4(0.0f, 0.0f, 0.0f, 1.0f), Oyster::Math::Float3(0.0f, 605.0f + i*5.0f, 10.0f), 5.0f, 0.5f, 0.8f, 0.6f); - this->dynamicObjects.Push(new DynamicObject(rigidBody_TestBox, Object::DefaultCollisionAfter, ObjectSpecialType_StandardBox, idCount++)); + this->dynamicObjects.Push(new DynamicObject(rigidBody_TestBox, Object::DefaultOnCollision, ObjectSpecialType_StandardBox, idCount++)); } /*offset += nrOfBoxex; for(int i =0; i< nrOfBoxex; i ++) { 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,5, -605 -( i*5)), 5); - this->dynamicObjects.Push(new DynamicObject(rigidBody_TestBox,Object::DefaultCollisionBefore, Object::DefaultCollisionAfter, OBJECT_TYPE::OBJECT_TYPE_BOX)); + this->dynamicObjects.Push(new DynamicObject(rigidBody_TestBox,Object::DefaultCollisionBefore, Object::DefaultOnCollision, OBJECT_TYPE::OBJECT_TYPE_BOX)); rigidBody_TestBox->SetCustomTag(this->dynamicObjects[i+offset]); } @@ -376,7 +358,7 @@ bool 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(200, 620 + ( i*7), 0), 5); - this->dynamicObjects.Push(new DynamicObject(rigidBody_TestBox,Object::DefaultCollisionBefore, Object::DefaultCollisionAfter, OBJECT_TYPE::OBJECT_TYPE_BOX)); + this->dynamicObjects.Push(new DynamicObject(rigidBody_TestBox,Object::DefaultCollisionBefore, Object::DefaultOnCollision, OBJECT_TYPE::OBJECT_TYPE_BOX)); rigidBody_TestBox->SetCustomTag(this->dynamicObjects[i+offset]); } offset += nrOfBoxex; @@ -384,18 +366,18 @@ bool 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(5, 605 + i*5, 0), 5); - this->dynamicObjects.Push(new DynamicObject(rigidBody_TestBox,Object::DefaultCollisionBefore, Object::DefaultCollisionAfter, OBJECT_TYPE::OBJECT_TYPE_BOX)); + this->dynamicObjects.Push(new DynamicObject(rigidBody_TestBox,Object::DefaultCollisionBefore, Object::DefaultOnCollision, OBJECT_TYPE::OBJECT_TYPE_BOX)); rigidBody_TestBox->SetCustomTag(this->dynamicObjects[i]); }*/ // add crystal ICustomBody* rigidBody_Crystal = API::Instance().AddCollisionBox(Oyster::Math::Float3(0.5f, 0.5f, 0.5f), Oyster::Math::Float4(0.0f, 0.0f, 0.0f, 1.0f), Oyster::Math::Float3(10.0f, 605.0f, 0.0f), 5.0f, 0.5f, 0.8f, 0.6f); - this->dynamicObjects.Push(new DynamicObject(rigidBody_Crystal, Object::DefaultCollisionAfter, ObjectSpecialType_StandardBox, idCount++)); + this->dynamicObjects.Push(new DynamicObject(rigidBody_Crystal, Object::DefaultOnCollision, ObjectSpecialType_StandardBox, idCount++)); // add house ICustomBody* rigidBody_House =API::Instance().AddCollisionBox(Oyster::Math::Float3(20.0f, 20.0f, 20.0f), Oyster::Math::Float4(0.0f, 0.0f, 0.0f, 1.0f), Oyster::Math::Float3(-50.0f, 590.0f, 0.0f), 0.0f, 0.5f, 0.8f, 0.6f); - this->staticObjects.Push(new StaticObject(rigidBody_House, Object::DefaultCollisionAfter, ObjectSpecialType_Generic, idCount++)); + this->staticObjects.Push(new StaticObject(rigidBody_House, Object::DefaultOnCollision, ObjectSpecialType_Generic, idCount++)); // add jumppad diff --git a/Code/Game/GameLogic/Level.h b/Code/Game/GameLogic/Level.h index 14269c73..fb26280c 100644 --- a/Code/Game/GameLogic/Level.h +++ b/Code/Game/GameLogic/Level.h @@ -14,7 +14,7 @@ #include "PhysicsAPI.h" #include "TeamManager.h" #include "DynamicArray.h" -#include "LevelLoader/LevelLoader.h" +#include "LevelLoader.h" namespace GameLogic { diff --git a/Code/Game/GameLogic/LevelLoader/LevelLoader.cpp b/Code/Game/GameLogic/LevelLoader/LevelLoader.cpp deleted file mode 100644 index 205da712..00000000 --- a/Code/Game/GameLogic/LevelLoader/LevelLoader.cpp +++ /dev/null @@ -1,52 +0,0 @@ -////////////////////////////////// -// Created by Sam Svensson 2013 // -////////////////////////////////// - -#include "LevelLoader.h" -#include "LevelParser.h" - -using namespace GameLogic; -using namespace GameLogic::LevelFileLoader; - -struct LevelLoader::PrivData -{ - LevelParser parser; - std::wstring folderPath; -}; - -LevelLoader::LevelLoader() - : pData(new PrivData) -{ - //standard path - pData->folderPath = L""; -} - -LevelLoader::LevelLoader(std::wstring folderPath) - : pData(new PrivData) -{ - pData->folderPath = folderPath; -} - -LevelLoader::~LevelLoader() -{ -} - -std::vector> LevelLoader::LoadLevel(std::wstring fileName) -{ - return pData->parser.Parse(pData->folderPath + fileName); -} - -LevelMetaData LevelLoader::LoadLevelHeader(std::wstring fileName) -{ - return pData->parser.ParseHeader(pData->folderPath + fileName); -} - -std::wstring LevelLoader::GetFolderPath() -{ - return this->pData->folderPath; -} - -void LevelLoader::SetFolderPath(std::wstring folderPath) -{ - this->pData->folderPath = folderPath; -} \ No newline at end of file diff --git a/Code/Game/GameLogic/LevelLoader/LevelLoader.h b/Code/Game/GameLogic/LevelLoader/LevelLoader.h deleted file mode 100644 index c14e2c4c..00000000 --- a/Code/Game/GameLogic/LevelLoader/LevelLoader.h +++ /dev/null @@ -1,56 +0,0 @@ -////////////////////////////////// -// Created by Sam Svensson 2013 // -////////////////////////////////// - -#ifndef LEVELLOADER_H -#define LEVELLOADER_H - -#include -#include -#include "Utilities.h" -#include "ObjectDefines.h" - -namespace GameLogic -{ - class LevelLoader - { - - public: - LevelLoader(); - /*********************************************************** - * Lets you set the standard folderpath for the levels - ********************************************************/ - LevelLoader(std::wstring folderPath); - ~LevelLoader(); - - /******************************************************** - * Loads the level and objects from file. - * @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::wstring fileName); - - /******************************************************** - * Just for fast access for the meta information about the level. - * @param fileName: Path to the level-file that you want to load. - * @return: Returns the meta information about the level. - ********************************************************/ - LevelMetaData LoadLevelHeader(std::wstring fileName); //. - - /*********************************************************** - * @return: Returns the current standard folder path - ********************************************************/ - std::wstring GetFolderPath(); - - /*********************************************************** - * Sets the standard folder path - ********************************************************/ - void SetFolderPath(std::wstring folderPath); - - private: - struct PrivData; - Utility::DynamicMemory::SmartPointer pData; - }; -} - -#endif \ No newline at end of file diff --git a/Code/Game/GameLogic/LevelLoader/LevelParser.cpp b/Code/Game/GameLogic/LevelLoader/LevelParser.cpp deleted file mode 100644 index 2d23f069..00000000 --- a/Code/Game/GameLogic/LevelLoader/LevelParser.cpp +++ /dev/null @@ -1,320 +0,0 @@ -///////////////////////////////////// -// Created by Pontus Fransson 2013 // -///////////////////////////////////// - -#include "LevelParser.h" -#include "Loader.h" -#include "ParseFunctions.h" - -using namespace GameLogic; -using namespace ::LevelFileLoader; -using namespace Utility::DynamicMemory; - -LevelParser::LevelParser() -{ - formatVersion.formatVersionMajor = 3; - formatVersion.formatVersionMinor = 0; -} - -LevelParser::~LevelParser() -{ -} - -std::vector> LevelParser::Parse(std::wstring filename) -{ - int bufferSize = 0; - int counter = 0; - bool loadCgf; - - std::vector> objects; - - //Read entire level file. - Loader loader; - char* buffer = (char*)loader.LoadFile(filename.c_str(), bufferSize); - - // Check if file was loaded, else return empty vector - if(!buffer) - { - return std::vector>(); - } - - //Read format version - LevelLoaderInternal::FormatVersion levelFormatVersion; - ParseObject(&buffer[counter], &levelFormatVersion, sizeof(levelFormatVersion)); - counter += sizeof(levelFormatVersion); - if(this->formatVersion != levelFormatVersion) - { - //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)); - switch((int)typeID) - { - case ObjectType_LevelMetaData: - { - SmartPointer header = new LevelMetaData; - ParseLevelMetaData(&buffer[counter], *(LevelMetaData*)header.Get(), counter); - objects.push_back(header); - break; - } - - case ObjectType_SpawnPoint: - { - loadCgf = false; - ObjectHeader* header = new ObjectHeader; - ParseObject(&buffer[counter], *header, counter, loadCgf); - - SpawnPointAttributes* spawn = new SpawnPointAttributes; - - spawn->typeID = header->typeID; - - for(int i = 0; i < 3; i++) - { - spawn->position[i] = header->position[i]; - } - - delete header; - //objects.push_back(header); - objects.push_back(spawn); - break; - } - - //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: - { - //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_StandardBox: - 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; - } - - default: - //Couldn't find specialType - break; - } - break; - } - - case ObjectType_Light: - { - LightType lightType; - - //Get Light type - ParseObject(&buffer[counter+4], &lightType, sizeof(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: - { - PointLight* header = new PointLight; - ParseObject(&buffer[counter], header, sizeof(*header)); - counter += sizeof(*header); - objects.push_back(header); - break; - } - case LightType_DirectionalLight: - { - DirectionalLight* header = new DirectionalLight; - ParseObject(&buffer[counter], header, sizeof(*header)); - counter += sizeof(*header); - objects.push_back(header); - break; - } - case LightType_SpotLight: - { - SpotLight* header = new SpotLight; - ParseObject(&buffer[counter], header, sizeof(*header)); - counter += sizeof(*header); - objects.push_back(header); - break; - } - default: - //Undefined LightType. - break; - } - break;*/ - } - default: - //Couldn't find typeID. FAIL!!!!!! - break; - } - } - - return objects; -} - -//för meta information om leveln. -LevelMetaData LevelParser::ParseHeader(std::wstring filename) -{ - int bufferSize = 0; - int counter = 0; - - LevelMetaData levelHeader; - levelHeader.typeID = ObjectType::ObjectType_Unknown; - - //Read entire level file. - Loader loader; - char* buffer = (char*)loader.LoadFile(filename.c_str(), bufferSize); - - //Read format version - 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) - { - ObjectType typeID; - ParseObject(&buffer[counter], &typeID, sizeof(typeID)); - - switch(typeID) - { - case ObjectType_LevelMetaData: - ParseLevelMetaData(&buffer[counter], levelHeader, counter); - return levelHeader; - break; - - //This is by design, static and dynamic is using the same converter. Do not add anything inbetween them. - case ObjectType_Static: case ObjectType_Dynamic: - { - ObjectHeader header; - ParseObject(&buffer[counter], &header, counter); - - switch(header.specialTypeID) - { - case ObjectSpecialType_JumpPad: - counter += sizeof(16); - break; - case ObjectSpecialType_Portal: - counter += sizeof(12); - break; - default: - break; - } - break; - } - - case ObjectType_Light: - { - LightType lightType; - ParseObject(&buffer[counter+4], &lightType, sizeof(lightType)); - - //We only support pointlight for now. - counter += sizeof(BasicLight); - /* - switch(lightType) - { - case LightType_PointLight: - { - counter += sizeof(PointLight); - break; - } - case LightType_DirectionalLight: - { - counter += sizeof(DirectionalLight); - break; - } - case LightType_SpotLight: - { - counter += sizeof(SpotLight); - break; - } - default: - //Undefined LightType. - break; - }*/ - } - - default: - //Couldn't find typeID. FAIL!!!!!! - break; - } - } - - return levelHeader; -} \ No newline at end of file diff --git a/Code/Game/GameLogic/LevelLoader/LevelParser.h b/Code/Game/GameLogic/LevelLoader/LevelParser.h deleted file mode 100644 index d0cb1f03..00000000 --- a/Code/Game/GameLogic/LevelLoader/LevelParser.h +++ /dev/null @@ -1,31 +0,0 @@ -#ifndef LEVEL_PARSER_H -#define LEVEL_PARSER_H - -#include -#include -#include "ObjectDefines.h" -#include "Utilities.h" - -namespace GameLogic -{ - namespace LevelFileLoader - { - class LevelParser - { - public: - LevelParser(); - ~LevelParser(); - - // - std::vector> Parse(std::wstring filename); - - // - LevelMetaData ParseHeader(std::wstring filename); - - private: - LevelLoaderInternal::FormatVersion formatVersion; - - }; - } -} -#endif \ No newline at end of file diff --git a/Code/Game/GameLogic/LevelLoader/Loader.cpp b/Code/Game/GameLogic/LevelLoader/Loader.cpp deleted file mode 100644 index 19ffa0f1..00000000 --- a/Code/Game/GameLogic/LevelLoader/Loader.cpp +++ /dev/null @@ -1,22 +0,0 @@ -////////////////////////////////// -// Created by Sam Svensson 2013 // -////////////////////////////////// - -#include "Loader.h" -#include - -using namespace GameLogic::LevelFileLoader; -using namespace Oyster::Resource; -using namespace std; - -char* Loader::LoadFile(std::wstring fileName, int &size) -{ - //convert from string to wstring - //std::wstring temp(fileName.begin(), fileName.end()); - - //convert from wstring to wchar then loads the file - char* buffer = (char*)OysterResource::LoadResource(fileName.c_str(), Oyster::Resource::ResourceType::ResourceType_Byte_Raw, -1 , false); - - size = OysterResource::GetResourceSize(buffer); - return buffer; -} \ No newline at end of file diff --git a/Code/Game/GameLogic/LevelLoader/Loader.h b/Code/Game/GameLogic/LevelLoader/Loader.h deleted file mode 100644 index 6deb8900..00000000 --- a/Code/Game/GameLogic/LevelLoader/Loader.h +++ /dev/null @@ -1,28 +0,0 @@ -////////////////////////////////// -// Created by Sam Svensson 2013 // -////////////////////////////////// - -#ifndef LOADER_H -#define LOADER_H - -#include "Resource\OysterResource.h" -#include - -namespace GameLogic -{ - namespace LevelFileLoader - { - class Loader - { - public: - Loader (){}; - ~Loader(){}; - char* LoadFile(std::wstring fileName, int &size); - - //TODO: - //Add functionality to load physicsObjects (hitboxes) - }; - } -} - -#endif; \ No newline at end of file diff --git a/Code/Game/GameLogic/LevelLoader/ObjectDefines.h b/Code/Game/GameLogic/LevelLoader/ObjectDefines.h deleted file mode 100644 index 131b2938..00000000 --- a/Code/Game/GameLogic/LevelLoader/ObjectDefines.h +++ /dev/null @@ -1,290 +0,0 @@ -#ifndef OBJECT_DEFINES_H -#define OBJECT_DEFINES_H - -#include -#include - -namespace GameLogic -{ - /************************************ - Enums - *************************************/ - - enum ObjectType - { - ObjectType_LevelMetaData, - ObjectType_Static, - ObjectType_Dynamic, - ObjectType_Light, - ObjectType_SpawnPoint, - //Etc - - ObjectType_NUM_OF_TYPES, - - ObjectType_Unknown = -1 - }; - - enum ObjectSpecialType - { - ObjectSpecialType_None, - ObjectSpecialType_Sky, - ObjectSpecialType_World, //Always the main celestial body - ObjectSpecialType_Building, - ObjectSpecialType_Stone, - ObjectSpecialType_StandardBox, - ObjectSpecialType_RedExplosiveBox, - ObjectSpecialType_SpikeBox, - ObjectSpecialType_Spike, - ObjectSpecialType_CrystalFormation, - ObjectSpecialType_CrystalShard, - ObjectSpecialType_JumpPad, - ObjectSpecialType_Portal, - ObjectSpecialType_Player, - ObjectSpecialType_Generic, - - - ObjectSpecialType_Count, - ObjectSpecialType_Unknown = -1 - }; - - enum CollisionGeometryType - { - CollisionGeometryType_Box, - CollisionGeometryType_Sphere, - CollisionGeometryType_Cylinder, - CollisionGeometryType_TriangleMesh, - - CollisionGeometryType_Count, - CollisionGeometryType_Unknown = -1 - }; - - //Only supports Pointlight right now. - enum LightType - { - LightType_PointLight, - //LightType_DirectionalLight, - //LightType_SpotLight, - - LightType_Count, - LightType_Unknown = -1 - }; - - //Should this be moved somewhere else? - enum GameMode - { - GameMode_FreeForAll, - GameMode_TeamDeathMatch, - //Etc - - GameMode_Count, - GameMode_Unknown = -1 - }; - - enum WorldSize - { - WorldSize_Tiny, - WorldSize_Small, - WorldSize_Medium, - WorldSize_Big, - WorldSize_Humongous, - - WorldSize_Count, - WorldSize_Unknown = -1 - }; - - - /************************************ - Structs - *************************************/ - namespace LevelLoaderInternal - { - struct FormatVersion - { - unsigned int formatVersionMajor; - unsigned int formatVersionMinor; - - FormatVersion() - : formatVersionMajor(0), formatVersionMinor(0) - {} - - 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(){} - }; - - namespace LevelLoaderInternal - { - 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 BoundingVolumeTriangleMesh : public BoundingVolumeBase - { - //Null terminated - wchar_t* filename; - }; - - struct BoundingVolume - { - CollisionGeometryType geoType; - union - { - LevelLoaderInternal::BoundingVolumeBox box; - LevelLoaderInternal::BoundingVolumeSphere sphere; - LevelLoaderInternal::BoundingVolumeCylinder cylinder; - LevelLoaderInternal::BoundingVolumeTriangleMesh triangleMesh; - }; - - virtual ~BoundingVolume() - { - if(geoType == CollisionGeometryType_TriangleMesh) - { - delete[] triangleMesh.filename; - } - } - }; - - } - - struct LevelMetaData : public ObjectTypeHeader - { - std::string levelName; - unsigned int levelVersion; - std::string levelDescription; - std::string levelAuthor; - unsigned int maxNumberOfPlayer; - WorldSize worldSize; - std::string overviewPicturePath; - std::vector gameModesSupported; - - virtual ~LevelMetaData(){} - - }; - - 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 Quaternion - float rotation[4]; - //Scale - float scale[3]; - - ::GameLogic::LevelLoaderInternal::BoundingVolume boundingVolume; - - virtual ~ObjectHeader(){} - }; - - struct SpawnPointAttributes : public ObjectTypeHeader - { - ObjectSpecialType specialTypeID; - float position[3]; - }; - /************************************ - 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 - *************************************/ - - struct BasicLight : public ObjectTypeHeader - { - 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]; - }; - - struct DirectionalLight : public BasicLight - { - float direction[3]; - }; - - struct SpotLight : public BasicLight - { - float direction[3]; - float range; - float attenuation[3]; - };*/ -} - -#endif \ No newline at end of file diff --git a/Code/Game/GameLogic/LevelLoader/ParseFunctions.cpp b/Code/Game/GameLogic/LevelLoader/ParseFunctions.cpp deleted file mode 100644 index 76d7d6c3..00000000 --- a/Code/Game/GameLogic/LevelLoader/ParseFunctions.cpp +++ /dev/null @@ -1,195 +0,0 @@ -////////////////////////////////// -// Created by Sam Svensson 2013 // -////////////////////////////////// - -#include "ParseFunctions.h" -#include "Packing/Packing.h" -#include "Loader.h" -#include "Utilities.h" -#include - -using namespace Oyster::Packing; -using namespace GameLogic::LevelFileLoader; -using namespace GameLogic; -using namespace std; - -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, bool loadCgf) - { - char tempName[128]; - unsigned int tempSize = 0; - int start = 0; - - memcpy(&header.typeID, &buffer[start], 4); - start += 4; - - memcpy(&header.specialTypeID, &buffer[start], 4); - start += 4; - - memcpy(&tempSize, &buffer[start], 4); - start += 4; - - memcpy(&tempName, &buffer[start], tempSize); - 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); - } - - //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; - } - - void ParseLevelMetaData(char* buffer, LevelMetaData &header, int &size) - { - int start = 0; - unsigned int tempSize; - char tempName[128]; - - memcpy(&header.typeID, &buffer[start], 4); - start += 4; - - memcpy(&tempSize , &buffer[start], 4); - start += 4; - - memcpy(&tempName, &buffer[start], tempSize); - header.levelName.assign(&tempName[0], &tempName[tempSize]); - start += tempSize; - - memcpy(&header.levelVersion, &buffer[start], 4); - start += 4; - - memcpy(&tempSize, &buffer[start], 4); - start +=4; - - memcpy(&tempName, &buffer[start], tempSize); - header.levelDescription.assign(&tempName[0], &tempName[tempSize]); - start += tempSize; - - memcpy(&tempSize, &buffer[start], 4); - start += 4; - - memcpy(&tempName, &buffer[start], tempSize); - header.levelAuthor.assign(&tempName[0], &tempName[tempSize]); - start += tempSize; - - memcpy(&header.maxNumberOfPlayer, &buffer[start], 4); - start += 4; - - memcpy(&header.worldSize, &buffer[start], 4); - start += 4; - - memcpy(&tempSize, &buffer[start], 4); - start += 4; - - memcpy(&tempName, &buffer[start], tempSize); - header.overviewPicturePath.assign(&tempName[0], &tempName[tempSize]); - start += tempSize; - - memcpy(&tempSize, &buffer[start], 4); - start += 4; - - int temp; - - for(int i = 0; i < (int)tempSize; i++) - { - memcpy(&temp, &buffer[start], 4); - start += 4; - header.gameModesSupported.push_back((GameMode)temp); - } - - 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(L"../Content/Worlds/cgf/" + Utility::String::StringToWstring(fileName, wstring()), fileLength); - - start = 0; - LevelLoaderInternal::FormatVersion version; - memcpy(&version, &buf[0], sizeof(version)); - start += 8; - - memcpy(&volume.geoType, &buf[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; - - case CollisionGeometryType_TriangleMesh: - //Get string size - memcpy(&tempSize, &buf[start], sizeof(tempSize)); - start += sizeof(tempSize); - - //Get actual string - volume.triangleMesh.filename = new wchar_t[tempSize+1]; - memcpy(volume.triangleMesh.filename, &buf[start], tempSize); - volume.triangleMesh.filename[tempSize] = '\0'; - break; - - default: - break; - } - } - } -} \ No newline at end of file diff --git a/Code/Game/GameLogic/LevelLoader/ParseFunctions.h b/Code/Game/GameLogic/LevelLoader/ParseFunctions.h deleted file mode 100644 index 0fc6dbc6..00000000 --- a/Code/Game/GameLogic/LevelLoader/ParseFunctions.h +++ /dev/null @@ -1,28 +0,0 @@ -////////////////////////////////// -// Created by Sam Svensson 2013 // -////////////////////////////////// - -#ifndef PARSERFUNCTIONS_H -#define PARSERFUNCTIONS_H -#include "ObjectDefines.h" - -namespace GameLogic -{ - namespace LevelFileLoader - { - /* - These functions will copy data from where the buffer pointer points. - header is the destination where the data will be copied. - size is either the size of the data to be copied (if it is NOT sent by reference). - Or the current index that is being used to parse the entire file (if it is sent by reference) this means you have to increase size with the appropiate size after you have copied. - - */ - void ParseObject(char* buffer, void *header, int size); - void ParseObject(char* buffer, ObjectHeader& header, int& size , bool loadCgf); - void ParseLevelMetaData(char* buffer, LevelMetaData &header, int &size); - void ParseBoundingVolume(char* buffer, LevelLoaderInternal::BoundingVolume& volume, int &size); - } -} - - -#endif \ No newline at end of file diff --git a/Code/Game/GameLogic/Object.cpp b/Code/Game/GameLogic/Object.cpp index 751dc454..1f43263b 100644 --- a/Code/Game/GameLogic/Object.cpp +++ b/Code/Game/GameLogic/Object.cpp @@ -15,11 +15,11 @@ const Game *Object::gameInstance = (Game*)(&Game::Instance()); 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 = ObjectSpecialType_Unknown; this->objectID = -1; + this->scale = Float3(1.0f, 1.0f, 1.0f); } Object::Object(Oyster::Physics::ICustomBody *rigidBody, void (*collisionFuncAfter)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), ObjectSpecialType type, int objectID) @@ -48,39 +48,12 @@ Object::~Object(void) } -ObjectSpecialType Object::GetObjectType() const + +void Object::SetOnCollision(OnCollisionCallback func) { - return this->type; -} -int Object::GetID() const -{ - return this->objectID; + this->rigidBody->SetSubscription((Oyster::Physics::ICustomBody::EventAction_AfterCollisionResponse)(func)); } -Oyster::Physics::ICustomBody* Object::GetRigidBody() -{ - return this->rigidBody; -} - - -void Object::BeginFrame() -{ - -} -// update physic -void Object::EndFrame() -{ - -} - -void Object::setBeforeCollisonFunc(Oyster::Physics::ICustomBody::SubscriptMessage (*collisionFuncBefore)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter)) -{ - //this->rigidBody->SetSubscription((Oyster::Physics::ICustomBody::EventAction_BeforeCollisionResponse)(collisionFuncBefore)); -} -void Object::setAfterCollisonFunc(Oyster::Physics::ICustomBody::SubscriptMessage (*collisionFuncAfter)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss)) -{ - this->rigidBody->SetSubscription((Oyster::Physics::ICustomBody::EventAction_AfterCollisionResponse)(collisionFuncAfter)); -} Oyster::Math::Float3 Object::GetPosition() { @@ -94,21 +67,9 @@ Oyster::Math::Quaternion Object::GetRotation() state = this->rigidBody->GetState(); return state.quaternion; } -Oyster::Math::Float3 Object::GetScale() -{ - Oyster::Physics::ICustomBody::State state; - state = this->rigidBody->GetState(); - return Float3(); -} Oyster::Math::Float4x4 Object::GetOrientation() { Oyster::Physics::ICustomBody::State state; state = this->rigidBody->GetState(); return state.GetOrientation(); } - - -Oyster::Math::Float Object::getExtraDamageOnCollision() -{ - return this->extraDamageOnCollision; -} \ No newline at end of file diff --git a/Code/Game/GameLogic/Object.h b/Code/Game/GameLogic/Object.h index 73853bd8..075236fe 100644 --- a/Code/Game/GameLogic/Object.h +++ b/Code/Game/GameLogic/Object.h @@ -16,47 +16,39 @@ namespace GameLogic class Object :public IObjectData { + public: + typedef Oyster::Physics::ICustomBody::SubscriptMessage (*OnCollisionCallback)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss); + public: Object(); - Object(Oyster::Physics::ICustomBody *rigidBody, void (*collisionFuncAfter)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), ObjectSpecialType type, int objectID); Object(Oyster::Physics::ICustomBody *rigidBody, Oyster::Physics::ICustomBody::SubscriptMessage (*collisionFuncAfter)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), ObjectSpecialType type, int objectID); ~Object(void); - 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; + inline ObjectSpecialType GetObjectType() const override { return this->type; } + inline int GetID() const override { return this->objectID; } + inline Oyster::Math::Float3 GetScale() override { return this->scale; } + inline Oyster::Math::Float3 GetPosition() override; + inline Oyster::Math::Quaternion GetRotation() override; + inline Oyster::Math::Float4x4 GetOrientation() override; + inline Oyster::Physics::ICustomBody* GetRigidBody() { return this->rigidBody; } + inline Oyster::Math::Float GetExtraDamageOnCollision() { return this->extraDamageOnCollision; } - Oyster::Math::Float getExtraDamageOnCollision(); + virtual void BeginFrame() { }; + virtual void EndFrame() { }; - // API overrides - - - - Oyster::Physics::ICustomBody* GetRigidBody(); - - virtual void BeginFrame(); - virtual void EndFrame(); - - void setBeforeCollisonFunc(Oyster::Physics::ICustomBody::SubscriptMessage (*collisionFuncBefore)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter)); - void setAfterCollisonFunc(Oyster::Physics::ICustomBody::SubscriptMessage (*collisionFuncAfter)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss)); - - static Oyster::Physics::ICustomBody::SubscriptMessage DefaultCollisionAfter(Oyster::Physics::ICustomBody *rigidBodyLevel, Oyster::Physics::ICustomBody *obj, Oyster::Math::Float kineticEnergyLoss); - - - public: //TODO: Hax This should be private when level is dynamic + void SetOnCollision(OnCollisionCallback func); + static Oyster::Physics::ICustomBody::SubscriptMessage DefaultOnCollision(Oyster::Physics::ICustomBody *rigidBodyObject, Oyster::Physics::ICustomBody *obj, Oyster::Math::Float kineticEnergyLoss); protected: Oyster::Physics::ICustomBody *rigidBody; static const Game* gameInstance; - Oyster::Math::Float3 currLook; - Oyster::Math::Float3 newLook; + + Oyster::Math::Float3 lookDirection; //The look direction for the camera + Oyster::Math::Float3 forwardDirection; //The forward direction of the rigid body + Oyster::Math::Float3 scale; //The scale of both rigid body and the mesh ObjectSpecialType type; int objectID; diff --git a/Code/Game/GameLogic/Player.cpp b/Code/Game/GameLogic/Player.cpp index 80969b29..b067d036 100644 --- a/Code/Game/GameLogic/Player.cpp +++ b/Code/Game/GameLogic/Player.cpp @@ -33,6 +33,8 @@ Player::Player(Oyster::Physics::ICustomBody *rigidBody, void (*EventOnCollision) this->moveDir = Oyster::Math::Float3(0,0,0); this->moveSpeed = 100; this->previousMoveSpeed = Oyster::Math::Float3(0,0,0); + + this->rotationUp = 0; } Player::Player(Oyster::Physics::ICustomBody *rigidBody, Oyster::Physics::ICustomBody::SubscriptMessage (*EventOnCollision)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), ObjectSpecialType type, int objectID, int teamID) @@ -53,6 +55,8 @@ Player::Player(Oyster::Physics::ICustomBody *rigidBody, Oyster::Physics::ICustom this->moveDir = Oyster::Math::Float3(0,0,0); this->moveSpeed = 20; this->previousMoveSpeed = Oyster::Math::Float3(0,0,0); + + this->rotationUp = 0; } Player::~Player(void) @@ -160,7 +164,6 @@ void Player::EndFrame() this->rigidBody->SetUp(this->rigidBody->GetState().centerPos.GetNormalized()); - Object::EndFrame(); } @@ -220,7 +223,7 @@ void Player::Respawn(Oyster::Math::Float3 spawnPoint) this->rigidBody->SetPosition(spawnPoint); } -void Player::Rotate(const Oyster::Math3D::Float3 lookDir, const Oyster::Math3D::Float3 right) +void Player::Rotate(const Oyster::Math3D::Float3& lookDir, const Oyster::Math3D::Float3& right) { // this is the camera right vector this->lookDir = lookDir; @@ -228,6 +231,11 @@ void Player::Rotate(const Oyster::Math3D::Float3 lookDir, const Oyster::Math3D:: //Oyster::Math::Float3 up = this->rigidBody->GetState().GetOrientation().v[1]; //this->rigidBody->SetUpAndRight(up, right); } +void Player::TurnLeft(Oyster::Math3D::Float deltaRadians) +{ + this->rotationUp += deltaRadians; + this->rigidBody->SetRotationAsAngularAxis(Oyster::Math3D::Float4(this->rigidBody->GetState().centerPos.GetNormalized(), this->rotationUp)); +} void Player::Jump() { diff --git a/Code/Game/GameLogic/Player.h b/Code/Game/GameLogic/Player.h index f2707cb3..13c6e300 100644 --- a/Code/Game/GameLogic/Player.h +++ b/Code/Game/GameLogic/Player.h @@ -46,7 +46,9 @@ namespace GameLogic void Respawn(Oyster::Math::Float3 spawnPoint); - void Rotate(const Oyster::Math3D::Float3 lookDir, const Oyster::Math3D::Float3 right); + void Rotate(const Oyster::Math3D::Float3& lookDir, const Oyster::Math3D::Float3& right); + + void TurnLeft(Oyster::Math3D::Float deltaRadians); /******************************************************** * Collision function for player, this is to be sent to physics through the subscribe function with the rigidbody @@ -94,6 +96,8 @@ namespace GameLogic Oyster::Math::Float moveSpeed; Oyster::Math::Float3 previousMoveSpeed; + Oyster::Math::Float rotationUp; + bool hasTakenDamage; float invincibleCooldown; diff --git a/Code/Game/GameProtocols/ObjectProtocols.h b/Code/Game/GameProtocols/ObjectProtocols.h index ff6aa6e5..fc02a4bd 100644 --- a/Code/Game/GameProtocols/ObjectProtocols.h +++ b/Code/Game/GameProtocols/ObjectProtocols.h @@ -561,11 +561,11 @@ namespace GameLogic this->protocol[0].type = Oyster::Network::NetAttributeType_Short; //PLAYER_ID - this->protocol[1].type = Oyster::Network::NetAttributeType_Int; + this->protocol[1].type = Oyster::Network::NetAttributeType_Bool; //TEAM_ID this->protocol[2].type = Oyster::Network::NetAttributeType_Int; //OWNER - this->protocol[3].type = Oyster::Network::NetAttributeType_Bool; + this->protocol[3].type = Oyster::Network::NetAttributeType_Int; //PLAYER-NAME this->protocol[4].type = Oyster::Network::NetAttributeType_CharArray; //MESH-NAME @@ -585,9 +585,10 @@ namespace GameLogic } Protocol_ObjectCreatePlayer(Oyster::Network::CustomNetProtocol& p) { - this->object_ID = p[1].value.netInt; - this->teamId = this->protocol[2].value.netInt; - this->owner = this->protocol[3].value.netBool; + this->owner = p[1].value.netBool; + this->object_ID = p[2].value.netInt; + this->teamId = p[3].value.netInt; + this->name.assign(p[4].value.netCharPtr); this->meshName.assign(p[5].value.netCharPtr); @@ -610,11 +611,11 @@ namespace GameLogic this->protocol[0].type = Oyster::Network::NetAttributeType_Short; //PLAYER_ID - this->protocol[1].type = Oyster::Network::NetAttributeType_Int; + this->protocol[1].type = Oyster::Network::NetAttributeType_Bool; //TEAM_ID this->protocol[2].type = Oyster::Network::NetAttributeType_Int; //OWNER - this->protocol[3].type = Oyster::Network::NetAttributeType_Bool; + this->protocol[3].type = Oyster::Network::NetAttributeType_Int; //PLAYER-NAME this->protocol[4].type = Oyster::Network::NetAttributeType_CharArray; //MESH-NAME @@ -644,10 +645,10 @@ namespace GameLogic } Oyster::Network::CustomNetProtocol GetProtocol() override { - - this->protocol[1].value = this->object_ID; - this->protocol[2].value = this->teamId; - this->protocol[3].value = this->owner; + this->protocol[1].value = this->owner; + this->protocol[2].value = this->object_ID; + this->protocol[3].value = this->teamId; + this->protocol.Set(4, this->name); this->protocol.Set(5, this->meshName); diff --git a/Code/Game/GameProtocols/PlayerProtocols.h b/Code/Game/GameProtocols/PlayerProtocols.h index b7d79d6c..57137fb4 100644 --- a/Code/Game/GameProtocols/PlayerProtocols.h +++ b/Code/Game/GameProtocols/PlayerProtocols.h @@ -74,69 +74,40 @@ namespace GameLogic Oyster::Network::CustomNetProtocol protocol; }; - struct Protocol_PlayerLook :public Oyster::Network::CustomProtocolObject + //protocol_Gameplay_PlayerLeftTurn + struct Protocol_PlayerLeftTurn : public ::Oyster::Network::CustomProtocolObject { - // can be swapped to a quaternion later - float lookDir[3]; - float right[3]; - - Protocol_PlayerLook() + public: + float deltaRadian; + + Protocol_PlayerLeftTurn() { - this->protocol[0].value = protocol_Gameplay_PlayerLookDir; - this->protocol[0].type = Oyster::Network::NetAttributeType_Short; - // LookDir - this->protocol[1].type = Oyster::Network::NetAttributeType_Float; - this->protocol[2].type = Oyster::Network::NetAttributeType_Float; - this->protocol[3].type = Oyster::Network::NetAttributeType_Float; - // Right - this->protocol[4].type = Oyster::Network::NetAttributeType_Float; - this->protocol[5].type = Oyster::Network::NetAttributeType_Float; - this->protocol[6].type = Oyster::Network::NetAttributeType_Float; - - memset(&this->lookDir[0], 0, sizeof(float) * 3); - memset(&this->right[0], 0, sizeof(float) * 3); + this->protocol[0].value = protocol_Gameplay_PlayerLeftTurn; + this->protocol[0].type = ::Oyster::Network::NetAttributeType_Short; + // deltaRadian + this->protocol[1].type = ::Oyster::Network::NetAttributeType_Float; } - Protocol_PlayerLook(Oyster::Network::CustomNetProtocol& p) - { - this->lookDir[0] = p[1].value.netFloat; - this->lookDir[1] = p[2].value.netFloat; - this->lookDir[2] = p[3].value.netFloat; - this->right[0] = p[4].value.netFloat; - this->right[1] = p[5].value.netFloat; - this->right[2] = p[6].value.netFloat; + Protocol_PlayerLeftTurn( const ::Oyster::Network::CustomNetProtocol &p ) + { + this->deltaRadian = p[1].value.netFloat; } - Protocol_PlayerLook(float l[3], float r[3]) + + Protocol_PlayerLeftTurn( float deltaRadian ) { - this->protocol[0].value = protocol_Gameplay_PlayerLookDir; - this->protocol[0].type = Oyster::Network::NetAttributeType_Short; - - this->protocol[1].type = Oyster::Network::NetAttributeType_Float; - this->protocol[2].type = Oyster::Network::NetAttributeType_Float; - this->protocol[3].type = Oyster::Network::NetAttributeType_Float; - - this->protocol[4].type = Oyster::Network::NetAttributeType_Float; - this->protocol[5].type = Oyster::Network::NetAttributeType_Float; - this->protocol[6].type = Oyster::Network::NetAttributeType_Float; - - memcpy(&this->lookDir[0], &l[0], sizeof(float) * 3); - memcpy(&this->right[0], &r[0], sizeof(float) * 3); + this->protocol[0].value = protocol_Gameplay_PlayerLeftTurn; + this->protocol[0].type = ::Oyster::Network::NetAttributeType_Short; + this->deltaRadian = deltaRadian; } - Oyster::Network::CustomNetProtocol GetProtocol() override + ::Oyster::Network::CustomNetProtocol GetProtocol() override { - this->protocol[1].value = this->lookDir[0]; - this->protocol[2].value = this->lookDir[1]; - this->protocol[3].value = this->lookDir[2]; - this->protocol[4].value = this->right[0]; - this->protocol[5].value = this->right[1]; - this->protocol[6].value = this->right[2]; - + this->protocol[1].value = this->deltaRadian; return protocol; } - private: - Oyster::Network::CustomNetProtocol protocol; + private: + ::Oyster::Network::CustomNetProtocol protocol; }; struct Protocol_PlayerChangeWeapon :public Oyster::Network::CustomProtocolObject diff --git a/Code/Game/GameProtocols/ProtocolIdentificationID.h b/Code/Game/GameProtocols/ProtocolIdentificationID.h index 25df7b78..4394a1a1 100644 --- a/Code/Game/GameProtocols/ProtocolIdentificationID.h +++ b/Code/Game/GameProtocols/ProtocolIdentificationID.h @@ -47,7 +47,7 @@ #define protocol_Gameplay_PlayerMovementLeft 301 #define protocol_Gameplay_PlayerMovementForward 302 #define protocol_Gameplay_PlayerMovementBackward 303 -#define protocol_Gameplay_PlayerLookDir 304 +#define protocol_Gameplay_PlayerLeftTurn 304 #define protocol_Gameplay_PlayerChangeWeapon 305 #define protocol_Gameplay_PlayerShot 306 #define protocol_Gameplay_PlayerJump 307 diff --git a/Code/Game/GameServer/GameServer.vcxproj b/Code/Game/GameServer/GameServer.vcxproj index 036459fa..a116e332 100644 --- a/Code/Game/GameServer/GameServer.vcxproj +++ b/Code/Game/GameServer/GameServer.vcxproj @@ -198,6 +198,9 @@ + + {f10cbc03-9809-4cba-95d8-327c287b18ee} + {2ec4dded-8f75-4c86-a10b-e1e8eb29f3ee} diff --git a/Code/Game/GameServer/GameSession.h b/Code/Game/GameServer/GameSession.h index 28e8bde3..ad9440e9 100644 --- a/Code/Game/GameServer/GameSession.h +++ b/Code/Game/GameServer/GameSession.h @@ -84,7 +84,7 @@ namespace DanBias void Gameplay_PlayerMovementBack ( DanBias::GameClient* c ); void Gameplay_PlayerMovementForth ( DanBias::GameClient* c ); void Gameplay_PlayerJump ( DanBias::GameClient* c ); - void Gameplay_PlayerLookDir ( GameLogic::Protocol_PlayerLook& p, DanBias::GameClient* c ); + void Gameplay_PlayerLeftTurn ( GameLogic::Protocol_PlayerLeftTurn& p, DanBias::GameClient* c ); void Gameplay_PlayerChangeWeapon ( GameLogic::Protocol_PlayerChangeWeapon& p, DanBias::GameClient* c ); void Gameplay_PlayerShot ( GameLogic::Protocol_PlayerShot& p, DanBias::GameClient* c ); void Gameplay_ObjectPickup ( GameLogic::Protocol_ObjectPickup& p, DanBias::GameClient* c ); diff --git a/Code/Game/GameServer/Implementation/GameClient.cpp b/Code/Game/GameServer/Implementation/GameClient.cpp index 81066450..9c04007f 100644 --- a/Code/Game/GameServer/Implementation/GameClient.cpp +++ b/Code/Game/GameServer/Implementation/GameClient.cpp @@ -17,7 +17,7 @@ GameClient::GameClient(Utility::DynamicMemory::SmartPointerclient = nwClient; this->player = 0; isReady = false; - this->character = L"Unknown"; + this->character = L"crate_colonists.dan"; this->alias = L"Unknown"; this->secondsSinceLastResponse = 0.0f; } @@ -25,7 +25,7 @@ GameClient::~GameClient() { this->player = 0; this->isReady = false; - this->character = L"Unknown"; + this->character = L"crate_colonists.dan"; this->alias = L"Unknown"; this->secondsSinceLastResponse = 0.0f; } diff --git a/Code/Game/GameServer/Implementation/GameSession_Gameplay.cpp b/Code/Game/GameServer/Implementation/GameSession_Gameplay.cpp index 6a9c09c2..8cbb542d 100644 --- a/Code/Game/GameServer/Implementation/GameSession_Gameplay.cpp +++ b/Code/Game/GameServer/Implementation/GameSession_Gameplay.cpp @@ -66,10 +66,10 @@ using namespace DanBias; break; case NetworkClient::ClientEventArgs::EventType_ProtocolFailedToSend: printf("\t(%i : %s) - EventType_ProtocolFailedToSend\n", cl->GetClient()->GetID(), e.sender->GetIpAddress().c_str()); - this->Detach(e.sender); + //this->Detach(e.sender); break; case NetworkClient::ClientEventArgs::EventType_ProtocolRecieved: - printf("\t(%i : %s) - EventType_ProtocolRecieved\n", cl->GetClient()->GetID(), e.sender->GetIpAddress().c_str()); + //printf("\t(%i : %s) - EventType_ProtocolRecieved\n", cl->GetClient()->GetID(), e.sender->GetIpAddress().c_str()); this->ParseProtocol(e.args.data.protocol, cl); break; } @@ -156,7 +156,7 @@ using namespace DanBias; break; case protocol_Gameplay_PlayerJump: this->Gameplay_PlayerJump ( c ); break; - case protocol_Gameplay_PlayerLookDir: this->Gameplay_PlayerLookDir ( Protocol_PlayerLook (p), c ); + case protocol_Gameplay_PlayerLeftTurn: this->Gameplay_PlayerLeftTurn ( Protocol_PlayerLeftTurn (p), c ); break; case protocol_Gameplay_PlayerChangeWeapon: this->Gameplay_PlayerChangeWeapon ( Protocol_PlayerChangeWeapon (p), c ); break; @@ -203,12 +203,9 @@ using namespace DanBias; { c->GetPlayer()->Move(GameLogic::PLAYER_MOVEMENT_JUMP); } - void GameSession::Gameplay_PlayerLookDir ( Protocol_PlayerLook& p, DanBias::GameClient* c ) + void GameSession::Gameplay_PlayerLeftTurn ( Protocol_PlayerLeftTurn& p, DanBias::GameClient* c ) { - Oyster::Math3D::Float3 lookDir = p.lookDir; - Oyster::Math3D::Float3 right = p.right; - - c->GetPlayer()->Rotate(lookDir, right); + c->GetPlayer()->TurnLeft( p.deltaRadian ); } void GameSession::Gameplay_PlayerChangeWeapon ( Protocol_PlayerChangeWeapon& p, DanBias::GameClient* c ) { diff --git a/Code/Game/GameServer/Implementation/GameSession_General.cpp b/Code/Game/GameServer/Implementation/GameSession_General.cpp index 933807a4..30eabed2 100644 --- a/Code/Game/GameServer/Implementation/GameSession_General.cpp +++ b/Code/Game/GameServer/Implementation/GameSession_General.cpp @@ -165,7 +165,8 @@ void GameSession::ThreadEntry( ) IPlayerData* pl = this->gClients[k]->GetPlayer(); Protocol_ObjectCreatePlayer p( pl->GetPosition(), pl->GetRotation(), pl->GetScale(), pl->GetID(), true, this->gClients[k]->GetPlayer()->GetTeamID(), - /*nwClient->GetAlias()*/"", /*playerData->GetMesh()*/"char_white.dan"); + Utility::String::WStringToString(this->gClients[k]->GetAlias(), std::string()), + Utility::String::WStringToString(this->gClients[k]->GetCharacter(), std::string())); readyList[i]->GetClient()->Send(p); } } @@ -204,7 +205,8 @@ bool GameSession::Join(gClient gameClient) { Protocol_ObjectCreatePlayer oc( playerData->GetPosition(), playerData->GetRotation(), playerData->GetScale(), playerData->GetID(), true, playerData->GetTeamID(), - /*nwClient->GetAlias()*/"Unknown", /*playerData->GetMesh()*/"char_white.dan"); + Utility::String::WStringToString(gameClient->GetAlias(), std::string()), + Utility::String::WStringToString(gameClient->GetCharacter(), std::string())); nwClient->Send(oc); } @@ -217,7 +219,8 @@ bool GameSession::Join(gClient gameClient) IPlayerData* temp = this->gClients[i]->GetPlayer(); Protocol_ObjectCreatePlayer oc( temp->GetPosition(), temp->GetRotation(), temp->GetScale(), temp->GetID(), false, temp->GetTeamID(), - /*nwClient->GetAlias()*/"Unknown", /*playerData->GetMesh()*/"char_white.dan"); + Utility::String::WStringToString(this->gClients[i]->GetAlias(), std::string()), + Utility::String::WStringToString(this->gClients[i]->GetCharacter(), std::string())); nwClient->Send(oc); } } diff --git a/Code/Game/LanServer/StandAloneLauncher/Form1.Designer.cs b/Code/Game/LanServer/StandAloneLauncher/Form1.Designer.cs index 4f9c169d..2fc06cef 100644 --- a/Code/Game/LanServer/StandAloneLauncher/Form1.Designer.cs +++ b/Code/Game/LanServer/StandAloneLauncher/Form1.Designer.cs @@ -210,11 +210,12 @@ this.mapName.FormattingEnabled = true; this.mapName.IntegralHeight = false; this.mapName.Items.AddRange(new object[] { - "Set default"}); + "Set directory"}); this.mapName.Location = new System.Drawing.Point(72, 7); this.mapName.Name = "mapName"; this.mapName.Size = new System.Drawing.Size(163, 21); this.mapName.TabIndex = 10; + this.mapName.SelectedIndexChanged += new System.EventHandler(this.mapName_SelectedIndexChanged); // // gameModes // @@ -481,7 +482,7 @@ this.tableLayoutPanel1.ColumnCount = 3; this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 35.29412F)); this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 64.70588F)); - this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 118F)); + this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 112F)); this.tableLayoutPanel1.Controls.Add(this.label6, 0, 0); this.tableLayoutPanel1.Controls.Add(this.label7, 1, 0); this.tableLayoutPanel1.Controls.Add(this.label8, 2, 0); @@ -515,7 +516,7 @@ // label8 // this.label8.AutoSize = true; - this.label8.Location = new System.Drawing.Point(116, 1); + this.label8.Location = new System.Drawing.Point(122, 1); this.label8.Name = "label8"; this.label8.Size = new System.Drawing.Size(34, 13); this.label8.TabIndex = 8; diff --git a/Code/Game/LanServer/StandAloneLauncher/Form1.cs b/Code/Game/LanServer/StandAloneLauncher/Form1.cs index 8b7e9474..cd52f3b6 100644 --- a/Code/Game/LanServer/StandAloneLauncher/Form1.cs +++ b/Code/Game/LanServer/StandAloneLauncher/Form1.cs @@ -25,12 +25,16 @@ namespace StandAloneLauncher { InitializeComponent(); - string[] maps = Directory.GetFiles("..\\Content\\Worlds\\"); + string[] maps = Directory.GetFiles("..\\Content\\Worlds\\"); for (int i = 0; i < maps.Length; i++) { - string temp = maps[i].Split('\\').Last() ; - this.mapName.Items.Add(temp); + string temp = maps[i].Split('\\').Last(); + string type = temp.Split('.').Last(); + if (type == "bias") + { + this.mapName.Items.Add(temp); + } } this.gameModes.SelectedIndex = 0; @@ -58,6 +62,19 @@ namespace StandAloneLauncher { if (this.serverIsRunning) { + if (gameIsStarted) + { + //this.gameServer.GameStop(); + + this.gameIsStarted = false; + this.buttonStartGame.Text = "Start Game"; + this.mapName.Enabled = true; + this.nrOfClients.Enabled = true; + this.gameModes.Enabled = true; + this.timeLimit.Enabled = true; + this.forceStart.Enabled = true; + } + this.serverIsRunning = false; this.gameServer.ServerStop(); this.listenPort.Enabled = true; @@ -66,7 +83,7 @@ namespace StandAloneLauncher this.serverToggle.Text = "Start server"; this.ServerInfoTextArea.AppendText(DateTime.Now.ToUniversalTime() + "\n\t" + "Server terminated!\n"); this.panel_commands.Visible = false; - this.panelServerCommands.Visible = false; + //this.panelServerCommands.Visible = false; } else { @@ -89,11 +106,11 @@ namespace StandAloneLauncher this.gameServer.ServerStart(); this.panel_commands.Visible = true; this.ServerInfoTextArea.AppendText(DateTime.Now.ToUniversalTime() + "\n\t" + "Server initiated!\n\tListening on port " + this.listenPort.Value.ToString() + "\n\tLocal IP: " + info.serverIp + "\n"); - this.panelServerCommands.Visible = true; + //this.panelServerCommands.Visible = true; } else { - this.ServerInfoTextArea.AppendText(DateTime.Now.ToUniversalTime() + "\n\t" + "Failed to initiate the server!"); + this.ServerInfoTextArea.AppendText(DateTime.Now.ToUniversalTime() + "\n\t" + "Failed to initiate the server!\n"); } } } @@ -104,6 +121,9 @@ namespace StandAloneLauncher { //this.gameServer.GameSetGameMode(this.gameModes.SelectedText); this.gameServer.GameSetGameTime((int)this.timeLimit.Value); + + + this.gameServer.GameSetMapName(this.mapName.Text); this.gameServer.GameSetMaxClients((int)this.nrOfClients.Value); @@ -125,6 +145,8 @@ namespace StandAloneLauncher } else { + //this.gameServer.GameStop(); + this.gameIsStarted = false; this.buttonStartGame.Text = "Start Game"; this.mapName.Enabled = true; @@ -152,7 +174,31 @@ namespace StandAloneLauncher p = this.panel2; this.dataProtocolFields.RowStyles.Add(new RowStyle(SizeType.Absolute, 27)); - + + } + + private void mapName_SelectedIndexChanged(object sender, EventArgs e) + { + if ( this.panel_commands.Visible && (this.mapName.SelectedItem.ToString() == "Set directory")) + { + FolderBrowserDialog f = new FolderBrowserDialog(); + DialogResult r = f.ShowDialog(); + if (r == System.Windows.Forms.DialogResult.OK) + { + this.mapName.Items.Clear(); + this.mapName.Items.Add("Set directory"); + string[] maps = Directory.GetFiles(f.SelectedPath); + for (int i = 0; i < maps.Length; i++) + { + string temp = maps[i].Split('\\').Last(); + string type = temp.Split('.').Last(); + if (type == "bias") + { + this.mapName.Items.Add(temp); + } + } + } + } } } } diff --git a/Code/Game/GameClient/GameClientState/LevelLoader/LevelLoader.cpp b/Code/Game/LevelLoader/LevelLoader.cpp similarity index 96% rename from Code/Game/GameClient/GameClientState/LevelLoader/LevelLoader.cpp rename to Code/Game/LevelLoader/LevelLoader.cpp index 8fe880f3..82583696 100644 --- a/Code/Game/GameClient/GameClientState/LevelLoader/LevelLoader.cpp +++ b/Code/Game/LevelLoader/LevelLoader.cpp @@ -48,5 +48,5 @@ std::string LevelLoader::GetFolderPath() void LevelLoader::SetFolderPath(std::string folderPath) { - + this->pData->folderPath = folderPath; } \ No newline at end of file diff --git a/Code/Game/GameClient/GameClientState/LevelLoader/LevelLoader.h b/Code/Game/LevelLoader/LevelLoader.h similarity index 100% rename from Code/Game/GameClient/GameClientState/LevelLoader/LevelLoader.h rename to Code/Game/LevelLoader/LevelLoader.h diff --git a/Code/GamePhysics/GamePhysics.vcxproj b/Code/Game/LevelLoader/LevelLoader.vcxproj similarity index 59% rename from Code/GamePhysics/GamePhysics.vcxproj rename to Code/Game/LevelLoader/LevelLoader.vcxproj index 07f5aed2..7f748c5f 100644 --- a/Code/GamePhysics/GamePhysics.vcxproj +++ b/Code/Game/LevelLoader/LevelLoader.vcxproj @@ -19,35 +19,35 @@ - {104FA3E9-94D9-4E1D-A941-28A03BC8A095} - GamePhysics + {6391E709-D9FA-4FEF-A3B9-4343DB5A0C63} + LevelLoader - DynamicLibrary + StaticLibrary true v110 - MultiByte + Unicode - DynamicLibrary + StaticLibrary true v110 - MultiByte + Unicode - DynamicLibrary + StaticLibrary false v110 true - MultiByte + Unicode - DynamicLibrary + StaticLibrary false v110 true - MultiByte + Unicode @@ -66,53 +66,45 @@ - $(SolutionDir)..\Bin\DLL\ - $(SolutionDir)..\Obj\$(ProjectName)\$(PlatformShortName)\$(Configuration)\ + $(SolutionDir)..\External\Lib\$(ProjectName)\ $(ProjectName)_$(PlatformShortName)D + $(SolutionDir)..\Obj\$(ProjectName)\$(PlatformShortName)\$(Configuration)\ - $(SolutionDir)..\Bin\DLL\ - $(SolutionDir)..\Obj\$(ProjectName)\$(PlatformShortName)\$(Configuration)\ + $(SolutionDir)..\External\Lib\$(ProjectName)\ $(ProjectName)_$(PlatformShortName) + $(SolutionDir)..\Obj\$(ProjectName)\$(PlatformShortName)\$(Configuration)\ - $(SolutionDir)..\Bin\DLL\ - $(SolutionDir)..\Obj\$(ProjectName)\$(PlatformShortName)\$(Configuration)\ + $(SolutionDir)..\External\Lib\$(ProjectName)\ $(ProjectName)_$(PlatformShortName)D + $(SolutionDir)..\Obj\$(ProjectName)\$(PlatformShortName)\$(Configuration)\ - $(SolutionDir)..\Bin\DLL\ - $(SolutionDir)..\Obj\$(ProjectName)\$(PlatformShortName)\$(Configuration)\ + $(SolutionDir)..\External\Lib\$(ProjectName)\ $(ProjectName)_$(PlatformShortName) + $(SolutionDir)..\Obj\$(ProjectName)\$(PlatformShortName)\$(Configuration)\ Level3 Disabled - $(SolutionDir)Misc;$(SolutionDir)OysterMath;$(SolutionDir)OysterPhysics3D;$(SolutionDir)Physics\Bullet Source\ - _WINDLL;PHYSICS_DLL_EXPORT;%(PreprocessorDefinitions) - false + true + $(SolutionDir)Misc\Utilities; true - - - $(SolutionDir)Physics/lib/debug/BulletCollision_Debug.lib;$(SolutionDir)Physics/lib/debug/BulletDynamics_Debug.lib;$(SolutionDir)Physics/lib/debug/LinearMath_Debug.lib;%(AdditionalDependencies) Level3 Disabled - $(SolutionDir)Misc;$(SolutionDir)OysterMath;$(SolutionDir)OysterPhysics3D;$(SolutionDir)Physics\Bullet Source\ - _WINDLL;PHYSICS_DLL_EXPORT;%(PreprocessorDefinitions) - false + true + $(SolutionDir)Misc\Utilities; true - - - $(SolutionDir)Physics/lib/debug/BulletCollision_Debugx64.lib;$(SolutionDir)Physics/lib/debug/BulletDynamics_Debugx64.lib;$(SolutionDir)Physics/lib/debug/LinearMath_Debugx64.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) @@ -121,18 +113,18 @@ MaxSpeed true true - $(SolutionDir)Misc;$(SolutionDir)OysterMath;$(SolutionDir)OysterPhysics3D;$(SolutionDir)Physics\Bullet Source\ - _WINDLL;PHYSICS_DLL_EXPORT;%(PreprocessorDefinitions) - false + true + $(SolutionDir)Misc\Utilities; true true true - - - $(SolutionDir)Physics/lib/release/BulletCollision.lib;$(SolutionDir)Physics/lib/release/BulletDynamics.lib;$(SolutionDir)Physics/lib/release/LinearMath.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) + + + + @@ -140,30 +132,32 @@ MaxSpeed true true - $(SolutionDir)Misc;$(SolutionDir)OysterMath;$(SolutionDir)OysterPhysics3D;$(SolutionDir)Physics\Bullet Source\ - _WINDLL;PHYSICS_DLL_EXPORT;%(PreprocessorDefinitions) - false + true + $(SolutionDir)Misc\Utilities; true true true - - - $(SolutionDir)Physics/lib/release/BulletCollisionx64.lib;$(SolutionDir)Physics/lib/release/BulletDynamicsx64.lib;$(SolutionDir)Physics/lib/release/LinearMathx64.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) - - - - - + + + + - - - + + + + + + + + + {2ec4dded-8f75-4c86-a10b-e1e8eb29f3ee} + diff --git a/Code/Game/LevelLoader/LevelLoader.vcxproj.user b/Code/Game/LevelLoader/LevelLoader.vcxproj.user new file mode 100644 index 00000000..2e28d6f7 --- /dev/null +++ b/Code/Game/LevelLoader/LevelLoader.vcxproj.user @@ -0,0 +1,22 @@ +ďťż + + + true + + + $(OutDir) + WindowsLocalDebugger + + + $(OutDir) + WindowsLocalDebugger + + + $(OutDir) + WindowsLocalDebugger + + + $(OutDir) + WindowsLocalDebugger + + \ No newline at end of file diff --git a/Code/Game/LevelLoader/LevelParser.cpp b/Code/Game/LevelLoader/LevelParser.cpp new file mode 100644 index 00000000..5f5a5341 --- /dev/null +++ b/Code/Game/LevelLoader/LevelParser.cpp @@ -0,0 +1,318 @@ +///////////////////////////////////// +// Created by Pontus Fransson 2013 // +///////////////////////////////////// + +#include "LevelParser.h" + +#include "Loader.h" +#include "ParseFunctions.h" + +using namespace GameLogic; +using namespace ::LevelFileLoader; +using namespace Utility::DynamicMemory; + +LevelParser::LevelParser() +{ + formatVersion.formatVersionMajor = 3; + formatVersion.formatVersionMinor = 0; +} + +LevelParser::~LevelParser() +{ +} + +std::vector> LevelParser::Parse(std::string filename) +{ + int bufferSize = 0; + int counter = 0; + bool loadCgf; + + std::vector> objects; + + //Read entire level file. + Loader loader; + char* buffer = (char*)loader.LoadFile(filename.c_str(), bufferSize); + + if(buffer) + { + //Read format version + LevelLoaderInternal::FormatVersion levelFormatVersion; + ParseObject(&buffer[counter], &levelFormatVersion, sizeof(levelFormatVersion)); + counter += sizeof(levelFormatVersion); + if(this->formatVersion != levelFormatVersion) + { + //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)); + switch((int)typeID) + { + case ObjectType_LevelMetaData: + { + SmartPointer header = new LevelMetaData; + ParseLevelMetaData(&buffer[counter], *(LevelMetaData*)header.Get(), counter); + objects.push_back(header); + break; + } + + case ObjectType_SpawnPoint: + { + loadCgf = false; + ObjectHeader* header = new ObjectHeader; + ParseObject(&buffer[counter], *header, counter, loadCgf); + + SpawnPointAttributes* spawn = new SpawnPointAttributes; + + spawn->typeID = header->typeID; + + for(int i = 0; i < 3; i++) + { + spawn->position[i] = header->position[i]; + } + + delete header; + //objects.push_back(header); + objects.push_back(spawn); + break; + } + + //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: + { + //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_StandardBox: + 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; + } + //this is a hotfix, fix so you only load the relevant data when the file is updated + default: + //Couldn't find specialType + break; + } + break; + } + + case ObjectType_Light: + { + LightType lightType; + + //Get Light type + ParseObject(&buffer[counter+4], &lightType, sizeof(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: + { + PointLight* header = new PointLight; + ParseObject(&buffer[counter], header, sizeof(*header)); + counter += sizeof(*header); + objects.push_back(header); + break; + } + case LightType_DirectionalLight: + { + DirectionalLight* header = new DirectionalLight; + ParseObject(&buffer[counter], header, sizeof(*header)); + counter += sizeof(*header); + objects.push_back(header); + break; + } + case LightType_SpotLight: + { + SpotLight* header = new SpotLight; + ParseObject(&buffer[counter], header, sizeof(*header)); + counter += sizeof(*header); + objects.push_back(header); + break; + } + default: + //Undefined LightType. + break; + } + break;*/ + } + default: + //Couldn't find typeID. FAIL!!!!!! + break; + } + } + } + + return objects; +} + +//för meta information om leveln. +LevelMetaData LevelParser::ParseHeader(std::string filename) +{ + int bufferSize = 0; + int counter = 0; + + LevelMetaData levelHeader; + levelHeader.typeID = ObjectType::ObjectType_Unknown; + + //Read entire level file. + Loader loader; + char* buffer = (char*)loader.LoadFile(filename.c_str(), bufferSize); + + //Read format version + 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) + { + ObjectType typeID; + ParseObject(&buffer[counter], &typeID, sizeof(typeID)); + + switch(typeID) + { + case ObjectType_LevelMetaData: + ParseLevelMetaData(&buffer[counter], levelHeader, counter); + return levelHeader; + break; + + //This is by design, static and dynamic is using the same converter. Do not add anything inbetween them. + case ObjectType_Static: case ObjectType_Dynamic: + { + ObjectHeader header; + ParseObject(&buffer[counter], &header, counter); + + switch(header.specialTypeID) + { + case ObjectSpecialType_JumpPad: + counter += sizeof(16); + break; + case ObjectSpecialType_Portal: + counter += sizeof(12); + break; + default: + break; + } + break; + } + + case ObjectType_Light: + { + LightType lightType; + ParseObject(&buffer[counter+4], &lightType, sizeof(lightType)); + + //We only support pointlight for now. + counter += sizeof(BasicLight); + /* + switch(lightType) + { + case LightType_PointLight: + { + counter += sizeof(PointLight); + break; + } + case LightType_DirectionalLight: + { + counter += sizeof(DirectionalLight); + break; + } + case LightType_SpotLight: + { + counter += sizeof(SpotLight); + break; + } + default: + //Undefined LightType. + break; + }*/ + } + + default: + //Couldn't find typeID. FAIL!!!!!! + break; + } + } + + return levelHeader; +} \ No newline at end of file diff --git a/Code/Game/GameClient/GameClientState/LevelLoader/LevelParser.h b/Code/Game/LevelLoader/LevelParser.h similarity index 100% rename from Code/Game/GameClient/GameClientState/LevelLoader/LevelParser.h rename to Code/Game/LevelLoader/LevelParser.h diff --git a/Code/Game/GameClient/GameClientState/LevelLoader/Loader.cpp b/Code/Game/LevelLoader/Loader.cpp similarity index 100% rename from Code/Game/GameClient/GameClientState/LevelLoader/Loader.cpp rename to Code/Game/LevelLoader/Loader.cpp diff --git a/Code/Game/GameClient/GameClientState/LevelLoader/Loader.h b/Code/Game/LevelLoader/Loader.h similarity index 100% rename from Code/Game/GameClient/GameClientState/LevelLoader/Loader.h rename to Code/Game/LevelLoader/Loader.h diff --git a/Code/Game/GameClient/GameClientState/LevelLoader/ObjectDefines.h b/Code/Game/LevelLoader/ObjectDefines.h similarity index 98% rename from Code/Game/GameClient/GameClientState/LevelLoader/ObjectDefines.h rename to Code/Game/LevelLoader/ObjectDefines.h index bb2ae439..918fb4e6 100644 --- a/Code/Game/GameClient/GameClientState/LevelLoader/ObjectDefines.h +++ b/Code/Game/LevelLoader/ObjectDefines.h @@ -31,7 +31,7 @@ namespace GameLogic ObjectSpecialType_World, //Always the main celestial body ObjectSpecialType_Building, ObjectSpecialType_Stone, - ObjectSpecialType_StandarsBox, + ObjectSpecialType_StandardBox, ObjectSpecialType_RedExplosiveBox, ObjectSpecialType_SpikeBox, ObjectSpecialType_Spike, @@ -40,6 +40,7 @@ namespace GameLogic ObjectSpecialType_JumpPad, ObjectSpecialType_Portal, ObjectSpecialType_Player, + ObjectSpecialType_Generic, ObjectSpecialType_Count, diff --git a/Code/Game/GameClient/GameClientState/LevelLoader/ParseFunctions.cpp b/Code/Game/LevelLoader/ParseFunctions.cpp similarity index 97% rename from Code/Game/GameClient/GameClientState/LevelLoader/ParseFunctions.cpp rename to Code/Game/LevelLoader/ParseFunctions.cpp index 59f967de..09adb298 100644 --- a/Code/Game/GameClient/GameClientState/LevelLoader/ParseFunctions.cpp +++ b/Code/Game/LevelLoader/ParseFunctions.cpp @@ -117,7 +117,7 @@ namespace GameLogic int temp; - for(int i = 0; i < tempSize; i++) + for(int i = 0; i < (int)tempSize; i++) { memcpy(&temp, &buffer[start], 4); start += 4; @@ -152,10 +152,9 @@ namespace GameLogic 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/GameClient/GameClientState/LevelLoader/ParseFunctions.h b/Code/Game/LevelLoader/ParseFunctions.h similarity index 100% rename from Code/Game/GameClient/GameClientState/LevelLoader/ParseFunctions.h rename to Code/Game/LevelLoader/ParseFunctions.h diff --git a/Code/Misc/Input/L_inputClass.h b/Code/Misc/Input/L_inputClass.h index 8ed8e528..5511102a 100644 --- a/Code/Misc/Input/L_inputClass.h +++ b/Code/Misc/Input/L_inputClass.h @@ -7,6 +7,7 @@ #ifndef _INPUTCLASS_H_ #define _INPUTCLASS_H_ +#define NOMINMAX #define DIRECTINPUT_VERSION 0x0800 #pragma comment(lib, "dinput8.lib") diff --git a/Code/Misc/OysterMath/Quaternion.h b/Code/Misc/OysterMath/Quaternion.h index f5ea5951..b2390a2d 100644 --- a/Code/Misc/OysterMath/Quaternion.h +++ b/Code/Misc/OysterMath/Quaternion.h @@ -49,7 +49,16 @@ namespace LinearAlgebra Quaternion operator - ( const Quaternion &quaternion ) const; Quaternion operator - ( ) const; + Quaternion & Conjugate( ); + Quaternion & Normalize( ); + Quaternion & Inverse( ); + Quaternion GetConjugate( ) const; + Quaternion GetNormalized( ) const; + Quaternion GetInversed( ) const; + ScalarType GetNorm( ) const; + ScalarType GetModulus( ) const; + }; /////////////////////////////////////////////////////////////////////////////////// @@ -205,11 +214,54 @@ namespace LinearAlgebra return Quaternion(-this->imaginary, -this->real); } + template + inline Quaternion & Quaternion::Conjugate( ) + { + this->imaginary = -this->imaginary; + return *this; + } + + template + inline Quaternion & Quaternion::Normalize( ) + { + return *this /= this->GetModulus(); + } + + template + inline Quaternion & Quaternion::Inverse( ) + { + return this->Conjugate() /= this->GetNorm(); + } + template inline Quaternion Quaternion::GetConjugate( ) const { return Quaternion(-this->imaginary, this->real ); } + + template + inline Quaternion Quaternion::GetNormalized( ) const + { + return *this / this->GetModulus(); + } + + template + inline Quaternion Quaternion::GetInversed( ) const + { + return this->GetConjugate() /= this->GetNorm(); + } + + template + inline ScalarType Quaternion::GetNorm( ) const + { + return this->imaginary.Dot(this->imaginary) + this->real * this->real; + } + + template + inline ScalarType Quaternion::GetModulus( ) const + { + return (ScalarType)::std::sqrt( this->GetNorm() ); + } } #endif \ No newline at end of file diff --git a/Code/Misc/Utilities/Utilities.h b/Code/Misc/Utilities/Utilities.h index b97d62d7..c259a845 100644 --- a/Code/Misc/Utilities/Utilities.h +++ b/Code/Misc/Utilities/Utilities.h @@ -337,11 +337,7 @@ namespace Utility template inline ValueType Clamp( const ValueType &value, const ValueType &min, const ValueType &max ) - { - if( value < min ) return min; - if( value > max ) return max; - return value; - } + { return value < min ? Max( value, max ) : min; } template inline ValueType Average( const ValueType &valueA, const ValueType &valueB ) diff --git a/Code/Network/NetworkAPI/NetworkClient.cpp b/Code/Network/NetworkAPI/NetworkClient.cpp index 69872fc1..fc561845 100644 --- a/Code/Network/NetworkAPI/NetworkClient.cpp +++ b/Code/Network/NetworkAPI/NetworkClient.cpp @@ -290,9 +290,12 @@ bool NetworkClient::Connect(ConnectionInfo& socket) bool NetworkClient::Connect(unsigned short port, const char serverIP[]) { - if(this->IsConnected()) return false; - if(this->privateData) return false; - if(!this->privateData) this->privateData = new PrivateData(); + //Return true if you are already connected. + if(this->IsConnected()) + return true; + + if(!this->privateData) + this->privateData = new PrivateData(); int result = this->privateData->connection.Connect(port, serverIP, false); @@ -317,15 +320,35 @@ bool NetworkClient::Connect(unsigned short port, std::wstring serverIP) return this->Connect(port, ip.c_str()); } +bool NetworkClient::Reconnect() +{ + //Return true if you are already connected. + if(this->IsConnected()) + return true; + + if(!this->privateData) this->privateData = new PrivateData(); + + int result = this->privateData->connection.Reconnect(); + + if(result != 0) + { + return false; + } + this->privateData->owner = 0; + this->privateData->parent = this; + this->privateData->thread.Start(); + + return true; +} + void NetworkClient::Disconnect() { if(!privateData) return; - privateData->thread.Terminate(); + privateData->thread.Stop(); privateData->connection.Disconnect(); this->privateData->sendQueue.Clear(); this->privateData->recieveQueue.Clear(); - } void NetworkClient::Send(CustomProtocolObject& protocol) diff --git a/Code/Network/NetworkAPI/NetworkClient.h b/Code/Network/NetworkAPI/NetworkClient.h index 6f037117..a7f3b0bb 100644 --- a/Code/Network/NetworkAPI/NetworkClient.h +++ b/Code/Network/NetworkAPI/NetworkClient.h @@ -93,6 +93,11 @@ namespace Oyster */ bool Connect(unsigned short port, std::wstring serverIP); + /**Tries to connect with the same port and ip it earlier used for Connect. + * + */ + bool Reconnect(); + /** * */ diff --git a/Code/Network/NetworkDependencies/Connection.cpp b/Code/Network/NetworkDependencies/Connection.cpp index 99cb8a71..2cd992a2 100644 --- a/Code/Network/NetworkDependencies/Connection.cpp +++ b/Code/Network/NetworkDependencies/Connection.cpp @@ -58,6 +58,9 @@ int Connection::Connect(unsigned short port , const char serverName[], bool bloc { if(this->socket == -1 || this->socket == 0) InitiateSocket(); + lastConnectPort = port; + lastConnectAddr = serverName; + struct hostent *hostEnt; if((hostEnt = gethostbyname(serverName)) == NULL) { @@ -83,6 +86,37 @@ int Connection::Connect(unsigned short port , const char serverName[], bool bloc return 0; } +int Connection::Reconnect() +{ + if(this->socket == -1 || this->socket == 0) InitiateSocket(); + + struct hostent *hostEnt; + if((hostEnt = gethostbyname(this->lastConnectAddr.c_str())) == NULL) + { + return WSAGetLastError(); + } + + struct sockaddr_in server; + server.sin_family = AF_INET; + server.sin_port = htons(this->lastConnectPort); + server.sin_addr.s_addr = *(unsigned long*) hostEnt->h_addr; + + SetBlockingMode(true); + + if(connect(this->socket, (sockaddr*)&server, sizeof(server)) == SOCKET_ERROR) + { + return WSAGetLastError(); + } + + closed = false; + stillSending = true; + + SetBlockingMode(blocking); + + //connection succesfull! + return 0; +} + int Connection::InitiateServer(unsigned short port) { int errorCode = 0; diff --git a/Code/Network/NetworkDependencies/Connection.h b/Code/Network/NetworkDependencies/Connection.h index 0f46a599..054537fc 100644 --- a/Code/Network/NetworkDependencies/Connection.h +++ b/Code/Network/NetworkDependencies/Connection.h @@ -28,6 +28,7 @@ namespace Oyster virtual int Disconnect(); virtual int Connect(ConnectionInfo info, bool blocking = false); virtual int Connect(unsigned short port , const char serverName[], bool blocking = false); + virtual int Reconnect(); virtual ConnectionInfo Listen(); @@ -47,6 +48,11 @@ namespace Oyster bool stillSending; bool closed; std::string addr; + + std::string lastConnectAddr; + unsigned short lastConnectPort; + + bool blocking; }; } } diff --git a/Code/Network/NetworkDependencies/IConnection.h b/Code/Network/NetworkDependencies/IConnection.h index 7c92f318..debdfe7b 100644 --- a/Code/Network/NetworkDependencies/IConnection.h +++ b/Code/Network/NetworkDependencies/IConnection.h @@ -39,6 +39,9 @@ namespace Oyster //(servers uses Listen instead of connect) virtual int Connect( unsigned short port, const char serverName[] ) { return false; }; + //Tries to connect with the same port and ip used for Connect. + virtual int Reconnect() = 0; + //Disconnects the client or server TODO: optimize! virtual int Disconnect() = 0; }; diff --git a/Code/OysterGraphics/DllInterfaces/GFXAPI.cpp b/Code/OysterGraphics/DllInterfaces/GFXAPI.cpp index 96e2bbe2..ccb811c1 100644 --- a/Code/OysterGraphics/DllInterfaces/GFXAPI.cpp +++ b/Code/OysterGraphics/DllInterfaces/GFXAPI.cpp @@ -24,6 +24,8 @@ namespace Oyster Model::Model* sphere; ID3D11RasterizerState* wire; + + ID3D11ShaderResourceView* debugSRV; #endif } @@ -50,8 +52,15 @@ namespace Oyster Render::Preparations::Basic::SetViewPort(); #ifdef _DEBUG //fix load model - cube = CreateModel(L"debug_cube.dan"); - sphere = CreateModel(L"debug_sphere.dan"); + + debugSRV = (ID3D11ShaderResourceView*)API::CreateTexture(L"color_white.png"); + debugSRV = (ID3D11ShaderResourceView*)API::CreateTexture(L"color_white.png"); + + cube = CreateModel(L"generic_cube.dan"); + cube->Tint = Math::Float3(0.0f,0.0f,1.0f); + sphere = CreateModel(L"generic_sphere.dan"); + sphere->Tint = Math::Float3(1.0f,0.5f,182/255.0f); + D3D11_RASTERIZER_DESC desc; desc.CullMode = D3D11_CULL_BACK; @@ -196,6 +205,7 @@ namespace Oyster void API::StartRenderWireFrame() { + Core::deviceContext->OMSetRenderTargets(Render::Resources::Gather::Pass.RTV.size(),&Render::Resources::Gather::Pass.RTV[0],NULL); Core::deviceContext->RSSetState(wire); Core::deviceContext->OMSetRenderTargets(Render::Resources::Gather::Pass.RTV.size(),&Render::Resources::Gather::Pass.RTV[0],NULL); } diff --git a/Code/OysterGraphics/FileLoader/ModelLoader.cpp b/Code/OysterGraphics/FileLoader/ModelLoader.cpp index ba0928cc..0c7125fd 100644 --- a/Code/OysterGraphics/FileLoader/ModelLoader.cpp +++ b/Code/OysterGraphics/FileLoader/ModelLoader.cpp @@ -700,7 +700,7 @@ static HRESULT CreateTextureFromWIC( _In_ ID3D11Device* d3dDevice, return hr; } //todo check calc - int TexSize = twidth * theight * bpp; + int TexSize = twidth * theight * (int)bpp; Oyster::Graphics::Core::UsedMem += TexSize; if ( autogen ) diff --git a/Code/OysterGraphics/OysterGraphics.vcxproj.user b/Code/OysterGraphics/OysterGraphics.vcxproj.user index 3f030911..9a0b0ae0 100644 --- a/Code/OysterGraphics/OysterGraphics.vcxproj.user +++ b/Code/OysterGraphics/OysterGraphics.vcxproj.user @@ -1,6 +1,6 @@ ďťż - false + true \ No newline at end of file diff --git a/Code/Physics/Bullet Source/BulletFileLoader/CMakeLists.txt b/Code/Physics/Bullet Source/BulletFileLoader/CMakeLists.txt new file mode 100644 index 00000000..51e33e44 --- /dev/null +++ b/Code/Physics/Bullet Source/BulletFileLoader/CMakeLists.txt @@ -0,0 +1,49 @@ +INCLUDE_DIRECTORIES( + ${BULLET_PHYSICS_SOURCE_DIR}/src +) + +SET(BulletFileLoader_SRCS +bChunk.cpp +bDNA.cpp +bFile.cpp +btBulletFile.cpp +) + +SET(BulletFileLoader_HDRS +bChunk.h +bCommon.h +bDefines.h +bDNA.h +bFile.h +btBulletFile.h +) + +ADD_LIBRARY(BulletFileLoader ${BulletFileLoader_SRCS} ${BulletFileLoader_HDRS}) + +IF (BUILD_SHARED_LIBS) + TARGET_LINK_LIBRARIES(BulletFileLoader LinearMath) +ENDIF (BUILD_SHARED_LIBS) + +SET_TARGET_PROPERTIES(BulletFileLoader PROPERTIES VERSION ${BULLET_VERSION}) +SET_TARGET_PROPERTIES(BulletFileLoader PROPERTIES SOVERSION ${BULLET_VERSION}) + +IF (INSTALL_EXTRA_LIBS) + IF (NOT INTERNAL_CREATE_DISTRIBUTABLE_MSVC_PROJECTFILES) + #FILES_MATCHING requires CMake 2.6 + IF (${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION} GREATER 2.5) + IF (APPLE AND BUILD_SHARED_LIBS AND FRAMEWORK) + INSTALL(TARGETS BulletFileLoader DESTINATION .) + ELSE (APPLE AND BUILD_SHARED_LIBS AND FRAMEWORK) + INSTALL(TARGETS BulletFileLoader DESTINATION lib${LIB_SUFFIX}) + INSTALL(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} +DESTINATION ${INCLUDE_INSTALL_DIR} FILES_MATCHING PATTERN "*.h" PATTERN +".svn" EXCLUDE PATTERN "CMakeFiles" EXCLUDE) + ENDIF (APPLE AND BUILD_SHARED_LIBS AND FRAMEWORK) + ENDIF (${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION} GREATER 2.5) + + IF (APPLE AND BUILD_SHARED_LIBS AND FRAMEWORK) + SET_TARGET_PROPERTIES(BulletFileLoader PROPERTIES FRAMEWORK true) + SET_TARGET_PROPERTIES(BulletFileLoader PROPERTIES PUBLIC_HEADER "${BulletFileLoader_HDRS}") + ENDIF (APPLE AND BUILD_SHARED_LIBS AND FRAMEWORK) + ENDIF (NOT INTERNAL_CREATE_DISTRIBUTABLE_MSVC_PROJECTFILES) +ENDIF (INSTALL_EXTRA_LIBS) diff --git a/Code/Physics/Bullet Source/BulletFileLoader/autogenerated/bullet.h b/Code/Physics/Bullet Source/BulletFileLoader/autogenerated/bullet.h new file mode 100644 index 00000000..2fe1d7fc --- /dev/null +++ b/Code/Physics/Bullet Source/BulletFileLoader/autogenerated/bullet.h @@ -0,0 +1,1228 @@ +/* Copyright (C) 2011 Erwin Coumans & Charlie C +* +* This software is provided 'as-is', without any express or implied +* warranty. In no event will the authors be held liable for any damages +* arising from the use of this software. +* +* Permission is granted to anyone to use this software for any purpose, +* including commercial applications, and to alter it and redistribute it +* freely, subject to the following restrictions: +* +* 1. The origin of this software must not be misrepresented; you must not +* claim that you wrote the original software. If you use this software +* in a product, an acknowledgment in the product documentation would be +* appreciated but is not required. +* 2. Altered source versions must be plainly marked as such, and must not be +* misrepresented as being the original software. +* 3. This notice may not be removed or altered from any source distribution. +*/ +// Auto generated from Bullet/Extras/HeaderGenerator/bulletGenerate.py +#ifndef __BULLET_H__ +#define __BULLET_H__ +namespace Bullet { + +// put an empty struct in the case +typedef struct bInvalidHandle { + int unused; +}bInvalidHandle; + + class PointerArray; + class btPhysicsSystem; + class ListBase; + class btVector3FloatData; + class btVector3DoubleData; + class btMatrix3x3FloatData; + class btMatrix3x3DoubleData; + class btTransformFloatData; + class btTransformDoubleData; + class btBvhSubtreeInfoData; + class btOptimizedBvhNodeFloatData; + class btOptimizedBvhNodeDoubleData; + class btQuantizedBvhNodeData; + class btQuantizedBvhFloatData; + class btQuantizedBvhDoubleData; + class btCollisionShapeData; + class btStaticPlaneShapeData; + class btConvexInternalShapeData; + class btPositionAndRadius; + class btMultiSphereShapeData; + class btIntIndexData; + class btShortIntIndexData; + class btShortIntIndexTripletData; + class btCharIndexTripletData; + class btMeshPartData; + class btStridingMeshInterfaceData; + class btTriangleMeshShapeData; + class btScaledTriangleMeshShapeData; + class btCompoundShapeChildData; + class btCompoundShapeData; + class btCylinderShapeData; + class btConeShapeData; + class btCapsuleShapeData; + class btTriangleInfoData; + class btTriangleInfoMapData; + class btGImpactMeshShapeData; + class btConvexHullShapeData; + class btCollisionObjectDoubleData; + class btCollisionObjectFloatData; + class btDynamicsWorldDoubleData; + class btDynamicsWorldFloatData; + class btRigidBodyFloatData; + class btRigidBodyDoubleData; + class btConstraintInfo1; + class btTypedConstraintFloatData; + class btTypedConstraintData; + class btTypedConstraintDoubleData; + class btPoint2PointConstraintFloatData; + class btPoint2PointConstraintDoubleData2; + class btPoint2PointConstraintDoubleData; + class btHingeConstraintDoubleData; + class btHingeConstraintFloatData; + class btHingeConstraintDoubleData2; + class btConeTwistConstraintDoubleData; + class btConeTwistConstraintData; + class btGeneric6DofConstraintData; + class btGeneric6DofConstraintDoubleData2; + class btGeneric6DofSpringConstraintData; + class btGeneric6DofSpringConstraintDoubleData2; + class btSliderConstraintData; + class btSliderConstraintDoubleData; + class btGearConstraintFloatData; + class btGearConstraintDoubleData; + class btContactSolverInfoDoubleData; + class btContactSolverInfoFloatData; + class SoftBodyMaterialData; + class SoftBodyNodeData; + class SoftBodyLinkData; + class SoftBodyFaceData; + class SoftBodyTetraData; + class SoftRigidAnchorData; + class SoftBodyConfigData; + class SoftBodyPoseData; + class SoftBodyClusterData; + class btSoftBodyJointData; + class btSoftBodyFloatData; +// -------------------------------------------------- // + class PointerArray + { + public: + int m_size; + int m_capacity; + void *m_data; + }; + + +// -------------------------------------------------- // + class btPhysicsSystem + { + public: + PointerArray m_collisionShapes; + PointerArray m_collisionObjects; + PointerArray m_constraints; + }; + + +// -------------------------------------------------- // + class ListBase + { + public: + void *first; + void *last; + }; + + +// -------------------------------------------------- // + class btVector3FloatData + { + public: + float m_floats[4]; + }; + + +// -------------------------------------------------- // + class btVector3DoubleData + { + public: + double m_floats[4]; + }; + + +// -------------------------------------------------- // + class btMatrix3x3FloatData + { + public: + btVector3FloatData m_el[3]; + }; + + +// -------------------------------------------------- // + class btMatrix3x3DoubleData + { + public: + btVector3DoubleData m_el[3]; + }; + + +// -------------------------------------------------- // + class btTransformFloatData + { + public: + btMatrix3x3FloatData m_basis; + btVector3FloatData m_origin; + }; + + +// -------------------------------------------------- // + class btTransformDoubleData + { + public: + btMatrix3x3DoubleData m_basis; + btVector3DoubleData m_origin; + }; + + +// -------------------------------------------------- // + class btBvhSubtreeInfoData + { + public: + int m_rootNodeIndex; + int m_subtreeSize; + short m_quantizedAabbMin[3]; + short m_quantizedAabbMax[3]; + }; + + +// -------------------------------------------------- // + class btOptimizedBvhNodeFloatData + { + public: + btVector3FloatData m_aabbMinOrg; + btVector3FloatData m_aabbMaxOrg; + int m_escapeIndex; + int m_subPart; + int m_triangleIndex; + char m_pad[4]; + }; + + +// -------------------------------------------------- // + class btOptimizedBvhNodeDoubleData + { + public: + btVector3DoubleData m_aabbMinOrg; + btVector3DoubleData m_aabbMaxOrg; + int m_escapeIndex; + int m_subPart; + int m_triangleIndex; + char m_pad[4]; + }; + + +// -------------------------------------------------- // + class btQuantizedBvhNodeData + { + public: + short m_quantizedAabbMin[3]; + short m_quantizedAabbMax[3]; + int m_escapeIndexOrTriangleIndex; + }; + + +// -------------------------------------------------- // + class btQuantizedBvhFloatData + { + public: + btVector3FloatData m_bvhAabbMin; + btVector3FloatData m_bvhAabbMax; + btVector3FloatData m_bvhQuantization; + int m_curNodeIndex; + int m_useQuantization; + int m_numContiguousLeafNodes; + int m_numQuantizedContiguousNodes; + btOptimizedBvhNodeFloatData *m_contiguousNodesPtr; + btQuantizedBvhNodeData *m_quantizedContiguousNodesPtr; + btBvhSubtreeInfoData *m_subTreeInfoPtr; + int m_traversalMode; + int m_numSubtreeHeaders; + }; + + +// -------------------------------------------------- // + class btQuantizedBvhDoubleData + { + public: + btVector3DoubleData m_bvhAabbMin; + btVector3DoubleData m_bvhAabbMax; + btVector3DoubleData m_bvhQuantization; + int m_curNodeIndex; + int m_useQuantization; + int m_numContiguousLeafNodes; + int m_numQuantizedContiguousNodes; + btOptimizedBvhNodeDoubleData *m_contiguousNodesPtr; + btQuantizedBvhNodeData *m_quantizedContiguousNodesPtr; + int m_traversalMode; + int m_numSubtreeHeaders; + btBvhSubtreeInfoData *m_subTreeInfoPtr; + }; + + +// -------------------------------------------------- // + class btCollisionShapeData + { + public: + char *m_name; + int m_shapeType; + char m_padding[4]; + }; + + +// -------------------------------------------------- // + class btStaticPlaneShapeData + { + public: + btCollisionShapeData m_collisionShapeData; + btVector3FloatData m_localScaling; + btVector3FloatData m_planeNormal; + float m_planeConstant; + char m_pad[4]; + }; + + +// -------------------------------------------------- // + class btConvexInternalShapeData + { + public: + btCollisionShapeData m_collisionShapeData; + btVector3FloatData m_localScaling; + btVector3FloatData m_implicitShapeDimensions; + float m_collisionMargin; + int m_padding; + }; + + +// -------------------------------------------------- // + class btPositionAndRadius + { + public: + btVector3FloatData m_pos; + float m_radius; + }; + + +// -------------------------------------------------- // + class btMultiSphereShapeData + { + public: + btConvexInternalShapeData m_convexInternalShapeData; + btPositionAndRadius *m_localPositionArrayPtr; + int m_localPositionArraySize; + char m_padding[4]; + }; + + +// -------------------------------------------------- // + class btIntIndexData + { + public: + int m_value; + }; + + +// -------------------------------------------------- // + class btShortIntIndexData + { + public: + short m_value; + char m_pad[2]; + }; + + +// -------------------------------------------------- // + class btShortIntIndexTripletData + { + public: + short m_values[3]; + char m_pad[2]; + }; + + +// -------------------------------------------------- // + class btCharIndexTripletData + { + public: + char m_values[3]; + char m_pad; + }; + + +// -------------------------------------------------- // + class btMeshPartData + { + public: + btVector3FloatData *m_vertices3f; + btVector3DoubleData *m_vertices3d; + btIntIndexData *m_indices32; + btShortIntIndexTripletData *m_3indices16; + btCharIndexTripletData *m_3indices8; + btShortIntIndexData *m_indices16; + int m_numTriangles; + int m_numVertices; + }; + + +// -------------------------------------------------- // + class btStridingMeshInterfaceData + { + public: + btMeshPartData *m_meshPartsPtr; + btVector3FloatData m_scaling; + int m_numMeshParts; + char m_padding[4]; + }; + + +// -------------------------------------------------- // + class btTriangleMeshShapeData + { + public: + btCollisionShapeData m_collisionShapeData; + btStridingMeshInterfaceData m_meshInterface; + btQuantizedBvhFloatData *m_quantizedFloatBvh; + btQuantizedBvhDoubleData *m_quantizedDoubleBvh; + btTriangleInfoMapData *m_triangleInfoMap; + float m_collisionMargin; + char m_pad3[4]; + }; + + +// -------------------------------------------------- // + class btScaledTriangleMeshShapeData + { + public: + btTriangleMeshShapeData m_trimeshShapeData; + btVector3FloatData m_localScaling; + }; + + +// -------------------------------------------------- // + class btCompoundShapeChildData + { + public: + btTransformFloatData m_transform; + btCollisionShapeData *m_childShape; + int m_childShapeType; + float m_childMargin; + }; + + +// -------------------------------------------------- // + class btCompoundShapeData + { + public: + btCollisionShapeData m_collisionShapeData; + btCompoundShapeChildData *m_childShapePtr; + int m_numChildShapes; + float m_collisionMargin; + }; + + +// -------------------------------------------------- // + class btCylinderShapeData + { + public: + btConvexInternalShapeData m_convexInternalShapeData; + int m_upAxis; + char m_padding[4]; + }; + + +// -------------------------------------------------- // + class btConeShapeData + { + public: + btConvexInternalShapeData m_convexInternalShapeData; + int m_upIndex; + char m_padding[4]; + }; + + +// -------------------------------------------------- // + class btCapsuleShapeData + { + public: + btConvexInternalShapeData m_convexInternalShapeData; + int m_upAxis; + char m_padding[4]; + }; + + +// -------------------------------------------------- // + class btTriangleInfoData + { + public: + int m_flags; + float m_edgeV0V1Angle; + float m_edgeV1V2Angle; + float m_edgeV2V0Angle; + }; + + +// -------------------------------------------------- // + class btTriangleInfoMapData + { + public: + int *m_hashTablePtr; + int *m_nextPtr; + btTriangleInfoData *m_valueArrayPtr; + int *m_keyArrayPtr; + float m_convexEpsilon; + float m_planarEpsilon; + float m_equalVertexThreshold; + float m_edgeDistanceThreshold; + float m_zeroAreaThreshold; + int m_nextSize; + int m_hashTableSize; + int m_numValues; + int m_numKeys; + char m_padding[4]; + }; + + +// -------------------------------------------------- // + class btGImpactMeshShapeData + { + public: + btCollisionShapeData m_collisionShapeData; + btStridingMeshInterfaceData m_meshInterface; + btVector3FloatData m_localScaling; + float m_collisionMargin; + int m_gimpactSubType; + }; + + +// -------------------------------------------------- // + class btConvexHullShapeData + { + public: + btConvexInternalShapeData m_convexInternalShapeData; + btVector3FloatData *m_unscaledPointsFloatPtr; + btVector3DoubleData *m_unscaledPointsDoublePtr; + int m_numUnscaledPoints; + char m_padding3[4]; + }; + + +// -------------------------------------------------- // + class btCollisionObjectDoubleData + { + public: + void *m_broadphaseHandle; + void *m_collisionShape; + btCollisionShapeData *m_rootCollisionShape; + char *m_name; + btTransformDoubleData m_worldTransform; + btTransformDoubleData m_interpolationWorldTransform; + btVector3DoubleData m_interpolationLinearVelocity; + btVector3DoubleData m_interpolationAngularVelocity; + btVector3DoubleData m_anisotropicFriction; + double m_contactProcessingThreshold; + double m_deactivationTime; + double m_friction; + double m_rollingFriction; + double m_restitution; + double m_hitFraction; + double m_ccdSweptSphereRadius; + double m_ccdMotionThreshold; + int m_hasAnisotropicFriction; + int m_collisionFlags; + int m_islandTag1; + int m_companionId; + int m_activationState1; + int m_internalType; + int m_checkCollideWith; + char m_padding[4]; + }; + + +// -------------------------------------------------- // + class btCollisionObjectFloatData + { + public: + void *m_broadphaseHandle; + void *m_collisionShape; + btCollisionShapeData *m_rootCollisionShape; + char *m_name; + btTransformFloatData m_worldTransform; + btTransformFloatData m_interpolationWorldTransform; + btVector3FloatData m_interpolationLinearVelocity; + btVector3FloatData m_interpolationAngularVelocity; + btVector3FloatData m_anisotropicFriction; + float m_contactProcessingThreshold; + float m_deactivationTime; + float m_friction; + float m_rollingFriction; + float m_restitution; + float m_hitFraction; + float m_ccdSweptSphereRadius; + float m_ccdMotionThreshold; + int m_hasAnisotropicFriction; + int m_collisionFlags; + int m_islandTag1; + int m_companionId; + int m_activationState1; + int m_internalType; + int m_checkCollideWith; + char m_padding[4]; + }; + + +// -------------------------------------------------- // + class btDynamicsWorldDoubleData + { + public: + btContactSolverInfoDoubleData m_solverInfo; + btVector3DoubleData m_gravity; + }; + + +// -------------------------------------------------- // + class btDynamicsWorldFloatData + { + public: + btContactSolverInfoFloatData m_solverInfo; + btVector3FloatData m_gravity; + }; + + +// -------------------------------------------------- // + class btRigidBodyFloatData + { + public: + btCollisionObjectFloatData m_collisionObjectData; + btMatrix3x3FloatData m_invInertiaTensorWorld; + btVector3FloatData m_linearVelocity; + btVector3FloatData m_angularVelocity; + btVector3FloatData m_angularFactor; + btVector3FloatData m_linearFactor; + btVector3FloatData m_gravity; + btVector3FloatData m_gravity_acceleration; + btVector3FloatData m_invInertiaLocal; + btVector3FloatData m_totalForce; + btVector3FloatData m_totalTorque; + float m_inverseMass; + float m_linearDamping; + float m_angularDamping; + float m_additionalDampingFactor; + float m_additionalLinearDampingThresholdSqr; + float m_additionalAngularDampingThresholdSqr; + float m_additionalAngularDampingFactor; + float m_linearSleepingThreshold; + float m_angularSleepingThreshold; + int m_additionalDamping; + }; + + +// -------------------------------------------------- // + class btRigidBodyDoubleData + { + public: + btCollisionObjectDoubleData m_collisionObjectData; + btMatrix3x3DoubleData m_invInertiaTensorWorld; + btVector3DoubleData m_linearVelocity; + btVector3DoubleData m_angularVelocity; + btVector3DoubleData m_angularFactor; + btVector3DoubleData m_linearFactor; + btVector3DoubleData m_gravity; + btVector3DoubleData m_gravity_acceleration; + btVector3DoubleData m_invInertiaLocal; + btVector3DoubleData m_totalForce; + btVector3DoubleData m_totalTorque; + double m_inverseMass; + double m_linearDamping; + double m_angularDamping; + double m_additionalDampingFactor; + double m_additionalLinearDampingThresholdSqr; + double m_additionalAngularDampingThresholdSqr; + double m_additionalAngularDampingFactor; + double m_linearSleepingThreshold; + double m_angularSleepingThreshold; + int m_additionalDamping; + char m_padding[4]; + }; + + +// -------------------------------------------------- // + class btConstraintInfo1 + { + public: + int m_numConstraintRows; + int nub; + }; + + +// -------------------------------------------------- // + class btTypedConstraintFloatData + { + public: + btRigidBodyFloatData *m_rbA; + btRigidBodyFloatData *m_rbB; + char *m_name; + int m_objectType; + int m_userConstraintType; + int m_userConstraintId; + int m_needsFeedback; + float m_appliedImpulse; + float m_dbgDrawSize; + int m_disableCollisionsBetweenLinkedBodies; + int m_overrideNumSolverIterations; + float m_breakingImpulseThreshold; + int m_isEnabled; + }; + + +// -------------------------------------------------- // + class btTypedConstraintData + { + public: + bInvalidHandle *m_rbA; + bInvalidHandle *m_rbB; + char *m_name; + int m_objectType; + int m_userConstraintType; + int m_userConstraintId; + int m_needsFeedback; + float m_appliedImpulse; + float m_dbgDrawSize; + int m_disableCollisionsBetweenLinkedBodies; + int m_overrideNumSolverIterations; + float m_breakingImpulseThreshold; + int m_isEnabled; + }; + + +// -------------------------------------------------- // + class btTypedConstraintDoubleData + { + public: + btRigidBodyDoubleData *m_rbA; + btRigidBodyDoubleData *m_rbB; + char *m_name; + int m_objectType; + int m_userConstraintType; + int m_userConstraintId; + int m_needsFeedback; + double m_appliedImpulse; + double m_dbgDrawSize; + int m_disableCollisionsBetweenLinkedBodies; + int m_overrideNumSolverIterations; + double m_breakingImpulseThreshold; + int m_isEnabled; + char padding[4]; + }; + + +// -------------------------------------------------- // + class btPoint2PointConstraintFloatData + { + public: + btTypedConstraintData m_typeConstraintData; + btVector3FloatData m_pivotInA; + btVector3FloatData m_pivotInB; + }; + + +// -------------------------------------------------- // + class btPoint2PointConstraintDoubleData2 + { + public: + btTypedConstraintDoubleData m_typeConstraintData; + btVector3DoubleData m_pivotInA; + btVector3DoubleData m_pivotInB; + }; + + +// -------------------------------------------------- // + class btPoint2PointConstraintDoubleData + { + public: + btTypedConstraintData m_typeConstraintData; + btVector3DoubleData m_pivotInA; + btVector3DoubleData m_pivotInB; + }; + + +// -------------------------------------------------- // + class btHingeConstraintDoubleData + { + public: + btTypedConstraintData m_typeConstraintData; + btTransformDoubleData m_rbAFrame; + btTransformDoubleData m_rbBFrame; + int m_useReferenceFrameA; + int m_angularOnly; + int m_enableAngularMotor; + float m_motorTargetVelocity; + float m_maxMotorImpulse; + float m_lowerLimit; + float m_upperLimit; + float m_limitSoftness; + float m_biasFactor; + float m_relaxationFactor; + }; + + +// -------------------------------------------------- // + class btHingeConstraintFloatData + { + public: + btTypedConstraintData m_typeConstraintData; + btTransformFloatData m_rbAFrame; + btTransformFloatData m_rbBFrame; + int m_useReferenceFrameA; + int m_angularOnly; + int m_enableAngularMotor; + float m_motorTargetVelocity; + float m_maxMotorImpulse; + float m_lowerLimit; + float m_upperLimit; + float m_limitSoftness; + float m_biasFactor; + float m_relaxationFactor; + }; + + +// -------------------------------------------------- // + class btHingeConstraintDoubleData2 + { + public: + btTypedConstraintDoubleData m_typeConstraintData; + btTransformDoubleData m_rbAFrame; + btTransformDoubleData m_rbBFrame; + int m_useReferenceFrameA; + int m_angularOnly; + int m_enableAngularMotor; + double m_motorTargetVelocity; + double m_maxMotorImpulse; + double m_lowerLimit; + double m_upperLimit; + double m_limitSoftness; + double m_biasFactor; + double m_relaxationFactor; + char m_padding1[4]; + }; + + +// -------------------------------------------------- // + class btConeTwistConstraintDoubleData + { + public: + btTypedConstraintDoubleData m_typeConstraintData; + btTransformDoubleData m_rbAFrame; + btTransformDoubleData m_rbBFrame; + double m_swingSpan1; + double m_swingSpan2; + double m_twistSpan; + double m_limitSoftness; + double m_biasFactor; + double m_relaxationFactor; + double m_damping; + }; + + +// -------------------------------------------------- // + class btConeTwistConstraintData + { + public: + btTypedConstraintData m_typeConstraintData; + btTransformFloatData m_rbAFrame; + btTransformFloatData m_rbBFrame; + float m_swingSpan1; + float m_swingSpan2; + float m_twistSpan; + float m_limitSoftness; + float m_biasFactor; + float m_relaxationFactor; + float m_damping; + char m_pad[4]; + }; + + +// -------------------------------------------------- // + class btGeneric6DofConstraintData + { + public: + btTypedConstraintData m_typeConstraintData; + btTransformFloatData m_rbAFrame; + btTransformFloatData m_rbBFrame; + btVector3FloatData m_linearUpperLimit; + btVector3FloatData m_linearLowerLimit; + btVector3FloatData m_angularUpperLimit; + btVector3FloatData m_angularLowerLimit; + int m_useLinearReferenceFrameA; + int m_useOffsetForConstraintFrame; + }; + + +// -------------------------------------------------- // + class btGeneric6DofConstraintDoubleData2 + { + public: + btTypedConstraintDoubleData m_typeConstraintData; + btTransformDoubleData m_rbAFrame; + btTransformDoubleData m_rbBFrame; + btVector3DoubleData m_linearUpperLimit; + btVector3DoubleData m_linearLowerLimit; + btVector3DoubleData m_angularUpperLimit; + btVector3DoubleData m_angularLowerLimit; + int m_useLinearReferenceFrameA; + int m_useOffsetForConstraintFrame; + }; + + +// -------------------------------------------------- // + class btGeneric6DofSpringConstraintData + { + public: + btGeneric6DofConstraintData m_6dofData; + int m_springEnabled[6]; + float m_equilibriumPoint[6]; + float m_springStiffness[6]; + float m_springDamping[6]; + }; + + +// -------------------------------------------------- // + class btGeneric6DofSpringConstraintDoubleData2 + { + public: + btGeneric6DofConstraintDoubleData2 m_6dofData; + int m_springEnabled[6]; + double m_equilibriumPoint[6]; + double m_springStiffness[6]; + double m_springDamping[6]; + }; + + +// -------------------------------------------------- // + class btSliderConstraintData + { + public: + btTypedConstraintData m_typeConstraintData; + btTransformFloatData m_rbAFrame; + btTransformFloatData m_rbBFrame; + float m_linearUpperLimit; + float m_linearLowerLimit; + float m_angularUpperLimit; + float m_angularLowerLimit; + int m_useLinearReferenceFrameA; + int m_useOffsetForConstraintFrame; + }; + + +// -------------------------------------------------- // + class btSliderConstraintDoubleData + { + public: + btTypedConstraintDoubleData m_typeConstraintData; + btTransformDoubleData m_rbAFrame; + btTransformDoubleData m_rbBFrame; + double m_linearUpperLimit; + double m_linearLowerLimit; + double m_angularUpperLimit; + double m_angularLowerLimit; + int m_useLinearReferenceFrameA; + int m_useOffsetForConstraintFrame; + }; + + +// -------------------------------------------------- // + class btGearConstraintFloatData + { + public: + btTypedConstraintFloatData m_typeConstraintData; + btVector3FloatData m_axisInA; + btVector3FloatData m_axisInB; + float m_ratio; + char m_padding[4]; + }; + + +// -------------------------------------------------- // + class btGearConstraintDoubleData + { + public: + btTypedConstraintDoubleData m_typeConstraintData; + btVector3DoubleData m_axisInA; + btVector3DoubleData m_axisInB; + double m_ratio; + }; + + +// -------------------------------------------------- // + class btContactSolverInfoDoubleData + { + public: + double m_tau; + double m_damping; + double m_friction; + double m_timeStep; + double m_restitution; + double m_maxErrorReduction; + double m_sor; + double m_erp; + double m_erp2; + double m_globalCfm; + double m_splitImpulsePenetrationThreshold; + double m_splitImpulseTurnErp; + double m_linearSlop; + double m_warmstartingFactor; + double m_maxGyroscopicForce; + double m_singleAxisRollingFrictionThreshold; + int m_numIterations; + int m_solverMode; + int m_restingContactRestitutionThreshold; + int m_minimumSolverBatchSize; + int m_splitImpulse; + char m_padding[4]; + }; + + +// -------------------------------------------------- // + class btContactSolverInfoFloatData + { + public: + float m_tau; + float m_damping; + float m_friction; + float m_timeStep; + float m_restitution; + float m_maxErrorReduction; + float m_sor; + float m_erp; + float m_erp2; + float m_globalCfm; + float m_splitImpulsePenetrationThreshold; + float m_splitImpulseTurnErp; + float m_linearSlop; + float m_warmstartingFactor; + float m_maxGyroscopicForce; + float m_singleAxisRollingFrictionThreshold; + int m_numIterations; + int m_solverMode; + int m_restingContactRestitutionThreshold; + int m_minimumSolverBatchSize; + int m_splitImpulse; + char m_padding[4]; + }; + + +// -------------------------------------------------- // + class SoftBodyMaterialData + { + public: + float m_linearStiffness; + float m_angularStiffness; + float m_volumeStiffness; + int m_flags; + }; + + +// -------------------------------------------------- // + class SoftBodyNodeData + { + public: + SoftBodyMaterialData *m_material; + btVector3FloatData m_position; + btVector3FloatData m_previousPosition; + btVector3FloatData m_velocity; + btVector3FloatData m_accumulatedForce; + btVector3FloatData m_normal; + float m_inverseMass; + float m_area; + int m_attach; + int m_pad; + }; + + +// -------------------------------------------------- // + class SoftBodyLinkData + { + public: + SoftBodyMaterialData *m_material; + int m_nodeIndices[2]; + float m_restLength; + int m_bbending; + }; + + +// -------------------------------------------------- // + class SoftBodyFaceData + { + public: + btVector3FloatData m_normal; + SoftBodyMaterialData *m_material; + int m_nodeIndices[3]; + float m_restArea; + }; + + +// -------------------------------------------------- // + class SoftBodyTetraData + { + public: + btVector3FloatData m_c0[4]; + SoftBodyMaterialData *m_material; + int m_nodeIndices[4]; + float m_restVolume; + float m_c1; + float m_c2; + int m_pad; + }; + + +// -------------------------------------------------- // + class SoftRigidAnchorData + { + public: + btMatrix3x3FloatData m_c0; + btVector3FloatData m_c1; + btVector3FloatData m_localFrame; + bInvalidHandle *m_rigidBody; + int m_nodeIndex; + float m_c2; + }; + + +// -------------------------------------------------- // + class SoftBodyConfigData + { + public: + int m_aeroModel; + float m_baumgarte; + float m_damping; + float m_drag; + float m_lift; + float m_pressure; + float m_volume; + float m_dynamicFriction; + float m_poseMatch; + float m_rigidContactHardness; + float m_kineticContactHardness; + float m_softContactHardness; + float m_anchorHardness; + float m_softRigidClusterHardness; + float m_softKineticClusterHardness; + float m_softSoftClusterHardness; + float m_softRigidClusterImpulseSplit; + float m_softKineticClusterImpulseSplit; + float m_softSoftClusterImpulseSplit; + float m_maxVolume; + float m_timeScale; + int m_velocityIterations; + int m_positionIterations; + int m_driftIterations; + int m_clusterIterations; + int m_collisionFlags; + }; + + +// -------------------------------------------------- // + class SoftBodyPoseData + { + public: + btMatrix3x3FloatData m_rot; + btMatrix3x3FloatData m_scale; + btMatrix3x3FloatData m_aqq; + btVector3FloatData m_com; + btVector3FloatData *m_positions; + float *m_weights; + int m_numPositions; + int m_numWeigts; + int m_bvolume; + int m_bframe; + float m_restVolume; + int m_pad; + }; + + +// -------------------------------------------------- // + class SoftBodyClusterData + { + public: + btTransformFloatData m_framexform; + btMatrix3x3FloatData m_locii; + btMatrix3x3FloatData m_invwi; + btVector3FloatData m_com; + btVector3FloatData m_vimpulses[2]; + btVector3FloatData m_dimpulses[2]; + btVector3FloatData m_lv; + btVector3FloatData m_av; + btVector3FloatData *m_framerefs; + int *m_nodeIndices; + float *m_masses; + int m_numFrameRefs; + int m_numNodes; + int m_numMasses; + float m_idmass; + float m_imass; + int m_nvimpulses; + int m_ndimpulses; + float m_ndamping; + float m_ldamping; + float m_adamping; + float m_matching; + float m_maxSelfCollisionImpulse; + float m_selfCollisionImpulseFactor; + int m_containsAnchor; + int m_collide; + int m_clusterIndex; + }; + + +// -------------------------------------------------- // + class btSoftBodyJointData + { + public: + void *m_bodyA; + void *m_bodyB; + btVector3FloatData m_refs[2]; + float m_cfm; + float m_erp; + float m_split; + int m_delete; + btVector3FloatData m_relPosition[2]; + int m_bodyAtype; + int m_bodyBtype; + int m_jointType; + int m_pad; + }; + + +// -------------------------------------------------- // + class btSoftBodyFloatData + { + public: + btCollisionObjectFloatData m_collisionObjectData; + SoftBodyPoseData *m_pose; + SoftBodyMaterialData **m_materials; + SoftBodyNodeData *m_nodes; + SoftBodyLinkData *m_links; + SoftBodyFaceData *m_faces; + SoftBodyTetraData *m_tetrahedra; + SoftRigidAnchorData *m_anchors; + SoftBodyClusterData *m_clusters; + btSoftBodyJointData *m_joints; + int m_numMaterials; + int m_numNodes; + int m_numLinks; + int m_numFaces; + int m_numTetrahedra; + int m_numAnchors; + int m_numClusters; + int m_numJoints; + SoftBodyConfigData m_config; + }; + + +} +#endif//__BULLET_H__ \ No newline at end of file diff --git a/Code/Physics/Bullet Source/BulletFileLoader/bChunk.cpp b/Code/Physics/Bullet Source/BulletFileLoader/bChunk.cpp new file mode 100644 index 00000000..564e5507 --- /dev/null +++ b/Code/Physics/Bullet Source/BulletFileLoader/bChunk.cpp @@ -0,0 +1,75 @@ +/* +bParse +Copyright (c) 2006-2009 Charlie C & Erwin Coumans http://gamekit.googlecode.com + +This software is provided 'as-is', without any express or implied warranty. +In no event will the authors be held liable for any damages arising from the use of this software. +Permission is granted to anyone to use this software for any purpose, +including commercial applications, and to alter it and redistribute it freely, +subject to the following restrictions: + +1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. +2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. +3. This notice may not be removed or altered from any source distribution. +*/ + +#include "bChunk.h" +#include "bDefines.h" +#include "bFile.h" + +#if !defined( __CELLOS_LV2__) && !defined(__MWERKS__) +#include +#endif +#include + + +using namespace bParse; + + +// ----------------------------------------------------- // +short ChunkUtils::swapShort(short sht) +{ + SWITCH_SHORT(sht); + return sht; +} + +// ----------------------------------------------------- // +int ChunkUtils::swapInt(int inte) +{ + SWITCH_INT(inte); + return inte; +} + +// ----------------------------------------------------- // +long64 ChunkUtils::swapLong64(long64 lng) +{ + SWITCH_LONGINT(lng); + return lng; +} + +// ----------------------------------------------------- // +int ChunkUtils::getOffset(int flags) +{ + // if the file is saved in a + // different format, get the + // file's chunk size + int res = CHUNK_HEADER_LEN; + + if (VOID_IS_8) + { + if (flags &FD_BITS_VARIES) + res = sizeof(bChunkPtr4); + } + else + { + if (flags &FD_BITS_VARIES) + res = sizeof(bChunkPtr8); + } + return res; +} + + + + + +//eof diff --git a/Code/Physics/Bullet Source/BulletFileLoader/bChunk.h b/Code/Physics/Bullet Source/BulletFileLoader/bChunk.h new file mode 100644 index 00000000..77039bcf --- /dev/null +++ b/Code/Physics/Bullet Source/BulletFileLoader/bChunk.h @@ -0,0 +1,92 @@ +/* +bParse +Copyright (c) 2006-2009 Charlie C & Erwin Coumans http://gamekit.googlecode.com + +This software is provided 'as-is', without any express or implied warranty. +In no event will the authors be held liable for any damages arising from the use of this software. +Permission is granted to anyone to use this software for any purpose, +including commercial applications, and to alter it and redistribute it freely, +subject to the following restrictions: + +1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. +2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. +3. This notice may not be removed or altered from any source distribution. +*/ + +#ifndef __BCHUNK_H__ +#define __BCHUNK_H__ + +#if defined (_WIN32) && ! defined (__MINGW32__) + #define long64 __int64 +#elif defined (__MINGW32__) + #include + #define long64 int64_t +#else + #define long64 long long +#endif + + +namespace bParse { + + + // ----------------------------------------------------- // + class bChunkPtr4 + { + public: + bChunkPtr4(){} + int code; + int len; + union + { + int m_uniqueInt; + }; + int dna_nr; + int nr; + }; + + // ----------------------------------------------------- // + class bChunkPtr8 + { + public: + bChunkPtr8(){} + int code, len; + union + { + long64 oldPrev; + int m_uniqueInts[2]; + }; + int dna_nr, nr; + }; + + // ----------------------------------------------------- // + class bChunkInd + { + public: + bChunkInd(){} + int code, len; + void *oldPtr; + int dna_nr, nr; + }; + + + // ----------------------------------------------------- // + class ChunkUtils + { + public: + + // file chunk offset + static int getOffset(int flags); + + // endian utils + static short swapShort(short sht); + static int swapInt(int inte); + static long64 swapLong64(long64 lng); + + }; + + + const int CHUNK_HEADER_LEN = ((sizeof(bChunkInd))); + const bool VOID_IS_8 = ((sizeof(void*)==8)); +} + +#endif//__BCHUNK_H__ diff --git a/Code/Physics/Bullet Source/BulletFileLoader/bCommon.h b/Code/Physics/Bullet Source/BulletFileLoader/bCommon.h new file mode 100644 index 00000000..b01d2b89 --- /dev/null +++ b/Code/Physics/Bullet Source/BulletFileLoader/bCommon.h @@ -0,0 +1,39 @@ +/* +bParse +Copyright (c) 2006-2009 Charlie C & Erwin Coumans http://gamekit.googlecode.com + +This software is provided 'as-is', without any express or implied warranty. +In no event will the authors be held liable for any damages arising from the use of this software. +Permission is granted to anyone to use this software for any purpose, +including commercial applications, and to alter it and redistribute it freely, +subject to the following restrictions: + +1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. +2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. +3. This notice may not be removed or altered from any source distribution. +*/ + +#ifndef __BCOMMON_H__ +#define __BCOMMON_H__ + + +#include +//#include "bLog.h" +#include "LinearMath/btAlignedObjectArray.h" +#include "LinearMath/btHashMap.h" + +namespace bParse { + + class bMain; + class bFileData; + class bFile; + class bDNA; + + // delete void* undefined + typedef struct bStructHandle {int unused;}bStructHandle; + typedef btAlignedObjectArray bListBasePtr; + typedef btHashMap bPtrMap; +} + + +#endif//__BCOMMON_H__ diff --git a/Code/Physics/Bullet Source/BulletFileLoader/bDNA.cpp b/Code/Physics/Bullet Source/BulletFileLoader/bDNA.cpp new file mode 100644 index 00000000..a362767b --- /dev/null +++ b/Code/Physics/Bullet Source/BulletFileLoader/bDNA.cpp @@ -0,0 +1,644 @@ +/* +bParse +Copyright (c) 2006-2009 Charlie C & Erwin Coumans http://gamekit.googlecode.com + +This software is provided 'as-is', without any express or implied warranty. +In no event will the authors be held liable for any damages arising from the use of this software. +Permission is granted to anyone to use this software for any purpose, +including commercial applications, and to alter it and redistribute it freely, +subject to the following restrictions: + +1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. +2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. +3. This notice may not be removed or altered from any source distribution. +*/ +#include + +#include "bDNA.h" +#include "bChunk.h" +#include +#include +#include + +//this define will force traversal of structures, to check backward (and forward) compatibility +//#define TEST_BACKWARD_FORWARD_COMPATIBILITY + + +using namespace bParse; + + +// ----------------------------------------------------- // +bDNA::bDNA() + : mPtrLen(0) +{ + // -- +} + +// ----------------------------------------------------- // +bDNA::~bDNA() +{ + // -- +} + +// ----------------------------------------------------- // +bool bDNA::lessThan(bDNA *file) +{ + return ( m_Names.size() < file->m_Names.size()); +} + +// ----------------------------------------------------- // +char *bDNA::getName(int ind) +{ + assert(ind <= (int)m_Names.size()); + return m_Names[ind].m_name; +} + + +// ----------------------------------------------------- // +char *bDNA::getType(int ind) +{ + assert(ind<= (int)mTypes.size()); + return mTypes[ind]; +} + + +// ----------------------------------------------------- // +short *bDNA::getStruct(int ind) +{ + assert(ind <= (int)mStructs.size()); + return mStructs[ind]; +} + + +// ----------------------------------------------------- // +short bDNA::getLength(int ind) +{ + assert(ind <= (int)mTlens.size()); + return mTlens[ind]; +} + + +// ----------------------------------------------------- // +int bDNA::getReverseType(short type) +{ + + int* intPtr = mStructReverse.find(type); + if (intPtr) + return *intPtr; + + return -1; +} + +// ----------------------------------------------------- // +int bDNA::getReverseType(const char *type) +{ + + btHashString key(type); + int* valuePtr = mTypeLookup.find(key); + if (valuePtr) + return *valuePtr; + + return -1; +} + +// ----------------------------------------------------- // +int bDNA::getNumStructs() +{ + return (int)mStructs.size(); +} + +// ----------------------------------------------------- // +bool bDNA::flagNotEqual(int dna_nr) +{ + assert(dna_nr <= (int)mCMPFlags.size()); + return mCMPFlags[dna_nr] == FDF_STRUCT_NEQU; +} + +// ----------------------------------------------------- // +bool bDNA::flagEqual(int dna_nr) +{ + assert(dna_nr <= (int)mCMPFlags.size()); + int flag = mCMPFlags[dna_nr]; + return flag == FDF_STRUCT_EQU; +} + +// ----------------------------------------------------- // +bool bDNA::flagNone(int dna_nr) +{ + assert(dna_nr <= (int)mCMPFlags.size()); + return mCMPFlags[dna_nr] == FDF_NONE; +} + +// ----------------------------------------------------- // +int bDNA::getPointerSize() +{ + return mPtrLen; +} + +// ----------------------------------------------------- // +void bDNA::initRecurseCmpFlags(int iter) +{ + // iter is FDF_STRUCT_NEQU + + short *oldStrc = mStructs[iter]; + short type = oldStrc[0]; + + for (int i=0; i<(int)mStructs.size(); i++) + { + if (i != iter && mCMPFlags[i] == FDF_STRUCT_EQU ) + { + short *curStruct = mStructs[i]; + int eleLen = curStruct[1]; + curStruct+=2; + + for (int j=0; jgetReverseType(typeName); + if (newLookup == -1) + { + mCMPFlags[i] = FDF_NONE; + continue; + } + short *curStruct = memDNA->mStructs[newLookup]; +#else + // memory for file + + if (oldLookup < memDNA->mStructs.size()) + { + short *curStruct = memDNA->mStructs[oldLookup]; +#endif + + + + // rebuild... + mCMPFlags[i] = FDF_STRUCT_NEQU; + +#ifndef TEST_BACKWARD_FORWARD_COMPATIBILITY + + if (curStruct[1] == oldStruct[1]) + { + // type len same ... + if (mTlens[oldStruct[0]] == memDNA->mTlens[curStruct[0]]) + { + bool isSame = true; + int elementLength = oldStruct[1]; + + + curStruct+=2; + oldStruct+=2; + + + for (int j=0; jmTypes[curStruct[0]])!=0) + { + isSame=false; + break; + } + + // name the same + if (strcmp(m_Names[oldStruct[1]].m_name, memDNA->m_Names[curStruct[1]].m_name)!=0) + { + isSame=false; + break; + } + } + // flag valid == + if (isSame) + mCMPFlags[i] = FDF_STRUCT_EQU; + } + } +#endif + } + } + + + + + + // recurse in + for ( i=0; i<(int)mStructs.size(); i++) + { + if (mCMPFlags[i] == FDF_STRUCT_NEQU) + initRecurseCmpFlags(i); + } +} + + + + +static int name_is_array(char* name, int* dim1, int* dim2) { + int len = strlen(name); + /*fprintf(stderr,"[%s]",name);*/ + /*if (len >= 1) { + if (name[len-1] != ']') + return 1; + } + return 0;*/ + char *bp; + int num; + if (dim1) { + *dim1 = 1; + } + if (dim2) { + *dim2 = 1; + } + bp = strchr(name, '['); + if (!bp) { + return 0; + } + num = 0; + while (++bp < name+len-1) { + const char c = *bp; + if (c == ']') { + break; + } + if (c <= '9' && c >= '0') { + num *= 10; + num += (c - '0'); + } else { + printf("array parse error.\n"); + return 0; + } + } + if (dim2) { + *dim2 = num; + } + + /* find second dim, if any. */ + bp = strchr(bp, '['); + if (!bp) { + return 1; /* at least we got the first dim. */ + } + num = 0; + while (++bp < name+len-1) { + const char c = *bp; + if (c == ']') { + break; + } + if (c <= '9' && c >= '0') { + num *= 10; + num += (c - '0'); + } else { + printf("array2 parse error.\n"); + return 1; + } + } + if (dim1) { + if (dim2) { + *dim1 = *dim2; + *dim2 = num; + } else { + *dim1 = num; + } + } + + return 1; +} + + +// ----------------------------------------------------- // +void bDNA::init(char *data, int len, bool swap) +{ + int *intPtr=0;short *shtPtr=0; + char *cp = 0;int dataLen =0;long nr=0; + intPtr = (int*)data; + + /* + SDNA (4 bytes) (magic number) + NAME (4 bytes) + (4 bytes) amount of names (int) + + + */ + + if (strncmp(data, "SDNA", 4)==0) + { + // skip ++ NAME + intPtr++; intPtr++; + } + + + + // Parse names + if (swap) + { + *intPtr = ChunkUtils::swapInt(*intPtr); + } + dataLen = *intPtr; + intPtr++; + + cp = (char*)intPtr; + int i; + for ( i=0; i amount of types (int) + + + */ + + intPtr = (int*)cp; + assert(strncmp(cp, "TYPE", 4)==0); intPtr++; + + if (swap) + { + *intPtr = ChunkUtils::swapInt(*intPtr); + } + dataLen = *intPtr; + intPtr++; + + cp = (char*)intPtr; + for ( i=0; i (short) the lengths of types + + */ + + // Parse type lens + intPtr = (int*)cp; + assert(strncmp(cp, "TLEN", 4)==0); intPtr++; + + dataLen = (int)mTypes.size(); + + shtPtr = (short*)intPtr; + for ( i=0; i amount of structs (int) + + + + + + + */ + + intPtr = (int*)shtPtr; + cp = (char*)intPtr; + assert(strncmp(cp, "STRC", 4)==0); intPtr++; + + if (swap) + { + *intPtr = ChunkUtils::swapInt(*intPtr); + } + dataLen = *intPtr; + intPtr++; + + + shtPtr = (short*)intPtr; + for ( i=0; itypes_count; ++i) { + /* if (!bf->types[i].is_struct)*/ + { + printf("%3d: sizeof(%s%s)=%d", + i, + bf->types[i].is_struct ? "struct " : "atomic ", + bf->types[i].name, bf->types[i].size); + if (bf->types[i].is_struct) { + int j; + printf(", %d fields: { ", bf->types[i].fieldtypes_count); + for (j=0; jtypes[i].fieldtypes_count; ++j) { + printf("%s %s", + bf->types[bf->types[i].fieldtypes[j]].name, + bf->names[bf->types[i].fieldnames[j]]); + if (j == bf->types[i].fieldtypes_count-1) { + printf(";}"); + } else { + printf("; "); + } + } + } + printf("\n\n"); + + } + } +#endif + +} + + + + +//eof + + diff --git a/Code/Physics/Bullet Source/BulletFileLoader/bDNA.h b/Code/Physics/Bullet Source/BulletFileLoader/bDNA.h new file mode 100644 index 00000000..691080bf --- /dev/null +++ b/Code/Physics/Bullet Source/BulletFileLoader/bDNA.h @@ -0,0 +1,110 @@ +/* +bParse +Copyright (c) 2006-2009 Charlie C & Erwin Coumans http://gamekit.googlecode.com + +This software is provided 'as-is', without any express or implied warranty. +In no event will the authors be held liable for any damages arising from the use of this software. +Permission is granted to anyone to use this software for any purpose, +including commercial applications, and to alter it and redistribute it freely, +subject to the following restrictions: + +1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. +2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. +3. This notice may not be removed or altered from any source distribution. +*/ + +#ifndef __BDNA_H__ +#define __BDNA_H__ + + +#include "bCommon.h" + +namespace bParse { + + struct bNameInfo + { + char* m_name; + bool m_isPointer; + int m_dim0; + int m_dim1; + }; + + class bDNA + { + public: + bDNA(); + ~bDNA(); + + void init(char *data, int len, bool swap=false); + + int getArraySize(char* str); + int getArraySizeNew(short name) + { + const bNameInfo& nameInfo = m_Names[name]; + return nameInfo.m_dim0*nameInfo.m_dim1; + } + int getElementSize(short type, short name) + { + const bNameInfo& nameInfo = m_Names[name]; + int size = nameInfo.m_isPointer ? mPtrLen*nameInfo.m_dim0*nameInfo.m_dim1 : mTlens[type]*nameInfo.m_dim0*nameInfo.m_dim1; + return size; + } + + int getNumNames() const + { + return m_Names.size(); + } + + char *getName(int ind); + char *getType(int ind); + short *getStruct(int ind); + short getLength(int ind); + int getReverseType(short type); + int getReverseType(const char *type); + + + int getNumStructs(); + + // + bool lessThan(bDNA* other); + + void initCmpFlags(bDNA *memDNA); + bool flagNotEqual(int dna_nr); + bool flagEqual(int dna_nr); + bool flagNone(int dna_nr); + + + int getPointerSize(); + + void dumpTypeDefinitions(); + + + private: + enum FileDNAFlags + { + FDF_NONE=0, + FDF_STRUCT_NEQU, + FDF_STRUCT_EQU + }; + + void initRecurseCmpFlags(int i); + + btAlignedObjectArray mCMPFlags; + + btAlignedObjectArray m_Names; + btAlignedObjectArray mTypes; + btAlignedObjectArray mStructs; + btAlignedObjectArray mTlens; + btHashMap mStructReverse; + btHashMap mTypeLookup; + + int mPtrLen; + + + + + }; +} + + +#endif//__BDNA_H__ diff --git a/Code/Physics/Bullet Source/BulletFileLoader/bDefines.h b/Code/Physics/Bullet Source/BulletFileLoader/bDefines.h new file mode 100644 index 00000000..238df7d4 --- /dev/null +++ b/Code/Physics/Bullet Source/BulletFileLoader/bDefines.h @@ -0,0 +1,140 @@ +/* Copyright (C) 2006-2009 Charlie C & Erwin Coumans http://gamekit.googlecode.com +* +* This software is provided 'as-is', without any express or implied +* warranty. In no event will the authors be held liable for any damages +* arising from the use of this software. +* +* Permission is granted to anyone to use this software for any purpose, +* including commercial applications, and to alter it and redistribute it +* freely, subject to the following restrictions: +* +* 1. The origin of this software must not be misrepresented; you must not +* claim that you wrote the original software. If you use this software +* in a product, an acknowledgment in the product documentation would be +* appreciated but is not required. +* 2. Altered source versions must be plainly marked as such, and must not be +* misrepresented as being the original software. +* 3. This notice may not be removed or altered from any source distribution. +*/ +#ifndef __B_DEFINES_H__ +#define __B_DEFINES_H__ + + +// MISC defines, see BKE_global.h, BKE_utildefines.h +#define SIZEOFBLENDERHEADER 12 + + +// ------------------------------------------------------------ +#if defined(__sgi) || defined (__sparc) || defined (__sparc__) || defined (__PPC__) || defined (__ppc__) || defined (__BIG_ENDIAN__) +# define MAKE_ID(a,b,c,d) ( (int)(a)<<24 | (int)(b)<<16 | (c)<<8 | (d) ) +#else +# define MAKE_ID(a,b,c,d) ( (int)(d)<<24 | (int)(c)<<16 | (b)<<8 | (a) ) +#endif + + +// ------------------------------------------------------------ +#if defined(__sgi) || defined(__sparc) || defined(__sparc__) || defined (__PPC__) || defined (__ppc__) || defined (__BIG_ENDIAN__) +# define MAKE_ID2(c, d) ( (c)<<8 | (d) ) +# define MOST_SIG_BYTE 0 +# define BBIG_ENDIAN +#else +# define MAKE_ID2(c, d) ( (d)<<8 | (c) ) +# define MOST_SIG_BYTE 1 +# define BLITTLE_ENDIAN +#endif + +// ------------------------------------------------------------ +#define ID_SCE MAKE_ID2('S', 'C') +#define ID_LI MAKE_ID2('L', 'I') +#define ID_OB MAKE_ID2('O', 'B') +#define ID_ME MAKE_ID2('M', 'E') +#define ID_CU MAKE_ID2('C', 'U') +#define ID_MB MAKE_ID2('M', 'B') +#define ID_MA MAKE_ID2('M', 'A') +#define ID_TE MAKE_ID2('T', 'E') +#define ID_IM MAKE_ID2('I', 'M') +#define ID_IK MAKE_ID2('I', 'K') +#define ID_WV MAKE_ID2('W', 'V') +#define ID_LT MAKE_ID2('L', 'T') +#define ID_SE MAKE_ID2('S', 'E') +#define ID_LF MAKE_ID2('L', 'F') +#define ID_LA MAKE_ID2('L', 'A') +#define ID_CA MAKE_ID2('C', 'A') +#define ID_IP MAKE_ID2('I', 'P') +#define ID_KE MAKE_ID2('K', 'E') +#define ID_WO MAKE_ID2('W', 'O') +#define ID_SCR MAKE_ID2('S', 'R') +#define ID_VF MAKE_ID2('V', 'F') +#define ID_TXT MAKE_ID2('T', 'X') +#define ID_SO MAKE_ID2('S', 'O') +#define ID_SAMPLE MAKE_ID2('S', 'A') +#define ID_GR MAKE_ID2('G', 'R') +#define ID_ID MAKE_ID2('I', 'D') +#define ID_AR MAKE_ID2('A', 'R') +#define ID_AC MAKE_ID2('A', 'C') +#define ID_SCRIPT MAKE_ID2('P', 'Y') +#define ID_FLUIDSIM MAKE_ID2('F', 'S') +#define ID_NT MAKE_ID2('N', 'T') +#define ID_BR MAKE_ID2('B', 'R') + + +#define ID_SEQ MAKE_ID2('S', 'Q') +#define ID_CO MAKE_ID2('C', 'O') +#define ID_PO MAKE_ID2('A', 'C') +#define ID_NLA MAKE_ID2('N', 'L') + +#define ID_VS MAKE_ID2('V', 'S') +#define ID_VN MAKE_ID2('V', 'N') + + +// ------------------------------------------------------------ +#define FORM MAKE_ID('F','O','R','M') +#define DDG1 MAKE_ID('3','D','G','1') +#define DDG2 MAKE_ID('3','D','G','2') +#define DDG3 MAKE_ID('3','D','G','3') +#define DDG4 MAKE_ID('3','D','G','4') +#define GOUR MAKE_ID('G','O','U','R') +#define BLEN MAKE_ID('B','L','E','N') +#define DER_ MAKE_ID('D','E','R','_') +#define V100 MAKE_ID('V','1','0','0') +#define DATA MAKE_ID('D','A','T','A') +#define GLOB MAKE_ID('G','L','O','B') +#define IMAG MAKE_ID('I','M','A','G') +#define TEST MAKE_ID('T','E','S','T') +#define USER MAKE_ID('U','S','E','R') + + +// ------------------------------------------------------------ +#define DNA1 MAKE_ID('D','N','A','1') +#define REND MAKE_ID('R','E','N','D') +#define ENDB MAKE_ID('E','N','D','B') +#define NAME MAKE_ID('N','A','M','E') +#define SDNA MAKE_ID('S','D','N','A') +#define TYPE MAKE_ID('T','Y','P','E') +#define TLEN MAKE_ID('T','L','E','N') +#define STRC MAKE_ID('S','T','R','C') + + +// ------------------------------------------------------------ +#define SWITCH_INT(a) { \ + char s_i, *p_i; \ + p_i= (char *)&(a); \ + s_i=p_i[0]; p_i[0]=p_i[3]; p_i[3]=s_i; \ + s_i=p_i[1]; p_i[1]=p_i[2]; p_i[2]=s_i; } + +// ------------------------------------------------------------ +#define SWITCH_SHORT(a) { \ + char s_i, *p_i; \ + p_i= (char *)&(a); \ + s_i=p_i[0]; p_i[0]=p_i[1]; p_i[1]=s_i; } + +// ------------------------------------------------------------ +#define SWITCH_LONGINT(a) { \ + char s_i, *p_i; \ + p_i= (char *)&(a); \ + s_i=p_i[0]; p_i[0]=p_i[7]; p_i[7]=s_i; \ + s_i=p_i[1]; p_i[1]=p_i[6]; p_i[6]=s_i; \ + s_i=p_i[2]; p_i[2]=p_i[5]; p_i[5]=s_i; \ + s_i=p_i[3]; p_i[3]=p_i[4]; p_i[4]=s_i; } + +#endif//__B_DEFINES_H__ diff --git a/Code/Physics/Bullet Source/BulletFileLoader/bFile.cpp b/Code/Physics/Bullet Source/BulletFileLoader/bFile.cpp new file mode 100644 index 00000000..c0e256fc --- /dev/null +++ b/Code/Physics/Bullet Source/BulletFileLoader/bFile.cpp @@ -0,0 +1,1757 @@ +/* +bParse +Copyright (c) 2006-2009 Charlie C & Erwin Coumans http://gamekit.googlecode.com + +This software is provided 'as-is', without any express or implied warranty. +In no event will the authors be held liable for any damages arising from the use of this software. +Permission is granted to anyone to use this software for any purpose, +including commercial applications, and to alter it and redistribute it freely, +subject to the following restrictions: + +1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. +2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. +3. This notice may not be removed or altered from any source distribution. +*/ +#include "bFile.h" +#include "bCommon.h" +#include "bChunk.h" +#include "bDNA.h" +#include +#include +#include +#include "bDefines.h" +#include "LinearMath/btSerializer.h" +#include "LinearMath/btAlignedAllocator.h" +#include "LinearMath/btMinMax.h" + +#define SIZEOFBLENDERHEADER 12 +#define MAX_ARRAY_LENGTH 512 +using namespace bParse; +#define MAX_STRLEN 1024 + +const char* getCleanName(const char* memName, char* buffer) +{ + int slen = strlen(memName); + assert(slen 0) + { + if (strncmp((tempBuffer + ChunkUtils::getOffset(mFlags)), "SDNANAME", 8) ==0) + dna.oldPtr = (tempBuffer + ChunkUtils::getOffset(mFlags)); + else dna.oldPtr = 0; + } + else dna.oldPtr = 0; + } + // Some Bullet files are missing the DNA1 block + // In Blender it's DNA1 + ChunkUtils::getOffset() + SDNA + NAME + // In Bullet tests its SDNA + NAME + else if (strncmp(tempBuffer, "SDNANAME", 8) ==0) + { + dna.oldPtr = blenderData + i; + dna.len = mFileLen-i; + + // Also no REND block, so exit now. + if (mVersion==276) break; + } + + if (mDataStart && dna.oldPtr) break; + tempBuffer++; + } + if (!dna.oldPtr || !dna.len) + { + //printf("Failed to find DNA1+SDNA pair\n"); + mFlags &= ~FD_OK; + return; + } + + + mFileDNA = new bDNA(); + + + ///mFileDNA->init will convert part of DNA file endianness to current CPU endianness if necessary + mFileDNA->init((char*)dna.oldPtr, dna.len, (mFlags & FD_ENDIAN_SWAP)!=0); + + + if (mVersion==276) + { + int i; + for (i=0;igetNumNames();i++) + { + if (strcmp(mFileDNA->getName(i),"int")==0) + { + mFlags |= FD_BROKEN_DNA; + } + } + if ((mFlags&FD_BROKEN_DNA)!=0) + { + //printf("warning: fixing some broken DNA version\n"); + } + } + + + + if (verboseMode & FD_VERBOSE_DUMP_DNA_TYPE_DEFINITIONS) + mFileDNA->dumpTypeDefinitions(); + + mMemoryDNA = new bDNA(); + int littleEndian= 1; + littleEndian= ((char*)&littleEndian)[0]; + + mMemoryDNA->init(memDna,memDnaLength,littleEndian==0); + + + + + ///@todo we need a better version check, add version/sub version info from FileGlobal into memory DNA/header files + if (mMemoryDNA->getNumNames() != mFileDNA->getNumNames()) + { + mFlags |= FD_VERSION_VARIES; + //printf ("Warning, file DNA is different than built in, performance is reduced. Best to re-export file with a matching version/platform"); + } + + // as long as it kept up to date it will be ok!! + if (mMemoryDNA->lessThan(mFileDNA)) + { + //printf ("Warning, file DNA is newer than built in."); + } + + + mFileDNA->initCmpFlags(mMemoryDNA); + + parseData(); + + resolvePointers(verboseMode); + + updateOldPointers(); + + +} + + + +// ----------------------------------------------------- // +void bFile::swap(char *head, bChunkInd& dataChunk, bool ignoreEndianFlag) +{ + char *data = head; + short *strc = mFileDNA->getStruct(dataChunk.dna_nr); + + + + const char s[] = "SoftBodyMaterialData"; + int szs = sizeof(s); + if (strncmp((char*)&dataChunk.code,"ARAY",4)==0) + { + short *oldStruct = mFileDNA->getStruct(dataChunk.dna_nr); + char *oldType = mFileDNA->getType(oldStruct[0]); + if (strncmp(oldType,s,szs)==0) + { + return; + } + } + + + int len = mFileDNA->getLength(strc[0]); + + for (int i=0; icode & 0xFFFF)==0) + c->code >>=16; + SWITCH_INT(c->len); + SWITCH_INT(c->dna_nr); + SWITCH_INT(c->nr); + } else + { + bChunkPtr8* c = (bChunkPtr8*) dataPtr; + if ((c->code & 0xFFFF)==0) + c->code >>=16; + SWITCH_INT(c->len); + SWITCH_INT(c->dna_nr); + SWITCH_INT(c->nr); + + } + } else + { + if (mFlags &FD_BITS_VARIES) + { + bChunkPtr8*c = (bChunkPtr8*) dataPtr; + if ((c->code & 0xFFFF)==0) + c->code >>=16; + SWITCH_INT(c->len); + SWITCH_INT(c->dna_nr); + SWITCH_INT(c->nr); + + } else + { + bChunkPtr4* c = (bChunkPtr4*) dataPtr; + if ((c->code & 0xFFFF)==0) + c->code >>=16; + SWITCH_INT(c->len); + + SWITCH_INT(c->dna_nr); + SWITCH_INT(c->nr); + + } + } + +} + + +void bFile::swapDNA(char* ptr) +{ + bool swap = ((mFlags & FD_ENDIAN_SWAP)!=0); + + char* data = &ptr[20]; +// void bDNA::init(char *data, int len, bool swap) + int *intPtr=0;short *shtPtr=0; + char *cp = 0;int dataLen =0;long nr=0; + intPtr = (int*)data; + + /* + SDNA (4 bytes) (magic number) + NAME (4 bytes) + (4 bytes) amount of names (int) + + + */ + + if (strncmp(data, "SDNA", 4)==0) + { + // skip ++ NAME + intPtr++; intPtr++; + } + + + + // Parse names + if (swap) + dataLen = ChunkUtils::swapInt(*intPtr); + else + dataLen = *intPtr; + + *intPtr = ChunkUtils::swapInt(*intPtr); + intPtr++; + + cp = (char*)intPtr; + int i; + for ( i=0; i amount of types (int) + + + */ + + intPtr = (int*)cp; + assert(strncmp(cp, "TYPE", 4)==0); intPtr++; + + if (swap) + dataLen = ChunkUtils::swapInt(*intPtr); + else + dataLen = *intPtr; + + *intPtr = ChunkUtils::swapInt(*intPtr); + + intPtr++; + + cp = (char*)intPtr; + for ( i=0; i (short) the lengths of types + + */ + + // Parse type lens + intPtr = (int*)cp; + assert(strncmp(cp, "TLEN", 4)==0); intPtr++; + + + shtPtr = (short*)intPtr; + for ( i=0; i amount of structs (int) + + + + + + + */ + + intPtr = (int*)shtPtr; + cp = (char*)intPtr; + assert(strncmp(cp, "STRC", 4)==0); + intPtr++; + + if (swap) + dataLen = ChunkUtils::swapInt(*intPtr); + else + dataLen = *intPtr; + + *intPtr = ChunkUtils::swapInt(*intPtr); + + intPtr++; + + + shtPtr = (short*)intPtr; + for ( i=0; i=0) + { + swap(dataPtrHead, dataChunk,ignoreEndianFlag); + } else + { + printf("unknown chunk\n"); + } + } + + // next please! + dataPtr += seek; + + seek = getNextBlock(&dataChunk, dataPtr, mFlags); + if (seek < 0) + break; + } + + if (mFlags & FD_ENDIAN_SWAP) + { + mFlags &= ~FD_ENDIAN_SWAP; + } else + { + mFlags |= FD_ENDIAN_SWAP; + } + + + +} + + +// ----------------------------------------------------- // +char* bFile::readStruct(char *head, bChunkInd& dataChunk) +{ + bool ignoreEndianFlag = false; + + if (mFlags & FD_ENDIAN_SWAP) + swap(head, dataChunk, ignoreEndianFlag); + + + + if (!mFileDNA->flagEqual(dataChunk.dna_nr)) + { + // Ouch! need to rebuild the struct + short *oldStruct,*curStruct; + char *oldType, *newType; + int oldLen, curLen, reverseOld; + + + oldStruct = mFileDNA->getStruct(dataChunk.dna_nr); + oldType = mFileDNA->getType(oldStruct[0]); + + oldLen = mFileDNA->getLength(oldStruct[0]); + + if ((mFlags&FD_BROKEN_DNA)!=0) + { + if ((strcmp(oldType,"btQuantizedBvhNodeData")==0)&&oldLen==20) + { + return 0; + } + if ((strcmp(oldType,"btShortIntIndexData")==0)) + { + int allocLen = 2; + char *dataAlloc = new char[(dataChunk.nr*allocLen)+1]; + memset(dataAlloc, 0, (dataChunk.nr*allocLen)+1); + short* dest = (short*) dataAlloc; + const short* src = (short*) head; + for (int i=0;igetReverseType(oldType); + + if ((reverseOld!=-1)) + { + // make sure it's here + //assert(reverseOld!= -1 && "getReverseType() returned -1, struct required!"); + + // + curStruct = mMemoryDNA->getStruct(reverseOld); + newType = mMemoryDNA->getType(curStruct[0]); + curLen = mMemoryDNA->getLength(curStruct[0]); + + + + // make sure it's the same + assert((strcmp(oldType, newType)==0) && "internal error, struct mismatch!"); + + + numallocs++; + // numBlocks * length + + int allocLen = (curLen); + char *dataAlloc = new char[(dataChunk.nr*allocLen)+1]; + memset(dataAlloc, 0, (dataChunk.nr*allocLen)); + + // track allocated + addDataBlock(dataAlloc); + + char *cur = dataAlloc; + char *old = head; + for (int block=0; blockgetStruct(dataChunk.dna_nr); + oldType = mFileDNA->getType(oldStruct[0]); + printf("%s equal structure, just memcpy\n",oldType); +#endif // + } + + + char *dataAlloc = new char[(dataChunk.len)+1]; + memset(dataAlloc, 0, dataChunk.len+1); + + + // track allocated + addDataBlock(dataAlloc); + + memcpy(dataAlloc, head, dataChunk.len); + return dataAlloc; + +} + + +// ----------------------------------------------------- // +void bFile::parseStruct(char *strcPtr, char *dtPtr, int old_dna, int new_dna, bool fixupPointers) +{ + if (old_dna == -1) return; + if (new_dna == -1) return; + + //disable this, because we need to fixup pointers/ListBase + if (0)//mFileDNA->flagEqual(old_dna)) + { + short *strc = mFileDNA->getStruct(old_dna); + int len = mFileDNA->getLength(strc[0]); + + memcpy(strcPtr, dtPtr, len); + return; + } + + // Ok, now build the struct + char *memType, *memName, *cpc, *cpo; + short *fileStruct, *filePtrOld, *memoryStruct, *firstStruct; + int elementLength, size, revType, old_nr, new_nr, fpLen; + short firstStructType; + + + // File to memory lookup + memoryStruct = mMemoryDNA->getStruct(new_dna); + fileStruct = mFileDNA->getStruct(old_dna); + firstStruct = fileStruct; + + + filePtrOld = fileStruct; + firstStructType = mMemoryDNA->getStruct(0)[0]; + + // Get number of elements + elementLength = memoryStruct[1]; + memoryStruct+=2; + + cpc = strcPtr; cpo = 0; + for (int ele=0; elegetType(memoryStruct[0]); + memName = mMemoryDNA->getName(memoryStruct[1]); + + + size = mMemoryDNA->getElementSize(memoryStruct[0], memoryStruct[1]); + revType = mMemoryDNA->getReverseType(memoryStruct[0]); + + if (revType != -1 && memoryStruct[0]>=firstStructType && memName[0] != '*') + { + cpo = getFileElement(firstStruct, memName, memType, dtPtr, &filePtrOld); + if (cpo) + { + int arrayLen = mFileDNA->getArraySizeNew(filePtrOld[1]); + old_nr = mFileDNA->getReverseType(memType); + new_nr = revType; + fpLen = mFileDNA->getElementSize(filePtrOld[0], filePtrOld[1]); + if (arrayLen==1) + { + parseStruct(cpc, cpo, old_nr, new_nr,fixupPointers); + } else + { + char* tmpCpc = cpc; + char* tmpCpo = cpo; + + for (int i=0;i3 && type <8) + { + char c; + char *cp = data; + for (int i=0; igetPointerSize(); + int ptrMem = mMemoryDNA->getPointerSize(); + + if (!src && !dst) + return; + + + if (ptrFile == ptrMem) + { + memcpy(dst, src, ptrMem); + } + else if (ptrMem==4 && ptrFile==8) + { + btPointerUid* oldPtr = (btPointerUid*)src; + btPointerUid* newPtr = (btPointerUid*)dst; + + if (oldPtr->m_uniqueIds[0] == oldPtr->m_uniqueIds[1]) + { + //Bullet stores the 32bit unique ID in both upper and lower part of 64bit pointers + //so it can be used to distinguish between .blend and .bullet + newPtr->m_uniqueIds[0] = oldPtr->m_uniqueIds[0]; + } else + { + //deal with pointers the Blender .blend style way, see + //readfile.c in the Blender source tree + long64 longValue = *((long64*)src); + //endian swap for 64bit pointer otherwise truncation will fail due to trailing zeros + if (mFlags & FD_ENDIAN_SWAP) + SWITCH_LONGINT(longValue); + *((int*)dst) = (int)(longValue>>3); + } + + } + else if (ptrMem==8 && ptrFile==4) + { + btPointerUid* oldPtr = (btPointerUid*)src; + btPointerUid* newPtr = (btPointerUid*)dst; + if (oldPtr->m_uniqueIds[0] == oldPtr->m_uniqueIds[1]) + { + newPtr->m_uniqueIds[0] = oldPtr->m_uniqueIds[0]; + newPtr->m_uniqueIds[1] = 0; + } else + { + *((long64*)dst)= *((int*)src); + } + } + else + { + printf ("%d %d\n", ptrFile,ptrMem); + assert(0 && "Invalid pointer len"); + } + + +} + + +// ----------------------------------------------------- // +void bFile::getMatchingFileDNA(short* dna_addr, const char* lookupName, const char* lookupType, char *strcData, char *data, bool fixupPointers) +{ + // find the matching memory dna data + // to the file being loaded. Fill the + // memory with the file data... + + int len = dna_addr[1]; + dna_addr+=2; + + for (int i=0; igetType(dna_addr[0]); + const char* name = mFileDNA->getName(dna_addr[1]); + + + + int eleLen = mFileDNA->getElementSize(dna_addr[0], dna_addr[1]); + + if ((mFlags&FD_BROKEN_DNA)!=0) + { + if ((strcmp(type,"short")==0)&&(strcmp(name,"int")==0)) + { + eleLen = 0; + } + } + + if (strcmp(lookupName, name)==0) + { + //int arrayLenold = mFileDNA->getArraySize((char*)name.c_str()); + int arrayLen = mFileDNA->getArraySizeNew(dna_addr[1]); + //assert(arrayLenold == arrayLen); + + if (name[0] == '*') + { + // cast pointers + int ptrFile = mFileDNA->getPointerSize(); + int ptrMem = mMemoryDNA->getPointerSize(); + safeSwapPtr(strcData,data); + + if (fixupPointers) + { + if (arrayLen > 1) + { + //void **sarray = (void**)strcData; + //void **darray = (void**)data; + + char *cpc, *cpo; + cpc = (char*)strcData; + cpo = (char*)data; + + for (int a=0; agetStruct(old_nr); + int elementLength = old[1]; + old+=2; + + for (int i=0; igetType(old[0]); + char* name = mFileDNA->getName(old[1]); + int len = mFileDNA->getElementSize(old[0], old[1]); + + if (strcmp(lookupName, name)==0) + { + if (strcmp(type, lookupType)==0) + { + if (foundPos) + *foundPos = old; + return data; + } + return 0; + } + data+=len; + } + return 0; +} + + +// ----------------------------------------------------- // +void bFile::swapStruct(int dna_nr, char *data,bool ignoreEndianFlag) +{ + if (dna_nr == -1) return; + + short *strc = mFileDNA->getStruct(dna_nr); + //short *firstStrc = strc; + + int elementLen= strc[1]; + strc+=2; + + short first = mFileDNA->getStruct(0)[0]; + + char *buf = data; + for (int i=0; igetType(strc[0]); + char *name = mFileDNA->getName(strc[1]); + + int size = mFileDNA->getElementSize(strc[0], strc[1]); + if (strc[0] >= first && name[0]!='*') + { + int old_nr = mFileDNA->getReverseType(type); + int arrayLen = mFileDNA->getArraySizeNew(strc[1]); + if (arrayLen==1) + { + swapStruct(old_nr,buf,ignoreEndianFlag); + } else + { + char* tmpBuf = buf; + for (int i=0;igetArraySize(name); + int arrayLen = mFileDNA->getArraySizeNew(strc[1]); + //assert(arrayLenOld == arrayLen); + swapData(buf, strc[0], arrayLen,ignoreEndianFlag); + } + buf+=size; + } +} + +void bFile::resolvePointersMismatch() +{ +// printf("resolvePointersStructMismatch\n"); + + int i; + + for (i=0;i< m_pointerFixupArray.size();i++) + { + char* cur = m_pointerFixupArray.at(i); + void** ptrptr = (void**) cur; + void* ptr = *ptrptr; + ptr = findLibPointer(ptr); + if (ptr) + { + //printf("Fixup pointer!\n"); + *(ptrptr) = ptr; + } else + { +// printf("pointer not found: %x\n",cur); + } + } + + + for (i=0; igetPointerSize(); + int ptrFile = mFileDNA->getPointerSize(); + + + int blockLen = block->len / ptrFile; + + void *onptr = findLibPointer(*ptrptr); + if (onptr) + { + char *newPtr = new char[blockLen * ptrMem]; + addDataBlock(newPtr); + memset(newPtr, 0, blockLen * ptrMem); + + void **onarray = (void**)onptr; + char *oldPtr = (char*)onarray; + + int p = 0; + while (blockLen-- > 0) + { + btPointerUid dp = {0}; + safeSwapPtr((char*)dp.m_uniqueIds, oldPtr); + + void **tptr = (void**)(newPtr + p * ptrMem); + *tptr = findLibPointer(dp.m_ptr); + + oldPtr += ptrFile; + ++p; + } + + *ptrptr = newPtr; + } + } + } +} + + +///this loop only works fine if the Blender DNA structure of the file matches the headerfiles +void bFile::resolvePointersChunk(const bChunkInd& dataChunk, int verboseMode) +{ + bParse::bDNA* fileDna = mFileDNA ? mFileDNA : mMemoryDNA; + + short int* oldStruct = fileDna->getStruct(dataChunk.dna_nr); + short oldLen = fileDna->getLength(oldStruct[0]); + //char* structType = fileDna->getType(oldStruct[0]); + + char* cur = (char*)findLibPointer(dataChunk.oldPtr); + for (int block=0; blockgetStruct(0)[0]; + + + char* elemPtr= strcPtr; + + short int* oldStruct = fileDna->getStruct(dna_nr); + + int elementLength = oldStruct[1]; + oldStruct+=2; + + int totalSize = 0; + + for (int ele=0; elegetType(oldStruct[0]); + memName = fileDna->getName(oldStruct[1]); + + + + int arrayLen = fileDna->getArraySizeNew(oldStruct[1]); + if (memName[0] == '*') + { + if (arrayLen > 1) + { + void **array= (void**)elemPtr; + for (int a=0; a ",&memName[1]); + printf("%d ", array[a]); + printf("\n",&memName[1]); + } + + array[a] = findLibPointer(array[a]); + } + } + else + { + void** ptrptr = (void**) elemPtr; + void* ptr = *ptrptr; + if (verboseMode & FD_VERBOSE_EXPORT_XML) + { + for (int i=0;i ",&memName[1]); + printf("%d ", ptr); + printf("\n",&memName[1]); + } + ptr = findLibPointer(ptr); + + if (ptr) + { + // printf("Fixup pointer at 0x%x from 0x%x to 0x%x!\n",ptrptr,*ptrptr,ptr); + *(ptrptr) = ptr; + if (memName[1] == '*' && ptrptr && *ptrptr) + { + // This will only work if the given **array is continuous + void **array= (void**)*(ptrptr); + void *np= array[0]; + int n=0; + while (np) + { + np= findLibPointer(array[n]); + if (np) array[n]= np; + n++; + } + } + } else + { + // printf("Cannot fixup pointer at 0x%x from 0x%x to 0x%x!\n",ptrptr,*ptrptr,ptr); + } + } + } else + { + int revType = fileDna->getReverseType(oldStruct[0]); + if (oldStruct[0]>=firstStructType) //revType != -1 && + { + char cleanName[MAX_STRLEN]; + getCleanName(memName,cleanName); + + int arrayLen = fileDna->getArraySizeNew(oldStruct[1]); + int byteOffset = 0; + + if (verboseMode & FD_VERBOSE_EXPORT_XML) + { + for (int i=0;i1) + { + printf("<%s type=\"%s\" count=%d>\n",cleanName,memType, arrayLen); + } else + { + printf("<%s type=\"%s\">\n",cleanName,memType); + } + } + + for (int i=0;i\n",cleanName); + } + } else + { + //export a simple type + if (verboseMode & FD_VERBOSE_EXPORT_XML) + { + + if (arrayLen>MAX_ARRAY_LENGTH) + { + printf("too long\n"); + } else + { + //printf("%s %s\n",memType,memName); + + bool isIntegerType = (strcmp(memType,"char")==0) || (strcmp(memType,"int")==0) || (strcmp(memType,"short")==0); + + if (isIntegerType) + { + const char* newtype="int"; + int dbarray[MAX_ARRAY_LENGTH]; + int* dbPtr = 0; + char* tmp = elemPtr; + dbPtr = &dbarray[0]; + if (dbPtr) + { + char cleanName[MAX_STRLEN]; + getCleanName(memName,cleanName); + + int i; + getElement(arrayLen, newtype,memType, tmp, (char*)dbPtr); + for (i=0;i",cleanName,memType); + else + printf("<%s type=\"%s\" count=%d>",cleanName,memType,arrayLen); + for (i=0;i\n",cleanName); + } + } else + { + const char* newtype="double"; + double dbarray[MAX_ARRAY_LENGTH]; + double* dbPtr = 0; + char* tmp = elemPtr; + dbPtr = &dbarray[0]; + if (dbPtr) + { + int i; + getElement(arrayLen, newtype,memType, tmp, (char*)dbPtr); + for (i=0;i",memName,memType); + } + else + { + printf("<%s type=\"%s\" count=%d>",cleanName,memType,arrayLen); + } + for (i=0;i\n",cleanName); + } + } + } + + } + } + } + + int size = fileDna->getElementSize(oldStruct[0], oldStruct[1]); + totalSize += size; + elemPtr+=size; + + } + + return totalSize; +} + + +///Resolve pointers replaces the original pointers in structures, and linked lists by the new in-memory structures +void bFile::resolvePointers(int verboseMode) +{ + bParse::bDNA* fileDna = mFileDNA ? mFileDNA : mMemoryDNA; + + //char *dataPtr = mFileBuffer+mDataStart; + + if (1) //mFlags & (FD_BITS_VARIES | FD_VERSION_VARIES)) + { + resolvePointersMismatch(); + } + + { + + if (verboseMode & FD_VERBOSE_EXPORT_XML) + { + printf("\n"); + int numitems = m_chunks.size(); + printf("\n", btGetVersion(), numitems); + } + for (int i=0;iflagEqual(dataChunk.dna_nr)) + { + //dataChunk.len + short int* oldStruct = fileDna->getStruct(dataChunk.dna_nr); + char* oldType = fileDna->getType(oldStruct[0]); + + if (verboseMode & FD_VERBOSE_EXPORT_XML) + printf(" <%s pointer=%d>\n",oldType,dataChunk.oldPtr); + + resolvePointersChunk(dataChunk, verboseMode); + + if (verboseMode & FD_VERBOSE_EXPORT_XML) + printf(" \n",oldType); + } else + { + //printf("skipping mStruct\n"); + } + } + if (verboseMode & FD_VERBOSE_EXPORT_XML) + { + printf("\n"); + } + } + + +} + + +// ----------------------------------------------------- // +void* bFile::findLibPointer(void *ptr) +{ + + bStructHandle** ptrptr = getLibPointers().find(ptr); + if (ptrptr) + return *ptrptr; + return 0; +} + + +void bFile::updateOldPointers() +{ + int i; + + for (i=0;igetStruct(dataChunk.dna_nr); + char* typeName = dna->getType(newStruct[0]); + printf("%3d: %s ",i,typeName); + + printf("code=%s ",codestr); + + printf("ptr=%p ",dataChunk.oldPtr); + printf("len=%d ",dataChunk.len); + printf("nr=%d ",dataChunk.nr); + if (dataChunk.nr!=1) + { + printf("not 1\n"); + } + printf("\n"); + + + + + } + +#if 0 + IDFinderData ifd; + ifd.success = 0; + ifd.IDname = NULL; + ifd.just_print_it = 1; + for (i=0; im_blocks.size(); ++i) + { + BlendBlock* bb = bf->m_blocks[i]; + printf("tag='%s'\tptr=%p\ttype=%s\t[%4d]", bb->tag, bb,bf->types[bb->type_index].name,bb->m_array_entries_.size()); + block_ID_finder(bb, bf, &ifd); + printf("\n"); + } +#endif + +} + + +void bFile::writeChunks(FILE* fp, bool fixupPointers) +{ + bParse::bDNA* fileDna = mFileDNA ? mFileDNA : mMemoryDNA; + + for (int i=0;igetStruct(dataChunk.dna_nr); + oldType = fileDna->getType(oldStruct[0]); + oldLen = fileDna->getLength(oldStruct[0]); + ///don't try to convert Link block data, just memcpy it. Other data can be converted. + reverseOld = mMemoryDNA->getReverseType(oldType); + + + if ((reverseOld!=-1)) + { + // make sure it's here + //assert(reverseOld!= -1 && "getReverseType() returned -1, struct required!"); + // + curStruct = mMemoryDNA->getStruct(reverseOld); + newType = mMemoryDNA->getType(curStruct[0]); + // make sure it's the same + assert((strcmp(oldType, newType)==0) && "internal error, struct mismatch!"); + + + curLen = mMemoryDNA->getLength(curStruct[0]); + dataChunk.dna_nr = reverseOld; + if (strcmp("Link",oldType)!=0) + { + dataChunk.len = curLen * dataChunk.nr; + } else + { +// printf("keep length of link = %d\n",dataChunk.len); + } + + //write the structure header + fwrite(&dataChunk,sizeof(bChunkInd),1,fp); + + + + short int* curStruct1; + curStruct1 = mMemoryDNA->getStruct(dataChunk.dna_nr); + assert(curStruct1 == curStruct); + + char* cur = fixupPointers ? (char*)findLibPointer(dataChunk.oldPtr) : (char*)dataChunk.oldPtr; + + //write the actual contents of the structure(s) + fwrite(cur,dataChunk.len,1,fp); + } else + { + printf("serious error, struct mismatch: don't write\n"); + } + } + +} + + +// ----------------------------------------------------- // +int bFile::getNextBlock(bChunkInd *dataChunk, const char *dataPtr, const int flags) +{ + bool swap = false; + bool varies = false; + + if (flags &FD_ENDIAN_SWAP) + swap = true; + if (flags &FD_BITS_VARIES) + varies = true; + + if (VOID_IS_8) + { + if (varies) + { + bChunkPtr4 head; + memcpy(&head, dataPtr, sizeof(bChunkPtr4)); + + + bChunkPtr8 chunk; + + chunk.code = head.code; + chunk.len = head.len; + chunk.m_uniqueInts[0] = head.m_uniqueInt; + chunk.m_uniqueInts[1] = 0; + chunk.dna_nr = head.dna_nr; + chunk.nr = head.nr; + + if (swap) + { + if ((chunk.code & 0xFFFF)==0) + chunk.code >>=16; + + SWITCH_INT(chunk.len); + SWITCH_INT(chunk.dna_nr); + SWITCH_INT(chunk.nr); + } + + + memcpy(dataChunk, &chunk, sizeof(bChunkInd)); + } + else + { + bChunkPtr8 c; + memcpy(&c, dataPtr, sizeof(bChunkPtr8)); + + if (swap) + { + if ((c.code & 0xFFFF)==0) + c.code >>=16; + + SWITCH_INT(c.len); + SWITCH_INT(c.dna_nr); + SWITCH_INT(c.nr); + } + + memcpy(dataChunk, &c, sizeof(bChunkInd)); + } + } + else + { + if (varies) + { + bChunkPtr8 head; + memcpy(&head, dataPtr, sizeof(bChunkPtr8)); + + + bChunkPtr4 chunk; + chunk.code = head.code; + chunk.len = head.len; + + if (head.m_uniqueInts[0]==head.m_uniqueInts[1]) + { + chunk.m_uniqueInt = head.m_uniqueInts[0]; + } else + { + long64 oldPtr =0; + memcpy(&oldPtr, &head.m_uniqueInts[0], 8); + if (swap) + SWITCH_LONGINT(oldPtr); + chunk.m_uniqueInt = (int)(oldPtr >> 3); + } + + + chunk.dna_nr = head.dna_nr; + chunk.nr = head.nr; + + if (swap) + { + if ((chunk.code & 0xFFFF)==0) + chunk.code >>=16; + + SWITCH_INT(chunk.len); + SWITCH_INT(chunk.dna_nr); + SWITCH_INT(chunk.nr); + } + + memcpy(dataChunk, &chunk, sizeof(bChunkInd)); + } + else + { + bChunkPtr4 c; + memcpy(&c, dataPtr, sizeof(bChunkPtr4)); + + if (swap) + { + if ((c.code & 0xFFFF)==0) + c.code >>=16; + + SWITCH_INT(c.len); + SWITCH_INT(c.dna_nr); + SWITCH_INT(c.nr); + } + memcpy(dataChunk, &c, sizeof(bChunkInd)); + } + } + + if (dataChunk->len < 0) + return -1; + +#if 0 + print ("----------"); + print (dataChunk->code); + print (dataChunk->len); + print (dataChunk->old); + print (dataChunk->dna_nr); + print (dataChunk->nr); +#endif + return (dataChunk->len+ChunkUtils::getOffset(flags)); +} + + + +//eof diff --git a/Code/Physics/Bullet Source/BulletFileLoader/bFile.h b/Code/Physics/Bullet Source/BulletFileLoader/bFile.h new file mode 100644 index 00000000..9df95adf --- /dev/null +++ b/Code/Physics/Bullet Source/BulletFileLoader/bFile.h @@ -0,0 +1,165 @@ +/* +bParse +Copyright (c) 2006-2009 Charlie C & Erwin Coumans http://gamekit.googlecode.com + +This software is provided 'as-is', without any express or implied warranty. +In no event will the authors be held liable for any damages arising from the use of this software. +Permission is granted to anyone to use this software for any purpose, +including commercial applications, and to alter it and redistribute it freely, +subject to the following restrictions: + +1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. +2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. +3. This notice may not be removed or altered from any source distribution. +*/ + +#ifndef __BFILE_H__ +#define __BFILE_H__ + +#include "bCommon.h" +#include "bChunk.h" +#include + +namespace bParse { + + // ----------------------------------------------------- // + enum bFileFlags + { + FD_INVALID =0, + FD_OK =1, + FD_VOID_IS_8 =2, + FD_ENDIAN_SWAP =4, + FD_FILE_64 =8, + FD_BITS_VARIES =16, + FD_VERSION_VARIES = 32, + FD_DOUBLE_PRECISION =64, + FD_BROKEN_DNA = 128 + }; + + enum bFileVerboseMode + { + FD_VERBOSE_EXPORT_XML = 1, + FD_VERBOSE_DUMP_DNA_TYPE_DEFINITIONS = 2, + FD_VERBOSE_DUMP_CHUNKS = 4, + FD_VERBOSE_DUMP_FILE_INFO=8, + }; + // ----------------------------------------------------- // + class bFile + { + protected: + + char m_headerString[7]; + + bool mOwnsBuffer; + char* mFileBuffer; + int mFileLen; + int mVersion; + + + bPtrMap mLibPointers; + + int mDataStart; + bDNA* mFileDNA; + bDNA* mMemoryDNA; + + btAlignedObjectArray m_pointerFixupArray; + btAlignedObjectArray m_pointerPtrFixupArray; + + btAlignedObjectArray m_chunks; + btHashMap m_chunkPtrPtrMap; + + // + + bPtrMap mDataPointers; + + + int mFlags; + + // //////////////////////////////////////////////////////////////////////////// + + // buffer offset util + int getNextBlock(bChunkInd *dataChunk, const char *dataPtr, const int flags); + void safeSwapPtr(char *dst, const char *src); + + virtual void parseHeader(); + + virtual void parseData() = 0; + + void resolvePointersMismatch(); + void resolvePointersChunk(const bChunkInd& dataChunk, int verboseMode); + + int resolvePointersStructRecursive(char *strcPtr, int old_dna, int verboseMode, int recursion); + //void swapPtr(char *dst, char *src); + + void parseStruct(char *strcPtr, char *dtPtr, int old_dna, int new_dna, bool fixupPointers); + void getMatchingFileDNA(short* old, const char* lookupName, const char* lookupType, char *strcData, char *data, bool fixupPointers); + char* getFileElement(short *firstStruct, char *lookupName, char *lookupType, char *data, short **foundPos); + + + void swap(char *head, class bChunkInd& ch, bool ignoreEndianFlag); + void swapData(char *data, short type, int arraySize, bool ignoreEndianFlag); + void swapStruct(int dna_nr, char *data, bool ignoreEndianFlag); + void swapLen(char *dataPtr); + void swapDNA(char* ptr); + + + char* readStruct(char *head, class bChunkInd& chunk); + char *getAsString(int code); + + void parseInternal(int verboseMode, char* memDna,int memDnaLength); + + public: + bFile(const char *filename, const char headerString[7]); + + //todo: make memoryBuffer const char + //bFile( const char *memoryBuffer, int len); + bFile( char *memoryBuffer, int len, const char headerString[7]); + virtual ~bFile(); + + bDNA* getFileDNA() + { + return mFileDNA; + } + + virtual void addDataBlock(char* dataBlock) = 0; + + int getFlags() const + { + return mFlags; + } + + bPtrMap& getLibPointers() + { + return mLibPointers; + } + + void* findLibPointer(void *ptr); + + bool ok(); + + virtual void parse(int verboseMode) = 0; + + virtual int write(const char* fileName, bool fixupPointers=false) = 0; + + virtual void writeChunks(FILE* fp, bool fixupPointers ); + + virtual void writeDNA(FILE* fp) = 0; + + void updateOldPointers(); + void resolvePointers(int verboseMode); + + void dumpChunks(bDNA* dna); + + int getVersion() const + { + return mVersion; + } + //pre-swap the endianness, so that data loaded on a target with different endianness doesn't need to be swapped + void preSwap(); + void writeFile(const char* fileName); + + }; +} + + +#endif//__BFILE_H__ diff --git a/Code/Physics/Bullet Source/BulletFileLoader/btBulletFile.cpp b/Code/Physics/Bullet Source/BulletFileLoader/btBulletFile.cpp new file mode 100644 index 00000000..3ecf8851 --- /dev/null +++ b/Code/Physics/Bullet Source/BulletFileLoader/btBulletFile.cpp @@ -0,0 +1,423 @@ +/* +bParse +Copyright (c) 2006-2010 Erwin Coumans http://gamekit.googlecode.com + +This software is provided 'as-is', without any express or implied warranty. +In no event will the authors be held liable for any damages arising from the use of this software. +Permission is granted to anyone to use this software for any purpose, +including commercial applications, and to alter it and redistribute it freely, +subject to the following restrictions: + +1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. +2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. +3. This notice may not be removed or altered from any source distribution. +*/ + +#include "btBulletFile.h" +#include "bDefines.h" +#include "bDNA.h" + +#if !defined( __CELLOS_LV2__) && !defined(__MWERKS__) +#include +#endif +#include + + +// 32 && 64 bit versions +#ifdef BT_INTERNAL_UPDATE_SERIALIZATION_STRUCTURES +#ifdef _WIN64 +extern char sBulletDNAstr64[]; +extern int sBulletDNAlen64; +#else +extern char sBulletDNAstr[]; +extern int sBulletDNAlen; +#endif //_WIN64 +#else//BT_INTERNAL_UPDATE_SERIALIZATION_STRUCTURES + +extern char sBulletDNAstr64[]; +extern int sBulletDNAlen64; +extern char sBulletDNAstr[]; +extern int sBulletDNAlen; + +#endif //BT_INTERNAL_UPDATE_SERIALIZATION_STRUCTURES + +using namespace bParse; + +btBulletFile::btBulletFile() +:bFile("", "BULLET ") +{ + mMemoryDNA = new bDNA(); //this memory gets released in the bFile::~bFile destructor,@todo not consistent with the rule 'who allocates it, has to deallocate it" + + m_DnaCopy = 0; + + +#ifdef BT_INTERNAL_UPDATE_SERIALIZATION_STRUCTURES +#ifdef _WIN64 + m_DnaCopy = (char*)btAlignedAlloc(sBulletDNAlen64,16); + memcpy(m_DnaCopy,sBulletDNAstr64,sBulletDNAlen64); + mMemoryDNA->init(m_DnaCopy,sBulletDNAlen64); +#else//_WIN64 + m_DnaCopy = (char*)btAlignedAlloc(sBulletDNAlen,16); + memcpy(m_DnaCopy,sBulletDNAstr,sBulletDNAlen); + mMemoryDNA->init(m_DnaCopy,sBulletDNAlen); +#endif//_WIN64 +#else//BT_INTERNAL_UPDATE_SERIALIZATION_STRUCTURES + if (VOID_IS_8) + { + m_DnaCopy = (char*) btAlignedAlloc(sBulletDNAlen64,16); + memcpy(m_DnaCopy,sBulletDNAstr64,sBulletDNAlen64); + mMemoryDNA->init(m_DnaCopy,sBulletDNAlen64); + } + else + { + m_DnaCopy =(char*) btAlignedAlloc(sBulletDNAlen,16); + memcpy(m_DnaCopy,sBulletDNAstr,sBulletDNAlen); + mMemoryDNA->init(m_DnaCopy,sBulletDNAlen); + } +#endif//BT_INTERNAL_UPDATE_SERIALIZATION_STRUCTURES +} + + + +btBulletFile::btBulletFile(const char* fileName) +:bFile(fileName, "BULLET ") +{ + m_DnaCopy = 0; +} + + + +btBulletFile::btBulletFile(char *memoryBuffer, int len) +:bFile(memoryBuffer,len, "BULLET ") +{ + m_DnaCopy = 0; +} + + +btBulletFile::~btBulletFile() +{ + if (m_DnaCopy) + btAlignedFree(m_DnaCopy); + + + while (m_dataBlocks.size()) + { + char* dataBlock = m_dataBlocks[m_dataBlocks.size()-1]; + delete[] dataBlock; + m_dataBlocks.pop_back(); + } + +} + + + +// ----------------------------------------------------- // +void btBulletFile::parseData() +{ +// printf ("Building datablocks"); +// printf ("Chunk size = %d",CHUNK_HEADER_LEN); +// printf ("File chunk size = %d",ChunkUtils::getOffset(mFlags)); + + const bool brokenDNA = (mFlags&FD_BROKEN_DNA)!=0; + + //const bool swap = (mFlags&FD_ENDIAN_SWAP)!=0; + + + mDataStart = 12; + + char *dataPtr = mFileBuffer+mDataStart; + + bChunkInd dataChunk; + dataChunk.code = 0; + + + //dataPtr += ChunkUtils::getNextBlock(&dataChunk, dataPtr, mFlags); + int seek = getNextBlock(&dataChunk, dataPtr, mFlags); + + + if (mFlags &FD_ENDIAN_SWAP) + swapLen(dataPtr); + + //dataPtr += ChunkUtils::getOffset(mFlags); + char *dataPtrHead = 0; + + while (dataChunk.code != DNA1) + { + if (!brokenDNA || (dataChunk.code != BT_QUANTIZED_BVH_CODE) ) + { + + // one behind + if (dataChunk.code == SDNA) break; + //if (dataChunk.code == DNA1) break; + + // same as (BHEAD+DATA dependency) + dataPtrHead = dataPtr+ChunkUtils::getOffset(mFlags); + if (dataChunk.dna_nr>=0) + { + char *id = readStruct(dataPtrHead, dataChunk); + + // lookup maps + if (id) + { + m_chunkPtrPtrMap.insert(dataChunk.oldPtr, dataChunk); + mLibPointers.insert(dataChunk.oldPtr, (bStructHandle*)id); + + m_chunks.push_back(dataChunk); + // block it + //bListBasePtr *listID = mMain->getListBasePtr(dataChunk.code); + //if (listID) + // listID->push_back((bStructHandle*)id); + } + + if (dataChunk.code == BT_SOFTBODY_CODE) + { + m_softBodies.push_back((bStructHandle*) id); + } + + if (dataChunk.code == BT_RIGIDBODY_CODE) + { + m_rigidBodies.push_back((bStructHandle*) id); + } + + if (dataChunk.code == BT_DYNAMICSWORLD_CODE) + { + m_dynamicsWorldInfo.push_back((bStructHandle*) id); + } + + if (dataChunk.code == BT_CONSTRAINT_CODE) + { + m_constraints.push_back((bStructHandle*) id); + } + + if (dataChunk.code == BT_QUANTIZED_BVH_CODE) + { + m_bvhs.push_back((bStructHandle*) id); + } + + if (dataChunk.code == BT_TRIANLGE_INFO_MAP) + { + m_triangleInfoMaps.push_back((bStructHandle*) id); + } + + if (dataChunk.code == BT_COLLISIONOBJECT_CODE) + { + m_collisionObjects.push_back((bStructHandle*) id); + } + + if (dataChunk.code == BT_SHAPE_CODE) + { + m_collisionShapes.push_back((bStructHandle*) id); + } + + // if (dataChunk.code == GLOB) + // { + // m_glob = (bStructHandle*) id; + // } + } else + { + printf("unknown chunk\n"); + + mLibPointers.insert(dataChunk.oldPtr, (bStructHandle*)dataPtrHead); + } + } else + { + printf("skipping BT_QUANTIZED_BVH_CODE due to broken DNA\n"); + } + + + dataPtr += seek; + + seek = getNextBlock(&dataChunk, dataPtr, mFlags); + if (mFlags &FD_ENDIAN_SWAP) + swapLen(dataPtr); + + if (seek < 0) + break; + } + +} + +void btBulletFile::addDataBlock(char* dataBlock) +{ + m_dataBlocks.push_back(dataBlock); + +} + + + + +void btBulletFile::writeDNA(FILE* fp) +{ + + bChunkInd dataChunk; + dataChunk.code = DNA1; + dataChunk.dna_nr = 0; + dataChunk.nr = 1; +#ifdef BT_INTERNAL_UPDATE_SERIALIZATION_STRUCTURES + if (VOID_IS_8) + { +#ifdef _WIN64 + dataChunk.len = sBulletDNAlen64; + dataChunk.oldPtr = sBulletDNAstr64; + fwrite(&dataChunk,sizeof(bChunkInd),1,fp); + fwrite(sBulletDNAstr64, sBulletDNAlen64,1,fp); +#else + btAssert(0); +#endif + } + else + { +#ifndef _WIN64 + dataChunk.len = sBulletDNAlen; + dataChunk.oldPtr = sBulletDNAstr; + fwrite(&dataChunk,sizeof(bChunkInd),1,fp); + fwrite(sBulletDNAstr, sBulletDNAlen,1,fp); +#else//_WIN64 + btAssert(0); +#endif//_WIN64 + } +#else//BT_INTERNAL_UPDATE_SERIALIZATION_STRUCTURES + if (VOID_IS_8) + { + dataChunk.len = sBulletDNAlen64; + dataChunk.oldPtr = sBulletDNAstr64; + fwrite(&dataChunk,sizeof(bChunkInd),1,fp); + fwrite(sBulletDNAstr64, sBulletDNAlen64,1,fp); + } + else + { + dataChunk.len = sBulletDNAlen; + dataChunk.oldPtr = sBulletDNAstr; + fwrite(&dataChunk,sizeof(bChunkInd),1,fp); + fwrite(sBulletDNAstr, sBulletDNAlen,1,fp); + } +#endif//BT_INTERNAL_UPDATE_SERIALIZATION_STRUCTURES +} + + +void btBulletFile::parse(int verboseMode) +{ +#ifdef BT_INTERNAL_UPDATE_SERIALIZATION_STRUCTURES + if (VOID_IS_8) + { +#ifdef _WIN64 + + if (m_DnaCopy) + delete m_DnaCopy; + m_DnaCopy = (char*)btAlignedAlloc(sBulletDNAlen64,16); + memcpy(m_DnaCopy,sBulletDNAstr64,sBulletDNAlen64); + parseInternal(verboseMode,(char*)sBulletDNAstr64,sBulletDNAlen64); +#else + btAssert(0); +#endif + } + else + { +#ifndef _WIN64 + + if (m_DnaCopy) + delete m_DnaCopy; + m_DnaCopy = (char*)btAlignedAlloc(sBulletDNAlen,16); + memcpy(m_DnaCopy,sBulletDNAstr,sBulletDNAlen); + parseInternal(verboseMode,m_DnaCopy,sBulletDNAlen); +#else + btAssert(0); +#endif + } +#else//BT_INTERNAL_UPDATE_SERIALIZATION_STRUCTURES + if (VOID_IS_8) + { + if (m_DnaCopy) + delete m_DnaCopy; + m_DnaCopy = (char*)btAlignedAlloc(sBulletDNAlen64,16); + memcpy(m_DnaCopy,sBulletDNAstr64,sBulletDNAlen64); + parseInternal(verboseMode,m_DnaCopy,sBulletDNAlen64); + } + else + { + if (m_DnaCopy) + delete m_DnaCopy; + m_DnaCopy = (char*)btAlignedAlloc(sBulletDNAlen,16); + memcpy(m_DnaCopy,sBulletDNAstr,sBulletDNAlen); + parseInternal(verboseMode,m_DnaCopy,sBulletDNAlen); + } +#endif//BT_INTERNAL_UPDATE_SERIALIZATION_STRUCTURES + + //the parsing will convert to cpu endian + mFlags &=~FD_ENDIAN_SWAP; + + int littleEndian= 1; + littleEndian= ((char*)&littleEndian)[0]; + + mFileBuffer[8] = littleEndian?'v':'V'; + +} + +// experimental +int btBulletFile::write(const char* fileName, bool fixupPointers) +{ + FILE *fp = fopen(fileName, "wb"); + if (fp) + { + char header[SIZEOFBLENDERHEADER] ; + memcpy(header, m_headerString, 7); + int endian= 1; + endian= ((char*)&endian)[0]; + + if (endian) + { + header[7] = '_'; + } else + { + header[7] = '-'; + } + if (VOID_IS_8) + { + header[8]='V'; + } else + { + header[8]='v'; + } + + header[9] = '2'; + header[10] = '7'; + header[11] = '5'; + + fwrite(header,SIZEOFBLENDERHEADER,1,fp); + + writeChunks(fp, fixupPointers); + + writeDNA(fp); + + fclose(fp); + + } else + { + printf("Error: cannot open file %s for writing\n",fileName); + return 0; + } + return 1; +} + + + +void btBulletFile::addStruct(const char* structType,void* data, int len, void* oldPtr, int code) +{ + + bParse::bChunkInd dataChunk; + dataChunk.code = code; + dataChunk.nr = 1; + dataChunk.len = len; + dataChunk.dna_nr = mMemoryDNA->getReverseType(structType); + dataChunk.oldPtr = oldPtr; + + ///Perform structure size validation + short* structInfo= mMemoryDNA->getStruct(dataChunk.dna_nr); + int elemBytes; + elemBytes= mMemoryDNA->getLength(structInfo[0]); +// int elemBytes = mMemoryDNA->getElementSize(structInfo[0],structInfo[1]); + assert(len==elemBytes); + + mLibPointers.insert(dataChunk.oldPtr, (bStructHandle*)data); + m_chunks.push_back(dataChunk); +} \ No newline at end of file diff --git a/Code/Physics/Bullet Source/BulletFileLoader/btBulletFile.h b/Code/Physics/Bullet Source/BulletFileLoader/btBulletFile.h new file mode 100644 index 00000000..c4d73562 --- /dev/null +++ b/Code/Physics/Bullet Source/BulletFileLoader/btBulletFile.h @@ -0,0 +1,83 @@ +/* +bParse +Copyright (c) 2006-2010 Charlie C & Erwin Coumans http://gamekit.googlecode.com + +This software is provided 'as-is', without any express or implied warranty. +In no event will the authors be held liable for any damages arising from the use of this software. +Permission is granted to anyone to use this software for any purpose, +including commercial applications, and to alter it and redistribute it freely, +subject to the following restrictions: + +1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. +2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. +3. This notice may not be removed or altered from any source distribution. +*/ + +#ifndef BT_BULLET_FILE_H +#define BT_BULLET_FILE_H + + +#include "bFile.h" +#include "LinearMath/btAlignedObjectArray.h" +#include "bDefines.h" + +#include "LinearMath/btSerializer.h" + + + +namespace bParse { + + // ----------------------------------------------------- // + class btBulletFile : public bFile + { + + + protected: + + char* m_DnaCopy; + + public: + + btAlignedObjectArray m_softBodies; + + btAlignedObjectArray m_rigidBodies; + + btAlignedObjectArray m_collisionObjects; + + btAlignedObjectArray m_collisionShapes; + + btAlignedObjectArray m_constraints; + + btAlignedObjectArray m_bvhs; + + btAlignedObjectArray m_triangleInfoMaps; + + btAlignedObjectArray m_dynamicsWorldInfo; + + btAlignedObjectArray m_dataBlocks; + btBulletFile(); + + btBulletFile(const char* fileName); + + btBulletFile(char *memoryBuffer, int len); + + virtual ~btBulletFile(); + + virtual void addDataBlock(char* dataBlock); + + + // experimental + virtual int write(const char* fileName, bool fixupPointers=false); + + virtual void parse(int verboseMode); + + virtual void parseData(); + + virtual void writeDNA(FILE* fp); + + void addStruct(const char* structType,void* data, int len, void* oldPtr, int code); + + }; +}; + +#endif //BT_BULLET_FILE_H diff --git a/Code/Physics/Bullet Source/BulletFileLoader/premake4.lua b/Code/Physics/Bullet Source/BulletFileLoader/premake4.lua new file mode 100644 index 00000000..f4aad3da --- /dev/null +++ b/Code/Physics/Bullet Source/BulletFileLoader/premake4.lua @@ -0,0 +1,12 @@ + project "BulletFileLoader" + + kind "StaticLib" + targetdir "../../lib" + includedirs { + "../../../src" + } + + files { + "**.cpp", + "**.h" + } \ No newline at end of file diff --git a/Code/Physics/Bullet Source/BulletWorldImporter/CMakeLists.txt b/Code/Physics/Bullet Source/BulletWorldImporter/CMakeLists.txt new file mode 100644 index 00000000..666ac21c --- /dev/null +++ b/Code/Physics/Bullet Source/BulletWorldImporter/CMakeLists.txt @@ -0,0 +1,40 @@ +INCLUDE_DIRECTORIES( + ${BULLET_PHYSICS_SOURCE_DIR}/src + ${BULLET_PHYSICS_SOURCE_DIR}/Extras/Serialize/BulletFileLoader +) + +ADD_LIBRARY( +BulletWorldImporter +btBulletWorldImporter.cpp +btBulletWorldImporter.h +btWorldImporter.cpp +btWorldImporter.h +) + +SET_TARGET_PROPERTIES(BulletWorldImporter PROPERTIES VERSION ${BULLET_VERSION}) +SET_TARGET_PROPERTIES(BulletWorldImporter PROPERTIES SOVERSION ${BULLET_VERSION}) + +IF (BUILD_SHARED_LIBS) + TARGET_LINK_LIBRARIES(BulletWorldImporter BulletDynamics BulletCollision BulletFileLoader LinearMath) +ENDIF (BUILD_SHARED_LIBS) + +IF (INSTALL_EXTRA_LIBS) + IF (NOT INTERNAL_CREATE_DISTRIBUTABLE_MSVC_PROJECTFILES) + #FILES_MATCHING requires CMake 2.6 + IF (${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION} GREATER 2.5) + IF (APPLE AND BUILD_SHARED_LIBS AND FRAMEWORK) + INSTALL(TARGETS BulletWorldImporter DESTINATION .) + ELSE (APPLE AND BUILD_SHARED_LIBS AND FRAMEWORK) + INSTALL(TARGETS BulletWorldImporter DESTINATION lib${LIB_SUFFIX}) + INSTALL(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} +DESTINATION ${INCLUDE_INSTALL_DIR} FILES_MATCHING PATTERN "*.h" PATTERN +".svn" EXCLUDE PATTERN "CMakeFiles" EXCLUDE) + ENDIF (APPLE AND BUILD_SHARED_LIBS AND FRAMEWORK) + ENDIF (${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION} GREATER 2.5) + + IF (APPLE AND BUILD_SHARED_LIBS AND FRAMEWORK) + SET_TARGET_PROPERTIES(BulletWorldImporter PROPERTIES FRAMEWORK true) + SET_TARGET_PROPERTIES(BulletWorldImporter PROPERTIES PUBLIC_HEADER "btBulletWorldImporter.h") + ENDIF (APPLE AND BUILD_SHARED_LIBS AND FRAMEWORK) + ENDIF (NOT INTERNAL_CREATE_DISTRIBUTABLE_MSVC_PROJECTFILES) +ENDIF (INSTALL_EXTRA_LIBS) diff --git a/Code/Physics/Bullet Source/BulletWorldImporter/btBulletWorldImporter.cpp b/Code/Physics/Bullet Source/BulletWorldImporter/btBulletWorldImporter.cpp new file mode 100644 index 00000000..3f3a3593 --- /dev/null +++ b/Code/Physics/Bullet Source/BulletWorldImporter/btBulletWorldImporter.cpp @@ -0,0 +1,362 @@ +/* +Bullet Continuous Collision Detection and Physics Library +Copyright (c) 2003-2012 Erwin Coumans http://bulletphysics.org + +This software is provided 'as-is', without any express or implied warranty. +In no event will the authors be held liable for any damages arising from the use of this software. +Permission is granted to anyone to use this software for any purpose, +including commercial applications, and to alter it and redistribute it freely, +subject to the following restrictions: + +1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. +2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. +3. This notice may not be removed or altered from any source distribution. +*/ + + +#include "btBulletWorldImporter.h" +#include "../BulletFileLoader/btBulletFile.h" + +#include "btBulletDynamicsCommon.h" +#include "BulletCollision/Gimpact/btGImpactShape.h" + + + +//#define USE_INTERNAL_EDGE_UTILITY +#ifdef USE_INTERNAL_EDGE_UTILITY +#include "BulletCollision/CollisionDispatch/btInternalEdgeUtility.h" +#endif //USE_INTERNAL_EDGE_UTILITY + +btBulletWorldImporter::btBulletWorldImporter(btDynamicsWorld* world) + :btWorldImporter(world) +{ +} + +btBulletWorldImporter::~btBulletWorldImporter() +{ +} + + +bool btBulletWorldImporter::loadFile( const char* fileName, const char* preSwapFilenameOut) +{ + bParse::btBulletFile* bulletFile2 = new bParse::btBulletFile(fileName); + + + bool result = loadFileFromMemory(bulletFile2); + //now you could save the file in 'native' format using + //bulletFile2->writeFile("native.bullet"); + if (result) + { + if (preSwapFilenameOut) + { + bulletFile2->preSwap(); + bulletFile2->writeFile(preSwapFilenameOut); + } + + } + delete bulletFile2; + + return result; + +} + + + +bool btBulletWorldImporter::loadFileFromMemory( char* memoryBuffer, int len) +{ + bParse::btBulletFile* bulletFile2 = new bParse::btBulletFile(memoryBuffer,len); + + bool result = loadFileFromMemory(bulletFile2); + + delete bulletFile2; + + return result; +} + + + + +bool btBulletWorldImporter::loadFileFromMemory( bParse::btBulletFile* bulletFile2) +{ + bool ok = (bulletFile2->getFlags()& bParse::FD_OK)!=0; + + if (ok) + bulletFile2->parse(m_verboseMode); + else + return false; + + if (m_verboseMode & bParse::FD_VERBOSE_DUMP_CHUNKS) + { + bulletFile2->dumpChunks(bulletFile2->getFileDNA()); + } + + return convertAllObjects(bulletFile2); + +} + +bool btBulletWorldImporter::convertAllObjects( bParse::btBulletFile* bulletFile2) +{ + + m_shapeMap.clear(); + m_bodyMap.clear(); + + int i; + + for (i=0;im_bvhs.size();i++) + { + btOptimizedBvh* bvh = createOptimizedBvh(); + + if (bulletFile2->getFlags() & bParse::FD_DOUBLE_PRECISION) + { + btQuantizedBvhDoubleData* bvhData = (btQuantizedBvhDoubleData*)bulletFile2->m_bvhs[i]; + bvh->deSerializeDouble(*bvhData); + } else + { + btQuantizedBvhFloatData* bvhData = (btQuantizedBvhFloatData*)bulletFile2->m_bvhs[i]; + bvh->deSerializeFloat(*bvhData); + } + m_bvhMap.insert(bulletFile2->m_bvhs[i],bvh); + } + + + + + + for (i=0;im_collisionShapes.size();i++) + { + btCollisionShapeData* shapeData = (btCollisionShapeData*)bulletFile2->m_collisionShapes[i]; + btCollisionShape* shape = convertCollisionShape(shapeData); + if (shape) + { + // printf("shapeMap.insert(%x,%x)\n",shapeData,shape); + m_shapeMap.insert(shapeData,shape); + } + + if (shape&& shapeData->m_name) + { + char* newname = duplicateName(shapeData->m_name); + m_objectNameMap.insert(shape,newname); + m_nameShapeMap.insert(newname,shape); + } + } + + + + + + for (int i=0;im_dynamicsWorldInfo.size();i++) + { + if (bulletFile2->getFlags() & bParse::FD_DOUBLE_PRECISION) + { + btDynamicsWorldDoubleData* solverInfoData = (btDynamicsWorldDoubleData*)bulletFile2->m_dynamicsWorldInfo[i]; + btContactSolverInfo solverInfo; + + btVector3 gravity; + gravity.deSerializeDouble(solverInfoData->m_gravity); + + solverInfo.m_tau = btScalar(solverInfoData->m_solverInfo.m_tau); + solverInfo.m_damping = btScalar(solverInfoData->m_solverInfo.m_damping); + solverInfo.m_friction = btScalar(solverInfoData->m_solverInfo.m_friction); + solverInfo.m_timeStep = btScalar(solverInfoData->m_solverInfo.m_timeStep); + + solverInfo.m_restitution = btScalar(solverInfoData->m_solverInfo.m_restitution); + solverInfo.m_maxErrorReduction = btScalar(solverInfoData->m_solverInfo.m_maxErrorReduction); + solverInfo.m_sor = btScalar(solverInfoData->m_solverInfo.m_sor); + solverInfo.m_erp = btScalar(solverInfoData->m_solverInfo.m_erp); + + solverInfo.m_erp2 = btScalar(solverInfoData->m_solverInfo.m_erp2); + solverInfo.m_globalCfm = btScalar(solverInfoData->m_solverInfo.m_globalCfm); + solverInfo.m_splitImpulsePenetrationThreshold = btScalar(solverInfoData->m_solverInfo.m_splitImpulsePenetrationThreshold); + solverInfo.m_splitImpulseTurnErp = btScalar(solverInfoData->m_solverInfo.m_splitImpulseTurnErp); + + solverInfo.m_linearSlop = btScalar(solverInfoData->m_solverInfo.m_linearSlop); + solverInfo.m_warmstartingFactor = btScalar(solverInfoData->m_solverInfo.m_warmstartingFactor); + solverInfo.m_maxGyroscopicForce = btScalar(solverInfoData->m_solverInfo.m_maxGyroscopicForce); + solverInfo.m_singleAxisRollingFrictionThreshold = btScalar(solverInfoData->m_solverInfo.m_singleAxisRollingFrictionThreshold); + + solverInfo.m_numIterations = solverInfoData->m_solverInfo.m_numIterations; + solverInfo.m_solverMode = solverInfoData->m_solverInfo.m_solverMode; + solverInfo.m_restingContactRestitutionThreshold = solverInfoData->m_solverInfo.m_restingContactRestitutionThreshold; + solverInfo.m_minimumSolverBatchSize = solverInfoData->m_solverInfo.m_minimumSolverBatchSize; + + solverInfo.m_splitImpulse = solverInfoData->m_solverInfo.m_splitImpulse; + + setDynamicsWorldInfo(gravity,solverInfo); + } else + { + btDynamicsWorldFloatData* solverInfoData = (btDynamicsWorldFloatData*)bulletFile2->m_dynamicsWorldInfo[i]; + btContactSolverInfo solverInfo; + + btVector3 gravity; + gravity.deSerializeFloat(solverInfoData->m_gravity); + + solverInfo.m_tau = solverInfoData->m_solverInfo.m_tau; + solverInfo.m_damping = solverInfoData->m_solverInfo.m_damping; + solverInfo.m_friction = solverInfoData->m_solverInfo.m_friction; + solverInfo.m_timeStep = solverInfoData->m_solverInfo.m_timeStep; + + solverInfo.m_restitution = solverInfoData->m_solverInfo.m_restitution; + solverInfo.m_maxErrorReduction = solverInfoData->m_solverInfo.m_maxErrorReduction; + solverInfo.m_sor = solverInfoData->m_solverInfo.m_sor; + solverInfo.m_erp = solverInfoData->m_solverInfo.m_erp; + + solverInfo.m_erp2 = solverInfoData->m_solverInfo.m_erp2; + solverInfo.m_globalCfm = solverInfoData->m_solverInfo.m_globalCfm; + solverInfo.m_splitImpulsePenetrationThreshold = solverInfoData->m_solverInfo.m_splitImpulsePenetrationThreshold; + solverInfo.m_splitImpulseTurnErp = solverInfoData->m_solverInfo.m_splitImpulseTurnErp; + + solverInfo.m_linearSlop = solverInfoData->m_solverInfo.m_linearSlop; + solverInfo.m_warmstartingFactor = solverInfoData->m_solverInfo.m_warmstartingFactor; + solverInfo.m_maxGyroscopicForce = solverInfoData->m_solverInfo.m_maxGyroscopicForce; + solverInfo.m_singleAxisRollingFrictionThreshold = solverInfoData->m_solverInfo.m_singleAxisRollingFrictionThreshold; + + solverInfo.m_numIterations = solverInfoData->m_solverInfo.m_numIterations; + solverInfo.m_solverMode = solverInfoData->m_solverInfo.m_solverMode; + solverInfo.m_restingContactRestitutionThreshold = solverInfoData->m_solverInfo.m_restingContactRestitutionThreshold; + solverInfo.m_minimumSolverBatchSize = solverInfoData->m_solverInfo.m_minimumSolverBatchSize; + + solverInfo.m_splitImpulse = solverInfoData->m_solverInfo.m_splitImpulse; + + setDynamicsWorldInfo(gravity,solverInfo); + } + } + + + for (i=0;im_rigidBodies.size();i++) + { + if (bulletFile2->getFlags() & bParse::FD_DOUBLE_PRECISION) + { + btRigidBodyDoubleData* colObjData = (btRigidBodyDoubleData*)bulletFile2->m_rigidBodies[i]; + convertRigidBodyDouble(colObjData); + } else + { + btRigidBodyFloatData* colObjData = (btRigidBodyFloatData*)bulletFile2->m_rigidBodies[i]; + convertRigidBodyFloat(colObjData); + } + + + } + + for (i=0;im_collisionObjects.size();i++) + { + if (bulletFile2->getFlags() & bParse::FD_DOUBLE_PRECISION) + { + btCollisionObjectDoubleData* colObjData = (btCollisionObjectDoubleData*)bulletFile2->m_collisionObjects[i]; + btCollisionShape** shapePtr = m_shapeMap.find(colObjData->m_collisionShape); + if (shapePtr && *shapePtr) + { + btTransform startTransform; + colObjData->m_worldTransform.m_origin.m_floats[3] = 0.f; + startTransform.deSerializeDouble(colObjData->m_worldTransform); + + btCollisionShape* shape = (btCollisionShape*)*shapePtr; + btCollisionObject* body = createCollisionObject(startTransform,shape,colObjData->m_name); + body->setFriction(btScalar(colObjData->m_friction)); + body->setRestitution(btScalar(colObjData->m_restitution)); + +#ifdef USE_INTERNAL_EDGE_UTILITY + if (shape->getShapeType() == TRIANGLE_MESH_SHAPE_PROXYTYPE) + { + btBvhTriangleMeshShape* trimesh = (btBvhTriangleMeshShape*)shape; + if (trimesh->getTriangleInfoMap()) + { + body->setCollisionFlags(body->getCollisionFlags() | btCollisionObject::CF_CUSTOM_MATERIAL_CALLBACK); + } + } +#endif //USE_INTERNAL_EDGE_UTILITY + m_bodyMap.insert(colObjData,body); + } else + { + printf("error: no shape found\n"); + } + + } else + { + btCollisionObjectFloatData* colObjData = (btCollisionObjectFloatData*)bulletFile2->m_collisionObjects[i]; + btCollisionShape** shapePtr = m_shapeMap.find(colObjData->m_collisionShape); + if (shapePtr && *shapePtr) + { + btTransform startTransform; + colObjData->m_worldTransform.m_origin.m_floats[3] = 0.f; + startTransform.deSerializeFloat(colObjData->m_worldTransform); + + btCollisionShape* shape = (btCollisionShape*)*shapePtr; + btCollisionObject* body = createCollisionObject(startTransform,shape,colObjData->m_name); + +#ifdef USE_INTERNAL_EDGE_UTILITY + if (shape->getShapeType() == TRIANGLE_MESH_SHAPE_PROXYTYPE) + { + btBvhTriangleMeshShape* trimesh = (btBvhTriangleMeshShape*)shape; + if (trimesh->getTriangleInfoMap()) + { + body->setCollisionFlags(body->getCollisionFlags() | btCollisionObject::CF_CUSTOM_MATERIAL_CALLBACK); + } + } +#endif //USE_INTERNAL_EDGE_UTILITY + m_bodyMap.insert(colObjData,body); + } else + { + printf("error: no shape found\n"); + } + } + + } + + + for (i=0;im_constraints.size();i++) + { + btTypedConstraintData2* constraintData = (btTypedConstraintData2*)bulletFile2->m_constraints[i]; + btTypedConstraintFloatData* singleC = (btTypedConstraintFloatData*)bulletFile2->m_constraints[i]; + btTypedConstraintDoubleData* doubleC = (btTypedConstraintDoubleData*)bulletFile2->m_constraints[i]; + + btCollisionObject** colAptr = m_bodyMap.find(constraintData->m_rbA); + btCollisionObject** colBptr = m_bodyMap.find(constraintData->m_rbB); + + btRigidBody* rbA = 0; + btRigidBody* rbB = 0; + + if (colAptr) + { + rbA = btRigidBody::upcast(*colAptr); + if (!rbA) + rbA = &getFixedBody(); + } + if (colBptr) + { + rbB = btRigidBody::upcast(*colBptr); + if (!rbB) + rbB = &getFixedBody(); + } + if (!rbA && !rbB) + continue; + + bool isDoublePrecisionData = (bulletFile2->getFlags() & bParse::FD_DOUBLE_PRECISION)!=0; + + if (isDoublePrecisionData) + { + if (bulletFile2->getVersion()>=282) + { + btTypedConstraintDoubleData* dc = (btTypedConstraintDoubleData*)constraintData; + convertConstraintDouble(dc, rbA,rbB, bulletFile2->getVersion()); + } else + { + //double-precision constraints were messed up until 2.82, try to recover data... + + btTypedConstraintData* oldData = (btTypedConstraintData*)constraintData; + + convertConstraintBackwardsCompatible281(oldData, rbA,rbB, bulletFile2->getVersion()); + + } + } + else + { + btTypedConstraintFloatData* dc = (btTypedConstraintFloatData*)constraintData; + convertConstraintFloat(dc, rbA,rbB, bulletFile2->getVersion()); + } + + + } + + return true; +} + diff --git a/Code/Physics/Bullet Source/BulletWorldImporter/btBulletWorldImporter.h b/Code/Physics/Bullet Source/BulletWorldImporter/btBulletWorldImporter.h new file mode 100644 index 00000000..27c1e7e3 --- /dev/null +++ b/Code/Physics/Bullet Source/BulletWorldImporter/btBulletWorldImporter.h @@ -0,0 +1,68 @@ +/* +Bullet Continuous Collision Detection and Physics Library +Copyright (c) 2003-2012 Erwin Coumans http://bulletphysics.org + +This software is provided 'as-is', without any express or implied warranty. +In no event will the authors be held liable for any damages arising from the use of this software. +Permission is granted to anyone to use this software for any purpose, +including commercial applications, and to alter it and redistribute it freely, +subject to the following restrictions: + +1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. +2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. +3. This notice may not be removed or altered from any source distribution. +*/ + + +#ifndef BULLET_WORLD_IMPORTER_H +#define BULLET_WORLD_IMPORTER_H + + +#include "btWorldImporter.h" + + +class btBulletFile; + + + + +namespace bParse +{ + class btBulletFile; + +}; + + + +///The btBulletWorldImporter is a starting point to import .bullet files. +///note that not all data is converted yet. You are expected to override or modify this class. +///See Bullet/Demos/SerializeDemo for a derived class that extract btSoftBody objects too. +class btBulletWorldImporter : public btWorldImporter +{ + + +public: + + btBulletWorldImporter(btDynamicsWorld* world=0); + + virtual ~btBulletWorldImporter(); + + ///if you pass a valid preSwapFilenameOut, it will save a new file with a different endianness + ///this pre-swapped file can be loaded without swapping on a target platform of different endianness + bool loadFile(const char* fileName, const char* preSwapFilenameOut=0); + + ///the memoryBuffer might be modified (for example if endian swaps are necessary) + bool loadFileFromMemory(char *memoryBuffer, int len); + + bool loadFileFromMemory(bParse::btBulletFile* file); + + //call make sure bulletFile2 has been parsed, either using btBulletFile::parse or btBulletWorldImporter::loadFileFromMemory + virtual bool convertAllObjects(bParse::btBulletFile* file); + + + + +}; + +#endif //BULLET_WORLD_IMPORTER_H + diff --git a/Code/Physics/Bullet Source/BulletWorldImporter/btWorldImporter.cpp b/Code/Physics/Bullet Source/BulletWorldImporter/btWorldImporter.cpp new file mode 100644 index 00000000..982931e0 --- /dev/null +++ b/Code/Physics/Bullet Source/BulletWorldImporter/btWorldImporter.cpp @@ -0,0 +1,1922 @@ +/* +Bullet Continuous Collision Detection and Physics Library +Copyright (c) 2003-2012 Erwin Coumans http://bulletphysics.org + +This software is provided 'as-is', without any express or implied warranty. +In no event will the authors be held liable for any damages arising from the use of this software. +Permission is granted to anyone to use this software for any purpose, +including commercial applications, and to alter it and redistribute it freely, +subject to the following restrictions: + +1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. +2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. +3. This notice may not be removed or altered from any source distribution. +*/ + +#include "btWorldImporter.h" +#include "btBulletDynamicsCommon.h" +#include "BulletCollision/Gimpact/btGImpactShape.h" + +btWorldImporter::btWorldImporter(btDynamicsWorld* world) +:m_dynamicsWorld(world), +m_verboseMode(0) +{ + +} + +btWorldImporter::~btWorldImporter() +{ +} + +void btWorldImporter::deleteAllData() +{ + int i; + for (i=0;iremoveConstraint(m_allocatedConstraints[i]); + delete m_allocatedConstraints[i]; + } + m_allocatedConstraints.clear(); + + + for (i=0;iremoveRigidBody(btRigidBody::upcast(m_allocatedRigidBodies[i])); + delete m_allocatedRigidBodies[i]; + } + + m_allocatedRigidBodies.clear(); + + + for (i=0;im_numMeshParts;a++) + { + btMeshPartData* curPart = &curData->m_meshPartsPtr[a]; + if(curPart->m_vertices3f) + delete [] curPart->m_vertices3f; + + if(curPart->m_vertices3d) + delete [] curPart->m_vertices3d; + + if(curPart->m_indices32) + delete [] curPart->m_indices32; + + if(curPart->m_3indices16) + delete [] curPart->m_3indices16; + + if(curPart->m_indices16) + delete [] curPart->m_indices16; + + if (curPart->m_3indices8) + delete [] curPart->m_3indices8; + + } + delete [] curData->m_meshPartsPtr; + delete curData; + } + m_allocatedbtStridingMeshInterfaceDatas.clear(); + + for (i=0;im_shapeType) + { + case STATIC_PLANE_PROXYTYPE: + { + btStaticPlaneShapeData* planeData = (btStaticPlaneShapeData*)shapeData; + btVector3 planeNormal,localScaling; + planeNormal.deSerializeFloat(planeData->m_planeNormal); + localScaling.deSerializeFloat(planeData->m_localScaling); + shape = createPlaneShape(planeNormal,planeData->m_planeConstant); + shape->setLocalScaling(localScaling); + + break; + } + case SCALED_TRIANGLE_MESH_SHAPE_PROXYTYPE: + { + btScaledTriangleMeshShapeData* scaledMesh = (btScaledTriangleMeshShapeData*) shapeData; + btCollisionShapeData* colShapeData = (btCollisionShapeData*) &scaledMesh->m_trimeshShapeData; + colShapeData->m_shapeType = TRIANGLE_MESH_SHAPE_PROXYTYPE; + btCollisionShape* childShape = convertCollisionShape(colShapeData); + btBvhTriangleMeshShape* meshShape = (btBvhTriangleMeshShape*)childShape; + btVector3 localScaling; + localScaling.deSerializeFloat(scaledMesh->m_localScaling); + + shape = createScaledTrangleMeshShape(meshShape, localScaling); + break; + } + case GIMPACT_SHAPE_PROXYTYPE: + { + btGImpactMeshShapeData* gimpactData = (btGImpactMeshShapeData*) shapeData; + if (gimpactData->m_gimpactSubType == CONST_GIMPACT_TRIMESH_SHAPE) + { + btStridingMeshInterfaceData* interfaceData = createStridingMeshInterfaceData(&gimpactData->m_meshInterface); + btTriangleIndexVertexArray* meshInterface = createMeshInterface(*interfaceData); + + + btGImpactMeshShape* gimpactShape = createGimpactShape(meshInterface); + btVector3 localScaling; + localScaling.deSerializeFloat(gimpactData->m_localScaling); + gimpactShape->setLocalScaling(localScaling); + gimpactShape->setMargin(btScalar(gimpactData->m_collisionMargin)); + gimpactShape->updateBound(); + shape = gimpactShape; + } else + { + printf("unsupported gimpact sub type\n"); + } + break; + } + + case CYLINDER_SHAPE_PROXYTYPE: + case CONE_SHAPE_PROXYTYPE: + case CAPSULE_SHAPE_PROXYTYPE: + case BOX_SHAPE_PROXYTYPE: + case SPHERE_SHAPE_PROXYTYPE: + case MULTI_SPHERE_SHAPE_PROXYTYPE: + case CONVEX_HULL_SHAPE_PROXYTYPE: + { + btConvexInternalShapeData* bsd = (btConvexInternalShapeData*)shapeData; + btVector3 implicitShapeDimensions; + implicitShapeDimensions.deSerializeFloat(bsd->m_implicitShapeDimensions); + btVector3 localScaling; + localScaling.deSerializeFloat(bsd->m_localScaling); + btVector3 margin(bsd->m_collisionMargin,bsd->m_collisionMargin,bsd->m_collisionMargin); + switch (shapeData->m_shapeType) + { + case BOX_SHAPE_PROXYTYPE: + { + btBoxShape* box= (btBoxShape*)createBoxShape(implicitShapeDimensions/localScaling+margin); + //box->initializePolyhedralFeatures(); + shape = box; + + break; + } + case SPHERE_SHAPE_PROXYTYPE: + { + shape = createSphereShape(implicitShapeDimensions.getX()); + break; + } + case CAPSULE_SHAPE_PROXYTYPE: + { + btCapsuleShapeData* capData = (btCapsuleShapeData*)shapeData; + switch (capData->m_upAxis) + { + case 0: + { + shape = createCapsuleShapeX(implicitShapeDimensions.getY()+bsd->m_collisionMargin*2,2*implicitShapeDimensions.getX()); + break; + } + case 1: + { + shape = createCapsuleShapeY(implicitShapeDimensions.getX()+bsd->m_collisionMargin*2,2*implicitShapeDimensions.getY()); + break; + } + case 2: + { + shape = createCapsuleShapeZ(implicitShapeDimensions.getX()+bsd->m_collisionMargin*2,2*implicitShapeDimensions.getZ()); + break; + } + default: + { + printf("error: wrong up axis for btCapsuleShape\n"); + } + bsd->m_collisionMargin = 0.f; + + }; + + break; + } + case CYLINDER_SHAPE_PROXYTYPE: + { + btCylinderShapeData* cylData = (btCylinderShapeData*) shapeData; + btVector3 halfExtents = implicitShapeDimensions+margin; + switch (cylData->m_upAxis) + { + case 0: + { + shape = createCylinderShapeX(halfExtents.getY(),halfExtents.getX()); + break; + } + case 1: + { + shape = createCylinderShapeY(halfExtents.getX(),halfExtents.getY()); + break; + } + case 2: + { + shape = createCylinderShapeZ(halfExtents.getX(),halfExtents.getZ()); + break; + } + default: + { + printf("unknown Cylinder up axis\n"); + } + + }; + + + + break; + } + case CONE_SHAPE_PROXYTYPE: + { + btConeShapeData* conData = (btConeShapeData*) shapeData; + btVector3 halfExtents = implicitShapeDimensions;//+margin; + switch (conData->m_upIndex) + { + case 0: + { + shape = createConeShapeX(halfExtents.getY(),halfExtents.getX()); + break; + } + case 1: + { + shape = createConeShapeY(halfExtents.getX(),halfExtents.getY()); + break; + } + case 2: + { + shape = createConeShapeZ(halfExtents.getX(),halfExtents.getZ()); + break; + } + default: + { + printf("unknown Cone up axis\n"); + } + + }; + + + + break; + } + case MULTI_SPHERE_SHAPE_PROXYTYPE: + { + btMultiSphereShapeData* mss = (btMultiSphereShapeData*)bsd; + int numSpheres = mss->m_localPositionArraySize; + + btAlignedObjectArray tmpPos; + btAlignedObjectArray radii; + radii.resize(numSpheres); + tmpPos.resize(numSpheres); + int i; + for ( i=0;im_localPositionArrayPtr[i].m_pos); + radii[i] = mss->m_localPositionArrayPtr[i].m_radius; + } + shape = createMultiSphereShape(&tmpPos[0],&radii[0],numSpheres); + break; + } + case CONVEX_HULL_SHAPE_PROXYTYPE: + { + // int sz = sizeof(btConvexHullShapeData); + // int sz2 = sizeof(btConvexInternalShapeData); + // int sz3 = sizeof(btCollisionShapeData); + btConvexHullShapeData* convexData = (btConvexHullShapeData*)bsd; + int numPoints = convexData->m_numUnscaledPoints; + + btAlignedObjectArray tmpPoints; + tmpPoints.resize(numPoints); + int i; + for ( i=0;im_unscaledPointsDoublePtr) + tmpPoints[i].deSerialize(convexData->m_unscaledPointsDoublePtr[i]); + if (convexData->m_unscaledPointsFloatPtr) + tmpPoints[i].deSerializeFloat(convexData->m_unscaledPointsFloatPtr[i]); +#else + if (convexData->m_unscaledPointsFloatPtr) + tmpPoints[i].deSerialize(convexData->m_unscaledPointsFloatPtr[i]); + if (convexData->m_unscaledPointsDoublePtr) + tmpPoints[i].deSerializeDouble(convexData->m_unscaledPointsDoublePtr[i]); +#endif //BT_USE_DOUBLE_PRECISION + } + btConvexHullShape* hullShape = createConvexHullShape(); + for (i=0;iaddPoint(tmpPoints[i]); + } + hullShape->setMargin(bsd->m_collisionMargin); + //hullShape->initializePolyhedralFeatures(); + shape = hullShape; + break; + } + default: + { + printf("error: cannot create shape type (%d)\n",shapeData->m_shapeType); + } + } + + if (shape) + { + shape->setMargin(bsd->m_collisionMargin); + + btVector3 localScaling; + localScaling.deSerializeFloat(bsd->m_localScaling); + shape->setLocalScaling(localScaling); + + } + break; + } + case TRIANGLE_MESH_SHAPE_PROXYTYPE: + { + btTriangleMeshShapeData* trimesh = (btTriangleMeshShapeData*)shapeData; + btStridingMeshInterfaceData* interfaceData = createStridingMeshInterfaceData(&trimesh->m_meshInterface); + btTriangleIndexVertexArray* meshInterface = createMeshInterface(*interfaceData); + if (!meshInterface->getNumSubParts()) + { + return 0; + } + + btVector3 scaling; scaling.deSerializeFloat(trimesh->m_meshInterface.m_scaling); + meshInterface->setScaling(scaling); + + + btOptimizedBvh* bvh = 0; +#if 1 + if (trimesh->m_quantizedFloatBvh) + { + btOptimizedBvh** bvhPtr = m_bvhMap.find(trimesh->m_quantizedFloatBvh); + if (bvhPtr && *bvhPtr) + { + bvh = *bvhPtr; + } else + { + bvh = createOptimizedBvh(); + bvh->deSerializeFloat(*trimesh->m_quantizedFloatBvh); + } + } + if (trimesh->m_quantizedDoubleBvh) + { + btOptimizedBvh** bvhPtr = m_bvhMap.find(trimesh->m_quantizedDoubleBvh); + if (bvhPtr && *bvhPtr) + { + bvh = *bvhPtr; + } else + { + bvh = createOptimizedBvh(); + bvh->deSerializeDouble(*trimesh->m_quantizedDoubleBvh); + } + } +#endif + + + btBvhTriangleMeshShape* trimeshShape = createBvhTriangleMeshShape(meshInterface,bvh); + trimeshShape->setMargin(trimesh->m_collisionMargin); + shape = trimeshShape; + + if (trimesh->m_triangleInfoMap) + { + btTriangleInfoMap* map = createTriangleInfoMap(); + map->deSerialize(*trimesh->m_triangleInfoMap); + trimeshShape->setTriangleInfoMap(map); + +#ifdef USE_INTERNAL_EDGE_UTILITY + gContactAddedCallback = btAdjustInternalEdgeContactsCallback; +#endif //USE_INTERNAL_EDGE_UTILITY + + } + + //printf("trimesh->m_collisionMargin=%f\n",trimesh->m_collisionMargin); + break; + } + case COMPOUND_SHAPE_PROXYTYPE: + { + btCompoundShapeData* compoundData = (btCompoundShapeData*)shapeData; + btCompoundShape* compoundShape = createCompoundShape(); + + btCompoundShapeChildData* childShapeDataArray = &compoundData->m_childShapePtr[0]; + + + btAlignedObjectArray childShapes; + for (int i=0;im_numChildShapes;i++) + { + btCompoundShapeChildData* ptr = &compoundData->m_childShapePtr[i]; + + btCollisionShapeData* cd = compoundData->m_childShapePtr[i].m_childShape; + + btCollisionShape* childShape = convertCollisionShape(cd); + if (childShape) + { + btTransform localTransform; + localTransform.deSerializeFloat(compoundData->m_childShapePtr[i].m_transform); + compoundShape->addChildShape(localTransform,childShape); + } else + { +#ifdef _DEBUG + printf("error: couldn't create childShape for compoundShape\n"); +#endif + } + + } + shape = compoundShape; + + break; + } + case SOFTBODY_SHAPE_PROXYTYPE: + { + return 0; + } + default: + { +#ifdef _DEBUG + printf("unsupported shape type (%d)\n",shapeData->m_shapeType); +#endif + } + } + + return shape; + +} + + + +char* btWorldImporter::duplicateName(const char* name) +{ + if (name) + { + int l = (int)strlen(name); + char* newName = new char[l+1]; + memcpy(newName,name,l); + newName[l] = 0; + m_allocatedNames.push_back(newName); + return newName; + } + return 0; +} + +void btWorldImporter::convertConstraintBackwardsCompatible281(btTypedConstraintData* constraintData, btRigidBody* rbA, btRigidBody* rbB, int fileVersion) +{ + + btTypedConstraint* constraint = 0; + + switch (constraintData->m_objectType) + { + case POINT2POINT_CONSTRAINT_TYPE: + { + btPoint2PointConstraintDoubleData* p2pData = (btPoint2PointConstraintDoubleData*)constraintData; + if (rbA && rbB) + { + btVector3 pivotInA,pivotInB; + pivotInA.deSerializeDouble(p2pData->m_pivotInA); + pivotInB.deSerializeDouble(p2pData->m_pivotInB); + constraint = createPoint2PointConstraint(*rbA,*rbB,pivotInA,pivotInB); + } else + { + btVector3 pivotInA; + pivotInA.deSerializeDouble(p2pData->m_pivotInA); + constraint = createPoint2PointConstraint(*rbA,pivotInA); + } + break; + } + case HINGE_CONSTRAINT_TYPE: + { + btHingeConstraint* hinge = 0; + + btHingeConstraintDoubleData* hingeData = (btHingeConstraintDoubleData*)constraintData; + if (rbA&& rbB) + { + btTransform rbAFrame,rbBFrame; + rbAFrame.deSerializeDouble(hingeData->m_rbAFrame); + rbBFrame.deSerializeDouble(hingeData->m_rbBFrame); + hinge = createHingeConstraint(*rbA,*rbB,rbAFrame,rbBFrame,hingeData->m_useReferenceFrameA!=0); + } else + { + btTransform rbAFrame; + rbAFrame.deSerializeDouble(hingeData->m_rbAFrame); + hinge = createHingeConstraint(*rbA,rbAFrame,hingeData->m_useReferenceFrameA!=0); + } + if (hingeData->m_enableAngularMotor) + { + hinge->enableAngularMotor(true,(btScalar)hingeData->m_motorTargetVelocity,(btScalar)hingeData->m_maxMotorImpulse); + } + hinge->setAngularOnly(hingeData->m_angularOnly!=0); + hinge->setLimit(btScalar(hingeData->m_lowerLimit),btScalar(hingeData->m_upperLimit),btScalar(hingeData->m_limitSoftness),btScalar(hingeData->m_biasFactor),btScalar(hingeData->m_relaxationFactor)); + + constraint = hinge; + break; + + } + case CONETWIST_CONSTRAINT_TYPE: + { + btConeTwistConstraintData* coneData = (btConeTwistConstraintData*)constraintData; + btConeTwistConstraint* coneTwist = 0; + + if (rbA&& rbB) + { + btTransform rbAFrame,rbBFrame; + rbAFrame.deSerializeFloat(coneData->m_rbAFrame); + rbBFrame.deSerializeFloat(coneData->m_rbBFrame); + coneTwist = createConeTwistConstraint(*rbA,*rbB,rbAFrame,rbBFrame); + } else + { + btTransform rbAFrame; + rbAFrame.deSerializeFloat(coneData->m_rbAFrame); + coneTwist = createConeTwistConstraint(*rbA,rbAFrame); + } + coneTwist->setLimit((btScalar)coneData->m_swingSpan1,(btScalar)coneData->m_swingSpan2,(btScalar)coneData->m_twistSpan,(btScalar)coneData->m_limitSoftness, + (btScalar)coneData->m_biasFactor,(btScalar)coneData->m_relaxationFactor); + coneTwist->setDamping((btScalar)coneData->m_damping); + + constraint = coneTwist; + break; + } + + case D6_SPRING_CONSTRAINT_TYPE: + { + + btGeneric6DofSpringConstraintData* dofData = (btGeneric6DofSpringConstraintData*)constraintData; + // int sz = sizeof(btGeneric6DofSpringConstraintData); + btGeneric6DofSpringConstraint* dof = 0; + + if (rbA && rbB) + { + btTransform rbAFrame,rbBFrame; + rbAFrame.deSerializeFloat(dofData->m_6dofData.m_rbAFrame); + rbBFrame.deSerializeFloat(dofData->m_6dofData.m_rbBFrame); + dof = createGeneric6DofSpringConstraint(*rbA,*rbB,rbAFrame,rbBFrame,dofData->m_6dofData.m_useLinearReferenceFrameA!=0); + } else + { + printf("Error in btWorldImporter::createGeneric6DofSpringConstraint: requires rbA && rbB\n"); + } + + if (dof) + { + btVector3 angLowerLimit,angUpperLimit, linLowerLimit,linUpperlimit; + angLowerLimit.deSerializeFloat(dofData->m_6dofData.m_angularLowerLimit); + angUpperLimit.deSerializeFloat(dofData->m_6dofData.m_angularUpperLimit); + linLowerLimit.deSerializeFloat(dofData->m_6dofData.m_linearLowerLimit); + linUpperlimit.deSerializeFloat(dofData->m_6dofData.m_linearUpperLimit); + + angLowerLimit.setW(0.f); + dof->setAngularLowerLimit(angLowerLimit); + dof->setAngularUpperLimit(angUpperLimit); + dof->setLinearLowerLimit(linLowerLimit); + dof->setLinearUpperLimit(linUpperlimit); + + int i; + if (fileVersion>280) + { + for (i=0;i<6;i++) + { + dof->setStiffness(i,(btScalar)dofData->m_springStiffness[i]); + dof->setEquilibriumPoint(i,(btScalar)dofData->m_equilibriumPoint[i]); + dof->enableSpring(i,dofData->m_springEnabled[i]!=0); + dof->setDamping(i,(btScalar)dofData->m_springDamping[i]); + } + } + } + + constraint = dof; + break; + + } + case D6_CONSTRAINT_TYPE: + { + btGeneric6DofConstraintData* dofData = (btGeneric6DofConstraintData*)constraintData; + btGeneric6DofConstraint* dof = 0; + + if (rbA&& rbB) + { + btTransform rbAFrame,rbBFrame; + rbAFrame.deSerializeFloat(dofData->m_rbAFrame); + rbBFrame.deSerializeFloat(dofData->m_rbBFrame); + dof = createGeneric6DofConstraint(*rbA,*rbB,rbAFrame,rbBFrame,dofData->m_useLinearReferenceFrameA!=0); + } else + { + if (rbB) + { + btTransform rbBFrame; + rbBFrame.deSerializeFloat(dofData->m_rbBFrame); + dof = createGeneric6DofConstraint(*rbB,rbBFrame,dofData->m_useLinearReferenceFrameA!=0); + } else + { + printf("Error in btWorldImporter::createGeneric6DofConstraint: missing rbB\n"); + } + } + + if (dof) + { + btVector3 angLowerLimit,angUpperLimit, linLowerLimit,linUpperlimit; + angLowerLimit.deSerializeFloat(dofData->m_angularLowerLimit); + angUpperLimit.deSerializeFloat(dofData->m_angularUpperLimit); + linLowerLimit.deSerializeFloat(dofData->m_linearLowerLimit); + linUpperlimit.deSerializeFloat(dofData->m_linearUpperLimit); + + dof->setAngularLowerLimit(angLowerLimit); + dof->setAngularUpperLimit(angUpperLimit); + dof->setLinearLowerLimit(linLowerLimit); + dof->setLinearUpperLimit(linUpperlimit); + } + + constraint = dof; + break; + } + case SLIDER_CONSTRAINT_TYPE: + { + btSliderConstraintData* sliderData = (btSliderConstraintData*)constraintData; + btSliderConstraint* slider = 0; + if (rbA&& rbB) + { + btTransform rbAFrame,rbBFrame; + rbAFrame.deSerializeFloat(sliderData->m_rbAFrame); + rbBFrame.deSerializeFloat(sliderData->m_rbBFrame); + slider = createSliderConstraint(*rbA,*rbB,rbAFrame,rbBFrame,sliderData->m_useLinearReferenceFrameA!=0); + } else + { + btTransform rbBFrame; + rbBFrame.deSerializeFloat(sliderData->m_rbBFrame); + slider = createSliderConstraint(*rbB,rbBFrame,sliderData->m_useLinearReferenceFrameA!=0); + } + slider->setLowerLinLimit((btScalar)sliderData->m_linearLowerLimit); + slider->setUpperLinLimit((btScalar)sliderData->m_linearUpperLimit); + slider->setLowerAngLimit((btScalar)sliderData->m_angularLowerLimit); + slider->setUpperAngLimit((btScalar)sliderData->m_angularUpperLimit); + slider->setUseFrameOffset(sliderData->m_useOffsetForConstraintFrame!=0); + constraint = slider; + break; + } + + default: + { + printf("unknown constraint type\n"); + } + }; + + if (constraint) + { + constraint->setDbgDrawSize((btScalar)constraintData->m_dbgDrawSize); + ///those fields didn't exist and set to zero for pre-280 versions, so do a check here + if (fileVersion>=280) + { + constraint->setBreakingImpulseThreshold((btScalar)constraintData->m_breakingImpulseThreshold); + constraint->setEnabled(constraintData->m_isEnabled!=0); + constraint->setOverrideNumSolverIterations(constraintData->m_overrideNumSolverIterations); + } + + if (constraintData->m_name) + { + char* newname = duplicateName(constraintData->m_name); + m_nameConstraintMap.insert(newname,constraint); + m_objectNameMap.insert(constraint,newname); + } + if(m_dynamicsWorld) + m_dynamicsWorld->addConstraint(constraint,constraintData->m_disableCollisionsBetweenLinkedBodies!=0); + } + +} + +void btWorldImporter::convertConstraintFloat(btTypedConstraintFloatData* constraintData, btRigidBody* rbA, btRigidBody* rbB, int fileVersion) +{ + btTypedConstraint* constraint = 0; + + switch (constraintData->m_objectType) + { + case POINT2POINT_CONSTRAINT_TYPE: + { + btPoint2PointConstraintFloatData* p2pData = (btPoint2PointConstraintFloatData*)constraintData; + if (rbA&& rbB) + { + btVector3 pivotInA,pivotInB; + pivotInA.deSerializeFloat(p2pData->m_pivotInA); + pivotInB.deSerializeFloat(p2pData->m_pivotInB); + constraint = createPoint2PointConstraint(*rbA,*rbB,pivotInA,pivotInB); + + } else + { + btVector3 pivotInA; + pivotInA.deSerializeFloat(p2pData->m_pivotInA); + constraint = createPoint2PointConstraint(*rbA,pivotInA); + } + break; + } + case HINGE_CONSTRAINT_TYPE: + { + btHingeConstraint* hinge = 0; + btHingeConstraintFloatData* hingeData = (btHingeConstraintFloatData*)constraintData; + if (rbA&& rbB) + { + btTransform rbAFrame,rbBFrame; + rbAFrame.deSerializeFloat(hingeData->m_rbAFrame); + rbBFrame.deSerializeFloat(hingeData->m_rbBFrame); + hinge = createHingeConstraint(*rbA,*rbB,rbAFrame,rbBFrame,hingeData->m_useReferenceFrameA!=0); + } else + { + btTransform rbAFrame; + rbAFrame.deSerializeFloat(hingeData->m_rbAFrame); + hinge = createHingeConstraint(*rbA,rbAFrame,hingeData->m_useReferenceFrameA!=0); + } + if (hingeData->m_enableAngularMotor) + { + hinge->enableAngularMotor(true,hingeData->m_motorTargetVelocity,hingeData->m_maxMotorImpulse); + } + hinge->setAngularOnly(hingeData->m_angularOnly!=0); + hinge->setLimit(btScalar(hingeData->m_lowerLimit),btScalar(hingeData->m_upperLimit),btScalar(hingeData->m_limitSoftness),btScalar(hingeData->m_biasFactor),btScalar(hingeData->m_relaxationFactor)); + + constraint = hinge; + break; + + } + case CONETWIST_CONSTRAINT_TYPE: + { + btConeTwistConstraintData* coneData = (btConeTwistConstraintData*)constraintData; + btConeTwistConstraint* coneTwist = 0; + + if (rbA&& rbB) + { + btTransform rbAFrame,rbBFrame; + rbAFrame.deSerializeFloat(coneData->m_rbAFrame); + rbBFrame.deSerializeFloat(coneData->m_rbBFrame); + coneTwist = createConeTwistConstraint(*rbA,*rbB,rbAFrame,rbBFrame); + } else + { + btTransform rbAFrame; + rbAFrame.deSerializeFloat(coneData->m_rbAFrame); + coneTwist = createConeTwistConstraint(*rbA,rbAFrame); + } + coneTwist->setLimit(coneData->m_swingSpan1,coneData->m_swingSpan2,coneData->m_twistSpan,coneData->m_limitSoftness,coneData->m_biasFactor,coneData->m_relaxationFactor); + coneTwist->setDamping(coneData->m_damping); + + constraint = coneTwist; + break; + } + + case D6_SPRING_CONSTRAINT_TYPE: + { + + btGeneric6DofSpringConstraintData* dofData = (btGeneric6DofSpringConstraintData*)constraintData; + // int sz = sizeof(btGeneric6DofSpringConstraintData); + btGeneric6DofSpringConstraint* dof = 0; + + if (rbA && rbB) + { + btTransform rbAFrame,rbBFrame; + rbAFrame.deSerializeFloat(dofData->m_6dofData.m_rbAFrame); + rbBFrame.deSerializeFloat(dofData->m_6dofData.m_rbBFrame); + dof = createGeneric6DofSpringConstraint(*rbA,*rbB,rbAFrame,rbBFrame,dofData->m_6dofData.m_useLinearReferenceFrameA!=0); + } else + { + printf("Error in btWorldImporter::createGeneric6DofSpringConstraint: requires rbA && rbB\n"); + } + + if (dof) + { + btVector3 angLowerLimit,angUpperLimit, linLowerLimit,linUpperlimit; + angLowerLimit.deSerializeFloat(dofData->m_6dofData.m_angularLowerLimit); + angUpperLimit.deSerializeFloat(dofData->m_6dofData.m_angularUpperLimit); + linLowerLimit.deSerializeFloat(dofData->m_6dofData.m_linearLowerLimit); + linUpperlimit.deSerializeFloat(dofData->m_6dofData.m_linearUpperLimit); + + angLowerLimit.setW(0.f); + dof->setAngularLowerLimit(angLowerLimit); + dof->setAngularUpperLimit(angUpperLimit); + dof->setLinearLowerLimit(linLowerLimit); + dof->setLinearUpperLimit(linUpperlimit); + + int i; + if (fileVersion>280) + { + for (i=0;i<6;i++) + { + dof->setStiffness(i,dofData->m_springStiffness[i]); + dof->setEquilibriumPoint(i,dofData->m_equilibriumPoint[i]); + dof->enableSpring(i,dofData->m_springEnabled[i]!=0); + dof->setDamping(i,dofData->m_springDamping[i]); + } + } + } + + constraint = dof; + break; + } + case D6_CONSTRAINT_TYPE: + { + btGeneric6DofConstraintData* dofData = (btGeneric6DofConstraintData*)constraintData; + btGeneric6DofConstraint* dof = 0; + + if (rbA&& rbB) + { + btTransform rbAFrame,rbBFrame; + rbAFrame.deSerializeFloat(dofData->m_rbAFrame); + rbBFrame.deSerializeFloat(dofData->m_rbBFrame); + dof = createGeneric6DofConstraint(*rbA,*rbB,rbAFrame,rbBFrame,dofData->m_useLinearReferenceFrameA!=0); + } else + { + if (rbB) + { + btTransform rbBFrame; + rbBFrame.deSerializeFloat(dofData->m_rbBFrame); + dof = createGeneric6DofConstraint(*rbB,rbBFrame,dofData->m_useLinearReferenceFrameA!=0); + } else + { + printf("Error in btWorldImporter::createGeneric6DofConstraint: missing rbB\n"); + } + } + + if (dof) + { + btVector3 angLowerLimit,angUpperLimit, linLowerLimit,linUpperlimit; + angLowerLimit.deSerializeFloat(dofData->m_angularLowerLimit); + angUpperLimit.deSerializeFloat(dofData->m_angularUpperLimit); + linLowerLimit.deSerializeFloat(dofData->m_linearLowerLimit); + linUpperlimit.deSerializeFloat(dofData->m_linearUpperLimit); + + dof->setAngularLowerLimit(angLowerLimit); + dof->setAngularUpperLimit(angUpperLimit); + dof->setLinearLowerLimit(linLowerLimit); + dof->setLinearUpperLimit(linUpperlimit); + } + + constraint = dof; + break; + } + case SLIDER_CONSTRAINT_TYPE: + { + btSliderConstraintData* sliderData = (btSliderConstraintData*)constraintData; + btSliderConstraint* slider = 0; + if (rbA&& rbB) + { + btTransform rbAFrame,rbBFrame; + rbAFrame.deSerializeFloat(sliderData->m_rbAFrame); + rbBFrame.deSerializeFloat(sliderData->m_rbBFrame); + slider = createSliderConstraint(*rbA,*rbB,rbAFrame,rbBFrame,sliderData->m_useLinearReferenceFrameA!=0); + } else + { + btTransform rbBFrame; + rbBFrame.deSerializeFloat(sliderData->m_rbBFrame); + slider = createSliderConstraint(*rbB,rbBFrame,sliderData->m_useLinearReferenceFrameA!=0); + } + slider->setLowerLinLimit(sliderData->m_linearLowerLimit); + slider->setUpperLinLimit(sliderData->m_linearUpperLimit); + slider->setLowerAngLimit(sliderData->m_angularLowerLimit); + slider->setUpperAngLimit(sliderData->m_angularUpperLimit); + slider->setUseFrameOffset(sliderData->m_useOffsetForConstraintFrame!=0); + constraint = slider; + break; + } + case GEAR_CONSTRAINT_TYPE: + { + btGearConstraintFloatData* gearData = (btGearConstraintFloatData*) constraintData; + btGearConstraint* gear = 0; + if (rbA&&rbB) + { + btVector3 axisInA,axisInB; + axisInA.deSerializeFloat(gearData->m_axisInA); + axisInB.deSerializeFloat(gearData->m_axisInB); + gear = createGearConstraint(*rbA, *rbB, axisInA,axisInB, gearData->m_ratio); + } else + { + btAssert(0); + //perhaps a gear against a 'fixed' body, while the 'fixed' body is not serialized? + //btGearConstraint(btRigidBody& rbA, btRigidBody& rbB, const btVector3& axisInA,const btVector3& axisInB, btScalar ratio=1.f); + } + constraint = gear; + break; + } + default: + { + printf("unknown constraint type\n"); + } + }; + + if (constraint) + { + constraint->setDbgDrawSize(constraintData->m_dbgDrawSize); + ///those fields didn't exist and set to zero for pre-280 versions, so do a check here + if (fileVersion>=280) + { + constraint->setBreakingImpulseThreshold(constraintData->m_breakingImpulseThreshold); + constraint->setEnabled(constraintData->m_isEnabled!=0); + constraint->setOverrideNumSolverIterations(constraintData->m_overrideNumSolverIterations); + } + + if (constraintData->m_name) + { + char* newname = duplicateName(constraintData->m_name); + m_nameConstraintMap.insert(newname,constraint); + m_objectNameMap.insert(constraint,newname); + } + if(m_dynamicsWorld) + m_dynamicsWorld->addConstraint(constraint,constraintData->m_disableCollisionsBetweenLinkedBodies!=0); + } + + +} + + + +void btWorldImporter::convertConstraintDouble(btTypedConstraintDoubleData* constraintData, btRigidBody* rbA, btRigidBody* rbB, int fileVersion) +{ + btTypedConstraint* constraint = 0; + + switch (constraintData->m_objectType) + { + case POINT2POINT_CONSTRAINT_TYPE: + { + btPoint2PointConstraintDoubleData2* p2pData = (btPoint2PointConstraintDoubleData2*)constraintData; + if (rbA && rbB) + { + btVector3 pivotInA,pivotInB; + pivotInA.deSerializeDouble(p2pData->m_pivotInA); + pivotInB.deSerializeDouble(p2pData->m_pivotInB); + constraint = createPoint2PointConstraint(*rbA,*rbB,pivotInA,pivotInB); + } else + { + btVector3 pivotInA; + pivotInA.deSerializeDouble(p2pData->m_pivotInA); + constraint = createPoint2PointConstraint(*rbA,pivotInA); + } + break; + } + case HINGE_CONSTRAINT_TYPE: + { + btHingeConstraint* hinge = 0; + + btHingeConstraintDoubleData2* hingeData = (btHingeConstraintDoubleData2*)constraintData; + if (rbA&& rbB) + { + btTransform rbAFrame,rbBFrame; + rbAFrame.deSerializeDouble(hingeData->m_rbAFrame); + rbBFrame.deSerializeDouble(hingeData->m_rbBFrame); + hinge = createHingeConstraint(*rbA,*rbB,rbAFrame,rbBFrame,hingeData->m_useReferenceFrameA!=0); + } else + { + btTransform rbAFrame; + rbAFrame.deSerializeDouble(hingeData->m_rbAFrame); + hinge = createHingeConstraint(*rbA,rbAFrame,hingeData->m_useReferenceFrameA!=0); + } + if (hingeData->m_enableAngularMotor) + { + hinge->enableAngularMotor(true,(btScalar)hingeData->m_motorTargetVelocity,(btScalar)hingeData->m_maxMotorImpulse); + } + hinge->setAngularOnly(hingeData->m_angularOnly!=0); + hinge->setLimit(btScalar(hingeData->m_lowerLimit),btScalar(hingeData->m_upperLimit),btScalar(hingeData->m_limitSoftness),btScalar(hingeData->m_biasFactor),btScalar(hingeData->m_relaxationFactor)); + + constraint = hinge; + break; + + } + case CONETWIST_CONSTRAINT_TYPE: + { + btConeTwistConstraintDoubleData* coneData = (btConeTwistConstraintDoubleData*)constraintData; + btConeTwistConstraint* coneTwist = 0; + + if (rbA&& rbB) + { + btTransform rbAFrame,rbBFrame; + rbAFrame.deSerializeDouble(coneData->m_rbAFrame); + rbBFrame.deSerializeDouble(coneData->m_rbBFrame); + coneTwist = createConeTwistConstraint(*rbA,*rbB,rbAFrame,rbBFrame); + } else + { + btTransform rbAFrame; + rbAFrame.deSerializeDouble(coneData->m_rbAFrame); + coneTwist = createConeTwistConstraint(*rbA,rbAFrame); + } + coneTwist->setLimit((btScalar)coneData->m_swingSpan1,(btScalar)coneData->m_swingSpan2,(btScalar)coneData->m_twistSpan,(btScalar)coneData->m_limitSoftness, + (btScalar)coneData->m_biasFactor,(btScalar)coneData->m_relaxationFactor); + coneTwist->setDamping((btScalar)coneData->m_damping); + + constraint = coneTwist; + break; + } + + case D6_SPRING_CONSTRAINT_TYPE: + { + + btGeneric6DofSpringConstraintDoubleData2* dofData = (btGeneric6DofSpringConstraintDoubleData2*)constraintData; + // int sz = sizeof(btGeneric6DofSpringConstraintData); + btGeneric6DofSpringConstraint* dof = 0; + + if (rbA && rbB) + { + btTransform rbAFrame,rbBFrame; + rbAFrame.deSerializeDouble(dofData->m_6dofData.m_rbAFrame); + rbBFrame.deSerializeDouble(dofData->m_6dofData.m_rbBFrame); + dof = createGeneric6DofSpringConstraint(*rbA,*rbB,rbAFrame,rbBFrame,dofData->m_6dofData.m_useLinearReferenceFrameA!=0); + } else + { + printf("Error in btWorldImporter::createGeneric6DofSpringConstraint: requires rbA && rbB\n"); + } + + if (dof) + { + btVector3 angLowerLimit,angUpperLimit, linLowerLimit,linUpperlimit; + angLowerLimit.deSerializeDouble(dofData->m_6dofData.m_angularLowerLimit); + angUpperLimit.deSerializeDouble(dofData->m_6dofData.m_angularUpperLimit); + linLowerLimit.deSerializeDouble(dofData->m_6dofData.m_linearLowerLimit); + linUpperlimit.deSerializeDouble(dofData->m_6dofData.m_linearUpperLimit); + + angLowerLimit.setW(0.f); + dof->setAngularLowerLimit(angLowerLimit); + dof->setAngularUpperLimit(angUpperLimit); + dof->setLinearLowerLimit(linLowerLimit); + dof->setLinearUpperLimit(linUpperlimit); + + int i; + if (fileVersion>280) + { + for (i=0;i<6;i++) + { + dof->setStiffness(i,(btScalar)dofData->m_springStiffness[i]); + dof->setEquilibriumPoint(i,(btScalar)dofData->m_equilibriumPoint[i]); + dof->enableSpring(i,dofData->m_springEnabled[i]!=0); + dof->setDamping(i,(btScalar)dofData->m_springDamping[i]); + } + } + } + + constraint = dof; + break; + } + case D6_CONSTRAINT_TYPE: + { + btGeneric6DofConstraintDoubleData2* dofData = (btGeneric6DofConstraintDoubleData2*)constraintData; + btGeneric6DofConstraint* dof = 0; + + if (rbA&& rbB) + { + btTransform rbAFrame,rbBFrame; + rbAFrame.deSerializeDouble(dofData->m_rbAFrame); + rbBFrame.deSerializeDouble(dofData->m_rbBFrame); + dof = createGeneric6DofConstraint(*rbA,*rbB,rbAFrame,rbBFrame,dofData->m_useLinearReferenceFrameA!=0); + } else + { + if (rbB) + { + btTransform rbBFrame; + rbBFrame.deSerializeDouble(dofData->m_rbBFrame); + dof = createGeneric6DofConstraint(*rbB,rbBFrame,dofData->m_useLinearReferenceFrameA!=0); + } else + { + printf("Error in btWorldImporter::createGeneric6DofConstraint: missing rbB\n"); + } + } + + if (dof) + { + btVector3 angLowerLimit,angUpperLimit, linLowerLimit,linUpperlimit; + angLowerLimit.deSerializeDouble(dofData->m_angularLowerLimit); + angUpperLimit.deSerializeDouble(dofData->m_angularUpperLimit); + linLowerLimit.deSerializeDouble(dofData->m_linearLowerLimit); + linUpperlimit.deSerializeDouble(dofData->m_linearUpperLimit); + + dof->setAngularLowerLimit(angLowerLimit); + dof->setAngularUpperLimit(angUpperLimit); + dof->setLinearLowerLimit(linLowerLimit); + dof->setLinearUpperLimit(linUpperlimit); + } + + constraint = dof; + break; + } + case SLIDER_CONSTRAINT_TYPE: + { + btSliderConstraintDoubleData* sliderData = (btSliderConstraintDoubleData*)constraintData; + btSliderConstraint* slider = 0; + if (rbA&& rbB) + { + btTransform rbAFrame,rbBFrame; + rbAFrame.deSerializeDouble(sliderData->m_rbAFrame); + rbBFrame.deSerializeDouble(sliderData->m_rbBFrame); + slider = createSliderConstraint(*rbA,*rbB,rbAFrame,rbBFrame,sliderData->m_useLinearReferenceFrameA!=0); + } else + { + btTransform rbBFrame; + rbBFrame.deSerializeDouble(sliderData->m_rbBFrame); + slider = createSliderConstraint(*rbB,rbBFrame,sliderData->m_useLinearReferenceFrameA!=0); + } + slider->setLowerLinLimit((btScalar)sliderData->m_linearLowerLimit); + slider->setUpperLinLimit((btScalar)sliderData->m_linearUpperLimit); + slider->setLowerAngLimit((btScalar)sliderData->m_angularLowerLimit); + slider->setUpperAngLimit((btScalar)sliderData->m_angularUpperLimit); + slider->setUseFrameOffset(sliderData->m_useOffsetForConstraintFrame!=0); + constraint = slider; + break; + } + case GEAR_CONSTRAINT_TYPE: + { + btGearConstraintDoubleData* gearData = (btGearConstraintDoubleData*) constraintData; + btGearConstraint* gear = 0; + if (rbA&&rbB) + { + btVector3 axisInA,axisInB; + axisInA.deSerializeDouble(gearData->m_axisInA); + axisInB.deSerializeDouble(gearData->m_axisInB); + gear = createGearConstraint(*rbA, *rbB, axisInA,axisInB, gearData->m_ratio); + } else + { + btAssert(0); + //perhaps a gear against a 'fixed' body, while the 'fixed' body is not serialized? + //btGearConstraint(btRigidBody& rbA, btRigidBody& rbB, const btVector3& axisInA,const btVector3& axisInB, btScalar ratio=1.f); + } + constraint = gear; + break; + } + default: + { + printf("unknown constraint type\n"); + } + }; + + if (constraint) + { + constraint->setDbgDrawSize((btScalar)constraintData->m_dbgDrawSize); + ///those fields didn't exist and set to zero for pre-280 versions, so do a check here + if (fileVersion>=280) + { + constraint->setBreakingImpulseThreshold((btScalar)constraintData->m_breakingImpulseThreshold); + constraint->setEnabled(constraintData->m_isEnabled!=0); + constraint->setOverrideNumSolverIterations(constraintData->m_overrideNumSolverIterations); + } + + if (constraintData->m_name) + { + char* newname = duplicateName(constraintData->m_name); + m_nameConstraintMap.insert(newname,constraint); + m_objectNameMap.insert(constraint,newname); + } + if(m_dynamicsWorld) + m_dynamicsWorld->addConstraint(constraint,constraintData->m_disableCollisionsBetweenLinkedBodies!=0); + } + + +} + + + + + + + + + + +btTriangleIndexVertexArray* btWorldImporter::createMeshInterface(btStridingMeshInterfaceData& meshData) +{ + btTriangleIndexVertexArray* meshInterface = createTriangleMeshContainer(); + + for (int i=0;iaddIndexedMesh(meshPart,meshPart.m_indexType); + } + } + + return meshInterface; +} + + +btStridingMeshInterfaceData* btWorldImporter::createStridingMeshInterfaceData(btStridingMeshInterfaceData* interfaceData) +{ + //create a new btStridingMeshInterfaceData that is an exact copy of shapedata and store it in the WorldImporter + btStridingMeshInterfaceData* newData = new btStridingMeshInterfaceData; + + newData->m_scaling = interfaceData->m_scaling; + newData->m_numMeshParts = interfaceData->m_numMeshParts; + newData->m_meshPartsPtr = new btMeshPartData[newData->m_numMeshParts]; + + for(int i = 0;i < newData->m_numMeshParts;i++) + { + btMeshPartData* curPart = &interfaceData->m_meshPartsPtr[i]; + btMeshPartData* curNewPart = &newData->m_meshPartsPtr[i]; + + curNewPart->m_numTriangles = curPart->m_numTriangles; + curNewPart->m_numVertices = curPart->m_numVertices; + + if(curPart->m_vertices3f) + { + curNewPart->m_vertices3f = new btVector3FloatData[curNewPart->m_numVertices]; + memcpy(curNewPart->m_vertices3f,curPart->m_vertices3f,sizeof(btVector3FloatData) * curNewPart->m_numVertices); + } + else + curNewPart->m_vertices3f = NULL; + + if(curPart->m_vertices3d) + { + curNewPart->m_vertices3d = new btVector3DoubleData[curNewPart->m_numVertices]; + memcpy(curNewPart->m_vertices3d,curPart->m_vertices3d,sizeof(btVector3DoubleData) * curNewPart->m_numVertices); + } + else + curNewPart->m_vertices3d = NULL; + + int numIndices = curNewPart->m_numTriangles * 3; + ///the m_3indices8 was not initialized in some Bullet versions, this can cause crashes at loading time + ///we catch it by only dealing with m_3indices8 if none of the other indices are initialized + bool uninitialized3indices8Workaround =false; + + if(curPart->m_indices32) + { + uninitialized3indices8Workaround=true; + curNewPart->m_indices32 = new btIntIndexData[numIndices]; + memcpy(curNewPart->m_indices32,curPart->m_indices32,sizeof(btIntIndexData) * numIndices); + } + else + curNewPart->m_indices32 = NULL; + + if(curPart->m_3indices16) + { + uninitialized3indices8Workaround=true; + curNewPart->m_3indices16 = new btShortIntIndexTripletData[curNewPart->m_numTriangles]; + memcpy(curNewPart->m_3indices16,curPart->m_3indices16,sizeof(btShortIntIndexTripletData) * curNewPart->m_numTriangles); + } + else + curNewPart->m_3indices16 = NULL; + + if(curPart->m_indices16) + { + uninitialized3indices8Workaround=true; + curNewPart->m_indices16 = new btShortIntIndexData[numIndices]; + memcpy(curNewPart->m_indices16,curPart->m_indices16,sizeof(btShortIntIndexData) * numIndices); + } + else + curNewPart->m_indices16 = NULL; + + if(!uninitialized3indices8Workaround && curPart->m_3indices8) + { + curNewPart->m_3indices8 = new btCharIndexTripletData[curNewPart->m_numTriangles]; + memcpy(curNewPart->m_3indices8,curPart->m_3indices8,sizeof(btCharIndexTripletData) * curNewPart->m_numTriangles); + } + else + curNewPart->m_3indices8 = NULL; + + } + + m_allocatedbtStridingMeshInterfaceDatas.push_back(newData); + + return(newData); +} + +#ifdef USE_INTERNAL_EDGE_UTILITY +extern ContactAddedCallback gContactAddedCallback; + +static bool btAdjustInternalEdgeContactsCallback(btManifoldPoint& cp, const btCollisionObject* colObj0,int partId0,int index0,const btCollisionObject* colObj1,int partId1,int index1) +{ + + btAdjustInternalEdgeContacts(cp,colObj1,colObj0, partId1,index1); + //btAdjustInternalEdgeContacts(cp,colObj1,colObj0, partId1,index1, BT_TRIANGLE_CONVEX_BACKFACE_MODE); + //btAdjustInternalEdgeContacts(cp,colObj1,colObj0, partId1,index1, BT_TRIANGLE_CONVEX_DOUBLE_SIDED+BT_TRIANGLE_CONCAVE_DOUBLE_SIDED); + return true; +} +#endif //USE_INTERNAL_EDGE_UTILITY + + + + +btCollisionObject* btWorldImporter::createCollisionObject(const btTransform& startTransform,btCollisionShape* shape, const char* bodyName) +{ + return createRigidBody(false,0,startTransform,shape,bodyName); +} + +void btWorldImporter::setDynamicsWorldInfo(const btVector3& gravity, const btContactSolverInfo& solverInfo) +{ + if (m_dynamicsWorld) + { + m_dynamicsWorld->setGravity(gravity); + m_dynamicsWorld->getSolverInfo() = solverInfo; + } + +} + +btRigidBody* btWorldImporter::createRigidBody(bool isDynamic, btScalar mass, const btTransform& startTransform,btCollisionShape* shape,const char* bodyName) +{ + btVector3 localInertia; + localInertia.setZero(); + + if (mass) + shape->calculateLocalInertia(mass,localInertia); + + btRigidBody* body = new btRigidBody(mass,0,shape,localInertia); + body->setWorldTransform(startTransform); + + if (m_dynamicsWorld) + m_dynamicsWorld->addRigidBody(body); + + if (bodyName) + { + char* newname = duplicateName(bodyName); + m_objectNameMap.insert(body,newname); + m_nameBodyMap.insert(newname,body); + } + m_allocatedRigidBodies.push_back(body); + return body; + +} + +btCollisionShape* btWorldImporter::createPlaneShape(const btVector3& planeNormal,btScalar planeConstant) +{ + btStaticPlaneShape* shape = new btStaticPlaneShape(planeNormal,planeConstant); + m_allocatedCollisionShapes.push_back(shape); + return shape; +} +btCollisionShape* btWorldImporter::createBoxShape(const btVector3& halfExtents) +{ + btBoxShape* shape = new btBoxShape(halfExtents); + m_allocatedCollisionShapes.push_back(shape); + return shape; +} +btCollisionShape* btWorldImporter::createSphereShape(btScalar radius) +{ + btSphereShape* shape = new btSphereShape(radius); + m_allocatedCollisionShapes.push_back(shape); + return shape; +} + + +btCollisionShape* btWorldImporter::createCapsuleShapeX(btScalar radius, btScalar height) +{ + btCapsuleShapeX* shape = new btCapsuleShapeX(radius,height); + m_allocatedCollisionShapes.push_back(shape); + return shape; +} + +btCollisionShape* btWorldImporter::createCapsuleShapeY(btScalar radius, btScalar height) +{ + btCapsuleShape* shape = new btCapsuleShape(radius,height); + m_allocatedCollisionShapes.push_back(shape); + return shape; +} + +btCollisionShape* btWorldImporter::createCapsuleShapeZ(btScalar radius, btScalar height) +{ + btCapsuleShapeZ* shape = new btCapsuleShapeZ(radius,height); + m_allocatedCollisionShapes.push_back(shape); + return shape; +} + +btCollisionShape* btWorldImporter::createCylinderShapeX(btScalar radius,btScalar height) +{ + btCylinderShapeX* shape = new btCylinderShapeX(btVector3(height,radius,radius)); + m_allocatedCollisionShapes.push_back(shape); + return shape; +} + +btCollisionShape* btWorldImporter::createCylinderShapeY(btScalar radius,btScalar height) +{ + btCylinderShape* shape = new btCylinderShape(btVector3(radius,height,radius)); + m_allocatedCollisionShapes.push_back(shape); + return shape; +} + +btCollisionShape* btWorldImporter::createCylinderShapeZ(btScalar radius,btScalar height) +{ + btCylinderShapeZ* shape = new btCylinderShapeZ(btVector3(radius,radius,height)); + m_allocatedCollisionShapes.push_back(shape); + return shape; +} + +btCollisionShape* btWorldImporter::createConeShapeX(btScalar radius,btScalar height) +{ + btConeShapeX* shape = new btConeShapeX(radius,height); + m_allocatedCollisionShapes.push_back(shape); + return shape; +} + +btCollisionShape* btWorldImporter::createConeShapeY(btScalar radius,btScalar height) +{ + btConeShape* shape = new btConeShape(radius,height); + m_allocatedCollisionShapes.push_back(shape); + return shape; +} + +btCollisionShape* btWorldImporter::createConeShapeZ(btScalar radius,btScalar height) +{ + btConeShapeZ* shape = new btConeShapeZ(radius,height); + m_allocatedCollisionShapes.push_back(shape); + return shape; +} + +btTriangleIndexVertexArray* btWorldImporter::createTriangleMeshContainer() +{ + btTriangleIndexVertexArray* in = new btTriangleIndexVertexArray(); + m_allocatedTriangleIndexArrays.push_back(in); + return in; +} + +btOptimizedBvh* btWorldImporter::createOptimizedBvh() +{ + btOptimizedBvh* bvh = new btOptimizedBvh(); + m_allocatedBvhs.push_back(bvh); + return bvh; +} + + +btTriangleInfoMap* btWorldImporter::createTriangleInfoMap() +{ + btTriangleInfoMap* tim = new btTriangleInfoMap(); + m_allocatedTriangleInfoMaps.push_back(tim); + return tim; +} + +btBvhTriangleMeshShape* btWorldImporter::createBvhTriangleMeshShape(btStridingMeshInterface* trimesh, btOptimizedBvh* bvh) +{ + if (bvh) + { + btBvhTriangleMeshShape* bvhTriMesh = new btBvhTriangleMeshShape(trimesh,bvh->isQuantized(), false); + bvhTriMesh->setOptimizedBvh(bvh); + m_allocatedCollisionShapes.push_back(bvhTriMesh); + return bvhTriMesh; + } + + btBvhTriangleMeshShape* ts = new btBvhTriangleMeshShape(trimesh,true); + m_allocatedCollisionShapes.push_back(ts); + return ts; + +} +btCollisionShape* btWorldImporter::createConvexTriangleMeshShape(btStridingMeshInterface* trimesh) +{ + return 0; +} +btGImpactMeshShape* btWorldImporter::createGimpactShape(btStridingMeshInterface* trimesh) +{ + btGImpactMeshShape* shape = new btGImpactMeshShape(trimesh); + m_allocatedCollisionShapes.push_back(shape); + return shape; + +} +btConvexHullShape* btWorldImporter::createConvexHullShape() +{ + btConvexHullShape* shape = new btConvexHullShape(); + m_allocatedCollisionShapes.push_back(shape); + return shape; +} + +btCompoundShape* btWorldImporter::createCompoundShape() +{ + btCompoundShape* shape = new btCompoundShape(); + m_allocatedCollisionShapes.push_back(shape); + return shape; +} + + +btScaledBvhTriangleMeshShape* btWorldImporter::createScaledTrangleMeshShape(btBvhTriangleMeshShape* meshShape,const btVector3& localScaling) +{ + btScaledBvhTriangleMeshShape* shape = new btScaledBvhTriangleMeshShape(meshShape,localScaling); + m_allocatedCollisionShapes.push_back(shape); + return shape; +} + +btMultiSphereShape* btWorldImporter::createMultiSphereShape(const btVector3* positions,const btScalar* radi,int numSpheres) +{ + btMultiSphereShape* shape = new btMultiSphereShape(positions, radi, numSpheres); + m_allocatedCollisionShapes.push_back(shape); + return shape; +} + +btRigidBody& btWorldImporter::getFixedBody() +{ + static btRigidBody s_fixed(0, 0,0); + s_fixed.setMassProps(btScalar(0.),btVector3(btScalar(0.),btScalar(0.),btScalar(0.))); + return s_fixed; +} + +btPoint2PointConstraint* btWorldImporter::createPoint2PointConstraint(btRigidBody& rbA,btRigidBody& rbB, const btVector3& pivotInA,const btVector3& pivotInB) +{ + btPoint2PointConstraint* p2p = new btPoint2PointConstraint(rbA,rbB,pivotInA,pivotInB); + m_allocatedConstraints.push_back(p2p); + return p2p; +} + +btPoint2PointConstraint* btWorldImporter::createPoint2PointConstraint(btRigidBody& rbA,const btVector3& pivotInA) +{ + btPoint2PointConstraint* p2p = new btPoint2PointConstraint(rbA,pivotInA); + m_allocatedConstraints.push_back(p2p); + return p2p; +} + + +btHingeConstraint* btWorldImporter::createHingeConstraint(btRigidBody& rbA,btRigidBody& rbB, const btTransform& rbAFrame, const btTransform& rbBFrame, bool useReferenceFrameA) +{ + btHingeConstraint* hinge = new btHingeConstraint(rbA,rbB,rbAFrame,rbBFrame,useReferenceFrameA); + m_allocatedConstraints.push_back(hinge); + return hinge; +} + +btHingeConstraint* btWorldImporter::createHingeConstraint(btRigidBody& rbA,const btTransform& rbAFrame, bool useReferenceFrameA) +{ + btHingeConstraint* hinge = new btHingeConstraint(rbA,rbAFrame,useReferenceFrameA); + m_allocatedConstraints.push_back(hinge); + return hinge; +} + +btConeTwistConstraint* btWorldImporter::createConeTwistConstraint(btRigidBody& rbA,btRigidBody& rbB,const btTransform& rbAFrame, const btTransform& rbBFrame) +{ + btConeTwistConstraint* cone = new btConeTwistConstraint(rbA,rbB,rbAFrame,rbBFrame); + m_allocatedConstraints.push_back(cone); + return cone; +} + +btConeTwistConstraint* btWorldImporter::createConeTwistConstraint(btRigidBody& rbA,const btTransform& rbAFrame) +{ + btConeTwistConstraint* cone = new btConeTwistConstraint(rbA,rbAFrame); + m_allocatedConstraints.push_back(cone); + return cone; +} + + +btGeneric6DofConstraint* btWorldImporter::createGeneric6DofConstraint(btRigidBody& rbA, btRigidBody& rbB, const btTransform& frameInA, const btTransform& frameInB ,bool useLinearReferenceFrameA) +{ + btGeneric6DofConstraint* dof = new btGeneric6DofConstraint(rbA,rbB,frameInA,frameInB,useLinearReferenceFrameA); + m_allocatedConstraints.push_back(dof); + return dof; +} + +btGeneric6DofConstraint* btWorldImporter::createGeneric6DofConstraint(btRigidBody& rbB, const btTransform& frameInB, bool useLinearReferenceFrameB) +{ + btGeneric6DofConstraint* dof = new btGeneric6DofConstraint(rbB,frameInB,useLinearReferenceFrameB); + m_allocatedConstraints.push_back(dof); + return dof; +} + +btGeneric6DofSpringConstraint* btWorldImporter::createGeneric6DofSpringConstraint(btRigidBody& rbA, btRigidBody& rbB, const btTransform& frameInA, const btTransform& frameInB ,bool useLinearReferenceFrameA) +{ + btGeneric6DofSpringConstraint* dof = new btGeneric6DofSpringConstraint(rbA,rbB,frameInA,frameInB,useLinearReferenceFrameA); + m_allocatedConstraints.push_back(dof); + return dof; +} + + +btSliderConstraint* btWorldImporter::createSliderConstraint(btRigidBody& rbA, btRigidBody& rbB, const btTransform& frameInA, const btTransform& frameInB ,bool useLinearReferenceFrameA) +{ + btSliderConstraint* slider = new btSliderConstraint(rbA,rbB,frameInA,frameInB,useLinearReferenceFrameA); + m_allocatedConstraints.push_back(slider); + return slider; +} + +btSliderConstraint* btWorldImporter::createSliderConstraint(btRigidBody& rbB, const btTransform& frameInB, bool useLinearReferenceFrameA) +{ + btSliderConstraint* slider = new btSliderConstraint(rbB,frameInB,useLinearReferenceFrameA); + m_allocatedConstraints.push_back(slider); + return slider; +} + +btGearConstraint* btWorldImporter::createGearConstraint(btRigidBody& rbA, btRigidBody& rbB, const btVector3& axisInA,const btVector3& axisInB, btScalar ratio) +{ + btGearConstraint* gear = new btGearConstraint(rbA,rbB,axisInA,axisInB,ratio); + m_allocatedConstraints.push_back(gear); + return gear; +} + + // query for data +int btWorldImporter::getNumCollisionShapes() const +{ + return m_allocatedCollisionShapes.size(); +} + +btCollisionShape* btWorldImporter::getCollisionShapeByIndex(int index) +{ + return m_allocatedCollisionShapes[index]; +} + +btCollisionShape* btWorldImporter::getCollisionShapeByName(const char* name) +{ + btCollisionShape** shapePtr = m_nameShapeMap.find(name); + if (shapePtr&& *shapePtr) + { + return *shapePtr; + } + return 0; +} + +btRigidBody* btWorldImporter::getRigidBodyByName(const char* name) +{ + btRigidBody** bodyPtr = m_nameBodyMap.find(name); + if (bodyPtr && *bodyPtr) + { + return *bodyPtr; + } + return 0; +} + +btTypedConstraint* btWorldImporter::getConstraintByName(const char* name) +{ + btTypedConstraint** constraintPtr = m_nameConstraintMap.find(name); + if (constraintPtr && *constraintPtr) + { + return *constraintPtr; + } + return 0; +} + +const char* btWorldImporter::getNameForPointer(const void* ptr) const +{ + const char*const * namePtr = m_objectNameMap.find(ptr); + if (namePtr && *namePtr) + return *namePtr; + return 0; +} + + +int btWorldImporter::getNumRigidBodies() const +{ + return m_allocatedRigidBodies.size(); +} + +btCollisionObject* btWorldImporter::getRigidBodyByIndex(int index) const +{ + return m_allocatedRigidBodies[index]; +} +int btWorldImporter::getNumConstraints() const +{ + return m_allocatedConstraints.size(); +} + +btTypedConstraint* btWorldImporter::getConstraintByIndex(int index) const +{ + return m_allocatedConstraints[index]; +} + +int btWorldImporter::getNumBvhs() const +{ + return m_allocatedBvhs.size(); +} + btOptimizedBvh* btWorldImporter::getBvhByIndex(int index) const +{ + return m_allocatedBvhs[index]; +} + +int btWorldImporter::getNumTriangleInfoMaps() const +{ + return m_allocatedTriangleInfoMaps.size(); +} + +btTriangleInfoMap* btWorldImporter::getTriangleInfoMapByIndex(int index) const +{ + return m_allocatedTriangleInfoMaps[index]; +} + + +void btWorldImporter::convertRigidBodyFloat( btRigidBodyFloatData* colObjData) +{ + btScalar mass = btScalar(colObjData->m_inverseMass? 1.f/colObjData->m_inverseMass : 0.f); + btVector3 localInertia; + localInertia.setZero(); + btCollisionShape** shapePtr = m_shapeMap.find(colObjData->m_collisionObjectData.m_collisionShape); + if (shapePtr && *shapePtr) + { + btTransform startTransform; + colObjData->m_collisionObjectData.m_worldTransform.m_origin.m_floats[3] = 0.f; + startTransform.deSerializeFloat(colObjData->m_collisionObjectData.m_worldTransform); + + // startTransform.setBasis(btMatrix3x3::getIdentity()); + btCollisionShape* shape = (btCollisionShape*)*shapePtr; + if (shape->isNonMoving()) + { + mass = 0.f; + } + if (mass) + { + shape->calculateLocalInertia(mass,localInertia); + } + bool isDynamic = mass!=0.f; + btRigidBody* body = createRigidBody(isDynamic,mass,startTransform,shape,colObjData->m_collisionObjectData.m_name); + body->setFriction(colObjData->m_collisionObjectData.m_friction); + body->setRestitution(colObjData->m_collisionObjectData.m_restitution); + btVector3 linearFactor,angularFactor; + linearFactor.deSerializeFloat(colObjData->m_linearFactor); + angularFactor.deSerializeFloat(colObjData->m_angularFactor); + body->setLinearFactor(linearFactor); + body->setAngularFactor(angularFactor); + +#ifdef USE_INTERNAL_EDGE_UTILITY + if (shape->getShapeType() == TRIANGLE_MESH_SHAPE_PROXYTYPE) + { + btBvhTriangleMeshShape* trimesh = (btBvhTriangleMeshShape*)shape; + if (trimesh->getTriangleInfoMap()) + { + body->setCollisionFlags(body->getCollisionFlags() | btCollisionObject::CF_CUSTOM_MATERIAL_CALLBACK); + } + } +#endif //USE_INTERNAL_EDGE_UTILITY + m_bodyMap.insert(colObjData,body); + } else + { + printf("error: no shape found\n"); + } +} + +void btWorldImporter::convertRigidBodyDouble( btRigidBodyDoubleData* colObjData) +{ + btScalar mass = btScalar(colObjData->m_inverseMass? 1.f/colObjData->m_inverseMass : 0.f); + btVector3 localInertia; + localInertia.setZero(); + btCollisionShape** shapePtr = m_shapeMap.find(colObjData->m_collisionObjectData.m_collisionShape); + if (shapePtr && *shapePtr) + { + btTransform startTransform; + colObjData->m_collisionObjectData.m_worldTransform.m_origin.m_floats[3] = 0.f; + startTransform.deSerializeDouble(colObjData->m_collisionObjectData.m_worldTransform); + + // startTransform.setBasis(btMatrix3x3::getIdentity()); + btCollisionShape* shape = (btCollisionShape*)*shapePtr; + if (shape->isNonMoving()) + { + mass = 0.f; + } + if (mass) + { + shape->calculateLocalInertia(mass,localInertia); + } + bool isDynamic = mass!=0.f; + btRigidBody* body = createRigidBody(isDynamic,mass,startTransform,shape,colObjData->m_collisionObjectData.m_name); + body->setFriction(btScalar(colObjData->m_collisionObjectData.m_friction)); + body->setRestitution(btScalar(colObjData->m_collisionObjectData.m_restitution)); + btVector3 linearFactor,angularFactor; + linearFactor.deSerializeDouble(colObjData->m_linearFactor); + angularFactor.deSerializeDouble(colObjData->m_angularFactor); + body->setLinearFactor(linearFactor); + body->setAngularFactor(angularFactor); + + +#ifdef USE_INTERNAL_EDGE_UTILITY + if (shape->getShapeType() == TRIANGLE_MESH_SHAPE_PROXYTYPE) + { + btBvhTriangleMeshShape* trimesh = (btBvhTriangleMeshShape*)shape; + if (trimesh->getTriangleInfoMap()) + { + body->setCollisionFlags(body->getCollisionFlags() | btCollisionObject::CF_CUSTOM_MATERIAL_CALLBACK); + } + } +#endif //USE_INTERNAL_EDGE_UTILITY + m_bodyMap.insert(colObjData,body); + } else + { + printf("error: no shape found\n"); + } +} diff --git a/Code/Physics/Bullet Source/BulletWorldImporter/btWorldImporter.h b/Code/Physics/Bullet Source/BulletWorldImporter/btWorldImporter.h new file mode 100644 index 00000000..bcd6405d --- /dev/null +++ b/Code/Physics/Bullet Source/BulletWorldImporter/btWorldImporter.h @@ -0,0 +1,212 @@ +/* +Bullet Continuous Collision Detection and Physics Library +Copyright (c) 2003-2012 Erwin Coumans http://bulletphysics.org + +This software is provided 'as-is', without any express or implied warranty. +In no event will the authors be held liable for any damages arising from the use of this software. +Permission is granted to anyone to use this software for any purpose, +including commercial applications, and to alter it and redistribute it freely, +subject to the following restrictions: + +1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. +2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. +3. This notice may not be removed or altered from any source distribution. +*/ + + +#ifndef BT_WORLD_IMPORTER_H +#define BT_WORLD_IMPORTER_H + +#include "LinearMath/btTransform.h" +#include "LinearMath/btVector3.h" +#include "LinearMath/btAlignedObjectArray.h" +#include "LinearMath/btHashMap.h" + +class btCollisionShape; +class btCollisionObject; +class btRigidBody; +class btTypedConstraint; +class btDynamicsWorld; +struct ConstraintInput; +class btRigidBodyColladaInfo; +struct btCollisionShapeData; +class btTriangleIndexVertexArray; +class btStridingMeshInterface; +struct btStridingMeshInterfaceData; +class btGImpactMeshShape; +class btOptimizedBvh; +struct btTriangleInfoMap; +class btBvhTriangleMeshShape; +class btPoint2PointConstraint; +class btHingeConstraint; +class btConeTwistConstraint; +class btGeneric6DofConstraint; +class btGeneric6DofSpringConstraint; +class btSliderConstraint; +class btGearConstraint; +struct btContactSolverInfo; +struct btTypedConstraintData; +struct btTypedConstraintFloatData; +struct btTypedConstraintDoubleData; + +struct btRigidBodyDoubleData; +struct btRigidBodyFloatData; + +#ifdef BT_USE_DOUBLE_PRECISION +#define btRigidBodyData btRigidBodyDoubleData +#else +#define btRigidBodyData btRigidBodyFloatData +#endif//BT_USE_DOUBLE_PRECISION + + +class btWorldImporter +{ +protected: + btDynamicsWorld* m_dynamicsWorld; + + int m_verboseMode; + + btAlignedObjectArray m_allocatedCollisionShapes; + btAlignedObjectArray m_allocatedRigidBodies; + btAlignedObjectArray m_allocatedConstraints; + btAlignedObjectArray m_allocatedBvhs; + btAlignedObjectArray m_allocatedTriangleInfoMaps; + btAlignedObjectArray m_allocatedTriangleIndexArrays; + btAlignedObjectArray m_allocatedbtStridingMeshInterfaceDatas; + + btAlignedObjectArray m_allocatedNames; + + btAlignedObjectArray m_indexArrays; + btAlignedObjectArray m_shortIndexArrays; + btAlignedObjectArray m_charIndexArrays; + + btAlignedObjectArray m_floatVertexArrays; + btAlignedObjectArray m_doubleVertexArrays; + + + btHashMap m_bvhMap; + btHashMap m_timMap; + + btHashMap m_nameShapeMap; + btHashMap m_nameBodyMap; + btHashMap m_nameConstraintMap; + btHashMap m_objectNameMap; + + btHashMap m_shapeMap; + btHashMap m_bodyMap; + + + //methods + + static btRigidBody& getFixedBody(); + + char* duplicateName(const char* name); + + btCollisionShape* convertCollisionShape( btCollisionShapeData* shapeData ); + + void convertConstraintBackwardsCompatible281(btTypedConstraintData* constraintData, btRigidBody* rbA, btRigidBody* rbB, int fileVersion); + void convertConstraintFloat(btTypedConstraintFloatData* constraintData, btRigidBody* rbA, btRigidBody* rbB, int fileVersion); + void convertConstraintDouble(btTypedConstraintDoubleData* constraintData, btRigidBody* rbA, btRigidBody* rbB, int fileVersion); + void convertRigidBodyFloat(btRigidBodyFloatData* colObjData); + void convertRigidBodyDouble( btRigidBodyDoubleData* colObjData); + +public: + + btWorldImporter(btDynamicsWorld* world); + + virtual ~btWorldImporter(); + + ///delete all memory collision shapes, rigid bodies, constraints etc. allocated during the load. + ///make sure you don't use the dynamics world containing objects after you call this method + virtual void deleteAllData(); + + void setVerboseMode(int verboseMode) + { + m_verboseMode = verboseMode; + } + + int getVerboseMode() const + { + return m_verboseMode; + } + + // query for data + int getNumCollisionShapes() const; + btCollisionShape* getCollisionShapeByIndex(int index); + int getNumRigidBodies() const; + btCollisionObject* getRigidBodyByIndex(int index) const; + int getNumConstraints() const; + btTypedConstraint* getConstraintByIndex(int index) const; + int getNumBvhs() const; + btOptimizedBvh* getBvhByIndex(int index) const; + int getNumTriangleInfoMaps() const; + btTriangleInfoMap* getTriangleInfoMapByIndex(int index) const; + + // queris involving named objects + btCollisionShape* getCollisionShapeByName(const char* name); + btRigidBody* getRigidBodyByName(const char* name); + btTypedConstraint* getConstraintByName(const char* name); + const char* getNameForPointer(const void* ptr) const; + + ///those virtuals are called by load and can be overridden by the user + + virtual void setDynamicsWorldInfo(const btVector3& gravity, const btContactSolverInfo& solverInfo); + + //bodies + virtual btRigidBody* createRigidBody(bool isDynamic, btScalar mass, const btTransform& startTransform, btCollisionShape* shape,const char* bodyName); + virtual btCollisionObject* createCollisionObject( const btTransform& startTransform, btCollisionShape* shape,const char* bodyName); + + ///shapes + + virtual btCollisionShape* createPlaneShape(const btVector3& planeNormal,btScalar planeConstant); + virtual btCollisionShape* createBoxShape(const btVector3& halfExtents); + virtual btCollisionShape* createSphereShape(btScalar radius); + virtual btCollisionShape* createCapsuleShapeX(btScalar radius, btScalar height); + virtual btCollisionShape* createCapsuleShapeY(btScalar radius, btScalar height); + virtual btCollisionShape* createCapsuleShapeZ(btScalar radius, btScalar height); + + virtual btCollisionShape* createCylinderShapeX(btScalar radius,btScalar height); + virtual btCollisionShape* createCylinderShapeY(btScalar radius,btScalar height); + virtual btCollisionShape* createCylinderShapeZ(btScalar radius,btScalar height); + virtual btCollisionShape* createConeShapeX(btScalar radius,btScalar height); + virtual btCollisionShape* createConeShapeY(btScalar radius,btScalar height); + virtual btCollisionShape* createConeShapeZ(btScalar radius,btScalar height); + virtual class btTriangleIndexVertexArray* createTriangleMeshContainer(); + virtual btBvhTriangleMeshShape* createBvhTriangleMeshShape(btStridingMeshInterface* trimesh, btOptimizedBvh* bvh); + virtual btCollisionShape* createConvexTriangleMeshShape(btStridingMeshInterface* trimesh); + virtual btGImpactMeshShape* createGimpactShape(btStridingMeshInterface* trimesh); + virtual btStridingMeshInterfaceData* createStridingMeshInterfaceData(btStridingMeshInterfaceData* interfaceData); + + virtual class btConvexHullShape* createConvexHullShape(); + virtual class btCompoundShape* createCompoundShape(); + virtual class btScaledBvhTriangleMeshShape* createScaledTrangleMeshShape(btBvhTriangleMeshShape* meshShape,const btVector3& localScalingbtBvhTriangleMeshShape); + + virtual class btMultiSphereShape* createMultiSphereShape(const btVector3* positions,const btScalar* radi,int numSpheres); + + virtual btTriangleIndexVertexArray* createMeshInterface(btStridingMeshInterfaceData& meshData); + + ///acceleration and connectivity structures + virtual btOptimizedBvh* createOptimizedBvh(); + virtual btTriangleInfoMap* createTriangleInfoMap(); + + ///constraints + virtual btPoint2PointConstraint* createPoint2PointConstraint(btRigidBody& rbA,btRigidBody& rbB, const btVector3& pivotInA,const btVector3& pivotInB); + virtual btPoint2PointConstraint* createPoint2PointConstraint(btRigidBody& rbA,const btVector3& pivotInA); + virtual btHingeConstraint* createHingeConstraint(btRigidBody& rbA,btRigidBody& rbB, const btTransform& rbAFrame, const btTransform& rbBFrame, bool useReferenceFrameA=false); + virtual btHingeConstraint* createHingeConstraint(btRigidBody& rbA,const btTransform& rbAFrame, bool useReferenceFrameA=false); + virtual btConeTwistConstraint* createConeTwistConstraint(btRigidBody& rbA,btRigidBody& rbB,const btTransform& rbAFrame, const btTransform& rbBFrame); + virtual btConeTwistConstraint* createConeTwistConstraint(btRigidBody& rbA,const btTransform& rbAFrame); + virtual btGeneric6DofConstraint* createGeneric6DofConstraint(btRigidBody& rbA, btRigidBody& rbB, const btTransform& frameInA, const btTransform& frameInB ,bool useLinearReferenceFrameA); + virtual btGeneric6DofConstraint* createGeneric6DofConstraint(btRigidBody& rbB, const btTransform& frameInB, bool useLinearReferenceFrameB); + virtual btGeneric6DofSpringConstraint* createGeneric6DofSpringConstraint(btRigidBody& rbA, btRigidBody& rbB, const btTransform& frameInA, const btTransform& frameInB ,bool useLinearReferenceFrameA); + virtual btSliderConstraint* createSliderConstraint(btRigidBody& rbA, btRigidBody& rbB, const btTransform& frameInA, const btTransform& frameInB ,bool useLinearReferenceFrameA); + virtual btSliderConstraint* createSliderConstraint(btRigidBody& rbB, const btTransform& frameInB, bool useLinearReferenceFrameA); + virtual btGearConstraint* createGearConstraint(btRigidBody& rbA, btRigidBody& rbB, const btVector3& axisInA,const btVector3& axisInB, btScalar ratio); + + + + +}; + + +#endif //BT_WORLD_IMPORTER_H \ No newline at end of file diff --git a/Code/Physics/Bullet Source/BulletWorldImporter/premake4.lua b/Code/Physics/Bullet Source/BulletWorldImporter/premake4.lua new file mode 100644 index 00000000..d847c7a9 --- /dev/null +++ b/Code/Physics/Bullet Source/BulletWorldImporter/premake4.lua @@ -0,0 +1,13 @@ + project "BulletWorldImporter" + + kind "StaticLib" + targetdir "../../lib" + includedirs { + "../BulletFileLoader", + "../../../src" + } + + files { + "**.cpp", + "**.h" + } \ No newline at end of file diff --git a/Code/Physics/GamePhysics/GamePhysics.vcxproj b/Code/Physics/GamePhysics/GamePhysics.vcxproj index a368bedf..2c48611a 100644 --- a/Code/Physics/GamePhysics/GamePhysics.vcxproj +++ b/Code/Physics/GamePhysics/GamePhysics.vcxproj @@ -97,7 +97,7 @@ true - $(SolutionDir)Physics/lib/debug/BulletCollision_Debug.lib;$(SolutionDir)Physics/lib/debug/BulletDynamics_Debug.lib;$(SolutionDir)Physics/lib/debug/LinearMath_Debug.lib;%(AdditionalDependencies) + $(SolutionDir)Physics/lib/debug/BulletCollision_Debug.lib;$(SolutionDir)Physics/lib/debug/BulletDynamics_Debug.lib;$(SolutionDir)Physics/lib/debug/LinearMath_Debug.lib;$(SolutionDir)Physics/lib/debug/BulletFileLoader_Debug.lib;$(SolutionDir)Physics/lib/debug/BulletWorldImporter_Debug.lib;%(AdditionalDependencies) @@ -112,7 +112,7 @@ true - $(SolutionDir)Physics/lib/debug/BulletCollision_Debugx64.lib;$(SolutionDir)Physics/lib/debug/BulletDynamics_Debugx64.lib;$(SolutionDir)Physics/lib/debug/LinearMath_Debugx64.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) + $(SolutionDir)Physics/lib/debug/BulletCollision_Debugx64.lib;$(SolutionDir)Physics/lib/debug/BulletDynamics_Debugx64.lib;$(SolutionDir)Physics/lib/debug/LinearMath_Debugx64.lib;$(SolutionDir)Physics/lib/debug/BulletWorldImporter_Debugx64.lib;$(SolutionDir)Physics/lib/debug/BulletFileLoader_Debugx64.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) @@ -131,7 +131,7 @@ true - $(SolutionDir)Physics/lib/release/BulletCollision.lib;$(SolutionDir)Physics/lib/release/BulletDynamics.lib;$(SolutionDir)Physics/lib/release/LinearMath.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) + $(SolutionDir)Physics/lib/release/BulletCollision.lib;$(SolutionDir)Physics/lib/release/BulletDynamics.lib;$(SolutionDir)Physics/lib/release/LinearMath.lib;$(SolutionDir)Physics/lib/release/BulletFileLoader.lib;$(SolutionDir)Physics/lib/release/BulletWorldImporter.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) @@ -150,7 +150,7 @@ true - $(SolutionDir)Physics/lib/release/BulletCollisionx64.lib;$(SolutionDir)Physics/lib/release/BulletDynamicsx64.lib;$(SolutionDir)Physics/lib/release/LinearMathx64.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) + $(SolutionDir)Physics/lib/release/BulletCollisionx64.lib;$(SolutionDir)Physics/lib/release/BulletDynamicsx64.lib;$(SolutionDir)Physics/lib/release/LinearMathx64.lib;$(SolutionDir)Physics/lib/release/BulletWorldImporterx64.lib;$(SolutionDir)Physics/lib/release/BulletFileLoaderx64.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) diff --git a/Code/Physics/GamePhysics/Implementation/PhysicsAPI_Impl.cpp b/Code/Physics/GamePhysics/Implementation/PhysicsAPI_Impl.cpp index 9cd87d1d..f2f97280 100644 --- a/Code/Physics/GamePhysics/Implementation/PhysicsAPI_Impl.cpp +++ b/Code/Physics/GamePhysics/Implementation/PhysicsAPI_Impl.cpp @@ -1,6 +1,9 @@ #include "PhysicsAPI_Impl.h" #include "OysterPhysics3D.h" #include "SimpleRigidBody.h" +#include + +#include using namespace ::Oyster; using namespace ::Oyster::Physics; @@ -92,8 +95,8 @@ ICustomBody* API_Impl::AddCollisionSphere(float radius, ::Oyster::Math::Float4 r state.centerPos = position; state.reach = Float3(radius, radius, radius); - state.dynamicFrictionCoeff = 0.5f; - state.staticFrictionCoeff = 0.5f; + state.dynamicFrictionCoeff = dynamicFriction; + state.staticFrictionCoeff = staticFriction; state.quaternion = Quaternion(Float3(rotation.xyz), rotation.w); state.mass = mass; @@ -131,8 +134,8 @@ ICustomBody* API_Impl::AddCollisionBox(Float3 halfSize, ::Oyster::Math::Float4 r state.centerPos = position; state.reach = halfSize; - state.dynamicFrictionCoeff = 0.5f; - state.staticFrictionCoeff = 0.5f; + state.dynamicFrictionCoeff = dynamicFriction; + state.staticFrictionCoeff = staticFriction; state.quaternion = Quaternion(Float3(rotation.xyz), rotation.w); state.mass = mass; @@ -170,8 +173,8 @@ ICustomBody* API_Impl::AddCollisionCylinder(::Oyster::Math::Float3 halfSize, ::O state.centerPos = position; state.reach = halfSize; - state.dynamicFrictionCoeff = 0.5f; - state.staticFrictionCoeff = 0.5f; + state.dynamicFrictionCoeff = dynamicFriction; + state.staticFrictionCoeff = staticFriction; state.quaternion = Quaternion(Float3(rotation.xyz), rotation.w); state.mass = mass; @@ -211,8 +214,55 @@ ICustomBody* API_Impl::AddCharacter(::Oyster::Math::Float height, ::Oyster::Math state.centerPos = position; state.reach = Float3(radius, height, radius); - state.dynamicFrictionCoeff = 0.5f; - state.staticFrictionCoeff = 0.5f; + state.dynamicFrictionCoeff = dynamicFriction; + state.staticFrictionCoeff = staticFriction; + state.quaternion = Quaternion(Float3(rotation.xyz), rotation.w); + state.mass = mass; + + body->SetState(state); + + return body; +} + +ICustomBody* API_Impl::AddTriangleMesh(const std::wstring fileName, ::Oyster::Math::Float4 rotation, ::Oyster::Math::Float3 position, float mass, float restitution, float staticFriction, float dynamicFriction) +{ + SimpleRigidBody* body = new SimpleRigidBody; + SimpleRigidBody::State state; + + btBulletWorldImporter bulletFile; + + typedef std::codecvt_utf8 convert_typeX; + std::wstring_convert converterX; + + std::string bulletPath = converterX.to_bytes(fileName); + + // Add collision shape + bulletFile.loadFile(bulletPath.c_str()); + btCollisionShape* collisionShape = bulletFile.getCollisionShapeByIndex(0); + body->SetCollisionShape(collisionShape); + + // Add motion state + btDefaultMotionState* motionState = new btDefaultMotionState(btTransform(btQuaternion(rotation.x, rotation.y, rotation.z, rotation.w),btVector3(position.x, position.y, position.z))); + body->SetMotionState(motionState); + + // Add rigid body + btVector3 fallInertia(0, 0, 0); + collisionShape->calculateLocalInertia(mass, fallInertia); + btRigidBody::btRigidBodyConstructionInfo rigidBodyCI(mass, motionState, collisionShape, fallInertia); + btRigidBody* rigidBody = new btRigidBody(rigidBodyCI); + rigidBody->setFriction(staticFriction); + rigidBody->setRestitution(restitution); + rigidBody->setUserPointer(body); + body->SetRigidBody(rigidBody); + + // Add rigid body to world + this->dynamicsWorld->addRigidBody(rigidBody); + this->customBodies.push_back(body); + + state.centerPos = position; + state.reach = Float3(0, 0, 0); + state.dynamicFrictionCoeff = dynamicFriction; + state.staticFrictionCoeff = staticFriction; state.quaternion = Quaternion(Float3(rotation.xyz), rotation.w); state.mass = mass; diff --git a/Code/Physics/GamePhysics/Implementation/PhysicsAPI_Impl.h b/Code/Physics/GamePhysics/Implementation/PhysicsAPI_Impl.h index 002cb039..4f30110b 100644 --- a/Code/Physics/GamePhysics/Implementation/PhysicsAPI_Impl.h +++ b/Code/Physics/GamePhysics/Implementation/PhysicsAPI_Impl.h @@ -66,6 +66,8 @@ namespace Oyster ICustomBody* AddCharacter(::Oyster::Math::Float height, ::Oyster::Math::Float radius, ::Oyster::Math::Float4 rotation, ::Oyster::Math::Float3 position, float mass, float restitution, float staticFriction, float dynamicFriction); + ICustomBody* AddTriangleMesh(const std::wstring fileName, ::Oyster::Math::Float4 rotation, ::Oyster::Math::Float3 position, float mass, float restitution, float staticFriction, float dynamicFriction); + void SetTimeStep(float timeStep); void UpdateWorld(); diff --git a/Code/Physics/GamePhysics/Implementation/SimpleRigidBody.cpp b/Code/Physics/GamePhysics/Implementation/SimpleRigidBody.cpp index 4cdb282d..ef003d7f 100644 --- a/Code/Physics/GamePhysics/Implementation/SimpleRigidBody.cpp +++ b/Code/Physics/GamePhysics/Implementation/SimpleRigidBody.cpp @@ -300,11 +300,13 @@ Float4x4 SimpleRigidBody::GetView( const ::Oyster::Math::Float3 &offset ) const Float3 SimpleRigidBody::GetGravity() const { - return (Float3)this->rigidBody->getGravity(); + btVector3 gravity = this->rigidBody->getGravity(); + return Float3(gravity.x(), gravity.y(), gravity.z()); } Float3 SimpleRigidBody::GetLinearVelocity() const { - return (Float3)this->rigidBody->getLinearVelocity(); + btVector3 linearVelocity = this->rigidBody->getLinearVelocity(); + return Float3(linearVelocity.x(), linearVelocity.y(), linearVelocity.z()); } diff --git a/Code/Physics/GamePhysics/PhysicsAPI.h b/Code/Physics/GamePhysics/PhysicsAPI.h index 9bbde6e2..72d4a8c6 100644 --- a/Code/Physics/GamePhysics/PhysicsAPI.h +++ b/Code/Physics/GamePhysics/PhysicsAPI.h @@ -89,6 +89,8 @@ namespace Oyster virtual ICustomBody* AddCharacter(::Oyster::Math::Float height, ::Oyster::Math::Float radius, ::Oyster::Math::Float4 rotation, ::Oyster::Math::Float3 position, float mass, float restitution, float staticFriction, float dynamicFriction) = 0; + virtual ICustomBody* AddTriangleMesh(const std::wstring fileName, ::Oyster::Math::Float4 rotation, ::Oyster::Math::Float3 position, float mass, float restitution, float staticFriction, float dynamicFriction) = 0; + virtual void SetTimeStep(float timeStep) = 0; virtual void UpdateWorld() = 0; diff --git a/Code/Physics/lib/Debug/BulletFileLoader_Debug.lib b/Code/Physics/lib/Debug/BulletFileLoader_Debug.lib new file mode 100644 index 00000000..fa5abf6e Binary files /dev/null and b/Code/Physics/lib/Debug/BulletFileLoader_Debug.lib differ diff --git a/Code/Physics/lib/Debug/BulletFileLoader_Debugx64.lib b/Code/Physics/lib/Debug/BulletFileLoader_Debugx64.lib new file mode 100644 index 00000000..ee5da394 Binary files /dev/null and b/Code/Physics/lib/Debug/BulletFileLoader_Debugx64.lib differ diff --git a/Code/Physics/lib/Debug/BulletWorldImporter_Debug.lib b/Code/Physics/lib/Debug/BulletWorldImporter_Debug.lib new file mode 100644 index 00000000..021e8935 Binary files /dev/null and b/Code/Physics/lib/Debug/BulletWorldImporter_Debug.lib differ diff --git a/Code/Physics/lib/Debug/BulletWorldImporter_Debugx64.lib b/Code/Physics/lib/Debug/BulletWorldImporter_Debugx64.lib new file mode 100644 index 00000000..a6bb7540 Binary files /dev/null and b/Code/Physics/lib/Debug/BulletWorldImporter_Debugx64.lib differ diff --git a/Code/Physics/lib/Release/BulletFileLoader.lib b/Code/Physics/lib/Release/BulletFileLoader.lib new file mode 100644 index 00000000..b1ff3742 Binary files /dev/null and b/Code/Physics/lib/Release/BulletFileLoader.lib differ diff --git a/Code/Physics/lib/Release/BulletFileLoaderx64.lib b/Code/Physics/lib/Release/BulletFileLoaderx64.lib new file mode 100644 index 00000000..d3b423fd Binary files /dev/null and b/Code/Physics/lib/Release/BulletFileLoaderx64.lib differ diff --git a/Code/Physics/lib/Release/BulletWorldImporter.lib b/Code/Physics/lib/Release/BulletWorldImporter.lib new file mode 100644 index 00000000..1cbf5e3b Binary files /dev/null and b/Code/Physics/lib/Release/BulletWorldImporter.lib differ diff --git a/Code/Physics/lib/Release/BulletWorldImporterx64.lib b/Code/Physics/lib/Release/BulletWorldImporterx64.lib new file mode 100644 index 00000000..a6a5f35d Binary files /dev/null and b/Code/Physics/lib/Release/BulletWorldImporterx64.lib differ