JSON-based controller descriptions
[lsnes.git] / src / core / advdumper.cpp
blobde054fcb662af37e109606063b30c2a0e2ae8328
1 #include "core/advdumper.hpp"
2 #include "core/command.hpp"
3 #include "core/dispatch.hpp"
4 #include "library/globalwrap.hpp"
5 #include "lua/lua.hpp"
6 #include "library/string.hpp"
8 #include <map>
9 #include <string>
11 namespace
13 globalwrap<std::map<std::string, adv_dumper*>> dumpers;
16 const std::string& adv_dumper::id() throw()
18 return d_id;
21 adv_dumper::~adv_dumper()
23 dumpers().erase(d_id);
24 information_dispatch::do_dumper_update();
27 std::set<adv_dumper*> adv_dumper::get_dumper_set() throw(std::bad_alloc)
29 std::set<adv_dumper*> d;
30 for(auto i : dumpers())
31 d.insert(i.second);
32 return d;
35 adv_dumper::adv_dumper(const std::string& id) throw(std::bad_alloc)
37 d_id = id;
38 dumpers()[d_id] = this;
41 unsigned adv_dumper::target_type_mask = 3;
42 unsigned adv_dumper::target_type_file = 0;
43 unsigned adv_dumper::target_type_prefix = 1;
44 unsigned adv_dumper::target_type_special = 2;
46 template<bool X> bool render_video_hud(struct framebuffer<X>& target, struct framebuffer_raw& source, uint32_t hscl,
47 uint32_t vscl, uint32_t roffset, uint32_t goffset, uint32_t boffset, uint32_t lgap, uint32_t tgap,
48 uint32_t rgap, uint32_t bgap, void(*fn)())
50 bool lua_kill_video = false;
51 struct lua_render_context lrc;
52 render_queue rq;
53 lrc.left_gap = lgap;
54 lrc.right_gap = rgap;
55 lrc.bottom_gap = bgap;
56 lrc.top_gap = tgap;
57 lrc.queue = &rq;
58 lrc.width = source.get_width();
59 lrc.height = source.get_height();
60 lua_callback_do_video(&lrc, lua_kill_video);
61 if(fn)
62 fn();
63 target.set_palette(roffset, goffset, boffset);
64 target.reallocate(lrc.left_gap + source.get_width() * hscl + lrc.right_gap, lrc.top_gap +
65 source.get_height() * vscl + lrc.bottom_gap, false);
66 target.set_origin(lrc.left_gap, lrc.top_gap);
67 target.copy_from(source, hscl, vscl);
68 rq.run(target);
69 return !lua_kill_video;
72 uint64_t killed_audio_length(uint32_t fps_n, uint32_t fps_d, double& fraction)
74 auto g = information_dispatch::get_sound_rate();
75 double x = 1.0 * fps_d * g.first / (fps_n * g.second) + fraction;
76 uint64_t y = x;
77 fraction = x - y;
78 return y;
81 template bool render_video_hud(struct framebuffer<false>& target, struct framebuffer_raw& source, uint32_t hscl,
82 uint32_t vscl, uint32_t roffset, uint32_t goffset, uint32_t boffset, uint32_t lgap, uint32_t tgap,
83 uint32_t rgap, uint32_t bgap, void(*fn)());
84 template bool render_video_hud(struct framebuffer<true>& target, struct framebuffer_raw& source, uint32_t hscl,
85 uint32_t vscl, uint32_t roffset, uint32_t goffset, uint32_t boffset, uint32_t lgap, uint32_t tgap,
86 uint32_t rgap, uint32_t bgap, void(*fn)());