mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-16 02:38:02 +00:00
Fix checking for GuiThread on Android
This commit is contained in:
@@ -4,6 +4,7 @@ import android.content.pm.ActivityInfo;
|
|||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Environment;
|
import android.os.Environment;
|
||||||
|
import android.os.Looper;
|
||||||
|
|
||||||
import com.badlogic.gdx.Gdx;
|
import com.badlogic.gdx.Gdx;
|
||||||
import com.badlogic.gdx.backends.android.AndroidApplication;
|
import com.badlogic.gdx.backends.android.AndroidApplication;
|
||||||
@@ -35,6 +36,8 @@ public class Main extends AndroidApplication {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
initialize(new Forge(getClipboard(), assetsDir), true);
|
Forge app = new Forge();
|
||||||
|
app.initialize(Looper.getMainLooper().getThread(), getClipboard(), assetsDir);
|
||||||
|
initialize(app, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,13 @@ import forge.util.Utils;
|
|||||||
|
|
||||||
public class Main {
|
public class Main {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
new LwjglApplication(new Forge(new LwjglClipboard(), "../forge-gui/"), "Forge", (int)Utils.BASE_WIDTH, (int)Utils.BASE_HEIGHT, true);
|
new ForgeApplication(new Forge());
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class ForgeApplication extends LwjglApplication {
|
||||||
|
private ForgeApplication(Forge app) {
|
||||||
|
super(app, "Forge", (int)Utils.BASE_WIDTH, (int)Utils.BASE_HEIGHT, true);
|
||||||
|
app.initialize(mainLoopThread, new LwjglClipboard(), "../forge-gui/");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ import forge.toolbox.FOverlay;
|
|||||||
import forge.util.Utils;
|
import forge.util.Utils;
|
||||||
|
|
||||||
public class Forge implements ApplicationListener {
|
public class Forge implements ApplicationListener {
|
||||||
private static Forge game;
|
private static boolean initialized;
|
||||||
private static Clipboard clipboard;
|
private static Clipboard clipboard;
|
||||||
private static int screenWidth;
|
private static int screenWidth;
|
||||||
private static int screenHeight;
|
private static int screenHeight;
|
||||||
@@ -51,13 +51,16 @@ public class Forge implements ApplicationListener {
|
|||||||
private static KeyInputAdapter keyInputAdapter;
|
private static KeyInputAdapter keyInputAdapter;
|
||||||
private static final Stack<FScreen> screens = new Stack<FScreen>();
|
private static final Stack<FScreen> screens = new Stack<FScreen>();
|
||||||
|
|
||||||
public Forge(Clipboard clipboard0, String assetDir0) {
|
public Forge() {
|
||||||
if (game != null) {
|
}
|
||||||
|
|
||||||
|
public void initialize(Thread guiThread, Clipboard clipboard0, String assetDir0) {
|
||||||
|
if (initialized) {
|
||||||
throw new RuntimeException("Cannot initialize Forge more than once");
|
throw new RuntimeException("Cannot initialize Forge more than once");
|
||||||
}
|
}
|
||||||
game = this;
|
|
||||||
clipboard = clipboard0;
|
clipboard = clipboard0;
|
||||||
GuiBase.setInterface(new GuiMobile(assetDir0));
|
GuiBase.setInterface(new GuiMobile(guiThread, assetDir0));
|
||||||
|
initialized = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -51,8 +51,10 @@ import forge.util.WaitRunnable;
|
|||||||
import forge.util.gui.SGuiChoose;
|
import forge.util.gui.SGuiChoose;
|
||||||
|
|
||||||
public class GuiMobile implements IGuiBase {
|
public class GuiMobile implements IGuiBase {
|
||||||
|
private final Thread guiThread;
|
||||||
private final String assetsDir;
|
private final String assetsDir;
|
||||||
public GuiMobile(String assetsDir0) {
|
public GuiMobile(Thread guiThread0, String assetsDir0) {
|
||||||
|
guiThread = guiThread0;
|
||||||
assetsDir = assetsDir0;
|
assetsDir = assetsDir0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -78,7 +80,7 @@ public class GuiMobile implements IGuiBase {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isGuiThread() {
|
public boolean isGuiThread() {
|
||||||
return Thread.currentThread().getName().startsWith("LWJGL");
|
return Thread.currentThread() == guiThread;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
Reference in New Issue
Block a user