Skip to content

Commit

Permalink
A bit of cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
0ffz committed Sep 14, 2023
1 parent aa4eb48 commit 56d8c58
Show file tree
Hide file tree
Showing 20 changed files with 28 additions and 40 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ data class Velocity(var x: Double, var y: Double)

class UpdatePositionSystem : TickingSystem(interval = 20.milliseconds) {
// Specify all components we want (Geary also supports branched AND/OR/NOT statements for selection)
val TargetScope.position by get<Position>()
val TargetScope.velocity by get<Velocity>()
val Pointer.position by get<Position>()
val Pointer.velocity by get<Velocity>()

override fun TargetScope.tick() {
override fun Pointer.tick() {
// We can access our components like regular variables!
position.x += velocity.x
position.y += velocity.y
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.mineinabyss.geary.game.systems

import com.mineinabyss.geary.datatypes.UnsafeAccessors
import com.mineinabyss.geary.annotations.optin.UnsafeAccessors
import com.mineinabyss.geary.game.components.Expiry
import com.mineinabyss.geary.systems.RepeatingSystem
import com.mineinabyss.geary.systems.accessors.Pointer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ 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.UnsafeAccessors
import com.mineinabyss.geary.annotations.optin.UnsafeAccessors
import com.mineinabyss.geary.helpers.addParent
import com.mineinabyss.geary.helpers.entity
import com.mineinabyss.geary.prefabs.configuration.components.ChildOnPrefab
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.mineinabyss.geary.prefabs.configuration.systems

import com.mineinabyss.geary.datatypes.Records
import com.mineinabyss.geary.datatypes.UnsafeAccessors
import com.mineinabyss.geary.annotations.optin.UnsafeAccessors
import com.mineinabyss.geary.systems.Listener
import com.mineinabyss.geary.systems.accessors.Pointers
import com.mineinabyss.geary.systems.accessors.RelationWithData
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.mineinabyss.geary.prefabs.systems

import com.mineinabyss.geary.datatypes.Records
import com.mineinabyss.geary.datatypes.UnsafeAccessors
import com.mineinabyss.geary.annotations.optin.UnsafeAccessors
import com.mineinabyss.geary.datatypes.family.family
import com.mineinabyss.geary.prefabs.events.PrefabLoaded
import com.mineinabyss.geary.prefabs.helpers.inheritPrefabs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package com.mineinabyss.geary.prefabs.systems

import com.mineinabyss.geary.components.relations.NoInherit
import com.mineinabyss.geary.datatypes.Records
import com.mineinabyss.geary.datatypes.UnsafeAccessors
import com.mineinabyss.geary.annotations.optin.UnsafeAccessors
import com.mineinabyss.geary.prefabs.PrefabKey
import com.mineinabyss.geary.prefabs.prefabs
import com.mineinabyss.geary.systems.Listener
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ package com.mineinabyss.geary.uuid.systems

import com.benasher44.uuid.Uuid
import com.benasher44.uuid.uuid4
import com.mineinabyss.geary.datatypes.Records
import com.mineinabyss.geary.datatypes.UnsafeAccessors
import com.mineinabyss.geary.annotations.optin.UnsafeAccessors
import com.mineinabyss.geary.systems.GearyListener
import com.mineinabyss.geary.systems.accessors.Pointers

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,5 +90,5 @@ class NewEntityBenchmark {

fun main() {
geary(TestEngineModule)
NewEntityBenchmark().create1MilEntitiesWith6Components()
NewEntityBenchmark().create1MilEntitiesWith0Components()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.mineinabyss.geary.annotations.optin

@RequiresOptIn(
level = RequiresOptIn.Level.ERROR,
message = "Reading and writing entity data without an accessor reduces speed and does not enforce null safety for accessors." +
" Be careful when manually removing components used by other accessors."
)
annotation class UnsafeAccessors
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,6 @@ class EntityType private constructor(

fun indexOf(id: ComponentId): Int {
return inner.indexOf(id)
// for (i in 0 until size) {
// if (inner[i] == id) return i
// }
// return -1
// return binarySearch(id).coerceAtLeast(-1)
}

tailrec fun binarySearch(id: ComponentId, fromIndex: Int = 0, toIndex: Int = size - 1): Int {
Expand Down Expand Up @@ -95,11 +90,4 @@ class EntityType private constructor(

override fun toString(): String =
inner.joinToString(", ", prefix = "[", postfix = "]") { it.readableString() }

companion object {
internal fun fromMutableArray(array: ULongArray): EntityType {
array.sort()
return EntityType(array)
}
}
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,9 @@
package com.mineinabyss.geary.datatypes

import com.mineinabyss.geary.annotations.optin.UnsafeAccessors
import com.mineinabyss.geary.engine.archetypes.Archetype
import com.mineinabyss.geary.modules.archetypes

@RequiresOptIn(
level = RequiresOptIn.Level.ERROR,
message = "Reading and writing entity data without an accessor reduces speed and does not enforce null safety for accessors." +
" Be careful when manually removing components used by other accessors."
)
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,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.mineinabyss.geary.systems.accessors.type

import com.mineinabyss.geary.datatypes.ComponentId
import com.mineinabyss.geary.datatypes.UnsafeAccessors
import com.mineinabyss.geary.annotations.optin.UnsafeAccessors
import com.mineinabyss.geary.datatypes.family.Family
import com.mineinabyss.geary.datatypes.family.family
import com.mineinabyss.geary.engine.archetypes.Archetype
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.mineinabyss.geary.systems.accessors.type

import com.mineinabyss.geary.datatypes.ComponentId
import com.mineinabyss.geary.datatypes.UnsafeAccessors
import com.mineinabyss.geary.annotations.optin.UnsafeAccessors
import com.mineinabyss.geary.engine.archetypes.Archetype
import com.mineinabyss.geary.systems.accessors.Pointer
import com.mineinabyss.geary.systems.accessors.ReadOnlyAccessor
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.mineinabyss.geary.systems.accessors.type

import com.mineinabyss.geary.datatypes.ComponentId
import com.mineinabyss.geary.datatypes.UnsafeAccessors
import com.mineinabyss.geary.annotations.optin.UnsafeAccessors
import com.mineinabyss.geary.systems.accessors.Pointer

@OptIn(UnsafeAccessors::class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package com.mineinabyss.geary.systems.accessors.type
import com.mineinabyss.geary.datatypes.ComponentId
import com.mineinabyss.geary.datatypes.EntityId
import com.mineinabyss.geary.datatypes.Relation
import com.mineinabyss.geary.datatypes.UnsafeAccessors
import com.mineinabyss.geary.annotations.optin.UnsafeAccessors
import com.mineinabyss.geary.datatypes.family.Family
import com.mineinabyss.geary.datatypes.family.family
import com.mineinabyss.geary.engine.archetypes.Archetype
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package com.mineinabyss.geary.systems.accessors.type
import com.mineinabyss.geary.datatypes.ComponentId
import com.mineinabyss.geary.datatypes.EntityId
import com.mineinabyss.geary.datatypes.Relation
import com.mineinabyss.geary.datatypes.UnsafeAccessors
import com.mineinabyss.geary.annotations.optin.UnsafeAccessors
import com.mineinabyss.geary.datatypes.family.Family
import com.mineinabyss.geary.datatypes.family.family
import com.mineinabyss.geary.engine.archetypes.Archetype
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.mineinabyss.geary.systems.accessors.type

import com.mineinabyss.geary.datatypes.ComponentId
import com.mineinabyss.geary.datatypes.UnsafeAccessors
import com.mineinabyss.geary.annotations.optin.UnsafeAccessors
import com.mineinabyss.geary.systems.accessors.Pointer

@OptIn(UnsafeAccessors::class)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.mineinabyss.geary.systems

import com.mineinabyss.geary.datatypes.HOLDS_DATA
import com.mineinabyss.geary.datatypes.UnsafeAccessors
import com.mineinabyss.geary.annotations.optin.UnsafeAccessors
import com.mineinabyss.geary.helpers.componentId
import com.mineinabyss.geary.helpers.entity
import com.mineinabyss.geary.helpers.tests.GearyTest
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.mineinabyss.geary.systems.accessors

import com.mineinabyss.geary.datatypes.UnsafeAccessors
import com.mineinabyss.geary.annotations.optin.UnsafeAccessors
import com.mineinabyss.geary.helpers.Comp1
import com.mineinabyss.geary.helpers.entity
import com.mineinabyss.geary.helpers.tests.GearyTest
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.mineinabyss.geary.systems.accessors

import com.mineinabyss.geary.datatypes.UnsafeAccessors
import com.mineinabyss.geary.annotations.optin.UnsafeAccessors
import com.mineinabyss.geary.helpers.Comp1
import com.mineinabyss.geary.helpers.entity
import com.mineinabyss.geary.helpers.tests.GearyTest
Expand Down

0 comments on commit 56d8c58

Please sign in to comment.