ruby2d 0.9.4 → 0.11.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/assets/include/SDL2/SDL.h +4 -1
- data/assets/include/SDL2/SDL_assert.h +3 -1
- data/assets/include/SDL2/SDL_atomic.h +1 -1
- data/assets/include/SDL2/SDL_audio.h +1 -1
- data/assets/include/SDL2/SDL_bits.h +1 -1
- data/assets/include/SDL2/SDL_blendmode.h +4 -1
- data/assets/include/SDL2/SDL_clipboard.h +1 -1
- data/assets/include/SDL2/SDL_config.h +1 -1
- data/assets/include/SDL2/SDL_config_android.h +7 -3
- data/assets/include/SDL2/SDL_config_iphoneos.h +16 -10
- data/assets/include/SDL2/SDL_config_macosx.h +40 -14
- data/assets/include/SDL2/SDL_config_minimal.h +1 -1
- data/assets/include/SDL2/SDL_config_os2.h +26 -8
- data/assets/include/SDL2/SDL_config_pandora.h +4 -2
- data/assets/include/SDL2/SDL_config_psp.h +2 -1
- data/assets/include/SDL2/SDL_config_windows.h +40 -9
- data/assets/include/SDL2/SDL_config_winrt.h +5 -2
- data/assets/include/SDL2/SDL_config_wiz.h +5 -2
- data/assets/include/SDL2/SDL_copying.h +1 -1
- data/assets/include/SDL2/SDL_cpuinfo.h +32 -3
- 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 +64 -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 +316 -4
- 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 +1 -1
- 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 +25 -16
- 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 +1 -1
- data/assets/include/SDL2/SDL_render.h +63 -3
- data/assets/include/SDL2/SDL_revision.h +2 -2
- data/assets/include/SDL2/SDL_rwops.h +2 -10
- data/assets/include/SDL2/SDL_scancode.h +1 -1
- data/assets/include/SDL2/SDL_sensor.h +25 -9
- 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 +11 -2
- data/assets/include/SDL2/SDL_system.h +50 -4
- data/assets/include/SDL2/SDL_syswm.h +29 -2
- 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 +14 -1
- 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 +1 -1
- 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 +1 -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 +6 -8
- data/assets/include/SDL2/begin_code.h +5 -9
- data/assets/include/SDL2/close_code.h +1 -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/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/lib/libSDL2.a +0 -0
- data/assets/mingw/lib/libSDL2.dll.a +0 -0
- data/assets/mingw/lib/libSDL2_test.a +0 -0
- data/assets/mingw/lib/libSDL2main.a +0 -0
- data/bin/ruby2d +1 -0
- 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 +37 -59
- data/ext/ruby2d/font.c +35 -0
- data/{assets/linux/simple2d/src → ext/ruby2d}/gl.c +66 -98
- data/ext/ruby2d/gl2.c +86 -0
- data/{assets/linux/simple2d/src → ext/ruby2d}/gl3.c +69 -112
- data/{assets/linux/simple2d/src → ext/ruby2d}/gles.c +22 -81
- data/ext/ruby2d/image.c +58 -0
- 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 +449 -439
- data/ext/ruby2d/ruby2d.h +652 -0
- data/{assets/linux/simple2d/src → ext/ruby2d}/shapes.c +18 -18
- data/{assets/linux/simple2d/src → ext/ruby2d}/sound.c +39 -14
- data/ext/ruby2d/text.c +22 -0
- data/{assets/linux/simple2d/src → ext/ruby2d}/window.c +63 -63
- data/lib/ruby2d/circle.rb +21 -3
- data/lib/ruby2d/cli/build.rb +4 -7
- data/lib/ruby2d/dsl.rb +16 -9
- data/lib/ruby2d/entity.rb +17 -0
- data/lib/ruby2d/font.rb +23 -3
- data/lib/ruby2d/image.rb +35 -7
- data/lib/ruby2d/line.rb +23 -1
- data/lib/ruby2d/music.rb +5 -0
- data/lib/ruby2d/pixel.rb +17 -0
- data/lib/ruby2d/quad.rb +21 -1
- data/lib/ruby2d/rectangle.rb +12 -3
- data/lib/ruby2d/renderable.rb +4 -20
- data/lib/ruby2d/sound.rb +30 -0
- data/lib/ruby2d/sprite.rb +57 -75
- data/lib/ruby2d/square.rb +10 -1
- data/lib/ruby2d/text.rb +55 -12
- data/lib/ruby2d/texture.rb +28 -0
- data/lib/ruby2d/tileset.rb +87 -0
- data/lib/ruby2d/triangle.rb +19 -1
- data/lib/ruby2d/version.rb +1 -1
- data/lib/ruby2d/vertices.rb +84 -0
- data/lib/ruby2d/window.rb +259 -22
- data/lib/ruby2d.rb +6 -1
- metadata +30 -26
- data/assets/include/simple2d.h +0 -757
- data/assets/linux/simple2d/Makefile +0 -260
- data/assets/linux/simple2d/bin/simple2d.sh +0 -1318
- data/assets/linux/simple2d/include/simple2d.h +0 -757
- data/assets/linux/simple2d/src/gl2.c +0 -146
- data/assets/linux/simple2d/src/image.c +0 -138
- data/assets/linux/simple2d/src/sprite.c +0 -147
- data/assets/linux/simple2d/src/text.c +0 -129
- data/assets/macos/lib/libsimple2d.a +0 -0
- data/assets/mingw/lib/libsimple2d.a +0 -0
data/lib/ruby2d/window.rb
CHANGED
@@ -4,22 +4,20 @@
|
|
4
4
|
|
5
5
|
module Ruby2D
|
6
6
|
class Window
|
7
|
+
@@open_window = false
|
7
8
|
|
8
9
|
# Event structures
|
9
|
-
EventDescriptor
|
10
|
-
MouseEvent
|
11
|
-
KeyEvent
|
10
|
+
EventDescriptor = Struct.new(:type, :id)
|
11
|
+
MouseEvent = Struct.new(:type, :button, :direction, :x, :y, :delta_x, :delta_y)
|
12
|
+
KeyEvent = Struct.new(:type, :key)
|
12
13
|
ControllerEvent = Struct.new(:which, :type, :axis, :value, :button)
|
13
14
|
ControllerAxisEvent = Struct.new(:which, :axis, :value)
|
14
15
|
ControllerButtonEvent = Struct.new(:which, :button)
|
15
16
|
|
16
17
|
def initialize(args = {})
|
17
18
|
|
18
|
-
# This window instance, stored so it can be called by the class methods
|
19
|
-
@@window = self
|
20
|
-
|
21
19
|
# Title of the window
|
22
|
-
@title = args[:title]
|
20
|
+
@title = args[:title] || "Ruby 2D"
|
23
21
|
|
24
22
|
# Window background color
|
25
23
|
@background = Color.new([0.0, 0.0, 0.0, 1.0])
|
@@ -51,14 +49,39 @@ module Ruby2D
|
|
51
49
|
# Vertical synchronization, set to prevent screen tearing (recommended)
|
52
50
|
@vsync = args[:vsync] || true
|
53
51
|
|
52
|
+
# Renderable objects currently in the window, like a linear scene graph
|
53
|
+
@objects = []
|
54
|
+
|
55
|
+
# Entities currently in the window
|
56
|
+
@entities = []
|
57
|
+
|
54
58
|
# Mouse X and Y position in the window
|
55
59
|
@mouse_x, @mouse_y = 0, 0
|
56
60
|
|
57
61
|
# Controller axis and button mappings file
|
58
62
|
@controller_mappings = File.expand_path('~') + "/.ruby2d/controllers.txt"
|
59
63
|
|
60
|
-
#
|
61
|
-
@
|
64
|
+
# Event stores for class pattern
|
65
|
+
@keys_down = []
|
66
|
+
@keys_held = []
|
67
|
+
@keys_up = []
|
68
|
+
@mouse_buttons_down = []
|
69
|
+
@mouse_buttons_up = []
|
70
|
+
@mouse_scroll_event = false
|
71
|
+
@mouse_scroll_direction = nil
|
72
|
+
@mouse_scroll_delta_x = 0
|
73
|
+
@mouse_scroll_delta_y = 0
|
74
|
+
@mouse_move_event = false
|
75
|
+
@mouse_move_delta_x = 0
|
76
|
+
@mouse_move_delta_y = 0
|
77
|
+
@controller_id = nil
|
78
|
+
@controller_axes_moved = []
|
79
|
+
@controller_axis_left_x = 0
|
80
|
+
@controller_axis_left_y = 0
|
81
|
+
@controller_axis_right_x = 0
|
82
|
+
@controller_axis_right_y = 0
|
83
|
+
@controller_buttons_down = []
|
84
|
+
@controller_buttons_up = []
|
62
85
|
|
63
86
|
# Unique ID for the input event being registered
|
64
87
|
@event_key = 0
|
@@ -83,6 +106,12 @@ module Ruby2D
|
|
83
106
|
# The window update block
|
84
107
|
@update_proc = Proc.new {}
|
85
108
|
|
109
|
+
# The window render block
|
110
|
+
@render_proc = Proc.new {}
|
111
|
+
|
112
|
+
# Detect if window is being used through the DSL or as a class instance
|
113
|
+
@using_dsl = !(method(:update).parameters.empty? || method(:render).parameters.empty?)
|
114
|
+
|
86
115
|
# Whether diagnostic messages should be printed
|
87
116
|
@diagnostics = false
|
88
117
|
|
@@ -118,43 +147,53 @@ module Ruby2D
|
|
118
147
|
def screenshot(opts = nil); get(:screenshot, opts) end
|
119
148
|
|
120
149
|
def get(sym, opts = nil)
|
121
|
-
|
150
|
+
DSL.window.get(sym, opts)
|
122
151
|
end
|
123
152
|
|
124
153
|
def set(opts)
|
125
|
-
|
154
|
+
DSL.window.set(opts)
|
126
155
|
end
|
127
156
|
|
128
157
|
def on(event, &proc)
|
129
|
-
|
158
|
+
DSL.window.on(event, &proc)
|
130
159
|
end
|
131
160
|
|
132
161
|
def off(event_descriptor)
|
133
|
-
|
162
|
+
DSL.window.off(event_descriptor)
|
134
163
|
end
|
135
164
|
|
136
165
|
def add(o)
|
137
|
-
|
166
|
+
DSL.window.add(o)
|
138
167
|
end
|
139
168
|
|
140
169
|
def remove(o)
|
141
|
-
|
170
|
+
DSL.window.remove(o)
|
142
171
|
end
|
143
172
|
|
144
173
|
def clear
|
145
|
-
|
174
|
+
DSL.window.clear
|
146
175
|
end
|
147
176
|
|
148
177
|
def update(&proc)
|
149
|
-
|
178
|
+
DSL.window.update(&proc)
|
179
|
+
end
|
180
|
+
|
181
|
+
def render(&proc)
|
182
|
+
DSL.window.render(&proc)
|
150
183
|
end
|
151
184
|
|
152
185
|
def show
|
153
|
-
|
186
|
+
DSL.window.show
|
154
187
|
end
|
155
188
|
|
156
189
|
def close
|
157
|
-
|
190
|
+
DSL.window.close
|
191
|
+
end
|
192
|
+
|
193
|
+
def render_ready_check
|
194
|
+
unless @@open_window
|
195
|
+
raise Error, "Attempting to draw before the window is ready. Please put calls to draw() inside of a render block."
|
196
|
+
end
|
158
197
|
end
|
159
198
|
end
|
160
199
|
|
@@ -219,6 +258,8 @@ module Ruby2D
|
|
219
258
|
case o
|
220
259
|
when nil
|
221
260
|
raise Error, "Cannot add '#{o.class}' to window!"
|
261
|
+
when Entity
|
262
|
+
@entities.push(o)
|
222
263
|
when Array
|
223
264
|
o.each { |x| add_object(x) }
|
224
265
|
else
|
@@ -232,8 +273,9 @@ module Ruby2D
|
|
232
273
|
raise Error, "Cannot remove '#{o.class}' from window!"
|
233
274
|
end
|
234
275
|
|
235
|
-
|
236
|
-
|
276
|
+
collection = o.class.ancestors.include?(Ruby2D::Entity) ? @entities : @objects
|
277
|
+
if i = collection.index(o)
|
278
|
+
collection.delete_at(i)
|
237
279
|
true
|
238
280
|
else
|
239
281
|
false
|
@@ -243,14 +285,21 @@ module Ruby2D
|
|
243
285
|
# Clear all objects from the window
|
244
286
|
def clear
|
245
287
|
@objects.clear
|
288
|
+
@entities.clear
|
246
289
|
end
|
247
290
|
|
248
|
-
# Set
|
291
|
+
# Set the update callback
|
249
292
|
def update(&proc)
|
250
293
|
@update_proc = proc
|
251
294
|
true
|
252
295
|
end
|
253
296
|
|
297
|
+
# Set the render callback
|
298
|
+
def render(&proc)
|
299
|
+
@render_proc = proc
|
300
|
+
true
|
301
|
+
end
|
302
|
+
|
254
303
|
# Generate a new event key (ID)
|
255
304
|
def new_event_key
|
256
305
|
@event_key = @event_key.next
|
@@ -271,6 +320,21 @@ module Ruby2D
|
|
271
320
|
@events[event_descriptor.type].delete(event_descriptor.id)
|
272
321
|
end
|
273
322
|
|
323
|
+
# Key down event method for class pattern
|
324
|
+
def key_down(key)
|
325
|
+
@keys_down.include? key
|
326
|
+
end
|
327
|
+
|
328
|
+
# Key held event method for class pattern
|
329
|
+
def key_held(key)
|
330
|
+
@keys_held.include? key
|
331
|
+
end
|
332
|
+
|
333
|
+
# Key up event method for class pattern
|
334
|
+
def key_up(key)
|
335
|
+
@keys_up.include? key
|
336
|
+
end
|
337
|
+
|
274
338
|
# Key callback method, called by the native and web extentions
|
275
339
|
def key_callback(type, key)
|
276
340
|
key = key.downcase
|
@@ -283,22 +347,66 @@ module Ruby2D
|
|
283
347
|
case type
|
284
348
|
# When key is pressed, fired once
|
285
349
|
when :down
|
350
|
+
# For class pattern
|
351
|
+
unless @using_dsl
|
352
|
+
unless @keys_down.include? key
|
353
|
+
@keys_down << key
|
354
|
+
end
|
355
|
+
end
|
356
|
+
|
357
|
+
# Call event handler
|
286
358
|
@events[:key_down].each do |id, e|
|
287
359
|
e.call(KeyEvent.new(type, key))
|
288
360
|
end
|
289
361
|
# When key is being held down, fired every frame
|
290
362
|
when :held
|
363
|
+
# For class pattern
|
364
|
+
unless @using_dsl
|
365
|
+
unless @keys_held.include? key
|
366
|
+
@keys_held << key
|
367
|
+
end
|
368
|
+
end
|
369
|
+
|
370
|
+
# Call event handler
|
291
371
|
@events[:key_held].each do |id, e|
|
292
372
|
e.call(KeyEvent.new(type, key))
|
293
373
|
end
|
294
374
|
# When key released, fired once
|
295
375
|
when :up
|
376
|
+
# For class pattern
|
377
|
+
unless @using_dsl
|
378
|
+
unless @keys_up.include? key
|
379
|
+
@keys_up << key
|
380
|
+
end
|
381
|
+
end
|
382
|
+
|
383
|
+
# Call event handler
|
296
384
|
@events[:key_up].each do |id, e|
|
297
385
|
e.call(KeyEvent.new(type, key))
|
298
386
|
end
|
299
387
|
end
|
300
388
|
end
|
301
389
|
|
390
|
+
# Mouse down event method for class pattern
|
391
|
+
def mouse_down(btn)
|
392
|
+
@mouse_buttons_down.include? btn
|
393
|
+
end
|
394
|
+
|
395
|
+
# Mouse up event method for class pattern
|
396
|
+
def mouse_up(btn)
|
397
|
+
@mouse_buttons_up.include? btn
|
398
|
+
end
|
399
|
+
|
400
|
+
# Mouse scroll event method for class pattern
|
401
|
+
def mouse_scroll
|
402
|
+
@mouse_scroll_event
|
403
|
+
end
|
404
|
+
|
405
|
+
# Mouse move event method for class pattern
|
406
|
+
def mouse_move
|
407
|
+
@mouse_move_event
|
408
|
+
end
|
409
|
+
|
302
410
|
# Mouse callback method, called by the native and web extentions
|
303
411
|
def mouse_callback(type, button, direction, x, y, delta_x, delta_y)
|
304
412
|
# All mouse events
|
@@ -309,21 +417,54 @@ module Ruby2D
|
|
309
417
|
case type
|
310
418
|
# When mouse button pressed
|
311
419
|
when :down
|
420
|
+
# For class pattern
|
421
|
+
unless @using_dsl
|
422
|
+
unless @mouse_buttons_down.include? button
|
423
|
+
@mouse_buttons_down << button
|
424
|
+
end
|
425
|
+
end
|
426
|
+
|
427
|
+
# Call event handler
|
312
428
|
@events[:mouse_down].each do |id, e|
|
313
429
|
e.call(MouseEvent.new(type, button, nil, x, y, nil, nil))
|
314
430
|
end
|
315
431
|
# When mouse button released
|
316
432
|
when :up
|
433
|
+
# For class pattern
|
434
|
+
unless @using_dsl
|
435
|
+
unless @mouse_buttons_up.include? button
|
436
|
+
@mouse_buttons_up << button
|
437
|
+
end
|
438
|
+
end
|
439
|
+
|
440
|
+
# Call event handler
|
317
441
|
@events[:mouse_up].each do |id, e|
|
318
442
|
e.call(MouseEvent.new(type, button, nil, x, y, nil, nil))
|
319
443
|
end
|
320
444
|
# When mouse motion / movement
|
321
445
|
when :scroll
|
446
|
+
# For class pattern
|
447
|
+
unless @using_dsl
|
448
|
+
@mouse_scroll_event = true
|
449
|
+
@mouse_scroll_direction = direction
|
450
|
+
@mouse_scroll_delta_x = delta_x
|
451
|
+
@mouse_scroll_delta_y = delta_y
|
452
|
+
end
|
453
|
+
|
454
|
+
# Call event handler
|
322
455
|
@events[:mouse_scroll].each do |id, e|
|
323
456
|
e.call(MouseEvent.new(type, nil, direction, nil, nil, delta_x, delta_y))
|
324
457
|
end
|
325
458
|
# When mouse scrolling, wheel or trackpad
|
326
459
|
when :move
|
460
|
+
# For class pattern
|
461
|
+
unless @using_dsl
|
462
|
+
@mouse_move_event = true
|
463
|
+
@mouse_move_delta_x = delta_x
|
464
|
+
@mouse_move_delta_y = delta_y
|
465
|
+
end
|
466
|
+
|
467
|
+
# Call event handler
|
327
468
|
@events[:mouse_move].each do |id, e|
|
328
469
|
e.call(MouseEvent.new(type, nil, nil, x, y, delta_x, delta_y))
|
329
470
|
end
|
@@ -337,6 +478,21 @@ module Ruby2D
|
|
337
478
|
end
|
338
479
|
end
|
339
480
|
|
481
|
+
# Controller axis event method for class pattern
|
482
|
+
def controller_axis(axis)
|
483
|
+
@controller_axes_moved.include? axis
|
484
|
+
end
|
485
|
+
|
486
|
+
# Controller button down event method for class pattern
|
487
|
+
def controller_button_down(btn)
|
488
|
+
@controller_buttons_down.include? btn
|
489
|
+
end
|
490
|
+
|
491
|
+
# Controller button up event method for class pattern
|
492
|
+
def controller_button_up(btn)
|
493
|
+
@controller_buttons_up.include? btn
|
494
|
+
end
|
495
|
+
|
340
496
|
# Controller callback method, called by the native and web extentions
|
341
497
|
def controller_callback(which, type, axis, value, button)
|
342
498
|
# All controller events
|
@@ -347,16 +503,56 @@ module Ruby2D
|
|
347
503
|
case type
|
348
504
|
# When controller axis motion, like analog sticks
|
349
505
|
when :axis
|
506
|
+
|
507
|
+
# For class pattern
|
508
|
+
unless @using_dsl
|
509
|
+
@controller_id = which
|
510
|
+
|
511
|
+
unless @controller_axes_moved.include? axis
|
512
|
+
@controller_axes_moved << axis
|
513
|
+
end
|
514
|
+
|
515
|
+
case axis
|
516
|
+
when :left_x
|
517
|
+
@controller_axis_left_x = value
|
518
|
+
when :left_y
|
519
|
+
@controller_axis_left_y = value
|
520
|
+
when :right_x
|
521
|
+
@controller_axis_right_x = value
|
522
|
+
when :right_y
|
523
|
+
@controller_axis_right_y = value
|
524
|
+
end
|
525
|
+
end
|
526
|
+
|
527
|
+
# Call event handler
|
350
528
|
@events[:controller_axis].each do |id, e|
|
351
529
|
e.call(ControllerAxisEvent.new(which, axis, value))
|
352
530
|
end
|
353
531
|
# When controller button is pressed
|
354
532
|
when :button_down
|
533
|
+
# For class pattern
|
534
|
+
unless @using_dsl
|
535
|
+
@controller_id = which
|
536
|
+
unless @controller_buttons_down.include? button
|
537
|
+
@controller_buttons_down << button
|
538
|
+
end
|
539
|
+
end
|
540
|
+
|
541
|
+
# Call event handler
|
355
542
|
@events[:controller_button_down].each do |id, e|
|
356
543
|
e.call(ControllerButtonEvent.new(which, button))
|
357
544
|
end
|
358
545
|
# When controller button is released
|
359
546
|
when :button_up
|
547
|
+
# For class pattern
|
548
|
+
unless @using_dsl
|
549
|
+
@controller_id = which
|
550
|
+
unless @controller_buttons_up.include? button
|
551
|
+
@controller_buttons_up << button
|
552
|
+
end
|
553
|
+
end
|
554
|
+
|
555
|
+
# Call event handler
|
360
556
|
@events[:controller_button_up].each do |id, e|
|
361
557
|
e.call(ControllerButtonEvent.new(which, button))
|
362
558
|
end
|
@@ -365,8 +561,17 @@ module Ruby2D
|
|
365
561
|
|
366
562
|
# Update callback method, called by the native and web extentions
|
367
563
|
def update_callback
|
564
|
+
unless @using_dsl
|
565
|
+
update
|
566
|
+
end
|
567
|
+
|
368
568
|
@update_proc.call
|
369
569
|
|
570
|
+
# Run update method on all entities
|
571
|
+
@entities.each do |e|
|
572
|
+
e.update
|
573
|
+
end
|
574
|
+
|
370
575
|
# Accept and eval commands if in console mode
|
371
576
|
if @console
|
372
577
|
if STDIN.ready?
|
@@ -385,10 +590,42 @@ module Ruby2D
|
|
385
590
|
end
|
386
591
|
end
|
387
592
|
|
593
|
+
# Clear inputs if using class pattern
|
594
|
+
unless @using_dsl
|
595
|
+
@keys_down.clear
|
596
|
+
@keys_held.clear
|
597
|
+
@keys_up.clear
|
598
|
+
@mouse_buttons_down.clear
|
599
|
+
@mouse_buttons_up.clear
|
600
|
+
@mouse_scroll_event = false
|
601
|
+
@mouse_move_event = false
|
602
|
+
@controller_axes_moved.clear
|
603
|
+
@controller_buttons_down.clear
|
604
|
+
@controller_buttons_up.clear
|
605
|
+
end
|
606
|
+
end
|
607
|
+
|
608
|
+
# Render callback method, called by the native and web extentions
|
609
|
+
def render_callback
|
610
|
+
unless @using_dsl
|
611
|
+
render
|
612
|
+
end
|
613
|
+
|
614
|
+
@render_proc.call
|
615
|
+
|
616
|
+
# Run render method on all entities
|
617
|
+
@entities.each do |e|
|
618
|
+
e.render
|
619
|
+
end
|
388
620
|
end
|
389
621
|
|
390
622
|
# Show the window
|
391
623
|
def show
|
624
|
+
if @@open_window
|
625
|
+
raise Error, "Window#show called multiple times, Ruby2D only supports a single open window"
|
626
|
+
end
|
627
|
+
|
628
|
+
@@open_window = true
|
392
629
|
ext_show
|
393
630
|
end
|
394
631
|
|
data/lib/ruby2d.rb
CHANGED
@@ -7,20 +7,25 @@ unless RUBY_ENGINE == 'mruby'
|
|
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'
|
25
|
+
require 'ruby2d/texture'
|
26
|
+
require 'ruby2d/vertices'
|
22
27
|
|
23
|
-
if
|
28
|
+
if defined?(RubyInstaller)
|
24
29
|
s2d_dll_path = Gem::Specification.find_by_name('ruby2d').gem_dir + '/assets/mingw/bin'
|
25
30
|
RubyInstaller::Runtime.add_dll_directory(File.expand_path(s2d_dll_path))
|
26
31
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby2d
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.11.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tom Black
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-11-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -69,9 +69,12 @@ files:
|
|
69
69
|
- assets/include/SDL2/SDL_keyboard.h
|
70
70
|
- assets/include/SDL2/SDL_keycode.h
|
71
71
|
- assets/include/SDL2/SDL_loadso.h
|
72
|
+
- assets/include/SDL2/SDL_locale.h
|
72
73
|
- assets/include/SDL2/SDL_log.h
|
73
74
|
- assets/include/SDL2/SDL_main.h
|
74
75
|
- assets/include/SDL2/SDL_messagebox.h
|
76
|
+
- assets/include/SDL2/SDL_metal.h
|
77
|
+
- assets/include/SDL2/SDL_misc.h
|
75
78
|
- assets/include/SDL2/SDL_mixer.h
|
76
79
|
- assets/include/SDL2/SDL_mouse.h
|
77
80
|
- assets/include/SDL2/SDL_mutex.h
|
@@ -123,7 +126,6 @@ files:
|
|
123
126
|
- assets/include/SDL2/begin_code.h
|
124
127
|
- assets/include/SDL2/close_code.h
|
125
128
|
- assets/include/glew.h
|
126
|
-
- assets/include/simple2d.h
|
127
129
|
- assets/ios/Assets.xcassets/AppIcon.appiconset/Contents.json
|
128
130
|
- assets/ios/Assets.xcassets/Contents.json
|
129
131
|
- assets/ios/Base.lproj/LaunchScreen.storyboard
|
@@ -165,23 +167,6 @@ files:
|
|
165
167
|
- assets/ios/MyApp.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist
|
166
168
|
- assets/ios/MyApp.xcodeproj/project.xcworkspace/xcshareddata/MyApp.xcscmblueprint
|
167
169
|
- assets/ios/main.c
|
168
|
-
- assets/linux/simple2d/Makefile
|
169
|
-
- assets/linux/simple2d/bin/simple2d.sh
|
170
|
-
- assets/linux/simple2d/include/simple2d.h
|
171
|
-
- assets/linux/simple2d/src/controllers.c
|
172
|
-
- assets/linux/simple2d/src/gl.c
|
173
|
-
- assets/linux/simple2d/src/gl2.c
|
174
|
-
- assets/linux/simple2d/src/gl3.c
|
175
|
-
- assets/linux/simple2d/src/gles.c
|
176
|
-
- assets/linux/simple2d/src/image.c
|
177
|
-
- assets/linux/simple2d/src/input.c
|
178
|
-
- assets/linux/simple2d/src/music.c
|
179
|
-
- assets/linux/simple2d/src/shapes.c
|
180
|
-
- assets/linux/simple2d/src/simple2d.c
|
181
|
-
- assets/linux/simple2d/src/sound.c
|
182
|
-
- assets/linux/simple2d/src/sprite.c
|
183
|
-
- assets/linux/simple2d/src/text.c
|
184
|
-
- assets/linux/simple2d/src/window.c
|
185
170
|
- assets/macos/lib/libFLAC.a
|
186
171
|
- assets/macos/lib/libSDL2.a
|
187
172
|
- assets/macos/lib/libSDL2_image.a
|
@@ -189,10 +174,10 @@ files:
|
|
189
174
|
- assets/macos/lib/libSDL2_ttf.a
|
190
175
|
- assets/macos/lib/libfreetype.a
|
191
176
|
- assets/macos/lib/libjpeg.a
|
177
|
+
- assets/macos/lib/libmodplug.a
|
192
178
|
- assets/macos/lib/libmpg123.a
|
193
179
|
- assets/macos/lib/libogg.a
|
194
180
|
- assets/macos/lib/libpng16.a
|
195
|
-
- assets/macos/lib/libsimple2d.a
|
196
181
|
- assets/macos/lib/libtiff.a
|
197
182
|
- assets/macos/lib/libvorbis.a
|
198
183
|
- assets/macos/lib/libvorbisfile.a
|
@@ -228,7 +213,6 @@ files:
|
|
228
213
|
- assets/mingw/lib/libSDL2main.a
|
229
214
|
- assets/mingw/lib/libglew32.a
|
230
215
|
- assets/mingw/lib/libglew32.dll.a
|
231
|
-
- assets/mingw/lib/libsimple2d.a
|
232
216
|
- assets/tvos/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Large.imagestack/Back.imagestacklayer/Content.imageset/Contents.json
|
233
217
|
- assets/tvos/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Large.imagestack/Back.imagestacklayer/Contents.json
|
234
218
|
- assets/tvos/Assets.xcassets/App Icon & Top Shelf Image.brandassets/App Icon - Large.imagestack/Contents.json
|
@@ -288,8 +272,23 @@ files:
|
|
288
272
|
- assets/tvos/MyApp.xcodeproj/project.xcworkspace/xcshareddata/MyApp.xcscmblueprint
|
289
273
|
- assets/tvos/main.c
|
290
274
|
- bin/ruby2d
|
275
|
+
- ext/ruby2d/common.c
|
276
|
+
- ext/ruby2d/controllers.c
|
291
277
|
- ext/ruby2d/extconf.rb
|
278
|
+
- ext/ruby2d/font.c
|
279
|
+
- ext/ruby2d/gl.c
|
280
|
+
- ext/ruby2d/gl2.c
|
281
|
+
- ext/ruby2d/gl3.c
|
282
|
+
- ext/ruby2d/gles.c
|
283
|
+
- ext/ruby2d/image.c
|
284
|
+
- ext/ruby2d/input.c
|
285
|
+
- ext/ruby2d/music.c
|
292
286
|
- ext/ruby2d/ruby2d.c
|
287
|
+
- ext/ruby2d/ruby2d.h
|
288
|
+
- ext/ruby2d/shapes.c
|
289
|
+
- ext/ruby2d/sound.c
|
290
|
+
- ext/ruby2d/text.c
|
291
|
+
- ext/ruby2d/window.c
|
293
292
|
- lib/ruby2d.rb
|
294
293
|
- lib/ruby2d/circle.rb
|
295
294
|
- lib/ruby2d/cli/build.rb
|
@@ -299,11 +298,13 @@ files:
|
|
299
298
|
- lib/ruby2d/cli/launch.rb
|
300
299
|
- lib/ruby2d/color.rb
|
301
300
|
- lib/ruby2d/dsl.rb
|
301
|
+
- lib/ruby2d/entity.rb
|
302
302
|
- lib/ruby2d/exceptions.rb
|
303
303
|
- lib/ruby2d/font.rb
|
304
304
|
- lib/ruby2d/image.rb
|
305
305
|
- lib/ruby2d/line.rb
|
306
306
|
- lib/ruby2d/music.rb
|
307
|
+
- lib/ruby2d/pixel.rb
|
307
308
|
- lib/ruby2d/quad.rb
|
308
309
|
- lib/ruby2d/rectangle.rb
|
309
310
|
- lib/ruby2d/renderable.rb
|
@@ -311,14 +312,17 @@ files:
|
|
311
312
|
- lib/ruby2d/sprite.rb
|
312
313
|
- lib/ruby2d/square.rb
|
313
314
|
- lib/ruby2d/text.rb
|
315
|
+
- lib/ruby2d/texture.rb
|
316
|
+
- lib/ruby2d/tileset.rb
|
314
317
|
- lib/ruby2d/triangle.rb
|
315
318
|
- lib/ruby2d/version.rb
|
319
|
+
- lib/ruby2d/vertices.rb
|
316
320
|
- lib/ruby2d/window.rb
|
317
321
|
homepage: http://www.ruby2d.com
|
318
322
|
licenses:
|
319
323
|
- MIT
|
320
324
|
metadata: {}
|
321
|
-
post_install_message:
|
325
|
+
post_install_message:
|
322
326
|
rdoc_options: []
|
323
327
|
require_paths:
|
324
328
|
- lib
|
@@ -333,8 +337,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
333
337
|
- !ruby/object:Gem::Version
|
334
338
|
version: '0'
|
335
339
|
requirements: []
|
336
|
-
rubygems_version: 3.
|
337
|
-
signing_key:
|
340
|
+
rubygems_version: 3.2.31
|
341
|
+
signing_key:
|
338
342
|
specification_version: 4
|
339
343
|
summary: Ruby 2D
|
340
344
|
test_files: []
|