del nullresource

v5stable
Ondřej Hruška 11 years ago
parent e773a5307a
commit 067f8b172c
  1. 24
      src/mightypork/gamecore/audio/NullAudio.java
  2. 11
      src/mightypork/gamecore/audio/SoundBank.java
  3. 1
      src/mightypork/gamecore/loading/AsyncResourceLoader.java
  4. 6
      src/mightypork/gamecore/loading/DeferredResource.java
  5. 12
      src/mightypork/gamecore/loading/NullResource.java

@ -1,24 +0,0 @@
package mightypork.gamecore.audio;
import mightypork.gamecore.loading.NullResource;
import mightypork.util.logging.LogAlias;
/**
* Placeholder for cases where no matching audio is found and
* {@link NullPointerException} has to be avoided.
*
* @author MightyPork
*/
@LogAlias(name = "NullAudio")
public class NullAudio extends DeferredAudio implements NullResource {
/**
* new null audio
*/
public NullAudio()
{
super(null);
}
}

@ -8,7 +8,6 @@ import mightypork.gamecore.audio.players.EffectPlayer;
import mightypork.gamecore.audio.players.LoopPlayer; import mightypork.gamecore.audio.players.LoopPlayer;
import mightypork.gamecore.control.AppAccess; import mightypork.gamecore.control.AppAccess;
import mightypork.gamecore.control.AppAdapter; import mightypork.gamecore.control.AppAdapter;
import mightypork.util.logging.Log;
/** /**
@ -18,10 +17,6 @@ import mightypork.util.logging.Log;
*/ */
public class SoundBank extends AppAdapter { public class SoundBank extends AppAdapter {
private static final DeferredAudio NO_SOUND = new NullAudio();
private static final LoopPlayer NULL_LOOP = new LoopPlayer(NO_SOUND, 0, 0, null);
private static final EffectPlayer NULL_EFFECT = new EffectPlayer(NO_SOUND, 0, 0, null);
private final Map<String, EffectPlayer> effects = new HashMap<>(); private final Map<String, EffectPlayer> effects = new HashMap<>();
private final Map<String, LoopPlayer> loops = new HashMap<>(); private final Map<String, LoopPlayer> loops = new HashMap<>();
@ -76,8 +71,7 @@ public class SoundBank extends AppAdapter {
{ {
final LoopPlayer p = loops.get(key); final LoopPlayer p = loops.get(key);
if (p == null) { if (p == null) {
Log.w("Requesting unknown sound loop \"" + key + "\"."); throw new RuntimeException("Unknown sound loop \"" + key + "\".");
return NULL_LOOP;
} }
return p; return p;
} }
@ -93,8 +87,7 @@ public class SoundBank extends AppAdapter {
{ {
final EffectPlayer p = effects.get(key); final EffectPlayer p = effects.get(key);
if (p == null) { if (p == null) {
Log.w("Requesting unknown sound effect \"" + key + "\"."); throw new RuntimeException("Unknown sound effect \"" + key + "\".");
return NULL_EFFECT;
} }
return p; return p;
} }

@ -64,7 +64,6 @@ public class AsyncResourceLoader extends Thread implements ResourceLoadRequest.L
public void loadResource(final Deferred resource) public void loadResource(final Deferred resource)
{ {
if (resource.isLoaded()) return; if (resource.isLoaded()) return;
if (resource instanceof NullResource) return;
// textures & fonts needs to be loaded in main thread // textures & fonts needs to be loaded in main thread
if (resource.getClass().isAnnotationPresent(MustLoadInMainThread.class)) { if (resource.getClass().isAnnotationPresent(MustLoadInMainThread.class)) {

@ -7,9 +7,7 @@ import mightypork.util.logging.LogAlias;
/** /**
* Deferred resource abstraction.<br> * Deferred resource abstraction.
* Resources implementing {@link NullResource} will be treated as fake and not
* attempted to load.
* *
* @author MightyPork * @author MightyPork
*/ */
@ -42,8 +40,6 @@ public abstract class DeferredResource implements Deferred, Destroyable {
loadFailed = false; loadFailed = false;
if (this instanceof NullResource) return; // don't even try
try { try {
if (resource == null) { if (resource == null) {
throw new NullPointerException("Resource string cannot be null for non-null resource."); throw new NullPointerException("Resource string cannot be null for non-null resource.");

@ -1,12 +0,0 @@
package mightypork.gamecore.loading;
/**
* Resource that is used as a placeholder instead of an actual resource; this
* resource should not be attempted to be loaded.
*
* @author MightyPork
*/
public interface NullResource {
}
Loading…
Cancel
Save