+// Copyright (C) 2021 Harry Godden (hgn)
+
+// Building:
+// gcc -rdynamic csRadar.c -o csRadar -lm -ldl
+//
+// Plugins:
+// gcc -fpic -shared -o ext/my_plugin.so my_plugin.c -lm
+
#define VALVE_IMPLEMENTATION
#define CSR_EXECUTABLE
#include "csRadar.h"
-// gcc -Wall -fsanitize=address csRadar.c -o csRadar -lm
-
int main( int argc, char *argv[] )
{
csr_api api =
{
.padding = 128.f,
.resolution = 1024,
+ .min_z = -INFINITY,
+ .max_z = INFINITY,
.write_txt = 1,
.api_version = csr_api_version,
.sampling_mode = k_EMSAA_RGSS
int output_set = 0;
char *extension = NULL;
+ char *gameinfo = NULL;
char *arg;
while( csr_argp( argc, argv ) )
goto IL_CSR_EXIT;
}
- api.strings[ api.num_strings ++ ] = arg;
+ api.strings[ api.num_strings ++ ].str = arg;
}
if( (arg = csr_opt_arg( 'o' )) )
{
strcpy( api.output_path, arg );
- csr_path_winunix( api.output_path );
-
output_set = 1;
}
if( (arg = csr_opt_arg( 'g' )) )
{
- fs_set_gameinfo( arg );
+ gameinfo = arg;
}
if( (arg = csr_opt_arg( 'r' )) )
{
extension = arg;
}
+
+ if( (arg = csr_long_opt_arg( "min" )) )
+ api.min_z = atof( arg );
+ if( (arg = csr_long_opt_arg( "max" )) )
+ api.max_z = atof( arg );
if( csr_opt( 'v' ) || csr_long_opt( "version" ) )
{
"Options:\n"
" -g <gameinfo.txt path> Required if you are loading models\n"
" -r 1024 Output resolution\n"
- " -o <output> Specify output name/path\n"
+ " -o <output> Specify output name/path (no extension, dir must exist)\n"
" -e <classname> Same as default arg, but instead filters for entity class\n"
" --padding=128 When cropping radar, add padding units to border\n"
- //" --standard-layers Use standard TAR layers/groups\n"
- " --write-normals Enable normals as an output stream\n"
- " --write-origins Enable entity origins as an output stream\n"
" --no-txt Don't create matching radar txt\n"
- " --multi-sample=RGSS [ none, 2x, rgss, 8r ]\n"
+ " --multi-sample=rgss [ none, 2x, rgss, 8r ]\n"
" --extension=TAR Use an extension binary instead\n"
+ " --min=z Miniumum height to render\n"
+ " --max=z Maxiumum height to render\n"
"\n"
" -v --version Display program version\n"
" -h --help Display this help text\n"
if( api.num_strings )
{
+ if( gameinfo )
+ {
+ fs_set_gameinfo( gameinfo );
+ }
+
// Path handling
if( !output_set )
{
- strcpy( api.output_path, api.strings[0] );
+ strcpy( api.output_path, api.strings[0].str );
csr_stripext( api.output_path );
}
- char *base_name;
- if( !(base_name = csr_findext( api.output_path, '/' ) ))
- {
- base_name = api.output_path;
- }
-
- strcpy( api.vmf_name, base_name );
+ strcpy( api.vmf_name, csr_filename( api.output_path ) );
+ strcpy( api.vmf_folder, api.output_path );
+ csr_downlvl( api.vmf_folder );
log_info( "output_path: '%s'\n", api.output_path );
log_info( "vmf_name: '%s'\n", api.vmf_name );
-
- api.map = vmf_init( api.strings[0] );
+ log_info( "vmf_folder: '%s'\n", api.vmf_folder );
+
+ api.map = vmf_init( api.strings[0].str );
if( api.map )
{
+ // Update arg inferred types
+ api.strings[0].type = k_iftype_vmf;
+ for( int i = 1; i < api.num_strings; i ++ )
+ {
+ if( vmf_visgroup_id( api.map->root, api.strings[i].str ) != -1 )
+ api.strings[i].type = k_iftype_visgroup;
+ else
+ api.strings[i].type = k_iftype_classname;
+ }
+
if( !extension )
- extension = "csRadarFree";
+ extension = "csr_substance";
csr_so ext = csr_libopen( extension );
csr_ext_main( &api );
// Do other
+ if( api.write_txt )
+ {
+ char radar_path[512];
+ strcpy( radar_path, api.output_path );
+ strcat( radar_path, ".txt" );
+ csr_write_txt( radar_path, api.vmf_name, &api.target );
+ }
csr_ext_exit( &api );
}