Cache position at start of GlobalUpdate(), avoids very rare issue of player positions being offset wrongly to other players when their positon changes mid-way through GlobalUpdate().

This commit is contained in:
UnknownShadow200 2016-06-16 20:12:22 +10:00
parent 5ec756c064
commit a793a164ba
2 changed files with 13 additions and 7 deletions

View File

@ -252,10 +252,16 @@ namespace MCGalaxy {
public static void GlobalUpdate() {
Player[] players = PlayerInfo.Online.Items;
// We need to cache the player's position before iterating.
// Avoids the very rare issue of player's position changing mid-way through iteration,
// which can cause this player to show minorly offset to other players.
foreach (Player p in players)
p.tempPos = p.pos;
foreach (Player p in players)
UpdatePosition(p);
foreach (Player p in players) {
p.oldpos = p.pos; p.oldrot = p.rot;
p.oldpos = p.tempPos; p.oldrot = p.rot;
}
}
@ -266,7 +272,7 @@ namespace MCGalaxy {
foreach (Player pl in players) {
if (p == pl || p.level != pl.level || !CanSeeEntity(p, pl)) continue;
byte pitch = p.hasChangeModel ? MakePitch(pl) : MakeClassicPitch(pl);
Entities.GetPositionPacket(ref ptr, pl.id, pl.pos, pl.oldpos, pl.rot, pl.oldrot, pitch);
Entities.GetPositionPacket(ref ptr, pl.id, pl.tempPos, pl.oldpos, pl.rot, pl.oldrot, pitch);
}
int count = (int)(ptr - src);

View File

@ -263,12 +263,12 @@ namespace MCGalaxy {
public bool Loading = true; //True if player is loading a map.
internal bool usingGoto = false;
public Vec3U16 lastClick = Vec3U16.Zero;
public ushort[] beforeTeleportPos = new ushort[] { 0, 0, 0 };
public ushort[] beforeTeleportPos = new ushort[3];
public string beforeTeleportMap = "";
public ushort[] pos = new ushort[] { 0, 0, 0 };
internal ushort[] oldpos = new ushort[] { 0, 0, 0 };
public byte[] rot = new byte[] { 0, 0 };
internal byte[] oldrot = new byte[] { 0, 0 };
public ushort[] pos = new ushort[3];
public byte[] rot = new byte[2];
internal ushort[] oldpos = new ushort[3], tempPos = new ushort[3];
internal byte[] oldrot = new byte[2];
//ushort[] clippos = new ushort[3] { 0, 0, 0 };
//byte[] cliprot = new byte[2] { 0, 0 };