Skip to content
Permalink
Browse files

integrated automatic embedded map config files

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 Apr 27, 2015
1 parent e3fc073 commit e318ecd68e5af9b66d6b45feb79dda38a9f1cd59
@@ -26,4 +26,4 @@ source/src/ac_server
source/src/cube.h.gch
source/src/Makefile_local
clientlog*.txt

dumpmapconfig.txt
@@ -271,7 +271,7 @@ tempalias __rebuildmapmodelmenus [
looplist $__mapmodelcategories [key menu] [delmenu $menu]
looplist (getmapmodelattributes explodekeywords sortby: keywords sortby: desc usage distribution) [path keyword desc usage dist] [
path = (concatword "mapmodels/" $path)
idxs = (mapmodelbyname $path)
idxs = (mapmodelslotbyname $path)
if (|| (! (strlen $keyword)) (< (findlist $__mapmodelcategories $keyword) 0)) [
keyword = unsorted
if (strcmp $dist "official") [ keyword = unsoo ] // unless someone writes the missing config files ;)
@@ -790,9 +790,14 @@ COMMANDF(soundmuted, "i", (int *n)
intret(audiomgr.soundmuted(*n));
});

VAR(mapsoundchanged, 0, 0, 1);

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

VARF(soundchannels, 4, 32, 1024, audiomgr.setchannels(soundchannels); );
@@ -807,6 +812,11 @@ COMMANDF(registersound, "siii", (char *name, int *vol, int *loop, int *audiblera
COMMANDF(mapsound, "si", (char *name, int *maxuses)
{
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)
@@ -32,6 +32,7 @@

extern sqr *world, *wmip[]; // map data, the mips are sequential 2D arrays in memory
extern header hdr; // current map header
extern _mapconfigdata mapconfigdata; // current mapconfig
extern int sfactor, ssize; // ssize = 2^sfactor
extern int cubicsize, mipsize; // cubicsize = ssize^2
extern physent *camera1; // camera representing perspective of player, usually player1
@@ -68,6 +69,10 @@ extern int verbose;
#define MAXCL 16
#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

#endif
@@ -301,12 +301,13 @@ extern SDL_Surface *forcergbsurface(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 *lookuptexture(int tex, Texture *failtex = notexture, bool trydl = false);
extern const char *gettextureslot(int i);
extern bool reloadtexture(Texture &t);
extern bool reloadtexture(const char *name);
extern void reloadtextures();
Texture *createtexturefromsurface(const char *name, SDL_Surface *s);
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)
{ return lookuptexture(tex, noworldtexture, trydl); }
@@ -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 rldecodecubes(ucharbuf &f, sqr *s, int len, int version, bool silent);
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 writeallxmaps();
extern int loadallxmaps();
@@ -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 updateclientname(playerent *d);
extern void writemapmodelattributes();
extern const char *mmshortname(const char *name);

// weapon
extern void shoot(playerent *d, vec &to);
@@ -468,8 +468,9 @@ float dynfov()
else return (float)fov;
}

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

float fovy, aspect;
int farplane;

@@ -107,31 +107,37 @@ VAR(mapmodelchanged, 0, 0, 1);

vector<mapmodelinfo> 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)
{
intret(mapmodels.length());
mapmodelinfo &mmi = mapmodels.add();
mmi.rad = *rad;
mmi.h = *h;
mmi.zoff = *zoff;
mmi.m = NULL;
formatstring(mmi.name)("%s%s", mmpath, name);
mapmodelchanged = 1;
flagmapconfigchange();
}
COMMAND(mapmodel, "iiiss");

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

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

COMMAND(mapmodel, "iiiss");
COMMAND(mapmodelreset, "");

COMMANDF(mapmodelname, "i", (int *idx) { result(mapmodels.inrange(*idx) ? mapmodels[*idx].name : ""); });
COMMANDF(mapmodelbyname, "s", (char *name)
COMMANDF(mapmodelslotname, "i", (int *idx) { result(mapmodels.inrange(*idx) ? mmshortname(mapmodels[*idx].name) : ""); }); // returns the model name that is configured in a certain slot
COMMANDF(mapmodelslotbyname, "s", (char *name) // returns the slot(s) that a certain mapmodel is configured in
{
string res = "";
loopv(mapmodels) if(!strcmp(name, mapmodels[i].name)) concatformatstring(res, "%s%d", *res ? " " : "", i);
@@ -481,28 +481,49 @@ Texture *createtexturefromsurface(const char *name, SDL_Surface *s)
struct Slot
{
string name;
float scale;
float scale, orgscale;
Texture *tex;
bool loaded;
};

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)
{
intret(slots.length());
Slot &s = slots.add();
copystring(s.name, name);
path(s.name);
s.tex = NULL;
s.loaded = false;
s.orgscale = *scale;
s.scale = (*scale > 0 && *scale <= 2.0f) ? *scale : 1.0f;
flagmapconfigchange();
}

COMMAND(texturereset, "");
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 *t = failtex;
@@ -511,13 +532,13 @@ Texture *lookuptexture(int tex, Texture *failtex, bool trydl)
Slot &s = slots[tex];
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);
if(!trydl)
{
if(s.tex==notexture) s.tex = failtex;
s.loaded = true;
}
if(s.tex==notexture) s.tex = failtex;
s.loaded = true;
}
}
if(s.tex) t = s.tex;
}
@@ -555,38 +576,52 @@ void reloadtextures()
}

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" };
if(reload) basename = skybox;
else copystring(skybox, basename);
const char *legacyprefix = "textures/skymaps/";
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)
{
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);
if(sky[i] == notexture && !reload && autodownload)
{
defformatstring(dl)("packages/%s", basename);
defformatstring(dl)("packages/%s%s", legacyprefix, loadsky);
requirepackage(PCK_SKYBOX, dl);
break;
}
}
}

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

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

void draw_envbox_face(float s0, float t0, float x0, float y0, float z0,
float s1, float t1, float x1, float y1, float z1,
@@ -4,7 +4,7 @@ VARP(saveshadows, 0, 1, 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);

const int dbgstenc = 0;
@@ -8,6 +8,7 @@ sqr *world = NULL;
int sfactor, ssize, cubicsize, mipsize;

header hdr;
_mapconfigdata mapconfigdata;

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

enum { MHF_AUTOMAPCONFIG = 1<<0 };

#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)

@@ -56,10 +58,24 @@ struct header // map file format header
uchar watercolor[4];
int maprevision;
int ambient;
int reserved[12];
int flags; // MHF_*
int reserved[11];
//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 header hdr;

0 comments on commit e318ecd

Please sign in to comment.
You can’t perform that action at this time.