Better handling of joysticks for the menus and an unused network fsm

This commit is contained in:
simon.kagstrom 2010-03-06 07:25:12 +00:00
parent 968d5caef7
commit c326c552e1
5 changed files with 106 additions and 19 deletions

View File

@ -161,9 +161,9 @@ private:
void c64_dtor(void); void c64_dtor(void);
void open_close_joysticks(int oldjoy1, int oldjoy2, int newjoy1, int newjoy2); void open_close_joysticks(int oldjoy1, int oldjoy2, int newjoy1, int newjoy2);
uint8 poll_joystick(int port); uint8 poll_joystick(int port);
uint8 poll_joystick_axes(int port); uint8 poll_joystick_axes(int port, bool *has_event);
uint8 poll_joystick_hats(int port); uint8 poll_joystick_hats(int port, bool *has_event);
uint8 poll_joystick_buttons(int port); uint8 poll_joystick_buttons(int port, bool *has_event);
void thread_func(void); void thread_func(void);
bool thread_running; // Emulation thread is running bool thread_running; // Emulation thread is running

View File

@ -778,7 +778,7 @@ void C64::open_close_joysticks(int oldjoy1, int oldjoy2, int newjoy1, int newjoy
} }
/* The implementation principles are borrowed from UAE */ /* 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]; SDL_Joystick *js = joy[port];
unsigned int i, axes; unsigned int i, axes;
@ -823,18 +823,20 @@ uint8 C64::poll_joystick_axes(int port)
if (axis < (*min_axis + (*max_axis - *min_axis)/3)) { if (axis < (*min_axis + (*max_axis - *min_axis)/3)) {
out &= neg_val; 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)) { else if (axis > (*min_axis + 2*(*max_axis - *min_axis)/3)) {
out &= pos_val; out &= pos_val;
Gui::gui->pushEvent(gui_pos_val); Gui::gui->pushJoystickEvent(gui_pos_val);
*has_event = true;
} }
} }
return out; return out;
} }
uint8 C64::poll_joystick_hats(int port) uint8 C64::poll_joystick_hats(int port, bool *has_event)
{ {
SDL_Joystick *js = joy[port]; SDL_Joystick *js = joy[port];
unsigned int i, hats; unsigned int i, hats;
@ -865,28 +867,32 @@ uint8 C64::poll_joystick_hats(int port)
right_ev = KEY_DOWN; 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) { if (v & SDL_HAT_UP) {
out &= up_mask; out &= up_mask;
Gui::gui->pushEvent(up_ev); Gui::gui->pushJoystickEvent(up_ev);
} }
if (v & SDL_HAT_DOWN) { if (v & SDL_HAT_DOWN) {
out &= down_mask; out &= down_mask;
Gui::gui->pushEvent(down_ev); Gui::gui->pushJoystickEvent(down_ev);
} }
if (v & SDL_HAT_LEFT) { if (v & SDL_HAT_LEFT) {
out &= left_mask; out &= left_mask;
Gui::gui->pushEvent(left_ev); Gui::gui->pushJoystickEvent(left_ev);
} }
if (v & SDL_HAT_RIGHT) { if (v & SDL_HAT_RIGHT) {
out &= right_mask; out &= right_mask;
Gui::gui->pushEvent(right_ev); Gui::gui->pushJoystickEvent(right_ev);
} }
} }
return out; return out;
} }
uint8 C64::poll_joystick_buttons(int port) uint8 C64::poll_joystick_buttons(int port, bool *has_event)
{ {
SDL_Joystick *js = joy[port]; SDL_Joystick *js = joy[port];
uint8 out = 0xff; uint8 out = 0xff;
@ -898,8 +904,11 @@ uint8 C64::poll_joystick_buttons(int port)
event_t ev = (event_t)ThePrefs.MenuJoystickButtons[i]; event_t ev = (event_t)ThePrefs.MenuJoystickButtons[i];
this->joy_button_pressed[i] = cur; this->joy_button_pressed[i] = cur;
if (cur) if (cur && ev != EVENT_NONE)
Gui::gui->pushEvent(ev); {
Gui::gui->pushJoystickEvent(ev);
*has_event = true;
}
if (kc == JOY_NONE) if (kc == JOY_NONE)
continue; continue;
@ -916,6 +925,7 @@ uint8 C64::poll_joystick_buttons(int port)
*/ */
uint8 C64::poll_joystick(int port) uint8 C64::poll_joystick(int port)
{ {
bool has_event = false;
uint8 out = 0xff; uint8 out = 0xff;
if (port == 0 && (joy[0] || joy[1])) if (port == 0 && (joy[0] || joy[1]))
@ -924,9 +934,12 @@ uint8 C64::poll_joystick(int port)
if (!joy[port]) if (!joy[port])
return out; return out;
out &= this->poll_joystick_axes(port); out &= this->poll_joystick_axes(port, &has_event);
out &= this->poll_joystick_hats(port); out &= this->poll_joystick_hats(port, &has_event);
out &= this->poll_joystick_buttons(port); out &= this->poll_joystick_buttons(port, &has_event);
if (!has_event)
Gui::gui->pushJoystickEvent(EVENT_NONE);
return out; return out;
} }

View File

@ -50,6 +50,66 @@
#define RLE_SIZE ( RAW_SIZE * 4 + 8) #define RLE_SIZE ( RAW_SIZE * 4 + 8)
#define DIFF_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) Network::Network(const char *remote_host, int port)
{ {
const size_t size = NETWORK_UPDATE_SIZE; const size_t size = NETWORK_UPDATE_SIZE;

View File

@ -362,17 +362,29 @@ void Gui::exitMenu()
this->saveGameInfo(this->metadata_base_path, this->cur_gameInfo->filename); 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; static Uint32 last_ticks;
Uint32 cur_ticks; Uint32 cur_ticks;
if (last == ev)
return;
cur_ticks = SDL_GetTicks(); cur_ticks = SDL_GetTicks();
if (cur_ticks - last_ticks < 150) if (cur_ticks - last_ticks < 150)
return; return;
last_ticks = cur_ticks; 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) if (ev == KEY_ENTER_MENU)
{ {
this->activate(); this->activate();

View File

@ -44,6 +44,8 @@ public:
void runLogic(void); void runLogic(void);
void pushJoystickEvent(event_t ev);
void pushEvent(event_t ev); void pushEvent(event_t ev);
void pushEvent(SDL_Event *ev); void pushEvent(SDL_Event *ev);