diff --git a/engine/src/main/java/org/terasology/config/PlayerConfig.java b/engine/src/main/java/org/terasology/config/PlayerConfig.java index e03ff221efd..fbcd3d3cea0 100644 --- a/engine/src/main/java/org/terasology/config/PlayerConfig.java +++ b/engine/src/main/java/org/terasology/config/PlayerConfig.java @@ -55,17 +55,22 @@ public void setColor(Color color) { this.color = color; } - public Float getHeight() { return height; } + public Float getHeight() { + return height; + } public void setHeight(Float height) { this.height = height; } - public Float getEyeHeight() { return eyeHeight; } + public Float getEyeHeight() { + return eyeHeight; + } public void setEyeHeight(Float eyeHeight) { - if (eyeHeight< this.height) + if (eyeHeight < this.height) { this.eyeHeight = eyeHeight; + } } private static String defaultPlayerName() { diff --git a/engine/src/main/java/org/terasology/logic/characters/AffectItemUseCooldownTimeEvent.java b/engine/src/main/java/org/terasology/logic/characters/AffectItemUseCooldownTimeEvent.java index eefbe8a1604..3656325efd2 100644 --- a/engine/src/main/java/org/terasology/logic/characters/AffectItemUseCooldownTimeEvent.java +++ b/engine/src/main/java/org/terasology/logic/characters/AffectItemUseCooldownTimeEvent.java @@ -21,4 +21,4 @@ public class AffectItemUseCooldownTimeEvent extends AbstractValueModifiableEvent public AffectItemUseCooldownTimeEvent(float baseValue) { super(baseValue); } -} \ No newline at end of file +} diff --git a/engine/src/main/java/org/terasology/logic/characters/KinematicCharacterMover.java b/engine/src/main/java/org/terasology/logic/characters/KinematicCharacterMover.java index 99746b8d3ac..9ac7ff5040a 100644 --- a/engine/src/main/java/org/terasology/logic/characters/KinematicCharacterMover.java +++ b/engine/src/main/java/org/terasology/logic/characters/KinematicCharacterMover.java @@ -671,8 +671,7 @@ private void walk(final CharacterMovementComponent movementComp, final Character movementComp.numberOfJumpsLeft--; } - } - else { + } else { if (moveResult.isTopHit() && endVelocity.y > 0) { endVelocity.y = -0.5f * endVelocity.y; } diff --git a/engine/src/main/java/org/terasology/logic/console/commandSystem/ConsoleCommand.java b/engine/src/main/java/org/terasology/logic/console/commandSystem/ConsoleCommand.java index 935f6426c1b..c2fc7394ba6 100644 --- a/engine/src/main/java/org/terasology/logic/console/commandSystem/ConsoleCommand.java +++ b/engine/src/main/java/org/terasology/logic/console/commandSystem/ConsoleCommand.java @@ -32,20 +32,24 @@ */ @API public interface ConsoleCommand extends Comparable { - Comparator COMPARATOR = (o1, o2) -> { - int nameComparison = o1.getName().compareTo(o2.getName()); + Comparator COMPARATOR = new Comparator() { - if (nameComparison != 0) { - return nameComparison; - } + @Override + public int compare(ConsoleCommand o1, ConsoleCommand o2) { + int nameComparison = o1.getName().compareTo(o2.getName()); - if (!o1.endsWithVarargs() && o2.endsWithVarargs()) { - return -1; - } else if (o1.endsWithVarargs() && !o2.endsWithVarargs()) { - return 1; - } + if (nameComparison != 0) { + return nameComparison; + } - return o2.getRequiredParameterCount() - o1.getRequiredParameterCount(); + if (!o1.endsWithVarargs() && o2.endsWithVarargs()) { + return -1; + } else if (o1.endsWithVarargs() && !o2.endsWithVarargs()) { + return 1; + } + + return o2.getRequiredParameterCount() - o1.getRequiredParameterCount(); + }; }; /** diff --git a/engine/src/main/java/org/terasology/network/internal/ClientConnectionHandler.java b/engine/src/main/java/org/terasology/network/internal/ClientConnectionHandler.java index 1c29b89cbe5..b0e5cf98519 100644 --- a/engine/src/main/java/org/terasology/network/internal/ClientConnectionHandler.java +++ b/engine/src/main/java/org/terasology/network/internal/ClientConnectionHandler.java @@ -71,24 +71,24 @@ public ClientConnectionHandler(JoinStatusImpl joinStatus, NetworkSystemImpl netw this.moduleManager = CoreRegistry.get(ModuleManager.class); } - private void scheduleTimeout(Channel inputChannel) { + private void scheduleTimeout(Channel inputChannel) { channel = inputChannel; - timeoutPoint = System.currentTimeMillis() + timeoutThreshold; - timeoutTimer.schedule(new java.util.TimerTask() { - @Override - public void run() { - synchronized (joinStatus) { - if (System.currentTimeMillis() > timeoutPoint - && joinStatus.getStatus() != JoinStatus.Status.COMPLETE - && joinStatus.getStatus() != JoinStatus.Status.FAILED) { - joinStatus.setErrorMessage("Server stopped responding."); + timeoutPoint = System.currentTimeMillis() + timeoutThreshold; + timeoutTimer.schedule(new java.util.TimerTask() { + @Override + public void run() { + synchronized (joinStatus) { + if (System.currentTimeMillis() > timeoutPoint + && joinStatus.getStatus() != JoinStatus.Status.COMPLETE + && joinStatus.getStatus() != JoinStatus.Status.FAILED) { + joinStatus.setErrorMessage("Server stopped responding."); channel.close(); - logger.error("Server timeout threshold of {} ms exceeded.", timeoutThreshold); - } - } - } - }, timeoutThreshold + 200); - } + logger.error("Server timeout threshold of {} ms exceeded.", timeoutThreshold); + } + } + } + }, timeoutThreshold + 200); + } @Override public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) { @@ -99,28 +99,29 @@ public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) { scheduleTimeout(ctx.getChannel()); // Handle message - NetData.NetMessage message = (NetData.NetMessage) e.getMessage(); - synchronized (joinStatus) { - timeoutPoint = System.currentTimeMillis() + timeoutThreshold; - if (message.hasServerInfo()) { - receivedServerInfo(ctx, message.getServerInfo()); - } else if (message.hasModuleDataHeader()) { - receiveModuleStart(ctx, message.getModuleDataHeader()); - } else if (message.hasModuleData()) { - receiveModule(ctx, message.getModuleData()); - } else if (message.hasJoinComplete()) { - if (missingModules.size() > 0) { - logger.error( - "The server did not send all of the modules that were needed before ending module transmission."); - } - completeJoin(ctx, message.getJoinComplete()); - } else { - logger.error("Received unexpected message"); - } - } - } + NetData.NetMessage message = (NetData.NetMessage) e.getMessage(); + synchronized (joinStatus) { + timeoutPoint = System.currentTimeMillis() + timeoutThreshold; + if (message.hasServerInfo()) { + receivedServerInfo(ctx, message.getServerInfo()); + } else if (message.hasModuleDataHeader()) { + receiveModuleStart(ctx, message.getModuleDataHeader()); + } else if (message.hasModuleData()) { + receiveModule(ctx, message.getModuleData()); + } else if (message.hasJoinComplete()) { + if (missingModules.size() > 0) { + logger.error( + "The server did not send all of the modules that were needed before ending module transmission."); + } + completeJoin(ctx, message.getJoinComplete()); + } else { + logger.error("Received unexpected message"); + } + } + } - private void receiveModuleStart(ChannelHandlerContext channelHandlerContext, NetData.ModuleDataHeader moduleDataHeader) { + private void receiveModuleStart(ChannelHandlerContext channelHandlerContext, + NetData.ModuleDataHeader moduleDataHeader) { if (receivingModule != null) { joinStatus.setErrorMessage("Module download error"); channelHandlerContext.getChannel().close(); @@ -133,16 +134,18 @@ private void receiveModuleStart(ChannelHandlerContext channelHandlerContext, Net channelHandlerContext.getChannel().close(); } else { String sizeString = getSizeString(moduleDataHeader.getSize()); - joinStatus.setCurrentActivity("Downloading " + moduleDataHeader.getId() + ":" + moduleDataHeader.getVersion() + " (" + sizeString + "," - + missingModules.size() + " modules remain)"); - logger.info("Downloading " + moduleDataHeader.getId() + ":" + moduleDataHeader.getVersion() + " (" + sizeString + "," - + missingModules.size() + " modules remain)"); + joinStatus.setCurrentActivity( + "Downloading " + moduleDataHeader.getId() + ":" + moduleDataHeader.getVersion() + " (" + + sizeString + "," + missingModules.size() + " modules remain)"); + logger.info("Downloading " + moduleDataHeader.getId() + ":" + moduleDataHeader.getVersion() + " (" + + sizeString + "," + missingModules.size() + " modules remain)"); receivingModule = moduleDataHeader; lengthReceived = 0; try { tempModuleLocation = Files.createTempFile("terasologyDownload", ".tmp"); tempModuleLocation.toFile().deleteOnExit(); - downloadingModule = new BufferedOutputStream(Files.newOutputStream(tempModuleLocation, StandardOpenOption.WRITE)); + downloadingModule = new BufferedOutputStream( + Files.newOutputStream(tempModuleLocation, StandardOpenOption.WRITE)); } catch (IOException e) { logger.error("Failed to write received module", e); joinStatus.setErrorMessage("Module download error"); @@ -150,7 +153,8 @@ private void receiveModuleStart(ChannelHandlerContext channelHandlerContext, Net } } } else { - logger.error("Received unwanted module {}:{} from server", moduleDataHeader.getId(), moduleDataHeader.getVersion()); + logger.error("Received unwanted module {}:{} from server", moduleDataHeader.getId(), + moduleDataHeader.getVersion()); joinStatus.setErrorMessage("Module download error"); channelHandlerContext.getChannel().close(); } @@ -230,7 +234,8 @@ private void receivedServerInfo(ChannelHandlerContext channelHandlerContext, Net // Request missing modules for (NetData.ModuleInfo info : message.getModuleList()) { - if (null == moduleManager.getRegistry().getModule(new Name(info.getModuleId()), new Version(info.getModuleVersion()))) { + if (null == moduleManager.getRegistry().getModule(new Name(info.getModuleId()), + new Version(info.getModuleVersion()))) { missingModules.add(info.getModuleId().toLowerCase(Locale.ENGLISH)); } } @@ -260,9 +265,9 @@ private void sendJoin(ChannelHandlerContext channelHandlerContext) { channelHandlerContext.getChannel().write(NetData.NetMessage.newBuilder().setJoin(bldr).build()); } - public JoinStatus getJoinStatus() { - synchronized (joinStatus) { - return joinStatus; - } - } + public JoinStatus getJoinStatus() { + synchronized (joinStatus) { + return joinStatus; + } + } } diff --git a/engine/src/main/java/org/terasology/rendering/nui/asset/UIData.java b/engine/src/main/java/org/terasology/rendering/nui/asset/UIData.java index b6cacb74eff..100ab9111b8 100644 --- a/engine/src/main/java/org/terasology/rendering/nui/asset/UIData.java +++ b/engine/src/main/java/org/terasology/rendering/nui/asset/UIData.java @@ -53,4 +53,4 @@ public void setSource(AssetDataFile source) { public AssetDataFile getSource() { return source; } -} \ No newline at end of file +} diff --git a/engine/src/main/java/org/terasology/rendering/nui/asset/UIElement.java b/engine/src/main/java/org/terasology/rendering/nui/asset/UIElement.java index e9475fe107e..2dca8319c6f 100644 --- a/engine/src/main/java/org/terasology/rendering/nui/asset/UIElement.java +++ b/engine/src/main/java/org/terasology/rendering/nui/asset/UIElement.java @@ -76,4 +76,4 @@ public UIWidget getRootWidget() { public AssetDataFile getSource() { return source; } -} \ No newline at end of file +} diff --git a/engine/src/main/java/org/terasology/rendering/nui/contextMenu/ContextMenuOption.java b/engine/src/main/java/org/terasology/rendering/nui/contextMenu/ContextMenuOption.java index 774b7b20445..2f62a343050 100644 --- a/engine/src/main/java/org/terasology/rendering/nui/contextMenu/ContextMenuOption.java +++ b/engine/src/main/java/org/terasology/rendering/nui/contextMenu/ContextMenuOption.java @@ -74,4 +74,4 @@ public E getObject() { public String toString() { return name; } -} \ No newline at end of file +} diff --git a/engine/src/main/java/org/terasology/rendering/nui/contextMenu/MenuTree.java b/engine/src/main/java/org/terasology/rendering/nui/contextMenu/MenuTree.java index a5b7b653fcf..9347a9af918 100644 --- a/engine/src/main/java/org/terasology/rendering/nui/contextMenu/MenuTree.java +++ b/engine/src/main/java/org/terasology/rendering/nui/contextMenu/MenuTree.java @@ -41,8 +41,8 @@ List getOptions() { return this.options; } - public void addOption(String name, Consumer consumer, E item) { - options.add(new ContextMenuOption(name, consumer, item, true)); + public void addOption(String optionName, Consumer consumer, E item) { + options.add(new ContextMenuOption(optionName, consumer, item, true)); } public void addSubmenu(MenuTree tree) { diff --git a/engine/src/main/java/org/terasology/rendering/nui/itemRendering/ToStringTextRenderer.java b/engine/src/main/java/org/terasology/rendering/nui/itemRendering/ToStringTextRenderer.java index 145c725ecde..da1ea666a87 100644 --- a/engine/src/main/java/org/terasology/rendering/nui/itemRendering/ToStringTextRenderer.java +++ b/engine/src/main/java/org/terasology/rendering/nui/itemRendering/ToStringTextRenderer.java @@ -36,8 +36,7 @@ public ToStringTextRenderer(TranslationSystem translationSystemInput) { public String getString(T value) { if (translationSystem == null) { return Objects.toString(value); - } - else { + } else { return translationSystem.translate(Objects.toString(value)); } } diff --git a/engine/src/main/java/org/terasology/rendering/nui/layers/mainMenu/SelectGameScreen.java b/engine/src/main/java/org/terasology/rendering/nui/layers/mainMenu/SelectGameScreen.java index 881c21f1474..4d3f7eeba15 100644 --- a/engine/src/main/java/org/terasology/rendering/nui/layers/mainMenu/SelectGameScreen.java +++ b/engine/src/main/java/org/terasology/rendering/nui/layers/mainMenu/SelectGameScreen.java @@ -75,9 +75,10 @@ public String get() { } final UILabel saveGamePath = find("saveGamePath", UILabel.class); - if(saveGamePath != null) - { - saveGamePath.setText(translationSystem.translate("${engine:menu#save-game-path} ")+PathManager.getInstance().getSavesPath().toAbsolutePath().toString()); + if(saveGamePath != null) { + saveGamePath.setText( + translationSystem.translate("${engine:menu#save-game-path} ") + + PathManager.getInstance().getSavesPath().toAbsolutePath().toString()); } final UIList gameList = find("gameList", UIList.class); diff --git a/engine/src/main/java/org/terasology/rendering/nui/layers/mainMenu/settings/PlayerSettingsScreen.java b/engine/src/main/java/org/terasology/rendering/nui/layers/mainMenu/settings/PlayerSettingsScreen.java index ba1dfc2b85b..f9c4fd7b0ba 100644 --- a/engine/src/main/java/org/terasology/rendering/nui/layers/mainMenu/settings/PlayerSettingsScreen.java +++ b/engine/src/main/java/org/terasology/rendering/nui/layers/mainMenu/settings/PlayerSettingsScreen.java @@ -61,7 +61,9 @@ public class PlayerSettingsScreen extends CoreScreenLayer { private final List colors = CieCamColors.L65C65; private UIText nametext; - private UISlider slider, heightSlider, eyeHeightSlider; + private UISlider slider; + private UISlider heightSlider; + private UISlider eyeHeightSlider; private UIImage img; private UIDropdownScrollable language; diff --git a/engine/src/main/java/org/terasology/rendering/nui/widgets/UISlider.java b/engine/src/main/java/org/terasology/rendering/nui/widgets/UISlider.java index d7d22d7a7cf..bf67a0b3262 100644 --- a/engine/src/main/java/org/terasology/rendering/nui/widgets/UISlider.java +++ b/engine/src/main/java/org/terasology/rendering/nui/widgets/UISlider.java @@ -162,8 +162,9 @@ public Vector2i getPreferredContentSize(Canvas canvas, Vector2i areaHint) { @Override public String getMode() { - if (!isEnabled()) + if (!isEnabled()) { return DISABLED_MODE; + } if (active) { return ACTIVE_MODE; diff --git a/engine/src/main/java/org/terasology/rendering/openvrprovider/ControllerListener.java b/engine/src/main/java/org/terasology/rendering/openvrprovider/ControllerListener.java index 55f8ace2c6b..437d5030707 100644 --- a/engine/src/main/java/org/terasology/rendering/openvrprovider/ControllerListener.java +++ b/engine/src/main/java/org/terasology/rendering/openvrprovider/ControllerListener.java @@ -5,16 +5,16 @@ /* Interface intended to be front-facing to user for controller interaction. */ public interface ControllerListener { - public final int LEFT_CONTROLLER = 0; - public final int RIGHT_CONTROLLER = 1; - public static int k_EAxis_Trigger = 1; - public static int k_EAxis_TouchPad = 0; - public static long k_buttonTouchpad = (1L << JOpenVRLibrary.EVRButtonId.EVRButtonId_k_EButton_SteamVR_Touchpad); - public static long k_buttonTrigger = (1L << JOpenVRLibrary.EVRButtonId.EVRButtonId_k_EButton_SteamVR_Trigger); - public static long k_buttonAppMenu = (1L << JOpenVRLibrary.EVRButtonId.EVRButtonId_k_EButton_ApplicationMenu); - public static long k_buttonGrip = (1L << JOpenVRLibrary.EVRButtonId.EVRButtonId_k_EButton_Grip); - public static float triggerThreshold = .25f; + int LEFT_CONTROLLER = 0; + int RIGHT_CONTROLLER = 1; + int EAXIS_TRIGGER = 1; + int EAXIS_TOUCHPAD = 0; + long BUTTON_TOUCHPAD = (1L << JOpenVRLibrary.EVRButtonId.EVRButtonId_k_EButton_SteamVR_Touchpad); + long BUTTON_TRIGGER = (1L << JOpenVRLibrary.EVRButtonId.EVRButtonId_k_EButton_SteamVR_Trigger); + long BUTTON_APP_MENU = (1L << JOpenVRLibrary.EVRButtonId.EVRButtonId_k_EButton_ApplicationMenu); + long BUTTON_GRIP = (1L << JOpenVRLibrary.EVRButtonId.EVRButtonId_k_EButton_Grip); + float TRIGGER_THRESHOLD = .25f; - public void buttonStateChanged(VRControllerState_t stateBefore, VRControllerState_t stateAfter, int nController); + void buttonStateChanged(VRControllerState_t stateBefore, VRControllerState_t stateAfter, int nController); // TODO: touch, axes } diff --git a/engine/src/main/java/org/terasology/world/chunks/internal/ChunkImpl.java b/engine/src/main/java/org/terasology/world/chunks/internal/ChunkImpl.java index bb3b2019435..ad5c13574da 100644 --- a/engine/src/main/java/org/terasology/world/chunks/internal/ChunkImpl.java +++ b/engine/src/main/java/org/terasology/world/chunks/internal/ChunkImpl.java @@ -43,8 +43,6 @@ import org.terasology.world.liquid.LiquidData; import java.text.DecimalFormat; -import java.util.concurrent.locks.ReadWriteLock; -import java.util.concurrent.locks.ReentrantReadWriteLock; /** * Chunks are the basic components of the world. Each chunk contains a fixed amount of blocks @@ -81,8 +79,6 @@ public class ChunkImpl implements Chunk { private AABB aabb; private Region3i region; - private final ReadWriteLock readWriteLock = new ReentrantReadWriteLock(); - private boolean disposed; private boolean ready; private volatile boolean dirty; @@ -445,6 +441,14 @@ public int hashCode() { return Objects.hashCode(chunkPos); } + @Override + public boolean equals(Object obj) { + // According to hashCode() two ChunkImpls are not equal when their + // position differs. The default equals() compares object instances. + // The same instance has the same chunkPos, so this is valid. + return super.equals(obj); + } + @Override public void setMesh(ChunkMesh mesh) { this.activeMesh = mesh; diff --git a/modules/Core/src/main/java/org/terasology/core/debug/AbstractBenchmarkInstance.java b/modules/Core/src/main/java/org/terasology/core/debug/AbstractBenchmarkInstance.java new file mode 100644 index 00000000000..1f8d89c01c6 --- /dev/null +++ b/modules/Core/src/main/java/org/terasology/core/debug/AbstractBenchmarkInstance.java @@ -0,0 +1,13 @@ +package org.terasology.core.debug; + +/** + * Describes an instance of a benchmark which can be run. + * + *

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.

+ */ +abstract class AbstractBenchmarkInstance { + + public abstract void runStep(); +} diff --git a/modules/Core/src/main/java/org/terasology/core/debug/BenchmarkScreen.java b/modules/Core/src/main/java/org/terasology/core/debug/BenchmarkScreen.java index 9ae9af72074..e078ddad42f 100644 --- a/modules/Core/src/main/java/org/terasology/core/debug/BenchmarkScreen.java +++ b/modules/Core/src/main/java/org/terasology/core/debug/BenchmarkScreen.java @@ -17,7 +17,6 @@ import org.terasology.context.Context; import org.terasology.entitySystem.entity.EntityRef; -import org.terasology.logic.players.LocalPlayer; import org.terasology.math.ChunkMath; import org.terasology.math.Region3i; import org.terasology.math.geom.Vector3f; @@ -29,25 +28,18 @@ import org.terasology.rendering.nui.widgets.UIButton; import org.terasology.rendering.nui.widgets.UIDropdownScrollable; import org.terasology.rendering.nui.widgets.UIText; -import org.terasology.world.WorldProvider; -import org.terasology.world.block.Block; -import org.terasology.world.block.BlockManager; import org.terasology.world.chunks.ChunkConstants; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; -import java.util.HashMap; import java.util.List; -import java.util.Map; /** * This screen can be shown with the showScreen command in order to measure the performance of the block placement. */ public class BenchmarkScreen extends BaseInteractionScreen { - private static final int BLOCKS_PER_CHUNK = ChunkConstants.CHUNK_SIZE.x * ChunkConstants.CHUNK_SIZE.y - * ChunkConstants.CHUNK_SIZE.z; - private static final int DEFAULT_ITERATION_COUNT = 200; + static final int DEFAULT_ITERATION_COUNT = 200; private UIText textArea; private UIButton closeButton; @@ -106,125 +98,6 @@ public void set(Object value) { } - /** - * Benchmark types the user can select and start. - */ - private enum BenchmarkType { - WORLD_PROVIDER_SET_BLOCK("WorldProvider.setBlock", 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", 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 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; - } - } - - /** - * Can banchmark either {@link WorldProvider#setBlock(Vector3i, Block)} or {@link WorldProvider#setBlocks(Map)} - * depending on a constructor argument. - */ - private static 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 = 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 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; - } - } - } - - - /** - * The interface runnable does not get used to have the possiblity in future to introduce a prepareStep and - * cleanupStep method. Those methods could be used in future to do stuff that mustnot be measured. - */ - private static abstract class AbstractBenchmarkInstance { - - public abstract void runStep(); - } - private void onStartStopButton(UIWidget uiWidget) { if (runningBenchmark == null) { handleBenchmarkStart(); @@ -239,7 +112,7 @@ private void handleBenchmarkStart() { sum = 0; min = Double.MAX_VALUE; max = Double.MIN_VALUE; - sortedDurations.clear();; + sortedDurations.clear(); updateStartStopButton(); } @@ -269,7 +142,7 @@ private void onCloseButton(UIWidget uiWidget) { getManager().popScreen(); } - private static Region3i getChunkRegionAbove(Vector3f location) { + static Region3i getChunkRegionAbove(Vector3f location) { Vector3i charecterPos = new Vector3i(location); Vector3i chunkAboveCharacter = ChunkMath.calcChunkPos(charecterPos); chunkAboveCharacter.addY(1); diff --git a/modules/Core/src/main/java/org/terasology/core/debug/BenchmarkType.java b/modules/Core/src/main/java/org/terasology/core/debug/BenchmarkType.java new file mode 100644 index 00000000000..ea788923885 --- /dev/null +++ b/modules/Core/src/main/java/org/terasology/core/debug/BenchmarkType.java @@ -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; + } +} diff --git a/modules/Core/src/main/java/org/terasology/core/debug/BlockPlacementBenchmark.java b/modules/Core/src/main/java/org/terasology/core/debug/BlockPlacementBenchmark.java new file mode 100644 index 00000000000..00099afcb0f --- /dev/null +++ b/modules/Core/src/main/java/org/terasology/core/debug/BlockPlacementBenchmark.java @@ -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 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; + } + } +} diff --git a/modules/Core/src/main/java/org/terasology/logic/inventory/CharacterInventorySystem.java b/modules/Core/src/main/java/org/terasology/logic/inventory/CharacterInventorySystem.java index 11274a2112c..a74289d9097 100644 --- a/modules/Core/src/main/java/org/terasology/logic/inventory/CharacterInventorySystem.java +++ b/modules/Core/src/main/java/org/terasology/logic/inventory/CharacterInventorySystem.java @@ -124,8 +124,7 @@ public void onDropItemRequest(DropItemRequest event, EntityRef character) { pickupItem.send(new DropItemEvent(event.getNewPosition())); - if (pickupItem.hasComponent(PickupComponent.class)) - { + if (pickupItem.hasComponent(PickupComponent.class)) { PickupComponent pickupComponent = pickupItem.getComponent(PickupComponent.class); pickupComponent.timeDropped = time.getGameTimeInMs(); pickupItem.saveComponent(pickupComponent); @@ -187,8 +186,7 @@ public void onDropItemRequest(DropItemButton event, EntityRef entity) { Vector3f maxAllowedDistanceInDirection = direction.mul(1.5f); HitResult hitResult = physics.rayTrace(position,direction,1.5f, StandardCollisionGroup.CHARACTER, StandardCollisionGroup.WORLD); - if (hitResult.isHit()) - { + if (hitResult.isHit()) { Vector3f possibleNewPosition = hitResult.getHitPoint(); maxAllowedDistanceInDirection = possibleNewPosition.sub(position); } @@ -240,8 +238,7 @@ public void onGiveItemToEntity(GiveItemEvent event, EntityRef entity) { } @ReceiveEvent(netFilter = RegisterMode.CLIENT) - public void onPlayerDeath(DeathEvent event, EntityRef entity) - { + public void onPlayerDeath(DeathEvent event, EntityRef entity) { resetDropMark(); } diff --git a/modules/Core/src/main/java/org/terasology/logic/inventory/events/DropItemRequest.java b/modules/Core/src/main/java/org/terasology/logic/inventory/events/DropItemRequest.java index 5534f1d81ec..a0702852b40 100644 --- a/modules/Core/src/main/java/org/terasology/logic/inventory/events/DropItemRequest.java +++ b/modules/Core/src/main/java/org/terasology/logic/inventory/events/DropItemRequest.java @@ -45,8 +45,7 @@ public DropItemRequest(EntityRef usedItem, EntityRef inventoryEntity, Vector3f i this.count = count; } - public DropItemRequest(EntityRef usedItem, EntityRef inventoryEntity, Vector3f impulse, Vector3f newPosition) - { + public DropItemRequest(EntityRef usedItem, EntityRef inventoryEntity, Vector3f impulse, Vector3f newPosition) { this(usedItem, inventoryEntity, impulse, newPosition, 1); } diff --git a/modules/Core/src/main/java/org/terasology/rendering/nui/layers/hud/DropItemRegion.java b/modules/Core/src/main/java/org/terasology/rendering/nui/layers/hud/DropItemRegion.java index c71aef7f788..8ac5d3719cd 100644 --- a/modules/Core/src/main/java/org/terasology/rendering/nui/layers/hud/DropItemRegion.java +++ b/modules/Core/src/main/java/org/terasology/rendering/nui/layers/hud/DropItemRegion.java @@ -81,4 +81,4 @@ public void onDraw(Canvas canvas) { super.onDraw(canvas); canvas.addInteractionRegion(interactionListener); } -} \ No newline at end of file +} diff --git a/modules/Core/src/main/java/org/terasology/rendering/nui/layers/ingame/inventory/InventoryCell.java b/modules/Core/src/main/java/org/terasology/rendering/nui/layers/ingame/inventory/InventoryCell.java index bdcb10312d8..55802c4d603 100644 --- a/modules/Core/src/main/java/org/terasology/rendering/nui/layers/ingame/inventory/InventoryCell.java +++ b/modules/Core/src/main/java/org/terasology/rendering/nui/layers/ingame/inventory/InventoryCell.java @@ -64,12 +64,11 @@ public boolean onMouseClick(NUIMouseClickEvent event) { int stackSize = InventoryUtils.getStackCount(getTargetItem()); if (stackSize > 0 && getTransferItem().getClass() != getTargetItem().getClass()) { giveAmount((stackSize + 1) / 2); - } - else { - int transferStackSize = InventoryUtils.getStackCount(getTransferItem()); - if (transferStackSize > 0) { - takeAmount(1); - } + } else { + int transferStackSize = InventoryUtils.getStackCount(getTransferItem()); + if (transferStackSize > 0) { + takeAmount(1); + } } } return true;