Skip to content

Commit bd0f4e6

Browse files
committed
feat: Add some javadocs
1 parent c0ed861 commit bd0f4e6

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

gdx-box2d-utils/src/main/java/com/badlogic/gdx/box2d/utils/Box2dWorldMultiThreader.java

+24-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,14 @@
1010
import java.util.concurrent.BlockingQueue;
1111
import java.util.concurrent.CountDownLatch;
1212

13+
/**
14+
* This class implements a basic TaskSystem in java, for multithreading of a box2d world.
15+
* One {@link Box2dWorldMultiThreader} handles one world.
16+
* The MultiThreader will create and keep alive the configured amount of workers,
17+
* After every world step, {@link Box2dWorldMultiThreader#afterStep()} needs to be called.
18+
* After the world is destroyed, {@link Box2dWorldMultiThreader#dispose()} needs to be called.
19+
* This class, like box2d, is not thread safe.
20+
*/
1321
public class Box2dWorldMultiThreader implements Disposable {
1422

1523
private static final int MAX_TASKS = 128;
@@ -24,6 +32,15 @@ public class Box2dWorldMultiThreader implements Disposable {
2432
private int taskCount = 0;
2533
private boolean running = true;
2634

35+
/**
36+
* This method creates and configures a {@link b2WorldDef} to use a newly created {@link Box2dWorldMultiThreader}
37+
*
38+
* After the world is destroyed, {@link Box2dWorldMultiThreader#dispose()} needs to be called.
39+
*
40+
* @param worldDef The world to configure
41+
* @param numWorkers The amount of worker
42+
* @return The created {@link Box2dWorldMultiThreader}
43+
*/
2744
public static Box2dWorldMultiThreader createForWorld(b2WorldDef worldDef, int numWorkers) {
2845
Box2dWorldMultiThreader multiThreader = new Box2dWorldMultiThreader(numWorkers);
2946
multiThreader.configureForWorld(worldDef);
@@ -35,7 +52,7 @@ private Box2dWorldMultiThreader(int numWorkers) {
3552
throw new IllegalArgumentException("Number of workers must be greater than 1");
3653
this.numWorkers = numWorkers;
3754
this.workers = new Thread[numWorkers];
38-
taskChunks = new ArrayBlockingQueue<>(MAX_TASKS * numWorkers);
55+
this.taskChunks = new ArrayBlockingQueue<>(MAX_TASKS * numWorkers);
3956

4057
for (int i = 0; i < numWorkers; i++) {
4158
final int workerId = i;
@@ -106,11 +123,17 @@ private void configureForWorld(b2WorldDef worldDef) {
106123
worldDef.workerCount(numWorkers);
107124
}
108125

126+
/**
127+
* This method needs to be called after every world step
128+
*/
109129
public void afterStep() {
110130
taskCount = 0;
111131
}
112132

113133

134+
/**
135+
* Cleans up all resources. Should not be called before destroying the world.
136+
*/
114137
@Override
115138
public void dispose() {
116139
running = false;

0 commit comments

Comments
 (0)