-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes all error violations in the Core project and also refactors some inner classes inside the debug.BenchmarkScreen to standalone classes.
- Loading branch information
Showing
8 changed files
with
154 additions
and
145 deletions.
There are no files selected for viewing
13 changes: 13 additions & 0 deletions
13
modules/Core/src/main/java/org/terasology/core/debug/AbstractBenchmarkInstance.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package org.terasology.core.debug; | ||
|
||
/** | ||
* Describes an instance of a benchmark which can be run. | ||
* | ||
* <p>The reason for not simply using the {@link Runnable} interface is that we | ||
* may need something like a {@code prepareStep()} or {@code cleanupStep()} | ||
* method, which must not be measured, in the future.</p> | ||
*/ | ||
abstract class AbstractBenchmarkInstance { | ||
|
||
public abstract void runStep(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
modules/Core/src/main/java/org/terasology/core/debug/BenchmarkType.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package org.terasology.core.debug; | ||
|
||
import org.terasology.context.Context; | ||
import org.terasology.world.chunks.ChunkConstants; | ||
|
||
/** | ||
* Benchmark types the user can select and start. | ||
*/ | ||
enum BenchmarkType { | ||
WORLD_PROVIDER_SET_BLOCK("WorldProvider.setBlock", BenchmarkScreen.DEFAULT_ITERATION_COUNT) { | ||
@Override | ||
public AbstractBenchmarkInstance createInstance(Context context) { | ||
return new BlockPlacementBenchmark(context, false); | ||
} | ||
|
||
@Override | ||
public String getDescription() { | ||
return "Uses setBlock of WorldProvder to replace the chunk (" + BLOCKS_PER_CHUNK + " blocks) above" + | ||
" the player one iteration with stone the other iteration with air"; | ||
|
||
} | ||
}, | ||
|
||
WORLD_PROVIDER_SET_BLOCKs("WorldProvider.setBlocks", BenchmarkScreen.DEFAULT_ITERATION_COUNT) { | ||
@Override | ||
public AbstractBenchmarkInstance createInstance(Context context) { | ||
return new BlockPlacementBenchmark(context, true); | ||
} | ||
|
||
@Override | ||
public String getDescription() { | ||
return "Uses setBlocks of WorldProvder to replace the chunk (" + BLOCKS_PER_CHUNK + " blocks) above" + | ||
" the player one iteration with stone the other iteration with air"; | ||
|
||
} | ||
}; | ||
|
||
private static final int BLOCKS_PER_CHUNK = ChunkConstants.CHUNK_SIZE.x * ChunkConstants.CHUNK_SIZE.y | ||
* ChunkConstants.CHUNK_SIZE.z; | ||
|
||
private String title; | ||
private int maxIterations; | ||
|
||
private BenchmarkType(String title, int maxIterations) { | ||
this.title = title; | ||
this.maxIterations = maxIterations; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return title; | ||
} | ||
|
||
/** | ||
* @return a runnable that will be invoked each iteration, and duration of the invokation will be recorded. | ||
*/ | ||
public abstract AbstractBenchmarkInstance createInstance(Context context); | ||
|
||
/** | ||
* | ||
* @return a description of the benchmark type. | ||
*/ | ||
public abstract String getDescription(); | ||
|
||
public String getTitle() { | ||
return title; | ||
} | ||
|
||
public int getMaxIterations() { | ||
return maxIterations; | ||
} | ||
} |
56 changes: 56 additions & 0 deletions
56
modules/Core/src/main/java/org/terasology/core/debug/BlockPlacementBenchmark.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package org.terasology.core.debug; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import org.terasology.context.Context; | ||
import org.terasology.logic.players.LocalPlayer; | ||
import org.terasology.math.Region3i; | ||
import org.terasology.math.geom.Vector3i; | ||
import org.terasology.world.WorldProvider; | ||
import org.terasology.world.block.Block; | ||
import org.terasology.world.block.BlockManager; | ||
|
||
/** | ||
* Can benchmark either {@link WorldProvider#setBlock(Vector3i, Block)} or {@link WorldProvider#setBlocks(Map)} | ||
* depending on a constructor argument. | ||
*/ | ||
class BlockPlacementBenchmark extends AbstractBenchmarkInstance { | ||
private final WorldProvider worldProvider; | ||
private final Region3i region3i; | ||
private final Block air; | ||
private final Block stone; | ||
private final boolean useSetBlocksInsteadOfSetBlock; | ||
private Block blockToPlace; | ||
|
||
public BlockPlacementBenchmark(Context context, boolean useSetBlocksInsteadOfSetBlock) { | ||
this.worldProvider = context.get(org.terasology.world.WorldProvider.class); | ||
LocalPlayer localPlayer = context.get(LocalPlayer.class); | ||
this.region3i = BenchmarkScreen.getChunkRegionAbove(localPlayer.getPosition()); | ||
BlockManager blockManager = context.get(BlockManager.class); | ||
this.stone = blockManager.getBlock("Core:Stone"); | ||
this.useSetBlocksInsteadOfSetBlock = useSetBlocksInsteadOfSetBlock; | ||
this.air = blockManager.getBlock("engine:air"); | ||
blockToPlace = stone; | ||
} | ||
|
||
@Override | ||
public void runStep() { | ||
if (useSetBlocksInsteadOfSetBlock) { | ||
Map<Vector3i,Block> blocksToPlace = new HashMap<>(); | ||
for (Vector3i v : region3i) { | ||
blocksToPlace.put(v, blockToPlace); | ||
} | ||
worldProvider.setBlocks(blocksToPlace); | ||
} else { | ||
for (Vector3i v : region3i) { | ||
worldProvider.setBlock(v, blockToPlace); | ||
} | ||
} | ||
if (blockToPlace == stone) { | ||
blockToPlace = air; | ||
} else { | ||
blockToPlace = stone; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters