MinecraftTAS / TASmod

Minecraft Tool-Assisted Speedrun (TAS) Tools with input playback
https://discord.gg/jGhNxpd
GNU General Public License v3.0
30 stars 5 forks source link

Retime TASfile index #158

Closed ScribbleTAS closed 1 year ago

ScribbleTAS commented 1 year ago

When recording, the index of the recording is 2 ticks ahead at all times, which creates some headaches regarding new features.

To solve this, the index increase needs to be moved to the end of the block.

    private void recordNextTick() {
-       index++;
        if(inputs.size()<=index) {
            if(inputs.size()<index) {
                TASmod.logger.warn("Index is {} inputs bigger than the container!", index-inputs.size()); //<- This will trigger every time
            }
            inputs.add(new TickInputContainer(index, keyboard.clone(), mouse.clone(), subticks.clone()));
        } else {
            inputs.set(index, new TickInputContainer(index, keyboard.clone(), mouse.clone(), subticks.clone()));
        }
        desyncMonitor.recordMonitor(); // Capturing monitor values
+       index++;
    }

As you may expect, this creates even more headaches with timing, however I feel that this is a good change for the future

ScribbleTAS commented 1 year ago

In the end, it was a bit different than what I proposed here.

The solution was to add an empty TickContainer to the inputs, when the recording is starting and if it's empty

case RECORDING:
            if (Minecraft.getMinecraft().player != null && startLocation.isEmpty()) {
                startLocation = getStartLocation(Minecraft.getMinecraft().player);
            }

+           if(this.inputs.isEmpty()) {
+               inputs.add(new TickInputContainer(index));
+               desyncMonitor.recordNull(index);
+           }

            state = TASstate.RECORDING;
            return verbose ? TextFormatting.GREEN + "Starting a recording" : "";

This will retime the index to be equal the size of the inputs rather than ahead of the size of the inputs.

The same also needs to happen for the desyncMonitor.

This also changes the stop condition of the playback:

    /*Stop condition*/
-   if (index >= inputs.size()) {
+   if (index == inputs.size()) {
        unpressContainer();
        TASstateClient.setOrSend(TASstate.NONE);
    }