Skip to content

Recording Controller / Auto-Playing Controller PR#32

Open
trickarcher wants to merge 3 commits into
masterfrom
auto_controller_devel
Open

Recording Controller / Auto-Playing Controller PR#32
trickarcher wants to merge 3 commits into
masterfrom
auto_controller_devel

Conversation

@trickarcher
Copy link
Copy Markdown
Collaborator

This PR adds the ability to record and play automatic inputs. Still a work in progress.

@trickarcher trickarcher requested a review from venkat24 January 25, 2020 04:20
Comment thread .gitignore Outdated
Comment thread CMakeLists.txt Outdated
Comment thread src/auto_controller/CMakeLists.txt Outdated
Comment thread src/auto_controller/include/auto_controller/auto_controller_core.h Outdated
Comment thread src/auto_controller/include/auto_controller/auto_controller_core.h Outdated
Comment thread src/controller/include/controller/controller.h Outdated
@venkat24
Copy link
Copy Markdown
Owner

Let's try to rethink this approach. Our requirements are two modes:

1. Record all events that are passed to the controller, as a user presses them.
Now, we see that all the data required to complete this feature are present within the controller module. All we need to do is store them in memory. Now, while recording, there is nothing different going on in the controller, apart from the fact that it is recording all the button presses.

Now, why does controller need to peek into debugger's ticks? The point of the tick is that is synchronized across all objects. Every time Debugger::tick() is called, it will call Gameboy::tick() exactly once, which can call Controller::tick() exactly once. At any point in time, the controller does not need someone to tell it what the current tick count is, if it is maintaining it's own version of tick and incrementing it every time its parent (Gameboy) ticks.

We come to the Recording feature. Since our RecordingController should really just be a fancy Controller that implements IController. Hence, we can simply make RecordingController inherit from Controller, and override the methods like press_button and release_button. These overrides will record the input, and then call the base class method (Remember to mark such methods as virtual). From the perspective of a class that is using an IController, like Memory or Video, the interface stays totally the same, but the underlying instance is now actually a RecordingController.

2. Playback events existing in memory, just as a user would.
For the second part, we need to mock the user button presses, which means that something (apart from the video module) must make calls to press_button and release_button on the controller object. I think it makes sense to make this a part of the debugger, and perhaps have the user write a command that specifies the button inputs file to use. Then, the debugger makes these 'fake' calls to the controller module. We don't really require an AutoController here (unless it could be some helper of debugger core).

Apologies for that exceedingly verbose comment 😅, but I felt we could use some streamlining here. Let me know if you've got some opinions, and we can refine this a bit more.

@trickarcher trickarcher force-pushed the auto_controller_devel branch from 31283cb to 22caaeb Compare January 25, 2020 15:32
Comment thread src/controller/include/controller/recording_controller.h Outdated
Comment thread src/main/main.cpp Outdated
Comment thread src/gameboy/include/gameboy/gameboy.h Outdated
Comment thread src/gameboy/include/gameboy/gameboy.h
Comment thread src/gameboy/src/gameboy.cpp Outdated
Comment thread src/controller/CMakeLists.txt
Comment thread src/controller/include/controller/recording_controller.h Outdated
Comment thread src/controller/src/controller.cpp Outdated
Comment thread src/gameboy/include/gameboy/gameboy.h
Comment thread src/gameboy/include/gameboy/gameboy.h Outdated
Comment thread src/gameboy/src/gameboy.cpp Outdated
Comment thread src/main/main.cpp Outdated
Comment thread src/main/main.cpp Outdated
Comment thread src/controller/include/controller/recording_controller.h
Comment thread src/controller/src/recording_controller.cpp Outdated
@venkat24
Copy link
Copy Markdown
Owner

@anish0x2a Looks like the CI is failing now because it can't find the JSON header.

Can you fix this?

* @param button Button to set
* @param value Value to set
*/
void set_button(Button button, bool value);
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

This can be made protected instead of public

* Specifies all the Debug configurations that should go into GameBoy
*/
struct DebugOptions {
std::string rom_path;
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

rom_path is not a debug option, it needs to be passed regardless of Debugging.

Move this back out as a normal parameter.

Comment on lines +43 to +44
bool is_recording = false;
std::string recording_output_json_filename = "test.txt";
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Add docstring comments for struct members.

* @param rom_path Path to ROM File
*/
Gameboy(std::string rom_path);
Gameboy(DebugOptions debug_options);
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Like I mentioned above, the rom_path should still be an independent parameter.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants