#include "glext.h"
#include "hud.h"
#include "gui.h"
-#include "game.h"
-#include "levels.h"
+#include "progress.h"
#include "config.h"
+#include "video.h"
#include "audio.h"
+#include "game_common.h"
+#include "game_client.h"
+
/*---------------------------------------------------------------------------*/
static int Lhud_id;
static int Rhud_id;
-static int Rhud2_id;
static int time_id;
static int coin_id;
-static int coin2_id;
static int ball_id;
static int scor_id;
static int goal_id;
static void hud_fps(void)
{
- static int fps = 0;
- static int then = 0;
- static int count = 0;
-
- int now = SDL_GetTicks();
-
- if (now - then > 250)
- {
- if (count)
- fprintf(stdout, "%f\n", (float) (now - then) / count);
-
- fps = count * 1000 / (now - then);
- then = now;
- count = 0;
-
- gui_set_count(fps_id, fps);
- }
- else count++;
+ gui_set_count(fps_id, video_perf());
}
void hud_init(void)
{
int id;
- char *str_view;
+ const char *str_view;
+ int v;
if ((Rhud_id = gui_hstack(0)))
{
gui_layout(Rhud_id, +1, -1);
}
- if ((Rhud2_id = gui_hstack(0)))
- {
- gui_label(Rhud2_id, _("Coins"), GUI_SML, 0, gui_wht, gui_wht);
- coin2_id = gui_count(Rhud2_id, 100, GUI_SML, GUI_NW);
- gui_layout(Rhud2_id, +1, -1);
- }
-
if ((Lhud_id = gui_hstack(0)))
{
if ((id = gui_vstack(Lhud_id)))
if ((time_id = gui_clock(0, 59999, GUI_MED, GUI_TOP)))
gui_layout(time_id, 0, -1);
- str_view = strlen(STR_VIEW0) > strlen(STR_VIEW1) ? STR_VIEW0 : STR_VIEW1;
- if (strlen(str_view) < strlen(STR_VIEW2))
- str_view = STR_VIEW2;
+
+ /* Find the longest view name. */
+
+ for (str_view = "", v = VIEW_NONE + 1; v < VIEW_MAX; v++)
+ if (strlen(view_to_str(v)) > strlen(str_view))
+ str_view = view_to_str(v);
+
if ((view_id = gui_label(0, str_view, GUI_SML, GUI_SW, gui_wht, gui_wht)))
gui_layout(view_id, 1, 1);
void hud_paint(void)
{
- int mode = curr_lg()->mode;
-
- if (mode == MODE_CHALLENGE)
+ if (curr_mode() == MODE_CHALLENGE)
gui_paint(Lhud_id);
- if (mode == MODE_PRACTICE)
- gui_paint(Rhud2_id);
- else
- gui_paint(Rhud_id);
-
+ gui_paint(Rhud_id);
gui_paint(time_id);
if (config_get_d(CONFIG_FPS))
gui_paint(fps_id);
- if (view_timer > 0.0f)
- gui_paint(view_id);
+ hud_view_paint();
}
void hud_update(int pulse)
{
- const struct level_game *lg = curr_lg();
-
int clock = curr_clock();
int coins = curr_coins();
int goal = curr_goal();
- int balls = lg->balls;
- int score = lg->score;
- int mode = lg->mode;
+ int balls = curr_balls();
+ int score = curr_score();
int c_id;
int last;
{
gui_set_clock(time_id, clock);
- if (last > clock && pulse && mode != MODE_PRACTICE)
+ if (last > clock && pulse)
{
if (clock <= 1000 && (last / 100) > (clock / 100))
{
/* balls and score + select coin widget */
- switch (mode)
+ switch (curr_mode())
{
case MODE_CHALLENGE:
if (gui_value(ball_id) != balls) gui_set_count(ball_id, balls);
c_id = coin_id;
break;
- case MODE_NORMAL:
- c_id = coin_id;
- break;
-
default:
- c_id = coin2_id;
+ c_id = coin_id;
break;
}
hud_update(1);
- view_timer -= dt;
-
gui_timer(Rhud_id, dt);
gui_timer(Lhud_id, dt);
gui_timer(time_id, dt);
- gui_timer(view_id, dt);
+
+ hud_view_timer(dt);
}
+/*---------------------------------------------------------------------------*/
+
void hud_view_pulse(int c)
{
- switch (c)
- {
- case 0: gui_set_label(view_id, STR_VIEW0); break;
- case 1: gui_set_label(view_id, STR_VIEW1); break;
- case 2: gui_set_label(view_id, STR_VIEW2); break;
- }
-
+ gui_set_label(view_id, view_to_str(c));
gui_pulse(view_id, 1.2f);
view_timer = 2.0f;
}
+void hud_view_timer(float dt)
+{
+ view_timer -= dt;
+ gui_timer(view_id, dt);
+}
+
+void hud_view_paint(void)
+{
+ if (view_timer > 0.0f)
+ gui_paint(view_id);
+}
+
/*---------------------------------------------------------------------------*/