Skip to content

Commit

Permalink
Improved logging, still run remaining ticks on exception in tick thread.
Browse files Browse the repository at this point in the history
Signed-off-by: Ross Allan <rallanpcl@gmail.com>
  • Loading branch information
LunNova committed Nov 20, 2012
1 parent 70de6c9 commit f322c36
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 34 deletions.
2 changes: 1 addition & 1 deletion build.xml
Expand Up @@ -58,7 +58,7 @@
</target>

<target name="version-not-provided" unless="env.BUILD_NUMBER">
<buildnumber/>
<property name="build.number" value="unknown"/>
</target>

<target name="version-provided" if="env.BUILD_NUMBER">
Expand Down
8 changes: 8 additions & 0 deletions src/common/me/nallar/tickthreading/Log.java
Expand Up @@ -3,11 +3,15 @@
import java.util.logging.Level;
import java.util.logging.Logger;

import cpw.mods.fml.common.FMLLog;
import net.minecraft.src.World;

@SuppressWarnings ("UnusedDeclaration")
public class Log {
private static final Logger LOGGER = Logger.getLogger("TickThreading");

static {
LOGGER.setParent(FMLLog.getLogger());
LOGGER.setLevel(Level.ALL);
}

Expand Down Expand Up @@ -66,4 +70,8 @@ public static void finer(String msg, Throwable t) {
public static void finest(String msg, Throwable t) {
LOGGER.log(Level.FINEST, msg, t);
}

public static String name(World world) {
return world.getWorldInfo().getWorldName() + ":" + world.getWorldInfo().getDimension() + ":" + world.hashCode();
}
}
48 changes: 26 additions & 22 deletions src/common/me/nallar/tickthreading/minecraft/ThreadManager.java
Expand Up @@ -75,31 +75,35 @@ public int getHashCode(Entity entity) {
}

private synchronized void processChanges() {
synchronized (changeProcessLock) {
for (TileEntity tileEntity : toAddTileEntities) {
getRunnableForTileEntity(tileEntity).add(tileEntity);
}
for (TileEntity tileEntity : toRemoveTileEntities) {
getRunnableForTileEntity(tileEntity).remove(tileEntity);
}
for (Entity entity : toAddEntities) {
getRunnableForEntity(entity).add(entity);
}
for (Entity entity : toRemoveEntities) {
getRunnableForEntity(entity).remove(entity);
}
Iterator<TickCallable<Object>> iterator = tickCallables.iterator();
while(iterator.hasNext()){
TickCallable tickCallable = iterator.next();
if(tickCallable.isEmpty()){
iterator.remove();
if(tickCallable instanceof EntityTickCallable){
entityRunnables.remove(tickCallable.hashCode);
} else {
tileEntityRunnables.remove(tickCallable.hashCode);
try{
synchronized (changeProcessLock) {
for (TileEntity tileEntity : toAddTileEntities) {
getRunnableForTileEntity(tileEntity).add(tileEntity);
}
for (TileEntity tileEntity : toRemoveTileEntities) {
getRunnableForTileEntity(tileEntity).remove(tileEntity);
}
for (Entity entity : toAddEntities) {
getRunnableForEntity(entity).add(entity);
}
for (Entity entity : toRemoveEntities) {
getRunnableForEntity(entity).remove(entity);
}
Iterator<TickCallable<Object>> iterator = tickCallables.iterator();
while(iterator.hasNext()){
TickCallable tickCallable = iterator.next();
if(tickCallable.isEmpty()){
iterator.remove();
if(tickCallable instanceof EntityTickCallable){
entityRunnables.remove(tickCallable.hashCode);
} else {
tileEntityRunnables.remove(tickCallable.hashCode);
}
}
}
}
} catch(Exception e) {
Log.severe("Exception occured while processing entity changes: ", e);
}
}

Expand Down
Expand Up @@ -58,13 +58,14 @@ public void onWorldLoad(WorldEvent.Load event) {
Field loadedTileEntityField = getListFields(World.class)[loadedTileEntityFieldIndex];
Field loadedEntityField = getListFields(World.class)[loadedEntityFieldIndex];
new LoadedTileEntityList<TileEntity>(event.world, loadedTileEntityField, manager);
Log.info("Threading initialised for world " + Log.name(event.world));
// TODO: Enable entity tick threading
// Requires:
// - AxisAlignedBB pool threadlocal
// - ^automated patching
//new LoadedEntityList<TileEntity>(event.world, loadedEntityField, manager);
} catch (Exception e) {
Log.severe("Failed to initialise tile threading for world " + event.world.getWorldInfo().getWorldName(), e);
Log.severe("Failed to initialise tile threading for world " + Log.name(event.world), e);
}
}

Expand All @@ -79,7 +80,7 @@ public void onWorldUnload(WorldEvent.Unload event) {
Log.severe("Looks like another mod broke threading for world, probably a long time ago: " + event.world.getWorldInfo().getWorldName());
}
} catch (Exception e) {
Log.severe("Probable memory leak: Failed to unload tile threading for world " + event.world.getWorldInfo().getWorldName(), e);
Log.severe("Probable memory leak: Failed to unload tile threading for world " + Log.name(event.world), e);
}
}

Expand Down
Expand Up @@ -19,9 +19,13 @@ public TileEntityTickCallable(World world, String identifier, ThreadManager mana

@Override
public T call() {
try {
IChunkProvider chunkProvider = world.getChunkProvider();
for (TileEntity tileEntity : tileEntityList) {
IChunkProvider chunkProvider = world.getChunkProvider();
for (TileEntity tileEntity : tileEntityList) {
try {
if (!tileEntity.isInvalid()) {
// TODO: Lock this chunk, and if this entity is on a boundary, that chunk.
tileEntity.updateEntity();
}
if (tileEntity.isInvalid()) {
manager.remove(tileEntity);
Log.warning("Removed invalid tile: " + tileEntity.xCoord + ", " + tileEntity.yCoord + ", " + tileEntity.zCoord + "\ttype:" + tileEntity.getClass().toString());
Expand All @@ -31,16 +35,14 @@ public T call() {
chunk.cleanChunkBlockTileEntity(tileEntity.xCoord & 0xf, tileEntity.yCoord, tileEntity.zCoord & 0xf);
}
}
} else {
tileEntity.updateEntity();
}
if (manager.getHashCode(tileEntity) != hashCode) {
} else if (manager.getHashCode(tileEntity) != hashCode) {
manager.remove(tileEntity);
manager.add(tileEntity);
}
} catch (Exception exception) {
Log.severe("Exception during tile entity tick ");
Log.severe("Tick region: " + identifier + ":", exception);
}
} catch (Exception exception) {
Log.severe("Exception during tile entity tick at " + identifier + ":", exception);
}
return null;
}
Expand Down

0 comments on commit f322c36

Please sign in to comment.