Rename GameStage to Stage
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
#include "stage_common.h"
|
||||
#include "stage.h"
|
||||
|
||||
GameStage *
|
||||
GameStage_new ()
|
||||
Stage *
|
||||
Stage_new ()
|
||||
{
|
||||
GameStage *g = g_new0 (GameStage, 1);
|
||||
Stage *g = g_new0 (Stage, 1);
|
||||
g->ui_context = UIContext_new ();
|
||||
g->ui_context->tooltip = PMUID ("tooltip");
|
||||
|
||||
@@ -13,12 +13,12 @@ GameStage_new ()
|
||||
}
|
||||
|
||||
void
|
||||
GameStage_register_UIContext_handlers (GameStage *self)
|
||||
Stage_register_UIContext_handlers (Stage *self)
|
||||
{
|
||||
/* UGH... I fucking hate this whole structure of the game I did
|
||||
here. It should be really extensible and whatnot, but jesus
|
||||
christ, it's so complex... */
|
||||
#define GAEH GameStage_add_event_handler
|
||||
#define GAEH Stage_add_event_handler
|
||||
|
||||
GAEH (self, 1, SDL_EVENT_WINDOW_RESIZED, NULL, NULL, UIContext_window_resize, self->ui_context);
|
||||
GAEH (self, 1, SDL_EVENT_KEY_DOWN, evt_pred_flag, "ui_has_focus", UIContext_key_down, self->ui_context);
|
||||
@@ -33,7 +33,7 @@ GameStage_register_UIContext_handlers (GameStage *self)
|
||||
}
|
||||
|
||||
void
|
||||
GameStage_add_event_handler (GameStage *self, int priority, unsigned int on_event,
|
||||
Stage_add_event_handler (Stage *self, int priority, unsigned int on_event,
|
||||
gboolean (*predicate) (SDL_Event *sdl_event, void *userdata),
|
||||
void *predicate_data,
|
||||
gboolean (*callback) (SDL_Event *sdl_event, void *userdata),
|
||||
@@ -57,7 +57,7 @@ GameStage_add_event_handler (GameStage *self, int priority, unsigned int on_even
|
||||
}
|
||||
|
||||
void
|
||||
GameStage_handle_SDL_Event (GameStage *self, SDL_Event *event)
|
||||
Stage_handle_SDL_Event (Stage *self, SDL_Event *event)
|
||||
{
|
||||
for (GList *l = self->event_handlers; l != NULL; l = l->next)
|
||||
{
|
||||
@@ -17,30 +17,30 @@ typedef struct {
|
||||
gboolean (*callback) (SDL_Event *sdl_event, void *userdata);
|
||||
} EventHandler;
|
||||
|
||||
typedef struct GameStage
|
||||
typedef struct Stage
|
||||
{
|
||||
UIContext *ui_context; /* Could be NULL... */
|
||||
World *world;
|
||||
|
||||
GList *event_handlers;
|
||||
|
||||
void (*on_enter) (struct GameStage *);
|
||||
void (*on_exit) (struct GameStage *);
|
||||
void (*on_update) (struct GameStage *);
|
||||
void (*on_render) (struct GameStage *);
|
||||
} GameStage;
|
||||
void (*on_enter) (struct Stage *);
|
||||
void (*on_exit) (struct Stage *);
|
||||
void (*on_update) (struct Stage *);
|
||||
void (*on_render) (struct Stage *);
|
||||
} Stage;
|
||||
|
||||
GameStage *GameStage_new ();
|
||||
Stage *Stage_new ();
|
||||
|
||||
void GameStage_register_UIContext_handlers (GameStage *self);
|
||||
void Stage_register_UIContext_handlers (Stage *self);
|
||||
|
||||
void GameStage_add_event_handler (GameStage *self, int priority, unsigned int on_event,
|
||||
void Stage_add_event_handler (Stage *self, int priority, unsigned int on_event,
|
||||
gboolean (*predicate) (SDL_Event *sdl_event, void *userdata),
|
||||
void *predicate_data,
|
||||
gboolean (*callback) (SDL_Event *sdl_event, void *userdata),
|
||||
void *callback_data);
|
||||
|
||||
void GameStage_handle_SDL_Event (GameStage *self, SDL_Event *event);
|
||||
void Stage_handle_SDL_Event (Stage *self, SDL_Event *event);
|
||||
|
||||
gboolean evt_pred_key (SDL_Event *event, void *data);
|
||||
gboolean evt_pred_flag (SDL_Event *event, void *data);
|
||||
@@ -1,14 +1,14 @@
|
||||
#include "stage_global.h"
|
||||
|
||||
static void
|
||||
_on_enter (GameStage *stage)
|
||||
_on_enter (Stage *stage)
|
||||
{
|
||||
UNUSED (stage);
|
||||
gvar_set ("last_time", SDL_GetTicks ());
|
||||
}
|
||||
|
||||
static void
|
||||
_on_update (GameStage *stage)
|
||||
_on_update (Stage *stage)
|
||||
{
|
||||
UNUSED (stage);
|
||||
unsigned int now = SDL_GetTicks ();
|
||||
@@ -16,12 +16,12 @@ _on_update (GameStage *stage)
|
||||
gvar_set ("last_time", now);
|
||||
}
|
||||
|
||||
GameStage *
|
||||
Stage *
|
||||
stage_global_new ()
|
||||
{
|
||||
GameStage *self = GameStage_new ();
|
||||
Stage *self = Stage_new ();
|
||||
|
||||
#define GAEH GameStage_add_event_handler
|
||||
#define GAEH Stage_add_event_handler
|
||||
|
||||
GAEH (self, 0, SDL_EVENT_WINDOW_RESIZED, NULL, NULL, graphics_cb_window_resize, NULL);
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
#pragma once
|
||||
|
||||
#include "stage_common.h"
|
||||
#include "stage.h"
|
||||
|
||||
#include "../graphics.h"
|
||||
#include "../gvar.h"
|
||||
|
||||
GameStage *stage_global_new ();
|
||||
Stage *stage_global_new ();
|
||||
|
||||
@@ -12,14 +12,14 @@ static const int render_distance_max = 12;
|
||||
static Entity *player_entity, *sky_entity;
|
||||
|
||||
static void
|
||||
_on_enter (GameStage *self)
|
||||
_on_enter (Stage *self)
|
||||
{
|
||||
UNUSED (self);
|
||||
gvar_set ("ui_has_focus", TRUE);
|
||||
}
|
||||
|
||||
static void
|
||||
_on_update (GameStage *self)
|
||||
_on_update (Stage *self)
|
||||
{
|
||||
Camera *cam = self->world->camera;
|
||||
|
||||
@@ -38,7 +38,7 @@ _on_update (GameStage *self)
|
||||
}
|
||||
|
||||
static void
|
||||
_on_render (GameStage *self)
|
||||
_on_render (Stage *self)
|
||||
{
|
||||
Profiler_begin (&profiler);
|
||||
World_render (self->world);
|
||||
@@ -154,17 +154,17 @@ _temporary_player_tick (Entity *self, World *world)
|
||||
}
|
||||
}
|
||||
|
||||
GameStage *
|
||||
Stage *
|
||||
stage_ingame_new ()
|
||||
{
|
||||
GameStage *self = GameStage_new ();
|
||||
Stage *self = Stage_new ();
|
||||
|
||||
self->on_enter = _on_enter;
|
||||
self->on_update = _on_update;
|
||||
self->on_render = _on_render;
|
||||
|
||||
#define KEY(k) GINT_TO_POINTER(k)
|
||||
#define GAEH GameStage_add_event_handler
|
||||
#define GAEH Stage_add_event_handler
|
||||
|
||||
GAEH (self, 0, SDL_EVENT_KEY_DOWN, evt_pred_key, KEY (SDLK_TAB), _switch_ui_focus, self->ui_context);
|
||||
|
||||
@@ -188,8 +188,8 @@ stage_ingame_new ()
|
||||
#undef GAEH
|
||||
#undef KEY
|
||||
|
||||
/* If your GameStage uses the UI, always call this. */
|
||||
GameStage_register_UIContext_handlers (self);
|
||||
/* If your Stage uses the UI, always call this. */
|
||||
Stage_register_UIContext_handlers (self);
|
||||
self->ui_context->root = PMUID ("debug_window");
|
||||
|
||||
player_entity = Entity_new ();
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
#pragma once
|
||||
|
||||
#include "stage_common.h"
|
||||
#include "stage.h"
|
||||
|
||||
#include "../gvar.h"
|
||||
#include "../profiler.h"
|
||||
#include "../graphics.h"
|
||||
|
||||
GameStage *stage_ingame_new ();
|
||||
Stage *stage_ingame_new ();
|
||||
|
||||
@@ -1,21 +1,21 @@
|
||||
#include "stage_main_menu.h"
|
||||
|
||||
static void
|
||||
_on_enter (GameStage *stage)
|
||||
_on_enter (Stage *stage)
|
||||
{
|
||||
UNUSED (stage);
|
||||
gvar_set ("ui_has_focus", TRUE);
|
||||
}
|
||||
|
||||
GameStage *
|
||||
Stage *
|
||||
stage_main_menu_new ()
|
||||
{
|
||||
GameStage *g = GameStage_new ();
|
||||
Stage *g = Stage_new ();
|
||||
|
||||
g->on_enter = _on_enter;
|
||||
|
||||
/* If your GameStage uses the UI, always call this. */
|
||||
GameStage_register_UIContext_handlers (g);
|
||||
/* If your Stage uses the UI, always call this. */
|
||||
Stage_register_UIContext_handlers (g);
|
||||
g->ui_context->root = PMUID ("main_menu");
|
||||
|
||||
return g;
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
#pragma once
|
||||
|
||||
#include "stage_common.h"
|
||||
#include "stage.h"
|
||||
|
||||
#include "../graphics.h"
|
||||
#include "../gvar.h"
|
||||
|
||||
GameStage *stage_main_menu_new ();
|
||||
Stage *stage_main_menu_new ();
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
#include "stage_mapeditor.h"
|
||||
|
||||
/* static void */
|
||||
/* _on_enter (GameStage *self) */
|
||||
/* _on_enter (Stage *self) */
|
||||
/* { */
|
||||
/* UNUSED (self); */
|
||||
/* gvar_set ("ui_has_focus", TRUE); */
|
||||
/* } */
|
||||
|
||||
/* static void */
|
||||
/* _on_update (GameStage *self) */
|
||||
/* _on_update (Stage *self) */
|
||||
/* { */
|
||||
/* World_update (self->world); */
|
||||
/* } */
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
#include "stage_common.h"
|
||||
#include "stage.h"
|
||||
|
||||
#include "../gvar.h"
|
||||
#include "../camera.h"
|
||||
#include "../profiler.h"
|
||||
#include "../graphics.h"
|
||||
|
||||
GameStage *stage_mapeditor_new ();
|
||||
Stage *stage_mapeditor_new ();
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
|
||||
static GHashTable *game_stages;
|
||||
|
||||
static GameStage *current_stage;
|
||||
static GameStage *global_stage;
|
||||
static Stage *current_stage;
|
||||
static Stage *global_stage;
|
||||
|
||||
void
|
||||
stageman_init ()
|
||||
@@ -32,7 +32,7 @@ stageman_guile_register ()
|
||||
}
|
||||
|
||||
void
|
||||
stageman_add_stage (const char *name, GameStage *stage)
|
||||
stageman_add_stage (const char *name, Stage *stage)
|
||||
{
|
||||
g_hash_table_replace (game_stages, g_strdup (name), stage);
|
||||
}
|
||||
@@ -40,7 +40,7 @@ stageman_add_stage (const char *name, GameStage *stage)
|
||||
void
|
||||
stageman_switch_stage (const char *name)
|
||||
{
|
||||
GameStage *next_stage = g_hash_table_lookup (game_stages, name);
|
||||
Stage *next_stage = g_hash_table_lookup (game_stages, name);
|
||||
|
||||
if (current_stage && current_stage->on_exit)
|
||||
{
|
||||
@@ -52,7 +52,7 @@ stageman_switch_stage (const char *name)
|
||||
/* When we enter, we also set the UI root to be the current
|
||||
window size. After that, if callbacks for a given stage are
|
||||
set up correctly (using
|
||||
GameStage_register_UIContext_handlers), then it will update
|
||||
Stage_register_UIContext_handlers), then it will update
|
||||
the root size automatically.*/
|
||||
next_stage->ui_context->root->size[0] = gvar_get ("window_width");
|
||||
next_stage->ui_context->root->size[1] = gvar_get ("window_height");
|
||||
@@ -79,11 +79,11 @@ void stageman_update ()
|
||||
void
|
||||
stageman_on_SDL_Event (SDL_Event *event)
|
||||
{
|
||||
GameStage_handle_SDL_Event (global_stage, event);
|
||||
Stage_handle_SDL_Event (global_stage, event);
|
||||
|
||||
if (current_stage && current_stage->event_handlers)
|
||||
{
|
||||
GameStage_handle_SDL_Event (current_stage, event);
|
||||
Stage_handle_SDL_Event (current_stage, event);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
#include <glib-2.0/glib.h>
|
||||
|
||||
#include "stage_common.h"
|
||||
#include "stage.h"
|
||||
#include "stage_global.h"
|
||||
|
||||
#include "stage_main_menu.h"
|
||||
@@ -11,7 +11,7 @@
|
||||
void stageman_init ();
|
||||
void stageman_guile_register ();
|
||||
static inline void stageman_free () { } /* TODO: implement */
|
||||
void stageman_add_stage (const char *name, GameStage *stage);
|
||||
void stageman_add_stage (const char *name, Stage *stage);
|
||||
void stageman_switch_stage (const char *name);
|
||||
|
||||
void stageman_update ();
|
||||
|
||||
Reference in New Issue
Block a user