Implemented functionality behind pause menu buttons

dev
Shariq Shah 6 years ago
parent b9abcf481d
commit 5abc152ab8
  1. 2
      src/common/version.h
  2. 6
      src/game/event.c
  3. 2
      src/game/event.h
  4. 13
      src/game/game.c
  5. 1
      src/game/game.h
  6. 42
      src/game/gui_game.c
  7. 2
      src/game/scene.c
  8. 7
      src/system/platform.c
  9. 1
      src/system/platform.h

@ -4,7 +4,7 @@
/* Auto generated version file. DO NOT MODIFY */
#define SYMMETRY_VERSION_MAJOR 0
#define SYMMETRY_VERSION_MINOR 1
#define SYMMETRY_VERSION_REVISION 335
#define SYMMETRY_VERSION_REVISION 336
#define SYMMETRY_VERSION_BRANCH "dev"
#endif

@ -1,5 +1,6 @@
#include "event.h"
#include "../common/log.h"
#include "game.h"
#include <string.h>
#include <assert.h>
@ -139,15 +140,16 @@ struct Event* event_manager_create_new_event(struct Event_Manager* event_manager
return new_event;
}
void event_manager_poll_events(struct Event_Manager* event_manager, bool* out_quit)
void event_manager_poll_events(struct Event_Manager* event_manager)
{
static SDL_Event event;
struct Game_State* game_state = game_state_get();
while(SDL_PollEvent(&event) != 0)
{
switch(event.type)
{
case SDL_QUIT:
*out_quit = true;
game_state->quit = true;
break;
case SDL_KEYDOWN: case SDL_KEYUP:
{

@ -140,7 +140,7 @@ void event_manager_unsubscribe_with_object(struct Event_Manager* event_
struct Event* event_manager_create_new_event(struct Event_Manager* event_manager);
void event_manager_send_event(struct Event_Manager* event_manager, struct Event* event);
void event_manager_send_event_entity(struct Event_Manager* event_manager, struct Event* event, struct Entity* entity);
void event_manager_poll_events(struct Event_Manager* event_manager, bool* out_quit);
void event_manager_poll_events(struct Event_Manager* event_manager);
void event_manager_cleanup(struct Event_Manager* event_manager);
const char* event_name_get(int event_type);

@ -43,7 +43,7 @@
#define MAX_NUM(a,b) ((a) < (b) ? (b) : (a))
#define LEN(a) (sizeof(a)/sizeof(a)[0])
static void game_update(float dt, bool* window_should_close);
static void game_update(float dt);
static void game_update_physics(float fixed_dt);
static void game_post_update(float dt);
static void game_render(void);
@ -69,6 +69,7 @@ bool game_init(struct Window* window, struct Hashmap* cvars)
game_state->window = window;
game_state->cvars = cvars;
game_state->is_initialized = false;
game_state->quit = false;
game_state->fixed_delta_time = 1.f / 60.f;
game_state->game_mode = GAME_MODE_GAME;
game_state->renderer = calloc(1, sizeof(*game_state->renderer));
@ -517,9 +518,8 @@ bool game_run(void)
{
uint32 previous_time = platform_ticks_get();
float accumulator = 0.f;
bool should_window_close = false;
while(!should_window_close)
while(!game_state->quit)
{
uint32 current_time = platform_ticks_get();
float frame_time = (float)(current_time - previous_time) / 1000.f;
@ -529,7 +529,7 @@ bool game_run(void)
struct Gui* gui = game_state->game_mode == GAME_MODE_EDITOR ? game_state->gui_editor : game_state->gui_game;
gui_input_begin(gui);
event_manager_poll_events(game_state->event_manager, &should_window_close);
event_manager_poll_events(game_state->event_manager);
gui_input_end(gui);
struct Game_State* game_state = game_state_get();
@ -539,7 +539,7 @@ bool game_run(void)
accumulator -= game_state->fixed_delta_time;
}
game_update(frame_time, &should_window_close);
game_update(frame_time);
game_post_update(frame_time);
game_render();
window_swap_buffers(game_state->window);
@ -547,7 +547,7 @@ bool game_run(void)
return true;
}
void game_update(float dt, bool* window_should_close)
void game_update(float dt)
{
static int frames = 0;
static int fps = 0;
@ -1966,7 +1966,6 @@ void game_cleanup(void)
texture_cleanup();
shader_cleanup();
sound_cleanup(game_state->sound);
//physics_cleanup();
debug_vars_cleanup(game_state->debug_vars);
event_manager_cleanup(game_state->event_manager);

@ -25,6 +25,7 @@ enum Game_Mode
struct Game_State
{
bool is_initialized;
bool quit;
int game_mode;
float fixed_delta_time;
struct Window* window;

@ -1,6 +1,7 @@
#include "gui_game.h"
#include "gui.h"
#include "game.h"
#include "scene.h"
#include "../common/log.h"
#include "../system/platform.h"
@ -40,13 +41,44 @@ void gui_game_update(struct Gui* gui_game, float dt)
void gui_game_pause_menu(struct nk_context* context)
{
struct Game_State* game_state = game_state_get();
int window_width = 0, window_height = 0;
window_get_drawable_size(game_state->window, &window_width, &window_height);
if(nk_begin(context, "Pause Gui", nk_rect(0, 0, window_width, window_height), NK_WINDOW_NO_SCROLLBAR))
int row_height = 30;
int popup_x = 0;
int popup_y = 0;
int popup_width = 300;
int popup_height = 200;
int display_width = 0;
int display_height = 0;
int popup_flags = NK_WINDOW_TITLE | NK_WINDOW_BORDER;
window_get_drawable_size(game_state_get()->window, &display_width, &display_height);
popup_x = (display_width / 2) - (popup_width / 2);
popup_y = (display_height / 2) - (popup_height / 2);
int background_window_flags = NK_WINDOW_BACKGROUND;
int previous_opacity = context->style.window.fixed_background.data.color.a;
context->style.window.fixed_background.data.color.a = 120;
if(nk_begin(context, "Pause Gui", nk_rect(0, 0, display_width, display_height), background_window_flags))
{
nk_layout_row_dynamic(context, 30, 1);
nk_label(context, "Hello from the Pause Menu!", NK_TEXT_ALIGN_CENTERED | NK_TEXT_ALIGN_MIDDLE);
nk_window_set_focus(context, "Pause Gui");
if(nk_popup_begin(context, NK_POPUP_DYNAMIC, "Game Paused", popup_flags, nk_recti(popup_x, popup_y, popup_width, popup_height)))
{
nk_layout_row_dynamic(context, row_height, 1);
int fullscreen = window_fullscreen_get(game_state->window) ? 1 : 0;
if(nk_checkbox_label(context, "Fullscreen", &fullscreen))
window_fullscreen_set(game_state->window, (bool)fullscreen);
nk_label(context, "Resolution", NK_TEXT_ALIGN_LEFT | NK_TEXT_ALIGN_MIDDLE);
if(nk_button_label(context, "Restart Level"))
{
char filename[MAX_FILENAME_LEN];
strncpy(filename, game_state->scene->filename, MAX_FILENAME_LEN);
if(!scene_load(game_state->scene, filename, DIRT_INSTALL))
log_error("gui_game:pause_menu", "Failed to reload Level");
}
if(nk_button_label(context, "Quit"))
game_state->quit = true;
nk_popup_end(context);
}
if(nk_button_label(context, "Button"))
{
log_message("Pressed!");

@ -89,6 +89,8 @@ void scene_init(struct Scene* scene)
editor_camera_init(game_state->editor, game_state->cvars);
editor_init_entities(game_state->editor);
if(game_state->game_mode == GAME_MODE_PAUSE)
game_state->game_mode = GAME_MODE_GAME;
scene->active_camera_index = game_state_get()->game_mode == GAME_MODE_GAME ? CAM_GAME : CAM_EDITOR;
scene->init = &scene_init_stub;
scene->cleanup = &scene_cleanup_stub;

@ -31,7 +31,7 @@ struct Window* window_create(const char* title, int width, int height, int msaa,
}
new_window->sdl_window = NULL;
new_window->gl_context = NULL;
new_window->is_fullscreen = 0;
new_window->is_fullscreen = false;
}
SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8);
@ -117,6 +117,11 @@ bool window_fullscreen_set(struct Window* window, bool fullscreen)
return success;
}
bool window_fullscreen_get(struct Window* window)
{
return window->is_fullscreen;
}
void window_make_context_current(struct Window* window)
{
SDL_GL_MakeCurrent((SDL_Window*)window->sdl_window, window->gl_context);

@ -25,6 +25,7 @@ void window_get_size(struct Window* window, int* out_width, int* out_h
void window_get_drawable_size(struct Window* window, int* out_width, int* out_height);
void window_swap_buffers(struct Window* window);
bool window_fullscreen_set(struct Window* window, bool fullscreen);
bool window_fullscreen_get(struct Window* window);
// Platform functions
bool platform_init(void);

Loading…
Cancel
Save