2021-07-19 11:47:33 +02:00
|
|
|
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
|
|
From: Phoenix616 <max@themoep.de>
|
|
|
|
Date: Mon, 28 Jun 2021 22:38:29 +0100
|
|
|
|
Subject: [PATCH] Rate options and timings for sensors and behaviors
|
|
|
|
|
|
|
|
This adds config options to specify the tick rate for sensors
|
|
|
|
and behaviors of different entity types as well as timings
|
|
|
|
for those in order to be able to have some metrics as to which
|
|
|
|
ones might need tweaking.
|
|
|
|
|
|
|
|
diff --git a/src/main/java/co/aikar/timings/MinecraftTimings.java b/src/main/java/co/aikar/timings/MinecraftTimings.java
|
2023-12-06 20:40:37 +01:00
|
|
|
index 4bd813161a5d76a83cdbd0a9209b9ea9e60ffe1b..e2764186bd6b838ed5cd86c15597a08d079ef984 100644
|
2021-07-19 11:47:33 +02:00
|
|
|
--- a/src/main/java/co/aikar/timings/MinecraftTimings.java
|
|
|
|
+++ b/src/main/java/co/aikar/timings/MinecraftTimings.java
|
2023-03-28 04:58:46 +02:00
|
|
|
@@ -115,6 +115,14 @@ public final class MinecraftTimings {
|
2021-07-19 11:47:33 +02:00
|
|
|
return Timings.ofSafe("Minecraft", "## tickEntity - " + entityType + " - " + type, tickEntityTimer);
|
|
|
|
}
|
|
|
|
|
|
|
|
+ public static Timing getBehaviorTimings(String type) {
|
2021-08-01 11:22:55 +02:00
|
|
|
+ return Timings.ofSafe("## Behavior - " + type);
|
2021-07-19 11:47:33 +02:00
|
|
|
+ }
|
|
|
|
+
|
2021-07-25 08:50:36 +02:00
|
|
|
+ public static Timing getSensorTimings(String type, int rate) {
|
2021-08-01 11:22:55 +02:00
|
|
|
+ return Timings.ofSafe("## Sensor - " + type + " (Default rate: " + rate + ")");
|
2021-07-19 11:47:33 +02:00
|
|
|
+ }
|
|
|
|
+
|
|
|
|
/**
|
|
|
|
* Get a named timer for the specified tile entity type to track type specific timings.
|
|
|
|
* @param entity
|
|
|
|
diff --git a/src/main/java/net/minecraft/world/entity/ai/behavior/Behavior.java b/src/main/java/net/minecraft/world/entity/ai/behavior/Behavior.java
|
2024-04-24 16:29:12 +02:00
|
|
|
index f639cafa64d98a001e622882c647701547f5c3ac..9379dd4056018b52c93ed4888dcdc94579bd9691 100644
|
2021-07-19 11:47:33 +02:00
|
|
|
--- a/src/main/java/net/minecraft/world/entity/ai/behavior/Behavior.java
|
|
|
|
+++ b/src/main/java/net/minecraft/world/entity/ai/behavior/Behavior.java
|
2024-04-12 21:14:06 +02:00
|
|
|
@@ -14,6 +14,10 @@ public abstract class Behavior<E extends LivingEntity> implements BehaviorContro
|
2021-07-19 11:47:33 +02:00
|
|
|
private long endTimestamp;
|
|
|
|
private final int minDuration;
|
|
|
|
private final int maxDuration;
|
|
|
|
+ // Paper start - configurable behavior tick rate and timings
|
|
|
|
+ private final String configKey;
|
|
|
|
+ private final co.aikar.timings.Timing timing;
|
2024-01-19 13:22:30 +01:00
|
|
|
+ // Paper end - configurable behavior tick rate and timings
|
2021-07-19 11:47:33 +02:00
|
|
|
|
|
|
|
public Behavior(Map<MemoryModuleType<?>, MemoryStatus> requiredMemoryState) {
|
|
|
|
this(requiredMemoryState, 60);
|
2024-04-12 21:14:06 +02:00
|
|
|
@@ -27,6 +31,15 @@ public abstract class Behavior<E extends LivingEntity> implements BehaviorContro
|
2021-07-19 11:47:33 +02:00
|
|
|
this.minDuration = minRunTime;
|
|
|
|
this.maxDuration = maxRunTime;
|
|
|
|
this.entryCondition = requiredMemoryState;
|
|
|
|
+ // Paper start - configurable behavior tick rate and timings
|
2024-04-23 21:23:27 +02:00
|
|
|
+ String key = io.papermc.paper.util.MappingEnvironment.reobf() ? io.papermc.paper.util.ObfHelper.INSTANCE.deobfClassName(this.getClass().getName()) : this.getClass().getName();
|
2021-08-14 12:06:17 +02:00
|
|
|
+ int lastSeparator = key.lastIndexOf('.');
|
|
|
|
+ if (lastSeparator != -1) {
|
|
|
|
+ key = key.substring(lastSeparator + 1);
|
2021-07-19 11:47:33 +02:00
|
|
|
+ }
|
2021-07-19 13:07:49 +02:00
|
|
|
+ this.configKey = key.toLowerCase(java.util.Locale.ROOT);
|
2021-07-19 11:47:33 +02:00
|
|
|
+ this.timing = co.aikar.timings.MinecraftTimings.getBehaviorTimings(configKey);
|
2024-01-19 13:22:30 +01:00
|
|
|
+ // Paper end - configurable behavior tick rate and timings
|
2021-07-19 11:47:33 +02:00
|
|
|
}
|
|
|
|
|
2022-12-07 21:16:54 +01:00
|
|
|
@Override
|
2024-04-12 21:14:06 +02:00
|
|
|
@@ -36,11 +49,19 @@ public abstract class Behavior<E extends LivingEntity> implements BehaviorContro
|
2021-07-19 11:47:33 +02:00
|
|
|
|
2022-12-07 21:16:54 +01:00
|
|
|
@Override
|
2021-07-19 11:47:33 +02:00
|
|
|
public final boolean tryStart(ServerLevel world, E entity, long time) {
|
2024-01-19 13:22:30 +01:00
|
|
|
+ // Paper start - configurable behavior tick rate and timings
|
2022-06-09 10:51:45 +02:00
|
|
|
+ int tickRate = java.util.Objects.requireNonNullElse(world.paperConfig().tickRates.behavior.get(entity.getType(), this.configKey), -1);
|
2021-07-19 11:47:33 +02:00
|
|
|
+ if (tickRate > -1 && time < this.endTimestamp + tickRate) {
|
|
|
|
+ return false;
|
|
|
|
+ }
|
2024-01-19 13:22:30 +01:00
|
|
|
+ // Paper end - configurable behavior tick rate and timings
|
2021-07-19 11:47:33 +02:00
|
|
|
if (this.hasRequiredMemories(entity) && this.checkExtraStartConditions(world, entity)) {
|
|
|
|
this.status = Behavior.Status.RUNNING;
|
|
|
|
int i = this.minDuration + world.getRandom().nextInt(this.maxDuration + 1 - this.minDuration);
|
2024-04-16 21:44:59 +02:00
|
|
|
this.endTimestamp = time + (long)i;
|
2021-07-19 11:47:33 +02:00
|
|
|
+ this.timing.startTiming(); // Paper - behavior timings
|
|
|
|
this.start(world, entity, time);
|
|
|
|
+ this.timing.stopTiming(); // Paper - behavior timings
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
2024-04-12 21:14:06 +02:00
|
|
|
@@ -52,11 +73,13 @@ public abstract class Behavior<E extends LivingEntity> implements BehaviorContro
|
2021-07-19 11:47:33 +02:00
|
|
|
|
2022-12-07 21:16:54 +01:00
|
|
|
@Override
|
2021-07-19 11:47:33 +02:00
|
|
|
public final void tickOrStop(ServerLevel world, E entity, long time) {
|
|
|
|
+ this.timing.startTiming(); // Paper - behavior timings
|
|
|
|
if (!this.timedOut(time) && this.canStillUse(world, entity, time)) {
|
|
|
|
this.tick(world, entity, time);
|
|
|
|
} else {
|
|
|
|
this.doStop(world, entity, time);
|
|
|
|
}
|
|
|
|
+ this.timing.stopTiming(); // Paper - behavior timings
|
|
|
|
}
|
|
|
|
|
2024-04-12 21:14:06 +02:00
|
|
|
protected void tick(ServerLevel world, E entity, long time) {
|
2021-07-19 11:47:33 +02:00
|
|
|
diff --git a/src/main/java/net/minecraft/world/entity/ai/sensing/Sensor.java b/src/main/java/net/minecraft/world/entity/ai/sensing/Sensor.java
|
2024-04-24 16:29:12 +02:00
|
|
|
index 671fc7725d7c801a2ba009da5bd1bc1a9530f187..85b4b24361e785acf75571ff98f924c00ae80748 100644
|
2021-07-19 11:47:33 +02:00
|
|
|
--- a/src/main/java/net/minecraft/world/entity/ai/sensing/Sensor.java
|
|
|
|
+++ b/src/main/java/net/minecraft/world/entity/ai/sensing/Sensor.java
|
2024-04-12 21:14:06 +02:00
|
|
|
@@ -26,8 +26,21 @@ public abstract class Sensor<E extends LivingEntity> {
|
|
|
|
.ignoreInvisibilityTesting();
|
2021-07-19 11:47:33 +02:00
|
|
|
private final int scanRate;
|
|
|
|
private long timeToTick;
|
|
|
|
+ // Paper start - configurable sensor tick rate and timings
|
|
|
|
+ private final String configKey;
|
|
|
|
+ private final co.aikar.timings.Timing timing;
|
|
|
|
+ // Paper end
|
|
|
|
|
|
|
|
public Sensor(int senseInterval) {
|
|
|
|
+ // Paper start - configurable sensor tick rate and timings
|
2024-04-23 21:23:27 +02:00
|
|
|
+ String key = io.papermc.paper.util.MappingEnvironment.reobf() ? io.papermc.paper.util.ObfHelper.INSTANCE.deobfClassName(this.getClass().getName()) : this.getClass().getName();
|
2021-08-14 12:06:17 +02:00
|
|
|
+ int lastSeparator = key.lastIndexOf('.');
|
|
|
|
+ if (lastSeparator != -1) {
|
|
|
|
+ key = key.substring(lastSeparator + 1);
|
2021-07-19 11:47:33 +02:00
|
|
|
+ }
|
2021-07-19 13:07:49 +02:00
|
|
|
+ this.configKey = key.toLowerCase(java.util.Locale.ROOT);
|
2021-07-25 08:50:36 +02:00
|
|
|
+ this.timing = co.aikar.timings.MinecraftTimings.getSensorTimings(configKey, senseInterval);
|
2021-07-19 11:47:33 +02:00
|
|
|
+ // Paper end
|
|
|
|
this.scanRate = senseInterval;
|
2024-04-16 21:44:59 +02:00
|
|
|
this.timeToTick = (long)RANDOM.nextInt(senseInterval);
|
2021-07-19 11:47:33 +02:00
|
|
|
}
|
2024-04-12 21:14:06 +02:00
|
|
|
@@ -38,8 +51,12 @@ public abstract class Sensor<E extends LivingEntity> {
|
2021-07-19 11:47:33 +02:00
|
|
|
|
|
|
|
public final void tick(ServerLevel world, E entity) {
|
|
|
|
if (--this.timeToTick <= 0L) {
|
2024-04-16 21:44:59 +02:00
|
|
|
- this.timeToTick = (long)this.scanRate;
|
2021-07-19 11:47:33 +02:00
|
|
|
+ // Paper start - configurable sensor tick rate and timings
|
2022-06-09 10:51:45 +02:00
|
|
|
+ this.timeToTick = java.util.Objects.requireNonNullElse(world.paperConfig().tickRates.sensor.get(entity.getType(), this.configKey), this.scanRate);
|
2021-07-19 11:47:33 +02:00
|
|
|
+ this.timing.startTiming();
|
|
|
|
+ // Paper end
|
|
|
|
this.doTick(world, entity);
|
|
|
|
+ this.timing.stopTiming(); // Paper - sensor timings
|
|
|
|
}
|
|
|
|
}
|
2024-04-12 21:14:06 +02:00
|
|
|
|