ruby2d-rpeck-windows 0.11.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/assets/README.md +22 -0
- data/assets/Rakefile +85 -0
- data/assets/app.icns +0 -0
- data/assets/include/SDL2/SDL.h +138 -0
- data/assets/include/SDL2/SDL_assert.h +293 -0
- data/assets/include/SDL2/SDL_atomic.h +295 -0
- data/assets/include/SDL2/SDL_audio.h +859 -0
- data/assets/include/SDL2/SDL_bits.h +121 -0
- data/assets/include/SDL2/SDL_blendmode.h +123 -0
- data/assets/include/SDL2/SDL_clipboard.h +71 -0
- data/assets/include/SDL2/SDL_config.h +55 -0
- data/assets/include/SDL2/SDL_config_android.h +182 -0
- data/assets/include/SDL2/SDL_config_iphoneos.h +207 -0
- data/assets/include/SDL2/SDL_config_macosx.h +266 -0
- data/assets/include/SDL2/SDL_config_minimal.h +85 -0
- data/assets/include/SDL2/SDL_config_os2.h +188 -0
- data/assets/include/SDL2/SDL_config_pandora.h +135 -0
- data/assets/include/SDL2/SDL_config_psp.h +165 -0
- data/assets/include/SDL2/SDL_config_windows.h +288 -0
- data/assets/include/SDL2/SDL_config_winrt.h +243 -0
- data/assets/include/SDL2/SDL_config_wiz.h +149 -0
- data/assets/include/SDL2/SDL_copying.h +20 -0
- data/assets/include/SDL2/SDL_cpuinfo.h +299 -0
- data/assets/include/SDL2/SDL_egl.h +1676 -0
- data/assets/include/SDL2/SDL_endian.h +263 -0
- data/assets/include/SDL2/SDL_error.h +112 -0
- data/assets/include/SDL2/SDL_events.h +827 -0
- data/assets/include/SDL2/SDL_filesystem.h +136 -0
- data/assets/include/SDL2/SDL_gamecontroller.h +541 -0
- data/assets/include/SDL2/SDL_gesture.h +87 -0
- data/assets/include/SDL2/SDL_haptic.h +1247 -0
- data/assets/include/SDL2/SDL_hints.h +1578 -0
- data/assets/include/SDL2/SDL_image.h +161 -0
- data/assets/include/SDL2/SDL_joystick.h +499 -0
- data/assets/include/SDL2/SDL_keyboard.h +217 -0
- data/assets/include/SDL2/SDL_keycode.h +351 -0
- data/assets/include/SDL2/SDL_loadso.h +81 -0
- data/assets/include/SDL2/SDL_locale.h +101 -0
- data/assets/include/SDL2/SDL_log.h +211 -0
- data/assets/include/SDL2/SDL_main.h +180 -0
- data/assets/include/SDL2/SDL_messagebox.h +146 -0
- data/assets/include/SDL2/SDL_metal.h +117 -0
- data/assets/include/SDL2/SDL_misc.h +75 -0
- data/assets/include/SDL2/SDL_mixer.h +651 -0
- data/assets/include/SDL2/SDL_mouse.h +302 -0
- data/assets/include/SDL2/SDL_mutex.h +251 -0
- data/assets/include/SDL2/SDL_name.h +33 -0
- data/assets/include/SDL2/SDL_opengl.h +2183 -0
- data/assets/include/SDL2/SDL_opengl_glext.h +11180 -0
- data/assets/include/SDL2/SDL_opengles.h +39 -0
- data/assets/include/SDL2/SDL_opengles2.h +52 -0
- data/assets/include/SDL2/SDL_opengles2_gl2.h +621 -0
- data/assets/include/SDL2/SDL_opengles2_gl2ext.h +2050 -0
- data/assets/include/SDL2/SDL_opengles2_gl2platform.h +30 -0
- data/assets/include/SDL2/SDL_opengles2_khrplatform.h +282 -0
- data/assets/include/SDL2/SDL_pixels.h +479 -0
- data/assets/include/SDL2/SDL_platform.h +198 -0
- data/assets/include/SDL2/SDL_power.h +75 -0
- data/assets/include/SDL2/SDL_quit.h +58 -0
- data/assets/include/SDL2/SDL_rect.h +174 -0
- data/assets/include/SDL2/SDL_render.h +1158 -0
- data/assets/include/SDL2/SDL_revision.h +2 -0
- data/assets/include/SDL2/SDL_rwops.h +283 -0
- data/assets/include/SDL2/SDL_scancode.h +413 -0
- data/assets/include/SDL2/SDL_sensor.h +267 -0
- data/assets/include/SDL2/SDL_shape.h +144 -0
- data/assets/include/SDL2/SDL_stdinc.h +647 -0
- data/assets/include/SDL2/SDL_surface.h +563 -0
- data/assets/include/SDL2/SDL_system.h +325 -0
- data/assets/include/SDL2/SDL_syswm.h +354 -0
- data/assets/include/SDL2/SDL_test.h +69 -0
- data/assets/include/SDL2/SDL_test_assert.h +105 -0
- data/assets/include/SDL2/SDL_test_common.h +218 -0
- data/assets/include/SDL2/SDL_test_compare.h +69 -0
- data/assets/include/SDL2/SDL_test_crc32.h +124 -0
- data/assets/include/SDL2/SDL_test_font.h +81 -0
- data/assets/include/SDL2/SDL_test_fuzzer.h +384 -0
- data/assets/include/SDL2/SDL_test_harness.h +134 -0
- data/assets/include/SDL2/SDL_test_images.h +78 -0
- data/assets/include/SDL2/SDL_test_log.h +67 -0
- data/assets/include/SDL2/SDL_test_md5.h +129 -0
- data/assets/include/SDL2/SDL_test_memory.h +63 -0
- data/assets/include/SDL2/SDL_test_random.h +115 -0
- data/assets/include/SDL2/SDL_thread.h +366 -0
- data/assets/include/SDL2/SDL_timer.h +115 -0
- data/assets/include/SDL2/SDL_touch.h +102 -0
- data/assets/include/SDL2/SDL_ttf.h +294 -0
- data/assets/include/SDL2/SDL_types.h +29 -0
- data/assets/include/SDL2/SDL_version.h +162 -0
- data/assets/include/SDL2/SDL_video.h +1282 -0
- data/assets/include/SDL2/SDL_vulkan.h +276 -0
- data/assets/include/SDL2/begin_code.h +166 -0
- data/assets/include/SDL2/close_code.h +40 -0
- data/assets/include/glew.h +23686 -0
- data/assets/ios/Assets.xcassets/AppIcon.appiconset/Contents.json +98 -0
- data/assets/ios/Assets.xcassets/Contents.json +6 -0
- data/assets/ios/Base.lproj/LaunchScreen.storyboard +27 -0
- data/assets/ios/Info.plist +43 -0
- data/assets/ios/MRuby.framework/Headers/mrbconf.h +143 -0
- data/assets/ios/MRuby.framework/Headers/mruby/array.h +280 -0
- data/assets/ios/MRuby.framework/Headers/mruby/boxing_nan.h +102 -0
- data/assets/ios/MRuby.framework/Headers/mruby/boxing_no.h +56 -0
- data/assets/ios/MRuby.framework/Headers/mruby/boxing_word.h +144 -0
- data/assets/ios/MRuby.framework/Headers/mruby/class.h +97 -0
- data/assets/ios/MRuby.framework/Headers/mruby/common.h +77 -0
- data/assets/ios/MRuby.framework/Headers/mruby/compile.h +195 -0
- data/assets/ios/MRuby.framework/Headers/mruby/data.h +75 -0
- data/assets/ios/MRuby.framework/Headers/mruby/debug.h +67 -0
- data/assets/ios/MRuby.framework/Headers/mruby/dump.h +196 -0
- data/assets/ios/MRuby.framework/Headers/mruby/error.h +75 -0
- data/assets/ios/MRuby.framework/Headers/mruby/gc.h +91 -0
- data/assets/ios/MRuby.framework/Headers/mruby/hash.h +215 -0
- data/assets/ios/MRuby.framework/Headers/mruby/irep.h +75 -0
- data/assets/ios/MRuby.framework/Headers/mruby/istruct.h +47 -0
- data/assets/ios/MRuby.framework/Headers/mruby/khash.h +274 -0
- data/assets/ios/MRuby.framework/Headers/mruby/numeric.h +161 -0
- data/assets/ios/MRuby.framework/Headers/mruby/object.h +44 -0
- data/assets/ios/MRuby.framework/Headers/mruby/opcode.h +69 -0
- data/assets/ios/MRuby.framework/Headers/mruby/ops.h +117 -0
- data/assets/ios/MRuby.framework/Headers/mruby/proc.h +131 -0
- data/assets/ios/MRuby.framework/Headers/mruby/range.h +49 -0
- data/assets/ios/MRuby.framework/Headers/mruby/re.h +16 -0
- data/assets/ios/MRuby.framework/Headers/mruby/string.h +444 -0
- data/assets/ios/MRuby.framework/Headers/mruby/throw.h +55 -0
- data/assets/ios/MRuby.framework/Headers/mruby/value.h +309 -0
- data/assets/ios/MRuby.framework/Headers/mruby/variable.h +136 -0
- data/assets/ios/MRuby.framework/Headers/mruby/version.h +110 -0
- data/assets/ios/MRuby.framework/Headers/mruby.h +1282 -0
- data/assets/ios/MRuby.framework/Info.plist +20 -0
- data/assets/ios/MRuby.framework/MRuby +0 -0
- data/assets/ios/MyApp.xcodeproj/project.pbxproj +368 -0
- data/assets/ios/MyApp.xcodeproj/project.xcworkspace/contents.xcworkspacedata +7 -0
- data/assets/ios/MyApp.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +8 -0
- data/assets/ios/MyApp.xcodeproj/project.xcworkspace/xcshareddata/MyApp.xcscmblueprint +30 -0
- data/assets/ios/main.c +1 -0
- data/assets/macos/lib/libFLAC.a +0 -0
- data/assets/macos/lib/libSDL2.a +0 -0
- data/assets/macos/lib/libSDL2_image.a +0 -0
- data/assets/macos/lib/libSDL2_mixer.a +0 -0
- data/assets/macos/lib/libSDL2_ttf.a +0 -0
- data/assets/macos/lib/libfreetype.a +0 -0
- data/assets/macos/lib/libjpeg.a +0 -0
- data/assets/macos/lib/libmodplug.a +0 -0
- data/assets/macos/lib/libmpg123.a +0 -0
- data/assets/macos/lib/libogg.a +0 -0
- data/assets/macos/lib/libpng16.a +0 -0
- data/assets/macos/lib/libtiff.a +0 -0
- data/assets/macos/lib/libvorbis.a +0 -0
- data/assets/macos/lib/libvorbisfile.a +0 -0
- data/assets/macos/lib/libwebp.a +0 -0
- data/assets/mingw/bin/SDL2.dll +0 -0
- data/assets/mingw/bin/SDL2_image.dll +0 -0
- data/assets/mingw/bin/SDL2_mixer.dll +0 -0
- data/assets/mingw/bin/SDL2_ttf.dll +0 -0
- data/assets/mingw/bin/glew32.dll +0 -0
- data/assets/mingw/bin/libFLAC-8.dll +0 -0
- data/assets/mingw/bin/libfreetype-6.dll +0 -0
- data/assets/mingw/bin/libjpeg-9.dll +0 -0
- data/assets/mingw/bin/libmodplug-1.dll +0 -0
- data/assets/mingw/bin/libmpg123-0.dll +0 -0
- data/assets/mingw/bin/libogg-0.dll +0 -0
- data/assets/mingw/bin/libopus-0.dll +0 -0
- data/assets/mingw/bin/libopusfile-0.dll +0 -0
- data/assets/mingw/bin/libpng16-16.dll +0 -0
- data/assets/mingw/bin/libtiff-5.dll +0 -0
- data/assets/mingw/bin/libvorbis-0.dll +0 -0
- data/assets/mingw/bin/libvorbisfile-3.dll +0 -0
- data/assets/mingw/bin/libwebp-7.dll +0 -0
- data/assets/mingw/bin/libwinpthread-1.dll +0 -0
- data/assets/mingw/bin/zlib1.dll +0 -0
- data/assets/mingw/lib/libSDL2.a +0 -0
- data/assets/mingw/lib/libSDL2.dll.a +0 -0
- data/assets/mingw/lib/libSDL2_image.a +0 -0
- data/assets/mingw/lib/libSDL2_image.dll.a +0 -0
- data/assets/mingw/lib/libSDL2_mixer.a +0 -0
- data/assets/mingw/lib/libSDL2_mixer.dll.a +0 -0
- data/assets/mingw/lib/libSDL2_test.a +0 -0
- data/assets/mingw/lib/libSDL2_ttf.a +0 -0
- data/assets/mingw/lib/libSDL2_ttf.dll.a +0 -0
- data/assets/mingw/lib/libSDL2main.a +0 -0
- data/assets/mingw/lib/libglew32.a +0 -0
- data/assets/mingw/lib/libglew32.dll.a +0 -0
- data/assets/tvos/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Large.imagestack/Back.imagestacklayer/Content.imageset/Contents.json +16 -0
- data/assets/tvos/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Large.imagestack/Back.imagestacklayer/Contents.json +6 -0
- data/assets/tvos/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Large.imagestack/Contents.json +17 -0
- data/assets/tvos/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Large.imagestack/Front.imagestacklayer/Content.imageset/Contents.json +16 -0
- data/assets/tvos/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Large.imagestack/Front.imagestacklayer/Contents.json +6 -0
- data/assets/tvos/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Large.imagestack/Middle.imagestacklayer/Content.imageset/Contents.json +16 -0
- data/assets/tvos/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Large.imagestack/Middle.imagestacklayer/Contents.json +6 -0
- data/assets/tvos/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Small.imagestack/Back.imagestacklayer/Content.imageset/Contents.json +16 -0
- data/assets/tvos/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Small.imagestack/Back.imagestacklayer/Contents.json +6 -0
- data/assets/tvos/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Small.imagestack/Contents.json +17 -0
- data/assets/tvos/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Small.imagestack/Front.imagestacklayer/Content.imageset/Contents.json +16 -0
- data/assets/tvos/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Small.imagestack/Front.imagestacklayer/Contents.json +6 -0
- data/assets/tvos/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Small.imagestack/Middle.imagestacklayer/Content.imageset/Contents.json +16 -0
- data/assets/tvos/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Small.imagestack/Middle.imagestacklayer/Contents.json +6 -0
- data/assets/tvos/Assets.xcassets/App Icon & Top Shelf Image.brandassets/Contents.json +32 -0
- data/assets/tvos/Assets.xcassets/App Icon & Top Shelf Image.brandassets/Top Shelf Image Wide.imageset/Contents.json +16 -0
- data/assets/tvos/Assets.xcassets/App Icon & Top Shelf Image.brandassets/Top Shelf Image.imageset/Contents.json +16 -0
- data/assets/tvos/Assets.xcassets/Contents.json +6 -0
- data/assets/tvos/Assets.xcassets/LaunchImage.launchimage/Contents.json +22 -0
- data/assets/tvos/Info.plist +30 -0
- data/assets/tvos/MRuby.framework/Headers/mrbconf.h +143 -0
- data/assets/tvos/MRuby.framework/Headers/mruby/array.h +280 -0
- data/assets/tvos/MRuby.framework/Headers/mruby/boxing_nan.h +102 -0
- data/assets/tvos/MRuby.framework/Headers/mruby/boxing_no.h +56 -0
- data/assets/tvos/MRuby.framework/Headers/mruby/boxing_word.h +144 -0
- data/assets/tvos/MRuby.framework/Headers/mruby/class.h +97 -0
- data/assets/tvos/MRuby.framework/Headers/mruby/common.h +77 -0
- data/assets/tvos/MRuby.framework/Headers/mruby/compile.h +195 -0
- data/assets/tvos/MRuby.framework/Headers/mruby/data.h +75 -0
- data/assets/tvos/MRuby.framework/Headers/mruby/debug.h +67 -0
- data/assets/tvos/MRuby.framework/Headers/mruby/dump.h +196 -0
- data/assets/tvos/MRuby.framework/Headers/mruby/error.h +75 -0
- data/assets/tvos/MRuby.framework/Headers/mruby/gc.h +91 -0
- data/assets/tvos/MRuby.framework/Headers/mruby/hash.h +215 -0
- data/assets/tvos/MRuby.framework/Headers/mruby/irep.h +75 -0
- data/assets/tvos/MRuby.framework/Headers/mruby/istruct.h +47 -0
- data/assets/tvos/MRuby.framework/Headers/mruby/khash.h +274 -0
- data/assets/tvos/MRuby.framework/Headers/mruby/numeric.h +161 -0
- data/assets/tvos/MRuby.framework/Headers/mruby/object.h +44 -0
- data/assets/tvos/MRuby.framework/Headers/mruby/opcode.h +69 -0
- data/assets/tvos/MRuby.framework/Headers/mruby/ops.h +117 -0
- data/assets/tvos/MRuby.framework/Headers/mruby/proc.h +131 -0
- data/assets/tvos/MRuby.framework/Headers/mruby/range.h +49 -0
- data/assets/tvos/MRuby.framework/Headers/mruby/re.h +16 -0
- data/assets/tvos/MRuby.framework/Headers/mruby/string.h +444 -0
- data/assets/tvos/MRuby.framework/Headers/mruby/throw.h +55 -0
- data/assets/tvos/MRuby.framework/Headers/mruby/value.h +309 -0
- data/assets/tvos/MRuby.framework/Headers/mruby/variable.h +136 -0
- data/assets/tvos/MRuby.framework/Headers/mruby/version.h +110 -0
- data/assets/tvos/MRuby.framework/Headers/mruby.h +1282 -0
- data/assets/tvos/MRuby.framework/Info.plist +20 -0
- data/assets/tvos/MRuby.framework/MRuby +0 -0
- data/assets/tvos/MyApp.xcodeproj/project.pbxproj +350 -0
- data/assets/tvos/MyApp.xcodeproj/project.xcworkspace/contents.xcworkspacedata +7 -0
- data/assets/tvos/MyApp.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +8 -0
- data/assets/tvos/MyApp.xcodeproj/project.xcworkspace/xcshareddata/MyApp.xcscmblueprint +30 -0
- data/assets/tvos/main.c +1 -0
- data/bin/ruby2d +142 -0
- data/ext/ruby2d/common.c +185 -0
- data/ext/ruby2d/controllers.c +110 -0
- data/ext/ruby2d/extconf.rb +147 -0
- data/ext/ruby2d/font.c +35 -0
- data/ext/ruby2d/gl.c +398 -0
- data/ext/ruby2d/gl2.c +86 -0
- data/ext/ruby2d/gl3.c +305 -0
- data/ext/ruby2d/gles.c +249 -0
- data/ext/ruby2d/image.c +58 -0
- data/ext/ruby2d/input.c +48 -0
- data/ext/ruby2d/music.c +127 -0
- data/ext/ruby2d/ruby2d.c +1374 -0
- data/ext/ruby2d/ruby2d.h +656 -0
- data/ext/ruby2d/shapes.c +154 -0
- data/ext/ruby2d/sound.c +118 -0
- data/ext/ruby2d/text.c +22 -0
- data/ext/ruby2d/window.c +414 -0
- data/lib/ruby2d/circle.rb +43 -0
- data/lib/ruby2d/cli/build.rb +237 -0
- data/lib/ruby2d/cli/colorize.rb +10 -0
- data/lib/ruby2d/cli/console.rb +65 -0
- data/lib/ruby2d/cli/enable_console.rb +5 -0
- data/lib/ruby2d/cli/launch.rb +50 -0
- data/lib/ruby2d/color.rb +136 -0
- data/lib/ruby2d/dsl.rb +46 -0
- data/lib/ruby2d/entity.rb +17 -0
- data/lib/ruby2d/exceptions.rb +6 -0
- data/lib/ruby2d/font.rb +96 -0
- data/lib/ruby2d/image.rb +58 -0
- data/lib/ruby2d/line.rb +89 -0
- data/lib/ruby2d/music.rb +67 -0
- data/lib/ruby2d/pixel.rb +17 -0
- data/lib/ruby2d/quad.rb +96 -0
- data/lib/ruby2d/rectangle.rb +65 -0
- data/lib/ruby2d/renderable.rb +40 -0
- data/lib/ruby2d/ruby2d.so +0 -0
- data/lib/ruby2d/sound.rb +55 -0
- data/lib/ruby2d/sprite.rb +232 -0
- data/lib/ruby2d/square.rb +37 -0
- data/lib/ruby2d/text.rb +76 -0
- data/lib/ruby2d/texture.rb +28 -0
- data/lib/ruby2d/tileset.rb +87 -0
- data/lib/ruby2d/triangle.rb +82 -0
- data/lib/ruby2d/version.rb +5 -0
- data/lib/ruby2d/vertices.rb +84 -0
- data/lib/ruby2d/window.rb +673 -0
- data/lib/ruby2d.rb +69 -0
- metadata +346 -0
data/ext/ruby2d/ruby2d.c
ADDED
@@ -0,0 +1,1374 @@
|
|
1
|
+
// Native C extension for Ruby and MRuby
|
2
|
+
|
3
|
+
// Ruby 2D includes
|
4
|
+
#if RUBY2D_IOS_TVOS
|
5
|
+
#else
|
6
|
+
#include <ruby2d.h>
|
7
|
+
#endif
|
8
|
+
|
9
|
+
// Ruby includes
|
10
|
+
#if MRUBY
|
11
|
+
#include <mruby.h>
|
12
|
+
#include <mruby/array.h>
|
13
|
+
#include <mruby/string.h>
|
14
|
+
#include <mruby/variable.h>
|
15
|
+
#include <mruby/numeric.h>
|
16
|
+
#include <mruby/data.h>
|
17
|
+
#include <mruby/irep.h>
|
18
|
+
#else
|
19
|
+
#include <ruby.h>
|
20
|
+
#endif
|
21
|
+
|
22
|
+
// Define Ruby type conversions in MRuby
|
23
|
+
#if MRUBY
|
24
|
+
// C to MRuby types
|
25
|
+
#define INT2FIX(val) (mrb_fixnum_value(val))
|
26
|
+
#define INT2NUM(val) (mrb_fixnum_value((mrb_int)(val)))
|
27
|
+
#define UINT2NUM(val) (INT2NUM((unsigned mrb_int)(val)))
|
28
|
+
#define LL2NUM(val) (INT2NUM(val))
|
29
|
+
#define ULL2NUM(val) (INT2NUM((unsigned __int64)(val)))
|
30
|
+
#define DBL2NUM(val) (mrb_float_value(mrb, (mrb_float)(val)))
|
31
|
+
// MRuby to C types
|
32
|
+
#define TO_PDT(val) ((mrb_type(val) == MRB_TT_FLOAT) ? mrb_float(val) : mrb_int(mrb, (val)))
|
33
|
+
#define FIX2INT(val) (mrb_fixnum(val))
|
34
|
+
#define NUM2INT(val) ((mrb_int)TO_PDT(val))
|
35
|
+
#define NUM2UINT(val) ((unsigned mrb_int)TO_PDT(val))
|
36
|
+
#define NUM2LONG(val) (mrb_int(mrb, (val)))
|
37
|
+
#define NUM2LL(val) ((__int64)(TO_PDT(val)))
|
38
|
+
#define NUM2ULL(val) ((unsigned __int64)(TO_PDT(val)))
|
39
|
+
#define NUM2DBL(val) (mrb_to_flo(mrb, (val)))
|
40
|
+
#define NUM2CHR(val) ((mrb_string_p(val) && (RSTRING_LEN(val)>=1)) ? RSTRING_PTR(val)[0] : (char)(NUM2INT(val) & 0xff))
|
41
|
+
// Memory management
|
42
|
+
#define ALLOC(type) ((type *)mrb_malloc(mrb, sizeof(type)))
|
43
|
+
#define ALLOC_N(type, n) ((type *)mrb_malloc(mrb, sizeof(type) * (n)))
|
44
|
+
#define ALLOCA_N(type, n) ((type *)alloca(sizeof(type) * (n)))
|
45
|
+
#define MEMCMP(p1, p2, type, n) (memcmp((p1), (p2), sizeof(type)*(n)))
|
46
|
+
#endif
|
47
|
+
|
48
|
+
// Define common types and API calls, mapping to both Ruby and MRuby APIs
|
49
|
+
#if MRUBY
|
50
|
+
// MRuby
|
51
|
+
#define R_VAL mrb_value
|
52
|
+
#define R_NIL (mrb_nil_value())
|
53
|
+
#define R_TRUE (mrb_true_value())
|
54
|
+
#define R_FALSE (mrb_false_value())
|
55
|
+
#define R_CLASS struct RClass *
|
56
|
+
#define r_iv_get(self, var) mrb_iv_get(mrb, self, mrb_intern_lit(mrb, var))
|
57
|
+
#define r_iv_set(self, var, val) mrb_iv_set(mrb, self, mrb_intern_lit(mrb, var), val)
|
58
|
+
#define r_funcall(self, method, num_args, ...) mrb_funcall(mrb, self, method, num_args, ##__VA_ARGS__)
|
59
|
+
#define r_str_new(str) mrb_str_new(mrb, str, strlen(str))
|
60
|
+
#define r_test(val) (mrb_test(val) == true)
|
61
|
+
#define r_ary_entry(ary, pos) mrb_ary_entry(ary, pos)
|
62
|
+
#define r_data_wrap_struct(name, data) mrb_obj_value(Data_Wrap_Struct(mrb, mrb->object_class, &name##_data_type, data))
|
63
|
+
#define r_data_get_struct(self, var, mrb_type, rb_type, data) Data_Get_Struct(mrb, r_iv_get(self, var), mrb_type, data)
|
64
|
+
#define r_define_module(name) mrb_define_module(mrb, name)
|
65
|
+
#define r_define_class(module, name) mrb_define_class_under(mrb, module, name, mrb->object_class)
|
66
|
+
#define r_define_method(class, name, function, args) mrb_define_method(mrb, class, name, function, args)
|
67
|
+
#define r_define_class_method(class, name, function, args) mrb_define_class_method(mrb, class, name, function, args)
|
68
|
+
#define r_args_none (MRB_ARGS_NONE())
|
69
|
+
#define r_args_req(n) MRB_ARGS_REQ(n)
|
70
|
+
// Helpers
|
71
|
+
#define r_char_to_sym(str) mrb_symbol_value(mrb_intern_cstr(mrb, str))
|
72
|
+
#else
|
73
|
+
// Ruby
|
74
|
+
#define R_VAL VALUE
|
75
|
+
#define R_NIL Qnil
|
76
|
+
#define R_TRUE Qtrue
|
77
|
+
#define R_FALSE Qfalse
|
78
|
+
#define R_CLASS R_VAL
|
79
|
+
#define r_iv_get(self, var) rb_iv_get(self, var)
|
80
|
+
#define r_iv_set(self, var, val) rb_iv_set(self, var, val)
|
81
|
+
#define r_funcall(self, method, num_args, ...) rb_funcall(self, rb_intern(method), num_args, ##__VA_ARGS__)
|
82
|
+
#define r_str_new(str) rb_str_new2(str)
|
83
|
+
#define r_test(val) (val != Qfalse && val != Qnil)
|
84
|
+
#define r_ary_entry(ary, pos) rb_ary_entry(ary, pos)
|
85
|
+
#define r_data_wrap_struct(name, data) Data_Wrap_Struct(rb_cObject, NULL, (free_##name), data)
|
86
|
+
#define r_data_get_struct(self, var, mrb_type, rb_type, data) Data_Get_Struct(r_iv_get(self, var), rb_type, data)
|
87
|
+
#define r_define_module(name) rb_define_module(name)
|
88
|
+
#define r_define_class(module, name) rb_define_class_under(module, name, rb_cObject)
|
89
|
+
#define r_define_method(class, name, function, args) rb_define_method(class, name, function, args)
|
90
|
+
#define r_define_class_method(class, name, function, args) rb_define_singleton_method(class, name, function, args)
|
91
|
+
#define r_args_none 0
|
92
|
+
#define r_args_req(n) n
|
93
|
+
// Helpers
|
94
|
+
#define r_char_to_sym(str) ID2SYM(rb_intern(str))
|
95
|
+
#endif
|
96
|
+
|
97
|
+
// Create the MRuby context
|
98
|
+
#if MRUBY
|
99
|
+
static mrb_state *mrb;
|
100
|
+
#endif
|
101
|
+
|
102
|
+
// Ruby 2D interpreter window
|
103
|
+
static R_VAL ruby2d_window;
|
104
|
+
|
105
|
+
// Ruby 2D native window
|
106
|
+
static R2D_Window *window;
|
107
|
+
|
108
|
+
// Method signatures and structures for Ruby 2D classes
|
109
|
+
#if MRUBY
|
110
|
+
static void free_sound(mrb_state *mrb, void *p_);
|
111
|
+
static const struct mrb_data_type sound_data_type = {
|
112
|
+
"sound", free_sound
|
113
|
+
};
|
114
|
+
static void free_music(mrb_state *mrb, void *p_);
|
115
|
+
static const struct mrb_data_type music_data_type = {
|
116
|
+
"music", free_music
|
117
|
+
};
|
118
|
+
static void free_surface(mrb_state *mrb, void *p_);
|
119
|
+
static const struct mrb_data_type surface_data_type = {
|
120
|
+
"surface", free_surface
|
121
|
+
};
|
122
|
+
static void free_font(mrb_state *mrb, void *p_);
|
123
|
+
static const struct mrb_data_type font_data_type = {
|
124
|
+
"font", free_font
|
125
|
+
};
|
126
|
+
#else
|
127
|
+
static void free_sound(R2D_Sound *snd);
|
128
|
+
static void free_music(R2D_Music *mus);
|
129
|
+
static void free_font(TTF_Font *font);
|
130
|
+
static void free_surface(SDL_Surface *font);
|
131
|
+
#endif
|
132
|
+
|
133
|
+
/*
|
134
|
+
* Function pointer to free the Ruby 2D native window
|
135
|
+
*/
|
136
|
+
static void free_window() {
|
137
|
+
R2D_FreeWindow(window);
|
138
|
+
}
|
139
|
+
|
140
|
+
|
141
|
+
/*
|
142
|
+
* Normalize controller axis values to 0.0...1.0
|
143
|
+
*/
|
144
|
+
double normalize_controller_axis(int val) {
|
145
|
+
return val > 0 ? val / 32767.0 : val / 32768.0;
|
146
|
+
}
|
147
|
+
|
148
|
+
|
149
|
+
/*
|
150
|
+
* Ruby2D#self.ext_base_path
|
151
|
+
*/
|
152
|
+
#if MRUBY
|
153
|
+
static R_VAL ruby2d_ext_base_path(mrb_state* mrb, R_VAL self) {
|
154
|
+
#else
|
155
|
+
static R_VAL ruby2d_ext_base_path(R_VAL self) {
|
156
|
+
#endif
|
157
|
+
return r_str_new(SDL_GetBasePath());
|
158
|
+
}
|
159
|
+
|
160
|
+
|
161
|
+
/*
|
162
|
+
* Ruby2D::Pixel#self.ext_draw
|
163
|
+
*/
|
164
|
+
#if MRUBY
|
165
|
+
static R_VAL ruby2d_pixel_ext_draw(mrb_state* mrb, R_VAL self) {
|
166
|
+
mrb_value a;
|
167
|
+
mrb_get_args(mrb, "o", &a);
|
168
|
+
#else
|
169
|
+
static R_VAL ruby2d_pixel_ext_draw(R_VAL self, R_VAL a) {
|
170
|
+
#endif
|
171
|
+
// `a` is the array representing the pixel
|
172
|
+
|
173
|
+
R2D_DrawQuad(
|
174
|
+
NUM2DBL(r_ary_entry(a, 0)), // x1
|
175
|
+
NUM2DBL(r_ary_entry(a, 1)), // y1
|
176
|
+
NUM2DBL(r_ary_entry(a, 8)), // color
|
177
|
+
NUM2DBL(r_ary_entry(a, 9)), // color
|
178
|
+
NUM2DBL(r_ary_entry(a, 10)), // color
|
179
|
+
NUM2DBL(r_ary_entry(a, 11)), // color
|
180
|
+
|
181
|
+
NUM2DBL(r_ary_entry(a, 2)), // x2
|
182
|
+
NUM2DBL(r_ary_entry(a, 3)), // y2
|
183
|
+
NUM2DBL(r_ary_entry(a, 8)), // color
|
184
|
+
NUM2DBL(r_ary_entry(a, 9)), // color
|
185
|
+
NUM2DBL(r_ary_entry(a, 10)), // color
|
186
|
+
NUM2DBL(r_ary_entry(a, 11)), // color
|
187
|
+
|
188
|
+
NUM2DBL(r_ary_entry(a, 4)), // x3
|
189
|
+
NUM2DBL(r_ary_entry(a, 5)), // y3
|
190
|
+
NUM2DBL(r_ary_entry(a, 8)), // color
|
191
|
+
NUM2DBL(r_ary_entry(a, 9)), // color
|
192
|
+
NUM2DBL(r_ary_entry(a, 10)), // color
|
193
|
+
NUM2DBL(r_ary_entry(a, 11)), // color
|
194
|
+
|
195
|
+
NUM2DBL(r_ary_entry(a, 6)), // x4
|
196
|
+
NUM2DBL(r_ary_entry(a, 7)), // y4
|
197
|
+
NUM2DBL(r_ary_entry(a, 8)), // color
|
198
|
+
NUM2DBL(r_ary_entry(a, 9)), // color
|
199
|
+
NUM2DBL(r_ary_entry(a, 10)), // color
|
200
|
+
NUM2DBL(r_ary_entry(a, 11)) // color
|
201
|
+
);
|
202
|
+
|
203
|
+
return R_NIL;
|
204
|
+
}
|
205
|
+
|
206
|
+
|
207
|
+
/*
|
208
|
+
* Ruby2D::Triangle#self.ext_draw
|
209
|
+
*/
|
210
|
+
#if MRUBY
|
211
|
+
static R_VAL ruby2d_triangle_ext_draw(mrb_state* mrb, R_VAL self) {
|
212
|
+
mrb_value a;
|
213
|
+
mrb_get_args(mrb, "o", &a);
|
214
|
+
#else
|
215
|
+
static R_VAL ruby2d_triangle_ext_draw(R_VAL self, R_VAL a) {
|
216
|
+
#endif
|
217
|
+
// `a` is the array representing the triangle
|
218
|
+
|
219
|
+
R2D_DrawTriangle(
|
220
|
+
NUM2DBL(r_ary_entry(a, 0)), // x1
|
221
|
+
NUM2DBL(r_ary_entry(a, 1)), // y1
|
222
|
+
NUM2DBL(r_ary_entry(a, 2)), // c1 red
|
223
|
+
NUM2DBL(r_ary_entry(a, 3)), // c1 green
|
224
|
+
NUM2DBL(r_ary_entry(a, 4)), // c1 blue
|
225
|
+
NUM2DBL(r_ary_entry(a, 5)), // c1 alpha
|
226
|
+
|
227
|
+
NUM2DBL(r_ary_entry(a, 6)), // x2
|
228
|
+
NUM2DBL(r_ary_entry(a, 7)), // y2
|
229
|
+
NUM2DBL(r_ary_entry(a, 8)), // c2 red
|
230
|
+
NUM2DBL(r_ary_entry(a, 9)), // c2 green
|
231
|
+
NUM2DBL(r_ary_entry(a, 10)), // c2 blue
|
232
|
+
NUM2DBL(r_ary_entry(a, 11)), // c2 alpha
|
233
|
+
|
234
|
+
NUM2DBL(r_ary_entry(a, 12)), // x3
|
235
|
+
NUM2DBL(r_ary_entry(a, 13)), // y3
|
236
|
+
NUM2DBL(r_ary_entry(a, 14)), // c3 red
|
237
|
+
NUM2DBL(r_ary_entry(a, 15)), // c3 green
|
238
|
+
NUM2DBL(r_ary_entry(a, 16)), // c3 blue
|
239
|
+
NUM2DBL(r_ary_entry(a, 17)) // c3 alpha
|
240
|
+
);
|
241
|
+
|
242
|
+
return R_NIL;
|
243
|
+
}
|
244
|
+
|
245
|
+
|
246
|
+
/*
|
247
|
+
* Ruby2D::Quad#self.ext_draw
|
248
|
+
*/
|
249
|
+
#if MRUBY
|
250
|
+
static R_VAL ruby2d_quad_ext_draw(mrb_state* mrb, R_VAL self) {
|
251
|
+
mrb_value a;
|
252
|
+
mrb_get_args(mrb, "o", &a);
|
253
|
+
#else
|
254
|
+
static R_VAL ruby2d_quad_ext_draw(R_VAL self, R_VAL a) {
|
255
|
+
#endif
|
256
|
+
// `a` is the array representing the quad
|
257
|
+
|
258
|
+
R2D_DrawQuad(
|
259
|
+
NUM2DBL(r_ary_entry(a, 0)), // x1
|
260
|
+
NUM2DBL(r_ary_entry(a, 1)), // y1
|
261
|
+
NUM2DBL(r_ary_entry(a, 2)), // c1 red
|
262
|
+
NUM2DBL(r_ary_entry(a, 3)), // c1 green
|
263
|
+
NUM2DBL(r_ary_entry(a, 4)), // c1 blue
|
264
|
+
NUM2DBL(r_ary_entry(a, 5)), // c1 alpha
|
265
|
+
|
266
|
+
NUM2DBL(r_ary_entry(a, 6)), // x2
|
267
|
+
NUM2DBL(r_ary_entry(a, 7)), // y2
|
268
|
+
NUM2DBL(r_ary_entry(a, 8)), // c2 red
|
269
|
+
NUM2DBL(r_ary_entry(a, 9)), // c2 green
|
270
|
+
NUM2DBL(r_ary_entry(a, 10)), // c2 blue
|
271
|
+
NUM2DBL(r_ary_entry(a, 11)), // c2 alpha
|
272
|
+
|
273
|
+
NUM2DBL(r_ary_entry(a, 12)), // x3
|
274
|
+
NUM2DBL(r_ary_entry(a, 13)), // y3
|
275
|
+
NUM2DBL(r_ary_entry(a, 14)), // c3 red
|
276
|
+
NUM2DBL(r_ary_entry(a, 15)), // c3 green
|
277
|
+
NUM2DBL(r_ary_entry(a, 16)), // c3 blue
|
278
|
+
NUM2DBL(r_ary_entry(a, 17)), // c3 alpha
|
279
|
+
|
280
|
+
NUM2DBL(r_ary_entry(a, 18)), // x4
|
281
|
+
NUM2DBL(r_ary_entry(a, 19)), // y4
|
282
|
+
NUM2DBL(r_ary_entry(a, 20)), // c4 red
|
283
|
+
NUM2DBL(r_ary_entry(a, 21)), // c4 green
|
284
|
+
NUM2DBL(r_ary_entry(a, 22)), // c4 blue
|
285
|
+
NUM2DBL(r_ary_entry(a, 23)) // c4 alpha
|
286
|
+
);
|
287
|
+
|
288
|
+
return R_NIL;
|
289
|
+
}
|
290
|
+
|
291
|
+
|
292
|
+
/*
|
293
|
+
* Ruby2D::Line#self.ext_draw
|
294
|
+
*/
|
295
|
+
#if MRUBY
|
296
|
+
static R_VAL ruby2d_line_ext_draw(mrb_state* mrb, R_VAL self) {
|
297
|
+
mrb_value a;
|
298
|
+
mrb_get_args(mrb, "o", &a);
|
299
|
+
#else
|
300
|
+
static R_VAL ruby2d_line_ext_draw(R_VAL self, R_VAL a) {
|
301
|
+
#endif
|
302
|
+
// `a` is the array representing the line
|
303
|
+
|
304
|
+
R2D_DrawLine(
|
305
|
+
NUM2DBL(r_ary_entry(a, 0)), // x1
|
306
|
+
NUM2DBL(r_ary_entry(a, 1)), // y1
|
307
|
+
NUM2DBL(r_ary_entry(a, 2)), // x2
|
308
|
+
NUM2DBL(r_ary_entry(a, 3)), // y2
|
309
|
+
NUM2DBL(r_ary_entry(a, 4)), // width
|
310
|
+
|
311
|
+
NUM2DBL(r_ary_entry(a, 5)), // c1 red
|
312
|
+
NUM2DBL(r_ary_entry(a, 6)), // c1 green
|
313
|
+
NUM2DBL(r_ary_entry(a, 7)), // c1 blue
|
314
|
+
NUM2DBL(r_ary_entry(a, 8)), // c1 alpha
|
315
|
+
|
316
|
+
NUM2DBL(r_ary_entry(a, 9)), // c2 red
|
317
|
+
NUM2DBL(r_ary_entry(a, 10)), // c2 green
|
318
|
+
NUM2DBL(r_ary_entry(a, 11)), // c2 blue
|
319
|
+
NUM2DBL(r_ary_entry(a, 12)), // c2 alpha
|
320
|
+
|
321
|
+
NUM2DBL(r_ary_entry(a, 13)), // c3 red
|
322
|
+
NUM2DBL(r_ary_entry(a, 14)), // c3 green
|
323
|
+
NUM2DBL(r_ary_entry(a, 15)), // c3 blue
|
324
|
+
NUM2DBL(r_ary_entry(a, 16)), // c3 alpha
|
325
|
+
|
326
|
+
NUM2DBL(r_ary_entry(a, 17)), // c4 red
|
327
|
+
NUM2DBL(r_ary_entry(a, 18)), // c4 green
|
328
|
+
NUM2DBL(r_ary_entry(a, 19)), // c4 blue
|
329
|
+
NUM2DBL(r_ary_entry(a, 20)) // c4 alpha
|
330
|
+
);
|
331
|
+
|
332
|
+
return R_NIL;
|
333
|
+
}
|
334
|
+
|
335
|
+
|
336
|
+
/*
|
337
|
+
* Ruby2D::Circle#self.ext_draw
|
338
|
+
*/
|
339
|
+
#if MRUBY
|
340
|
+
static R_VAL ruby2d_circle_ext_draw(mrb_state* mrb, R_VAL self) {
|
341
|
+
mrb_value a;
|
342
|
+
mrb_get_args(mrb, "o", &a);
|
343
|
+
#else
|
344
|
+
static R_VAL ruby2d_circle_ext_draw(R_VAL self, R_VAL a) {
|
345
|
+
#endif
|
346
|
+
// `a` is the array representing the circle
|
347
|
+
|
348
|
+
R2D_DrawCircle(
|
349
|
+
NUM2DBL(r_ary_entry(a, 0)), // x
|
350
|
+
NUM2DBL(r_ary_entry(a, 1)), // y
|
351
|
+
NUM2DBL(r_ary_entry(a, 2)), // radius
|
352
|
+
NUM2DBL(r_ary_entry(a, 3)), // sectors
|
353
|
+
NUM2DBL(r_ary_entry(a, 4)), // red
|
354
|
+
NUM2DBL(r_ary_entry(a, 5)), // green
|
355
|
+
NUM2DBL(r_ary_entry(a, 6)), // blue
|
356
|
+
NUM2DBL(r_ary_entry(a, 7)) // alpha
|
357
|
+
);
|
358
|
+
|
359
|
+
return R_NIL;
|
360
|
+
}
|
361
|
+
|
362
|
+
|
363
|
+
/*
|
364
|
+
* Ruby2D::Image#ext_load_image
|
365
|
+
* Create an SDL surface from an image path, return the surface, width, and height
|
366
|
+
*/
|
367
|
+
#if MRUBY
|
368
|
+
static R_VAL ruby2d_image_ext_load_image(mrb_state* mrb, R_VAL self) {
|
369
|
+
R2D_Init();
|
370
|
+
|
371
|
+
mrb_value result = mrb_ary_new(mrb);
|
372
|
+
|
373
|
+
mrb_value path;
|
374
|
+
mrb_get_args(mrb, "s", &path);
|
375
|
+
|
376
|
+
SDL_Surface *surface = R2D_CreateImageSurface(RSTRING_PTR(path));
|
377
|
+
R2D_ImageConvertToRGB(surface);
|
378
|
+
|
379
|
+
mrb_ary_push(mrb, result, r_data_wrap_struct(surface, surface));
|
380
|
+
mrb_ary_push(mrb, result, INT2NUM(surface->w));
|
381
|
+
mrb_ary_push(mrb, result, INT2NUM(surface->h));
|
382
|
+
|
383
|
+
return result;
|
384
|
+
}
|
385
|
+
#else
|
386
|
+
static R_VAL ruby2d_image_ext_load_image(R_VAL self, R_VAL path) {
|
387
|
+
R2D_Init();
|
388
|
+
|
389
|
+
VALUE result = rb_ary_new2(3);
|
390
|
+
|
391
|
+
SDL_Surface *surface = R2D_CreateImageSurface(RSTRING_PTR(path));
|
392
|
+
R2D_ImageConvertToRGB(surface);
|
393
|
+
|
394
|
+
rb_ary_push(result, r_data_wrap_struct(surface, surface));
|
395
|
+
rb_ary_push(result, INT2NUM(surface->w));
|
396
|
+
rb_ary_push(result, INT2NUM(surface->h));
|
397
|
+
|
398
|
+
return result;
|
399
|
+
}
|
400
|
+
#endif
|
401
|
+
|
402
|
+
/*
|
403
|
+
* Ruby2D::Text#ext_load_text
|
404
|
+
*/
|
405
|
+
#if MRUBY
|
406
|
+
static R_VAL ruby2d_text_ext_load_text(mrb_state* mrb, R_VAL self) {
|
407
|
+
R2D_Init();
|
408
|
+
|
409
|
+
mrb_value result = mrb_ary_new(mrb);
|
410
|
+
|
411
|
+
mrb_value font, message;
|
412
|
+
mrb_get_args(mrb, "oo", &font, &message);
|
413
|
+
|
414
|
+
TTF_Font *ttf_font;
|
415
|
+
Data_Get_Struct(mrb, font, &font_data_type, ttf_font);
|
416
|
+
//r_data_get_struct(self, font, &font_data_type, TTF_Font, ttf_font);
|
417
|
+
|
418
|
+
// #define r_data_get_struct(self, var, mrb_type, rb_type, data) Data_Get_Struct(mrb, r_iv_get(self, var), mrb_type, data)
|
419
|
+
|
420
|
+
SDL_Surface *surface = R2D_TextCreateSurface(ttf_font, RSTRING_PTR(message));
|
421
|
+
if (!surface) {
|
422
|
+
return result;
|
423
|
+
}
|
424
|
+
|
425
|
+
mrb_ary_push(mrb, result, r_data_wrap_struct(surface, surface));
|
426
|
+
mrb_ary_push(mrb, result, INT2NUM(surface->w));
|
427
|
+
mrb_ary_push(mrb, result, INT2NUM(surface->h));
|
428
|
+
|
429
|
+
return result;
|
430
|
+
}
|
431
|
+
#else
|
432
|
+
static R_VAL ruby2d_text_ext_load_text(R_VAL self, R_VAL font, R_VAL message) {
|
433
|
+
R2D_Init();
|
434
|
+
|
435
|
+
VALUE result = rb_ary_new2(3);
|
436
|
+
|
437
|
+
TTF_Font *ttf_font;
|
438
|
+
Data_Get_Struct(font, TTF_Font, ttf_font);
|
439
|
+
|
440
|
+
SDL_Surface *surface = R2D_TextCreateSurface(ttf_font, RSTRING_PTR(message));
|
441
|
+
if (!surface) {
|
442
|
+
return result;
|
443
|
+
}
|
444
|
+
|
445
|
+
rb_ary_push(result, r_data_wrap_struct(surface, surface));
|
446
|
+
rb_ary_push(result, INT2NUM(surface->w));
|
447
|
+
rb_ary_push(result, INT2NUM(surface->h));
|
448
|
+
|
449
|
+
return result;
|
450
|
+
}
|
451
|
+
#endif
|
452
|
+
|
453
|
+
/*
|
454
|
+
* Ruby2D::Texture#ext_create
|
455
|
+
*/
|
456
|
+
#if MRUBY
|
457
|
+
static R_VAL ruby2d_texture_ext_create(mrb_state* mrb, R_VAL self) {
|
458
|
+
GLuint texture_id = 0;
|
459
|
+
SDL_Surface *surface;
|
460
|
+
|
461
|
+
mrb_value rubySurface, width, height;
|
462
|
+
mrb_get_args(mrb, "ooo", &rubySurface, &width, &height);
|
463
|
+
|
464
|
+
//Data_Get_Struct(mrb, rubySurface, SDL_Surface, surface);
|
465
|
+
Data_Get_Struct(mrb, rubySurface, &surface_data_type, surface);
|
466
|
+
//r_data_get_struct(self, "@data", &surface_data_type, SDL_Surface, surface);
|
467
|
+
|
468
|
+
// Detect image mode
|
469
|
+
GLint format = GL_RGB;
|
470
|
+
if (surface->format->BytesPerPixel == 4) {
|
471
|
+
format = GL_RGBA;
|
472
|
+
}
|
473
|
+
|
474
|
+
R2D_GL_CreateTexture(&texture_id, format,
|
475
|
+
NUM2INT(width), NUM2INT(height),
|
476
|
+
surface->pixels, GL_NEAREST);
|
477
|
+
|
478
|
+
return INT2NUM(texture_id);
|
479
|
+
}
|
480
|
+
#else
|
481
|
+
static R_VAL ruby2d_texture_ext_create(R_VAL self, R_VAL rubySurface, R_VAL width, R_VAL height) {
|
482
|
+
GLuint texture_id = 0;
|
483
|
+
SDL_Surface *surface;
|
484
|
+
Data_Get_Struct(rubySurface, SDL_Surface, surface);
|
485
|
+
|
486
|
+
// Detect image mode
|
487
|
+
GLint format = GL_RGB;
|
488
|
+
if (surface->format->BytesPerPixel == 4) {
|
489
|
+
format = GL_RGBA;
|
490
|
+
}
|
491
|
+
|
492
|
+
R2D_GL_CreateTexture(&texture_id, format,
|
493
|
+
NUM2INT(width), NUM2INT(height),
|
494
|
+
surface->pixels, GL_NEAREST);
|
495
|
+
|
496
|
+
return INT2NUM(texture_id);
|
497
|
+
}
|
498
|
+
#endif
|
499
|
+
|
500
|
+
/*
|
501
|
+
* Ruby2D::Texture#ext_delete
|
502
|
+
*/
|
503
|
+
#if MRUBY
|
504
|
+
static R_VAL ruby2d_texture_ext_delete(mrb_state* mrb, R_VAL self) {
|
505
|
+
mrb_value rubyTexture_id;
|
506
|
+
mrb_get_args(mrb, "o", &rubyTexture_id);
|
507
|
+
#else
|
508
|
+
static R_VAL ruby2d_texture_ext_delete(R_VAL self, R_VAL rubyTexture_id) {
|
509
|
+
#endif
|
510
|
+
GLuint texture_id = NUM2INT(rubyTexture_id);
|
511
|
+
|
512
|
+
R2D_GL_FreeTexture(&texture_id);
|
513
|
+
|
514
|
+
return R_NIL;
|
515
|
+
}
|
516
|
+
|
517
|
+
|
518
|
+
/*
|
519
|
+
* Ruby2D::Sound#ext_init
|
520
|
+
* Initialize sound structure data
|
521
|
+
*/
|
522
|
+
#if MRUBY
|
523
|
+
static R_VAL ruby2d_sound_ext_init(mrb_state* mrb, R_VAL self) {
|
524
|
+
mrb_value path;
|
525
|
+
mrb_get_args(mrb, "o", &path);
|
526
|
+
#else
|
527
|
+
static R_VAL ruby2d_sound_ext_init(R_VAL self, R_VAL path) {
|
528
|
+
#endif
|
529
|
+
R2D_Sound *snd = R2D_CreateSound(RSTRING_PTR(path));
|
530
|
+
if (!snd) return R_FALSE;
|
531
|
+
r_iv_set(self, "@data", r_data_wrap_struct(sound, snd));
|
532
|
+
return R_TRUE;
|
533
|
+
}
|
534
|
+
|
535
|
+
|
536
|
+
/*
|
537
|
+
* Ruby2D::Sound#ext_play
|
538
|
+
*/
|
539
|
+
#if MRUBY
|
540
|
+
static R_VAL ruby2d_sound_ext_play(mrb_state* mrb, R_VAL self) {
|
541
|
+
#else
|
542
|
+
static R_VAL ruby2d_sound_ext_play(R_VAL self) {
|
543
|
+
#endif
|
544
|
+
R2D_Sound *snd;
|
545
|
+
r_data_get_struct(self, "@data", &sound_data_type, R2D_Sound, snd);
|
546
|
+
R2D_PlaySound(snd);
|
547
|
+
return R_NIL;
|
548
|
+
}
|
549
|
+
|
550
|
+
|
551
|
+
/*
|
552
|
+
* Ruby2D::Sound#ext_length
|
553
|
+
*/
|
554
|
+
#if MRUBY
|
555
|
+
static R_VAL ruby2d_sound_ext_length(mrb_state* mrb, R_VAL self) {
|
556
|
+
#else
|
557
|
+
static R_VAL ruby2d_sound_ext_length(R_VAL self) {
|
558
|
+
#endif
|
559
|
+
R2D_Sound *snd;
|
560
|
+
r_data_get_struct(self, "@data", &sound_data_type, R2D_Sound, snd);
|
561
|
+
return INT2NUM(R2D_GetSoundLength(snd));
|
562
|
+
}
|
563
|
+
|
564
|
+
|
565
|
+
/*
|
566
|
+
* Free sound structure attached to Ruby 2D `Sound` class
|
567
|
+
*/
|
568
|
+
#if MRUBY
|
569
|
+
static void free_sound(mrb_state *mrb, void *p_) {
|
570
|
+
R2D_Sound *snd = (R2D_Sound *)p_;
|
571
|
+
#else
|
572
|
+
static void free_sound(R2D_Sound *snd) {
|
573
|
+
#endif
|
574
|
+
R2D_FreeSound(snd);
|
575
|
+
}
|
576
|
+
|
577
|
+
/*
|
578
|
+
* Ruby2D::Sound#ext_get_volume
|
579
|
+
*/
|
580
|
+
#if MRUBY
|
581
|
+
static R_VAL ruby2d_sound_ext_get_volume(mrb_state* mrb, R_VAL self) {
|
582
|
+
#else
|
583
|
+
static R_VAL ruby2d_sound_ext_get_volume(R_VAL self) {
|
584
|
+
#endif
|
585
|
+
R2D_Sound *snd;
|
586
|
+
r_data_get_struct(self, "@data", &sound_data_type, R2D_Sound, snd);
|
587
|
+
return INT2NUM(ceil(Mix_VolumeChunk(snd->data, -1) * (100.0 / MIX_MAX_VOLUME)));
|
588
|
+
}
|
589
|
+
|
590
|
+
/*
|
591
|
+
* Ruby2D::Music#ext_set_volume
|
592
|
+
*/
|
593
|
+
#if MRUBY
|
594
|
+
static R_VAL ruby2d_sound_ext_set_volume(mrb_state* mrb, R_VAL self) {
|
595
|
+
mrb_value volume;
|
596
|
+
mrb_get_args(mrb, "o", &volume);
|
597
|
+
#else
|
598
|
+
static R_VAL ruby2d_sound_ext_set_volume(R_VAL self, R_VAL volume) {
|
599
|
+
#endif
|
600
|
+
R2D_Sound *snd;
|
601
|
+
r_data_get_struct(self, "@data", &sound_data_type, R2D_Sound, snd);
|
602
|
+
Mix_VolumeChunk(snd->data, (NUM2INT(volume) / 100.0) * MIX_MAX_VOLUME);
|
603
|
+
return R_NIL;
|
604
|
+
}
|
605
|
+
|
606
|
+
/*
|
607
|
+
* Ruby2D::Sound#ext_get_mix_volume
|
608
|
+
*/
|
609
|
+
#if MRUBY
|
610
|
+
static R_VAL ruby2d_sound_ext_get_mix_volume(mrb_state* mrb, R_VAL self) {
|
611
|
+
#else
|
612
|
+
static R_VAL ruby2d_sound_ext_get_mix_volume(R_VAL self) {
|
613
|
+
#endif
|
614
|
+
return INT2NUM(ceil(Mix_Volume(-1, -1) * (100.0 / MIX_MAX_VOLUME)));
|
615
|
+
}
|
616
|
+
|
617
|
+
/*
|
618
|
+
* Ruby2D::Music#ext_set_mix_volume
|
619
|
+
*/
|
620
|
+
#if MRUBY
|
621
|
+
static R_VAL ruby2d_sound_ext_set_mix_volume(mrb_state* mrb, R_VAL self) {
|
622
|
+
mrb_value volume;
|
623
|
+
mrb_get_args(mrb, "o", &volume);
|
624
|
+
#else
|
625
|
+
static R_VAL ruby2d_sound_ext_set_mix_volume(R_VAL self, R_VAL volume) {
|
626
|
+
#endif
|
627
|
+
Mix_Volume(-1, (NUM2INT(volume) / 100.0) * MIX_MAX_VOLUME);
|
628
|
+
return R_NIL;
|
629
|
+
}
|
630
|
+
|
631
|
+
/*
|
632
|
+
* Ruby2D::Music#ext_init
|
633
|
+
* Initialize music structure data
|
634
|
+
*/
|
635
|
+
#if MRUBY
|
636
|
+
static R_VAL ruby2d_music_ext_init(mrb_state* mrb, R_VAL self) {
|
637
|
+
mrb_value path;
|
638
|
+
mrb_get_args(mrb, "o", &path);
|
639
|
+
#else
|
640
|
+
static R_VAL ruby2d_music_ext_init(R_VAL self, R_VAL path) {
|
641
|
+
#endif
|
642
|
+
R2D_Music *mus = R2D_CreateMusic(RSTRING_PTR(path));
|
643
|
+
if (!mus) return R_FALSE;
|
644
|
+
r_iv_set(self, "@data", r_data_wrap_struct(music, mus));
|
645
|
+
return R_TRUE;
|
646
|
+
}
|
647
|
+
|
648
|
+
|
649
|
+
/*
|
650
|
+
* Ruby2D::Music#ext_play
|
651
|
+
*/
|
652
|
+
#if MRUBY
|
653
|
+
static R_VAL ruby2d_music_ext_play(mrb_state* mrb, R_VAL self) {
|
654
|
+
#else
|
655
|
+
static R_VAL ruby2d_music_ext_play(R_VAL self) {
|
656
|
+
#endif
|
657
|
+
R2D_Music *mus;
|
658
|
+
r_data_get_struct(self, "@data", &music_data_type, R2D_Music, mus);
|
659
|
+
R2D_PlayMusic(mus, r_test(r_iv_get(self, "@loop")));
|
660
|
+
return R_NIL;
|
661
|
+
}
|
662
|
+
|
663
|
+
|
664
|
+
/*
|
665
|
+
* Ruby2D::Music#ext_pause
|
666
|
+
*/
|
667
|
+
#if MRUBY
|
668
|
+
static R_VAL ruby2d_music_ext_pause(mrb_state* mrb, R_VAL self) {
|
669
|
+
#else
|
670
|
+
static R_VAL ruby2d_music_ext_pause(R_VAL self) {
|
671
|
+
#endif
|
672
|
+
R2D_PauseMusic();
|
673
|
+
return R_NIL;
|
674
|
+
}
|
675
|
+
|
676
|
+
|
677
|
+
/*
|
678
|
+
* Ruby2D::Music#ext_resume
|
679
|
+
*/
|
680
|
+
#if MRUBY
|
681
|
+
static R_VAL ruby2d_music_ext_resume(mrb_state* mrb, R_VAL self) {
|
682
|
+
#else
|
683
|
+
static R_VAL ruby2d_music_ext_resume(R_VAL self) {
|
684
|
+
#endif
|
685
|
+
R2D_ResumeMusic();
|
686
|
+
return R_NIL;
|
687
|
+
}
|
688
|
+
|
689
|
+
|
690
|
+
/*
|
691
|
+
* Ruby2D::Music#ext_stop
|
692
|
+
*/
|
693
|
+
#if MRUBY
|
694
|
+
static R_VAL ruby2d_music_ext_stop(mrb_state* mrb, R_VAL self) {
|
695
|
+
#else
|
696
|
+
static R_VAL ruby2d_music_ext_stop(R_VAL self) {
|
697
|
+
#endif
|
698
|
+
R2D_StopMusic();
|
699
|
+
return R_NIL;
|
700
|
+
}
|
701
|
+
|
702
|
+
|
703
|
+
/*
|
704
|
+
* Ruby2D::Music#ext_get_volume
|
705
|
+
*/
|
706
|
+
#if MRUBY
|
707
|
+
static R_VAL ruby2d_music_ext_get_volume(mrb_state* mrb, R_VAL self) {
|
708
|
+
#else
|
709
|
+
static R_VAL ruby2d_music_ext_get_volume(R_VAL self) {
|
710
|
+
#endif
|
711
|
+
return INT2NUM(R2D_GetMusicVolume());
|
712
|
+
}
|
713
|
+
|
714
|
+
|
715
|
+
/*
|
716
|
+
* Ruby2D::Music#ext_set_volume
|
717
|
+
*/
|
718
|
+
#if MRUBY
|
719
|
+
static R_VAL ruby2d_music_ext_set_volume(mrb_state* mrb, R_VAL self) {
|
720
|
+
mrb_value volume;
|
721
|
+
mrb_get_args(mrb, "o", &volume);
|
722
|
+
#else
|
723
|
+
static R_VAL ruby2d_music_ext_set_volume(R_VAL self, R_VAL volume) {
|
724
|
+
#endif
|
725
|
+
R2D_SetMusicVolume(NUM2INT(volume));
|
726
|
+
return R_NIL;
|
727
|
+
}
|
728
|
+
|
729
|
+
|
730
|
+
/*
|
731
|
+
* Ruby2D::Music#ext_fadeout
|
732
|
+
*/
|
733
|
+
#if MRUBY
|
734
|
+
static R_VAL ruby2d_music_ext_fadeout(mrb_state* mrb, R_VAL self) {
|
735
|
+
mrb_value ms;
|
736
|
+
mrb_get_args(mrb, "o", &ms);
|
737
|
+
#else
|
738
|
+
static R_VAL ruby2d_music_ext_fadeout(R_VAL self, R_VAL ms) {
|
739
|
+
#endif
|
740
|
+
R2D_FadeOutMusic(NUM2INT(ms));
|
741
|
+
return R_NIL;
|
742
|
+
}
|
743
|
+
|
744
|
+
|
745
|
+
/*
|
746
|
+
* Ruby2D::Music#ext_length
|
747
|
+
*/
|
748
|
+
#if MRUBY
|
749
|
+
static R_VAL ruby2d_music_ext_length(mrb_state* mrb, R_VAL self) {
|
750
|
+
#else
|
751
|
+
static R_VAL ruby2d_music_ext_length(R_VAL self) {
|
752
|
+
#endif
|
753
|
+
R2D_Music *ms;
|
754
|
+
r_data_get_struct(self, "@data", &music_data_type, R2D_Music, ms);
|
755
|
+
return INT2NUM(R2D_GetMusicLength(ms));
|
756
|
+
}
|
757
|
+
|
758
|
+
/*
|
759
|
+
* Ruby2D::Font#ext_load
|
760
|
+
*/
|
761
|
+
#if MRUBY
|
762
|
+
static R_VAL ruby2d_font_ext_load(mrb_state* mrb, R_VAL self) {
|
763
|
+
mrb_value path, size, style;
|
764
|
+
mrb_get_args(mrb, "ooo", &path, &size, &style);
|
765
|
+
#else
|
766
|
+
static R_VAL ruby2d_font_ext_load(R_VAL self, R_VAL path, R_VAL size, R_VAL style) {
|
767
|
+
#endif
|
768
|
+
R2D_Init();
|
769
|
+
|
770
|
+
TTF_Font *font = R2D_FontCreateTTFFont(RSTRING_PTR(path), NUM2INT(size), RSTRING_PTR(style));
|
771
|
+
if (!font) {
|
772
|
+
return R_NIL;
|
773
|
+
}
|
774
|
+
|
775
|
+
return r_data_wrap_struct(font, font);
|
776
|
+
}
|
777
|
+
|
778
|
+
|
779
|
+
/*
|
780
|
+
* Ruby2D::Texture#ext_draw
|
781
|
+
*/
|
782
|
+
#if MRUBY
|
783
|
+
static R_VAL ruby2d_texture_ext_draw(mrb_state* mrb, R_VAL self) {
|
784
|
+
mrb_value ruby_coordinates, ruby_texture_coordinates, ruby_color, texture_id;
|
785
|
+
mrb_get_args(mrb, "oooo", &ruby_coordinates, &ruby_texture_coordinates, &ruby_color, &texture_id);
|
786
|
+
#else
|
787
|
+
static R_VAL ruby2d_texture_ext_draw(R_VAL self, R_VAL ruby_coordinates, R_VAL ruby_texture_coordinates, R_VAL ruby_color, R_VAL texture_id) {
|
788
|
+
#endif
|
789
|
+
GLfloat coordinates[8];
|
790
|
+
GLfloat texture_coordinates[8];
|
791
|
+
GLfloat color[4];
|
792
|
+
|
793
|
+
for(int i = 0; i < 8; i++) { coordinates[i] = NUM2DBL(r_ary_entry(ruby_coordinates, i)); }
|
794
|
+
for(int i = 0; i < 8; i++) { texture_coordinates[i] = NUM2DBL(r_ary_entry(ruby_texture_coordinates, i)); }
|
795
|
+
for(int i = 0; i < 4; i++) { color[i] = NUM2DBL(r_ary_entry(ruby_color, i)); }
|
796
|
+
|
797
|
+
R2D_GL_DrawTexture(coordinates, texture_coordinates, color, NUM2INT(texture_id));
|
798
|
+
|
799
|
+
return R_NIL;
|
800
|
+
}
|
801
|
+
|
802
|
+
/*
|
803
|
+
* Free surface structure used within the Ruby 2D `Texture` class
|
804
|
+
*/
|
805
|
+
#if MRUBY
|
806
|
+
static void free_surface(mrb_state *mrb, void *p_) {
|
807
|
+
SDL_Surface *surface = (SDL_Surface *)p_;
|
808
|
+
#else
|
809
|
+
static void free_surface(SDL_Surface *surface) {
|
810
|
+
#endif
|
811
|
+
SDL_FreeSurface(surface);
|
812
|
+
}
|
813
|
+
|
814
|
+
/*
|
815
|
+
* Free font structure stored in the Ruby 2D `Font` class
|
816
|
+
*/
|
817
|
+
#if MRUBY
|
818
|
+
static void free_font(mrb_state *mrb, void *p_) {
|
819
|
+
TTF_Font *font = (TTF_Font *)p_;
|
820
|
+
#else
|
821
|
+
static void free_font(TTF_Font *font) {
|
822
|
+
#endif
|
823
|
+
TTF_CloseFont(font);
|
824
|
+
}
|
825
|
+
|
826
|
+
/*
|
827
|
+
* Free music structure attached to Ruby 2D `Music` class
|
828
|
+
*/
|
829
|
+
#if MRUBY
|
830
|
+
static void free_music(mrb_state *mrb, void *p_) {
|
831
|
+
R2D_Music *mus = (R2D_Music *)p_;
|
832
|
+
#else
|
833
|
+
static void free_music(R2D_Music *mus) {
|
834
|
+
#endif
|
835
|
+
R2D_FreeMusic(mus);
|
836
|
+
}
|
837
|
+
|
838
|
+
/*
|
839
|
+
* Ruby 2D native `on_key` input callback function
|
840
|
+
*/
|
841
|
+
static void on_key(R2D_Event e) {
|
842
|
+
|
843
|
+
R_VAL type;
|
844
|
+
|
845
|
+
switch (e.type) {
|
846
|
+
case R2D_KEY_DOWN:
|
847
|
+
type = r_char_to_sym("down");
|
848
|
+
break;
|
849
|
+
case R2D_KEY_HELD:
|
850
|
+
type = r_char_to_sym("held");
|
851
|
+
break;
|
852
|
+
case R2D_KEY_UP:
|
853
|
+
type = r_char_to_sym("up");
|
854
|
+
break;
|
855
|
+
}
|
856
|
+
|
857
|
+
r_funcall(ruby2d_window, "key_callback", 2, type, r_str_new(e.key));
|
858
|
+
}
|
859
|
+
|
860
|
+
|
861
|
+
/*
|
862
|
+
* Ruby 2D native `on_mouse` input callback function
|
863
|
+
*/
|
864
|
+
void on_mouse(R2D_Event e) {
|
865
|
+
|
866
|
+
R_VAL type = R_NIL; R_VAL button = R_NIL; R_VAL direction = R_NIL;
|
867
|
+
|
868
|
+
switch (e.type) {
|
869
|
+
case R2D_MOUSE_DOWN:
|
870
|
+
// type, button, x, y
|
871
|
+
type = r_char_to_sym("down");
|
872
|
+
break;
|
873
|
+
case R2D_MOUSE_UP:
|
874
|
+
// type, button, x, y
|
875
|
+
type = r_char_to_sym("up");
|
876
|
+
break;
|
877
|
+
case R2D_MOUSE_SCROLL:
|
878
|
+
// type, direction, delta_x, delta_y
|
879
|
+
type = r_char_to_sym("scroll");
|
880
|
+
direction = e.direction == R2D_MOUSE_SCROLL_NORMAL ?
|
881
|
+
r_char_to_sym("normal") : r_char_to_sym("inverted");
|
882
|
+
break;
|
883
|
+
case R2D_MOUSE_MOVE:
|
884
|
+
// type, x, y, delta_x, delta_y
|
885
|
+
type = r_char_to_sym("move");
|
886
|
+
break;
|
887
|
+
}
|
888
|
+
|
889
|
+
if (e.type == R2D_MOUSE_DOWN || e.type == R2D_MOUSE_UP) {
|
890
|
+
switch (e.button) {
|
891
|
+
case R2D_MOUSE_LEFT:
|
892
|
+
button = r_char_to_sym("left");
|
893
|
+
break;
|
894
|
+
case R2D_MOUSE_MIDDLE:
|
895
|
+
button = r_char_to_sym("middle");
|
896
|
+
break;
|
897
|
+
case R2D_MOUSE_RIGHT:
|
898
|
+
button = r_char_to_sym("right");
|
899
|
+
break;
|
900
|
+
case R2D_MOUSE_X1:
|
901
|
+
button = r_char_to_sym("x1");
|
902
|
+
break;
|
903
|
+
case R2D_MOUSE_X2:
|
904
|
+
button = r_char_to_sym("x2");
|
905
|
+
break;
|
906
|
+
}
|
907
|
+
}
|
908
|
+
|
909
|
+
r_funcall(
|
910
|
+
ruby2d_window, "mouse_callback", 7, type, button, direction,
|
911
|
+
INT2NUM(e.x), INT2NUM(e.y), INT2NUM(e.delta_x), INT2NUM(e.delta_y)
|
912
|
+
);
|
913
|
+
}
|
914
|
+
|
915
|
+
|
916
|
+
/*
|
917
|
+
* Ruby 2D native `on_controller` input callback function
|
918
|
+
*/
|
919
|
+
static void on_controller(R2D_Event e) {
|
920
|
+
|
921
|
+
R_VAL type = R_NIL; R_VAL axis = R_NIL; R_VAL button = R_NIL;
|
922
|
+
|
923
|
+
switch (e.type) {
|
924
|
+
case R2D_AXIS:
|
925
|
+
type = r_char_to_sym("axis");
|
926
|
+
switch (e.axis) {
|
927
|
+
case R2D_AXIS_LEFTX:
|
928
|
+
axis = r_char_to_sym("left_x");
|
929
|
+
break;
|
930
|
+
case R2D_AXIS_LEFTY:
|
931
|
+
axis = r_char_to_sym("left_y");
|
932
|
+
break;
|
933
|
+
case R2D_AXIS_RIGHTX:
|
934
|
+
axis = r_char_to_sym("right_x");
|
935
|
+
break;
|
936
|
+
case R2D_AXIS_RIGHTY:
|
937
|
+
axis = r_char_to_sym("right_y");
|
938
|
+
break;
|
939
|
+
case R2D_AXIS_TRIGGERLEFT:
|
940
|
+
axis = r_char_to_sym("trigger_left");
|
941
|
+
break;
|
942
|
+
case R2D_AXIS_TRIGGERRIGHT:
|
943
|
+
axis = r_char_to_sym("trigger_right");
|
944
|
+
break;
|
945
|
+
case R2D_AXIS_INVALID:
|
946
|
+
axis = r_char_to_sym("invalid");
|
947
|
+
break;
|
948
|
+
}
|
949
|
+
break;
|
950
|
+
case R2D_BUTTON_DOWN: case R2D_BUTTON_UP:
|
951
|
+
type = e.type == R2D_BUTTON_DOWN ? r_char_to_sym("button_down") : r_char_to_sym("button_up");
|
952
|
+
switch (e.button) {
|
953
|
+
case R2D_BUTTON_A:
|
954
|
+
button = r_char_to_sym("a");
|
955
|
+
break;
|
956
|
+
case R2D_BUTTON_B:
|
957
|
+
button = r_char_to_sym("b");
|
958
|
+
break;
|
959
|
+
case R2D_BUTTON_X:
|
960
|
+
button = r_char_to_sym("x");
|
961
|
+
break;
|
962
|
+
case R2D_BUTTON_Y:
|
963
|
+
button = r_char_to_sym("y");
|
964
|
+
break;
|
965
|
+
case R2D_BUTTON_BACK:
|
966
|
+
button = r_char_to_sym("back");
|
967
|
+
break;
|
968
|
+
case R2D_BUTTON_GUIDE:
|
969
|
+
button = r_char_to_sym("guide");
|
970
|
+
break;
|
971
|
+
case R2D_BUTTON_START:
|
972
|
+
button = r_char_to_sym("start");
|
973
|
+
break;
|
974
|
+
case R2D_BUTTON_LEFTSTICK:
|
975
|
+
button = r_char_to_sym("left_stick");
|
976
|
+
break;
|
977
|
+
case R2D_BUTTON_RIGHTSTICK:
|
978
|
+
button = r_char_to_sym("right_stick");
|
979
|
+
break;
|
980
|
+
case R2D_BUTTON_LEFTSHOULDER:
|
981
|
+
button = r_char_to_sym("left_shoulder");
|
982
|
+
break;
|
983
|
+
case R2D_BUTTON_RIGHTSHOULDER:
|
984
|
+
button = r_char_to_sym("right_shoulder");
|
985
|
+
break;
|
986
|
+
case R2D_BUTTON_DPAD_UP:
|
987
|
+
button = r_char_to_sym("up");
|
988
|
+
break;
|
989
|
+
case R2D_BUTTON_DPAD_DOWN:
|
990
|
+
button = r_char_to_sym("down");
|
991
|
+
break;
|
992
|
+
case R2D_BUTTON_DPAD_LEFT:
|
993
|
+
button = r_char_to_sym("left");
|
994
|
+
break;
|
995
|
+
case R2D_BUTTON_DPAD_RIGHT:
|
996
|
+
button = r_char_to_sym("right");
|
997
|
+
break;
|
998
|
+
case R2D_BUTTON_INVALID:
|
999
|
+
button = r_char_to_sym("invalid");
|
1000
|
+
break;
|
1001
|
+
}
|
1002
|
+
break;
|
1003
|
+
}
|
1004
|
+
|
1005
|
+
r_funcall(
|
1006
|
+
ruby2d_window, "controller_callback", 5, INT2NUM(e.which),
|
1007
|
+
type, axis, DBL2NUM(normalize_controller_axis(e.value)), button
|
1008
|
+
);
|
1009
|
+
}
|
1010
|
+
|
1011
|
+
|
1012
|
+
/*
|
1013
|
+
* Ruby 2D native `update` callback function
|
1014
|
+
*/
|
1015
|
+
static void update() {
|
1016
|
+
|
1017
|
+
// Set the cursor
|
1018
|
+
r_iv_set(ruby2d_window, "@mouse_x", INT2NUM(window->mouse.x));
|
1019
|
+
r_iv_set(ruby2d_window, "@mouse_y", INT2NUM(window->mouse.y));
|
1020
|
+
|
1021
|
+
// Store frames
|
1022
|
+
r_iv_set(ruby2d_window, "@frames", DBL2NUM(window->frames));
|
1023
|
+
|
1024
|
+
// Store frame rate
|
1025
|
+
r_iv_set(ruby2d_window, "@fps", DBL2NUM(window->fps));
|
1026
|
+
|
1027
|
+
// Call update proc, `window.update`
|
1028
|
+
r_funcall(ruby2d_window, "update_callback", 0);
|
1029
|
+
}
|
1030
|
+
|
1031
|
+
|
1032
|
+
/*
|
1033
|
+
* Ruby 2D native `render` callback function
|
1034
|
+
*/
|
1035
|
+
static void render() {
|
1036
|
+
|
1037
|
+
// Set background color
|
1038
|
+
R_VAL bc = r_iv_get(ruby2d_window, "@background");
|
1039
|
+
window->background.r = NUM2DBL(r_iv_get(bc, "@r"));
|
1040
|
+
window->background.g = NUM2DBL(r_iv_get(bc, "@g"));
|
1041
|
+
window->background.b = NUM2DBL(r_iv_get(bc, "@b"));
|
1042
|
+
window->background.a = NUM2DBL(r_iv_get(bc, "@a"));
|
1043
|
+
|
1044
|
+
// Read window objects
|
1045
|
+
R_VAL objects = r_iv_get(ruby2d_window, "@objects");
|
1046
|
+
int num_objects = NUM2INT(r_funcall(objects, "length", 0));
|
1047
|
+
|
1048
|
+
// Switch on each object type
|
1049
|
+
for (int i = 0; i < num_objects; ++i) {
|
1050
|
+
R_VAL el = r_ary_entry(objects, i);
|
1051
|
+
r_funcall(el, "render", 0); // call the object's `render` function
|
1052
|
+
}
|
1053
|
+
|
1054
|
+
// Call render proc, `window.render`
|
1055
|
+
r_funcall(ruby2d_window, "render_callback", 0);
|
1056
|
+
}
|
1057
|
+
|
1058
|
+
|
1059
|
+
/*
|
1060
|
+
* Ruby2D::Window#ext_diagnostics
|
1061
|
+
*/
|
1062
|
+
#if MRUBY
|
1063
|
+
static R_VAL ruby2d_ext_diagnostics(mrb_state* mrb, R_VAL self) {
|
1064
|
+
mrb_value enable;
|
1065
|
+
mrb_get_args(mrb, "o", &enable);
|
1066
|
+
#else
|
1067
|
+
static R_VAL ruby2d_ext_diagnostics(R_VAL self, R_VAL enable) {
|
1068
|
+
#endif
|
1069
|
+
// Set Ruby 2D native diagnostics
|
1070
|
+
R2D_Diagnostics(r_test(enable));
|
1071
|
+
return R_TRUE;
|
1072
|
+
}
|
1073
|
+
|
1074
|
+
|
1075
|
+
/*
|
1076
|
+
* Ruby2D::Window#ext_get_display_dimensions
|
1077
|
+
*/
|
1078
|
+
#if MRUBY
|
1079
|
+
static R_VAL ruby2d_window_ext_get_display_dimensions(mrb_state* mrb, R_VAL self) {
|
1080
|
+
#else
|
1081
|
+
static R_VAL ruby2d_window_ext_get_display_dimensions(R_VAL self) {
|
1082
|
+
#endif
|
1083
|
+
int w; int h;
|
1084
|
+
R2D_GetDisplayDimensions(&w, &h);
|
1085
|
+
r_iv_set(self, "@display_width" , INT2NUM(w));
|
1086
|
+
r_iv_set(self, "@display_height", INT2NUM(h));
|
1087
|
+
return R_NIL;
|
1088
|
+
}
|
1089
|
+
|
1090
|
+
|
1091
|
+
/*
|
1092
|
+
* Ruby2D::Window#ext_add_controller_mappings
|
1093
|
+
*/
|
1094
|
+
#if MRUBY
|
1095
|
+
static R_VAL ruby2d_window_ext_add_controller_mappings(mrb_state* mrb, R_VAL self) {
|
1096
|
+
mrb_value path;
|
1097
|
+
mrb_get_args(mrb, "o", &path);
|
1098
|
+
#else
|
1099
|
+
static R_VAL ruby2d_window_ext_add_controller_mappings(R_VAL self, R_VAL path) {
|
1100
|
+
#endif
|
1101
|
+
R2D_Log(R2D_INFO, "Adding controller mappings from `%s`", RSTRING_PTR(path));
|
1102
|
+
R2D_AddControllerMappingsFromFile(RSTRING_PTR(path));
|
1103
|
+
return R_NIL;
|
1104
|
+
}
|
1105
|
+
|
1106
|
+
|
1107
|
+
/*
|
1108
|
+
* Ruby2D::Window#ext_show
|
1109
|
+
*/
|
1110
|
+
#if MRUBY
|
1111
|
+
static R_VAL ruby2d_window_ext_show(mrb_state* mrb, R_VAL self) {
|
1112
|
+
#else
|
1113
|
+
static R_VAL ruby2d_window_ext_show(R_VAL self) {
|
1114
|
+
#endif
|
1115
|
+
ruby2d_window = self;
|
1116
|
+
|
1117
|
+
// Add controller mappings from file
|
1118
|
+
r_funcall(self, "add_controller_mappings", 0);
|
1119
|
+
|
1120
|
+
// Get window attributes
|
1121
|
+
char *title = RSTRING_PTR(r_iv_get(self, "@title"));
|
1122
|
+
int width = NUM2INT(r_iv_get(self, "@width"));
|
1123
|
+
int height = NUM2INT(r_iv_get(self, "@height"));
|
1124
|
+
int fps_cap = NUM2INT(r_iv_get(self, "@fps_cap"));
|
1125
|
+
|
1126
|
+
// Get the window icon
|
1127
|
+
char *icon = NULL;
|
1128
|
+
R_VAL iv_icon = r_iv_get(self, "@icon");
|
1129
|
+
if (r_test(iv_icon)) icon = RSTRING_PTR(iv_icon);
|
1130
|
+
|
1131
|
+
// Get window flags
|
1132
|
+
int flags = 0;
|
1133
|
+
if (r_test(r_iv_get(self, "@resizable"))) {
|
1134
|
+
flags = flags | R2D_RESIZABLE;
|
1135
|
+
}
|
1136
|
+
if (r_test(r_iv_get(self, "@borderless"))) {
|
1137
|
+
flags = flags | R2D_BORDERLESS;
|
1138
|
+
}
|
1139
|
+
if (r_test(r_iv_get(self, "@fullscreen"))) {
|
1140
|
+
flags = flags | R2D_FULLSCREEN;
|
1141
|
+
}
|
1142
|
+
if (r_test(r_iv_get(self, "@highdpi"))) {
|
1143
|
+
flags = flags | R2D_HIGHDPI;
|
1144
|
+
}
|
1145
|
+
|
1146
|
+
// Check viewport size and set
|
1147
|
+
|
1148
|
+
R_VAL vp_w = r_iv_get(self, "@viewport_width");
|
1149
|
+
int viewport_width = r_test(vp_w) ? NUM2INT(vp_w) : width;
|
1150
|
+
|
1151
|
+
R_VAL vp_h = r_iv_get(self, "@viewport_height");
|
1152
|
+
int viewport_height = r_test(vp_h) ? NUM2INT(vp_h) : height;
|
1153
|
+
|
1154
|
+
// Create and show window
|
1155
|
+
|
1156
|
+
window = R2D_CreateWindow(
|
1157
|
+
title, width, height, update, render, flags
|
1158
|
+
);
|
1159
|
+
|
1160
|
+
window->viewport.width = viewport_width;
|
1161
|
+
window->viewport.height = viewport_height;
|
1162
|
+
window->fps_cap = fps_cap;
|
1163
|
+
window->icon = icon;
|
1164
|
+
window->on_key = on_key;
|
1165
|
+
window->on_mouse = on_mouse;
|
1166
|
+
window->on_controller = on_controller;
|
1167
|
+
|
1168
|
+
R2D_Show(window);
|
1169
|
+
|
1170
|
+
atexit(free_window);
|
1171
|
+
return R_NIL;
|
1172
|
+
}
|
1173
|
+
|
1174
|
+
/*
|
1175
|
+
* Ruby2D::Window#ext_screenshot
|
1176
|
+
*/
|
1177
|
+
#if MRUBY
|
1178
|
+
static R_VAL ruby2d_ext_screenshot(mrb_state* mrb, R_VAL self) {
|
1179
|
+
mrb_value path;
|
1180
|
+
mrb_get_args(mrb, "o", &path);
|
1181
|
+
#else
|
1182
|
+
static R_VAL ruby2d_ext_screenshot(R_VAL self, R_VAL path) {
|
1183
|
+
#endif
|
1184
|
+
if (window) {
|
1185
|
+
R2D_Screenshot(window, RSTRING_PTR(path));
|
1186
|
+
return path;
|
1187
|
+
} else {
|
1188
|
+
return R_FALSE;
|
1189
|
+
}
|
1190
|
+
}
|
1191
|
+
|
1192
|
+
|
1193
|
+
/*
|
1194
|
+
* Ruby2D::Window#ext_close
|
1195
|
+
*/
|
1196
|
+
static R_VAL ruby2d_window_ext_close() {
|
1197
|
+
R2D_Close(window);
|
1198
|
+
return R_NIL;
|
1199
|
+
}
|
1200
|
+
|
1201
|
+
|
1202
|
+
#if MRUBY
|
1203
|
+
/*
|
1204
|
+
* MRuby entry point
|
1205
|
+
*/
|
1206
|
+
int main() {
|
1207
|
+
// Open the MRuby environment
|
1208
|
+
mrb = mrb_open();
|
1209
|
+
if (!mrb) { /* handle error */ }
|
1210
|
+
|
1211
|
+
// Load the Ruby 2D library
|
1212
|
+
mrb_load_irep(mrb, ruby2d_lib);
|
1213
|
+
|
1214
|
+
#else
|
1215
|
+
/*
|
1216
|
+
* Ruby C extension init
|
1217
|
+
*/
|
1218
|
+
void Init_ruby2d() {
|
1219
|
+
#endif
|
1220
|
+
|
1221
|
+
// Ruby2D
|
1222
|
+
R_CLASS ruby2d_module = r_define_module("Ruby2D");
|
1223
|
+
|
1224
|
+
// Ruby2D#self.ext_base_path
|
1225
|
+
r_define_class_method(ruby2d_module, "ext_base_path", ruby2d_ext_base_path, r_args_none);
|
1226
|
+
|
1227
|
+
// Ruby2D::Pixel
|
1228
|
+
R_CLASS ruby2d_pixel_class = r_define_class(ruby2d_module, "Pixel");
|
1229
|
+
|
1230
|
+
// Ruby2D::Pixel#self.ext_draw
|
1231
|
+
r_define_class_method(ruby2d_pixel_class, "ext_draw", ruby2d_pixel_ext_draw, r_args_req(1));
|
1232
|
+
|
1233
|
+
// Ruby2D::Triangle
|
1234
|
+
R_CLASS ruby2d_triangle_class = r_define_class(ruby2d_module, "Triangle");
|
1235
|
+
|
1236
|
+
// Ruby2D::Triangle#self.ext_draw
|
1237
|
+
r_define_class_method(ruby2d_triangle_class, "ext_draw", ruby2d_triangle_ext_draw, r_args_req(1));
|
1238
|
+
|
1239
|
+
// Ruby2D::Quad
|
1240
|
+
R_CLASS ruby2d_quad_class = r_define_class(ruby2d_module, "Quad");
|
1241
|
+
|
1242
|
+
// Ruby2D::Quad#self.ext_draw
|
1243
|
+
r_define_class_method(ruby2d_quad_class, "ext_draw", ruby2d_quad_ext_draw, r_args_req(1));
|
1244
|
+
|
1245
|
+
// Ruby2D::Line
|
1246
|
+
R_CLASS ruby2d_line_class = r_define_class(ruby2d_module, "Line");
|
1247
|
+
|
1248
|
+
// Ruby2D::Line#self.ext_draw
|
1249
|
+
r_define_class_method(ruby2d_line_class, "ext_draw", ruby2d_line_ext_draw, r_args_req(1));
|
1250
|
+
|
1251
|
+
// Ruby2D::Circle
|
1252
|
+
R_CLASS ruby2d_circle_class = r_define_class(ruby2d_module, "Circle");
|
1253
|
+
|
1254
|
+
// Ruby2D::Circle#self.ext_draw
|
1255
|
+
r_define_class_method(ruby2d_circle_class, "ext_draw", ruby2d_circle_ext_draw, r_args_req(1));
|
1256
|
+
|
1257
|
+
// Ruby2D::Image
|
1258
|
+
R_CLASS ruby2d_image_class = r_define_class(ruby2d_module, "Image");
|
1259
|
+
|
1260
|
+
// Ruby2D::Image#ext_load_image
|
1261
|
+
r_define_class_method(ruby2d_image_class, "ext_load_image", ruby2d_image_ext_load_image, r_args_req(1));
|
1262
|
+
|
1263
|
+
// Ruby2D::Text
|
1264
|
+
R_CLASS ruby2d_text_class = r_define_class(ruby2d_module, "Text");
|
1265
|
+
|
1266
|
+
// Ruby2D::Text#ext_load_text
|
1267
|
+
r_define_class_method(ruby2d_text_class, "ext_load_text", ruby2d_text_ext_load_text, r_args_req(2));
|
1268
|
+
|
1269
|
+
// Ruby2D::Sound
|
1270
|
+
R_CLASS ruby2d_sound_class = r_define_class(ruby2d_module, "Sound");
|
1271
|
+
|
1272
|
+
// Ruby2D::Sound#ext_init
|
1273
|
+
r_define_method(ruby2d_sound_class, "ext_init", ruby2d_sound_ext_init, r_args_req(1));
|
1274
|
+
|
1275
|
+
// Ruby2D::Sound#ext_play
|
1276
|
+
r_define_method(ruby2d_sound_class, "ext_play", ruby2d_sound_ext_play, r_args_none);
|
1277
|
+
|
1278
|
+
// Ruby2D::Sound#ext_get_volume
|
1279
|
+
r_define_method(ruby2d_sound_class, "ext_get_volume", ruby2d_sound_ext_get_volume, r_args_none);
|
1280
|
+
|
1281
|
+
// Ruby2D::Sound#ext_set_volume
|
1282
|
+
r_define_method(ruby2d_sound_class, "ext_set_volume", ruby2d_sound_ext_set_volume, r_args_req(1));
|
1283
|
+
|
1284
|
+
// Ruby2D::Sound#self.ext_get_mix_volume
|
1285
|
+
r_define_class_method(ruby2d_sound_class, "ext_get_mix_volume", ruby2d_sound_ext_get_mix_volume, r_args_none);
|
1286
|
+
|
1287
|
+
// Ruby2D::Sound#self.ext_set_mix_volume
|
1288
|
+
r_define_class_method(ruby2d_sound_class, "ext_set_mix_volume", ruby2d_sound_ext_set_mix_volume, r_args_req(1));
|
1289
|
+
|
1290
|
+
// Ruby2D::Sound#ext_length
|
1291
|
+
r_define_method(ruby2d_sound_class, "ext_length", ruby2d_sound_ext_length, r_args_none);
|
1292
|
+
|
1293
|
+
// Ruby2D::Music
|
1294
|
+
R_CLASS ruby2d_music_class = r_define_class(ruby2d_module, "Music");
|
1295
|
+
|
1296
|
+
// Ruby2D::Music#ext_init
|
1297
|
+
r_define_method(ruby2d_music_class, "ext_init", ruby2d_music_ext_init, r_args_req(1));
|
1298
|
+
|
1299
|
+
// Ruby2D::Music#ext_play
|
1300
|
+
r_define_method(ruby2d_music_class, "ext_play", ruby2d_music_ext_play, r_args_none);
|
1301
|
+
|
1302
|
+
// Ruby2D::Music#ext_pause
|
1303
|
+
r_define_method(ruby2d_music_class, "ext_pause", ruby2d_music_ext_pause, r_args_none);
|
1304
|
+
|
1305
|
+
// Ruby2D::Music#ext_resume
|
1306
|
+
r_define_method(ruby2d_music_class, "ext_resume", ruby2d_music_ext_resume, r_args_none);
|
1307
|
+
|
1308
|
+
// Ruby2D::Music#ext_stop
|
1309
|
+
r_define_method(ruby2d_music_class, "ext_stop", ruby2d_music_ext_stop, r_args_none);
|
1310
|
+
|
1311
|
+
// Ruby2D::Music#self.ext_get_volume
|
1312
|
+
r_define_class_method(ruby2d_music_class, "ext_get_volume", ruby2d_music_ext_get_volume, r_args_none);
|
1313
|
+
|
1314
|
+
// Ruby2D::Music#self.ext_set_volume
|
1315
|
+
r_define_class_method(ruby2d_music_class, "ext_set_volume", ruby2d_music_ext_set_volume, r_args_req(1));
|
1316
|
+
|
1317
|
+
// Ruby2D::Music#ext_fadeout
|
1318
|
+
r_define_method(ruby2d_music_class, "ext_fadeout", ruby2d_music_ext_fadeout, r_args_req(1));
|
1319
|
+
|
1320
|
+
// Ruby2D::Music#ext_length
|
1321
|
+
r_define_method(ruby2d_music_class, "ext_length", ruby2d_music_ext_length, r_args_none);
|
1322
|
+
|
1323
|
+
// Ruby2D::Font
|
1324
|
+
R_CLASS ruby2d_font_class = r_define_class(ruby2d_module, "Font");
|
1325
|
+
|
1326
|
+
// Ruby2D::Font#ext_load
|
1327
|
+
r_define_class_method(ruby2d_font_class, "ext_load", ruby2d_font_ext_load, r_args_req(3));
|
1328
|
+
|
1329
|
+
// Ruby2D::Texture
|
1330
|
+
R_CLASS ruby2d_texture_class = r_define_class(ruby2d_module, "Texture");
|
1331
|
+
|
1332
|
+
// Ruby2D::Texture#ext_draw
|
1333
|
+
r_define_method(ruby2d_texture_class, "ext_draw", ruby2d_texture_ext_draw, r_args_req(4));
|
1334
|
+
|
1335
|
+
// Ruby2D::Texture#ext_create
|
1336
|
+
r_define_method(ruby2d_texture_class, "ext_create", ruby2d_texture_ext_create, r_args_req(3));
|
1337
|
+
|
1338
|
+
// Ruby2D::Texture#ext_delete
|
1339
|
+
r_define_method(ruby2d_texture_class, "ext_delete", ruby2d_texture_ext_delete, r_args_req(1));
|
1340
|
+
|
1341
|
+
// Ruby2D::Window
|
1342
|
+
R_CLASS ruby2d_window_class = r_define_class(ruby2d_module, "Window");
|
1343
|
+
|
1344
|
+
// Ruby2D::Window#ext_diagnostics
|
1345
|
+
r_define_method(ruby2d_window_class, "ext_diagnostics", ruby2d_ext_diagnostics, r_args_req(1));
|
1346
|
+
|
1347
|
+
// Ruby2D::Window#ext_get_display_dimensions
|
1348
|
+
r_define_method(ruby2d_window_class, "ext_get_display_dimensions", ruby2d_window_ext_get_display_dimensions, r_args_none);
|
1349
|
+
|
1350
|
+
// Ruby2D::Window#ext_add_controller_mappings
|
1351
|
+
r_define_method(ruby2d_window_class, "ext_add_controller_mappings", ruby2d_window_ext_add_controller_mappings, r_args_req(1));
|
1352
|
+
|
1353
|
+
// Ruby2D::Window#ext_show
|
1354
|
+
r_define_method(ruby2d_window_class, "ext_show", ruby2d_window_ext_show, r_args_none);
|
1355
|
+
|
1356
|
+
// Ruby2D::Window#ext_screenshot
|
1357
|
+
r_define_method(ruby2d_window_class, "ext_screenshot", ruby2d_ext_screenshot, r_args_req(1));
|
1358
|
+
|
1359
|
+
// Ruby2D::Window#ext_close
|
1360
|
+
r_define_method(ruby2d_window_class, "ext_close", ruby2d_window_ext_close, r_args_none);
|
1361
|
+
|
1362
|
+
#if MRUBY
|
1363
|
+
// Load the Ruby 2D app
|
1364
|
+
mrb_load_irep(mrb, ruby2d_app);
|
1365
|
+
|
1366
|
+
// If an exception, print error
|
1367
|
+
if (mrb->exc) mrb_print_error(mrb);
|
1368
|
+
|
1369
|
+
// Close the MRuby environment
|
1370
|
+
mrb_close(mrb);
|
1371
|
+
|
1372
|
+
return 0;
|
1373
|
+
#endif
|
1374
|
+
}
|