void game_loop () { SDL_Event event; int done = 0, eventstate; if (GT_MP) net_game_fillsockaddr (); if ( SDL_InitSubSystem ( SDL_INIT_JOYSTICK ) < 0 ) { fprintf ( stderr, "Unable to initialize Joystick: %s\n", SDL_GetError() ); } printf ( "%i joysticks found\n", SDL_NumJoysticks () ); menu = NULL; bman.updatestatusbar = 1; // force an update timestamp = SDL_GetTicks (); // needed for time sync. d_gamedetail ("GAME START"); gfx_blitupdaterectclear (); draw_logo (); draw_field (); SDL_Flip (gfx.screen); draw_players (); if (bman.p_nr >= 0 && bman.p_nr < MAX_PLAYERS) { players[bman.p_nr].ready = 1; if (GT_MP_PTPS) send_playerdata (&players[bman.p_servnr].net.addr, bman.p_nr, &players[bman.p_nr]); } if (bman.p2_nr >= 0 && bman.p2_nr < MAX_PLAYERS) { players[bman.p2_nr].ready = 1; if (GT_MP_PTPS) send_playerdata (&players[bman.p_servnr].net.addr, bman.p2_nr, &players[bman.p2_nr]); } fire_init(); while (!done && (bman.state == GS_running || bman.state == GS_ready)) { SDL_JoystickUpdate (); if ((eventstate = SDL_PollEvent (&event)) != 0) switch (event.type) { case (SDL_QUIT): done = 1; bman.state = GS_quit; } /* * input handling */ keyb_loop (&event); game_keys_loop (); if (GT_MP) chat_loop (&event); if ((!IS_LPLAYER2) && (!chat.active)) chat_setactive (1, 1); restore_players_screen (); player_check (bman.p_nr); if (IS_LPLAYER2) player_check (bman.p2_nr); dead_playerani (); special_loop (); player_move (bman.p_nr); if (IS_LPLAYER2) player_move (bman.p2_nr); if (GT_MP) { player_calcpos (); network_loop (); } if (bman.state == GS_running) single_loop (); bomb_loop (); /* wind_loop (); SOON */ fire_loop (); field_loop (); flitems_loop (); draw_players (); game_draw_info (); // will set the var bman.player_nr /* check if there is only one player left and the game is in multiplayer mode and if there the last dieing animation is done */ if (game_check_endgame () && bman.timeout >= 0.0f) bman.timeout = 0.0f; if ((GT_SP || GT_MP_PTPM) && bman.timeout < -GAME_OVERTIMEOUT) { d_printf ("GAME: Game Over\n"); done = 1; } stonelist_draw (); /* if there is any menu displayed do so */ if (menu != NULL) game_menu_loop (&event, eventstate); gfx_blitdraw (); s_calctimesync (); bman.timeout -= timediff; } if (menu != NULL) { menu_delete (menu); menu = NULL; } gfx_blitdraw (); chat_show (-1, -1, -1, -1); draw_logo (); gfx_blitupdaterectclear (); SDL_Flip (gfx.screen); d_gamedetail ("GAME END"); d_printf ("done = %d\n", done); };
/* * redraw_screen * * This function is called once per time around the main loop. It redraws the * screen with all players in the correct positions. * * Parameters: screen - The screen object on which we are drawing. * match_state - The unique objects in a match. */ void redraw_screen(SCREEN *screen, MATCH_STATE *match_state, FONT *font) { /* * Local Variables. */ char score_string[10]; char game_time_string[10]; /* * Clear the screen before doing any drawing. */ glClear(GL_COLOR_BUFFER_BIT); draw_pitch_background(screen, match_state->pitch); /* * Draw the pitch outline. This is the lines and the 'permanent' markings. */ draw_pitch_lines(screen, match_state->pitch); /* * After drawing the screen iterate over the list of players in both teams * and if they have new positions then update them. */ draw_players(match_state->teams, match_state->players_per_team, match_state->animation_handler); /* * Draw the disc on top of the players. */ draw_disc(match_state->disc, 50.0f); /* * Put the score on the screen as text. We make this independent of scaling * and screen movement so that the text is on a fixed position on the screen * regardless of the orientation etc. */ glPushMatrix(); glLoadIdentity(); convert_score_to_text(match_state->match_stats->team_a_score, match_state->match_stats->team_b_score, score_string); draw_text(score_string, 250, 10, font); glPopMatrix(); /* * Put the current game time in the top left of the screen. This counts up. */ glPushMatrix(); glLoadIdentity(); convert_timer_to_text(match_state->match_stats->game_timer, game_time_string); draw_text(game_time_string, 10, 10, font); glPopMatrix(); /* * This performs the actual update of the screen so until this line nothing * we have done will be rendered each time around the render loop. */ SDL_GL_SwapBuffers(); }