Skip to content

Commit 53b0116

Browse files
author
Robot
committed
Generate sources (8315097)
1 parent 3f57c2d commit 53b0116

File tree

25 files changed

+797
-544
lines changed

25 files changed

+797
-544
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ This section defines two sets of step-by-step instructions to install *CrSFML* b
6464
- Easier installation.
6565
- Disadvantages:
6666
- Tied to a particular version of SFML.
67-
- Although sizes of SFML objects seem to always be of equal or smaller sizes than on Linux 64-bit (where the sources are generated), this is not completely guaranteed. So, in case of a mismatch, data may be written outside of the memory region allocated for an object.
67+
- Although sizes of SFML objects seem to always be of equal or smaller sizes than on Linux 64-bit with latest GCC (where the sources are generated), this is not completely guaranteed. So, in case of a mismatch, data may be written outside of the memory region allocated for an object.
6868

6969
### Install SFML
7070

examples/diagnostics.cr

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -94,13 +94,13 @@ def test_mouse()
9494
shape.point_count = 3
9595
shape.fill_color = SF.color(128, 0, 255)
9696
shape.position = m - {0, 4}
97-
shape[0] = SF.vector2(-8, 0)
98-
shape[1] = SF.vector2(8, 0)
99-
shape[2] = SF.vector2(0, -wheel_delta.y*5)
97+
shape[0] = SF.vector2f(-8, 0)
98+
shape[1] = SF.vector2f(8, 0)
99+
shape[2] = SF.vector2f(0, -wheel_delta.y*5)
100100
$window.draw shape
101-
shape[0] = SF.vector2(0, -8)
102-
shape[1] = SF.vector2(0, 8)
103-
shape[2] = SF.vector2(-wheel_delta.x*5, 0)
101+
shape[0] = SF.vector2f(0, -8)
102+
shape[1] = SF.vector2f(0, 8)
103+
shape[2] = SF.vector2f(-wheel_delta.x*5, 0)
104104
$window.draw shape
105105

106106
$window.display()
@@ -149,7 +149,7 @@ def test_controller()
149149
rescue
150150
delta = {0, button_pos.size - btn - 1}
151151
end
152-
shape.position = SF.vector2(400, 300) + SF.vector2(delta) * {30, 30}
152+
shape.position = SF.vector2(400, 300) + SF.vector2(*delta) * 30
153153
text.position = shape.position
154154
shape.fill_color = SF::Joystick.button_pressed?(js, btn) ? SF.color(255, 128, 0) : SF.color(0, 128, 0)
155155

@@ -182,7 +182,7 @@ def test_controller()
182182
any = true
183183
end
184184
next unless any
185-
shape.position = SF.vector2(400, 300) + SF.vector2(delta) * {30, 30} + {dx*0.3, dy*0.3}
185+
shape.position = SF.vector2(400, 300) + SF.vector2(*delta) * 30 + SF.vector2(dx, dy) * 0.3
186186

187187
$window.draw shape
188188
end
@@ -206,7 +206,7 @@ class Button < SF::RectangleShape
206206
super(SF.vector2(width, height))
207207
@text = SF::Text.new(message, $font, (height*0.8).to_i)
208208
self.fill_color = color
209-
@text.position = SF.vector2((width - @text.global_bounds.width) / 2, -height / 20)
209+
@text.position = SF.vector2(((width - @text.global_bounds.width) / 2).to_i, -height / 20)
210210
end
211211

212212
def draw(target, states : SF::RenderStates)
@@ -233,14 +233,18 @@ actions.each_key do |btn|
233233
y += h + h/2
234234
end
235235

236+
version_text = SF::Text.new("SFML v#{SF::SFML_VERSION}\nCrSFML v#{SF::VERSION}", $font, 20)
237+
version_text.origin = {0, version_text.local_bounds.height}
238+
version_text.position = {5, $window.size.y - 15}
239+
236240
while $window.open?
237241
while event = $window.poll_event()
238242
case event
239243
when SF::Event::Closed
240244
$window.close()
241245
when SF::Event::MouseButtonPressed
242246
actions.each_key do |btn|
243-
if btn.global_bounds.contains(event.x.to_f, event.y.to_f)
247+
if btn.global_bounds.contains?(event.x.to_f, event.y.to_f)
244248
actions[btn].call
245249
break
246250
end
@@ -252,5 +256,6 @@ while $window.open?
252256
actions.each_key do |btn|
253257
$window.draw(btn)
254258
end
259+
$window.draw(version_text)
255260
$window.display()
256261
end

examples/echo.cr

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,48 @@
11
require "crsfml"
22
require "crsfml/audio"
33

4-
$mutex = SF::Mutex.new()
5-
6-
$samples = Slice(Int16).new(1024*1024, 0i16)
7-
$count = 0
8-
9-
104
class MySoundRecorder < SF::SoundRecorder
5+
def initialize(@samples : Array(Int16), @mutex : SF::Mutex)
6+
super()
7+
end
118
def on_start()
129
true
1310
end
1411
def on_process_samples(samples)
15-
$mutex.lock
16-
samples.each do |x|
17-
$samples[$count] = x
18-
$count += 1
19-
end
20-
$mutex.unlock
12+
@mutex.lock
13+
@samples.concat(samples)
14+
@mutex.unlock
2115
true
2216
end
2317
def on_stop()
2418
end
2519
end
2620

2721
class MySoundStream < SF::SoundStream
22+
def initialize(@samples : Array(Int16), @mutex : SF::Mutex, *args)
23+
super(*args)
24+
@result = [] of Int16
25+
end
2826
def on_get_data()
29-
while $count == 0
27+
while @samples.empty?
3028
SF.sleep(SF.seconds(0.05))
3129
end
32-
$mutex.lock
33-
result = $samples.to_unsafe.to_slice($count)
34-
$count = 0
35-
$mutex.unlock
36-
result
30+
@mutex.lock
31+
@result.replace(@samples)
32+
@samples.clear
33+
@mutex.unlock
34+
@result.to_unsafe.to_slice(@result.size)
3735
end
3836
def on_seek(position)
3937
end
4038
end
4139

40+
samples = Array(Int16).new
41+
mutex = SF::Mutex.new()
4242

43-
sr = MySoundRecorder.new()
43+
sr = MySoundRecorder.new(samples, mutex)
4444
sr.start(44100)
45-
ss = MySoundStream.new(1, 44100)
45+
ss = MySoundStream.new(samples, mutex, 1, 44100)
4646
ss.play()
4747

4848
puts "Recording... Press Enter to stop"

examples/shader.cr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ text.position = {30, 20}
2424
text.color = SF::Color::Black
2525
wb_shader = SF::Shader.from_file("resources/shaders/wave.vert", "resources/shaders/blur.frag")
2626

27-
window = SF::RenderWindow.new(SF::VideoMode.new(800, 600), "SFML Shader", SF::Titlebar|SF::Close)
27+
window = SF::RenderWindow.new(SF::VideoMode.new(800, 600), "SFML Shader", SF::Style::Titlebar|SF::Style::Close)
2828
window.vertical_sync_enabled = true
2929

3030
scene = rand(2)

src/audio/lib.cr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ lib VoidCSFML
2727
fun soundsource_isrelativetolistener(self : Void*, result : Bool*)
2828
fun soundsource_getmindistance(self : Void*, result : LibC::Float*)
2929
fun soundsource_getattenuation(self : Void*, result : LibC::Float*)
30-
$soundstream_ongetdata_callback : Void*, Int16*, LibC::SizeT, Bool* ->
30+
$soundstream_ongetdata_callback : Void*, Int16**, LibC::SizeT*, Bool* ->
3131
$soundstream_onseek_callback : Void*, Void* ->
3232
fun soundstream_finalize(self : Void*)
3333
fun soundstream_play(self : Void*)

0 commit comments

Comments
 (0)