reflexion 0.1.32 → 0.1.33
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/.doc/ext/reflex/shape.cpp +5 -31
- data/.doc/ext/reflex/view.cpp +8 -34
- data/.github/workflows/release-gem.yml +4 -1
- data/ChangeLog.md +7 -0
- data/Rakefile +5 -5
- data/VERSION +1 -1
- data/ext/reflex/extconf.rb +0 -1
- data/ext/reflex/shape.cpp +6 -35
- data/ext/reflex/view.cpp +15 -44
- data/include/reflex/ruby/application.h +3 -3
- data/include/reflex/ruby/event.h +27 -27
- data/include/reflex/ruby/filter.h +3 -3
- data/include/reflex/ruby/image_view.h +3 -3
- data/include/reflex/ruby/pointer.h +3 -3
- data/include/reflex/ruby/selector.h +3 -3
- data/include/reflex/ruby/shape.h +20 -11
- data/include/reflex/ruby/style.h +5 -5
- data/include/reflex/ruby/timer.h +3 -3
- data/include/reflex/ruby/view.h +12 -3
- data/include/reflex/ruby/window.h +3 -3
- data/include/reflex/shape.h +5 -11
- data/include/reflex/view.h +5 -11
- data/lib/reflex/fixture.rb +1 -2
- data/lib/reflex/shape.rb +2 -2
- data/lib/reflex/view.rb +1 -28
- data/reflex.gemspec +4 -4
- data/samples/reflexion/breakout.rb +1 -1
- data/src/body.cpp +2 -2
- data/src/fixture.cpp +8 -62
- data/src/fixture.h +0 -8
- data/src/shape.cpp +45 -60
- data/src/view.cpp +6 -34
- data/src/world.cpp +41 -10
- data/src/world.h +9 -7
- data/test/helper.rb +2 -1
- data/test/{test_reflex.rb → test_reflex_init.rb} +3 -3
- data/test/test_shape.rb +0 -22
- data/test/test_view.rb +0 -12
- metadata +13 -13
data/src/world.cpp
CHANGED
@@ -3,9 +3,9 @@
|
|
3
3
|
|
4
4
|
#include <assert.h>
|
5
5
|
#include <memory>
|
6
|
-
#include <
|
7
|
-
#include <
|
8
|
-
#include <
|
6
|
+
#include <box2d/b2_draw.h>
|
7
|
+
#include <box2d/b2_world.h>
|
8
|
+
#include <box2d/b2_contact.h>
|
9
9
|
#include "reflex/event.h"
|
10
10
|
#include "reflex/exception.h"
|
11
11
|
#include "shape.h"
|
@@ -80,7 +80,7 @@ namespace Reflex
|
|
80
80
|
}
|
81
81
|
|
82
82
|
void DrawCircle (
|
83
|
-
const b2Vec2& center,
|
83
|
+
const b2Vec2& center, float radius, const b2Color& color)
|
84
84
|
{
|
85
85
|
assert(painter);
|
86
86
|
|
@@ -90,7 +90,7 @@ namespace Reflex
|
|
90
90
|
}
|
91
91
|
|
92
92
|
void DrawSolidCircle (
|
93
|
-
const b2Vec2& center,
|
93
|
+
const b2Vec2& center, float radius, const b2Vec2& axis, const b2Color& color)
|
94
94
|
{
|
95
95
|
assert(painter);
|
96
96
|
|
@@ -109,6 +109,15 @@ namespace Reflex
|
|
109
109
|
painter->line(to_point(p1, ppm), to_point(p2, ppm));
|
110
110
|
}
|
111
111
|
|
112
|
+
void DrawPoint (const b2Vec2& center, float size, const b2Color& color)
|
113
|
+
{
|
114
|
+
assert(painter);
|
115
|
+
|
116
|
+
painter->set_fill(color.r, color.g, color.b, color.a * 0.5);
|
117
|
+
painter->no_stroke();
|
118
|
+
painter->ellipse(to_point(center, ppm), to_coord(size / 2, ppm));
|
119
|
+
}
|
120
|
+
|
112
121
|
void DrawTransform (const b2Transform& transform)
|
113
122
|
{
|
114
123
|
assert(painter);
|
@@ -147,11 +156,13 @@ namespace Reflex
|
|
147
156
|
self->ppm = pixels_per_meter;
|
148
157
|
|
149
158
|
self->b2world.SetContactListener(this);
|
159
|
+
self->b2world.SetContactFilter(this);
|
150
160
|
}
|
151
161
|
|
152
162
|
World::~World ()
|
153
163
|
{
|
154
164
|
self->b2world.SetContactListener(NULL);
|
165
|
+
self->b2world.SetContactFilter(NULL);
|
155
166
|
}
|
156
167
|
|
157
168
|
void
|
@@ -235,17 +246,37 @@ namespace Reflex
|
|
235
246
|
if (!self->debug_draw) return;
|
236
247
|
|
237
248
|
self->debug_draw->begin(painter);
|
238
|
-
self->b2world.
|
249
|
+
self->b2world.DebugDraw();
|
239
250
|
self->debug_draw->end();
|
240
251
|
}
|
241
252
|
|
253
|
+
bool
|
254
|
+
World::ShouldCollide (b2Fixture* f1, b2Fixture* f2)
|
255
|
+
{
|
256
|
+
Shape* s1 = (Shape*) f1->GetUserData().pointer;
|
257
|
+
Shape* s2 = (Shape*) f2->GetUserData().pointer;
|
258
|
+
if (!s1 || !s2)
|
259
|
+
return false;
|
260
|
+
|
261
|
+
View* v1 = s1->owner();
|
262
|
+
View* v2 = s2->owner();
|
263
|
+
if (!v1 || !v2 || !View_is_active(*v1) || !View_is_active(*v2))
|
264
|
+
return false;
|
265
|
+
|
266
|
+
return
|
267
|
+
s1->will_contact(s2) &&
|
268
|
+
s2->will_contact(s1) &&
|
269
|
+
v1->will_contact(v2) &&
|
270
|
+
v2->will_contact(v1);
|
271
|
+
}
|
272
|
+
|
242
273
|
void
|
243
274
|
World::BeginContact (b2Contact* contact)
|
244
275
|
{
|
245
|
-
Shape* s1 = (Shape*) contact->GetFixtureA()->GetUserData();
|
276
|
+
Shape* s1 = (Shape*) contact->GetFixtureA()->GetUserData().pointer;
|
246
277
|
if (!s1) return;
|
247
278
|
|
248
|
-
Shape* s2 = (Shape*) contact->GetFixtureB()->GetUserData();
|
279
|
+
Shape* s2 = (Shape*) contact->GetFixtureB()->GetUserData().pointer;
|
249
280
|
if (!s2) return;
|
250
281
|
|
251
282
|
if (!View_is_active(*s1->owner()) || !View_is_active(*s2->owner()))
|
@@ -259,10 +290,10 @@ namespace Reflex
|
|
259
290
|
void
|
260
291
|
World::EndContact (b2Contact* contact)
|
261
292
|
{
|
262
|
-
Shape* s1 = (Shape*) contact->GetFixtureA()->GetUserData();
|
293
|
+
Shape* s1 = (Shape*) contact->GetFixtureA()->GetUserData().pointer;
|
263
294
|
if (!s1) return;
|
264
295
|
|
265
|
-
Shape* s2 = (Shape*) contact->GetFixtureB()->GetUserData();
|
296
|
+
Shape* s2 = (Shape*) contact->GetFixtureB()->GetUserData().pointer;
|
266
297
|
if (!s2) return;
|
267
298
|
|
268
299
|
if (!View_is_active(*s1->owner()) || !View_is_active(*s2->owner()))
|
data/src/world.h
CHANGED
@@ -4,8 +4,8 @@
|
|
4
4
|
#define __REFLEX_SRC_WORLD_H__
|
5
5
|
|
6
6
|
|
7
|
-
#include <
|
8
|
-
#include <
|
7
|
+
#include <box2d/b2_math.h>
|
8
|
+
#include <box2d/b2_world_callbacks.h>
|
9
9
|
#include <xot/noncopyable.h>
|
10
10
|
#include <xot/pimpl.h>
|
11
11
|
#include <rays/point.h>
|
@@ -24,7 +24,7 @@ namespace Reflex
|
|
24
24
|
class Body;
|
25
25
|
|
26
26
|
|
27
|
-
class World : public Xot::NonCopyable, private b2ContactListener
|
27
|
+
class World : public Xot::NonCopyable, private b2ContactFilter, b2ContactListener
|
28
28
|
{
|
29
29
|
|
30
30
|
public:
|
@@ -64,15 +64,17 @@ namespace Reflex
|
|
64
64
|
|
65
65
|
protected:
|
66
66
|
|
67
|
-
virtual
|
67
|
+
virtual bool ShouldCollide (b2Fixture* f1, b2Fixture* f2) override;
|
68
68
|
|
69
|
-
virtual void
|
69
|
+
virtual void BeginContact (b2Contact* contact) override;
|
70
|
+
|
71
|
+
virtual void EndContact (b2Contact* contact) override;
|
70
72
|
|
71
73
|
};// World
|
72
74
|
|
73
75
|
|
74
76
|
template <typename T>
|
75
|
-
inline
|
77
|
+
inline float
|
76
78
|
to_b2coord (T t, float scale)
|
77
79
|
{
|
78
80
|
return t / scale;
|
@@ -97,7 +99,7 @@ namespace Reflex
|
|
97
99
|
}
|
98
100
|
|
99
101
|
inline coord
|
100
|
-
to_coord (
|
102
|
+
to_coord (float t, float scale)
|
101
103
|
{
|
102
104
|
return t * scale;
|
103
105
|
}
|
data/test/helper.rb
CHANGED
@@ -7,13 +7,13 @@ $REFLEX_NOAUTOINIT = true
|
|
7
7
|
require_relative 'helper'
|
8
8
|
|
9
9
|
|
10
|
-
class
|
10
|
+
class TestReflexInit < Test::Unit::TestCase
|
11
11
|
|
12
|
-
def test_init()
|
12
|
+
def test_init!()
|
13
13
|
assert_raise(Reflex::ReflexError) {Reflex.fin!}
|
14
14
|
assert Reflex.init!
|
15
15
|
assert_raise(Reflex::ReflexError) {Reflex.init!}
|
16
16
|
assert Reflex.fin!
|
17
17
|
end
|
18
18
|
|
19
|
-
end#
|
19
|
+
end# TestReflexInit
|
data/test/test_shape.rb
CHANGED
@@ -46,26 +46,4 @@ class TestShape < Test::Unit::TestCase
|
|
46
46
|
assert_equal false, s.sensor?
|
47
47
|
end
|
48
48
|
|
49
|
-
def test_category()
|
50
|
-
s = shape
|
51
|
-
assert_equal 0b1, s.category_bits
|
52
|
-
s.category_bits = 0b1010
|
53
|
-
assert_equal 0b1010, s.category_bits
|
54
|
-
s.category_bits |= 0b100
|
55
|
-
assert_equal 0b1110, s.category_bits
|
56
|
-
s.category_bits &= ~0b10
|
57
|
-
assert_equal 0b1100, s.category_bits
|
58
|
-
end
|
59
|
-
|
60
|
-
def test_collision()
|
61
|
-
s = shape
|
62
|
-
assert_equal 0xffff, s.collision_mask
|
63
|
-
s.collision_mask = 0b1010
|
64
|
-
assert_equal 0b1010, s.collision_mask
|
65
|
-
s.collision_mask |= 0b100
|
66
|
-
assert_equal 0b1110, s.collision_mask
|
67
|
-
s.collision_mask &= ~0b10
|
68
|
-
assert_equal 0b1100, s.collision_mask
|
69
|
-
end
|
70
|
-
|
71
49
|
end# TestShape
|
data/test/test_view.rb
CHANGED
@@ -285,16 +285,4 @@ class TestView < Test::Unit::TestCase
|
|
285
285
|
assert_equal false, v.sensor?
|
286
286
|
end
|
287
287
|
|
288
|
-
def test_category()
|
289
|
-
p, v = view, view
|
290
|
-
p.add v
|
291
|
-
assert_equal [:all], v.category
|
292
|
-
end
|
293
|
-
|
294
|
-
def test_collision()
|
295
|
-
p, v = view, view
|
296
|
-
p.add v
|
297
|
-
#assert_equal [:all], v.collision
|
298
|
-
end
|
299
|
-
|
300
288
|
end# TestView
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: reflexion
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.33
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- xordog
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-04-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: xot
|
@@ -16,56 +16,56 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 0.1.
|
19
|
+
version: 0.1.33
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 0.1.
|
26
|
+
version: 0.1.33
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rucy
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: 0.1.
|
33
|
+
version: 0.1.33
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: 0.1.
|
40
|
+
version: 0.1.33
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: beeps
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: 0.1.
|
47
|
+
version: 0.1.33
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: 0.1.
|
54
|
+
version: 0.1.33
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: rays
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
59
|
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: 0.1.
|
61
|
+
version: 0.1.33
|
62
62
|
type: :runtime
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: 0.1.
|
68
|
+
version: 0.1.33
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: rake
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -404,7 +404,7 @@ files:
|
|
404
404
|
- test/test_model_owner.rb
|
405
405
|
- test/test_pointer.rb
|
406
406
|
- test/test_pointer_event.rb
|
407
|
-
- test/
|
407
|
+
- test/test_reflex_init.rb
|
408
408
|
- test/test_scroll_event.rb
|
409
409
|
- test/test_selector.rb
|
410
410
|
- test/test_shape.rb
|
@@ -433,7 +433,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
433
433
|
- !ruby/object:Gem::Version
|
434
434
|
version: '0'
|
435
435
|
requirements: []
|
436
|
-
rubygems_version: 3.4.
|
436
|
+
rubygems_version: 3.4.10
|
437
437
|
signing_key:
|
438
438
|
specification_version: 4
|
439
439
|
summary: A Graphical User Interface Tool Kit.
|
@@ -452,7 +452,7 @@ test_files:
|
|
452
452
|
- test/test_model_owner.rb
|
453
453
|
- test/test_pointer.rb
|
454
454
|
- test/test_pointer_event.rb
|
455
|
-
- test/
|
455
|
+
- test/test_reflex_init.rb
|
456
456
|
- test/test_scroll_event.rb
|
457
457
|
- test/test_selector.rb
|
458
458
|
- test/test_shape.rb
|