diff options
| author | Jonathan Bradley <jcb@pikum.xyz> | 2023-10-04 16:52:40 -0400 |
|---|---|---|
| committer | Jonathan Bradley <jcb@pikum.xyz> | 2023-10-04 16:52:40 -0400 |
| commit | e12ba8979c54e45296ae748e5fb3e586ad4f0bdc (patch) | |
| tree | 3aa292381b78253cfa99bd3213eae94c5d6eb212 | |
| parent | 81e30ca719be3db253a93bf8328b39226ebb58e5 (diff) | |
saving and loading file with instances works as expected
| -rw-r--r-- | src/game.cpp | 9 | ||||
| -rw-r--r-- | src/helpers.cpp | 7 |
2 files changed, 8 insertions, 8 deletions
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<void *>(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; } diff --git a/src/helpers.cpp b/src/helpers.cpp index 7ae21c9..22be4de 100644 --- a/src/helpers.cpp +++ b/src/helpers.cpp @@ -124,7 +124,7 @@ STR2NUM_ERROR str2num(float &f, char const *s, char *&pEnd) { if (errno == ERANGE && l == -HUGE_VALF) { return UNDERFLOW; } - if (*s == '\0' || *pEnd != '\0') { + if (*s == '\0' || s == pEnd) { return INCONVERTIBLE; } f = l; @@ -137,17 +137,16 @@ STR2NUM_ERROR str2num(float &f, char const *s) { } STR2NUM_ERROR str2num(double &d, char const *s, char *&pEnd) { - char *end; float l; errno = 0; - l = strtod(s, &end); + l = strtod(s, &pEnd); if (errno == ERANGE && l == HUGE_VAL) { return OVERFLOW; } if (errno == ERANGE && l == -HUGE_VAL) { return UNDERFLOW; } - if (*s == '\0' || *end != '\0') { + if (*s == '\0' || s == pEnd) { return INCONVERTIBLE; } d = l; |
