chaos pt 2
authorhgn <hgodden00@gmail.com>
Mon, 20 Nov 2023 10:02:40 +0000 (10:02 +0000)
committerhgn <hgodden00@gmail.com>
Mon, 20 Nov 2023 10:02:40 +0000 (10:02 +0000)
26 files changed:
build.c
camera.h
ent_miniworld.c
ent_miniworld.h
entity.h
player.c
player.h
player_common.c
render.h
respawn.c
shaders/blit_transition.fs [new file with mode: 0644]
shaders/blit_transition.h [new file with mode: 0644]
skaterift.c
workshop.c
world.c
world.h
world_entity.c
world_entity.h
world_gate.c
world_gate.h
world_load.c
world_render.c
world_render.h
world_routes.c
world_water.c
world_water.h

diff --git a/build.c b/build.c
index 4cf3b34c3e017dc07701bd133e99a56a82ac43c6..0470a3b926f199fc6b91e3c52a86c5a33bd27b66 100644 (file)
--- a/build.c
+++ b/build.c
@@ -275,5 +275,6 @@ void build_shaders(void){
    _S( "blit",      "blit.vs",      "blit.fs" );
    _S( "blitblur",  "blit.vs",      "blitblur.fs" );
    _S( "blitcolour","blit.vs",      "colour.fs" );
+   _S( "blit_transition", "blit.vs", "blit_transition.fs" );
    _S( "routeui",   "routeui.vs",   "routeui.fs" );
 }
index c1744d86f23f556deaad3f4e7c2bfc55a8f122ea..7bd14e64e6c0eefd4db4d71d6d79cbb4fe8d2558 100644 (file)
--- a/camera.h
+++ b/camera.h
@@ -29,11 +29,10 @@ static void camera_lerp_angles( v3f a, v3f b, float t, v3f d ){
    d[2] = vg_lerpf(  a[2], b[2], t );
 }
 
+/* lerp position, fov, and angles */
 static void camera_lerp( camera *a, camera *b, float t, camera *d ){
    v3_lerp( a->pos, b->pos, t, d->pos );
-   d->angles[0] = vg_alerpf( a->angles[0], b->angles[0], t );
-   d->angles[1] = vg_lerpf( a->angles[1], b->angles[1], t );
-   d->angles[2] = vg_lerpf( a->angles[2], b->angles[2], t );
+   camera_lerp_angles( a->angles, b->angles, t, d->angles );
    d->fov = vg_lerpf( a->fov, b->fov, t );
 }
 
@@ -43,6 +42,16 @@ static void camera_copy( camera *a, camera *d ){
    d->fov = a->fov;
 }
 
+static void m4x3_transform_camera( m4x3f m, camera *cam ){
+   m4x3_mulv( m, cam->pos, cam->pos );
+
+   v3f v0;
+   v3_angles_vector( cam->angles, v0 );
+   m3x3_mulv( m, v0, v0 );
+   v3_normalize( v0 );
+   v3_angles( v0, cam->angles );
+}
+
 /*
  * 1) [angles, pos] -> transform 
  */
index cd79b4552626ca5dda89aac1bbcd0b7d1ef63419..9c439c7c797a5c7f44bd7abc233f8d7540e93560 100644 (file)
@@ -13,14 +13,10 @@ static void ent_miniworld_call( world_instance *world, ent_call *call ){
       const char *uid = mdl_pstr( &world->meta, miniworld->pstr_world );
       skaterift_load_world_command( 1, (const char *[]){ uid } );
 
-      global_miniworld.active_id = call->id;
+      global_miniworld.active = miniworld;
    }
    else if( call->function == 1 ){
-
-      if( global_miniworld.active_id == call->id )
-         global_miniworld.active_id = 0;
-      else 
-         vg_warn( "bad call\n" );
+      global_miniworld.active = NULL;
 
       if( miniworld->proxy ){
          ent_prop *prop = mdl_arritm( &world->ent_prop, 
@@ -30,17 +26,19 @@ static void ent_miniworld_call( world_instance *world, ent_call *call ){
    }
 }
 
-static void ent_miniworld_render( world_instance *host_world ){
-   u32 entity_id = global_miniworld.active_id;
+static void ent_miniworld_render( world_instance *host_world, camera *cam ){
+   if( host_world != &world_static.instances[k_world_purpose_hub] )
+      return;
+
+   ent_miniworld *miniworld = global_miniworld.active;
 
-   if( !entity_id )
+   if( !miniworld )
       return;
-   
-   ent_miniworld *miniworld = mdl_arritm( &host_world->ent_miniworld, 
-                                          mdl_entity_id_id(entity_id) );
+
+   world_instance *dest_world = &world_static.instances[k_world_purpose_client];
 
    int rendering = 1;
-   if( miniworld->purpose == k_world_purpose_invalid )
+   if( dest_world->status != k_world_status_loaded )
       rendering = 0;
 
    if( miniworld->proxy ){
@@ -52,24 +50,48 @@ static void ent_miniworld_render( world_instance *host_world ){
          prop->flags |= 0x1;
    }
 
+
    if( !rendering )
       return;
 
-   world_instance *dest_world = &world_static.instances[miniworld->purpose];
-
-
    m4x3f mmdl;
    mdl_transform_m4x3( &miniworld->transform, mmdl );
-   render_world_override( dest_world, host_world, mmdl );
-
+   render_world_override( dest_world, host_world, mmdl, cam );
    //render_world_routes( , &skaterift.cam, 1 );
 }
 
 static void ent_miniworld_preupdate(void){
-   if( !global_miniworld.active_id )
+   if( world_static.active_instance == k_world_purpose_client ){
+      if( button_down(k_srbind_mleft) ){
+         global_miniworld.transition = -1;
+         global_miniworld.t = 1.0f;
+
+         global_miniworld.cam = skaterift.cam;
+         m4x3_transform_camera( global_miniworld.mmdl, &global_miniworld.cam );
+         world_switch_instance(0);
+      }
+   }
+
+   ent_miniworld *miniworld = global_miniworld.active;
+   if( !miniworld )
       return;
 
-   if( button_down( k_srbind_use ) ){
-      
+   world_instance *world = world_current_instance();
+
+   if( global_miniworld.transition ){
+   }
+   else {
+      int rendering = 1;
+      if( world_static.instances[k_world_purpose_client].status 
+            == k_world_status_loaded ){
+         if( button_down( k_srbind_mright ) ){
+            global_miniworld.transition = 1;
+            global_miniworld.t = 0.0f;
+            global_miniworld.cam = skaterift.cam;
+
+            mdl_transform_m4x3( &miniworld->transform, global_miniworld.mmdl );
+            world_switch_instance(1);
+         }
+      }
    }
 }
index 73b660eafed88bf770fea3e4304c97bec70f9f7a..2be614187f2f42b94ab23af0832f5ae71b89ab81 100644 (file)
@@ -4,10 +4,16 @@
 #include "entity.h"
 
 struct {
-   u32 active_id;
+   ent_miniworld *active;
+   int transition;
+   f32 t;
+
+   m4x3f mmdl;
+   camera cam;
 }
 static global_miniworld;
 
 static void ent_miniworld_call( world_instance *world, ent_call *call );
+static void ent_miniworld_render( world_instance *host_world, camera *cam );
 
 #endif /* ENT_MINIWORLD_H */
index bdb69f85593b01008d3793f267b4cff26fd3992f..7cfce589b881e60605e57d9b2d0b5b3cb8f4e4f1 100644 (file)
--- a/entity.h
+++ b/entity.h
@@ -505,7 +505,7 @@ struct ent_miniworld {
    mdl_transform transform;
    u32 pstr_world;
 
-   i32 purpose;
+   i32 purpose_DELTED;
    u32 proxy;
 };
 
index 23cb5fcaf4ceeaae7f8d09c020be987e08d5fba0..3084828d38cb7a804cc205c15446d7a1525b3c9e 100644 (file)
--- a/player.c
+++ b/player.c
@@ -15,7 +15,7 @@
 
 static int localplayer_cmd_respawn( int argc, const char *argv[] ){
    ent_spawn *rp = NULL, *r;
-   world_instance *world = localplayer.viewable_world;
+   world_instance *world = world_current_instance();
 
    if( argc == 1 ){
       rp = world_find_spawn_by_name( world, argv[0] );
@@ -236,7 +236,6 @@ static void player__reset(void){
 
    localplayer.immobile = 0;
    localplayer.gate_waiting = NULL;
-   localplayer.viewable_world = world_current_instance();
 
    world_static.challenge_target = NULL;
    world_static.challenge_timer = 0.0f;
@@ -253,6 +252,8 @@ static void player__reset(void){
          world_routes_clear( instance );
       }
    }
+
+   v3_copy( localplayer.rb.co, localplayer.cam_control.tpv_lpf );
 }
 
 static void player__spawn( ent_spawn *rp ){
index cd6bca59e83419045ec930bd668918ceef32c6ee..63cd302d673f6f518db6e0130a1b88899ef14b01 100644 (file)
--- a/player.h
+++ b/player.h
@@ -76,8 +76,8 @@ struct {
 #if 0
    v4f   qbasis;
    m3x3f basis, invbasis, basis_gate;
-#endif
    world_instance *viewable_world;
+#endif
 
    /*
     * Camera management
index 8ea57a4380021585af39ea05e0ad3868ed421f20..d1e8fc604aaa067766690eba1d6b5b59abff1bcb 100644 (file)
@@ -27,7 +27,6 @@ static void player_camera_portal_correction(void){
          vg_success( "Plane cleared\n" );
          player_apply_transport_to_cam( localplayer.gate_waiting->transport );
          localplayer.gate_waiting = NULL;
-         localplayer.viewable_world = world_current_instance();
       }
       else{
          /* de-transform camera and player back */
@@ -220,7 +219,7 @@ static void player__cam_iterate(void){
       ent_camera *cam = NULL;
       f32 min_dist = k_cinema;
 
-      world_instance *world = localplayer.viewable_world;
+      world_instance *world = world_current_instance();
       for( u32 i=0; i<mdl_arrcount(&world->ent_camera); i++ ){
          ent_camera *c = mdl_arritm(&world->ent_camera,i);
 
index ea88ecc4df956c54f206f50a3b5c5946a17aea43..8310ca535bb166ad9f084aa81f9c7ae4a368b024 100644 (file)
--- a/render.h
+++ b/render.h
@@ -10,6 +10,7 @@
 #include "shaders/blit.h"
 #include "shaders/blitblur.h"
 #include "shaders/blitcolour.h"
+#include "shaders/blit_transition.h"
 
 #define WORKSHOP_PREVIEW_WIDTH  504
 #define WORKSHOP_PREVIEW_HEIGHT 336
@@ -597,6 +598,7 @@ static void render_init(void)
    shader_blit_register();
    shader_blitblur_register();
    shader_blitcolour_register();
+   shader_blit_transition_register();
 
    vg_async_call( async_render_init, NULL, 0 );
 }
index 084844d03298bab2d4dc1341a87a7e4a97968bfd..f7be930b60cf883f1f571bc0c178b5fc1258cb8e 100644 (file)
--- a/respawn.c
+++ b/respawn.c
@@ -101,8 +101,6 @@ static void respawn_chooser_pre_update(void){
 
       if( respawn_chooser.spawn ){
          world_static.active_instance = respawn_chooser.world_id;
-         localplayer.viewable_world = 
-            &world_static.instances[ respawn_chooser.world_id ];
          player__spawn( respawn_chooser.spawn );
       }
       return;
diff --git a/shaders/blit_transition.fs b/shaders/blit_transition.fs
new file mode 100644 (file)
index 0000000..1f73abd
--- /dev/null
@@ -0,0 +1,15 @@
+out vec4 FragColor;
+in vec2 aUv;
+uniform float uT;
+
+void main(){
+   float d = uT + distance( aUv, vec2(0.5,0.5) );
+
+   vec3 vDither = vec3( dot( vec2( 171.0, 231.0 ), gl_FragCoord.xy) );
+   float dither = fract( vDither.g / 71.0 ) - 0.5;
+
+   if( d+dither < -0.5 )
+      discard;
+
+   FragColor = vec4( 1.0, 0.0, 0.0, 1.0 );
+}
diff --git a/shaders/blit_transition.h b/shaders/blit_transition.h
new file mode 100644 (file)
index 0000000..f5f3049
--- /dev/null
@@ -0,0 +1,61 @@
+#ifndef SHADER_blit_transition_H
+#define SHADER_blit_transition_H
+static void shader_blit_transition_link(void);
+static void shader_blit_transition_register(void);
+static struct vg_shader _shader_blit_transition = {
+   .name = "blit_transition",
+   .link = shader_blit_transition_link,
+   .vs = 
+{
+.orig_file = "shaders/blit.vs",
+.static_src = 
+"layout (location=0) in vec2 a_co;\n"
+"out vec2 aUv;\n"
+"\n"
+"uniform vec2 uInverseRatio;\n"
+"\n"
+"void main()\n"
+"{\n"
+"   gl_Position = vec4(a_co*2.0-1.0,0.0,1.0);\n"
+"   aUv = a_co * uInverseRatio;\n"
+"}\n"
+""},
+   .fs = 
+{
+.orig_file = "shaders/blit_transition.fs",
+.static_src = 
+"out vec4 FragColor;\n"
+"in vec2 aUv;\n"
+"uniform float uT;\n"
+"\n"
+"void main(){\n"
+"   float d = uT + distance( aUv, vec2(0.5,0.5) );\n"
+"\n"
+"   vec3 vDither = vec3( dot( vec2( 171.0, 231.0 ), gl_FragCoord.xy) );\n"
+"   float dither = fract( vDither.g / 71.0 ) - 0.5;\n"
+"\n"
+"   if( d+dither < -0.5 )\n"
+"      discard;\n"
+"\n"
+"   FragColor = vec4( 1.0, 0.0, 0.0, 1.0 );\n"
+"}\n"
+""},
+};
+
+static GLuint _uniform_blit_transition_uInverseRatio;
+static GLuint _uniform_blit_transition_uT;
+static void shader_blit_transition_uInverseRatio(v2f v){
+   glUniform2fv(_uniform_blit_transition_uInverseRatio,1,v);
+}
+static void shader_blit_transition_uT(float f){
+   glUniform1f(_uniform_blit_transition_uT,f);
+}
+static void shader_blit_transition_register(void){
+   vg_shader_register( &_shader_blit_transition );
+}
+static void shader_blit_transition_use(void){ glUseProgram(_shader_blit_transition.id); }
+static void shader_blit_transition_link(void){
+   _uniform_blit_transition_uInverseRatio = glGetUniformLocation( _shader_blit_transition.id, "uInverseRatio" );
+   _uniform_blit_transition_uT = glGetUniformLocation( _shader_blit_transition.id, "uT" );
+}
+#endif /* SHADER_blit_transition_H */
index 24c39a8ff9fa307ea6bc81ec6166eb0528ab7687..254c80df27e6a28700d52ed788bdf2b657408ac3 100644 (file)
@@ -333,11 +333,11 @@ static void vg_pre_update(void){
    vg.time_rate = vg_smoothstepf( skaterift.time_rate );
    
    /* TODO: how can we compress this? */
+   ent_miniworld_preupdate();
    player__pre_update();
    world_entity_focus_preupdate();
    skaterift_replay_pre_update();
    remote_sfx_pre_update();
-   ent_miniworld_preupdate();
 
    world_update( world_current_instance(), localplayer.rb.co );
    audio_ambient_sprites_update( world_current_instance(), localplayer.rb.co );
@@ -477,53 +477,47 @@ static void render_scene(void){
    /* Draw world */
    glEnable( GL_DEPTH_TEST );
 
-   world_instance *view_world = localplayer.viewable_world;
-
-   if( view_world == NULL ){
-      glClearColor( 0.25f, 0.25f, 0.0f, 1.0f );
-      glClear( GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT|GL_STENCIL_BUFFER_BIT );
-      return;
-   }
-
    for( u32 i=0; i<vg_list_size(world_static.instances); i++ ){
       if( world_static.instances[i].status == k_world_status_loaded ){
          world_prerender( &world_static.instances[i] );
       }
    }
 
-   if( skaterift.activity == k_skaterift_respawning ){
-      glDrawBuffers( 1, (GLenum[]){ GL_COLOR_ATTACHMENT0 } );
-      glClearColor( 0.624f, 0.659f, 0.769f, 0.0f );
-      glClearColor( 0.824f, 0.0f, 0.1f, 0.0f );
-      glClear( GL_COLOR_BUFFER_BIT );
-      glDrawBuffers( 2, (GLenum[]){ GL_COLOR_ATTACHMENT0, 
-                                    GL_COLOR_ATTACHMENT1 } );
-#if 0
-      view_world = &world_static.instances[respawn_chooser.world_id];
-      render_world_override( view_world );
-      render_world_routes( view_world, &skaterift.cam, 1 );
-#endif
+   render_world( world_current_instance(), &skaterift.cam, 0, 0, 1, 1 );
+
+   world_instance *holdout_world = NULL;
+   f32 t = 0.0f;
+
+   if( global_miniworld.transition == 1 ){
+      holdout_world = &world_static.instances[ k_world_purpose_hub ];
+      t = global_miniworld.t;
    }
-   else{
-      render_world( view_world, &skaterift.cam, 0 );
-      render_water_texture( view_world, &skaterift.cam, 0 );
-      render_fb_bind( gpipeline.fb_main, 1 );
-      render_water_surface( view_world, &skaterift.cam );
-      render_remote_players( view_world, &skaterift.cam );
-      ent_miniworld_render( view_world );
+   else if( global_miniworld.transition == -1 ){
+      holdout_world = &world_static.instances[ k_world_purpose_client ];
+      t = 1.0f-global_miniworld.t;
+   }
+   else {
    }
 
-}
+   if( holdout_world ){
+      if( holdout_world->status != k_world_status_loaded )
+         return;
 
-static void render_scene_gate_subview(void){
-   render_fb_bind( gpipeline.fb_main, 1 );
-   world_instance *view_world = localplayer.viewable_world;
-   if( !view_world ) return; /* ??? */
-   if( skaterift.activity == k_skaterift_respawning ) return;
+      t = vg_smoothstepf( t );
+
+      glEnable( GL_STENCIL_TEST );
+      glDisable( GL_DEPTH_TEST );
+      glStencilOp( GL_KEEP, GL_KEEP, GL_REPLACE );  
+      glStencilFunc( GL_ALWAYS, 1, 0xFF ); 
+      glStencilMask( 0xFF );
 
-   int depth = 1;
-   if( localplayer.gate_waiting ) depth = 0;
-   render_world_gates( view_world, &skaterift.cam, depth );
+      shader_blit_transition_use();
+      shader_blit_transition_uInverseRatio( (v2f){1.0f,1.0f} );
+      shader_blit_transition_uT( -(sqrtf(2)+0.5f) * t );
+
+      render_fsquad();
+      render_world( holdout_world, &global_miniworld.cam, 1, 0, 1, 1 );
+   }
 }
 
 static void skaterift_composite_maincamera(void){
@@ -537,6 +531,20 @@ static void skaterift_composite_maincamera(void){
    skaterift.cam.nearz = 0.1f;
    skaterift.cam.farz  = 2100.0f;
 
+   if( global_miniworld.transition ){
+      f32 dt = vg.time_frame_delta / 2.0f,
+          s  = vg_signf( global_miniworld.transition );
+      global_miniworld.t += s * dt;
+
+      if( (global_miniworld.t > 1.0f) || (global_miniworld.t < 0.0f) ){
+         /* TODO: maybe next frame! */
+         global_miniworld.t = vg_clampf( global_miniworld.t, 0.0f, 1.0f );
+         global_miniworld.transition = 0;
+      }
+      else {
+      }
+   }
+
    if( skaterift.activity == k_skaterift_respawning ){
       camera_copy( &respawn_chooser.cam, &skaterift.cam );
       skaterift.cam.nearz = 4.0f;
@@ -544,20 +552,6 @@ static void skaterift_composite_maincamera(void){
    }
 
    camera_update_transform( &skaterift.cam );
-
-#if 0 
-   if( skaterift.activity != k_skaterift_respawning ){
-      if( localplayer.gate_waiting ){
-         m3x3_mul( localplayer.basis_gate, skaterift.cam.transform, 
-                   skaterift.cam.transform );
-      }
-      else{
-         m3x3_mul( localplayer.basis, skaterift.cam.transform, 
-                   skaterift.cam.transform );
-      }
-   }
-#endif
-   
    camera_update_view( &skaterift.cam );
    camera_update_projection( &skaterift.cam );
    camera_finalize( &skaterift.cam );
@@ -577,11 +571,7 @@ static void render_main_game(void){
    skaterift_composite_maincamera();
 
    /* --------------------------------------------------------------------- */
-
-   world_instance *view_world = localplayer.viewable_world;
-   if( (view_world != NULL) && (skaterift.activity != k_skaterift_respawning) ){
-      render_world_cubemaps( view_world );
-   }
+   render_world_cubemaps( world_current_instance() );
 
    /* variable res target */
    render_fb_bind( gpipeline.fb_main, 1 );
@@ -600,7 +590,10 @@ static void render_main_game(void){
                                    portals */
 
    /* continue with variable rate */
-   render_scene_gate_subview();
+   if( !global_miniworld.transition ){
+      render_fb_bind( gpipeline.fb_main, 1 );
+      render_world_gates( world_current_instance(), &skaterift.cam );
+   }
 
    /* composite */
    present_view_with_post_processing();
index d8f15ed80a4635819e39e60b26ecfb29e96500df..c074e156f3e090fee656d7b9d5774a01565d0ad7 100644 (file)
@@ -857,7 +857,7 @@ static void workshop_render_world_preview(void){
    glEnable( GL_DEPTH_TEST );
    glDisable( GL_BLEND );
 
-   render_world( localplayer.viewable_world, &skaterift.cam, 1 );
+   render_world( world_current_instance(), &skaterift.cam, 0, 0, 1, 1 );
 
    glBindFramebuffer( GL_FRAMEBUFFER, 0 );
    glViewport( 0,0, vg.window_x, vg.window_y );
@@ -910,9 +910,8 @@ static void workshop_render_player_preview(void){
    camera_update_projection( &cam );
    camera_finalize( &cam );
 
-   world_instance *world = localplayer.viewable_world;
-   render_playermodel( &cam, world, 0, &workshop_form.player_model, sk,
-                        localplayer.final_mtx );
+   render_playermodel( &cam, world_current_instance(), 0, 
+                       &workshop_form.player_model, sk, localplayer.final_mtx );
 
    glBindFramebuffer( GL_FRAMEBUFFER, 0 );
    glViewport( 0,0, vg.window_x, vg.window_y );
@@ -1001,7 +1000,7 @@ static void workshop_render_board_preview(void){
    glBufferSubData( GL_UNIFORM_BUFFER, 0, 
                     sizeof(struct ub_world_lighting), &world->ub_lighting );
 
-   render_world( world, &cam, 1 );
+   render_world( world, &cam, 0, 0, 1, 1 );
    struct player_board_pose pose = {0};
    render_board( &cam, world, board, mmdl,  &pose, k_board_shader_entity );
    render_board( &cam, world, board, mmdl1, &pose, k_board_shader_entity );
diff --git a/world.c b/world.c
index ad0372389a54eaff63cdbdb0011098a1877c2915..4f8cda2f165221c7e18ff4d70ed9fe0a0d1d6f1b 100644 (file)
--- a/world.c
+++ b/world.c
@@ -44,29 +44,9 @@ static void world_switch_instance( u32 index ){
    world_instance *current = 
       &world_static.instances[ world_static.active_instance ];
 
-   if( index != world_static.active_instance ){
+   if( index != world_static.active_instance )
       v3_copy( localplayer.rb.co, current->player_co );
-      v3_copy( localplayer.angles, current->player_angles );
-      v3_copy( localplayer.cam.pos, current->cam_co );
-      current->player_angles[3] = player_get_heading_yaw();
-   }
-
    v3_copy( new->player_co, localplayer.rb.co );
-   v3_copy( new->player_angles, localplayer.angles );
-   v3_copy( new->cam_co, localplayer.cam.pos );
-   q_axis_angle( localplayer.rb.q, (v3f){0,1,0}, new->player_angles[3] );
-
-   /* run exit events on triggers */
-   for( u32 i=0; i<world_static.active_trigger_volume_count; i++ ){
-      i32 idx = world_static.active_trigger_volumes[i];
-      ent_volume *volume = mdl_arritm( &current->ent_volume, idx );
-
-      ent_call basecall;
-      basecall.function = k_ent_function_trigger_leave;
-      basecall.id = mdl_entity_id( k_ent_volume, idx );
-      basecall.data = NULL;
-      entity_call( current, &basecall );
-   }
 
    world_static.active_instance = index;
 
diff --git a/world.h b/world.h
index 0efe185087d5b5087098117ad86397a5a2eeb6e3..0a67abf855df6d9216424243f9730770e945acda 100644 (file)
--- a/world.h
+++ b/world.h
@@ -63,8 +63,7 @@ struct world_instance {
     * -------------------------------------------------------
     */
 
-   v4f player_co, player_angles;
-   v3f cam_co;
+   v4f player_co;
 
    void *heap;
    enum world_status{
index a12e071ade86fdf4a749ea840e1f61edcc434ed7..d34ed6e0932f88d0d70a70bddf6f6ce8afd21dc0 100644 (file)
@@ -605,6 +605,7 @@ static void world_entity_start( world_instance *world, vg_msg *sav ){
    }
 }
 
+#if 0
 /* 
  * used for relinking multi-world data. ran anytime the world setup changes
  */
@@ -634,6 +635,7 @@ static void world_entity_relink( world_instance *world ){
       }
    }
 }
+#endif
 
 static void world_entity_serialize( world_instance *world, vg_msg *sav ){
    for( u32 i=0; i<mdl_arrcount(&world->ent_challenge); i++ ){
index fc66d7469badf7578f991b8c5b0b3b4f92ce8adf..1e5e70c684d55e4ace42df0749ce31d008a602fb 100644 (file)
@@ -13,7 +13,6 @@ static ent_spawn *world_find_spawn_by_name( world_instance *world,
 static ent_spawn *world_find_closest_spawn( world_instance *world, 
                                                v3f position );
 static void world_entity_start( world_instance *world, vg_msg *sav );
-static void world_entity_relink( world_instance *world );
 static void world_entity_serialize( world_instance *world, vg_msg *sav );
 
 static void ent_volume_call( world_instance *world, ent_call *call );
index 96317c1b4da3b458a8fbb449c0caddf3f1823c0e..bc21e95bc13dea6cd4a1645201ba7ffd0b859167 100644 (file)
@@ -86,8 +86,7 @@ static void ent_gate_get_mdl_mtx( ent_gate *gate, m4x3f mmdl ){
  * Render the view through a gate
  */
 static int render_gate( world_instance *world, world_instance *world_inside,
-                           ent_gate *gate, camera *cam, int layer_depth )
-{
+                           ent_gate *gate, camera *cam ){
    v3f viewdir, gatedir;
    m3x3_mulv( cam->transform, (v3f){0.0f,0.0f,-1.0f}, viewdir );
    q_mulv( gate->q[0], (v3f){0.0f,0.0f,-1.0f}, gatedir );
@@ -145,63 +144,42 @@ static int render_gate( world_instance *world, world_instance *world_inside,
    camera_finalize( &world_gates.cam );
 
    vg_line_point( world_gates.cam.transform[3], 0.3f, 0xff00ff00 );
-   {
-      shader_model_gate_use();
-      shader_model_gate_uPv( cam->mtx.pv );
-      shader_model_gate_uCam( cam->pos );
-      shader_model_gate_uColour( (v4f){0.0f,1.0f,0.0f,0.0f} );
-      shader_model_gate_uTime( vg.time*0.25f );
-      shader_model_gate_uInvRes( (v2f){
-            1.0f / (float)vg.window_x,
-            1.0f / (float)vg.window_y });
-
-      glEnable( GL_STENCIL_TEST );
-      glStencilOp( GL_KEEP, GL_KEEP, GL_REPLACE );  
-      glStencilFunc( GL_ALWAYS, 1, 0xFF ); 
-      glStencilMask( 0xFF );
-      glDisable( GL_CULL_FACE );
-
-      m4x3f mmdl;
-      ent_gate_get_mdl_mtx( gate, mmdl );
-      shader_model_gate_uMdl( mmdl );
-      
-      if( gate->flags & k_ent_gate_custom_mesh ){
-         mesh_bind( &world->mesh_no_collide );
-         for( u32 i=0; i<gate->submesh_count; i++ ){
-            mdl_submesh *sm = mdl_arritm( &world->meta.submeshs, 
-                                          gate->submesh_start+i );
-            mdl_draw_submesh( sm );
-         }
-      }
-      else {
-         mesh_bind( &world_gates.mesh );
-         mdl_draw_submesh( &world_gates.sm_surface );
-      }
 
-      glClear( GL_DEPTH_BUFFER_BIT );
-      glStencilFunc( GL_EQUAL, 1, 0xFF );
-      glStencilMask( 0x00 ); 
-      glEnable( GL_CULL_FACE );
+   shader_model_gate_use();
+   shader_model_gate_uPv( cam->mtx.pv );
+   shader_model_gate_uCam( cam->pos );
+   shader_model_gate_uColour( (v4f){0.0f,1.0f,0.0f,0.0f} );
+   shader_model_gate_uTime( vg.time*0.25f );
+   shader_model_gate_uInvRes( (v2f){
+         1.0f / (float)vg.window_x,
+         1.0f / (float)vg.window_y });
+
+   glEnable( GL_STENCIL_TEST );
+   glStencilOp( GL_KEEP, GL_KEEP, GL_REPLACE );  
+   glStencilFunc( GL_ALWAYS, 1, 0xFF ); 
+   glStencilMask( 0xFF );
+   glDisable( GL_CULL_FACE );
+
+   m4x3f mmdl;
+   ent_gate_get_mdl_mtx( gate, mmdl );
+   shader_model_gate_uMdl( mmdl );
+   
+   if( gate->flags & k_ent_gate_custom_mesh ){
+      mesh_bind( &world->mesh_no_collide );
+      for( u32 i=0; i<gate->submesh_count; i++ ){
+         mdl_submesh *sm = mdl_arritm( &world->meta.submeshs, 
+                                       gate->submesh_start+i );
+         mdl_draw_submesh( sm );
+      }
    }
-
-   render_world( world_inside, &world_gates.cam, layer_depth );
-   render_remote_players( world_inside, &world_gates.cam );
-
-   {
-      glDisable( GL_STENCIL_TEST );
-
-      render_water_texture( world_inside, &world_gates.cam, layer_depth );
-      render_fb_bind( gpipeline.fb_main, 1 );
-
-      glEnable( GL_STENCIL_TEST );
-
-      render_water_surface( world_inside, &world_gates.cam );
-
-      glStencilMask( 0xFF );
-      glStencilFunc( GL_ALWAYS, 1, 0xFF );
-      glDisable( GL_STENCIL_TEST );
+   else {
+      mesh_bind( &world_gates.mesh );
+      mdl_draw_submesh( &world_gates.sm_surface );
    }
 
+   render_world( world_inside, &world_gates.cam, 
+                 1, !localplayer.gate_waiting, 1, 1 );
+
    return 1;
 }
 
index 201187cfbc9ee32944bde7ba1c27fa674d0a2f3a..a8decacf6dafebe29906103cc7e568d9222c6d60 100644 (file)
@@ -21,7 +21,7 @@ static world_gates;
 static void world_gates_init(void);
 static void gate_transform_update( ent_gate *gate );
 static int render_gate( world_instance *world, world_instance *world_inside,
-                           ent_gate *gate, camera *cam, int layer_depth );
+                           ent_gate *gate, camera *cam );
 
 static int gate_intersect( ent_gate *gate, v3f pos, v3f last );
 static u32 world_intersect_gates( world_instance *world, v3f pos, v3f last );
index 6378e9bd5cac18487da984d3c3b97a1d408fb00c..50a882c2fab5dc1f8907a87c051d189eb55fed62 100644 (file)
@@ -107,7 +107,6 @@ static void world_instance_load_mdl( u32 instance_id, const char *path ){
 
    /* init player position.
     *   - this is overriden by the save state when(if) it loads */
-   v3_zero( world->player_angles );
    ent_spawn *rp = world_find_spawn_by_name( world, "start" );
    if( !rp ) rp = world_find_closest_spawn( world, (v3f){0.0f,0.0f,0.0f} );
 
@@ -147,13 +146,6 @@ static void skaterift_world_load_done( void *payload, u32 size ){
    world_entity_start( world, &sav );
    world->status = k_world_status_loaded;
    world_static.load_state = k_world_loader_none;
-
-   for( int i=0; i<k_world_max; i ++ ){
-      world_instance *wi = &world_static.instances[i];
-
-      if( wi->status == k_world_status_loaded )
-         world_entity_relink( wi );
-   }
 }
 
 struct world_load_args {
@@ -313,8 +305,6 @@ static void skaterift_change_world_start( addon_reg *reg ){
          }
       }
 
-      world_entity_relink( &world_static.instances[k_world_purpose_hub] );
-
       world_static.instance_addons[ k_world_purpose_client ] = reg;
       network_send_item( k_netmsg_playeritem_world1 );
       relink_all_remote_player_worlds();
index 1d2256b4f6ddf88d7cefc696b68ece318e23e585..cdbe37ebfbbfe022ed2f8eeaff1d9f8cfd5c4dd4 100644 (file)
@@ -10,6 +10,8 @@
 #include "font.h"
 #include "gui.h"
 #include "respawn.h"
+#include "ent_miniworld.h"
+#include "player_remote.h"
 
 static int ccmd_set_time( int argc, const char *argv[] ){
    world_instance *world = world_current_instance();
@@ -364,11 +366,11 @@ static void render_world_standard( world_instance *world, camera *cam ){
 }
 
 static void render_world_cubemapped( world_instance *world, camera *cam,
-                                        int layer_depth ){
+                                     int enabled ){
    if( !mdl_arrcount( &world->ent_cubemap ) )
       return;
 
-   if( layer_depth == -1 ){
+   if( !enabled ){
       world_shader_standard_bind( world, cam );
 
       struct world_pass pass = {
@@ -448,7 +450,7 @@ static void render_world_alphatest( world_instance *world, camera *cam ){
 
 static
 void world_render_challenges( world_instance *world, struct world_pass *pass,
-                              v3f pos, int layer_depth ){
+                              v3f pos ){
    if( !world ) return;
    if( skaterift.activity == k_skaterift_replay ) return;
    if( world != world_current_instance() ) return;
@@ -608,8 +610,7 @@ void world_render_challenges( world_instance *world, struct world_pass *pass,
    }
 }
 
-static void render_world_fxglow( world_instance *world, camera *cam,
-                                    int layer_depth ){
+static void render_world_fxglow( world_instance *world, camera *cam ){
    shader_scene_fxglow_use();
    shader_scene_fxglow_uUvOffset( (v2f){ 0.0f, 0.0f } );
    shader_scene_fxglow_uTexMain(1);
@@ -635,7 +636,7 @@ static void render_world_fxglow( world_instance *world, camera *cam,
    };
 
    world_render_both_stages( world, &pass );
-   world_render_challenges( world, &pass, cam->pos, layer_depth );
+   world_render_challenges( world, &pass, cam->pos );
 
    glEnable(GL_CULL_FACE);
 }
@@ -696,13 +697,18 @@ static void render_sky( world_instance *world, camera *cam ){
 
    m4x4_copy( cam->mtx.v, v );
    m4x4_copy( cam->mtx_prev.v, v_prev );
+
+   for( int i=0; i<3; i++ ){
+      v3_normalize(v[i]);
+      v3_normalize(v_prev[i]);
+   }
    v3_zero( v[3] );
    v3_zero( v_prev[3] );
 
    m4x4_copy( cam->mtx.p,      pv );
    m4x4_copy( cam->mtx_prev.p, pv_prev );
-   m4x4_reset_clipping( pv,      cam->farz, cam->nearz );
-   m4x4_reset_clipping( pv_prev, cam->farz, cam->nearz );
+   m4x4_reset_clipping( pv,      100.0f, 0.1f );
+   m4x4_reset_clipping( pv_prev, 100.0f, 0.1f );
 
    m4x4_mul( pv,      v,      pv );
    m4x4_mul( pv_prev, v_prev, pv_prev );
@@ -750,9 +756,7 @@ static void render_sky( world_instance *world, camera *cam ){
    glDepthMask( GL_TRUE );
 }
 
-static void render_world_gates( world_instance *world, camera *cam,
-                                   int layer_depth )
-{
+static void render_world_gates( world_instance *world, camera *cam ){
    float closest = INFINITY;
    struct ent_gate *gate = NULL;
 
@@ -775,7 +779,7 @@ static void render_world_gates( world_instance *world, camera *cam,
    
    world->rendering_gate = gate;
    if( gate )
-      render_gate( world, world, gate, cam, layer_depth );
+      render_gate( world, world, gate, cam );
 }
 
 static void world_prerender( world_instance *world ){
@@ -826,20 +830,32 @@ static void world_prerender( world_instance *world ){
 }
 
 static void render_world( world_instance *world, camera *cam,
-                             int layer_depth )
-{
+                          int stenciled, int viewing_from_gate, 
+                          int with_water, int with_cubemaps ){
+   if( stenciled ){
+      glClear( GL_DEPTH_BUFFER_BIT );
+      glStencilFunc( GL_EQUAL, 1, 0xFF );
+      glStencilMask( 0x00 ); 
+      glEnable( GL_CULL_FACE );
+      glEnable( GL_STENCIL_TEST );
+   }
+   else {
+      glStencilMask( 0xFF );
+      glStencilFunc( GL_ALWAYS, 1, 0xFF );
+      glDisable( GL_STENCIL_TEST );
+   }
+
    render_sky( world, cam );
 
-   render_world_routes( world, cam, layer_depth );
+   render_world_routes( world, cam, viewing_from_gate );
    render_world_standard( world, cam );
-   render_world_cubemapped( world, cam, layer_depth );
+   render_world_cubemapped( world, cam, with_cubemaps );
 
    render_world_vb( world, cam );
    render_world_alphatest( world, cam );
    render_terrain( world, cam );
 
-   if( layer_depth == -1 ) return;
-   if( layer_depth == 0 ){
+   if( !viewing_from_gate ){
       world_entity_focus_render();
 
       /* Render SFD's */
@@ -862,30 +878,57 @@ static void render_world( world_instance *world, camera *cam,
       }
    }
 
-   f32 greyout = 0.0f;
-   if( mdl_entity_id_type(world_static.focused_entity) == k_ent_challenge )
-      greyout = world_static.focus_strength;
-
-   if( greyout > 0.0f ){
-      glDrawBuffers( 1, (GLenum[]){ GL_COLOR_ATTACHMENT0 } );
-      glEnable(GL_BLEND);
-      glDisable(GL_DEPTH_TEST);
-      glDepthMask(GL_FALSE);
-      glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
-      glBlendEquation(GL_FUNC_ADD);
-
-      shader_blitcolour_use();
-      shader_blitcolour_uColour( (v4f){ 0.5f, 0.5f, 0.5f, greyout*0.56f } );
-      render_fsquad();
-      
-      glDisable(GL_BLEND);
-      glEnable(GL_DEPTH_TEST);
-      glDepthMask(GL_TRUE);
-      glDrawBuffers( 2, (GLenum[]){ GL_COLOR_ATTACHMENT0, 
-                                    GL_COLOR_ATTACHMENT1 } );
+   if( !viewing_from_gate ){
+      f32 greyout = 0.0f;
+      if( mdl_entity_id_type(world_static.focused_entity) == k_ent_challenge )
+         greyout = world_static.focus_strength;
+
+      if( greyout > 0.0f ){
+         glDrawBuffers( 1, (GLenum[]){ GL_COLOR_ATTACHMENT0 } );
+         glEnable(GL_BLEND);
+         glDisable(GL_DEPTH_TEST);
+         glDepthMask(GL_FALSE);
+         glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+         glBlendEquation(GL_FUNC_ADD);
+
+         shader_blitcolour_use();
+         shader_blitcolour_uColour( (v4f){ 0.5f, 0.5f, 0.5f, greyout*0.56f } );
+         render_fsquad();
+         
+         glDisable(GL_BLEND);
+         glEnable(GL_DEPTH_TEST);
+         glDepthMask(GL_TRUE);
+         glDrawBuffers( 2, (GLenum[]){ GL_COLOR_ATTACHMENT0, 
+                                       GL_COLOR_ATTACHMENT1 } );
+      }
+
+      render_world_fxglow( world, cam );
    }
+   
+   if( with_water ){
+      render_water_texture( world, cam );
+      render_fb_bind( gpipeline.fb_main, 1 );
+   }
+
+   if( stenciled ){
+      glStencilFunc( GL_EQUAL, 1, 0xFF );
+      glStencilMask( 0x00 ); 
+      glEnable( GL_CULL_FACE );
+      glEnable( GL_STENCIL_TEST );
+   }
+
+   if( with_water ){
+      render_water_surface( world, cam );
+   }
+
+   render_remote_players( world, cam );
+   ent_miniworld_render( world, cam );
 
-   render_world_fxglow( world, cam, layer_depth );
+   if( stenciled ){
+      glStencilMask( 0xFF );
+      glStencilFunc( GL_ALWAYS, 1, 0xFF );
+      glDisable( GL_STENCIL_TEST );
+   }
 }
 
 
@@ -917,9 +960,10 @@ static void render_world_override_pass( world_instance *world,
 
 static void render_world_override( world_instance *world,
                                    world_instance *lighting_source,
-                                   m4x3f mmdl ){
+                                   m4x3f mmdl,
+                                   camera *cam ){
    struct world_pass pass = {
-      .cam = &skaterift.cam,
+      .cam = cam,
       .fn_bind_textures = bindpoint_override,
       .fn_set_mdl = shader_scene_override_uMdl,
       .fn_set_uPvmPrev = shader_scene_override_uPvmPrev,
@@ -942,7 +986,7 @@ static void render_world_override( world_instance *world,
 
    m4x4f mpvm_prev;
    m4x3_expand( mmdl, mpvm_prev );
-   m4x4_mul( skaterift.cam.mtx_prev.pv, mpvm_prev, mpvm_prev );
+   m4x4_mul( cam->mtx_prev.pv, mpvm_prev, mpvm_prev );
 
    m3x3f mnormal;
    m3x3_inv( mmdl, mnormal );
@@ -972,7 +1016,6 @@ static void render_world_override( world_instance *world,
    shader_scene_override_uSpawnPos( uSpawnPos );
 
 
-
    glDisable( GL_CULL_FACE );
    mesh_bind( &world->mesh_geo );
    pass.geo_type = k_world_geo_type_solid;
@@ -1026,7 +1069,7 @@ static void render_cubemap_side( world_instance *world, ent_cubemap *cm,
    camera_finalize( &cam );
    camera_finalize( &cam );
 
-   render_world( world, &cam, -1 );
+   render_world( world, &cam, 0, 1, 1, 0 );
 }
 
 static void render_world_cubemaps( world_instance *world ){
index d7ea51976729012e95dc76dd01e61ab67e108deb..383706853a4aeb1325f32555da58d47069e0d27c 100644 (file)
@@ -75,13 +75,15 @@ static void world_bind_light_index( world_instance *world,
                                        int slot );
 static void render_world_position( world_instance *world, camera *cam );
 static void render_world_depth( world_instance *world, camera *cam );
-static void render_world( world_instance *world, camera *cam, 
-                             int layer_depth );
+static void render_world( world_instance *world, camera *cam,
+                          int stenciled, int viewing_from_gate, 
+                          int with_water, int with_cubemaps );
 static void render_world_cubemaps( world_instance *world );
 static void bind_terrain_noise(void);
 static void render_world_override( world_instance *world,
                                    world_instance *lighting_source,
-                                   m4x3f mmdl );
+                                   m4x3f mmdl,
+                                   camera *cam );
 
 #define WORLD_BIND_LIGHT_BUFFERS_UB0_TEX234( WORLD, SHADER )            \
    world_link_lighting_ub( WORLD, _shader_##SHADER.id );                \
index 9dc678ebd918065786d0e960db03a2cdb9b8a2ec..e4b444a2a63f5e872ae0a9341fa78456b6ecf37a 100644 (file)
@@ -865,7 +865,7 @@ static void render_gate_markers( int run_id, ent_gate *gate ){
 }
 
 static void render_world_routes( world_instance *world, camera *cam, 
-                                    int layer_depth ){
+                                 int viewing_from_gate ){
    m4x3f identity_matrix;
    m4x3_identity( identity_matrix );
 
@@ -900,7 +900,7 @@ static void render_world_routes( world_instance *world, camera *cam,
 
    /* timers
     * ---------------------------------------------------- */
-   if( layer_depth == 0 ){
+   if( !viewing_from_gate ){
       font3d_bind( &gui.font, k_font_shader_default, 0, world, cam );
 
       for( u32 i=0; i<world_render.timer_text_count; i++ ){
@@ -987,7 +987,7 @@ static void render_world_routes( world_instance *world, camera *cam,
 
             shader_model_gate_uColour( colour );
 
-            u32 next = route->active_checkpoint+1+layer_depth;
+            u32 next = route->active_checkpoint+1+viewing_from_gate;
                 next = next % route->checkpoints_count;
                 next += route->checkpoints_start;
 
index 980ae0204ffcc99f1f50a716fad85b4caf682e24..085e25250ac8217ea746c97bdf918c67105f79f6 100644 (file)
@@ -43,8 +43,7 @@ static void world_bind_light_index( world_instance *world,
 /*
  * Does not write motion vectors
  */
-static void render_water_texture( world_instance *world, camera *cam,
-                                     int layer_depth ){
+static void render_water_texture( world_instance *world, camera *cam ){
    if( !world->water.enabled || (vg.quality_profile == k_quality_profile_low) )
       return;
 
@@ -88,7 +87,7 @@ static void render_water_texture( world_instance *world, camera *cam,
    glEnable( GL_DEPTH_TEST );
    glDisable( GL_BLEND );
    glCullFace( GL_FRONT );
-   render_world( world, &water_cam, layer_depth );
+   render_world( world, &water_cam, 0, 1, 0, 1 );
    glCullFace( GL_BACK );
    
    /*
index 6681460bc306c37bd6500190670c42795eb6b8d0..b45ee3a260ab351b783544234a386026e7ccc899 100644 (file)
@@ -14,8 +14,7 @@ static world_water;
 static void world_water_init(void);
 
 static void water_set_surface( world_instance *world, float height );
-static void render_water_texture( world_instance *world, camera *cam,
-                                     int layer_depth );
+static void render_water_texture( world_instance *world, camera *cam );
 static void render_water_surface( world_instance *world, camera *cam );
 
 #endif /* WATER_H */