From 2bf6bea14f88306beb8f1ffce76b439e59d1459c Mon Sep 17 00:00:00 2001 From: Sara Date: Wed, 29 Nov 2023 14:12:44 +0100 Subject: [PATCH] fix(types): removed implicit type casts --- core/src/animation_sprite.c | 2 +- core/src/input.c | 7 ++++--- core/src/input_axis.c | 8 ++++---- core/src/physics_entity.c | 2 +- core/src/render.c | 4 ++-- core/src/rigidbody.c | 4 ++-- core/src/shape.c | 2 +- game/src/PlayerStates.c | 3 ++- game/src/beat-em-up.c | 8 ++++---- 9 files changed, 21 insertions(+), 19 deletions(-) diff --git a/core/src/animation_sprite.c b/core/src/animation_sprite.c index 40a8f3c..d54c03c 100644 --- a/core/src/animation_sprite.c +++ b/core/src/animation_sprite.c @@ -39,7 +39,7 @@ void animation_sprite_draw(AnimationSprite* self, Transform* transform) { const size_t frame_count = spritesheet_get_tile_count(self->sheet); const float time = game_time() - self->start_time; - size_t frame = time / self->frame_interval; + size_t frame = (size_t)(time / self->frame_interval); switch(self->loop_mode) { case LoopMode_Hide: diff --git a/core/src/input.c b/core/src/input.c index 8c6d162..a8f0e31 100644 --- a/core/src/input.c +++ b/core/src/input.c @@ -20,8 +20,9 @@ void _internal_open_keyboard() { } static inline -void _internal_open_controller(size_t id) { +void _internal_open_controller(int id) { InputDevice* device = malloc(sizeof(InputDevice)); + ASSERT_RETURN(device != NULL, , "Failed to allocate space for gamecontroller input device"); *device = (InputDevice) { .listeners = NULL, .type = InputDevice_Gamepad, @@ -42,8 +43,8 @@ void input_init() { _internal_open_keyboard(); // open any controllers already available - const size_t joystick_count = SDL_NumJoysticks(); - for(size_t i = 0; i < joystick_count; ++i) { + const int joystick_count = SDL_NumJoysticks(); + for(int i = 0; i < joystick_count; ++i) { _internal_open_controller(i); } } diff --git a/core/src/input_axis.c b/core/src/input_axis.c index be26af9..d5233de 100644 --- a/core/src/input_axis.c +++ b/core/src/input_axis.c @@ -50,7 +50,7 @@ int controlleraxis_is_changed_by(ControllerAxis* self, SDL_Event event) { } InputEvent controlleraxis_evaluate(ControllerAxis* self, SDL_Event event) { - float result = (float)event.caxis.value / 32767.0; + float result = (float)event.caxis.value / 32767.0f; return (InputEvent) { .type = InputEvent_Float, .as_float = result @@ -116,19 +116,19 @@ InputEvent _internal_event_to_type(InputEventType type, InputEvent event) { LOG_ERROR("No (1)"); break; case InputEvent_Bool: - as_float = event.as_bool; + as_float = (float)event.as_bool; break; case InputEvent_Float: as_float = event.as_float; break; case InputEvent_Int: - as_float = event.as_int; + as_float = (float)event.as_int; break; } event.type = type; switch(type) { case InputEvent_Int: - event.as_int = round(as_float); + event.as_int = (int)round(as_float); return event; case InputEvent_Float: event.as_float = as_float; diff --git a/core/src/physics_entity.c b/core/src/physics_entity.c index 660f63e..48f6451 100644 --- a/core/src/physics_entity.c +++ b/core/src/physics_entity.c @@ -72,7 +72,7 @@ void physics_entity_solve_contacts(PhysicsEntity self, List* contacts) { float dot = vdotf(dir, vel); if(dot < 0) - vel = vsubf(vel, vmulff(dir, dot * (1.0 + rigidbody_get_bounce(body)))); + vel = vsubf(vel, vmulff(dir, dot * (1.0f + rigidbody_get_bounce(body)))); rigidbody_set_velocity(body, vel); } diff --git a/core/src/render.c b/core/src/render.c index 57e11ad..f569593 100644 --- a/core/src/render.c +++ b/core/src/render.c @@ -62,10 +62,10 @@ void render_calculate_render_area() { // calculate the largest area that will fit the entire rendertexture into the window space g_render_area = (SDL_Rect) {0, 0, window_resolution.x, window_resolution.y}; if(window_aspect <= target_aspect) { - g_render_area.h = window_resolution.x / target_aspect; + g_render_area.h = (int)((float)window_resolution.x / target_aspect); g_render_area.y = (window_resolution.y - g_render_area.h) / 2; } else { - g_render_area.w = window_resolution.y * target_aspect; + g_render_area.w = (int)((float)window_resolution.y * target_aspect); g_render_area.x += (window_resolution.x - g_render_area.w) / 2; } } diff --git a/core/src/rigidbody.c b/core/src/rigidbody.c index 56be4f9..c45d14e 100644 --- a/core/src/rigidbody.c +++ b/core/src/rigidbody.c @@ -84,11 +84,11 @@ void _internal_debug_draw_collision_edge(RigidBody* self, Contact* contact) { Vector b = camera_world_to_pixel_point(&g_camera, right); Vector n = transform_direction(&g_camera.transform, contact->hit.normal); SDL_SetRenderDrawColor(g_renderer, 255, 2, 255, 255); - SDL_RenderDrawLine(g_renderer, a.x, a.y, b.x, b.y); + SDL_RenderDrawLineF(g_renderer, a.x, a.y, b.x, b.y); a = camera_world_to_pixel_point(&g_camera, point); b = vaddf(a, vmulff(n, 100.f)); SDL_SetRenderDrawColor(g_renderer, 255, 0, 0, 255); - SDL_RenderDrawLine(g_renderer, a.x, a.y, b.x, b.y); + SDL_RenderDrawLineF(g_renderer, a.x, a.y, b.x, b.y); #endif } diff --git a/core/src/shape.c b/core/src/shape.c index d111710..52bc5d1 100644 --- a/core/src/shape.c +++ b/core/src/shape.c @@ -55,7 +55,7 @@ Vector _shape_calculate_mean(Shape* self) { size_t count = 0; list_foreach(Vector*, point, &self->points) { ++count; - avg = vaddf(avg, vmulff(*point, 1.0/count)); + avg = vaddf(avg, vmulff(*point, 1.f/count)); } return avg; diff --git a/game/src/PlayerStates.c b/game/src/PlayerStates.c index 7480033..7720551 100644 --- a/game/src/PlayerStates.c +++ b/game/src/PlayerStates.c @@ -1,5 +1,6 @@ #include "PlayerStates.h" #include "Player.h" +#include "Layers.h" #include "physics_world.h" static inline @@ -53,7 +54,7 @@ void PlayerAttackEnter(Player* self) { static void PlayerAttackTrigger(Player* self) { Collider* found = physics_world_box_query(vaddf(self->transform.position, MakeVector(self->facing * (0.2f + 0.1f), 0.f)), - MakeVector(0.1f, 0.06f), PHYSICS_LAYER_DEFAULT, self->rigidbody); + MakeVector(0.1f, 0.06f), PHYSICS_LAYER_COMBAT, self->rigidbody); if(found != NULL) { PhysicsEntity entity = collider_get_owner(found); entity.message_receiver->handle_message(entity.data, 1, (void*)1u); diff --git a/game/src/beat-em-up.c b/game/src/beat-em-up.c index 44803bc..29909c3 100644 --- a/game/src/beat-em-up.c +++ b/game/src/beat-em-up.c @@ -9,10 +9,10 @@ void play() { SpawnProp(MakeVector(2.f, 0.f), sprite_from_spritesheet(spritesheet_load("assets/bag.png", IVectorFrom(512)), 0), shape_new((Vector[]){ - MakeVector(-0.2, -0.075), - MakeVector( 0.2, -0.075), - MakeVector( 0.2, 0.075), - MakeVector(-0.2, 0.075) + MakeVector(-0.2f, -0.075f), + MakeVector( 0.2f, -0.075f), + MakeVector( 0.2f, 0.075f), + MakeVector(-0.2f, 0.075f) }, 4), MakeVector(0.5f, .93f) );