summary refs log tree commit diff stats
path: root/src/com/fourisland/fourpuzzle/gamestate/mapview
diff options
context:
space:
mode:
authorStarla Insigna <hatkirby@fourisland.com>2009-03-19 22:58:24 -0400
committerStarla Insigna <hatkirby@fourisland.com>2009-03-19 22:58:24 -0400
commitfc3afd1d6460b2aa453167498979bbf7a636ef45 (patch)
tree390d5003901ec8b6e951dae2daedb485033c8b6e /src/com/fourisland/fourpuzzle/gamestate/mapview
parent0ebc2f2c92e4b51069f497aca9f715198010bdf2 (diff)
downloadfourpuzzle-fc3afd1d6460b2aa453167498979bbf7a636ef45.tar.gz
fourpuzzle-fc3afd1d6460b2aa453167498979bbf7a636ef45.tar.bz2
fourpuzzle-fc3afd1d6460b2aa453167498979bbf7a636ef45.zip
Engine: Fixed many potential bugs
Identified by FindBugs. http://findbugs.sourceforge.net/
Diffstat (limited to 'src/com/fourisland/fourpuzzle/gamestate/mapview')
-rwxr-xr-xsrc/com/fourisland/fourpuzzle/gamestate/mapview/ChipSet.java2
-rwxr-xr-xsrc/com/fourisland/fourpuzzle/gamestate/mapview/MapViewGameState.java4
-rwxr-xr-xsrc/com/fourisland/fourpuzzle/gamestate/mapview/event/AnimationType.java6
-rwxr-xr-xsrc/com/fourisland/fourpuzzle/gamestate/mapview/event/CommonEvent.java6
-rwxr-xr-xsrc/com/fourisland/fourpuzzle/gamestate/mapview/event/EventHandler.java4
-rwxr-xr-xsrc/com/fourisland/fourpuzzle/gamestate/mapview/event/EventList.java34
-rwxr-xr-xsrc/com/fourisland/fourpuzzle/gamestate/mapview/event/HeroEvent.java30
-rw-r--r--src/com/fourisland/fourpuzzle/gamestate/mapview/event/ImmutableEvent.java2
-rwxr-xr-xsrc/com/fourisland/fourpuzzle/gamestate/mapview/event/SpecialEvent.java2
-rwxr-xr-xsrc/com/fourisland/fourpuzzle/gamestate/mapview/event/movement/CustomMovementType.java3
-rwxr-xr-xsrc/com/fourisland/fourpuzzle/gamestate/mapview/event/specialmove/LoopUntilCollisionMoveEvent.java3
-rwxr-xr-xsrc/com/fourisland/fourpuzzle/gamestate/mapview/event/specialmove/MoveEventThread.java3
-rwxr-xr-xsrc/com/fourisland/fourpuzzle/gamestate/mapview/viewpoint/MovingViewpoint.java2
-rw-r--r--src/com/fourisland/fourpuzzle/gamestate/mapview/viewpoint/ShakingViewpoint.java2
14 files changed, 84 insertions, 19 deletions
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 {
52 52
53 public static void initalize(String name) 53 public static void initalize(String name)
54 { 54 {
55 ResourceMap rm = PuzzleApplication.INSTANCE.getContext().getResourceManager().getResourceMap(); 55 ResourceMap rm = PuzzleApplication.getInstance().getContext().getResourceManager().getResourceMap();
56 InputStream cs = null; 56 InputStream cs = null;
57 57
58 if (rm.getClassLoader().getResource(rm.getResourcesDir() + "chipset/" + name + ".tsx") == null) 58 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 {
83 * walkthrough flag so the Hero can walk through stuff */ 83 * walkthrough flag so the Hero can walk through stuff */
84 if (key.isCtrlDown() && !debugWalkthrough) 84 if (key.isCtrlDown() && !debugWalkthrough)
85 { 85 {
86 if (PuzzleApplication.INSTANCE.getContext().getResourceMap().getBoolean("debugMode")) 86 if (PuzzleApplication.getInstance().getContext().getResourceMap().getBoolean("debugMode"))
87 { 87 {
88 debugWalkthrough = true; 88 debugWalkthrough = true;
89 } 89 }
@@ -188,7 +188,7 @@ public class MapViewGameState implements GameState {
188 { 188 {
189 /* If debug mode is enabled and F11 is pressed, cancel any running 189 /* If debug mode is enabled and F11 is pressed, cancel any running
190 * events */ 190 * events */
191 if ((key.getKey() == KeyEvent.VK_F11) && (PuzzleApplication.INSTANCE.getContext().getResourceMap().getBoolean("debugMode"))) 191 if ((key.getKey() == KeyEvent.VK_F11) && (PuzzleApplication.getInstance().getContext().getResourceMap().getBoolean("debugMode")))
192 { 192 {
193 for (LayerEvent ev : currentMap.getEvents()) 193 for (LayerEvent ev : currentMap.getEvents())
194 { 194 {
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 {
26 */ 26 */
27 CommonWithStepping(true, true) 27 CommonWithStepping(true, true)
28 { 28 {
29 Interval in = Interval.createTickInterval(2); 29 transient Interval in = Interval.createTickInterval(2);
30 30
31 @Override 31 @Override
32 public void tick(PossibleEvent pe) 32 public void tick(PossibleEvent pe)
@@ -56,7 +56,7 @@ public enum AnimationType {
56 */ 56 */
57 TurnLeft(true, true) 57 TurnLeft(true, true)
58 { 58 {
59 Interval in = Interval.createTickInterval(2); 59 transient Interval in = Interval.createTickInterval(2);
60 60
61 @Override 61 @Override
62 public void tick(PossibleEvent pe) 62 public void tick(PossibleEvent pe)
@@ -73,7 +73,7 @@ public enum AnimationType {
73 */ 73 */
74 TurnRight(true, true) 74 TurnRight(true, true)
75 { 75 {
76 Interval in = Interval.createTickInterval(2); 76 transient Interval in = Interval.createTickInterval(2);
77 77
78 @Override 78 @Override
79 public void tick(PossibleEvent pe) 79 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 {
51 this.callback = callback; 51 this.callback = callback;
52 } 52 }
53 53
54 public EventCallTime getCalltime() { 54 public EventCallTime getCalltime()
55 {
55 return calltime; 56 return calltime;
56 } 57 }
57 58
58 public void setCalltime(EventCallTime calltime) { 59 public void setCalltime(EventCallTime calltime)
60 {
59 this.calltime = calltime; 61 this.calltime = calltime;
60 } 62 }
61 63
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 {
59 * Also reset the viewpoint in case the viewpoint was 59 * Also reset the viewpoint in case the viewpoint was
60 * fixed during the thread */ 60 * fixed during the thread */
61 61
62 SpecialEvent.mapView.setViewpoint(new AutomaticViewpoint(SpecialEvent.mapView.getCurrentMap())); 62 new SpecialEvent().ResetViewpoint();
63 } catch (ResourceNotFoundException ex) 63 } catch (ResourceNotFoundException ex)
64 { 64 {
65 PuzzleApplication.INSTANCE.reportError(ex); 65 PuzzleApplication.reportError(ex);
66 } 66 }
67 } 67 }
68 }; 68 };
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;
14 */ 14 */
15public class EventList extends Vector<LayerEvent> { 15public class EventList extends Vector<LayerEvent> {
16 16
17 private static final long serialVersionUID = 765438545;
18
17 public EventList(Map parentMap) 19 public EventList(Map parentMap)
18 { 20 {
19 setParentMap(parentMap); 21 setParentMap(parentMap);
@@ -62,7 +64,7 @@ public class EventList extends Vector<LayerEvent> {
62 return super.add(o); 64 return super.add(o);
63 } 65 }
64 66
65 private Map parentMap = null; 67 private transient Map parentMap = null;
66 public Map getParentMap() 68 public Map getParentMap()
67 { 69 {
68 return parentMap; 70 return parentMap;
@@ -77,4 +79,34 @@ public class EventList extends Vector<LayerEvent> {
77 } 79 }
78 } 80 }
79 81
82 @Override
83 public int hashCode()
84 {
85 int hash = 3;
86 hash = 59 * hash + (this.parentMap != null ? this.parentMap.hashCode() : 0);
87 return hash;
88 }
89
90 @Override
91 public boolean equals(Object obj)
92 {
93 if (obj == null)
94 {
95 return false;
96 }
97
98 if (getClass() != obj.getClass())
99 {
100 return false;
101 }
102
103 final EventList other = (EventList) obj;
104 if (this.parentMap != other.parentMap && (this.parentMap == null || !this.parentMap.equals(other.parentMap)))
105 {
106 return false;
107 }
108
109 return true;
110 }
111
80} 112}
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;
14import com.fourisland.fourpuzzle.gamestate.mapview.Map; 14import com.fourisland.fourpuzzle.gamestate.mapview.Map;
15import com.fourisland.fourpuzzle.gamestate.mapview.MapViewGameState; 15import com.fourisland.fourpuzzle.gamestate.mapview.MapViewGameState;
16import com.fourisland.fourpuzzle.gamestate.mapview.event.graphic.BlankEventGraphic; 16import com.fourisland.fourpuzzle.gamestate.mapview.event.graphic.BlankEventGraphic;
17import java.io.IOException;
18import java.io.ObjectInputStream;
19import java.io.ObjectOutputStream;
20import java.io.Serializable;
17 21
18/** 22/**
19 * 23 *
20 * @author hatkirby 24 * @author hatkirby
21 */ 25 */
22public class HeroEvent extends AbstractEvent implements Event { 26public class HeroEvent extends AbstractEvent implements Event, Serializable {
27
28 private static final long serialVersionUID = 402340890;
23 29
24 public HeroEvent() 30 public HeroEvent()
25 { 31 {
@@ -73,5 +79,27 @@ public class HeroEvent extends AbstractEvent implements Event {
73 { 79 {
74 return ((MapViewGameState) Game.getGameState()).getCurrentMap(); 80 return ((MapViewGameState) Game.getGameState()).getCurrentMap();
75 } 81 }
82
83 /**
84 * Serialize this HeroEvent instance
85 *
86 * When serializing a HeroEvent, the only information that is really
87 * necessary is the Hero's location and direction, because all other
88 * important information is serialized by SaveFile.
89 *
90 * @serialData The Hero's location (as a Point object) is emitted, followed
91 * by the a Direction object representing the Hero's direction.
92 */
93 private void writeObject(ObjectOutputStream s) throws IOException
94 {
95 s.writeObject(getLocation());
96 s.writeObject(getDirection());
97 }
98
99 private void readObject(ObjectInputStream s) throws IOException, ClassNotFoundException
100 {
101 setLocation((Point) s.readObject());
102 setDirection((Direction) s.readObject());
103 }
76 104
77} 105}
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
26 26
27 public String getLabel() 27 public String getLabel()
28 { 28 {
29 return new String(ev.getLabel()); 29 return ev.getLabel();
30 } 30 }
31 31
32 public Point getLocation() 32 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;
30 */ 30 */
31public class SpecialEvent { 31public class SpecialEvent {
32 32
33 protected static MapViewGameState mapView = null; 33 private static MapViewGameState mapView = null;
34 public static void setMapView(MapViewGameState mapView) 34 public static void setMapView(MapViewGameState mapView)
35 { 35 {
36 SpecialEvent.mapView = mapView; 36 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;
7 7
8import com.fourisland.fourpuzzle.Direction; 8import com.fourisland.fourpuzzle.Direction;
9import com.fourisland.fourpuzzle.gamestate.mapview.event.ImmutableEvent; 9import com.fourisland.fourpuzzle.gamestate.mapview.event.ImmutableEvent;
10import java.util.Arrays;
10 11
11/** 12/**
12 * CustomMovementEvent takes an array of Directions and directions the event 13 * CustomMovementEvent takes an array of Directions and directions the event
@@ -22,7 +23,7 @@ public class CustomMovementType implements MovementType {
22 23
23 public CustomMovementType(Direction[] moves) 24 public CustomMovementType(Direction[] moves)
24 { 25 {
25 this.moves = moves; 26 this.moves = Arrays.copyOf(moves, moves.length);
26 } 27 }
27 28
28 public Direction nextMovement(ImmutableEvent ev) 29 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;
7 7
8import com.fourisland.fourpuzzle.gamestate.mapview.event.Event; 8import com.fourisland.fourpuzzle.gamestate.mapview.event.Event;
9import java.awt.Point; 9import java.awt.Point;
10import java.util.Arrays;
10 11
11/** 12/**
12 * LoopUntilCollisionMoveEvent takes an array of <b>MoveEvent</b>s and repeatedly 13 * LoopUntilCollisionMoveEvent takes an array of <b>MoveEvent</b>s and repeatedly
@@ -24,7 +25,7 @@ public class LoopUntilCollisionMoveEvent implements MoveEvent {
24 25
25 public LoopUntilCollisionMoveEvent(MoveEvent[] moves) 26 public LoopUntilCollisionMoveEvent(MoveEvent[] moves)
26 { 27 {
27 this.moves = moves; 28 this.moves = Arrays.copyOf(moves, moves.length);
28 } 29 }
29 30
30 public void doAction(Event ev) 31 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;
9import com.fourisland.fourpuzzle.gamestate.mapview.event.Event; 9import com.fourisland.fourpuzzle.gamestate.mapview.event.Event;
10import com.fourisland.fourpuzzle.gamestate.mapview.event.LayerEvent; 10import com.fourisland.fourpuzzle.gamestate.mapview.event.LayerEvent;
11import java.util.ArrayList; 11import java.util.ArrayList;
12import java.util.Arrays;
12import java.util.List; 13import java.util.List;
13import java.util.Vector; 14import java.util.Vector;
14import java.util.concurrent.ExecutorService; 15import java.util.concurrent.ExecutorService;
@@ -34,7 +35,7 @@ public class MoveEventThread implements Runnable {
34 public MoveEventThread(Event ev, MoveEvent[] actions) 35 public MoveEventThread(Event ev, MoveEvent[] actions)
35 { 36 {
36 this.ev = ev; 37 this.ev = ev;
37 this.actions = actions; 38 this.actions = Arrays.copyOf(actions, actions.length);
38 } 39 }
39 40
40 public void start() 41 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 {
39 this.sy = sy; 39 this.sy = sy;
40 this.dx = dx; 40 this.dx = dx;
41 this.dy = dy; 41 this.dy = dy;
42 this.speed = length / Game.FPS; 42 this.speed = length / (double) Game.FPS;
43 this.xdist = dx - sx; 43 this.xdist = dx - sx;
44 this.ydist = dy - sy; 44 this.ydist = dy - sy;
45 this.callback = callback; 45 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 {
28 this.length = length; 28 this.length = length;
29 this.x = x; 29 this.x = x;
30 this.y = y; 30 this.y = y;
31 this.in = Interval.createMillisInterval(1000 / speed.getSpeed()); 31 this.in = Interval.createMillisInterval(1000F / speed.getSpeed());
32 this.speed = speed; 32 this.speed = speed;
33 this.callback = callback; 33 this.callback = callback;
34 this.start = System.currentTimeMillis(); 34 this.start = System.currentTimeMillis();