Added client side debug for packets per block
This commit is contained in:
parent
da96375b8c
commit
8bf0e12ba8
4 changed files with 97 additions and 4 deletions
|
@ -29,13 +29,14 @@ public class Effects
|
|||
double dy = y - cy;
|
||||
double dz = z - cz;
|
||||
double ratio = Math.sqrt(dx * dx + dy * dy + dz * dz);
|
||||
|
||||
while (Math.abs(cx - x) > Math.abs(dx / ratio))
|
||||
int i = 0;
|
||||
while (Math.abs(cx - x) > Math.abs(dx / ratio) && i < 100)
|
||||
{
|
||||
world.spawnParticle("townaura", cx, cy, cz, 0.0D, 0.0D, 0.0D);
|
||||
cx += dx * 0.1 / ratio;
|
||||
cy += dy * 0.1 / ratio;
|
||||
cz += dz * 0.1 / ratio;
|
||||
i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,6 +9,7 @@ import net.minecraft.item.Item;
|
|||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.crafting.FurnaceRecipes;
|
||||
import net.minecraftforge.common.Configuration;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.event.ForgeSubscribe;
|
||||
import net.minecraftforge.event.world.WorldEvent;
|
||||
import net.minecraftforge.oredict.OreDictionary;
|
||||
|
@ -30,6 +31,7 @@ import cpw.mods.fml.common.event.FMLPreInitializationEvent;
|
|||
import cpw.mods.fml.common.event.FMLServerStoppingEvent;
|
||||
import cpw.mods.fml.common.network.NetworkMod;
|
||||
import cpw.mods.fml.common.network.NetworkRegistry;
|
||||
import cpw.mods.fml.common.registry.TickRegistry;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import dark.api.ProcessorRecipes;
|
||||
import dark.api.ProcessorRecipes.ProcessorType;
|
||||
|
@ -60,6 +62,7 @@ import dark.core.common.transmit.BlockWire;
|
|||
import dark.core.common.transmit.ItemBlockWire;
|
||||
import dark.core.network.PacketHandler;
|
||||
import dark.core.prefab.ModPrefab;
|
||||
import dark.core.prefab.helpers.PacketDataWatcher;
|
||||
import dark.core.prefab.items.ItemBlockHolder;
|
||||
import dark.core.prefab.machine.BlockMulti;
|
||||
import dark.core.registration.ModObjectRegistry;
|
||||
|
@ -119,8 +122,8 @@ public class DarkMain extends ModPrefab
|
|||
{
|
||||
instance = this;
|
||||
super.preInit(event);
|
||||
|
||||
NetworkRegistry.instance().registerGuiHandler(this, proxy);
|
||||
MinecraftForge.EVENT_BUS.register(PacketDataWatcher.instance);
|
||||
proxy.preInit();
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package dark.core.network;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.network.INetworkManager;
|
||||
import net.minecraft.network.packet.Packet250CustomPayload;
|
||||
|
@ -10,6 +12,7 @@ import universalelectricity.prefab.network.IPacketReceiver;
|
|||
import com.google.common.io.ByteArrayDataInput;
|
||||
|
||||
import cpw.mods.fml.common.network.Player;
|
||||
import dark.core.prefab.helpers.PacketDataWatcher;
|
||||
|
||||
public class PacketManagerTile implements IPacketManager
|
||||
{
|
||||
|
@ -44,6 +47,7 @@ public class PacketManagerTile implements IPacketManager
|
|||
|
||||
if (tileEntity != null)
|
||||
{
|
||||
PacketDataWatcher.instance.onPacketData(tileEntity, packet, System.currentTimeMillis());
|
||||
if (tileEntity instanceof ISimplePacketReceiver)
|
||||
{
|
||||
String pId = data.readUTF();
|
||||
|
@ -63,5 +67,4 @@ public class PacketManagerTile implements IPacketManager
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
86
src/dark/core/prefab/helpers/PacketDataWatcher.java
Normal file
86
src/dark/core/prefab/helpers/PacketDataWatcher.java
Normal file
|
@ -0,0 +1,86 @@
|
|||
package dark.core.prefab.helpers;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.EnumSet;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.network.packet.Packet250CustomPayload;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.ChatMessageComponent;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.event.ForgeSubscribe;
|
||||
import net.minecraftforge.event.entity.player.PlayerInteractEvent;
|
||||
import net.minecraftforge.event.entity.player.PlayerInteractEvent.Action;
|
||||
import universalelectricity.core.vector.Vector3;
|
||||
|
||||
import com.builtbroken.common.Pair;
|
||||
|
||||
import cpw.mods.fml.common.IScheduledTickHandler;
|
||||
import cpw.mods.fml.common.TickType;
|
||||
|
||||
public class PacketDataWatcher
|
||||
{
|
||||
HashMap<Pair<World, Vector3>, List<Integer>> packetSizes = new HashMap<Pair<World, Vector3>, List<Integer>>();
|
||||
|
||||
public static PacketDataWatcher instance = new PacketDataWatcher();
|
||||
|
||||
public boolean enable = false;
|
||||
|
||||
public void onPacketData(TileEntity entity, Packet250CustomPayload data, long t)
|
||||
{
|
||||
if (entity != null && enable)
|
||||
{
|
||||
Pair<World, Vector3> location = new Pair<World, Vector3>(entity.worldObj, new Vector3(entity));
|
||||
List<Integer> l = this.packetSizes.get(location);
|
||||
if (l == null)
|
||||
{
|
||||
l = new ArrayList<Integer>();
|
||||
}
|
||||
l.add(data.getPacketSize());
|
||||
this.packetSizes.put(location, l);
|
||||
}
|
||||
}
|
||||
|
||||
@ForgeSubscribe
|
||||
public void playerRightClickEvent(PlayerInteractEvent event)
|
||||
{
|
||||
if (event.action == Action.RIGHT_CLICK_BLOCK && event.entityPlayer.capabilities.isCreativeMode && event.entityPlayer.getHeldItem() != null && event.entityPlayer.getHeldItem().itemID == Item.blazeRod.itemID)
|
||||
{
|
||||
if (event.entityPlayer.worldObj.isRemote)
|
||||
{
|
||||
if (event.entityPlayer.isSneaking())
|
||||
{
|
||||
this.enable = !this.enable;
|
||||
event.entityPlayer.sendChatToPlayer(ChatMessageComponent.createFromText("PacketWatcher is now " + (this.enable ? "Enabled. Now caching packet sizes." : "Disabled. Data cache has been cleared")));
|
||||
this.packetSizes.clear();
|
||||
}
|
||||
else
|
||||
{
|
||||
TileEntity ent = event.entityPlayer.worldObj.getBlockTileEntity(event.x, event.y, event.z);
|
||||
if (ent != null)
|
||||
{
|
||||
System.out.println("Entity Check");
|
||||
Pair<World, Vector3> location = new Pair(ent.worldObj, new Vector3(ent));
|
||||
int p = 0, a = 0;
|
||||
if (this.packetSizes.get(location) != null)
|
||||
{
|
||||
for (int i : this.packetSizes.get(location))
|
||||
{
|
||||
a += i;
|
||||
}
|
||||
p = this.packetSizes.get(location).size();
|
||||
a /= (p > 0 ? p : 1);
|
||||
}
|
||||
event.entityPlayer.sendChatToPlayer(ChatMessageComponent.createFromText("AveragePacketSize: " + a + "bits for " + p + " packets"));
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue