2e117cf33ecc351f3ca1cbe622754d1d7b1c94cd
2 * =============================================================================
4 * Copyright . . . -----, ,----- ,---. .---.
5 * 2021-2022 |\ /| | / | | | | /|
6 * | \ / | +-- / +----- +---' | / |
7 * | \ / | | / | | \ | / |
8 * | \/ | | / | | \ | / |
9 * ' ' '--' [] '----- '----- ' ' '---' SOFTWARE
11 * =============================================================================
28 int main( int argc
, char *argv
[] )
30 vg_mem
.use_libc_malloc
= 0;
31 vg_set_mem_quota( 128*1024*1024 );
32 vg_enter( argc
, argv
, "Voyager Game Engine" );
37 VG_STATIC
void highscores_save_at_exit(void)
39 highscores_serialize_all();
42 VG_STATIC
void vg_launch_opt(void)
47 VG_STATIC
void vg_preload(void)
51 vg_convar_push( (struct vg_convar
){
54 .data_type
= k_convar_dtype_i32
,
55 .opt_i32
= { .min
=0, .max
=1, .clamp
=1 },
59 vg_convar_push( (struct vg_convar
){
62 .data_type
= k_convar_dtype_i32
,
63 .opt_i32
= { .min
=0, .max
=1, .clamp
=1 },
67 vg_info(" Copyright . . . -----, ,----- ,---. .---. \n" );
68 vg_info(" 2021-2022 |\\ /| | / | | | | /| \n" );
69 vg_info(" | \\ / | +-- / +----- +---' | / | \n" );
70 vg_info(" | \\ / | | / | | \\ | / | \n" );
71 vg_info(" | \\/ | | / | | \\ | / | \n" );
72 vg_info(" ' ' '--' [] '----- '----- ' ' '---' "
75 highscores_init( 2000, 50 );
76 if( !highscores_read() )
77 highscores_create_db();
79 vg_loader_step( NULL
, highscores_save_at_exit
);
82 vg_loader_step( NULL
, steam_end
);
83 vg_loader_step( network_init
, network_end
);
86 VG_STATIC
void vg_load(void)
88 vg_loader_step( render_init
, NULL
);
89 vg_loader_step( menu_init
, NULL
);
90 vg_loader_step( world_init
, NULL
);
91 vg_loader_step( player_init
, NULL
);
94 vg_loader_step( audio_init
, audio_free
);
97 /* 'systems' are completely loaded now */
98 strcpy( world
.world_name
, "maps/mp_mtzero.mdl" );
99 //strcpy( world.world_name, "maps/mp_gridmap.mdl" );
101 vg_console_load_autos();
104 VG_STATIC
void vg_start(void)
106 reset_player( 1, (const char *[]){ "start" } );
109 VG_STATIC
void draw_origin_axis(void)
111 vg_line( (v3f
){ 0.0f
, 0.0f
, 0.0f
}, (v3f
){ 1.0f
, 0.0f
, 0.0f
}, 0xffff0000 );
112 vg_line( (v3f
){ 0.0f
, 0.0f
, 0.0f
}, (v3f
){ 0.0f
, 1.0f
, 0.0f
}, 0xff00ff00 );
113 vg_line( (v3f
){ 0.0f
, 0.0f
, 0.0f
}, (v3f
){ 0.0f
, 0.0f
, 1.0f
}, 0xff0000ff );
116 VG_STATIC
void vg_update(void)
126 world_update( player
.phys
.rb
.co
);
130 VG_STATIC
void vg_update_fixed(void)
134 player_update_fixed();
138 VG_STATIC
void vg_update_post(void)
142 player_update_post();
147 VG_STATIC
void vg_framebuffer_resize( int w
, int h
)
152 VG_STATIC
void present_view_with_post_processing(void)
154 glBindFramebuffer( GL_FRAMEBUFFER
, 0 );
157 glDisable(GL_DEPTH_TEST
);
158 glBlendFunc(GL_ONE_MINUS_DST_ALPHA
, GL_DST_ALPHA
);
159 glBlendEquation(GL_FUNC_ADD
);
163 shader_blitblur_use();
164 shader_blitblur_uTexMain( 0 );
165 shader_blitblur_uTexMotion( 1 );
166 shader_blitblur_uBlurStrength(cl_blur_strength
/ (vg
.frame_delta
*60.0f
));
169 v2_muls( (v2f
){ 0.04f
, 0.001f
}, menu_opacity
, menu_blurring
);
170 shader_blitblur_uOverrideDir( menu_blurring
);
172 if( cl_view_id
== 0 )
173 render_fb_bind_texture( gpipeline
.fb_main
, 0, 0 );
174 else if( cl_view_id
== 1 )
175 render_fb_bind_texture( gpipeline
.fb_main
, 1, 0 );
177 render_fb_bind_texture( gpipeline
.fb_main
, 0, 0 );
179 render_fb_bind_texture( gpipeline
.fb_main
, 1, 1 );
184 shader_blit_uTexMain( 0 );
185 render_fb_bind_texture( gpipeline
.fb_main
, 0, 0 );
191 VG_STATIC
void render_player_transparent(void)
193 static camera small_cam
; /* DOES NOT NEED TO BE STATIC BUT MINGW
196 m4x3_copy( main_camera
.transform
, small_cam
.transform
);
198 small_cam
.fov
= main_camera
.fov
;
199 small_cam
.nearz
= 0.05f
;
200 small_cam
.farz
= 60.0f
;
202 camera_update_view( &small_cam
);
203 camera_update_projection( &small_cam
);
204 camera_finalize( &small_cam
);
206 /* Draw player to window buffer and blend background ontop */
208 glBindFramebuffer( GL_FRAMEBUFFER
, 0 );
209 draw_player( &small_cam
);
212 VG_STATIC
void render_scene(void)
214 render_fb_bind( gpipeline
.fb_main
);
215 glClearColor( 0.0f
, 0.0f
, 0.0f
, 1.0f
);
216 glClear( GL_COLOR_BUFFER_BIT
| GL_DEPTH_BUFFER_BIT
| GL_STENCIL_BUFFER_BIT
);
219 glEnable( GL_DEPTH_TEST
);
221 render_world( &main_camera
);
223 int player_transparent
= !(player
.is_dead
|| freecam
),
224 player_draw
= !cl_menu
;
226 if( !player_transparent
&& player_draw
)
227 draw_player( &main_camera
);
229 render_water_texture( &main_camera
);
230 render_fb_bind( gpipeline
.fb_main
);
231 render_water_surface( &main_camera
);
232 render_world_gates( &main_camera
);
234 if( player_transparent
&& player_draw
)
235 render_player_transparent();
238 VG_STATIC
void render_menu(void)
240 glClear( GL_DEPTH_BUFFER_BIT
);
241 menu_render( &main_camera
);
244 VG_STATIC
void render_main_game(void)
246 static float fov
= 60.0f
;
247 float fov_target
= vg_lerpf( 90.0f
, 110.0f
, cl_fov
);
248 if( player
.phys
.on_board
)
249 fov_target
= vg_lerpf( 97.0f
, 135.0f
, cl_fov
);
251 fov_target
= menu_fov_target
;
252 fov
= vg_lerpf( fov
, fov_target
, vg
.frame_delta
* 2.0f
);
253 fov
= freecam
? 60.0f
: fov
;
255 main_camera
.fov
= fov
;
256 main_camera
.nearz
= 0.1f
;
257 main_camera
.farz
= 2100.0f
;
259 camera_update_view( &main_camera
);
260 camera_update_projection( &main_camera
);
261 camera_finalize( &main_camera
);
263 /* ========== Begin Frame ========== */
266 present_view_with_post_processing();
271 render_player_transparent();
274 /* =========== End Frame =========== */
277 VG_STATIC
void vg_render(void)
279 glBindFramebuffer( GL_FRAMEBUFFER
, 0 );
281 glViewport( 0,0, vg
.window_x
, vg
.window_y
);
282 glDisable( GL_DEPTH_TEST
);
284 glClearColor( 1.0f
, 0.0f
, 0.0f
, 0.0f
);
285 glClear( GL_COLOR_BUFFER_BIT
|GL_DEPTH_BUFFER_BIT
);
291 glDisable( GL_DEPTH_TEST
);
292 vg_lines_drawall( (float *)main_camera
.mtx
.pv
);
293 glViewport( 0,0, vg
.window_x
, vg
.window_y
);
296 VG_STATIC
void vg_ui(void)
303 ui_global_ctx
.cursor
[0] = 10;
304 ui_global_ctx
.cursor
[1] = 10;
305 ui_global_ctx
.cursor
[2] = 200;
306 ui_global_ctx
.cursor
[3] = 20;
308 struct ub_world_lighting
*wl
= &gpipeline
.ub_world_lighting
;
309 struct ui_slider_vector
310 s5
= { .min
=0.0f
, .max
=2.0f
, .len
=3, .data
=wl
->g_ambient_colour
};
313 s8
= { .min
=0.0f
, .max
=2.0f
, .data
= &gpipeline
.shadow_spread
},
314 s9
= { .min
=0.0f
, .max
=25.0f
, .data
= &gpipeline
.shadow_length
};
316 for( int i
=0; i
<3; i
++ )
317 run_light_widget( &gpipeline
.widgets
[i
] );
319 gui_text( ui_global_ctx
.cursor
, "Ambient", 1, 0 );
320 ui_global_ctx
.cursor
[1] += 16;
321 ui_slider_vector( &ui_global_ctx
, &s5
);
323 gui_text( ui_global_ctx
.cursor
, "Shadows", 1, 0 );
324 ui_global_ctx
.cursor
[1] += 16;
325 ui_slider( &ui_global_ctx
, &s8
);
326 ui_slider( &ui_global_ctx
, &s9
);
328 gui_text( ui_global_ctx
.cursor
, "Misc", 1, 0 );
329 ui_global_ctx
.cursor
[1] += 16;
330 struct ui_checkbox c1
= {.data
= &wl
->g_light_preview
};
331 ui_checkbox( &ui_global_ctx
, &c1
);
333 render_update_lighting_ub();
337 //glPolygonMode( GL_FRONT_AND_BACK, GL_LINE );
340 render_world_routes_ui();
342 //glPolygonMode( GL_FRONT_AND_BACK, GL_FILL );
344 audio_debug_soundscapes();
345 render_view_framebuffer_ui();
349 VG_STATIC
void run_light_widget( struct light_widget
*lw
)
351 struct ui_checkbox c1
= { .data
=&lw
->enabled
};
353 ui_checkbox( &ui_global_ctx
, &c1
);
357 struct ui_slider_vector
358 colour
= { .min
=0.0f
, .max
=2.0f
, .len
=3, .data
=lw
->colour
},
359 dir
= { .min
=-VG_PIf
, .max
=VG_PIf
, .len
=2, .data
=lw
->dir
};
361 ui_slider_vector( &ui_global_ctx
, &colour
);
362 ui_global_ctx
.cursor
[1] += 4;
363 ui_slider_vector( &ui_global_ctx
, &dir
);
368 VG_STATIC
void run_debug_info(void)
372 snprintf( buf
, 40, "%.2fm/s", v3_length( player
.phys
.rb
.v
) );
373 ui_text( (ui_px
[2]){ 0, 0 }, buf
, 1, k_text_align_left
);
375 snprintf( buf
, 40, "%.2f %.2f %.2f m/s",
376 player
.phys
.a
[0], player
.phys
.a
[1], player
.phys
.a
[2] );
377 ui_text( (ui_px
[2]){ 0, 20 }, buf
, 1, k_text_align_left
);
379 snprintf( buf
, 40, "pos %.2f %.2f %.2f",
380 player
.phys
.rb
.co
[0], player
.phys
.rb
.co
[1], player
.phys
.rb
.co
[2] );
381 ui_text( (ui_px
[2]){ 0, 40 }, buf
, 1, k_text_align_left
);
383 if( vg_input
.controller_handle
)
385 for( int i
=0; i
<vg_list_size(vg_input
.controller_axises
); i
++ )
387 snprintf( buf
, 40, "%.2f", vg_input
.controller_axises
[i
] );
388 ui_text( (ui_px
[2]){ 0, (i
+3)*20 }, buf
, 1, k_text_align_left
);
393 ui_text( (ui_px
[2]){ 0, 60 },
394 "Gamepad not ready", 1, k_text_align_left
);