X-Git-Url: https://git.artsoft.org/?a=blobdiff_plain;f=src%2Fevents.c;h=a38a6ef0f96c40825db0d04fb710114ce5685c00;hb=a4d4e8e444b21b58dcc88b52ff22726c545142a4;hp=71d03604c22eb6081e1632232d3ffb852a5c9e41;hpb=2fe0fbc2a34fd4b50081f1829931dea3ca2c4c1c;p=rocksndiamonds.git diff --git a/src/events.c b/src/events.c index 71d03604..a38a6ef0 100644 --- a/src/events.c +++ b/src/events.c @@ -34,34 +34,40 @@ void EventLoop(void) switch(event.type) { - case Expose: - HandleExposeEvent((XExposeEvent *) &event); - break; - case UnmapNotify: - SleepWhileUnmapped(); - break; case ButtonPress: case ButtonRelease: HandleButtonEvent((XButtonEvent *) &event); break; + case MotionNotify: HandleMotionEvent((XMotionEvent *) &event); break; + case KeyPress: case KeyRelease: HandleKeyEvent((XKeyEvent *) &event); break; - case FocusIn: - case FocusOut: - HandleFocusEvent((XFocusChangeEvent *) &event); - break; - case ClientMessage: - HandleClientMessageEvent((XClientMessageEvent *) &event); - break; + default: + HandleOtherEvents(&event); break; } } + + HandleNoXEvent(); + + /* don't use all CPU time when idle; the main loop while playing + has its own synchronization and is CPU friendly, too */ + + if (game_status != PLAYING) + { + XSync(display, FALSE); + Delay(10); + } + + + +#if 0 else /* got no event, but don't be lazy... */ { HandleNoXEvent(); @@ -75,12 +81,41 @@ void EventLoop(void) Delay(10); } } +#endif + + if (game_status == EXITGAME) return; } } +void HandleOtherEvents(XEvent *event) +{ + switch(event->type) + { + case Expose: + HandleExposeEvent((XExposeEvent *) event); + break; + + case UnmapNotify: + SleepWhileUnmapped(); + break; + + case FocusIn: + case FocusOut: + HandleFocusEvent((XFocusChangeEvent *) event); + break; + + case ClientMessage: + HandleClientMessageEvent((XClientMessageEvent *) event); + break; + + default: + break; + } +} + void ClearEventQueue() { while(XPending(display)) @@ -91,26 +126,16 @@ void ClearEventQueue() switch(event.type) { - case Expose: - HandleExposeEvent((XExposeEvent *) &event); - break; - case UnmapNotify: - SleepWhileUnmapped(); - break; case ButtonRelease: button_status = MB_RELEASED; break; + case KeyRelease: key_joystick_mapping = 0; break; - case FocusIn: - case FocusOut: - HandleFocusEvent((XFocusChangeEvent *) &event); - break; - case ClientMessage: - HandleClientMessageEvent((XClientMessageEvent *) &event); - break; + default: + HandleOtherEvents(&event); break; } } @@ -118,7 +143,7 @@ void ClearEventQueue() void SleepWhileUnmapped() { - BOOL window_unmapped = TRUE; + boolean window_unmapped = TRUE; XAutoRepeatOn(display); @@ -130,22 +155,27 @@ void SleepWhileUnmapped() switch(event.type) { - case Expose: - HandleExposeEvent((XExposeEvent *) &event); - break; case ButtonRelease: button_status = MB_RELEASED; break; + case KeyRelease: key_joystick_mapping = 0; break; + case MapNotify: window_unmapped = FALSE; break; - case ClientMessage: - HandleClientMessageEvent((XClientMessageEvent *) &event); + + case UnmapNotify: + /* this is only to surely prevent the 'should not happen' case + * of recursively looping between 'SleepWhileUnmapped()' and + * 'HandleOtherEvents()' which usually calls this funtion. + */ break; + default: + HandleOtherEvents(&event); break; } } @@ -159,7 +189,7 @@ void HandleExposeEvent(XExposeEvent *event) int x = event->x, y = event->y; int width = event->width, height = event->height; - if (direct_draw_on && game_status==PLAYING) + if (setup.direct_draw_on && game_status==PLAYING) { int xx,yy; int x1 = (x-SX)/TILEX, y1 = (y-SY)/TILEY; @@ -176,7 +206,7 @@ void HandleExposeEvent(XExposeEvent *event) SetDrawtoField(DRAW_DIRECT); } - if (soft_scrolling_on && game_status == PLAYING) + if (setup.soft_scrolling_on && game_status == PLAYING) { int fx = FX, fy = FY; @@ -245,7 +275,7 @@ void HandleClientMessageEvent(XClientMessageEvent *event) { if ((event->window == window) && (event->data.l[0] == XInternAtom(display, "WM_DELETE_WINDOW", FALSE))) - game_status = EXITGAME; + CloseAllAndExit(0); } void HandleButton(int mx, int my, int button) @@ -295,27 +325,45 @@ void HandleButton(int mx, int my, int button) case MAINMENU: HandleMainMenu(mx,my,0,0,button); break; + case TYPENAME: HandleTypeName(0,XK_Return); break; + case CHOOSELEVEL: HandleChooseLevel(mx,my,0,0,button); break; + case HALLOFFAME: HandleHallOfFame(button); break; + case LEVELED: LevelEd(mx,my,button); break; + case HELPSCREEN: HandleHelpScreen(button); break; + case SETUP: HandleSetupScreen(mx,my,0,0,button); break; + + case SETUPINPUT: + HandleSetupInputScreen(mx,my,0,0,button); + break; + case PLAYING: + + /* --> NoXEvent() will follow */ + + /* HandleGameActions(0); + */ + break; + default: break; } @@ -340,6 +388,7 @@ void HandleKey(KeySym key, int key_status) case XK_j: joy |= JOY_LEFT; break; + case XK_Right: #ifdef XK_KP_Right case XK_KP_Right: @@ -351,6 +400,7 @@ void HandleKey(KeySym key, int key_status) case XK_k: joy |= JOY_RIGHT; break; + case XK_Up: #ifdef XK_KP_Up case XK_KP_Up: @@ -362,6 +412,7 @@ void HandleKey(KeySym key, int key_status) case XK_i: joy |= JOY_UP; break; + case XK_Down: #ifdef XK_KP_Down case XK_KP_Down: @@ -373,54 +424,63 @@ void HandleKey(KeySym key, int key_status) case XK_m: joy |= JOY_DOWN; break; + #ifdef XK_KP_Home case XK_KP_Home: /* Diagonalrichtungen */ #endif case XK_KP_7: joy |= JOY_UP | JOY_LEFT; break; + #ifdef XK_KP_Page_Up case XK_KP_Page_Up: #endif case XK_KP_9: joy = JOY_UP | JOY_RIGHT; break; + #ifdef XK_KP_End case XK_KP_End: #endif case XK_KP_1: joy |= JOY_DOWN | JOY_LEFT; break; + #ifdef XK_KP_Page_Down case XK_KP_Page_Down: #endif case XK_KP_3: joy |= JOY_DOWN | JOY_RIGHT; break; + #ifndef MSDOS case XK_S: /* Feld entfernen */ #endif case XK_s: joy |= JOY_BUTTON_1 | JOY_LEFT; break; + #ifndef MSDOS case XK_D: #endif case XK_d: joy |= JOY_BUTTON_1 | JOY_RIGHT; break; + #ifndef MSDOS case XK_E: #endif case XK_e: joy |= JOY_BUTTON_1 | JOY_UP; break; + #ifndef MSDOS case XK_X: #endif case XK_x: joy |= JOY_BUTTON_1 | JOY_DOWN; break; + case XK_Shift_L: /* Linker Feuerknopf */ #ifndef MSDOS case XK_Control_L: @@ -429,6 +489,7 @@ void HandleKey(KeySym key, int key_status) #endif joy |= JOY_BUTTON_1; break; + case XK_Shift_R: /* Rechter Feuerknopf */ #ifndef MSDOS case XK_Control_R: @@ -441,6 +502,7 @@ void HandleKey(KeySym key, int key_status) case XK_b: joy |= JOY_BUTTON_2; break; + default: break; } @@ -485,10 +547,11 @@ void HandleKey(KeySym key, int key_status) case TYPENAME: HandleTypeName(0,key); break; + case MAINMENU: case CHOOSELEVEL: case SETUP: - { + case SETUPINPUT: switch(key) { case XK_Return: @@ -498,15 +561,19 @@ void HandleKey(KeySym key, int key_status) HandleChooseLevel(0,0,0,0,MB_MENU_CHOICE); else if (game_status==SETUP) HandleSetupScreen(0,0,0,0,MB_MENU_CHOICE); + else if (game_status==SETUPINPUT) + HandleSetupInputScreen(0,0,0,0,MB_MENU_CHOICE); break; + default: break; } break; - } + case HELPSCREEN: HandleHelpScreen(MB_RELEASED); break; + case HALLOFFAME: switch(key) { @@ -515,13 +582,16 @@ void HandleKey(KeySym key, int key_status) DrawMainMenu(); BackToFront(); break; + default: break; } break; + case LEVELED: LevelNameTyping(key); break; + case PLAYING: { switch(key) @@ -558,14 +628,17 @@ void HandleKey(KeySym key, int key_status) ScrollStepSize = TILEX/8; printf("ScrollStepSize == %d (1/8)\n", ScrollStepSize); break; + case XK_g: ScrollStepSize = TILEX/4; printf("ScrollStepSize == %d (1/4)\n", ScrollStepSize); break; + case XK_h: ScrollStepSize = TILEX/2; printf("ScrollStepSize == %d (1/2)\n", ScrollStepSize); break; + case XK_l: ScrollStepSize = TILEX; printf("ScrollStepSize == %d (1/1)\n", ScrollStepSize); @@ -648,7 +721,7 @@ void HandleKey(KeySym key, int key_status) } */ - printf("direct_draw_on == %d\n", direct_draw_on); + printf("direct_draw_on == %d\n", setup.direct_draw_on); break; @@ -702,7 +775,8 @@ void HandleNoXEvent() return; } - HandleNetworking(); + if (options.network) + HandleNetworking(); switch(game_status) { @@ -711,8 +785,10 @@ void HandleNoXEvent() case HALLOFFAME: case HELPSCREEN: case SETUP: + case SETUPINPUT: HandleJoystick(); break; + case PLAYING: HandleJoystick(); @@ -721,6 +797,7 @@ void HandleNoXEvent() */ break; + default: break; } @@ -730,11 +807,6 @@ void HandleJoystick() { int joystick = Joystick(); int keyboard = key_joystick_mapping; - - /* - int joy = (tape.playing ? TapePlayAction() : (joystick | keyboard)); - */ - int joy = (joystick | keyboard); int left = joy & JOY_LEFT; int right = joy & JOY_RIGHT; @@ -750,10 +822,11 @@ void HandleJoystick() case MAINMENU: case CHOOSELEVEL: case SETUP: + case SETUPINPUT: { static long joystickmove_delay = 0; - if (joystick && !button && !DelayReached(&joystickmove_delay,15)) + if (joystick && !button && !DelayReached(&joystickmove_delay,150)) newbutton = dx = dy = 0; if (game_status==MAINMENU) @@ -762,6 +835,9 @@ void HandleJoystick() HandleChooseLevel(0,0,dx,dy,newbutton ? MB_MENU_CHOICE : MB_MENU_MARK); else if (game_status==SETUP) HandleSetupScreen(0,0,dx,dy,newbutton ? MB_MENU_CHOICE : MB_MENU_MARK); + else if (game_status==SETUPINPUT) + HandleSetupInputScreen(0,0,dx,dy, + newbutton ? MB_MENU_CHOICE : MB_MENU_MARK); break; } @@ -788,11 +864,6 @@ void HandleJoystick() if (tape.pausing || AllPlayersGone) joy = 0; - /* - if (!network_player_action_stored) - SendToServer_MovePlayer(joy, 0); - */ - HandleGameActions((byte)joy); break;