implement terrascript profiling

This commit is contained in:
dfsek
2021-04-12 00:45:52 -07:00
parent 9c1a35f444
commit f78ee70609
@@ -32,6 +32,7 @@ import com.dfsek.terra.api.structures.structure.Rotation;
import com.dfsek.terra.api.structures.structure.buffer.Buffer; import com.dfsek.terra.api.structures.structure.buffer.Buffer;
import com.dfsek.terra.api.structures.structure.buffer.DirectBuffer; import com.dfsek.terra.api.structures.structure.buffer.DirectBuffer;
import com.dfsek.terra.api.structures.structure.buffer.StructureBuffer; import com.dfsek.terra.api.structures.structure.buffer.StructureBuffer;
import com.dfsek.terra.profiler.ProfileFrame;
import com.google.common.cache.Cache; import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder; import com.google.common.cache.CacheBuilder;
import net.jafama.FastMath; import net.jafama.FastMath;
@@ -105,22 +106,28 @@ public class StructureScript {
* @return Whether generation was successful * @return Whether generation was successful
*/ */
public boolean execute(Location location, Random random, Rotation rotation) { public boolean execute(Location location, Random random, Rotation rotation) {
try(ProfileFrame ignore = main.getProfiler().profile("terrascript:" + id)) {
StructureBuffer buffer = new StructureBuffer(location); StructureBuffer buffer = new StructureBuffer(location);
boolean level = applyBlock(new TerraImplementationArguments(buffer, rotation, random, 0)); boolean level = applyBlock(new TerraImplementationArguments(buffer, rotation, random, 0));
buffer.paste(); buffer.paste();
return level; return level;
} }
}
public boolean execute(Location location, Chunk chunk, Random random, Rotation rotation) { public boolean execute(Location location, Chunk chunk, Random random, Rotation rotation) {
try(ProfileFrame ignore = main.getProfiler().profile("terrascript_chunk:" + id)) {
StructureBuffer buffer = computeBuffer(location, random, rotation); StructureBuffer buffer = computeBuffer(location, random, rotation);
buffer.paste(chunk); buffer.paste(chunk);
return buffer.succeeded(); return buffer.succeeded();
} }
}
public boolean test(Location location, Random random, Rotation rotation) { public boolean test(Location location, Random random, Rotation rotation) {
try(ProfileFrame ignore = main.getProfiler().profile("terrascript_test:" + id)) {
StructureBuffer buffer = computeBuffer(location, random, rotation); StructureBuffer buffer = computeBuffer(location, random, rotation);
return buffer.succeeded(); return buffer.succeeded();
} }
}
private StructureBuffer computeBuffer(Location location, Random random, Rotation rotation) { private StructureBuffer computeBuffer(Location location, Random random, Rotation rotation) {
try { try {
@@ -135,13 +142,17 @@ public class StructureScript {
} }
public boolean executeInBuffer(Buffer buffer, Random random, Rotation rotation, int recursions) { public boolean executeInBuffer(Buffer buffer, Random random, Rotation rotation, int recursions) {
try(ProfileFrame ignore = main.getProfiler().profile("terrascript_recursive:" + id)) {
return applyBlock(new TerraImplementationArguments(buffer, rotation, random, recursions)); return applyBlock(new TerraImplementationArguments(buffer, rotation, random, recursions));
} }
}
public boolean executeDirect(Location location, Random random, Rotation rotation) { public boolean executeDirect(Location location, Random random, Rotation rotation) {
try(ProfileFrame ignore = main.getProfiler().profile("terrascript_direct:" + id)) {
DirectBuffer buffer = new DirectBuffer(location); DirectBuffer buffer = new DirectBuffer(location);
return applyBlock(new TerraImplementationArguments(buffer, rotation, random, 0)); return applyBlock(new TerraImplementationArguments(buffer, rotation, random, 0));
} }
}
public String getId() { public String getId() {
return id; return id;