revised model loading order
[csRadar.git] / csRadar.c
index 2bde6027f01b26565f53b92a57d957aeb061f202..e68237c5f46edf4d3220f2c8dac68506c01c2852 100644 (file)
--- a/csRadar.c
+++ b/csRadar.c
@@ -4,8 +4,10 @@
 #include <string.h>
 #include <math.h>
 #include <time.h>
+#include <stdarg.h>
 
 // CSR lib
+#include "csrLog.h"
 #include "csrOpt.h"
 #include "csrTypes.h"
 #include "csrMath.h"
@@ -43,6 +45,7 @@ int main( int argc, char *argv[] )
        char output_path[ 512 ];                // Full path eg. /home/harry/my_map.vmf
        char vmf_name[ 128 ];                   // Just the base name eg. my_map
        int output_set = 0;
+       EMSAA sampling_mode = k_EMSAA_RGSS;
 
        while( csr_argp( argc, argv ) )
        {
@@ -50,9 +53,8 @@ int main( int argc, char *argv[] )
                {
                        if( num_strings == 20 )
                        {
-                               fprintf( stderr, "Too many arguments! Max 20\n" );
-                               fs_exit();
-                               exit(0);
+                               log_error( "Too many arguments! Max 20\n" );
+                               goto IL_CSR_EXIT;
                        }
                        
                        strings[ num_strings ++ ] = arg;
@@ -80,11 +82,36 @@ int main( int argc, char *argv[] )
                {
                        padding = atof( arg );
                }
+               
+               if( (arg = csr_long_opt_arg( "multi-sample" )) )
+               {
+                       if( !strcmp( arg, "none" ))
+                       {
+                               sampling_mode = k_EMSAA_none;
+                       }
+                       else if( !strcmp( arg, "rgss" ))
+                       {
+                               sampling_mode = k_EMSAA_RGSS;
+                       }
+                       else if( !strcmp( arg, "2x" ))
+                       {
+                               sampling_mode = k_EMSAA_2x2;
+                       }
+                       else if( !strcmp( arg, "8r" ))
+                       {
+                               sampling_mode = k_EMSAA_8R;
+                       }
+                       else
+                       {
+                               log_error( "Invalid sampling pattern '%s'\n", arg );
+                               goto IL_CSR_EXIT;
+                       }
+               }
 
                if( csr_opt( 'v' ) || csr_long_opt( "version" ) )
                {
                        printf( "csRadar version: " CSR_VERSION "\n" );
-                       return 0;
+                       goto IL_CSR_EXIT;
                }
                
                if( csr_opt( 'h' ) || csr_long_opt( "help" ) )
@@ -104,21 +131,22 @@ int main( int argc, char *argv[] )
                                "   -r 1024                        Output resolution\n"
                                "   -o <output>                    Specify output name/path\n"
                                "   --padding=128                  When cropping radar, add padding units to border\n"
-                               "   --standard-layers              Use standard TAR layers/groups\n"
+                               //"   --standard-layers              Use standard TAR layers/groups\n"
                                "   --no-txt                       Don't create matching radar txt\n"
-                               "   --multi-sample=                [ none, 2, 4, 4r, 8kn (default), 16c ]\n"
+                               "   --multi-sample=RGSS            [ none, 2x, rgss, 8r ]\n"
+                               "   --extension=TAR                Use an extension binary instead\n"
                                "\n"
                                "   -v --version                   Display program version\n"
                                "   -h --help                      Display this help text\n"
                        );
                        
-                       return 0;
+                       goto IL_CSR_EXIT;
                }
        }
        
        if( num_strings )
        {
-               vmf_map *map = vmf_init( strings[0], 1 );
+               vmf_map *map = vmf_init( strings[0] );
        
                if( map )
                {
@@ -137,16 +165,17 @@ int main( int argc, char *argv[] )
                        
                        strcpy( vmf_name, base_name );
                        
-                       printf( "output_path: '%s'\nvmf_name: '%s'\n", output_path, vmf_name );
-                       
+                       log_info( "output_path: '%s'\n", output_path );
+                       log_info( "vmf_name: '%s'\n", vmf_name );
                        
-                       // Main
-                                       
+                       // Main                 
                        csr_target target;
                        
-                       csr_create_target( &target, resolution, resolution );
+                       csr_create_target( &target, resolution, resolution, sampling_mode );
                        csr_rt_clear( &target );
                        
+                       csr_use_program( &target, frag_gbuffer );
+                       
                        // Compute bounds
                        csr_filter filter = 
                        {
@@ -154,27 +183,35 @@ int main( int argc, char *argv[] )
                                .visgroup = NULL,
                                .compute_bounds_only = 1
                        };
-                       draw_vmf_group( &target, map, map->root, &filter, NULL, NULL );
-                       csr_auto_fit( &target, padding );
-                       filter.compute_bounds_only = 0;
                        
-                       if( num_strings == 1 )
-                       {
-                               // Draw everything
-                               draw_vmf_group( &target, map, map->root, NULL, NULL, NULL );
-                               csr_rt_save_buffers( &target, output_path, "all" );
-                       }
-                       else
+                       // One pass for fitting, second pass for drawing
+                       for( int i = 0; i < 2; i ++ )
                        {
-                               // Draw groups
-                               for( int i = 1; i < num_strings; i ++ )
+                               if( num_strings == 1 )
                                {
-                                       filter.visgroup = strings[ i ];
-                                       
-                                       draw_vmf_group( &target, map, map->root, NULL, NULL, NULL );
-                                       csr_rt_save_buffers( &target, output_path, strings[i] );
-                                       
-                                       csr_rt_clear( &target );
+                                       // Draw everything
+                                       draw_vmf_group( &target, map, map->root, &filter, NULL, NULL );
+                                       csr_rt_save_buffers( &target, output_path, "all" );
+                               }
+                               else
+                               {
+                                       // Draw groups
+                                       for( int i = 1; i < num_strings; i ++ )
+                                       {
+                                               filter.visgroup = strings[ i ];
+                                               
+                                               draw_vmf_group( &target, map, map->root, &filter, NULL, NULL );
+                                               csr_rt_save_buffers( &target, output_path, strings[i] );
+                                               
+                                               csr_rt_clear( &target );
+                                       }
+                               }
+                               
+                               if( i == 0 )
+                               {
+                                       filter.compute_bounds_only = 0;
+                                       csr_auto_fit( &target, padding );
+                                       vmf_load_models( map );
                                }
                        }
                        
@@ -193,15 +230,15 @@ int main( int argc, char *argv[] )
                }
                else
                {
-                       fprintf( stderr, "Could not load VMF\n" );
+                       log_error( "Could not load VMF\n" );
                }
        }
        else
        {
-               fprintf( stderr, "Missing required argument: mapfile\n" );
+               log_error( "Missing required argument: mapfile\n" );
        }
        
+IL_CSR_EXIT:
        fs_exit();
-
        return 0;
 }