From d565295ea93c4d521d20f1bc3099b4dea1c5b32b Mon Sep 17 00:00:00 2001 From: shariq Date: Wed, 6 Sep 2017 21:13:48 +0500 Subject: [PATCH] Fixed missing new-line in light serialization and a bug caused by checking eof in scene files --- README.md | 3 ++- src/libsymmetry/entity.c | 2 +- src/libsymmetry/scene.c | 10 +++++++++- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 0ad02e4..0df8dae 100644 --- a/README.md +++ b/README.md @@ -151,7 +151,6 @@ - Add camera fbo params into camera struct so they can be saved and loaded into file - Finish loading scene from file - - Fix space not being added after some entities are written to file - Update makefiles to be able to compile the code in it's current state - Find a solution for the asset import/export situation by either updating the blender exporter or adding assimp as dependancy - Fix bugs with sound sources not updating @@ -313,3 +312,5 @@ * Made dll reloading workaround compatilble on linux * Default keybindings as fallback * Implemented writing scene to file + * Fixed space not being added after light entities are written to file by adding missing new-line + * Fixed error caused by the way eof was checked in scene file diff --git a/src/libsymmetry/entity.c b/src/libsymmetry/entity.c index 4eb6fe0..82516c9 100644 --- a/src/libsymmetry/entity.c +++ b/src/libsymmetry/entity.c @@ -261,7 +261,7 @@ bool entity_write(struct Entity* entity, FILE* file) fprintf(file, "valid: %s\n", entity->light.valid ? "true" : "false"); fprintf(file, "cast_shadow: %s\n", entity->light.cast_shadow ? "true" : "false"); fprintf(file, "pcf_enabled: %s\n", entity->light.pcf_enabled ? "true" : "false"); - fprintf(file, "color: %.5f %.5f %.5f", + fprintf(file, "color: %.5f %.5f %.5f\n", entity->light.color.x, entity->light.color.y, entity->light.color.z); diff --git a/src/libsymmetry/scene.c b/src/libsymmetry/scene.c index 4828850..396e16d 100644 --- a/src/libsymmetry/scene.c +++ b/src/libsymmetry/scene.c @@ -132,18 +132,26 @@ bool scene_load(const char* filename, int directory_type) } int count = 0; + int eof_char = -1; while(!feof(entity_file)) { + if(eof_char != -1) ungetc(eof_char, entity_file); struct Entity* new_entity = NULL; new_entity = entity_read(entity_file); if(!new_entity) + { log_error("scene:load", "Error reading entity"); + } else { log_message("Loaded %s", new_entity->name); count++; } - int c = fgetc(entity_file); + eof_char = fgetc(entity_file); + /* To check end of file, we get the next character and before beginning + loop we check if eof occured, feof only returns true if the last read + was an eof. If it wasn't eof then we return the character back to the + stream and carry on. */ } log_message("%d entites loaded from %s", count, filename);