Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions src/org/andengine/engine/Engine.java
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ public class Engine implements SensorEventListener, OnTouchListener, ITouchEvent

protected int mSurfaceWidth = 1; // 1 to prevent accidental DIV/0
protected int mSurfaceHeight = 1; // 1 to prevent accidental DIV/0
private volatile boolean mIsLagging;

// ===========================================================
// Constructors
Expand Down Expand Up @@ -580,11 +581,15 @@ private void throwOnDestroyed() throws EngineDestroyedException {
}

public void onUpdate(final long pNanosecondsElapsed) throws InterruptedException {
final float pSecondsElapsed = pNanosecondsElapsed * TimeConstants.SECONDS_PER_NANOSECOND;
float pSecondsElapsed = pNanosecondsElapsed * TimeConstants.SECONDS_PER_NANOSECOND;

this.mSecondsElapsedTotal += pSecondsElapsed;
this.mLastTick += pNanosecondsElapsed;

if (this.mIsLagging) {
pSecondsElapsed = 16666666 * TimeConstants.SECONDS_PER_NANOSECOND;
}

this.mTouchController.onUpdate(pSecondsElapsed);
this.onUpdateUpdateHandlers(pSecondsElapsed);
this.onUpdateScene(pSecondsElapsed);
Expand Down Expand Up @@ -613,9 +618,10 @@ public void onDrawFrame(final GLState pGLState) throws InterruptedException {
try {
engineLock.waitUntilCanDraw();

this.mVertexBufferObjectManager.updateVertexBufferObjects(pGLState);
this.mTextureManager.updateTextures(pGLState);
this.mFontManager.updateFonts(pGLState);
this.mIsLagging = false;
this.mIsLagging |= this.mVertexBufferObjectManager.updateVertexBufferObjects(pGLState);
this.mIsLagging |= this.mTextureManager.updateTextures(pGLState);
this.mIsLagging |= this.mFontManager.updateFonts(pGLState);

this.onUpdateDrawHandlers(pGLState, this.mCamera);
this.onDrawScene(pGLState, this.mCamera);
Expand Down
11 changes: 10 additions & 1 deletion src/org/andengine/opengl/font/FontManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public class FontManager {
private final ArrayList<Font> mFontsManaged = new ArrayList<Font>();
private final ArrayList<BitmapFont> mBitmapFontsManaged = new ArrayList<BitmapFont>();
private final HashMap<String, IFont> mFontsMapped = new HashMap<String, IFont>();
private boolean mReloading;

// ===========================================================
// Constructors
Expand Down Expand Up @@ -141,17 +142,25 @@ public synchronized void unloadFonts(final BitmapFont ... pBitmapFonts) {
}
}

public synchronized void updateFonts(final GLState pGLState) {
public synchronized boolean updateFonts(final GLState pGLState) {
final ArrayList<Font> fonts = this.mFontsManaged;
final int fontCount = fonts.size();
if(fontCount > 0){
for(int i = fontCount - 1; i >= 0; i--){
fonts.get(i).update(pGLState);
}
}

if (this.mReloading) {
this.mReloading = false;
return true;
} else {
return false;
}
}

public synchronized void onReload() {
this.mReloading = true;
final ArrayList<Font> managedFonts = this.mFontsManaged;
for(int i = managedFonts.size() - 1; i >= 0; i--) {
managedFonts.get(i).invalidateLetters();
Expand Down
11 changes: 10 additions & 1 deletion src/org/andengine/opengl/texture/TextureManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public class TextureManager {
private final ArrayList<ITexture> mTexturesToBeUnloaded = new ArrayList<ITexture>();

private TextureWarmUpVertexBufferObject mTextureWarmUpVertexBufferObject;
private boolean mReloading;

// ===========================================================
// Constructors
Expand All @@ -61,6 +62,7 @@ public synchronized void onCreate() {
}

public synchronized void onReload() {
this.mReloading = true;
final HashSet<ITexture> managedTextures = this.mTexturesManaged;
if(!managedTextures.isEmpty()) {
for(final ITexture texture : managedTextures) { // TODO Can the use of the iterator be avoided somehow?
Expand Down Expand Up @@ -225,7 +227,7 @@ public synchronized boolean unloadTexture(final GLState pGLState, final ITexture
}
}

public synchronized void updateTextures(final GLState pGLState) {
public synchronized boolean updateTextures(final GLState pGLState) {
final HashSet<ITexture> texturesManaged = this.mTexturesManaged;
final ArrayList<ITexture> texturesLoaded = this.mTexturesLoaded;
final ArrayList<ITexture> texturesToBeLoaded = this.mTexturesToBeLoaded;
Expand Down Expand Up @@ -281,6 +283,13 @@ public synchronized void updateTextures(final GLState pGLState) {
if((texturesToBeLoadedCount > 0) || (texturesToBeUnloadedCount > 0)) {
System.gc();
}

if (this.mReloading) {
this.mReloading = false;
return true;
} else {
return false;
}
}

public synchronized ITexture getTexture(final String pID, final AssetManager pAssetManager, final String pAssetPath) throws IOException {
Expand Down
12 changes: 11 additions & 1 deletion src/org/andengine/opengl/vbo/VertexBufferObjectManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ public class VertexBufferObjectManager {

private final ArrayList<IVertexBufferObject> mVertexBufferObjectsToBeUnloaded = new ArrayList<IVertexBufferObject>();

private boolean mReloading;

// ===========================================================
// Constructors
// ===========================================================
Expand Down Expand Up @@ -91,6 +93,7 @@ public synchronized void onUnloadVertexBufferObject(final IVertexBufferObject pV
}

public synchronized void onReload() {
this.mReloading = true;
final ArrayList<IVertexBufferObject> vertexBufferObjectsLoaded = this.mVertexBufferObjectsLoaded;
for(int i = vertexBufferObjectsLoaded.size() - 1; i >= 0; i--) {
vertexBufferObjectsLoaded.get(i).setNotLoadedToHardware();
Expand All @@ -99,7 +102,7 @@ public synchronized void onReload() {
vertexBufferObjectsLoaded.clear();
}

public synchronized void updateVertexBufferObjects(final GLState pGLState) {
public synchronized boolean updateVertexBufferObjects(final GLState pGLState) {
final ArrayList<IVertexBufferObject> vertexBufferObjectsLoaded = this.mVertexBufferObjectsLoaded;
final ArrayList<IVertexBufferObject> vertexBufferObjectsToBeUnloaded = this.mVertexBufferObjectsToBeUnloaded;

Expand All @@ -111,6 +114,13 @@ public synchronized void updateVertexBufferObjects(final GLState pGLState) {
}
vertexBufferObjectsLoaded.remove(vertexBufferObjectToBeUnloaded);
}

if (this.mReloading) {
this.mReloading = false;
return true;
} else {
return false;
}
}

// ===========================================================
Expand Down