Skip to content

Commit

Permalink
Fix missing methods with newer fastutil version + other bugfixes
Browse files Browse the repository at this point in the history
  • Loading branch information
0ffz committed Jan 14, 2022
1 parent 01f07fc commit 58bcceb
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ repositories {
object GearyDeps {
val bimap = "com.uchuhimo:kotlinx-bimap:1.2"
val bitvector = "net.onedaybeard.bitvector:bitvector-jvm:0.1.4"
val fastutil = "it.unimi.dsi:fastutil:8.5.4"
val fastutil = "it.unimi.dsi:fastutil:8.2.2" //Version on minecraft server
val reflections = "org.reflections:reflections:0.9.12"
val plugman = "com.rylinaux:PlugMan:2.2.5"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public value class GearyType private constructor(
public fun last(): GearyComponentId = inner.lastLong().toULong()

public inline fun forEach(run: (GearyComponentId) -> Unit) {
val iterator = inner.longIterator()
val iterator = inner.iterator()
while (iterator.hasNext()) {
run(iterator.nextLong().toULong())
}
Expand All @@ -42,7 +42,7 @@ public value class GearyType private constructor(
}

public inline fun forEachIndexed(run: (Int, GearyComponentId) -> Unit) {
val iterator = inner.longIterator()
val iterator = inner.iterator()
var i = 0
forEach { run(i++, iterator.nextLong().toULong()) }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,19 @@ public value class GearyEntity(public val id: GearyEntityId) {
public fun removeRelation(relation: Relation): Boolean =
remove(Relation.of(relation.key, relation.value).id)

/** Removes all relations with a value of type [V] on the entity. */
public inline fun <reified V : GearyComponent> removeRelationsByValue(): Set<GearyComponent> =
removeRelationsByValue(componentId<V>())

/** Removes all relations with a value with id [componentId] on the entity. */
public fun removeRelationsByValue(componentId: GearyComponentId): Set<GearyComponent> {
val comps = Engine.getRelationsFor(this, RelationValueId(componentId))
comps.forEach { (_, relation) ->
removeRelation(relation)
}
return comps.mapTo(mutableSetOf()) { it.first }
}

/**
* Adds a [component] to this entity's type, setting no data.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package com.mineinabyss.geary.ecs.api.systems
import com.mineinabyss.geary.ecs.accessors.TargetScope
import com.mineinabyss.geary.ecs.engine.ArchetypeIterator
import com.mineinabyss.geary.ecs.query.Query
import com.mineinabyss.idofront.time.ticks
import kotlin.time.Duration
import kotlin.time.Duration.Companion.milliseconds

/**
* #### [Guide: Ticking systems](https://wiki.mineinabyss.com/geary/guide/ticking-systems)
Expand All @@ -16,7 +16,7 @@ import kotlin.time.Duration.Companion.milliseconds
* @see [ArchetypeIterator]
*/
public abstract class TickingSystem(
public val interval: Duration = 20.milliseconds,
public val interval: Duration = 1.ticks,
init: (TickingSystem.() -> Unit)? = null
) : Query(), GearySystem {
protected var iteration: Int = 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ public open class GearyEngine : TickingEngine() {

override fun tick(currentTick: Long) {
registeredSystems
.filter { currentTick % it.interval.inWholeTicks == 0L }
.filter { currentTick % it.interval.inWholeTicks.coerceAtLeast(1) == 0L }
.forEach {
try {
it.runSystem()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ import java.util.*
import kotlin.io.path.div
import kotlin.reflect.KClass

public val gearyPlugin: GearyPlugin = Bukkit.getPluginManager().getPlugin("Geary") as GearyPlugin

public class GearyPlugin : JavaPlugin() {
override fun onLoad() {
IdofrontPlatforms.load(this, "mineinabyss")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import com.mineinabyss.geary.ecs.serialization.Formats
import com.mineinabyss.geary.minecraft.access.BukkitEntityAssociations
import com.mineinabyss.geary.prefabs.PrefabKey
import com.mineinabyss.geary.prefabs.PrefabManager
import com.mineinabyss.idofront.plugin.registerEvents
import kotlinx.serialization.InternalSerializationApi
import kotlinx.serialization.KSerializer
import kotlinx.serialization.Serializable
Expand All @@ -20,7 +19,6 @@ import kotlinx.serialization.modules.SerializersModuleBuilder
import kotlinx.serialization.modules.polymorphic
import kotlinx.serialization.serializerOrNull
import org.bukkit.entity.Entity
import org.bukkit.event.Listener
import org.bukkit.plugin.Plugin
import java.io.File
import kotlin.reflect.KClass
Expand Down Expand Up @@ -145,7 +143,6 @@ public class GearyAddon(

/** Registers a list of [systems]. */
public fun systems(vararg systems: GearySystem) {
plugin.registerEvents(*systems.filterIsInstance<Listener>().toTypedArray())
systems.forEach { system(it) }
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,18 @@ package com.mineinabyss.geary.minecraft.engine

import co.aikar.timings.Timings
import com.mineinabyss.geary.ecs.api.entities.GearyEntity
import com.mineinabyss.geary.ecs.api.systems.GearySystem
import com.mineinabyss.geary.ecs.api.systems.TickingSystem
import com.mineinabyss.geary.ecs.engine.GearyEngine
import com.mineinabyss.geary.minecraft.GearyPlugin
import com.mineinabyss.geary.minecraft.events.GearyEntityRemoveEvent
import com.mineinabyss.geary.minecraft.gearyPlugin
import com.mineinabyss.idofront.events.call
import com.mineinabyss.idofront.plugin.registerEvents
import com.okkero.skedule.schedule
import org.bukkit.Bukkit
import org.bukkit.NamespacedKey
import org.bukkit.event.Listener
import java.util.*

public class SpigotEngine : GearyEngine() {
Expand All @@ -28,6 +32,13 @@ public class SpigotEngine : GearyEngine() {
}.getOrThrow()
}

override fun addSystem(system: GearySystem) {
super.addSystem(system)

if (system is Listener)
gearyPlugin.registerEvents(system)
}

override fun scheduleSystemTicking() {
//tick all systems every interval ticks
GearyPlugin.instance.schedule {
Expand All @@ -41,7 +52,7 @@ public class SpigotEngine : GearyEngine() {

override fun removeEntity(entity: GearyEntity) {
if (entity.has<UUID>())
//TODO this should be unnecessary now
//TODO this should be unnecessary now
GearyEntityRemoveEvent(entity).call()
super.removeEntity(entity)
}
Expand Down

0 comments on commit 58bcceb

Please sign in to comment.