Merge remote-tracking branch 'origin/GameLogic' into Camera-test-merge
Conflicts: Code/Game/DanBiasGame/DanBiasGame_Impl.cpp Code/Game/DanBiasGame/GameClientState/GameState.cpp Code/Game/DanBiasGame/GameClientState/LoginState.cpp
This commit is contained in:
commit
45f6d983ad
|
@ -37,16 +37,10 @@ namespace DanBias
|
||||||
{}
|
{}
|
||||||
|
|
||||||
//Circle vs point collision
|
//Circle vs point collision
|
||||||
bool Collision(InputClass* inputObject)
|
bool Collision(Oyster::Event::MouseInput& input)
|
||||||
{
|
{
|
||||||
POINT p;
|
|
||||||
RECT r;
|
|
||||||
GetCursorPos(&p);
|
|
||||||
ScreenToClient(WindowShell::GetHWND(), &p);
|
|
||||||
GetClientRect(WindowShell::GetHWND(), &r);
|
|
||||||
|
|
||||||
//Should come from the InputClass
|
//Should come from the InputClass
|
||||||
float xMouse = (float)p.x / (float)r.right, yMouse = (float)p.y / (float)r.bottom;
|
float xMouse = input.x, yMouse = input.y;
|
||||||
|
|
||||||
double normx = (xMouse - xPos) / width;
|
double normx = (xMouse - xPos) / width;
|
||||||
double normy = (yMouse - yPos) / height;
|
double normy = (yMouse - yPos) / height;
|
||||||
|
|
|
@ -37,16 +37,10 @@ namespace DanBias
|
||||||
{}
|
{}
|
||||||
|
|
||||||
//Circle vs point collision
|
//Circle vs point collision
|
||||||
bool Collision(InputClass* inputObject)
|
bool Collision(Oyster::Event::MouseInput& input)
|
||||||
{
|
{
|
||||||
POINT p;
|
|
||||||
RECT r;
|
|
||||||
GetCursorPos(&p);
|
|
||||||
ScreenToClient(WindowShell::GetHWND(), &p);
|
|
||||||
GetClientRect(WindowShell::GetHWND(), &r);
|
|
||||||
|
|
||||||
//Should come from the InputClass
|
//Should come from the InputClass
|
||||||
float xMouse = (float)p.x / (float)r.right, yMouse = (float)p.y / (float)r.bottom;
|
float xMouse = input.x, yMouse = input.y;
|
||||||
|
|
||||||
float widthTemp = xPos - width * 0.5f;
|
float widthTemp = xPos - width * 0.5f;
|
||||||
float widthTemp2 = xPos + width * 0.5f;
|
float widthTemp2 = xPos + width * 0.5f;
|
||||||
|
|
|
@ -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)
|
||||||
|
{
|
||||||
|
|
||||||
}
|
}
|
|
@ -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;
|
||||||
|
|
|
@ -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:
|
||||||
|
|
|
@ -23,7 +23,7 @@ namespace GameLogic
|
||||||
LevelMetaData ParseHeader(std::string filename);
|
LevelMetaData ParseHeader(std::string filename);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
FormatVersion formatVersion;
|
LevelLoaderInternal::FormatVersion formatVersion;
|
||||||
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -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
|
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -60,17 +60,18 @@ void AttatchmentMassDriver::Update(float dt)
|
||||||
//update position of heldObject if there is an object being held
|
//update position of heldObject if there is an object being held
|
||||||
if(hasObject)
|
if(hasObject)
|
||||||
{
|
{
|
||||||
Oyster::Physics::ICustomBody::State state;
|
//Oyster::Physics::ICustomBody::State state;
|
||||||
state = heldObject->GetState();
|
//state = heldObject->GetState();
|
||||||
Oyster::Math::Float3 ownerPos = owner->GetPosition();
|
Oyster::Math::Float3 ownerPos = owner->GetPosition();
|
||||||
Oyster::Physics::ICustomBody::State ownerState = owner->GetRigidBody()->GetState();
|
Oyster::Physics::ICustomBody::State ownerState = owner->GetRigidBody()->GetState();
|
||||||
Oyster::Math::Float3 up = -ownerState.GetOrientation().v[2];
|
Oyster::Math::Float3 up = -ownerState.GetOrientation().v[2];
|
||||||
up *= -0.3;
|
up *= -0.3;
|
||||||
Oyster::Math::Float3 pos = ownerPos + up + (owner->GetLookDir().GetNormalized()*10);
|
Oyster::Math::Float3 pos = ownerPos + (owner->GetLookDir().GetNormalized()*5);
|
||||||
|
|
||||||
state.centerPos = pos;
|
//state.centerPos = pos;
|
||||||
|
heldObject->SetPosition(pos);
|
||||||
|
|
||||||
heldObject->SetState(state);
|
//heldObject->SetState(state);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -86,10 +87,8 @@ void AttatchmentMassDriver::ForcePush(const GameLogic::WEAPON_FIRE &usage, float
|
||||||
if(hasObject)
|
if(hasObject)
|
||||||
{
|
{
|
||||||
Oyster::Physics::API::Instance().ReleaseFromLimbo(heldObject);
|
Oyster::Physics::API::Instance().ReleaseFromLimbo(heldObject);
|
||||||
pushForce = Oyster::Math::Float4(this->owner->GetLookDir()) * (700);
|
pushForce = Oyster::Math::Float4(this->owner->GetLookDir()) * (400);
|
||||||
Oyster::Physics::ICustomBody::State state = heldObject->GetState();
|
heldObject->ApplyImpulse((Oyster::Math::Float3)pushForce);
|
||||||
//state.ApplyLinearImpulse((Oyster::Math::Float3)pushForce);
|
|
||||||
heldObject->SetState(state);
|
|
||||||
|
|
||||||
hasObject = false;
|
hasObject = false;
|
||||||
heldObject = NULL;
|
heldObject = NULL;
|
||||||
|
@ -101,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);
|
||||||
|
|
||||||
|
|
|
@ -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,9 +129,9 @@ 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
|
||||||
weapon->hasObject = true;
|
weapon->hasObject = true;
|
||||||
|
|
||||||
|
|
|
@ -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)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
|
@ -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);
|
||||||
|
|
||||||
|
|
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
|
@ -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;
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -21,15 +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_UNKNOWN = -1,
|
|
||||||
};
|
|
||||||
|
|
||||||
enum WEAPON_FIRE
|
enum WEAPON_FIRE
|
||||||
{
|
{
|
||||||
WEAPON_USE_PRIMARY_PRESS = 0,
|
WEAPON_USE_PRIMARY_PRESS = 0,
|
||||||
|
|
|
@ -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;
|
||||||
|
|
|
@ -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();
|
||||||
}
|
}
|
||||||
|
|
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -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);
|
||||||
|
|
||||||
|
|
|
@ -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,9 +286,16 @@ 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
|
||||||
|
ICustomBody* rigidBody_Jumppad = API::Instance().AddCollisionBox(Oyster::Math::Float3(1, 1, 1), Oyster::Math::Float4(0, 0, 0, 1), Oyster::Math::Float3(4, 600.3, 0), 5, 0.5f, 0.8f, 0.6f);
|
||||||
|
|
||||||
|
this->staticObjects.Push(new JumpPad(rigidBody_Jumppad, JumpPad::JumpPadActivated, ObjectSpecialType_JumpPad, Oyster::Math::Float3(0,2000,0)));
|
||||||
|
rigidBody_Jumppad->SetCustomTag(this->staticObjects[1]);
|
||||||
|
this->staticObjects[1]->objectID = idCount++;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Level::AddPlayerToTeam(Player *player, int teamID)
|
void Level::AddPlayerToTeam(Player *player, int teamID)
|
||||||
|
@ -202,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];
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
#include "StaticObject.h"
|
#include "StaticObject.h"
|
||||||
#include "DynamicObject.h"
|
#include "DynamicObject.h"
|
||||||
#include "GameModeType.h"
|
#include "GameModeType.h"
|
||||||
|
#include "JumpPad.h"
|
||||||
#include "Player.h"
|
#include "Player.h"
|
||||||
#include "PhysicsAPI.h"
|
#include "PhysicsAPI.h"
|
||||||
#include "TeamManager.h"
|
#include "TeamManager.h"
|
||||||
|
|
|
@ -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;
|
||||||
|
|
|
@ -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,
|
||||||
|
|
|
@ -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)
|
||||||
{
|
{
|
||||||
|
|
|
@ -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);
|
||||||
}
|
}
|
||||||
|
|
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
|
@ -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:
|
||||||
|
|
|
@ -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();
|
||||||
|
|
|
@ -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();
|
||||||
|
|
||||||
|
|
|
@ -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)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
|
@ -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);
|
||||||
|
|
||||||
|
|
|
@ -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()));
|
||||||
|
|
||||||
|
|
|
@ -106,36 +106,36 @@ void SimpleRigidBody::SetLinearVelocity(Float3 velocity)
|
||||||
void SimpleRigidBody::SetPosition(::Oyster::Math::Float3 position)
|
void SimpleRigidBody::SetPosition(::Oyster::Math::Float3 position)
|
||||||
{
|
{
|
||||||
btTransform trans;
|
btTransform trans;
|
||||||
this->motionState->getWorldTransform(trans);
|
trans = this->rigidBody->getWorldTransform();
|
||||||
trans.setOrigin(btVector3(position.x, position.y, position.z));
|
trans.setOrigin(btVector3(position.x, position.y, position.z));
|
||||||
this->motionState->setWorldTransform(trans);
|
this->rigidBody->setWorldTransform(trans);
|
||||||
this->state.centerPos = position;
|
this->state.centerPos = position;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SimpleRigidBody::SetRotation(Float4 quaternion)
|
void SimpleRigidBody::SetRotation(Float4 quaternion)
|
||||||
{
|
{
|
||||||
btTransform trans;
|
btTransform trans;
|
||||||
this->motionState->getWorldTransform(trans);
|
trans = this->rigidBody->getWorldTransform();
|
||||||
trans.setRotation(btQuaternion(quaternion.x, quaternion.y, quaternion.z, quaternion.w));
|
trans.setRotation(btQuaternion(quaternion.x, quaternion.y, quaternion.z, quaternion.w));
|
||||||
this->motionState->setWorldTransform(trans);
|
this->rigidBody->setWorldTransform(trans);
|
||||||
this->state.quaternion = Quaternion(quaternion.xyz, quaternion.w);
|
this->state.quaternion = Quaternion(quaternion.xyz, quaternion.w);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SimpleRigidBody::SetRotation(::Oyster::Math::Quaternion quaternion)
|
void SimpleRigidBody::SetRotation(::Oyster::Math::Quaternion quaternion)
|
||||||
{
|
{
|
||||||
btTransform trans;
|
btTransform trans;
|
||||||
this->motionState->getWorldTransform(trans);
|
trans = this->rigidBody->getWorldTransform();
|
||||||
trans.setRotation(btQuaternion(quaternion.imaginary.x, quaternion.imaginary.y, quaternion.imaginary.z, quaternion.real));
|
trans.setRotation(btQuaternion(quaternion.imaginary.x, quaternion.imaginary.y, quaternion.imaginary.z, quaternion.real));
|
||||||
this->motionState->setWorldTransform(trans);
|
this->rigidBody->setWorldTransform(trans);
|
||||||
this->state.quaternion = quaternion;
|
this->state.quaternion = quaternion;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SimpleRigidBody::SetRotation(Float3 eulerAngles)
|
void SimpleRigidBody::SetRotation(Float3 eulerAngles)
|
||||||
{
|
{
|
||||||
btTransform trans;
|
btTransform trans;
|
||||||
this->motionState->getWorldTransform(trans);
|
trans = this->rigidBody->getWorldTransform();
|
||||||
trans.setRotation(btQuaternion(eulerAngles.x, eulerAngles.y, eulerAngles.z));
|
trans.setRotation(btQuaternion(eulerAngles.x, eulerAngles.y, eulerAngles.z));
|
||||||
this->motionState->setWorldTransform(trans);
|
this->rigidBody->setWorldTransform(trans);
|
||||||
this->state.quaternion = Quaternion(Float3(trans.getRotation().x(), trans.getRotation().y(), trans.getRotation().z()), trans.getRotation().w());
|
this->state.quaternion = Quaternion(Float3(trans.getRotation().x(), trans.getRotation().y(), trans.getRotation().z()), trans.getRotation().w());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -46,7 +46,7 @@ namespace Oyster
|
||||||
|
|
||||||
private:
|
private:
|
||||||
//Implement this in the inherited classes for collision against that shape.
|
//Implement this in the inherited classes for collision against that shape.
|
||||||
virtual bool Collision(InputClass *input) = 0;
|
virtual bool Collision(MouseInput& input) = 0;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
EventButton();
|
EventButton();
|
||||||
|
@ -56,7 +56,7 @@ namespace Oyster
|
||||||
EventButton(EventFunc func, Owner owner, void* userData);
|
EventButton(EventFunc func, Owner owner, void* userData);
|
||||||
virtual ~EventButton();
|
virtual ~EventButton();
|
||||||
|
|
||||||
void Update(InputClass *input);
|
void Update(MouseInput& input);
|
||||||
|
|
||||||
//Send event to callback function
|
//Send event to callback function
|
||||||
void SendEvent(ButtonState state);
|
void SendEvent(ButtonState state);
|
||||||
|
@ -135,16 +135,18 @@ namespace Oyster
|
||||||
|
|
||||||
//Checks for collision and
|
//Checks for collision and
|
||||||
template <typename Owner>
|
template <typename Owner>
|
||||||
void EventButton<Owner>::Update(InputClass *input)
|
void EventButton<Owner>::Update(MouseInput& input)
|
||||||
{
|
{
|
||||||
if(this->privData.enabled)
|
if(this->privData.enabled)
|
||||||
{
|
{
|
||||||
ButtonState currentState = ButtonState_None;
|
ButtonState currentState = ButtonState_None;
|
||||||
static bool outside = false;
|
static bool outside = false;
|
||||||
static bool clicked = false;
|
static bool clicked = false;
|
||||||
|
|
||||||
|
//Check for collision against the button.
|
||||||
if(Collision(input))
|
if(Collision(input))
|
||||||
{
|
{
|
||||||
if(input->IsMousePressed())
|
if(input.mouseButtonPressed)
|
||||||
{
|
{
|
||||||
//Change state when the mouse button is pressed
|
//Change state when the mouse button is pressed
|
||||||
switch(this->privData.previousState)
|
switch(this->privData.previousState)
|
||||||
|
|
|
@ -20,6 +20,7 @@ EventButtonCollection::~EventButtonCollection()
|
||||||
if(EventHandler::Instance().collections.at(i) == this)
|
if(EventHandler::Instance().collections.at(i) == this)
|
||||||
{
|
{
|
||||||
EventHandler::Instance().collections.erase(EventHandler::Instance().collections.begin() + i);
|
EventHandler::Instance().collections.erase(EventHandler::Instance().collections.begin() + i);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -31,13 +32,13 @@ EventButtonCollection::~EventButtonCollection()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void EventButtonCollection::Update(InputClass* inputObject)
|
void EventButtonCollection::Update(MouseInput& input)
|
||||||
{
|
{
|
||||||
if(this->collectionState == EventCollectionState_Enabled)
|
if(this->collectionState == EventCollectionState_Enabled)
|
||||||
{
|
{
|
||||||
for(int i = 0; i < (int)buttons.size(); i++)
|
for(int i = 0; i < (int)buttons.size(); i++)
|
||||||
{
|
{
|
||||||
buttons[i]->Update(inputObject);
|
buttons[i]->Update(input);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,7 +36,7 @@ namespace Oyster
|
||||||
EventButtonCollection(EventCollectionState state = EventCollectionState_Enabled);
|
EventButtonCollection(EventCollectionState state = EventCollectionState_Enabled);
|
||||||
~EventButtonCollection();
|
~EventButtonCollection();
|
||||||
|
|
||||||
void Update(InputClass* inputObject);
|
void Update(MouseInput& input);
|
||||||
void Render();
|
void Render();
|
||||||
|
|
||||||
/*Add a button to the collection when a button is added to the collection you are not allowed to delete it.
|
/*Add a button to the collection when a button is added to the collection you are not allowed to delete it.
|
||||||
|
|
|
@ -19,30 +19,19 @@ EventHandler::EventHandler()
|
||||||
|
|
||||||
EventHandler::~EventHandler()
|
EventHandler::~EventHandler()
|
||||||
{
|
{
|
||||||
int size = collections.size();
|
Clean();
|
||||||
for(int i = 0; i < size; i++)
|
|
||||||
{
|
|
||||||
delete collections[i];
|
|
||||||
collections[i] = NULL;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void EventHandler::Clean()
|
void EventHandler::Clean()
|
||||||
{
|
{
|
||||||
int size = collections.size();
|
|
||||||
for(int i = 0; i < size; i++)
|
|
||||||
{
|
|
||||||
delete collections[i];
|
|
||||||
collections[i] = NULL;
|
|
||||||
}
|
|
||||||
collections.clear();
|
collections.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
void EventHandler::Update(InputClass* inputObject)
|
void EventHandler::Update(MouseInput& input)
|
||||||
{
|
{
|
||||||
for(int i = 0; i < (int)collections.size(); i++)
|
for(int i = 0; i < (int)collections.size(); i++)
|
||||||
{
|
{
|
||||||
collections.at(i)->Update(inputObject);
|
collections.at(i)->Update(input);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -65,14 +54,12 @@ void EventHandler::AddCollection(EventButtonCollection* collection)
|
||||||
collections.push_back(collection);
|
collections.push_back(collection);
|
||||||
}
|
}
|
||||||
|
|
||||||
void EventHandler::DeleteCollection(EventButtonCollection* collection)
|
void EventHandler::ReleaseCollection(EventButtonCollection* collection)
|
||||||
{
|
{
|
||||||
for(int i = 0; i < collections.size(); i++)
|
for(int i = 0; i < collections.size(); i++)
|
||||||
{
|
{
|
||||||
if(collections.at(i) == collection)
|
if(collections.at(i) == collection)
|
||||||
{
|
{
|
||||||
delete collection;
|
|
||||||
collection = NULL;
|
|
||||||
collections.erase(collections.begin() + i);
|
collections.erase(collections.begin() + i);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,14 +26,15 @@ namespace Oyster
|
||||||
|
|
||||||
void Clean();
|
void Clean();
|
||||||
|
|
||||||
void Update(InputClass* inputObject);
|
void Update(MouseInput& input);
|
||||||
void Render();
|
void Render();
|
||||||
|
|
||||||
/*Add a collection to the EventHandler will only add collections not already present in the list.
|
/*Add a collection to the EventHandler will only add collections not already present in the list.
|
||||||
|
|
||||||
*/
|
*/
|
||||||
void AddCollection(EventButtonCollection* collection);
|
void AddCollection(EventButtonCollection* collection);
|
||||||
void DeleteCollection(EventButtonCollection* collection);
|
|
||||||
|
void ReleaseCollection(EventButtonCollection* collection);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
//Can't copy this class.
|
//Can't copy this class.
|
||||||
|
@ -43,7 +44,7 @@ namespace Oyster
|
||||||
private:
|
private:
|
||||||
std::vector<EventButtonCollection*> collections;
|
std::vector<EventButtonCollection*> collections;
|
||||||
|
|
||||||
//EventButtonCollection is a firend so it can delete it self.
|
//EventButtonCollection is a friend so it can delete it self.
|
||||||
friend class EventButtonCollection;
|
friend class EventButtonCollection;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,13 +20,22 @@ namespace Oyster
|
||||||
ButtonState_Released,
|
ButtonState_Released,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
//Takes normalized device coordinates
|
||||||
|
struct MouseInput
|
||||||
|
{
|
||||||
|
//Normalized device coordinates
|
||||||
|
float x, y;
|
||||||
|
bool mouseButtonPressed;
|
||||||
|
};
|
||||||
|
|
||||||
class IEventButton
|
class IEventButton
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
virtual ~IEventButton(){}
|
virtual ~IEventButton(){}
|
||||||
|
|
||||||
virtual void Render() = 0;
|
virtual void Render() = 0;
|
||||||
virtual void Update(InputClass *input) = 0;
|
|
||||||
|
virtual void Update(MouseInput& input) = 0;
|
||||||
|
|
||||||
virtual void SendEvent(ButtonState state) = 0;
|
virtual void SendEvent(ButtonState state) = 0;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue