mirror of
https://github.com/ZDoom/raze-gles.git
synced 2025-02-12 14:45:41 +00:00
- let OSD_Dispatch forward everything to the ZDoom-based command dispatcher.
Essentially making the OSD a dumb terminal. :P
This commit is contained in:
parent
189ce21acf
commit
44f81ebd56
3 changed files with 5 additions and 226 deletions
|
@ -17,6 +17,7 @@
|
||||||
#include "m_crc32.h"
|
#include "m_crc32.h"
|
||||||
#include "c_commandline.h"
|
#include "c_commandline.h"
|
||||||
#include "c_bind.h"
|
#include "c_bind.h"
|
||||||
|
#include "c_dispatch.h"
|
||||||
|
|
||||||
#include "vfs.h"
|
#include "vfs.h"
|
||||||
|
|
||||||
|
@ -1528,217 +1529,11 @@ void OSD_DispatchQueued(void)
|
||||||
OSD_Dispatch((const char *)osd->history.buf[cmd]);
|
OSD_Dispatch((const char *)osd->history.buf[cmd]);
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
|
||||||
// OSD_Dispatch() -- Executes a command string
|
|
||||||
//
|
|
||||||
static char *osd_strtoken(char *s, char **ptrptr, int *restart)
|
|
||||||
{
|
|
||||||
*restart = 0;
|
|
||||||
if (!ptrptr) return NULL;
|
|
||||||
|
|
||||||
// if s != NULL, we process from the start of s, otherwise
|
|
||||||
// we just continue with where ptrptr points to
|
|
||||||
|
|
||||||
char *p = s ? s : *ptrptr;
|
|
||||||
|
|
||||||
if (!p) return NULL;
|
|
||||||
|
|
||||||
// eat up any leading whitespace
|
|
||||||
while (*p == ' ') p++;
|
|
||||||
|
|
||||||
// a semicolon is an end of statement delimiter like a \0 is, so we signal
|
|
||||||
// the caller to 'restart' for the rest of the string pointed at by *ptrptr
|
|
||||||
if (*p == ';')
|
|
||||||
{
|
|
||||||
*restart = 1;
|
|
||||||
*ptrptr = p+1;
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
// or if we hit the end of the input, signal all done by nulling *ptrptr
|
|
||||||
else if (*p == 0)
|
|
||||||
{
|
|
||||||
*ptrptr = NULL;
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
char *start;
|
|
||||||
|
|
||||||
if (*p == '\"')
|
|
||||||
{
|
|
||||||
// quoted string
|
|
||||||
start = ++p;
|
|
||||||
char *p2 = p;
|
|
||||||
while (*p != 0)
|
|
||||||
{
|
|
||||||
if (*p == '\"')
|
|
||||||
{
|
|
||||||
p++;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
else if (*p == '\\')
|
|
||||||
{
|
|
||||||
switch (*(++p))
|
|
||||||
{
|
|
||||||
case 'n':
|
|
||||||
*p2 = '\n'; break;
|
|
||||||
case 'r':
|
|
||||||
*p2 = '\r'; break;
|
|
||||||
default:
|
|
||||||
*p2 = *p; break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
*p2 = *p;
|
|
||||||
}
|
|
||||||
p2++, p++;
|
|
||||||
}
|
|
||||||
*p2 = 0;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
start = p;
|
|
||||||
while (*p != 0 && *p != ';' && *p != ' ') p++;
|
|
||||||
}
|
|
||||||
|
|
||||||
// if we hit the end of input, signal all done by nulling *ptrptr
|
|
||||||
if (*p == 0)
|
|
||||||
{
|
|
||||||
*ptrptr = NULL;
|
|
||||||
}
|
|
||||||
// or if we came upon a semicolon, signal caller to restart with the
|
|
||||||
// string at *ptrptr
|
|
||||||
else if (*p == ';')
|
|
||||||
{
|
|
||||||
*p = 0;
|
|
||||||
*ptrptr = p+1;
|
|
||||||
*restart = 1;
|
|
||||||
}
|
|
||||||
// otherwise, clip off the token and carry on
|
|
||||||
else
|
|
||||||
{
|
|
||||||
*(p++) = 0;
|
|
||||||
*ptrptr = p;
|
|
||||||
}
|
|
||||||
|
|
||||||
return start;
|
|
||||||
}
|
|
||||||
|
|
||||||
#define MAXPARMS 256
|
#define MAXPARMS 256
|
||||||
void OSD_Dispatch(const char *cmd)
|
void OSD_Dispatch(const char *cmd)
|
||||||
{
|
{
|
||||||
char *workbuf = Xstrdup(cmd);
|
AddCommandString(cmd);
|
||||||
char *state = workbuf;
|
|
||||||
char *wtp;
|
|
||||||
|
|
||||||
int restart = 0;
|
|
||||||
|
|
||||||
do
|
|
||||||
{
|
|
||||||
char const *token;
|
|
||||||
|
|
||||||
if ((token = osd_strtoken(state, &wtp, &restart)) == NULL)
|
|
||||||
{
|
|
||||||
state = wtp;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// cheap hack for comments in cfgs
|
|
||||||
if (token[0] == '/' && token[1] == '/')
|
|
||||||
{
|
|
||||||
Xfree(workbuf);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto const *symbol = osd_findexactsymbol(token);
|
|
||||||
|
|
||||||
if (symbol == NULL)
|
|
||||||
{
|
|
||||||
// Quick hack to make ZDoom CVARs accessible. This isn't fully functional and only meant as a transitional helper.
|
|
||||||
auto cv = FindCVar(token, nullptr);
|
|
||||||
if (cv)
|
|
||||||
{
|
|
||||||
token = osd_strtoken(NULL, &wtp, &restart);
|
|
||||||
|
|
||||||
if (token == nullptr)
|
|
||||||
{
|
|
||||||
if (cv->GetDescription())
|
|
||||||
OSD_Printf("%s: %s\n", cv->GetName(), cv->GetDescription());
|
|
||||||
ECVarType type;
|
|
||||||
auto val = cv->GetFavoriteRep(&type);
|
|
||||||
switch (type)
|
|
||||||
{
|
|
||||||
case CVAR_String:
|
|
||||||
OSD_Printf("%s is %s\n", cv->GetName(), val.String);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case CVAR_Int:
|
|
||||||
OSD_Printf("%s is %d\n", cv->GetName(), val.Int);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case CVAR_Float:
|
|
||||||
OSD_Printf("%s is %2.5f\n", cv->GetName(), val.Float);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case CVAR_Bool:
|
|
||||||
OSD_Printf("%s is %s\n", cv->GetName(), val.Bool? "true" : "false");
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
UCVarValue val;
|
|
||||||
val.String = token;
|
|
||||||
cv->SetGenericRep(val, CVAR_String);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
static char const s_gamefunc_[] = "gamefunc_";
|
|
||||||
size_t constexpr strlen_gamefunc_ = ARRAY_SIZE(s_gamefunc_) - 1;
|
|
||||||
size_t const strlen_token = Bstrlen(token);
|
|
||||||
|
|
||||||
if ((strlen_gamefunc_ >= strlen_token || Bstrncmp(token, s_gamefunc_, strlen_gamefunc_)) && !m32_osd_tryscript)
|
|
||||||
OSD_Printf("%s\"%s\" is not a valid command or cvar\n", osd->draw.highlight, token);
|
|
||||||
|
|
||||||
Xfree(workbuf);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto name = token;
|
|
||||||
char const *parms[MAXPARMS] = {};
|
|
||||||
int numparms = 0;
|
|
||||||
|
|
||||||
while (wtp && !restart)
|
|
||||||
{
|
|
||||||
token = osd_strtoken(NULL, &wtp, &restart);
|
|
||||||
if (token && numparms < MAXPARMS) parms[numparms++] = token;
|
|
||||||
}
|
|
||||||
|
|
||||||
osdfuncparm_t const ofp = { numparms, name, parms, cmd };
|
|
||||||
|
|
||||||
if (symbol->func == OSD_ALIAS)
|
|
||||||
OSD_Dispatch(symbol->help);
|
|
||||||
else if (symbol->func != OSD_UNALIASED)
|
|
||||||
{
|
|
||||||
switch (symbol->func(&ofp))
|
|
||||||
{
|
|
||||||
default:
|
|
||||||
case OSDCMD_OK: break;
|
|
||||||
case OSDCMD_SHOWHELP: OSD_Printf("%s\n", symbol->help); break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
state = wtp;
|
|
||||||
}
|
|
||||||
while (wtp && restart);
|
|
||||||
|
|
||||||
Xfree(workbuf);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -310,7 +310,7 @@ void FGameConfigFile::DoGameSetup (const char *gamename)
|
||||||
while (NextInSection (key, value))
|
while (NextInSection (key, value))
|
||||||
{
|
{
|
||||||
FStringf cmd("alias %s \"%s\"", key, value);
|
FStringf cmd("alias %s \"%s\"", key, value);
|
||||||
OSD_Dispatch(cmd);
|
C_DoCommand(cmd);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -355,11 +355,11 @@ void FGameConfigFile::DoKeySetup(const char *gamename)
|
||||||
{
|
{
|
||||||
const char* key;
|
const char* key;
|
||||||
const char* value;
|
const char* value;
|
||||||
OSD_Dispatch("unbindall");
|
C_DoCommand("unbindall");
|
||||||
while (NextInSection(key, value))
|
while (NextInSection(key, value))
|
||||||
{
|
{
|
||||||
FStringf cmd("bind %s \"%s\"", key, value);
|
FStringf cmd("bind %s \"%s\"", key, value);
|
||||||
OSD_Dispatch(cmd);
|
C_DoCommand(cmd);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -430,22 +430,6 @@ int32_t JoystickAnalogueDead[MAXJOYAXES];
|
||||||
int32_t JoystickAnalogueSaturate[MAXJOYAXES];
|
int32_t JoystickAnalogueSaturate[MAXJOYAXES];
|
||||||
int32_t JoystickAnalogueInvert[MAXJOYAXES];
|
int32_t JoystickAnalogueInvert[MAXJOYAXES];
|
||||||
|
|
||||||
static const char* mousedefaults[MAXMOUSEBUTTONS] =
|
|
||||||
{
|
|
||||||
"Fire",
|
|
||||||
"Weapon_Special_Fire",
|
|
||||||
"",
|
|
||||||
"",
|
|
||||||
"Previous_Weapon",
|
|
||||||
"Next_Weapon",
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
static const char* mouseclickeddefaults[MAXMOUSEBUTTONS] =
|
|
||||||
{
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
static const char* mouseanalogdefaults[MAXMOUSEAXES] =
|
static const char* mouseanalogdefaults[MAXMOUSEAXES] =
|
||||||
{
|
{
|
||||||
"analog_turning",
|
"analog_turning",
|
||||||
|
|
Loading…
Reference in a new issue