diff --git a/CHANGES b/CHANGES index b0681cc3..96ef66a4 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,9 @@ +[0.0.4] +- Smooth camera pan +- Update HyperLap2D project version to 0.1.1 +- Performance plugin now shows used memory +- Some memory optimizations + [0.0.3] - Fixed bright lights on some GPUs - Fixed undo\redo when creating new objects diff --git a/assets/plugins/plugin-9patch-0.0.2.jar b/assets/plugins/plugin-9patch-0.0.3.jar similarity index 90% rename from assets/plugins/plugin-9patch-0.0.2.jar rename to assets/plugins/plugin-9patch-0.0.3.jar index 9d1ff8e0..aeb249ae 100644 Binary files a/assets/plugins/plugin-9patch-0.0.2.jar and b/assets/plugins/plugin-9patch-0.0.3.jar differ diff --git a/assets/plugins/plugin-performance-0.0.2.jar b/assets/plugins/plugin-performance-0.0.2.jar deleted file mode 100644 index 883aea66..00000000 Binary files a/assets/plugins/plugin-performance-0.0.2.jar and /dev/null differ diff --git a/assets/plugins/plugin-performance-0.0.3.jar b/assets/plugins/plugin-performance-0.0.3.jar new file mode 100644 index 00000000..655c5963 Binary files /dev/null and b/assets/plugins/plugin-performance-0.0.3.jar differ diff --git a/assets/plugins/plugin-skin-composer-0.0.2.jar b/assets/plugins/plugin-skin-composer-0.0.2.jar deleted file mode 100644 index 501cb0be..00000000 Binary files a/assets/plugins/plugin-skin-composer-0.0.2.jar and /dev/null differ diff --git a/assets/plugins/plugin-skin-composer-0.0.3.jar b/assets/plugins/plugin-skin-composer-0.0.3.jar new file mode 100644 index 00000000..bed373d0 Binary files /dev/null and b/assets/plugins/plugin-skin-composer-0.0.3.jar differ diff --git a/assets/plugins/plugin-tiled-0.0.2.jar b/assets/plugins/plugin-tiled-0.0.3.jar similarity index 91% rename from assets/plugins/plugin-tiled-0.0.2.jar rename to assets/plugins/plugin-tiled-0.0.3.jar index 9d36f42d..5a15f97f 100644 Binary files a/assets/plugins/plugin-tiled-0.0.2.jar and b/assets/plugins/plugin-tiled-0.0.3.jar differ diff --git a/plugin-performance/src/main/java/games/rednblack/editor/plugin/performance/PerformancePanel.java b/plugin-performance/src/main/java/games/rednblack/editor/plugin/performance/PerformancePanel.java index 55a21c9c..5fb30007 100644 --- a/plugin-performance/src/main/java/games/rednblack/editor/plugin/performance/PerformancePanel.java +++ b/plugin-performance/src/main/java/games/rednblack/editor/plugin/performance/PerformancePanel.java @@ -2,18 +2,25 @@ package games.rednblack.editor.plugin.performance; import com.badlogic.ashley.core.Engine; import com.badlogic.gdx.Gdx; +import com.badlogic.gdx.utils.TimeUtils; import com.kotcrab.vis.ui.widget.VisLabel; import com.kotcrab.vis.ui.widget.VisTable; import games.rednblack.h2d.common.UIDraggablePanel; +import java.lang.management.ManagementFactory; +import java.lang.management.MemoryUsage; +import java.text.DecimalFormat; + public class PerformancePanel extends UIDraggablePanel { private VisTable mainTable; private VisLabel entitiesCount; private VisLabel fpsLbl; + private VisLabel memoryLabel; private Engine engine; + private long time; public PerformancePanel() { super("Performance"); @@ -21,7 +28,7 @@ public class PerformancePanel extends UIDraggablePanel { mainTable = new VisTable(); - getContentTable().add(mainTable).left().width(150).pad(5); + getContentTable().add(mainTable).left().width(250).pad(5); } public void initView() { @@ -29,7 +36,7 @@ public class PerformancePanel extends UIDraggablePanel { entitiesCount = new VisLabel(); fpsLbl = new VisLabel(); - + memoryLabel = new VisLabel(); mainTable.add(new VisLabel("Entity count: ")).right(); mainTable.add(entitiesCount).left().padLeft(4); @@ -38,7 +45,13 @@ public class PerformancePanel extends UIDraggablePanel { mainTable.add(new VisLabel("FPS: ")).right(); mainTable.add(fpsLbl).left().padLeft(4); mainTable.row(); + + mainTable.add(new VisLabel("Memory: ")).right(); + mainTable.add(memoryLabel).left().padLeft(4); + mainTable.row(); pack(); + + time = TimeUtils.millis(); } public void initLockView() { @@ -50,12 +63,41 @@ public class PerformancePanel extends UIDraggablePanel { @Override public void act(float delta) { super.act(delta); - if(entitiesCount != null && fpsLbl != null) { + if (TimeUtils.timeSinceMillis(time) > 1000) { entitiesCount.setText(engine.getEntities().size() + ""); fpsLbl.setText(Gdx.graphics.getFramesPerSecond() + ""); + MemoryUsage memoryUsage = ManagementFactory.getMemoryMXBean().getHeapMemoryUsage(); + long usedMemory = memoryUsage.getUsed(); + long allocatedMemory = memoryUsage.getCommitted(); + memoryLabel.setText(getFileSizeString(usedMemory) + " of " + getFileSizeString(allocatedMemory)); } } + public static final long KB = 1024; + public static final long MB = 1024 * KB; + public static final long GB = 1024 * MB; + public static final long PB = 1024 * GB; + + DecimalFormat df = new DecimalFormat("#"); + + public String getFileSizeString(long size) { + int digits = getDigits(size); + df.applyPattern(digits == 0 ? "#" : "#." + getDigits(digits)); + if (size < KB) { + return df.format(size) + " " + "KB"; + } else if (size < MB) { + return df.format((float) size / KB) + " " + "KB"; + } else if (size < GB) { + return df.format((float) size / MB) + " " + "MB"; + } else { + return df.format((float) size / GB) + " " + "GB"; + } + } + + private int getDigits(long size) { + return size < GB ? 0 : 2; + } + public void setEngine(Engine engine) { this.engine = engine; } diff --git a/src/main/java/games/rednblack/editor/view/ui/RulersUI.java b/src/main/java/games/rednblack/editor/view/ui/RulersUI.java index 68300650..7c86a1c9 100644 --- a/src/main/java/games/rednblack/editor/view/ui/RulersUI.java +++ b/src/main/java/games/rednblack/editor/view/ui/RulersUI.java @@ -20,6 +20,8 @@ import games.rednblack.editor.HyperLap2DFacade; import games.rednblack.editor.utils.Guide; import games.rednblack.editor.view.stage.Sandbox; +import java.util.HashMap; + /** * Created by azakhary on 7/18/2015. */ @@ -68,6 +70,12 @@ public class RulersUI extends Actor { private Guide draggingGuide = null; private boolean lockLines; + private final Vector2 tmp1 = new Vector2(); + private final Vector2 tmp2 = new Vector2(); + private final Circle tmpCircle = new Circle(); + + private final HashMap labelTextCache = new HashMap<>(); + public RulersUI() { shapeRenderer = new ShapeRenderer(); @@ -84,12 +92,14 @@ public class RulersUI extends Actor { private boolean isTouchingDownRuler; private boolean isTouchDownRulerVertical; + private final Vector2 tmp = new Vector2(); + private final Circle tmpCircle = new Circle(); @Override public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) { super.touchDown(event, x, y, pointer, button); - Circle touchCircle = new Circle(); + Circle touchCircle = tmpCircle; touchCircle.radius = 5; touchCircle.setPosition(x - Gdx.graphics.getWidth() / 2f, y - Gdx.graphics.getHeight() / 2f); @@ -118,7 +128,7 @@ public class RulersUI extends Actor { if (lockLines) return; - Vector2 downPost = new Vector2(getTouchDownX(), getTouchDownY()); + Vector2 downPost = tmp.set(getTouchDownX(), getTouchDownY()); if (isTouchingDownRuler && draggingGuide == null && downPost.dst(x, y) > 3) { draggingGuide = new Guide(isTouchDownRulerVertical); guides.add(draggingGuide); @@ -126,7 +136,7 @@ public class RulersUI extends Actor { //Changes the dragging guide's position to the world position if (draggingGuide != null) { - Vector2 worldCoords = hereToWorld(new Vector2(x - Gdx.graphics.getWidth() / 2f, y - Gdx.graphics.getHeight() / 2f)); + Vector2 worldCoords = hereToWorld(tmp.set(x - Gdx.graphics.getWidth() / 2f, y - Gdx.graphics.getHeight() / 2f)); if (draggingGuide.isVertical) { draggingGuide.pos = worldCoords.x; if (!isShowingPixels) @@ -273,11 +283,11 @@ public class RulersUI extends Actor { shapeRenderer.line(verticalRect.x + verticalRect.width + 1, verticalRect.y, verticalRect.x + verticalRect.width + 1, verticalRect.y + verticalRect.height - rulerBoxSize); //Functional lines to show grid - Vector2 startPoint = new Vector2(horizontalRect.x + rulerBoxSize, verticalRect.y); + Vector2 startPoint = tmp1.set(horizontalRect.x + rulerBoxSize, verticalRect.y); Vector2 worldStartPoint = hereToWorld(startPoint); worldStartPoint.x -= worldStartPoint.x % gridMeasuringSizeInWorld; worldStartPoint.y -= worldStartPoint.y % gridMeasuringSizeInWorld; - Vector2 worldStartPointCpy = new Vector2(worldStartPoint); + Vector2 worldStartPointCpy = tmp2.set(worldStartPoint); Vector2 gridCurrPoint = worldToHere(worldStartPoint); labels.clear(); @@ -311,8 +321,14 @@ public class RulersUI extends Actor { VisLabel label = Pools.obtain(VisLabel.class); label.setColor(TEXT_COLOR); - String lblText = (int) Math.abs(worldStartPointCpy.y + iterator * gridMeasuringSize) + ""; - lblText = verticalize(lblText); + int textNumber = (int) Math.abs(worldStartPointCpy.y + iterator * gridMeasuringSize); + labelTextCache.putIfAbsent(textNumber, ""); + String lblText = labelTextCache.get(textNumber); + if (lblText.equals("")) { + lblText = verticalize(textNumber + ""); + labelTextCache.put(textNumber, lblText); + } + label.setText(lblText); label.setWrap(true); label.setPosition(Gdx.graphics.getWidth() / 2f + verticalRect.x + 3, Gdx.graphics.getHeight() / 2f + gridCurrPoint.y - label.getPrefHeight() / 2); @@ -338,12 +354,12 @@ public class RulersUI extends Actor { } if (guide.isVertical) { - Vector2 localCoords = worldToHere(new Vector2(guide.pos, 0)); + Vector2 localCoords = worldToHere(tmp1.set(guide.pos, 0)); if (localCoords.x > verticalRect.x + verticalRect.width) { shapeRenderer.line(localCoords.x, -Gdx.graphics.getHeight() / 2f, localCoords.x, horizontalRect.y); } } else { - Vector2 localCoords = worldToHere(new Vector2(0, guide.pos)); + Vector2 localCoords = worldToHere(tmp1.set(0, guide.pos)); if (localCoords.y < horizontalRect.y) { shapeRenderer.line(verticalRect.x + verticalRect.getWidth(), localCoords.y, Gdx.graphics.getWidth(), localCoords.y); } @@ -381,13 +397,18 @@ public class RulersUI extends Actor { } } + private final StringBuilder labelVerticalBuilder = new StringBuilder(); + private String verticalize(String text) { - String newText = ""; - for (int i = 0; i < text.length(); i++) { - newText += text.charAt(i) + "\n"; + if (labelVerticalBuilder.length() != text.length() * 2) { + labelVerticalBuilder.setLength(text.length() * 2); + } + for (int i = 0, j = 0; i < text.length(); i++, j+=2) { + labelVerticalBuilder.setCharAt(j, text.charAt(i)); + labelVerticalBuilder.setCharAt(j + 1, '\n'); } - return newText; + return labelVerticalBuilder.toString(); } @Override @@ -405,10 +426,10 @@ public class RulersUI extends Actor { } public Guide guideCollision(float x, float y) { - Vector2 point = new Vector2(x - Gdx.graphics.getWidth() / 2f, y - Gdx.graphics.getHeight() / 2f); + Vector2 point = tmp1.set(x - Gdx.graphics.getWidth() / 2f, y - Gdx.graphics.getHeight() / 2f); point = hereToWorld(point); - Circle touchCircle = new Circle(); + Circle touchCircle = tmpCircle; touchCircle.radius = 3f / Sandbox.getInstance().getPixelPerWU(); touchCircle.setPosition(point.x, point.y); diff --git a/src/main/java/games/rednblack/editor/view/ui/widget/actors/GridView.java b/src/main/java/games/rednblack/editor/view/ui/widget/actors/GridView.java index e4bbaac3..050d84c3 100644 --- a/src/main/java/games/rednblack/editor/view/ui/widget/actors/GridView.java +++ b/src/main/java/games/rednblack/editor/view/ui/widget/actors/GridView.java @@ -43,6 +43,8 @@ public class GridView extends Actor { private int gridSize; int gridLinesCount; + private final Color tmpColor = new Color(); + public GridView() { gridSize = 50; gridLinesCount = 40; @@ -123,7 +125,7 @@ public class GridView extends Actor { if(offsetTmp < 0) offset = (int) -Math.floor(-offsetTmp); i += offset; - Color color = new Color(Color.WHITE); + Color color = tmpColor.set(Color.WHITE); if((gridLinesCount/2 - i - 1) % 4 == 0) { color.a = 0.1f;