OSDN Git Service

[UI][Agar] Fix auto repeating problems.
authorK.Ohta <whatisthis.sowhat@gmail.com>
Fri, 9 Jan 2015 07:37:29 +0000 (16:37 +0900)
committerK.Ohta <whatisthis.sowhat@gmail.com>
Fri, 9 Jan 2015 07:37:29 +0000 (16:37 +0900)
source/src/agar/common/agar_input.cpp
source/src/agar/common/agar_main.cpp
source/src/agar/common/simd_types.h

index 4dd91ff..91b6383 100644 (file)
@@ -7,6 +7,8 @@
        [ win32 input ]
 */
 
+#include <agar/core.h>
+#include <agar/gui.h>
 #include "emu.h"
 #include "vm/vm.h"
 #include "fifo.h"
 #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];
index 465e71d..3b71ca9 100644 (file)
@@ -16,6 +16,7 @@
 #include "menu_common.h"\r
 #include "agar_gldraw.h"\r
 \r
+#include <SDL/SDL.h>\r
 #include <agar/dev.h>\r
 \r
 \r
@@ -335,14 +336,14 @@ bool InitInstance(void)
       InitGL_AG2(640, 400);\r
       hGLView->wid.flags |= (AG_WIDGET_CATCH_TAB | AG_WIDGET_NOSPACING);\r
 \r
-      AG_GLViewKeyupFn(hGLView, ProcessKeyUp, "%p", NULL);\r
+      AG_GLViewKeyupFn(hGLView, ProcessKeyUp,  NULL);\r
       AG_GLViewKeydownFn(hGLView, ProcessKeyDown, NULL);\r
       AG_GLViewButtonupFn(hGLView,  OnMouseMotion, NULL);\r
       AG_GLViewButtondownFn(hGLView, OnMouseButtonDown, NULL);\r
       AG_GLViewMotionFn(hGLView,  OnMouseButtonUp, NULL);\r
-      AG_GLViewDrawFn(hGLView, AGEventDrawGL2, "%p", NULL);\r
-      AG_GLViewScaleFn(hGLView, AGEventScaleGL, "%p", NULL);\r
-      AG_GLViewOverlayFn(hGLView, AGEventOverlayGL, "%p", NULL);\r
+      AG_GLViewDrawFn(hGLView, AGEventDrawGL2, NULL);\r
+      AG_GLViewScaleFn(hGLView, AGEventScaleGL, NULL);\r
+      AG_GLViewOverlayFn(hGLView, AGEventOverlayGL, NULL);\r
        \r
       AG_RedrawOnTick(hGLView, 1000 / 30); // 30fps\r
       AG_WidgetFocus(AGWIDGET(hGLView));\r
@@ -351,7 +352,7 @@ bool InitInstance(void)
       hSDLView = AGAR_SDLViewNew(AGWIDGET(hBox), NULL, NULL);\r
       if(hSDLView == NULL) return false;\r
       hScreenWidget = AGWIDGET(hSDLView);\r
-      AGAR_SDLViewDrawFn(hSDLView, AGAR_SDLViewUpdateSrc, "%p", NULL);\r
+      AGAR_SDLViewDrawFn(hSDLView, AGAR_SDLViewUpdateSrc, NULL);\r
       AGAR_SDLViewSurfaceNew(hSDLView, 640, 400);\r
       AG_SetEvent(hSDLView, "key-up", ProcessKeyUp, NULL);\r
       AG_SetEvent(hSDLView, "key-down", ProcessKeyDown, NULL);\r
@@ -484,6 +485,141 @@ void *EmuThread(void *arg)
 #endif\r
 \r
 \r
+BOOL EventGuiSingle(AG_Driver *drv, AG_DriverEvent *ev)\r
+{\r
+   if(ev == NULL) return TRUE;\r
+   /* Retrieve the next queued event. */\r
+   if (AG_ProcessEvent(drv, ev) == -1)         return FALSE;\r
+   /* Forward the event to Agar. */\r
+   return TRUE;\r
+}\r
+\r
+void ConvertSDLEvent(AG_Driver *obj, SDL_Event *event, AG_DriverEvent *dev)\r
+{\r
+//     AG_SDL_GetNextEvent(void *obj, AG_DriverEvent *dev)\r
+       AG_Driver *drv = AGDRIVER(obj);\r
+       SDL_Event ev = *event;\r
+//        if(drv == NULL) return;\r
+\r
+//     if(agDriverSw) {\r
+//             drv = &agDriverSw->_inherit;\r
+//     } else {\r
+//\r
+//     }\r
+\r
+       switch (ev.type) {\r
+        case SDL_MOUSEMOTION:\r
+               if(drv != NULL) AG_MouseMotionUpdate(drv->mouse, ev.motion.x, ev.motion.y);\r
+               dev->type = AG_DRIVER_MOUSE_MOTION;\r
+               dev->win = NULL;\r
+               dev->data.motion.x = ev.motion.x;\r
+               dev->data.motion.y = ev.motion.y;\r
+               break;\r
+       case SDL_MOUSEBUTTONUP:\r
+               if(drv != NULL) AG_MouseButtonUpdate(drv->mouse, AG_BUTTON_RELEASED,\r
+                               ev.button.button);\r
+               dev->type = AG_DRIVER_MOUSE_BUTTON_UP;\r
+               dev->win = NULL;\r
+               dev->data.button.which = (AG_MouseButton)ev.button.button;\r
+               dev->data.button.x = ev.button.x;\r
+               dev->data.button.y = ev.button.y;\r
+               break;\r
+       case SDL_MOUSEBUTTONDOWN:\r
+               if(drv != NULL) AG_MouseButtonUpdate(drv->mouse, AG_BUTTON_PRESSED,\r
+                               ev.button.button);\r
+\r
+               dev->type = AG_DRIVER_MOUSE_BUTTON_DOWN;\r
+               dev->win = NULL;\r
+               dev->data.button.which = (AG_MouseButton)ev.button.button;\r
+               dev->data.button.x = ev.button.x;\r
+               dev->data.button.y = ev.button.y;\r
+               break;\r
+       case SDL_KEYDOWN:\r
+               if(drv != NULL) AG_KeyboardUpdate(drv->kbd, AG_KEY_PRESSED,\r
+                               (AG_KeySym)ev.key.keysym.sym,\r
+                               (Uint32)ev.key.keysym.unicode);\r
+\r
+               dev->type = AG_DRIVER_KEY_DOWN;\r
+               dev->win = NULL;\r
+               dev->data.key.ks = (AG_KeySym)ev.key.keysym.sym;\r
+               dev->data.key.ucs = (Uint32)ev.key.keysym.unicode;\r
+               break;\r
+       case SDL_KEYUP:\r
+               if(drv != NULL) AG_KeyboardUpdate(drv->kbd, AG_KEY_RELEASED,\r
+                               (AG_KeySym)ev.key.keysym.sym,\r
+                               (Uint32)ev.key.keysym.unicode);\r
+\r
+               dev->type = AG_DRIVER_KEY_UP;\r
+               dev->win = NULL;\r
+               dev->data.key.ks = (AG_KeySym)ev.key.keysym.sym;\r
+               dev->data.key.ucs = (Uint32)ev.key.keysym.unicode;\r
+               break;\r
+        case SDL_VIDEORESIZE:\r
+               dev->type = AG_DRIVER_VIDEORESIZE;\r
+               dev->win = NULL;\r
+               dev->data.videoresize.x = 0;\r
+               dev->data.videoresize.y = 0;\r
+               dev->data.videoresize.w = (int)ev.resize.w;\r
+               dev->data.videoresize.h = (int)ev.resize.h;\r
+               break;\r
+       case SDL_VIDEOEXPOSE:\r
+               dev->type = AG_DRIVER_EXPOSE;\r
+               dev->win = NULL;\r
+               break;\r
+       case SDL_QUIT:\r
+       case SDL_USEREVENT:\r
+               dev->type = AG_DRIVER_CLOSE;\r
+               dev->win = NULL;\r
+               break;\r
+        default:\r
+               dev->type = AG_DRIVER_UNKNOWN;\r
+               dev->win = NULL;\r
+               break;\r
+       }\r
+}\r
+\r
+\r
+\r
+BOOL EventSDL(AG_Driver *drv)\r
+{\r
+//     SDL_Surface *p;\r
+       SDL_Event eventQueue;\r
+       AG_DriverEvent event;\r
+\r
+       /*\r
+        * JoyStickなどはSDLが管理する\r
+        */\r
+//     AG_SDL_GetNextEvent(void *obj, AG_DriverEvent *dev)\r
+\r
+//     if(SDL_WasInit(SDL_INIT_JOYSTICK) != 0) {\r
+//             p = SDL_GetVideoSurface();\r
+//             if(p == NULL) return TRUE;\r
+               while (SDL_PollEvent(&eventQueue))\r
+//             if(SDL_PollEvent(&eventQueue))\r
+               {\r
+                       switch (eventQueue.type)\r
+                       {\r
+                       case SDL_JOYAXISMOTION: /* JS */\r
+                               //OnMoveJoy(&eventQueue);\r
+                               break;\r
+                       case SDL_JOYBUTTONDOWN:\r
+                               //OnPressJoy(&eventQueue);\r
+                               break;\r
+                       case SDL_JOYBUTTONUP:\r
+                               //OnReleaseJoy(&eventQueue);\r
+                               break;\r
+                       default:\r
+                               ConvertSDLEvent(drv, &eventQueue, &event);\r
+                               if(!EventGuiSingle(drv, &event)) return FALSE;\r
+                               break;\r
+                       }\r
+               }\r
+//     }\r
+       return TRUE;\r
+}\r
+\r
+\r
+\r
 void AGDrawTaskEvent(BOOL flag)\r
 {\r
    Uint32 nDrawTick2D;\r
@@ -525,7 +661,7 @@ void AGDrawTaskEvent(BOOL flag)
         }\r
         if(fps < 10) fps = 10; // 10ms = 100fps.\r
       }\r
-      //if(EventSDL(NULL) == FALSE) return;\r
+      if(EventSDL(NULL) == FALSE) return;\r
       nDrawTick2D = AG_GetTicks();\r
 \r
       if(nDrawTick2D < nDrawTick1D) nDrawTick1D = 0; // オーバーフロー対策\r
@@ -547,7 +683,7 @@ void AGDrawTaskEvent(BOOL flag)
       } \r
       if(AG_PendingEvents(NULL) != 0) {\r
         AG_DriverEvent dev;\r
-        //if(EventSDL(NULL) == FALSE) return;\r
+        if(EventSDL(NULL) == FALSE) return;\r
         if(AG_GetNextEvent(NULL, &dev) == 1) AG_ProcessEvent(NULL, &dev);\r
 //      AG_Delay(1);\r
       }\r
index bbe08aa..51b3dfe 100644 (file)
@@ -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