Conversion to new updated stack allocators master
authorhgn <hgodden00@gmail.com>
Sat, 28 Jun 2025 01:34:25 +0000 (02:34 +0100)
committerhgn <hgodden00@gmail.com>
Sat, 28 Jun 2025 01:34:25 +0000 (02:34 +0100)
48 files changed:
src/addon.c
src/addon.h
src/addon_types.c
src/array_file.c
src/array_file.h
src/board_maker.c
src/board_maker.h
src/build_control_overlay.c
src/compass.c
src/control_overlay.c
src/ent_npc.c
src/ent_script.c
src/ent_script.h
src/font.h
src/gameserver.c
src/gameserver.h
src/gui.h
src/metascene.c
src/metascene.h
src/model.c
src/model.h
src/network_requests.c
src/particle.c
src/player.c
src/player_glide.c
src/player_render.c
src/render.c
src/replay2.c
src/scripts/city.c [deleted file]
src/scripts/hub.c [deleted file]
src/scripts/l1_speed.c
src/scripts/mtzero.c [deleted file]
src/scripts/tutorial_island.c
src/scripts/valley.c [deleted file]
src/skaterift.c
src/skeleton.h
src/trail.c
src/workshop.c
src/workshop.h
src/world.c
src/world.h
src/world_entity.c
src/world_gate.c
src/world_gen.c
src/world_load.c
src/world_map.c
src/world_render.c
src/world_sfd.c

index 2f6173df35af974edcfd4f592c133fb3f75c3b6b..2763abb65728b237341ad11cc0820a61847d1c6e 100644 (file)
@@ -310,7 +310,7 @@ void addon_system_init( void )
    THREAD_1;
 
    u32 reg_size = sizeof(addon_reg)*ADDON_MOUNTED_MAX;
-   _addon.registry = vg_linear_alloc( vg_mem.rtmemory, reg_size );
+   _addon.registry = vg_stack_allocate( &vg.rtmem, reg_size, 8, "Addon Registry" );
 
    for( u32 type=0; type<k_addon_type_max; type++ )
    {
@@ -321,7 +321,7 @@ void addon_system_init( void )
       {
          /* create the allocations pool */
          u32 alloc_size = sizeof(struct addon_cache_entry)*inf->cache_count;
-         cache->allocs = vg_linear_alloc( vg_mem.rtmemory, alloc_size );
+         cache->allocs = vg_stack_allocate( &vg.rtmem, alloc_size, 8, "Cache entries" );
          memset( cache->allocs, 0, alloc_size );
 
          cache->pool.buffer = cache->allocs;
@@ -332,26 +332,19 @@ void addon_system_init( void )
 
          /* create the real memory */
          u32 cache_size = inf->cache_stride*inf->cache_count;
-         cache->items = vg_linear_alloc( vg_mem.rtmemory, cache_size );
+         cache->items = vg_stack_allocate( &vg.rtmem, cache_size, 8, "Cache data" );
          cache->stride = inf->cache_stride;
          memset( cache->items, 0, cache_size );
 
-         if( inf->item_arena_size )
-         {
-            u32 index_size = inf->cache_count * sizeof( void* );
-            cache->arenas = vg_linear_alloc( vg_mem.rtmemory, index_size );
-         }
-
          for( i32 j=0; j<inf->cache_count; j++ )
          {
             struct addon_cache_entry *alloc = &cache->allocs[j];
             alloc->addon_id = 0;
 
             if( inf->item_arena_size )
-            {
-               cache->arenas[j] = _vg_create_linear_allocator( vg_mem.rtmemory, inf->item_arena_size, VG_MEMORY_SYSTEM,
-                                                               "Item cache's arena" );
-            }
+               alloc->item_arena = vg_stack_make_substack( &vg.rtmem, inf->item_arena_size, "Addon item arena" );
+            else
+               alloc->item_arena = NULL;
          }
       }
    }
@@ -798,13 +791,6 @@ bool addon_get_content_folder( addon_id addon_id, vg_str *folder )
    }
 }
 
-void *addon_cache_item_arena( enum addon_type type, addon_cache_id id )
-{
-   VG_ASSERT( id );
-   struct addon_cache *cache = &_addon.cache[type];
-   return cache->arenas[ id-1 ];
-}
-
 struct cache_complete_info
 {
    enum addon_type type;
@@ -866,21 +852,18 @@ static void cache_load_task( vg_async_task *task )
       goto e0;
    }
    
+   vg_stack_allocator *arena = cache_entry->item_arena;
    if( info->type == k_addon_type_board )
    {
       struct player_board *board = addon_cache_item_data( info->type, info->cache_id, 0 );
-      void *arena = addon_cache_item_arena( info->type, info->cache_id );
-      vg_linear_clear( arena );
-
+      vg_stack_clear( arena );
       player_board_load( board, content_path.buffer, arena );
       result_state = k_addon_cache_state_loaded;
    }
    else if( info->type == k_addon_type_player )
    {
       struct player_model *model = addon_cache_item_data( info->type, info->cache_id, 0 );
-      void *arena = addon_cache_item_arena( info->type, info->cache_id );
-      vg_linear_clear( arena );
-
+      vg_stack_clear( arena );
       player_model_load( model, content_path.buffer, arena );
       result_state = k_addon_cache_state_loaded;
    }
index 555d8c2d93f2887f92f66fe0c527685ea34afdda..5a3d6b99795f7397a48e03398fa1c4688a10209b 100644 (file)
@@ -52,12 +52,12 @@ struct _addon
          state;
 
          char local_cpart[ ADDON_CPART_MAX ];
+         vg_stack_allocator *item_arena;
       }
       *allocs;
       vg_pool pool;
 
-      void **arenas;
-      void *items;  /* the real data */
+      void *items;  /* Small header struct */
       size_t stride;
    }
    cache[k_addon_type_max];
index aebb9968eda765038058973d78a7da7ee7bfa663..32186ade53175ef2953d1f3282f05aafa3cbf602 100644 (file)
@@ -8,13 +8,13 @@ struct addon_type_info addon_type_infos[] =
       .local_content_folder = "boards/",
       .cache_stride = sizeof(struct player_board),
       .cache_count  = 20,
-      .item_arena_size = 1024 * 2
+      .item_arena_size = VG_KB(2)
    },
    [k_addon_type_player] = {
       .local_content_folder = "playermodels/",
       .cache_stride = sizeof(struct player_model),
       .cache_count  = 20,
-      .item_arena_size = 1024 * 20
+      .item_arena_size = VG_KB(20)
    },
    [k_addon_type_world] = {
       .local_content_folder = "maps/"
index c786d5a7f6dde4900fdfc80f266f0d074a0e5a11..30b1754104e1882b8affde0e943f982effd30759 100644 (file)
@@ -64,13 +64,12 @@ static void af_load_array_file_buffer( array_file_context *ctx, array_file_meta
 }
 
 void af_load_array_file( array_file_context *ctx, array_file_ptr *out_ptr, 
-                         array_file_meta *arr, void *lin_alloc, u32 stride )
+                         array_file_meta *arr, vg_stack_allocator *stack, u32 stride )
 {
    if( arr->item_count )
    {
       u32 size = stride*arr->item_count;
-      out_ptr->data = lin_alloc? vg_linear_alloc( lin_alloc, vg_align8(size) ):
-                                 malloc( size );
+      out_ptr->data = stack? vg_stack_allocate( stack, size, 8, NULL ): malloc( size );
       af_load_array_file_buffer( ctx, arr, out_ptr->data, stride );
    }
    else
@@ -108,14 +107,13 @@ array_file_meta *af_find_array( array_file_context *ctx, const char *name )
    return NULL;
 }
 
-int af_load_array( array_file_context *ctx, array_file_ptr *ptr,
-                   const char *name, void *lin_alloc, u32 stride )
+int af_load_array( array_file_context *ctx, array_file_ptr *ptr, const char *name, vg_stack_allocator *stack, u32 stride )
 {
    array_file_meta *arr = af_find_array( ctx, name );
 
    if( arr )
    {
-      af_load_array_file( ctx, ptr, arr, lin_alloc, stride );
+      af_load_array_file( ctx, ptr, arr, stack, stride );
       return 1;
    }
    else
@@ -127,8 +125,7 @@ int af_load_array( array_file_context *ctx, array_file_ptr *ptr,
    }
 }
 
-void af_open( array_file_context *ctx, const char *path, 
-              u32 min_version, u32 max_version, void *lin_alloc )
+void af_open( array_file_context *ctx, const char *path, u32 min_version, u32 max_version, vg_stack_allocator *stack )
 {
    ctx->fp = fopen( path, "rb" );
    if( !ctx->fp )
@@ -156,11 +153,10 @@ void af_open( array_file_context *ctx, const char *path,
       vg_fatal_exit();
    }
 
-   af_load_array_file( ctx, &ctx->index, &ctx->header.index, lin_alloc,
-                       sizeof(array_file_meta) );
+   af_load_array_file( ctx, &ctx->index, &ctx->header.index, stack, sizeof(array_file_meta) );
 
    array_file_ptr strings;
-   af_load_array( ctx, &strings, "strings", lin_alloc, 1 );
+   af_load_array( ctx, &strings, "strings", stack, 1 );
    ctx->strings = strings.data;
 }
 
@@ -216,13 +212,13 @@ static bool af_next( struct af_compiler_iter *iter )
 
 af_compiler_item *af_compiler_allocate_items( af_compiler *compiler, af_compiler_index *index, u32 count )
 {
-   af_compiler_item *entry = vg_linear_alloc( compiler->allocator, sizeof(af_compiler_item) );
+   af_compiler_item *entry = VG_STACK_ALLOCATE_STRUCT( compiler->stack, af_compiler_item );
    entry->next = NULL;
 
    u32 data_size = count * index->element_size;
    index->element_count += count;
 
-   entry->data = vg_linear_alloc( compiler->allocator, data_size );
+   entry->data = vg_stack_allocate( compiler->stack, data_size, 8, NULL );
    entry->count = count;
 
    for( u32 i=0; i<data_size; i ++ )
@@ -270,9 +266,9 @@ u32 af_compile_string( af_compiler *compiler, const char *string )
    return offset;
 }
 
-void af_compiler_init( af_compiler *compiler, void *allocator )
+void af_compiler_init( af_compiler *compiler, vg_stack_allocator *stack )
 {
-   compiler->allocator = allocator;
+   compiler->stack = stack;
    af_compiler_init_index( &compiler->index, "index", sizeof(af_compiler_index) );
    compiler->strings_index = af_compiler_create_index( compiler, "strings", 1 );
    af_compile_string( compiler, "nul" );
index 973a282f33fcfcef49263f10dee1b99dc79f9706..f67337fe856d736849490745d1f9895670ca6c92 100644 (file)
@@ -1,5 +1,5 @@
 #pragma once
-//#include "vg/submodules/hashmap.c/hashmap.h"
+#include "vg_mem.h"
 
 typedef struct array_file_ptr array_file_ptr;
 typedef struct array_file_meta array_file_meta;
@@ -34,19 +34,17 @@ struct array_file_context
    const void *strings;
 };
 
-void af_open( array_file_context *ctx, const char *path, u32 min_version, u32 max_version, void *lin_alloc );
+void af_open( array_file_context *ctx, const char *path, u32 min_version, u32 max_version, vg_stack_allocator *stack );
 void af_close( array_file_context *ctx );
 
 /* array loading */
 array_file_meta *af_find_array( array_file_context *ctx, const char *name );
 void af_load_array_file( array_file_context *ctx, array_file_ptr *out_ptr, 
-                         array_file_meta *arr, void *lin_alloc, 
-                         u32 stride );
-int af_load_array( array_file_context *ctx, array_file_ptr *ptr,
-                   const char *name, void *lin_alloc, u32 stride );
+                         array_file_meta *arr, vg_stack_allocator *stack, u32 stride );
+int af_load_array( array_file_context *ctx, array_file_ptr *ptr, const char *name, vg_stack_allocator *stack, u32 stride );
 
-#define AF_LOAD_ARRAY_STRUCT( CTX, PTR, STRUCT, ALLOCATOR ) \
-   af_load_array( CTX, PTR, #STRUCT, ALLOCATOR, sizeof(STRUCT) )
+#define AF_LOAD_ARRAY_STRUCT( CTX, PTR, STRUCT, STACK ) \
+   af_load_array( CTX, PTR, #STRUCT, STACK, sizeof(STRUCT) )
 
 /* array access */
 void *af_arritm( array_file_ptr *arr, u32 index );
@@ -85,7 +83,7 @@ struct af_compiler_index
 
 struct af_compiler
 {
-   void *allocator;
+   vg_stack_allocator *stack;
 
    af_compiler_index index,
                      *strings_index;
@@ -96,7 +94,7 @@ struct af_compiler
    u32 file_offset;
 };
 
-void af_compiler_init( af_compiler *compiler, void *allocator );
+void af_compiler_init( af_compiler *compiler, vg_stack_allocator *stack );
 af_compiler_item *af_compiler_allocate_items( af_compiler *compiler, af_compiler_index *index, u32 count );
 af_compiler_index *af_compiler_create_index( af_compiler *compiler, const char *alias, u32 element_size );
 bool af_write( af_compiler *compiler, const char *path, u32 version );
index dc869a612e48c88150229897f503189731549540..e53e803007350cc460160e5c9cc6560313044e38 100644 (file)
@@ -112,15 +112,15 @@ const char *_board_maker_template_paths[] =
 static void _board_maker_load_template( void *_ )
 {
    THREAD_1;
-   vg_linear_clear( _board_maker.template_heap );
+   vg_stack_free( &_board_maker.template_stack );
 
    mdl_context *mdl = &_board_maker.template_mdl;
-   mdl_open( mdl, _board_maker_template_paths[_board_maker.template_selection], _board_maker.template_heap );
-   mdl_load_metadata_block( mdl, _board_maker.template_heap );
+   mdl_open( mdl, _board_maker_template_paths[_board_maker.template_selection], &_board_maker.template_stack );
+   mdl_load_metadata_block( mdl, &_board_maker.template_stack );
 
    /* we need this for compiling it back down */
-   mdl_load_mesh_block( mdl, _board_maker.template_heap );
-   AF_LOAD_ARRAY_STRUCT( &mdl->af, &_board_maker.template_mdl_markers, ent_marker, _board_maker.template_heap );
+   mdl_load_mesh_block( mdl, &_board_maker.template_stack );
+   AF_LOAD_ARRAY_STRUCT( &mdl->af, &_board_maker.template_mdl_markers, ent_marker, &_board_maker.template_stack );
 
    mdl_async_full_load_std( mdl, NULL );
    mdl_close( mdl );
@@ -923,8 +923,6 @@ void _board_maker_open(void)
       return;
 
    VG_ASSERT( _board_maker.state == k_board_maker_state_not_ready );
-   VG_ASSERT( _board_maker.static_heap == NULL );
-   VG_ASSERT( _board_maker.template_heap == NULL );
 
    q_identity( _board_maker.q );
    v3_zero( _board_maker.w );
@@ -932,8 +930,8 @@ void _board_maker_open(void)
    _board_maker.template_loaded = -1;
    _board_maker.template_selection = 0;
 
-   _board_maker.static_heap = _vg_create_linear_allocator( NULL, 8*1024*1024, VG_MEMORY_SYSTEM, "Board maker static" );
-   _board_maker.template_heap = _vg_create_linear_allocator( NULL, 16*1024*1024, VG_MEMORY_SYSTEM, "Board maker dynamic" );
+   vg_stack_init( &_board_maker.static_stack, NULL, VG_MB(8), "Board Maker: Static Stack" );
+   vg_stack_init( &_board_maker.template_stack, NULL, VG_MB(16), "Board Maker: Template Stack" );
 
    for( u32 i=0; i<k_workshop_shader_part_max; i ++ )
    {
@@ -970,11 +968,8 @@ void _board_maker_close(void)
    mdl_sync_std_unload( &_board_maker.template_mdl );
    _board_maker.template_loaded = -1;
 
-   vg_allocator_free( _board_maker.static_heap );
-   vg_allocator_free( _board_maker.template_heap );
-
-   _board_maker.static_heap = NULL;
-   _board_maker.template_heap = NULL;
+   vg_stack_free( &_board_maker.static_stack );
+   vg_stack_free( &_board_maker.template_stack );
    _board_maker.state = k_board_maker_state_not_ready;
 
    localplayer.immobile = 0;
index 8bc485a315dc3c0c835376741f27c6b6128cf4d1..7f12d2e97b2cd447d4967d518b98409b9e26b1d7 100644 (file)
@@ -42,8 +42,7 @@ struct _board_maker
    }
    state;
 
-   void *static_heap;
-   void *template_heap;
+   vg_stack_allocator static_stack, template_stack;
 
    enum board_maker_compositor_state
    {
index 86669cbd8a98d7a2b1e4a007e5af0316beb986e3..46dd837af8fb681c11f05df37f6b15942e0ba2be 100644 (file)
@@ -5,17 +5,21 @@
 void build_control_overlay(void)
 {
    FILE *hdr = fopen( "src/control_overlay.h.generated", "w" );
+
+   vg_stack_allocator stack;
+   vg_stack_init( &stack, NULL, VG_MB(8), "Model buffer" );
+
    mdl_context ctx;
-   mdl_open( &ctx, "content_skaterift/models/rs_overlay.mdl", NULL );
-   mdl_load_metadata_block( &ctx, NULL );
+   mdl_open( &ctx, "content_skaterift/models/rs_overlay.mdl", &stack );
+   mdl_load_metadata_block( &ctx, &stack );
    mdl_close( &ctx );
 
    for( u32 i=0; i<ctx.mesh_count; i ++ )
    {
       mdl_mesh *mesh = &ctx.meshes[ i ];
-      fprintf( hdr, "   %s = %u,\n", 
-                  af_str( &ctx.af, mesh->pstr_name ), mesh->submesh_start );
+      fprintf( hdr, "   %s = %u,\n", af_str( &ctx.af, mesh->pstr_name ), mesh->submesh_start );
    }
 
+   vg_stack_free( &stack );
    fclose( hdr );
 }
index 7dd9fd3787bffa47ce166dd24c7369be7b57827b..240b12f5bf6fcc7a9472291317ee84d16be3db8a 100644 (file)
@@ -7,10 +7,9 @@ struct _compass _compass = { .alpha = 1 };
 void compass_init(void)
 {
    mdl_context *mdl = &_compass.mdl;
-   void *allocator = vg_mem.rtmemory;
 
-   mdl_open( mdl, "models/rs_compass.mdl", allocator );
-   mdl_load_metadata_block( mdl, allocator );
+   mdl_open( mdl, "models/rs_compass.mdl", &vg.rtmem );
+   mdl_load_metadata_block( mdl, &vg.rtmem );
    mdl_async_full_load_std( mdl, NULL );
    _compass.sm_comp = mdl_get_submesh_index( mdl, "comp" );
    _compass.sm_comp_bar = mdl_get_submesh_index( mdl, "comp_bar" );
index 3132fb34c378e02f5c96d4c88f72cf84a4f63854..a9aaa9683ce4ce6b679971fadb4a4ae7c37a7838 100644 (file)
@@ -33,11 +33,10 @@ static void control_overlay_init_finish( void *userdata )
 
 void control_overlay_init(void)
 {
-   void *alloc = vg_mem.rtmemory;
    mdl_context *mdl = &control_overlay.mdl;
 
-   mdl_open( mdl, "models/rs_overlay.mdl", alloc );
-   mdl_load_metadata_block( mdl, alloc );
+   mdl_open( mdl, "models/rs_overlay.mdl", &vg.rtmem );
+   mdl_load_metadata_block( mdl, &vg.rtmem );
    mdl_async_full_load_std( mdl, NULL );
    mdl_close( mdl );
    vg_async_call( &vg.main_tasks, control_overlay_init_finish, NULL );
index 973468d308919b48b131ea9025a9a5c03d0a2b38..5f264033b2fd83c533c206160fde9a6b7661b1ff 100644 (file)
@@ -225,10 +225,9 @@ void _ent_npc_init(void)
       }
    }
 
-   void *alloc = vg_mem.rtmemory;
    mdl_context *mdl = &_npc.gino.mdl;
-   mdl_open( mdl, "models/gino.mdl", alloc );
-   mdl_load_metadata_block( mdl, alloc );
+   mdl_open( mdl, "models/gino.mdl", &vg.rtmem );
+   mdl_load_metadata_block( mdl, &vg.rtmem );
    mdl_async_full_load_std( mdl, NULL );
    _npc.gino.sm_main = mdl_get_submesh_index( mdl, "gino" );
    _npc.gino.sm_hat = mdl_get_submesh_index( mdl, "gino.hat" );
@@ -240,7 +239,7 @@ void _ent_npc_init(void)
    for( u32 i=0; i<4; i ++ )
    {
       struct human_npc *human = &_npc.humans[i];
-      human->final_mtx = vg_linear_alloc( alloc, mtx_size );
+      human->final_mtx = vg_stack_allocate( &vg.rtmem, mtx_size, 8, "Final MTX" );
    }
    player_get_anim( &_npc.anim_idle, "idle_lean+y" );
    player_get_anim( &_npc.anim_stand, "idle_cycle+y" );
index 3ccd61e5cae9343041282956cf583328dfe80c83..a35b8fc89a87a8bcfb691657c843ef27bf604ec9 100644 (file)
@@ -32,12 +32,12 @@ static void ent_script_event_init( ent_script_event *event, world_instance *worl
    event->script_alias = _ent_script_table[ script->script_id ].alias;
 }
 
-void ent_script_alloc( world_instance *world, void *heap )
+void ent_script_alloc( world_instance *world, vg_stack_allocator *stack )
 {
-   _ent_script.userdata_array = vg_linear_alloc( heap, af_arrcount( &world->ent_script ) * sizeof(void*) );
+   _ent_script.userdata_array = vg_stack_allocate( stack, af_arrcount( &world->ent_script ) * sizeof(void*), 8, NULL );
 
    struct script_event_allocate info;
-   info.heap = heap;
+   info.heap = stack;
 
    struct ent_script_event event;
    event.type = k_escript_event_allocate;
index 4cb63ef3a87250cbea67731e00b6b0039fd55f54..a29b2fe2418bb8701b81fbce14d98bc4d4d1278f 100644 (file)
@@ -2,7 +2,7 @@
 
 struct script_event_allocate
 {
-   void *heap;
+   vg_stack_allocator *heap;
    void *userdata;
 };
 
@@ -55,5 +55,5 @@ extern _ent_script_table[];
 void ent_script_propogate_event( world_instance *world, struct ent_script_event *event );
 void ent_script_start( world_instance *world );
 void ent_script_update( world_instance *world );
-void ent_script_alloc( world_instance *world, void *heap );
+void ent_script_alloc( world_instance *world, vg_stack_allocator *stack );
 entity_event_result _ent_script_world_event( ent_event *event );
index 43e8537035366c816e5c7cfdc1d8cde84ba98ddf..c5504c7863f4c3eb8e5502e20349d1be55f608f7 100644 (file)
@@ -87,28 +87,24 @@ static void font3d_load( font3d *font, const char *mdl_path, void *alloc )
    mdl_open( mdl, mdl_path, alloc );
    mdl_load_metadata_block( mdl, alloc );
 
-   vg_linear_clear( vg_mem.scratch );
+   vg_stack_clear( &vg.scratch );
    array_file_ptr fonts;
-   AF_LOAD_ARRAY_STRUCT( &mdl->af, &fonts, ent_font, vg_mem.scratch );
+   AF_LOAD_ARRAY_STRUCT( &mdl->af, &fonts, ent_font, &vg.scratch );
    font->info = *((ent_font *)af_arritm(&fonts,0));
 
-   AF_LOAD_ARRAY_STRUCT( &mdl->af, &font->font_variants, 
-                                    ent_font_variant, alloc );
+   AF_LOAD_ARRAY_STRUCT( &mdl->af, &font->font_variants, ent_font_variant, alloc );
    AF_LOAD_ARRAY_STRUCT( &mdl->af, &font->glyphs, ent_glyph, alloc );
-
-   vg_linear_clear( vg_mem.scratch );
+   vg_stack_clear( &vg.scratch );
 
    if( !font->mdl.texture_count )
       vg_fatal_error( "No texture in font file" );
 
    mdl_texture *tex0 = &mdl->textures[ 0 ];
-   void *data = vg_linear_alloc( vg_mem.scratch, tex0->file.pack_size );
+   void *data = vg_stack_allocate( &vg.scratch, tex0->file.pack_size, 8, "Pack data" );
    mdl_fread_pack_file( mdl, &tex0->file, data );
 
    mdl_async_load_glmesh( mdl, &font->mesh, NULL );
-   vg_tex2d_load_qoi_async( data, tex0->file.pack_size, 
-                            VG_TEX2D_LINEAR|VG_TEX2D_CLAMP,
-                            &font->texture );
+   vg_tex2d_load_qoi_async( data, tex0->file.pack_size, VG_TEX2D_LINEAR|VG_TEX2D_CLAMP, &font->texture );
 
    mdl_close( mdl );
 }
@@ -142,9 +138,8 @@ static gui_font3d;
 /*
  * world can be null if not using world shader 
  */
-static void font3d_bind( font3d *font, enum font_shader shader, 
-                         int depth_compare, world_instance *world,
-                         vg_camera *cam ){
+static void font3d_bind( font3d *font, enum font_shader shader, int depth_compare, world_instance *world,vg_camera *cam )
+{
    gui_font3d.shader = shader;
    gui_font3d.font = font;
    glActiveTexture( GL_TEXTURE1 );
@@ -157,7 +152,8 @@ static void font3d_bind( font3d *font, enum font_shader shader,
       shader_model_font_uTexMain( 1 );
       shader_model_font_uDepthMode( depth_compare );
 
-      if( depth_compare ){
+      if( depth_compare )
+      {
          depth_compare_bind( 
             shader_model_font_uTexSceneDepth,
             shader_model_font_uInverseRatioDepth,
index 407601f22fce36ffe09333f93a8339f9de725d5e..1d3d946bdd48dcbab3b0efe1fe122d31f9ad4718 100644 (file)
@@ -983,8 +983,6 @@ int main( int argc, const char *argv[] )
    if( !vg_init_async_queue( &_gameserver.tasks ) )
       goto E0;
    
-   vg_set_mem_quota( 40*1024*1024 ); // unused??
-   vg_alloc_quota();
    if( !db_init() )
       goto E0;
 
index 123d2c99783badb645b04a7b39823a12a76b4fd8..d60486ec867ba205f5eae40a7704dd4d3aed75da 100644 (file)
@@ -5,7 +5,7 @@
 #include "vg/vg_steam.h"
 #include "vg/vg_steam_networking.h"
 #include "vg/vg_steam_http.h"
-#include "vg/vg_steam_auth.h"
+#include "vg/vg_steam_auth_server.h"
 #include "vg/vg_async2.h"
 #include "network_msg.h"
 #include "network_common.h"
index e36204d4052db15d1238c0fb02053942017b40c0..7ff3678a3dcedf46bed085592b4bb1632fd9a9a2 100644 (file)
--- a/src/gui.h
+++ b/src/gui.h
@@ -349,15 +349,13 @@ static void gui_icon_setcolour( v4f colour ){
 
 static void gui_init(void)
 {
-   font3d_load( &gui.font, "models/rs_font.mdl", vg_mem.rtmemory );
+   font3d_load( &gui.font, "models/rs_font.mdl", &vg.rtmem );
    vg_console_reg_cmd( "gui_location", gui_location_print_ccmd, NULL );
 
    /* load icons */
-   void *alloc = vg_mem.rtmemory;
-
    mdl_context *mdl = &gui.model_icons;
-   mdl_open( mdl, "models/rs_icons.mdl", alloc );
-   mdl_load_metadata_block( mdl, alloc );
+   mdl_open( mdl, "models/rs_icons.mdl", &vg.rtmem );
+   mdl_load_metadata_block( mdl, &vg.rtmem );
 
    gui.icon_submeshes[ k_gui_icon_tick1 ] = mdl_get_submesh_index( mdl, "icon_tick1" );
    gui.icon_submeshes[ k_gui_icon_tick2 ] = mdl_get_submesh_index( mdl, "icon_tick2" );
@@ -380,11 +378,11 @@ static void gui_init(void)
    gui.icon_submeshes[ k_gui_icon_story2d ]= mdl_get_submesh_index( mdl,"icon_story2d");
    gui.icon_submeshes[ k_gui_icon_story_done2d ]= mdl_get_submesh_index( mdl,"icon_story_done2d");
 
-   vg_linear_clear( vg_mem.scratch );
+   vg_stack_clear( &vg.scratch );
    if( !gui.model_icons.texture_count )
       vg_fatal_error( "No texture in menu file" );
    mdl_texture *tex0 = &gui.model_icons.textures[ 0 ];
-   void *data = vg_linear_alloc( vg_mem.scratch, tex0->file.pack_size );
+   void *data = vg_stack_allocate( &vg.scratch, tex0->file.pack_size, 8, "Pack data" );
    mdl_fread_pack_file( &gui.model_icons, &tex0->file, data );
    vg_tex2d_load_qoi_async( data, tex0->file.pack_size, VG_TEX2D_LINEAR|VG_TEX2D_CLAMP, &gui.icons_texture );
    mdl_async_load_glmesh( &gui.model_icons, &gui.icons_mesh, NULL );
index 0059a562ad8bdb42a6a910a04fc3502814ba109d..2d956ad058224a0ed96a51b4d7e2e8967e8ec29c 100644 (file)
@@ -146,14 +146,14 @@ static void cutscene_load_thread( vg_async_task *task )
    struct cutscene_load_info *info = (void *)task->data;
    vg_info( "Loading cutscene: %s\n", info->path );
 
-   u32 size = 20*1024*1024;
-   _cutscene.arena = _vg_create_linear_allocator( NULL, size, VG_MEMORY_SYSTEM, "Cutscene" );
-   metascene_load( &_cutscene.meta, info->path, _cutscene.arena );
+   _cutscene.stack = vg_stack_make_substack( &vg.rtmem, VG_MB(20), "Cutscene Stack" );
+   metascene_load( &_cutscene.meta, info->path, _cutscene.stack );
 
    _cutscene.instance_count = af_arrcount( &_cutscene.meta.instances );
-   _cutscene.instances = vg_linear_alloc( _cutscene.arena, sizeof(struct cs_instance) * _cutscene.instance_count );
+   _cutscene.instances = vg_stack_allocate( _cutscene.stack, sizeof(struct cs_instance) * _cutscene.instance_count, 
+                                             8, "Instances" );
 
-   _cutscene.refs = NULL;
+   _cutscene.refs = vg_stack_allocate( _cutscene.stack, 0, 8, "References" );
    _cutscene.unique_refs = 0;
    for( u32 i=0; i < _cutscene.instance_count; i ++ )
    {
@@ -178,7 +178,7 @@ static void cutscene_load_thread( vg_async_task *task )
 
       if( !ref )
       {
-         _cutscene.refs = vg_linear_extend( _cutscene.arena, _cutscene.refs, sizeof( struct model_ref ) );
+         vg_stack_extend_last( _cutscene.stack, sizeof(struct model_ref) );
          ref_id = _cutscene.unique_refs;
          ref = &_cutscene.refs[ ref_id ];
          ref->name = name;
@@ -205,21 +205,22 @@ static void cutscene_load_thread( vg_async_task *task )
       vg_strcat( &mdl_path, ".mdl" );
 
       vg_info( "Loading instance model: %s\n", mdl_path.buffer );
-      mdl_open( &ref->mdl, mdl_path.buffer, _cutscene.arena );
-      mdl_load_metadata_block( &ref->mdl, _cutscene.arena );
+      mdl_open( &ref->mdl, mdl_path.buffer, _cutscene.stack );
+      mdl_load_metadata_block( &ref->mdl, _cutscene.stack );
       mdl_async_full_load_std( &ref->mdl, NULL );
       mdl_close( &ref->mdl );
 
       u32 skeleton_count = ref->mdl.armature_count;
       if( skeleton_count )
       {
-         ref->skeletons = vg_linear_alloc( _cutscene.arena, sizeof(struct cs_skeleton) * skeleton_count );
+         ref->skeletons = vg_stack_allocate( _cutscene.stack, sizeof(struct cs_skeleton) * skeleton_count,
+                                             8, "Skeletons" );
 
          ref->total_skinning_bones = 0;
          for( u32 j=0; j<skeleton_count; j ++ )
          {
             struct cs_skeleton *skele = &ref->skeletons[ j ];
-            skeleton_setup( &skele->sk, &ref->mdl, j, _cutscene.arena );
+            skeleton_setup( &skele->sk, &ref->mdl, j, _cutscene.stack );
             skele->skinning_offset = ref->total_skinning_bones;
             ref->total_skinning_bones += skele->sk.bone_count;
          }
@@ -237,7 +238,8 @@ static void cutscene_load_thread( vg_async_task *task )
       struct cs_instance *ins = &_cutscene.instances[ i ];
       struct model_ref *ref = &_cutscene.refs[ ins->ref_id ];
 
-      ins->skinning_data = vg_linear_alloc( _cutscene.arena, sizeof(m4x3f) * ref->total_skinning_bones );
+      ins->skinning_data = vg_stack_allocate( _cutscene.stack, sizeof(m4x3f) * ref->total_skinning_bones,
+                                              8, "Skinning Data" );
       for( u32 j=0; j<ref->total_skinning_bones; j ++ )
          m4x3_identity( ins->skinning_data[ j ] );
 
@@ -280,7 +282,7 @@ static void cutscene_load_thread( vg_async_task *task )
             clip->_.clip.size = 0;
          }
 
-         audio_clip_load( &clip->_.clip, _cutscene.arena );
+         audio_clip_load( &clip->_.clip, _cutscene.stack );
       }
    }
 
@@ -468,6 +470,7 @@ void cutscene_update( f32 delta )
 {
    if( _cutscene.state == k_cutscene_state_unloading )
    {
+      // NOTE: This somestimes still fails!
       if( !vg_audio_flagged_stopped( AUDIO_FLAG_CUTSCENE ) )
       {
          static u32 ticker = 0;
@@ -480,8 +483,7 @@ void cutscene_update( f32 delta )
          return;
       }
 
-      vg_allocator_free( _cutscene.arena );
-      _cutscene.arena = NULL;
+      vg_stack_free( _cutscene.stack );
       _cutscene.state = k_cutscene_state_none;
       _cutscene.marker_this_frame = NULL;
       _cutscene.subtitle = NULL;
index 1f6a7971a367cb39e2f3b977844979760e725311..a26fe30773a32220d39b1a95e2704b0b41fa37b3 100644 (file)
@@ -132,7 +132,7 @@ struct cs_subtitle
 struct _cutscene
 {
    ms_context meta;
-   void *arena;
+   vg_stack_allocator *stack;
 
    enum cutscene_state
    {
index 7e1e489d289a1cb7229899a77960bd88cc3117f6..2425b302525d8f23305af2854b3da265711a3c70 100644 (file)
@@ -43,55 +43,55 @@ void mdl_fread_pack_file( mdl_context *mdl, mdl_file *info, void *dst )
    }
 }
 
-void mdl_load_mesh_block( mdl_context *mdl, void *lin_alloc )
+void mdl_load_mesh_block( mdl_context *mdl, vg_stack_allocator *stack )
 {
    struct array_file_ptr ptr;
-   AF_LOAD_ARRAY_STRUCT( &mdl->af, &ptr, mdl_vert,   lin_alloc );
+   AF_LOAD_ARRAY_STRUCT( &mdl->af, &ptr, mdl_vert, stack );
    mdl->verts = ptr.data;
    mdl->vert_count = ptr.count;
 
-   AF_LOAD_ARRAY_STRUCT( &mdl->af, &ptr, mdl_indice, lin_alloc );
+   AF_LOAD_ARRAY_STRUCT( &mdl->af, &ptr, mdl_indice, stack );
    mdl->indices = ptr.data;
    mdl->indice_count = ptr.count;
 }
 
-void mdl_load_metadata_block( mdl_context *mdl, void *lin_alloc )
+void mdl_load_metadata_block( mdl_context *mdl, vg_stack_allocator *stack )
 {
    struct array_file_ptr ptr;
-   AF_LOAD_ARRAY_STRUCT( &mdl->af, &ptr, mdl_mesh,     lin_alloc );
+   AF_LOAD_ARRAY_STRUCT( &mdl->af, &ptr, mdl_mesh, stack );
    mdl->meshes = ptr.data;
    mdl->mesh_count = ptr.count;
 
-   AF_LOAD_ARRAY_STRUCT( &mdl->af, &ptr, mdl_submesh,  lin_alloc );
+   AF_LOAD_ARRAY_STRUCT( &mdl->af, &ptr, mdl_submesh, stack );
    mdl->submeshes = ptr.data;
    mdl->submesh_count = ptr.count;
 
-   AF_LOAD_ARRAY_STRUCT( &mdl->af, &ptr, mdl_texture,  lin_alloc );
+   AF_LOAD_ARRAY_STRUCT( &mdl->af, &ptr, mdl_texture, stack );
    mdl->textures = ptr.data;
    mdl->texture_count = ptr.count;
 
-   AF_LOAD_ARRAY_STRUCT( &mdl->af, &ptr, mdl_armature, lin_alloc );
+   AF_LOAD_ARRAY_STRUCT( &mdl->af, &ptr, mdl_armature, stack );
    mdl->armatures = ptr.data;
    mdl->armature_count = ptr.count;
 
-   AF_LOAD_ARRAY_STRUCT( &mdl->af, &ptr, mdl_bone,     lin_alloc );
+   AF_LOAD_ARRAY_STRUCT( &mdl->af, &ptr, mdl_bone, stack );
    mdl->bones = ptr.data;
    mdl->bone_count = ptr.count;
 
-   mdl_load_materials( mdl, lin_alloc );
+   mdl_load_materials( mdl, stack );
 }
 
-void *mdl_shader_standard( vg_msg *msg, void *alloc )
+static void *mdl_shader_standard( vg_msg *msg, vg_stack_allocator *stack )
 {
-   struct shader_props_standard *props = vg_linear_alloc( alloc, sizeof(struct shader_props_standard) );
+   struct shader_props_standard *props = VG_STACK_ALLOCATE_STRUCT( stack, struct shader_props_standard );
    vg_msg_getkvintg( msg, "tex_diffuse", k_vg_msg_u32, &props->tex_diffuse, NULL );
    vg_msg_getkvintg( msg, "render_flags", k_vg_msg_u32, &props->render_flags, NULL );
    return props;
 }
 
-void *mdl_shader_terrain( vg_msg *msg, void *alloc )
+static void *mdl_shader_terrain( vg_msg *msg, vg_stack_allocator *stack )
 {
-   struct shader_props_terrain *props = vg_linear_alloc( alloc, sizeof(struct shader_props_terrain) );
+   struct shader_props_terrain *props = VG_STACK_ALLOCATE_STRUCT( stack, struct shader_props_terrain );
    vg_msg_getkvintg( msg, "tex_diffuse", k_vg_msg_u32, &props->tex_diffuse, NULL );
    vg_msg_getkvvecf( msg, "sand_colour", k_vg_msg_v4f, props->sand_colour, (v4f){ 0.79, 0.63, 0.48, 1.0 } );
    vg_msg_getkvvecf( msg, "blend_offset", k_vg_msg_v2f, props->blend_offset, (v2f){ 0.5, 0.0 } );
@@ -99,17 +99,17 @@ void *mdl_shader_terrain( vg_msg *msg, void *alloc )
    return props;
 }
 
-void *mdl_shader_vertex_blend( vg_msg *msg, void *alloc )
+static void *mdl_shader_vertex_blend( vg_msg *msg, vg_stack_allocator *stack )
 {
-   struct shader_props_vertex_blend *props = vg_linear_alloc( alloc, sizeof(struct shader_props_vertex_blend) );
+   struct shader_props_vertex_blend *props = VG_STACK_ALLOCATE_STRUCT( stack, struct shader_props_vertex_blend );
    vg_msg_getkvintg( msg, "tex_diffuse", k_vg_msg_u32, &props->tex_diffuse, NULL );
    vg_msg_getkvvecf( msg, "blend_offset", k_vg_msg_v2f, props->blend_offset, (v2f){ 0.5, 0.0 } );
    return props;
 }
 
-void *mdl_shader_water( vg_msg *msg, void *alloc )
+static void *mdl_shader_water( vg_msg *msg, vg_stack_allocator *stack )
 {
-   struct shader_props_water *props = vg_linear_alloc( alloc, sizeof(struct shader_props_water) );
+   struct shader_props_water *props = VG_STACK_ALLOCATE_STRUCT( stack, struct shader_props_water );
    vg_msg_getkvvecf( msg, "shore_colour", k_vg_msg_v4f, props->shore_colour, (v4f){0.03,0.32,0.61,1.0} );
    vg_msg_getkvvecf( msg, "deep_colour", k_vg_msg_v4f, props->deep_colour, (v4f){0.0,0.006,0.03,1.0} );
    vg_msg_getkvintg( msg, "fog_scale", k_vg_msg_f32, &props->fog_scale, (f32[]){0.04} );
@@ -119,11 +119,9 @@ void *mdl_shader_water( vg_msg *msg, void *alloc )
    return props;
 }
 
-void *mdl_shader_cubemapped( vg_msg *msg, void *alloc )
+void *mdl_shader_cubemapped( vg_msg *msg, vg_stack_allocator *stack )
 {
-   struct shader_props_cubemapped *props = 
-      vg_linear_alloc( alloc, sizeof(struct shader_props_cubemapped) );
-
+   struct shader_props_cubemapped *props = VG_STACK_ALLOCATE_STRUCT( stack, struct shader_props_cubemapped );
    vg_msg_getkvintg( msg, "tex_diffuse", k_vg_msg_u32, &props->tex_diffuse, NULL );
    vg_msg_getkvintg( msg, "cubemap_entity", k_vg_msg_u32, &props->cubemap_entity, NULL );
    vg_msg_getkvvecf( msg, "tint", k_vg_msg_v4f, props->tint, (v4f){1.0,1.0,1.0,1.0} );
@@ -144,14 +142,11 @@ const char *_shader_prop_workshop_keys[] =
    [k_workshop_shader_part_deck    ] = "deck"
 };
 
-void *mdl_shader_workshop( vg_msg *msg, void *alloc )
+void *mdl_shader_workshop( vg_msg *msg, vg_stack_allocator *stack )
 {
-   struct shader_props_workshop *props = vg_linear_alloc( alloc, sizeof(struct shader_props_workshop) );
-
+   struct shader_props_workshop *props = VG_STACK_ALLOCATE_STRUCT( stack, struct shader_props_workshop );
    for( u32 i=0; i<k_workshop_shader_part_max; i ++ )
-   {
       vg_msg_getkvintg( msg, _shader_prop_workshop_keys[i], k_vg_msg_u32, &props->tex_all[i], NULL );
-   }
 
    return props;
 }
@@ -183,27 +178,21 @@ static bool mdl_legacy_v105_properties( struct mdl_material_v105 *mat, vg_msg *d
    return 1;
 }
 
-void mdl_load_materials( mdl_context *mdl, void *lin_alloc )
+void mdl_load_materials( mdl_context *mdl, vg_stack_allocator *stack )
 {
    array_file_ptr mats_ptr;
-   AF_LOAD_ARRAY_STRUCT( &mdl->af, &mats_ptr, mdl_material, lin_alloc );
+   AF_LOAD_ARRAY_STRUCT( &mdl->af, &mats_ptr, mdl_material, stack );
    mdl->materials = mats_ptr.data;
    mdl->material_count = mats_ptr.count;
 
 #if (MDL_VERSION_MIN <= 105)
-   /* load legacy material data into scratch */
    array_file_ptr legacy_materials;
    if( mdl->version <= 105 )
-   {
-      af_load_array( &mdl->af, &legacy_materials, "mdl_material", vg_mem.scratch, sizeof(struct mdl_material_v105) );
-   }
+      af_load_array( &mdl->af, &legacy_materials, "mdl_material", stack, sizeof(struct mdl_material_v105) );
 #endif
 
    array_file_ptr data;
-   af_load_array( &mdl->af, &data, "shader_data", vg_mem.scratch, 1 );
-
-   if( !lin_alloc )
-      return;
+   af_load_array( &mdl->af, &data, "shader_data", stack, 1 );
 
    for( u32 i=0; i<mdl->material_count; i ++ )
    {
@@ -229,27 +218,27 @@ void mdl_load_materials( mdl_context *mdl, void *lin_alloc )
           mat->shader == k_shader_foliage ||
           mat->shader == k_shader_fxglow )
       {
-         mat->props.compiled = mdl_shader_standard( &msg, lin_alloc );
+         mat->props.compiled = mdl_shader_standard( &msg, stack );
       }
       else if( mat->shader == k_shader_standard_vertex_blend )
       {
-         mat->props.compiled = mdl_shader_vertex_blend( &msg, lin_alloc );
+         mat->props.compiled = mdl_shader_vertex_blend( &msg, stack );
       }
       else if( mat->shader == k_shader_cubemap )
       {
-         mat->props.compiled = mdl_shader_cubemapped( &msg, lin_alloc );
+         mat->props.compiled = mdl_shader_cubemapped( &msg, stack );
       }
       else if( mat->shader == k_shader_terrain_blend )
       {
-         mat->props.compiled = mdl_shader_terrain( &msg, lin_alloc );
+         mat->props.compiled = mdl_shader_terrain( &msg, stack );
       }
       else if( mat->shader == k_shader_water )
       {
-         mat->props.compiled = mdl_shader_water( &msg, lin_alloc );
+         mat->props.compiled = mdl_shader_water( &msg, stack );
       }
       else if( mat->shader == k_shader_workshop )
       {
-         mat->props.compiled = mdl_shader_workshop( &msg, lin_alloc );
+         mat->props.compiled = mdl_shader_workshop( &msg, stack );
       }
       else
          mat->props.compiled = NULL;
@@ -259,10 +248,10 @@ void mdl_load_materials( mdl_context *mdl, void *lin_alloc )
 /*
  * if calling mdl_open, and the file does not exist, the game will fatal quit
  */
-void mdl_open( mdl_context *mdl, const char *path, void *lin_alloc )
+void mdl_open( mdl_context *mdl, const char *path, vg_stack_allocator *stack )
 {
    memset( mdl, 0, sizeof( mdl_context ) );
-   af_open( &mdl->af, path, MDL_VERSION_MIN, MDL_VERSION_NR, lin_alloc );
+   af_open( &mdl->af, path, MDL_VERSION_MIN, MDL_VERSION_NR, stack );
    mdl->version = mdl->af.header.version;
 
    array_file_meta *pack = af_find_array( &mdl->af, "pack" );
@@ -495,17 +484,15 @@ void mdl_async_load_glmesh( mdl_context *mdl, glmesh *mesh, u32 *fixup_table )
 void mdl_async_full_load_std( mdl_context *mdl, u32 *fixup_table )
 {
    THREAD_1;
-
    mdl_async_load_glmesh( mdl, &mdl->mesh, fixup_table );
    
    for( u32 i=0; i<mdl->texture_count; i ++ )
    {
-      vg_linear_clear( vg_mem.scratch );
+      vg_stack_clear( &vg.scratch );
       mdl_texture *tex = &mdl->textures[ i ];
 
-      void *data = vg_linear_alloc( vg_mem.scratch, tex->file.pack_size );
+      void *data = vg_stack_allocate( &vg.scratch, tex->file.pack_size, 8, "MDL Pack Data" );
       mdl_fread_pack_file( mdl, &tex->file, data );
-
       vg_tex2d_load_qoi_async( data, tex->file.pack_size, VG_TEX2D_CLAMP|VG_TEX2D_NEAREST, &tex->glname );
    }
 }
@@ -522,7 +509,8 @@ void mdl_sync_std_unload( mdl_context *mdl )
 
 void mdl_compiler_init( mdl_compiler *compiler )
 {
-   af_compiler_init( &compiler->af, _vg_create_linear_allocator( NULL, 10*1024*1024, VG_MEMORY_SYSTEM, "MDL Compile" ) );
+   vg_stack_init( &compiler->stack, NULL, VG_MB(10), "MDL Compiler" );
+   af_compiler_init( &compiler->af, &compiler->stack );
    compiler->meshes = af_compiler_create_index( &compiler->af, "mdl_mesh", sizeof(mdl_mesh) );
    compiler->submeshes = af_compiler_create_index( &compiler->af, "mdl_submesh", sizeof(mdl_submesh) );
    compiler->vertices = af_compiler_create_index( &compiler->af, "mdl_vert", sizeof(mdl_vert) );
@@ -647,5 +635,5 @@ void mdl_compiler_push_shaderdata( mdl_compiler *compiler, u32 shader_id, vg_msg
 
 void mdl_compiler_free( mdl_compiler *compiler )
 {
-   vg_allocator_free( compiler->af.allocator );
+   vg_stack_free( &compiler->stack );
 }
index 79a110bedc9d12ec4bbd7ce141bcf2fda39ab83c..f70740df5101e1327afc39d0dee223b4a5298d26 100644 (file)
@@ -290,16 +290,16 @@ void mesh_draw( glmesh *mesh );
 void mesh_free( glmesh *mesh );
 
 /* file context management */
-void mdl_open( mdl_context *mdl, const char *path, void *lin_alloc );
+void mdl_open( mdl_context *mdl, const char *path, vg_stack_allocator *stack );
 void mdl_close( mdl_context *mdl );
 
 /* pack access */
 void mdl_fread_pack_file( mdl_context *mdl, mdl_file *info, void *dst );
 
 /* standard array groups */
-void mdl_load_metadata_block( mdl_context *mdl, void *lin_alloc );
-void mdl_load_mesh_block( mdl_context *mdl, void *lin_alloc );
-void mdl_load_materials( mdl_context *mdl, void *lin_alloc );
+void mdl_load_metadata_block( mdl_context *mdl, vg_stack_allocator *stack );
+void mdl_load_mesh_block( mdl_context *mdl, vg_stack_allocator *stack );
+void mdl_load_materials( mdl_context *mdl, vg_stack_allocator *stack );
 
 /* load mesh */
 void mdl_async_load_glmesh( mdl_context *mdl, glmesh *mesh, u32 *fixup_table );
@@ -332,4 +332,6 @@ struct mdl_compiler
                      *armatures,
                      *textures,
                      *pack_data;
+
+   vg_stack_allocator stack;
 };
index d5447fc3b3a54d18205830a9af94dbb031976f24..29fd69dedac9d1c86bb3290b98f5aac3189b71c4 100644 (file)
@@ -301,10 +301,10 @@ void _net_handle_response_message( SteamNetworkingMessage_t *msg )
 void _net_requests_init(void)
 {
    u32 alloc_size = sizeof(net_request)*NETWORK_MAX_REQUESTS;
-   _net_requests.request_buffer = vg_linear_alloc( vg_mem.rtmemory, alloc_size );
+   _net_requests.request_buffer = vg_stack_allocate( &vg.rtmem, alloc_size, 8, "Request buffer" );
    memset( _net_requests.request_buffer, 0, alloc_size );
 
-   _net_requests.data_buffer = vg_linear_alloc( vg_mem.rtmemory, 4*1024*1024 );
+   _net_requests.data_buffer = vg_stack_allocate( &vg.rtmem, VG_MB(4), 8, "Request data buffer" );
 
    vg_pool *pool = &_net_requests.request_pool;
    pool->buffer = _net_requests.request_buffer;
index d589679e811e624fdad68d3370aa1305de49fcd4..5b2539557e7a39c3e5ae4ff8120bad2d34106e79 100644 (file)
@@ -114,8 +114,8 @@ void particle_alloc( particle_system *sys, u32 max )
    size_t stride = sizeof(particle_vert);
 
    sys->max = max;
-   sys->array = vg_linear_alloc( vg_mem.rtmemory, max*sizeof(particle) );
-   sys->vertices = vg_linear_alloc( vg_mem.rtmemory, max*stride*4 );
+   sys->array = vg_stack_allocate( &vg.rtmem, max*sizeof(particle), 8, "Particle array" );
+   sys->vertices = vg_stack_allocate( &vg.rtmem, max*stride*4, 8, "Particle vertices" );
 
    vg_async_task *task = vg_allocate_async_task( &vg.main_tasks, sizeof(particle_system *) + max*sizeof(u16)*6, 1 );
    struct particle_init_args *init = (void *)task->data;
index 167e90bd19dcaf4e46b7499940a2af3b1873b279..de25a2428121cdd4175fa148354b171f6eb60188 100644 (file)
@@ -89,10 +89,9 @@ void player_init(void)
 #endif
    vg_console_reg_var( "invert_y", &k_invert_y, k_var_dtype_i32, VG_VAR_PERSISTENT );
 
-   void *alloc = vg_mem.rtmemory;
    mdl_context *mdl = &localplayer.battery;
-   mdl_open( mdl, "models/battery.mdl", alloc );
-   mdl_load_metadata_block( mdl, alloc );
+   mdl_open( mdl, "models/battery.mdl", &vg.rtmem );
+   mdl_load_metadata_block( mdl, &vg.rtmem );
    mdl_async_full_load_std( mdl, NULL );
    mdl_close( mdl );
 }
index 922d1d82a0ae8827dc51aa585ffdb2072465d1e4..5c2d56503da05aa313521b04883c60ab87eb8cf9 100644 (file)
@@ -452,16 +452,15 @@ void player_glide_bind(void)
    struct skeleton *sk = &localplayer.skeleton;
    player_get_anim( &player_glide.anim_glide, "glide_pose" );
 
-   void *alloc = vg_mem.rtmemory;
    mdl_context *mdl = &player_glide.glider;
 
-   mdl_open( mdl, "models/glider.mdl", alloc );
-   mdl_load_metadata_block( mdl, alloc );
+   mdl_open( mdl, "models/glider.mdl", &vg.rtmem );
+   mdl_load_metadata_block( mdl, &vg.rtmem );
    mdl_async_full_load_std( mdl, NULL );
 
    /* load trail positions */
    array_file_ptr markers;
-   AF_LOAD_ARRAY_STRUCT( &mdl->af, &markers, ent_marker, vg_mem.scratch );
+   AF_LOAD_ARRAY_STRUCT( &mdl->af, &markers, ent_marker, &vg.scratch );
    mdl_close( mdl );
 
    for( u32 i=0; i<af_arrcount( &markers ); i ++ )
index cf947d0b94ab6e8229ae08cd361d725dbfc03721..82dccde3403385a5666eab50a64c97de56af2b7e 100644 (file)
@@ -19,7 +19,7 @@
 
 void player_load_animations( const char *path )
 {
-   metascene_load( &localplayer.animations, path, vg_mem.rtmemory );
+   metascene_load( &localplayer.animations, path, &vg.rtmem );
 }
 
 void player_get_anim( skeleton_anim *out_anim, const char *name )
@@ -50,12 +50,12 @@ void player_get_anim( skeleton_anim *out_anim, const char *name )
 void player_load_animation_reference( const char *path )
 {
    mdl_context *meta = &localplayer.skeleton_meta;
-   mdl_open( meta, path, vg_mem.rtmemory );
-   mdl_load_metadata_block( meta, vg_mem.rtmemory );
+   mdl_open( meta, path, &vg.rtmem );
+   mdl_load_metadata_block( meta, &vg.rtmem );
    mdl_close( meta );
 
    struct skeleton *sk = &localplayer.skeleton;
-   skeleton_setup( sk, meta, 0, vg_mem.rtmemory );
+   skeleton_setup( sk, meta, 0, &vg.rtmem );
 
    localplayer.id_world      = skeleton_bone_id( sk, "world" );
    localplayer.id_hip        = skeleton_bone_id( sk, "hips" );
@@ -109,9 +109,9 @@ void player_load_animation_reference( const char *path )
 
    /* allocate matrix buffers for localplayer and remote players */
    u32 mtx_size = sizeof(m4x3f)*sk->bone_count;
-   localplayer.final_mtx = vg_linear_alloc( vg_mem.rtmemory, mtx_size );
-   netplayers.final_mtx = vg_linear_alloc( vg_mem.rtmemory, mtx_size*NETWORK_MAX_PLAYERS );
-   netplayers.glider_mtx = vg_linear_alloc( vg_mem.rtmemory, sizeof(m4x3f)*NETWORK_MAX_PLAYERS );
+   localplayer.final_mtx = vg_stack_allocate( &vg.rtmem, mtx_size, 8, "Final MTX" );
+   netplayers.final_mtx = vg_stack_allocate( &vg.rtmem, mtx_size*NETWORK_MAX_PLAYERS, 8, "Network final MTX" );
+   netplayers.glider_mtx = vg_stack_allocate( &vg.rtmem, sizeof(m4x3f)*NETWORK_MAX_PLAYERS, 8, "Glider MTX" );
 }
 
 /* TODO: allow error handling */
@@ -124,7 +124,7 @@ void player_board_load( player_board *board, const char *path, void *arena )
    mdl_async_full_load_std( &board->mdl, NULL );
 
    array_file_ptr markers;
-   AF_LOAD_ARRAY_STRUCT( &board->mdl.af, &markers, ent_marker, vg_mem.scratch );
+   AF_LOAD_ARRAY_STRUCT( &board->mdl.af, &markers, ent_marker, &vg.scratch );
 
    for( int i=0; i<4; i++ )
       board->wheels[i].indice_count = 0;
index 20beb4bc034b3ea3c129c21460cc619d4ee2cda5..68bb8a3af30bd602b9f02ee2030528016c099b4b 100644 (file)
@@ -65,12 +65,10 @@ void render_init(void)
    vg_console_reg_var( "fov", &k_fov, k_var_dtype_f32, VG_VAR_PERSISTENT );
    vg_console_reg_var( "cam_height", &k_cam_height, k_var_dtype_f32, VG_VAR_PERSISTENT );
 
-   void *alloc = vg_mem.rtmemory;
-
    /* 
     * Workshop preview
     */
-   g_render.fb_workshop_preview = vg_framebuffer_allocate( alloc, 2, 1 );
+   g_render.fb_workshop_preview = vg_framebuffer_allocate( &vg.rtmem, 2, 1 );
    g_render.fb_workshop_preview->display_name = "workshop_preview";
    g_render.fb_workshop_preview->resolution_div = 0;
    g_render.fb_workshop_preview->fixed_w = WORKSHOP_PREVIEW_WIDTH;
@@ -94,7 +92,7 @@ void render_init(void)
    /*
     * Network status
     */
-   g_render.fb_network_status = vg_framebuffer_allocate( alloc, 1, 1 );
+   g_render.fb_network_status = vg_framebuffer_allocate( &vg.rtmem, 1, 1 );
    g_render.fb_network_status->display_name = "network_status_ui";
    g_render.fb_network_status->resolution_div = 0;
    g_render.fb_network_status->fixed_w = 128;
@@ -109,7 +107,7 @@ void render_init(void)
    };
    vg_framebuffer_create( g_render.fb_network_status );
 
-   g_render.fb_compass = vg_framebuffer_allocate( alloc, 1, 1 );
+   g_render.fb_compass = vg_framebuffer_allocate( &vg.rtmem, 1, 1 );
    g_render.fb_compass->display_name = "compass";
    g_render.fb_compass->resolution_div = 0;
    g_render.fb_compass->fixed_w = 800;
index 2446d44ec3854abe001a584611289366ae0d9a61..04486ba129b52932f916e0ca880e7fc35021ef91 100644 (file)
@@ -53,15 +53,15 @@ void _replay2_init(void)
    u32 MB = 1024*1024,
        size = 4*MB;
 
-   _remote_replay.buffer.buffer = vg_linear_alloc( vg_mem.rtmemory, size );
+   _remote_replay.buffer.buffer = vg_stack_allocate( &vg.rtmem, size, 8, "Remote replay buffer" );
    _remote_replay.buffer.size = size;
 
-   _replay2.buffer.buffer = vg_linear_alloc( vg_mem.rtmemory, size*2 );
+   _replay2.buffer.buffer = vg_stack_allocate( &vg.rtmem, size*2, 8, "Replay buffer" );
    _replay2.buffer.size = size*2;
 
    struct skeleton *sk = &localplayer.skeleton;
    u32 mtx_size = sizeof(m4x3f)*sk->bone_count;
-   _replay2.final_mtx = vg_linear_alloc( vg_mem.rtmemory, mtx_size );
+   _replay2.final_mtx = vg_stack_allocate( &vg.rtmem, mtx_size, 8, "Replay Final MTX" );
 }
 
 void _replay2_clear_local_buffer(void)
diff --git a/src/scripts/city.c b/src/scripts/city.c
deleted file mode 100644 (file)
index 385a4de..0000000
+++ /dev/null
@@ -1,161 +0,0 @@
-static bool _skaterift_script_city( ent_script_event *event )
-{
-#if 0
-   if( on_atom_once( event, "ch3s1_view" ) )
-   {
-      static const struct cs_subtitle EN[] = 
-      {
-         { "j1",  KCOL_JOHN "Ohh this is it guys." },
-         { "j2",  KCOL_JOHN "Good enough!" },
-         { "m1",  KCOL_MIKE "Never even thought I'd visit the USA" },
-         { "m2",  KCOL_MIKE "But here we are I guess.." },
-         { "j3",  KCOL_JOHN "I've had weirder sundays." },
-         { "m3",  KCOL_MIKE "Somehow I'm not surprised." },
-         { NULL, NULL },
-      };
-      _cutscene_load_and_play( "metascenes/ch3s1.ms", EN, 1 );
-   }
-
-   // REgion complete
-   if( on_function_trigger( event, 5 ) )
-   {
-      if( _skaterift_atom_status( "ch3s2_view" ) == 0 )
-         _skaterift_atom_set( "ch3s2_view", 2 );
-   }
-
-   // On activate finale challenge
-   if( on_function_trigger( event, 7 ) )
-   {
-   }
-
-   // On complete finale challenge
-   if( on_function_trigger( event, 8 ) )
-   {
-      _skaterift_atom_set( "city_finale", 3 );
-      if( _skaterift_atom_status( "ch3s3_view" ) == 0 )
-         _skaterift_atom_set( "ch3s3_view", 2 );
-   }
-
-   u64 status;
-   if( on_atom_changed( event, "city_finale", &status ) )
-   {
-      _ent_list_set_visible( _ent_list_get_aliased( "finale" ), status > 0 );
-      _ent_list_set_visible( _ent_list_get_aliased( "finale_marker" ), status == 2 );
-   }
-#endif
-   return 1;
-}
-
-static bool _skaterift_script_ch3s2( ent_script_event *event )
-{
-#if 0
-   u64 status;
-   if( on_atom_changed( event, "ch3s2_view", &status ) )
-      _ent_list_set_visible( event->entity_list, status == 2 );
-
-   if( on_function_trigger( event, 0 ) )
-   {
-      if( on_atom_once( event, "ch3s2_view" ) )
-      {
-         _skaterift_atom_set( "city_finale", 2 );
-
-         static const struct cs_subtitle EN[] = 
-         {
-            { "m1",  KCOL_MIKE "Is that the FBI??" },
-            { "m2",  KCOL_MIKE "I don't know about this man things are getting weird." },
-            { "m3",  KCOL_MIKE "Oh no that is not good" },
-            { "m4",  KCOL_MIKE "What do they even want with him?" },
-            { "m5",  KCOL_MIKE "Ahhh yeah, the aliens. That'l do it." },
-            { NULL, NULL },
-         };
-         _cutscene_load_and_play( "metascenes/ch3s2.ms", EN, 1 );
-      }
-   }
-#endif
-   return 1;
-}
-
-struct script_ch3s3_waiter
-{
-   bool go;
-};
-
-static bool _skaterift_script_ch3s3( ent_script_event *event )
-{
-#if 0
-   if( event->type == k_escript_event_allocate )
-   {
-      struct script_event_allocate *event_info = event->info;
-      struct script_ch3s3_waiter *waiter = vg_linear_alloc( event_info->heap, sizeof(struct script_ch3s3_waiter) );
-      waiter->go = 0;
-      event_info->userdata = waiter;
-      return 1;
-   }
-   struct script_ch1s6a_waiter *waiter = event->userdata;
-
-   u64 status;
-   if( on_atom_changed( event, "ch3s3_view", &status ) )
-      _ent_list_set_visible( event->entity_list, status == 2 );
-
-   if( on_function_trigger( event, 0 ) )
-   {
-      if( on_atom_once( event, "ch3s3_view" ) )
-      {
-         _skaterift_atom_set( "unlock_valley", 1 );
-
-         static const struct cs_subtitle EN[] = 
-         {
-            { "p1",  KCOL_PRES "Yall have some explaining to do here.." },
-            { "p2",  KCOL_PRES "Every single power plant in the USA is currently offline" },
-            { "p3",  KCOL_PRES "And yet.." },
-            { "p4",  KCOL_PRES "There is no national emergency?" },
-            { "p5",  KCOL_PRES "Nothing is wrong!" },
-            { "p6",  KCOL_PRES "So where the hell is all this power coming from?" },
-            { "p7",  KCOL_PRES "We traced it back here, to you guys" },
-            { "p8",  KCOL_PRES "Now, please. Enlighten me." },
-            { "p9",  KCOL_PRES "How exactly are you powering all of America?" },
-            { "p10", KCOL_PRES "From this one tiny establishment?" },
-            { "m1",  KCOL_MIKE "Look, this is gonna be a tough one to explain mate" },
-            { "m2",  KCOL_MIKE "And to be honest I don't really get it myself" },
-            { "p11", KCOL_PRES "Do your best!" },
-            { "m3",  KCOL_MIKE "Mr. President, we saw you take JC," },
-            { "m4",  KCOL_MIKE "Didn't he explain it to you already?" },
-            { "p12", KCOL_PRES "JC JC.." },
-            { "p13", KCOL_PRES "Ah! John Cockroach.." },
-            { "p14", KCOL_PRES "Of course. He's a friend of yours?" },
-            { "m5",  KCOL_MIKE "Yeah.. I'm an intern at his wood company." },
-            { "m6",  KCOL_MIKE "And this is just a friend of ours here." },
-            { "p15", KCOL_PRES "So what you're telling me is, and what he told me is," },
-            { "p16", KCOL_PRES "Three random people, from a wood company," },
-            { "p17", KCOL_PRES "in Tasmania, Australia" },
-            { "p18", KCOL_PRES "just happen to have nuclear fusion" },
-            { "m7",  KCOL_MIKE "Yeah I guess.." },
-            { "p19", KCOL_PRES "Man I cannot believe that old guy was telling the truth this whole time" },
-            { "m8",  KCOL_MIKE "Thats what I've been saying!" },
-            { "p20", KCOL_PRES "The world don't make sense any more" },
-            { "p21", KCOL_PRES "Well! Fortunately for you lot," },
-            { "p22", KCOL_PRES "you're coming with us!" },
-            { "p23", KCOL_PRES "We're sending you to Cambodia." },
-            { "m9",  KCOL_MIKE "What!?" },
-            { "m10", KCOL_MIKE "Can he even do that?" },
-            { "p24", KCOL_PRES "Yes I can. Now, get in." },
-            { NULL, NULL },
-         };
-         _cutscene_load_and_play( "metascenes/ch3s3.ms", EN, 1 );
-         waiter->go = 1;
-      }
-   }
-   if( event->type == k_escript_event_update )
-   {
-      if( waiter->go )
-      {
-         if( _cutscene.state == k_cutscene_state_none )
-         {
-            waiter->go = 0;
-            skaterift_load_world_command( 1, (const char *[]){ "sr002-local-dev_hub" } );
-         }
-      }
-   }
-#endif
-   return 1;
-}
diff --git a/src/scripts/hub.c b/src/scripts/hub.c
deleted file mode 100644 (file)
index 5f9dfbe..0000000
+++ /dev/null
@@ -1,143 +0,0 @@
-struct script_hub
-{
-   ent_list *break_list;
-};
-
-static bool _skaterift_script_hub( ent_script_event *event )
-{
-#if 0
-   if( event->type == k_escript_event_allocate )
-   {
-      struct script_event_allocate *event_info = event->info;
-      struct script_hub *script_hub = vg_linear_alloc( event_info->heap, sizeof(struct script_hub) );
-      script_hub->break_list = NULL;
-      event_info->userdata = script_hub;
-      return 1;
-   }
-
-   struct script_hub *script_hub = event->userdata;
-
-   if( on_completion_changed(event) )
-   {
-      u64 progress = _skaterift_atom_status( "story" );
-
-      /* blockers
-       * ------------------------------------------------------------------------ */
-      struct 
-      {
-         const char *ms, *stage, *view_atom, *list_name;
-         bool unlocked;
-      }
-      blocks[] =
-      {
-         { "metascenes/unlock_mtzero.ms", "mz",     "unlock_mtzero_view", "mtzero:locked" },
-         { "metascenes/unlock_city.ms",   "city",   "unlock_city_view",   "city:locked" },
-         { "metascenes/unlock_valley.ms", "valley", "unlock_valley_view", "valley:locked" },
-      };
-
-      i32 highest_index = -1;
-      for( i32 i=0; i<VG_ARRAY_LEN(blocks); i ++ )
-      {
-         blocks[i].unlocked = 0;
-         ent_list *list = _ent_list_get_aliased( blocks[i].list_name );
-         if( progress >= _skaterift_atom_enum_index( "story", blocks[i].stage, ATOM_MAX ) )
-         {
-            blocks[i].unlocked = 1;
-            _ent_list_set_visible( list, 0 );
-            highest_index = i;
-         }
-         else
-            _ent_list_set_visible( list, 1 );
-      }
-
-      if( highest_index != -1 )
-      {
-         ent_list *list = _ent_list_get_aliased( blocks[highest_index].list_name );
-         if( on_atom_once( event, blocks[highest_index].view_atom ) )
-         {
-            _cutscene_load_and_play( blocks[highest_index].ms, NULL, 1 );
-            _ent_list_set_visible( list, 1 );
-            script_hub->break_list = list;
-         }
-         else
-            _ent_list_set_visible( list, 0 );
-      }
-
-      /* spawns locked behind the boxes 
-       * ------------------------------------------------------------------------ */
-      world_instance *world = &_world.main;
-      u32 spawns_allowed = 0;
-      if( blocks[0].unlocked ) spawns_allowed |= k_ent_spawn_flag_group_1;
-      if( blocks[1].unlocked ) spawns_allowed |= k_ent_spawn_flag_group_2;
-      if( blocks[2].unlocked ) spawns_allowed |= k_ent_spawn_flag_group_3;
-      for( u32 i=0; i<af_arrcount(&world->ent_spawn); i++ )
-      {
-         ent_spawn *spawn = af_arritm( &world->ent_spawn, i );
-         bool allow = 0;
-
-         if( spawn->flags == 0 ) allow = 1;
-         if( spawn->flags & spawns_allowed ) allow = 1;
-
-         if( allow ) spawn->flags &= ~(u32)k_ent_spawn_flag_locked;
-         else        spawn->flags |= k_ent_spawn_flag_locked;
-      }
-   }
-
-   if( on_cutscene_marker( event, "$break" ) )
-      _explode_template_boom( script_hub->break_list );
-
-   if( on_world_start( event ) )
-   {
-      // TODO: Move these into atoms?
-      world_instance *world = &_world.main;
-      for( u32 i=0; i<af_arrcount( &world->ent_prop ); i ++ )
-      {
-         ent_prop *prop = af_arritm( &world->ent_prop, i );
-
-         if( AF_STR_EQ( &world->meta.af, prop->pstr_alias, "MARC" ) )
-            if( skaterift.achievements & 0x1 )
-               prop->flags &= ~0x1;
-
-         if( AF_STR_EQ( &world->meta.af, prop->pstr_alias, "ALBERT" ) )
-            if( skaterift.achievements & 0x2 )
-               prop->flags &= ~0x1;
-
-         if( AF_STR_EQ( &world->meta.af, prop->pstr_alias, "JANET" ) )
-            if( skaterift.achievements & 0x4 )
-               prop->flags &= ~0x1;
-
-         if( AF_STR_EQ( &world->meta.af, prop->pstr_alias, "BERNADETTA" ) )
-            if( skaterift.achievements & 0x8 )
-               prop->flags &= ~0x1;
-      }
-   }
-
-   /* gino helper board maker thing
-    * ------------------------------------------------------------------------ */
-   if( event->type == k_escript_event_atom_changed )
-   {
-      bool visible = 0;
-      if( _skaterift_atom_status( "board_maker_unlock" ) )
-         if( _skaterift_atom_status( "board_maker_hub_view" ) == 0 )
-            visible = 1;
-
-      _ent_list_set_visible( _ent_list_get_aliased( "gino_board_maker" ), visble );
-   }
-
-   if( on_function_trigger( event, 5 ) )
-   {
-      _skaterift_atom_set( "board_maker_hub_view", 1 );
-
-      // Hide just the notifier
-      struct ent_list_iter iter;
-      _ent_list_iter_start( &iter, _ent_list_get_aliased( "gino_board_maker" ), k_ent_marker );
-      if( _ent_list_iter( &iter ) )
-      {
-         world_instance *world = &_world.main;
-         ent_marker *marker = af_arritm( &world->ent_marker, iter.index );
-         marker->flags |= (u32)k_ent_marker_flag_hidden;
-      }
-   }
-#endif
-   return 0;
-}
index 6b929f3d824163cd09f25b1be811e256eb434e01..ca1f3ee50bd816042727b9ea45c8ac17aadabfc5 100644 (file)
@@ -8,7 +8,7 @@ static bool _script_l1_speed( ent_script_event *event )
    if( event->type == k_escript_event_allocate )
    {
       struct script_event_allocate *event_info = event->info;
-      struct script_speed *s = vg_linear_alloc( event_info->heap, sizeof(struct script_speed) );
+      struct script_speed *s = VG_STACK_ALLOCATE_STRUCT( event_info->heap, struct script_speed );
       s->ok = 0;
       s->init = 0;
       event_info->userdata = s;
diff --git a/src/scripts/mtzero.c b/src/scripts/mtzero.c
deleted file mode 100644 (file)
index ef728d7..0000000
+++ /dev/null
@@ -1,417 +0,0 @@
-static bool _skaterift_script_mtzero( ent_script_event *event )
-{
-#if 0
-   /* intro movie */
-   if( on_atom_once( event, "ch2s1_view" ) )
-   {
-      static const struct cs_subtitle EN[] = 
-      {
-         { "j1", KCOL_JOHN "Eughhh boy" },
-         { "j2", KCOL_JOHN "When we get off this thing I gotta go lay down for a bit" },
-         { "j3", KCOL_JOHN "Oh look" },
-         { "j4", KCOL_JOHN "There's Mike over there" },
-         { "j5", KCOL_JOHN "HELLO MIKE!" },
-         { "j7", KCOL_JOHN "Yeah listen.." },
-         { "j8", KCOL_JOHN "I know things are a bit weird at the moment" },
-         { "j9", KCOL_JOHN "but it'l make sense soon" },
-         { "j10", KCOL_JOHN "I garuntee it" },
-         { "j11", KCOL_JOHN "50%% probably garuntee it" },
-         { "j12", KCOL_JOHN "I need you to go on, keep on setting some time trials here" },
-         { "j13", KCOL_JOHN "We're gonna need your speed later" },
-         { "j14", KCOL_JOHN "Its.. Why I picked you." },
-         { NULL, NULL },
-      };
-      _cutscene_load_and_play( "metascenes/ch1s2.ms", EN, 1 );
-   }
-
-   /* requirements for battery jump */
-   if( on_completion_changed( event ) )
-   {  
-      bool requirements_met = 1;
-      struct ent_list_iter iter;
-      _ent_list_iter_start( &iter, _ent_list_get_aliased( "battery_requirements" ), k_ent_route );
-      while( _ent_list_iter( &iter ) )
-      {
-         ent_route *route = af_arritm( &_world.main.ent_route, iter.index );
-         if( !(route->flags & (k_ent_route_flag_achieve_gold|k_ent_route_flag_achieve_silver)) )
-         {
-            requirements_met = 0;
-            break;
-         }
-      }
-
-      if( requirements_met )
-         if( _skaterift_atom_status( "ch2s3_view" ) == 0 )
-            _skaterift_atom_set( "ch2s3_view", 2 );
-   }
-#endif
-
-   return 1;
-}
-
-static bool _skaterift_script_mtzero_after( ent_script_event *event )
-{
-   return 1;
-}
-
-static bool _skaterift_script_ch2s2( ent_script_event *event )
-{
-#if 0
-   if( on_function_trigger( event, 0 ) )
-   {
-      if( on_atom_once( event, "ch2s2_view" ) )
-      {
-         static const struct cs_subtitle EN[] = 
-         {
-            { "m1", KCOL_MIKE "Haha!" },
-            { "m2", KCOL_MIKE "Usually you don't put up with JC's nonsense.." },
-            { "m3", KCOL_MIKE "He's been banging on about how we need to set some kind of speed record" },
-            { "m4", KCOL_MIKE "For his.. \"Experiment\"" },
-            { "m5", KCOL_MIKE "To be honest..." },
-            { "m6", KCOL_MIKE "I'm just pretending to go along with it at this point.." },
-            { "m7", KCOL_MIKE "I don't want to loose my internship at the wood place.." },
-            { "m7b", KCOL_MIKE "He is my boss after all" },
-            { "m9", KCOL_MIKE "Anyway uh, speaking of" },
-            { "m10", KCOL_MIKE "I gotta go take care of yet another catastrophe he's created back there." },
-            { "m11", KCOL_MIKE "I won't go into it." },
-            { "m12", KCOL_MIKE "But umm" },
-            { "m13", KCOL_MIKE "Good to see you back again" },
-            { "m14", KCOL_MIKE "Later." },
-            { NULL, NULL },
-         };
-         _cutscene_load_and_play( "metascenes/ch2s2.ms", EN, 1 );
-      }
-   }
-   u64 status;
-   if( on_atom_changed( event, "ch2s2_view", &status ) )
-      _ent_list_set_visible( event->entity_list, status == 0 );
-#endif
-   return 1;
-}
-
-static bool _skaterift_script_ch2s3( ent_script_event *event )
-{
-#if 0
-   if( on_function_trigger( event, 0 ) )
-   {
-      if( on_atom_once( event, "ch2s3_view" ) )
-      {
-         static const struct cs_subtitle EN[] = 
-         {
-            { "m1",  KCOL_MIKE "Holy! You actually bothered to do these?" },
-            { "m2",  KCOL_MIKE "I mean.." },
-            { "m3",  KCOL_MIKE "JC's gonna be over the moon obviously, but" },
-            { "m4",  KCOL_MIKE "Why?" },
-            { "m5",  KCOL_MIKE "Don't you think its.. pointless?" },
-            { "m6",  KCOL_MIKE "Myeah I'm heading back to the shop" },
-            { "m7",  KCOL_MIKE "Coming?" },
-            { "m8",  KCOL_MIKE "Ohh man.." },
-            { "m9",  KCOL_MIKE "What a **** racket" },
-            { "m10", KCOL_MIKE "It's 8pm even." },
-            { "j1",  KCOL_JOHN "You guys can't be walking in and scaring me like that" },
-            { "m11", KCOL_MIKE "John, " },
-            { "m12", KCOL_MIKE "Whats that?" },
-            { "j2",  KCOL_JOHN "uhhh just uh just uhh" },
-            { "j3",  KCOL_JOHN "just cleaning something up for a client" },
-            { "m13", KCOL_MIKE "A 20ft tall quaterpipe" },
-            { "m14", KCOL_MIKE "for a client.." },
-            { "m15", KCOL_MIKE "on an island full of pensioners?" },
-            { "j4",  KCOL_JOHN "Yeah why not?" },
-            { "j5",  KCOL_JOHN "Skating's taking off right now!" },
-            { "m16", KCOL_MIKE "Come on mate.." },
-            { "j6",  KCOL_JOHN "Aight look.." },
-            { "j7",  KCOL_JOHN "I'm just skimming little bits from the surplus" },
-            { "j8",  KCOL_JOHN "I got this plan right." },
-            { "j9",  KCOL_JOHN "It's gonna be BIG" },
-            { "j10", KCOL_JOHN "People from all over the world are gonna come to see it." },
-            { "j11", KCOL_JOHN "You know how like uh..." },
-            { "j12", KCOL_JOHN "You know how no one visits the west island?" },
-            { "m17", KCOL_MIKE "Well.. yeah?" },
-            { "j13", KCOL_JOHN "Behold!" },
-            { "j14", KCOL_JOHN "Mango mega island!" },
-            { "j15", KCOL_JOHN "A skaters dream.." },
-            { "m18", KCOL_MIKE "Ohhh yeah john" },
-            { "m19", KCOL_MIKE "Looks great!" },
-            { "m20", KCOL_MIKE "And whos gonna build this.." },
-            { "m21", KCOL_MIKE "gigantic skate thing then..?" },
-            { "j16", KCOL_JOHN "Well uhhh" },
-            { "j17", KCOL_JOHN "Thats where I need your guys help." },
-            { "m22", KCOL_MIKE "What are we gonna help with exactly?" },
-            { "m23", KCOL_MIKE "You always do this John." },
-            { "m24", KCOL_MIKE "Have some grand idea and suddenly everyones onboard with it." },
-            { "j18", KCOL_JOHN "Whens the last time I asked you for anything?" },
-            { "m25", KCOL_MIKE "Yesterday.." },
-            { "j19", KCOL_JOHN "Oh..." },
-            { "j20", KCOL_JOHN "Yeah, anyway" },
-            { "j21", KCOL_JOHN "All I need is for you guys to finish the time trials" },
-            { "j22", KCOL_JOHN "Go work on those, and come back when you've got it." },
-            { "m26", KCOL_MIKE "Yeah well I got news for you!" },
-            { "m27", KCOL_MIKE "Bird here has smashed all of them already." },
-            { "j23", KCOL_JOHN "wait what?" },
-            { "j24", KCOL_JOHN "You did!?" },
-            { "j25", KCOL_JOHN "really???" },
-            { "j26", KCOL_JOHN "Holy I knew you were good!" },
-            { "m28", KCOL_MIKE "Yeah but uhh.." },
-            { "m29", KCOL_MIKE "What exactly does this have to do with building a world record size skatepark island?" },
-            { "j27", KCOL_JOHN "You see.." },
-            { "j28", KCOL_JOHN "It was the missing component. It was speed." },
-            { "j29", KCOL_JOHN "It's all we needed, to build a time net" },
-            { "j30", KCOL_JOHN "Large enough to create infinite energy." },
-            { "m30", KCOL_MIKE "Infinite.. energy..?" },
-            { "j31", KCOL_JOHN "Yeah! You know to uh contact Allen and Alvin." },
-            { "j32", KCOL_JOHN "They're the ones who are gonna help us with this whole thing." },
-            { "m31", KCOL_MIKE "Them! Ahhh no man" },
-            { "m32", KCOL_MIKE "not the aliens again.." },
-            { "m33", KCOL_MIKE "the tiny little dudes you saw in a drug induced coma" },
-            { "m34", KCOL_MIKE "are gonna help us build a megapark, on an abandoned island" },
-            { "m35", KCOL_MIKE "I dont even know why I asked.." },
-            { "m36", KCOL_MIKE "I'm clocking out. See you later." },
-            { "j33", KCOL_JOHN "Look..." },
-            { "j34", KCOL_JOHN "I'm not crazy, I promise. Just trust me." },
-            { "j35", KCOL_JOHN "Lemme prove it." },
-            { "j36", KCOL_JOHN "Bring this with you, hold onto it." },
-            { "j37", KCOL_JOHN "Skate those trails as fast as you can with it on you." },
-            { "j38", KCOL_JOHN "You'll understand when it happens," },
-            { "j39", KCOL_JOHN "And you'll see what I mean by that" },
-            { "j40", KCOL_JOHN "You'll just see it.. and" },
-            { "j41", KCOL_JOHN "If anyone asks, you didn't get this from me." },
-            { "j42", KCOL_JOHN "But I'll be there, I'll be watching, just get on with it." },
-            { NULL, NULL },
-         };
-         _cutscene_load_and_play( "metascenes/ch2s3a.ms", EN, 1 );
-      }
-   }
-   u64 status;
-   if( on_atom_changed( event, "ch2s3_view", &status ) )
-      _ent_list_set_visible( event->entity_list, status == 2 );
-#endif
-   return 1;
-}
-
-static bool _skaterift_script_ch2s5_before( ent_script_event *event )
-{
-#if 0
-   u64 status;
-   if( on_atom_changed( event, "ch2s5_view", &status ) )
-      _ent_list_set_visible(  event->entity_list, status == 2 );
-
-   if( on_function_trigger( event, 0 ) )
-   {
-      _skaterift_atom_set( "ch2s5_view", 3 );
-      skaterift_load_world_command( 1, (const char *[]){ "reload" } );
-   }
-#endif
-   return 1;
-}
-
-static bool _skaterift_script_ch2s5_after( ent_script_event *event )
-{
-#if 0
-   u64 status;
-   if( on_atom_changed( event, "ch2s5_view", &status ) )
-   {
-      if( status == 3 )
-      {
-         _skaterift_atom_set( "ch2s5_view", 1 );
-         static const struct cs_subtitle EN[] = 
-         {
-            { "m1",  KCOL_MIKE "Hi mate, hows it goin?" },
-            { "m2",  KCOL_MIKE "Yeah yeah.. I get you.. um." },
-            { "m3",  KCOL_MIKE "I genuinely have no idea where he found that cell thing" },
-            { "m4",  KCOL_MIKE "I reckon it came of some kind of secret government tech or whatever" },
-            { "m5",  KCOL_MIKE "but.." },
-            { "m6",  KCOL_MIKE "Now you know what he was doing with all those stupid poles he put up across the island" },
-            { "m7",  KCOL_MIKE "I'm starting to think I might be going crazy but.." },
-            { "m8",  KCOL_MIKE "Did you see the whole west side has actually been taken over?" },
-            { "m9",  KCOL_MIKE "Just like JC was saying.." },
-            { "m10", KCOL_MIKE "Are you telling me the aliens are actually real?" },
-            { NULL, NULL },
-         };
-         _cutscene_load_and_play( "metascenes/ch2s5.ms", EN, 1 );
-      }
-   }
-#endif
-   return 1;
-}
-
-struct script_ch2s6_waiter
-{
-   bool go;
-};
-
-static bool _skaterift_script_ch2s6( ent_script_event *event )
-{
-#if 0
-   if( event->type == k_escript_event_allocate )
-   {
-      struct script_event_allocate *event_info = event->info;
-      struct script_ch2s6_waiter *waiter = vg_linear_alloc( event_info->heap, sizeof(struct script_ch2s6_waiter) );
-      waiter->go = 0;
-      event_info->userdata = waiter;
-      return 1;
-   }
-   struct script_ch2s6_waiter *waiter = event->userdata;
-
-   u64 status;
-   if( on_atom_changed( event, "ch2s6_view", &status ) )
-      _ent_list_set_visible( event->entity_list, status == 2 );
-
-   // TODOX1: THERE ARE NO UNLOCK CONDITIONS FOR THIS YET!
-
-   if( on_function_trigger( event, 0 ) )
-   {
-      if( on_atom_once( event, "ch2s6_view" ) )
-      {
-         _skaterift_atom_set( "unlock_city", 1 );
-         _skaterift_atom_set( "ch2s6_view", 1 );
-         static const struct cs_subtitle EN[] = 
-         {
-            { "j1",  KCOL_JOHN "Ello guys" },
-            { "j2",  KCOL_JOHN "Bout time you showed up" },
-            { "j3",  KCOL_JOHN "Look who I've got here!" },
-            { "m1",  KCOL_MIKE "Uhhhhhhhhhhhhhhhhhhhhhhhhhhh" },
-            { "m2",  KCOL_MIKE "Right then." },
-            { "m3",  KCOL_MIKE "I almost feel bad for these guys" },
-            { "m4",  KCOL_MIKE "Couldve' been any scientist across the planet" },
-            { "m5",  KCOL_MIKE "you know actually smart people" },
-            { "m6",  KCOL_MIKE "but no.." },
-            { "m7",  KCOL_MIKE "JC somehow contacts them first" },
-            { "j4",  KCOL_JOHN "Heyyy man." },
-            { "j5",  KCOL_JOHN "This required a special kind of science" },
-            { "j6",  KCOL_JOHN "The kinda stuff the world isn't quite ready for yet." },
-            { "j7",  KCOL_JOHN "But if you're done insulting me.." },
-            { "j8",  KCOL_JOHN "We're off to the states for a bit." },
-            { "j9",  KCOL_JOHN "Fancy a road trip?" },
-            { NULL, NULL },
-         };
-         _cutscene_load_and_play( "metascenes/ch2s6.ms", EN, 1 );
-      }
-   }
-   if( event->type == k_escript_event_update )
-   {
-      if( waiter->go )
-      {
-         waiter->go = 0;
-         if( _cutscene.state == k_cutscene_state_none )
-         {
-            skaterift_load_world_command( 1, (const char *[]){ "sr002-local-dev_hub" } );
-         }
-      }
-   }
-#endif
-   return 1;
-}
-
-static bool _skaterift_script_ch2e1( ent_script_event *event )
-{
-#if 0
-   if( on_function_trigger( event, 0 ) )
-   {
-      if( on_atom_once( event, "ch2e1_view" ) )
-      {
-         _skaterift_atom_set( "board_maker_unlock", 1 );
-         static const struct cs_subtitle EN[] = 
-         {
-            { "j1",  KCOL_JOHN "Hey bird I'm just working on some boards here." },
-            { "j2",  KCOL_JOHN "If you wanna give me a graphic," },
-            { "j3",  KCOL_JOHN "I'll print it onto this plywood and press it" },
-            { "j4",  KCOL_JOHN "Mike'l griptape it and seal it" },
-            { "j5",  KCOL_JOHN "Ready to sell and skate!" },
-            { NULL, NULL },
-         };
-         _cutscene_load_and_play( "metascenes/ch2e1.ms", EN, 1 );
-      }
-   }
-   u64 status;
-   if( on_atom_changed( event, "ch2e1_view", &status ) )
-      _ent_list_set_visible( event->entity_list, status == 2 );
-#endif
-   return 1;
-}
-
-struct script_ch2s4_waiter
-{
-   bool go;
-   f32 timer;
-   ent_list *break_list;
-};
-
-static bool _skaterift_script_battery_jump( ent_script_event *event )
-{
-#if 0
-   if( event->type == k_escript_event_allocate )
-   {
-      struct script_event_allocate *event_info = event->info;
-      struct script_ch2s4_waiter *waiter = vg_linear_alloc( event_info->heap, sizeof(struct script_ch2s4_waiter) );
-      waiter->go = 0;
-      waiter->timer = 0.0f;
-      waiter->break_list = NULL;
-      event_info->userdata = waiter;
-      return 1;
-   }
-   struct script_ch2s4_waiter *waiter = event->userdata;
-   if( on_cutscene_marker( event, "$break" ) )
-      _explode_template_boom( waiter->break_list );
-
-   if( on_function_trigger( event, 2 ) )
-   {
-      if( on_atom_once( event, "ch2s4_view" ) )
-      {
-         _skaterift_atom_set( "ch2s5_view", 2 );
-         waiter->go = 1;
-      }
-   }
-
-   /* viewed ch2s3 means we allowing this challenge now */
-   u64 status;
-   if( on_atom_changed( event, "ch2s3_view", &status ) )
-      _ent_list_set_visible( event->entity_list, status == 1 );
-
-   if( event->type == k_escript_event_update )
-   {
-      if( waiter->go )
-      {
-         waiter->timer += vg.time_frame_delta;
-         if( waiter->timer > 2.0f )
-         {
-            waiter->go = 0;
-            static const struct cs_subtitle EN[] = 
-            {
-               { "j1",  KCOL_JOHN "Oh my god.." },
-               { "j2",  KCOL_JOHN "You **** did it now" },
-               { "j3",  KCOL_JOHN "I told you I am not crazy!" },
-               { "j4",  KCOL_JOHN "You've done me a real solid mate." },
-               { "j5",  KCOL_JOHN "When I switch this thing on" },
-               { "j6",  KCOL_JOHN "It's gonna broadcast our location to them.." },
-               { "j7",  KCOL_JOHN "We have just enough power. Thanks to you my friend" },
-               { "j8",  KCOL_JOHN "Okayyy any second" },
-               { "j9",  KCOL_JOHN "BOSH" },
-               { "j10", KCOL_JOHN "HELLO MY FRIENDS" },
-               { "j11", KCOL_JOHN "WE NEED HELP" },
-               { "j12", KCOL_JOHN "THIS IS CAPTAIN JOHN COCROACH" },
-               { "j13", KCOL_JOHN "PLEASE COME AS SOON AS YOU CAN TO MT.ZERO ISLAND" },
-               { "j14", KCOL_JOHN "Our coordinates are...." },
-               { NULL, NULL },
-            };
-            _cutscene_load_and_play( "metascenes/ch2s4.ms", EN, 1 );
-         }
-      }
-   }
-
-   if( on_function_trigger( event, 0 ) )
-   {
-      if( on_atom_once( event, "battery_jump_view" ) )
-      {
-         _cutscene_load_and_play( "metascenes/battery_intro.ms", NULL, 1 );
-         waiter->break_list = _ent_list_get_aliased( "battery:locked" );
-      }
-   }
-
-   if( event->type == k_escript_event_world_start )
-   {
-      _ent_list_set_visible( _ent_list_get_aliased( "battery:locked" ), 
-                             _skaterift_atom_status( "battery_jump_view" ) == 0 );
-   }
-#endif
-   return 1;
-}
index 0ee86337e66ed81c31ded02643a12ff26caedb06..eff9853db187d8731007906f856623e8bacca2fb 100644 (file)
@@ -9,7 +9,7 @@ static bool _skaterift_script_volc( ent_script_event *event )
    if( event->type == k_escript_event_allocate )
    {
       struct script_event_allocate *event_info = event->info;
-      struct script_volcano *v = vg_linear_alloc( event_info->heap, sizeof(struct script_volcano) );
+      struct script_volcano *v = VG_STACK_ALLOCATE_STRUCT( event_info->heap, struct script_volcano );
       v->docks_wait = 0;
       v->stopped_timer = 0.0f;
       event_info->userdata = v;
diff --git a/src/scripts/valley.c b/src/scripts/valley.c
deleted file mode 100644 (file)
index 727be69..0000000
+++ /dev/null
@@ -1,183 +0,0 @@
-#if 0
-struct script_valley_waiter
-{
-   bool go;
-};
-
-static bool _skaterift_script_valley( ent_script_event *event )
-{
-   if( event->type == k_escript_event_allocate )
-   {
-      struct script_event_allocate *event_info = event->info;
-      struct script_valley_waiter *waiter = vg_linear_alloc( event_info->heap, sizeof(struct script_valley_waiter) );
-      waiter->go = 0;
-      event_info->userdata = waiter;
-      return 1;
-   }
-   struct script_valley_waiter *waiter = event->userdata;
-
-
-
-
-#if 0
-
-   if( on_atom_once( event, "ch4s1a_view" ) )
-   {
-      /* ch4s1: Mike and you are first encountering the valley world */
-      static const struct cs_subtitle EN[] = 
-      {
-         { "m1",  KCOL_MIKE "It's gotta be some kind of dream right?" },
-         { "m2",  KCOL_MIKE "I mean... Cambodia?" },
-         { "m3",  KCOL_MIKE "What are we even doing here?" },
-         { NULL, NULL },
-      };
-      _cutscene_load_and_play( "metascenes/ch4s1a.ms", EN, 1 );
-   }
-
-   /* main region is completed (this is just the time trial as of 14.05.25, unlock ch4s2 cutscene */
-   if( on_function_trigger( event, 27 ) )
-   {
-      if( _skaterift_atom_status( "ch4s2_view" ) == 0 )
-         _skaterift_atom_set( "ch4s2_view", 2 );
-   }
-
-   u64 status;
-   if( on_atom_changed( event, "valley_finale", &status ) )
-   {
-      _ent_list_set_visible( _ent_list_get_aliased( "finale:locked" ),   status != 1 );
-      _ent_list_set_visible( _ent_list_get_aliased( "finale:unlocked" ), status == 1 );
-   }
-
-   /* finale completed, trigger the exit movie */
-   if( on_function_trigger( event, 21 ) )
-   {
-      _ent_list_set_visible( _ent_list_get_aliased( "rocket" ), 0 );
-      _skaterift_atom_set( "unlock_venus", 1 );
-      waiter->go = 1;
-      if( on_atom_once( event, "rocket_launch_view" ) )
-      {
-         static const struct cs_subtitle EN[] = 
-         {
-            { NULL, NULL },
-         };
-         _cutscene_load_and_play( "metascenes/ch4rk.ms", EN, 1 );
-      }
-   }
-
-   if( on_cutscene_marker( event, "$fast" ) )
-      k_day_length = 0.1f;
-   if( on_cutscene_marker( event, "$normal" ) )
-      k_day_length = 30.0f;
-
-   u64 _0, _1;
-   if( on_atom_changed( event, "valley_finale", &_0 ) || on_atom_changed( event, "unlock_venus", &_1 ) )
-   {
-      // Notification & video tape
-      bool visible = _skaterift_atom_status( "valley_finale" );
-      bool completed = _skaterift_atom_status( "unlock_venus" );
-      _ent_list_set_visible( _ent_list_get_aliased( "finale_not_done" ), visible && !completed );
-   }
-
-   if( event->type == k_escript_event_update )
-   {
-      if( waiter->go )
-      {
-         if( _cutscene.state == k_cutscene_state_none )
-         {
-            waiter->go = 0;
-            skaterift_load_world_command( 1, (const char *[]){ "sr002-local-venus" } );
-         }
-      }
-   }
-
-#endif
-   return 1;
-}
-
-static bool _skaterift_script_ch4s2( ent_script_event *event )
-{
-   /* ch4s2: Mike and you find the rocket, and talk to the FBI person. */
-   u64 status;
-   if( on_atom_changed( event, "ch4s2_view", &status ) )
-   {
-      _ent_list_set_visible( event->entity_list, status == 2 );
-
-      bool launched = _skaterift_atom_status( "unlock_venus" );
-      _ent_list_set_visible( _ent_list_get_aliased( "rocket" ), (status >= 1) && !(launched) );
-   }
-
-   if( on_function_trigger( event, 0 ) )
-   {
-      if( on_atom_once( event, "ch4s2_view" ) )
-      {
-         _skaterift_atom_set( "valley_cave", 1 );
-         _ent_npc_set_in_cutscene( k_npc_fbi, 1 );
-
-         static const struct cs_subtitle EN[] = 
-         {
-            { "m1",  KCOL_MIKE "What the hell is that thing?" },
-            { "f1",  KCOL_FBI  "Look man, all they told is that uhh" },
-            { "f2",  KCOL_FBI  "they're sending you up to one of saturns moons.." },
-            { "f3",  KCOL_FBI  "On that thing." },
-            { "f4",  KCOL_FBI  "To help you on your mission." },
-            { "f5",  KCOL_FBI  "You guys are more important than any person on earth right now" },
-            { "f6",  KCOL_FBI  "According to the president." },
-            { "f7",  KCOL_FBI  "But obviously this is some kind of joke I'm not in on." },
-            { "f8",  KCOL_FBI  "I don't believe a word of it." },
-            { NULL, NULL },
-         };
-         _cutscene_load_and_play( "metascenes/ch4s2.ms", EN, 1 );
-      }
-   }
-
-   return 1;
-}
-
-static bool _skaterift_script_ch4s1( ent_script_event *event )
-{
-   u64 _0, _1;
-   if( on_atom_changed( event, "valley_cave", &_0 ) || on_atom_changed( event, "valley_finale", &_1 ) )
-   {
-      // Notification & video tape
-      bool visible = _skaterift_atom_status( "valley_cave" );
-      bool completed = _skaterift_atom_status( "valley_finale" );
-      _ent_list_set_visible( _ent_list_get_aliased( "cave_not_done" ), visible && !completed );
-      _ent_list_set_visible( event->entity_list, visible );
-   }
-
-   /* triggers on challenge activating */
-   if( on_function_trigger( event, 3 ) )
-   {
-      /* ch4s1: (Yes, this comes after ch4s2), Mike is leaving, because JC hasn't shown up anywhere. */
-      if( on_atom_once( event, "ch4s1_view" ) )
-      {
-         static const struct cs_subtitle EN[] = 
-         {
-         { "m1",  KCOL_MIKE "John hasn't turned up anywhere.." },
-         { "m2",  KCOL_MIKE "Not here, not back in Australia" },
-         { "m3",  KCOL_MIKE "nowhere?" },
-         { "m4",  KCOL_MIKE "I don't know how we can trust a single note.." },
-         { "m5",  KCOL_MIKE "I mean it is JC but.." },
-         { "m6",  KCOL_MIKE "Come on." },
-         { "m7",  KCOL_MIKE "I havn't seen him in weeks" },
-         { "m8",  KCOL_MIKE "I'm gonna go home," },
-         { "m9",  KCOL_MIKE "I'm bailing on this one man I'm sorry." },
-         { NULL, NULL },
-         };
-         _cutscene_load_and_play( "metascenes/ch4s1.ms", EN, 1 );
-      }
-   }
-   
-   /* triggers on challenge completed */
-   if( on_function_trigger( event, 6 ) )
-      _skaterift_atom_set( "valley_finale", 1 );
-
-   return 1;
-}
-
-static bool _skaterift_script_ch4s3( ent_script_event *event )
-{
-   // on venus
-   return 1;
-}
-#endif
index 1ad64a45c4564b2ba335f96584216a4dadc63bcd..939951876ddabf93b77b583ac84e91d7b3381349 100644 (file)
@@ -73,9 +73,9 @@ static void skaterift_load_player_content(void)
 
    player_load_animation_reference( "models/ch_none.mdl" );
    player_load_animations( "metascenes/skater.ms" );
-   player_model_load( &localplayer.fallback_model, "models/ch_none.mdl", vg_mem.rtmemory );
+   player_model_load( &localplayer.fallback_model, "models/ch_none.mdl", &vg.rtmem );
    player__bind();
-   player_board_load( &localplayer.fallback_board, "models/board_none.mdl", vg_mem.rtmemory );
+   player_board_load( &localplayer.fallback_board, "models/board_none.mdl", &vg.rtmem );
 }
 
 int skaterift_quit_command( int argc, const char *argv[] )
@@ -104,7 +104,7 @@ static void game_load_co( vg_coroutine *co )
       if( g_client.demo_mode != 2 )
       {
          u32 sz; char *drm;
-         if( (drm = vg_file_read_text( vg_mem.scratch, "DRM", &sz )) )
+         if( (drm = vg_file_read( &vg.scratch, "DRM", &sz, 1 )) )
             if( !strcmp(drm, "blibby!") )
                g_client.demo_mode = 0;
       }
@@ -185,7 +185,7 @@ static void game_load_co( vg_coroutine *co )
 
       _world.loader_instance = &_world.main;
       _world.loader_preview_mode = 0;
-      _world.loader_heap = _world.heap; 
+      _world.loader_stack = _world.stack;
 
       if( !_world.load_addon )
       {
@@ -677,9 +677,6 @@ void vg_framebuffer_resize( int w, int h )
 #include "ent_cutscene.c"
 #include "ent_atom.c"
 
-//TODO
-//#include "vg/submodules/hashmap.c/hashmap.c"
-
 static void _handle_vg_signal( vg_signal_id id, bool state )
 {
    if( (id == vg.sig_engine) && state )
@@ -692,6 +689,10 @@ static void _handle_vg_signal( vg_signal_id id, bool state )
 int main( int argc, const char *argv[] )
 {
    vg_init( argc, argv, "Voyager Game Engine" );
+   vg_stack_init( &vg.rtmem, NULL, VG_MB(200), "RT Memory" );
+   vg_stack_set_flags( &vg.rtmem, VG_STACK_ALLOCATOR_METADATA );
+   vg_stack_init( &vg.scratch, NULL, VG_MB(10), "Scratch" );
+
    network_set_host( "skaterift.com", NULL );
 
    {
@@ -712,8 +713,6 @@ int main( int argc, const char *argv[] )
          skaterift.override_load_world = arg;
    }
 
-   vg_mem.use_libc_malloc = 0;
-   vg_set_mem_quota( 200*1024*1024 );
    skaterift.sig_world = _vg_tower_create_signal( "World Loaded" );
    skaterift.full_ready_mask = _vg_tower_mask( skaterift.sig_world ) | 
                                _vg_tower_mask( vg.sig_engine ) | 
index 74b31b2b33f672952ce454ef47f8e3c374f49e6a..87780aff53ab388ef7c21ec72e4dffe7a19530fe 100644 (file)
@@ -404,7 +404,7 @@ static void skeleton_apply_standard( struct skeleton *skele, ms_keyframe *pose,
    skeleton_apply_transform( skele, transform, final_mtx );
 }
 
-static void skeleton_alloc_from( struct skeleton *skele, void *lin_alloc, mdl_context *mdl, mdl_armature *armature )
+static void skeleton_alloc_from( struct skeleton *skele, vg_stack_allocator *stack, mdl_context *mdl, mdl_armature *armature )
 {
    skele->bone_count     = armature->bone_count+1;
    skele->ik_count       = 0;
@@ -422,8 +422,8 @@ static void skeleton_alloc_from( struct skeleton *skele, void *lin_alloc, mdl_co
    u32 bone_size = sizeof(struct skeleton_bone) * skele->bone_count,
        ik_size   = sizeof(struct skeleton_ik)   * skele->ik_count;
 
-   skele->bones = vg_linear_alloc( lin_alloc, bone_size );
-   skele->ik    = vg_linear_alloc( lin_alloc, ik_size );
+   skele->bones = vg_stack_allocate( stack, bone_size, 8, NULL );
+   skele->ik    = vg_stack_allocate( stack, ik_size, 8, NULL );
 
    memset( skele->bones, 0, bone_size );
    memset( skele->ik, 0, ik_size );
@@ -435,7 +435,7 @@ static void skeleton_fatal_err(void)
 }
 
 /* Setup a skeleton from model. mdl's metadata should stick around */
-void skeleton_setup( struct skeleton *skele, mdl_context *mdl, u32 index, void *lin_alloc )
+void skeleton_setup( struct skeleton *skele, mdl_context *mdl, u32 index, vg_stack_allocator *stack )
 {
    u32 ik_count = 0, collider_count = 0;
    skele->bone_count = 0;
@@ -448,7 +448,7 @@ void skeleton_setup( struct skeleton *skele, mdl_context *mdl, u32 index, void *
    }
 
    mdl_armature *armature = &mdl->armatures[ index ];
-   skeleton_alloc_from( skele, lin_alloc, mdl, armature );
+   skeleton_alloc_from( skele, stack, mdl, armature );
 
    for( u32 i=0; i<armature->bone_count; i++ )
    {
index 20c83b593ee73bbbe31180a494d21e9bb80736bf..fa123c13f2aa8091cf612f2dc85ef6b5221cce3b 100644 (file)
@@ -145,8 +145,8 @@ void trail_alloc( trail_system *sys, u32 max )
 
    size_t stride = sizeof(trail_vert);
    sys->max = max;
-   sys->array = vg_linear_alloc( vg_mem.rtmemory, max*sizeof(trail_point) );
-   sys->vertices = vg_linear_alloc( vg_mem.rtmemory, max*stride*2 );
+   sys->array = vg_stack_allocate( &vg.rtmem, max*sizeof(trail_point), 8, "Trail array" );
+   sys->vertices = vg_stack_allocate( &vg.rtmem, max*stride*2, 8, "Trail vertices" );
 
    vg_async_task *task = vg_allocate_async_task( &vg.main_tasks, sizeof(struct trail_init_args), 1 );
    struct trail_init_args *init = (void *)task->data;
index 8f6d31984921504e52538f2f62c3c1a8f7338957..7735e7f553ea2a7e9816df7a4051adaf662bd968 100644 (file)
@@ -291,7 +291,7 @@ static void _workshop_form_submit_t1( void *userdata )
    u8 descriptor_buf[ 512 ];
    vg_msg descriptor;
    vg_msg_init( &descriptor, descriptor_buf, sizeof(descriptor_buf) );
-   vg_linear_clear( vg_mem.scratch );
+   vg_stack_clear( &vg.scratch );
 
    /* short description */
    vg_msg_frame( &descriptor, "workshop" );
@@ -304,7 +304,7 @@ static void _workshop_form_submit_t1( void *userdata )
    vg_msg_end_frame( &descriptor );
    //vg_msg_wkvstr( &descriptor, "location", "USA" );
 
-   char *short_descriptor_str = vg_linear_alloc( vg_mem.scratch, vg_align8(descriptor.cur.co*2+1));
+   char *short_descriptor_str = vg_stack_allocate( &vg.scratch, descriptor.cur.co*2+1, 1, "Descriptor String" );
    vg_bin_str( descriptor_buf, short_descriptor_str, descriptor.cur.co );
    short_descriptor_str[descriptor.cur.co*2] = '\0';
    vg_info( "binstr: %s\n", short_descriptor_str );
@@ -421,8 +421,8 @@ static void workshop_op_submit( ui_context *ctx )
 
    int w, h;
    vg_framebuffer_get_res( g_render.fb_workshop_preview, &w, &h );
-   vg_linear_clear( vg_mem.scratch );
-   workshop_form.img_buffer = vg_linear_alloc( vg_mem.scratch, w*h*3 );
+   vg_stack_clear( &vg.scratch );
+   workshop_form.img_buffer = vg_stack_allocate( &vg.scratch, w*h*3, 8, "Image buffer" );
 
    vg_info( "read framebuffer: glReadPixels( %dx%d )\n", w,h );
 
@@ -518,21 +518,21 @@ static void _workshop_form_load_t1( void *userdata )
       return;
    }
 
-   if( workshop_form.model_arena == NULL )
+   if( workshop_form.model_stack.capacity == 0 )
    {
-      workshop_form.model_arena = 
-         _vg_create_linear_allocator( NULL, 1024*2, VG_MEMORY_SYSTEM, "Workshop model data arena" );
+      // This leaks. Dosnt get freed.
+      vg_stack_init( &workshop_form.model_stack, NULL, VG_KB(16), "Workshop model data" );
    }
-   void *arena = workshop_form.model_arena;
-   vg_linear_clear( arena );
+   
+   vg_stack_clear( &workshop_form.model_stack );
 
    if( workshop_form.submission.type == k_addon_type_board )
-      player_board_load( &workshop_form.board_model, path_buf, arena );
+      player_board_load( &workshop_form.board_model, path_buf, &workshop_form.model_stack );
    else if( workshop_form.submission.type == k_addon_type_player )
    {
       workshop_form.playermodel_view.cache_slot = 0;
       workshop_form.playermodel_view.fallback = &workshop_form.player_model;
-      player_model_load( &workshop_form.player_model, path_buf, arena );
+      player_model_load( &workshop_form.player_model, path_buf, &workshop_form.model_stack );
    }
 
    vg_async_call( &vg.main_tasks, workshop_form_loadmodel_async_complete, NULL );
index 9cdec71dc6ca3b73e79231c2b99baa4ca2a0b59e..a162d3eef20ad5ed156aa7e26f44bf8f20a00cc1 100644 (file)
@@ -71,7 +71,7 @@ struct workshop_form
     */
 
    char addon_folder[128];
-   void *model_arena;
+   vg_stack_allocator model_stack;
    struct player_board board_model;
 
    struct player_model player_model;
index 6a7b4d37c93a07548877591b9a94f4c46d592ced..21eb5cba55393fe959d16e3c49126d5e30e76f99 100644 (file)
@@ -22,11 +22,10 @@ void world_init(void)
    vg_loader_step( world_routes_init, NULL );
 
    /* Allocate dynamic world memory arena */
-   u32 max_size = 76*1024*1024;
-   _world.heap = vg_create_linear_allocator( vg_mem.rtmemory, max_size, VG_MEMORY_SYSTEM );
-
-   max_size = 32*1024*1024;
-   _world.preview_heap = vg_create_linear_allocator( vg_mem.rtmemory, max_size, VG_MEMORY_SYSTEM );
+   _world.stack = vg_stack_make_substack( &vg.rtmem, VG_MB(76), "World main data" );
+   vg_stack_set_flags( _world.stack, VG_STACK_ALLOCATOR_METADATA );
+   _world.preview_stack = vg_stack_make_substack( &vg.rtmem, VG_MB(32), "World preview data" );
+   vg_stack_set_flags( _world.preview_stack, VG_STACK_ALLOCATOR_METADATA );
 }
 
 void world_update( world_instance *world, v3f pos )
index 20ddd516bf647c82a15e2c91c679ea2242ae4db2..8f425468210f1b1de8c944404f39af958379c763 100644 (file)
@@ -57,7 +57,7 @@ struct world_instance
 {
    bool complete;
    addon_id addon_id;
-   void *heap;
+   vg_stack_allocator *stack;
 
    struct
    {
@@ -226,7 +226,7 @@ struct world_static
     * Allocated as system memory
     * --------------------------------------------------------------------------
     */
-   void *heap, *preview_heap;
+   vg_stack_allocator *stack, *preview_stack;
 
    u32 current_run_version;
    f64 last_gate_hit_time;
@@ -258,7 +258,7 @@ struct world_static
 
    addon_id load_addon;
    world_instance *loader_instance;
-   void *loader_heap;
+   vg_stack_allocator *loader_stack;
    bool loader_preview_mode;
    char loader_filename[64];
 
index d71b6fc65cff10f420c104557eb0ad06f324faed..a25d176a8edc03a625c3ff868b64e700317ee7bd 100644 (file)
@@ -73,8 +73,8 @@ void world_gen_entities_init( world_instance *world )
 
    if( world->nonlocal_gate_count )
    {
-      world->nonlocal_gates_cubemaps = vg_linear_alloc( world->heap, 
-                                                        vg_align8(world->nonlocal_gate_count*sizeof(GLuint)) );
+      world->nonlocal_gates_cubemaps = vg_stack_allocate( world->stack, world->nonlocal_gate_count*sizeof(GLuint),
+                                                          8, "Non-local cubemaps" );
       for( u32 i=0; i<world->nonlocal_gate_count; i ++ )
          world->nonlocal_gates_cubemaps[i] = 0;
 
@@ -133,8 +133,8 @@ void world_gen_entities_init( world_instance *world )
             /* embedded files are fine to clear the scratch buffer, only
              * external audio uses it */
 
-            vg_linear_clear( vg_mem.scratch );
-            void *data = vg_linear_alloc( vg_mem.scratch, clip->_.file.pack_size );
+            vg_stack_clear( &vg.scratch );
+            void *data = vg_stack_allocate( &vg.scratch, clip->_.file.pack_size, 8, "Pack data" );
 
             mdl_fread_pack_file( &world->meta, &clip->_.file, data );
 
@@ -151,7 +151,7 @@ void world_gen_entities_init( world_instance *world )
             clip->_.clip.size = 0;
          }
 
-         audio_clip_load( &clip->_.clip, world->heap );
+         audio_clip_load( &clip->_.clip, world->stack );
       }
    }
 
@@ -174,7 +174,7 @@ void world_gen_entities_init( world_instance *world )
       indexed_count += af_arrcount( indexables[i].array );
    vg_info( "indexing %u entities\n", indexed_count );
 
-   world->entity_list = vg_linear_alloc( world->heap, vg_align8(indexed_count*sizeof(u32)));
+   world->entity_list = vg_stack_allocate( world->stack, indexed_count*sizeof(u32), 4, "Entity List");
 
    u32 index=0;
    for( u32 i=0; i<VG_ARRAY_LEN(indexables); i++ )
@@ -185,7 +185,7 @@ void world_gen_entities_init( world_instance *world )
          world->entity_list[index ++] = mdl_entity_id( type, j );
    }
 
-   world->entity_bh = bh_create( world->heap, &bh_system_entity_list, world, indexed_count, 2 );
+   world->entity_bh = bh_create( world->stack, &bh_system_entity_list, world, indexed_count, 2 );
 
    /* FIXME: This should be scene geometry instead?????????? */
    world->tar_min = world->entity_bh->nodes[0].bbx[0][1];
index d607fc8f6a3a82ad1184d9e13b709f508acfad0b..9e673d211d47984be0ae9b9a36b06db109e2f555 100644 (file)
@@ -49,11 +49,11 @@ void gate_transform_update( ent_gate *gate )
 void world_gates_init(void)
 {
    vg_info( "world_gates_init\n" );
-   vg_linear_clear( vg_mem.scratch );
+   vg_stack_clear( &vg.scratch );
 
    mdl_context mgate;
-   mdl_open( &mgate, "models/rs_gate.mdl", vg_mem.scratch );
-   mdl_load_metadata_block( &mgate, vg_mem.scratch );
+   mdl_open( &mgate, "models/rs_gate.mdl", &vg.scratch );
+   mdl_load_metadata_block( &mgate, &vg.scratch );
 
    world_gates.sm_surface = mgate.submeshes[ mdl_get_submesh_index( &mgate, "rs_gate" ) ];
 
index 443096be232b0a4d3658de9e35ebb7437aa66948..81cadf2a1fba7b9f6fee253981c848746e156023 100644 (file)
@@ -218,8 +218,7 @@ void world_gen_generate_meshes( world_instance *world )
    u32 geo_max_verts = 320000,
        geo_max_indices = 1200000;
    scene_init( &world->scene_geo, geo_max_verts, geo_max_indices );
-   u32 buf_size = scene_mem_required( &world->scene_geo );
-   u8 *buffer = vg_linear_alloc( world->heap, buf_size );
+   u8 *buffer = vg_stack_allocate( world->stack, scene_mem_required( &world->scene_geo ), 8, "Geometry buffer" );
    scene_supply_buffer( &world->scene_geo, buffer );
 
    m4x3f midentity;
@@ -256,8 +255,7 @@ void world_gen_generate_meshes( world_instance *world )
 
    world->scene_geo.max_indices = world->scene_geo.indice_count;
    world->scene_geo.max_vertices = world->scene_geo.vertex_count;
-   buf_size = scene_mem_required( &world->scene_geo );
-   buffer = vg_linear_resize( world->heap, buffer, buf_size );
+   vg_stack_resize_last( world->stack, scene_mem_required( &world->scene_geo ) );
 
    world->scene_geo.arrvertices = (scene_vert *)(buffer);
    world->scene_geo.arrindices = (u32 *)(buffer + new_vert_size);
@@ -275,7 +273,7 @@ void world_gen_generate_meshes( world_instance *world )
    if( !_world.loader_preview_mode )
    {
       vg_info( "creating bvh\n" );
-      world->geo_bh = scene_bh_create( world->heap, &world->scene_geo );
+      world->geo_bh = scene_bh_create( world->stack, &world->scene_geo );
    }
 
    /*
@@ -741,7 +739,7 @@ void world_gen_load_surfaces( world_instance *world )
    {
       vg_info( "Loading textures\n" );
       world->texture_count = world->meta.texture_count+1;
-      world->textures = vg_linear_alloc( world->heap, vg_align8(sizeof(GLuint)*world->texture_count) );
+      world->textures = vg_stack_allocate( world->stack, sizeof(GLuint)*world->texture_count, 8, "Textures" );
       world->textures[0] = vg.tex_missing;
 
       for( u32 i=0; i<world->meta.texture_count; i++ )
@@ -753,8 +751,8 @@ void world_gen_load_surfaces( world_instance *world )
             vg_fatal_error( "World models must have packed textures!" );
          }
 
-         vg_linear_clear( vg_mem.scratch );
-         void *src_data = vg_linear_alloc( vg_mem.scratch, tex->file.pack_size );
+         vg_stack_clear( &vg.scratch );
+         void *src_data = vg_stack_allocate( &vg.scratch, tex->file.pack_size, 8, "Pack Data" );
          mdl_fread_pack_file( &world->meta, &tex->file, src_data );
 
          vg_tex2d_load_qoi_async( src_data, tex->file.pack_size,
@@ -766,7 +764,7 @@ void world_gen_load_surfaces( world_instance *world )
    vg_info( "Loading materials\n" );
 
    world->surface_count = world->meta.material_count+1;
-   world->surfaces = vg_linear_alloc( world->heap, vg_align8(sizeof(struct world_surface)*world->surface_count) );
+   world->surfaces = vg_stack_allocate( world->stack, sizeof(struct world_surface)*world->surface_count, 8, "Surfaces" );
 
    /* error material */
    struct world_surface *errmat = &world->surfaces[0];
index f775a953a4b83e55c614a90dca18f75874c70e6f..701df9fe618258e4a4c1453ce3b330043c6055da 100644 (file)
 /* 
  * load the .mdl file located in path as a world instance
  */
-static void world_instance_load_mdl( world_instance *world, const char *path, void *heap )
+static void world_instance_load_mdl( world_instance *world, const char *path, vg_stack_allocator *stack )
 {
    vg_loader_set_user_information( "Loading world data" );
-
    world_init_blank( world );
-   world->heap = heap;
+   world->stack = stack;
    
    vg_info( "Loading world model: %s\n", path );
 
    mdl_context *meta = &world->meta;
    array_file_context *af = &meta->af;
 
-   mdl_open( meta, path, world->heap );
-   mdl_load_metadata_block( meta, world->heap );
-   mdl_load_mesh_block( meta, world->heap );
+   mdl_open( meta, path, world->stack );
+   mdl_load_metadata_block( meta, world->stack );
+   mdl_load_mesh_block( meta, world->stack );
 
    bool load_all = !_world.loader_preview_mode;
 
    if( load_all )
    {
-      AF_LOAD_ARRAY_STRUCT( af, &world->ent_gate,      ent_gate,       heap );
-      AF_LOAD_ARRAY_STRUCT( af, &world->ent_camera,    ent_camera,     heap );
+      AF_LOAD_ARRAY_STRUCT( af, &world->ent_gate,      ent_gate,   stack );
+      AF_LOAD_ARRAY_STRUCT( af, &world->ent_camera,    ent_camera, stack );
 
 #if (MDL_VERSION_MIN <= 107)
       if( meta->version <= 107 )
       {
          array_file_ptr legacy_cameras;
-         af_load_array( af, &legacy_cameras, "ent_camera",
-               vg_mem.scratch, sizeof(struct ent_camera_v107) );
+         af_load_array( af, &legacy_cameras, "ent_camera", &vg.scratch, sizeof(struct ent_camera_v107) );
 
          for( u32 i=0; i<af_arrcount(&legacy_cameras); i ++ )
          {
@@ -52,12 +50,12 @@ static void world_instance_load_mdl( world_instance *world, const char *path, vo
       }
 #endif
 
-      AF_LOAD_ARRAY_STRUCT( af, &world->ent_spawn,     ent_spawn,      heap );
+      AF_LOAD_ARRAY_STRUCT( af, &world->ent_spawn,     ent_spawn,      stack );
 
       if( af_arrcount( &world->ent_spawn ) == 0 )
       {
          vg_warn( "There are no spawn points in the world; defaulting to first non-local gate.\n" );
-         world->ent_spawn.data = vg_linear_alloc( heap, 1*sizeof(ent_spawn) );
+         world->ent_spawn.data = vg_stack_allocate( stack, 1*sizeof(ent_spawn), 8, NULL );
          world->ent_spawn.count = 1;
          world->ent_spawn.stride = sizeof(ent_spawn);
 
@@ -86,42 +84,42 @@ static void world_instance_load_mdl( world_instance *world, const char *path, vo
          }
       }
 
-      AF_LOAD_ARRAY_STRUCT( af, &world->ent_light,     ent_light,      heap );
-      AF_LOAD_ARRAY_STRUCT( af, &world->ent_route_node,ent_route_node, heap );
-      AF_LOAD_ARRAY_STRUCT( af, &world->ent_path_index,ent_path_index, heap );
-      AF_LOAD_ARRAY_STRUCT( af, &world->ent_checkpoint,ent_checkpoint, heap );
+      AF_LOAD_ARRAY_STRUCT( af, &world->ent_light,     ent_light,      stack );
+      AF_LOAD_ARRAY_STRUCT( af, &world->ent_route_node,ent_route_node, stack );
+      AF_LOAD_ARRAY_STRUCT( af, &world->ent_path_index,ent_path_index, stack );
+      AF_LOAD_ARRAY_STRUCT( af, &world->ent_checkpoint,ent_checkpoint, stack );
    }
 
-   AF_LOAD_ARRAY_STRUCT( af, &world->ent_route,     ent_route,      heap );
-   AF_LOAD_ARRAY_STRUCT( af, &world->ent_region,    ent_region,     heap );
+   AF_LOAD_ARRAY_STRUCT( af, &world->ent_route,     ent_route,      stack );
+   AF_LOAD_ARRAY_STRUCT( af, &world->ent_region,    ent_region,     stack );
 
    if( load_all )
    {
-      AF_LOAD_ARRAY_STRUCT( af, &world->ent_water,     ent_water,      heap );
-      AF_LOAD_ARRAY_STRUCT( af, &world->ent_audio_clip,ent_audio_clip, heap );
-      AF_LOAD_ARRAY_STRUCT( af, &world->ent_audio,     ent_audio,      heap );
-      AF_LOAD_ARRAY_STRUCT( af, &world->ent_volume,    ent_volume,     heap );
-      AF_LOAD_ARRAY_STRUCT( af, &world->ent_traffic,   ent_traffic,    heap );
-      AF_LOAD_ARRAY_STRUCT( af, &world->ent_marker,    ent_marker,     heap );
-      AF_LOAD_ARRAY_STRUCT( af, &world->ent_skateshop, ent_skateshop,  heap );
-      AF_LOAD_ARRAY_STRUCT( af, &world->ent_swspreview,ent_swspreview, heap );
-      AF_LOAD_ARRAY_STRUCT( af, &world->ent_ccmd,      ent_ccmd,       heap );
-      AF_LOAD_ARRAY_STRUCT( af, &world->ent_objective, ent_objective,  heap );
-      AF_LOAD_ARRAY_STRUCT( af, &world->ent_challenge, ent_challenge,  heap );
-      AF_LOAD_ARRAY_STRUCT( af, &world->ent_cubemap,   ent_cubemap,    heap );
-      AF_LOAD_ARRAY_STRUCT( af, &world->ent_prop,      ent_prop,       heap );
-      AF_LOAD_ARRAY_STRUCT( af, &world->ent_glider,    ent_glider,     heap );
-      AF_LOAD_ARRAY_STRUCT( af, &world->ent_list,      ent_list,       heap );
-      AF_LOAD_ARRAY_STRUCT( af, &world->file_entity_ref, file_entity_ref, heap );
-      AF_LOAD_ARRAY_STRUCT( af, &world->ent_script, ent_script, heap );
-      AF_LOAD_ARRAY_STRUCT( af, &world->ent_event,     ent_event, heap );
-      AF_LOAD_ARRAY_STRUCT( af, &world->ent_npc,       ent_npc, heap );
-      AF_LOAD_ARRAY_STRUCT( af, &world->ent_atom,      ent_atom, heap );
-      AF_LOAD_ARRAY_STRUCT( af, &world->ent_cutscene,  ent_cutscene, heap );
+      AF_LOAD_ARRAY_STRUCT( af, &world->ent_water,     ent_water,      stack );
+      AF_LOAD_ARRAY_STRUCT( af, &world->ent_audio_clip,ent_audio_clip, stack );
+      AF_LOAD_ARRAY_STRUCT( af, &world->ent_audio,     ent_audio,      stack );
+      AF_LOAD_ARRAY_STRUCT( af, &world->ent_volume,    ent_volume,     stack );
+      AF_LOAD_ARRAY_STRUCT( af, &world->ent_traffic,   ent_traffic,    stack );
+      AF_LOAD_ARRAY_STRUCT( af, &world->ent_marker,    ent_marker,     stack );
+      AF_LOAD_ARRAY_STRUCT( af, &world->ent_skateshop, ent_skateshop,  stack );
+      AF_LOAD_ARRAY_STRUCT( af, &world->ent_swspreview,ent_swspreview, stack );
+      AF_LOAD_ARRAY_STRUCT( af, &world->ent_ccmd,      ent_ccmd,       stack );
+      AF_LOAD_ARRAY_STRUCT( af, &world->ent_objective, ent_objective,  stack );
+      AF_LOAD_ARRAY_STRUCT( af, &world->ent_challenge, ent_challenge,  stack );
+      AF_LOAD_ARRAY_STRUCT( af, &world->ent_cubemap,   ent_cubemap,    stack );
+      AF_LOAD_ARRAY_STRUCT( af, &world->ent_prop,      ent_prop,       stack );
+      AF_LOAD_ARRAY_STRUCT( af, &world->ent_glider,    ent_glider,     stack );
+      AF_LOAD_ARRAY_STRUCT( af, &world->ent_list,      ent_list,       stack );
+      AF_LOAD_ARRAY_STRUCT( af, &world->file_entity_ref, file_entity_ref, stack );
+      AF_LOAD_ARRAY_STRUCT( af, &world->ent_script, ent_script, stack );
+      AF_LOAD_ARRAY_STRUCT( af, &world->ent_event,     ent_event, stack );
+      AF_LOAD_ARRAY_STRUCT( af, &world->ent_npc,       ent_npc, stack );
+      AF_LOAD_ARRAY_STRUCT( af, &world->ent_atom,      ent_atom, stack );
+      AF_LOAD_ARRAY_STRUCT( af, &world->ent_cutscene,  ent_cutscene, stack );
    }
 
    array_file_ptr infos;
-   AF_LOAD_ARRAY_STRUCT( af, &infos, ent_worldinfo, vg_mem.scratch );
+   AF_LOAD_ARRAY_STRUCT( af, &infos, ent_worldinfo, &vg.scratch );
 
    world->skybox = k_skybox_default;
    if( af_arrcount(&infos) )
@@ -203,20 +201,19 @@ static void world_instance_load_mdl( world_instance *world, const char *path, vo
    if( load_all )
    {
       u32 bs = af_arrcount(&world->ent_route)*sizeof(struct leaderboard_cache);
-      world->leaderboard_cache = vg_linear_alloc( heap, bs );
+      world->leaderboard_cache = vg_stack_allocate( stack, bs, 8, "Leaderboards cache" );
 
       for( u32 i=0; i<af_arrcount( &world->ent_route ); i ++ )
       {
          struct leaderboard_cache *board = &world->leaderboard_cache[i];
-         board->data = vg_linear_alloc( heap, NETWORK_REQUEST_MAX );
+         board->data = vg_stack_allocate( stack, NETWORK_REQUEST_MAX, 8, NULL );
          board->status = k_request_status_client_error;
          board->cache_time = 0.0;
          board->data_len = 0;
       }
 
-      world->routes_ui = vg_linear_alloc( heap, sizeof(struct route_ui)*af_arrcount(&world->ent_route) );
-
-      ent_script_alloc( world, heap );
+      world->routes_ui = vg_stack_allocate( stack, sizeof(struct route_ui)*af_arrcount(&world->ent_route), 8, "Route UI buffer" );
+      ent_script_alloc( world, stack );
 
       vg_loader_set_user_information( "Postprocessing world" );
       vg_async_call( &vg.main_tasks, async_world_postprocess, world );
@@ -330,7 +327,7 @@ void skaterift_world_load_t1( vg_async_task *task )
       strcpy( mdl_path, "models/world_error.mdl" );
    }
 
-   world_instance_load_mdl( _world.loader_instance, mdl_path, _world.loader_heap );
+   world_instance_load_mdl( _world.loader_instance, mdl_path, _world.loader_stack );
    vg_async_call( &vg.main_tasks, async_world_loader_done, NULL );
 }
 
@@ -434,7 +431,7 @@ void world_switcher_update(void)
    if( _world.loader_state == k_world_loader_ready )
    {
       _world.loader_state = k_world_loader_loading;
-      vg_linear_clear( _world.loader_heap );
+      vg_stack_clear( _world.loader_stack );
       vg_async_task *task = vg_allocate_async_task( &vg.loader_tasks, sizeof(struct world_load_info), 1 );
       struct world_load_info *info = (void *)task->data;
       vg_str folder_str;
@@ -505,8 +502,7 @@ void skaterift_load_world_start( addon_id addon_id, bool preview )
    char uid[ADDON_UID_MAX];
    addon_make_uid( addon_id, uid );
    vg_info( "loading world: %s %s\n", uid, preview? "(preview mode)": "" );
-
-   vg_linear_clear( vg_mem.scratch ); /* ?? */
+   vg_stack_clear( &vg.scratch ); /* ?? */
 
    if( preview )
    {
@@ -528,7 +524,7 @@ void skaterift_load_world_start( addon_id addon_id, bool preview )
    }
 
    _world.loader_instance = world;
-   _world.loader_heap = preview? _world.preview_heap: _world.heap;
+   _world.loader_stack = preview? _world.preview_stack: _world.stack;
    _world.loader_preview_mode = preview;
    _world_loader_set_addon( addon_id );
 }
index b7a06a33ebd4d9c0fea9eb02ccfcfd802c54dd45..4488dcaecf8b1aef26fee3ab7800158d2447ecdb 100644 (file)
@@ -1122,11 +1122,11 @@ void world_map_gui( ui_context *ctx, ui_rect main_area, i32 mh, i32 mv, bool *al
 void world_map_init(void)
 {
    mdl_context *model = &world_map.superworld_meta;
-   mdl_open( model, "models/rs_superworlds.mdl", vg_mem.rtmemory );
-   mdl_load_metadata_block( model, vg_mem.rtmemory );
+   mdl_open( model, "models/rs_superworlds.mdl", &vg.rtmem );
+   mdl_load_metadata_block( model, &vg.rtmem );
    mdl_async_load_glmesh( model, &world_map.superworld_mesh, NULL );
-   AF_LOAD_ARRAY_STRUCT( &model->af, &world_map.ent_camera, ent_camera, vg_mem.rtmemory );
-   AF_LOAD_ARRAY_STRUCT( &model->af, &world_map.ent_marker, ent_marker, vg_mem.rtmemory );
+   AF_LOAD_ARRAY_STRUCT( &model->af, &world_map.ent_camera, ent_camera, &vg.rtmem );
+   AF_LOAD_ARRAY_STRUCT( &model->af, &world_map.ent_marker, ent_marker, &vg.rtmem );
    mdl_close( model );
 
    world_map.superworld_cam.nearz = 0.1f;
index 7a451b0c3dfa04feb1f9aa659c326c4db944b439..58ba661bd16231081771bad9b94a99bea7f12027 100644 (file)
@@ -52,11 +52,11 @@ void world_render_init(void)
    vg_console_reg_cmd( "render_portals", ccmd_render_portals, NULL );
 
    vg_info( "Loading world resources\n" );
-   vg_linear_clear( vg_mem.scratch );
+   vg_stack_clear( &vg.scratch );
 
    mdl_context msky;
-   mdl_open( &msky, "models/rs_skydome.mdl", vg_mem.scratch );
-   mdl_load_metadata_block( &msky, vg_mem.scratch );
+   mdl_open( &msky, "models/rs_skydome.mdl", &vg.scratch );
+   mdl_load_metadata_block( &msky, &vg.scratch );
    mdl_async_load_glmesh( &msky, &world_render.skydome, NULL );
    world_render.skydome_complete_mesh = msky.submeshes[ mdl_get_submesh_index( &msky, "dome_complete" ) ];
    world_render.skydome_squanched_mesh = msky.submeshes[ mdl_get_submesh_index( &msky, "dome_squanched" ) ];
@@ -69,7 +69,7 @@ void world_render_init(void)
 
    vg_info( "Allocate frame buffers\n" );
    world_instance *world = &_world.main;
-   world->heightmap = vg_framebuffer_allocate( vg_mem.rtmemory, 1, 0 );
+   world->heightmap = vg_framebuffer_allocate( &vg.rtmem, 1, 0 );
    world->heightmap->display_name = NULL;
    world->heightmap->fixed_w = 1024;
    world->heightmap->fixed_h = 1024;
index 7f0a1c940f63b6ed8fdd418d6263c2217b0484e2..9a39a9a5350a9827e2c7b825aa906cdaaae134d1 100644 (file)
@@ -311,14 +311,14 @@ void sfd_render( world_instance *world, vg_camera *cam, m4x3f transform )
 void world_sfd_init(void)
 {
    vg_info( "world_sfd_init\n" );
-   vg_linear_clear( vg_mem.scratch );
+   vg_stack_clear( &vg.scratch );
 
    mdl_context mscoreboard;
-   mdl_open( &mscoreboard, "models/rs_scoretext.mdl", vg_mem.scratch );
-   mdl_load_metadata_block( &mscoreboard, vg_mem.scratch );
+   mdl_open( &mscoreboard, "models/rs_scoretext.mdl", &vg.scratch );
+   mdl_load_metadata_block( &mscoreboard, &vg.scratch );
    mdl_async_load_glmesh( &mscoreboard, &world_sfd.mesh_base, NULL );
 
-   mdl_load_mesh_block( &mscoreboard, vg_mem.scratch );
+   mdl_load_mesh_block( &mscoreboard, &vg.scratch );
 
    scene_context *scene = &world_sfd.scene;
    vg_async_task *task = scene_alloc_async( scene, &world_sfd.mesh_display, 3000, 8000 );
@@ -353,7 +353,7 @@ void world_sfd_init(void)
 
    world_sfd.w = w;
    world_sfd.h = h;
-   world_sfd.buffer = vg_linear_alloc( vg_mem.rtmemory, 2*w*h*sizeof(float) );
+   world_sfd.buffer = vg_stack_allocate( &vg.rtmem, 2*w*h*sizeof(f32), 8, "SFD Buffer" );
 
    for( int i=0; i<w*h*2; i++ )
       world_sfd.buffer[i] = 0.0f;