Merge branch 'master' of github.com:ancurio/mkxp
This commit is contained in:
commit
8f935da48e
Binary file not shown.
After Width: | Height: | Size: 17 KiB |
|
@ -0,0 +1 @@
|
||||||
|
#define IDI_APPICON 101
|
|
@ -0,0 +1,4 @@
|
||||||
|
#include <windows.h>
|
||||||
|
#include "resource.h"
|
||||||
|
|
||||||
|
IDI_APPICON ICON "icon.ico"
|
|
@ -82,6 +82,7 @@ RB_METHOD(mriP);
|
||||||
RB_METHOD(mkxpDataDirectory);
|
RB_METHOD(mkxpDataDirectory);
|
||||||
RB_METHOD(mkxpPuts);
|
RB_METHOD(mkxpPuts);
|
||||||
RB_METHOD(mkxpRawKeyStates);
|
RB_METHOD(mkxpRawKeyStates);
|
||||||
|
RB_METHOD(mkxpMouseInWindow);
|
||||||
|
|
||||||
RB_METHOD(mriRgssMain);
|
RB_METHOD(mriRgssMain);
|
||||||
RB_METHOD(mriRgssStop);
|
RB_METHOD(mriRgssStop);
|
||||||
|
@ -146,6 +147,7 @@ static void mriBindingInit()
|
||||||
_rb_define_module_function(mod, "data_directory", mkxpDataDirectory);
|
_rb_define_module_function(mod, "data_directory", mkxpDataDirectory);
|
||||||
_rb_define_module_function(mod, "puts", mkxpPuts);
|
_rb_define_module_function(mod, "puts", mkxpPuts);
|
||||||
_rb_define_module_function(mod, "raw_key_states", mkxpRawKeyStates);
|
_rb_define_module_function(mod, "raw_key_states", mkxpRawKeyStates);
|
||||||
|
_rb_define_module_function(mod, "mouse_in_window", mkxpMouseInWindow);
|
||||||
|
|
||||||
rb_gv_set("MKXP", Qtrue);
|
rb_gv_set("MKXP", Qtrue);
|
||||||
}
|
}
|
||||||
|
@ -237,6 +239,13 @@ RB_METHOD(mkxpRawKeyStates)
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
RB_METHOD(mkxpMouseInWindow)
|
||||||
|
{
|
||||||
|
RB_UNUSED_PARAM;
|
||||||
|
|
||||||
|
return rb_bool_new(EventThread::mouseState.inWindow);
|
||||||
|
}
|
||||||
|
|
||||||
static VALUE rgssMainCb(VALUE block)
|
static VALUE rgssMainCb(VALUE block)
|
||||||
{
|
{
|
||||||
rb_funcall2(block, rb_intern("call"), 0, 0);
|
rb_funcall2(block, rb_intern("call"), 0, 0);
|
||||||
|
@ -483,8 +492,9 @@ static void runRMXPScripts(BacktraceData &btData)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Execute preloaded scripts */
|
/* Execute preloaded scripts */
|
||||||
for (size_t i = 0; i < conf.preloadScripts.size(); ++i)
|
for (std::set<std::string>::iterator i = conf.preloadScripts.begin();
|
||||||
runCustomScript(conf.preloadScripts[i]);
|
i != conf.preloadScripts.end(); ++i)
|
||||||
|
runCustomScript(*i);
|
||||||
|
|
||||||
VALUE exc = rb_gv_get("$!");
|
VALUE exc = rb_gv_get("$!");
|
||||||
if (exc != Qnil)
|
if (exc != Qnil)
|
||||||
|
|
|
@ -134,6 +134,12 @@ static std::string prefPath(const char *org, const char *app)
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
std::set<T> setFromVec(const std::vector<T> &vec)
|
||||||
|
{
|
||||||
|
return std::set<T>(vec.begin(), vec.end());
|
||||||
|
}
|
||||||
|
|
||||||
typedef std::vector<std::string> StringVec;
|
typedef std::vector<std::string> StringVec;
|
||||||
namespace po = boost::program_options;
|
namespace po = boost::program_options;
|
||||||
|
|
||||||
|
@ -226,7 +232,7 @@ void Config::read(int argc, char *argv[])
|
||||||
|
|
||||||
PO_DESC_ALL;
|
PO_DESC_ALL;
|
||||||
|
|
||||||
GUARD_ALL( preloadScripts = vm["preloadScript"].as<StringVec>(); );
|
GUARD_ALL( preloadScripts = setFromVec(vm["preloadScript"].as<StringVec>()); );
|
||||||
|
|
||||||
GUARD_ALL( rtps = vm["RTP"].as<StringVec>(); );
|
GUARD_ALL( rtps = vm["RTP"].as<StringVec>(); );
|
||||||
|
|
||||||
|
|
|
@ -24,6 +24,7 @@
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include <set>
|
||||||
|
|
||||||
struct CropTexture
|
struct CropTexture
|
||||||
{
|
{
|
||||||
|
@ -83,7 +84,7 @@ struct Config
|
||||||
bool useScriptNames;
|
bool useScriptNames;
|
||||||
|
|
||||||
std::string customScript;
|
std::string customScript;
|
||||||
std::vector<std::string> preloadScripts;
|
std::set<std::string> preloadScripts;
|
||||||
std::vector<std::string> rtps;
|
std::vector<std::string> rtps;
|
||||||
|
|
||||||
std::vector<std::string> fontSubs;
|
std::vector<std::string> fontSubs;
|
||||||
|
|
|
@ -83,6 +83,7 @@ enum
|
||||||
REQUEST_SETCURSORVISIBLE,
|
REQUEST_SETCURSORVISIBLE,
|
||||||
|
|
||||||
UPDATE_FPS,
|
UPDATE_FPS,
|
||||||
|
UPDATE_SCREEN_RECT,
|
||||||
|
|
||||||
EVENT_COUNT
|
EVENT_COUNT
|
||||||
};
|
};
|
||||||
|
@ -131,6 +132,8 @@ void EventThread::process(RGSSThreadData &rtData)
|
||||||
bool displayingFPS = false;
|
bool displayingFPS = false;
|
||||||
|
|
||||||
bool cursorInWindow = false;
|
bool cursorInWindow = false;
|
||||||
|
/* Will be updated eventually */
|
||||||
|
SDL_Rect gameScreen = { 0, 0, 0, 0 };
|
||||||
|
|
||||||
/* SDL doesn't send an initial FOCUS_GAINED event */
|
/* SDL doesn't send an initial FOCUS_GAINED event */
|
||||||
bool windowFocused = true;
|
bool windowFocused = true;
|
||||||
|
@ -170,7 +173,7 @@ void EventThread::process(RGSSThreadData &rtData)
|
||||||
delete sMenu;
|
delete sMenu;
|
||||||
sMenu = 0;
|
sMenu = 0;
|
||||||
|
|
||||||
updateCursorState(cursorInWindow && windowFocused);
|
updateCursorState(cursorInWindow && windowFocused, gameScreen);
|
||||||
}
|
}
|
||||||
|
|
||||||
continue;
|
continue;
|
||||||
|
@ -211,14 +214,14 @@ void EventThread::process(RGSSThreadData &rtData)
|
||||||
case SDL_WINDOWEVENT_ENTER :
|
case SDL_WINDOWEVENT_ENTER :
|
||||||
cursorInWindow = true;
|
cursorInWindow = true;
|
||||||
mouseState.inWindow = true;
|
mouseState.inWindow = true;
|
||||||
updateCursorState(cursorInWindow && windowFocused && !sMenu);
|
updateCursorState(cursorInWindow && windowFocused && !sMenu, gameScreen);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SDL_WINDOWEVENT_LEAVE :
|
case SDL_WINDOWEVENT_LEAVE :
|
||||||
cursorInWindow = false;
|
cursorInWindow = false;
|
||||||
mouseState.inWindow = false;
|
mouseState.inWindow = false;
|
||||||
updateCursorState(cursorInWindow && windowFocused && !sMenu);
|
updateCursorState(cursorInWindow && windowFocused && !sMenu, gameScreen);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -229,13 +232,13 @@ void EventThread::process(RGSSThreadData &rtData)
|
||||||
|
|
||||||
case SDL_WINDOWEVENT_FOCUS_GAINED :
|
case SDL_WINDOWEVENT_FOCUS_GAINED :
|
||||||
windowFocused = true;
|
windowFocused = true;
|
||||||
updateCursorState(cursorInWindow && windowFocused && !sMenu);
|
updateCursorState(cursorInWindow && windowFocused && !sMenu, gameScreen);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SDL_WINDOWEVENT_FOCUS_LOST :
|
case SDL_WINDOWEVENT_FOCUS_LOST :
|
||||||
windowFocused = false;
|
windowFocused = false;
|
||||||
updateCursorState(cursorInWindow && windowFocused && !sMenu);
|
updateCursorState(cursorInWindow && windowFocused && !sMenu, gameScreen);
|
||||||
resetInputStates();
|
resetInputStates();
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
@ -268,7 +271,7 @@ void EventThread::process(RGSSThreadData &rtData)
|
||||||
if (!sMenu)
|
if (!sMenu)
|
||||||
{
|
{
|
||||||
sMenu = new SettingsMenu(rtData);
|
sMenu = new SettingsMenu(rtData);
|
||||||
updateCursorState(false);
|
updateCursorState(false, gameScreen);
|
||||||
}
|
}
|
||||||
|
|
||||||
sMenu->raise();
|
sMenu->raise();
|
||||||
|
@ -374,6 +377,7 @@ void EventThread::process(RGSSThreadData &rtData)
|
||||||
case SDL_MOUSEMOTION :
|
case SDL_MOUSEMOTION :
|
||||||
mouseState.x = event.motion.x;
|
mouseState.x = event.motion.x;
|
||||||
mouseState.y = event.motion.y;
|
mouseState.y = event.motion.y;
|
||||||
|
updateCursorState(cursorInWindow, gameScreen);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SDL_FINGERDOWN :
|
case SDL_FINGERDOWN :
|
||||||
|
@ -413,7 +417,7 @@ void EventThread::process(RGSSThreadData &rtData)
|
||||||
|
|
||||||
case REQUEST_SETCURSORVISIBLE :
|
case REQUEST_SETCURSORVISIBLE :
|
||||||
showCursor = event.user.code;
|
showCursor = event.user.code;
|
||||||
updateCursorState(cursorInWindow);
|
updateCursorState(cursorInWindow, gameScreen);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case UPDATE_FPS :
|
case UPDATE_FPS :
|
||||||
|
@ -438,6 +442,15 @@ void EventThread::process(RGSSThreadData &rtData)
|
||||||
|
|
||||||
SDL_SetWindowTitle(win, buffer);
|
SDL_SetWindowTitle(win, buffer);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case UPDATE_SCREEN_RECT :
|
||||||
|
gameScreen.x = event.user.windowID;
|
||||||
|
gameScreen.y = event.user.code;
|
||||||
|
gameScreen.w = reinterpret_cast<intptr_t>(event.user.data1);
|
||||||
|
gameScreen.h = reinterpret_cast<intptr_t>(event.user.data2);
|
||||||
|
updateCursorState(cursorInWindow, gameScreen);
|
||||||
|
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -532,9 +545,13 @@ void EventThread::setFullscreen(SDL_Window *win, bool mode)
|
||||||
fullscreen = mode;
|
fullscreen = mode;
|
||||||
}
|
}
|
||||||
|
|
||||||
void EventThread::updateCursorState(bool inWindow)
|
void EventThread::updateCursorState(bool inWindow,
|
||||||
|
const SDL_Rect &screen)
|
||||||
{
|
{
|
||||||
if (inWindow)
|
SDL_Point pos = { mouseState.x, mouseState.y };
|
||||||
|
bool inScreen = inWindow && SDL_PointInRect(&pos, &screen);
|
||||||
|
|
||||||
|
if (inScreen)
|
||||||
SDL_ShowCursor(showCursor ? SDL_TRUE : SDL_FALSE);
|
SDL_ShowCursor(showCursor ? SDL_TRUE : SDL_FALSE);
|
||||||
else
|
else
|
||||||
SDL_ShowCursor(SDL_TRUE);
|
SDL_ShowCursor(SDL_TRUE);
|
||||||
|
@ -640,6 +657,19 @@ void EventThread::notifyFrame()
|
||||||
SDL_PushEvent(&event);
|
SDL_PushEvent(&event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void EventThread::notifyGameScreenChange(const SDL_Rect &screen)
|
||||||
|
{
|
||||||
|
/* We have to get a bit hacky here to fit the rectangle
|
||||||
|
* data into the user event struct */
|
||||||
|
SDL_Event event;
|
||||||
|
event.type = usrIdStart + UPDATE_SCREEN_RECT;
|
||||||
|
event.user.windowID = screen.x;
|
||||||
|
event.user.code = screen.y;
|
||||||
|
event.user.data1 = reinterpret_cast<void*>(screen.w);
|
||||||
|
event.user.data2 = reinterpret_cast<void*>(screen.h);
|
||||||
|
SDL_PushEvent(&event);
|
||||||
|
}
|
||||||
|
|
||||||
void SyncPoint::haltThreads()
|
void SyncPoint::haltThreads()
|
||||||
{
|
{
|
||||||
if (mainSync.locked)
|
if (mainSync.locked)
|
||||||
|
|
|
@ -98,12 +98,16 @@ public:
|
||||||
/* RGSS thread calls this once per frame */
|
/* RGSS thread calls this once per frame */
|
||||||
void notifyFrame();
|
void notifyFrame();
|
||||||
|
|
||||||
|
/* Called on game screen (size / offset) changes */
|
||||||
|
void notifyGameScreenChange(const SDL_Rect &screen);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static int eventFilter(void *, SDL_Event*);
|
static int eventFilter(void *, SDL_Event*);
|
||||||
|
|
||||||
void resetInputStates();
|
void resetInputStates();
|
||||||
void setFullscreen(SDL_Window *, bool mode);
|
void setFullscreen(SDL_Window *, bool mode);
|
||||||
void updateCursorState(bool inWindow);
|
void updateCursorState(bool inWindow,
|
||||||
|
const SDL_Rect &screen);
|
||||||
|
|
||||||
bool fullscreen;
|
bool fullscreen;
|
||||||
bool showCursor;
|
bool showCursor;
|
||||||
|
|
|
@ -458,7 +458,7 @@ struct FontSetsCBData
|
||||||
SharedFontState *sfs;
|
SharedFontState *sfs;
|
||||||
};
|
};
|
||||||
|
|
||||||
static void fontSetEnumCB(void *data, const char *,
|
static void fontSetEnumCB(void *data, const char *dir,
|
||||||
const char *fname)
|
const char *fname)
|
||||||
{
|
{
|
||||||
FontSetsCBData *d = static_cast<FontSetsCBData*>(data);
|
FontSetsCBData *d = static_cast<FontSetsCBData*>(data);
|
||||||
|
@ -480,7 +480,7 @@ static void fontSetEnumCB(void *data, const char *,
|
||||||
return;
|
return;
|
||||||
|
|
||||||
char filename[512];
|
char filename[512];
|
||||||
snprintf(filename, sizeof(filename), "Fonts/%s", fname);
|
snprintf(filename, sizeof(filename), "%s/%s", dir, fname);
|
||||||
|
|
||||||
PHYSFS_File *handle = PHYSFS_openRead(filename);
|
PHYSFS_File *handle = PHYSFS_openRead(filename);
|
||||||
|
|
||||||
|
@ -495,11 +495,29 @@ static void fontSetEnumCB(void *data, const char *,
|
||||||
SDL_RWclose(&ops);
|
SDL_RWclose(&ops);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Basically just a case-insensitive search
|
||||||
|
* for the folder "Fonts"... */
|
||||||
|
static void findFontsFolderCB(void *data, const char *,
|
||||||
|
const char *fname)
|
||||||
|
{
|
||||||
|
size_t i = 0;
|
||||||
|
char buffer[512];
|
||||||
|
const char *s = fname;
|
||||||
|
|
||||||
|
while (s && i < sizeof(buffer))
|
||||||
|
buffer[i++] = tolower(*s++);
|
||||||
|
|
||||||
|
buffer[i] = '\0';
|
||||||
|
|
||||||
|
if (strcmp(buffer, "fonts") == 0)
|
||||||
|
PHYSFS_enumerateFilesCallback(fname, fontSetEnumCB, data);
|
||||||
|
}
|
||||||
|
|
||||||
void FileSystem::initFontSets(SharedFontState &sfs)
|
void FileSystem::initFontSets(SharedFontState &sfs)
|
||||||
{
|
{
|
||||||
FontSetsCBData d = { p, &sfs };
|
FontSetsCBData d = { p, &sfs };
|
||||||
|
|
||||||
PHYSFS_enumerateFilesCallback("Fonts", fontSetEnumCB, &d);
|
PHYSFS_enumerateFilesCallback(".", findFontsFolderCB, &d);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct OpenReadEnumData
|
struct OpenReadEnumData
|
||||||
|
|
|
@ -566,6 +566,9 @@ struct GraphicsPrivate
|
||||||
glState.viewport.refresh();
|
glState.viewport.refresh();
|
||||||
recalculateScreenSize(threadData);
|
recalculateScreenSize(threadData);
|
||||||
updateScreenResoRatio(threadData);
|
updateScreenResoRatio(threadData);
|
||||||
|
|
||||||
|
SDL_Rect screen = { scOffset.x, scOffset.y, scSize.x, scSize.y };
|
||||||
|
threadData->ethread->notifyGameScreenChange(screen);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -671,9 +671,6 @@ int Input::mouseX()
|
||||||
{
|
{
|
||||||
RGSSThreadData &rtData = shState->rtData();
|
RGSSThreadData &rtData = shState->rtData();
|
||||||
|
|
||||||
if (!EventThread::mouseState.inWindow)
|
|
||||||
return -20;
|
|
||||||
|
|
||||||
return (EventThread::mouseState.x - rtData.screenOffset.x) * rtData.sizeResoRatio.x;
|
return (EventThread::mouseState.x - rtData.screenOffset.x) * rtData.sizeResoRatio.x;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -681,9 +678,6 @@ int Input::mouseY()
|
||||||
{
|
{
|
||||||
RGSSThreadData &rtData = shState->rtData();
|
RGSSThreadData &rtData = shState->rtData();
|
||||||
|
|
||||||
if (!EventThread::mouseState.inWindow)
|
|
||||||
return -20;
|
|
||||||
|
|
||||||
return (EventThread::mouseState.y - rtData.screenOffset.y) * rtData.sizeResoRatio.y;
|
return (EventThread::mouseState.y - rtData.screenOffset.y) * rtData.sizeResoRatio.y;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
44
src/main.cpp
44
src/main.cpp
|
@ -40,7 +40,11 @@
|
||||||
|
|
||||||
#include "binding.h"
|
#include "binding.h"
|
||||||
|
|
||||||
|
#ifdef __WINDOWS__
|
||||||
|
#include "resource.h"
|
||||||
|
#elif __LINUX__
|
||||||
#include "icon.png.xxd"
|
#include "icon.png.xxd"
|
||||||
|
#endif
|
||||||
|
|
||||||
static void
|
static void
|
||||||
rgssThreadError(RGSSThreadData *rtData, const std::string &msg)
|
rgssThreadError(RGSSThreadData *rtData, const std::string &msg)
|
||||||
|
@ -166,6 +170,24 @@ static void showInitError(const std::string &msg)
|
||||||
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "mkxp", msg.c_str(), 0);
|
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "mkxp", msg.c_str(), 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void setupWindowIcon(const Config &conf, SDL_Window *win)
|
||||||
|
{
|
||||||
|
SDL_RWops *iconSrc;
|
||||||
|
|
||||||
|
if (conf.iconPath.empty())
|
||||||
|
iconSrc = SDL_RWFromConstMem(assets_icon_png, assets_icon_png_len);
|
||||||
|
else
|
||||||
|
iconSrc = SDL_RWFromFile(conf.iconPath.c_str(), "rb");
|
||||||
|
|
||||||
|
SDL_Surface *iconImg = IMG_Load_RW(iconSrc, SDL_TRUE);
|
||||||
|
|
||||||
|
if (iconImg)
|
||||||
|
{
|
||||||
|
SDL_SetWindowIcon(win, iconImg);
|
||||||
|
SDL_FreeSurface(iconImg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
SDL_SetHint(SDL_HINT_VIDEO_MINIMIZE_ON_FOCUS_LOSS, "0");
|
SDL_SetHint(SDL_HINT_VIDEO_MINIMIZE_ON_FOCUS_LOSS, "0");
|
||||||
|
@ -239,16 +261,6 @@ int main(int argc, char *argv[])
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Setup application icon */
|
|
||||||
SDL_RWops *iconSrc;
|
|
||||||
|
|
||||||
if (conf.iconPath.empty())
|
|
||||||
iconSrc = SDL_RWFromConstMem(assets_icon_png, assets_icon_png_len);
|
|
||||||
else
|
|
||||||
iconSrc = SDL_RWFromFile(conf.iconPath.c_str(), "rb");
|
|
||||||
|
|
||||||
SDL_Surface *iconImg = IMG_Load_RW(iconSrc, SDL_TRUE);
|
|
||||||
|
|
||||||
SDL_Window *win;
|
SDL_Window *win;
|
||||||
Uint32 winFlags = SDL_WINDOW_OPENGL | SDL_WINDOW_INPUT_FOCUS;
|
Uint32 winFlags = SDL_WINDOW_OPENGL | SDL_WINDOW_INPUT_FOCUS;
|
||||||
|
|
||||||
|
@ -267,11 +279,13 @@ int main(int argc, char *argv[])
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (iconImg)
|
/* OSX and Windows have their own native ways of
|
||||||
{
|
* dealing with icons; don't interfere with them */
|
||||||
SDL_SetWindowIcon(win, iconImg);
|
#ifdef __LINUX__
|
||||||
SDL_FreeSurface(iconImg);
|
setupWindowIcon(conf, win);
|
||||||
}
|
#else
|
||||||
|
(void) setupWindowIcon;
|
||||||
|
#endif
|
||||||
|
|
||||||
ALCdevice *alcDev = alcOpenDevice(0);
|
ALCdevice *alcDev = alcOpenDevice(0);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue