You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/FAQ.md
+7-7Lines changed: 7 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -9,23 +9,23 @@ should be included if possible. Support is [appreciated](https://github.com/spon
9
9
Box2D [logo](https://box2d.org/images/logo.svg).
10
10
11
11
## What platforms does Box2D support?
12
-
Box2D is developed using C17. Ports and bindings are likely available for most languages and platforms.
12
+
Box2D is developed using C. Ports and bindings are likely available for most languages and platforms.
13
13
14
-
Erin Catto maintains the C17 version, but provides no support for other languages. Other languages are supported
14
+
Erin Catto maintains the C version, but provides no support for other languages. Other languages are supported
15
15
by the community and possibly by the authors of those ports.
16
16
17
17
## Who makes it?
18
-
Erin Catto is the creator and sole contributor of the C17 version of Box2D, with various others supporting the ports. Box2D is an open source project, and accepts community feedback.
18
+
Erin Catto is the creator and sole contributor of the C version of Box2D, with various others supporting the ports. Box2D is an open source project, and accepts community feedback.
19
19
20
20
## How do I get help?
21
21
You should read the documentation and the rest of this FAQ first. Also, you should study the examples included in the source distribution. Then you can visit the [Discord](https://discord.gg/aM4mRKxW) to ask any remaining questions.
22
22
23
-
Please to not message or email Erin Catto for support. It is best to ask questions on the Discord server so that everyone can benefit from the discussion.
23
+
Please to not message or email Erin Catto directly for support. It is best to ask questions on the Discord server so that everyone can benefit from the discussion.
24
24
25
25
## Documentation
26
26
27
27
### Why isn't a feature documented?
28
-
If you grab the latest code from the git master branch you will likely find features that are not documented in the manual. New features are added to the manual after they are mature and a new point release is imminent. However, all major features added to Box2D are accompanied by example code in the samples application to test the feature and show the intended usage.
28
+
If you grab the latest code from the git main branch you will likely find features that are not documented in the manual. New features are added to the manual after they are mature and a new point release is imminent. However, all major features added to Box2D are accompanied by example code in the samples application to test the feature and show the intended usage.
29
29
30
30
## Prerequisites
31
31
@@ -106,9 +106,9 @@ For the same input, and same binary, Box2D will reproduce any simulation. Box2D
106
106
107
107
Box2D is also deterministic under multithreading. A simulation using two threads will give the same result as eight threads.
108
108
109
-
However, people often want more stringent determinism. People often want to know if Box2D can produce identical results on different binaries and on different platforms. Currently this is not provided, but the situation may improve in a future update.
109
+
Box2D has cross-platform determinism as of version 3.1.
110
110
111
-
todo update here on cross-platform determinism
111
+
However, Box2D does not have rollback determinism.
112
112
113
113
### But I really want determinism
114
114
This naturally leads to the question of fixed-point math. Box2D does not support fixed-point math. In the past Box2D was ported to the NDS in fixed-point and apparently it worked okay. Fixed-point math is slower and more tedious to develop, so I have chosen not to use fixed-point for the development of Box2D.
> The character mover feature is new to version 3.1 and should be considered experimental.
5
+
6
+
Box2D provides a few structures and functions you can use to build a character mover.
7
+
8
+
These features support a `geometric` character mover. This is like
9
+
a `kinematic` mover except the character mover is not a rigid body and does
10
+
not exist in the simulation world. This is done to achieve features that
11
+
would be difficult with a kinematic body.
12
+
13
+
This type of mover may not be suitable for your game. It is less physical than a rigid body, but
14
+
it gives you more control over the movement. It is the type of mover you might find
15
+
in a first-person shooter or a game with platforming elements.
16
+
17
+
The mover is assumed to be a capsule. Using a capsule helps keep movement smooth. The capsule should
18
+
have a significant radius. It does not have to be a vertical capsule, but that is likely
19
+
to be the easiest setup. There is no explicit handling of rotation. But slow rotation can
20
+
work with this system.
21
+
22
+
Let's review the features. First there are a couple world query functions.
23
+
24
+
`b2World_CastMover()` is a custom shape cast that tries to avoid getting stuck when shapes start out touching.
25
+
The feature is called _encroachment_. Since the capsule has a significant radius it can move closer
26
+
to a surface it is touching without the inner line segment generating an overlap, which would cause
27
+
the shape cast to fail. Due to the internal use of GJK, encroachment has little cost. The idea with encroachment is that
28
+
the mover is trying to slide along a surface and we don't want to stop that even if there is some small movement into the surface.
29
+
30
+
`b2World_CollideMover()` complements the cast function. This function generates collision planes for touching and/or overlapped surfaces. The character mover is assumed to have a fixed rotation, so it doesn't need contact manifolds or contact points. It just needs collision planes. Each plane is returned with the `b2Plane` and a `b2ShapeId` for each shape the mover is touching.
31
+
32
+
Once you have some collision planes from `b2World_CollideMover()`, you can process and filter them to generate an array of `b2CollisionPlane`. These collision planes can then be sent to `b2SolvePlanes()` to generate a new position for the mover
33
+
that attempts to find the optimal new position given the current position.
34
+
35
+
These collision planes support *soft collision* using a `pushLimit`. This push limit is a distance value. A rigid surface will have a push limit of `FLT_MAX`. However, you may want some surfaces to have a limited effect on the character. For example, you may want the mover to push through other players or enemies yet still resolve the collision so they are not overlapped. Another example is a door or elevator that could otherwise push the mover through the floor.
36
+
37
+
Finally after calling `b2SolverPlanes()` you can call `b2ClipVector()` to clip your velocity vector so the mover will not keep trying to push into a wall, which could lead to a huge velocity accumulation otherwise.
38
+
39
+
The `Mover` sample shows all these functions being used together. It also includes other common character features such as acceleration and friction, jumping, and a pogo stick.
@@ -210,7 +212,7 @@ You can cast a ray at a shape to get the point of first intersection and normal
210
212
> consistent with Box2D treating convex shapes as solid.
211
213
212
214
```c
213
-
b2RayCastInput input;
215
+
b2RayCastInput input = {0};
214
216
input.origin = (b2Vec2){0.0f, 0.0f};
215
217
input.translation = (b2Vec2){1.0f, 0.0f};
216
218
input.maxFraction = 1.0f;
@@ -226,7 +228,7 @@ if (output.hit == true)
226
228
You can also cast a shape at another shape. This uses an abstract way of describing the moving shape. It is represented as a point cloud with a radius. This implies a convex shape even if the input data is not convex. The internal algorithm (GJK) will essentially only use the convex portion.
Copy file name to clipboardExpand all lines: docs/foundation.md
+10-1Lines changed: 10 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -54,9 +54,18 @@ So when you design your game loop, you should let Box2D *go wide* and use multip
54
54
In a multithreaded environment you must be careful to avoid [race conditions](https://en.wikipedia.org/wiki/Race_condition). Modifying the world while it is simulating will lead to unpredictable behavior and this is never safe. It is also not safe to read data from a Box2D world while it is simulating. Box2D may move data structures to improve cache performance. So it is very likely that you will read garbage data.
55
55
56
56
> **Caution**:
57
-
> Do not read or write the Box2D world during `b2World_Step()`
57
+
> Do not perform read or write operations on a Box2D world during `b2World_Step()`
58
58
59
59
> **Caution**:
60
60
> Do not write to the Box2D world from multiple threads
61
61
62
62
It *is safe* to do ray-casts, shape-casts, and overlap tests from multiple threads outside of `b2World_Step()`. Generally, any read-only operation is safe to do multithreaded outside of `b2World_Step()`. This can be very useful if you have multithreaded game logic.
63
+
64
+
## Multithreading Multiple Worlds
65
+
Some applications may wish to create multiple Box2D worlds and simulate them on different threads. This works fine because Box2D has very limited use of globals.
66
+
67
+
There are a few caveats:
68
+
- You will get a race condition if you create or destroy Box2D worlds from multiple threads. You should use a mutex to guard this.
69
+
- If you will simulate multiple Box2D worlds simultaneously, then they should probably not use a task system. Otherwise you're likely to get preemption.
70
+
- Any callbacks you hook up to Box2D must be thread-safe, such as memory allocators.
71
+
- All of the limitations for single world simulation still apply.
0 commit comments