From fa2bd58408b2728f1e5b2f07750dcc0cc2ff0f53 Mon Sep 17 00:00:00 2001 From: Cedric Date: Fri, 25 Oct 2024 14:38:14 +0200 Subject: [PATCH 01/20] fix: issue with threads blocking each other --- .../com/troblecodings/signals/handler/SignalStateHandler.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/troblecodings/signals/handler/SignalStateHandler.java b/src/main/java/com/troblecodings/signals/handler/SignalStateHandler.java index b5b3be404..d3f09ade3 100644 --- a/src/main/java/com/troblecodings/signals/handler/SignalStateHandler.java +++ b/src/main/java/com/troblecodings/signals/handler/SignalStateHandler.java @@ -113,9 +113,11 @@ public static void runTaskWhenSignalLoaded(final SignalStateInfo info, if (!info.isValid() || info.worldNullOrClientSide()) return; if (isSignalLoaded(info)) { + final Map properties; synchronized (CURRENTLY_LOADED_STATES) { - listener.update(info, CURRENTLY_LOADED_STATES.get(info), ChangedState.UPDATED); + properties = CURRENTLY_LOADED_STATES.get(info); } + listener.update(info, properties, ChangedState.UPDATED); } else { synchronized (TASKS_WHEN_LOAD) { final List list = TASKS_WHEN_LOAD.computeIfAbsent(info, From 32eb77072ceb02c7ea2e36f7cdcb99cca54b6ffe Mon Sep 17 00:00:00 2001 From: Uhutown Date: Sat, 26 Oct 2024 12:52:17 +0200 Subject: [PATCH 02/20] ref: better code performance with sync statemets --- .../signals/handler/NameHandler.java | 19 ++++++++++--------- .../signals/handler/SignalStateHandler.java | 11 ++++++----- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/src/main/java/com/troblecodings/signals/handler/NameHandler.java b/src/main/java/com/troblecodings/signals/handler/NameHandler.java index bd710ef7f..ab1c81f5d 100644 --- a/src/main/java/com/troblecodings/signals/handler/NameHandler.java +++ b/src/main/java/com/troblecodings/signals/handler/NameHandler.java @@ -144,9 +144,7 @@ private static ByteBuffer packToBuffer(final BlockPos pos, final String name) { } public static boolean isNameLoaded(final StateInfo info) { - synchronized (ALL_NAMES) { - return ALL_NAMES.containsKey(info); - } + return ALL_NAMES.containsKey(info); } public static void runTaskWhenNameLoaded(final StateInfo info, @@ -154,9 +152,11 @@ public static void runTaskWhenNameLoaded(final StateInfo info, if (!info.isValid() || info.worldNullOrClientSide()) return; if (isNameLoaded(info)) { + final String name; synchronized (ALL_NAMES) { - listener.update(info, ALL_NAMES.get(info), ChangedState.UPDATED); + name = ALL_NAMES.get(info); } + listener.update(info, name, ChangedState.UPDATED); } else { synchronized (TASKS_WHEN_LOAD) { final List list = TASKS_WHEN_LOAD.computeIfAbsent(info, @@ -361,12 +361,13 @@ public static void loadNames(final List infos, ALL_NAMES.put(info.info, name); } sendToAll(info.info, name); + final List tasks; synchronized (TASKS_WHEN_LOAD) { - final List tasks = TASKS_WHEN_LOAD.remove(info.info); - if (tasks != null) { - tasks.forEach(listener -> listener.update(info.info, name, - ChangedState.ADDED_TO_CACHE)); - } + tasks = TASKS_WHEN_LOAD.remove(info.info); + } + if (tasks != null) { + tasks.forEach(listener -> listener.update(info.info, name, + ChangedState.ADDED_TO_CACHE)); } }); }); diff --git a/src/main/java/com/troblecodings/signals/handler/SignalStateHandler.java b/src/main/java/com/troblecodings/signals/handler/SignalStateHandler.java index d3f09ade3..ad4265c98 100644 --- a/src/main/java/com/troblecodings/signals/handler/SignalStateHandler.java +++ b/src/main/java/com/troblecodings/signals/handler/SignalStateHandler.java @@ -562,12 +562,13 @@ public static void loadSignals(final List signals, } sendToAll(info.info, properties); updateListeners(info.info, properties, ChangedState.ADDED_TO_CACHE); + final List tasks; synchronized (TASKS_WHEN_LOAD) { - final List tasks = TASKS_WHEN_LOAD.remove(info.info); - if (tasks != null) { - tasks.forEach(listener -> listener.update(info.info, properties, - ChangedState.ADDED_TO_CACHE)); - } + tasks = TASKS_WHEN_LOAD.remove(info.info); + } + if (tasks != null) { + tasks.forEach(listener -> listener.update(info.info, properties, + ChangedState.ADDED_TO_CACHE)); } }); }); From 07add1f261aefde326aa1e1044cf0cf6120ad556 Mon Sep 17 00:00:00 2001 From: Philipp Date: Sat, 26 Oct 2024 17:30:09 +0200 Subject: [PATCH 03/20] fix: wn blinking --- .../assets/opensignals/modeldefinitions/wnsignal.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/resources/assets/opensignals/modeldefinitions/wnsignal.json b/src/main/resources/assets/opensignals/modeldefinitions/wnsignal.json index 658f6e7b5..1c19eb6fc 100644 --- a/src/main/resources/assets/opensignals/modeldefinitions/wnsignal.json +++ b/src/main/resources/assets/opensignals/modeldefinitions/wnsignal.json @@ -83,7 +83,8 @@ { "blockstate":"hasandis(WNTYPE) && with(WNCROSS.BLINK)", "retexture":{ - "lamp_1": "lamp_white_blink" + "lamp_1_north": "lamp_white_blink", + "lamp_1_south": "lamp_white_blink" } } ] From 705090cdfbeda199a5c912c4c0b8f863d561a4a9 Mon Sep 17 00:00:00 2001 From: Cedric Date: Sun, 27 Oct 2024 17:49:32 +0100 Subject: [PATCH 04/20] fix: NPE in SignalBoxPathway --- .../signals/signalbox/SignalBoxPathway.java | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/troblecodings/signals/signalbox/SignalBoxPathway.java b/src/main/java/com/troblecodings/signals/signalbox/SignalBoxPathway.java index 91d6f76b7..86c8302a0 100644 --- a/src/main/java/com/troblecodings/signals/signalbox/SignalBoxPathway.java +++ b/src/main/java/com/troblecodings/signals/signalbox/SignalBoxPathway.java @@ -621,9 +621,15 @@ private void resetAllTrainNumbers() { } private void resetAllTrainNumbers(final List trainNumberDisplays) { - if (grid != null && trainNumberDisplays != null) - trainNumberDisplays.forEach(ident -> grid.getNode(ident.point).getOption(ident.mode) - .orElse(new PathOptionEntry()).removeEntry(PathEntryType.TRAINNUMBER)); + if (grid != null && trainNumberDisplays != null) { + trainNumberDisplays.forEach(ident -> { + final SignalBoxNode node = grid.getNode(ident.point); + if (node == null) + return; + node.getOption(ident.mode).orElse(new PathOptionEntry()) + .removeEntry(PathEntryType.TRAINNUMBER); + }); + } } public void deactivateAllOutputsOnPathway() { From f04630efe8c74cbcdb29bb2373a9b0fdec00b8b0 Mon Sep 17 00:00:00 2001 From: Cedric Date: Sun, 27 Oct 2024 18:14:20 +0100 Subject: [PATCH 05/20] hopefully fix: issues in updateing previous pathaways --- .../troblecodings/signals/signalbox/SignalBoxPathway.java | 5 ++++- .../troblecodings/signals/signalbox/config/SignalConfig.java | 5 +++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/troblecodings/signals/signalbox/SignalBoxPathway.java b/src/main/java/com/troblecodings/signals/signalbox/SignalBoxPathway.java index 86c8302a0..20b359de1 100644 --- a/src/main/java/com/troblecodings/signals/signalbox/SignalBoxPathway.java +++ b/src/main/java/com/troblecodings/signals/signalbox/SignalBoxPathway.java @@ -156,7 +156,10 @@ public void setPathStatus(final EnumPathUsage status) { public void updatePrevious() { if (grid == null) return; - grid.updatePrevious(this); + loadTileAndExecute(tile -> { + grid = tile.getSignalBoxGrid(); + grid.updatePrevious(this); + }); } protected SignalStateInfo lastSignalInfo = null; diff --git a/src/main/java/com/troblecodings/signals/signalbox/config/SignalConfig.java b/src/main/java/com/troblecodings/signals/signalbox/config/SignalConfig.java index 340bc0888..ea0ad3126 100644 --- a/src/main/java/com/troblecodings/signals/signalbox/config/SignalConfig.java +++ b/src/main/java/com/troblecodings/signals/signalbox/config/SignalConfig.java @@ -141,9 +141,10 @@ private void loadWithoutPredicate(final List values, .filter(entry -> oldProperties.containsKey(entry.getKey())) .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue))); }); - if (!propertiesToSet.isEmpty()) + if (!propertiesToSet.isEmpty()) { SignalStateHandler.setStates(current, propertiesToSet); - pathway.updatePrevious(); + pathway.updatePrevious(); + } }); } } From eb3b3dd8d33faf94a882f7a6e3660ff314d4c204 Mon Sep 17 00:00:00 2001 From: Cedric Date: Sun, 27 Oct 2024 18:23:40 +0100 Subject: [PATCH 06/20] ref: redone last commit, added debug output --- .../com/troblecodings/signals/signalbox/SignalBoxGrid.java | 5 +++++ .../troblecodings/signals/signalbox/SignalBoxPathway.java | 5 +---- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/troblecodings/signals/signalbox/SignalBoxGrid.java b/src/main/java/com/troblecodings/signals/signalbox/SignalBoxGrid.java index c7b77ac96..234ca7cee 100644 --- a/src/main/java/com/troblecodings/signals/signalbox/SignalBoxGrid.java +++ b/src/main/java/com/troblecodings/signals/signalbox/SignalBoxGrid.java @@ -87,6 +87,11 @@ private void onWayAdd(final SignalBoxPathway pathway) { startsToPath.put(pathway.getFirstPoint(), pathway); endsToPath.put(pathway.getLastPoint(), pathway); updatePrevious(pathway); + System.out.println("Updateing Previous for " + pathway + "!"); + System.out.println("Call: "); + for (final StackTraceElement el : Thread.currentThread().getStackTrace()) { + System.out.println(" " + el); + } } public List getGreenSignals() { diff --git a/src/main/java/com/troblecodings/signals/signalbox/SignalBoxPathway.java b/src/main/java/com/troblecodings/signals/signalbox/SignalBoxPathway.java index 20b359de1..86c8302a0 100644 --- a/src/main/java/com/troblecodings/signals/signalbox/SignalBoxPathway.java +++ b/src/main/java/com/troblecodings/signals/signalbox/SignalBoxPathway.java @@ -156,10 +156,7 @@ public void setPathStatus(final EnumPathUsage status) { public void updatePrevious() { if (grid == null) return; - loadTileAndExecute(tile -> { - grid = tile.getSignalBoxGrid(); - grid.updatePrevious(this); - }); + grid.updatePrevious(this); } protected SignalStateInfo lastSignalInfo = null; From 3f5e178fed920eb8942fba0c305cade9f28e7e66 Mon Sep 17 00:00:00 2001 From: Cedric Date: Sun, 27 Oct 2024 18:33:53 +0100 Subject: [PATCH 07/20] ref: changed location of debug --- .../signals/signalbox/SignalBoxGrid.java | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/troblecodings/signals/signalbox/SignalBoxGrid.java b/src/main/java/com/troblecodings/signals/signalbox/SignalBoxGrid.java index 234ca7cee..5097d919e 100644 --- a/src/main/java/com/troblecodings/signals/signalbox/SignalBoxGrid.java +++ b/src/main/java/com/troblecodings/signals/signalbox/SignalBoxGrid.java @@ -87,11 +87,6 @@ private void onWayAdd(final SignalBoxPathway pathway) { startsToPath.put(pathway.getFirstPoint(), pathway); endsToPath.put(pathway.getLastPoint(), pathway); updatePrevious(pathway); - System.out.println("Updateing Previous for " + pathway + "!"); - System.out.println("Call: "); - for (final StackTraceElement el : Thread.currentThread().getStackTrace()) { - System.out.println(" " + el); - } } public List getGreenSignals() { @@ -191,6 +186,12 @@ protected void updatePrevious(final SignalBoxPathway pathway) { if (previousPath != null) { previousPath.setSignals(); } + System.out.println("Updateing Previous for " + pathway + "!"); + System.out.println("Previous: " + previousPath); + System.out.println("Call: "); + for (final StackTraceElement el : Thread.currentThread().getStackTrace()) { + System.out.println(" " + el); + } } public void resetAllPathways() { From 896a38d85d5ca3a983edb19f801b8d7f050969e9 Mon Sep 17 00:00:00 2001 From: Cedric Date: Sun, 27 Oct 2024 18:53:59 +0100 Subject: [PATCH 08/20] ref: changed system for updateing pws --- .../signals/signalbox/SignalBoxGrid.java | 1 + .../signals/signalbox/SignalBoxPathway.java | 17 ++++++++--------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/troblecodings/signals/signalbox/SignalBoxGrid.java b/src/main/java/com/troblecodings/signals/signalbox/SignalBoxGrid.java index 5097d919e..ed23dc17d 100644 --- a/src/main/java/com/troblecodings/signals/signalbox/SignalBoxGrid.java +++ b/src/main/java/com/troblecodings/signals/signalbox/SignalBoxGrid.java @@ -131,6 +131,7 @@ protected void resetPathway(final SignalBoxPathway pathway) { updatePrevious(pathway); this.startsToPath.remove(pathway.getFirstPoint()); this.endsToPath.remove(pathway.getLastPoint()); + pathway.postReset(); } protected void updateToNet(final SignalBoxPathway pathway) { diff --git a/src/main/java/com/troblecodings/signals/signalbox/SignalBoxPathway.java b/src/main/java/com/troblecodings/signals/signalbox/SignalBoxPathway.java index 86c8302a0..7df624bc2 100644 --- a/src/main/java/com/troblecodings/signals/signalbox/SignalBoxPathway.java +++ b/src/main/java/com/troblecodings/signals/signalbox/SignalBoxPathway.java @@ -237,10 +237,6 @@ private void updatePreSignals() { final MainSignalIdentifier startSignal = data.getStartSignal(); if (startSignal == null) return; - final SignalBoxPathway next = getNextPathway(); - if (next != null && (next.isEmptyOrBroken() || next.isBlocked)) { - return; - } final StateInfo identifier = new StateInfo(tile.getWorld(), tile.getPos()); final Signal first = SignalBoxHandler.getSignal(identifier, startSignal.pos); if (first == null) @@ -445,11 +441,14 @@ public void resetPathway(final @Nullable Point point) { resetAllTrainNumbers(); sendTrainNumberUpdates(); resetProtectionWay(); - final SignalBoxPathway next = getNextPathway(); - if (next != null) { - next.updatePreSignals(); - next.updateSignalStates(); - } + } + } + + public void postReset() { + final SignalBoxPathway next = getNextPathway(); + if (next != null) { + next.updatePreSignals(); + next.updateSignalStates(); } } From 04ce08d721d12620ce9a1707c61fe28a592b51c4 Mon Sep 17 00:00:00 2001 From: Cedric Date: Sun, 27 Oct 2024 19:29:22 +0100 Subject: [PATCH 09/20] ref: removed debug --- .../com/troblecodings/signals/signalbox/SignalBoxGrid.java | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/main/java/com/troblecodings/signals/signalbox/SignalBoxGrid.java b/src/main/java/com/troblecodings/signals/signalbox/SignalBoxGrid.java index ed23dc17d..350e3a23a 100644 --- a/src/main/java/com/troblecodings/signals/signalbox/SignalBoxGrid.java +++ b/src/main/java/com/troblecodings/signals/signalbox/SignalBoxGrid.java @@ -187,12 +187,6 @@ protected void updatePrevious(final SignalBoxPathway pathway) { if (previousPath != null) { previousPath.setSignals(); } - System.out.println("Updateing Previous for " + pathway + "!"); - System.out.println("Previous: " + previousPath); - System.out.println("Call: "); - for (final StackTraceElement el : Thread.currentThread().getStackTrace()) { - System.out.println(" " + el); - } } public void resetAllPathways() { From ad9881839d9cb048b05aa5da6eafe7bded18bfdc Mon Sep 17 00:00:00 2001 From: Cedric Date: Sun, 27 Oct 2024 20:00:04 +0100 Subject: [PATCH 10/20] ref: added Thread Pool to update signals not in main thread --- .../signalbox/config/SignalConfig.java | 24 +++++++++++-------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/src/main/java/com/troblecodings/signals/signalbox/config/SignalConfig.java b/src/main/java/com/troblecodings/signals/signalbox/config/SignalConfig.java index ea0ad3126..a8e9fe626 100644 --- a/src/main/java/com/troblecodings/signals/signalbox/config/SignalConfig.java +++ b/src/main/java/com/troblecodings/signals/signalbox/config/SignalConfig.java @@ -3,6 +3,8 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; import java.util.stream.Collectors; import com.google.common.collect.Maps; @@ -25,6 +27,7 @@ public final class SignalConfig { private static final LoadHolder> LOAD_HOLDER = new LoadHolder<>( SignalConfig.class); + private final ExecutorService service = Executors.newCachedThreadPool(); private final SignalBoxPathway pathway; public SignalConfig(final SignalBoxPathway pathway) { @@ -50,7 +53,7 @@ public void change(final ConfigInfo info) { final List shuntingValues = OneSignalNonPredicateConfigParser.SHUNTINGCONFIGS .get(currentSignal); if (shuntingValues != null && info.currentinfo.isValid()) { - loadWithoutPredicate(shuntingValues, info.currentinfo); + service.execute(() -> loadWithoutPredicate(shuntingValues, info.currentinfo)); } } } @@ -97,16 +100,17 @@ public void loadDisable(final ConfigInfo info) { } private void changeIfPresent(final List values, final ConfigInfo info) { - loadSignalAndRunTask(info.currentinfo, (stateInfo, oldProperties, _u) -> { - if (info.nextinfo != null) { - loadSignalAndRunTask(info.nextinfo, (nextInfo, nextProperties, _u2) -> { - changeSignals(values, info, oldProperties, nextProperties); - }); - } else { - changeSignals(values, info, oldProperties, null); - } + service.execute(() -> { + loadSignalAndRunTask(info.currentinfo, (stateInfo, oldProperties, _u) -> { + if (info.nextinfo != null) { + loadSignalAndRunTask(info.nextinfo, (nextInfo, nextProperties, _u2) -> { + changeSignals(values, info, oldProperties, nextProperties); + }); + } else { + changeSignals(values, info, oldProperties, null); + } + }); }); - } private void changeSignals(final List values, final ConfigInfo info, From 1443e5c44c1e25896d5df55f5973f22efc99f7e1 Mon Sep 17 00:00:00 2001 From: Cedric Date: Sun, 27 Oct 2024 20:05:31 +0100 Subject: [PATCH 11/20] ref: changed to static reference --- .../signalbox/config/SignalConfig.java | 38 +++++++++---------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/src/main/java/com/troblecodings/signals/signalbox/config/SignalConfig.java b/src/main/java/com/troblecodings/signals/signalbox/config/SignalConfig.java index a8e9fe626..d8523e697 100644 --- a/src/main/java/com/troblecodings/signals/signalbox/config/SignalConfig.java +++ b/src/main/java/com/troblecodings/signals/signalbox/config/SignalConfig.java @@ -26,8 +26,8 @@ public final class SignalConfig { private static final LoadHolder> LOAD_HOLDER = new LoadHolder<>( SignalConfig.class); + private static final ExecutorService SERVICE = Executors.newCachedThreadPool(); - private final ExecutorService service = Executors.newCachedThreadPool(); private final SignalBoxPathway pathway; public SignalConfig(final SignalBoxPathway pathway) { @@ -53,7 +53,7 @@ public void change(final ConfigInfo info) { final List shuntingValues = OneSignalNonPredicateConfigParser.SHUNTINGCONFIGS .get(currentSignal); if (shuntingValues != null && info.currentinfo.isValid()) { - service.execute(() -> loadWithoutPredicate(shuntingValues, info.currentinfo)); + loadWithoutPredicate(shuntingValues, info.currentinfo); } } } @@ -100,16 +100,14 @@ public void loadDisable(final ConfigInfo info) { } private void changeIfPresent(final List values, final ConfigInfo info) { - service.execute(() -> { - loadSignalAndRunTask(info.currentinfo, (stateInfo, oldProperties, _u) -> { - if (info.nextinfo != null) { - loadSignalAndRunTask(info.nextinfo, (nextInfo, nextProperties, _u2) -> { - changeSignals(values, info, oldProperties, nextProperties); - }); - } else { - changeSignals(values, info, oldProperties, null); - } - }); + loadSignalAndRunTask(info.currentinfo, (stateInfo, oldProperties, _u) -> { + if (info.nextinfo != null) { + loadSignalAndRunTask(info.nextinfo, (nextInfo, nextProperties, _u2) -> { + changeSignals(values, info, oldProperties, nextProperties); + }); + } else { + changeSignals(values, info, oldProperties, null); + } }); } @@ -155,12 +153,14 @@ private void loadWithoutPredicate(final List values, private static void loadSignalAndRunTask(final SignalStateInfo info, final SignalStateListener task) { - final boolean isSignalLoaded = SignalStateHandler.isSignalLoaded(info); - if (!isSignalLoaded) { - SignalStateHandler.loadSignal(new SignalStateLoadHoler(info, LOAD_HOLDER)); - task.andThen((_u1, _u2, _u3) -> SignalStateHandler - .unloadSignal(new SignalStateLoadHoler(info, LOAD_HOLDER))); - } - SignalStateHandler.runTaskWhenSignalLoaded(info, task); + SERVICE.execute(() -> { + final boolean isSignalLoaded = SignalStateHandler.isSignalLoaded(info); + if (!isSignalLoaded) { + SignalStateHandler.loadSignal(new SignalStateLoadHoler(info, LOAD_HOLDER)); + task.andThen((_u1, _u2, _u3) -> SignalStateHandler + .unloadSignal(new SignalStateLoadHoler(info, LOAD_HOLDER))); + } + SignalStateHandler.runTaskWhenSignalLoaded(info, task); + }); } } From a439c8d2c91baa449a61c5cc62774e9b7927794d Mon Sep 17 00:00:00 2001 From: Cedric Date: Sun, 27 Oct 2024 20:27:18 +0100 Subject: [PATCH 12/20] fix: NPE in PW --- .../com/troblecodings/signals/signalbox/SignalBoxPathway.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/java/com/troblecodings/signals/signalbox/SignalBoxPathway.java b/src/main/java/com/troblecodings/signals/signalbox/SignalBoxPathway.java index 7df624bc2..3d84acc1d 100644 --- a/src/main/java/com/troblecodings/signals/signalbox/SignalBoxPathway.java +++ b/src/main/java/com/troblecodings/signals/signalbox/SignalBoxPathway.java @@ -609,6 +609,8 @@ private void sendTrainNumberUpdates() { buffer.putInt(trainNumberDisplays.size()); trainNumberDisplays.forEach(ident -> { final SignalBoxNode node = grid.getNode(ident.point); + if (node == null) + return; node.getPoint().writeNetwork(buffer); node.writeNetwork(buffer); }); From 40528e31805d29aa360d60d023a4ed47f17e78a4 Mon Sep 17 00:00:00 2001 From: Cedric Date: Sun, 27 Oct 2024 20:29:28 +0100 Subject: [PATCH 13/20] ref: added code to fix box --- .../com/troblecodings/signals/signalbox/SignalBoxGrid.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/main/java/com/troblecodings/signals/signalbox/SignalBoxGrid.java b/src/main/java/com/troblecodings/signals/signalbox/SignalBoxGrid.java index 350e3a23a..e18ae625a 100644 --- a/src/main/java/com/troblecodings/signals/signalbox/SignalBoxGrid.java +++ b/src/main/java/com/troblecodings/signals/signalbox/SignalBoxGrid.java @@ -192,6 +192,12 @@ protected void updatePrevious(final SignalBoxPathway pathway) { public void resetAllPathways() { ImmutableSet.copyOf(this.startsToPath.values()).forEach(this::resetPathway); clearPaths(); + modeGrid.values().forEach(node -> { + node.forEach(mode -> { + node.getOption(mode).ifPresent(entry -> entry.getEntry(PathEntryType.PATHUSAGE) + .ifPresent(_u -> entry.removeEntry(PathEntryType.PATHUSAGE))); + }); + }); } public void resetAllSignals() { From 864e6a4ebb79cd72aa5316bf2fd7865fd6eb2923 Mon Sep 17 00:00:00 2001 From: Cedric Date: Sun, 27 Oct 2024 20:51:07 +0100 Subject: [PATCH 14/20] ref: changed system so THREAD calls SERVER not NEW THREAD --- .../signals/signalbox/config/SignalConfig.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/troblecodings/signals/signalbox/config/SignalConfig.java b/src/main/java/com/troblecodings/signals/signalbox/config/SignalConfig.java index d8523e697..c61246de1 100644 --- a/src/main/java/com/troblecodings/signals/signalbox/config/SignalConfig.java +++ b/src/main/java/com/troblecodings/signals/signalbox/config/SignalConfig.java @@ -129,7 +129,7 @@ private void changeSignals(final List values, final ConfigInfo i }); if (!propertiesToSet.isEmpty()) { SignalStateHandler.setStates(info.currentinfo, propertiesToSet); - pathway.updatePrevious(); + updatePreviousPathway(info.currentinfo); } } @@ -145,12 +145,16 @@ private void loadWithoutPredicate(final List values, }); if (!propertiesToSet.isEmpty()) { SignalStateHandler.setStates(current, propertiesToSet); - pathway.updatePrevious(); + updatePreviousPathway(current); } }); } } + private void updatePreviousPathway(final SignalStateInfo info) { + info.world.getMinecraftServer().addScheduledTask(() -> pathway.updatePrevious()); + } + private static void loadSignalAndRunTask(final SignalStateInfo info, final SignalStateListener task) { SERVICE.execute(() -> { From 72c1d6c0a7d5af1229fb412c873bf4601734baa4 Mon Sep 17 00:00:00 2001 From: Cedric Date: Sun, 27 Oct 2024 21:02:20 +0100 Subject: [PATCH 15/20] ref: removed ThreadPool --- .../signalbox/config/SignalConfig.java | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/src/main/java/com/troblecodings/signals/signalbox/config/SignalConfig.java b/src/main/java/com/troblecodings/signals/signalbox/config/SignalConfig.java index c61246de1..0d47abad1 100644 --- a/src/main/java/com/troblecodings/signals/signalbox/config/SignalConfig.java +++ b/src/main/java/com/troblecodings/signals/signalbox/config/SignalConfig.java @@ -3,8 +3,6 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; import java.util.stream.Collectors; import com.google.common.collect.Maps; @@ -26,7 +24,6 @@ public final class SignalConfig { private static final LoadHolder> LOAD_HOLDER = new LoadHolder<>( SignalConfig.class); - private static final ExecutorService SERVICE = Executors.newCachedThreadPool(); private final SignalBoxPathway pathway; @@ -157,14 +154,12 @@ private void updatePreviousPathway(final SignalStateInfo info) { private static void loadSignalAndRunTask(final SignalStateInfo info, final SignalStateListener task) { - SERVICE.execute(() -> { - final boolean isSignalLoaded = SignalStateHandler.isSignalLoaded(info); - if (!isSignalLoaded) { - SignalStateHandler.loadSignal(new SignalStateLoadHoler(info, LOAD_HOLDER)); - task.andThen((_u1, _u2, _u3) -> SignalStateHandler - .unloadSignal(new SignalStateLoadHoler(info, LOAD_HOLDER))); - } - SignalStateHandler.runTaskWhenSignalLoaded(info, task); - }); + final boolean isSignalLoaded = SignalStateHandler.isSignalLoaded(info); + if (!isSignalLoaded) { + SignalStateHandler.loadSignal(new SignalStateLoadHoler(info, LOAD_HOLDER)); + task.andThen((_u1, _u2, _u3) -> SignalStateHandler + .unloadSignal(new SignalStateLoadHoler(info, LOAD_HOLDER))); + } + SignalStateHandler.runTaskWhenSignalLoaded(info, task); } } From ad44661e2c61fc54392e140858336a499abccb31 Mon Sep 17 00:00:00 2001 From: Cedric Date: Sun, 27 Oct 2024 21:15:27 +0100 Subject: [PATCH 16/20] ref: changed to old update system --- .../signals/signalbox/SignalBoxGrid.java | 13 +++++++++++-- .../signals/signalbox/config/SignalConfig.java | 3 ++- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/troblecodings/signals/signalbox/SignalBoxGrid.java b/src/main/java/com/troblecodings/signals/signalbox/SignalBoxGrid.java index e18ae625a..451e2c75b 100644 --- a/src/main/java/com/troblecodings/signals/signalbox/SignalBoxGrid.java +++ b/src/main/java/com/troblecodings/signals/signalbox/SignalBoxGrid.java @@ -183,10 +183,19 @@ protected void addPathway(final PathwayData data) { } protected void updatePrevious(final SignalBoxPathway pathway) { - SignalBoxPathway previousPath = endsToPath.get(pathway.getFirstPoint()); - if (previousPath != null) { + SignalBoxPathway previousPath = pathway; + int count = 0; + while ((previousPath = endsToPath.get(previousPath.getFirstPoint())) != null) { + if (count > endsToPath.size()) { + break; + } previousPath.setSignals(); } + if (count == 0) { + if (OpenSignalsMain.isDebug()) { + OpenSignalsMain.getLogger().debug("Could not find previous! " + pathway); + } + } } public void resetAllPathways() { diff --git a/src/main/java/com/troblecodings/signals/signalbox/config/SignalConfig.java b/src/main/java/com/troblecodings/signals/signalbox/config/SignalConfig.java index 0d47abad1..1de9eaa57 100644 --- a/src/main/java/com/troblecodings/signals/signalbox/config/SignalConfig.java +++ b/src/main/java/com/troblecodings/signals/signalbox/config/SignalConfig.java @@ -149,7 +149,8 @@ private void loadWithoutPredicate(final List values, } private void updatePreviousPathway(final SignalStateInfo info) { - info.world.getMinecraftServer().addScheduledTask(() -> pathway.updatePrevious()); + // info.world.getMinecraftServer().addScheduledTask(() -> + // pathway.updatePrevious()); } private static void loadSignalAndRunTask(final SignalStateInfo info, From 1c117e6c7a3aa6be69a4c2a093d29e7e13dad871 Mon Sep 17 00:00:00 2001 From: Cedric Date: Sun, 27 Oct 2024 21:33:11 +0100 Subject: [PATCH 17/20] fix: missing UI update; ref: changed SignalConfig back to static --- .../signalbox/InterSignalBoxPathway.java | 1 + .../signals/signalbox/SignalBoxPathway.java | 10 +++----- .../signalbox/config/SignalConfig.java | 25 ++++++------------- 3 files changed, 12 insertions(+), 24 deletions(-) diff --git a/src/main/java/com/troblecodings/signals/signalbox/InterSignalBoxPathway.java b/src/main/java/com/troblecodings/signals/signalbox/InterSignalBoxPathway.java index 6d1302b13..1d1d0f83a 100644 --- a/src/main/java/com/troblecodings/signals/signalbox/InterSignalBoxPathway.java +++ b/src/main/java/com/troblecodings/signals/signalbox/InterSignalBoxPathway.java @@ -211,6 +211,7 @@ public boolean tryBlock(final BlockPos position) { pathwayToBlock = (InterSignalBoxPathway) pw; pathwayToBlock.setPathStatus(EnumPathUsage.BLOCKED); pathwayToBlock.updateTrainNumber(trainNumber); + otherGrid.updateToNet(pathwayToBlock); }); } return result; diff --git a/src/main/java/com/troblecodings/signals/signalbox/SignalBoxPathway.java b/src/main/java/com/troblecodings/signals/signalbox/SignalBoxPathway.java index 3d84acc1d..1bf9e7432 100644 --- a/src/main/java/com/troblecodings/signals/signalbox/SignalBoxPathway.java +++ b/src/main/java/com/troblecodings/signals/signalbox/SignalBoxPathway.java @@ -43,7 +43,6 @@ public class SignalBoxPathway implements IChunkLoadable { protected final PathwayData data; - protected final SignalConfig config; protected boolean isBlocked; protected boolean isAutoPathway = false; @@ -58,7 +57,6 @@ public void setTile(final SignalBoxTileEntity tile) { } public SignalBoxPathway(final PathwayData data) { - this.config = new SignalConfig(this); this.data = data; this.originalFirstPoint = new Point(data.getFirstPoint()); updatePathwayToAutomatic(); @@ -205,7 +203,7 @@ protected void setSignals(final SignalStateInfo lastSignal) { if (first == null) return; final SignalStateInfo firstInfo = new SignalStateInfo(world, startSignal.pos, first); - config.change(new ConfigInfo(firstInfo, lastSignal, data)); + SignalConfig.change(new ConfigInfo(firstInfo, lastSignal, data)); updatePreSignals(); } final SignalBoxPathway next = getNextPathway(); @@ -225,9 +223,9 @@ protected void setSignals(final SignalStateInfo lastSignal) { new SignalStateInfo(world, position.pos, current), lastSignal, data, position.isRepeater); if (position.guiMode.equals(EnumGuiMode.HP)) { - config.loadDisable(info); + SignalConfig.loadDisable(info); } else { - config.change(info); + SignalConfig.change(info); } }); updateSignalStates(); @@ -247,7 +245,7 @@ private void updatePreSignals() { final Signal current = SignalBoxHandler.getSignal(identifier, posIdent.pos); if (current == null) return; - config.change( + SignalConfig.change( new ConfigInfo(new SignalStateInfo(tile.getWorld(), posIdent.pos, current), firstInfo, data, posIdent.isRepeater)); }); diff --git a/src/main/java/com/troblecodings/signals/signalbox/config/SignalConfig.java b/src/main/java/com/troblecodings/signals/signalbox/config/SignalConfig.java index 1de9eaa57..87daa4a87 100644 --- a/src/main/java/com/troblecodings/signals/signalbox/config/SignalConfig.java +++ b/src/main/java/com/troblecodings/signals/signalbox/config/SignalConfig.java @@ -18,20 +18,16 @@ import com.troblecodings.signals.handler.SignalStateHandler; import com.troblecodings.signals.handler.SignalStateInfo; import com.troblecodings.signals.properties.PredicatedPropertyBase.ConfigProperty; -import com.troblecodings.signals.signalbox.SignalBoxPathway; public final class SignalConfig { private static final LoadHolder> LOAD_HOLDER = new LoadHolder<>( SignalConfig.class); - private final SignalBoxPathway pathway; - - public SignalConfig(final SignalBoxPathway pathway) { - this.pathway = pathway; + private SignalConfig() { } - public void change(final ConfigInfo info) { + public static void change(final ConfigInfo info) { final Signal currentSignal = info.currentinfo.signal; if (info.type.equals(PathType.NORMAL)) { if (info.nextinfo != null && info.nextinfo.isValid()) { @@ -55,7 +51,7 @@ public void change(final ConfigInfo info) { } } - private void loadDefault(final ConfigInfo info) { + private static void loadDefault(final ConfigInfo info) { if (!info.currentinfo.isValid()) return; final List defaultValues = OneSignalPredicateConfigParser.DEFAULTCONFIGS @@ -88,7 +84,7 @@ public static void reset(final ResetInfo info) { }); } - public void loadDisable(final ConfigInfo info) { + public static void loadDisable(final ConfigInfo info) { final List disableValues = OneSignalPredicateConfigParser.DISABLECONFIGS .get(info.currentinfo.signal); if (disableValues != null) { @@ -96,7 +92,7 @@ public void loadDisable(final ConfigInfo info) { } } - private void changeIfPresent(final List values, final ConfigInfo info) { + private static void changeIfPresent(final List values, final ConfigInfo info) { loadSignalAndRunTask(info.currentinfo, (stateInfo, oldProperties, _u) -> { if (info.nextinfo != null) { loadSignalAndRunTask(info.nextinfo, (nextInfo, nextProperties, _u2) -> { @@ -108,7 +104,7 @@ private void changeIfPresent(final List values, final ConfigInfo }); } - private void changeSignals(final List values, final ConfigInfo info, + private static void changeSignals(final List values, final ConfigInfo info, final Map oldProperties, final Map nextProperties) { final Map, Object> object = new HashMap<>(); @@ -126,11 +122,10 @@ private void changeSignals(final List values, final ConfigInfo i }); if (!propertiesToSet.isEmpty()) { SignalStateHandler.setStates(info.currentinfo, propertiesToSet); - updatePreviousPathway(info.currentinfo); } } - private void loadWithoutPredicate(final List values, + private static void loadWithoutPredicate(final List values, final SignalStateInfo current) { if (values != null) { loadSignalAndRunTask(current, (info, oldProperties, _u) -> { @@ -142,17 +137,11 @@ private void loadWithoutPredicate(final List values, }); if (!propertiesToSet.isEmpty()) { SignalStateHandler.setStates(current, propertiesToSet); - updatePreviousPathway(current); } }); } } - private void updatePreviousPathway(final SignalStateInfo info) { - // info.world.getMinecraftServer().addScheduledTask(() -> - // pathway.updatePrevious()); - } - private static void loadSignalAndRunTask(final SignalStateInfo info, final SignalStateListener task) { final boolean isSignalLoaded = SignalStateHandler.isSignalLoaded(info); From aebed96074ca95ee1150a2dfe1ea2505c82289e9 Mon Sep 17 00:00:00 2001 From: Cedric Date: Sun, 27 Oct 2024 23:42:32 +0100 Subject: [PATCH 18/20] fix: missing statement --- .../java/com/troblecodings/signals/signalbox/SignalBoxGrid.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/com/troblecodings/signals/signalbox/SignalBoxGrid.java b/src/main/java/com/troblecodings/signals/signalbox/SignalBoxGrid.java index 451e2c75b..533aecaa2 100644 --- a/src/main/java/com/troblecodings/signals/signalbox/SignalBoxGrid.java +++ b/src/main/java/com/troblecodings/signals/signalbox/SignalBoxGrid.java @@ -190,6 +190,7 @@ protected void updatePrevious(final SignalBoxPathway pathway) { break; } previousPath.setSignals(); + count++; } if (count == 0) { if (OpenSignalsMain.isDebug()) { From c54659b20057f770f9ac8f5adaf2d0aba40de1c8 Mon Sep 17 00:00:00 2001 From: Cedric <103828586+Uhutown@users.noreply.github.com> Date: Fri, 1 Nov 2024 15:24:59 +0100 Subject: [PATCH 19/20] ref: removed debug stuff --- .../com/troblecodings/signals/signalbox/SignalBoxGrid.java | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/main/java/com/troblecodings/signals/signalbox/SignalBoxGrid.java b/src/main/java/com/troblecodings/signals/signalbox/SignalBoxGrid.java index 533aecaa2..39fba3e44 100644 --- a/src/main/java/com/troblecodings/signals/signalbox/SignalBoxGrid.java +++ b/src/main/java/com/troblecodings/signals/signalbox/SignalBoxGrid.java @@ -202,12 +202,6 @@ protected void updatePrevious(final SignalBoxPathway pathway) { public void resetAllPathways() { ImmutableSet.copyOf(this.startsToPath.values()).forEach(this::resetPathway); clearPaths(); - modeGrid.values().forEach(node -> { - node.forEach(mode -> { - node.getOption(mode).ifPresent(entry -> entry.getEntry(PathEntryType.PATHUSAGE) - .ifPresent(_u -> entry.removeEntry(PathEntryType.PATHUSAGE))); - }); - }); } public void resetAllSignals() { From 6a3caf3111ea4966cd705a2ef7a925793e5c8a35 Mon Sep 17 00:00:00 2001 From: Cedric Date: Fri, 1 Nov 2024 15:39:32 +0100 Subject: [PATCH 20/20] ref: changelog and version --- .github/workflows/gradle.yml | 2 +- changelog.md | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/.github/workflows/gradle.yml b/.github/workflows/gradle.yml index 135c7a6e9..994bb0612 100644 --- a/.github/workflows/gradle.yml +++ b/.github/workflows/gradle.yml @@ -30,7 +30,7 @@ jobs: if: endswith(github.ref_name, 'master') && github.ref_protected && github.ref_type == 'branch' runs-on: ubuntu-latest env: - APPVEYOR_BUILD_VERSION: '3.6.2' + APPVEYOR_BUILD_VERSION: '3.6.3' CURSETOKEN: ${{ secrets.CURSETOKEN }} steps: - uses: actions/checkout@v3 diff --git a/changelog.md b/changelog.md index 0308af702..86d983f43 100644 --- a/changelog.md +++ b/changelog.md @@ -1,5 +1,10 @@ # Changelog +## [1.12.2 - 3.6.3] +* fix: threads blocking each other +* ref: better system for pathway updateing and signal setting +* fix: wrong lamp in wn signal + ## [1.12.2 - 3.6.2] * feat: added train length signs * feat: added trainnumber element