reflexion 0.4.2 → 0.5.0
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/application.cpp +2 -0
- data/.doc/ext/reflex/device.cpp +2 -1
- data/.doc/ext/reflex/ellipse_shape.cpp +2 -0
- data/.doc/ext/reflex/filter.cpp +2 -0
- data/.doc/ext/reflex/image_view.cpp +2 -0
- data/.doc/ext/reflex/line_shape.cpp +2 -0
- data/.doc/ext/reflex/midi.cpp +2 -1
- data/.doc/ext/reflex/polygon_shape.cpp +2 -0
- data/.doc/ext/reflex/rect_shape.cpp +2 -0
- data/.doc/ext/reflex/shape.cpp +1 -0
- data/.doc/ext/reflex/timer.cpp +1 -0
- data/.doc/ext/reflex/view.cpp +1 -0
- data/.doc/ext/reflex/window.cpp +2 -0
- data/CLAUDE.md +1 -1
- data/ChangeLog.md +11 -0
- data/Rakefile +3 -2
- data/Reflex.podspec +105 -0
- data/VERSION +1 -1
- data/ext/reflex/application.cpp +2 -0
- data/ext/reflex/device.cpp +2 -1
- data/ext/reflex/ellipse_shape.cpp +2 -0
- data/ext/reflex/filter.cpp +2 -0
- data/ext/reflex/image_view.cpp +2 -0
- data/ext/reflex/line_shape.cpp +2 -0
- data/ext/reflex/midi.cpp +2 -1
- data/ext/reflex/polygon_shape.cpp +2 -0
- data/ext/reflex/rect_shape.cpp +2 -0
- data/ext/reflex/shape.cpp +1 -0
- data/ext/reflex/timer.cpp +1 -0
- data/ext/reflex/view.cpp +1 -0
- data/ext/reflex/window.cpp +2 -0
- data/pod.rake +41 -0
- data/reflex.gemspec +3 -3
- data/src/body.cpp +93 -90
- data/src/body.h +7 -7
- data/src/fixture.cpp +301 -49
- data/src/fixture.h +55 -10
- data/src/osx/app_delegate.mm +6 -4
- data/src/shape.cpp +58 -51
- data/src/shape.h +0 -3
- data/src/timer.cpp +8 -10
- data/src/view.cpp +1 -0
- data/src/world.cpp +301 -128
- data/src/world.h +12 -21
- metadata +10 -8
data/src/shape.cpp
CHANGED
|
@@ -2,12 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
|
|
4
4
|
#include <assert.h>
|
|
5
|
-
#include <box2d/
|
|
6
|
-
#include <box2d/
|
|
7
|
-
#include <box2d/b2_circle_shape.h>
|
|
8
|
-
#include <box2d/b2_edge_shape.h>
|
|
9
|
-
#include <box2d/b2_chain_shape.h>
|
|
10
|
-
#include <box2d/b2_polygon_shape.h>
|
|
5
|
+
#include <box2d/box2d.h>
|
|
6
|
+
#include <box2d/collision.h>
|
|
11
7
|
#include <rays/polygon.h>
|
|
12
8
|
#include "reflex/exception.h"
|
|
13
9
|
#include "reflex/debug.h"
|
|
@@ -105,23 +101,25 @@ namespace Reflex
|
|
|
105
101
|
|
|
106
102
|
public:
|
|
107
103
|
|
|
108
|
-
FixtureBuilder (Shape* shape
|
|
104
|
+
FixtureBuilder (Shape* shape)
|
|
109
105
|
: shape(shape), head(NULL), tail(NULL)
|
|
110
106
|
{
|
|
111
107
|
assert(shape);
|
|
112
|
-
|
|
113
|
-
if (head) add(head);
|
|
114
108
|
}
|
|
115
109
|
|
|
116
|
-
void add (const
|
|
110
|
+
void add (const b2Circle& b2circle)
|
|
117
111
|
{
|
|
118
|
-
|
|
112
|
+
append(new Fixture(get_body(), b2circle, shape));
|
|
113
|
+
}
|
|
119
114
|
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
115
|
+
void add (const b2Polygon& b2polygon)
|
|
116
|
+
{
|
|
117
|
+
append(new Fixture(get_body(), b2polygon, shape));
|
|
118
|
+
}
|
|
123
119
|
|
|
124
|
-
|
|
120
|
+
void add (const b2Vec2* points, size_t size, bool loop)
|
|
121
|
+
{
|
|
122
|
+
append(new Fixture(get_body(), points, size, loop, shape));
|
|
125
123
|
}
|
|
126
124
|
|
|
127
125
|
Fixture* fixtures () const
|
|
@@ -135,6 +133,15 @@ namespace Reflex
|
|
|
135
133
|
|
|
136
134
|
Fixture *head, *tail;
|
|
137
135
|
|
|
136
|
+
Body* get_body ()
|
|
137
|
+
{
|
|
138
|
+
Body* body = View_get_body(shape->owner());
|
|
139
|
+
if (!body)
|
|
140
|
+
invalid_state_error(__FILE__, __LINE__);
|
|
141
|
+
|
|
142
|
+
return body;
|
|
143
|
+
}
|
|
144
|
+
|
|
138
145
|
void append (Fixture* fixture)
|
|
139
146
|
{
|
|
140
147
|
if (!fixture) return;
|
|
@@ -159,8 +166,11 @@ namespace Reflex
|
|
|
159
166
|
{
|
|
160
167
|
assert(shape);
|
|
161
168
|
|
|
162
|
-
|
|
163
|
-
|
|
169
|
+
b2Circle b2shape = {{0, 0}, 0};
|
|
170
|
+
|
|
171
|
+
FixtureBuilder builder(shape);
|
|
172
|
+
builder.add(b2shape);
|
|
173
|
+
return builder.fixtures();
|
|
164
174
|
}
|
|
165
175
|
|
|
166
176
|
static Fixture*
|
|
@@ -185,12 +195,11 @@ namespace Reflex
|
|
|
185
195
|
FixtureBuilder builder(shape);
|
|
186
196
|
for (size_t i = 0; i < b2points.size(); i += 3)
|
|
187
197
|
{
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
if (b2shape.m_count != 3)
|
|
198
|
+
b2Hull hull = b2ComputeHull(&b2points[i], 3);
|
|
199
|
+
if (hull.count != 3)
|
|
191
200
|
continue;// skip too small triangle
|
|
192
201
|
|
|
193
|
-
builder.add(&
|
|
202
|
+
builder.add(b2MakePolygon(&hull, 0));
|
|
194
203
|
}
|
|
195
204
|
|
|
196
205
|
return builder.fixtures();
|
|
@@ -203,24 +212,15 @@ namespace Reflex
|
|
|
203
212
|
{
|
|
204
213
|
assert(builder && buffer);
|
|
205
214
|
|
|
215
|
+
if (polyline.size() < 2)
|
|
216
|
+
return;
|
|
217
|
+
|
|
206
218
|
buffer->clear();
|
|
207
219
|
buffer->reserve(polyline.size());
|
|
208
220
|
for (const auto& point : polyline)
|
|
209
221
|
buffer->emplace_back(to_b2vec2(point, ppm));
|
|
210
222
|
|
|
211
|
-
|
|
212
|
-
if (polyline.loop())
|
|
213
|
-
b2shape.CreateLoop(&(*buffer)[0], (int32) buffer->size());
|
|
214
|
-
else
|
|
215
|
-
{
|
|
216
|
-
b2shape.CreateChain(
|
|
217
|
-
&(*buffer)[0],
|
|
218
|
-
(int32) buffer->size(),
|
|
219
|
-
(*buffer)[0],
|
|
220
|
-
(*buffer)[buffer->size() - 1]);
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
builder->add(&b2shape);
|
|
223
|
+
builder->add(buffer->data(), buffer->size(), polyline.loop());
|
|
224
224
|
}
|
|
225
225
|
|
|
226
226
|
static Fixture*
|
|
@@ -816,20 +816,22 @@ namespace Reflex
|
|
|
816
816
|
invalid_state_error(__FILE__, __LINE__);
|
|
817
817
|
|
|
818
818
|
float ppm = owner->meter2pixel();
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
819
|
+
float l = to_b2coord(frame.x, ppm);
|
|
820
|
+
float t = to_b2coord(frame.y, ppm);
|
|
821
|
+
float r = to_b2coord(frame.x + frame.w, ppm);
|
|
822
|
+
float b = to_b2coord(frame.y + frame.h, ppm);
|
|
823
823
|
b2Vec2 b2points[] = {{l, t}, {l, b}, {r, b}, {r, t}};
|
|
824
824
|
|
|
825
|
-
|
|
826
|
-
|
|
825
|
+
b2Hull hull = b2ComputeHull(&b2points[0], 4);
|
|
826
|
+
if (hull.count < 3)
|
|
827
|
+
return NULL;
|
|
827
828
|
|
|
828
|
-
|
|
829
|
+
FixtureBuilder builder(shape);
|
|
830
|
+
builder.add(b2MakePolygon(&hull, 0));
|
|
831
|
+
return builder.fixtures();
|
|
829
832
|
}
|
|
830
833
|
|
|
831
|
-
Fixture* create_rect_fixture_without_division (
|
|
832
|
-
Shape* shape, const Bounds& frame)
|
|
834
|
+
Fixture* create_rect_fixture_without_division (Shape* shape, const Bounds& frame)
|
|
833
835
|
{
|
|
834
836
|
assert(shape);
|
|
835
837
|
|
|
@@ -845,16 +847,19 @@ namespace Reflex
|
|
|
845
847
|
|
|
846
848
|
float ppm = owner->meter2pixel();
|
|
847
849
|
const Polyline& polyline = polygon[0];
|
|
848
|
-
assert(polyline
|
|
850
|
+
assert(polyline.size() <= 8);
|
|
849
851
|
|
|
850
852
|
b2Vec2 b2points[8];
|
|
851
853
|
for (size_t i = 0; i < polyline.size(); ++i)
|
|
852
854
|
b2points[i] = to_b2vec2(polyline[i], ppm);
|
|
853
855
|
|
|
854
|
-
|
|
855
|
-
|
|
856
|
+
b2Hull hull = b2ComputeHull(&b2points[0], (int32_t) polyline.size());
|
|
857
|
+
if (hull.count < 3)
|
|
858
|
+
return NULL;
|
|
856
859
|
|
|
857
|
-
|
|
860
|
+
FixtureBuilder builder(shape);
|
|
861
|
+
builder.add(b2MakePolygon(&hull, 0));
|
|
862
|
+
return builder.fixtures();
|
|
858
863
|
}
|
|
859
864
|
|
|
860
865
|
Polygon get_polygon_for_shape () const override
|
|
@@ -1049,11 +1054,13 @@ namespace Reflex
|
|
|
1049
1054
|
|
|
1050
1055
|
float ppm = owner->meter2pixel();
|
|
1051
1056
|
|
|
1052
|
-
|
|
1053
|
-
b2shape.
|
|
1054
|
-
b2shape.
|
|
1057
|
+
b2Circle b2shape;
|
|
1058
|
+
b2shape.center = to_b2vec2(frame.center(), ppm);
|
|
1059
|
+
b2shape.radius = to_b2coord(frame.width / 2, ppm);
|
|
1055
1060
|
|
|
1056
|
-
|
|
1061
|
+
FixtureBuilder builder(shape);
|
|
1062
|
+
builder.add(b2shape);
|
|
1063
|
+
return builder.fixtures();
|
|
1057
1064
|
}
|
|
1058
1065
|
|
|
1059
1066
|
Polygon get_polygon_for_shape () const override
|
data/src/shape.h
CHANGED
data/src/timer.cpp
CHANGED
|
@@ -16,20 +16,17 @@ namespace Reflex
|
|
|
16
16
|
struct Timer::Data
|
|
17
17
|
{
|
|
18
18
|
|
|
19
|
-
View
|
|
19
|
+
Xot::WeakRef<View> owner;
|
|
20
20
|
|
|
21
|
-
int id
|
|
21
|
+
int id = ID_INVALID;
|
|
22
22
|
|
|
23
|
-
|
|
23
|
+
int count = 1;
|
|
24
24
|
|
|
25
|
-
|
|
25
|
+
float interval = -1;
|
|
26
26
|
|
|
27
|
-
|
|
27
|
+
double next_time = -1;
|
|
28
28
|
|
|
29
|
-
|
|
30
|
-
: owner(NULL), id(ID_INVALID), count(1), interval(-1), next_time(-1)
|
|
31
|
-
{
|
|
32
|
-
}
|
|
29
|
+
SelectorPtr pselector;
|
|
33
30
|
|
|
34
31
|
Selector& selector ()
|
|
35
32
|
{
|
|
@@ -66,6 +63,7 @@ namespace Reflex
|
|
|
66
63
|
void
|
|
67
64
|
Timer::fire ()
|
|
68
65
|
{
|
|
66
|
+
if (!self->owner) return;
|
|
69
67
|
if (!*this)
|
|
70
68
|
invalid_state_error(__FILE__, __LINE__);
|
|
71
69
|
|
|
@@ -82,7 +80,7 @@ namespace Reflex
|
|
|
82
80
|
View*
|
|
83
81
|
Timer::owner () const
|
|
84
82
|
{
|
|
85
|
-
return self->owner;
|
|
83
|
+
return self->owner.get();
|
|
86
84
|
}
|
|
87
85
|
|
|
88
86
|
int
|