From 55f1542c767eae072f354466f27d1c5de8700a3a Mon Sep 17 00:00:00 2001 From: Jonas Kulla Date: Thu, 28 Aug 2014 23:11:10 +0200 Subject: [PATCH] Merge separate RGSS version build configs into one Setup active RGSS version at runtime. Desired version can be specified via config, or as default, auto detected from the game files. This removes the need to build specifically for each version, which should help packaging a lot. This also greatly reduces the danger of introducing code that wouldn't compile on all RGSS version paths (as certain code paths were completely ifdef'd out). This can be optimized more, eg. not compiling shaders that aren't needed in the active version. --- CMakeLists.txt | 30 ++++--- README.md | 3 +- binding-mri/audio-binding.cpp | 15 ++-- binding-mri/binding-mri.cpp | 80 +++++++++---------- binding-mri/binding-util.h | 4 +- binding-mri/bitmap-binding.cpp | 73 +++++++++-------- binding-mri/font-binding.cpp | 44 +++++----- binding-mri/graphics-binding.cpp | 14 ++-- binding-mri/input-binding.cpp | 60 +++++++------- binding-mri/module_rpg.cpp | 8 +- .../{module_rpg.rb.xxd => module_rpg1.rb.xxd} | 4 +- binding-mri/module_rpg2.rb.xxd | 4 +- binding-mri/module_rpg3.rb.xxd | 4 +- binding-mri/sprite-binding.cpp | 19 ++--- binding-mri/tilemapvx-binding.cpp | 19 +++-- binding-mri/viewport-binding.cpp | 8 +- binding-mri/viewportelement-binding.h | 10 +-- binding-mri/windowvx-binding.cpp | 34 ++++---- binding-mruby/binding-util.h | 2 - binding-mruby/input-binding.cpp | 70 ++++++++-------- binding-mruby/sprite-binding.cpp | 18 ++--- mkxp.conf.sample | 22 ++++- mkxp.pro | 78 ++++-------------- src/aldatasource.h | 2 - src/alstream.cpp | 40 ++++++---- src/bitmap.cpp | 4 - src/bitmap.h | 2 - src/config.cpp | 37 ++++++++- src/config.h | 10 +-- src/font.cpp | 18 ++--- src/font.h | 2 + src/graphics.cpp | 8 +- src/input.cpp | 32 +++++--- src/scene.cpp | 16 ++-- src/shader.cpp | 7 -- src/shader.h | 6 -- src/sharedstate.cpp | 30 ++++--- src/sharedstate.h | 2 + src/sprite.cpp | 15 ++-- src/tileatlasvx.cpp | 32 ++++---- src/windowvx.cpp | 39 +++++---- 41 files changed, 460 insertions(+), 465 deletions(-) rename binding-mri/{module_rpg.rb.xxd => module_rpg1.rb.xxd} (99%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 95314fb..932d3a6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,7 +3,6 @@ Project(mkxp) ## Setup options ## -option(RGSS2 "Enable RGSS2" OFF) option(MIDI "Enable midi support" ON) option(WORKDIR_CURRENT "Keep current directory on startup" OFF) option(FORCE32 "Force 32bit compile on 64bit OS" OFF) @@ -87,6 +86,7 @@ endif() pkg_check_modules(SIGCXX REQUIRED sigc++-2.0) pkg_check_modules(PIXMAN REQUIRED pixman-1) pkg_check_modules(PHYSFS REQUIRED physfs>=2.1) +pkg_check_modules(VORBISFILE REQUIRED vorbisfile) pkg_check_modules(SDL2 REQUIRED sdl2) pkg_check_modules(SDL2_TTF REQUIRED SDL2_ttf) pkg_check_modules(SDL2_IMAGE REQUIRED SDL2_image) @@ -148,6 +148,9 @@ set(MAIN_HEADERS src/alstream.h src/audiostream.h src/rgssad.h + src/windowvx.h + src/tilemapvx.h + src/tileatlasvx.h ) set(MAIN_SOURCE @@ -185,6 +188,11 @@ set(MAIN_SOURCE src/audiostream.cpp src/rgssad.cpp src/bundledfont.cpp + src/vorbissource.cpp + src/windowvx.cpp + src/tilemapvx.cpp + src/tileatlasvx.cpp + src/autotilesvx.cpp ) source_group("MKXP Source" FILES ${MAIN_SOURCE} ${MAIN_HEADERS}) @@ -206,23 +214,17 @@ set(EMBEDDED_INPUT shader/simpleColor.vert shader/sprite.vert shader/tilemap.vert + shader/blur.frag + shader/blurH.vert + shader/blurV.vert + shader/simpleMatrix.vert assets/liberation.ttf ) if (RGSS2) - pkg_check_modules(RGSS2 REQUIRED vorbisfile) list(APPEND DEFINES RGSS2 ) - list(APPEND MAIN_SOURCE - src/vorbissource.cpp - ) - list(APPEND EMBEDDED_INPUT - shader/blur.frag - shader/blurH.vert - shader/blurV.vert - shader/simpleMatrix.vert - ) endif() if (MIDI) @@ -305,6 +307,8 @@ if (BINDING STREQUAL "MRI") binding-mri/audio-binding.cpp binding-mri/module_rpg.cpp binding-mri/filesystem-binding.cpp + binding-mri/windowvx-binding.cpp + binding-mri/tilemapvx-binding.cpp ) elseif(BINDING STREQUAL "MRUBY") message(FATAL_ERROR "Mruby support in CMake needs to be finished") @@ -395,7 +399,7 @@ target_include_directories(${PROJECT_NAME} PRIVATE ${SDL2_INCLUDE_DIRS} # Blindly assume other SDL bits are in same directory ${Boost_INCLUDE_DIR} ${MRI_INCLUDE_DIRS} - ${RGSS2_INCLUDE_DIRS} + ${VORBISFILE_INCLUDE_DIRS} ${MIDI_INCLUDE_DIRS} ${OPENAL_INCLUDE_DIR} ) @@ -410,7 +414,7 @@ target_link_libraries(${PROJECT_NAME} ${PIXMAN_LIBRARIES} ${Boost_LIBRARIES} ${MRI_LIBRARIES} - ${RGSS2_LIBRARIES} + ${VORBISFILE_LIBRARIES} ${MIDI_LIBRARIES} ${OPENAL_LIBRARY} ${ZLIB_LIBRARY} diff --git a/README.md b/README.md index fa24768..e21e854 100644 --- a/README.md +++ b/README.md @@ -58,6 +58,7 @@ This binding only exists for testing purposes and does nothing (the engine quits * SDL2_image * SDL2_ttf * SDL_sound (latest hg, apply provided patches!) +* vorbisfile * pixman * fluidsynth (if midi enabled) * zlib (only ruby bindings) @@ -77,8 +78,6 @@ By default, mkxp switches into the directory where its binary is contained and t To auto detect the encoding of the game title in `Game.ini` and auto convert it to UTF-8, build with `CONFIG+=INI_ENCODING`. Requires iconv implementation and libguess. If the encoding is wrongly detected, you can set the "titleLanguage" hint in mkxp.conf. -**RGSS Version**: Add `RGSS_VER=`, with `` being either 1, 2 or 3, to the parameter list to select the desired version. The default is 1. - **MRI-Binding**: pkg-config will look for `ruby-2.1.pc`, but you can modify mkxp.pro to use 2.0 instead. This is the default binding, so no arguments to qmake needed (`BINDING=MRI` to be explicit). **MRuby-Binding**: place the "mruby" folder into the project folder and build it first. Add `BINDING=MRUBY` to qmake's arguments. diff --git a/binding-mri/audio-binding.cpp b/binding-mri/audio-binding.cpp index 6fd41c0..4c8952e 100644 --- a/binding-mri/audio-binding.cpp +++ b/binding-mri/audio-binding.cpp @@ -32,7 +32,10 @@ int volume = 100; \ int pitch = 100; \ double pos = 0.0; \ - rb_get_args(argc, argv, "z|iif", &filename, &volume, &pitch, &pos RB_ARG_END); \ + if (rgssVer >= 3) \ + rb_get_args(argc, argv, "z|iif", &filename, &volume, &pitch, &pos RB_ARG_END); \ + else \ + rb_get_args(argc, argv, "z|ii", &filename, &volume, &pitch RB_ARG_END); \ GUARD_EXC( shState->audio().entity##Play(filename, volume, pitch, pos); ) \ return Qnil; \ } \ @@ -83,13 +86,8 @@ RB_METHOD(audio_##entity##Fade) \ return rb_float_new(shState->audio().entity##Pos()); \ } -#ifdef RGSS3 DEF_PLAY_STOP_POS( bgm ) DEF_PLAY_STOP_POS( bgs ) -#else -DEF_PLAY_STOP( bgm ) -DEF_PLAY_STOP( bgs ) -#endif DEF_PLAY_STOP( me ) @@ -124,10 +122,11 @@ audioBindingInit() BIND_PLAY_STOP_FADE( bgs ); BIND_PLAY_STOP_FADE( me ); -#ifdef RGSS3 + if (rgssVer >= 3) + { BIND_POS( bgm ); BIND_POS( bgs ); -#endif + } BIND_PLAY_STOP( se ) } diff --git a/binding-mri/binding-mri.cpp b/binding-mri/binding-mri.cpp index 00567eb..07168d7 100644 --- a/binding-mri/binding-mri.cpp +++ b/binding-mri/binding-mri.cpp @@ -30,13 +30,15 @@ #include #include +#include #include - #include #include -extern const char module_rpg[]; +extern const char module_rpg1[]; +extern const char module_rpg2[]; +extern const char module_rpg3[]; static void mriBindingExecute(); static void mriBindingTerminate(); @@ -58,11 +60,8 @@ void viewportBindingInit(); void planeBindingInit(); void windowBindingInit(); void tilemapBindingInit(); - -#ifdef RGSS2 void windowVXBindingInit(); void tilemapVXBindingInit(); -#endif void inputBindingInit(); void audioBindingInit(); @@ -75,11 +74,8 @@ RB_METHOD(mriP); RB_METHOD(mriDataDirectory); RB_METHOD(mkxpPuts); -#ifdef RGSS3 RB_METHOD(mriRgssMain); -#else RB_METHOD(_kernelCaller); -#endif static void mriBindingInit() { @@ -91,13 +87,16 @@ static void mriBindingInit() viewportBindingInit(); planeBindingInit(); -#ifdef RGSS2 - windowVXBindingInit(); - tilemapVXBindingInit(); -#else - windowBindingInit(); - tilemapBindingInit(); -#endif + if (rgssVer == 1) + { + windowBindingInit(); + tilemapBindingInit(); + } + else + { + windowVXBindingInit(); + tilemapVXBindingInit(); + } inputBindingInit(); audioBindingInit(); @@ -105,27 +104,35 @@ static void mriBindingInit() fileIntBindingInit(); -#ifdef RGSS3 - _rb_define_module_function(rb_mKernel, "rgss_main", mriRgssMain); + if (rgssVer >= 3) + { + _rb_define_module_function(rb_mKernel, "rgss_main", mriRgssMain); - _rb_define_module_function(rb_mKernel, "msgbox", mriPrint); - _rb_define_module_function(rb_mKernel, "msgbox_p", mriP); -#else - _rb_define_module_function(rb_mKernel, "print", mriPrint); - _rb_define_module_function(rb_mKernel, "p", mriP); -#endif + _rb_define_module_function(rb_mKernel, "msgbox", mriPrint); + _rb_define_module_function(rb_mKernel, "msgbox_p", mriP); + } + else + { + _rb_define_module_function(rb_mKernel, "print", mriPrint); + _rb_define_module_function(rb_mKernel, "p", mriP); - rb_eval_string(module_rpg); + rb_define_alias(rb_singleton_class(rb_mKernel), "_mkxp_kernel_caller_alias", "caller"); + _rb_define_module_function(rb_mKernel, "caller", _kernelCaller); + } + + if (rgssVer == 1) + rb_eval_string(module_rpg1); + else if (rgssVer == 2) + rb_eval_string(module_rpg2); + else if (rgssVer == 3) + rb_eval_string(module_rpg3); + else + assert(!"unreachable"); VALUE mod = rb_define_module("System"); _rb_define_module_function(mod, "data_directory", mriDataDirectory); _rb_define_module_function(mod, "puts", mkxpPuts); -#ifndef RGSS3 - rb_define_alias(rb_singleton_class(rb_mKernel), "_mkxp_kernel_caller_alias", "caller"); - _rb_define_module_function(rb_mKernel, "caller", _kernelCaller); -#endif - rb_gv_set("MKXP", Qtrue); } @@ -200,8 +207,6 @@ RB_METHOD(mriDataDirectory) return pathStr; } -#ifdef RGSS3 - RB_METHOD(mriRgssMain) { RB_UNUSED_PARAM; @@ -212,8 +217,6 @@ RB_METHOD(mriRgssMain) return Qnil; } -#else - RB_METHOD(_kernelCaller) { RB_UNUSED_PARAM; @@ -246,8 +249,6 @@ RB_METHOD(_kernelCaller) return trace; } -#endif - static VALUE newStringUTF8(const char *string, long length) { return rb_enc_str_new(string, length, rb_utf8_encoding()); @@ -287,12 +288,6 @@ static void runCustomScript(const std::string &filename) VALUE kernelLoadDataInt(const char *filename); -#ifdef RGSS3 -#define RGSS_SECTION_STR "{%04ld}" -#else -#define RGSS_SECTION_STR "Section%03ld" -#endif - static void runRMXPScripts() { const Config &conf = shState->rtData().config; @@ -391,7 +386,8 @@ static void runRMXPScripts() else { char buf[32]; - int len = snprintf(buf, sizeof(buf), RGSS_SECTION_STR, i); + const char *format = rgssVer >= 3 ? "{%04ld}" : "Section%03ld"; + int len = snprintf(buf, sizeof(buf), format, i); fname = newStringUTF8(buf, len); } diff --git a/binding-mri/binding-util.h b/binding-mri/binding-util.h index 2f40366..8fcdab5 100644 --- a/binding-mri/binding-util.h +++ b/binding-mri/binding-util.h @@ -47,10 +47,8 @@ struct RbData { VALUE exc[RbExceptionsMax]; -#ifdef RGSS3 - /* Input module */ + /* Input module (RGSS3) */ VALUE buttoncodeHash; -#endif RbData(); ~RbData(); diff --git a/binding-mri/bitmap-binding.cpp b/binding-mri/bitmap-binding.cpp index 245a6c3..a5652f8 100644 --- a/binding-mri/bitmap-binding.cpp +++ b/binding-mri/bitmap-binding.cpp @@ -22,6 +22,7 @@ #include "bitmap.h" #include "font.h" #include "exception.h" +#include "sharedstate.h" #include "disposable-binding.h" #include "binding-util.h" #include "binding-types.h" @@ -252,17 +253,20 @@ RB_METHOD(bitmapDrawText) VALUE rectObj; Rect *rect; -#ifdef RGSS2 - VALUE strObj; - rb_get_args(argc, argv, "oo|i", &rectObj, &strObj, &align RB_ARG_END); + if (rgssVer >= 2) + { + VALUE strObj; + rb_get_args(argc, argv, "oo|i", &rectObj, &strObj, &align RB_ARG_END); - if (rb_type(strObj) != RUBY_T_STRING) - strObj = rb_funcallv(strObj, rb_intern("to_s"), 0, 0); + if (rb_type(strObj) != RUBY_T_STRING) + strObj = rb_funcallv(strObj, rb_intern("to_s"), 0, 0); - str = RSTRING_PTR(strObj); -#else - rb_get_args(argc, argv, "oz|i", &rectObj, &str, &align RB_ARG_END); -#endif + str = RSTRING_PTR(strObj); + } + else + { + rb_get_args(argc, argv, "oz|i", &rectObj, &str, &align RB_ARG_END); + } rect = getPrivateDataCheck(rectObj, RectType); @@ -272,17 +276,20 @@ RB_METHOD(bitmapDrawText) { int x, y, width, height; -#ifdef RGSS2 - VALUE strObj; - rb_get_args(argc, argv, "iiiio|i", &x, &y, &width, &height, &strObj, &align RB_ARG_END); + if (rgssVer >= 2) + { + VALUE strObj; + rb_get_args(argc, argv, "iiiio|i", &x, &y, &width, &height, &strObj, &align RB_ARG_END); - if (rb_type(strObj) != RUBY_T_STRING) - strObj = rb_funcallv(strObj, rb_intern("to_s"), 0, 0); + if (rb_type(strObj) != RUBY_T_STRING) + strObj = rb_funcallv(strObj, rb_intern("to_s"), 0, 0); - str = RSTRING_PTR(strObj); -#else - rb_get_args(argc, argv, "iiiiz|i", &x, &y, &width, &height, &str, &align RB_ARG_END); -#endif + str = RSTRING_PTR(strObj); + } + else + { + rb_get_args(argc, argv, "iiiiz|i", &x, &y, &width, &height, &str, &align RB_ARG_END); + } GUARD_EXC( b->drawText(x, y, width, height, str, align); ); } @@ -296,17 +303,20 @@ RB_METHOD(bitmapTextSize) const char *str; -#ifdef RGSS2 - VALUE strObj; - rb_get_args(argc, argv, "o", &strObj RB_ARG_END); + if (rgssVer >= 2) + { + VALUE strObj; + rb_get_args(argc, argv, "o", &strObj RB_ARG_END); - if (rb_type(strObj) != RUBY_T_STRING) - strObj = rb_funcallv(strObj, rb_intern("to_s"), 0, 0); + if (rb_type(strObj) != RUBY_T_STRING) + strObj = rb_funcallv(strObj, rb_intern("to_s"), 0, 0); - str = RSTRING_PTR(strObj); -#else - rb_get_args(argc, argv, "z", &str RB_ARG_END); -#endif + str = RSTRING_PTR(strObj); + } + else + { + rb_get_args(argc, argv, "z", &str RB_ARG_END); + } IntRect value; GUARD_EXC( value = b->textSize(str); ); @@ -318,8 +328,6 @@ RB_METHOD(bitmapTextSize) DEF_PROP_OBJ(Bitmap, Font, Font, "font") -#ifdef RGSS2 - RB_METHOD(bitmapGradientFillRect) { Bitmap *b = getPrivateData(self); @@ -408,8 +416,6 @@ RB_METHOD(bitmapRadialBlur) return Qnil; } -#endif - // FIXME: This isn't entire correct as the cloned bitmap // does not get a cloned version of the original bitmap's 'font' // attribute (the internal font attrb is the default one, whereas @@ -444,12 +450,13 @@ bitmapBindingInit() _rb_define_method(klass, "draw_text", bitmapDrawText); _rb_define_method(klass, "text_size", bitmapTextSize); -#ifdef RGSS2 + if (rgssVer >= 2) + { _rb_define_method(klass, "gradient_fill_rect", bitmapGradientFillRect); _rb_define_method(klass, "clear_rect", bitmapClearRect); _rb_define_method(klass, "blur", bitmapBlur); _rb_define_method(klass, "radial_blur", bitmapRadialBlur); -#endif + } INIT_PROP_BIND(Bitmap, Font, "font"); } diff --git a/binding-mri/font-binding.cpp b/binding-mri/font-binding.cpp index 78a54bd..abf0581 100644 --- a/binding-mri/font-binding.cpp +++ b/binding-mri/font-binding.cpp @@ -61,10 +61,11 @@ RB_METHOD(fontInitialize) f->setColor(new Color(*f->getColor())); wrapProperty(self, f->getColor(), "color", ColorType); -#ifdef RGSS3 + if (rgssVer >= 3) + { f->setOutColor(new Color(*f->getOutColor())); wrapProperty(self, f->getOutColor(), "out_color", ColorType); -#endif + } if (NIL_P(name)) name = rb_iv_get(rb_obj_class(self), "default_name"); @@ -92,10 +93,11 @@ RB_METHOD(fontInitializeCopy) f->setColor(new Color(*f->getColor())); wrapProperty(self, f->getColor(), "color", ColorType); -#ifdef RGSS3 + if (rgssVer >= 3) + { f->setOutColor(new Color(*f->getOutColor())); wrapProperty(self, f->getOutColor(), "out_color", ColorType); -#endif + } return self; } @@ -166,16 +168,10 @@ RB_METHOD(FontSetName) DEF_PROP_I(Font, Size) DEF_PROP_B(Font, Bold) DEF_PROP_B(Font, Italic) -DEF_PROP_OBJ(Font, Color, Color, "color") - -#ifdef RGSS2 DEF_PROP_B(Font, Shadow) -#endif - -#ifdef RGSS3 DEF_PROP_B(Font, Outline) +DEF_PROP_OBJ(Font, Color, Color, "color") DEF_PROP_OBJ(Font, Color, OutColor, "out_color") -#endif #define DEF_KLASS_PROP(Klass, type, PropName, param_t_s, value_fun) \ RB_METHOD(Klass##Get##PropName) \ @@ -195,12 +191,7 @@ DEF_PROP_OBJ(Font, Color, OutColor, "out_color") DEF_KLASS_PROP(Font, int, DefaultSize, "i", rb_fix_new) DEF_KLASS_PROP(Font, bool, DefaultBold, "b", rb_bool_new) DEF_KLASS_PROP(Font, bool, DefaultItalic, "b", rb_bool_new) - -#ifdef RGSS2 DEF_KLASS_PROP(Font, bool, DefaultShadow, "b", rb_bool_new) -#endif - -#ifdef RGSS3 DEF_KLASS_PROP(Font, bool, DefaultOutline, "b", rb_bool_new) RB_METHOD(FontGetDefaultOutColor) @@ -221,7 +212,6 @@ RB_METHOD(FontSetDefaultOutColor) return colorObj; } -#endif RB_METHOD(FontGetDefaultName) { @@ -285,14 +275,16 @@ fontBindingInit() INIT_KLASS_PROP_BIND(Font, DefaultItalic, "default_italic"); INIT_KLASS_PROP_BIND(Font, DefaultColor, "default_color"); -#ifdef RGSS2 + if (rgssVer >= 2) + { INIT_KLASS_PROP_BIND(Font, DefaultShadow, "default_shadow"); -#endif + } -#ifdef RGSS3 + if (rgssVer >= 3) + { INIT_KLASS_PROP_BIND(Font, DefaultOutline, "default_outline"); INIT_KLASS_PROP_BIND(Font, DefaultOutColor, "default_out_color"); -#endif + } rb_define_class_method(klass, "exist?", fontDoesExist); @@ -305,12 +297,14 @@ fontBindingInit() INIT_PROP_BIND(Font, Italic, "italic"); INIT_PROP_BIND(Font, Color, "color"); -#ifdef RGSS2 + if (rgssVer >= 2) + { INIT_PROP_BIND(Font, Shadow, "shadow"); -#endif + } -#ifdef RGSS3 + if (rgssVer >= 3) + { INIT_PROP_BIND(Font, Outline, "outline"); INIT_PROP_BIND(Font, OutColor, "out_color"); -#endif + } } diff --git a/binding-mri/graphics-binding.cpp b/binding-mri/graphics-binding.cpp index 8125837..20bf593 100644 --- a/binding-mri/graphics-binding.cpp +++ b/binding-mri/graphics-binding.cpp @@ -97,11 +97,6 @@ RB_METHOD(graphicsFrameReset) return rb_bool_new(value); \ } -DEF_GRA_PROP_I(FrameRate) -DEF_GRA_PROP_I(FrameCount) - -#ifdef RGSS2 - RB_METHOD(graphicsWidth) { RB_UNUSED_PARAM; @@ -179,10 +174,10 @@ RB_METHOD(graphicsResizeScreen) return Qnil; } +DEF_GRA_PROP_I(FrameRate) +DEF_GRA_PROP_I(FrameCount) DEF_GRA_PROP_I(Brightness) -#endif - DEF_GRA_PROP_B(Fullscreen) DEF_GRA_PROP_B(ShowCursor) @@ -204,7 +199,8 @@ void graphicsBindingInit() INIT_GRA_PROP_BIND( FrameRate, "frame_rate" ); INIT_GRA_PROP_BIND( FrameCount, "frame_count" ); -#ifdef RGSS2 + if (rgssVer >= 2) + { _rb_define_module_function(module, "width", graphicsWidth); _rb_define_module_function(module, "height", graphicsHeight); _rb_define_module_function(module, "wait", graphicsWait); @@ -214,7 +210,7 @@ void graphicsBindingInit() _rb_define_module_function(module, "resize_screen", graphicsResizeScreen); INIT_GRA_PROP_BIND( Brightness, "brightness" ); -#endif + } INIT_GRA_PROP_BIND( Fullscreen, "fullscreen" ); INIT_GRA_PROP_BIND( ShowCursor, "show_cursor" ); diff --git a/binding-mri/input-binding.cpp b/binding-mri/input-binding.cpp index 36094f2..0fc0ef2 100644 --- a/binding-mri/input-binding.cpp +++ b/binding-mri/input-binding.cpp @@ -38,15 +38,18 @@ static int getButtonArg(int argc, VALUE *argv) { int num; -#ifdef RGSS3 - ID sym; - rb_get_args(argc, argv, "n", &sym RB_ARG_END); + if (rgssVer >= 3) + { + ID sym; + rb_get_args(argc, argv, "n", &sym RB_ARG_END); - VALUE symHash = getRbData()->buttoncodeHash; - num = FIX2INT(rb_hash_lookup2(symHash, ID2SYM(sym), INT2FIX(Input::None))); -#else - rb_get_args(argc, argv, "i", &num RB_ARG_END); -#endif + VALUE symHash = getRbData()->buttoncodeHash; + num = FIX2INT(rb_hash_lookup2(symHash, ID2SYM(sym), INT2FIX(Input::None))); + } + else + { + rb_get_args(argc, argv, "i", &num RB_ARG_END); + } return num; } @@ -161,29 +164,32 @@ inputBindingInit() _rb_define_module_function(module, "mouse_x", inputMouseX); _rb_define_module_function(module, "mouse_y", inputMouseY); -#ifndef RGSS3 - for (size_t i = 0; i < buttonCodesN; ++i) + if (rgssVer >= 3) { - ID sym = rb_intern(buttonCodes[i].str); - VALUE val = INT2FIX(buttonCodes[i].val); + VALUE symHash = rb_hash_new(); - rb_const_set(module, sym, val); + for (size_t i = 0; i < buttonCodesN; ++i) + { + ID sym = rb_intern(buttonCodes[i].str); + VALUE val = INT2FIX(buttonCodes[i].val); + + /* In RGSS3 all Input::XYZ constants are equal to :XYZ symbols, + * to be compatible with the previous convention */ + rb_const_set(module, sym, ID2SYM(sym)); + rb_hash_aset(symHash, ID2SYM(sym), val); + } + + rb_iv_set(module, "buttoncodes", symHash); + getRbData()->buttoncodeHash = symHash; } -#else - VALUE symHash = rb_hash_new(); - - for (size_t i = 0; i < buttonCodesN; ++i) + else { - ID sym = rb_intern(buttonCodes[i].str); - VALUE val = INT2FIX(buttonCodes[i].val); + for (size_t i = 0; i < buttonCodesN; ++i) + { + ID sym = rb_intern(buttonCodes[i].str); + VALUE val = INT2FIX(buttonCodes[i].val); - /* In RGSS3 all Input::XYZ constants are equal to :XYZ symbols, - * to be compatible with the previous convention */ - rb_const_set(module, sym, ID2SYM(sym)); - rb_hash_aset(symHash, ID2SYM(sym), val); + rb_const_set(module, sym, val); + } } - - rb_iv_set(module, "buttoncodes", symHash); - getRbData()->buttoncodeHash = symHash; -#endif } diff --git a/binding-mri/module_rpg.cpp b/binding-mri/module_rpg.cpp index 762e140..021b323 100644 --- a/binding-mri/module_rpg.cpp +++ b/binding-mri/module_rpg.cpp @@ -1,8 +1,4 @@ -#ifdef RGSS3 -# include "module_rpg3.rb.xxd" -#elif RGSS2 +# include "module_rpg1.rb.xxd" # include "module_rpg2.rb.xxd" -#else -# include "module_rpg.rb.xxd" -#endif +# include "module_rpg3.rb.xxd" diff --git a/binding-mri/module_rpg.rb.xxd b/binding-mri/module_rpg1.rb.xxd similarity index 99% rename from binding-mri/module_rpg.rb.xxd rename to binding-mri/module_rpg1.rb.xxd index fc02c39..d15c18e 100644 --- a/binding-mri/module_rpg.rb.xxd +++ b/binding-mri/module_rpg1.rb.xxd @@ -1,4 +1,4 @@ -extern const char module_rpg[] = { +extern const char module_rpg1[] = { 0x6d, 0x6f, 0x64, 0x75, 0x6c, 0x65, 0x20, 0x52, 0x50, 0x47, 0x0a, 0x20, 0x20, 0x6d, 0x6f, 0x64, 0x75, 0x6c, 0x65, 0x20, 0x43, 0x61, 0x63, 0x68, 0x65, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x40, 0x63, 0x61, 0x63, 0x68, 0x65, 0x20, 0x3d, 0x20, 0x7b, 0x7d, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x64, 0x65, @@ -2404,4 +2404,4 @@ extern const char module_rpg[] = { 0x74, 0x72, 0x5f, 0x61, 0x63, 0x63, 0x65, 0x73, 0x73, 0x6f, 0x72, 0x20, 0x3a, 0x70, 0x69, 0x74, 0x63, 0x68, 0x0a, 0x20, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x65, 0x6e, 0x64, 0x0a, 0x00 }; -extern const unsigned int module_rpg_len = 38461; \ No newline at end of file +extern const unsigned int module_rpg1_len = 38461; diff --git a/binding-mri/module_rpg2.rb.xxd b/binding-mri/module_rpg2.rb.xxd index f06514d..e850791 100644 --- a/binding-mri/module_rpg2.rb.xxd +++ b/binding-mri/module_rpg2.rb.xxd @@ -1,4 +1,4 @@ -extern const char module_rpg[] = { +extern const char module_rpg2[] = { 0x6d, 0x6f, 0x64, 0x75, 0x6c, 0x65, 0x20, 0x52, 0x50, 0x47, 0x0a, 0x20, 0x20, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x20, 0x4d, 0x61, 0x70, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x64, 0x65, 0x66, 0x20, 0x69, 0x6e, 0x69, 0x74, 0x69, 0x61, 0x6c, 0x69, 0x7a, 0x65, 0x28, 0x77, 0x69, 0x64, 0x74, 0x68, 0x2c, @@ -1441,4 +1441,4 @@ extern const char module_rpg[] = { 0x0a, 0x20, 0x20, 0x20, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x65, 0x6e, 0x64, 0x0a, 0x00 }; -extern const unsigned int module_rpg_len = 23043; \ No newline at end of file +extern const unsigned int module_rpg2_len = 23043; diff --git a/binding-mri/module_rpg3.rb.xxd b/binding-mri/module_rpg3.rb.xxd index ba89233..b22ebb6 100644 --- a/binding-mri/module_rpg3.rb.xxd +++ b/binding-mri/module_rpg3.rb.xxd @@ -1,4 +1,4 @@ -extern const char module_rpg[] = { +extern const char module_rpg3[] = { 0x0a, 0x6d, 0x6f, 0x64, 0x75, 0x6c, 0x65, 0x20, 0x52, 0x50, 0x47, 0x0a, 0x20, 0x20, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x20, 0x4d, 0x61, 0x70, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x20, 0x45, 0x6e, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x65, 0x72, 0x0a, 0x20, 0x20, 0x20, 0x20, @@ -1401,4 +1401,4 @@ extern const char module_rpg[] = { 0x65, 0x5f, 0x73, 0x74, 0x6f, 0x70, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x20, 0x20, 0x65, 0x6e, 0x64, 0x0a, 0x0a, 0x65, 0x6e, 0x64, 0x0a, 0x00 }; -extern const unsigned int module_rpg_len = 22410; \ No newline at end of file +extern const unsigned int module_rpg3_len = 22410; diff --git a/binding-mri/sprite-binding.cpp b/binding-mri/sprite-binding.cpp index bf0d4f7..6dea6f5 100644 --- a/binding-mri/sprite-binding.cpp +++ b/binding-mri/sprite-binding.cpp @@ -20,6 +20,7 @@ */ #include "sprite.h" +#include "sharedstate.h" #include "disposable-binding.h" #include "flashable-binding.h" #include "sceneelement-binding.h" @@ -60,15 +61,17 @@ DEF_PROP_I(Sprite, OY) DEF_PROP_I(Sprite, BushDepth) DEF_PROP_I(Sprite, Opacity) DEF_PROP_I(Sprite, BlendType) +DEF_PROP_I(Sprite, WaveAmp) +DEF_PROP_I(Sprite, WaveLength) +DEF_PROP_I(Sprite, WaveSpeed) DEF_PROP_F(Sprite, ZoomX) DEF_PROP_F(Sprite, ZoomY) DEF_PROP_F(Sprite, Angle) +DEF_PROP_F(Sprite, WavePhase) DEF_PROP_B(Sprite, Mirror) -#ifdef RGSS2 - RB_METHOD(spriteWidth) { RB_UNUSED_PARAM; @@ -93,13 +96,6 @@ RB_METHOD(spriteHeight) return rb_fix_new(value); } -DEF_PROP_I(Sprite, WaveAmp) -DEF_PROP_I(Sprite, WaveLength) -DEF_PROP_I(Sprite, WaveSpeed) -DEF_PROP_F(Sprite, WavePhase) - -#endif - void spriteBindingInit() { @@ -130,7 +126,8 @@ spriteBindingInit() INIT_PROP_BIND( Sprite, Color, "color" ); INIT_PROP_BIND( Sprite, Tone, "tone" ); -#ifdef RGSS2 + if (rgssVer >= 2) + { _rb_define_method(klass, "width", spriteWidth); _rb_define_method(klass, "height", spriteHeight); @@ -138,5 +135,5 @@ spriteBindingInit() INIT_PROP_BIND( Sprite, WaveLength, "wave_length" ); INIT_PROP_BIND( Sprite, WaveSpeed, "wave_speed" ); INIT_PROP_BIND( Sprite, WavePhase, "wave_phase" ); -#endif + } } diff --git a/binding-mri/tilemapvx-binding.cpp b/binding-mri/tilemapvx-binding.cpp index bfa3d39..c688d72 100644 --- a/binding-mri/tilemapvx-binding.cpp +++ b/binding-mri/tilemapvx-binding.cpp @@ -23,17 +23,12 @@ #include "viewport.h" #include "bitmap.h" #include "table.h" +#include "sharedstate.h" #include "disposable-binding.h" #include "binding-util.h" #include "binding-types.h" -#ifdef RGSS3 -# define FLAGS_PROP "flags" -#else -# define FLAGS_PROP "passages" -#endif - DEF_TYPE(TilemapVX); rb_data_type_struct BitmapArrayType; @@ -93,7 +88,7 @@ DEF_PROP_OBJ_NIL(TilemapVX, Viewport, Viewport, "viewport") DEF_PROP_OBJ(TilemapVX, Table, MapData, "map_data") DEF_PROP_OBJ(TilemapVX, Table, FlashData, "flash_data") -DEF_PROP_OBJ(TilemapVX, Table, Flags, FLAGS_PROP) +DEF_PROP_OBJ(TilemapVX, Table, Flags, "flags") DEF_PROP_B(TilemapVX, Visible) @@ -149,11 +144,19 @@ tilemapVXBindingInit() INIT_PROP_BIND( TilemapVX, Viewport, "viewport" ); INIT_PROP_BIND( TilemapVX, MapData, "map_data" ); INIT_PROP_BIND( TilemapVX, FlashData, "flash_data" ); - INIT_PROP_BIND( TilemapVX, Flags, FLAGS_PROP ); INIT_PROP_BIND( TilemapVX, Visible, "visible" ); INIT_PROP_BIND( TilemapVX, OX, "ox" ); INIT_PROP_BIND( TilemapVX, OY, "oy" ); + if (rgssVer == 3) + { + INIT_PROP_BIND( TilemapVX, Flags, "flags" ); + } + else + { + INIT_PROP_BIND( TilemapVX, Flags, "passages" ); + } + initType(BitmapArrayType, "BitmapArray", 0); klass = rb_define_class_under(klass, "BitmapArray", rb_cObject); diff --git a/binding-mri/viewport-binding.cpp b/binding-mri/viewport-binding.cpp index 1c0a389..2cd6fd4 100644 --- a/binding-mri/viewport-binding.cpp +++ b/binding-mri/viewport-binding.cpp @@ -20,6 +20,7 @@ */ #include "viewport.h" +#include "sharedstate.h" #include "disposable-binding.h" #include "flashable-binding.h" #include "sceneelement-binding.h" @@ -32,14 +33,11 @@ RB_METHOD(viewportInitialize) { Viewport *v; -#ifdef RGSS3 - if (argc == 0) + if (argc == 0 && rgssVer >= 3) { v = new Viewport(); } - else -#endif - if (argc == 1) + else if (argc == 1) { /* The rect arg is only used to init the viewport, * and does NOT replace its 'rect' property */ diff --git a/binding-mri/viewportelement-binding.h b/binding-mri/viewportelement-binding.h index 2359198..21e3fef 100644 --- a/binding-mri/viewportelement-binding.h +++ b/binding-mri/viewportelement-binding.h @@ -23,6 +23,7 @@ #define VIEWPORTELEMENTBINDING_H #include "viewport.h" +#include "sharedstate.h" #include "binding-util.h" #include "binding-types.h" @@ -39,8 +40,6 @@ RB_METHOD(viewportElementGetViewport) return rb_iv_get(self, "viewport"); } -#ifdef RGSS2 - template RB_METHOD(viewportElementSetViewport) { @@ -63,8 +62,6 @@ RB_METHOD(viewportElementSetViewport) return viewportObj; } -#endif - template static C * viewportElementInitialize(int argc, VALUE *argv, VALUE self) @@ -98,9 +95,10 @@ viewportElementBindingInit(VALUE klass) _rb_define_method(klass, "viewport", viewportElementGetViewport); -#ifdef RGSS2 + if (rgssVer >= 2) + { _rb_define_method(klass, "viewport=", viewportElementSetViewport); -#endif + } } #endif // VIEWPORTELEMENTBINDING_H diff --git a/binding-mri/windowvx-binding.cpp b/binding-mri/windowvx-binding.cpp index 9b15011..b698a58 100644 --- a/binding-mri/windowvx-binding.cpp +++ b/binding-mri/windowvx-binding.cpp @@ -34,17 +34,20 @@ RB_METHOD(windowVXInitialize) { WindowVX *w; -#if RGSS_VER == 3 - int x, y, width, height; - x = y = width = height = 0; + if (rgssVer >= 3) + { + int x, y, width, height; + x = y = width = height = 0; - if (argc == 4) - rb_get_args(argc, argv, "iiii", &x, &y, &width, &height RB_ARG_END); + if (argc == 4) + rb_get_args(argc, argv, "iiii", &x, &y, &width, &height RB_ARG_END); - w = new WindowVX(x, y, width, height); -#else - w = viewportElementInitialize(argc, argv, self); -#endif + w = new WindowVX(x, y, width, height); + } + else + { + w = viewportElementInitialize(argc, argv, self); + } setPrivateData(self, w); @@ -54,12 +57,13 @@ RB_METHOD(windowVXInitialize) wrapProperty(self, w->getTone(), "tone", ToneType); wrapProperty(self, w->getCursorRect(), "cursor_rect", RectType); -#ifdef RGSS2 - Bitmap *contents = new Bitmap(1, 1); - VALUE contentsObj = wrapObject(contents, BitmapType); - bitmapInitProps(contents, contentsObj); - rb_iv_set(self, "contents", contentsObj); -#endif + if (rgssVer >= 2) + { + Bitmap *contents = new Bitmap(1, 1); + VALUE contentsObj = wrapObject(contents, BitmapType); + bitmapInitProps(contents, contentsObj); + rb_iv_set(self, "contents", contentsObj); + } return self; } diff --git a/binding-mruby/binding-util.h b/binding-mruby/binding-util.h index d7c92da..448bf4a 100644 --- a/binding-mruby/binding-util.h +++ b/binding-mruby/binding-util.h @@ -98,9 +98,7 @@ struct MrbData * so I can measure how much of a speed difference they make */ mrb_sym symbols[CommonSymbolsMax]; -#ifdef RGSS3 mrb_value buttoncodeHash; -#endif MrbData(mrb_state *mrb); }; diff --git a/binding-mruby/input-binding.cpp b/binding-mruby/input-binding.cpp index 61896e8..7791dec 100644 --- a/binding-mruby/input-binding.cpp +++ b/binding-mruby/input-binding.cpp @@ -41,17 +41,20 @@ static mrb_int getButtonArg(mrb_state *mrb) { mrb_int num; -#ifdef RGSS3 - mrb_sym sym; - mrb_get_args(mrb, "n", &sym); + if (rgssVer >= 3) + { + mrb_sym sym; + mrb_get_args(mrb, "n", &sym); - mrb_value symHash = getMrbData(mrb)->buttoncodeHash; - mrb_value numVal = mrb_hash_fetch(mrb, symHash, mrb_symbol_value(sym), - mrb_fixnum_value(Input::None)); - num = mrb_fixnum(numVal); -#else - mrb_get_args(mrb, "i", &num); -#endif + mrb_value symHash = getMrbData(mrb)->buttoncodeHash; + mrb_value numVal = mrb_hash_fetch(mrb, symHash, mrb_symbol_value(sym), + mrb_fixnum_value(Input::None)); + num = mrb_fixnum(numVal); + } + else + { + mrb_get_args(mrb, "i", &num); + } return num; } @@ -167,32 +170,35 @@ inputBindingInit(mrb_state *mrb) mrb_value modVal = mrb_obj_value(module); -#ifndef RGSS3 - for (size_t i = 0; i < buttonCodesN; ++i) + if (rgssVer >= 3) { - const char *str = buttonCodes[i].str; - mrb_sym sym = mrb_intern_static(mrb, str, strlen(str)); - mrb_value val = mrb_fixnum_value(buttonCodes[i].val); + mrb_value symHash = mrb_hash_new_capa(mrb, buttonCodesN); - mrb_const_set(mrb, modVal, sym, val); + for (size_t i = 0; i < buttonCodesN; ++i) + { + const char *str = buttonCodes[i].str; + mrb_sym sym = mrb_intern_static(mrb, str, strlen(str)); + mrb_value symVal = mrb_symbol_value(sym); + mrb_value val = mrb_fixnum_value(buttonCodes[i].val); + + /* In RGSS3 all Input::XYZ constants are equal to :XYZ symbols, + * to be compatible with the previous convention */ + mrb_const_set(mrb, modVal, sym, symVal); + mrb_hash_set(mrb, symHash, symVal, val); + } + + mrb_iv_set(mrb, modVal, mrb_intern_lit(mrb, "buttoncodes"), symHash); + getMrbData(mrb)->buttoncodeHash = symHash; } -#else - mrb_value symHash = mrb_hash_new_capa(mrb, buttonCodesN); - - for (size_t i = 0; i < buttonCodesN; ++i) + else { - const char *str = buttonCodes[i].str; - mrb_sym sym = mrb_intern_static(mrb, str, strlen(str)); - mrb_value symVal = mrb_symbol_value(sym); - mrb_value val = mrb_fixnum_value(buttonCodes[i].val); + for (size_t i = 0; i < buttonCodesN; ++i) + { + const char *str = buttonCodes[i].str; + mrb_sym sym = mrb_intern_static(mrb, str, strlen(str)); + mrb_value val = mrb_fixnum_value(buttonCodes[i].val); - /* In RGSS3 all Input::XYZ constants are equal to :XYZ symbols, - * to be compatible with the previous convention */ - mrb_const_set(mrb, modVal, sym, symVal); - mrb_hash_set(mrb, symHash, symVal, val); + mrb_const_set(mrb, modVal, sym, val); + } } - - mrb_iv_set(mrb, modVal, mrb_intern_lit(mrb, "buttoncodes"), symHash); - getMrbData(mrb)->buttoncodeHash = symHash; -#endif } diff --git a/binding-mruby/sprite-binding.cpp b/binding-mruby/sprite-binding.cpp index a25e91e..ddfee1e 100644 --- a/binding-mruby/sprite-binding.cpp +++ b/binding-mruby/sprite-binding.cpp @@ -59,15 +59,17 @@ DEF_PROP_I(Sprite, OY) DEF_PROP_I(Sprite, BushDepth) DEF_PROP_I(Sprite, Opacity) DEF_PROP_I(Sprite, BlendType) +DEF_PROP_I(Sprite, WaveAmp) +DEF_PROP_I(Sprite, WaveLength) +DEF_PROP_I(Sprite, WaveSpeed) DEF_PROP_F(Sprite, ZoomX) DEF_PROP_F(Sprite, ZoomY) DEF_PROP_F(Sprite, Angle) +DEF_PROP_F(Sprite, WavePhase) DEF_PROP_B(Sprite, Mirror) -#ifdef RGSS2 - MRB_METHOD(spriteWidth) { Sprite *s = getPrivateData(mrb, self); @@ -88,13 +90,6 @@ MRB_METHOD(spriteHeight) return mrb_fixnum_value(value); } -DEF_PROP_I(Sprite, WaveAmp) -DEF_PROP_I(Sprite, WaveLength) -DEF_PROP_I(Sprite, WaveSpeed) -DEF_PROP_F(Sprite, WavePhase) - -#endif - void spriteBindingInit(mrb_state *mrb) { @@ -122,7 +117,8 @@ spriteBindingInit(mrb_state *mrb) INIT_PROP_BIND( Sprite, Color, "color" ); INIT_PROP_BIND( Sprite, Tone, "tone" ); -#ifdef RGSS2 + if (rgssVer >= 2) + { mrb_define_method(mrb, klass, "width", spriteWidth, MRB_ARGS_NONE()); mrb_define_method(mrb, klass, "height", spriteHeight, MRB_ARGS_NONE()); @@ -130,7 +126,7 @@ spriteBindingInit(mrb_state *mrb) INIT_PROP_BIND( Sprite, WaveLength, "wave_length" ); INIT_PROP_BIND( Sprite, WaveSpeed, "wave_speed" ); INIT_PROP_BIND( Sprite, WavePhase, "wave_phase" ); -#endif + } mrb_define_method(mrb, klass, "inspect", inspectObject, MRB_ARGS_NONE()); } diff --git a/mkxp.conf.sample b/mkxp.conf.sample index fd38497..78c0ffc 100644 --- a/mkxp.conf.sample +++ b/mkxp.conf.sample @@ -1,5 +1,15 @@ # Lines starting with '#' are comments +# Specify the RGSS version to run under. +# Possible values are 0, 1, 2, 3. If set to 0, +# mkxp will try to guess the required version +# based on the game files found in gameFolder. +# If this fails, the version defaults to 1. +# (default: 0) +# +# rgssVersion=1 + + # Create a debug context and log # OpenGL debug information to the console # (default: disabled) @@ -40,12 +50,20 @@ # vsync=false -# Create the window with 640 in width at startup +# Specify the window width on startup. If set to 0, +# it will default to the default resolution width +# specific to the RGSS version (640 in RGSS1, 544 +# in RGSS2 or higher). +# (default: 0) # # defScreenW=640 -# Create the window with 480 in height at startup +# Specify the window height on startup. If set to 0, +# it will default to the default resolution height +# specific to the RGSS version (480 in RGSS1, 416 +# in RGSS2 or higher). +# (default: 0) # # defScreenH=480 diff --git a/mkxp.pro b/mkxp.pro index 211b9db..1cbed85 100644 --- a/mkxp.pro +++ b/mkxp.pro @@ -45,45 +45,11 @@ contains(BINDING, NULL) { CONFIG += BINDING_NULL } -# TODO: Use RGSS_VER macro instead of RGSSN in C++ sources -isEmpty(RGSS_VER) { - RGSS_VER = 1 -} - -contains(RGSS_VER, 1) { - _HAVE_RGSS_VER = YES - DEFINES += "RGSS_VER=1" -} - -contains(RGSS_VER, 2) { - contains(_HAVE_RGSS_VER, YES) { - error("Only one RGSS version may be selected") - } - _HAVE_RGSS_VER = YES - - CONFIG += RGSS2 - DEFINES += RGSS2 "RGSS_VER=2" -} - -contains(RGSS_VER, 3) { - contains(_HAVE_RGSS_VER, YES) { - error("Only one RGSS version may be selected") - } - _HAVE_RGSS_VER = YES - - CONFIG += RGSS2 RGSS3 - DEFINES += RGSS2 RGSS3 "RGSS_VER=3" -} - unix { CONFIG += link_pkgconfig - PKGCONFIG += sigc++-2.0 pixman-1 zlib physfs \ + PKGCONFIG += sigc++-2.0 pixman-1 zlib physfs vorbisfile \ sdl2 SDL2_image SDL2_ttf SDL_sound openal - RGSS2 { - PKGCONFIG += vorbisfile - } - MIDI { PKGCONFIG += fluidsynth } @@ -166,7 +132,10 @@ HEADERS += \ src/aldatasource.h \ src/alstream.h \ src/audiostream.h \ - src/rgssad.h + src/rgssad.h \ + src/windowvx.h \ + src/tilemapvx.h \ + src/tileatlasvx.h SOURCES += \ src/main.cpp \ @@ -202,7 +171,12 @@ SOURCES += \ src/alstream.cpp \ src/audiostream.cpp \ src/rgssad.cpp \ - src/bundledfont.cpp + src/bundledfont.cpp \ + src/vorbissource.cpp \ + src/windowvx.cpp \ + src/tilemapvx.cpp \ + src/tileatlasvx.cpp \ + src/autotilesvx.cpp EMBED = \ shader/transSimple.frag \ @@ -219,28 +193,12 @@ EMBED = \ shader/simpleColor.vert \ shader/sprite.vert \ shader/tilemap.vert \ - assets/liberation.ttf - -RGSS2 { - HEADERS += \ - src/windowvx.h \ - src/tilemapvx.h \ - src/tileatlasvx.h - - SOURCES += \ - src/vorbissource.cpp \ - src/windowvx.cpp \ - src/tilemapvx.cpp \ - src/tileatlasvx.cpp \ - src/autotilesvx.cpp - - EMBED += \ shader/blur.frag \ shader/blurH.vert \ shader/blurV.vert \ shader/simpleMatrix.vert \ - shader/tilemapvx.vert -} + shader/tilemapvx.vert \ + assets/liberation.ttf MIDI { HEADERS += \ @@ -352,13 +310,9 @@ BINDING_MRI { binding-mri/tilemap-binding.cpp \ binding-mri/audio-binding.cpp \ binding-mri/module_rpg.cpp \ - binding-mri/filesystem-binding.cpp - - RGSS2 { - SOURCES += \ - binding-mri/windowvx-binding.cpp \ - binding-mri/tilemapvx-binding.cpp - } + binding-mri/filesystem-binding.cpp \ + binding-mri/windowvx-binding.cpp \ + binding-mri/tilemapvx-binding.cpp } OTHER_FILES += $$EMBED diff --git a/src/aldatasource.h b/src/aldatasource.h index 1b72177..b607a80 100644 --- a/src/aldatasource.h +++ b/src/aldatasource.h @@ -58,10 +58,8 @@ ALDataSource *createSDLSource(SDL_RWops &ops, uint32_t maxBufSize, bool looped); -#ifdef RGSS2 ALDataSource *createVorbisSource(SDL_RWops &ops, bool looped); -#endif #ifdef MIDI ALDataSource *createMidiSource(SDL_RWops &ops, diff --git a/src/alstream.cpp b/src/alstream.cpp index a8646d4..80d8695 100644 --- a/src/alstream.cpp +++ b/src/alstream.cpp @@ -198,27 +198,33 @@ void ALStream::openSource(const std::string &filename) shState->fileSystem().openRead(srcOps, filename.c_str(), FileSystem::Audio, false, &ext); needsRewind = false; -#if RGSS2 || MIDI - /* Try to read ogg file signature */ - char sig[5] = { 0 }; - SDL_RWread(&srcOps, sig, 1, 4); - SDL_RWseek(&srcOps, 0, RW_SEEK_SET); + bool readSig = rgssVer >= 2; -#ifdef RGSS2 - if (!strcmp(sig, "OggS")) - { - source = createVorbisSource(srcOps, looped); - return; - } -#endif #ifdef MIDI - if (!strcmp(sig, "MThd")) + readSig = true; +#endif + + if (readSig) { - source = createMidiSource(srcOps, looped); - return; + /* Try to read ogg file signature */ + char sig[5] = { 0 }; + SDL_RWread(&srcOps, sig, 1, 4); + SDL_RWseek(&srcOps, 0, RW_SEEK_SET); + + if (!strcmp(sig, "OggS")) + { + source = createVorbisSource(srcOps, looped); + return; + } + +#ifdef MIDI + if (!strcmp(sig, "MThd")) + { + source = createMidiSource(srcOps, looped); + return; + } +#endif } -#endif -#endif source = createSDLSource(srcOps, ext, STREAM_BUF_SIZE, looped); } diff --git a/src/bitmap.cpp b/src/bitmap.cpp index 4cafda7..f508334 100644 --- a/src/bitmap.cpp +++ b/src/bitmap.cpp @@ -551,8 +551,6 @@ void Bitmap::clearRect(const IntRect &rect) p->onModified(); } -#ifdef RGSS2 - void Bitmap::blur() { GUARD_MEGA; @@ -689,8 +687,6 @@ void Bitmap::radialBlur(int angle, int divisions) p->onModified(); } -#endif - void Bitmap::clear() { GUARD_MEGA; diff --git a/src/bitmap.h b/src/bitmap.h index 612d11f..22da2fe 100644 --- a/src/bitmap.h +++ b/src/bitmap.h @@ -73,10 +73,8 @@ public: int width, int height); void clearRect(const IntRect &rect); -#ifdef RGSS2 void blur(); void radialBlur(int angle, int divisions); -#endif void clear(); diff --git a/src/config.cpp b/src/config.cpp index 9166ddb..680953c 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -122,14 +122,15 @@ typedef std::vector StringVec; namespace po = boost::program_options; Config::Config() - : debugMode(false), + : rgssVersion(0), + debugMode(false), winResizable(false), fullscreen(false), fixedAspectRatio(true), smoothScaling(false), vsync(false), - defScreenW(DEF_SCREEN_W), - defScreenH(DEF_SCREEN_H), + defScreenW(0), + defScreenH(0), fixedFramerate(0), frameSkip(true), solidFonts(false), @@ -147,6 +148,7 @@ Config::Config() void Config::read(int argc, char *argv[]) { #define PO_DESC_ALL \ + PO_DESC(rgssVersion, int) \ PO_DESC(debugMode, bool) \ PO_DESC(winResizable, bool) \ PO_DESC(fullscreen, bool) \ @@ -219,7 +221,7 @@ void Config::read(int argc, char *argv[]) GUARD_ALL( fontSubs = vm["fontSub"].as(); ); - GUARD_ALL( rubyLoadpaths = vm["rubyLoadpath"].as(); ) + GUARD_ALL( rubyLoadpaths = vm["rubyLoadpath"].as(); ); #undef PO_DESC #undef PO_DESC_ALL @@ -329,4 +331,31 @@ void Config::readGameINI() if (game.title.empty()) game.title = baseName(gameFolder); + + if (rgssVersion == 0) + { + /* Try to guess RGSS version based on Data/Scripts extension */ + rgssVersion = 1; + + if (!game.scripts.empty()) + { + const char *p = &game.scripts[game.scripts.size()]; + const char *head = &game.scripts[0]; + + while (--p != head) + if (*p == '.') + break; + + if (!strcmp(p, ".rvdata")) + rgssVersion = 2; + else if (!strcmp(p, ".rvdata2")) + rgssVersion = 3; + } + } + + if (defScreenW <= 0) + defScreenW = (rgssVersion == 1 ? 640 : 544); + + if (defScreenH <= 0) + defScreenH = (rgssVersion == 1 ? 480 : 416); } diff --git a/src/config.h b/src/config.h index c22b44a..e47cc32 100644 --- a/src/config.h +++ b/src/config.h @@ -25,16 +25,10 @@ #include #include -#ifndef RGSS2 -# define DEF_SCREEN_W 640 -# define DEF_SCREEN_H 480 -#else -# define DEF_SCREEN_W 544 -# define DEF_SCREEN_H 416 -#endif - struct Config { + int rgssVersion; + bool debugMode; bool winResizable; diff --git a/src/font.cpp b/src/font.cpp index aca1de0..8a85f6c 100644 --- a/src/font.cpp +++ b/src/font.cpp @@ -48,14 +48,6 @@ BUNDLED_FONT_DECL(liberation) #define BNDL_F_D(f) BUNDLED_FONT_D(f) #define BNDL_F_L(f) BUNDLED_FONT_L(f) -#ifdef RGSS3 -# define DEF_SHADOW false -# define DEF_OUTLINE true -#else -# define DEF_SHADOW true -# define DEF_OUTLINE false -#endif - typedef std::pair FontKey; static SDL_RWops *openBundledFont() @@ -269,14 +261,20 @@ std::string FontPrivate::defaultName = "Arial"; int FontPrivate::defaultSize = 22; bool FontPrivate::defaultBold = false; bool FontPrivate::defaultItalic = false; -bool FontPrivate::defaultOutline = DEF_OUTLINE; -bool FontPrivate::defaultShadow = DEF_SHADOW; +bool FontPrivate::defaultOutline = false; /* Inited at runtime */ +bool FontPrivate::defaultShadow = false; /* Inited at runtime */ Color *FontPrivate::defaultColor = &FontPrivate::defaultColorTmp; Color *FontPrivate::defaultOutColor = &FontPrivate::defaultOutColorTmp; Color FontPrivate::defaultColorTmp(255, 255, 255, 255); Color FontPrivate::defaultOutColorTmp(0, 0, 0, 128); +void Font::initDefaults() +{ + FontPrivate::defaultOutline = (rgssVer >= 3 ? true : false); + FontPrivate::defaultShadow = (rgssVer >= 3 ? false : true ); +} + bool Font::doesExist(const char *name) { if (!name) diff --git a/src/font.h b/src/font.h index 0e90385..8a5b075 100644 --- a/src/font.h +++ b/src/font.h @@ -102,6 +102,8 @@ public: DECL_ATTR_STATIC( DefaultOutline, bool ) DECL_ATTR_STATIC( DefaultOutColor, Color* ) + static void initDefaults(); + /* internal */ _TTF_Font *getSdlFont(); diff --git a/src/graphics.cpp b/src/graphics.cpp index d7e38f2..9f69076 100644 --- a/src/graphics.cpp +++ b/src/graphics.cpp @@ -45,11 +45,9 @@ #include #include -#ifdef RGSS2 -# define DEF_FRAMERATE 60 -#else -# define DEF_FRAMERATE 40 -#endif +#define DEF_SCREEN_W (rgssVer == 1 ? 640 : 544) +#define DEF_SCREEN_H (rgssVer == 1 ? 480 : 416) +#define DEF_FRAMERATE (rgssVer == 1 ? 40 : 60) struct PingPong { diff --git a/src/input.cpp b/src/input.cpp index 15201ee..5e1085b 100644 --- a/src/input.cpp +++ b/src/input.cpp @@ -205,23 +205,32 @@ static const KbBindingData defaultKbBindings[] = { SDL_SCANCODE_B, Input::None }, { SDL_SCANCODE_D, Input::Z }, { SDL_SCANCODE_Q, Input::L }, - { SDL_SCANCODE_W, Input::R }, -#if RGSS_VER == 1 + { SDL_SCANCODE_W, Input::R } +}; + +/* RGSS1 */ +static const KbBindingData defaultKbBindings1[] = +{ { SDL_SCANCODE_Z, Input::A }, { SDL_SCANCODE_C, Input::C }, { SDL_SCANCODE_V, Input::Z }, { SDL_SCANCODE_A, Input::Y }, { SDL_SCANCODE_S, Input::X } -#else +}; + +/* RGSS2 and higher */ +static const KbBindingData defaultKbBindings2[] = +{ { SDL_SCANCODE_Z, Input::C }, { SDL_SCANCODE_C, Input::None }, { SDL_SCANCODE_V, Input::None }, { SDL_SCANCODE_A, Input::X }, { SDL_SCANCODE_S, Input::Y } -#endif }; static elementsN(defaultKbBindings); +static elementsN(defaultKbBindings1); +static elementsN(defaultKbBindings2); /* Rebindable */ static const JsBindingData defaultJsBindings[] = @@ -374,15 +383,20 @@ struct InputPrivate void initKbBindings() { - kbBindings.resize(staticKbBindingsN+defaultKbBindingsN); - - size_t n = 0; + kbBindings.clear(); for (size_t i = 0; i < staticKbBindingsN; ++i) - kbBindings[n++] = KbBinding(staticKbBindings[i]); + kbBindings.push_back(KbBinding(staticKbBindings[i])); for (size_t i = 0; i < defaultKbBindingsN; ++i) - kbBindings[n++] = KbBinding(defaultKbBindings[i]); + kbBindings.push_back(KbBinding(defaultKbBindings[i])); + + if (rgssVer == 1) + for (size_t i = 0; i < defaultKbBindings1N; ++i) + kbBindings.push_back(KbBinding(defaultKbBindings1[i])); + else + for (size_t i = 0; i < defaultKbBindings2N; ++i) + kbBindings.push_back(KbBinding(defaultKbBindings2[i])); /* Add to binging array */ for (size_t i = 0; i < kbBindings.size(); ++i) diff --git a/src/scene.cpp b/src/scene.cpp index a9836af..c352eb7 100644 --- a/src/scene.cpp +++ b/src/scene.cpp @@ -179,13 +179,15 @@ bool SceneElement::operator<(const SceneElement &o) const { if (z == o.z) { -#ifdef RGSS2 - /* RGSS2: If two sprites' Z values collide, - * their Y coordinates decide draw order. Only - * on equal Y does the creation time take effect */ - if (isSprite && o.isSprite && spriteY != o.spriteY) - return (spriteY < o.spriteY); -#endif + if (rgssVer >= 2) + { + /* RGSS2: If two sprites' Z values collide, + * their Y coordinates decide draw order. Only + * on equal Y does the creation time take effect */ + if (isSprite && o.isSprite && spriteY != o.spriteY) + return (spriteY < o.spriteY); + } + return (creationStamp <= o.creationStamp); } diff --git a/src/shader.cpp b/src/shader.cpp index 4db3095..481067f 100644 --- a/src/shader.cpp +++ b/src/shader.cpp @@ -42,14 +42,11 @@ #include "../simpleColor.vert.xxd" #include "../sprite.vert.xxd" #include "../tilemap.vert.xxd" - -#ifdef RGSS2 #include "../blur.frag.xxd" #include "../simpleMatrix.vert.xxd" #include "../blurH.vert.xxd" #include "../blurV.vert.xxd" #include "../tilemapvx.vert.xxd" -#endif #define INIT_SHADER(vert, frag, name) \ @@ -505,8 +502,6 @@ void HueShader::setInputTexture(TEX::ID tex) } -#ifdef RGSS2 - SimpleMatrixShader::SimpleMatrixShader() { INIT_SHADER(simpleMatrix, simpleAlpha, SimpleMatrixShader); @@ -551,8 +546,6 @@ void TilemapVXShader::setAniOffset(const Vec2 &value) gl.Uniform2f(u_aniOffset, value.x, value.y); } -#endif - BltShader::BltShader() { diff --git a/src/shader.h b/src/shader.h index 8dfb387..768d53b 100644 --- a/src/shader.h +++ b/src/shader.h @@ -213,7 +213,6 @@ private: GLint u_hueAdjust, u_inputTexture; }; -#ifdef RGSS2 class SimpleMatrixShader : public ShaderBase { public: @@ -255,8 +254,6 @@ private: GLint u_aniOffset; }; -#endif - /* Bitmap blit */ class BltShader : public ShaderBase { @@ -288,12 +285,9 @@ struct ShaderSet SimpleTransShader simpleTrans; HueShader hue; BltShader blt; - -#ifdef RGSS2 SimpleMatrixShader simpleMatrix; BlurShader blur; TilemapVXShader tilemapVX; -#endif }; #endif // SHADER_H diff --git a/src/sharedstate.cpp b/src/sharedstate.cpp index a7fbcde..eff10c0 100644 --- a/src/sharedstate.cpp +++ b/src/sharedstate.cpp @@ -46,15 +46,21 @@ #include SharedState *SharedState::instance = 0; +int SharedState::rgssVersion = 0; static GlobalIBO *_globalIBO = 0; -#ifdef RGSS3 -#define GAME_ARCHIVE "Game.rgss3a" -#elif RGSS2 -#define GAME_ARCHIVE "Game.rgss2a" -#else -#define GAME_ARCHIVE "Game.rgssad" -#endif +static const char *defGameArchive() +{ + if (rgssVer == 1) + return "Game.rgssad"; + else if (rgssVer == 2) + return "Game.rgss2a"; + else if (rgssVer == 3) + return "Game.rgss3a"; + + assert(!"unreachable"); + return 0; +} struct SharedStatePrivate { @@ -122,7 +128,7 @@ struct SharedStatePrivate } // FIXME find out correct archive filename - std::string archPath = GAME_ARCHIVE; + std::string archPath = defGameArchive(); /* Check if a game archive exists */ FILE *tmp = fopen(archPath.c_str(), "r"); @@ -158,8 +164,9 @@ struct SharedStatePrivate /* RGSS3 games will call setup_midi, so there's * no need to do it on startup */ -#if MIDI && !RGSS3 - midiState.initDefaultSynths(); +#if MIDI + if (rgssVer <= 2) + midiState.initDefaultSynths(); #endif } @@ -177,6 +184,9 @@ void SharedState::initInstance(RGSSThreadData *threadData) * SharedState depends on GlobalIBO existing, * Font depends on SharedState existing */ + rgssVersion = threadData->config.rgssVersion; + Font::initDefaults(); + _globalIBO = new GlobalIBO(); _globalIBO->ensureSize(1); diff --git a/src/sharedstate.h b/src/sharedstate.h index dd30e8c..6ce964d 100644 --- a/src/sharedstate.h +++ b/src/sharedstate.h @@ -26,6 +26,7 @@ #define shState SharedState::instance #define glState shState->_glState() +#define rgssVer SharedState::rgssVersion struct SharedStatePrivate; struct RGSSThreadData; @@ -114,6 +115,7 @@ struct SharedState void checkShutdown(); static SharedState *instance; + static int rgssVersion; /* This function will throw an Exception instance * on initialization error */ diff --git a/src/sprite.cpp b/src/sprite.cpp index 6c5b184..21af6d0 100644 --- a/src/sprite.cpp +++ b/src/sprite.cpp @@ -374,11 +374,11 @@ void Sprite::setY(int value) p->trans.setPosition(Vec2(getX(), value)); -#ifdef RGSS2 - p->wave.dirty = true; - - setSpriteY(value); -#endif + if (rgssVer >= 2) + { + p->wave.dirty = true; + setSpriteY(value); + } } void Sprite::setOX(int value) @@ -413,9 +413,8 @@ void Sprite::setZoomY(float value) p->trans.setScale(Vec2(getZoomX(), value)); p->recomputeBushDepth(); -#ifdef RGSS2 - p->wave.dirty = true; -#endif + if (rgssVer >= 2) + p->wave.dirty = true; } void Sprite::setAngle(float value) diff --git a/src/tileatlasvx.cpp b/src/tileatlasvx.cpp index 09988f9..a2062ad 100644 --- a/src/tileatlasvx.cpp +++ b/src/tileatlasvx.cpp @@ -280,13 +280,14 @@ void build(TEXFBO &tf, Bitmap *bitmaps[BM_COUNT]) FBO::clear(); glState.clearColor.pop(); -#ifdef RGSS3 - SDL_Surface *shadow = createShadowSet(); - TEX::bind(tf.tex); - TEX::uploadSubImage(shadowArea.x*32, shadowArea.y*32, - shadow->w, shadow->h, shadow->pixels, GL_RGBA); - SDL_FreeSurface(shadow); -#endif + if (rgssVer >= 3) + { + SDL_Surface *shadow = createShadowSet(); + TEX::bind(tf.tex); + TEX::uploadSubImage(shadowArea.x*32, shadowArea.y*32, + shadow->w, shadow->h, shadow->pixels, GL_RGBA); + SDL_FreeSurface(shadow); + } Bitmap *bm; #define EXEC_BLITS(part) \ @@ -585,12 +586,12 @@ onTile(Reader &reader, int16_t tileID, { int16_t flag = tableGetSafe(flags, tileID); bool overPlayer = flag & OVER_PLAYER_FLAG; + bool isTable; -#if RGSS_VER == 3 - bool isTable = flag & TABLE_FLAG; -#elif RGSS_VER == 2 - bool isTable = (tileID - 0x0B00) % (8 * 0x30) >= (7 * 0x30); -#endif + if (rgssVer >= 3) + isTable = flag & TABLE_FLAG; + else + isTable = (tileID - 0x0B00) % (8 * 0x30) >= (7 * 0x30); /* B ~ E */ if (tileID < 0x0400) @@ -683,11 +684,8 @@ void readTiles(Reader &reader, const Table &data, for (int i = 0; i < 2; ++i) readLayer(reader, data, flags, ox, oy, w, h, i); -#ifdef RGSS3 - readShadowLayer(reader, data, ox, oy, w, h); -#else - (void) createShadowSet; (void) readShadowLayer; -#endif + if (rgssVer >= 3) + readShadowLayer(reader, data, ox, oy, w, h); readLayer(reader, data, flags, ox, oy, w, h, 2); } diff --git a/src/windowvx.cpp b/src/windowvx.cpp index f82a1fd..11aed18 100644 --- a/src/windowvx.cpp +++ b/src/windowvx.cpp @@ -35,15 +35,9 @@ #include #include -#ifdef RGSS3 -# define DEF_Z 100 -# define DEF_PADDING 12 -# define DEF_BACK_OPAC 192 -#else -# define DEF_Z 0 -# define DEF_PADDING 16 -# define DEF_BACK_OPAC 255 -#endif +#define DEF_Z (rgssVer >= 3 ? 100 : 0) +#define DEF_PADDING (rgssVer >= 3 ? 12 : 16) +#define DEF_BACK_OPAC (rgssVer >= 3 ? 192 : 255) template struct Sides @@ -765,11 +759,11 @@ struct WindowVXPrivate glState.scissorBox.push(); glState.scissorTest.pushSet(true); -#ifdef RGSS3 - glState.scissorBox.setIntersect(clip); -#else - glState.scissorBox.setIntersect(IntRect(trans.x, trans.y, geo.w, geo.h)); -#endif + if (rgssVer >= 3) + glState.scissorBox.setIntersect(clip); + else + glState.scissorBox.setIntersect(IntRect(trans.x, trans.y, geo.w, geo.h)); + IntRect pad = padRect; pad.x += trans.x; pad.y += trans.y; @@ -779,10 +773,13 @@ struct WindowVXPrivate Vec2i contTrans = pad.pos(); contTrans.x += cursorRect->x; contTrans.y += cursorRect->y; -#ifdef RGSS3 - contTrans.x -= contentsOff.x; - contTrans.y -= contentsOff.y; -#endif + + if (rgssVer >= 3) + { + contTrans.x -= contentsOff.x; + contTrans.y -= contentsOff.y; + } + shader.setTranslation(contTrans); TEX::setSmooth(true); @@ -792,9 +789,9 @@ struct WindowVXPrivate if (contents) { -#ifndef RGSS3 - glState.scissorBox.setIntersect(clip); -#endif + if (rgssVer <= 2) + glState.scissorBox.setIntersect(clip); + Vec2i contTrans = pad.pos(); contTrans.x -= contentsOff.x; contTrans.y -= contentsOff.y;