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

This commit is contained in:
Pontus Fransson 2014-02-12 15:12:28 +01:00
commit 7a218c61d8
32 changed files with 684 additions and 244 deletions

View File

@ -4,7 +4,9 @@
#include "NetworkClient.h" #include "NetworkClient.h"
#include "Camera.h" #include "Camera.h"
#include <GameServerAPI.h> #include <GameServerAPI.h>
#include "LevelLoader\ObjectDefines.h"
using namespace GameLogic;
using namespace DanBias::Client; using namespace DanBias::Client;
using namespace Oyster::Math; using namespace Oyster::Math;
struct GameState::myData struct GameState::myData
@ -78,7 +80,7 @@ GameState::gameStateState GameState::LoadGame()
//LoadModels("3bana.bias"); //LoadModels("3bana.bias");
// hardcoded objects // hardcoded objects
LoadModels(); LoadModels("C:/Users/Sam/Documents/GitHub/Danbias/Bin/Content/worlds/ccc.bias");
Float3 startPos = Float3(0,0,20.0f); Float3 startPos = Float3(0,0,20.0f);
InitCamera(startPos); InitCamera(startPos);
return gameStateState_playing; return gameStateState_playing;
@ -200,9 +202,9 @@ bool GameState::LoadModels(std::string mapFile)
modelData.modelPath.assign(staticObjData->ModelFile.begin(), staticObjData->ModelFile.end()); modelData.modelPath.assign(staticObjData->ModelFile.begin(), staticObjData->ModelFile.end());
modelData.visible = true; modelData.visible = true;
//modelData.position = ; modelData.position = staticObjData->position;
//modelData.rotation = Oyster::Math::Quaternion(Oyster::Math::Float3(2,2,-2), 1); modelData.rotation = Oyster::Math::Quaternion(Oyster::Math::Float3(staticObjData->rotation), staticObjData->rotation[3]);
//modelData.scale = Oyster::Math::Float3(2,2,2); modelData.scale = staticObjData->scale;
modelData.id = modelId++; modelData.id = modelId++;
this->staticObjects.Push(new C_StaticObj()); this->staticObjects.Push(new C_StaticObj());
@ -212,11 +214,11 @@ bool GameState::LoadModels(std::string mapFile)
case GameLogic::ObjectType::ObjectType_Dynamic: case GameLogic::ObjectType::ObjectType_Dynamic:
{ {
GameLogic::ObjectHeader* dynamicObjData = ((GameLogic::ObjectHeader*)obj); GameLogic::ObjectHeader* dynamicObjData = ((GameLogic::ObjectHeader*)obj);
//modelData.position = ;
//modelData.rotation = Oyster::Math::Quaternion(Oyster::Math::Float3(2,2,-2), 1);
//modelData.scale = Oyster::Math::Float3(2,2,2);
modelData.modelPath.assign(dynamicObjData->ModelFile.begin(), dynamicObjData->ModelFile.end()); modelData.modelPath.assign(dynamicObjData->ModelFile.begin(), dynamicObjData->ModelFile.end());
modelData.visible = true; modelData.visible = true;
modelData.position = dynamicObjData->position;
modelData.rotation = Oyster::Math::Quaternion(Oyster::Math::Float3(dynamicObjData->rotation), dynamicObjData->rotation[3]);
modelData.scale = dynamicObjData->scale;
modelData.id = modelId++; modelData.id = modelId++;
this->dynamicObjects.Push(new C_DynamicObj()); this->dynamicObjects.Push(new C_DynamicObj());
@ -230,8 +232,8 @@ bool GameState::LoadModels(std::string mapFile)
if(lightData->lightType == GameLogic::LightType_PointLight) if(lightData->lightType == GameLogic::LightType_PointLight)
{ {
Oyster::Graphics::Definitions::Pointlight plight; Oyster::Graphics::Definitions::Pointlight plight;
plight.Pos = ((GameLogic::PointLight*)lightData)->position; plight.Pos = ((GameLogic::BasicLight*)lightData)->position;
plight.Color = lightData->diffuseColor; plight.Color = lightData->color;
plight.Radius = 100; plight.Radius = 100;
plight.Bright = 0.9f; plight.Bright = 0.9f;
Oyster::Graphics::API::AddLight(plight); Oyster::Graphics::API::AddLight(plight);
@ -561,6 +563,7 @@ void GameState::Protocol( ObjPos* pos )
if(dynamicObjects[i]->GetId() == myId) // playerobj if(dynamicObjects[i]->GetId() == myId) // playerobj
{ {
Float3 pos = dynamicObjects[i]->getPos(); Float3 pos = dynamicObjects[i]->getPos();
Float3 up = dynamicObjects[i]->getWorld().v[1]; Float3 up = dynamicObjects[i]->getWorld().v[1];
Float3 objForward = dynamicObjects[i]->getWorld().v[2]; Float3 objForward = dynamicObjects[i]->getWorld().v[2];

View File

@ -17,7 +17,14 @@ struct LevelLoader::PrivData
LevelLoader::LevelLoader() LevelLoader::LevelLoader()
: pData(new PrivData) : pData(new PrivData)
{ {
pData->folderPath = "Standard path"; //standard path
pData->folderPath = "";
}
LevelLoader::LevelLoader(std::string folderPath)
: pData(new PrivData)
{
pData->folderPath = folderPath;
} }
LevelLoader::~LevelLoader() LevelLoader::~LevelLoader()
@ -26,10 +33,20 @@ LevelLoader::~LevelLoader()
std::vector<Utility::DynamicMemory::SmartPointer<ObjectTypeHeader>> LevelLoader::LoadLevel(std::string fileName) std::vector<Utility::DynamicMemory::SmartPointer<ObjectTypeHeader>> LevelLoader::LoadLevel(std::string fileName)
{ {
return pData->parser.Parse(fileName); return pData->parser.Parse(pData->folderPath + fileName);
} }
LevelMetaData LevelLoader::LoadLevelHeader(std::string fileName) LevelMetaData LevelLoader::LoadLevelHeader(std::string fileName)
{ {
return pData->parser.ParseHeader(fileName); return pData->parser.ParseHeader(pData->folderPath + fileName);
}
std::string LevelLoader::GetFolderPath()
{
return this->pData->folderPath;
}
void LevelLoader::SetFolderPath(std::string folderPath)
{
} }

View File

@ -17,11 +17,15 @@ namespace GameLogic
public: public:
LevelLoader(); LevelLoader();
/***********************************************************
* Lets you set the standard folderpath for the levels
********************************************************/
LevelLoader(std::string folderPath);
~LevelLoader(); ~LevelLoader();
/******************************************************** /********************************************************
* Loads the level and objects from file. * Loads the level and objects from file.
* @param fileName: Path to the level-file that you want to load. * @param fileName: Path/name to the level-file that you want to load.
* @return: Returns all structs with objects and information about the level. * @return: Returns all structs with objects and information about the level.
********************************************************/ ********************************************************/
std::vector<Utility::DynamicMemory::SmartPointer<ObjectTypeHeader>> LoadLevel(std::string fileName); std::vector<Utility::DynamicMemory::SmartPointer<ObjectTypeHeader>> LoadLevel(std::string fileName);
@ -33,6 +37,16 @@ namespace GameLogic
********************************************************/ ********************************************************/
LevelMetaData LoadLevelHeader(std::string fileName); //. LevelMetaData LoadLevelHeader(std::string fileName); //.
/***********************************************************
* @return: Returns the current standard folder path
********************************************************/
std::string GetFolderPath();
/***********************************************************
* Sets the standard folder path
********************************************************/
void SetFolderPath(std::string folderPath);
private: private:
struct PrivData; struct PrivData;
Utility::DynamicMemory::SmartPointer<PrivData> pData; Utility::DynamicMemory::SmartPointer<PrivData> pData;

View File

@ -1,3 +1,7 @@
/////////////////////////////////////
// Created by Pontus Fransson 2013 //
/////////////////////////////////////
#include "LevelParser.h" #include "LevelParser.h"
#include "Loader.h" #include "Loader.h"
@ -9,7 +13,7 @@ using namespace Utility::DynamicMemory;
LevelParser::LevelParser() LevelParser::LevelParser()
{ {
formatVersion.formatVersionMajor = 1; formatVersion.formatVersionMajor = 3;
formatVersion.formatVersionMinor = 0; formatVersion.formatVersionMinor = 0;
} }
@ -21,6 +25,7 @@ std::vector<SmartPointer<ObjectTypeHeader>> LevelParser::Parse(std::string filen
{ {
int bufferSize = 0; int bufferSize = 0;
int counter = 0; int counter = 0;
bool loadCgf;
std::vector<SmartPointer<ObjectTypeHeader>> objects; std::vector<SmartPointer<ObjectTypeHeader>> objects;
@ -29,35 +34,117 @@ std::vector<SmartPointer<ObjectTypeHeader>> LevelParser::Parse(std::string filen
char* buffer = (char*)loader.LoadFile(filename.c_str(), bufferSize); char* buffer = (char*)loader.LoadFile(filename.c_str(), bufferSize);
//Read format version //Read format version
FormatVersion levelFormatVersion; LevelLoaderInternal::FormatVersion levelFormatVersion;
ParseObject(&buffer[counter], &levelFormatVersion, sizeof(levelFormatVersion)); ParseObject(&buffer[counter], &levelFormatVersion, sizeof(levelFormatVersion));
counter += sizeof(levelFormatVersion); counter += sizeof(levelFormatVersion);
if(this->formatVersion != levelFormatVersion) if(this->formatVersion != levelFormatVersion)
{ {
//Do something if it's not the same version //Returns an empty vector, because it will most likely fail to read the level format.
return objects;
} }
while(counter < bufferSize) while(counter < bufferSize)
{ {
loadCgf = true;
//Get typeID //Get typeID
ObjectTypeHeader typeID; ObjectType typeID;
ParseObject(&buffer[counter], &typeID, sizeof(typeID)); ParseObject(&buffer[counter], &typeID, sizeof(typeID));
switch((int)typeID.typeID) switch((int)typeID)
{ {
case ObjectType_LevelMetaData: case ObjectType_LevelMetaData:
{ {
LevelMetaData* header = new LevelMetaData; SmartPointer<ObjectTypeHeader> header = new LevelMetaData;
ParseLevelMetaData(&buffer[counter], *header, counter); ParseLevelMetaData(&buffer[counter], *(LevelMetaData*)header.Get(), counter);
objects.push_back(header); objects.push_back(header);
break; break;
} }
//This is by design, static and dynamic is using the same converter. Do not add anything inbetween them. //This is by design, static and dynamic is using the same converter. Do not add anything inbetween them.
//Unless they are changed to not be the same.
case ObjectType_Static: case ObjectType_Dynamic: case ObjectType_Static: case ObjectType_Dynamic:
{ {
ObjectHeader* header = new ObjectHeader; //Get specialType.
ParseObject(&buffer[counter], *header, counter); ObjectSpecialType specialType;
objects.push_back(header); ParseObject(&buffer[counter+4], &specialType, sizeof(typeID));
switch(specialType)
{
//there is no difference when parsing these specialTypes.
case ObjectSpecialType_CrystalShard:
case ObjectSpecialType_CrystalFormation:
case ObjectSpecialType_Spike:
case ObjectSpecialType_SpikeBox:
case ObjectSpecialType_RedExplosiveBox:
case ObjectSpecialType_StandarsBox:
case ObjectSpecialType_Stone:
case ObjectSpecialType_Building:
{
ObjectHeader* header = new ObjectHeader;
ParseObject(&buffer[counter], *header, counter, loadCgf);
objects.push_back(header);
break;
}
case ObjectSpecialType_JumpPad:
{
JumpPadAttributes* header = new JumpPadAttributes;
ParseObject(&buffer[counter], *header, counter, loadCgf);
//Read the spec
ParseObject(&buffer[counter], header->direction, 16);
counter += 16;
objects.push_back(header);
break;
}
case ObjectSpecialType_Portal:
{
PortalAttributes* header = new PortalAttributes;
ParseObject(&buffer[counter], *header, counter, loadCgf);
ParseObject(&buffer[counter], header->destination, 12);
counter += 12;
objects.push_back(header);
break;
}
case ObjectSpecialType_World:
{
WorldAttributes* header = new WorldAttributes;
ParseObject(&buffer[counter], *header, counter, loadCgf);
ParseObject(&buffer[counter], &header->worldSize, 8);
counter += 8;
objects.push_back(header);
break;
}
case ObjectSpecialType_Sky:
{
loadCgf = false;
SkyAttributes* header = new SkyAttributes;
ParseObject(&buffer[counter], *header, counter, loadCgf);
ParseObject(&buffer[counter], &header->skySize, 4);
counter += 4;
objects.push_back(header);
break;
}
case ObjectSpecialType_SpawnPoint:
{
loadCgf = false;
ObjectHeader* header = new ObjectHeader;
ParseObject(&buffer[counter], *header, counter, loadCgf);
}
default:
//Couldn't find specialType
break;
}
break; break;
} }
@ -68,7 +155,12 @@ std::vector<SmartPointer<ObjectTypeHeader>> LevelParser::Parse(std::string filen
//Get Light type //Get Light type
ParseObject(&buffer[counter+4], &lightType, sizeof(lightType)); ParseObject(&buffer[counter+4], &lightType, sizeof(lightType));
switch(lightType) //We only support PointLight for now.
BasicLight* header = new BasicLight;
ParseObject(&buffer[counter], header, sizeof(*header));
counter += sizeof(*header);
objects.push_back(header);
/*switch(lightType)
{ {
case LightType_PointLight: case LightType_PointLight:
{ {
@ -98,7 +190,7 @@ std::vector<SmartPointer<ObjectTypeHeader>> LevelParser::Parse(std::string filen
//Undefined LightType. //Undefined LightType.
break; break;
} }
break; break;*/
} }
default: default:
//Couldn't find typeID. FAIL!!!!!! //Couldn't find typeID. FAIL!!!!!!
@ -123,21 +215,25 @@ LevelMetaData LevelParser::ParseHeader(std::string filename)
char* buffer = (char*)loader.LoadFile(filename.c_str(), bufferSize); char* buffer = (char*)loader.LoadFile(filename.c_str(), bufferSize);
//Read format version //Read format version
FormatVersion levelFormatVersion; LevelLoaderInternal::FormatVersion levelFormatVersion;
ParseObject(&buffer[counter], &levelFormatVersion, sizeof(formatVersion)); ParseObject(&buffer[counter], &levelFormatVersion, sizeof(formatVersion));
counter += sizeof(levelFormatVersion); counter += sizeof(levelFormatVersion);
if(this->formatVersion != levelFormatVersion) if(this->formatVersion != levelFormatVersion)
{ {
//Do something if it's not the same version //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. //Find the header in the returned string.
while(counter < bufferSize) while(counter < bufferSize)
{ {
ObjectTypeHeader typeID; ObjectType typeID;
ParseObject(&buffer[counter], &typeID, sizeof(typeID)); ParseObject(&buffer[counter], &typeID, sizeof(typeID));
switch(typeID.typeID) switch(typeID)
{ {
case ObjectType_LevelMetaData: case ObjectType_LevelMetaData:
ParseLevelMetaData(&buffer[counter], levelHeader, counter); ParseLevelMetaData(&buffer[counter], levelHeader, counter);
@ -148,7 +244,19 @@ LevelMetaData LevelParser::ParseHeader(std::string filename)
case ObjectType_Static: case ObjectType_Dynamic: case ObjectType_Static: case ObjectType_Dynamic:
{ {
ObjectHeader header; ObjectHeader header;
ParseObject(&buffer[counter], header, counter); ParseObject(&buffer[counter], &header, counter);
switch(header.specialTypeID)
{
case ObjectSpecialType_JumpPad:
counter += sizeof(16);
break;
case ObjectSpecialType_Portal:
counter += sizeof(12);
break;
default:
break;
}
break; break;
} }
@ -157,6 +265,9 @@ LevelMetaData LevelParser::ParseHeader(std::string filename)
LightType lightType; LightType lightType;
ParseObject(&buffer[counter+4], &lightType, sizeof(lightType)); ParseObject(&buffer[counter+4], &lightType, sizeof(lightType));
//We only support pointlight for now.
counter += sizeof(BasicLight);
/*
switch(lightType) switch(lightType)
{ {
case LightType_PointLight: case LightType_PointLight:
@ -177,7 +288,7 @@ LevelMetaData LevelParser::ParseHeader(std::string filename)
default: default:
//Undefined LightType. //Undefined LightType.
break; break;
} }*/
} }
default: default:

View File

@ -23,7 +23,7 @@ namespace GameLogic
LevelMetaData ParseHeader(std::string filename); LevelMetaData ParseHeader(std::string filename);
private: private:
FormatVersion formatVersion; LevelLoaderInternal::FormatVersion formatVersion;
}; };
} }

View File

@ -23,31 +23,45 @@ namespace GameLogic
ObjectType_Unknown = -1 ObjectType_Unknown = -1
}; };
enum UsePhysics enum ObjectSpecialType
{ {
UsePhysics_UseFullPhysics, ObjectSpecialType_None,
UsePhysics_IgnoreGravity, ObjectSpecialType_Sky,
UsePhysics_IgnorePhysics, ObjectSpecialType_World, //Always the main celestial body
UsePhysics_IgnoreCollision, ObjectSpecialType_Building,
ObjectSpecialType_Stone,
ObjectSpecialType_StandarsBox,
ObjectSpecialType_RedExplosiveBox,
ObjectSpecialType_SpikeBox,
ObjectSpecialType_Spike,
ObjectSpecialType_CrystalFormation,
ObjectSpecialType_CrystalShard,
ObjectSpecialType_JumpPad,
ObjectSpecialType_Portal,
ObjectSpecialType_SpawnPoint,
ObjectSpecialType_Player,
UsePhysics_Count,
UsePhysics_Unknown = -1 ObjectSpecialType_Count,
ObjectSpecialType_Unknown = -1
}; };
enum CollisionGeometryType enum CollisionGeometryType
{ {
CollisionGeometryType_Box, CollisionGeometryType_Box,
CollisionGeometryType_Sphere, CollisionGeometryType_Sphere,
CollisionGeometryType_Cylinder,
CollisionGeometryType_Count, CollisionGeometryType_Count,
CollisionGeometryType_Unknown = -1 CollisionGeometryType_Unknown = -1
}; };
//Only supports Pointlight right now.
enum LightType enum LightType
{ {
LightType_PointLight, LightType_PointLight,
LightType_DirectionalLight, //LightType_DirectionalLight,
LightType_SpotLight, //LightType_SpotLight,
LightType_Count, LightType_Count,
LightType_Unknown = -1 LightType_Unknown = -1
@ -80,38 +94,84 @@ namespace GameLogic
/************************************ /************************************
Structs Structs
*************************************/ *************************************/
namespace LevelLoaderInternal
struct FormatVersion
{ {
unsigned int formatVersionMajor; struct FormatVersion
unsigned int formatVersionMinor;
bool operator ==(const FormatVersion& obj)
{ {
return (this->formatVersionMajor != obj.formatVersionMajor && this->formatVersionMinor != obj.formatVersionMinor); unsigned int formatVersionMajor;
} unsigned int formatVersionMinor;
bool operator !=(const FormatVersion& obj) FormatVersion()
{ : formatVersionMajor(0), formatVersionMinor(0)
return !(*this == obj); {}
}
}; FormatVersion(unsigned int major, unsigned int minor)
: formatVersionMajor(major), formatVersionMinor(minor)
{}
bool operator ==(const FormatVersion& obj)
{
return (this->formatVersionMajor == obj.formatVersionMajor && this->formatVersionMinor == obj.formatVersionMinor);
}
bool operator !=(const FormatVersion& obj)
{
return !(*this == obj);
}
};
}
struct ObjectTypeHeader struct ObjectTypeHeader
{ {
ObjectType typeID; ObjectType typeID;
//Unless this is here the object destructor wont be called.
virtual ~ObjectTypeHeader(){}
}; };
struct PhysicsObject namespace LevelLoaderInternal
{ {
UsePhysics usePhysics; const FormatVersion boundingVolumeVersion(2, 0);
float mass;
float inertiaMagnitude[3]; struct BoundingVolumeBase
float inertiaRotation[3]; {
float frictionCoeffStatic; CollisionGeometryType geoType;
float frictionCoeffDynamic; float position[3];
CollisionGeometryType geometryType; float rotation[4];
}; float frictionCoeffStatic;
float frictionCoeffDynamic;
float restitutionCoeff;
float mass;
};
struct BoundingVolumeBox : public BoundingVolumeBase
{
float size[3];
};
struct BoundingVolumeSphere : public BoundingVolumeBase
{
float radius;
};
struct BoundingVolumeCylinder : public BoundingVolumeBase
{
float length;
float radius;
};
struct BoundingVolume
{
CollisionGeometryType geoType;
union
{
LevelLoaderInternal::BoundingVolumeBox box;
LevelLoaderInternal::BoundingVolumeSphere sphere;
LevelLoaderInternal::BoundingVolumeCylinder cylinder;
};
};
}
struct LevelMetaData : public ObjectTypeHeader struct LevelMetaData : public ObjectTypeHeader
{ {
@ -123,21 +183,56 @@ namespace GameLogic
WorldSize worldSize; WorldSize worldSize;
std::string overviewPicturePath; std::string overviewPicturePath;
std::vector<GameMode> gameModesSupported; std::vector<GameMode> gameModesSupported;
virtual ~LevelMetaData(){}
}; };
struct ObjectHeader : public ObjectTypeHeader, public PhysicsObject struct ObjectHeader : public ObjectTypeHeader
{ {
//Special type id for special objects: portal, jumppad, exploding objects, etc.
ObjectSpecialType specialTypeID;
//Model, //Model,
std::string ModelFile; std::string ModelFile;
//Position //Position
float position[3]; float position[3];
//Rotation //Rotation Quaternion
float rotation[3]; float rotation[4];
float angle;
//Scale //Scale
float scale[3]; float scale[3];
::GameLogic::LevelLoaderInternal::BoundingVolume boundingVolume;
virtual ~ObjectHeader(){}
}; };
/************************************
Special objects
*************************************/
struct JumpPadAttributes : public ObjectHeader
{
float direction[3];
float power;
};
struct PortalAttributes : public ObjectHeader
{
float destination[3];
};
struct WorldAttributes : public ObjectHeader
{
float worldSize;
float atmoSphereSize;
};
struct SkyAttributes : public ObjectHeader
{
float skySize;
};
/************************************ /************************************
Lights Lights
@ -145,12 +240,13 @@ namespace GameLogic
struct BasicLight : public ObjectTypeHeader struct BasicLight : public ObjectTypeHeader
{ {
LightType lightType; LightType lightType; //Is not used right now
float ambientColor[3]; float color[3];
float diffuseColor[3]; float position[3];
float specularColor[3]; float raduis;
float intensity;
}; };
/* We only support pointlight right now.
struct PointLight : public BasicLight struct PointLight : public BasicLight
{ {
float position[3]; float position[3];
@ -166,7 +262,7 @@ namespace GameLogic
float direction[3]; float direction[3];
float range; float range;
float attenuation[3]; float attenuation[3];
}; };*/
} }
#endif #endif

View File

@ -3,10 +3,9 @@
////////////////////////////////// //////////////////////////////////
#include "ParseFunctions.h" #include "ParseFunctions.h"
#include "../../../../Misc/Packing/Packing.h" #include "Loader.h"
#include <string> #include <string>
using namespace Oyster::Packing;
using namespace GameLogic::LevelFileLoader; using namespace GameLogic::LevelFileLoader;
using namespace GameLogic; using namespace GameLogic;
using namespace std; using namespace std;
@ -15,12 +14,13 @@ namespace GameLogic
{ {
namespace LevelFileLoader namespace LevelFileLoader
{ {
//can parse any struct if the struct doesnt contain strings or char[]
void ParseObject(char* buffer, void *header, int size) void ParseObject(char* buffer, void *header, int size)
{ {
memcpy(header, buffer, size); memcpy(header, buffer, size);
} }
void ParseObject(char* buffer, ObjectHeader& header, int& size) void ParseObject(char* buffer, ObjectHeader& header, int& size, bool loadCgf)
{ {
char tempName[128]; char tempName[128];
unsigned int tempSize = 0; unsigned int tempSize = 0;
@ -29,6 +29,9 @@ namespace GameLogic
memcpy(&header.typeID, &buffer[start], 4); memcpy(&header.typeID, &buffer[start], 4);
start += 4; start += 4;
memcpy(&header.specialTypeID, &buffer[start], 4);
start += 4;
memcpy(&tempSize, &buffer[start], 4); memcpy(&tempSize, &buffer[start], 4);
start += 4; start += 4;
@ -36,13 +39,29 @@ namespace GameLogic
header.ModelFile.assign(&tempName[0], &tempName[tempSize]); header.ModelFile.assign(&tempName[0], &tempName[tempSize]);
start += tempSize; start += tempSize;
//The reset of the object struct
//3 float[3], 1 float //3 float[3], 1 float
memcpy(&header.position, &buffer[start], 40); memcpy(&header.position, &buffer[start], 40);
start += 40; start += 40;
//2 float[3], 3 float, 2 uint //if loadCgf : Read path for bounding volume
memcpy(&header.usePhysics, &buffer[start], 44); if(loadCgf)
start += 44; {
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; size += start;
} }
@ -107,5 +126,57 @@ namespace GameLogic
size += start; size += start;
} }
void ParseBoundingVolume(char* buffer, LevelLoaderInternal::BoundingVolume& volume, int &size)
{
int start = 0;
int tempSize = 0;
char tempName[128];
memcpy(&tempSize, &buffer[start], 4);
start += 4;
memcpy(&tempName, &buffer[start], tempSize);
string fileName;
fileName.assign(&tempName[0], &tempName[tempSize]);
start += tempSize;
size += start;
//Läs in filen.
int fileLength = 0;
Loader loader;
char* buf = loader.LoadFile("C:/Users/Sam/Documents/GitHub/Danbias/Bin/Content/worlds/cgf/"+ fileName, fileLength);
start = 0;
LevelLoaderInternal::FormatVersion version;
memcpy(&version, &buf[0], sizeof(version));
start += 4;
memcpy(&volume.geoType, &buf[start], sizeof(volume.geoType));
start += sizeof(volume.geoType);
switch(volume.geoType)
{
case CollisionGeometryType_Box:
memcpy(&volume.box, &buf[start], sizeof(volume.box));
start += sizeof(volume.box);
break;
case CollisionGeometryType_Sphere:
memcpy(&volume.sphere, &buf[start], sizeof(volume.sphere));
start += sizeof(volume.sphere);
break;
case CollisionGeometryType_Cylinder:
memcpy(&volume.cylinder, &buf[start], sizeof(volume.cylinder));
start += sizeof(volume.cylinder);
break;
default:
break;
}
}
} }
} }

View File

@ -17,10 +17,10 @@ namespace GameLogic
Or the current index that is being used to parse the entire file (if it is sent by reference) this means you have to increase size with the appropiate size after you have copied. Or the current index that is being used to parse the entire file (if it is sent by reference) this means you have to increase size with the appropiate size after you have copied.
*/ */
void ParseObject(char* buffer, void *header, int size); void ParseObject(char* buffer, void *header, int size);
void ParseObject(char* buffer, ObjectHeader& header, int& size); void ParseObject(char* buffer, ObjectHeader& header, int& size , bool loadCgf);
void ParseLevelMetaData(char* buffer, LevelMetaData &header, int &size); void ParseLevelMetaData(char* buffer, LevelMetaData &header, int &size);
void ParseBoundingVolume(char* buffer, LevelLoaderInternal::BoundingVolume& volume, int &size);
} }
} }

View File

@ -87,7 +87,7 @@ void AttatchmentMassDriver::ForcePush(const GameLogic::WEAPON_FIRE &usage, float
if(hasObject) if(hasObject)
{ {
Oyster::Physics::API::Instance().ReleaseFromLimbo(heldObject); Oyster::Physics::API::Instance().ReleaseFromLimbo(heldObject);
pushForce = Oyster::Math::Float4(this->owner->GetLookDir()) * (100); pushForce = Oyster::Math::Float4(this->owner->GetLookDir()) * (400);
heldObject->ApplyImpulse((Oyster::Math::Float3)pushForce); heldObject->ApplyImpulse((Oyster::Math::Float3)pushForce);
hasObject = false; hasObject = false;
@ -100,7 +100,7 @@ void AttatchmentMassDriver::ForcePush(const GameLogic::WEAPON_FIRE &usage, float
Oyster::Math::Float lenght = 10; Oyster::Math::Float lenght = 10;
Oyster::Math::Float3 pos = owner->GetRigidBody()->GetState().centerPos; Oyster::Math::Float3 pos = owner->GetRigidBody()->GetState().centerPos;
pushForce = Oyster::Math::Float4(this->owner->GetLookDir()) * (100); pushForce = Oyster::Math::Float4(this->owner->GetLookDir()) * (400);
Oyster::Collision3D::Cone *hitCone = new Oyster::Collision3D::Cone(lenght,pos,(Oyster::Math::Float4)owner->GetRigidBody()->GetState().quaternion,radius); Oyster::Collision3D::Cone *hitCone = new Oyster::Collision3D::Cone(lenght,pos,(Oyster::Math::Float4)owner->GetRigidBody()->GetState().quaternion,radius);

View File

@ -24,19 +24,14 @@ using namespace GameLogic;
switch (realObj->GetObjectType()) switch (realObj->GetObjectType())
{ {
case OBJECT_TYPE::OBJECT_TYPE_GENERIC: case ObjectSpecialType_StandarsBox:
PlayerVObject(*player,*realObj, kineticEnergyLoss); PlayerVObject(*player,*realObj, kineticEnergyLoss);
//return Physics::ICustomBody::SubscriptMessage_none; //return Physics::ICustomBody::SubscriptMessage_none;
break; break;
case ObjectSpecialType_Player:
case OBJECT_TYPE::OBJECT_TYPE_BOX:
PlayerVObject(*player,*realObj, kineticEnergyLoss);
//return Physics::ICustomBody::SubscriptMessage_none; //return Physics::ICustomBody::SubscriptMessage_none;
break; break;
case OBJECT_TYPE::OBJECT_TYPE_PLAYER: case ObjectSpecialType_World:
//return Physics::ICustomBody::SubscriptMessage_none;
break;
case OBJECT_TYPE::OBJECT_TYPE_WORLD:
PlayerVObject(*player,*realObj, kineticEnergyLoss); PlayerVObject(*player,*realObj, kineticEnergyLoss);
//player->playerState = PLAYER_STATE::PLAYER_STATE_WALKING; //player->playerState = PLAYER_STATE::PLAYER_STATE_WALKING;
break; break;
@ -52,25 +47,21 @@ using namespace GameLogic;
switch (realObj->GetObjectType()) switch (realObj->GetObjectType())
{ {
case OBJECT_TYPE::OBJECT_TYPE_GENERIC: case ObjectSpecialType_Generic:
break; break;
case OBJECT_TYPE::OBJECT_TYPE_BOX: case ObjectSpecialType_StandarsBox:
break; break;
case OBJECT_TYPE::OBJECT_TYPE_PLAYER: case ObjectSpecialType_Player:
SendObjectFlying(*obj, jumpPad->pushForce); SendObjectFlying(*obj, jumpPad->pushForce);
break; break;
case OBJECT_TYPE::OBJECT_TYPE_WORLD: case ObjectSpecialType_World:
break; break;
} }
} }
void SendObjectFlying(Oyster::Physics::ICustomBody &obj, Oyster::Math::Float3 force) void SendObjectFlying(Oyster::Physics::ICustomBody &obj, Oyster::Math::Float3 force)
{ {
Oyster::Physics::ICustomBody::State state; obj.ApplyImpulse(force);
state = obj.GetState();
//state.ApplyLinearImpulse(force);
obj.SetState(state);
} }
@ -115,7 +106,7 @@ using namespace GameLogic;
Object *realObj = (Object*)obj->GetCustomTag(); Object *realObj = (Object*)obj->GetCustomTag();
if(realObj->GetObjectType() == OBJECT_TYPE_PLAYER || realObj->GetObjectType() == OBJECT_TYPE_WORLD) if(realObj->GetObjectType() == ObjectSpecialType_Player || realObj->GetObjectType() == ObjectSpecialType_World)
return; return;
obj->ApplyImpulse(((forcePushData*)(args))->pushForce); obj->ApplyImpulse(((forcePushData*)(args))->pushForce);
@ -138,7 +129,7 @@ using namespace GameLogic;
switch(realObj->GetObjectType()) switch(realObj->GetObjectType())
{ {
case OBJECT_TYPE::OBJECT_TYPE_BOX: case ObjectSpecialType_StandarsBox:
//move obj to limbo in physics to make sure it wont collide with anything //move obj to limbo in physics to make sure it wont collide with anything
// Oyster::Physics::API::Instance().MoveToLimbo(obj); // Oyster::Physics::API::Instance().MoveToLimbo(obj);
weapon->heldObject = obj; //weapon now holds the object weapon->heldObject = obj; //weapon now holds the object

View File

@ -9,28 +9,28 @@ DynamicObject::DynamicObject()
{ {
} }
DynamicObject::DynamicObject(OBJECT_TYPE type) DynamicObject::DynamicObject(ObjectSpecialType type)
:Object(type) :Object(type)
{ {
} }
DynamicObject::DynamicObject(Oyster::Physics::ICustomBody *rigidBody, OBJECT_TYPE type) DynamicObject::DynamicObject(Oyster::Physics::ICustomBody *rigidBody, ObjectSpecialType type)
:Object(rigidBody,type) :Object(rigidBody,type)
{ {
} }
DynamicObject::DynamicObject( void* collisionFuncAfter, OBJECT_TYPE type) DynamicObject::DynamicObject( void* collisionFuncAfter, ObjectSpecialType type)
:Object(collisionFuncAfter,type) :Object(collisionFuncAfter,type)
{ {
} }
DynamicObject::DynamicObject(Oyster::Physics::ICustomBody *rigidBody , void* collisionFuncAfter, OBJECT_TYPE type) DynamicObject::DynamicObject(Oyster::Physics::ICustomBody *rigidBody , void* collisionFuncAfter, ObjectSpecialType type)
:Object(rigidBody, collisionFuncAfter, type) :Object(rigidBody, collisionFuncAfter, type)
{ {
} }
DynamicObject::DynamicObject(Oyster::Physics::ICustomBody *rigidBody , Oyster::Physics::ICustomBody::SubscriptMessage (*collisionFuncAfter)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), OBJECT_TYPE type) DynamicObject::DynamicObject(Oyster::Physics::ICustomBody *rigidBody , Oyster::Physics::ICustomBody::SubscriptMessage (*collisionFuncAfter)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), ObjectSpecialType type)
:Object(rigidBody, collisionFuncAfter, type) :Object(rigidBody, collisionFuncAfter, type)
{ {

View File

@ -14,11 +14,13 @@ namespace GameLogic
public: public:
DynamicObject(); DynamicObject();
DynamicObject(OBJECT_TYPE type);
DynamicObject(Oyster::Physics::ICustomBody *rigidBody, OBJECT_TYPE type); DynamicObject(ObjectSpecialType type);
DynamicObject( void* collisionFuncAfter, OBJECT_TYPE type); DynamicObject(Oyster::Physics::ICustomBody *rigidBody, ObjectSpecialType type);
DynamicObject(Oyster::Physics::ICustomBody *rigidBody , void* collisionFuncAfter, OBJECT_TYPE type); DynamicObject( void* collisionFuncAfter, ObjectSpecialType type);
DynamicObject(Oyster::Physics::ICustomBody *rigidBody , Oyster::Physics::ICustomBody::SubscriptMessage (*collisionFuncAfter)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), OBJECT_TYPE type); DynamicObject(Oyster::Physics::ICustomBody *rigidBody , void* collisionFuncAfter, ObjectSpecialType type);
DynamicObject(Oyster::Physics::ICustomBody *rigidBody , Oyster::Physics::ICustomBody::SubscriptMessage (*collisionFuncAfter)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), ObjectSpecialType type);
~DynamicObject(void); ~DynamicObject(void);

View File

@ -81,8 +81,8 @@ Game::LevelData* Game::CreateLevel()
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(1000);
//this->level->level->InitiateLevel("3bana.bias"); this->level->level->InitiateLevel("C:/Users/Sam/Documents/GitHub/Danbias/Bin/Content/worlds/ccc.bias");
return this->level; return this->level;
} }

View File

@ -40,8 +40,10 @@ namespace GameLogic
Oyster::Math::Float3 GetScale() override; Oyster::Math::Float3 GetScale() override;
Oyster::Math::Float4x4 GetOrientation() override; Oyster::Math::Float4x4 GetOrientation() override;
int GetID() const override; int GetID() const override;
OBJECT_TYPE GetObjectType() const override;
void Rotate(const Oyster::Math3D::Float3 lookDir, const Oyster::Math3D::Float3 right) override; void Rotate(const Oyster::Math3D::Float3 lookDir, const Oyster::Math3D::Float3 right) override;
ObjectSpecialType GetObjectType() const override;
Player *player; Player *player;
}; };
@ -56,7 +58,7 @@ namespace GameLogic
Oyster::Math::Float3 GetScale() override; Oyster::Math::Float3 GetScale() override;
Oyster::Math::Float4x4 GetOrientation() override; Oyster::Math::Float4x4 GetOrientation() override;
int GetID() const override; int GetID() const override;
OBJECT_TYPE GetObjectType() const override; ObjectSpecialType GetObjectType() const override;
int getNrOfDynamicObj()const override; int getNrOfDynamicObj()const override;
IObjectData* GetObjectAt(int ID) const override; IObjectData* GetObjectAt(int ID) const override;
Level *level; Level *level;

View File

@ -12,6 +12,7 @@
#include "GameLogicDef.h" #include "GameLogicDef.h"
#include "GameLogicStates.h" #include "GameLogicStates.h"
#include <OysterMath.h> #include <OysterMath.h>
#include "LevelLoader\ObjectDefines.h"
namespace GameLogic namespace GameLogic
@ -66,7 +67,7 @@ namespace GameLogic
/** Get the type of the object /** Get the type of the object
* @return The OBJECT_TYPE of the object is returned * @return The OBJECT_TYPE of the object is returned
*/ */
virtual OBJECT_TYPE GetObjectType() const = 0; virtual ObjectSpecialType GetObjectType() const = 0;
}; };
class IPlayerData :public IObjectData class IPlayerData :public IObjectData

View File

@ -21,16 +21,6 @@ namespace GameLogic
PLAYER_STATE_INVALID = 8, PLAYER_STATE_INVALID = 8,
}; };
enum OBJECT_TYPE
{
OBJECT_TYPE_PLAYER = 0,
OBJECT_TYPE_BOX = 1,
OBJECT_TYPE_WORLD = 2,
OBJECT_TYPE_GENERIC = 4,
OBJECT_TYPE_JUMPPAD = 8,
OBJECT_TYPE_UNKNOWN = -1,
};
enum WEAPON_FIRE enum WEAPON_FIRE
{ {
WEAPON_USE_PRIMARY_PRESS = 0, WEAPON_USE_PRIMARY_PRESS = 0,

View File

@ -38,7 +38,7 @@ int Game::LevelData::GetID() const
{ {
return ((IObjectData*)this->level)->GetID(); return ((IObjectData*)this->level)->GetID();
} }
OBJECT_TYPE Game::LevelData::GetObjectType() const ObjectSpecialType Game::LevelData::GetObjectType() const
{ {
return ((IObjectData*)this->level)->GetObjectType(); return ((IObjectData*)this->level)->GetObjectType();
//return OBJECT_TYPE_UNKNOWN; //return OBJECT_TYPE_UNKNOWN;

View File

@ -6,7 +6,9 @@ using namespace GameLogic;
Game::PlayerData::PlayerData() 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(0,603,0);
Oyster::Math::Float3 centerPosition = Oyster::Math::Float3(0,400,0);
Oyster::Math::Float3 size = Oyster::Math::Float3(0.25f,1.0f,0.5f); Oyster::Math::Float3 size = Oyster::Math::Float3(0.25f,1.0f,0.5f);
Oyster::Math::Float mass = 60; Oyster::Math::Float mass = 60;
Oyster::Math::Float restitutionCoeff = 0.5; Oyster::Math::Float restitutionCoeff = 0.5;
@ -18,7 +20,8 @@ Game::PlayerData::PlayerData()
Oyster::Physics::ICustomBody* rigidBody = Oyster::Physics::API::Instance().AddCollisionBox(size, Oyster::Math::Float4(0, 0, 0, 1), centerPosition, mass, 0.5f, 0.8f, 0.6f ); Oyster::Physics::ICustomBody* rigidBody = Oyster::Physics::API::Instance().AddCollisionBox(size, Oyster::Math::Float4(0, 0, 0, 1), centerPosition, mass, 0.5f, 0.8f, 0.6f );
rigidBody->SetAngularFactor(0.0f); rigidBody->SetAngularFactor(0.0f);
//create player with this rigid body //create player with this rigid body
this->player = new Player(rigidBody, Player::PlayerCollision, OBJECT_TYPE::OBJECT_TYPE_PLAYER); this->player = new Player(rigidBody, Player::PlayerCollision, ObjectSpecialType_Player);
this->player->GetRigidBody()->SetCustomTag(this); this->player->GetRigidBody()->SetCustomTag(this);
player->EndFrame(); player->EndFrame();
} }
@ -68,7 +71,7 @@ int Game::PlayerData::GetTeamID() const
return this->player->GetTeamID(); return this->player->GetTeamID();
} }
OBJECT_TYPE Game::PlayerData::GetObjectType() const ObjectSpecialType Game::PlayerData::GetObjectType() const
{ {
return this->player->GetObjectType(); return this->player->GetObjectType();
} }

View File

@ -8,10 +8,10 @@ JumpPad::JumpPad(void)
{ {
} }
JumpPad::JumpPad(Oyster::Physics::ICustomBody *rigidBody, Oyster::Physics::ICustomBody::SubscriptMessage (*collisionFuncAfter)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), OBJECT_TYPE type, Oyster::Math::Float3 pushForce) JumpPad::JumpPad(Oyster::Physics::ICustomBody *rigidBody, void (*collisionFuncAfter)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), ObjectSpecialType type, Oyster::Math::Float3 pushForce)
:StaticObject(rigidBody, collisionFuncAfter, type) :StaticObject(rigidBody, collisionFuncAfter, type)
{ {
this->pushForce = pushForce;
} }

View File

@ -9,8 +9,9 @@ namespace GameLogic
JumpPad(void); JumpPad(void);
JumpPad(Oyster::Physics::ICustomBody *rigidBody JumpPad(Oyster::Physics::ICustomBody *rigidBody
,Oyster::Physics::ICustomBody::SubscriptMessage (*collisionFuncAfter)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss) ,void (*collisionFuncAfter)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss)
,OBJECT_TYPE type, Oyster::Math::Float3 pushForce); ,ObjectSpecialType type, Oyster::Math::Float3 pushForce);
~JumpPad(void); ~JumpPad(void);

View File

@ -53,6 +53,11 @@ void Level::InitiateLevel(std::string levelPath)
int modelCount = 0; int modelCount = 0;
int staticObjCount = 0; int staticObjCount = 0;
int dynamicObjCount = 0; int dynamicObjCount = 0;
Oyster::Math::Float3 rigidWorldPos;
Oyster::Math::Float4 rigidWorldRotation;
float rigidBodyMass;
float rigidBodyRadius;
Oyster::Math::Float3 rigidBodySize;
for (int i = 0; i < objCount; i++) for (int i = 0; i < objCount; i++)
{ {
ObjectTypeHeader* obj = objects.at(i); ObjectTypeHeader* obj = objects.at(i);
@ -73,33 +78,135 @@ void Level::InitiateLevel(std::string levelPath)
//LevelLoaderInternal::BoundingVolumeBase* staticObjPhysicData = ((ObjectHeader*)obj); //LevelLoaderInternal::BoundingVolumeBase* staticObjPhysicData = ((ObjectHeader*)obj);
staticObjData->ModelFile; staticObjData->ModelFile;
ICustomBody* rigidBody_Static; ICustomBody* rigidBody_Static = NULL;
// collision shape // collision shape
// radius, rotation in world, position in world, mass, restitution, static and dynamic friction // radius, rotation in world, position in world, mass, restitution, static and dynamic friction
ICustomBody* rigidBody = API::Instance().AddCollisionSphere(599.2f, Oyster::Math::Float4(0, 0, 0, 1), Oyster::Math::Float3(0, 0, 0), 0, 0.5f, 0.8f, 0.6f); if(staticObjData->boundingVolume.geoType == CollisionGeometryType_Sphere)
{
//offset the rigidPosition from modelspace to worldspace;
rigidWorldPos = (Oyster::Math::Float3)staticObjData->position + (Oyster::Math::Float3)staticObjData->boundingVolume.sphere.position;
//scales the position so the collision geomentry is in the right place
rigidWorldPos = rigidWorldPos * staticObjData->scale;
//offset the rigidRotation from modelspace to worldspace;
rigidWorldRotation = (Oyster::Math::Float4)staticObjData->rotation + (Oyster::Math::Float4)staticObjData->boundingVolume.sphere.rotation;
//mass scaled
rigidBodyMass = staticObjData->scale[0] * staticObjData->scale[1] * staticObjData->scale[2] * staticObjData->boundingVolume.sphere.mass;
//Radius scaled
rigidBodyRadius = (staticObjData->scale[0] * staticObjData->scale[1] * staticObjData->scale[2] / 3) * staticObjData->boundingVolume.sphere.radius;
//create the rigid body
rigidBody_Static = API::Instance().AddCollisionSphere( rigidBodyRadius , rigidWorldRotation , rigidWorldPos , rigidBodyMass, staticObjData->boundingVolume.sphere.restitutionCoeff , staticObjData->boundingVolume.sphere.frictionCoeffStatic , staticObjData->boundingVolume.sphere.frictionCoeffDynamic);
}
else if(staticObjData->boundingVolume.geoType == CollisionGeometryType_Box)
{
//offset the rigidPosition from modelspace to worldspace;
rigidWorldPos = (Oyster::Math::Float3)staticObjData->position + (Oyster::Math::Float3)staticObjData->boundingVolume.box.position;
//scales the position so the collision geomentry is in the right place
rigidWorldPos = rigidWorldPos * staticObjData->scale;
//offset the rigidRotation from modelspace to worldspace;
rigidWorldRotation = (Oyster::Math::Float4)staticObjData->rotation + (Oyster::Math::Float4)staticObjData->boundingVolume.box.rotation;
//mass scaled
rigidBodyMass = staticObjData->scale[0] * staticObjData->scale[1] * staticObjData->scale[2] * staticObjData->boundingVolume.box.mass;
//size scaled
rigidBodySize = (Oyster::Math::Float3)staticObjData->boundingVolume.box.size * (Oyster::Math::Float3)staticObjData->scale;
//create the rigid body
rigidBody_Static = API::Instance().AddCollisionBox(rigidBodySize , rigidWorldRotation , rigidWorldPos , rigidBodyMass, staticObjData->boundingVolume.box.restitutionCoeff , staticObjData->boundingVolume.box.frictionCoeffStatic , staticObjData->boundingVolume.box.frictionCoeffDynamic);
}
else if(staticObjData->boundingVolume.geoType == CollisionGeometryType_Cylinder)
{
}
// add rigidbody to the logical obj // add rigidbody to the logical obj
// Object::DefaultCollisionBefore, Object::DefaultCollisionAfter for now, gamelogic will take care of this // Object::DefaultCollisionBefore, Object::DefaultCollisionAfter for now, gamelogic will take care of this
// set object_type to objID // set object_type to objID
this->staticObjects.Push(new StaticObject(rigidBody, Object::DefaultCollisionAfter, OBJECT_TYPE::OBJECT_TYPE_BOX));
this->staticObjects[staticObjCount]->objectID = modelCount++; if(rigidBody_Static != NULL)
rigidBody->SetCustomTag(this->staticObjects[staticObjCount]); {
this->staticObjects.Push(new StaticObject(rigidBody_Static, Object::DefaultCollisionAfter, (ObjectSpecialType)staticObjData->specialTypeID));
this->staticObjects[staticObjCount]->objectID = modelCount++;
rigidBody_Static->SetCustomTag(this->staticObjects[staticObjCount]);
}
} }
break; break;
case ObjectType::ObjectType_Dynamic: case ObjectType::ObjectType_Dynamic:
{ {
ObjectHeader* staticObjData = ((ObjectHeader*)obj); ObjectHeader* dynamicObjData = ((ObjectHeader*)obj);
staticObjData->ModelFile; dynamicObjData->ModelFile;
ICustomBody* rigidBody_Dynamic; ICustomBody* rigidBody_Dynamic = NULL;
rigidBody_Dynamic = API::Instance().AddCollisionBox(Oyster::Math::Float3(0.5f, 0.5f, 0.5f), Oyster::Math::Float4(0, 0, 0, 1), Oyster::Math::Float3(0, 605 + i*5, 10), 5, 0.5f, 0.8f, 0.6f); // collision shape
// radius, rotation in world, position in world, mass, restitution, static and dynamic friction
if(dynamicObjData->boundingVolume.geoType == CollisionGeometryType_Sphere)
{
//offset the rigidPosition from modelspace to worldspace;
rigidWorldPos = (Oyster::Math::Float3)dynamicObjData->position + (Oyster::Math::Float3)dynamicObjData->boundingVolume.sphere.position;
//scales the position so the collision geomentry is in the right place
rigidWorldPos = rigidWorldPos * dynamicObjData->scale;
//offset the rigidRotation from modelspace to worldspace;
rigidWorldRotation = (Oyster::Math::Float4)dynamicObjData->rotation + (Oyster::Math::Float4)dynamicObjData->boundingVolume.sphere.rotation;
//mass scaled
rigidBodyMass = dynamicObjData->scale[0] * dynamicObjData->scale[1] * dynamicObjData->scale[2] * dynamicObjData->boundingVolume.sphere.mass;
//size scaled
rigidBodyRadius = (dynamicObjData->scale[0] * dynamicObjData->scale[1] * dynamicObjData->scale[2] / 3) * dynamicObjData->boundingVolume.sphere.radius;
//create the rigid body
rigidBody_Dynamic = API::Instance().AddCollisionBox(rigidBodyRadius , rigidWorldRotation , rigidWorldPos , rigidBodyMass, dynamicObjData->boundingVolume.sphere.restitutionCoeff , dynamicObjData->boundingVolume.sphere.frictionCoeffStatic , dynamicObjData->boundingVolume.sphere.frictionCoeffDynamic);
}
else if(dynamicObjData->boundingVolume.geoType == CollisionGeometryType_Box)
{
//offset the rigidPosition from modelspace to worldspace;
rigidWorldPos = (Oyster::Math::Float3)dynamicObjData->position + (Oyster::Math::Float3)dynamicObjData->boundingVolume.box.position;
//scales the position so the collision geomentry is in the right place
rigidWorldPos = rigidWorldPos * dynamicObjData->scale;
//offset the rigidRotation from modelspace to worldspace;
rigidWorldRotation = (Oyster::Math::Float4)dynamicObjData->rotation + (Oyster::Math::Float4)dynamicObjData->boundingVolume.box.rotation;
//mass scaled
rigidBodyMass = dynamicObjData->scale[0] * dynamicObjData->scale[1] * dynamicObjData->scale[2] * dynamicObjData->boundingVolume.box.mass;
//size scaled
rigidBodySize = (Oyster::Math::Float3)dynamicObjData->boundingVolume.box.size * (Oyster::Math::Float3)dynamicObjData->scale;
//create the rigid body
rigidBody_Dynamic = API::Instance().AddCollisionBox(rigidBodySize , rigidWorldRotation , rigidWorldPos , rigidBodyMass, dynamicObjData->boundingVolume.box.restitutionCoeff , dynamicObjData->boundingVolume.box.frictionCoeffStatic , dynamicObjData->boundingVolume.box.frictionCoeffDynamic);
}
else if(dynamicObjData->boundingVolume.geoType == CollisionGeometryType_Cylinder)
{
}
// add rigidbody to the logical obj
// Object::DefaultCollisionBefore, Object::DefaultCollisionAfter for now, gamelogic will take care of this
// set object_type to objID
if(rigidBody_Dynamic != NULL)
{
this->dynamicObjects.Push(new DynamicObject(rigidBody_Dynamic , Object::DefaultCollisionAfter, (ObjectSpecialType)dynamicObjData->specialTypeID));
this->dynamicObjects[dynamicObjCount]->objectID = modelCount++;
rigidBody_Dynamic->SetCustomTag(this->dynamicObjects[dynamicObjCount]);
}
this->dynamicObjects.Push(new DynamicObject(rigidBody_Dynamic, Object::DefaultCollisionAfter, OBJECT_TYPE::OBJECT_TYPE_BOX));
this->dynamicObjects[dynamicObjCount]->objectID = modelCount++;
rigidBody_Dynamic->SetCustomTag(this->dynamicObjects[dynamicObjCount]);
} }
break; break;
case ObjectType::ObjectType_Light: case ObjectType::ObjectType_Light:
@ -117,7 +224,9 @@ void Level::InitiateLevel(float radius)
int idCount = 100; int idCount = 100;
// add level sphere // add level sphere
ICustomBody* rigidBody = API::Instance().AddCollisionSphere(599.2f, Oyster::Math::Float4(0, 0, 0, 1), Oyster::Math::Float3(0, 0, 0), 0, 0.5f, 0.8f, 0.6f); ICustomBody* rigidBody = API::Instance().AddCollisionSphere(599.2f, Oyster::Math::Float4(0, 0, 0, 1), Oyster::Math::Float3(0, 0, 0), 0, 0.5f, 0.8f, 0.6f);
levelObj = new StaticObject(rigidBody, LevelCollisionAfter, OBJECT_TYPE::OBJECT_TYPE_WORLD);
levelObj = new StaticObject(rigidBody, LevelCollisionAfter, ObjectSpecialType_World);
this->levelObj->objectID = idCount++; this->levelObj->objectID = idCount++;
rigidBody->SetCustomTag(levelObj); rigidBody->SetCustomTag(levelObj);
@ -130,7 +239,8 @@ void Level::InitiateLevel(float radius)
{ {
rigidBody_TestBox = API::Instance().AddCollisionBox(Oyster::Math::Float3(0.5f, 0.5f, 0.5f), Oyster::Math::Float4(0, 0, 0, 1), Oyster::Math::Float3(0, 605 + i*5, 10), 5, 0.5f, 0.8f, 0.6f); rigidBody_TestBox = API::Instance().AddCollisionBox(Oyster::Math::Float3(0.5f, 0.5f, 0.5f), Oyster::Math::Float4(0, 0, 0, 1), Oyster::Math::Float3(0, 605 + i*5, 10), 5, 0.5f, 0.8f, 0.6f);
this->dynamicObjects.Push(new DynamicObject(rigidBody_TestBox, Object::DefaultCollisionAfter, OBJECT_TYPE::OBJECT_TYPE_BOX)); this->dynamicObjects.Push(new DynamicObject(rigidBody_TestBox, Object::DefaultCollisionAfter, ObjectSpecialType_StandarsBox));
this->dynamicObjects[i]->objectID = idCount++; this->dynamicObjects[i]->objectID = idCount++;
rigidBody_TestBox->SetCustomTag(this->dynamicObjects[i]); rigidBody_TestBox->SetCustomTag(this->dynamicObjects[i]);
} }
@ -168,7 +278,7 @@ 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, 0, 0, 1), Oyster::Math::Float3(10, 605, 0), 5, 0.5f, 0.8f, 0.6f);
this->dynamicObjects.Push(new DynamicObject(rigidBody_Crystal, Object::DefaultCollisionAfter, OBJECT_TYPE::OBJECT_TYPE_BOX)); this->dynamicObjects.Push(new DynamicObject(rigidBody_Crystal, Object::DefaultCollisionAfter, ObjectSpecialType_StandarsBox));
rigidBody_Crystal->SetCustomTag(this->dynamicObjects[nrOfBoxex]); rigidBody_Crystal->SetCustomTag(this->dynamicObjects[nrOfBoxex]);
this->dynamicObjects[nrOfBoxex]->objectID = idCount++; this->dynamicObjects[nrOfBoxex]->objectID = idCount++;
@ -176,14 +286,14 @@ void Level::InitiateLevel(float radius)
// 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, 20, 20), Oyster::Math::Float4(0, 0, 0, 1), Oyster::Math::Float3(-50, 590, 0), 0, 0.5f, 0.8f, 0.6f);
this->staticObjects.Push(new StaticObject(rigidBody_House, Object::DefaultCollisionAfter, OBJECT_TYPE::OBJECT_TYPE_GENERIC)); this->staticObjects.Push(new StaticObject(rigidBody_House, Object::DefaultCollisionAfter, ObjectSpecialType_Generic));
rigidBody_House->SetCustomTag(this->staticObjects[0]); rigidBody_House->SetCustomTag(this->staticObjects[0]);
this->staticObjects[0]->objectID = idCount++; this->staticObjects[0]->objectID = idCount++;
// add jumppad // add jumppad
ICustomBody* rigidBody_Jumppad = API::Instance().AddCollisionBox(Oyster::Math::Float3(0.5f, 0.5f, 0.5f), Oyster::Math::Float4(0, 0, 0, 1), Oyster::Math::Float3(4, 600.3, 0), 5, 0.5f, 0.8f, 0.6f); ICustomBody* rigidBody_Jumppad = API::Instance().AddCollisionBox(Oyster::Math::Float3(1, 1, 1), Oyster::Math::Float4(0, 0, 0, 1), Oyster::Math::Float3(4, 600.3, 0), 5, 0.5f, 0.8f, 0.6f);
this->staticObjects.Push(new JumpPad(rigidBody_Jumppad, Object::DefaultCollisionAfter, OBJECT_TYPE::OBJECT_TYPE_JUMPPAD, Oyster::Math::Float3(0,1,0))); this->staticObjects.Push(new JumpPad(rigidBody_Jumppad, JumpPad::JumpPadActivated, ObjectSpecialType_JumpPad, Oyster::Math::Float3(0,2000,0)));
rigidBody_Jumppad->SetCustomTag(this->staticObjects[1]); rigidBody_Jumppad->SetCustomTag(this->staticObjects[1]);
this->staticObjects[1]->objectID = idCount++; this->staticObjects[1]->objectID = idCount++;
} }
@ -209,7 +319,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 < 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

@ -25,6 +25,7 @@ std::vector<SmartPointer<ObjectTypeHeader>> LevelParser::Parse(std::string filen
{ {
int bufferSize = 0; int bufferSize = 0;
int counter = 0; int counter = 0;
bool loadCgf;
std::vector<SmartPointer<ObjectTypeHeader>> objects; std::vector<SmartPointer<ObjectTypeHeader>> objects;
@ -38,14 +39,13 @@ std::vector<SmartPointer<ObjectTypeHeader>> LevelParser::Parse(std::string filen
counter += sizeof(levelFormatVersion); counter += sizeof(levelFormatVersion);
if(this->formatVersion != levelFormatVersion) if(this->formatVersion != levelFormatVersion)
{ {
//Do something if it's not the same version
//Returns an empty vector, because it will most likely fail to read the level format. //Returns an empty vector, because it will most likely fail to read the level format.
return objects; return objects;
} }
while(counter < bufferSize) while(counter < bufferSize)
{ {
loadCgf = true;
//Get typeID //Get typeID
ObjectType typeID; ObjectType typeID;
ParseObject(&buffer[counter], &typeID, sizeof(typeID)); ParseObject(&buffer[counter], &typeID, sizeof(typeID));
@ -69,45 +69,43 @@ std::vector<SmartPointer<ObjectTypeHeader>> LevelParser::Parse(std::string filen
switch(specialType) switch(specialType)
{ {
//These three does not have any specail variables at this time. //there is no difference when parsing these specialTypes.
//There for they are using the same 'parser'. case ObjectSpecialType_CrystalShard:
case ObjectSpecialType_CrystalFormation:
case ObjectSpecialType_Spike:
case ObjectSpecialType_SpikeBox:
case ObjectSpecialType_RedExplosiveBox:
case ObjectSpecialType_StandarsBox:
case ObjectSpecialType_Stone:
case ObjectSpecialType_Building: case ObjectSpecialType_Building:
case ObjectSpecialType_Damaging:
case ObjectSpecialType_Explosive:
{ {
ObjectHeader* header = new ObjectHeader; ObjectHeader* header = new ObjectHeader;
ParseObject(&buffer[counter], *header, counter); ParseObject(&buffer[counter], *header, counter, loadCgf);
objects.push_back(header); objects.push_back(header);
break; break;
} }
case ObjectSpecialType_JumpPad: case ObjectSpecialType_JumpPad:
{ {
JumpPadAttributes* header = new JumpPadAttributes; JumpPadAttributes* header = new JumpPadAttributes;
ParseObject(&buffer[counter], *header, counter); ParseObject(&buffer[counter], *header, counter, loadCgf);
//Read the spec //Read the spec
ParseObject(&buffer[counter], header->direction, 16); ParseObject(&buffer[counter], header->direction, 16);
counter += 16;
objects.push_back(header); objects.push_back(header);
break; break;
} }
case ObjectSpecialType_BoostPad:
{
JumpPadAttributes* header = new JumpPadAttributes;
ParseObject(&buffer[counter], *header, counter);
ParseObject(&buffer[counter], header->direction, 16);
objects.push_back(header);
break;
}
case ObjectSpecialType_Portal: case ObjectSpecialType_Portal:
{ {
PortalAttributes* header = new PortalAttributes; PortalAttributes* header = new PortalAttributes;
ParseObject(&buffer[counter], *header, counter); ParseObject(&buffer[counter], *header, counter, loadCgf);
ParseObject(&buffer[counter], header->destination, 12); ParseObject(&buffer[counter], header->destination, 12);
counter += 12;
objects.push_back(header); objects.push_back(header);
break; break;
@ -116,22 +114,33 @@ std::vector<SmartPointer<ObjectTypeHeader>> LevelParser::Parse(std::string filen
case ObjectSpecialType_World: case ObjectSpecialType_World:
{ {
WorldAttributes* header = new WorldAttributes; WorldAttributes* header = new WorldAttributes;
ParseObject(&buffer[counter], *header, counter); ParseObject(&buffer[counter], *header, counter, loadCgf);
ParseObject(&buffer[counter], &header->worldSize, 8); ParseObject(&buffer[counter], &header->worldSize, 8);
counter += 8;
objects.push_back(header); objects.push_back(header);
break; break;
} }
case ObjectSpecialType_Sky: case ObjectSpecialType_Sky:
{ {
loadCgf = false;
SkyAttributes* header = new SkyAttributes; SkyAttributes* header = new SkyAttributes;
ParseObject(&buffer[counter], *header, counter); ParseObject(&buffer[counter], *header, counter, loadCgf);
ParseObject(&buffer[counter], &header->skySize, 4); ParseObject(&buffer[counter], &header->skySize, 4);
counter += 4;
objects.push_back(header); objects.push_back(header);
break; break;
} }
case ObjectSpecialType_SpawnPoint:
{
loadCgf = false;
ObjectHeader* header = new ObjectHeader;
ParseObject(&buffer[counter], *header, counter, loadCgf);
}
default: default:
//Couldn't find specialType //Couldn't find specialType
break; break;
@ -235,16 +244,13 @@ LevelMetaData LevelParser::ParseHeader(std::string filename)
case ObjectType_Static: case ObjectType_Dynamic: case ObjectType_Static: case ObjectType_Dynamic:
{ {
ObjectHeader header; ObjectHeader header;
ParseObject(&buffer[counter], header, counter); ParseObject(&buffer[counter], &header, counter);
switch(header.specialTypeID) switch(header.specialTypeID)
{ {
case ObjectSpecialType_JumpPad: case ObjectSpecialType_JumpPad:
counter += sizeof(16); counter += sizeof(16);
break; break;
case ObjectSpecialType_BoostPad:
counter += sizeof(16);
break;
case ObjectSpecialType_Portal: case ObjectSpecialType_Portal:
counter += sizeof(12); counter += sizeof(12);
break; break;

View File

@ -25,30 +25,28 @@ namespace GameLogic
enum ObjectSpecialType enum ObjectSpecialType
{ {
ObjectSpecialType_None,
ObjectSpecialType_Sky,
ObjectSpecialType_World, //Always the main celestial body ObjectSpecialType_World, //Always the main celestial body
ObjectSpecialType_Building, ObjectSpecialType_Building,
ObjectSpecialType_Damaging, ObjectSpecialType_Stone,
ObjectSpecialType_Explosive, ObjectSpecialType_StandarsBox,
ObjectSpecialType_RedExplosiveBox,
ObjectSpecialType_SpikeBox,
ObjectSpecialType_Spike,
ObjectSpecialType_CrystalFormation,
ObjectSpecialType_CrystalShard,
ObjectSpecialType_JumpPad, ObjectSpecialType_JumpPad,
ObjectSpecialType_BoostPad,
ObjectSpecialType_Portal, ObjectSpecialType_Portal,
ObjectSpecialType_Sky, ObjectSpecialType_SpawnPoint,
ObjectSpecialType_Player,
ObjectSpecialType_Generic,
ObjectSpecialType_Count, ObjectSpecialType_Count,
ObjectSpecialType_Unknown = -1 ObjectSpecialType_Unknown = -1
}; };
enum UsePhysics
{
UsePhysics_UseFullPhysics,
UsePhysics_IgnoreGravity,
UsePhysics_IgnorePhysics,
UsePhysics_IgnoreCollision,
UsePhysics_Count,
UsePhysics_Unknown = -1
};
enum CollisionGeometryType enum CollisionGeometryType
{ {
CollisionGeometryType_Box, CollisionGeometryType_Box,

View File

@ -16,13 +16,13 @@ namespace GameLogic
{ {
namespace LevelFileLoader namespace LevelFileLoader
{ {
//can parse any struct without strings or char[] //can parse any struct if the struct doesnt contain strings or char[]
void ParseObject(char* buffer, void *header, int size) void ParseObject(char* buffer, void *header, int size)
{ {
memcpy(header, buffer, size); memcpy(header, buffer, size);
} }
void ParseObject(char* buffer, ObjectHeader& header, int& size) void ParseObject(char* buffer, ObjectHeader& header, int& size, bool loadCgf)
{ {
char tempName[128]; char tempName[128];
unsigned int tempSize = 0; unsigned int tempSize = 0;
@ -46,8 +46,24 @@ namespace GameLogic
memcpy(&header.position, &buffer[start], 40); memcpy(&header.position, &buffer[start], 40);
start += 40; start += 40;
//Read path for bounding volume //if loadCgf : Read path for bounding volume
ParseBoundingVolume(&buffer[start], header.boundingVolume, start); 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; size += start;
} }
@ -133,15 +149,14 @@ namespace GameLogic
//Läs in filen. //Läs in filen.
int fileLength = 0; int fileLength = 0;
Loader loader; Loader loader;
char* buf = loader.LoadFile("E:\\Dropbox\\Programming\\Github\\Danbias\\Bin\\Content\\Worlds\\cgf\\"+ fileName, fileLength); char* buf = loader.LoadFile("C:/Users/Sam/Documents/GitHub/Danbias/Bin/Content/worlds/cgf/"+ fileName, fileLength);
start = 0; start = 0;
LevelLoaderInternal::FormatVersion version; LevelLoaderInternal::FormatVersion version;
memcpy(&version, &buf[0], sizeof(version)); memcpy(&version, &buf[0], sizeof(version));
start += 4; start += 8;
memcpy(&volume.geoType, &buf[start], sizeof(volume.geoType)); memcpy(&volume.geoType, &buf[start], sizeof(volume.geoType));
start += sizeof(volume.geoType);
switch(volume.geoType) switch(volume.geoType)
{ {

View File

@ -17,9 +17,8 @@ namespace GameLogic
Or the current index that is being used to parse the entire file (if it is sent by reference) this means you have to increase size with the appropiate size after you have copied. Or the current index that is being used to parse the entire file (if it is sent by reference) this means you have to increase size with the appropiate size after you have copied.
*/ */
void ParseObject(char* buffer, void *header, int size); void ParseObject(char* buffer, void *header, int size);
void ParseObject(char* buffer, ObjectHeader& header, int& size); void ParseObject(char* buffer, ObjectHeader& header, int& size , bool loadCgf);
void ParseLevelMetaData(char* buffer, LevelMetaData &header, int &size); void ParseLevelMetaData(char* buffer, LevelMetaData &header, int &size);
void ParseBoundingVolume(char* buffer, LevelLoaderInternal::BoundingVolume& volume, int &size); void ParseBoundingVolume(char* buffer, LevelLoaderInternal::BoundingVolume& volume, int &size);
} }

View File

@ -18,25 +18,26 @@ Object::Object()
this->rigidBody = API::Instance().AddCollisionBox(Oyster::Math::Float3(0.0f, 0.0f, 0.0f), Oyster::Math::Float4(0, 0, 0, 1), Oyster::Math::Float3(0, 0, 0), 0, 0.5f, 0.8f, 0.6f); this->rigidBody = API::Instance().AddCollisionBox(Oyster::Math::Float3(0.0f, 0.0f, 0.0f), Oyster::Math::Float4(0, 0, 0, 1), Oyster::Math::Float3(0, 0, 0), 0, 0.5f, 0.8f, 0.6f);
this->type = OBJECT_TYPE::OBJECT_TYPE_UNKNOWN; this->type = ObjectSpecialType_Unknown;
this->objectID = GID(); this->objectID = GID();
} }
Object::Object(OBJECT_TYPE type) Object::Object(ObjectSpecialType type)
{ {
this->rigidBody = API::Instance().AddCollisionBox(Oyster::Math::Float3(0.0f, 0.0f, 0.0f), Oyster::Math::Float4(0, 0, 0, 1), Oyster::Math::Float3(0, 0, 0), 0, 0.5f, 0.8f, 0.6f); this->rigidBody = API::Instance().AddCollisionBox(Oyster::Math::Float3(0.0f, 0.0f, 0.0f), Oyster::Math::Float4(0, 0, 0, 1), Oyster::Math::Float3(0, 0, 0), 0, 0.5f, 0.8f, 0.6f);
this->type = type; this->type = type;
this->objectID = GID(); this->objectID = GID();
} }
Object::Object(Oyster::Physics::ICustomBody *rigidBody, OBJECT_TYPE type) Object::Object(Oyster::Physics::ICustomBody *rigidBody, ObjectSpecialType type)
{ {
this->rigidBody = rigidBody; this->rigidBody = rigidBody;
this->type = type; this->type = type;
this->objectID = GID(); this->objectID = GID();
} }
Object::Object( void* collisionFuncAfter, OBJECT_TYPE type) Object::Object( void* collisionFuncAfter, ObjectSpecialType type)
{ {
this->rigidBody = API::Instance().AddCollisionBox(Oyster::Math::Float3(0.0f, 0.0f, 0.0f), Oyster::Math::Float4(0, 0, 0, 1), Oyster::Math::Float3(0, 0, 0), 0, 0.5f, 0.8f, 0.6f); this->rigidBody = API::Instance().AddCollisionBox(Oyster::Math::Float3(0.0f, 0.0f, 0.0f), Oyster::Math::Float4(0, 0, 0, 1), Oyster::Math::Float3(0, 0, 0), 0, 0.5f, 0.8f, 0.6f);
@ -44,7 +45,7 @@ Object::Object( void* collisionFuncAfter, OBJECT_TYPE type)
this->objectID = GID(); this->objectID = GID();
} }
Object::Object(Oyster::Physics::ICustomBody *rigidBody, void* collisionFuncAfter, OBJECT_TYPE type) Object::Object(Oyster::Physics::ICustomBody *rigidBody, void* collisionFuncAfter, ObjectSpecialType type)
{ {
this->rigidBody = rigidBody; this->rigidBody = rigidBody;
this->rigidBody->SetSubscription((Oyster::Physics::ICustomBody::EventAction_AfterCollisionResponse)(collisionFuncAfter)); this->rigidBody->SetSubscription((Oyster::Physics::ICustomBody::EventAction_AfterCollisionResponse)(collisionFuncAfter));
@ -52,7 +53,8 @@ Object::Object(Oyster::Physics::ICustomBody *rigidBody, void* collisionFuncAfter
this->objectID = GID(); this->objectID = GID();
} }
Object::Object(Oyster::Physics::ICustomBody *rigidBody , Oyster::Physics::ICustomBody::SubscriptMessage (*collisionFuncAfter)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), OBJECT_TYPE type)
Object::Object(Oyster::Physics::ICustomBody *rigidBody , Oyster::Physics::ICustomBody::SubscriptMessage (*collisionFuncAfter)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), ObjectSpecialType type)
{ {
this->rigidBody = rigidBody; this->rigidBody = rigidBody;
this->rigidBody->SetSubscription((Oyster::Physics::ICustomBody::EventAction_AfterCollisionResponse)(collisionFuncAfter)); this->rigidBody->SetSubscription((Oyster::Physics::ICustomBody::EventAction_AfterCollisionResponse)(collisionFuncAfter));
@ -71,7 +73,7 @@ Object::~Object(void)
} }
OBJECT_TYPE Object::GetObjectType() const ObjectSpecialType Object::GetObjectType() const
{ {
return this->type; return this->type;
} }

View File

@ -18,21 +18,24 @@ namespace GameLogic
{ {
public: public:
Object(); Object();
Object(OBJECT_TYPE type); Object(ObjectSpecialType type);
Object(Oyster::Physics::ICustomBody *rigidBody, OBJECT_TYPE type); Object(Oyster::Physics::ICustomBody *rigidBody, ObjectSpecialType type);
Object(void* collisionFuncAfter, OBJECT_TYPE type); Object(void* collisionFuncAfter, ObjectSpecialType type);
Object(Oyster::Physics::ICustomBody *rigidBody, void* collisionFuncAfter, OBJECT_TYPE type); Object(Oyster::Physics::ICustomBody *rigidBody, void* collisionFuncAfter, ObjectSpecialType type);
Object(Oyster::Physics::ICustomBody *rigidBody, Oyster::Physics::ICustomBody::SubscriptMessage (*collisionFuncAfter)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), OBJECT_TYPE type); Object(Oyster::Physics::ICustomBody *rigidBody, Oyster::Physics::ICustomBody::SubscriptMessage (*collisionFuncAfter)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), ObjectSpecialType type);
~Object(void); ~Object(void);
OBJECT_TYPE GetObjectType() const override; ObjectSpecialType GetObjectType() const override;
int GetID() const override; int GetID() const override;
void setID(int id);
Oyster::Math::Float3 GetPosition() override; Oyster::Math::Float3 GetPosition() override;
Oyster::Math::Quaternion GetRotation() override; Oyster::Math::Quaternion GetRotation() override;
Oyster::Math::Float3 GetScale() override; Oyster::Math::Float3 GetScale() override;
Oyster::Math::Float4x4 GetOrientation() override; Oyster::Math::Float4x4 GetOrientation() override;
void setID(int id); // API overrides
Oyster::Physics::ICustomBody* GetRigidBody(); Oyster::Physics::ICustomBody* GetRigidBody();
void ApplyLinearImpulse(Oyster::Math::Float3 force); void ApplyLinearImpulse(Oyster::Math::Float3 force);
@ -45,8 +48,9 @@ namespace GameLogic
static Oyster::Physics::ICustomBody::SubscriptMessage DefaultCollisionAfter(Oyster::Physics::ICustomBody *rigidBodyLevel, Oyster::Physics::ICustomBody *obj, Oyster::Math::Float kineticEnergyLoss); static Oyster::Physics::ICustomBody::SubscriptMessage DefaultCollisionAfter(Oyster::Physics::ICustomBody *rigidBodyLevel, Oyster::Physics::ICustomBody *obj, Oyster::Math::Float kineticEnergyLoss);
public: //HACK: This should be private when level is dynamic
OBJECT_TYPE type; public: //TODO: Hax This should be private when level is dynamic
ObjectSpecialType type;
int objectID; int objectID;
protected: protected:

View File

@ -13,27 +13,28 @@ Player::Player()
{ {
} }
Player::Player(OBJECT_TYPE type) Player::Player(ObjectSpecialType type)
:DynamicObject(type) :DynamicObject(type)
{ {
InitPlayer(); InitPlayer();
} }
Player::Player(Oyster::Physics::ICustomBody *rigidBody, OBJECT_TYPE type) Player::Player(Oyster::Physics::ICustomBody *rigidBody, ObjectSpecialType type)
:DynamicObject(rigidBody,type) :DynamicObject(rigidBody,type)
{ {
InitPlayer(); InitPlayer();
} }
Player::Player( void* collisionFuncAfter, OBJECT_TYPE type)
Player::Player( void* collisionFuncAfter, ObjectSpecialType type)
:DynamicObject(collisionFuncAfter,type) :DynamicObject(collisionFuncAfter,type)
{ {
InitPlayer(); InitPlayer();
} }
Player::Player(Oyster::Physics::ICustomBody *rigidBody, void* collisionFuncAfter, OBJECT_TYPE type) Player::Player(Oyster::Physics::ICustomBody *rigidBody, void* collisionFuncAfter, ObjectSpecialType type)
:DynamicObject(rigidBody, collisionFuncAfter, type) :DynamicObject(rigidBody, collisionFuncAfter, type)
{ {
InitPlayer(); InitPlayer();
} }
Player::Player(Oyster::Physics::ICustomBody *rigidBody, Oyster::Physics::ICustomBody::SubscriptMessage (*collisionFuncAfter)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), OBJECT_TYPE type) Player::Player(Oyster::Physics::ICustomBody *rigidBody, Oyster::Physics::ICustomBody::SubscriptMessage (*collisionFuncAfter)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), ObjectSpecialType type)
:DynamicObject(rigidBody, collisionFuncAfter, type) :DynamicObject(rigidBody, collisionFuncAfter, type)
{ {
InitPlayer(); InitPlayer();

View File

@ -16,11 +16,12 @@ namespace GameLogic
{ {
public: public:
Player(void); Player(void);
Player(OBJECT_TYPE type); Player(ObjectSpecialType type);
Player(Oyster::Physics::ICustomBody *rigidBody, OBJECT_TYPE type); Player(Oyster::Physics::ICustomBody *rigidBody, ObjectSpecialType type);
Player( void* collisionFuncAfter, OBJECT_TYPE type); Player( void* collisionFuncAfter, ObjectSpecialType type);
Player(Oyster::Physics::ICustomBody *rigidBody, void* collisionFuncAfter, OBJECT_TYPE type); Player(Oyster::Physics::ICustomBody *rigidBody, void* collisionFuncAfter, ObjectSpecialType type);
Player(Oyster::Physics::ICustomBody *rigidBody, Oyster::Physics::ICustomBody::SubscriptMessage (*collisionFuncAfter)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), OBJECT_TYPE type); Player(Oyster::Physics::ICustomBody *rigidBody, Oyster::Physics::ICustomBody::SubscriptMessage (*collisionFuncAfter)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), ObjectSpecialType type);
~Player(void); ~Player(void);
void InitPlayer(); void InitPlayer();

View File

@ -10,29 +10,29 @@ StaticObject::StaticObject()
{ {
} }
StaticObject::StaticObject(OBJECT_TYPE type) StaticObject::StaticObject(ObjectSpecialType type)
:Object(type) :Object(type)
{ {
} }
StaticObject::StaticObject(Oyster::Physics::ICustomBody *rigidBody, OBJECT_TYPE type) StaticObject::StaticObject(Oyster::Physics::ICustomBody *rigidBody, ObjectSpecialType type)
:Object(rigidBody,type) :Object(rigidBody,type)
{ {
//this->rigidBody->SetGravity(true); //this->rigidBody->SetGravity(true);
//this->rigidBody->SetSubscription((Oyster::Physics::ICustomBody::EventAction_BeforeCollisionResponse)(CollisionManager::IgnoreCollision)); //this->rigidBody->SetSubscription((Oyster::Physics::ICustomBody::EventAction_BeforeCollisionResponse)(CollisionManager::IgnoreCollision));
} }
StaticObject::StaticObject( void* collisionFuncAfter, OBJECT_TYPE type) StaticObject::StaticObject( void* collisionFuncAfter, ObjectSpecialType type)
:Object(collisionFuncAfter,type) :Object(collisionFuncAfter,type)
{ {
} }
StaticObject::StaticObject(Oyster::Physics::ICustomBody *rigidBody , void* collisionFuncAfter, OBJECT_TYPE type) StaticObject::StaticObject(Oyster::Physics::ICustomBody *rigidBody , void* collisionFuncAfter, ObjectSpecialType type)
:Object(rigidBody, collisionFuncAfter, type) :Object(rigidBody, collisionFuncAfter, type)
{ {
} }
StaticObject::StaticObject(Oyster::Physics::ICustomBody *rigidBody , Oyster::Physics::ICustomBody::SubscriptMessage (*collisionFuncAfter)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), OBJECT_TYPE type) StaticObject::StaticObject(Oyster::Physics::ICustomBody *rigidBody , Oyster::Physics::ICustomBody::SubscriptMessage (*collisionFuncAfter)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), ObjectSpecialType type)
:Object(rigidBody, collisionFuncAfter, type) :Object(rigidBody, collisionFuncAfter, type)
{ {

View File

@ -8,6 +8,7 @@
#include "Object.h" #include "Object.h"
namespace GameLogic namespace GameLogic
{ {
@ -16,11 +17,12 @@ namespace GameLogic
public: public:
StaticObject(); StaticObject();
StaticObject(OBJECT_TYPE type);
StaticObject(Oyster::Physics::ICustomBody *rigidBody, OBJECT_TYPE type); StaticObject(ObjectSpecialType type);
StaticObject( void* collisionFuncAfter, OBJECT_TYPE type); StaticObject(Oyster::Physics::ICustomBody *rigidBody, ObjectSpecialType type);
StaticObject(Oyster::Physics::ICustomBody *rigidBody , void* collisionFuncAfter, OBJECT_TYPE type); StaticObject( void* collisionFuncAfter, ObjectSpecialType type);
StaticObject(Oyster::Physics::ICustomBody *rigidBody , Oyster::Physics::ICustomBody::SubscriptMessage (*collisionFuncAfter)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), OBJECT_TYPE type); StaticObject(Oyster::Physics::ICustomBody *rigidBody , void* collisionFuncAfter, ObjectSpecialType type);
StaticObject(Oyster::Physics::ICustomBody *rigidBody , Oyster::Physics::ICustomBody::SubscriptMessage (*collisionFuncAfter)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), ObjectSpecialType type);
~StaticObject(void); ~StaticObject(void);

View File

@ -201,7 +201,7 @@ void API_Impl::UpdateWorld()
{ {
SimpleRigidBody* simpleBody = dynamic_cast<SimpleRigidBody*>(this->customBodies[i]); SimpleRigidBody* simpleBody = dynamic_cast<SimpleRigidBody*>(this->customBodies[i]);
btTransform trans; btTransform trans;
simpleBody->GetMotionState()->getWorldTransform(trans); trans = simpleBody->GetRigidBody()->getWorldTransform();
this->customBodies[i]->SetPosition(Float3(trans.getOrigin().x(), trans.getOrigin().y(), trans.getOrigin().z())); this->customBodies[i]->SetPosition(Float3(trans.getOrigin().x(), trans.getOrigin().y(), trans.getOrigin().z()));
this->customBodies[i]->SetRotation(Quaternion(Float3(trans.getRotation().x(), trans.getRotation().y(), trans.getRotation().z()), trans.getRotation().w())); this->customBodies[i]->SetRotation(Quaternion(Float3(trans.getRotation().x(), trans.getRotation().y(), trans.getRotation().z()), trans.getRotation().w()));