Refactor T_MovePlane a little bit

This commit is contained in:
MascaraSnake 2020-04-18 01:08:01 +02:00
parent 272a8e532b
commit 06ce2b3b2c
3 changed files with 141 additions and 164 deletions

View file

@ -47,8 +47,7 @@ void T_MoveCeiling(ceiling_t *ceiling)
case 0: // IN STASIS case 0: // IN STASIS
break; break;
case 1: // UP case 1: // UP
res = T_MovePlane(ceiling->sector, ceiling->speed, ceiling->topheight, false, res = T_MovePlane(ceiling->sector, ceiling->speed, ceiling->topheight, false, true, ceiling->direction);
1, ceiling->direction);
if (ceiling->type == bounceCeiling) if (ceiling->type == bounceCeiling)
{ {
@ -159,8 +158,7 @@ void T_MoveCeiling(ceiling_t *ceiling)
break; break;
case -1: // DOWN case -1: // DOWN
res = T_MovePlane(ceiling->sector, ceiling->speed, ceiling->bottomheight, res = T_MovePlane(ceiling->sector, ceiling->speed, ceiling->bottomheight, ceiling->crush, true, ceiling->direction);
ceiling->crush, 1, ceiling->direction);
if (ceiling->type == bounceCeiling) if (ceiling->type == bounceCeiling)
{ {
@ -314,11 +312,10 @@ void T_CrushCeiling(ceiling_t *ceiling)
if (ceiling->type == crushBothOnce) if (ceiling->type == crushBothOnce)
{ {
// Move the floor // Move the floor
T_MovePlane(ceiling->sector, ceiling->speed, ceiling->bottomheight-(ceiling->topheight-ceiling->bottomheight), false, 0, -ceiling->direction); T_MovePlane(ceiling->sector, ceiling->speed, ceiling->bottomheight-(ceiling->topheight-ceiling->bottomheight), false, false, -ceiling->direction);
} }
res = T_MovePlane(ceiling->sector, ceiling->speed, ceiling->topheight, res = T_MovePlane(ceiling->sector, ceiling->speed, ceiling->topheight, false, true, ceiling->direction);
false, 1, ceiling->direction);
if (res == pastdest) if (res == pastdest)
{ {
@ -357,11 +354,10 @@ void T_CrushCeiling(ceiling_t *ceiling)
if (ceiling->type == crushBothOnce) if (ceiling->type == crushBothOnce)
{ {
// Move the floor // Move the floor
T_MovePlane(ceiling->sector, ceiling->speed, ceiling->bottomheight, ceiling->crush, 0, -ceiling->direction); T_MovePlane(ceiling->sector, ceiling->speed, ceiling->bottomheight, ceiling->crush, false, -ceiling->direction);
} }
res = T_MovePlane(ceiling->sector, ceiling->speed, ceiling->bottomheight, res = T_MovePlane(ceiling->sector, ceiling->speed, ceiling->bottomheight, ceiling->crush, true, ceiling->direction);
ceiling->crush, 1, ceiling->direction);
if (res == pastdest) if (res == pastdest)
{ {

View file

@ -30,146 +30,127 @@
// Move a plane (floor or ceiling) and check for crushing // Move a plane (floor or ceiling) and check for crushing
// //
result_e T_MovePlane(sector_t *sector, fixed_t speed, fixed_t dest, boolean crush, result_e T_MovePlane(sector_t *sector, fixed_t speed, fixed_t dest, boolean crush,
INT32 floorOrCeiling, INT32 direction) boolean ceiling, INT32 direction)
{ {
boolean flag;
fixed_t lastpos; fixed_t lastpos;
fixed_t destheight; // used to keep floors/ceilings from moving through each other fixed_t destheight; // used to keep floors/ceilings from moving through each other
sector->moved = true; sector->moved = true;
switch (floorOrCeiling) if (ceiling)
{ {
case 0: lastpos = sector->ceilingheight;
// moving a floor // moving a ceiling
switch (direction) switch (direction)
{ {
case -1: case -1:
// Moving a floor down // moving a ceiling down
if (sector->floorheight - speed < dest) // keep ceiling from moving through floors
destheight = (dest > sector->floorheight) ? dest : sector->floorheight;
if (sector->ceilingheight - speed < destheight)
{
sector->ceilingheight = destheight;
if (P_CheckSector(sector, crush))
{ {
lastpos = sector->floorheight; sector->ceilingheight = lastpos;
sector->floorheight = dest; P_CheckSector(sector, crush);
flag = P_CheckSector(sector, crush);
if (flag && sector->numattached)
{
sector->floorheight = lastpos;
P_CheckSector(sector, crush);
}
return pastdest;
} }
else return pastdest;
}
else
{
// crushing is possible
sector->ceilingheight -= speed;
if (P_CheckSector(sector, crush))
{ {
lastpos = sector->floorheight; sector->ceilingheight = lastpos;
sector->floorheight -= speed; P_CheckSector(sector, crush);
flag = P_CheckSector(sector, crush); return crushed;
if (flag && sector->numattached)
{
sector->floorheight = lastpos;
P_CheckSector(sector, crush);
return crushed;
}
} }
break; }
break;
case 1: case 1:
// Moving a floor up // moving a ceiling up
// keep floor from moving through ceilings if (sector->ceilingheight + speed > dest)
destheight = (dest < sector->ceilingheight) ? dest : sector->ceilingheight; {
if (sector->floorheight + speed > destheight) sector->ceilingheight = dest;
if (P_CheckSector(sector, crush) && sector->numattached)
{ {
lastpos = sector->floorheight; sector->ceilingheight = lastpos;
sector->floorheight = destheight; P_CheckSector(sector, crush);
flag = P_CheckSector(sector, crush);
if (flag)
{
sector->floorheight = lastpos;
P_CheckSector(sector, crush);
}
return pastdest;
} }
else return pastdest;
}
else
{
sector->ceilingheight += speed;
if (P_CheckSector(sector, crush) && sector->numattached)
{ {
// crushing is possible sector->ceilingheight = lastpos;
lastpos = sector->floorheight; P_CheckSector(sector, crush);
sector->floorheight += speed; return crushed;
flag = P_CheckSector(sector, crush);
if (flag)
{
sector->floorheight = lastpos;
P_CheckSector(sector, crush);
return crushed;
}
} }
break; }
} break;
break; }
}
else
{
lastpos = sector->floorheight;
// moving a floor
switch (direction)
{
case -1:
// Moving a floor down
if (sector->floorheight - speed < dest)
{
sector->floorheight = dest;
if (P_CheckSector(sector, crush) && sector->numattached)
{
sector->floorheight = lastpos;
P_CheckSector(sector, crush);
}
return pastdest;
}
else
{
sector->floorheight -= speed;
if (P_CheckSector(sector, crush) && sector->numattached)
{
sector->floorheight = lastpos;
P_CheckSector(sector, crush);
return crushed;
}
}
break;
case 1: case 1:
// moving a ceiling // Moving a floor up
switch (direction) // keep floor from moving through ceilings
{ destheight = (dest < sector->ceilingheight) ? dest : sector->ceilingheight;
case -1: if (sector->floorheight + speed > destheight)
// moving a ceiling down {
// keep ceiling from moving through floors sector->floorheight = destheight;
destheight = (dest > sector->floorheight) ? dest : sector->floorheight; if (P_CheckSector(sector, crush))
if (sector->ceilingheight - speed < destheight)
{ {
lastpos = sector->ceilingheight; sector->floorheight = lastpos;
sector->ceilingheight = destheight; P_CheckSector(sector, crush);
flag = P_CheckSector(sector, crush);
if (flag)
{
sector->ceilingheight = lastpos;
P_CheckSector(sector, crush);
}
return pastdest;
} }
else return pastdest;
}
else
{
// crushing is possible
sector->floorheight += speed;
if (P_CheckSector(sector, crush))
{ {
// crushing is possible sector->floorheight = lastpos;
lastpos = sector->ceilingheight; P_CheckSector(sector, crush);
sector->ceilingheight -= speed; return crushed;
flag = P_CheckSector(sector, crush);
if (flag)
{
sector->ceilingheight = lastpos;
P_CheckSector(sector, crush);
return crushed;
}
} }
break; }
break;
case 1: }
// moving a ceiling up
if (sector->ceilingheight + speed > dest)
{
lastpos = sector->ceilingheight;
sector->ceilingheight = dest;
flag = P_CheckSector(sector, crush);
if (flag && sector->numattached)
{
sector->ceilingheight = lastpos;
P_CheckSector(sector, crush);
}
return pastdest;
}
else
{
lastpos = sector->ceilingheight;
sector->ceilingheight += speed;
flag = P_CheckSector(sector, crush);
if (flag && sector->numattached)
{
sector->ceilingheight = lastpos;
P_CheckSector(sector, crush);
return crushed;
}
}
break;
}
break;
} }
return ok; return ok;
@ -192,7 +173,7 @@ void T_MoveFloor(floormove_t *movefloor)
res = T_MovePlane(movefloor->sector, res = T_MovePlane(movefloor->sector,
movefloor->speed, movefloor->speed,
movefloor->floordestheight, movefloor->floordestheight,
movefloor->crush, 0, movefloor->direction); movefloor->crush, false, movefloor->direction);
if (movefloor->type == bounceFloor) if (movefloor->type == bounceFloor)
{ {
@ -385,7 +366,7 @@ void T_MoveElevator(elevator_t *elevator)
elevator->speed, elevator->speed,
elevator->ceilingdestheight, elevator->ceilingdestheight,
elevator->distance, elevator->distance,
1, // move floor true, // move ceiling
elevator->direction elevator->direction
); );
@ -395,7 +376,7 @@ void T_MoveElevator(elevator_t *elevator)
elevator->speed, elevator->speed,
elevator->floordestheight, elevator->floordestheight,
elevator->distance, elevator->distance,
0, // move ceiling false, // move floor
elevator->direction elevator->direction
); );
@ -447,7 +428,7 @@ void T_MoveElevator(elevator_t *elevator)
elevator->speed, elevator->speed,
elevator->floordestheight, elevator->floordestheight,
elevator->distance, elevator->distance,
0, // move ceiling false, // move floor
elevator->direction elevator->direction
); );
@ -459,7 +440,7 @@ void T_MoveElevator(elevator_t *elevator)
elevator->speed, elevator->speed,
elevator->ceilingdestheight, elevator->ceilingdestheight,
elevator->distance, elevator->distance,
1, // move floor true, // move ceiling
elevator->direction elevator->direction
); );
} }
@ -739,8 +720,8 @@ void T_BounceCheese(levelspecthink_t *bouncer)
if (remove) if (remove)
{ {
T_MovePlane(bouncer->sector, 0, bouncer->sector->ceilingheight, 0, 1, -1); // update things on ceiling T_MovePlane(bouncer->sector, 0, bouncer->sector->ceilingheight, false, true, -1); // update things on ceiling
T_MovePlane(bouncer->sector, 0, bouncer->sector->floorheight, 0, 0, -1); // update things on floor T_MovePlane(bouncer->sector, 0, bouncer->sector->floorheight, false, false, -1); // update things on floor
P_RecalcPrecipInSector(actionsector); P_RecalcPrecipInSector(actionsector);
bouncer->sector->ceilingdata = NULL; bouncer->sector->ceilingdata = NULL;
bouncer->sector->floordata = NULL; bouncer->sector->floordata = NULL;
@ -752,9 +733,9 @@ void T_BounceCheese(levelspecthink_t *bouncer)
} }
T_MovePlane(bouncer->sector, bouncer->speed/2, bouncer->sector->ceilingheight - T_MovePlane(bouncer->sector, bouncer->speed/2, bouncer->sector->ceilingheight -
70*FRACUNIT, 0, 1, -1); // move ceiling 70*FRACUNIT, false, true, -1); // move ceiling
T_MovePlane(bouncer->sector, bouncer->speed/2, bouncer->sector->floorheight - 70*FRACUNIT, T_MovePlane(bouncer->sector, bouncer->speed/2, bouncer->sector->floorheight - 70*FRACUNIT,
0, 0, -1); // move floor false, false, -1); // move floor
bouncer->sector->floorspeed = -bouncer->speed/2; bouncer->sector->floorspeed = -bouncer->speed/2;
bouncer->sector->ceilspeed = 42; bouncer->sector->ceilspeed = 42;
@ -790,8 +771,8 @@ void T_BounceCheese(levelspecthink_t *bouncer)
{ {
bouncer->sector->floorheight = bouncer->floorwasheight; bouncer->sector->floorheight = bouncer->floorwasheight;
bouncer->sector->ceilingheight = bouncer->ceilingwasheight; bouncer->sector->ceilingheight = bouncer->ceilingwasheight;
T_MovePlane(bouncer->sector, 0, bouncer->sector->ceilingheight, 0, 1, -1); // update things on ceiling T_MovePlane(bouncer->sector, 0, bouncer->sector->ceilingheight, false, true, -1); // update things on ceiling
T_MovePlane(bouncer->sector, 0, bouncer->sector->floorheight, 0, 0, -1); // update things on floor T_MovePlane(bouncer->sector, 0, bouncer->sector->floorheight, false, false, -1); // update things on floor
bouncer->sector->ceilingdata = NULL; bouncer->sector->ceilingdata = NULL;
bouncer->sector->floordata = NULL; bouncer->sector->floordata = NULL;
bouncer->sector->floorspeed = 0; bouncer->sector->floorspeed = 0;
@ -940,8 +921,8 @@ void T_StartCrumble(elevator_t *elevator)
elevator->sector, elevator->sector,
elevator->speed, elevator->speed,
dest, dest,
0, false,
1, // move floor true, // move ceiling
elevator->direction elevator->direction
); );
@ -955,8 +936,8 @@ void T_StartCrumble(elevator_t *elevator)
elevator->sector, elevator->sector,
elevator->speed, elevator->speed,
dest, dest,
0, false,
0, // move ceiling false, // move floor
elevator->direction elevator->direction
); );
@ -1007,8 +988,8 @@ void T_MarioBlock(levelspecthink_t *block)
block->sector, block->sector,
block->speed, block->speed,
block->sector->ceilingheight + 70*FRACUNIT * block->direction, block->sector->ceilingheight + 70*FRACUNIT * block->direction,
0, false,
1, // move floor true, // move ceiling
block->direction block->direction
); );
@ -1017,8 +998,8 @@ void T_MarioBlock(levelspecthink_t *block)
block->sector, block->sector,
block->speed, block->speed,
block->sector->floorheight + 70*FRACUNIT * block->direction, block->sector->floorheight + 70*FRACUNIT * block->direction,
0, false,
0, // move ceiling false, // move floor
block->direction block->direction
); );
@ -1228,8 +1209,8 @@ void T_ThwompSector(levelspecthink_t *thwomp)
thwomp->sector, // sector thwomp->sector, // sector
thwomp->speed, // speed thwomp->speed, // speed
thwomp->floorwasheight, // dest thwomp->floorwasheight, // dest
0, // crush false, // crush
0, // floor or ceiling (0 for floor) false, // ceiling?
thwomp->direction // direction thwomp->direction // direction
); );
@ -1239,8 +1220,8 @@ void T_ThwompSector(levelspecthink_t *thwomp)
thwomp->sector, // sector thwomp->sector, // sector
thwomp->speed, // speed thwomp->speed, // speed
thwomp->ceilingwasheight, // dest thwomp->ceilingwasheight, // dest
0, // crush false, // crush
1, // floor or ceiling (1 for ceiling) true, // ceiling?
thwomp->direction // direction thwomp->direction // direction
); );
@ -1268,8 +1249,8 @@ void T_ThwompSector(levelspecthink_t *thwomp)
thwomp->speed, // speed thwomp->speed, // speed
P_FloorzAtPos(thwompx, thwompy, thwomp->sector->floorheight, P_FloorzAtPos(thwompx, thwompy, thwomp->sector->floorheight,
thwomp->sector->ceilingheight - thwomp->sector->floorheight), // dest thwomp->sector->ceilingheight - thwomp->sector->floorheight), // dest
0, // crush false, // crush
0, // floor or ceiling (0 for floor) false, // ceiling?
thwomp->direction // direction thwomp->direction // direction
); );
@ -1283,8 +1264,8 @@ void T_ThwompSector(levelspecthink_t *thwomp)
- (thwomp->sector->floorheight + thwomp->speed)) - (thwomp->sector->floorheight + thwomp->speed))
+ (thwomp->sector->ceilingheight + (thwomp->sector->ceilingheight
- (thwomp->sector->floorheight + thwomp->speed/2)), // dest - (thwomp->sector->floorheight + thwomp->speed/2)), // dest
0, // crush false, // crush
1, // floor or ceiling (1 for ceiling) true, // ceiling?
thwomp->direction // direction thwomp->direction // direction
); );
@ -1786,8 +1767,8 @@ void T_RaiseSector(raise_t *raise)
raise->sector, // sector raise->sector, // sector
speed, // speed speed, // speed
ceilingdestination, // dest ceilingdestination, // dest
0, // crush false, // crush
1, // floor or ceiling (1 for ceiling) true, // ceiling?
direction // direction direction // direction
); );
@ -1797,8 +1778,8 @@ void T_RaiseSector(raise_t *raise)
raise->sector, // sector raise->sector, // sector
speed, // speed speed, // speed
floordestination, // dest floordestination, // dest
0, // crush false, // crush
0, // floor or ceiling (0 for floor) false, // ceiling?
direction // direction direction // direction
); );
@ -1900,9 +1881,9 @@ void T_PlaneDisplace(planedisplace_t *pd)
} }
if (pd->type == pd_floor || pd->type == pd_both) if (pd->type == pd_floor || pd->type == pd_both)
T_MovePlane(target, INT32_MAX/2, target->floorheight+diff, 0, 0, direction); // move floor T_MovePlane(target, INT32_MAX/2, target->floorheight+diff, false, false, direction); // move floor
if (pd->type == pd_ceiling || pd->type == pd_both) if (pd->type == pd_ceiling || pd->type == pd_both)
T_MovePlane(target, INT32_MAX/2, target->ceilingheight+diff, 0, 1, direction); // move ceiling T_MovePlane(target, INT32_MAX/2, target->ceilingheight+diff, false, true, direction); // move ceiling
pd->last_height = control->floorheight; pd->last_height = control->floorheight;
} }

View file

@ -368,7 +368,7 @@ typedef enum
} result_e; } result_e;
result_e T_MovePlane(sector_t *sector, fixed_t speed, fixed_t dest, boolean crush, result_e T_MovePlane(sector_t *sector, fixed_t speed, fixed_t dest, boolean crush,
INT32 floorOrCeiling, INT32 direction); boolean ceiling, INT32 direction);
INT32 EV_DoFloor(line_t *line, floor_e floortype); INT32 EV_DoFloor(line_t *line, floor_e floortype);
INT32 EV_DoElevator(line_t *line, elevator_e elevtype, boolean customspeed); INT32 EV_DoElevator(line_t *line, elevator_e elevtype, boolean customspeed);
void EV_CrumbleChain(sector_t *sec, ffloor_t *rover); void EV_CrumbleChain(sector_t *sec, ffloor_t *rover);