Make changes for Emscripten
This commit is contained in:
parent
776564d583
commit
8c5db3a401
|
@ -27,7 +27,7 @@
|
||||||
#define DEF_PLAY_STOP(entity) \
|
#define DEF_PLAY_STOP(entity) \
|
||||||
MRB_FUNCTION(audio_##entity##Play) \
|
MRB_FUNCTION(audio_##entity##Play) \
|
||||||
{ \
|
{ \
|
||||||
char *filename; \
|
return mrb_nil_value();char *filename; \
|
||||||
mrb_int volume = 100; \
|
mrb_int volume = 100; \
|
||||||
mrb_int pitch = 100; \
|
mrb_int pitch = 100; \
|
||||||
mrb_get_args(mrb, "z|ii", &filename, &volume, &pitch); \
|
mrb_get_args(mrb, "z|ii", &filename, &volume, &pitch); \
|
||||||
|
@ -36,7 +36,7 @@
|
||||||
} \
|
} \
|
||||||
MRB_FUNCTION(audio_##entity##Stop) \
|
MRB_FUNCTION(audio_##entity##Stop) \
|
||||||
{ \
|
{ \
|
||||||
MRB_FUN_UNUSED_PARAM; \
|
return mrb_nil_value();MRB_FUN_UNUSED_PARAM; \
|
||||||
shState->audio().entity##Stop(); \
|
shState->audio().entity##Stop(); \
|
||||||
return mrb_nil_value(); \
|
return mrb_nil_value(); \
|
||||||
}
|
}
|
||||||
|
@ -44,7 +44,7 @@
|
||||||
#define DEF_FADE(entity) \
|
#define DEF_FADE(entity) \
|
||||||
MRB_FUNCTION(audio_##entity##Fade) \
|
MRB_FUNCTION(audio_##entity##Fade) \
|
||||||
{ \
|
{ \
|
||||||
mrb_int time; \
|
return mrb_nil_value();mrb_int time; \
|
||||||
mrb_get_args(mrb, "i", &time); \
|
mrb_get_args(mrb, "i", &time); \
|
||||||
shState->audio().entity##Fade(time); \
|
shState->audio().entity##Fade(time); \
|
||||||
return mrb_nil_value(); \
|
return mrb_nil_value(); \
|
||||||
|
|
|
@ -48,6 +48,13 @@
|
||||||
#include "binding-util.h"
|
#include "binding-util.h"
|
||||||
#include "binding-types.h"
|
#include "binding-types.h"
|
||||||
#include "mrb-ext/marshal.h"
|
#include "mrb-ext/marshal.h"
|
||||||
|
#include "mrb-ext/file-helper.h"
|
||||||
|
|
||||||
|
#ifdef __EMSCRIPTEN__
|
||||||
|
#include <emscripten.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
static void mrbBindingExecute();
|
static void mrbBindingExecute();
|
||||||
static void mrbBindingTerminate();
|
static void mrbBindingTerminate();
|
||||||
|
@ -65,7 +72,6 @@ ScriptBinding *scriptBinding = &scriptBindingImpl;
|
||||||
|
|
||||||
void fileBindingInit(mrb_state *);
|
void fileBindingInit(mrb_state *);
|
||||||
void timeBindingInit(mrb_state *);
|
void timeBindingInit(mrb_state *);
|
||||||
void marshalBindingInit(mrb_state *);
|
|
||||||
void kernelBindingInit(mrb_state *);
|
void kernelBindingInit(mrb_state *);
|
||||||
|
|
||||||
void tableBindingInit(mrb_state *);
|
void tableBindingInit(mrb_state *);
|
||||||
|
@ -82,9 +88,6 @@ void inputBindingInit(mrb_state *);
|
||||||
void audioBindingInit(mrb_state *);
|
void audioBindingInit(mrb_state *);
|
||||||
void graphicsBindingInit(mrb_state *);
|
void graphicsBindingInit(mrb_state *);
|
||||||
|
|
||||||
/* From module_rpg.c */
|
|
||||||
extern const uint8_t mrbModuleRPG[];
|
|
||||||
|
|
||||||
static void mrbBindingInit(mrb_state *mrb)
|
static void mrbBindingInit(mrb_state *mrb)
|
||||||
{
|
{
|
||||||
int arena = mrb_gc_arena_save(mrb);
|
int arena = mrb_gc_arena_save(mrb);
|
||||||
|
@ -92,7 +95,6 @@ static void mrbBindingInit(mrb_state *mrb)
|
||||||
/* Init standard classes */
|
/* Init standard classes */
|
||||||
fileBindingInit(mrb);
|
fileBindingInit(mrb);
|
||||||
timeBindingInit(mrb);
|
timeBindingInit(mrb);
|
||||||
marshalBindingInit(mrb);
|
|
||||||
kernelBindingInit(mrb);
|
kernelBindingInit(mrb);
|
||||||
|
|
||||||
/* Init RGSS classes */
|
/* Init RGSS classes */
|
||||||
|
@ -111,13 +113,10 @@ static void mrbBindingInit(mrb_state *mrb)
|
||||||
audioBindingInit(mrb);
|
audioBindingInit(mrb);
|
||||||
graphicsBindingInit(mrb);
|
graphicsBindingInit(mrb);
|
||||||
|
|
||||||
/* Load RPG module */
|
|
||||||
mrb_load_irep(mrb, mrbModuleRPG);
|
|
||||||
|
|
||||||
/* Load global constants */
|
/* Load global constants */
|
||||||
mrb_define_global_const(mrb, "MKXP", mrb_true_value());
|
mrb_define_global_const(mrb, "MKXP", mrb_true_value());
|
||||||
|
|
||||||
mrb_value debug = rb_bool_new(shState->config().editor.debug);
|
mrb_value debug = mrb_bool_value(shState->config().editor.debug);
|
||||||
if (rgssVer == 1)
|
if (rgssVer == 1)
|
||||||
mrb_define_global_const(mrb, "DEBUG", debug);
|
mrb_define_global_const(mrb, "DEBUG", debug);
|
||||||
else if (rgssVer >= 2)
|
else if (rgssVer >= 2)
|
||||||
|
@ -254,6 +253,14 @@ runMrbFile(mrb_state *mrb, const char *filename)
|
||||||
fclose(f);
|
fclose(f);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mrb_state * static_mrb;
|
||||||
|
mrb_state * static_scriptmrb;
|
||||||
|
mrbc_context * static_ctx;
|
||||||
|
|
||||||
|
void main_update_loop() {
|
||||||
|
mrb_load_nstring_cxt(static_mrb, "main_update_loop", 16, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
runRMXPScripts(mrb_state *mrb, mrbc_context *ctx)
|
runRMXPScripts(mrb_state *mrb, mrbc_context *ctx)
|
||||||
{
|
{
|
||||||
|
@ -273,24 +280,23 @@ runRMXPScripts(mrb_state *mrb, mrbc_context *ctx)
|
||||||
|
|
||||||
/* We use a secondary util state to unmarshal the scripts */
|
/* We use a secondary util state to unmarshal the scripts */
|
||||||
mrb_state *scriptMrb = mrb_open();
|
mrb_state *scriptMrb = mrb_open();
|
||||||
SDL_RWops ops;
|
|
||||||
|
|
||||||
shState->fileSystem().openReadRaw(ops, scriptPack.c_str());
|
|
||||||
|
|
||||||
mrb_value scriptArray = mrb_nil_value();
|
mrb_value scriptArray = mrb_nil_value();
|
||||||
std::string readError;
|
std::string readError;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
scriptArray = marshalLoadInt(scriptMrb, &ops);
|
SDL_rw_file_helper fileHelper;
|
||||||
|
fileHelper.filename = scriptPack.c_str();
|
||||||
|
char * contents = fileHelper.read();
|
||||||
|
mrb_value rawdata = mrb_str_new_static(mrb, contents, fileHelper.length);
|
||||||
|
scriptArray = mrb_marshal_load(mrb, rawdata);
|
||||||
}
|
}
|
||||||
catch (const Exception &e)
|
catch (const Exception &e)
|
||||||
{
|
{
|
||||||
readError = std::string(": ") + e.msg;
|
readError = std::string(": ") + e.msg;
|
||||||
}
|
}
|
||||||
|
|
||||||
SDL_RWclose(&ops);
|
|
||||||
|
|
||||||
if (!mrb_array_p(scriptArray))
|
if (!mrb_array_p(scriptArray))
|
||||||
{
|
{
|
||||||
showError(std::string("Failed to read script data") + readError);
|
showError(std::string("Failed to read script data") + readError);
|
||||||
|
@ -298,7 +304,7 @@ runRMXPScripts(mrb_state *mrb, mrbc_context *ctx)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
int scriptCount = mrb_ary_len(scriptMrb, scriptArray);
|
int scriptCount = RARRAY_LEN(scriptArray);
|
||||||
|
|
||||||
std::string decodeBuffer;
|
std::string decodeBuffer;
|
||||||
decodeBuffer.resize(0x1000);
|
decodeBuffer.resize(0x1000);
|
||||||
|
@ -357,11 +363,28 @@ runRMXPScripts(mrb_state *mrb, mrbc_context *ctx)
|
||||||
|
|
||||||
mrb_gc_arena_restore(mrb, ai);
|
mrb_gc_arena_restore(mrb, ai);
|
||||||
|
|
||||||
if (mrb->exc)
|
if (mrb->exc) {
|
||||||
|
printf("%s - err\n", ctx->filename);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
static_mrb = mrb;
|
||||||
|
static_scriptmrb = scriptMrb;
|
||||||
|
|
||||||
|
#ifdef __EMSCRIPTEN__
|
||||||
|
/* Use loop for emscripten */
|
||||||
|
main_update_loop();
|
||||||
|
checkException(static_mrb);
|
||||||
|
emscripten_set_main_loop(main_update_loop, 0, 0);
|
||||||
|
#else
|
||||||
|
while (true) {
|
||||||
|
main_update_loop();
|
||||||
|
SDL_Delay(3);
|
||||||
|
if (static_mrb->exc)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
mrb_close(scriptMrb);
|
mrb_close(scriptMrb);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
static void mrbBindingExecute()
|
static void mrbBindingExecute()
|
||||||
|
@ -370,29 +393,27 @@ static void mrbBindingExecute()
|
||||||
|
|
||||||
shState->setBindingData(mrb);
|
shState->setBindingData(mrb);
|
||||||
|
|
||||||
MrbData mrbData(mrb);
|
MrbData * mrbData = new MrbData(mrb);
|
||||||
mrb->ud = &mrbData;
|
mrb->ud = mrbData;
|
||||||
|
|
||||||
mrb_define_module_function(mrb, mrb->kernel_module, "time_op",
|
mrb_define_module_function(mrb, mrb->kernel_module, "time_op",
|
||||||
mkxpTimeOp, MRB_ARGS_OPT(2) | MRB_ARGS_BLOCK());
|
mkxpTimeOp, MRB_ARGS_OPT(2) | MRB_ARGS_BLOCK());
|
||||||
|
|
||||||
mrbBindingInit(mrb);
|
mrbBindingInit(mrb);
|
||||||
|
|
||||||
mrbc_context *ctx = mrbc_context_new(mrb);
|
static_ctx = mrbc_context_new(mrb);
|
||||||
ctx->capture_errors = 1;
|
static_ctx->capture_errors = 1;
|
||||||
|
|
||||||
const Config &conf = shState->rtData().config;
|
const Config &conf = shState->rtData().config;
|
||||||
const std::string &customScript = conf.customScript;
|
const std::string &customScript = conf.customScript;
|
||||||
// const std::string &mrbFile = conf.mrbFile;
|
|
||||||
(void) runMrbFile; // FIXME mrbFile support on ice for now
|
(void) runMrbFile; // FIXME mrbFile support on ice for now
|
||||||
|
|
||||||
if (!customScript.empty())
|
if (!customScript.empty())
|
||||||
runCustomScript(mrb, ctx, customScript.c_str());
|
runCustomScript(mrb, static_ctx, customScript.c_str());
|
||||||
// else if (!mrbFile.empty())
|
|
||||||
// runMrbFile(mrb, mrbFile.c_str());
|
|
||||||
else
|
else
|
||||||
runRMXPScripts(mrb, ctx);
|
runRMXPScripts(mrb, static_ctx);
|
||||||
|
|
||||||
|
#ifndef __EMSCRIPTEN__
|
||||||
checkException(mrb);
|
checkException(mrb);
|
||||||
|
|
||||||
shState->rtData().rqTermAck.set();
|
shState->rtData().rqTermAck.set();
|
||||||
|
@ -400,6 +421,7 @@ static void mrbBindingExecute()
|
||||||
|
|
||||||
mrbc_context_free(mrb, ctx);
|
mrbc_context_free(mrb, ctx);
|
||||||
mrb_close(mrb);
|
mrb_close(mrb);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
static void mrbBindingTerminate()
|
static void mrbBindingTerminate()
|
||||||
|
|
|
@ -71,8 +71,7 @@ static const MrbExcData excData[] =
|
||||||
{ Shutdown, "SystemExit" },
|
{ Shutdown, "SystemExit" },
|
||||||
{ PHYSFS, "PHYSFSError" },
|
{ PHYSFS, "PHYSFSError" },
|
||||||
{ SDL, "SDLError" },
|
{ SDL, "SDLError" },
|
||||||
{ MKXP, "MKXPError" },
|
{ MKXP, "MKXPError" }
|
||||||
{ IO, "IOError" }
|
|
||||||
};
|
};
|
||||||
|
|
||||||
static elementsN(excData);
|
static elementsN(excData);
|
||||||
|
@ -118,6 +117,7 @@ MrbData::MrbData(mrb_state *mrb)
|
||||||
|
|
||||||
exc[TypeError] = mrb_class_get(mrb, "TypeError");
|
exc[TypeError] = mrb_class_get(mrb, "TypeError");
|
||||||
exc[ArgumentError] = mrb_class_get(mrb, "ArgumentError");
|
exc[ArgumentError] = mrb_class_get(mrb, "ArgumentError");
|
||||||
|
exc[IOError] = mrb_class_get(mrb, "IOError");
|
||||||
|
|
||||||
for (size_t i = 0; i < symDataN; ++i)
|
for (size_t i = 0; i < symDataN; ++i)
|
||||||
symbols[symData[i].ind] = mrb_intern_cstr(mrb, symData[i].str);
|
symbols[symData[i].ind] = mrb_intern_cstr(mrb, symData[i].str);
|
||||||
|
@ -134,6 +134,7 @@ static const MrbException excToMrbExc[] =
|
||||||
|
|
||||||
TypeError,
|
TypeError,
|
||||||
ArgumentError,
|
ArgumentError,
|
||||||
|
IOError,
|
||||||
|
|
||||||
PHYSFS, /* PHYSFSError */
|
PHYSFS, /* PHYSFSError */
|
||||||
SDL, /* SDLError */
|
SDL, /* SDLError */
|
||||||
|
|
|
@ -28,6 +28,7 @@
|
||||||
#include <mruby/data.h>
|
#include <mruby/data.h>
|
||||||
#include <mruby/variable.h>
|
#include <mruby/variable.h>
|
||||||
#include <mruby/class.h>
|
#include <mruby/class.h>
|
||||||
|
#include <mruby/string.h>
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
|
@ -90,6 +91,7 @@ enum MrbException
|
||||||
|
|
||||||
TypeError,
|
TypeError,
|
||||||
ArgumentError,
|
ArgumentError,
|
||||||
|
IOError,
|
||||||
|
|
||||||
MrbExceptionsMax
|
MrbExceptionsMax
|
||||||
};
|
};
|
||||||
|
@ -352,11 +354,13 @@ inline mrb_value
|
||||||
objectLoad(mrb_state *mrb, mrb_value self, const mrb_data_type &type)
|
objectLoad(mrb_state *mrb, mrb_value self, const mrb_data_type &type)
|
||||||
{
|
{
|
||||||
RClass *klass = mrb_class_ptr(self);
|
RClass *klass = mrb_class_ptr(self);
|
||||||
char *data;
|
|
||||||
int data_len;
|
|
||||||
mrb_get_args(mrb, "s", &data, &data_len);
|
|
||||||
|
|
||||||
C *c = C::deserialize(data, data_len);
|
mrb_value data;
|
||||||
|
mrb_get_args(mrb, "S", &data);
|
||||||
|
|
||||||
|
int data_len = mrb_string_value_len(mrb, data);
|
||||||
|
|
||||||
|
C *c = C::deserialize(RSTRING_PTR(data), data_len);
|
||||||
|
|
||||||
RData *obj = mrb_data_object_alloc(mrb, klass, c, &type);
|
RData *obj = mrb_data_object_alloc(mrb, klass, c, &type);
|
||||||
mrb_value obj_value = mrb_obj_value(obj);
|
mrb_value obj_value = mrb_obj_value(obj);
|
||||||
|
|
|
@ -27,25 +27,25 @@
|
||||||
#include "binding-util.h"
|
#include "binding-util.h"
|
||||||
#include "binding-types.h"
|
#include "binding-types.h"
|
||||||
|
|
||||||
|
#include <mruby/string.h>
|
||||||
|
|
||||||
DEF_TYPE(Bitmap);
|
DEF_TYPE(Bitmap);
|
||||||
|
|
||||||
MRB_METHOD(bitmapInitialize)
|
MRB_METHOD(bitmapInitialize)
|
||||||
{
|
{
|
||||||
Bitmap *b = 0;
|
Bitmap *b = 0;
|
||||||
|
|
||||||
if (mrb->c->ci->argc == 1)
|
mrb_value one, two;
|
||||||
{
|
int argc = mrb_get_args(mrb, "o|i", &one, &two);
|
||||||
char *filename;
|
|
||||||
mrb_get_args(mrb, "z", &filename);
|
|
||||||
|
|
||||||
GUARD_EXC( b = new Bitmap(filename); )
|
if (argc == 1)
|
||||||
|
{
|
||||||
|
const char *fmt = RSTRING_CSTR(mrb, one);
|
||||||
|
GUARD_EXC( b = new Bitmap(fmt); )
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
mrb_int width, height;
|
GUARD_EXC( b = new Bitmap(mrb_fixnum(one), mrb_fixnum(two)); )
|
||||||
mrb_get_args(mrb, "ii", &width, &height);
|
|
||||||
|
|
||||||
GUARD_EXC( b = new Bitmap(width, height); )
|
|
||||||
}
|
}
|
||||||
|
|
||||||
setPrivateData(self, b, BitmapType);
|
setPrivateData(self, b, BitmapType);
|
||||||
|
@ -149,12 +149,14 @@ MRB_METHOD(bitmapFillRect)
|
||||||
mrb_value colorObj;
|
mrb_value colorObj;
|
||||||
Color *color;
|
Color *color;
|
||||||
|
|
||||||
if (mrb->c->ci->argc == 2)
|
mrb_value one, two, three, four, five;
|
||||||
{
|
int argc = mrb_get_args(mrb, "oo|iio", &one, &two, &three, &four, &five);
|
||||||
mrb_value rectObj;
|
|
||||||
Rect *rect;
|
|
||||||
|
|
||||||
mrb_get_args(mrb, "oo", &rectObj, &colorObj);
|
if (argc == 2)
|
||||||
|
{
|
||||||
|
mrb_value rectObj = one;
|
||||||
|
colorObj = two;
|
||||||
|
Rect *rect;
|
||||||
|
|
||||||
rect = getPrivateDataCheck<Rect>(mrb, rectObj, RectType);
|
rect = getPrivateDataCheck<Rect>(mrb, rectObj, RectType);
|
||||||
color = getPrivateDataCheck<Color>(mrb, colorObj, ColorType);
|
color = getPrivateDataCheck<Color>(mrb, colorObj, ColorType);
|
||||||
|
@ -163,9 +165,11 @@ MRB_METHOD(bitmapFillRect)
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
mrb_int x, y, width, height;
|
mrb_int x = mrb_fixnum(one),
|
||||||
|
y = mrb_fixnum(two),
|
||||||
mrb_get_args(mrb, "iiiio", &x, &y, &width, &height, &colorObj);
|
width = mrb_fixnum(three),
|
||||||
|
height = mrb_fixnum(four);
|
||||||
|
colorObj = five;
|
||||||
|
|
||||||
color = getPrivateDataCheck<Color>(mrb, colorObj, ColorType);
|
color = getPrivateDataCheck<Color>(mrb, colorObj, ColorType);
|
||||||
|
|
||||||
|
|
|
@ -49,7 +49,12 @@ MRB_METHOD(fontInitialize)
|
||||||
|
|
||||||
mrb_get_args(mrb, "|zi", &name, &size);
|
mrb_get_args(mrb, "|zi", &name, &size);
|
||||||
|
|
||||||
Font *f = new Font(name, size);
|
Font *f;
|
||||||
|
|
||||||
|
std::vector<std::string> names;
|
||||||
|
names.push_back(name);
|
||||||
|
|
||||||
|
f = new Font(&names, size);
|
||||||
|
|
||||||
setPrivateData(self, f, FontType);
|
setPrivateData(self, f, FontType);
|
||||||
|
|
||||||
|
@ -86,9 +91,7 @@ MRB_METHOD(fontInitializeCopy)
|
||||||
|
|
||||||
MRB_METHOD(FontGetName)
|
MRB_METHOD(FontGetName)
|
||||||
{
|
{
|
||||||
Font *f = getPrivateData<Font>(mrb, self);
|
return mrb_iv_get(mrb, self, mrb_intern_cstr(mrb, "name"));
|
||||||
|
|
||||||
return mrb_str_new_cstr(mrb, f->getName());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
MRB_METHOD(FontSetName)
|
MRB_METHOD(FontSetName)
|
||||||
|
@ -98,7 +101,11 @@ MRB_METHOD(FontSetName)
|
||||||
mrb_value name;
|
mrb_value name;
|
||||||
mrb_get_args(mrb, "S", &name);
|
mrb_get_args(mrb, "S", &name);
|
||||||
|
|
||||||
f->setName(RSTRING_PTR(name));
|
std::vector<std::string> names;
|
||||||
|
names.push_back(RSTRING_PTR(name));
|
||||||
|
|
||||||
|
f->setName(names);
|
||||||
|
mrb_iv_set(mrb, self, mrb_intern_cstr(mrb, "name"), name);
|
||||||
|
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
@ -135,17 +142,21 @@ DEF_KLASS_PROP(Font, mrb_bool, DefaultItalic, "b", bool)
|
||||||
DEF_KLASS_PROP(Font, mrb_bool, DefaultOutline, "b", bool)
|
DEF_KLASS_PROP(Font, mrb_bool, DefaultOutline, "b", bool)
|
||||||
DEF_KLASS_PROP(Font, mrb_bool, DefaultShadow, "b", bool)
|
DEF_KLASS_PROP(Font, mrb_bool, DefaultShadow, "b", bool)
|
||||||
|
|
||||||
MRB_FUNCTION(FontGetDefaultName)
|
MRB_METHOD(FontGetDefaultName)
|
||||||
{
|
{
|
||||||
return mrb_str_new_cstr(mrb, Font::getDefaultName());
|
return mrb_iv_get(mrb, self, mrb_intern_cstr(mrb, "default_name"));
|
||||||
}
|
}
|
||||||
|
|
||||||
MRB_FUNCTION(FontSetDefaultName)
|
MRB_METHOD(FontSetDefaultName)
|
||||||
{
|
{
|
||||||
mrb_value nameObj;
|
mrb_value nameObj;
|
||||||
mrb_get_args(mrb, "S", &nameObj);
|
mrb_get_args(mrb, "S", &nameObj);
|
||||||
|
|
||||||
Font::setDefaultName(RSTRING_PTR(nameObj));
|
std::vector<std::string> names;
|
||||||
|
names.push_back(RSTRING_PTR(nameObj));
|
||||||
|
|
||||||
|
Font::setDefaultName(names, shState->fontState());
|
||||||
|
mrb_iv_set(mrb, self, mrb_intern_cstr(mrb, "default_name"), nameObj);
|
||||||
|
|
||||||
return nameObj;
|
return nameObj;
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,11 +27,13 @@
|
||||||
|
|
||||||
#include <mruby/hash.h>
|
#include <mruby/hash.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include "eventthread.h"
|
||||||
|
|
||||||
MRB_FUNCTION(inputUpdate)
|
MRB_FUNCTION(inputUpdate)
|
||||||
{
|
{
|
||||||
MRB_FUN_UNUSED_PARAM;
|
MRB_FUN_UNUSED_PARAM;
|
||||||
|
|
||||||
|
shState->eThread().process(shState->rtData());
|
||||||
shState->input().update();
|
shState->input().update();
|
||||||
|
|
||||||
return mrb_nil_value();
|
return mrb_nil_value();
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,43 @@
|
||||||
|
|
||||||
|
#include "file-helper.h"
|
||||||
|
#include <SDL_rwops.h>
|
||||||
|
|
||||||
|
char* SDL_rw_file_helper::read() {
|
||||||
|
SDL_RWops *rw = SDL_RWFromFile(filename, "rb");
|
||||||
|
if (rw == NULL) return NULL;
|
||||||
|
|
||||||
|
Sint64 res_size = SDL_RWsize(rw);
|
||||||
|
char* res = (char*)malloc(res_size + 1);
|
||||||
|
|
||||||
|
Sint64 nb_read_total = 0, nb_read = 1;
|
||||||
|
char* buf = res;
|
||||||
|
while (nb_read_total < res_size && nb_read != 0) {
|
||||||
|
nb_read = SDL_RWread(rw, buf, 1, (res_size - nb_read_total));
|
||||||
|
nb_read_total += nb_read;
|
||||||
|
buf += nb_read;
|
||||||
|
}
|
||||||
|
SDL_RWclose(rw);
|
||||||
|
if (nb_read_total != res_size) {
|
||||||
|
free(res);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
res[nb_read_total] = '\0';
|
||||||
|
length = nb_read_total;
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool SDL_rw_file_helper::write(char * data) {
|
||||||
|
SDL_RWops *rw = SDL_RWFromFile(filename, "w");
|
||||||
|
if(rw != NULL) {
|
||||||
|
size_t len = SDL_strlen(data);
|
||||||
|
if (SDL_RWwrite(rw, data, 1, len) != len) {
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
SDL_RWclose(rw);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
|
@ -0,0 +1,6 @@
|
||||||
|
struct SDL_rw_file_helper {
|
||||||
|
const char * filename;
|
||||||
|
char * read();
|
||||||
|
int length;
|
||||||
|
bool write(char * data);
|
||||||
|
};
|
|
@ -454,10 +454,11 @@ MRB_METHOD(fileReadLines)
|
||||||
FILE *f = p->fp();
|
FILE *f = p->fp();
|
||||||
|
|
||||||
mrb_value arg;
|
mrb_value arg;
|
||||||
mrb_get_args(mrb, "|o", &arg);
|
int argc = mrb_get_args(mrb, "|o", &arg);
|
||||||
|
|
||||||
const char *rs = "\n"; (void) rs;
|
const char *rs = "\n"; (void) rs;
|
||||||
if (mrb->c->ci->argc > 0)
|
|
||||||
|
if (argc > 0)
|
||||||
{
|
{
|
||||||
Debug() << "FIXME: File.readlines: rs not implemented";
|
Debug() << "FIXME: File.readlines: rs not implemented";
|
||||||
|
|
||||||
|
@ -596,7 +597,7 @@ fileBindingInit(mrb_state *mrb)
|
||||||
mrb_define_method(mrb, klass, "path", fileGetPath, MRB_ARGS_NONE());
|
mrb_define_method(mrb, klass, "path", fileGetPath, MRB_ARGS_NONE());
|
||||||
|
|
||||||
/* FileTest */
|
/* FileTest */
|
||||||
RClass *module = mrb_define_module(mrb, "FileTest");
|
RClass *module = mrb_define_module(mrb, "MKXPFileTest");
|
||||||
mrb_define_module_function(mrb, module, "exist?", fileTestDoesExist, MRB_ARGS_REQ(1));
|
mrb_define_module_function(mrb, module, "exist?", fileTestDoesExist, MRB_ARGS_REQ(1));
|
||||||
mrb_define_module_function(mrb, module, "directory?", fileTestIsDirectory, MRB_ARGS_REQ(1));
|
mrb_define_module_function(mrb, module, "directory?", fileTestIsDirectory, MRB_ARGS_REQ(1));
|
||||||
mrb_define_module_function(mrb, module, "file?", fileTestIsFile, MRB_ARGS_REQ(1));
|
mrb_define_module_function(mrb, module, "file?", fileTestIsFile, MRB_ARGS_REQ(1));
|
||||||
|
|
|
@ -30,6 +30,7 @@
|
||||||
|
|
||||||
#include "../binding-util.h"
|
#include "../binding-util.h"
|
||||||
#include "marshal.h"
|
#include "marshal.h"
|
||||||
|
#include "file-helper.h"
|
||||||
#include "sharedstate.h"
|
#include "sharedstate.h"
|
||||||
#include "eventthread.h"
|
#include "eventthread.h"
|
||||||
#include "exception.h"
|
#include "exception.h"
|
||||||
|
@ -137,10 +138,11 @@ MRB_FUNCTION(kernelSrand)
|
||||||
{
|
{
|
||||||
srandCalled = true;
|
srandCalled = true;
|
||||||
|
|
||||||
if (mrb->c->ci->argc == 1)
|
|
||||||
{
|
|
||||||
mrb_int seed;
|
mrb_int seed;
|
||||||
mrb_get_args(mrb, "i", &seed);
|
int argc = mrb_get_args(mrb, "|i", &seed);
|
||||||
|
|
||||||
|
if (argc == 1)
|
||||||
|
{
|
||||||
srand(seed);
|
srand(seed);
|
||||||
|
|
||||||
int oldSeed = currentSeed;
|
int oldSeed = currentSeed;
|
||||||
|
@ -171,19 +173,19 @@ MRB_FUNCTION(kernelLoadData)
|
||||||
const char *filename;
|
const char *filename;
|
||||||
mrb_get_args(mrb, "z", &filename);
|
mrb_get_args(mrb, "z", &filename);
|
||||||
|
|
||||||
SDL_RWops ops;
|
|
||||||
GUARD_EXC( shState->fileSystem().openRead(ops, filename); )
|
|
||||||
|
|
||||||
mrb_value obj;
|
mrb_value obj;
|
||||||
try { obj = marshalLoadInt(mrb, &ops); }
|
try {
|
||||||
|
SDL_rw_file_helper fileHelper;
|
||||||
|
fileHelper.filename = filename;
|
||||||
|
char * contents = fileHelper.read();
|
||||||
|
mrb_value rawdata = mrb_str_new_static(mrb, contents, fileHelper.length);
|
||||||
|
obj = mrb_marshal_load(mrb, rawdata);
|
||||||
|
}
|
||||||
catch (const Exception &e)
|
catch (const Exception &e)
|
||||||
{
|
{
|
||||||
SDL_RWclose(&ops);
|
|
||||||
raiseMrbExc(mrb, e);
|
raiseMrbExc(mrb, e);
|
||||||
}
|
}
|
||||||
|
|
||||||
SDL_RWclose(&ops);
|
|
||||||
|
|
||||||
return obj;
|
return obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -194,19 +196,18 @@ MRB_FUNCTION(kernelSaveData)
|
||||||
|
|
||||||
mrb_get_args(mrb, "oz", &obj, &filename);
|
mrb_get_args(mrb, "oz", &obj, &filename);
|
||||||
|
|
||||||
SDL_RWops *ops = SDL_RWFromFile(filename, "w");
|
try {
|
||||||
if (!ops)
|
mrb_value dumped = mrb_nil_value();
|
||||||
mrb_raise(mrb, getMrbData(mrb)->exc[SDL], SDL_GetError());
|
mrb_marshal_dump(mrb, obj, dumped);
|
||||||
|
SDL_rw_file_helper fileHelper;
|
||||||
try { marshalDumpInt(mrb, ops, obj); }
|
fileHelper.filename = filename;
|
||||||
|
fileHelper.write(RSTRING_PTR(dumped));
|
||||||
|
}
|
||||||
catch (const Exception &e)
|
catch (const Exception &e)
|
||||||
{
|
{
|
||||||
SDL_RWclose(ops);
|
|
||||||
raiseMrbExc(mrb, e);
|
raiseMrbExc(mrb, e);
|
||||||
}
|
}
|
||||||
|
|
||||||
SDL_RWclose(ops);
|
|
||||||
|
|
||||||
return mrb_nil_value();
|
return mrb_nil_value();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1,31 +1,15 @@
|
||||||
/*
|
#ifndef MRUBY_MARSHAL_H
|
||||||
** marshal.h
|
#define MRUBY_MARSHAL_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 MARSHAL_H
|
#if defined(__cplusplus)
|
||||||
#define MARSHAL_H
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <mruby.h>
|
mrb_value mrb_marshal_dump(mrb_state* M, mrb_value v, mrb_value out);
|
||||||
#include <SDL_rwops.h>
|
mrb_value mrb_marshal_load(mrb_state* M, mrb_value str);
|
||||||
|
|
||||||
void marshalDumpInt(mrb_state *, SDL_RWops *, mrb_value);
|
#if defined(__cplusplus)
|
||||||
mrb_value marshalLoadInt(mrb_state *, SDL_RWops *);
|
} /* extern "C" { */
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif // MARSHAL_H
|
#endif /* MRUBY_ARRAY_H */
|
||||||
|
|
|
@ -27,7 +27,7 @@
|
||||||
|
|
||||||
#include "time.h"
|
#include "time.h"
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
struct TimeImpl
|
struct TimeImpl
|
||||||
{
|
{
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -32,24 +32,26 @@ MRB_METHOD(viewportInitialize)
|
||||||
{
|
{
|
||||||
Viewport *v;
|
Viewport *v;
|
||||||
|
|
||||||
if (mrb->c->ci->argc == 1)
|
mrb_value one, two, three, four;
|
||||||
|
int argc = mrb_get_args(mrb, "o|iii", &one, &two, &three, &four);
|
||||||
|
|
||||||
|
if (argc == 1)
|
||||||
{
|
{
|
||||||
/* The rect arg is only used to init the viewport,
|
/* The rect arg is only used to init the viewport,
|
||||||
* and does NOT replace its 'rect' property */
|
* and does NOT replace its 'rect' property */
|
||||||
mrb_value rectObj;
|
mrb_value rectObj = one;
|
||||||
Rect *rect;
|
Rect *rect;
|
||||||
|
|
||||||
mrb_get_args(mrb, "o", &rectObj);
|
|
||||||
|
|
||||||
rect = getPrivateDataCheck<Rect>(mrb, rectObj, RectType);
|
rect = getPrivateDataCheck<Rect>(mrb, rectObj, RectType);
|
||||||
|
|
||||||
v = new Viewport(rect);
|
v = new Viewport(rect);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
mrb_int x, y, width, height;
|
mrb_int x = mrb_fixnum(one),
|
||||||
|
y = mrb_fixnum(two),
|
||||||
mrb_get_args(mrb, "iiii", &x, &y, &width, &height);
|
width = mrb_fixnum(three),
|
||||||
|
height = mrb_fixnum(four);
|
||||||
|
|
||||||
v = new Viewport(x, y, width, height);
|
v = new Viewport(x, y, width, height);
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,7 +22,7 @@
|
||||||
#ifndef ALUTIL_H
|
#ifndef ALUTIL_H
|
||||||
#define ALUTIL_H
|
#define ALUTIL_H
|
||||||
|
|
||||||
#include <al.h>
|
#include <AL/al.h>
|
||||||
#include <SDL_audio.h>
|
#include <SDL_audio.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
|
||||||
|
|
|
@ -210,7 +210,7 @@ struct ALStreamOpenHandler : FileSystem::OpenHandler
|
||||||
: srcOps(&srcOps), looped(looped), source(0)
|
: srcOps(&srcOps), looped(looped), source(0)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
bool tryRead(SDL_RWops &ops, const char *ext)
|
bool tryRead(SDL_RWops &ops, const char *ext, const char *fullPath)
|
||||||
{
|
{
|
||||||
/* Copy this because we need to keep it around,
|
/* Copy this because we need to keep it around,
|
||||||
* as we will continue reading data from it later */
|
* as we will continue reading data from it later */
|
||||||
|
|
|
@ -241,9 +241,13 @@ struct BitmapOpenHandler : FileSystem::OpenHandler
|
||||||
: surf(0)
|
: surf(0)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
bool tryRead(SDL_RWops &ops, const char *ext)
|
bool tryRead(SDL_RWops &ops, const char *ext, const char * fullPath)
|
||||||
{
|
{
|
||||||
|
#ifdef __EMSCRIPTEN__
|
||||||
|
surf = IMG_Load(fullPath);
|
||||||
|
#else
|
||||||
surf = IMG_LoadTyped_RW(&ops, 1, ext);
|
surf = IMG_LoadTyped_RW(&ops, 1, ext);
|
||||||
|
#endif
|
||||||
return surf != 0;
|
return surf != 0;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -254,9 +258,11 @@ Bitmap::Bitmap(const char *filename)
|
||||||
shState->fileSystem().openRead(handler, filename);
|
shState->fileSystem().openRead(handler, filename);
|
||||||
SDL_Surface *imgSurf = handler.surf;
|
SDL_Surface *imgSurf = handler.surf;
|
||||||
|
|
||||||
if (!imgSurf)
|
if (!imgSurf) {
|
||||||
|
printf("ERROR OCCURED LOADING IMAGE %s : %s\n", filename, SDL_GetError());
|
||||||
throw Exception(Exception::SDLError, "Error loading image '%s': %s",
|
throw Exception(Exception::SDLError, "Error loading image '%s': %s",
|
||||||
filename, SDL_GetError());
|
filename, SDL_GetError());
|
||||||
|
}
|
||||||
|
|
||||||
p->ensureFormat(imgSurf, SDL_PIXELFORMAT_ABGR8888);
|
p->ensureFormat(imgSurf, SDL_PIXELFORMAT_ABGR8888);
|
||||||
|
|
||||||
|
|
|
@ -150,14 +150,9 @@ Config::Config()
|
||||||
|
|
||||||
void Config::read(int argc, char *argv[])
|
void Config::read(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
gameFolder = "game";
|
#undef PO_DESC
|
||||||
defScreenW = 640;
|
#define PO_DESC(a, b, c) a = c;
|
||||||
defScreenH = 480;
|
|
||||||
enableBlitting = true;
|
|
||||||
smoothScaling = true;
|
|
||||||
subImageFix = false;
|
|
||||||
|
|
||||||
#if 0
|
|
||||||
#define PO_DESC_ALL \
|
#define PO_DESC_ALL \
|
||||||
PO_DESC(rgssVersion, int, 0) \
|
PO_DESC(rgssVersion, int, 0) \
|
||||||
PO_DESC(debugMode, bool, false) \
|
PO_DESC(debugMode, bool, false) \
|
||||||
|
@ -194,6 +189,19 @@ void Config::read(int argc, char *argv[])
|
||||||
PO_DESC(pathCache, bool, true) \
|
PO_DESC(pathCache, bool, true) \
|
||||||
PO_DESC(useScriptNames, bool, false)
|
PO_DESC(useScriptNames, bool, false)
|
||||||
|
|
||||||
|
PO_DESC_ALL;
|
||||||
|
gameFolder = "game";
|
||||||
|
fixedFramerate = -1;
|
||||||
|
syncToRefreshrate = false;
|
||||||
|
rgssVersion = 1;
|
||||||
|
defScreenW = 640;
|
||||||
|
defScreenH = 480;
|
||||||
|
enableBlitting = false;
|
||||||
|
|
||||||
|
#undef PO_DESC
|
||||||
|
#undef PO_DESC_ALL
|
||||||
|
|
||||||
|
#if 0
|
||||||
// Not gonna take your shit boost
|
// Not gonna take your shit boost
|
||||||
#define GUARD_ALL( exp ) try { exp } catch(...) {}
|
#define GUARD_ALL( exp ) try { exp } catch(...) {}
|
||||||
|
|
||||||
|
|
|
@ -29,9 +29,8 @@
|
||||||
#include <SDL_touch.h>
|
#include <SDL_touch.h>
|
||||||
#include <SDL_rect.h>
|
#include <SDL_rect.h>
|
||||||
|
|
||||||
#include <al.h>
|
#include <AL/al.h>
|
||||||
#include <alc.h>
|
#include <AL/alc.h>
|
||||||
#include <alext.h>
|
|
||||||
|
|
||||||
#include "sharedstate.h"
|
#include "sharedstate.h"
|
||||||
#include "graphics.h"
|
#include "graphics.h"
|
||||||
|
@ -41,18 +40,10 @@
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
typedef void (ALC_APIENTRY *LPALCDEVICEPAUSESOFT) (ALCdevice *device);
|
|
||||||
typedef void (ALC_APIENTRY *LPALCDEVICERESUMESOFT) (ALCdevice *device);
|
|
||||||
|
|
||||||
#define AL_DEVICE_PAUSE_FUN \
|
|
||||||
AL_FUN(DevicePause, LPALCDEVICEPAUSESOFT) \
|
|
||||||
AL_FUN(DeviceResume, LPALCDEVICERESUMESOFT)
|
|
||||||
|
|
||||||
struct ALCFunctions
|
struct ALCFunctions
|
||||||
{
|
{
|
||||||
#define AL_FUN(name, type) type name;
|
|
||||||
AL_DEVICE_PAUSE_FUN
|
|
||||||
#undef AL_FUN
|
|
||||||
} static alc;
|
} static alc;
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -62,13 +53,9 @@ initALCFunctions(ALCdevice *alcDev)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
Debug() << "ALC_SOFT_pause_device present";
|
Debug() << "ALC_SOFT_pause_device present";
|
||||||
|
|
||||||
#define AL_FUN(name, type) alc. name = (type) alcGetProcAddress(alcDev, "alc" #name "SOFT");
|
|
||||||
AL_DEVICE_PAUSE_FUN;
|
|
||||||
#undef AL_FUN
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#define HAVE_ALC_DEVICE_PAUSE alc.DevicePause
|
#define HAVE_ALC_DEVICE_PAUSE false
|
||||||
|
|
||||||
uint8_t EventThread::keyStates[];
|
uint8_t EventThread::keyStates[];
|
||||||
EventThread::JoyState EventThread::joyState;
|
EventThread::JoyState EventThread::joyState;
|
||||||
|
@ -112,6 +99,8 @@ void EventThread::process(RGSSThreadData &rtData)
|
||||||
SDL_Window *win = rtData.window;
|
SDL_Window *win = rtData.window;
|
||||||
UnidirMessage<Vec2i> &windowSizeMsg = rtData.windowSizeMsg;
|
UnidirMessage<Vec2i> &windowSizeMsg = rtData.windowSizeMsg;
|
||||||
|
|
||||||
|
static bool once = true;
|
||||||
|
if (once) {
|
||||||
initALCFunctions(rtData.alcDev);
|
initALCFunctions(rtData.alcDev);
|
||||||
|
|
||||||
// XXX this function breaks input focus on OSX
|
// XXX this function breaks input focus on OSX
|
||||||
|
@ -119,6 +108,9 @@ void EventThread::process(RGSSThreadData &rtData)
|
||||||
SDL_SetEventFilter(eventFilter, &rtData);
|
SDL_SetEventFilter(eventFilter, &rtData);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
once = false;
|
||||||
|
}
|
||||||
|
|
||||||
fullscreen = rtData.config.fullscreen;
|
fullscreen = rtData.config.fullscreen;
|
||||||
int toggleFSMod = rtData.config.anyAltToggleFS ? KMOD_ALT : KMOD_LALT;
|
int toggleFSMod = rtData.config.anyAltToggleFS ? KMOD_ALT : KMOD_LALT;
|
||||||
|
|
||||||
|
@ -159,13 +151,8 @@ void EventThread::process(RGSSThreadData &rtData)
|
||||||
|
|
||||||
SettingsMenu *sMenu = 0;
|
SettingsMenu *sMenu = 0;
|
||||||
|
|
||||||
while (true)
|
while (SDL_PollEvent(&event))
|
||||||
{
|
{
|
||||||
if (!SDL_WaitEvent(&event))
|
|
||||||
{
|
|
||||||
Debug() << "EventThread: Event error";
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (sMenu && sMenu->onEvent(event))
|
if (sMenu && sMenu->onEvent(event))
|
||||||
{
|
{
|
||||||
|
@ -459,11 +446,13 @@ void EventThread::process(RGSSThreadData &rtData)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifndef __EMSCRIPTEN__
|
||||||
/* Just in case */
|
/* Just in case */
|
||||||
rtData.syncPoint.resumeThreads();
|
rtData.syncPoint.resumeThreads();
|
||||||
|
|
||||||
if (SDL_JoystickGetAttached(js))
|
if (SDL_JoystickGetAttached(js))
|
||||||
SDL_JoystickClose(js);
|
SDL_JoystickClose(js);
|
||||||
|
#endif
|
||||||
|
|
||||||
delete sMenu;
|
delete sMenu;
|
||||||
}
|
}
|
||||||
|
@ -477,8 +466,10 @@ int EventThread::eventFilter(void *data, SDL_Event *event)
|
||||||
case SDL_APP_WILLENTERBACKGROUND :
|
case SDL_APP_WILLENTERBACKGROUND :
|
||||||
Debug() << "SDL_APP_WILLENTERBACKGROUND";
|
Debug() << "SDL_APP_WILLENTERBACKGROUND";
|
||||||
|
|
||||||
|
#if HAVE_ALC_DEVICE_PAUSE
|
||||||
if (HAVE_ALC_DEVICE_PAUSE)
|
if (HAVE_ALC_DEVICE_PAUSE)
|
||||||
alc.DevicePause(rtData.alcDev);
|
alc.DevicePause(rtData.alcDev);
|
||||||
|
#endif
|
||||||
|
|
||||||
rtData.syncPoint.haltThreads();
|
rtData.syncPoint.haltThreads();
|
||||||
|
|
||||||
|
@ -495,8 +486,10 @@ int EventThread::eventFilter(void *data, SDL_Event *event)
|
||||||
case SDL_APP_DIDENTERFOREGROUND :
|
case SDL_APP_DIDENTERFOREGROUND :
|
||||||
Debug() << "SDL_APP_DIDENTERFOREGROUND";
|
Debug() << "SDL_APP_DIDENTERFOREGROUND";
|
||||||
|
|
||||||
|
#if HAVE_ALC_DEVICE_PAUSE
|
||||||
if (HAVE_ALC_DEVICE_PAUSE)
|
if (HAVE_ALC_DEVICE_PAUSE)
|
||||||
alc.DeviceResume(rtData.alcDev);
|
alc.DeviceResume(rtData.alcDev);
|
||||||
|
#endif
|
||||||
|
|
||||||
rtData.syncPoint.resumeThreads();
|
rtData.syncPoint.resumeThreads();
|
||||||
|
|
||||||
|
@ -593,18 +586,11 @@ void EventThread::requestShowCursor(bool mode)
|
||||||
SDL_PushEvent(&event);
|
SDL_PushEvent(&event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
void EventThread::showMessageBox(const char *body, int flags)
|
void EventThread::showMessageBox(const char *body, int flags)
|
||||||
{
|
{
|
||||||
msgBoxDone.clear();
|
msgBoxDone.clear();
|
||||||
|
printf(body);
|
||||||
SDL_Event event;
|
|
||||||
event.user.code = flags;
|
|
||||||
event.user.data1 = strdup(body);
|
|
||||||
event.type = usrIdStart + REQUEST_MESSAGEBOX;
|
|
||||||
SDL_PushEvent(&event);
|
|
||||||
|
|
||||||
/* Keep repainting screen while box is open */
|
|
||||||
shState->graphics().repaintWait(msgBoxDone);
|
|
||||||
/* Prevent endless loops */
|
/* Prevent endless loops */
|
||||||
resetInputStates();
|
resetInputStates();
|
||||||
}
|
}
|
||||||
|
|
|
@ -625,7 +625,7 @@ openReadEnumCB(void *d, const char *dirpath, const char *filename)
|
||||||
|
|
||||||
const char *ext = findExt(filename);
|
const char *ext = findExt(filename);
|
||||||
|
|
||||||
if (data.handler.tryRead(data.ops, ext))
|
if (data.handler.tryRead(data.ops, ext, fullPath))
|
||||||
data.stopSearching = true;
|
data.stopSearching = true;
|
||||||
|
|
||||||
++data.matchCount;
|
++data.matchCount;
|
||||||
|
@ -678,12 +678,16 @@ void FileSystem::openRead(OpenHandler &handler, const char *filename)
|
||||||
PHYSFS_enumerate(dir, openReadEnumCB, &data);
|
PHYSFS_enumerate(dir, openReadEnumCB, &data);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (data.physfsError)
|
if (data.physfsError) {
|
||||||
|
printf("PHYSFS ERROR %s\n", filename);
|
||||||
throw Exception(Exception::PHYSFSError, "PhysFS: %s", data.physfsError);
|
throw Exception(Exception::PHYSFSError, "PhysFS: %s", data.physfsError);
|
||||||
|
}
|
||||||
|
|
||||||
if (data.matchCount == 0)
|
if (data.matchCount == 0) {
|
||||||
|
printf("NO SUCH FILE %s\n", filename);
|
||||||
throw Exception(Exception::NoFileError, "%s", filename);
|
throw Exception(Exception::NoFileError, "%s", filename);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void FileSystem::openReadRaw(SDL_RWops &ops,
|
void FileSystem::openReadRaw(SDL_RWops &ops,
|
||||||
const char *filename,
|
const char *filename,
|
||||||
|
|
|
@ -53,7 +53,7 @@ public:
|
||||||
* After this function returns, ops becomes invalid, so don't take
|
* After this function returns, ops becomes invalid, so don't take
|
||||||
* references to it. Instead, copy the structure without closing
|
* references to it. Instead, copy the structure without closing
|
||||||
* if you need to further read from it later. */
|
* if you need to further read from it later. */
|
||||||
virtual bool tryRead(SDL_RWops &ops, const char *ext) = 0;
|
virtual bool tryRead(SDL_RWops &ops, const char *ext, const char *fullPath) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
void openRead(OpenHandler &handler,
|
void openRead(OpenHandler &handler,
|
||||||
|
@ -66,7 +66,6 @@ public:
|
||||||
|
|
||||||
/* Does not perform extension supplementing */
|
/* Does not perform extension supplementing */
|
||||||
bool exists(const char *filename);
|
bool exists(const char *filename);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
FileSystemPrivate *p;
|
FileSystemPrivate *p;
|
||||||
};
|
};
|
||||||
|
|
|
@ -13,8 +13,12 @@
|
||||||
#elif __WINDOWS__
|
#elif __WINDOWS__
|
||||||
#define FLUID_LIB "fluidsynth.dll"
|
#define FLUID_LIB "fluidsynth.dll"
|
||||||
#else
|
#else
|
||||||
|
#ifdef __EMSCRIPTEN__
|
||||||
|
#define FLUID_LIB "fluidsynth.bc"
|
||||||
|
#else
|
||||||
#error "platform not recognized"
|
#error "platform not recognized"
|
||||||
#endif
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
struct FluidFunctions fluid;
|
struct FluidFunctions fluid;
|
||||||
|
|
||||||
|
@ -22,6 +26,10 @@ static void *so;
|
||||||
|
|
||||||
void initFluidFunctions()
|
void initFluidFunctions()
|
||||||
{
|
{
|
||||||
|
#ifdef __EMSCRIPTEN__
|
||||||
|
goto fail;
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef SHARED_FLUID
|
#ifdef SHARED_FLUID
|
||||||
|
|
||||||
#define FLUID_FUN(name, type) \
|
#define FLUID_FUN(name, type) \
|
||||||
|
|
|
@ -418,6 +418,10 @@ struct FPSLimiter
|
||||||
private:
|
private:
|
||||||
void delayTicks(uint64_t ticks)
|
void delayTicks(uint64_t ticks)
|
||||||
{
|
{
|
||||||
|
#ifdef __EMSCRIPTEN__
|
||||||
|
return;
|
||||||
|
#endif
|
||||||
|
|
||||||
#if defined(HAVE_NANOSLEEP)
|
#if defined(HAVE_NANOSLEEP)
|
||||||
struct timespec req;
|
struct timespec req;
|
||||||
uint64_t nsec = ticks / tickFreqNS;
|
uint64_t nsec = ticks / tickFreqNS;
|
||||||
|
@ -751,6 +755,7 @@ void Graphics::transition(int duration,
|
||||||
/* We need to clean up transMap properly before
|
/* We need to clean up transMap properly before
|
||||||
* a possible longjmp, so we manually test for
|
* a possible longjmp, so we manually test for
|
||||||
* shutdown/reset here */
|
* shutdown/reset here */
|
||||||
|
|
||||||
if (p->threadData->rqTerm)
|
if (p->threadData->rqTerm)
|
||||||
{
|
{
|
||||||
glState.blend.pop();
|
glState.blend.pop();
|
||||||
|
|
34
src/main.cpp
34
src/main.cpp
|
@ -19,7 +19,7 @@
|
||||||
** along with mkxp. If not, see <http://www.gnu.org/licenses/>.
|
** along with mkxp. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <alc.h>
|
#include <AL/alc.h>
|
||||||
|
|
||||||
#include <SDL.h>
|
#include <SDL.h>
|
||||||
#include <SDL_image.h>
|
#include <SDL_image.h>
|
||||||
|
@ -111,11 +111,6 @@ int rgssThreadFun(void *userdata)
|
||||||
|
|
||||||
printGLInfo();
|
printGLInfo();
|
||||||
|
|
||||||
bool vsync = conf.vsync || conf.syncToRefreshrate;
|
|
||||||
SDL_GL_SetSwapInterval(vsync ? 1 : 0);
|
|
||||||
|
|
||||||
GLDebugLogger dLogger;
|
|
||||||
|
|
||||||
/* Setup AL context */
|
/* Setup AL context */
|
||||||
ALCcontext *alcCtx = alcCreateContext(threadData->alcDev, 0);
|
ALCcontext *alcCtx = alcCreateContext(threadData->alcDev, 0);
|
||||||
|
|
||||||
|
@ -145,6 +140,7 @@ int rgssThreadFun(void *userdata)
|
||||||
/* Start script execution */
|
/* Start script execution */
|
||||||
scriptBinding->execute();
|
scriptBinding->execute();
|
||||||
|
|
||||||
|
#ifndef __EMSCRIPTEN__
|
||||||
threadData->rqTermAck.set();
|
threadData->rqTermAck.set();
|
||||||
threadData->ethread->requestTerminate();
|
threadData->ethread->requestTerminate();
|
||||||
|
|
||||||
|
@ -152,6 +148,10 @@ int rgssThreadFun(void *userdata)
|
||||||
|
|
||||||
alcDestroyContext(alcCtx);
|
alcDestroyContext(alcCtx);
|
||||||
SDL_GL_DeleteContext(glCtx);
|
SDL_GL_DeleteContext(glCtx);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
bool vsync = conf.vsync || conf.syncToRefreshrate;
|
||||||
|
SDL_GL_SetSwapInterval(vsync ? 1 : 0);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -239,7 +239,11 @@ int main(int argc, char *argv[])
|
||||||
assert(conf.rgssVersion >= 1 && conf.rgssVersion <= 3);
|
assert(conf.rgssVersion >= 1 && conf.rgssVersion <= 3);
|
||||||
printRgssVersion(conf.rgssVersion);
|
printRgssVersion(conf.rgssVersion);
|
||||||
|
|
||||||
|
#ifdef __EMSCRIPTEN__
|
||||||
|
int imgFlags = 0;
|
||||||
|
#else
|
||||||
int imgFlags = IMG_INIT_PNG | IMG_INIT_JPG;
|
int imgFlags = IMG_INIT_PNG | IMG_INIT_JPG;
|
||||||
|
#endif
|
||||||
if (IMG_Init(imgFlags) != imgFlags)
|
if (IMG_Init(imgFlags) != imgFlags)
|
||||||
{
|
{
|
||||||
showInitError(std::string("Error initializing SDL_image: ") + SDL_GetError());
|
showInitError(std::string("Error initializing SDL_image: ") + SDL_GetError());
|
||||||
|
@ -324,13 +328,19 @@ int main(int argc, char *argv[])
|
||||||
/* Load and post key bindings */
|
/* Load and post key bindings */
|
||||||
rtData.bindingUpdateMsg.post(loadBindings(conf));
|
rtData.bindingUpdateMsg.post(loadBindings(conf));
|
||||||
|
|
||||||
/* Start RGSS thread */
|
|
||||||
SDL_Thread *rgssThread =
|
|
||||||
SDL_CreateThread(rgssThreadFun, "rgss", &rtData);
|
|
||||||
|
|
||||||
/* Start event processing */
|
/* Start event processing */
|
||||||
eventThread.process(rtData);
|
eventThread.process(rtData);
|
||||||
|
|
||||||
|
#ifdef __EMSCRIPTEN__
|
||||||
|
::rgssThreadFun(&rtData);
|
||||||
|
printf("Exiting main function\n");
|
||||||
|
return 0;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Start RGSS thread */
|
||||||
|
rgssThreadFun(&rtData);
|
||||||
|
return 0;
|
||||||
|
|
||||||
/* Request RGSS thread to stop */
|
/* Request RGSS thread to stop */
|
||||||
rtData.rqTerm.set();
|
rtData.rqTerm.set();
|
||||||
|
|
||||||
|
@ -350,8 +360,8 @@ int main(int argc, char *argv[])
|
||||||
|
|
||||||
/* If RGSS thread ack'd request, wait for it to shutdown,
|
/* If RGSS thread ack'd request, wait for it to shutdown,
|
||||||
* otherwise abandon hope and just end the process as is. */
|
* otherwise abandon hope and just end the process as is. */
|
||||||
if (rtData.rqTermAck)
|
if (rtData.rqTermAck);
|
||||||
SDL_WaitThread(rgssThread, 0);
|
// SDL_WaitThread(rgssThread, 0);
|
||||||
else
|
else
|
||||||
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, conf.windowTitle.c_str(),
|
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, conf.windowTitle.c_str(),
|
||||||
"The RGSS script seems to be stuck and mkxp will now force quit", win);
|
"The RGSS script seems to be stuck and mkxp will now force quit", win);
|
||||||
|
|
|
@ -23,7 +23,8 @@
|
||||||
#include "boost-hash.h"
|
#include "boost-hash.h"
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <string.h>
|
#include <string>
|
||||||
|
#include <cstring>
|
||||||
|
|
||||||
struct RGSS_entryData
|
struct RGSS_entryData
|
||||||
{
|
{
|
||||||
|
@ -293,7 +294,8 @@ processDirectories(RGSS_archiveData *data, BoostSet<std::string> &topLevel,
|
||||||
if (slash)
|
if (slash)
|
||||||
nameBuf[i] = '\0';
|
nameBuf[i] = '\0';
|
||||||
|
|
||||||
topLevel.insert(nameBuf);
|
std::string nameBufStr(nameBuf);
|
||||||
|
topLevel.insert(nameBufStr);
|
||||||
|
|
||||||
if (slash)
|
if (slash)
|
||||||
nameBuf[i] = '/';
|
nameBuf[i] = '/';
|
||||||
|
@ -639,3 +641,4 @@ const PHYSFS_Archiver RGSS3_Archiver =
|
||||||
RGSS_stat,
|
RGSS_stat,
|
||||||
RGSS_closeArchive
|
RGSS_closeArchive
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,10 @@
|
||||||
#ifndef SDLUTIL_H
|
#ifndef SDLUTIL_H
|
||||||
#define SDLUTIL_H
|
#define SDLUTIL_H
|
||||||
|
|
||||||
|
#ifndef __EMSCRIPTEN__
|
||||||
#include <SDL_atomic.h>
|
#include <SDL_atomic.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <SDL_thread.h>
|
#include <SDL_thread.h>
|
||||||
#include <SDL_rwops.h>
|
#include <SDL_rwops.h>
|
||||||
|
|
||||||
|
@ -17,21 +20,37 @@ struct AtomicFlag
|
||||||
|
|
||||||
void set()
|
void set()
|
||||||
{
|
{
|
||||||
|
#ifdef __EMSCRIPTEN__
|
||||||
|
atom = true;
|
||||||
|
#else
|
||||||
SDL_AtomicSet(&atom, 1);
|
SDL_AtomicSet(&atom, 1);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void clear()
|
void clear()
|
||||||
{
|
{
|
||||||
|
#ifdef __EMSCRIPTEN__
|
||||||
|
atom = false;
|
||||||
|
#else
|
||||||
SDL_AtomicSet(&atom, 0);
|
SDL_AtomicSet(&atom, 0);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
operator bool() const
|
operator bool() const
|
||||||
{
|
{
|
||||||
|
#ifdef __EMSCRIPTEN__
|
||||||
|
return atom;
|
||||||
|
#else
|
||||||
return SDL_AtomicGet(&atom);
|
return SDL_AtomicGet(&atom);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
#ifdef __EMSCRIPTEN__
|
||||||
|
bool atom = false;
|
||||||
|
#else
|
||||||
mutable SDL_atomic_t atom;
|
mutable SDL_atomic_t atom;
|
||||||
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
template<class C, void (C::*func)()>
|
template<class C, void (C::*func)()>
|
||||||
|
|
|
@ -263,16 +263,13 @@ void SharedState::bindTex()
|
||||||
|
|
||||||
void SharedState::ensureTexSize(int minW, int minH, Vec2i ¤tSizeOut)
|
void SharedState::ensureTexSize(int minW, int minH, Vec2i ¤tSizeOut)
|
||||||
{
|
{
|
||||||
if (minW > p->globalTexW)
|
minW = findNextPow2(minW); minH = findNextPow2(minH);
|
||||||
{
|
|
||||||
p->globalTexDirty = true;
|
|
||||||
p->globalTexW = findNextPow2(minW);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (minH > p->globalTexH)
|
if (minW != p->globalTexW || minH != p->globalTexH)
|
||||||
{
|
{
|
||||||
|
p->globalTexW = minW;
|
||||||
|
p->globalTexH = minH;
|
||||||
p->globalTexDirty = true;
|
p->globalTexDirty = true;
|
||||||
p->globalTexH = findNextPow2(minH);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
currentSizeOut = Vec2i(p->globalTexW, p->globalTexH);
|
currentSizeOut = Vec2i(p->globalTexW, p->globalTexH);
|
||||||
|
@ -280,22 +277,12 @@ void SharedState::ensureTexSize(int minW, int minH, Vec2i ¤tSizeOut)
|
||||||
|
|
||||||
TEXFBO &SharedState::gpTexFBO(int minW, int minH)
|
TEXFBO &SharedState::gpTexFBO(int minW, int minH)
|
||||||
{
|
{
|
||||||
bool needResize = false;
|
minW = findNextPow2(minW); minH = findNextPow2(minH);
|
||||||
|
|
||||||
if (minW > p->gpTexFBO.width)
|
if (minW != p->gpTexFBO.width || minH != p->gpTexFBO.height)
|
||||||
{
|
|
||||||
p->gpTexFBO.width = findNextPow2(minW);
|
|
||||||
needResize = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (minH > p->gpTexFBO.height)
|
|
||||||
{
|
|
||||||
p->gpTexFBO.height = findNextPow2(minH);
|
|
||||||
needResize = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (needResize)
|
|
||||||
{
|
{
|
||||||
|
p->gpTexFBO.width = minW;
|
||||||
|
p->gpTexFBO.height = minH;
|
||||||
TEX::bind(p->gpTexFBO.tex);
|
TEX::bind(p->gpTexFBO.tex);
|
||||||
TEX::allocEmpty(p->gpTexFBO.width, p->gpTexFBO.height);
|
TEX::allocEmpty(p->gpTexFBO.width, p->gpTexFBO.height);
|
||||||
}
|
}
|
||||||
|
|
|
@ -192,7 +192,7 @@ struct SoundOpenHandler : FileSystem::OpenHandler
|
||||||
: buffer(0)
|
: buffer(0)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
bool tryRead(SDL_RWops &ops, const char *ext)
|
bool tryRead(SDL_RWops &ops, const char *ext, const char *fullPath)
|
||||||
{
|
{
|
||||||
Sound_Sample *sample = Sound_NewSample(&ops, ext, 0, STREAM_BUF_SIZE);
|
Sound_Sample *sample = Sound_NewSample(&ops, ext, 0, STREAM_BUF_SIZE);
|
||||||
|
|
||||||
|
|
|
@ -388,30 +388,17 @@ struct WindowPrivate
|
||||||
|
|
||||||
void ensureBaseTexReady()
|
void ensureBaseTexReady()
|
||||||
{
|
{
|
||||||
/* Make sure texture is big enough */
|
/* Make sure texture is properly sized */
|
||||||
int newW = baseTex.width;
|
int newW = findNextPow2(size.x);
|
||||||
int newH = baseTex.height;
|
int newH = findNextPow2(size.y);
|
||||||
bool resizeNeeded = false;
|
|
||||||
|
|
||||||
if (size.x > baseTex.width)
|
if (newW != baseTex.width || newH != baseTex.height)
|
||||||
{
|
{
|
||||||
newW = findNextPow2(size.x);
|
|
||||||
resizeNeeded = true;
|
|
||||||
}
|
|
||||||
if (size.y > baseTex.height)
|
|
||||||
{
|
|
||||||
newH = findNextPow2(size.y);
|
|
||||||
resizeNeeded = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!resizeNeeded)
|
|
||||||
return;
|
|
||||||
|
|
||||||
shState->texPool().release(baseTex);
|
shState->texPool().release(baseTex);
|
||||||
baseTex = shState->texPool().request(newW, newH);
|
baseTex = shState->texPool().request(newW, newH);
|
||||||
|
|
||||||
baseTexDirty = true;
|
baseTexDirty = true;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void redrawBaseTex()
|
void redrawBaseTex()
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue