effort to have no warnings once again

This commit is contained in:
veclav talica 2024-10-13 21:32:31 +03:00
parent d884cd45d9
commit da98c0941b
15 changed files with 84 additions and 43 deletions

View File

@ -175,20 +175,19 @@ function(give_options_without_warnings target)
target_compile_options(${target} PUBLIC
${BUILD_FLAGS}
$<$<CONFIG:Release>:${BUILD_FLAGS_RELEASE}>
$<$<CONFIG:Debug>:${BUILD_FLAGS_DEBUG}>
$<$<BOOL:${LINUX}>:-Wl,-rpath,$ORIGIN/>)
$<$<CONFIG:Debug>:${BUILD_FLAGS_DEBUG}>)
target_link_options(${target} PUBLIC
${BUILD_FLAGS}
# -Wl,--no-undefined # TODO: use later for implementing no-libc
$<$<CONFIG:Release>:${BUILD_FLAGS_RELEASE}>
$<$<CONFIG:Debug>:${BUILD_FLAGS_DEBUG}>
$<$<BOOL:${LINUX}>:-Wl,-rpath,$ORIGIN/>
-Bsymbolic-functions
-Wl,--hash-style=gnu)
target_compile_definitions(${target} PRIVATE
$<$<BOOL:${TWN_FEATURE_DYNLIB_GAME}>:TWN_FEATURE_DYNLIB_GAME>)
$<$<BOOL:${TWN_FEATURE_DYNLIB_GAME}>:TWN_FEATURE_DYNLIB_GAME>
_GNU_SOURCE)
endfunction()
@ -200,7 +199,8 @@ function(give_options target)
-Wno-padded
-Wno-declaration-after-statement
-Wno-unsafe-buffer-usage
-Wno-unused-command-line-argument)
-Wno-unused-command-line-argument
-Wno-covered-switch-default)
set(WARNING_FLAGS
-Wall
@ -264,6 +264,8 @@ function(use_townengine target sources output_directory)
# launcher binary, loads game and engine shared library
add_executable(${target} ${TWN_ROOT_DIR}/src/twn_main.c)
target_compile_options(${target} PRIVATE $<$<BOOL:${LINUX}>:-Wl,-rpath,$ORIGIN/>)
# todo: copy instead?
# put libtownengine.so alongside the binary
set_target_properties(${TWN_TARGET} PROPERTIES

View File

@ -13,7 +13,7 @@
#define RIGHT_CLICK_ADD 500
void handle_input(void)
static void handle_input(void)
{
State *state = ctx.udata;

View File

@ -39,7 +39,7 @@ static void load_game_object(void) {
goto ERR_OPENING_SO;
}
#pragma GCC diagnostic push
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wpedantic"
game_tick_callback = (void (*)(void))dlsym(new_handle, "game_tick");
@ -83,6 +83,7 @@ static void watcher_callback(XWATCHER_FILE_EVENT event,
(void)data;
switch(event) {
case XWATCHER_FILE_CREATED:
case XWATCHER_FILE_MODIFIED:
SDL_LockMutex(lock);
last_tick_modified = ctx.game.frame_number;
@ -90,6 +91,12 @@ static void watcher_callback(XWATCHER_FILE_EVENT event,
SDL_UnlockMutex(lock);
break;
case XWATCHER_FILE_UNSPECIFIED:
case XWATCHER_FILE_REMOVED:
case XWATCHER_FILE_OPENED:
case XWATCHER_FILE_ATTRIBUTES_CHANGED:
case XWATCHER_FILE_NONE:
case XWATCHER_FILE_RENAMED:
default:
break;
}

View File

@ -223,6 +223,8 @@ static void render_2d(void) {
case PRIMITIVE_2D_TEXT:
render_text(&current->text);
break;
default:
SDL_assert(false);
}
}
}

View File

@ -194,6 +194,8 @@ void use_2d_pipeline(void);
void use_texture_mode(TextureMode mode);
void upload_quad_vertices(Rect rect);
void finally_render_sprites(Primitive2D const primitives[],
struct SpriteBatch batch,
VertexBuffer buffer);

View File

@ -3,7 +3,7 @@
#include <SDL2/SDL.h>
char *paths_in_use;
static char *paths_in_use;
void draw_skybox(const char *paths) {
if (paths_in_use && SDL_strcmp(paths, paths_in_use) == 0)

View File

@ -199,9 +199,14 @@ void render_sprites(const Primitive2D primitives[],
v2 = (Vec2){ sprite.rect.x + sprite.rect.w, sprite.rect.y + sprite.rect.h };
v3 = (Vec2){ sprite.rect.x + sprite.rect.w, sprite.rect.y };
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wfloat-equal"
} else if (sprite.rect.w == sprite.rect.h) {
/* rotated square case */
#pragma GCC diagnostic pop
const Vec2 c = frect_center(sprite.rect);
const Vec2 t = fast_cossine(sprite.rotation + (float)M_PI_4);
const Vec2 d = {

View File

@ -35,7 +35,7 @@ void draw_triangle(const char *path,
.uv2 = uv2,
}};
union UncoloredSpaceTriangle *triangles = (union UncoloredSpaceTriangle *)batch_p->value.primitives;
union UncoloredSpaceTriangle *triangles = (union UncoloredSpaceTriangle *)(void *)batch_p->value.primitives;
arrpush(triangles, triangle);
batch_p->value.primitives = (uint8_t *)triangles;
@ -66,7 +66,7 @@ void draw_uncolored_space_traingle_batch(struct MeshBatch *batch,
/* update pixel-based uvs to correspond with texture atlases */
for (size_t i = 0; i < primitives_len; ++i) {
struct UncoloredSpaceTrianglePayload *payload =
&((union UncoloredSpaceTriangle *)batch->primitives)[i].payload;
&((union UncoloredSpaceTriangle *)(void *)batch->primitives)[i].payload;
payload->uv0.x = xr + ((float)payload->uv0.x / srcrect.w) * wr;
payload->uv0.y = yr + ((float)payload->uv0.y / srcrect.h) * hr;

View File

@ -7,7 +7,6 @@
#include <sys/auxv.h>
#include <elf.h>
#include <linux/limits.h>
#define __USE_GNU
#include <dlfcn.h>
#include <SDL2/SDL.h>

View File

@ -126,6 +126,8 @@ static union AudioContext init_audio_context(const char *path, AudioFileType typ
};
}
case AUDIO_FILE_TYPE_UNKNOWN:
case AUDIO_FILE_TYPE_COUNT:
default:
CRY("Audio error", "Unhandled audio format (in init)");
return (union AudioContext){0};
@ -147,6 +149,8 @@ static void repeat_audio(AudioChannel *channel) {
break;
}
case AUDIO_FILE_TYPE_UNKNOWN:
case AUDIO_FILE_TYPE_COUNT:
default:
CRY("Audio error", "Unhandled audio format (in repeat)");
break;
@ -219,6 +223,8 @@ TWN_API void audio_set(const char *channel, AudioParam param, float value) {
}
pair->value.panning = value;
break;
default:
CRY("Audio channel parameter setting failed", "Invalid parameter enum given");
}
}
@ -229,8 +235,8 @@ static void audio_mixin_streams(const AudioChannel *channel,
uint8_t *restrict b,
size_t frames)
{
float *const sa = (float *)a;
float *const sb = (float *)b;
float *const sa = (float *)(void *)a;
float *const sb = (float *)(void *)b;
const float left_panning = fminf(fabsf(channel->panning - 1.0f), 1.0f);
const float right_panning = fminf(fabsf(channel->panning + 1.0f), 1.0f);
@ -321,6 +327,8 @@ static void audio_sample_and_mixin_channel(const AudioChannel *channel,
break;
}
case AUDIO_FILE_TYPE_UNKNOWN:
case AUDIO_FILE_TYPE_COUNT:
default:
CRY("Audio error", "Unhandled audio format (in sampling)");
break;

View File

@ -15,6 +15,12 @@ static void update_action_pressed_state(InputState *input, Action *action) {
switch (action->bindings[i].source) {
case BUTTON_SOURCE_NOT_SET:
break;
case BUTTON_SOURCE_KEYBOARD_CHARACTER:
CRY("Action pressed state updated failed", "BUTTON_SOURCE_KEYBOARD_CHARACTER isn't handled");
break;
case BUTTON_SOURCE_GAMEPAD:
CRY("Action pressed state updated failed", "BUTTON_SOURCE_GAMEPAD isn't handled");
break;
case BUTTON_SOURCE_KEYBOARD_PHYSICAL:
/* not pressed */
if (input->keyboard_state[action->bindings[i].code.scancode] == 0) {
@ -98,6 +104,8 @@ static void input_bind_code_to_action(InputState *input,
case BUTTON_SOURCE_MOUSE:
is_already_bound = binding->code.mouse_button == code.mouse_button;
break;
default:
SDL_assert(false);
}
if (is_already_bound) {
@ -156,6 +164,8 @@ static void input_unbind_code_from_action(InputState *input,
case BUTTON_SOURCE_MOUSE:
is_bound = binding->code.mouse_button == code.mouse_button;
break;
default:
SDL_assert(false);
}
/* stop early, this won't change */
@ -220,7 +230,7 @@ void input_bind_action_control(char const *action_name,
input_bind_code_to_action(&ctx.input,
action_name,
BUTTON_SOURCE_MOUSE,
(union ButtonCode) { .mouse_button = SDL_BUTTON(mouse_button)});
(union ButtonCode) { .mouse_button = (uint8_t)SDL_BUTTON(mouse_button)});
} else
log_warn("(%s) Invalid control value given: %i.", __func__, control);
}
@ -242,7 +252,7 @@ void input_unbind_action_control(char const *action_name,
input_unbind_code_from_action(&ctx.input,
action_name,
BUTTON_SOURCE_MOUSE,
(union ButtonCode) { .mouse_button = SDL_BUTTON(mouse_button)});
(union ButtonCode) { .mouse_button = (uint8_t)SDL_BUTTON(mouse_button)});
} else
log_warn("(%s) Invalid control value given: %i.", __func__, control);
}

View File

@ -112,7 +112,7 @@ static void APIENTRY opengl_log(GLenum source,
#endif
void preserve_persistent_ctx_fields(void) {
static void preserve_persistent_ctx_fields(void) {
ctx.game.udata = ctx.game_copy.udata;
}

View File

@ -394,7 +394,7 @@ void textures_update_atlas(TextureCache *cache) {
add_new_atlas(cache);
++cache->atlas_index;
}
};
}
update_texture_rects_in_atlas(cache, rects);
recreate_current_atlas_texture(cache);

View File

@ -17,10 +17,16 @@ void cry_impl(const char *file, const int line, const char *title, const char *t
static void log_impl(const char *restrict format, va_list args, SDL_LogPriority priority) {
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wformat-nonliteral"
SDL_LogMessageV(SDL_LOG_CATEGORY_APPLICATION,
priority,
format,
args);
#pragma GCC diagnostic pop
}

View File

@ -476,7 +476,7 @@ extern void stbds_rand_seed(size_t seed);
// these are the hash functions used internally if you want to test them or use them for other purposes
extern size_t stbds_hash_bytes(void *p, size_t len, size_t seed);
extern size_t stbds_hash_string(char *str, size_t seed);
extern size_t stbds_hash_string(char const*str, size_t seed);
// this is a simple string arena allocator, initialize with e.g. 'stbds_string_arena my_arena={0}'.
typedef struct stbds_string_arena stbds_string_arena;
@ -494,11 +494,11 @@ extern void stbds_unit_tests(void);
extern void * stbds_arrgrowf(void *a, size_t elemsize, size_t addlen, size_t min_cap);
extern void stbds_arrfreef(void *a);
extern void stbds_hmfree_func(void *p, size_t elemsize);
extern void * stbds_hmget_key(void *a, size_t elemsize, void *key, size_t keysize, int mode);
extern void * stbds_hmget_key_ts(void *a, size_t elemsize, void *key, size_t keysize, ptrdiff_t *temp, int mode);
extern void * stbds_hmget_key(void *a, size_t elemsize, void const*key, size_t keysize, int mode);
extern void * stbds_hmget_key_ts(void *a, size_t elemsize, void const*key, size_t keysize, ptrdiff_t *temp, int mode);
extern void * stbds_hmput_default(void *a, size_t elemsize);
extern void * stbds_hmput_key(void *a, size_t elemsize, void *key, size_t keysize, int mode);
extern void * stbds_hmdel_key(void *a, size_t elemsize, void *key, size_t keysize, size_t keyoffset, int mode);
extern void * stbds_hmput_key(void *a, size_t elemsize, void const*key, size_t keysize, int mode);
extern void * stbds_hmdel_key(void *a, size_t elemsize, void const*key, size_t keysize, size_t keyoffset, int mode);
extern void * stbds_shmode_func(size_t elemsize, int mode);
#ifdef __cplusplus
@ -531,7 +531,7 @@ extern void * stbds_shmode_func(size_t elemsize, int mode);
#define STBDS_OFFSETOF(var,field) ((char *) &(var)->field - (char *) (var))
#define stbds_header(t) ((stbds_array_header *) (t) - 1)
#define stbds_header(t) (((stbds_array_header *) (void *) (t)) - 1)
#define stbds_temp(t) stbds_header(t)->temp
#define stbds_temp_key(t) (*(char **) stbds_header(t)->hash_table)
@ -561,7 +561,7 @@ extern void * stbds_shmode_func(size_t elemsize, int mode);
#define stbds_arrgrow(a,b,c) ((a) = stbds_arrgrowf_wrapper((a), sizeof *(a), (b), (c)))
#define stbds_hmput(t, k, v) \
((t) = stbds_hmput_key_wrapper((t), sizeof *(t), (void*) STBDS_ADDRESSOF((t)->key, (k)), sizeof (t)->key, 0), \
((t) = stbds_hmput_key_wrapper((t), sizeof *(t), (void const*) STBDS_ADDRESSOF((t)->key, (k)), sizeof (t)->key, 0), \
(t)[stbds_temp((t)-1)].key = (k), \
(t)[stbds_temp((t)-1)].value = (v))
@ -570,11 +570,11 @@ extern void * stbds_shmode_func(size_t elemsize, int mode);
(t)[stbds_temp((t)-1)] = (s))
#define stbds_hmgeti(t,k) \
((t) = stbds_hmget_key_wrapper((t), sizeof *(t), (void*) STBDS_ADDRESSOF((t)->key, (k)), sizeof (t)->key, STBDS_HM_BINARY), \
((t) = stbds_hmget_key_wrapper((t), sizeof *(t), (void const*) STBDS_ADDRESSOF((t)->key, (k)), sizeof (t)->key, STBDS_HM_BINARY), \
stbds_temp((t)-1))
#define stbds_hmgeti_ts(t,k,temp) \
((t) = stbds_hmget_key_ts_wrapper((t), sizeof *(t), (void*) STBDS_ADDRESSOF((t)->key, (k)), sizeof (t)->key, &(temp), STBDS_HM_BINARY), \
((t) = stbds_hmget_key_ts_wrapper((t), sizeof *(t), (void const*) STBDS_ADDRESSOF((t)->key, (k)), sizeof (t)->key, &(temp), STBDS_HM_BINARY), \
(temp))
#define stbds_hmgetp(t, k) \
@ -584,7 +584,7 @@ extern void * stbds_shmode_func(size_t elemsize, int mode);
((void) stbds_hmgeti_ts(t,k,temp), &(t)[temp])
#define stbds_hmdel(t,k) \
(((t) = stbds_hmdel_key_wrapper((t),sizeof *(t), (void*) STBDS_ADDRESSOF((t)->key, (k)), sizeof (t)->key, STBDS_OFFSETOF((t),key), STBDS_HM_BINARY)),(t)?stbds_temp((t)-1):0)
(((t) = stbds_hmdel_key_wrapper((t),sizeof *(t), (void const*) STBDS_ADDRESSOF((t)->key, (k)), sizeof (t)->key, STBDS_OFFSETOF((t),key), STBDS_HM_BINARY)),(t)?stbds_temp((t)-1):0)
#define stbds_hmdefault(t, v) \
((t) = stbds_hmput_default_wrapper((t), sizeof *(t)), (t)[-1].value = (v))
@ -603,28 +603,28 @@ extern void * stbds_shmode_func(size_t elemsize, int mode);
#define stbds_hmgetp_null(t,k) (stbds_hmgeti(t,k) == -1 ? NULL : &(t)[stbds_temp((t)-1)])
#define stbds_shput(t, k, v) \
((t) = stbds_hmput_key_wrapper((t), sizeof *(t), (void*) (k), sizeof (t)->key, STBDS_HM_STRING), \
((t) = stbds_hmput_key_wrapper((t), sizeof *(t), (void const*) (k), sizeof (t)->key, STBDS_HM_STRING), \
(t)[stbds_temp((t)-1)].value = (v))
#define stbds_shputi(t, k, v) \
((t) = stbds_hmput_key_wrapper((t), sizeof *(t), (void*) (k), sizeof (t)->key, STBDS_HM_STRING), \
((t) = stbds_hmput_key_wrapper((t), sizeof *(t), (void const*) (k), sizeof (t)->key, STBDS_HM_STRING), \
(t)[stbds_temp((t)-1)].value = (v), stbds_temp((t)-1))
#define stbds_shputs(t, s) \
((t) = stbds_hmput_key_wrapper((t), sizeof *(t), (void*) (s).key, sizeof (s).key, STBDS_HM_STRING), \
((t) = stbds_hmput_key_wrapper((t), sizeof *(t), (void const*) (s).key, sizeof (s).key, STBDS_HM_STRING), \
(t)[stbds_temp((t)-1)] = (s), \
(t)[stbds_temp((t)-1)].key = stbds_temp_key((t)-1)) // above line overwrites whole structure, so must rewrite key here if it was allocated internally
#define stbds_pshput(t, p) \
((t) = stbds_hmput_key_wrapper((t), sizeof *(t), (void*) (p)->key, sizeof (p)->key, STBDS_HM_PTR_TO_STRING), \
((t) = stbds_hmput_key_wrapper((t), sizeof *(t), (void const*) (p)->key, sizeof (p)->key, STBDS_HM_PTR_TO_STRING), \
(t)[stbds_temp((t)-1)] = (p))
#define stbds_shgeti(t,k) \
((t) = stbds_hmget_key_wrapper((t), sizeof *(t), (void*) (k), sizeof (t)->key, STBDS_HM_STRING), \
((t) = stbds_hmget_key_wrapper((t), sizeof *(t), (void const*) (k), sizeof (t)->key, STBDS_HM_STRING), \
stbds_temp((t)-1))
#define stbds_pshgeti(t,k) \
((t) = stbds_hmget_key_wrapper((t), sizeof *(t), (void*) (k), sizeof (*(t))->key, STBDS_HM_PTR_TO_STRING), \
((t) = stbds_hmget_key_wrapper((t), sizeof *(t), (void const*) (k), sizeof (*(t))->key, STBDS_HM_PTR_TO_STRING), \
stbds_temp((t)-1))
#define stbds_shgetp(t, k) \
@ -634,9 +634,9 @@ extern void * stbds_shmode_func(size_t elemsize, int mode);
((void) stbds_pshgeti(t,k), (t)[stbds_temp((t)-1)])
#define stbds_shdel(t,k) \
(((t) = stbds_hmdel_key_wrapper((t),sizeof *(t), (void*) (k), sizeof (t)->key, STBDS_OFFSETOF((t),key), STBDS_HM_STRING)),(t)?stbds_temp((t)-1):0)
(((t) = stbds_hmdel_key_wrapper((t),sizeof *(t), (void const*) (k), sizeof (t)->key, STBDS_OFFSETOF((t),key), STBDS_HM_STRING)),(t)?stbds_temp((t)-1):0)
#define stbds_pshdel(t,k) \
(((t) = stbds_hmdel_key_wrapper((t),sizeof *(t), (void*) (k), sizeof (*(t))->key, STBDS_OFFSETOF(*(t),key), STBDS_HM_PTR_TO_STRING)),(t)?stbds_temp((t)-1):0)
(((t) = stbds_hmdel_key_wrapper((t),sizeof *(t), (void const*) (k), sizeof (*(t))->key, STBDS_OFFSETOF(*(t),key), STBDS_HM_PTR_TO_STRING)),(t)?stbds_temp((t)-1):0)
#define stbds_sh_new_arena(t) \
((t) = stbds_shmode_func_wrapper(t, sizeof *(t), STBDS_SH_ARENA))
@ -702,10 +702,10 @@ template<class T> static T * stbds_hmget_key_ts_wrapper(T *a, size_t elemsize, v
template<class T> static T * stbds_hmput_default_wrapper(T *a, size_t elemsize) {
return (T*)stbds_hmput_default((void *)a, elemsize);
}
template<class T> static T * stbds_hmput_key_wrapper(T *a, size_t elemsize, void *key, size_t keysize, int mode) {
template<class T> static T * stbds_hmput_key_wrapper(T *a, size_t elemsize, void const*key, size_t keysize, int mode) {
return (T*)stbds_hmput_key((void*)a, elemsize, key, keysize, mode);
}
template<class T> static T * stbds_hmdel_key_wrapper(T *a, size_t elemsize, void *key, size_t keysize, size_t keyoffset, int mode){
template<class T> static T * stbds_hmdel_key_wrapper(T *a, size_t elemsize, void const*key, size_t keysize, size_t keyoffset, int mode){
return (T*)stbds_hmdel_key((void*)a, elemsize, key, keysize, keyoffset, mode);
}
template<class T> static T * stbds_shmode_func_wrapper(T *, size_t elemsize, int mode) {
@ -1013,7 +1013,7 @@ static stbds_hash_index *stbds_make_hash_index(size_t slot_count, stbds_hash_ind
#define STBDS_ROTATE_LEFT(val, n) (((val) << (n)) | ((val) >> (STBDS_SIZE_T_BITS - (n))))
#define STBDS_ROTATE_RIGHT(val, n) (((val) >> (n)) | ((val) << (STBDS_SIZE_T_BITS - (n))))
size_t stbds_hash_string(char *str, size_t seed)
size_t stbds_hash_string(char const*str, size_t seed)
{
size_t hash = seed;
while (*str)
@ -1278,7 +1278,7 @@ static ptrdiff_t stbds_hm_find_slot(void *a, size_t elemsize, void *key, size_t
/* NOTREACHED */
}
void * stbds_hmget_key_ts(void *a, size_t elemsize, void *key, size_t keysize, ptrdiff_t *temp, int mode)
void * stbds_hmget_key_ts(void *a, size_t elemsize, void const*key, size_t keysize, ptrdiff_t *temp, int mode)
{
size_t keyoffset = 0;
if (a == NULL) {
@ -1309,7 +1309,7 @@ void * stbds_hmget_key_ts(void *a, size_t elemsize, void *key, size_t keysize, p
}
}
void * stbds_hmget_key(void *a, size_t elemsize, void *key, size_t keysize, int mode)
void * stbds_hmget_key(void *a, size_t elemsize, void const*key, size_t keysize, int mode)
{
ptrdiff_t temp;
void *p = stbds_hmget_key_ts(a, elemsize, key, keysize, &temp, mode);
@ -1334,7 +1334,7 @@ void * stbds_hmput_default(void *a, size_t elemsize)
static char *stbds_strdup(char *str);
void *stbds_hmput_key(void *a, size_t elemsize, void *key, size_t keysize, int mode)
void *stbds_hmput_key(void *a, size_t elemsize, void const *key, size_t keysize, int mode)
{
size_t keyoffset=0;
void *raw_a;
@ -1370,7 +1370,7 @@ void *stbds_hmput_key(void *a, size_t elemsize, void *key, size_t keysize, int m
// we iterate hash table explicitly because we want to track if we saw a tombstone
{
size_t hash = mode >= STBDS_HM_STRING ? stbds_hash_string((char*)key,table->seed) : stbds_hash_bytes(key, keysize,table->seed);
size_t hash = mode >= STBDS_HM_STRING ? stbds_hash_string((char const*)key,table->seed) : stbds_hash_bytes(key, keysize,table->seed);
size_t step = STBDS_BUCKET_LENGTH;
size_t pos;
ptrdiff_t tombstone = -1;
@ -1469,7 +1469,7 @@ void * stbds_shmode_func(size_t elemsize, int mode)
return STBDS_ARR_TO_HASH(a,elemsize);
}
void * stbds_hmdel_key(void *a, size_t elemsize, void *key, size_t keysize, size_t keyoffset, int mode)
void * stbds_hmdel_key(void *a, size_t elemsize, void const*key, size_t keysize, size_t keyoffset, int mode)
{
if (a == NULL) {
return 0;