1 #ifndef _instance__hpp__included__
2 #define _instance__hpp__included__
5 #include "core/command.hpp"
6 #include "core/controllerframe.hpp"
7 #include "core/debug.hpp"
8 #include "core/emustatus.hpp"
9 #include "core/framebuffer.hpp"
10 #include "core/framerate.hpp"
11 #include "core/inthread.hpp"
12 #include "core/movie.hpp"
13 #include "core/moviedata.hpp"
14 #include "core/mbranch.hpp"
15 #include "core/memorymanip.hpp"
16 #include "core/memorywatch.hpp"
17 #include "core/multitrack.hpp"
18 #include "core/project.hpp"
19 #include "library/command.hpp"
20 #include "library/exrethrow.hpp"
21 #include "library/lua-base.hpp"
22 #include "library/memoryspace.hpp"
23 #include "library/settingvar.hpp"
24 #include "library/keyboard.hpp"
25 #include "library/keyboard-mapper.hpp"
28 * Information about keypress.
33 * Create null keypress (no modifiers, NULL key and released).
37 * Create new keypress.
39 keypress_info(keyboard::modifier_set mod
, keyboard::key
& _key
, short _value
);
41 * Create new keypress (two keys).
43 keypress_info(keyboard::modifier_set mod
, keyboard::key
& _key
, keyboard::key
& _key2
, short _value
);
47 keyboard::modifier_set modifiers
;
49 * The actual key (first)
53 * The actual key (second)
63 void functor_call_helper2(void* args
)
65 (*reinterpret_cast<T
*>(args
))();
66 delete reinterpret_cast<T
*>(args
);
71 struct function_queue_entry
73 std::function
<void()> fn
;
74 std::function
<void(std::exception
& e
)> onerror
;
78 threads::lock queue_lock
;
79 threads::cv queue_condition
;
80 std::deque
<keypress_info
> keypresses
;
81 std::deque
<std::string
> commands
;
82 std::deque
<function_queue_entry
> functions
;
83 volatile uint64_t functions_executed
;
84 volatile uint64_t next_function
;
85 volatile bool system_thread_available
;
86 bool queue_function_run
;
90 input_queue(command::group
& _command
);
94 * - Can be called from any thread.
96 * Parameter k: The keypress to queue.
98 void queue(const keypress_info
& k
) throw(std::bad_alloc
);
102 * - Can be called from any thread.
104 * Parameter c: The command to queue.
106 void queue(const std::string
& c
) throw(std::bad_alloc
);
108 * Queue function to be called in emulation thread.
110 * - Can be called from any thread (exception: Synchronous mode can not be used from emulation nor main threads).
112 * Parameter f: The function to execute.
113 * Parameter onerror: Function to call on error.
114 * Parameter arg: Argument to pass to the function.
115 * Parameter sync: If true, execute function call synchronously, else asynchronously.
117 void queue(std::function
<void()> f
, std::function
<void(std::exception
& e
)> onerror
, bool sync
)
118 throw(std::bad_alloc
);
122 void run_queues() throw();
124 * Call function synchronously in emulation thread.
126 void run(std::function
<void()> fn
)
128 exrethrow::storage ex
;
129 queue(fn
, [&ex
](std::exception
& e
) { ex
= exrethrow::storage(e
); }, true);
133 * Queue asynchrous function in emulation thread.
135 void run_async(std::function
<void()> fn
,
136 std::function
<void(std::exception
& e
)> onerror
)
138 queue(fn
, onerror
, false);
141 * Run internal queues.
143 void run_queue(bool unlocked
) throw();
145 command::group
& command
;
148 struct emulator_instance
155 settingvar::group settings
;
156 settingvar::cache setcache
;
157 voice_commentary commentary
;
158 subtitle_commentary subtitles
;
159 movie_branches mbranch
;
160 multitrack_edit mteditor
;
161 _lsnes_status status_A
;
162 _lsnes_status status_B
;
163 _lsnes_status status_C
;
164 triplebuffer::triplebuffer
<_lsnes_status
> status
;
165 keyboard::keyboard keyboard
;
166 keyboard::mapper mapper
;
167 command::group command
;
168 alias_binds_manager abindmanager
;
170 cart_mappings_refresher cmapper
;
171 controller_state controls
;
172 project_state project
;
174 framerate_regulator framerate
;
175 emu_framebuffer fbuf
;
177 threads::id emu_thread
;
180 extern emulator_instance lsnes_instance
;
182 emulator_instance
& CORE();