Skip to content

Commit

Permalink
input: Rename engine controller to game controller.
Browse files Browse the repository at this point in the history
  • Loading branch information
heinezen committed Nov 20, 2023
1 parent 96cf0a2 commit eaf1830
Show file tree
Hide file tree
Showing 10 changed files with 34 additions and 30 deletions.
2 changes: 1 addition & 1 deletion libopenage/input/action.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ enum class input_action_t {
PUSH_CONTEXT,
POP_CONTEXT,
REMOVE_CONTEXT,
ENGINE,
GAME,
CAMERA,
GUI,
CUSTOM,
Expand Down
2 changes: 1 addition & 1 deletion libopenage/input/controller/game/binding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@

namespace openage::input::game {

} // namespace openage::input::engine
} // namespace openage::input::game
2 changes: 1 addition & 1 deletion libopenage/input/controller/game/binding_context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,4 @@ const binding_action &BindingContext::lookup(const Event &ev) const {
throw Error{MSG(err) << "Event is not bound in binding_action context."};
}

} // namespace openage::input::engine
} // namespace openage::input::game
2 changes: 1 addition & 1 deletion libopenage/input/controller/game/binding_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,4 @@ class BindingContext {
std::unordered_map<event_class, binding_action, event_class_hash> by_class;
};

} // namespace openage::input::engine
} // namespace openage::input::game
3 changes: 2 additions & 1 deletion libopenage/input/controller/game/controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,8 @@ class Controller : public std::enable_shared_from_this<Controller> {
/**
* Setup default controller action bindings:
*
* - Mouse click: Create game entity.
* - CTRL + Left Mouse click: Create game entity.
* - Right Mouse click: Move game entity.
*
* @param ctx Binding context the actions are added to.
* @param time_loop Time loop for getting simulation time.
Expand Down
8 changes: 4 additions & 4 deletions libopenage/input/input_context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,16 @@ const std::string &InputContext::get_id() {
return this->id;
}

void InputContext::set_engine_bindings(const std::shared_ptr<game::BindingContext> &bindings) {
this->engine_bindings = bindings;
void InputContext::set_game_bindings(const std::shared_ptr<game::BindingContext> &bindings) {
this->game_bindings = bindings;
}

void InputContext::set_camera_bindings(const std::shared_ptr<camera::BindingContext> &bindings) {
this->camera_bindings = bindings;
}

const std::shared_ptr<game::BindingContext> &InputContext::get_engine_bindings() {
return this->engine_bindings;
const std::shared_ptr<game::BindingContext> &InputContext::get_game_bindings() {
return this->game_bindings;
}

const std::shared_ptr<camera::BindingContext> &InputContext::get_camera_bindings() {
Expand Down
8 changes: 4 additions & 4 deletions libopenage/input/input_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class InputContext {
*
* @param bindings Binding context for gamestate events.
*/
void set_engine_bindings(const std::shared_ptr<game::BindingContext> &bindings);
void set_game_bindings(const std::shared_ptr<game::BindingContext> &bindings);

/**
* Set the associated context for binding input events to camera actions.
Expand All @@ -61,7 +61,7 @@ class InputContext {
*
* @return Binding context of the input context.
*/
const std::shared_ptr<game::BindingContext> &get_engine_bindings();
const std::shared_ptr<game::BindingContext> &get_game_bindings();

/**
* Get the associated context for binding input events to camera actions.
Expand Down Expand Up @@ -138,9 +138,9 @@ class InputContext {
std::unordered_map<event_class, input_action, event_class_hash> by_class;

/**
* Additional context for engine events.
* Additional context for game simulation events.
*/
std::shared_ptr<game::BindingContext> engine_bindings;
std::shared_ptr<game::BindingContext> game_bindings;

/**
* Additional context for camera actions.
Expand Down
21 changes: 12 additions & 9 deletions libopenage/input/input_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ InputManager::InputManager() :
global_context{std::make_shared<InputContext>("main")},
active_contexts{},
available_contexts{},
engine_controller{nullptr},
game_controller{nullptr},
camera_controller{nullptr},
gui_input{nullptr} {
}
Expand All @@ -27,8 +27,8 @@ void InputManager::set_camera_controller(const std::shared_ptr<camera::Controlle
this->camera_controller = controller;
}

void InputManager::set_engine_controller(const std::shared_ptr<game::Controller> controller) {
this->engine_controller = controller;
void InputManager::set_game_controller(const std::shared_ptr<game::Controller> controller) {
this->game_controller = controller;
}

const std::shared_ptr<InputContext> &InputManager::get_global_context() {
Expand Down Expand Up @@ -173,8 +173,8 @@ void InputManager::process_action(const input::Event &ev,
this->pop_context(ctx_id);
break;
}
case input_action_t::ENGINE:
this->engine_controller->process(args, ctx->get_engine_bindings());
case input_action_t::GAME:
this->game_controller->process(args, ctx->get_game_bindings());
break;

case input_action_t::CAMERA:
Expand Down Expand Up @@ -214,14 +214,17 @@ void setup_defaults(const std::shared_ptr<InputContext> &ctx) {
ctx->bind(ev_wheel_down, camera_action);
ctx->bind(event_class::MOUSE_MOVE, camera_action);

// engine
input_action engine_action{input_action_t::ENGINE};
// game
input_action game_action{input_action_t::GAME};

Event ev_mouse_lmb{event_class::MOUSE_BUTTON, Qt::LeftButton, Qt::NoModifier, QEvent::MouseButtonRelease};
Event ev_mouse_rmb{event_class::MOUSE_BUTTON, Qt::RightButton, Qt::NoModifier, QEvent::MouseButtonRelease};

ctx->bind(ev_mouse_lmb, engine_action);
ctx->bind(ev_mouse_rmb, engine_action);
ctx->bind(ev_mouse_lmb, game_action);
ctx->bind(ev_mouse_rmb, game_action);

// also forward all other mouse button events
ctx->bind(event_class::MOUSE_BUTTON, game_action);
}


Expand Down
10 changes: 5 additions & 5 deletions libopenage/input/input_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,11 @@ class InputManager {
void set_camera_controller(const std::shared_ptr<camera::Controller> controller);

/**
* Set the controller for the engine.
* Set the controller for the game simulation.
*
* @param controller Engine controller.
* @param controller Game controller.
*/
void set_engine_controller(const std::shared_ptr<game::Controller> controller);
void set_game_controller(const std::shared_ptr<game::Controller> controller);

/**
* returns the global keybind context.
Expand Down Expand Up @@ -170,9 +170,9 @@ class InputManager {
std::unordered_map<std::string, std::shared_ptr<InputContext>> available_contexts;

/**
* Interface to the engine.
* Interface to the game simulation.
*/
std::shared_ptr<game::Controller> engine_controller;
std::shared_ptr<game::Controller> game_controller;

/**
* Interface to the camera.
Expand Down
6 changes: 3 additions & 3 deletions libopenage/presenter/presenter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -215,12 +215,12 @@ void Presenter::init_input() {
log::log(INFO << "Loading game simulation controls");

// TODO: Remove hardcoding
auto engine_controller = std::make_shared<input::game::Controller>(
auto game_controller = std::make_shared<input::game::Controller>(
std::unordered_set<size_t>{0, 1, 2, 3}, 0);
auto engine_context = std::make_shared<input::game::BindingContext>();
input::game::setup_defaults(engine_context, this->time_loop, this->simulation, this->camera);
this->input_manager->set_engine_controller(engine_controller);
input_ctx->set_engine_bindings(engine_context);
this->input_manager->set_game_controller(game_controller);
input_ctx->set_game_bindings(engine_context);
}

// attach GUI if it's initialized
Expand Down

0 comments on commit eaf1830

Please sign in to comment.