diff --git a/Code/Game/GameLogic/Game.cpp b/Code/Game/GameLogic/Game.cpp index 900799e3..ba294349 100644 --- a/Code/Game/GameLogic/Game.cpp +++ b/Code/Game/GameLogic/Game.cpp @@ -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; } diff --git a/Code/Game/GameLogic/Game.h b/Code/Game/GameLogic/Game.h index 9c21ec1b..6623756f 100644 --- a/Code/Game/GameLogic/Game.h +++ b/Code/Game/GameLogic/Game.h @@ -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; diff --git a/Code/Game/GameLogic/GameAPI.h b/Code/Game/GameLogic/GameAPI.h index 3325115f..65d606d8 100644 --- a/Code/Game/GameLogic/GameAPI.h +++ b/Code/Game/GameLogic/GameAPI.h @@ -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 ? diff --git a/Code/Game/GameLogic/Level.cpp b/Code/Game/GameLogic/Level.cpp index 4d3cf703..3c289766 100644 --- a/Code/Game/GameLogic/Level.cpp +++ b/Code/Game/GameLogic/Level.cpp @@ -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> objects; diff --git a/Code/Game/GameLogic/Level.h b/Code/Game/GameLogic/Level.h index 623d04b2..18d650e8 100644 --- a/Code/Game/GameLogic/Level.h +++ b/Code/Game/GameLogic/Level.h @@ -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); diff --git a/Code/Game/GameLogic/LevelLoader/LevelLoader.cpp b/Code/Game/GameLogic/LevelLoader/LevelLoader.cpp index 8fe880f3..205da712 100644 --- a/Code/Game/GameLogic/LevelLoader/LevelLoader.cpp +++ b/Code/Game/GameLogic/LevelLoader/LevelLoader.cpp @@ -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> LevelLoader::LoadLevel(std::string fileName) +std::vector> 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; } \ No newline at end of file diff --git a/Code/Game/GameLogic/LevelLoader/LevelLoader.h b/Code/Game/GameLogic/LevelLoader/LevelLoader.h index aa67c4f5..c14e2c4c 100644 --- a/Code/Game/GameLogic/LevelLoader/LevelLoader.h +++ b/Code/Game/GameLogic/LevelLoader/LevelLoader.h @@ -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> LoadLevel(std::string fileName); + std::vector> 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; diff --git a/Code/Game/GameLogic/LevelLoader/LevelParser.cpp b/Code/Game/GameLogic/LevelLoader/LevelParser.cpp index 1e33361d..061e2c08 100644 --- a/Code/Game/GameLogic/LevelLoader/LevelParser.cpp +++ b/Code/Game/GameLogic/LevelLoader/LevelParser.cpp @@ -20,7 +20,7 @@ LevelParser::~LevelParser() { } -std::vector> LevelParser::Parse(std::string filename) +std::vector> LevelParser::Parse(std::wstring filename) { int bufferSize = 0; int counter = 0; @@ -32,6 +32,12 @@ std::vector> 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>(); + } + //Read format version LevelLoaderInternal::FormatVersion levelFormatVersion; ParseObject(&buffer[counter], &levelFormatVersion, sizeof(levelFormatVersion)); @@ -215,7 +221,7 @@ std::vector> 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; diff --git a/Code/Game/GameLogic/LevelLoader/LevelParser.h b/Code/Game/GameLogic/LevelLoader/LevelParser.h index 8f2a9150..d0cb1f03 100644 --- a/Code/Game/GameLogic/LevelLoader/LevelParser.h +++ b/Code/Game/GameLogic/LevelLoader/LevelParser.h @@ -17,10 +17,10 @@ namespace GameLogic ~LevelParser(); // - std::vector> Parse(std::string filename); + std::vector> Parse(std::wstring filename); // - LevelMetaData ParseHeader(std::string filename); + LevelMetaData ParseHeader(std::wstring filename); private: LevelLoaderInternal::FormatVersion formatVersion; diff --git a/Code/Game/GameLogic/LevelLoader/Loader.cpp b/Code/Game/GameLogic/LevelLoader/Loader.cpp index 3e15315c..19ffa0f1 100644 --- a/Code/Game/GameLogic/LevelLoader/Loader.cpp +++ b/Code/Game/GameLogic/LevelLoader/Loader.cpp @@ -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; diff --git a/Code/Game/GameLogic/LevelLoader/Loader.h b/Code/Game/GameLogic/LevelLoader/Loader.h index 0433194e..6deb8900 100644 --- a/Code/Game/GameLogic/LevelLoader/Loader.h +++ b/Code/Game/GameLogic/LevelLoader/Loader.h @@ -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) diff --git a/Code/Game/GameLogic/LevelLoader/ParseFunctions.cpp b/Code/Game/GameLogic/LevelLoader/ParseFunctions.cpp index daa62752..76d7d6c3 100644 --- a/Code/Game/GameLogic/LevelLoader/ParseFunctions.cpp +++ b/Code/Game/GameLogic/LevelLoader/ParseFunctions.cpp @@ -5,6 +5,7 @@ #include "ParseFunctions.h" #include "Packing/Packing.h" #include "Loader.h" +#include "Utilities.h" #include 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;