diff --git a/Core/Core/CoreInstance.cpp b/Core/Core/CoreInstance.cpp index 7d2e47b..3d316d5 100644 --- a/Core/Core/CoreInstance.cpp +++ b/Core/Core/CoreInstance.cpp @@ -34,11 +34,18 @@ CoreInstance::CoreInstance() memorySize_ = System::getMemorySize(); std::ifstream main_config_file(main_config_name); + std::string payload; + if (main_config_file.fail()) throw std::runtime_error("Fail open main config file"); - std::string payload; - std::getline(main_config_file, payload); + main_config_file.seekg(0, std::ios::end); + size_t size_config = main_config_file.tellg(); + main_config_file.seekg(0, std::ios::beg); + payload.resize(size_config); + + main_config_file.read(payload.data(), payload.size()); + main_config_file.close(); SaveMap load_main_config(payload); main_config_.load(std::make_shared(load_main_config)); diff --git a/Core/Game/SaveMap/SaveMap.cpp b/Core/Game/SaveMap/SaveMap.cpp index dc148f1..ec18bf5 100644 --- a/Core/Game/SaveMap/SaveMap.cpp +++ b/Core/Game/SaveMap/SaveMap.cpp @@ -37,6 +37,8 @@ SaveMap::SaveMap(const std::string& json_data) { size_t key_begin = i = json_data_blank.find_first_of('\"', i) + 1; size_t key_end = i = json_data_blank.find_first_of('\"', i); + if (0 == key_begin) + return; std::string name = json_data_blank.substr(key_begin, key_end - key_begin); diff --git a/Core/Game/WorldFactory.hpp b/Core/Game/WorldFactory.hpp index 5e8a006..d9ac6d0 100644 --- a/Core/Game/WorldFactory.hpp +++ b/Core/Game/WorldFactory.hpp @@ -25,8 +25,12 @@ struct WorldFactory std::ifstream config_file("./Worlds/" #WorldName ".world");\ if (config_file.fail())\ throw std::runtime_error("Can't open world file");\ + config_file.seekg(0, std::ios::end);\ + size_t file_size = config_file.tellg();\ + config_file.seekg(0, std::ios::beg);\ std::string data;\ - std::getline(config_file, data);\ + data.resize(file_size);\ + config_file.read(data.data(), file_size);\ world->load(std::make_shared(data));\ return world;\ }}, diff --git a/TestGame/Worlds/TestWorld.world b/TestGame/Worlds/TestWorld.world index b63c26a..ada8632 100644 --- a/TestGame/Worlds/TestWorld.world +++ b/TestGame/Worlds/TestWorld.world @@ -1 +1,39 @@ -{"Class name":"TestWorld","dtime":5.000000,"Parent parameters":{"Class name":"World","loActors":[{"Class name":"StaticMesh","Parent parameters":{"Class name":"Mesh","smodel_name_":"TestModel","Parent parameters":{"Class name":"Actor","oloc":{"Class name":"Vector3D","dx":0.0,"dy":0.0,"dz":0.0},"orot":{"Class name":"Vector3D","dx":0.0,"dy":0.0,"dz":0.0},"oscale":{"Class name":"Vector3D","dx":0.0,"dy":0.0,"dz":0.0},"tags":[]}}}]}} \ No newline at end of file +{ + "Class name": "TestWorld", + "dtime": 5.000000, + "Parent parameters": { + "Class name":"World", + "vsActorsIDs": ["Mesh"], + "loActors": [ + { + "Class name": "StaticMesh", + "Parent parameters": { + "Class name": "Mesh", + "smodel_name_": "TestModel", + "Parent parameters": { + "Class name":"Actor", + "oloc": { + "Class name":"Vector3D", + "dx":0.0, + "dy":0.0, + "dz":0.0 + }, + "orot": { + "Class name":"Vector3D", + "dx":0.0, + "dy":0.0, + "dz":0.0 + }, + "oscale": { + "Class name": "Vector3D", + "dx": 0.0, + "dy": 0.0, + "dz": 0.0 + }, + "tags":[] + } + } + } + ] + } +} \ No newline at end of file diff --git a/TestGame/main_config.conf b/TestGame/main_config.conf index e2d7189..9f00330 100644 --- a/TestGame/main_config.conf +++ b/TestGame/main_config.conf @@ -1 +1,7 @@ -{"Class name":"MainConfig","dmin_memory_size":4096.0,"imin_CPU_count":1,"sgame_name":"Test Game","sbase_world":"TestWorld"} \ No newline at end of file +{ + "Class name": "MainConfig", + "dmin_memory_size": 4096.0, + "imin_CPU_count": 1, + "sgame_name": "Test Game", + "sbase_world": "TestWorld" +} \ No newline at end of file