This commit is contained in:
Colin Godsey 2018-08-08 18:07:03 -06:00
parent c09191b7f9
commit 0753b9271f
2 changed files with 62 additions and 58 deletions

View File

@ -1,11 +1,11 @@
From 81259e2cb7b30df39c3d1b23d66ec2c1bdde2a5d Mon Sep 17 00:00:00 2001 From 3ac10ee43109b578232e3d127511e761ddc87a1a Mon Sep 17 00:00:00 2001
From: Colin Godsey <crgodsey@gmail.com> From: Colin Godsey <crgodsey@gmail.com>
Date: Wed, 8 Aug 2018 16:10:06 -0600 Date: Wed, 8 Aug 2018 10:10:06 -0600
Subject: [PATCH] Add entity count cache Subject: [PATCH] Add entity count cache
diff --git a/src/main/java/net/minecraft/server/World.java b/src/main/java/net/minecraft/server/World.java diff --git a/src/main/java/net/minecraft/server/World.java b/src/main/java/net/minecraft/server/World.java
index 004c3ec4..09c2bc32 100644 index 004c3ec47..c392595c0 100644
--- a/src/main/java/net/minecraft/server/World.java --- a/src/main/java/net/minecraft/server/World.java
+++ b/src/main/java/net/minecraft/server/World.java +++ b/src/main/java/net/minecraft/server/World.java
@@ -50,10 +50,41 @@ public abstract class World implements GeneratorAccess, IIBlockAccess, AutoClose @@ -50,10 +50,41 @@ public abstract class World implements GeneratorAccess, IIBlockAccess, AutoClose
@ -66,48 +66,49 @@ index 004c3ec4..09c2bc32 100644
private final long G = 16777215L; private final long G = 16777215L;
private int H; public int getSkylightSubtracted() { return this.H; } public void setSkylightSubtracted(int value) { this.H = value;} // Paper - OBFHELPER private int H; public int getSkylightSubtracted() { return this.H; } public void setSkylightSubtracted(int value) { this.H = value;} // Paper - OBFHELPER
protected int m = (new Random()).nextInt(); protected int m = (new Random()).nextInt();
@@ -2439,19 +2472,16 @@ public abstract class World implements GeneratorAccess, IIBlockAccess, AutoClose @@ -2440,6 +2473,8 @@ public abstract class World implements GeneratorAccess, IIBlockAccess, AutoClose
} }
- public int a(Class<?> oclass) { public int a(Class<?> oclass) {
+ // Paper start - entity count cache + if (true) return getEntityCount(oclass); //Paper - short circuit to cached method
+ private int countEntityType(Class<?> oclass) { +
int i = 0; int i = 0;
Iterator iterator = this.entityList.iterator(); Iterator iterator = this.entityList.iterator();
while (iterator.hasNext()) { @@ -2464,6 +2499,71 @@ public abstract class World implements GeneratorAccess, IIBlockAccess, AutoClose
Entity entity = (Entity) iterator.next();
- if (entity.shouldBeRemoved) continue; // Paper
// CraftBukkit start - Split out persistent check, don't apply it to special persistent mobs
- if (entity instanceof EntityInsentient) {
- EntityInsentient entityinsentient = (EntityInsentient) entity;
- if (entityinsentient.isTypeNotPersistent() && entityinsentient.isPersistent()) {
- continue;
- }
+ if (shouldIgnoreForCount(entity)) {
+ continue;
}
if (oclass.isAssignableFrom(entity.getClass())) {
@@ -2464,6 +2494,52 @@ public abstract class World implements GeneratorAccess, IIBlockAccess, AutoClose
return i; return i;
} }
+ public int getEntityCount(Class<?> oclass) { return a(oclass); } // Paper - OBFHELPER + // Paper start - entity count cache
+ public int a(Class<?> oclass) { + private int countEntityType(Class<?> oclass) {
+ if(countCache.containsKey(oclass)) { + int i = 0;
+ return countCache.get(oclass); + Iterator iterator = this.entityList.iterator();
+ } else { +
+ int count = countEntityType(oclass); + while (iterator.hasNext()) {
+ Entity entity = (Entity) iterator.next();
+
+ if (shouldIgnoreForCount(entity)) continue;
+ if (oclass.isAssignableFrom(entity.getClass())) i++;
+ }
+
+ return i;
+ }
+
+ public int getEntityCount(Class<?> oclass) {
+ Integer count = countCache.get(oclass);
+
+ if (count != null) return count;
+
+ count = countEntityType(oclass);
+ +
+ countCache.put(oclass, count); + countCache.put(oclass, count);
+ +
+ return count; + return count;
+ } + }
+ }
+ +
+ public boolean shouldIgnoreForCount(Entity entity) { + public boolean shouldIgnoreForCount(Entity entity) {
+ if (entity == null) return true;
+
+ if (entity instanceof EntityInsentient) { + if (entity instanceof EntityInsentient) {
+ EntityInsentient entityinsentient = (EntityInsentient) entity; + EntityInsentient entityinsentient = (EntityInsentient) entity;
+ return entityinsentient.isTypeNotPersistent() && entityinsentient.isPersistent(); + return entityinsentient.isTypeNotPersistent() && entityinsentient.isPersistent();
@ -116,27 +117,30 @@ index 004c3ec4..09c2bc32 100644
+ return false; + return false;
+ } + }
+ +
+ protected void updateEntityCount(Class<?> clazz, boolean incr) {
+ Integer countObject = countCache.get(clazz);
+
+ if (countObject == null) return;
+
+ int count = countObject;
+
+ if (incr) count++;
+ else count--;
+
+ if(count < 0) {
+ e.warn("Entity count cache has gone negative");
+ count = 0;
+ }
+
+ countCache.put(clazz, count);
+ }
+
+ protected void updateEntityCount(Entity entity, boolean incr) { + protected void updateEntityCount(Entity entity, boolean incr) {
+ if(entity == null) return;
+ if (shouldIgnoreForCount(entity)) return; + if (shouldIgnoreForCount(entity)) return;
+ +
+ countCache.replaceAll((clazz, count) -> { + for (Class<?> clazz = entity.getClass() ; !clazz.equals(Object.class) ; clazz = clazz.getSuperclass()) {
+ if(clazz.isAssignableFrom(entity.getClass())) { + updateEntityCount(clazz, incr);
+ int newCount = count;
+
+ if(incr) newCount++;
+ else newCount--;
+
+ if(newCount < 0) {
+ e.warn("Entity count cache has gone negative");
+ newCount = 0;
+ } + }
+
+ return newCount;
+ } else {
+ return count;
+ }
+ });
+ } + }
+ // Paper end + // Paper end
+ +

View File

@ -1,11 +1,11 @@
From 35c565d267a562633607766e1264ac0cd4c01d87 Mon Sep 17 00:00:00 2001 From b9f0b43802d049d91f4db3cf26bce5f2084de76e Mon Sep 17 00:00:00 2001
From: Colin Godsey <crgodsey@gmail.com> From: Colin Godsey <crgodsey@gmail.com>
Date: Wed, 8 Aug 2018 16:33:21 -0600 Date: Wed, 8 Aug 2018 11:33:21 -0600
Subject: [PATCH] Configurable speed for water flowing over lava Subject: [PATCH] Configurable speed for water flowing over lava
diff --git a/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java b/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java diff --git a/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java b/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java
index 61c8b58b..ab3f59ad 100644 index 61c8b58b1..ab3f59ad7 100644
--- a/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java --- a/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java
+++ b/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java +++ b/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java
@@ -436,6 +436,12 @@ public class PaperWorldConfig { @@ -436,6 +436,12 @@ public class PaperWorldConfig {
@ -22,7 +22,7 @@ index 61c8b58b..ab3f59ad 100644
SAFE_REGEN, REGEN, DELETE, NOTHING, WARN SAFE_REGEN, REGEN, DELETE, NOTHING, WARN
} }
diff --git a/src/main/java/net/minecraft/server/BlockFluids.java b/src/main/java/net/minecraft/server/BlockFluids.java diff --git a/src/main/java/net/minecraft/server/BlockFluids.java b/src/main/java/net/minecraft/server/BlockFluids.java
index 6ecc1f84..637f6580 100644 index 6ecc1f84e..637f6580b 100644
--- a/src/main/java/net/minecraft/server/BlockFluids.java --- a/src/main/java/net/minecraft/server/BlockFluids.java
+++ b/src/main/java/net/minecraft/server/BlockFluids.java +++ b/src/main/java/net/minecraft/server/BlockFluids.java
@@ -67,10 +67,24 @@ public class BlockFluids extends Block implements IFluidSource { @@ -67,10 +67,24 @@ public class BlockFluids extends Block implements IFluidSource {