summaryrefslogtreecommitdiff
path: root/src/p_spec.c
diff options
context:
space:
mode:
authorSimon Howard2007-06-12 18:49:29 +0000
committerSimon Howard2007-06-12 18:49:29 +0000
commit22d473c19cddb35c8ba90fbe52beb7dff8377688 (patch)
tree78eaa7fbb9f9ba8f79f3fe76b69e9a813603b932 /src/p_spec.c
parentc131d939ed389ac381853f904fa8d09ec1100aac (diff)
downloadchocolate-doom-22d473c19cddb35c8ba90fbe52beb7dff8377688.tar.gz
chocolate-doom-22d473c19cddb35c8ba90fbe52beb7dff8377688.tar.bz2
chocolate-doom-22d473c19cddb35c8ba90fbe52beb7dff8377688.zip
Emulate overflows in P_FindNextHighestFloor. Thanks to entryway for this
fix. Subversion-branch: /trunk/chocolate-doom Subversion-revision: 902
Diffstat (limited to 'src/p_spec.c')
-rw-r--r--src/p_spec.c85
1 files changed, 48 insertions, 37 deletions
diff --git a/src/p_spec.c b/src/p_spec.c
index 8fc99707..01b612a1 100644
--- a/src/p_spec.c
+++ b/src/p_spec.c
@@ -328,59 +328,70 @@ fixed_t P_FindHighestFloorSurrounding(sector_t *sec)
// FIND NEXT HIGHEST FLOOR IN SURROUNDING SECTORS
// Note: this should be doable w/o a fixed array.
+// Thanks to entryway for the Vanilla overflow emulation.
+
// 20 adjoining sectors max!
-#define MAX_ADJOINING_SECTORS 20
+#define MAX_ADJOINING_SECTORS 20
fixed_t
P_FindNextHighestFloor
-( sector_t* sec,
- int currentheight )
+( sector_t* sec,
+ int currentheight )
{
- int i;
- int h;
- int min;
- line_t* check;
- sector_t* other;
- fixed_t height = currentheight;
-
-
- fixed_t heightlist[MAX_ADJOINING_SECTORS];
-
- for (i=0, h=0 ;i < sec->linecount ; i++)
+ int i;
+ int h;
+ int min;
+ line_t* check;
+ sector_t* other;
+ fixed_t height = currentheight;
+ fixed_t heightlist[MAX_ADJOINING_SECTORS + 2];
+
+ for (i=0, h=0; i < sec->linecount; i++)
{
- check = sec->lines[i];
- other = getNextSector(check,sec);
-
- if (!other)
- continue;
-
- if (other->floorheight > height)
- heightlist[h++] = other->floorheight;
-
- // Check for overflow. Exit.
- if ( h >= MAX_ADJOINING_SECTORS )
- {
- fprintf( stderr,
- "Sector with more than 20 adjoining sectors\n" );
- break;
- }
+ check = sec->lines[i];
+ other = getNextSector(check,sec);
+
+ if (!other)
+ continue;
+
+ if (other->floorheight > height)
+ {
+ // Emulation of memory (stack) overflow
+ if (h == MAX_ADJOINING_SECTORS + 1)
+ {
+ height = other->floorheight;
+ }
+ else if (h == MAX_ADJOINING_SECTORS + 2)
+ {
+ // Fatal overflow: game crashes at 22 textures
+ I_Error("Sector with more than 22 adjoining sectors. "
+ "Vanilla will crash here");
+ }
+
+ heightlist[h++] = other->floorheight;
+ }
}
// Find lowest height in list
if (!h)
- return currentheight;
-
+ {
+ return currentheight;
+ }
+
min = heightlist[0];
// Range checking?
- for (i = 1;i < h;i++)
- if (heightlist[i] < min)
- min = heightlist[i];
-
+ for (i = 1; i < h; i++)
+ {
+ if (heightlist[i] < min)
+ {
+ min = heightlist[i];
+ }
+ }
+
return min;
}
-
//
// FIND LOWEST CEILING IN THE SURROUNDING SECTORS
//