Cleanup input.h
This commit is contained in:
parent
1c73fb7240
commit
32c7883f82
87
src/input.cc
87
src/input.cc
|
@ -5,6 +5,7 @@
|
||||||
#include "audio_engine.h"
|
#include "audio_engine.h"
|
||||||
#include "color.h"
|
#include "color.h"
|
||||||
#include "core.h"
|
#include "core.h"
|
||||||
|
#include "dinput.h"
|
||||||
#include "draw.h"
|
#include "draw.h"
|
||||||
#include "kb.h"
|
#include "kb.h"
|
||||||
#include "memory.h"
|
#include "memory.h"
|
||||||
|
@ -15,24 +16,52 @@
|
||||||
|
|
||||||
namespace fallout {
|
namespace fallout {
|
||||||
|
|
||||||
|
typedef struct InputEvent {
|
||||||
|
// This is either logical key or input event id, which can be either
|
||||||
|
// character code pressed or some other numbers used throughout the
|
||||||
|
// game interface.
|
||||||
|
int logicalKey;
|
||||||
|
int mouseX;
|
||||||
|
int mouseY;
|
||||||
|
} InputEvent;
|
||||||
|
|
||||||
|
typedef struct RepeatInfo {
|
||||||
|
// Time when appropriate key was pressed down or -1 if it's up.
|
||||||
|
int tick;
|
||||||
|
int repeatCount;
|
||||||
|
} RepeatInfo;
|
||||||
|
|
||||||
|
typedef struct TickerListNode {
|
||||||
|
int flags;
|
||||||
|
TickerProc* proc;
|
||||||
|
struct TickerListNode* next;
|
||||||
|
} TickerListNode;
|
||||||
|
|
||||||
|
static int dequeueInputEvent();
|
||||||
|
static void pauseGame();
|
||||||
|
static int pauseHandlerDefaultImpl();
|
||||||
|
static void screenshotBlitter(unsigned char* src, int src_pitch, int a3, int x, int y, int width, int height, int dest_x, int dest_y);
|
||||||
|
static void buildNormalizedQwertyKeys();
|
||||||
|
static void _GNW95_process_key(KeyboardData* data);
|
||||||
|
|
||||||
static void idleImpl();
|
static void idleImpl();
|
||||||
|
|
||||||
// 0x51E234
|
// 0x51E234
|
||||||
IdleFunc* _idle_func = NULL;
|
static IdleFunc* _idle_func = NULL;
|
||||||
|
|
||||||
// 0x51E238
|
// 0x51E238
|
||||||
FocusFunc* _focus_func = NULL;
|
static FocusFunc* _focus_func = NULL;
|
||||||
|
|
||||||
// 0x51E23C
|
// 0x51E23C
|
||||||
int gKeyboardKeyRepeatRate = 80;
|
static int gKeyboardKeyRepeatRate = 80;
|
||||||
|
|
||||||
// 0x51E240
|
// 0x51E240
|
||||||
int gKeyboardKeyRepeatDelay = 500;
|
static int gKeyboardKeyRepeatDelay = 500;
|
||||||
|
|
||||||
// A map of SDL_SCANCODE_* constants normalized for QWERTY keyboard.
|
// A map of SDL_SCANCODE_* constants normalized for QWERTY keyboard.
|
||||||
//
|
//
|
||||||
// 0x6ABC70
|
// 0x6ABC70
|
||||||
int gNormalizedQwertyKeys[SDL_NUM_SCANCODES];
|
static int gNormalizedQwertyKeys[SDL_NUM_SCANCODES];
|
||||||
|
|
||||||
// Ring buffer of input events.
|
// Ring buffer of input events.
|
||||||
//
|
//
|
||||||
|
@ -40,52 +69,52 @@ int gNormalizedQwertyKeys[SDL_NUM_SCANCODES];
|
||||||
// buffer is full it will not overwrite values until they are dequeued.
|
// buffer is full it will not overwrite values until they are dequeued.
|
||||||
//
|
//
|
||||||
// 0x6ABD70
|
// 0x6ABD70
|
||||||
InputEvent gInputEventQueue[40];
|
static InputEvent gInputEventQueue[40];
|
||||||
|
|
||||||
// 0x6ABF50
|
// 0x6ABF50
|
||||||
STRUCT_6ABF50 _GNW95_key_time_stamps[SDL_NUM_SCANCODES];
|
static RepeatInfo _GNW95_key_time_stamps[SDL_NUM_SCANCODES];
|
||||||
|
|
||||||
// 0x6AC750
|
// 0x6AC750
|
||||||
int _input_mx;
|
static int _input_mx;
|
||||||
|
|
||||||
// 0x6AC754
|
// 0x6AC754
|
||||||
int _input_my;
|
static int _input_my;
|
||||||
|
|
||||||
// 0x6AC75C
|
// 0x6AC75C
|
||||||
bool gPaused;
|
static bool gPaused;
|
||||||
|
|
||||||
// 0x6AC760
|
// 0x6AC760
|
||||||
int gScreenshotKeyCode;
|
static int gScreenshotKeyCode;
|
||||||
|
|
||||||
// 0x6AC764
|
// 0x6AC764
|
||||||
int _using_msec_timer;
|
static int _using_msec_timer;
|
||||||
|
|
||||||
// 0x6AC768
|
// 0x6AC768
|
||||||
int gPauseKeyCode;
|
static int gPauseKeyCode;
|
||||||
|
|
||||||
// 0x6AC76C
|
// 0x6AC76C
|
||||||
ScreenshotHandler* gScreenshotHandler;
|
static ScreenshotHandler* gScreenshotHandler;
|
||||||
|
|
||||||
// 0x6AC770
|
// 0x6AC770
|
||||||
int gInputEventQueueReadIndex;
|
static int gInputEventQueueReadIndex;
|
||||||
|
|
||||||
// 0x6AC774
|
// 0x6AC774
|
||||||
unsigned char* gScreenshotBuffer;
|
static unsigned char* gScreenshotBuffer;
|
||||||
|
|
||||||
// 0x6AC778
|
// 0x6AC778
|
||||||
PauseHandler* gPauseHandler;
|
static PauseHandler* gPauseHandler;
|
||||||
|
|
||||||
// 0x6AC77C
|
// 0x6AC77C
|
||||||
int gInputEventQueueWriteIndex;
|
static int gInputEventQueueWriteIndex;
|
||||||
|
|
||||||
// 0x6AC780
|
// 0x6AC780
|
||||||
bool gRunLoopDisabled;
|
static bool gRunLoopDisabled;
|
||||||
|
|
||||||
// 0x6AC784
|
// 0x6AC784
|
||||||
TickerListNode* gTickerListHead;
|
static TickerListNode* gTickerListHead;
|
||||||
|
|
||||||
// 0x6AC788
|
// 0x6AC788
|
||||||
unsigned int gTickerLastTimestamp;
|
static unsigned int gTickerLastTimestamp;
|
||||||
|
|
||||||
// 0x4C8A70
|
// 0x4C8A70
|
||||||
int coreInit(int a1)
|
int coreInit(int a1)
|
||||||
|
@ -232,7 +261,7 @@ void enqueueInputEvent(int a1)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 0x4C8C9C
|
// 0x4C8C9C
|
||||||
int dequeueInputEvent()
|
static int dequeueInputEvent()
|
||||||
{
|
{
|
||||||
if (gInputEventQueueReadIndex == -1) {
|
if (gInputEventQueueReadIndex == -1) {
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -341,7 +370,7 @@ void tickersDisable()
|
||||||
}
|
}
|
||||||
|
|
||||||
// 0x4C8DFC
|
// 0x4C8DFC
|
||||||
void pauseGame()
|
static void pauseGame()
|
||||||
{
|
{
|
||||||
if (!gPaused) {
|
if (!gPaused) {
|
||||||
gPaused = true;
|
gPaused = true;
|
||||||
|
@ -357,7 +386,7 @@ void pauseGame()
|
||||||
}
|
}
|
||||||
|
|
||||||
// 0x4C8E38
|
// 0x4C8E38
|
||||||
int pauseHandlerDefaultImpl()
|
static int pauseHandlerDefaultImpl()
|
||||||
{
|
{
|
||||||
int windowWidth = fontGetStringWidth("Paused") + 32;
|
int windowWidth = fontGetStringWidth("Paused") + 32;
|
||||||
int windowHeight = 3 * fontGetLineHeight() + 16;
|
int windowHeight = 3 * fontGetLineHeight() + 16;
|
||||||
|
@ -439,7 +468,7 @@ void takeScreenshot()
|
||||||
}
|
}
|
||||||
|
|
||||||
// 0x4C8FF0
|
// 0x4C8FF0
|
||||||
void screenshotBlitter(unsigned char* src, int srcPitch, int a3, int srcX, int srcY, int width, int height, int destX, int destY)
|
static void screenshotBlitter(unsigned char* src, int srcPitch, int a3, int srcX, int srcY, int width, int height, int destX, int destY)
|
||||||
{
|
{
|
||||||
int destWidth = _scr_size.right - _scr_size.left + 1;
|
int destWidth = _scr_size.right - _scr_size.left + 1;
|
||||||
blitBufferToBuffer(src + srcPitch * srcY + srcX, width, height, srcPitch, gScreenshotBuffer + destWidth * destY + destX, destWidth);
|
blitBufferToBuffer(src + srcPitch * srcY + srcX, width, height, srcPitch, gScreenshotBuffer + destWidth * destY + destX, destWidth);
|
||||||
|
@ -702,7 +731,7 @@ IdleFunc* inputGetIdleFunc()
|
||||||
}
|
}
|
||||||
|
|
||||||
// 0x4C9490
|
// 0x4C9490
|
||||||
void buildNormalizedQwertyKeys()
|
static void buildNormalizedQwertyKeys()
|
||||||
{
|
{
|
||||||
int* keys = gNormalizedQwertyKeys;
|
int* keys = gNormalizedQwertyKeys;
|
||||||
int k;
|
int k;
|
||||||
|
@ -1097,7 +1126,7 @@ void _GNW95_process_message()
|
||||||
int tick = _get_time();
|
int tick = _get_time();
|
||||||
|
|
||||||
for (int key = 0; key < SDL_NUM_SCANCODES; key++) {
|
for (int key = 0; key < SDL_NUM_SCANCODES; key++) {
|
||||||
STRUCT_6ABF50* ptr = &(_GNW95_key_time_stamps[key]);
|
RepeatInfo* ptr = &(_GNW95_key_time_stamps[key]);
|
||||||
if (ptr->tick != -1) {
|
if (ptr->tick != -1) {
|
||||||
int elapsedTime = ptr->tick > tick ? INT_MAX : tick - ptr->tick;
|
int elapsedTime = ptr->tick > tick ? INT_MAX : tick - ptr->tick;
|
||||||
int delay = ptr->repeatCount == 0 ? gKeyboardKeyRepeatDelay : gKeyboardKeyRepeatRate;
|
int delay = ptr->repeatCount == 0 ? gKeyboardKeyRepeatDelay : gKeyboardKeyRepeatRate;
|
||||||
|
@ -1124,7 +1153,7 @@ void _GNW95_clear_time_stamps()
|
||||||
}
|
}
|
||||||
|
|
||||||
// 0x4C9E14
|
// 0x4C9E14
|
||||||
void _GNW95_process_key(KeyboardData* data)
|
static void _GNW95_process_key(KeyboardData* data)
|
||||||
{
|
{
|
||||||
data->key = gNormalizedQwertyKeys[data->key];
|
data->key = gNormalizedQwertyKeys[data->key];
|
||||||
|
|
||||||
|
@ -1134,7 +1163,7 @@ void _GNW95_process_key(KeyboardData* data)
|
||||||
vcrStop();
|
vcrStop();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
STRUCT_6ABF50* ptr = &(_GNW95_key_time_stamps[data->key]);
|
RepeatInfo* ptr = &(_GNW95_key_time_stamps[data->key]);
|
||||||
if (data->down == 1) {
|
if (data->down == 1) {
|
||||||
ptr->tick = _get_time();
|
ptr->tick = _get_time();
|
||||||
ptr->repeatCount = 0;
|
ptr->repeatCount = 0;
|
||||||
|
|
52
src/input.h
52
src/input.h
|
@ -1,78 +1,28 @@
|
||||||
#ifndef FALLOUT_INPUT_H_
|
#ifndef FALLOUT_INPUT_H_
|
||||||
#define FALLOUT_INPUT_H_
|
#define FALLOUT_INPUT_H_
|
||||||
|
|
||||||
#include "dinput.h"
|
|
||||||
|
|
||||||
namespace fallout {
|
namespace fallout {
|
||||||
|
|
||||||
typedef struct STRUCT_6ABF50 {
|
|
||||||
// Time when appropriate key was pressed down or -1 if it's up.
|
|
||||||
int tick;
|
|
||||||
int repeatCount;
|
|
||||||
} STRUCT_6ABF50;
|
|
||||||
|
|
||||||
typedef struct InputEvent {
|
|
||||||
// This is either logical key or input event id, which can be either
|
|
||||||
// character code pressed or some other numbers used throughout the
|
|
||||||
// game interface.
|
|
||||||
int logicalKey;
|
|
||||||
int mouseX;
|
|
||||||
int mouseY;
|
|
||||||
} InputEvent;
|
|
||||||
|
|
||||||
typedef void(IdleFunc)();
|
typedef void(IdleFunc)();
|
||||||
typedef void(FocusFunc)(bool focus);
|
typedef void(FocusFunc)(bool focus);
|
||||||
typedef void(TickerProc)();
|
typedef void(TickerProc)();
|
||||||
|
|
||||||
typedef struct TickerListNode {
|
|
||||||
int flags;
|
|
||||||
TickerProc* proc;
|
|
||||||
struct TickerListNode* next;
|
|
||||||
} TickerListNode;
|
|
||||||
|
|
||||||
typedef int(PauseHandler)();
|
typedef int(PauseHandler)();
|
||||||
typedef int(ScreenshotHandler)(int width, int height, unsigned char* buffer, unsigned char* palette);
|
typedef int(ScreenshotHandler)(int width, int height, unsigned char* buffer, unsigned char* palette);
|
||||||
|
|
||||||
extern IdleFunc* _idle_func;
|
|
||||||
extern FocusFunc* _focus_func;
|
|
||||||
extern int gKeyboardKeyRepeatRate;
|
|
||||||
extern int gKeyboardKeyRepeatDelay;
|
|
||||||
extern bool _keyboard_hooked;
|
|
||||||
|
|
||||||
extern int gNormalizedQwertyKeys[SDL_NUM_SCANCODES];
|
|
||||||
extern InputEvent gInputEventQueue[40];
|
|
||||||
extern STRUCT_6ABF50 _GNW95_key_time_stamps[SDL_NUM_SCANCODES];
|
|
||||||
extern int _input_mx;
|
|
||||||
extern int _input_my;
|
|
||||||
extern bool gPaused;
|
|
||||||
extern int gScreenshotKeyCode;
|
|
||||||
extern int _using_msec_timer;
|
|
||||||
extern int gPauseKeyCode;
|
|
||||||
extern ScreenshotHandler* gScreenshotHandler;
|
|
||||||
extern int gInputEventQueueReadIndex;
|
|
||||||
extern unsigned char* gScreenshotBuffer;
|
|
||||||
extern PauseHandler* gPauseHandler;
|
|
||||||
extern int gInputEventQueueWriteIndex;
|
|
||||||
extern bool gRunLoopDisabled;
|
|
||||||
extern TickerListNode* gTickerListHead;
|
|
||||||
extern unsigned int gTickerLastTimestamp;
|
|
||||||
int coreInit(int a1);
|
int coreInit(int a1);
|
||||||
void coreExit();
|
void coreExit();
|
||||||
int _get_input();
|
int _get_input();
|
||||||
void _process_bk();
|
void _process_bk();
|
||||||
void enqueueInputEvent(int a1);
|
void enqueueInputEvent(int a1);
|
||||||
int dequeueInputEvent();
|
|
||||||
void inputEventQueueReset();
|
void inputEventQueueReset();
|
||||||
void tickersExecute();
|
void tickersExecute();
|
||||||
void tickersAdd(TickerProc* fn);
|
void tickersAdd(TickerProc* fn);
|
||||||
void tickersRemove(TickerProc* fn);
|
void tickersRemove(TickerProc* fn);
|
||||||
void tickersEnable();
|
void tickersEnable();
|
||||||
void tickersDisable();
|
void tickersDisable();
|
||||||
void pauseGame();
|
|
||||||
int pauseHandlerDefaultImpl();
|
|
||||||
void pauseHandlerConfigure(int keyCode, PauseHandler* fn);
|
void pauseHandlerConfigure(int keyCode, PauseHandler* fn);
|
||||||
void takeScreenshot();
|
void takeScreenshot();
|
||||||
void screenshotBlitter(unsigned char* src, int src_pitch, int a3, int x, int y, int width, int height, int dest_x, int dest_y);
|
|
||||||
int screenshotHandlerDefaultImpl(int width, int height, unsigned char* data, unsigned char* palette);
|
int screenshotHandlerDefaultImpl(int width, int height, unsigned char* data, unsigned char* palette);
|
||||||
void screenshotHandlerConfigure(int keyCode, ScreenshotHandler* handler);
|
void screenshotHandlerConfigure(int keyCode, ScreenshotHandler* handler);
|
||||||
unsigned int _get_time();
|
unsigned int _get_time();
|
||||||
|
@ -89,11 +39,9 @@ void inputSetFocusFunc(FocusFunc* func);
|
||||||
FocusFunc* inputGetFocusFunc();
|
FocusFunc* inputGetFocusFunc();
|
||||||
void inputSetIdleFunc(IdleFunc* func);
|
void inputSetIdleFunc(IdleFunc* func);
|
||||||
IdleFunc* inputGetIdleFunc();
|
IdleFunc* inputGetIdleFunc();
|
||||||
void buildNormalizedQwertyKeys();
|
|
||||||
int _GNW95_input_init();
|
int _GNW95_input_init();
|
||||||
void _GNW95_process_message();
|
void _GNW95_process_message();
|
||||||
void _GNW95_clear_time_stamps();
|
void _GNW95_clear_time_stamps();
|
||||||
void _GNW95_process_key(KeyboardData* data);
|
|
||||||
void _GNW95_lost_focus();
|
void _GNW95_lost_focus();
|
||||||
|
|
||||||
} // namespace fallout
|
} // namespace fallout
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
#include "color.h"
|
#include "color.h"
|
||||||
#include "core.h"
|
#include "core.h"
|
||||||
#include "debug.h"
|
#include "debug.h"
|
||||||
|
#include "dinput.h"
|
||||||
#include "draw.h"
|
#include "draw.h"
|
||||||
#include "input.h"
|
#include "input.h"
|
||||||
#include "memory.h"
|
#include "memory.h"
|
||||||
|
|
Loading…
Reference in New Issue