*/
#define SR_NETWORKED
+#define VG_DEVWINDOW
#include "common.h"
#include "conf.h"
#include "steam.h"
#include "render.h"
#include "audio.h"
#include "world.h"
-
-
-
+#include "font.h"
#include "player.h"
-static player_instance localplayer;
+
VG_STATIC struct player_avatar localplayer_avatar;
VG_STATIC glmesh localplayer_meshes[3];
vg_tex2d localplayer_texture = { .path = "textures/ch_gradient.qoi" };
-player_instance *tmp_localplayer(void)
-{
- return &localplayer;
-}
-
#include "network.h"
#include "menu.h"
#include "vehicle.h"
-static int cl_ui = 1,
- cl_light_edit = 0;
+#define DEV_AARON
+#ifdef DEV_AARON
+static rb_object aaron={
+ .type=k_rb_shape_box,
+ .rb.bbx = {{ -2.0f, -1.0f, -1.0f }, { 2.0f, 1.0f, 1.0f }}
+};
+#endif
int main( int argc, char *argv[] )
{
vg_mem.use_libc_malloc = 0;
vg_set_mem_quota( 160*1024*1024 );
vg_enter( argc, argv, "Voyager Game Engine" );
-
return 0;
}
VG_STATIC void vg_launch_opt(void)
{
-
-}
-
-VG_STATIC int __kill( int argc, const char *argv[] )
-{
-#if 0
- player_use_device( &localplayer, &player_device_dead, &localplayer_dead );
-#endif
- return 0;
-}
-
-VG_STATIC int __respawn( int argc, const char *argv[] )
-{
- ent_spawn *rp = NULL, *r;
- world_instance *world = get_active_world();
-
- if( argc == 1 ){
- for( u32 i=0; i<mdl_arrcount(&world->ent_spawn); i++ ){
- r = mdl_arritm( &world->ent_spawn, i );
- if( !strcmp( mdl_pstr(&world->meta, r->pstr_name),argv[0] ) ){
- rp = r;
- break;
- }
- }
-
- if( !rp )
- vg_warn( "No spawn named '%s'\n", argv[0] );
- }
-
- if( !rp ){
- float min_dist = INFINITY;
-
- for( u32 i=0; i<mdl_arrcount(&world->ent_spawn); i++ ){
- r = mdl_arritm( &world->ent_spawn, i );
- float d = v3_dist2( r->transform.co, localplayer.rb.co );
-
- if( d < min_dist ){
- min_dist = d;
- rp = r;
- }
- }
- }
-
- if( !rp ){
- vg_error( "No spawn found\n" );
-
- if( !mdl_arrcount(&world->ent_spawn) )
- return 0;
-
- rp = mdl_arritm( &world->ent_spawn, 0 );
- }
-
- player__spawn( &localplayer, rp );
- return 1;
}
VG_STATIC void vg_preload(void)
{
g_conf_init();
- common_var_temp();
-
- vg_var_push( (struct vg_var){
- .name = "cl_ui",
- .data = &cl_ui,
- .data_type = k_var_dtype_i32,
- .opt_i32 = { .min=0, .max=1, .clamp=1 },
- .persistent = 0
- });
-
- vg_var_push( (struct vg_var){
- .name = "ledit",
- .data = &cl_light_edit,
- .data_type = k_var_dtype_i32,
- .opt_i32 = { .min=0, .max=1, .clamp=1 },
- .persistent = 0
- });
-
- vg_function_push( (struct vg_cmd) {
- .name = "respawn",
- .function = __respawn,
- //.poll_suggest = reset_player_poll
- });
-
- vg_function_push( (struct vg_cmd) {
- .name = "ded",
- .function = __kill,
- //.poll_suggest = reset_player_poll
- });
-
vg_info(" Copyright . . . -----, ,----- ,---. .---. \n" );
-vg_info(" 2021-2022 |\\ /| | / | | | | /| \n" );
+vg_info(" 2021-2023 |\\ /| | / | | | | /| \n" );
vg_info(" | \\ / | +-- / +----- +---' | / | \n" );
vg_info(" | \\ / | | / | | \\ | / | \n" );
vg_info(" | \\/ | | / | | \\ | / | \n" );
steam_init();
vg_loader_step( NULL, steam_end );
vg_loader_step( network_init, network_end );
+
+#ifdef DEV_AARON
+ q_identity( aaron.rb.q );
+ v3_zero( aaron.rb.w );
+ v3_zero( aaron.rb.co );
+ v3_zero( aaron.rb.v );
+ rb_init_object( &aaron );
+#endif
}
VG_STATIC void load_playermodels(void)
vg_loader_step( render_init, NULL );
vg_loader_step( menu_init, NULL );
vg_loader_step( world_init, NULL );
- //vg_loader_step( player_init, NULL );
- //vg_loader_step( vehicle_init, NULL );
- //
- //vg_loader_step( player_model_init, NULL );
+ vg_loader_step( vehicle_init, NULL );
+ vg_loader_step( font3d_init, NULL );
+
+ font3d_load( &world_global.font, "models/rs_font.mdl", vg_mem.rtmemory );
+
+ vg_loader_step( player_init, NULL );
+ vg_loader_step( player_ragdoll_init, NULL );
/* ----------------- */
vg_loader_step( load_playermodels, NULL );
VG_STATIC void vg_start(void)
{
- __respawn( 1, (const char *[]){ "start" } );
+ localplayer.viewable_world = get_active_world();
+ localplayer_cmd_respawn( 1, (const char *[]){ "start" } );
}
VG_STATIC void draw_origin_axis(void)
{
steam_update();
- if( vg.is_loaded )
- {
+ if( vg.is_loaded ){
draw_origin_axis();
network_update();
-#if 0
- if( !gzoomer.inside )
- player_update_pre();
-#endif
-
player__pre_update( &localplayer );
- world_update( get_active_world(), localplayer.rb.co );
- audio_update();
+ world_update( get_active_world(), localplayer.rb.co );
+ audio_ambient_sprites_update( get_active_world(), localplayer.rb.co );
}
}
VG_STATIC void vg_update_fixed(void)
{
- if( vg.is_loaded )
- {
-#if 0
- if( !gzoomer.inside )
- player_update_fixed();
+ if( vg.is_loaded ){
+ world_routes_fixedupdate( get_active_world() );
+ player__update( &localplayer );
vehicle_update_fixed();
-#endif
- player__update( &localplayer );
- }
-}
+#ifdef DEV_AARON
+ world_instance *world = get_active_world();
+ rb_solver_reset();
+ rb_ct *buf = rb_global_buffer();
-VG_STATIC void vg_update_post(void)
-{
- if( vg.is_loaded )
- {
-#if 0
- if( gzoomer.inside )
- {
- vehicle_camera();
- }
- else
- {
- player_update_post();
+ int l = rb_box__scene( aaron.rb.to_world, aaron.rb.bbx,
+ NULL, &world->rb_geo.inf.scene, buf );
+ for( int j=0; j<l; j++ ){
+ buf[j].rba = &aaron.rb;
+ buf[j].rbb = &world->rb_geo.rb;
}
-#endif
+ rb_contact_count += l;
+ rb_presolve_contacts( rb_contact_buffer, rb_contact_count );
- player__post_update( &localplayer );
-
-
- float inr3 = 0.57735027,
- inr2 = 0.70710678118;
-
- v3f sample_directions[] = {
- { -1.0f, 0.0f, 0.0f },
- { 1.0f, 0.0f, 0.0f },
- { 0.0f, 0.0f, 1.0f },
- { 0.0f, 0.0f, -1.0f },
- { 0.0f, 1.0f, 0.0f },
- { 0.0f, -1.0f, 0.0f },
- { -inr3, inr3, inr3 },
- { inr3, inr3, inr3 },
- { -inr3, inr3, -inr3 },
- { inr3, inr3, -inr3 },
- { -inr2, 0.0f, inr2 },
- { inr2, 0.0f, inr2 },
- { -inr2, 0.0f, -inr2 },
- { inr2, 0.0f, -inr2 },
- };
-
- static int si = 0;
- static float distances[16];
-
- ray_hit ray;
- ray.dist = 5.0f;
-
- v3f rc, rd, ro;
- v3_copy( sample_directions[ si ], rd );
- v3_add( localplayer.rb.co, (v3f){0.0f,1.5f,0.0f}, ro );
- v3_copy( ro, rc );
-
- float dist = 200.0f;
-
- for( int i=0; i<10; i++ ){
- if( ray_world( get_active_world(), rc, rd, &ray ) ){
- dist = (float)i*5.0f + ray.dist;
- break;
- }
- else{
- v3_muladds( rc, rd, ray.dist, rc );
- }
+ for( int j=0; j<8; j++ ){
+ rb_solve_contacts( rb_contact_buffer, rb_contact_count );
}
- distances[si] = dist;
-
-
- for( int i=0; i<14; i++ ){
- if( distances[i] != 200.0f ){
- u32 colours[] = { VG__RED, VG__BLUE, VG__GREEN,
- VG__CYAN, VG__YELOW, VG__PINK,
- VG__WHITE };
-
- u32 colour = colours[i%7];
+ rb_iter( &aaron.rb );
+ rb_update_transform( &aaron.rb );
+#endif
- v3f p1;
- v3_muladds( ro, sample_directions[i], distances[i], p1 );
- vg_line( ro, p1, colour );
- vg_line_pt3( p1, 0.1f, colour );
- }
- }
+ }
+}
- si ++;
- if( si >= 14 )
- si = 0;
+VG_STATIC void vg_update_post(void)
+{
+ if( vg.is_loaded ){
+ player__post_update( &localplayer );
+ float dist;
+ int sample_index;
+ world_audio_sample_distances( localplayer.rb.co, &sample_index, &dist );
- /* FIXME: TEMP */
audio_lock();
- vg_dsp.echo_distances[si] = dist;
+ vg_dsp.echo_distances[sample_index] = dist;
v3f ears = { 1.0f,0.0f,0.0f };
m3x3_mulv( main_camera.transform, ears, ears );
v3_copy( ears, vg_audio.external_listener_ears );
v3_copy( main_camera.transform[3], vg_audio.external_listener_pos );
- /* TODO: this is transformed back and fourth twice. */
if( localplayer.gate_waiting ){
m4x3_mulv( localplayer.gate_waiting->transport,
vg_audio.external_listener_pos,
audio_unlock();
menu_update();
-#if 0
vehicle_update_post();
+
+#ifdef DEV_AARON
+ SDL_Scancode sc = SDL_GetScancodeFromKey( SDLK_q );
+ if( vg_input.sdl_keys[sc] ){
+ m4x3_mulv( main_camera.transform, (v3f){0.0f,0.0f,-3.0f},
+ aaron.rb.co );
+
+ v3_zero( aaron.rb.v );
+ v3_zero( aaron.rb.w );
+ rb_update_transform( &aaron.rb );
+ }
+
+ rb_object_debug( &aaron, VG__PINK );
#endif
}
}
return;
}
+ world_prerender( view_world );
render_world( view_world, &main_camera, 0 );
render_water_texture( view_world, &main_camera, 0 );
render_fb_bind( gpipeline.fb_main, 1 );
render_water_surface( view_world, &main_camera );
+}
+
+VG_STATIC void render_scene_gate_subview(void)
+{
+ render_fb_bind( gpipeline.fb_main, 1 );
+ world_instance *view_world = localplayer.viewable_world;
int depth = 1;
if( localplayer.gate_waiting ) depth = 0;
render_world_gates( view_world, &main_camera, depth );
-
- if( !cl_menu )
- render_player_transparent();
}
VG_STATIC void render_main_game(void)
render_scene();
if( cl_menu ) {
- glClear( GL_DEPTH_BUFFER_BIT );
+ //glClear( GL_DEPTH_BUFFER_BIT );
menu_render_bg();
glEnable( GL_DEPTH_TEST );
- render_player_transparent();
}
+ render_player_transparent();
+ render_scene_gate_subview();
+
present_view_with_post_processing();
if( cl_menu )
world_instance *world = get_active_world();
menu_crap_ui();
- audio_debug_soundscapes();
render_view_framebuffer_ui();
-
-#if 0
- player_physics_gui();
-#endif
-}
-
-VG_STATIC void run_debug_info(void)
-{
-#if 0
- char buf[40];
-
- snprintf( buf, 40, "%.2fm/s", v3_length( player.rb.v ) );
- ui_text( (ui_px [2]){ 0, 0 }, buf, 1, k_text_align_left );
-
- snprintf( buf, 40, "%.2f %.2f %.2f m/s",
- player.phys.a[0], player.phys.a[1], player.phys.a[2] );
- ui_text( (ui_px [2]){ 0, 20 }, buf, 1, k_text_align_left );
-
- snprintf( buf, 40, "pos %.2f %.2f %.2f",
- player.phys.rb.co[0], player.phys.rb.co[1], player.phys.rb.co[2] );
- ui_text( (ui_px [2]){ 0, 40 }, buf, 1, k_text_align_left );
-
- if( vg_input.controller_handle )
- {
- for( int i=0; i<vg_list_size(vg_input.controller_axises); i++ )
- {
- snprintf( buf, 40, "%.2f", vg_input.controller_axises[i] );
- ui_text( (ui_px [2]){ 0, (i+3)*20 }, buf, 1, k_text_align_left );
- }
- }
- else
- {
- ui_text( (ui_px [2]){ 0, 60 },
- "Gamepad not ready", 1, k_text_align_left );
- }
-#endif
}