X-Git-Url: https://git.artsoft.org/?a=blobdiff_plain;f=src%2Fevents.c;h=1e2ca16841661450886d719a2f701e0c8eea49be;hb=2ae6ae8ed951e87fcba7c363705cd6ddea8de91c;hp=e2f9db8ec530d9f93614a2ae27fb82cbfc39e2ba;hpb=41cfe645942062496cd063eb46e17d677a76c645;p=rocksndiamonds.git diff --git a/src/events.c b/src/events.c index e2f9db8e..1e2ca168 100644 --- a/src/events.c +++ b/src/events.c @@ -1,26 +1,26 @@ /*********************************************************** -* Rocks'n'Diamonds -- McDuffin Strikes Back! * +* Rocks'n'Diamonds -- McDuffin Strikes Back! * *----------------------------------------------------------* -* (c) 1995-98 Artsoft Entertainment * -* Holger Schemel * -* Oststrasse 11a * -* 33604 Bielefeld * -* phone: ++49 +521 290471 * -* email: aeglos@valinor.owl.de * +* (c) 1995-2000 Artsoft Entertainment * +* Holger Schemel * +* Detmolder Strasse 189 * +* 33604 Bielefeld * +* Germany * +* e-mail: info@artsoft.org * *----------------------------------------------------------* -* events.c * +* events.c * ***********************************************************/ +#include "libgame/libgame.h" + #include "events.h" #include "init.h" #include "screens.h" #include "tools.h" #include "game.h" #include "editor.h" -#include "misc.h" #include "tape.h" #include "joystick.h" -#include "buttons.h" #include "network.h" /* values for key_status */ @@ -33,7 +33,7 @@ delay problems with lots of mouse motion events when mouse button not pressed */ -int EventFilter(const Event *event) +int FilterMouseMotionEvents(const Event *event) { if (event->type != EVENT_MOTIONNOTIFY) return 1; @@ -55,7 +55,7 @@ void EventLoop(void) NextEvent(&event); - if (EventFilter(&event)) + if (FilterMouseMotionEvents(&event)) { switch(event.type) { @@ -79,13 +79,15 @@ void EventLoop(void) } } } - - HandleNoXEvent(); + else + HandleNoEvent(); /* 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) + if (game_status == PLAYING) + HandleGameActions(); + else { SyncDisplay(); if (!PendingEvent()) /* delay only if no pending events */ @@ -121,7 +123,7 @@ void HandleOtherEvents(Event *event) HandleClientMessageEvent((ClientMessageEvent *) event); break; -#ifdef USE_SDL_LIBRARY +#if defined(TARGET_SDL) case SDL_JOYAXISMOTION: case SDL_JOYBUTTONDOWN: case SDL_JOYBUTTONUP: @@ -204,7 +206,7 @@ void SleepWhileUnmapped() void HandleExposeEvent(ExposeEvent *event) { -#ifndef USE_SDL_LIBRARY +#ifndef TARGET_SDL int x = event->x, y = event->y; int width = event->width, height = event->height; @@ -258,7 +260,7 @@ void HandleMotionEvent(MotionEvent *event) if (!PointerInWindow(window)) return; /* window and pointer are on different screens */ -#if 0 +#if 1 if (button_status == MB_RELEASED && game_status != LEVELED) return; #endif @@ -324,15 +326,8 @@ void HandleFocusEvent(FocusChangeEvent *event) void HandleClientMessageEvent(ClientMessageEvent *event) { -#ifdef USE_SDL_LIBRARY - CloseAllAndExit(0); /* the only possible message here is SDL_QUIT */ -#else -#ifndef MSDOS - if ((event->window == window) && - (event->data.l[0] == XInternAtom(display, "WM_DELETE_WINDOW", FALSE))) + if (CheckCloseWindowEvent(event)) CloseAllAndExit(0); -#endif -#endif } void HandleButton(int mx, int my, int button) @@ -360,7 +355,7 @@ void HandleButton(int mx, int my, int button) break; case TYPENAME: - HandleTypeName(0, KEY_Return); + HandleTypeName(0, KSYM_Return); break; case CHOOSELEVEL: @@ -424,6 +419,7 @@ void HandleButton(int mx, int my, int button) void HandleKey(Key key, int key_status) { int joy = 0; + boolean anyTextGadgetActiveOrJustFinished = anyTextGadgetActive(); static struct SetupKeyboardInfo custom_key; static struct { @@ -489,7 +485,7 @@ void HandleKey(Key key, int key_status) if (key_status == KEY_RELEASED) return; - if ((key == KEY_Return || key == KEY_space) && + if ((key == KSYM_Return || key == KSYM_space) && game_status == PLAYING && AllPlayersGone) { CloseDoor(DOOR_CLOSE_1); @@ -499,7 +495,7 @@ void HandleKey(Key key, int key_status) } /* allow quick escape to the main menu with the Escape key */ - if (key == KEY_Escape && game_status != MAINMENU) + if (key == KSYM_Escape && game_status != MAINMENU) { CloseDoor(DOOR_CLOSE_1 | DOOR_OPEN_2 | DOOR_NO_DELAY); game_status = MAINMENU; @@ -532,8 +528,8 @@ void HandleKey(Key key, int key_status) case SETUPINPUT: switch(key) { - case KEY_Return: - case KEY_space: + case KSYM_Return: + case KSYM_space: if (game_status == MAINMENU) HandleMainMenu(0,0, 0,0, MB_MENU_CHOICE); else if (game_status == CHOOSELEVEL) @@ -544,12 +540,12 @@ void HandleKey(Key key, int key_status) HandleSetupInputScreen(0,0, 0,0, MB_MENU_CHOICE); break; - case KEY_Page_Up: + case KSYM_Page_Up: if (game_status == CHOOSELEVEL) HandleChooseLevel(0,0, 0,-SCR_FIELDY, MB_MENU_MARK); break; - case KEY_Page_Down: + case KSYM_Page_Down: if (game_status == CHOOSELEVEL) HandleChooseLevel(0,0, 0,SCR_FIELDY, MB_MENU_MARK); break; @@ -566,18 +562,18 @@ void HandleKey(Key key, int key_status) case HALLOFFAME: switch(key) { - case KEY_Return: - case KEY_space: + case KSYM_Return: + case KSYM_space: game_status = MAINMENU; DrawMainMenu(); BackToFront(); break; - case KEY_Page_Up: + case KSYM_Page_Up: HandleHallOfFame(0,0, 0,-SCR_FIELDY, MB_MENU_MARK); break; - case KEY_Page_Down: + case KSYM_Page_Down: HandleHallOfFame(0,0, 0,SCR_FIELDY, MB_MENU_MARK); break; @@ -587,7 +583,8 @@ void HandleKey(Key key, int key_status) break; case LEVELED: - HandleLevelEditorKeyInput(key); + if (!anyTextGadgetActiveOrJustFinished) + HandleLevelEditorKeyInput(key); break; case PLAYING: @@ -596,17 +593,17 @@ void HandleKey(Key key, int key_status) { #ifdef DEBUG - case KEY_0: - case KEY_1: - case KEY_2: - case KEY_3: - case KEY_4: - case KEY_5: - case KEY_6: - case KEY_7: - case KEY_8: - case KEY_9: - if (key == KEY_0) + case KSYM_0: + case KSYM_1: + case KSYM_2: + case KSYM_3: + case KSYM_4: + case KSYM_5: + case KSYM_6: + case KSYM_7: + case KSYM_8: + case KSYM_9: + if (key == KSYM_0) { if (GameFrameDelay == 500) GameFrameDelay = GAME_FRAME_DELAY; @@ -614,14 +611,46 @@ void HandleKey(Key key, int key_status) GameFrameDelay = 500; } else - GameFrameDelay = (key - KEY_0) * 10; + GameFrameDelay = (key - KSYM_0) * 10; printf("Game speed == %d%% (%d ms delay between two frames)\n", GAME_FRAME_DELAY * 100 / GameFrameDelay, GameFrameDelay); break; + case KSYM_d: + if (options.debug) + { + options.debug = FALSE; + printf("debug mode disabled\n"); + } + else + { + options.debug = TRUE; + printf("debug mode enabled\n"); + } + break; + + case KSYM_s: + if (!global.fps_slowdown) + { + global.fps_slowdown = TRUE; + global.fps_slowdown_factor = 2; + printf("fps slowdown enabled -- display only every 2nd frame\n"); + } + else if (global.fps_slowdown_factor == 2) + { + global.fps_slowdown_factor = 4; + printf("fps slowdown enabled -- display only every 4th frame\n"); + } + else + { + global.fps_slowdown = FALSE; + global.fps_slowdown_factor = 1; + printf("fps slowdown disabled\n"); + } + break; #if 0 - case KEY_a: + case KSYM_a: if (ScrollStepSize == TILEX/8) ScrollStepSize = TILEX/4; else @@ -631,7 +660,7 @@ void HandleKey(Key key, int key_status) #endif #if 0 - case KEY_m: + case KSYM_m: if (MoveSpeed == 8) { MoveSpeed = 4; @@ -646,30 +675,28 @@ void HandleKey(Key key, int key_status) break; #endif - case KEY_f: + case KSYM_f: ScrollStepSize = TILEX/8; printf("ScrollStepSize == %d (1/8)\n", ScrollStepSize); break; - case KEY_g: + case KSYM_g: ScrollStepSize = TILEX/4; printf("ScrollStepSize == %d (1/4)\n", ScrollStepSize); break; - case KEY_h: + case KSYM_h: ScrollStepSize = TILEX/2; printf("ScrollStepSize == %d (1/2)\n", ScrollStepSize); break; - case KEY_l: + case KSYM_l: ScrollStepSize = TILEX; printf("ScrollStepSize == %d (1/1)\n", ScrollStepSize); break; -#ifndef MSDOS - case KEY_Q: -#endif - case KEY_q: + case KSYM_Q: + case KSYM_q: local_player->dynamite = 1000; break; @@ -677,7 +704,7 @@ void HandleKey(Key key, int key_status) #if 0 - case KEY_z: + case KSYM_z: { int i; @@ -706,7 +733,7 @@ void HandleKey(Key key, int key_status) } } -void HandleNoXEvent() +void HandleNoEvent() { if (button_status && game_status != PLAYING) { @@ -714,15 +741,12 @@ void HandleNoXEvent() return; } -#ifndef MSDOS +#if defined(PLATFORM_UNIX) if (options.network) HandleNetworking(); #endif HandleJoystick(); - - if (game_status == PLAYING) - HandleGameActions(); } static int HandleJoystickForAllPlayers()