5347d751021634e7b31c04ac7eb90d1fd4c00022
33 #define CSR_VERSION "0.0.1"
35 // gcc -Wall -fsanitize=address csRadar.c -o csRadar -lm
37 int main( int argc
, char *argv
[] )
43 float padding
= 128.f
;
44 u32 resolution
= 1024;
46 char output_path
[ 512 ]; // Full path eg. /home/harry/my_map.vmf
47 char vmf_name
[ 128 ]; // Just the base name eg. my_map
49 EMSAA sampling_mode
= k_EMSAA_RGSS
;
51 while( csr_argp( argc
, argv
) )
53 if( (arg
= csr_arg()) )
55 if( num_strings
== 20 )
57 log_error( "Too many arguments! Max 20\n" );
61 strings
[ num_strings
++ ] = arg
;
64 if( (arg
= csr_opt_arg( 'o' )) )
66 strcpy( output_path
, arg
);
67 csr_path_winunix( output_path
);
72 if( (arg
= csr_opt_arg( 'g' )) )
74 fs_set_gameinfo( arg
);
77 if( (arg
= csr_opt_arg( 'r' )) )
79 resolution
= atoi( arg
);
82 if( (arg
= csr_long_opt_arg( "padding" )) )
84 padding
= atof( arg
);
87 if( (arg
= csr_long_opt_arg( "multi-sample" )) )
89 if( !strcmp( arg
, "none" ))
91 sampling_mode
= k_EMSAA_none
;
93 else if( !strcmp( arg
, "rgss" ))
95 sampling_mode
= k_EMSAA_RGSS
;
97 else if( !strcmp( arg
, "2x" ))
99 sampling_mode
= k_EMSAA_2x2
;
101 else if( !strcmp( arg
, "8r" ))
103 sampling_mode
= k_EMSAA_8R
;
107 log_error( "Invalid sampling pattern '%s'\n", arg
);
112 if( csr_opt( 'v' ) || csr_long_opt( "version" ) )
114 printf( "csRadar version: " CSR_VERSION
"\n" );
118 if( csr_opt( 'h' ) || csr_long_opt( "help" ) )
123 "csRadar Copyright (C) 2021 Harry Godden (hgn)\n"
125 "Usage: ./csRadar map.vmf -g \"/gamedir/gameinfo.txt\" layout cover\n"
126 " VMF file is first, then any other arguments (eg. layout, cover), will specify\n"
127 " visgroups to be rendered into individual files\n"
128 " No visgroups specified will simply draw everything\n"
131 " -g <gameinfo.txt path> Required if you are loading models\n"
132 " -r 1024 Output resolution\n"
133 " -o <output> Specify output name/path\n"
134 " --padding=128 When cropping radar, add padding units to border\n"
135 //" --standard-layers Use standard TAR layers/groups\n"
136 " --no-txt Don't create matching radar txt\n"
137 " --multi-sample=RGSS [ none, 2x, rgss, 8r ]\n"
138 " --extension=TAR Use an extension binary instead\n"
140 " -v --version Display program version\n"
141 " -h --help Display this help text\n"
150 vmf_map
*map
= vmf_init( strings
[0] );
157 strcpy( output_path
, strings
[0] );
158 csr_stripext( output_path
);
162 if( !(base_name
= csr_findext( output_path
, '/' ) ))
164 base_name
= output_path
;
167 strcpy( vmf_name
, base_name
);
169 log_info( "output_path: '%s'\n", output_path
);
170 log_info( "vmf_name: '%s'\n", vmf_name
);
175 csr_create_target( &target
, resolution
, resolution
, sampling_mode
);
176 csr_rt_clear( &target
);
178 csr_use_program( &target
, frag_gbuffer
);
185 .compute_bounds_only
= 1
188 // One pass for fitting, second pass for drawing
189 for( int i
= 0; i
< 2; i
++ )
191 if( num_strings
== 1 )
194 draw_vmf_group( &target
, map
, map
->root
, &filter
, NULL
, NULL
);
195 csr_rt_save_buffers( &target
, output_path
, "all" );
200 for( int i
= 1; i
< num_strings
; i
++ )
202 filter
.visgroup
= strings
[ i
];
204 draw_vmf_group( &target
, map
, map
->root
, &filter
, NULL
, NULL
);
205 csr_rt_save_buffers( &target
, output_path
, strings
[i
] );
207 csr_rt_clear( &target
);
213 filter
.compute_bounds_only
= 0;
214 csr_auto_fit( &target
, padding
);
215 vmf_load_models( map
);
220 csr_prog_begin( "Rendering" );
226 csr_prog_update( prog
);
238 char txt_path
[ 512 ];
240 strcpy( txt_path
, output_path
);
241 strcat( txt_path
, ".txt" );
243 csr_write_txt( txt_path
, vmf_name
, &target
);
246 csr_rt_free( &target
);
251 log_error( "Could not load VMF\n" );
256 log_error( "Missing required argument: mapfile\n" );