medfall

A super great game engine
Log | Files | Refs

commit f64cf5d7b058b9e1e215a58dc70b44e134d6c9e8
parent c23d1d090ad72f4fa86274eb22f13cfff542efc0
Author: Michael Savage <mikejsavage@gmail.com>
Date:   Mon, 29 Oct 2018 21:49:07 +0200

BSP improvements

Diffstat:
bsp.cc | 49++++++++++++++++++++++++++++++++++++++++++++-----
main.cc | 2++
2 files changed, 46 insertions(+), 5 deletions(-)

diff --git a/bsp.cc b/bsp.cc @@ -291,7 +291,7 @@ BSP_Leaf & BSP::position_to_leaf( v3 pos ) const { } GAME_INIT( game_init ) { - bsp_init( &game->bsp, "assets/bomb_carentan.bsp" ); + bsp_init( &game->bsp, "assets/acidwdm2.bsp" ); MemoryArena arena = memarena_push_arena( &mem->persistent_arena, megabytes( 10 ) ); @@ -345,7 +345,9 @@ GAME_FRAME( game_frame ) { const v3 right = normalize( cross( forward, world_up ) ); const v3 up = normalize( cross( right, forward ) ); - float speed = 320.0f; + float speed = input->keys[ KEY_LEFTCTRL ] ? 640 : 320; + if( input->keys[ KEY_LEFTALT ] ) + speed = 100; game->pos += forward * speed * dt * fb; game->pos += right * speed * dt * lr; game->pos.z += dz * speed * dt; @@ -405,9 +407,47 @@ GAME_FRAME( game_frame ) { renderer_end_pass(); } + // UI pass + renderer_begin_pass( RENDERER_CLEAR_COLOUR_DONT, RENDERER_CLEAR_DEPTH_DONT ); + + // draw crosshair { - renderer_begin_pass( RENDERER_CLEAR_COLOUR_DONT, RENDERER_CLEAR_DEPTH_DONT ); + const float aspect = get_aspect_ratio(); + const float crosshair_thickness = 0.0025f; + const float crosshair_length = 0.01f; + + const v4 red( 1, 0, 0, 1 ); + immediate_triangle( + v3( -crosshair_length, crosshair_thickness, 0 ), + v3( -crosshair_length, -crosshair_thickness, 0 ), + v3( crosshair_length, crosshair_thickness, 0 ), + red + ); + immediate_triangle( + v3( crosshair_length, -crosshair_thickness, 0 ), + v3( crosshair_length, crosshair_thickness, 0 ), + v3( -crosshair_length, -crosshair_thickness, 0 ), + red + ); + immediate_triangle( + v3( crosshair_thickness / aspect, crosshair_length * aspect, 0 ), + v3( -crosshair_thickness / aspect, crosshair_length * aspect, 0 ), + v3( crosshair_thickness / aspect, -crosshair_length * aspect, 0 ), + red + ); + immediate_triangle( + v3( -crosshair_thickness / aspect, -crosshair_length * aspect, 0 ), + v3( crosshair_thickness / aspect, -crosshair_length * aspect, 0 ), + v3( -crosshair_thickness / aspect, crosshair_length * aspect, 0 ), + red + ); + RenderState render_state; + render_state.shader = get_shader( SHADER_UI ); + render_state.depth_func = DEPTHFUNC_ALWAYS; + immediate_render( render_state ); + } + { char buf[ 256 ]; snprintf( buf, sizeof( buf ), "pos: (%.2f %.2f %.2f) pitch: %.2f yaw: %.2f forward: (%.2f %.2f %.2f) right: (%.2f %.2f %.2f) up: (%.2f %.2f %.2f)", game->pos.x, game->pos.y, game->pos.z, game->pitch, game->yaw, forward.x, forward.y, forward.z, @@ -416,9 +456,8 @@ GAME_FRAME( game_frame ) { ); draw_text( buf, 2, 2, 16 ); draw_text( str< 128 >( "drawcalls = {}, tris = {}", renderer_num_draw_calls(), renderer_num_vertices() / 3 ).c_str(), 2, 20, 16 ); - - renderer_end_pass(); } + renderer_end_pass(); renderer_end_frame(); } diff --git a/main.cc b/main.cc @@ -93,6 +93,8 @@ int main( int argc, char ** argv ) { input.keys[ KEY_W ] = glfwGetKey( window, GLFW_KEY_W ) == GLFW_PRESS; input.keys[ KEY_SPACE ] = glfwGetKey( window, GLFW_KEY_SPACE ) == GLFW_PRESS; input.keys[ KEY_LEFTSHIFT ] = glfwGetKey( window, GLFW_KEY_LEFT_SHIFT ) == GLFW_PRESS; + input.keys[ KEY_LEFTCTRL ] = glfwGetKey( window, GLFW_KEY_LEFT_CONTROL ) == GLFW_PRESS; + input.keys[ KEY_LEFTALT ] = glfwGetKey( window, GLFW_KEY_LEFT_ALT ) == GLFW_PRESS; input.keys[ KEY_UPARROW ] = glfwGetKey( window, GLFW_KEY_UP ) == GLFW_PRESS; input.keys[ KEY_DOWNARROW ] = glfwGetKey( window, GLFW_KEY_DOWN ) == GLFW_PRESS; input.keys[ KEY_LEFTARROW ] = glfwGetKey( window, GLFW_KEY_LEFT ) == GLFW_PRESS;