optimization - use a pointer for wpad data

This commit is contained in:
dborth 2009-10-13 00:41:01 +00:00
parent ad69f20371
commit 314c33eada
9 changed files with 66 additions and 49 deletions

View File

@ -36,9 +36,6 @@ void UpdatePads()
for(int i=3; i >= 0; i--) for(int i=3; i >= 0; i--)
{ {
memcpy(&userInput[i].wpad, WPAD_Data(i), sizeof(WPADData));
userInput[i].chan = i;
userInput[i].pad.btns_d = PAD_ButtonsDown(i); userInput[i].pad.btns_d = PAD_ButtonsDown(i);
userInput[i].pad.btns_u = PAD_ButtonsUp(i); userInput[i].pad.btns_u = PAD_ButtonsUp(i);
userInput[i].pad.btns_h = PAD_ButtonsHeld(i); userInput[i].pad.btns_h = PAD_ButtonsHeld(i);
@ -51,6 +48,20 @@ void UpdatePads()
} }
} }
/****************************************************************************
* SetupPads
*
* Sets up userInput triggers for use
***************************************************************************/
void SetupPads()
{
for(int i=0; i < 4; i++)
{
userInput[i].chan = i;
userInput[i].wpad = WPAD_Data(i);
}
}
/**************************************************************************** /****************************************************************************
* ShutoffRumble * ShutoffRumble
***************************************************************************/ ***************************************************************************/

View File

@ -20,6 +20,7 @@ extern int rumbleRequest[4];
void ShutoffRumble(); void ShutoffRumble();
void DoRumble(int i); void DoRumble(int i);
void SetupPads();
void UpdatePads(); void UpdatePads();
bool MenuRequested(); bool MenuRequested();

View File

@ -210,7 +210,8 @@ class GuiTrigger
u8 type; //!< trigger type (TRIGGER_SIMPLE, TRIGGER_HELD, TRIGGER_BUTTON_ONLY, TRIGGER_BUTTON_ONLY_IN_FOCUS) u8 type; //!< trigger type (TRIGGER_SIMPLE, TRIGGER_HELD, TRIGGER_BUTTON_ONLY, TRIGGER_BUTTON_ONLY_IN_FOCUS)
s32 chan; //!< Trigger controller channel (0-3, -1 for all) s32 chan; //!< Trigger controller channel (0-3, -1 for all)
WPADData wpad; //!< Wii controller trigger data WPADData * wpad; //!< Wii controller trigger
WPADData wpaddata; //!< Wii controller trigger data
PADData pad; //!< GameCube controller trigger data PADData pad; //!< GameCube controller trigger data
}; };

View File

@ -161,9 +161,9 @@ void GuiButton::Update(GuiTrigger * t)
#ifdef HW_RVL #ifdef HW_RVL
// cursor // cursor
if(t->wpad.ir.valid && t->chan >= 0) if(t->wpad->ir.valid && t->chan >= 0)
{ {
if(this->IsInside(t->wpad.ir.x, t->wpad.ir.y)) if(this->IsInside(t->wpad->ir.x, t->wpad->ir.y))
{ {
if(state == STATE_DEFAULT) // we weren't on the button before! if(state == STATE_DEFAULT) // we weren't on the button before!
{ {
@ -209,24 +209,24 @@ void GuiButton::Update(GuiTrigger * t)
if(trigger[i] && (trigger[i]->chan == -1 || trigger[i]->chan == t->chan)) if(trigger[i] && (trigger[i]->chan == -1 || trigger[i]->chan == t->chan))
{ {
// higher 16 bits only (wiimote) // higher 16 bits only (wiimote)
wm_btns = t->wpad.btns_d << 16; wm_btns = t->wpad->btns_d << 16;
wm_btns_trig = trigger[i]->wpad.btns_d << 16; wm_btns_trig = trigger[i]->wpad->btns_d << 16;
// lower 16 bits only (classic controller) // lower 16 bits only (classic controller)
cc_btns = t->wpad.btns_d >> 16; cc_btns = t->wpad->btns_d >> 16;
cc_btns_trig = trigger[i]->wpad.btns_d >> 16; cc_btns_trig = trigger[i]->wpad->btns_d >> 16;
if( if(
(t->wpad.btns_d > 0 && (t->wpad->btns_d > 0 &&
(wm_btns == wm_btns_trig || (wm_btns == wm_btns_trig ||
(cc_btns == cc_btns_trig && t->wpad.exp.type == EXP_CLASSIC))) || (cc_btns == cc_btns_trig && t->wpad->exp.type == EXP_CLASSIC))) ||
(t->pad.btns_d == trigger[i]->pad.btns_d && t->pad.btns_d > 0)) (t->pad.btns_d == trigger[i]->pad.btns_d && t->pad.btns_d > 0))
{ {
if(t->chan == stateChan || stateChan == -1) if(t->chan == stateChan || stateChan == -1)
{ {
if(state == STATE_SELECTED) if(state == STATE_SELECTED)
{ {
if(!t->wpad.ir.valid || this->IsInside(t->wpad.ir.x, t->wpad.ir.y)) if(!t->wpad->ir.valid || this->IsInside(t->wpad->ir.x, t->wpad->ir.y))
{ {
this->SetState(STATE_CLICKED, t->chan); this->SetState(STATE_CLICKED, t->chan);
@ -259,19 +259,19 @@ void GuiButton::Update(GuiTrigger * t)
if(trigger[i] && (trigger[i]->chan == -1 || trigger[i]->chan == t->chan)) if(trigger[i] && (trigger[i]->chan == -1 || trigger[i]->chan == t->chan))
{ {
// higher 16 bits only (wiimote) // higher 16 bits only (wiimote)
wm_btns = t->wpad.btns_d << 16; wm_btns = t->wpad->btns_d << 16;
wm_btns_h = t->wpad.btns_h << 16; wm_btns_h = t->wpad->btns_h << 16;
wm_btns_trig = trigger[i]->wpad.btns_h << 16; wm_btns_trig = trigger[i]->wpad->btns_h << 16;
// lower 16 bits only (classic controller) // lower 16 bits only (classic controller)
cc_btns = t->wpad.btns_d >> 16; cc_btns = t->wpad->btns_d >> 16;
cc_btns_h = t->wpad.btns_h >> 16; cc_btns_h = t->wpad->btns_h >> 16;
cc_btns_trig = trigger[i]->wpad.btns_h >> 16; cc_btns_trig = trigger[i]->wpad->btns_h >> 16;
if( if(
(t->wpad.btns_d > 0 && (t->wpad->btns_d > 0 &&
(wm_btns == wm_btns_trig || (wm_btns == wm_btns_trig ||
(cc_btns == cc_btns_trig && t->wpad.exp.type == EXP_CLASSIC))) || (cc_btns == cc_btns_trig && t->wpad->exp.type == EXP_CLASSIC))) ||
(t->pad.btns_d == trigger[i]->pad.btns_h && t->pad.btns_d > 0)) (t->pad.btns_d == trigger[i]->pad.btns_h && t->pad.btns_d > 0))
{ {
if(trigger[i]->type == TRIGGER_HELD && state == STATE_SELECTED && if(trigger[i]->type == TRIGGER_HELD && state == STATE_SELECTED &&
@ -280,9 +280,9 @@ void GuiButton::Update(GuiTrigger * t)
} }
if( if(
(t->wpad.btns_h > 0 && (t->wpad->btns_h > 0 &&
(wm_btns_h == wm_btns_trig || (wm_btns_h == wm_btns_trig ||
(cc_btns_h == cc_btns_trig && t->wpad.exp.type == EXP_CLASSIC))) || (cc_btns_h == cc_btns_trig && t->wpad->exp.type == EXP_CLASSIC))) ||
(t->pad.btns_h == trigger[i]->pad.btns_h && t->pad.btns_h > 0)) (t->pad.btns_h == trigger[i]->pad.btns_h && t->pad.btns_h > 0))
{ {
if(trigger[i]->type == TRIGGER_HELD) if(trigger[i]->type == TRIGGER_HELD)

View File

@ -69,6 +69,7 @@ GuiElement * GuiElement::GetParent()
{ {
return parentElement; return parentElement;
} }
/** /**
* Get the left position of the GuiElement. * Get the left position of the GuiElement.
* @see SetLeft() * @see SetLeft()

View File

@ -18,8 +18,9 @@ static int scrollDelay = 0;
GuiTrigger::GuiTrigger() GuiTrigger::GuiTrigger()
{ {
chan = -1; chan = -1;
memset(&wpad, 0, sizeof(WPADData)); memset(&wpaddata, 0, sizeof(WPADData));
memset(&pad, 0, sizeof(PADData)); memset(&pad, 0, sizeof(PADData));
wpad = &wpaddata;
} }
/** /**
@ -38,7 +39,7 @@ void GuiTrigger::SetSimpleTrigger(s32 ch, u32 wiibtns, u16 gcbtns)
{ {
type = TRIGGER_SIMPLE; type = TRIGGER_SIMPLE;
chan = ch; chan = ch;
wpad.btns_d = wiibtns; wpaddata.btns_d = wiibtns;
pad.btns_d = gcbtns; pad.btns_d = gcbtns;
} }
@ -51,7 +52,7 @@ void GuiTrigger::SetHeldTrigger(s32 ch, u32 wiibtns, u16 gcbtns)
{ {
type = TRIGGER_HELD; type = TRIGGER_HELD;
chan = ch; chan = ch;
wpad.btns_h = wiibtns; wpaddata.btns_h = wiibtns;
pad.btns_h = gcbtns; pad.btns_h = gcbtns;
} }
@ -63,7 +64,7 @@ void GuiTrigger::SetButtonOnlyTrigger(s32 ch, u32 wiibtns, u16 gcbtns)
{ {
type = TRIGGER_BUTTON_ONLY; type = TRIGGER_BUTTON_ONLY;
chan = ch; chan = ch;
wpad.btns_d = wiibtns; wpaddata.btns_d = wiibtns;
pad.btns_d = gcbtns; pad.btns_d = gcbtns;
} }
@ -76,7 +77,7 @@ void GuiTrigger::SetButtonOnlyInFocusTrigger(s32 ch, u32 wiibtns, u16 gcbtns)
{ {
type = TRIGGER_BUTTON_ONLY_IN_FOCUS; type = TRIGGER_BUTTON_ONLY_IN_FOCUS;
chan = ch; chan = ch;
wpad.btns_d = wiibtns; wpaddata.btns_d = wiibtns;
pad.btns_d = gcbtns; pad.btns_d = gcbtns;
} }
@ -91,27 +92,27 @@ s8 GuiTrigger::WPAD_Stick(u8 right, int axis)
float mag = 0.0; float mag = 0.0;
float ang = 0.0; float ang = 0.0;
switch (wpad.exp.type) switch (wpad->exp.type)
{ {
case WPAD_EXP_NUNCHUK: case WPAD_EXP_NUNCHUK:
case WPAD_EXP_GUITARHERO3: case WPAD_EXP_GUITARHERO3:
if (right == 0) if (right == 0)
{ {
mag = wpad.exp.nunchuk.js.mag; mag = wpad->exp.nunchuk.js.mag;
ang = wpad.exp.nunchuk.js.ang; ang = wpad->exp.nunchuk.js.ang;
} }
break; break;
case WPAD_EXP_CLASSIC: case WPAD_EXP_CLASSIC:
if (right == 0) if (right == 0)
{ {
mag = wpad.exp.classic.ljs.mag; mag = wpad->exp.classic.ljs.mag;
ang = wpad.exp.classic.ljs.ang; ang = wpad->exp.classic.ljs.ang;
} }
else else
{ {
mag = wpad.exp.classic.rjs.mag; mag = wpad->exp.classic.rjs.mag;
ang = wpad.exp.classic.rjs.ang; ang = wpad->exp.classic.rjs.ang;
} }
break; break;
@ -136,12 +137,12 @@ bool GuiTrigger::Left()
{ {
u32 wiibtn = WPAD_BUTTON_LEFT; u32 wiibtn = WPAD_BUTTON_LEFT;
if((wpad.btns_d | wpad.btns_h) & (wiibtn | WPAD_CLASSIC_BUTTON_LEFT) if((wpad->btns_d | wpad->btns_h) & (wiibtn | WPAD_CLASSIC_BUTTON_LEFT)
|| (pad.btns_d | pad.btns_h) & PAD_BUTTON_LEFT || (pad.btns_d | pad.btns_h) & PAD_BUTTON_LEFT
|| pad.stickX < -PADCAL || pad.stickX < -PADCAL
|| WPAD_Stick(0,0) < -PADCAL) || WPAD_Stick(0,0) < -PADCAL)
{ {
if(wpad.btns_d & (wiibtn | WPAD_CLASSIC_BUTTON_LEFT) if(wpad->btns_d & (wiibtn | WPAD_CLASSIC_BUTTON_LEFT)
|| pad.btns_d & PAD_BUTTON_LEFT) || pad.btns_d & PAD_BUTTON_LEFT)
{ {
scrollDelay = SCROLL_INITIAL_DELAY; // reset scroll delay. scrollDelay = SCROLL_INITIAL_DELAY; // reset scroll delay.
@ -165,12 +166,12 @@ bool GuiTrigger::Right()
{ {
u32 wiibtn = WPAD_BUTTON_RIGHT; u32 wiibtn = WPAD_BUTTON_RIGHT;
if((wpad.btns_d | wpad.btns_h) & (wiibtn | WPAD_CLASSIC_BUTTON_RIGHT) if((wpad->btns_d | wpad->btns_h) & (wiibtn | WPAD_CLASSIC_BUTTON_RIGHT)
|| (pad.btns_d | pad.btns_h) & PAD_BUTTON_RIGHT || (pad.btns_d | pad.btns_h) & PAD_BUTTON_RIGHT
|| pad.stickX > PADCAL || pad.stickX > PADCAL
|| WPAD_Stick(0,0) > PADCAL) || WPAD_Stick(0,0) > PADCAL)
{ {
if(wpad.btns_d & (wiibtn | WPAD_CLASSIC_BUTTON_RIGHT) if(wpad->btns_d & (wiibtn | WPAD_CLASSIC_BUTTON_RIGHT)
|| pad.btns_d & PAD_BUTTON_RIGHT) || pad.btns_d & PAD_BUTTON_RIGHT)
{ {
scrollDelay = SCROLL_INITIAL_DELAY; // reset scroll delay. scrollDelay = SCROLL_INITIAL_DELAY; // reset scroll delay.
@ -194,12 +195,12 @@ bool GuiTrigger::Up()
{ {
u32 wiibtn = WPAD_BUTTON_UP; u32 wiibtn = WPAD_BUTTON_UP;
if((wpad.btns_d | wpad.btns_h) & (wiibtn | WPAD_CLASSIC_BUTTON_UP) if((wpad->btns_d | wpad->btns_h) & (wiibtn | WPAD_CLASSIC_BUTTON_UP)
|| (pad.btns_d | pad.btns_h) & PAD_BUTTON_UP || (pad.btns_d | pad.btns_h) & PAD_BUTTON_UP
|| pad.stickY > PADCAL || pad.stickY > PADCAL
|| WPAD_Stick(0,1) > PADCAL) || WPAD_Stick(0,1) > PADCAL)
{ {
if(wpad.btns_d & (wiibtn | WPAD_CLASSIC_BUTTON_UP) if(wpad->btns_d & (wiibtn | WPAD_CLASSIC_BUTTON_UP)
|| pad.btns_d & PAD_BUTTON_UP) || pad.btns_d & PAD_BUTTON_UP)
{ {
scrollDelay = SCROLL_INITIAL_DELAY; // reset scroll delay. scrollDelay = SCROLL_INITIAL_DELAY; // reset scroll delay.
@ -223,12 +224,12 @@ bool GuiTrigger::Down()
{ {
u32 wiibtn = WPAD_BUTTON_DOWN; u32 wiibtn = WPAD_BUTTON_DOWN;
if((wpad.btns_d | wpad.btns_h) & (wiibtn | WPAD_CLASSIC_BUTTON_DOWN) if((wpad->btns_d | wpad->btns_h) & (wiibtn | WPAD_CLASSIC_BUTTON_DOWN)
|| (pad.btns_d | pad.btns_h) & PAD_BUTTON_DOWN || (pad.btns_d | pad.btns_h) & PAD_BUTTON_DOWN
|| pad.stickY < -PADCAL || pad.stickY < -PADCAL
|| WPAD_Stick(0,1) < -PADCAL) || WPAD_Stick(0,1) < -PADCAL)
{ {
if(wpad.btns_d & (wiibtn | WPAD_CLASSIC_BUTTON_DOWN) if(wpad->btns_d & (wiibtn | WPAD_CLASSIC_BUTTON_DOWN)
|| pad.btns_d & PAD_BUTTON_DOWN) || pad.btns_d & PAD_BUTTON_DOWN)
{ {
scrollDelay = SCROLL_INITIAL_DELAY; // reset scroll delay. scrollDelay = SCROLL_INITIAL_DELAY; // reset scroll delay.

View File

@ -195,7 +195,7 @@ void GuiWindow::ToggleFocus(GuiTrigger * t)
} }
} }
// change focus // change focus
else if(t->wpad.btns_d & (WPAD_BUTTON_1 | WPAD_BUTTON_B | WPAD_CLASSIC_BUTTON_B) else if(t->wpad->btns_d & (WPAD_BUTTON_1 | WPAD_BUTTON_B | WPAD_CLASSIC_BUTTON_B)
|| t->pad.btns_d & PAD_BUTTON_B) || t->pad.btns_d & PAD_BUTTON_B)
{ {
for (i = found; i < _elements.size(); i++) for (i = found; i < _elements.size(); i++)

View File

@ -51,9 +51,9 @@ static void * UpdateGUI (void *arg)
for(i=3; i >= 0; i--) // so that player 1's cursor appears on top! for(i=3; i >= 0; i--) // so that player 1's cursor appears on top!
{ {
if(userInput[i].wpad.ir.valid) if(userInput[i].wpad->ir.valid)
Menu_DrawImg(userInput[i].wpad.ir.x-48, userInput[i].wpad.ir.y-48, Menu_DrawImg(userInput[i].wpad->ir.x-48, userInput[i].wpad->ir.y-48,
96, 96, pointer[i]->GetImage(), userInput[i].wpad.ir.angle, 1, 1, 255); 96, 96, pointer[i]->GetImage(), userInput[i].wpad->ir.angle, 1, 1, 255);
DoRumble(i); DoRumble(i);
} }
@ -274,7 +274,7 @@ static void * WindowCredits(void *arg)
{ {
for(i=0; i < 4; i++) for(i=0; i < 4; i++)
{ {
if(userInput[i].wpad.btns_d || userInput[i].pad.btns_d) if(userInput[i].wpad->btns_d || userInput[i].pad.btns_d)
exit = true; exit = true;
} }
usleep(THREAD_SLEEP); usleep(THREAD_SLEEP);
@ -492,7 +492,7 @@ void HomeMenu ()
if(WPAD_Probe(i, NULL) == WPAD_ERR_NONE) if(WPAD_Probe(i, NULL) == WPAD_ERR_NONE)
{ {
newStatus = true; newStatus = true;
newLevel = (userInput[i].wpad.battery_level / 100.0) * 4; newLevel = (userInput[i].wpad->battery_level / 100.0) * 4;
if(newLevel > 4) newLevel = 4; if(newLevel > 4) newLevel = 4;
} }
else else

View File

@ -18,6 +18,7 @@
#include "wiihardware.h" #include "wiihardware.h"
#include "FreeTypeGX.h" #include "FreeTypeGX.h"
#include "input.h"
#include "filelist.h" #include "filelist.h"
#include "SDL_events.h" #include "SDL_events.h"
@ -205,6 +206,7 @@ void WiiInit()
__exception_setreload(8); __exception_setreload(8);
fatInitDefault(); fatInitDefault();
ASND_Init(); ASND_Init();
SetupPads();
InitFreeType((u8*)font_ttf, font_ttf_size); InitFreeType((u8*)font_ttf, font_ttf_size);
LWP_CreateThread (&keythread, PressKeys, NULL, NULL, 0, 65); LWP_CreateThread (&keythread, PressKeys, NULL, NULL, 0, 65);
appPath[0] = 0; appPath[0] = 0;