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 PlaybackSerialiser #203

Merged
merged 79 commits into from
Jul 11, 2024

Conversation

ScribbleTAS
Copy link
Member

@ScribbleTAS ScribbleTAS commented Apr 14, 2024

Part 3 of my ongoing quest to refactor the mod.

While the first PR (#179) was hooking into the vanilla code,
the second PR (#200) was about storing the inputs and metadata in RAM.

In this PR I will tackle the task of storing all the inputs we recorded to the file.

Current

The current system is (as always) a hardcoded mess of stuff somewhat randomly put together...
Now with a bit more experience under my belt, I should be able to upgrade whatever I wrote 3 years ago...

Changes

PlaybackSerialiser

The serialiser has been completely rewritten to support the new subtick format that was introduced in #179.

Alpha

0|Keyboard:;|Mouse:;[MOUSEMOVED,0,0,0]|Camera:0.0;0.0~&				//Monitoring:0.0 0.0 0.0 0.0 0.0 0.0 0
1|Keyboard:; |Mouse:;[MOUSEMOVED,0,-121,58]|Camera:0.0;0.0~&				//Monitoring:-38.874069623529465 56.0 1.4322641845001531 0.0 -0.0784000015258789 0.0 0
2|Keyboard:;|Mouse:;[MOUSEMOVED,0,-121,58]|Camera:0.0;0.0~&				//Monitoring:-38.874069623529465 56.0 1.4322641845001531 0.0 -0.0784000015258789 0.0 0
3|Keyboard:;|Mouse:;[MOUSEMOVED,0,-121,58]|Camera:0.0;0.0~&				//Monitoring:-38.874069623529465 56.0 1.4322641845001531 0.0 -0.0784000015258789 0.0 0

In Alpha, every line contained one tick, with the mouse being the only peripheral that supported subticks (in square brackets).
Monitoring was put at the end of the line in a comment, with an infuriating ~& inbetween, which was the only way for me at the time to seperate data from comments.

Overall the file format looks very messy.

Beta

23|||21.749935;-318.6463		// $desyncMonitor(-33.52014, 56.00000, -4.20817, 0.00000, -0.07840, 0.00000);
24|||		// $desyncMonitor(-33.52014, 56.00000, -4.20817, 0.00000, -0.07840, 0.00000);
25|||		// $desyncMonitor(-33.52014, 56.00000, -4.20817, 0.00000, -0.07840, 0.00000);
26|||		// $desyncMonitor(-33.52014, 56.00000, -4.20817, 0.00000, -0.07840, 0.00000);
27|||21.749935;-320.8963		// $desyncMonitor(-33.52014, 56.00000, -4.20817, 0.00000, -0.07840, 0.00000);
28|||21.149935;-322.5463		// $desyncMonitor(-33.52014, 56.00000, -4.20817, 0.00000, -0.07840, 0.00000);
	1|||20.849936;-322.84628
	2|||20.249935;-323.4463
	3|||19.499935;-324.34628
	4|||19.199936;-324.49628
	5|||19.049936;-324.64627
	6|||18.899937;-324.49628
29|LCONTROL;||18.749937;-324.1963		// $desyncMonitor(-33.59629, 56.00000, -4.10603, -0.04158, -0.07840, 0.05577);
	1|W,LCONTROL;^W||18.599937;-324.0463
	2|||18.599937;-323.8963
	3|||18.449938;-323.8963
	4|||18.449938;-323.7463
	5|||18.299938;-323.7463
	6|||18.299938;-323.5963
	7|||18.299938;-323.44632
	8|||18.149939;-323.44632
	9|||18.149939;-323.29633

Now in the beta, subticks are denoted with a TAB at the beginning, while the start of the tick is without it.
Keyboard, Mouse and Camera indicators have been removed as well as the ~& at the end of the file.

Monitoring is now done via "File Commands", which can be turned off if necessary.

Relative input

For cursor and camera angle, it is now possible to put ~ in front of your value (e.g. ~45), instead of hard values.
This will change the value relative to the previous value (e.g Add 45 units).

API

This PR adds 3 new registries related to serialisation.

PlaybackMetadata

Enables you to store things in the header of the TASfile

public class YourMetadataExtension extends PlaybackMetadataExtension {

	@Override
	public String getExtensionName() {
		return "Your Extension";
	}

	@Override
	public PlaybackMetadata onStore() {
		PlaybackMetadata metadata = new PlaybackMetadata(this);
		metadata.setValue("key", "value");
		return metadata;
	}

	@Override
	public void onLoad(PlaybackMetadata metadata) {
		System.out.println(metadata.getValue("key"));
	}

	@Override
	public void onClear() {
		// Clear any stored things
	}

}

Register this with TASmodAPIRegistry.PLAYBACK_METADATA.register(new YourMetadataExtension())

The resulting header in the TASfile should contain something similar to this:

--------------------- Your Extension --------------------
key:value

PlaybackFileCommands

File commands are additions to the TASfile in the form of $name(args); for extended functionality.

In Alpha, this was done using a system named "control bytes" made by @PancakeTAS.
It was possible to add certain lines to the TASfile, which executed functionality when the playback ran over that tick.

  • $interpolation on/off: Turns on/off interpolation for playback
  • $hud on/off: Turns on/off hud during playback
  • $info off/String: Adds a box to the top left with a custom string

This functionality has now been moved to file commands:

  • interpolation: Removed, as interpolation is now handled by subticks, you can delete the camera angle subticks to selectively turn off interpolation.
  • $hud(true|false);: Same as before
  • $label(String): To turn off, leave the String empty.

Additionally, desyncMonitoring was implemented during Alpha versions by being hardcoded at the end of the lines.
As seen in the examples above, desyncMonitor is now a file command.

File commands have the benefit, that they are easily extendible and can be turned off if needed.

Other specifications:

  • Multiple file commands can be in the same line: //$hud(false); $info();
  • Comments can be in the same line as file commands: //$hud(true); This is a comment1
  • There are 2 types of file commands (and comments), Inline and Endline
    • Inline comments are comments before a tick line.
      File commands in these comments are only performed on the whole tick.
      // This is an inline comment $hud(false);
      29|LCONTROL;||18.749937;-324.1963
      1|W,LCONTROL;^W||18.599937;-324.0463
      2|||18.599937;-323.8963
      
    • Endline comments appear at the end of a line. File commands are executed on a subtick level
      29|LCONTROL;||18.749937;-324.1963	// This is an endline comment $desyncMonitor(etc..);
      1|W,LCONTROL;^W||18.599937;-324.0463
      2|||18.599937;-323.8963
      

Similar to MetadataExtensions, you can create your own by extending PlaybackFileCommandExtension and registering it with TASmodAPIRegistry.PLAYBACK_FILE_COMMAND.register(new YourFileCommandExtension()).

Flavors can be turned off with /filecommand <fcname>, while /filecommand shows, which fcs are enabled.

SerialiserFlavor

If you want TASmod to support an entire new TASfile syntax, then you can create a new flavor2 by extending SerialiserFlavorBase and registering it with TASmodAPIRegistry.SERIALISER_FLAVOR.register(new YourFlavorExtension);

You can specify the flavor during the /saveTAS command: /saveTAS <name> [flavor]. When specifying a flavor, it will be set as the default, so the second save will not need the flavor.

The defaultFlavor is currently called "beta1".

Renames

  • mctcommon/server => mctcommon/networking
  • Moved TASmodKeybinds to registries package
  • Moved TASmodPackets to registries package
  • Split EventClient and EventServer into more files:
    • EventTickrate
    • EventSavestate
    • EventVirtualInput

Fixes

  • Fixed F8,F9 not being recognised in chat
  • Fixed TASmodConfig not being extendible

TODO

CustomSerialisers

PlaybackExtensions

  • Add PlaybackExtensionRegistry
  • Convert DesyncMonitor to extension
  • Convert ControlBytes to extension

Footnotes

  1. File commands can appear after or inbetween a comment, but when saving, file commands will be moved to the beginning of the file.

  2. It's called flavors, as markup languages like Markdown are not entirely the same across websites and apps. These versions are called "flavors". For example the github flavor of Markdown supports footnotes, while other flavors do not.

@ScribbleTAS ScribbleTAS added this to the Beta1.0 milestone Apr 14, 2024
@ScribbleTAS ScribbleTAS added Refactor This issue talks about refactoring code TASFile Issue relates to the playback file used to store inputs labels Apr 14, 2024
@ScribbleTAS ScribbleTAS self-assigned this Apr 14, 2024
@ScribbleTAS
Copy link
Member Author

ScribbleTAS commented May 7, 2024

Note to self:
Do new registry stuff

@ScribbleTAS
Copy link
Member Author

ScribbleTAS commented May 8, 2024

Note to self:
Continue doing registry stuff!
Then make a new one for flavors and start writing the new system!

@ScribbleTAS ScribbleTAS force-pushed the refactor/serialiser branch from 64573de to d5b5188 Compare May 8, 2024 21:13
- Preparing for developing and testing the flavor
- Created package 'flavor'
- Moved each registration in it's own method
- Moved /restartandplay functionality to PlaybackController
- [MCTCommon] Added functionality to AbstractRegistry
- Moved Keybind registering to TASmodKeybinds
- Added TASmodRegistry
@ScribbleTAS ScribbleTAS force-pushed the refactor/serialiser branch from d5b5188 to ae3c1dc Compare May 9, 2024 13:21
- Renamed PlaybackSerialiserFlavorBase to PlaybackFlavorBase
- Renamed PlaybackSerialiserFlavorRegistry to PlaybackFlavorRegistry
- Added PlaybackFlavorRegistry to TASmodRegistry
- Continued on PlaybackFlavorBase
@ScribbleTAS
Copy link
Member Author

Note to self:
Continue on PlaybackFlavorBase and BetaFlavor. Get unit tests up and running for flavors to be able to test them!

@ScribbleTAS ScribbleTAS force-pushed the refactor/serialiser branch from fdf1953 to 17beb2a Compare May 10, 2024 12:10
@ScribbleTAS ScribbleTAS force-pushed the refactor/serialiser branch from 17beb2a to 91af4a2 Compare May 10, 2024 12:12
- Added better container handling to flavor base
- [PlaybackController] Removed tick field from TickInputContainer and added it to serialiser
- [VirtualInput] Made toString() public
@ScribbleTAS
Copy link
Member Author

Note to self:
Deserialiser time!

@ScribbleTAS ScribbleTAS force-pushed the refactor/serialiser branch from 852d17a to 86c5c52 Compare July 1, 2024 21:38
This removes duplicate code in PlaybackMetadataRegistry, PlaybackFileCommandsRegistry and SerialiserFlavorRegistry

- Moved TASmod specific configuration out of MCTCommon and created TASmodConfig
- Added AbstractRegistry to Networking and Config
- Renamed package "MCTCommon/server" to "MCTCommon/networking"

- Added package registries
- Renamed TASmodRegistry to TASmodAPIRegistry
- Moved TASmodKeybinds to registries package
- Moved TASmodPackets to registries package

- Added seperate loading method for config. This is necessary as ConfigOptions need to be registered first
- This will only store files up to the stop index for savestate purposes
- Added EventSavestate, EventVirtualInput, EventTickratechanger
@ScribbleTAS
Copy link
Member Author

ScribbleTAS commented Jul 3, 2024

Note to self:

  • Remove camera angle stuff in file
    - [ ] Add K, M, C

Metadata now looks like this:
---------------------- Test1 ---------------------
Test1:This is a test

---------------------- Test2 ---------------------
Test2:This is another test
@ScribbleTAS
Copy link
Member Author

ScribbleTAS commented Jul 8, 2024

Note to self:

  • Add command for fileCommands
  • Add config option for file commands

Removed a lot empty slots from the file

- [VirtualInput] Added #isEmpty()
- Fixed currentLine not containing the rough line during serialisation
@ScribbleTAS ScribbleTAS force-pushed the refactor/serialiser branch from e80f464 to d3a11d8 Compare July 8, 2024 21:13
- Renamed PlaybackSerialiser to PlaybackSerialiserOld
- Added documentation to PlaybackSerialiser
- Removed BetaFlavorTest as that is tested in SerialiserFlavorBase
- Fixed tests failing
- Organised some imports
- Moved PlaybackMetadataExtension to PlaybackMetadata
@ScribbleTAS ScribbleTAS marked this pull request as ready for review July 10, 2024 17:39
@ScribbleTAS ScribbleTAS requested a review from PancakeTAS July 10, 2024 17:40
@PancakeTAS
Copy link
Member

🥳 🥳 🥳 🥳 🥳
you'll be getting my full review in approx 3-5 business days

Copy link
Member

@PancakeTAS PancakeTAS left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

few nitpicks, got only through half of the files before I got demotivated
image

@ScribbleTAS ScribbleTAS merged commit 283e291 into MinecraftTAS:develop Jul 11, 2024
2 checks passed
@ScribbleTAS ScribbleTAS deleted the refactor/serialiser branch July 11, 2024 11:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Refactor This issue talks about refactoring code TASFile Issue relates to the playback file used to store inputs
Projects
Archived in project
2 participants