Argh!
This commit is contained in:
1 parent
4a60babf75
commit
217f15452c
10 files changed
+1593
-80
No files matched your search
@@ -3,6 +3,7 @@
|
||||
# Core sources
|
||||
set(SRB2_CORE_SOURCES
|
||||
am_map.c
|
||||
args.c
|
||||
b_bot.c
|
||||
command.c
|
||||
comptime.c
|
||||
@@ -50,6 +51,7 @@ set(SRB2_CORE_SOURCES
|
||||
|
||||
set(SRB2_CORE_HEADERS
|
||||
am_map.h
|
||||
args.h
|
||||
b_bot.h
|
||||
byteptr.h
|
||||
command.h
|
||||
|
||||
@@ -607,6 +607,7 @@ OBJS:=$(i_main_o) \
|
||||
$(OBJDIR)/lzf.o \
|
||||
$(OBJDIR)/vid_copy.o \
|
||||
$(OBJDIR)/b_bot.o \
|
||||
$(OBJDIR)/args.o \
|
||||
$(i_cdmus_o) \
|
||||
$(i_net_o) \
|
||||
$(i_system_o) \
|
||||
|
||||
+1309
File diff suppressed because it is too large.
Load diff
+206
@@ -0,0 +1,206 @@
|
||||
// -----------------------------------------------------------------------------
|
||||
// Args: a C99 library for parsing command line arguments.
|
||||
// Version: 2.8.0
|
||||
// Notes: This has been edited to work properly within SRB2.
|
||||
// Licensed under the 0BSD license.
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
#ifndef args_h
|
||||
#define args_h
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Types.
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
// An ArgParser instance stores registered flags, options and commands.
|
||||
typedef struct ArgParser ArgParser;
|
||||
|
||||
// A command callback function should accept two arguments: the command's name
|
||||
// and the command's ArgParser instance.
|
||||
typedef void (*ap_callback_t)(char* cmd_name, ArgParser* cmd_parser);
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Initialization, parsing, teardown.
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
// Initializes a new ArgParser instance. Returns NULL if sufficient memory
|
||||
// cannot be allocated for the new parser.
|
||||
ArgParser* ap_new();
|
||||
|
||||
// Specifies a helptext string for the parser. If [helptext] is not NULL, this
|
||||
// activates an automatic --help/-h flag. (Either --help or -h can be overridden
|
||||
// by explicitly registered flags.) The parser stores and manages its own copy
|
||||
// of the [helptext] string so [helptext] can be freed immediately after this
|
||||
// call if it was dynamically constructed.
|
||||
void ap_set_helptext(ArgParser* parser, const char* helptext);
|
||||
|
||||
// Returns a pointer to the parser's helptext string.
|
||||
char* ap_get_helptext(ArgParser* parser);
|
||||
|
||||
// Specifies a version string for the parser. If [version] is not NULL, this
|
||||
// activates an automatic --version/-v flag. (Either --version or -v can be
|
||||
// overridden by explicitly registered flags.) The parser stores and manages its
|
||||
// own copy of the [version] string so [version] can be freed immediately after
|
||||
// this call if it was dynamically constructed.
|
||||
void ap_set_version(ArgParser* parser, const char* version);
|
||||
|
||||
// Returns a pointer to the parser's version string.
|
||||
char* ap_get_version(ArgParser* parser);
|
||||
|
||||
// If toggled to true, the first positional argument ends option parsing; all
|
||||
// subsequent arguments will be treated as positionals. Defaults to false.
|
||||
void ap_first_pos_arg_ends_options(ArgParser* parser, bool enable);
|
||||
|
||||
// Parses the application's command line arguments. The parameters are assumed
|
||||
// to be [argc] and [argv] as supplied to main(), i.e. the first element of the
|
||||
// array is assumed to be the binary name and is therefore ignored. Returns true
|
||||
// if the arguments were successfully parsed. Returns false if parsing failed
|
||||
// due to a memory allocation error. (This memory allocation error may have
|
||||
// occured during set-up rather than during parsing.)
|
||||
bool ap_parse(ArgParser* parser, int argc, char** argv);
|
||||
|
||||
// Frees the memory associated with the parser and any subparsers.
|
||||
void ap_free(ArgParser* parser);
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Register flags and options.
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
// Registers a new flag.
|
||||
void ap_flag(ArgParser* parser, const char* name);
|
||||
|
||||
// Registers a new string-valued option.
|
||||
void ap_str_opt(ArgParser* parser, const char* name, const char* fallback);
|
||||
|
||||
// Registers a new integer-valued option.
|
||||
void ap_int_opt(ArgParser* parser, const char* name, int fallback);
|
||||
|
||||
// Registers a new double-valued option.
|
||||
void ap_dbl_opt(ArgParser* parser, const char* name, double fallback);
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Inspect flags and options.
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
// Returns the number of times the specified flag or option was found.
|
||||
int ap_count(ArgParser* parser, const char* name);
|
||||
|
||||
// Returns true if the specified flag or option was found.
|
||||
bool ap_found(ArgParser* parser, const char* name);
|
||||
|
||||
// Returns the value of a string option.
|
||||
char* ap_str_value(ArgParser* parser, const char* name);
|
||||
|
||||
// Returns the string value at the specified index.
|
||||
char* ap_str_value_at_index(ArgParser* parser, const char* name, int index);
|
||||
|
||||
// Returns the value of an integer option.
|
||||
int ap_int_value(ArgParser* parser, const char* name);
|
||||
|
||||
// Returns the integer value at the specified index.
|
||||
int ap_int_value_at_index(ArgParser* parser, const char* name, int index);
|
||||
|
||||
// Returns the value of a floating-point option.
|
||||
double ap_dbl_value(ArgParser* parser, const char* name);
|
||||
|
||||
// Returns the floating-point value at the specified index.
|
||||
double ap_dbl_value_at_index(ArgParser* parser, const char* name, int index);
|
||||
|
||||
// Returns an option's values as a freshly-allocated array of string
|
||||
// pointers. The array's memory is not affected by calls to ap_free().
|
||||
// Returns NULL if memory allocation fails.
|
||||
char** ap_str_values(ArgParser* parser, const char* name);
|
||||
|
||||
// Returns an option's values as a freshly-allocated array of integers.
|
||||
// The array's memory is not affected by calls to ap_free().
|
||||
// Returns NULL if memory allocation fails.
|
||||
int* ap_int_values(ArgParser* parser, const char* name);
|
||||
|
||||
// Returns an option's values as a freshly-allocated array of doubles.
|
||||
// The array's memory is not affected by calls to ap_free().
|
||||
// Returns NULL if memory allocation fails.
|
||||
double* ap_dbl_values(ArgParser* parser, const char* name);
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Positional arguments.
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
// Returns true if the parser has found one or more positional arguments.
|
||||
bool ap_has_args(ArgParser* parser);
|
||||
|
||||
// Returns the number of positional arguments.
|
||||
int ap_count_args(ArgParser* parser);
|
||||
|
||||
// Returns the positional argument at the specified index.
|
||||
char* ap_arg(ArgParser* parser, int index);
|
||||
|
||||
// Returns the positional arguments as a freshly-allocated array of string
|
||||
// pointers. The memory occupied by the returned array is not affected by
|
||||
// calls to ap_free(). Returns NULL if memory allocation fails.
|
||||
char** ap_args(ArgParser* parser);
|
||||
|
||||
// Attempts to parse and return the positional arguments as a freshly allocated
|
||||
// array of integers. Exits with an error message on failure. The memory
|
||||
// occupied by the returned array is not affected by calls to ap_free().
|
||||
// Returns NULL if memory allocation fails.
|
||||
int* ap_args_as_ints(ArgParser* parser);
|
||||
|
||||
// Attempts to parse and return the positional arguments as a freshly allocated
|
||||
// array of doubles. Exits with an error message on failure. The memory
|
||||
// occupied by the returned array is not affected by calls to ap_free().
|
||||
// Returns NULL if memory allocation fails.
|
||||
double* ap_args_as_doubles(ArgParser* parser);
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Commands.
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
// Registers a new command. Returns the ArgParser instance for the command.
|
||||
// Returns NULL if sufficient memory cannot be allocated for the new parser.
|
||||
ArgParser* ap_cmd(ArgParser* parser, const char* name);
|
||||
|
||||
// Registers a callback function on a command parser. The function will be
|
||||
// called if the command is found.
|
||||
void ap_callback(ArgParser* parser, ap_callback_t function);
|
||||
|
||||
// Returns true if the parser has found a command.
|
||||
bool ap_has_cmd(ArgParser* parser);
|
||||
|
||||
// Returns the command name, if the parser has found a command.
|
||||
char* ap_cmd_name(ArgParser* parser);
|
||||
|
||||
// Returns the command's parser instance, if the parser has found a command.
|
||||
ArgParser* ap_cmd_parser(ArgParser* parser);
|
||||
|
||||
// This boolean switch toggles support for an automatic 'help' command that
|
||||
// prints subcommand helptext. The value defaults to false but gets toggled
|
||||
// automatically to true whenever a command is registered. You can use this
|
||||
// function to disable the feature if required.
|
||||
void ap_enable_help_command(ArgParser* parser, bool enable);
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Debugging utilities.
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
// Dump a parser instance for debugging.
|
||||
void ap_print(ArgParser* parser);
|
||||
|
||||
// True if an attempt to allocate memory failed.
|
||||
bool ap_had_memory_error(ArgParser* parser);
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Deprecated.
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
// Replaced by ap_enable_help_command().
|
||||
void ap_cmd_help(ArgParser* parser, bool enable);
|
||||
|
||||
// Replaced by ap_set_helptext().
|
||||
void ap_helptext(ArgParser* parser, const char* helptext);
|
||||
|
||||
// Replaced by ap_set_version().
|
||||
void ap_version(ArgParser* parser, const char* version);
|
||||
|
||||
#endif
|
||||
+11
-1
@@ -278,7 +278,7 @@ static xcommand_t *com_commands = NULL; // current commands
|
||||
|
||||
#define MAX_ARGS 80
|
||||
static size_t com_argc;
|
||||
static char *com_argv[MAX_ARGS];
|
||||
char *com_argv[MAX_ARGS];
|
||||
static const char *com_null_string = "";
|
||||
static char *com_args = NULL; // current command args or NULL
|
||||
|
||||
@@ -328,6 +328,16 @@ const char *COM_Argv(size_t arg)
|
||||
return com_argv[arg];
|
||||
}
|
||||
|
||||
/** Returns all of the console command arguments
|
||||
*
|
||||
* \return String pointer to the argv table.
|
||||
* \sa COM_ArgvList
|
||||
*/
|
||||
char **COM_ArgvList(void)
|
||||
{
|
||||
return com_argv;
|
||||
}
|
||||
|
||||
/** Gets all console command arguments.
|
||||
*
|
||||
* \return String pointer to all arguments for the last command.
|
||||
|
||||
@@ -33,8 +33,12 @@ typedef void (*com_func_t)(void);
|
||||
void COM_AddCommand(const char *name, com_func_t func);
|
||||
int COM_AddLuaCommand(const char *name);
|
||||
|
||||
#define MAX_ARGS 80
|
||||
extern char *com_argv[MAX_ARGS];
|
||||
|
||||
size_t COM_Argc(void);
|
||||
const char *COM_Argv(size_t arg); // if argv > argc, returns empty string
|
||||
char **COM_ArgvList(void);
|
||||
char *COM_Args(void);
|
||||
size_t COM_CheckParm(const char *check); // like M_CheckParm :)
|
||||
size_t COM_CheckPartialParm(const char *check);
|
||||
|
||||
+46
-79
@@ -141,11 +141,7 @@ static void Command_SetViews_f(void);
|
||||
|
||||
static void Command_Addfile(void);
|
||||
static void Command_Addskins(void);
|
||||
static void Command_Localskin1(void);
|
||||
static void Command_Localskin2(void);
|
||||
static void Command_Localskin3(void);
|
||||
static void Command_Localskin4(void);
|
||||
static void Command_LocalskinAll(void);
|
||||
static void Command_GLocalSkin(void);
|
||||
static void Command_ListWADS_f(void);
|
||||
#ifdef DELFILE
|
||||
static void Command_Delfile(void);
|
||||
@@ -628,11 +624,7 @@ void D_RegisterServerCommands(void)
|
||||
|
||||
COM_AddCommand("addfile", Command_Addfile);
|
||||
COM_AddCommand("addskins", Command_Addskins);
|
||||
COM_AddCommand("localskin", Command_Localskin1);
|
||||
COM_AddCommand("localskin2", Command_Localskin2);
|
||||
COM_AddCommand("localskin3", Command_Localskin3);
|
||||
COM_AddCommand("localskin4", Command_Localskin4);
|
||||
COM_AddCommand("localskinall", Command_LocalskinAll);
|
||||
COM_AddCommand("localskin", Command_GLocalSkin);
|
||||
COM_AddCommand("listwad", Command_ListWADS_f);
|
||||
|
||||
#ifdef DELFILE
|
||||
@@ -4534,81 +4526,56 @@ Command_Addskins (void)
|
||||
}
|
||||
*/
|
||||
}
|
||||
// args n stuff
|
||||
#include "args.h"
|
||||
|
||||
static void Command_Localskin1 (void) {
|
||||
if (!Playing() && !demo.playback)
|
||||
{
|
||||
CONS_Printf("You can only use this command in gameplay.\n");
|
||||
return;
|
||||
}
|
||||
if (COM_Argc() > 3)
|
||||
{
|
||||
CONS_Printf("localskin <name>: Set a localskin.\n");
|
||||
return;
|
||||
}
|
||||
if (fasticmp(COM_Argv(2), "-display") || fasticmp(COM_Argv(2), "-d"))
|
||||
SetLocalPlayerSkin(displayplayers[0], COM_Argv(1), &cv_localskin);
|
||||
else
|
||||
SetLocalPlayerSkin(consoleplayer, COM_Argv(1), &cv_localskin);
|
||||
}
|
||||
static void Command_GLocalSkin (void) {
|
||||
ArgParser* parser = ap_new();
|
||||
ap_set_helptext(parser, "Usage: localskin [options] <name>\n\nOptions: \n\
|
||||
-d, --display: Use the first displaying player instead of yourself.\n\
|
||||
Has no effect on replays. Omits any player related\n\
|
||||
options.\n\
|
||||
-a, --all: Set a localskin to all players. Omits any player related\n\
|
||||
options.\n\
|
||||
-p, --player: Set a localskin to a specific player name.\n\
|
||||
If omitted, defaults to the client player, unless -d \n\
|
||||
or --display is added.");
|
||||
ap_set_version(parser, "");
|
||||
ap_str_opt(parser, "player p", player_names[consoleplayer]);
|
||||
ap_flag(parser, "display d");
|
||||
ap_flag(parser, "all a");
|
||||
|
||||
static void Command_Localskin2 (void) {
|
||||
if (!Playing() && !demo.playback)
|
||||
{
|
||||
CONS_Printf("You can only use this command in gameplay.\n");
|
||||
return;
|
||||
}
|
||||
if (COM_Argc() != 2)
|
||||
{
|
||||
CONS_Printf("localskin2 <name>: Set a localskin.\n");
|
||||
return;
|
||||
}
|
||||
SetLocalPlayerSkin(displayplayers[1], COM_Argv(1), &cv_localskin2);
|
||||
}
|
||||
ap_parse(parser, COM_Argc(), COM_ArgvList());
|
||||
|
||||
static void Command_Localskin3 (void) {
|
||||
if (!Playing() && !demo.playback)
|
||||
{
|
||||
CONS_Printf("You can only use this command in gameplay.\n");
|
||||
return;
|
||||
}
|
||||
if (COM_Argc() != 2)
|
||||
{
|
||||
CONS_Printf("localskin3 <name>: Set a localskin.\n");
|
||||
return;
|
||||
}
|
||||
SetLocalPlayerSkin(displayplayers[2], COM_Argv(1), &cv_localskin3);
|
||||
}
|
||||
boolean disply;
|
||||
boolean allp;
|
||||
|
||||
static void Command_Localskin4 (void) {
|
||||
if (!Playing() && !demo.playback)
|
||||
{
|
||||
CONS_Printf("You can only use this command in gameplay.\n");
|
||||
return;
|
||||
}
|
||||
if (COM_Argc() != 2)
|
||||
{
|
||||
CONS_Printf("localskin4 <name>: Set a localskin.\n");
|
||||
return;
|
||||
}
|
||||
SetLocalPlayerSkin(displayplayers[3], COM_Argv(1), &cv_localskin4);
|
||||
}
|
||||
if (ap_found(parser, "display")) disply = true; else disply = false;
|
||||
if (ap_found(parser, "all")) allp = true; else allp = false;
|
||||
|
||||
static void Command_LocalskinAll (void) {
|
||||
if (!Playing() && !demo.playback)
|
||||
{
|
||||
CONS_Printf("You can only use this command in gameplay.\n");
|
||||
return;
|
||||
}
|
||||
if (COM_Argc() != 2)
|
||||
{
|
||||
CONS_Printf("localskinall <name>: Set a localskin to all players.\n");
|
||||
return;
|
||||
}
|
||||
INT32 i;
|
||||
for (i; i < MAXPLAYERS; i++) {
|
||||
SetLocalPlayerSkin(i, COM_Argv(1), &cv_localskinall);
|
||||
INT32 i, idx;
|
||||
i = 0;
|
||||
idx = 0;
|
||||
|
||||
for (idx = 0; idx < ap_count_args(parser); idx++) {
|
||||
if (disply) {
|
||||
SetLocalPlayerSkin(displayplayers[0], ap_arg(parser, idx), &cv_localskin);
|
||||
return;
|
||||
} else {
|
||||
for (i = 0; i < MAXPLAYERS; i++) {
|
||||
if (allp) {
|
||||
SetLocalPlayerSkin(i, ap_arg(parser, idx), &cv_localskinall);
|
||||
} else {
|
||||
if (fasticmp(player_names[i], ap_str_value(parser, "player"))) {
|
||||
SetLocalPlayerSkin(i, ap_arg(parser, idx), &cv_localskin);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ap_free(parser);
|
||||
}
|
||||
|
||||
#ifdef DELFILE
|
||||
|
||||
@@ -4169,6 +4169,12 @@ void A_SignPlayer(mobj_t *actor)
|
||||
// same thing happens on p_mobj.c
|
||||
ov->localskin = &localskins[actor->target->player->localskin - 1];
|
||||
ov->skinlocal = actor->target->skinlocal;
|
||||
} else {
|
||||
// needs - 1 or else it pukes an error out
|
||||
// same thing happens on p_mobj.c
|
||||
if (actor->target->player->localskin)
|
||||
ov->localskin = &skins[actor->target->player->localskin - 1];
|
||||
ov->skinlocal = actor->target->skinlocal;
|
||||
}
|
||||
P_SetMobjState(ov, actor->info->seestate); // S_PLAY_SIGN
|
||||
}
|
||||
|
||||
@@ -2727,7 +2727,9 @@ void R_InitSkins(void)
|
||||
strncpy(skin->facerank, "PLAYRANK", 9);
|
||||
strncpy(skin->facewant, "PLAYWANT", 9);
|
||||
strncpy(skin->facemmap, "PLAYMMAP", 9);
|
||||
skin->wadnum = 0; // god what have you brought to this world
|
||||
skin->prefcolor = SKINCOLOR_BLUE;
|
||||
skin->localskin = false;
|
||||
|
||||
// SRB2kart
|
||||
skin->kartspeed = 8;
|
||||
@@ -2877,10 +2879,12 @@ void SetLocalPlayerSkin(INT32 playernum, const char *skinname, consvar_t *cvar)
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
if (player->localskin > 0)
|
||||
CV_StealthSet(cvar, ( (player->skinlocal) ? localskins : skins )[player->localskin - 1].name);
|
||||
else
|
||||
CV_StealthSet(cvar, "none");
|
||||
*/
|
||||
}
|
||||
|
||||
// Same as SetPlayerSkin, but uses the skin #.
|
||||
@@ -3337,6 +3341,8 @@ next_token:
|
||||
Forceskin_cons_t[numskins+1].strvalue = skins[numskins].name;
|
||||
}
|
||||
|
||||
skin->localskin = local;
|
||||
|
||||
// add face graphics
|
||||
if (local) {
|
||||
ST_LoadLocalFaceGraphics(skin->facerank, skin->facewant, skin->facemmap, numlocalskins);
|
||||
|
||||
@@ -94,6 +94,8 @@ typedef struct
|
||||
|
||||
// specific sounds per skin
|
||||
sfxenum_t soundsid[NUMSKINSOUNDS]; // sound # in S_sfx table
|
||||
|
||||
boolean localskin;
|
||||
} skin_t;
|
||||
|
||||
extern CV_PossibleValue_t Forceskin_cons_t[];
|
||||
|
||||
Reference in new issue
Block a user