ruby-sfml 3.0.0.6 → 3.0.0.7
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.
- checksums.yaml +4 -4
- data/.rdoc_options +44 -0
- data/CHANGELOG.md +40 -3
- data/README.md +71 -25
- data/lib/sfml/app.rb +5 -0
- data/lib/sfml/assets.rb +2 -0
- data/lib/sfml/audio/listener.rb +7 -0
- data/lib/sfml/audio/music.rb +51 -0
- data/lib/sfml/audio/sound.rb +41 -0
- data/lib/sfml/audio/sound_buffer.rb +4 -0
- data/lib/sfml/audio/sound_buffer_recorder.rb +2 -0
- data/lib/sfml/audio/sound_cone.rb +1 -0
- data/lib/sfml/audio/sound_recorder.rb +5 -0
- data/lib/sfml/audio/sound_stream.rb +46 -0
- data/lib/sfml/graphics/animation.rb +10 -0
- data/lib/sfml/graphics/blend_mode.rb +1 -0
- data/lib/sfml/graphics/circle_shape.rb +16 -0
- data/lib/sfml/graphics/color.rb +31 -0
- data/lib/sfml/graphics/convex_shape.rb +9 -0
- data/lib/sfml/graphics/font.rb +2 -0
- data/lib/sfml/graphics/image.rb +2 -0
- data/lib/sfml/graphics/particle_system.rb +5 -0
- data/lib/sfml/graphics/rectangle_shape.rb +11 -0
- data/lib/sfml/graphics/render_target.rb +1 -0
- data/lib/sfml/graphics/render_texture.rb +7 -0
- data/lib/sfml/graphics/render_window.rb +26 -0
- data/lib/sfml/graphics/shape.rb +5 -0
- data/lib/sfml/graphics/shape_inspectable.rb +2 -0
- data/lib/sfml/graphics/sprite.rb +4 -0
- data/lib/sfml/graphics/sprite_sheet.rb +2 -0
- data/lib/sfml/graphics/stencil_mode.rb +1 -0
- data/lib/sfml/graphics/text.rb +19 -0
- data/lib/sfml/graphics/texture.rb +5 -0
- data/lib/sfml/graphics/texture_atlas.rb +2 -0
- data/lib/sfml/graphics/transform.rb +2 -0
- data/lib/sfml/graphics/transformable.rb +12 -0
- data/lib/sfml/graphics/vertex_array.rb +18 -0
- data/lib/sfml/graphics/vertex_buffer.rb +4 -0
- data/lib/sfml/graphics/view.rb +5 -0
- data/lib/sfml/network/ftp.rb +34 -0
- data/lib/sfml/network/http.rb +1 -0
- data/lib/sfml/network/ip_address.rb +1 -0
- data/lib/sfml/network/packet.rb +28 -0
- data/lib/sfml/network/socket_selector.rb +1 -0
- data/lib/sfml/network/tcp_listener.rb +3 -0
- data/lib/sfml/network/tcp_socket.rb +4 -0
- data/lib/sfml/network/udp_socket.rb +3 -0
- data/lib/sfml/scene.rb +2 -0
- data/lib/sfml/system/clock.rb +1 -0
- data/lib/sfml/system/rect.rb +27 -5
- data/lib/sfml/system/time.rb +22 -2
- data/lib/sfml/system/vector2.rb +42 -2
- data/lib/sfml/system/vector3.rb +45 -2
- data/lib/sfml/version.rb +1 -1
- data/lib/sfml/window/clipboard.rb +1 -0
- data/lib/sfml/window/context_settings.rb +1 -0
- data/lib/sfml/window/event.rb +2 -0
- data/lib/sfml/window/joystick.rb +3 -0
- data/lib/sfml/window/sensor.rb +1 -0
- data/lib/sfml/window/video_mode.rb +2 -0
- data/lib/sfml/window/window.rb +12 -0
- data/ruby-sfml.gemspec +6 -2
- metadata +3 -2
data/lib/sfml/system/vector3.rb
CHANGED
|
@@ -1,10 +1,16 @@
|
|
|
1
1
|
module SFML
|
|
2
|
-
# 3D vector with float components. Mirrors Vector2's surface
|
|
2
|
+
# 3D vector with float components. Mirrors Vector2's surface — same
|
|
3
|
+
# arithmetic, same coerce trick for `2 * v`, same pattern-match
|
|
4
|
+
# support. Used by the 3D-audio API (`Sound#position`, `Listener`,
|
|
5
|
+
# …) and as a back-end for `Image` size hints.
|
|
3
6
|
class Vector3
|
|
4
7
|
attr_reader :x, :y, :z
|
|
5
8
|
|
|
9
|
+
# Compact constructor: `Vector3[1, 2, 3]`.
|
|
6
10
|
def self.[](x, y, z) = new(x, y, z)
|
|
7
|
-
|
|
11
|
+
|
|
12
|
+
# The (0, 0, 0) vector.
|
|
13
|
+
def self.zero = new(0, 0, 0)
|
|
8
14
|
|
|
9
15
|
def initialize(x = 0, y = 0, z = 0)
|
|
10
16
|
@x = x
|
|
@@ -13,29 +19,44 @@ module SFML
|
|
|
13
19
|
freeze
|
|
14
20
|
end
|
|
15
21
|
|
|
22
|
+
# Component-wise addition.
|
|
16
23
|
def +(other) = Vector3.new(@x + other.x, @y + other.y, @z + other.z)
|
|
24
|
+
# Component-wise subtraction.
|
|
17
25
|
def -(other) = Vector3.new(@x - other.x, @y - other.y, @z - other.z)
|
|
26
|
+
# Multiply every component by `scalar`.
|
|
18
27
|
def *(scalar) = Vector3.new(@x * scalar, @y * scalar, @z * scalar)
|
|
28
|
+
# Divide every component by `scalar` (promotes to Float).
|
|
19
29
|
def /(scalar) = Vector3.new(@x / scalar.to_f, @y / scalar.to_f, @z / scalar.to_f)
|
|
30
|
+
# Negate every component.
|
|
20
31
|
def -@ = Vector3.new(-@x, -@y, -@z)
|
|
21
32
|
|
|
33
|
+
# Value equality — all three components must match.
|
|
22
34
|
def ==(other)
|
|
23
35
|
other.is_a?(Vector3) && @x == other.x && @y == other.y && @z == other.z
|
|
24
36
|
end
|
|
25
37
|
alias eql? ==
|
|
38
|
+
# Hash key support.
|
|
26
39
|
def hash = [@x, @y, @z].hash
|
|
27
40
|
|
|
41
|
+
# Euclidean length √(x² + y² + z²). Prefer `length_sq` for
|
|
42
|
+
# comparisons to skip the square root.
|
|
28
43
|
def length = Math.sqrt(length_sq)
|
|
44
|
+
# Squared length (x² + y² + z²) — faster than `length` when you
|
|
45
|
+
# only need to compare magnitudes.
|
|
29
46
|
def length_sq = (@x * @x) + (@y * @y) + (@z * @z)
|
|
30
47
|
|
|
48
|
+
# Unit vector in the same direction. Zero vector returns itself
|
|
49
|
+
# unchanged.
|
|
31
50
|
def normalize
|
|
32
51
|
len = length
|
|
33
52
|
return Vector3.zero if len.zero?
|
|
34
53
|
self / len
|
|
35
54
|
end
|
|
36
55
|
|
|
56
|
+
# Scalar dot product.
|
|
37
57
|
def dot(other) = (@x * other.x) + (@y * other.y) + (@z * other.z)
|
|
38
58
|
|
|
59
|
+
# 3D cross product (vector perpendicular to both).
|
|
39
60
|
def cross(other)
|
|
40
61
|
Vector3.new(
|
|
41
62
|
(@y * other.z) - (@z * other.y),
|
|
@@ -50,9 +71,13 @@ module SFML
|
|
|
50
71
|
[self, other]
|
|
51
72
|
end
|
|
52
73
|
|
|
74
|
+
# Euclidean distance between two points — accepts Vector3 or
|
|
75
|
+
# `[x, y, z]`.
|
|
53
76
|
def distance(other) = (self - _coerce(other)).length
|
|
77
|
+
# Squared distance (skip the square root) for comparisons.
|
|
54
78
|
def distance_sq(other) = (self - _coerce(other)).length_sq
|
|
55
79
|
|
|
80
|
+
# Linear interpolation toward `other` at parameter `t` ∈ [0, 1].
|
|
56
81
|
def lerp(other, t)
|
|
57
82
|
o = _coerce(other)
|
|
58
83
|
Vector3.new(@x + (o.x - @x) * t, @y + (o.y - @y) * t, @z + (o.z - @z) * t)
|
|
@@ -69,6 +94,7 @@ module SFML
|
|
|
69
94
|
Math.acos(cos)
|
|
70
95
|
end
|
|
71
96
|
|
|
97
|
+
# Vector projection of `self` onto `other`.
|
|
72
98
|
def project_on(other)
|
|
73
99
|
o = _coerce(other)
|
|
74
100
|
d = o.length_sq
|
|
@@ -76,11 +102,15 @@ module SFML
|
|
|
76
102
|
o * (dot(o) / d)
|
|
77
103
|
end
|
|
78
104
|
|
|
105
|
+
# Reflect this vector across the plane defined by `normal`.
|
|
106
|
+
# `normal` should be unit-length.
|
|
79
107
|
def reflect(normal)
|
|
80
108
|
n = _coerce(normal)
|
|
81
109
|
self - (n * (2 * dot(n)))
|
|
82
110
|
end
|
|
83
111
|
|
|
112
|
+
# Clamp the magnitude into [min_len, max_len]. Either bound may
|
|
113
|
+
# be `nil` to leave that side unclamped.
|
|
84
114
|
def clamp_length(min_len = nil, max_len)
|
|
85
115
|
len = length
|
|
86
116
|
return self if len.zero?
|
|
@@ -93,15 +123,28 @@ module SFML
|
|
|
93
123
|
self * (target / len)
|
|
94
124
|
end
|
|
95
125
|
|
|
126
|
+
# `true` iff all three components are zero.
|
|
96
127
|
def zero? = @x.zero? && @y.zero? && @z.zero?
|
|
128
|
+
|
|
129
|
+
# Per-component absolute value.
|
|
97
130
|
def abs = Vector3.new(@x.abs, @y.abs, @z.abs)
|
|
131
|
+
|
|
132
|
+
# Drop the z component → Vector2.
|
|
98
133
|
def to_v2 = Vector2.new(@x, @y)
|
|
99
134
|
|
|
135
|
+
# As `[x, y, z]`.
|
|
100
136
|
def to_a = [@x, @y, @z]
|
|
137
|
+
|
|
138
|
+
# As `{x:, y:, z:}`.
|
|
101
139
|
def to_h = { x: @x, y: @y, z: @z }
|
|
140
|
+
|
|
141
|
+
# Pattern-match support for `in [x, y, z]`.
|
|
102
142
|
def deconstruct = [@x, @y, @z]
|
|
143
|
+
|
|
144
|
+
# Pattern-match support for `in {x:, y:, z:}`.
|
|
103
145
|
def deconstruct_keys(_keys) = { x: @x, y: @y, z: @z }
|
|
104
146
|
|
|
147
|
+
# String representation for debugging.
|
|
105
148
|
def to_s = "Vector3(#{@x}, #{@y}, #{@z})"
|
|
106
149
|
alias inspect to_s
|
|
107
150
|
|
data/lib/sfml/version.rb
CHANGED
data/lib/sfml/window/event.rb
CHANGED
|
@@ -34,6 +34,7 @@ module SFML
|
|
|
34
34
|
{ type: @type, **@data }
|
|
35
35
|
end
|
|
36
36
|
|
|
37
|
+
# `true` if respond to missing.
|
|
37
38
|
def respond_to_missing?(name, _private = false)
|
|
38
39
|
@data.key?(name) || super
|
|
39
40
|
end
|
|
@@ -43,6 +44,7 @@ module SFML
|
|
|
43
44
|
super
|
|
44
45
|
end
|
|
45
46
|
|
|
47
|
+
# String representation for debugging.
|
|
46
48
|
def to_s = "#<SFML::Event #{@type} #{@data.inspect}>"
|
|
47
49
|
alias inspect to_s
|
|
48
50
|
|
data/lib/sfml/window/joystick.rb
CHANGED
|
@@ -29,6 +29,7 @@ module SFML
|
|
|
29
29
|
|
|
30
30
|
module_function
|
|
31
31
|
|
|
32
|
+
# `true` if connected.
|
|
32
33
|
def connected?(joystick)
|
|
33
34
|
C::Window.sfJoystick_isConnected(_id(joystick))
|
|
34
35
|
end
|
|
@@ -37,6 +38,7 @@ module SFML
|
|
|
37
38
|
C::Window.sfJoystick_getButtonCount(_id(joystick))
|
|
38
39
|
end
|
|
39
40
|
|
|
41
|
+
# `true` if has axis.
|
|
40
42
|
def has_axis?(joystick, axis)
|
|
41
43
|
C::Window.sfJoystick_hasAxis(_id(joystick), _axis_code(axis))
|
|
42
44
|
end
|
|
@@ -48,6 +50,7 @@ module SFML
|
|
|
48
50
|
C::Window.sfJoystick_getAxisPosition(_id(joystick), _axis_code(axis))
|
|
49
51
|
end
|
|
50
52
|
|
|
53
|
+
# `true` if button pressed.
|
|
51
54
|
def button_pressed?(joystick, button)
|
|
52
55
|
C::Window.sfJoystick_isButtonPressed(_id(joystick), Integer(button))
|
|
53
56
|
end
|
data/lib/sfml/window/sensor.rb
CHANGED
|
@@ -39,8 +39,10 @@ module SFML
|
|
|
39
39
|
C::Window.sfVideoMode_isValid(to_native)
|
|
40
40
|
end
|
|
41
41
|
|
|
42
|
+
# Returns the size.
|
|
42
43
|
def size = Vector2.new(@width, @height)
|
|
43
44
|
|
|
45
|
+
# String representation for debugging.
|
|
44
46
|
def to_s = "#<SFML::VideoMode #{@width}x#{@height}@#{@bits_per_pixel}>"
|
|
45
47
|
alias inspect to_s
|
|
46
48
|
|
data/lib/sfml/window/window.rb
CHANGED
|
@@ -43,6 +43,7 @@ module SFML
|
|
|
43
43
|
self.vsync = opts[:vsync] unless opts[:vsync].nil?
|
|
44
44
|
end
|
|
45
45
|
|
|
46
|
+
# `true` if open.
|
|
46
47
|
def open?
|
|
47
48
|
C::Window.sfWindow_isOpen(@handle)
|
|
48
49
|
end
|
|
@@ -71,6 +72,7 @@ module SFML
|
|
|
71
72
|
self
|
|
72
73
|
end
|
|
73
74
|
|
|
75
|
+
# Set the title.
|
|
74
76
|
def title=(value)
|
|
75
77
|
C::Window.sfWindow_setTitle(@handle, value.to_s)
|
|
76
78
|
end
|
|
@@ -80,6 +82,7 @@ module SFML
|
|
|
80
82
|
Vector2.new(v[:x], v[:y])
|
|
81
83
|
end
|
|
82
84
|
|
|
85
|
+
# Set the size.
|
|
83
86
|
def size=(value)
|
|
84
87
|
vec = value.is_a?(Vector2) ? value : Vector2.new(*value)
|
|
85
88
|
v = C::System::Vector2u.new
|
|
@@ -92,6 +95,7 @@ module SFML
|
|
|
92
95
|
Vector2.new(v[:x], v[:y])
|
|
93
96
|
end
|
|
94
97
|
|
|
98
|
+
# Set the position.
|
|
95
99
|
def position=(value)
|
|
96
100
|
vec = value.is_a?(Vector2) ? value : Vector2.new(*value)
|
|
97
101
|
v = C::System::Vector2i.new
|
|
@@ -99,18 +103,22 @@ module SFML
|
|
|
99
103
|
C::Window.sfWindow_setPosition(@handle, v)
|
|
100
104
|
end
|
|
101
105
|
|
|
106
|
+
# Set the visible.
|
|
102
107
|
def visible=(value)
|
|
103
108
|
C::Window.sfWindow_setVisible(@handle, value ? true : false)
|
|
104
109
|
end
|
|
105
110
|
|
|
111
|
+
# Set the framerate limit.
|
|
106
112
|
def framerate_limit=(value)
|
|
107
113
|
C::Window.sfWindow_setFramerateLimit(@handle, Integer(value))
|
|
108
114
|
end
|
|
109
115
|
|
|
116
|
+
# Set the vsync.
|
|
110
117
|
def vsync=(enabled)
|
|
111
118
|
C::Window.sfWindow_setVerticalSyncEnabled(@handle, enabled ? true : false)
|
|
112
119
|
end
|
|
113
120
|
|
|
121
|
+
# Set the key repeat enabled.
|
|
114
122
|
def key_repeat_enabled=(value)
|
|
115
123
|
C::Window.sfWindow_setKeyRepeatEnabled(@handle, value ? true : false)
|
|
116
124
|
end
|
|
@@ -119,6 +127,7 @@ module SFML
|
|
|
119
127
|
C::Window.sfWindow_requestFocus(@handle)
|
|
120
128
|
end
|
|
121
129
|
|
|
130
|
+
# `true` if focused.
|
|
122
131
|
def focused?
|
|
123
132
|
C::Window.sfWindow_hasFocus(@handle)
|
|
124
133
|
end
|
|
@@ -137,10 +146,12 @@ module SFML
|
|
|
137
146
|
@cursor = cursor # keep alive
|
|
138
147
|
end
|
|
139
148
|
|
|
149
|
+
# Set the cursor visible.
|
|
140
150
|
def cursor_visible=(visible)
|
|
141
151
|
C::Window.sfWindow_setMouseCursorVisible(@handle, visible ? true : false)
|
|
142
152
|
end
|
|
143
153
|
|
|
154
|
+
# Set the cursor grabbed.
|
|
144
155
|
def cursor_grabbed=(grabbed)
|
|
145
156
|
C::Window.sfWindow_setMouseCursorGrabbed(@handle, grabbed ? true : false)
|
|
146
157
|
end
|
|
@@ -187,6 +198,7 @@ module SFML
|
|
|
187
198
|
C::Window.sfWindow_setMinimumSize(@handle, _vec2u_or_nil(value))
|
|
188
199
|
end
|
|
189
200
|
|
|
201
|
+
# Set the maximum size.
|
|
190
202
|
def maximum_size=(value)
|
|
191
203
|
C::Window.sfWindow_setMaximumSize(@handle, _vec2u_or_nil(value))
|
|
192
204
|
end
|
data/ruby-sfml.gemspec
CHANGED
|
@@ -15,7 +15,7 @@ Gem::Specification.new do |spec|
|
|
|
15
15
|
spec.metadata["homepage_uri"] = spec.homepage
|
|
16
16
|
spec.metadata["source_code_uri"] = spec.homepage
|
|
17
17
|
spec.metadata["bug_tracker_uri"] = "#{spec.homepage}/issues"
|
|
18
|
-
spec.metadata["documentation_uri"] = "https://
|
|
18
|
+
spec.metadata["documentation_uri"] = "https://ruby-sfml-doc.netlify.app/"
|
|
19
19
|
spec.metadata["changelog_uri"] = "#{spec.homepage}/blob/main/CHANGELOG.md"
|
|
20
20
|
|
|
21
21
|
spec.files = Dir[
|
|
@@ -25,7 +25,11 @@ Gem::Specification.new do |spec|
|
|
|
25
25
|
"README.md",
|
|
26
26
|
"CHANGELOG.md",
|
|
27
27
|
"LICENSE.txt",
|
|
28
|
-
"ruby-sfml.gemspec"
|
|
28
|
+
"ruby-sfml.gemspec",
|
|
29
|
+
# Shipping .rdoc_options means the docs site (and anyone running
|
|
30
|
+
# `rdoc` against the unpacked gem) gets the project's preferred
|
|
31
|
+
# title, markup dialect, template, and exclude list automatically.
|
|
32
|
+
".rdoc_options"
|
|
29
33
|
]
|
|
30
34
|
spec.require_paths = ["lib"]
|
|
31
35
|
spec.extensions = ["ext/ruby-sfml/extconf.rb"]
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: ruby-sfml
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 3.0.0.
|
|
4
|
+
version: 3.0.0.7
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Mykhailo Melnyk
|
|
@@ -74,6 +74,7 @@ extensions:
|
|
|
74
74
|
- ext/ruby-sfml/extconf.rb
|
|
75
75
|
extra_rdoc_files: []
|
|
76
76
|
files:
|
|
77
|
+
- ".rdoc_options"
|
|
77
78
|
- CHANGELOG.md
|
|
78
79
|
- LICENSE.txt
|
|
79
80
|
- README.md
|
|
@@ -165,7 +166,7 @@ metadata:
|
|
|
165
166
|
homepage_uri: https://github.com/sOM2H/ruby-sfml
|
|
166
167
|
source_code_uri: https://github.com/sOM2H/ruby-sfml
|
|
167
168
|
bug_tracker_uri: https://github.com/sOM2H/ruby-sfml/issues
|
|
168
|
-
documentation_uri: https://
|
|
169
|
+
documentation_uri: https://ruby-sfml-doc.netlify.app/
|
|
169
170
|
changelog_uri: https://github.com/sOM2H/ruby-sfml/blob/main/CHANGELOG.md
|
|
170
171
|
rdoc_options: []
|
|
171
172
|
require_paths:
|