reflexion 0.1.12 → 0.1.13
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 +5 -5
- data/.doc/ext/reflex/application.cpp +9 -5
- data/.doc/ext/reflex/capture_event.cpp +0 -4
- data/.doc/ext/reflex/contact_event.cpp +17 -10
- data/.doc/ext/reflex/draw_event.cpp +1 -5
- data/.doc/ext/reflex/ellipse_shape.cpp +51 -24
- data/.doc/ext/reflex/event.cpp +0 -4
- data/.doc/ext/reflex/filter.cpp +81 -0
- data/.doc/ext/reflex/focus_event.cpp +9 -13
- data/.doc/ext/reflex/frame_event.cpp +40 -6
- data/.doc/ext/reflex/image_view.cpp +1 -10
- data/.doc/ext/reflex/key_event.cpp +2 -6
- data/.doc/ext/reflex/line_shape.cpp +99 -0
- data/.doc/ext/reflex/motion_event.cpp +75 -0
- data/.doc/ext/reflex/native.cpp +18 -18
- data/.doc/ext/reflex/pointer_event.cpp +5 -11
- data/.doc/ext/reflex/polygon_shape.cpp +65 -0
- data/.doc/ext/reflex/rect_shape.cpp +102 -23
- data/.doc/ext/reflex/reflex.cpp +21 -2
- data/.doc/ext/reflex/scroll_event.cpp +0 -6
- data/.doc/ext/reflex/selector.cpp +43 -15
- data/.doc/ext/reflex/shape.cpp +211 -0
- data/.doc/ext/reflex/style.cpp +359 -185
- data/.doc/ext/reflex/style_length.cpp +163 -35
- data/.doc/ext/reflex/timer.cpp +101 -0
- data/.doc/ext/reflex/timer_event.cpp +123 -0
- data/.doc/ext/reflex/update_event.cpp +11 -6
- data/.doc/ext/reflex/view.cpp +548 -144
- data/.doc/ext/reflex/wheel_event.cpp +0 -22
- data/.doc/ext/reflex/window.cpp +7 -15
- data/README.md +1 -1
- data/Rakefile +14 -12
- data/VERSION +1 -1
- data/ext/reflex/application.cpp +10 -5
- data/ext/reflex/capture_event.cpp +1 -5
- data/ext/reflex/contact_event.cpp +19 -11
- data/ext/reflex/defs.h +5 -2
- data/ext/reflex/draw_event.cpp +2 -6
- data/ext/reflex/ellipse_shape.cpp +56 -25
- data/ext/reflex/event.cpp +0 -4
- data/ext/reflex/extconf.rb +1 -2
- data/ext/reflex/filter.cpp +86 -0
- data/ext/reflex/focus_event.cpp +11 -15
- data/ext/reflex/frame_event.cpp +46 -7
- data/ext/reflex/image_view.cpp +1 -10
- data/ext/reflex/key_event.cpp +3 -7
- data/ext/reflex/line_shape.cpp +104 -0
- data/ext/reflex/motion_event.cpp +79 -0
- data/ext/reflex/native.cpp +18 -18
- data/ext/reflex/pointer_event.cpp +6 -12
- data/ext/reflex/polygon_shape.cpp +68 -0
- data/ext/reflex/rect_shape.cpp +113 -24
- data/ext/reflex/reflex.cpp +21 -2
- data/ext/reflex/scroll_event.cpp +1 -7
- data/ext/reflex/selector.cpp +46 -16
- data/ext/reflex/selector.h +130 -0
- data/ext/reflex/shape.cpp +231 -0
- data/ext/reflex/style.cpp +363 -192
- data/ext/reflex/style_length.cpp +164 -37
- data/ext/reflex/timer.cpp +108 -0
- data/ext/reflex/timer_event.cpp +133 -0
- data/ext/reflex/update_event.cpp +13 -7
- data/ext/reflex/view.cpp +594 -150
- data/ext/reflex/wheel_event.cpp +1 -25
- data/ext/reflex/window.cpp +7 -15
- data/include/reflex/application.h +2 -0
- data/include/reflex/debug.h +22 -0
- data/include/reflex/defs.h +45 -0
- data/include/reflex/event.h +60 -16
- data/include/reflex/exception.h +9 -0
- data/include/reflex/filter.h +56 -0
- data/include/reflex/image_view.h +1 -1
- data/include/reflex/ruby/application.h +17 -9
- data/include/reflex/ruby/event.h +22 -0
- data/include/reflex/ruby/filter.h +69 -0
- data/include/reflex/ruby/selector.h +1 -1
- data/include/reflex/ruby/shape.h +140 -0
- data/include/reflex/ruby/style.h +1 -1
- data/include/reflex/ruby/timer.h +69 -0
- data/include/reflex/ruby/view.h +43 -76
- data/include/reflex/ruby/window.h +17 -32
- data/include/reflex/ruby.h +6 -4
- data/include/reflex/selector.h +54 -2
- data/include/reflex/shape.h +211 -0
- data/include/reflex/style.h +111 -77
- data/include/reflex/timer.h +73 -0
- data/include/reflex/view.h +181 -59
- data/include/reflex/window.h +4 -3
- data/include/reflex.h +5 -4
- data/lib/reflex/application.rb +6 -3
- data/lib/reflex/button.rb +2 -2
- data/lib/reflex/capture_event.rb +7 -6
- data/lib/reflex/contact_event.rb +10 -12
- data/lib/reflex/draw_event.rb +6 -1
- data/lib/reflex/ellipse_shape.rb +27 -0
- data/lib/reflex/filter.rb +18 -0
- data/lib/reflex/fixture.rb +4 -0
- data/lib/reflex/focus_event.rb +10 -12
- data/lib/reflex/frame_event.rb +1 -1
- data/lib/reflex/helper.rb +17 -29
- data/lib/reflex/key_event.rb +13 -11
- data/lib/reflex/line_shape.rb +18 -0
- data/lib/reflex/{texture.rb → matrix.rb} +2 -2
- data/lib/reflex/module.rb +4 -19
- data/lib/reflex/pointer_event.rb +26 -37
- data/lib/reflex/polygon.rb +14 -0
- data/lib/reflex/polygon_shape.rb +23 -0
- data/lib/reflex/polyline.rb +13 -0
- data/lib/reflex/rect_shape.rb +20 -0
- data/lib/reflex/reflex.rb +1 -3
- data/lib/reflex/scroll_event.rb +1 -1
- data/lib/reflex/selector.rb +2 -2
- data/lib/reflex/shape.rb +62 -0
- data/lib/reflex/style.rb +78 -11
- data/lib/reflex/style_length.rb +0 -11
- data/lib/reflex/text_view.rb +7 -24
- data/lib/reflex/timer.rb +30 -0
- data/lib/reflex/timer_event.rb +29 -0
- data/lib/reflex/update_event.rb +1 -1
- data/lib/reflex/view.rb +127 -32
- data/lib/reflex/wheel_event.rb +9 -1
- data/lib/reflex/window.rb +29 -9
- data/lib/reflex.rb +11 -5
- data/lib/reflexion.rb +23 -7
- data/reflex.gemspec +8 -10
- data/samples/bats.rb +4 -4
- data/samples/fans.rb +1 -1
- data/samples/fps.rb +5 -3
- data/samples/hello.rb +4 -6
- data/samples/image.rb +5 -4
- data/samples/ios/hello/hello.xcodeproj/project.pbxproj +0 -2
- data/samples/layout.rb +16 -7
- data/samples/model.rb +10 -7
- data/samples/physics.rb +22 -20
- data/samples/reflexion/breakout.rb +4 -5
- data/samples/reflexion/hello.rb +2 -2
- data/samples/reflexion/jump_action.rb +191 -0
- data/samples/reflexion/noise.rb +23 -0
- data/samples/reflexion/paint.rb +7 -6
- data/samples/reflexion/physics.rb +15 -8
- data/samples/reflexion/pulse.rb +24 -10
- data/samples/shader.rb +8 -6
- data/samples/shapes.rb +63 -14
- data/samples/tree.rb +9 -10
- data/samples/views.rb +3 -3
- data/samples/visuals.rb +2 -5
- data/src/body.cpp +146 -345
- data/src/body.h +91 -0
- data/src/event.cpp +66 -16
- data/src/exception.cpp +13 -3
- data/src/filter.cpp +76 -0
- data/src/fixture.cpp +164 -39
- data/src/fixture.h +85 -0
- data/src/image_view.cpp +4 -4
- data/src/ios/app_delegate.h +5 -10
- data/src/ios/app_delegate.mm +79 -41
- data/src/ios/application.h +32 -0
- data/src/ios/application.mm +35 -25
- data/src/ios/event.mm +8 -4
- data/src/ios/reflex.mm +0 -7
- data/src/ios/view_controller.h +33 -0
- data/src/ios/view_controller.mm +436 -0
- data/src/ios/window.h +40 -0
- data/src/ios/window.mm +59 -250
- data/src/osx/app_delegate.h +5 -10
- data/src/osx/app_delegate.mm +52 -55
- data/src/osx/application.h +32 -0
- data/src/osx/application.mm +44 -39
- data/src/osx/native_window.h +0 -15
- data/src/osx/native_window.mm +131 -115
- data/src/osx/opengl_view.h +0 -2
- data/src/osx/opengl_view.mm +12 -3
- data/src/osx/reflex.mm +0 -9
- data/src/osx/window.h +42 -0
- data/src/osx/window.mm +45 -252
- data/src/selector.cpp +232 -7
- data/src/selector.h +52 -0
- data/src/shape.cpp +1191 -0
- data/src/shape.h +61 -0
- data/src/style.cpp +571 -374
- data/src/style.h +39 -0
- data/src/timer.cpp +291 -0
- data/src/timer.h +55 -0
- data/src/view.cpp +1624 -984
- data/src/view.h +56 -0
- data/src/win32/window.cpp +3 -4
- data/src/window.cpp +275 -20
- data/src/window.h +92 -0
- data/src/world.cpp +112 -111
- data/src/world.h +34 -53
- data/task/box2d.rake +31 -10
- data/test/test_capture_event.rb +8 -6
- data/test/test_pointer_event.rb +85 -0
- data/test/test_selector.rb +1 -1
- data/test/test_shape.rb +71 -0
- data/test/test_style.rb +77 -11
- data/test/test_style_length.rb +42 -13
- data/test/test_view.rb +138 -14
- metadata +109 -210
- data/.doc/ext/reflex/arc_shape.cpp +0 -89
- data/.doc/ext/reflex/body.cpp +0 -299
- data/.doc/ext/reflex/fixture.cpp +0 -101
- data/.doc/ext/reflex/shape_view.cpp +0 -153
- data/ext/reflex/arc_shape.cpp +0 -94
- data/ext/reflex/body.cpp +0 -328
- data/ext/reflex/fixture.cpp +0 -108
- data/ext/reflex/shape_view.cpp +0 -161
- data/include/reflex/bitmap.h +0 -20
- data/include/reflex/body.h +0 -128
- data/include/reflex/bounds.h +0 -20
- data/include/reflex/color.h +0 -20
- data/include/reflex/color_space.h +0 -20
- data/include/reflex/fixture.h +0 -117
- data/include/reflex/font.h +0 -20
- data/include/reflex/image.h +0 -20
- data/include/reflex/matrix.h +0 -20
- data/include/reflex/painter.h +0 -20
- data/include/reflex/point.h +0 -24
- data/include/reflex/ruby/body.h +0 -41
- data/include/reflex/ruby/fixture.h +0 -41
- data/include/reflex/ruby/shape_view.h +0 -96
- data/include/reflex/shader.h +0 -20
- data/include/reflex/shape_view.h +0 -146
- data/include/reflex/texture.h +0 -20
- data/lib/reflex/body.rb +0 -22
- data/lib/reflex/flags.rb +0 -18
- data/lib/reflex/shape_view.rb +0 -25
- data/src/ios/application_data.h +0 -45
- data/src/ios/native_window.h +0 -39
- data/src/ios/native_window.mm +0 -224
- data/src/ios/opengl_view.h +0 -13
- data/src/ios/opengl_view.mm +0 -139
- data/src/ios/window_data.h +0 -75
- data/src/osx/application_data.h +0 -45
- data/src/osx/window_data.h +0 -75
- data/src/physics/Box2D/Box2D.h +0 -68
- data/src/physics/Box2D/Collision/Shapes/b2ChainShape.cpp +0 -193
- data/src/physics/Box2D/Collision/Shapes/b2ChainShape.h +0 -105
- data/src/physics/Box2D/Collision/Shapes/b2CircleShape.cpp +0 -99
- data/src/physics/Box2D/Collision/Shapes/b2CircleShape.h +0 -91
- data/src/physics/Box2D/Collision/Shapes/b2EdgeShape.cpp +0 -138
- data/src/physics/Box2D/Collision/Shapes/b2EdgeShape.h +0 -74
- data/src/physics/Box2D/Collision/Shapes/b2PolygonShape.cpp +0 -467
- data/src/physics/Box2D/Collision/Shapes/b2PolygonShape.h +0 -101
- data/src/physics/Box2D/Collision/Shapes/b2Shape.h +0 -101
- data/src/physics/Box2D/Collision/b2BroadPhase.cpp +0 -119
- data/src/physics/Box2D/Collision/b2BroadPhase.h +0 -257
- data/src/physics/Box2D/Collision/b2CollideCircle.cpp +0 -154
- data/src/physics/Box2D/Collision/b2CollideEdge.cpp +0 -698
- data/src/physics/Box2D/Collision/b2CollidePolygon.cpp +0 -239
- data/src/physics/Box2D/Collision/b2Collision.cpp +0 -252
- data/src/physics/Box2D/Collision/b2Collision.h +0 -277
- data/src/physics/Box2D/Collision/b2Distance.cpp +0 -603
- data/src/physics/Box2D/Collision/b2Distance.h +0 -141
- data/src/physics/Box2D/Collision/b2DynamicTree.cpp +0 -778
- data/src/physics/Box2D/Collision/b2DynamicTree.h +0 -289
- data/src/physics/Box2D/Collision/b2TimeOfImpact.cpp +0 -486
- data/src/physics/Box2D/Collision/b2TimeOfImpact.h +0 -58
- data/src/physics/Box2D/Common/b2BlockAllocator.cpp +0 -215
- data/src/physics/Box2D/Common/b2BlockAllocator.h +0 -62
- data/src/physics/Box2D/Common/b2Draw.cpp +0 -44
- data/src/physics/Box2D/Common/b2Draw.h +0 -86
- data/src/physics/Box2D/Common/b2GrowableStack.h +0 -85
- data/src/physics/Box2D/Common/b2Math.cpp +0 -94
- data/src/physics/Box2D/Common/b2Math.h +0 -720
- data/src/physics/Box2D/Common/b2Settings.cpp +0 -44
- data/src/physics/Box2D/Common/b2Settings.h +0 -151
- data/src/physics/Box2D/Common/b2StackAllocator.cpp +0 -83
- data/src/physics/Box2D/Common/b2StackAllocator.h +0 -60
- data/src/physics/Box2D/Common/b2Timer.cpp +0 -101
- data/src/physics/Box2D/Common/b2Timer.h +0 -50
- data/src/physics/Box2D/Dynamics/Contacts/b2ChainAndCircleContact.cpp +0 -53
- data/src/physics/Box2D/Dynamics/Contacts/b2ChainAndCircleContact.h +0 -39
- data/src/physics/Box2D/Dynamics/Contacts/b2ChainAndPolygonContact.cpp +0 -53
- data/src/physics/Box2D/Dynamics/Contacts/b2ChainAndPolygonContact.h +0 -39
- data/src/physics/Box2D/Dynamics/Contacts/b2CircleContact.cpp +0 -52
- data/src/physics/Box2D/Dynamics/Contacts/b2CircleContact.h +0 -39
- data/src/physics/Box2D/Dynamics/Contacts/b2Contact.cpp +0 -247
- data/src/physics/Box2D/Dynamics/Contacts/b2Contact.h +0 -349
- data/src/physics/Box2D/Dynamics/Contacts/b2ContactSolver.cpp +0 -838
- data/src/physics/Box2D/Dynamics/Contacts/b2ContactSolver.h +0 -95
- data/src/physics/Box2D/Dynamics/Contacts/b2EdgeAndCircleContact.cpp +0 -49
- data/src/physics/Box2D/Dynamics/Contacts/b2EdgeAndCircleContact.h +0 -39
- data/src/physics/Box2D/Dynamics/Contacts/b2EdgeAndPolygonContact.cpp +0 -49
- data/src/physics/Box2D/Dynamics/Contacts/b2EdgeAndPolygonContact.h +0 -39
- data/src/physics/Box2D/Dynamics/Contacts/b2PolygonAndCircleContact.cpp +0 -49
- data/src/physics/Box2D/Dynamics/Contacts/b2PolygonAndCircleContact.h +0 -38
- data/src/physics/Box2D/Dynamics/Contacts/b2PolygonContact.cpp +0 -52
- data/src/physics/Box2D/Dynamics/Contacts/b2PolygonContact.h +0 -39
- data/src/physics/Box2D/Dynamics/Joints/b2DistanceJoint.cpp +0 -260
- data/src/physics/Box2D/Dynamics/Joints/b2DistanceJoint.h +0 -169
- data/src/physics/Box2D/Dynamics/Joints/b2FrictionJoint.cpp +0 -251
- data/src/physics/Box2D/Dynamics/Joints/b2FrictionJoint.h +0 -119
- data/src/physics/Box2D/Dynamics/Joints/b2GearJoint.cpp +0 -419
- data/src/physics/Box2D/Dynamics/Joints/b2GearJoint.h +0 -125
- data/src/physics/Box2D/Dynamics/Joints/b2Joint.cpp +0 -211
- data/src/physics/Box2D/Dynamics/Joints/b2Joint.h +0 -226
- data/src/physics/Box2D/Dynamics/Joints/b2MotorJoint.cpp +0 -304
- data/src/physics/Box2D/Dynamics/Joints/b2MotorJoint.h +0 -133
- data/src/physics/Box2D/Dynamics/Joints/b2MouseJoint.cpp +0 -222
- data/src/physics/Box2D/Dynamics/Joints/b2MouseJoint.h +0 -129
- data/src/physics/Box2D/Dynamics/Joints/b2PrismaticJoint.cpp +0 -629
- data/src/physics/Box2D/Dynamics/Joints/b2PrismaticJoint.h +0 -196
- data/src/physics/Box2D/Dynamics/Joints/b2PulleyJoint.cpp +0 -348
- data/src/physics/Box2D/Dynamics/Joints/b2PulleyJoint.h +0 -152
- data/src/physics/Box2D/Dynamics/Joints/b2RevoluteJoint.cpp +0 -502
- data/src/physics/Box2D/Dynamics/Joints/b2RevoluteJoint.h +0 -204
- data/src/physics/Box2D/Dynamics/Joints/b2RopeJoint.cpp +0 -241
- data/src/physics/Box2D/Dynamics/Joints/b2RopeJoint.h +0 -114
- data/src/physics/Box2D/Dynamics/Joints/b2WeldJoint.cpp +0 -344
- data/src/physics/Box2D/Dynamics/Joints/b2WeldJoint.h +0 -126
- data/src/physics/Box2D/Dynamics/Joints/b2WheelJoint.cpp +0 -419
- data/src/physics/Box2D/Dynamics/Joints/b2WheelJoint.h +0 -210
- data/src/physics/Box2D/Dynamics/b2Body.cpp +0 -549
- data/src/physics/Box2D/Dynamics/b2Body.h +0 -860
- data/src/physics/Box2D/Dynamics/b2ContactManager.cpp +0 -296
- data/src/physics/Box2D/Dynamics/b2ContactManager.h +0 -52
- data/src/physics/Box2D/Dynamics/b2Fixture.cpp +0 -303
- data/src/physics/Box2D/Dynamics/b2Fixture.h +0 -345
- data/src/physics/Box2D/Dynamics/b2Island.cpp +0 -539
- data/src/physics/Box2D/Dynamics/b2Island.h +0 -93
- data/src/physics/Box2D/Dynamics/b2TimeStep.h +0 -70
- data/src/physics/Box2D/Dynamics/b2World.cpp +0 -1339
- data/src/physics/Box2D/Dynamics/b2World.h +0 -354
- data/src/physics/Box2D/Dynamics/b2WorldCallbacks.cpp +0 -36
- data/src/physics/Box2D/Dynamics/b2WorldCallbacks.h +0 -155
- data/src/physics/Box2D/Rope/b2Rope.cpp +0 -259
- data/src/physics/Box2D/Rope/b2Rope.h +0 -115
- data/src/shape_view.cpp +0 -306
data/src/world.cpp
CHANGED
@@ -2,20 +2,25 @@
|
|
2
2
|
|
3
3
|
|
4
4
|
#include <assert.h>
|
5
|
-
#include <
|
6
|
-
#include <Box2D/Dynamics/b2Body.h>
|
5
|
+
#include <memory>
|
7
6
|
#include <Box2D/Common/b2Draw.h>
|
8
|
-
#include <
|
9
|
-
#include
|
10
|
-
#include "reflex/view.h"
|
7
|
+
#include <Box2D/Dynamics/b2World.h>
|
8
|
+
#include <Box2D/Dynamics/Contacts/b2Contact.h>
|
11
9
|
#include "reflex/event.h"
|
12
10
|
#include "reflex/exception.h"
|
11
|
+
#include "shape.h"
|
12
|
+
#include "view.h"
|
13
|
+
#include "body.h"
|
14
|
+
#include "fixture.h"
|
13
15
|
|
14
16
|
|
15
17
|
namespace Reflex
|
16
18
|
{
|
17
19
|
|
18
20
|
|
21
|
+
static constexpr double DELTA_TIME = 1. / 60.;
|
22
|
+
|
23
|
+
|
19
24
|
class DebugDraw : public b2Draw
|
20
25
|
{
|
21
26
|
|
@@ -35,12 +40,12 @@ namespace Reflex
|
|
35
40
|
void begin (Painter* painter)
|
36
41
|
{
|
37
42
|
this->painter = painter;
|
38
|
-
painter->
|
43
|
+
painter->push_state();
|
39
44
|
}
|
40
45
|
|
41
46
|
void end ()
|
42
47
|
{
|
43
|
-
painter->
|
48
|
+
painter->pop_state();
|
44
49
|
painter = NULL;
|
45
50
|
}
|
46
51
|
|
@@ -52,11 +57,11 @@ namespace Reflex
|
|
52
57
|
painter->no_fill();
|
53
58
|
painter->set_stroke(color.r, color.g, color.b, color.a * 0.5);
|
54
59
|
|
55
|
-
|
60
|
+
std::unique_ptr<Point[]> points(new Point[vertexCount]);
|
56
61
|
for (int i = 0; i < vertexCount; ++i)
|
57
|
-
points[i] =
|
62
|
+
points[i] = to_point(vertices[i], ppm);
|
58
63
|
|
59
|
-
painter->
|
64
|
+
painter->line(&points[0], vertexCount, true);
|
60
65
|
}
|
61
66
|
|
62
67
|
void DrawSolidPolygon (
|
@@ -67,11 +72,11 @@ namespace Reflex
|
|
67
72
|
painter->set_fill(color.r, color.g, color.b, color.a * 0.5);
|
68
73
|
painter->no_stroke();
|
69
74
|
|
70
|
-
|
75
|
+
std::unique_ptr<Point[]> points(new Point[vertexCount]);
|
71
76
|
for (int i = 0; i < vertexCount; ++i)
|
72
|
-
points[i] =
|
77
|
+
points[i] = to_point(vertices[i], ppm);
|
73
78
|
|
74
|
-
painter->
|
79
|
+
painter->line(&points[0], vertexCount, true);
|
75
80
|
}
|
76
81
|
|
77
82
|
void DrawCircle (
|
@@ -118,176 +123,172 @@ namespace Reflex
|
|
118
123
|
};// DebugDraw
|
119
124
|
|
120
125
|
|
121
|
-
World::
|
122
|
-
: world(b2Vec2(0, 0)), ppm(pixels_per_meter), last_step(0), wall_(NULL),
|
123
|
-
debug_draw(NULL)
|
126
|
+
struct World::Data
|
124
127
|
{
|
125
|
-
world.SetContactListener(this);
|
126
|
-
wall_ = create_body(owner);
|
127
|
-
}
|
128
128
|
|
129
|
-
|
130
|
-
{
|
131
|
-
delete debug_draw;
|
132
|
-
}
|
129
|
+
b2World b2world;
|
133
130
|
|
134
|
-
|
135
|
-
World::step (float dt)
|
136
|
-
{
|
137
|
-
static const double DT = 1. / 60.;
|
131
|
+
float ppm, time_scale;
|
138
132
|
|
139
|
-
|
140
|
-
last_step = fmod(dt, DT);
|
133
|
+
std::unique_ptr<DebugDraw> debug_draw;
|
141
134
|
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
135
|
+
Data ()
|
136
|
+
: b2world(b2Vec2(0, 0)), ppm(0), time_scale(1)
|
137
|
+
{
|
138
|
+
}
|
146
139
|
|
147
|
-
|
148
|
-
World::create_body (View* owner, const Point& position, float degree)
|
149
|
-
{
|
150
|
-
if (!owner)
|
151
|
-
argument_error(__FILE__, __LINE__);
|
152
|
-
|
153
|
-
if (world.IsLocked())
|
154
|
-
invalid_state_error(__FILE__, __LINE__);
|
155
|
-
|
156
|
-
b2BodyDef def;
|
157
|
-
def.position = to_b2vec2(position, ppm);
|
158
|
-
def.angle = Xot::deg2rad(degree);
|
159
|
-
b2Body* body = world.CreateBody(&def);
|
160
|
-
body->SetUserData(owner);
|
161
|
-
return new Body(body, ppm);
|
162
|
-
}
|
140
|
+
};// World::Data
|
163
141
|
|
164
|
-
|
165
|
-
World::
|
142
|
+
|
143
|
+
World::World (float pixels_per_meter)
|
166
144
|
{
|
167
|
-
|
168
|
-
argument_error(__FILE__, __LINE__);
|
145
|
+
assert(pixels_per_meter > 0);
|
169
146
|
|
170
|
-
|
171
|
-
if (!b || world.IsLocked())
|
172
|
-
invalid_state_error(__FILE__, __LINE__);
|
147
|
+
self->ppm = pixels_per_meter;
|
173
148
|
|
174
|
-
|
149
|
+
self->b2world.SetContactListener(this);
|
175
150
|
}
|
176
151
|
|
177
|
-
|
178
|
-
World::resize (coord width, coord height)
|
152
|
+
World::~World ()
|
179
153
|
{
|
180
|
-
|
181
|
-
|
182
|
-
const Point points[] = {
|
183
|
-
Point(0, 0),
|
184
|
-
Point(0, height),
|
185
|
-
Point(width, height),
|
186
|
-
Point(width, 0),
|
187
|
-
};
|
188
|
-
wall_->add_edge(points, 4, true);
|
154
|
+
self->b2world.SetContactListener(NULL);
|
189
155
|
}
|
190
156
|
|
191
157
|
void
|
192
|
-
World::
|
158
|
+
World::update (float duration)
|
193
159
|
{
|
194
|
-
|
160
|
+
float dt = DELTA_TIME * self->time_scale;
|
161
|
+
if (dt <= 0) return;
|
162
|
+
|
163
|
+
int count = (int) (duration / DELTA_TIME);
|
164
|
+
if (count < 1) count = 1;
|
195
165
|
|
196
|
-
|
197
|
-
|
198
|
-
debug_draw->end();
|
166
|
+
for (int i = 0; i < count; ++i)
|
167
|
+
self->b2world.Step(dt, 8, 4);
|
199
168
|
}
|
200
169
|
|
201
170
|
float
|
202
171
|
World::meter2pixel (float meter) const
|
203
172
|
{
|
204
|
-
return meter * ppm;
|
173
|
+
return meter == 1 ? self->ppm : meter * self->ppm;
|
205
174
|
}
|
206
175
|
|
207
176
|
void
|
208
177
|
World::set_gravity (const Point& gravity)
|
209
178
|
{
|
210
|
-
|
179
|
+
b2Vec2 b2gravity = to_b2vec2(gravity, self->ppm);
|
180
|
+
if (b2gravity == self->b2world.GetGravity())
|
181
|
+
return;
|
182
|
+
|
183
|
+
self->b2world.SetGravity(b2gravity);
|
211
184
|
}
|
212
185
|
|
213
186
|
Point
|
214
187
|
World::gravity () const
|
215
188
|
{
|
216
|
-
return to_point(
|
189
|
+
return to_point(self->b2world.GetGravity(), self->ppm);
|
217
190
|
}
|
218
191
|
|
219
|
-
|
220
|
-
World::
|
192
|
+
void
|
193
|
+
World::set_time_scale (float scale)
|
221
194
|
{
|
222
|
-
|
195
|
+
self->time_scale = scale;
|
223
196
|
}
|
224
197
|
|
225
|
-
|
226
|
-
World::
|
198
|
+
float
|
199
|
+
World::time_scale () const
|
227
200
|
{
|
228
|
-
return
|
201
|
+
return self->time_scale;
|
229
202
|
}
|
230
203
|
|
231
204
|
void
|
232
205
|
World::set_debug (bool state)
|
233
206
|
{
|
234
|
-
if (state ==
|
207
|
+
if (state == debug()) return;
|
235
208
|
|
236
|
-
if (
|
237
|
-
debug_draw = new DebugDraw(ppm);
|
238
|
-
else
|
209
|
+
if (state)
|
239
210
|
{
|
240
|
-
|
241
|
-
debug_draw
|
211
|
+
assert(!self->debug_draw);
|
212
|
+
self->debug_draw.reset(new DebugDraw(self->ppm));
|
242
213
|
}
|
214
|
+
else
|
215
|
+
self->debug_draw.reset();
|
243
216
|
|
244
|
-
|
217
|
+
self->b2world.SetDebugDraw(self->debug_draw.get());
|
245
218
|
}
|
246
219
|
|
247
220
|
bool
|
248
|
-
World::
|
221
|
+
World::debug () const
|
249
222
|
{
|
250
|
-
return debug_draw;
|
223
|
+
return !!self->debug_draw;
|
251
224
|
}
|
252
225
|
|
253
|
-
|
226
|
+
void
|
227
|
+
World::on_update (float dt)
|
228
|
+
{
|
229
|
+
update(DELTA_TIME);
|
230
|
+
}
|
231
|
+
|
232
|
+
void
|
233
|
+
World::on_draw (Painter* painter)
|
234
|
+
{
|
235
|
+
if (!self->debug_draw) return;
|
236
|
+
|
237
|
+
self->debug_draw->begin(painter);
|
238
|
+
self->b2world.DrawDebugData();
|
239
|
+
self->debug_draw->end();
|
240
|
+
}
|
254
241
|
|
255
242
|
void
|
256
243
|
World::BeginContact (b2Contact* contact)
|
257
244
|
{
|
258
|
-
|
259
|
-
if (!
|
245
|
+
Shape* s1 = (Shape*) contact->GetFixtureA()->GetUserData();
|
246
|
+
if (!s1) return;
|
260
247
|
|
261
|
-
|
262
|
-
if (!
|
248
|
+
Shape* s2 = (Shape*) contact->GetFixtureB()->GetUserData();
|
249
|
+
if (!s2) return;
|
263
250
|
|
264
|
-
if (!
|
251
|
+
if (!View_is_active(*s1->owner()) || !View_is_active(*s2->owner()))
|
265
252
|
return;
|
266
253
|
|
267
|
-
ContactEvent
|
268
|
-
|
269
|
-
|
270
|
-
ContactEvent e2(ContactEvent::BEGIN, v1);
|
271
|
-
v2->on_contact(&e2);
|
254
|
+
Shape_call_contact_event(s1, ContactEvent(ContactEvent::BEGIN, s2));
|
255
|
+
Shape_call_contact_event(s2, ContactEvent(ContactEvent::BEGIN, s1));
|
272
256
|
}
|
273
257
|
|
274
258
|
void
|
275
259
|
World::EndContact (b2Contact* contact)
|
276
260
|
{
|
277
|
-
|
278
|
-
if (!
|
261
|
+
Shape* s1 = (Shape*) contact->GetFixtureA()->GetUserData();
|
262
|
+
if (!s1) return;
|
279
263
|
|
280
|
-
|
281
|
-
if (!
|
264
|
+
Shape* s2 = (Shape*) contact->GetFixtureB()->GetUserData();
|
265
|
+
if (!s2) return;
|
282
266
|
|
283
|
-
if (!
|
267
|
+
if (!View_is_active(*s1->owner()) || !View_is_active(*s2->owner()))
|
284
268
|
return;
|
285
269
|
|
286
|
-
ContactEvent
|
287
|
-
|
270
|
+
Shape_call_contact_event(s1, ContactEvent(ContactEvent::END, s2));
|
271
|
+
Shape_call_contact_event(s2, ContactEvent(ContactEvent::END, s1));
|
272
|
+
}
|
273
|
+
|
288
274
|
|
289
|
-
|
290
|
-
|
275
|
+
World*
|
276
|
+
World_get_temporary ()
|
277
|
+
{
|
278
|
+
static World world;
|
279
|
+
return &world;
|
280
|
+
}
|
281
|
+
|
282
|
+
b2World*
|
283
|
+
World_get_b2ptr (World* world)
|
284
|
+
{
|
285
|
+
return world ? &world->self->b2world : NULL;
|
286
|
+
}
|
287
|
+
|
288
|
+
const b2World*
|
289
|
+
World_get_b2ptr (const World* world)
|
290
|
+
{
|
291
|
+
return World_get_b2ptr(const_cast<World*>(world));
|
291
292
|
}
|
292
293
|
|
293
294
|
|
data/src/world.h
CHANGED
@@ -4,13 +4,16 @@
|
|
4
4
|
#define __REFLEX_SRC_WORLD_H__
|
5
5
|
|
6
6
|
|
7
|
-
#include <
|
8
|
-
#include <Box2D/Dynamics/b2World.h>
|
7
|
+
#include <Box2D/Common/b2Math.h>
|
9
8
|
#include <Box2D/Dynamics/b2WorldCallbacks.h>
|
10
|
-
#include <
|
9
|
+
#include <xot/noncopyable.h>
|
10
|
+
#include <xot/pimpl.h>
|
11
|
+
#include <rays/point.h>
|
12
|
+
#include <rays/painter.h>
|
11
13
|
#include <reflex/defs.h>
|
12
|
-
|
13
|
-
|
14
|
+
|
15
|
+
|
16
|
+
class b2World;
|
14
17
|
|
15
18
|
|
16
19
|
namespace Reflex
|
@@ -18,30 +21,24 @@ namespace Reflex
|
|
18
21
|
|
19
22
|
|
20
23
|
class View;
|
21
|
-
|
22
24
|
class Body;
|
23
25
|
|
24
|
-
class DebugDraw;
|
25
|
-
|
26
26
|
|
27
|
-
class World : public
|
27
|
+
class World : public Xot::NonCopyable, private b2ContactListener
|
28
28
|
{
|
29
29
|
|
30
30
|
public:
|
31
31
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
void step (float dt);
|
37
|
-
|
38
|
-
Body* create_body (View* owner, const Point& position = 0, float degree = 0);
|
32
|
+
enum
|
33
|
+
{
|
34
|
+
DEFAULT_PIXELS_PER_METER = 100
|
35
|
+
};
|
39
36
|
|
40
|
-
|
37
|
+
World (float pixels_per_meter = DEFAULT_PIXELS_PER_METER);
|
41
38
|
|
42
|
-
|
39
|
+
virtual ~World ();
|
43
40
|
|
44
|
-
void
|
41
|
+
void update (float duration = 0);
|
45
42
|
|
46
43
|
float meter2pixel (float meter = 1) const;
|
47
44
|
|
@@ -49,29 +46,27 @@ namespace Reflex
|
|
49
46
|
|
50
47
|
Point gravity () const;
|
51
48
|
|
52
|
-
void
|
53
|
-
|
54
|
-
bool debugging () const;
|
49
|
+
void set_time_scale (float scale);
|
55
50
|
|
56
|
-
|
51
|
+
float time_scale () const;
|
57
52
|
|
58
|
-
|
53
|
+
void set_debug (bool state = true);
|
59
54
|
|
60
|
-
|
55
|
+
bool debug () const;
|
61
56
|
|
62
|
-
void
|
57
|
+
virtual void on_update (float dt);
|
63
58
|
|
64
|
-
void
|
59
|
+
virtual void on_draw (Painter* painter);
|
65
60
|
|
66
|
-
|
61
|
+
struct Data;
|
67
62
|
|
68
|
-
|
63
|
+
Xot::PImpl<Data> self;
|
69
64
|
|
70
|
-
|
65
|
+
protected:
|
71
66
|
|
72
|
-
|
67
|
+
virtual void BeginContact (b2Contact* contact);
|
73
68
|
|
74
|
-
|
69
|
+
virtual void EndContact (b2Contact* contact);
|
75
70
|
|
76
71
|
};// World
|
77
72
|
|
@@ -101,33 +96,12 @@ namespace Reflex
|
|
101
96
|
to_b2coord(v.y, scale));
|
102
97
|
}
|
103
98
|
|
104
|
-
|
105
99
|
inline coord
|
106
100
|
to_coord (float32 t, float scale)
|
107
101
|
{
|
108
102
|
return t * scale;
|
109
103
|
}
|
110
104
|
|
111
|
-
inline Coord2
|
112
|
-
to_coord2 (const b2Vec2& v, float scale)
|
113
|
-
{
|
114
|
-
Coord2 c;
|
115
|
-
c.reset(
|
116
|
-
to_coord(v.x, scale),
|
117
|
-
to_coord(v.y, scale));
|
118
|
-
return c;
|
119
|
-
}
|
120
|
-
|
121
|
-
inline Coord3
|
122
|
-
to_coord3 (const b2Vec2& v, float scale)
|
123
|
-
{
|
124
|
-
Coord3 c;
|
125
|
-
c.reset(
|
126
|
-
to_coord(v.x, scale),
|
127
|
-
to_coord(v.y, scale));
|
128
|
-
return c;
|
129
|
-
}
|
130
|
-
|
131
105
|
inline Point
|
132
106
|
to_point (const b2Vec2& v, float scale)
|
133
107
|
{
|
@@ -137,6 +111,13 @@ namespace Reflex
|
|
137
111
|
}
|
138
112
|
|
139
113
|
|
114
|
+
World* World_get_temporary ();
|
115
|
+
|
116
|
+
b2World* World_get_b2ptr ( World* world);
|
117
|
+
|
118
|
+
const b2World* World_get_b2ptr (const World* world);
|
119
|
+
|
120
|
+
|
140
121
|
}// Reflex
|
141
122
|
|
142
123
|
|
data/task/box2d.rake
CHANGED
@@ -1,25 +1,46 @@
|
|
1
1
|
# -*- mode: ruby; coding: utf-8 -*-
|
2
2
|
|
3
3
|
|
4
|
+
task :box2d => 'box2d:update'
|
5
|
+
|
6
|
+
|
4
7
|
namespace :box2d do
|
5
8
|
|
6
9
|
|
7
|
-
mod
|
8
|
-
|
9
|
-
|
10
|
+
mod = MODULE
|
11
|
+
tmp_dir = mod.root_dir 'tmp'
|
12
|
+
|
13
|
+
lib_git = 'https://github.com/erincatto/Box2D'
|
14
|
+
lib_name = File.basename lib_git
|
15
|
+
lib_root = "#{tmp_dir}/#{lib_name}"
|
16
|
+
lib_path = "Box2D/Box2D"
|
17
|
+
|
18
|
+
copy_from = "#{lib_root}/#{lib_path}"
|
19
|
+
copy_to_base = mod.root_dir 'src/physics'
|
20
|
+
copy_to = "#{copy_to_base}/#{File.basename lib_path}"
|
21
|
+
copy_exts = %w[h cpp]
|
10
22
|
|
11
23
|
|
12
|
-
task :update =>
|
13
|
-
sh %( rm -rf #{
|
14
|
-
sh %( cp -r #{
|
24
|
+
task :update => [:clone, copy_to_base] do
|
25
|
+
sh %( rm -rf #{copy_to} )
|
26
|
+
sh %( cp -r #{copy_from} #{copy_to_base} )
|
27
|
+
|
28
|
+
Dir.glob "#{copy_to}/**/*" do |path|
|
29
|
+
ext = path[/\.[^.]+$/]
|
30
|
+
sh %( rm -f #{path} ) if ext && ext !~ /\.(#{copy_exts.join '|'})/i
|
31
|
+
end
|
32
|
+
end
|
15
33
|
|
16
|
-
|
17
|
-
|
18
|
-
sh %(
|
34
|
+
task :clone => tmp_dir do
|
35
|
+
Dir.chdir tmp_dir do
|
36
|
+
sh %( git clone #{lib_git} ) unless File.exist? lib_root
|
37
|
+
Dir.chdir lib_root do
|
38
|
+
sh %( git pull --rebase )
|
39
|
+
end
|
19
40
|
end
|
20
41
|
end
|
21
42
|
|
22
|
-
directory
|
43
|
+
directory tmp_dir, copy_to_base
|
23
44
|
|
24
45
|
|
25
46
|
end# :box2d
|
data/test/test_capture_event.rb
CHANGED
@@ -6,18 +6,20 @@ require_relative 'helper'
|
|
6
6
|
|
7
7
|
class TestCaptureEvent < Test::Unit::TestCase
|
8
8
|
|
9
|
-
def
|
10
|
-
Reflex::CaptureEvent.new *args.map {|arg|
|
9
|
+
def event (*args)
|
10
|
+
Reflex::CaptureEvent.new *args.map {|arg|
|
11
|
+
Reflex::View.capture_flag.symbols2bits *arg
|
12
|
+
}
|
11
13
|
end
|
12
14
|
|
13
15
|
def test_begin ()
|
14
|
-
c =
|
16
|
+
c = event [:key, :pointer], []
|
15
17
|
assert_equal [:key, :pointer], c.begin
|
16
18
|
assert_equal true, c.begin?(:key)
|
17
19
|
assert_equal true, c.begin?(:pointer)
|
18
20
|
assert_equal true, c.begin?(:all)
|
19
21
|
|
20
|
-
c =
|
22
|
+
c = event [:key], []
|
21
23
|
assert_equal [:key], c.begin
|
22
24
|
assert_equal true, c.begin?(:key)
|
23
25
|
assert_equal false, c.begin?(:pointer)
|
@@ -25,13 +27,13 @@ class TestCaptureEvent < Test::Unit::TestCase
|
|
25
27
|
end
|
26
28
|
|
27
29
|
def test_end ()
|
28
|
-
c =
|
30
|
+
c = event [], [:key, :pointer]
|
29
31
|
assert_equal [:key, :pointer], c.end
|
30
32
|
assert_equal true, c.end?(:key)
|
31
33
|
assert_equal true, c.end?(:pointer)
|
32
34
|
assert_equal true, c.end?(:all)
|
33
35
|
|
34
|
-
c =
|
36
|
+
c = event [], [:key]
|
35
37
|
assert_equal [:key], c.end
|
36
38
|
assert_equal true, c.end?(:key)
|
37
39
|
assert_equal false, c.end?(:pointer)
|
@@ -0,0 +1,85 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
|
3
|
+
|
4
|
+
require_relative 'helper'
|
5
|
+
|
6
|
+
|
7
|
+
class TestPointerEvent < Test::Unit::TestCase
|
8
|
+
|
9
|
+
T = true
|
10
|
+
F = false
|
11
|
+
|
12
|
+
def event (*args)
|
13
|
+
Reflex::PointerEvent.new *args
|
14
|
+
end
|
15
|
+
|
16
|
+
def type (arg)
|
17
|
+
event(arg).tap do |o|
|
18
|
+
def o.test ()
|
19
|
+
[type, down?, up?, move?]
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_type ()
|
25
|
+
o = type Reflex::PointerEvent::TYPE_NONE
|
26
|
+
assert_equal [:none, F, F, F], o.test
|
27
|
+
|
28
|
+
o = type Reflex::PointerEvent::TYPE_DOWN
|
29
|
+
assert_equal [:down, T, F, F], o.test
|
30
|
+
|
31
|
+
o = type Reflex::PointerEvent::TYPE_UP
|
32
|
+
assert_equal [:up, F, T, F], o.test
|
33
|
+
|
34
|
+
o = type Reflex::PointerEvent::TYPE_MOVE
|
35
|
+
assert_equal [:move, F, F, T], o.test
|
36
|
+
end
|
37
|
+
|
38
|
+
def pointer_type (arg)
|
39
|
+
event(Reflex::PointerEvent::TYPE_NONE, arg).tap do |o|
|
40
|
+
def o.test ()
|
41
|
+
[pointer_type, left?, right?, middle?, touch?, pen?]
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_pointer_type ()
|
47
|
+
o = pointer_type Reflex::PointerEvent::POINTER_NONE
|
48
|
+
assert_equal [[], F, F, F, F, F], o.test
|
49
|
+
|
50
|
+
o = pointer_type Reflex::PointerEvent::POINTER_MOUSE_LEFT
|
51
|
+
assert_equal [[:mouse_left], T, F, F, F, F], o.test
|
52
|
+
|
53
|
+
o = pointer_type Reflex::PointerEvent::POINTER_MOUSE_RIGHT
|
54
|
+
assert_equal [[:mouse_right], F, T, F, F, F], o.test
|
55
|
+
|
56
|
+
o = pointer_type Reflex::PointerEvent::POINTER_MOUSE_MIDDLE
|
57
|
+
assert_equal [[:mouse_middle], F, F, T, F, F], o.test
|
58
|
+
|
59
|
+
o = pointer_type Reflex::PointerEvent::POINTER_TOUCH
|
60
|
+
assert_equal [[:touch], F, F, F, T, F], o.test
|
61
|
+
|
62
|
+
o = pointer_type Reflex::PointerEvent::POINTER_PEN
|
63
|
+
assert_equal [[:pen], F, F, F, F, T], o.test
|
64
|
+
|
65
|
+
o = pointer_type Reflex::PointerEvent::POINTER_MOUSE_LEFT |
|
66
|
+
Reflex::PointerEvent::POINTER_MOUSE_RIGHT
|
67
|
+
types = [:mouse_left, :mouse_right]
|
68
|
+
assert_equal [types, T, T, F, F, F], o.test
|
69
|
+
|
70
|
+
o = pointer_type Reflex::PointerEvent::POINTER_MOUSE_LEFT |
|
71
|
+
Reflex::PointerEvent::POINTER_MOUSE_RIGHT |
|
72
|
+
Reflex::PointerEvent::POINTER_MOUSE_MIDDLE
|
73
|
+
types = [:mouse_left, :mouse_right, :mouse_middle]
|
74
|
+
assert_equal [types, T, T, T, F, F], o.test
|
75
|
+
|
76
|
+
o = pointer_type Reflex::PointerEvent::POINTER_MOUSE_LEFT |
|
77
|
+
Reflex::PointerEvent::POINTER_MOUSE_RIGHT |
|
78
|
+
Reflex::PointerEvent::POINTER_MOUSE_MIDDLE |
|
79
|
+
Reflex::PointerEvent::POINTER_TOUCH |
|
80
|
+
Reflex::PointerEvent::POINTER_PEN
|
81
|
+
types = [:mouse_left, :mouse_right, :mouse_middle, :touch, :pen]
|
82
|
+
assert_equal [types, T, T, T, T, T], o.test
|
83
|
+
end
|
84
|
+
|
85
|
+
end# TestPointerEvent
|