GameLogic - Added filename to paramater when initiating a level, Also changed some string to wstrings
This commit is contained in:
parent
86ef521abd
commit
8a0dbe969c
|
@ -76,14 +76,12 @@ Game::PlayerData* Game::CreatePlayer()
|
||||||
return this->players[i];
|
return this->players[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
Game::LevelData* Game::CreateLevel()
|
Game::LevelData* Game::CreateLevel(const wchar_t mapName[255])
|
||||||
{
|
{
|
||||||
if(this->level) return this->level;
|
if(this->level) return this->level;
|
||||||
|
|
||||||
this->level = new LevelData();
|
this->level = new LevelData();
|
||||||
//this->level->level->InitiateLevel(1000);
|
this->level->level->InitiateLevel(mapName);
|
||||||
this->level->level->InitiateLevel("../Content/Worlds/ccc.bias");
|
|
||||||
|
|
||||||
|
|
||||||
return this->level;
|
return this->level;
|
||||||
}
|
}
|
||||||
|
|
|
@ -72,7 +72,7 @@ namespace GameLogic
|
||||||
|
|
||||||
void GetAllPlayerPositions() const override;
|
void GetAllPlayerPositions() const override;
|
||||||
PlayerData* CreatePlayer() override;
|
PlayerData* CreatePlayer() override;
|
||||||
LevelData* CreateLevel() override;
|
LevelData* CreateLevel(const wchar_t mapName[255] ) override;
|
||||||
void CreateTeam() override;
|
void CreateTeam() override;
|
||||||
bool NewFrame() override;
|
bool NewFrame() override;
|
||||||
void SetFPS( int FPS ) override;
|
void SetFPS( int FPS ) override;
|
||||||
|
|
|
@ -139,7 +139,7 @@ namespace GameLogic
|
||||||
/** Creates a level
|
/** Creates a level
|
||||||
* @return Returns a ILevelData container to use for level manipulation
|
* @return Returns a ILevelData container to use for level manipulation
|
||||||
*/
|
*/
|
||||||
virtual ILevelData* CreateLevel( void ) = 0;
|
virtual ILevelData* CreateLevel( const wchar_t mapName[255] ) = 0;
|
||||||
|
|
||||||
/** Creates a team
|
/** Creates a team
|
||||||
* @return ?
|
* @return ?
|
||||||
|
|
|
@ -197,7 +197,7 @@ ICustomBody* Level::InitRigidBodySphere( const ObjectHeader* obj)
|
||||||
rigidBody = API::Instance().AddCollisionSphere( rigidBodyRadius , rigidWorldRotation , rigidWorldPos , rigidBodyMass, obj->boundingVolume.sphere.restitutionCoeff , obj->boundingVolume.sphere.frictionCoeffStatic , obj->boundingVolume.sphere.frictionCoeffDynamic);
|
rigidBody = API::Instance().AddCollisionSphere( rigidBodyRadius , rigidWorldRotation , rigidWorldPos , rigidBodyMass, obj->boundingVolume.sphere.restitutionCoeff , obj->boundingVolume.sphere.frictionCoeffStatic , obj->boundingVolume.sphere.frictionCoeffDynamic);
|
||||||
return rigidBody;
|
return rigidBody;
|
||||||
}
|
}
|
||||||
void Level::InitiateLevel(std::string levelPath)
|
void Level::InitiateLevel(std::wstring levelPath)
|
||||||
{
|
{
|
||||||
LevelLoader ll;
|
LevelLoader ll;
|
||||||
std::vector<Utility::DynamicMemory::SmartPointer<ObjectTypeHeader>> objects;
|
std::vector<Utility::DynamicMemory::SmartPointer<ObjectTypeHeader>> objects;
|
||||||
|
|
|
@ -30,7 +30,7 @@ namespace GameLogic
|
||||||
* Initiates a level for players to play on
|
* Initiates a level for players to play on
|
||||||
* @param levelPath: Path to a file that contains all information on the level
|
* @param levelPath: Path to a file that contains all information on the level
|
||||||
********************************************************/
|
********************************************************/
|
||||||
void InitiateLevel(std::string levelPath);
|
void InitiateLevel(std::wstring levelPath);
|
||||||
void InitiateLevel(float radius);
|
void InitiateLevel(float radius);
|
||||||
Oyster::Physics::ICustomBody* InitRigidBodyCube( const ObjectHeader* obj);
|
Oyster::Physics::ICustomBody* InitRigidBodyCube( const ObjectHeader* obj);
|
||||||
Oyster::Physics::ICustomBody* InitRigidBodySphere( const ObjectHeader* obj);
|
Oyster::Physics::ICustomBody* InitRigidBodySphere( const ObjectHeader* obj);
|
||||||
|
|
|
@ -11,17 +11,17 @@ using namespace GameLogic::LevelFileLoader;
|
||||||
struct LevelLoader::PrivData
|
struct LevelLoader::PrivData
|
||||||
{
|
{
|
||||||
LevelParser parser;
|
LevelParser parser;
|
||||||
std::string folderPath;
|
std::wstring folderPath;
|
||||||
};
|
};
|
||||||
|
|
||||||
LevelLoader::LevelLoader()
|
LevelLoader::LevelLoader()
|
||||||
: pData(new PrivData)
|
: pData(new PrivData)
|
||||||
{
|
{
|
||||||
//standard path
|
//standard path
|
||||||
pData->folderPath = "";
|
pData->folderPath = L"";
|
||||||
}
|
}
|
||||||
|
|
||||||
LevelLoader::LevelLoader(std::string folderPath)
|
LevelLoader::LevelLoader(std::wstring folderPath)
|
||||||
: pData(new PrivData)
|
: pData(new PrivData)
|
||||||
{
|
{
|
||||||
pData->folderPath = folderPath;
|
pData->folderPath = folderPath;
|
||||||
|
@ -31,22 +31,22 @@ LevelLoader::~LevelLoader()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<Utility::DynamicMemory::SmartPointer<ObjectTypeHeader>> LevelLoader::LoadLevel(std::string fileName)
|
std::vector<Utility::DynamicMemory::SmartPointer<ObjectTypeHeader>> LevelLoader::LoadLevel(std::wstring fileName)
|
||||||
{
|
{
|
||||||
return pData->parser.Parse(pData->folderPath + fileName);
|
return pData->parser.Parse(pData->folderPath + fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
LevelMetaData LevelLoader::LoadLevelHeader(std::string fileName)
|
LevelMetaData LevelLoader::LoadLevelHeader(std::wstring fileName)
|
||||||
{
|
{
|
||||||
return pData->parser.ParseHeader(pData->folderPath + fileName);
|
return pData->parser.ParseHeader(pData->folderPath + fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string LevelLoader::GetFolderPath()
|
std::wstring LevelLoader::GetFolderPath()
|
||||||
{
|
{
|
||||||
return this->pData->folderPath;
|
return this->pData->folderPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
void LevelLoader::SetFolderPath(std::string folderPath)
|
void LevelLoader::SetFolderPath(std::wstring folderPath)
|
||||||
{
|
{
|
||||||
|
this->pData->folderPath = folderPath;
|
||||||
}
|
}
|
|
@ -20,7 +20,7 @@ namespace GameLogic
|
||||||
/***********************************************************
|
/***********************************************************
|
||||||
* Lets you set the standard folderpath for the levels
|
* Lets you set the standard folderpath for the levels
|
||||||
********************************************************/
|
********************************************************/
|
||||||
LevelLoader(std::string folderPath);
|
LevelLoader(std::wstring folderPath);
|
||||||
~LevelLoader();
|
~LevelLoader();
|
||||||
|
|
||||||
/********************************************************
|
/********************************************************
|
||||||
|
@ -28,24 +28,24 @@ namespace GameLogic
|
||||||
* @param fileName: Path/name 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::wstring fileName);
|
||||||
|
|
||||||
/********************************************************
|
/********************************************************
|
||||||
* Just for fast access for the meta information about the level.
|
* Just for fast access for the meta information about the level.
|
||||||
* @param fileName: Path to the level-file that you want to load.
|
* @param fileName: Path to the level-file that you want to load.
|
||||||
* @return: Returns the meta information about the level.
|
* @return: Returns the meta information about the level.
|
||||||
********************************************************/
|
********************************************************/
|
||||||
LevelMetaData LoadLevelHeader(std::string fileName); //.
|
LevelMetaData LoadLevelHeader(std::wstring fileName); //.
|
||||||
|
|
||||||
/***********************************************************
|
/***********************************************************
|
||||||
* @return: Returns the current standard folder path
|
* @return: Returns the current standard folder path
|
||||||
********************************************************/
|
********************************************************/
|
||||||
std::string GetFolderPath();
|
std::wstring GetFolderPath();
|
||||||
|
|
||||||
/***********************************************************
|
/***********************************************************
|
||||||
* Sets the standard folder path
|
* Sets the standard folder path
|
||||||
********************************************************/
|
********************************************************/
|
||||||
void SetFolderPath(std::string folderPath);
|
void SetFolderPath(std::wstring folderPath);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
struct PrivData;
|
struct PrivData;
|
||||||
|
|
|
@ -20,7 +20,7 @@ LevelParser::~LevelParser()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<SmartPointer<ObjectTypeHeader>> LevelParser::Parse(std::string filename)
|
std::vector<SmartPointer<ObjectTypeHeader>> LevelParser::Parse(std::wstring filename)
|
||||||
{
|
{
|
||||||
int bufferSize = 0;
|
int bufferSize = 0;
|
||||||
int counter = 0;
|
int counter = 0;
|
||||||
|
@ -32,6 +32,12 @@ std::vector<SmartPointer<ObjectTypeHeader>> LevelParser::Parse(std::string filen
|
||||||
Loader loader;
|
Loader loader;
|
||||||
char* buffer = (char*)loader.LoadFile(filename.c_str(), bufferSize);
|
char* buffer = (char*)loader.LoadFile(filename.c_str(), bufferSize);
|
||||||
|
|
||||||
|
// Check if file was loaded, else return empty vector
|
||||||
|
if(bufferSize == 0)
|
||||||
|
{
|
||||||
|
return std::vector<SmartPointer<ObjectTypeHeader>>();
|
||||||
|
}
|
||||||
|
|
||||||
//Read format version
|
//Read format version
|
||||||
LevelLoaderInternal::FormatVersion levelFormatVersion;
|
LevelLoaderInternal::FormatVersion levelFormatVersion;
|
||||||
ParseObject(&buffer[counter], &levelFormatVersion, sizeof(levelFormatVersion));
|
ParseObject(&buffer[counter], &levelFormatVersion, sizeof(levelFormatVersion));
|
||||||
|
@ -215,7 +221,7 @@ std::vector<SmartPointer<ObjectTypeHeader>> LevelParser::Parse(std::string filen
|
||||||
}
|
}
|
||||||
|
|
||||||
//för meta information om leveln.
|
//för meta information om leveln.
|
||||||
LevelMetaData LevelParser::ParseHeader(std::string filename)
|
LevelMetaData LevelParser::ParseHeader(std::wstring filename)
|
||||||
{
|
{
|
||||||
int bufferSize = 0;
|
int bufferSize = 0;
|
||||||
int counter = 0;
|
int counter = 0;
|
||||||
|
|
|
@ -17,10 +17,10 @@ namespace GameLogic
|
||||||
~LevelParser();
|
~LevelParser();
|
||||||
|
|
||||||
//
|
//
|
||||||
std::vector<Utility::DynamicMemory::SmartPointer<ObjectTypeHeader>> Parse(std::string filename);
|
std::vector<Utility::DynamicMemory::SmartPointer<ObjectTypeHeader>> Parse(std::wstring filename);
|
||||||
|
|
||||||
//
|
//
|
||||||
LevelMetaData ParseHeader(std::string filename);
|
LevelMetaData ParseHeader(std::wstring filename);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
LevelLoaderInternal::FormatVersion formatVersion;
|
LevelLoaderInternal::FormatVersion formatVersion;
|
||||||
|
|
|
@ -9,13 +9,13 @@ using namespace GameLogic::LevelFileLoader;
|
||||||
using namespace Oyster::Resource;
|
using namespace Oyster::Resource;
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
char* Loader::LoadFile(std::string fileName, int &size)
|
char* Loader::LoadFile(std::wstring fileName, int &size)
|
||||||
{
|
{
|
||||||
//convert from string to wstring
|
//convert from string to wstring
|
||||||
std::wstring temp(fileName.begin(), fileName.end());
|
//std::wstring temp(fileName.begin(), fileName.end());
|
||||||
|
|
||||||
//convert from wstring to wchar then loads the file
|
//convert from wstring to wchar then loads the file
|
||||||
char* buffer = (char*)OysterResource::LoadResource(temp.c_str(), Oyster::Resource::ResourceType::ResourceType_Byte_Raw, -1 , false);
|
char* buffer = (char*)OysterResource::LoadResource(fileName.c_str(), Oyster::Resource::ResourceType::ResourceType_Byte_Raw, -1 , false);
|
||||||
|
|
||||||
size = OysterResource::GetResourceSize(buffer);
|
size = OysterResource::GetResourceSize(buffer);
|
||||||
return buffer;
|
return buffer;
|
||||||
|
|
|
@ -17,7 +17,7 @@ namespace GameLogic
|
||||||
public:
|
public:
|
||||||
Loader (){};
|
Loader (){};
|
||||||
~Loader(){};
|
~Loader(){};
|
||||||
char* LoadFile(std::string fileName, int &size);
|
char* LoadFile(std::wstring fileName, int &size);
|
||||||
|
|
||||||
//TODO:
|
//TODO:
|
||||||
//Add functionality to load physicsObjects (hitboxes)
|
//Add functionality to load physicsObjects (hitboxes)
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
#include "ParseFunctions.h"
|
#include "ParseFunctions.h"
|
||||||
#include "Packing/Packing.h"
|
#include "Packing/Packing.h"
|
||||||
#include "Loader.h"
|
#include "Loader.h"
|
||||||
|
#include "Utilities.h"
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
using namespace Oyster::Packing;
|
using namespace Oyster::Packing;
|
||||||
|
@ -149,7 +150,7 @@ namespace GameLogic
|
||||||
//Läs in filen.
|
//Läs in filen.
|
||||||
int fileLength = 0;
|
int fileLength = 0;
|
||||||
Loader loader;
|
Loader loader;
|
||||||
char* buf = loader.LoadFile("../Content/Worlds/cgf/"+ fileName, fileLength);
|
char* buf = loader.LoadFile(L"../Content/Worlds/cgf/" + Utility::String::StringToWstring(fileName, wstring()), fileLength);
|
||||||
|
|
||||||
start = 0;
|
start = 0;
|
||||||
LevelLoaderInternal::FormatVersion version;
|
LevelLoaderInternal::FormatVersion version;
|
||||||
|
|
Loading…
Reference in New Issue