summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorStarla Insigna <hatkirby@fourisland.com>2009-02-03 21:47:22 -0500
committerStarla Insigna <hatkirby@fourisland.com>2009-02-03 21:47:22 -0500
commita9e21cb37d1e6887270f68d90f2f3c8bcd775df2 (patch)
treec444fc8268d6a829a9e17b9c9d4ab7dc501f6124
parent029190712a8f38cef760741cf53652e0ccd89172 (diff)
downloadfourpuzzle-a9e21cb37d1e6887270f68d90f2f3c8bcd775df2.tar.gz
fourpuzzle-a9e21cb37d1e6887270f68d90f2f3c8bcd775df2.tar.bz2
fourpuzzle-a9e21cb37d1e6887270f68d90f2f3c8bcd775df2.zip
Added Executor to MoveEventThread
-rw-r--r--src/com/fourisland/fourpuzzle/gamestate/mapview/MapViewGameState.java4
-rw-r--r--src/com/fourisland/fourpuzzle/gamestate/mapview/event/SpecialEvent.java4
-rw-r--r--src/com/fourisland/fourpuzzle/gamestate/mapview/event/specialmove/MoveEventThread.java29
3 files changed, 21 insertions, 16 deletions
diff --git a/src/com/fourisland/fourpuzzle/gamestate/mapview/MapViewGameState.java b/src/com/fourisland/fourpuzzle/gamestate/mapview/MapViewGameState.java index 9c66a9c..9c8e9d7 100644 --- a/src/com/fourisland/fourpuzzle/gamestate/mapview/MapViewGameState.java +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/MapViewGameState.java
@@ -79,7 +79,7 @@ public class MapViewGameState implements GameState {
79 debugWalkthrough = false; 79 debugWalkthrough = false;
80 } 80 }
81 81
82 if (!hero.isMoving() && !MoveEventThread.isHeroMoving() && !EventHandler.isRunningEvent()) 82 if (!hero.isMoving() && !MoveEventThread.isHeroActive() && !EventHandler.isRunningEvent())
83 { 83 {
84 Direction toMove = null; 84 Direction toMove = null;
85 Boolean letsMove = false; 85 Boolean letsMove = false;
@@ -181,7 +181,7 @@ public class MapViewGameState implements GameState {
181 { 181 {
182 if (!ev.isMoving()) 182 if (!ev.isMoving())
183 { 183 {
184 if (!MoveEventThread.isOtherMoving(ev)) 184 if (!MoveEventThread.isOtherActive(ev))
185 { 185 {
186 if (!EventHandler.isRunningEvent()) 186 if (!EventHandler.isRunningEvent())
187 { 187 {
diff --git a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/SpecialEvent.java b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/SpecialEvent.java index cf31bf1..c39082d 100644 --- a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/SpecialEvent.java +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/SpecialEvent.java
@@ -112,7 +112,7 @@ public class SpecialEvent {
112 */ 112 */
113 public void MoveEvent(MoveEvent[] actions) 113 public void MoveEvent(MoveEvent[] actions)
114 { 114 {
115 new Thread(new MoveEventThread(Game.getHeroEvent(), actions)).start(); 115 new MoveEventThread(Game.getHeroEvent(), actions).start();
116 } 116 }
117 117
118 /** 118 /**
@@ -123,7 +123,7 @@ public class SpecialEvent {
123 */ 123 */
124 public void MoveEvent(MoveEvent[] actions, String label) 124 public void MoveEvent(MoveEvent[] actions, String label)
125 { 125 {
126 new Thread(new MoveEventThread(((MapViewGameState) Game.getGameState()).getCurrentMap().getEvent(label), actions)).start(); 126 new MoveEventThread(mapView.getCurrentMap().getEvent(label), actions).start();
127 } 127 }
128 128
129 /** 129 /**
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 d129303..488331a 100644 --- a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/specialmove/MoveEventThread.java +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/specialmove/MoveEventThread.java
@@ -10,6 +10,8 @@ import 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.List; 11import java.util.List;
12import java.util.Vector; 12import java.util.Vector;
13import java.util.concurrent.Executor;
14import java.util.concurrent.Executors;
13import java.util.concurrent.Semaphore; 15import java.util.concurrent.Semaphore;
14 16
15/** 17/**
@@ -17,7 +19,9 @@ import java.util.concurrent.Semaphore;
17 * @author hatkirby 19 * @author hatkirby
18 */ 20 */
19public class MoveEventThread implements Runnable { 21public class MoveEventThread implements Runnable {
20 22
23 private static Executor moveEventExecutor = Executors.newCachedThreadPool();
24
21 private static volatile List<Event> events = new Vector<Event>(); 25 private static volatile List<Event> events = new Vector<Event>();
22 private static volatile Semaphore moveEventWait = new Semaphore(100); 26 private static volatile Semaphore moveEventWait = new Semaphore(100);
23 27
@@ -29,6 +33,11 @@ public class MoveEventThread implements Runnable {
29 this.ev = ev; 33 this.ev = ev;
30 this.actions = actions; 34 this.actions = actions;
31 } 35 }
36
37 public void start()
38 {
39 moveEventExecutor.execute(this);
40 }
32 41
33 public void run() 42 public void run()
34 { 43 {
@@ -58,24 +67,20 @@ public class MoveEventThread implements Runnable {
58 moveEventWait.release(); 67 moveEventWait.release();
59 } 68 }
60 69
61 /* TODO Rename the two following methods (isHeroMoving and isOtherMoving) 70 public static void moveAll() throws InterruptedException
62 * to isHeroActive and isOtherActive respectively.
63 */
64
65 public static boolean isHeroMoving()
66 { 71 {
67 return (events.contains(Game.getHeroEvent())); 72 moveEventWait.acquire(100);
73 moveEventWait.release(100);
68 } 74 }
69 75
70 public static boolean isOtherMoving(LayerEvent event) 76 public static boolean isHeroActive()
71 { 77 {
72 return (events.contains(event)); 78 return (events.contains(Game.getHeroEvent()));
73 } 79 }
74 80
75 public static void moveAll() throws InterruptedException 81 public static boolean isOtherActive(LayerEvent event)
76 { 82 {
77 moveEventWait.acquire(100); 83 return (events.contains(event));
78 moveEventWait.release(100);
79 } 84 }
80 85
81} 86}