-Subproject commit 6ed8d054340ee8a93a684e11360b66cd8a5c168e
+Subproject commit c5b4df0e1061175cb11e3ebbf8045178339864a5
-Subproject commit 44e971c774d9ec67ca6c1f16c5a476724821ab63
+Subproject commit eb5332d0b5e48d58397e6f27475a18e058330d23
-Subproject commit b8d77df1e80b652a57f0b7270449b179a6b91f40
+Subproject commit dfc056e813c98d307238d35f7f041a725d699dfc
-Subproject commit 8b5f1f37b5b75829fc72d38e7b5d4bcbf8a26d55
+Subproject commit 5736b15f7ea0ffb08dd38af21067c314d6a3aae9
#include "vg_platform.h"
#include "vg_mem.h"
-
- #ifndef _WIN32
- #include <execinfo.h>
- #endif
-
-VG_STATIC void vg_print_backtrace(void)
-{
-#ifndef _WIN32
-
- void *array[20];
- char **strings;
- int size, i;
-
- size = backtrace( array, 20 );
- strings = backtrace_symbols( array, size );
-
- if( strings != NULL ){
- vg_error( "---------------- gnu backtrace -------------\n" );
-
- for( int i=0; i<size; i++ )
- vg_info( "%s\n", strings[i] );
-
- vg_error( "---------------- gnu backtrace -------------\n" );
- }
-
- free( strings );
-
-#endif
-}
#ifdef VG_GAME
#include "dep/glad/glad.h"
}
}
+VG_STATIC void vg_assert_thread( enum vg_thread_purpose required ){
+ enum vg_thread_purpose purpose = vg_thread_purpose();
+
+ if( purpose != required ){
+ vg_fatal_error( "thread_purpose must be %u not %u\n", required, purpose );
+ }
+}
+
VG_STATIC void _vg_opengl_sync_init(void)
{
vg.sem_loader = SDL_CreateSemaphore(1);
{
va_list args;
va_start( args, fmt );
- _vg_log_write( stderr, KRED " fatal" KWHT "| " KRED, fmt, args );
+ _vg_logx_va( stderr, NULL, "fatal", KRED, fmt, args );
va_end( args );
vg_print_backtrace();
{
va_list args;
va_start( args, fmt );
- _vg_log_write( stderr, KRED " fatal" KWHT "| " KRED, fmt, args );
+ _vg_logx_va( stderr, NULL, "fatal", KRED, fmt, args );
va_end( args );
exit(0);
}
u32 NvOptimusEnablement = 0x00000001;
int AmdPowerXpressRequestHighPerformance = 1;
+#include "vg_log.c"
+
#endif /* VG_HEADER_H */
SDL_AtomicLock( &log_print_sl );
- int ptr = vg_log.buffer_line_current;
+ int ptr = vg_log.log_line_current;
int const fh = 14, log_lines = 32;
- int console_lines = VG_MIN( log_lines, vg_log.buffer_line_count );
+ int console_lines = VG_MIN( log_lines, vg_log.log_line_count );
ui_rect rect_log = { 0, 0, vg.window_x, log_lines*fh },
rect_input = { 0, log_lines*fh + 1, vg.window_x, fh*2 },
for( int i=0; i<console_lines; i ++ ){
ptr --;
- if( ptr < 0 ) ptr = vg_list_size( vg_log.buffer )-1;
+ if( ptr < 0 ) ptr = vg_list_size( vg_log.log )-1;
- ui_text( rect_line, vg_log.buffer[ptr], 1, k_ui_align_left, 0 );
+ ui_text( rect_line, vg_log.log[ptr], 1, k_ui_align_left, 0 );
rect_line[1] -= fh;
}
--- /dev/null
+#ifndef VG_LOG_C
+#include <stdarg.h>
+#include <string.h>
+#include <malloc.h>
+#include "vg_stdint.h"
+#include "vg_platform.h"
+#include "vg_log.h"
+
+#ifndef _WIN32
+ #include <execinfo.h>
+#endif
+
+static void _vg_log_append_line( const char *str ){
+ if( vg_log.log_line_count < vg_list_size( vg_log.log ) )
+ vg_log.log_line_count ++;
+
+ char *dest = vg_log.log[ vg_log.log_line_current ++ ];
+ vg_strncpy( str, dest, vg_list_size(vg_log.log[0]), k_strncpy_allow_cutoff );
+
+ if( vg_log.log_line_current >= vg_list_size( vg_log.log ) )
+ vg_log.log_line_current = 0;
+}
+
+static void _vg_logx_va( FILE *file,
+ const char *location, const char *prefix,
+ const char *colour,
+ const char *fmt, va_list args )
+{
+
+ /* @model.h:2000 info| dwahjdiawdjaiwdwadwa djaidjwa\n
+ * | djwaidwaj waodawh a\n
+ * | dwajdkiawjdiw
+ */
+
+#ifdef VG_GAME
+ SDL_AtomicLock( &log_print_sl );
+#endif
+
+ char buffer[4096];
+
+ vsnprintf( buffer, vg_list_size(buffer), fmt, args );
+
+ const char *line = buffer;
+ char logline[96];
+
+ for( u32 i=0; i<vg_list_size(buffer); i++ ){
+ char c = buffer[i];
+
+ if( c == '\0' || c == '\n' ){
+ buffer[i] = '\0';
+
+ const char *line_prefix = "",
+ *line_location = "";
+
+ if( line == buffer ) {
+ line_prefix = prefix;
+ line_location = location;
+ }
+
+ snprintf( logline, 96, "%s%7s" KNRM "|%s %s",
+ colour, line_prefix, colour, line );
+ _vg_log_append_line( logline );
+
+ if( location ){
+#ifdef VG_GAME
+ const char *thread_colours[] = {
+ KGRN, KMAG, KCYN, KYEL, KBLU
+ };
+
+ const char *colour = thread_colours[
+ (vg_thread_purpose() % vg_list_size( thread_colours ))];
+
+ fprintf( file, "%s[%u]"KNRM"%.32s",
+ colour, vg_thread_purpose(), line_location );
+#else
+ fprintf( file, KNRM "%.32s", line_location );
+#endif
+ }
+
+ fputs( logline, file );
+ fputc( '\n', file );
+ fputs( KNRM, file );
+
+ if( c == '\0' ) break;
+ if( buffer[i+1] == '\0' ) break;
+ line = buffer+i+1;
+ }
+ }
+
+#ifdef VG_GAME
+ SDL_AtomicUnlock( &log_print_sl );
+#endif
+}
+
+static void vg_logx( FILE *file,
+ const char *location, const char *prefix,
+ const char *colour,
+ const char *fmt, ... ){
+
+ va_list args;
+ va_start( args, fmt );
+ _vg_logx_va( file,
+#ifdef VG_LOG_SOURCE_INFO
+ location,
+#else
+ NULL,
+#endif
+ prefix, colour, fmt, args );
+ va_end( args );
+}
+
+static void vg_print_backtrace(void){
+#ifndef _WIN32
+
+ void *array[20];
+ char **strings;
+ int size, i;
+
+ size = backtrace( array, 20 );
+ strings = backtrace_symbols( array, size );
+
+ if( strings != NULL ){
+ vg_error( "---------------- gnu backtrace -------------\n" );
+
+ for( int i=0; i<size; i++ )
+ vg_info( "%s\n", strings[i] );
+
+ vg_error( "---------------- gnu backtrace -------------\n" );
+ }
+
+ free( strings );
+
+#endif
+}
+
+#endif /* VG_LOG_C */
#ifndef VG_LOG_H
#define VG_LOG_H
-#include <stdarg.h>
-#include <string.h>
-#include <malloc.h>
-#include "vg_stdint.h"
-#include "vg_platform.h"
+#define VG_LOG_MCSTR(S) VG_LOG_MCSTR2(S)
+#define VG_LOG_MCSTR2(S) #S
+#define VG_LOG_WHERE "@"__FILE__":"VG_LOG_MCSTR(__LINE__)\
+ " "
+
+#define vg_success( ... ) \
+ vg_logx(stdout,VG_LOG_WHERE,"success",KGRN,__VA_ARGS__)
+#define vg_info( ... ) \
+ vg_logx(stdout,VG_LOG_WHERE,"info",KWHT,__VA_ARGS__)
+#define vg_warn( ... ) \
+ vg_logx(stdout,VG_LOG_WHERE,"warn",KYEL,__VA_ARGS__ )
+#define vg_error( ... ) \
+ vg_logx(stdout,VG_LOG_WHERE,"error",KRED,__VA_ARGS__)
+#define vg_low( ... ) \
+ vg_logx(stdout,VG_LOG_WHERE,"log",KWHT,__VA_ARGS__)
-#ifdef _WIN32
-#define KNRM ""
-#define KBLK ""
-#define KRED ""
-#define KGRN ""
-#define KYEL ""
-#define KBLU ""
-#define KMAG ""
-#define KCYN ""
-#define KWHT ""
-#else
#define KNRM "\x1B[0m"
#define KBLK "\x1B[30m"
#define KRED "\x1B[31m"
#define KMAG "\x1B[35m"
#define KCYN "\x1B[36m"
#define KWHT "\x1B[37m"
-#endif
#define PRINTF_v2f( V2 ) "%.4f %.4f\n", V2[0], V2[1]
#define PRINTF_v3f( V3 ) "%.4f %.4f %.4f\n", V3[0], V3[1], V3[2]
#endif
#ifdef VG_GAME
-static SDL_SpinLock log_print_sl;
+ #include "dep/sdl/include/SDL.h"
+ static SDL_SpinLock log_print_sl;
#endif
-struct vg_log
-{
- char buffer[64][96];
- u32 buffer_line_count, buffer_line_current;
+struct vg_log{
+ char log[64][96];
+ u32 log_line_count, log_line_current;
}
static vg_log;
-void _vg_console_append_to_log( const char *str )
-{
- if( vg_log.buffer_line_count < vg_list_size( vg_log.buffer ) )
- vg_log.buffer_line_count ++;
+static void vg_logx( FILE *file,
+ const char *location, const char *prefix,
+ const char *colour,
+ const char *fmt, ... );
- char *dest = vg_log.buffer[ vg_log.buffer_line_current ++ ];
+static void _vg_logx_va( FILE *file,
+ const char *location, const char *prefix,
+ const char *colour,
+ const char *fmt, va_list args );
- for( int i=0; i<vg_list_size( vg_log.buffer[0] ); i++ ){
- if( !str[i] || ( i == vg_list_size(vg_log.buffer[0])-1 ) ){
- dest[i] = '\0';
- break;
- }
+static void vg_print_backtrace(void);
- dest[i] = str[i];
- }
-
- if( vg_log.buffer_line_current >= vg_list_size( vg_log.buffer ) )
- vg_log.buffer_line_current = 0;
-}
-
-VG_STATIC void _vg_log_write( FILE *file, const char *prefix,
- const char *fmt, va_list args )
-{
-#ifdef VG_GAME
- SDL_AtomicLock( &log_print_sl );
-#endif
- char buffer[ 4096 ];
- int i, j;
-
- for( i=0; i<vg_list_size( buffer ); i ++ ){
- if( prefix[i] )
- buffer[i] = prefix[i];
- else
- break;
- }
-
- j = i + vsnprintf( buffer + i, vg_list_size( buffer ) - i -12, fmt, args );
- strcpy( buffer + j, KNRM );
-
- fputs( buffer, file );
-
- _vg_console_append_to_log( buffer );
-#ifdef VG_GAME
- SDL_AtomicUnlock( &log_print_sl );
#endif
-}
-
-#define VG_LOGX( NAME, PIPE, PFX ) \
-VG_STATIC void NAME(const char *fmt, ...) \
-{ \
- va_list args; \
- va_start( args, fmt ); \
- _vg_log_write( PIPE, (PFX), fmt, args ); \
- va_end( args ); \
-}
-
-VG_LOGX( vg_success, stdout, (KGRN "success" KWHT "| " KGRN) )
-VG_LOGX( vg_info, stdout, (KNRM " info" KWHT "| " KNRM) )
-VG_LOGX( vg_warn, stdout, (KYEL " warn" KWHT "| " KYEL) )
-VG_LOGX( vg_error, stderr, (KRED " error" KWHT "| " KRED) )
-VG_LOGX( vg_low, stdout, (KWHT " log" KWHT "| " KWHT) )
-
-#endif /* VG_LOG_H */
#include "vg.h"
#include "vg_stdint.h"
#include "vg_platform.h"
+#include "vg_log.h"
#include <stdlib.h>
#include <malloc.h>
*/
VG_STATIC void vg_fatal_error( const char *fmt, ... );
+
+#if 0
VG_STATIC void vg_error(const char *fmt, ...);
VG_STATIC void vg_info(const char *fmt, ...);
+#endif
VG_STATIC u32 vg_align8( u32 s )
{
#ifndef VG_MEM_POOL_H
#define VG_MEM_POOL_H
-/* pool for loaded addons */
-#define VG_POOL_NIL 0xffff
+#include "vg/vg_mem.h"
+#include "stddef.h"
+#include "vg/vg_stdint.h"
typedef struct vg_pool vg_pool;
typedef struct vg_pool_node vg_pool_node;
size_t stride, offset;
};
-static vg_pool_node *vg_pool_nodeptr ( vg_pool *pool, void *item );
-static void *vg_pool_item ( vg_pool *pool, u16 index );
+static vg_pool_node *vg_pool_nodeptr ( vg_pool *pool, u16 id );
+static void *vg_pool_item ( vg_pool *pool, u16 id );
static void vg_pool_init ( vg_pool *pool );
-static u16 addon_item_index ( vg_pool *pool, void *item );
-static void *vg_pool_lru ( vg_pool *pool );
-static void vg_pool_watch ( vg_pool *pool, void *item );
-static void vg_pool_unwatch ( vg_pool *pool, void *item );
+static u16 vg_pool_id ( vg_pool *pool, void *item );
+static u16 vg_pool_lru ( vg_pool *pool );
+static void vg_pool_watch ( vg_pool *pool, u16 id );
+static void vg_pool_unwatch ( vg_pool *pool, u16 id );
/* implementation
* -------------------------------------------------------------------------- */
-static vg_pool_node *vg_pool_nodeptr( vg_pool *pool, void *item ){
- if( !item ) return NULL;
- else return item + pool->offset;
+static vg_pool_node *vg_pool_nodeptr( vg_pool *pool, u16 id ){
+ if( !id ) return NULL;
+ else {
+ return pool->buffer + (pool->stride*(id-1)) + pool->offset;
+ }
}
-static void *vg_pool_item( vg_pool *pool, u16 index ){
- if( index == VG_POOL_NIL ) return NULL;
- else return pool->buffer + pool->stride*(size_t)index;
+static void *vg_pool_item( vg_pool *pool, u16 id ){
+ if( !id ) return NULL;
+ else return pool->buffer + pool->stride*(size_t)(id-1);
}
static void vg_pool_init( vg_pool *pool ){
- pool->head = 0;
- pool->tail = pool->count -1;
- for( i32 ib=0; ib < pool->count; ib++ ){
- void *vb = vg_pool_item( pool, ib );
- vg_pool_node *nb = vg_pool_nodeptr( pool, vb );
-
- i32 ia = ib-1, ic = ib+1;
- nb->l = ia>=0? ia: VG_POOL_NIL,
- nb->r = ic<pool->count? ic: VG_POOL_NIL;
+ pool->head = 1;
+ pool->tail = pool->count;
+ for( u16 ib=1; ib <= pool->count; ib++ ){
+ vg_pool_node *nb = vg_pool_nodeptr( pool, ib );
+
+ u16 ia = ib-1, ic = ib+1;
+ nb->l = ia;
+ nb->r = ic<=pool->count? ic: 0;
nb->ref_count = 0;
}
}
-static u16 addon_item_index( vg_pool *pool, void *item ){
- return (item - pool->buffer) / pool->stride;
+static u16 vg_pool_id( vg_pool *pool, void *item ){
+ return ((item - pool->buffer) / pool->stride) + 1;
}
-static void *vg_pool_lru( vg_pool *pool ){
- u16 head = pool->head;
- if( head == VG_POOL_NIL ) return NULL;
+static void vg_pool_unlink( vg_pool *pool, u16 id ){
+ vg_pool_node *node = vg_pool_nodeptr( pool, id );
+ vg_pool_node *l = vg_pool_nodeptr( pool, node->l ),
+ *r = vg_pool_nodeptr( pool, node->r );
- void *item = vg_pool_item( pool, head );
- vg_pool_node *node = vg_pool_nodeptr( pool, item );
+ if( pool->head == id ) pool->head = node->r;
+ if( pool->tail == id ) pool->tail = node->l;
+
+ if( l ) l->r = node->r;
+ if( r ) r->l = node->l;
+
+ node->r = 0;
+ node->l = 0;
+}
- if( pool->head == pool->tail ) pool->tail = VG_POOL_NIL;
- pool->head = node->r;
+static u16 vg_pool_lru( vg_pool *pool ){
+ u16 head = pool->head;
+ if( !head ) return 0;
- node->l = VG_POOL_NIL;
- node->r = VG_POOL_NIL;
- return item;
+ vg_pool_unlink( pool, head );
+ return head;
}
-static void vg_pool_watch( vg_pool *pool, void *item ){
- vg_pool_node *node = vg_pool_nodeptr( pool, item );
+static void vg_pool_watch( vg_pool *pool, u16 id ){
+ vg_pool_node *node = vg_pool_nodeptr( pool, id );
+
+ if( !node->ref_count ){
+ vg_pool_unlink( pool, id );
+ }
if( node->ref_count >= 128 )
vg_fatal_error( "pool watch missmatch (limit is 128)\n" );
}
/* if after this no more watches, places back into the volatile list */
-static void vg_pool_unwatch( vg_pool *pool, void *item ){
- vg_pool_node *node = vg_pool_nodeptr( pool, item );
+static void vg_pool_unwatch( vg_pool *pool, u16 id ){
+ vg_pool_node *node = vg_pool_nodeptr( pool, id );
if( node->ref_count == 0 )
vg_fatal_error( "pool unwatch missmatch (no watchers)\n" );
node->ref_count --;
if( !node->ref_count ){
- void *item_head = vg_pool_item( pool, pool->head ),
- *item_tail = vg_pool_item( pool, pool->tail );
- vg_pool_node *head = vg_pool_nodeptr( pool, item_head ),
- *tail = vg_pool_nodeptr( pool, item_tail );
+ vg_pool_node *head = vg_pool_nodeptr( pool, pool->head ),
+ *tail = vg_pool_nodeptr( pool, pool->tail );
- u16 index = addon_item_index( pool, item );
- if( tail ) tail->r = index;
+ if( tail ) tail->r = id;
node->l = pool->tail;
- pool->tail = index;
- if( !head ) pool->head = index;
+ pool->tail = id;
+ if( !head ) pool->head = id;
}
}