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 float[] recentValue;
private float[] prevVal = new float[4];
public Uniform( int location ) {
public Uniform(int location) {
this.location = location;
}
@ -40,43 +40,44 @@ public class Uniform {
}
public void enable() {
GLES20.glEnableVertexAttribArray( location );
GLES20.glEnableVertexAttribArray(location);
}
public void disable() {
GLES20.glDisableVertexAttribArray( location );
GLES20.glDisableVertexAttribArray(location);
}
public void value1f( float value ) {
if (sameFloat(new float[]{value})) return;
GLES20.glUniform1f( location, value );
public void value1f(float value) {
GLES20.glUniform1f(location, value);
}
public void value2f( float v1, float v2 ) {
if (sameFloat(new float[]{v1, v2})) return;
GLES20.glUniform2f( location, v1, v2 );
public void value2f(float v1, float v2) {
GLES20.glUniform2f(location, v1, v2);
}
public void value4f( float v1, float v2, float v3, float v4 ) {
if (sameFloat(new float[]{v1, v2, v3, v4})) return;
GLES20.glUniform4f( location, v1, v2, v3, v4 );
}
public void valueM3( float[] value ) {
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 );
}
public void value4f(float v1, float v2, float v3, float v4) {
if (v1 == prevVal[0] &&
v2 == prevVal[1] &&
v3 == prevVal[2] &&
v4 == prevVal[3])
return;
private boolean sameFloat(float[] newValue){
if (Arrays.equals(recentValue, newValue))
return true;
recentValue = newValue;
return false;
prevVal[0] = v1;
prevVal[1] = v2;
prevVal[2] = v3;
prevVal[3] = v4;
GLES20.glUniform4f(location, v1, v2, v3, v4);
}
}
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() {
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.BuffIndicator;
import com.shatteredpixel.shatteredpixeldungeon.ui.QuickSlotButton;
import com.shatteredpixel.shatteredpixeldungeon.ui.StatusPane;
import com.shatteredpixel.shatteredpixeldungeon.utils.BArray;
import com.shatteredpixel.shatteredpixeldungeon.utils.GLog;
import com.shatteredpixel.shatteredpixeldungeon.windows.WndMessage;
@ -1406,6 +1407,7 @@ public class Hero extends Char {
belongings.specialKeys[Dungeon.depth]--;
Level.set( doorCell, Terrain.UNLOCKED_EXIT );
}
StatusPane.needsKeyUpdate = true;
Level.set( doorCell, door == Terrain.LOCKED_DOOR ? Terrain.DOOR : Terrain.UNLOCKED_EXIT );
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.items.Item;
import com.shatteredpixel.shatteredpixeldungeon.scenes.GameScene;
import com.shatteredpixel.shatteredpixeldungeon.ui.StatusPane;
import com.watabou.noosa.audio.Sample;
import com.watabou.utils.Bundle;
@ -48,6 +49,7 @@ public abstract class Key extends Item {
GameScene.pickUpJournal(this);
Sample.INSTANCE.play( Assets.SND_ITEM );
hero.spendAndNext( TIME_TO_PICK_UP );
StatusPane.needsKeyUpdate = true;
return true;
}

View File

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