ohsp

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

commit e6ab15e4696e60031ceab70b7762b2b8f44341d8
parent 794953f645df5bfa202f13f5f85f77f6913a50c1
Author: amin <dev@aminmesbah.com>
Date:   Fri, 27 Oct 2017 04:28:33 +0000

Fix hanging bug caused by uninitialized variables

The game would sometimes appear to init and just hang, not processing
any new input. This would only happen some of the time. Digging revealed
crazy values for the vector lengths and angles.

Of course! They were never initialized. Moving the initialization to
functions will help prevent this.

FossilOrigin-Name: 3dfb6154ca0fd00a3ad708ba76a5079dddabac5ff4ab27a3899b5c28485fe995
Diffstat:
Msrc/game.c | 12+++++++++---
1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/src/game.c b/src/game.c @@ -16,9 +16,6 @@ void game_init(struct GameState *game_state, int field_width, int field_height) return; } - game_state->view.dx = 0; - game_state->view.dy = 0; - game_state->view.zoom = 1; game_state->player.angle = 0; game_state->player.speed = 0; game_state->player.mass = 10; @@ -26,6 +23,15 @@ void game_init(struct GameState *game_state, int field_width, int field_height) game_state->player.x = field_width / 2; game_state->player.y = field_height / 2; game_state->player.color = 0x888888; + game_state->thrust_vector01.angle = 0; + game_state->thrust_vector01.length = 0; + game_state->thrust_vector02.angle = 0; + game_state->thrust_vector02.length = 0; + game_state->thrust_vector_sum.angle = 0; + game_state->thrust_vector_sum.length = 0; + game_state->view.dx = 0; + game_state->view.dy = 0; + game_state->view.zoom = 1; }