From fc3afd1d6460b2aa453167498979bbf7a636ef45 Mon Sep 17 00:00:00 2001 From: Starla Insigna Date: Thu, 19 Mar 2009 22:58:24 -0400 Subject: Engine: Fixed many potential bugs Identified by FindBugs. http://findbugs.sourceforge.net/ --- src/com/fourisland/fourpuzzle/Display.java | 12 +++++--- .../fourisland/fourpuzzle/PuzzleApplication.java | 18 +++++------- src/com/fourisland/fourpuzzle/SaveFile.java | 8 +++-- .../fourpuzzle/gamestate/mapview/ChipSet.java | 2 +- .../gamestate/mapview/MapViewGameState.java | 4 +-- .../gamestate/mapview/event/AnimationType.java | 6 ++-- .../gamestate/mapview/event/CommonEvent.java | 6 ++-- .../gamestate/mapview/event/EventHandler.java | 4 +-- .../gamestate/mapview/event/EventList.java | 34 +++++++++++++++++++++- .../gamestate/mapview/event/HeroEvent.java | 30 ++++++++++++++++++- .../gamestate/mapview/event/ImmutableEvent.java | 2 +- .../gamestate/mapview/event/SpecialEvent.java | 2 +- .../mapview/event/movement/CustomMovementType.java | 3 +- .../specialmove/LoopUntilCollisionMoveEvent.java | 3 +- .../mapview/event/specialmove/MoveEventThread.java | 3 +- .../mapview/viewpoint/MovingViewpoint.java | 2 +- .../mapview/viewpoint/ShakingViewpoint.java | 2 +- .../fourpuzzle/transition/SlideTransition.java | 2 +- src/com/fourisland/fourpuzzle/util/Interval.java | 13 ++++++++- src/com/fourisland/fourpuzzle/util/MidiParser.java | 2 +- .../fourisland/fourpuzzle/util/ObjectLoader.java | 10 +++---- src/com/fourisland/fourpuzzle/util/PauseTimer.java | 4 +-- .../fourisland/fourpuzzle/window/ChoiceWindow.java | 8 ++--- src/com/fourisland/fourpuzzle/window/Window.java | 2 +- 24 files changed, 128 insertions(+), 54 deletions(-) (limited to 'src/com') diff --git a/src/com/fourisland/fourpuzzle/Display.java b/src/com/fourisland/fourpuzzle/Display.java index c8d17d9..b7569aa 100755 --- a/src/com/fourisland/fourpuzzle/Display.java +++ b/src/com/fourisland/fourpuzzle/Display.java @@ -42,8 +42,7 @@ import org.jdesktop.application.ResourceMap; */ public class Display { - public static int tileAnimationFrame = 0; - + private static int tileAnimationFrame = 0; private static List renderables = new CopyOnWriteArrayList(); public static void render(Component gameFrame) @@ -229,10 +228,10 @@ public class Display { return; } catch (RuntimeException ex) { - PuzzleApplication.INSTANCE.reportError(ex); + PuzzleApplication.reportError(ex); } catch (Error ex) { - PuzzleApplication.INSTANCE.reportError(ex); + PuzzleApplication.reportError(ex); } } }; @@ -331,4 +330,9 @@ public class Display { return cachePoint; } + public int getTileAnimationFrame() + { + return tileAnimationFrame; + } + } diff --git a/src/com/fourisland/fourpuzzle/PuzzleApplication.java b/src/com/fourisland/fourpuzzle/PuzzleApplication.java index f88b0ad..88236f9 100755 --- a/src/com/fourisland/fourpuzzle/PuzzleApplication.java +++ b/src/com/fourisland/fourpuzzle/PuzzleApplication.java @@ -28,10 +28,8 @@ import org.jdesktop.application.Application; */ public class PuzzleApplication extends Application { - public static PuzzleApplication INSTANCE; - public static boolean debugSpeed = false; - public static boolean stretchScreen = true; - public static boolean gameSleep = false; + private static boolean stretchScreen = true; + private static boolean gameSleep = false; private static JDialog gameDialog = new JDialog(new JFrame(), false); private static Semaphore gameDialogHandler = new Semaphore(1); @@ -101,9 +99,9 @@ public class PuzzleApplication extends Application { { /* If debug mode is enabled, holding Shift down should put * the game into hyperactive mode */ - if (INSTANCE.getContext().getResourceMap().getBoolean("debugMode")) + if (getInstance().getContext().getResourceMap().getBoolean("debugMode")) { - debugSpeed = true; + Interval.setDebugSpeed(true); } } else if (e.getKeyCode() == KeyEvent.VK_F12) { @@ -125,7 +123,7 @@ public class PuzzleApplication extends Application { if (e.getKeyCode() == KeyEvent.VK_SHIFT) { // If Shift is let go of, hyperactive mode should end - debugSpeed = false; + Interval.setDebugSpeed(false); } else { KeyboardInput.getKey().letGo(); } @@ -140,8 +138,6 @@ public class PuzzleApplication extends Application { @Override protected void startup() { - INSTANCE = this; - // Create the game form initGameDialog(true); @@ -197,10 +193,10 @@ public class PuzzleApplication extends Application { public String getGamePackage() { - return INSTANCE.getContext().getResourceMap().getString("Application.package"); + return getInstance().getContext().getResourceMap().getString("Application.package"); } - public void reportError(Throwable ex) + public static void reportError(Throwable ex) { if ((ex instanceof Exception) && !(ex instanceof RuntimeException)) { diff --git a/src/com/fourisland/fourpuzzle/SaveFile.java b/src/com/fourisland/fourpuzzle/SaveFile.java index 44b3cdd..7a9c6cf 100755 --- a/src/com/fourisland/fourpuzzle/SaveFile.java +++ b/src/com/fourisland/fourpuzzle/SaveFile.java @@ -23,6 +23,8 @@ import java.util.logging.Logger; */ public class SaveFile implements Serializable { + private static final long serialVersionUID = 234503257; + /** * Creates a new SaveFile */ @@ -31,7 +33,7 @@ public class SaveFile implements Serializable { switches = new HashMap(); party = Database.createParty(); variables = new HashMap(); - currentMap = new String(); + currentMap = ""; hero = new HeroEvent(); } @@ -43,7 +45,7 @@ public class SaveFile implements Serializable { */ public SaveFile(int file) throws IOException { - InputStream is = PuzzleApplication.INSTANCE.getContext().getLocalStorage().openInputFile("Save" + file + ".sav"); + InputStream is = PuzzleApplication.getInstance().getContext().getLocalStorage().openInputFile("Save" + file + ".sav"); ObjectInputStream ois = new ObjectInputStream(is); SaveFile temp = null; try { @@ -63,7 +65,7 @@ public class SaveFile implements Serializable { public void saveGame(int file) throws IOException { - OutputStream os = PuzzleApplication.INSTANCE.getContext().getLocalStorage().openOutputFile("Save" + file + ".sav"); + OutputStream os = PuzzleApplication.getInstance().getContext().getLocalStorage().openOutputFile("Save" + file + ".sav"); ObjectOutputStream oos = new ObjectOutputStream(os); oos.writeObject(this); oos.close(); diff --git a/src/com/fourisland/fourpuzzle/gamestate/mapview/ChipSet.java b/src/com/fourisland/fourpuzzle/gamestate/mapview/ChipSet.java index a4d7ac3..e6af66d 100755 --- a/src/com/fourisland/fourpuzzle/gamestate/mapview/ChipSet.java +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/ChipSet.java @@ -52,7 +52,7 @@ public class ChipSet { public static void initalize(String name) { - ResourceMap rm = PuzzleApplication.INSTANCE.getContext().getResourceManager().getResourceMap(); + ResourceMap rm = PuzzleApplication.getInstance().getContext().getResourceManager().getResourceMap(); InputStream cs = null; if (rm.getClassLoader().getResource(rm.getResourcesDir() + "chipset/" + name + ".tsx") == null) diff --git a/src/com/fourisland/fourpuzzle/gamestate/mapview/MapViewGameState.java b/src/com/fourisland/fourpuzzle/gamestate/mapview/MapViewGameState.java index 89fac99..d3bd101 100755 --- a/src/com/fourisland/fourpuzzle/gamestate/mapview/MapViewGameState.java +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/MapViewGameState.java @@ -83,7 +83,7 @@ public class MapViewGameState implements GameState { * walkthrough flag so the Hero can walk through stuff */ if (key.isCtrlDown() && !debugWalkthrough) { - if (PuzzleApplication.INSTANCE.getContext().getResourceMap().getBoolean("debugMode")) + if (PuzzleApplication.getInstance().getContext().getResourceMap().getBoolean("debugMode")) { debugWalkthrough = true; } @@ -188,7 +188,7 @@ public class MapViewGameState implements GameState { { /* If debug mode is enabled and F11 is pressed, cancel any running * events */ - if ((key.getKey() == KeyEvent.VK_F11) && (PuzzleApplication.INSTANCE.getContext().getResourceMap().getBoolean("debugMode"))) + if ((key.getKey() == KeyEvent.VK_F11) && (PuzzleApplication.getInstance().getContext().getResourceMap().getBoolean("debugMode"))) { for (LayerEvent ev : currentMap.getEvents()) { diff --git a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/AnimationType.java b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/AnimationType.java index 76582e3..55dc6d0 100755 --- a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/AnimationType.java +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/AnimationType.java @@ -26,7 +26,7 @@ public enum AnimationType { */ CommonWithStepping(true, true) { - Interval in = Interval.createTickInterval(2); + transient Interval in = Interval.createTickInterval(2); @Override public void tick(PossibleEvent pe) @@ -56,7 +56,7 @@ public enum AnimationType { */ TurnLeft(true, true) { - Interval in = Interval.createTickInterval(2); + transient Interval in = Interval.createTickInterval(2); @Override public void tick(PossibleEvent pe) @@ -73,7 +73,7 @@ public enum AnimationType { */ TurnRight(true, true) { - Interval in = Interval.createTickInterval(2); + transient Interval in = Interval.createTickInterval(2); @Override public void tick(PossibleEvent pe) diff --git a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/CommonEvent.java b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/CommonEvent.java index edfdb8f..9c5bf14 100755 --- a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/CommonEvent.java +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/CommonEvent.java @@ -51,11 +51,13 @@ public class CommonEvent { this.callback = callback; } - public EventCallTime getCalltime() { + public EventCallTime getCalltime() + { return calltime; } - public void setCalltime(EventCallTime calltime) { + public void setCalltime(EventCallTime calltime) + { this.calltime = calltime; } diff --git a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/EventHandler.java b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/EventHandler.java index e24b79c..9cb67ba 100755 --- a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/EventHandler.java +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/EventHandler.java @@ -59,10 +59,10 @@ public class EventHandler { * Also reset the viewpoint in case the viewpoint was * fixed during the thread */ - SpecialEvent.mapView.setViewpoint(new AutomaticViewpoint(SpecialEvent.mapView.getCurrentMap())); + new SpecialEvent().ResetViewpoint(); } catch (ResourceNotFoundException ex) { - PuzzleApplication.INSTANCE.reportError(ex); + PuzzleApplication.reportError(ex); } } }; diff --git a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/EventList.java b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/EventList.java index 7120a91..d790195 100755 --- a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/EventList.java +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/EventList.java @@ -14,6 +14,8 @@ import java.util.Vector; */ public class EventList extends Vector { + private static final long serialVersionUID = 765438545; + public EventList(Map parentMap) { setParentMap(parentMap); @@ -62,7 +64,7 @@ public class EventList extends Vector { return super.add(o); } - private Map parentMap = null; + private transient Map parentMap = null; public Map getParentMap() { return parentMap; @@ -77,4 +79,34 @@ public class EventList extends Vector { } } + @Override + public int hashCode() + { + int hash = 3; + hash = 59 * hash + (this.parentMap != null ? this.parentMap.hashCode() : 0); + return hash; + } + + @Override + public boolean equals(Object obj) + { + if (obj == null) + { + return false; + } + + if (getClass() != obj.getClass()) + { + return false; + } + + final EventList other = (EventList) obj; + if (this.parentMap != other.parentMap && (this.parentMap == null || !this.parentMap.equals(other.parentMap))) + { + return false; + } + + return true; + } + } diff --git a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/HeroEvent.java b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/HeroEvent.java index 5db87a0..1f5607e 100755 --- a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/HeroEvent.java +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/HeroEvent.java @@ -14,12 +14,18 @@ import com.fourisland.fourpuzzle.database.GameCharacter; import com.fourisland.fourpuzzle.gamestate.mapview.Map; import com.fourisland.fourpuzzle.gamestate.mapview.MapViewGameState; import com.fourisland.fourpuzzle.gamestate.mapview.event.graphic.BlankEventGraphic; +import java.io.IOException; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; +import java.io.Serializable; /** * * @author hatkirby */ -public class HeroEvent extends AbstractEvent implements Event { +public class HeroEvent extends AbstractEvent implements Event, Serializable { + + private static final long serialVersionUID = 402340890; public HeroEvent() { @@ -73,5 +79,27 @@ public class HeroEvent extends AbstractEvent implements Event { { return ((MapViewGameState) Game.getGameState()).getCurrentMap(); } + + /** + * Serialize this HeroEvent instance + * + * When serializing a HeroEvent, the only information that is really + * necessary is the Hero's location and direction, because all other + * important information is serialized by SaveFile. + * + * @serialData The Hero's location (as a Point object) is emitted, followed + * by the a Direction object representing the Hero's direction. + */ + private void writeObject(ObjectOutputStream s) throws IOException + { + s.writeObject(getLocation()); + s.writeObject(getDirection()); + } + + private void readObject(ObjectInputStream s) throws IOException, ClassNotFoundException + { + setLocation((Point) s.readObject()); + setDirection((Direction) s.readObject()); + } } diff --git a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/ImmutableEvent.java b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/ImmutableEvent.java index b722b68..7bd0c42 100644 --- a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/ImmutableEvent.java +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/ImmutableEvent.java @@ -26,7 +26,7 @@ public final class ImmutableEvent public String getLabel() { - return new String(ev.getLabel()); + return ev.getLabel(); } public Point getLocation() diff --git a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/SpecialEvent.java b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/SpecialEvent.java index 2db33f7..30db7a2 100755 --- a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/SpecialEvent.java +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/SpecialEvent.java @@ -30,7 +30,7 @@ import java.util.concurrent.CountDownLatch; */ public class SpecialEvent { - protected static MapViewGameState mapView = null; + private static MapViewGameState mapView = null; public static void setMapView(MapViewGameState mapView) { SpecialEvent.mapView = mapView; diff --git a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/movement/CustomMovementType.java b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/movement/CustomMovementType.java index 78dd991..a63feda 100755 --- a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/movement/CustomMovementType.java +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/movement/CustomMovementType.java @@ -7,6 +7,7 @@ package com.fourisland.fourpuzzle.gamestate.mapview.event.movement; import com.fourisland.fourpuzzle.Direction; import com.fourisland.fourpuzzle.gamestate.mapview.event.ImmutableEvent; +import java.util.Arrays; /** * CustomMovementEvent takes an array of Directions and directions the event @@ -22,7 +23,7 @@ public class CustomMovementType implements MovementType { public CustomMovementType(Direction[] moves) { - this.moves = moves; + this.moves = Arrays.copyOf(moves, moves.length); } public Direction nextMovement(ImmutableEvent ev) diff --git a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/specialmove/LoopUntilCollisionMoveEvent.java b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/specialmove/LoopUntilCollisionMoveEvent.java index 02744d0..daceffd 100755 --- a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/specialmove/LoopUntilCollisionMoveEvent.java +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/specialmove/LoopUntilCollisionMoveEvent.java @@ -7,6 +7,7 @@ package com.fourisland.fourpuzzle.gamestate.mapview.event.specialmove; import com.fourisland.fourpuzzle.gamestate.mapview.event.Event; import java.awt.Point; +import java.util.Arrays; /** * LoopUntilCollisionMoveEvent takes an array of MoveEvents and repeatedly @@ -24,7 +25,7 @@ public class LoopUntilCollisionMoveEvent implements MoveEvent { public LoopUntilCollisionMoveEvent(MoveEvent[] moves) { - this.moves = moves; + this.moves = Arrays.copyOf(moves, moves.length); } public void doAction(Event ev) diff --git a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/specialmove/MoveEventThread.java b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/specialmove/MoveEventThread.java index d05a3d8..dae49cb 100755 --- a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/specialmove/MoveEventThread.java +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/specialmove/MoveEventThread.java @@ -9,6 +9,7 @@ import com.fourisland.fourpuzzle.Game; import com.fourisland.fourpuzzle.gamestate.mapview.event.Event; import com.fourisland.fourpuzzle.gamestate.mapview.event.LayerEvent; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import java.util.Vector; import java.util.concurrent.ExecutorService; @@ -34,7 +35,7 @@ public class MoveEventThread implements Runnable { public MoveEventThread(Event ev, MoveEvent[] actions) { this.ev = ev; - this.actions = actions; + this.actions = Arrays.copyOf(actions, actions.length); } public void start() diff --git a/src/com/fourisland/fourpuzzle/gamestate/mapview/viewpoint/MovingViewpoint.java b/src/com/fourisland/fourpuzzle/gamestate/mapview/viewpoint/MovingViewpoint.java index e6db32b..edaa580 100755 --- a/src/com/fourisland/fourpuzzle/gamestate/mapview/viewpoint/MovingViewpoint.java +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/viewpoint/MovingViewpoint.java @@ -39,7 +39,7 @@ public class MovingViewpoint implements Viewpoint { this.sy = sy; this.dx = dx; this.dy = dy; - this.speed = length / Game.FPS; + this.speed = length / (double) Game.FPS; this.xdist = dx - sx; this.ydist = dy - sy; this.callback = callback; diff --git a/src/com/fourisland/fourpuzzle/gamestate/mapview/viewpoint/ShakingViewpoint.java b/src/com/fourisland/fourpuzzle/gamestate/mapview/viewpoint/ShakingViewpoint.java index f2b40e7..80d36b3 100644 --- a/src/com/fourisland/fourpuzzle/gamestate/mapview/viewpoint/ShakingViewpoint.java +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/viewpoint/ShakingViewpoint.java @@ -28,7 +28,7 @@ public class ShakingViewpoint implements Viewpoint { this.length = length; this.x = x; this.y = y; - this.in = Interval.createMillisInterval(1000 / speed.getSpeed()); + this.in = Interval.createMillisInterval(1000F / speed.getSpeed()); this.speed = speed; this.callback = callback; this.start = System.currentTimeMillis(); diff --git a/src/com/fourisland/fourpuzzle/transition/SlideTransition.java b/src/com/fourisland/fourpuzzle/transition/SlideTransition.java index aa91061..c7b7ad2 100755 --- a/src/com/fourisland/fourpuzzle/transition/SlideTransition.java +++ b/src/com/fourisland/fourpuzzle/transition/SlideTransition.java @@ -42,7 +42,7 @@ public class SlideTransition implements MultidirectionalTransition { way = SlideDirection.SideToSide; } - wait = Math.round(max / (Game.FPS/2)); + wait = max / (Game.FPS/2); } public TransitionDirection getDirection() diff --git a/src/com/fourisland/fourpuzzle/util/Interval.java b/src/com/fourisland/fourpuzzle/util/Interval.java index 1e5e8f3..0b0125d 100755 --- a/src/com/fourisland/fourpuzzle/util/Interval.java +++ b/src/com/fourisland/fourpuzzle/util/Interval.java @@ -33,7 +33,7 @@ public class Interval { private long last = System.nanoTime(); public boolean isElapsed() { - if (PuzzleApplication.debugSpeed) + if (Interval.getDebugSpeed()) { return true; } @@ -47,5 +47,16 @@ public class Interval { return false; } + + private static boolean debugSpeed = false; + public static void setDebugSpeed(boolean debugSpeed) + { + Interval.debugSpeed = debugSpeed; + } + + public static boolean getDebugSpeed() + { + return debugSpeed; + } } diff --git a/src/com/fourisland/fourpuzzle/util/MidiParser.java b/src/com/fourisland/fourpuzzle/util/MidiParser.java index 3d6c06b..408ea75 100644 --- a/src/com/fourisland/fourpuzzle/util/MidiParser.java +++ b/src/com/fourisland/fourpuzzle/util/MidiParser.java @@ -27,7 +27,7 @@ public class MidiParser { public Sequence parse() throws InvalidMidiDataException { - Sequence temp = temp = new Sequence(seq.getDivisionType(), seq.getResolution()); + Sequence temp = new Sequence(seq.getDivisionType(), seq.getResolution()); for (Track t : seq.getTracks()) { diff --git a/src/com/fourisland/fourpuzzle/util/ObjectLoader.java b/src/com/fourisland/fourpuzzle/util/ObjectLoader.java index f1cb157..efeec7e 100755 --- a/src/com/fourisland/fourpuzzle/util/ObjectLoader.java +++ b/src/com/fourisland/fourpuzzle/util/ObjectLoader.java @@ -55,7 +55,7 @@ public class ObjectLoader { { if (!imageCache.containsKey(type + "/" + name)) { - ResourceMap rm = PuzzleApplication.INSTANCE.getContext().getResourceManager().getResourceMap(); + ResourceMap rm = PuzzleApplication.getInstance().getContext().getResourceManager().getResourceMap(); String filename = getFilename(type, name, "png"); InputStream str = rm.getClassLoader().getResourceAsStream(filename); BufferedImage bImg = null; @@ -75,7 +75,7 @@ public class ObjectLoader { { if (!imageCache.containsKey(type + "/" + name)) { - ResourceMap rm = PuzzleApplication.INSTANCE.getContext().getResourceManager().getResourceMap(); + ResourceMap rm = PuzzleApplication.getInstance().getContext().getResourceManager().getResourceMap(); String filename = getFilename(type, name, "png"); InputStream str = rm.getClassLoader().getResourceAsStream(filename); BufferedImage bImg = null; @@ -107,7 +107,7 @@ public class ObjectLoader { { if (!musicCache.containsKey(name)) { - ResourceMap rm = PuzzleApplication.INSTANCE.getContext().getResourceManager().getResourceMap(); + ResourceMap rm = PuzzleApplication.getInstance().getContext().getResourceManager().getResourceMap(); String filename = getFilename("Music", name, "mid"); InputStream str = rm.getClassLoader().getResourceAsStream(filename); Sequence seq = null; @@ -136,7 +136,7 @@ public class ObjectLoader { { if (!soundCache.containsKey("Sound/" + name)) { - ResourceMap rm = PuzzleApplication.INSTANCE.getContext().getResourceManager().getResourceMap(); + ResourceMap rm = PuzzleApplication.getInstance().getContext().getResourceManager().getResourceMap(); String filename = getFilename("Sound", name, "wav"); InputStream soundFile = rm.getClassLoader().getResourceAsStream(filename); AudioInputStream ais = null; @@ -173,7 +173,7 @@ public class ObjectLoader { public static String getFilename(String type, String name, String ex) { - ResourceMap rm = PuzzleApplication.INSTANCE.getContext().getResourceManager().getResourceMap(); + ResourceMap rm = PuzzleApplication.getInstance().getContext().getResourceManager().getResourceMap(); String f = rm.getResourcesDir() + type.toLowerCase() + "/" + name + "." + ex; URL fu = rm.getClassLoader().getResource(f); diff --git a/src/com/fourisland/fourpuzzle/util/PauseTimer.java b/src/com/fourisland/fourpuzzle/util/PauseTimer.java index f26f105..c3df5df 100644 --- a/src/com/fourisland/fourpuzzle/util/PauseTimer.java +++ b/src/com/fourisland/fourpuzzle/util/PauseTimer.java @@ -5,8 +5,6 @@ package com.fourisland.fourpuzzle.util; -import com.fourisland.fourpuzzle.PuzzleApplication; - /** * * @author hatkirby @@ -22,7 +20,7 @@ public class PauseTimer { Interval in = Interval.createTickInterval(1); public boolean isElapsed() { - if (PuzzleApplication.debugSpeed) + if (Interval.getDebugSpeed()) { return true; } diff --git a/src/com/fourisland/fourpuzzle/window/ChoiceWindow.java b/src/com/fourisland/fourpuzzle/window/ChoiceWindow.java index 8dce753..2dbd605 100755 --- a/src/com/fourisland/fourpuzzle/window/ChoiceWindow.java +++ b/src/com/fourisland/fourpuzzle/window/ChoiceWindow.java @@ -61,18 +61,15 @@ public class ChoiceWindow implements Renderable, Inputable { } private List choices; - int numChoices; boolean center; private int width; private int height; BufferedImage cacheBase; int x; int y; - String clickSound; private ChoiceWindow(Builder builder) { this.choices = builder.choices; - numChoices = choices.size(); this.center = builder.center; for (String choice : choices) @@ -211,6 +208,7 @@ public class ChoiceWindow implements Renderable, Inputable { } } + Object hasInputLock = new Object(); Boolean hasInput = false; PauseTimer pt = new PauseTimer(0); public void processInput(KeyInput key) @@ -231,7 +229,7 @@ public class ChoiceWindow implements Renderable, Inputable { } } else if (key.isActionDown()) { - synchronized (hasInput) + synchronized (hasInputLock) { hasInput = true; } @@ -240,7 +238,7 @@ public class ChoiceWindow implements Renderable, Inputable { public boolean hasInput() { - synchronized (hasInput) + synchronized (hasInputLock) { return hasInput; } diff --git a/src/com/fourisland/fourpuzzle/window/Window.java b/src/com/fourisland/fourpuzzle/window/Window.java index db1bfab..661f4a2 100644 --- a/src/com/fourisland/fourpuzzle/window/Window.java +++ b/src/com/fourisland/fourpuzzle/window/Window.java @@ -26,7 +26,7 @@ public enum Window }, Selector(64) { - Interval in = Interval.createTickInterval(4); + transient Interval in = Interval.createTickInterval(4); boolean isFlashing = false; @Override -- cgit 1.4.1