2013-09-01 14:27:21 +00:00
|
|
|
/*
|
|
|
|
** eventthread.h
|
|
|
|
**
|
|
|
|
** This file is part of mkxp.
|
|
|
|
**
|
|
|
|
** Copyright (C) 2013 Jonas Kulla <Nyocurio@gmail.com>
|
|
|
|
**
|
|
|
|
** mkxp is free software: you can redistribute it and/or modify
|
|
|
|
** it under the terms of the GNU General Public License as published by
|
|
|
|
** the Free Software Foundation, either version 2 of the License, or
|
|
|
|
** (at your option) any later version.
|
|
|
|
**
|
|
|
|
** mkxp is distributed in the hope that it will be useful,
|
|
|
|
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
** GNU General Public License for more details.
|
|
|
|
**
|
|
|
|
** You should have received a copy of the GNU General Public License
|
|
|
|
** along with mkxp. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef EVENTTHREAD_H
|
|
|
|
#define EVENTTHREAD_H
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
#include "etc-internal.h"
|
|
|
|
|
2013-10-13 21:21:34 +00:00
|
|
|
#include "SDL_scancode.h"
|
|
|
|
#include "SDL_joystick.h"
|
|
|
|
#include "SDL_mouse.h"
|
2013-09-01 14:27:21 +00:00
|
|
|
|
2013-10-13 21:21:34 +00:00
|
|
|
#include "SDL_mutex.h"
|
2013-09-01 14:27:21 +00:00
|
|
|
|
|
|
|
#include <QByteArray>
|
|
|
|
#include <QVector>
|
|
|
|
|
2013-10-06 05:05:01 +00:00
|
|
|
#include <stdint.h>
|
|
|
|
|
2013-09-01 14:27:21 +00:00
|
|
|
struct RGSSThreadData;
|
|
|
|
struct SDL_Thread;
|
|
|
|
struct SDL_Window;
|
|
|
|
|
|
|
|
class EventThread
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
static bool keyStates[SDL_NUM_SCANCODES];
|
|
|
|
|
|
|
|
struct JoyState
|
|
|
|
{
|
|
|
|
int xAxis;
|
|
|
|
int yAxis;
|
|
|
|
|
|
|
|
bool buttons[16];
|
|
|
|
};
|
|
|
|
|
|
|
|
static JoyState joyState;
|
|
|
|
|
|
|
|
struct MouseState
|
|
|
|
{
|
|
|
|
int x, y;
|
|
|
|
bool buttons[SDL_BUTTON_X2+1];
|
|
|
|
};
|
|
|
|
|
|
|
|
static MouseState mouseState;
|
|
|
|
|
|
|
|
EventThread();
|
|
|
|
|
|
|
|
void process(RGSSThreadData &rtData);
|
|
|
|
void cleanup();
|
|
|
|
|
2013-10-06 05:05:01 +00:00
|
|
|
/* Called from RGSS thread */
|
2013-09-01 14:27:21 +00:00
|
|
|
void requestFullscreenMode(bool mode);
|
|
|
|
void requestWindowResize(int width, int height);
|
2013-09-24 20:52:42 +00:00
|
|
|
void requestShowCursor(bool mode);
|
2013-09-01 14:27:21 +00:00
|
|
|
|
|
|
|
void requestTerminate();
|
|
|
|
|
2013-09-24 20:52:42 +00:00
|
|
|
bool getFullscreen() const;
|
|
|
|
bool getShowCursor() const;
|
2013-09-01 14:27:21 +00:00
|
|
|
|
|
|
|
void showMessageBox(const char *body, int flags = 0);
|
|
|
|
|
2013-10-06 05:05:01 +00:00
|
|
|
/* RGSS thread calls this once per frame */
|
|
|
|
void notifyFrame();
|
|
|
|
|
2013-09-01 14:27:21 +00:00
|
|
|
private:
|
2013-09-04 10:10:21 +00:00
|
|
|
void resetInputStates();
|
2013-09-01 14:27:21 +00:00
|
|
|
void setFullscreen(SDL_Window *, bool mode);
|
2013-09-24 20:52:42 +00:00
|
|
|
void updateCursorState(bool inWindow);
|
2013-10-06 05:05:01 +00:00
|
|
|
|
2013-09-01 14:27:21 +00:00
|
|
|
bool fullscreen;
|
2013-09-24 20:52:42 +00:00
|
|
|
bool showCursor;
|
2013-09-01 14:27:21 +00:00
|
|
|
volatile bool msgBoxDone;
|
2013-10-06 05:05:01 +00:00
|
|
|
|
|
|
|
struct
|
|
|
|
{
|
|
|
|
uint64_t lastFrame;
|
|
|
|
uint64_t displayCounter;
|
|
|
|
bool displaying;
|
|
|
|
bool immInitFlag;
|
|
|
|
bool immFiniFlag;
|
|
|
|
uint64_t acc;
|
|
|
|
uint32_t accDiv;
|
|
|
|
} fps;
|
2013-09-01 14:27:21 +00:00
|
|
|
};
|
|
|
|
|
2013-10-06 05:11:03 +00:00
|
|
|
/* Used to asynchronously inform the RGSS thread
|
2013-09-04 10:09:09 +00:00
|
|
|
* about window size changes */
|
2013-09-01 14:27:21 +00:00
|
|
|
struct WindowSizeNotify
|
|
|
|
{
|
|
|
|
SDL_mutex *mutex;
|
|
|
|
|
|
|
|
volatile bool changedFlag;
|
|
|
|
volatile int w, h;
|
|
|
|
|
|
|
|
WindowSizeNotify()
|
|
|
|
{
|
|
|
|
mutex = SDL_CreateMutex();
|
|
|
|
changedFlag = false;
|
|
|
|
w = h = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
~WindowSizeNotify()
|
|
|
|
{
|
|
|
|
SDL_DestroyMutex(mutex);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Done from the sending side */
|
|
|
|
void notifyChange(int w, int h)
|
|
|
|
{
|
|
|
|
SDL_LockMutex(mutex);
|
|
|
|
|
|
|
|
this->w = w;
|
|
|
|
this->h = h;
|
|
|
|
changedFlag = true;
|
|
|
|
|
|
|
|
SDL_UnlockMutex(mutex);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Done from the receiving side */
|
|
|
|
bool pollChange(int *w, int *h)
|
|
|
|
{
|
|
|
|
if (!changedFlag)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
SDL_LockMutex(mutex);
|
|
|
|
|
|
|
|
*w = this->w;
|
|
|
|
*h = this->h;
|
|
|
|
changedFlag = false;
|
|
|
|
|
|
|
|
SDL_UnlockMutex(mutex);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct RGSSThreadData
|
|
|
|
{
|
2013-10-06 05:11:03 +00:00
|
|
|
/* Main thread sets this to request RGSS thread to terminate */
|
2013-09-01 14:27:21 +00:00
|
|
|
volatile bool rqTerm;
|
2013-10-06 05:11:03 +00:00
|
|
|
/* In response, RGSS thread sets this to confirm
|
2013-09-01 14:27:21 +00:00
|
|
|
* that it received the request and isn't stuck */
|
|
|
|
volatile bool rqTermAck;
|
|
|
|
|
|
|
|
EventThread *ethread;
|
|
|
|
WindowSizeNotify windowSizeMsg;
|
|
|
|
|
|
|
|
const char *argv0;
|
|
|
|
|
|
|
|
SDL_Window *window;
|
|
|
|
|
|
|
|
Vec2 sizeResoRatio;
|
2013-09-23 08:39:16 +00:00
|
|
|
Vec2i screenOffset;
|
2013-09-01 14:27:21 +00:00
|
|
|
|
|
|
|
Config config;
|
|
|
|
|
|
|
|
QByteArray rgssErrorMsg;
|
|
|
|
|
|
|
|
RGSSThreadData(EventThread *ethread,
|
|
|
|
const char *argv0,
|
|
|
|
SDL_Window *window)
|
|
|
|
: rqTerm(false),
|
|
|
|
rqTermAck(false),
|
|
|
|
ethread(ethread),
|
|
|
|
argv0(argv0),
|
|
|
|
window(window),
|
|
|
|
sizeResoRatio(1, 1)
|
|
|
|
{}
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif // EVENTTHREAD_H
|