Skip to content

Commit 68588cc

Browse files
committed
fix(physics2d): entity collision type to cardinal id
1 parent 6b6ad70 commit 68588cc

3 files changed

Lines changed: 15 additions & 28 deletions

File tree

pkg/plugin/physics2d/component/active_contacts.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package component
22

3+
import "github.com/argus-labs/world-engine/pkg/cardinal"
4+
35
// PhysicsSingletonTag marks the single entity that holds physics plugin state (ActiveContacts).
46
type PhysicsSingletonTag struct{}
57

@@ -8,11 +10,11 @@ func (PhysicsSingletonTag) Name() string { return "physics_singleton_tag" }
810
// ContactPairEntry is one active contact pair tracked by the physics engine. Entries are
911
// normalized: EntityA < EntityB (or if equal, ShapeIndexA <= ShapeIndexB).
1012
type ContactPairEntry struct {
11-
EntityA uint64 `json:"a"`
12-
ShapeIndexA int `json:"sa"`
13-
EntityB uint64 `json:"b"`
14-
ShapeIndexB int `json:"sb"`
15-
IsSensor bool `json:"sensor"`
13+
EntityA cardinal.EntityID `json:"a"`
14+
ShapeIndexA int `json:"sa"`
15+
EntityB cardinal.EntityID `json:"b"`
16+
ShapeIndexB int `json:"sb"`
17+
IsSensor bool `json:"sensor"`
1618
// Fixture filters for normalized EntityA/B (recovery End / trigger vs contact routing).
1719
// Omitempty keeps older snapshots valid.
1820
FilterACategoryBits uint64 `json:"fa_cat,omitempty"`

pkg/plugin/physics2d/internal/contact_flush.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -258,8 +258,8 @@ func lessBufferedContactEvent(a, b BufferedContactEvent) bool {
258258
return a.Kind < b.Kind
259259
}
260260
return lessContactPairByEndpoints(
261-
uint64(a.EntityA), a.ShapeIndexA, uint64(a.EntityB), a.ShapeIndexB,
262-
uint64(b.EntityA), b.ShapeIndexA, uint64(b.EntityB), b.ShapeIndexB,
261+
a.EntityA, a.ShapeIndexA, a.EntityB, a.ShapeIndexB,
262+
b.EntityA, b.ShapeIndexA, b.EntityB, b.ShapeIndexB,
263263
)
264264
}
265265

pkg/plugin/physics2d/internal/runtime.go

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package internal
22

33
import (
4-
"math"
54
"sort"
65

76
"github.com/argus-labs/world-engine/pkg/cardinal"
@@ -125,15 +124,10 @@ func (rt *PhysicsRuntime) PruneActiveContactsInvolvingEntity(entityID cardinal.E
125124
func (rt *PhysicsRuntime) LoadActiveContactsFromComponent(ac component.ActiveContacts) {
126125
rt.ActiveContacts = make(map[ContactPairKey]ContactPairInfo, len(ac.Pairs))
127126
for _, p := range ac.Pairs {
128-
entityA, okA := entityIDFromUint64(p.EntityA)
129-
entityB, okB := entityIDFromUint64(p.EntityB)
130-
if !okA || !okB {
131-
continue
132-
}
133127
key := ContactPairKey{
134-
EntityA: entityA,
128+
EntityA: p.EntityA,
135129
ShapeIndexA: p.ShapeIndexA,
136-
EntityB: entityB,
130+
EntityB: p.EntityB,
137131
ShapeIndexB: p.ShapeIndexB,
138132
}
139133
rt.ActiveContacts[key] = ContactPairInfo{
@@ -153,15 +147,6 @@ func (rt *PhysicsRuntime) LoadActiveContactsFromComponent(ac component.ActiveCon
153147
rt.ActiveContactsDirty = false
154148
}
155149

156-
// entityIDFromUint64 maps persisted wire format (uint64) to cardinal.EntityID (uint32).
157-
// Oversized values are rejected so corrupt snapshots cannot truncate silently.
158-
func entityIDFromUint64(u uint64) (cardinal.EntityID, bool) {
159-
if u > math.MaxUint32 {
160-
return 0, false
161-
}
162-
return cardinal.EntityID(uint32(u)), true
163-
}
164-
165150
// ActiveContactsToComponent converts the working map to the ECS component format (sorted
166151
// slice for deterministic snapshots).
167152
func (rt *PhysicsRuntime) ActiveContactsToComponent() component.ActiveContacts {
@@ -171,9 +156,9 @@ func (rt *PhysicsRuntime) ActiveContactsToComponent() component.ActiveContacts {
171156
pairs := make([]component.ContactPairEntry, 0, len(rt.ActiveContacts))
172157
for key, info := range rt.ActiveContacts {
173158
pairs = append(pairs, component.ContactPairEntry{
174-
EntityA: uint64(key.EntityA),
159+
EntityA: key.EntityA,
175160
ShapeIndexA: key.ShapeIndexA,
176-
EntityB: uint64(key.EntityB),
161+
EntityB: key.EntityB,
177162
ShapeIndexB: key.ShapeIndexB,
178163
IsSensor: info.IsSensor,
179164
FilterACategoryBits: info.FilterA.CategoryBits,
@@ -208,8 +193,8 @@ func lessContactPairEntry(a, b component.ContactPairEntry) bool {
208193

209194
// lessContactPairByEndpoints compares (entityA, shapeIndexA, entityB, shapeIndexB) lexicographically.
210195
func lessContactPairByEndpoints(
211-
aEA uint64, aSA int, aEB uint64, aSB int,
212-
bEA uint64, bSA int, bEB uint64, bSB int,
196+
aEA cardinal.EntityID, aSA int, aEB cardinal.EntityID, aSB int,
197+
bEA cardinal.EntityID, bSA int, bEB cardinal.EntityID, bSB int,
213198
) bool {
214199
if aEA != bEA {
215200
return aEA < bEA

0 commit comments

Comments
 (0)