From: fred-boy Date: Sat, 24 Nov 2018 20:48:07 +0000 (+0700) Subject: Optimization X-Git-Tag: alpha0.4~70 X-Git-Url: http://deadsoftware.ru/gitweb?a=commitdiff_plain;h=1c798d88e9c23d438e7fa770c9670b02a761f866;p=cavedroid.git Optimization Draw background fade with shape renderer (fps boost?) --- diff --git a/android/build.gradle b/android/build.gradle index e917a5f..4beaa6e 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -40,11 +40,11 @@ android { // the natives configuration, and extracts them to the proper libs/ folders // so they get packed with the APK. task copyAndroidNatives() { - file("libs/armeabi/").mkdirs(); - file("libs/armeabi-v7a/").mkdirs(); - file("libs/arm64-v8a/").mkdirs(); - file("libs/x86_64/").mkdirs(); - file("libs/x86/").mkdirs(); + file("libs/armeabi/").mkdirs() + file("libs/armeabi-v7a/").mkdirs() + file("libs/arm64-v8a/").mkdirs() + file("libs/x86_64/").mkdirs() + file("libs/x86/").mkdirs() configurations.natives.files.each { jar -> def outputDir = null @@ -106,7 +106,7 @@ eclipse { project { name = appName + "-android" natures 'com.android.ide.eclipse.adt.AndroidNature' - buildCommands.clear(); + buildCommands.clear() buildCommand "com.android.ide.eclipse.adt.ResourceManagerBuilder" buildCommand "com.android.ide.eclipse.adt.PreCompilerBuilder" buildCommand "org.eclipse.jdt.core.javabuilder" @@ -116,14 +116,14 @@ eclipse { // sets up the Android Idea project, using the old Ant based build. idea { module { - sourceDirs += file("src"); + sourceDirs += file("src") scopes = [COMPILE: [plus: [project.configurations.compile]]] iml { withXml { def node = it.asNode() - def builder = NodeBuilder.newInstance(); - builder.current = node; + def builder = NodeBuilder.newInstance() + builder.current = node builder.component(name: "FacetManager") { facet(type: "android", name: "Android") { configuration { diff --git a/core/src/ru/deadsoftware/cavecraft/game/GamePhysics.java b/core/src/ru/deadsoftware/cavecraft/game/GamePhysics.java index 94f6f36..88791dc 100644 --- a/core/src/ru/deadsoftware/cavecraft/game/GamePhysics.java +++ b/core/src/ru/deadsoftware/cavecraft/game/GamePhysics.java @@ -26,20 +26,14 @@ class GamePhysics { private boolean checkJump(Rectangle rect, int dir) { int bl; - switch (dir) { - case 0: - bl = gp.world.getForeMap((int) ((rect.x - 8) / 16), (int) ((rect.y + rect.height - 8) / 16)); - if (checkColl(new Rectangle(rect.x - 8, rect.y - 18, rect.width, rect.height))) bl = 0; - break; - case 1: - bl = gp.world.getForeMap((int) ((rect.x + rect.width + 8) / 16), (int) ((rect.y + rect.height - 8) / 16)); - if (checkColl(new Rectangle(rect.x + rect.width + 8, rect.y - 18, rect.width, rect.height))) bl = 0; - break; - default: - bl = 0; - } + int blX = (int) (rect.x + rect.width * dir - 8 + 16 * dir); + int blY = (int) (rect.y + rect.height - 8); + + bl = gp.world.getForeMap(blX / 16, blY / 16); + if (checkColl(new Rectangle(blX, rect.y - 18, rect.width, rect.height))) bl = 0; + return (bl > 0 && GameItems.getBlock(bl).toJump() && - (rect.y + rect.height) - GameItems.getBlock(bl).getRect((int) ((rect.x - 8) / 16), (int) ((rect.y + rect.height - 8) / 16)).y > 8); + (rect.y + rect.height) - GameItems.getBlock(bl).getRect(blX / 16, blY / 16).y > 8); } private boolean checkColl(Rectangle rect) { diff --git a/core/src/ru/deadsoftware/cavecraft/game/GameRenderer.java b/core/src/ru/deadsoftware/cavecraft/game/GameRenderer.java index 72686d1..3d65ddc 100644 --- a/core/src/ru/deadsoftware/cavecraft/game/GameRenderer.java +++ b/core/src/ru/deadsoftware/cavecraft/game/GameRenderer.java @@ -2,6 +2,7 @@ package ru.deadsoftware.cavecraft.game; import com.badlogic.gdx.Gdx; import com.badlogic.gdx.graphics.GL20; +import com.badlogic.gdx.graphics.glutils.ShapeRenderer; import ru.deadsoftware.cavecraft.CaveGame; import ru.deadsoftware.cavecraft.GameScreen; import ru.deadsoftware.cavecraft.game.mobs.Mob; @@ -46,8 +47,6 @@ public class GameRenderer extends Renderer { drawX(x), drawY(y)); if (gp.world.getForeMap(x, y) == 0 && x == gp.curX && y == gp.curY) drawWreck(gp.world.getBackMap(gp.curX, gp.curY)); - Assets.shade.setPosition(drawX(x), drawY(y)); - Assets.shade.draw(spriter); } } if (gp.world.getForeMap(x, y) > 0 && GameItems.getBlock(gp.world.getForeMap(x, y)).isBackground() == drawBG) { @@ -71,6 +70,22 @@ public class GameRenderer extends Renderer { drawBlock(x, y, bg); } } + if (bg) { + spriter.end(); + Gdx.gl.glEnable(GL20.GL_BLEND); + Gdx.gl.glBlendFunc(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA); + shaper.begin(ShapeRenderer.ShapeType.Filled); + shaper.setColor(0f, 0f, 0f, .5f); + for (int y = minY; y < maxY; y++) { + for (int x = minX; x < maxX; x++) { + if ((gp.world.getForeMap(x, y) == 0 || GameItems.getBlock(gp.world.getForeMap(x, y)).isTransparent()) + && gp.world.getBackMap(x, y) > 0) shaper.rect(drawX(x), drawY(y), 16, 16); + } + } + shaper.end(); + Gdx.gl.glDisable(GL20.GL_BLEND); + spriter.begin(); + } } private void drawMob(Mob mob) { diff --git a/core/src/ru/deadsoftware/cavecraft/game/GameSaver.java b/core/src/ru/deadsoftware/cavecraft/game/GameSaver.java index c4e13a6..00d91bf 100644 --- a/core/src/ru/deadsoftware/cavecraft/game/GameSaver.java +++ b/core/src/ru/deadsoftware/cavecraft/game/GameSaver.java @@ -23,10 +23,10 @@ public class GameSaver { out.write(intToBytes(VERSION)); out.write(intToBytes(width)); out.write(intToBytes(height)); - for (int y = 0; y < map[0].length; y++) { + for (int y = 0; y < height; y++) { bl = map[0][y]; rl = 0; - for (int x = 0; x < map.length; x++) { + for (int x = 0; x < width; x++) { if (map[x][y] != bl) { out.write(intToBytes(rl)); out.write(intToBytes(bl)); diff --git a/core/src/ru/deadsoftware/cavecraft/game/GameWorld.java b/core/src/ru/deadsoftware/cavecraft/game/GameWorld.java index 25d3660..e6c5633 100644 --- a/core/src/ru/deadsoftware/cavecraft/game/GameWorld.java +++ b/core/src/ru/deadsoftware/cavecraft/game/GameWorld.java @@ -38,44 +38,39 @@ public class GameWorld { return x; } - public int getForeMap(int x, int y) { + private int getMap(int x, int y, int layer) { int map = 0; try { x = transformX(x); - map = foreMap[x][y]; + map = (layer == 0) ? foreMap[x][y] : backMap[x][y]; } catch (ArrayIndexOutOfBoundsException e) { - //Gdx.app.error("GameWorld",e.toString()); } return map; } - public void setForeMap(int x, int y, int value) { + private void setMap(int x, int y, int layer, int value) { try { x = transformX(x); - foreMap[x][y] = value; + if (layer == 0) foreMap[x][y] = value; + else backMap[x][y] = value; } catch (ArrayIndexOutOfBoundsException e) { - //Gdx.app.error("GameWorld", e.toString()); } } + public int getForeMap(int x, int y) { + return getMap(x, y, 0); + } + + public void setForeMap(int x, int y, int value) { + setMap(x, y, 0, value); + } + public int getBackMap(int x, int y) { - int map = 0; - try { - x = transformX(x); - map = backMap[x][y]; - } catch (ArrayIndexOutOfBoundsException e) { - //Gdx.app.error("GameWorld",e.toString()); - } - return map; + return getMap(x, y, 1); } public void setBackMap(int x, int y, int value) { - try { - x = transformX(x); - backMap[x][y] = value; - } catch (ArrayIndexOutOfBoundsException e) { - //Gdx.app.error("GameWorld", e.toString()); - } + setMap(x, y, 1, value); } private void placeSlab(int x, int y, int value) { diff --git a/core/src/ru/deadsoftware/cavecraft/game/objects/Player.java b/core/src/ru/deadsoftware/cavecraft/game/objects/Player.java index 16e3a52..5810eb5 100644 --- a/core/src/ru/deadsoftware/cavecraft/game/objects/Player.java +++ b/core/src/ru/deadsoftware/cavecraft/game/objects/Player.java @@ -45,7 +45,7 @@ public class Player extends Mob implements Serializable { } public void setDir(int dir) { - if (dir != getDir()) changeDir(); + if (dir != getDir()) switchDir(); } @Override @@ -54,7 +54,6 @@ public class Player extends Mob implements Serializable { @Override public void changeDir() { - switchDir(); } @Override diff --git a/core/src/ru/deadsoftware/cavecraft/menu/MenuRenderer.java b/core/src/ru/deadsoftware/cavecraft/menu/MenuRenderer.java index 7a660e7..bdaf2b1 100644 --- a/core/src/ru/deadsoftware/cavecraft/menu/MenuRenderer.java +++ b/core/src/ru/deadsoftware/cavecraft/menu/MenuRenderer.java @@ -53,8 +53,8 @@ public class MenuRenderer extends Renderer { spriter.draw(Assets.menuBtn[button.getType()], button.getX(), button.getY()); setFontColor(255, 255, 255); drawString(button.getLabel(), - (button.getX() + button.getWidth() / 2) - Assets.getStringWidth(button.getLabel()) / 2, - (button.getY() + button.getHeight() / 2) - Assets.getStringHeight(button.getLabel()) / 2); + (button.getX() + button.getWidth() / 2) - (float) Assets.getStringWidth(button.getLabel()) / 2, + (button.getY() + button.getHeight() / 2) - (float) Assets.getStringHeight(button.getLabel()) / 2); } private void drawButtons(Array