b46f3771b5a565abba28504e852f745fe97f5bfc
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;
24 //#define SR_NETWORKED
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 vg_init( argc
, argv
, "Voyager Game Engine" );
94 static int playermodel( int argc
, char const *argv
[] )
96 if( argc
< 1 ) return 0;
98 glmesh old_mesh
= player
.mdl
.mesh
;
100 if( character_load( &player
.mdl
, argv
[0] ) )
101 mesh_free( &old_mesh
);
110 vg_convar_push( (struct vg_convar
){
113 .data_type
= k_convar_dtype_i32
,
114 .opt_i32
= { .min
=0, .max
=1, .clamp
=1 },
118 vg_convar_push( (struct vg_convar
){
120 .data
= &walk_grid_iterations
,
121 .data_type
= k_convar_dtype_i32
,
122 .opt_i32
= { .min
=0, .max
=1, .clamp
=0 },
126 vg_convar_push( (struct vg_convar
){
129 .data_type
= k_convar_dtype_f32
,
130 .opt_f32
= { .clamp
= 0 },
134 vg_convar_push( (struct vg_convar
){
137 .data_type
= k_convar_dtype_i32
,
138 .opt_i32
= { .min
=0, .max
=1, .clamp
=1 },
142 vg_convar_push( (struct vg_convar
){
145 .data_type
= k_convar_dtype_i32
,
146 .opt_i32
= { .min
=0, .max
=1, .clamp
=1 },
150 vg_convar_push( (struct vg_convar
){
151 .name
= "walk_speed",
152 .data
= &k_walkspeed
,
153 .data_type
= k_convar_dtype_f32
,
154 .opt_f32
= { .clamp
= 0 },
158 vg_convar_push( (struct vg_convar
){
161 .data_type
= k_convar_dtype_f32
,
162 .opt_f32
= { .clamp
= 0 },
166 vg_convar_push( (struct vg_convar
){
167 .name
= "walk_accel",
168 .data
= &k_walk_accel
,
169 .data_type
= k_convar_dtype_f32
,
170 .opt_f32
= { .clamp
= 0 },
174 vg_convar_push( (struct vg_convar
){
177 .data_type
= k_convar_dtype_f32
,
178 .opt_f32
= { .clamp
= 0 },
182 vg_convar_push( (struct vg_convar
){
184 .data
= &sv_debugcam
,
185 .data_type
= k_convar_dtype_i32
,
186 .opt_i32
= { .min
=0, .max
=1, .clamp
=0 },
190 vg_convar_push( (struct vg_convar
){
193 .data_type
= k_convar_dtype_i32
,
194 .opt_i32
= { .min
=0, .max
=1, .clamp
=0 },
198 vg_function_push( (struct vg_cmd
){
200 .function
= reset_player
203 vg_tex2d_init( texture_list
, vg_list_size( texture_list
) );
208 * If we're in physics test mode we dont need to load anything else, this
209 * parameter is dev only. TODO: dev only cvars that don't ship with the game
210 * when building in release mode.
215 character_load( &player
.mdl
, "ch_new" );
216 character_init_ragdoll( &player
.mdl
);
220 reset_player( 1, (const char *[]){ "start" } );
221 rb_init( &player
.rb
);
225 else if( sv_scene
== 1 )
227 physics_test_start();
229 else if( sv_scene
== 2 )
238 vg_tex2d_free( texture_list
, vg_list_size(texture_list
) );
239 /* TODO: THE REST OF THE GOD DAMN FREEING STUFF */
252 //traffic_visualize( world.traffic, world.traffic_count );
255 if( glfwGetKey( vg_window
, GLFW_KEY_J
))
257 v3_copy( player
.camera_pos
, world
.mr_ball
.co
);
260 else if( sv_scene
== 1 )
262 physics_test_update();
264 else if( sv_scene
== 2 )
270 static void vg_framebuffer_resize( int w
, int h
)
277 static void draw_origin_axis(void)
279 vg_line( (v3f
){ 0.0f
, 0.0f
, 0.0f
}, (v3f
){ 1.0f
, 0.0f
, 0.0f
}, 0xffff0000 );
280 vg_line( (v3f
){ 0.0f
, 0.0f
, 0.0f
}, (v3f
){ 0.0f
, 1.0f
, 0.0f
}, 0xff00ff00 );
281 vg_line( (v3f
){ 0.0f
, 0.0f
, 0.0f
}, (v3f
){ 0.0f
, 0.0f
, 1.0f
}, 0xff0000ff );
284 static void render_main_game(void)
286 float speed
= freecam
? 0.0f
: v3_length( player
.rb
.v
);
287 v3f shake
= { vg_randf()-0.5f
, vg_randf()-0.5f
, vg_randf()-0.5f
};
288 v3_muls( shake
, speed
*0.01f
, shake
);
291 m4x3_expand( player
.camera_inverse
, world_4x4
);
293 gpipeline
.fov
= freecam
? 60.0f
: 125.0f
; /* 120 */
294 m4x4_projection( vg_pv
, gpipeline
.fov
,
295 (float)vg_window_x
/ (float)vg_window_y
,
298 m4x4_mul( vg_pv
, world_4x4
, vg_pv
);
300 glEnable( GL_DEPTH_TEST
);
306 int draw_solid
= player
.is_dead
| freecam
;
308 render_world( vg_pv
, player
.camera
);
311 render_water_texture( player
.camera
);
313 glBindFramebuffer( GL_FRAMEBUFFER
, 0 );
314 render_water_surface( vg_pv
, player
.camera
);
316 vg_tex2d_bind( &tex_water
, 1 ); /*TODO: ?*/
317 render_world_gates( vg_pv
, player
.camera
);
319 /* Copy the RGB of what we have into the background buffer */
320 glBindFramebuffer( GL_READ_FRAMEBUFFER
, 0 );
321 glBindFramebuffer( GL_DRAW_FRAMEBUFFER
, gpipeline
.fb_background
);
322 glBlitFramebuffer( 0,0, vg_window_x
, vg_window_y
,
323 0,0, vg_window_x
, vg_window_y
,
327 /* Clear out the colour buffer, but keep depth */
328 glBindFramebuffer( GL_FRAMEBUFFER
, 0 );
329 glClearColor( 0.0f
, 0.0f
, 0.0f
, 0.0f
);
331 if( !player
.is_dead
)
332 glClear( GL_COLOR_BUFFER_BIT
|GL_DEPTH_BUFFER_BIT
);
334 glClear( GL_COLOR_BUFFER_BIT
);
338 m4x4_projection( vg_pv
, gpipeline
.fov
,
339 (float)vg_window_x
/ (float)vg_window_y
,
341 m4x4_mul( vg_pv
, world_4x4
, vg_pv
);
345 /* Draw back in the background
347 * TODO: need to disable alpha write in the terrain shader so this works
351 glDisable(GL_DEPTH_TEST
);
352 glBlendFunc(GL_ONE_MINUS_DST_ALPHA
, GL_DST_ALPHA
);
353 glBlendEquation(GL_FUNC_ADD
);
356 shader_blit_uTexMain( 0 );
357 glActiveTexture(GL_TEXTURE0
);
358 glBindTexture( GL_TEXTURE_2D
, gpipeline
.rgb_background
);
364 glDisable( GL_DEPTH_TEST
);
365 vg_lines_drawall( (float *)vg_pv
);
366 glViewport( 0,0, vg_window_x
, vg_window_y
);
371 glBindFramebuffer( GL_FRAMEBUFFER
, 0 );
372 glViewport( 0,0, vg_window_x
, vg_window_y
);
374 glDisable( GL_DEPTH_TEST
);
375 glClearColor( 0.11f
, 0.35f
, 0.37f
, 1.0f
);
376 glClear( GL_COLOR_BUFFER_BIT
| GL_DEPTH_BUFFER_BIT
| GL_STENCIL_BUFFER_BIT
);
378 #ifndef SR_NETWORK_TEST
385 else if( sv_scene
== 1 )
387 physics_test_render();
389 else if( sv_scene
== 2 )
391 anim_test_render( &tex_characters
);
396 static void run_light_widget( struct light_widget
*lw
)
398 struct ui_checkbox c1
= { .data
=&lw
->enabled
};
400 ui_checkbox( &ui_global_ctx
, &c1
);
404 struct ui_slider_vector
405 colour
= { .min
=0.0f
, .max
=2.0f
, .len
=3, .data
=lw
->colour
},
406 dir
= { .min
=-VG_PIf
, .max
=VG_PIf
, .len
=2, .data
=lw
->dir
};
408 ui_slider_vector( &ui_global_ctx
, &colour
);
409 ui_global_ctx
.cursor
[1] += 4;
410 ui_slider_vector( &ui_global_ctx
, &dir
);
414 static void run_debug_info(void)
418 snprintf( buf
, 40, "%.2fm/s", v3_length( player
.rb
.v
) );
419 gui_text( (ui_px
[2]){ 0, 0 }, buf
, 1, k_text_align_left
);
421 snprintf( buf
, 40, "%.2f %.2f %.2f m/s",
422 player
.a
[0], player
.a
[1], player
.a
[2] );
423 gui_text( (ui_px
[2]){ 0, 20 }, buf
, 1, k_text_align_left
);
425 snprintf( buf
, 40, "pos %.2f %.2f %.2f",
426 player
.rb
.co
[0], player
.rb
.co
[1], player
.rb
.co
[2] );
427 gui_text( (ui_px
[2]){ 0, 40 }, buf
, 1, k_text_align_left
);
429 if( vg_gamepad_ready
)
431 for( int i
=0; i
<6; i
++ )
433 snprintf( buf
, 40, "%.2f", vg_gamepad
.axes
[i
] );
434 gui_text( (ui_px
[2]){ 0, (i
+3)*20 }, buf
, 1, k_text_align_left
);
439 gui_text( (ui_px
[2]){ 0, 60 },
440 "Gamepad not ready", 1, k_text_align_left
);
448 ui_global_ctx
.cursor
[0] = 10;
449 ui_global_ctx
.cursor
[1] = 10;
450 ui_global_ctx
.cursor
[2] = 200;
451 ui_global_ctx
.cursor
[3] = 20;
453 struct ub_world_lighting
*wl
= &gpipeline
.ub_world_lighting
;
454 struct ui_slider_vector
455 s5
= { .min
=0.0f
, .max
=2.0f
, .len
=3, .data
=wl
->g_ambient_colour
};
458 s8
= { .min
=0.0f
, .max
=2.0f
, .data
= &gpipeline
.shadow_spread
},
459 s9
= { .min
=0.0f
, .max
=25.0f
, .data
= &gpipeline
.shadow_length
};
461 for( int i
=0; i
<3; i
++ )
462 run_light_widget( &gpipeline
.widgets
[i
] );
464 gui_text( ui_global_ctx
.cursor
, "Ambient", 1, 0 );
465 ui_global_ctx
.cursor
[1] += 16;
466 ui_slider_vector( &ui_global_ctx
, &s5
);
468 gui_text( ui_global_ctx
.cursor
, "Shadows", 1, 0 );
469 ui_global_ctx
.cursor
[1] += 16;
470 ui_slider( &ui_global_ctx
, &s8
);
471 ui_slider( &ui_global_ctx
, &s9
);
473 gui_text( ui_global_ctx
.cursor
, "Misc", 1, 0 );
474 ui_global_ctx
.cursor
[1] += 16;
475 struct ui_checkbox c1
= {.data
= &wl
->g_light_preview
};
476 ui_checkbox( &ui_global_ctx
, &c1
);
478 render_update_lighting_ub();
481 //glPolygonMode( GL_FRONT_AND_BACK, GL_LINE );
484 render_world_routes_ui();
486 //glPolygonMode( GL_FRONT_AND_BACK, GL_FILL );
489 static double last_b_press
= 0.0;
491 double localtime
= vg_time
- last_b_press
;
493 world_routes_ui_updatetime( 0, localtime
);
494 world_routes_ui_draw( 0, (v4f
){ 1.0f
,0.0f
,1.0f
,1.0f
}, 9.0f
);
496 if( glfwGetKey(vg_window
,GLFW_KEY_B
) )
497 world_routes_ui_notch( 0, localtime
);
499 if( vg_time
-last_b_press
> 1.0 )
500 if( glfwGetKey(vg_window
,GLFW_KEY_N
) )
502 last_b_press
= vg_time
;
503 world_routes_ui_newseg( 0 );
506 static double last_m_press
;
507 if( vg_time
-last_m_press
> 1.0 )
508 if( glfwGetKey( vg_window
, GLFW_KEY_M
) )
510 last_m_press
= vg_time
;
512 vg_info( "start: %u\n",world
.routes
.routes
[0].ui
.segment_count
);
513 for( int i
=0; i
<world
.routes
.routes
[0].ui
.segment_count
; i
++ )
514 world_routes_ui_popfirst(0);
516 vg_info( "new: %u\n",world
.routes
.routes
[0].ui
.segment_count
);