simplify
authorhgn <hgodden00@gmail.com>
Mon, 24 Apr 2023 12:00:24 +0000 (13:00 +0100)
committerhgn <hgodden00@gmail.com>
Mon, 24 Apr 2023 12:00:24 +0000 (13:00 +0100)
vg.h
vg_async.h
vg_audio_dsp.h
vg_input.h
vg_lines.h

diff --git a/vg.h b/vg.h
index 9ad04b1f659ca600fc9529fcd3399ef9f9dfea0b..d98828e3bd380b2f9d041436e2dc29045110487f 100644 (file)
--- a/vg.h
+++ b/vg.h
@@ -282,9 +282,7 @@ VG_STATIC void async_vg_bake_shaders( void *payload, u32 size )
 VG_STATIC void vg_bake_shaders(void)
 {
    vg_console_reg_cmd( "reload_shaders", vg_shaders_live_recompile, NULL );
-
-   vg_async_item *call = vg_async_alloc(0);
-   vg_async_dispatch( call, async_vg_bake_shaders );
+   vg_async_call( async_vg_bake_shaders, NULL, 0 );
 }
 
 void async_internal_complete( void *payload, u32 size )
@@ -313,8 +311,7 @@ VG_STATIC void _vg_load_full(void)
    vg_loader_step( vg_audio_init, vg_audio_free );
    vg_loader_step( vg_profiler_init, NULL );
 
-   vg_async_item *test_async = vg_async_alloc( 0 );
-   vg_async_dispatch( test_async, async_internal_complete );
+   vg_async_call( async_internal_complete, NULL, 0 );
 
    /* client */
    vg_load();
index 190b5a8271552ae1dae6ff71646a45febca94b82..fd65c0db77ba3484882aa066866d01e21b8c14fe 100644 (file)
@@ -98,6 +98,9 @@ VG_STATIC vg_async_item *vg_async_alloc( u32 size )
    return entry;
 }
 
+/*
+ * Wait until the current stack of async calls is completely flushed out 
+ */
 VG_STATIC void vg_async_stall(void)
 {
    vg_info( "async_stall: %d\n", SDL_SemValue( vg_async.sem_wait_for_flush ) );
@@ -118,6 +121,18 @@ VG_STATIC void vg_async_dispatch( vg_async_item *item,
    SDL_AtomicUnlock( &vg_async.sl_index );
 }
 
+/*
+ * Make a simple async call without allocating extra.
+ */
+VG_STATIC void vg_async_call( void (*runner)( void *payload, u32 size ), 
+                              void *payload, u32 size )
+{
+   vg_async_item *call = vg_async_alloc(0);
+   call->payload = payload;
+   call->size = size;
+   vg_async_dispatch( call, runner );
+}
+
 /*
  * Run as much of the async buffer as possible
  */
index e6a953ec5cae6e7c8acd6f356388d27b3e46aac3..c973cc9a865daa8c4238e5b00ee4ad780ae71392 100644 (file)
@@ -154,8 +154,7 @@ static void vg_dsp_init( void )
    vg_dsp.buffer = vg_linear_alloc( vg_mem.rtmemory, 1024*1024*1 );
    vg_dsp.view_texture_buffer = vg_linear_alloc( vg_mem.rtmemory, 512*512 );
 
-   vg_async_item *call = vg_async_alloc(0);
-   vg_async_dispatch( call, async_vg_dsp_alloc_texture );
+   vg_async_call( async_vg_dsp_alloc_texture, NULL, 0 );
 
    /* temporary global design */
    dsp_init_lpf( &__lpf_mud_free, 125.0f );
index 778d6f09c2ec8455e35c9fa1aad5fe775fce8a53..02c271a1ca85b0b88f829cbc8a33264ad57855c6 100644 (file)
@@ -589,8 +589,7 @@ VG_STATIC void async_vg_input_init( void *payload, u32 size )
 
 VG_STATIC void vg_input_init(void)
 {
-   vg_async_item *call = vg_async_alloc(0);
-   vg_async_dispatch( call, async_vg_input_init );
+   vg_async_call( async_vg_input_init, NULL, 0 );
 }
 
 VG_STATIC void vg_input_free(void)
index 84e9632d9a90f863839e2f9c5a6c9359a0d94dd9..58818f25510f683103c0296f112cf0bfff4ef648 100644 (file)
@@ -113,8 +113,7 @@ VG_STATIC void async_vg_lines_init( void *payload, u32 payload_size )
 
 VG_STATIC void vg_lines_init(void)
 {
-   vg_async_item *call = vg_async_alloc(0);
-   vg_async_dispatch( call, async_vg_lines_init );
+   vg_async_call( async_vg_lines_init, NULL, 0 );
 
    vg_console_reg_var( "vg_lines", &vg_lines.draw, k_var_dtype_i32, 
                        VG_VAR_CHEAT );