More changes to view distance API implementation

Should fix GH-381
This commit is contained in:
Zach Brown 2016-08-13 15:26:40 -05:00
parent e51a3a332e
commit f80163c4ab
No known key found for this signature in database
GPG key ID: CC9DA35FC5450B76
3 changed files with 101 additions and 14 deletions

View file

@ -1,4 +1,4 @@
From 068369d52a9520129daf8c4f175e21d3eff59ec6 Mon Sep 17 00:00:00 2001
From 32205193321f857475c11a9e4b1e30a7d9031817 Mon Sep 17 00:00:00 2001
From: Byteflux <byte@byteflux.net>
Date: Wed, 2 Mar 2016 14:35:27 -0600
Subject: [PATCH] Add player view distance API
@ -25,7 +25,7 @@ index 522c7f2..4950db4 100644
// CraftBukkit start
public String displayName;
diff --git a/src/main/java/net/minecraft/server/PlayerChunkMap.java b/src/main/java/net/minecraft/server/PlayerChunkMap.java
index 797a84f..df6801f 100644
index 797a84f..fcd0186 100644
--- a/src/main/java/net/minecraft/server/PlayerChunkMap.java
+++ b/src/main/java/net/minecraft/server/PlayerChunkMap.java
@@ -47,7 +47,7 @@ public class PlayerChunkMap {
@ -85,7 +85,94 @@ index 797a84f..df6801f 100644
// this.c(l1, i2).a(entityplayer);
chunksToLoad.add(new ChunkCoordIntPair(l1, i2)); // CraftBukkit
}
@@ -495,4 +503,20 @@ public class PlayerChunkMap {
@@ -378,6 +386,8 @@ public class PlayerChunkMap {
return playerchunk != null && playerchunk.d(entityplayer) && playerchunk.e();
}
+ public final void setViewDistanceForAll(int viewDistance) { this.a(viewDistance); } // Paper - OBFHELPER
+ // Paper start - Separate into two methods
public void a(int i) {
i = MathHelper.clamp(i, 3, 32);
if (i != this.j) {
@@ -387,36 +397,55 @@ public class PlayerChunkMap {
while (iterator.hasNext()) {
EntityPlayer entityplayer = (EntityPlayer) iterator.next();
- int k = (int) entityplayer.locX >> 4;
- int l = (int) entityplayer.locZ >> 4;
- int i1;
- int j1;
-
- if (j > 0) {
- for (i1 = k - i; i1 <= k + i; ++i1) {
- for (j1 = l - i; j1 <= l + i; ++j1) {
- PlayerChunk playerchunk = this.c(i1, j1);
-
- if (!playerchunk.d(entityplayer)) {
- playerchunk.a(entityplayer);
- }
+ this.setViewDistance(entityplayer, i, false); // Paper - Split, don't mark sort pending, we'll handle it after
+ }
+
+ this.j = i;
+ this.e();
+ }
+ }
+
+ public void setViewDistance(EntityPlayer entityplayer, int i) {
+ this.setViewDistance(entityplayer, i, true); // Mark sort pending by default so we don't have to remember to do so all the time
+ }
+
+ // Copied from above with minor changes
+ public void setViewDistance(EntityPlayer entityplayer, int i, boolean markSort) {
+ i = MathHelper.clamp(i, 3, 32);
+ int oldViewDistance = entityplayer.getViewDistance();
+ if (i != oldViewDistance) {
+ int j = i - oldViewDistance;
+
+ int k = (int) entityplayer.locX >> 4;
+ int l = (int) entityplayer.locZ >> 4;
+ int i1;
+ int j1;
+
+ if (j > 0) {
+ for (i1 = k - i; i1 <= k + i; ++i1) {
+ for (j1 = l - i; j1 <= l + i; ++j1) {
+ PlayerChunk playerchunk = this.c(i1, j1);
+
+ if (!playerchunk.d(entityplayer)) {
+ playerchunk.a(entityplayer);
}
}
- } else {
- for (i1 = k - this.j; i1 <= k + this.j; ++i1) {
- for (j1 = l - this.j; j1 <= l + this.j; ++j1) {
- if (!this.a(i1, j1, k, l, i)) {
- this.c(i1, j1).b(entityplayer);
- }
+ }
+ } else {
+ for (i1 = k - oldViewDistance; i1 <= k + oldViewDistance; ++i1) {
+ for (j1 = l - oldViewDistance; j1 <= l + oldViewDistance; ++j1) {
+ if (!this.a(i1, j1, k, l, i)) {
+ this.c(i1, j1).b(entityplayer);
}
}
}
+ if (markSort) {
+ this.e();
+ }
}
-
- this.j = i;
- this.e();
}
}
+ // Paper end
private void e() {
this.l = true;
@@ -495,4 +524,20 @@ public class PlayerChunkMap {
}
}
// CraftBukkit end
@ -99,9 +186,9 @@ index 797a84f..df6801f 100644
+ viewDistance = -1;
+ }
+ if (viewDistance != oldViewDistance) {
+ removePlayer(player);
+ // Order matters
+ this.setViewDistance(player, viewDistance);
+ player.setViewDistance(viewDistance);
+ addPlayer(player);
+ }
+ }
+ // Paper end
@ -128,5 +215,5 @@ index 64c9c1c..e09dc78 100644
private final Player.Spigot spigot = new Player.Spigot()
{
--
2.9.0.windows.1
2.9.2.windows.1

View file

@ -1,14 +1,14 @@
From 2981829cfa78bbae1675dbea13ec8c08c3d8da45 Mon Sep 17 00:00:00 2001
From e3f1de4b334cfc96f9a55a02bc54ba7439f65c2f Mon Sep 17 00:00:00 2001
From: Daniel Ennis <dennis@icontact.com>
Date: Sun, 20 Mar 2016 15:22:42 -0400
Subject: [PATCH] Catch Async PlayerChunkMap operations
diff --git a/src/main/java/net/minecraft/server/PlayerChunkMap.java b/src/main/java/net/minecraft/server/PlayerChunkMap.java
index df6801f..6320247 100644
index fcd0186..c9d48ac 100644
--- a/src/main/java/net/minecraft/server/PlayerChunkMap.java
+++ b/src/main/java/net/minecraft/server/PlayerChunkMap.java
@@ -440,10 +440,12 @@ public class PlayerChunkMap {
@@ -461,10 +461,12 @@ public class PlayerChunkMap {
}
public void a(PlayerChunk playerchunk) {
@ -22,5 +22,5 @@ index df6801f..6320247 100644
long i = d(chunkcoordintpair.x, chunkcoordintpair.z);
--
2.9.0
2.9.2.windows.1

View file

@ -1,4 +1,4 @@
From 3d70eed63d400403703741a82b6d244ad746d5b7 Mon Sep 17 00:00:00 2001
From 4774815b3312ab0d3971130862e6d717509f9df0 Mon Sep 17 00:00:00 2001
From: Aikar <aikar@aikar.co>
Date: Sat, 18 Jun 2016 23:22:12 -0400
Subject: [PATCH] Delay Chunk Unloads based on Player Movement
@ -108,10 +108,10 @@ index dd40e98..f109e98 100644
// CraftBukkit end
diff --git a/src/main/java/net/minecraft/server/PlayerChunkMap.java b/src/main/java/net/minecraft/server/PlayerChunkMap.java
index 6320247..9fed846 100644
index c9d48ac..8e0b66d 100644
--- a/src/main/java/net/minecraft/server/PlayerChunkMap.java
+++ b/src/main/java/net/minecraft/server/PlayerChunkMap.java
@@ -458,7 +458,13 @@ public class PlayerChunkMap {
@@ -479,7 +479,13 @@ public class PlayerChunkMap {
Chunk chunk = playerchunk.f();
if (chunk != null) {
@ -140,5 +140,5 @@ index cf76fd3..af2f24a 100644
}
--
2.9.0
2.9.2.windows.1