From afad80be3ea0b7fdfdf6ac766092bea050258401 Mon Sep 17 00:00:00 2001 From: Lee Salzman Date: Sun, 30 Dec 2007 00:01:46 +0000 Subject: [PATCH] *** empty log message *** git-svn-id: svn://svn.code.sf.net/p/actiongame/code/trunk/ac@1525 e016b1c5-ed68-44aa-a2f7-31cac88cffde --- source/src/command.cpp | 61 +++++++++++++++++++++++++++++++------- source/src/command.h | 52 ++++++++++++++++++++++++++++++-- source/src/docs.cpp | 2 +- source/src/hudgun.h | 2 +- source/src/rendercubes.cpp | 2 +- source/src/tools.h | 30 +++++++++++++++---- source/src/tristrip.h | 4 +-- 7 files changed, 130 insertions(+), 23 deletions(-) diff --git a/source/src/command.cpp b/source/src/command.cpp index 6f944323..6599c657 100644 --- a/source/src/command.cpp +++ b/source/src/command.cpp @@ -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; - 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; + 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; + 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; - 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 = i1min ? 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\n", xmlstringenc(name, id.name, _MAXDEFSTR)); fprintf(f, "\t\t\t\t\tTODO\n"); - fprintf(f, "\t\t\t\t\t\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\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\n"); } diff --git a/source/src/hudgun.h b/source/src/hudgun.h index 049cb06b..2223723e 100644 --- a/source/src/hudgun.h +++ b/source/src/hudgun.h @@ -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 diff --git a/source/src/rendercubes.cpp b/source/src/rendercubes.cpp index 1a07b36b..7552922f 100644 --- a/source/src/rendercubes.cpp +++ b/source/src/rendercubes.cpp @@ -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; \ diff --git a/source/src/tools.h b/source/src/tools.h index 3a24f94f..9516e926 100644 --- a/source/src/tools.h +++ b/source/src/tools.h @@ -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 +void swap(T &a, T &b) +{ + T t = a; + a = b; + b = t; +} +#ifdef max +#undef max #endif +#ifdef min +#undef min +#endif +template +A max(const A &a, const B &b) +{ + return a > b ? a : b; +} +template +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); } diff --git a/source/src/tristrip.h b/source/src/tristrip.h index c3d54b48..5cf62565 100644 --- a/source/src/tristrip.h +++ b/source/src/tristrip.h @@ -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]);