From b8c23d8c6ffd1fd251bdaf3e7e6b28e788420515 Mon Sep 17 00:00:00 2001 From: badlogicgames Date: Fri, 16 Mar 2012 14:12:40 +0000 Subject: [PATCH] [fixed] GwtGL20 didn't deallocate texture ids [fixed] GwtGraphics reports ppi/ppc/density [fixed] Everything should use TimeUtils#nanoTime/millies instead of System.nanoTime for greater portability. [fixed] AssetManager fully functional :D [fixed] added missing methods to Pixmap emu class [fixed] added missing methods to Texture emu class [added] ParticleEffect emu class [fixed] ShaderProgram emu class now handles setting uniforms correctly... [fixed] Matrix4 emu class now emulates all original Matrix4 methods [added] ArrayMap, SerializationException to emu package [changed] All the tests are fixed up. Made a list of tests in GwtTestStarter that work. This excludes any tests using box2d, scene2d or OpenGL ES 1.0. [fixed] other classes so we can have more complete gwt backend support. --- .../badlogic/gdx/backends/gwt/GwtApplication.java | 4 + .../badlogic/gdx/backends/gwt/GwtFileHandle.java | 7 + .../src/com/badlogic/gdx/backends/gwt/GwtGL20.java | 7 +- .../com/badlogic/gdx/backends/gwt/GwtGraphics.java | 10 +- .../com/badlogic/gdx/backends/gwt/GwtInput.java | 7 +- .../com/badlogic/gdx/assets/AssetLoadingTask.java | 60 +++- .../emu/com/badlogic/gdx/assets/AssetManager.java | 34 +- .../badlogic/gdx/assets/loaders/TextureLoader.java | 98 ++++++ .../loaders/resolvers/ResolutionFileResolver.java | 86 +++++ .../com/badlogic/gdx/files/FileHandleStream.java | 86 +++++ .../gwt/emu/com/badlogic/gdx/graphics/Pixmap.java | 12 + .../gwt/emu/com/badlogic/gdx/graphics/Texture.java | 11 +- .../badlogic/gdx/graphics/g2d/ParticleEffect.java | 190 +++++++++++ .../gdx/graphics/glutils/ShaderProgram.java | 6 +- .../gwt/emu/com/badlogic/gdx/math/Matrix4.java | 80 ++--- .../gwt/emu/com/badlogic/gdx/utils/ArrayMap.java | 374 +++++++++++++++++++++ .../badlogic/gdx/utils/SerializationException.java | 69 ++++ .../gwt/emu/com/badlogic/gdx/utils/TimeUtils.java | 23 ++ gdx/src/com/badlogic/gdx.gwt.xml | 304 +++++++++++------ .../com/badlogic/gdx/assets/AssetLoadingTask.java | 3 +- gdx/src/com/badlogic/gdx/assets/AssetManager.java | 3 +- .../gdx/graphics/g3d/keyframed/KeyframedModel.java | 18 +- .../gdx/graphics/g3d/loaders/md5/MD5Jni.java | 2 +- .../com/badlogic/gdx/input/GestureDetector.java | 7 +- gdx/src/com/badlogic/gdx/scenes/scene2d/Actor.java | 2 +- .../badlogic/gdx/scenes/scene2d/ui/TextField.java | 3 +- gdx/src/com/badlogic/gdx/utils/Base64Coder.java | 2 +- .../com/badlogic/gdx/utils/GwtModuleGenerator.java | 116 +++++++ gdx/src/com/badlogic/gdx/utils/TimeUtils.java | 23 ++ tests/gdx-tests-android/assets/assets.txt | 28 +- tests/gdx-tests-gwt/.classpath | 2 +- .../.settings/com.google.gwt.eclipse.core.prefs | 4 +- .../gdx/tests/gwt/client/GwtTestStarter.java | 85 ++++- tests/gdx-tests-gwt/war/assets.txt | 2 +- .../gdx/tests/lwjgl/LwjglDebugStarter.java | 14 +- .../src/com/badlogic/gdx/GdxTests.gwt.xml | 54 ++- .../com/badlogic/gdx/tests/AssetManagerTest.java | 49 ++- .../gdx/tests/BitmapFontAlignmentTest.java | 3 +- .../com/badlogic/gdx/tests/BitmapFontFlipTest.java | 3 +- .../src/com/badlogic/gdx/tests/BitmapFontTest.java | 28 +- .../com/badlogic/gdx/tests/BufferUtilsTest.java | 97 +++--- .../src/com/badlogic/gdx/tests/DecalTest.java | 16 +- .../src/com/badlogic/gdx/tests/DeltaTimeTest.java | 5 +- .../src/com/badlogic/gdx/tests/FillrateTest.java | 7 +- .../badlogic/gdx/tests/IntegerBitmapFontTest.java | 4 +- .../badlogic/gdx/tests/InverseKinematicsTest.java | 27 +- .../com/badlogic/gdx/tests/IsometricTileTest.java | 48 ++- .../src/com/badlogic/gdx/tests/MD5Test.java | 13 +- .../src/com/badlogic/gdx/tests/MatrixJNITest.java | 29 +- .../src/com/badlogic/gdx/tests/MeshShaderTest.java | 2 +- .../src/com/badlogic/gdx/tests/MultitouchTest.java | 79 +---- .../src/com/badlogic/gdx/tests/MusicTest.java | 2 +- .../src/com/badlogic/gdx/tests/ParallaxTest.java | 2 +- .../badlogic/gdx/tests/ParticleEmitterTest.java | 3 +- .../com/badlogic/gdx/tests/PixelsPerInchTest.java | 6 +- .../com/badlogic/gdx/tests/PixmapBlendingTest.java | 5 +- .../src/com/badlogic/gdx/tests/PixmapTest.java | 7 - .../com/badlogic/gdx/tests/ShapeRendererTest.java | 2 +- .../badlogic/gdx/tests/SimpleAnimationTest.java | 47 +-- .../src/com/badlogic/gdx/tests/SimpleTest.java | 101 ------ .../badlogic/gdx/tests/SpriteBatchShaderTest.java | 41 +-- .../com/badlogic/gdx/tests/SpriteBatchTest.java | 51 +-- .../com/badlogic/gdx/tests/SpriteCacheTest.java | 42 ++- .../badlogic/gdx/tests/SpritePerformanceTest.java | 7 +- .../src/com/badlogic/gdx/tests/TerrainTest.java | 7 +- .../com/badlogic/gdx/tests/TextureBindTestGL2.java | 8 - .../badlogic/gdx/tests/TexturePackerAtlasTest.java | 21 -- .../src/com/badlogic/gdx/tests/VBOVATest.java | 9 +- .../gdx/tests/VertexBufferObjectShaderTest.java | 15 +- .../src/com/badlogic/gdx/tests/WaterRipples.java | 3 +- .../src/com/badlogic/gdx/tests/YDownTest.java | 2 +- .../src/com/badlogic/gdx/tests/utils/GdxTests.java | 4 +- 72 files changed, 1897 insertions(+), 734 deletions(-) create mode 100644 backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/com/badlogic/gdx/assets/loaders/TextureLoader.java create mode 100644 backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/com/badlogic/gdx/assets/loaders/resolvers/ResolutionFileResolver.java create mode 100644 backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/com/badlogic/gdx/files/FileHandleStream.java create mode 100644 backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/com/badlogic/gdx/graphics/g2d/ParticleEffect.java create mode 100644 backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/com/badlogic/gdx/utils/ArrayMap.java create mode 100644 backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/com/badlogic/gdx/utils/SerializationException.java create mode 100644 backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/com/badlogic/gdx/utils/TimeUtils.java create mode 100644 gdx/src/com/badlogic/gdx/utils/GwtModuleGenerator.java create mode 100644 gdx/src/com/badlogic/gdx/utils/TimeUtils.java delete mode 100644 tests/gdx-tests/src/com/badlogic/gdx/tests/SimpleTest.java delete mode 100644 tests/gdx-tests/src/com/badlogic/gdx/tests/TextureBindTestGL2.java delete mode 100644 tests/gdx-tests/src/com/badlogic/gdx/tests/TexturePackerAtlasTest.java diff --git a/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/GwtApplication.java b/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/GwtApplication.java index 21f4352e9..894288eb0 100644 --- a/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/GwtApplication.java +++ b/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/GwtApplication.java @@ -425,4 +425,8 @@ public abstract class GwtApplication implements EntryPoint, Application { public String getBaseUrl () { return preloader.baseUrl; } + + public Preloader getPreloader () { + return preloader; + } } diff --git a/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/GwtFileHandle.java b/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/GwtFileHandle.java index 0080143a4..9e11a71a1 100644 --- a/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/GwtFileHandle.java +++ b/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/GwtFileHandle.java @@ -12,6 +12,7 @@ import java.io.UnsupportedEncodingException; import java.io.Writer; import com.badlogic.gdx.Files.FileType; +import com.badlogic.gdx.Gdx; import com.badlogic.gdx.backends.gwt.preloader.Preloader; import com.badlogic.gdx.files.FileHandle; import com.badlogic.gdx.utils.GdxRuntimeException; @@ -27,6 +28,12 @@ public class GwtFileHandle extends FileHandle { this.file = fileName; this.type = type; } + + public GwtFileHandle(String path) { + this.type = FileType.Internal; + this.preloader = ((GwtApplication)Gdx.app).getPreloader(); + this.file = path; + } public String path () { return file; diff --git a/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/GwtGL20.java b/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/GwtGL20.java index a844a22cf..b67336f97 100644 --- a/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/GwtGL20.java +++ b/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/GwtGL20.java @@ -243,6 +243,7 @@ public class GwtGL20 implements GL20 { for(int i = 0; i < n; i++) { int id = textures.get(); WebGLTexture texture = this.textures.get(id); + deallocateTextureId(id); gl.deleteTexture(texture); } } @@ -274,8 +275,7 @@ public class GwtGL20 implements GL20 { @Override public void glDrawElements (int mode, int count, int type, Buffer indices) { - // FIXME this assumes that we actually use index buffers, not index arrays... - gl.drawElements(mode, count, type, indices.position()); + gl.drawElements(mode, count, type, indices.position()); // FIXME this is assuming WebGL supports client side buffers... } @Override @@ -344,8 +344,7 @@ public class GwtGL20 implements GL20 { @Override public void glReadPixels (int x, int y, int width, int height, int format, int type, Buffer pixels) { - // FIXME - throw new GdxRuntimeException("not implemented"); + throw new GdxRuntimeException("Not supported by GWT backend"); } @Override diff --git a/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/GwtGraphics.java b/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/GwtGraphics.java index a949a0e76..87a88145c 100644 --- a/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/GwtGraphics.java +++ b/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/GwtGraphics.java @@ -130,22 +130,22 @@ public class GwtGraphics implements Graphics { @Override public float getPpiX () { - return 0; + return 96; } @Override public float getPpiY () { - return 0; + return 96; } @Override public float getPpcX () { - return 0; + return 96 / 2.54f; } @Override public float getPpcY () { - return 0; + return 96 / 2.54f; } @Override @@ -268,7 +268,7 @@ public class GwtGraphics implements Graphics { @Override public float getDensity () { - throw new GdxRuntimeException("No supported"); + return 96 / 160; } @Override diff --git a/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/GwtInput.java b/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/GwtInput.java index 2c3f2823f..276be55f0 100644 --- a/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/GwtInput.java +++ b/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/GwtInput.java @@ -7,6 +7,7 @@ import java.util.Set; import com.badlogic.gdx.Gdx; import com.badlogic.gdx.Input; import com.badlogic.gdx.InputProcessor; +import com.badlogic.gdx.utils.TimeUtils; import com.google.gwt.core.client.JavaScriptObject; import com.google.gwt.dom.client.Document; import com.google.gwt.dom.client.Element; @@ -321,7 +322,7 @@ public class GwtInput implements Input { this.deltaY = 0; this.mouseX = (int)getRelativeX(e, canvas); this.mouseY = (int)getRelativeY(e, canvas); - this.currentEventTimeStamp = System.currentTimeMillis() * 1000; + this.currentEventTimeStamp = TimeUtils.nanoTime(); if(processor != null) processor.touchDown(mouseX, mouseY, 0, getButton(e.getButton())); } @@ -330,7 +331,7 @@ public class GwtInput implements Input { this.deltaY = (int)getRelativeY(e, canvas) - mouseY; this.mouseX = (int)getRelativeX(e, canvas); this.mouseY = (int)getRelativeY(e, canvas); - this.currentEventTimeStamp = System.currentTimeMillis() * 1000; + this.currentEventTimeStamp = TimeUtils.nanoTime(); if(processor != null) { if(touched) processor.touchDragged(mouseX, mouseY, 0); else processor.touchMoved(mouseX, mouseY); @@ -345,7 +346,7 @@ public class GwtInput implements Input { this.deltaY = (int)getRelativeY(e, canvas) - mouseY; this.mouseX = (int)getRelativeX(e, canvas); this.mouseY = (int)getRelativeY(e, canvas); - this.currentEventTimeStamp = System.currentTimeMillis() * 1000; + this.currentEventTimeStamp = TimeUtils.nanoTime(); this.touched = false; if(processor != null) processor.touchUp(mouseX, mouseY, 0, getButton(e.getButton())); } diff --git a/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/com/badlogic/gdx/assets/AssetLoadingTask.java b/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/com/badlogic/gdx/assets/AssetLoadingTask.java index 84cce091c..ff31a66fd 100644 --- a/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/com/badlogic/gdx/assets/AssetLoadingTask.java +++ b/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/com/badlogic/gdx/assets/AssetLoadingTask.java @@ -1,17 +1,19 @@ package com.badlogic.gdx.assets; -import java.util.ArrayList; - import com.badlogic.gdx.assets.loaders.AssetLoader; +import com.badlogic.gdx.assets.loaders.AsynchronousAssetLoader; +import com.badlogic.gdx.assets.loaders.SynchronousAssetLoader; +import com.badlogic.gdx.utils.Array; public class AssetLoadingTask { AssetManager manager; public AssetDescriptor assetDesc; AssetLoader loader; - public boolean cancel; - public long startTime; - public boolean dependenciesLoaded; - public ArrayList dependencies; + boolean cancel; + long startTime; + boolean dependenciesLoaded; + Array dependencies; + Object asset; public AssetLoadingTask(AssetManager manager, AssetDescriptor desc, AssetLoader loader) { this.manager = manager; @@ -20,9 +22,51 @@ public class AssetLoadingTask { } public boolean update () { - return false; + if(loader instanceof AsynchronousAssetLoader) { + handleAsynchLoader((AsynchronousAssetLoader)loader); + } else { + handleSynchLoader((SynchronousAssetLoader)loader); + } + return asset != null; + } + + private void handleSynchLoader (SynchronousAssetLoader loader) { + if(!dependenciesLoaded) { + Array dependencies = loader.getDependencies(assetDesc.fileName, assetDesc.params); + if (dependencies != null) { + for (AssetDescriptor desc : dependencies) { + manager.injectDependency(assetDesc.fileName, desc); + } + dependenciesLoaded = true; + } else { + // if we have no dependencies, we load the async part of the task immediately. + asset = loader.load(manager, assetDesc.fileName, assetDesc.params); + } + } else { + asset = loader.load(manager, assetDesc.fileName, assetDesc.params); + } } + + private void handleAsynchLoader(AsynchronousAssetLoader loader) { + if(!dependenciesLoaded) { + Array dependencies = loader.getDependencies(assetDesc.fileName, assetDesc.params); + if (dependencies != null) { + for (AssetDescriptor desc : dependencies) { + manager.injectDependency(assetDesc.fileName, desc); + } + dependenciesLoaded = true; + } else { + // we can load everything we are always on the rendering thread. + loader.loadAsync(manager, assetDesc.fileName, assetDesc.params); + asset = loader.loadSync(manager, assetDesc.fileName, assetDesc.params); + } + } else { + loader.loadAsync(manager, assetDesc.fileName, assetDesc.params); + asset = loader.loadSync(manager, assetDesc.fileName, assetDesc.params); + } + } + public Object getAsset () { - return null; + return asset; } } diff --git a/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/com/badlogic/gdx/assets/AssetManager.java b/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/com/badlogic/gdx/assets/AssetManager.java index 8b71b376a..d78160653 100644 --- a/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/com/badlogic/gdx/assets/AssetManager.java +++ b/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/com/badlogic/gdx/assets/AssetManager.java @@ -20,8 +20,20 @@ import java.util.ArrayList; import java.util.Stack; import com.badlogic.gdx.assets.loaders.AssetLoader; +import com.badlogic.gdx.assets.loaders.BitmapFontLoader; import com.badlogic.gdx.assets.loaders.FileHandleResolver; +import com.badlogic.gdx.assets.loaders.MusicLoader; +import com.badlogic.gdx.assets.loaders.PixmapLoader; +import com.badlogic.gdx.assets.loaders.SoundLoader; +import com.badlogic.gdx.assets.loaders.TextureAtlasLoader; +import com.badlogic.gdx.assets.loaders.TextureLoader; import com.badlogic.gdx.assets.loaders.resolvers.InternalFileHandleResolver; +import com.badlogic.gdx.audio.Music; +import com.badlogic.gdx.audio.Sound; +import com.badlogic.gdx.graphics.Pixmap; +import com.badlogic.gdx.graphics.Texture; +import com.badlogic.gdx.graphics.g2d.BitmapFont; +import com.badlogic.gdx.graphics.g2d.TextureAtlas; import com.badlogic.gdx.utils.Array; import com.badlogic.gdx.utils.Disposable; import com.badlogic.gdx.utils.GdxRuntimeException; @@ -48,12 +60,12 @@ public class AssetManager implements Disposable { /** Creates a new AssetManager with all default loaders. */ public AssetManager (FileHandleResolver resolver) { -// setLoader(BitmapFont.class, new BitmapFontLoader(resolver)); -// setLoader(Music.class, new MusicLoader(resolver)); -// setLoader(Pixmap.class, new PixmapLoader(resolver)); -// setLoader(Sound.class, new SoundLoader(resolver)); -// setLoader(TextureAtlas.class, new TextureAtlasLoader(resolver)); -// setLoader(Texture.class, new TextureLoader(resolver)); + setLoader(BitmapFont.class, new BitmapFontLoader(resolver)); + setLoader(Music.class, new MusicLoader(resolver)); + setLoader(Pixmap.class, new PixmapLoader(resolver)); + setLoader(Sound.class, new SoundLoader(resolver)); + setLoader(TextureAtlas.class, new TextureAtlasLoader(resolver)); + setLoader(Texture.class, new TextureLoader(resolver)); // setLoader(Skin.class, new SkinLoader(resolver)); // setLoader(TileMapRenderer.class, new TileMapRendererLoader(resolver)); } @@ -324,8 +336,7 @@ public class AssetManager implements Disposable { private void addTask (AssetDescriptor assetDesc) { AssetLoader loader = loaders.get(assetDesc.type); if (loader == null) throw new GdxRuntimeException("No loader for type: " + assetDesc.type.getName()); - // FIXME -// tasks.push(new AssetLoadingTask(this, assetDesc, loader, threadPool)); + tasks.push(new AssetLoadingTask(this, assetDesc, loader)); } /** Updates the current task on the top of the task stack. @@ -445,13 +456,6 @@ public class AssetManager implements Disposable { public synchronized void dispose () { // log.debug("Disposing."); clear(); - // FIXME -// threadPool.shutdown(); -// try { -// threadPool.awaitTermination(Long.MAX_VALUE, TimeUnit.SECONDS); -// } catch (InterruptedException e) { -// new GdxRuntimeException("Couldn't shutdown loading thread"); -// } } /** Clears and disposes all assets and the preloading queue. */ diff --git a/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/com/badlogic/gdx/assets/loaders/TextureLoader.java b/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/com/badlogic/gdx/assets/loaders/TextureLoader.java new file mode 100644 index 000000000..c2b7eac41 --- /dev/null +++ b/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/com/badlogic/gdx/assets/loaders/TextureLoader.java @@ -0,0 +1,98 @@ +/******************************************************************************* + * Copyright 2011 See AUTHORS file. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ******************************************************************************/ + +package com.badlogic.gdx.assets.loaders; + +import com.badlogic.gdx.assets.AssetDescriptor; +import com.badlogic.gdx.assets.AssetLoaderParameters; +import com.badlogic.gdx.assets.AssetManager; +import com.badlogic.gdx.files.FileHandle; +import com.badlogic.gdx.graphics.Pixmap; +import com.badlogic.gdx.graphics.Pixmap.Format; +import com.badlogic.gdx.graphics.Texture; +import com.badlogic.gdx.graphics.Texture.TextureFilter; +import com.badlogic.gdx.graphics.Texture.TextureWrap; +import com.badlogic.gdx.graphics.TextureData; +import com.badlogic.gdx.graphics.glutils.FileTextureData; +import com.badlogic.gdx.utils.Array; + +public class TextureLoader extends AsynchronousAssetLoader { + TextureData data; + Texture texture; + + public TextureLoader (FileHandleResolver resolver) { + super(resolver); + } + + @Override + public void loadAsync (AssetManager manager, String fileName, TextureParameter parameter) { + if (parameter == null || (parameter != null && parameter.textureData == null)) { + Pixmap pixmap = null; + Format format = null; + boolean genMipMaps = false; + texture = null; + + if (parameter != null) { + format = parameter.format; + genMipMaps = parameter.genMipMaps; + texture = parameter.texture; + } + + FileHandle handle = resolve(fileName); + pixmap = new Pixmap(handle); + data = new FileTextureData(handle, pixmap, format, genMipMaps); + } else { + data = parameter.textureData; + if(!data.isPrepared()) data.prepare(); + texture = parameter.texture; + } + } + + @Override + public Texture loadSync (AssetManager manager, String fileName, TextureParameter parameter) { + Texture texture = this.texture; + if (texture != null) { + texture.load(data); + } else { + texture = new Texture(data); + } + if (parameter != null) { + texture.setFilter(parameter.minFilter, parameter.magFilter); + texture.setWrap(parameter.wrapU, parameter.wrapV); + } + return texture; + } + + @Override + public Array getDependencies (String fileName, TextureParameter parameter) { + return null; + } + + static public class TextureParameter extends AssetLoaderParameters { + /** the format of the final Texture. Uses the source images format if null **/ + public Format format = null; + /** whether to generate mipmaps **/ + public boolean genMipMaps = false; + /** The texture to put the {@link TextureData} in, optional. **/ + public Texture texture = null; + /** TextureData for textures created on the fly, optional. When set, all format and genMipMaps are ignored */ + public TextureData textureData = null; + public TextureFilter minFilter = TextureFilter.Nearest; + public TextureFilter magFilter = TextureFilter.Nearest; + public TextureWrap wrapU = TextureWrap.ClampToEdge; + public TextureWrap wrapV = TextureWrap.ClampToEdge; + } +} diff --git a/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/com/badlogic/gdx/assets/loaders/resolvers/ResolutionFileResolver.java b/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/com/badlogic/gdx/assets/loaders/resolvers/ResolutionFileResolver.java new file mode 100644 index 000000000..55dab5988 --- /dev/null +++ b/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/com/badlogic/gdx/assets/loaders/resolvers/ResolutionFileResolver.java @@ -0,0 +1,86 @@ +/******************************************************************************* + * Copyright 2011 See AUTHORS file. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ******************************************************************************/ + +package com.badlogic.gdx.assets.loaders.resolvers; + +import com.badlogic.gdx.Gdx; +import com.badlogic.gdx.assets.loaders.FileHandleResolver; +import com.badlogic.gdx.assets.loaders.resolvers.ResolutionFileResolver.Resolution; +import com.badlogic.gdx.backends.gwt.GwtFileHandle; +import com.badlogic.gdx.files.FileHandle; + +public class ResolutionFileResolver implements FileHandleResolver { + public static class Resolution { + int portraitWidth; + int portraitHeight; + String suffix; + + public Resolution (int portraitWidth, int portraitHeight, String suffix) { + this.portraitWidth = portraitWidth; + this.portraitHeight = portraitHeight; + this.suffix = suffix; + } + } + + final FileHandleResolver baseResolver; + final Resolution[] descriptors; + + public ResolutionFileResolver (FileHandleResolver baseResolver, Resolution... descriptors) { + this.baseResolver = baseResolver; + this.descriptors = descriptors; + } + + @Override + public FileHandle resolve (String fileName) { + Resolution bestDesc = choose(descriptors); + FileHandle originalHandle = new GwtFileHandle(fileName); + FileHandle handle = baseResolver.resolve(resolve(originalHandle, bestDesc.suffix)); + if (!handle.exists()) handle = baseResolver.resolve(fileName); + return handle; + } + + protected String resolve (FileHandle originalHandle, String suffix) { + return originalHandle.parent() + "/" + suffix + "/" + originalHandle.name(); + } + + static public Resolution choose (Resolution... descriptors) { + int width = 0; + if (Gdx.graphics.getWidth() > Gdx.graphics.getHeight()) { + width = Gdx.graphics.getHeight(); + } else { + width = Gdx.graphics.getWidth(); + } + + Resolution bestDesc = null; + // Find lowest. + int best = Integer.MAX_VALUE; + for (int i = 0, n = descriptors.length; i < n; i++) { + if (descriptors[i].portraitWidth < best) { + best = descriptors[i].portraitWidth; + bestDesc = descriptors[i]; + } + } + // Find higher, but not over the screen res. + best = Integer.MAX_VALUE; + for (int i = 0, n = descriptors.length; i < n; i++) { + if (descriptors[i].portraitWidth <= width) { + best = descriptors[i].portraitWidth; + bestDesc = descriptors[i]; + } + } + return bestDesc; + } +} diff --git a/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/com/badlogic/gdx/files/FileHandleStream.java b/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/com/badlogic/gdx/files/FileHandleStream.java new file mode 100644 index 000000000..9a32cae9f --- /dev/null +++ b/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/com/badlogic/gdx/files/FileHandleStream.java @@ -0,0 +1,86 @@ +/******************************************************************************* + * Copyright 2011 See AUTHORS file. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ******************************************************************************/ + +package com.badlogic.gdx.files; + +import java.io.InputStream; +import java.io.OutputStream; + +import com.badlogic.gdx.Files.FileType; +import com.badlogic.gdx.Gdx; +import com.badlogic.gdx.backends.gwt.GwtApplication; +import com.badlogic.gdx.backends.gwt.GwtFileHandle; + +/** A FileHandle intended to be subclassed for the purpose of implementing {@link #read()} and/or {@link #write(boolean)}. Methods + * that would manipulate the file instead throw UnsupportedOperationException. + * @author Nathan Sweet */ +public abstract class FileHandleStream extends GwtFileHandle { + public FileHandleStream (String path) { + super(((GwtApplication)Gdx.app).getPreloader(), path, FileType.Internal); + } + + public boolean isDirectory () { + return false; + } + + public long length () { + return 0; + } + + public boolean exists () { + return true; + } + + public FileHandle child (String name) { + throw new UnsupportedOperationException(); + } + + public FileHandle parent () { + throw new UnsupportedOperationException(); + } + + public InputStream read () { + throw new UnsupportedOperationException(); + } + + public OutputStream write (boolean overwrite) { + throw new UnsupportedOperationException(); + } + + public FileHandle[] list () { + throw new UnsupportedOperationException(); + } + + public void mkdirs () { + throw new UnsupportedOperationException(); + } + + public boolean delete () { + throw new UnsupportedOperationException(); + } + + public boolean deleteDirectory () { + throw new UnsupportedOperationException(); + } + + public void copyTo (FileHandle dest) { + throw new UnsupportedOperationException(); + } + + public void moveTo (FileHandle dest) { + throw new UnsupportedOperationException(); + } +} diff --git a/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/com/badlogic/gdx/graphics/Pixmap.java b/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/com/badlogic/gdx/graphics/Pixmap.java index 5ad4a5fde..8a9aea06d 100644 --- a/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/com/badlogic/gdx/graphics/Pixmap.java +++ b/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/com/badlogic/gdx/graphics/Pixmap.java @@ -140,6 +140,18 @@ public class Pixmap implements Disposable { public Format getFormat () { return format; } + + public int getGLInternalFormat() { + return GL20.GL_RGBA; + } + + public int getGLFormat() { + return GL20.GL_RGBA; + } + + public int getGLType() { + return GL20.GL_UNSIGNED_BYTE; + } public int getWidth () { return width; diff --git a/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/com/badlogic/gdx/graphics/Texture.java b/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/com/badlogic/gdx/graphics/Texture.java index eaf6a0bcd..f1588a14c 100644 --- a/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/com/badlogic/gdx/graphics/Texture.java +++ b/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/com/badlogic/gdx/graphics/Texture.java @@ -3,6 +3,7 @@ package com.badlogic.gdx.graphics; import java.nio.IntBuffer; import com.badlogic.gdx.Gdx; +import com.badlogic.gdx.assets.AssetManager; import com.badlogic.gdx.files.FileHandle; import com.badlogic.gdx.graphics.Pixmap.Format; import com.badlogic.gdx.graphics.TextureData.TextureDataType; @@ -144,7 +145,11 @@ public class Texture { * @param x The x coordinate in pixels * @param y The y coordinate in pixels */ public void draw (Pixmap pixmap, int x, int y) { - throw new GdxRuntimeException("can't draw to a managed texture"); + if (data.isManaged()) throw new GdxRuntimeException("can't draw to a managed texture"); + + Gdx.gl.glBindTexture(GL10.GL_TEXTURE_2D, glHandle); + Gdx.gl.glTexSubImage2D(GL10.GL_TEXTURE_2D, 0, x, y, pixmap.getWidth(), pixmap.getHeight(), pixmap.getGLFormat(), + pixmap.getGLType(), pixmap.getPixels()); } /** @return the width of the texture in pixels */ @@ -215,4 +220,8 @@ public class Texture { Gdx.gl.glDeleteTextures(1, buffer); glHandle = 0; } + + public static void setAssetManager(AssetManager manager) { + // FIXME well not really, no pause/resume cycle + } } diff --git a/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/com/badlogic/gdx/graphics/g2d/ParticleEffect.java b/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/com/badlogic/gdx/graphics/g2d/ParticleEffect.java new file mode 100644 index 000000000..5dfc3b7e8 --- /dev/null +++ b/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/com/badlogic/gdx/graphics/g2d/ParticleEffect.java @@ -0,0 +1,190 @@ +/******************************************************************************* + * Copyright 2011 See AUTHORS file. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ******************************************************************************/ + +package com.badlogic.gdx.graphics.g2d; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.Writer; + +import com.badlogic.gdx.files.FileHandle; +import com.badlogic.gdx.graphics.Texture; +import com.badlogic.gdx.utils.Array; +import com.badlogic.gdx.utils.Disposable; +import com.badlogic.gdx.utils.GdxRuntimeException; + +/** + * See http://www.badlogicgames.com/wordpress/?p=1255 + * @author mzechner + * + */ +public class ParticleEffect implements Disposable { + private final Array emitters; + + public ParticleEffect () { + emitters = new Array(8); + } + + public ParticleEffect (ParticleEffect effect) { + emitters = new Array(true, effect.emitters.size); + for (int i = 0, n = effect.emitters.size; i < n; i++) + emitters.add(new ParticleEmitter(effect.emitters.get(i))); + } + + public void start () { + for (int i = 0, n = emitters.size; i < n; i++) + emitters.get(i).start(); + } + + public void update (float delta) { + for (int i = 0, n = emitters.size; i < n; i++) + emitters.get(i).update(delta); + } + + public void draw (SpriteBatch spriteBatch) { + for (int i = 0, n = emitters.size; i < n; i++) + emitters.get(i).draw(spriteBatch); + } + + public void draw (SpriteBatch spriteBatch, float delta) { + for (int i = 0, n = emitters.size; i < n; i++) + emitters.get(i).draw(spriteBatch, delta); + } + + public void allowCompletion () { + for (int i = 0, n = emitters.size; i < n; i++) + emitters.get(i).allowCompletion(); + } + + public boolean isComplete () { + for (int i = 0, n = emitters.size; i < n; i++) { + ParticleEmitter emitter = emitters.get(i); + if (emitter.isContinuous()) return false; + if (!emitter.isComplete()) return false; + } + return true; + } + + public void setDuration (int duration) { + for (int i = 0, n = emitters.size; i < n; i++) { + ParticleEmitter emitter = emitters.get(i); + emitter.setContinuous(false); + emitter.duration = duration; + emitter.durationTimer = 0; + } + } + + public void setPosition (float x, float y) { + for (int i = 0, n = emitters.size; i < n; i++) + emitters.get(i).setPosition(x, y); + } + + public void setFlip (boolean flipX, boolean flipY) { + for (int i = 0, n = emitters.size; i < n; i++) + emitters.get(i).setFlip(flipX, flipY); + } + + public Array getEmitters () { + return emitters; + } + + /** Returns the emitter with the specified name, or null. */ + public ParticleEmitter findEmitter (String name) { + for (int i = 0, n = emitters.size; i < n; i++) { + ParticleEmitter emitter = emitters.get(i); + if (emitter.getName().equals(name)) return emitter; + } + return null; + } + + public void save (File file) { + throw new GdxRuntimeException("Not supported in GWT backend"); + } + + public void load (FileHandle effectFile, FileHandle imagesDir) { + loadEmitters(effectFile); + loadEmitterImages(imagesDir); + } + + public void load (FileHandle effectFile, TextureAtlas atlas) { + loadEmitters(effectFile); + loadEmitterImages(atlas); + } + + public void loadEmitters (FileHandle effectFile) { + InputStream input = effectFile.read(); + emitters.clear(); + BufferedReader reader = null; + try { + reader = new BufferedReader(new InputStreamReader(input), 512); + while (true) { + ParticleEmitter emitter = new ParticleEmitter(reader); + reader.readLine(); + emitter.setImagePath(reader.readLine()); + emitters.add(emitter); + if (reader.readLine() == null) break; + if (reader.readLine() == null) break; + } + } catch (IOException ex) { + throw new GdxRuntimeException("Error loading effect: " + effectFile, ex); + } finally { + try { + if (reader != null) reader.close(); + } catch (IOException ex) { + } + } + } + + public void loadEmitterImages (TextureAtlas atlas) { + for (int i = 0, n = emitters.size; i < n; i++) { + ParticleEmitter emitter = emitters.get(i); + String imagePath = emitter.getImagePath(); + if (imagePath == null) continue; + String imageName = new File(imagePath.replace('\\', '/')).getName(); + int lastDotIndex = imageName.lastIndexOf('.'); + if (lastDotIndex != -1) imageName = imageName.substring(0, lastDotIndex); + Sprite sprite = atlas.createSprite(imageName); + if (sprite == null) throw new IllegalArgumentException("SpriteSheet missing image: " + imageName); + emitter.setSprite(sprite); + } + } + + public void loadEmitterImages (FileHandle imagesDir) { + for (int i = 0, n = emitters.size; i < n; i++) { + ParticleEmitter emitter = emitters.get(i); + String imagePath = emitter.getImagePath(); + if (imagePath == null) continue; + String imageName = new File(imagePath.replace('\\', '/')).getName(); + emitter.setSprite(new Sprite(loadTexture(imagesDir.child(imageName)))); + } + } + + protected Texture loadTexture (FileHandle file) { + return new Texture(file, false); + } + + /** Disposes the texture for each sprite for each ParticleEmitter. */ + public void dispose () { + for (int i = 0, n = emitters.size; i < n; i++) { + ParticleEmitter emitter = emitters.get(i); + emitter.getSprite().getTexture().dispose(); + } + } +} diff --git a/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/com/badlogic/gdx/graphics/glutils/ShaderProgram.java b/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/com/badlogic/gdx/graphics/glutils/ShaderProgram.java index 5cab24932..b35a9c035 100644 --- a/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/com/badlogic/gdx/graphics/glutils/ShaderProgram.java +++ b/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/com/badlogic/gdx/graphics/glutils/ShaderProgram.java @@ -129,7 +129,6 @@ public class ShaderProgram implements Disposable { private boolean invalidated; /** direct buffer for passing float and int uniform arrays **/ - private ByteBuffer buffer = null; private FloatBuffer floatBuffer = null; public ShaderProgram (FileHandle vertexShader, FileHandle fragmentShader) { @@ -599,9 +598,8 @@ public class ShaderProgram implements Disposable { } private void ensureBufferCapacity (int numBytes) { - if (buffer == null || buffer.capacity() != numBytes) { - buffer = BufferUtils.newByteBuffer(numBytes); - floatBuffer = buffer.asFloatBuffer(); + if (floatBuffer == null || floatBuffer.capacity() != numBytes / 4) { + floatBuffer = BufferUtils.newFloatBuffer(numBytes / 4); } } diff --git a/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/com/badlogic/gdx/math/Matrix4.java b/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/com/badlogic/gdx/math/Matrix4.java index 9e28f222a..265e8d8fb 100644 --- a/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/com/badlogic/gdx/math/Matrix4.java +++ b/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/com/badlogic/gdx/math/Matrix4.java @@ -816,32 +816,32 @@ public class Matrix4 implements Serializable { return true; } - static void matrix4_mulVec(float[] mat, float[] vec) { - float x = vec[0] * mat[M00] + vec[1] * mat[M01] + vec[2] * mat[M02] + mat[M03]; - float y = vec[0] * mat[M10] + vec[1] * mat[M11] + vec[2] * mat[M12] + mat[M13]; - float z = vec[0] * mat[M20] + vec[1] * mat[M21] + vec[2] * mat[M22] + mat[M23]; - vec[0] = x; - vec[1] = y; - vec[2] = z; + static void matrix4_mulVec(float[] mat, float[] vec, int offset) { + float x = vec[offset + 0] * mat[M00] + vec[offset + 1] * mat[M01] + vec[offset + 2] * mat[M02] + mat[M03]; + float y = vec[offset + 0] * mat[M10] + vec[offset + 1] * mat[M11] + vec[offset + 2] * mat[M12] + mat[M13]; + float z = vec[offset + 0] * mat[M20] + vec[offset + 1] * mat[M21] + vec[offset + 2] * mat[M22] + mat[M23]; + vec[offset + 0] = x; + vec[offset + 1] = y; + vec[offset + 2] = z; } - static void matrix4_proj(float[] mat, float[] vec) { - float inv_w = 1.0f / (vec[0] * mat[M30] + vec[1] * mat[M31] + vec[2] * mat[M32] + mat[M33]); - float x = (vec[0] * mat[M00] + vec[1] * mat[M01] + vec[2] * mat[M02] + mat[M03]) * inv_w; - float y = (vec[0] * mat[M10] + vec[1] * mat[M11] + vec[2] * mat[M12] + mat[M13]) * inv_w; - float z = (vec[0] * mat[M20] + vec[1] * mat[M21] + vec[2] * mat[M22] + mat[M23]) * inv_w; - vec[0] = x; - vec[1] = y; - vec[2] = z; + static void matrix4_proj(float[] mat, float[] vec, int offset) { + float inv_w = 1.0f / (vec[offset + 0] * mat[M30] + vec[offset + 1] * mat[M31] + vec[offset + 2] * mat[M32] + mat[M33]); + float x = (vec[offset + 0] * mat[M00] + vec[offset + 1] * mat[M01] + vec[offset + 2] * mat[M02] + mat[M03]) * inv_w; + float y = (vec[offset + 0] * mat[M10] + vec[offset + 1] * mat[M11] + vec[offset + 2] * mat[M12] + mat[M13]) * inv_w; + float z = (vec[offset + 0] * mat[M20] + vec[offset + 1] * mat[M21] + vec[offset + 2] * mat[M22] + mat[M23]) * inv_w; + vec[offset + 0] = x; + vec[offset + 1] = y; + vec[offset + 2] = z; } - static void matrix4_rot(float[] mat, float[] vec) { - float x = vec[0] * mat[M00] + vec[1] * mat[M01] + vec[2] * mat[M02]; - float y = vec[0] * mat[M10] + vec[1] * mat[M11] + vec[2] * mat[M12]; - float z = vec[0] * mat[M20] + vec[1] * mat[M21] + vec[2] * mat[M22]; - vec[0] = x; - vec[1] = y; - vec[2] = z; + static void matrix4_rot(float[] mat, float[] vec, int offset) { + float x = vec[offset + 0] * mat[M00] + vec[offset + 1] * mat[M01] + vec[offset + 2] * mat[M02]; + float y = vec[offset + 0] * mat[M10] + vec[offset + 1] * mat[M11] + vec[offset + 2] * mat[M12]; + float z = vec[offset + 0] * mat[M20] + vec[offset + 1] * mat[M21] + vec[offset + 2] * mat[M22]; + vec[offset + 0] = x; + vec[offset + 1] = y; + vec[offset + 2] = z; } /** Multiplies the matrix mata with matrix matb, storing the result in mata. The arrays are assumed to hold 4x4 column major @@ -860,7 +860,7 @@ public class Matrix4 implements Serializable { * @param mat the matrix * @param vec the vector. */ public static void mulVec (float[] mat, float[] vec) { - matrix4_mulVec(mat, vec); + matrix4_mulVec(mat, vec, 0); } /** Multiplies the vectors with the given matrix. The matrix array is assumed to hold a 4x4 column major matrix as you can get @@ -875,12 +875,10 @@ public class Matrix4 implements Serializable { * @param numVecs the number of vectors * @param stride the stride between vectors in floats */ public static void mulVec (float[] mat, float[] vecs, int offset, int numVecs, int stride) { - // FIXME -// float* vecPtr = vecs + offset; -// for(int i = 0; i < numVecs; i++) { -// matrix4_mulVec(mat, vecPtr); -// vecPtr += stride; -// } + for(int i = 0; i < numVecs; i++) { + matrix4_mulVec(mat, vecs, offset); + offset += stride; + } } /** Multiplies the vector with the given matrix, performing a division by w. The matrix array is assumed to hold a 4x4 column @@ -890,7 +888,7 @@ public class Matrix4 implements Serializable { * @param mat the matrix * @param vec the vector. */ public static void prj (float[] mat, float[] vec) { - matrix4_proj(mat, vec); + matrix4_proj(mat, vec, 0); } /** Multiplies the vectors with the given matrix, , performing a division by w. The matrix array is assumed to hold a 4x4 column @@ -905,12 +903,10 @@ public class Matrix4 implements Serializable { * @param numVecs the number of vectors * @param stride the stride between vectors in floats */ public static void prj (float[] mat, float[] vecs, int offset, int numVecs, int stride) { - // FIXME -// float* vecPtr = vecs + offset; -// for(int i = 0; i < numVecs; i++) { -// matrix4_proj(mat, vecPtr); -// vecPtr += stride; -// } + for(int i = 0; i < numVecs; i++) { + matrix4_proj(mat, vecs, offset); + offset += stride; + } } /** Multiplies the vector with the top most 3x3 sub-matrix of the given matrix. The matrix array is assumed to hold a 4x4 column @@ -920,7 +916,7 @@ public class Matrix4 implements Serializable { * @param mat the matrix * @param vec the vector. */ public static void rot (float[] mat, float[] vec) { - matrix4_rot(mat, vec); + matrix4_rot(mat, vec, 0); } /** Multiplies the vectors with the top most 3x3 sub-matrix of the given matrix. The matrix array is assumed to hold a 4x4 @@ -935,12 +931,10 @@ public class Matrix4 implements Serializable { * @param numVecs the number of vectors * @param stride the stride between vectors in floats */ public static void rot (float[] mat, float[] vecs, int offset, int numVecs, int stride) { - // FIXME -// float* vecPtr = vecs + offset; -// for(int i = 0; i < numVecs; i++) { -// matrix4_rot(mat, vecPtr); -// vecPtr += stride; -// } + for(int i = 0; i < numVecs; i++) { + matrix4_rot(mat, vecs, offset); + offset += stride; + } } /** Computes the inverse of the given matrix. The matrix array is assumed to hold a 4x4 column major matrix as you can get from diff --git a/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/com/badlogic/gdx/utils/ArrayMap.java b/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/com/badlogic/gdx/utils/ArrayMap.java new file mode 100644 index 000000000..b17caef5e --- /dev/null +++ b/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/com/badlogic/gdx/utils/ArrayMap.java @@ -0,0 +1,374 @@ + +package com.badlogic.gdx.utils; + +import com.badlogic.gdx.math.MathUtils; + +// BOZO - Add iterator. + +/** An ordered or unordered map of objects. This implementation uses arrays to store the keys and values, which means + * {@link #getKey(Object, boolean)} does a comparison for each key in the map. This may be acceptable for small maps and has the + * benefits that {@link #put(Object, Object)} and the keys and values can be accessed by index, which makes iteration fast. Like + * {@link Array}, if ordered is false, this class avoids a memory copy when removing elements (the last element is moved to the + * removed element's position). + * @author Nathan Sweet */ +public class ArrayMap { + public K[] keys; + public V[] values; + public int size; + public boolean ordered; + + /** Creates an ordered map with a capacity of 16. */ + public ArrayMap () { + this(true, 16); + } + + /** Creates an ordered map with the specified capacity. */ + public ArrayMap (int capacity) { + this(true, capacity); + } + + /** @param ordered If false, methods that remove elements may change the order of other elements in the arrays, which avoids a + * memory copy. + * @param capacity Any elements added beyond this will cause the backing arrays to be grown. */ + public ArrayMap (boolean ordered, int capacity) { + this.ordered = ordered; + keys = (K[])new Object[capacity]; + values = (V[])new Object[capacity]; + } + + /** Creates a new map with {@link #keys} and {@link #values} of the specified type. + * @param ordered If false, methods that remove elements may change the order of other elements in the arrays, which avoids a + * memory copy. + * @param capacity Any elements added beyond this will cause the backing arrays to be grown. */ + public ArrayMap (boolean ordered, int capacity, Class keyArrayType, Class valueArrayType) { + this.ordered = ordered; + keys = (K[])new Object[capacity]; + values = (V[])new Object[capacity]; + } + + /** Creates an ordered map with {@link #keys} and {@link #values} of the specified type and a capacity of 16. */ + public ArrayMap (Class keyArrayType, Class valueArrayType) { + this(false, 16, keyArrayType, valueArrayType); + } + + /** Creates a new map containing the elements in the specified map. The new map will have the same type of backing arrays and + * will be ordered if the specified map is ordered. The capacity is set to the number of elements, so any subsequent elements + * added will cause the backing arrays to be grown. */ + public ArrayMap (ArrayMap array) { + this(array.ordered, array.size, (Class)array.keys.getClass().getComponentType(), (Class)array.values.getClass() + .getComponentType()); + size = array.size; + System.arraycopy(array.keys, 0, keys, 0, size); + System.arraycopy(array.values, 0, values, 0, size); + } + + public void put (K key, V value) { + if (size == keys.length) resize(Math.max(8, (int)(size * 1.75f))); + keys[size] = key; + values[size++] = value; + } + + public void addAll (ArrayMap map) { + addAll(map, 0, map.size); + } + + public void addAll (ArrayMap map, int offset, int length) { + if (offset + length > map.size) + throw new IllegalArgumentException("offset + length must be <= size: " + offset + " + " + length + " <= " + map.size); + int sizeNeeded = size + length - offset; + if (sizeNeeded >= keys.length) resize(Math.max(8, (int)(sizeNeeded * 1.75f))); + System.arraycopy(map.keys, offset, keys, size, length); + System.arraycopy(map.values, offset, values, size, length); + size += length; + } + + /** Returns the value for the specified key. Note this does a .equals() comparison of each key in reverse order until the + * specified key is found. */ + public V get (K key) { + Object[] keys = this.keys; + int i = size - 1; + if (key == null) { + for (; i >= 0; i--) + if (keys[i] == key) return values[i]; + } else { + for (; i >= 0; i--) + if (key.equals(keys[i])) return values[i]; + } + return null; + } + + /** Returns the value for the specified key. Note this does a comparison of each key in reverse order until the specified key is + * found. + * @param identity If true, == comparison will be used. If false, .equals() comaparison will be used. */ + public V get (K key, boolean identity) { + Object[] keys = this.keys; + int i = size - 1; + if (identity || key == null) { + for (; i >= 0; i--) + if (keys[i] == key) return values[i]; + } else { + for (; i >= 0; i--) + if (key.equals(keys[i])) return values[i]; + } + return null; + } + + /** Returns the key for the specified value. Note this does a comparison of each value in reverse order until the specified + * value is found. + * @param identity If true, == comparison will be used. If false, .equals() comaparison will be used. */ + public K getKey (V value, boolean identity) { + Object[] values = this.values; + int i = size - 1; + if (identity || values == null) { + for (; i >= 0; i--) + if (values[i] == values) return keys[i]; + } else { + for (; i >= 0; i--) + if (values.equals(values[i])) return keys[i]; + } + return null; + } + + public K getKeyAt (int index) { + if (index >= size) throw new IndexOutOfBoundsException(String.valueOf(index)); + return keys[index]; + } + + public V getValueAt (int index) { + if (index >= size) throw new IndexOutOfBoundsException(String.valueOf(index)); + return values[index]; + } + + public void setKey (int index, K key) { + if (index >= size) throw new IndexOutOfBoundsException(String.valueOf(index)); + keys[index] = key; + } + + public void setValue (int index, V value) { + if (index >= size) throw new IndexOutOfBoundsException(String.valueOf(index)); + values[index] = value; + } + + public void insert (int index, K key, V value) { + if (size == keys.length) resize(Math.max(8, (int)(size * 1.75f))); + if (ordered) { + System.arraycopy(keys, index, keys, index + 1, size - index); + System.arraycopy(values, index, values, index + 1, size - index); + } else { + keys[size] = keys[index]; + values[size] = values[index]; + } + size++; + keys[index] = key; + values[index] = value; + } + + /** @param identity If true, == comparison will be used. If false, .equals() comaparison will be used. */ + public boolean containsKey (K key, boolean identity) { + K[] keys = this.keys; + int i = size - 1; + if (identity || key == null) { + while (i >= 0) + if (keys[i--] == key) return true; + } else { + while (i >= 0) + if (key.equals(keys[i--])) return true; + } + return false; + } + + /** @param identity If true, == comparison will be used. If false, .equals() comaparison will be used. */ + public boolean containsValue (V value, boolean identity) { + V[] values = this.values; + int i = size - 1; + if (identity || value == null) { + while (i >= 0) + if (values[i--] == value) return true; + } else { + while (i >= 0) + if (value.equals(values[i--])) return true; + } + return false; + } + + public int indexOfKey (K key, boolean identity) { + Object[] keys = this.keys; + if (identity || key == null) { + for (int i = 0, n = size; i < n; i++) + if (keys[i] == key) return i; + } else { + for (int i = 0, n = size; i < n; i++) + if (key.equals(keys[i])) return i; + } + return -1; + } + + public int indexOfValue (V value, boolean identity) { + Object[] values = this.values; + if (identity || value == null) { + for (int i = 0, n = size; i < n; i++) + if (values[i] == value) return i; + } else { + for (int i = 0, n = size; i < n; i++) + if (value.equals(values[i])) return i; + } + return -1; + } + + public V removeKey (K key, boolean identity) { + Object[] keys = this.keys; + if (identity || key == null) { + for (int i = 0, n = size; i < n; i++) { + if (keys[i] == key) { + V value = values[i]; + removeIndex(i); + return value; + } + } + } else { + for (int i = 0, n = size; i < n; i++) { + if (key.equals(keys[i])) { + V value = values[i]; + removeIndex(i); + return value; + } + } + } + return null; + } + + public boolean removeValue (V value, boolean identity) { + Object[] values = this.values; + if (identity || value == null) { + for (int i = 0, n = size; i < n; i++) { + if (values[i] == value) { + removeIndex(i); + return true; + } + } + } else { + for (int i = 0, n = size; i < n; i++) { + if (value.equals(values[i])) { + removeIndex(i); + return true; + } + } + } + return false; + } + + /** Removes and returns the key/values pair at the specified index. */ + public void removeIndex (int index) { + if (index >= size) throw new IndexOutOfBoundsException(String.valueOf(index)); + Object[] keys = this.keys; + size--; + if (ordered) { + System.arraycopy(keys, index + 1, keys, index, size - index); + System.arraycopy(values, index + 1, values, index, size - index); + } else { + keys[index] = keys[size]; + values[index] = values[size]; + } + keys[size] = null; + values[size] = null; + } + + /** Returns the last key. */ + public K peekKey () { + return keys[size - 1]; + } + + /** Returns the last value. */ + public V peekValue () { + return values[size - 1]; + } + + public void clear () { + K[] keys = this.keys; + V[] values = this.values; + for (int i = 0, n = size; i < n; i++) { + keys[i] = null; + values[i] = null; + } + size = 0; + } + + /** Reduces the size of the backing arrays to the size of the actual number of entries. This is useful to release memory when + * many items have been removed, or if it is known that more entries will not be added. */ + public void shrink () { + resize(size); + } + + /** Increases the size of the backing arrays to acommodate the specified number of additional entries. Useful before adding many + * entries to avoid multiple backing array resizes. */ + public void ensureCapacity (int additionalCapacity) { + int sizeNeeded = size + additionalCapacity; + if (sizeNeeded >= keys.length) resize(Math.max(8, sizeNeeded)); + } + + protected void resize (int newSize) { + K[] newKeys = (K[])new Object[newSize]; + System.arraycopy(keys, 0, newKeys, 0, Math.min(keys.length, newKeys.length)); + this.keys = newKeys; + + V[] newValues = (V[])new Object[newSize]; + System.arraycopy(values, 0, newValues, 0, Math.min(values.length, newValues.length)); + this.values = newValues; + } + + public void reverse () { + for (int i = 0, lastIndex = size - 1, n = size / 2; i < n; i++) { + int ii = lastIndex - i; + K tempKey = keys[i]; + keys[i] = keys[ii]; + keys[ii] = tempKey; + + V tempValue = values[i]; + values[i] = values[ii]; + values[ii] = tempValue; + } + } + + public void shuffle () { + for (int i = size - 1; i >= 0; i--) { + int ii = MathUtils.random(i); + K tempKey = keys[i]; + keys[i] = keys[ii]; + keys[ii] = tempKey; + + V tempValue = values[i]; + values[i] = values[ii]; + values[ii] = tempValue; + } + } + + /** Reduces the size of the arrays to the specified size. If the arrays are already smaller than the specified size, no action + * is taken. */ + public void truncate (int newSize) { + if (size <= newSize) return; + for (int i = newSize; i < size; i++) { + keys[i] = null; + values[i] = null; + } + size = newSize; + } + + public String toString () { + if (size == 0) return "{}"; + K[] keys = this.keys; + V[] values = this.values; + StringBuilder buffer = new StringBuilder(32); + buffer.append('{'); + buffer.append(keys[0]); + buffer.append('='); + buffer.append(values[0]); + for (int i = 1; i < size; i++) { + buffer.append(", "); + buffer.append(keys[i]); + buffer.append('='); + buffer.append(values[i]); + } + buffer.append('}'); + return buffer.toString(); + } +} diff --git a/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/com/badlogic/gdx/utils/SerializationException.java b/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/com/badlogic/gdx/utils/SerializationException.java new file mode 100644 index 000000000..87894a8e8 --- /dev/null +++ b/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/com/badlogic/gdx/utils/SerializationException.java @@ -0,0 +1,69 @@ +/******************************************************************************* + * Copyright 2011 See AUTHORS file. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ******************************************************************************/ + +package com.badlogic.gdx.utils; + +/** Indicates an error during serialization due to misconfiguration or during deserialization due to invalid input data. + * @author Nathan Sweet */ +public class SerializationException extends RuntimeException { + private StringBuffer trace; + + public SerializationException () { + super(); + } + + public SerializationException (String message, Throwable cause) { + super(message, cause); + } + + public SerializationException (String message) { + super(message); + } + + public SerializationException (Throwable cause) { + super("", cause); + } + + /** Returns true if any of the exceptions that caused this exception are of the specified type. */ + public boolean causedBy (Class type) { + return causedBy(this, type); + } + + private boolean causedBy (Throwable ex, Class type) { + Throwable cause = ex.getCause(); + if (cause == null || cause == ex) return false; + return false; + } + + public String getMessage () { + if (trace == null) return super.getMessage(); + StringBuffer buffer = new StringBuffer(512); + buffer.append(super.getMessage()); + if (buffer.length() > 0) buffer.append('\n'); + buffer.append("Serialization trace:"); + buffer.append(trace); + return buffer.toString(); + } + + /** Adds information to the exception message about where in the the object graph serialization failure occurred. Serializers + * can catch {@link SerializationException}, add trace information, and rethrow the exception. */ + public void addTrace (String info) { + if (info == null) throw new IllegalArgumentException("info cannot be null."); + if (trace == null) trace = new StringBuffer(512); + trace.append('\n'); + trace.append(info); + } +} diff --git a/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/com/badlogic/gdx/utils/TimeUtils.java b/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/com/badlogic/gdx/utils/TimeUtils.java new file mode 100644 index 000000000..64c4cf699 --- /dev/null +++ b/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/com/badlogic/gdx/utils/TimeUtils.java @@ -0,0 +1,23 @@ +package com.badlogic.gdx.utils; + +/** + * Wrapper around System.nanoTime() and System.currentTimeMillis(). Use this + * if you want to be compatible across all platforms! + * @author mzechner + * + */ +public class TimeUtils { + /** + * @return The current value of the system timer, in nanoseconds. + */ + public static long nanoTime() { + return System.currentTimeMillis() * 1000000l; + } + + /** + * @return the difference, measured in milliseconds, between the current time and midnight, January 1, 1970 UTC. + */ + public static long millis() { + return System.currentTimeMillis(); + } +} diff --git a/gdx/src/com/badlogic/gdx.gwt.xml b/gdx/src/com/badlogic/gdx.gwt.xml index b98cc2e75..c36d581f9 100644 --- a/gdx/src/com/badlogic/gdx.gwt.xml +++ b/gdx/src/com/badlogic/gdx.gwt.xml @@ -1,103 +1,201 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/gdx/src/com/badlogic/gdx/assets/AssetLoadingTask.java b/gdx/src/com/badlogic/gdx/assets/AssetLoadingTask.java index 7389ed8a9..32fda699b 100644 --- a/gdx/src/com/badlogic/gdx/assets/AssetLoadingTask.java +++ b/gdx/src/com/badlogic/gdx/assets/AssetLoadingTask.java @@ -26,6 +26,7 @@ import com.badlogic.gdx.assets.loaders.SynchronousAssetLoader; import com.badlogic.gdx.utils.Array; import com.badlogic.gdx.utils.GdxRuntimeException; import com.badlogic.gdx.utils.Logger; +import com.badlogic.gdx.utils.TimeUtils; /** Responsible for loading an asset through an {@link AssetLoader} based on an {@link AssetDescriptor}. Implements * {@link Callable} and is used with an {@link ExecutorService threadpool} to load parts of an asset asynchronously if the asset is @@ -55,7 +56,7 @@ class AssetLoadingTask implements Callable { this.assetDesc = assetDesc; this.loader = loader; this.threadPool = threadPool; - startTime = manager.log.getLevel() == Logger.DEBUG ? System.nanoTime() : 0; + startTime = manager.log.getLevel() == Logger.DEBUG ? TimeUtils.nanoTime() : 0; } /** Loads parts of the asset asynchronously if the loader is an {@link AsynchronousAssetLoader}. */ diff --git a/gdx/src/com/badlogic/gdx/assets/AssetManager.java b/gdx/src/com/badlogic/gdx/assets/AssetManager.java index d4e63aee5..0e69ec9c3 100644 --- a/gdx/src/com/badlogic/gdx/assets/AssetManager.java +++ b/gdx/src/com/badlogic/gdx/assets/AssetManager.java @@ -48,6 +48,7 @@ import com.badlogic.gdx.utils.GdxRuntimeException; import com.badlogic.gdx.utils.Logger; import com.badlogic.gdx.utils.ObjectIntMap; import com.badlogic.gdx.utils.ObjectMap; +import com.badlogic.gdx.utils.TimeUtils; public class AssetManager implements Disposable { final ObjectMap> assets = new ObjectMap>(); @@ -389,7 +390,7 @@ public class AssetManager implements Disposable { task.assetDesc.params.loadedCallback.finishedLoading(this, task.assetDesc.fileName, task.assetDesc.type); } - long endTime = System.nanoTime(); + long endTime = TimeUtils.nanoTime(); log.debug("Loaded: " + (endTime - task.startTime) / 1000000f + "ms " + task.assetDesc); } diff --git a/gdx/src/com/badlogic/gdx/graphics/g3d/keyframed/KeyframedModel.java b/gdx/src/com/badlogic/gdx/graphics/g3d/keyframed/KeyframedModel.java index 257435f05..3005b163e 100644 --- a/gdx/src/com/badlogic/gdx/graphics/g3d/keyframed/KeyframedModel.java +++ b/gdx/src/com/badlogic/gdx/graphics/g3d/keyframed/KeyframedModel.java @@ -144,10 +144,8 @@ public class KeyframedModel { numVertices = vertices.length; numIndices = indices.length; if (!cached) { - k.vertices[m] = new float[vertices.length]; - k.vertices[m] = vertices.clone(); - k.indices[m] = new short[indices.length]; - k.indices[m] = indices.clone(); + k.vertices[m] = clone(vertices); + k.indices[m] = clone(indices); } if (target[m] == null) { @@ -202,6 +200,18 @@ public class KeyframedModel { return a; } + private short[] clone (short[] indices) { + short[] tmp = new short[indices.length]; + System.arraycopy(indices, 0, tmp, 0, indices.length); + return tmp; + } + + private float[] clone (float[] vertices) { + float[] tmp = new float[vertices.length]; + System.arraycopy(vertices, 0, tmp, 0, vertices.length); + return tmp; + } + public void getJointData (int tagIndex, Vector3 pos, Quaternion orient) { Keyframe kf = animator.getInterpolatedKeyframe(); pos.set(kf.taggedJointPos[tagIndex]); diff --git a/gdx/src/com/badlogic/gdx/graphics/g3d/loaders/md5/MD5Jni.java b/gdx/src/com/badlogic/gdx/graphics/g3d/loaders/md5/MD5Jni.java index 1ae158445..eb3453851 100644 --- a/gdx/src/com/badlogic/gdx/graphics/g3d/loaders/md5/MD5Jni.java +++ b/gdx/src/com/badlogic/gdx/graphics/g3d/loaders/md5/MD5Jni.java @@ -20,7 +20,7 @@ import com.badlogic.gdx.math.Vector3; public class MD5Jni { public static native void calculateVertices (float[] joints, float[] weights, float[] verticesIn, float[] verticesOut, - int numVertices, int vstride, int wstride); /* + int numVertices, int vstride, int wstride)/*-{ }-*/; /* for (int vertexOffset = 2, k = 0; vertexOffset < numVertices; vertexOffset += vstride) { float finalX = 0; float finalY = 0; diff --git a/gdx/src/com/badlogic/gdx/input/GestureDetector.java b/gdx/src/com/badlogic/gdx/input/GestureDetector.java index 845aa9c83..547eaad1f 100644 --- a/gdx/src/com/badlogic/gdx/input/GestureDetector.java +++ b/gdx/src/com/badlogic/gdx/input/GestureDetector.java @@ -19,6 +19,7 @@ package com.badlogic.gdx.input; import com.badlogic.gdx.Gdx; import com.badlogic.gdx.InputAdapter; import com.badlogic.gdx.math.Vector2; +import com.badlogic.gdx.utils.TimeUtils; public class GestureDetector extends InputAdapter { public static interface GestureListener { @@ -266,9 +267,9 @@ public class GestureDetector extends InputAdapter { panning = false; if (inTapSquare & !longPressFired) { // handle taps - if (System.nanoTime() - lastTapTime > tapCountInterval) tapCount = 0; + if (TimeUtils.nanoTime() - lastTapTime > tapCountInterval) tapCount = 0; tapCount++; - lastTapTime = System.nanoTime(); + lastTapTime = TimeUtils.nanoTime(); gestureStartTime = 0; return listener.tap(tapSquareCenterX, tapSquareCenterY, tapCount); } else if (pinching) { @@ -304,7 +305,7 @@ public class GestureDetector extends InputAdapter { * @return whether the user touched the screen for as much or more than the given duration. */ public boolean isLongPressed (float duration) { if (gestureStartTime == 0) return false; - return System.nanoTime() - gestureStartTime > (long)(duration * 1000000000l); + return TimeUtils.nanoTime() - gestureStartTime > (long)(duration * 1000000000l); } public boolean isPanning () { diff --git a/gdx/src/com/badlogic/gdx/scenes/scene2d/Actor.java b/gdx/src/com/badlogic/gdx/scenes/scene2d/Actor.java index d940936f2..840a4890b 100644 --- a/gdx/src/com/badlogic/gdx/scenes/scene2d/Actor.java +++ b/gdx/src/com/badlogic/gdx/scenes/scene2d/Actor.java @@ -183,7 +183,7 @@ public abstract class Actor { @Override public String toString () { - String name = this.name != null ? this.name : getClass().getSimpleName(); + String name = this.name != null ? this.name : getClass().getName(); if (name.equals("")) name = getClass().getName(); return name + " pos=" + x + "," + y + " origin=" + originX + "," + originY + " size=" + width + "," + height; } diff --git a/gdx/src/com/badlogic/gdx/scenes/scene2d/ui/TextField.java b/gdx/src/com/badlogic/gdx/scenes/scene2d/ui/TextField.java index 0eda8457a..6478746f9 100644 --- a/gdx/src/com/badlogic/gdx/scenes/scene2d/ui/TextField.java +++ b/gdx/src/com/badlogic/gdx/scenes/scene2d/ui/TextField.java @@ -32,6 +32,7 @@ import com.badlogic.gdx.scenes.scene2d.Actor; import com.badlogic.gdx.scenes.scene2d.Group; import com.badlogic.gdx.scenes.scene2d.ui.utils.Clipboard; import com.badlogic.gdx.utils.FloatArray; +import com.badlogic.gdx.utils.TimeUtils; /** A single-line text input field. *

@@ -257,7 +258,7 @@ public class TextField extends Widget { } private void blink () { - long time = System.nanoTime(); + long time = TimeUtils.nanoTime(); if ((time - lastBlink) / 1000000000.0f > blinkTime) { cursorOn = !cursorOn; lastBlink = time; diff --git a/gdx/src/com/badlogic/gdx/utils/Base64Coder.java b/gdx/src/com/badlogic/gdx/utils/Base64Coder.java index b9e15d2e7..9826931c6 100644 --- a/gdx/src/com/badlogic/gdx/utils/Base64Coder.java +++ b/gdx/src/com/badlogic/gdx/utils/Base64Coder.java @@ -30,7 +30,7 @@ package com.badlogic.gdx.utils; public class Base64Coder { // The line separator string of the operating system. - private static final String systemLineSeparator = System.getProperty("line.separator"); + private static final String systemLineSeparator = "\n"; // Mapping table from 6-bit nibbles to Base64 characters. private static char[] map1 = new char[64]; diff --git a/gdx/src/com/badlogic/gdx/utils/GwtModuleGenerator.java b/gdx/src/com/badlogic/gdx/utils/GwtModuleGenerator.java new file mode 100644 index 000000000..fd4e243e9 --- /dev/null +++ b/gdx/src/com/badlogic/gdx/utils/GwtModuleGenerator.java @@ -0,0 +1,116 @@ + +package com.badlogic.gdx.utils; + +import java.io.IOException; +import java.io.StringWriter; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; +import java.util.TreeMap; + +import com.badlogic.gdx.files.FileHandle; + +/** Generates the gdx.gwt.xml file by running through the gdx/src/ directory and cross-referencing it with the gdx-backends-gwt + * directory. + * @author mzechner */ +public class GwtModuleGenerator { + private static void gatherJavaFiles (FileHandle dir, Set names, Map fileHandles, + boolean recursive) { + if (dir.name().equals(".svn")) return; + FileHandle[] files = dir.list(); + for (FileHandle file : files) { + if (file.isDirectory() && recursive) { + gatherJavaFiles(file, names, fileHandles, recursive); + } else { + if (file.extension().equals("java")) { + System.out.println(file.name()); + if(names.contains(file.name())) System.out.println(file.name() + " duplicate!"); + names.add(file.name()); + fileHandles.put(file.name(), file); + } + } + } + } + + public static void main (String[] args) throws IOException { + Set excludes = new HashSet(); + Map excludesHandles = new HashMap(); + System.out.println("Excludes -------------------------------------------------"); + gatherJavaFiles(new FileHandle("../backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/com/badlogic/gdx"), excludes, excludesHandles, true); + System.out.println("#" + excludes.size()); + + // build and shared library loading utils + excludes.add("GdxBuild.java"); + excludes.add("GdxNativesLoader.java"); + excludes.add("GwtModuleGenerator.java"); + excludes.add("SharedLibraryLoader.java"); + + // native pixmap routines + excludes.add("Gdx2DPixmap.java"); + excludes.add("PixmapIO.java"); + excludes.add("ETC1.java"); + excludes.add("ETC1TextureData.java"); + excludes.add("ScreenUtils.java"); + + // asset manager related + excludes.add("ResolutionFileResolver.java"); // FIXME + excludes.add("SkinLoader.java"); + + // remote input + excludes.add("RemoteInput.java"); + excludes.add("RemoteSender.java"); + + // box2d + excludes.add("ParticleEmitterBox2D.java"); + gatherJavaFiles(new FileHandle("src/com/badlogic/gdx/physics/box2d"), excludes, excludesHandles, true); + + // tiled support + excludes.add("TiledLoader.java"); // FIXME? + excludes.add("TileMapRendererLoader.java"); // FIXME? + + // various utils + excludes.add("AtomicQueue.java"); + excludes.add("LittleEndianInputStream.java"); + excludes.add("PauseableThread.java"); + excludes.add("Json.java"); + excludes.add("JsonWriter.java"); + + // scene2d ui package + gatherJavaFiles(new FileHandle("src/com/badlogic/gdx/scenes/scene2d/ui"), excludes, excludesHandles, true); + + Set includes = new HashSet(); + Map includesHandles = new TreeMap(); + System.out.println("Includes -------------------------------------------------"); + gatherJavaFiles(new FileHandle("src"), includes, includesHandles, true); + System.out.println("#" + includes.size()); + + for (String include : includes) { + if (!excludes.contains(include)) continue; + FileHandle includeFile = includesHandles.get(include); + FileHandle excludeFile = excludesHandles.get(include); + includesHandles.remove(include); + System.out.println("excluded '" + include + "'"); + } + + System.out.println("diff: " + includesHandles.size()); + + StringWriter writer = new StringWriter(); + writer.write("\n"); + XmlWriter builder = new XmlWriter(writer); + builder.element("module").attribute("rename-to", "com.badlogic.gdx"); + builder.element("source").attribute("path", "gdx"); + for(String include: includesHandles.keySet()) { + String name = includesHandles.get(include).path().replace("\\", "/").replace("src/com/badlogic/gdx/", ""); + builder.element("include").attribute("name", name).pop(); + } + // duplicate names... + builder.element("include").attribute("name", "graphics/g2d/Animation.java").pop(); + builder.element("include").attribute("name", "graphics/g3d/Animation.java").pop(); + builder.pop(); + builder.pop(); + System.out.println(writer); + + new FileHandle("src/com/badlogic/gdx.gwt.xml").writeString(writer.toString(), false); + } +} diff --git a/gdx/src/com/badlogic/gdx/utils/TimeUtils.java b/gdx/src/com/badlogic/gdx/utils/TimeUtils.java new file mode 100644 index 000000000..1181c44c9 --- /dev/null +++ b/gdx/src/com/badlogic/gdx/utils/TimeUtils.java @@ -0,0 +1,23 @@ +package com.badlogic.gdx.utils; + +/** + * Wrapper around System.nanoTime() and System.currentTimeMillis(). Use this + * if you want to be compatible across all platforms! + * @author mzechner + * + */ +public class TimeUtils { + /** + * @return The current value of the system timer, in nanoseconds. + */ + public static long nanoTime() { + return System.nanoTime(); + } + + /** + * @return the difference, measured in milliseconds, between the current time and midnight, January 1, 1970 UTC. + */ + public static long millis() { + return System.currentTimeMillis(); + } +} diff --git a/tests/gdx-tests-android/assets/assets.txt b/tests/gdx-tests-android/assets/assets.txt index 56074fab4..75d40be60 100644 --- a/tests/gdx-tests-android/assets/assets.txt +++ b/tests/gdx-tests-android/assets/assets.txt @@ -1,9 +1,10 @@ -t:data/gwttestparams.txt +t:assets.txt i:data/43kJgl.jpg i:data/alpha.png i:data/animation.png t:data/arial-15.fnt i:data/arial-15_00.png +b:data/arial.ttf i:data/badlogic.jpg i:data/badlogicsmall.jpg i:data/black_marked_0.png @@ -15,14 +16,20 @@ i:data/debug.png t:data/default.fnt i:data/default.png i:data/default_00.png +b:data/DroidSansJapanese.ttf +b:data/DroidSerif-Bold.ttf +b:data/DroidSerif-Italic.ttf +b:data/DroidSerif-Regular.ttf i:data/egg.png i:data/environment.jpg t:data/font.fnt i:data/font.png i:data/group-debug.png +t:data/gwttestparams.txt i:data/isotile.png t:data/issue_pack i:data/jump.png +t:data/jump.txt i:data/layers.png t:data/pack i:data/pack1.png @@ -39,6 +46,12 @@ i:data/resource1.jpg i:data/rgb.png t:data/scene.obj t:data/scene2.obj +b:data/shaders/batch.frag +b:data/shaders/batch.vert +b:data/shaders/convolution.frag +b:data/shaders/default.frag +b:data/shaders/default.vert +b:data/shaders/depthtocolor.frag t:data/shaders/flat-frag.glsl t:data/shaders/flat-vert.glsl t:data/shaders/flattex-frag.glsl @@ -57,6 +70,8 @@ i:data/stone2.png i:data/stones.jpg i:data/sys.png i:data/t8890.png +b:data/test.etc1 +b:data/test.p i:data/test.png i:data/test3.png i:data/test4.png @@ -65,10 +80,18 @@ i:data/testdot.png t:data/testpack i:data/Textures1.png i:data/tile.png +b:data/tiledmap/alignment test.tmx +b:data/tiledmap/margin spacing doctype test.tmx t:data/tiledmap/perspective walls packfile t:data/tiledmap/perspective walls test packfile i:data/tiledmap/perspective walls test1.png +b:data/tiledmap/perspective walls.tmx i:data/tiledmap/perspective walls1.png +b:data/tiledmap/tilemap csv.tmx +b:data/tiledmap/tilemap gzip.tmx +b:data/tiledmap/tilemap uncompressed.tmx +b:data/tiledmap/tilemap xml.tmx +b:data/tiledmap/tilemap zlib.tmx t:data/tiledmap/tileset packfile i:data/tiledmap/tileset1.png t:data/tiledmap/tileset2 packfile @@ -81,8 +104,11 @@ t:data/tiledmap/tmw-desert-spacing packfile i:data/tiledmap/tmw-desert-spacing1.png i:data/tiles.png i:data/ui.png +b:data/uiskin.json i:data/uiskin.png t:data/verdana39.fnt i:data/verdana39.png +b:data/walk1.md5anim i:data/walkanim.png i:data/wheel.png +b:data/zfat.md5mesh diff --git a/tests/gdx-tests-gwt/.classpath b/tests/gdx-tests-gwt/.classpath index 0244afaae..8ef1c2c26 100644 --- a/tests/gdx-tests-gwt/.classpath +++ b/tests/gdx-tests-gwt/.classpath @@ -3,8 +3,8 @@ - + diff --git a/tests/gdx-tests-gwt/.settings/com.google.gwt.eclipse.core.prefs b/tests/gdx-tests-gwt/.settings/com.google.gwt.eclipse.core.prefs index 122e28d93..662a9d67c 100644 --- a/tests/gdx-tests-gwt/.settings/com.google.gwt.eclipse.core.prefs +++ b/tests/gdx-tests-gwt/.settings/com.google.gwt.eclipse.core.prefs @@ -1,5 +1,5 @@ -#Thu Mar 15 17:56:44 CET 2012 +#Fri Mar 16 10:43:47 CET 2012 eclipse.preferences.version=1 entryPointModules= filesCopiedToWebInfLib=gwt-servlet.jar -gwtCompileSettings=PGd3dC1jb21waWxlLXNldHRpbmdzPjxsb2ctbGV2ZWw+SU5GTzwvbG9nLWxldmVsPjxvdXRwdXQtc3R5bGU+T0JGVVNDQVRFRDwvb3V0cHV0LXN0eWxlPjxleHRyYS1hcmdzPjwhW0NEQVRBW11dPjwvZXh0cmEtYXJncz48dm0tYXJncz48IVtDREFUQVstWG14NTEybV1dPjwvdm0tYXJncz48ZW50cnktcG9pbnQtbW9kdWxlPmNvbS5iYWRsb2dpYy5nZHgudGVzdHMuZ3d0LkdkeFRlc3RzR3d0PC9lbnRyeS1wb2ludC1tb2R1bGU+PC9nd3QtY29tcGlsZS1zZXR0aW5ncz4\= +gwtCompileSettings=PGd3dC1jb21waWxlLXNldHRpbmdzPjxsb2ctbGV2ZWw+SU5GTzwvbG9nLWxldmVsPjxvdXRwdXQtc3R5bGU+T0JGVVNDQVRFRDwvb3V0cHV0LXN0eWxlPjxleHRyYS1hcmdzPjwhW0NEQVRBWy1zdHJpY3RdXT48L2V4dHJhLWFyZ3M+PHZtLWFyZ3M+PCFbQ0RBVEFbLVhteDUxMm1dXT48L3ZtLWFyZ3M+PGVudHJ5LXBvaW50LW1vZHVsZT5jb20uYmFkbG9naWMuZ2R4LnRlc3RzLmd3dC5HZHhUZXN0c0d3dDwvZW50cnktcG9pbnQtbW9kdWxlPjwvZ3d0LWNvbXBpbGUtc2V0dGluZ3M+ diff --git a/tests/gdx-tests-gwt/src/com/badlogic/gdx/tests/gwt/client/GwtTestStarter.java b/tests/gdx-tests-gwt/src/com/badlogic/gdx/tests/gwt/client/GwtTestStarter.java index 8ea2f8377..83156fe86 100644 --- a/tests/gdx-tests-gwt/src/com/badlogic/gdx/tests/gwt/client/GwtTestStarter.java +++ b/tests/gdx-tests-gwt/src/com/badlogic/gdx/tests/gwt/client/GwtTestStarter.java @@ -4,10 +4,89 @@ package com.badlogic.gdx.tests.gwt.client; import com.badlogic.gdx.ApplicationListener; import com.badlogic.gdx.backends.gwt.GwtApplication; import com.badlogic.gdx.backends.gwt.GwtApplicationConfiguration; -import com.badlogic.gdx.tests.gwt.GwtBinaryTest; +import com.badlogic.gdx.tests.AlphaTest; +import com.badlogic.gdx.tests.AnimationTest; +import com.badlogic.gdx.tests.AssetManagerTest; +import com.badlogic.gdx.tests.AtlasIssueTest; +import com.badlogic.gdx.tests.BitmapFontAlignmentTest; +import com.badlogic.gdx.tests.BitmapFontFlipTest; +import com.badlogic.gdx.tests.BitmapFontTest; +import com.badlogic.gdx.tests.BlitTest; +import com.badlogic.gdx.tests.CustomShaderSpriteBatchTest; +import com.badlogic.gdx.tests.DecalTest; +import com.badlogic.gdx.tests.EdgeDetectionTest; +import com.badlogic.gdx.tests.FilterPerformanceTest; +import com.badlogic.gdx.tests.FrameBufferTest; +import com.badlogic.gdx.tests.GestureDetectorTest; +import com.badlogic.gdx.tests.IndexBufferObjectShaderTest; +import com.badlogic.gdx.tests.IntegerBitmapFontTest; +import com.badlogic.gdx.tests.InverseKinematicsTest; +import com.badlogic.gdx.tests.IsoCamTest; +import com.badlogic.gdx.tests.IsometricTileTest; +import com.badlogic.gdx.tests.MatrixJNITest; +import com.badlogic.gdx.tests.MeshShaderTest; +import com.badlogic.gdx.tests.MultitouchTest; +import com.badlogic.gdx.tests.MusicTest; +import com.badlogic.gdx.tests.ParallaxTest; +import com.badlogic.gdx.tests.ParticleEmitterTest; +import com.badlogic.gdx.tests.PixelsPerInchTest; +import com.badlogic.gdx.tests.RotationTest; +import com.badlogic.gdx.tests.ShaderMultitextureTest; +import com.badlogic.gdx.tests.ShapeRendererTest; +import com.badlogic.gdx.tests.SimpleAnimationTest; +import com.badlogic.gdx.tests.SimpleDecalTest; +import com.badlogic.gdx.tests.SortedSpriteTest; +import com.badlogic.gdx.tests.SpriteBatchShaderTest; +import com.badlogic.gdx.tests.SpriteCacheOffsetTest; +import com.badlogic.gdx.tests.SpriteCacheTest; +import com.badlogic.gdx.tests.TextureAtlasTest; +import com.badlogic.gdx.tests.VertexBufferObjectShaderTest; +import com.badlogic.gdx.tests.YDownTest; +import com.badlogic.gdx.tests.utils.GdxTest; public class GwtTestStarter extends GwtApplication { - + GdxTest[] tests = { + new AlphaTest(), + new AnimationTest(), + new AssetManagerTest(), + new AtlasIssueTest(), + new BitmapFontAlignmentTest(), + new BitmapFontFlipTest(), + new BitmapFontTest(), + new BlitTest(), + new CustomShaderSpriteBatchTest(), + new DecalTest(), + new EdgeDetectionTest(), + new FilterPerformanceTest(), + new FrameBufferTest(), + new GestureDetectorTest(), + new IndexBufferObjectShaderTest(), + new IntegerBitmapFontTest(), + new InverseKinematicsTest(), + new IsoCamTest(), + new IsometricTileTest(), + new MatrixJNITest(), + new MeshShaderTest(), + new MultitouchTest(), + new MusicTest(), + new ParallaxTest(), + new ParticleEmitterTest(), + new PixelsPerInchTest(), +// new PixmapBlendingTest(), // no idea why this doesn't work + new RotationTest(), + new ShaderMultitextureTest(), + new ShapeRendererTest(), + new SimpleAnimationTest(), + new SimpleDecalTest(), + new SortedSpriteTest(), + new SpriteBatchShaderTest(), + new SpriteCacheOffsetTest(), + new SpriteCacheTest(), + new TextureAtlasTest(), + new VertexBufferObjectShaderTest(), + new YDownTest() + }; + @Override public GwtApplicationConfiguration getConfig () { return new GwtApplicationConfiguration(640, 640); @@ -15,6 +94,6 @@ public class GwtTestStarter extends GwtApplication { @Override public ApplicationListener getApplicationListener () { - return new GwtBinaryTest(); + return new AssetManagerTest(); } } diff --git a/tests/gdx-tests-gwt/war/assets.txt b/tests/gdx-tests-gwt/war/assets.txt index 1690b7ceb..75d40be60 100644 --- a/tests/gdx-tests-gwt/war/assets.txt +++ b/tests/gdx-tests-gwt/war/assets.txt @@ -111,4 +111,4 @@ i:data/verdana39.png b:data/walk1.md5anim i:data/walkanim.png i:data/wheel.png -b:data/zfat.md5mesh \ No newline at end of file +b:data/zfat.md5mesh diff --git a/tests/gdx-tests-lwjgl/src/com/badlogic/gdx/tests/lwjgl/LwjglDebugStarter.java b/tests/gdx-tests-lwjgl/src/com/badlogic/gdx/tests/lwjgl/LwjglDebugStarter.java index bcb7c285c..6181337ba 100644 --- a/tests/gdx-tests-lwjgl/src/com/badlogic/gdx/tests/lwjgl/LwjglDebugStarter.java +++ b/tests/gdx-tests-lwjgl/src/com/badlogic/gdx/tests/lwjgl/LwjglDebugStarter.java @@ -18,7 +18,19 @@ package com.badlogic.gdx.tests.lwjgl; import com.badlogic.gdx.backends.lwjgl.LwjglApplication; import com.badlogic.gdx.backends.lwjgl.LwjglApplicationConfiguration; +import com.badlogic.gdx.tests.AssetManagerTest; +import com.badlogic.gdx.tests.AtlasIssueTest; +import com.badlogic.gdx.tests.BitmapFontAlignmentTest; +import com.badlogic.gdx.tests.CustomShaderSpriteBatchTest; +import com.badlogic.gdx.tests.DecalTest; import com.badlogic.gdx.tests.MeshShaderTest; +import com.badlogic.gdx.tests.ParticleEmitterTest; +import com.badlogic.gdx.tests.PixelsPerInchTest; +import com.badlogic.gdx.tests.PixmapBlendingTest; +import com.badlogic.gdx.tests.ShaderMultitextureTest; +import com.badlogic.gdx.tests.SpriteBatchShaderTest; +import com.badlogic.gdx.tests.SpriteCacheOffsetTest; +import com.badlogic.gdx.tests.VertexBufferObjectShaderTest; import com.badlogic.gdx.tests.gwt.GwtBinaryTest; import com.badlogic.gdx.tests.utils.GdxTest; import com.badlogic.gdx.utils.SharedLibraryLoader; @@ -32,7 +44,7 @@ public class LwjglDebugStarter { new SharedLibraryLoader("../../extensions/gdx-image/libs/gdx-image-natives.jar").load("gdx-image"); new SharedLibraryLoader("../../extensions/gdx-freetype/libs/gdx-freetype-natives.jar").load("gdx-freetype"); - GdxTest test = new GwtBinaryTest(); + GdxTest test = new AssetManagerTest(); LwjglApplicationConfiguration config = new LwjglApplicationConfiguration(); config.width = 800; config.height = 480; diff --git a/tests/gdx-tests/src/com/badlogic/gdx/GdxTests.gwt.xml b/tests/gdx-tests/src/com/badlogic/gdx/GdxTests.gwt.xml index 060b90bf3..06b8e5543 100644 --- a/tests/gdx-tests/src/com/badlogic/gdx/GdxTests.gwt.xml +++ b/tests/gdx-tests/src/com/badlogic/gdx/GdxTests.gwt.xml @@ -1,5 +1,57 @@ - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/tests/gdx-tests/src/com/badlogic/gdx/tests/AssetManagerTest.java b/tests/gdx-tests/src/com/badlogic/gdx/tests/AssetManagerTest.java index 51493df66..50637da8e 100644 --- a/tests/gdx-tests/src/com/badlogic/gdx/tests/AssetManagerTest.java +++ b/tests/gdx-tests/src/com/badlogic/gdx/tests/AssetManagerTest.java @@ -22,7 +22,6 @@ import com.badlogic.gdx.Gdx; import com.badlogic.gdx.assets.AssetErrorListener; import com.badlogic.gdx.assets.AssetManager; import com.badlogic.gdx.assets.loaders.TextureLoader; -import com.badlogic.gdx.assets.loaders.TileMapRendererLoader; import com.badlogic.gdx.assets.loaders.resolvers.InternalFileHandleResolver; import com.badlogic.gdx.assets.loaders.resolvers.ResolutionFileResolver; import com.badlogic.gdx.assets.loaders.resolvers.ResolutionFileResolver.Resolution; @@ -31,12 +30,9 @@ import com.badlogic.gdx.graphics.Texture; import com.badlogic.gdx.graphics.g2d.BitmapFont; import com.badlogic.gdx.graphics.g2d.SpriteBatch; import com.badlogic.gdx.graphics.g2d.TextureAtlas; -import com.badlogic.gdx.graphics.g2d.tiled.TileAtlas; -import com.badlogic.gdx.graphics.g2d.tiled.TileMapRenderer; -import com.badlogic.gdx.graphics.g2d.tiled.TiledLoader; -import com.badlogic.gdx.graphics.g2d.tiled.TiledMap; import com.badlogic.gdx.tests.utils.GdxTest; import com.badlogic.gdx.utils.BufferUtils; +import com.badlogic.gdx.utils.TimeUtils; public class AssetManagerTest extends GdxTest implements AssetErrorListener { @Override @@ -68,50 +64,50 @@ public class AssetManagerTest extends GdxTest implements AssetErrorListener { boolean diagnosed = false; private long start; - private TileMapRenderer renderer; - private TileAtlas atlas; - private TiledMap map; - private Texture tex3; +// private TileMapRenderer renderer; +// private TileAtlas atlas; +// private TiledMap map; +// private Texture tex3; private BitmapFont font2; private TextureAtlas tex2; private Texture tex1; private void load() { - start = System.nanoTime(); + start = TimeUtils.nanoTime(); tex1 = new Texture("data/animation.png"); tex2 = new TextureAtlas(Gdx.files.internal("data/pack")); font2 = new BitmapFont(Gdx.files.internal("data/verdana39.fnt"), false); - tex3 = new Texture("data/test.etc1"); - map = TiledLoader.createMap(Gdx.files.internal("data/tiledmap/tilemap csv.tmx")); - atlas = new TileAtlas(map, Gdx.files.internal("data/tiledmap/")); - renderer = new TileMapRenderer(map, atlas, 8, 8); - System.out.println("plain took: " + (System.nanoTime() - start) / 1000000000.0f); +// tex3 = new Texture("data/test.etc1"); +// map = TiledLoader.createMap(Gdx.files.internal("data/tiledmap/tilemap csv.tmx")); +// atlas = new TileAtlas(map, Gdx.files.internal("data/tiledmap/")); +// renderer = new TileMapRenderer(map, atlas, 8, 8); + System.out.println("plain took: " + (TimeUtils.nanoTime() - start) / 1000000000.0f); - start = System.nanoTime(); + start = TimeUtils.nanoTime(); manager.load("data/animation.png", Texture.class); manager.load("data/pack1.png", Texture.class); manager.load("data/pack", TextureAtlas.class); manager.load("data/verdana39.png", Texture.class); manager.load("data/verdana39.fnt", BitmapFont.class); - manager.load("data/test.etc1", Texture.class); - manager.load("data/tiledmap/tilemap csv.tmx", TileMapRenderer.class, new TileMapRendererLoader.TileMapParameter("data/tiledmap/", 8, 8)); +// manager.load("data/test.etc1", Texture.class); +// manager.load("data/tiledmap/tilemap csv.tmx", TileMapRenderer.class, new TileMapRendererLoader.TileMapParameter("data/tiledmap/", 8, 8)); } private void unload() { tex1.dispose(); tex2.dispose(); font2.dispose(); - tex3.dispose(); - atlas.dispose(); - renderer.dispose(); +// tex3.dispose(); +// atlas.dispose(); +// renderer.dispose(); manager.unload("data/animation.png"); manager.unload("data/pack1.png"); manager.unload("data/pack"); manager.unload("data/verdana39.png"); manager.unload("data/verdana39.fnt"); - manager.unload("data/test.etc1"); - manager.unload("data/tiledmap/tilemap csv.tmx"); +// manager.unload("data/test.etc1"); +// manager.unload("data/tiledmap/tilemap csv.tmx"); } private void invalidateTexture(Texture texture) { @@ -124,9 +120,8 @@ public class AssetManagerTest extends GdxTest implements AssetErrorListener { Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT); boolean result = manager.update(); if (result & !diagnosed) { -// Gdx.app.log("AssetManagerTest", "\n" + manager.getDiagnostics() + "\n" + Texture.getManagedStatus()); diagnosed = true; - System.out.println("took: " + (System.nanoTime() - start) / 1000000000.0f); + System.out.println("took: " + (TimeUtils.nanoTime() - start) / 1000000000.0f); unload(); load(); diagnosed = false; @@ -135,12 +130,12 @@ public class AssetManagerTest extends GdxTest implements AssetErrorListener { frame++; batch.begin(); - if (manager.isLoaded("data/test.etc1")) batch.draw(manager.get("data/test.etc1", Texture.class), 0, 0); if (manager.isLoaded("data/animation.png")) batch.draw(manager.get("data/animation.png", Texture.class), 100, 100); if (manager.isLoaded("data/verdana39.png")) batch.draw(manager.get("data/verdana39.png", Texture.class), 300, 100); if (manager.isLoaded("data/pack")) batch.draw(manager.get("data/pack", TextureAtlas.class).findRegion("particle-star"), 164, 100); if (manager.isLoaded("data/verdana39.fnt")) manager.get("data/verdana39.fnt", BitmapFont.class).draw(batch, "This is a test", 100, 200); - if (manager.isLoaded("data/tiledmap/tilemap csv.tmx")) manager.get("data/tiledmap/tilemap csv.tmx", TileMapRenderer.class).render(); +// if (manager.isLoaded("data/test.etc1")) batch.draw(manager.get("data/test.etc1", Texture.class), 0, 0); +// if (manager.isLoaded("data/tiledmap/tilemap csv.tmx")) manager.get("data/tiledmap/tilemap csv.tmx", TileMapRenderer.class).render(); font.draw(batch, "loaded: " + manager.getProgress() + ", reloads: " + reloads, 0, 30); batch.end(); diff --git a/tests/gdx-tests/src/com/badlogic/gdx/tests/BitmapFontAlignmentTest.java b/tests/gdx-tests/src/com/badlogic/gdx/tests/BitmapFontAlignmentTest.java index bfe81c667..730c78c75 100644 --- a/tests/gdx-tests/src/com/badlogic/gdx/tests/BitmapFontAlignmentTest.java +++ b/tests/gdx-tests/src/com/badlogic/gdx/tests/BitmapFontAlignmentTest.java @@ -58,8 +58,7 @@ public class BitmapFontAlignmentTest extends GdxTest { @Override public void render () { - GL10 gl = Gdx.graphics.getGL10(); - gl.glClear(GL10.GL_COLOR_BUFFER_BIT); + Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT); spriteBatch.begin(); logoSprite.draw(spriteBatch); switch (renderMode) { diff --git a/tests/gdx-tests/src/com/badlogic/gdx/tests/BitmapFontFlipTest.java b/tests/gdx-tests/src/com/badlogic/gdx/tests/BitmapFontFlipTest.java index da209164e..9ac95ff4f 100644 --- a/tests/gdx-tests/src/com/badlogic/gdx/tests/BitmapFontFlipTest.java +++ b/tests/gdx-tests/src/com/badlogic/gdx/tests/BitmapFontFlipTest.java @@ -97,8 +97,7 @@ public class BitmapFontFlipTest extends GdxTest { public void render () { red.a = (red.a + Gdx.graphics.getDeltaTime() * 0.1f) % 1; - GL10 gl = Gdx.graphics.getGL10(); - gl.glClear(GL10.GL_COLOR_BUFFER_BIT); + Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT); spriteBatch.begin(); logoSprite.draw(spriteBatch); switch (renderMode) { diff --git a/tests/gdx-tests/src/com/badlogic/gdx/tests/BitmapFontTest.java b/tests/gdx-tests/src/com/badlogic/gdx/tests/BitmapFontTest.java index 9a6de40ee..19bd7c287 100644 --- a/tests/gdx-tests/src/com/badlogic/gdx/tests/BitmapFontTest.java +++ b/tests/gdx-tests/src/com/badlogic/gdx/tests/BitmapFontTest.java @@ -25,21 +25,22 @@ import com.badlogic.gdx.graphics.g2d.BitmapFont.TextBounds; import com.badlogic.gdx.graphics.g2d.SpriteBatch; import com.badlogic.gdx.graphics.g2d.TextureAtlas; import com.badlogic.gdx.graphics.glutils.ImmediateModeRenderer10; +import com.badlogic.gdx.graphics.glutils.ShapeRenderer; +import com.badlogic.gdx.graphics.glutils.ShapeRenderer.ShapeType; import com.badlogic.gdx.tests.utils.GdxTest; public class BitmapFontTest extends GdxTest { private SpriteBatch spriteBatch; private BitmapFont font; - ImmediateModeRenderer10 renderer; - + private ShapeRenderer renderer; + @Override public void create () { spriteBatch = new SpriteBatch(); - TextureAtlas textureAtlas = new TextureAtlas("data/pack"); font = new BitmapFont(Gdx.files.internal("data/verdana39.fnt"), textureAtlas.findRegion("verdana39"), false); - - renderer = new ImmediateModeRenderer10(); + renderer = new ShapeRenderer(); + renderer.setProjectionMatrix(spriteBatch.getProjectionMatrix()); } @Override @@ -48,9 +49,8 @@ public class BitmapFontTest extends GdxTest { int viewHeight = Gdx.graphics.getHeight(); - GL10 gl = Gdx.graphics.getGL10(); - gl.glClearColor(1, 1, 1, 1); - gl.glClear(GL10.GL_COLOR_BUFFER_BIT); + Gdx.gl.glClearColor(1, 1, 1, 1); + Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT); spriteBatch.begin(); String text = "Sphinx of black quartz, judge my vow."; @@ -78,16 +78,8 @@ public class BitmapFontTest extends GdxTest { spriteBatch.end(); - drawRect(x, viewHeight - y, x + alignmentWidth, 300); - } - - public void drawRect (float x1, float y1, float x2, float y2) { - renderer.begin(GL10.GL_LINE_STRIP); - renderer.vertex(x1, y1, 0); - renderer.vertex(x1, y2, 0); - renderer.vertex(x2, y2, 0); - renderer.vertex(x2, y1, 0); - renderer.vertex(x1, y1, 0); + renderer.begin(ShapeType.Rectangle); + renderer.rect(x, viewHeight - y, x + alignmentWidth, 300); renderer.end(); } diff --git a/tests/gdx-tests/src/com/badlogic/gdx/tests/BufferUtilsTest.java b/tests/gdx-tests/src/com/badlogic/gdx/tests/BufferUtilsTest.java index 285df10a8..a3f006548 100644 --- a/tests/gdx-tests/src/com/badlogic/gdx/tests/BufferUtilsTest.java +++ b/tests/gdx-tests/src/com/badlogic/gdx/tests/BufferUtilsTest.java @@ -27,6 +27,7 @@ import com.badlogic.gdx.Gdx; import com.badlogic.gdx.tests.utils.GdxTest; import com.badlogic.gdx.utils.BufferUtils; import com.badlogic.gdx.utils.GdxRuntimeException; +import com.badlogic.gdx.utils.TimeUtils; public class BufferUtilsTest extends GdxTest { static final int NUM_MB = 5; @@ -125,38 +126,38 @@ public class BufferUtilsTest extends GdxTest { final int NUM_MB = 5; // relative put - long start = System.nanoTime(); + long start = TimeUtils.nanoTime(); for (int j = 0; j < NUM_MB; j++) { bb.clear(); for (int i = 0; i < len; i++) bb.put(bytes[i]); } - Gdx.app.log("BufferUtilsTest", "ByteBuffer relative put: " + (System.nanoTime() - start) / 1000000000.0f); + Gdx.app.log("BufferUtilsTest", "ByteBuffer relative put: " + (TimeUtils.nanoTime() - start) / 1000000000.0f); // absolute put - start = System.nanoTime(); + start = TimeUtils.nanoTime(); for (int j = 0; j < NUM_MB; j++) { bb.clear(); for (int i = 0; i < len; i++) bb.put(i, bytes[i]); } - Gdx.app.log("BufferUtilsTest", "ByteBuffer absolute put: " + (System.nanoTime() - start) / 1000000000.0f); + Gdx.app.log("BufferUtilsTest", "ByteBuffer absolute put: " + (TimeUtils.nanoTime() - start) / 1000000000.0f); // bulk put - start = System.nanoTime(); + start = TimeUtils.nanoTime(); for (int j = 0; j < NUM_MB; j++) { bb.clear(); bb.put(bytes); } - Gdx.app.log("BufferUtilsTest", "ByteBuffer bulk put: " + (System.nanoTime() - start) / 1000000000.0f); + Gdx.app.log("BufferUtilsTest", "ByteBuffer bulk put: " + (TimeUtils.nanoTime() - start) / 1000000000.0f); // JNI put - start = System.nanoTime(); + start = TimeUtils.nanoTime(); for (int j = 0; j < NUM_MB; j++) { bb.clear(); BufferUtils.copy(bytes, 0, bb, len); } - Gdx.app.log("BufferUtilsTest", "ByteBuffer native bulk put: " + (System.nanoTime() - start) / 1000000000.0f); + Gdx.app.log("BufferUtilsTest", "ByteBuffer native bulk put: " + (TimeUtils.nanoTime() - start) / 1000000000.0f); } private void benchShort () { @@ -165,38 +166,38 @@ public class BufferUtilsTest extends GdxTest { int len = shorts.length; // relative put - long start = System.nanoTime(); + long start = TimeUtils.nanoTime(); for (int j = 0; j < NUM_MB; j++) { sb.clear(); for (int i = 0; i < len; i++) sb.put(shorts[i]); } - Gdx.app.log("BufferUtilsTest", "ShortBuffer relative put: " + (System.nanoTime() - start) / 1000000000.0f); + Gdx.app.log("BufferUtilsTest", "ShortBuffer relative put: " + (TimeUtils.nanoTime() - start) / 1000000000.0f); // absolute put - start = System.nanoTime(); + start = TimeUtils.nanoTime(); for (int j = 0; j < NUM_MB; j++) { sb.clear(); for (int i = 0; i < len; i++) sb.put(i, shorts[i]); } - Gdx.app.log("BufferUtilsTest", "ShortBuffer absolute put: " + (System.nanoTime() - start) / 1000000000.0f); + Gdx.app.log("BufferUtilsTest", "ShortBuffer absolute put: " + (TimeUtils.nanoTime() - start) / 1000000000.0f); // bulk put - start = System.nanoTime(); + start = TimeUtils.nanoTime(); for (int j = 0; j < NUM_MB; j++) { sb.clear(); sb.put(shorts); } - Gdx.app.log("BufferUtilsTest", "ShortBuffer bulk put: " + (System.nanoTime() - start) / 1000000000.0f); + Gdx.app.log("BufferUtilsTest", "ShortBuffer bulk put: " + (TimeUtils.nanoTime() - start) / 1000000000.0f); // JNI put - start = System.nanoTime(); + start = TimeUtils.nanoTime(); for (int j = 0; j < NUM_MB; j++) { sb.clear(); BufferUtils.copy(shorts, 0, sb, len); } - Gdx.app.log("BufferUtilsTest", "ShortBuffer native bulk put: " + (System.nanoTime() - start) / 1000000000.0f); + Gdx.app.log("BufferUtilsTest", "ShortBuffer native bulk put: " + (TimeUtils.nanoTime() - start) / 1000000000.0f); } private void benchInt () { @@ -205,38 +206,38 @@ public class BufferUtilsTest extends GdxTest { int len = ints.length; // relative put - long start = System.nanoTime(); + long start = TimeUtils.nanoTime(); for (int j = 0; j < NUM_MB; j++) { ib.clear(); for (int i = 0; i < len; i++) ib.put(ints[i]); } - Gdx.app.log("BufferUtilsTest", "IntBuffer relative put: " + (System.nanoTime() - start) / 1000000000.0f); + Gdx.app.log("BufferUtilsTest", "IntBuffer relative put: " + (TimeUtils.nanoTime() - start) / 1000000000.0f); // absolute put - start = System.nanoTime(); + start = TimeUtils.nanoTime(); for (int j = 0; j < NUM_MB; j++) { ib.clear(); for (int i = 0; i < len; i++) ib.put(i, ints[i]); } - Gdx.app.log("BufferUtilsTest", "IntBuffer absolute put: " + (System.nanoTime() - start) / 1000000000.0f); + Gdx.app.log("BufferUtilsTest", "IntBuffer absolute put: " + (TimeUtils.nanoTime() - start) / 1000000000.0f); // bulk put - start = System.nanoTime(); + start = TimeUtils.nanoTime(); for (int j = 0; j < NUM_MB; j++) { ib.clear(); ib.put(ints); } - Gdx.app.log("BufferUtilsTest", "IntBuffer bulk put: " + (System.nanoTime() - start) / 1000000000.0f); + Gdx.app.log("BufferUtilsTest", "IntBuffer bulk put: " + (TimeUtils.nanoTime() - start) / 1000000000.0f); // JNI put - start = System.nanoTime(); + start = TimeUtils.nanoTime(); for (int j = 0; j < NUM_MB; j++) { ib.clear(); BufferUtils.copy(ints, 0, ib, len); } - Gdx.app.log("BufferUtilsTest", "IntBuffer native bulk put: " + (System.nanoTime() - start) / 1000000000.0f); + Gdx.app.log("BufferUtilsTest", "IntBuffer native bulk put: " + (TimeUtils.nanoTime() - start) / 1000000000.0f); } private void benchLong () { @@ -245,38 +246,38 @@ public class BufferUtilsTest extends GdxTest { int len = longs.length; // relative put - long start = System.nanoTime(); + long start = TimeUtils.nanoTime(); for (int j = 0; j < NUM_MB; j++) { lb.clear(); for (int i = 0; i < len; i++) lb.put(longs[i]); } - Gdx.app.log("BufferUtilsTest", "LongBuffer relative put: " + (System.nanoTime() - start) / 1000000000.0f); + Gdx.app.log("BufferUtilsTest", "LongBuffer relative put: " + (TimeUtils.nanoTime() - start) / 1000000000.0f); // absolute put - start = System.nanoTime(); + start = TimeUtils.nanoTime(); for (int j = 0; j < NUM_MB; j++) { lb.clear(); for (int i = 0; i < len; i++) lb.put(i, longs[i]); } - Gdx.app.log("BufferUtilsTest", "LongBuffer absolute put: " + (System.nanoTime() - start) / 1000000000.0f); + Gdx.app.log("BufferUtilsTest", "LongBuffer absolute put: " + (TimeUtils.nanoTime() - start) / 1000000000.0f); // bulk put - start = System.nanoTime(); + start = TimeUtils.nanoTime(); for (int j = 0; j < NUM_MB; j++) { lb.clear(); lb.put(longs); } - Gdx.app.log("BufferUtilsTest", "LongBuffer bulk put: " + (System.nanoTime() - start) / 1000000000.0f); + Gdx.app.log("BufferUtilsTest", "LongBuffer bulk put: " + (TimeUtils.nanoTime() - start) / 1000000000.0f); // JNI put - start = System.nanoTime(); + start = TimeUtils.nanoTime(); for (int j = 0; j < NUM_MB; j++) { lb.clear(); BufferUtils.copy(longs, 0, lb, len); } - Gdx.app.log("BufferUtilsTest", "LongBuffer native bulk put: " + (System.nanoTime() - start) / 1000000000.0f); + Gdx.app.log("BufferUtilsTest", "LongBuffer native bulk put: " + (TimeUtils.nanoTime() - start) / 1000000000.0f); } private void benchFloat () { @@ -285,38 +286,38 @@ public class BufferUtilsTest extends GdxTest { int len = floats.length; // relative put - long start = System.nanoTime(); + long start = TimeUtils.nanoTime(); for (int j = 0; j < NUM_MB; j++) { fb.clear(); for (int i = 0; i < len; i++) fb.put(floats[i]); } - Gdx.app.log("BufferUtilsTest", "FloatBuffer relative put: " + (System.nanoTime() - start) / 1000000000.0f); + Gdx.app.log("BufferUtilsTest", "FloatBuffer relative put: " + (TimeUtils.nanoTime() - start) / 1000000000.0f); // absolute put - start = System.nanoTime(); + start = TimeUtils.nanoTime(); for (int j = 0; j < NUM_MB; j++) { fb.clear(); for (int i = 0; i < len; i++) fb.put(i, floats[i]); } - Gdx.app.log("BufferUtilsTest", "FloatBuffer absolute put: " + (System.nanoTime() - start) / 1000000000.0f); + Gdx.app.log("BufferUtilsTest", "FloatBuffer absolute put: " + (TimeUtils.nanoTime() - start) / 1000000000.0f); // bulk put - start = System.nanoTime(); + start = TimeUtils.nanoTime(); for (int j = 0; j < NUM_MB; j++) { fb.clear(); fb.put(floats); } - Gdx.app.log("BufferUtilsTest", "FloatBuffer bulk put: " + (System.nanoTime() - start) / 1000000000.0f); + Gdx.app.log("BufferUtilsTest", "FloatBuffer bulk put: " + (TimeUtils.nanoTime() - start) / 1000000000.0f); // JNI put - start = System.nanoTime(); + start = TimeUtils.nanoTime(); for (int j = 0; j < NUM_MB; j++) { fb.clear(); BufferUtils.copy(floats, 0, fb, len); } - Gdx.app.log("BufferUtilsTest", "FloatBuffer native bulk put: " + (System.nanoTime() - start) / 1000000000.0f); + Gdx.app.log("BufferUtilsTest", "FloatBuffer native bulk put: " + (TimeUtils.nanoTime() - start) / 1000000000.0f); } private void benchDouble () { @@ -325,38 +326,38 @@ public class BufferUtilsTest extends GdxTest { int len = doubles.length; // relative put - long start = System.nanoTime(); + long start = TimeUtils.nanoTime(); for (int j = 0; j < NUM_MB; j++) { db.clear(); for (int i = 0; i < len; i++) db.put(doubles[i]); } - Gdx.app.log("BufferUtilsTest", "DoubleBuffer relative put: " + (System.nanoTime() - start) / 1000000000.0f); + Gdx.app.log("BufferUtilsTest", "DoubleBuffer relative put: " + (TimeUtils.nanoTime() - start) / 1000000000.0f); // absolute put - start = System.nanoTime(); + start = TimeUtils.nanoTime(); for (int j = 0; j < NUM_MB; j++) { db.clear(); for (int i = 0; i < len; i++) db.put(i, doubles[i]); } - Gdx.app.log("BufferUtilsTest", "DoubleBuffer absolute put: " + (System.nanoTime() - start) / 1000000000.0f); + Gdx.app.log("BufferUtilsTest", "DoubleBuffer absolute put: " + (TimeUtils.nanoTime() - start) / 1000000000.0f); // bulk put - start = System.nanoTime(); + start = TimeUtils.nanoTime(); for (int j = 0; j < NUM_MB; j++) { db.clear(); db.put(doubles); } - Gdx.app.log("BufferUtilsTest", "DoubleBuffer bulk put: " + (System.nanoTime() - start) / 1000000000.0f); + Gdx.app.log("BufferUtilsTest", "DoubleBuffer bulk put: " + (TimeUtils.nanoTime() - start) / 1000000000.0f); // JNI put - start = System.nanoTime(); + start = TimeUtils.nanoTime(); for (int j = 0; j < NUM_MB; j++) { db.clear(); BufferUtils.copy(doubles, 0, db, len); } - Gdx.app.log("BufferUtilsTest", "DoubleBuffer bulk put: " + (System.nanoTime() - start) / 1000000000.0f); + Gdx.app.log("BufferUtilsTest", "DoubleBuffer bulk put: " + (TimeUtils.nanoTime() - start) / 1000000000.0f); } private void checkInt (long val1, long val2) { diff --git a/tests/gdx-tests/src/com/badlogic/gdx/tests/DecalTest.java b/tests/gdx-tests/src/com/badlogic/gdx/tests/DecalTest.java index 52c4a14e3..9b426dc2e 100644 --- a/tests/gdx-tests/src/com/badlogic/gdx/tests/DecalTest.java +++ b/tests/gdx-tests/src/com/badlogic/gdx/tests/DecalTest.java @@ -24,6 +24,7 @@ import com.badlogic.gdx.graphics.GL10; import com.badlogic.gdx.graphics.OrthographicCamera; import com.badlogic.gdx.graphics.Texture; import com.badlogic.gdx.graphics.g2d.TextureRegion; +import com.badlogic.gdx.graphics.g3d.decals.CameraGroupStrategy; import com.badlogic.gdx.graphics.g3d.decals.Decal; import com.badlogic.gdx.graphics.g3d.decals.DecalBatch; import com.badlogic.gdx.graphics.g3d.decals.GroupStrategy; @@ -35,8 +36,6 @@ public class DecalTest extends GdxTest { public static final int TARGET_FPS = 40; public static final int INITIAL_RENDERED = 100; private boolean willItBlend_that_is_the_question = true; - private GroupStrategy strategy = new SimpleOrthoGroupStrategy(); - // private GroupStrategy strategy = new DefaultGroupStrategy(); Texture egg; Texture wheel; LinkedList toRender = new LinkedList(); @@ -52,7 +51,7 @@ public class DecalTest extends GdxTest { @Override public void create () { Gdx.gl.glEnable(GL10.GL_DEPTH_TEST); - Gdx.gl10.glDepthFunc(GL10.GL_LESS); + Gdx.gl.glDepthFunc(GL10.GL_LESS); egg = new Texture(Gdx.files.internal("data/egg.png")); egg.setFilter(Texture.TextureFilter.Linear, Texture.TextureFilter.Linear); @@ -65,8 +64,13 @@ public class DecalTest extends GdxTest { h = Gdx.graphics.getHeight() / 0.8f; for (int i = 0; i < INITIAL_RENDERED; i++) { toRender.add(makeDecal()); - } - batch = new DecalBatch(strategy); + } + cam = new OrthographicCamera(Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); + cam.near = 0.1f; + cam.far = 10f; + cam.position.set(0, 0, 0.1f); + cam.direction.set(0, 0, -1f); + batch = new DecalBatch(new CameraGroupStrategy(cam)); Gdx.gl.glClearColor(1, 1, 0, 1); } @@ -120,8 +124,6 @@ public class DecalTest extends GdxTest { cam.far = 10f; cam.position.set(0, 0, 0.1f); cam.direction.set(0, 0, -1f); - cam.update(); - cam.apply(Gdx.gl10); } private Decal makeDecal () { diff --git a/tests/gdx-tests/src/com/badlogic/gdx/tests/DeltaTimeTest.java b/tests/gdx-tests/src/com/badlogic/gdx/tests/DeltaTimeTest.java index dc43458b8..183e921ee 100644 --- a/tests/gdx-tests/src/com/badlogic/gdx/tests/DeltaTimeTest.java +++ b/tests/gdx-tests/src/com/badlogic/gdx/tests/DeltaTimeTest.java @@ -18,6 +18,7 @@ package com.badlogic.gdx.tests; import com.badlogic.gdx.Gdx; import com.badlogic.gdx.tests.utils.GdxTest; +import com.badlogic.gdx.utils.TimeUtils; public class DeltaTimeTest extends GdxTest { @@ -30,12 +31,12 @@ public class DeltaTimeTest extends GdxTest { @Override public void create () { - lastFrameTime = System.nanoTime(); + lastFrameTime = TimeUtils.nanoTime(); } @Override public void render () { - long frameTime = System.nanoTime(); + long frameTime = TimeUtils.nanoTime(); float deltaTime = (frameTime - lastFrameTime) / 1000000000.0f; lastFrameTime = frameTime; diff --git a/tests/gdx-tests/src/com/badlogic/gdx/tests/FillrateTest.java b/tests/gdx-tests/src/com/badlogic/gdx/tests/FillrateTest.java index 7c21dae29..2b23fd20e 100644 --- a/tests/gdx-tests/src/com/badlogic/gdx/tests/FillrateTest.java +++ b/tests/gdx-tests/src/com/badlogic/gdx/tests/FillrateTest.java @@ -25,12 +25,13 @@ import com.badlogic.gdx.graphics.Texture.TextureFilter; import com.badlogic.gdx.graphics.VertexAttribute; import com.badlogic.gdx.graphics.VertexAttributes; import com.badlogic.gdx.tests.utils.GdxTest; +import com.badlogic.gdx.utils.TimeUtils; public class FillrateTest extends GdxTest implements InputProcessor { Texture texture; Mesh mesh; int numFills = 1; - long lastOut = System.nanoTime(); + long lastOut = TimeUtils.nanoTime(); int mode = 0; float mean = 0; @@ -109,11 +110,11 @@ public class FillrateTest extends GdxTest implements InputProcessor { if (Gdx.graphics.getDeltaTime() < 1 / 60f) numFills++; - if (System.nanoTime() - lastOut >= 1000000000) { + if (TimeUtils.nanoTime() - lastOut >= 1000000000) { Gdx.app.log("FillrateTest", "fills: " + mean / frames + ", fps: " + frames + ", mode" + mode); mean = 0; frames = 0; - lastOut = System.nanoTime(); + lastOut = TimeUtils.nanoTime(); if (Gdx.graphics.getFramesPerSecond() < 60) numFills--; } } diff --git a/tests/gdx-tests/src/com/badlogic/gdx/tests/IntegerBitmapFontTest.java b/tests/gdx-tests/src/com/badlogic/gdx/tests/IntegerBitmapFontTest.java index 827f5e101..3b4d96367 100644 --- a/tests/gdx-tests/src/com/badlogic/gdx/tests/IntegerBitmapFontTest.java +++ b/tests/gdx-tests/src/com/badlogic/gdx/tests/IntegerBitmapFontTest.java @@ -21,6 +21,7 @@ import com.badlogic.gdx.graphics.g2d.BitmapFont; import com.badlogic.gdx.graphics.g2d.BitmapFont.HAlignment; import com.badlogic.gdx.graphics.g2d.BitmapFontCache; import com.badlogic.gdx.graphics.g2d.SpriteBatch; +import com.badlogic.gdx.graphics.g2d.TextureAtlas; import com.badlogic.gdx.tests.utils.GdxTest; public class IntegerBitmapFontTest extends GdxTest { @@ -38,7 +39,8 @@ public class IntegerBitmapFontTest extends GdxTest { SpriteBatch batch; public void create () { - font = new BitmapFont(); + TextureAtlas textureAtlas = new TextureAtlas("data/pack"); + font = new BitmapFont(Gdx.files.internal("data/verdana39.fnt"), textureAtlas.findRegion("verdana39"), false); singleLineCache = new BitmapFontCache(font, true); multiLineCache = new BitmapFontCache(font, true); singleLineCacheNonInteger = new BitmapFontCache(font, false); diff --git a/tests/gdx-tests/src/com/badlogic/gdx/tests/InverseKinematicsTest.java b/tests/gdx-tests/src/com/badlogic/gdx/tests/InverseKinematicsTest.java index 61e874365..09669cd0d 100644 --- a/tests/gdx-tests/src/com/badlogic/gdx/tests/InverseKinematicsTest.java +++ b/tests/gdx-tests/src/com/badlogic/gdx/tests/InverseKinematicsTest.java @@ -19,6 +19,8 @@ import com.badlogic.gdx.Gdx; import com.badlogic.gdx.graphics.GL10; import com.badlogic.gdx.graphics.OrthographicCamera; import com.badlogic.gdx.graphics.glutils.ImmediateModeRenderer10; +import com.badlogic.gdx.graphics.glutils.ShapeRenderer; +import com.badlogic.gdx.graphics.glutils.ShapeRenderer.ShapeType; import com.badlogic.gdx.math.Vector2; import com.badlogic.gdx.math.Vector3; import com.badlogic.gdx.tests.utils.GdxTest; @@ -50,7 +52,7 @@ public class InverseKinematicsTest extends GdxTest { static final float GRAVITY = 0; OrthographicCamera camera; - ImmediateModeRenderer10 renderer; + ShapeRenderer renderer; Bone[] bones; Vector3 globalCoords = new Vector3(); Vector3 endPoint = new Vector3(); @@ -60,7 +62,9 @@ public class InverseKinematicsTest extends GdxTest { public void create () { float aspect = Gdx.graphics.getWidth() / (float)Gdx.graphics.getHeight(); camera = new OrthographicCamera(15 * aspect, 15); - renderer = new ImmediateModeRenderer10(); + camera.update(); + renderer = new ShapeRenderer(); + renderer.setProjectionMatrix(camera.combined); bones = new Bone[] {new Bone("bone0", 0, 0, 0), new Bone("bone1", 0, 2, 2), new Bone("bone2", 0, 4, 2), new Bone("bone3", 0, 6, 2), new Bone("end", 0, 8, 2)}; @@ -72,7 +76,7 @@ public class InverseKinematicsTest extends GdxTest { Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT); camera.update(); - camera.apply(Gdx.gl10); + renderer.setProjectionMatrix(camera.combined); if (Gdx.input.isTouched()) camera.unproject(globalCoords.set(Gdx.input.getX(), Gdx.input.getY(), 0)); solveFakeIK(globalCoords); @@ -80,24 +84,19 @@ public class InverseKinematicsTest extends GdxTest { } private void renderBones () { - renderer.begin(GL10.GL_LINES); + renderer.begin(ShapeType.Line); + renderer.setColor(0, 1, 0, 1); for (int i = 0; i < bones.length - 1; i++) { - renderer.color(0, 1, 0, 1); - renderer.vertex(bones[i].position); - renderer.color(0, 1, 0, 1); - renderer.vertex(bones[i + 1].position); + renderer.line(bones[i].position.x, bones[i].position.y, bones[i + 1].position.x, bones[i + 1].position.y); } renderer.end(); - Gdx.gl10.glPointSize(5); - - renderer.begin(GL10.GL_POINTS); + renderer.begin(ShapeType.Point); + renderer.setColor(1, 0, 0, 1); for (int i = 0; i < bones.length; i++) { - renderer.color(1, 0, 0, 1); - renderer.vertex(bones[i].position); + renderer.point(bones[i].position.x, bones[i].position.y, 0); } renderer.end(); - Gdx.gl10.glPointSize(1); } public void solveFakeIK (Vector3 target) { diff --git a/tests/gdx-tests/src/com/badlogic/gdx/tests/IsometricTileTest.java b/tests/gdx-tests/src/com/badlogic/gdx/tests/IsometricTileTest.java index 36390f262..8a25d0aeb 100644 --- a/tests/gdx-tests/src/com/badlogic/gdx/tests/IsometricTileTest.java +++ b/tests/gdx-tests/src/com/badlogic/gdx/tests/IsometricTileTest.java @@ -24,8 +24,11 @@ import com.badlogic.gdx.graphics.OrthographicCamera; import com.badlogic.gdx.graphics.Texture; import com.badlogic.gdx.graphics.g2d.SpriteCache; import com.badlogic.gdx.graphics.glutils.ImmediateModeRenderer10; +import com.badlogic.gdx.graphics.glutils.ShapeRenderer; +import com.badlogic.gdx.graphics.glutils.ShapeRenderer.ShapeType; import com.badlogic.gdx.tests.utils.GdxTest; import com.badlogic.gdx.tests.utils.OrthoCamController; +import com.badlogic.gdx.utils.TimeUtils; public class IsometricTileTest extends GdxTest { static final int LAYERS = 1; @@ -43,8 +46,8 @@ public class IsometricTileTest extends GdxTest { int[] layers = new int[LAYERS]; OrthographicCamera cam; OrthoCamController camController; - ImmediateModeRenderer10 renderer; - long startTime = System.nanoTime(); + ShapeRenderer renderer; + long startTime = TimeUtils.nanoTime(); @Override public void create () { @@ -52,7 +55,7 @@ public class IsometricTileTest extends GdxTest { camController = new OrthoCamController(cam); Gdx.input.setInputProcessor(camController); - renderer = new ImmediateModeRenderer10(); + renderer = new ShapeRenderer(); texture = new Texture(Gdx.files.internal("data/isotile.png")); Random rand = new Random(); @@ -79,13 +82,12 @@ public class IsometricTileTest extends GdxTest { @Override public void render () { - GL10 gl = Gdx.gl10; - gl.glClearColor(0.7f, 0.7f, 0.7f, 1); - gl.glClear(GL10.GL_COLOR_BUFFER_BIT); + Gdx.gl.glClearColor(0.7f, 0.7f, 0.7f, 1); + Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT); cam.update(); - gl.glEnable(GL10.GL_BLEND); - gl.glBlendFunc(GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA); + Gdx.gl.glEnable(GL10.GL_BLEND); + Gdx.gl.glBlendFunc(GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA); for (int i = 0; i < LAYERS; i++) { SpriteCache cache = caches[i]; cache.setProjectionMatrix(cam.combined); @@ -94,25 +96,17 @@ public class IsometricTileTest extends GdxTest { cache.end(); } - renderer.begin(GL10.GL_LINES); - renderer.color(1, 0, 0, 1); - renderer.vertex(0, 0, 0); - renderer.color(1, 0, 0, 1); - renderer.vertex(500, 0, 0); - renderer.color(0, 1, 0, 1); - renderer.vertex(0, 0, 0); - renderer.color(0, 1, 0, 1); - renderer.vertex(0, 500, 0); - - renderer.color(0, 0, 1, 1); - renderer.vertex(0, BOUND_Y, 0); - renderer.color(0, 0, 1, 1); - renderer.vertex(BOUND_X, BOUND_Y, 0); - - renderer.color(0, 0, 1, 1); - renderer.vertex(BOUND_X, 0, 0); - renderer.color(0, 0, 1, 1); - renderer.vertex(BOUND_X, BOUND_Y, 0); + renderer.setProjectionMatrix(cam.combined); + renderer.begin(ShapeType.Line); + renderer.setColor(1, 0, 0, 1); + renderer.line(0, 0, 500, 0); + renderer.line(0, 0, 0, 500); + + renderer.setColor(0, 0, 1, 1); + renderer.line(0, BOUND_Y, BOUND_X, BOUND_Y); + + renderer.setColor(0, 0, 1, 1); + renderer.line(BOUND_X, 0, BOUND_X, BOUND_Y); renderer.end(); } diff --git a/tests/gdx-tests/src/com/badlogic/gdx/tests/MD5Test.java b/tests/gdx-tests/src/com/badlogic/gdx/tests/MD5Test.java index 95050f6d2..018a33cf0 100644 --- a/tests/gdx-tests/src/com/badlogic/gdx/tests/MD5Test.java +++ b/tests/gdx-tests/src/com/badlogic/gdx/tests/MD5Test.java @@ -29,6 +29,7 @@ import com.badlogic.gdx.graphics.g3d.loaders.md5.MD5Loader; import com.badlogic.gdx.graphics.g3d.loaders.md5.MD5Model; import com.badlogic.gdx.graphics.g3d.loaders.md5.MD5Renderer; import com.badlogic.gdx.tests.utils.GdxTest; +import com.badlogic.gdx.utils.TimeUtils; public class MD5Test extends GdxTest implements InputProcessor { PerspectiveCamera camera; @@ -52,10 +53,10 @@ public class MD5Test extends GdxTest implements InputProcessor { renderer = new MD5Renderer(model, useNormals, false); renderer.setSkeleton(model.baseSkeleton); - // long start = System.nanoTime(); + // long start = TimeUtils.nanoTime(); // for( int i = 0; i < 100000; i++ ) // renderer.setSkeleton( model.baseSkeleton ); - // app.log( "MD5 Test", "took: " + (System.nanoTime() - start ) / + // app.log( "MD5 Test", "took: " + (TimeUtils.nanoTime() - start ) / // 1000000000.0 ); camera = new PerspectiveCamera(60, Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); @@ -94,15 +95,15 @@ public class MD5Test extends GdxTest implements InputProcessor { gl.glRotatef(angle, 0, 1, 0); gl.glRotatef(-90, 1, 0, 0); - start = System.nanoTime(); + start = TimeUtils.nanoTime(); MD5Animation.interpolate(anim.frames[animInfo.getCurrentFrame()], anim.frames[animInfo.getNextFrame()], skeleton, animInfo.getInterpolation()); renderer.setSkeleton(skeleton); - skinTime = (System.nanoTime() - start) / 1000000000.0f; + skinTime = (TimeUtils.nanoTime() - start) / 1000000000.0f; - start = System.nanoTime(); + start = TimeUtils.nanoTime(); renderer.render(); - renderTime = (System.nanoTime() - start) / 1000000000.0f; + renderTime = (TimeUtils.nanoTime() - start) / 1000000000.0f; gl.glPopMatrix(); } diff --git a/tests/gdx-tests/src/com/badlogic/gdx/tests/MatrixJNITest.java b/tests/gdx-tests/src/com/badlogic/gdx/tests/MatrixJNITest.java index a9c97729f..f83e0c861 100644 --- a/tests/gdx-tests/src/com/badlogic/gdx/tests/MatrixJNITest.java +++ b/tests/gdx-tests/src/com/badlogic/gdx/tests/MatrixJNITest.java @@ -20,6 +20,7 @@ import com.badlogic.gdx.math.Matrix4; import com.badlogic.gdx.math.Vector3; import com.badlogic.gdx.tests.utils.GdxTest; import com.badlogic.gdx.utils.GdxRuntimeException; +import com.badlogic.gdx.utils.TimeUtils; public class MatrixJNITest extends GdxTest { @Override @@ -76,48 +77,48 @@ public class MatrixJNITest extends GdxTest { Matrix4 mata = new Matrix4(); Matrix4 matb = new Matrix4(); - long start = System.nanoTime(); + long start = TimeUtils.nanoTime(); for (int i = 0; i < 1000000; i++) { mata.mul(matb); } - Gdx.app.log("MatrixJNITest", "java matrix * matrix took: " + (System.nanoTime() - start) / 1000000000.0f); + Gdx.app.log("MatrixJNITest", "java matrix * matrix took: " + (TimeUtils.nanoTime() - start) / 1000000000.0f); - start = System.nanoTime(); + start = TimeUtils.nanoTime(); for (int i = 0; i < 1000000; i++) { Matrix4.mul(mata.val, matb.val); } - Gdx.app.log("MatrixJNITest", "jni matrix * matrix took: " + (System.nanoTime() - start) / 1000000000.0f); + Gdx.app.log("MatrixJNITest", "jni matrix * matrix took: " + (TimeUtils.nanoTime() - start) / 1000000000.0f); Vector3 vec = new Vector3(); - start = System.nanoTime(); + start = TimeUtils.nanoTime(); for (int i = 0; i < 500000; i++) { vec.mul(mata); } - Gdx.app.log("MatrixJNITest", "java vecs * matrix took: " + (System.nanoTime() - start) / 1000000000.0f); + Gdx.app.log("MatrixJNITest", "java vecs * matrix took: " + (TimeUtils.nanoTime() - start) / 1000000000.0f); float[] fvec = new float[3]; - start = System.nanoTime(); + start = TimeUtils.nanoTime(); for (int i = 0; i < 500000; i++) { Matrix4.mulVec(mata.val, fvec); } - Gdx.app.log("MatrixJNITest", "jni vecs * matrix took: " + (System.nanoTime() - start) / 1000000000.0f); + Gdx.app.log("MatrixJNITest", "jni vecs * matrix took: " + (TimeUtils.nanoTime() - start) / 1000000000.0f); float[] fvecs = new float[3 * 500000]; - start = System.nanoTime(); + start = TimeUtils.nanoTime(); Matrix4.mulVec(mata.val, fvecs, 0, 500000, 3); - Gdx.app.log("MatrixJNITest", "jni bulk vecs * matrix took: " + (System.nanoTime() - start) / 1000000000.0f); + Gdx.app.log("MatrixJNITest", "jni bulk vecs * matrix took: " + (TimeUtils.nanoTime() - start) / 1000000000.0f); - start = System.nanoTime(); + start = TimeUtils.nanoTime(); for (int i = 0; i < 1000000; i++) { mata.inv(); } - Gdx.app.log("MatrixJNITest", "java inv(matrix): " + (System.nanoTime() - start) / 1000000000.0f); + Gdx.app.log("MatrixJNITest", "java inv(matrix): " + (TimeUtils.nanoTime() - start) / 1000000000.0f); - start = System.nanoTime(); + start = TimeUtils.nanoTime(); for (int i = 0; i < 1000000; i++) { Matrix4.inv(mata.val); } - Gdx.app.log("MatrixJNITest", "jni inv(matrix): " + (System.nanoTime() - start) / 1000000000.0f); + Gdx.app.log("MatrixJNITest", "jni inv(matrix): " + (TimeUtils.nanoTime() - start) / 1000000000.0f); } private void check (Vector3 vec, float[] fvec) { diff --git a/tests/gdx-tests/src/com/badlogic/gdx/tests/MeshShaderTest.java b/tests/gdx-tests/src/com/badlogic/gdx/tests/MeshShaderTest.java index 9b0b4a762..777324f0c 100644 --- a/tests/gdx-tests/src/com/badlogic/gdx/tests/MeshShaderTest.java +++ b/tests/gdx-tests/src/com/badlogic/gdx/tests/MeshShaderTest.java @@ -63,7 +63,7 @@ public class MeshShaderTest extends GdxTest { shader = new ShaderProgram(vertexShader, fragmentShader); if (shader.isCompiled() == false) { Gdx.app.log("ShaderTest", shader.getLog()); - System.exit(0); + Gdx.app.exit(); } mesh = new Mesh(true, 4, 6, VertexAttribute.Position(), VertexAttribute.ColorUnpacked(), VertexAttribute.TexCoords(0)); diff --git a/tests/gdx-tests/src/com/badlogic/gdx/tests/MultitouchTest.java b/tests/gdx-tests/src/com/badlogic/gdx/tests/MultitouchTest.java index 395f84b39..4c5698f55 100644 --- a/tests/gdx-tests/src/com/badlogic/gdx/tests/MultitouchTest.java +++ b/tests/gdx-tests/src/com/badlogic/gdx/tests/MultitouchTest.java @@ -23,22 +23,24 @@ import com.badlogic.gdx.graphics.Color; import com.badlogic.gdx.graphics.GL10; import com.badlogic.gdx.graphics.OrthographicCamera; import com.badlogic.gdx.graphics.glutils.ImmediateModeRenderer10; +import com.badlogic.gdx.graphics.glutils.ShapeRenderer; +import com.badlogic.gdx.graphics.glutils.ShapeRenderer.ShapeType; import com.badlogic.gdx.tests.utils.GdxTest; +import com.badlogic.gdx.utils.TimeUtils; -public class MultitouchTest extends GdxTest implements InputProcessor { - ImmediateModeRenderer10 renderer; +public class MultitouchTest extends GdxTest { + ShapeRenderer renderer; OrthographicCamera camera; - long startTime = System.nanoTime(); + long startTime = TimeUtils.nanoTime(); Color[] colors = {Color.RED, Color.BLUE, Color.GREEN, Color.WHITE}; @Override public void render () { - Gdx.graphics.getGL10().glClear(GL10.GL_COLOR_BUFFER_BIT); - Gdx.graphics.getGL10().glViewport(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); + Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT); camera.update(); - camera.apply(Gdx.gl10); - renderer.begin(GL10.GL_TRIANGLES); + renderer.setProjectionMatrix(camera.combined); + renderer.begin(ShapeType.FilledTriangle); int size = Math.max(Gdx.graphics.getWidth(), Gdx.graphics.getHeight()) / 10; for (int i = 0; i < 10; i++) { if (Gdx.input.isTouched(i) == false) continue; @@ -46,76 +48,17 @@ public class MultitouchTest extends GdxTest implements InputProcessor { float x = Gdx.input.getX(i); float y = Gdx.graphics.getHeight() - Gdx.input.getY(i) - 1; Color col = colors[i % colors.length]; - renderer.color(col.r, col.g, col.b, col.a); - renderer.vertex(x, y + size, 0); - renderer.color(col.r, col.g, col.b, col.a); - renderer.vertex(x + size, y - size, 0); - renderer.color(col.r, col.g, col.b, col.a); - renderer.vertex(x - size, y - size, 0); + renderer.filledTriangle(x, y + size, x + size, y - size, x - size, y - size); } - renderer.end(); - -// if (System.nanoTime() - startTime > 1000000000l) { -// Gdx.app.log("MultiTouhTest", "fps:" + Gdx.graphics.getFramesPerSecond()); -// startTime = System.nanoTime(); -// } } @Override public void create () { Gdx.app.log("Multitouch", "multitouch supported: " + Gdx.input.isPeripheralAvailable(Peripheral.MultitouchScreen)); - renderer = new ImmediateModeRenderer10(); + renderer = new ShapeRenderer(); camera = new OrthographicCamera(Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); camera.position.set(Gdx.graphics.getWidth() / 2.0f, Gdx.graphics.getHeight() / 2.0f, 0); Gdx.input.setInputProcessor(this); } - - @Override - public boolean keyDown (int keycode) { - return false; - } - - @Override - public boolean keyTyped (char character) { - return false; - } - - @Override - public boolean keyUp (int keycode) { - return false; - } - - @Override - public boolean touchDown (int x, int y, int pointer, int newParam) { -// Gdx.app.log("Multitouch", "down: " + pointer); - return false; - } - - @Override - public boolean touchDragged (int x, int y, int pointer) { -// Gdx.app.log("Multitouch", "drag: " + pointer); - return false; - } - - @Override - public boolean touchUp (int x, int y, int pointer, int button) { -// Gdx.app.log("Multitouch", "up: " + pointer); - return false; - } - - @Override - public boolean needsGL20 () { - return false; - } - - @Override - public boolean touchMoved (int x, int y) { - return false; - } - - @Override - public boolean scrolled (int amount) { - return false; - } } diff --git a/tests/gdx-tests/src/com/badlogic/gdx/tests/MusicTest.java b/tests/gdx-tests/src/com/badlogic/gdx/tests/MusicTest.java index e129e547f..0bc64b1a4 100644 --- a/tests/gdx-tests/src/com/badlogic/gdx/tests/MusicTest.java +++ b/tests/gdx-tests/src/com/badlogic/gdx/tests/MusicTest.java @@ -41,7 +41,7 @@ public class MusicTest extends GdxTest { @Override public void create () { for (int i = 0; i < music.length; i++) { - music[i] = Gdx.audio.newMusic(Gdx.files.internal("data/music.mp3")); + music[i] = Gdx.audio.newMusic(Gdx.files.internal("data/cloudconnected.ogg")); } buttons = new TextureRegion(new Texture(Gdx.files.internal("data/playback.png"))); diff --git a/tests/gdx-tests/src/com/badlogic/gdx/tests/ParallaxTest.java b/tests/gdx-tests/src/com/badlogic/gdx/tests/ParallaxTest.java index 7b2f882f8..97ed0f7cc 100644 --- a/tests/gdx-tests/src/com/badlogic/gdx/tests/ParallaxTest.java +++ b/tests/gdx-tests/src/com/badlogic/gdx/tests/ParallaxTest.java @@ -74,7 +74,7 @@ public class ParallaxTest extends GdxTest { controller = new OrthoCamController(camera); Gdx.input.setInputProcessor(controller); batch = new SpriteBatch(); - font = new BitmapFont(); + font = new BitmapFont(Gdx.files.internal("data/arial-15.fnt"), false); } @Override diff --git a/tests/gdx-tests/src/com/badlogic/gdx/tests/ParticleEmitterTest.java b/tests/gdx-tests/src/com/badlogic/gdx/tests/ParticleEmitterTest.java index 13c6d951e..fe4304ab8 100644 --- a/tests/gdx-tests/src/com/badlogic/gdx/tests/ParticleEmitterTest.java +++ b/tests/gdx-tests/src/com/badlogic/gdx/tests/ParticleEmitterTest.java @@ -115,8 +115,7 @@ public class ParticleEmitterTest extends GdxTest { public void render () { spriteBatch.getProjectionMatrix().setToOrtho2D(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); float delta = Gdx.graphics.getDeltaTime(); - GL10 gl = Gdx.graphics.getGL10(); - gl.glClear(GL10.GL_COLOR_BUFFER_BIT); + Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT); spriteBatch.begin(); effect.draw(spriteBatch, delta); spriteBatch.end(); diff --git a/tests/gdx-tests/src/com/badlogic/gdx/tests/PixelsPerInchTest.java b/tests/gdx-tests/src/com/badlogic/gdx/tests/PixelsPerInchTest.java index c3ddde245..5dc5bdb46 100644 --- a/tests/gdx-tests/src/com/badlogic/gdx/tests/PixelsPerInchTest.java +++ b/tests/gdx-tests/src/com/badlogic/gdx/tests/PixelsPerInchTest.java @@ -31,13 +31,13 @@ public class PixelsPerInchTest extends GdxTest { @Override public void create () { - font = new BitmapFont(); + font = new BitmapFont(Gdx.files.internal("data/arial-15.fnt"), false); batch = new SpriteBatch(); texture = new Texture(Gdx.files.internal("data/badlogicsmall.jpg")); } public void render () { - Gdx.gl10.glClear(GL10.GL_COLOR_BUFFER_BIT); + Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT); batch.begin(); float width = (int)(Gdx.graphics.getPpcX() * 2); @@ -51,7 +51,7 @@ public class PixelsPerInchTest extends GdxTest { @Override public boolean needsGL20 () { - return false; + return true; } } diff --git a/tests/gdx-tests/src/com/badlogic/gdx/tests/PixmapBlendingTest.java b/tests/gdx-tests/src/com/badlogic/gdx/tests/PixmapBlendingTest.java index 5e9a5be71..d32420e89 100644 --- a/tests/gdx-tests/src/com/badlogic/gdx/tests/PixmapBlendingTest.java +++ b/tests/gdx-tests/src/com/badlogic/gdx/tests/PixmapBlendingTest.java @@ -63,9 +63,8 @@ public class PixmapBlendingTest extends GdxTest { @Override public void render () { - GL10 gl = Gdx.graphics.getGL10(); - gl.glClearColor(0, 1, 0, 1); - gl.glClear(GL10.GL_COLOR_BUFFER_BIT); + Gdx.gl.glClearColor(0, 1, 0, 1); + Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT); spriteBatch.begin(); logoSprite.draw(spriteBatch); diff --git a/tests/gdx-tests/src/com/badlogic/gdx/tests/PixmapTest.java b/tests/gdx-tests/src/com/badlogic/gdx/tests/PixmapTest.java index f9676486f..1f953c36a 100644 --- a/tests/gdx-tests/src/com/badlogic/gdx/tests/PixmapTest.java +++ b/tests/gdx-tests/src/com/badlogic/gdx/tests/PixmapTest.java @@ -19,7 +19,6 @@ package com.badlogic.gdx.tests; import com.badlogic.gdx.Gdx; import com.badlogic.gdx.graphics.GL10; import com.badlogic.gdx.graphics.Pixmap; -import com.badlogic.gdx.graphics.PixmapIO; import com.badlogic.gdx.graphics.Texture; import com.badlogic.gdx.graphics.g2d.SpriteBatch; import com.badlogic.gdx.graphics.g2d.TextureRegion; @@ -38,12 +37,6 @@ public class PixmapTest extends GdxTest { TextureRegion region; public void create () { - pixmap = new Pixmap(2, 2, Pixmap.Format.RGBA8888); - pixmap.setColor(1, 0, 0, 1); - pixmap.fill(); - PixmapIO.writePNG(Gdx.files.absolute("test.png"), pixmap); - pixmap.dispose(); - // Create an empty dynamic pixmap pixmap = new Pixmap(800, 480, Pixmap.Format.RGBA8888); // Pixmap.Format.RGBA8888); diff --git a/tests/gdx-tests/src/com/badlogic/gdx/tests/ShapeRendererTest.java b/tests/gdx-tests/src/com/badlogic/gdx/tests/ShapeRendererTest.java index b6ab5a12e..346de810d 100644 --- a/tests/gdx-tests/src/com/badlogic/gdx/tests/ShapeRendererTest.java +++ b/tests/gdx-tests/src/com/badlogic/gdx/tests/ShapeRendererTest.java @@ -49,7 +49,7 @@ public class ShapeRendererTest extends GdxTest { controller = new PerspectiveCamController(cam); Gdx.input.setInputProcessor(controller); batch = new SpriteBatch(); - font = new BitmapFont(); + font = new BitmapFont(Gdx.files.internal("data/arial-15.fnt"), false); } public void render () { diff --git a/tests/gdx-tests/src/com/badlogic/gdx/tests/SimpleAnimationTest.java b/tests/gdx-tests/src/com/badlogic/gdx/tests/SimpleAnimationTest.java index ba177b6ec..a1840ce16 100644 --- a/tests/gdx-tests/src/com/badlogic/gdx/tests/SimpleAnimationTest.java +++ b/tests/gdx-tests/src/com/badlogic/gdx/tests/SimpleAnimationTest.java @@ -26,7 +26,7 @@ import com.badlogic.gdx.graphics.g2d.TextureRegion; import com.badlogic.gdx.math.Vector2; import com.badlogic.gdx.tests.utils.GdxTest; -public class SimpleAnimationTest extends GdxTest implements InputProcessor { +public class SimpleAnimationTest extends GdxTest { @Override public boolean needsGL20 () { @@ -83,50 +83,7 @@ public class SimpleAnimationTest extends GdxTest implements InputProcessor { @Override public boolean touchDown (int x, int y, int pointer, int button) { position.x = x; - position.y = y; - // System.out.println(position); + position.y = Gdx.graphics.getHeight() - y; return true; } - - @Override - public boolean keyDown (int keycode) { - // TODO Auto-generated method stub - return false; - } - - @Override - public boolean keyUp (int keycode) { - // TODO Auto-generated method stub - return false; - } - - @Override - public boolean keyTyped (char character) { - // TODO Auto-generated method stub - return false; - } - - @Override - public boolean touchUp (int x, int y, int pointer, int button) { - // TODO Auto-generated method stub - return false; - } - - @Override - public boolean touchDragged (int x, int y, int pointer) { - // TODO Auto-generated method stub - return false; - } - - @Override - public boolean touchMoved (int x, int y) { - // TODO Auto-generated method stub - return false; - } - - @Override - public boolean scrolled (int amount) { - // TODO Auto-generated method stub - return false; - } } diff --git a/tests/gdx-tests/src/com/badlogic/gdx/tests/SimpleTest.java b/tests/gdx-tests/src/com/badlogic/gdx/tests/SimpleTest.java deleted file mode 100644 index d1b51a9ec..000000000 --- a/tests/gdx-tests/src/com/badlogic/gdx/tests/SimpleTest.java +++ /dev/null @@ -1,101 +0,0 @@ -/******************************************************************************* - * Copyright 2011 See AUTHORS file. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - ******************************************************************************/ - -package com.badlogic.gdx.tests; - -import com.badlogic.gdx.Gdx; -import com.badlogic.gdx.InputProcessor; -import com.badlogic.gdx.graphics.GL10; -import com.badlogic.gdx.tests.utils.GdxTest; - -public class SimpleTest extends GdxTest implements InputProcessor { - float r = 1, g = 0, b = 0; - - @Override - public void create () { - Gdx.app.log("Simple Test", "Thread=" + Thread.currentThread().getId() + ", surface created"); - Gdx.input.setInputProcessor(this); - } - - @Override - public void render () { - GL10 gl = Gdx.app.getGraphics().getGL10(); - - gl.glClearColor(r, g, b, 1); - gl.glClear(GL10.GL_COLOR_BUFFER_BIT); - } - - @Override - public void dispose () { - Gdx.app.log("Simple Test", "Thread=" + Thread.currentThread().getId() + ", application destroyed"); - } - - @Override - public boolean keyDown (int keycode) { - return false; - } - - @Override - public boolean keyTyped (char character) { - return false; - } - - @Override - public boolean keyUp (int keycode) { - return false; - } - - @Override - public boolean touchDown (int x, int y, int pointer, int newParam) { - return false; - } - - @Override - public boolean touchDragged (int x, int y, int pointer) { - return false; - } - - @Override - public boolean touchUp (int x, int y, int pointer, int button) { - r = (float)Math.random(); - g = (float)Math.random(); - b = (float)Math.random(); - return false; - } - - @Override - public void pause () { - } - - @Override - public void resume () { - } - - @Override - public boolean needsGL20 () { - return false; - } - - @Override - public boolean touchMoved (int x, int y) { - return false; - } - - @Override - public boolean scrolled (int amount) { - return false; - } -} diff --git a/tests/gdx-tests/src/com/badlogic/gdx/tests/SpriteBatchShaderTest.java b/tests/gdx-tests/src/com/badlogic/gdx/tests/SpriteBatchShaderTest.java index 0c7630d63..623d0515d 100644 --- a/tests/gdx-tests/src/com/badlogic/gdx/tests/SpriteBatchShaderTest.java +++ b/tests/gdx-tests/src/com/badlogic/gdx/tests/SpriteBatchShaderTest.java @@ -25,11 +25,12 @@ import com.badlogic.gdx.graphics.Pixmap.Format; import com.badlogic.gdx.graphics.Texture; import com.badlogic.gdx.graphics.g2d.SpriteBatch; import com.badlogic.gdx.tests.utils.GdxTest; +import com.badlogic.gdx.utils.TimeUtils; public class SpriteBatchShaderTest extends GdxTest { int SPRITES = 400; - long startTime = System.nanoTime(); + long startTime = TimeUtils.nanoTime(); int frames = 0; Texture texture; @@ -56,37 +57,37 @@ public class SpriteBatchShaderTest extends GdxTest { float draw2 = 0; float drawText = 0; - long start = System.nanoTime(); + long start = TimeUtils.nanoTime(); spriteBatch.begin(); - begin = (System.nanoTime() - start) / 1000000000.0f; + begin = (TimeUtils.nanoTime() - start) / 1000000000.0f; int len = coords.length; - start = System.nanoTime(); + start = TimeUtils.nanoTime(); for (int i = 0; i < len; i += 2) spriteBatch.draw(texture, coords[i], coords[i + 1], 0, 0, 32, 32); - draw1 = (System.nanoTime() - start) / 1000000000.0f; + draw1 = (TimeUtils.nanoTime() - start) / 1000000000.0f; - start = System.nanoTime(); + start = TimeUtils.nanoTime(); spriteBatch.setColor(col); for (int i = 0; i < coords2.length; i += 2) spriteBatch.draw(texture2, coords2[i], coords2[i + 1], 0, 0, 32, 32); - draw2 = (System.nanoTime() - start) / 1000000000.0f; + draw2 = (TimeUtils.nanoTime() - start) / 1000000000.0f; - start = System.nanoTime(); + start = TimeUtils.nanoTime(); // spriteBatch.drawText(font, "Question?", 100, 300, Color.RED); // spriteBatch.drawText(font, "and another this is a test", 200, 100, Color.WHITE); // spriteBatch.drawText(font, "all hail and another this is a test", 200, 200, Color.WHITE); - drawText = (System.nanoTime() - start) / 1000000000.0f; + drawText = (TimeUtils.nanoTime() - start) / 1000000000.0f; - start = System.nanoTime(); + start = TimeUtils.nanoTime(); spriteBatch.end(); - end = (System.nanoTime() - start) / 1000000000.0f; + end = (TimeUtils.nanoTime() - start) / 1000000000.0f; - if (System.nanoTime() - startTime > 1000000000) { + if (TimeUtils.nanoTime() - startTime > 1000000000) { Gdx.app.log("SpriteBatch", "fps: " + frames + ", render calls: " + spriteBatch.renderCalls + ", " + begin + ", " + draw1 + ", " + draw2 + ", " + drawText + ", " + end); frames = 0; - startTime = System.nanoTime(); + startTime = TimeUtils.nanoTime(); } frames++; } @@ -94,24 +95,14 @@ public class SpriteBatchShaderTest extends GdxTest { @Override public void create () { spriteBatch = new SpriteBatch(); - Pixmap pixmap = new Pixmap(Gdx.files.internal("data/badlogicsmall.jpg")); -// pixmap.setColor( 0, 0, 0, 0 ); -// pixmap.fillCircle( 16, 16, 4 ); - texture = new Texture(32, 32, Format.RGB565); - texture.draw(pixmap, 0, 0); - pixmap.dispose(); + texture = new Texture(Gdx.files.internal("data/badlogicsmall.jpg")); - pixmap = new Pixmap(32, 32, Format.RGB565); + Pixmap pixmap = new Pixmap(32, 32, Format.RGB565); pixmap.setColor(1, 1, 0, 0.7f); pixmap.fill(); -// pixmap.setColor( 0, 0, 0, 0 ); -// pixmap.fillCircle( 16, 16, 4 ); -// texture2 = new Texture(pixmap); pixmap.dispose(); -// if (font == null) font = Gdx.graphics.newFont("Arial", 32, FontStyle.Plain); - for (int i = 0; i < coords.length; i += 2) { coords[i] = (int)(Math.random() * Gdx.graphics.getWidth()); coords[i + 1] = (int)(Math.random() * Gdx.graphics.getHeight()); diff --git a/tests/gdx-tests/src/com/badlogic/gdx/tests/SpriteBatchTest.java b/tests/gdx-tests/src/com/badlogic/gdx/tests/SpriteBatchTest.java index da40c9301..27b9fdcb4 100644 --- a/tests/gdx-tests/src/com/badlogic/gdx/tests/SpriteBatchTest.java +++ b/tests/gdx-tests/src/com/badlogic/gdx/tests/SpriteBatchTest.java @@ -26,11 +26,12 @@ import com.badlogic.gdx.graphics.Texture.TextureFilter; import com.badlogic.gdx.graphics.g2d.Sprite; import com.badlogic.gdx.graphics.g2d.SpriteBatch; import com.badlogic.gdx.tests.utils.GdxTest; +import com.badlogic.gdx.utils.TimeUtils; public class SpriteBatchTest extends GdxTest implements InputProcessor { int SPRITES = 100 / 2; - long startTime = System.nanoTime(); + long startTime = TimeUtils.nanoTime(); int frames = 0; Texture texture; @@ -75,37 +76,37 @@ public class SpriteBatchTest extends GdxTest implements InputProcessor { SCALE_SPEED = -1; } - long start = System.nanoTime(); + long start = TimeUtils.nanoTime(); spriteBatch.begin(); - begin = (System.nanoTime() - start) / 1000000000.0f; + begin = (TimeUtils.nanoTime() - start) / 1000000000.0f; - start = System.nanoTime(); + start = TimeUtils.nanoTime(); for (int i = 0; i < sprites.length; i += 6) spriteBatch.draw(texture, sprites[i], sprites[i + 1], 16, 16, 32, 32, scale, scale, angle, 0, 0, 32, 32, false, false); - draw1 = (System.nanoTime() - start) / 1000000000.0f; + draw1 = (TimeUtils.nanoTime() - start) / 1000000000.0f; - start = System.nanoTime(); + start = TimeUtils.nanoTime(); for (int i = 0; i < sprites2.length; i += 6) spriteBatch .draw(texture2, sprites2[i], sprites2[i + 1], 16, 16, 32, 32, scale, scale, angle, 0, 0, 32, 32, false, false); - draw2 = (System.nanoTime() - start) / 1000000000.0f; + draw2 = (TimeUtils.nanoTime() - start) / 1000000000.0f; - start = System.nanoTime(); + start = TimeUtils.nanoTime(); // spriteBatch.drawText(font, "Question?", 100, 300, Color.RED); // spriteBatch.drawText(font, "and another this is a test", 200, 100, Color.WHITE); // spriteBatch.drawText(font, "all hail and another this is a test", 200, 200, Color.WHITE); // spriteBatch.drawText(font, "normal fps: " + Gdx.graphics.getFramesPerSecond(), 10, 30, Color.RED); - drawText = (System.nanoTime() - start) / 1000000000.0f; + drawText = (TimeUtils.nanoTime() - start) / 1000000000.0f; - start = System.nanoTime(); + start = TimeUtils.nanoTime(); spriteBatch.end(); - end = (System.nanoTime() - start) / 1000000000.0f; + end = (TimeUtils.nanoTime() - start) / 1000000000.0f; - if (System.nanoTime() - startTime > 1000000000) { + if (TimeUtils.nanoTime() - startTime > 1000000000) { Gdx.app.log("SpriteBatch", "fps: " + frames + ", render calls: " + spriteBatch.renderCalls + ", " + begin + ", " + draw1 + ", " + draw2 + ", " + drawText + ", " + end); frames = 0; - startTime = System.nanoTime(); + startTime = TimeUtils.nanoTime(); } frames++; @@ -122,9 +123,9 @@ public class SpriteBatchTest extends GdxTest implements InputProcessor { float draw2 = 0; float drawText = 0; - long start = System.nanoTime(); + long start = TimeUtils.nanoTime(); spriteBatch.begin(); - begin = (System.nanoTime() - start) / 1000000000.0f; + begin = (TimeUtils.nanoTime() - start) / 1000000000.0f; float angleInc = ROTATION_SPEED * Gdx.graphics.getDeltaTime(); scale += SCALE_SPEED * Gdx.graphics.getDeltaTime(); @@ -137,38 +138,38 @@ public class SpriteBatchTest extends GdxTest implements InputProcessor { SCALE_SPEED = -1; } - start = System.nanoTime(); + start = TimeUtils.nanoTime(); for (int i = 0; i < SPRITES; i++) { if (angleInc != 0) sprites3[i].rotate(angleInc); // this is aids if (scale != 1) sprites3[i].setScale(scale); // this is aids sprites3[i].draw(spriteBatch); } - draw1 = (System.nanoTime() - start) / 1000000000.0f; + draw1 = (TimeUtils.nanoTime() - start) / 1000000000.0f; - start = System.nanoTime(); + start = TimeUtils.nanoTime(); for (int i = SPRITES; i < SPRITES << 1; i++) { if (angleInc != 0) sprites3[i].rotate(angleInc); // this is aids if (scale != 1) sprites3[i].setScale(scale); // this is aids sprites3[i].draw(spriteBatch); } - draw2 = (System.nanoTime() - start) / 1000000000.0f; + draw2 = (TimeUtils.nanoTime() - start) / 1000000000.0f; - start = System.nanoTime(); + start = TimeUtils.nanoTime(); // spriteBatch.drawText(font, "Question?", 100, 300, Color.RED); // spriteBatch.drawText(font, "and another this is a test", 200, 100, Color.WHITE); // spriteBatch.drawText(font, "all hail and another this is a test", 200, 200, Color.WHITE); // spriteBatch.drawText(font, "Sprite fps: " + Gdx.graphics.getFramesPerSecond(), 10, 30, Color.RED); - drawText = (System.nanoTime() - start) / 1000000000.0f; + drawText = (TimeUtils.nanoTime() - start) / 1000000000.0f; - start = System.nanoTime(); + start = TimeUtils.nanoTime(); spriteBatch.end(); - end = (System.nanoTime() - start) / 1000000000.0f; + end = (TimeUtils.nanoTime() - start) / 1000000000.0f; - if (System.nanoTime() - startTime > 1000000000) { + if (TimeUtils.nanoTime() - startTime > 1000000000) { Gdx.app.log("SpriteBatch", "fps: " + frames + ", render calls: " + spriteBatch.renderCalls + ", " + begin + ", " + draw1 + ", " + draw2 + ", " + drawText + ", " + end); frames = 0; - startTime = System.nanoTime(); + startTime = TimeUtils.nanoTime(); } frames++; } diff --git a/tests/gdx-tests/src/com/badlogic/gdx/tests/SpriteCacheTest.java b/tests/gdx-tests/src/com/badlogic/gdx/tests/SpriteCacheTest.java index f92fbbcaf..3e07b4a3c 100644 --- a/tests/gdx-tests/src/com/badlogic/gdx/tests/SpriteCacheTest.java +++ b/tests/gdx-tests/src/com/badlogic/gdx/tests/SpriteCacheTest.java @@ -28,11 +28,12 @@ import com.badlogic.gdx.graphics.g2d.Sprite; import com.badlogic.gdx.graphics.g2d.SpriteCache; import com.badlogic.gdx.math.MathUtils; import com.badlogic.gdx.tests.utils.GdxTest; +import com.badlogic.gdx.utils.TimeUtils; public class SpriteCacheTest extends GdxTest implements InputProcessor { int SPRITES = 400 / 2; - long startTime = System.nanoTime(); + long startTime = TimeUtils.nanoTime(); int frames = 0; Texture texture; @@ -60,23 +61,23 @@ public class SpriteCacheTest extends GdxTest implements InputProcessor { float end = 0; float draw1 = 0; - long start = System.nanoTime(); + long start = TimeUtils.nanoTime(); spriteCache.begin(); - begin = (System.nanoTime() - start) / 1000000000.0f; + begin = (TimeUtils.nanoTime() - start) / 1000000000.0f; - start = System.nanoTime(); + start = TimeUtils.nanoTime(); spriteCache.draw(normalCacheID); - draw1 = (System.nanoTime() - start) / 1000000000.0f; + draw1 = (TimeUtils.nanoTime() - start) / 1000000000.0f; - start = System.nanoTime(); + start = TimeUtils.nanoTime(); spriteCache.end(); - end = (System.nanoTime() - start) / 1000000000.0f; + end = (TimeUtils.nanoTime() - start) / 1000000000.0f; - if (System.nanoTime() - startTime > 1000000000) { + if (TimeUtils.nanoTime() - startTime > 1000000000) { // Gdx.app.log( "SpriteBatch", "fps: " + frames + ", render calls: " + spriteBatch.renderCalls + ", " + begin + ", " + draw1 + // ", " + draw2 + ", " + drawText + ", " + end ); frames = 0; - startTime = System.nanoTime(); + startTime = TimeUtils.nanoTime(); } frames++; } @@ -92,23 +93,23 @@ public class SpriteCacheTest extends GdxTest implements InputProcessor { float draw2 = 0; float drawText = 0; - long start = System.nanoTime(); + long start = TimeUtils.nanoTime(); spriteCache.begin(); - begin = (System.nanoTime() - start) / 1000000000.0f; + begin = (TimeUtils.nanoTime() - start) / 1000000000.0f; - start = System.nanoTime(); + start = TimeUtils.nanoTime(); spriteCache.draw(spriteCacheID); - draw1 = (System.nanoTime() - start) / 1000000000.0f; + draw1 = (TimeUtils.nanoTime() - start) / 1000000000.0f; - start = System.nanoTime(); + start = TimeUtils.nanoTime(); spriteCache.end(); - end = (System.nanoTime() - start) / 1000000000.0f; + end = (TimeUtils.nanoTime() - start) / 1000000000.0f; - if (System.nanoTime() - startTime > 1000000000) { + if (TimeUtils.nanoTime() - startTime > 1000000000) { // Gdx.app.log( "SpriteBatch", "fps: " + frames + ", render calls: " + spriteBatch.renderCalls + ", " + begin + ", " + draw1 + // ", " + draw2 + ", " + drawText + ", " + end ); frames = 0; - startTime = System.nanoTime(); + startTime = TimeUtils.nanoTime(); } frames++; } @@ -117,13 +118,10 @@ public class SpriteCacheTest extends GdxTest implements InputProcessor { public void create () { spriteCache = new SpriteCache(1000, true); - Pixmap pixmap = new Pixmap(Gdx.files.internal("data/badlogicsmall.jpg")); - texture = new Texture(32, 32, Format.RGB565); + Texture texture = new Texture(Gdx.files.internal("data/badlogicsmall.jpg")); texture.setFilter(TextureFilter.Linear, TextureFilter.Linear); - texture.draw(pixmap, 0, 0); - pixmap.dispose(); - pixmap = new Pixmap(32, 32, Format.RGBA8888); + Pixmap pixmap = new Pixmap(32, 32, Format.RGBA8888); pixmap.setColor(1, 1, 0, 0.5f); pixmap.fill(); texture2 = new Texture(pixmap); diff --git a/tests/gdx-tests/src/com/badlogic/gdx/tests/SpritePerformanceTest.java b/tests/gdx-tests/src/com/badlogic/gdx/tests/SpritePerformanceTest.java index fe1d94785..9e06e9f04 100644 --- a/tests/gdx-tests/src/com/badlogic/gdx/tests/SpritePerformanceTest.java +++ b/tests/gdx-tests/src/com/badlogic/gdx/tests/SpritePerformanceTest.java @@ -25,6 +25,7 @@ import com.badlogic.gdx.graphics.g2d.Sprite; import com.badlogic.gdx.graphics.g2d.SpriteBatch; import com.badlogic.gdx.graphics.g2d.SpriteCache; import com.badlogic.gdx.tests.utils.GdxTest; +import com.badlogic.gdx.utils.TimeUtils; public class SpritePerformanceTest extends GdxTest { StringBuilder log = new StringBuilder(); @@ -70,7 +71,7 @@ public class SpritePerformanceTest extends GdxTest { } int spritesHandle = cache.endCache(); - startTime = System.nanoTime(); + startTime = TimeUtils.nanoTime(); frames = 0; } @@ -116,11 +117,11 @@ public class SpritePerformanceTest extends GdxTest { } frames++; - if (System.nanoTime() - startTime > 5000000000l) { + if (TimeUtils.nanoTime() - startTime > 5000000000l) { Gdx.app.log("SpritePerformanceTest", "mode: " + modes[mode] + ", fps: " + frames / 5.0f); log.append("mode: " + modes[mode] + ", fps: " + frames / 5.0f + "\n"); frames = 0; - startTime = System.nanoTime(); + startTime = TimeUtils.nanoTime(); mode++; if (mode > 9) mode = 0; } diff --git a/tests/gdx-tests/src/com/badlogic/gdx/tests/TerrainTest.java b/tests/gdx-tests/src/com/badlogic/gdx/tests/TerrainTest.java index 8f1f57302..3acd7c032 100644 --- a/tests/gdx-tests/src/com/badlogic/gdx/tests/TerrainTest.java +++ b/tests/gdx-tests/src/com/badlogic/gdx/tests/TerrainTest.java @@ -32,6 +32,7 @@ import com.badlogic.gdx.math.Intersector; import com.badlogic.gdx.math.Vector3; import com.badlogic.gdx.math.collision.Ray; import com.badlogic.gdx.tests.utils.GdxTest; +import com.badlogic.gdx.utils.TimeUtils; public class TerrainTest extends GdxTest { ImmediateModeRenderer10 renderer; @@ -40,7 +41,7 @@ public class TerrainTest extends GdxTest { PerspectiveCamera camera; Vector3 intersection = new Vector3(); boolean intersected = false; - long lastTime = System.nanoTime(); + long lastTime = TimeUtils.nanoTime(); @Override public void create () { @@ -88,9 +89,9 @@ public class TerrainTest extends GdxTest { handleInput(Gdx.input, Gdx.graphics.getDeltaTime()); - if (System.nanoTime() - lastTime > 1000000000) { + if (TimeUtils.nanoTime() - lastTime > 1000000000) { Gdx.app.log("TerrainTest", "fps: " + Gdx.graphics.getFramesPerSecond()); - lastTime = System.nanoTime(); + lastTime = TimeUtils.nanoTime(); } } diff --git a/tests/gdx-tests/src/com/badlogic/gdx/tests/TextureBindTestGL2.java b/tests/gdx-tests/src/com/badlogic/gdx/tests/TextureBindTestGL2.java deleted file mode 100644 index 9df386b6b..000000000 --- a/tests/gdx-tests/src/com/badlogic/gdx/tests/TextureBindTestGL2.java +++ /dev/null @@ -1,8 +0,0 @@ -package com.badlogic.gdx.tests; - -public class TextureBindTestGL2 extends TextureBindTest { - @Override - public boolean needsGL20() { - return true; - } -} diff --git a/tests/gdx-tests/src/com/badlogic/gdx/tests/TexturePackerAtlasTest.java b/tests/gdx-tests/src/com/badlogic/gdx/tests/TexturePackerAtlasTest.java deleted file mode 100644 index 1d76a3a46..000000000 --- a/tests/gdx-tests/src/com/badlogic/gdx/tests/TexturePackerAtlasTest.java +++ /dev/null @@ -1,21 +0,0 @@ -/******************************************************************************* - * Copyright 2011 See AUTHORS file. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - ******************************************************************************/ - -package com.badlogic.gdx.tests; - -public class TexturePackerAtlasTest { - -} diff --git a/tests/gdx-tests/src/com/badlogic/gdx/tests/VBOVATest.java b/tests/gdx-tests/src/com/badlogic/gdx/tests/VBOVATest.java index c0e20a1d9..26eb57f4e 100644 --- a/tests/gdx-tests/src/com/badlogic/gdx/tests/VBOVATest.java +++ b/tests/gdx-tests/src/com/badlogic/gdx/tests/VBOVATest.java @@ -28,6 +28,7 @@ import com.badlogic.gdx.graphics.glutils.VertexBufferObject; import com.badlogic.gdx.graphics.glutils.VertexBufferObjectSubData; import com.badlogic.gdx.graphics.glutils.VertexData; import com.badlogic.gdx.tests.utils.GdxTest; +import com.badlogic.gdx.utils.TimeUtils; public class VBOVATest extends GdxTest { @@ -83,7 +84,7 @@ public class VBOVATest extends GdxTest { indices[i] = (short)i; } - startTime = System.nanoTime(); + startTime = TimeUtils.nanoTime(); } @Override @@ -136,17 +137,17 @@ public class VBOVATest extends GdxTest { vertexBuffer.unbind(); } - long endTime = System.nanoTime(); + long endTime = TimeUtils.nanoTime(); if (endTime - startTime >= 4000000000l) { double secs = (endTime - startTime) / 1000000000.0; double fps = frames / secs; - Gdx.app.log("VBOVATest", vertexBuffer.getClass().getSimpleName() + ", " + isStatic + ", " + (mode > 2) + ", " + fps); + Gdx.app.log("VBOVATest", vertexBuffer.getClass().getName() + ", " + isStatic + ", " + (mode > 2) + ", " + fps); mode++; if (mode > 5) { mode = 0; isStatic = !isStatic; } - startTime = System.nanoTime(); + startTime = TimeUtils.nanoTime(); frames = 0; } diff --git a/tests/gdx-tests/src/com/badlogic/gdx/tests/VertexBufferObjectShaderTest.java b/tests/gdx-tests/src/com/badlogic/gdx/tests/VertexBufferObjectShaderTest.java index c12d8aa46..9b30cee9b 100644 --- a/tests/gdx-tests/src/com/badlogic/gdx/tests/VertexBufferObjectShaderTest.java +++ b/tests/gdx-tests/src/com/badlogic/gdx/tests/VertexBufferObjectShaderTest.java @@ -24,6 +24,7 @@ import com.badlogic.gdx.graphics.GL20; import com.badlogic.gdx.graphics.Texture; import com.badlogic.gdx.graphics.VertexAttribute; import com.badlogic.gdx.graphics.VertexAttributes; +import com.badlogic.gdx.graphics.glutils.IndexBufferObject; import com.badlogic.gdx.graphics.glutils.ShaderProgram; import com.badlogic.gdx.graphics.glutils.VertexBufferObject; import com.badlogic.gdx.tests.utils.GdxTest; @@ -33,7 +34,7 @@ public class VertexBufferObjectShaderTest extends GdxTest { Texture texture; ShaderProgram shader; VertexBufferObject vbo; - ShortBuffer indices; + IndexBufferObject indices; @Override public boolean needsGL20 () { @@ -51,6 +52,7 @@ public class VertexBufferObjectShaderTest extends GdxTest { public void render () { GL20 gl = Gdx.gl20; gl.glViewport(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); + Gdx.gl.glClearColor(0.7f, 0, 0, 1); gl.glClear(GL20.GL_COLOR_BUFFER_BIT); gl.glEnable(GL20.GL_TEXTURE_2D); @@ -58,7 +60,9 @@ public class VertexBufferObjectShaderTest extends GdxTest { shader.setUniformi("u_texture", 0); texture.bind(); vbo.bind(shader); - gl.glDrawElements(GL20.GL_TRIANGLES, 3, GL20.GL_UNSIGNED_SHORT, indices); + indices.bind(); + gl.glDrawElements(GL20.GL_TRIANGLES, 3, GL20.GL_UNSIGNED_SHORT, indices.getBuffer().position()); + indices.unbind(); vbo.unbind(shader); shader.end(); } @@ -81,9 +85,8 @@ public class VertexBufferObjectShaderTest extends GdxTest { float[] vertices = new float[] {-1, -1, 0, 0, Color.toFloatBits(1f, 0f, 0f, 1f), 0, 1, 0.5f, 1.0f, Color.toFloatBits(0f, 1f, 0f, 1f), 1, -1, 1, 0, Color.toFloatBits(0f, 0f, 1f, 1f)}; vbo.setVertices(vertices, 0, vertices.length); - indices = BufferUtils.newShortBuffer(3); - indices.put(new short[] {0, 1, 2}); - indices.flip(); + indices = new IndexBufferObject(3); + indices.setIndices(new short[] {0, 1, 2}, 0, 3); texture = new Texture(Gdx.files.internal("data/badlogic.jpg")); } @@ -93,4 +96,4 @@ public class VertexBufferObjectShaderTest extends GdxTest { vbo.invalidate(); } -} +} \ No newline at end of file diff --git a/tests/gdx-tests/src/com/badlogic/gdx/tests/WaterRipples.java b/tests/gdx-tests/src/com/badlogic/gdx/tests/WaterRipples.java index b149ab5c4..b2038c84e 100644 --- a/tests/gdx-tests/src/com/badlogic/gdx/tests/WaterRipples.java +++ b/tests/gdx-tests/src/com/badlogic/gdx/tests/WaterRipples.java @@ -33,6 +33,7 @@ import com.badlogic.gdx.math.Plane; import com.badlogic.gdx.math.Vector3; import com.badlogic.gdx.math.collision.Ray; import com.badlogic.gdx.tests.utils.GdxTest; +import com.badlogic.gdx.utils.TimeUtils; public class WaterRipples extends GdxTest implements InputProcessor { static final short WIDTH = 50; @@ -160,7 +161,7 @@ public class WaterRipples extends GdxTest implements InputProcessor { } } - long lastTick = System.nanoTime(); + long lastTick = TimeUtils.nanoTime(); Random rand = new Random(); @Override diff --git a/tests/gdx-tests/src/com/badlogic/gdx/tests/YDownTest.java b/tests/gdx-tests/src/com/badlogic/gdx/tests/YDownTest.java index 3ccc0e394..f9c99e962 100644 --- a/tests/gdx-tests/src/com/badlogic/gdx/tests/YDownTest.java +++ b/tests/gdx-tests/src/com/badlogic/gdx/tests/YDownTest.java @@ -34,7 +34,7 @@ public class YDownTest extends GdxTest { public void create () { // a bitmap font to draw some text, note that we // pass true to the constructor, which flips glyphs on y - font = new BitmapFont(true); + font = new BitmapFont(Gdx.files.internal("data/arial-15.fnt"), true); // a texture region, note the flipping on y again region = new TextureRegion(new Texture("data/badlogic.jpg")); diff --git a/tests/gdx-tests/src/com/badlogic/gdx/tests/utils/GdxTests.java b/tests/gdx-tests/src/com/badlogic/gdx/tests/utils/GdxTests.java index ed5dcbf1a..c569edb8a 100644 --- a/tests/gdx-tests/src/com/badlogic/gdx/tests/utils/GdxTests.java +++ b/tests/gdx-tests/src/com/badlogic/gdx/tests/utils/GdxTests.java @@ -79,7 +79,7 @@ public class GdxTests { PixmapTest.class, PreferencesTest.class, ProjectiveTextureTest.class, Pong.class, ProjectTest.class, RemoteTest.class, RotationTest.class, ShaderMultitextureTest.class, - ShadowMappingTest.class, SplineTest.class, SimpleTest.class, + ShadowMappingTest.class, SplineTest.class, SimpleAnimationTest.class, SimpleDecalTest.class, SimpleStageCullingTest.class, SoundTest.class, SpriteCacheTest.class, SpriteCacheOffsetTest.class, @@ -97,7 +97,7 @@ public class GdxTests { VorbisTest.class, WaterRipples.class, HelloTriangle.class, SimpleVertexShader.class, ShapeRendererTest.class, MoveSpriteExample.class, StbTrueTypeTest.class, SoundTouchTest.class, Mpg123Test.class, WavTest.class, - TextButtonTest.class, TextButtonTestGL2.class, TextureBindTest.class, TextureBindTestGL2.class, + TextButtonTest.class, TextButtonTestGL2.class, TextureBindTest.class, SortedSpriteTest.class, ExternalMusicTest.class, SoftKeyboardTest.class, DirtyRenderingTest.class, FreeTypeTest.class, YDownTest.class}; -- 2.11.0