Fixed concurrency issue with loading queue in main loop.

v5stable
Ondřej Hruška 11 years ago
parent e03d547fab
commit 94f0b4c3e4
  1. 2
      src/mightypork/gamecore/audio/DeferredAudio.java
  2. 5
      src/mightypork/gamecore/control/BaseApp.java
  3. 42
      src/mightypork/gamecore/loading/AsyncResourceLoader.java
  4. 6
      src/mightypork/gamecore/loading/BaseDeferredResource.java
  5. 2
      src/mightypork/gamecore/render/fonts/DeferredFont.java
  6. 2
      src/mightypork/gamecore/render/textures/DeferredTexture.java
  7. 2
      src/mightypork/utils/logging/LogInstance.java

@ -86,7 +86,7 @@ public class DeferredAudio extends BaseDeferredResource {
@Override
protected void loadResource(String resource) throws IOException
protected synchronized final void loadResource(String resource) throws IOException
{
final String ext = FileUtils.getExtension(resource);

@ -43,7 +43,6 @@ public abstract class BaseApp implements AppAccess {
*/
public void start()
{
Log.i("Commencing initialization sequence...");
initialize();
@ -70,7 +69,7 @@ public abstract class BaseApp implements AppAccess {
org.newdawn.slick.util.Log.setLogSystem(new SlickLogRedirector(log));
// only here it makes sense to log.
Log.f1("Initializing subsystems...");
Log.i("=== Commencing initialization sequence ===");
/*
* Event bus
@ -128,7 +127,7 @@ public abstract class BaseApp implements AppAccess {
initScreens(screenRegistry);
postInit();
Log.i("Initialized sequence completed.");
Log.i("=== Initialized sequence completed ===");
}

@ -39,8 +39,28 @@ public class AsyncResourceLoader extends Thread implements ResourceLoadRequest.L
@Override
public void loadResource(DeferredResource resource)
public void loadResource(final DeferredResource resource)
{
if (resource.isLoaded()) return;
if (resource instanceof NullResource) return;
// textures & fonts needs to be loaded in main thread
if (resource.getClass().isAnnotationPresent(MustLoadInMainThread.class)) {
Log.f3("<LOADER> Delegating to main thread:\n " + Log.str(resource));
app.getEventBus().send(new MainLoopTaskRequest(new Runnable() {
@Override
public void run()
{
resource.load();
}
}));
return;
}
toLoad.add(resource);
}
@ -58,26 +78,6 @@ public class AsyncResourceLoader extends Thread implements ResourceLoadRequest.L
if (!def.isLoaded()) {
// skip nulls
if (def instanceof NullResource) continue;
// textures & fonts needs to be loaded in main thread
if (def.getClass().isAnnotationPresent(MustLoadInMainThread.class)) {
Log.f3("<LOADER> Delegating to main thread:\n " + Log.str(def));
app.getEventBus().send(new MainLoopTaskRequest(new Runnable() {
@Override
public void run()
{
def.load();
}
}));
continue;
}
Log.f3("<LOADER> Loading async:\n " + Log.str(def));
exs.submit(new Runnable() {

@ -31,7 +31,8 @@ public abstract class BaseDeferredResource implements DeferredResource, Destroya
{
if (loadAttempted) {
Log.w("<RES> Already loaded @ load():\n " + this);
return;
(new IllegalStateException()).printStackTrace();
//return;
}
loadAttempted = true;
@ -55,7 +56,7 @@ public abstract class BaseDeferredResource implements DeferredResource, Destroya
@Override
public final boolean isLoaded()
public synchronized final boolean isLoaded()
{
if (isNull()) return false;
@ -76,6 +77,7 @@ public abstract class BaseDeferredResource implements DeferredResource, Destroya
return true;
} else {
Log.w("<RES> First use, not loaded yet - loading directly\n " + this);
(new IllegalStateException()).printStackTrace();
load();
}

@ -87,7 +87,7 @@ public class DeferredFont extends BaseDeferredResource implements GLFont {
@Override
protected final void loadResource(String path) throws FontFormatException, IOException
protected synchronized final void loadResource(String path) throws FontFormatException, IOException
{
final Font awtFont = getAwtFont(path, (float) size, style.numval);

@ -38,7 +38,7 @@ public class DeferredTexture extends BaseDeferredResource implements FilteredTex
@Override
protected void loadResource(String path)
protected synchronized void loadResource(String path)
{
backingTexture = Render.loadTexture(path);
}

@ -104,7 +104,7 @@ public class LogInstance {
logger.setUseParentHandlers(false);
logger.setLevel(Level.ALL);
final String stamp = (new SimpleDateFormat("yyyy/MM/dd HH:mm:ss")).format(new Date());
i("= Logger \"" + name + "\" initialized =\n" + stamp);
i("Logger \"" + name + "\" initialized.\n" + stamp);
}

Loading…
Cancel
Save