imgui revision
[vg.git] / vg_loader.h
index 3c519b57137bc99d19707c80b07c421e1c178079..62fbe21192726c0b0084ae461356baa71ff72dd2 100644 (file)
 #ifndef VG_LOADER_H
 #define VG_LOADER_H
 
-#include "common.h"
+#define VG_GAME
+#include "vg/vg.h"
+#include "vg/vg_shader.h"
 
-VG_STATIC void vg_loader_start( void(*pfn)(void) );
+VG_STATIC void vg_loader_start( void(*pfn)(void *data), void *data );
 VG_STATIC void vg_loader_step( void( *fn_load )(void), void( *fn_free )(void) );
 
 static struct vg_shader _shader_loader = 
@@ -59,7 +61,6 @@ static struct vg_shader _shader_loader =
       
       "void main()"
       "{"
-
          "vec3 col = 0.5+0.5*sin( uTime + aUv.xyx + vec3(0.0,2.0,4.0) );"
          
          "vec2 uvx = aUv - vec2( 0.5 );"
@@ -79,8 +80,7 @@ static struct vg_shader _shader_loader =
 static struct vg_loader
 {
    /* Shutdown steps */
-   struct loader_free_step
-   {
+   struct loader_free_step{
       void (*fn_free)(void);
    }
    step_buffer[16];
@@ -184,21 +184,20 @@ VG_STATIC void _vg_loader_render(void)
    glClear( GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT );
 
    _vg_render_log();
-   vg.loader_ring = 0.8f;
+   vg.loader_ring = 1.0f;
 }
 
 
 VG_STATIC void vg_load_full(void);
 
-VG_STATIC int _vg_loader_thread(void *pfn)
-{
+VG_STATIC int _vg_loader_thread( void *pfn ){
    if( setjmp( vg.env_loader_exit ) )
       return 0;
 
    /* Run client loader */
    vg_info( "Starting client loader thread @%p\n", pfn );
-   void (*call_func)(void) = pfn;
-   call_func();
+   void (*call_func)(void *data) = pfn;
+   call_func( vg.thread_data );
 
    SDL_SemPost( vg.sem_loader );
    vg.thread_id_loader = 0;
@@ -206,9 +205,20 @@ VG_STATIC int _vg_loader_thread(void *pfn)
    return 0;
 }
 
-VG_STATIC void vg_loader_start( void(*pfn)(void) )
+static int vg_loader_availible(void){
+   if( SDL_SemValue( vg.sem_loader ) ){
+      if( !(vg_async.start) )
+         return 1;
+   }
+
+   return 0;
+}
+
+VG_STATIC void vg_loader_start( void(*pfn)(void *data), void *data )
 {
    SDL_SemWait( vg.sem_loader );
+
+   vg.thread_data = data;
    SDL_CreateThread( _vg_loader_thread, "Loader thread", pfn );
 }