ruby2d 0.9.2 → 0.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (162) hide show
  1. checksums.yaml +4 -4
  2. data/assets/README.md +7 -8
  3. data/assets/Rakefile +85 -0
  4. data/assets/include/SDL2/SDL.h +4 -1
  5. data/assets/include/SDL2/SDL_assert.h +3 -1
  6. data/assets/include/SDL2/SDL_atomic.h +20 -2
  7. data/assets/include/SDL2/SDL_audio.h +47 -14
  8. data/assets/include/SDL2/SDL_bits.h +10 -1
  9. data/assets/include/SDL2/SDL_blendmode.h +10 -7
  10. data/assets/include/SDL2/SDL_clipboard.h +1 -1
  11. data/assets/include/SDL2/SDL_config.h +24 -390
  12. data/assets/include/SDL2/SDL_config_android.h +182 -0
  13. data/assets/include/SDL2/SDL_config_iphoneos.h +207 -0
  14. data/assets/include/SDL2/SDL_config_macosx.h +266 -0
  15. data/assets/include/SDL2/SDL_config_minimal.h +85 -0
  16. data/assets/include/SDL2/SDL_config_os2.h +188 -0
  17. data/assets/include/SDL2/SDL_config_pandora.h +135 -0
  18. data/assets/include/SDL2/SDL_config_psp.h +165 -0
  19. data/assets/include/SDL2/SDL_config_windows.h +288 -0
  20. data/assets/include/SDL2/SDL_config_winrt.h +243 -0
  21. data/assets/include/SDL2/SDL_config_wiz.h +149 -0
  22. data/assets/include/SDL2/SDL_copying.h +20 -0
  23. data/assets/include/SDL2/SDL_cpuinfo.h +119 -8
  24. data/assets/include/SDL2/SDL_egl.h +4 -1
  25. data/assets/include/SDL2/SDL_endian.h +6 -3
  26. data/assets/include/SDL2/SDL_error.h +38 -2
  27. data/assets/include/SDL2/SDL_events.h +67 -28
  28. data/assets/include/SDL2/SDL_filesystem.h +1 -1
  29. data/assets/include/SDL2/SDL_gamecontroller.h +160 -9
  30. data/assets/include/SDL2/SDL_gesture.h +1 -1
  31. data/assets/include/SDL2/SDL_haptic.h +10 -1
  32. data/assets/include/SDL2/SDL_hints.h +460 -17
  33. data/assets/include/SDL2/SDL_image.h +2 -2
  34. data/assets/include/SDL2/SDL_joystick.h +115 -24
  35. data/assets/include/SDL2/SDL_keyboard.h +1 -1
  36. data/assets/include/SDL2/SDL_keycode.h +11 -9
  37. data/assets/include/SDL2/SDL_loadso.h +1 -1
  38. data/assets/include/SDL2/SDL_locale.h +101 -0
  39. data/assets/include/SDL2/SDL_log.h +3 -3
  40. data/assets/include/SDL2/SDL_main.h +28 -16
  41. data/assets/include/SDL2/SDL_messagebox.h +6 -4
  42. data/assets/include/SDL2/SDL_metal.h +117 -0
  43. data/assets/include/SDL2/SDL_misc.h +75 -0
  44. data/assets/include/SDL2/SDL_mouse.h +1 -1
  45. data/assets/include/SDL2/SDL_mutex.h +1 -1
  46. data/assets/include/SDL2/SDL_name.h +1 -1
  47. data/assets/include/SDL2/SDL_opengl.h +1 -1
  48. data/assets/include/SDL2/SDL_opengl_glext.h +3 -0
  49. data/assets/include/SDL2/SDL_opengles.h +1 -1
  50. data/assets/include/SDL2/SDL_opengles2.h +1 -1
  51. data/assets/include/SDL2/SDL_pixels.h +27 -18
  52. data/assets/include/SDL2/SDL_platform.h +1 -1
  53. data/assets/include/SDL2/SDL_power.h +1 -1
  54. data/assets/include/SDL2/SDL_quit.h +1 -1
  55. data/assets/include/SDL2/SDL_rect.h +29 -3
  56. data/assets/include/SDL2/SDL_render.h +230 -3
  57. data/assets/include/SDL2/SDL_revision.h +2 -2
  58. data/assets/include/SDL2/SDL_rwops.h +51 -22
  59. data/assets/include/SDL2/SDL_scancode.h +2 -2
  60. data/assets/include/SDL2/SDL_sensor.h +28 -12
  61. data/assets/include/SDL2/SDL_shape.h +1 -1
  62. data/assets/include/SDL2/SDL_stdinc.h +44 -4
  63. data/assets/include/SDL2/SDL_surface.h +12 -2
  64. data/assets/include/SDL2/SDL_system.h +50 -4
  65. data/assets/include/SDL2/SDL_syswm.h +39 -9
  66. data/assets/include/SDL2/SDL_test.h +1 -1
  67. data/assets/include/SDL2/SDL_test_assert.h +1 -1
  68. data/assets/include/SDL2/SDL_test_common.h +32 -2
  69. data/assets/include/SDL2/SDL_test_compare.h +1 -1
  70. data/assets/include/SDL2/SDL_test_crc32.h +1 -1
  71. data/assets/include/SDL2/SDL_test_font.h +1 -1
  72. data/assets/include/SDL2/SDL_test_fuzzer.h +1 -1
  73. data/assets/include/SDL2/SDL_test_harness.h +1 -1
  74. data/assets/include/SDL2/SDL_test_images.h +1 -1
  75. data/assets/include/SDL2/SDL_test_log.h +1 -1
  76. data/assets/include/SDL2/SDL_test_md5.h +1 -1
  77. data/assets/include/SDL2/SDL_test_memory.h +3 -3
  78. data/assets/include/SDL2/SDL_test_random.h +1 -1
  79. data/assets/include/SDL2/SDL_thread.h +34 -11
  80. data/assets/include/SDL2/SDL_timer.h +1 -1
  81. data/assets/include/SDL2/SDL_touch.h +17 -1
  82. data/assets/include/SDL2/SDL_types.h +1 -1
  83. data/assets/include/SDL2/SDL_version.h +2 -2
  84. data/assets/include/SDL2/SDL_video.h +11 -5
  85. data/assets/include/SDL2/SDL_vulkan.h +9 -11
  86. data/assets/include/SDL2/begin_code.h +8 -9
  87. data/assets/include/SDL2/close_code.h +4 -1
  88. data/assets/macos/lib/libFLAC.a +0 -0
  89. data/assets/macos/lib/libSDL2.a +0 -0
  90. data/assets/macos/lib/libSDL2_image.a +0 -0
  91. data/assets/macos/lib/libSDL2_mixer.a +0 -0
  92. data/assets/macos/lib/libSDL2_ttf.a +0 -0
  93. data/assets/macos/lib/libfreetype.a +0 -0
  94. data/assets/macos/lib/libjpeg.a +0 -0
  95. data/assets/macos/lib/libmpg123.a +0 -0
  96. data/assets/macos/lib/libogg.a +0 -0
  97. data/assets/macos/lib/libpng16.a +0 -0
  98. data/assets/macos/lib/libtiff.a +0 -0
  99. data/assets/macos/lib/libvorbis.a +0 -0
  100. data/assets/macos/lib/libvorbisfile.a +0 -0
  101. data/assets/macos/lib/libwebp.a +0 -0
  102. data/assets/mingw/bin/SDL2.dll +0 -0
  103. data/assets/mingw/bin/SDL2_image.dll +0 -0
  104. data/assets/mingw/bin/libpng16-16.dll +0 -0
  105. data/assets/mingw/bin/libtiff-5.dll +0 -0
  106. data/assets/mingw/bin/libwebp-7.dll +0 -0
  107. data/assets/mingw/lib/libSDL2.a +0 -0
  108. data/assets/mingw/lib/libSDL2.dll.a +0 -0
  109. data/assets/mingw/lib/libSDL2_image.a +0 -0
  110. data/assets/mingw/lib/libSDL2_image.dll.a +0 -0
  111. data/assets/mingw/lib/libSDL2_test.a +0 -0
  112. data/assets/mingw/lib/libSDL2main.a +0 -0
  113. data/bin/ruby2d +2 -1
  114. data/{assets/linux/simple2d/src/simple2d.c → ext/ruby2d/common.c} +32 -32
  115. data/{assets/linux/simple2d/src → ext/ruby2d}/controllers.c +17 -17
  116. data/ext/ruby2d/extconf.rb +6 -36
  117. data/{assets/linux/simple2d/src → ext/ruby2d}/gl.c +106 -85
  118. data/{assets/linux/simple2d/src → ext/ruby2d}/gl2.c +35 -20
  119. data/{assets/linux/simple2d/src → ext/ruby2d}/gl3.c +146 -58
  120. data/{assets/linux/simple2d/src → ext/ruby2d}/gles.c +41 -26
  121. data/{assets/linux/simple2d/src → ext/ruby2d}/image.c +16 -16
  122. data/{assets/linux/simple2d/src → ext/ruby2d}/input.c +8 -8
  123. data/{assets/linux/simple2d/src → ext/ruby2d}/music.c +30 -17
  124. data/ext/ruby2d/ruby2d.c +427 -290
  125. data/ext/ruby2d/ruby2d.h +789 -0
  126. data/{assets/linux/simple2d/src → ext/ruby2d}/shapes.c +18 -18
  127. data/ext/ruby2d/sound.c +118 -0
  128. data/{assets/linux/simple2d/src → ext/ruby2d}/sprite.c +16 -16
  129. data/{assets/linux/simple2d/src → ext/ruby2d}/text.c +22 -22
  130. data/ext/ruby2d/tileset.c +30 -0
  131. data/{assets/linux/simple2d/src → ext/ruby2d}/window.c +71 -60
  132. data/lib/ruby2d.rb +5 -2
  133. data/lib/ruby2d/circle.rb +18 -2
  134. data/lib/ruby2d/cli/build.rb +3 -8
  135. data/lib/ruby2d/cli/colorize.rb +10 -0
  136. data/lib/ruby2d/dsl.rb +16 -9
  137. data/lib/ruby2d/entity.rb +17 -0
  138. data/lib/ruby2d/font.rb +4 -3
  139. data/lib/ruby2d/image.rb +24 -1
  140. data/lib/ruby2d/line.rb +20 -0
  141. data/lib/ruby2d/music.rb +5 -0
  142. data/lib/ruby2d/pixel.rb +17 -0
  143. data/lib/ruby2d/quad.rb +18 -0
  144. data/lib/ruby2d/rectangle.rb +11 -2
  145. data/lib/ruby2d/renderable.rb +4 -8
  146. data/lib/ruby2d/sound.rb +5 -0
  147. data/lib/ruby2d/sprite.rb +35 -3
  148. data/lib/ruby2d/square.rb +9 -0
  149. data/lib/ruby2d/text.rb +22 -1
  150. data/lib/ruby2d/tileset.rb +69 -0
  151. data/lib/ruby2d/triangle.rb +16 -0
  152. data/lib/ruby2d/version.rb +1 -1
  153. data/lib/ruby2d/window.rb +249 -22
  154. metadata +41 -27
  155. data/assets/include/simple2d.h +0 -735
  156. data/assets/linux/simple2d/Makefile +0 -250
  157. data/assets/linux/simple2d/bin/simple2d.sh +0 -1249
  158. data/assets/linux/simple2d/include/simple2d.h +0 -735
  159. data/assets/linux/simple2d/src/sound.c +0 -56
  160. data/assets/macos/lib/libsimple2d.a +0 -0
  161. data/assets/mingw/lib/libsimple2d.a +0 -0
  162. data/lib/ruby2d/colorize.rb +0 -10
@@ -38,8 +38,24 @@ module Ruby2D
38
38
  questioned_area <= self_area
39
39
  end
40
40
 
41
+ def self.draw(opts = {})
42
+ ext_draw([
43
+ opts[:x1], opts[:y1], opts[:color][0][0], opts[:color][0][1], opts[:color][0][2], opts[:color][0][3],
44
+ opts[:x2], opts[:y2], opts[:color][1][0], opts[:color][1][1], opts[:color][1][2], opts[:color][1][3],
45
+ opts[:x3], opts[:y3], opts[:color][2][0], opts[:color][2][1], opts[:color][2][2], opts[:color][2][3]
46
+ ])
47
+ end
48
+
41
49
  private
42
50
 
51
+ def render
52
+ self.class.ext_draw([
53
+ @x1, @y1, @c1.r, @c1.g, @c1.b, @c1.a,
54
+ @x2, @y2, @c2.r, @c2.g, @c2.b, @c2.a,
55
+ @x3, @y3, @c3.r, @c3.g, @c3.b, @c3.a
56
+ ])
57
+ end
58
+
43
59
  def triangle_area(x1, y1, x2, y2, x3, y3)
44
60
  (x1*y2 + x2*y3 + x3*y1 - x3*y2 - x1*y3 - x2*y1).abs / 2
45
61
  end
@@ -1,5 +1,5 @@
1
1
  # Ruby2D::VERSION
2
2
 
3
3
  module Ruby2D
4
- VERSION = '0.9.2'
4
+ VERSION = '0.10.0'
5
5
  end
data/lib/ruby2d/window.rb CHANGED
@@ -6,20 +6,17 @@ module Ruby2D
6
6
  class Window
7
7
 
8
8
  # Event structures
9
- EventDescriptor = Struct.new(:type, :id)
10
- MouseEvent = Struct.new(:type, :button, :direction, :x, :y, :delta_x, :delta_y)
11
- KeyEvent = Struct.new(:type, :key)
9
+ EventDescriptor = Struct.new(:type, :id)
10
+ MouseEvent = Struct.new(:type, :button, :direction, :x, :y, :delta_x, :delta_y)
11
+ KeyEvent = Struct.new(:type, :key)
12
12
  ControllerEvent = Struct.new(:which, :type, :axis, :value, :button)
13
13
  ControllerAxisEvent = Struct.new(:which, :axis, :value)
14
14
  ControllerButtonEvent = Struct.new(:which, :button)
15
15
 
16
16
  def initialize(args = {})
17
17
 
18
- # This window instance, stored so it can be called by the class methods
19
- @@window = self
20
-
21
18
  # Title of the window
22
- @title = args[:title] || "Ruby 2D"
19
+ @title = args[:title] || "Ruby 2D"
23
20
 
24
21
  # Window background color
25
22
  @background = Color.new([0.0, 0.0, 0.0, 1.0])
@@ -51,14 +48,39 @@ module Ruby2D
51
48
  # Vertical synchronization, set to prevent screen tearing (recommended)
52
49
  @vsync = args[:vsync] || true
53
50
 
51
+ # Renderable objects currently in the window, like a linear scene graph
52
+ @objects = []
53
+
54
+ # Entities currently in the window
55
+ @entities = []
56
+
54
57
  # Mouse X and Y position in the window
55
58
  @mouse_x, @mouse_y = 0, 0
56
59
 
57
60
  # Controller axis and button mappings file
58
61
  @controller_mappings = File.expand_path('~') + "/.ruby2d/controllers.txt"
59
62
 
60
- # Renderable objects currently in the window, like a linear scene graph
61
- @objects = []
63
+ # Event stores for class pattern
64
+ @keys_down = []
65
+ @keys_held = []
66
+ @keys_up = []
67
+ @mouse_buttons_down = []
68
+ @mouse_buttons_up = []
69
+ @mouse_scroll_event = false
70
+ @mouse_scroll_direction = nil
71
+ @mouse_scroll_delta_x = 0
72
+ @mouse_scroll_delta_y = 0
73
+ @mouse_move_event = false
74
+ @mouse_move_delta_x = 0
75
+ @mouse_move_delta_y = 0
76
+ @controller_id = nil
77
+ @controller_axes_moved = []
78
+ @controller_axis_left_x = 0
79
+ @controller_axis_left_y = 0
80
+ @controller_axis_right_x = 0
81
+ @controller_axis_right_y = 0
82
+ @controller_buttons_down = []
83
+ @controller_buttons_up = []
62
84
 
63
85
  # Unique ID for the input event being registered
64
86
  @event_key = 0
@@ -83,6 +105,14 @@ module Ruby2D
83
105
  # The window update block
84
106
  @update_proc = Proc.new {}
85
107
 
108
+ # The window render block
109
+ @render_proc = Proc.new {}
110
+
111
+ # Detect if window is being used through the DSL or as a class instance
112
+ unless method(:update).parameters.empty? || method(:render).parameters.empty?
113
+ @using_dsl = true
114
+ end
115
+
86
116
  # Whether diagnostic messages should be printed
87
117
  @diagnostics = false
88
118
 
@@ -118,43 +148,47 @@ module Ruby2D
118
148
  def screenshot(opts = nil); get(:screenshot, opts) end
119
149
 
120
150
  def get(sym, opts = nil)
121
- @@window.get(sym, opts)
151
+ DSL.window.get(sym, opts)
122
152
  end
123
153
 
124
154
  def set(opts)
125
- @@window.set(opts)
155
+ DSL.window.set(opts)
126
156
  end
127
157
 
128
158
  def on(event, &proc)
129
- @@window.on(event, &proc)
159
+ DSL.window.on(event, &proc)
130
160
  end
131
161
 
132
162
  def off(event_descriptor)
133
- @@window.off(event_descriptor)
163
+ DSL.window.off(event_descriptor)
134
164
  end
135
165
 
136
166
  def add(o)
137
- @@window.add(o)
167
+ DSL.window.add(o)
138
168
  end
139
169
 
140
170
  def remove(o)
141
- @@window.remove(o)
171
+ DSL.window.remove(o)
142
172
  end
143
173
 
144
174
  def clear
145
- @@window.clear
175
+ DSL.window.clear
146
176
  end
147
177
 
148
178
  def update(&proc)
149
- @@window.update(&proc)
179
+ DSL.window.update(&proc)
180
+ end
181
+
182
+ def render(&proc)
183
+ DSL.window.render(&proc)
150
184
  end
151
185
 
152
186
  def show
153
- @@window.show
187
+ DSL.window.show
154
188
  end
155
189
 
156
190
  def close
157
- @@window.close
191
+ DSL.window.close
158
192
  end
159
193
  end
160
194
 
@@ -219,6 +253,8 @@ module Ruby2D
219
253
  case o
220
254
  when nil
221
255
  raise Error, "Cannot add '#{o.class}' to window!"
256
+ when Entity
257
+ @entities.push(o)
222
258
  when Array
223
259
  o.each { |x| add_object(x) }
224
260
  else
@@ -232,8 +268,9 @@ module Ruby2D
232
268
  raise Error, "Cannot remove '#{o.class}' from window!"
233
269
  end
234
270
 
235
- if i = @objects.index(o)
236
- @objects.delete_at(i)
271
+ collection = o.class.ancestors.include?(Ruby2D::Entity) ? @entities : @objects
272
+ if i = collection.index(o)
273
+ collection.delete_at(i)
237
274
  true
238
275
  else
239
276
  false
@@ -243,14 +280,21 @@ module Ruby2D
243
280
  # Clear all objects from the window
244
281
  def clear
245
282
  @objects.clear
283
+ @entities.clear
246
284
  end
247
285
 
248
- # Set an update callback
286
+ # Set the update callback
249
287
  def update(&proc)
250
288
  @update_proc = proc
251
289
  true
252
290
  end
253
291
 
292
+ # Set the render callback
293
+ def render(&proc)
294
+ @render_proc = proc
295
+ true
296
+ end
297
+
254
298
  # Generate a new event key (ID)
255
299
  def new_event_key
256
300
  @event_key = @event_key.next
@@ -271,6 +315,21 @@ module Ruby2D
271
315
  @events[event_descriptor.type].delete(event_descriptor.id)
272
316
  end
273
317
 
318
+ # Key down event method for class pattern
319
+ def key_down(key)
320
+ @keys_down.include? key
321
+ end
322
+
323
+ # Key held event method for class pattern
324
+ def key_held(key)
325
+ @keys_held.include? key
326
+ end
327
+
328
+ # Key up event method for class pattern
329
+ def key_up(key)
330
+ @keys_up.include? key
331
+ end
332
+
274
333
  # Key callback method, called by the native and web extentions
275
334
  def key_callback(type, key)
276
335
  key = key.downcase
@@ -283,22 +342,66 @@ module Ruby2D
283
342
  case type
284
343
  # When key is pressed, fired once
285
344
  when :down
345
+ # For class pattern
346
+ unless @using_dsl
347
+ unless @keys_down.include? key
348
+ @keys_down << key
349
+ end
350
+ end
351
+
352
+ # Call event handler
286
353
  @events[:key_down].each do |id, e|
287
354
  e.call(KeyEvent.new(type, key))
288
355
  end
289
356
  # When key is being held down, fired every frame
290
357
  when :held
358
+ # For class pattern
359
+ unless @using_dsl
360
+ unless @keys_held.include? key
361
+ @keys_held << key
362
+ end
363
+ end
364
+
365
+ # Call event handler
291
366
  @events[:key_held].each do |id, e|
292
367
  e.call(KeyEvent.new(type, key))
293
368
  end
294
369
  # When key released, fired once
295
370
  when :up
371
+ # For class pattern
372
+ unless @using_dsl
373
+ unless @keys_up.include? key
374
+ @keys_up << key
375
+ end
376
+ end
377
+
378
+ # Call event handler
296
379
  @events[:key_up].each do |id, e|
297
380
  e.call(KeyEvent.new(type, key))
298
381
  end
299
382
  end
300
383
  end
301
384
 
385
+ # Mouse down event method for class pattern
386
+ def mouse_down(btn)
387
+ @mouse_buttons_down.include? btn
388
+ end
389
+
390
+ # Mouse up event method for class pattern
391
+ def mouse_up(btn)
392
+ @mouse_buttons_up.include? btn
393
+ end
394
+
395
+ # Mouse scroll event method for class pattern
396
+ def mouse_scroll
397
+ @mouse_scroll_event
398
+ end
399
+
400
+ # Mouse move event method for class pattern
401
+ def mouse_move
402
+ @mouse_move_event
403
+ end
404
+
302
405
  # Mouse callback method, called by the native and web extentions
303
406
  def mouse_callback(type, button, direction, x, y, delta_x, delta_y)
304
407
  # All mouse events
@@ -309,21 +412,54 @@ module Ruby2D
309
412
  case type
310
413
  # When mouse button pressed
311
414
  when :down
415
+ # For class pattern
416
+ unless @using_dsl
417
+ unless @mouse_buttons_down.include? button
418
+ @mouse_buttons_down << button
419
+ end
420
+ end
421
+
422
+ # Call event handler
312
423
  @events[:mouse_down].each do |id, e|
313
424
  e.call(MouseEvent.new(type, button, nil, x, y, nil, nil))
314
425
  end
315
426
  # When mouse button released
316
427
  when :up
428
+ # For class pattern
429
+ unless @using_dsl
430
+ unless @mouse_buttons_up.include? button
431
+ @mouse_buttons_up << button
432
+ end
433
+ end
434
+
435
+ # Call event handler
317
436
  @events[:mouse_up].each do |id, e|
318
437
  e.call(MouseEvent.new(type, button, nil, x, y, nil, nil))
319
438
  end
320
439
  # When mouse motion / movement
321
440
  when :scroll
441
+ # For class pattern
442
+ unless @using_dsl
443
+ @mouse_scroll_event = true
444
+ @mouse_scroll_direction = direction
445
+ @mouse_scroll_delta_x = delta_x
446
+ @mouse_scroll_delta_y = delta_y
447
+ end
448
+
449
+ # Call event handler
322
450
  @events[:mouse_scroll].each do |id, e|
323
451
  e.call(MouseEvent.new(type, nil, direction, nil, nil, delta_x, delta_y))
324
452
  end
325
453
  # When mouse scrolling, wheel or trackpad
326
454
  when :move
455
+ # For class pattern
456
+ unless @using_dsl
457
+ @mouse_move_event = true
458
+ @mouse_move_delta_x = delta_x
459
+ @mouse_move_delta_y = delta_y
460
+ end
461
+
462
+ # Call event handler
327
463
  @events[:mouse_move].each do |id, e|
328
464
  e.call(MouseEvent.new(type, nil, nil, x, y, delta_x, delta_y))
329
465
  end
@@ -337,6 +473,21 @@ module Ruby2D
337
473
  end
338
474
  end
339
475
 
476
+ # Controller axis event method for class pattern
477
+ def controller_axis(axis)
478
+ @controller_axes_moved.include? axis
479
+ end
480
+
481
+ # Controller button down event method for class pattern
482
+ def controller_button_down(btn)
483
+ @controller_buttons_down.include? btn
484
+ end
485
+
486
+ # Controller button up event method for class pattern
487
+ def controller_button_up(btn)
488
+ @controller_buttons_up.include? btn
489
+ end
490
+
340
491
  # Controller callback method, called by the native and web extentions
341
492
  def controller_callback(which, type, axis, value, button)
342
493
  # All controller events
@@ -347,16 +498,56 @@ module Ruby2D
347
498
  case type
348
499
  # When controller axis motion, like analog sticks
349
500
  when :axis
501
+
502
+ # For class pattern
503
+ unless @using_dsl
504
+ @controller_id = which
505
+
506
+ unless @controller_axes_moved.include? axis
507
+ @controller_axes_moved << axis
508
+ end
509
+
510
+ case axis
511
+ when :left_x
512
+ @controller_axis_left_x = value
513
+ when :left_y
514
+ @controller_axis_left_y = value
515
+ when :right_x
516
+ @controller_axis_right_x = value
517
+ when :right_y
518
+ @controller_axis_right_y = value
519
+ end
520
+ end
521
+
522
+ # Call event handler
350
523
  @events[:controller_axis].each do |id, e|
351
524
  e.call(ControllerAxisEvent.new(which, axis, value))
352
525
  end
353
526
  # When controller button is pressed
354
527
  when :button_down
528
+ # For class pattern
529
+ unless @using_dsl
530
+ @controller_id = which
531
+ unless @controller_buttons_down.include? button
532
+ @controller_buttons_down << button
533
+ end
534
+ end
535
+
536
+ # Call event handler
355
537
  @events[:controller_button_down].each do |id, e|
356
538
  e.call(ControllerButtonEvent.new(which, button))
357
539
  end
358
540
  # When controller button is released
359
541
  when :button_up
542
+ # For class pattern
543
+ unless @using_dsl
544
+ @controller_id = which
545
+ unless @controller_buttons_up.include? button
546
+ @controller_buttons_up << button
547
+ end
548
+ end
549
+
550
+ # Call event handler
360
551
  @events[:controller_button_up].each do |id, e|
361
552
  e.call(ControllerButtonEvent.new(which, button))
362
553
  end
@@ -365,8 +556,17 @@ module Ruby2D
365
556
 
366
557
  # Update callback method, called by the native and web extentions
367
558
  def update_callback
559
+ unless @using_dsl
560
+ update
561
+ end
562
+
368
563
  @update_proc.call
369
564
 
565
+ # Run update method on all entities
566
+ @entities.each do |e|
567
+ e.update
568
+ end
569
+
370
570
  # Accept and eval commands if in console mode
371
571
  if @console
372
572
  if STDIN.ready?
@@ -385,6 +585,33 @@ module Ruby2D
385
585
  end
386
586
  end
387
587
 
588
+ # Clear inputs if using class pattern
589
+ unless @using_dsl
590
+ @keys_down.clear
591
+ @keys_held.clear
592
+ @keys_up.clear
593
+ @mouse_buttons_down.clear
594
+ @mouse_buttons_up.clear
595
+ @mouse_scroll_event = false
596
+ @mouse_move_event = false
597
+ @controller_axes_moved.clear
598
+ @controller_buttons_down.clear
599
+ @controller_buttons_up.clear
600
+ end
601
+ end
602
+
603
+ # Render callback method, called by the native and web extentions
604
+ def render_callback
605
+ unless @using_dsl
606
+ render
607
+ end
608
+
609
+ @render_proc.call
610
+
611
+ # Run render method on all entities
612
+ @entities.each do |e|
613
+ e.render
614
+ end
388
615
  end
389
616
 
390
617
  # Show the window