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/common.c
ADDED
@@ -0,0 +1,185 @@
|
|
1
|
+
// Ruby 2D Shared functions and data
|
2
|
+
|
3
|
+
#include "ruby2d.h"
|
4
|
+
|
5
|
+
// Initalize shared data
|
6
|
+
bool R2D_diagnostics = false;
|
7
|
+
|
8
|
+
// Initialization status
|
9
|
+
static bool initted = false;
|
10
|
+
|
11
|
+
|
12
|
+
/*
|
13
|
+
* Provide a `vasprintf()` implementation for Windows
|
14
|
+
*/
|
15
|
+
#if WINDOWS && !MINGW
|
16
|
+
int vasprintf(char **strp, const char *fmt, va_list ap) {
|
17
|
+
int r = -1, size = _vscprintf(fmt, ap);
|
18
|
+
if ((size >= 0) && (size < INT_MAX)) {
|
19
|
+
*strp = (char *)malloc(size + 1);
|
20
|
+
if (*strp) {
|
21
|
+
r = vsnprintf(*strp, size + 1, fmt, ap);
|
22
|
+
if (r == -1) free(*strp);
|
23
|
+
}
|
24
|
+
} else { *strp = 0; }
|
25
|
+
return(r);
|
26
|
+
}
|
27
|
+
#endif
|
28
|
+
|
29
|
+
|
30
|
+
/*
|
31
|
+
* Checks if a file exists and can be accessed
|
32
|
+
*/
|
33
|
+
bool R2D_FileExists(const char *path) {
|
34
|
+
if (!path) return false;
|
35
|
+
|
36
|
+
if (access(path, F_OK) != -1) {
|
37
|
+
return true;
|
38
|
+
} else {
|
39
|
+
return false;
|
40
|
+
}
|
41
|
+
}
|
42
|
+
|
43
|
+
|
44
|
+
/*
|
45
|
+
* Logs standard messages to the console
|
46
|
+
*/
|
47
|
+
void R2D_Log(int type, const char *msg, ...) {
|
48
|
+
|
49
|
+
// Always log if diagnostics set, or if a warning or error message
|
50
|
+
if (R2D_diagnostics || type != R2D_INFO) {
|
51
|
+
|
52
|
+
va_list args;
|
53
|
+
va_start(args, msg);
|
54
|
+
|
55
|
+
switch (type) {
|
56
|
+
case R2D_INFO:
|
57
|
+
printf("\033[1;36mInfo:\033[0m ");
|
58
|
+
break;
|
59
|
+
case R2D_WARN:
|
60
|
+
printf("\033[1;33mWarning:\033[0m ");
|
61
|
+
break;
|
62
|
+
case R2D_ERROR:
|
63
|
+
printf("\033[1;31mError:\033[0m ");
|
64
|
+
break;
|
65
|
+
}
|
66
|
+
|
67
|
+
vprintf(msg, args);
|
68
|
+
printf("\n");
|
69
|
+
va_end(args);
|
70
|
+
}
|
71
|
+
}
|
72
|
+
|
73
|
+
|
74
|
+
/*
|
75
|
+
* Logs Ruby 2D errors to the console, with caller and message body
|
76
|
+
*/
|
77
|
+
void R2D_Error(const char *caller, const char *msg, ...) {
|
78
|
+
va_list args;
|
79
|
+
va_start(args, msg);
|
80
|
+
char *fmsg;
|
81
|
+
vasprintf(&fmsg, msg, args);
|
82
|
+
R2D_Log(R2D_ERROR, "(%s) %s", caller, fmsg);
|
83
|
+
free(fmsg);
|
84
|
+
va_end(args);
|
85
|
+
}
|
86
|
+
|
87
|
+
|
88
|
+
/*
|
89
|
+
* Enable/disable logging of diagnostics
|
90
|
+
*/
|
91
|
+
void R2D_Diagnostics(bool status) {
|
92
|
+
R2D_diagnostics = status;
|
93
|
+
}
|
94
|
+
|
95
|
+
|
96
|
+
/*
|
97
|
+
* Enable terminal colors in Windows
|
98
|
+
*/
|
99
|
+
void R2D_Windows_EnableTerminalColors() {
|
100
|
+
#if WINDOWS
|
101
|
+
HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);
|
102
|
+
DWORD dwMode = 0;
|
103
|
+
GetConsoleMode(hOut, &dwMode);
|
104
|
+
dwMode |= ENABLE_VIRTUAL_TERMINAL_PROCESSING;
|
105
|
+
SetConsoleMode(hOut, dwMode);
|
106
|
+
#endif
|
107
|
+
}
|
108
|
+
|
109
|
+
|
110
|
+
/*
|
111
|
+
* Initialize Ruby 2D subsystems
|
112
|
+
*/
|
113
|
+
bool R2D_Init() {
|
114
|
+
if (initted) return true;
|
115
|
+
|
116
|
+
// Enable terminal colors in Windows
|
117
|
+
R2D_Windows_EnableTerminalColors();
|
118
|
+
|
119
|
+
R2D_Log(R2D_INFO, "Initializing Ruby 2D");
|
120
|
+
|
121
|
+
// Initialize SDL
|
122
|
+
if (SDL_Init(SDL_INIT_EVERYTHING) != 0) {
|
123
|
+
R2D_Error("SDL_Init", SDL_GetError());
|
124
|
+
return false;
|
125
|
+
}
|
126
|
+
|
127
|
+
// Initialize SDL_ttf
|
128
|
+
if (TTF_Init() != 0) {
|
129
|
+
R2D_Error("TTF_Init", TTF_GetError());
|
130
|
+
return false;
|
131
|
+
}
|
132
|
+
|
133
|
+
// Initialize SDL_mixer
|
134
|
+
int mix_flags = MIX_INIT_FLAC | MIX_INIT_OGG | MIX_INIT_MP3;
|
135
|
+
int mix_initted = Mix_Init(mix_flags);
|
136
|
+
|
137
|
+
// Bug in SDL2_mixer 2.0.2:
|
138
|
+
// Mix_Init should return OR'ed flags if successful, but returns 0 instead.
|
139
|
+
// Fixed in: https://hg.libsdl.org/SDL_mixer/rev/7fa15b556953
|
140
|
+
const SDL_version *linked_version = Mix_Linked_Version();
|
141
|
+
if (linked_version->major == 2 && linked_version->minor == 0 && linked_version->patch == 2) {
|
142
|
+
// It's version 2.0.2, don't check for Mix_Init errors
|
143
|
+
} else {
|
144
|
+
if ((mix_initted&mix_flags) != mix_flags) {
|
145
|
+
R2D_Error("Mix_Init", Mix_GetError());
|
146
|
+
}
|
147
|
+
}
|
148
|
+
|
149
|
+
if (Mix_OpenAudio(44100, MIX_DEFAULT_FORMAT, 2, 4096) != 0) {
|
150
|
+
R2D_Error("Mix_OpenAudio", Mix_GetError());
|
151
|
+
return false;
|
152
|
+
}
|
153
|
+
|
154
|
+
// Call `R2D_Quit` at program exit
|
155
|
+
atexit(R2D_Quit);
|
156
|
+
|
157
|
+
// All subsystems initted
|
158
|
+
initted = true;
|
159
|
+
return true;
|
160
|
+
}
|
161
|
+
|
162
|
+
|
163
|
+
/*
|
164
|
+
* Gets the primary display's dimensions
|
165
|
+
*/
|
166
|
+
void R2D_GetDisplayDimensions(int *w, int *h) {
|
167
|
+
R2D_Init();
|
168
|
+
SDL_DisplayMode dm;
|
169
|
+
SDL_GetCurrentDisplayMode(0, &dm);
|
170
|
+
*w = dm.w;
|
171
|
+
*h = dm.h;
|
172
|
+
}
|
173
|
+
|
174
|
+
|
175
|
+
/*
|
176
|
+
* Quits Ruby 2D subsystems
|
177
|
+
*/
|
178
|
+
void R2D_Quit() {
|
179
|
+
IMG_Quit();
|
180
|
+
Mix_CloseAudio();
|
181
|
+
Mix_Quit();
|
182
|
+
TTF_Quit();
|
183
|
+
SDL_Quit();
|
184
|
+
initted = false;
|
185
|
+
}
|
@@ -0,0 +1,110 @@
|
|
1
|
+
// controllers.c
|
2
|
+
|
3
|
+
#include "ruby2d.h"
|
4
|
+
|
5
|
+
// Stores the last joystick instance ID seen by the system. These instance IDs
|
6
|
+
// are unique and increment with each new joystick connected.
|
7
|
+
static int last_intance_id = -1;
|
8
|
+
|
9
|
+
|
10
|
+
/*
|
11
|
+
* Add controller mapping from string
|
12
|
+
*/
|
13
|
+
void R2D_AddControllerMapping(const char *map) {
|
14
|
+
int result = SDL_GameControllerAddMapping(map);
|
15
|
+
|
16
|
+
char guid[33];
|
17
|
+
strncpy(guid, map, 32);
|
18
|
+
|
19
|
+
switch (result) {
|
20
|
+
case 1:
|
21
|
+
R2D_Log(R2D_INFO, "Mapping added for GUID: %s", guid);
|
22
|
+
break;
|
23
|
+
case 0:
|
24
|
+
R2D_Log(R2D_INFO, "Mapping updated for GUID: %s", guid);
|
25
|
+
break;
|
26
|
+
case -1:
|
27
|
+
R2D_Error("SDL_GameControllerAddMapping", SDL_GetError());
|
28
|
+
break;
|
29
|
+
}
|
30
|
+
}
|
31
|
+
|
32
|
+
|
33
|
+
/*
|
34
|
+
* Add controller mappings from the specified file
|
35
|
+
*/
|
36
|
+
void R2D_AddControllerMappingsFromFile(const char *path) {
|
37
|
+
if (!R2D_FileExists(path)) {
|
38
|
+
R2D_Log(R2D_WARN, "Controller mappings file not found: %s", path);
|
39
|
+
return;
|
40
|
+
}
|
41
|
+
|
42
|
+
int mappings_added = SDL_GameControllerAddMappingsFromFile(path);
|
43
|
+
if (mappings_added == -1) {
|
44
|
+
R2D_Error("SDL_GameControllerAddMappingsFromFile", SDL_GetError());
|
45
|
+
} else {
|
46
|
+
R2D_Log(R2D_INFO, "Added %i controller mapping(s)", mappings_added);
|
47
|
+
}
|
48
|
+
}
|
49
|
+
|
50
|
+
|
51
|
+
/*
|
52
|
+
* Check if joystick is a controller
|
53
|
+
*/
|
54
|
+
bool R2D_IsController(SDL_JoystickID id) {
|
55
|
+
return SDL_GameControllerFromInstanceID(id) == NULL ? false : true;
|
56
|
+
}
|
57
|
+
|
58
|
+
|
59
|
+
/*
|
60
|
+
* Open controllers and joysticks
|
61
|
+
*/
|
62
|
+
void R2D_OpenControllers() {
|
63
|
+
|
64
|
+
char guid_str[33];
|
65
|
+
|
66
|
+
// Enumerate joysticks
|
67
|
+
for (int device_index = 0; device_index < SDL_NumJoysticks(); ++device_index) {
|
68
|
+
|
69
|
+
// Check if joystick supports SDL's game controller interface (a mapping is available)
|
70
|
+
if (SDL_IsGameController(device_index)) {
|
71
|
+
SDL_GameController *controller = SDL_GameControllerOpen(device_index);
|
72
|
+
SDL_JoystickID intance_id = SDL_JoystickInstanceID(SDL_GameControllerGetJoystick(controller));
|
73
|
+
|
74
|
+
SDL_JoystickGetGUIDString(
|
75
|
+
SDL_JoystickGetGUID(SDL_GameControllerGetJoystick(controller)),
|
76
|
+
guid_str, 33
|
77
|
+
);
|
78
|
+
|
79
|
+
if (intance_id > last_intance_id) {
|
80
|
+
if (controller) {
|
81
|
+
R2D_Log(R2D_INFO, "Controller #%i: %s\n GUID: %s", intance_id, SDL_GameControllerName(controller), guid_str);
|
82
|
+
} else {
|
83
|
+
R2D_Log(R2D_ERROR, "Could not open controller #%i: %s", intance_id, SDL_GetError());
|
84
|
+
}
|
85
|
+
last_intance_id = intance_id;
|
86
|
+
}
|
87
|
+
|
88
|
+
// Controller interface not supported, try to open as joystick
|
89
|
+
} else {
|
90
|
+
SDL_Joystick *joy = SDL_JoystickOpen(device_index);
|
91
|
+
SDL_JoystickID intance_id = SDL_JoystickInstanceID(joy);
|
92
|
+
|
93
|
+
if (!joy) {
|
94
|
+
R2D_Log(R2D_ERROR, "Could not open controller");
|
95
|
+
} else if(intance_id > last_intance_id) {
|
96
|
+
SDL_JoystickGetGUIDString(
|
97
|
+
SDL_JoystickGetGUID(joy),
|
98
|
+
guid_str, 33
|
99
|
+
);
|
100
|
+
R2D_Log(R2D_INFO,
|
101
|
+
"Controller #%i: %s\n GUID: %s\n Axes: %d\n Buttons: %d\n Balls: %d",
|
102
|
+
intance_id, SDL_JoystickName(joy), guid_str, SDL_JoystickNumAxes(joy),
|
103
|
+
SDL_JoystickNumButtons(joy), SDL_JoystickNumBalls(joy)
|
104
|
+
);
|
105
|
+
R2D_Log(R2D_WARN, "Controller #%i does not have a mapping available", intance_id);
|
106
|
+
last_intance_id = intance_id;
|
107
|
+
}
|
108
|
+
}
|
109
|
+
}
|
110
|
+
}
|
@@ -0,0 +1,147 @@
|
|
1
|
+
require 'mkmf'
|
2
|
+
require_relative '../../lib/ruby2d/cli/colorize'
|
3
|
+
|
4
|
+
$errors = [] # Holds errors
|
5
|
+
|
6
|
+
# Set the OS platform
|
7
|
+
case RUBY_PLATFORM
|
8
|
+
when /darwin/
|
9
|
+
$platform = :macos
|
10
|
+
when /linux/
|
11
|
+
$platform = :linux
|
12
|
+
if `cat /etc/os-release` =~ /raspbian/
|
13
|
+
$platform = :linux_rpi
|
14
|
+
end
|
15
|
+
when /bsd/
|
16
|
+
$platform = :bsd
|
17
|
+
when /mingw/
|
18
|
+
$platform = :windows
|
19
|
+
else
|
20
|
+
$platform = nil
|
21
|
+
end
|
22
|
+
|
23
|
+
|
24
|
+
# Helper functions #############################################################
|
25
|
+
|
26
|
+
# Print installation errors
|
27
|
+
def print_errors
|
28
|
+
puts "
|
29
|
+
#{"== #{"Ruby 2D Installation Errors".error} =======================================\n"}
|
30
|
+
#{$errors.join("\n ")}\n
|
31
|
+
#{"======================================================================"}"
|
32
|
+
end
|
33
|
+
|
34
|
+
|
35
|
+
# Add compiler and linker flags
|
36
|
+
def add_flags(type, flags)
|
37
|
+
case type
|
38
|
+
when :c
|
39
|
+
$CFLAGS << " #{flags} "
|
40
|
+
when :ld
|
41
|
+
$LDFLAGS << " #{flags} "
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
|
46
|
+
# Check for SDL libraries
|
47
|
+
def check_sdl
|
48
|
+
unless have_library('SDL2') && have_library('SDL2_image') && have_library('SDL2_mixer') && have_library('SDL2_ttf')
|
49
|
+
|
50
|
+
$errors << "Couldn't find packages needed by Ruby 2D."
|
51
|
+
|
52
|
+
case $platform
|
53
|
+
when :linux, :linux_rpi
|
54
|
+
# Fedora and CentOS
|
55
|
+
if system('which yum')
|
56
|
+
$errors << "Install the following packages using `yum` (or `dnf`) and try again:\n" <<
|
57
|
+
" SDL2-devel SDL2_image-devel SDL2_mixer-devel SDL2_ttf-devel".bold
|
58
|
+
|
59
|
+
# Arch
|
60
|
+
elsif system('which pacman')
|
61
|
+
$errors << "Install the following packages using `pacman` and try again:\n" <<
|
62
|
+
" sdl2 sdl2_image sdl2_mixer sdl2_ttf".bold
|
63
|
+
|
64
|
+
# openSUSE
|
65
|
+
elsif system('which zypper')
|
66
|
+
$errors << "Install the following packages using `zypper` and try again:\n" <<
|
67
|
+
" libSDL2-devel libSDL2_image-devel libSDL2_mixer-devel libSDL2_ttf-devel".bold
|
68
|
+
|
69
|
+
# Ubuntu, Debian, and Mint
|
70
|
+
# `apt` must be last because openSUSE has it aliased to `zypper`
|
71
|
+
elsif system('which apt')
|
72
|
+
$errors << "Install the following packages using `apt` and try again:\n" <<
|
73
|
+
" libsdl2-dev libsdl2-image-dev libsdl2-mixer-dev libsdl2-ttf-dev".bold
|
74
|
+
end
|
75
|
+
when :bsd
|
76
|
+
$errors << "Install the following packages using `pkg` and try again:\n" <<
|
77
|
+
" sdl2 sdl2_image sdl2_mixer sdl2_ttf".bold
|
78
|
+
end
|
79
|
+
|
80
|
+
$errors << "" << "See #{"ruby2d.com".bold} for additional help."
|
81
|
+
print_errors; exit
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
|
86
|
+
# Set Raspberry Pi flags
|
87
|
+
def set_rpi_flags
|
88
|
+
if $platform == :linux_rpi
|
89
|
+
add_flags(:c, '-I/opt/vc/include')
|
90
|
+
add_flags(:ld, '-L/opt/vc/lib -lbrcmGLESv2')
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
|
95
|
+
# Use SDL and other libraries installed by the user (not those bundled with the gem)
|
96
|
+
def use_usr_libs
|
97
|
+
# Add flags
|
98
|
+
set_rpi_flags
|
99
|
+
add_flags(:c, '-I/usr/local/include')
|
100
|
+
end
|
101
|
+
|
102
|
+
|
103
|
+
# Configure native extension ###################################################
|
104
|
+
|
105
|
+
# Build Ruby 2D native extention using libraries installed by user
|
106
|
+
# To use install flag: `gem install ruby2d -- libs`
|
107
|
+
if ARGV.include? 'libs'
|
108
|
+
use_usr_libs
|
109
|
+
|
110
|
+
# Use libraries provided by the gem (default)
|
111
|
+
else
|
112
|
+
add_flags(:c, '-std=c11')
|
113
|
+
|
114
|
+
case $platform
|
115
|
+
|
116
|
+
when :macos
|
117
|
+
add_flags(:c, '-I../../assets/include')
|
118
|
+
ldir = "#{Dir.pwd}/../../assets/macos/lib"
|
119
|
+
|
120
|
+
add_flags(:ld, "#{ldir}/libSDL2.a #{ldir}/libSDL2_image.a #{ldir}/libSDL2_mixer.a #{ldir}/libSDL2_ttf.a")
|
121
|
+
add_flags(:ld, "#{ldir}/libjpeg.a #{ldir}/libpng16.a #{ldir}/libtiff.a #{ldir}/libwebp.a")
|
122
|
+
add_flags(:ld, "#{ldir}/libmpg123.a #{ldir}/libogg.a #{ldir}/libFLAC.a #{ldir}/libvorbis.a #{ldir}/libvorbisfile.a")
|
123
|
+
add_flags(:ld, "#{ldir}/libfreetype.a #{ldir}/libmodplug.a")
|
124
|
+
add_flags(:ld, "-Wl,-framework,Cocoa -Wl,-framework,GameController -Wl,-framework,ForceFeedback")
|
125
|
+
|
126
|
+
when :linux, :linux_rpi, :bsd
|
127
|
+
check_sdl
|
128
|
+
|
129
|
+
set_rpi_flags
|
130
|
+
add_flags(:ld, "-lSDL2 -lSDL2_image -lSDL2_mixer -lSDL2_ttf -lm")
|
131
|
+
if $platform == :linux then add_flags(:ld, '-lGL') end
|
132
|
+
|
133
|
+
when :windows
|
134
|
+
add_flags(:c, '-I../../assets/include')
|
135
|
+
add_flags(:ld, '-L../../assets/mingw/lib -lSDL2 -lSDL2_image -lSDL2_mixer -lSDL2_ttf')
|
136
|
+
add_flags(:ld, '-lmingw32 -lopengl32 -lglew32')
|
137
|
+
|
138
|
+
# If can't detect the platform, use libraries installed by the user
|
139
|
+
else
|
140
|
+
use_usr_libs
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
$LDFLAGS.gsub!(/\n/, ' ') # remove newlines in flags, they can cause problems
|
145
|
+
|
146
|
+
# Create Makefile
|
147
|
+
create_makefile('ruby2d/ruby2d')
|
data/ext/ruby2d/font.c
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
// font.c
|
2
|
+
|
3
|
+
#include "ruby2d.h"
|
4
|
+
|
5
|
+
|
6
|
+
/*
|
7
|
+
* Create a TTF_Font object given a path to a font and a size
|
8
|
+
*/
|
9
|
+
TTF_Font *R2D_FontCreateTTFFont(const char *path, int size, const char *style) {
|
10
|
+
|
11
|
+
// Check if font file exists
|
12
|
+
if (!R2D_FileExists(path)) {
|
13
|
+
R2D_Error("R2D_FontCreateTTFFont", "Font file `%s` not found", path);
|
14
|
+
return NULL;
|
15
|
+
}
|
16
|
+
|
17
|
+
TTF_Font *font = TTF_OpenFont(path, size);
|
18
|
+
|
19
|
+
if (!font) {
|
20
|
+
R2D_Error("TTF_OpenFont", TTF_GetError());
|
21
|
+
return NULL;
|
22
|
+
}
|
23
|
+
|
24
|
+
if(strncmp(style, "bold", 4) == 0) {
|
25
|
+
TTF_SetFontStyle(font, TTF_STYLE_BOLD);
|
26
|
+
} else if(strncmp(style, "italic", 6) == 0) {
|
27
|
+
TTF_SetFontStyle(font, TTF_STYLE_ITALIC);
|
28
|
+
} else if(strncmp(style, "underline", 9) == 0) {
|
29
|
+
TTF_SetFontStyle(font, TTF_STYLE_UNDERLINE);
|
30
|
+
} else if(strncmp(style, "strikethrough", 13) == 0) {
|
31
|
+
TTF_SetFontStyle(font, TTF_STYLE_STRIKETHROUGH);
|
32
|
+
}
|
33
|
+
|
34
|
+
return font;
|
35
|
+
}
|