From c326c552e12586cf4c479b8d1e6dac905772397a Mon Sep 17 00:00:00 2001 From: "simon.kagstrom" Date: Sat, 6 Mar 2010 07:25:12 +0000 Subject: [PATCH] Better handling of joysticks for the menus and an unused network fsm --- Src/C64.h | 6 ++--- Src/Display.cpp | 41 +++++++++++++++++++++------------ Src/Network.cpp | 60 +++++++++++++++++++++++++++++++++++++++++++++++++ Src/gui/gui.cpp | 16 +++++++++++-- Src/gui/gui.hh | 2 ++ 5 files changed, 106 insertions(+), 19 deletions(-) diff --git a/Src/C64.h b/Src/C64.h index 55b2826..7ba15c0 100644 --- a/Src/C64.h +++ b/Src/C64.h @@ -161,9 +161,9 @@ private: void c64_dtor(void); void open_close_joysticks(int oldjoy1, int oldjoy2, int newjoy1, int newjoy2); uint8 poll_joystick(int port); - uint8 poll_joystick_axes(int port); - uint8 poll_joystick_hats(int port); - uint8 poll_joystick_buttons(int port); + uint8 poll_joystick_axes(int port, bool *has_event); + uint8 poll_joystick_hats(int port, bool *has_event); + uint8 poll_joystick_buttons(int port, bool *has_event); void thread_func(void); bool thread_running; // Emulation thread is running diff --git a/Src/Display.cpp b/Src/Display.cpp index 8561149..e9ba850 100644 --- a/Src/Display.cpp +++ b/Src/Display.cpp @@ -778,7 +778,7 @@ void C64::open_close_joysticks(int oldjoy1, int oldjoy2, int newjoy1, int newjoy } /* The implementation principles are borrowed from UAE */ -uint8 C64::poll_joystick_axes(int port) +uint8 C64::poll_joystick_axes(int port, bool *has_event) { SDL_Joystick *js = joy[port]; unsigned int i, axes; @@ -823,18 +823,20 @@ uint8 C64::poll_joystick_axes(int port) if (axis < (*min_axis + (*max_axis - *min_axis)/3)) { out &= neg_val; - Gui::gui->pushEvent(gui_neg_val); + Gui::gui->pushJoystickEvent(gui_neg_val); + *has_event = true; } else if (axis > (*min_axis + 2*(*max_axis - *min_axis)/3)) { out &= pos_val; - Gui::gui->pushEvent(gui_pos_val); + Gui::gui->pushJoystickEvent(gui_pos_val); + *has_event = true; } } return out; } -uint8 C64::poll_joystick_hats(int port) +uint8 C64::poll_joystick_hats(int port, bool *has_event) { SDL_Joystick *js = joy[port]; unsigned int i, hats; @@ -865,28 +867,32 @@ uint8 C64::poll_joystick_hats(int port) right_ev = KEY_DOWN; } + if ((v & (SDL_HAT_UP | SDL_HAT_DOWN | SDL_HAT_LEFT | SDL_HAT_RIGHT)) == 0) + continue; + *has_event = true; + if (v & SDL_HAT_UP) { out &= up_mask; - Gui::gui->pushEvent(up_ev); + Gui::gui->pushJoystickEvent(up_ev); } if (v & SDL_HAT_DOWN) { out &= down_mask; - Gui::gui->pushEvent(down_ev); + Gui::gui->pushJoystickEvent(down_ev); } if (v & SDL_HAT_LEFT) { out &= left_mask; - Gui::gui->pushEvent(left_ev); + Gui::gui->pushJoystickEvent(left_ev); } if (v & SDL_HAT_RIGHT) { out &= right_mask; - Gui::gui->pushEvent(right_ev); + Gui::gui->pushJoystickEvent(right_ev); } } return out; } -uint8 C64::poll_joystick_buttons(int port) +uint8 C64::poll_joystick_buttons(int port, bool *has_event) { SDL_Joystick *js = joy[port]; uint8 out = 0xff; @@ -898,8 +904,11 @@ uint8 C64::poll_joystick_buttons(int port) event_t ev = (event_t)ThePrefs.MenuJoystickButtons[i]; this->joy_button_pressed[i] = cur; - if (cur) - Gui::gui->pushEvent(ev); + if (cur && ev != EVENT_NONE) + { + Gui::gui->pushJoystickEvent(ev); + *has_event = true; + } if (kc == JOY_NONE) continue; @@ -916,6 +925,7 @@ uint8 C64::poll_joystick_buttons(int port) */ uint8 C64::poll_joystick(int port) { + bool has_event = false; uint8 out = 0xff; if (port == 0 && (joy[0] || joy[1])) @@ -924,9 +934,12 @@ uint8 C64::poll_joystick(int port) if (!joy[port]) return out; - out &= this->poll_joystick_axes(port); - out &= this->poll_joystick_hats(port); - out &= this->poll_joystick_buttons(port); + out &= this->poll_joystick_axes(port, &has_event); + out &= this->poll_joystick_hats(port, &has_event); + out &= this->poll_joystick_buttons(port, &has_event); + + if (!has_event) + Gui::gui->pushJoystickEvent(EVENT_NONE); return out; } diff --git a/Src/Network.cpp b/Src/Network.cpp index ca7b386..2c89a23 100644 --- a/Src/Network.cpp +++ b/Src/Network.cpp @@ -50,6 +50,66 @@ #define RLE_SIZE ( RAW_SIZE * 4 + 8) #define DIFF_SIZE ( RAW_SIZE * 4 + 8) +#if 0 +class ConnectionFSM : public TimeoutHandler +{ +public: + ConnectionFSM() + { + this->rese(); + } + + void connectToPeer() + { + this->setState(CONNECT_TO_PEER); + } + + void peerConnected() + { + /* Reset the FSM */ + this->reset(); + } + + void connectToBroker() + { + this->setState(CONNECT_TO_BROKER); + + Gui::gui->timerController->arm(this, 4000); + } + + void timeoutCallback() + { + /* New state, everything is fine */ + if (this->last_state != this->state) + return; + + switch(state) + { + default: + break; + } + } + + void reset() + { + this->state = 0; + this->last_state = -1; + } + + static ConnectionFSM fsm; + +private: + + void setState(int state) + { + this->last_state = this->state; + this->state = state; + } + + int state, last_state; +}; +#endif + Network::Network(const char *remote_host, int port) { const size_t size = NETWORK_UPDATE_SIZE; diff --git a/Src/gui/gui.cpp b/Src/gui/gui.cpp index fb6cc80..ba49300 100644 --- a/Src/gui/gui.cpp +++ b/Src/gui/gui.cpp @@ -362,17 +362,29 @@ void Gui::exitMenu() this->saveGameInfo(this->metadata_base_path, this->cur_gameInfo->filename); } -void Gui::pushEvent(event_t ev) + +void Gui::pushJoystickEvent(event_t ev) { - GuiView *cur_view = this->peekView(); + static event_t last = EVENT_NONE; static Uint32 last_ticks; Uint32 cur_ticks; + if (last == ev) + return; + cur_ticks = SDL_GetTicks(); if (cur_ticks - last_ticks < 150) return; last_ticks = cur_ticks; + this->pushEvent(ev); + last = ev; +} + +void Gui::pushEvent(event_t ev) +{ + GuiView *cur_view = this->peekView(); + if (ev == KEY_ENTER_MENU) { this->activate(); diff --git a/Src/gui/gui.hh b/Src/gui/gui.hh index 84a8aca..f27b9d3 100644 --- a/Src/gui/gui.hh +++ b/Src/gui/gui.hh @@ -44,6 +44,8 @@ public: void runLogic(void); + void pushJoystickEvent(event_t ev); + void pushEvent(event_t ev); void pushEvent(SDL_Event *ev);