diff --git a/.gitignore b/.gitignore index 27a8143..288c555 100644 --- a/.gitignore +++ b/.gitignore @@ -14,6 +14,7 @@ xxd+ # VS Code /.vscode +*.code-workspace # Codeblocks mkxp.layout diff --git a/.gitmodules b/.gitmodules index 03246df..e69de29 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,4 +0,0 @@ -[submodule "cwalk"] - path = cwalk - url = https://github.com/likle/cwalk - branch = stable diff --git a/README.md b/README.md index 8fac92f..39724ad 100644 --- a/README.md +++ b/README.md @@ -21,6 +21,7 @@ This binding should support RGSS1, RGSS2 and RGSS3, though I've only tested it w ## Dependencies / Building +* ObjFW * Boost.Unordered (headers only) * Boost.Program_options * libsigc++ 2.0 @@ -254,24 +255,31 @@ mingw-w64-i686-SDL2_{image,ttf} ```sh mkdir src; cd src git clone https://github.com/Ancurio/SDL_Sound +git clone https://github.com/ObjFW/ObjFW git clone https://github.com/inori-z/ruby --single-branch --branch ruby_1_8_7 cd SDL_Sound && ./bootstrap ./configure --enable-{modplug,speex,flac}=no make install -j`nproc` -cd .. + +cd ../ObjFW +./autogen.sh +./configure +make install -j`nproc` + +cd ../ruby # when you install ruby, some extensions might not want to build. # You probably don’t particularly need any, so you can just delete # any problematic ones if you like: -rm -rf ruby/ext/{tk,win32ole,openssl} +rm -rf ext/{tk,win32ole,openssl} # and try building again afterwards. Or you can try to fix whatever # the problem is (missing libraries, usually). Hey, do whatever you need to # do, Capp’n. -cd ruby && autoconf +autoconf ./configure --enable-shared --disable-install-doc make -j`nproc` && make install cd .. @@ -285,7 +293,7 @@ cd .. 5. Build mkxp-z: ```sh -git clone --recursive https://github.com/inori-z/mkxp-z +git clone https://github.com/inori-z/mkxp-z cd mkxp-z # Ruby 1.8 doesn’t support pkg-config (Might add it in, since this @@ -308,7 +316,7 @@ You'll find your stuff under your MSYS home directory. You can also type `explor 2. Get most of your dependencies from Homebrew: ```sh -brew install meson cmake automake autoconf sdl2 sdl2_{image,ttf} \ +brew install meson cmake automake autoconf sdl2 sdl2_{image,ttf} objfw \ boost pixman physfs libsigc++ libvorbis fluidsynth pkgconfig libtool ``` @@ -322,19 +330,20 @@ git clone https://github.com/inori-z/ruby --single-branch --branch ruby_1_8_7 cd SDL_Sound && ./bootstrap ./configure make install -j`nproc` -cd .. + +cd ../ruby # when you install ruby, some extensions might not want to build. # You probably don’t particularly need any, so you can just delete # any problematic ones if you like: -rm -rf ruby/ext/tk +rm -rf ext/tk # and try building again afterwards. Or you can try to fix whatever # the problem is (missing libraries, usually). Hey, do whatever you # need to do, Capp’n. -cd ruby && autoconf +autoconf # We're putting our build of ruby in its own prefix. macOS already # includes Ruby (at least until 10.16 or so), and you really do @@ -348,21 +357,21 @@ cd .. 4. Build mkxp-z: ```sh -git clone --recursive https://github.com/inori-z/mkxp-z +git clone https://github.com/inori-z/mkxp-z cd mkxp-z # Ruby 1.8 doesn’t support pkg-config (Might add it in, since this # is a bit annoying) so you have to set include and link paths yourself. # the header folder that Ruby 1.8 creates for macOS includes a version -# number (i.e. `x86_64-darwin18.7.0`), and is going to be located under +# number (i.e. `x86_64-darwin19.0.0`), and is going to be located under # `/usr/local/opt/mkxp-ruby/lib/ruby/1.8`. # You will also need to link to `/usr/local/opt/mkxp-ruby/lib`, and tell # meson where your pkgconfig path is (`/usr/local/lib/pkgconfig`). meson build -Dpkg_config_path=/usr/local/lib/pkgconfig \ --Dcpp_args=-I/usr/local/opt/mkxp-ruby/lib/ruby/1.8/x86_64-darwin18.7.0 \ --Dcpp_link_args=-L/usr/local/opt/mkxp-ruby/lib +-Dcpp_args=-I/usr/local/opt/mkxp-ruby/lib/ruby/1.8/x86_64-darwin19.0.0 \ +-Dobjcpp_link_args=-L/usr/local/opt/mkxp-ruby/lib cd build ninja @@ -371,7 +380,7 @@ ninja Your results will be in `~/src/mkxp-z/build` . You can type `open ~/src/mkxp-z/build` to get there quickly. -## Building on Linux (Ubuntu Disco) +## Building on Linux (Ubuntu Eoan) > I'm assuming that if you're using anything other than Ubuntu, you're probably familiar enough with this sort of thing to not need instructions. In fact, you've probably built this thing already, haven't you? @@ -405,15 +414,20 @@ cd ../.. # Now we can do the other stuff: git clone https://github.com/Ancurio/SDL_Sound +git clone https://github.com/ObjFW/ObjFW git clone https://github.com/inori-z/ruby --single-branch --branch ruby_1_8_7 cd SDL_Sound && ./bootstrap ./configure make -j`nproc` sudo make install -cd .. -cd ruby && autoconf +cd ../ObjFW +./autogen.sh +./configure +make install -j`nproc` + +cd ../ruby && autoconf ./configure --enable-shared --disable-install-doc make -j`nproc` sudo make install @@ -423,7 +437,7 @@ cd .. 4. Build mkxp-z: ```sh -git clone --recursive https://github.com/inori-z/mkxp-z +git clone https://github.com/inori-z/mkxp-z cd mkxp-z # Ruby 1.8 doesn’t support pkg-config (Might add it in, since this diff --git a/assets/meson.build b/assets/meson.build index 06c35e0..754b203 100644 --- a/assets/meson.build +++ b/assets/meson.build @@ -11,9 +11,8 @@ endif embedded_assets_f = files(embedded_assets) count = 0 -processed_assets = [] foreach file : embedded_assets_f - processed_assets += custom_target(embedded_assets[count], + global_sources += custom_target(embedded_assets[count], input: file, output: '@0@.xxd'.format(embedded_assets[count]), command: [ diff --git a/binding/binding-mri.cpp b/binding/binding-mri.cpp index 5313452..982b3c5 100644 --- a/binding/binding-mri.cpp +++ b/binding/binding-mri.cpp @@ -33,11 +33,14 @@ #include "lang-fun.h" #include "boost-hash.h" +extern "C" +{ #include #ifndef OLD_RUBY #include #endif +} #include #include diff --git a/binding/meson.build b/binding/meson.build index 64bcee1..285f68f 100644 --- a/binding/meson.build +++ b/binding/meson.build @@ -1,27 +1,18 @@ ver = get_option('mri_version') -binding_dependencies = [] if ver.version_compare('>1.8') == true - binding_dependencies += dependency('ruby-' + ver) + global_dependencies += dependency('ruby-' + ver) else lib = get_option('ruby_lib') - binding_dependencies += compiler.find_library(lib) - add_project_arguments('-DOLD_RUBY', language: 'cpp') + global_dependencies += compilers['cpp'].find_library(lib) + add_project_arguments('-DOLD_RUBY', language: ['cpp','objc','objcpp']) endif if get_option('no_preload_scripts') == true - add_project_arguments('-DNO_PRELOAD_SCRIPTS', language: 'cpp') + add_project_arguments('-DNO_PRELOAD_SCRIPTS', language: ['cpp','objc','objcpp']) endif -binding_headers = files( - 'binding-util.h', - 'binding-types.h', - 'serializable-binding.h', - 'disposable-binding.h', - 'sceneelement-binding.h', - 'viewportelement-binding.h', - 'flashable-binding.h', -) +global_include_dirs += include_directories('.') binding_source = [files( 'binding-mri.cpp', @@ -49,4 +40,4 @@ if discord == true binding_source += files('discord-binding.cpp') endif -bindings = [binding_headers, binding_source] +global_sources += binding_source \ No newline at end of file diff --git a/cwalk b/cwalk deleted file mode 160000 index fe3b37e..0000000 --- a/cwalk +++ /dev/null @@ -1 +0,0 @@ -Subproject commit fe3b37eb3cbcc0f45fb3f1bed0a40f1cfb234ce4 diff --git a/meson.build b/meson.build index 609bb54..eace241 100644 --- a/meson.build +++ b/meson.build @@ -1,4 +1,4 @@ -project('mkxp-z', 'cpp', 'c', version: '1.1.0', default_options: ['cpp_std=c++11']) +project('mkxp-z', 'cpp', 'objc', 'objcpp', version: '1.2.0', default_options: ['cpp_std=c++11', 'buildtype=release']) minimum_macos_version = get_option('macos_min_version') @@ -6,8 +6,9 @@ minimum_macos_version = get_option('macos_min_version') # it still needs to be cleaned up xxd = find_program('xxd', native: true) +objfw = find_program('objfw-config', native: true) host_system = host_machine.system() -compiler = meson.get_compiler('cpp') +compilers = {'cpp': meson.get_compiler('cpp'), 'objc': meson.get_compiler('objc'), 'objcpp': meson.get_compiler('objcpp')} # ==================== # Ext libs @@ -19,7 +20,7 @@ ext_dependencies = [] discord = false discord_libpath = get_option('discord_sdk_path') if discord_libpath != '' - discordlib = compiler.find_library('discord_game_sdk', required: false, dirs: '@0@/lib/@1@'.format(discord_libpath, host_machine.cpu_family())) + discordlib = compilers['cpp'].find_library('discord_game_sdk', required: false, dirs: '@0@/lib/@1@'.format(discord_libpath, host_machine.cpu_family())) if discordlib.found() == true add_project_arguments(['-I@0@/c'.format(discord_libpath), '-DHAVE_DISCORDSDK'], language: 'cpp') @@ -31,25 +32,41 @@ endif # ==================== # Main source # ==================== +global_sources = [] +global_dependencies = [] +global_include_dirs = [] +global_args = [] +global_link_args = [] + +# Suppress warnings +global_args += ['-Wno-non-virtual-dtor', '-Wno-reorder'] if get_option('workdir_current') - add_project_arguments('-DWORKDIR_CURRENT', language: 'cpp') + global_args += '-DWORKDIR_CURRENT' endif if get_option('independent_appimage') - add_project_arguments('-DINDEPENDENT_APPIMAGE', language: 'cpp') + global_args += '-DINDEPENDENT_APPIMAGE' endif if get_option('use_fakeapi') - add_project_arguments('-DUSE_FAKEAPI', language: 'cpp') + global_args += '-DUSE_FAKEAPI' endif if not get_option('console') - add_project_arguments('-DNO_CONSOLE', language: 'cpp') + global_args += '-DNO_CONSOLE' endif if get_option('mk') - add_project_arguments('-DMARIN', language: 'cpp') + global_args += '-DMARIN' +endif + +global_args += run_command(objfw,'--cppflags').stdout().split() +add_project_arguments(run_command(objfw,'--objcflags').stdout().split(), language:'objc') +add_project_link_arguments(run_command(objfw,'--libs','--ldflags').stdout().split(), language:['objc','objcpp']) + +if compilers['objc'].get_id() == 'clang' + add_project_arguments(run_command(objfw,'--arc').stdout().split(), language: ['objc','objcpp']) endif subdir('src') @@ -57,40 +74,36 @@ subdir('binding') subdir('shader') subdir('assets') -all_sources = [main, bindings, processed_shaders, processed_assets] -include_dirs = [include_directories('src', 'binding')] - -# Use cwalk -all_sources += files('cwalk/src/cwalk.c') -include_dirs += include_directories('cwalk/include') +#all_sources = [main, bindings, processed_shaders, processed_assets] +global_include_dirs += include_directories('src', 'binding') # Disable some warnings -add_project_arguments(['-Wno-reorder', '-Wno-non-virtual-dtor', '-Wno-uninitialized'], language: 'cpp') - - -linker_args = [] +#add_project_arguments(['-Wno-reorder', '-Wno-non-virtual-dtor', '-Wno-uninitialized'], language: 'cpp') if host_system == 'windows' subdir('windows') - all_sources += windows_resources - include_dirs += include_directories('windows') + global_sources += windows_resources + global_include_dirs += include_directories('windows') elif host_system == 'darwin' subdir('macos') - if compiler.get_id() == 'clang' - add_project_arguments('-stdlib=libc++', language: 'cpp') - add_project_arguments('-Wno-undefined-var-template', language: 'cpp') - add_project_arguments('-mmacosx-version-min='+minimum_macos_version, language: 'cpp') - add_project_arguments('-mmacosx-version-min='+minimum_macos_version, language: 'c') - add_project_link_arguments('-mmacosx-version-min='+minimum_macos_version, language: 'cpp') + if compilers['cpp'].get_id() == 'clang' + add_project_arguments('-stdlib=libc++', language: ['cpp','objcpp']) + add_project_arguments('-std=c++11', language: 'objcpp') + global_args += ['-Wno-undefined-var-template', '-mmacosx-version-min='+minimum_macos_version] + global_link_args += '-mmacosx-version-min='+minimum_macos_version endif else subdir('linux') endif executable(meson.project_name(), - sources: all_sources, - dependencies: [main_dependencies, binding_dependencies, ext_dependencies], - include_directories: include_dirs, + sources: global_sources, + dependencies: [global_dependencies, ext_dependencies], + include_directories: global_include_dirs, + link_args: global_link_args, + cpp_args: global_args, + objc_args: global_args, + objcpp_args: global_args, gui_app: (get_option('console') == false), install: (host_system != 'windows') ) diff --git a/shader/meson.build b/shader/meson.build index 06a31eb..8eb0c6d 100644 --- a/shader/meson.build +++ b/shader/meson.build @@ -29,9 +29,8 @@ embedded_shaders = [ embedded_shaders_f = files(embedded_shaders) count = 0 -processed_shaders = [] foreach file : embedded_shaders_f - processed_shaders += custom_target(embedded_shaders[count], + global_sources += custom_target(embedded_shaders[count], input: file, output: '@0@.xxd'.format(embedded_shaders[count]), command: [ diff --git a/src/filesystem.cpp b/src/filesystem.mm similarity index 94% rename from src/filesystem.cpp rename to src/filesystem.mm index 9af92fc..0eccf8d 100644 --- a/src/filesystem.cpp +++ b/src/filesystem.mm @@ -19,35 +19,31 @@ ** along with mkxp. If not, see . */ -#include "filesystem.h" +#import -#include "rgssad.h" -#include "font.h" -#include "util.h" -#include "exception.h" -#include "sharedstate.h" -#include "boost-hash.h" -#include "debugwriter.h" +#import "filesystem.h" -// boost::filesystem::path and std::filesystem::path -// are too troublesome -extern "C"{ -#include "cwalk.h" -} +#import "rgssad.h" +#import "font.h" +#import "util.h" +#import "exception.h" +#import "sharedstate.h" +#import "boost-hash.h" +#import "debugwriter.h" -#include +#import -#include +#import -#include -#include -#include -#include -#include -#include +#import +#import +#import +#import +#import +#import #ifdef __APPLE__ -#include +#import #endif struct SDLRWIoContext @@ -643,6 +639,7 @@ void FileSystem::openRead(OpenHandler &handler, const char *filename) // FIXME: Paths with Windows drive letters don't // hecking work, apparently never did char *filename_nm = normalize(filename, false, false); + Debug() << filename_nm; char buffer[512]; size_t len = strcpySafe(buffer, filename_nm, sizeof(buffer), -1); delete filename_nm; @@ -718,23 +715,28 @@ void FileSystem::openReadRaw(SDL_RWops &ops, // SDL_SaveBMP wants absolute paths char* FileSystem::normalize(const char *pathname, bool preferred, bool absolute) { - char *path_nml = new char[512]; - char *path_abs = 0; -#ifdef __WIN32__ - cwk_path_set_style((preferred) ? CWK_STYLE_WINDOWS : CWK_STYLE_UNIX); -#endif - - if (cwk_path_is_relative(pathname) && absolute) + @autoreleasepool { - path_abs = new char[512]; - char bp[512] = {0}; - getcwd(bp, 512); - cwk_path_join(bp, pathname, path_abs, 512); + char* ret = new char[512]; + id str = [OFMutableString stringWithUTF8String:pathname]; + + if (absolute) + { + OFURL* base = [OFURL fileURLWithPath:[[OFFileManager defaultManager] currentDirectoryPath]]; + OFURL* purl = [OFURL fileURLWithPath:str]; + OFString* path = [[OFURL URLWithString:[purl string] relativeToURL:base] path]; + str = [OFMutableString stringWithString:path]; + } + +#ifdef __WIN32__ + if (preferred) + { + [str replaceOccurrencesOfString:@"/" withString:@"\\"]; + } +#endif + strncpy(ret, [[str stringByStandardizingPath] UTF8String], 512); + return ret; } - - cwk_path_normalize((path_abs) ? path_abs : (char*)pathname, path_nml, 512); - if (path_abs) delete path_abs; - return path_nml; } bool FileSystem::exists(const char *filename) diff --git a/src/meson.build b/src/meson.build index 8fb60e0..fdfd8eb 100644 --- a/src/meson.build +++ b/src/meson.build @@ -12,22 +12,23 @@ boost = dependency('boost', version: '>=1.49', modules: 'program_options') openal = dependency('openal') zlib = dependency('zlib') -main_dependencies = [sigcxx, openal, opengl, boost, zlib, pixman, physfs, vorbisfile, sdl2, sdl2_ttf, sdl2_image, sdl_sound] +global_include_dirs += include_directories('.') +global_dependencies += [sigcxx, openal, opengl, boost, zlib, pixman, physfs, vorbisfile, sdl2, sdl2_ttf, sdl2_image, sdl_sound] if host_system == 'darwin' - main_dependencies += compiler.find_library('iconv') - main_dependencies += dependency('CoreFoundation') + global_dependencies += compilers['cpp'].find_library('iconv') + global_dependencies += dependency('CoreFoundation') if openal.type_name() != 'pkgconfig' add_project_arguments('-DUSE_MAC_OPENAL', language: 'cpp') endif elif host_system == 'windows' - main_dependencies += compiler.find_library('wsock32') + global_dependencies += compiler.find_library('wsock32') endif if get_option('shared_fluid') == true fluidsynth = dependency('fluidsynth') add_project_arguments('-DSHARED_FLUID', language: 'cpp') - main_dependencies += fluidsynth + global_dependencies += fluidsynth endif if get_option('default_framerate') == true @@ -38,75 +39,12 @@ if get_option('cjk_fallback_font') == true add_project_arguments('-DCJK_FALLBACK', language: 'cpp') endif -main_headers = files( - 'quadarray.h', - 'audio.h', - 'binding.h', - 'bitmap.h', - 'disposable.h', - 'etc.h', - 'etc-internal.h', - 'eventthread.h', - 'flashable.h', - 'font.h', - 'input.h', - 'iniconfig.h', - 'plane.h', - 'scene.h', - 'sprite.h', - 'table.h', - 'texpool.h', - 'tilequad.h', - 'transform.h', - 'viewport.h', - 'window.h', - 'serializable.h', - 'shader.h', - 'glstate.h', - 'quad.h', - 'tilemap.h', - 'tilemap-common.h', - 'graphics.h', - 'gl-debug.h', - 'global-ibo.h', - 'exception.h', - 'filesystem.h', - 'serial-util.h', - 'intrulist.h', - 'binding.h', - 'gl-util.h', - 'util.h', - 'config.h', - 'settingsmenu.h', - 'keybindings.h', - 'tileatlas.h', - 'sharedstate.h', - 'al-util.h', - 'boost-hash.h', - 'debugwriter.h', - 'gl-fun.h', - 'gl-meta.h', - 'vertex.h', - 'soundemitter.h', - 'aldatasource.h', - 'alstream.h', - 'audiostream.h', - 'rgssad.h', - 'windowvx.h', - 'tilemapvx.h', - 'tileatlasvx.h', - 'sharedmidistate.h', - 'fluid-fun.h', - 'sdl-util.h', - 'lang-fun.h' -) - main_source = files( 'main.cpp', 'audio.cpp', 'bitmap.cpp', 'eventthread.cpp', - 'filesystem.cpp', + 'filesystem.mm', 'font.cpp', 'input.cpp', 'iniconfig.cpp', @@ -148,12 +86,12 @@ main_source = files( 'lang-fun.cpp' ) -main = [main_source, main_headers] - if get_option('use_fakeapi') == true - main += files('fake-api.cpp', 'fake-api.h') + main_source += files('fake-api.cpp') endif if discord == true - main += files('discordstate.cpp', 'discordstate.h') + main_source += files('discordstate.cpp') endif + +global_sources += main_source \ No newline at end of file