Skip to content

Commit 565cb69

Browse files
committed
add delay count in application
1 parent 12c5607 commit 565cb69

File tree

2 files changed

+32
-10
lines changed

2 files changed

+32
-10
lines changed

backends/backend-teavm/src/main/java/com/github/xpenatan/gdx/backends/teavm/TeaApplication.java

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import com.github.xpenatan.gdx.backends.teavm.dom.EventListenerWrapper;
2020
import com.github.xpenatan.gdx.backends.teavm.dom.EventWrapper;
2121
import com.github.xpenatan.gdx.backends.teavm.dom.impl.TeaWindow;
22+
import com.github.xpenatan.gdx.backends.teavm.filesystem.FileDB;
2223
import com.github.xpenatan.gdx.backends.teavm.preloader.AssetDownloadImpl;
2324
import com.github.xpenatan.gdx.backends.teavm.preloader.AssetDownloader;
2425
import com.github.xpenatan.gdx.backends.teavm.preloader.AssetDownloader.AssetDownload;
@@ -37,6 +38,8 @@ public class TeaApplication implements Application, Runnable {
3738

3839
private static TeaAgentInfo agentInfo;
3940

41+
public int delayInitCount;
42+
4043
public static TeaAgentInfo getAgentInfo() {
4144
return agentInfo;
4245
}
@@ -56,7 +59,7 @@ public static TeaApplication get() {
5659
private final Array<LifecycleListener> lifecycleListeners = new Array<LifecycleListener>(4);
5760
private TeaWindow window;
5861

59-
private AppState initState = AppState.LOAD_ASSETS;
62+
private AppState initState = AppState.INIT;
6063

6164
private int lastWidth = -1;
6265
private int lastHeight = 1;
@@ -162,8 +165,6 @@ public void handleEvent(EventWrapper evt) {
162165
}
163166
});
164167

165-
window.requestAnimationFrame(this);
166-
167168
if(config.isAutoSizeApplication()) {
168169
window.addEventListener("resize", new EventListenerWrapper() {
169170
@Override
@@ -188,13 +189,21 @@ public void handleEvent(EventWrapper evt) {
188189
}
189190
});
190191
}
192+
193+
// Init database
194+
FileDB.getInstance();
195+
window.requestAnimationFrame(this);
191196
}
192197

193198
@Override
194199
public void run() {
195200
AppState state = initState;
196201
try {
197202
switch(state) {
203+
case INIT:
204+
if(delayInitCount == 0) {
205+
initState = AppState.LOAD_ASSETS;
206+
}
198207
case LOAD_ASSETS:
199208
int queue = AssetDownloader.getInstance().getQueue();
200209
if(queue == 0) {
@@ -448,6 +457,7 @@ public static boolean isMobileDevice () {
448457
}
449458

450459
public enum AppState {
460+
INIT,
451461
LOAD_ASSETS,
452462
APP_CREATE,
453463
APP_LOOP
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package com.github.xpenatan.gdx.backends.teavm.filesystem;
22

3+
import com.badlogic.gdx.Gdx;
4+
import com.github.xpenatan.gdx.backends.teavm.TeaApplication;
35
import com.github.xpenatan.gdx.backends.teavm.TeaFileHandle;
46
import java.io.InputStream;
57
import org.teavm.jso.indexeddb.IDBDatabase;
@@ -8,65 +10,75 @@
810

911
public class IndexedDBStorage extends FileDB {
1012

11-
private IDBDatabase result = null;
13+
private IDBDatabase dataBase = null;
1214

1315
public IndexedDBStorage() {
14-
16+
TeaApplication teaApplication = (TeaApplication)Gdx.app;
17+
teaApplication.delayInitCount++;
1518
IDBFactory instance = IDBFactory.getInstance();
16-
1719
IDBOpenDBRequest request = instance.open("TeaVM", 1);
1820
request.setOnSuccess(() -> {
19-
result = request.getResult();
21+
dataBase = request.getResult();
2022
System.out.println("SUCCESS");
23+
teaApplication.delayInitCount--;
2124
});
2225

2326
request.setOnError(() -> {
2427
System.out.println("ERROR");
28+
teaApplication.delayInitCount--;
2529
});
2630
}
2731

2832
@Override
2933
public InputStream read(TeaFileHandle file) {
34+
35+
System.out.println("1111");
3036
return null;
3137
}
3238

3339
@Override
3440
protected void writeInternal(TeaFileHandle file, byte[] data, boolean append, int expectedLength) {
35-
41+
System.out.println("2222");
3642
}
3743

3844
@Override
3945
protected String[] paths(TeaFileHandle file) {
46+
47+
System.out.println("3333");
4048
return new String[0];
4149
}
4250

4351
@Override
4452
public boolean isDirectory(TeaFileHandle file) {
53+
System.out.println("4444");
4554
return false;
4655
}
4756

4857
@Override
4958
public void mkdirs(TeaFileHandle file) {
50-
59+
System.out.println("5555");
5160
}
5261

5362
@Override
5463
public boolean exists(TeaFileHandle file) {
64+
System.out.println("6666");
5565
return false;
5666
}
5767

5868
@Override
5969
public boolean delete(TeaFileHandle file) {
70+
System.out.println("7777");
6071
return false;
6172
}
6273

6374
@Override
6475
public long length(TeaFileHandle file) {
76+
System.out.println("8888");
6577
return 0;
6678
}
6779

6880
@Override
6981
public void rename(TeaFileHandle source, TeaFileHandle target) {
70-
82+
System.out.println("9999");
7183
}
7284
}

0 commit comments

Comments
 (0)