30 #define CSR_VERSION "0.0.1"
32 // gcc -Wall -fsanitize=address csRadar.c -o csRadar -lm
34 int main( int argc
, char *argv
[] )
40 float padding
= 128.f
;
41 u32 resolution
= 1024;
42 int standard_layers
= 0;
45 char output_path
[ 512 ]; // Full path eg. /home/harry/my_map.vmf
46 char vmf_name
[ 128 ]; // Just the base name eg. my_map
48 EMSAA sampling_mode
= k_EMSAA_RGSS
;
50 while( csr_argp( argc
, argv
) )
52 if( (arg
= csr_arg()) )
54 if( num_strings
== 20 )
56 log_error( "Too many arguments! Max 20\n" );
60 strings
[ num_strings
++ ] = arg
;
63 if( (arg
= csr_opt_arg( 'o' )) )
65 strcpy( output_path
, arg
);
66 csr_path_winunix( output_path
);
71 if( (arg
= csr_opt_arg( 'g' )) )
73 fs_set_gameinfo( arg
);
76 if( (arg
= csr_opt_arg( 'r' )) )
78 resolution
= atoi( arg
);
81 if( (arg
= csr_long_opt_arg( "padding" )) )
83 padding
= atof( arg
);
86 if( (arg
= csr_long_opt_arg( "multi-sample" )) )
88 if( !strcmp( arg
, "none" ))
90 sampling_mode
= k_EMSAA_none
;
92 else if( !strcmp( arg
, "rgss" ))
94 sampling_mode
= k_EMSAA_RGSS
;
96 else if( !strcmp( arg
, "2x" ))
98 sampling_mode
= k_EMSAA_2x2
;
100 else if( !strcmp( arg
, "8r" ))
102 sampling_mode
= k_EMSAA_8R
;
106 log_error( "Invalid sampling pattern '%s'\n", arg
);
111 if( csr_opt( 'v' ) || csr_long_opt( "version" ) )
113 printf( "csRadar version: " CSR_VERSION
"\n" );
117 if( csr_opt( 'h' ) || csr_long_opt( "help" ) )
122 "csRadar Copyright (C) 2021 Harry Godden (hgn)\n"
124 "Usage: ./csRadar map.vmf -g \"/gamedir/gameinfo.txt\" layout cover\n"
125 " VMF file is first, then any other arguments (eg. layout, cover), will specify\n"
126 " visgroups to be rendered into individual files\n"
127 " No visgroups specified will simply draw everything\n"
130 " -g <gameinfo.txt path> Required if you are loading models\n"
131 " -r 1024 Output resolution\n"
132 " -o <output> Specify output name/path\n"
133 " --padding=128 When cropping radar, add padding units to border\n"
134 //" --standard-layers Use standard TAR layers/groups\n"
135 " --no-txt Don't create matching radar txt\n"
136 " --multi-sample=RGSS [ none, 2x, rgss, 8r ]\n"
137 " --extension=TAR Use an extension binary instead\n"
139 " -v --version Display program version\n"
140 " -h --help Display this help text\n"
149 vmf_map
*map
= vmf_init( strings
[0] );
156 strcpy( output_path
, strings
[0] );
157 csr_stripext( output_path
);
161 if( !(base_name
= csr_findext( output_path
, '/' ) ))
163 base_name
= output_path
;
166 strcpy( vmf_name
, base_name
);
168 log_info( "output_path: '%s'\n", output_path
);
169 log_info( "vmf_name: '%s'\n", vmf_name
);
174 csr_create_target( &target
, resolution
, resolution
, sampling_mode
);
175 csr_rt_clear( &target
);
177 csr_use_program( &target
, frag_gbuffer
);
184 .compute_bounds_only
= 1
187 // One pass for fitting, second pass for drawing
188 for( int i
= 0; i
< 2; i
++ )
190 if( num_strings
== 1 )
193 draw_vmf_group( &target
, map
, map
->root
, &filter
, NULL
, NULL
);
194 csr_rt_save_buffers( &target
, output_path
, "all" );
199 for( int i
= 1; i
< num_strings
; i
++ )
201 filter
.visgroup
= strings
[ i
];
203 draw_vmf_group( &target
, map
, map
->root
, &filter
, NULL
, NULL
);
204 csr_rt_save_buffers( &target
, output_path
, strings
[i
] );
206 csr_rt_clear( &target
);
212 filter
.compute_bounds_only
= 0;
213 csr_auto_fit( &target
, padding
);
214 vmf_load_models( map
);
220 char txt_path
[ 512 ];
222 strcpy( txt_path
, output_path
);
223 strcat( txt_path
, ".txt" );
225 csr_write_txt( txt_path
, vmf_name
, &target
);
228 csr_rt_free( &target
);
233 log_error( "Could not load VMF\n" );
238 log_error( "Missing required argument: mapfile\n" );