mirror of
https://github.com/PaperMC/Paper.git
synced 2024-11-08 03:39:48 +01:00
Take the count mapping one step further by removing chunk traversal for count seeking altogether
This commit is contained in:
parent
2471de6147
commit
0436193bc8
@ -1,4 +1,4 @@
|
|||||||
From 9b80ec89a6c650410da797ad30fd6f6343d465a2 Mon Sep 17 00:00:00 2001
|
From a6f63db4333363a12ea2905bc4a2093abde6839d Mon Sep 17 00:00:00 2001
|
||||||
From: Aikar <aikar@aikar.co>
|
From: Aikar <aikar@aikar.co>
|
||||||
Date: Tue, 29 Jan 2013 13:25:53 -0500
|
Date: Tue, 29 Jan 2013 13:25:53 -0500
|
||||||
Subject: [PATCH] Only count entities in chunks being processed for the spawn
|
Subject: [PATCH] Only count entities in chunks being processed for the spawn
|
||||||
@ -6,7 +6,7 @@ Subject: [PATCH] Only count entities in chunks being processed for the spawn
|
|||||||
|
|
||||||
|
|
||||||
diff --git a/src/main/java/net/minecraft/server/SpawnerCreature.java b/src/main/java/net/minecraft/server/SpawnerCreature.java
|
diff --git a/src/main/java/net/minecraft/server/SpawnerCreature.java b/src/main/java/net/minecraft/server/SpawnerCreature.java
|
||||||
index b3e2818..6362a37 100644
|
index b3e2818..21fbf7d 100644
|
||||||
--- a/src/main/java/net/minecraft/server/SpawnerCreature.java
|
--- a/src/main/java/net/minecraft/server/SpawnerCreature.java
|
||||||
+++ b/src/main/java/net/minecraft/server/SpawnerCreature.java
|
+++ b/src/main/java/net/minecraft/server/SpawnerCreature.java
|
||||||
@@ -16,6 +16,7 @@ public final class SpawnerCreature {
|
@@ -16,6 +16,7 @@ public final class SpawnerCreature {
|
||||||
@ -17,34 +17,7 @@ index b3e2818..6362a37 100644
|
|||||||
|
|
||||||
protected static ChunkPosition getRandomPosition(World world, int i, int j) {
|
protected static ChunkPosition getRandomPosition(World world, int i, int j) {
|
||||||
Chunk chunk = world.getChunkAt(i, j);
|
Chunk chunk = world.getChunkAt(i, j);
|
||||||
@@ -26,6 +27,26 @@ public final class SpawnerCreature {
|
@@ -34,13 +35,24 @@ public final class SpawnerCreature {
|
||||||
return new ChunkPosition(k, i1, l);
|
|
||||||
}
|
|
||||||
|
|
||||||
+ // Spigot start - get entity count only from chunks being processed in b
|
|
||||||
+ public static final int getEntityCount(WorldServer server, Class oClass) {
|
|
||||||
+ int i = 0;
|
|
||||||
+ for (Long coord : b.keySet()) {
|
|
||||||
+ int x = LongHash.msw(coord);
|
|
||||||
+ int z = LongHash.lsw(coord);
|
|
||||||
+ if (!server.chunkProviderServer.unloadQueue.contains(x,z) && server.isChunkLoaded(x, z)) {
|
|
||||||
+ for (List<Entity> entitySlice : server.getChunkAt(x, z).entitySlices) {
|
|
||||||
+ for (Entity entity : entitySlice) {
|
|
||||||
+ if (oClass.isAssignableFrom(entity.getClass())) {
|
|
||||||
+ ++i;
|
|
||||||
+ }
|
|
||||||
+ }
|
|
||||||
+ }
|
|
||||||
+ }
|
|
||||||
+ }
|
|
||||||
+ return i;
|
|
||||||
+ }
|
|
||||||
+ // Spigot end
|
|
||||||
+
|
|
||||||
public static final int spawnEntities(WorldServer worldserver, boolean flag, boolean flag1, boolean flag2) {
|
|
||||||
if (!flag && !flag1) {
|
|
||||||
return 0;
|
|
||||||
@@ -34,13 +55,24 @@ public final class SpawnerCreature {
|
|
||||||
|
|
||||||
int i;
|
int i;
|
||||||
int j;
|
int j;
|
||||||
@ -70,7 +43,7 @@ index b3e2818..6362a37 100644
|
|||||||
|
|
||||||
for (int l = -b0; l <= b0; ++l) {
|
for (int l = -b0; l <= b0; ++l) {
|
||||||
for (int i1 = -b0; i1 <= b0; ++i1) {
|
for (int i1 = -b0; i1 <= b0; ++i1) {
|
||||||
@@ -88,13 +120,15 @@ public final class SpawnerCreature {
|
@@ -88,13 +100,15 @@ public final class SpawnerCreature {
|
||||||
if (limit == 0) {
|
if (limit == 0) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -78,7 +51,7 @@ index b3e2818..6362a37 100644
|
|||||||
// CraftBukkit end
|
// CraftBukkit end
|
||||||
|
|
||||||
- if ((!enumcreaturetype.d() || flag1) && (enumcreaturetype.d() || flag) && (!enumcreaturetype.e() || flag2) && worldserver.a(enumcreaturetype.a()) <= limit * b.size() / 256) { // CraftBukkit - use per-world limits
|
- if ((!enumcreaturetype.d() || flag1) && (enumcreaturetype.d() || flag) && (!enumcreaturetype.e() || flag2) && worldserver.a(enumcreaturetype.a()) <= limit * b.size() / 256) { // CraftBukkit - use per-world limits
|
||||||
+ if ((!enumcreaturetype.d() || flag1) && (enumcreaturetype.d() || flag) && (!enumcreaturetype.e() || flag2) && (mobcnt = getEntityCount(worldserver, enumcreaturetype.a())) <= limit * b.size() / 256) { // CraftBukkit - use per-world limits and use all loaded chunks
|
+ if ((!enumcreaturetype.d() || flag1) && (enumcreaturetype.d() || flag) && (!enumcreaturetype.e() || flag2) && (mobcnt = worldserver.a(enumcreaturetype.a())) <= limit * b.size() / 256) { // CraftBukkit - use per-world limits and use all loaded chunks
|
||||||
Iterator iterator = b.keySet().iterator();
|
Iterator iterator = b.keySet().iterator();
|
||||||
|
|
||||||
+ int moblimit = (limit * b.size() / 256) - mobcnt + 1; // CraftBukkit - up to 1 more than limit
|
+ int moblimit = (limit * b.size() / 256) - mobcnt + 1; // CraftBukkit - up to 1 more than limit
|
||||||
@ -88,7 +61,7 @@ index b3e2818..6362a37 100644
|
|||||||
// CraftBukkit start
|
// CraftBukkit start
|
||||||
long key = ((Long) iterator.next()).longValue();
|
long key = ((Long) iterator.next()).longValue();
|
||||||
|
|
||||||
@@ -158,6 +192,12 @@ public final class SpawnerCreature {
|
@@ -158,6 +172,12 @@ public final class SpawnerCreature {
|
||||||
a(entityliving, worldserver, f, f1, f2);
|
a(entityliving, worldserver, f, f1, f2);
|
||||||
worldserver.addEntity(entityliving, SpawnReason.NATURAL);
|
worldserver.addEntity(entityliving, SpawnReason.NATURAL);
|
||||||
// CraftBukkit end
|
// CraftBukkit end
|
||||||
@ -102,5 +75,5 @@ index b3e2818..6362a37 100644
|
|||||||
continue label110;
|
continue label110;
|
||||||
}
|
}
|
||||||
--
|
--
|
||||||
1.8.2.1
|
1.7.11.msysgit.0
|
||||||
|
|
||||||
|
@ -1,83 +1,73 @@
|
|||||||
From 42fcf69ddb25ec9aebbd6bbd45e552870b0373a9 Mon Sep 17 00:00:00 2001
|
From b59089bc2de520bc295712f1320a568dfb218bdd Mon Sep 17 00:00:00 2001
|
||||||
From: Ammar Askar <ammar@ammaraskar.com>
|
From: Ammar Askar <ammar@ammaraskar.com>
|
||||||
Date: Sat, 20 Apr 2013 12:26:20 +0500
|
Date: Sat, 20 Apr 2013 12:26:20 +0500
|
||||||
Subject: [PATCH] Save entity counts for randomly spawned creatures to avoid
|
Subject: [PATCH] Save entity counts for randomly spawned creatures to avoid
|
||||||
repeatedly traversing over the entity slices
|
repeatedly traversing over the entity slices and chunks
|
||||||
|
|
||||||
---
|
|
||||||
src/main/java/net/minecraft/server/Chunk.java | 16 ++++++++++++++++
|
|
||||||
src/main/java/net/minecraft/server/SpawnerCreature.java | 10 ++--------
|
|
||||||
2 files changed, 18 insertions(+), 8 deletions(-)
|
|
||||||
|
|
||||||
diff --git a/src/main/java/net/minecraft/server/Chunk.java b/src/main/java/net/minecraft/server/Chunk.java
|
diff --git a/src/main/java/net/minecraft/server/Chunk.java b/src/main/java/net/minecraft/server/Chunk.java
|
||||||
index 7f1c155..11e1a4e 100644
|
index 7f1c155..7dd931c 100644
|
||||||
--- a/src/main/java/net/minecraft/server/Chunk.java
|
--- a/src/main/java/net/minecraft/server/Chunk.java
|
||||||
+++ b/src/main/java/net/minecraft/server/Chunk.java
|
+++ b/src/main/java/net/minecraft/server/Chunk.java
|
||||||
@@ -9,6 +9,7 @@ import java.util.Map;
|
@@ -560,6 +560,13 @@ public class Chunk {
|
||||||
import java.util.Random;
|
|
||||||
|
|
||||||
import org.bukkit.Bukkit; // CraftBukkit
|
|
||||||
+import gnu.trove.map.hash.TObjectIntHashMap; // Spigot
|
|
||||||
|
|
||||||
public class Chunk {
|
|
||||||
|
|
||||||
@@ -33,6 +34,7 @@ public class Chunk {
|
|
||||||
public int p;
|
|
||||||
private int u;
|
|
||||||
boolean q;
|
|
||||||
+ protected TObjectIntHashMap<Class> entityCount = new TObjectIntHashMap<Class>(); // Spigot
|
|
||||||
|
|
||||||
public Chunk(World world, int i, int j) {
|
|
||||||
this.sections = new ChunkSection[16];
|
|
||||||
@@ -560,6 +562,13 @@ public class Chunk {
|
|
||||||
entity.ak = k;
|
entity.ak = k;
|
||||||
entity.al = this.z;
|
entity.al = this.z;
|
||||||
this.entitySlices[k].add(entity);
|
this.entitySlices[k].add(entity);
|
||||||
+ // Spigot start - increment creature type count
|
+ // Spigot start - increment creature type count
|
||||||
+ for (EnumCreatureType creatureType : EnumCreatureType.values()) {
|
+ for (EnumCreatureType creatureType : EnumCreatureType.values()) {
|
||||||
+ if (creatureType.a().isAssignableFrom(entity.getClass())) {
|
+ if (creatureType.a().isAssignableFrom(entity.getClass())) {
|
||||||
+ this.entityCount.adjustOrPutValue(creatureType.a(), 1, 1);
|
+ world.entityCount.adjustOrPutValue(creatureType.a(), 1, 1);
|
||||||
+ }
|
+ }
|
||||||
+ }
|
+ }
|
||||||
+ // Spigot end
|
+ // Spigot end
|
||||||
}
|
}
|
||||||
|
|
||||||
public void b(Entity entity) {
|
public void b(Entity entity) {
|
||||||
@@ -576,6 +585,13 @@ public class Chunk {
|
@@ -576,6 +583,13 @@ public class Chunk {
|
||||||
}
|
}
|
||||||
|
|
||||||
this.entitySlices[i].remove(entity);
|
this.entitySlices[i].remove(entity);
|
||||||
+ // Spigot start - decrement creature type count
|
+ // Spigot start - decrement creature type count
|
||||||
+ for (EnumCreatureType creatureType : EnumCreatureType.values()) {
|
+ for (EnumCreatureType creatureType : EnumCreatureType.values()) {
|
||||||
+ if (creatureType.a().isAssignableFrom(entity.getClass())) {
|
+ if (creatureType.a().isAssignableFrom(entity.getClass())) {
|
||||||
+ this.entityCount.adjustValue(creatureType.a(), -1);
|
+ world.entityCount.adjustValue(creatureType.a(), -1);
|
||||||
+ }
|
+ }
|
||||||
+ }
|
+ }
|
||||||
+ // Spigot end
|
+ // Spigot end
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean d(int i, int j, int k) {
|
public boolean d(int i, int j, int k) {
|
||||||
diff --git a/src/main/java/net/minecraft/server/SpawnerCreature.java b/src/main/java/net/minecraft/server/SpawnerCreature.java
|
diff --git a/src/main/java/net/minecraft/server/World.java b/src/main/java/net/minecraft/server/World.java
|
||||||
index 6362a37..2c3b94d 100644
|
index 7e10318..3b23a58 100644
|
||||||
--- a/src/main/java/net/minecraft/server/SpawnerCreature.java
|
--- a/src/main/java/net/minecraft/server/World.java
|
||||||
+++ b/src/main/java/net/minecraft/server/SpawnerCreature.java
|
+++ b/src/main/java/net/minecraft/server/World.java
|
||||||
@@ -33,14 +33,8 @@ public final class SpawnerCreature {
|
@@ -76,6 +76,7 @@ public abstract class World implements IBlockAccess {
|
||||||
for (Long coord : b.keySet()) {
|
int[] H;
|
||||||
int x = LongHash.msw(coord);
|
public boolean isStatic;
|
||||||
int z = LongHash.lsw(coord);
|
// Spigot start
|
||||||
- if (!server.chunkProviderServer.unloadQueue.contains(x,z) && server.isChunkLoaded(x, z)) {
|
+ protected gnu.trove.map.hash.TObjectIntHashMap<Class> entityCount = new gnu.trove.map.hash.TObjectIntHashMap<Class>();
|
||||||
- for (List<Entity> entitySlice : server.getChunkAt(x, z).entitySlices) {
|
|
||||||
- for (Entity entity : entitySlice) {
|
public static long chunkToKey(int x, int z) {
|
||||||
- if (oClass.isAssignableFrom(entity.getClass())) {
|
long k = ((((long)x) & 0xFFFF0000L) << 16) | ((((long)x) & 0x0000FFFFL) << 0);
|
||||||
- ++i;
|
@@ -2456,6 +2457,9 @@ public abstract class World implements IBlockAccess {
|
||||||
- }
|
|
||||||
- }
|
|
||||||
- }
|
|
||||||
+ if (!server.chunkProviderServer.unloadQueue.contains(coord) && server.isChunkLoaded(x, z)) {
|
|
||||||
+ i += server.getChunkAt(x, z).entityCount.get(oClass);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int a(Class oclass) {
|
||||||
|
+ // Spigot start - commented out inefficient chunk traversing in favour of keeping entity counts in a map
|
||||||
|
+ return this.entityCount.get(oclass);
|
||||||
|
+ /*
|
||||||
|
int i = 0;
|
||||||
|
|
||||||
|
for (int j = 0; j < this.entityList.size(); ++j) {
|
||||||
|
@@ -2467,6 +2471,8 @@ public abstract class World implements IBlockAccess {
|
||||||
}
|
}
|
||||||
|
|
||||||
return i;
|
return i;
|
||||||
|
+ */
|
||||||
|
+ // Spigot end
|
||||||
|
}
|
||||||
|
|
||||||
|
public void a(List list) {
|
||||||
--
|
--
|
||||||
1.7.11.msysgit.0
|
1.7.11.msysgit.0
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user