@@ -65,6 +65,7 @@ CInput::CInput(BOOL bExclusive, int deviceForInit)
65
65
66
66
CInput::~CInput (void )
67
67
{
68
+ SDL_SetRelativeMouseMode (SDL_FALSE);
68
69
#ifdef ENGINE_BUILD
69
70
Device.seqFrame .Remove (this );
70
71
Device.seqAppDeactivate .Remove (this );
@@ -79,89 +80,67 @@ void CInput::DumpStatistics(IGameFont& font, IPerformanceAlert* alert)
79
80
font.OutNext (" *** INPUT: %2.2fms" , pInput->GetStats ().FrameTime .result );
80
81
}
81
82
82
- void CInput::SetAllAcquire (BOOL bAcquire)
83
- {
84
- }
83
+ void CInput::SetAllAcquire (BOOL bAcquire) {}
85
84
86
- void CInput::SetMouseAcquire (BOOL bAcquire)
87
- {
88
- }
85
+ void CInput::SetMouseAcquire (BOOL bAcquire) {}
89
86
void CInput::SetKBDAcquire (BOOL bAcquire) {}
90
87
// -----------------------------------------------------------------------
91
- void CInput::KeyUpdate (SDL_Event* event)
88
+ BOOL b_altF4 = FALSE ;
89
+ void CInput::KeyUpdate ()
92
90
{
91
+ if (b_altF4)
92
+ return ;
93
+
93
94
bool b_dik_pause_was_pressed = false ;
94
95
95
- if (SDL_SCANCODE_PAUSE == event->key .keysym .scancode )
96
+ const Uint8* state = SDL_GetKeyboardState (NULL );
97
+ #ifndef _EDITOR
98
+ bool b_alt_tab = false ;
99
+
100
+ if (!b_altF4 && state[SDL_SCANCODE_F4] && (state[SDL_SCANCODE_RALT] || state[SDL_SCANCODE_LALT]))
96
101
{
97
- if (SDL_KEYDOWN == event->key .type )
98
- b_dik_pause_was_pressed = true ;
102
+ b_altF4 = TRUE ;
103
+ Engine.Event .Defer (" KERNEL:disconnect" );
104
+ Engine.Event .Defer (" KERNEL:quit" );
105
+ SDL_Event ev;
106
+ ev.type = SDL_QUIT;
107
+ SDL_PushEvent (&ev);
99
108
}
109
+ #endif
110
+ if (b_altF4)
111
+ return ;
100
112
101
113
#ifndef _EDITOR
102
- bool b_alt_tab = false ;
103
-
104
114
if (Device.dwPrecacheFrame == 0 )
105
115
#endif
106
116
{
107
- const Uint8* state = SDL_GetKeyboardState (NULL );
108
-
109
- if (SDL_KEYDOWN == event->key .type )
110
- cbStack.back ()->IR_OnKeyboardPress (event->key .keysym .scancode );
111
- else if (SDL_KEYUP == event->key .type )
117
+ for (u32 i = 0 ; i < COUNT_KB_BUTTONS; i++)
112
118
{
113
- cbStack.back ()->IR_OnKeyboardRelease (event->key .keysym .scancode );
119
+ if (state[i])
120
+ cbStack.back ()->IR_OnKeyboardPress (i);
121
+ else
122
+ {
123
+ cbStack.back ()->IR_OnKeyboardRelease (i);
114
124
#ifndef _EDITOR
115
- if (SDL_SCANCODE_TAB == event->key .keysym .scancode && KMOD_ALT == SDL_GetModState ())
116
- b_alt_tab = true ;
125
+ if (SDL_SCANCODE_TAB == state[i] &&
126
+ (iGetAsyncKeyState (SDL_SCANCODE_LALT) || iGetAsyncKeyState (SDL_SCANCODE_RALT)))
127
+ b_alt_tab = true ;
117
128
#endif
129
+ }
118
130
}
119
131
120
132
for (u32 i = 0 ; i < COUNT_KB_BUTTONS; i++)
121
- if (state[i])
133
+ if (KBState[i] && state[i])
122
134
cbStack.back ()->IR_OnKeyboardHold (i);
135
+
136
+ for (u32 idx = 0 ; idx < COUNT_KB_BUTTONS; idx++)
137
+ KBState[idx] = state[idx];
123
138
}
124
139
125
140
#ifndef _EDITOR
126
141
if (b_alt_tab)
127
142
SDL_MinimizeWindow (Device.m_sdlWnd );
128
143
#endif
129
- /*
130
- #ifndef _EDITOR
131
- //update xinput if exist
132
- for( DWORD iUserIndex=0; iUserIndex<DXUT_MAX_CONTROLLERS; iUserIndex++ )
133
- {
134
- DXUTGetGamepadState( iUserIndex, &g_GamePads[iUserIndex], true, false );
135
-
136
- if( !g_GamePads[iUserIndex].bConnected )
137
- continue; // unplugged?
138
-
139
- bool new_b, old_b;
140
- new_b = !!(g_GamePads[iUserIndex].wPressedButtons & XINPUT_GAMEPAD_A);
141
- old_b = !!(g_GamePads[iUserIndex].wLastButtons & XINPUT_GAMEPAD_A);
142
-
143
- if(new_b != old_b)
144
- {
145
- if(old_b)
146
- cbStack.back()->IR_OnMousePress(0);
147
- else
148
- cbStack.back()->IR_OnMouseRelease(0);
149
- }
150
- int dx,dy;
151
- dx = iFloor(g_GamePads[iUserIndex].fThumbRX*6);
152
- dy = iFloor(g_GamePads[iUserIndex].fThumbRY*6);
153
- if(dx || dy)
154
- cbStack.back()->IR_OnMouseMove ( dx, dy );
155
- }
156
-
157
- if(Device.fTimeGlobal > stop_vibration_time)
158
- {
159
- stop_vibration_time = flt_max;
160
- set_vibration (0, 0);
161
- }
162
- //xinput
163
- #endif
164
- */
165
144
}
166
145
167
146
bool CInput::get_key_name (int dik, LPSTR dest_str, int dest_sz)
@@ -209,46 +188,71 @@ void CInput::ClipCursor(bool clip)
209
188
}
210
189
}
211
190
212
- void CInput::MouseUpdate (SDL_Event * event)
191
+ void CInput::MouseUpdate (SDL_Event* event)
213
192
{
214
- DWORD dwElements = MOUSEBUFFERSIZE;
215
-
216
193
#ifndef _EDITOR
217
194
if (Device.dwPrecacheFrame )
218
195
return ;
219
196
#endif
220
197
BOOL mouse_prev[COUNT_MOUSE_BUTTONS];
221
198
222
- mouse_prev[0 ] = mouseState[0 ];
223
- mouse_prev[1 ] = mouseState[1 ];
224
- mouse_prev[2 ] = mouseState[2 ];
225
- mouse_prev[3 ] = mouseState[3 ];
226
- mouse_prev[4 ] = mouseState[4 ];
227
- mouse_prev[5 ] = mouseState[5 ];
228
- mouse_prev[6 ] = mouseState[6 ];
229
- mouse_prev[7 ] = mouseState[7 ];
230
-
231
199
offs[0 ] = offs[1 ] = offs[2 ] = 0 ;
232
200
233
201
switch (event->type )
234
202
{
235
203
case SDL_MOUSEMOTION:
204
+ {
205
+ offs[0 ] += event->motion .xrel ;
206
+ offs[1 ] += event->motion .yrel ;
236
207
timeStamp[0 ] = event->motion .timestamp ;
237
- cbStack.back ()->IR_OnMouseMove (event->motion .xrel , event->motion .yrel );
238
- break ;
239
- case SDL_MOUSEBUTTONUP:
240
- cbStack.back ()->IR_OnMouseRelease (event->button .button );
208
+ timeStamp[1 ] = event->motion .timestamp ;
209
+ if (offs[0 ] || offs[1 ])
210
+ cbStack.back ()->IR_OnMouseMove (offs[0 ], offs[1 ]);
211
+ }
212
+ break ;
213
+ case SDL_MOUSEBUTTONUP:
214
+ mouseState[event->button .button ] = FALSE ;
215
+ cbStack.back ()->IR_OnKeyboardRelease (SDL_NUM_SCANCODES + event->button .button );
241
216
break ;
242
217
case SDL_MOUSEBUTTONDOWN:
243
- cbStack.back ()->IR_OnMousePress (event->button .button );
218
+ mouseState[event->button .button ] = TRUE ;
219
+ cbStack.back ()->IR_OnKeyboardPress (SDL_NUM_SCANCODES + event->button .button );
244
220
break ;
245
221
case SDL_MOUSEWHEEL:
222
+ offs[2 ] += event->wheel .direction ;
246
223
timeStamp[2 ] = event->wheel .timestamp ;
247
- cbStack.back ()->IR_OnMouseWheel (event->wheel .direction );
224
+ if (offs[2 ])
225
+ cbStack.back ()->IR_OnMouseWheel (offs[2 ]);
226
+ break ;
227
+ default :
228
+ if (timeStamp[1 ] && ((dwCurTime - timeStamp[1 ]) >= 25 ))
229
+ cbStack.back ()->IR_OnMouseStop (1 , timeStamp[1 ] = 0 );
230
+ if (timeStamp[0 ] && ((dwCurTime - timeStamp[0 ]) >= 25 ))
231
+ cbStack.back ()->IR_OnMouseStop (0 , timeStamp[0 ] = 0 );
248
232
break ;
249
- default : break ;
250
233
}
251
234
235
+ auto isButtonOnHold = [&](int i) {
236
+ if (mouseState[i] && mouse_prev[i])
237
+ cbStack.back ()->IR_OnMouseHold (i);
238
+ };
239
+
240
+ isButtonOnHold (0 );
241
+ isButtonOnHold (1 );
242
+ isButtonOnHold (2 );
243
+ isButtonOnHold (3 );
244
+ isButtonOnHold (4 );
245
+ isButtonOnHold (5 );
246
+ isButtonOnHold (6 );
247
+
248
+ mouse_prev[0 ] = mouseState[0 ];
249
+ mouse_prev[1 ] = mouseState[1 ];
250
+ mouse_prev[2 ] = mouseState[2 ];
251
+ mouse_prev[3 ] = mouseState[3 ];
252
+ mouse_prev[4 ] = mouseState[4 ];
253
+ mouse_prev[5 ] = mouseState[5 ];
254
+ mouse_prev[6 ] = mouseState[6 ];
255
+ mouse_prev[7 ] = mouseState[7 ];
252
256
}
253
257
254
258
// -------------------------------------------------------
@@ -327,41 +331,29 @@ void CInput::OnFrame(void)
327
331
328
332
while (SDL_PollEvent (&event))
329
333
{
334
+ BOOL b_break_cycle = false ;
330
335
switch (event.type )
331
336
{
332
337
case SDL_KEYDOWN:
333
- case SDL_KEYUP: KeyUpdate (&event ); continue ;
338
+ case SDL_KEYUP: KeyUpdate (); continue ;
334
339
335
340
case SDL_MOUSEMOTION:
336
341
case SDL_MOUSEBUTTONUP:
337
342
case SDL_MOUSEBUTTONDOWN:
338
343
case SDL_MOUSEWHEEL:
339
344
MouseUpdate (&event);
340
- // MouseUpdate();
341
345
continue ;
342
- // case SDL_WINDOWEVENT:
343
- // switch (event.window.event)
344
- // {
345
- // case SDL_WINDOWEVENT_CLOSE:
346
- // event.type = SDL_QUIT;
347
- // SDL_PushEvent(&event);
348
- // continue;
349
- // case SDL_WINDOWEVENT_ENTER:
350
- // #if SDL_VERSION_ATLEAST(2, 0, 5)
351
- // case SDL_WINDOWEVENT_TAKE_FOCUS:
352
- // RDEVICE.OnWM_Activate(event.window.data1, event.window.data2);
353
- // continue;
354
- // #endif
355
- // default: SDL_Log("Window %d got unknown event %d", event.window.windowID, event.window.event); continue;
356
- // }
357
- // continue;
358
- case SDL_QUIT:
359
- Engine.Event .Defer (" KERNEL:disconnect" );
360
- Engine.Event .Defer (" KERNEL:quit" );
346
+ case SDL_QUIT: // go to outside event loop
347
+ event.type = SDL_QUIT;
348
+ SDL_PushEvent (&event);
349
+ b_break_cycle = TRUE ;
361
350
break ;
362
351
363
352
default : continue ;
364
353
}
354
+
355
+ if (b_break_cycle)
356
+ break ;
365
357
}
366
358
367
359
stats.FrameTime .End ();
@@ -380,9 +372,9 @@ void CInput::unacquire() {}
380
372
381
373
void CInput::acquire (const bool & exclusive)
382
374
{
383
- // pMouse->SetCooperativeLevel(Device.editor() ? Device.editor()->main_handle() : RDEVICE.m_sdlWnd,
375
+ // pMouse->SetCooperativeLevel(Device.editor() ? Device.editor()->main_handle() : RDEVICE.m_sdlWnd,
384
376
// (exclusive ? DISCL_EXCLUSIVE : DISCL_NONEXCLUSIVE) | DISCL_FOREGROUND | DISCL_NOWINKEY);
385
- // pMouse->Acquire();
377
+ // pMouse->Acquire();
386
378
}
387
379
388
380
void CInput::exclusive_mode (const bool & exclusive)
0 commit comments