Skip to content

Commit

Permalink
Merge pull request #428 from skedastik/fix-wall-alignment
Browse files Browse the repository at this point in the history
  • Loading branch information
rherriman authored Feb 8, 2025
2 parents b03c3ae + cfb0c09 commit b588817
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 32 deletions.
8 changes: 4 additions & 4 deletions src/compat/Types.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ typedef uint16_t port_num;
typedef int32_t ClockTick; // integer counter returned by UDPComm::GetClock()

struct Rect {
int16_t top;
int16_t left;
int16_t bottom;
int16_t right;
Fixed top;
Fixed left;
Fixed bottom;
Fixed right;
};
typedef struct Rect Rect;

Expand Down
8 changes: 4 additions & 4 deletions src/game/CRamp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ CAbstractActor *CRamp::EndScript() {
maskBits |= kSolidBit + kDoorIgnoreBit;

deltaY = ReadFixedVar(iDeltaY);
dims[0] = FMulDivNZ(gLastBoxRect.right - gLastBoxRect.left, FIX(5), 72);
dims[0] = gLastBoxRect.right - gLastBoxRect.left;
dims[1] = ReadFixedVar(iThickness);
dims[2] = FMulDivNZ(gLastBoxRect.bottom - gLastBoxRect.top, FIX(5), 72);
dims[2] = gLastBoxRect.bottom - gLastBoxRect.top;

if (dims[0] > LOCATORRECTSIZE)
dims[0] = LOCATORRECTSIZE;
Expand All @@ -77,8 +77,8 @@ CAbstractActor *CRamp::EndScript() {
heading += 0x8000;
}

location[0] = FMulDivNZ(gLastBoxRect.right + gLastBoxRect.left, FIX(5), 144);
location[2] = FMulDivNZ(gLastBoxRect.bottom + gLastBoxRect.top, FIX(5), 144);
location[0] = (gLastBoxRect.right + gLastBoxRect.left) >> 1;
location[2] = (gLastBoxRect.bottom + gLastBoxRect.top) >> 1;

partCount = 1;

Expand Down
14 changes: 7 additions & 7 deletions src/game/CWallActor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@ void CWallActor::MakeWallFromRect(Rect *theRect, Fixed height, short decimateWal
partYon = ReadFixedVar(iWallYon);

do {
dim[0] = FDivNZ(theRect->right - theRect->left, 72);
dim[0] = theRect->right - theRect->left;
dim[1] = 0;
dim[2] = FDivNZ(theRect->bottom - theRect->top, 72);
dim[2] = theRect->bottom - theRect->top;

tooBig =
dim[0] > LOCATORRECTSIZE / 5 || dim[2] > LOCATORRECTSIZE / 5; // VectorLength(3, dim) > LOCATORRECTSIZE/5;
dim[0] > LOCATORRECTSIZE || dim[2] > LOCATORRECTSIZE; // VectorLength(3, dim) > LOCATORRECTSIZE/5;
if (tooBig) {
CWallActor *otherWall;
Rect smallRect;
Expand All @@ -66,11 +66,11 @@ void CWallActor::MakeWallFromRect(Rect *theRect, Fixed height, short decimateWal
}
} while (tooBig);

centerX = FMulDivNZ(theRect->right + theRect->left, FIX(5), 144);
centerZ = FMulDivNZ(theRect->bottom + theRect->top, FIX(5), 144);
centerX = (theRect->right + theRect->left) / 2;
centerZ = (theRect->bottom + theRect->top) / 2;

dim[0] = dim[0] * 5 / 2;
dim[2] = dim[2] * 5 / 2;
dim[0] = dim[0] / 2;
dim[2] = dim[2] / 2;
if (height) {
dim[1] = (1 + height) >> 1;
//dim[1] = (1 + height * ReadFixedVar(iPixelToThickness)) >> 1;
Expand Down
8 changes: 4 additions & 4 deletions src/game/CYonBox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ CAbstractActor *CYonBox::EndScript() {
if (CAbstractYon::EndScript()) {
Fixed deltaY;

minBounds[0] = FMulDivNZ(gLastBoxRect.left, FIX(5), 72);
minBounds[2] = FMulDivNZ(gLastBoxRect.top, FIX(5), 72);
minBounds[0] = gLastBoxRect.left;
minBounds[2] = gLastBoxRect.top;

maxBounds[0] = FMulDivNZ(gLastBoxRect.right, FIX(5), 72);
maxBounds[2] = FMulDivNZ(gLastBoxRect.bottom, FIX(5), 72);
maxBounds[0] = gLastBoxRect.right;
maxBounds[2] = gLastBoxRect.bottom;

deltaY = ReadFixedVar(iDeltaY);
if (deltaY <= 0) {
Expand Down
25 changes: 12 additions & 13 deletions src/level/LevelLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
#include <regex>

#define POINTTOUNIT(pt) (pt * 20480 / 9)
#define UNITPOINTS (double)14.4 // 72 / 5

typedef struct {
Fixed v;
Expand Down Expand Up @@ -228,18 +227,18 @@ struct ALFWalker: pugi::xml_tree_walker {

if (!node.attribute("x").empty() && !node.attribute("z").empty() &&
!node.attribute("w").empty() && !node.attribute("d").empty()) {
double boxCenterX = ReadDoubleVar("x") * UNITPOINTS,
boxCenterZ = ReadDoubleVar("z") * UNITPOINTS,
boxWidth = ReadDoubleVar("w") * UNITPOINTS,
boxDepth = ReadDoubleVar("d") * UNITPOINTS;
double boxLeft = boxCenterX - (boxWidth / 2.0),
boxRight = boxLeft + boxWidth,
boxTop = boxCenterZ - (boxDepth / 2.0),
boxBottom = boxTop + boxDepth;
gLastBoxRect.top = std::lround(boxTop);
gLastBoxRect.left = std::lround(boxLeft);
gLastBoxRect.bottom = std::lround(boxBottom);
gLastBoxRect.right = std::lround(boxRight);
Fixed boxCenterX = ToFixed(ReadDoubleVar("x")),
boxCenterZ = ToFixed(ReadDoubleVar("z")),
boxWidth = ToFixed(ReadDoubleVar("w")),
boxDepth = ToFixed(ReadDoubleVar("d"));
Fixed boxLeft = boxCenterX - (boxWidth / 2),
boxRight = boxLeft + boxWidth,
boxTop = boxCenterZ - (boxDepth / 2),
boxBottom = boxTop + boxDepth;
gLastBoxRect.top = boxTop;
gLastBoxRect.left = boxLeft;
gLastBoxRect.bottom = boxBottom;
gLastBoxRect.right = boxRight;
}

if (!node.attribute("cx").empty() && !node.attribute("cz").empty()) {
Expand Down

0 comments on commit b588817

Please sign in to comment.