5f782d70877f5eca72cdd935554a331042e717b9
2 * =============================================================================
4 * Copyright . . . -----, ,----- ,---. .---.
5 * 2021-2022 |\ /| | / | | | | /|
6 * | \ / | +-- / +----- +---' | / |
7 * | \ / | | / | | \ | / |
8 * | \/ | | / | | \ | / |
9 * ' ' '--' [] '----- '----- ' ' '---' SOFTWARE
11 * =============================================================================
27 int main( int argc
, char *argv
[] )
29 vg_mem
.use_libc_malloc
= 0;
30 vg_set_mem_quota( 128*1024*1024 );
31 vg_enter( argc
, argv
, "Voyager Game Engine" );
36 VG_STATIC
void highscores_save_at_exit(void*_
)
38 highscores_serialize_all();
41 VG_STATIC
void vg_launch_opt(void)
46 VG_STATIC
void vg_preload(void)
48 vg_convar_push( (struct vg_convar
){
51 .data_type
= k_convar_dtype_i32
,
52 .opt_i32
= { .min
=0, .max
=1, .clamp
=1 },
56 vg_convar_push( (struct vg_convar
){
58 .data
= &g_fov_option
,
59 .data_type
= k_convar_dtype_f32
,
60 .opt_f32
= { .clamp
= 0 },
64 vg_info(" Copyright . . . -----, ,----- ,---. .---. \n" );
65 vg_info(" 2021-2022 |\\ /| | / | | | | /| \n" );
66 vg_info(" | \\ / | +-- / +----- +---' | / | \n" );
67 vg_info(" | \\ / | | / | | \\ | / | \n" );
68 vg_info(" | \\/ | | / | | \\ | / | \n" );
69 vg_info(" ' ' '--' [] '----- '----- ' ' '---' "
72 highscores_init( 2000, 50 );
73 if( !highscores_read() )
74 highscores_create_db();
76 vg_loader_highwater( NULL
, highscores_save_at_exit
, NULL
);
81 vg_loader_highwater( NULL
, steam_end
, NULL
);
82 vg_loader_highwater( network_init
, network_end
, NULL
);
85 VG_STATIC
void vg_load(void)
87 vg_loader_highwater( render_init
, NULL
, NULL
);
88 vg_loader_highwater( menu_init
, NULL
, NULL
);
89 vg_loader_highwater( world_init
, NULL
, NULL
);
90 vg_loader_highwater( player_init
, NULL
, NULL
);
93 vg_loader_highwater( audio_init
, audio_free
, NULL
);
96 /* 'systems' are completely loaded now */
97 strcpy( world
.world_name
, "maps/mp_mtzero.mdl" );
98 strcpy( world
.world_name
, "maps/mp_gridmap.mdl" );
100 vg_console_load_autos();
103 VG_STATIC
void vg_start(void)
105 reset_player( 1, (const char *[]){ "start" } );
108 VG_STATIC
void draw_origin_axis(void)
110 vg_line( (v3f
){ 0.0f
, 0.0f
, 0.0f
}, (v3f
){ 1.0f
, 0.0f
, 0.0f
}, 0xffff0000 );
111 vg_line( (v3f
){ 0.0f
, 0.0f
, 0.0f
}, (v3f
){ 0.0f
, 1.0f
, 0.0f
}, 0xff00ff00 );
112 vg_line( (v3f
){ 0.0f
, 0.0f
, 0.0f
}, (v3f
){ 0.0f
, 0.0f
, 1.0f
}, 0xff0000ff );
115 VG_STATIC
void vg_update( int loaded
)
125 world_update( player
.phys
.rb
.co
);
129 VG_STATIC
void vg_update_fixed( int loaded
)
133 player_update_fixed();
137 VG_STATIC
void vg_update_post( int loaded
)
141 player_update_post();
146 VG_STATIC
void vg_framebuffer_resize( int w
, int h
)
152 VG_STATIC
void render_main_game(void)
155 m4x3_expand( camera_mtx_inverse
, world_4x4
);
157 static float fov
= 60.0f
;
159 float fov_target
= vg_lerpf( 90.0f
, 110.0f
, g_fov_option
);
161 if( player
.phys
.on_board
)
162 fov_target
= vg_lerpf( 97.0f
, 135.0f
, g_fov_option
);
165 fov_target
= menu_fov_target
;
167 fov
= vg_lerpf( fov
, fov_target
, vg
.frame_delta
* 2.0f
);
169 gpipeline
.fov
= freecam
? 60.0f
: fov
; /* 120 */
170 m4x4_projection( vg
.pv
, gpipeline
.fov
,
171 (float)vg
.window_x
/ (float)vg
.window_y
,
174 m4x4_mul( vg
.pv
, world_4x4
, vg
.pv
);
175 glEnable( GL_DEPTH_TEST
);
181 int draw_solid
= player
.is_dead
| freecam
;
182 render_world( vg
.pv
, camera_mtx
);
185 draw_player( camera_mtx
);
187 render_water_texture( camera_mtx
);
189 glBindFramebuffer( GL_FRAMEBUFFER
, 0 );
190 render_water_surface( vg
.pv
, camera_mtx
);
191 render_world_gates( vg
.pv
, player
.phys
.rb
.co
, camera_mtx
);
195 glClear( GL_DEPTH_BUFFER_BIT
);
196 menu_render( vg
.pv
);
199 /* Copy the RGB of what we have into the background buffer */
200 glBindFramebuffer( GL_READ_FRAMEBUFFER
, 0 );
201 glBindFramebuffer( GL_DRAW_FRAMEBUFFER
, gpipeline
.fb_background
);
202 glBlitFramebuffer( 0,0, vg
.window_x
, vg
.window_y
,
203 0,0, vg
.window_x
, vg
.window_y
,
207 /* Clear out the colour buffer, but keep depth */
208 glBindFramebuffer( GL_FRAMEBUFFER
, 0 );
209 glClearColor( 0.0f
, 0.0f
, 0.0f
, 0.0f
);
211 if( !player
.is_dead
)
212 glClear( GL_COLOR_BUFFER_BIT
|GL_DEPTH_BUFFER_BIT
);
214 glClear( GL_COLOR_BUFFER_BIT
);
218 m4x4_projection( vg
.pv
, gpipeline
.fov
,
219 (float)vg
.window_x
/ (float)vg
.window_y
,
221 m4x4_mul( vg
.pv
, world_4x4
, vg
.pv
);
222 draw_player( camera_mtx
);
225 /* Draw back in the background
227 * TODO: need to disable alpha write in the terrain shader so this works
231 glDisable(GL_DEPTH_TEST
);
232 glBlendFunc(GL_ONE_MINUS_DST_ALPHA
, GL_DST_ALPHA
);
233 glBlendEquation(GL_FUNC_ADD
);
236 shader_blit_uTexMain( 0 );
237 glActiveTexture(GL_TEXTURE0
);
238 glBindTexture( GL_TEXTURE_2D
, gpipeline
.rgb_background
);
243 VG_STATIC
void vg_render(void)
245 glBindFramebuffer( GL_FRAMEBUFFER
, 0 );
246 glViewport( 0,0, vg
.window_x
, vg
.window_y
);
247 glDisable( GL_DEPTH_TEST
);
249 glClearColor( 0.11f
, 0.35f
, 0.37f
, 1.0f
);
250 glClear( GL_COLOR_BUFFER_BIT
| GL_DEPTH_BUFFER_BIT
| GL_STENCIL_BUFFER_BIT
);
257 glDisable( GL_DEPTH_TEST
);
258 vg_lines_drawall( (float *)vg
.pv
);
259 glViewport( 0,0, vg
.window_x
, vg
.window_y
);
262 VG_STATIC
void vg_ui(void)
269 ui_global_ctx
.cursor
[0] = 10;
270 ui_global_ctx
.cursor
[1] = 10;
271 ui_global_ctx
.cursor
[2] = 200;
272 ui_global_ctx
.cursor
[3] = 20;
274 struct ub_world_lighting
*wl
= &gpipeline
.ub_world_lighting
;
275 struct ui_slider_vector
276 s5
= { .min
=0.0f
, .max
=2.0f
, .len
=3, .data
=wl
->g_ambient_colour
};
279 s8
= { .min
=0.0f
, .max
=2.0f
, .data
= &gpipeline
.shadow_spread
},
280 s9
= { .min
=0.0f
, .max
=25.0f
, .data
= &gpipeline
.shadow_length
};
282 for( int i
=0; i
<3; i
++ )
283 run_light_widget( &gpipeline
.widgets
[i
] );
285 gui_text( ui_global_ctx
.cursor
, "Ambient", 1, 0 );
286 ui_global_ctx
.cursor
[1] += 16;
287 ui_slider_vector( &ui_global_ctx
, &s5
);
289 gui_text( ui_global_ctx
.cursor
, "Shadows", 1, 0 );
290 ui_global_ctx
.cursor
[1] += 16;
291 ui_slider( &ui_global_ctx
, &s8
);
292 ui_slider( &ui_global_ctx
, &s9
);
294 gui_text( ui_global_ctx
.cursor
, "Misc", 1, 0 );
295 ui_global_ctx
.cursor
[1] += 16;
296 struct ui_checkbox c1
= {.data
= &wl
->g_light_preview
};
297 ui_checkbox( &ui_global_ctx
, &c1
);
299 render_update_lighting_ub();
303 //glPolygonMode( GL_FRONT_AND_BACK, GL_LINE );
306 render_world_routes_ui();
308 //glPolygonMode( GL_FRONT_AND_BACK, GL_FILL );
310 audio_debug_soundscapes();
314 VG_STATIC
void run_light_widget( struct light_widget
*lw
)
316 struct ui_checkbox c1
= { .data
=&lw
->enabled
};
318 ui_checkbox( &ui_global_ctx
, &c1
);
322 struct ui_slider_vector
323 colour
= { .min
=0.0f
, .max
=2.0f
, .len
=3, .data
=lw
->colour
},
324 dir
= { .min
=-VG_PIf
, .max
=VG_PIf
, .len
=2, .data
=lw
->dir
};
326 ui_slider_vector( &ui_global_ctx
, &colour
);
327 ui_global_ctx
.cursor
[1] += 4;
328 ui_slider_vector( &ui_global_ctx
, &dir
);
333 VG_STATIC
void run_debug_info(void)
337 snprintf( buf
, 40, "%.2fm/s", v3_length( player
.phys
.rb
.v
) );
338 ui_text( (ui_px
[2]){ 0, 0 }, buf
, 1, k_text_align_left
);
340 snprintf( buf
, 40, "%.2f %.2f %.2f m/s",
341 player
.phys
.a
[0], player
.phys
.a
[1], player
.phys
.a
[2] );
342 ui_text( (ui_px
[2]){ 0, 20 }, buf
, 1, k_text_align_left
);
344 snprintf( buf
, 40, "pos %.2f %.2f %.2f",
345 player
.phys
.rb
.co
[0], player
.phys
.rb
.co
[1], player
.phys
.rb
.co
[2] );
346 ui_text( (ui_px
[2]){ 0, 40 }, buf
, 1, k_text_align_left
);
348 if( vg_input
.controller_handle
)
350 for( int i
=0; i
<vg_list_size(vg_input
.controller_axises
); i
++ )
352 snprintf( buf
, 40, "%.2f", vg_input
.controller_axises
[i
] );
353 ui_text( (ui_px
[2]){ 0, (i
+3)*20 }, buf
, 1, k_text_align_left
);
358 ui_text( (ui_px
[2]){ 0, 60 },
359 "Gamepad not ready", 1, k_text_align_left
);