Rewrite and unify the handling of the scrollwheel between layers, fixing it in the editor's 2D mode and tile selector under SDL.

The scrollwheel is unique among PC input because it has no innate "hold length". Previously, the layers gave the mousewheel a fake hold length to allow the not-necessarily-synchronous game/editor code to pick up the input before the layers marked it as "no longer pressed". This passed under Windows, but it didn't slide under SDL.

Besides the two problems listed above, it also potentially limited the rate of weapon selection, where scrolling too fast would not register every clicks. [Unrelatedly, this is still the case when you scroll faster than the game's own tickrate, but addressing that would require rewriting input handling to go through a list of "events" for each tic instead of looking at overall pressed/unpressed states.]

git-svn-id: https://svn.eduke32.com/eduke32@4200 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
hendricks266 2013-12-20 07:24:09 +00:00
parent ee9e84c356
commit cfedcbd7d7
7 changed files with 71 additions and 54 deletions

View file

@ -149,6 +149,7 @@ void readmousebstatus(int32_t *b);
void readjoybstatus(int32_t *b); void readjoybstatus(int32_t *b);
void setjoydeadzone(int32_t axis, uint16_t dead, uint16_t satur); void setjoydeadzone(int32_t axis, uint16_t dead, uint16_t satur);
void getjoydeadzone(int32_t axis, uint16_t *dead, uint16_t *satur); void getjoydeadzone(int32_t axis, uint16_t *dead, uint16_t *satur);
extern int32_t inputchecked;
int32_t inittimer(int32_t); int32_t inittimer(int32_t);
void uninittimer(void); void uninittimer(void);

View file

@ -741,6 +741,8 @@ CANCEL:
M32_DrawRoomsAndMasks(); M32_DrawRoomsAndMasks();
inputchecked = 1;
#ifdef M32_SHOWDEBUG #ifdef M32_SHOWDEBUG
if (searchstat>=0 && (searchwall<0 || searchsector<0)) if (searchstat>=0 && (searchwall<0 || searchsector<0))
{ {
@ -3722,6 +3724,8 @@ void overheadeditor(void)
OSD_Draw(); OSD_Draw();
} }
inputchecked = 1;
VM_OnEvent(EVENT_PREKEYS2D, -1); VM_OnEvent(EVENT_PREKEYS2D, -1);
ExtCheckKeys(); // TX 20050101, it makes more sense to have this here so keys can be overwritten with new functions in bstub.c ExtCheckKeys(); // TX 20050101, it makes more sense to have this here so keys can be overwritten with new functions in bstub.c
@ -5695,14 +5699,22 @@ end_point_dragging:
{ {
if ((DOWN_BK(MOVEUP) || (bstatus&16)) && m32_sideelev < 512) if ((DOWN_BK(MOVEUP) || (bstatus&16)) && m32_sideelev < 512)
{ {
m32_sideelev += synctics<<(1+!!(bstatus&16)); if (DOWN_BK(MOVEUP))
m32_sideelev += synctics<<1;
if (bstatus&16)
m32_sideelev += 4<<1;
if (m32_sideelev > 512) if (m32_sideelev > 512)
m32_sideelev = 512; m32_sideelev = 512;
_printmessage16("Sideview elevation: %d", m32_sideelev); _printmessage16("Sideview elevation: %d", m32_sideelev);
} }
if ((DOWN_BK(MOVEDOWN) || (bstatus&32)) && m32_sideelev > 0) if ((DOWN_BK(MOVEDOWN) || (bstatus&32)) && m32_sideelev > 0)
{ {
m32_sideelev -= synctics<<(1+!!(bstatus&32)); if (DOWN_BK(MOVEDOWN))
m32_sideelev -= synctics<<1;
if (bstatus&32)
m32_sideelev -= 4<<1;
if (m32_sideelev < 0) if (m32_sideelev < 0)
m32_sideelev = 0; m32_sideelev = 0;
_printmessage16("Sideview elevation: %d", m32_sideelev); _printmessage16("Sideview elevation: %d", m32_sideelev);
@ -5714,13 +5726,21 @@ end_point_dragging:
if ((DOWN_BK(MOVEUP) || (bstatus&16)) && zoom < 65536) if ((DOWN_BK(MOVEUP) || (bstatus&16)) && zoom < 65536)
{ {
zoom += synctics*(zoom>>4); if (DOWN_BK(MOVEUP))
zoom += synctics*(zoom>>4);
if (bstatus&16)
zoom += 4*(zoom>>4);
if (zoom < 24) zoom += 2; if (zoom < 24) zoom += 2;
didzoom = 1; didzoom = 1;
} }
if ((DOWN_BK(MOVEDOWN) || (bstatus&32)) && zoom > 8) if ((DOWN_BK(MOVEDOWN) || (bstatus&32)) && zoom > 8)
{ {
zoom -= synctics*(zoom>>4); if (DOWN_BK(MOVEDOWN))
zoom -= synctics*(zoom>>4);
if (bstatus&32)
zoom -= 4*(zoom>>4);
didzoom = 1; didzoom = 1;
} }
@ -9051,6 +9071,8 @@ int32_t _getnumber256(const char *namestart, int32_t num, int32_t maxnumber, cha
searchx = osearchx; searchx = osearchx;
searchy = osearchy; searchy = osearchy;
inputchecked = 1;
if ((flags&8)==0) if ((flags&8)==0)
ExtCheckKeys(); ExtCheckKeys();

View file

@ -10,12 +10,10 @@ static BOOL rawinput_started = 0;
static uint8_t KeyboardState[256] = {0}; // VKeys static uint8_t KeyboardState[256] = {0}; // VKeys
extern volatile uint8_t moustat, mousegrab; extern volatile uint8_t moustat, mousegrab;
extern uint32_t mousewheel[2];
extern void SetKey(int32_t key, int32_t state); extern void SetKey(int32_t key, int32_t state);
//#define MASK_DOWN (1<<(i<<1)) //#define MASK_DOWN (1<<(i<<1))
//#define MASK_UP (MASK_DOWN<<1) //#define MASK_UP (MASK_DOWN<<1)
#define MouseWheelFakePressTime 50
#ifndef GET_RAWINPUT_CODE_WPARAM #ifndef GET_RAWINPUT_CODE_WPARAM
#define GET_RAWINPUT_CODE_WPARAM(wParam) ((wParam) & 0xff) #define GET_RAWINPUT_CODE_WPARAM(wParam) ((wParam) & 0xff)
#endif #endif
@ -73,15 +71,11 @@ static inline void RI_ProcessMouse(const RAWMOUSE *rmouse)
if (MWheel > 0) // wheel up if (MWheel > 0) // wheel up
{ {
if (mousewheel[0] > 0 && mousepresscallback) mousepresscallback(5,0);
mousewheel[0] = getticks();
mouseb |= 16; mouseb |= 16;
if (mousepresscallback) mousepresscallback(5, 1); if (mousepresscallback) mousepresscallback(5, 1);
} }
else if (MWheel < 0) // wheel down else if (MWheel < 0) // wheel down
{ {
if (mousewheel[1] > 0 && mousepresscallback) mousepresscallback(6,0);
mousewheel[1] = getticks();
mouseb |= 32; mouseb |= 32;
if (mousepresscallback) mousepresscallback(6, 1); if (mousepresscallback) mousepresscallback(6, 1);
} }
@ -225,6 +219,18 @@ void RI_PollDevices(BOOL loop)
rawinput_started = 1; rawinput_started = 1;
} }
if (inputchecked)
{
if (mousepresscallback)
{
if (mouseb & 16)
mousepresscallback(5, 0);
if (mouseb & 32)
mousepresscallback(6, 0);
}
mouseb &= ~(16|32);
}
// snapshot the whole keyboard state so we can translate key presses into ascii later // snapshot the whole keyboard state so we can translate key presses into ascii later
for (i = 0; i < 256; i++) for (i = 0; i < 256; i++)
KeyboardState[i] = GetAsyncKeyState(i) >> 8; KeyboardState[i] = GetAsyncKeyState(i) >> 8;
@ -239,18 +245,6 @@ void RI_PollDevices(BOOL loop)
ClientToScreen((HWND)win_gethwnd(), &pt); ClientToScreen((HWND)win_gethwnd(), &pt);
SetCursorPos(pt.x, pt.y); SetCursorPos(pt.x, pt.y);
// do this here because we only want the wheel to signal once, but hold the state for a moment
if (mousewheel[0] > 0 && getticks() - mousewheel[0] > MouseWheelFakePressTime)
{
if (mousepresscallback) mousepresscallback(5,0);
mousewheel[0] = 0; mouseb &= ~16;
}
if (mousewheel[1] > 0 && getticks() - mousewheel[1] > MouseWheelFakePressTime)
{
if (mousepresscallback) mousepresscallback(6,0);
mousewheel[1] = 0; mouseb &= ~32;
}
} }
} }

View file

@ -61,8 +61,7 @@ int32_t startwin_settitle(const char *s) { UNREFERENCED_PARAMETER(s); return 0;
#define ANY_WINDOWED_SIZE #define ANY_WINDOWED_SIZE
// fix for mousewheel // fix for mousewheel
#define MWHEELTICKS 10 int32_t inputchecked = 0;
static uint32_t mwheelup, mwheeldown;
extern int32_t app_main(int32_t argc, const char **argv); extern int32_t app_main(int32_t argc, const char **argv);
@ -2026,6 +2025,21 @@ int32_t handleevents(void)
int32_t code, rv=0, j; int32_t code, rv=0, j;
SDL_Event ev; SDL_Event ev;
if (inputchecked)
{
if (moustat)
{
if (mousepresscallback)
{
if (mouseb & 16)
mousepresscallback(5, 0);
if (mouseb & 32)
mousepresscallback(6, 0);
}
mouseb &= ~(16|32);
}
}
while (SDL_PollEvent(&ev)) while (SDL_PollEvent(&ev))
{ {
switch (ev.type) switch (ev.type)
@ -2108,14 +2122,12 @@ int32_t handleevents(void)
// initprintf("wheel y %d\n",ev.wheel.y); // initprintf("wheel y %d\n",ev.wheel.y);
if (ev.wheel.y > 0) if (ev.wheel.y > 0)
{ {
mwheelup = totalclock;
mouseb |= 16; mouseb |= 16;
if (mousepresscallback) if (mousepresscallback)
mousepresscallback(5, 1); mousepresscallback(5, 1);
} }
if (ev.wheel.y < 0) if (ev.wheel.y < 0)
{ {
mwheeldown = totalclock;
mouseb |= 32; mouseb |= 32;
if (mousepresscallback) if (mousepresscallback)
mousepresscallback(6, 1); mousepresscallback(6, 1);
@ -2260,16 +2272,6 @@ int32_t handleevents(void)
if (ev.button.state == SDL_PRESSED) if (ev.button.state == SDL_PRESSED)
{ {
#if SDL_MAJOR_VERSION==1
if (ev.button.button == SDL_BUTTON_WHEELUP)
{
mwheelup = totalclock;
}
if (ev.button.button == SDL_BUTTON_WHEELDOWN)
{
mwheeldown = totalclock;
}
#endif
mouseb |= (1<<j); mouseb |= (1<<j);
} }
else else
@ -2385,21 +2387,9 @@ int32_t handleevents(void)
// if (mousex|mousey) printf("%d,%d\n",mousex,mousey); /// // if (mousex|mousey) printf("%d,%d\n",mousex,mousey); ///
sampletimer(); inputchecked = 0;
if (moustat) sampletimer();
{
if ((mwheelup) && (mwheelup <= (unsigned)(totalclock - MWHEELTICKS)))
{
mouseb &= ~16;
mwheelup = 0;
}
if ((mwheeldown) && (mwheeldown <= (unsigned)(totalclock - MWHEELTICKS)))
{
mouseb &= ~32;
mwheeldown = 0;
}
}
#ifndef _WIN32 #ifndef _WIN32
startwin_idle(NULL); startwin_idle(NULL);

View file

@ -159,8 +159,8 @@ char quitevent=0;
char appactive=1; char appactive=1;
char realfs=0; char realfs=0;
char regrabmouse=0; char regrabmouse=0;
uint32_t mousewheel[2] = { 0,0 };
char defaultlayoutname[KL_NAMELENGTH]; char defaultlayoutname[KL_NAMELENGTH];
int32_t inputchecked = 0;
//------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------
// DINPUT (JOYSTICK) // DINPUT (JOYSTICK)
@ -722,6 +722,8 @@ int32_t handleevents(void)
WndProcCallback(msg.hwnd, msg.message, msg.wParam, msg.lParam); WndProcCallback(msg.hwnd, msg.message, msg.wParam, msg.lParam);
} }
inputchecked = 0;
if (!appactive || quitevent) rv = -1; if (!appactive || quitevent) rv = -1;
sampletimer(); sampletimer();
@ -809,6 +811,9 @@ void idle_waitevent_timeout(uint32_t timeout)
if (PeekMessage(&msg, 0, WM_INPUT, WM_INPUT, PM_QS_INPUT)) if (PeekMessage(&msg, 0, WM_INPUT, WM_INPUT, PM_QS_INPUT))
{ {
RI_PollDevices(TRUE); RI_PollDevices(TRUE);
inputchecked = 0;
return; return;
} }
@ -926,11 +931,10 @@ void releaseallbuttons(void)
if (mouseb & 2) mousepresscallback(2, 0); if (mouseb & 2) mousepresscallback(2, 0);
if (mouseb & 4) mousepresscallback(3, 0); if (mouseb & 4) mousepresscallback(3, 0);
if (mouseb & 8) mousepresscallback(4, 0); if (mouseb & 8) mousepresscallback(4, 0);
if (mousewheel[0]>0) mousepresscallback(5,0); if (mouseb & 16) mousepresscallback(5, 0);
if (mousewheel[1]>0) mousepresscallback(6,0); if (mouseb & 32) mousepresscallback(6, 0);
if (mouseb & 64) mousepresscallback(7, 0); if (mouseb & 64) mousepresscallback(7, 0);
} }
mousewheel[0]=mousewheel[1]=0;
mouseb = 0; mouseb = 0;
if (joypresscallback) if (joypresscallback)

View file

@ -4285,6 +4285,8 @@ static void getnumberptr256(const char *namestart, void *num, int32_t bytes, int
searchx = osearchx; searchx = osearchx;
searchy = osearchy; searchy = osearchy;
inputchecked = 1;
ExtCheckKeys(); ExtCheckKeys();
Bsprintf(buffer,"%s%d",namestart,danum); Bsprintf(buffer,"%s%d",namestart,danum);
@ -4478,6 +4480,8 @@ ENDFOR1:
searchx = osearchx; searchx = osearchx;
searchy = osearchy; searchy = osearchy;
inputchecked = 1;
ExtCheckKeys(); ExtCheckKeys();
printmessage256(0,0,"^251Text entry mode.^31 Navigation keys change vars."); printmessage256(0,0,"^251Text entry mode.^31 Navigation keys change vars.");

View file

@ -791,6 +791,8 @@ void CONTROL_GetInput(ControlInfo *info)
CONTROL_PollDevices(info); CONTROL_PollDevices(info);
CONTROL_GetFunctionInput(); CONTROL_GetFunctionInput();
inputchecked = 1;
} }
int32_t CONTROL_Startup(controltype which, int32_t(*TimeFunction)(void), int32_t ticspersecond) int32_t CONTROL_Startup(controltype which, int32_t(*TimeFunction)(void), int32_t ticspersecond)