Fix load configs
This commit is contained in:
@@ -34,11 +34,18 @@ CoreInstance::CoreInstance()
|
|||||||
memorySize_ = System::getMemorySize();
|
memorySize_ = System::getMemorySize();
|
||||||
|
|
||||||
std::ifstream main_config_file(main_config_name);
|
std::ifstream main_config_file(main_config_name);
|
||||||
|
std::string payload;
|
||||||
|
|
||||||
if (main_config_file.fail())
|
if (main_config_file.fail())
|
||||||
throw std::runtime_error("Fail open main config file");
|
throw std::runtime_error("Fail open main config file");
|
||||||
|
|
||||||
std::string payload;
|
main_config_file.seekg(0, std::ios::end);
|
||||||
std::getline(main_config_file, payload);
|
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);
|
SaveMap load_main_config(payload);
|
||||||
|
|
||||||
main_config_.load(std::make_shared<SaveMap>(load_main_config));
|
main_config_.load(std::make_shared<SaveMap>(load_main_config));
|
||||||
|
|||||||
@@ -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_begin = i = json_data_blank.find_first_of('\"', i) + 1;
|
||||||
size_t key_end = i = json_data_blank.find_first_of('\"', i);
|
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);
|
std::string name = json_data_blank.substr(key_begin, key_end - key_begin);
|
||||||
|
|
||||||
|
|||||||
@@ -25,8 +25,12 @@ struct WorldFactory
|
|||||||
std::ifstream config_file("./Worlds/" #WorldName ".world");\
|
std::ifstream config_file("./Worlds/" #WorldName ".world");\
|
||||||
if (config_file.fail())\
|
if (config_file.fail())\
|
||||||
throw std::runtime_error("Can't open world file");\
|
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::string data;\
|
||||||
std::getline(config_file, data);\
|
data.resize(file_size);\
|
||||||
|
config_file.read(data.data(), file_size);\
|
||||||
world->load(std::make_shared<SaveMap>(data));\
|
world->load(std::make_shared<SaveMap>(data));\
|
||||||
return world;\
|
return 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":[]}}}]}}
|
{
|
||||||
|
"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":[]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1 +1,7 @@
|
|||||||
{"Class name":"MainConfig","dmin_memory_size":4096.0,"imin_CPU_count":1,"sgame_name":"Test Game","sbase_world":"TestWorld"}
|
{
|
||||||
|
"Class name": "MainConfig",
|
||||||
|
"dmin_memory_size": 4096.0,
|
||||||
|
"imin_CPU_count": 1,
|
||||||
|
"sgame_name": "Test Game",
|
||||||
|
"sbase_world": "TestWorld"
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user