ohsp

Prototype for a game with dual thruster controls.
git clone git://git.amin.space/ohsp.git
Log | Files | Refs | LICENSE

commit 4cedde2e66c63d75e367806d2ed8f5dae336e8b1
parent f45455ff10f8719153768b80d7a58b0cb1fb0108
Author: amin <dev@aminmesbah.com>
Date:   Sun, 12 Nov 2017 00:58:52 +0000

Prevent unintended double promotion

- Append 'f' to intended float literals
- Use cosf and sinf() consistently
- Double promotion was found with the `Wdouble-promotion` GCC option

FossilOrigin-Name: 60c083056c4e37b64204b3305d96aed10a973c0628cc49bc48fc0b599b084e51
Diffstat:
Msrc/entity.c | 2+-
Msrc/entity.h | 2+-
Msrc/game.c | 18+++++++++---------
Msrc/game.h | 2+-
4 files changed, 12 insertions(+), 12 deletions(-)

diff --git a/src/entity.c b/src/entity.c @@ -11,7 +11,7 @@ struct Vec2d vec2d_add(float angle1, float length1, float angle2, float length2) struct Vec2d new_vec = { - .angle = 0.5 * M_PI - atan2f(y, x), + .angle = 0.5f * M_PI - atan2f(y, x), .length = hypotf(x, y), }; return new_vec; diff --git a/src/entity.h b/src/entity.h @@ -4,7 +4,7 @@ #include <stdint.h> #ifndef M_PI -#define M_PI (3.14159265358979323846264338327950288) +#define M_PI 3.141592f #endif struct Entity diff --git a/src/game.c b/src/game.c @@ -83,10 +83,10 @@ void game_update(struct GameState *game_state, struct GameControllerInput game_i game_state->thrust_vector02.length); struct Entity *player = &game_state->player; - entity_accelerate(player, game_state->thrust_vector_sum.angle, game_state->thrust_vector_sum.length * 0.01); + entity_accelerate(player, game_state->thrust_vector_sum.angle, game_state->thrust_vector_sum.length * 0.01f); - player->x += player->speed * cos(player->angle); - player->y += player->speed * sin(player->angle); + player->x += player->speed * cosf(player->angle); + player->y += player->speed * sinf(player->angle); player->x = wrap(player->x, 0, field_width); player->y = wrap(player->y, 0, field_height); } @@ -106,8 +106,8 @@ void game_render(struct OffscreenBuffer *buffer, float dt, struct GameState *gam game_render_vector(buffer, &game_state->thrust_vector_sum, player.x, player.y, 5, 0xFF00FF); game_render_circle(buffer, - player.x + 100 * (player.speed * cos(player.angle)), - player.y + 100 * (player.speed * sin(player.angle)), + player.x + 100 * (player.speed * cosf(player.angle)), + player.y + 100 * (player.speed * sinf(player.angle)), 5, 0x00FF00); } @@ -157,10 +157,10 @@ void game_render_line(struct OffscreenBuffer *buffer, float x0, float y0, float { game_set_pixel(buffer, x, y, color); error += delta_err; - if (error >= 0.5) + if (error >= 0.5f) { y += 1; - error -= 1.0; + error -= 1.0f; } } } @@ -169,8 +169,8 @@ void game_render_line(struct OffscreenBuffer *buffer, float x0, float y0, float void game_render_vector(struct OffscreenBuffer *buffer, struct Vec2d *v, float x0, float y0, float radius, uint32_t color) { - float x1 = x0 + 100 * (v->length * cos(v->angle)); - float y1 = y0 + 100 * (v->length * sin(v->angle)); + float x1 = x0 + 100 * (v->length * cosf(v->angle)); + float y1 = y0 + 100 * (v->length * sinf(v->angle)); game_render_line(buffer, x0, y0, x1, y1, color); game_render_circle(buffer, x1, y1, radius, color); } diff --git a/src/game.h b/src/game.h @@ -16,7 +16,7 @@ #define MS_PER_UPDATE (SECOND / UPDATES_PER_SECOND) #ifndef M_PI -#define M_PI (3.14159265358979323846264338327950288) +#define M_PI 3.141592f #endif #define COLOR_BACKGROUND 0x000000