28 #define CSR_VERSION "0.0.1"
30 // gcc -Wall -fsanitize=address csRadar.c -o csRadar -lm
32 int main( int argc
, char *argv
[] )
38 float padding
= 128.f
;
39 u32 resolution
= 1024;
40 int standard_layers
= 0;
43 char output_path
[ 512 ]; // Full path eg. /home/harry/my_map.vmf
44 char vmf_name
[ 128 ]; // Just the base name eg. my_map
47 while( csr_argp( argc
, argv
) )
49 if( (arg
= csr_arg()) )
51 if( num_strings
== 20 )
53 fprintf( stderr
, "Too many arguments! Max 20\n" );
58 printf( "got: %s\n", arg
);
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( csr_opt( 'v' ) || csr_long_opt( "version" ) )
88 printf( "csRadar version: " CSR_VERSION
"\n" );
92 if( csr_opt( 'h' ) || csr_long_opt( "help" ) )
97 "csRadar Copyright (C) 2021 Harry Godden (hgn)\n"
99 "Usage: ./csRadar map.vmf -g \"/gamedir/gameinfo.txt\" layout cover\n"
100 " VMF file is first, then any other arguments (eg. layout, cover), will specify\n"
101 " visgroups to be rendered into individual files\n"
102 " No visgroups specified will simply draw everything\n"
105 " -g <gameinfo.txt path> Required if you are loading models\n"
106 " -r 1024 Output resolution\n"
107 " -o <output> Specify output name/path\n"
108 " --padding=128 When cropping radar, add padding units to border\n"
109 " --standard-layers Use standard TAR layers/groups\n"
110 " --no-txt Don't create matching radar txt\n"
111 " --multi-sample= [ none, 2, 4, 4r, 8kn (default), 16c ]\n"
113 " -v --version Display program version\n"
114 " -h --help Display this help text\n"
123 vmf_map
*map
= vmf_init( strings
[0], 1 );
130 strcpy( output_path
, strings
[0] );
131 csr_stripext( output_path
);
135 if( !(base_name
= csr_findext( output_path
, '/' ) ))
137 base_name
= output_path
;
140 strcpy( vmf_name
, base_name
);
142 printf( "output_path: '%s'\nvmf_name: '%s'\n", output_path
, vmf_name
);
149 csr_create_target( &target
, resolution
, resolution
);
150 csr_rt_clear( &target
);
157 .compute_bounds_only
= 1
160 // One pass for fitting, second pass for drawing
161 for( int i
= 0; i
< 2; i
++ )
163 if( num_strings
== 1 )
166 draw_vmf_group( &target
, map
, map
->root
, &filter
, NULL
, NULL
);
167 csr_rt_save_buffers( &target
, output_path
, "all" );
172 for( int i
= 1; i
< num_strings
; i
++ )
174 filter
.visgroup
= strings
[ i
];
176 draw_vmf_group( &target
, map
, map
->root
, &filter
, NULL
, NULL
);
177 csr_rt_save_buffers( &target
, output_path
, strings
[i
] );
179 csr_rt_clear( &target
);
183 filter
.compute_bounds_only
= 0;
184 csr_auto_fit( &target
, padding
);
189 char txt_path
[ 512 ];
191 strcpy( txt_path
, output_path
);
192 strcat( txt_path
, ".txt" );
194 csr_write_txt( txt_path
, vmf_name
, &target
);
197 csr_rt_free( &target
);
202 fprintf( stderr
, "Could not load VMF\n" );
207 fprintf( stderr
, "Missing required argument: mapfile\n" );