2023-05-23 15:28:53 -04:00
|
|
|
/* +------------------------------------------------------+
|
|
|
|
____/ \____ /| - Open source game framework licensed to freely use, |
|
|
|
|
\ / / | copy, modify and sell without restriction |
|
|
|
|
+--\ ^__^ /--+ | |
|
|
|
|
| ~/ \~ | | - created for <https://foam.shampoo.ooo> |
|
|
|
|
| ~~~~~~~~~~~~ | +------------------------------------------------------+
|
|
|
|
| SPACE ~~~~~ | /
|
|
|
|
| ~~~~~~~ BOX |/
|
|
|
|
+-------------*/
|
|
|
|
|
|
|
|
#pragma once
|
2019-05-07 03:33:54 -04:00
|
|
|
|
2021-09-08 20:07:11 -04:00
|
|
|
#define GLM_ENABLE_EXPERIMENTAL
|
|
|
|
|
2020-09-04 23:10:39 -04:00
|
|
|
#include <list>
|
|
|
|
#include <vector>
|
2019-05-07 03:33:54 -04:00
|
|
|
#include <sstream>
|
|
|
|
#include <string>
|
2019-05-19 05:55:46 -04:00
|
|
|
#include <functional>
|
2019-05-22 04:27:15 -04:00
|
|
|
#include <cstdlib>
|
2020-07-19 15:43:47 -04:00
|
|
|
#include <fstream>
|
2023-10-18 00:07:32 -04:00
|
|
|
#include <thread>
|
2019-05-07 03:33:54 -04:00
|
|
|
#include "SDL.h"
|
2020-07-19 15:43:47 -04:00
|
|
|
#include "SDL_mixer.h"
|
2019-05-07 03:33:54 -04:00
|
|
|
#include "glm/ext.hpp"
|
|
|
|
#include "json/json.hpp"
|
|
|
|
#include "filesystem.hpp"
|
2020-07-19 15:43:47 -04:00
|
|
|
#include "Node.hpp"
|
2023-06-08 20:04:40 -04:00
|
|
|
#include "Configuration.hpp"
|
2019-05-16 03:51:36 -04:00
|
|
|
#include "Animation.hpp"
|
2021-10-02 19:21:07 -04:00
|
|
|
#include "Log.hpp"
|
2019-05-07 03:33:54 -04:00
|
|
|
|
2019-05-25 07:28:05 -04:00
|
|
|
struct Stash
|
|
|
|
{
|
|
|
|
std::vector<unsigned char*> pixel_buffers;
|
2019-06-16 03:05:02 -04:00
|
|
|
std::vector<bool> flipped;
|
2019-06-04 03:20:13 -04:00
|
|
|
std::vector<Uint8*> audio_buffers;
|
|
|
|
std::vector<int> audio_buffer_lengths;
|
2019-05-25 07:28:05 -04:00
|
|
|
int frame_offset;
|
|
|
|
|
|
|
|
Stash(int frame_offset = 0) : frame_offset(frame_offset) {}
|
|
|
|
};
|
|
|
|
|
2021-08-02 20:18:56 -04:00
|
|
|
class Recorder : public Node
|
2019-05-07 03:33:54 -04:00
|
|
|
{
|
|
|
|
|
2021-08-02 20:18:56 -04:00
|
|
|
private:
|
|
|
|
|
2019-05-31 02:54:31 -04:00
|
|
|
Stash current_stash = Stash();
|
|
|
|
Stash most_recent_stash;
|
2019-07-21 03:13:19 -04:00
|
|
|
std::list<Stash> in_game_stashes;
|
|
|
|
std::list<Stash> video_stashes;
|
2019-06-04 03:20:13 -04:00
|
|
|
fs::path current_video_directory, current_audio_path;
|
2019-05-31 02:54:31 -04:00
|
|
|
bool is_recording = false, writing_recording = false, writing_most_recent = false;
|
2019-06-04 03:20:13 -04:00
|
|
|
std::ofstream audio_file;
|
2019-05-16 03:51:36 -04:00
|
|
|
|
2021-08-02 20:18:56 -04:00
|
|
|
float frame_length();
|
|
|
|
static void process_audio(void*, Uint8*, int);
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
2023-06-23 01:45:28 -04:00
|
|
|
Animation animation = Animation(std::bind(&Recorder::add_frame, this));
|
2023-06-08 12:56:21 -04:00
|
|
|
|
2019-05-07 03:33:54 -04:00
|
|
|
Recorder(Node*);
|
|
|
|
void respond(SDL_Event&);
|
|
|
|
void capture_screen();
|
2019-05-31 02:54:31 -04:00
|
|
|
void grab_stash();
|
|
|
|
void write_most_recent_frames();
|
2019-05-16 03:51:36 -04:00
|
|
|
void start_recording();
|
2019-06-04 03:20:13 -04:00
|
|
|
void open_audio_file();
|
2019-05-25 07:28:05 -04:00
|
|
|
void add_frame();
|
|
|
|
int get_memory_size();
|
2019-06-04 03:20:13 -04:00
|
|
|
void make_directory();
|
2019-07-21 03:13:19 -04:00
|
|
|
void write_stash_frames(Stash*);
|
2019-05-25 07:28:05 -04:00
|
|
|
void keep_stash();
|
2019-05-16 03:51:36 -04:00
|
|
|
void end_recording();
|
2019-05-25 07:28:05 -04:00
|
|
|
void finish_writing_video();
|
2019-05-31 02:54:31 -04:00
|
|
|
void write_mp4();
|
2019-06-04 03:20:13 -04:00
|
|
|
void write_audio(Uint8*, int);
|
2023-06-07 20:22:20 -04:00
|
|
|
void update(float timestamp);
|
2021-08-14 19:53:39 -04:00
|
|
|
virtual std::string class_name() const { return "Recorder"; }
|
2019-05-07 03:33:54 -04:00
|
|
|
|
|
|
|
};
|