Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- moved some event related code to 'common'.
- Loading branch information
Showing
24 changed files
with
410 additions
and
237 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,198 @@ | ||
/* | ||
** c_dispatch.cpp | ||
** Functions for executing console commands and aliases | ||
** | ||
**--------------------------------------------------------------------------- | ||
** Copyright 1998-2016 Randy Heit | ||
** Copyright 2003-2019 Christoph Oelckers | ||
** All rights reserved. | ||
** | ||
** Redistribution and use in source and binary forms, with or without | ||
** modification, are permitted provided that the following conditions | ||
** are met: | ||
** | ||
** 1. Redistributions of source code must retain the above copyright | ||
** notice, this list of conditions and the following disclaimer. | ||
** 2. Redistributions in binary form must reproduce the above copyright | ||
** notice, this list of conditions and the following disclaimer in the | ||
** documentation and/or other materials provided with the distribution. | ||
** 3. The name of the author may not be used to endorse or promote products | ||
** derived from this software without specific prior written permission. | ||
** | ||
** THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR | ||
** IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | ||
** OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | ||
** IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, | ||
** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
** NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | ||
** THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
**--------------------------------------------------------------------------- | ||
** | ||
*/ | ||
|
||
#include "c_bind.h" | ||
#include "d_eventbase.h" | ||
#include "c_console.h" | ||
#include "d_gui.h" | ||
#include "menu.h" | ||
#include "utf8.h" | ||
#include "m_joy.h" | ||
#include "vm.h" | ||
|
||
bool G_Responder(event_t* ev); | ||
|
||
int eventhead; | ||
int eventtail; | ||
event_t events[MAXEVENTS]; | ||
|
||
//========================================================================== | ||
// | ||
// D_ProcessEvents | ||
// | ||
// Send all the events of the given timestamp down the responder chain. | ||
// Events are asynchronous inputs generally generated by the game user. | ||
// Events can be discarded if no responder claims them | ||
// | ||
//========================================================================== | ||
|
||
void D_ProcessEvents (void) | ||
{ | ||
event_t *ev; | ||
while (eventtail != eventhead) | ||
{ | ||
ev = &events[eventtail]; | ||
eventtail = (eventtail + 1) & (MAXEVENTS - 1); | ||
if (ev->type == EV_None) | ||
continue; | ||
if (ev->type == EV_DeviceChange) | ||
UpdateJoystickMenu(I_UpdateDeviceList()); | ||
if (C_Responder (ev)) | ||
continue; // console ate the event | ||
if (M_Responder (ev)) | ||
continue; // menu ate the event | ||
G_Responder (ev); | ||
} | ||
} | ||
|
||
//========================================================================== | ||
// | ||
// D_RemoveNextCharEvent | ||
// | ||
// Removes the next EV_GUI_Char event in the input queue. Used by the menu, | ||
// since it (generally) consumes EV_GUI_KeyDown events and not EV_GUI_Char | ||
// events, and it needs to ensure that there is no left over input when it's | ||
// done. If there are multiple EV_GUI_KeyDowns before the EV_GUI_Char, then | ||
// there are dead chars involved, so those should be removed, too. We do | ||
// this by changing the message type to EV_None rather than by actually | ||
// removing the event from the queue. | ||
// | ||
//========================================================================== | ||
|
||
void D_RemoveNextCharEvent() | ||
{ | ||
assert(events[eventtail].type == EV_GUI_Event && events[eventtail].subtype == EV_GUI_KeyDown); | ||
for (int evnum = eventtail; evnum != eventhead; evnum = (evnum+1) & (MAXEVENTS-1)) | ||
{ | ||
event_t *ev = &events[evnum]; | ||
if (ev->type != EV_GUI_Event) | ||
break; | ||
if (ev->subtype == EV_GUI_KeyDown || ev->subtype == EV_GUI_Char) | ||
{ | ||
ev->type = EV_None; | ||
if (ev->subtype == EV_GUI_Char) | ||
break; | ||
} | ||
else | ||
{ | ||
break; | ||
} | ||
} | ||
} | ||
|
||
|
||
FInputEvent::FInputEvent(const event_t *ev) | ||
{ | ||
Type = (EGenericEvent)ev->type; | ||
// we don't want the modders to remember what weird fields mean what for what events. | ||
KeyScan = 0; | ||
KeyChar = 0; | ||
MouseX = 0; | ||
MouseY = 0; | ||
switch (Type) | ||
{ | ||
case EV_None: | ||
break; | ||
case EV_KeyDown: | ||
case EV_KeyUp: | ||
KeyScan = ev->data1; | ||
KeyChar = ev->data2; | ||
KeyString = FString(char(ev->data1)); | ||
break; | ||
case EV_Mouse: | ||
MouseX = ev->x; | ||
MouseY = ev->y; | ||
break; | ||
default: | ||
break; // EV_DeviceChange = wat? | ||
} | ||
} | ||
|
||
FUiEvent::FUiEvent(const event_t *ev) | ||
{ | ||
Type = (EGUIEvent)ev->subtype; | ||
KeyChar = 0; | ||
IsShift = false; | ||
IsAlt = false; | ||
IsCtrl = false; | ||
MouseX = 0; | ||
MouseY = 0; | ||
// we don't want the modders to remember what weird fields mean what for what events. | ||
switch (ev->subtype) | ||
{ | ||
case EV_GUI_None: | ||
break; | ||
case EV_GUI_KeyDown: | ||
case EV_GUI_KeyRepeat: | ||
case EV_GUI_KeyUp: | ||
KeyChar = ev->data1; | ||
KeyString = FString(char(ev->data1)); | ||
IsShift = !!(ev->data3 & GKM_SHIFT); | ||
IsAlt = !!(ev->data3 & GKM_ALT); | ||
IsCtrl = !!(ev->data3 & GKM_CTRL); | ||
break; | ||
case EV_GUI_Char: | ||
KeyChar = ev->data1; | ||
KeyString = MakeUTF8(ev->data1); | ||
IsAlt = !!ev->data2; // only true for Win32, not sure about SDL | ||
break; | ||
default: // mouse event | ||
// note: SDL input doesn't seem to provide these at all | ||
//Printf("Mouse data: %d, %d, %d, %d\n", ev->x, ev->y, ev->data1, ev->data2); | ||
MouseX = ev->data1; | ||
MouseY = ev->data2; | ||
IsShift = !!(ev->data3 & GKM_SHIFT); | ||
IsAlt = !!(ev->data3 & GKM_ALT); | ||
IsCtrl = !!(ev->data3 & GKM_CTRL); | ||
break; | ||
} | ||
} | ||
|
||
DEFINE_FIELD_X(UiEvent, FUiEvent, Type); | ||
DEFINE_FIELD_X(UiEvent, FUiEvent, KeyString); | ||
DEFINE_FIELD_X(UiEvent, FUiEvent, KeyChar); | ||
DEFINE_FIELD_X(UiEvent, FUiEvent, MouseX); | ||
DEFINE_FIELD_X(UiEvent, FUiEvent, MouseY); | ||
DEFINE_FIELD_X(UiEvent, FUiEvent, IsShift); | ||
DEFINE_FIELD_X(UiEvent, FUiEvent, IsAlt); | ||
DEFINE_FIELD_X(UiEvent, FUiEvent, IsCtrl); | ||
|
||
DEFINE_FIELD_X(InputEvent, FInputEvent, Type); | ||
DEFINE_FIELD_X(InputEvent, FInputEvent, KeyScan); | ||
DEFINE_FIELD_X(InputEvent, FInputEvent, KeyString); | ||
DEFINE_FIELD_X(InputEvent, FInputEvent, KeyChar); | ||
DEFINE_FIELD_X(InputEvent, FInputEvent, MouseX); | ||
DEFINE_FIELD_X(InputEvent, FInputEvent, MouseY); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
#pragma once | ||
#include <stdint.h> | ||
#include "d_gui.h" | ||
|
||
// Input event types. | ||
enum EGenericEvent | ||
{ | ||
EV_None, | ||
EV_KeyDown, // data1: scan code, data2: Qwerty ASCII code | ||
EV_KeyUp, // same | ||
EV_Mouse, // x, y: mouse movement deltas | ||
EV_GUI_Event, // subtype specifies actual event | ||
EV_DeviceChange,// a device has been connected or removed | ||
}; | ||
|
||
// Event structure. | ||
struct event_t | ||
{ | ||
uint8_t type; | ||
uint8_t subtype; | ||
int16_t data1; // keys / mouse/joystick buttons | ||
int16_t data2; | ||
int16_t data3; | ||
int x; // mouse/joystick x move | ||
int y; // mouse/joystick y move | ||
}; | ||
|
||
|
||
|
||
// Called by IO functions when input is detected. | ||
void D_PostEvent (const event_t* ev); | ||
void D_RemoveNextCharEvent(); | ||
void D_ProcessEvents(void); | ||
|
||
enum | ||
{ | ||
MAXEVENTS = 128 | ||
}; | ||
|
||
extern event_t events[MAXEVENTS]; | ||
extern int eventhead; | ||
extern int eventtail; | ||
|
||
struct FUiEvent | ||
{ | ||
// this essentially translates event_t UI events to ZScript. | ||
EGUIEvent Type; | ||
// for keys/chars/whatever | ||
FString KeyString; | ||
int KeyChar; | ||
// for mouse | ||
int MouseX; | ||
int MouseY; | ||
// global (?) | ||
bool IsShift; | ||
bool IsCtrl; | ||
bool IsAlt; | ||
|
||
FUiEvent(const event_t *ev); | ||
}; | ||
|
||
struct FInputEvent | ||
{ | ||
// this translates regular event_t events to ZScript (not UI, UI events are sent via DUiEvent and only if requested!) | ||
EGenericEvent Type = EV_None; | ||
// for keys | ||
int KeyScan; | ||
FString KeyString; | ||
int KeyChar; | ||
// for mouse | ||
int MouseX; | ||
int MouseY; | ||
|
||
FInputEvent(const event_t *ev); | ||
}; | ||
|
Oops, something went wrong.