From fd0183d34a53468a6c1552cf3419f45e6640aeb3 Mon Sep 17 00:00:00 2001 From: Sara Date: Wed, 22 Nov 2023 13:01:04 +0100 Subject: [PATCH] chore(windows port): Cleaned up some msvc warnings Mainly relating to double -> float casts and some size_t -> long casts --- core/src/assets.c | 14 ++++++-------- core/src/assets.h | 4 ++-- core/src/camera.c | 4 ++-- core/src/program.c | 6 +++--- core/src/vmath.h | 6 +++--- 5 files changed, 16 insertions(+), 18 deletions(-) diff --git a/core/src/assets.c b/core/src/assets.c index 6473d2c..0f90a1d 100644 --- a/core/src/assets.c +++ b/core/src/assets.c @@ -10,16 +10,16 @@ static asset_id _next_id = 0; static size_t file_length(FILE* fp) { - size_t start = ftell(fp); + long start = ftell(fp); fseek(fp, 0, SEEK_END); - size_t r = ftell(fp); + long r = ftell(fp); fseek(fp, start, SEEK_SET); - return r; + return (size_t)r; } static void read_file(FILE* fp, char* out_buffer, size_t out_size) { - size_t start = ftell(fp); + long start = ftell(fp); fread(out_buffer, 1, out_size, fp); fseek(fp, start, SEEK_SET); } @@ -88,15 +88,13 @@ asset_id get_asset_id(void* asset) { } void free_asset(asset_id id) { - Asset* found; - size_t found_index; + Asset* found = NULL; + size_t found_index = _assets.len; for(size_t i = 0; i < _assets.len; ++i) { found = list_at_as(Asset, &_assets, i); if(found->tc->get_id(found->data) == id) { found_index = i; break; - } else { - found = NULL; } } ASSERT_RETURN(found != NULL,, "Attempt to free nonexistent asset."); diff --git a/core/src/assets.h b/core/src/assets.h index 8f6a11b..579254a 100644 --- a/core/src/assets.h +++ b/core/src/assets.h @@ -31,8 +31,8 @@ size_t json_array_len(cJSON* array); static inline Vector json_array_to_vector(cJSON* array) { return (Vector) { - cJSON_GetArrayItem(array, 0)->valuedouble, - cJSON_GetArrayItem(array, 1)->valuedouble, + (float)cJSON_GetArrayItem(array, 0)->valuedouble, + (float)cJSON_GetArrayItem(array, 1)->valuedouble, }; } static inline diff --git a/core/src/camera.c b/core/src/camera.c index 80b7946..c9c896b 100644 --- a/core/src/camera.c +++ b/core/src/camera.c @@ -21,7 +21,7 @@ SDL_FRect camera_world_to_pixel_rect(Camera* self, SDL_FRect* world_space) { t.scale = OneVector; t = transform_invert(t); - Vector tl = {world_space->x + (self->fov / 2.0), world_space->y + (_camera_height(self) / 2.0)}; + Vector tl = {world_space->x + (self->fov / 2.0f), world_space->y + (_camera_height(self) / 2.0f)}; Vector size = {world_space->w, world_space->h}; tl = vmulff(transform_point(&t, tl), g_render_resolution.x / self->fov); @@ -40,7 +40,7 @@ Vector camera_world_to_pixel_point(Camera* self, Vector point) { t.scale = OneVector; t = transform_invert(t); - point = (Vector){point.x + (self->fov / 2.0), point.y + (_camera_height(self) / 2.0)}; + point = (Vector){point.x + (self->fov / 2.0f), point.y + (_camera_height(self) / 2.0f)}; return vmulff(transform_point(&t, point), g_render_resolution.x / self->fov); } diff --git a/core/src/program.c b/core/src/program.c index 62a7220..7f7ade9 100644 --- a/core/src/program.c +++ b/core/src/program.c @@ -25,7 +25,7 @@ double tstos(struct timespec ts) { struct timespec get_time() { struct timespec ts; - timespec_get(&ts, TIME_UTC); + (void)timespec_get(&ts, TIME_UTC); return ts; } @@ -132,10 +132,10 @@ void program_handle_windowevent(SDL_WindowEvent* event) { inline float delta_time() { - return _target_delta_time == 0 ? _delta_time : _target_delta_time; + return (float)(_target_delta_time == 0 ? _delta_time : _target_delta_time); } inline float game_time() { - return get_time_s() - _game_start_time; + return (float)(get_time_s() - _game_start_time); } diff --git a/core/src/vmath.h b/core/src/vmath.h index 4c92d6b..029463f 100644 --- a/core/src/vmath.h +++ b/core/src/vmath.h @@ -106,7 +106,7 @@ float vsqrmagnitudef(Vector a) { static inline Vector vnormalizedf(Vector a) { if(veqf(a, ZeroVector)) return ZeroVector; - return vmulff(a, 1.0/vmagnitudef(a)); + return vmulff(a, 1.0f/vmagnitudef(a)); } static inline float vdotf(Vector a, Vector b) { @@ -122,7 +122,7 @@ float vsqrdistf(Vector a, Vector b) { } static inline Vector vreciprocalf(Vector a) { - return (Vector){1.0/a.x, 1.0/a.y}; + return (Vector){1.0f/a.x, 1.0f/a.y}; } static inline Vector vrotatef(Vector a, float t) { @@ -157,7 +157,7 @@ Vector vaveragef(Vector* array, size_t count) { for(size_t i = 0; i < count; ++i) { acc = vaddf(acc, array[i]); } - return vmulff(acc, 1.0/(float)count); + return vmulff(acc, 1.0f/(float)count); } static inline