Merge branch 'GameClient' of https://github.com/dean11/Danbias into GameClient

Conflicts:
	Code/Game/GameLogic/LevelLoader/LevelLoader.cpp
	Code/Game/GameLogic/LevelLoader/LevelLoader.h
	Code/Game/GameLogic/LevelLoader/LevelParser.cpp
	Code/Game/GameLogic/LevelLoader/LevelParser.h
	Code/Game/GameLogic/LevelLoader/Loader.cpp
	Code/Game/GameLogic/LevelLoader/Loader.h
	Code/Game/GameLogic/LevelLoader/ObjectDefines.h
	Code/Game/GameLogic/LevelLoader/ParseFunctions.cpp
This commit is contained in:
Pontus Fransson 2014-02-19 11:25:33 +01:00
commit 6c19c12682
60 changed files with 8947 additions and 325 deletions

View File

@ -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 <Utilities.h>
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<Oyster::Network::NetworkClient*, Oyster::Network::NetworkClient::ClientEventArgs> 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<Client::GameState*>(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<Client::GameState*>(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<Client::GameState*>(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<Client::GameState*>(gameClientState))
((Client::GameState*)gameClientState)->Protocol(&protocolData);
}
break;
case protocol_Lobby_Create:
{
if(dynamic_cast<Client::LobbyState*>(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<Client::GameState*>(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

View File

@ -187,7 +187,7 @@ void GameState::ReadKeyInput()
{ {
if( this->privData->input->IsKeyPressed(DIK_W) ) 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->nwClient->Send( Protocol_PlayerMovementForward() );
this->privData->key_forward = true; this->privData->key_forward = true;
@ -198,7 +198,7 @@ void GameState::ReadKeyInput()
if( this->privData->input->IsKeyPressed(DIK_S) ) 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->nwClient->Send( Protocol_PlayerMovementBackward() );
this->privData->key_backward = true; this->privData->key_backward = true;
@ -209,7 +209,7 @@ void GameState::ReadKeyInput()
if( this->privData->input->IsKeyPressed(DIK_A) ) 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->nwClient->Send( Protocol_PlayerMovementLeft() );
this->privData->key_strafeLeft = true; this->privData->key_strafeLeft = true;
@ -220,7 +220,7 @@ void GameState::ReadKeyInput()
if( this->privData->input->IsKeyPressed(DIK_D) ) 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->nwClient->Send( Protocol_PlayerMovementRight() );
this->privData->key_strafeRight = true; this->privData->key_strafeRight = true;
@ -372,7 +372,9 @@ const GameClientState::NetEvent & GameState::DataRecieved( const GameClientState
if( this->privData->myId == decoded.object_ID ) if( this->privData->myId == decoded.object_ID )
{ {
this->privData->camera.SetPosition( position ); this->privData->camera.SetPosition( position );
this->privData->camera.SetRotation( rotation ); //this->privData->camera.SetRotation( rotation );
this->privData->player.setPos( position );
//this->privData->player.setRot( rotation );
} }
C_DynamicObj *object = (*this->privData->dynamicObjects)[decoded.object_ID]; C_DynamicObj *object = (*this->privData->dynamicObjects)[decoded.object_ID];

View File

@ -60,8 +60,8 @@ bool LanMenuState::Init( SharedStateContent &shared )
// create guiElements // create guiElements
this->privData->connectIP = new TextField<LanMenuState*>( L"color_white.png", Float4(1.0f), Float4(0.0f), this, Float3(0.5f, 0.3f, 0.5f), Float2(0.8f, 0.09f), ResizeAspectRatio_None ); this->privData->connectIP = new TextField<LanMenuState*>( L"color_white.png", Float4(1.0f), Float4(0.0f), this, Float3(0.5f, 0.3f, 0.5f), Float2(0.8f, 0.09f), ResizeAspectRatio_None );
this->privData->connectIP->ReserveLines( 1 ); this->privData->connectIP->ReserveLines( 1 );
//this->privData->connectIP->AppendText( L"127.0.0.1" ); this->privData->connectIP->AppendText( L"127.0.0.1" );
this->privData->connectIP->AppendText( L"194.47.150.206" ); // HACK: connecting to Dennis's server //this->privData->connectIP->AppendText( L"194.47.150.206" ); // HACK: connecting to Dennis's server
this->privData->connectIP->SetFontHeight( 0.08f ); this->privData->connectIP->SetFontHeight( 0.08f );
this->privData->connectIP->SetLineSpacing( 0.005f ); this->privData->connectIP->SetLineSpacing( 0.005f );
this->privData->connectIP->SetTopAligned(); this->privData->connectIP->SetTopAligned();

View File

@ -141,6 +141,14 @@ void NetLoadState::LoadGame( const ::std::string &fileName )
desc.scale = oh->scale; desc.scale = oh->scale;
desc.visible = true; desc.visible = true;
// HACK: untill the world is right in lvl format
if( oh->specialTypeID == ObjectSpecialType_World)
{
desc.position = Float3(0,0,0);
desc.rotation = Quaternion::identity;
desc.scale = Float3(300,300,300);
}
C_StaticObj *staticObject = new C_StaticObj(); C_StaticObj *staticObject = new C_StaticObj();
if( staticObject->Init( desc ) ) if( staticObject->Init( desc ) )
{ {

View File

@ -170,12 +170,12 @@ using namespace GameLogic;
void PlayerVLethalObject(Player &player, Object &obj, Oyster::Math::Float kineticEnergyLoss, Oyster::Math::Float ExtraDamage) void PlayerVLethalObject(Player &player, Object &obj, Oyster::Math::Float kineticEnergyLoss, Oyster::Math::Float ExtraDamage)
{ {
int damageDone = 0; Oyster::Math::Float damageDone = 0;
int forceThreashHold = 200000; Oyster::Math::Float forceThreashHold = 200000;
if(kineticEnergyLoss > forceThreashHold) //should only take damage if the force is high enough if(kineticEnergyLoss > forceThreashHold) //should only take damage if the force is high enough
{ {
damageDone = (int)(kineticEnergyLoss * 0.10f); damageDone = (kineticEnergyLoss * 0.10f);
damageDone += ExtraDamage; damageDone += ExtraDamage;
//player.DamageLife(damageDone); //player.DamageLife(damageDone);
} }

View File

@ -76,14 +76,12 @@ Game::PlayerData* Game::CreatePlayer()
return this->players[i]; return this->players[i];
} }
Game::LevelData* Game::CreateLevel() Game::LevelData* Game::CreateLevel(const wchar_t mapName[255])
{ {
if(this->level) return this->level; if(this->level) return this->level;
this->level = new LevelData(); this->level = new LevelData();
//this->level->level->InitiateLevel(1000); this->level->level->InitiateLevel(mapName);
this->level->level->InitiateLevel("../Content/Worlds/ccc.bias");
return this->level; return this->level;
} }

View File

@ -72,7 +72,7 @@ namespace GameLogic
void GetAllPlayerPositions() const override; void GetAllPlayerPositions() const override;
PlayerData* CreatePlayer() override; PlayerData* CreatePlayer() override;
LevelData* CreateLevel() override; LevelData* CreateLevel(const wchar_t mapName[255] ) override;
void CreateTeam() override; void CreateTeam() override;
bool NewFrame() override; bool NewFrame() override;
void SetFPS( int FPS ) override; void SetFPS( int FPS ) override;

View File

@ -139,7 +139,7 @@ namespace GameLogic
/** Creates a level /** Creates a level
* @return Returns a ILevelData container to use for level manipulation * @return Returns a ILevelData container to use for level manipulation
*/ */
virtual ILevelData* CreateLevel( void ) = 0; virtual ILevelData* CreateLevel( const wchar_t mapName[255] ) = 0;
/** Creates a team /** Creates a team
* @return ? * @return ?

View File

@ -55,7 +55,7 @@ IObjectData* Game::LevelData::GetObjectAt(int ID) const
void Game::LevelData::GetAllDynamicObjects(Utility::DynamicMemory::DynamicArray<IObjectData*>& mem) const void Game::LevelData::GetAllDynamicObjects(Utility::DynamicMemory::DynamicArray<IObjectData*>& mem) const
{ {
mem.Resize(level->dynamicObjects.Size()); mem.Resize(level->dynamicObjects.Size());
for(int i = 0; i < level->dynamicObjects.Size(); i++) for(int i = 0; i < (int)level->dynamicObjects.Size(); i++)
{ {
mem[i] = level->dynamicObjects[i]; mem[i] = level->dynamicObjects[i];
} }

View File

@ -7,7 +7,7 @@ Game::PlayerData::PlayerData()
{ {
//set some stats that are appropriate to a player //set some stats that are appropriate to a player
Oyster::Math::Float3 centerPosition = Oyster::Math::Float3(50,130,0); Oyster::Math::Float3 centerPosition = Oyster::Math::Float3(-50,180,0);
Oyster::Math::Float3 size = Oyster::Math::Float3(0.25f,2.0f,0.5f); Oyster::Math::Float3 size = Oyster::Math::Float3(0.25f,2.0f,0.5f);
Oyster::Math::Float mass = 60; Oyster::Math::Float mass = 60;
@ -27,9 +27,7 @@ Game::PlayerData::PlayerData()
} }
Game::PlayerData::PlayerData(int playerID,int teamID) Game::PlayerData::PlayerData(int playerID,int teamID)
{ {
Oyster::Physics::ICustomBody* rigidBody;
this->player = new Player(); this->player = new Player();
} }
Game::PlayerData::~PlayerData() Game::PlayerData::~PlayerData()
{ {

View File

@ -4,6 +4,10 @@
#include "JumpPad.h" #include "JumpPad.h"
#include "ExplosiveCrate.h" #include "ExplosiveCrate.h"
#include "Portal.h" #include "Portal.h"
//Conversion from wstring to string
#include <codecvt>
using namespace GameLogic; using namespace GameLogic;
using namespace Utility::DynamicMemory; using namespace Utility::DynamicMemory;
using namespace Oyster::Physics; using namespace Oyster::Physics;
@ -26,14 +30,14 @@ Object* Level::createGameObj(ObjectHeader* obj, ICustomBody* rigidBody)
{ {
case ObjectSpecialType_None: case ObjectSpecialType_None:
{ {
gameObj = new StaticObject(rigidBody, Object::DefaultCollisionAfter, (ObjectSpecialType)obj->specialTypeID, objID++); gameObj = new StaticObject(rigidBody, Object::DefaultCollisionAfter, (ObjectSpecialType)obj->specialTypeID, objID);
} }
break; break;
case ObjectSpecialType_Sky: case ObjectSpecialType_Sky:
{ {
float skySize = ((SkyAttributes*)obj)->skySize; float skySize = ((SkyAttributes*)obj)->skySize;
//gameObj = new StaticObject(rigidBody, Object::DefaultCollisionAfter, (ObjectSpecialType)obj->specialTypeID, objID++); //gameObj = new StaticObject(rigidBody, Object::DefaultCollisionAfter, (ObjectSpecialType)obj->specialTypeID, objID);
} }
break; break;
case ObjectSpecialType_World: case ObjectSpecialType_World:
@ -44,28 +48,28 @@ Object* Level::createGameObj(ObjectHeader* obj, ICustomBody* rigidBody)
float worldSize = ((WorldAttributes*)obj)->worldSize; float worldSize = ((WorldAttributes*)obj)->worldSize;
float atmosphereSize = ((WorldAttributes*)obj)->atmoSphereSize; float atmosphereSize = ((WorldAttributes*)obj)->atmoSphereSize;
gameObj = new StaticObject(rigidBody, Object::DefaultCollisionAfter, (ObjectSpecialType)obj->specialTypeID, objID++); gameObj = new StaticObject(rigidBody, Object::DefaultCollisionAfter, (ObjectSpecialType)obj->specialTypeID, objID);
} }
break; break;
case ObjectSpecialType_Building: case ObjectSpecialType_Building:
{ {
gameObj = new StaticObject(rigidBody, Object::DefaultCollisionAfter, (ObjectSpecialType)obj->specialTypeID, objID++); gameObj = new StaticObject(rigidBody, Object::DefaultCollisionAfter, (ObjectSpecialType)obj->specialTypeID, objID);
} }
case ObjectSpecialType_Stone: case ObjectSpecialType_Stone:
{ {
gameObj = new DynamicObject(rigidBody, Object::DefaultCollisionAfter, (ObjectSpecialType)obj->specialTypeID, objID++); gameObj = new DynamicObject(rigidBody, Object::DefaultCollisionAfter, (ObjectSpecialType)obj->specialTypeID, objID);
} }
break; break;
case ObjectSpecialType_StandardBox: case ObjectSpecialType_StandardBox:
{ {
gameObj = new DynamicObject(rigidBody, Object::DefaultCollisionAfter, (ObjectSpecialType)obj->specialTypeID, objID++); gameObj = new DynamicObject(rigidBody, Object::DefaultCollisionAfter, (ObjectSpecialType)obj->specialTypeID, objID);
} }
break; break;
case ObjectSpecialType_RedExplosiveBox: case ObjectSpecialType_RedExplosiveBox:
{ {
int dmg = 50; Oyster::Math::Float dmg = 50;
Oyster::Math::Float force = 50; Oyster::Math::Float force = 50;
int radie = 50; Oyster::Math::Float radie = 50;
gameObj = new ExplosiveCrate(rigidBody, (ObjectSpecialType)obj->specialTypeID, objID++, dmg, force, radie); gameObj = new ExplosiveCrate(rigidBody, (ObjectSpecialType)obj->specialTypeID, objID++, dmg, force, radie);
} }
break; break;
@ -75,24 +79,24 @@ Object* Level::createGameObj(ObjectHeader* obj, ICustomBody* rigidBody)
// break; // break;
case ObjectSpecialType_SpikeBox: case ObjectSpecialType_SpikeBox:
{ {
gameObj = new DynamicObject(rigidBody, Object::DefaultCollisionAfter, (ObjectSpecialType)obj->specialTypeID, objID++); gameObj = new DynamicObject(rigidBody, Object::DefaultCollisionAfter, (ObjectSpecialType)obj->specialTypeID, objID);
} }
break; break;
case ObjectSpecialType_Spike: case ObjectSpecialType_Spike:
{ {
gameObj = new DynamicObject(rigidBody, Object::DefaultCollisionAfter, (ObjectSpecialType)obj->specialTypeID, objID++); gameObj = new DynamicObject(rigidBody, Object::DefaultCollisionAfter, (ObjectSpecialType)obj->specialTypeID, objID);
} }
break; break;
case ObjectSpecialType_CrystalFormation: case ObjectSpecialType_CrystalFormation:
{ {
int dmg = 50; int dmg = 50;
//gameObj = new Crystal(rigidBody); //gameObj = new Crystal(rigidBody);
gameObj = new StaticObject(rigidBody, Object::DefaultCollisionAfter, (ObjectSpecialType)obj->specialTypeID, objID++); gameObj = new StaticObject(rigidBody, Object::DefaultCollisionAfter, (ObjectSpecialType)obj->specialTypeID, objID);
} }
break; break;
case ObjectSpecialType_CrystalShard: case ObjectSpecialType_CrystalShard:
{ {
gameObj = new DynamicObject(rigidBody, Object::DefaultCollisionAfter, (ObjectSpecialType)obj->specialTypeID, objID++); gameObj = new DynamicObject(rigidBody, Object::DefaultCollisionAfter, (ObjectSpecialType)obj->specialTypeID, objID);
} }
break; break;
case ObjectSpecialType_JumpPad: case ObjectSpecialType_JumpPad:
@ -100,13 +104,13 @@ Object* Level::createGameObj(ObjectHeader* obj, ICustomBody* rigidBody)
float power = 500; //((JumpPadAttributes*)obj)->power; float power = 500; //((JumpPadAttributes*)obj)->power;
Oyster::Math::Float3 dir = ((JumpPadAttributes*)obj)->direction; Oyster::Math::Float3 dir = ((JumpPadAttributes*)obj)->direction;
Oyster::Math::Float3 pushForce = dir * power; 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; break;
case ObjectSpecialType_Portal: case ObjectSpecialType_Portal:
{ {
Oyster::Math::Float3 destination = ((PortalAttributes*)obj)->destination; 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; break;
//case ObjectSpecialType_SpawnPoint: //case ObjectSpecialType_SpawnPoint:
@ -122,12 +126,12 @@ Object* Level::createGameObj(ObjectHeader* obj, ICustomBody* rigidBody)
break; break;
case ObjectSpecialType_Generic: case ObjectSpecialType_Generic:
{ {
gameObj = new StaticObject(rigidBody, Object::DefaultCollisionAfter, (ObjectSpecialType)obj->specialTypeID, objID++); gameObj = new StaticObject(rigidBody, Object::DefaultCollisionAfter, (ObjectSpecialType)obj->specialTypeID, objID);
} }
break; break;
default: default:
{ {
gameObj = new StaticObject(rigidBody, Object::DefaultCollisionAfter, (ObjectSpecialType)obj->specialTypeID, objID++); gameObj = new StaticObject(rigidBody, Object::DefaultCollisionAfter, (ObjectSpecialType)obj->specialTypeID, objID);
} }
break; break;
} }
@ -197,11 +201,22 @@ ICustomBody* Level::InitRigidBodySphere( const ObjectHeader* obj)
rigidBody = API::Instance().AddCollisionSphere( rigidBodyRadius , rigidWorldRotation , rigidWorldPos , rigidBodyMass, obj->boundingVolume.sphere.restitutionCoeff , obj->boundingVolume.sphere.frictionCoeffStatic , obj->boundingVolume.sphere.frictionCoeffDynamic); rigidBody = API::Instance().AddCollisionSphere( rigidBodyRadius , rigidWorldRotation , rigidWorldPos , rigidBodyMass, obj->boundingVolume.sphere.restitutionCoeff , obj->boundingVolume.sphere.frictionCoeffStatic , obj->boundingVolume.sphere.frictionCoeffDynamic);
return rigidBody; return rigidBody;
} }
void Level::InitiateLevel(std::string levelPath) bool Level::InitiateLevel(std::wstring levelPath)
{ {
LevelLoader ll; LevelLoader ll;
ll.SetFolderPath("..\\Content\\Worlds\\");
std::vector<Utility::DynamicMemory::SmartPointer<ObjectTypeHeader>> objects; std::vector<Utility::DynamicMemory::SmartPointer<ObjectTypeHeader>> objects;
objects = ll.LoadLevel(levelPath);
//Convert from wstring to string
typedef std::codecvt_utf8<wchar_t> convert_typeX;
std::wstring_convert<convert_typeX, wchar_t> converterX;
std::string convertedLevelPath = converterX.to_bytes(levelPath);
objects = ll.LoadLevel(convertedLevelPath);
if(objects.size() == 0)
return false;
API::Instance().SetGravityPoint(Oyster::Math3D::Float3(0,0,0)); API::Instance().SetGravityPoint(Oyster::Math3D::Float3(0,0,0));
API::Instance().SetGravity(200); API::Instance().SetGravity(200);
@ -209,6 +224,7 @@ void Level::InitiateLevel(std::string levelPath)
for (int i = 0; i < objCount; i++) for (int i = 0; i < objCount; i++)
{ {
++this->objID;
ObjectTypeHeader* obj = objects.at(i); ObjectTypeHeader* obj = objects.at(i);
switch (obj->typeID) switch (obj->typeID)
{ {
@ -225,13 +241,10 @@ void Level::InitiateLevel(std::string levelPath)
staticObjData->ModelFile; staticObjData->ModelFile;
ICustomBody* rigidBody_Static = NULL; ICustomBody* rigidBody_Static = NULL;
if((ObjectSpecialType)staticObjData->specialTypeID == ObjectSpecialType_Sky)
{
} // HACK: untill the world is right in lvl format
if((ObjectSpecialType)staticObjData->specialTypeID == ObjectSpecialType_World) if((ObjectSpecialType)staticObjData->specialTypeID == ObjectSpecialType_World)
{ {
Oyster::Math::Float3 rigidWorldPos; Oyster::Math::Float3 rigidWorldPos;
Oyster::Math::Float4 rigidWorldRotation; Oyster::Math::Float4 rigidWorldRotation;
float rigidBodyMass; float rigidBodyMass;
@ -245,9 +258,8 @@ void Level::InitiateLevel(std::string levelPath)
rigidWorldRotation = Oyster::Math::Float4(0,0,0,1); rigidWorldRotation = Oyster::Math::Float4(0,0,0,1);
//mass scaled //mass scaled
rigidBodyMass = 100; rigidBodyMass = 0;
//Radius scaled //Radius scaled
rigidBodyRadius = 150; rigidBodyRadius = 150;
@ -332,8 +344,9 @@ void Level::InitiateLevel(std::string levelPath)
break; break;
} }
} }
return true;
} }
void Level::InitiateLevel(float radius) bool Level::InitiateLevel(float radius)
{ {
API::Instance().SetGravityPoint(Oyster::Math3D::Float3(0,0,0)); API::Instance().SetGravityPoint(Oyster::Math3D::Float3(0,0,0));
API::Instance().SetGravity(200); API::Instance().SetGravity(200);
@ -353,7 +366,7 @@ void Level::InitiateLevel(float radius)
int offset = 0; int offset = 0;
for(int i =0; i< nrOfBoxex; i ++) 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, 605 + i*5, 10), 5, 0.5f, 0.8f, 0.6f); 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::DefaultCollisionAfter, ObjectSpecialType_StandardBox, idCount++));
} }
@ -385,17 +398,18 @@ void Level::InitiateLevel(float radius)
}*/ }*/
// add crystal // add crystal
ICustomBody* rigidBody_Crystal = API::Instance().AddCollisionBox(Oyster::Math::Float3(0.5f, 0.5f, 0.5f), Oyster::Math::Float4(0, 0, 0, 1), Oyster::Math::Float3(10, 605, 0), 5, 0.5f, 0.8f, 0.6f); 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::DefaultCollisionAfter, ObjectSpecialType_StandardBox, idCount++));
// add house // add house
ICustomBody* rigidBody_House =API::Instance().AddCollisionBox(Oyster::Math::Float3(20, 20, 20), Oyster::Math::Float4(0, 0, 0, 1), Oyster::Math::Float3(-50, 590, 0), 0, 0.5f, 0.8f, 0.6f); 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::DefaultCollisionAfter, ObjectSpecialType_Generic, idCount++));
// add jumppad // add jumppad
ICustomBody* rigidBody_Jumppad = API::Instance().AddCollisionBox(Oyster::Math::Float3(1, 1, 1), Oyster::Math::Float4(0, 0, 0, 1), Oyster::Math::Float3(4, 600.3, 0), 5, 0.5f, 0.8f, 0.6f); ICustomBody* rigidBody_Jumppad = API::Instance().AddCollisionBox(Oyster::Math::Float3(1.0f, 1.0f, 1.0f), Oyster::Math::Float4(0.0f, 0.0f, 0.0f, 1.0f), Oyster::Math::Float3(4.0f, 600.3f, 0.0f), 5.0f, 0.5f, 0.8f, 0.6f);
this->staticObjects.Push(new JumpPad(rigidBody_Jumppad, ObjectSpecialType_JumpPad,idCount++ ,Oyster::Math::Float3(0,2000,0))); this->staticObjects.Push(new JumpPad(rigidBody_Jumppad, ObjectSpecialType_JumpPad,idCount++ ,Oyster::Math::Float3(0,2000,0)));
return true;
} }
void Level::AddPlayerToTeam(Player *player, int teamID) void Level::AddPlayerToTeam(Player *player, int teamID)
@ -419,7 +433,7 @@ int Level::getNrOfDynamicObj()
} }
Object* Level::GetObj( int ID) const Object* Level::GetObj( int ID) const
{ {
for (int i = 0; i < this->dynamicObjects.Size(); i++) for (int i = 0; i < (int)this->dynamicObjects.Size(); i++)
{ {
if(this->dynamicObjects[i]->GetID() == ID) if(this->dynamicObjects[i]->GetID() == ID)
return this->dynamicObjects[i]; return this->dynamicObjects[i];

View File

@ -30,8 +30,8 @@ namespace GameLogic
* Initiates a level for players to play on * Initiates a level for players to play on
* @param levelPath: Path to a file that contains all information on the level * @param levelPath: Path to a file that contains all information on the level
********************************************************/ ********************************************************/
void InitiateLevel(std::string levelPath); bool InitiateLevel(std::wstring levelPath);
void InitiateLevel(float radius); bool InitiateLevel(float radius);
Oyster::Physics::ICustomBody* InitRigidBodyCube( const ObjectHeader* obj); Oyster::Physics::ICustomBody* InitRigidBodyCube( const ObjectHeader* obj);
Oyster::Physics::ICustomBody* InitRigidBodySphere( const ObjectHeader* obj); Oyster::Physics::ICustomBody* InitRigidBodySphere( const ObjectHeader* obj);

View File

@ -0,0 +1,52 @@
//////////////////////////////////
// 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<Utility::DynamicMemory::SmartPointer<ObjectTypeHeader>> 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;
}

View File

@ -0,0 +1,56 @@
//////////////////////////////////
// Created by Sam Svensson 2013 //
//////////////////////////////////
#ifndef LEVELLOADER_H
#define LEVELLOADER_H
#include <string>
#include <vector>
#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<Utility::DynamicMemory::SmartPointer<ObjectTypeHeader>> 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<PrivData> pData;
};
}
#endif

View File

@ -0,0 +1,320 @@
/////////////////////////////////////
// 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<SmartPointer<ObjectTypeHeader>> LevelParser::Parse(std::wstring filename)
{
int bufferSize = 0;
int counter = 0;
bool loadCgf;
std::vector<SmartPointer<ObjectTypeHeader>> 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<SmartPointer<ObjectTypeHeader>>();
}
//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<ObjectTypeHeader> 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;
}

View File

@ -0,0 +1,31 @@
#ifndef LEVEL_PARSER_H
#define LEVEL_PARSER_H
#include <string>
#include <vector>
#include "ObjectDefines.h"
#include "Utilities.h"
namespace GameLogic
{
namespace LevelFileLoader
{
class LevelParser
{
public:
LevelParser();
~LevelParser();
//
std::vector<Utility::DynamicMemory::SmartPointer<ObjectTypeHeader>> Parse(std::wstring filename);
//
LevelMetaData ParseHeader(std::wstring filename);
private:
LevelLoaderInternal::FormatVersion formatVersion;
};
}
}
#endif

View File

@ -0,0 +1,22 @@
//////////////////////////////////
// Created by Sam Svensson 2013 //
//////////////////////////////////
#include "Loader.h"
#include <fstream>
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;
}

View File

@ -0,0 +1,28 @@
//////////////////////////////////
// Created by Sam Svensson 2013 //
//////////////////////////////////
#ifndef LOADER_H
#define LOADER_H
#include "Resource\OysterResource.h"
#include <string>
namespace GameLogic
{
namespace LevelFileLoader
{
class Loader
{
public:
Loader (){};
~Loader(){};
char* LoadFile(std::wstring fileName, int &size);
//TODO:
//Add functionality to load physicsObjects (hitboxes)
};
}
}
#endif;

View File

@ -0,0 +1,290 @@
#ifndef OBJECT_DEFINES_H
#define OBJECT_DEFINES_H
#include <string>
#include <vector>
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<GameMode> 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

View File

@ -0,0 +1,195 @@
//////////////////////////////////
// Created by Sam Svensson 2013 //
//////////////////////////////////
#include "ParseFunctions.h"
#include "Packing/Packing.h"
#include "Loader.h"
#include "Utilities.h"
#include <string>
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;
}
}
}
}

View File

@ -90,7 +90,7 @@ void Player::BeginFrame()
forwardDir.Normalize(); forwardDir.Normalize();
rightDir.Normalize(); rightDir.Normalize();
Oyster::Math::Float3 walkDirection = Oyster::Math::Float3(0.0, 0.0, 0.0); Oyster::Math::Float3 walkDirection = Oyster::Math::Float3(0.0, 0.0, 0.0);
Oyster::Math::Float walkSpeed = this->moveSpeed*0.2; Oyster::Math::Float walkSpeed = this->moveSpeed*0.2f;
if (key_forward > 0.001) if (key_forward > 0.001)
{ {
@ -122,7 +122,7 @@ void Player::BeginFrame()
if (key_forward <= 0.001 && key_backward <= 0.001 && key_strafeRight <= 0.001 && key_strafeLeft <= 0.001 && key_jump <= 0.001 && this->rigidBody->GetLambda() < 0.7f) if (key_forward <= 0.001 && key_backward <= 0.001 && key_strafeRight <= 0.001 && key_strafeLeft <= 0.001 && key_jump <= 0.001 && this->rigidBody->GetLambda() < 0.7f)
{ {
/* Dampen when on the ground and not being moved by the player */ /* Dampen when on the ground and not being moved by the player */
linearVelocity *= 0.2; linearVelocity *= 0.2f;
this->rigidBody->SetLinearVelocity (linearVelocity); this->rigidBody->SetLinearVelocity (linearVelocity);
} }
else else

View File

@ -99,7 +99,7 @@ bool GameSession::Create(GameDescription& desc, bool forceStart)
} }
/* Create the game level */ /* Create the game level */
if(!(this->levelData = this->gameInstance.CreateLevel())) if(!(this->levelData = this->gameInstance.CreateLevel(this->description.mapName.c_str())))
{ {
printf("Level not created!"); printf("Level not created!");
return false; return false;

View File

@ -1,5 +1,10 @@
<?xml version="1.0" encoding="utf-8" ?> <?xml version="1.0" encoding="utf-8" ?>
<configuration> <configuration>
<configSections>
<sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
<section name="StandAloneLauncher.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
</sectionGroup>
</configSections>
<startup> <startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" /> <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup> </startup>
@ -8,4 +13,11 @@
<probing privatePath="..\..\Bin\DLL\" /> <probing privatePath="..\..\Bin\DLL\" />
</assemblyBinding> </assemblyBinding>
</runtime> </runtime>
<userSettings>
<StandAloneLauncher.Properties.Settings>
<setting name="Dennis" serializeAs="String">
<value>.\..\Content\</value>
</setting>
</StandAloneLauncher.Properties.Settings>
</userSettings>
</configuration> </configuration>

View File

@ -36,7 +36,6 @@
this.label_listenPort = new System.Windows.Forms.Label(); this.label_listenPort = new System.Windows.Forms.Label();
this.panel_serverOptions = new System.Windows.Forms.Panel(); this.panel_serverOptions = new System.Windows.Forms.Panel();
this.panel_commands = new System.Windows.Forms.Panel(); this.panel_commands = new System.Windows.Forms.Panel();
this.mapName = new System.Windows.Forms.TextBox();
this.timeLimit = new System.Windows.Forms.NumericUpDown(); this.timeLimit = new System.Windows.Forms.NumericUpDown();
this.gameModes = new System.Windows.Forms.ComboBox(); this.gameModes = new System.Windows.Forms.ComboBox();
this.label3 = new System.Windows.Forms.Label(); this.label3 = new System.Windows.Forms.Label();
@ -52,6 +51,22 @@
this.splitter1 = new System.Windows.Forms.Splitter(); this.splitter1 = new System.Windows.Forms.Splitter();
this.clientInfoBox = new System.Windows.Forms.ListBox(); this.clientInfoBox = new System.Windows.Forms.ListBox();
this.panel_CommanArea = new System.Windows.Forms.Panel(); this.panel_CommanArea = new System.Windows.Forms.Panel();
this.label5 = new System.Windows.Forms.Label();
this.mapName = new System.Windows.Forms.ComboBox();
this.panelServerCommands = new System.Windows.Forms.Panel();
this.buttonExecuteSend = new System.Windows.Forms.Button();
this.panel2 = new System.Windows.Forms.Panel();
this.comboBox1 = new System.Windows.Forms.ComboBox();
this.numericUpDown1 = new System.Windows.Forms.NumericUpDown();
this.textBox1 = new System.Windows.Forms.TextBox();
this.tableLayoutPanel1 = new System.Windows.Forms.TableLayoutPanel();
this.label6 = new System.Windows.Forms.Label();
this.label7 = new System.Windows.Forms.Label();
this.label8 = new System.Windows.Forms.Label();
this.dataProtocolFields = new System.Windows.Forms.TableLayoutPanel();
this.buttonAddNewDataField = new System.Windows.Forms.Button();
this.button2 = new System.Windows.Forms.Button();
this.buttonsAtBottom = new System.Windows.Forms.TableLayoutPanel();
((System.ComponentModel.ISupportInitialize)(this.listenPort)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.listenPort)).BeginInit();
this.panel_serverOptions.SuspendLayout(); this.panel_serverOptions.SuspendLayout();
this.panel_commands.SuspendLayout(); this.panel_commands.SuspendLayout();
@ -59,13 +74,20 @@
((System.ComponentModel.ISupportInitialize)(this.nrOfClients)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.nrOfClients)).BeginInit();
this.panel_clientArea.SuspendLayout(); this.panel_clientArea.SuspendLayout();
this.panel_CommanArea.SuspendLayout(); this.panel_CommanArea.SuspendLayout();
this.panelServerCommands.SuspendLayout();
this.panel2.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).BeginInit();
this.tableLayoutPanel1.SuspendLayout();
this.dataProtocolFields.SuspendLayout();
this.buttonsAtBottom.SuspendLayout();
this.SuspendLayout(); this.SuspendLayout();
// //
// serverToggle // serverToggle
// //
this.serverToggle.Location = new System.Drawing.Point(9, 106); this.serverToggle.Dock = System.Windows.Forms.DockStyle.Bottom;
this.serverToggle.Location = new System.Drawing.Point(0, 83);
this.serverToggle.Name = "serverToggle"; this.serverToggle.Name = "serverToggle";
this.serverToggle.Size = new System.Drawing.Size(75, 23); this.serverToggle.Size = new System.Drawing.Size(241, 20);
this.serverToggle.TabIndex = 0; this.serverToggle.TabIndex = 0;
this.serverToggle.Text = "Start server"; this.serverToggle.Text = "Start server";
this.serverToggle.UseVisualStyleBackColor = true; this.serverToggle.UseVisualStyleBackColor = true;
@ -140,46 +162,40 @@
this.panel_serverOptions.Dock = System.Windows.Forms.DockStyle.Top; this.panel_serverOptions.Dock = System.Windows.Forms.DockStyle.Top;
this.panel_serverOptions.Location = new System.Drawing.Point(0, 0); this.panel_serverOptions.Location = new System.Drawing.Point(0, 0);
this.panel_serverOptions.Name = "panel_serverOptions"; this.panel_serverOptions.Name = "panel_serverOptions";
this.panel_serverOptions.Size = new System.Drawing.Size(200, 141); this.panel_serverOptions.Size = new System.Drawing.Size(241, 103);
this.panel_serverOptions.TabIndex = 6; this.panel_serverOptions.TabIndex = 6;
// //
// panel_commands // panel_commands
// //
this.panel_commands.Controls.Add(this.mapName);
this.panel_commands.Controls.Add(this.timeLimit); this.panel_commands.Controls.Add(this.timeLimit);
this.panel_commands.Controls.Add(this.mapName);
this.panel_commands.Controls.Add(this.gameModes); this.panel_commands.Controls.Add(this.gameModes);
this.panel_commands.Controls.Add(this.label3); this.panel_commands.Controls.Add(this.label3);
this.panel_commands.Controls.Add(this.forceStart); this.panel_commands.Controls.Add(this.forceStart);
this.panel_commands.Controls.Add(this.label2); this.panel_commands.Controls.Add(this.label2);
this.panel_commands.Controls.Add(this.label4); this.panel_commands.Controls.Add(this.label4);
this.panel_commands.Controls.Add(this.label5);
this.panel_commands.Controls.Add(this.labelClientsConnected); this.panel_commands.Controls.Add(this.labelClientsConnected);
this.panel_commands.Controls.Add(this.label1); this.panel_commands.Controls.Add(this.label1);
this.panel_commands.Controls.Add(this.nrOfClients); this.panel_commands.Controls.Add(this.nrOfClients);
this.panel_commands.Controls.Add(this.buttonStartGame); this.panel_commands.Controls.Add(this.buttonStartGame);
this.panel_commands.Location = new System.Drawing.Point(3, 150); this.panel_commands.Dock = System.Windows.Forms.DockStyle.Top;
this.panel_commands.Location = new System.Drawing.Point(0, 103);
this.panel_commands.Name = "panel_commands"; this.panel_commands.Name = "panel_commands";
this.panel_commands.Size = new System.Drawing.Size(191, 202); this.panel_commands.Size = new System.Drawing.Size(241, 188);
this.panel_commands.TabIndex = 7; this.panel_commands.TabIndex = 7;
this.panel_commands.Visible = false; this.panel_commands.Visible = false;
// //
// mapName
//
this.mapName.Location = new System.Drawing.Point(75, 10);
this.mapName.Name = "mapName";
this.mapName.Size = new System.Drawing.Size(113, 20);
this.mapName.TabIndex = 12;
this.mapName.Text = "2ofAll_updated.bias";
//
// timeLimit // timeLimit
// //
this.timeLimit.Location = new System.Drawing.Point(109, 94); this.timeLimit.Location = new System.Drawing.Point(112, 89);
this.timeLimit.Minimum = new decimal(new int[] { this.timeLimit.Minimum = new decimal(new int[] {
5, 5,
0, 0,
0, 0,
0}); 0});
this.timeLimit.Name = "timeLimit"; this.timeLimit.Name = "timeLimit";
this.timeLimit.Size = new System.Drawing.Size(68, 20); this.timeLimit.Size = new System.Drawing.Size(123, 20);
this.timeLimit.TabIndex = 11; this.timeLimit.TabIndex = 11;
this.timeLimit.ThousandsSeparator = true; this.timeLimit.ThousandsSeparator = true;
this.timeLimit.Value = new decimal(new int[] { this.timeLimit.Value = new decimal(new int[] {
@ -195,9 +211,9 @@
this.gameModes.Items.AddRange(new object[] { this.gameModes.Items.AddRange(new object[] {
"Free-for-all", "Free-for-all",
"Team death-match"}); "Team death-match"});
this.gameModes.Location = new System.Drawing.Point(78, 66); this.gameModes.Location = new System.Drawing.Point(77, 61);
this.gameModes.Name = "gameModes"; this.gameModes.Name = "gameModes";
this.gameModes.Size = new System.Drawing.Size(110, 21); this.gameModes.Size = new System.Drawing.Size(158, 21);
this.gameModes.TabIndex = 10; this.gameModes.TabIndex = 10;
// //
// label3 // label3
@ -242,11 +258,11 @@
// labelClientsConnected // labelClientsConnected
// //
this.labelClientsConnected.AutoSize = true; this.labelClientsConnected.AutoSize = true;
this.labelClientsConnected.Location = new System.Drawing.Point(9, 149); this.labelClientsConnected.Location = new System.Drawing.Point(131, 147);
this.labelClientsConnected.Name = "labelClientsConnected"; this.labelClientsConnected.Name = "labelClientsConnected";
this.labelClientsConnected.Size = new System.Drawing.Size(104, 13); this.labelClientsConnected.Size = new System.Drawing.Size(80, 13);
this.labelClientsConnected.TabIndex = 8; this.labelClientsConnected.TabIndex = 8;
this.labelClientsConnected.Text = "Clients connected: 0"; this.labelClientsConnected.Text = "Game clients: 0";
// //
// label1 // label1
// //
@ -259,7 +275,7 @@
// //
// nrOfClients // nrOfClients
// //
this.nrOfClients.Location = new System.Drawing.Point(78, 36); this.nrOfClients.Location = new System.Drawing.Point(72, 34);
this.nrOfClients.Maximum = new decimal(new int[] { this.nrOfClients.Maximum = new decimal(new int[] {
20, 20,
0, 0,
@ -271,7 +287,7 @@
0, 0,
0}); 0});
this.nrOfClients.Name = "nrOfClients"; this.nrOfClients.Name = "nrOfClients";
this.nrOfClients.Size = new System.Drawing.Size(39, 20); this.nrOfClients.Size = new System.Drawing.Size(163, 20);
this.nrOfClients.TabIndex = 7; this.nrOfClients.TabIndex = 7;
this.nrOfClients.Value = new decimal(new int[] { this.nrOfClients.Value = new decimal(new int[] {
10, 10,
@ -281,9 +297,10 @@
// //
// buttonStartGame // buttonStartGame
// //
this.buttonStartGame.Location = new System.Drawing.Point(9, 176); this.buttonStartGame.Dock = System.Windows.Forms.DockStyle.Bottom;
this.buttonStartGame.Location = new System.Drawing.Point(0, 166);
this.buttonStartGame.Name = "buttonStartGame"; this.buttonStartGame.Name = "buttonStartGame";
this.buttonStartGame.Size = new System.Drawing.Size(75, 23); this.buttonStartGame.Size = new System.Drawing.Size(241, 22);
this.buttonStartGame.TabIndex = 6; this.buttonStartGame.TabIndex = 6;
this.buttonStartGame.Text = "Start game"; this.buttonStartGame.Text = "Start game";
this.buttonStartGame.UseVisualStyleBackColor = true; this.buttonStartGame.UseVisualStyleBackColor = true;
@ -295,9 +312,9 @@
this.panel_clientArea.Controls.Add(this.splitter1); this.panel_clientArea.Controls.Add(this.splitter1);
this.panel_clientArea.Controls.Add(this.clientInfoBox); this.panel_clientArea.Controls.Add(this.clientInfoBox);
this.panel_clientArea.Dock = System.Windows.Forms.DockStyle.Fill; this.panel_clientArea.Dock = System.Windows.Forms.DockStyle.Fill;
this.panel_clientArea.Location = new System.Drawing.Point(200, 0); this.panel_clientArea.Location = new System.Drawing.Point(241, 0);
this.panel_clientArea.Name = "panel_clientArea"; this.panel_clientArea.Name = "panel_clientArea";
this.panel_clientArea.Size = new System.Drawing.Size(535, 616); this.panel_clientArea.Size = new System.Drawing.Size(494, 616);
this.panel_clientArea.TabIndex = 8; this.panel_clientArea.TabIndex = 8;
// //
// ServerInfoTextArea // ServerInfoTextArea
@ -307,19 +324,19 @@
this.ServerInfoTextArea.Dock = System.Windows.Forms.DockStyle.Fill; this.ServerInfoTextArea.Dock = System.Windows.Forms.DockStyle.Fill;
this.ServerInfoTextArea.Font = new System.Drawing.Font("GulimChe", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.ServerInfoTextArea.Font = new System.Drawing.Font("GulimChe", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.ServerInfoTextArea.ForeColor = System.Drawing.SystemColors.Info; this.ServerInfoTextArea.ForeColor = System.Drawing.SystemColors.Info;
this.ServerInfoTextArea.Location = new System.Drawing.Point(0, 152); this.ServerInfoTextArea.Location = new System.Drawing.Point(0, 269);
this.ServerInfoTextArea.Name = "ServerInfoTextArea"; this.ServerInfoTextArea.Name = "ServerInfoTextArea";
this.ServerInfoTextArea.ReadOnly = true; this.ServerInfoTextArea.ReadOnly = true;
this.ServerInfoTextArea.Size = new System.Drawing.Size(535, 464); this.ServerInfoTextArea.Size = new System.Drawing.Size(494, 347);
this.ServerInfoTextArea.TabIndex = 1; this.ServerInfoTextArea.TabIndex = 1;
this.ServerInfoTextArea.Text = ""; this.ServerInfoTextArea.Text = "";
// //
// splitter1 // splitter1
// //
this.splitter1.Dock = System.Windows.Forms.DockStyle.Top; this.splitter1.Dock = System.Windows.Forms.DockStyle.Top;
this.splitter1.Location = new System.Drawing.Point(0, 147); this.splitter1.Location = new System.Drawing.Point(0, 264);
this.splitter1.Name = "splitter1"; this.splitter1.Name = "splitter1";
this.splitter1.Size = new System.Drawing.Size(535, 5); this.splitter1.Size = new System.Drawing.Size(494, 5);
this.splitter1.TabIndex = 2; this.splitter1.TabIndex = 2;
this.splitter1.TabStop = false; this.splitter1.TabStop = false;
// //
@ -329,19 +346,221 @@
this.clientInfoBox.FormattingEnabled = true; this.clientInfoBox.FormattingEnabled = true;
this.clientInfoBox.Location = new System.Drawing.Point(0, 0); this.clientInfoBox.Location = new System.Drawing.Point(0, 0);
this.clientInfoBox.Name = "clientInfoBox"; this.clientInfoBox.Name = "clientInfoBox";
this.clientInfoBox.Size = new System.Drawing.Size(535, 147); this.clientInfoBox.Size = new System.Drawing.Size(494, 264);
this.clientInfoBox.TabIndex = 0; this.clientInfoBox.TabIndex = 0;
// //
// panel_CommanArea // panel_CommanArea
// //
this.panel_CommanArea.Controls.Add(this.panelServerCommands);
this.panel_CommanArea.Controls.Add(this.panel_commands); this.panel_CommanArea.Controls.Add(this.panel_commands);
this.panel_CommanArea.Controls.Add(this.panel_serverOptions); this.panel_CommanArea.Controls.Add(this.panel_serverOptions);
this.panel_CommanArea.Dock = System.Windows.Forms.DockStyle.Left; this.panel_CommanArea.Dock = System.Windows.Forms.DockStyle.Left;
this.panel_CommanArea.Location = new System.Drawing.Point(0, 0); this.panel_CommanArea.Location = new System.Drawing.Point(0, 0);
this.panel_CommanArea.Name = "panel_CommanArea"; this.panel_CommanArea.Name = "panel_CommanArea";
this.panel_CommanArea.Size = new System.Drawing.Size(200, 616); this.panel_CommanArea.Size = new System.Drawing.Size(241, 616);
this.panel_CommanArea.TabIndex = 9; this.panel_CommanArea.TabIndex = 9;
// //
// label5
//
this.label5.AutoSize = true;
this.label5.Location = new System.Drawing.Point(23, 147);
this.label5.Name = "label5";
this.label5.Size = new System.Drawing.Size(81, 13);
this.label5.TabIndex = 8;
this.label5.Text = "Lobby clients: 0";
//
// mapName
//
this.mapName.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.mapName.FormattingEnabled = true;
this.mapName.IntegralHeight = false;
this.mapName.Items.AddRange(new object[] {
"Set default"});
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;
//
// panelServerCommands
//
this.panelServerCommands.Controls.Add(this.dataProtocolFields);
this.panelServerCommands.Dock = System.Windows.Forms.DockStyle.Top;
this.panelServerCommands.Location = new System.Drawing.Point(0, 291);
this.panelServerCommands.Name = "panelServerCommands";
this.panelServerCommands.Size = new System.Drawing.Size(241, 85);
this.panelServerCommands.TabIndex = 8;
this.panelServerCommands.Visible = false;
//
// buttonExecuteSend
//
this.buttonExecuteSend.Dock = System.Windows.Forms.DockStyle.Fill;
this.buttonExecuteSend.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.buttonExecuteSend.Location = new System.Drawing.Point(116, 0);
this.buttonExecuteSend.Margin = new System.Windows.Forms.Padding(0);
this.buttonExecuteSend.Name = "buttonExecuteSend";
this.buttonExecuteSend.Size = new System.Drawing.Size(117, 21);
this.buttonExecuteSend.TabIndex = 0;
this.buttonExecuteSend.Text = "Send";
this.buttonExecuteSend.UseVisualStyleBackColor = true;
//
// panel2
//
this.panel2.Controls.Add(this.button2);
this.panel2.Controls.Add(this.textBox1);
this.panel2.Controls.Add(this.comboBox1);
this.panel2.Controls.Add(this.numericUpDown1);
this.panel2.Dock = System.Windows.Forms.DockStyle.Fill;
this.panel2.Location = new System.Drawing.Point(4, 32);
this.panel2.Name = "panel2";
this.panel2.Size = new System.Drawing.Size(233, 21);
this.panel2.TabIndex = 0;
//
// comboBox1
//
this.comboBox1.Dock = System.Windows.Forms.DockStyle.Left;
this.comboBox1.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.comboBox1.FormattingEnabled = true;
this.comboBox1.IntegralHeight = false;
this.comboBox1.Items.AddRange(new object[] {
"netBool;",
"netChar;",
"netUChar;",
"netShort;",
"netUShort;",
"netInt;",
"netUInt;",
"netInt64;",
"netUInt64;",
"netFloat;",
"netDouble;",
"netCharPtr;"});
this.comboBox1.Location = new System.Drawing.Point(42, 0);
this.comboBox1.Name = "comboBox1";
this.comboBox1.Size = new System.Drawing.Size(78, 21);
this.comboBox1.TabIndex = 10;
//
// numericUpDown1
//
this.numericUpDown1.Dock = System.Windows.Forms.DockStyle.Left;
this.numericUpDown1.Location = new System.Drawing.Point(0, 0);
this.numericUpDown1.Name = "numericUpDown1";
this.numericUpDown1.Size = new System.Drawing.Size(42, 20);
this.numericUpDown1.TabIndex = 11;
//
// textBox1
//
this.textBox1.Dock = System.Windows.Forms.DockStyle.Left;
this.textBox1.Location = new System.Drawing.Point(120, 0);
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(64, 20);
this.textBox1.TabIndex = 12;
//
// tableLayoutPanel1
//
this.tableLayoutPanel1.CellBorderStyle = System.Windows.Forms.TableLayoutPanelCellBorderStyle.Single;
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, 110F));
this.tableLayoutPanel1.Controls.Add(this.label6, 0, 0);
this.tableLayoutPanel1.Controls.Add(this.label7, 1, 0);
this.tableLayoutPanel1.Controls.Add(this.label8, 2, 0);
this.tableLayoutPanel1.Dock = System.Windows.Forms.DockStyle.Fill;
this.tableLayoutPanel1.Location = new System.Drawing.Point(4, 4);
this.tableLayoutPanel1.Name = "tableLayoutPanel1";
this.tableLayoutPanel1.RowCount = 1;
this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 27.05882F));
this.tableLayoutPanel1.Size = new System.Drawing.Size(233, 21);
this.tableLayoutPanel1.TabIndex = 9;
//
// label6
//
this.label6.AutoSize = true;
this.label6.Location = new System.Drawing.Point(4, 1);
this.label6.Name = "label6";
this.label6.Size = new System.Drawing.Size(18, 13);
this.label6.TabIndex = 8;
this.label6.Text = "ID";
this.label6.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// label7
//
this.label7.AutoSize = true;
this.label7.Location = new System.Drawing.Point(46, 1);
this.label7.Name = "label7";
this.label7.Size = new System.Drawing.Size(31, 13);
this.label7.TabIndex = 8;
this.label7.Text = "Type";
//
// label8
//
this.label8.AutoSize = true;
this.label8.Location = new System.Drawing.Point(123, 1);
this.label8.Name = "label8";
this.label8.Size = new System.Drawing.Size(34, 13);
this.label8.TabIndex = 8;
this.label8.Text = "Value";
//
// dataProtocolFields
//
this.dataProtocolFields.CellBorderStyle = System.Windows.Forms.TableLayoutPanelCellBorderStyle.Single;
this.dataProtocolFields.ColumnCount = 1;
this.dataProtocolFields.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 21F));
this.dataProtocolFields.Controls.Add(this.panel2, 0, 1);
this.dataProtocolFields.Controls.Add(this.tableLayoutPanel1, 0, 0);
this.dataProtocolFields.Controls.Add(this.buttonsAtBottom, 0, 2);
this.dataProtocolFields.Dock = System.Windows.Forms.DockStyle.Fill;
this.dataProtocolFields.Location = new System.Drawing.Point(0, 0);
this.dataProtocolFields.Margin = new System.Windows.Forms.Padding(0);
this.dataProtocolFields.Name = "dataProtocolFields";
this.dataProtocolFields.RowCount = 3;
this.dataProtocolFields.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 27F));
this.dataProtocolFields.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 27F));
this.dataProtocolFields.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F));
this.dataProtocolFields.Size = new System.Drawing.Size(241, 85);
this.dataProtocolFields.TabIndex = 9;
//
// buttonAddNewDataField
//
this.buttonAddNewDataField.Dock = System.Windows.Forms.DockStyle.Fill;
this.buttonAddNewDataField.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.buttonAddNewDataField.Location = new System.Drawing.Point(0, 0);
this.buttonAddNewDataField.Margin = new System.Windows.Forms.Padding(0);
this.buttonAddNewDataField.Name = "buttonAddNewDataField";
this.buttonAddNewDataField.Size = new System.Drawing.Size(116, 21);
this.buttonAddNewDataField.TabIndex = 1;
this.buttonAddNewDataField.Text = "Add field";
this.buttonAddNewDataField.UseVisualStyleBackColor = true;
this.buttonAddNewDataField.Click += new System.EventHandler(this.buttonAddNewDataField_Click);
//
// button2
//
this.button2.Dock = System.Windows.Forms.DockStyle.Fill;
this.button2.FlatAppearance.BorderColor = System.Drawing.Color.Black;
this.button2.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.button2.Location = new System.Drawing.Point(184, 0);
this.button2.Margin = new System.Windows.Forms.Padding(0);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(49, 21);
this.button2.TabIndex = 0;
this.button2.Text = "remove";
this.button2.UseVisualStyleBackColor = true;
//
// buttonsAtBottom
//
this.buttonsAtBottom.ColumnCount = 2;
this.buttonsAtBottom.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50F));
this.buttonsAtBottom.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50F));
this.buttonsAtBottom.Controls.Add(this.buttonAddNewDataField, 0, 0);
this.buttonsAtBottom.Controls.Add(this.buttonExecuteSend, 1, 0);
this.buttonsAtBottom.Dock = System.Windows.Forms.DockStyle.Fill;
this.buttonsAtBottom.Location = new System.Drawing.Point(4, 60);
this.buttonsAtBottom.Name = "buttonsAtBottom";
this.buttonsAtBottom.RowCount = 1;
this.buttonsAtBottom.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 50F));
this.buttonsAtBottom.Size = new System.Drawing.Size(233, 21);
this.buttonsAtBottom.TabIndex = 10;
//
// Form1 // Form1
// //
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
@ -361,6 +580,14 @@
((System.ComponentModel.ISupportInitialize)(this.nrOfClients)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.nrOfClients)).EndInit();
this.panel_clientArea.ResumeLayout(false); this.panel_clientArea.ResumeLayout(false);
this.panel_CommanArea.ResumeLayout(false); this.panel_CommanArea.ResumeLayout(false);
this.panelServerCommands.ResumeLayout(false);
this.panel2.ResumeLayout(false);
this.panel2.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).EndInit();
this.tableLayoutPanel1.ResumeLayout(false);
this.tableLayoutPanel1.PerformLayout();
this.dataProtocolFields.ResumeLayout(false);
this.buttonsAtBottom.ResumeLayout(false);
this.ResumeLayout(false); this.ResumeLayout(false);
} }
@ -387,10 +614,25 @@
private System.Windows.Forms.NumericUpDown timeLimit; private System.Windows.Forms.NumericUpDown timeLimit;
private System.Windows.Forms.Label label3; private System.Windows.Forms.Label label3;
private System.Windows.Forms.Label label4; private System.Windows.Forms.Label label4;
private System.Windows.Forms.TextBox mapName;
private System.Windows.Forms.CheckBox forceStart; private System.Windows.Forms.CheckBox forceStart;
private System.Windows.Forms.Label labelClientsConnected; private System.Windows.Forms.Label labelClientsConnected;
private System.Windows.Forms.Panel panel_CommanArea; private System.Windows.Forms.Panel panel_CommanArea;
private System.Windows.Forms.Label label5;
private System.Windows.Forms.ComboBox mapName;
private System.Windows.Forms.Panel panelServerCommands;
private System.Windows.Forms.Button buttonExecuteSend;
private System.Windows.Forms.Panel panel2;
private System.Windows.Forms.ComboBox comboBox1;
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.NumericUpDown numericUpDown1;
private System.Windows.Forms.TableLayoutPanel dataProtocolFields;
private System.Windows.Forms.TableLayoutPanel tableLayoutPanel1;
private System.Windows.Forms.Label label6;
private System.Windows.Forms.Label label7;
private System.Windows.Forms.Label label8;
private System.Windows.Forms.Button buttonAddNewDataField;
private System.Windows.Forms.Button button2;
private System.Windows.Forms.TableLayoutPanel buttonsAtBottom;
} }
} }

View File

@ -11,6 +11,7 @@ using System.Windows.Interop;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Threading; using System.Threading;
using System.Timers; using System.Timers;
using System.IO;
namespace StandAloneLauncher namespace StandAloneLauncher
{ {
@ -18,12 +19,22 @@ namespace StandAloneLauncher
{ {
System.Windows.Interop.StandaloneGameServerCLI gameServer; System.Windows.Interop.StandaloneGameServerCLI gameServer;
bool serverIsRunning = false; bool serverIsRunning = false;
bool gameIsStarted = false;
public Form1() public Form1()
{ {
InitializeComponent(); InitializeComponent();
this.gameModes.SelectedIndex = 0;
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);
}
this.gameModes.SelectedIndex = 0;
this.mapName.SelectedIndex = 0;
} }
public bool Initiate() public bool Initiate()
@ -55,6 +66,7 @@ namespace StandAloneLauncher
this.serverToggle.Text = "Start server"; this.serverToggle.Text = "Start server";
this.ServerInfoTextArea.AppendText(DateTime.Now.ToUniversalTime() + "\n\t" + "Server terminated!\n"); this.ServerInfoTextArea.AppendText(DateTime.Now.ToUniversalTime() + "\n\t" + "Server terminated!\n");
this.panel_commands.Visible = false; this.panel_commands.Visible = false;
this.panelServerCommands.Visible = false;
} }
else else
{ {
@ -77,6 +89,7 @@ namespace StandAloneLauncher
this.gameServer.ServerStart(); this.gameServer.ServerStart();
this.panel_commands.Visible = true; 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.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;
} }
else else
{ {
@ -87,18 +100,38 @@ namespace StandAloneLauncher
private void buttonStartGame_Click(object sender, EventArgs e) private void buttonStartGame_Click(object sender, EventArgs e)
{ {
//this.gameServer.GameSetGameMode(this.gameModes.SelectedText); if (!gameIsStarted)
this.gameServer.GameSetGameTime((int)this.timeLimit.Value);
this.gameServer.GameSetMapName(this.mapName.Text);
this.gameServer.GameSetMaxClients((int)this.nrOfClients.Value);
if (!this.gameServer.GameStart( this.forceStart.Checked ))
{ {
this.ServerInfoTextArea.AppendText(DateTime.Now.ToUniversalTime() + "\n\t" + "Failed to start the game session!\n"); //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);
if (!(gameIsStarted = this.gameServer.GameStart(this.forceStart.Checked)))
{
this.ServerInfoTextArea.AppendText(DateTime.Now.ToUniversalTime() + "\n\t" + "Failed to start the game session!\n");
}
else
{
this.ServerInfoTextArea.AppendText(DateTime.Now.ToUniversalTime() + "\n\t" + "Game session started!\n");
this.buttonStartGame.Text = "Stop Game";
this.mapName.Enabled = false;
this.nrOfClients.Enabled = false;
this.gameModes.Enabled = false;
this.timeLimit.Enabled = false;
this.forceStart.Enabled = false;
}
} }
else else
{ {
this.ServerInfoTextArea.AppendText(DateTime.Now.ToUniversalTime() + "\n\t" + "Game session started!\n"); 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;
} }
} }
@ -109,5 +142,17 @@ namespace StandAloneLauncher
this.gameServer.ServerStop(); this.gameServer.ServerStop();
} }
} }
private void buttonAddNewDataField_Click(object sender, EventArgs e)
{
this.dataProtocolFields.RowCount++;
this.dataProtocolFields.SetRow(this.buttonsAtBottom, this.dataProtocolFields.RowCount - 1);
Panel p = new Panel();
p = this.panel2;
this.dataProtocolFields.RowStyles.Add(new RowStyle(SizeType.Absolute, 27));
}
} }
} }

View File

@ -8,23 +8,31 @@
// </auto-generated> // </auto-generated>
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
namespace StandAloneLauncher.Properties namespace StandAloneLauncher.Properties {
{
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")] [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")]
internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
{
private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
public static Settings Default public static Settings Default {
{ get {
get
{
return defaultInstance; return defaultInstance;
} }
} }
[global::System.Configuration.UserScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute(".\\..\\Content\\")]
public string Dennis {
get {
return ((string)(this["Dennis"]));
}
set {
this["Dennis"] = value;
}
}
} }
} }

View File

@ -1,7 +1,9 @@
<?xml version='1.0' encoding='utf-8'?> <?xml version='1.0' encoding='utf-8'?>
<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)"> <SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)" GeneratedClassNamespace="StandAloneLauncher.Properties" GeneratedClassName="Settings">
<Profiles> <Profiles />
<Profile Name="(Default)" /> <Settings>
</Profiles> <Setting Name="Dennis" Type="System.String" Scope="User">
<Settings /> <Value Profile="(Default)">.\..\Content\</Value>
</Setting>
</Settings>
</SettingsFile> </SettingsFile>

View File

@ -80,6 +80,7 @@
<ItemGroup> <ItemGroup>
<Reference Include="System" /> <Reference Include="System" />
<Reference Include="System.Core" /> <Reference Include="System.Core" />
<Reference Include="System.DirectoryServices" />
<Reference Include="System.Xml.Linq" /> <Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" /> <Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" /> <Reference Include="Microsoft.CSharp" />

View File

@ -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)

File diff suppressed because it is too large Load Diff

View File

@ -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 <memory.h>
#endif
#include <string.h>
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

View File

@ -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 <stdint.h>
#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__

View File

@ -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 <assert.h>
//#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<bStructHandle*> bListBasePtr;
typedef btHashMap<btHashPtr, bStructHandle*> bPtrMap;
}
#endif//__BCOMMON_H__

View File

@ -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 <assert.h>
#include "bDNA.h"
#include "bChunk.h"
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
//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; j<eleLen; j++, curStruct+=2)
{
if (curStruct[0] == type)
{
//char *name = m_Names[curStruct[1]].m_name;
//if (name[0] != '*')
if (m_Names[curStruct[1]].m_isPointer)
{
mCMPFlags[i] = FDF_STRUCT_NEQU;
initRecurseCmpFlags(i);
}
}
}
}
}
}
// ----------------------------------------------------- //
void bDNA::initCmpFlags(bDNA *memDNA)
{
// compare the file to memory
// this ptr should be the file data
assert(!m_Names.size() == 0 && "SDNA empty!");
mCMPFlags.resize(mStructs.size(), FDF_NONE);
int i;
for ( i=0; i<(int)mStructs.size(); i++)
{
short *oldStruct = mStructs[i];
int oldLookup = getReverseType(oldStruct[0]);
if (oldLookup == -1)
{
mCMPFlags[i] = FDF_NONE;
continue;
}
//char* typeName = mTypes[oldStruct[0]];
//#define SLOW_FORWARD_COMPATIBLE 1
#ifdef SLOW_FORWARD_COMPATIBLE
char* typeName = mTypes[oldLookup];
int newLookup = memDNA->getReverseType(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; j<elementLength; j++, curStruct+=2, oldStruct+=2)
{
// type the same
//const char* typeFileDNA = mTypes[oldStruct[0]];
//const char* typeMemDNA = mTypes[curStruct[0]];
if (strcmp(mTypes[oldStruct[0]], memDNA->mTypes[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)
<nr> (4 bytes) amount of names (int)
<string>
<string>
*/
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<dataLen; i++)
{
bNameInfo info;
info.m_name = cp;
info.m_isPointer = (info.m_name[0] == '*') || (info.m_name[1] == '*');
name_is_array(info.m_name,&info.m_dim0,&info.m_dim1);
m_Names.push_back(info);
while (*cp)cp++;
cp++;
}
{
nr= (long)cp;
//long mask=3;
nr= ((nr+3)&~3)-nr;
while (nr--)
{
cp++;
}
}
/*
TYPE (4 bytes)
<nr> amount of types (int)
<string>
<string>
*/
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<dataLen; i++)
{
mTypes.push_back(cp);
while (*cp)cp++;
cp++;
}
{
nr= (long)cp;
// long mask=3;
nr= ((nr+3)&~3)-nr;
while (nr--)
{
cp++;
}
}
/*
TLEN (4 bytes)
<len> (short) the lengths of types
<len>
*/
// Parse type lens
intPtr = (int*)cp;
assert(strncmp(cp, "TLEN", 4)==0); intPtr++;
dataLen = (int)mTypes.size();
shtPtr = (short*)intPtr;
for ( i=0; i<dataLen; i++, shtPtr++)
{
if (swap)
shtPtr[0] = ChunkUtils::swapShort(shtPtr[0]);
mTlens.push_back(shtPtr[0]);
}
if (dataLen & 1) shtPtr++;
/*
STRC (4 bytes)
<nr> amount of structs (int)
<typenr>
<nr_of_elems>
<typenr>
<namenr>
<typenr>
<namenr>
*/
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; i<dataLen; i++)
{
mStructs.push_back (shtPtr);
if (swap)
{
shtPtr[0]= ChunkUtils::swapShort(shtPtr[0]);
shtPtr[1]= ChunkUtils::swapShort(shtPtr[1]);
int len = shtPtr[1];
shtPtr+= 2;
for (int a=0; a<len; a++, shtPtr+=2)
{
shtPtr[0]= ChunkUtils::swapShort(shtPtr[0]);
shtPtr[1]= ChunkUtils::swapShort(shtPtr[1]);
}
}
else
shtPtr+= (2*shtPtr[1])+2;
}
// build reverse lookups
for ( i=0; i<(int)mStructs.size(); i++)
{
short *strc = mStructs.at(i);
if (!mPtrLen && strcmp(mTypes[strc[0]],"ListBase")==0)
{
mPtrLen = mTlens[strc[0]]/2;
}
mStructReverse.insert(strc[0], i);
mTypeLookup.insert(btHashString(mTypes[strc[0]]),i);
}
}
// ----------------------------------------------------- //
int bDNA::getArraySize(char* string)
{
int ret = 1;
int len = strlen(string);
char* next = 0;
for (int i=0; i<len; i++)
{
char c = string[i];
if (c == '[')
next = &string[i+1];
else if (c==']')
if (next)
ret *= atoi(next);
}
// print (string << ' ' << ret);
return ret;
}
void bDNA::dumpTypeDefinitions()
{
int i;
int numTypes = mTypes.size();
for (i=0;i<numTypes;i++)
{
}
for ( i=0; i<(int)mStructs.size(); i++)
{
int totalBytes=0;
short *oldStruct = mStructs[i];
int oldLookup = getReverseType(oldStruct[0]);
if (oldLookup == -1)
{
mCMPFlags[i] = FDF_NONE;
continue;
}
short* newStruct = mStructs[oldLookup];
char* typeName = mTypes[newStruct[0]];
printf("%3d: %s ",i,typeName);
//char *name = mNames[oldStruct[1]];
int len = oldStruct[1];
printf(" (%d fields) ",len);
oldStruct+=2;
printf("{");
int j;
for (j=0; j<len; ++j,oldStruct+=2) {
const char* name = m_Names[oldStruct[1]].m_name;
printf("%s %s", mTypes[oldStruct[0]],name);
int elemNumBytes= 0;
int arrayDimensions = getArraySizeNew(oldStruct[1]);
if (m_Names[oldStruct[1]].m_isPointer)
{
elemNumBytes = VOID_IS_8 ? 8 : 4;
} else
{
elemNumBytes = getLength(oldStruct[0]);
}
printf(" /* %d bytes */",elemNumBytes*arrayDimensions);
if (j == len-1) {
printf(";}");
} else {
printf("; ");
}
totalBytes+=elemNumBytes*arrayDimensions;
}
printf("\ntotalBytes=%d\n\n",totalBytes);
}
#if 0
/* dump out display of types and their sizes */
for (i=0; i<bf->types_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; j<bf->types[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

View File

@ -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<int> mCMPFlags;
btAlignedObjectArray<bNameInfo> m_Names;
btAlignedObjectArray<char*> mTypes;
btAlignedObjectArray<short*> mStructs;
btAlignedObjectArray<short> mTlens;
btHashMap<btHashInt, int> mStructReverse;
btHashMap<btHashString,int> mTypeLookup;
int mPtrLen;
};
}
#endif//__BDNA_H__

View File

@ -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__

File diff suppressed because it is too large Load Diff

View File

@ -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 <stdio.h>
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<char*> m_pointerFixupArray;
btAlignedObjectArray<char*> m_pointerPtrFixupArray;
btAlignedObjectArray<bChunkInd> m_chunks;
btHashMap<btHashPtr, bChunkInd> 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__

View File

@ -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 <memory.h>
#endif
#include <string.h>
// 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);
}

View File

@ -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<bStructHandle*> m_softBodies;
btAlignedObjectArray<bStructHandle*> m_rigidBodies;
btAlignedObjectArray<bStructHandle*> m_collisionObjects;
btAlignedObjectArray<bStructHandle*> m_collisionShapes;
btAlignedObjectArray<bStructHandle*> m_constraints;
btAlignedObjectArray<bStructHandle*> m_bvhs;
btAlignedObjectArray<bStructHandle*> m_triangleInfoMaps;
btAlignedObjectArray<bStructHandle*> m_dynamicsWorldInfo;
btAlignedObjectArray<char*> 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

View File

@ -0,0 +1,12 @@
project "BulletFileLoader"
kind "StaticLib"
targetdir "../../lib"
includedirs {
"../../../src"
}
files {
"**.cpp",
"**.h"
}

View File

@ -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)

View File

@ -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;i<bulletFile2->m_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;i<bulletFile2->m_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;i<bulletFile2->m_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;i<bulletFile2->m_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;i<bulletFile2->m_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;i<bulletFile2->m_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;
}

View File

@ -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

File diff suppressed because it is too large Load Diff

View File

@ -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<btCollisionShape*> m_allocatedCollisionShapes;
btAlignedObjectArray<btCollisionObject*> m_allocatedRigidBodies;
btAlignedObjectArray<btTypedConstraint*> m_allocatedConstraints;
btAlignedObjectArray<btOptimizedBvh*> m_allocatedBvhs;
btAlignedObjectArray<btTriangleInfoMap*> m_allocatedTriangleInfoMaps;
btAlignedObjectArray<btTriangleIndexVertexArray*> m_allocatedTriangleIndexArrays;
btAlignedObjectArray<btStridingMeshInterfaceData*> m_allocatedbtStridingMeshInterfaceDatas;
btAlignedObjectArray<char*> m_allocatedNames;
btAlignedObjectArray<int*> m_indexArrays;
btAlignedObjectArray<short int*> m_shortIndexArrays;
btAlignedObjectArray<unsigned char*> m_charIndexArrays;
btAlignedObjectArray<btVector3FloatData*> m_floatVertexArrays;
btAlignedObjectArray<btVector3DoubleData*> m_doubleVertexArrays;
btHashMap<btHashPtr,btOptimizedBvh*> m_bvhMap;
btHashMap<btHashPtr,btTriangleInfoMap*> m_timMap;
btHashMap<btHashString,btCollisionShape*> m_nameShapeMap;
btHashMap<btHashString,btRigidBody*> m_nameBodyMap;
btHashMap<btHashString,btTypedConstraint*> m_nameConstraintMap;
btHashMap<btHashPtr,const char*> m_objectNameMap;
btHashMap<btHashPtr,btCollisionShape*> m_shapeMap;
btHashMap<btHashPtr,btCollisionObject*> 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

View File

@ -0,0 +1,13 @@
project "BulletWorldImporter"
kind "StaticLib"
targetdir "../../lib"
includedirs {
"../BulletFileLoader",
"../../../src"
}
files {
"**.cpp",
"**.h"
}

View File

@ -97,7 +97,7 @@
<GenerateDebugInformation>true</GenerateDebugInformation> <GenerateDebugInformation>true</GenerateDebugInformation>
<ModuleDefinitionFile> <ModuleDefinitionFile>
</ModuleDefinitionFile> </ModuleDefinitionFile>
<AdditionalDependencies>$(SolutionDir)Physics/lib/debug/BulletCollision_Debug.lib;$(SolutionDir)Physics/lib/debug/BulletDynamics_Debug.lib;$(SolutionDir)Physics/lib/debug/LinearMath_Debug.lib;%(AdditionalDependencies)</AdditionalDependencies> <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)</AdditionalDependencies>
</Link> </Link>
</ItemDefinitionGroup> </ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
@ -112,7 +112,7 @@
<GenerateDebugInformation>true</GenerateDebugInformation> <GenerateDebugInformation>true</GenerateDebugInformation>
<ModuleDefinitionFile> <ModuleDefinitionFile>
</ModuleDefinitionFile> </ModuleDefinitionFile>
<AdditionalDependencies>$(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)</AdditionalDependencies> <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)</AdditionalDependencies>
</Link> </Link>
</ItemDefinitionGroup> </ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
@ -131,7 +131,7 @@
<OptimizeReferences>true</OptimizeReferences> <OptimizeReferences>true</OptimizeReferences>
<ModuleDefinitionFile> <ModuleDefinitionFile>
</ModuleDefinitionFile> </ModuleDefinitionFile>
<AdditionalDependencies>$(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)</AdditionalDependencies> <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)</AdditionalDependencies>
</Link> </Link>
</ItemDefinitionGroup> </ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
@ -150,7 +150,7 @@
<OptimizeReferences>true</OptimizeReferences> <OptimizeReferences>true</OptimizeReferences>
<ModuleDefinitionFile> <ModuleDefinitionFile>
</ModuleDefinitionFile> </ModuleDefinitionFile>
<AdditionalDependencies>$(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)</AdditionalDependencies> <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)</AdditionalDependencies>
</Link> </Link>
</ItemDefinitionGroup> </ItemDefinitionGroup>
<ItemGroup> <ItemGroup>

View File

@ -1,6 +1,9 @@
#include "PhysicsAPI_Impl.h" #include "PhysicsAPI_Impl.h"
#include "OysterPhysics3D.h" #include "OysterPhysics3D.h"
#include "SimpleRigidBody.h" #include "SimpleRigidBody.h"
#include <BulletWorldImporter\btBulletWorldImporter.h>
#include <codecvt>
using namespace ::Oyster; using namespace ::Oyster;
using namespace ::Oyster::Physics; using namespace ::Oyster::Physics;
@ -92,8 +95,8 @@ ICustomBody* API_Impl::AddCollisionSphere(float radius, ::Oyster::Math::Float4 r
state.centerPos = position; state.centerPos = position;
state.reach = Float3(radius, radius, radius); state.reach = Float3(radius, radius, radius);
state.dynamicFrictionCoeff = 0.5f; state.dynamicFrictionCoeff = dynamicFriction;
state.staticFrictionCoeff = 0.5f; state.staticFrictionCoeff = staticFriction;
state.quaternion = Quaternion(Float3(rotation.xyz), rotation.w); state.quaternion = Quaternion(Float3(rotation.xyz), rotation.w);
state.mass = mass; state.mass = mass;
@ -131,8 +134,8 @@ ICustomBody* API_Impl::AddCollisionBox(Float3 halfSize, ::Oyster::Math::Float4 r
state.centerPos = position; state.centerPos = position;
state.reach = halfSize; state.reach = halfSize;
state.dynamicFrictionCoeff = 0.5f; state.dynamicFrictionCoeff = dynamicFriction;
state.staticFrictionCoeff = 0.5f; state.staticFrictionCoeff = staticFriction;
state.quaternion = Quaternion(Float3(rotation.xyz), rotation.w); state.quaternion = Quaternion(Float3(rotation.xyz), rotation.w);
state.mass = mass; state.mass = mass;
@ -170,8 +173,8 @@ ICustomBody* API_Impl::AddCollisionCylinder(::Oyster::Math::Float3 halfSize, ::O
state.centerPos = position; state.centerPos = position;
state.reach = halfSize; state.reach = halfSize;
state.dynamicFrictionCoeff = 0.5f; state.dynamicFrictionCoeff = dynamicFriction;
state.staticFrictionCoeff = 0.5f; state.staticFrictionCoeff = staticFriction;
state.quaternion = Quaternion(Float3(rotation.xyz), rotation.w); state.quaternion = Quaternion(Float3(rotation.xyz), rotation.w);
state.mass = mass; state.mass = mass;
@ -211,8 +214,55 @@ ICustomBody* API_Impl::AddCharacter(::Oyster::Math::Float height, ::Oyster::Math
state.centerPos = position; state.centerPos = position;
state.reach = Float3(radius, height, radius); state.reach = Float3(radius, height, radius);
state.dynamicFrictionCoeff = 0.5f; state.dynamicFrictionCoeff = dynamicFriction;
state.staticFrictionCoeff = 0.5f; 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<wchar_t> convert_typeX;
std::wstring_convert<convert_typeX, wchar_t> 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.quaternion = Quaternion(Float3(rotation.xyz), rotation.w);
state.mass = mass; state.mass = mass;

View File

@ -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* 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 SetTimeStep(float timeStep);
void UpdateWorld(); void UpdateWorld();

View File

@ -300,11 +300,13 @@ Float4x4 SimpleRigidBody::GetView( const ::Oyster::Math::Float3 &offset ) const
Float3 SimpleRigidBody::GetGravity() const Float3 SimpleRigidBody::GetGravity() const
{ {
return this->rigidBody->getGravity(); btVector3 gravity = this->rigidBody->getGravity();
return Float3(gravity.x(), gravity.y(), gravity.z());
} }
Float3 SimpleRigidBody::GetLinearVelocity() const Float3 SimpleRigidBody::GetLinearVelocity() const
{ {
return this->rigidBody->getLinearVelocity(); btVector3 linearVelocity = this->rigidBody->getLinearVelocity();
return Float3(linearVelocity.x(), linearVelocity.y(), linearVelocity.z());
} }

View File

@ -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* 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 SetTimeStep(float timeStep) = 0;
virtual void UpdateWorld() = 0; virtual void UpdateWorld() = 0;

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.