Commit 9f7a5e89 authored by Benjamin 'Albsi' Albsmeier's avatar Benjamin 'Albsi' Albsmeier
Browse files

input methodes now renamed to snake case

parent 1af81e5d
......@@ -29,7 +29,7 @@ beam_inverse_mouse_button : right
beam_inverse_controller_axis : righttrigger
place_item_key1 : Space
place_item_mouse_button : Middle
place_item_controller_button : A
place_item_controller_button : a
test_key1 : t
test_key2 : p
test_mouse_button : middle
......
......@@ -34,8 +34,8 @@ namespace gdw{
engine &engine_;
glm::vec2 pos_;
int windowWidth_ = 800;
int windowHeight_ = 600;
int window_width_ = 800;
int window_height_ = 600;
public:
input(engine& engine);
~input();
......@@ -76,37 +76,37 @@ namespace gdw{
* controller axis: <name>_controller_axis : <axis> + '_positiv' or '_negativ' (ignored if trigger)
* example: test_controller_axis : leftx_positiv
*/
void addMapping(std::string name);
void add_mapping(std::string name);
/**prints the mapping*/
void printMapping();
void print_mapping();
/**Returns true every frame, as long as it is down
* controller_id only for multi controller
*/
bool isPressed(std::string mapping, int controller_id = -1);
bool pressed(std::string mapping, int controller_id = -1);
/**Returns true once it is pressed
* controller_id only for multi controller
*/
bool isDown(std::string mapping, int controller_id = -1);
bool down(std::string mapping, int controller_id = -1);
/**Returns true once it is released
* controller_id only for multi controller
*/
bool isReleased(std::string mapping, int controller_id = -1);
bool released(std::string mapping, int controller_id = -1);
/**returns x position of the mouse cursor or of the controller cross-hair*/
int positionX();
int position_x();
/**returns y position of the mouse cursor or of the controller cross-hair*/
int positionY();
int position_y();
/**x motion of the mouse wheel*/
int mouseWheelX();
int mouse_wheel_x();
/**y motion of the mouse wheel*/
int mouseWheelY();
int mouse_wheel_y();
std::shared_ptr<gdw::keyboard> keyboard() noexcept {return keyboard_;};
std::shared_ptr<gdw::controller> controller(int id = -1);
......
......@@ -43,13 +43,13 @@ namespace gdw {
}
void AudioEventHandler::playStateUpdate(float) {
if ((this->engine.input().isPressed("move_left") || this->engine.input().isPressed("move_right")) && !this->playerMoving) {
if ((this->engine.input().pressed("move_left") || this->engine.input().pressed("move_right")) && !this->playerMoving) {
this->channels["ship"] = this->engine.audio().queue_sound("engine", -1);
this->engine.audio().sound_volume(40, this->channels["ship"]);
this->playerMoving = true;
}
if (!this->engine.input().isDown("move_left") && !this->engine.input().isDown("move_right") && this->playerMoving) {
if (!this->engine.input().down("move_left") && !this->engine.input().down("move_right") && this->playerMoving) {
this->engine.audio().stop_sound(this->channels["ship"], 800);
this->playerMoving = false;
......
......@@ -48,7 +48,7 @@ namespace gdw {
ui_system_ = make_unique<gdw::ui_system>(*this);
game_state_machine_ = make_unique<gdw::game_state_machine>(*this);
input_->addMapping("state_switch");
input_->add_mapping("state_switch");
}
engine::~engine() noexcept {
......
......@@ -48,14 +48,14 @@ namespace gdw {
}
void credits_state::update(float dt) {
if (this->engine_.input().isPressed("state_switch"))
if (this->engine_.input().pressed("state_switch"))
this->engine_.game_state_machine().change_state<menu_state>();
if (this->rootElement->y_px() <= (this->rootElement->height_px() + this->engine_.graphics_system().height()) * -1) {
this->rootElement->y(this->uiManager->getElementById("credits")->height());
this->topMargin = 0.5f/100*5;
}
double scrollAmount = this->engine_.input().isDown("beam_normal") ? 0.005 : 0.001;
scrollAmount = this->engine_.input().isDown("beam_inverse") ? 0.010 : scrollAmount;
double scrollAmount = this->engine_.input().down("beam_normal") ? 0.005 : 0.001;
scrollAmount = this->engine_.input().down("beam_inverse") ? 0.010 : scrollAmount;
this->rootElement->y(this->rootElement->y() - scrollAmount);
}
......
......@@ -71,7 +71,7 @@ void play_state::update(float dt) {
engine_.game_play_system().update(dt);
this->engine_.audioEventHandler().playStateUpdate(dt);
if (this->engine_.input().isPressed("state_switch"))
if (this->engine_.input().pressed("state_switch"))
this->engine_.game_state_machine().change_state<menu_state>();
}
......
......@@ -28,12 +28,12 @@ namespace gdw {
game_input_manager::game_input_manager(engine& engine):engine_(engine) {
auto& input = engine_.input();
input.addMapping("test");
input.addMapping("move_left");
input.addMapping("move_right");
input.addMapping("place_item");
input.addMapping("beam_normal");
input.addMapping("beam_inverse");
input.add_mapping("test");
input.add_mapping("move_left");
input.add_mapping("move_right");
input.add_mapping("place_item");
input.add_mapping("beam_normal");
input.add_mapping("beam_inverse");
}
game_input_manager::~game_input_manager() {
......@@ -49,8 +49,8 @@ namespace gdw {
auto& input = engine_.input();
auto& level_manager = engine_.game_play_system().level_manager();
float x = (float(input.positionX())/engine_.graphics_system().width()) * 2.0f -1;
float y = (float(input.positionY())/engine_.graphics_system().height()) * 2.0f -1;
float x = (float(input.position_x())/engine_.graphics_system().width()) * 2.0f -1;
float y = (float(input.position_y())/engine_.graphics_system().height()) * 2.0f -1;
auto cam = level_manager.camera()->component<camera_component>();
auto camera = level_manager.camera();
......@@ -82,21 +82,21 @@ namespace gdw {
constexpr float rotation_speed = 7.f;
constexpr float turn_rate_modifier = 4.5f;
if (input.isPressed("test")){
if (input.pressed("test")){
//log << "input test pressed" << std::endl;
input.printMapping();
input.print_mapping();
}
/*if (input.isDown("test")){
log << "pos: x:" << input.positionX() << " y:" << input.positionY() << std::endl;
/*if (input.down("test")){
log << "pos: x:" << input.position_x() << " y:" << input.position_y() << std::endl;
//log << "input test down" << std::endl;
}*/
/*if (input.isReleased("test")){
/*if (input.released("test")){
log << "input test released" << std::endl;
}*/
if (input.isDown("move_left") && player->position().x > -maximum_movement_distance) {
if (input.down("move_left") && player->position().x > -maximum_movement_distance) {
auto orientation = player->rotation()*glm::vec3(0,0,1);
auto diff = std::abs(orientation.x - (-1.f)) + std::abs(orientation.z - (0.f));
auto clamped = glm::clamp(diff/turn_rate_modifier, 0.f, 1.f);
......@@ -109,7 +109,7 @@ namespace gdw {
move->add_angular_force(glm::vec3(0.f, -rotation_speed*(std::pow(diff, 1.4f)) , 0.f));
}
if (engine_.input().isDown("move_right") && player->position().x < maximum_movement_distance) {
if (engine_.input().down("move_right") && player->position().x < maximum_movement_distance) {
auto orientation = player->rotation()*glm::vec3(0,0,1);
auto diff = std::abs(orientation.x - (1.f)) + std::abs(orientation.z - (0.f));
auto clamped = glm::clamp(diff/turn_rate_modifier, 0.f, 1.f);
......@@ -123,7 +123,7 @@ namespace gdw {
}
// SET ITEM WITH SPACE KEY
if (input.isDown("place_item")) {
if (input.down("place_item")) {
engine_.game_play_system().player_item_manager().place_item(get_world_mouse_pos());
}
}
......@@ -133,35 +133,35 @@ namespace gdw {
auto &level_manager = engine_.game_play_system().level_manager();
//MOUSEWHEEL
if(input.mouseWheelY() < 0.f) {
if(input.mouse_wheel_y() < 0.f) {
auto cam = engine_.game_play_system().level_manager().camera();
cam->position(cam->position()+glm::vec3(0,1.f,1.f));
level_manager.set_weapon(weapon_type::tractor_beam);
}
if(input.mouseWheelY() > 0.f) {
if(input.mouse_wheel_y() > 0.f) {
auto cam = engine_.game_play_system().level_manager().camera();
cam->position(cam->position()+glm::vec3(0,-1.f,-1.f));
level_manager.set_weapon(weapon_type::portal_gun);
}
if(input.isPressed("beam_normal")) {
if(input.pressed("beam_normal")) {
engine_.audioEventHandler().trigger(AudioEventHandler::TRAKTORBEAM_REVERSE_ACTIVATED);
}
if(input.isReleased("beam_normal")) {
if(input.released("beam_normal")) {
engine_.audioEventHandler().trigger(AudioEventHandler::TRAKTORBEAM_REVERSE_DEACTIVATED);
}
if(input.isPressed("beam_inverse")) {
if(input.pressed("beam_inverse")) {
engine_.audioEventHandler().trigger(AudioEventHandler::TRAKTORBEAM_ACTIVATED);
}
if(input.isReleased("beam_inverse")) {
if(input.released("beam_inverse")) {
engine_.audioEventHandler().trigger(AudioEventHandler::TRAKTORBEAM_DEACTIVATED);
}
//LEFT && RIGHT CLICK
switch(level_manager.weapon()) {
case weapon_type::tractor_beam: {
if(input.isDown("beam_normal") || input.isDown("beam_inverse")) {
if(input.down("beam_normal") || input.down("beam_inverse")) {
auto intersection_point = get_world_mouse_pos();
auto cannon = level_manager.cannon();
......@@ -174,7 +174,7 @@ namespace gdw {
ray r(cannon_pos + offset, intersection_point);
auto ray_unnormalized = glm::vec3(1.f);
if (input.isDown("beam_normal")) {
if (input.down("beam_normal")) {
ray_unnormalized = r.source - r.destination;
} else {
ray_unnormalized = r.destination - r.source;
......@@ -190,7 +190,7 @@ namespace gdw {
process_beam_collision(r, ray_unnormalized, beam_velocity, ray_length_, asteroid_hit, portal_type, remaining_length);
if (input.isDown("beam_normal")) {
if (input.down("beam_normal")) {
auto ray_length = (std::abs(ray_length_ - 0.f) < 0.001f)? glm::length(ray_unnormalized): ray_length_;
render_ray(&r, offset, ray_length, 0.18f, false, glm::vec3(0.5f, 0.6f, 0.9f));
} else {
......@@ -206,7 +206,7 @@ namespace gdw {
portal_type = -1;
ray_length_ = remaining_length;
process_beam_collision(r2, ray_unnormalized, beam_velocity, ray_length_, asteroid_hit, portal_type, remaining_length);
if (input.isDown("beam_normal")) {
if (input.down("beam_normal")) {
render_ray(&r2, offset, remaining_length, 0.18f, false, glm::vec3(0,0,1));
} else {
render_ray(&r2, offset, remaining_length, 0.18f, true, glm::vec3(1,0,0));
......@@ -221,7 +221,7 @@ namespace gdw {
portal_type = -1;
ray_length_ = remaining_length;
process_beam_collision(r2, ray_unnormalized, beam_velocity, ray_length_, asteroid_hit, portal_type, remaining_length);
if (input.isDown("beam_normal")) {
if (input.down("beam_normal")) {
render_ray(&r2, offset, remaining_length, 0.18f, false, glm::vec3(0,0,1));
} else {
render_ray(&r2, offset, remaining_length, 0.18f, true, glm::vec3(1,0,0));
......@@ -236,13 +236,13 @@ namespace gdw {
break;
}
case weapon_type::portal_gun: {
if(input.isDown("beam_normal") || input.isDown("beam_inverse")) {
if(input.down("beam_normal") || input.down("beam_inverse")) {
auto intersection_point = get_world_mouse_pos();
if(input.isDown("beam_normal"))
if(input.down("beam_normal"))
level_manager.create_blue_portal(intersection_point);
if(input.isDown("beam_inverse"))
if(input.down("beam_inverse"))
level_manager.create_yellow_portal(intersection_point);
}
break;
......
......@@ -22,8 +22,8 @@ namespace gdw{
mapping_ = std::make_shared<gdw::input_mapping>(this, engine_);
controller_manager_ = std::make_shared<gdw::controller_manager>(this, engine_);
windowWidth_ = engine_.getConfig().get<int>("width",800);
windowHeight_ = engine_.getConfig().get<int>("height",600);
window_width_ = engine_.getConfig().get<int>("width",800);
window_height_ = engine_.getConfig().get<int>("height",600);
}
input::~input(){}
......@@ -45,16 +45,16 @@ namespace gdw{
}
//MAPPING
void input::addMapping(std::string name){
void input::add_mapping(std::string name){
mapping_->add(name);
}
void input::printMapping(){
void input::print_mapping(){
mapping_->print();
}
//RETURN
bool input::isPressed(std::string id, int controller_id){
bool input::pressed(std::string id, int controller_id){
if(!mapping_->is_mapping(id))return false;
if(keyboard_->pressed(mapping_->key_1(id))){
return true;
......@@ -74,7 +74,7 @@ namespace gdw{
return false;
}
bool input::isDown(std::string id, int controller_id){
bool input::down(std::string id, int controller_id){
if(!mapping_->is_mapping(id))return false;
if(keyboard_->down(mapping_->key_1(id))){
return true;
......@@ -94,7 +94,7 @@ namespace gdw{
return false;
}
bool input::isReleased(std::string id, int controller_id){
bool input::released(std::string id, int controller_id){
if(!mapping_->is_mapping(id))return false;
if(keyboard_->released(mapping_->key_1(id))){
return true;
......@@ -114,19 +114,19 @@ namespace gdw{
return false;
}
int input::positionX(){
int input::position_x(){
return pos_.x;
}
int input::positionY(){
int input::position_y(){
return pos_.y;
}
int input::mouseWheelX(){
int input::mouse_wheel_x(){
return mouse_->wheel_x();
}
int input::mouseWheelY(){
int input::mouse_wheel_y(){
return mouse_->wheel_y();
}
......
......@@ -44,7 +44,7 @@ namespace gdw {
width(engine_.graphics_system().width());
height(engine_.graphics_system().height());
engine_.input().addMapping("button_click");
engine_.input().add_mapping("button_click");
}
ui_system::~ui_system(){
......@@ -56,8 +56,8 @@ namespace gdw {
//engine_.graphics_system().height()
//glClearStencil( 0 );
//nvgluBindFramebuffer( NVGFrameBuffer_ );
float mousex = engine_.input().positionX();
float mousey = engine_.input().positionY();
float mousex = engine_.input().position_x();
float mousey = engine_.input().position_y();
for(auto& widget : child_widgets_) {
handleInput(mousex,mousey,widget.get());
......@@ -113,10 +113,10 @@ namespace gdw {
if(x > 0 && y > 0 && x < widget->width_px() && y < widget->height_px()){
widget->on_hover(x,y);
if(engine_.input().isPressed("button_click")){
if(engine_.input().pressed("button_click")){
widget->on_pressed(x,y);
}
if(engine_.input().isReleased("button_click")){
if(engine_.input().released("button_click")){
widget->on_released(x,y);
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment