# HG changeset patch # User Tero Marttila # Date 1232576906 -7200 # Node ID 38cba347a3a959c59ae8848d458f0f497b111d7b # Parent c1069d23890ba17730c701986074e79d271344c5 clean up InputHandler/GameView to use signals for input diff -r c1069d23890b -r 38cba347a3a9 src/Graphics/GameView.cc --- a/src/Graphics/GameView.cc Thu Jan 22 00:13:53 2009 +0200 +++ b/src/Graphics/GameView.cc Thu Jan 22 00:28:26 2009 +0200 @@ -20,6 +20,7 @@ message_view.add_message(CL_Color::white, "Hello World!"); // enable GUI input + slots.connect(graphics->input.gui.sig_input(), this, &GameView::handleInput); graphics->input.gui.enable(); } @@ -33,6 +34,7 @@ info_view = new PlayerInfoView(getInfoViewArea(), player); // enable player input + slots.connect(graphics->input.player.sig_input(), player, &LocalPlayer::handleInput); graphics->input.player.enable(); } @@ -82,19 +84,6 @@ void GameView::draw (Display &display) { CL_GraphicContext *gc = display.get_gc(); - // XXX: these should not be done from here - handleInput(graphics->input.readGuiInput(), 0); - - // XXX: this should /really/ be somewhere else - if (player) { - PlayerInput input; - TimeMS dt; - - graphics->input.readPlayerInput(input, dt); - - player->handleInput(input, dt); - } - // calculate camera PixelCoordinate camera(0, 0); diff -r c1069d23890b -r 38cba347a3a9 src/Graphics/GameView.hh --- a/src/Graphics/GameView.hh Thu Jan 22 00:13:53 2009 +0200 +++ b/src/Graphics/GameView.hh Thu Jan 22 00:28:26 2009 +0200 @@ -39,6 +39,8 @@ */ GuiInput flags; + CL_SlotContainer slots; + public: /** * Constructed once the game is running diff -r c1069d23890b -r 38cba347a3a9 src/Graphics/Input.cc --- a/src/Graphics/Input.cc Thu Jan 22 00:13:53 2009 +0200 +++ b/src/Graphics/Input.cc Thu Jan 22 00:28:26 2009 +0200 @@ -151,7 +151,7 @@ return; // all bits that are held down, even those ignored - BitMaskType raw_value = 0; + BitMaskType raw_value = 0, this_value = 0; // update the key-repeat queue queue.update(dt); @@ -187,15 +187,23 @@ } } - // set bit in masks - this->value |= e->input; + // set bit in value mask + this_value |= e->input; } } + // signal unless value was and remains zero + if (this_value || prev_value) { + // trigger signal + _sig_input(this_value, dt); + } + // update prev_value, also adding ignored values prev_value = raw_value; - // then increment our dt + // update our collective value + dt for use with readValue + // XXX: remove this functionality? + value |= this_value; this->dt += dt; } diff -r c1069d23890b -r 38cba347a3a9 src/Graphics/Input.hh --- a/src/Graphics/Input.hh Thu Jan 22 00:13:53 2009 +0200 +++ b/src/Graphics/Input.hh Thu Jan 22 00:28:26 2009 +0200 @@ -5,6 +5,7 @@ #include "../Timer.hh" #include "../Types.hh" +#include #include #include @@ -198,6 +199,11 @@ * Are we enabled or not? */ bool _enabled; + + /** + * The keyevent signal + */ + CL_Signal_v2 _sig_input; public: /** @@ -249,6 +255,11 @@ * Current enable/disable state */ bool enabled (void) const { return _enabled; } + + /** + * This signal is triggered whenever there is nonzero input, or when the input goes to zero + */ + CL_Signal_v2& sig_input (void) { return _sig_input; } }; /** @@ -301,7 +312,6 @@ - /* * Public template class method definitions */