del nullresource

v5stable
Ondřej Hruška 10 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.control.AppAccess;
import mightypork.gamecore.control.AppAdapter;
import mightypork.util.logging.Log;
/**
@ -18,10 +17,6 @@ import mightypork.util.logging.Log;
*/
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, LoopPlayer> loops = new HashMap<>();
@ -76,8 +71,7 @@ public class SoundBank extends AppAdapter {
{
final LoopPlayer p = loops.get(key);
if (p == null) {
Log.w("Requesting unknown sound loop \"" + key + "\".");
return NULL_LOOP;
throw new RuntimeException("Unknown sound loop \"" + key + "\".");
}
return p;
}
@ -93,8 +87,7 @@ public class SoundBank extends AppAdapter {
{
final EffectPlayer p = effects.get(key);
if (p == null) {
Log.w("Requesting unknown sound effect \"" + key + "\".");
return NULL_EFFECT;
throw new RuntimeException("Unknown sound effect \"" + key + "\".");
}
return p;
}

@ -64,7 +64,6 @@ public class AsyncResourceLoader extends Thread implements ResourceLoadRequest.L
public void loadResource(final Deferred 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)) {

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