CoordinatesChunk can now use some metadata for various purposes (right now, will be used for ChunkLoaded/Forced).

Finer profiling of the worldTick. Will be reworked later.
Packets with a size > 32000 are dropped before being sent and print an error to the server console.
This commit is contained in:
ProfMobius committed 2014-03-25 18:39:46 +01:00
1 parent dcbc5e2f59
commit d8dc1af510
7 files changed
+137 -39

No files matched your search

@@ -11,6 +11,7 @@ import net.minecraft.world.ChunkCoordIntPair;
public final class CoordinatesChunk implements ISerializable {
public final int dim, x, y, z;
public final int chunkX, chunkZ;
public final byte metadata;
//public boolean isChunk;
public CoordinatesChunk(CoordinatesBlock coord){
@@ -21,6 +22,8 @@ public final class CoordinatesChunk implements ISerializable {
this.x = chunkX << 4;
this.y = 0;
this.z = chunkZ << 4;
this.metadata = 0;
}
public CoordinatesChunk(int dim, int chunkX, int chunkZ){
@@ -30,9 +33,23 @@ public final class CoordinatesChunk implements ISerializable {
this.x = chunkX << 4;
this.y = 0;
this.z = chunkZ << 4;
this.z = chunkZ << 4;
this.metadata = 0;
}
public CoordinatesChunk(int dim, int chunkX, int chunkZ, byte metadata){
this.dim = dim;
this.chunkX = chunkX;
this.chunkZ = chunkZ;
this.x = chunkX << 4;
this.y = 0;
this.z = chunkZ << 4;
this.metadata = metadata;
}
public CoordinatesChunk(TileEntity te){
this.dim = te.getWorldObj().provider.dimensionId;
this.chunkX = te.xCoord >> 4;
@@ -40,7 +57,9 @@ public final class CoordinatesChunk implements ISerializable {
this.x = this.chunkX << 4;
this.y = 0;
this.z = this.chunkZ << 4;
this.z = this.chunkZ << 4;
this.metadata = 0;
}
public String toString(){
@@ -72,10 +91,11 @@ public final class CoordinatesChunk implements ISerializable {
public void writeToStream(DataOutputStream stream) throws IOException {
stream.writeInt(this.dim);
stream.writeInt(this.chunkX);
stream.writeInt(this.chunkZ);
stream.writeInt(this.chunkZ);
stream.writeByte(this.metadata);
}
public static CoordinatesChunk readFromStream(DataInputStream stream) throws IOException {
return new CoordinatesChunk(stream.readInt(), stream.readInt(), stream.readInt());
return new CoordinatesChunk(stream.readInt(), stream.readInt(), stream.readInt(), stream.readByte());
}
}
@@ -9,31 +9,24 @@ public class GlobalTimingManager {
public static HashMap<Integer, StatsWorld> worldTickStats = new HashMap<Integer, StatsWorld>();
public static HashMap<Integer, StatsWorld> entUpdateStats = new HashMap<Integer, StatsWorld>();
public static HashMap<Integer, StatsWorld> worldUpdatesStats = new HashMap<Integer, StatsWorld>();
public static HashMap<Integer, StatsWorld> worldBlocksAndAmbianceStats = new HashMap<Integer, StatsWorld>();
public static HashMap<Integer, StatsWorld> worldPlayerInstancesStats = new HashMap<Integer, StatsWorld>();
public static HashMap<Integer, StatsWorld> worldVillageCollectionStats = new HashMap<Integer, StatsWorld>();
public static HashMap<Integer, StatsWorld> worldVillageSiegeStats = new HashMap<Integer, StatsWorld>();
public static HashMap<Integer, StatsWorld> worldApplyBlockEventsStats = new HashMap<Integer, StatsWorld>();
/* Add an entity to the stat array, with timing data */
public static void addWorldTickStat(int id, long timing){
if (!(worldTickStats.containsKey(id)))
worldTickStats.put(id, new StatsWorld(id));
worldTickStats.get(id).addMeasure(timing);
}
public static void addEntUpdateStat(int id, long timing){
if (!(entUpdateStats.containsKey(id)))
entUpdateStats.put(id, new StatsWorld(id));
entUpdateStats.get(id).addMeasure(timing);
}
public static double getTotalWorldTickStats(){
double total = 0D;
for (Integer dim : worldTickStats.keySet())
total += worldTickStats.get(dim).getGeometricMean();
return total;
}
public static double getTotalEntUpdateStats(){
double total = 0D;
for (Integer dim : entUpdateStats.keySet())
total += entUpdateStats.get(dim).getGeometricMean();
return total;
public static void addStat(int id, long timing, HashMap<Integer, StatsWorld> target){
if (!(target.containsKey(id)))
target.put(id, new StatsWorld(id));
target.get(id).addMeasure(timing);
}
public static double getTotalStats(HashMap<Integer, StatsWorld> target){
double total = 0D;
for (Integer dim : target.keySet())
total += target.get(dim).getGeometricMean();
return total;
}
}
@@ -18,7 +18,7 @@ public class EntUpdateProfiler extends AbstractProfiler implements IProfilerEntU
@Override
public void EntUpdateEnd(int id) {
this.clock.stop();
GlobalTimingManager.addEntUpdateStat(id, this.clock.timeDelta);
GlobalTimingManager.addStat(id, this.clock.timeDelta, GlobalTimingManager.entUpdateStats);
}
}
@@ -10,16 +10,88 @@ public class WorldTickProfiler extends AbstractProfiler implements IProfilerWorl
//public static WorldTickProfiler instance() {return _instance;}
//public StatsBase stats = new StatsBase();
protected Clock clock_1 = new Clock();
protected Clock clock_2 = new Clock();
protected Clock clock_3 = new Clock();
protected Clock clock_4 = new Clock();
protected Clock clock_5 = new Clock();
protected Clock clock_6 = new Clock();
@Override
public void WorldTickStart(int id) {
this.clock.start();
}
@Override
public void WorldTickEnd(int id) {
this.clock.stop();
GlobalTimingManager.addWorldTickStat(id, this.clock.timeDelta);
GlobalTimingManager.addStat(id, this.clock.timeDelta, GlobalTimingManager.worldTickStats);
}
@Override
public void UpdatesS(int dim) {
this.clock_1.start();
}
@Override
public void UpdatesE(int dim) {
this.clock_1.stop();
GlobalTimingManager.addStat(dim, this.clock_1.timeDelta, GlobalTimingManager.worldUpdatesStats);
}
@Override
public void BlocksAndAmbianceS(int dim) {
this.clock_2.start();
}
@Override
public void BlocksAndAmbianceE(int dim) {
this.clock_2.stop();
GlobalTimingManager.addStat(dim, this.clock_2.timeDelta, GlobalTimingManager.worldBlocksAndAmbianceStats);
}
@Override
public void PlayerInstancesS(int dim) {
this.clock_3.start();
}
@Override
public void PlayerInstancesE(int dim) {
this.clock_3.stop();
GlobalTimingManager.addStat(dim, this.clock_3.timeDelta, GlobalTimingManager.worldPlayerInstancesStats);
}
@Override
public void VillageCollectionS(int dim) {
this.clock_4.start();
}
@Override
public void VillageCollectionE(int dim) {
this.clock_4.stop();
GlobalTimingManager.addStat(dim, this.clock_4.timeDelta, GlobalTimingManager.worldVillageCollectionStats);
}
@Override
public void VillageSiegeS(int dim) {
this.clock_5.start();
}
@Override
public void VillageSiegeE(int dim) {
this.clock_5.stop();
GlobalTimingManager.addStat(dim, this.clock_5.timeDelta, GlobalTimingManager.worldVillageSiegeStats);
}
@Override
public void ApplyBlockEventsS(int dim) {
this.clock_6.start();
}
@Override
public void ApplyBlockEventsE(int dim) {
this.clock_6.stop();
GlobalTimingManager.addStat(dim, this.clock_6.timeDelta, GlobalTimingManager.worldApplyBlockEventsStats);
}
}
@@ -114,13 +114,24 @@ public class OpisServerTickHandler implements ITickHandler {
modOpis.profilerRun = false;
ProfilerRegistrar.turnOff();
// Here we should send a full update to all the clients registered
OpisPacketHandler.sendPacketToAllSwing(Packet_DataValue.create(Message.STATUS_STOP, new SerialInt(modOpis.profilerMaxTicks)));
for (Player player : PlayerTracker.instance().playersSwing){
OpisPacketHandler.sendFullUpdate(player);
}
System.out.printf("worldUpdatesStats : %s µs\n", GlobalTimingManager.getTotalStats(GlobalTimingManager.worldUpdatesStats));
System.out.printf("worldBlocksAndAmbianceStats : %s µs\n", GlobalTimingManager.getTotalStats(GlobalTimingManager.worldBlocksAndAmbianceStats));
System.out.printf("worldPlayerInstancesStats : %s µs\n", GlobalTimingManager.getTotalStats(GlobalTimingManager.worldPlayerInstancesStats));
System.out.printf("worldVillageCollectionStats : %s µs\n", GlobalTimingManager.getTotalStats(GlobalTimingManager.worldVillageCollectionStats));
System.out.printf("worldVillageSiegeStats : %s µs\n", GlobalTimingManager.getTotalStats(GlobalTimingManager.worldVillageSiegeStats));
System.out.printf("worldApplyBlockEventsStats : %s µs\n", GlobalTimingManager.getTotalStats(GlobalTimingManager.worldApplyBlockEventsStats));
}
}
}
@@ -176,8 +176,10 @@ public class OpisPacketHandler implements IPacketHandler {
}
public static void validateAndSend(Packet_DataAbstract capsule, Player player){
if (capsule.msg.canPlayerUseCommand(player))
if (capsule.msg.canPlayerUseCommand(player) && capsule.packet.getPacketSize() < 32000)
PacketDispatcher.sendPacketToPlayer(capsule.packet, player);
else if (capsule.packet.getPacketSize() > 32000)
modOpis.log.warning(String.format("Data packet size of type %s too big : %d ! Dropping !", capsule.msg, capsule.packet.getPacketSize()));
}
public static void sendPacketToAllSwing(Packet_DataAbstract capsule){
@@ -204,8 +206,8 @@ public class OpisPacketHandler implements IPacketHandler {
SerialDouble totalTimeTE = new SerialDouble(TileEntityManager.getTotalUpdateTime());
SerialDouble totalTimeEnt = new SerialDouble(EntityManager.getTotalUpdateTime());
SerialDouble totalTimeHandler = new SerialDouble(TickHandlerManager.getTotalUpdateTime());
SerialDouble totalWorldTick = new SerialDouble(GlobalTimingManager.getTotalWorldTickStats());
SerialDouble totalEntUpdate = new SerialDouble(GlobalTimingManager.getTotalEntUpdateStats());
SerialDouble totalWorldTick = new SerialDouble(GlobalTimingManager.getTotalStats(GlobalTimingManager.worldTickStats));
SerialDouble totalEntUpdate = new SerialDouble(GlobalTimingManager.getTotalStats(GlobalTimingManager.entUpdateStats));
OpisPacketHandler.validateAndSend(Packet_DataList.create(Message.LIST_TIMING_HANDLERS, timingHandlers), player);
OpisPacketHandler.validateAndSend(Packet_DataList.create(Message.LIST_TIMING_ENTITIES, timingEntities), player);
@@ -112,11 +112,11 @@ public class ServerMessageHandler {
}
else if (maintype == Message.VALUE_TIMING_WORLDTICK){
OpisPacketHandler.validateAndSend(Packet_DataValue.create(Message.VALUE_TIMING_WORLDTICK, new SerialDouble(GlobalTimingManager.getTotalWorldTickStats())), (Player)player);
OpisPacketHandler.validateAndSend(Packet_DataValue.create(Message.VALUE_TIMING_WORLDTICK, new SerialDouble(GlobalTimingManager.getTotalStats(GlobalTimingManager.worldTickStats))), (Player)player);
}
else if (maintype == Message.VALUE_TIMING_ENTUPDATE){
OpisPacketHandler.validateAndSend(Packet_DataValue.create(Message.VALUE_TIMING_ENTUPDATE, new SerialDouble(GlobalTimingManager.getTotalEntUpdateStats())), (Player)player);
OpisPacketHandler.validateAndSend(Packet_DataValue.create(Message.VALUE_TIMING_ENTUPDATE, new SerialDouble(GlobalTimingManager.getTotalStats(GlobalTimingManager.entUpdateStats))), (Player)player);
}
else if (maintype == Message.LIST_AMOUNT_ENTITIES){