Skip to content

Commit

Permalink
Use partialtick and not rendertick! Also request networks when openin…
Browse files Browse the repository at this point in the history
…g the artnet configuration UI.
  • Loading branch information
Rushmead committed Aug 3, 2024
1 parent 48ac42f commit f2fc05b
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 4 deletions.
14 changes: 14 additions & 0 deletions common/src/main/java/dev/imabad/theatrical/TheatricalClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -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(){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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: {
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import org.jetbrains.annotations.Nullable;

import java.util.*;
import java.util.concurrent.ConcurrentHashMap;

public class DMXNetwork {
private final UUID id;
Expand Down Expand Up @@ -101,7 +102,7 @@ public String toString() {
}

public void addConsumer(BlockPos pos, DMXConsumer consumer){
Map<BlockPos, DMXConsumer> universe = universeToNodeMap.computeIfAbsent(consumer.getUniverse(), (uni) -> new HashMap<>());
Map<BlockPos, DMXConsumer> universe = universeToNodeMap.computeIfAbsent(consumer.getUniverse(), (uni) -> new ConcurrentHashMap<>());
universe.put(pos, consumer);
universeToNodeMap.put(consumer.getUniverse(), universe);
new NotifyConsumerChange(consumer.getUniverse(),
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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)));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
// }
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
// }
});
Expand Down

0 comments on commit f2fc05b

Please sign in to comment.