From 8dce4bc0f041064468c14fd0d0517fb6ac26c719 Mon Sep 17 00:00:00 2001 From: Philipp Date: Sat, 26 Oct 2024 17:30:13 +0200 Subject: [PATCH 1/3] 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 f2c2a48632f4b549f431c3ccd46271f417b06067 Mon Sep 17 00:00:00 2001 From: Cedric Date: Fri, 1 Nov 2024 15:24:12 +0100 Subject: [PATCH 2/3] fix: issues with loading signals and problems with PWs --- .../signals/handler/NameHandler.java | 19 +++++---- .../signals/handler/SignalStateHandler.java | 15 ++++--- .../signalbox/InterSignalBoxPathway.java | 4 +- .../signals/signalbox/SignalBoxGrid.java | 15 ++++++- .../signals/signalbox/SignalBoxPathway.java | 41 +++++++++++-------- .../signalbox/config/SignalConfig.java | 20 ++++----- 6 files changed, 65 insertions(+), 49 deletions(-) diff --git a/src/main/java/com/troblecodings/signals/handler/NameHandler.java b/src/main/java/com/troblecodings/signals/handler/NameHandler.java index cb3cfaf06..cbf736536 100644 --- a/src/main/java/com/troblecodings/signals/handler/NameHandler.java +++ b/src/main/java/com/troblecodings/signals/handler/NameHandler.java @@ -151,9 +151,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, @@ -161,9 +159,11 @@ public static void runTaskWhenNameLoaded(final StateInfo info, if (!info.isValid() || info.isWorldNullOrClientSide()) 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, @@ -373,12 +373,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 de9e01a0e..bace1eab9 100644 --- a/src/main/java/com/troblecodings/signals/handler/SignalStateHandler.java +++ b/src/main/java/com/troblecodings/signals/handler/SignalStateHandler.java @@ -129,9 +129,11 @@ public static void runTaskWhenSignalLoaded(final SignalStateInfo info, if (!info.isValid() || info.isWorldNullOrClientSide()) 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, @@ -575,12 +577,13 @@ public static void loadSignals(final List signals, } sendTo(info.info, properties, player); 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)); } }); }); diff --git a/src/main/java/com/troblecodings/signals/signalbox/InterSignalBoxPathway.java b/src/main/java/com/troblecodings/signals/signalbox/InterSignalBoxPathway.java index f2f78ec81..18ed87e35 100644 --- a/src/main/java/com/troblecodings/signals/signalbox/InterSignalBoxPathway.java +++ b/src/main/java/com/troblecodings/signals/signalbox/InterSignalBoxPathway.java @@ -178,10 +178,12 @@ public boolean tryBlock(final BlockPos position) { final boolean result = super.tryBlock(position); if (result && pathwayToBlock != null) { pathwayToBlock.loadTileAndExecute(otherTile -> { - pathwayToBlock = (InterSignalBoxPathway) otherTile.getSignalBoxGrid() + final SignalBoxGrid otherGrid = otherTile.getSignalBoxGrid(); + pathwayToBlock = (InterSignalBoxPathway) otherGrid .getPathwayByLastPoint(pathwayToBlock.getLastPoint()); pathwayToBlock.setPathStatus(EnumPathUsage.BLOCKED); pathwayToBlock.updateTrainNumber(trainNumber); + otherGrid.updateToNet(pathwayToBlock); }); } return result; diff --git a/src/main/java/com/troblecodings/signals/signalbox/SignalBoxGrid.java b/src/main/java/com/troblecodings/signals/signalbox/SignalBoxGrid.java index 59d82f3e5..99a1f09ef 100644 --- a/src/main/java/com/troblecodings/signals/signalbox/SignalBoxGrid.java +++ b/src/main/java/com/troblecodings/signals/signalbox/SignalBoxGrid.java @@ -132,6 +132,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) { @@ -184,9 +185,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(); + count++; + } + if (count == 0) { + if (OpenSignalsMain.isDebug()) { + OpenSignalsMain.getLogger().debug("Could not find previous! " + pathway); + } } } diff --git a/src/main/java/com/troblecodings/signals/signalbox/SignalBoxPathway.java b/src/main/java/com/troblecodings/signals/signalbox/SignalBoxPathway.java index 3dcda7811..810584b44 100644 --- a/src/main/java/com/troblecodings/signals/signalbox/SignalBoxPathway.java +++ b/src/main/java/com/troblecodings/signals/signalbox/SignalBoxPathway.java @@ -44,7 +44,6 @@ public class SignalBoxPathway implements IChunkLoadable { protected final PathwayData data; - protected final SignalConfig config; protected boolean isBlocked; protected boolean isAutoPathway = false; @@ -59,7 +58,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(); @@ -206,7 +204,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(); @@ -226,9 +224,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(); @@ -238,10 +236,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.getLevel(), tile.getBlockPos()); final Signal first = SignalBoxHandler.getSignal(identifier, startSignal.pos); if (first == null) @@ -252,7 +246,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.getLevel(), posIdent.pos, current), firstInfo, data, posIdent.isRepeater)); }); @@ -446,11 +440,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(); } } @@ -611,6 +608,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); }); @@ -622,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() { 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..1a72795a6 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) -> { @@ -109,7 +105,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<>(); @@ -127,11 +123,10 @@ private void changeSignals(final List values, final ConfigInfo i }); if (!propertiesToSet.isEmpty()) { SignalStateHandler.setStates(info.currentinfo, propertiesToSet); - pathway.updatePrevious(); } } - private void loadWithoutPredicate(final List values, + private static void loadWithoutPredicate(final List values, final SignalStateInfo current) { if (values != null) { loadSignalAndRunTask(current, (info, oldProperties, _u) -> { @@ -143,7 +138,6 @@ private void loadWithoutPredicate(final List values, }); if (!propertiesToSet.isEmpty()) SignalStateHandler.setStates(current, propertiesToSet); - pathway.updatePrevious(); }); } } From 1bcaae7aa72e961358a8d6946ec264ab4b147d13 Mon Sep 17 00:00:00 2001 From: Cedric Date: Fri, 1 Nov 2024 15:38:59 +0100 Subject: [PATCH 3/3] 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 bdf07cee9..8aa600093 100644 --- a/changelog.md +++ b/changelog.md @@ -1,5 +1,10 @@ # Changelog +## [1.16.5 - 3.6.3] +* fix: threads blocking each other +* ref: better system for pathway updateing and signal setting +* fix: wrong lamp in wn signal + ## [1.16.5 - 3.6.2] * feat: added train length signs * feat: added trainnumber element