From c7f36b24e8d8c4424d2a5164476a5562b889ae5e Mon Sep 17 00:00:00 2001 From: hgn Date: Thu, 18 May 2023 03:00:16 +0100 Subject: [PATCH] memory semantics --- vg.h | 4 ++- vg_audio.h | 74 +++++++++++++++++++++------------------------------ vg_lines.h | 2 ++ vg_mem.h | 34 ++++------------------- vg_platform.h | 15 ++++++++--- 5 files changed, 52 insertions(+), 77 deletions(-) diff --git a/vg.h b/vg.h index 62651c0..9b8c023 100644 --- a/vg.h +++ b/vg.h @@ -458,6 +458,9 @@ VG_STATIC void _vg_gameloop_render(void) } else vg_gui(); + /* vg tools */ + audio_debug_ui( vg.pv ); + ui_postrender(); #if 0 ui_begin( vg.window_x, vg.window_y ); @@ -505,7 +508,6 @@ VG_STATIC void _vg_gameloop_render(void) } /* FIXME */ - audio_debug_ui( vg.pv ); vg_gui(); ui_resolve(); diff --git a/vg_audio.h b/vg_audio.h index 120622c..67cc3f1 100644 --- a/vg_audio.h +++ b/vg_audio.h @@ -125,7 +125,8 @@ static struct vg_audio_system{ struct audio_channel{ int allocated; - u32 group; + u16 group; + u8 world_id; char name[32]; /* only editable while allocated == 0 */ audio_clip *source; /* ... */ @@ -327,6 +328,7 @@ VG_STATIC void vg_audio_free(void) static void audio_channel_init( audio_channel *ch, audio_clip *clip, u32 flags ) { ch->group = 0; + ch->world_id = 0; ch->source = clip; ch->flags = flags; ch->colour = 0x00333333; @@ -352,10 +354,15 @@ static void audio_channel_init( audio_channel *ch, audio_clip *clip, u32 flags ) ch->editble_state_write_mask = 0x00; } -static void audio_channel_group( audio_channel *ch, u32 group ) +static void audio_channel_group( audio_channel *ch, u16 group ) { ch->group = group; - ch->colour = ((group * 29986577) & 0x00ffffff) | 0xff000000; + ch->colour = (((u32)group * 29986577) & 0x00ffffff) | 0xff000000; +} + +static void audio_channel_world( audio_channel *ch, u8 world_id ) +{ + ch->world_id = world_id; } static audio_channel *audio_get_first_idle_channel(void) @@ -371,7 +378,7 @@ static audio_channel *audio_get_first_idle_channel(void) return NULL; } -static audio_channel *audio_get_group_idle_channel( u32 group, u32 max_count ) +static audio_channel *audio_get_group_idle_channel( u16 group, u32 max_count ) { u32 count = 0; audio_channel *dest = NULL; @@ -397,7 +404,7 @@ static audio_channel *audio_get_group_idle_channel( u32 group, u32 max_count ) return NULL; } -static audio_channel *audio_get_group_first_active_channel( u32 group ) +static audio_channel *audio_get_group_first_active_channel( u16 group ) { for( int i=0; iallocated ){ - ui_fill_rect( vg_uictx.cursor, 0x50333333 ); - - ui_end_down(); - vg_uictx.cursor[1] += 1; + ui_fill( row, 0x50333333 ); continue; } @@ -1345,8 +1340,9 @@ VG_STATIC void audio_debug_ui( m4x4f mtx_pv ) u32 format_index = (ch->source->flags & AUDIO_FLAG_FORMAT)>>9; - snprintf( perf, 127, "%02d %c%c%cD %s [%s] %4.2fv'%s'", + snprintf( perf, 127, "%02d[%#04x.%#06x]%c%c%cD %s [%s] %4.2fv'%s'", i, + ch->world_id, ch->group, (ch->editable_state.relinquished)? 'r': '_', 0? 'r': '_', 0? '3': '2', @@ -1355,14 +1351,8 @@ VG_STATIC void audio_debug_ui( m4x4f mtx_pv ) ch->editable_state.volume, ch->name ); - ui_fill_rect( vg_uictx.cursor, 0xa0000000 | ch->colour ); - - vg_uictx.cursor[0] += 2; - vg_uictx.cursor[1] += 2; - ui_text( vg_uictx.cursor, perf, 1, 0 ); - - ui_end_down(); - vg_uictx.cursor[1] += 1; + ui_fill( row, 0xa0000000 | ch->colour ); + ui_text( row, perf, 1, k_ui_align_middle_left, 0 ); if( AUDIO_FLAG_SPACIAL_3D ){ v4f wpos; @@ -1378,7 +1368,7 @@ VG_STATIC void audio_debug_ui( m4x4f mtx_pv ) ui_rect wr; wr[0] = vg_clampf(wpos[0] * vg.window_x, -32000.0f,32000.0f); wr[1] = vg_clampf((1.0f-wpos[1]) * vg.window_y,-32000.0f,32000.0f); - wr[2] = 100; + wr[2] = 1000; wr[3] = 17; for( int j=0; j<12; j++ ){ @@ -1399,13 +1389,11 @@ VG_STATIC void audio_debug_ui( m4x4f mtx_pv ) wr[1] += 18; } - ui_text( wr, perf, 1, 0 ); - - ui_rect_copy( wr, overlap_buffer[ overlap_length ++ ] ); + ui_text( wr, perf, 1, k_ui_align_middle_left, 0 ); + rect_copy( wr, overlap_buffer[ overlap_length ++ ] ); } } } -#endif audio_unlock(); } diff --git a/vg_lines.h b/vg_lines.h index 4a77502..5c88d9b 100644 --- a/vg_lines.h +++ b/vg_lines.h @@ -149,6 +149,8 @@ VG_STATIC void vg_line2( line_co from, line_co to, u32 fc, u32 tc ) if( !vg_lines.allow_input ) return; + return; + u32 size = 2 * sizeof(struct vg_lines_vert); struct vg_lines_vert *v = vg_linear_alloc( vg_lines.vertex_buffer, size ); diff --git a/vg_mem.h b/vg_mem.h index 598bc83..49ab3e3 100644 --- a/vg_mem.h +++ b/vg_mem.h @@ -49,37 +49,12 @@ struct vg_allocation_meta struct vg_linear_allocator { u32 size; - /* */ - /* */ - /* */ u32 cur; - /* */ - /* */ - /* */ u16 allocation_count; - /* */ u16 flags; - /* */ u32 last_alloc_size; - /* */ - /* */ - /* */ void *last_alloc; - /* */ - /* */ - /* */ - /* */ - /* */ - /* */ - /* */ vg_allocation_meta *alloc_table; - /* */ - /* */ - /* */ - /* */ - /* */ - /* */ - /* */ #ifdef _WIN32 /* 32 bit pointers! */ @@ -216,8 +191,10 @@ VG_STATIC void vg_linear_del( void *buffer, void *data ) { vg_linear_allocator *alloc = vg_linear_header( buffer ); - if( alloc->last_alloc != data ) - vg_fatal_error( "This block has been fixed!" ); + if( alloc->last_alloc != data ){ + vg_fatal_error( "This block has been fixed! Last alloc: %p, this: %p\n", + alloc->last_alloc, data ); + } if( vg_mem.use_libc_malloc && (alloc->flags & VG_MEMORY_SYSTEM) ){ vg_allocation_meta *meta = &alloc->alloc_table[alloc->allocation_count-1]; @@ -339,9 +316,8 @@ VG_STATIC void *vg_create_linear_allocator( void *lin_alloc, u32 size, } alloc->cur += block_size; - alloc->last_alloc = NULL; /* cant resize this block! */ + alloc->last_alloc = header; alloc->last_alloc_size = block_size; - alloc->allocation_count ++; } else{ diff --git a/vg_platform.h b/vg_platform.h index c7e178b..98baef8 100644 --- a/vg_platform.h +++ b/vg_platform.h @@ -41,9 +41,11 @@ struct vg_achievement enum strncpy_behaviour{ k_strncpy_always_add_null = 0, - k_strncpy_allow_cutoff = 1 + k_strncpy_allow_cutoff = 1, + k_strncpy_overflow_fatal = 2 }; +VG_STATIC void vg_fatal_error( const char *fmt, ... ); VG_STATIC u32 vg_strncpy( const char *src, char *dst, u32 len, enum strncpy_behaviour behaviour ) { @@ -52,9 +54,14 @@ VG_STATIC u32 vg_strncpy( const char *src, char *dst, u32 len, if( !src[i] ) return i; - if( (behaviour == k_strncpy_always_add_null) && (i == len-1) ){ - dst[i] = '\0'; - return i; + if( i == len-1 ){ + if( behaviour == k_strncpy_always_add_null ){ + dst[i] = '\0'; + return i; + } + else if( behaviour == k_strncpy_overflow_fatal ){ + vg_fatal_error( "Strncpy dest exceeded buffer length\n" ); + } } } -- 2.25.1