ruby2d 0.9.2 → 0.10.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/assets/README.md +7 -8
- data/assets/Rakefile +85 -0
- data/assets/include/SDL2/SDL.h +4 -1
- data/assets/include/SDL2/SDL_assert.h +3 -1
- data/assets/include/SDL2/SDL_atomic.h +20 -2
- data/assets/include/SDL2/SDL_audio.h +47 -14
- data/assets/include/SDL2/SDL_bits.h +10 -1
- data/assets/include/SDL2/SDL_blendmode.h +10 -7
- data/assets/include/SDL2/SDL_clipboard.h +1 -1
- data/assets/include/SDL2/SDL_config.h +24 -390
- 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 +119 -8
- data/assets/include/SDL2/SDL_egl.h +4 -1
- data/assets/include/SDL2/SDL_endian.h +6 -3
- data/assets/include/SDL2/SDL_error.h +38 -2
- data/assets/include/SDL2/SDL_events.h +67 -28
- data/assets/include/SDL2/SDL_filesystem.h +1 -1
- data/assets/include/SDL2/SDL_gamecontroller.h +160 -9
- data/assets/include/SDL2/SDL_gesture.h +1 -1
- data/assets/include/SDL2/SDL_haptic.h +10 -1
- data/assets/include/SDL2/SDL_hints.h +460 -17
- data/assets/include/SDL2/SDL_image.h +2 -2
- data/assets/include/SDL2/SDL_joystick.h +115 -24
- data/assets/include/SDL2/SDL_keyboard.h +1 -1
- data/assets/include/SDL2/SDL_keycode.h +11 -9
- data/assets/include/SDL2/SDL_loadso.h +1 -1
- data/assets/include/SDL2/SDL_locale.h +101 -0
- data/assets/include/SDL2/SDL_log.h +3 -3
- data/assets/include/SDL2/SDL_main.h +28 -16
- data/assets/include/SDL2/SDL_messagebox.h +6 -4
- data/assets/include/SDL2/SDL_metal.h +117 -0
- data/assets/include/SDL2/SDL_misc.h +75 -0
- data/assets/include/SDL2/SDL_mouse.h +1 -1
- data/assets/include/SDL2/SDL_mutex.h +1 -1
- data/assets/include/SDL2/SDL_name.h +1 -1
- data/assets/include/SDL2/SDL_opengl.h +1 -1
- data/assets/include/SDL2/SDL_opengl_glext.h +3 -0
- data/assets/include/SDL2/SDL_opengles.h +1 -1
- data/assets/include/SDL2/SDL_opengles2.h +1 -1
- data/assets/include/SDL2/SDL_pixels.h +27 -18
- data/assets/include/SDL2/SDL_platform.h +1 -1
- data/assets/include/SDL2/SDL_power.h +1 -1
- data/assets/include/SDL2/SDL_quit.h +1 -1
- data/assets/include/SDL2/SDL_rect.h +29 -3
- data/assets/include/SDL2/SDL_render.h +230 -3
- data/assets/include/SDL2/SDL_revision.h +2 -2
- data/assets/include/SDL2/SDL_rwops.h +51 -22
- data/assets/include/SDL2/SDL_scancode.h +2 -2
- data/assets/include/SDL2/SDL_sensor.h +28 -12
- data/assets/include/SDL2/SDL_shape.h +1 -1
- data/assets/include/SDL2/SDL_stdinc.h +44 -4
- data/assets/include/SDL2/SDL_surface.h +12 -2
- data/assets/include/SDL2/SDL_system.h +50 -4
- data/assets/include/SDL2/SDL_syswm.h +39 -9
- data/assets/include/SDL2/SDL_test.h +1 -1
- data/assets/include/SDL2/SDL_test_assert.h +1 -1
- data/assets/include/SDL2/SDL_test_common.h +32 -2
- data/assets/include/SDL2/SDL_test_compare.h +1 -1
- data/assets/include/SDL2/SDL_test_crc32.h +1 -1
- data/assets/include/SDL2/SDL_test_font.h +1 -1
- data/assets/include/SDL2/SDL_test_fuzzer.h +1 -1
- data/assets/include/SDL2/SDL_test_harness.h +1 -1
- data/assets/include/SDL2/SDL_test_images.h +1 -1
- data/assets/include/SDL2/SDL_test_log.h +1 -1
- data/assets/include/SDL2/SDL_test_md5.h +1 -1
- data/assets/include/SDL2/SDL_test_memory.h +3 -3
- data/assets/include/SDL2/SDL_test_random.h +1 -1
- data/assets/include/SDL2/SDL_thread.h +34 -11
- data/assets/include/SDL2/SDL_timer.h +1 -1
- data/assets/include/SDL2/SDL_touch.h +17 -1
- data/assets/include/SDL2/SDL_types.h +1 -1
- data/assets/include/SDL2/SDL_version.h +2 -2
- data/assets/include/SDL2/SDL_video.h +11 -5
- data/assets/include/SDL2/SDL_vulkan.h +9 -11
- data/assets/include/SDL2/begin_code.h +8 -9
- data/assets/include/SDL2/close_code.h +4 -1
- 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/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/libpng16-16.dll +0 -0
- data/assets/mingw/bin/libtiff-5.dll +0 -0
- data/assets/mingw/bin/libwebp-7.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_test.a +0 -0
- data/assets/mingw/lib/libSDL2main.a +0 -0
- data/bin/ruby2d +2 -1
- data/{assets/linux/simple2d/src/simple2d.c → ext/ruby2d/common.c} +32 -32
- data/{assets/linux/simple2d/src → ext/ruby2d}/controllers.c +17 -17
- data/ext/ruby2d/extconf.rb +6 -36
- data/{assets/linux/simple2d/src → ext/ruby2d}/gl.c +106 -85
- data/{assets/linux/simple2d/src → ext/ruby2d}/gl2.c +35 -20
- data/{assets/linux/simple2d/src → ext/ruby2d}/gl3.c +146 -58
- data/{assets/linux/simple2d/src → ext/ruby2d}/gles.c +41 -26
- data/{assets/linux/simple2d/src → ext/ruby2d}/image.c +16 -16
- data/{assets/linux/simple2d/src → ext/ruby2d}/input.c +8 -8
- data/{assets/linux/simple2d/src → ext/ruby2d}/music.c +30 -17
- data/ext/ruby2d/ruby2d.c +427 -290
- data/ext/ruby2d/ruby2d.h +789 -0
- data/{assets/linux/simple2d/src → ext/ruby2d}/shapes.c +18 -18
- data/ext/ruby2d/sound.c +118 -0
- data/{assets/linux/simple2d/src → ext/ruby2d}/sprite.c +16 -16
- data/{assets/linux/simple2d/src → ext/ruby2d}/text.c +22 -22
- data/ext/ruby2d/tileset.c +30 -0
- data/{assets/linux/simple2d/src → ext/ruby2d}/window.c +71 -60
- data/lib/ruby2d.rb +5 -2
- data/lib/ruby2d/circle.rb +18 -2
- data/lib/ruby2d/cli/build.rb +3 -8
- data/lib/ruby2d/cli/colorize.rb +10 -0
- data/lib/ruby2d/dsl.rb +16 -9
- data/lib/ruby2d/entity.rb +17 -0
- data/lib/ruby2d/font.rb +4 -3
- data/lib/ruby2d/image.rb +24 -1
- data/lib/ruby2d/line.rb +20 -0
- data/lib/ruby2d/music.rb +5 -0
- data/lib/ruby2d/pixel.rb +17 -0
- data/lib/ruby2d/quad.rb +18 -0
- data/lib/ruby2d/rectangle.rb +11 -2
- data/lib/ruby2d/renderable.rb +4 -8
- data/lib/ruby2d/sound.rb +5 -0
- data/lib/ruby2d/sprite.rb +35 -3
- data/lib/ruby2d/square.rb +9 -0
- data/lib/ruby2d/text.rb +22 -1
- data/lib/ruby2d/tileset.rb +69 -0
- data/lib/ruby2d/triangle.rb +16 -0
- data/lib/ruby2d/version.rb +1 -1
- data/lib/ruby2d/window.rb +249 -22
- metadata +41 -27
- data/assets/include/simple2d.h +0 -735
- data/assets/linux/simple2d/Makefile +0 -250
- data/assets/linux/simple2d/bin/simple2d.sh +0 -1249
- data/assets/linux/simple2d/include/simple2d.h +0 -735
- data/assets/linux/simple2d/src/sound.c +0 -56
- data/assets/macos/lib/libsimple2d.a +0 -0
- data/assets/mingw/lib/libsimple2d.a +0 -0
- data/lib/ruby2d/colorize.rb +0 -10
@@ -0,0 +1,30 @@
|
|
1
|
+
// tileset.c
|
2
|
+
|
3
|
+
#include "ruby2d.h"
|
4
|
+
|
5
|
+
|
6
|
+
/*
|
7
|
+
* Draw a tile
|
8
|
+
*/
|
9
|
+
void R2D_DrawTile(R2D_Image *img, int tw, int th, int padding, int spacing, int tx, int ty, int x, int y) {
|
10
|
+
if (!img) return;
|
11
|
+
|
12
|
+
if (img->texture_id == 0) {
|
13
|
+
R2D_GL_CreateTexture(&img->texture_id, img->format,
|
14
|
+
img->width, img->height,
|
15
|
+
img->surface->pixels, GL_NEAREST);
|
16
|
+
SDL_FreeSurface(img->surface);
|
17
|
+
}
|
18
|
+
|
19
|
+
GLfloat tx1 = (double)(padding + ((spacing + tw) * tx)) / (double) img->width ;
|
20
|
+
GLfloat tx2 = tx1 + ((double)tw / (double) img->width);
|
21
|
+
GLfloat tx3 = tx2;
|
22
|
+
GLfloat tx4 = tx1;
|
23
|
+
|
24
|
+
GLfloat ty1 = (double)(padding + ((spacing + th) * ty)) / (double) img ->height;
|
25
|
+
GLfloat ty2 = ty1;
|
26
|
+
GLfloat ty3 = ty1 + ((double)th / (double) img->height);
|
27
|
+
GLfloat ty4 = ty3;
|
28
|
+
|
29
|
+
R2D_GL_DrawTile(img, x, y, tw, th, tx1, ty1, tx2, ty2, tx3, ty3, tx4, ty4);
|
30
|
+
}
|
@@ -1,25 +1,25 @@
|
|
1
1
|
// window.c
|
2
2
|
|
3
|
-
#include "
|
3
|
+
#include "ruby2d.h"
|
4
4
|
|
5
5
|
|
6
6
|
/*
|
7
7
|
* Create a window
|
8
8
|
*/
|
9
|
-
|
10
|
-
|
9
|
+
R2D_Window *R2D_CreateWindow(const char *title, int width, int height,
|
10
|
+
R2D_Update update, R2D_Render render, int flags) {
|
11
11
|
|
12
|
-
|
12
|
+
R2D_Init();
|
13
13
|
|
14
14
|
SDL_DisplayMode dm;
|
15
15
|
SDL_GetCurrentDisplayMode(0, &dm);
|
16
|
-
|
16
|
+
R2D_Log(R2D_INFO, "Current display mode is %dx%dpx @ %dhz", dm.w, dm.h, dm.refresh_rate);
|
17
17
|
|
18
|
-
width = width ==
|
19
|
-
height = height ==
|
18
|
+
width = width == R2D_DISPLAY_WIDTH ? dm.w : width;
|
19
|
+
height = height == R2D_DISPLAY_HEIGHT ? dm.h : height;
|
20
20
|
|
21
21
|
// Allocate window and set default values
|
22
|
-
|
22
|
+
R2D_Window *window = (R2D_Window *) malloc(sizeof(R2D_Window));
|
23
23
|
window->sdl = NULL;
|
24
24
|
window->glcontext = NULL;
|
25
25
|
window->title = title;
|
@@ -29,7 +29,7 @@ S2D_Window *S2D_CreateWindow(const char *title, int width, int height,
|
|
29
29
|
window->orig_height = height;
|
30
30
|
window->viewport.width = width;
|
31
31
|
window->viewport.height = height;
|
32
|
-
window->viewport.mode =
|
32
|
+
window->viewport.mode = R2D_SCALE;
|
33
33
|
window->update = update;
|
34
34
|
window->render = render;
|
35
35
|
window->flags = flags;
|
@@ -53,10 +53,10 @@ S2D_Window *S2D_CreateWindow(const char *title, int width, int height,
|
|
53
53
|
/*
|
54
54
|
* Show the window
|
55
55
|
*/
|
56
|
-
int
|
56
|
+
int R2D_Show(R2D_Window *window) {
|
57
57
|
|
58
58
|
if (!window) {
|
59
|
-
|
59
|
+
R2D_Error("R2D_Show", "Window cannot be shown (because it's NULL)");
|
60
60
|
return 1;
|
61
61
|
}
|
62
62
|
|
@@ -68,8 +68,8 @@ int S2D_Show(S2D_Window *window) {
|
|
68
68
|
SDL_WINDOW_OPENGL | window->flags // flags
|
69
69
|
);
|
70
70
|
|
71
|
-
if (!window->sdl)
|
72
|
-
if (window->icon)
|
71
|
+
if (!window->sdl) R2D_Error("SDL_CreateWindow", SDL_GetError());
|
72
|
+
if (window->icon) R2D_SetIcon(window, window->icon);
|
73
73
|
|
74
74
|
// The window created by SDL might not actually be the requested size.
|
75
75
|
// If it's not the same, retrieve and store the actual window size.
|
@@ -77,7 +77,7 @@ int S2D_Show(S2D_Window *window) {
|
|
77
77
|
SDL_GetWindowSize(window->sdl, &actual_width, &actual_height);
|
78
78
|
|
79
79
|
if ((window->width != actual_width) || (window->height != actual_height)) {
|
80
|
-
|
80
|
+
R2D_Log(R2D_INFO,
|
81
81
|
"Scaling window to %ix%i (requested size was %ix%i)",
|
82
82
|
actual_width, actual_height, window->width, window->height
|
83
83
|
);
|
@@ -89,7 +89,13 @@ int S2D_Show(S2D_Window *window) {
|
|
89
89
|
|
90
90
|
// Set Up OpenGL /////////////////////////////////////////////////////////////
|
91
91
|
|
92
|
-
|
92
|
+
R2D_GL_Init(window);
|
93
|
+
|
94
|
+
// SDL 2.0.10 and macOS 10.15 fix ////////////////////////////////////////////
|
95
|
+
|
96
|
+
#if MACOS
|
97
|
+
SDL_SetWindowSize(window->sdl, window->width, window->height);
|
98
|
+
#endif
|
93
99
|
|
94
100
|
// Set Main Loop Data ////////////////////////////////////////////////////////
|
95
101
|
|
@@ -110,7 +116,7 @@ int S2D_Show(S2D_Window *window) {
|
|
110
116
|
// Enable VSync
|
111
117
|
if (window->vsync) {
|
112
118
|
if (!SDL_SetHint(SDL_HINT_RENDER_VSYNC, "1")) {
|
113
|
-
|
119
|
+
R2D_Log(R2D_WARN, "VSync cannot be enabled");
|
114
120
|
}
|
115
121
|
}
|
116
122
|
|
@@ -122,7 +128,7 @@ int S2D_Show(S2D_Window *window) {
|
|
122
128
|
|
123
129
|
// Clear Frame /////////////////////////////////////////////////////////////
|
124
130
|
|
125
|
-
|
131
|
+
R2D_GL_Clear(window->background);
|
126
132
|
|
127
133
|
// Set FPS /////////////////////////////////////////////////////////////////
|
128
134
|
|
@@ -158,8 +164,8 @@ int S2D_Show(S2D_Window *window) {
|
|
158
164
|
|
159
165
|
case SDL_KEYDOWN:
|
160
166
|
if (window->on_key && e.key.repeat == 0) {
|
161
|
-
|
162
|
-
.type =
|
167
|
+
R2D_Event event = {
|
168
|
+
.type = R2D_KEY_DOWN, .key = SDL_GetScancodeName(e.key.keysym.scancode)
|
163
169
|
};
|
164
170
|
window->on_key(event);
|
165
171
|
}
|
@@ -167,8 +173,8 @@ int S2D_Show(S2D_Window *window) {
|
|
167
173
|
|
168
174
|
case SDL_KEYUP:
|
169
175
|
if (window->on_key) {
|
170
|
-
|
171
|
-
.type =
|
176
|
+
R2D_Event event = {
|
177
|
+
.type = R2D_KEY_UP, .key = SDL_GetScancodeName(e.key.keysym.scancode)
|
172
178
|
};
|
173
179
|
window->on_key(event);
|
174
180
|
}
|
@@ -176,11 +182,11 @@ int S2D_Show(S2D_Window *window) {
|
|
176
182
|
|
177
183
|
case SDL_MOUSEBUTTONDOWN: case SDL_MOUSEBUTTONUP:
|
178
184
|
if (window->on_mouse) {
|
179
|
-
|
180
|
-
|
185
|
+
R2D_GetMouseOnViewport(window, e.button.x, e.button.y, &mx, &my);
|
186
|
+
R2D_Event event = {
|
181
187
|
.button = e.button.button, .x = mx, .y = my
|
182
188
|
};
|
183
|
-
event.type = e.type == SDL_MOUSEBUTTONDOWN ?
|
189
|
+
event.type = e.type == SDL_MOUSEBUTTONDOWN ? R2D_MOUSE_DOWN : R2D_MOUSE_UP;
|
184
190
|
event.dblclick = e.button.clicks == 2 ? true : false;
|
185
191
|
window->on_mouse(event);
|
186
192
|
}
|
@@ -188,8 +194,8 @@ int S2D_Show(S2D_Window *window) {
|
|
188
194
|
|
189
195
|
case SDL_MOUSEWHEEL:
|
190
196
|
if (window->on_mouse) {
|
191
|
-
|
192
|
-
.type =
|
197
|
+
R2D_Event event = {
|
198
|
+
.type = R2D_MOUSE_SCROLL, .direction = e.wheel.direction,
|
193
199
|
.delta_x = e.wheel.x, .delta_y = -e.wheel.y
|
194
200
|
};
|
195
201
|
window->on_mouse(event);
|
@@ -198,9 +204,9 @@ int S2D_Show(S2D_Window *window) {
|
|
198
204
|
|
199
205
|
case SDL_MOUSEMOTION:
|
200
206
|
if (window->on_mouse) {
|
201
|
-
|
202
|
-
|
203
|
-
.type =
|
207
|
+
R2D_GetMouseOnViewport(window, e.motion.x, e.motion.y, &mx, &my);
|
208
|
+
R2D_Event event = {
|
209
|
+
.type = R2D_MOUSE_MOVE,
|
204
210
|
.x = mx, .y = my, .delta_x = e.motion.xrel, .delta_y = e.motion.yrel
|
205
211
|
};
|
206
212
|
window->on_mouse(event);
|
@@ -209,8 +215,8 @@ int S2D_Show(S2D_Window *window) {
|
|
209
215
|
|
210
216
|
case SDL_CONTROLLERAXISMOTION:
|
211
217
|
if (window->on_controller) {
|
212
|
-
|
213
|
-
.which = e.caxis.which, .type =
|
218
|
+
R2D_Event event = {
|
219
|
+
.which = e.caxis.which, .type = R2D_AXIS,
|
214
220
|
.axis = e.caxis.axis, .value = e.caxis.value
|
215
221
|
};
|
216
222
|
window->on_controller(event);
|
@@ -218,9 +224,9 @@ int S2D_Show(S2D_Window *window) {
|
|
218
224
|
break;
|
219
225
|
|
220
226
|
case SDL_JOYAXISMOTION:
|
221
|
-
if (window->on_controller && !
|
222
|
-
|
223
|
-
.which = e.jaxis.which, .type =
|
227
|
+
if (window->on_controller && !R2D_IsController(e.jbutton.which)) {
|
228
|
+
R2D_Event event = {
|
229
|
+
.which = e.jaxis.which, .type = R2D_AXIS,
|
224
230
|
.axis = e.jaxis.axis, .value = e.jaxis.value
|
225
231
|
};
|
226
232
|
window->on_controller(event);
|
@@ -229,35 +235,35 @@ int S2D_Show(S2D_Window *window) {
|
|
229
235
|
|
230
236
|
case SDL_CONTROLLERBUTTONDOWN: case SDL_CONTROLLERBUTTONUP:
|
231
237
|
if (window->on_controller) {
|
232
|
-
|
238
|
+
R2D_Event event = {
|
233
239
|
.which = e.cbutton.which, .button = e.cbutton.button
|
234
240
|
};
|
235
|
-
event.type = e.type == SDL_CONTROLLERBUTTONDOWN ?
|
241
|
+
event.type = e.type == SDL_CONTROLLERBUTTONDOWN ? R2D_BUTTON_DOWN : R2D_BUTTON_UP;
|
236
242
|
window->on_controller(event);
|
237
243
|
}
|
238
244
|
break;
|
239
245
|
|
240
246
|
case SDL_JOYBUTTONDOWN: case SDL_JOYBUTTONUP:
|
241
|
-
if (window->on_controller && !
|
242
|
-
|
247
|
+
if (window->on_controller && !R2D_IsController(e.jbutton.which)) {
|
248
|
+
R2D_Event event = {
|
243
249
|
.which = e.jbutton.which, .button = e.jbutton.button
|
244
250
|
};
|
245
|
-
event.type = e.type == SDL_JOYBUTTONDOWN ?
|
251
|
+
event.type = e.type == SDL_JOYBUTTONDOWN ? R2D_BUTTON_DOWN : R2D_BUTTON_UP;
|
246
252
|
window->on_controller(event);
|
247
253
|
}
|
248
254
|
break;
|
249
255
|
|
250
256
|
case SDL_JOYDEVICEADDED:
|
251
|
-
|
252
|
-
|
257
|
+
R2D_Log(R2D_INFO, "Controller connected (%i total)", SDL_NumJoysticks());
|
258
|
+
R2D_OpenControllers();
|
253
259
|
break;
|
254
260
|
|
255
261
|
case SDL_JOYDEVICEREMOVED:
|
256
|
-
if (
|
257
|
-
|
262
|
+
if (R2D_IsController(e.jdevice.which)) {
|
263
|
+
R2D_Log(R2D_INFO, "Controller #%i: %s removed (%i remaining)", e.jdevice.which, SDL_GameControllerName(SDL_GameControllerFromInstanceID(e.jdevice.which)), SDL_NumJoysticks());
|
258
264
|
SDL_GameControllerClose(SDL_GameControllerFromInstanceID(e.jdevice.which));
|
259
265
|
} else {
|
260
|
-
|
266
|
+
R2D_Log(R2D_INFO, "Controller #%i: %s removed (%i remaining)", e.jdevice.which, SDL_JoystickName(SDL_JoystickFromInstanceID(e.jdevice.which)), SDL_NumJoysticks());
|
261
267
|
SDL_JoystickClose(SDL_JoystickFromInstanceID(e.jdevice.which));
|
262
268
|
}
|
263
269
|
break;
|
@@ -268,13 +274,13 @@ int S2D_Show(S2D_Window *window) {
|
|
268
274
|
// Store new window size, set viewport
|
269
275
|
window->width = e.window.data1;
|
270
276
|
window->height = e.window.data2;
|
271
|
-
|
277
|
+
R2D_GL_SetViewport(window);
|
272
278
|
break;
|
273
279
|
}
|
274
280
|
break;
|
275
281
|
|
276
282
|
case SDL_QUIT:
|
277
|
-
|
283
|
+
R2D_Close(window);
|
278
284
|
break;
|
279
285
|
}
|
280
286
|
}
|
@@ -286,8 +292,8 @@ int S2D_Show(S2D_Window *window) {
|
|
286
292
|
for (int i = 0; i < num_keys; i++) {
|
287
293
|
if (window->on_key) {
|
288
294
|
if (key_state[i] == 1) {
|
289
|
-
|
290
|
-
.type =
|
295
|
+
R2D_Event event = {
|
296
|
+
.type = R2D_KEY_HELD, .key = SDL_GetScancodeName(i)
|
291
297
|
};
|
292
298
|
window->on_key(event);
|
293
299
|
}
|
@@ -297,7 +303,7 @@ int S2D_Show(S2D_Window *window) {
|
|
297
303
|
// Get and store mouse position relative to the viewport
|
298
304
|
int wx, wy; // mouse x, y coordinates relative to the window
|
299
305
|
SDL_GetMouseState(&wx, &wy);
|
300
|
-
|
306
|
+
R2D_GetMouseOnViewport(window, wx, wy, &window->mouse.x, &window->mouse.y);
|
301
307
|
|
302
308
|
// Update Window State /////////////////////////////////////////////////////
|
303
309
|
|
@@ -313,6 +319,11 @@ int S2D_Show(S2D_Window *window) {
|
|
313
319
|
if (window->render) window->render();
|
314
320
|
|
315
321
|
// Draw Frame //////////////////////////////////////////////////////////////
|
322
|
+
|
323
|
+
// Render and flush all OpenGL buffers
|
324
|
+
R2D_GL_FlushBuffers();
|
325
|
+
|
326
|
+
// Swap buffers to display drawn contents in the window
|
316
327
|
SDL_GL_SwapWindow(window->sdl);
|
317
328
|
}
|
318
329
|
|
@@ -323,14 +334,14 @@ int S2D_Show(S2D_Window *window) {
|
|
323
334
|
/*
|
324
335
|
* Set the icon for the window
|
325
336
|
*/
|
326
|
-
void
|
327
|
-
|
337
|
+
void R2D_SetIcon(R2D_Window *window, const char *icon) {
|
338
|
+
R2D_Image *img = R2D_CreateImage(icon);
|
328
339
|
if (img) {
|
329
340
|
window->icon = icon;
|
330
341
|
SDL_SetWindowIcon(window->sdl, img->surface);
|
331
|
-
|
342
|
+
R2D_FreeImage(img);
|
332
343
|
} else {
|
333
|
-
|
344
|
+
R2D_Log(R2D_WARN, "Could not set window icon");
|
334
345
|
}
|
335
346
|
}
|
336
347
|
|
@@ -338,10 +349,10 @@ void S2D_SetIcon(S2D_Window *window, const char *icon) {
|
|
338
349
|
/*
|
339
350
|
* Take a screenshot of the window
|
340
351
|
*/
|
341
|
-
void
|
352
|
+
void R2D_Screenshot(R2D_Window *window, const char *path) {
|
342
353
|
|
343
354
|
#if GLES
|
344
|
-
|
355
|
+
R2D_Error("R2D_Screenshot", "Not supported in OpenGL ES");
|
345
356
|
#else
|
346
357
|
// Create a surface the size of the window
|
347
358
|
SDL_Surface *surface = SDL_CreateRGBSurface(
|
@@ -357,7 +368,7 @@ void S2D_Screenshot(S2D_Window *window, const char *path) {
|
|
357
368
|
|
358
369
|
void *temp_row = (void *)malloc(surface->pitch);
|
359
370
|
if (!temp_row) {
|
360
|
-
|
371
|
+
R2D_Error("R2D_Screenshot", "Out of memory!");
|
361
372
|
SDL_FreeSurface(surface);
|
362
373
|
return;
|
363
374
|
}
|
@@ -382,9 +393,9 @@ void S2D_Screenshot(S2D_Window *window, const char *path) {
|
|
382
393
|
/*
|
383
394
|
* Close the window
|
384
395
|
*/
|
385
|
-
int
|
396
|
+
int R2D_Close(R2D_Window *window) {
|
386
397
|
if (!window->close) {
|
387
|
-
|
398
|
+
R2D_Log(R2D_INFO, "Closing window");
|
388
399
|
window->close = true;
|
389
400
|
}
|
390
401
|
return 0;
|
@@ -394,8 +405,8 @@ int S2D_Close(S2D_Window *window) {
|
|
394
405
|
/*
|
395
406
|
* Free all resources
|
396
407
|
*/
|
397
|
-
int
|
398
|
-
|
408
|
+
int R2D_FreeWindow(R2D_Window *window) {
|
409
|
+
R2D_Close(window);
|
399
410
|
SDL_GL_DeleteContext(window->glcontext);
|
400
411
|
SDL_DestroyWindow(window->sdl);
|
401
412
|
free(window);
|
data/lib/ruby2d.rb
CHANGED
@@ -1,26 +1,29 @@
|
|
1
1
|
# Ruby2D module and native extension loader, adds DSL
|
2
2
|
|
3
3
|
unless RUBY_ENGINE == 'mruby'
|
4
|
-
require 'ruby2d/colorize'
|
4
|
+
require 'ruby2d/cli/colorize'
|
5
5
|
require 'ruby2d/exceptions'
|
6
6
|
require 'ruby2d/renderable'
|
7
7
|
require 'ruby2d/color'
|
8
8
|
require 'ruby2d/window'
|
9
9
|
require 'ruby2d/dsl'
|
10
|
+
require 'ruby2d/entity'
|
10
11
|
require 'ruby2d/quad'
|
11
12
|
require 'ruby2d/line'
|
12
13
|
require 'ruby2d/circle'
|
13
14
|
require 'ruby2d/rectangle'
|
14
15
|
require 'ruby2d/square'
|
15
16
|
require 'ruby2d/triangle'
|
17
|
+
require 'ruby2d/pixel'
|
16
18
|
require 'ruby2d/image'
|
17
19
|
require 'ruby2d/sprite'
|
20
|
+
require 'ruby2d/tileset'
|
18
21
|
require 'ruby2d/font'
|
19
22
|
require 'ruby2d/text'
|
20
23
|
require 'ruby2d/sound'
|
21
24
|
require 'ruby2d/music'
|
22
25
|
|
23
|
-
if
|
26
|
+
if defined?(RubyInstaller)
|
24
27
|
s2d_dll_path = Gem::Specification.find_by_name('ruby2d').gem_dir + '/assets/mingw/bin'
|
25
28
|
RubyInstaller::Runtime.add_dll_directory(File.expand_path(s2d_dll_path))
|
26
29
|
end
|
data/lib/ruby2d/circle.rb
CHANGED
@@ -10,8 +10,8 @@ module Ruby2D
|
|
10
10
|
@x = opts[:x] || 25
|
11
11
|
@y = opts[:y] || 25
|
12
12
|
@z = opts[:z] || 0
|
13
|
-
@radius = opts[:radius] ||
|
14
|
-
@sectors = opts[:sectors] ||
|
13
|
+
@radius = opts[:radius] || 50
|
14
|
+
@sectors = opts[:sectors] || 30
|
15
15
|
self.color = opts[:color] || 'white'
|
16
16
|
self.opacity = opts[:opacity] if opts[:opacity]
|
17
17
|
add
|
@@ -21,5 +21,21 @@ module Ruby2D
|
|
21
21
|
Math.sqrt((x - @x)**2 + (y - @y)**2) <= @radius
|
22
22
|
end
|
23
23
|
|
24
|
+
def self.draw(opts = {})
|
25
|
+
ext_draw([
|
26
|
+
opts[:x], opts[:y], opts[:radius], opts[:sectors],
|
27
|
+
opts[:color][0], opts[:color][1], opts[:color][2], opts[:color][3]
|
28
|
+
])
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
def render
|
34
|
+
self.class.ext_draw([
|
35
|
+
@x, @y, @radius, @sectors,
|
36
|
+
@color.r, @color.g, @color.b, @color.a
|
37
|
+
])
|
38
|
+
end
|
39
|
+
|
24
40
|
end
|
25
41
|
end
|
data/lib/ruby2d/cli/build.rb
CHANGED
@@ -7,7 +7,7 @@ require 'fileutils'
|
|
7
7
|
|
8
8
|
# The Ruby 2D library files
|
9
9
|
@lib_files = [
|
10
|
-
'colorize',
|
10
|
+
'cli/colorize',
|
11
11
|
'exceptions',
|
12
12
|
'renderable',
|
13
13
|
'color',
|
@@ -96,7 +96,7 @@ def build_native(rb_file)
|
|
96
96
|
end
|
97
97
|
|
98
98
|
# Compile to a native executable
|
99
|
-
`cc build/app.c -lmruby
|
99
|
+
`cc build/app.c -lmruby -o build/app`
|
100
100
|
|
101
101
|
# Clean up
|
102
102
|
clean_up unless @debug
|
@@ -162,12 +162,6 @@ end
|
|
162
162
|
def build_ios_tvos(rb_file, device)
|
163
163
|
check_build_src_file(rb_file)
|
164
164
|
|
165
|
-
# Check for Simple 2D framework,
|
166
|
-
unless File.exist?('/usr/local/Frameworks/Simple2D/iOS/Simple2D.framework') && File.exist?('/usr/local/Frameworks/Simple2D/tvOS/Simple2D.framework')
|
167
|
-
puts "#{'Error:'.error} Simple 2D iOS and tvOS frameworks not found. Install them and try again.\n"
|
168
|
-
exit
|
169
|
-
end
|
170
|
-
|
171
165
|
# Check if MRuby exists; if not, quit
|
172
166
|
if `which mruby`.empty?
|
173
167
|
puts "#{'Error:'.error} Can't find MRuby, which is needed to build native Ruby 2D applications.\n"
|
@@ -197,6 +191,7 @@ def build_ios_tvos(rb_file, device)
|
|
197
191
|
f << File.read("#{@gem_dir}/ext/ruby2d/ruby2d.c")
|
198
192
|
end
|
199
193
|
|
194
|
+
# TODO: Need add this functionality to the gem
|
200
195
|
# Build the Xcode project
|
201
196
|
`simple2d build --#{device} build/#{device}/MyApp.xcodeproj`
|
202
197
|
|