*** empty log message ***

git-svn-id: svn://svn.code.sf.net/p/actiongame/code/trunk/ac@1525 e016b1c5-ed68-44aa-a2f7-31cac88cffde
This commit is contained in:
Lee Salzman
2007-12-30 00:01:46 +00:00
parent bb4e33a26a
commit afad80be3e
7 changed files with 130 additions and 23 deletions
+50 -11
View File
@@ -17,7 +17,7 @@ void alias(const char *name, const char *action)
ident *b = idents->access(name);
if(!b)
{
ident b = { ID_ALIAS, newstring(name), 0, 0, 0, 0, 0, newstring(action), 0, persistidents, execcontext };
ident b(ID_ALIAS, newstring(name), newstring(action), persistidents, execcontext);
idents->access(b.name, &b);
}
else if(b->type==ID_ALIAS)
@@ -36,13 +36,29 @@ COMMAND(alias, ARG_2STR);
int variable(const char *name, int min, int cur, int max, int *storage, void (*fun)(), bool persist)
{
if(!idents) idents = new hashtable<const char *, ident>;
ident v = { ID_VAR, name, min, max, storage, fun, 0, 0, 0, persist, IEXC_CORE };
ident v(ID_VAR, name, min, max, storage, fun, persist, IEXC_CORE);
idents->access(name, &v);
return cur;
}
void setvar(const char *name, int i) { *idents->access(name)->storage = i; }
int getvar(const char *name) { return *idents->access(name)->storage; }
float fvariable(const char *name, float cur, float *storage, void (*fun)(), bool persist)
{
if(!idents) idents = new hashtable<const char *, ident>;
ident v(ID_FVAR, name, storage, fun, persist, IEXC_CORE);
idents->access(name, &v);
return cur;
}
char *svariable(const char *name, const char *cur, char **storage, void (*fun)(), bool persist)
{
if(!idents) idents = new hashtable<const char *, ident>;
ident v(ID_SVAR, name, storage, fun, persist, IEXC_CORE);
idents->access(name, &v);
return newstring(cur);
}
void setvar(const char *name, int i) { *idents->access(name)->storage.i = i; }
int getvar(const char *name) { return *idents->access(name)->storage.i; }
bool identexists(const char *name) { return idents->access(name)!=NULL; }
const char *getalias(const char *name)
@@ -54,7 +70,7 @@ const char *getalias(const char *name)
bool addcommand(const char *name, void (*fun)(), int narg)
{
if(!idents) idents = new hashtable<const char *, ident>;
ident c = { ID_COMMAND, name, 0, 0, 0, fun, narg, 0, 0, false, IEXC_CORE };
ident c(ID_COMMAND, name, fun, narg, IEXC_CORE);
idents->access(name, &c);
return false;
}
@@ -106,7 +122,9 @@ char *lookup(char *n) // find value of ident reference
ident *id = idents->access(n+1);
if(id) switch(id->type)
{
case ID_VAR: string t; itoa(t, *(id->storage)); return exchangestr(n, t);
case ID_VAR: { string t; itoa(t, *id->storage.i); return exchangestr(n, t); }
case ID_FVAR: { s_sprintfd(t)("%f", *id->storage.f); return exchangestr(n, t); }
case ID_SVAR: return exchangestr(n, *id->storage.s);
case ID_ALIAS: return exchangestr(n, id->action);
}
conoutf("unknown alias lookup: %s", n+1);
@@ -193,7 +211,7 @@ int execute(const char *p) // all evaluation happens
break;
case ID_VAR: // game defined variables
if(!w[1][0]) conoutf("%s = %d", c, *id->storage); // var with no value just prints its current value
if(!w[1][0]) conoutf("%s = %d", c, *id->storage.i); // var with no value just prints its current value
else if(id->min>id->max) conoutf("variable %s is read-only", id->name);
else
{
@@ -203,11 +221,29 @@ int execute(const char *p) // all evaluation happens
i1 = i1<id->min ? id->min : id->max; // clamp to valid range
conoutf("valid range for %s is %d..%d", id->name, id->min, id->max);
}
*id->storage = i1;
*id->storage.i = i1;
if(id->fun) ((void (__cdecl *)())id->fun)(); // call trigger function if available
}
break;
case ID_FVAR: // game defined variables
if(!w[1][0]) conoutf("%s = %f", c, *id->storage.f); // var with no value just prints its current value
else
{
*id->storage.f = atof(w[1]);
if(id->fun) ((void (__cdecl *)())id->fun)(); // call trigger function if available
}
break;
case ID_SVAR: // game defined variables
if(!w[1][0]) conoutf(strchr(*id->storage.s, '"') ? "%s = [%s]" : "%s = \"%s\"", c, *id->storage.s); // var with no value just prints its current value
else
{
*id->storage.s = exchangestr(*id->storage.s, newstring(w[1]));
if(id->fun) ((void (__cdecl *)())id->fun)(); // call trigger function if available
}
break;
case ID_ALIAS: // alias, also used as functions and (global) variables
for(int i = 1; i<numargs; i++)
{
@@ -344,9 +380,12 @@ void writecfg()
fprintf(f, "fpsrange %d %d\n", lowfps, highfps);
fprintf(f, "\n");
enumerate(*idents, ident, id,
if(id.type==ID_VAR && id.persist)
if(!id.persist) continue;
switch(id.type)
{
fprintf(f, "%s %d\n", id.name, *id.storage);
case ID_VAR: fprintf(f, "%s %d\n", id.name, *id.storage.i); break;
case ID_FVAR: fprintf(f, "%s %f\n", id.name, *id.storage.f); break;
case ID_SVAR: fprintf(f, "%s [%s]\n", id.name, *id.storage.s); break;
}
);
fprintf(f, "\n");
+50 -2
View File
@@ -1,16 +1,53 @@
enum { ID_VAR, ID_COMMAND, ID_ALIAS };
enum { ID_VAR, ID_FVAR, ID_SVAR, ID_COMMAND, ID_ALIAS };
struct ident
{
int type; // one of ID_* above
const char *name;
int min, max; // ID_VAR
int *storage; // ID_VAR
union
{
int *i; // ID_VAR
float *f; // ID_FVAR
char **s; // ID_SVAR;
} storage;
void (*fun)(); // ID_VAR, ID_COMMAND
int narg; // ID_VAR, ID_COMMAND
char *action, *executing; // ID_ALIAS
bool persist;
int context;
ident() {}
// ID_VAR
ident(int type, const char *name, int min, int max, int *i, void (*fun)(), bool persist, int context)
: type(type), name(name), min(min), max(max), fun(fun),
narg(0), action(0), executing(0), persist(persist), context(context)
{ storage.i = i; }
// ID_FVAR
ident(int type, const char *name, float *f, void (*fun)(), bool persist, int context)
: type(type), name(name), min(0), max(0), fun(fun),
narg(0), action(0), executing(0), persist(persist), context(context)
{ storage.f = f; }
// ID_SVAR
ident(int type, const char *name, char **s, void (*fun)(), bool persist, int context)
: type(type), name(name), min(0), max(0), fun(fun),
narg(0), action(0), executing(0), persist(persist), context(context)
{ storage.s = s; }
// ID_ALIAS
ident(int type, const char *name, char *action, bool persist, int context)
: type(type), name(name), min(0), max(0), fun(0),
narg(0), action(action), executing(0), persist(persist), context(context)
{ storage.i = NULL; }
// ID_COMMAND
ident(int type, const char *name, void (*fun)(), int narg, int context)
: type(type), name(name), min(0), max(0), fun(fun),
narg(narg), action(0), executing(0), persist(false), context(context)
{ storage.i = NULL; }
};
enum // function signatures for script functions, see command.cpp
@@ -29,10 +66,21 @@ enum { IEXC_CORE = 0, IEXC_FOREIGN, IEXC_NUM }; // script execution context
// nasty macros for registering script functions, abuses globals to avoid excessive infrastructure
#define COMMANDN(name, fun, nargs) static bool __dummy_##fun = addcommand(#name, (void (*)())fun, nargs)
#define COMMAND(name, nargs) COMMANDN(name, name, nargs)
#define VARP(name, min, cur, max) int name = variable(#name, min, cur, max, &name, NULL, true)
#define VAR(name, min, cur, max) int name = variable(#name, min, cur, max, &name, NULL, false)
#define VARF(name, min, cur, max, body) void var_##name(); int name = variable(#name, min, cur, max, &name, var_##name, false); void var_##name() { body; }
#define VARFP(name, min, cur, max, body) void var_##name(); int name = variable(#name, min, cur, max, &name, var_##name, true); void var_##name() { body; }
#define FVARP(name, cur) float name = fvariable(#name, cur, &name, NULL, true)
#define FVAR(name, cur) float name = fvariable(#name, cur, &name, NULL, false)
#define FVARF(name, cur, body) void var_##name(); float name = fvariable(#name, cur, &name, var_##name, false); void var_##name() { body; }
#define FVARFP(name, cur, body) void var_##name(); float name = fvariable(#name, cur, &name, var_##name, true); void var_##name() { body; }
#define SVARP(name, cur) char *name = svariable(#name, cur, &name, NULL, true)
#define SVAR(name, cur) char *name = svariable(#name, cur, &name, NULL, false)
#define SVARF(name, cur, body) void var_##name(); char *name = svariable(#name, cur, &name, var_##name, false); void var_##name() { body; }
#define SVARFP(name, cur, body) void var_##name(); char *name = svariable(#name, cur, &name, var_##name, true); void var_##name() { body; }
#define ATOI(s) strtol(s, NULL, 0) // supports hexadecimal numbers
+1 -1
View File
@@ -268,7 +268,7 @@ void docwritebaseref(char *ref, char *schemalocation, char *transformation)
if(id.type != ID_VAR) continue;
fprintf(f, "\t\t\t\t<variable name=\"%s\">\n", xmlstringenc(name, id.name, _MAXDEFSTR));
fprintf(f, "\t\t\t\t\t<description>TODO</description>\n");
fprintf(f, "\t\t\t\t\t<value %s description=\"TODO\" minValue=\"%i\" maxValue=\"%i\" defaultValue=\"%i\" %s/>\n", id.min>id.max ? "" : "token=\"N\"", id.min, id.max, *id.storage, id.min>id.max ? "readOnly=\"true\"" : "");
fprintf(f, "\t\t\t\t\t<value %s description=\"TODO\" minValue=\"%i\" maxValue=\"%i\" defaultValue=\"%i\" %s/>\n", id.min>id.max ? "" : "token=\"N\"", id.min, id.max, *id.storage.i, id.min>id.max ? "readOnly=\"true\"" : "");
fprintf(f, "\t\t\t\t</variable>\n");
}
+1 -1
View File
@@ -83,7 +83,7 @@ struct weaponmove
swayspeed *= plspeed/2;
swayupspeed *= plspeed/2;
swap(float, sway.x, sway.y);
swap(sway.x, sway.y);
sway.y = -sway.y;
swayupspeed = fabs(swayupspeed); // sway a semicirle only
+1 -1
View File
@@ -127,7 +127,7 @@ VAR(mergestrips, 0, 1, 1);
int type = GL_TRIANGLE_STRIP, len = verts.length()-firstindex; \
if(mergestrips) switch(len) { \
case 3: type = GL_TRIANGLES; break; \
case 4: type = GL_QUADS; swap(vertex, verts.last(), verts[verts.length()-2]); break; \
case 4: type = GL_QUADS; swap(verts.last(), verts[verts.length()-2]); break; \
} \
addstrip(type, striptex, firstindex, len); \
floorstrip = deltastrip = false; \
+25 -5
View File
@@ -22,13 +22,33 @@ typedef unsigned int uint;
#define ASSERT(c) if(c) {}
#endif
#define swap(t,a,b) { t m=a; a=b; b=m; }
#ifndef max
#define max(a,b) (((a) > (b)) ? (a) : (b))
#ifdef swap
#undef swap
#endif
#ifndef min
#define min(a,b) (((a) < (b)) ? (a) : (b))
template<class T>
void swap(T &a, T &b)
{
T t = a;
a = b;
b = t;
}
#ifdef max
#undef max
#endif
#ifdef min
#undef min
#endif
template<class A, class B>
A max(const A &a, const B &b)
{
return a > b ? a : b;
}
template<class A, class B>
A min(const A &a, const B &b)
{
return a < b ? a : b;
}
#define rnd(max) (rand()%(max))
#define rndreset() (srand(1))
#define rndtime() { loopi(lastmillis&0xF) rnd(i+1); }
+2 -2
View File
@@ -207,9 +207,9 @@ struct tristrip
}
int from = findedge(first, triangles[cur]),
to = findedge(first, triangles[cur], first.v[from]);
if(from+1!=to) swap(int, from, to);
if(from+1!=to) swap(from, to);
strip.add(first.v[(to+1)%3]);
if(reverse) swap(int, from, to);
if(reverse) swap(from, to);
strip.add(first.v[from]);
strip.add(first.v[to]);