WIP: Emscripten support
This commit is contained in:
parent
fe3d727fd4
commit
5b3c1d2b13
12 changed files with 168 additions and 103 deletions
|
@ -21,10 +21,9 @@
|
|||
|
||||
#ifndef BOOSTHASH_H
|
||||
#define BOOSTHASH_H
|
||||
|
||||
#include <boost/unordered/unordered_map.hpp>
|
||||
#include <boost/unordered/unordered_set.hpp>
|
||||
|
||||
#include <string>
|
||||
#include <map>
|
||||
#include <set>
|
||||
#include <utility>
|
||||
|
||||
/* Wrappers around the boost unordered template classes,
|
||||
|
@ -34,7 +33,7 @@ template<typename K, typename V>
|
|||
class BoostHash
|
||||
{
|
||||
private:
|
||||
typedef boost::unordered_map<K, V> BoostType;
|
||||
typedef std::map<K, V> BoostType;
|
||||
typedef std::pair<K, V> PairType;
|
||||
BoostType p;
|
||||
|
||||
|
@ -98,7 +97,7 @@ template<typename K>
|
|||
class BoostSet
|
||||
{
|
||||
private:
|
||||
typedef boost::unordered_set<K> BoostType;
|
||||
typedef std::set<K> BoostType;
|
||||
BoostType p;
|
||||
|
||||
public:
|
||||
|
|
|
@ -21,9 +21,9 @@
|
|||
|
||||
#include "config.h"
|
||||
|
||||
#include <boost/program_options/options_description.hpp>
|
||||
#include <boost/program_options/parsers.hpp>
|
||||
#include <boost/program_options/variables_map.hpp>
|
||||
//#include <boost/program_options/options_description.hpp>
|
||||
//#include <boost/program_options/parsers.hpp>
|
||||
//#include <boost/program_options/variables_map.hpp>
|
||||
|
||||
#include <SDL_filesystem.h>
|
||||
|
||||
|
@ -140,8 +140,8 @@ std::set<T> setFromVec(const std::vector<T> &vec)
|
|||
return std::set<T>(vec.begin(), vec.end());
|
||||
}
|
||||
|
||||
typedef std::vector<std::string> StringVec;
|
||||
namespace po = boost::program_options;
|
||||
//typedef std::vector<std::string> StringVec;
|
||||
//namespace po = boost::program_options;
|
||||
|
||||
#define CONF_FILE "mkxp.conf"
|
||||
|
||||
|
@ -150,6 +150,8 @@ Config::Config()
|
|||
|
||||
void Config::read(int argc, char *argv[])
|
||||
{
|
||||
gameFolder = "game";
|
||||
#if 0
|
||||
#define PO_DESC_ALL \
|
||||
PO_DESC(rgssVersion, int, 0) \
|
||||
PO_DESC(debugMode, bool, false) \
|
||||
|
@ -244,6 +246,8 @@ void Config::read(int argc, char *argv[])
|
|||
|
||||
#undef PO_DESC
|
||||
#undef PO_DESC_ALL
|
||||
#endif
|
||||
preloadScripts.insert("win32_wrap.rb");
|
||||
|
||||
rgssVersion = clamp(rgssVersion, 0, 3);
|
||||
|
||||
|
@ -276,6 +280,7 @@ static void setupScreenSize(Config &conf)
|
|||
|
||||
void Config::readGameINI()
|
||||
{
|
||||
|
||||
if (!customScript.empty())
|
||||
{
|
||||
game.title = baseName(customScript);
|
||||
|
@ -287,7 +292,7 @@ void Config::readGameINI()
|
|||
|
||||
return;
|
||||
}
|
||||
|
||||
#if 0
|
||||
po::options_description podesc;
|
||||
podesc.add_options()
|
||||
("Game.Title", po::value<std::string>())
|
||||
|
@ -295,9 +300,11 @@ void Config::readGameINI()
|
|||
;
|
||||
|
||||
po::variables_map vm;
|
||||
#endif
|
||||
|
||||
std::string iniFilename = execName + ".ini";
|
||||
SDLRWStream iniFile(iniFilename.c_str(), "r");
|
||||
|
||||
#if 0
|
||||
if (iniFile)
|
||||
{
|
||||
try
|
||||
|
@ -317,9 +324,11 @@ void Config::readGameINI()
|
|||
|
||||
GUARD_ALL( game.title = vm["Game.Title"].as<std::string>(); );
|
||||
GUARD_ALL( game.scripts = vm["Game.Scripts"].as<std::string>(); );
|
||||
#endif
|
||||
game.scripts = "Data/Scripts.rxdata";
|
||||
|
||||
|
||||
strReplace(game.scripts, '\\', '/');
|
||||
|
||||
#ifdef INI_ENCODING
|
||||
/* Can add more later */
|
||||
const char *languages[] =
|
||||
|
|
54
src/config.h
54
src/config.h
|
@ -28,56 +28,56 @@
|
|||
|
||||
struct Config
|
||||
{
|
||||
int rgssVersion;
|
||||
int rgssVersion = 0;
|
||||
|
||||
bool debugMode;
|
||||
bool printFPS;
|
||||
bool debugMode = false;
|
||||
bool printFPS = false;
|
||||
|
||||
bool winResizable;
|
||||
bool fullscreen;
|
||||
bool fixedAspectRatio;
|
||||
bool smoothScaling;
|
||||
bool vsync;
|
||||
bool winResizable = false;
|
||||
bool fullscreen = false;
|
||||
bool fixedAspectRatio = true;
|
||||
bool smoothScaling = true;
|
||||
bool vsync = false;
|
||||
|
||||
int defScreenW;
|
||||
int defScreenH;
|
||||
int defScreenW = 0;
|
||||
int defScreenH = 0;
|
||||
|
||||
int fixedFramerate;
|
||||
bool frameSkip;
|
||||
bool syncToRefreshrate;
|
||||
int fixedFramerate = 0;
|
||||
bool frameSkip =true;
|
||||
bool syncToRefreshrate = false;
|
||||
|
||||
bool solidFonts;
|
||||
bool solidFonts = false;
|
||||
|
||||
bool subImageFix;
|
||||
bool enableBlitting;
|
||||
int maxTextureSize;
|
||||
bool subImageFix = false;
|
||||
bool enableBlitting = true;
|
||||
int maxTextureSize = 0;
|
||||
|
||||
std::string gameFolder;
|
||||
bool anyAltToggleFS;
|
||||
bool enableReset;
|
||||
bool allowSymlinks;
|
||||
bool pathCache;
|
||||
std::string gameFolder = ".";
|
||||
bool anyAltToggleFS = false;
|
||||
bool enableReset = true;
|
||||
bool allowSymlinks = false;
|
||||
bool pathCache=true;
|
||||
|
||||
std::string dataPathOrg;
|
||||
std::string dataPathApp;
|
||||
|
||||
std::string iconPath;
|
||||
std::string execName;
|
||||
std::string execName = "Game";
|
||||
std::string titleLanguage;
|
||||
|
||||
struct
|
||||
{
|
||||
std::string soundFont;
|
||||
bool chorus;
|
||||
bool reverb;
|
||||
bool chorus = false;
|
||||
bool reverb = false;
|
||||
} midi;
|
||||
|
||||
struct
|
||||
{
|
||||
int sourceCount;
|
||||
int sourceCount = 6;
|
||||
} SE;
|
||||
|
||||
bool useScriptNames;
|
||||
bool useScriptNames = false;
|
||||
|
||||
std::string customScript;
|
||||
std::set<std::string> preloadScripts;
|
||||
|
|
|
@ -100,7 +100,9 @@ bool EventThread::allocUserEvents()
|
|||
|
||||
return true;
|
||||
}
|
||||
|
||||
#ifdef __EMSCRIPTEN__
|
||||
#include <emscripten.h>
|
||||
#endif
|
||||
EventThread::EventThread()
|
||||
: fullscreen(false),
|
||||
showCursor(false)
|
||||
|
@ -108,64 +110,43 @@ EventThread::EventThread()
|
|||
|
||||
void EventThread::process(RGSSThreadData &rtData)
|
||||
{
|
||||
SDL_Event event;
|
||||
UnidirMessage<Vec2i> windowSizeMsg;
|
||||
|
||||
static bool once = true;
|
||||
if (once) {
|
||||
SDL_Event event;
|
||||
SDL_Window *win = rtData.window;
|
||||
UnidirMessage<Vec2i> &windowSizeMsg = rtData.windowSizeMsg;
|
||||
|
||||
initALCFunctions(rtData.alcDev);
|
||||
|
||||
// XXX this function breaks input focus on OSX
|
||||
#ifndef __MACOSX__
|
||||
SDL_SetEventFilter(eventFilter, &rtData);
|
||||
#endif
|
||||
|
||||
fullscreen = rtData.config.fullscreen;
|
||||
int toggleFSMod = rtData.config.anyAltToggleFS ? KMOD_ALT : KMOD_LALT;
|
||||
toggleFSMod = rtData.config.anyAltToggleFS ? KMOD_ALT : KMOD_LALT;
|
||||
|
||||
fps.lastFrame = SDL_GetPerformanceCounter();
|
||||
fps.displayCounter = 0;
|
||||
fps.acc = 0;
|
||||
fps.accDiv = 0;
|
||||
|
||||
if (rtData.config.printFPS)
|
||||
fps.sendUpdates.set();
|
||||
|
||||
bool displayingFPS = false;
|
||||
|
||||
bool cursorInWindow = false;
|
||||
/* Will be updated eventually */
|
||||
SDL_Rect gameScreen = { 0, 0, 0, 0 };
|
||||
|
||||
/* SDL doesn't send an initial FOCUS_GAINED event */
|
||||
bool windowFocused = true;
|
||||
|
||||
bool terminate = false;
|
||||
|
||||
SDL_Joystick *js = 0;
|
||||
if (SDL_NumJoysticks() > 0)
|
||||
js = SDL_JoystickOpen(0);
|
||||
|
||||
char buffer[128];
|
||||
|
||||
char pendingTitle[128];
|
||||
bool havePendingTitle = false;
|
||||
|
||||
bool resetting = false;
|
||||
|
||||
int winW, winH;
|
||||
int i;
|
||||
|
||||
SDL_GetWindowSize(win, &winW, &winH);
|
||||
|
||||
SettingsMenu *sMenu = 0;
|
||||
|
||||
while (true)
|
||||
once = false;
|
||||
}
|
||||
while (SDL_PollEvent(&event))
|
||||
{
|
||||
if (!SDL_WaitEvent(&event))
|
||||
{
|
||||
Debug() << "EventThread: Event error";
|
||||
break;
|
||||
}
|
||||
#ifdef __EMSCRIPTEN__
|
||||
emscripten_sleep(10);
|
||||
#endif
|
||||
// if (!SDL_WaitEvent(&event))
|
||||
// {
|
||||
// Debug() << "EventThread: Event error";
|
||||
// break;
|
||||
// }
|
||||
|
||||
if (sMenu && sMenu->onEvent(event))
|
||||
{
|
||||
|
@ -460,12 +441,12 @@ void EventThread::process(RGSSThreadData &rtData)
|
|||
}
|
||||
|
||||
/* Just in case */
|
||||
rtData.syncPoint.resumeThreads();
|
||||
//rtData.syncPoint.resumeThreads();
|
||||
|
||||
if (SDL_JoystickGetAttached(js))
|
||||
SDL_JoystickClose(js);
|
||||
//if (SDL_JoystickGetAttached(js))
|
||||
// SDL_JoystickClose(js);
|
||||
|
||||
delete sMenu;
|
||||
//delete sMenu;
|
||||
}
|
||||
|
||||
int EventThread::eventFilter(void *data, SDL_Event *event)
|
||||
|
|
|
@ -35,7 +35,7 @@
|
|||
#include <string>
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
class SettingsMenu;
|
||||
struct RGSSThreadData;
|
||||
typedef struct ALCdevice_struct ALCdevice;
|
||||
struct SDL_Window;
|
||||
|
@ -123,6 +123,35 @@ private:
|
|||
double acc;
|
||||
uint32_t accDiv;
|
||||
} fps;
|
||||
|
||||
SDL_Window *win;
|
||||
int toggleFSMod;
|
||||
|
||||
bool displayingFPS = false;
|
||||
|
||||
bool cursorInWindow = false;
|
||||
/* Will be updated eventually */
|
||||
SDL_Rect gameScreen = { 0, 0, 0, 0 };
|
||||
|
||||
/* SDL doesn't send an initial FOCUS_GAINED event */
|
||||
bool windowFocused = true;
|
||||
|
||||
bool terminate = false;
|
||||
|
||||
SDL_Joystick *js = 0;
|
||||
|
||||
char buffer[128];
|
||||
|
||||
char pendingTitle[128];
|
||||
bool havePendingTitle = false;
|
||||
|
||||
bool resetting = false;
|
||||
|
||||
int winW, winH;
|
||||
int i;
|
||||
|
||||
SettingsMenu *sMenu = 0;
|
||||
|
||||
};
|
||||
|
||||
/* Used to asynchronously inform the RGSS thread
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
** You should have received a copy of the GNU General Public License
|
||||
** along with mkxp. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <cassert>
|
||||
#include "filesystem.h"
|
||||
|
||||
#include "rgssad.h"
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
#elif __WINDOWS__
|
||||
#define FLUID_LIB "fluidsynth.dll"
|
||||
#else
|
||||
#error "platform not recognized"
|
||||
//#error "platform not recognized"
|
||||
#endif
|
||||
|
||||
struct FluidFunctions fluid;
|
||||
|
@ -26,6 +26,7 @@ static void *so;
|
|||
|
||||
void initFluidFunctions()
|
||||
{
|
||||
#if 0
|
||||
#ifdef SHARED_FLUID
|
||||
|
||||
#define FLUID_FUN(name, type) \
|
||||
|
@ -64,4 +65,7 @@ fail:
|
|||
SDL_UnloadObject(so);
|
||||
so = 0;
|
||||
#endif
|
||||
#endif
|
||||
so = 0;
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -318,7 +318,9 @@ private:
|
|||
|
||||
/* Nanoseconds per second */
|
||||
#define NS_PER_S 1000000000
|
||||
|
||||
#ifdef __EMSCRIPTEN__
|
||||
#include <emscripten.h>
|
||||
#endif
|
||||
struct FPSLimiter
|
||||
{
|
||||
uint64_t lastTickCount;
|
||||
|
@ -420,6 +422,7 @@ struct FPSLimiter
|
|||
private:
|
||||
void delayTicks(uint64_t ticks)
|
||||
{
|
||||
#ifndef __EMSCRIPTEN__
|
||||
#if defined(HAVE_NANOSLEEP)
|
||||
struct timespec req;
|
||||
uint64_t nsec = ticks / tickFreqNS;
|
||||
|
@ -441,6 +444,10 @@ private:
|
|||
}
|
||||
#else
|
||||
SDL_Delay(ticks / tickFreqMS);
|
||||
#endif
|
||||
#endif
|
||||
#ifdef __EMSCRIPTEN
|
||||
emscripten_sleep(ticks /tickFreqMS);
|
||||
#endif
|
||||
}
|
||||
};
|
||||
|
|
11
src/main.cpp
11
src/main.cpp
|
@ -232,7 +232,7 @@ int main(int argc, char *argv[])
|
|||
}
|
||||
|
||||
conf.readGameINI();
|
||||
|
||||
printf("%s\n", conf.gameFolder.c_str());
|
||||
assert(conf.rgssVersion >= 1 && conf.rgssVersion <= 3);
|
||||
printRgssVersion(conf.rgssVersion);
|
||||
|
||||
|
@ -322,8 +322,9 @@ int main(int argc, char *argv[])
|
|||
rtData.bindingUpdateMsg.post(loadBindings(conf));
|
||||
|
||||
/* Start RGSS thread */
|
||||
SDL_Thread *rgssThread =
|
||||
SDL_CreateThread(rgssThreadFun, "rgss", &rtData);
|
||||
//SDL_Thread *rgssThread =
|
||||
// SDL_CreateThread(rgssThreadFun, "rgss", &rtData);
|
||||
::rgssThreadFun(&rtData);
|
||||
|
||||
/* Start event processing */
|
||||
eventThread.process(rtData);
|
||||
|
@ -347,8 +348,8 @@ int main(int argc, char *argv[])
|
|||
|
||||
/* If RGSS thread ack'd request, wait for it to shutdown,
|
||||
* otherwise abandon hope and just end the process as is. */
|
||||
if (rtData.rqTermAck)
|
||||
SDL_WaitThread(rgssThread, 0);
|
||||
if (rtData.rqTermAck){}
|
||||
//SDL_WaitThread(rgssThread, 0);
|
||||
else
|
||||
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, conf.game.title.c_str(),
|
||||
"The RGSS script seems to be stuck and mkxp will now force quit", win);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue