reflexion 0.4.2 → 0.5.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/src/shape.cpp CHANGED
@@ -2,12 +2,8 @@
2
2
 
3
3
 
4
4
  #include <assert.h>
5
- #include <box2d/b2_body.h>
6
- #include <box2d/b2_fixture.h>
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, const b2Shape* head = NULL)
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 b2Shape* b2shape)
110
+ void add (const b2Circle& b2circle)
117
111
  {
118
- assert(b2shape);
112
+ append(new Fixture(get_body(), b2circle, shape));
113
+ }
119
114
 
120
- Body* body = View_get_body(shape->owner());
121
- if (!body)
122
- invalid_state_error(__FILE__, __LINE__);
115
+ void add (const b2Polygon& b2polygon)
116
+ {
117
+ append(new Fixture(get_body(), b2polygon, shape));
118
+ }
123
119
 
124
- append(new Fixture(body, b2shape, shape));
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
- b2CircleShape b2shape;
163
- return FixtureBuilder(shape, &b2shape).fixtures();
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
- b2PolygonShape b2shape;
189
- b2shape.Set(&b2points[i], 3);
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(&b2shape);
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
- b2ChainShape b2shape;
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
- coord l = to_b2coord(frame.x, ppm);
820
- coord t = to_b2coord(frame.y, ppm);
821
- coord r = to_b2coord(frame.x + frame.w, ppm);
822
- coord b = to_b2coord(frame.x + frame.h, ppm);
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
- b2PolygonShape b2shape;
826
- b2shape.Set(&b2points[0], 4);
825
+ b2Hull hull = b2ComputeHull(&b2points[0], 4);
826
+ if (hull.count < 3)
827
+ return NULL;
827
828
 
828
- return FixtureBuilder(shape, &b2shape).fixtures();
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[0].size() <= 8);
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
- b2PolygonShape b2shape;
855
- b2shape.Set(&b2points[0], (int32) polyline.size());
856
+ b2Hull hull = b2ComputeHull(&b2points[0], (int32_t) polyline.size());
857
+ if (hull.count < 3)
858
+ return NULL;
856
859
 
857
- return FixtureBuilder(shape, &b2shape).fixtures();
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
- b2CircleShape b2shape;
1053
- b2shape.m_p = to_b2vec2(frame.center(), ppm);
1054
- b2shape.m_radius = to_b2coord(frame.width / 2, ppm);
1057
+ b2Circle b2shape;
1058
+ b2shape.center = to_b2vec2(frame.center(), ppm);
1059
+ b2shape.radius = to_b2coord(frame.width / 2, ppm);
1055
1060
 
1056
- return FixtureBuilder(shape, &b2shape).fixtures();
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
@@ -8,9 +8,6 @@
8
8
  #include "reflex/shape.h"
9
9
 
10
10
 
11
- class b2Shape;
12
-
13
-
14
11
  namespace Reflex
15
12
  {
16
13
 
data/src/timer.cpp CHANGED
@@ -16,20 +16,17 @@ namespace Reflex
16
16
  struct Timer::Data
17
17
  {
18
18
 
19
- View* owner;
19
+ Xot::WeakRef<View> owner;
20
20
 
21
- int id, count;
21
+ int id = ID_INVALID;
22
22
 
23
- float interval;
23
+ int count = 1;
24
24
 
25
- double next_time;
25
+ float interval = -1;
26
26
 
27
- SelectorPtr pselector;
27
+ double next_time = -1;
28
28
 
29
- Data ()
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
data/src/view.cpp CHANGED
@@ -318,6 +318,7 @@ namespace Reflex
318
318
  clear_walls(view);
319
319
 
320
320
  View* wall = new View(WALL_NAME);
321
+ wall->set_shape(NULL);
321
322
  wall->add_shape(new WallShape(WallShape::ALL));
322
323
  wall->set_static();
323
324