ruby-sfml 3.0.0.7 → 3.0.0.8
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/CHANGELOG.md +26 -4
- data/lib/sfml/app.rb +5 -0
- data/lib/sfml/assets.rb +26 -4
- data/lib/sfml/audio/sound.rb +1 -0
- data/lib/sfml/audio/sound_buffer.rb +1 -0
- data/lib/sfml/audio/sound_buffer_recorder.rb +3 -0
- data/lib/sfml/audio/sound_cone.rb +2 -0
- data/lib/sfml/audio/sound_recorder.rb +2 -0
- data/lib/sfml/audio/sound_stream.rb +1 -0
- data/lib/sfml/graphics/animation.rb +1 -0
- data/lib/sfml/graphics/blend_mode.rb +6 -0
- data/lib/sfml/graphics/circle_shape.rb +1 -0
- data/lib/sfml/graphics/color.rb +11 -0
- data/lib/sfml/graphics/convex_shape.rb +1 -0
- data/lib/sfml/graphics/font.rb +1 -0
- data/lib/sfml/graphics/image.rb +5 -0
- data/lib/sfml/graphics/particle_system.rb +2 -0
- data/lib/sfml/graphics/rectangle_shape.rb +1 -0
- data/lib/sfml/graphics/render_states.rb +3 -0
- data/lib/sfml/graphics/render_target.rb +4 -0
- data/lib/sfml/graphics/render_texture.rb +2 -0
- data/lib/sfml/graphics/render_window.rb +2 -0
- data/lib/sfml/graphics/shader.rb +4 -0
- data/lib/sfml/graphics/shape.rb +2 -0
- data/lib/sfml/graphics/shape_inspectable.rb +4 -0
- data/lib/sfml/graphics/sprite.rb +8 -0
- data/lib/sfml/graphics/sprite_sheet.rb +2 -0
- data/lib/sfml/graphics/stencil_mode.rb +4 -0
- data/lib/sfml/graphics/text.rb +3 -0
- data/lib/sfml/graphics/texture.rb +3 -0
- data/lib/sfml/graphics/texture_atlas.rb +2 -0
- data/lib/sfml/graphics/transform.rb +6 -0
- data/lib/sfml/graphics/transformable_object.rb +3 -0
- data/lib/sfml/graphics/vertex.rb +2 -0
- data/lib/sfml/graphics/vertex_array.rb +2 -0
- data/lib/sfml/graphics/vertex_buffer.rb +9 -0
- data/lib/sfml/graphics/view.rb +5 -0
- data/lib/sfml/keybindings.rb +1 -0
- data/lib/sfml/network/ftp.rb +2 -0
- data/lib/sfml/network/http.rb +11 -1
- data/lib/sfml/network/ip_address.rb +10 -0
- data/lib/sfml/network/packet.rb +2 -0
- data/lib/sfml/network/socket_selector.rb +5 -0
- data/lib/sfml/network/tcp_listener.rb +1 -0
- data/lib/sfml/network/tcp_socket.rb +3 -0
- data/lib/sfml/network/udp_socket.rb +4 -0
- data/lib/sfml/scene.rb +1 -0
- data/lib/sfml/system/clock.rb +10 -1
- data/lib/sfml/system/rect.rb +2 -0
- data/lib/sfml/system/time.rb +3 -0
- data/lib/sfml/system/vector2.rb +3 -0
- data/lib/sfml/system/vector3.rb +3 -0
- data/lib/sfml/version.rb +1 -1
- data/lib/sfml/window/clipboard.rb +1 -0
- data/lib/sfml/window/context_settings.rb +3 -0
- data/lib/sfml/window/cursor.rb +1 -0
- data/lib/sfml/window/event.rb +13 -1
- data/lib/sfml/window/joystick.rb +1 -0
- data/lib/sfml/window/keyboard.rb +7 -0
- data/lib/sfml/window/mouse.rb +2 -0
- data/lib/sfml/window/sensor.rb +5 -0
- data/lib/sfml/window/video_mode.rb +4 -0
- data/lib/sfml/window/window.rb +19 -1
- metadata +1 -1
|
@@ -27,12 +27,15 @@ module SFML
|
|
|
27
27
|
class StencilMode
|
|
28
28
|
# Order matches sfStencilComparison in CSFML 3.
|
|
29
29
|
COMPARISONS = %i[never less less_equal greater greater_equal equal not_equal always].freeze
|
|
30
|
+
# Comparison symbol → integer Hash.
|
|
30
31
|
COMPARISON_INDEX = COMPARISONS.each_with_index.to_h.freeze
|
|
31
32
|
|
|
32
33
|
# Order matches sfStencilUpdateOperation in CSFML 3.
|
|
33
34
|
OPERATIONS = %i[keep zero replace increment decrement invert].freeze
|
|
35
|
+
# Update-op symbol → integer Hash.
|
|
34
36
|
OPERATION_INDEX = OPERATIONS.each_with_index.to_h.freeze
|
|
35
37
|
|
|
38
|
+
# The comparison, update operation, reference, mask, only write mask components.
|
|
36
39
|
attr_reader :comparison, :update_operation, :reference, :mask, :only_write_mask
|
|
37
40
|
|
|
38
41
|
def initialize(comparison: :always, update_operation: :keep,
|
|
@@ -62,6 +65,7 @@ module SFML
|
|
|
62
65
|
# Returns the hash.
|
|
63
66
|
def hash = [comparison, update_operation, reference, mask, only_write_mask].hash
|
|
64
67
|
|
|
68
|
+
# Returns the to s.
|
|
65
69
|
def to_s
|
|
66
70
|
"StencilMode(#{comparison}, #{update_operation}, ref=#{reference}, " \
|
|
67
71
|
"mask=#{format('0x%08X', mask)}, only_write=#{only_write_mask})"
|
data/lib/sfml/graphics/text.rb
CHANGED
|
@@ -15,6 +15,7 @@ module SFML
|
|
|
15
15
|
include Graphics::Transformable
|
|
16
16
|
CSFML_PREFIX = :sfText
|
|
17
17
|
|
|
18
|
+
# Bitmask values for each style symbol.
|
|
18
19
|
STYLES = {
|
|
19
20
|
regular: 0,
|
|
20
21
|
bold: 1 << 0,
|
|
@@ -47,6 +48,7 @@ module SFML
|
|
|
47
48
|
self.scale = opts[:scale] if opts.key?(:scale)
|
|
48
49
|
end
|
|
49
50
|
|
|
51
|
+
# The font.
|
|
50
52
|
attr_reader :font
|
|
51
53
|
|
|
52
54
|
# Replace the font used to render this Text.
|
|
@@ -201,6 +203,7 @@ module SFML
|
|
|
201
203
|
Rect.from_native(C::Graphics.sfText_getGlobalBounds(@handle))
|
|
202
204
|
end
|
|
203
205
|
|
|
206
|
+
# Returns the draw on.
|
|
204
207
|
def draw_on(target, states_ptr = nil) # :nodoc:
|
|
205
208
|
target._draw_native(:Text, @handle, states_ptr)
|
|
206
209
|
end
|
|
@@ -116,6 +116,7 @@ module SFML
|
|
|
116
116
|
img
|
|
117
117
|
end
|
|
118
118
|
|
|
119
|
+
# Returns the size.
|
|
119
120
|
def size
|
|
120
121
|
Vector2.from_native(C::Graphics.sfTexture_getSize(@handle))
|
|
121
122
|
end
|
|
@@ -151,11 +152,13 @@ module SFML
|
|
|
151
152
|
# `SFML::Texture.unbind`.
|
|
152
153
|
COORDINATE_TYPES = {normalized: 0, pixels: 1}.freeze
|
|
153
154
|
|
|
155
|
+
# Returns the bind.
|
|
154
156
|
def bind(coord: :normalized)
|
|
155
157
|
raise ArgumentError, "coord must be :normalized or :pixels" unless COORDINATE_TYPES.key?(coord)
|
|
156
158
|
C::Graphics.sfTexture_bind(@handle, COORDINATE_TYPES[coord])
|
|
157
159
|
end
|
|
158
160
|
|
|
161
|
+
# Returns the self.
|
|
159
162
|
def self.unbind
|
|
160
163
|
C::Graphics.sfTexture_bind(nil, 0)
|
|
161
164
|
end
|
|
@@ -20,6 +20,7 @@ module SFML
|
|
|
20
20
|
# Frame lookups are tolerant of the `.png` extension — Aseprite
|
|
21
21
|
# exports `walk-0.png`, but you can write `atlas.region("walk-0")`.
|
|
22
22
|
class TextureAtlas
|
|
23
|
+
# File-extension regex for atlas image files.
|
|
23
24
|
IMAGE_EXTS = /\.(?:png|jpg|jpeg|bmp|tga|gif)\z/i
|
|
24
25
|
|
|
25
26
|
# @param json_path [String] path to the atlas JSON
|
|
@@ -46,6 +47,7 @@ module SFML
|
|
|
46
47
|
@source = source
|
|
47
48
|
end
|
|
48
49
|
|
|
50
|
+
# The texture, source components.
|
|
49
51
|
attr_reader :texture, :source
|
|
50
52
|
|
|
51
53
|
# Returns the frame names.
|
|
@@ -20,6 +20,8 @@ module SFML
|
|
|
20
20
|
# work with a fresh copy use `t.dup`. The CSFML constant for the
|
|
21
21
|
# identity is exposed via `Transform.identity`.
|
|
22
22
|
class Transform
|
|
23
|
+
# Build a fresh identity Transform. Compose with `#translate` /
|
|
24
|
+
# `#rotate` / `#scale`.
|
|
23
25
|
def initialize
|
|
24
26
|
@struct = C::Graphics::Transform.new
|
|
25
27
|
# Start as identity by copying CSFML's sfTransform_Identity.
|
|
@@ -27,6 +29,7 @@ module SFML
|
|
|
27
29
|
@struct.pointer.write_bytes(identity_bytes)
|
|
28
30
|
end
|
|
29
31
|
|
|
32
|
+
# Alias for `Transform.new` — reads better at call site.
|
|
30
33
|
def self.identity
|
|
31
34
|
new
|
|
32
35
|
end
|
|
@@ -42,6 +45,8 @@ module SFML
|
|
|
42
45
|
t
|
|
43
46
|
end
|
|
44
47
|
|
|
48
|
+
# Deep-copy hook — `t.dup` clones the underlying matrix, not just
|
|
49
|
+
# the pointer.
|
|
45
50
|
def initialize_dup(other)
|
|
46
51
|
super
|
|
47
52
|
@struct = C::Graphics::Transform.new
|
|
@@ -137,6 +142,7 @@ module SFML
|
|
|
137
142
|
|
|
138
143
|
private
|
|
139
144
|
|
|
145
|
+
# Returns the allocate new with.
|
|
140
146
|
def allocate_new_with(native_struct)
|
|
141
147
|
t = self.class.allocate
|
|
142
148
|
new_buf = C::Graphics::Transform.new
|
|
@@ -25,14 +25,17 @@ module SFML
|
|
|
25
25
|
self.scale = opts[:scale] if opts.key?(:scale)
|
|
26
26
|
end
|
|
27
27
|
|
|
28
|
+
# Returns the transform.
|
|
28
29
|
def transform
|
|
29
30
|
C::Graphics.sfTransformable_getTransform(@handle)
|
|
30
31
|
end
|
|
31
32
|
|
|
33
|
+
# Returns the inverse transform.
|
|
32
34
|
def inverse_transform
|
|
33
35
|
C::Graphics.sfTransformable_getInverseTransform(@handle)
|
|
34
36
|
end
|
|
35
37
|
|
|
38
|
+
# Returns the dup.
|
|
36
39
|
def dup
|
|
37
40
|
ptr = C::Graphics.sfTransformable_copy(@handle)
|
|
38
41
|
raise GraphicsError, "sfTransformable_copy returned NULL" if ptr.null?
|
data/lib/sfml/graphics/vertex.rb
CHANGED
|
@@ -7,6 +7,7 @@ module SFML
|
|
|
7
7
|
# SFML::Vertex.new([10, 20], color: SFML::Color.red)
|
|
8
8
|
# SFML::Vertex.new([10, 20], color: SFML::Color.red, tex_coords: [0, 0])
|
|
9
9
|
class Vertex
|
|
10
|
+
# The position, color, tex coords components.
|
|
10
11
|
attr_accessor :position, :color, :tex_coords
|
|
11
12
|
|
|
12
13
|
def initialize(position = Vector2.zero, color: Color::WHITE, tex_coords: Vector2.zero)
|
|
@@ -15,6 +16,7 @@ module SFML
|
|
|
15
16
|
@tex_coords = _coerce_vec2(tex_coords)
|
|
16
17
|
end
|
|
17
18
|
|
|
19
|
+
# Returns the to s.
|
|
18
20
|
def to_s
|
|
19
21
|
"Vertex(#{@position.x}, #{@position.y})"
|
|
20
22
|
end
|
|
@@ -21,6 +21,7 @@ module SFML
|
|
|
21
21
|
|
|
22
22
|
# Order matches sfPrimitiveType in CSFML/Graphics/PrimitiveType.h.
|
|
23
23
|
PRIMITIVE_TYPES = %i[points lines line_strip triangles triangle_strip triangle_fan].freeze
|
|
24
|
+
# Primitive symbol → integer index Hash.
|
|
24
25
|
PRIMITIVE_INDEX = PRIMITIVE_TYPES.each_with_index.to_h.freeze
|
|
25
26
|
|
|
26
27
|
# Build an empty VertexArray. `primitive_type` chooses how
|
|
@@ -123,6 +124,7 @@ module SFML
|
|
|
123
124
|
Rect.from_native(C::Graphics.sfVertexArray_getBounds(@handle))
|
|
124
125
|
end
|
|
125
126
|
|
|
127
|
+
# Returns the draw on.
|
|
126
128
|
def draw_on(target, states_ptr = nil) # :nodoc:
|
|
127
129
|
target._draw_native(:VertexArray, @handle, states_ptr)
|
|
128
130
|
end
|
|
@@ -21,12 +21,17 @@ module SFML
|
|
|
21
21
|
# `SFML::VertexBuffer.available?` returns false and you should
|
|
22
22
|
# fall back to `VertexArray`.
|
|
23
23
|
class VertexBuffer
|
|
24
|
+
# VBO usage hints in CSFML enum order.
|
|
24
25
|
USAGES = C::Graphics::VERTEX_BUFFER_USAGES
|
|
26
|
+
# Usage symbol → integer Hash.
|
|
25
27
|
USAGE_INDEX = USAGES.each_with_index.to_h.freeze
|
|
26
28
|
|
|
29
|
+
# Primitive type symbols in `sfPrimitiveType` order.
|
|
27
30
|
PRIMITIVE_TYPES = VertexArray::PRIMITIVE_TYPES
|
|
31
|
+
# Primitive symbol → integer index Hash.
|
|
28
32
|
PRIMITIVE_INDEX = VertexArray::PRIMITIVE_INDEX
|
|
29
33
|
|
|
34
|
+
# Returns the self.
|
|
30
35
|
def self.available?
|
|
31
36
|
C::Graphics.sfVertexBuffer_isAvailable
|
|
32
37
|
end
|
|
@@ -61,6 +66,7 @@ module SFML
|
|
|
61
66
|
alias size count
|
|
62
67
|
alias length count
|
|
63
68
|
|
|
69
|
+
# Returns the primitive type.
|
|
64
70
|
def primitive_type
|
|
65
71
|
PRIMITIVE_TYPES[C::Graphics.sfVertexBuffer_getPrimitiveType(@handle)] || :unknown
|
|
66
72
|
end
|
|
@@ -73,6 +79,7 @@ module SFML
|
|
|
73
79
|
C::Graphics.sfVertexBuffer_setPrimitiveType(@handle, idx)
|
|
74
80
|
end
|
|
75
81
|
|
|
82
|
+
# Returns the usage.
|
|
76
83
|
def usage
|
|
77
84
|
USAGES[C::Graphics.sfVertexBuffer_getUsage(@handle)] || :unknown
|
|
78
85
|
end
|
|
@@ -120,10 +127,12 @@ module SFML
|
|
|
120
127
|
self
|
|
121
128
|
end
|
|
122
129
|
|
|
130
|
+
# Returns the self.
|
|
123
131
|
def self.unbind
|
|
124
132
|
C::Graphics.sfVertexBuffer_bind(nil)
|
|
125
133
|
end
|
|
126
134
|
|
|
135
|
+
# Returns the draw on.
|
|
127
136
|
def draw_on(target, states_ptr = nil) # :nodoc:
|
|
128
137
|
target._draw_native(:VertexBuffer, @handle, states_ptr)
|
|
129
138
|
end
|
data/lib/sfml/graphics/view.rb
CHANGED
|
@@ -19,6 +19,8 @@ module SFML
|
|
|
19
19
|
#
|
|
20
20
|
# All coordinate inputs accept either a SFML::Vector2 or a [x, y] array.
|
|
21
21
|
class View
|
|
22
|
+
# Build a View. All four kwargs may be passed up-front or set
|
|
23
|
+
# later. `_handle:` is for internal wrapping of CSFML pointers.
|
|
22
24
|
def initialize(center: nil, size: nil, rotation: nil, viewport: nil, _handle: nil)
|
|
23
25
|
ptr = _handle || C::Graphics.sfView_create
|
|
24
26
|
raise GraphicsError, "sfView_create returned NULL" if ptr.null?
|
|
@@ -55,6 +57,7 @@ module SFML
|
|
|
55
57
|
new(_handle: copy)
|
|
56
58
|
end
|
|
57
59
|
|
|
60
|
+
# Centre point of the view in world coordinates.
|
|
58
61
|
def center
|
|
59
62
|
Vector2.from_native(C::Graphics.sfView_getCenter(@handle))
|
|
60
63
|
end
|
|
@@ -64,6 +67,7 @@ module SFML
|
|
|
64
67
|
C::Graphics.sfView_setCenter(@handle, _vec2(value).to_native_f)
|
|
65
68
|
end
|
|
66
69
|
|
|
70
|
+
# Visible area in world units (NOT pixels). Halving this zooms in.
|
|
67
71
|
def size
|
|
68
72
|
Vector2.from_native(C::Graphics.sfView_getSize(@handle))
|
|
69
73
|
end
|
|
@@ -73,6 +77,7 @@ module SFML
|
|
|
73
77
|
C::Graphics.sfView_setSize(@handle, _vec2(value).to_native_f)
|
|
74
78
|
end
|
|
75
79
|
|
|
80
|
+
# Rotation in degrees (counter-clockwise).
|
|
76
81
|
def rotation
|
|
77
82
|
C::Graphics.sfView_getRotation(@handle)
|
|
78
83
|
end
|
data/lib/sfml/keybindings.rb
CHANGED
|
@@ -10,6 +10,7 @@ module SFML
|
|
|
10
10
|
# so `class Sub < Parent; on_key :x, :foo; end` keeps the parent's
|
|
11
11
|
# other bindings while overriding (or adding) `:x`.
|
|
12
12
|
module Keybindings
|
|
13
|
+
# Returns the on key.
|
|
13
14
|
def on_key(code, target = nil, &block)
|
|
14
15
|
@key_handlers ||= {}
|
|
15
16
|
handler = block || target
|
data/lib/sfml/network/ftp.rb
CHANGED
|
@@ -16,7 +16,9 @@ module SFML
|
|
|
16
16
|
# for commands that return a path or a list). All responses expose
|
|
17
17
|
# `#ok?`, `#status` (Integer), `#status_symbol`, `#message`.
|
|
18
18
|
class Ftp
|
|
19
|
+
# Standard port for the protocol.
|
|
19
20
|
DEFAULT_PORT = 21
|
|
21
|
+
# Default per-call timeout.
|
|
20
22
|
DEFAULT_TIMEOUT = SFML::Time.zero
|
|
21
23
|
|
|
22
24
|
# FTP status codes mapped to symbols. The transport-error ones
|
data/lib/sfml/network/http.rb
CHANGED
|
@@ -20,9 +20,12 @@ module SFML
|
|
|
20
20
|
# http_version: [major, minor] (default [1, 0])
|
|
21
21
|
# timeout: SFML::Time or seconds (default 0 = no timeout)
|
|
22
22
|
class Http
|
|
23
|
+
# Default per-call timeout.
|
|
23
24
|
DEFAULT_TIMEOUT = SFML::Time.zero
|
|
24
25
|
DEFAULT_VERSION = [1, 0].freeze
|
|
25
26
|
|
|
27
|
+
# Build an HTTP client pinned to `host` (URL prefix). Pass
|
|
28
|
+
# `port: 0` to let CSFML pick the protocol's default port.
|
|
26
29
|
def initialize(host, port: 0)
|
|
27
30
|
ptr = C::Network.sfHttp_create
|
|
28
31
|
raise NetworkError, "sfHttp_create returned NULL" if ptr.null?
|
|
@@ -31,6 +34,8 @@ module SFML
|
|
|
31
34
|
C::Network.sfHttp_setHost(@handle, host.to_s, Integer(port))
|
|
32
35
|
end
|
|
33
36
|
|
|
37
|
+
# Send a request and wait for the response. See the class doc
|
|
38
|
+
# for all the kwargs.
|
|
34
39
|
def send_request(method: :get, uri: "/", fields: nil, body: nil,
|
|
35
40
|
http_version: DEFAULT_VERSION, timeout: DEFAULT_TIMEOUT)
|
|
36
41
|
request_ptr = C::Network.sfHttpRequest_create
|
|
@@ -78,10 +83,13 @@ module SFML
|
|
|
78
83
|
1000 => :invalid_response, 1001 => :connection_failed,
|
|
79
84
|
}.freeze
|
|
80
85
|
|
|
86
|
+
# Responses are created via `Http#send_request`, not directly.
|
|
81
87
|
def initialize
|
|
82
88
|
raise NoMethodError, "use SFML::Network::Http#send_request to create a Response"
|
|
83
89
|
end
|
|
84
90
|
|
|
91
|
+
# Numeric HTTP status code (200, 404, ...). Combine with
|
|
92
|
+
# `STATUS_NAMES` or use `#status_symbol`.
|
|
85
93
|
def status
|
|
86
94
|
C::Network.sfHttpResponse_getStatus(@handle)
|
|
87
95
|
end
|
|
@@ -92,10 +100,12 @@ module SFML
|
|
|
92
100
|
STATUS_NAMES[status] || status
|
|
93
101
|
end
|
|
94
102
|
|
|
95
|
-
#
|
|
103
|
+
# Response body as a Ruby String.
|
|
96
104
|
def body = C::Network.sfHttpResponse_getBody(@handle).to_s
|
|
105
|
+
# Look up a response header by name (case-insensitive in HTTP).
|
|
97
106
|
def field(name) = C::Network.sfHttpResponse_getField(@handle, name.to_s)
|
|
98
107
|
|
|
108
|
+
# HTTP version the server replied with, as `[major, minor]`.
|
|
99
109
|
def http_version
|
|
100
110
|
[
|
|
101
111
|
C::Network.sfHttpResponse_getMajorVersion(@handle),
|
|
@@ -10,14 +10,17 @@ module SFML
|
|
|
10
10
|
# SFML::Network::IpAddress::BROADCAST # 255.255.255.255
|
|
11
11
|
# SFML::Network::IpAddress.local # local network IP
|
|
12
12
|
class IpAddress
|
|
13
|
+
# Parse from a dotted-decimal string like `"192.168.1.42"`.
|
|
13
14
|
def self.from_string(s)
|
|
14
15
|
wrap(C::Network.sfIpAddress_fromString(s.to_s))
|
|
15
16
|
end
|
|
16
17
|
|
|
18
|
+
# Build from four octets: `from_bytes(192, 168, 1, 42)`.
|
|
17
19
|
def self.from_bytes(a, b, c, d)
|
|
18
20
|
wrap(C::Network.sfIpAddress_fromBytes(Integer(a), Integer(b), Integer(c), Integer(d)))
|
|
19
21
|
end
|
|
20
22
|
|
|
23
|
+
# Build from a 32-bit packed integer.
|
|
21
24
|
def self.from_integer(n)
|
|
22
25
|
wrap(C::Network.sfIpAddress_fromInteger(Integer(n)))
|
|
23
26
|
end
|
|
@@ -40,15 +43,18 @@ module SFML
|
|
|
40
43
|
ip.freeze
|
|
41
44
|
end
|
|
42
45
|
|
|
46
|
+
# Dotted-decimal string ("192.168.1.42").
|
|
43
47
|
def to_s
|
|
44
48
|
@struct[:address].to_ptr.read_string_to_null
|
|
45
49
|
end
|
|
46
50
|
alias inspect to_s
|
|
47
51
|
|
|
52
|
+
# Packed 32-bit Integer view of the address.
|
|
48
53
|
def to_i
|
|
49
54
|
C::Network.sfIpAddress_toInteger(@struct)
|
|
50
55
|
end
|
|
51
56
|
|
|
57
|
+
# Value equality — same dotted-decimal string.
|
|
52
58
|
def ==(other)
|
|
53
59
|
other.is_a?(IpAddress) && to_s == other.to_s
|
|
54
60
|
end
|
|
@@ -59,9 +65,13 @@ module SFML
|
|
|
59
65
|
# @!visibility private
|
|
60
66
|
attr_reader :struct
|
|
61
67
|
|
|
68
|
+
# The 0.0.0.0 / empty placeholder address.
|
|
62
69
|
NONE = wrap(C::Network.sfIpAddress_None)
|
|
70
|
+
# 0.0.0.0 — match any local interface.
|
|
63
71
|
ANY = wrap(C::Network.sfIpAddress_Any)
|
|
72
|
+
# 127.0.0.1 — local-only.
|
|
64
73
|
LOCALHOST = wrap(C::Network.sfIpAddress_LocalHost)
|
|
74
|
+
# 255.255.255.255 — broadcast on the local subnet.
|
|
65
75
|
BROADCAST = wrap(C::Network.sfIpAddress_Broadcast)
|
|
66
76
|
end
|
|
67
77
|
end
|
data/lib/sfml/network/packet.rb
CHANGED
|
@@ -27,6 +27,7 @@ module SFML
|
|
|
27
27
|
@handle = FFI::AutoPointer.new(ptr, C::Network.method(:sfPacket_destroy))
|
|
28
28
|
end
|
|
29
29
|
|
|
30
|
+
# Returns the clear.
|
|
30
31
|
def clear
|
|
31
32
|
C::Network.sfPacket_clear(@handle)
|
|
32
33
|
self
|
|
@@ -134,6 +135,7 @@ module SFML
|
|
|
134
135
|
buf.read_string.force_encoding(Encoding::UTF_8)
|
|
135
136
|
end
|
|
136
137
|
|
|
138
|
+
# Returns the dup.
|
|
137
139
|
def dup
|
|
138
140
|
ptr = C::Network.sfPacket_copy(@handle)
|
|
139
141
|
raise NetworkError, "sfPacket_copy returned NULL" if ptr.null?
|
|
@@ -24,6 +24,7 @@ module SFML
|
|
|
24
24
|
# objects; this binding exists for game code that's already using
|
|
25
25
|
# `SFML::Network::Tcp{Socket,Listener}` / `UdpSocket`.
|
|
26
26
|
class SocketSelector
|
|
27
|
+
# Create an empty selector. Use `#add` to register sockets.
|
|
27
28
|
def initialize
|
|
28
29
|
ptr = C::Network.sfSocketSelector_create
|
|
29
30
|
raise NetworkError, "sfSocketSelector_create returned NULL" if ptr.null?
|
|
@@ -31,6 +32,8 @@ module SFML
|
|
|
31
32
|
@handle = FFI::AutoPointer.new(ptr, C::Network.method(:sfSocketSelector_destroy))
|
|
32
33
|
end
|
|
33
34
|
|
|
35
|
+
# Register a `TcpListener`, `TcpSocket`, or `UdpSocket` for
|
|
36
|
+
# monitoring. Chainable.
|
|
34
37
|
def add(socket)
|
|
35
38
|
case socket
|
|
36
39
|
when TcpListener then C::Network.sfSocketSelector_addTcpListener(@handle, socket.handle)
|
|
@@ -43,6 +46,7 @@ module SFML
|
|
|
43
46
|
self
|
|
44
47
|
end
|
|
45
48
|
|
|
49
|
+
# Stop monitoring a previously-added socket. Chainable.
|
|
46
50
|
def remove(socket)
|
|
47
51
|
case socket
|
|
48
52
|
when TcpListener then C::Network.sfSocketSelector_removeTcpListener(@handle, socket.handle)
|
|
@@ -55,6 +59,7 @@ module SFML
|
|
|
55
59
|
self
|
|
56
60
|
end
|
|
57
61
|
|
|
62
|
+
# Unregister all sockets.
|
|
58
63
|
def clear
|
|
59
64
|
C::Network.sfSocketSelector_clear(@handle)
|
|
60
65
|
self
|
|
@@ -29,11 +29,13 @@ module SFML
|
|
|
29
29
|
C::Network::STATUSES[code]
|
|
30
30
|
end
|
|
31
31
|
|
|
32
|
+
# Returns the disconnect.
|
|
32
33
|
def disconnect
|
|
33
34
|
C::Network.sfTcpSocket_disconnect(@handle)
|
|
34
35
|
self
|
|
35
36
|
end
|
|
36
37
|
|
|
38
|
+
# Returns the send.
|
|
37
39
|
def send(data)
|
|
38
40
|
bytes = data.to_s
|
|
39
41
|
buf = FFI::MemoryPointer.new(:uint8, bytes.bytesize)
|
|
@@ -87,6 +89,7 @@ module SFML
|
|
|
87
89
|
# Returns the remote port.
|
|
88
90
|
def remote_port = C::Network.sfTcpSocket_getRemotePort(@handle)
|
|
89
91
|
|
|
92
|
+
# Returns the remote address.
|
|
90
93
|
def remote_address
|
|
91
94
|
IpAddress.wrap(C::Network.sfTcpSocket_getRemoteAddress(@handle))
|
|
92
95
|
end
|
|
@@ -9,6 +9,7 @@ module SFML
|
|
|
9
9
|
# sock.send("hello", to: SFML::Network::IpAddress::LOCALHOST, port: 9000)
|
|
10
10
|
# status, bytes, addr, port = sock.receive(max: 1024)
|
|
11
11
|
class UdpSocket
|
|
12
|
+
# Max UDP payload CSFML will send in one call.
|
|
12
13
|
MAX_DATAGRAM_SIZE = C::Network.sfUdpSocket_maxDatagramSize
|
|
13
14
|
|
|
14
15
|
def initialize
|
|
@@ -17,17 +18,20 @@ module SFML
|
|
|
17
18
|
@handle = FFI::AutoPointer.new(ptr, C::Network.method(:sfUdpSocket_destroy))
|
|
18
19
|
end
|
|
19
20
|
|
|
21
|
+
# Returns the bind.
|
|
20
22
|
def bind(port:, address: IpAddress::ANY)
|
|
21
23
|
addr = address.is_a?(IpAddress) ? address : IpAddress.from_string(address)
|
|
22
24
|
code = C::Network.sfUdpSocket_bind(@handle, Integer(port), addr.struct)
|
|
23
25
|
C::Network::STATUSES[code]
|
|
24
26
|
end
|
|
25
27
|
|
|
28
|
+
# Returns the unbind.
|
|
26
29
|
def unbind
|
|
27
30
|
C::Network.sfUdpSocket_unbind(@handle)
|
|
28
31
|
self
|
|
29
32
|
end
|
|
30
33
|
|
|
34
|
+
# Returns the send.
|
|
31
35
|
def send(data, to:, port:)
|
|
32
36
|
bytes = data.to_s
|
|
33
37
|
addr = to.is_a?(IpAddress) ? to : IpAddress.from_string(to)
|
data/lib/sfml/scene.rb
CHANGED
data/lib/sfml/system/clock.rb
CHANGED
|
@@ -6,36 +6,45 @@ module SFML
|
|
|
6
6
|
# puts clock.elapsed_time.as_seconds
|
|
7
7
|
# clock.restart # returns the elapsed time and resets to zero
|
|
8
8
|
class Clock
|
|
9
|
+
# Create a fresh clock — starts running at zero.
|
|
9
10
|
def initialize
|
|
10
11
|
ptr = C::System.sfClock_create
|
|
11
12
|
raise Error, "sfClock_create returned NULL" if ptr.null?
|
|
12
13
|
@handle = FFI::AutoPointer.new(ptr, C::System.method(:sfClock_destroy))
|
|
13
14
|
end
|
|
14
15
|
|
|
16
|
+
# Time elapsed since the clock was last started / restarted, as a
|
|
17
|
+
# `SFML::Time`. Aliased as `#elapsed`.
|
|
15
18
|
def elapsed_time
|
|
16
19
|
Time.from_native(C::System.sfClock_getElapsedTime(@handle))
|
|
17
20
|
end
|
|
18
21
|
alias elapsed elapsed_time
|
|
19
22
|
|
|
20
|
-
# `true` if
|
|
23
|
+
# `true` if the clock is currently ticking (not paused via `#stop`).
|
|
21
24
|
def running?
|
|
22
25
|
C::System.sfClock_isRunning(@handle)
|
|
23
26
|
end
|
|
24
27
|
|
|
28
|
+
# Resume after `#stop`. No-op if already running.
|
|
25
29
|
def start
|
|
26
30
|
C::System.sfClock_start(@handle)
|
|
27
31
|
self
|
|
28
32
|
end
|
|
29
33
|
|
|
34
|
+
# Pause the clock — `#elapsed_time` freezes until `#start`.
|
|
30
35
|
def stop
|
|
31
36
|
C::System.sfClock_stop(@handle)
|
|
32
37
|
self
|
|
33
38
|
end
|
|
34
39
|
|
|
40
|
+
# Atomic "read elapsed + reset to zero". Standard pattern for
|
|
41
|
+
# per-frame dt: `dt = clock.restart`.
|
|
35
42
|
def restart
|
|
36
43
|
Time.from_native(C::System.sfClock_restart(@handle))
|
|
37
44
|
end
|
|
38
45
|
|
|
46
|
+
# Reset to zero without affecting the running state. Returns the
|
|
47
|
+
# elapsed time before the reset.
|
|
39
48
|
def reset
|
|
40
49
|
Time.from_native(C::System.sfClock_reset(@handle))
|
|
41
50
|
end
|
data/lib/sfml/system/rect.rb
CHANGED
|
@@ -11,6 +11,7 @@ module SFML
|
|
|
11
11
|
#
|
|
12
12
|
# Used by Text#local_bounds, Text#global_bounds, Sprite#texture_rect, etc.
|
|
13
13
|
class Rect
|
|
14
|
+
# The position, size components.
|
|
14
15
|
attr_reader :position, :size
|
|
15
16
|
|
|
16
17
|
# `position` and `size` may each be a `Vector2` OR a `[x, y]` Array.
|
|
@@ -76,6 +77,7 @@ module SFML
|
|
|
76
77
|
def to_s = "Rect(x=#{x}, y=#{y}, w=#{width}, h=#{height})"
|
|
77
78
|
alias inspect to_s
|
|
78
79
|
|
|
80
|
+
# Returns the self.
|
|
79
81
|
def self.from_native(struct) # :nodoc:
|
|
80
82
|
new(
|
|
81
83
|
Vector2.new(struct[:position][:x], struct[:position][:y]),
|
data/lib/sfml/system/time.rb
CHANGED
|
@@ -13,6 +13,7 @@ module SFML
|
|
|
13
13
|
class Time
|
|
14
14
|
include Comparable
|
|
15
15
|
|
|
16
|
+
# The microseconds.
|
|
16
17
|
attr_reader :microseconds
|
|
17
18
|
|
|
18
19
|
# Build a Time from a Float of seconds.
|
|
@@ -57,10 +58,12 @@ module SFML
|
|
|
57
58
|
def to_s = "#<SFML::Time #{as_seconds}s>"
|
|
58
59
|
alias inspect to_s
|
|
59
60
|
|
|
61
|
+
# Returns the self.
|
|
60
62
|
def self.from_native(struct) # :nodoc:
|
|
61
63
|
new(struct[:microseconds])
|
|
62
64
|
end
|
|
63
65
|
|
|
66
|
+
# Returns the to native.
|
|
64
67
|
def to_native # :nodoc:
|
|
65
68
|
C::System::Time.new.tap { |t| t[:microseconds] = @microseconds }
|
|
66
69
|
end
|
data/lib/sfml/system/vector2.rb
CHANGED
|
@@ -7,6 +7,7 @@ module SFML
|
|
|
7
7
|
# v * 2 #=> Vector2(6, 8)
|
|
8
8
|
# x, y = v # destructures via to_a
|
|
9
9
|
class Vector2
|
|
10
|
+
# The X coordinate, Y coordinate components.
|
|
10
11
|
attr_reader :x, :y
|
|
11
12
|
|
|
12
13
|
# Compact constructor: `Vector2[3, 4]` reads naturally as a literal.
|
|
@@ -161,10 +162,12 @@ module SFML
|
|
|
161
162
|
def to_s = "Vector2(#{@x}, #{@y})"
|
|
162
163
|
alias inspect to_s
|
|
163
164
|
|
|
165
|
+
# Returns the self.
|
|
164
166
|
def self.from_native(struct) # :nodoc:
|
|
165
167
|
new(struct[:x], struct[:y])
|
|
166
168
|
end
|
|
167
169
|
|
|
170
|
+
# Returns the to native f.
|
|
168
171
|
def to_native_f # :nodoc:
|
|
169
172
|
C::System::Vector2f.new.tap { |v| v[:x] = @x; v[:y] = @y }
|
|
170
173
|
end
|
data/lib/sfml/system/vector3.rb
CHANGED
|
@@ -4,6 +4,7 @@ module SFML
|
|
|
4
4
|
# support. Used by the 3D-audio API (`Sound#position`, `Listener`,
|
|
5
5
|
# …) and as a back-end for `Image` size hints.
|
|
6
6
|
class Vector3
|
|
7
|
+
# The X coordinate, Y coordinate, Z coordinate components.
|
|
7
8
|
attr_reader :x, :y, :z
|
|
8
9
|
|
|
9
10
|
# Compact constructor: `Vector3[1, 2, 3]`.
|
|
@@ -148,10 +149,12 @@ module SFML
|
|
|
148
149
|
def to_s = "Vector3(#{@x}, #{@y}, #{@z})"
|
|
149
150
|
alias inspect to_s
|
|
150
151
|
|
|
152
|
+
# Returns the self.
|
|
151
153
|
def self.from_native(struct) # :nodoc:
|
|
152
154
|
new(struct[:x], struct[:y], struct[:z])
|
|
153
155
|
end
|
|
154
156
|
|
|
157
|
+
# Returns the to native f.
|
|
155
158
|
def to_native_f # :nodoc:
|
|
156
159
|
C::System::Vector3f.new.tap { |v| v[:x] = @x; v[:y] = @y; v[:z] = @z }
|
|
157
160
|
end
|
data/lib/sfml/version.rb
CHANGED
|
@@ -28,6 +28,7 @@ module SFML
|
|
|
28
28
|
debug: C::Window::ContextAttribute::DEBUG,
|
|
29
29
|
}.freeze
|
|
30
30
|
|
|
31
|
+
# The depth bits, stencil bits, antialiasing components.
|
|
31
32
|
attr_reader :depth_bits, :stencil_bits, :antialiasing,
|
|
32
33
|
:major_version, :minor_version, :attribute_flags,
|
|
33
34
|
:srgb_capable
|
|
@@ -64,6 +65,7 @@ module SFML
|
|
|
64
65
|
s
|
|
65
66
|
end
|
|
66
67
|
|
|
68
|
+
# Returns the self.
|
|
67
69
|
def self.from_native(struct)
|
|
68
70
|
attrs = ATTRIBUTE_FLAGS.find { |_, v| v == struct[:attribute_flags] }&.first || :default
|
|
69
71
|
new(
|
|
@@ -94,6 +96,7 @@ module SFML
|
|
|
94
96
|
@major_version, @minor_version, @attribute_flags,
|
|
95
97
|
@srgb_capable].hash
|
|
96
98
|
|
|
99
|
+
# Returns the to s.
|
|
97
100
|
def to_s
|
|
98
101
|
"ContextSettings(aa=#{@antialiasing}, depth=#{@depth_bits}, " \
|
|
99
102
|
"stencil=#{@stencil_bits}, gl=#{@major_version}.#{@minor_version})"
|
data/lib/sfml/window/cursor.rb
CHANGED
|
@@ -19,6 +19,7 @@ module SFML
|
|
|
19
19
|
size_top_left size_bottom_right size_bottom_left size_top_right
|
|
20
20
|
size_all cross help not_allowed
|
|
21
21
|
].freeze
|
|
22
|
+
# Type symbol → integer index Hash.
|
|
22
23
|
TYPE_INDEX = TYPES.each_with_index.to_h.freeze
|
|
23
24
|
|
|
24
25
|
# Build a cursor matching one of the OS-supplied shapes. Some types
|