summaryrefslogtreecommitdiff
path: root/NET/worlds/scape/ParallelAction.java
diff options
context:
space:
mode:
authorFuwn <[email protected]>2026-02-12 22:33:32 -0800
committerFuwn <[email protected]>2026-02-12 22:33:32 -0800
commitc7a9d4a6bd53ed7d61731770f2f10e8b9fd435f9 (patch)
treedf9f48bf128a6c0186a8e91857d6ff30fe0e9f18 /NET/worlds/scape/ParallelAction.java
downloadworldsplayer-c7a9d4a6bd53ed7d61731770f2f10e8b9fd435f9.tar.xz
worldsplayer-c7a9d4a6bd53ed7d61731770f2f10e8b9fd435f9.zip
Initial commit
Diffstat (limited to 'NET/worlds/scape/ParallelAction.java')
-rw-r--r--NET/worlds/scape/ParallelAction.java140
1 files changed, 140 insertions, 0 deletions
diff --git a/NET/worlds/scape/ParallelAction.java b/NET/worlds/scape/ParallelAction.java
new file mode 100644
index 0000000..f2ece12
--- /dev/null
+++ b/NET/worlds/scape/ParallelAction.java
@@ -0,0 +1,140 @@
+package NET.worlds.scape;
+
+import java.io.IOException;
+import java.util.Enumeration;
+import java.util.Vector;
+
+public class ParallelAction extends Action implements RunningActionCallback {
+ protected static final int NONE = 0;
+ protected static final int FIRST = 1;
+ protected static final int ALL = -1;
+ protected Vector actions = new Vector();
+ protected int waitState = -1;
+ protected int waitingFor = 0;
+ protected Object currentRun = null;
+ private static Object classCookie = new Object();
+
+ @Override
+ public Persister trigger(Event evt, Persister seqID) {
+ if (seqID == null) {
+ if (this.waitingFor == 0) {
+ this.currentRun = new Object();
+ if (this.waitState == -1) {
+ this.waitingFor = this.actions.size();
+ seqID = this;
+ } else if (this.waitState == 1) {
+ this.waitingFor = 1;
+ seqID = this;
+ } else {
+ this.waitingFor = 0;
+ seqID = null;
+ }
+
+ RunningActionHandler.trigger(this.actions, this.getWorld(), evt, this, this.currentRun);
+ }
+ } else if (this.waitingFor == 0) {
+ seqID = null;
+ }
+
+ return seqID;
+ }
+
+ @Override
+ public void actionDone(Action a, Event e, Object o) {
+ if (this.waitingFor > 0 && o == this.currentRun) {
+ this.waitingFor--;
+ }
+ }
+
+ public void setWaitForAll() {
+ this.waitState = -1;
+ }
+
+ public void setWaitForFirst() {
+ this.waitState = 1;
+ }
+
+ public void setWaitForNone() {
+ this.waitState = 0;
+ }
+
+ public void addComponent(Action act) {
+ assert act != null;
+
+ this.actions.addElement(act);
+ }
+
+ public void insertComponent(Action act, int index) {
+ assert act != null;
+
+ this.actions.insertElementAt(act, index);
+ }
+
+ public boolean removeComponent(Action act) {
+ assert act != null;
+
+ return this.actions.removeElement(act);
+ }
+
+ public Enumeration getComponents() {
+ return this.actions.elements();
+ }
+
+ @Override
+ public Object properties(int index, int offset, int mode, Object value) throws NoSuchPropertyException {
+ Object ret = null;
+ switch (index - offset) {
+ case 0:
+ if (mode == 0) {
+ ret = ObjectPropertyAdder.make(new VectorProperty(this, index, "Components"), this.getRoot(), "NET.worlds.scape.Action");
+ } else if (mode == 1) {
+ ret = this.actions.clone();
+ } else if (mode == 4) {
+ this.actions.removeElement(value);
+ } else if (mode == 3) {
+ this.actions.addElement((Action)value);
+ }
+ break;
+ case 1:
+ if (mode == 0) {
+ String[] names = new String[]{"None", "First", "All"};
+ int[] values = new int[]{0, 1, -1};
+ ret = EnumPropertyEditor.make(new Property(this, index, "Wait for"), names, values);
+ } else if (mode == 1) {
+ ret = new Integer(this.waitState);
+ } else if (mode == 2) {
+ this.waitState = (Integer)value;
+ }
+ break;
+ default:
+ ret = super.properties(index, offset + 2, mode, value);
+ }
+
+ return ret;
+ }
+
+ @Override
+ public void saveState(Saver s) throws IOException {
+ s.saveVersion(2, classCookie);
+ super.saveState(s);
+ s.saveVector(this.actions);
+ s.saveInt(this.waitState);
+ }
+
+ @Override
+ public void restoreState(Restorer r) throws IOException, TooNewException {
+ switch (r.restoreVersion(classCookie)) {
+ case 1:
+ super.restoreState(r);
+ this.actions = r.restoreVector();
+ break;
+ case 2:
+ super.restoreState(r);
+ this.actions = r.restoreVector();
+ this.waitState = r.restoreInt();
+ break;
+ default:
+ throw new TooNewException();
+ }
+ }
+}