Antkeeper  0.0.1
controls.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2023 Christopher J. Howard
3  *
4  * This file is part of Antkeeper source code.
5  *
6  * Antkeeper source code is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * Antkeeper source code is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
18  */
19 
20 #include "game/controls.hpp"
21 #include "game/graphics.hpp"
22 #include "game/menu.hpp"
23 #include "game/control-profile.hpp"
26 #include <engine/utility/json.hpp>
29 
30 
32 {
33  auto& mappings = profile.mappings;
34  auto& settings = profile.settings;
35 
36  mappings.clear();
37  settings.clear();
38 
39  // Fullscreen
40  mappings.emplace("fullscreen", std::make_unique<input::key_mapping>(nullptr, input::scancode::f11, 0, false));
41  mappings.emplace("fullscreen", std::make_unique<input::key_mapping>(nullptr, input::scancode::enter, input::modifier_key::alt, false));
42 
43  // Screenshot
44  mappings.emplace("screenshot", std::make_unique<input::key_mapping>(nullptr, input::scancode::f12, 0, false));
45  mappings.emplace("screenshot", std::make_unique<input::key_mapping>(nullptr, input::scancode::print_screen, 0, false));
46 
47  // Menu up
48  mappings.emplace("menu_up", std::make_unique<input::key_mapping>(nullptr, input::scancode::up, 0, true));
49  mappings.emplace("menu_up", std::make_unique<input::key_mapping>(nullptr, input::scancode::w, 0, true));
50  mappings.emplace("menu_up", std::make_unique<input::key_mapping>(nullptr, input::scancode::i, 0, true));
51  mappings.emplace("menu_up", std::make_unique<input::gamepad_axis_mapping>(nullptr, input::gamepad_axis::left_stick_y, true));
52  mappings.emplace("menu_up", std::make_unique<input::gamepad_axis_mapping>(nullptr, input::gamepad_axis::right_stick_y, true));
53  mappings.emplace("menu_up", std::make_unique<input::gamepad_button_mapping>(nullptr, input::gamepad_button::dpad_up));
54 
55  // Menu down
56  mappings.emplace("menu_down", std::make_unique<input::key_mapping>(nullptr, input::scancode::down, 0, true));
57  mappings.emplace("menu_down", std::make_unique<input::key_mapping>(nullptr, input::scancode::s, 0, true));
58  mappings.emplace("menu_down", std::make_unique<input::key_mapping>(nullptr, input::scancode::k, 0, true));
59  mappings.emplace("menu_down", std::make_unique<input::gamepad_axis_mapping>(nullptr, input::gamepad_axis::left_stick_y, false));
60  mappings.emplace("menu_down", std::make_unique<input::gamepad_axis_mapping>(nullptr, input::gamepad_axis::right_stick_y, false));
61  mappings.emplace("menu_down", std::make_unique<input::gamepad_button_mapping>(nullptr, input::gamepad_button::dpad_down));
62 
63  // Menu left
64  mappings.emplace("menu_left", std::make_unique<input::key_mapping>(nullptr, input::scancode::left, 0, true));
65  mappings.emplace("menu_left", std::make_unique<input::key_mapping>(nullptr, input::scancode::a, 0, true));
66  mappings.emplace("menu_left", std::make_unique<input::key_mapping>(nullptr, input::scancode::j, 0, true));
67  mappings.emplace("menu_left", std::make_unique<input::gamepad_axis_mapping>(nullptr, input::gamepad_axis::left_stick_x, true));
68  mappings.emplace("menu_left", std::make_unique<input::gamepad_axis_mapping>(nullptr, input::gamepad_axis::right_stick_x, true));
69  mappings.emplace("menu_left", std::make_unique<input::gamepad_button_mapping>(nullptr, input::gamepad_button::dpad_left));
70  mappings.emplace("menu_left", std::make_unique<input::mouse_scroll_mapping>(nullptr, input::mouse_scroll_axis::x, true));
71  mappings.emplace("menu_left", std::make_unique<input::mouse_scroll_mapping>(nullptr, input::mouse_scroll_axis::y, true));
72 
73  // Menu right
74  mappings.emplace("menu_right", std::make_unique<input::key_mapping>(nullptr, input::scancode::right, 0, true));
75  mappings.emplace("menu_right", std::make_unique<input::key_mapping>(nullptr, input::scancode::d, 0, true));
76  mappings.emplace("menu_right", std::make_unique<input::key_mapping>(nullptr, input::scancode::l, 0, true));
77  mappings.emplace("menu_right", std::make_unique<input::gamepad_axis_mapping>(nullptr, input::gamepad_axis::left_stick_x, false));
78  mappings.emplace("menu_right", std::make_unique<input::gamepad_axis_mapping>(nullptr, input::gamepad_axis::right_stick_x, false));
79  mappings.emplace("menu_right", std::make_unique<input::gamepad_button_mapping>(nullptr, input::gamepad_button::dpad_right));
80  mappings.emplace("menu_right", std::make_unique<input::mouse_scroll_mapping>(nullptr, input::mouse_scroll_axis::x, false));
81  mappings.emplace("menu_right", std::make_unique<input::mouse_scroll_mapping>(nullptr, input::mouse_scroll_axis::y, false));
82 
83  // Menu select
84  mappings.emplace("menu_select", std::make_unique<input::key_mapping>(nullptr, input::scancode::enter, 0, false));
85  mappings.emplace("menu_select", std::make_unique<input::key_mapping>(nullptr, input::scancode::space, 0, false));
86  mappings.emplace("menu_select", std::make_unique<input::key_mapping>(nullptr, input::scancode::e, 0, false));
87  mappings.emplace("menu_select", std::make_unique<input::gamepad_button_mapping>(nullptr, input::gamepad_button::a));
88 
89  // Menu back
90  mappings.emplace("menu_back", std::make_unique<input::key_mapping>(nullptr, input::scancode::escape, 0, false));
91  mappings.emplace("menu_back", std::make_unique<input::key_mapping>(nullptr, input::scancode::backspace, 0, false));
92  mappings.emplace("menu_back", std::make_unique<input::key_mapping>(nullptr, input::scancode::q, 0, false));
93  mappings.emplace("menu_back", std::make_unique<input::gamepad_button_mapping>(nullptr, input::gamepad_button::b));
94  mappings.emplace("menu_back", std::make_unique<input::gamepad_button_mapping>(nullptr, input::gamepad_button::back));
95 
96  // Menu modifier
97  mappings.emplace("menu_modifier", std::make_unique<input::key_mapping>(nullptr, input::scancode::left_shift, 0, false));
98  mappings.emplace("menu_modifier", std::make_unique<input::key_mapping>(nullptr, input::scancode::right_shift, 0, false));
99 
100  // Move forward
101  mappings.emplace("move_forward", std::make_unique<input::key_mapping>(nullptr, input::scancode::w, 0, false));
102  mappings.emplace("move_forward", std::make_unique<input::gamepad_axis_mapping>(nullptr, input::gamepad_axis::left_stick_y, true));
103 
104  // Move back
105  mappings.emplace("move_back", std::make_unique<input::key_mapping>(nullptr, input::scancode::s, 0, false));
106  mappings.emplace("move_back", std::make_unique<input::gamepad_axis_mapping>(nullptr, input::gamepad_axis::left_stick_y, false));
107 
108  // Move left
109  mappings.emplace("move_left", std::make_unique<input::key_mapping>(nullptr, input::scancode::a, 0, false));
110  mappings.emplace("move_left", std::make_unique<input::gamepad_axis_mapping>(nullptr, input::gamepad_axis::left_stick_x, true));
111 
112  // Move right
113  mappings.emplace("move_right", std::make_unique<input::key_mapping>(nullptr, input::scancode::d, 0, false));
114  mappings.emplace("move_right", std::make_unique<input::gamepad_axis_mapping>(nullptr, input::gamepad_axis::left_stick_x, false));
115 
116  // Move up
117  mappings.emplace("move_up", std::make_unique<input::mouse_scroll_mapping>(nullptr, input::mouse_scroll_axis::y, false));
118  mappings.emplace("move_up", std::make_unique<input::gamepad_axis_mapping>(nullptr, input::gamepad_axis::right_trigger, false));
119 
120  // Move down
121  mappings.emplace("move_down", std::make_unique<input::mouse_scroll_mapping>(nullptr, input::mouse_scroll_axis::y, true));
122  mappings.emplace("move_down", std::make_unique<input::gamepad_axis_mapping>(nullptr, input::gamepad_axis::left_trigger, false));
123 
124  // Interact
125  mappings.emplace("interact", std::make_unique<input::key_mapping>(nullptr, input::scancode::e, 0, false));
126  mappings.emplace("interact", std::make_unique<input::gamepad_button_mapping>(nullptr, input::gamepad_button::a));
127 
128  // Move fast
129  // mappings.emplace("move_fast", std::make_unique<input::key_mapping>(nullptr, input::scancode::left_shift, 0, false));
130 
131  // Move slow
132  mappings.emplace("move_slow", std::make_unique<input::key_mapping>(nullptr, input::scancode::left_ctrl, 0, false));
133 
134  // Camera mouse pick
135  mappings.emplace("camera_mouse_pick", std::make_unique<input::mouse_button_mapping>(nullptr, input::mouse_button::left));
136 
137  // Camera mouse look
138  mappings.emplace("camera_mouse_look", std::make_unique<input::mouse_button_mapping>(nullptr, input::mouse_button::right));
139 
140  // Camera mouse drag
141  mappings.emplace("camera_mouse_drag", std::make_unique<input::mouse_button_mapping>(nullptr, input::mouse_button::middle));
142 
143  // Camera zoom
144  mappings.emplace("camera_mouse_zoom", std::make_unique<input::key_mapping>(nullptr, input::scancode::z, 0, false));
145  mappings.emplace("camera_zoom_in", std::make_unique<input::mouse_scroll_mapping>(nullptr, input::mouse_scroll_axis::y, false));
146  mappings.emplace("camera_zoom_out", std::make_unique<input::mouse_scroll_mapping>(nullptr, input::mouse_scroll_axis::y, true));
147 
148  // Camera orbit
149  mappings.emplace("camera_orbit_left", std::make_unique<input::key_mapping>(nullptr, input::scancode::left, 0, false));
150  mappings.emplace("camera_orbit_left", std::make_unique<input::gamepad_axis_mapping>(nullptr, input::gamepad_axis::right_stick_x, false));
151  mappings.emplace("camera_orbit_right", std::make_unique<input::key_mapping>(nullptr, input::scancode::right, 0, false));
152  mappings.emplace("camera_orbit_right", std::make_unique<input::gamepad_axis_mapping>(nullptr, input::gamepad_axis::right_stick_x, true));
153  mappings.emplace("camera_orbit_up", std::make_unique<input::key_mapping>(nullptr, input::scancode::up, 0, false));
154  mappings.emplace("camera_orbit_up", std::make_unique<input::gamepad_axis_mapping>(nullptr, input::gamepad_axis::right_stick_y, true));
155  mappings.emplace("camera_orbit_down", std::make_unique<input::key_mapping>(nullptr, input::scancode::up, 0, false));
156  mappings.emplace("camera_orbit_down", std::make_unique<input::gamepad_axis_mapping>(nullptr, input::gamepad_axis::right_stick_y, false));
157 
158  // Camera look ahead
159  mappings.emplace("camera_look_ahead", std::make_unique<input::key_mapping>(nullptr, input::scancode::left_shift, 0, false));
160  mappings.emplace("camera_look_ahead", std::make_unique<input::gamepad_axis_mapping>(nullptr, input::gamepad_axis::left_trigger, false));
161 
162  // Camera presets
163  mappings.emplace("camera_preset_1", std::make_unique<input::key_mapping>(nullptr, input::scancode::digit_1, 0, false));
164  mappings.emplace("camera_preset_2", std::make_unique<input::key_mapping>(nullptr, input::scancode::digit_2, 0, false));
165  mappings.emplace("camera_preset_3", std::make_unique<input::key_mapping>(nullptr, input::scancode::digit_3, 0, false));
166  mappings.emplace("camera_preset_4", std::make_unique<input::key_mapping>(nullptr, input::scancode::digit_4, 0, false));
167  mappings.emplace("camera_preset_5", std::make_unique<input::key_mapping>(nullptr, input::scancode::digit_5, 0, false));
168  mappings.emplace("camera_preset_6", std::make_unique<input::key_mapping>(nullptr, input::scancode::digit_6, 0, false));
169  mappings.emplace("camera_preset_7", std::make_unique<input::key_mapping>(nullptr, input::scancode::digit_7, 0, false));
170  mappings.emplace("camera_preset_8", std::make_unique<input::key_mapping>(nullptr, input::scancode::digit_8, 0, false));
171  mappings.emplace("camera_preset_9", std::make_unique<input::key_mapping>(nullptr, input::scancode::digit_9, 0, false));
172  mappings.emplace("camera_preset_10", std::make_unique<input::key_mapping>(nullptr, input::scancode::digit_0, 0, false));
173  mappings.emplace("camera_save_preset", std::make_unique<input::key_mapping>(nullptr, input::scancode::left_ctrl, 0, false));
174  mappings.emplace("camera_save_preset", std::make_unique<input::key_mapping>(nullptr, input::scancode::right_ctrl, 0, false));
175 
176  // Oviposit
177  mappings.emplace("oviposit", std::make_unique<input::key_mapping>(nullptr, input::scancode::left_alt, 0, false));
178 
179  // Pause
180  mappings.emplace("pause", std::make_unique<input::key_mapping>(nullptr, input::scancode::escape, 0, false));
181  mappings.emplace("pause", std::make_unique<input::gamepad_button_mapping>(nullptr, input::gamepad_button::start));
182 
183  // Toggle debug UI
184  mappings.emplace("toggle_debug", std::make_unique<input::key_mapping>(nullptr, input::scancode::grave, 0, false));
185 
186  // Adjust exposure
187  mappings.emplace("adjust_exposure", std::make_unique<input::key_mapping>(nullptr, input::scancode::b, 0, false));
188 
189  // Adjust time
190  mappings.emplace("adjust_time", std::make_unique<input::key_mapping>(nullptr, input::scancode::t, 0, false));
191 }
192 
193 void apply_control_profile(::game& ctx, const ::control_profile& profile)
194 {
195  auto add_mappings = [&profile](input::action_map& map, input::action& action, hash::fnv1a32_t key)
196  {
197  auto range = profile.mappings.equal_range(key);
198  for (auto i = range.first; i != range.second; ++i)
199  {
200  map.add_mapping(action, *i->second);
201  }
202  };
203 
204  // Window controls
206  add_mappings(ctx.window_action_map, ctx.fullscreen_action, "fullscreen");
207  add_mappings(ctx.window_action_map, ctx.screenshot_action, "screenshot");
208 
209  // Menu controls
211  add_mappings(ctx.menu_action_map, ctx.menu_up_action, "menu_up");
212  add_mappings(ctx.menu_action_map, ctx.menu_down_action, "menu_down");
213  add_mappings(ctx.menu_action_map, ctx.menu_left_action, "menu_left");
214  add_mappings(ctx.menu_action_map, ctx.menu_right_action, "menu_right");
215  add_mappings(ctx.menu_action_map, ctx.menu_select_action, "menu_select");
216  add_mappings(ctx.menu_action_map, ctx.menu_back_action, "menu_back");
217  add_mappings(ctx.menu_action_map, ctx.menu_modifier_action, "menu_modifier");
218 
219  // Movement controls
221  add_mappings(ctx.movement_action_map, ctx.move_forward_action, "move_forward");
222  add_mappings(ctx.movement_action_map, ctx.move_back_action, "move_back");
223  add_mappings(ctx.movement_action_map, ctx.move_left_action, "move_left");
224  add_mappings(ctx.movement_action_map, ctx.move_right_action, "move_right");
225  add_mappings(ctx.movement_action_map, ctx.move_up_action, "move_up");
226  add_mappings(ctx.movement_action_map, ctx.move_down_action, "move_down");
227  add_mappings(ctx.movement_action_map, ctx.move_fast_action, "move_fast");
228  add_mappings(ctx.movement_action_map, ctx.move_slow_action, "move_slow");
229  add_mappings(ctx.movement_action_map, ctx.pause_action, "pause");
230 
231  // Camera controls
233  add_mappings(ctx.camera_action_map, ctx.camera_mouse_pick_action, "camera_mouse_pick");
234  add_mappings(ctx.camera_action_map, ctx.camera_mouse_look_action, "camera_mouse_look");
235  add_mappings(ctx.camera_action_map, ctx.camera_mouse_drag_action, "camera_mouse_drag");
236  add_mappings(ctx.camera_action_map, ctx.camera_mouse_zoom_action, "camera_mouse_zoom");
237  add_mappings(ctx.camera_action_map, ctx.camera_zoom_in_action, "camera_zoom_in");
238  add_mappings(ctx.camera_action_map, ctx.camera_zoom_out_action, "camera_zoom_out");
239  add_mappings(ctx.camera_action_map, ctx.camera_orbit_left_action, "camera_orbit_left");
240  add_mappings(ctx.camera_action_map, ctx.camera_orbit_right_action, "camera_orbit_right");
241  add_mappings(ctx.camera_action_map, ctx.camera_orbit_up_action, "camera_orbit_up");
242  add_mappings(ctx.camera_action_map, ctx.camera_orbit_down_action, "camera_orbit_down");
243  add_mappings(ctx.camera_action_map, ctx.camera_look_ahead_action, "camera_look_ahead");
244  add_mappings(ctx.camera_action_map, ctx.camera_preset_1_action, "camera_preset_1");
245  add_mappings(ctx.camera_action_map, ctx.camera_preset_2_action, "camera_preset_2");
246  add_mappings(ctx.camera_action_map, ctx.camera_preset_3_action, "camera_preset_3");
247  add_mappings(ctx.camera_action_map, ctx.camera_preset_4_action, "camera_preset_4");
248  add_mappings(ctx.camera_action_map, ctx.camera_preset_5_action, "camera_preset_5");
249  add_mappings(ctx.camera_action_map, ctx.camera_preset_6_action, "camera_preset_6");
250  add_mappings(ctx.camera_action_map, ctx.camera_preset_7_action, "camera_preset_7");
251  add_mappings(ctx.camera_action_map, ctx.camera_preset_8_action, "camera_preset_8");
252  add_mappings(ctx.camera_action_map, ctx.camera_preset_9_action, "camera_preset_9");
253  add_mappings(ctx.camera_action_map, ctx.camera_preset_10_action, "camera_preset_10");
254  add_mappings(ctx.camera_action_map, ctx.camera_save_preset_action, "camera_save_preset");
255 
256  // Ant controls
258  add_mappings(ctx.ant_action_map, ctx.ant_move_forward_action, "move_forward");
259  add_mappings(ctx.ant_action_map, ctx.ant_move_back_action, "move_back");
260  add_mappings(ctx.ant_action_map, ctx.ant_move_left_action, "move_left");
261  add_mappings(ctx.ant_action_map, ctx.ant_move_right_action, "move_right");
262  add_mappings(ctx.ant_action_map, ctx.ant_move_fast_action, "move_fast");
263  add_mappings(ctx.ant_action_map, ctx.ant_move_slow_action, "move_slow");
264  add_mappings(ctx.ant_action_map, ctx.ant_interact_action, "interact");
265  add_mappings(ctx.ant_action_map, ctx.ant_oviposit_action, "oviposit");
266 
267  // Debug controls
268  add_mappings(ctx.debug_action_map, ctx.toggle_debug_ui_action, "toggle_debug");
269  add_mappings(ctx.debug_action_map, ctx.adjust_exposure_action, "adjust_exposure");
270  add_mappings(ctx.debug_action_map, ctx.adjust_time_action, "adjust_time");
271 }
272 
274 {
275  auto add_mappings = [&profile](const input::action_map& map, const input::action& action, hash::fnv1a32_t key)
276  {
277  auto gamepad_axis_mappings = map.get_gamepad_axis_mappings(action);
278  auto gamepad_button_mappings = map.get_gamepad_button_mappings(action);
279  auto key_mappings = map.get_key_mappings(action);
280  auto mouse_button_mappings = map.get_mouse_button_mappings(action);
281  auto mouse_motion_mappings = map.get_mouse_motion_mappings(action);
282  auto mouse_scroll_mappings = map.get_mouse_scroll_mappings(action);
283 
284  for (const auto& mapping: gamepad_axis_mappings)
285  {
286  profile.mappings.emplace(key, std::make_unique<input::gamepad_axis_mapping>(mapping));
287  }
288  for (const auto& mapping: gamepad_button_mappings)
289  {
290  profile.mappings.emplace(key, std::make_unique<input::gamepad_button_mapping>(mapping));
291  }
292  for (const auto& mapping: key_mappings)
293  {
294  profile.mappings.emplace(key, std::make_unique<input::key_mapping>(mapping));
295  }
296  for (const auto& mapping: mouse_button_mappings)
297  {
298  profile.mappings.emplace(key, std::make_unique<input::mouse_button_mapping>(mapping));
299  }
300  for (const auto& mapping: mouse_motion_mappings)
301  {
302  profile.mappings.emplace(key, std::make_unique<input::mouse_motion_mapping>(mapping));
303  }
304  for (const auto& mapping: mouse_scroll_mappings)
305  {
306  profile.mappings.emplace(key, std::make_unique<input::mouse_scroll_mapping>(mapping));
307  }
308  };
309 
310  profile.mappings.clear();
311 
312  // Window controls
313  add_mappings(ctx.window_action_map, ctx.fullscreen_action, "fullscreen");
314  add_mappings(ctx.window_action_map, ctx.screenshot_action, "screenshot");
315 
316  // Menu controls
317  add_mappings(ctx.menu_action_map, ctx.menu_up_action, "menu_up");
318  add_mappings(ctx.menu_action_map, ctx.menu_down_action, "menu_down");
319  add_mappings(ctx.menu_action_map, ctx.menu_left_action, "menu_left");
320  add_mappings(ctx.menu_action_map, ctx.menu_right_action, "menu_right");
321  add_mappings(ctx.menu_action_map, ctx.menu_select_action, "menu_select");
322  add_mappings(ctx.menu_action_map, ctx.menu_back_action, "menu_back");
323  add_mappings(ctx.menu_action_map, ctx.menu_modifier_action, "menu_modifier");
324 
325  // Movement controls
326  add_mappings(ctx.movement_action_map, ctx.move_forward_action, "move_forward");
327  add_mappings(ctx.movement_action_map, ctx.move_back_action, "move_back");
328  add_mappings(ctx.movement_action_map, ctx.move_left_action, "move_left");
329  add_mappings(ctx.movement_action_map, ctx.move_right_action, "move_right");
330  add_mappings(ctx.movement_action_map, ctx.move_up_action, "move_up");
331  add_mappings(ctx.movement_action_map, ctx.move_down_action, "move_down");
332  add_mappings(ctx.movement_action_map, ctx.move_fast_action, "move_fast");
333  add_mappings(ctx.movement_action_map, ctx.move_slow_action, "move_slow");
334  add_mappings(ctx.movement_action_map, ctx.pause_action, "pause");
335 
336  // Ant controls
337  add_mappings(ctx.ant_action_map, ctx.ant_move_forward_action, "move_forward");
338  add_mappings(ctx.ant_action_map, ctx.ant_move_back_action, "move_back");
339  add_mappings(ctx.ant_action_map, ctx.ant_move_left_action, "move_left");
340  add_mappings(ctx.ant_action_map, ctx.ant_move_right_action, "move_right");
341  add_mappings(ctx.ant_action_map, ctx.ant_move_fast_action, "move_fast");
342  add_mappings(ctx.ant_action_map, ctx.ant_move_slow_action, "move_slow");
343  add_mappings(ctx.ant_action_map, ctx.ant_interact_action, "interact");
344  add_mappings(ctx.ant_action_map, ctx.ant_oviposit_action, "oviposit");
345 
346  // Camera controls
347  add_mappings(ctx.camera_action_map, ctx.camera_mouse_pick_action, "camera_mouse_pick");
348  add_mappings(ctx.camera_action_map, ctx.camera_mouse_look_action, "camera_mouse_look");
349  add_mappings(ctx.camera_action_map, ctx.camera_mouse_drag_action, "camera_mouse_drag");
350  add_mappings(ctx.camera_action_map, ctx.camera_mouse_zoom_action, "camera_mouse_zoom");
351  add_mappings(ctx.camera_action_map, ctx.camera_zoom_in_action, "camera_zoom_in");
352  add_mappings(ctx.camera_action_map, ctx.camera_zoom_out_action, "camera_zoom_out");
353  add_mappings(ctx.camera_action_map, ctx.camera_orbit_left_action, "camera_orbit_left");
354  add_mappings(ctx.camera_action_map, ctx.camera_orbit_right_action, "camera_orbit_right");
355  add_mappings(ctx.camera_action_map, ctx.camera_orbit_up_action, "camera_orbit_up");
356  add_mappings(ctx.camera_action_map, ctx.camera_orbit_down_action, "camera_orbit_down");
357  add_mappings(ctx.camera_action_map, ctx.camera_look_ahead_action, "camera_look_ahead");
358  add_mappings(ctx.camera_action_map, ctx.camera_preset_1_action, "camera_preset_1");
359  add_mappings(ctx.camera_action_map, ctx.camera_preset_2_action, "camera_preset_2");
360  add_mappings(ctx.camera_action_map, ctx.camera_preset_3_action, "camera_preset_3");
361  add_mappings(ctx.camera_action_map, ctx.camera_preset_4_action, "camera_preset_4");
362  add_mappings(ctx.camera_action_map, ctx.camera_preset_5_action, "camera_preset_5");
363  add_mappings(ctx.camera_action_map, ctx.camera_preset_6_action, "camera_preset_6");
364  add_mappings(ctx.camera_action_map, ctx.camera_preset_7_action, "camera_preset_7");
365  add_mappings(ctx.camera_action_map, ctx.camera_preset_8_action, "camera_preset_8");
366  add_mappings(ctx.camera_action_map, ctx.camera_preset_9_action, "camera_preset_9");
367  add_mappings(ctx.camera_action_map, ctx.camera_preset_10_action, "camera_preset_10");
368  add_mappings(ctx.camera_action_map, ctx.camera_save_preset_action, "camera_save_preset");
369 
370  // Debug controls
371  add_mappings(ctx.debug_action_map, ctx.toggle_debug_ui_action, "toggle_debug");
372  add_mappings(ctx.debug_action_map, ctx.adjust_exposure_action, "adjust_exposure");
373  add_mappings(ctx.debug_action_map, ctx.adjust_time_action, "adjust_time");
374 }
375 
377 {
378  // Setup pause control
379  ctx.movement_action_subscriptions.emplace_back
380  (
381  ctx.pause_action.get_activated_channel().subscribe
382  (
383  [&ctx](const auto& event)
384  {
385  if (!ctx.resume_callback)
386  {
387  // Queue disable game controls and push pause state
388  ctx.function_queue.push
389  (
390  [&ctx]()
391  {
392  // Disable game controls
393  ::disable_game_controls(ctx);
394 
395  // Push pause menu state
396  ctx.state_machine.emplace(std::make_unique<pause_menu_state>(ctx));
397  }
398  );
399 
400  // Set resume callback
401  ctx.resume_callback = [&ctx]()
402  {
403  enable_game_controls(ctx);
404  ctx.resume_callback = nullptr;
405  };
406  }
407  }
408  )
409  );
410 }
411 
413 {
415 }
416 
418 {
420 
422  ctx.move_back_action.reset();
423  ctx.move_left_action.reset();
424  ctx.move_right_action.reset();
425  ctx.move_up_action.reset();
426  ctx.move_down_action.reset();
427  ctx.move_fast_action.reset();
428  ctx.move_slow_action.reset();
429  ctx.pause_action.reset();
430 }
Definition: game.hpp:121
input::action camera_preset_3_action
Definition: game.hpp:240
input::action ant_move_fast_action
Definition: game.hpp:255
input::action ant_move_back_action
Definition: game.hpp:252
input::action camera_preset_6_action
Definition: game.hpp:243
input::action camera_preset_8_action
Definition: game.hpp:245
input::action_map window_action_map
Definition: game.hpp:200
input::action camera_preset_4_action
Definition: game.hpp:241
input::action camera_look_ahead_action
Definition: game.hpp:237
input::action menu_modifier_action
Definition: game.hpp:211
input::action move_up_action
Definition: game.hpp:220
input::action move_down_action
Definition: game.hpp:221
input::action move_right_action
Definition: game.hpp:219
input::action ant_oviposit_action
Definition: game.hpp:258
input::action menu_left_action
Definition: game.hpp:207
input::action menu_up_action
Definition: game.hpp:205
input::action ant_interact_action
Definition: game.hpp:257
input::action toggle_debug_ui_action
Definition: game.hpp:261
input::action_map ant_action_map
Definition: game.hpp:250
input::action adjust_exposure_action
Definition: game.hpp:262
input::action pause_action
Definition: game.hpp:224
input::action ant_move_slow_action
Definition: game.hpp:256
input::action camera_preset_9_action
Definition: game.hpp:246
input::action camera_preset_7_action
Definition: game.hpp:244
input::action camera_save_preset_action
Definition: game.hpp:248
input::action menu_back_action
Definition: game.hpp:210
input::action_map camera_action_map
Definition: game.hpp:226
input::action camera_orbit_right_action
Definition: game.hpp:234
input::action menu_select_action
Definition: game.hpp:209
std::vector< std::shared_ptr<::event::subscription > > movement_action_subscriptions
Definition: game.hpp:269
input::action camera_mouse_drag_action
Definition: game.hpp:229
input::action camera_preset_1_action
Definition: game.hpp:238
input::action move_left_action
Definition: game.hpp:218
input::action camera_orbit_left_action
Definition: game.hpp:233
input::action move_forward_action
Definition: game.hpp:216
input::action ant_move_right_action
Definition: game.hpp:254
input::action camera_preset_5_action
Definition: game.hpp:242
input::action fullscreen_action
Definition: game.hpp:201
input::action screenshot_action
Definition: game.hpp:202
input::action camera_mouse_look_action
Definition: game.hpp:228
input::action adjust_time_action
Definition: game.hpp:263
input::action_map menu_action_map
Definition: game.hpp:204
input::action camera_mouse_pick_action
Definition: game.hpp:227
input::action ant_move_forward_action
Definition: game.hpp:251
input::action camera_preset_10_action
Definition: game.hpp:247
input::action camera_orbit_up_action
Definition: game.hpp:235
input::action camera_preset_2_action
Definition: game.hpp:239
input::action menu_down_action
Definition: game.hpp:206
input::action camera_orbit_down_action
Definition: game.hpp:236
input::action move_slow_action
Definition: game.hpp:223
input::action move_back_action
Definition: game.hpp:217
input::action move_fast_action
Definition: game.hpp:222
input::action camera_zoom_in_action
Definition: game.hpp:231
input::action menu_right_action
Definition: game.hpp:208
input::action ant_move_left_action
Definition: game.hpp:253
input::action_map movement_action_map
Definition: game.hpp:213
input::action camera_mouse_zoom_action
Definition: game.hpp:230
input::action_map debug_action_map
Definition: game.hpp:260
input::action camera_zoom_out_action
Definition: game.hpp:232
Maps input to a set of contextually-related actions.
Definition: action-map.hpp:43
void disable()
Disables the mapping of input events to actions.
Definition: action-map.cpp:41
void remove_mappings(action &action, mapping_type type)
Unmaps input from an action.
Definition: action-map.cpp:157
void enable()
Enables the mapping of input events to actions.
Definition: action-map.cpp:28
Evaluates an activation state given input values and publishes events on activation state changes.
Definition: action.hpp:33
void reset() noexcept
Resets the activation state of the action without publishing any events.
Definition: action.cpp:75
::event::channel< action_activated_event > & get_activated_channel() noexcept
Returns the channel through which action activated events are published.
Definition: action.hpp:91
void update_control_profile(::game &ctx, ::control_profile &profile)
Updates a control profile after actions have been remapped.
Definition: controls.cpp:273
void apply_control_profile(::game &ctx, const ::control_profile &profile)
Applies a control profile to the game context.
Definition: controls.cpp:193
void setup_game_controls(::game &ctx)
Definition: controls.cpp:376
void reset_control_profile(::control_profile &profile)
Resets a control profile to default settings.
Definition: controls.cpp:31
void enable_game_controls(::game &ctx)
Definition: controls.cpp:412
void disable_game_controls(::game &ctx)
Definition: controls.cpp:417
Publish-subscribe messaging.
Definition: channel.hpp:32
@ alt
One or both alt modifier keys are pressed.
@ dpad_down
D-pad down button.
@ dpad_up
D-pad up button.
@ back
Back button.
@ dpad_left
D-pad left button.
@ dpad_right
D-pad right button.
@ start
Start button.
@ middle
Middle mouse button.
@ right
Right mouse button.
@ left
Left mouse button.
@ left_trigger
Left trigger.
@ right_trigger
Right trigger.
@ right_stick_y
Right stick Y-axis.
@ left_stick_y
Left stick Y-axis.
@ left_stick_x
Left stick X-axis.
@ right_stick_x
Right stick X-axis.
constexpr T map(T x, T from_min, T from_max, T to_min, T to_max) noexcept
Remaps a number from one range to another.
Definition: map.hpp:37
dict< hash::fnv1a32_t > settings
Profile-specific settings.
std::multimap< hash::fnv1a32_t, std::unique_ptr< input::mapping > > mappings
Input mappings.
32-bit FNV-1a hash value.
Definition: fnv1a.hpp:117