Skip to content

Commit

Permalink
Send bundles instead of individual messages.
Browse files Browse the repository at this point in the history
  • Loading branch information
Provismet committed Sep 30, 2023
1 parent c40b664 commit 5426132
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 10 deletions.
13 changes: 9 additions & 4 deletions src/main/java/com/provismet/vmcmc/vmc/CaptureRegistry.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package com.provismet.vmcmc.vmc;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.function.Function;

import com.illposed.osc.OSCPacket;
import com.provismet.vmcmc.ClientVMC;

import net.minecraft.client.MinecraftClient;
Expand Down Expand Up @@ -48,26 +51,28 @@ public static void registerStandardEvents () {
}

public static void iterate (MinecraftClient client) {
if (client.player == null && PacketSender.isValid()) return;
if (client.player == null || !PacketSender.isValid()) return;

List<OSCPacket> messages = new ArrayList<>(REGISTRY.size());

REGISTRY.forEach((id, callbackInfo) -> {
float output = callbackInfo.getRight().apply(client);

switch (callbackInfo.getLeft()) {
case BLEND_SHAPE:
PacketSender.sendBlendShape(id.toString(), output);
messages.add(PacketSender.createBlendShape(id.toString(), output));
break;

case BONE:
PacketSender.sendBone(id.toString(), output);
break;

default:
break;
}
});

PacketSender.sendBlendApply();
messages.add(PacketSender.createBlendApply());
PacketSender.sendBundle(messages);
}

public enum CaptureType {
Expand Down
46 changes: 40 additions & 6 deletions src/main/java/com/provismet/vmcmc/vmc/PacketSender.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@
import java.util.Arrays;
import java.util.List;

import org.apache.commons.lang3.NotImplementedException;

import com.illposed.osc.OSCBundle;
import com.illposed.osc.OSCMessage;
import com.illposed.osc.OSCPacket;
import com.illposed.osc.transport.OSCPortOut;
import com.provismet.vmcmc.ClientVMC;

Expand All @@ -26,28 +30,58 @@ public static boolean isValid () {
return portOut != null;
}

public static void sendBlendShape (String name, float value) {
List<Object> args = Arrays.asList(name, value);
OSCMessage message = new OSCMessage("/VMC/Ext/Blend/Val", args);
public static OSCMessage createBlendShape (String name, float value) {
return new OSCMessage("/VMC/Ext/Blend/Val", Arrays.asList(name, value));
}

public static void sendBlendShape (String name, float value) {
try {
portOut.send(message);
portOut.send(createBlendShape(name, value));
}
catch (Exception e) {
ClientVMC.LOGGER.error("Failed to send message: ", e);
}
}

public static void sendBone (String name, float value) {
public static OSCMessage createBone (String name, List<Float> XYZ, List<Float> Quaternion) {
throw new NotImplementedException(); // TODO: Add bone sending.
}

public static void sendBone (String name, List<Float> XYZ, List<Float> Quaternion) {
try {
portOut.send(createBone(name, XYZ, Quaternion));
}
catch (Exception e) {

}
}

public static OSCMessage createBlendApply () {
return new OSCMessage("/VMC/Ext/Blend/Apply");
}

public static void sendBlendApply () {
try {
portOut.send(new OSCMessage("/VMC/Ext/Blend/Apply"));
portOut.send(createBlendApply());
}
catch (Exception e) {

}
}

public static void sendBundle (OSCPacket... packets) {
sendBundle(Arrays.asList(packets));
}

public static void sendBundle (List<OSCPacket> packets) {
OSCBundle bundle = new OSCBundle(packets);

try {
portOut.send(bundle);
ClientVMC.LOGGER.info("Sent bundle.");
}
catch (Exception e) {
ClientVMC.LOGGER.error("Failed to send OSC bundle:", e);
}
}
}

0 comments on commit 5426132

Please sign in to comment.