7495ff34d9b5368422934a50063a89a64c2d8cdc
2 * Copyright (C) Mount0 Software, Harry Godden - All Rights Reserved
8 vg_tex2d tex_norwey
= { .path
= "textures/norway_foliage.qoi" };
9 vg_tex2d tex_grid
= { .path
= "textures/grid.qoi" };
10 vg_tex2d tex_sky
= { .path
= "textures/sky.qoi" };
11 vg_tex2d tex_gradients
= { .path
= "textures/gradients.qoi",
12 .flags
= VG_TEXTURE_CLAMP
};
13 vg_tex2d tex_cement
= { .path
= "textures/cement512.qoi" };
14 vg_tex2d tex_water
= { .path
= "textures/water.qoi" };
17 static int debugview
= 0;
18 static int sv_debugcam
= 0;
19 static int lightedit
= 0;
20 static int sv_scene
= 0;
26 /* uncomment this to run the game without any graphics being drawn */
27 //#define SR_NETWORK_TEST
37 //#include "terrain.h"
38 //#include "character.h"
40 #include "rigidbody.h"
45 #include "shaders/blit.h"
46 #include "shaders/standard.h"
47 #include "shaders/unlit.h"
49 #include "physics_test.h"
50 #include "anim_test.h"
55 void vg_register(void)
57 shader_blit_register();
58 shader_standard_register();
59 shader_vblend_register();
60 shader_unlit_register();
68 static void init_other(void)
78 vg_tex2d
*texture_list
[] =
89 int main( int argc
, char *argv
[] )
91 highscores_init( 2000, 50 );
92 vg_init( argc
, argv
, "Voyager Game Engine" );
95 static int playermodel( int argc
, char const *argv
[] )
97 if( argc
< 1 ) return 0;
99 glmesh old_mesh
= player
.mdl
.mesh
;
101 if( character_load( &player
.mdl
, argv
[0] ) )
102 mesh_free( &old_mesh
);
111 vg_convar_push( (struct vg_convar
){
114 .data_type
= k_convar_dtype_i32
,
115 .opt_i32
= { .min
=0, .max
=1, .clamp
=1 },
119 vg_convar_push( (struct vg_convar
){
121 .data
= &walk_grid_iterations
,
122 .data_type
= k_convar_dtype_i32
,
123 .opt_i32
= { .min
=0, .max
=1, .clamp
=0 },
127 vg_convar_push( (struct vg_convar
){
130 .data_type
= k_convar_dtype_f32
,
131 .opt_f32
= { .clamp
= 0 },
135 vg_convar_push( (struct vg_convar
){
138 .data_type
= k_convar_dtype_i32
,
139 .opt_i32
= { .min
=0, .max
=1, .clamp
=1 },
143 vg_convar_push( (struct vg_convar
){
146 .data_type
= k_convar_dtype_i32
,
147 .opt_i32
= { .min
=0, .max
=1, .clamp
=1 },
151 vg_convar_push( (struct vg_convar
){
152 .name
= "walk_speed",
153 .data
= &k_walkspeed
,
154 .data_type
= k_convar_dtype_f32
,
155 .opt_f32
= { .clamp
= 0 },
159 vg_convar_push( (struct vg_convar
){
162 .data_type
= k_convar_dtype_f32
,
163 .opt_f32
= { .clamp
= 0 },
167 vg_convar_push( (struct vg_convar
){
168 .name
= "walk_accel",
169 .data
= &k_walk_accel
,
170 .data_type
= k_convar_dtype_f32
,
171 .opt_f32
= { .clamp
= 0 },
175 vg_convar_push( (struct vg_convar
){
177 .data
= &k_ragdoll_floatyiness
,
178 .data_type
= k_convar_dtype_f32
,
179 .opt_f32
= { .clamp
= 0 },
183 vg_convar_push( (struct vg_convar
){
185 .data
= &k_ragdoll_floatydrag
,
186 .data_type
= k_convar_dtype_f32
,
187 .opt_f32
= { .clamp
= 0 },
191 vg_convar_push( (struct vg_convar
){
194 .data_type
= k_convar_dtype_f32
,
195 .opt_f32
= { .clamp
= 0 },
199 vg_convar_push( (struct vg_convar
){
201 .data
= &sv_debugcam
,
202 .data_type
= k_convar_dtype_i32
,
203 .opt_i32
= { .min
=0, .max
=1, .clamp
=0 },
207 vg_convar_push( (struct vg_convar
){
210 .data_type
= k_convar_dtype_i32
,
211 .opt_i32
= { .min
=0, .max
=1, .clamp
=0 },
215 vg_function_push( (struct vg_cmd
){
217 .function
= reset_player
220 vg_tex2d_init( texture_list
, vg_list_size( texture_list
) );
225 * If we're in physics test mode we dont need to load anything else, this
226 * parameter is dev only. TODO: dev only cvars that don't ship with the game
227 * when building in release mode.
232 character_load( &player
.mdl
, "ch_new" );
233 character_init_ragdoll( &player
.mdl
);
237 reset_player( 1, (const char *[]){ "start" } );
238 rb_init( &player
.rb
);
242 else if( sv_scene
== 1 )
244 physics_test_start();
246 else if( sv_scene
== 2 )
255 vg_tex2d_free( texture_list
, vg_list_size(texture_list
) );
256 /* TODO: THE REST OF THE GOD DAMN FREEING STUFF */
259 highscores_serialize_all();
272 //traffic_visualize( world.traffic, world.traffic_count );
275 if( glfwGetKey( vg_window
, GLFW_KEY_J
))
277 v3_copy( player
.camera_pos
, world
.mr_ball
.co
);
280 else if( sv_scene
== 1 )
282 physics_test_update();
284 else if( sv_scene
== 2 )
290 static void vg_framebuffer_resize( int w
, int h
)
297 static void draw_origin_axis(void)
299 vg_line( (v3f
){ 0.0f
, 0.0f
, 0.0f
}, (v3f
){ 1.0f
, 0.0f
, 0.0f
}, 0xffff0000 );
300 vg_line( (v3f
){ 0.0f
, 0.0f
, 0.0f
}, (v3f
){ 0.0f
, 1.0f
, 0.0f
}, 0xff00ff00 );
301 vg_line( (v3f
){ 0.0f
, 0.0f
, 0.0f
}, (v3f
){ 0.0f
, 0.0f
, 1.0f
}, 0xff0000ff );
304 static void render_main_game(void)
306 float speed
= freecam
? 0.0f
: v3_length( player
.rb
.v
);
307 v3f shake
= { vg_randf()-0.5f
, vg_randf()-0.5f
, vg_randf()-0.5f
};
308 v3_muls( shake
, speed
*0.01f
, shake
);
311 m4x3_expand( player
.camera_inverse
, world_4x4
);
313 gpipeline
.fov
= freecam
? 60.0f
: 125.0f
; /* 120 */
314 m4x4_projection( vg_pv
, gpipeline
.fov
,
315 (float)vg_window_x
/ (float)vg_window_y
,
318 m4x4_mul( vg_pv
, world_4x4
, vg_pv
);
320 glEnable( GL_DEPTH_TEST
);
326 int draw_solid
= player
.is_dead
| freecam
;
328 render_world( vg_pv
, player
.camera
);
331 render_water_texture( player
.camera
);
333 glBindFramebuffer( GL_FRAMEBUFFER
, 0 );
334 render_water_surface( vg_pv
, player
.camera
);
336 vg_tex2d_bind( &tex_water
, 1 ); /*TODO: ?*/
337 render_world_gates( vg_pv
, player
.camera
);
339 /* Copy the RGB of what we have into the background buffer */
340 glBindFramebuffer( GL_READ_FRAMEBUFFER
, 0 );
341 glBindFramebuffer( GL_DRAW_FRAMEBUFFER
, gpipeline
.fb_background
);
342 glBlitFramebuffer( 0,0, vg_window_x
, vg_window_y
,
343 0,0, vg_window_x
, vg_window_y
,
347 /* Clear out the colour buffer, but keep depth */
348 glBindFramebuffer( GL_FRAMEBUFFER
, 0 );
349 glClearColor( 0.0f
, 0.0f
, 0.0f
, 0.0f
);
351 if( !player
.is_dead
)
352 glClear( GL_COLOR_BUFFER_BIT
|GL_DEPTH_BUFFER_BIT
);
354 glClear( GL_COLOR_BUFFER_BIT
);
358 m4x4_projection( vg_pv
, gpipeline
.fov
,
359 (float)vg_window_x
/ (float)vg_window_y
,
361 m4x4_mul( vg_pv
, world_4x4
, vg_pv
);
365 /* Draw back in the background
367 * TODO: need to disable alpha write in the terrain shader so this works
371 glDisable(GL_DEPTH_TEST
);
372 glBlendFunc(GL_ONE_MINUS_DST_ALPHA
, GL_DST_ALPHA
);
373 glBlendEquation(GL_FUNC_ADD
);
376 shader_blit_uTexMain( 0 );
377 glActiveTexture(GL_TEXTURE0
);
378 glBindTexture( GL_TEXTURE_2D
, gpipeline
.rgb_background
);
384 glDisable( GL_DEPTH_TEST
);
385 vg_lines_drawall( (float *)vg_pv
);
386 glViewport( 0,0, vg_window_x
, vg_window_y
);
391 glBindFramebuffer( GL_FRAMEBUFFER
, 0 );
392 glViewport( 0,0, vg_window_x
, vg_window_y
);
394 glDisable( GL_DEPTH_TEST
);
395 glClearColor( 0.11f
, 0.35f
, 0.37f
, 1.0f
);
396 glClear( GL_COLOR_BUFFER_BIT
| GL_DEPTH_BUFFER_BIT
| GL_STENCIL_BUFFER_BIT
);
398 #ifndef SR_NETWORK_TEST
405 else if( sv_scene
== 1 )
407 physics_test_render();
409 else if( sv_scene
== 2 )
411 anim_test_render( &tex_characters
);
416 static void run_light_widget( struct light_widget
*lw
)
418 struct ui_checkbox c1
= { .data
=&lw
->enabled
};
420 ui_checkbox( &ui_global_ctx
, &c1
);
424 struct ui_slider_vector
425 colour
= { .min
=0.0f
, .max
=2.0f
, .len
=3, .data
=lw
->colour
},
426 dir
= { .min
=-VG_PIf
, .max
=VG_PIf
, .len
=2, .data
=lw
->dir
};
428 ui_slider_vector( &ui_global_ctx
, &colour
);
429 ui_global_ctx
.cursor
[1] += 4;
430 ui_slider_vector( &ui_global_ctx
, &dir
);
434 static void run_debug_info(void)
438 snprintf( buf
, 40, "%.2fm/s", v3_length( player
.rb
.v
) );
439 gui_text( (ui_px
[2]){ 0, 0 }, buf
, 1, k_text_align_left
);
441 snprintf( buf
, 40, "%.2f %.2f %.2f m/s",
442 player
.a
[0], player
.a
[1], player
.a
[2] );
443 gui_text( (ui_px
[2]){ 0, 20 }, buf
, 1, k_text_align_left
);
445 snprintf( buf
, 40, "pos %.2f %.2f %.2f",
446 player
.rb
.co
[0], player
.rb
.co
[1], player
.rb
.co
[2] );
447 gui_text( (ui_px
[2]){ 0, 40 }, buf
, 1, k_text_align_left
);
449 if( vg_gamepad_ready
)
451 for( int i
=0; i
<6; i
++ )
453 snprintf( buf
, 40, "%.2f", vg_gamepad
.axes
[i
] );
454 gui_text( (ui_px
[2]){ 0, (i
+3)*20 }, buf
, 1, k_text_align_left
);
459 gui_text( (ui_px
[2]){ 0, 60 },
460 "Gamepad not ready", 1, k_text_align_left
);
468 ui_global_ctx
.cursor
[0] = 10;
469 ui_global_ctx
.cursor
[1] = 10;
470 ui_global_ctx
.cursor
[2] = 200;
471 ui_global_ctx
.cursor
[3] = 20;
473 struct ub_world_lighting
*wl
= &gpipeline
.ub_world_lighting
;
474 struct ui_slider_vector
475 s5
= { .min
=0.0f
, .max
=2.0f
, .len
=3, .data
=wl
->g_ambient_colour
};
478 s8
= { .min
=0.0f
, .max
=2.0f
, .data
= &gpipeline
.shadow_spread
},
479 s9
= { .min
=0.0f
, .max
=25.0f
, .data
= &gpipeline
.shadow_length
};
481 for( int i
=0; i
<3; i
++ )
482 run_light_widget( &gpipeline
.widgets
[i
] );
484 gui_text( ui_global_ctx
.cursor
, "Ambient", 1, 0 );
485 ui_global_ctx
.cursor
[1] += 16;
486 ui_slider_vector( &ui_global_ctx
, &s5
);
488 gui_text( ui_global_ctx
.cursor
, "Shadows", 1, 0 );
489 ui_global_ctx
.cursor
[1] += 16;
490 ui_slider( &ui_global_ctx
, &s8
);
491 ui_slider( &ui_global_ctx
, &s9
);
493 gui_text( ui_global_ctx
.cursor
, "Misc", 1, 0 );
494 ui_global_ctx
.cursor
[1] += 16;
495 struct ui_checkbox c1
= {.data
= &wl
->g_light_preview
};
496 ui_checkbox( &ui_global_ctx
, &c1
);
498 render_update_lighting_ub();
501 //glPolygonMode( GL_FRONT_AND_BACK, GL_LINE );
504 render_world_routes_ui();
506 //glPolygonMode( GL_FRONT_AND_BACK, GL_FILL );
508 audio_debug_soundscapes();
512 static double last_b_press
= 0.0;
514 double localtime
= vg_time
- last_b_press
;
516 world_routes_ui_updatetime( 0, localtime
);
517 world_routes_ui_draw( 0, (v4f
){ 1.0f
,0.0f
,1.0f
,1.0f
}, 9.0f
);
519 if( glfwGetKey(vg_window
,GLFW_KEY_B
) )
520 world_routes_ui_notch( 0, localtime
);
522 if( vg_time
-last_b_press
> 1.0 )
523 if( glfwGetKey(vg_window
,GLFW_KEY_N
) )
525 last_b_press
= vg_time
;
526 world_routes_ui_newseg( 0 );
529 static double last_m_press
;
530 if( vg_time
-last_m_press
> 1.0 )
531 if( glfwGetKey( vg_window
, GLFW_KEY_M
) )
533 last_m_press
= vg_time
;
535 vg_info( "start: %u\n",world
.routes
.routes
[0].ui
.segment_count
);
536 for( int i
=0; i
<world
.routes
.routes
[0].ui
.segment_count
; i
++ )
537 world_routes_ui_popfirst(0);
539 vg_info( "new: %u\n",world
.routes
.routes
[0].ui
.segment_count
);