MIRRORS.CPP 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. #include <stdlib.h>
  2. #include "debug4g.h"
  3. #include "engine.h"
  4. #include "gameutil.h"
  5. #include "mirrors.h"
  6. #include "names.h"
  7. #include "screen.h"
  8. #include "view.h"
  9. #include "globals.h"
  10. #include "error.h"
  11. #include "helix.h"
  12. #include "key.h"
  13. #include "misc.h"
  14. #define MAXMIRRORS 64
  15. /***********************************************************************
  16. * static variables
  17. **********************************************************************/
  18. static short mirrorwall[MAXMIRRORS], mirrorcnt;
  19. /*******************************************************************************
  20. FUNCTION: InitMirrors()
  21. DESCRIPTION:
  22. PARAMETERS:
  23. NOTES:
  24. Requires a 64 tile range beginning at MIRRORLABEL, a constant
  25. aligned on a value of 32.
  26. Requires MIRROR and MIRRORLABEL constants defined in NAMES.H.
  27. *******************************************************************************/
  28. void InitMirrors( void )
  29. {
  30. int i, j;
  31. //Scan wall tags
  32. mirrorcnt = 0;
  33. tilesizx[MIRROR] = 0;
  34. tilesizy[MIRROR] = 0;
  35. for( i = 0; i < MAXMIRRORS; i++)
  36. {
  37. tilesizx[i + MIRRORLABEL] = 0;
  38. tilesizy[i + MIRRORLABEL] = 0;
  39. }
  40. for( i = numwalls - 1; i >= 0; i--)
  41. {
  42. if (mirrorcnt == MAXMIRRORS)
  43. {
  44. dprintf("Maximum mirror count reached.\n");
  45. break;
  46. }
  47. if ( (wall[i].cstat & kWallOneWay) && wall[i].overpicnum == MIRROR && wall[i].nextwall >= 0 )
  48. {
  49. short backSector = wall[i].nextsector;
  50. sector[backSector].ceilingpicnum = MIRROR;
  51. sector[backSector].floorpicnum = MIRROR;
  52. // sector[backSector].floorstat |= kSectorParallax; // is this needed?
  53. // sector[backSector].ceilingstat |= kSectorParallax; // is this needed?
  54. wall[i].overpicnum = (short)(MIRRORLABEL + mirrorcnt);
  55. // wall[i].cstat &= ~kWallMasked;
  56. // wall[i].cstat |= kWallOneWay;
  57. mirrorwall[mirrorcnt] = (short)i;
  58. mirrorcnt++;
  59. }
  60. }
  61. for (i = 0; i < mirrorcnt; i++)
  62. {
  63. short nSector = wall[mirrorwall[i]].nextsector;
  64. short wall0 = sector[nSector].wallptr;
  65. short wallN = (short)(wall0 + sector[nSector].wallnum);
  66. for (j = wall0; j < wallN; j++)
  67. {
  68. wall[j].picnum = MIRROR;
  69. wall[j].overpicnum = MIRROR;
  70. }
  71. }
  72. dprintf("%d mirrors initialized\n", mirrorcnt);
  73. }
  74. void TranslateMirrorColors( int shade, int pal )
  75. {
  76. shade = ClipRange(shade, 0, kPalLookups - 1);
  77. BYTE *lut = palookup[pal] + shade * 256;
  78. BYTE *p = (BYTE *)gPageTable[0].begin;
  79. for (int i = 0; i < gPageTable[0].size; i++, p++)
  80. {
  81. *p = lut[*p];
  82. }
  83. }
  84. /*******************************************************************************
  85. FUNCTION: DrawMirrors()
  86. DESCRIPTION:
  87. PARAMETERS:
  88. NOTES:
  89. MUST be called before drawrooms and before gotpic is cleared.
  90. Assumes MIRRORLABEL is aligned to a value of 32
  91. Assumes MAXMIRRORS = 64
  92. *******************************************************************************/
  93. void DrawMirrors( long x, long y, long z, short ang, long horiz )
  94. {
  95. int i;
  96. long tx, ty;
  97. short tang;
  98. DWORD dw0 = *(long *)&gotpic[MIRRORLABEL >> 3];
  99. DWORD dw1 = *(long *)&gotpic[(MIRRORLABEL >> 3) + 4];
  100. if ( !(dw0 | dw1) )
  101. return; // no mirror visible
  102. for( i = MAXMIRRORS - 1; i >= 0; i-- )
  103. {
  104. if ( TestBitString(gotpic, i + MIRRORLABEL) )
  105. {
  106. ClearBitString(gotpic, MIRRORLABEL + i);
  107. // Prepare drawrooms for drawing mirror and calculate reflected
  108. // position into tx, ty, and tang (tz == z)
  109. // Must call preparemirror before drawrooms and completemirror after drawrooms
  110. short nWall = mirrorwall[i];
  111. short nSector = wall[nWall].nextsector;
  112. preparemirror( x, y, z, ang, horiz, nWall, nSector, &tx, &ty, &tang);
  113. clearview(0);
  114. drawrooms( tx, ty, z, tang, horiz, nSector);
  115. viewProcessSprites(tx, ty, z);
  116. drawmasks();
  117. if (keystatus[KEY_M])
  118. {
  119. scrNextPage();
  120. dprintf("Mirror %d\n", i);
  121. dprintf(" mirrorwall[i] = %d\n", nWall);
  122. dprintf(" wall.nextwall = %d\n", wall[nWall].nextwall);
  123. dprintf(" wall.nextsector = %d\n", wall[nWall].nextsector);
  124. while ( keystatus[KEY_M] );
  125. }
  126. completemirror(); // Reverse screen x-wise in this function
  127. TranslateMirrorColors(wall[nWall].shade, wall[nWall].pal);
  128. break;
  129. }
  130. }
  131. }