Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Index: audiomanager.cpp
- ===================================================================
- --- audiomanager.cpp (revision 7532)
- +++ audiomanager.cpp (working copy)
- @@ -290,6 +290,7 @@
- void audiomanager::mapsoundreset()
- {
- mapsounds.shrink(0);
- + packagesmanager::reset(PCK_AUDIO);
- locations.deleteworldobjsounds();
- }
- @@ -806,6 +807,9 @@
- COMMANDF(mapsound, "si", (char *name, int *maxuses)
- {
- audiomgr.addsound(name, 255, *maxuses, true, mapsounds, false, 0);
- + defformatstring(fullname)("packages/audio/%s", name);
- + unixpath(path(fullname));
- + packagesmanager::linktomap(fullname);
- });
- COMMANDF(registermusic, "s", (char *name)
- Index: clientgame.cpp
- ===================================================================
- --- clientgame.cpp (revision 7532)
- +++ clientgame.cpp (working copy)
- @@ -1757,3 +1757,255 @@
- }
- COMMAND(serverextension, "ss");
- +
- +// packages browser
- +// certainly not the best file to put this though
- +namespace packagesmanager
- +{
- + hashtable<const char *, package *> packages; // installed packages (hashtable vs vector?)
- + int offsets[PCK_NUM] = { 0, 0, 0, 0, 0 };
- + void *texturesmenu = NULL, *mapmodelsmenu = NULL;
- +
- + // basic managment
- + void add(package *pck, bool map)
- + {
- + package *cpy = new package();
- + *cpy = *pck;
- + cpy->inmap = map;
- + packages.access(newstring(pck->name), cpy);
- + }
- +
- + bool linktomap(char *name)
- + {
- + package **p = packages.access(name);
- + if(p && *p)
- + {
- + (*p)->inmap = true;
- + (*p)->offset = offsets[(*p)->type]++;
- + //conoutf("Linked \"%s\" (%d)", (*p)->shortname, (*p)->offset);
- + return true;
- + }
- + else return false;
- + }
- +
- + void reset(int type)
- + {
- + enumerate(packages, package *, pck,
- + {
- + if(type < 0 || type == pck->type)
- + {
- + pck->inmap = false;
- + pck->offset = -1;
- + }
- + });
- + loopi(offsets) if(type < 0 || type == i) offsets[i] = 0;
- + }
- +
- + int offsetsort(package **a, package **b)
- + {
- + return (*a)->offset == (*b)->offset ? 0 : ((*a)->offset < (*b)->offset ? -1 : 1);
- + }
- +
- + // menus
- + void refreshtexmenu(void *menu, bool init)
- + {
- + static vector<mline> lines;
- + menureset(menu);
- + lines.shrink(0);
- +
- + enumerate(packages, package *, pck,
- + {
- + if(pck->type == PCK_TEXTURE)
- + {
- + mline &l = lines.add();
- + copystring(l.name, pck->shortname);
- + formatstring(l.cmd)("toggletexture \"%s\"", pck->name);
- + menuimagemanual(menu, pck->name, NULL, l.name, l.cmd, NULL, l.name);
- + }
- + });
- + }
- +
- + void refreshmdlmenu(void *menu, bool init)
- + {
- + static vector<mline> lines;
- + menureset(menu);
- + lines.shrink(0);
- +
- + enumerate(packages, package *, pck,
- + {
- + if(pck->type == PCK_MAPMODEL)
- + {
- + mline &l = lines.add();
- + copystring(l.name, pck->shortname);
- + formatstring(l.cmd)("togglemapmodel \"%s\"", pck->name);
- + defformatstring(hover)("chmenumdl pckmapmodels \"mapmodels/%s\" all 50 4", pck->shortname);
- + menumanual(menu, l.name, NULL, NULL, NULL, newstring(hover));
- + }
- + });
- + }
- +
- + // remove/add action from the menus
- + void toggletexture(char *name)
- + {
- + package **pp = packages.access(name);
- + if(pp)
- + {
- + if(!(*pp)->inmap)
- + {
- + if(offsets[PCK_TEXTURE] >= 255) conoutf("\f3can't add more textures: 256-slot limit reached");
- + else
- + {
- + conoutf("added \"%s\" to the list of textures", (*pp)->shortname);
- + linktomap(name);
- + }
- + }
- + else
- + {
- + conoutf("removed \"%s\" from the list of textures", (*pp)->shortname);
- + (*pp)->inmap = false;
- + enumerate(packages, package *, pck,
- + {
- + if(pck->type == PCK_TEXTURE && pck->offset > (*pp)->offset)
- + --pck->offset;
- + });
- + (*pp)->offset = 0;
- + offsets[PCK_TEXTURE]--;
- + }
- + }
- + }
- + COMMAND(toggletexture, "s");
- +
- + // installed packages listing
- + // inspired from akimbo's platform code
- + // possible FIXME: too many redundancies ?
- + void browsetextures(char *path)
- + {
- + vector<char *> files;
- + defformatstring(realpath)("packages/textures%s", path ? path : "");
- + if(!path)
- + path = "";
- +
- + listdir(realpath, NULL, files);
- + loopv(files) if(files[i][0] != '.')
- + {
- + char *extension = strrchr(files[i], '.');
- + if(extension && (!strcmp(extension, ".jpg") || !strcmp(extension, ".png")))
- + {
- + // valid package
- + package pck;
- + defformatstring(fullname)("%s/%s", realpath, files[i]);
- + defformatstring(shortname)("%s/%s", path, files[i]);
- + pck.basename = newstring(files[i]);
- + pck.name = newstring(fullname);
- + pck.shortname = newstring(shortname+1);
- + pck.type = PCK_TEXTURE;
- + add(&pck, false);
- + }
- + else if(strcmp(files[i], "skymaps"))
- + {
- + // possibly a directory
- + defformatstring(newpath)("%s/%s", path, files[i]);
- + browsetextures(newpath);
- + }
- + }
- + }
- +
- + void browseskymaps(char *path)
- + {
- + vector<char *> files;
- + defformatstring(realpath)("packages/textures/skymaps%s", path ? path : "");
- + if(!path)
- + path = "";
- +
- + listdir(realpath, NULL, files);
- + loopv(files) if(files[i][0] != '.')
- + {
- + char *extension = strrchr(files[i], '.');
- + char *suffix = strrchr(files[i], '_');
- + int suffix_len = suffix ? strlen(suffix) : 0;
- + if(extension && (!strcmp(extension, ".jpg") || !strcmp(extension, ".png"))
- + && suffix_len > 3 && suffix[1] == 'f' && suffix[2] == 't')
- + {
- + // valid package
- + package pck;
- + string file = ""; copystring(file, files[i], suffix-files[i]+1);
- + defformatstring(fullname)("%s/%s", realpath, file);
- + defformatstring(shortname)("%s/%s", path, file);
- + pck.basename = newstring(file);
- + pck.name = newstring(fullname);
- + pck.shortname = newstring(shortname+1);
- + pck.type = PCK_SKYBOX;
- + add(&pck, false);
- + }
- + else
- + {
- + // possibly a directory
- + defformatstring(newpath)("%s/%s", path, files[i]);
- + browseskymaps(newpath);
- + }
- + }
- + }
- +
- + void browsesounds(char *path)
- + {
- + vector<char *> files;
- + defformatstring(realpath)("packages/audio%s", path ? path : "");
- + if(!path)
- + path = "";
- +
- + listdir(realpath, NULL, files);
- + loopv(files) if(files[i][0] != '.')
- + {
- + char *extension = strrchr(files[i], '.');
- + if(extension && !strcmp(extension, ".ogg"))
- + {
- + // valid package
- + package pck;
- + defformatstring(fullname)("%s/%s", realpath, files[i]);
- + defformatstring(shortname)("%s/%s", path, files[i]);
- + pck.basename = newstring(files[i]);
- + pck.name = newstring(fullname);
- + pck.shortname = newstring(shortname+1);
- + pck.type = PCK_AUDIO;
- + add(&pck, false);
- + }
- + else
- + {
- + // possibly a directory
- + defformatstring(newpath)("%s/%s", path, files[i]);
- + browsesounds(newpath);
- + }
- + }
- + }
- +
- + void browsemapmodels(char *path)
- + {
- + vector<char *> files;
- + defformatstring(realpath)("packages/models/mapmodels%s", path ? path : "");
- + if(!path)
- + path = "";
- +
- + listdir(realpath, NULL, files);
- + loopv(files) if(files[i][0] != '.')
- + {
- + char *extension = strrchr(files[i], '.');
- + if(extension && (!strcmp(extension, ".md2") || !strcmp(extension, ".md3")))
- + {
- + // valid package
- + package pck;
- + pck.basename = newstring(strrchr(path, '/')+1);
- + pck.name = newstring(realpath);
- + pck.shortname = newstring(path[0] == '/' ? path+1 : path);
- + pck.type = PCK_MAPMODEL;
- + add(&pck, false);
- + break;
- + }
- + else
- + {
- + // possibly a directory
- + defformatstring(newpath)("%s/%s", path, files[i]);
- + browsemapmodels(newpath);
- + }
- + }
- + }
- +}
- \ No newline at end of file
- Index: entity.h
- ===================================================================
- --- entity.h (revision 7532)
- +++ entity.h (working copy)
- @@ -663,16 +663,47 @@
- pckserver() : addr(NULL), pending(false), responsive(true), ping(-1) {}
- };
- -enum { PCK_TEXTURE, PCK_SKYBOX, PCK_MAPMODEL, PCK_AUDIO, PCK_MAP, PCK_NUM };
- +enum { PCK_TEXTURE = 0, PCK_SKYBOX, PCK_MAPMODEL, PCK_AUDIO, PCK_MAP, PCK_NUM };
- struct package
- {
- - char *name;
- - int type, number;
- - bool pending;
- + char *name, *shortname, *basename;
- + int type, number, offset;
- + bool pending, inmap;
- pckserver *source;
- CURL *curl;
- - package() : name(NULL), type(-1), number(0), pending(false), source(NULL), curl(NULL) {}
- + package() : name(NULL), shortname(NULL), basename(NULL), type(-1), number(0), offset(0), pending(false), inmap(false), source(NULL), curl(NULL) {}
- };
- +
- +struct Texture;
- +struct Slot
- +{
- + string name;
- + float scale;
- + Texture *tex;
- + bool loaded;
- +};
- +
- +// packages manager
- +namespace packagesmanager
- +{
- + extern hashtable<const char *, package *> packages;
- + extern int offsets[PCK_NUM];
- + extern void *texturesmenu, *mapmodelsmenu;
- +
- + void browsetextures(char *path = NULL);
- + void browsemapmodels(char *path = NULL);
- + void browsesounds(char *path = NULL);
- + void browseskymaps(char *path = NULL);
- +
- + void reset(int type = -1);
- + bool linktomap(char *name);
- +
- + int offsetsort(package **a, package **b);
- +
- + void refreshtexmenu(void *menu, bool init);
- + void refreshmdlmenu(void *menu, bool init);
- +}
- +
- #endif
- \ No newline at end of file
- Index: main.cpp
- ===================================================================
- --- main.cpp (revision 7532)
- +++ main.cpp (working copy)
- @@ -981,7 +981,7 @@
- }
- #endif
- -VARP(compatibilitymode, 0, 1, 1); // FIXME : find a better place to put this ?
- +VARP(compatibilitymode, 0, 0, 1); // FIXME : find a better place to put this ?
- int main(int argc, char **argv)
- {
- @@ -1129,6 +1129,27 @@
- nomodel = loadmodel("misc/gib01", -1); //FIXME: need actual placeholder model
- if(!notexture) fatal("could not find core models");
- + // list all installed packages.
- + // maybe it should not be run @ startup, although it is quite fast.
- + stopwatch watch;
- + watch.start();
- + packagesmanager::browsetextures();
- + packagesmanager::browsesounds();
- + packagesmanager::browsemapmodels();
- + packagesmanager::browseskymaps();
- + /*enumerate(packagesmanager::packages, package *, pack,
- + {
- + switch(pack->type)
- + {
- + case PCK_TEXTURE: conoutf("tex: %s | %s | %s", pack->name, pack->shortname, pack->basename); break;
- + case PCK_SKYBOX: conoutf("sbx: %s | %s | %s", pack->name, pack->shortname, pack->basename); break;
- + case PCK_MAPMODEL: conoutf("mdl: %s | %s | %s", pack->name, pack->shortname, pack->basename); break;
- + case PCK_AUDIO: conoutf("snd: %s | %s | %s", pack->name, pack->shortname, pack->basename); break;
- + default: break;
- + }
- + });*/
- + conoutf("listed %d installed packages (%d milliseconds)", packagesmanager::packages.numelems, watch.stop());
- +
- initlog("console");
- per_idents = false;
- // Main font file, all other font files execute from here.
- @@ -1156,6 +1177,10 @@
- giveadminmenu = addmenu("give admin", NULL, true, refreshsopmenu);
- docmenu = addmenu("reference", NULL, true, renderdocmenu);
- applymenu = addmenu("apply", "apply changes now?", true, refreshapplymenu);
- + packagesmanager::texturesmenu = addmenu("pcktextures", "textures", true, packagesmanager::refreshtexmenu);
- + packagesmanager::mapmodelsmenu = addmenu("pckmapmodels", "mapmodels", true, packagesmanager::refreshmdlmenu);
- + ((gmenu *)packagesmanager::texturesmenu)->showthumb = ((gmenu *)packagesmanager::mapmodelsmenu)->showthumb = false;
- + ((gmenu *)packagesmanager::texturesmenu)->preload = ((gmenu *)packagesmanager::mapmodelsmenu)->preload = false;
- exec("config/scontext.cfg");
- exec("config/locale.cfg");
- @@ -1235,7 +1260,7 @@
- initlog("mainloop");
- inputgrab(grabinput = true);
- -
- +
- inmainloop = true;
- #ifdef _DEBUG
- int lastflush = 0;
- Index: menus.cpp
- ===================================================================
- --- menus.cpp (revision 7532)
- +++ menus.cpp (working copy)
- @@ -60,7 +60,7 @@
- else curmenu->close();
- }
- if((curmenu = (gmenu *)m)) curmenu->open();
- -}
- +}
- void showmenu(const char *name, bool top)
- {
- @@ -275,7 +275,7 @@
- mitemimagemanual(gmenu *parent, const char *filename, const char *altfontname, char *text, char *action, char *hoveraction, color *bgcolor, const char *desc = NULL) : mitemmanual(parent, text, action, hoveraction, bgcolor, desc), filename(filename)
- {
- - image = filename ? textureload(filename, 3) : NULL;
- + image = filename && parent->preload ? textureload(filename, 3) : NULL;
- altfont = altfontname ? getfont(altfontname) : NULL;
- }
- virtual ~mitemimagemanual() {}
- @@ -287,10 +287,10 @@
- virtual void render(int x, int y, int w)
- {
- mitem::render(x, y, w);
- - if(image || altfont)
- + if((image || !parent->preload) || altfont)
- {
- int xs = 0;
- - if(image)
- + if(image && parent->showthumb)
- {
- glBindTexture(GL_TEXTURE_2D, image->id);
- glDisable(GL_BLEND);
- @@ -320,8 +320,9 @@
- }
- delete[] r;
- }
- - if(image && isselection() && !hidebigmenuimages && image->ys > FONTH)
- + if((image || !parent->preload) && isselection() && !hidebigmenuimages)
- {
- + if(!image && !(image = textureload(filename, 3))) return;
- w += FONTH;
- int xs = (2 * VIRTW - w) / 5, ys = (xs * image->ys) / image->xs;
- x = (6 * VIRTW + w - 2 * xs) / 4; y = VIRTH - ys / 2;
- @@ -843,10 +844,10 @@
- COMMAND(delmenu, "s");
- -void menumanual(void *menu, char *text, char *action, color *bgcolor, const char *desc)
- +void menumanual(void *menu, char *text, char *action, color *bgcolor, const char *desc, char *hoveraction)
- {
- gmenu &m = *(gmenu *)menu;
- - m.items.add(new mitemmanual(&m, text, action, NULL, bgcolor, desc));
- + m.items.add(new mitemmanual(&m, text, action, hoveraction, bgcolor, desc));
- }
- void menuimagemanual(void *menu, const char *filename, const char *altfontname, char *text, char *action, color *bgcolor, const char *desc)
- Index: protos.h
- ===================================================================
- --- protos.h (revision 7532)
- +++ protos.h (working copy)
- @@ -90,7 +90,7 @@
- extern void rendermenu();
- extern bool menuvisible();
- extern void menureset(void *menu);
- -extern void menumanual(void *menu, char *text, char *action = NULL, color *bgcolor = NULL, const char *desc = NULL);
- +extern void menumanual(void *menu, char *text, char *action = NULL, color *bgcolor = NULL, const char *desc = NULL, char *hoveraction = NULL);
- extern void menuimagemanual(void *menu, const char *filename1, const char *filename2, char *text, char *action = NULL, color *bgcolor = NULL, const char *desc = NULL);
- extern void menutitle(void *menu, const char *title = NULL);
- extern bool needscoresreorder;
- @@ -154,13 +154,13 @@
- bool (__cdecl *keyfunc)(void *, int, bool, int);
- char *initaction;
- char *usefont;
- - bool allowblink;
- + bool allowblink, showthumb, preload;
- const char *mdl;
- int anim, rotspeed, scale;
- int footlen;
- mdirlist *dirlist;
- - gmenu() : name(0), title(0), header(0), footer(0), initaction(0), usefont(0), allowblink(0), mdl(0), footlen(0), dirlist(0) {}
- + gmenu() : name(0), title(0), header(0), footer(0), initaction(0), usefont(0), allowblink(0), showthumb(true), preload(true), mdl(0), footlen(0), dirlist(0) {}
- virtual ~gmenu()
- {
- DELETEA(name);
- Index: rendermodel.cpp
- ===================================================================
- --- rendermodel.cpp (revision 7533)
- +++ rendermodel.cpp (working copy)
- @@ -97,11 +97,18 @@
- mmi.m = NULL;
- mmi.clipped = mmi.h >= 0.1f;
- formatstring(mmi.name)("mapmodels/%s", name);
- + defformatstring(fullname)("packages/models/mapmodels/%s", name);
- + unixpath(path(fullname));
- + packagesmanager::linktomap(fullname);
- }
- void mapmodelreset()
- {
- - if(execcontext==IEXC_MAPCFG) mapmodels.shrink(0);
- + if(execcontext==IEXC_MAPCFG)
- + {
- + mapmodels.shrink(0);
- + packagesmanager::reset(PCK_MAPMODEL);
- + }
- }
- mapmodelinfo &getmminfo(int i) { return mapmodels.inrange(i) ? mapmodels[i] : *(mapmodelinfo *)0; }
- Index: texture.cpp
- ===================================================================
- --- texture.cpp (revision 7532)
- +++ texture.cpp (working copy)
- @@ -478,19 +478,18 @@
- return t;
- }
- -struct Slot
- -{
- - string name;
- - float scale;
- - Texture *tex;
- - bool loaded;
- -};
- -
- vector<Slot> slots;
- -void texturereset() { if(execcontext==IEXC_MAPCFG) slots.setsize(0); }
- +void texturereset()
- +{
- + if(execcontext==IEXC_MAPCFG)
- + {
- + slots.setsize(0);
- + packagesmanager::reset(PCK_TEXTURE);
- + }
- +}
- -void texture(char *scale, char *name)
- +void texture(float *scale, char *name)
- {
- Slot &s = slots.add();
- copystring(s.name, name);
- @@ -498,6 +497,10 @@
- s.tex = NULL;
- s.loaded = false;
- s.scale = (*scale > 0 && *scale <= 2.0f) ? *scale : 1.0f;
- +
- + defformatstring(fullname)("packages/textures/%s", s.name);
- + unixpath(fullname);
- + packagesmanager::linktomap(fullname);
- }
- COMMAND(texturereset, "");
- Index: worldio.cpp
- ===================================================================
- --- worldio.cpp (revision 7532)
- +++ worldio.cpp (working copy)
- @@ -555,4 +555,63 @@
- return true;
- }
- -COMMANDN(savemap, save_world, "s");
- \ No newline at end of file
- +COMMANDN(savemap, save_world, "s");
- +
- +// generate map cfg.
- +// TODO ? avoid redundancies with default_map_settings.cfg
- +// (e.g., don't use texturesreset when it's not necessary?)
- +
- +void savemapcfg()
- +{
- + vector<package *> mappackages;
- + extern int fog, fogcolour, shadowyaw;
- + extern vector<Slot> slots;
- + enumerate(packagesmanager::packages, package *, pck,
- + {
- + if(pck->inmap) mappackages.add(pck);
- + });
- + mappackages.sort(packagesmanager::offsetsort);
- +
- + stream *f = openrawfile(mcfname, "w+");
- + if(!f)
- + {
- + conoutf("\f3failed to write the CFG file");
- + return;
- + }
- + f->printf("// Auto generated map-cfg file.\n");
- + f->printf("\n");
- +
- + // allowed idents (reminder)
- + // loadnotexture loadsky mapmodelreset mapmodel texturereset texture fog fogcolour mapsoundreset mapsound watercolour shadowyaw
- +
- + f->printf("fog %d\n", fog);
- + f->printf("fogcolour 0x%x\n", fogcolour);
- + f->printf("watercolour %d %d %d %d\n", hdr.watercolor[0], hdr.watercolor[1], hdr.watercolor[2], hdr.watercolor[3]);
- + f->printf("shadowyaw %d\n", shadowyaw);
- +
- + f->printf("\nmapmodelreset\n");
- + loopv(mappackages) if(mappackages[i]->type == PCK_MAPMODEL)
- + {
- + mapmodelinfo &mmi = getmminfo(mappackages[i]->offset);
- + f->printf("mapmodel %.2f %.2f %.2f 0 \"%s\" // %d\n",
- + &mmi ? mmi.rad : 0, &mmi ? mmi.h : 0, &mmi ? mmi.zoff : 0,
- + mappackages[i]->shortname, mappackages[i]->offset);
- + }
- +
- + f->printf("\ntexturereset\n");
- + loopv(mappackages) if(mappackages[i]->type == PCK_TEXTURE)
- + {
- + string scale = "0";
- + if(slots.inrange(mappackages[i]->offset) && abs(slots[mappackages[i]->offset].scale-1.0f) > 0.01f)
- + ftoa(scale, slots[mappackages[i]->offset].scale);
- + f->printf("texture %s \"%s\" // %d\n", scale, mappackages[i]->shortname, mappackages[i]->offset);
- + }
- +
- + f->printf("\nmapsoundreset\n");
- + loopv(mappackages) if(mappackages[i]->type == PCK_AUDIO)
- + {
- + f->printf("mapsound \"%s\" -1 // %d\n", mappackages[i]->shortname, mappackages[i]->offset);
- + }
- + f->close();
- +}
- +COMMAND(savemapcfg, "");
- \ No newline at end of file
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement