GameLogic - Added filename to paramater when initiating a level, Also changed some string to wstrings

This commit is contained in:
Dennis Andersen 2014-02-18 21:24:21 +01:00
parent 86ef521abd
commit 8a0dbe969c
12 changed files with 35 additions and 30 deletions

View File

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

View File

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

View File

@ -139,7 +139,7 @@ namespace GameLogic
/** Creates a level
* @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
* @return ?

View File

@ -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);
return rigidBody;
}
void Level::InitiateLevel(std::string levelPath)
void Level::InitiateLevel(std::wstring levelPath)
{
LevelLoader ll;
std::vector<Utility::DynamicMemory::SmartPointer<ObjectTypeHeader>> objects;

View File

@ -30,7 +30,7 @@ namespace GameLogic
* Initiates a level for players to play on
* @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);
Oyster::Physics::ICustomBody* InitRigidBodyCube( const ObjectHeader* obj);
Oyster::Physics::ICustomBody* InitRigidBodySphere( const ObjectHeader* obj);

View File

@ -11,17 +11,17 @@ using namespace GameLogic::LevelFileLoader;
struct LevelLoader::PrivData
{
LevelParser parser;
std::string folderPath;
std::wstring folderPath;
};
LevelLoader::LevelLoader()
: pData(new PrivData)
{
//standard path
pData->folderPath = "";
pData->folderPath = L"";
}
LevelLoader::LevelLoader(std::string folderPath)
LevelLoader::LevelLoader(std::wstring folderPath)
: pData(new PrivData)
{
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);
}
LevelMetaData LevelLoader::LoadLevelHeader(std::string fileName)
LevelMetaData LevelLoader::LoadLevelHeader(std::wstring fileName)
{
return pData->parser.ParseHeader(pData->folderPath + fileName);
}
std::string LevelLoader::GetFolderPath()
std::wstring LevelLoader::GetFolderPath()
{
return this->pData->folderPath;
}
void LevelLoader::SetFolderPath(std::string folderPath)
void LevelLoader::SetFolderPath(std::wstring folderPath)
{
this->pData->folderPath = folderPath;
}

View File

@ -20,7 +20,7 @@ namespace GameLogic
/***********************************************************
* Lets you set the standard folderpath for the levels
********************************************************/
LevelLoader(std::string folderPath);
LevelLoader(std::wstring folderPath);
~LevelLoader();
/********************************************************
@ -28,24 +28,24 @@ namespace GameLogic
* @param fileName: Path/name to the level-file that you want to load.
* @return: Returns all structs with objects and information about the level.
********************************************************/
std::vector<Utility::DynamicMemory::SmartPointer<ObjectTypeHeader>> LoadLevel(std::string fileName);
std::vector<Utility::DynamicMemory::SmartPointer<ObjectTypeHeader>> LoadLevel(std::wstring fileName);
/********************************************************
* Just for fast access for the meta information about the level.
* @param fileName: Path to the level-file that you want to load.
* @return: Returns the meta information about the level.
********************************************************/
LevelMetaData LoadLevelHeader(std::string fileName); //.
LevelMetaData LoadLevelHeader(std::wstring fileName); //.
/***********************************************************
* @return: Returns the current standard folder path
********************************************************/
std::string GetFolderPath();
std::wstring GetFolderPath();
/***********************************************************
* Sets the standard folder path
********************************************************/
void SetFolderPath(std::string folderPath);
void SetFolderPath(std::wstring folderPath);
private:
struct PrivData;

View File

@ -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 counter = 0;
@ -32,6 +32,12 @@ std::vector<SmartPointer<ObjectTypeHeader>> LevelParser::Parse(std::string filen
Loader loader;
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
LevelLoaderInternal::FormatVersion 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.
LevelMetaData LevelParser::ParseHeader(std::string filename)
LevelMetaData LevelParser::ParseHeader(std::wstring filename)
{
int bufferSize = 0;
int counter = 0;

View File

@ -17,10 +17,10 @@ namespace GameLogic
~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:
LevelLoaderInternal::FormatVersion formatVersion;

View File

@ -9,13 +9,13 @@ using namespace GameLogic::LevelFileLoader;
using namespace Oyster::Resource;
using namespace std;
char* Loader::LoadFile(std::string fileName, int &size)
char* Loader::LoadFile(std::wstring fileName, int &size)
{
//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
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);
return buffer;

View File

@ -17,7 +17,7 @@ namespace GameLogic
public:
Loader (){};
~Loader(){};
char* LoadFile(std::string fileName, int &size);
char* LoadFile(std::wstring fileName, int &size);
//TODO:
//Add functionality to load physicsObjects (hitboxes)

View File

@ -5,6 +5,7 @@
#include "ParseFunctions.h"
#include "Packing/Packing.h"
#include "Loader.h"
#include "Utilities.h"
#include <string>
using namespace Oyster::Packing;
@ -149,7 +150,7 @@ namespace GameLogic
//Läs in filen.
int fileLength = 0;
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;
LevelLoaderInternal::FormatVersion version;