Skip to content

Commit

Permalink
integrated automatic embedded map config files
Browse files Browse the repository at this point in the history
This patch enables an option to keep the map config embedded in the map
file - with autogenerated content. Any changes to map config data will be
written with the map. This includes data by loadnotexture, loadsky,
mapmodel, texture, fog, fogcolour, mapsound and shadowyaw. Once enabled,
all changes with those commands become persistent to the map.

New variables:

mapsoundchanged
  Set to "1" with every command that changes mapsound slots. Should be
  used to trigger a rebuild of mapsound menus.

New/changed commands:

mapsound
  Now returns the number of the created slot.

mapmodel
  Now returns the number of the created slot.

texture
  Now returns the number of the created slot.

loadsky
  Is now a builtin string variable (instead of a command), which means,
  that the current value can easily be retrieved or edited.
  The skymap name in the argument is now required to start with
  "textures/skymaps/" - but that part of the path can be omitted.
  examples:
    loadsky steini/steini2 (loads textures/skymaps/steini/steini2_*)
    loadsky textures/skymaps/steini/steini2 (same)
    loadsky ../foo/bar (loads textures/foo/bar_*)
    echo $loadsky

getnotexture
  Returns the current "notexture" path. (Set by loadnotexture)

dumpmapconfig (available for debug binaries only)
  Writes the current automatically generated map config to
  dumpmapconfig.txt.

DOCREF mapsoundchanged mapsound mapmodel texture loadsky getnotexture
  • Loading branch information
ac-stef committed May 18, 2015
1 parent e3fc073 commit e318ecd
Show file tree
Hide file tree
Showing 12 changed files with 192 additions and 39 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Expand Up @@ -26,4 +26,4 @@ source/src/ac_server
source/src/cube.h.gch source/src/cube.h.gch
source/src/Makefile_local source/src/Makefile_local
clientlog*.txt clientlog*.txt

dumpmapconfig.txt
2 changes: 1 addition & 1 deletion config/menus_edit.cfg
Expand Up @@ -271,7 +271,7 @@ tempalias __rebuildmapmodelmenus [
looplist $__mapmodelcategories [key menu] [delmenu $menu] looplist $__mapmodelcategories [key menu] [delmenu $menu]
looplist (getmapmodelattributes explodekeywords sortby: keywords sortby: desc usage distribution) [path keyword desc usage dist] [ looplist (getmapmodelattributes explodekeywords sortby: keywords sortby: desc usage distribution) [path keyword desc usage dist] [
path = (concatword "mapmodels/" $path) path = (concatword "mapmodels/" $path)
idxs = (mapmodelbyname $path) idxs = (mapmodelslotbyname $path)
if (|| (! (strlen $keyword)) (< (findlist $__mapmodelcategories $keyword) 0)) [ if (|| (! (strlen $keyword)) (< (findlist $__mapmodelcategories $keyword) 0)) [
keyword = unsorted keyword = unsorted
if (strcmp $dist "official") [ keyword = unsoo ] // unless someone writes the missing config files ;) if (strcmp $dist "official") [ keyword = unsoo ] // unless someone writes the missing config files ;)
Expand Down
10 changes: 10 additions & 0 deletions source/src/audiomanager.cpp
Expand Up @@ -790,9 +790,14 @@ COMMANDF(soundmuted, "i", (int *n)
intret(audiomgr.soundmuted(*n)); intret(audiomgr.soundmuted(*n));
}); });


VAR(mapsoundchanged, 0, 0, 1);

COMMANDF(mapsoundreset, "", () COMMANDF(mapsoundreset, "", ()
{ {
audiomgr.mapsoundreset(); audiomgr.mapsoundreset();
mapconfigdata.mapsoundlines.shrink(0);
mapsoundchanged = 1;
flagmapconfigchange();
}); });


VARF(soundchannels, 4, 32, 1024, audiomgr.setchannels(soundchannels); ); VARF(soundchannels, 4, 32, 1024, audiomgr.setchannels(soundchannels); );
Expand All @@ -807,6 +812,11 @@ COMMANDF(registersound, "siii", (char *name, int *vol, int *loop, int *audiblera
COMMANDF(mapsound, "si", (char *name, int *maxuses) COMMANDF(mapsound, "si", (char *name, int *maxuses)
{ {
audiomgr.addsound(name, 255, *maxuses, true, mapsounds, false, 0); audiomgr.addsound(name, 255, *maxuses, true, mapsounds, false, 0);
intret(mapconfigdata.mapsoundlines.length());
copystring(mapconfigdata.mapsoundlines.add().name, name);
mapconfigdata.mapsoundlines.last().maxuses = *maxuses;
mapsoundchanged = 1;
flagmapconfigchange();
}); });


COMMANDF(registermusic, "s", (char *name) COMMANDF(registermusic, "s", (char *name)
Expand Down
5 changes: 5 additions & 0 deletions source/src/cube.h
Expand Up @@ -32,6 +32,7 @@


extern sqr *world, *wmip[]; // map data, the mips are sequential 2D arrays in memory extern sqr *world, *wmip[]; // map data, the mips are sequential 2D arrays in memory
extern header hdr; // current map header extern header hdr; // current map header
extern _mapconfigdata mapconfigdata; // current mapconfig
extern int sfactor, ssize; // ssize = 2^sfactor extern int sfactor, ssize; // ssize = 2^sfactor
extern int cubicsize, mipsize; // cubicsize = ssize^2 extern int cubicsize, mipsize; // cubicsize = ssize^2
extern physent *camera1; // camera representing perspective of player, usually player1 extern physent *camera1; // camera representing perspective of player, usually player1
Expand Down Expand Up @@ -68,6 +69,10 @@ extern int verbose;
#define MAXCL 16 #define MAXCL 16
#define CONFIGROTATEMAX 5 // keep 5 old versions of saved.cfg and init.cfg around #define CONFIGROTATEMAX 5 // keep 5 old versions of saved.cfg and init.cfg around


#define DEFAULT_FOG 180
#define DEFAULT_FOGCOLOUR 0x8099B3
#define DEFAULT_SHADOWYAW 45

#include "protos.h" // external function decls #include "protos.h" // external function decls


#endif #endif
Expand Down
6 changes: 5 additions & 1 deletion source/src/protos.h
Expand Up @@ -301,12 +301,13 @@ extern SDL_Surface *forcergbsurface(SDL_Surface *os);
extern SDL_Surface *forcergbasurface(SDL_Surface *os); extern SDL_Surface *forcergbasurface(SDL_Surface *os);
extern Texture *textureload(const char *name, int clamp = 0, bool mipmap = true, bool canreduce = false, float scale = 1.0f, bool trydl = false); extern Texture *textureload(const char *name, int clamp = 0, bool mipmap = true, bool canreduce = false, float scale = 1.0f, bool trydl = false);
extern Texture *lookuptexture(int tex, Texture *failtex = notexture, bool trydl = false); extern Texture *lookuptexture(int tex, Texture *failtex = notexture, bool trydl = false);
extern const char *gettextureslot(int i);
extern bool reloadtexture(Texture &t); extern bool reloadtexture(Texture &t);
extern bool reloadtexture(const char *name); extern bool reloadtexture(const char *name);
extern void reloadtextures(); extern void reloadtextures();
Texture *createtexturefromsurface(const char *name, SDL_Surface *s); Texture *createtexturefromsurface(const char *name, SDL_Surface *s);
extern void blitsurface(SDL_Surface *dst, SDL_Surface *src, int x, int y); extern void blitsurface(SDL_Surface *dst, SDL_Surface *src, int x, int y);
void loadsky(char *basename, bool reload); void loadskymap(bool reload);


static inline Texture *lookupworldtexture(int tex, bool trydl = true) static inline Texture *lookupworldtexture(int tex, bool trydl = true)
{ return lookuptexture(tex, noworldtexture, trydl); } { return lookuptexture(tex, noworldtexture, trydl); }
Expand Down Expand Up @@ -687,6 +688,8 @@ extern uchar *readmcfggz(char *name, int *size, int *sizegz);
extern void rlencodecubes(vector<uchar> &f, sqr *s, int len, bool preservesolids); extern void rlencodecubes(vector<uchar> &f, sqr *s, int len, bool preservesolids);
extern void rldecodecubes(ucharbuf &f, sqr *s, int len, int version, bool silent); extern void rldecodecubes(ucharbuf &f, sqr *s, int len, int version, bool silent);
extern void clearheaderextras(); extern void clearheaderextras();
extern void flagmapconfigchange();
extern void getcurrentmapconfig(vector<char> &f, bool onlysounds);
extern void xmapbackup(const char *nickprefix, const char *nick); extern void xmapbackup(const char *nickprefix, const char *nick);
extern void writeallxmaps(); extern void writeallxmaps();
extern int loadallxmaps(); extern int loadallxmaps();
Expand Down Expand Up @@ -745,6 +748,7 @@ extern void renderclient(playerent *d);
extern void renderclient(playerent *d, const char *mdlname, const char *vwepname, int tex = 0); extern void renderclient(playerent *d, const char *mdlname, const char *vwepname, int tex = 0);
extern void updateclientname(playerent *d); extern void updateclientname(playerent *d);
extern void writemapmodelattributes(); extern void writemapmodelattributes();
extern const char *mmshortname(const char *name);


// weapon // weapon
extern void shoot(playerent *d, vec &to); extern void shoot(playerent *d, vec &to);
Expand Down
5 changes: 3 additions & 2 deletions source/src/rendergl.cpp
Expand Up @@ -468,8 +468,9 @@ float dynfov()
else return (float)fov; else return (float)fov;
} }


VAR(fog, 64, 180, 1024); VARF(fog, 64, DEFAULT_FOG, 1024, flagmapconfigchange());
VAR(fogcolour, 0, 0x8099B3, 0xFFFFFF); VARF(fogcolour, 0, DEFAULT_FOGCOLOUR, 0xFFFFFF, flagmapconfigchange());

float fovy, aspect; float fovy, aspect;
int farplane; int farplane;


Expand Down
20 changes: 13 additions & 7 deletions source/src/rendermodel.cpp
Expand Up @@ -107,31 +107,37 @@ VAR(mapmodelchanged, 0, 0, 1);


vector<mapmodelinfo> mapmodels; vector<mapmodelinfo> mapmodels;
const char *mmpath = "mapmodels/"; const char *mmpath = "mapmodels/";
const char *mmshortname(const char *name) { return !strncmp(name, mmpath, strlen(mmpath)) ? name + strlen(mmpath) : name; }


void mapmodel(int *rad, int *h, int *zoff, char *snap, char *name) void mapmodel(int *rad, int *h, int *zoff, char *snap, char *name)
{ {
intret(mapmodels.length());
mapmodelinfo &mmi = mapmodels.add(); mapmodelinfo &mmi = mapmodels.add();
mmi.rad = *rad; mmi.rad = *rad;
mmi.h = *h; mmi.h = *h;
mmi.zoff = *zoff; mmi.zoff = *zoff;
mmi.m = NULL; mmi.m = NULL;
formatstring(mmi.name)("%s%s", mmpath, name); formatstring(mmi.name)("%s%s", mmpath, name);
mapmodelchanged = 1; mapmodelchanged = 1;
flagmapconfigchange();
} }
COMMAND(mapmodel, "iiiss");


void mapmodelreset() void mapmodelreset()
{ {
if(execcontext==IEXC_MAPCFG) mapmodels.shrink(0); if(execcontext==IEXC_MAPCFG)
mapmodelchanged = 1; {
mapmodels.shrink(0);
mapmodelchanged = 1;
flagmapconfigchange();
}
} }
COMMAND(mapmodelreset, "");


mapmodelinfo &getmminfo(int i) { return mapmodels.inrange(i) ? mapmodels[i] : *(mapmodelinfo *)0; } mapmodelinfo &getmminfo(int i) { return mapmodels.inrange(i) ? mapmodels[i] : *(mapmodelinfo *)0; }


COMMAND(mapmodel, "iiiss"); COMMANDF(mapmodelslotname, "i", (int *idx) { result(mapmodels.inrange(*idx) ? mmshortname(mapmodels[*idx].name) : ""); }); // returns the model name that is configured in a certain slot
COMMAND(mapmodelreset, ""); COMMANDF(mapmodelslotbyname, "s", (char *name) // returns the slot(s) that a certain mapmodel is configured in

COMMANDF(mapmodelname, "i", (int *idx) { result(mapmodels.inrange(*idx) ? mapmodels[*idx].name : ""); });
COMMANDF(mapmodelbyname, "s", (char *name)
{ {
string res = ""; string res = "";
loopv(mapmodels) if(!strcmp(name, mapmodels[i].name)) concatformatstring(res, "%s%d", *res ? " " : "", i); loopv(mapmodels) if(!strcmp(name, mapmodels[i].name)) concatformatstring(res, "%s%d", *res ? " " : "", i);
Expand Down
65 changes: 50 additions & 15 deletions source/src/texture.cpp
Expand Up @@ -481,28 +481,49 @@ Texture *createtexturefromsurface(const char *name, SDL_Surface *s)
struct Slot struct Slot
{ {
string name; string name;
float scale; float scale, orgscale;
Texture *tex; Texture *tex;
bool loaded; bool loaded;
}; };


vector<Slot> slots; vector<Slot> slots;


void texturereset() { if(execcontext==IEXC_MAPCFG) slots.setsize(0); } COMMANDF(texturereset, "", ()
{
if(execcontext==IEXC_MAPCFG)
{
slots.setsize(0);
flagmapconfigchange();
}
});


void texture(float *scale, char *name) void texture(float *scale, char *name)
{ {
intret(slots.length());
Slot &s = slots.add(); Slot &s = slots.add();
copystring(s.name, name); copystring(s.name, name);
path(s.name);
s.tex = NULL; s.tex = NULL;
s.loaded = false; s.loaded = false;
s.orgscale = *scale;
s.scale = (*scale > 0 && *scale <= 2.0f) ? *scale : 1.0f; s.scale = (*scale > 0 && *scale <= 2.0f) ? *scale : 1.0f;
flagmapconfigchange();
} }


COMMAND(texturereset, "");
COMMAND(texture, "fs"); COMMAND(texture, "fs");


const char *gettextureslot(int i)
{
static string res;
if(slots.inrange(i))
{
Slot &s = slots[i];
defformatstring(d)("%d", int(s.orgscale));
formatstring(res)("texture %s \"%s\"", s.orgscale == int(s.orgscale) ? d : floatstr(s.orgscale), s.name);
return res;
}
else return NULL;
}

Texture *lookuptexture(int tex, Texture *failtex, bool trydl) Texture *lookuptexture(int tex, Texture *failtex, bool trydl)
{ {
Texture *t = failtex; Texture *t = failtex;
Expand All @@ -511,13 +532,13 @@ Texture *lookuptexture(int tex, Texture *failtex, bool trydl)
Slot &s = slots[tex]; Slot &s = slots[tex];
if(!s.loaded) if(!s.loaded)
{ {
defformatstring(pname)("packages/textures/%s", s.name); defformatstring(pname)("packages/textures/%s", path(s.name, true));
s.tex = textureload(pname, 0, true, true, s.scale, trydl); s.tex = textureload(pname, 0, true, true, s.scale, trydl);
if(!trydl) if(!trydl)
{ {
if(s.tex==notexture) s.tex = failtex; if(s.tex==notexture) s.tex = failtex;
s.loaded = true; s.loaded = true;
} }
} }
if(s.tex) t = s.tex; if(s.tex) t = s.tex;
} }
Expand Down Expand Up @@ -555,38 +576,52 @@ void reloadtextures()
} }


Texture *sky[6] = {NULL, NULL, NULL, NULL, NULL, NULL}; Texture *sky[6] = {NULL, NULL, NULL, NULL, NULL, NULL};
static string skybox;


void loadsky(char *basename, bool reload) SVARF(loadsky, "", { loadskymap(false); });

void loadskymap(bool reload)
{ {
const char *side[] = { "lf", "rt", "ft", "bk", "dn", "up" }; const char *side[] = { "lf", "rt", "ft", "bk", "dn", "up" };
if(reload) basename = skybox; const char *legacyprefix = "textures/skymaps/";
else copystring(skybox, basename); if(!reload)
{
int n = strlen(legacyprefix);
if(!strncmp(loadsky, legacyprefix, n))
{ // remove the prefix
char *t = loadsky;
loadsky = newstring(loadsky + n);
delstring(t);
}
flagmapconfigchange();
}
loopi(6) loopi(6)
{ {
defformatstring(name)("packages/%s_%s.jpg", basename, side[i]); defformatstring(name)("packages/%s%s_%s.jpg", legacyprefix, loadsky, side[i]);
sky[i] = textureload(name, 3); sky[i] = textureload(name, 3);
if(sky[i] == notexture && !reload && autodownload) if(sky[i] == notexture && !reload && autodownload)
{ {
defformatstring(dl)("packages/%s", basename); defformatstring(dl)("packages/%s%s", legacyprefix, loadsky);
requirepackage(PCK_SKYBOX, dl); requirepackage(PCK_SKYBOX, dl);
break; break;
} }
} }
} }


COMMANDF(loadsky, "s", (char *name) { loadsky(name, false); intret(0); });
void loadnotexture(char *c) void loadnotexture(char *c)
{ {
noworldtexture = notexture; // reset to default noworldtexture = notexture; // reset to default
*mapconfigdata.notexturename = '\0';
if(c[0]) if(c[0])
{ {
defformatstring(p)("packages/textures/%s", c); defformatstring(p)("packages/textures/%s", c);
noworldtexture = textureload(p); noworldtexture = textureload(p);
if(noworldtexture==notexture) conoutf("could not load alternative texture '%s'.", p); if(noworldtexture==notexture) conoutf("could not load alternative texture '%s'.", p);
} }
flagmapconfigchange();
} }

COMMAND(loadnotexture, "s"); COMMAND(loadnotexture, "s");
COMMANDF(getnotexture, "", () { result(mapconfigdata.notexturename); });


void draw_envbox_face(float s0, float t0, float x0, float y0, float z0, void draw_envbox_face(float s0, float t0, float x0, float y0, float z0,
float s1, float t1, float x1, float y1, float z1, float s1, float t1, float x1, float y1, float z1,
Expand Down
2 changes: 1 addition & 1 deletion source/src/vertmodel.h
Expand Up @@ -4,7 +4,7 @@ VARP(saveshadows, 0, 1, 1);


VARP(dynshadowquad, 0, 0, 1); VARP(dynshadowquad, 0, 0, 1);


VAR(shadowyaw, 0, 45, 360); VARF(shadowyaw, 0, DEFAULT_SHADOWYAW, 360, flagmapconfigchange());
vec shadowdir(0, 0, -1), shadowpos(0, 0, 0); vec shadowdir(0, 0, -1), shadowpos(0, 0, 0);


const int dbgstenc = 0; const int dbgstenc = 0;
Expand Down
2 changes: 2 additions & 0 deletions source/src/world.cpp
Expand Up @@ -8,6 +8,7 @@ sqr *world = NULL;
int sfactor, ssize, cubicsize, mipsize; int sfactor, ssize, cubicsize, mipsize;


header hdr; header hdr;
_mapconfigdata mapconfigdata;


// main geometric mipmapping routine, recursively rebuild mipmaps within block b. // main geometric mipmapping routine, recursively rebuild mipmaps within block b.
// tries to produce cube out of 4 lower level mips as well as possible, // tries to produce cube out of 4 lower level mips as well as possible,
Expand Down Expand Up @@ -529,6 +530,7 @@ bool empty_world(int factor, bool force) // main empty world creation routine
{ // all-new map { // all-new map
int oldunsavededits = unsavededits; int oldunsavededits = unsavededits;
memset(&hdr, 0, sizeof(header)); memset(&hdr, 0, sizeof(header));
mapconfigdata.clear();
formatstring(hdr.maptitle)("Untitled Map by %s", player1->name); formatstring(hdr.maptitle)("Untitled Map by %s", player1->name);
setvar("waterlevel", (hdr.waterlevel = -100000)); setvar("waterlevel", (hdr.waterlevel = -100000));
setwatercolor(); setwatercolor();
Expand Down
18 changes: 17 additions & 1 deletion source/src/world.h
Expand Up @@ -40,6 +40,8 @@ enum // stuff encoded in sqr.tag
}; };
#define TAGANYCLIP (TAGCLIP|TAGPLCLIP) #define TAGANYCLIP (TAGCLIP|TAGPLCLIP)


enum { MHF_AUTOMAPCONFIG = 1<<0 };

#define MAXMAPVERSION 10 // defines the highest readable format #define MAXMAPVERSION 10 // defines the highest readable format
#define MAPVERSION 9 // default map format version to be written (bump if map format changes, see worldio.cpp) #define MAPVERSION 9 // default map format version to be written (bump if map format changes, see worldio.cpp)


Expand All @@ -56,10 +58,24 @@ struct header // map file format header
uchar watercolor[4]; uchar watercolor[4];
int maprevision; int maprevision;
int ambient; int ambient;
int reserved[12]; int flags; // MHF_*
int reserved[11];
//char mediareq[128]; // version 7 and 8 only. //char mediareq[128]; // version 7 and 8 only.
}; };


struct mapsoundline { string name; int maxuses; };

struct _mapconfigdata
{
string notexturename;
vector<mapsoundline> mapsoundlines;
void clear()
{
*notexturename = '\0';
mapsoundlines.shrink(0);
}
};

struct mapstats struct mapstats
{ {
struct header hdr; struct header hdr;
Expand Down

0 comments on commit e318ecd

Please sign in to comment.