Antkeeper  0.0.1
debug-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"
22 #include "game/world.hpp"
23 
25 {
26  // Toggle debug UI
27  ctx.event_subscriptions.emplace_back
28  (
30  (
31  [&](const auto& event)
32  {
33  ctx.debug_ui_visible = !ctx.debug_ui_visible;
34  if (ctx.debug_ui_visible)
35  {
36  ctx.ui_scene->add_object(*ctx.frame_time_text);
37  }
38  else
39  {
40  ctx.ui_scene->remove_object(*ctx.frame_time_text);
41  }
42  }
43  )
44  );
45 
46  ctx.event_subscriptions.emplace_back
47  (
48  ctx.input_manager->get_event_dispatcher().subscribe<input::mouse_moved_event>
49  (
50  [&](const auto& event)
51  {
52  if (ctx.adjust_time_action.is_active())
53  {
54  const double sensitivity = 1.0 / static_cast<double>(ctx.window->get_viewport_size().x());
55  const double t = ctx.astronomy_system->get_time();
56  ::world::set_time(ctx, t + static_cast<double>(event.difference.x()) * sensitivity);
57  }
58 
59  if (ctx.adjust_exposure_action.is_active())
60  {
61  scene::camera* camera{};
62  if (ctx.active_scene == ctx.surface_scene.get())
63  {
64  camera = ctx.surface_camera.get();
65  }
66  else if (ctx.active_scene == ctx.underground_scene.get())
67  {
68  camera = ctx.underground_camera.get();
69  }
70 
71  if (camera)
72  {
73  const float sensitivity = 8.0f / static_cast<float>(ctx.window->get_viewport_size().y());
74  ctx.surface_camera->set_exposure_value(ctx.surface_camera->get_exposure_value() + static_cast<float>(event.difference.y()) * sensitivity);
75  }
76  }
77  }
78  )
79  );
80 }
81 
83 {
85 }
86 
88 {
93 }
Definition: game.hpp:121
input::action toggle_debug_ui_action
Definition: game.hpp:261
input::action adjust_exposure_action
Definition: game.hpp:262
std::vector< std::shared_ptr<::event::subscription > > event_subscriptions
Definition: game.hpp:265
input::action adjust_time_action
Definition: game.hpp:263
input::action_map debug_action_map
Definition: game.hpp:260
void disable()
Disables the mapping of input events to actions.
Definition: action-map.cpp:41
void enable()
Enables the mapping of input events to actions.
Definition: action-map.cpp:28
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 enable_debug_controls(::game &ctx)
void setup_debug_controls(::game &ctx)
void disable_debug_controls(::game &ctx)
Publish-subscribe messaging.
Definition: channel.hpp:32
Event generated when a mouse has been moved.