X-Git-Url: https://git.artsoft.org/?a=blobdiff_plain;f=src%2Fevents.c;h=b5be2a1610394fd4e33fa3078d2e3e5124eeff8c;hb=de8b3ae622eae10f1caf96872fb1790f7bd9644b;hp=a46f3548117071086e8be052b6024e40e7c0647b;hpb=bb2ddcf13df18d69e4472d4697da173981970e9d;p=rocksndiamonds.git diff --git a/src/events.c b/src/events.c index a46f3548..b5be2a16 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-2002 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 "files.h" #include "tape.h" -#include "joystick.h" -#include "buttons.h" #include "network.h" /* values for key_status */ @@ -30,21 +30,54 @@ /* event filter especially needed for SDL event filtering due to - delay problems with lots of mouse motion events when mouse - button not pressed */ + delay problems with lots of mouse motion events when mouse button + not pressed (X11 can handle this with 'PointerMotionHintMask') */ -int EventFilter(const Event *event) +int FilterMouseMotionEvents(const Event *event) { + /* non-motion events are directly passed to event handler functions */ if (event->type != EVENT_MOTIONNOTIFY) return 1; - /* get mouse motion events without pressed button only in level editor */ + /* when playing, display a different mouse pointer inside the playfield */ + if (game_status == PLAYING) + { + static boolean inside_field = FALSE; + MotionEvent *motion = (MotionEvent *)event; + + if ((motion->x >= SX && motion->x < SX + SXSIZE && + motion->y >= SY && motion->y < SY + SYSIZE) != inside_field) + { + inside_field = !inside_field; + + SetMouseCursor(inside_field ? CURSOR_PLAYFIELD : CURSOR_DEFAULT); + } + } + + /* skip mouse motion events without pressed button outside level editor */ if (button_status == MB_RELEASED && game_status != LEVELED) return 0; else return 1; } +/* this is only really needed for non-SDL targets to filter unwanted events; + when using SDL with properly installed event filter, this function can be + replaced with a simple "NextEvent()" call, but it doesn't hurt either */ + +static boolean NextValidEvent(Event *event) +{ + while (PendingEvent()) + { + NextEvent(event); + + if (FilterMouseMotionEvents(event)) + return TRUE; + } + + return FALSE; +} + void EventLoop(void) { while(1) @@ -53,9 +86,7 @@ void EventLoop(void) { Event event; - NextEvent(&event); - - if (EventFilter(&event)) + if (NextValidEvent(&event)) { switch(event.type) { @@ -79,13 +110,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 */ @@ -109,7 +142,11 @@ void HandleOtherEvents(Event *event) break; case EVENT_UNMAPNOTIFY: +#if 0 + /* This causes the game to stop not only when iconified, but also + when on another virtual desktop, which might be not desired. */ SleepWhileUnmapped(); +#endif break; case EVENT_FOCUSIN: @@ -121,7 +158,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: @@ -159,6 +196,16 @@ void ClearEventQueue() } } +void ClearPlayerAction() +{ + int i; + + /* simulate key release events for still pressed keys */ + key_joystick_mapping = 0; + for (i=0; ix, y = event->y; - int width = event->width, height = event->height; - - if (setup.direct_draw && game_status==PLAYING) - { - int xx,yy; - int x1 = (x-SX)/TILEX, y1 = (y-SY)/TILEY; - int x2 = (x-SX+width)/TILEX, y2 = (y-SY+height)/TILEY; - - SetDrawtoField(DRAW_BACKBUFFER); - - for(xx=0; xx=x1 && xx<=x2 && yy>=y1 && yy<=y2) - DrawScreenField(xx,yy); - DrawAllPlayers(); - - SetDrawtoField(DRAW_DIRECT); - } - - if (setup.soft_scrolling && game_status == PLAYING) - { - int fx = FX, fy = FY; - - fx += (ScreenMovDir & (MV_LEFT|MV_RIGHT) ? ScreenGfxPos : 0); - fy += (ScreenMovDir & (MV_UP|MV_DOWN) ? ScreenGfxPos : 0); - - BlitBitmap(fieldbuffer, backbuffer, fx,fy, SXSIZE,SYSIZE, SX,SY); - } - - BlitBitmap(drawto, window, x,y, width,height, x,y); - +#ifndef TARGET_SDL + RedrawPlayfield(FALSE, event->x, event->y, event->width, event->height); FlushDisplay(); #endif } @@ -258,7 +274,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 @@ -283,16 +299,11 @@ void HandleFocusEvent(FocusChangeEvent *event) if (event->type == EVENT_FOCUSOUT) { - int i; - KeyboardAutoRepeatOn(); - old_joystick_status = joystick_status; - joystick_status = JOYSTICK_OFF; + old_joystick_status = joystick.status; + joystick.status = JOYSTICK_NOT_AVAILABLE; - /* simulate key release events for still pressed keys */ - key_joystick_mapping = 0; - for (i=0; itype == EVENT_FOCUSIN) { @@ -318,21 +329,14 @@ void HandleFocusEvent(FocusChangeEvent *event) KeyboardAutoRepeatOff(); } if (old_joystick_status != -1) - joystick_status = old_joystick_status; + joystick.status = old_joystick_status; } } 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 +364,7 @@ void HandleButton(int mx, int my, int button) break; case TYPENAME: - HandleTypeName(0, KEY_Return); + HandleTypeName(0, KSYM_Return); break; case CHOOSELEVEL: @@ -382,10 +386,6 @@ void HandleButton(int mx, int my, int button) HandleSetupScreen(mx,my, 0,0, button); break; - case SETUPINPUT: - HandleSetupInputScreen(mx,my, 0,0, button); - break; - case PLAYING: #ifdef DEBUG if (button == MB_RELEASED) @@ -424,6 +424,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 { @@ -442,6 +443,9 @@ void HandleKey(Key key, int key_status) if (game_status == PLAYING) { + /* only needed for single-step tape recording mode */ + static boolean clear_button_2[MAX_PLAYERS] = { FALSE,FALSE,FALSE,FALSE }; + static boolean bomb_placed[MAX_PLAYERS] = { FALSE,FALSE,FALSE,FALSE }; int pnr; for (pnr=0; pnrdynamite = 1000; break; @@ -709,7 +777,7 @@ void HandleKey(Key key, int key_status) #if 0 - case KEY_z: + case KSYM_z: { int i; @@ -738,7 +806,7 @@ void HandleKey(Key key, int key_status) } } -void HandleNoXEvent() +void HandleNoEvent() { if (button_status && game_status != PLAYING) { @@ -746,15 +814,12 @@ void HandleNoXEvent() return; } -#if !defined(MSDOS) && !defined(WIN32) +#if defined(PLATFORM_UNIX) if (options.network) HandleNetworking(); #endif HandleJoystick(); - - if (game_status == PLAYING) - HandleGameActions(); } static int HandleJoystickForAllPlayers() @@ -774,11 +839,9 @@ static int HandleJoystickForAllPlayers() joy_action = Joystick(i); result |= joy_action; - if (!setup.input[i].use_joystick) continue; - stored_player[i].action = joy_action; } @@ -804,7 +867,6 @@ void HandleJoystick() case MAINMENU: case CHOOSELEVEL: case SETUP: - case SETUPINPUT: { static unsigned long joystickmove_delay = 0; @@ -812,15 +874,12 @@ void HandleJoystick() !DelayReached(&joystickmove_delay, GADGET_FRAME_DELAY)) newbutton = dx = dy = 0; - if (game_status==MAINMENU) + if (game_status == MAINMENU) HandleMainMenu(0,0,dx,dy,newbutton ? MB_MENU_CHOICE : MB_MENU_MARK); - else if (game_status==CHOOSELEVEL) + else if (game_status == CHOOSELEVEL) HandleChooseLevel(0,0,dx,dy,newbutton ? MB_MENU_CHOICE : MB_MENU_MARK); - else if (game_status==SETUP) + 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; } @@ -832,6 +891,10 @@ void HandleJoystick() HandleHelpScreen(!newbutton); break; + case LEVELED: + HandleLevelEditorIdle(); + break; + case PLAYING: if (tape.playing || keyboard) newbutton = ((joy & JOY_BUTTON) != 0);