| 22 | import java.util.* |
| 23 | import java.util.function.BiConsumer |
| 24 | import java.util.function.Consumer |
| 25 | |
| 26 | class 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 | } |
nothing calls this directly
no test coverage detected