From e12ba8979c54e45296ae748e5fb3e586ad4f0bdc Mon Sep 17 00:00:00 2001 From: Jonathan Bradley Date: Wed, 4 Oct 2023 16:52:40 -0400 Subject: saving and loading file with instances works as expected --- src/game.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'src/game.cpp') diff --git a/src/game.cpp b/src/game.cpp index 6ce4847..f464c41 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -192,13 +192,13 @@ void ParseInstance(std::ifstream &stream) { char entTypeCode[21]; memset(reinterpret_cast(entTypeCode), '\0', 21); while (stream.getline(readLine, readLineLength)) { - if (strcmp(PKE_FILE_OBJ_END, readLine) == 0) { + if (strstr(PKE_FILE_OBJ_END, readLine)) { if (entTypeCode[0] == '\0') { printf("[Game::ParseInstance] Failed to create instance from save file. No EntTypeCode present."); break; } int64_t existingEntityTypeIndex = EntityType_FindByTypeCode(entTypeCode); - if (existingEntityTypeIndex != -1) { + if (existingEntityTypeIndex == -1) { printf("[Game::ParseInstance] Failed to create instance from save file. Unknown EntityTypeCode: \"%s\"", entTypeCode); break; } @@ -230,7 +230,7 @@ void ParseInstance(std::ifstream &stream) { long index = 0; do { assert(index < 3); - STR2NUM_ERROR result = str2num(comp.instPos.scale[index], startingChar, pEnd); + STR2NUM_ERROR result = str2num(comp.instPos.pos[index], startingChar, pEnd); assert(result == STR2NUM_ERROR::SUCCESS); startingChar = pEnd + 1; ++index; @@ -245,7 +245,7 @@ void ParseInstance(std::ifstream &stream) { long index = 0; do { assert(index < 4); - STR2NUM_ERROR result = str2num(comp.instPos.scale[index], startingChar, pEnd); + STR2NUM_ERROR result = str2num(comp.instPos.rot[index], startingChar, pEnd); assert(result == STR2NUM_ERROR::SUCCESS); startingChar = pEnd + 1; ++index; @@ -298,6 +298,7 @@ void SaveSceneFile(const char *sceneFilePath) { const auto &instance = instances[i]; if (instance.entHandle == EntityHandle_MAX) continue; + f << PKE_FILE_OBJ_INSTANCE << std::endl; SerializeInstance(f, instance); f << PKE_FILE_OBJ_END << std::endl; } -- cgit v1.2.3