MCPcopy Index your code
hub / github.com/OpenEndedGroup/Field2 / PhysicsSystem

Class PhysicsSystem

src/main/java/trace/physics/PhysicsSystem.kt:24–444  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

22import java.util.*
23import java.util.function.BiConsumer
24import java.util.function.Consumer
25
26class PhysicsSystem {
27
28 val physics: Dict.Prop<FLineToPhysics> = Dict.Prop<Any>("physics")
29 .toCanon<Any>().set(Dict.domain, "fline")
30
31 val onContactStart: Dict.Prop<IdempotencyMap<BiConsumer<FLine, List<field.linalg.Vec2>?>>> = Dict.Prop<Any>("onContactStart")
32 .toCanon<Any>().autoConstructs { IdempotencyMap<BiConsumer<FLine, List<field.linalg.Vec2>?>>(BiConsumer::class.java) }.set(Dict.domain, "fline")
33
34 val onContactEnd: Dict.Prop<IdempotencyMap<Consumer<FLine>>> = Dict.Prop<Any>("onContactEnd")
35 .toCanon<Any>().autoConstructs { IdempotencyMap<Consumer<FLine>>(Consumer::class.java) }.set(Dict.domain, "fline")
36
37
38 val world = World(Vec2(0f, 0f))
39
40 val allPhysicsLines = mutableSetOf<FLineToPhysics>();
41
42 var TICK = 0L;
43
44 class Contact(val tick: Long, val A: FLine, val B: FLine) {
45 var terminated = -1L
46
47 override fun equals(other: Any?): Boolean {
48 if (this === other) return true
49 if (other !is Contact) return false
50
51 if (A != other.A) return false
52 if (B != other.B) return false
53
54 return true
55 }
56
57 override fun hashCode(): Int {
58 var result = A.hashCode()
59 result = 31 * result + B.hashCode()
60 return result
61 }
62
63 var points: List<field.linalg.Vec2>? = null
64 }
65
66 val contacts = mutableSetOf<Contact>();
67
68 init {
69 world.setContactListener(object : ContactListener {
70 override fun beginContact(contact: org.jbox2d.dynamics.contacts.Contact) {
71 val A = fixturesToFLines[contact.fixtureA]
72 val B = fixturesToFLines[contact.fixtureB]
73 if (A != null && B != null) {
74 val c = Contact(tick = TICK, A = A, B = B)
75 val wm = WorldManifold()
76 contact.getWorldManifold(wm)
77 c.points = wm.points.map { convert2(it) }
78
79 contacts.remove(c)
80 contacts.add(c)
81 }

Callers

nothing calls this directly

Calls 6

IdempotencyMapClass · 0.85
toCanonMethod · 0.80
PropMethod · 0.80
autoConstructsMethod · 0.80
setMethod · 0.65
Vec2Class · 0.50

Tested by

no test coverage detected