v0.7.5b: adjusted text rendering to always occur on the render thread

This commit is contained in:
Evan Debenham 2019-10-08 14:29:50 -04:00
parent d7815b7739
commit bbee1a1372
11 changed files with 261 additions and 145 deletions

View File

@ -32,6 +32,7 @@ import com.watabou.input.InputHandler;
import com.watabou.input.KeyEvent; import com.watabou.input.KeyEvent;
import com.watabou.noosa.audio.Music; import com.watabou.noosa.audio.Music;
import com.watabou.noosa.audio.Sample; import com.watabou.noosa.audio.Sample;
import com.watabou.utils.Callback;
import com.watabou.utils.PlatformSupport; import com.watabou.utils.PlatformSupport;
import com.watabou.utils.Reflection; import com.watabou.utils.Reflection;
@ -245,6 +246,15 @@ public class Game implements ApplicationListener {
Gdx.app.error("GAME", sw.toString()); Gdx.app.error("GAME", sw.toString());
} }
public static void runOnRenderThread(Callback c){
Gdx.app.postRunnable(new Runnable() {
@Override
public void run() {
c.call();
}
});
}
public static void vibrate( int milliseconds ) { public static void vibrate( int milliseconds ) {
Gdx.input.vibrate(milliseconds); Gdx.input.vibrate(milliseconds);
} }

View File

@ -127,6 +127,7 @@ import com.watabou.noosa.Camera;
import com.watabou.noosa.Game; import com.watabou.noosa.Game;
import com.watabou.noosa.audio.Sample; import com.watabou.noosa.audio.Sample;
import com.watabou.utils.Bundle; import com.watabou.utils.Bundle;
import com.watabou.utils.Callback;
import com.watabou.utils.GameMath; import com.watabou.utils.GameMath;
import com.watabou.utils.PathFinder; import com.watabou.utils.PathFinder;
import com.watabou.utils.Random; import com.watabou.utils.Random;
@ -661,8 +662,13 @@ public class Hero extends Char {
Heap heap = Dungeon.level.heaps.get( dst ); Heap heap = Dungeon.level.heaps.get( dst );
if (heap != null && heap.type == Type.FOR_SALE && heap.size() == 1) { if (heap != null && heap.type == Type.FOR_SALE && heap.size() == 1) {
Game.runOnRenderThread(new Callback() {
@Override
public void call() {
GameScene.show( new WndTradeItem( heap, true ) ); GameScene.show( new WndTradeItem( heap, true ) );
} }
});
}
return false; return false;
@ -876,7 +882,12 @@ public class Hero extends Char {
if (Dungeon.depth == 1) { if (Dungeon.depth == 1) {
if (belongings.getItem( Amulet.class ) == null) { if (belongings.getItem( Amulet.class ) == null) {
Game.runOnRenderThread(new Callback() {
@Override
public void call() {
GameScene.show( new WndMessage( Messages.get(this, "leave") ) ); GameScene.show( new WndMessage( Messages.get(this, "leave") ) );
}
});
ready(); ready();
} else { } else {
Badges.silentValidateHappyEnd(); Badges.silentValidateHappyEnd();
@ -1425,7 +1436,13 @@ public class Hero extends Char {
} else { } else {
Dungeon.deleteGame( GamesInProgress.curSlot, false ); Dungeon.deleteGame( GamesInProgress.curSlot, false );
GameScene.show( new WndResurrect( ankh, cause ) ); final Ankh finalAnkh = ankh;
Game.runOnRenderThread(new Callback() {
@Override
public void call() {
GameScene.show( new WndResurrect( finalAnkh, cause ) );
}
});
} }
} }

View File

@ -43,8 +43,10 @@ import com.shatteredpixel.shatteredpixeldungeon.sprites.BlacksmithSprite;
import com.shatteredpixel.shatteredpixeldungeon.utils.GLog; import com.shatteredpixel.shatteredpixeldungeon.utils.GLog;
import com.shatteredpixel.shatteredpixeldungeon.windows.WndBlacksmith; import com.shatteredpixel.shatteredpixeldungeon.windows.WndBlacksmith;
import com.shatteredpixel.shatteredpixeldungeon.windows.WndQuest; import com.shatteredpixel.shatteredpixeldungeon.windows.WndQuest;
import com.watabou.noosa.Game;
import com.watabou.noosa.audio.Sample; import com.watabou.noosa.audio.Sample;
import com.watabou.utils.Bundle; import com.watabou.utils.Bundle;
import com.watabou.utils.Callback;
import com.watabou.utils.Random; import com.watabou.utils.Random;
import java.util.ArrayList; import java.util.ArrayList;
@ -70,8 +72,11 @@ public class Blacksmith extends NPC {
if (!Quest.given) { if (!Quest.given) {
GameScene.show( new WndQuest( this, Game.runOnRenderThread(new Callback() {
Quest.alternative ? Messages.get(this, "blood_1") : Messages.get(this, "gold_1") ) { @Override
public void call() {
GameScene.show( new WndQuest( Blacksmith.this,
Quest.alternative ? Messages.get(Blacksmith.this, "blood_1") : Messages.get(Blacksmith.this, "gold_1") ) {
@Override @Override
public void onBackPressed() { public void onBackPressed() {
@ -88,6 +93,8 @@ public class Blacksmith extends NPC {
} }
} }
} ); } );
}
});
Notes.add( Notes.Landmark.TROLL ); Notes.add( Notes.Landmark.TROLL );
@ -133,7 +140,12 @@ public class Blacksmith extends NPC {
} }
} else if (!Quest.reforged) { } else if (!Quest.reforged) {
GameScene.show( new WndBlacksmith( this, Dungeon.hero ) ); Game.runOnRenderThread(new Callback() {
@Override
public void call() {
GameScene.show( new WndBlacksmith( Blacksmith.this, Dungeon.hero ) );
}
});
} else { } else {

View File

@ -49,8 +49,10 @@ import com.shatteredpixel.shatteredpixeldungeon.sprites.GhostSprite;
import com.shatteredpixel.shatteredpixeldungeon.utils.GLog; import com.shatteredpixel.shatteredpixeldungeon.utils.GLog;
import com.shatteredpixel.shatteredpixeldungeon.windows.WndQuest; import com.shatteredpixel.shatteredpixeldungeon.windows.WndQuest;
import com.shatteredpixel.shatteredpixeldungeon.windows.WndSadGhost; import com.shatteredpixel.shatteredpixeldungeon.windows.WndSadGhost;
import com.watabou.noosa.Game;
import com.watabou.noosa.audio.Sample; import com.watabou.noosa.audio.Sample;
import com.watabou.utils.Bundle; import com.watabou.utils.Bundle;
import com.watabou.utils.Callback;
import com.watabou.utils.Random; import com.watabou.utils.Random;
import com.watabou.utils.Reflection; import com.watabou.utils.Reflection;
@ -114,20 +116,30 @@ public class Ghost extends NPC {
if (Quest.given) { if (Quest.given) {
if (Quest.weapon != null) { if (Quest.weapon != null) {
if (Quest.processed) { if (Quest.processed) {
GameScene.show(new WndSadGhost(this, Quest.type)); Game.runOnRenderThread(new Callback() {
@Override
public void call() {
GameScene.show(new WndSadGhost(Ghost.this, Quest.type));
}
});
} else { } else {
Game.runOnRenderThread(new Callback() {
@Override
public void call() {
switch (Quest.type) { switch (Quest.type) {
case 1: case 1:
default: default:
GameScene.show(new WndQuest(this, Messages.get(this, "rat_2"))); GameScene.show(new WndQuest(Ghost.this, Messages.get(Ghost.this, "rat_2")));
break; break;
case 2: case 2:
GameScene.show(new WndQuest(this, Messages.get(this, "gnoll_2"))); GameScene.show(new WndQuest(Ghost.this, Messages.get(Ghost.this, "gnoll_2")));
break; break;
case 3: case 3:
GameScene.show(new WndQuest(this, Messages.get(this, "crab_2"))); GameScene.show(new WndQuest(Ghost.this, Messages.get(Ghost.this, "crab_2")));
break; break;
} }
}
});
int newPos = -1; int newPos = -1;
for (int i = 0; i < 10; i++) { for (int i = 0; i < 10; i++) {
@ -165,9 +177,14 @@ public class Ghost extends NPC {
if (questBoss.pos != -1) { if (questBoss.pos != -1) {
GameScene.add(questBoss); GameScene.add(questBoss);
GameScene.show( new WndQuest( this, txt_quest ) );
Quest.given = true; Quest.given = true;
Notes.add( Notes.Landmark.GHOST ); Notes.add( Notes.Landmark.GHOST );
Game.runOnRenderThread(new Callback() {
@Override
public void call() {
GameScene.show( new WndQuest( Ghost.this, txt_quest ) );
}
});
} }
} }

View File

@ -37,7 +37,9 @@ import com.shatteredpixel.shatteredpixeldungeon.scenes.GameScene;
import com.shatteredpixel.shatteredpixeldungeon.sprites.ImpSprite; import com.shatteredpixel.shatteredpixeldungeon.sprites.ImpSprite;
import com.shatteredpixel.shatteredpixeldungeon.windows.WndImp; import com.shatteredpixel.shatteredpixeldungeon.windows.WndImp;
import com.shatteredpixel.shatteredpixeldungeon.windows.WndQuest; import com.shatteredpixel.shatteredpixeldungeon.windows.WndQuest;
import com.watabou.noosa.Game;
import com.watabou.utils.Bundle; import com.watabou.utils.Bundle;
import com.watabou.utils.Callback;
import com.watabou.utils.PathFinder; import com.watabou.utils.PathFinder;
import com.watabou.utils.Random; import com.watabou.utils.Random;
@ -94,7 +96,12 @@ public class Imp extends NPC {
DwarfToken tokens = Dungeon.hero.belongings.getItem( DwarfToken.class ); DwarfToken tokens = Dungeon.hero.belongings.getItem( DwarfToken.class );
if (tokens != null && (tokens.quantity() >= 8 || (!Quest.alternative && tokens.quantity() >= 6))) { if (tokens != null && (tokens.quantity() >= 8 || (!Quest.alternative && tokens.quantity() >= 6))) {
GameScene.show( new WndImp( this, tokens ) ); Game.runOnRenderThread(new Callback() {
@Override
public void call() {
GameScene.show( new WndImp( Imp.this, tokens ) );
}
});
} else { } else {
tell( Quest.alternative ? tell( Quest.alternative ?
Messages.get(this, "monks_2", Dungeon.hero.givenName()) Messages.get(this, "monks_2", Dungeon.hero.givenName())
@ -113,8 +120,12 @@ public class Imp extends NPC {
} }
private void tell( String text ) { private void tell( String text ) {
GameScene.show( Game.runOnRenderThread(new Callback() {
new WndQuest( this, text )); @Override
public void call() {
GameScene.show( new WndQuest( Imp.this, text ));
}
});
} }
public void flee() { public void flee() {

View File

@ -32,6 +32,8 @@ import com.shatteredpixel.shatteredpixeldungeon.scenes.GameScene;
import com.shatteredpixel.shatteredpixeldungeon.sprites.ShopkeeperSprite; import com.shatteredpixel.shatteredpixeldungeon.sprites.ShopkeeperSprite;
import com.shatteredpixel.shatteredpixeldungeon.windows.WndBag; import com.shatteredpixel.shatteredpixeldungeon.windows.WndBag;
import com.shatteredpixel.shatteredpixeldungeon.windows.WndTradeItem; import com.shatteredpixel.shatteredpixeldungeon.windows.WndTradeItem;
import com.watabou.noosa.Game;
import com.watabou.utils.Callback;
public class Shopkeeper extends NPC { public class Shopkeeper extends NPC {
@ -100,7 +102,12 @@ public class Shopkeeper extends NPC {
@Override @Override
public boolean interact() { public boolean interact() {
Game.runOnRenderThread(new Callback() {
@Override
public void call() {
sell(); sell();
}
});
return false; return false;
} }
} }

View File

@ -42,7 +42,9 @@ import com.shatteredpixel.shatteredpixeldungeon.scenes.GameScene;
import com.shatteredpixel.shatteredpixeldungeon.sprites.WandmakerSprite; import com.shatteredpixel.shatteredpixeldungeon.sprites.WandmakerSprite;
import com.shatteredpixel.shatteredpixeldungeon.windows.WndQuest; import com.shatteredpixel.shatteredpixeldungeon.windows.WndQuest;
import com.shatteredpixel.shatteredpixeldungeon.windows.WndWandmaker; import com.shatteredpixel.shatteredpixeldungeon.windows.WndWandmaker;
import com.watabou.noosa.Game;
import com.watabou.utils.Bundle; import com.watabou.utils.Bundle;
import com.watabou.utils.Callback;
import com.watabou.utils.Random; import com.watabou.utils.Random;
import java.util.ArrayList; import java.util.ArrayList;
@ -100,11 +102,16 @@ public class Wandmaker extends NPC {
} }
if (item != null) { if (item != null) {
GameScene.show( new WndWandmaker( this, item ) ); Game.runOnRenderThread(new Callback() {
@Override
public void call() {
GameScene.show( new WndWandmaker( Wandmaker.this, item ) );
}
});
} else { } else {
String msg = ""; String msg;
switch(Quest.type){ switch(Quest.type){
case 1: case 1: default:
msg = Messages.get(this, "reminder_dust", Dungeon.hero.givenName()); msg = Messages.get(this, "reminder_dust", Dungeon.hero.givenName());
break; break;
case 2: case 2:
@ -114,7 +121,12 @@ public class Wandmaker extends NPC {
msg = Messages.get(this, "reminder_berry", Dungeon.hero.givenName()); msg = Messages.get(this, "reminder_berry", Dungeon.hero.givenName());
break; break;
} }
GameScene.show(new WndQuest(this, msg)); Game.runOnRenderThread(new Callback() {
@Override
public void call() {
GameScene.show(new WndQuest(Wandmaker.this, msg));
}
});
} }
} else { } else {
@ -151,14 +163,19 @@ public class Wandmaker extends NPC {
} }
msg2 += Messages.get(this, "intro_2"); msg2 += Messages.get(this, "intro_2");
final String msg2final = msg2; final String msg1Final = msg1;
final NPC wandmaker = this; final String msg2Final = msg2;
GameScene.show(new WndQuest(wandmaker, msg1){ Game.runOnRenderThread(new Callback() {
@Override
public void call() {
GameScene.show(new WndQuest(Wandmaker.this, msg1Final){
@Override @Override
public void hide() { public void hide() {
super.hide(); super.hide();
GameScene.show(new WndQuest(wandmaker, msg2final)); GameScene.show(new WndQuest(Wandmaker.this, msg2Final));
}
});
} }
}); });

View File

@ -27,6 +27,7 @@ import com.shatteredpixel.shatteredpixeldungeon.tiles.DungeonTilemap;
import com.watabou.noosa.Camera; import com.watabou.noosa.Camera;
import com.watabou.noosa.Game; import com.watabou.noosa.Game;
import com.watabou.noosa.RenderedText; import com.watabou.noosa.RenderedText;
import com.watabou.utils.Callback;
import com.watabou.utils.SparseArray; import com.watabou.utils.SparseArray;
import java.util.ArrayList; import java.util.ArrayList;
@ -40,8 +41,6 @@ public class FloatingText extends RenderedText {
private int key = -1; private int key = -1;
private float cameraZoom = -1;
private static final SparseArray<ArrayList<FloatingText>> stacks = new SparseArray<>(); private static final SparseArray<ArrayList<FloatingText>> stacks = new SparseArray<>();
public FloatingText() { public FloatingText() {
@ -83,12 +82,8 @@ public class FloatingText extends RenderedText {
revive(); revive();
if (cameraZoom != Camera.main.zoom) { size( 9 * PixelScene.defaultZoom);
cameraZoom = Camera.main.zoom; scale.set( 1 / (float)PixelScene.defaultZoom );
PixelScene.chooseFont( 9, cameraZoom );
size( 9 * (int)cameraZoom);
scale.set( 1 /cameraZoom );
}
text( text ); text( text );
hardlight( color ); hardlight( color );
@ -102,19 +97,29 @@ public class FloatingText extends RenderedText {
/* STATIC METHODS */ /* STATIC METHODS */
public static void show( float x, float y, String text, int color ) { public static void show( float x, float y, String text, int color ) {
Game.runOnRenderThread(new Callback() {
@Override
public void call() {
FloatingText txt = GameScene.status(); FloatingText txt = GameScene.status();
if (txt != null){ if (txt != null){
txt.reset(x, y, text, color); txt.reset(x, y, text, color);
} }
} }
});
}
public static void show( float x, float y, int key, String text, int color ) { public static void show( float x, float y, int key, String text, int color ) {
Game.runOnRenderThread(new Callback() {
@Override
public void call() {
FloatingText txt = GameScene.status(); FloatingText txt = GameScene.status();
if (txt != null) { if (txt != null){
txt.reset(x, y, text, color); txt.reset(x, y, text, color);
push(txt, key); push(txt, key);
} }
} }
});
}
private static void push( FloatingText txt, int key ) { private static void push( FloatingText txt, int key ) {

View File

@ -44,6 +44,7 @@ import com.shatteredpixel.shatteredpixeldungeon.windows.WndOptions;
import com.watabou.noosa.Camera; import com.watabou.noosa.Camera;
import com.watabou.noosa.Game; import com.watabou.noosa.Game;
import com.watabou.noosa.audio.Sample; import com.watabou.noosa.audio.Sample;
import com.watabou.utils.Callback;
import com.watabou.utils.Random; import com.watabou.utils.Random;
public class Chasm { public class Chasm {
@ -51,6 +52,9 @@ public class Chasm {
public static boolean jumpConfirmed = false; public static boolean jumpConfirmed = false;
public static void heroJump( final Hero hero ) { public static void heroJump( final Hero hero ) {
Game.runOnRenderThread(new Callback() {
@Override
public void call() {
GameScene.show( GameScene.show(
new WndOptions( Messages.get(Chasm.class, "chasm"), new WndOptions( Messages.get(Chasm.class, "chasm"),
Messages.get(Chasm.class, "jump"), Messages.get(Chasm.class, "jump"),
@ -66,6 +70,8 @@ public class Chasm {
} }
); );
} }
});
}
public static void heroFall( int pos ) { public static void heroFall( int pos ) {

View File

@ -536,6 +536,8 @@ public class GameScene extends PixelScene {
if (Runtime.getRuntime().availableProcessors() == 1) { if (Runtime.getRuntime().availableProcessors() == 1) {
actorThread.setPriority(Thread.NORM_PRIORITY - 1); actorThread.setPriority(Thread.NORM_PRIORITY - 1);
} }
actorThread.setName("SHPD Actor Thread");
Thread.currentThread().setName("SHPD Render Thread");
actorThread.start(); actorThread.start();
} else { } else {
synchronized (actorThread) { synchronized (actorThread) {

View File

@ -48,21 +48,11 @@ public class GameLog extends Component implements Signal.Listener<String> {
recreateLines(); recreateLines();
} }
private synchronized void recreateLines() { private static ArrayList<String> textsToAdd = new ArrayList<>();
for (Entry entry : entries) {
lastEntry = PixelScene.renderMultiline( entry.text, 6 );
lastEntry.hardlight( lastColor = entry.color );
add( lastEntry );
}
}
public synchronized void newLine() {
lastEntry = null;
}
@Override @Override
public synchronized boolean onSignal( String text ) { public synchronized void update() {
for (String text : textsToAdd){
if (length != entries.size()){ if (length != entries.size()){
clear(); clear();
recreateLines(); recreateLines();
@ -124,8 +114,30 @@ public class GameLog extends Component implements Signal.Listener<String> {
lastEntry = null; lastEntry = null;
} }
} }
}
if (!textsToAdd.isEmpty()){
layout(); layout();
textsToAdd.clear();
}
super.update();
}
private synchronized void recreateLines() {
for (Entry entry : entries) {
lastEntry = PixelScene.renderMultiline( entry.text, 6 );
lastEntry.hardlight( lastColor = entry.color );
add( lastEntry );
}
}
public synchronized void newLine() {
lastEntry = null;
}
@Override
public synchronized boolean onSignal( String text ) {
textsToAdd.add(text);
return false; return false;
} }