v0.4.2: reduced amount of allocations occurring when frames are drawn

This commit is contained in:
Evan Debenham 2016-08-21 23:55:57 -04:00 committed by Evan Debenham
parent 9663a47958
commit b821bfddf8
5 changed files with 50 additions and 32 deletions

View File

@ -29,9 +29,9 @@ public class Uniform {
private int location; private int location;
private float[] recentValue; private float[] prevVal = new float[4];
public Uniform( int location ) { public Uniform(int location) {
this.location = location; this.location = location;
} }
@ -40,43 +40,44 @@ public class Uniform {
} }
public void enable() { public void enable() {
GLES20.glEnableVertexAttribArray( location ); GLES20.glEnableVertexAttribArray(location);
} }
public void disable() { public void disable() {
GLES20.glDisableVertexAttribArray( location ); GLES20.glDisableVertexAttribArray(location);
} }
public void value1f( float value ) { public void value1f(float value) {
if (sameFloat(new float[]{value})) return; GLES20.glUniform1f(location, value);
GLES20.glUniform1f( location, value );
} }
public void value2f( float v1, float v2 ) { public void value2f(float v1, float v2) {
if (sameFloat(new float[]{v1, v2})) return; GLES20.glUniform2f(location, v1, v2);
GLES20.glUniform2f( location, v1, v2 );
} }
public void value4f( float v1, float v2, float v3, float v4 ) { public void value4f(float v1, float v2, float v3, float v4) {
if (sameFloat(new float[]{v1, v2, v3, v4})) return; if (v1 == prevVal[0] &&
GLES20.glUniform4f( location, v1, v2, v3, v4 ); v2 == prevVal[1] &&
} v3 == prevVal[2] &&
v4 == prevVal[3])
public void valueM3( float[] value ) { return;
if (sameFloat(value)) return;
GLES20.glUniformMatrix3fv( location, 1, false, value, 0 );
}
public void valueM4( float[] value ) {
if (sameFloat(value)) return;
GLES20.glUniformMatrix4fv( location, 1, false, value, 0 );
}
private boolean sameFloat(float[] newValue){ prevVal[0] = v1;
if (Arrays.equals(recentValue, newValue)) prevVal[1] = v2;
return true; prevVal[2] = v3;
prevVal[3] = v4;
recentValue = newValue; GLES20.glUniform4f(location, v1, v2, v3, v4);
return false;
} }
}
public void valueM3(float[] value) {
GLES20.glUniformMatrix3fv(location, 1, false, value, 0);
}
public void valueM4(float[] value) {
if (Arrays.equals(prevVal, value))
return;
System.arraycopy(value, 0, prevVal, 0, 4);
GLES20.glUniformMatrix4fv(location, 1, false, value, 0);
}
}

View File

@ -151,4 +151,11 @@ public class PointF {
public String toString() { public String toString() {
return "" + x + ", " + y; return "" + x + ", " + y;
} }
@Override
public boolean equals(Object o) {
if (super.equals(o))
return true;
return o instanceof PointF && (((PointF)o).x == x && ((PointF)o).y == y);
}
} }

View File

@ -100,6 +100,7 @@ import com.shatteredpixel.shatteredpixeldungeon.sprites.HeroSprite;
import com.shatteredpixel.shatteredpixeldungeon.ui.AttackIndicator; import com.shatteredpixel.shatteredpixeldungeon.ui.AttackIndicator;
import com.shatteredpixel.shatteredpixeldungeon.ui.BuffIndicator; import com.shatteredpixel.shatteredpixeldungeon.ui.BuffIndicator;
import com.shatteredpixel.shatteredpixeldungeon.ui.QuickSlotButton; import com.shatteredpixel.shatteredpixeldungeon.ui.QuickSlotButton;
import com.shatteredpixel.shatteredpixeldungeon.ui.StatusPane;
import com.shatteredpixel.shatteredpixeldungeon.utils.BArray; import com.shatteredpixel.shatteredpixeldungeon.utils.BArray;
import com.shatteredpixel.shatteredpixeldungeon.utils.GLog; import com.shatteredpixel.shatteredpixeldungeon.utils.GLog;
import com.shatteredpixel.shatteredpixeldungeon.windows.WndMessage; import com.shatteredpixel.shatteredpixeldungeon.windows.WndMessage;
@ -1406,6 +1407,7 @@ public class Hero extends Char {
belongings.specialKeys[Dungeon.depth]--; belongings.specialKeys[Dungeon.depth]--;
Level.set( doorCell, Terrain.UNLOCKED_EXIT ); Level.set( doorCell, Terrain.UNLOCKED_EXIT );
} }
StatusPane.needsKeyUpdate = true;
Level.set( doorCell, door == Terrain.LOCKED_DOOR ? Terrain.DOOR : Terrain.UNLOCKED_EXIT ); Level.set( doorCell, door == Terrain.LOCKED_DOOR ? Terrain.DOOR : Terrain.UNLOCKED_EXIT );
GameScene.updateMap( doorCell ); GameScene.updateMap( doorCell );

View File

@ -24,6 +24,7 @@ import com.shatteredpixel.shatteredpixeldungeon.Assets;
import com.shatteredpixel.shatteredpixeldungeon.actors.hero.Hero; import com.shatteredpixel.shatteredpixeldungeon.actors.hero.Hero;
import com.shatteredpixel.shatteredpixeldungeon.items.Item; import com.shatteredpixel.shatteredpixeldungeon.items.Item;
import com.shatteredpixel.shatteredpixeldungeon.scenes.GameScene; import com.shatteredpixel.shatteredpixeldungeon.scenes.GameScene;
import com.shatteredpixel.shatteredpixeldungeon.ui.StatusPane;
import com.watabou.noosa.audio.Sample; import com.watabou.noosa.audio.Sample;
import com.watabou.utils.Bundle; import com.watabou.utils.Bundle;
@ -48,6 +49,7 @@ public abstract class Key extends Item {
GameScene.pickUpJournal(this); GameScene.pickUpJournal(this);
Sample.INSTANCE.play( Assets.SND_ITEM ); Sample.INSTANCE.play( Assets.SND_ITEM );
hero.spendAndNext( TIME_TO_PICK_UP ); hero.spendAndNext( TIME_TO_PICK_UP );
StatusPane.needsKeyUpdate = true;
return true; return true;
} }

View File

@ -231,6 +231,8 @@ public class StatusPane extends Component {
true ); true );
} }
public static boolean needsKeyUpdate = false;
private static class JournalButton extends Button { private static class JournalButton extends Button {
private Image bg; private Image bg;
@ -253,6 +255,7 @@ public class StatusPane extends Component {
icon = new Image( Assets.MENU, 31, 0, 11, 7); icon = new Image( Assets.MENU, 31, 0, 11, 7);
add( icon ); add( icon );
needsKeyUpdate = true;
} }
@Override @Override
@ -270,10 +273,13 @@ public class StatusPane extends Component {
@Override @Override
public void update() { public void update() {
super.update(); super.update();
updateKeyDisplay(); if (needsKeyUpdate)
updateKeyDisplay();
} }
public void updateKeyDisplay() { public void updateKeyDisplay() {
needsKeyUpdate = false;
boolean foundKeys = false; boolean foundKeys = false;
boolean blackKey = false; boolean blackKey = false;
boolean specialKey = false; boolean specialKey = false;