Skip to content

Commit

Permalink
svn r6456 (2020 edition)
Browse files Browse the repository at this point in the history
  • Loading branch information
sauerbraten committed Nov 30, 2020
1 parent dd0b3a9 commit 09a8e0c
Show file tree
Hide file tree
Showing 16 changed files with 245 additions and 54 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
src/**/*.a
src/**/*.gch
src/**/*.o
src/**/*.orig
src/sauer_client
src/sauer_server
patch_drafts
Expand Down
6 changes: 3 additions & 3 deletions src/engine/3dgui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ struct gui : g3d_gui
int x1 = int(floor(screenw*(xi*scale.x+origin.x))), y1 = int(floor(screenh*(1 - ((yi+ys)*scale.y+origin.y)))),
x2 = int(ceil(screenw*((xi+xs)*scale.x+origin.x))), y2 = int(ceil(screenh*(1 - (yi*scale.y+origin.y))));
glDisable(GL_BLEND);
modelpreview::start(x1, y1, x2-x1, y2-y1, overlaid);
modelpreview::start(x1, y1, x2-x1, y2-y1, overlaid!=NULL);
game::renderplayerpreview(model, team, weap);
modelpreview::end();
hudshader->set();
Expand Down Expand Up @@ -381,7 +381,7 @@ struct gui : g3d_gui
int x1 = int(floor(screenw*(xi*scale.x+origin.x))), y1 = int(floor(screenh*(1 - ((yi+ys)*scale.y+origin.y)))),
x2 = int(ceil(screenw*((xi+xs)*scale.x+origin.x))), y2 = int(ceil(screenh*(1 - (yi*scale.y+origin.y))));
glDisable(GL_BLEND);
modelpreview::start(x1, y1, x2-x1, y2-y1, overlaid);
modelpreview::start(x1, y1, x2-x1, y2-y1, overlaid!=NULL);
model *m = loadmodel(name);
if(m)
{
Expand Down Expand Up @@ -438,7 +438,7 @@ struct gui : g3d_gui
int x1 = int(floor(screenw*(xi*scale.x+origin.x))), y1 = int(floor(screenh*(1 - ((yi+ys)*scale.y+origin.y)))),
x2 = int(ceil(screenw*((xi+xs)*scale.x+origin.x))), y2 = int(ceil(screenh*(1 - (yi*scale.y+origin.y))));
glDisable(GL_BLEND);
modelpreview::start(x1, y1, x2-x1, y2-y1, overlaid);
modelpreview::start(x1, y1, x2-x1, y2-y1, overlaid!=NULL);
previewprefab(prefab, color);
modelpreview::end();
hudshader->set();
Expand Down
200 changes: 184 additions & 16 deletions src/engine/command.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -630,6 +630,17 @@ void setvarchecked(ident *id, int val)
}
}

static inline void setvarchecked(ident *id, tagval *args, int numargs)
{
int val = forceint(args[0]);
if(id->flags&IDF_HEX && numargs > 1)
{
val = (val << 16) | (forceint(args[1])<<8);
if(numargs > 2) val |= forceint(args[2]);
}
setvarchecked(id, val);
}

float clampfvar(ident *id, float val, float minval, float maxval)
{
if(val < minval) val = minval;
Expand Down Expand Up @@ -676,21 +687,53 @@ void setsvarchecked(ident *id, const char *val)
}
}

ICOMMAND(set, "rt", (ident *id, tagval *v),
{
switch(id->type)
{
case ID_ALIAS:
if(id->index < MAXARGS) setarg(*id, *v); else setalias(*id, *v);
v->type = VAL_NULL;
break;
case ID_VAR:
setvarchecked(id, forceint(*v));
break;
case ID_FVAR:
setfvarchecked(id, forcefloat(*v));
break;
case ID_SVAR:
setsvarchecked(id, forcestr(*v));
break;
case ID_COMMAND:
if(id->flags&IDF_EMUVAR)
{
tagval arg;
arg.setint(execute(id, NULL, 0, true) ? 0 : 1);
execute(id, &arg, 1, false);
break;
}
default:
debugcode("cannot redefine builtin %s with an alias", id->name);
break;
}
});

bool addcommand(const char *name, identfun fun, const char *args)
{
uint argmask = 0;
int numargs = 0;
int numargs = 0, flags = 0;
bool limit = true;
for(const char *fmt = args; *fmt; fmt++) switch(*fmt)
{
case 'i': case 'b': case 'f': case 't': case 'N': case 'D': if(numargs < MAXARGS) numargs++; break;
case 's': case 'e': case 'r': case '$': if(numargs < MAXARGS) { argmask |= 1<<numargs; numargs++; } break;
case '$': flags |= IDF_EMUVAR; // fall through
case 's': case 'e': case 'r': if(numargs < MAXARGS) { argmask |= 1<<numargs; numargs++; } break;
case '1': case '2': case '3': case '4': if(numargs < MAXARGS) fmt -= *fmt-'0'+1; break;
case 'C': case 'V': limit = false; break;
default: fatal("builtin %s declared with illegal type: %s", name, args); break;
}
if(limit && numargs > MAXCOMARGS) fatal("builtin %s declared with too many args: %d", name, numargs);
addident(ident(ID_COMMAND, name, args, argmask, numargs, (void *)fun));
addident(ident(ID_COMMAND, name, args, argmask, numargs, (void *)fun, flags));
return false;
}

Expand Down Expand Up @@ -1325,13 +1368,36 @@ static void compilestatements(vector<uint> &code, const char *&p, int rettype, i
if(idname)
{
id = newident(idname, IDF_UNKNOWN);
if(!id || id->type != ID_ALIAS) { compilestr(code, idname, idlen, true); id = NULL; }
if(id) switch(id->type)
{
case ID_ALIAS:
if(!(more = compilearg(code, p, VAL_ANY))) compilestr(code);
code.add((id->index < MAXARGS ? CODE_ALIASARG : CODE_ALIAS)|(id->index<<8));
goto endcommand;
case ID_VAR:
if(!(more = compilearg(code, p, VAL_INT))) compileint(code);
code.add(CODE_IVAR1|(id->index<<8));
goto endcommand;
case ID_FVAR:
if(!(more = compilearg(code, p, VAL_FLOAT))) compilefloat(code);
code.add(CODE_FVAR1|(id->index<<8));
goto endcommand;
case ID_SVAR:
if(!(more = compilearg(code, p, VAL_STR))) compilestr(code);
code.add(CODE_SVAR1|(id->index<<8));
goto endcommand;
case ID_COMMAND:
if(id->flags&IDF_EMUVAR) goto compilecommand;
break;
}
compilestr(code, idname, idlen, true);
delete[] idname;
}
if(!(more = compilearg(code, p, VAL_ANY))) compilestr(code);
code.add(id && idname ? (id->index < MAXARGS ? CODE_ALIASARG : CODE_ALIAS)|(id->index<<8) : CODE_ALIASU);
code.add(CODE_ALIASU);
goto endstatement;
}
compilecommand:
numargs = 0;
if(!idname)
{
Expand Down Expand Up @@ -1432,6 +1498,7 @@ static void compilestatements(vector<uint> &code, const char *&p, int rettype, i
}
break;
}
endcommand:
delete[] idname;
}
endstatement:
Expand Down Expand Up @@ -1540,15 +1607,37 @@ void printsvar(ident *id, const char *s)
conoutf(CON_INFO, id->index, strchr(s, '"') ? "%s = [%s]" : "%s = \"%s\"", id->name, s);
}

template <class V>
static void printvar(ident *id, int type, V &val)
{
switch(type)
{
case VAL_INT: printvar(id, val.getint()); break;
case VAL_FLOAT: printfvar(id, val.getfloat()); break;
default: printsvar(id, val.getstr()); break;
}
}

void printvar(ident *id)
{
switch(id->type)
{
case ID_VAR: printvar(id, *id->storage.i); break;
case ID_FVAR: printfvar(id, *id->storage.f); break;
case ID_SVAR: printsvar(id, *id->storage.s); break;
case ID_ALIAS: printvar(id, id->valtype, *id); break;
case ID_COMMAND:
if(id->flags&IDF_EMUVAR)
{
tagval result;
executeret(id, NULL, 0, true, result);
printvar(id, result.type, result);
freearg(result);
}
break;
}
}
ICOMMAND(printvar, "r", (ident *id), printvar(id));

typedef void (__cdecl *comfun)();
typedef void (__cdecl *comfun1)(void *);
Expand Down Expand Up @@ -2046,17 +2135,7 @@ static const uint *runcode(const uint *code, tagval &result)
goto exit;
}
case ID_VAR:
if(numargs <= 1) printvar(id);
else
{
int val = forceint(args[1]);
if(id->flags&IDF_HEX && numargs > 2)
{
val = (val << 16) | (forceint(args[2])<<8);
if(numargs > 3) val |= forceint(args[3]);
}
setvarchecked(id, val);
}
if(numargs <= 1) printvar(id); else setvarchecked(id, &args[1], numargs-1);
goto forceresult;
case ID_FVAR:
if(numargs <= 1) printvar(id); else setfvarchecked(id, forcefloat(args[1]));
Expand Down Expand Up @@ -2095,6 +2174,50 @@ void executeret(const char *p, tagval &result)
if(int(code[0]) >= 0x100) code.disown();
}

void executeret(ident *id, tagval *args, int numargs, bool lookup, tagval &result)
{
result.setnull();
++rundepth;
tagval *prevret = commandret;
commandret = &result;
if(rundepth > MAXRUNDEPTH) debugcode("exceeded recursion limit");
else if(id) switch(id->type)
{
default:
if(!id->fun) break;
// fall-through
case ID_COMMAND:
if(numargs < id->numargs)
{
tagval buf[MAXARGS];
memcpy(buf, args, numargs*sizeof(tagval));
callcommand(id, buf, numargs, lookup);
}
else callcommand(id, args, numargs, lookup);
numargs = 0;
break;
case ID_VAR:
if(numargs <= 0) printvar(id); else setvarchecked(id, args, numargs);
break;
case ID_FVAR:
if(numargs <= 0) printvar(id); else setfvarchecked(id, forcefloat(args[0]));
break;
case ID_SVAR:
if(numargs <= 0) printvar(id); else setsvarchecked(id, forcestr(args[0]));
break;
case ID_ALIAS:
if(id->index < MAXARGS && !(aliasstack->usedargs&(1<<id->index))) break;
if(id->valtype==VAL_NULL) break;
#define op RET_NULL
CALLALIAS(0);
#undef op
break;
}
freeargs(args, numargs, 0);
commandret = prevret;
--rundepth;
}

char *executestr(const uint *code)
{
tagval result;
Expand All @@ -2113,6 +2236,21 @@ char *executestr(const char *p)
return result.s;
}

char *executestr(ident *id, tagval *args, int numargs, bool lookup)
{
tagval result;
executeret(id, args, numargs, lookup, result);
if(result.type == VAL_NULL) return NULL;
forcestr(result);
return result.s;
}

char *execidentstr(const char *name, bool lookup)
{
ident *id = idents.access(name);
return id ? executestr(id, NULL, 0, lookup) : NULL;
}

int execute(const uint *code)
{
tagval result;
Expand All @@ -2135,6 +2273,21 @@ int execute(const char *p)
return i;
}

int execute(ident *id, tagval *args, int numargs, bool lookup)
{
tagval result;
executeret(id, args, numargs, lookup, result);
int i = result.getint();
freearg(result);
return i;
}

int execident(const char *name, int noid, bool lookup)
{
ident *id = idents.access(name);
return id ? execute(id, NULL, 0, lookup) : noid;
}

static inline bool getbool(const char *s)
{
switch(s[0])
Expand Down Expand Up @@ -2193,6 +2346,21 @@ bool executebool(const char *p)
return b;
}

bool executebool(ident *id, tagval *args, int numargs, bool lookup)
{
tagval result;
executeret(id, args, numargs, lookup, result);
bool b = getbool(result);
freearg(result);
return b;
}

bool execidentbool(const char *name, bool noid, bool lookup)
{
ident *id = idents.access(name);
return id ? executebool(id, NULL, 0, lookup) : noid;
}

bool execfile(const char *cfgfile, bool msg)
{
string s;
Expand Down
8 changes: 8 additions & 0 deletions src/engine/octaedit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2877,6 +2877,14 @@ void showtexgui(int *n)
// 0/noargs = toggle, 1 = on, other = off - will autoclose if too far away or exit editmode
COMMAND(showtexgui, "i");

bool cleartexgui()
{
if(!gui.menuon) return false;
gui.showtextures(false);
return true;
}
ICOMMAND(cleartexgui, "", (), intret(cleartexgui() ? 1 : 0));

void rendertexturepanel(int w, int h)
{
if((texpaneltimer -= curtime)>0 && editmode)
Expand Down
Loading

0 comments on commit 09a8e0c

Please sign in to comment.