update gwt
This commit is contained in:
parent
2d18e7d25f
commit
5cb3eb9dd1
@ -16,8 +16,6 @@
|
|||||||
|
|
||||||
package com.badlogic.gdx.backends.gwt;
|
package com.badlogic.gdx.backends.gwt;
|
||||||
|
|
||||||
import org.oscim.backend.GL20;
|
|
||||||
|
|
||||||
import com.badlogic.gdx.Application;
|
import com.badlogic.gdx.Application;
|
||||||
import com.badlogic.gdx.ApplicationListener;
|
import com.badlogic.gdx.ApplicationListener;
|
||||||
import com.badlogic.gdx.Audio;
|
import com.badlogic.gdx.Audio;
|
||||||
@ -31,6 +29,7 @@ import com.badlogic.gdx.Preferences;
|
|||||||
import com.badlogic.gdx.backends.gwt.preloader.Preloader;
|
import com.badlogic.gdx.backends.gwt.preloader.Preloader;
|
||||||
import com.badlogic.gdx.backends.gwt.preloader.Preloader.PreloaderCallback;
|
import com.badlogic.gdx.backends.gwt.preloader.Preloader.PreloaderCallback;
|
||||||
import com.badlogic.gdx.backends.gwt.preloader.Preloader.PreloaderState;
|
import com.badlogic.gdx.backends.gwt.preloader.Preloader.PreloaderState;
|
||||||
|
import com.badlogic.gdx.graphics.GL20;
|
||||||
import com.badlogic.gdx.utils.Array;
|
import com.badlogic.gdx.utils.Array;
|
||||||
import com.badlogic.gdx.utils.Clipboard;
|
import com.badlogic.gdx.utils.Clipboard;
|
||||||
import com.badlogic.gdx.utils.ObjectMap;
|
import com.badlogic.gdx.utils.ObjectMap;
|
||||||
@ -45,11 +44,13 @@ import com.google.gwt.dom.client.Style.Unit;
|
|||||||
import com.google.gwt.user.client.Timer;
|
import com.google.gwt.user.client.Timer;
|
||||||
import com.google.gwt.user.client.ui.HasHorizontalAlignment;
|
import com.google.gwt.user.client.ui.HasHorizontalAlignment;
|
||||||
import com.google.gwt.user.client.ui.HasVerticalAlignment;
|
import com.google.gwt.user.client.ui.HasVerticalAlignment;
|
||||||
|
import com.google.gwt.user.client.ui.Image;
|
||||||
import com.google.gwt.user.client.ui.InlineHTML;
|
import com.google.gwt.user.client.ui.InlineHTML;
|
||||||
import com.google.gwt.user.client.ui.Label;
|
import com.google.gwt.user.client.ui.Label;
|
||||||
import com.google.gwt.user.client.ui.Panel;
|
import com.google.gwt.user.client.ui.Panel;
|
||||||
import com.google.gwt.user.client.ui.RootPanel;
|
import com.google.gwt.user.client.ui.RootPanel;
|
||||||
import com.google.gwt.user.client.ui.SimplePanel;
|
import com.google.gwt.user.client.ui.SimplePanel;
|
||||||
|
import com.google.gwt.user.client.ui.TextArea;
|
||||||
import com.google.gwt.user.client.ui.VerticalPanel;
|
import com.google.gwt.user.client.ui.VerticalPanel;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -67,23 +68,30 @@ public abstract class GwtApplication implements EntryPoint, Application {
|
|||||||
private GwtInput input;
|
private GwtInput input;
|
||||||
private GwtNet net;
|
private GwtNet net;
|
||||||
private Panel root = null;
|
private Panel root = null;
|
||||||
|
private TextArea log = null;
|
||||||
private int logLevel = LOG_ERROR;
|
private int logLevel = LOG_ERROR;
|
||||||
private Array<Runnable> runnables = new Array<Runnable>();
|
private Array<Runnable> runnables = new Array<Runnable>();
|
||||||
private Array<Runnable> runnablesHelper = new Array<Runnable>();
|
private Array<Runnable> runnablesHelper = new Array<Runnable>();
|
||||||
private Array<LifecycleListener> lifecycleListeners = new Array<LifecycleListener>();
|
private Array<LifecycleListener> lifecycleListeners = new Array<LifecycleListener>();
|
||||||
private int lastWidth, lastHeight;
|
private int lastWidth;
|
||||||
private Preloader preloader;
|
private int lastHeight;
|
||||||
|
Preloader preloader;
|
||||||
private static AgentInfo agentInfo;
|
private static AgentInfo agentInfo;
|
||||||
private ObjectMap<String, Preferences> prefs = new ObjectMap<String, Preferences>();
|
private ObjectMap<String, Preferences> prefs = new ObjectMap<String, Preferences>();
|
||||||
|
|
||||||
/** @return the configuration for the {@link GwtApplication}. */
|
/** @return the configuration for the {@link GwtApplication}. */
|
||||||
public abstract GwtApplicationConfiguration getConfig();
|
public abstract GwtApplicationConfiguration getConfig();
|
||||||
|
|
||||||
|
public String getPreloaderBaseURL() {
|
||||||
|
return GWT.getHostPageBaseURL() + "assets/";
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onModuleLoad() {
|
public void onModuleLoad() {
|
||||||
GwtApplication.agentInfo = computeAgentInfo();
|
GwtApplication.agentInfo = computeAgentInfo();
|
||||||
this.listener = getApplicationListener();
|
this.listener = getApplicationListener();
|
||||||
this.config = getConfig();
|
this.config = getConfig();
|
||||||
|
this.log = config.log;
|
||||||
|
|
||||||
if (config.rootPanel != null) {
|
if (config.rootPanel != null) {
|
||||||
this.root = config.rootPanel;
|
this.root = config.rootPanel;
|
||||||
@ -110,8 +118,13 @@ public abstract class GwtApplication implements EntryPoint, Application {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//// initialize SoundManager2
|
||||||
|
//SoundManager.init(GWT.getModuleBaseURL(), 9, true, new SoundManager.SoundManagerCallback() {
|
||||||
|
//
|
||||||
|
// @Override
|
||||||
|
// public void onready () {
|
||||||
final PreloaderCallback callback = getPreloaderCallback();
|
final PreloaderCallback callback = getPreloaderCallback();
|
||||||
preloader = new Preloader();
|
preloader = createPreloader();
|
||||||
preloader.preload("assets.txt", new PreloaderCallback() {
|
preloader.preload("assets.txt", new PreloaderCallback() {
|
||||||
@Override
|
@Override
|
||||||
public void error(String file) {
|
public void error(String file) {
|
||||||
@ -122,14 +135,21 @@ public abstract class GwtApplication implements EntryPoint, Application {
|
|||||||
public void update(PreloaderState state) {
|
public void update(PreloaderState state) {
|
||||||
callback.update(state);
|
callback.update(state);
|
||||||
if (state.hasEnded()) {
|
if (state.hasEnded()) {
|
||||||
root.clear();
|
getRootPanel().clear();
|
||||||
setupLoop();
|
setupLoop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
//}
|
||||||
|
//@Override
|
||||||
|
//public void ontimeout (String status, String errorType) {
|
||||||
|
// error("SoundManager", status + " " + errorType);
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
//});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setupLoop() {
|
void setupLoop() {
|
||||||
// setup modules
|
// setup modules
|
||||||
try {
|
try {
|
||||||
graphics = new GwtGraphics(root, config);
|
graphics = new GwtGraphics(root, config);
|
||||||
@ -138,10 +158,8 @@ public abstract class GwtApplication implements EntryPoint, Application {
|
|||||||
root.add(new Label("Sorry, your browser doesn't seem to support WebGL"));
|
root.add(new Label("Sorry, your browser doesn't seem to support WebGL"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
lastWidth = graphics.getWidth();
|
lastWidth = graphics.getWidth();
|
||||||
lastHeight = graphics.getHeight();
|
lastHeight = graphics.getHeight();
|
||||||
|
|
||||||
Gdx.app = this;
|
Gdx.app = this;
|
||||||
//Gdx.audio = new GwtAudio();
|
//Gdx.audio = new GwtAudio();
|
||||||
Gdx.graphics = graphics;
|
Gdx.graphics = graphics;
|
||||||
@ -152,42 +170,44 @@ public abstract class GwtApplication implements EntryPoint, Application {
|
|||||||
Gdx.input = this.input;
|
Gdx.input = this.input;
|
||||||
this.net = new GwtNet();
|
this.net = new GwtNet();
|
||||||
Gdx.net = this.net;
|
Gdx.net = this.net;
|
||||||
final double pixelRatio = GwtGraphics.getDevicePixelRatioJSNI();
|
|
||||||
consoleLog("> " + config.width + "x" + config.height + " ratio:" + pixelRatio);
|
|
||||||
|
|
||||||
// tell listener about app creation
|
// tell listener about app creation
|
||||||
try {
|
try {
|
||||||
listener.create();
|
listener.create();
|
||||||
listener.resize(
|
listener.resize(graphics.getWidth(), graphics.getHeight());
|
||||||
(int) (graphics.getWidth()),
|
|
||||||
(int) (graphics.getHeight()));
|
|
||||||
} catch (Throwable t) {
|
} catch (Throwable t) {
|
||||||
error("GwtApplication", "exception: " + t.getMessage(), t);
|
error("GwtApplication", "exception: " + t.getMessage(), t);
|
||||||
t.printStackTrace();
|
t.printStackTrace();
|
||||||
throw new RuntimeException(t);
|
throw new RuntimeException(t);
|
||||||
}
|
}
|
||||||
|
|
||||||
final int frameTime = (int) ((1f / config.fps) * 1000);
|
|
||||||
|
|
||||||
Gdx.gl.glClearColor(1, 1, 1, 1);
|
Gdx.gl.glClearColor(1, 1, 1, 1);
|
||||||
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
|
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
|
||||||
|
|
||||||
|
final int frameTime = (int) ((1f / config.fps) * 1000);
|
||||||
|
|
||||||
// setup rendering timer
|
// setup rendering timer
|
||||||
new Timer() {
|
new Timer() {
|
||||||
//long lastRun;
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
//long startRender = 0;
|
|
||||||
try {
|
try {
|
||||||
graphics.update();
|
mainLoop(this, frameTime);
|
||||||
if (graphics.getWidth() != lastWidth
|
} catch (Throwable t) {
|
||||||
|| graphics.getHeight() != lastHeight) {
|
error("GwtApplication", "exception: " + t.getMessage(), t);
|
||||||
|
throw new RuntimeException(t);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//}.scheduleRepeating((int) ((1f / config.fps) * 1000));
|
||||||
|
}.schedule(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
void mainLoop(Timer timer, int frameTime) {
|
||||||
|
graphics.update();
|
||||||
|
if (Gdx.graphics.getWidth() != lastWidth || Gdx.graphics.getHeight() != lastHeight) {
|
||||||
|
GwtApplication.this.listener.resize(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
|
||||||
lastWidth = graphics.getWidth();
|
lastWidth = graphics.getWidth();
|
||||||
lastHeight = graphics.getHeight();
|
lastHeight = graphics.getHeight();
|
||||||
|
Gdx.gl.glViewport(0, 0, lastWidth, lastHeight);
|
||||||
GwtApplication.this.listener.resize(lastWidth, lastHeight);
|
|
||||||
//Gdx.gl.glViewport(0, 0, lastWidth, lastHeight);
|
|
||||||
}
|
}
|
||||||
runnablesHelper.addAll(runnables);
|
runnablesHelper.addAll(runnables);
|
||||||
runnables.clear();
|
runnables.clear();
|
||||||
@ -195,26 +215,13 @@ public abstract class GwtApplication implements EntryPoint, Application {
|
|||||||
runnablesHelper.get(i).run();
|
runnablesHelper.get(i).run();
|
||||||
}
|
}
|
||||||
runnablesHelper.clear();
|
runnablesHelper.clear();
|
||||||
//startRender = System.currentTimeMillis();
|
|
||||||
listener.render();
|
listener.render();
|
||||||
input.justTouched = false;
|
input.justTouched = false;
|
||||||
} catch (Throwable t) {
|
|
||||||
error("GwtApplication", "exception: " + t.getMessage(), t);
|
|
||||||
throw new RuntimeException(t);
|
|
||||||
}
|
|
||||||
|
|
||||||
long now = System.currentTimeMillis();
|
long now = System.currentTimeMillis();
|
||||||
int diff = (int) (now - graphics.lastTimeStamp);
|
int diff = (int) (now - graphics.lastTimeStamp);
|
||||||
|
|
||||||
//if (diff > 80)
|
|
||||||
// consoleLog("diff " + diff + " " + (now - startRender) + " " + graphics.getFramesPerSecond() );
|
|
||||||
|
|
||||||
diff = frameTime - diff;
|
diff = frameTime - diff;
|
||||||
//lastRun = now;
|
timer.schedule(diff > 5 ? diff : 5);
|
||||||
|
|
||||||
this.schedule(diff > 5 ? diff : 5);
|
|
||||||
}
|
|
||||||
}.schedule(0); //scheduleRepeating((int) ((1f / config.fps) * 1000));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Panel getRootPanel() {
|
public Panel getRootPanel() {
|
||||||
@ -223,14 +230,16 @@ public abstract class GwtApplication implements EntryPoint, Application {
|
|||||||
|
|
||||||
long loadStart = TimeUtils.nanoTime();
|
long loadStart = TimeUtils.nanoTime();
|
||||||
|
|
||||||
|
public Preloader createPreloader() {
|
||||||
|
return new Preloader(getPreloaderBaseURL());
|
||||||
|
}
|
||||||
|
|
||||||
public PreloaderCallback getPreloaderCallback() {
|
public PreloaderCallback getPreloaderCallback() {
|
||||||
final Panel preloaderPanel = new VerticalPanel();
|
final Panel preloaderPanel = new VerticalPanel();
|
||||||
preloaderPanel.setStyleName("gdx-preloader");
|
preloaderPanel.setStyleName("gdx-preloader");
|
||||||
|
final Image logo = new Image(GWT.getModuleBaseURL() + "logo.png");
|
||||||
//final Image logo = new Image(GWT.getModuleBaseURL() + "logo.png");
|
logo.setStyleName("logo");
|
||||||
//logo.setStyleName("logo");
|
preloaderPanel.add(logo);
|
||||||
//preloaderPanel.add(logo);
|
|
||||||
|
|
||||||
final Panel meterPanel = new SimplePanel();
|
final Panel meterPanel = new SimplePanel();
|
||||||
meterPanel.setStyleName("gdx-meter");
|
meterPanel.setStyleName("gdx-meter");
|
||||||
meterPanel.addStyleName("red");
|
meterPanel.addStyleName("red");
|
||||||
@ -288,7 +297,7 @@ public abstract class GwtApplication implements EntryPoint, Application {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void log(String tag, String message, Exception exception) {
|
public void log(String tag, String message, Throwable exception) {
|
||||||
if (logLevel >= LOG_INFO) {
|
if (logLevel >= LOG_INFO) {
|
||||||
consoleLog(tag + ": " + message + "\n" + exception.getMessage());
|
consoleLog(tag + ": " + message + "\n" + exception.getMessage());
|
||||||
consoleLog(getStackTrace(exception));
|
consoleLog(getStackTrace(exception));
|
||||||
@ -337,6 +346,11 @@ public abstract class GwtApplication implements EntryPoint, Application {
|
|||||||
this.logLevel = logLevel;
|
this.logLevel = logLevel;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getLogLevel() {
|
||||||
|
return logLevel;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ApplicationType getType() {
|
public ApplicationType getType() {
|
||||||
return ApplicationType.WebGL;
|
return ApplicationType.WebGL;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user