Allow binding commands to class instance
[lsnes.git] / include / core / project.hpp
blob916ab8fcc6b6e33de202d4c3edfdc8d8559c6849
1 #ifndef _project__hpp__included__
2 #define _project__hpp__included__
4 #include <string>
5 #include <map>
6 #include <list>
7 #include <vector>
8 #include "core/rom-small.hpp"
9 #include "library/command.hpp"
10 #include "library/json.hpp"
12 class voice_commentary;
13 class memwatch_set;
14 class controller_state;
15 class button_mapping;
16 class emulator_dispatch;
17 class input_queue;
18 class status_updater;
19 namespace settingvar { class cache; }
21 //A branch.
22 struct project_branch_info
24 //Parent branch ID.
25 uint64_t pbid;
26 //Name.
27 std::string name;
30 //Information about project.
31 struct project_info
33 //Internal ID of the project.
34 std::string id;
35 //Name of the project.
36 std::string name;
37 //Bundle ROM used.
38 std::string rom;
39 //ROMs used.
40 std::string roms[ROM_SLOT_COUNT];
41 //Last savestate.
42 std::string last_save;
43 //Directory for save/load dialogs.
44 std::string directory;
45 //Prefix for save/load dialogs.
46 std::string prefix;
47 //List of Lua scripts to run at startup.
48 std::list<std::string> luascripts;
49 //Memory watches.
50 std::map<std::string, std::string> watches;
51 //Macros.
52 std::map<std::string, JSON::node> macros;
53 //Branches.
54 std::map<uint64_t, project_branch_info> branches;
55 uint64_t active_branch;
56 uint64_t next_branch;
57 //Filename this was loaded from.
58 std::string filename;
59 //Stub movie data.
60 std::string gametype;
61 std::map<std::string, std::string> settings;
62 std::string coreversion;
63 std::string gamename;
64 std::string projectid;
65 std::string romimg_sha256[ROM_SLOT_COUNT];
66 std::string romxml_sha256[ROM_SLOT_COUNT];
67 std::string namehint[ROM_SLOT_COUNT];
68 std::vector<std::pair<std::string, std::string>> authors;
69 std::map<std::string, std::vector<char>> movie_sram;
70 std::vector<char> anchor_savestate;
71 int64_t movie_rtc_second;
72 int64_t movie_rtc_subsecond;
73 /**
74 * Make empty project info.
76 project_info(emulator_dispatch& _dispatch);
77 /**
78 * Obtain parent of branch.
80 * Parameter bid: The branch ID.
81 * Returns: The parent branch ID.
82 * Throws std::runtime_error: Invalid branch ID.
84 * Note: bid 0 is root. Calling this on root always gives 0.
86 uint64_t get_parent_branch(uint64_t bid);
87 /**
88 * Get current branch id.
90 * Returns: The branch id.
92 uint64_t get_current_branch() { return active_branch; }
93 /**
94 * Set current branch.
96 * Parameter bid: The branch id.
97 * Throws std::runtime_error: Invalid branch ID.
99 void set_current_branch(uint64_t bid);
101 * Get name of branch.
103 * Parameter bid: The branch id.
104 * Throws std::runtime_error: Invalid branch ID.
105 * Note: The name of ROOT branch is always empty string.
107 const std::string& get_branch_name(uint64_t bid);
109 * Set name of branch.
111 * Parameter bid: The branch id.
112 * Parameter name: The new name
113 * Throws std::runtime_error: Invalid branch ID.
114 * Note: The name of ROOT branch can't be changed.
116 void set_branch_name(uint64_t bid, const std::string& name);
118 * Set parent branch of branch.
120 * Parameter bid: The branch id.
121 * Parameter pbid: The new parent branch id.
122 * Throws std::runtime_error: Invalid branch ID, or cyclic dependency.
123 * Note: The parent of ROOT branch can't be set.
125 void set_parent_branch(uint64_t bid, uint64_t pbid);
127 * Enumerate child branches of specified branch.
129 * Parameter bid: The branch id.
130 * Returns: The set of chilid branch IDs.
131 * Throws std::runtime_error: Invalid branch ID.
133 std::set<uint64_t> branch_children(uint64_t bid);
135 * Create a new branch.
137 * Parameter pbid: Parent of the new branch.
138 * Parameter name: Name of new branch.
139 * Returns: Id of new branch.
140 * Throws std::runtime_error: Invalid branch ID.
142 uint64_t create_branch(uint64_t pbid, const std::string& name);
144 * Delete a branch.
146 * Parameter bid: The branch id.
147 * Throws std::runtime_error: Invalid branch ID or branch has children.
149 void delete_branch(uint64_t bid);
151 * Get name of current branch as string.
153 std::string get_branch_string();
155 * Flush the project to disk.
157 void flush();
158 private:
159 void write(std::ostream& s);
160 emulator_dispatch& edispatch;
163 class project_state
165 public:
166 project_state(voice_commentary& _commentary, memwatch_set& _mwatch, command::group& _command,
167 controller_state& _controls, settingvar::cache& _setcache, button_mapping& _buttons,
168 emulator_dispatch& _edispatch, input_queue& _iqueue, loaded_rom& _rom, status_updater& _supdater);
169 ~project_state();
171 * Get currently active project.
173 * Returns: The currently active project or NULL if none.
175 project_info* get();
177 * Change currently active project. This reloads Lua VM, ROM and savestate.
179 * Parameter p: The new currently active project, or NULL to switch out of any project.
180 * Parameter current: If true, do not reload ROM, movie nor state.
182 bool set(project_info* p, bool current = false);
184 * Enumerate all known projects.
186 * Returns: Map from IDs of projects to project names.
188 std::map<std::string, std::string> enumerate();
190 * Load a given project.
192 * Parameter id: The ID of project to load.
193 * Returns: The project information.
195 project_info& load(const std::string& id);
197 * Get project movie path.
199 * Returns: The movie path.
201 std::string moviepath();
203 * Get project other path.
205 * Returns: The other path.
207 std::string otherpath();
209 * Get project savestate extension.
211 * Returns: The savestate extension.
213 std::string savestate_ext();
215 * Copy watches to project
217 void copy_watches(project_info& p);
219 * Copy macros to project.
221 void copy_macros(project_info& p, controller_state& s);
222 private:
223 void recursive_list_branch(uint64_t bid, std::set<unsigned>& dset, unsigned depth, bool last_of);
224 void do_branch_ls();
225 void do_branch_mk(const std::string& a);
226 void do_branch_rm(const std::string& a);
227 void do_branch_set(const std::string& a);
228 void do_branch_rp(const std::string& a);
229 void do_branch_mv(const std::string& a);
230 project_info* active_project;
231 voice_commentary& commentary;
232 memwatch_set& mwatch;
233 command::group& command;
234 controller_state& controls;
235 settingvar::cache& setcache;
236 button_mapping& buttons;
237 emulator_dispatch& edispatch;
238 input_queue& iqueue;
239 loaded_rom& rom;
240 status_updater& supdater;
241 command::_fnptr<> branch_ls;
242 command::_fnptr<const std::string&> branch_mk;
243 command::_fnptr<const std::string&> branch_rm;
244 command::_fnptr<const std::string&> branch_set;
245 command::_fnptr<const std::string&> branch_rp;
246 command::_fnptr<const std::string&> branch_mv;
249 #endif