84 lines
2.2 KiB
C++
84 lines
2.2 KiB
C++
/* +------------------------------------------------------+
|
|
____/ \____ /| - Open source game framework licensed to freely use, |
|
|
\ / / | copy, modify and sell without restriction |
|
|
+--\ ^__^ /--+ | |
|
|
| ~/ \~ | | - created for <https://foam.shampoo.ooo> |
|
|
| ~~~~~~~~~~~~ | +------------------------------------------------------+
|
|
| SPACE ~~~~~ | /
|
|
| ~~~~~~~ BOX |/
|
|
+-------------*/
|
|
|
|
#pragma once
|
|
|
|
#define GLM_ENABLE_EXPERIMENTAL
|
|
|
|
#include <list>
|
|
#include <vector>
|
|
#include <sstream>
|
|
#include <string>
|
|
#include <thread>
|
|
#include <functional>
|
|
#include <cstdlib>
|
|
#include <fstream>
|
|
#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<unsigned char*> pixel_buffers;
|
|
std::vector<bool> flipped;
|
|
std::vector<Uint8*> audio_buffers;
|
|
std::vector<int> 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<Stash> in_game_stashes;
|
|
std::list<Stash> 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(&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"; }
|
|
|
|
};
|