1 // Copyright (C) 2021 Harry Godden (hgn)
4 // gcc -rdynamic csRadar.c -o csRadar -lm -ldl
7 // gcc -fpic -shared -o ext/my_plugin.so my_plugin.c -lm
9 #define VALVE_IMPLEMENTATION
10 #define CSR_EXECUTABLE
13 int main( int argc
, char *argv
[] )
20 .api_version
= csr_api_version
,
21 .sampling_mode
= k_EMSAA_RGSS
25 char *extension
= NULL
;
26 char *gameinfo
= NULL
;
29 while( csr_argp( argc
, argv
) )
31 if( (arg
= csr_arg()) )
33 if( api
.num_strings
== 20 )
35 log_error( "Too many arguments! Max 20\n" );
39 api
.strings
[ api
.num_strings
++ ].str
= arg
;
42 if( (arg
= csr_opt_arg( 'o' )) )
44 strcpy( api
.output_path
, arg
);
45 csr_path_winunix( api
.output_path
);
50 if( (arg
= csr_opt_arg( 'g' )) )
55 if( (arg
= csr_opt_arg( 'r' )) )
57 api
.resolution
= atoi( arg
);
60 if( (arg
= csr_long_opt_arg( "padding" )) )
62 api
.padding
= atof( arg
);
65 if( (arg
= csr_long_opt_arg( "multi-sample" )) )
67 if( !strcmp( arg
, "none" ))
69 api
.sampling_mode
= k_EMSAA_none
;
71 else if( !strcmp( arg
, "rgss" ))
73 api
.sampling_mode
= k_EMSAA_RGSS
;
75 else if( !strcmp( arg
, "2x" ))
77 api
.sampling_mode
= k_EMSAA_2x2
;
79 else if( !strcmp( arg
, "8r" ))
81 api
.sampling_mode
= k_EMSAA_8R
;
85 log_error( "Invalid sampling pattern '%s'\n", arg
);
90 if( (arg
= csr_long_opt_arg( "extension" )) )
95 if( csr_opt( 'v' ) || csr_long_opt( "version" ) )
97 printf( "csRadar build: %u, api_version: %u\n", csr_build
, csr_api_version
);
101 if( csr_opt( 'h' ) || csr_long_opt( "help" ) )
106 "csRadar Copyright (C) 2021 Harry Godden (hgn)\n"
108 "Usage: ./csRadar map.vmf -g \"/gamedir/gameinfo.txt\" layout cover\n"
109 " VMF file is first, then any other arguments (eg. layout, cover), will specify\n"
110 " visgroups to be rendered into individual files\n"
111 " No visgroups specified will simply draw everything\n"
114 " -g <gameinfo.txt path> Required if you are loading models\n"
115 " -r 1024 Output resolution\n"
116 " -o <output> Specify output name/path\n"
117 " -e <classname> Same as default arg, but instead filters for entity class\n"
118 //" -s <height> Add a vertical split at this height\n"
119 " --padding=128 When cropping radar, add padding units to border\n"
120 //" --standard-layers Use standard TAR layers/groups\n"
121 " --no-txt Don't create matching radar txt\n"
122 " --multi-sample=RGSS [ none, 2x, rgss, 8r ]\n"
123 " --extension=TAR Use an extension binary instead\n"
125 " -v --version Display program version\n"
126 " -h --help Display this help text\n"
133 if( api
.num_strings
)
137 fs_set_gameinfo( gameinfo
);
143 strcpy( api
.output_path
, api
.strings
[0].str
);
144 csr_stripext( api
.output_path
);
148 if( !(base_name
= csr_findext( api
.output_path
, '/' ) ))
150 base_name
= api
.output_path
;
153 strcpy( api
.vmf_name
, base_name
);
155 log_info( "output_path: '%s'\n", api
.output_path
);
156 log_info( "vmf_name: '%s'\n", api
.vmf_name
);
158 api
.map
= vmf_init( api
.strings
[0].str
);
161 // Update arg inferred types
162 api
.strings
[0].type
= k_iftype_vmf
;
163 for( int i
= 1; i
< api
.num_strings
; i
++ )
165 if( vmf_visgroup_id( api
.map
->root
, api
.strings
[i
].str
) != -1 )
166 api
.strings
[i
].type
= k_iftype_visgroup
;
168 api
.strings
[i
].type
= k_iftype_classname
;
172 extension
= "csRadarFree";
174 csr_so ext
= csr_libopen( extension
);
178 void (*csr_ext_main
)(csr_api
*);
179 void (*csr_ext_exit
)(csr_api
*);
181 csr_ext_main
= csr_get_proc( ext
, "csr_ext_main" );
182 csr_ext_exit
= csr_get_proc( ext
, "csr_ext_exit" );
184 if( csr_ext_main
&& csr_ext_exit
)
186 csr_ext_main( &api
);
190 csr_ext_exit( &api
);
208 log_error( "Could not load VMF\n" );
213 log_error( "Missing required argument: mapfile\n" );