getting stuff working on windows again
[vg.git] / vg_profiler.h
index 944a5bb2a02155e571b9e0b1781bf31e3bce7a7d..bfdde127af5b921840a79b66aa7c57c7367996be 100644 (file)
@@ -13,8 +13,8 @@ struct vg_profile
 {
    const char *name;
 
-   u64 samples[ VG_PROFILE_SAMPLE_COUNT ];
-   u32 buffer_count, buffer_current;
+   u64    samples[ VG_PROFILE_SAMPLE_COUNT ];
+   u32    buffer_count, buffer_current;
 
    enum profile_mode
    {
@@ -49,17 +49,16 @@ VG_STATIC void vg_profile_end( struct vg_profile *profile )
    u64 time_end = SDL_GetPerformanceCounter(),
        delta    = time_end - profile->start;
 
-   if( profile->mode == k_profile_mode_frame )
-   {
+   if( profile->mode == k_profile_mode_frame ){
       profile->samples[ profile->buffer_current ] = delta;
       vg_profile_increment( profile );
    }
-   else
-   {
+   else{
       profile->samples[ profile->buffer_current ] += delta;
    }
 }
 
+#if 0
 VG_STATIC void vg_profile_drawn( struct vg_profile **profiles, u32 count,
                               float budget, ui_rect panel, u32 colour_offset )
 {
@@ -78,11 +77,10 @@ VG_STATIC void vg_profile_drawn( struct vg_profile **profiles, u32 count,
    ui_fill_rect( panel, 0xa0000000 );
 
    assert( count <= 8 );
-   float avgs[8];
-   int   ptrs[8];
+   double avgs[8];
+   int    ptrs[8];
 
-   for( int i=0; i<count; i++ )
-   {
+   for( int i=0; i<count; i++ ){
       ptrs[i] = profiles[i]->buffer_current;
       avgs[i] = 0.0f;
    }
@@ -92,20 +90,18 @@ VG_STATIC void vg_profile_drawn( struct vg_profile **profiles, u32 count,
 
    double rate_mul = 1000.0 / (double)SDL_GetPerformanceFrequency();
 
-   for( int i=0; i<VG_PROFILE_SAMPLE_COUNT-1; i++ )
-   {
-      float total = 0.0f;
+   for( int i=0; i<VG_PROFILE_SAMPLE_COUNT-1; i++ ){
+      double total = 0.0;
 
-      for( int j=0; j<count; j++ )
-      {
+      for( int j=0; j<count; j++ ){
          ptrs[j] --;
 
          if( ptrs[j] < 0 )
             ptrs[j] = VG_PROFILE_SAMPLE_COUNT-1;
 
-         float sample  = (double)profiles[j]->samples[ptrs[j]] * rate_mul,
-               px      = (total  / (budget)) * sw,
-               wx      = (sample / (budget)) * sw;
+         double sample  = (double)profiles[j]->samples[ptrs[j]] * rate_mul,
+                px      = (total  / (budget)) * sw,
+                wx      = (sample / (budget)) * sw;
 
          ui_rect block = { panel[0] + px, panel[1] + (float)i*sh,
                            wx,            sh };
@@ -120,8 +116,14 @@ VG_STATIC void vg_profile_drawn( struct vg_profile **profiles, u32 count,
 
    char infbuf[64];
 
-   for( int i=0; i<count; i++ )
-   {
+   snprintf( infbuf, 64, "accuracy: %.7fms", rate_mul );
+   ui_text( (ui_rect){ panel[0] + 4,
+                       panel[1] + 0 * 14, 0, 0 }, 
+                       infbuf,
+                       1,
+                       k_text_align_left );
+
+   for( int i=0; i<count; i++ ){
       snprintf( infbuf, 64, "%.4fms %s", 
                         avgs[i] * (1.0f/(VG_PROFILE_SAMPLE_COUNT-1)),
                         profiles[i]->name );
@@ -133,16 +135,11 @@ VG_STATIC void vg_profile_drawn( struct vg_profile **profiles, u32 count,
                           k_text_align_left );
    }
 }
+#endif
 
 VG_STATIC void vg_profiler_init(void)
 {
-   vg_var_push( (struct vg_var){
-      .name = "vg_profiler",
-      .data = &vg_profiler,
-      .data_type = k_var_dtype_i32,
-      .opt_i32 = { .min=0, .max=1, .clamp=1 },
-      .persistent = 1
-   });
+   VG_VAR_I32( vg_profiler, flags=VG_VAR_PERSISTENT );
 }
 
 #endif /* VG_PROFILER_H */