ray 0.0.0.pre2 → 0.0.1
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.
- data/.gitignore +1 -0
- data/.rspec +3 -0
- data/README.md +62 -0
- data/Rakefile +33 -23
- data/VERSION +1 -1
- data/ext/audio.c +473 -0
- data/ext/color.c +4 -4
- data/ext/event.c +25 -3
- data/ext/extconf.rb +35 -22
- data/ext/font.c +287 -0
- data/ext/image.c +682 -33
- data/ext/joystick.c +9 -9
- data/ext/ray.c +166 -55
- data/ext/ray.h +120 -9
- data/ext/ray_osx.m +161 -0
- data/ext/rect.c +31 -4
- data/lib/ray/audio.rb +52 -0
- data/lib/ray/color.rb +16 -0
- data/lib/ray/dsl.rb +1 -3
- data/lib/ray/dsl/event.rb +1 -39
- data/lib/ray/dsl/event_listener.rb +38 -0
- data/lib/ray/dsl/event_runner.rb +3 -1
- data/lib/ray/dsl/event_translator.rb +74 -8
- data/lib/ray/dsl/handler.rb +3 -33
- data/lib/ray/dsl/matcher.rb +129 -23
- data/lib/ray/font.rb +108 -0
- data/lib/ray/font_set.rb +37 -0
- data/lib/ray/game.rb +171 -34
- data/lib/ray/helper.rb +43 -5
- data/lib/ray/image.rb +90 -3
- data/lib/ray/image_set.rb +35 -0
- data/lib/ray/joystick.rb +30 -0
- data/lib/ray/music_set.rb +35 -0
- data/lib/ray/ray.rb +17 -9
- data/lib/ray/rect.rb +51 -0
- data/lib/ray/resource_set.rb +92 -0
- data/lib/ray/scene.rb +220 -51
- data/lib/ray/sound_set.rb +35 -0
- data/lib/ray/sprite.rb +184 -0
- data/psp/ext.c +4 -0
- data/samples/hello_world/hello.rb +35 -0
- data/samples/hello_world/hello_dsl.rb +24 -0
- data/samples/pong/pong.rb +128 -0
- data/samples/sokoban/level_1 +7 -0
- data/samples/sokoban/sokoban.rb +370 -0
- data/spec/ray/audio_spec.rb +146 -0
- data/spec/ray/color_spec.rb +13 -0
- data/spec/ray/event_spec.rb +57 -168
- data/spec/ray/font_spec.rb +93 -0
- data/spec/ray/image_set_spec.rb +48 -0
- data/spec/ray/image_spec.rb +130 -44
- data/spec/ray/joystick_spec.rb +13 -9
- data/spec/ray/matcher_spec.rb +32 -55
- data/spec/ray/ray_spec.rb +33 -31
- data/spec/ray/rect_spec.rb +80 -0
- data/spec/ray/resource_set_spec.rb +105 -0
- data/spec/ray/sprite_spec.rb +163 -0
- data/spec/res/VeraMono.ttf +0 -0
- data/spec/res/aqua2.bmp +0 -0
- data/spec/res/pop.wav +0 -0
- data/spec/spec.opts +4 -0
- data/spec/spec_helper.rb +8 -0
- data/yard_ext.rb +91 -0
- metadata +104 -38
- data/bin/ray +0 -5
- data/bin/ray_irb +0 -4
- data/ext/SDLMain.h +0 -17
- data/ext/SDLMain.m +0 -381
- data/lib/ray/config.rb +0 -84
- data/lib/ray/dsl/converter.rb +0 -65
- data/lib/ray/dsl/listener.rb +0 -30
- data/lib/ray/dsl/type.rb +0 -58
- data/spec/ray/config_spec.rb +0 -90
- data/spec/ray/conversion_spec.rb +0 -43
- data/spec/ray/type_spec.rb +0 -17
- data/spec_runner.rb +0 -27
@@ -0,0 +1,48 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
Ray.image_set(/^test:(red|green|blue)$/) do |col|
|
4
|
+
%w(red green blue).include?(col).should == true
|
5
|
+
Ray::Image.new(:w => 50, :h => 50).fill(Ray::Color.send(col))
|
6
|
+
end
|
7
|
+
|
8
|
+
describe Ray::ImageSet do
|
9
|
+
before :all do
|
10
|
+
Ray.init
|
11
|
+
end
|
12
|
+
|
13
|
+
describe ".[]" do
|
14
|
+
it "should return a new image" do
|
15
|
+
Ray::ImageSet["test:red"].should be_a(Ray::Image)
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should always return the same image" do
|
19
|
+
obj = Ray::ImageSet["test:green"]
|
20
|
+
obj.object_id.should == Ray::ImageSet["test:green"].object_id
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should allow to remove images from cache" do
|
25
|
+
obj = Ray::ImageSet["test:red"]
|
26
|
+
other = Ray::ImageSet["test:blue"]
|
27
|
+
Ray::ImageSet.delete_if { |name, img| name == "test:red" }
|
28
|
+
obj.object_id.should_not == Ray::ImageSet["test:red"].object_id
|
29
|
+
other.object_id.should == Ray::ImageSet["test:blue"].object_id
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should also use Ray::Image's cache" do
|
33
|
+
img = Ray::ImageSet[path_of("aqua.bmp")]
|
34
|
+
img.should == Ray::Image[path_of("aqua.bmp")]
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should also handle Ray::Image's cache" do
|
38
|
+
img = Ray::ImageSet[path_of("aqua.bmp")]
|
39
|
+
|
40
|
+
Ray::ImageSet.delete_if { |name, img| name == path_of("aqua.bmp") }
|
41
|
+
img.should_not == Ray::Image[path_of("aqua.bmp")]
|
42
|
+
img.should_not == Ray::ImageSet[path_of("aqua.bmp")]
|
43
|
+
end
|
44
|
+
|
45
|
+
after :all do
|
46
|
+
Ray.stop
|
47
|
+
end
|
48
|
+
end
|
data/spec/ray/image_spec.rb
CHANGED
@@ -1,76 +1,162 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
1
3
|
describe Ray::Image do
|
2
|
-
before :
|
4
|
+
before :all do
|
3
5
|
Ray.init
|
4
6
|
@win = Ray.create_window(:w => 100, :h => 100)
|
5
7
|
end
|
6
8
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
img.blit(:on => Ray::Color.new(10, 20, 30))
|
13
|
-
}.should raise_exception(TypeError)
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
context "when trying to use a non-rect as a position" do
|
18
|
-
it "should raise a type error" do
|
19
|
-
img = Ray::Image.new(:w => 50, :h => 50)
|
20
|
-
lambda {
|
21
|
-
img.blit(:from => Ray::Color.new(10, 20, 30), :on => @win)
|
22
|
-
}.should raise_exception(TypeError)
|
23
|
-
|
24
|
-
lambda {
|
25
|
-
img.blit(:on => @win, :at => Ray::Color.new(10, 20, 30))
|
26
|
-
}.should raise_exception(TypeError)
|
27
|
-
end
|
28
|
-
end
|
9
|
+
it "should raise a type error when blitting on something that isn't an image" do
|
10
|
+
img = Ray::Image.new(:w => 50, :h => 50)
|
11
|
+
lambda {
|
12
|
+
img.blit(:on => Ray::Color.new(10, 20, 30))
|
13
|
+
}.should raise_exception(TypeError)
|
29
14
|
end
|
30
15
|
|
31
16
|
describe "#initialize" do
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
}.should raise_exception(TypeError)
|
37
|
-
end
|
17
|
+
it "should raise a type error if the argument isn't a hash or a string " do
|
18
|
+
lambda {
|
19
|
+
Ray::Image.new(3)
|
20
|
+
}.should raise_exception(TypeError)
|
38
21
|
end
|
39
22
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
}.should_not raise_exception
|
45
|
-
end
|
23
|
+
it "should not raise an error when loading an existing image" do
|
24
|
+
lambda {
|
25
|
+
Ray::Image.new(path_of("aqua.bmp"))
|
26
|
+
}.should_not raise_exception
|
46
27
|
end
|
47
28
|
|
48
|
-
|
49
|
-
|
29
|
+
it "should raise an error when loading an unexisting file " do
|
30
|
+
lambda {
|
31
|
+
Ray::Image.new("does_not_exist.bmp")
|
32
|
+
}.should raise_exception
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should be able to load a file from an IO" do
|
36
|
+
File.open(path_of("aqua.bmp")) do |io|
|
50
37
|
lambda {
|
51
|
-
Ray::Image.new(
|
52
|
-
}.
|
38
|
+
img = Ray::Image.new(io)
|
39
|
+
}.should_not raise_exception
|
53
40
|
end
|
54
41
|
end
|
55
42
|
|
56
43
|
if Ray.has_image_support?
|
57
|
-
it "should be able to load other
|
44
|
+
it "should be able to load other kind of images" do
|
58
45
|
lambda {
|
59
46
|
Ray::Image.new(path_of("aqua.png"))
|
60
47
|
}.should_not raise_exception
|
61
48
|
end
|
62
49
|
|
63
|
-
|
64
|
-
|
50
|
+
it "should be able to load other kind of images from an IO" do
|
51
|
+
File.open(path_of("aqua.png")) do |io|
|
65
52
|
lambda {
|
66
|
-
Ray::Image.new(
|
53
|
+
Ray::Image.new(io)
|
67
54
|
}.should_not raise_exception
|
68
55
|
end
|
69
56
|
end
|
57
|
+
|
58
|
+
it "should load images even if the extension is incorrect" do
|
59
|
+
lambda {
|
60
|
+
Ray::Image.new(path_of("not_a_jpeg.jpeg"))
|
61
|
+
}.should_not raise_exception
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
describe ".[]" do
|
67
|
+
it "should return a new image" do
|
68
|
+
Ray::Image[path_of("aqua.bmp")].should be_a(Ray::Image)
|
69
|
+
end
|
70
|
+
|
71
|
+
it "should always return the same image" do
|
72
|
+
obj = Ray::Image[path_of("aqua2.bmp")]
|
73
|
+
obj.object_id.should == Ray::Image[path_of("aqua2.bmp")].object_id
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
describe "#==" do
|
78
|
+
it "should be true if the parameter uses the same surface" do
|
79
|
+
@win.should == Ray.screen
|
80
|
+
|
81
|
+
first = Ray::Image.new(:w => 10, :h => 10).fill(Ray::Color.red)
|
82
|
+
sec = Ray::Image.new(:w => 10, :h => 10).fill(Ray::Color.red)
|
83
|
+
|
84
|
+
first.should_not == sec
|
85
|
+
end
|
86
|
+
|
87
|
+
it "should not raise an exception for non-images" do
|
88
|
+
lambda {
|
89
|
+
@win == 3
|
90
|
+
}.should_not raise_exception
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
describe "#dup" do
|
95
|
+
it "should create a new surface" do
|
96
|
+
first = Ray::Image.new(:w => 10, :h => 10).fill(Ray::Color.red)
|
97
|
+
sec = first.dup
|
98
|
+
|
99
|
+
first.should_not == sec
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
describe "#[]" do
|
104
|
+
it "should return nil for pixels outside the image" do
|
105
|
+
Ray::Image.new(:w => 10, :h => 10)[10, 10].should be_nil
|
106
|
+
end
|
107
|
+
|
108
|
+
it "should return a color for pixels inside the image" do
|
109
|
+
Ray::Image.new(:w => 10, :h => 10)[5, 5].should be_a(Ray::Color)
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
describe "#[]=" do
|
114
|
+
it "should change the color of the pixel" do
|
115
|
+
img = Ray::Image.new(:w => 10, :h => 10)
|
116
|
+
img.lock { img[5, 5] = Ray::Color.new(10, 15, 20) }
|
117
|
+
|
118
|
+
col = img[5, 5]
|
119
|
+
col.r.should == 10
|
120
|
+
col.g.should == 15
|
121
|
+
col.b.should == 20
|
122
|
+
end
|
123
|
+
|
124
|
+
it "should raise an error for pixels outside the image" do
|
125
|
+
img = Ray::Image.new(:w => 10, :h => 10)
|
126
|
+
lambda {
|
127
|
+
img.lock { img[11, 11] = Ray::Color.new(10, 15, 20) }
|
128
|
+
}.should raise_exception
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
describe "#clip" do
|
133
|
+
it "should return the clipping rect if there are no arguments" do
|
134
|
+
img = Ray::Image.new(:w => 10, :h => 10)
|
135
|
+
img.clip.should == Ray::Rect.new(0, 0, 10, 10)
|
136
|
+
end
|
137
|
+
|
138
|
+
it "should change the clip rect when called with a rect" do
|
139
|
+
img = Ray::Image.new(:w => 10, :h => 10)
|
140
|
+
img.clip([5, 5, 3, 3])
|
141
|
+
img.clip.should == Ray::Rect.new(5, 5, 3, 3)
|
142
|
+
end
|
143
|
+
|
144
|
+
it "should return the new rect" do
|
145
|
+
img = Ray::Image.new(:w => 10, :h => 10)
|
146
|
+
img.clip([5, 5, 3, 3]).should == Ray::Rect.new(5, 5, 3, 3)
|
147
|
+
end
|
148
|
+
|
149
|
+
it "should change the clipping rect only within a block" do
|
150
|
+
img = Ray::Image.new(:w => 10, :h => 10)
|
151
|
+
img.clip([5, 5, 3, 3]) do
|
152
|
+
img.clip.should == Ray::Rect.new(5, 5, 3, 3)
|
153
|
+
end
|
154
|
+
|
155
|
+
img.clip.should == Ray::Rect.new(0, 0, 10, 10)
|
70
156
|
end
|
71
157
|
end
|
72
158
|
|
73
|
-
after :
|
159
|
+
after :all do
|
74
160
|
Ray.stop
|
75
161
|
end
|
76
162
|
end
|
data/spec/ray/joystick_spec.rb
CHANGED
@@ -1,17 +1,21 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
1
3
|
describe Ray::Joystick do
|
2
4
|
describe ".handle_event" do
|
3
|
-
|
4
|
-
|
5
|
+
before :all do
|
6
|
+
Ray.init
|
7
|
+
end
|
5
8
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
+
it "can be changed" do
|
10
|
+
Ray::Joystick.handle_event = true
|
11
|
+
Ray::Joystick.handle_event.should be_true
|
9
12
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
+
Ray::Joystick.handle_event = false
|
14
|
+
Ray::Joystick.handle_event.should be_false
|
15
|
+
end
|
13
16
|
|
14
|
-
|
17
|
+
after :all do
|
18
|
+
Ray.init
|
15
19
|
end
|
16
20
|
end
|
17
21
|
end
|
data/spec/ray/matcher_spec.rb
CHANGED
@@ -1,73 +1,50 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
1
3
|
describe Ray::Matchers do
|
2
|
-
|
3
|
-
|
4
|
-
Ray.describe_matcher(:
|
4
|
+
it "should add matchers as public methods" do
|
5
|
+
lambda {
|
6
|
+
Ray.describe_matcher(:awesome_matcher) do |reg|
|
5
7
|
lambda { |str| str =~ reg }
|
6
8
|
end
|
7
|
-
|
8
|
-
Ray::Matchers.
|
9
|
-
|
10
|
-
|
11
|
-
context "without a defined target" do
|
12
|
-
it "should create one operate on anything" do
|
13
|
-
Ray.describe_matcher(:foo_matcher) do |something|
|
14
|
-
lambda { |x| x == something }
|
15
|
-
end
|
16
|
-
|
17
|
-
obj = Object.new
|
18
|
-
obj.extend Ray::Matchers
|
19
|
-
|
20
|
-
obj.instance_eval do
|
21
|
-
matcher = foo_matcher("")
|
22
|
-
matcher.can_match_on?(Object).should == true
|
23
|
-
end
|
9
|
+
}.should change {
|
10
|
+
Ray::Matchers.instance_methods.any? do |i|
|
11
|
+
i == :awesome_matcher or i == "awesome_matcher"
|
24
12
|
end
|
25
|
-
|
13
|
+
}.from(false).to(true)
|
26
14
|
end
|
27
15
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
lambda { |str| str =~ reg }
|
32
|
-
end
|
16
|
+
it "should return a Ray::DSL::Matchers for defined matchers" do
|
17
|
+
Ray.describe_matcher(:match) do |reg|
|
18
|
+
lambda { |str| str =~ reg }
|
33
19
|
end
|
34
20
|
|
35
|
-
|
36
|
-
|
37
|
-
@obj.extend Ray::Matchers
|
38
|
-
end
|
21
|
+
@obj = Object.new
|
22
|
+
@obj.extend Ray::Matchers
|
39
23
|
|
40
|
-
|
41
|
-
@obj.instance_eval { match("foo") }.should be_a(Ray::DSL::Matcher)
|
42
|
-
end
|
24
|
+
@obj.instance_eval { match("foo") }.should be_a(Ray::DSL::Matcher)
|
43
25
|
end
|
44
|
-
end
|
45
26
|
|
46
|
-
describe
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
matcher.can_match_on?(Object).should be_false
|
27
|
+
describe "#where" do
|
28
|
+
it "should return a matcher matching if the block returns true" do
|
29
|
+
obj = Object.new
|
30
|
+
obj.extend Ray::Helper
|
51
31
|
|
52
|
-
|
53
|
-
|
54
|
-
|
32
|
+
res = 0
|
33
|
+
obj.instance_eval do
|
34
|
+
self.event_runner = Ray::DSL::EventRunner.new
|
55
35
|
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
end
|
61
|
-
end
|
36
|
+
on :foo, where { |x| x > 10 } do |x|
|
37
|
+
x.should > 10
|
38
|
+
res += 1
|
39
|
+
end
|
62
40
|
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
41
|
+
raise_event(:foo, 10)
|
42
|
+
raise_event(:foo, 15)
|
43
|
+
|
44
|
+
listener_runner.run
|
45
|
+
end
|
68
46
|
|
69
|
-
|
70
|
-
matcher.match?(Class.new(String).new).should be_true
|
47
|
+
res.should == 1
|
71
48
|
end
|
72
49
|
end
|
73
50
|
end
|
data/spec/ray/ray_spec.rb
CHANGED
@@ -1,51 +1,44 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
1
2
|
require 'rbconfig'
|
2
3
|
|
3
4
|
describe Ray do
|
4
5
|
describe ".create_window" do
|
5
|
-
|
6
|
-
|
7
|
-
Ray.init
|
6
|
+
it "should raise runtime error for invalid configurations" do
|
7
|
+
Ray.init
|
8
8
|
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
lambda {
|
10
|
+
Ray.create_window(:w => 100, :h => 100, :bpp => 1)
|
11
|
+
}.should raise_exception(RuntimeError)
|
12
12
|
|
13
|
-
|
14
|
-
end
|
13
|
+
Ray.stop
|
15
14
|
end
|
16
15
|
|
17
|
-
|
18
|
-
|
19
|
-
Ray.init
|
16
|
+
it "should create a window of the expected size for valid configurations" do
|
17
|
+
Ray.init
|
20
18
|
|
21
|
-
|
22
|
-
|
23
|
-
|
19
|
+
win = Ray.create_window(:w => 100, :h => 50)
|
20
|
+
win.width.should == 100
|
21
|
+
win.height.should == 50
|
24
22
|
|
25
|
-
|
26
|
-
|
27
|
-
|
23
|
+
win = Ray.create_window(:width => 50, :height => 100)
|
24
|
+
win.width.should == 50
|
25
|
+
win.height.should == 100
|
28
26
|
|
29
|
-
|
30
|
-
end
|
27
|
+
Ray.stop
|
31
28
|
end
|
32
29
|
end
|
33
30
|
|
34
31
|
describe ".can_use_mode?" do
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
Ray.stop
|
40
|
-
end
|
32
|
+
it "should return false for invalid configurations" do
|
33
|
+
Ray.init
|
34
|
+
Ray.can_use_mode?(:w => 100, :h => 100, :bpp => 1).should be_false
|
35
|
+
Ray.stop
|
41
36
|
end
|
42
37
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
Ray.stop
|
48
|
-
end
|
38
|
+
it "should return true for valid configurations" do
|
39
|
+
Ray.init
|
40
|
+
Ray.can_use_mode?(:w => 480, :h => 272).should be_true
|
41
|
+
Ray.stop
|
49
42
|
end
|
50
43
|
end
|
51
44
|
|
@@ -83,4 +76,13 @@ describe Ray do
|
|
83
76
|
|
84
77
|
after :all do Ray.stop end
|
85
78
|
end
|
79
|
+
|
80
|
+
describe ".init" do
|
81
|
+
it "should allow to pass a hash to add options" do
|
82
|
+
lambda {
|
83
|
+
Ray.init({})
|
84
|
+
Ray.stop
|
85
|
+
}.should_not raise_exception
|
86
|
+
end
|
87
|
+
end
|
86
88
|
end
|