diff options
Diffstat (limited to 'src/com')
| -rw-r--r-- | src/com/fourisland/fourpuzzle/gamestate/mapview/event/specialmove/MoveEventThread.java | 32 |
1 files changed, 16 insertions, 16 deletions
| 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 df4f4ee..2395dd0 100644 --- a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/specialmove/MoveEventThread.java +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/specialmove/MoveEventThread.java | |||
| @@ -10,7 +10,7 @@ import com.fourisland.fourpuzzle.gamestate.mapview.event.Event; | |||
| 10 | import com.fourisland.fourpuzzle.gamestate.mapview.event.LayerEvent; | 10 | import com.fourisland.fourpuzzle.gamestate.mapview.event.LayerEvent; |
| 11 | import java.util.List; | 11 | import java.util.List; |
| 12 | import java.util.Vector; | 12 | import java.util.Vector; |
| 13 | import java.util.concurrent.CountDownLatch; | 13 | import java.util.concurrent.Semaphore; |
| 14 | import java.util.logging.Level; | 14 | import java.util.logging.Level; |
| 15 | import java.util.logging.Logger; | 15 | import java.util.logging.Logger; |
| 16 | 16 | ||
| @@ -19,14 +19,12 @@ import java.util.logging.Logger; | |||
| 19 | * @author hatkirby | 19 | * @author hatkirby |
| 20 | */ | 20 | */ |
| 21 | public class MoveEventThread implements Runnable { | 21 | public class MoveEventThread implements Runnable { |
| 22 | |||
| 23 | private static volatile List<Event> events = new Vector<Event>(); | ||
| 24 | private static volatile Semaphore moveEventWait = new Semaphore(100); | ||
| 22 | 25 | ||
| 23 | public static volatile int countMoveEventThreads = 0; | 26 | private Event ev; |
| 24 | 27 | private MoveEvent[] actions; | |
| 25 | static volatile List<Event> events = new Vector<Event>(); | ||
| 26 | static volatile CountDownLatch moveEventWait = new CountDownLatch(0); | ||
| 27 | |||
| 28 | Event ev; | ||
| 29 | MoveEvent[] actions; | ||
| 30 | 28 | ||
| 31 | public MoveEventThread(Event ev, MoveEvent[] actions) | 29 | public MoveEventThread(Event ev, MoveEvent[] actions) |
| 32 | { | 30 | { |
| @@ -36,6 +34,12 @@ public class MoveEventThread implements Runnable { | |||
| 36 | 34 | ||
| 37 | public void run() | 35 | public void run() |
| 38 | { | 36 | { |
| 37 | try { | ||
| 38 | moveEventWait.acquire(); | ||
| 39 | } catch (InterruptedException ex) { | ||
| 40 | Logger.getLogger(MoveEventThread.class.getName()).log(Level.SEVERE, null, ex); | ||
| 41 | } | ||
| 42 | |||
| 39 | while (ev.isMoving()) | 43 | while (ev.isMoving()) |
| 40 | { | 44 | { |
| 41 | try { | 45 | try { |
| @@ -47,18 +51,13 @@ public class MoveEventThread implements Runnable { | |||
| 47 | 51 | ||
| 48 | events.add(ev); | 52 | events.add(ev); |
| 49 | 53 | ||
| 50 | MoveEventThread.countMoveEventThreads++; | ||
| 51 | moveEventWait = new CountDownLatch(countMoveEventThreads); | ||
| 52 | |||
| 53 | for (MoveEvent action : actions) | 54 | for (MoveEvent action : actions) |
| 54 | { | 55 | { |
| 55 | action.doAction(ev); | 56 | action.doAction(ev); |
| 56 | } | 57 | } |
| 57 | 58 | ||
| 58 | events.remove(ev); | 59 | events.remove(ev); |
| 59 | 60 | moveEventWait.release(); | |
| 60 | MoveEventThread.countMoveEventThreads--; | ||
| 61 | moveEventWait.countDown(); | ||
| 62 | } | 61 | } |
| 63 | 62 | ||
| 64 | /* TODO Rename the two following methods (isHeroMoving and isOtherMoving) | 63 | /* TODO Rename the two following methods (isHeroMoving and isOtherMoving) |
| @@ -78,7 +77,8 @@ public class MoveEventThread implements Runnable { | |||
| 78 | public static void moveAll() | 77 | public static void moveAll() |
| 79 | { | 78 | { |
| 80 | try { | 79 | try { |
| 81 | moveEventWait.await(); | 80 | moveEventWait.acquire(100); |
| 81 | moveEventWait.release(100); | ||
| 82 | } catch (InterruptedException ex) { | 82 | } catch (InterruptedException ex) { |
| 83 | Logger.getLogger(MoveEventThread.class.getName()).log(Level.SEVERE, null, ex); | 83 | Logger.getLogger(MoveEventThread.class.getName()).log(Level.SEVERE, null, ex); |
| 84 | } | 84 | } |
