diff --git a/src/libtrx/filesystem.c b/src/libtrx/filesystem.c index 906032745..4ce3ab763 100644 --- a/src/libtrx/filesystem.c +++ b/src/libtrx/filesystem.c @@ -283,56 +283,56 @@ MYFILE *File_Open(const char *path, FILE_OPEN_MODE mode) return file; } -void File_ReadData(MYFILE *const file, void *const data, const size_t size) +bool File_ReadData(MYFILE *const file, void *const data, const size_t size) { - fread(data, size, 1, file->fp); + return fread(data, size, 1, file->fp) == 1; } -void File_ReadItems( +bool File_ReadItems( MYFILE *const file, void *data, const size_t count, const size_t item_size) { - fread(data, item_size, count, file->fp); + return fread(data, item_size, count, file->fp) == count; } int8_t File_ReadS8(MYFILE *const file) { int8_t result; - fread(&result, sizeof(result), 1, file->fp); + File_ReadData(file, &result, sizeof(result)); return result; } int16_t File_ReadS16(MYFILE *const file) { int16_t result; - fread(&result, sizeof(result), 1, file->fp); + File_ReadData(file, &result, sizeof(result)); return result; } int32_t File_ReadS32(MYFILE *const file) { int32_t result; - fread(&result, sizeof(result), 1, file->fp); + File_ReadData(file, &result, sizeof(result)); return result; } uint8_t File_ReadU8(MYFILE *const file) { uint8_t result; - fread(&result, sizeof(result), 1, file->fp); + File_ReadData(file, &result, sizeof(result)); return result; } uint16_t File_ReadU16(MYFILE *const file) { uint16_t result; - fread(&result, sizeof(result), 1, file->fp); + File_ReadData(file, &result, sizeof(result)); return result; } uint32_t File_ReadU32(MYFILE *const file) { uint32_t result; - fread(&result, sizeof(result), 1, file->fp); + File_ReadData(file, &result, sizeof(result)); return result; } diff --git a/src/libtrx/game/game_flow/reader.c b/src/libtrx/game/game_flow/reader.c index 26f096e74..77ff36e2e 100644 --- a/src/libtrx/game/game_flow/reader.c +++ b/src/libtrx/game/game_flow/reader.c @@ -108,12 +108,11 @@ static void M_LoadCommonSettings( if (tmp_value != nullptr && tmp_value->type == JSON_TYPE_ARRAY) { const JSON_ARRAY *const tmp_arr = JSON_ValueAsArray(tmp_value); const RGB_F color = { - JSON_ArrayGetDouble(tmp_arr, 0, JSON_INVALID_NUMBER), - JSON_ArrayGetDouble(tmp_arr, 1, JSON_INVALID_NUMBER), - JSON_ArrayGetDouble(tmp_arr, 2, JSON_INVALID_NUMBER), + JSON_ArrayGetDouble(tmp_arr, 0, -1.0), + JSON_ArrayGetDouble(tmp_arr, 1, -1.0), + JSON_ArrayGetDouble(tmp_arr, 2, -1.0), }; - if (color.r != JSON_INVALID_NUMBER && color.g != JSON_INVALID_NUMBER - && color.b != JSON_INVALID_NUMBER) { + if (color.r >= 0.0 && color.g >= 0.0 && color.b >= 0.0) { settings->water_color.is_present = true; settings->water_color.value = (RGB_888) { color.r * 255.0f, @@ -515,7 +514,8 @@ static void M_LoadTitleLevel(JSON_OBJECT *obj, GAME_FLOW *const gf) JSON_OBJECT *title_obj = JSON_ObjectGetObject(obj, "title"); if (title_obj != nullptr) { gf->title_level = Memory_Alloc(sizeof(GF_LEVEL)); - M_LoadLevel(title_obj, gf, gf->title_level, 0, GFL_TITLE); + M_LoadLevel( + title_obj, gf, gf->title_level, 0, (void *)(intptr_t)GFL_TITLE); } } diff --git a/src/libtrx/include/libtrx/filesystem.h b/src/libtrx/include/libtrx/filesystem.h index 20a789db5..584166af6 100644 --- a/src/libtrx/include/libtrx/filesystem.h +++ b/src/libtrx/include/libtrx/filesystem.h @@ -39,8 +39,8 @@ char *File_GuessExtension(const char *path, const char **extensions); MYFILE *File_Open(const char *path, FILE_OPEN_MODE mode); -void File_ReadData(MYFILE *file, void *data, size_t size); -void File_ReadItems(MYFILE *file, void *data, size_t count, size_t item_size); +bool File_ReadData(MYFILE *file, void *data, size_t size); +bool File_ReadItems(MYFILE *file, void *data, size_t count, size_t item_size); int8_t File_ReadS8(MYFILE *file); int16_t File_ReadS16(MYFILE *file); int32_t File_ReadS32(MYFILE *file); diff --git a/src/tr2/game/items.c b/src/tr2/game/items.c index b04adfdce..a66bb7eb3 100644 --- a/src/tr2/game/items.c +++ b/src/tr2/game/items.c @@ -364,7 +364,7 @@ const BOUNDS_16 *Item_GetBoundsAccurate(const ITEM *const item) ANIM_FRAME *Item_GetBestFrame(const ITEM *const item) { ANIM_FRAME *frames[2]; - int32_t rate; + int32_t rate = 0; const int32_t frac = Item_GetFrames(item, frames, &rate); return frames[(frac > rate / 2) ? 1 : 0]; } diff --git a/src/tr2/game/lara/draw.c b/src/tr2/game/lara/draw.c index 60cf7ce56..04fa37486 100644 --- a/src/tr2/game/lara/draw.c +++ b/src/tr2/game/lara/draw.c @@ -473,6 +473,13 @@ void Lara_Draw_I( Matrix_Rot16_ID(mesh_rots_1[LM_UARM_R], mesh_rots_2[LM_UARM_R]); Output_DrawObjectMesh_I(g_Lara.mesh_ptrs[LM_UARM_R], clip); +// NOTE: gcc wrongly complains about mesh_rots_1 possibly being NULL. +// While this is not the case, it's curious how the pistols subtract the +// frame_base from g_Lara.*_arm.frame_num to access the mesh_rots, and the +// rifles do not. +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Warray-bounds" + M_DrawBodyPart(LM_LARM_R, bone, mesh_rots_1, mesh_rots_2, clip); M_DrawBodyPart(LM_HAND_R, bone, mesh_rots_1, mesh_rots_2, clip); @@ -486,6 +493,8 @@ void Lara_Draw_I( M_DrawBodyPart(LM_LARM_L, bone, mesh_rots_1, mesh_rots_2, clip); M_DrawBodyPart(LM_HAND_L, bone, mesh_rots_1, mesh_rots_2, clip); +#pragma GCC diagnostic pop + if (g_Lara.right_arm.flash_gun) { *g_MatrixPtr = saved_matrix; Gun_DrawFlash(gun_type, clip); diff --git a/src/tr2/game/level.c b/src/tr2/game/level.c index 6ff60b7d0..2a128e8fe 100644 --- a/src/tr2/game/level.c +++ b/src/tr2/game/level.c @@ -143,22 +143,24 @@ static int32_t M_CompareSampleOffsets(const void *const a, const void *const b) static void M_InitialiseSoundEffects(const char *file_name) { BENCHMARK benchmark = Benchmark_Start(); + LEVEL_INFO *info = nullptr; SAMPLE_ENTRY *entries = nullptr; + if (file_name == nullptr) { file_name = g_GameFlow.settings.sfx_path; } const char *full_path = File_GetFullPath(file_name == nullptr ? DEFAULT_SFX_PATH : file_name); LOG_DEBUG("Loading samples from %s", full_path); + MYFILE *const fp = File_Open(full_path, FILE_OPEN_READ); Memory_FreePointer(&full_path); - if (fp == nullptr) { Shell_ExitSystemFmt("Could not open %s file", file_name); goto finish; } - LEVEL_INFO *const info = Level_GetInfo(); + info = Level_GetInfo(); const int32_t sample_count = info->samples.offset_count; entries = Memory_Alloc(sizeof(SAMPLE_ENTRY) * sample_count); for (int32_t i = 0; i < sample_count; i++) {