From 34043bdcc0d083d37610c9dcf2ff8cdfec725710 Mon Sep 17 00:00:00 2001 From: "K.Ohta" Date: Fri, 9 Jan 2015 16:37:29 +0900 Subject: [PATCH] [UI][Agar] Fix auto repeating problems. --- source/src/agar/common/agar_input.cpp | 45 +++++++--- source/src/agar/common/agar_main.cpp | 150 ++++++++++++++++++++++++++++++++-- source/src/agar/common/simd_types.h | 1 + 3 files changed, 176 insertions(+), 20 deletions(-) diff --git a/source/src/agar/common/agar_input.cpp b/source/src/agar/common/agar_input.cpp index 4dd91fff9..91b638354 100644 --- a/source/src/agar/common/agar_input.cpp +++ b/source/src/agar/common/agar_input.cpp @@ -7,6 +7,8 @@ [ win32 input ] */ +#include +#include #include "emu.h" #include "vm/vm.h" #include "fifo.h" @@ -14,6 +16,10 @@ #include "agar_input.h" #include "agar_main.h" +#ifndef Ulong +#define Ulong unsigned long +#endif + #define KEY_KEEP_FRAMES 3 extern "C" { @@ -137,30 +143,33 @@ const struct WIndowsKeyTable WindowsKeyMappings[] = { { 0xffff, 0xffff} }; + static int mouse_x = 0; static int mouse_y = 0; static int mouse_relx = 0; static int mouse_rely = 0; static uint32 mouse_buttons = 0; - - + + void ProcessKeyUp(AG_Event *event) { int key = AG_INT(1); int mod = AG_INT(2); - uint32_t unicode = AG_INT(3); -#ifdef USE_BUTTON + uint32_t unicode = AG_ULONG(3); + +//#ifdef USE_BUTTON emu->key_up(key); -#endif + +//#endif } void ProcessKeyDown(AG_Event *event) { int key = AG_INT(1); int mod = AG_INT(2); - uint32_t unicode = AG_INT(3); + uint32_t unicode = AG_ULONG(3); //#ifdef USE_BUTTON - emu->key_down(key, true); + emu->key_down(key, false); //#endif } @@ -370,8 +379,12 @@ void EMU::release_input() void EMU::update_input() { -#if 1 -#ifdef USE_SHIFT_NUMPAD_KEY + + int *keystat; + int i_c = 0;; + + +# ifdef USE_SHIFT_NUMPAD_KEY // update numpad key status if(key_shift_pressed && !key_shift_released) { if(key_status[VK_SHIFT] == 0) { @@ -497,7 +510,8 @@ void EMU::update_input() } } #endif - + +#if 0 #ifdef USE_AUTO_KEY // auto key switch(autokey_phase) { @@ -576,10 +590,10 @@ static const int numpad_table[256] = { void EMU::key_down(int sym, bool repeat) { - printf("KEY DOWN: %04x\n", sym); - bool keep_frames = true; + bool keep_frames = false; uint8 code; code = convert_AGKey2VK(sym); + //printf("Key down %03x %03x\n", sym, code); #if 1 if(code == VK_SHIFT) { if(GetAsyncKeyState(VK_LSHIFT) & 0x8000) key_status[VK_LSHIFT] = 0x80; @@ -638,7 +652,7 @@ void EMU::key_up(int sym) { uint8 code; code = convert_AGKey2VK(sym); - + //printf("Key up %03x %03x\n", sym, code); #if 1 if(code == VK_SHIFT) { #ifndef USE_SHIFT_NUMPAD_KEY @@ -651,7 +665,11 @@ void EMU::key_up(int sym) } else if(code == VK_MENU) { if(!(GetAsyncKeyState(VK_LMENU) & 0x8000)) key_status[VK_LMENU] &= 0x7f; if(!(GetAsyncKeyState(VK_RMENU) & 0x8000)) key_status[VK_RMENU] &= 0x7f; + } else { + key_status[code] &= 0x7f; + vm->key_up(code); } + #ifdef USE_SHIFT_NUMPAD_KEY if(code == VK_SHIFT) { key_shift_pressed = false; @@ -661,6 +679,7 @@ void EMU::key_up(int sym) key_converted[code] = 0; code = numpad_table[code]; } + #endif if(!(code == VK_SHIFT || code == VK_CONTROL || code == VK_MENU)) { code = keycode_conv[code]; diff --git a/source/src/agar/common/agar_main.cpp b/source/src/agar/common/agar_main.cpp index 465e71d8b..3b71ca957 100644 --- a/source/src/agar/common/agar_main.cpp +++ b/source/src/agar/common/agar_main.cpp @@ -16,6 +16,7 @@ #include "menu_common.h" #include "agar_gldraw.h" +#include #include @@ -335,14 +336,14 @@ bool InitInstance(void) InitGL_AG2(640, 400); hGLView->wid.flags |= (AG_WIDGET_CATCH_TAB | AG_WIDGET_NOSPACING); - AG_GLViewKeyupFn(hGLView, ProcessKeyUp, "%p", NULL); + AG_GLViewKeyupFn(hGLView, ProcessKeyUp, NULL); AG_GLViewKeydownFn(hGLView, ProcessKeyDown, NULL); AG_GLViewButtonupFn(hGLView, OnMouseMotion, NULL); AG_GLViewButtondownFn(hGLView, OnMouseButtonDown, NULL); AG_GLViewMotionFn(hGLView, OnMouseButtonUp, NULL); - AG_GLViewDrawFn(hGLView, AGEventDrawGL2, "%p", NULL); - AG_GLViewScaleFn(hGLView, AGEventScaleGL, "%p", NULL); - AG_GLViewOverlayFn(hGLView, AGEventOverlayGL, "%p", NULL); + AG_GLViewDrawFn(hGLView, AGEventDrawGL2, NULL); + AG_GLViewScaleFn(hGLView, AGEventScaleGL, NULL); + AG_GLViewOverlayFn(hGLView, AGEventOverlayGL, NULL); AG_RedrawOnTick(hGLView, 1000 / 30); // 30fps AG_WidgetFocus(AGWIDGET(hGLView)); @@ -351,7 +352,7 @@ bool InitInstance(void) hSDLView = AGAR_SDLViewNew(AGWIDGET(hBox), NULL, NULL); if(hSDLView == NULL) return false; hScreenWidget = AGWIDGET(hSDLView); - AGAR_SDLViewDrawFn(hSDLView, AGAR_SDLViewUpdateSrc, "%p", NULL); + AGAR_SDLViewDrawFn(hSDLView, AGAR_SDLViewUpdateSrc, NULL); AGAR_SDLViewSurfaceNew(hSDLView, 640, 400); AG_SetEvent(hSDLView, "key-up", ProcessKeyUp, NULL); AG_SetEvent(hSDLView, "key-down", ProcessKeyDown, NULL); @@ -484,6 +485,141 @@ void *EmuThread(void *arg) #endif +BOOL EventGuiSingle(AG_Driver *drv, AG_DriverEvent *ev) +{ + if(ev == NULL) return TRUE; + /* Retrieve the next queued event. */ + if (AG_ProcessEvent(drv, ev) == -1) return FALSE; + /* Forward the event to Agar. */ + return TRUE; +} + +void ConvertSDLEvent(AG_Driver *obj, SDL_Event *event, AG_DriverEvent *dev) +{ +// AG_SDL_GetNextEvent(void *obj, AG_DriverEvent *dev) + AG_Driver *drv = AGDRIVER(obj); + SDL_Event ev = *event; +// if(drv == NULL) return; + +// if(agDriverSw) { +// drv = &agDriverSw->_inherit; +// } else { +// +// } + + switch (ev.type) { + case SDL_MOUSEMOTION: + if(drv != NULL) AG_MouseMotionUpdate(drv->mouse, ev.motion.x, ev.motion.y); + dev->type = AG_DRIVER_MOUSE_MOTION; + dev->win = NULL; + dev->data.motion.x = ev.motion.x; + dev->data.motion.y = ev.motion.y; + break; + case SDL_MOUSEBUTTONUP: + if(drv != NULL) AG_MouseButtonUpdate(drv->mouse, AG_BUTTON_RELEASED, + ev.button.button); + dev->type = AG_DRIVER_MOUSE_BUTTON_UP; + dev->win = NULL; + dev->data.button.which = (AG_MouseButton)ev.button.button; + dev->data.button.x = ev.button.x; + dev->data.button.y = ev.button.y; + break; + case SDL_MOUSEBUTTONDOWN: + if(drv != NULL) AG_MouseButtonUpdate(drv->mouse, AG_BUTTON_PRESSED, + ev.button.button); + + dev->type = AG_DRIVER_MOUSE_BUTTON_DOWN; + dev->win = NULL; + dev->data.button.which = (AG_MouseButton)ev.button.button; + dev->data.button.x = ev.button.x; + dev->data.button.y = ev.button.y; + break; + case SDL_KEYDOWN: + if(drv != NULL) AG_KeyboardUpdate(drv->kbd, AG_KEY_PRESSED, + (AG_KeySym)ev.key.keysym.sym, + (Uint32)ev.key.keysym.unicode); + + dev->type = AG_DRIVER_KEY_DOWN; + dev->win = NULL; + dev->data.key.ks = (AG_KeySym)ev.key.keysym.sym; + dev->data.key.ucs = (Uint32)ev.key.keysym.unicode; + break; + case SDL_KEYUP: + if(drv != NULL) AG_KeyboardUpdate(drv->kbd, AG_KEY_RELEASED, + (AG_KeySym)ev.key.keysym.sym, + (Uint32)ev.key.keysym.unicode); + + dev->type = AG_DRIVER_KEY_UP; + dev->win = NULL; + dev->data.key.ks = (AG_KeySym)ev.key.keysym.sym; + dev->data.key.ucs = (Uint32)ev.key.keysym.unicode; + break; + case SDL_VIDEORESIZE: + dev->type = AG_DRIVER_VIDEORESIZE; + dev->win = NULL; + dev->data.videoresize.x = 0; + dev->data.videoresize.y = 0; + dev->data.videoresize.w = (int)ev.resize.w; + dev->data.videoresize.h = (int)ev.resize.h; + break; + case SDL_VIDEOEXPOSE: + dev->type = AG_DRIVER_EXPOSE; + dev->win = NULL; + break; + case SDL_QUIT: + case SDL_USEREVENT: + dev->type = AG_DRIVER_CLOSE; + dev->win = NULL; + break; + default: + dev->type = AG_DRIVER_UNKNOWN; + dev->win = NULL; + break; + } +} + + + +BOOL EventSDL(AG_Driver *drv) +{ +// SDL_Surface *p; + SDL_Event eventQueue; + AG_DriverEvent event; + + /* + * JoyStickなどはSDLが管理する + */ +// AG_SDL_GetNextEvent(void *obj, AG_DriverEvent *dev) + +// if(SDL_WasInit(SDL_INIT_JOYSTICK) != 0) { +// p = SDL_GetVideoSurface(); +// if(p == NULL) return TRUE; + while (SDL_PollEvent(&eventQueue)) +// if(SDL_PollEvent(&eventQueue)) + { + switch (eventQueue.type) + { + case SDL_JOYAXISMOTION: /* JS */ + //OnMoveJoy(&eventQueue); + break; + case SDL_JOYBUTTONDOWN: + //OnPressJoy(&eventQueue); + break; + case SDL_JOYBUTTONUP: + //OnReleaseJoy(&eventQueue); + break; + default: + ConvertSDLEvent(drv, &eventQueue, &event); + if(!EventGuiSingle(drv, &event)) return FALSE; + break; + } + } +// } + return TRUE; +} + + + void AGDrawTaskEvent(BOOL flag) { Uint32 nDrawTick2D; @@ -525,7 +661,7 @@ void AGDrawTaskEvent(BOOL flag) } if(fps < 10) fps = 10; // 10ms = 100fps. } - //if(EventSDL(NULL) == FALSE) return; + if(EventSDL(NULL) == FALSE) return; nDrawTick2D = AG_GetTicks(); if(nDrawTick2D < nDrawTick1D) nDrawTick1D = 0; // オーバーフロー対策 @@ -547,7 +683,7 @@ void AGDrawTaskEvent(BOOL flag) } if(AG_PendingEvents(NULL) != 0) { AG_DriverEvent dev; - //if(EventSDL(NULL) == FALSE) return; + if(EventSDL(NULL) == FALSE) return; if(AG_GetNextEvent(NULL, &dev) == 1) AG_ProcessEvent(NULL, &dev); // AG_Delay(1); } diff --git a/source/src/agar/common/simd_types.h b/source/src/agar/common/simd_types.h index bbe08aa50..51b3dfe0b 100644 --- a/source/src/agar/common/simd_types.h +++ b/source/src/agar/common/simd_types.h @@ -27,6 +27,7 @@ typedef int32_t Sint32; typedef int16_t Sint16; typedef int8_t Sint8; typedef int BOOL; + #define FALSE 0 #define TRUE 1 -- 2.11.0