diff --git a/README.md b/README.md index de134b8..d80ab0b 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/src/libsymmetry/editor.c b/src/libsymmetry/editor.c index 873f281..34d3bbc 100644 --- a/src/libsymmetry/editor.c +++ b/src/libsymmetry/editor.c @@ -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]; diff --git a/src/libsymmetry/editor.h b/src/libsymmetry/editor.h index e52afde..4f2ec0d 100644 --- a/src/libsymmetry/editor.h +++ b/src/libsymmetry/editor.h @@ -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); diff --git a/src/libsymmetry/game.c b/src/libsymmetry/game.c index efd981e..4af570f 100644 --- a/src/libsymmetry/game.c +++ b/src/libsymmetry/game.c @@ -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(); + platform->window.swap_buffers(game_state->window); } return true; } @@ -488,10 +486,24 @@ 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("Reload_Game_Lib", KS_RELEASED)) + 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; platform->reload_game_lib(); @@ -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); - editor_update(dt); - input_update(); /* This should always be the last thing(Why??). Probably - * put this in post update? */ + if(game_state->game_mode == GAME_MODE_GAME) + { + platform->physics.step(dt); + } + else if(game_state->game_mode == GAME_MODE_EDITOR) + { + editor_update(dt); + } +} + +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) diff --git a/src/libsymmetry/game.h b/src/libsymmetry/game.h index 88b9674..bbced1e 100644 --- a/src/libsymmetry/game.h +++ b/src/libsymmetry/game.h @@ -18,8 +18,8 @@ struct Player; enum Game_Mode { - GM_GAME = 0, - GM_EDITOR + GAME_MODE_GAME = 0, + GAME_MODE_EDITOR }; struct Game_State diff --git a/src/libsymmetry/input.c b/src/libsymmetry/input.c index 5620371..6db9b92 100644 --- a/src/libsymmetry/input.c +++ b/src/libsymmetry/input.c @@ -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; diff --git a/src/libsymmetry/input.h b/src/libsymmetry/input.h index 141bbdc..a0c94dc 100644 --- a/src/libsymmetry/input.h +++ b/src/libsymmetry/input.h @@ -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); diff --git a/src/libsymmetry/player.c b/src/libsymmetry/player.c index a2e547b..bc81f93 100644 --- a/src/libsymmetry/player.c +++ b/src/libsymmetry/player.c @@ -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) diff --git a/src/libsymmetry/scene.c b/src/libsymmetry/scene.c index 675c5d6..f712a22 100644 --- a/src/libsymmetry/scene.c +++ b/src/libsymmetry/scene.c @@ -9,6 +9,7 @@ #include "model.h" #include "light.h" #include "player.h" +#include "game.h" #include #include @@ -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)