mirror of
https://github.com/ClassiCube/MCGalaxy.git
synced 2025-09-23 12:42:22 -04:00
Fix delta calculation
This commit is contained in:
parent
77f5744314
commit
2fe118d0ff
@ -69,6 +69,7 @@ namespace MCGalaxy {
|
||||
|
||||
level = lvl;
|
||||
id = NextFreeId(this);
|
||||
supportsExtPositions = true;
|
||||
|
||||
botTimer.Elapsed += BotTimerFunc;
|
||||
botTimer.Start();
|
||||
|
@ -233,9 +233,9 @@ namespace MCGalaxy {
|
||||
return buffer;
|
||||
}
|
||||
|
||||
public unsafe static void GetPositionPacket(ref byte* ptr, byte id, Position pos,
|
||||
public unsafe static void GetPositionPacket(ref byte* ptr, byte id, bool extPositions, Position pos,
|
||||
Position oldPos, Orientation rot, Orientation oldRot) {
|
||||
Position delta = GetDelta(pos, oldPos);
|
||||
Position delta = GetDelta(pos, oldPos, extPositions);
|
||||
bool posChanged = delta.X != 0 || delta.Y != 0 || delta.Z != 0;
|
||||
bool oriChanged = rot.RotY != oldRot.RotY || rot.HeadX != oldRot.HeadX;
|
||||
bool absPosUpdate = Math.Abs(delta.X) > 32 || Math.Abs(delta.Y) > 32 || Math.Abs(delta.Z) > 32;
|
||||
@ -269,9 +269,12 @@ namespace MCGalaxy {
|
||||
}
|
||||
}
|
||||
|
||||
static Position GetDelta(Position pos, Position oldPos) {
|
||||
return new Position(pos.X - oldPos.X, pos.Y - oldPos.Y, pos.Z - oldPos.Z);
|
||||
// TODO: proper delta calculation for 16 bit clients
|
||||
static Position GetDelta(Position pos, Position old, bool extPositions) {
|
||||
Position delta = new Position(pos.X - old.X, pos.Y - old.Y, pos.Z - old.Z);
|
||||
if (extPositions) return delta;
|
||||
|
||||
delta.X = (short)delta.X; delta.Y = (short)delta.Y; delta.Z = (short)delta.Z;
|
||||
return delta;
|
||||
}
|
||||
|
||||
public static void GlobalUpdate() {
|
||||
@ -299,7 +302,8 @@ namespace MCGalaxy {
|
||||
|
||||
Orientation rot = pl.Rot;
|
||||
rot.HeadX = p.hasChangeModel ? MakePitch(pl, rot.HeadX) : MakeClassicPitch(pl, rot.HeadX);
|
||||
Entities.GetPositionPacket(ref ptr, pl.id, pl.tempPos, pl.lastPos, rot, pl.lastRot);
|
||||
Entities.GetPositionPacket(ref ptr, pl.id, pl.supportsExtPositions,
|
||||
pl.tempPos, pl.lastPos, rot, pl.lastRot);
|
||||
}
|
||||
|
||||
int count = (int)(ptr - src);
|
||||
|
@ -29,6 +29,7 @@ namespace MCGalaxy {
|
||||
// Last sent orientation/position, for delta calculation
|
||||
protected internal Orientation lastRot;
|
||||
protected internal Position lastPos;
|
||||
internal bool supportsExtPositions;
|
||||
// TODO: struct assignment needs to be THREADSAFE
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user