Added profiler to sphere generator
This commit is contained in:
parent
9414f773bb
commit
a5c84ebdcd
1 changed files with 44 additions and 41 deletions
|
@ -7,6 +7,7 @@ import net.minecraft.init.Blocks;
|
|||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.world.World;
|
||||
import cpw.mods.fml.common.FMLCommonHandler;
|
||||
import cr0s.warpdrive.LocalProfiler;
|
||||
import cr0s.warpdrive.WarpDrive;
|
||||
import cr0s.warpdrive.config.MetaBlock;
|
||||
import cr0s.warpdrive.config.structures.Orb;
|
||||
|
@ -46,30 +47,30 @@ public final class EntitySphereGen extends Entity {
|
|||
public int xCoord;
|
||||
public int yCoord;
|
||||
public int zCoord;
|
||||
|
||||
|
||||
private int radius;
|
||||
private int gasColor;
|
||||
|
||||
|
||||
private final int BLOCKS_PER_TICK = 5000;
|
||||
|
||||
|
||||
private final int STATE_SAVING = 0;
|
||||
private final int STATE_SETUP = 1;
|
||||
private final int STATE_DELETE = 2;
|
||||
private final int STATE_STOP = 3;
|
||||
private int state = STATE_DELETE;
|
||||
private int ticksDelay = 0;
|
||||
|
||||
|
||||
private int currentIndex = 0;
|
||||
private int pregenSize = 0;
|
||||
|
||||
|
||||
private ArrayList<JumpBlock> blocks;
|
||||
private Orb orb;
|
||||
private boolean replace;
|
||||
|
||||
|
||||
public EntitySphereGen(World world) {
|
||||
super(world);
|
||||
}
|
||||
|
||||
|
||||
public EntitySphereGen(World world, int x, int y, int z, int radius, Orb orb, boolean replace) {
|
||||
super(world);
|
||||
this.xCoord = x;
|
||||
|
@ -87,13 +88,13 @@ public final class EntitySphereGen extends Entity {
|
|||
this.orb = orb;
|
||||
this.replace = replace;
|
||||
}
|
||||
|
||||
|
||||
public void killEntity() {
|
||||
this.state = STATE_STOP;
|
||||
worldObj.markBlockRangeForRenderUpdate(xCoord - radius, yCoord - radius, zCoord - radius, xCoord + radius, yCoord + radius, zCoord + radius);
|
||||
worldObj.removeEntity(this);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onUpdate() {
|
||||
if (FMLCommonHandler.instance().getEffectiveSide().isClient()) {
|
||||
|
@ -110,50 +111,53 @@ public final class EntitySphereGen extends Entity {
|
|||
tickScheduleBlocks();
|
||||
this.state = STATE_SETUP;
|
||||
break;
|
||||
|
||||
|
||||
case STATE_SETUP:
|
||||
if (currentIndex >= blocks.size() - 1)
|
||||
this.state = STATE_DELETE;
|
||||
else
|
||||
tickPlaceBlocks();
|
||||
break;
|
||||
|
||||
|
||||
case STATE_DELETE:
|
||||
currentIndex = 0;
|
||||
killEntity();
|
||||
break;
|
||||
|
||||
|
||||
default:
|
||||
WarpDrive.logger.error(this + " Invalid state " + state + ". Killing entity...");
|
||||
killEntity();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void tickPlaceBlocks() {
|
||||
int blocksToMove = Math.min(BLOCKS_PER_TICK, blocks.size() - currentIndex);
|
||||
// LocalProfiler.start("[EntitySphereGen] Placing blocks: " +
|
||||
// currentIndex + "/" + blocks.size());
|
||||
LocalProfiler.start("[EntitySphereGen] Placing blocks from " + currentIndex + " to " + (currentIndex + blocksToMove) + "/" + blocks.size());
|
||||
int notifyFlag;
|
||||
|
||||
|
||||
for (int index = 0; index < blocksToMove; index++) {
|
||||
if (currentIndex >= blocks.size())
|
||||
break;
|
||||
notifyFlag = (currentIndex % 1000 == 0 ? 2 : 0);
|
||||
notifyFlag = (currentIndex % 1000 == 0 ? 2 : 2);
|
||||
JumpBlock jb = blocks.get(currentIndex);
|
||||
JumpBlock.setBlockNoLight(worldObj, jb.x, jb.y, jb.z, jb.block, jb.blockMeta, notifyFlag);
|
||||
// worldObj.setBlock(jb.x, jb.y, jb.z, jb.block, jb.blockMeta, notifyFlag);
|
||||
currentIndex++;
|
||||
}
|
||||
|
||||
// LocalProfiler.stop();
|
||||
|
||||
LocalProfiler.stop();
|
||||
}
|
||||
|
||||
|
||||
private void tickScheduleBlocks() {
|
||||
radius += 0.5D; // Radius from center of block
|
||||
|
||||
LocalProfiler.start("[EntitySphereGen] Saving blocks");
|
||||
|
||||
// Radius from center of block
|
||||
radius += 0.5D;
|
||||
|
||||
// sphere
|
||||
int ceilRadius = (int) Math.ceil(radius);
|
||||
|
||||
|
||||
// Pass the cube and check points for sphere equation x^2 + y^2 + z^2 = r^2
|
||||
for (int x = 0; x <= ceilRadius; x++) {
|
||||
double x2 = (x + 0.5D) * (x + 0.5D);
|
||||
|
@ -161,38 +165,37 @@ public final class EntitySphereGen extends Entity {
|
|||
double y2 = (y + 0.5D) * (y + 0.5D);
|
||||
for (int z = 0; z <= ceilRadius; z++) {
|
||||
double z2 = (z + 0.5D) * (z + 0.5D);
|
||||
double dSq = Math.sqrt(x2 + y2 + z2); // Distance from current position
|
||||
// to center
|
||||
|
||||
double dSq = Math.sqrt(x2 + y2 + z2); // Distance from current position to center
|
||||
|
||||
// Skip too far blocks
|
||||
if (dSq > radius)
|
||||
continue;
|
||||
|
||||
|
||||
int rad = (int) Math.ceil(dSq);
|
||||
|
||||
|
||||
// Add blocks to memory
|
||||
OrbShell orbShell = orb.getShellForRadius(rad);
|
||||
MetaBlock metablock = orbShell.getRandomBlock(rand);
|
||||
addBlock(new JumpBlock(metablock.block, metablock.metadata, xCoord + x, yCoord + y, zCoord + z));
|
||||
|
||||
|
||||
metablock = orbShell.getRandomBlock(rand);
|
||||
addBlock(new JumpBlock(metablock.block, metablock.metadata, xCoord - x, yCoord + y, zCoord + z));
|
||||
|
||||
|
||||
metablock = orbShell.getRandomBlock(rand);
|
||||
addBlock(new JumpBlock(metablock.block, metablock.metadata, xCoord + x, yCoord - y, zCoord + z));
|
||||
|
||||
|
||||
metablock = orbShell.getRandomBlock(rand);
|
||||
addBlock(new JumpBlock(metablock.block, metablock.metadata, xCoord + x, yCoord + y, zCoord - z));
|
||||
|
||||
|
||||
metablock = orbShell.getRandomBlock(rand);
|
||||
addBlock(new JumpBlock(metablock.block, metablock.metadata, xCoord - x, yCoord - y, zCoord + z));
|
||||
|
||||
|
||||
metablock = orbShell.getRandomBlock(rand);
|
||||
addBlock(new JumpBlock(metablock.block, metablock.metadata, xCoord + x, yCoord - y, zCoord - z));
|
||||
|
||||
|
||||
metablock = orbShell.getRandomBlock(rand);
|
||||
addBlock(new JumpBlock(metablock.block, metablock.metadata, xCoord - x, yCoord + y, zCoord - z));
|
||||
|
||||
|
||||
metablock = orbShell.getRandomBlock(rand);
|
||||
addBlock(new JumpBlock(metablock.block, metablock.metadata, xCoord - x, yCoord - y, zCoord - z));
|
||||
}
|
||||
|
@ -201,9 +204,9 @@ public final class EntitySphereGen extends Entity {
|
|||
if (blocks != null) {
|
||||
WarpDrive.logger.info("[EntitySphereGen] Saved " + blocks.size() + " blocks (estimated to " + pregenSize + ")");
|
||||
}
|
||||
// LocalProfiler.stop();
|
||||
LocalProfiler.stop();
|
||||
}
|
||||
|
||||
|
||||
private void addBlock(JumpBlock jb) {
|
||||
if (blocks == null)
|
||||
return;
|
||||
|
@ -221,19 +224,19 @@ public final class EntitySphereGen extends Entity {
|
|||
return;
|
||||
blocks.add(jb);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void readEntityFromNBT(NBTTagCompound tag) {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void entityInit() {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void writeEntityToNBT(NBTTagCompound tag) {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean shouldRenderInPass(int pass) {
|
||||
return false;
|
||||
|
|
Loading…
Reference in a new issue