Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor PlaybackController #200

Merged
merged 27 commits into from
Apr 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
08a134a
[PlaybackController] Add events that fire when updating VirtualInput
ScribbleTAS Feb 27, 2024
bdd6c0e
[PlaybackController] Fix tests failing
ScribbleTAS Feb 28, 2024
43f2940
[VirtualInput] Renamed copyFrom to moveFrom and added copyFrom
ScribbleTAS Feb 29, 2024
2e94dda
[PlaybackController] Added playback metadata
ScribbleTAS Feb 29, 2024
0eaf3b6
[PlaybackController] Added playback metadata registry
ScribbleTAS Mar 25, 2024
9a3cc99
[PlaybackController] Add onCreate to events
ScribbleTAS Mar 27, 2024
2426356
[PLaybackController] Added test for PlaybackMetadata
ScribbleTAS Mar 30, 2024
69972bd
[PlaybackController] Switch from Properties to Hashmap, add tests
ScribbleTAS Mar 31, 2024
9f0013b
[Common] Added 'isAssignableFrom' to type checking
ScribbleTAS Apr 1, 2024
c7c2178
[VirtualInput] Added deepCopy for also copying subticks
ScribbleTAS Apr 1, 2024
d62d382
[PlaybackController] Add implement events into controller
ScribbleTAS Apr 1, 2024
5be5eb1
[PlaybackController] Connect new VirtualInput with controller
ScribbleTAS Apr 1, 2024
08f16ff
Fixes crash when no inputs are loaded (#185)
ScribbleTAS Apr 1, 2024
4264c62
Fix test
ScribbleTAS Apr 1, 2024
7f3fab5
Update Loom to 1.6, Update loader to 0.15.9
ScribbleTAS Apr 2, 2024
6d2594b
[PlaybackController] Extracting start/stop recording/playback from se…
ScribbleTAS Apr 2, 2024
017314d
Update gradle version in workflows to 8.6
ScribbleTAS Apr 2, 2024
87ab153
[VirtualInput] Renamed clone to shallowClone and added clone
ScribbleTAS Apr 3, 2024
a818f08
[PlaybackController] Fixed interpolation
ScribbleTAS Apr 4, 2024
f304244
[VirtualInput] Added tests
ScribbleTAS Apr 5, 2024
f8cf266
[PlaybackSerialiser] Add base class
ScribbleTAS Apr 6, 2024
be74f5e
[PlaybackMetadata] Adding handleOnLoad and handleOnSave
ScribbleTAS Apr 6, 2024
3287dca
[VirtualInput] Fixed mouse pointer not being recorded in GUI screens
ScribbleTAS Apr 7, 2024
b6ee9ee
[VirtualInput] Fixed camera flickering when start/stopping play/rec
ScribbleTAS Apr 12, 2024
4d1594e
[PlaybackMetadata] Add credits playback metadata extension
ScribbleTAS Apr 12, 2024
75f3413
[PlaybackMetadata] Added StartpositionMetadataExtension
ScribbleTAS Apr 13, 2024
12e039b
[PlaybackMetadata] Finish logic for StartpositionMetadataExtension
ScribbleTAS Apr 13, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
- name: Setup Gradle
uses: gradle/gradle-build-action@v2.4.0
with:
gradle-version: 8.4
gradle-version: 8.6
- name: Build TASmod with Gradle
run: gradle build
- name: Upload Test Report
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/buildandupload.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
- name: Setup Gradle
uses: gradle/gradle-build-action@v2.4.0
with:
gradle-version: 8.4
gradle-version: 8.6
- name: Build TASmod with Gradle
run: gradle build
- name: Upload artifact
Expand Down
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ org.gradle.jvmargs=-Xmx3G

# Fabric properties
minecraft_version=1.12.2
loader_version=0.15.6
loom_version=1.5-SNAPSHOT
loader_version=0.15.9
loom_version=1.6-SNAPSHOT

# Mod properties
mod_name=Tool-Assisted Speedrun Mod
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,18 @@ public static void register(EventBase eventListener) {
}
}

/**
* Registers multiple objects to be an event listener. The objects must
* implement an event extending {@link EventBase}
*
* @param eventListeners The event listeners to register
*/
public static void register(EventBase... eventListeners) {
for (EventBase eventListener : eventListeners) {
register(eventListener);
}
}

/**
* Unregisters an object from being an event listener.
*
Expand All @@ -130,6 +142,17 @@ public static void unregister(EventBase eventListener) {
}
}

/**
* Unregisters multiple objects from being an event listener.
*
* @param eventListener The event listeners to unregister
*/
public static void unregister(EventBase... eventListeners) {
for (EventBase eventListener : eventListeners) {
unregister(eventListener);
}
}

/**
* Fires an event without parameters
*
Expand All @@ -151,6 +174,7 @@ public static Object fireEvent(Class<? extends EventListenerRegistry.EventBase>
public static Object fireEvent(Class<? extends EventListenerRegistry.EventBase> eventClass, Object... eventParams) {
ArrayList<EventBase> listenerList = EVENTLISTENER_REGISTRY.get(eventClass);
if (listenerList == null) {
// throw new EventException("The event has not been registered yet", eventClass);
return null;
}

Expand Down Expand Up @@ -250,12 +274,7 @@ private static boolean checkTypes(Method method, Object... parameters) {
for (int i = 0; i < methodParameterTypes.length; i++) {
Class<?> paramName = methodParameterTypes[i];
Class<?> eventName = eventParameterTypes[i];

if (paramName == null || eventName == null) {
continue;
}

if (!paramName.equals(eventName) && !paramName.isAssignableFrom(eventName)) {
if (!paramName.equals(eventName) && (paramName != null && eventName != null && !paramName.isAssignableFrom(eventName))) {
return false;
}
}
Expand All @@ -265,7 +284,11 @@ private static boolean checkTypes(Method method, Object... parameters) {
private static Class<?>[] getParameterTypes(Object... parameters) {
Class<?>[] out = new Class[parameters.length];
for (int i = 0; i < parameters.length; i++) {
out[i] = parameters[i] == null ? null : parameters[i].getClass();
if (parameters[i] == null) {
out[i] = null;
continue;
}
out[i] = parameters[i].getClass();
}
return out;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ public class PacketHandlerRegistry {
private static final List<PacketHandlerBase> REGISTRY = new ArrayList<>();

public static void register(PacketHandlerBase handler) {
if(handler==null) {
if (handler == null) {
throw new NullPointerException("Tried to register a handler with value null");
}
if(containsClass(handler)) {

if (containsClass(handler)) {
MCTCommon.LOGGER.warn("Trying to register packet handler {}, but another instance of this class is already registered!", handler.getClass().getName());
return;
}

if (!REGISTRY.contains(handler)) {
REGISTRY.add(handler);
} else {
Expand All @@ -35,13 +35,13 @@ public static void register(PacketHandlerBase handler) {
}

public static void unregister(PacketHandlerBase handler) {
if(handler==null) {
if (handler == null) {
throw new NullPointerException("Tried to unregister a handler with value null");
}
if (REGISTRY.contains(handler)) {
REGISTRY.remove(handler);
} else {
MCTCommon.LOGGER.warn("Trying to unregister packet handler {}, but is was not registered!", handler.getClass().getName());
MCTCommon.LOGGER.warn("Trying to unregister packet handler {}, but it was not registered!", handler.getClass().getName());
}
}

Expand All @@ -65,14 +65,14 @@ public static void handle(Side side, PacketID packet, ByteBuffer buf, String use
}
}
}
if(!isImplemented) {
if (!isImplemented) {
throw new PacketNotImplementedException(packet, side);
}
}

private static boolean containsClass(PacketHandlerBase handler) {
for(PacketHandlerBase packethandler : REGISTRY) {
if(packethandler.getClass().equals(handler.getClass())) {
for (PacketHandlerBase packethandler : REGISTRY) {
if (packethandler.getClass().equals(handler.getClass())) {
return true;
}
}
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/com/minecrafttas/tasmod/TASmod.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import com.minecrafttas.tasmod.ktrng.KillTheRNGHandler;
import com.minecrafttas.tasmod.networking.TASmodPackets;
import com.minecrafttas.tasmod.playback.PlaybackControllerServer;
import com.minecrafttas.tasmod.playback.metadata.integrated.StartpositionMetadataExtension;
import com.minecrafttas.tasmod.savestates.SavestateHandlerServer;
import com.minecrafttas.tasmod.savestates.files.SavestateTrackerFile;
import com.minecrafttas.tasmod.tickratechanger.TickrateChangerServer;
Expand Down Expand Up @@ -68,6 +69,8 @@ public class TASmod implements ModInitializer, EventServerInit, EventServerStop{

public static final boolean isDevEnvironment = FabricLoaderImpl.INSTANCE.isDevelopmentEnvironment();

public static final StartpositionMetadataExtension startPositionMetadataExtension = new StartpositionMetadataExtension();

@Override
public void onInitialize() {

Expand Down Expand Up @@ -96,6 +99,7 @@ public void onInitialize() {
PacketHandlerRegistry.register(tickratechanger);
PacketHandlerRegistry.register(ktrngHandler);
PacketHandlerRegistry.register(playbackControllerServer);
PacketHandlerRegistry.register(startPositionMetadataExtension);
}

@Override
Expand Down
28 changes: 21 additions & 7 deletions src/main/java/com/minecrafttas/tasmod/TASmodClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@
import com.minecrafttas.tasmod.networking.TASmodPackets;
import com.minecrafttas.tasmod.playback.PlaybackControllerClient;
import com.minecrafttas.tasmod.playback.PlaybackControllerClient.TASstate;
import com.minecrafttas.tasmod.playback.PlaybackSerialiser;
import com.minecrafttas.tasmod.playback.metadata.PlaybackMetadataRegistry;
import com.minecrafttas.tasmod.playback.metadata.integrated.CreditsMetadataExtension;
import com.minecrafttas.tasmod.playback.metadata.integrated.StartpositionMetadataExtension;
import com.minecrafttas.tasmod.playback.tasfile.PlaybackSerialiser;
import com.minecrafttas.tasmod.savestates.SavestateHandlerClient;
import com.minecrafttas.tasmod.tickratechanger.TickrateChangerClient;
import com.minecrafttas.tasmod.ticksync.TickSyncClient;
Expand Down Expand Up @@ -85,6 +88,10 @@ public class TASmodClient implements ClientModInitializer, EventClientInit, Even
public static SavestateHandlerClient savestateHandlerClient = new SavestateHandlerClient();

public static Client client;

public static CreditsMetadataExtension creditsMetadataExtension = new CreditsMetadataExtension();

public static StartpositionMetadataExtension startpositionMetadataExtension = new StartpositionMetadataExtension();
/**
* The container where all inputs get stored during recording or stored and
* ready to be played back
Expand Down Expand Up @@ -153,6 +160,12 @@ public void onInitializeClient() {
}
return gui;
}));
EventListenerRegistry.register(controller);
PlaybackMetadataRegistry.register(creditsMetadataExtension);
EventListenerRegistry.register(creditsMetadataExtension);

PlaybackMetadataRegistry.register(startpositionMetadataExtension);
EventListenerRegistry.register(startpositionMetadataExtension);

// Register packet handlers
LOGGER.info(LoggerMarkers.Networking, "Registering network handlers on client");
Expand Down Expand Up @@ -195,14 +208,15 @@ public void onClientInit(Minecraft mc) {
})));
blockedKeybindings.add(keybindManager.registerKeybind(new Keybind("Open InfoGui Editor", "TASmod", Keyboard.KEY_F6, () -> Minecraft.getMinecraft().displayGuiScreen(TASmodClient.hud))));
blockedKeybindings.add(keybindManager.registerKeybind(new Keybind("Various Testing", "TASmod", Keyboard.KEY_F12, () -> {
TASmodClient.client.disconnect();
controller.setTASState(TASstate.RECORDING);
}, VirtualKeybindings::isKeyDown)));
blockedKeybindings.add(keybindManager.registerKeybind(new Keybind("Various Testing2", "TASmod", Keyboard.KEY_F7, () -> {
try {
TASmodClient.client = new Client("localhost", TASmod.networkingport-1, TASmodPackets.values(), mc.getSession().getProfile().getName(), true);
} catch (Exception e) {
e.printStackTrace();
}
// try {
// TASmodClient.client = new Client("localhost", TASmod.networkingport-1, TASmodPackets.values(), mc.getSession().getProfile().getName(), true);
// } catch (Exception e) {
// e.printStackTrace();
// }
controller.setTASState(TASstate.PLAYBACK);
}, VirtualKeybindings::isKeyDown)));
blockedKeybindings.forEach(VirtualKeybindings::registerBlockedKeyBinding);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public String getUsage(ICommandSender sender) {

@Override
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException {
sender.sendMessage(new TextComponentString(TextFormatting.RED + "This feature does not work at the moment!"));
if (sender instanceof EntityPlayer) {
if (sender.canUseCommand(2, "load")) {
if (args.length < 1) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ public List<String> getAliases() {

@Override
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException {
sender.sendMessage(new TextComponentString(TextFormatting.RED + "This feature doesn't work at the moment!"));
if (!(sender instanceof EntityPlayer)) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ public List<String> getAliases() {

@Override
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException {
sender.sendMessage(new TextComponentString(TextFormatting.RED + "This feature doesn't work at the moment!"));
if (!(sender instanceof EntityPlayer)) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public List<String> getAliases() {

@Override
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException {
sender.sendMessage(new TextComponentString(TextFormatting.RED + "This feature does not work at the moment!"));
if (sender instanceof EntityPlayer) {
if (sender.canUseCommand(2, "save")) {
if (args.length < 1) {
Expand Down
78 changes: 70 additions & 8 deletions src/main/java/com/minecrafttas/tasmod/events/EventClient.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
package com.minecrafttas.tasmod.events;

import com.minecrafttas.mctcommon.events.EventListenerRegistry.EventBase;
import com.minecrafttas.tasmod.virtual.VirtualCameraAngle;
import com.minecrafttas.tasmod.virtual.VirtualInput.VirtualCameraAngleInput;
import com.minecrafttas.tasmod.virtual.VirtualInput.VirtualKeyboardInput;
import com.minecrafttas.tasmod.virtual.VirtualInput.VirtualMouseInput;
import com.minecrafttas.tasmod.virtual.VirtualKeyboard;
import com.minecrafttas.tasmod.virtual.VirtualMouse;

import net.minecraft.client.Minecraft;

/**
Expand All @@ -9,39 +16,94 @@
* @author Scribble
*/
public interface EventClient {

/**
* Fired when the hotbar is drawn on screen
*/
@FunctionalInterface
public static interface EventDrawHotbar extends EventBase{
public static interface EventDrawHotbar extends EventBase {
/**
* Fired when the hotbar is drawn on screen
*/
public void onDrawHotbar();
}

/**
* Fired at the end of a client tick
*/
@FunctionalInterface
public static interface EventClientTickPost extends EventBase{
public static interface EventClientTickPost extends EventBase {

/**
* Fired at the end of a client tick
*/
public void onClientTickPost(Minecraft mc);
}

/**
* Fired when the tickrate changes on the client side
*/
@FunctionalInterface
public static interface EventClientTickrateChange extends EventBase{
public static interface EventClientTickrateChange extends EventBase {

/**
* Fired at the end of a client tick
*/
public void onClientTickrateChange(float tickrate);
}


/**
* Fired when the {@link VirtualKeyboardInput#currentKeyboard} is updated
*
* @see VirtualKeyboardInput#nextKeyboardTick()
*/
@FunctionalInterface
public static interface EventVirtualKeyboardTick extends EventBase {

/**
* Fired when the {@link VirtualKeyboard} ticks
*
* @param vkeyboard The {@link VirtualKeyboardInput#nextKeyboard} that is supposed to be pressed
* @returns The redirected keyboard
* @see VirtualKeyboardInput#nextKeyboardTick()
*/
public VirtualKeyboard onVirtualKeyboardTick(VirtualKeyboard vkeyboard);
}

/**
* Fired when the {@link VirtualMouseInput#currentMouse} is updated
*
* @see VirtualMouseInput#nextMouseTick()
*/
@FunctionalInterface
public static interface EventVirtualMouseTick extends EventBase {

/**
* Fired when the {@link VirtualMouseInput#currentMouse} is updated
*
* @param vmouse The {@link VirtualMouseInput#nextMouse} that is supposed to be pressed
* @returns The redirected mouse
* @see VirtualMouseInput#nextMouseTick()
*/
public VirtualMouse onVirtualMouseTick(VirtualMouse vmouse);
}

/**
* Fired when the {@link VirtualCameraAngleInput#currentCameraAngle} is updated
*
* @see VirtualCameraAngleInput#nextCameraTick()
*/
@FunctionalInterface
public static interface EventVirtualCameraAngleTick extends EventBase {

/**
* Fired when the {@link VirtualCameraAngleInput#currentCameraAngle} is updated
*
* @param vcamera The {@link VirtualCameraAngleInput#nextCameraAngle}
* @returns The redirected cameraAngle
* @see VirtualCameraAngleInput#nextCameraTick()
*/
public VirtualCameraAngle onVirtualCameraTick(VirtualCameraAngle vcamera);
}
}
Loading
Loading