some scheduler stuff

This commit is contained in:
sirjonasxx 2021-04-27 22:08:03 +02:00
parent e7d7e243a7
commit 1c4c7b03c0
3 changed files with 16 additions and 23 deletions

View File

@ -11,6 +11,7 @@ import javafx.beans.property.SimpleObjectProperty;
import gearth.misc.StringifyAble; import gearth.misc.StringifyAble;
import gearth.protocol.HMessage; import gearth.protocol.HMessage;
import gearth.protocol.HPacket; import gearth.protocol.HPacket;
import javafx.beans.property.SimpleStringProperty;
/** /**
* Created by Jonas on 07/04/18. * Created by Jonas on 07/04/18.
@ -20,20 +21,20 @@ public class ScheduleItem {
private SimpleIntegerProperty indexProperty; private SimpleIntegerProperty indexProperty;
private SimpleBooleanProperty pausedProperty; private SimpleBooleanProperty pausedProperty;
private SimpleObjectProperty<Interval> delayProperty; private SimpleObjectProperty<Interval> delayProperty;
private SimpleObjectProperty<HPacket> packetProperty;
private SimpleObjectProperty<HMessage.Direction> destinationProperty; private SimpleObjectProperty<HMessage.Direction> destinationProperty;
private SimpleStringProperty packetAsStringProperty;
public ScheduleItem() {} public ScheduleItem() {}
public ScheduleItem (int index, boolean paused, Interval delay, HPacket packet, HMessage.Direction destination) { public ScheduleItem (int index, boolean paused, Interval delay, String packetAsString, HMessage.Direction destination) {
construct(index, paused, delay, packet, destination); construct(index, paused, delay, packetAsString, destination);
} }
protected void construct(int index, boolean paused, Interval delay, HPacket packet, HMessage.Direction destination) { protected void construct(int index, boolean paused, Interval delay, String packetAsString, HMessage.Direction destination) {
this.indexProperty = new SimpleIntegerProperty(index); this.indexProperty = new SimpleIntegerProperty(index);
this.pausedProperty = new SimpleBooleanProperty(paused); this.pausedProperty = new SimpleBooleanProperty(paused);
this.delayProperty = new SimpleObjectProperty<>(delay); this.delayProperty = new SimpleObjectProperty<>(delay);
this.packetProperty = new SimpleObjectProperty<>(packet); this.packetAsStringProperty = new SimpleStringProperty(packetAsString);
this.destinationProperty = new SimpleObjectProperty<>(destination); this.destinationProperty = new SimpleObjectProperty<>(destination);
} }
@ -49,8 +50,8 @@ public class ScheduleItem {
return delayProperty; return delayProperty;
} }
public SimpleObjectProperty<HPacket> getPacketProperty() { public SimpleStringProperty getPacketAsStringProperty() {
return packetProperty; return packetAsStringProperty;
} }
public SimpleObjectProperty<HMessage.Direction> getDestinationProperty() { public SimpleObjectProperty<HMessage.Direction> getDestinationProperty() {

View File

@ -2,6 +2,7 @@ package gearth.services.scheduler;
import gearth.protocol.HConnection; import gearth.protocol.HConnection;
import gearth.protocol.HMessage; import gearth.protocol.HMessage;
import gearth.protocol.HPacket;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashSet; import java.util.HashSet;
@ -36,11 +37,13 @@ public class Scheduler<T extends ScheduleItem> {
Interval cur = item.getDelayProperty().get(); Interval cur = item.getDelayProperty().get();
for (int i = 0; i < changed; i++) { for (int i = 0; i < changed; i++) {
if ((t - i) % cur.getDelay() == cur.getOffset()) { if ((t - i) % cur.getDelay() == cur.getOffset()) {
HPacket hPacket = new HPacket(item.getPacketAsStringProperty().getName());
if (item.getDestinationProperty().get() == HMessage.Direction.TOSERVER) { if (item.getDestinationProperty().get() == HMessage.Direction.TOSERVER) {
connection.sendToServerAsync(item.getPacketProperty().get()); connection.sendToServer(hPacket);
} }
else { else {
connection.sendToClientAsync(item.getPacketProperty().get()); connection.sendToClient(hPacket);
} }
} }
} }

View File

@ -15,21 +15,15 @@ import javafx.beans.property.SimpleStringProperty;
public class InteractableScheduleItem extends ScheduleItem implements StringifyAble { public class InteractableScheduleItem extends ScheduleItem implements StringifyAble {
private SimpleStringProperty packetAsStringProperty;
public InteractableScheduleItem(int index, boolean paused, Interval delay, HPacket packet, String inputPacket, HMessage.Direction destination) { public InteractableScheduleItem(int index, boolean paused, Interval delay, String inputPacket, HMessage.Direction destination) {
super(index, paused, delay, packet, destination); super(index, paused, delay, inputPacket, destination);
this.packetAsStringProperty = new SimpleStringProperty(inputPacket);
} }
public InteractableScheduleItem(String stringifyAbleRepresentation) { public InteractableScheduleItem(String stringifyAbleRepresentation) {
constructFromString(stringifyAbleRepresentation); constructFromString(stringifyAbleRepresentation);
} }
public SimpleStringProperty getPacketAsStringProperty() {
return packetAsStringProperty;
}
private Observable<OnDeleteListener> onDeleteObservable = new Observable<>(OnDeleteListener::onDelete); private Observable<OnDeleteListener> onDeleteObservable = new Observable<>(OnDeleteListener::onDelete);
public void onDelete(OnDeleteListener listener) { public void onDelete(OnDeleteListener listener) {
onDeleteObservable.addListener(listener); onDeleteObservable.addListener(listener);
@ -72,8 +66,6 @@ public class InteractableScheduleItem extends ScheduleItem implements StringifyA
.append("\t") .append("\t")
.append(getDelayProperty().get().toString()) .append(getDelayProperty().get().toString())
.append("\t") .append("\t")
// .append(getPacketProperty().get().toString())
// .append("\t")
.append(getDestinationProperty().get().name()) .append(getDestinationProperty().get().name())
.append("\t") .append("\t")
.append(getPacketAsStringProperty().get()); .append(getPacketAsStringProperty().get());
@ -87,13 +79,10 @@ public class InteractableScheduleItem extends ScheduleItem implements StringifyA
int index = Integer.parseInt(parts[0]); int index = Integer.parseInt(parts[0]);
boolean paused = parts[1].equals("true"); boolean paused = parts[1].equals("true");
Interval delay = new Interval(parts[2]); Interval delay = new Interval(parts[2]);
// HPacket packet = new HPacket(parts[3]);
HMessage.Direction direction = parts[3].equals(HMessage.Direction.TOSERVER.name()) ? HMessage.Direction.TOSERVER : HMessage.Direction.TOCLIENT; HMessage.Direction direction = parts[3].equals(HMessage.Direction.TOSERVER.name()) ? HMessage.Direction.TOSERVER : HMessage.Direction.TOCLIENT;
String packetAsString = parts[4]; String packetAsString = parts[4];
HPacket packet = new HPacket(packetAsString);
construct(index, paused, delay, packet, direction); construct(index, paused, delay, packetAsString, direction);
this.packetAsStringProperty = new SimpleStringProperty(packetAsString);
} }
} }