From f2fc05b599b3bffcafc92960f36e092574438691 Mon Sep 17 00:00:00 2001 From: Stuart Pomeroy Date: Sat, 3 Aug 2024 14:04:41 +0100 Subject: [PATCH] Use partialtick and not rendertick! Also request networks when opening the artnet configuration UI. --- .../dev/imabad/theatrical/TheatricalClient.java | 14 ++++++++++++++ .../client/dmx/TheatricalArtNetClient.java | 7 ++++++- .../java/dev/imabad/theatrical/dmx/DMXNetwork.java | 3 ++- .../mixin/client/OptionsScreenMixin.java | 2 ++ .../imabad/theatrical/forge/TheatricalForge.java | 2 +- .../theatrical/neoforge/TheatricalNeoForge.java | 2 +- 6 files changed, 26 insertions(+), 4 deletions(-) diff --git a/common/src/main/java/dev/imabad/theatrical/TheatricalClient.java b/common/src/main/java/dev/imabad/theatrical/TheatricalClient.java index 826c135..390056d 100644 --- a/common/src/main/java/dev/imabad/theatrical/TheatricalClient.java +++ b/common/src/main/java/dev/imabad/theatrical/TheatricalClient.java @@ -63,6 +63,20 @@ public static void init() { ClientPlayerEvent.CLIENT_PLAYER_QUIT.register((event) -> { onWorldClose(); }); +/* We send straight from the ArtNetClient now instead of looping on a tick. + ClientTickEvent.CLIENT_LEVEL_POST.register(instance -> { + if(instance.dimension().equals(Level.OVERWORLD)) { + if (TheatricalConfig.INSTANCE.CLIENT.artnetEnabled) { + for (int univers : artNetManager.getClient().getUniverses()) { + if(univers != -1) { + byte[] data = artNetManager.getClient().readDmxData(0, univers); + new SendArtNetData(artNetManager.getNetworkId(), univers, data).sendToServer(); + } + } + } + } + }); +*/ } public static ArtNetManager getArtNetManager(){ diff --git a/common/src/main/java/dev/imabad/theatrical/client/dmx/TheatricalArtNetClient.java b/common/src/main/java/dev/imabad/theatrical/client/dmx/TheatricalArtNetClient.java index eb6ff33..9ed2cdb 100644 --- a/common/src/main/java/dev/imabad/theatrical/client/dmx/TheatricalArtNetClient.java +++ b/common/src/main/java/dev/imabad/theatrical/client/dmx/TheatricalArtNetClient.java @@ -8,6 +8,7 @@ import ch.bildspur.artnet.rdm.RDMPacket; import ch.bildspur.artnet.rdm.RDMParameter; import dev.imabad.theatrical.Constants; +import dev.imabad.theatrical.Theatrical; import dev.imabad.theatrical.TheatricalExpectPlatform; import dev.imabad.theatrical.api.Fixture; import dev.imabad.theatrical.api.dmx.DMXPersonality; @@ -174,6 +175,10 @@ private void sendTOD(int universe){ getArtNetServer().broadcastPacket(replyPacket); } + public int[] getUniverses(){ + return this.universes; + } + private void onPacketReceived(InetAddress sourceAddress, final ArtNetPacket packet) { switch(packet.getType()){ case ART_OUTPUT: { @@ -185,7 +190,7 @@ private void onPacketReceived(InetAddress sourceAddress, final ArtNetPacket pack int universe = dmxPacket.getUniverseID(); lastPacketMS = System.currentTimeMillis(); getInputBuffer().setDmxData((short) subnet, (short) universe, dmxPacket.getDmxData()); - if(subnet == 0) { + if(subnet == 0 && isSubscribedTo(universe)) { new SendArtNetData(manager.getNetworkId(), universe, dmxPacket.getDmxData()).sendToServer(); } break; diff --git a/common/src/main/java/dev/imabad/theatrical/dmx/DMXNetwork.java b/common/src/main/java/dev/imabad/theatrical/dmx/DMXNetwork.java index 2c1fdf0..5967469 100644 --- a/common/src/main/java/dev/imabad/theatrical/dmx/DMXNetwork.java +++ b/common/src/main/java/dev/imabad/theatrical/dmx/DMXNetwork.java @@ -15,6 +15,7 @@ import org.jetbrains.annotations.Nullable; import java.util.*; +import java.util.concurrent.ConcurrentHashMap; public class DMXNetwork { private final UUID id; @@ -101,7 +102,7 @@ public String toString() { } public void addConsumer(BlockPos pos, DMXConsumer consumer){ - Map universe = universeToNodeMap.computeIfAbsent(consumer.getUniverse(), (uni) -> new HashMap<>()); + Map universe = universeToNodeMap.computeIfAbsent(consumer.getUniverse(), (uni) -> new ConcurrentHashMap<>()); universe.put(pos, consumer); universeToNodeMap.put(consumer.getUniverse(), universe); new NotifyConsumerChange(consumer.getUniverse(), diff --git a/common/src/main/java/dev/imabad/theatrical/mixin/client/OptionsScreenMixin.java b/common/src/main/java/dev/imabad/theatrical/mixin/client/OptionsScreenMixin.java index c9d95a6..30fa043 100644 --- a/common/src/main/java/dev/imabad/theatrical/mixin/client/OptionsScreenMixin.java +++ b/common/src/main/java/dev/imabad/theatrical/mixin/client/OptionsScreenMixin.java @@ -1,6 +1,7 @@ package dev.imabad.theatrical.mixin.client; import dev.imabad.theatrical.client.gui.screen.ArtNetConfigurationScreen; +import dev.imabad.theatrical.net.artnet.RequestNetworks; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.components.Button; import net.minecraft.client.gui.layouts.GridLayout; @@ -30,6 +31,7 @@ protected OptionsScreenMixin(Component title) { @Inject(method = "init()V", at = @At(value = "INVOKE", target="Lnet/minecraft/client/gui/layouts/GridLayout$RowHelper;addChild(Lnet/minecraft/client/gui/layouts/LayoutElement;ILnet/minecraft/client/gui/layouts/LayoutSettings;)Lnet/minecraft/client/gui/layouts/LayoutElement;"), locals = LocalCapture.CAPTURE_FAILHARD) private void onCreatePauseMenu(CallbackInfo ci, GridLayout gridLayout, GridLayout.RowHelper rowHelper){ if(Minecraft.getInstance().level != null) { + new RequestNetworks().sendToServer(); rowHelper.addChild(this.openScreenButton(Component.translatable("button.artnetconfig"), () -> new ArtNetConfigurationScreen((OptionsScreen) (Object) this))); } } diff --git a/forge/src/main/java/dev/imabad/theatrical/forge/TheatricalForge.java b/forge/src/main/java/dev/imabad/theatrical/forge/TheatricalForge.java index c9982a0..208816a 100644 --- a/forge/src/main/java/dev/imabad/theatrical/forge/TheatricalForge.java +++ b/forge/src/main/java/dev/imabad/theatrical/forge/TheatricalForge.java @@ -41,7 +41,7 @@ public void onClient(FMLClientSetupEvent event){ } // if(Platform.isDevelopmentEnvironment()) { if (renderLevelStageEvent.getStage() == RenderLevelStageEvent.Stage.AFTER_PARTICLES) { - TheatricalClient.renderWorldLast(renderLevelStageEvent.getPoseStack(), renderLevelStageEvent.getProjectionMatrix(), renderLevelStageEvent.getCamera(), renderLevelStageEvent.getRenderTick()); + TheatricalClient.renderWorldLast(renderLevelStageEvent.getPoseStack(), renderLevelStageEvent.getProjectionMatrix(), renderLevelStageEvent.getCamera(), renderLevelStageEvent.getPartialTick()); } // } }); diff --git a/neoforge/src/main/java/dev/imabad/theatrical/neoforge/TheatricalNeoForge.java b/neoforge/src/main/java/dev/imabad/theatrical/neoforge/TheatricalNeoForge.java index 2317056..0ad6c7d 100644 --- a/neoforge/src/main/java/dev/imabad/theatrical/neoforge/TheatricalNeoForge.java +++ b/neoforge/src/main/java/dev/imabad/theatrical/neoforge/TheatricalNeoForge.java @@ -46,7 +46,7 @@ public static void setupClient(FMLClientSetupEvent event) { } // if(Platform.isDevelopmentEnvironment()) { if(renderLevelStageEvent.getStage() == RenderLevelStageEvent.Stage.AFTER_PARTICLES){ - TheatricalClient.renderWorldLast(renderLevelStageEvent.getPoseStack(), renderLevelStageEvent.getProjectionMatrix(), renderLevelStageEvent.getCamera(), renderLevelStageEvent.getRenderTick()); + TheatricalClient.renderWorldLast(renderLevelStageEvent.getPoseStack(), renderLevelStageEvent.getProjectionMatrix(), renderLevelStageEvent.getCamera(), renderLevelStageEvent.getPartialTick()); } // } });