mirror of
https://github.com/OMGeeky/andors-trail.git
synced 2026-02-23 15:38:29 +01:00
Additional safeguards to stop movementhandler when movement should be aborted.
git-svn-id: https://andors-trail.googlecode.com/svn/trunk@189 08aca716-68be-ccc6-4d58-36f5abd142ac
This commit is contained in:
@@ -23,10 +23,10 @@ public final class GameRoundController implements TimedMessageTask.Callback {
|
||||
|
||||
private int ticksUntilNextRound = Constants.TICKS_PER_ROUND;
|
||||
private int ticksUntilNextFullRound = Constants.TICKS_PER_FULLROUND;
|
||||
public void onTick(TimedMessageTask task) {
|
||||
public boolean onTick(TimedMessageTask task) {
|
||||
//L.log(id + " : Controller::tick()");
|
||||
if (!model.uiSelections.isMainActivityVisible) return;
|
||||
if (model.uiSelections.isInCombat) return;
|
||||
if (!model.uiSelections.isMainActivityVisible) return false;
|
||||
if (model.uiSelections.isInCombat) return false;
|
||||
|
||||
onNewTick();
|
||||
|
||||
@@ -42,7 +42,7 @@ public final class GameRoundController implements TimedMessageTask.Callback {
|
||||
ticksUntilNextFullRound = Constants.TICKS_PER_FULLROUND;
|
||||
}
|
||||
|
||||
roundTimer.queueAnotherTick();
|
||||
return true;
|
||||
}
|
||||
|
||||
public void resume() {
|
||||
|
||||
@@ -288,12 +288,12 @@ public final class MovementController implements TimedMessageTask.Callback {
|
||||
movementHandler.stop();
|
||||
}
|
||||
|
||||
public void onTick(TimedMessageTask task) {
|
||||
if (!model.uiSelections.isMainActivityVisible) return;
|
||||
if (model.uiSelections.isInCombat) return;
|
||||
public boolean onTick(TimedMessageTask task) {
|
||||
if (!model.uiSelections.isMainActivityVisible) return false;
|
||||
if (model.uiSelections.isInCombat) return false;
|
||||
|
||||
movePlayer(movementDx, movementDy);
|
||||
|
||||
movementHandler.queueAnotherTick();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ public final class TimedMessageTask extends Handler {
|
||||
private final Callback callback;
|
||||
private long nextTickTime;
|
||||
private boolean hasQueuedTick = false;
|
||||
private boolean isAlive = false;
|
||||
|
||||
public TimedMessageTask(Callback callback, long interval, boolean requireIntervalBeforeFirstTick) {
|
||||
this.interval = interval;
|
||||
@@ -19,14 +20,15 @@ public final class TimedMessageTask extends Handler {
|
||||
|
||||
@Override
|
||||
public void handleMessage(Message msg) {
|
||||
if (!hasQueuedTick) return;
|
||||
if (!isAlive) return;
|
||||
if (!hasQueuedTick) return;
|
||||
hasQueuedTick = false;
|
||||
tick();
|
||||
if (tick()) queueAnotherTick();
|
||||
}
|
||||
|
||||
private void tick() {
|
||||
private boolean tick() {
|
||||
nextTickTime = System.currentTimeMillis() + interval;
|
||||
callback.onTick(this);
|
||||
return callback.onTick(this);
|
||||
}
|
||||
|
||||
private void sleep(long delayMillis) {
|
||||
@@ -52,15 +54,17 @@ public final class TimedMessageTask extends Handler {
|
||||
}
|
||||
|
||||
public void start() {
|
||||
isAlive = true;
|
||||
if (shouldCauseTickOnStart()) tick();
|
||||
queueAnotherTick();
|
||||
}
|
||||
|
||||
public void stop() {
|
||||
hasQueuedTick = false;
|
||||
isAlive = false;
|
||||
}
|
||||
|
||||
public interface Callback {
|
||||
public void onTick(TimedMessageTask task);
|
||||
public boolean onTick(TimedMessageTask task);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user