73a4a02aa1
- Tiles are initialized after being constructed which makes life simpler for custom tiles which no longer have to have their own constructor that passes Tile's stuff down to it. - Tiles are no longer LRU cached (because we blow through that cache instantly on all but the smallest of scenes), and are now tracked by weak references so that we guarantee that only one instance of a tile is ever in memory. - Added code to track and report memory usage of weak cached tiles as well as "stray" tiles which are created through other means than asking a TileSet for a tile (fringe tiles being the most prolific example). git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@2628 542714f4-19e9-0310-aa3c-eee0fc999fb1
121 lines
3.4 KiB
Java
121 lines
3.4 KiB
Java
//
|
|
// $Id: SceneBlockResolver.java,v 1.9 2003/05/31 00:56:38 mdb Exp $
|
|
|
|
package com.threerings.miso.client;
|
|
|
|
import java.awt.EventQueue;
|
|
|
|
import com.samskivert.util.Histogram;
|
|
import com.samskivert.util.LoopingThread;
|
|
import com.samskivert.util.Queue;
|
|
|
|
import com.threerings.miso.Log;
|
|
|
|
/**
|
|
* A separate thread for resolving miso scene blocks.
|
|
*/
|
|
public class SceneBlockResolver extends LoopingThread
|
|
{
|
|
/**
|
|
* Queues up a scene block for resolution.
|
|
*/
|
|
public void resolveBlock (SceneBlock block, boolean hipri)
|
|
{
|
|
Log.debug("Queueing block for resolution " + block +
|
|
" (" + hipri + ").");
|
|
if (hipri) {
|
|
_queue.prepend(block);
|
|
} else {
|
|
_queue.append(block);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Temporarily suspends the scene block resolution thread.
|
|
*/
|
|
public synchronized void suspendResolution ()
|
|
{
|
|
_resolving = false;
|
|
}
|
|
|
|
/**
|
|
* Restores the operation of the scene block resolution thread after a
|
|
* previous call to {@link #suspendResolution}.
|
|
*/
|
|
public synchronized void restoreResolution ()
|
|
{
|
|
_resolving = true;
|
|
notify();
|
|
}
|
|
|
|
/**
|
|
* Returns the number of scene blocks on the resolution queue.
|
|
*/
|
|
public int queueSize ()
|
|
{
|
|
return _queue.size();
|
|
}
|
|
|
|
// documentation inherited
|
|
public void iterate ()
|
|
{
|
|
final SceneBlock block = (SceneBlock)_queue.get();
|
|
|
|
while (!_resolving) {
|
|
synchronized (this) {
|
|
try {
|
|
wait();
|
|
} catch (InterruptedException ie) {
|
|
Log.info("Resolver interrupted.");
|
|
}
|
|
}
|
|
}
|
|
|
|
try {
|
|
long start = System.currentTimeMillis();
|
|
Log.debug("Resolving block " + block + ".");
|
|
if (block.resolve()) {
|
|
Log.debug("Resolved block " + block + ".");
|
|
}
|
|
long elapsed = System.currentTimeMillis() - start;
|
|
_histo.addValue((int)elapsed);
|
|
|
|
// warn if a block takes a long time to resolve
|
|
if (elapsed > LONG_RESOLVE_TIME) {
|
|
Log.warning("Block took long time to resolve [block=" + block +
|
|
", elapsed=" + elapsed + "ms].");
|
|
}
|
|
|
|
// queue it up on the AWT thread to complete its resolution
|
|
final boolean report = (_queue.size() == 0);
|
|
EventQueue.invokeLater(new Runnable() {
|
|
public void run () {
|
|
// let the block's panel know that it is resolved
|
|
block.wasResolved();
|
|
// report statistics
|
|
// if (report) {
|
|
// Log.info("Resolution histogram " +
|
|
// _histo.summarize() + ".");
|
|
// }
|
|
}
|
|
});
|
|
|
|
} catch (Exception e) {
|
|
Log.warning("Block failed during resolution " + block + ".");
|
|
Log.logStackTrace(e);
|
|
}
|
|
}
|
|
|
|
/** The invoker's queue of units to be executed. */
|
|
protected Queue _queue = new Queue();
|
|
|
|
/** Indicates whether or not we are resolving or suspended. */
|
|
protected boolean _resolving = true;
|
|
|
|
/** Used to time block loading. */
|
|
protected Histogram _histo = new Histogram(0, 25, 100);
|
|
|
|
/** Blocks shouldn't take too long to resolve. */
|
|
protected static final long LONG_RESOLVE_TIME = 500L;
|
|
}
|