Skip to content

Commit

Permalink
Use records typealias, remove ops/s comments
Browse files Browse the repository at this point in the history
  • Loading branch information
0ffz committed Sep 5, 2023
1 parent 28738fa commit 1cd4a99
Show file tree
Hide file tree
Showing 18 changed files with 27 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package com.mineinabyss.geary.prefabs.configuration.systems

import com.mineinabyss.geary.components.EntityName
import com.mineinabyss.geary.components.relations.NoInherit
import com.mineinabyss.geary.datatypes.Records
import com.mineinabyss.geary.datatypes.UnsafeAccessors
import com.mineinabyss.geary.helpers.addParent
import com.mineinabyss.geary.helpers.entity
Expand All @@ -17,7 +16,7 @@ class ParseChildOnPrefab : Listener() {
private var Pointers.child by get<ChildOnPrefab>().removable().whenSetOnTarget()

@OptIn(UnsafeAccessors::class)
override fun Records.handle() {
override fun Pointers.handle() {
entity {
addParent(target.entity)
setAll(child!!.components)
Expand All @@ -30,7 +29,7 @@ class ParseChildrenOnPrefab : Listener() {
private var Pointers.children by get<ChildrenOnPrefab>().removable().whenSetOnTarget()

@OptIn(UnsafeAccessors::class)
override fun Records.handle() {
override fun Pointers.handle() {
children!!.nameToComponents.forEach { (name, components) ->
entity {
set(EntityName(name))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package com.mineinabyss.geary.prefabs.configuration.systems

import com.mineinabyss.geary.datatypes.Records
import com.mineinabyss.geary.prefabs.configuration.components.RelationOnPrefab
import com.mineinabyss.geary.systems.Listener
import com.mineinabyss.geary.systems.accessors.Pointers


class ParseRelationOnPrefab : Listener() {
private var Records.relation by get<RelationOnPrefab>().removable().whenSetOnTarget()
private var Pointers.relation by get<RelationOnPrefab>().removable().whenSetOnTarget()

override fun Records.handle() {
override fun Pointers.handle() {
try {
val rel: RelationOnPrefab = relation!!
// entity.setRelation(relation.value, entity.parseEntity(relation.key).id)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@ package com.mineinabyss.geary.prefabs.configuration.systems
import com.mineinabyss.geary.datatypes.Records
import com.mineinabyss.geary.datatypes.UnsafeAccessors
import com.mineinabyss.geary.systems.Listener
import com.mineinabyss.geary.systems.accessors.Pointers
import com.mineinabyss.geary.systems.accessors.RelationWithData


class ParseRelationWithDataSystem : Listener() {
private val Records.relationWithData by get<RelationWithData<*, *>>().whenSetOnTarget()

@OptIn(UnsafeAccessors::class)
override fun Records.handle() {
override fun Pointers.handle() {
val entity = target.entity
val data = relationWithData.data
val targetData = relationWithData.targetData
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class InheritPrefabsOnLoad : Listener() {
private val Pointers.loaded by family { has<PrefabLoaded>() }.on(event)

@OptIn(UnsafeAccessors::class)
override fun Records.handle() {
override fun Pointers.handle() {
target.entity.inheritPrefabs()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@ import com.mineinabyss.geary.datatypes.UnsafeAccessors
import com.mineinabyss.geary.prefabs.PrefabKey
import com.mineinabyss.geary.prefabs.prefabs
import com.mineinabyss.geary.systems.Listener
import com.mineinabyss.geary.systems.accessors.Pointers


class TrackPrefabsByKeySystem : Listener() {
private val Records.key by get<PrefabKey>().whenSetOnTarget()

@OptIn(UnsafeAccessors::class)
override fun Records.handle() {
override fun Pointers.handle() {
prefabs.manager.registerPrefab(key, target.entity)
target.entity.addRelation<NoInherit, PrefabKey>()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class TrackUuidOnAdd : GearyListener() {
val Pointers.regenerateUUIDOnClash by get<RegenerateUUIDOnClash>().orNull().on(target)

@OptIn(UnsafeAccessors::class)
override fun Records.handle() {
override fun Pointers.handle() {
if (uuid in uuid2Geary)
if (regenerateUUIDOnClash != null) {
val newUuid = uuid4()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class UnTrackUuidOnRemove : GearyListener() {
private val Pointers.uuid by get<Uuid>().on(target)
private val Pointers.removed by family { has<EntityRemoved>() }.on(event)

override fun Records.handle() {
override fun Pointers.handle() {
uuid2Geary.remove(uuid)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ class VelocitySystemBenchmark {
}
}

// 0.606 ops/s
@Benchmark
fun velocitySystem() {
VelocitySystem.tickAll()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,22 +30,19 @@ class MemoryAccessBenchmarks {
accessorWithScope = AccessorWithScope(intArr)
}

// >2bil ops/s
// @Benchmark
@Benchmark
fun emptyLoop() {
for (i in 0 until oneMil) {
}
}

// 1.8bil ops/s
@Benchmark
fun readIntArrDirectly() {
for (i in 0 until oneMil) {
intArr[i] + 1
}
}

// 1.7bil ops/s
@Benchmark
fun readObjArrDirectly() {
for (i in 0 until oneMil) {
Expand All @@ -60,7 +57,6 @@ class MemoryAccessBenchmarks {
}
}

// 1.3bil ops/s
@Benchmark
fun read2ArrDirectly() {
for (i in 0 until oneMil) {
Expand All @@ -83,8 +79,6 @@ class MemoryAccessBenchmarks {
}
}


// 23470 ops/s
@Benchmark
fun readWriteSingleIntArrDirectly() {
for (i in 0 until oneMil) {
Expand All @@ -93,7 +87,6 @@ class MemoryAccessBenchmarks {
}


// 15503 ops/s
@Benchmark
fun readWriteTwoArrDirectly() {
for (i in 0 until oneMil) {
Expand All @@ -116,7 +109,6 @@ class MemoryAccessBenchmarks {
}
}

// 1907 ops/s
@Benchmark
fun readPackToSeparateArr() {
val arr = IntArray(oneMil)
Expand All @@ -125,8 +117,6 @@ class MemoryAccessBenchmarks {
}
}

// 1.5bil ops/s
// Even with a full object instantiation, we don't lose much!
@Benchmark
fun readIntArrWithIndirection() {
for (i in 0 until oneMil) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package com.mineinabyss.geary.benchmarks.unpacking

import com.mineinabyss.geary.benchmarks.helpers.Comp1
import com.mineinabyss.geary.benchmarks.helpers.tenMil
import com.mineinabyss.geary.datatypes.family.family
import com.mineinabyss.geary.helpers.entity
import com.mineinabyss.geary.modules.TestEngineModule
import com.mineinabyss.geary.modules.geary
Expand Down Expand Up @@ -30,7 +29,6 @@ class Unpack1Benchmark {
}
}

// 5.149 ops/s
@Benchmark
fun unpack1of1Comp() {
SystemOf1.run {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ class Unpack2Benchmark {
}
}

// 4.993 ops/s
@Benchmark
fun unpack1of2Comp() {
SystemOf1.run {
Expand All @@ -47,7 +46,6 @@ class Unpack2Benchmark {
}
}

// 3.576 ops/s
@Benchmark
fun unpack2of2Comp() {
SystemOf2.run {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import com.mineinabyss.geary.modules.archetypes
)
annotation class UnsafeAccessors

/** A record created in place that delegates to the real entity pointer the first time [entity] gets accessed. */
class RecordPointer @PublishedApi internal constructor(
archetype: Archetype,
row: Int
Expand Down Expand Up @@ -40,8 +41,8 @@ class RecordPointer @PublishedApi internal constructor(
return entity
}

operator fun component1(): Archetype =
@OptIn(UnsafeAccessors::class) archetype
@UnsafeAccessors
operator fun component1(): Archetype = archetype

operator fun component2(): Int = row
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.mineinabyss.geary.systems

import com.mineinabyss.geary.datatypes.Records
import com.mineinabyss.geary.helpers.componentId
import com.mineinabyss.geary.systems.accessors.*
import com.mineinabyss.geary.systems.accessors.type.ComponentAccessor
Expand Down Expand Up @@ -59,6 +58,6 @@ abstract class Listener : AccessorOperations(), System {
return this.on(event)
}

abstract fun Records.handle()
abstract fun Pointers.handle()
}

Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import com.mineinabyss.geary.helpers.getArchetype
import com.mineinabyss.geary.helpers.tests.GearyTest
import com.mineinabyss.geary.modules.geary
import com.mineinabyss.geary.systems.Listener
import com.mineinabyss.geary.systems.accessors.Pointers
import io.kotest.matchers.shouldBe
import org.junit.jupiter.api.Test

Expand All @@ -19,7 +20,7 @@ internal class ComponentAddEventTest : GearyTest() {
val Records.int by get<Int>().whenSetOnTarget()
val Records.double by get<Double>().whenSetOnTarget()

override fun Records.handle() {
override fun Pointers.handle() {
inc++
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import com.mineinabyss.geary.helpers.entity
import com.mineinabyss.geary.helpers.tests.GearyTest
import com.mineinabyss.geary.modules.geary
import com.mineinabyss.geary.systems.Listener
import com.mineinabyss.geary.systems.accessors.Pointers
import io.kotest.matchers.shouldBe
import kotlin.test.Test

Expand All @@ -14,7 +15,7 @@ class SimpleComponentAddListenerTest : GearyTest() {

val Records.data by get<Int>().whenSetOnTarget()

override fun Records.handle() {
override fun Pointers.handle() {
called += 1
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import com.mineinabyss.geary.helpers.entity
import com.mineinabyss.geary.helpers.tests.GearyTest
import com.mineinabyss.geary.modules.geary
import com.mineinabyss.geary.systems.Listener
import com.mineinabyss.geary.systems.accessors.Pointers
import io.kotest.matchers.shouldBe
import kotlin.test.Test

Expand All @@ -17,7 +18,7 @@ class SimpleEventTest : GearyTest() {
val Records.data by get<Int>().on(target)
val Records.event by get<MyEvent>().on(event)

override fun Records.handle() {
override fun Pointers.handle() {
called += 1
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import com.mineinabyss.geary.helpers.entity
import com.mineinabyss.geary.helpers.tests.GearyTest
import com.mineinabyss.geary.modules.geary
import com.mineinabyss.geary.systems.Listener
import com.mineinabyss.geary.systems.accessors.Pointers
import io.kotest.matchers.shouldBe
import org.junit.jupiter.api.Test

Expand All @@ -22,7 +23,7 @@ class SourceTargetEventTest : GearyTest() {
event.mutableFamily.add(family { has<Attack>() })
}

override fun Records.handle() {
override fun Pointers.handle() {
health = Health(health.amount - strength.amount)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import com.mineinabyss.geary.helpers.entity
import com.mineinabyss.geary.helpers.tests.GearyTest
import com.mineinabyss.geary.modules.archetypes
import com.mineinabyss.geary.modules.geary
import com.mineinabyss.geary.systems.accessors.Pointers
import io.kotest.matchers.collections.shouldContain
import io.kotest.matchers.shouldBe
import org.junit.jupiter.api.Test
Expand All @@ -17,7 +18,7 @@ internal class QueryManagerTest : GearyTest() {
var ran = 0
private val Records.testComponent by get<TestComponent>().on(target)

override fun Records.handle() {
override fun Pointers.handle() {
ran++
}
}
Expand Down

0 comments on commit 1cd4a99

Please sign in to comment.