Don't waste resources creating absolute positon updates when bot hasn't moved and hasn't rotated. Partially addresses #459.

This commit is contained in:
UnknownShadow200 2017-08-01 23:46:14 +10:00
parent 16e87c8c3a
commit 5e0fcf6119
2 changed files with 8 additions and 10 deletions

View File

@ -19,6 +19,7 @@ using System;
using System.Collections.Generic;
using MCGalaxy.Bots;
using MCGalaxy.Maths;
using MCGalaxy.Network;
namespace MCGalaxy {
@ -127,11 +128,13 @@ namespace MCGalaxy {
DoMove();
}
// TODO: check if external code modified pos/rot
byte[] packet = Entities.GetPositionPacket(this, false);
lastPos = Pos; lastRot = Rot;
if (packet == null) return;
byte[] extPacket = Entities.GetPositionPacket(this, true);
Position pos = Pos; Orientation rot = Rot;
if (pos == lastPos && rot.HeadX == lastRot.HeadX && rot.RotY == lastRot.RotY) return;
lastPos = pos; lastRot = rot;
// TODO: relative position updates, combine packets
byte[] packet = Packet.Teleport(id, pos, rot, false);
byte[] extPacket = Packet.Teleport(id, pos, rot, true);
Player[] players = PlayerInfo.Online.Items;
foreach (Player p in players) {

View File

@ -235,11 +235,6 @@ namespace MCGalaxy {
#region Position updates
public static byte[] GetPositionPacket(PlayerBot bot, bool extPos) {
// TODO: not sure why bots only work with absolute packets
return Packet.Teleport(bot.id, bot.Pos, bot.Rot, extPos);
}
public unsafe static void GetPositionPacket(ref byte* ptr, byte id, bool srcExtPos, bool extPos,
Position pos, Position oldPos, Orientation rot, Orientation oldRot) {
Position delta = GetDelta(pos, oldPos, srcExtPos);