home *** CD-ROM | disk | FTP | other *** search
/ 1,001 Nights of Doom / 1001NightsOfDoom1995wickedSensations.iso / nodebild / idbsp10.zip / SAVEBSP.C < prev    next >
Text File  |  1994-05-31  |  22KB  |  783 lines

  1. /* savebsp.m */
  2.  
  3. #include "idbsp.h"
  4.  
  5. /*
  6. id              secstore_i;
  7. id              mapvertexstore_i;
  8. id              subsecstore_i;
  9. id              maplinestore_i;
  10. id              nodestore_i;
  11. id              mapthingstore_i;
  12. id              ldefstore_i;
  13. id              sdefstore_i;
  14. */
  15.  
  16. STORAGE *secstore_i;
  17. STORAGE *mapvertexstore_i;
  18. STORAGE *subsecstore_i;
  19. STORAGE *maplinestore_i;
  20. STORAGE *nodestore_i;
  21. STORAGE *mapthingstore_i;
  22. STORAGE *ldefstore_i;
  23. STORAGE *sdefstore_i;
  24.  
  25. /*
  26. ===============================================================================
  27.  
  28.                         the output functions byte swap and write lumps
  29.  
  30. ===============================================================================
  31. */
  32.  
  33.  
  34. /*
  35. ================
  36. =
  37. = WriteStorage
  38. =
  39. ================
  40. */
  41.  
  42. /*void WriteStorage (char *name, id store, int esize) */
  43. void WriteStorage(char *name, STORAGE *store, int esize)
  44. {
  45.         int             count, len;
  46.  
  47. /*      count = [store count]; */
  48.         count = store->count;
  49.         len = esize*count;
  50. /*      [wad_i addName: name data:[store elementAt:0] size:len]; */
  51.         addName(name, store->data, len);
  52.         printf ("%s (%i): %i\n",name,count,len);
  53. }
  54.  
  55.  
  56. /*
  57. =================
  58. =
  59. = OutputSectors
  60. =
  61. =================
  62. */
  63.  
  64. void OutputSectors (void)
  65. {
  66.         int             i, count;
  67.         mapsector_t             *p;
  68. /*
  69.         count = [secstore_i count];
  70.         p = [secstore_i elementAt:0];
  71. */
  72.         count = secstore_i->count;
  73.         p = secstore_i->data;
  74.  
  75. /*
  76.         for (i=0 ; i<count ; i++, p++)
  77.         {
  78.                 p->floorheight = SHORT(p->floorheight);
  79.                 p->ceilingheight = SHORT(p->ceilingheight);
  80.                 p->lightlevel = SHORT(p->lightlevel);
  81.                 p->special = SHORT(p->special);
  82.                 p->tag = SHORT(p->tag);
  83.         }
  84. */
  85.  
  86.         WriteStorage ("sectors", secstore_i, sizeof(mapsector_t));
  87. }
  88.  
  89.  
  90. /*
  91. =================
  92. =
  93. = OutputSegs
  94. =
  95. =================
  96. */
  97.  
  98. void OutputSegs (void)
  99. {
  100.         int             i, count;
  101.         mapseg_t                *p;
  102. /*
  103.         count = [maplinestore_i count];
  104.         p = [maplinestore_i elementAt:0];
  105. */
  106.         count = maplinestore_i->count;
  107.         p = maplinestore_i->data;
  108. /*
  109.         for (i=0 ; i<count ; i++, p++)
  110.         {
  111.                 p->v1 = SHORT(p->v1);
  112.                 p->v2 = SHORT(p->v2);
  113.                 p->angle = SHORT(p->angle);
  114.                 p->linedef = SHORT(p->linedef);
  115.                 p->side = SHORT(p->side);
  116.                 p->offset = SHORT(p->offset);
  117.         }
  118. */
  119.         WriteStorage ("segs",maplinestore_i, sizeof(mapseg_t));
  120. }
  121.  
  122.  
  123. /*
  124. =================
  125. =
  126. = OutputSubsectors
  127. =
  128. =================
  129. */
  130.  
  131. void OutputSubsectors (void)
  132. {
  133.         int             i, count;
  134.         mapsubsector_t          *p;
  135. /*
  136.         count = [subsecstore_i count];
  137.         p = [subsecstore_i elementAt:0];
  138. */
  139.         count = subsecstore_i->count;
  140.         p = subsecstore_i->data;
  141. /*
  142.         for (i=0 ; i<count ; i++, p++)
  143.         {
  144.                 p->numsegs = SHORT(p->numsegs);
  145.                 p->firstseg = SHORT(p->firstseg);
  146.         }
  147. */
  148.         WriteStorage ("ssectors", subsecstore_i, sizeof(mapsubsector_t));
  149. }
  150.  
  151.  
  152. /*
  153. =================
  154. =
  155. = OutputVertexes
  156. =
  157. =================
  158. */
  159.  
  160. void OutputVertexes (void)
  161. {
  162.         int             i, count;
  163.         mapvertex_t             *p;
  164. /*
  165.         count = [mapvertexstore_i count];
  166.         p = [mapvertexstore_i elementAt:0];
  167. */
  168.         count = mapvertexstore_i->count;
  169.         p = mapvertexstore_i->data;
  170. /*
  171.         for (i=0 ; i<count ; i++, p++)
  172.         {
  173.                 p->x = SHORT(p->x);
  174.                 p->y = SHORT(p->y);
  175.         }
  176. */
  177.         WriteStorage ("vertexes",mapvertexstore_i, sizeof(mapvertex_t));
  178. }
  179.  
  180.  
  181. /*
  182. =================
  183. =
  184. = OutputThings
  185. =
  186. =================
  187. */
  188.  
  189. void OutputThings (void)
  190. {
  191.         int             i, count;
  192.         mapthing_t              *p;
  193. /*
  194.         count = [mapthingstore_i count];
  195.         p = [mapthingstore_i elementAt:0];
  196. */
  197.         count = mapthingstore_i->count;
  198.         p = mapthingstore_i->data;
  199. /*
  200.         for (i=0 ; i<count ; i++, p++)
  201.         {
  202.                 p->x = SHORT(p->x);
  203.                 p->y = SHORT(p->y);
  204.                 p->angle = SHORT(p->angle);
  205.                 p->type = SHORT(p->type);
  206.                 p->options = SHORT(p->options);
  207.         }
  208. */
  209.         WriteStorage ("things", mapthingstore_i, sizeof(mapthing_t));
  210. }
  211.  
  212.  
  213. /*
  214. =================
  215. =
  216. = OutputLineDefs
  217. =
  218. =================
  219. */
  220.  
  221. void OutputLineDefs (void)
  222. {
  223.         int             i, count;
  224.         maplinedef_t            *p;
  225. /*
  226.         count = [ldefstore_i count];
  227.         p = [ldefstore_i elementAt:0];
  228. */
  229.         count = ldefstore_i->count;
  230.         p = ldefstore_i->data;
  231. #if 0
  232.         for (i=0 ; i<count ; i++, p++)
  233.         {
  234.                 p->v1 = SHORT(p->v1);
  235.                 p->v2 = SHORT(p->v2);
  236. /* some ancient version of DoomEd left ML_MAPPED flags in some of the levels */
  237.                 p->flags = SHORT(p->flags&~ML_MAPPED);
  238.                 p->special = SHORT(p->special);
  239.                 p->tag = SHORT(p->tag);
  240.                 p->sidenum[0] = SHORT(p->sidenum[0]);
  241.                 p->sidenum[1] = SHORT(p->sidenum[1]);
  242.         }
  243. #endif
  244.         WriteStorage ("linedefs", ldefstore_i, sizeof(maplinedef_t));
  245. }
  246.  
  247.  
  248. /*
  249. =================
  250. =
  251. = OutputSideDefs
  252. =
  253. =================
  254. */
  255.  
  256. void OutputSideDefs (void)
  257. {
  258.         int             i, count;
  259.         mapsidedef_t            *p;
  260. /*
  261.         count = [sdefstore_i count];
  262.         p = [sdefstore_i elementAt:0];
  263. */
  264.         count = sdefstore_i->count;
  265.         p = sdefstore_i->data;
  266. /*
  267.         for (i=0 ; i<count ; i++, p++)
  268.         {
  269.                 p->textureoffset = SHORT(p->textureoffset);
  270.                 p->rowoffset = SHORT(p->rowoffset);
  271.                 p->sector = SHORT(p->sector);
  272.         }
  273. */
  274.         WriteStorage ("sidedefs", sdefstore_i, sizeof(mapsidedef_t));
  275. }
  276.  
  277.  
  278. /*
  279. =================
  280. =
  281. = OutputNodes
  282. =
  283. =================
  284. */
  285.  
  286. void OutputNodes (void)
  287. {
  288.         int             i, j, count;
  289.         mapnode_t               *p;
  290. /*
  291.         count = [nodestore_i count];
  292.         p = [nodestore_i elementAt:0];
  293. */
  294.         count = nodestore_i->count;
  295.         p = nodestore_i->data;
  296. /*
  297.         for (i=0 ; i<count ; i++, p++)
  298.         {
  299.                 for (j=0 ; j<sizeof(mapnode_t)/2 ; j++)
  300.                         ((short *)p)[j] = SHORT(((short *)p)[j]);
  301.         }
  302. */
  303.         WriteStorage ("nodes", nodestore_i, sizeof(mapnode_t));
  304. }
  305.  
  306.  
  307. /*
  308. ===============================================================================
  309.  
  310.                                                         PROCESSING
  311.  
  312. ===============================================================================
  313. */
  314.  
  315.  
  316. /*
  317. =================
  318. =
  319. = UniqueVertex
  320. =
  321. = Returns the vertex number, adding a new vertex if needed
  322. =================
  323. */
  324.  
  325. int UniqueVertex (int x, int y)
  326. {
  327.         int                             i, count;
  328.         mapvertex_t             mv, *mvp;
  329.  
  330.         mv.x = x;
  331.         mv.y = y;
  332.  
  333. /* see if an identical vertex already exists */
  334. /*
  335.         count = [mapvertexstore_i count];
  336.         mvp = [mapvertexstore_i elementAt:0];
  337. */
  338.         count = mapvertexstore_i->count;
  339.         mvp = mapvertexstore_i->data;
  340.         for (i=0 ; i<count ; i++, mvp++)
  341.                 if (mvp->x == mv.x && mvp->y == mv.y)
  342.                         return i;
  343.  
  344. /*      [mapvertexstore_i addElement: &mv]; */
  345.         memcpy((mapvertex_t *)mapvertexstore_i->data + mapvertexstore_i->count, &mv,
  346.                                         sizeof(mapvertex_t));
  347.         mapvertexstore_i->count += 1;
  348.         mapvertexstore_i->data = (mapvertex_t *)realloc(mapvertexstore_i->data,
  349.                                                                                                                 sizeof(mapvertex_t) * (mapvertexstore_i->count + 1));
  350.  
  351.         return count;
  352. }
  353.  
  354.  
  355. /*
  356. =============================================================================
  357. */
  358.  
  359. float   bbox[4];
  360.  
  361. /*
  362. =================
  363. =
  364. = AddPointToBBox
  365. =
  366. =================
  367. */
  368.  
  369. void AddPointToBBox (NXPoint *pt)
  370. {
  371.         if (pt->x < bbox[BOXLEFT])
  372.                 bbox[BOXLEFT] = pt->x;
  373.         if (pt->x > bbox[BOXRIGHT])
  374.                 bbox[BOXRIGHT] = pt->x;
  375.  
  376.         if (pt->y > bbox[BOXTOP])
  377.                 bbox[BOXTOP] = pt->y;
  378.         if (pt->y < bbox[BOXBOTTOM])
  379.                 bbox[BOXBOTTOM] = pt->y;
  380. }
  381.  
  382.  
  383. /*
  384. =================
  385. =
  386. = ProcessLines
  387. =
  388. = Adds the lines in a subsector to the mapline storage
  389. =================
  390. */
  391.  
  392. /* void ProcessLines (id store_i) */
  393. void ProcessLines(STORAGE *store_i)
  394. {
  395.         int                     i,count;
  396.         line_t          *wline;
  397.         mapseg_t        line;
  398.         short           angle;
  399.         float           fangle;
  400.  
  401.         bbox[BOXLEFT] = INT_MAX;
  402.         bbox[BOXRIGHT] = INT_MIN;
  403.         bbox[BOXTOP] = INT_MIN;
  404.         bbox[BOXBOTTOM] = INT_MAX;
  405.  
  406. /*      count = [store_i count]; */
  407.         count = store_i->count;
  408.         for (i=0 ; i<count ; i++)
  409.         {
  410. /*              wline = [store_i elementAt: i]; */
  411.                 wline = (line_t *)store_i->data + i;
  412.                 if (wline->grouped)
  413.                         printf ("ERROR: line regrouped\n");
  414.                 wline->grouped = true;
  415.  
  416.                 memset (&line, 0, sizeof(line));
  417.                 AddPointToBBox (&wline->p1);
  418.                 AddPointToBBox (&wline->p2);
  419.                 line.v1 = UniqueVertex (wline->p1.x, wline->p1.y);
  420.                 line.v2 = UniqueVertex (wline->p2.x, wline->p2.y);
  421.                 line.linedef = wline->linedef;
  422.                 line.side = wline->side;
  423.                 line.offset = wline->offset;
  424.                 fangle = atan2 (wline->p2.y - wline->p1.y, wline->p2.x - wline->p1.x);
  425.                 angle = (short)(fangle/(PI*2)*0x10000);
  426.                 line.angle = angle;
  427. /*              [maplinestore_i addElement: &line]; */
  428.                 memcpy((mapseg_t *)maplinestore_i->data + maplinestore_i->count, &line,
  429.                                                 sizeof(line));
  430.                 maplinestore_i->count += 1;
  431.                 maplinestore_i->data = (mapseg_t *)realloc(maplinestore_i->data,
  432.                                                                                                         sizeof(mapseg_t) * (maplinestore_i->count + 1));
  433.         }
  434. }
  435.  
  436.  
  437. /*
  438. =================
  439. =
  440. = ProcessSubsector
  441. =
  442. =================
  443. */
  444.  
  445. /* int ProcessSubsector (id wmaplinestore_i) */
  446. int ProcessSubsector(STORAGE *wmaplinestore_i)
  447. {
  448.         int                             count;
  449.         worldline_t             *linedef;
  450.         line_t                  *wline;
  451.         mapsubsector_t  sub;
  452.  
  453.         memset (&sub,0,sizeof(sub));
  454.  
  455. /*      count = [wmaplinestore_i count]; */
  456.         count = wmaplinestore_i->count;
  457.         if (count < 1)
  458.                 Error ("ProcessSubsector: count = %i",count);
  459.  
  460. /*      wline = [wmaplinestore_i elementAt: 0]; */
  461.         wline = wmaplinestore_i->data;
  462.  
  463. /*      linedef = [linestore_i elementAt: wline->linedef]; */
  464.         linedef = (worldline_t *)linestore_i->data + wline->linedef;
  465.                 sub.numsegs = count;
  466. /*      sub.firstseg = [maplinestore_i count]; */
  467.                 sub.firstseg = maplinestore_i->count;
  468.                 ProcessLines (wmaplinestore_i);
  469.  
  470. /* add the new subsector
  471.                 [subsecstore_i addElement: &sub];
  472. */
  473.                 memcpy((mapsubsector_t *)subsecstore_i->data + subsecstore_i->count, &sub,
  474.                                                                                 sizeof(mapsubsector_t));
  475.                 subsecstore_i->count += 1;
  476.                 subsecstore_i->data = (mapsubsector_t *)realloc(subsecstore_i->data,
  477.                                         sizeof(mapsubsector_t) * (subsecstore_i->count + 1));
  478.  
  479. /*      return [subsecstore_i count]-1; */
  480.                 return subsecstore_i->count - 1;
  481. }
  482.  
  483. /*
  484. =================
  485. =
  486. = ProcessNode
  487. =
  488. =================
  489. */
  490.  
  491. int ProcessNode (bspnode_t *node, short *totalbox)
  492. {
  493.         short           subbox[2][4];
  494.         int                     i, r;
  495.         mapnode_t       mnode;
  496.  
  497.         memset (&mnode,0,sizeof(mnode));
  498.  
  499.         if (node->lines_i)      /* NF_SUBSECTOR flags a subsector */
  500.         {
  501.                 r = ProcessSubsector (node->lines_i);
  502.                 for (i=0 ; i<4 ; i++)
  503.                         totalbox[i] = bbox[i];
  504.                 return r | NF_SUBSECTOR;
  505.         }
  506.  
  507.         mnode.x =node->divline.pt.x;
  508.         mnode.y =node->divline.pt.y;
  509.         mnode.dx =node->divline.dx;
  510.         mnode.dy =node->divline.dy;
  511.  
  512.         r = ProcessNode(node->side[0], subbox[0]);
  513.         mnode.children[0] =r;
  514.         for (i=0 ; i<4 ; i++)
  515.                 mnode.bbox[0][i] =subbox[0][i];
  516.  
  517.         r = ProcessNode (node->side[1],subbox[1]);
  518.         mnode.children[1] =r;
  519.         for (i=0 ; i<4 ; i++)
  520.                 mnode.bbox[1][i] =subbox[1][i];
  521.  
  522.         totalbox[BOXLEFT] = MIN(subbox[0][BOXLEFT], subbox[1][BOXLEFT]);
  523.         totalbox[BOXTOP] = MAX(subbox[0][BOXTOP], subbox[1][BOXTOP]);
  524.         totalbox[BOXRIGHT] = MAX(subbox[0][BOXRIGHT], subbox[1][BOXRIGHT]);
  525.         totalbox[BOXBOTTOM] = MIN(subbox[0][BOXBOTTOM], subbox[1][BOXBOTTOM]);
  526.  
  527. /*      [nodestore_i addElement: &mnode]; */
  528.         memcpy((mapnode_t *)nodestore_i->data + nodestore_i->count, &mnode, sizeof(mapnode_t));
  529.         nodestore_i->count += 1;
  530.         nodestore_i->data = (mapnode_t *)realloc(nodestore_i->data,
  531.                                                                                         sizeof(mapnode_t) * (nodestore_i->count + 1));
  532.  
  533. /*      return [nodestore_i count] - 1; */
  534.         return nodestore_i->count - 1;
  535. }
  536.  
  537.  
  538. /*
  539. =================
  540. =
  541. = ProcessNodes
  542. =
  543. = Recursively builds the nodes, subsectors, and line lists,
  544. = then writes the lumps
  545. =================
  546. */
  547.  
  548. void ProcessNodes (void)
  549. {
  550.         short   worldbounds[4];
  551. /*
  552.         subsecstore_i = [[Storage alloc]
  553.                 initCount:              0
  554.                 elementSize:    sizeof(mapsubsector_t)
  555.                 description:    NULL];
  556.         maplinestore_i = [[Storage alloc]
  557.                 initCount:              0
  558.                 elementSize:    sizeof(mapseg_t)
  559.                 description:    NULL];
  560.         nodestore_i = [[Storage alloc]
  561.                 initCount:              0
  562.                 elementSize:    sizeof(mapnode_t)
  563.                 description:    NULL];
  564. */
  565.         subsecstore_i = (STORAGE *)SafeMalloc(sizeof(STORAGE));
  566.         subsecstore_i->data = (mapsubsector_t *)SafeMalloc(sizeof(mapsubsector_t));
  567.         subsecstore_i->count = 0;
  568.         subsecstore_i->size = sizeof(mapsubsector_t);
  569.  
  570.         maplinestore_i = (STORAGE *)SafeMalloc(sizeof(STORAGE));
  571.         maplinestore_i->data = (mapseg_t *)SafeMalloc(sizeof(mapseg_t));
  572.         maplinestore_i->count = 0;
  573.         maplinestore_i->size = sizeof(mapseg_t);
  574.  
  575.         nodestore_i = (STORAGE *)SafeMalloc(sizeof(STORAGE));
  576.         nodestore_i->data = (mapnode_t *)SafeMalloc(sizeof(mapnode_t));
  577.         nodestore_i->count = 0;
  578.         nodestore_i->size = sizeof(mapnode_t);
  579.  
  580.         ProcessNode (startnode, worldbounds);
  581.  
  582. }
  583.  
  584.  
  585. /*
  586. =================
  587. =
  588. = ProcessThings
  589. =
  590. =================
  591. */
  592.  
  593. void ProcessThings (void)
  594. {
  595.         worldthing_t    *wt;
  596.         mapthing_t              mt;
  597.         int                             count;
  598.  
  599. /*
  600.         mapthingstore_i = [[Storage alloc]
  601.                 initCount:              0
  602.                 elementSize:    sizeof(mapthing_t)
  603.                 description:    NULL];
  604. */
  605.         mapthingstore_i = (STORAGE *)SafeMalloc(sizeof(STORAGE));
  606.         mapthingstore_i->data = (mapthing_t *)SafeMalloc(sizeof(mapthing_t));
  607.         mapthingstore_i->count = 0;
  608.         mapthingstore_i->size = sizeof(mapthing_t);
  609.  
  610. /*
  611.         count = [thingstore_i count];
  612.         wt = [thingstore_i elementAt: 0];
  613. */
  614.         count = thingstore_i->count;
  615.         wt = thingstore_i->data;
  616.         while (count--)
  617.         {
  618.                 memset (&mt,0,sizeof(mt));
  619.                 mt.x =wt->origin.x;
  620.                 mt.y =wt->origin.y;
  621.                 mt.angle =wt->angle;
  622.                 mt.type =wt->type;
  623.                 mt.options =wt->options;
  624. /*              [mapthingstore_i addElement: &mt]; */
  625.                 memcpy((mapthing_t *)mapthingstore_i->data + mapthingstore_i->count, &mt,
  626.                                                 sizeof(mapthing_t));
  627.                 mapthingstore_i->count += 1;
  628.                 mapthingstore_i->data = (mapthing_t *)realloc(mapthingstore_i->data,
  629.                                                                                                                 sizeof(mapthing_t) * (mapthingstore_i->count + 1));
  630.                 wt++;
  631.         }
  632.  
  633. }
  634.  
  635. /*
  636. =============================================================================
  637. */
  638.  
  639. /*
  640. ==================
  641. =
  642. = ProcessSidedef
  643. =
  644. ==================
  645. */
  646.  
  647. int ProcessSidedef (worldside_t *ws)
  648. {
  649.         mapsidedef_t    ms;
  650.  
  651.         ms.textureoffset = ws->firstcollumn;
  652.         ms.rowoffset = ws->firstrow;
  653.         memcpy (ms.toptexture, ws->toptexture, 8);
  654.         memcpy (ms.bottomtexture, ws->bottomtexture, 8);
  655.         memcpy (ms.midtexture, ws->midtexture, 8);
  656.         ms.sector = ws->sector;
  657.  
  658. /*      [sdefstore_i addElement: &ms]; */
  659.         memcpy((mapsidedef_t *)sdefstore_i->data + sdefstore_i->count, &ms, sizeof(mapsidedef_t));
  660.         sdefstore_i->count += 1;
  661.         sdefstore_i->data = (mapsidedef_t *)realloc(sdefstore_i->data,
  662.                                                                                         sizeof(mapsidedef_t) * (sdefstore_i->count + 1));
  663.  
  664. /*      return [sdefstore_i count]-1; */
  665.         return sdefstore_i->count - 1;
  666. }
  667.  
  668. /*
  669. ==================
  670. =
  671. = ProcessLineSideDefs
  672. =
  673. = Must be called after BuildSectors
  674. ==================
  675. */
  676.  
  677. void ProcessLineSideDefs (void)
  678. {
  679.         int                             i, count;
  680.         maplinedef_t    ld;
  681.         worldline_t             *wl;
  682. /*
  683.         mapvertexstore_i = [[Storage alloc]
  684.                 initCount:              0
  685.                 elementSize:    sizeof(mapvertex_t)
  686.                 description:    NULL];
  687.         ldefstore_i = [[Storage alloc]
  688.                 initCount:              0
  689.                 elementSize:    sizeof(maplinedef_t)
  690.                 description:    NULL];
  691.         sdefstore_i = [[Storage alloc]
  692.                 initCount:              0
  693.                 elementSize:    sizeof(mapsidedef_t)
  694.                 description:    NULL];
  695. */
  696.         mapvertexstore_i = (STORAGE *)SafeMalloc(sizeof(STORAGE));
  697.         mapvertexstore_i->data = (mapvertex_t *)SafeMalloc(sizeof(mapvertex_t));
  698.         mapvertexstore_i->count = 0;
  699.         mapvertexstore_i->size = sizeof(mapvertex_t);
  700.  
  701.         ldefstore_i = (STORAGE *)SafeMalloc(sizeof(STORAGE));
  702.         ldefstore_i->data = (maplinedef_t *)SafeMalloc(sizeof(maplinedef_t));
  703.         ldefstore_i->count = 0;
  704.         ldefstore_i->size = sizeof(maplinedef_t);
  705.  
  706.         sdefstore_i = (STORAGE *)SafeMalloc(sizeof(STORAGE));
  707.         sdefstore_i->data = (mapsidedef_t *)SafeMalloc(sizeof(mapsidedef_t));
  708.         sdefstore_i->count = 0;
  709.         sdefstore_i->size = sizeof(mapsidedef_t);
  710.  
  711. /*
  712.         count = [linestore_i count];
  713.         wl = [linestore_i elementAt:0];
  714. */
  715.         count = linestore_i->count;
  716.         wl = linestore_i->data;
  717.         for (i=0 ; i<count ; i++, wl++)
  718.         {
  719.                 ld.v1 = UniqueVertex(wl->p1.x,wl->p1.y);
  720.                 ld.v2 =UniqueVertex(wl->p2.x,wl->p2.y);
  721.                 ld.flags =wl->flags;
  722.                 ld.special =wl->special;
  723.                 ld.tag =wl->tag;
  724.                 ld.sidenum[0] =ProcessSidedef(&wl->side[0]);
  725.                 if (wl->flags & ML_TWOSIDED)
  726.                         ld.sidenum[1] =ProcessSidedef(&wl->side[1]);
  727.                 else
  728.                         ld.sidenum[1] =-1;
  729. /*              [ldefstore_i addElement: &ld]; */
  730.  
  731.                 memcpy((maplinedef_t *)ldefstore_i->data + ldefstore_i->count, &ld, sizeof(maplinedef_t));
  732.                 ldefstore_i->count += 1;
  733.                 ldefstore_i->data = (maplinedef_t *)realloc(ldefstore_i->data,
  734.                                                                                                 sizeof(maplinedef_t) * (ldefstore_i->count + 1));
  735.         }
  736.  
  737. }
  738.  
  739. /*
  740. =============================================================================
  741. */
  742.  
  743. /*
  744. ==================
  745. =
  746. = SaveDoomMap
  747. =
  748. ==================
  749. */
  750.  
  751. void SaveDoomMap (void)
  752. {
  753.         printf("\nBuildSectordefs\n");
  754.         BuildSectordefs ();
  755.  
  756.         printf("ProcessThings\n");
  757.         ProcessThings ();
  758.  
  759.         printf("ProcessLineSideDefs\n");
  760.         ProcessLineSideDefs ();
  761.  
  762.         printf("ProcessNodes\n");
  763.         ProcessNodes ();
  764.  
  765.         printf("ProcessSectors\n");
  766.         ProcessSectors ();
  767.  
  768.         printf("\nProcessConnections\n");
  769.         ProcessConnections ();
  770.  
  771. /* all processing is complete, write everything out */
  772.         OutputThings ();
  773.         OutputLineDefs ();
  774.         OutputSideDefs ();
  775.         OutputVertexes ();
  776.         OutputSegs ();
  777.         OutputSubsectors ();
  778.         OutputNodes ();
  779.         OutputSectors ();
  780.         OutputConnections ();
  781. }
  782.  
  783.