From a9e21cb37d1e6887270f68d90f2f3c8bcd775df2 Mon Sep 17 00:00:00 2001 From: Starla Insigna Date: Tue, 3 Feb 2009 21:47:22 -0500 Subject: Added Executor to MoveEventThread --- .../gamestate/mapview/MapViewGameState.java | 4 +-- .../gamestate/mapview/event/SpecialEvent.java | 4 +-- .../mapview/event/specialmove/MoveEventThread.java | 29 +++++++++++++--------- 3 files changed, 21 insertions(+), 16 deletions(-) (limited to 'src/com') 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 { debugWalkthrough = false; } - if (!hero.isMoving() && !MoveEventThread.isHeroMoving() && !EventHandler.isRunningEvent()) + if (!hero.isMoving() && !MoveEventThread.isHeroActive() && !EventHandler.isRunningEvent()) { Direction toMove = null; Boolean letsMove = false; @@ -181,7 +181,7 @@ public class MapViewGameState implements GameState { { if (!ev.isMoving()) { - if (!MoveEventThread.isOtherMoving(ev)) + if (!MoveEventThread.isOtherActive(ev)) { if (!EventHandler.isRunningEvent()) { 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 { */ public void MoveEvent(MoveEvent[] actions) { - new Thread(new MoveEventThread(Game.getHeroEvent(), actions)).start(); + new MoveEventThread(Game.getHeroEvent(), actions).start(); } /** @@ -123,7 +123,7 @@ public class SpecialEvent { */ public void MoveEvent(MoveEvent[] actions, String label) { - new Thread(new MoveEventThread(((MapViewGameState) Game.getGameState()).getCurrentMap().getEvent(label), actions)).start(); + new MoveEventThread(mapView.getCurrentMap().getEvent(label), actions).start(); } /** 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; import com.fourisland.fourpuzzle.gamestate.mapview.event.LayerEvent; import java.util.List; import java.util.Vector; +import java.util.concurrent.Executor; +import java.util.concurrent.Executors; import java.util.concurrent.Semaphore; /** @@ -17,7 +19,9 @@ import java.util.concurrent.Semaphore; * @author hatkirby */ public class MoveEventThread implements Runnable { - + + private static Executor moveEventExecutor = Executors.newCachedThreadPool(); + private static volatile List events = new Vector(); private static volatile Semaphore moveEventWait = new Semaphore(100); @@ -29,6 +33,11 @@ public class MoveEventThread implements Runnable { this.ev = ev; this.actions = actions; } + + public void start() + { + moveEventExecutor.execute(this); + } public void run() { @@ -58,24 +67,20 @@ public class MoveEventThread implements Runnable { moveEventWait.release(); } - /* TODO Rename the two following methods (isHeroMoving and isOtherMoving) - * to isHeroActive and isOtherActive respectively. - */ - - public static boolean isHeroMoving() + public static void moveAll() throws InterruptedException { - return (events.contains(Game.getHeroEvent())); + moveEventWait.acquire(100); + moveEventWait.release(100); } - public static boolean isOtherMoving(LayerEvent event) + public static boolean isHeroActive() { - return (events.contains(event)); + return (events.contains(Game.getHeroEvent())); } - public static void moveAll() throws InterruptedException + public static boolean isOtherActive(LayerEvent event) { - moveEventWait.acquire(100); - moveEventWait.release(100); + return (events.contains(event)); } } -- cgit 1.4.1