small compression
[carveJwlIkooP6JGAAIwe30JlM.git] / skaterift.c
index 388e37ebeac21af80f77375cad69cecfb0cc9b85..34e42f39cd5ed8ee533490a37aa8971d6ab77419 100644 (file)
 #include "respawn.c"
 #include "network.c"
 #include "player_remote.c"
+#include "vg/vg_audio_dsp.h"
 
 static struct player_avatar localplayer_avatar;
 
 int main( int argc, char *argv[] ){
-#if 0
-   u8 buf[ 512 ];
-   bitpack_ctx ctx = {
-      .buffer = buf,
-      .buffer_len = 512,
-      .bytes = 0,
-      .mode = k_bitpack_compress
-   };
-
-   v4f q = {  0.388, -0.565, 0.515, 0.515 };
-   vg_info( "q: %f %f %f %f\n", q[0], q[1], q[2], q[3] );
-
-   /* compress */
-   bitpack_qquat( &ctx, q );
-
-   vg_info( "compressed bytes: %u\n", ctx.bytes );
-
-   /* decompress */
-   ctx.bytes = 0;
-   ctx.mode = k_bitpack_decompress;
-
-   bitpack_qquat( &ctx, q );
-   vg_info( "q: %f %f %f %f\n", q[0], q[1], q[2], q[3] );
-
-   return 0;
-#endif
-
    vg_mem.use_libc_malloc = 0;
    vg_set_mem_quota( 160*1024*1024 );
    vg_enter( argc, argv, "Voyager Game Engine" ); 
@@ -93,9 +67,15 @@ int main( int argc, char *argv[] ){
 }
 
 static void vg_launch_opt(void){
+   const char *arg;
    if( vg_long_opt( "noauth" ) ){
       network_client.auth_mode = eServerModeNoAuthentication;
    }
+
+   if( (arg = vg_long_opt_arg( "server" )) ){
+      vg_strncpy( arg, network_client.server_adress, 64, 
+                  k_strncpy_overflow_fatal );
+   }
 }
 
 static void vg_preload(void){
@@ -136,27 +116,25 @@ static void skaterift_restore_state(void){
    strcpy( sav.path, str_skaterift_main_save );
    savedata_file_read( &sav );
 
-   vg_msg kvsav = {0};
-   kvsav.buf = sav.buf;
-   kvsav.len = sav.len;
-   kvsav.max = sizeof(sav.buf);
+   vg_msg kvsav;
+   vg_msg_init( &kvsav, sav.buf, sizeof(sav.buf) );
 
    u32 board_reg_id = 0,
        player_reg_id = 0;
 
-   vg_msg player = kvsav;
-   if( vg_msg_seekframe( &player, "player", 0 ) ){
+   vg_msg_cursor orig = kvsav.cur;
+
+   if( vg_msg_seekframe( &kvsav, "player" ) ){
       addon_alias q;
 
       /* board */
-      skaterift_read_addon_alias( &player, "board", k_addon_type_board, &q );
+      skaterift_read_addon_alias( &kvsav, "board", k_addon_type_board, &q );
       u32 reg_id = addon_match( &q );
       if( reg_id != 0xffffffff ) 
          board_reg_id = reg_id;
 
-
       /* playermodel */
-      skaterift_read_addon_alias( &player, "playermodel", 
+      skaterift_read_addon_alias( &kvsav, "playermodel", 
                                   k_addon_type_player, &q );
       reg_id = addon_match( &q );
       if( reg_id != 0xffffffff ) 
@@ -168,12 +146,12 @@ static void skaterift_restore_state(void){
    localplayer.playermodel_view_slot = 
       addon_cache_create_viewer( k_addon_type_player, player_reg_id );
 
-   vg_msg world = kvsav;
-   if( vg_msg_seekframe( &world, "world", 0 ) ){
+   kvsav.cur = orig;
+   if( vg_msg_seekframe( &kvsav, "world" ) ){
       addon_alias q;
 
       /* world */
-      skaterift_read_addon_alias( &world, "alias", k_addon_type_world, &q );
+      skaterift_read_addon_alias( &kvsav, "alias", k_addon_type_world, &q );
       u32 reg_id = addon_match( &q );
       if( reg_id != 0xffffffff ){
          addon_reg *reg = get_addon_from_index( k_addon_type_world, reg_id );
@@ -185,14 +163,13 @@ static void skaterift_restore_state(void){
          };
          skaterift_world_load_thread( &args );
 
-         world_set_active_instance( vg_msg_seekkvu32( &world, "index", 0 ) );
+         world_set_active_instance( vg_msg_getkvu32( &kvsav, "index", 0 ) );
          world_static.active_trigger_volume_count = 0;
          localplayer.viewable_world = world_current_instance();
       }
 
-      vg_msg_cmd position = vg_msg_seekkv( &world, "position", 0 );
       v3f pos;
-      vg_msg_convert_num( &position, k_vg_msg_float|k_vg_msg_32b, 3, pos );
+      vg_msg_getkvv3f( &kvsav, "position", pos, (v3f){0.0f,0.0f,0.0f} );
 
       if( v3_length2(pos) > 1.0f )
          player__setpos( pos );
@@ -255,14 +232,13 @@ static void vg_load(void){
                                                 k_addon_type_world, 
                                                 ".mdl" );
    {
-      vg_msg msg = {0};
-      msg.buf = spawn->metadata;
-      msg.max = sizeof(spawn->metadata);
+      vg_msg msg;
+      vg_msg_init( &msg, spawn->metadata, sizeof(spawn->metadata) );
       vg_msg_frame( &msg, "workshop" );
       vg_msg_wkvstr( &msg, "title", "Understate DIY" );
       vg_msg_end_frame( &msg );
       vg_msg_wkvstr( &msg, "location", "USA" );
-      spawn->metadata_len = msg.cur;
+      spawn->metadata_len = msg.cur.co;
    }
 
    /* mtzero island */
@@ -270,14 +246,13 @@ static void vg_load(void){
                                                 k_addon_type_world,
                                                 ".mdl" );
    {
-      vg_msg msg = {0};
-      msg.buf = mtzero->metadata;
-      msg.max = sizeof(mtzero->metadata);
+      vg_msg msg;
+      vg_msg_init( &msg, spawn->metadata, sizeof(mtzero->metadata) );
       vg_msg_frame( &msg, "workshop" );
       vg_msg_wkvstr( &msg, "title", "Mt.Zero Island" );
       vg_msg_end_frame( &msg );
       vg_msg_wkvstr( &msg, "location", "Australia" );
-      mtzero->metadata_len = msg.cur;
+      mtzero->metadata_len = msg.cur.co;
    }
 
    /* load home/permanent world manually */
@@ -513,6 +488,7 @@ static void render_scene(void){
                                     GL_COLOR_ATTACHMENT1 } );
       view_world = &world_static.instances[respawn_chooser.world_id];
       render_world_override( view_world );
+      render_world_routes( view_world, &skaterift.cam, 1 );
    }
    else{
       render_world( view_world, &skaterift.cam, 0 );
@@ -585,7 +561,7 @@ static void render_main_game(void){
    /* --------------------------------------------------------------------- */
 
    world_instance *view_world = localplayer.viewable_world;
-   if( view_world != NULL ){
+   if( (view_world != NULL) && (skaterift.activity != k_skaterift_respawning) ){
       render_world_cubemaps( view_world );
 
       ent_gate *gate = view_world->rendering_gate;