mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-12 13:07:29 +00:00
IAction optimisations
This commit is contained in:
1 parent
aec11c617b
commit
fe786babc6
2 files changed
+24
-43
No files matched your search
@@ -271,6 +271,12 @@ public class Action implements IAction {
|
||||
if (done)
|
||||
return;
|
||||
|
||||
if (startAfterTicks > 0) {
|
||||
manager.LOGGER.log(String.format("Starts after %s ticks...", startAfterTicks), this);
|
||||
startAfterTicks--;
|
||||
return;
|
||||
}
|
||||
|
||||
if (duration == 0 && onStart != null)
|
||||
execute("start", this::executeOnStart);
|
||||
|
||||
@@ -279,13 +285,7 @@ public class Action implements IAction {
|
||||
|
||||
duration++;
|
||||
|
||||
if (manager.debug)
|
||||
manager.LOGGER.log(String.format("Ticking... (duration = %s/%s, count = %s/%s)", duration, maxDuration, count, maxCount), this);
|
||||
|
||||
if (startAfterTicks > 0) {
|
||||
startAfterTicks--;
|
||||
return;
|
||||
}
|
||||
inheritedTick();
|
||||
|
||||
if (maxDuration > -1 && duration >= maxDuration || maxCount == 0) {
|
||||
if (manager.debug)
|
||||
@@ -295,18 +295,25 @@ public class Action implements IAction {
|
||||
return;
|
||||
}
|
||||
|
||||
if (duration % updateEveryXTick == 0 && task != null)
|
||||
execute("task", this::executeTask);
|
||||
|
||||
if (maxCount > -1 && count >= maxCount) {
|
||||
if (manager.debug)
|
||||
manager.LOGGER.log("Reached max count of Action '%s' on queue '%s'", this);
|
||||
manager.LOGGER.log("Reached max count", this);
|
||||
|
||||
markDone();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void inheritedTick() {
|
||||
if (manager.debug)
|
||||
manager.LOGGER.log(String.format("Ticking... (duration = %s/%s, count = %s/%s)", duration, maxDuration, count, maxCount), this);
|
||||
|
||||
|
||||
if (duration % updateEveryXTick == 0 && task != null)
|
||||
execute("task", this::executeTask);
|
||||
}
|
||||
|
||||
public void execute(String taskName, Runnable task) {
|
||||
if (isThreaded)
|
||||
actionThread.execute(taskName, task);
|
||||
@@ -341,7 +348,7 @@ public class Action implements IAction {
|
||||
}
|
||||
|
||||
if (manager.debug)
|
||||
manager.LOGGER.log("Finished executing task", this);
|
||||
manager.LOGGER.log(String.format("Finished executing task (count = %s/%s)", count, maxCount), this);
|
||||
}
|
||||
|
||||
protected void executeOnDone() {
|
||||
@@ -373,7 +380,7 @@ public class Action implements IAction {
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return String.format("IAction '%s' [queue='%s', scheduled=%s, done=%s, paused=%s, updateEvery=%s, duration=%d/%d, count=%d/%d, threaded=%s]", name != null ? name : "unnamed", getQueueName(), isScheduled, done, isPaused(), updateEveryXTick, duration, maxDuration, count, maxCount, isThreaded);
|
||||
return String.format("%s '%s' [queue='%s', scheduled=%s, done=%s, paused=%s, updateEvery=%s, duration=%d/%d, count=%d/%d, threaded=%s]", getClass().getSimpleName(), name != null ? name : "unnamed", getQueueName(), isScheduled, done, isPaused(), updateEveryXTick, duration, maxDuration, count, maxCount, isThreaded);
|
||||
}
|
||||
///////////////////////////////////////////////////
|
||||
//////////////////////////////////////////////////
|
||||
|
||||
@@ -91,31 +91,11 @@ public class ConditionalAction extends Action implements IConditionalAction {
|
||||
return terminateWhen != null && terminateWhen.apply(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tick() {
|
||||
if (isDone())
|
||||
return;
|
||||
|
||||
if (duration == 0 && onStart != null)
|
||||
execute("start", this::executeOnStart);
|
||||
|
||||
if (isDone())
|
||||
return;
|
||||
|
||||
duration++;
|
||||
|
||||
public void inheritedTick() {
|
||||
if (manager.inDebugMode())
|
||||
manager.LOGGER.log(String.format("Ticking... (duration = %s/%s, count = %s/%s, checkCount = %s/%s)", duration, maxDuration, count, maxCount, checkCount, maxChecks), this);
|
||||
|
||||
if (maxDuration > -1 && duration >= maxDuration || maxCount == 0) {
|
||||
if (manager.inDebugMode())
|
||||
manager.LOGGER.log("Reached max duration", this);
|
||||
|
||||
markDone();
|
||||
return;
|
||||
}
|
||||
|
||||
if (maxChecks > -1 && checkCount > maxChecks) {
|
||||
if (maxChecks > -1 && checkCount >= maxChecks) {
|
||||
if (manager.inDebugMode())
|
||||
manager.LOGGER.log("Reached max check count", this);
|
||||
|
||||
@@ -139,18 +119,12 @@ public class ConditionalAction extends Action implements IConditionalAction {
|
||||
|
||||
execute("task", execute);
|
||||
}
|
||||
|
||||
if (maxCount > -1 && count >= maxCount) {
|
||||
if (manager.inDebugMode())
|
||||
manager.LOGGER.log("Reached max count", this);
|
||||
|
||||
markDone();
|
||||
}
|
||||
}
|
||||
|
||||
protected void executeTask() {
|
||||
if (manager.inDebugMode())
|
||||
manager.LOGGER.log("Executing task...", this);
|
||||
|
||||
try {
|
||||
task.accept(this);
|
||||
count++;
|
||||
@@ -161,7 +135,7 @@ public class ConditionalAction extends Action implements IConditionalAction {
|
||||
}
|
||||
|
||||
if (manager.inDebugMode())
|
||||
manager.LOGGER.log("Finished executing task", this);
|
||||
manager.LOGGER.log(String.format("Finished executing task (count = %s/%s)", count, maxCount), this);
|
||||
|
||||
}
|
||||
|
||||
@@ -181,7 +155,7 @@ public class ConditionalAction extends Action implements IConditionalAction {
|
||||
|
||||
|
||||
public String toString() {
|
||||
return String.format("IConditionalAction '%s' [queue='%s', scheduled=%s, done=%s, paused=%s, updateEvery=%s, duration=%d/%d, count=%d/%d, checks=%d/%d, taskExecuted=%s, threaded=%s]",
|
||||
return String.format("%s '%s' [queue='%s', scheduled=%s, done=%s, paused=%s, updateEvery=%s, duration=%d/%d, count=%d/%d, checks=%d/%d, taskExecuted=%s, threaded=%s]", getClass().getSimpleName(),
|
||||
name != null ? name : "unnamed", getQueueName(),
|
||||
isScheduled,
|
||||
done,
|
||||
|
||||
Reference in new issue
Block a user