Begin using Objective-C (ObjFW), remove cwalk

This commit is contained in:
Inori 2019-12-14 13:31:48 -05:00
parent b1fd0c8616
commit c863267965
11 changed files with 134 additions and 179 deletions

1
.gitignore vendored
View file

@ -14,6 +14,7 @@ xxd+
# VS Code
/.vscode
*.code-workspace
# Codeblocks
mkxp.layout

4
.gitmodules vendored
View file

@ -1,4 +0,0 @@
[submodule "cwalk"]
path = cwalk
url = https://github.com/likle/cwalk
branch = stable

View file

@ -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

View file

@ -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: [

View file

@ -33,11 +33,14 @@
#include "lang-fun.h"
#include "boost-hash.h"
extern "C"
{
#include <ruby.h>
#ifndef OLD_RUBY
#include <ruby/encoding.h>
#endif
}
#include <assert.h>
#include <string>

View file

@ -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

1
cwalk

@ -1 +0,0 @@
Subproject commit fe3b37eb3cbcc0f45fb3f1bed0a40f1cfb234ce4

View file

@ -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')
)

View file

@ -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: [

View file

@ -19,35 +19,31 @@
** along with mkxp. If not, see <http://www.gnu.org/licenses/>.
*/
#include "filesystem.h"
#import <ObjFW/ObjFW.h>
#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 <physfs.h>
#import <physfs.h>
#include <SDL_sound.h>
#import <SDL_sound.h>
#include <unistd.h>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <vector>
#include <stack>
#import <unistd.h>
#import <stdio.h>
#import <string.h>
#import <algorithm>
#import <vector>
#import <stack>
#ifdef __APPLE__
#include <iconv.h>
#import <iconv.h>
#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];
}
cwk_path_normalize((path_abs) ? path_abs : (char*)pathname, path_nml, 512);
if (path_abs) delete path_abs;
return path_nml;
#ifdef __WIN32__
if (preferred)
{
[str replaceOccurrencesOfString:@"/" withString:@"\\"];
}
#endif
strncpy(ret, [[str stringByStandardizingPath] UTF8String], 512);
return ret;
}
}
bool FileSystem::exists(const char *filename)

View file

@ -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