medfall

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

commit 37872d577449889243687b6575fcb4559bc17b10
parent 4d87603346f676c033740386718a713143a97726
Author: Michael Savage <mikejsavage@gmail.com>
Date:   Sun Dec 11 14:28:05 +0200

Fireballs!

Diffstat:
hm.cc | 67+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 67 insertions(+), 0 deletions(-)
diff --git a/hm.cc b/hm.cc @@ -10,6 +10,7 @@ #include "skybox.h" #include "work_queue.h" #include "text_renderer.h" +#include "pool.h" static const char * vert_src = GLSL( in vec3 position; @@ -140,6 +141,19 @@ static m4 camera_to_view( v3 position, v3 angles ) { return m4_translation( -position ) * m4_rotz( -angles.y ) * m4_rotx( -angles.x ); } +struct Fireball { + v3 pos; + v3 velocity; +}; + +struct Explosion { + v3 pos; + double created_at; +}; + +static Pool< Fireball, 1024 > fireballs; +static Pool< Explosion, 1024 > explosions; + extern "C" GAME_FRAME( game_frame ) { renderer_begin_frame( CLEARCOLOUR_DONT ); @@ -201,6 +215,59 @@ extern "C" GAME_FRAME( game_frame ) { immediate_render( &imm, impact_render_state ); } + if( input->keys[ KEY_F ] ) { + Fireball * fireball = fireballs.acquire(); + fireball->pos = game->pos; + fireball->velocity = 128.0f * angles_to_vector( game->angles ); + } + + { + ImmediateContext imm; + static ImmediateTriangle asdf[ megabytes( 1 ) ]; + immediate_init( &imm, asdf, ARRAY_COUNT( asdf ) ); + + for( Fireball * fireball : fireballs ) { + v3 new_pos = fireball->pos + fireball->velocity * dt; + + float t; + if( segment_vs_terrain( &game->tm, fireball->pos, new_pos, &t ) ) { + Explosion * explosion = explosions.acquire(); + explosion->pos = fireball->pos + t * ( new_pos - fireball->pos ); + explosion->created_at = current_time; + + fireballs.release( fireball ); + } + else { + const float gravity = 9.81f; + fireball->pos = new_pos; + fireball->velocity.z -= dt * gravity; + immediate_sphere( &imm, fireball->pos, 4, v4( 1, 0, 0, 1 ) ); + } + } + + RenderState fireball_render_state = { }; + fireball_render_state.shader = game->test_outline_shader; + fireball_render_state.ubs[ UB_VS_HOT ] = ub_sphere; + immediate_render( &imm, fireball_render_state ); + + immediate_init( &imm, asdf, ARRAY_COUNT( asdf ) ); + + for( Explosion * explosion : explosions ) { + float t = current_time - explosion->created_at; + if( t < 0.5f ) { + immediate_sphere( &imm, explosion->pos, t * 32.0f, v4( 1, 0.5, 0, 1 ) ); + } + else { + explosions.release( explosion ); + } + } + + RenderState explosion_render_state = { }; + explosion_render_state.shader = game->test_outline_shader; + explosion_render_state.ubs[ UB_VS_HOT ] = ub_sphere; + immediate_render( &imm, explosion_render_state ); + } + { char buf[ 128 ]; snprintf( buf, sizeof( buf ), "Frame time: %.1fms FPS: %.1f", dt * 1000.0f, 1.0f / dt );