Advertisement
lucasgautheron

dyn mdl tex menu and map cfg generation

Aug 28th, 2013
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 21.63 KB | None | 0 0
  1. Index: audiomanager.cpp
  2. ===================================================================
  3. --- audiomanager.cpp    (revision 7532)
  4. +++ audiomanager.cpp    (working copy)
  5. @@ -290,6 +290,7 @@
  6.  void audiomanager::mapsoundreset()
  7.  {
  8.      mapsounds.shrink(0);
  9. +    packagesmanager::reset(PCK_AUDIO);
  10.      locations.deleteworldobjsounds();
  11.  }
  12.  
  13. @@ -806,6 +807,9 @@
  14.  COMMANDF(mapsound, "si", (char *name, int *maxuses)
  15.  {
  16.      audiomgr.addsound(name, 255, *maxuses, true, mapsounds, false, 0);
  17. +    defformatstring(fullname)("packages/audio/%s", name);
  18. +    unixpath(path(fullname));
  19. +    packagesmanager::linktomap(fullname);
  20.  });
  21.  
  22.  COMMANDF(registermusic, "s", (char *name)
  23. Index: clientgame.cpp
  24. ===================================================================
  25. --- clientgame.cpp  (revision 7532)
  26. +++ clientgame.cpp  (working copy)
  27. @@ -1757,3 +1757,255 @@
  28.  }
  29.  
  30.  COMMAND(serverextension, "ss");
  31. +
  32. +// packages browser
  33. +// certainly not the best file to put this though
  34. +namespace packagesmanager
  35. +{
  36. +    hashtable<const char *, package *> packages; // installed packages (hashtable vs vector?)
  37. +    int offsets[PCK_NUM] = { 0, 0, 0, 0, 0 };
  38. +    void *texturesmenu = NULL, *mapmodelsmenu = NULL;
  39. +
  40. +    // basic managment
  41. +    void add(package *pck, bool map)
  42. +    {
  43. +        package *cpy = new package();
  44. +        *cpy = *pck;
  45. +        cpy->inmap = map;
  46. +        packages.access(newstring(pck->name), cpy);
  47. +    }
  48. +
  49. +    bool linktomap(char *name)
  50. +    {
  51. +        package **p = packages.access(name);
  52. +        if(p && *p)
  53. +        {
  54. +            (*p)->inmap = true;
  55. +            (*p)->offset = offsets[(*p)->type]++;
  56. +            //conoutf("Linked \"%s\" (%d)", (*p)->shortname, (*p)->offset);
  57. +            return true;
  58. +        }
  59. +        else return false;
  60. +    }
  61. +
  62. +    void reset(int type)
  63. +    {
  64. +        enumerate(packages, package *, pck,
  65. +        {
  66. +            if(type < 0 || type == pck->type)
  67. +            {
  68. +                pck->inmap = false;
  69. +                pck->offset = -1;
  70. +            }
  71. +        });
  72. +        loopi(offsets) if(type < 0 || type == i) offsets[i] = 0;
  73. +    }
  74. +
  75. +    int offsetsort(package **a, package **b)
  76. +    {
  77. +        return (*a)->offset == (*b)->offset ? 0 : ((*a)->offset < (*b)->offset ? -1 : 1);
  78. +    }
  79. +
  80. +    // menus
  81. +    void refreshtexmenu(void *menu, bool init)
  82. +    {
  83. +        static vector<mline> lines;
  84. +        menureset(menu);
  85. +        lines.shrink(0);
  86. +
  87. +        enumerate(packages, package *, pck,
  88. +        {
  89. +            if(pck->type == PCK_TEXTURE)
  90. +            {
  91. +                mline &l = lines.add();
  92. +                copystring(l.name, pck->shortname);
  93. +                formatstring(l.cmd)("toggletexture \"%s\"", pck->name);
  94. +                menuimagemanual(menu, pck->name, NULL, l.name, l.cmd, NULL, l.name);
  95. +            }
  96. +        });
  97. +    }
  98. +
  99. +    void refreshmdlmenu(void *menu, bool init)
  100. +    {
  101. +        static vector<mline> lines;
  102. +        menureset(menu);
  103. +        lines.shrink(0);
  104. +
  105. +        enumerate(packages, package *, pck,
  106. +        {
  107. +            if(pck->type == PCK_MAPMODEL)
  108. +            {
  109. +                mline &l = lines.add();
  110. +                copystring(l.name, pck->shortname);
  111. +                formatstring(l.cmd)("togglemapmodel \"%s\"", pck->name);
  112. +                defformatstring(hover)("chmenumdl pckmapmodels \"mapmodels/%s\" all 50 4", pck->shortname);
  113. +                menumanual(menu, l.name, NULL, NULL, NULL, newstring(hover));
  114. +            }
  115. +        });
  116. +    }
  117. +
  118. +    // remove/add action from the menus
  119. +    void toggletexture(char *name)
  120. +    {
  121. +        package **pp = packages.access(name);
  122. +        if(pp)
  123. +        {
  124. +            if(!(*pp)->inmap)
  125. +            {
  126. +                if(offsets[PCK_TEXTURE] >= 255) conoutf("\f3can't add more textures: 256-slot limit reached");
  127. +                else
  128. +                {
  129. +                    conoutf("added \"%s\" to the list of textures", (*pp)->shortname);
  130. +                    linktomap(name);
  131. +                }
  132. +            }
  133. +            else
  134. +            {
  135. +                conoutf("removed \"%s\" from the list of textures", (*pp)->shortname);
  136. +                (*pp)->inmap = false;
  137. +                enumerate(packages, package *, pck,
  138. +                {
  139. +                    if(pck->type == PCK_TEXTURE && pck->offset > (*pp)->offset)
  140. +                        --pck->offset;
  141. +                });
  142. +                (*pp)->offset = 0;
  143. +                offsets[PCK_TEXTURE]--;
  144. +            }
  145. +        }
  146. +    }
  147. +    COMMAND(toggletexture, "s");
  148. +
  149. +    // installed packages listing
  150. +    // inspired from akimbo's platform code
  151. +    // possible FIXME: too many redundancies ?
  152. +    void browsetextures(char *path)
  153. +    {
  154. +        vector<char *> files;
  155. +        defformatstring(realpath)("packages/textures%s", path ? path : "");
  156. +        if(!path)
  157. +            path = "";
  158. +
  159. +        listdir(realpath, NULL, files);
  160. +        loopv(files) if(files[i][0] != '.')
  161. +        {
  162. +            char *extension = strrchr(files[i], '.');
  163. +            if(extension && (!strcmp(extension, ".jpg") || !strcmp(extension, ".png")))
  164. +            {
  165. +                // valid package
  166. +                package pck;
  167. +                defformatstring(fullname)("%s/%s", realpath, files[i]);
  168. +                defformatstring(shortname)("%s/%s", path, files[i]);
  169. +                pck.basename = newstring(files[i]);
  170. +                pck.name = newstring(fullname);
  171. +                pck.shortname = newstring(shortname+1);
  172. +                pck.type = PCK_TEXTURE;
  173. +                add(&pck, false);
  174. +            }
  175. +            else if(strcmp(files[i], "skymaps"))
  176. +            {
  177. +                // possibly a directory
  178. +                defformatstring(newpath)("%s/%s", path, files[i]);
  179. +                browsetextures(newpath);
  180. +            }
  181. +        }
  182. +    }
  183. +
  184. +    void browseskymaps(char *path)
  185. +    {
  186. +        vector<char *> files;
  187. +        defformatstring(realpath)("packages/textures/skymaps%s", path ? path : "");
  188. +        if(!path)
  189. +            path = "";
  190. +
  191. +        listdir(realpath, NULL, files);
  192. +        loopv(files) if(files[i][0] != '.')
  193. +        {
  194. +            char *extension = strrchr(files[i], '.');
  195. +            char *suffix = strrchr(files[i], '_');
  196. +            int suffix_len = suffix ? strlen(suffix) : 0;
  197. +            if(extension && (!strcmp(extension, ".jpg") || !strcmp(extension, ".png"))
  198. +                && suffix_len > 3 && suffix[1] == 'f' && suffix[2] == 't')
  199. +            {
  200. +                // valid package
  201. +                package pck;
  202. +                string file = ""; copystring(file, files[i], suffix-files[i]+1);
  203. +                defformatstring(fullname)("%s/%s", realpath, file);
  204. +                defformatstring(shortname)("%s/%s", path, file);
  205. +                pck.basename = newstring(file);
  206. +                pck.name = newstring(fullname);
  207. +                pck.shortname = newstring(shortname+1);
  208. +                pck.type = PCK_SKYBOX;
  209. +                add(&pck, false);
  210. +            }
  211. +            else
  212. +            {
  213. +                // possibly a directory
  214. +                defformatstring(newpath)("%s/%s", path, files[i]);
  215. +                browseskymaps(newpath);
  216. +            }
  217. +        }
  218. +    }
  219. +
  220. +    void browsesounds(char *path)
  221. +    {
  222. +        vector<char *> files;
  223. +        defformatstring(realpath)("packages/audio%s", path ? path : "");
  224. +        if(!path)
  225. +            path = "";
  226. +
  227. +        listdir(realpath, NULL, files);
  228. +        loopv(files) if(files[i][0] != '.')
  229. +        {
  230. +            char *extension = strrchr(files[i], '.');
  231. +            if(extension && !strcmp(extension, ".ogg"))
  232. +            {
  233. +                // valid package
  234. +                package pck;
  235. +                defformatstring(fullname)("%s/%s", realpath, files[i]);
  236. +                defformatstring(shortname)("%s/%s", path, files[i]);
  237. +                pck.basename = newstring(files[i]);
  238. +                pck.name = newstring(fullname);
  239. +                pck.shortname = newstring(shortname+1);
  240. +                pck.type = PCK_AUDIO;
  241. +                add(&pck, false);
  242. +            }
  243. +            else
  244. +            {
  245. +                // possibly a directory
  246. +                defformatstring(newpath)("%s/%s", path, files[i]);
  247. +                browsesounds(newpath);
  248. +            }
  249. +        }
  250. +    }
  251. +
  252. +    void browsemapmodels(char *path)
  253. +    {
  254. +        vector<char *> files;
  255. +        defformatstring(realpath)("packages/models/mapmodels%s", path ? path : "");
  256. +        if(!path)
  257. +            path = "";
  258. +
  259. +        listdir(realpath, NULL, files);
  260. +        loopv(files) if(files[i][0] != '.')
  261. +        {
  262. +            char *extension = strrchr(files[i], '.');
  263. +            if(extension && (!strcmp(extension, ".md2") || !strcmp(extension, ".md3")))
  264. +            {
  265. +                // valid package
  266. +                package pck;
  267. +                pck.basename = newstring(strrchr(path, '/')+1);
  268. +                pck.name = newstring(realpath);
  269. +                pck.shortname = newstring(path[0] == '/' ? path+1 : path);
  270. +                pck.type = PCK_MAPMODEL;
  271. +                add(&pck, false);
  272. +                break;
  273. +            }
  274. +            else
  275. +            {
  276. +                // possibly a directory
  277. +                defformatstring(newpath)("%s/%s", path, files[i]);
  278. +                browsemapmodels(newpath);
  279. +            }
  280. +        }
  281. +    }
  282. +}
  283. \ No newline at end of file
  284. Index: entity.h
  285. ===================================================================
  286. --- entity.h    (revision 7532)
  287. +++ entity.h    (working copy)
  288. @@ -663,16 +663,47 @@
  289.      pckserver() : addr(NULL), pending(false), responsive(true), ping(-1) {}
  290.  };
  291.  
  292. -enum { PCK_TEXTURE, PCK_SKYBOX, PCK_MAPMODEL, PCK_AUDIO, PCK_MAP, PCK_NUM };
  293. +enum { PCK_TEXTURE = 0, PCK_SKYBOX, PCK_MAPMODEL, PCK_AUDIO, PCK_MAP, PCK_NUM };
  294.  
  295.  struct package
  296.  {
  297. -    char *name;
  298. -    int type, number;
  299. -    bool pending;
  300. +    char *name, *shortname, *basename;
  301. +    int type, number, offset;
  302. +    bool pending, inmap;
  303.      pckserver *source;
  304.      CURL *curl;
  305.  
  306. -    package() : name(NULL), type(-1), number(0), pending(false), source(NULL), curl(NULL) {}
  307. +    package() : name(NULL), shortname(NULL), basename(NULL), type(-1), number(0), offset(0), pending(false), inmap(false), source(NULL), curl(NULL) {}
  308.  };
  309. +
  310. +struct Texture;
  311. +struct Slot
  312. +{
  313. +    string name;
  314. +    float scale;
  315. +    Texture *tex;
  316. +    bool loaded;
  317. +};
  318. +
  319. +// packages manager
  320. +namespace packagesmanager
  321. +{
  322. +    extern hashtable<const char *, package *> packages;
  323. +    extern int offsets[PCK_NUM];
  324. +    extern void *texturesmenu, *mapmodelsmenu;
  325. +
  326. +    void browsetextures(char *path = NULL);
  327. +    void browsemapmodels(char *path = NULL);
  328. +    void browsesounds(char *path = NULL);
  329. +    void browseskymaps(char *path = NULL);
  330. +
  331. +    void reset(int type = -1);
  332. +    bool linktomap(char *name);
  333. +
  334. +    int offsetsort(package **a, package **b);
  335. +
  336. +    void refreshtexmenu(void *menu, bool init);
  337. +    void refreshmdlmenu(void *menu, bool init);
  338. +}
  339. +
  340.  #endif
  341. \ No newline at end of file
  342. Index: main.cpp
  343. ===================================================================
  344. --- main.cpp    (revision 7532)
  345. +++ main.cpp    (working copy)
  346. @@ -981,7 +981,7 @@
  347.  }
  348.  #endif
  349.  
  350. -VARP(compatibilitymode, 0, 1, 1); // FIXME : find a better place to put this ?
  351. +VARP(compatibilitymode, 0, 0, 1); // FIXME : find a better place to put this ?
  352.  
  353.  int main(int argc, char **argv)
  354.  {
  355. @@ -1129,6 +1129,27 @@
  356.      nomodel = loadmodel("misc/gib01", -1);      //FIXME: need actual placeholder model
  357.      if(!notexture) fatal("could not find core models");
  358.  
  359. +    // list all installed packages.
  360. +    // maybe it should not be run @ startup, although it is quite fast.
  361. +    stopwatch watch;
  362. +    watch.start();
  363. +    packagesmanager::browsetextures();
  364. +    packagesmanager::browsesounds();
  365. +    packagesmanager::browsemapmodels();
  366. +    packagesmanager::browseskymaps();
  367. +    /*enumerate(packagesmanager::packages, package *, pack,
  368. +    {
  369. +        switch(pack->type)
  370. +        {
  371. +            case PCK_TEXTURE: conoutf("tex: %s | %s | %s", pack->name, pack->shortname, pack->basename); break;
  372. +            case PCK_SKYBOX: conoutf("sbx: %s | %s | %s", pack->name, pack->shortname, pack->basename); break;
  373. +            case PCK_MAPMODEL: conoutf("mdl: %s | %s | %s", pack->name, pack->shortname, pack->basename); break;
  374. +            case PCK_AUDIO: conoutf("snd: %s | %s | %s", pack->name, pack->shortname, pack->basename); break;
  375. +            default: break;
  376. +        }
  377. +    });*/
  378. +    conoutf("listed %d installed packages (%d milliseconds)", packagesmanager::packages.numelems, watch.stop());
  379. +
  380.      initlog("console");
  381.      per_idents = false;
  382.      // Main font file, all other font files execute from here.
  383. @@ -1156,6 +1177,10 @@
  384.      giveadminmenu = addmenu("give admin", NULL, true, refreshsopmenu);
  385.      docmenu = addmenu("reference", NULL, true, renderdocmenu);
  386.      applymenu = addmenu("apply", "apply changes now?", true, refreshapplymenu);
  387. +    packagesmanager::texturesmenu = addmenu("pcktextures", "textures", true, packagesmanager::refreshtexmenu);
  388. +    packagesmanager::mapmodelsmenu = addmenu("pckmapmodels", "mapmodels", true, packagesmanager::refreshmdlmenu);
  389. +    ((gmenu *)packagesmanager::texturesmenu)->showthumb = ((gmenu *)packagesmanager::mapmodelsmenu)->showthumb = false;
  390. +    ((gmenu *)packagesmanager::texturesmenu)->preload = ((gmenu *)packagesmanager::mapmodelsmenu)->preload = false;
  391.  
  392.      exec("config/scontext.cfg");
  393.      exec("config/locale.cfg");
  394. @@ -1235,7 +1260,7 @@
  395.      initlog("mainloop");
  396.  
  397.      inputgrab(grabinput = true);
  398. -
  399. +    
  400.      inmainloop = true;
  401.  #ifdef _DEBUG
  402.      int lastflush = 0;
  403. Index: menus.cpp
  404. ===================================================================
  405. --- menus.cpp   (revision 7532)
  406. +++ menus.cpp   (working copy)
  407. @@ -60,7 +60,7 @@
  408.          else curmenu->close();
  409.      }
  410.      if((curmenu = (gmenu *)m)) curmenu->open();
  411. -}
  412. +}
  413.  
  414.  void showmenu(const char *name, bool top)
  415.  {
  416. @@ -275,7 +275,7 @@
  417.  
  418.      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)
  419.      {
  420. -        image = filename ? textureload(filename, 3) : NULL;
  421. +        image = filename && parent->preload ? textureload(filename, 3) : NULL;
  422.          altfont = altfontname ? getfont(altfontname) : NULL;
  423.      }
  424.      virtual ~mitemimagemanual() {}
  425. @@ -287,10 +287,10 @@
  426.      virtual void render(int x, int y, int w)
  427.      {
  428.          mitem::render(x, y, w);
  429. -        if(image || altfont)
  430. +        if((image || !parent->preload) || altfont)
  431.          {
  432.              int xs = 0;
  433. -            if(image)
  434. +            if(image && parent->showthumb)
  435.              {
  436.                  glBindTexture(GL_TEXTURE_2D, image->id);
  437.                  glDisable(GL_BLEND);
  438. @@ -320,8 +320,9 @@
  439.                  }
  440.                  delete[] r;
  441.              }
  442. -            if(image && isselection() && !hidebigmenuimages && image->ys > FONTH)
  443. +            if((image || !parent->preload) && isselection() && !hidebigmenuimages)
  444.              {
  445. +                if(!image && !(image = textureload(filename, 3))) return;
  446.                  w += FONTH;
  447.                  int xs = (2 * VIRTW - w) / 5, ys = (xs * image->ys) / image->xs;
  448.                  x = (6 * VIRTW + w - 2 * xs) / 4; y = VIRTH - ys / 2;
  449. @@ -843,10 +844,10 @@
  450.  
  451.  COMMAND(delmenu, "s");
  452.  
  453. -void menumanual(void *menu, char *text, char *action, color *bgcolor, const char *desc)
  454. +void menumanual(void *menu, char *text, char *action, color *bgcolor, const char *desc, char *hoveraction)
  455.  {
  456.      gmenu &m = *(gmenu *)menu;
  457. -    m.items.add(new mitemmanual(&m, text, action, NULL, bgcolor, desc));
  458. +    m.items.add(new mitemmanual(&m, text, action, hoveraction, bgcolor, desc));
  459.  }
  460.  
  461.  void menuimagemanual(void *menu, const char *filename, const char *altfontname, char *text, char *action, color *bgcolor, const char *desc)
  462. Index: protos.h
  463. ===================================================================
  464. --- protos.h    (revision 7532)
  465. +++ protos.h    (working copy)
  466. @@ -90,7 +90,7 @@
  467.  extern void rendermenu();
  468.  extern bool menuvisible();
  469.  extern void menureset(void *menu);
  470. -extern void menumanual(void *menu, char *text, char *action = NULL, color *bgcolor = NULL, const char *desc = NULL);
  471. +extern void menumanual(void *menu, char *text, char *action = NULL, color *bgcolor = NULL, const char *desc = NULL, char *hoveraction = NULL);
  472.  extern void menuimagemanual(void *menu, const char *filename1, const char *filename2, char *text, char *action = NULL, color *bgcolor = NULL, const char *desc = NULL);
  473.  extern void menutitle(void *menu, const char *title = NULL);
  474.  extern bool needscoresreorder;
  475. @@ -154,13 +154,13 @@
  476.      bool (__cdecl *keyfunc)(void *, int, bool, int);
  477.      char *initaction;
  478.      char *usefont;
  479. -    bool allowblink;
  480. +    bool allowblink, showthumb, preload;
  481.      const char *mdl;
  482.      int anim, rotspeed, scale;
  483.      int footlen;
  484.      mdirlist *dirlist;
  485.  
  486. -    gmenu() : name(0), title(0), header(0), footer(0), initaction(0), usefont(0), allowblink(0), mdl(0), footlen(0), dirlist(0) {}
  487. +    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) {}
  488.      virtual ~gmenu()
  489.      {
  490.          DELETEA(name);
  491. Index: rendermodel.cpp
  492. ===================================================================
  493. --- rendermodel.cpp (revision 7533)
  494. +++ rendermodel.cpp (working copy)
  495. @@ -97,11 +97,18 @@
  496.      mmi.m = NULL;
  497.      mmi.clipped = mmi.h >= 0.1f;
  498.      formatstring(mmi.name)("mapmodels/%s", name);
  499. +    defformatstring(fullname)("packages/models/mapmodels/%s", name);
  500. +    unixpath(path(fullname));
  501. +    packagesmanager::linktomap(fullname);
  502.  }
  503.  
  504.  void mapmodelreset()
  505.  {
  506. -    if(execcontext==IEXC_MAPCFG) mapmodels.shrink(0);
  507. +    if(execcontext==IEXC_MAPCFG)
  508. +    {
  509. +        mapmodels.shrink(0);
  510. +        packagesmanager::reset(PCK_MAPMODEL);
  511. +    }
  512.  }
  513.  
  514.  mapmodelinfo &getmminfo(int i) { return mapmodels.inrange(i) ? mapmodels[i] : *(mapmodelinfo *)0; }
  515. Index: texture.cpp
  516. ===================================================================
  517. --- texture.cpp (revision 7532)
  518. +++ texture.cpp (working copy)
  519. @@ -478,19 +478,18 @@
  520.      return t;
  521.  }
  522.  
  523. -struct Slot
  524. -{
  525. -    string name;
  526. -    float scale;
  527. -    Texture *tex;
  528. -    bool loaded;
  529. -};
  530. -
  531.  vector<Slot> slots;
  532.  
  533. -void texturereset() { if(execcontext==IEXC_MAPCFG) slots.setsize(0); }
  534. +void texturereset()
  535. +{
  536. +    if(execcontext==IEXC_MAPCFG)
  537. +    {
  538. +        slots.setsize(0);
  539. +        packagesmanager::reset(PCK_TEXTURE);
  540. +    }
  541. +}
  542.  
  543. -void texture(char *scale, char *name)
  544. +void texture(float *scale, char *name)
  545.  {
  546.      Slot &s = slots.add();
  547.      copystring(s.name, name);
  548. @@ -498,6 +497,10 @@
  549.      s.tex = NULL;
  550.      s.loaded = false;
  551.      s.scale = (*scale > 0 && *scale <= 2.0f) ? *scale : 1.0f;
  552. +    
  553. +    defformatstring(fullname)("packages/textures/%s", s.name);
  554. +    unixpath(fullname);
  555. +    packagesmanager::linktomap(fullname);
  556.  }
  557.  
  558.  COMMAND(texturereset, "");
  559. Index: worldio.cpp
  560. ===================================================================
  561. --- worldio.cpp (revision 7532)
  562. +++ worldio.cpp (working copy)
  563. @@ -555,4 +555,63 @@
  564.      return true;
  565.  }
  566.  
  567. -COMMANDN(savemap, save_world, "s");
  568. \ No newline at end of file
  569. +COMMANDN(savemap, save_world, "s");
  570. +
  571. +// generate map cfg.
  572. +// TODO ? avoid redundancies with default_map_settings.cfg
  573. +// (e.g., don't use texturesreset when it's not necessary?)
  574. +
  575. +void savemapcfg()
  576. +{
  577. +    vector<package *> mappackages;
  578. +    extern int fog, fogcolour, shadowyaw;
  579. +    extern vector<Slot> slots;
  580. +    enumerate(packagesmanager::packages, package *, pck,
  581. +    {
  582. +        if(pck->inmap) mappackages.add(pck);
  583. +    });
  584. +    mappackages.sort(packagesmanager::offsetsort);
  585. +
  586. +    stream *f = openrawfile(mcfname, "w+");
  587. +    if(!f)
  588. +    {
  589. +        conoutf("\f3failed to write the CFG file");
  590. +        return;
  591. +    }
  592. +    f->printf("// Auto generated map-cfg file.\n");
  593. +    f->printf("\n");
  594. +
  595. +    // allowed idents (reminder)
  596. +    // loadnotexture loadsky mapmodelreset mapmodel texturereset texture fog fogcolour mapsoundreset mapsound watercolour shadowyaw
  597. +    
  598. +    f->printf("fog %d\n", fog);
  599. +    f->printf("fogcolour 0x%x\n", fogcolour);
  600. +    f->printf("watercolour %d %d %d %d\n", hdr.watercolor[0], hdr.watercolor[1], hdr.watercolor[2], hdr.watercolor[3]);
  601. +    f->printf("shadowyaw %d\n", shadowyaw);
  602. +
  603. +    f->printf("\nmapmodelreset\n");
  604. +    loopv(mappackages) if(mappackages[i]->type == PCK_MAPMODEL)
  605. +    {
  606. +        mapmodelinfo &mmi = getmminfo(mappackages[i]->offset);
  607. +        f->printf("mapmodel %.2f %.2f %.2f 0 \"%s\" // %d\n",
  608. +            &mmi ? mmi.rad : 0, &mmi ? mmi.h : 0, &mmi ? mmi.zoff : 0,
  609. +            mappackages[i]->shortname, mappackages[i]->offset);
  610. +    }
  611. +    
  612. +    f->printf("\ntexturereset\n");
  613. +    loopv(mappackages) if(mappackages[i]->type == PCK_TEXTURE)
  614. +    {
  615. +        string scale = "0";
  616. +        if(slots.inrange(mappackages[i]->offset) && abs(slots[mappackages[i]->offset].scale-1.0f) > 0.01f)
  617. +            ftoa(scale, slots[mappackages[i]->offset].scale);
  618. +        f->printf("texture %s \"%s\" // %d\n", scale, mappackages[i]->shortname, mappackages[i]->offset);
  619. +    }
  620. +
  621. +    f->printf("\nmapsoundreset\n");
  622. +    loopv(mappackages) if(mappackages[i]->type == PCK_AUDIO)
  623. +    {
  624. +        f->printf("mapsound \"%s\" -1 // %d\n", mappackages[i]->shortname, mappackages[i]->offset);
  625. +    }
  626. +    f->close();
  627. +}
  628. +COMMAND(savemapcfg, "");
  629. \ No newline at end of file
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement