1 #define VALVE_IMPLEMENTATION
5 // gcc -Wall -fsanitize=address csRadar.c -o csRadar -lm
7 int main( int argc
, char *argv
[] )
14 .api_version
= csr_api_version
,
15 .sampling_mode
= k_EMSAA_RGSS
19 char *extension
= NULL
;
22 while( csr_argp( argc
, argv
) )
24 if( (arg
= csr_arg()) )
26 if( api
.num_strings
== 20 )
28 log_error( "Too many arguments! Max 20\n" );
32 api
.strings
[ api
.num_strings
++ ] = arg
;
35 if( (arg
= csr_opt_arg( 'o' )) )
37 strcpy( api
.output_path
, arg
);
38 csr_path_winunix( api
.output_path
);
43 if( (arg
= csr_opt_arg( 'g' )) )
45 fs_set_gameinfo( arg
);
48 if( (arg
= csr_opt_arg( 'r' )) )
50 api
.resolution
= atoi( arg
);
53 if( (arg
= csr_long_opt_arg( "padding" )) )
55 api
.padding
= atof( arg
);
58 if( (arg
= csr_long_opt_arg( "multi-sample" )) )
60 if( !strcmp( arg
, "none" ))
62 api
.sampling_mode
= k_EMSAA_none
;
64 else if( !strcmp( arg
, "rgss" ))
66 api
.sampling_mode
= k_EMSAA_RGSS
;
68 else if( !strcmp( arg
, "2x" ))
70 api
.sampling_mode
= k_EMSAA_2x2
;
72 else if( !strcmp( arg
, "8r" ))
74 api
.sampling_mode
= k_EMSAA_8R
;
78 log_error( "Invalid sampling pattern '%s'\n", arg
);
83 if( (arg
= csr_long_opt_arg( "extension" )) )
88 if( csr_opt( 'v' ) || csr_long_opt( "version" ) )
90 printf( "csRadar build: %u, api_version: %u\n", csr_build
, csr_api_version
);
94 if( csr_opt( 'h' ) || csr_long_opt( "help" ) )
99 "csRadar Copyright (C) 2021 Harry Godden (hgn)\n"
101 "Usage: ./csRadar map.vmf -g \"/gamedir/gameinfo.txt\" layout cover\n"
102 " VMF file is first, then any other arguments (eg. layout, cover), will specify\n"
103 " visgroups to be rendered into individual files\n"
104 " No visgroups specified will simply draw everything\n"
107 " -g <gameinfo.txt path> Required if you are loading models\n"
108 " -r 1024 Output resolution\n"
109 " -o <output> Specify output name/path\n"
110 " --padding=128 When cropping radar, add padding units to border\n"
111 //" --standard-layers Use standard TAR layers/groups\n"
112 " --write-normals Enable normals as an output stream\n"
113 " --write-origins Enable entity origins as an output stream\n"
114 " --no-txt Don't create matching radar txt\n"
115 " --multi-sample=RGSS [ none, 2x, rgss, 8r ]\n"
116 " --extension=TAR Use an extension binary instead\n"
118 " -v --version Display program version\n"
119 " -h --help Display this help text\n"
126 if( api
.num_strings
)
131 strcpy( api
.output_path
, api
.strings
[0] );
132 csr_stripext( api
.output_path
);
136 if( !(base_name
= csr_findext( api
.output_path
, '/' ) ))
138 base_name
= api
.output_path
;
141 strcpy( api
.vmf_name
, base_name
);
143 log_info( "output_path: '%s'\n", api
.output_path
);
144 log_info( "vmf_name: '%s'\n", api
.vmf_name
);
146 api
.map
= vmf_init( api
.strings
[0] );
150 extension
= "csRadarFree";
152 csr_so ext
= csr_libopen( extension
);
156 void (*csr_ext_main
)(csr_api
*);
157 void (*csr_ext_exit
)(csr_api
*);
159 csr_ext_main
= csr_get_proc( ext
, "csr_ext_main" );
160 csr_ext_exit
= csr_get_proc( ext
, "csr_ext_exit" );
162 if( csr_ext_main
&& csr_ext_exit
)
164 csr_ext_main( &api
);
168 csr_ext_exit( &api
);
186 log_error( "Could not load VMF\n" );
191 log_error( "Missing required argument: mapfile\n" );