medfall

A super great game engine
Log | Files | Refs

commit 6f0be43695f47b80396772406d5e289c6c243b8f
parent d6ef807a5a3c4ff0b3cd4c79420af4b79fc3b344
Author: Michael Savage <mikejsavage@gmail.com>
Date:   Sat, 25 Nov 2017 23:02:16 +0200

Press C to freeze the clipmap

Diffstat:
clipmap.cc | 16++++++++++++----
game.h | 3+++
keys.h | 2+-
main.cc | 1+
4 files changed, 17 insertions(+), 5 deletions(-)

diff --git a/clipmap.cc b/clipmap.cc @@ -572,6 +572,10 @@ GAME_FRAME( game_frame ) { game->velocity = v3( 0 ); game->on_ground = false; } + if( input->keys[ KEY_C ] && input->key_edges[ KEY_C ] ) { + game->frozen = !game->frozen; + game->frozen_pos = game->pos; + } dpitch -= float( input->mouse_dy * 0.25 ); dyaw -= float( input->mouse_dx * 0.25 ); @@ -754,6 +758,10 @@ GAME_FRAME( game_frame ) { rotation_uniforms[ 2 ] = renderer_uniforms( m4_rotz90() ); rotation_uniforms[ 3 ] = renderer_uniforms( m4_rotz180() ); + if( !game->frozen ) { + game->frozen_pos = game->pos; + } + // draw terrain { RenderState render_state; @@ -768,7 +776,7 @@ GAME_FRAME( game_frame ) { // draw cross { - v2 snapped_pos = floorf( game->pos.xy() ); + v2 snapped_pos = floorf( game->frozen_pos.xy() ); render_state.uniforms[ UNIFORMS_MODEL ] = rotation_uniforms[ 0 ]; render_state.uniforms[ UNIFORMS_CLIPMAP ] = renderer_uniforms( snapped_pos, 1.0f ); renderer_draw_mesh( clipmap.gpu.cross, render_state ); @@ -777,7 +785,7 @@ GAME_FRAME( game_frame ) { for( u32 l = 0; l < NUM_LODS; l++ ) { float scale = checked_cast< float >( u32( 1 ) << l ); v2 tile_size = v2( checked_cast< float >( PATCH_RESOLUTION << l ) ); - v2 snapped_pos = floorf( game->pos.xy() / scale ) * scale; + v2 snapped_pos = floorf( game->frozen_pos.xy() / scale ) * scale; v2 base = snapped_pos - v2( checked_cast< float >( PATCH_RESOLUTION << ( l + 1 ) ) ); // draw tiles @@ -829,13 +837,13 @@ GAME_FRAME( game_frame ) { if( l != NUM_LODS - 1 ) { float next_scale = scale * 2.0f; - v2 next_snapped_pos = floorf( game->pos.xy() / next_scale ) * next_scale; + v2 next_snapped_pos = floorf( game->frozen_pos.xy() / next_scale ) * next_scale; // draw trim { v2 tile_centre = snapped_pos + v2( scale * 0.5f ); - v2 d = game->pos.xy() - next_snapped_pos; + v2 d = game->frozen_pos.xy() - next_snapped_pos; u32 r = 0; r |= d.x >= scale ? 0 : 2; r |= d.y >= scale ? 0 : 1; diff --git a/game.h b/game.h @@ -28,6 +28,9 @@ struct GameState { BSP bsp; BSPRenderer bspr; + bool frozen; + v3 frozen_pos; + WorkQueue background_tasks; Skybox skybox; diff --git a/keys.h b/keys.h @@ -8,7 +8,7 @@ enum KeyNames { KEY_A = 'a', // KEY_B, - // KEY_C, + KEY_C = 'c', KEY_D = 'd', // KEY_E, KEY_F = 'f', diff --git a/main.cc b/main.cc @@ -74,6 +74,7 @@ int main( int argc, char ** argv ) { // TODO: do this properly GameInput input = { }; input.keys[ KEY_A ] = glfwGetKey( window, GLFW_KEY_A ) == GLFW_PRESS; + input.keys[ KEY_C ] = glfwGetKey( window, GLFW_KEY_C ) == GLFW_PRESS; input.keys[ KEY_D ] = glfwGetKey( window, GLFW_KEY_D ) == GLFW_PRESS; input.keys[ KEY_F ] = glfwGetKey( window, GLFW_KEY_F ) == GLFW_PRESS; input.keys[ KEY_G ] = glfwGetKey( window, GLFW_KEY_G ) == GLFW_PRESS;