29 #include YFM_YCLib_Input
30 #include YFM_YCLib_NativeAPI
31 #if YF_Multithread == 1
34 # define YCL_Def_LockGuard(_lck, _mutex) \
35 std::lock_guard<std::mutex> _lck(_mutex);
37 # define YCL_Def_LockGuard(...)
40 # include <android/input.h>
65 #if YCL_KEYSTATE_DIRECT
77 #if YF_Multithread == 1
78 std::mutex CompKeyMutex;
83 std::mutex CursorMutex;
86 float LastCursorPosX, LastCursorPosY;
102 return *pOldKeyState;
108 FetchKeyDownStateRaw()
110 return FetchKeyStateRef() & ~FetchOldKeyStateRef();
116 return (FetchKeyStateRef() ^ FetchOldKeyStateRef()) & ~FetchKeyStateRef();
127 return FetchKeyStateRef();
135 return FetchOldKeyStateRef();
143 return FetchKeyDownStateRaw();
151 return FetchKeyUpStateRaw();
163 yunseq(pKeyState->reset(), pOldKeyState->reset());
174 #if YCL_KEYSTATE_DIRECT
175 OldKeyState = KeyState;
180 KeyState = ::keysCurrent();
183 for(
std::size_t i(1); i < platform::KeyBitsetWidth - 1; ++i)
184 pKeyState->set(i, ::GetAsyncKeyState(i) & 0x8000);
191 std::pair<std::int16_t, std::int16_t>
194 using pr_type = std::pair<std::int16_t, std::int16_t>;
199 return YB_LIKELY(tp.px != 0 && tp.py != 0) ? pr_type(tp.px - 1, tp.py - 1)
219 return WaitForKey(KEY_TOUCH | KEY_A | KEY_B | KEY_X | KEY_Y
220 | KEY_LEFT | KEY_RIGHT | KEY_UP | KEY_DOWN
221 | KEY_START | KEY_SELECT);
227 return WaitForKey(KEY_A | KEY_B | KEY_X | KEY_Y
228 | KEY_LEFT | KEY_RIGHT | KEY_UP | KEY_DOWN
229 | KEY_START | KEY_SELECT);
235 return WaitForKey(KEY_LEFT | KEY_RIGHT | KEY_UP | KEY_DOWN);
241 return WaitForKey(KEY_A | KEY_B | KEY_X | KEY_Y);
244 std::pair<float, float>
249 return {LastCursorPosX, LastCursorPosY};
253 SaveInput(const ::AInputEvent& e)
255 const auto update_key([](std::int32_t action,
const std::uint8_t keycode){
262 case ::AKEY_EVENT_ACTION_DOWN:
263 case ::AKEY_EVENT_ACTION_UP:
264 FetchKeyStateRef().set(keycode,
265 action == ::AKEY_EVENT_ACTION_DOWN);
267 case ::AKEY_EVENT_ACTION_MULTIPLE:
273 switch(::AInputEvent_getType(&e))
275 case AINPUT_EVENT_TYPE_KEY:
276 if(~::AKeyEvent_getFlags(&e) & ::AKEY_EVENT_FLAG_CANCELED)
277 update_key(::AKeyEvent_getAction(&e),
278 ::AKeyEvent_getKeyCode(&e) & 0xFF);
280 case AINPUT_EVENT_TYPE_MOTION:
287 if(::AMotionEvent_getFlags(&e) != AMOTION_EVENT_FLAG_WINDOW_IS_OBSCURED)
288 switch(::AKeyEvent_getAction(&e) & AMOTION_EVENT_ACTION_MASK)
290 case AMOTION_EVENT_ACTION_CANCEL:
299 yunseq(LastCursorPosX = ::AMotionEvent_getRawX(&e, 0),
300 LastCursorPosY = ::AMotionEvent_getRawY(&e, 0));
YF_API const platform::KeyInput & FetchKeyState()
取按键状态。
YF_API const platform::KeyInput & FetchOldKeyState()
取上一次更新的按键状态。
void swap(any &x, any &y)
交换对象。
YF_API void WaitForInput()
等待任意按键。
#define yunseq
无序列依赖表达式组求值。
#define YAssertNonnull(_expr)
YF_API platform::KeyInput FetchKeyUpState()
取键释放状态。
YF_API void ClearKeyStates()
清除按键缓冲。
YF_API platform::KeyInput FetchKeyDownState()
取键按下状态。
#define YCL_Def_LockGuard(...)
YF_API void UpdateKeyStates()
更新按键状态。
std::bitset< KeyBitsetWidth > KeyInput
按键并行位宽。