// ----------------------------------------------------------------------- // // // MODULE : ltserverphysics.cpp // // See ltserverphysics.h -- in particular the note that this is NOT LithTech's // physics, which the numbers below will otherwise invite you to forget. // // ----------------------------------------------------------------------- // #include "windows.h" #include "lithtech.h" #include "ltserverphysics.h" #include "ltserverobjects.h" #include "ltserverhost.h" #include "ltworldcollide.h" #include "ltworld.h" #include "ltserverbrush.h" #include #include #include #include #include #include typedef CLTServerObjects::Record SRec; namespace { // ⚠️ GRAVITY IS -2000, AND IT WAS -1000 FOR TWO MONTHS (HANDOVER 5ff). // lithtech.exe builds the client's and the server's MotionInfo with // (0, -2000, 0) and slide ratio -0.7071 (0x410aa2 and 0x4135ec: push 0, // 0xc4fa0000, 0; then SetForce 0x410e20), the donor's motion.h says the // same, and nothing in NOLF ever sets another: WorldProperties has no // gravity property and no ObjectDLL code calls SetGlobalForce. The old // comment here claimed -1000 was "NOLF's own default"; it was a guess. // // ⚠️ THE PLAYER JUMPED TWICE AS HIGH. CPlayerObj sends this value // (PSTATE_GRAVITY, PlayerObj.cpp:1583) and CMoveMgr makes it its own // m_fGravity (CMoveMgr.cpp:2091), so JumpSpeed 550 rose 156 units in 1.1 s // instead of ~78 in 0.57 s. Every FLAG_GRAVITY server object -- bodies, // dropped pickups, thrown grenades -- fell at half speed with it. // // LT_OLDGRAVITY=1 = the old -1000 (says so; see DefaultForce below). float g_Force[3] = { 0.0f, -2000.0f, 0.0f }; // Applies LT_OLDGRAVITY before the first read or write of g_Force, so the // game's own SetGlobalForce still wins over the default. void DefaultForce() { static bool s_bDone = false; if (s_bDone) return; s_bDone = true; if (getenv("LT_OLDGRAVITY")) { g_Force[0] = 0.0f; g_Force[1] = -1000.0f; g_Force[2] = 0.0f; printf("[PHYS] LT_OLDGRAVITY=1 -- world gravity -1000 (old; lithtech.exe: -2000)\n"); fflush(stdout); } } // CCharacter sets 24; the engine default before anyone sets one. float g_fStairHeight = 24.0f; unsigned int g_nMoved = 0; // MoveTo calls that changed a position unsigned int g_nBlocked = 0; // MoveTo calls that ended where they began unsigned int g_nStepped = 0; // moves rescued by the stair lift unsigned int g_nIntegrated = 0; // objects the integrator touched unsigned int g_nGravity = 0; // objects seen with FLAG_GRAVITY unsigned int g_nWithVel = 0; // objects seen with a non-zero velocity unsigned int g_FlagsSeen = 0; // OR of every object's flags unsigned int g_nWithFlags = 0; bool Tracing() { static const bool b = (getenv("LT_PHYSTRACE") != 0); return b; } // ⚠️ THE SPHERE THAT STANDS IN FOR A BOX. Objects are boxes in this game // and the collision takes a sphere, so the radius is the box's smaller // horizontal half-extent -- the LARGER one would wedge a character in a // doorway it is meant to fit through, which reads as "the AI are stuck" // and is the harder failure to diagnose. float RadiusOf(const SRec* p) { float rx = p->m_Dims[0], rz = p->m_Dims[2]; float r = (rx < rz) ? rx : rz; if (r < 1.0f) r = 1.0f; // a zero-dims object still needs a body return r; } // How often each CalcMotion branch ran (LTPHYS_*), and with friction. unsigned int g_nBranch[LTPHYS_FREE + 1] = { 0 }; unsigned int g_nFriction = 0; // ⚠️ THE PLANE STOOD ON, for CalcMotion's slope tests (5fg): lithtech.exe // reads the BSP node the object stands on (+0xec). The port's ground is a // probe (ltworldcollide.cpp, 0.75 skin, n.y > 0.7) that keeps no plane, so // this asks a short ray straight down from the centre, past the sphere's // bottom -- as the client's GetStandingOn does. A miss (a ledge's edge) // answers "straight up", the original's rule for standing on an object. // Asked only for an object standing AND moving: a resting one stops first. bool ServerGroundNormal(void* pCtx, float* pN3) { const SRec* p = (const SRec*)pCtx; if (!p || !LTWorldCollide_Ready()) return false; const float fR = RadiusOf(p); const float from[3] = { p->m_Pos[0], p->m_Pos[1], p->m_Pos[2] }; const float to[3] = { p->m_Pos[0], p->m_Pos[1] - fR - 4.0f, p->m_Pos[2] }; float pt[3], n[3], t; if (!LTGetWorldCollide()->RaySegment(from, to, pt, n, &t)) return false; if (n[1] <= 0.0f) return false; pN3[0] = n[0]; pN3[1] = n[1]; pN3[2] = n[2]; return true; } // The plane found for the standing test, handed to CalcMotion as is. const float kUp[3] = { 0.0f, 1.0f, 0.0f }; struct GroundCtx { bool m_bHave; float m_N[3]; }; bool GroundCtxNormal(void* pCtx, float* pN3) { const GroundCtx* g = (const GroundCtx*)pCtx; if (!g || !g->m_bHave) return false; pN3[0] = g->m_N[0]; pN3[1] = g->m_N[1]; pN3[2] = g->m_N[2]; return true; } unsigned int g_nArriving = 0; // on the probe's floor, still falling into it unsigned int g_nGoThru = 0; // steps of FLAG_GOTHRUWORLD objects (no world touch) unsigned int g_nInVolumes = 0; // object-steps handed to at least one volume (5fj) // ---- LT_ARCTRACE=1 (5fg): each FLAG_GRAVITY object's flights and slides // // // One [ARC] line per spell in the air (from where, at what velocity, to // where, how long, how far) and per slide on the floor (from what speed, // how far, how long until it stopped), so the old and the new step can be // compared on the same throw. An object removed mid-spell (a bomb that // went off on impact) is reported where it was last seen. struct ArcState { int m_nState; // 0 idle, 1 in the air, 2 sliding float m_fT; float m_P0[3], m_V0[3], m_Last[3]; float m_fTop; std::string m_sName; }; std::map g_Arcs; unsigned int g_nArcPrinted = 0; void ArcPrint(const char* pWhat, const ArcState& s, const float* pEnd, float fSpeedEnd) { if (g_nArcPrinted++ >= 200) return; const float dx = pEnd[0] - s.m_P0[0], dz = pEnd[2] - s.m_P0[2]; printf("[ARC] %-20s %-8s from (%.1f %.1f %.1f) vel (%.1f %.1f %.1f) -> (%.1f %.1f %.1f) after %.3f s: %.1f across, %+.1f up (top %+.1f), speed then %.1f\n", s.m_sName.empty() ? "(unnamed)" : s.m_sName.c_str(), pWhat, s.m_P0[0], s.m_P0[1], s.m_P0[2], s.m_V0[0], s.m_V0[1], s.m_V0[2], pEnd[0], pEnd[1], pEnd[2], s.m_fT, sqrtf(dx*dx + dz*dz), pEnd[1] - s.m_P0[1], s.m_fTop - s.m_P0[1], fSpeedEnd); fflush(stdout); } void ArcTrace(void* h, const float* pPrePos, const float* pPreVel, float dt) { SRec* p = CLTServerObjects::FromHandle(h); const bool bLive = p && LTServerHost_IsLive(h); std::map::iterator it = g_Arcs.find(h); if (!bLive) { if (it != g_Arcs.end()) { if (it->second.m_nState) ArcPrint(it->second.m_nState == 1 ? "air,gone" : "slid,gone", it->second, it->second.m_Last, 0.0f); g_Arcs.erase(it); } return; } if (!(p->m_Flags & FLAG_GRAVITY)) return; if (it == g_Arcs.end()) { ArcState s0; s0.m_nState = 0; s0.m_fT = 0.0f; s0.m_fTop = 0.0f; it = g_Arcs.insert(std::make_pair(h, s0)).first; } ArcState& s = it->second; const float* v = p->m_Vel; const float fSpeed = sqrtf(v[0]*v[0] + v[1]*v[1] + v[2]*v[2]); const float fFlat2 = v[0]*v[0] + v[2]*v[2]; const bool bAir = !p->m_bOnGround; for (int k = 0; k < 3; ++k) s.m_Last[k] = p->m_Pos[k]; if (s.m_nState == 0) { if ((bAir && fSpeed > 1.0f) || (!bAir && fFlat2 > 1.0f)) { s.m_nState = bAir ? 1 : 2; s.m_fT = dt; s.m_sName = p->m_sName; for (int k = 0; k < 3; ++k) { s.m_P0[k] = pPrePos[k]; s.m_V0[k] = pPreVel[k]; } s.m_fTop = p->m_Pos[1] > pPrePos[1] ? p->m_Pos[1] : pPrePos[1]; } return; } s.m_fT += dt; if (p->m_Pos[1] > s.m_fTop) s.m_fTop = p->m_Pos[1]; if (s.m_nState == 1 && !bAir) { ArcPrint("air", s, p->m_Pos, fSpeed); s.m_nState = 0; } else if (s.m_nState == 2 && (bAir || fFlat2 <= 1.0f)) { ArcPrint(bAir ? "slid,off" : "slid", s, p->m_Pos, fSpeed); s.m_nState = 0; } } } // ---- lithtech.exe's CalcMotion (0x4500d0) -- see ltserverphysics.h ----- // // // Read off the shipped binary (HANDOVER 5fg), the donor's motion.cpp says the // same: constants 0.1 (0x4a1e24), 0.01 (0x4a1e08), 0.5 (0x4a1a74); the // MotionInfo's slide ratio is -0.7071 (0xbf350481, set at 0x410aa2/0x4135ec) // and its unit force the force's direction. The order of the float operations // is the binary's; x87's wider intermediates are not reproduced. bool LTPhys_CalcMotion(float dt, bool bGravity, bool bStanding, bool (*pGetNormal)(void* pCtx, float* pN3), void* pCtx, float fFriction, float* v, float* a, float* dr, int* pBranch, bool* pbFriction) { static const float kSlideRatio = -0.70710677f; float F[3]; LTServerPhys_GetGlobalForce(F); const float fTimeIntegral = dt * dt * 0.5f; float fVel2 = v[0]*v[0] + v[1]*v[1] + v[2]*v[2]; float fAcc2 = a[0]*a[0] + a[1]*a[1] + a[2]*a[2]; if (fVel2 < 0.1f) { fVel2 = 0.0f; v[0] = v[1] = v[2] = 0.0f; } if (fAcc2 < 0.1f) { fAcc2 = 0.0f; a[0] = a[1] = a[2] = 0.0f; } dr[0] = dr[1] = dr[2] = 0.0f; bool bFriction = false; int nBranch = LTPHYS_FREE; if (bGravity) { if (bStanding) { if (fVel2 < 0.1f && fAcc2 < 0.1f) { v[0] = v[1] = v[2] = 0.0f; a[0] = a[1] = a[2] = 0.0f; if (pBranch) *pBranch = LTPHYS_STOP; if (pbFriction) *pbFriction = false; return false; } // The force's direction (0x436760 Mag, then 1/mag), and the plane: // the node stood on, else minus the unit force. float fd[3] = { F[0], F[1], F[2] }; const float fFMag = sqrtf(fd[0]*fd[0] + fd[1]*fd[1] + fd[2]*fd[2]); if (fFMag != 0.0f) { const float r = 1.0f / fFMag; fd[0] *= r; fd[1] *= r; fd[2] *= r; } float n[3] = { -fd[0], -fd[1], -fd[2] }; if (fFMag == 0.0f) { n[0] = 0.0f; n[1] = 1.0f; n[2] = 0.0f; } float nPlane[3]; if (pGetNormal && pGetNormal(pCtx, nPlane)) { n[0] = nPlane[0]; n[1] = nPlane[1]; n[2] = nPlane[2]; } const float awf[3] = { a[0] + F[0], a[1] + F[1], a[2] + F[2] }; if (fd[0]*n[0] + fd[1]*n[1] + fd[2]*n[2] > kSlideRatio) { // "Steep": slide along the plane, never up it, at |a + F|. nBranch = LTPHYS_STEEP; const float fMag = sqrtf(awf[0]*awf[0] + awf[1]*awf[1] + awf[2]*awf[2]); const float d = awf[0]*n[0] + awf[1]*n[1] + awf[2]*n[2]; for (int k = 0; k < 3; ++k) a[k] = awf[k] - n[k] * d; const float fUp = a[0]*fd[0] + a[1]*fd[1] + a[2]*fd[2]; if (fUp < 0.0f) for (int k = 0; k < 3; ++k) a[k] -= fd[k] * fUp; const float m = sqrtf(a[0]*a[0] + a[1]*a[1] + a[2]*a[2]); if (m != 0.0f) { const float s = fMag / m; a[0] *= s; a[1] *= s; a[2] *= s; } } else { const float nv[3] = { v[0] + F[0] * dt, v[1] + F[1] * dt, v[2] + F[2] * dt }; if (nv[0]*n[0] + nv[1]*n[1] + nv[2]*n[2] > 0.01f) { nBranch = LTPHYS_JUMP; // leaving the plane: full force for (int k = 0; k < 3; ++k) a[k] = awf[k]; } else if (a[0]*n[0] + a[1]*n[1] + a[2]*n[2] > 0.01f) { // "Downhill": turned into the plane, same magnitude. nBranch = LTPHYS_DOWNHILL; const float fMag = sqrtf(a[0]*a[0] + a[1]*a[1] + a[2]*a[2]); const float d = n[0]*a[0] + n[1]*a[1] + n[2]*a[2] + 1.0f; for (int k = 0; k < 3; ++k) a[k] -= n[k] * d; const float m = sqrtf(a[0]*a[0] + a[1]*a[1] + a[2]*a[2]); if (m != 0.0f) { const float s = fMag / m; a[0] *= s; a[1] *= s; a[2] *= s; } bFriction = true; } else { nBranch = LTPHYS_WALK; // the force is held by the floor bFriction = true; } } } else { nBranch = LTPHYS_FALL; for (int k = 0; k < 3; ++k) a[k] += F[k]; } } else if (fVel2 < 0.1f && fAcc2 < 0.1f) { v[0] = v[1] = v[2] = 0.0f; a[0] = a[1] = a[2] = 0.0f; if (pBranch) *pBranch = LTPHYS_STOP; if (pbFriction) *pbFriction = false; return false; } const float k = fFriction; if (bFriction && k > 0.0f) { // 0x4506d2: exp by x87 f2xm1/fscale; the closed form of v' = a - k v. const float e = expf(-k * dt); const float f = (1.0f - e) / k / k; for (int i = 0; i < 3; ++i) { const float akk = a[i] / k; const float vNew = (v[i] - akk) * e + akk; dr[i] = akk * dt + (v[i] * k - a[i]) * f; v[i] = vNew; } } else { bFriction = false; for (int i = 0; i < 3; ++i) { dr[i] = v[i] * dt + a[i] * (fTimeIntegral * 0.5f); v[i] += a[i] * dt; } } if (pBranch) *pBranch = nBranch; if (pbFriction) *pbFriction = bFriction; return true; } // ⚠️ These three now just forward to the SHARED grid (ltworldcollide.h). They // are kept as server-named entry points because the server's world-load path // calls them and should not have to know where the grid lives. void LTServerPhys_BuildFor(const CLTWorld* pWorld) { LTWorldCollide_BuildFor(pWorld); } void LTServerPhys_Reset() { LTWorldCollide_Reset(); } bool LTServerPhys_Ready() { return LTWorldCollide_Ready(); } bool LTServerPhys_MoveTo(void* hObj, const float* pWantPos3, bool* pbGround) { if (pbGround) *pbGround = false; SRec* p = CLTServerObjects::FromHandle(hObj); if (!p || !pWantPos3) return false; p->m_bEverMoved = true; // MoveObject makes the container links (5fj) // ⚠️ WITH NO COLLISION BUILT THIS IS A TELEPORT, and saying so matters: // the walk viewer builds its own grid and the server builds this one, so // a path that forgot to build would move everything through walls and // look like a collision BUG rather than a missing call. if (!LTServerPhys_Ready()) { for (int k = 0; k < 3; ++k) p->m_Pos[k] = pWantPos3[k]; return true; } const float fR = RadiusOf(p); float start[3] = { p->m_Pos[0], p->m_Pos[1], p->m_Pos[2] }; float delta[3] = { pWantPos3[0] - start[0], pWantPos3[1] - start[1], pWantPos3[2] - start[2] }; if (delta[0] == 0.0f && delta[1] == 0.0f && delta[2] == 0.0f) { if (pbGround) *pbGround = p->m_bOnGround; return false; } float pos[3] = { start[0], start[1], start[2] }; bool bGround = false; CLTWorldCollide::Contacts contacts; LTGetWorldCollide()->MoveSphere(pos, delta, fR, &bGround, &contacts); // ⚠️ THE STAIR LIFT, and it is the difference between a level you can walk // through and one where every doorway sill stops you. If the flat part of // the move was blocked, try again from stair height up and drop back down. // Walk mode does exactly this (ltworldwalk.cpp) and it is why the viewer // can climb M01S01's steps; the server had no equivalent at all. const float fFlatWanted = fabsf(delta[0]) + fabsf(delta[2]); const float fFlatGot = fabsf(pos[0] - start[0]) + fabsf(pos[2] - start[2]); if (g_fStairHeight > 0.0f && fFlatWanted > 0.01f && fFlatGot < fFlatWanted * 0.5f) { float lifted[3] = { start[0], start[1] + g_fStairHeight, start[2] }; if (!LTGetWorldCollide()->Overlaps(lifted, fR)) { float flat[3] = { delta[0], 0.0f, delta[2] }; bool bG2 = false; CLTWorldCollide::Contacts c2; LTGetWorldCollide()->MoveSphere(lifted, flat, fR, &bG2, &c2); const float fGot2 = fabsf(lifted[0] - start[0]) + fabsf(lifted[2] - start[2]); if (fGot2 > fFlatGot) { contacts = c2; // the path taken is the one that touched float drop[3] = { 0.0f, -(g_fStairHeight + 1.0f), 0.0f }; LTGetWorldCollide()->MoveSphere(lifted, drop, fR, &bG2); for (int k = 0; k < 3; ++k) pos[k] = lifted[k]; bGround = bG2; ++g_nStepped; } } } for (int k = 0; k < 3; ++k) p->m_Pos[k] = pos[k]; p->m_bOnGround = bGround; if (pbGround) *pbGround = bGround; // ⚠️ THE WORLD TOUCH (5do) -- the donor's CollideAgainstWorld // (moveobject.cpp) and collision response (collision.cpp). Without it a // projectile SLID along the wall it met and was never told: a crossbow // bolt fired at a wall lived on (no sticking), grenades could not bounce. // For each surface the sphere was pushed out of, in order: if the object // moves INTO it, the stopping velocity is -n(v.n) and the force that // times IMPULSE_TIME_CONSTANT (0.01) and the mass; the velocity offset // gets the extra -n x 0.05 (EXTRA_PENETRATION_ADD, "so friction will still // be applied"). A touch-notify object is told if the force reaches its // ignore limit (default 1000; projectiles set 0), with the LAST surface's // plane and polygon; then the offset is added to its velocity -- the // engine's half of every bounce the game computes. FLAG_GOTHRUWORLD // objects do not collide in the donor and are not touched here. // LT_NOWORLDTOUCH=1 = the old slide with nothing told (says so). static const bool s_bNoTouch = []() { const bool b = (getenv("LT_NOWORLDTOUCH") != 0); if (b) { printf("[PHYS] LT_NOWORLDTOUCH=1 -- moving objects slide along the world and are never told (old)\n"); fflush(stdout); } return b; }(); if (contacts.m_nHits > 0 && !s_bNoTouch && !(p->m_Flags & FLAG_GOTHRUWORLD)) { const int nN = contacts.m_nHits < CLTWorldCollide::Contacts::kMaxNormals ? contacts.m_nHits : (int)CLTWorldCollide::Contacts::kMaxNormals; float off[3] = { 0, 0, 0 }, force[3] = { 0, 0, 0 }; const float fMass = p->m_fMass > 0.0f ? p->m_fMass : 0.0f; for (int i = 0; i < nN; ++i) { const float* n = contacts.m_Normals[i]; const float vd = (p->m_Vel[0] + off[0]) * n[0] + (p->m_Vel[1] + off[1]) * n[1] + (p->m_Vel[2] + off[2]) * n[2]; if (vd >= 0.0f) continue; for (int k = 0; k < 3; ++k) { const float add = -n[k] * vd; force[k] += add * 0.01f * fMass; off[k] += add - n[k] * 0.05f; } } const float fForce2 = force[0]*force[0] + force[1]*force[1] + force[2]*force[2]; const float fLimit = p->m_fForceIgnoreLimit; if ((p->m_Flags & FLAG_TOUCH_NOTIFY) && fForce2 >= fLimit * fLimit) { const float* nL = contacts.m_Normals[nN - 1]; const float fDist = nL[0]*contacts.m_Point[0] + nL[1]*contacts.m_Point[1] + nL[2]*contacts.m_Point[2]; LTServerHost_WorldTouch(hObj, contacts.m_pOwner, nL, fDist, contacts.m_nPoly, off, sqrtf(fForce2)); } // The game may have removed it, moved it or set its velocity; the // offset still applies on top, as the donor applies it after. SRec* pAfter = CLTServerObjects::FromHandle(hObj); if (pAfter && LTServerHost_IsLive(hObj)) for (int k = 0; k < 3; ++k) pAfter->m_Vel[k] += off[k]; } const bool bMoved = (pos[0] != start[0] || pos[1] != start[1] || pos[2] != start[2]); if (bMoved) ++g_nMoved; else ++g_nBlocked; if (Tracing() && !bMoved) printf("[PHYS] blocked %-24s at (%.0f %.0f %.0f) r=%.0f\n", p->m_sName.empty() ? "(unnamed)" : p->m_sName.c_str(), start[0], start[1], start[2], fR); return bMoved; } void LTServerPhys_TeleportTo(void* hObj, const float* pPos3) { SRec* p = CLTServerObjects::FromHandle(hObj); if (!p || !pPos3) return; for (int k = 0; k < 3; ++k) p->m_Pos[k] = pPos3[k]; p->m_bOnGround = false; p->m_bEverMoved = true; // a teleport makes the container links too (5fj) } void LTServerPhys_Update(float fDelta) { if (fDelta <= 0.0f) return; DefaultForce(); // ⚠️ CLAMPED. A frame that stalled -- a texture decode, a breakpoint, a // level load -- would otherwise integrate a single step across the level // and fling everything through the geometry. Walk mode clamps for the same // reason at the same value. if (fDelta > 0.10f) fDelta = 0.10f; // LT_OLDSERVERSTEP=1 = the port's old integrator (5fg; says so): // v += (a + g) dt, downward velocity zeroed on the floor, moved by the new // velocity, acceleration kept, no friction. static const bool s_bOldStep = []() { const bool b = (getenv("LT_OLDSERVERSTEP") != 0); if (b) { printf("[PHYS] LT_OLDSERVERSTEP=1 -- server objects step by the new velocity, keep their acceleration, no friction (old)\n"); fflush(stdout); } return b; }(); static const bool s_bArcTrace = (getenv("LT_ARCTRACE") != 0); if (s_bArcTrace) // objects removed since the last step for (std::map::iterator it = g_Arcs.begin(); it != g_Arcs.end(); ) { std::map::iterator cur = it++; if (!CLTServerObjects::FromHandle(cur->first) || !LTServerHost_IsLive(cur->first)) ArcTrace(cur->first, 0, 0, 0.0f); } // This step's volumes (HANDOVER 5fj). Not with LT_OLDSERVERSTEP=1: the // copy below is CalcMotion's, and the old integrator has none. const unsigned int nVolumes = s_bOldStep ? 0 : LTServerHost_BeginContainerPass(); const unsigned int n = LTServerHost_ObjectCount(); for (unsigned int i = 0; i < n; ++i) { void* h = LTServerHost_ObjectAt(i); SRec* p = CLTServerObjects::FromHandle(h); if (!p) continue; // Asleep (HANDOVER 5cp): lithtech.exe moves only awake objects. if (p->m_nInactive) continue; // ⚠️ ITS VOLUMES FIRST (HANDOVER 5fj, lithtech.exe 0x4698d1..0x469976): // an object that is no container and has been moved since it was // created (= has container links) hands a COPY of its acceleration, // velocity and flags to every volume it is in (MID_AFFECTPHYSICS -- // water's viscosity, current and liquid gravity, and every volume's // damage), and is then stepped FROM THE COPY. An object in a volume is // never skipped by the early out: lithtech.exe sets IFLAG_APPLYPHYSICS // again after each step in one (0x4699b1), so the player standing // still in poison gas keeps being handed to it -- that is what hurts. float cv[3], ca[3]; unsigned int cflags = p->m_Flags; unsigned int nIn = 0; if (nVolumes && p->m_bEverMoved && !(p->m_Flags & FLAG_CONTAINER)) { for (int k = 0; k < 3; ++k) { cv[k] = p->m_Vel[k]; ca[k] = p->m_Accel[k]; } nIn = LTServerHost_ContainerPass(h, ca, cv, &cflags); if (nIn) { ++g_nInVolumes; p = CLTServerObjects::FromHandle(h); // a volume may have removed it if (!p) continue; } } const bool bGravity = nIn ? (cflags & FLAG_GRAVITY) != 0 : (p->m_Flags & FLAG_GRAVITY) != 0; const bool bVel = (p->m_Vel[0] != 0.0f || p->m_Vel[1] != 0.0f || p->m_Vel[2] != 0.0f); if (bGravity) ++g_nGravity; if (bVel) ++g_nWithVel; g_FlagsSeen |= p->m_Flags; if (p->m_Flags) ++g_nWithFlags; // ⚠️ THE EARLY OUT THAT MAKES THIS AFFORDABLE. A level is 731 objects // and a handful of them ever move; without this every light, every // AINode and every trigger would be swept against the world each tick. if (!nIn && !bGravity && p->m_Vel[0] == 0.0f && p->m_Vel[1] == 0.0f && p->m_Vel[2] == 0.0f && p->m_Accel[0] == 0.0f && p->m_Accel[1] == 0.0f && p->m_Accel[2] == 0.0f) continue; const float fPrePos[3] = { p->m_Pos[0], p->m_Pos[1], p->m_Pos[2] }; const float fPreVel[3] = { p->m_Vel[0], p->m_Vel[1], p->m_Vel[2] }; if (s_bOldStep) { for (int k = 0; k < 3; ++k) { float a = p->m_Accel[k]; if (bGravity) a += g_Force[k]; p->m_Vel[k] += a * fDelta; } // ⚠️ RESTING KILLS DOWNWARD VELOCITY, or gravity accumulates forever // while the object sits on the floor and the first sideways nudge // launches it at whatever speed it has silently reached. if (p->m_bOnGround && p->m_Vel[1] < 0.0f) p->m_Vel[1] = 0.0f; float want[3] = { p->m_Pos[0] + p->m_Vel[0] * fDelta, p->m_Pos[1] + p->m_Vel[1] * fDelta, p->m_Pos[2] + p->m_Vel[2] * fDelta }; bool bGround = false; LTServerPhys_MoveTo(h, want, &bGround); ++g_nIntegrated; if (s_bArcTrace) ArcTrace(h, fPrePos, fPreVel, fDelta); continue; } // ⚠️ LITHTECH.EXE'S OWN STEP (HANDOVER 5fg): the object update // 0x469800 runs CalcMotion (call sites 0x46998e, with containers, // and 0x469afe) on the object's velocity and acceleration, then -- // only when CalcMotion did not stop it -- CLEARS THE ACCELERATION // (0x4699d6) and moves the object by the displacement if // |dr|^2 > 0.001 (0x4699f4, [0x4a1a54]). The port integrated by the // NEW velocity (dr = (v + a dt) dt), kept every acceleration forever // (CCharacter::SpawnItem's one-frame push of a dropped item never // ended) and had no friction at all: m_fFriction was stored, never // read, and started at 0 where lithtech.exe's objects start at 5 // (0x45a91f). A grenade fell 0.75 g dt^2 a frame too far: 25 units // per second of flight at 60 fps. The resting rule -- downward // velocity zeroed on the floor -- is the world touch's job now // (5do: the velocity into a surface is taken away, as the donor's // collision response does), and CalcMotion's walk branch adds no // gravity to an object standing still. // In a volume the step runs on the volumes' copy (5fj, above). float v[3] = { p->m_Vel[0], p->m_Vel[1], p->m_Vel[2] }; float a[3] = { p->m_Accel[0], p->m_Accel[1], p->m_Accel[2] }; if (nIn) for (int k = 0; k < 3; ++k) { v[k] = cv[k]; a[k] = ca[k]; } float dr[3]; int nBranch = LTPHYS_FREE; bool bFriction = false; // ⚠️ STANDING MEANS THE FLOOR HAS STOPPED IT. lithtech.exe sets // "standing on" from the collision of the move itself, and that // collision has taken the velocity into the plane away, all but the // 0.05 it leaves on purpose (EXTRA_PENETRATION_ADD) -- a standing // object never still falls into its floor. The port's ground is a // probe with a 0.75 skin (ltworldcollide.cpp), so a falling object // whose step ends inside the skin, short of contact, counted as // standing at full speed: a coin landing at 605 u/s took two frames // of WALK friction (-15%) before its first touch, and bounced short. // So: standing, but moving into the plane faster than 0.1 u/s, is // the last bit of a fall. LT_OLDSERVERSTEP=1 has no such rule. GroundCtx g; g.m_bHave = false; bool bStanding = p->m_bOnGround; if (bStanding && bGravity && v[0]*v[0] + v[1]*v[1] + v[2]*v[2] >= 0.1f) { g.m_bHave = ServerGroundNormal(p, g.m_N); const float* n = g.m_bHave ? g.m_N : kUp; if (v[0]*n[0] + v[1]*n[1] + v[2]*n[2] < -0.1f) { bStanding = false; ++g_nArriving; } } const bool bGo = LTPhys_CalcMotion(fDelta, bGravity, bStanding, GroundCtxNormal, &g, p->m_fFriction, v, a, dr, &nBranch, &bFriction); ++g_nBranch[nBranch]; if (bFriction) ++g_nFriction; if (p->m_Flags & FLAG_GOTHRUWORLD) ++g_nGoThru; if (!nIn) for (int k = 0; k < 3; ++k) { p->m_Vel[k] = v[k]; p->m_Accel[k] = 0.0f; } else { // ⚠️ WHAT OF THE VOLUMES' COPY THE OBJECT KEEPS (5fj) -- CalcMotion // writes the OBJECT's velocity, not the copy it ran on: // stop (0x450694): the object's v and a = 0; // friction (0x450910): v = a/k + (v_copy - a/k) e^(-k dt); // no friction (0x4509b5): v = v_object + a_copy dt. // So a volume's ACCELERATION (liquid gravity) carries over from // step to step, but its change to the VELOCITY -- viscosity's // brake, the current's push -- only moves the object this step, // unless it is sliding on a floor (friction branch). if (!bGo) for (int k = 0; k < 3; ++k) p->m_Vel[k] = 0.0f; else if (bFriction) for (int k = 0; k < 3; ++k) p->m_Vel[k] = v[k]; else for (int k = 0; k < 3; ++k) p->m_Vel[k] += a[k] * fDelta; for (int k = 0; k < 3; ++k) p->m_Accel[k] = 0.0f; } if (bGo && dr[0]*dr[0] + dr[1]*dr[1] + dr[2]*dr[2] > 0.001f) { const float want[3] = { p->m_Pos[0] + dr[0], p->m_Pos[1] + dr[1], p->m_Pos[2] + dr[2] }; bool bGround = false; LTServerPhys_MoveTo(h, want, &bGround); ++g_nIntegrated; } if (s_bArcTrace) ArcTrace(h, fPrePos, fPreVel, fDelta); } } // ⚠️ Slab test against an axis-aligned box. Returns the near hit distance. static bool RayBox(const float* o, const float* d, float fLen, const float* mn, const float* mx, float* pT, float* pN) { // LT_RAYBOXEDGES=1 = old (see the edge test below); read on the first // box test, so an A/B arm announces itself even if no ray reaches a box. static const bool s_bEdges = []() { const bool b = (getenv("LT_RAYBOXEDGES") != 0); if (b) { printf("[PHYS] LT_RAYBOXEDGES=1 -- a ray along an object box's edge hits it (old)\n"); fflush(stdout); } return b; }(); float tmin = 0.0f, tmax = fLen; int nAxis = 0; float nSign = -1.0f; for (int k = 0; k < 3; ++k) { if (fabsf(d[k]) < 1e-8f) { // Parallel to this slab: miss unless the origin is already inside. if (o[k] < mn[k] || o[k] > mx[k]) return false; continue; } const float inv = 1.0f / d[k]; float t1 = (mn[k] - o[k]) * inv; float t2 = (mx[k] - o[k]) * inv; float s = -1.0f; if (t1 > t2) { float t = t1; t1 = t2; t2 = t; s = 1.0f; } if (t1 > tmin) { tmin = t1; nAxis = k; nSign = s; } if (t2 < tmax) tmax = t2; if (tmin > tmax) return false; } // ⚠️ A RAY ALONG THE BOX'S EDGE MISSES (HANDOVER 5dz). The donor's face // test is strict (fullintersectline.cpp DO_PLANE_TEST_*: min < x < max on // the face's other two axes). M04S02's spawners stand 24 x 16 units // apart, so jorgen2's floor ray ran down x = -800, exactly jorgen1's // edge: it "landed" on his head, 106 units up, and hung there all // mission. LT_RAYBOXEDGES=1 = old (edges hit; says so). if (!s_bEdges) for (int k = 0; k < 3; ++k) { if (k == nAxis) continue; const float p = o[k] + d[k] * tmin; if (p <= mn[k] || p >= mx[k]) return false; } *pT = tmin; pN[0] = pN[1] = pN[2] = 0.0f; pN[nAxis] = nSign; return true; } namespace { // What a ray has found so far: the world's answer going into the object // loop, the nearest hit coming out of it. struct RayBest { float m_fBest; float m_N[3]; void* m_h; bool m_bHit; unsigned int m_nPoly; }; // LT_RAYGRIDDIFF=1 census of the object loop (5eg), printed at exit. unsigned long long g_nObjAsked = 0, g_nObjDiff = 0, g_nObjHits = 0; unsigned long long g_nFilterNew = 0, g_nFilterOld = 0; void ObjDiffCensus() { printf("[OBJRAY] %llu object loop(s) run both ways (%llu ended on an object), %llu differ; the game's filter was asked %llu time(s) box-first, %llu the old way\n", g_nObjAsked, g_nObjHits, g_nObjDiff, g_nFilterNew, g_nFilterOld); fflush(stdout); } } // ⚠️ THE GEOMETRY FIRST, THE GAME'S FILTER LAST (5eg). Every ray walked every // live object (~1,470 in M02S01), and every object that passed the flag checks // had its name compared against the power lines and was then handed to the // game's filter -- a call into the game, which on the client side also looks // the object's mirror up -- before any box was tested. Lens flares cast one // such ray a frame across the whole level, and this walk was most of what // was left of the server ray after 5ef. // // Now the box (a brush object: its geometry) is tested first, and the name // and the filter are asked only for an object whose hit would become the // nearest. The answers are the same because both questions are pure: the name // is a string compare, and every object filter the game hands a ray (20 of // them, server and client: CAI's, CScanner's, Activate, DoVector, Explosion, // Ground, Flying, the liquid, list and non-solid ones) reads flags, classes, // user flags, container codes, positions and alignment and changes nothing. // Objects are still walked in list order with the same tie rules, and an // object the filter turns away still never moves fBest, so the nearest hit is // the same object at the same bits. The donor asks its filter only after a // sphere test too (fullintersectline.cpp i_HandlePossibleIntersection) -- the // old order called into the game for objects LithTech never asked about. // LT_RAYOBJOLD=1 = the old order (says so); LT_RAYGRIDDIFF=1 runs both and // counts any difference, and how often each asked the filter ([OBJRAY]). static void RayObjects(bool bOld, const float* pFrom3, const float* pTo3, const float* d, float fLen, bool (*pFilter)(void*, void*), void* pUser, bool bIgnoreNonSolid, unsigned long long* pFilterCalls, RayBest& b) { // ⚠️ SOLID **OR RAYHIT** -- the donor's rule (fullintersectline.cpp // i_ISCallback). A character is shot through its CCharacterHitBox, // which is RAYHIT and NOT solid; testing SOLID alone let every bullet // pass through every enemy (M01S01, HANDOVER 5bb). Triggers carry // neither flag, so the Activate fix below still holds. // LT_SOLIDONLYRAYS=1 = the old rule. static const bool s_bSolidOnly = []() { const bool b = (getenv("LT_SOLIDONLYRAYS") != 0); if (b) { printf("[PHYS] LT_SOLIDONLYRAYS=1 -- rays ignore RAYHIT-only objects\n"); fflush(stdout); } return b; }(); // ⚠️ A BRUSH OBJECT IS HIT BY ITS GEOMETRY, WHERE IT IS NOW -- not by // its load-time box. An opened shutter (M01S01 `vwindow2`) kept // catching every shot through the window. LT_BOXRAYS=1 = the old rule. static const bool s_bBoxRays = []() { const bool b = (getenv("LT_BOXRAYS") != 0); if (b) { printf("[PHYS] LT_BOXRAYS=1 -- brush objects hit-tested by their box\n"); fflush(stdout); } return b; }(); const unsigned int nHitFlags = s_bSolidOnly ? FLAG_SOLID : (FLAG_SOLID | FLAG_RAYHIT); // The two questions that are not geometry, asked last (box-first) or // before the geometry (old). DEVIATIONS E-008: rays pass through the // power lines (the user's call). The game's own filter is how the player // avoids shooting himself and how activate skips what it does not want. auto wanted = [&](void* h, const SRec* p) -> bool { if (LTServerBrush_RaysPassThrough(p->m_sName.c_str())) return false; if (!pFilter) return true; ++*pFilterCalls; return pFilter(h, pUser); }; const unsigned int n = LTServerHost_ObjectCount(); for (unsigned int i = 0; i < n; ++i) { void* h = bOld ? LTServerHost_ObjectAt(i) : LTServerHost_ListedObjectAt(i); SRec* p = CLTServerObjects::FromHandle(h); if (!p) continue; // ⚠️ A ZERO-SIZED OBJECT IS NOT A TARGET -- unless it is a BRUSH // object with a box of its own (see Record::m_bHasBox). Triggers, AI // nodes and sounds have neither, and treating them as points would // make the player "activate" invisible bookkeeping. // ⚠️ THE GAME'S QUERY FLAGS, which IntersectSegment used to drop. // Activate asks for IGNORE_NONSOLID: a trigger volume is not something // a ray stops on. Measured on T01S03 before this: an Activate ray aimed // at TrainingDoor1 from behind stopped at 'CivTrigger' -- a 128x64x64 // invisible volume -- and never reached the door. if (bIgnoreNonSolid && !(p->m_Flags & nHitFlags)) continue; if (bOld && LTServerBrush_RaysPassThrough(p->m_sName.c_str())) continue; const bool bBox = p->m_bHasBox; if (!bBox && p->m_Dims[0] <= 0.0f && p->m_Dims[1] <= 0.0f && p->m_Dims[2] <= 0.0f) continue; // ⚠️ A NON-SOLID brush (a trigger volume, an AI volume) is not // something a ray stops on. Same flag the game's IGNORE_NONSOLID means. if (bBox && !(p->m_Flags & nHitFlags)) continue; if (bOld && pFilter) { ++*pFilterCalls; if (!pFilter(h, pUser)) continue; } if (bBox && !s_bBoxRays) { float fFrac, nb[3]; unsigned int nBP = 0; const int r = LTServerBrush_RayTest(h, pFrom3, pTo3, &fFrac, nb, &nBP); if (r >= 0) { // Same tie rule as the box below: a brush beats the world it // is also part of when they are hit at the same distance. if (r == 1 && fFrac * fLen < b.m_fBest + 1.0f && (bOld || wanted(h, p))) { b.m_fBest = fFrac * fLen; for (int k=0;k<3;++k) b.m_N[k]=nb[k]; b.m_h = h; b.m_bHit = true; b.m_nPoly = nBP; } continue; } } float mn[3], mx[3]; if (bBox) { // ⚠️ The box FOLLOWS THE OBJECT: a door that has slid open is hit // where it is now, not where the level put it. Translation only -- // a swinging door is approximated by its rest box moved with it. for (int k = 0; k < 3; ++k) { const float d0 = p->m_Pos[k] - p->m_BoxRestPos[k]; mn[k] = p->m_BoxMin[k] + d0; mx[k] = p->m_BoxMax[k] + d0; } } else { for (int k = 0; k < 3; ++k) { mn[k] = p->m_Pos[k] - p->m_Dims[k]; mx[k] = p->m_Pos[k] + p->m_Dims[k]; } } // ⚠️ A BOX THE RAY STARTS INSIDE IS NOT A HIT AT ZERO DISTANCE. // // The game casts from an object's own position constantly -- // MoveObjectToFloor (ServerUtilities.cpp:480) drops a 10,000-unit ray // straight down from the player -- and the player's own hit box sits // at that exact point. Reporting it gives a hit at distance 0, so // MoveObjectToFloor computes fDist = 0, decides the object is already // on the floor, and leaves it hanging in the air. Measured on T01S02: // the cast from the lobby TeleportPoint returned the player's own box // instead of the floor 64 units below. // // Real LithTech's filter callbacks are how the game normally avoids // this, but MoveObjectToFloor passes none -- so the engine has to be // the one that does not answer "you are standing on yourself". bool bInside = true; for (int k = 0; k < 3; ++k) if (pFrom3[k] < mn[k] || pFrom3[k] > mx[k]) { bInside = false; break; } if (bInside) continue; float t, nb[3]; // ⚠️ A BRUSH OBJECT WINS A TIE WITH THE WORLD. Its triangles are in // the collision set too (as dynamic geometry, which carries no owner), // and its box encloses them exactly -- so the box face and the // triangle are hit at the SAME distance. With a strict "<" the world // won that tie and every door reported itself as "the world": the // Activate ray reached TrainingDoor1's face at z=-1788 and the game // was told it had touched a wall. const float fSlack = bBox ? 1.0f : 0.0f; // world units, like fBest if (RayBox(pFrom3, d, b.m_fBest + fSlack, mn, mx, &t, nb) && t < b.m_fBest + fSlack && (bOld || wanted(h, p))) { b.m_fBest = t; for (int k=0;k<3;++k) b.m_N[k]=nb[k]; b.m_h = h; b.m_bHit = true; b.m_nPoly = 0; } } } bool LTServerPhys_RayTest(const float* pFrom3, const float* pTo3, bool (*pFilter)(void*, void*), void* pUser, float* pPoint3, float* pNormal3, void** ppHitObj, bool bObjects, bool bIgnoreNonSolid, unsigned int* pPolyId) { if (ppHitObj) *ppHitObj = 0; if (pPolyId) *pPolyId = 0; if (!pFrom3 || !pTo3) return false; float d[3] = { pTo3[0]-pFrom3[0], pTo3[1]-pFrom3[1], pTo3[2]-pFrom3[2] }; const float fLen = sqrtf(d[0]*d[0] + d[1]*d[1] + d[2]*d[2]); if (fLen <= 0.0f) return false; for (int k = 0; k < 3; ++k) d[k] /= fLen; RayBest b = { fLen, { 0.0f, 1.0f, 0.0f }, 0, false, 0 }; // --- the world -------------------------------------------------------- // if (LTWorldCollide_Ready()) { float pt[3], n[3], t; unsigned int nWP = 0; if (LTGetWorldCollide()->RaySegment(pFrom3, pTo3, pt, n, &t, &nWP)) { const float fDist = t * fLen; if (fDist < b.m_fBest) { b.m_fBest = fDist; for (int k=0;k<3;++k) b.m_N[k]=n[k]; b.m_h = 0; b.m_bHit = true; b.m_nPoly = nWP; } } } // --- every live object's box ------------------------------------------ // // LT_RAYOBJOLD=1 / LT_RAYGRIDDIFF=1 -- see RayObjects. static const bool s_bObjOld = []() { const bool b = (getenv("LT_RAYOBJOLD") != 0); if (b) { printf("[PHYS] LT_RAYOBJOLD=1 -- rays ask the game's filter before an object's box (old)\n"); fflush(stdout); } return b; }(); static const bool s_bObjDiff = []() { const bool b = (getenv("LT_RAYGRIDDIFF") != 0); if (b) { printf("[PHYS] LT_RAYGRIDDIFF=1 -- the ray's object loop also run the other way\n"); fflush(stdout); atexit(ObjDiffCensus); } return b; }(); if (bObjects) { const RayBest bWorld = b; unsigned long long nCalls = 0; RayObjects(s_bObjOld, pFrom3, pTo3, d, fLen, pFilter, pUser, bIgnoreNonSolid, s_bObjDiff ? (s_bObjOld ? &g_nFilterOld : &g_nFilterNew) : &nCalls, b); if (s_bObjDiff) { RayBest b2 = bWorld; RayObjects(!s_bObjOld, pFrom3, pTo3, d, fLen, pFilter, pUser, bIgnoreNonSolid, s_bObjOld ? &g_nFilterNew : &g_nFilterOld, b2); ++g_nObjAsked; if (b.m_h) ++g_nObjHits; if (b.m_bHit != b2.m_bHit || b.m_h != b2.m_h || b.m_nPoly != b2.m_nPoly || memcmp(&b.m_fBest, &b2.m_fBest, sizeof(float)) != 0 || memcmp(b.m_N, b2.m_N, sizeof(b.m_N)) != 0) { if (++g_nObjDiff <= 20) { printf("[OBJRAY] #%llu ray from (%.1f %.1f %.1f) to (%.1f %.1f %.1f): %s %s '%s' at %.4f, %s %s '%s' at %.4f\n", g_nObjDiff, pFrom3[0], pFrom3[1], pFrom3[2], pTo3[0], pTo3[1], pTo3[2], s_bObjOld ? "old" : "box-first", b.m_bHit ? "HIT" : "miss", b.m_h ? CLTServerObjects::FromHandle(b.m_h)->m_sName.c_str() : "world", b.m_fBest, s_bObjOld ? "box-first" : "old", b2.m_bHit ? "HIT" : "miss", b2.m_h ? CLTServerObjects::FromHandle(b2.m_h)->m_sName.c_str() : "world", b2.m_fBest); fflush(stdout); } } } } if (!b.m_bHit) return false; if (pPoint3) for (int k = 0; k < 3; ++k) pPoint3[k] = pFrom3[k] + d[k]*b.m_fBest; if (pNormal3) for (int k = 0; k < 3; ++k) pNormal3[k] = b.m_N[k]; if (ppHitObj) *ppHitObj = b.m_h; if (pPolyId) *pPolyId = b.m_nPoly; return true; } bool LTServerPhys_RayTestFiltered(const float* pFrom3, const float* pTo3, bool (*pFilter)(void*, void*), void* pUser, bool (*pPolyFilter)(unsigned int, void*), float* pPoint3, float* pNormal3, void** ppHitObj, bool bObjects, bool bIgnoreNonSolid, unsigned int* pPolyId) { static const bool s_bOff = []() { const bool b = (getenv("LT_NOPOLYFILTER") != 0); if (b) { printf("[PHYS] LT_NOPOLYFILTER=1 -- the game's polygon filter is ignored\n"); fflush(stdout); } return b; }(); if (!pPolyFilter || s_bOff) return LTServerPhys_RayTest(pFrom3, pTo3, pFilter, pUser, pPoint3, pNormal3, ppHitObj, bObjects, bIgnoreNonSolid, pPolyId); if (ppHitObj) *ppHitObj = 0; if (pPolyId) *pPolyId = 0; if (!pFrom3 || !pTo3) return false; float d[3] = { pTo3[0]-pFrom3[0], pTo3[1]-pFrom3[1], pTo3[2]-pFrom3[2] }; const float fLen = sqrtf(d[0]*d[0] + d[1]*d[1] + d[2]*d[2]); if (fLen <= 0.0f) return false; for (int k = 0; k < 3; ++k) d[k] /= fLen; // Re-cast from just past each rejected polygon. 0.25 units clears the // surface without stepping over anything a level could build. float from[3] = { pFrom3[0], pFrom3[1], pFrom3[2] }; for (int nStep = 0; nStep < 16; ++nStep) { float pt[3], nrm[3]; void* hHit = 0; unsigned int nPoly = 0; if (!LTServerPhys_RayTest(from, pTo3, pFilter, pUser, pt, nrm, &hHit, bObjects, bIgnoreNonSolid, &nPoly)) return false; if (nPoly == 0 || pPolyFilter(nPoly, pUser)) { if (pPoint3) for (int k = 0; k < 3; ++k) pPoint3[k] = pt[k]; if (pNormal3) for (int k = 0; k < 3; ++k) pNormal3[k] = nrm[k]; if (ppHitObj) *ppHitObj = hHit; if (pPolyId) *pPolyId = nPoly; return true; } float fDone = 0.0f; for (int k = 0; k < 3; ++k) fDone += (pt[k] - pFrom3[k]) * d[k]; if (fDone + 0.25f >= fLen) return false; for (int k = 0; k < 3; ++k) from[k] = pt[k] + d[k] * 0.25f; } return false; } void LTServerPhys_SetGlobalForce(const float* pF3) { if (!pF3) return; DefaultForce(); for (int k = 0; k < 3; ++k) g_Force[k] = pF3[k]; } void LTServerPhys_GetGlobalForce(float* pF3) { if (!pF3) return; DefaultForce(); for (int k = 0; k < 3; ++k) pF3[k] = g_Force[k]; } void LTServerPhys_SetStairHeight(float f) { g_fStairHeight = (f >= 0.0f) ? f : 0.0f; } float LTServerPhys_GetStairHeight() { return g_fStairHeight; } bool LTServerPhys_GetGround(void* hObj) { SRec* p = CLTServerObjects::FromHandle(hObj); return p ? p->m_bOnGround : false; } void LTServerPhys_DumpCensus() { // ⚠️ PRINTS EVEN WHEN EVERY COUNTER IS ZERO, once collision exists. "The // physics ran and moved nothing" is a RESULT -- it is how this module's // first run was found to be doing nothing at all -- and a census that goes // quiet in exactly that case is the one that hides it. if (!LTWorldCollide_Ready() && !g_nIntegrated) return; printf("\n[PHYS] server movement\n"); printf(" collision %u triangle(s); %u integrated step(s)\n", LTGetWorldCollide()->Triangles(), g_nIntegrated); printf(" moves: %u went somewhere, %u blocked, %u rescued by the stair lift\n", g_nMoved, g_nBlocked, g_nStepped); printf(" %u object(s) carry FLAG_GRAVITY, %u have a velocity\n", g_nGravity, g_nWithVel); printf(" flags: %u object-tick(s) carried any flag; union 0x%08x\n", g_nWithFlags, g_FlagsSeen); printf(" CalcMotion branches (5fg): stop %u, fall %u, steep %u, jump %u, downhill %u, walk %u, no gravity %u; %u with friction\n", g_nBranch[LTPHYS_STOP], g_nBranch[LTPHYS_FALL], g_nBranch[LTPHYS_STEEP], g_nBranch[LTPHYS_JUMP], g_nBranch[LTPHYS_DOWNHILL], g_nBranch[LTPHYS_WALK], g_nBranch[LTPHYS_FREE], g_nFriction); printf(" %u step(s) on the probe's floor still falling into it (taken as falling); %u step(s) of FLAG_GOTHRUWORLD objects\n", g_nArriving, g_nGoThru); printf(" %u object-step(s) handed to their volumes (MID_AFFECTPHYSICS, 5fj)\n", g_nInVolumes); if (!g_nIntegrated) printf(" ⚠️ NOTHING INTEGRATED. Either no object has velocity or\n" " gravity, or the integrator is not being called.\n"); if (!LTGetWorldCollide()->Triangles()) printf(" ⚠️ NO COLLISION BUILT -- every move was a teleport.\n"); fflush(stdout); }