feat(physics): live-entity collision plumbing (Commit A)
Plumbing-only foundation for the upcoming live-entity (NPC / monster / player) collision port. No behavior change — the new fields default to zero/None so the 5 existing static-entity Register call sites in GameWindow.cs are untouched. Wire layer: - CreateObject parser now surfaces PhysicsState (acclient.h:2815 — ETHEREAL_PS=0x4, IGNORE_COLLISIONS_PS=0x10, HAS_PHYSICS_BSP_PS=0x10000, ...) which the parser previously dropped at line ~337 with a bare `pos += 4`. - CreateObject parser now surfaces ObjectDescriptionFlags (the retail PWD._bitfield trailer per acclient.h:6431-6463), where acclient_2013_pseudo_c.txt:406898-406918 ACCWeenieObject::IsPK / IsPKLite / IsImpenetrable read bits 5 / 25 / 21 directly. Previously read-and-discarded. - WorldSession.EntitySpawn carries both new fields through to subscribers. Physics layer: - New `EntityCollisionFlags` enum (IsPlayer / IsCreature / IsPK / IsPKLite / IsImpenetrable) + `FromPwdBitfield` helper. Bit positions verified against retail's SetPlayerKillerStatus ( acclient_2013_pseudo_c.txt:441868-441890) which maps PKStatusEnum→bitfield exactly: PK=0x4→bit5, PKLite=0x40→bit25, Free=0x20→bit21. - `ShadowEntry` extended with `State` (raw PhysicsState bits) + `Flags` (decoded EntityCollisionFlags). Backward-compatible — all five existing landblock-entity Register call sites omit them. - `ShadowObjectRegistry.UpdatePosition(entityId, pos, rot, ...)` — fast-path for the 5–10 Hz UpdatePosition (0xF748) stream the server emits per visible entity. Reuses the entry's existing shape + state + flags. Mirrors retail's CPhysicsObj::SetPosition (acclient_2013_pseudo_c.txt:284276) which keeps the same shape and re-registers cell membership. - `ObjectInfoState` adds `IsPK = 0x800` and `IsPKLite = 0x1000` matching retail's OBJECTINFO::state bits (acclient.h:6190-6194). Used by Commit C's PvP exemption gate. Tests: - `EntityCollisionFlagsTests` — 7 tests covering empty / each bit alone / PK+player combo / unrelated-bit ignore. - `ShadowObjectRegistryTests` — 5 new tests: UpdatePosition moves entry to new cell, preserves State/Flags, unregistered no-op, Register stores State/Flags, defaults are zero/None. - `CreateObjectTests` — 3 new tests verifying PhysicsState + PWD bitfield (with PK / PKLite bit cases) parse and surface. 1454 → 1454 + 15 = covered by suite. dotnet build + dotnet test green. Foundation for Commit B (live-entity registration) and Commit C (PvP exemption block in FindObjCollisions). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
90aa74a3cb
commit
ffefc6977f
8 changed files with 432 additions and 14 deletions
|
|
@ -84,6 +84,24 @@ public static class CreateObject
|
|||
/// SetupTableId are nullable because their corresponding
|
||||
/// physics-description-flag bits may not be set on every CreateObject.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// <para>
|
||||
/// <see cref="PhysicsState"/> (<c>acclient.h:2815</c>) carries flag
|
||||
/// bits like <c>ETHEREAL_PS=0x4</c>, <c>IGNORE_COLLISIONS_PS=0x10</c>,
|
||||
/// <c>HAS_PHYSICS_BSP_PS=0x10000</c> — the bits retail's
|
||||
/// <c>FindObjCollisions</c> reads to short-circuit ethereal /
|
||||
/// no-collision entities. Pre-2026-04-29 (Commit A of the live-entity
|
||||
/// collision port) the parser silently dropped this field.
|
||||
/// </para>
|
||||
/// <para>
|
||||
/// <see cref="ObjectDescriptionFlags"/> is the <c>PWD._bitfield</c>
|
||||
/// trailer (<c>acclient.h:6431-6463</c>) — bits include <c>BF_PLAYER (0x8)</c>,
|
||||
/// <c>BF_PLAYER_KILLER (0x20)</c>, <c>BF_FREE_PKSTATUS (0x200000)</c>,
|
||||
/// <c>BF_PKLITE_PKSTATUS (0x2000000)</c>. Decoded into
|
||||
/// <c>EntityCollisionFlags</c> at registration time for the PvP
|
||||
/// exemption gate.
|
||||
/// </para>
|
||||
/// </remarks>
|
||||
public readonly record struct Parsed(
|
||||
uint Guid,
|
||||
ServerPosition? Position,
|
||||
|
|
@ -100,7 +118,9 @@ public static class CreateObject
|
|||
ushort InstanceSequence = 0,
|
||||
ushort TeleportSequence = 0,
|
||||
ushort ServerControlSequence = 0,
|
||||
ushort ForcePositionSequence = 0);
|
||||
ushort ForcePositionSequence = 0,
|
||||
uint? PhysicsState = null,
|
||||
uint? ObjectDescriptionFlags = null);
|
||||
|
||||
/// <summary>
|
||||
/// The relevant subset of the server-sent <c>MovementData</c> /
|
||||
|
|
@ -260,6 +280,12 @@ public static class CreateObject
|
|||
float? objScale = null;
|
||||
ServerMotionState? motionState = null;
|
||||
uint? motionTableId = null;
|
||||
// Commit A 2026-04-29 — live-entity collision plumbing. PhysicsState
|
||||
// (acclient.h:2815) was previously skipped at line ~337; the PWD
|
||||
// _bitfield (acclient.h:6431-6463) was previously discarded as
|
||||
// "ObjectDescriptionFlags" at the WeenieHeader trailer.
|
||||
uint? physicsState = null;
|
||||
uint? objectDescriptionFlags = null;
|
||||
|
||||
try
|
||||
{
|
||||
|
|
@ -334,7 +360,10 @@ public static class CreateObject
|
|||
if (body.Length - pos < 8) return null;
|
||||
var physicsFlags = (PhysicsDescriptionFlag)BinaryPrimitives.ReadUInt32LittleEndian(body.Slice(pos));
|
||||
pos += 4;
|
||||
pos += 4; // PhysicsState (skip)
|
||||
// PhysicsState (acclient.h:2815). Previously skipped, now
|
||||
// surfaced for live-entity collision (Commit A 2026-04-29).
|
||||
physicsState = BinaryPrimitives.ReadUInt32LittleEndian(body.Slice(pos));
|
||||
pos += 4;
|
||||
|
||||
if ((physicsFlags & PhysicsDescriptionFlag.Movement) != 0)
|
||||
{
|
||||
|
|
@ -463,7 +492,16 @@ public static class CreateObject
|
|||
if (body.Length - pos >= 4)
|
||||
itemType = ReadU32(body, ref pos);
|
||||
if (body.Length - pos >= 4)
|
||||
_ = ReadU32(body, ref pos); // ObjectDescriptionFlags
|
||||
{
|
||||
// ObjectDescriptionFlags = retail PWD._bitfield
|
||||
// (acclient.h:6431-6463). Carries BF_PLAYER (0x8),
|
||||
// BF_PLAYER_KILLER (0x20), BF_FREE_PKSTATUS (0x200000),
|
||||
// BF_PKLITE_PKSTATUS (0x2000000) — the bits that
|
||||
// acclient_2013_pseudo_c.txt:406898-406918 read for
|
||||
// IsPK() / IsPKLite() / IsImpenetrable(). Previously
|
||||
// discarded; now surfaced for the PvP collision rule.
|
||||
objectDescriptionFlags = ReadU32(body, ref pos);
|
||||
}
|
||||
AlignTo4(ref pos);
|
||||
}
|
||||
catch { /* truncated name — partial result is still useful */ }
|
||||
|
|
@ -471,13 +509,15 @@ public static class CreateObject
|
|||
|
||||
return new Parsed(guid, position, setupTableId, animParts,
|
||||
textureChanges, subPalettes, basePaletteId, objScale, name, itemType, motionState, motionTableId,
|
||||
instanceSeq, teleportSeq, serverControlSeq, forcePositionSeq);
|
||||
instanceSeq, teleportSeq, serverControlSeq, forcePositionSeq,
|
||||
physicsState, objectDescriptionFlags);
|
||||
|
||||
// Local helper: if we ran out of fields past PhysicsData, still
|
||||
// return the useful prefix (guid/position/setup/animParts/textures/palettes/scale/motion).
|
||||
Parsed PartialResult() => new(
|
||||
guid, position, setupTableId, animParts,
|
||||
textureChanges, subPalettes, basePaletteId, objScale, null, null, motionState, motionTableId);
|
||||
textureChanges, subPalettes, basePaletteId, objScale, null, null, motionState, motionTableId,
|
||||
PhysicsState: physicsState, ObjectDescriptionFlags: objectDescriptionFlags);
|
||||
}
|
||||
catch
|
||||
{
|
||||
|
|
|
|||
|
|
@ -56,7 +56,14 @@ public sealed class WorldSession : IDisposable
|
|||
string? Name,
|
||||
uint? ItemType,
|
||||
CreateObject.ServerMotionState? MotionState,
|
||||
uint? MotionTableId);
|
||||
uint? MotionTableId,
|
||||
// Commit A 2026-04-29 — live-entity collision plumbing.
|
||||
// PhysicsState: retail acclient.h:2815 (ETHEREAL_PS=0x4,
|
||||
// IGNORE_COLLISIONS_PS=0x10, HAS_PHYSICS_BSP_PS=0x10000, ...).
|
||||
// ObjectDescriptionFlags: retail PWD._bitfield (acclient.h:6431-6463)
|
||||
// — drives IsPlayer/IsPK/IsPKLite/IsImpenetrable for PvP gating.
|
||||
uint? PhysicsState = null,
|
||||
uint? ObjectDescriptionFlags = null);
|
||||
|
||||
/// <summary>Fires when the session finishes parsing a CreateObject.</summary>
|
||||
public event Action<EntitySpawn>? EntitySpawned;
|
||||
|
|
@ -648,7 +655,9 @@ public sealed class WorldSession : IDisposable
|
|||
parsed.Value.Name,
|
||||
parsed.Value.ItemType,
|
||||
parsed.Value.MotionState,
|
||||
parsed.Value.MotionTableId));
|
||||
parsed.Value.MotionTableId,
|
||||
parsed.Value.PhysicsState,
|
||||
parsed.Value.ObjectDescriptionFlags));
|
||||
}
|
||||
}
|
||||
else if (op == DeleteObject.Opcode)
|
||||
|
|
|
|||
67
src/AcDream.Core/Physics/EntityCollisionFlags.cs
Normal file
67
src/AcDream.Core/Physics/EntityCollisionFlags.cs
Normal file
|
|
@ -0,0 +1,67 @@
|
|||
namespace AcDream.Core.Physics;
|
||||
|
||||
/// <summary>
|
||||
/// Per-entity flags driving the retail-faithful PvP / Player /
|
||||
/// Impenetrable exemption logic in <c>FindObjCollisions</c>. Decoded
|
||||
/// from <c>PublicWeenieDesc._bitfield</c> at <c>CreateObject</c> time.
|
||||
///
|
||||
/// <para>
|
||||
/// Bit positions (verified against
|
||||
/// <c>docs/research/named-retail/acclient_2013_pseudo_c.txt:406898-406918</c>
|
||||
/// where <c>ACCWeenieObject::IsPK/IsPKLite/IsImpenetrable</c> read directly
|
||||
/// from <c>this->pwd._bitfield</c>):
|
||||
/// </para>
|
||||
/// <list type="bullet">
|
||||
/// <item><c>BF_PLAYER = 0x8</c> (bit 3) → <see cref="IsPlayer"/></item>
|
||||
/// <item><c>BF_PLAYER_KILLER = 0x20</c> (bit 5) → <see cref="IsPK"/></item>
|
||||
/// <item><c>BF_FREE_PKSTATUS = 0x200000</c> (bit 21) → <see cref="IsImpenetrable"/></item>
|
||||
/// <item><c>BF_PKLITE_PKSTATUS = 0x2000000</c> (bit 25) → <see cref="IsPKLite"/></item>
|
||||
/// </list>
|
||||
///
|
||||
/// <para>
|
||||
/// <see cref="IsCreature"/> is NOT a PWD bit — retail derives it from
|
||||
/// <c>PublicWeenieDesc._type</c> matching <c>ITEM_TYPE_CREATURE</c>
|
||||
/// (acclient.h ITEM_TYPE enum). Set at registration time by callers that
|
||||
/// already know the item type.
|
||||
/// </para>
|
||||
/// </summary>
|
||||
[Flags]
|
||||
public enum EntityCollisionFlags : byte
|
||||
{
|
||||
None = 0x00,
|
||||
/// <summary>Set when <c>BF_PLAYER (0x8)</c> is set in <c>pwd._bitfield</c>.</summary>
|
||||
IsPlayer = 0x01,
|
||||
/// <summary>Derived from <c>ItemType.Creature</c> on the spawn payload.</summary>
|
||||
IsCreature = 0x02,
|
||||
/// <summary>Set when <c>BF_PLAYER_KILLER (0x20)</c> is set.</summary>
|
||||
IsPK = 0x04,
|
||||
/// <summary>Set when <c>BF_PKLITE_PKSTATUS (0x2000000)</c> is set.</summary>
|
||||
IsPKLite = 0x08,
|
||||
/// <summary>Set when <c>BF_FREE_PKSTATUS (0x200000)</c> is set (a.k.a. "Free" PK status — cannot be PKed).</summary>
|
||||
IsImpenetrable = 0x10,
|
||||
}
|
||||
|
||||
/// <summary>Helpers to convert raw retail bitfields into <see cref="EntityCollisionFlags"/>.</summary>
|
||||
public static class EntityCollisionFlagsExt
|
||||
{
|
||||
/// <summary>
|
||||
/// Decode the player/PK/PKLite/Impenetrable bits from a
|
||||
/// <c>PublicWeenieDesc._bitfield</c> value (the WeenieHeader trailer
|
||||
/// field acdream's parser surfaces as <c>ObjectDescriptionFlags</c>).
|
||||
///
|
||||
/// <para>Bit positions per
|
||||
/// <c>docs/research/named-retail/acclient.h:6431-6463</c>
|
||||
/// (<c>PublicWeenieDesc::BitfieldIndex</c>) and
|
||||
/// <c>acclient_2013_pseudo_c.txt:441868-441890</c>
|
||||
/// (<c>PublicWeenieDesc::SetPlayerKillerStatus</c>).</para>
|
||||
/// </summary>
|
||||
public static EntityCollisionFlags FromPwdBitfield(uint bitfield)
|
||||
{
|
||||
var flags = EntityCollisionFlags.None;
|
||||
if ((bitfield & 0x8u) != 0) flags |= EntityCollisionFlags.IsPlayer;
|
||||
if ((bitfield & 0x20u) != 0) flags |= EntityCollisionFlags.IsPK;
|
||||
if ((bitfield & 0x200000u) != 0) flags |= EntityCollisionFlags.IsImpenetrable;
|
||||
if ((bitfield & 0x2000000u) != 0) flags |= EntityCollisionFlags.IsPKLite;
|
||||
return flags;
|
||||
}
|
||||
}
|
||||
|
|
@ -19,11 +19,24 @@ public sealed class ShadowObjectRegistry
|
|||
|
||||
/// <summary>
|
||||
/// Register an entity into the cells it overlaps based on world position + radius.
|
||||
///
|
||||
/// <para>
|
||||
/// The optional <paramref name="state"/> + <paramref name="flags"/>
|
||||
/// parameters carry retail <c>PhysicsState</c> bits and decoded
|
||||
/// <see cref="EntityCollisionFlags"/> respectively, so the
|
||||
/// <c>FindObjCollisions</c> retail-faithful exemption block (PvP rule,
|
||||
/// ETHEREAL skip, viewer-vs-creature) can short-circuit without an
|
||||
/// extra lookup. Default <c>state=0</c> + <c>flags=None</c> preserves
|
||||
/// the original "static decoration" behavior — the existing 5
|
||||
/// landblock-entity registration sites pass nothing.
|
||||
/// </para>
|
||||
/// </summary>
|
||||
public void Register(uint entityId, uint gfxObjId, Vector3 worldPos, Quaternion rotation,
|
||||
float radius, float worldOffsetX, float worldOffsetY, uint landblockId,
|
||||
ShadowCollisionType collisionType = ShadowCollisionType.BSP,
|
||||
float cylHeight = 0f, float scale = 1.0f)
|
||||
float cylHeight = 0f, float scale = 1.0f,
|
||||
uint state = 0u,
|
||||
EntityCollisionFlags flags = EntityCollisionFlags.None)
|
||||
{
|
||||
Deregister(entityId);
|
||||
|
||||
|
|
@ -38,7 +51,8 @@ public sealed class ShadowObjectRegistry
|
|||
int minCy = Math.Max(0, (int)((localY - radius) / 24f));
|
||||
int maxCy = Math.Min(7, (int)((localY + radius) / 24f));
|
||||
|
||||
var entry = new ShadowEntry(entityId, gfxObjId, worldPos, rotation, radius, collisionType, cylHeight, scale);
|
||||
var entry = new ShadowEntry(entityId, gfxObjId, worldPos, rotation, radius,
|
||||
collisionType, cylHeight, scale, state, flags);
|
||||
var cellIds = new List<uint>();
|
||||
|
||||
uint lbPrefix = landblockId & 0xFFFF0000u;
|
||||
|
|
@ -62,6 +76,56 @@ public sealed class ShadowObjectRegistry
|
|||
_entityToCells[entityId] = cellIds;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Update an already-registered entity's world position + rotation,
|
||||
/// preserving its <see cref="ShadowEntry.State"/>,
|
||||
/// <see cref="ShadowEntry.Flags"/>, and shape parameters.
|
||||
///
|
||||
/// <para>
|
||||
/// Cheaper than <see cref="Deregister"/> + <see cref="Register"/> for
|
||||
/// the 5–10 Hz <c>UpdatePosition (0xF748)</c> stream the server emits
|
||||
/// per visible entity: this is the path retail's
|
||||
/// <c>CPhysicsObj::SetPosition</c> takes (cited at
|
||||
/// <c>acclient_2013_pseudo_c.txt:284276</c>) — same shape, new cell
|
||||
/// membership. If the entity isn't already registered, this is a
|
||||
/// no-op so callers don't have to gate.
|
||||
/// </para>
|
||||
/// </summary>
|
||||
public void UpdatePosition(uint entityId, Vector3 worldPos, Quaternion rotation,
|
||||
float worldOffsetX, float worldOffsetY, uint landblockId)
|
||||
{
|
||||
// Find the existing entry (any cell holds a copy with the same
|
||||
// entity-scoped state + flags + shape).
|
||||
if (!_entityToCells.TryGetValue(entityId, out var oldCells) || oldCells.Count == 0)
|
||||
return;
|
||||
|
||||
ShadowEntry? template = null;
|
||||
foreach (var oldCellId in oldCells)
|
||||
{
|
||||
if (_cells.TryGetValue(oldCellId, out var list))
|
||||
{
|
||||
foreach (var e in list)
|
||||
{
|
||||
if (e.EntityId == entityId)
|
||||
{
|
||||
template = e;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (template is not null) break;
|
||||
}
|
||||
if (template is null)
|
||||
return;
|
||||
|
||||
// Preserve everything except position + rotation.
|
||||
var t = template.Value;
|
||||
Register(entityId, t.GfxObjId, worldPos, rotation, t.Radius,
|
||||
worldOffsetX, worldOffsetY, landblockId,
|
||||
t.CollisionType, t.CylHeight, t.Scale,
|
||||
t.State, t.Flags);
|
||||
}
|
||||
|
||||
/// <summary>Remove an entity from all cells it was registered in.</summary>
|
||||
public void Deregister(uint entityId)
|
||||
{
|
||||
|
|
@ -203,4 +267,18 @@ public readonly record struct ShadowEntry(
|
|||
float Radius,
|
||||
ShadowCollisionType CollisionType = ShadowCollisionType.BSP,
|
||||
float CylHeight = 0f,
|
||||
float Scale = 1.0f);
|
||||
float Scale = 1.0f,
|
||||
/// <summary>
|
||||
/// Retail <c>PhysicsState</c> bits (<c>acclient.h:2815</c>). Used
|
||||
/// by <c>FindObjCollisions</c> to honor <c>ETHEREAL_PS=0x4</c> +
|
||||
/// <c>IGNORE_COLLISIONS_PS=0x10</c> short-circuits. Zero for static
|
||||
/// landblock entities (default behavior matches pre-Commit-A).
|
||||
/// </summary>
|
||||
uint State = 0u,
|
||||
/// <summary>
|
||||
/// Decoded player / PK / PKLite / Impenetrable flags driving the
|
||||
/// retail PvP exemption block in <c>FindObjCollisions</c>. Built
|
||||
/// from <c>PWD._bitfield</c> at <c>CreateObject</c> time via
|
||||
/// <see cref="EntityCollisionFlagsExt.FromPwdBitfield(uint)"/>.
|
||||
/// </summary>
|
||||
EntityCollisionFlags Flags = EntityCollisionFlags.None);
|
||||
|
|
|
|||
|
|
@ -34,6 +34,13 @@ public enum ObjectInfoState : uint
|
|||
IsPlayer = 0x100,
|
||||
EdgeSlide = 0x200,
|
||||
IgnoreCreatures = 0x400,
|
||||
/// <summary>Bits added 2026-04-29 (Commit A live-entity collision):
|
||||
/// the moving object's PK status drives the player-vs-player
|
||||
/// exemption block in <c>FindObjCollisions</c> per
|
||||
/// <c>acclient_2013_pseudo_c.txt:276807-276839</c>. Values match
|
||||
/// retail's <c>OBJECTINFO::state</c> bits (acclient.h:6190-6194).</summary>
|
||||
IsPK = 0x800,
|
||||
IsPKLite = 0x1000,
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue