diff --git a/source/src/clientgame.cpp b/source/src/clientgame.cpp index 765b157a..f140314e 100644 --- a/source/src/clientgame.cpp +++ b/source/src/clientgame.cpp @@ -18,9 +18,9 @@ bool intermission = false; playerent *player1 = newplayerent(); // our client vector players; // other clients -VAR(sensitivity, 0, 10, 1000); -VAR(sensitivityscale, 1, 1, 100); -VAR(invmouse, 0, 0, 1); +VARP(sensitivity, 0, 30, 1000); +VARP(sensitivityscale, 1, 10, 100); +VARP(invmouse, 0, 0, 1); int lastmillis = 0; int curtime; diff --git a/source/src/command.cpp b/source/src/command.cpp index 57cffac3..dc87d6dd 100644 --- a/source/src/command.cpp +++ b/source/src/command.cpp @@ -22,19 +22,22 @@ char *exchangestr(char *o, char *n) { delete[] o; return newstring(n); }; hashtable *idents = NULL; // contains ALL vars/commands/aliases +bool persistidents = true; + void alias(char *name, char *action) { ident *b = idents->access(name); if(!b) { name = newstring(name); - ident b = { ID_ALIAS, name, 0, 0, 0, 0, 0, newstring(action), 0, false }; + ident b = { ID_ALIAS, name, 0, 0, 0, 0, 0, newstring(action), 0, true }; idents->access(name, &b); } else if(b->type==ID_ALIAS) { if(b->action!=b->executing) delete[] b->action; b->action = newstring(action); + if(b->persist!=persistidents) b->persist = persistidents; } else conoutf("cannot redefine builtin %s with an alias", name); }; @@ -330,3 +333,34 @@ int strcmpa(char *a, char *b) { return strcmp(a,b)==0; }; COMMANDN(strcmp, strc int rndn(int a) { return a>0 ? rnd(a) : 0; }; COMMANDN(rnd, rndn, ARG_1EXP); +void writecfg() +{ + FILE *f = fopen("config/saved.cfg", "w"); + if(!f) return; + fprintf(f, "// automatically written on exit, DO NOT MODIFY\n// delete this file to have defaults.cfg overwrite these settings\n// modify settings in game, or put settings in autoexec.cfg to override anything\n\n"); + fprintf(f, "name %s\nteam %s\nskin %d\n", player1->name, player1->team, player1->skin); + fprintf(f, "loadcrosshair %s\n", crosshair->name+strlen("packages/misc/crosshairs/")); + extern int lowfps, highfps; + fprintf(f, "fpsrange %d %d\n", lowfps, highfps); + fprintf(f, "\n"); + enumerate(*idents, ident, id, + if(id.type==ID_VAR && id.persist) + { + fprintf(f, "%s %d\n", id.name, *id.storage); + }; + ); + fprintf(f, "\n"); + writebinds(f); + fprintf(f, "\n"); + enumerate(*idents, ident, id, + if(id.type==ID_ALIAS && id.persist && id.action[0]) + { + fprintf(f, "alias \"%s\" [%s]\n", id.name, id.action); + }; + ); + fprintf(f, "\n"); + fclose(f); +}; + +COMMAND(writecfg, ARG_NONE); + diff --git a/source/src/console.cpp b/source/src/console.cpp index ce5f66e0..cab1bca2 100644 --- a/source/src/console.cpp +++ b/source/src/console.cpp @@ -355,3 +355,11 @@ char *getcurcommand() return saycommandon ? commandbuf : NULL; }; +void writebinds(FILE *f) +{ + loopv(keyms) + { + if(*keyms[i].action) fprintf(f, "bind \"%s\" [%s]\n", keyms[i].name, keyms[i].action); + }; +}; + diff --git a/source/src/main.cpp b/source/src/main.cpp index 61484236..3c6ad5cd 100644 --- a/source/src/main.cpp +++ b/source/src/main.cpp @@ -24,6 +24,7 @@ void cleanup(char *msg) // single program exit point; void quit() // normal exit { writeservercfg(); + writecfg(); cleanup(NULL); exit(EXIT_SUCCESS); }; @@ -159,7 +160,7 @@ void screenres(int w, int h, int bpp = 0) COMMAND(screenres, ARG_3INT); -VAR(maxfps, 5, 200, 500); +VARP(maxfps, 5, 200, 500); void limitfps(int &millis, int curmillis) { @@ -304,17 +305,25 @@ int main(int argc, char **argv) newmenu("flags\tfrags\tpj\tping\tteam\tname"); newmenu("kick player"); newmenu("ban player"); + + extern bool persistidents; + persistidents = false; exec("config/keymap.cfg"); exec("config/menus.cfg"); exec("config/prefabs.cfg"); exec("config/sounds.cfg"); - exec("config/servers.cfg"); - exec("config/autoexec.cfg"); - + execfile("config/servers.cfg"); + persistidents = true; + + if(!execfile("config/saved.cfg")) exec("config/defaults.cfg"); + execfile("config/autoexec.cfg"); + + execute("start_game"); + log("localconnect"); localconnect(); changemap("maps/ac_complex"); - + log("mainloop"); int ignore = 5, grabmouse = 0; #ifdef _DEBUG diff --git a/source/src/physics.cpp b/source/src/physics.cpp index efa436f1..5f49bf76 100644 --- a/source/src/physics.cpp +++ b/source/src/physics.cpp @@ -159,7 +159,7 @@ bool collide(physent *d, bool spawn, float drop, float rise) return true; } -VAR(maxroll, 0, 3, 20); +VARP(maxroll, 0, 0, 20); // main physics routine, moves a player/monster for a curtime step // moveres indicated the physics precision (which is lower for monsters and multiplayer prediction) @@ -318,7 +318,7 @@ void moveplayer(physent *pl, int moveres, bool local, int curtime) // End add }; -VAR(minframetime, 5, 10, 20); +VARP(minframetime, 5, 10, 20); int physicsfraction = 0, physicsrepeat = 0; diff --git a/source/src/protos.h b/source/src/protos.h index b44e9681..b2d5e76a 100644 --- a/source/src/protos.h +++ b/source/src/protos.h @@ -21,6 +21,7 @@ extern void rendercommand(int x, int y); extern void renderconsole(); extern char *getcurcommand(); extern char *addreleaseaction(char *s); +extern void writebinds(FILE *f); // menus extern bool rendermenu(); diff --git a/source/src/rendercubes.cpp b/source/src/rendercubes.cpp index 89a7d37d..067d180d 100644 --- a/source/src/rendercubes.cpp +++ b/source/src/rendercubes.cpp @@ -52,7 +52,7 @@ VAR(mergestrips, 0, 1, 1); void finishstrips() { stripend(); }; sqr sbright, sdark; -VAR(lighterror,1,8,100); +VARP(lighterror,1,8,100); void render_flat(int wtex, int x, int y, int size, int h, sqr *l1, sqr *l2, sqr *l3, sqr *l4, bool isceil) // floor/ceil quads { @@ -261,7 +261,7 @@ void render_square(int wtex, float floor1, float floor2, float ceil1, float ceil int wx1, wy1, wx2, wy2; -VAR(watersubdiv, 1, 4, 64); +VARP(watersubdiv, 1, 4, 64); VARF(waterlevel, -128, -128, 127, if(!noteditmode()) hdr.waterlevel = waterlevel); inline void vertw(int v1, float v2, int v3, float t1, float t2, float t) diff --git a/source/src/renderextras.cpp b/source/src/renderextras.cpp index b4eabed5..272ec9e1 100644 --- a/source/src/renderextras.cpp +++ b/source/src/renderextras.cpp @@ -293,13 +293,13 @@ void invertperspective() glLoadMatrixd(inv); }; -VAR(crosshairsize, 0, 15, 50); +VARP(crosshairsize, 0, 15, 50); int dblend = 0; void damageblend(int n) { dblend += n; }; -VAR(hidestats, 0, 0, 1); -VAR(crosshairfx, 0, 1, 1); +VARP(hidestats, 0, 1, 1); +VARP(crosshairfx, 0, 1, 1); /*VAR(scopefov, 5, 50, 50); bool scoped = false; @@ -627,9 +627,9 @@ void renderbounceents() }; }; -VAR(gibnum, 0, 6, 1000); -VAR(gibttl, 0, 5000, 15000); -VAR(gibspeed, 1, 5, 20); +VARP(gibnum, 0, 6, 1000); +VARP(gibttl, 0, 5000, 15000); +VARP(gibspeed, 1, 5, 20); void addgib(playerent *d) { diff --git a/source/src/rendergl.cpp b/source/src/rendergl.cpp index c88e75cf..91c1fb04 100644 --- a/source/src/rendergl.cpp +++ b/source/src/rendergl.cpp @@ -253,7 +253,7 @@ void addstrip(int type, int tex, int start, int n) s.num = n; }; -VARF(gamma, 30, 100, 300, +VARFP(gamma, 30, 100, 300, { float f = gamma/100.0f; if(SDL_SetGamma(f,f,f)==-1) @@ -300,14 +300,14 @@ void transplayer() glTranslated(-camera1->o.x, -camera1->o.z, -camera1->o.y); }; -VAR(fov, 90, 105, 120); +VARP(fov, 90, 105, 120); int xtraverts; VAR(fog, 64, 180, 1024); VAR(fogcolour, 0, 0x8099B3, 0xFFFFFF); -VAR(hudgun,0,1,1); +VARP(hudgun,0,1,1); char *hudgunnames[] = { "knife", "pistol", "shotgun", "subgun", "sniper", "assault", "grenade"}; diff --git a/source/src/worldrender.cpp b/source/src/worldrender.cpp index 80e67783..425d7686 100644 --- a/source/src/worldrender.cpp +++ b/source/src/worldrender.cpp @@ -66,7 +66,7 @@ int min_lod; int lod_factor() { return lod; }; -VAR(minlod, LOW_LOD, LOW_LOD, MAX_LOD); +VARP(minlod, LOW_LOD, LOW_LOD, MAX_LOD); int stats[LARGEST_FACTOR];