/* +------------------------------------------------------+ ____/ \____ /| - Open source game framework licensed to freely use, | \ / / | copy, modify and sell without restriction | +--\ ^__^ /--+ | | | ~/ \~ | | - created for | | ~~~~~~~~~~~~ | +------------------------------------------------------+ | SPACE ~~~~~ | / | ~~~~~~~ BOX |/ +-------------*/ #pragma once #define GLM_ENABLE_EXPERIMENTAL #include #include #include #include #include #include #include #include #include "SDL.h" #include "SDL_mixer.h" #include "glm/ext.hpp" #include "json/json.hpp" #include "filesystem.hpp" #include "Node.hpp" #include "Configuration.hpp" #include "Animation.hpp" #include "Log.hpp" struct Stash { std::vector pixel_buffers; std::vector flipped; std::vector audio_buffers; std::vector audio_buffer_lengths; int frame_offset; Stash(int frame_offset = 0) : frame_offset(frame_offset) {} }; class Recorder : public Node { private: Stash current_stash = Stash(); Stash most_recent_stash; std::list in_game_stashes; std::list video_stashes; fs::path current_video_directory, current_audio_path; bool is_recording = false, writing_recording = false, writing_most_recent = false; std::ofstream audio_file; float frame_length(); static void process_audio(void*, Uint8*, int); public: Animation animation = Animation(std::bind(&Recorder::add_frame, this)); Recorder(Node*); void respond(SDL_Event&); void capture_screen(); void grab_stash(); void write_most_recent_frames(); void start_recording(); void open_audio_file(); void add_frame(); int get_memory_size(); void make_directory(); void write_stash_frames(Stash*); void keep_stash(); void end_recording(); void finish_writing_video(); void write_mp4(); void write_audio(Uint8*, int); void update(float timestamp); virtual std::string class_name() const { return "Recorder"; } };