From aa318f53454ed9cbe935d59d51dc453ea78c4ed9 Mon Sep 17 00:00:00 2001 From: rr- Date: Mon, 22 Feb 2021 00:59:38 +0100 Subject: [PATCH] add -Wall --- Makefile | 2 +- src/game/data.h | 2 +- src/game/lara1gun.c | 2 +- src/game/text.c | 6 +++--- src/game/types.h | 16 ++++++++-------- src/mod.c | 5 ++--- src/specific/file.c | 2 +- src/specific/init.c | 6 +++--- src/util.c | 10 ++++++++++ src/util.h | 11 +++-------- 10 files changed, 33 insertions(+), 29 deletions(-) diff --git a/Makefile b/Makefile index aa74d1332..e40b9182c 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ CC=i686-w64-mingw32-gcc -CFLAGS=-W -Isrc +CFLAGS=-Wall -Isrc C_FILES = $(shell find src/ -type f -name '*.c') O_FILES = $(patsubst src/%.c, build/%.o, $(C_FILES)) diff --git a/src/game/data.h b/src/game/data.h index 8389e35de..eba779db7 100644 --- a/src/game/data.h +++ b/src/game/data.h @@ -20,7 +20,7 @@ #define PhdPersp VAR_U_(0x0069518C, int32_t) #define PhdFarZ VAR_U_(0x00695184, int32_t) #define PhdNearZ VAR_U_(0x006CAD04, int32_t) -#define FloorData VAR_U_(0x0045F1BC, uint16_t*) +#define FloorData VAR_U_(0x0045F1BC, int16_t*) #define StringToShow ARRAY_(0x00456AD0, char, [128]) #define MeshBase VAR_U_(0x0045F1B8, int16_t*) #define Meshes VAR_U_(0x00461F34, int16_t**) diff --git a/src/game/lara1gun.c b/src/game/lara1gun.c index d53ac1fd6..e8c33faa0 100644 --- a/src/game/lara1gun.c +++ b/src/game/lara1gun.c @@ -202,7 +202,7 @@ void __cdecl AnimateShotgun() void __cdecl FireShotgun() { - int i, r, fired; + int r, fired; PHD_ANGLE angles[2]; PHD_ANGLE dangles[2]; diff --git a/src/game/text.c b/src/game/text.c index 1be7abf79..0de0c557c 100644 --- a/src/game/text.c +++ b/src/game/text.c @@ -228,11 +228,11 @@ int32_t __cdecl T_GetTextWidth(TEXTSTRING* textstring) int width = 0; char* ptr = textstring->string; for (char letter = *ptr; *ptr; letter = *ptr++) { - if (letter == '\x7F' || letter > 10 && letter < 32) { + if (letter == 0x7F || (letter > 10 && letter < 32)) { continue; } - if (letter == ' ') { + if (letter == 32) { width += textstring->word_spacing * textstring->scale_h / PHD_ONE; continue; } @@ -245,7 +245,7 @@ int32_t __cdecl T_GetTextWidth(TEXTSTRING* textstring) letter = letter + 81; } - width += ((TextSpacing[letter] + textstring->letter_spacing) + width += ((TextSpacing[(uint8_t)letter] + textstring->letter_spacing) * textstring->scale_h) / PHD_ONE; } diff --git a/src/game/types.h b/src/game/types.h index 76c569ed9..b7d4ad394 100644 --- a/src/game/types.h +++ b/src/game/types.h @@ -682,10 +682,10 @@ typedef struct { } PHD_VECTOR; typedef struct { - /* 0000 */ uint16_t room_num; - /* 0002 */ uint16_t x; - /* 0004 */ uint16_t y; - /* 0006 */ uint16_t z; + /* 0000 */ int16_t room_num; + /* 0002 */ int16_t x; + /* 0004 */ int16_t y; + /* 0006 */ int16_t z; /* 0008 */ POS_3D vertex[4]; /* 0020 end */ } DOOR_INFO; @@ -795,9 +795,9 @@ typedef struct { } ITEM_INFO; typedef struct { - /* 0000 */ uint16_t* frame_base; - /* 0004 */ uint16_t frame_number; - /* 0006 */ uint16_t lock; + /* 0000 */ int16_t* frame_base; + /* 0004 */ int16_t frame_number; + /* 0006 */ int16_t lock; /* 0008 */ PHD_ANGLE y_rot; /* 000A */ PHD_ANGLE x_rot; /* 000C */ PHD_ANGLE z_rot; @@ -1226,7 +1226,7 @@ typedef struct { /* 0012 end */ } AI_INFO; -#pragma pop +#pragma pack(pop) typedef void(__cdecl* ControlRoutine)(ITEM_INFO*, COLL_INFO*); typedef void(__cdecl* CollisionRoutine)(ITEM_INFO*, COLL_INFO*); diff --git a/src/mod.c b/src/mod.c index 73aa5a3f2..14669430e 100644 --- a/src/mod.c +++ b/src/mod.c @@ -63,8 +63,7 @@ void Tomb1MRenderBar(int value, int value_max, int bar_type) { const int p1 = -100; const int p2 = -200; - const int p3 = -300; - const int p4 = -400; + const int p3 = -400; const int percent_max = 100; if (value < 0) { @@ -147,7 +146,7 @@ void Tomb1MRenderBar(int value, int value_max, int bar_type) for (int i = 0; i < height; i++) { int color_index = i * COLOR_BAR_SIZE / height; Insert2DLine( - left, top + i, right, top + i, p4, + left, top + i, right, top + i, p3, color_bar[bar_type][color_index]); } } diff --git a/src/specific/file.c b/src/specific/file.c index ee717a864..91b2cc401 100644 --- a/src/specific/file.c +++ b/src/specific/file.c @@ -307,7 +307,7 @@ int32_t __cdecl S_LoadLevel(int level_id) const char* __cdecl GetFullPath(const char* filename) { - TRACE(filename); + TRACE("%s", filename); #ifdef TOMB1M_FEAT_NOCD sprintf(newpath, ".\\%s", filename); #else diff --git a/src/specific/init.c b/src/specific/init.c index ed4b32282..88b840fba 100644 --- a/src/specific/init.c +++ b/src/specific/init.c @@ -10,14 +10,14 @@ #include #include -void __cdecl DB_Log(char* a1, ...) +void __cdecl DB_Log(char* fmt, ...) { va_list va; char buffer[256] = { 0 }; - va_start(va, a1); + va_start(va, fmt); if (!dword_45A1F0) { - vsprintf(buffer, a1, va); + vsprintf(buffer, fmt, va); TRACE(buffer); OutputDebugStringA(buffer); OutputDebugStringA("\n"); diff --git a/src/util.c b/src/util.c index 8fb588ed0..6cd409526 100644 --- a/src/util.c +++ b/src/util.c @@ -4,6 +4,16 @@ #include #include +void Tomb1MTraceFunc( + const char* file, int line, const char* func, const char* fmt, ...) +{ + va_list va; + va_start(va, fmt); + printf("%s %d %s ", file, line, func); + vprintf(fmt, va); + printf("\n"); +} + void Tomb1MInjectFunc(void* from, void* to) { DWORD tmp; diff --git a/src/util.h b/src/util.h index 3c0d05aea..cca742599 100644 --- a/src/util.h +++ b/src/util.h @@ -18,18 +18,13 @@ typedef struct { } JMP; #pragma pack(pop) -#define TRACE(...) \ - { \ - printf("%s:%d %s ", __FILE__, __LINE__, __func__); \ - printf(__VA_ARGS__); \ - printf("\n"); \ - fflush(stdout); \ - } - +#define TRACE(...) Tomb1MTraceFunc(__FILE__, __LINE__, __func__, __VA_ARGS__) #define VAR_U_(address, type) (*(type*)(address)) #define VAR_I_(address, type, value) (*(type*)(address)) #define ARRAY_(address, type, length) (*(type(*) length)(address)) +void Tomb1MTraceFunc( + const char* file, int line, const char* func, const char* fmt, ...); void Tomb1MInjectFunc(void* from, void* to); void Tomb1MPrintStackTrace();