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 strings
[ num_strings
++ ] = arg
;
61 if( (arg
= csr_opt_arg( 'o' )) )
63 strcpy( output_path
, arg
);
64 csr_path_winunix( output_path
);
69 if( (arg
= csr_opt_arg( 'g' )) )
71 fs_set_gameinfo( arg
);
74 if( (arg
= csr_opt_arg( 'r' )) )
76 resolution
= atoi( arg
);
79 if( (arg
= csr_long_opt_arg( "padding" )) )
81 padding
= atof( arg
);
84 if( csr_opt( 'v' ) || csr_long_opt( "version" ) )
86 printf( "csRadar version: " CSR_VERSION
"\n" );
90 if( csr_opt( 'h' ) || csr_long_opt( "help" ) )
95 "csRadar Copyright (C) 2021 Harry Godden (hgn)\n"
97 "Usage: ./csRadar map.vmf -g \"/gamedir/gameinfo.txt\" layout cover\n"
98 " VMF file is first, then any other arguments (eg. layout, cover), will specify\n"
99 " visgroups to be rendered into individual files\n"
100 " No visgroups specified will simply draw everything\n"
103 " -g <gameinfo.txt path> Required if you are loading models\n"
104 " -r 1024 Output resolution\n"
105 " -o <output> Specify output name/path\n"
106 " --padding=128 When cropping radar, add padding units to border\n"
107 " --standard-layers Use standard TAR layers/groups\n"
108 " --no-txt Don't create matching radar txt\n"
109 " --multi-sample= [ none, 2, 4, 4r, 8kn (default), 16c ]\n"
111 " -v --version Display program version\n"
112 " -h --help Display this help text\n"
121 vmf_map
*map
= vmf_init( strings
[0], 1 );
128 strcpy( output_path
, strings
[0] );
129 csr_stripext( output_path
);
133 if( !(base_name
= csr_findext( output_path
, '/' ) ))
135 base_name
= output_path
;
138 strcpy( vmf_name
, base_name
);
140 printf( "output_path: '%s'\nvmf_name: '%s'\n", output_path
, vmf_name
);
147 csr_create_target( &target
, resolution
, resolution
);
148 csr_rt_clear( &target
);
155 .compute_bounds_only
= 1
157 draw_vmf_group( &target
, map
, map
->root
, &filter
, NULL
, NULL
);
158 csr_auto_fit( &target
, padding
);
159 filter
.compute_bounds_only
= 0;
161 if( num_strings
== 1 )
164 draw_vmf_group( &target
, map
, map
->root
, NULL
, NULL
, NULL
);
165 csr_rt_save_buffers( &target
, output_path
, "all" );
170 for( int i
= 1; i
< num_strings
; i
++ )
172 filter
.visgroup
= strings
[ i
];
174 draw_vmf_group( &target
, map
, map
->root
, NULL
, NULL
, NULL
);
175 csr_rt_save_buffers( &target
, output_path
, strings
[i
] );
177 csr_rt_clear( &target
);
183 char txt_path
[ 512 ];
185 strcpy( txt_path
, output_path
);
186 strcat( txt_path
, ".txt" );
188 csr_write_txt( txt_path
, vmf_name
, &target
);
191 csr_rt_free( &target
);
196 fprintf( stderr
, "Could not load VMF\n" );
201 fprintf( stderr
, "Missing required argument: mapfile\n" );