Skip to content

Commit

Permalink
Cleaning out some TODOs
Browse files Browse the repository at this point in the history
  • Loading branch information
0ffz committed Feb 28, 2024
1 parent 6202329 commit a305b25
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.mineinabyss.geary.uuid

import com.mineinabyss.geary.addons.dsl.GearyAddonWithDefault
import com.mineinabyss.geary.uuid.systems.createTrackUUIDOnAddSystem
import com.mineinabyss.geary.uuid.systems.createUntrackUuidOnRemoveSystem
import com.mineinabyss.geary.uuid.systems.createTrackUUIDOnAddListener
import com.mineinabyss.geary.uuid.systems.createUntrackUuidOnRemoveListener
import com.mineinabyss.idofront.di.DI

val uuid2Geary by DI.observe<UUID2GearyMap>()
Expand All @@ -11,7 +11,7 @@ object UUIDTracking : GearyAddonWithDefault<UUID2GearyMap> {
override fun default() = SimpleUUID2GearyMap()

override fun UUID2GearyMap.install() {
createTrackUUIDOnAddSystem()
createUntrackUuidOnRemoveSystem()
createTrackUUIDOnAddListener()
createUntrackUuidOnRemoveListener()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,13 @@ package com.mineinabyss.geary.uuid.systems

import com.benasher44.uuid.Uuid
import com.benasher44.uuid.uuid4
import com.mineinabyss.geary.annotations.optin.UnsafeAccessors
import com.mineinabyss.geary.modules.geary
import com.mineinabyss.geary.systems.builders.listener
import com.mineinabyss.geary.systems.query.ListenerQuery
import com.mineinabyss.geary.uuid.components.RegenerateUUIDOnClash
import com.mineinabyss.geary.uuid.uuid2Geary

@OptIn(UnsafeAccessors::class)
fun createTrackUUIDOnAddSystem() = geary.listener(object : ListenerQuery() {
fun createTrackUUIDOnAddListener() = geary.listener(object : ListenerQuery() {
var uuid by get<Uuid>()
val regenerateUUIDOnClash by get<RegenerateUUIDOnClash>().orNull()
override fun ensure() = event.anySet(::uuid)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@ import com.mineinabyss.geary.systems.builders.listener
import com.mineinabyss.geary.systems.query.ListenerQuery
import com.mineinabyss.geary.uuid.uuid2Geary

//TODO fix
fun createUntrackUuidOnRemoveSystem() = geary.listener(object : ListenerQuery() {
fun createUntrackUuidOnRemoveListener() = geary.listener(object : ListenerQuery() {
val uuid by get<Uuid>()
override fun ensure() = event.invoke { has<EntityRemoved>() }
}).exec {
uuid2Geary.remove(uuid)
}
}).exec { uuid2Geary.remove(uuid) }
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import com.mineinabyss.geary.annotations.optin.UnsafeAccessors
import com.mineinabyss.geary.datatypes.GearyEntity
import com.mineinabyss.geary.engine.archetypes.Archetype
import com.mineinabyss.geary.helpers.fastForEach
import com.mineinabyss.geary.systems.accessors.type.ComponentAccessor

class CachedQueryRunner<T : Query> internal constructor(val query: T) {
val matchedArchetypes: MutableList<Archetype> = mutableListOf()
Expand All @@ -24,10 +23,12 @@ class CachedQueryRunner<T : Query> internal constructor(val query: T) {
while (n < size) {
val archetype = matched[n]
archetype.isIterating = true

// We disallow entity archetype modifications while iterating, but allow creating new entities.
// These will always end up at the end of the archetype list so we just don't iterate over them.
val upTo = archetype.size
var row = 0
query.originalArchetype = archetype
// TODO upTo isn't perfect for cases where entities may be added or removed in the same iteration
accessors.fastForEach { it.updateCache(archetype) }
while (row < upTo) {
query.originalRow = row
Expand Down

0 comments on commit a305b25

Please sign in to comment.