Advertisement
Guest User

Untitled

a guest
Jun 10th, 2010
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 10.34 KB | None | 0 0
  1. Index: D:/andre/prg/doom/prboom-plus/branches/prboom-plus-24/src/p_setup.c
  2. ===================================================================
  3. --- D:/andre/prg/doom/prboom-plus/branches/prboom-plus-24/src/p_setup.c (revision 3466)
  4. +++ D:/andre/prg/doom/prboom-plus/branches/prboom-plus-24/src/p_setup.c (revision 3467)
  5. @@ -226,19 +226,41 @@
  6.  static dboolean P_CheckForDeePBSPv4Nodes(int lumpnum, int gl_lumpnum)
  7.  {
  8.    const void *data;
  9. +  int result = false;
  10.  
  11.    data = W_CacheLumpNum(lumpnum + ML_NODES);
  12.    if (!memcmp(data, "xNd4\0\0\0\0", 8))
  13.    {
  14. -    lprintf(LO_WARN, "P_CheckForDeePBSPv4Nodes: DeePBSP v4 Extended nodes are detected\n");
  15. -    return true;
  16. +    lprintf(LO_INFO, "P_CheckForDeePBSPv4Nodes: DeePBSP v4 Extended nodes are detected\n");
  17. +    result = true;
  18.    }
  19.    W_UnlockLumpNum(lumpnum + ML_NODES);
  20.  
  21. -  return false;
  22. +  return result;
  23.  }
  24.  
  25.  //
  26. +// P_CheckForZDoomUncompressedNodes
  27. +// http://zdoom.org/wiki/ZDBSP#Compressed_Nodes
  28. +//
  29. +
  30. +static int P_CheckForZDoomUncompressedNodes(int lumpnum, int gl_lumpnum)
  31. +{
  32. +  const void *data;
  33. +  int result = false;
  34. +
  35. +  data = W_CacheLumpNum(lumpnum + ML_NODES);
  36. +  if (!memcmp(data, "XNOD", 4))
  37. +  {
  38. +    lprintf(LO_INFO, "P_CheckForZDoomUncompressedNodes: ZDoom uncompressed normal nodes are detected\n");
  39. +    result = true;
  40. +  }
  41. +  W_UnlockLumpNum(lumpnum + ML_NODES);
  42. +
  43. +  return result;
  44. +}
  45. +
  46. +//
  47.  // P_GetNodesVersion
  48.  //
  49.  
  50. @@ -936,7 +958,7 @@
  51.        I_Error("P_LoadNodes_V4: no nodes in level");
  52.    }
  53.  
  54. -  for (i=0; i<numnodes; i++)
  55. +  for (i = 0; i < numnodes; i++)
  56.      {
  57.        node_t *no = nodes + i;
  58.        const mapnode_v4_t *mn = (const mapnode_v4_t *) data + i;
  59. @@ -960,6 +982,240 @@
  60.    W_UnlockLumpNum(lump); // cph - release the data
  61.  }
  62.  
  63. +static void CheckZNodesOverflow(int *size, int count)
  64. +{
  65. +  (*size) -= count;
  66. +
  67. +  if ((*size) < 0)
  68. +  {
  69. +    I_Error("P_LoadZNodes: incorrect nodes");
  70. +  }
  71. +}
  72. +
  73. +static void P_LoadZSegs (const byte *data)
  74. +{
  75. +  int i;
  76. +
  77. +  for (i = 0; i < numsegs; i++)
  78. +  {
  79. +    line_t *ldef;
  80. +    unsigned int v1, v2;
  81. +    unsigned int linedef;
  82. +    unsigned char side;
  83. +    seg_t *li = segs+i;
  84. +    const mapseg_znod_t *ml = (const mapseg_znod_t *) data + i;
  85. +
  86. +    v1 = ml->v1;
  87. +    v2 = ml->v2;
  88. +
  89. +    li->iSegID = i; // proff 11/05/2000: needed for OpenGL
  90. +    li->miniseg = false;
  91. +
  92. +    linedef = (unsigned short)LittleShort(ml->linedef);
  93. +
  94. +    //e6y: check for wrong indexes
  95. +    if ((unsigned int)linedef >= (unsigned int)numlines)
  96. +    {
  97. +      I_Error("P_LoadZSegs: seg %d references a non-existent linedef %d",
  98. +        i, (unsigned)linedef);
  99. +    }
  100. +
  101. +    ldef = &lines[linedef];
  102. +    li->linedef = ldef;
  103. +    side = ml->side;
  104. +
  105. +    //e6y: fix wrong side index
  106. +    if (side != 0 && side != 1)
  107. +    {
  108. +      lprintf(LO_WARN, "P_LoadZSegs: seg %d contains wrong side index %d. Replaced with 1.\n", i, side);
  109. +      side = 1;
  110. +    }
  111. +
  112. +    //e6y: check for wrong indexes
  113. +    if ((unsigned)ldef->sidenum[side] >= (unsigned)numsides)
  114. +    {
  115. +      I_Error("P_LoadZSegs: linedef %d for seg %d references a non-existent sidedef %d",
  116. +        linedef, i, (unsigned)ldef->sidenum[side]);
  117. +    }
  118. +
  119. +    li->sidedef = &sides[ldef->sidenum[side]];
  120. +
  121. +    /* cph 2006/09/30 - our frontsector can be the second side of the
  122. +    * linedef, so must check for NO_INDEX in case we are incorrectly
  123. +    * referencing the back of a 1S line */
  124. +    if (ldef->sidenum[side] != NO_INDEX)
  125. +    {
  126. +      li->frontsector = sides[ldef->sidenum[side]].sector;
  127. +    }
  128. +    else
  129. +    {
  130. +      li->frontsector = 0;
  131. +      lprintf(LO_WARN, "P_LoadZSegs: front of seg %i has no sidedef\n", i);
  132. +    }
  133. +
  134. +    if ((ldef->flags & ML_TWOSIDED) && (ldef->sidenum[side^1] != NO_INDEX))
  135. +      li->backsector = sides[ldef->sidenum[side^1]].sector;
  136. +    else
  137. +      li->backsector = 0;
  138. +
  139. +    li->v1 = &vertexes[v1];
  140. +    li->v2 = &vertexes[v2];
  141. +
  142. +    li->length = GetDistance(li->v2->x - li->v1->x, li->v2->y - li->v1->y);
  143. +    li->offset = GetOffset(li->v1, (side ? ldef->v2 : ldef->v1));
  144. +    li->angle = R_PointToAngle2(segs[i].v1->x, segs[i].v1->y, segs[i].v2->x, segs[i].v2->y);
  145. +    //li->angle = (int)((float)atan2(li->v2->y - li->v1->y,li->v2->x - li->v1->x) * (ANG180 / M_PI));
  146. +  }
  147. +}
  148. +
  149. +static void P_LoadZNodes(int lump, int glnodes)
  150. +{
  151. +  const byte *data;
  152. +  unsigned int i, len;
  153. +
  154. +  unsigned int orgVerts, newVerts;
  155. +  unsigned int numSubs, currSeg;
  156. +  unsigned int numSegs;
  157. +  unsigned int numNodes;
  158. +  vertex_t *newvertarray = NULL;
  159. +
  160. +  data = W_CacheLumpNum(lump);
  161. +  len =  W_LumpLength(lump);
  162. +  
  163. +  // skip header
  164. +  CheckZNodesOverflow(&len, 4);
  165. +  data += 4;
  166. +
  167. +  // Read extra vertices added during node building
  168. +  CheckZNodesOverflow(&len, sizeof(orgVerts));
  169. +  orgVerts = *((unsigned int*)data);
  170. +  data += sizeof(orgVerts);
  171. +
  172. +  CheckZNodesOverflow(&len, sizeof(newVerts));
  173. +  newVerts = *((unsigned int*)data);
  174. +  data += sizeof(newVerts);
  175. +
  176. +  if (!samelevel)
  177. +  {
  178. +    if (orgVerts + newVerts == (unsigned int)numvertexes)
  179. +    {
  180. +      newvertarray = vertexes;
  181. +    }
  182. +    else
  183. +    {
  184. +      newvertarray = calloc(orgVerts + newVerts, sizeof(vertex_t));
  185. +      memcpy (newvertarray, vertexes, orgVerts * sizeof(vertex_t));
  186. +    }
  187. +
  188. +    CheckZNodesOverflow(&len, newVerts * (sizeof(newvertarray[0].x) + sizeof(newvertarray[0].y)));
  189. +    for (i = 0; i < newVerts; i++)
  190. +    {
  191. +      newvertarray[i + orgVerts].x = *((unsigned int*)data);
  192. +      data += sizeof(newvertarray[0].x);
  193. +
  194. +      newvertarray[i + orgVerts].y = *((unsigned int*)data);
  195. +      data += sizeof(newvertarray[0].y);
  196. +    }
  197. +
  198. +    if (vertexes != newvertarray)
  199. +    {
  200. +      for (i = 0; i < (unsigned int)numlines; i++)
  201. +      {
  202. +        lines[i].v1 = lines[i].v1 - vertexes + newvertarray;
  203. +        lines[i].v2 = lines[i].v2 - vertexes + newvertarray;
  204. +      }
  205. +      free(vertexes);
  206. +      vertexes = newvertarray;
  207. +      numvertexes = orgVerts + newVerts;
  208. +    }
  209. +  }
  210. +  else
  211. +  {
  212. +    int size = newVerts * (sizeof(newvertarray[0].x) + sizeof(newvertarray[0].y));
  213. +    CheckZNodesOverflow(&len, size);
  214. +    data += size;
  215. +  }
  216. +
  217. +  // Read the subsectors
  218. +  CheckZNodesOverflow(&len, sizeof(numSubs));
  219. +  numSubs = *((unsigned int*)data);
  220. +  data += sizeof(numSubs);
  221. +
  222. +  numsubsectors = numSubs;
  223. +  if (numsubsectors <= 0)
  224. +    I_Error("P_LoadZNodes: no subsectors in level");
  225. +  subsectors = calloc_IfSameLevel(subsectors, numsubsectors, sizeof(subsector_t));
  226. +
  227. +  CheckZNodesOverflow(&len, numSubs * sizeof(mapsubsector_znod_t));
  228. +  for (i = currSeg = 0; i < numSubs; i++)
  229. +  {
  230. +    const mapsubsector_znod_t *mseg = (const mapsubsector_znod_t *) data + i;
  231. +
  232. +    subsectors[i].firstline = currSeg;
  233. +    subsectors[i].numlines = mseg->numsegs;
  234. +    currSeg += mseg->numsegs;
  235. +  }
  236. +  data += numSubs * sizeof(mapsubsector_znod_t);
  237. +
  238. +  // Read the segs
  239. +  CheckZNodesOverflow(&len, sizeof(numSegs));
  240. +  numSegs = *((unsigned int*)data);
  241. +  data += sizeof(numSegs);
  242. +
  243. +  // The number of segs stored should match the number of
  244. +  // segs used by subsectors.
  245. +  if (numSegs != currSeg)
  246. +  {
  247. +    I_Error("P_LoadZNodes: Incorrect number of segs in nodes.");
  248. +  }
  249. +
  250. +  numsegs = numSegs;
  251. +  segs = calloc_IfSameLevel(segs, numsegs, sizeof(seg_t));
  252. +
  253. +  if (glnodes == 0)
  254. +  {
  255. +    CheckZNodesOverflow(&len, numsegs * sizeof(mapseg_znod_t));
  256. +    P_LoadZSegs(data);
  257. +    data += numsegs * sizeof(mapseg_znod_t);
  258. +  }
  259. +  else
  260. +  {
  261. +    //P_LoadGLZSegs (data, glnodes);
  262. +    I_Error("P_LoadZNodes: GL segs are not supported.");
  263. +  }
  264. +
  265. +  // Read nodes
  266. +  CheckZNodesOverflow(&len, sizeof(numNodes));
  267. +  numNodes = *((unsigned int*)data);
  268. +  data += sizeof(numNodes);
  269. +
  270. +  numnodes = numNodes;
  271. +  nodes = calloc_IfSameLevel(nodes, numNodes, sizeof(node_t));
  272. +
  273. +  CheckZNodesOverflow(&len, numNodes * sizeof(mapnode_znod_t));
  274. +  for (i = 0; i < numNodes; i++)
  275. +  {
  276. +    int j, k;
  277. +    node_t *no = nodes + i;
  278. +    const mapnode_znod_t *mn = (const mapnode_znod_t *) data + i;
  279. +
  280. +    no->x = LittleShort(mn->x)<<FRACBITS;
  281. +    no->y = LittleShort(mn->y)<<FRACBITS;
  282. +    no->dx = LittleShort(mn->dx)<<FRACBITS;
  283. +    no->dy = LittleShort(mn->dy)<<FRACBITS;
  284. +
  285. +    for (j = 0; j < 2; j++)
  286. +    {
  287. +      no->children[j] = (unsigned int)(mn->children[j]);
  288. +
  289. +      for (k = 0; k < 4; k++)
  290. +        no->bbox[j][k] = LittleShort(mn->bbox[j][k])<<FRACBITS;
  291. +    }
  292. +  }
  293. +
  294. +  W_UnlockLumpNum(lump); // cph - release the data
  295. +}
  296. +
  297.  static int no_overlapped_sprites;
  298.  #define GETXY(mobj) (mobj->x + (mobj->y >> 16))
  299.  static int C_DECL dicmp_sprite_by_pos(const void *a, const void *b)
  300. @@ -2145,8 +2401,12 @@
  301.    }
  302.    else
  303.    {
  304. -    if (P_CheckForDeePBSPv4Nodes(lumpnum, gl_lumpnum))
  305. +    if (P_CheckForZDoomUncompressedNodes(lumpnum, gl_lumpnum))
  306.      {
  307. +      P_LoadZNodes(lumpnum + ML_NODES, 0);
  308. +    }
  309. +    else if (P_CheckForDeePBSPv4Nodes(lumpnum, gl_lumpnum))
  310. +    {
  311.        P_LoadSubsectors_V4(lumpnum + ML_SSECTORS);
  312.        P_LoadNodes_V4(lumpnum + ML_NODES);
  313.        P_LoadSegs_V4(lumpnum + ML_SEGS);
  314. Index: D:/andre/prg/doom/prboom-plus/branches/prboom-plus-24/src/doomdata.h
  315. ===================================================================
  316. --- D:/andre/prg/doom/prboom-plus/branches/prboom-plus-24/src/doomdata.h    (revision 3466)
  317. +++ D:/andre/prg/doom/prboom-plus/branches/prboom-plus-24/src/doomdata.h    (revision 3467)
  318. @@ -165,6 +165,10 @@
  319.    int firstseg;
  320.  } PACKEDATTR mapsubsector_v4_t;
  321.  
  322. +typedef struct {
  323. +  unsigned int numsegs;
  324. +} PACKEDATTR mapsubsector_znod_t;
  325. +
  326.  // LineSeg, generated by splitting LineDefs
  327.  // using partition lines selected by BSP builder.
  328.  typedef struct {
  329. @@ -185,6 +189,13 @@
  330.    unsigned short offset;
  331.  } PACKEDATTR mapseg_v4_t;
  332.  
  333. +typedef struct {
  334. +  unsigned int v1, v2;
  335. +  unsigned short linedef;
  336. +  unsigned char side;
  337. +} PACKEDATTR mapseg_znod_t;
  338. +
  339. +
  340.  // BSP node structure.
  341.  
  342.  // Indicate a leaf.
  343. @@ -213,6 +224,17 @@
  344.    int children[2];
  345.  } PACKEDATTR mapnode_v4_t;
  346.  
  347. +typedef struct {
  348. +  short x;  // Partition line from (x,y) to x+dx,y+dy)
  349. +  short y;
  350. +  short dx;
  351. +  short dy;
  352. +  // Bounding box for each child, clip against view frustum.
  353. +  short bbox[2][4];
  354. +  // If NF_SUBSECTOR its a subsector, else it's a node of another subtree.
  355. +  int children[2];
  356. +} PACKEDATTR mapnode_znod_t;
  357. +
  358.  // Thing definition, position, orientation and type,
  359.  // plus skill/visibility flags and attributes.
  360.  typedef struct {
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement