Implemented switching between game and editor mode

dev
Shariq Shah 7 years ago
parent 90cb201359
commit 02ee41c788
  1. 1
      README.md
  2. 8
      src/libsymmetry/editor.c
  3. 1
      src/libsymmetry/editor.h
  4. 40
      src/libsymmetry/game.c
  5. 4
      src/libsymmetry/game.h
  6. 2
      src/libsymmetry/input.c
  7. 2
      src/libsymmetry/input.h
  8. 8
      src/libsymmetry/player.c
  9. 5
      src/libsymmetry/scene.c

@ -156,6 +156,7 @@
- ## TODO
- Switching between editor and game mode/cameras
- In-game scrollable console/log-viewer
- Player projectiles and sounds
- NPR and cross-hatching
- Remove model and replace all usages with static mesh

@ -94,6 +94,9 @@ void editor_init_camera(void)
int render_width = hashmap_int_get(config, "render_width");
int render_height = hashmap_int_get(config, "render_height");
camera_attach_fbo(editor_camera, render_width, render_height, true, true, true);
vec3 cam_pos = {5.f, 20.f, 50.f};
transform_translate(editor_camera, &cam_pos, TS_WORLD);
}
int editor_debugvar_slot_create(const char* name, int value_type)
@ -545,11 +548,6 @@ void editor_update(float dt)
}
}
void editor_toggle(void)
{
editor_state.enabled = !editor_state.enabled;
}
void editor_camera_update(float dt)
{
struct Camera* editor_camera = &game_state_get()->scene->cameras[CAM_EDITOR];

@ -6,7 +6,6 @@
void editor_init(void);
void editor_init_camera(void);
void editor_update(float dt);
void editor_toggle(void);
void editor_cleanup(void);
int editor_debugvar_slot_create(const char* name, int value_type);
void editor_debugvar_slot_remove(int index);

@ -42,6 +42,7 @@
static bool game_run(void);
static void game_update(float dt, bool* window_should_close);
static void game_post_update(float dt);
static void game_render(void);
static void game_debug(float dt);
static void game_debug_gui(float dt);
@ -75,6 +76,7 @@ bool game_init(struct Window* window, struct Platform_Api* platform_api)
{
game_state->window = window;
game_state->is_initialized = false;
game_state->game_mode = GAME_MODE_GAME;
game_state->renderer = malloc(sizeof(*game_state->renderer));
game_state->scene = malloc(sizeof(*game_state->scene));
@ -103,8 +105,6 @@ bool game_init(struct Window* window, struct Platform_Api* platform_api)
editor_init();
renderer_init(game_state->renderer);
scene_init(game_state->scene);
game_state->game_mode = GM_GAME;
}
/* Debug scene setup */
@ -476,11 +476,9 @@ bool game_run(void)
gui_input_end();
game_update(delta_time, &should_window_close);
platform->physics.step(delta_time);
game_post_update(delta_time);
game_render();
platform->window.swap_buffers(game_state->window);
scene_post_update(game_state->scene);
platform->sound.update_3d();
}
return true;
}
@ -488,9 +486,23 @@ bool game_run(void)
void game_update(float dt, bool* window_should_close)
{
if(input_is_key_pressed(KEY_ESCAPE)) *window_should_close = true;
if(input_map_state_get("Editor_Toggle", KS_RELEASED)) editor_toggle();
if(input_map_state_get("Window_Fullscreen", KS_RELEASED)) platform->window.fullscreen_set(game_state->window, 1);
if(input_map_state_get("Window_Maximize", KS_RELEASED)) platform->window.fullscreen_set(game_state->window, 0);
if(input_map_state_get("Editor_Toggle", KS_RELEASED))
{
//editor_toggle();
if(game_state->game_mode == GAME_MODE_EDITOR)
{
game_state->game_mode = GAME_MODE_GAME;
game_state->scene->active_camera_index = CAM_GAME;
}
else if(game_state->game_mode == GAME_MODE_GAME)
{
game_state->game_mode = GAME_MODE_EDITOR;
game_state->scene->active_camera_index = CAM_EDITOR;
}
}
if(input_map_state_get("Reload_Game_Lib", KS_RELEASED))
{
*window_should_close = true;
@ -501,9 +513,21 @@ void game_update(float dt, bool* window_should_close)
//game_debug(dt);
//debug_gui(dt);
scene_update(game_state->scene, dt);
if(game_state->game_mode == GAME_MODE_GAME)
{
platform->physics.step(dt);
}
else if(game_state->game_mode == GAME_MODE_EDITOR)
{
editor_update(dt);
input_update(); /* This should always be the last thing(Why??). Probably
* put this in post update? */
}
}
void game_post_update(float dt)
{
input_post_update();
scene_post_update(game_state->scene);
platform->sound.update_3d();
}
void game_debug_gui(float dt)

@ -18,8 +18,8 @@ struct Player;
enum Game_Mode
{
GM_GAME = 0,
GM_EDITOR
GAME_MODE_GAME = 0,
GAME_MODE_EDITOR
};
struct Game_State

@ -361,7 +361,7 @@ bool input_mousebutton_state_get(uint button, int state_type)
return state_type == current_state ? true : false;
}
void input_update(void)
void input_post_update(void)
{
struct Variant* value = NULL;
char* key = NULL;

@ -425,7 +425,7 @@ void input_mouse_delta_get(int* xpos, int* ypos); // Use with relative mouse mod
void input_mouse_pos_set(int xpos, int ypos);
void input_mouse_mode_set(enum Mouse_Mode mode);
int input_mouse_mode_get(void);
void input_update(void);
void input_post_update(void);
bool input_map_state_get(const char* map_name, int state);
bool input_map_create(const char* name, struct Key_Binding key_combination);
bool input_map_keys_set(const char* name, struct Key_Binding key_combination);

@ -17,7 +17,7 @@ void player_init(struct Player* player, struct Scene* scene)
player->move_speed_multiplier = hashmap_int_get(config, "player_move_speed_multiplier");
player->turn_speed = hashmap_int_get(config, "player_turn_speed");
player->mesh = scene_static_mesh_create(scene, "Player_Mesh", player, "default.pamesh", MAT_BLINN);
player->mesh = scene_static_mesh_create(scene, "Player_Mesh", player, "sphere.symbres", MAT_BLINN);
struct Camera* player_camera = &scene->cameras[CAM_GAME];
entity_rename(player_camera, "Player_Camera");
@ -32,6 +32,12 @@ void player_init(struct Player* player, struct Scene* scene)
int render_height = hashmap_int_get(config, "render_height");
camera_attach_fbo(player_camera, render_width, render_height, true, true, true);
transform_parent_set(player_camera, player, true);
vec3 cam_translation = {0.f, 20.f, 2.f};
transform_translate(player_camera, &cam_translation, TS_LOCAL);
vec3 cam_axis = {-1.f, 0.f, 0.f};
transform_rotate(player_camera, &cam_axis, 85.f, TS_LOCAL);
}
void player_destroy(struct Player* player)

@ -9,6 +9,7 @@
#include "model.h"
#include "light.h"
#include "player.h"
#include "game.h"
#include <assert.h>
#include <string.h>
@ -50,7 +51,7 @@ void scene_init(struct Scene* scene)
player_init(&scene->player, scene);
editor_init_camera();
scene->active_camera_index = CAM_EDITOR;
scene->active_camera_index = game_state_get()->game_mode == GAME_MODE_GAME ? CAM_GAME : CAM_EDITOR;
}
bool scene_load(struct Scene* scene, const char* filename, int dir_type);
@ -72,7 +73,7 @@ void scene_destroy(struct Scene* scene)
void scene_update(struct Scene* scene, float dt)
{
player_update(&scene->player, scene, dt);
if(game_state_get()->game_mode == GAME_MODE_GAME) player_update(&scene->player, scene, dt);
}
void scene_post_update(struct Scene* scene)

Loading…
Cancel
Save