Skip to content

Commit

Permalink
- RR: cleaned up and floatified the mine cart code
Browse files Browse the repository at this point in the history
  • Loading branch information
coelckers committed Feb 15, 2022
1 parent 13d01bc commit 6fbecf2
Show file tree
Hide file tree
Showing 9 changed files with 120 additions and 164 deletions.
2 changes: 1 addition & 1 deletion source/core/gamefuncs.cpp
Expand Up @@ -185,7 +185,7 @@ void calcSlope(const sectortype* sec, float xpos, float ypos, float* pceilz, flo

void PlanesAtPoint(const sectortype* sec, float dax, float day, float* pceilz, float* pflorz)
{
calcSlope(sec, dax * worldtomap, day * worldtomap, pceilz, pflorz);
calcSlope(sec, dax * worldtoint, day * worldtoint, pceilz, pflorz);
if (pceilz) *pceilz *= -(1 / 256.f);
if (pflorz) *pflorz *= -(1 / 256.f);
}
Expand Down
15 changes: 10 additions & 5 deletions source/core/maptypes.h
Expand Up @@ -36,8 +36,13 @@ Prepared for public release: 03/21/2003 - Charlie Wiederhold, 3D Realms

void MarkVerticesForSector(int sector);

static constexpr double maptoworld = (1 / 16.);
static constexpr double worldtomap = 16.;
static constexpr double maptoworld = (1 / 16.); // this for necessary conversions to convert map data to floating point representation.
static constexpr double inttoworld = (1 / 16.); // this is for conversions needed to make floats coexist with existing code.
static constexpr double worldtoint = 16.;

static constexpr double zmaptoworld = (1 / 256.); // this for necessary conversions to convert map data to floating point representation.
static constexpr double zinttoworld = (1 / 256.); // this is for conversions needed to make floats coexist with existing code.
static constexpr double zworldtoint = 256.;

//=============================================================================
//
Expand Down Expand Up @@ -363,7 +368,7 @@ struct walltype
{
DVector2 pos;

vec2_t wall_int_pos() const { return vec2_t(pos.X * worldtomap, pos.Y * worldtomap); };
vec2_t wall_int_pos() const { return vec2_t(pos.X * worldtoint, pos.Y * worldtoint); };
void setPosFromLoad(int x, int y) { pos = { x * maptoworld, y * maptoworld }; }

int32_t point2;
Expand Down Expand Up @@ -561,8 +566,8 @@ inline void walltype::moved()

inline void walltype::movexy(int newx, int newy)
{
pos.X = newx * maptoworld;
pos.Y = newy * maptoworld;
pos.X = newx * inttoworld;
pos.Y = newy * inttoworld;
lengthflags = 3;
sectorp()->dirty = EDirty::AllDirty;
}
Expand Down
4 changes: 2 additions & 2 deletions source/games/blood/src/triggers.cpp
Expand Up @@ -847,8 +847,8 @@ void TranslateSector(sectortype* pSector, int a2, int a3, int a4, int a5, int a6
int ang = interpolatedvalue(a8, a11, a3);
int v14 = ang - v44;

DVector2 pivot = { a4 * maptoworld, a5 * maptoworld };
DVector2 offset = { (vc - a4) * maptoworld, (v8 - a5) * maptoworld };
DVector2 pivot = { a4 * inttoworld, a5 * inttoworld };
DVector2 offset = { (vc - a4) * inttoworld, (v8 - a5) * inttoworld };
auto angle = buildang(ang);

auto rotatewall = [=](walltype* wal, binangle angle, const DVector2& offset)
Expand Down
24 changes: 12 additions & 12 deletions source/games/duke/src/_polymost.cpp
Expand Up @@ -213,27 +213,27 @@ static void geometryEffect(int cposx, int cposy, int cposz, binangle cang, fixed
while (auto act = it.Next())
{
ChangeActorSect(act, geosectorwarp[gs]);
SetActor(act, { act->spr.pos.X -= int(geox[gs] * worldtomap), act->spr.pos.Y -= int(geoy[gs] * worldtomap), act->spr.pos.Z });
SetActor(act, { act->spr.pos.X -= int(geox[gs] * worldtoint), act->spr.pos.Y -= int(geoy[gs] * worldtoint), act->spr.pos.Z });
}
if (geosector[gs] == sectp)
{
geosect = geosectorwarp[gs];
geoid = gs;
}
}
cposx -= int(geox[geoid] * worldtomap);
cposy -= int(geoy[geoid] * worldtomap);
cposx -= int(geox[geoid] * worldtoint);
cposy -= int(geoy[geoid] * worldtoint);
renderDrawRoomsQ16(cposx, cposy, cposz, cang.asq16(), choriz.asq16(), sect, false);
cposx += int(geox[geoid] * worldtomap);
cposy += int(geoy[geoid] * worldtomap);
cposx += int(geox[geoid] * worldtoint);
cposy += int(geoy[geoid] * worldtoint);
for (gs = 0; gs < geocnt; gs++)
{
tgsect = geosectorwarp[gs];
DukeSectIterator it(tgsect);
while (auto act = it.Next())
{
ChangeActorSect(act, geosector[gs]);
SetActor(act, { act->spr.pos.X += int(geox[gs] * worldtomap), act->spr.pos.Y += int(geoy[gs] * worldtomap), act->spr.pos.Z });
SetActor(act, { act->spr.pos.X += int(geox[gs] * worldtoint), act->spr.pos.Y += int(geoy[gs] * worldtoint), act->spr.pos.Z });
}
}
fi.animatesprites(pm_tsprite, pm_spritesortcnt, cposx, cposy, cang.asbuild(), smoothratio);
Expand All @@ -245,27 +245,27 @@ static void geometryEffect(int cposx, int cposy, int cposz, binangle cang, fixed
while (auto act = it.Next())
{
ChangeActorSect(act, geosectorwarp2[gs]);
SetActor(act, { act->spr.pos.X -= int(geox2[gs] * worldtomap), act->spr.pos.Y -= int(geoy2[gs] * worldtomap), act->spr.pos.Z });
SetActor(act, { act->spr.pos.X -= int(geox2[gs] * worldtoint), act->spr.pos.Y -= int(geoy2[gs] * worldtoint), act->spr.pos.Z });
}
if (geosector[gs] == sectp)
{
geosect = geosectorwarp2[gs];
geoid = gs;
}
}
cposx -= int(geox2[geoid] * worldtomap);
cposy -= int(geoy2[geoid] * worldtomap);
cposx -= int(geox2[geoid] * worldtoint);
cposy -= int(geoy2[geoid] * worldtoint);
renderDrawRoomsQ16(cposx, cposy, cposz, cang.asq16(), choriz.asq16(), sect, false);
cposx += int(geox2[geoid] * worldtomap);
cposy += int(geoy2[geoid] * worldtomap);
cposx += int(geox2[geoid] * worldtoint);
cposy += int(geoy2[geoid] * worldtoint);
for (gs = 0; gs < geocnt; gs++)
{
tgsect = geosectorwarp2[gs];
DukeSectIterator it(tgsect);
while (auto act = it.Next())
{
ChangeActorSect(act, geosector[gs]);
SetActor(act, { act->spr.pos.X += int(geox2[gs] * worldtomap), act->spr.pos.Y += int(geoy2[gs] * worldtomap), act->spr.pos.Z });
SetActor(act, { act->spr.pos.X += int(geox2[gs] * worldtoint), act->spr.pos.Y += int(geoy2[gs] * worldtoint), act->spr.pos.Z });
}
}
fi.animatesprites(pm_tsprite, pm_spritesortcnt, cposx, cposy, cang.asbuild(), smoothratio);
Expand Down

0 comments on commit 6fbecf2

Please sign in to comment.