mirror of
https://github.com/sirjonasxx/G-Earth.git
synced 2025-01-19 00:26:27 +01:00
fix synchronization Scheduler + code structure update
This commit is contained in:
parent
86c694f8f8
commit
1204666dd8
@ -12,7 +12,9 @@ import main.protocol.HPacket;
|
|||||||
import main.ui.SubForm;
|
import main.ui.SubForm;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by Jonas on 06/04/18.
|
* Created by Jonas on 06/04/18.
|
||||||
@ -49,7 +51,11 @@ public class Scheduler extends SubForm {
|
|||||||
updateUI();
|
updateUI();
|
||||||
|
|
||||||
new Thread(() -> {
|
new Thread(() -> {
|
||||||
long i = 0;
|
long t = System.currentTimeMillis();
|
||||||
|
long changed = 1;
|
||||||
|
|
||||||
|
Set<ScheduleItem> set = new HashSet<>();
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
try {
|
try {
|
||||||
Thread.sleep(1);
|
Thread.sleep(1);
|
||||||
@ -57,17 +63,31 @@ public class Scheduler extends SubForm {
|
|||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
for (ScheduleItem item : scheduleItemList) {
|
set.clear();
|
||||||
|
for (int i = scheduleItemList.size() - 1; i >= 0; i--) {
|
||||||
|
set.add(scheduleItemList.get(i));
|
||||||
|
}
|
||||||
|
|
||||||
|
for (ScheduleItem item : set) {
|
||||||
if (!item.getPausedProperty().get()) {
|
if (!item.getPausedProperty().get()) {
|
||||||
Interval cur = item.getDelayProperty().get();
|
Interval cur = item.getDelayProperty().get();
|
||||||
if (i % cur.getDelay() == cur.getOffset()) {
|
for (int i = 0; i < changed; i++) {
|
||||||
|
if ((t - i) % cur.getDelay() == cur.getOffset()) {
|
||||||
|
if (item.getDestinationProperty().getValue() == HMessage.Side.TOSERVER) {
|
||||||
getHConnection().sendToServerAsync(item.getPacketProperty().get());
|
getHConnection().sendToServerAsync(item.getPacketProperty().get());
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
getHConnection().sendToClient(item.getPacketProperty().get());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
i++;
|
long newT = System.currentTimeMillis();
|
||||||
|
changed = newT - t;
|
||||||
|
t = newT;
|
||||||
}
|
}
|
||||||
}).start();
|
}).start();
|
||||||
|
|
||||||
@ -99,6 +119,22 @@ public class Scheduler extends SubForm {
|
|||||||
new HPacket(txt_packet.getText()),
|
new HPacket(txt_packet.getText()),
|
||||||
rb_incoming.isSelected() ? HMessage.Side.TOCLIENT : HMessage.Side.TOSERVER);
|
rb_incoming.isSelected() ? HMessage.Side.TOCLIENT : HMessage.Side.TOSERVER);
|
||||||
|
|
||||||
|
addItem(newItem);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
|
||||||
|
isBeingEdited.getPacketProperty().set(new HPacket(txt_packet.getText()));
|
||||||
|
isBeingEdited.getDelayProperty().set(new Interval(txt_delay.getText()));
|
||||||
|
isBeingEdited.getDestinationProperty().set(rb_incoming.isSelected() ? HMessage.Side.TOCLIENT : HMessage.Side.TOSERVER);
|
||||||
|
isBeingEdited.isUpdatedTrigger();
|
||||||
|
|
||||||
|
isBeingEdited = null;
|
||||||
|
setInputDefault();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void addItem(ScheduleItem newItem) {
|
||||||
new ScheduleItemContainer(newItem, schedulecontainer, scrollpane);
|
new ScheduleItemContainer(newItem, schedulecontainer, scrollpane);
|
||||||
scheduleItemList.add(newItem);
|
scheduleItemList.add(newItem);
|
||||||
|
|
||||||
@ -136,18 +172,6 @@ public class Scheduler extends SubForm {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
|
|
||||||
isBeingEdited.getPacketProperty().set(new HPacket(txt_packet.getText()));
|
|
||||||
isBeingEdited.getDelayProperty().set(new Interval(txt_delay.getText()));
|
|
||||||
isBeingEdited.getDestinationProperty().set(rb_incoming.isSelected() ? HMessage.Side.TOCLIENT : HMessage.Side.TOSERVER);
|
|
||||||
isBeingEdited.isUpdatedTrigger();
|
|
||||||
|
|
||||||
isBeingEdited = null;
|
|
||||||
setInputDefault();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private void setInputDefault() {
|
private void setInputDefault() {
|
||||||
txt_delay.setText(defaultInterval.toString());
|
txt_delay.setText(defaultInterval.toString());
|
||||||
|
Loading…
Reference in New Issue
Block a user