medfall

A super great game engine
Log | Files | Refs

commit 850e1d0904f8d681c4a1923c1074d0db5eee05af
parent e94d14a39897b7fe75dfdf79fd4be5302db9fafa
Author: Michael Savage <mikejsavage@gmail.com>
Date:   Tue, 31 Oct 2017 21:35:33 +0200

Quadtree/wireframe render toggles

Diffstat:
clipmap.cc | 37++++++++++++++++++++++++++++++++++++-
main.cc | 1+
2 files changed, 37 insertions(+), 1 deletion(-)

diff --git a/clipmap.cc b/clipmap.cc @@ -151,6 +151,24 @@ GAME_INIT( game_init ) { skybox_init( &game->skybox ); } +static void draw_qt( MinMaxu32 aabb, const array< HeightmapQuadTreeNode > nodes, size_t node_idx ) { + if( aabb.maxs.x - aabb.mins.x < 64 ) { + return; + } + + v3 mins = v3( aabb.mins.x, aabb.mins.y, aabb.mins.z / 256.0f ) - v3( 2048.0f, 2048.0f, 0 ); + v3 maxs = v3( aabb.maxs.x, aabb.maxs.y, aabb.maxs.z / 256.0f ) - v3( 2048.0f, 2048.0f, 0 ); + immediate_aabb( mins, maxs, v4( 0, 0, 1, 1 ) ); + + for( size_t i = 0; i < 4; i++ ) { + MinMaxu32 child_aabb = aabb.quadrant( i ).clamp_z( nodes[ node_idx * 4 + i + 1 ].min_z, nodes[ node_idx * 4 + i + 1 ].max_z ); + draw_qt( child_aabb, nodes, node_idx * 4 + i + 1 ); + } +} + +static bool draw_wireframe = false; +static bool draw_quadtree = false; + GAME_FRAME( game_frame ) { float fb = float( input->keys[ KEY_W ] - input->keys[ KEY_S ] ); float lr = float( input->keys[ KEY_D ] - input->keys[ KEY_A ] ); @@ -162,6 +180,11 @@ GAME_FRAME( game_frame ) { dpitch = input->keys[ KEY_K ] - input->keys[ KEY_I ]; dyaw += input->keys[ KEY_J ] - input->keys[ KEY_L ]; + if( input->keys[ KEY_M ] && input->key_edges[ KEY_M ] ) + draw_wireframe = !draw_wireframe; + if( input->keys[ KEY_T ] && input->key_edges[ KEY_T ] ) + draw_quadtree = !draw_quadtree; + dpitch -= float( input->mouse_dy * 0.25 ); dyaw -= float( input->mouse_dx * 0.25 ); @@ -219,7 +242,7 @@ GAME_FRAME( game_frame ) { render_state.textures[ 1 ] = clipmap.normalmap; render_state.textures[ 2 ] = clipmap.horizonmap; render_state.textures[ 3 ] = renderer_blue_noise(); - // render_state.wireframe = true; + render_state.wireframe = draw_wireframe; renderer_draw_mesh( clipmap.tile, render_state ); } } @@ -239,6 +262,18 @@ GAME_FRAME( game_frame ) { immediate_render( impact_render_state ); } + if( draw_quadtree ) { + v3u32 mins = v3u32( 0, 0, clipmap.quadtree.nodes[ 0 ].min_z ); + v3u32 maxs = v3u32( clipmap.quadtree.dim, clipmap.quadtree.dim, clipmap.quadtree.nodes[ 0 ].max_z ); + draw_qt( MinMaxu32( mins, maxs ), clipmap.quadtree.nodes, 0 ); + + RenderState render_state; + render_state.shader = get_shader( SHADER_WIREFRAME ); + render_state.uniforms[ UNIFORMS_VIEW ] = view_uniforms; + render_state.wireframe = true; + immediate_render( render_state ); + } + { const str< 128 > status( "Frame time: {.1}ms FPS: {.1}", dt * 1000.0f, 1.0f / dt ); draw_text( status.c_str(), 2, 2, 16.0f ); diff --git a/main.cc b/main.cc @@ -80,6 +80,7 @@ int main( int argc, char ** argv ) { input.keys[ KEY_J ] = glfwGetKey( window, GLFW_KEY_J ) == GLFW_PRESS; input.keys[ KEY_K ] = glfwGetKey( window, GLFW_KEY_K ) == GLFW_PRESS; input.keys[ KEY_L ] = glfwGetKey( window, GLFW_KEY_L ) == GLFW_PRESS; + input.keys[ KEY_M ] = glfwGetKey( window, GLFW_KEY_M ) == GLFW_PRESS; input.keys[ KEY_N ] = glfwGetKey( window, GLFW_KEY_N ) == GLFW_PRESS; input.keys[ KEY_S ] = glfwGetKey( window, GLFW_KEY_S ) == GLFW_PRESS; input.keys[ KEY_T ] = glfwGetKey( window, GLFW_KEY_T ) == GLFW_PRESS;