From 2f412de0a867ffffe70909d9bb69434e3ac6b16b Mon Sep 17 00:00:00 2001
From: "nathan.sweet"
Date: Sun, 14 Aug 2011 01:40:36 +0000
Subject: [PATCH] [updated] Everything to use the latest source formatter. Yay!
Use it, love it!
---
.../backends/android/AndroidApplication.java | 537 ++--
.../AndroidApplicationConfiguration.java | 39 +-
.../gdx/backends/android/AndroidAudio.java | 52 +-
.../backends/android/AndroidAudioDevice.java | 27 +-
.../android/AndroidAudioRecorder.java | 14 +-
.../backends/android/AndroidFileHandle.java | 6 +-
.../gdx/backends/android/AndroidFiles.java | 28 +-
.../gdx/backends/android/AndroidGL10.java | 280 +-
.../gdx/backends/android/AndroidGL11.java | 155 +-
.../gdx/backends/android/AndroidGL20.java | 1 +
.../gdx/backends/android/AndroidGLU.java | 28 +-
.../gdx/backends/android/AndroidGraphics.java | 246 +-
.../gdx/backends/android/AndroidInput.java | 140 +-
.../android/AndroidMultiTouchHandler.java | 62 +-
.../gdx/backends/android/AndroidMusic.java | 35 +-
.../backends/android/AndroidPreferences.java | 89 +-
.../android/AndroidSingleTouchHandler.java | 16 +-
.../gdx/backends/android/AndroidSound.java | 9 +-
.../backends/android/AndroidTouchHandler.java | 5 +-
.../surfaceview/DefaultGLSurfaceView.java | 30 +-
.../surfaceview/FillResolutionStrategy.java | 23 +-
.../surfaceview/FixedResolutionStrategy.java | 28 +-
.../surfaceview/GLBaseSurfaceView.java | 227 +-
.../android/surfaceview/GLDebugHelper.java | 37 +-
.../android/surfaceview/GLErrorWrapper.java | 6 +-
.../android/surfaceview/GLException.java | 8 +-
.../android/surfaceview/GLLogWrapper.java | 19 +-
.../android/surfaceview/GLSurfaceView20.java | 419 ++-
.../surfaceview/GLSurfaceViewCupcake.java | 211 +-
.../android/surfaceview/GLWrapperBase.java | 4 +-
.../surfaceview/GdxEglConfigChooser.java | 77 +-
.../surfaceview/RatioResolutionStrategy.java | 58 +-
.../surfaceview/ResolutionStrategy.java | 35 +-
.../gdx/backends/jogl/JoglAnimator.java | 46 +-
.../gdx/backends/jogl/JoglApplication.java | 171 +-
.../jogl/JoglApplicationConfiguration.java | 43 +-
.../gdx/backends/jogl/JoglFileHandle.java | 6 +-
.../badlogic/gdx/backends/jogl/JoglFiles.java | 28 +-
.../badlogic/gdx/backends/jogl/JoglGL10.java | 280 +-
.../badlogic/gdx/backends/jogl/JoglGL11.java | 155 +-
.../badlogic/gdx/backends/jogl/JoglGL20.java | 455 ++-
.../badlogic/gdx/backends/jogl/JoglGLU.java | 18 +-
.../gdx/backends/jogl/JoglGraphics.java | 246 +-
.../gdx/backends/jogl/JoglGraphicsBase.java | 59 +-
.../badlogic/gdx/backends/jogl/JoglInput.java | 255 +-
.../gdx/backends/jogl/JoglNativesLoader.java | 7 +-
.../gdx/backends/jogl/JoglPreferences.java | 125 +-
.../gdx/backends/lwjgl/LwjglApplet.java | 16 +-
.../gdx/backends/lwjgl/LwjglApplication.java | 115 +-
.../lwjgl/LwjglApplicationConfiguration.java | 53 +-
.../gdx/backends/lwjgl/LwjglCanvas.java | 1 -
.../gdx/backends/lwjgl/LwjglFileHandle.java | 6 +-
.../gdx/backends/lwjgl/LwjglFiles.java | 28 +-
.../gdx/backends/lwjgl/LwjglFrame.java | 1 -
.../gdx/backends/lwjgl/LwjglGL10.java | 19 +-
.../gdx/backends/lwjgl/LwjglGL11.java | 8 +-
.../gdx/backends/lwjgl/LwjglGL20.java | 20 +-
.../badlogic/gdx/backends/lwjgl/LwjglGLU.java | 54 +-
.../gdx/backends/lwjgl/LwjglGraphics.java | 118 +-
.../gdx/backends/lwjgl/LwjglInput.java | 427 ++-
.../backends/lwjgl/LwjglNativesLoader.java | 8 +-
.../gdx/backends/lwjgl/LwjglPreferences.java | 125 +-
.../gdx/backends/angle/AngleApplication.java | 101 +-
.../gdx/backends/angle/AngleAudio.java | 20 +-
.../gdx/backends/angle/AngleAudioDevice.java | 11 +-
.../backends/angle/AngleAudioRecorder.java | 8 +-
.../gdx/backends/angle/AngleFileHandle.java | 6 +-
.../gdx/backends/angle/AngleFiles.java | 22 +-
.../gdx/backends/angle/AngleGLES0.java | 1 +
.../badlogic/gdx/backends/angle/AngleGLU.java | 56 +-
.../gdx/backends/angle/AngleGraphics.java | 96 +-
.../gdx/backends/angle/AngleInput.java | 359 ++-
.../gdx/backends/angle/AngleMusic.java | 28 +-
.../gdx/backends/angle/AnglePreferences.java | 127 +-
.../gdx/backends/angle/AngleSound.java | 16 +-
.../gdx/backends/angle/PNGDecoder.java | 12 +-
.../badlogic/gdx/backends/gwt/GdxGwtTest.java | 19 +-
.../gdx/backends/gwt/GwtApplication.java | 82 +-
.../gwt/GwtApplicationConfiguration.java | 5 +-
.../badlogic/gdx/backends/gwt/GwtGL20.java | 617 ++--
.../gdx/backends/gwt/GwtGraphics.java | 83 +-
.../badlogic/gdx/backends/gwt/PlainTest.java | 10 +-
.../com/badlogic/gdx/files/FileHandle.java | 1 +
.../emu/com/badlogic/gdx/graphics/Pixmap.java | 3 +-
.../com/badlogic/gdx/graphics/Texture.java | 3 +-
.../com/badlogic/gdx/utils/NumberUtils.java | 21 +-
.../gwt/corp/compatibility/Compatibility.java | 104 +-
.../corp/compatibility/CompatibilityImpl.java | 53 +-
.../compatibility/ConsolePrintStream.java | 53 +-
.../gwt/corp/compatibility/Endianness.java | 2 +-
.../gwt/corp/compatibility/Numbers.java | 163 +-
.../compatibility/StringToByteBuffer.java | 9 +-
.../gwt/emu/java/nio/BaseByteBuffer.java | 97 +-
.../gdx/backends/gwt/emu/java/nio/Buffer.java | 474 ++-
.../gwt/emu/java/nio/BufferFactory.java | 315 +-
.../emu/java/nio/BufferOverflowException.java | 25 +-
.../java/nio/BufferUnderflowException.java | 25 +-
.../backends/gwt/emu/java/nio/ByteBuffer.java | 1953 +++++-------
.../gwt/emu/java/nio/ByteBufferWrapper.java | 5 +-
.../backends/gwt/emu/java/nio/ByteOrder.java | 89 +-
.../gwt/emu/java/nio/CharArrayBuffer.java | 125 +-
.../backends/gwt/emu/java/nio/CharBuffer.java | 1423 ++++-----
.../gwt/emu/java/nio/CharSequenceAdapter.java | 247 +-
.../emu/java/nio/CharToByteBufferAdapter.java | 365 ++-
.../gwt/emu/java/nio/DirectByteBuffer.java | 421 ++-
.../java/nio/DirectReadOnlyByteBuffer.java | 247 +-
.../nio/DirectReadOnlyFloatBufferAdapter.java | 229 +-
.../nio/DirectReadOnlyIntBufferAdapter.java | 230 +-
.../nio/DirectReadOnlyShortBufferAdapter.java | 226 +-
.../java/nio/DirectReadWriteByteBuffer.java | 390 ++-
.../DirectReadWriteFloatBufferAdapter.java | 264 +-
.../nio/DirectReadWriteIntBufferAdapter.java | 260 +-
.../DirectReadWriteShortBufferAdapter.java | 265 +-
.../gwt/emu/java/nio/DoubleArrayBuffer.java | 103 +-
.../gwt/emu/java/nio/DoubleBuffer.java | 962 +++---
.../java/nio/DoubleToByteBufferAdapter.java | 343 +-
.../gwt/emu/java/nio/FloatArrayBuffer.java | 100 +-
.../gwt/emu/java/nio/FloatBuffer.java | 961 +++---
.../java/nio/FloatToByteBufferAdapter.java | 341 +-
.../gwt/emu/java/nio/HasArrayBufferView.java | 6 +-
.../gwt/emu/java/nio/HeapByteBuffer.java | 439 ++-
.../gwt/emu/java/nio/IntArrayBuffer.java | 101 +-
.../backends/gwt/emu/java/nio/IntBuffer.java | 946 +++---
.../emu/java/nio/IntToByteBufferAdapter.java | 346 +-
.../emu/java/nio/InvalidMarkException.java | 24 +-
.../gwt/emu/java/nio/LongArrayBuffer.java | 99 +-
.../backends/gwt/emu/java/nio/LongBuffer.java | 955 +++---
.../emu/java/nio/LongToByteBufferAdapter.java | 341 +-
.../emu/java/nio/ReadOnlyBufferException.java | 24 +-
.../emu/java/nio/ReadOnlyCharArrayBuffer.java | 145 +-
.../java/nio/ReadOnlyDoubleArrayBuffer.java | 134 +-
.../java/nio/ReadOnlyFloatArrayBuffer.java | 132 +-
.../emu/java/nio/ReadOnlyHeapByteBuffer.java | 217 +-
.../emu/java/nio/ReadOnlyIntArrayBuffer.java | 131 +-
.../emu/java/nio/ReadOnlyLongArrayBuffer.java | 131 +-
.../java/nio/ReadOnlyShortArrayBuffer.java | 132 +-
.../java/nio/ReadWriteCharArrayBuffer.java | 179 +-
.../java/nio/ReadWriteDoubleArrayBuffer.java | 186 +-
.../java/nio/ReadWriteFloatArrayBuffer.java | 186 +-
.../emu/java/nio/ReadWriteHeapByteBuffer.java | 344 +-
.../emu/java/nio/ReadWriteIntArrayBuffer.java | 180 +-
.../java/nio/ReadWriteLongArrayBuffer.java | 180 +-
.../java/nio/ReadWriteShortArrayBuffer.java | 185 +-
.../gwt/emu/java/nio/ShortArrayBuffer.java | 101 +-
.../gwt/emu/java/nio/ShortBuffer.java | 948 +++---
.../java/nio/ShortToByteBufferAdapter.java | 345 +-
.../gwt/emu/java/nio/StringByteBuffer.java | 391 +--
.../backends/openal/JavaSoundAudioDevice.java | 10 +-
.../openal/JavaSoundAudioRecorder.java | 5 +-
.../com/badlogic/gdx/backends/openal/Mp3.java | 11 +-
.../com/badlogic/gdx/backends/openal/Ogg.java | 5 +-
.../gdx/backends/openal/OggInputStream.java | 40 +-
.../gdx/backends/openal/OpenALAudio.java | 6 +-
.../gdx/backends/openal/OpenALSound.java | 7 +-
.../com/badlogic/gdx/backends/openal/Wav.java | 1 +
.../src/com/badlogic/cuboc/Cuboc.java | 23 +-
.../cuboc/src/com/badlogic/cubocy/Bob.java | 123 +-
.../cuboc/src/com/badlogic/cubocy/Cube.java | 173 +-
.../cuboc/src/com/badlogic/cubocy/Cubocy.java | 10 +-
.../src/com/badlogic/cubocy/Dispenser.java | 7 +-
.../src/com/badlogic/cubocy/EndDoor.java | 5 +-
.../cuboc/src/com/badlogic/cubocy/Laser.java | 146 +-
.../cuboc/src/com/badlogic/cubocy/Map.java | 70 +-
.../src/com/badlogic/cubocy/MapRenderer.java | 170 +-
.../src/com/badlogic/cubocy/MovingSpikes.java | 74 +-
.../cubocy/OnscreenControlRenderer.java | 41 +-
.../cuboc/src/com/badlogic/cubocy/Rocket.java | 61 +-
.../badlogic/cubocy/screens/CubocScreen.java | 26 +-
.../cubocy/screens/GameOverScreen.java | 22 +-
.../badlogic/cubocy/screens/GameScreen.java | 34 +-
.../badlogic/cubocy/screens/IntroScreen.java | 24 +-
.../com/badlogic/cubocy/screens/MainMenu.java | 24 +-
.../com/badlogic/gdx/HelloWorldAndroid.java | 5 +-
.../badlogic/gdx/helloworld/HelloWorld.java | 44 +-
.../gdx/helloworld/HelloWorldDesktop.java | 1 +
.../gdxinvaders/GdxInvadersAndroid.java | 7 +-
.../com/badlogic/gdxinvaders/GdxInvaders.java | 20 +-
.../gdxinvaders/GdxInvadersDesktop.java | 9 +-
.../com/badlogic/gdxinvaders/Renderer.java | 23 +-
.../gdxinvaders/screens/GameLoop.java | 18 +-
.../gdxinvaders/screens/GameOver.java | 25 +-
.../gdxinvaders/screens/MainMenu.java | 29 +-
.../badlogic/gdxinvaders/screens/Screen.java | 29 +-
.../com/badlogic/metagun/MetagunAndroid.java | 15 +-
.../src/com/mojang/metagun/Art.java | 50 +-
.../src/com/mojang/metagun/Input.java | 207 +-
.../src/com/mojang/metagun/Metagun.java | 45 +-
.../com/mojang/metagun/MetagunDesktop.java | 3 +-
.../src/com/mojang/metagun/Sound.java | 55 +-
.../src/com/mojang/metagun/Stats.java | 105 +-
.../src/com/mojang/metagun/entity/Boss.java | 157 +-
.../com/mojang/metagun/entity/BossNeck.java | 131 +-
.../com/mojang/metagun/entity/BossPart.java | 14 +-
.../src/com/mojang/metagun/entity/Bullet.java | 126 +-
.../src/com/mojang/metagun/entity/Entity.java | 175 +-
.../com/mojang/metagun/entity/Explosion.java | 95 +-
.../src/com/mojang/metagun/entity/Gore.java | 69 +-
.../com/mojang/metagun/entity/Gremlin.java | 201 +-
.../src/com/mojang/metagun/entity/Gunner.java | 295 +-
.../src/com/mojang/metagun/entity/Hat.java | 128 +-
.../com/mojang/metagun/entity/HeadGore.java | 91 +-
.../mojang/metagun/entity/Jabberwocky.java | 147 +-
.../src/com/mojang/metagun/entity/Player.java | 449 +--
.../com/mojang/metagun/entity/PlayerGore.java | 89 +-
.../src/com/mojang/metagun/entity/Sign.java | 73 +-
.../src/com/mojang/metagun/entity/Spark.java | 69 +-
.../src/com/mojang/metagun/level/Camera.java | 15 +-
.../src/com/mojang/metagun/level/Level.java | 21 +-
.../metagun/screen/ExpositionScreen.java | 99 +-
.../com/mojang/metagun/screen/GameScreen.java | 22 +-
.../metagun/screen/LevelTransitionScreen.java | 27 +-
.../mojang/metagun/screen/PauseScreen.java | 137 +-
.../src/com/mojang/metagun/screen/Screen.java | 2 +-
.../mojang/metagun/screen/SignReadScreen.java | 272 +-
.../mojang/metagun/screen/TitleScreen.java | 71 +-
.../com/mojang/metagun/screen/WinScreen.java | 121 +-
.../rtm-android/src/com/badlogic/rtm/Rtm.java | 4 +-
.../src/com/badlogic/rtm/LevelRenderer.java | 23 +-
.../rtm/src/com/badlogic/rtm/RtmDesktop.java | 1 +
.../superjumper/SuperJumperAndroid.java | 16 +-
.../badlogicgames/superjumper/Animation.java | 44 +-
.../com/badlogicgames/superjumper/Assets.java | 177 +-
.../com/badlogicgames/superjumper/Bob.java | 119 +-
.../com/badlogicgames/superjumper/Castle.java | 12 +-
.../com/badlogicgames/superjumper/Coin.java | 27 +-
.../superjumper/DynamicGameObject.java | 17 +-
.../com/badlogicgames/superjumper/Game.java | 29 +-
.../badlogicgames/superjumper/GameObject.java | 15 +-
.../badlogicgames/superjumper/GameScreen.java | 55 +-
.../badlogicgames/superjumper/HelpScreen.java | 127 +-
.../superjumper/HelpScreen2.java | 126 +-
.../superjumper/HelpScreen3.java | 126 +-
.../superjumper/HelpScreen4.java | 125 +-
.../superjumper/HelpScreen5.java | 126 +-
.../superjumper/HighscoresScreen.java | 24 +-
.../superjumper/MainMenuScreen.java | 22 +-
.../superjumper/OverlapTester.java | 36 +-
.../badlogicgames/superjumper/Platform.java | 95 +-
.../com/badlogicgames/superjumper/Screen.java | 25 +-
.../badlogicgames/superjumper/Settings.java | 96 +-
.../com/badlogicgames/superjumper/Spring.java | 14 +-
.../badlogicgames/superjumper/Squirrel.java | 53 +-
.../superjumper/SuperJumper.java | 28 +-
.../superjumper/SuperJumperDesktop.java | 3 +-
.../com/badlogicgames/superjumper/World.java | 414 ++-
.../superjumper/WorldRenderer.java | 14 +-
.../bouncy/BouncyAndroid.java | 4 +-
.../bouncy/BaseFieldDelegate.java | 33 +-
.../com/dozingcatsoftware/bouncy/Bouncy.java | 27 +-
.../com/dozingcatsoftware/bouncy/Field.java | 103 +-
.../dozingcatsoftware/bouncy/FieldLayout.java | 6 +-
.../bouncy/GLFieldRenderer.java | 9 +-
.../dozingcatsoftware/bouncy/GameMessage.java | 4 +-
.../bouncy/IFieldRenderer.java | 6 +-
.../bouncy/elements/Box2DFactory.java | 22 +-
.../bouncy/elements/BumperElement.java | 18 +-
.../elements/DropTargetGroupElement.java | 18 +-
.../bouncy/elements/FieldElement.java | 90 +-
.../bouncy/elements/FlipperElement.java | 21 +-
.../bouncy/elements/RolloverGroupElement.java | 38 +-
.../bouncy/elements/SensorElement.java | 22 +-
.../bouncy/elements/WallArcElement.java | 12 +-
.../bouncy/elements/WallElement.java | 22 +-
.../bouncy/elements/WallPathElement.java | 12 +-
.../bouncy/fields/Field1Delegate.java | 15 +-
.../bouncy/util/JSONArray.java | 1538 ++++-----
.../bouncy/util/JSONException.java | 33 +-
.../bouncy/util/JSONObject.java | 2811 ++++++++---------
.../bouncy/util/JSONString.java | 23 +-
.../bouncy/util/JSONStringer.java | 110 +-
.../bouncy/util/JSONTokener.java | 791 +++--
.../bouncy/util/JSONUtils.java | 26 +-
.../bouncy/util/JSONWriter.java | 508 ++-
.../android/VeryAngryRobotsActivity.java | 23 +-
.../badlydrawngames/general/CameraHelper.java | 62 +-
.../badlydrawngames/general/Colliders.java | 101 +-
.../general/CollisionGeometry.java | 28 +-
.../com/badlydrawngames/general/Config.java | 38 +-
.../badlydrawngames/general/GameScreen.java | 18 +-
.../src/com/badlydrawngames/general/Grid.java | 35 +-
.../badlydrawngames/general/MathUtils.java | 20 +-
.../com/badlydrawngames/general/Particle.java | 26 +-
.../general/ParticleManager.java | 16 +-
.../com/badlydrawngames/general/Pools.java | 35 +-
.../badlydrawngames/general/Rectangles.java | 18 +-
.../badlydrawngames/general/ScoreString.java | 41 +-
.../badlydrawngames/general/SimpleButton.java | 76 +-
.../veryangryrobots/AchievementsListener.java | 2 +-
.../veryangryrobots/AchievementsNotifier.java | 10 +-
.../veryangryrobots/Assets.java | 115 +-
.../veryangryrobots/DesktopStarter.java | 4 +-
.../veryangryrobots/DifficultyManager.java | 11 +-
.../veryangryrobots/Flyup.java | 11 +-
.../veryangryrobots/FlyupManager.java | 13 +-
.../veryangryrobots/IShowScores.java | 3 +-
.../veryangryrobots/ISubmitScores.java | 3 +-
.../veryangryrobots/MainMenuScreen.java | 61 +-
.../veryangryrobots/MazeGenerator.java | 103 +-
.../veryangryrobots/ParticleAdapter.java | 40 +-
.../veryangryrobots/RoomBuilder.java | 80 +-
.../ScoreBasedDifficultyManager.java | 64 +-
.../veryangryrobots/ScoreListener.java | 5 +-
.../veryangryrobots/ScoreNotifier.java | 14 +-
.../veryangryrobots/ScoresScreen.java | 43 +-
.../veryangryrobots/ScoringEventListener.java | 2 +-
.../veryangryrobots/ScoringEventNotifier.java | 13 +-
.../veryangryrobots/SoundManager.java | 54 +-
.../veryangryrobots/StatusManager.java | 143 +-
.../veryangryrobots/StatusView.java | 50 +-
.../veryangryrobots/VeryAngryRobotsGame.java | 30 +-
.../veryangryrobots/World.java | 303 +-
.../veryangryrobots/WorldListener.java | 32 +-
.../veryangryrobots/WorldNotifier.java | 34 +-
.../veryangryrobots/WorldPresenter.java | 84 +-
.../veryangryrobots/WorldView.java | 187 +-
.../veryangryrobots/mobiles/BaseShot.java | 12 +-
.../veryangryrobots/mobiles/Captain.java | 36 +-
.../veryangryrobots/mobiles/GameObject.java | 122 +-
.../veryangryrobots/mobiles/Player.java | 21 +-
.../veryangryrobots/mobiles/PlayerShot.java | 7 +-
.../veryangryrobots/mobiles/Robot.java | 101 +-
.../veryangryrobots/mobiles/RobotShot.java | 16 +-
eclipse-formatter.xml | 24 +-
.../badlogic/gdx/beans/AppletInitializer.java | 4 +-
.../gdx/beans/ArrayPersistenceDelegate.java | 187 +-
.../beans/AwtChoicePersistenceDelegate.java | 32 +-
.../beans/AwtColorPersistenceDelegate.java | 17 +-
.../AwtComponentPersistenceDelegate.java | 36 +-
.../AwtContainerPersistenceDelegate.java | 34 +-
.../beans/AwtCursorPersistenceDelegate.java | 15 +-
.../AwtDimensionPersistenceDelegate.java | 15 +-
.../gdx/beans/AwtFontPersistenceDelegate.java | 17 +-
...tFontTextAttributePersistenceDelegate.java | 6 +-
.../beans/AwtInsetsPersistenceDelegate.java | 17 +-
.../gdx/beans/AwtListPersistenceDelegate.java | 37 +-
.../beans/AwtMenuBarPersistenceDelegate.java | 38 +-
.../gdx/beans/AwtMenuPersistenceDelegate.java | 38 +-
.../AwtMenuShortcutPersistenceDelegate.java | 19 +-
.../beans/AwtPointPersistenceDelegate.java | 15 +-
.../AwtRectanglePersistenceDelegate.java | 36 +-
.../AwtScrollPanePersistenceDelegate.java | 17 +-
.../AwtSystemColorPersistenceDelegate.java | 6 +-
.../badlogic/gdx/beans/BeanDescriptor.java | 134 +-
.../src/com/badlogic/gdx/beans/BeanInfo.java | 24 +-
.../src/com/badlogic/gdx/beans/Beans.java | 749 ++---
.../gdx/beans/ClassPersistenceDelegate.java | 134 +-
.../beans/CustomizedObjectInputStream.java | 97 +-
.../com/badlogic/gdx/beans/Customizer.java | 8 +-
.../gdx/beans/DefaultPersistenceDelegate.java | 475 ++-
.../com/badlogic/gdx/beans/DesignMode.java | 6 +-
.../src/com/badlogic/gdx/beans/Encoder.java | 704 ++---
.../com/badlogic/gdx/beans/EventHandler.java | 630 ++--
.../gdx/beans/EventSetDescriptor.java | 768 +++--
.../badlogic/gdx/beans/ExceptionListener.java | 2 +-
.../com/badlogic/gdx/beans/Expression.java | 86 +-
.../badlogic/gdx/beans/FeatureDescriptor.java | 400 ++-
.../gdx/beans/FieldPersistenceDelegate.java | 58 +-
.../gdx/beans/IndexedPropertyChangeEvent.java | 66 +-
.../gdx/beans/IndexedPropertyDescriptor.java | 657 ++--
.../gdx/beans/IntrospectionException.java | 8 +-
.../com/badlogic/gdx/beans/Introspector.java | 552 ++--
.../badlogic/gdx/beans/MethodDescriptor.java | 139 +-
.../gdx/beans/MethodPersistenceDelegate.java | 58 +-
.../gdx/beans/NullPersistenceDelegate.java | 36 +-
.../gdx/beans/ParameterDescriptor.java | 8 +-
.../gdx/beans/PersistenceDelegate.java | 165 +-
.../PrimitiveWrapperPersistenceDelegate.java | 78 +-
.../gdx/beans/PropertyChangeEvent.java | 53 +-
.../gdx/beans/PropertyChangeListener.java | 4 +-
.../beans/PropertyChangeListenerProxy.java | 31 +-
.../gdx/beans/PropertyChangeSupport.java | 468 ++-
.../gdx/beans/PropertyDescriptor.java | 479 ++-
.../badlogic/gdx/beans/PropertyEditor.java | 26 +-
.../gdx/beans/PropertyEditorManager.java | 187 +-
.../gdx/beans/PropertyEditorSupport.java | 203 +-
.../gdx/beans/PropertyVetoException.java | 52 +-
.../gdx/beans/ProxyPersistenceDelegate.java | 50 +-
.../badlogic/gdx/beans/SimpleBeanInfo.java | 85 +-
.../badlogic/gdx/beans/StandardBeanInfo.java | 2767 ++++++++--------
.../src/com/badlogic/gdx/beans/Statement.java | 1090 +++----
.../beans/StaticFieldPersistenceDelegate.java | 20 +-
.../gdx/beans/StringPersistenceDelegate.java | 45 +-
...wingAbstractButtonPersistenceDelegate.java | 107 +-
.../beans/SwingBoxPersistenceDelegate.java | 39 +-
...faultComboBoxModelPersistenceDelegate.java | 36 +-
.../beans/SwingJFramePersistenceDelegate.java | 104 +-
.../SwingJTabbedPanePersistenceDelegate.java | 97 +-
...wingToolTipManagerPersistenceDelegate.java | 9 +-
.../UtilCollectionPersistenceDelegate.java | 92 +-
.../beans/UtilDatePersistenceDelegate.java | 15 +-
.../beans/UtilListPersistenceDelegate.java | 101 +-
.../gdx/beans/UtilMapPersistenceDelegate.java | 32 +-
.../gdx/beans/VetoableChangeListener.java | 6 +-
.../beans/VetoableChangeListenerProxy.java | 33 +-
.../gdx/beans/VetoableChangeSupport.java | 420 ++-
.../com/badlogic/gdx/beans/Visibility.java | 8 +-
.../com/badlogic/gdx/beans/XMLDecoder.java | 1214 ++++---
.../com/badlogic/gdx/beans/XMLEncoder.java | 1747 +++++-----
.../gdx/beans/beancontext/BeanContext.java | 32 +-
.../beans/beancontext/BeanContextChild.java | 17 +-
.../BeanContextChildComponentProxy.java | 2 +-
.../beancontext/BeanContextChildSupport.java | 310 +-
.../BeanContextContainerProxy.java | 2 +-
.../beans/beancontext/BeanContextEvent.java | 42 +-
.../BeanContextMembershipEvent.java | 62 +-
.../BeanContextMembershipListener.java | 6 +-
.../beans/beancontext/BeanContextProxy.java | 4 +-
.../BeanContextServiceAvailableEvent.java | 39 +-
.../BeanContextServiceProvider.java | 9 +-
.../BeanContextServiceProviderBeanInfo.java | 2 +-
.../BeanContextServiceRevokedEvent.java | 52 +-
.../BeanContextServiceRevokedListener.java | 4 +-
.../beancontext/BeanContextServices.java | 37 +-
.../BeanContextServicesListener.java | 8 +-
.../BeanContextServicesSupport.java | 1849 +++++------
.../beans/beancontext/BeanContextSupport.java | 2406 +++++++-------
.../org/apache/harmony/beans/Argument.java | 80 +-
.../org/apache/harmony/beans/BeansUtils.java | 189 +-
.../src/org/apache/harmony/beans/Command.java | 1630 +++++-----
.../src/org/apache/harmony/beans/Handler.java | 224 +-
.../harmony/beans/internal/nls/Messages.java | 280 +-
.../com/badlogic/gdx/remote/GdxRemote.java | 19 +-
.../com/badlogic/gdx/remote/UxAndroid.java | 62 +-
.../g3d/tests/ModelViewerActivity.java | 31 +-
.../graphics/g3d/AnimatedModelInstance.java | 9 +-
.../gdx/graphics/g3d/ModelLoaderHints.java | 14 +-
.../gdx/graphics/g3d/ModelRenderer.java | 12 +-
.../gdx/graphics/g3d/StillModelInstance.java | 9 +-
.../com/badlogic/gdx/graphics/g3d/Test.java | 28 +-
.../g3d/loaders/KeyframedModelLoader.java | 10 +-
.../gdx/graphics/g3d/loaders/ModelLoader.java | 15 +-
.../g3d/loaders/ModelLoaderRegistry.java | 415 +--
.../g3d/loaders/SkeletonModelLoader.java | 10 +-
.../g3d/loaders/StillModelLoader.java | 12 +-
.../g3d/loaders/collada/ColladaLoader.java | 61 +-
.../graphics/g3d/loaders/collada/Faces.java | 218 +-
.../g3d/loaders/collada/Geometry.java | 44 +-
.../graphics/g3d/loaders/collada/Source.java | 25 +-
.../g3d/loaders/g3d/G3dConstants.java | 8 +-
.../graphics/g3d/loaders/g3d/G3dLoader.java | 167 +-
.../graphics/g3d/loaders/g3d/G3dtLoader.java | 282 +-
.../g3d/loaders/g3d/chunks/ChunkReader.java | 333 +-
.../g3d/loaders/g3d/chunks/ChunkWriter.java | 161 +-
.../g3d/chunks/CountingDataInputStream.java | 54 +-
.../g3d/loaders/g3d/chunks/G3dExporter.java | 105 +-
.../graphics/g3d/loaders/md2/MD2Frame.java | 1 +
.../graphics/g3d/loaders/md2/MD2Header.java | 1 +
.../graphics/g3d/loaders/md2/MD2Loader.java | 48 +-
.../graphics/g3d/loaders/md2/MD2Triangle.java | 4 +-
.../g3d/loaders/ogre/OgreXmlLoader.java | 373 ++-
.../g3d/loaders/ogre/mesh/Animation.java | 123 +-
.../g3d/loaders/ogre/mesh/Animations.java | 62 +-
.../g3d/loaders/ogre/mesh/Binormal.java | 13 +-
.../loaders/ogre/mesh/Boneassignments.java | 62 +-
.../g3d/loaders/ogre/mesh/ColourDiffuse.java | 45 +-
.../g3d/loaders/ogre/mesh/ColourSpecular.java | 45 +-
.../g3d/loaders/ogre/mesh/Extremes.java | 62 +-
.../graphics/g3d/loaders/ogre/mesh/Face.java | 13 +-
.../graphics/g3d/loaders/ogre/mesh/Faces.java | 66 +-
.../g3d/loaders/ogre/mesh/Geometry.java | 66 +-
.../g3d/loaders/ogre/mesh/Keyframe.java | 158 +-
.../g3d/loaders/ogre/mesh/Keyframes.java | 60 +-
.../g3d/loaders/ogre/mesh/Levelofdetail.java | 201 +-
.../g3d/loaders/ogre/mesh/Lodfacelist.java | 140 +-
.../g3d/loaders/ogre/mesh/Lodgenerated.java | 123 +-
.../g3d/loaders/ogre/mesh/Lodmanual.java | 89 +-
.../graphics/g3d/loaders/ogre/mesh/Mesh.java | 376 +--
.../g3d/loaders/ogre/mesh/Normal.java | 13 +-
.../g3d/loaders/ogre/mesh/ObjectFactory.java | 539 ++--
.../graphics/g3d/loaders/ogre/mesh/Pose.java | 196 +-
.../g3d/loaders/ogre/mesh/Poseoffset.java | 333 +-
.../g3d/loaders/ogre/mesh/Poseref.java | 97 +-
.../graphics/g3d/loaders/ogre/mesh/Poses.java | 62 +-
.../g3d/loaders/ogre/mesh/Position.java | 13 +-
.../g3d/loaders/ogre/mesh/Sharedgeometry.java | 100 +-
.../g3d/loaders/ogre/mesh/Skeletonlink.java | 45 +-
.../g3d/loaders/ogre/mesh/Submesh.java | 274 +-
.../loaders/ogre/mesh/SubmeshExtremes.java | 100 +-
.../g3d/loaders/ogre/mesh/Submeshes.java | 62 +-
.../g3d/loaders/ogre/mesh/Submeshname.java | 89 +-
.../g3d/loaders/ogre/mesh/Submeshnames.java | 62 +-
.../g3d/loaders/ogre/mesh/Tangent.java | 17 +-
.../g3d/loaders/ogre/mesh/Texcoord.java | 17 +-
.../g3d/loaders/ogre/mesh/Texture.java | 89 +-
.../g3d/loaders/ogre/mesh/Textures.java | 62 +-
.../graphics/g3d/loaders/ogre/mesh/Track.java | 171 +-
.../g3d/loaders/ogre/mesh/Tracks.java | 62 +-
.../g3d/loaders/ogre/mesh/Vertex.java | 312 +-
.../ogre/mesh/Vertexboneassignment.java | 13 +-
.../g3d/loaders/ogre/mesh/Vertexbuffer.java | 471 ++-
.../g3d/loaders/ogre/skeleton/Animation.java | 55 +-
.../loaders/ogre/skeleton/Animationlink.java | 97 +-
.../loaders/ogre/skeleton/Animationlinks.java | 62 +-
.../g3d/loaders/ogre/skeleton/Animations.java | 62 +-
.../g3d/loaders/ogre/skeleton/Axis.java | 13 +-
.../g3d/loaders/ogre/skeleton/Bone.java | 29 +-
.../loaders/ogre/skeleton/Bonehierarchy.java | 60 +-
.../g3d/loaders/ogre/skeleton/Boneparent.java | 89 +-
.../g3d/loaders/ogre/skeleton/Bones.java | 62 +-
.../g3d/loaders/ogre/skeleton/Keyframe.java | 17 +-
.../g3d/loaders/ogre/skeleton/Keyframes.java | 62 +-
.../loaders/ogre/skeleton/ObjectFactory.java | 279 +-
.../g3d/loaders/ogre/skeleton/Position.java | 13 +-
.../g3d/loaders/ogre/skeleton/Rotate.java | 13 +-
.../g3d/loaders/ogre/skeleton/Rotation.java | 13 +-
.../g3d/loaders/ogre/skeleton/Scale.java | 17 +-
.../g3d/loaders/ogre/skeleton/Skeleton.java | 156 +-
.../g3d/loaders/ogre/skeleton/Track.java | 91 +-
.../g3d/loaders/ogre/skeleton/Tracks.java | 62 +-
.../g3d/loaders/ogre/skeleton/Translate.java | 13 +-
.../g3d/loaders/wavefront/ObjLoader.java | 107 +-
.../g3d/materials/ColorAttribute.java | 18 +-
.../gdx/graphics/g3d/materials/Material.java | 35 +-
.../g3d/materials/MaterialAttribute.java | 15 +-
.../g3d/materials/TextureAttribute.java | 23 +-
.../gdx/graphics/g3d/model/AnimatedModel.java | 9 +-
.../gdx/graphics/g3d/model/Animation.java | 7 +-
.../gdx/graphics/g3d/model/Model.java | 27 +-
.../gdx/graphics/g3d/model/SubMesh.java | 5 +-
.../graphics/g3d/model/keyframe/Keyframe.java | 9 +-
.../model/keyframe/KeyframedAnimation.java | 7 +-
.../g3d/model/keyframe/KeyframedModel.java | 151 +-
.../g3d/model/keyframe/KeyframedSubMesh.java | 15 +-
.../graphics/g3d/model/skeleton/Skeleton.java | 95 +-
.../g3d/model/skeleton/SkeletonAnimation.java | 7 +-
.../g3d/model/skeleton/SkeletonJoint.java | 13 +-
.../g3d/model/skeleton/SkeletonKeyframe.java | 14 +-
.../g3d/model/skeleton/SkeletonModel.java | 147 +-
.../g3d/model/skeleton/SkeletonSubMesh.java | 10 +-
.../graphics/g3d/model/still/StillModel.java | 41 +-
.../g3d/model/still/StillSubMesh.java | 8 +-
.../gdx/graphics/g3d/test/ChunkTest.java | 71 +-
.../g3d/test/KeyframedModelViewer.java | 138 +-
.../gdx/graphics/g3d/test/QbobViewer.java | 123 +-
.../g3d/test/SkeletonModelViewer.java | 126 +-
.../graphics/g3d/test/StillModelViewer.java | 170 +-
.../gdx/graphics/g3d/test/Viewer.java | 113 +-
.../graphics/g3d/test/WolfensteinTest.java | 72 +-
.../test/utils/PerspectiveCamController.java | 21 +-
.../gdx/tiledmappacker/TileSetLayout.java | 13 +-
.../gdx/tiledmappacker/TiledMapPacker.java | 48 +-
.../badlogic/gdx/twl/ButtonTestAndroid.java | 9 +-
.../com/badlogic/gdx/twl/NodeTestAndroid.java | 7 +-
.../badlogic/gdx/twl/TextAreaTestAndroid.java | 9 +-
.../com/badlogic/gdx/twl/TwlTestActivity.java | 47 +-
.../badlogic/gdx/twl/tests/ButtonTest.java | 25 +-
.../gdx/twl/tests/ButtonTestDesktop.java | 1 +
.../badlogic/gdx/twl/tests/TextAreaTest.java | 19 +-
.../gdx/twl/tests/TextAreaTestDesktop.java | 1 +
.../gdx/twl/tests/nodes/Connection.java | 74 +-
.../badlogic/gdx/twl/tests/nodes/Node.java | 99 +-
.../gdx/twl/tests/nodes/NodeArea.java | 312 +-
.../gdx/twl/tests/nodes/NodeTest.java | 79 +-
.../gdx/twl/tests/nodes/NodeTestDesktop.java | 7 +-
.../com/badlogic/gdx/twl/tests/nodes/Pad.java | 224 +-
.../src/com/badlogic/gdx/twl/Layout.java | 45 +-
.../gdx-twl/src/com/badlogic/gdx/twl/TWL.java | 39 +-
.../gdx/twl/renderer/GdxCacheContext.java | 5 +-
.../badlogic/gdx/twl/renderer/GdxFont.java | 23 +-
.../badlogic/gdx/twl/renderer/GdxImage.java | 6 +-
.../gdx/twl/renderer/GdxRenderer.java | 73 +-
.../badlogic/gdx/twl/renderer/GdxTexture.java | 38 +-
gdx/src/com/badlogic/gdx/Application.java | 119 +-
.../com/badlogic/gdx/ApplicationListener.java | 38 +-
gdx/src/com/badlogic/gdx/Audio.java | 32 +-
gdx/src/com/badlogic/gdx/Files.java | 69 +-
gdx/src/com/badlogic/gdx/Game.java | 32 +-
gdx/src/com/badlogic/gdx/Gdx.java | 12 +-
gdx/src/com/badlogic/gdx/Graphics.java | 352 +--
gdx/src/com/badlogic/gdx/Input.java | 363 +--
gdx/src/com/badlogic/gdx/InputAdapter.java | 14 +-
.../com/badlogic/gdx/InputMultiplexer.java | 13 +-
gdx/src/com/badlogic/gdx/InputProcessor.java | 56 +-
gdx/src/com/badlogic/gdx/Preferences.java | 84 +-
gdx/src/com/badlogic/gdx/Screen.java | 37 +-
gdx/src/com/badlogic/gdx/Version.java | 9 +-
.../badlogic/gdx/assets/AssetDescriptor.java | 18 +-
.../gdx/assets/AssetErrorListener.java | 3 +-
.../gdx/assets/AssetLoaderParameters.java | 1 +
.../badlogic/gdx/assets/AssetLoadingTask.java | 77 +-
.../com/badlogic/gdx/assets/AssetManager.java | 304 +-
.../gdx/assets/ReferenceCountedAsset.java | 6 +-
.../gdx/assets/loaders/AssetLoader.java | 13 +-
.../loaders/AsynchronousAssetLoader.java | 10 +-
.../gdx/assets/loaders/BitmapFontLoader.java | 10 +-
.../assets/loaders/BitmapFontParameter.java | 1 +
.../assets/loaders/FileHandleResolver.java | 3 +-
.../gdx/assets/loaders/MusicLoader.java | 1 +
.../gdx/assets/loaders/MusicParameter.java | 1 +
.../gdx/assets/loaders/PixmapLoader.java | 5 +-
.../gdx/assets/loaders/PixmapParameter.java | 1 +
.../gdx/assets/loaders/SoundLoader.java | 1 +
.../gdx/assets/loaders/SoundParameter.java | 1 +
.../loaders/SynchronousAssetLoader.java | 5 +-
.../assets/loaders/TextureAtlasLoader.java | 22 +-
.../assets/loaders/TextureAtlasParameter.java | 3 +-
.../gdx/assets/loaders/TextureLoader.java | 25 +-
.../gdx/assets/loaders/TextureParameter.java | 5 +-
.../resolvers/ExternalFileHandleResolver.java | 1 +
.../resolvers/InternalFileHandleResolver.java | 1 +
.../com/badlogic/gdx/audio/AudioDevice.java | 36 +-
.../com/badlogic/gdx/audio/AudioRecorder.java | 18 +-
gdx/src/com/badlogic/gdx/audio/Music.java | 52 +-
gdx/src/com/badlogic/gdx/audio/Sound.java | 26 +-
.../gdx/audio/analysis/AudioTools.java | 50 +-
.../com/badlogic/gdx/audio/analysis/DFT.java | 21 +-
.../com/badlogic/gdx/audio/analysis/FFT.java | 29 +-
.../gdx/audio/analysis/FourierTransform.java | 162 +-
.../badlogic/gdx/audio/analysis/KissFFT.java | 106 +-
.../gdx/audio/analysis/NativeFFT.java | 8 +-
.../gdx/audio/analysis/ThresholdFunction.java | 20 +-
.../com/badlogic/gdx/audio/io/Decoder.java | 36 +-
.../badlogic/gdx/audio/io/Mpg123Decoder.java | 47 +-
.../badlogic/gdx/audio/io/VorbisDecoder.java | 56 +-
.../com/badlogic/gdx/files/FileHandle.java | 126 +-
.../badlogic/gdx/files/FileHandleStream.java | 7 +-
gdx/src/com/badlogic/gdx/graphics/Camera.java | 224 +-
gdx/src/com/badlogic/gdx/graphics/Color.java | 126 +-
.../com/badlogic/gdx/graphics/FPSLogger.java | 26 +-
gdx/src/com/badlogic/gdx/graphics/GL10.java | 8 +-
gdx/src/com/badlogic/gdx/graphics/GL11.java | 8 +-
gdx/src/com/badlogic/gdx/graphics/GL20.java | 12 +-
.../com/badlogic/gdx/graphics/GLCommon.java | 8 +-
gdx/src/com/badlogic/gdx/graphics/GLU.java | 21 +-
gdx/src/com/badlogic/gdx/graphics/Mesh.java | 365 +--
.../gdx/graphics/OrthographicCamera.java | 19 +-
.../gdx/graphics/PerspectiveCamera.java | 31 +-
gdx/src/com/badlogic/gdx/graphics/Pixmap.java | 341 +-
.../com/badlogic/gdx/graphics/Texture.java | 303 +-
.../badlogic/gdx/graphics/TextureData.java | 45 +-
.../badlogic/gdx/graphics/TextureDict.java | 96 +-
.../com/badlogic/gdx/graphics/TextureRef.java | 76 +-
.../gdx/graphics/VertexAttribute.java | 14 +-
.../gdx/graphics/VertexAttributes.java | 35 +-
.../badlogic/gdx/graphics/g2d/Animation.java | 77 +-
.../badlogic/gdx/graphics/g2d/BitmapFont.java | 234 +-
.../gdx/graphics/g2d/BitmapFontCache.java | 122 +-
.../gdx/graphics/g2d/EmptyNinePatch.java | 4 +-
.../gdx/graphics/g2d/Gdx2DPixmap.java | 207 +-
.../badlogic/gdx/graphics/g2d/NinePatch.java | 107 +-
.../gdx/graphics/g2d/ParticleEffect.java | 12 +-
.../gdx/graphics/g2d/ParticleEmitter.java | 12 +-
.../com/badlogic/gdx/graphics/g2d/Sprite.java | 152 +-
.../gdx/graphics/g2d/SpriteBatch.java | 223 +-
.../gdx/graphics/g2d/SpriteCache.java | 211 +-
.../gdx/graphics/g2d/TextureAtlas.java | 203 +-
.../gdx/graphics/g2d/TextureRegion.java | 121 +-
.../graphics/g2d/tiled/SimpleTileAtlas.java | 91 +-
.../gdx/graphics/g2d/tiled/TileAtlas.java | 193 +-
.../graphics/g2d/tiled/TileMapRenderer.java | 305 +-
.../gdx/graphics/g2d/tiled/TileSet.java | 16 +-
.../gdx/graphics/g2d/tiled/TiledLayer.java | 23 +-
.../gdx/graphics/g2d/tiled/TiledLoader.java | 31 +-
.../gdx/graphics/g2d/tiled/TiledMap.java | 22 +-
.../gdx/graphics/g2d/tiled/TiledObject.java | 7 +-
.../graphics/g2d/tiled/TiledObjectGroup.java | 7 +-
.../badlogic/gdx/graphics/g3d/Animation.java | 12 +-
.../badlogic/gdx/graphics/g3d/Animator.java | 137 +-
.../badlogic/gdx/graphics/g3d/Material.java | 91 +-
.../g3d/decals/CameraGroupStrategy.java | 94 +-
.../gdx/graphics/g3d/decals/Decal.java | 535 ++--
.../gdx/graphics/g3d/decals/DecalBatch.java | 175 +-
.../graphics/g3d/decals/DecalMaterial.java | 37 +-
.../g3d/decals/DefaultGroupStrategy.java | 60 +-
.../gdx/graphics/g3d/decals/GroupPlug.java | 13 +-
.../graphics/g3d/decals/GroupStrategy.java | 85 +-
.../g3d/decals/PluggableGroupStrategy.java | 28 +-
.../g3d/decals/SimpleOrthoGroupStrategy.java | 60 +-
.../gdx/graphics/g3d/keyframed/Keyframe.java | 10 +-
.../g3d/keyframed/KeyframeAnimation.java | 26 +-
.../g3d/keyframed/KeyframeAnimator.java | 185 +-
.../g3d/keyframed/KeyframedModel.java | 328 +-
.../graphics/g3d/loaders/ModelLoaderOld.java | 14 +-
.../g3d/loaders/md5/MD5Animation.java | 36 +-
.../g3d/loaders/md5/MD5AnimationInfo.java | 1 +
.../graphics/g3d/loaders/md5/MD5Animator.java | 44 +-
.../gdx/graphics/g3d/loaders/md5/MD5Jni.java | 1 +
.../graphics/g3d/loaders/md5/MD5Joints.java | 23 +-
.../graphics/g3d/loaders/md5/MD5Loader.java | 232 +-
.../gdx/graphics/g3d/loaders/md5/MD5Mesh.java | 433 +--
.../graphics/g3d/loaders/md5/MD5Model.java | 30 +-
.../g3d/loaders/md5/MD5Quaternion.java | 21 +-
.../graphics/g3d/loaders/md5/MD5Renderer.java | 128 +-
.../graphics/g3d/loaders/obj/ObjLoader.java | 42 +-
.../badlogic/gdx/graphics/glutils/ETC1.java | 225 +-
.../gdx/graphics/glutils/ETC1TextureData.java | 23 +-
.../gdx/graphics/glutils/FileTextureData.java | 23 +-
.../gdx/graphics/glutils/FrameBuffer.java | 76 +-
.../glutils/ImmediateModeRenderer10.java | 60 +-
.../glutils/ImmediateModeRenderer20.java | 179 +-
.../graphics/glutils/IndexBufferObject.java | 56 +-
.../glutils/IndexBufferObjectSubData.java | 56 +-
.../gdx/graphics/glutils/IndexData.java | 44 +-
.../gdx/graphics/glutils/MipMapGenerator.java | 85 +-
.../graphics/glutils/PixmapTextureData.java | 13 +-
.../gdx/graphics/glutils/ShaderProgram.java | 365 +--
.../gdx/graphics/glutils/VertexArray.java | 80 +-
.../graphics/glutils/VertexBufferObject.java | 106 +-
.../glutils/VertexBufferObjectSubData.java | 89 +-
.../gdx/graphics/glutils/VertexData.java | 44 +-
.../com/badlogic/gdx/input/RemoteInput.java | 258 +-
.../com/badlogic/gdx/input/RemoteSender.java | 130 +-
.../badlogic/gdx/math/CatmullRomSpline.java | 58 +-
gdx/src/com/badlogic/gdx/math/Circle.java | 34 +-
.../gdx/math/EarClippingTriangulator.java | 197 +-
gdx/src/com/badlogic/gdx/math/Frustum.java | 167 +-
.../com/badlogic/gdx/math/Intersector.java | 196 +-
gdx/src/com/badlogic/gdx/math/MathUtils.java | 48 +-
gdx/src/com/badlogic/gdx/math/Matrix3.java | 111 +-
gdx/src/com/badlogic/gdx/math/Matrix4.java | 402 +--
gdx/src/com/badlogic/gdx/math/Plane.java | 85 +-
gdx/src/com/badlogic/gdx/math/Polygon.java | 97 +-
gdx/src/com/badlogic/gdx/math/Quaternion.java | 449 ++-
gdx/src/com/badlogic/gdx/math/Rectangle.java | 102 +-
gdx/src/com/badlogic/gdx/math/Vector2.java | 207 +-
gdx/src/com/badlogic/gdx/math/Vector3.java | 246 +-
.../com/badlogic/gdx/math/WindowedMean.java | 46 +-
.../gdx/math/collision/BoundingBox.java | 122 +-
.../com/badlogic/gdx/math/collision/Ray.java | 54 +-
.../badlogic/gdx/math/collision/Segment.java | 22 +-
.../badlogic/gdx/math/collision/Sphere.java | 26 +-
.../com/badlogic/gdx/physics/box2d/Body.java | 316 +-
.../badlogic/gdx/physics/box2d/BodyDef.java | 44 +-
.../gdx/physics/box2d/Box2DDebugRenderer.java | 5 +-
.../gdx/physics/box2d/CircleShape.java | 23 +-
.../badlogic/gdx/physics/box2d/Contact.java | 30 +-
.../gdx/physics/box2d/ContactFilter.java | 8 +-
.../gdx/physics/box2d/ContactImpulse.java | 27 +-
.../gdx/physics/box2d/ContactListener.java | 45 +-
.../physics/box2d/DestructionListener.java | 1 +
.../badlogic/gdx/physics/box2d/Filter.java | 22 +-
.../badlogic/gdx/physics/box2d/Fixture.java | 95 +-
.../gdx/physics/box2d/FixtureDef.java | 16 +-
.../com/badlogic/gdx/physics/box2d/Joint.java | 39 +-
.../badlogic/gdx/physics/box2d/JointDef.java | 1 +
.../badlogic/gdx/physics/box2d/JointEdge.java | 7 +-
.../badlogic/gdx/physics/box2d/Manifold.java | 79 +-
.../badlogic/gdx/physics/box2d/MassData.java | 8 +-
.../gdx/physics/box2d/PolygonShape.java | 44 +-
.../gdx/physics/box2d/QueryCallback.java | 11 +-
.../gdx/physics/box2d/RayCastCallback.java | 31 +-
.../com/badlogic/gdx/physics/box2d/Shape.java | 33 +-
.../badlogic/gdx/physics/box2d/Transform.java | 36 +-
.../com/badlogic/gdx/physics/box2d/World.java | 211 +-
.../gdx/physics/box2d/WorldManifold.java | 19 +-
.../physics/box2d/joints/DistanceJoint.java | 31 +-
.../box2d/joints/DistanceJointDef.java | 31 +-
.../physics/box2d/joints/FrictionJoint.java | 21 +-
.../box2d/joints/FrictionJointDef.java | 25 +-
.../gdx/physics/box2d/joints/GearJoint.java | 15 +-
.../physics/box2d/joints/GearJointDef.java | 21 +-
.../gdx/physics/box2d/joints/LineJoint.java | 63 +-
.../physics/box2d/joints/LineJointDef.java | 47 +-
.../gdx/physics/box2d/joints/MouseJoint.java | 39 +-
.../physics/box2d/joints/MouseJointDef.java | 23 +-
.../physics/box2d/joints/PrismaticJoint.java | 59 +-
.../box2d/joints/PrismaticJointDef.java | 51 +-
.../gdx/physics/box2d/joints/PulleyJoint.java | 27 +-
.../physics/box2d/joints/PulleyJointDef.java | 47 +-
.../physics/box2d/joints/RevoluteJoint.java | 61 +-
.../box2d/joints/RevoluteJointDef.java | 47 +-
.../gdx/physics/box2d/joints/WeldJoint.java | 7 +-
.../physics/box2d/joints/WeldJointDef.java | 1 +
.../badlogic/gdx/scenes/scene2d/Action.java | 65 +-
.../badlogic/gdx/scenes/scene2d/Actor.java | 69 +-
.../gdx/scenes/scene2d/AnimationAction.java | 24 +-
.../gdx/scenes/scene2d/CompositeAction.java | 13 +-
.../badlogic/gdx/scenes/scene2d/Group.java | 279 +-
.../gdx/scenes/scene2d/Interpolator.java | 25 +-
.../badlogic/gdx/scenes/scene2d/Layout.java | 3 +-
.../gdx/scenes/scene2d/OnActionCompleted.java | 24 +-
.../badlogic/gdx/scenes/scene2d/Stage.java | 255 +-
.../gdx/scenes/scene2d/TemporalAction.java | 13 +-
.../scene2d/actions/ActionResetingPool.java | 10 +-
.../gdx/scenes/scene2d/actions/Delay.java | 31 +-
.../gdx/scenes/scene2d/actions/FadeIn.java | 19 +-
.../gdx/scenes/scene2d/actions/FadeOut.java | 19 +-
.../gdx/scenes/scene2d/actions/FadeTo.java | 19 +-
.../gdx/scenes/scene2d/actions/Forever.java | 22 +-
.../gdx/scenes/scene2d/actions/MoveBy.java | 19 +-
.../gdx/scenes/scene2d/actions/MoveTo.java | 19 +-
.../gdx/scenes/scene2d/actions/Parallel.java | 34 +-
.../gdx/scenes/scene2d/actions/Remove.java | 31 +-
.../gdx/scenes/scene2d/actions/Repeat.java | 25 +-
.../gdx/scenes/scene2d/actions/RotateBy.java | 19 +-
.../gdx/scenes/scene2d/actions/RotateTo.java | 19 +-
.../gdx/scenes/scene2d/actions/ScaleTo.java | 19 +-
.../gdx/scenes/scene2d/actions/Sequence.java | 51 +-
.../gdx/scenes/scene2d/actors/BoundGroup.java | 8 +-
.../gdx/scenes/scene2d/actors/Button.java | 39 +-
.../gdx/scenes/scene2d/actors/FastImage.java | 49 +-
.../gdx/scenes/scene2d/actors/Image.java | 13 +-
.../gdx/scenes/scene2d/actors/Label.java | 16 +-
.../scenes/scene2d/actors/LinearGroup.java | 1 +
.../AccelerateDecelerateInterpolator.java | 28 +-
.../interpolators/AccelerateInterpolator.java | 28 +-
.../interpolators/AnticipateInterpolator.java | 28 +-
.../interpolators/DecelerateInterpolator.java | 28 +-
.../interpolators/LinearInterpolator.java | 25 +-
.../interpolators/OvershootInterpolator.java | 32 +-
.../gdx/scenes/scene2d/ui/Button.java | 165 +-
.../gdx/scenes/scene2d/ui/CheckBox.java | 171 +-
.../gdx/scenes/scene2d/ui/ComboBox.java | 275 +-
.../scenes/scene2d/ui/FlickScrollPane.java | 258 +-
.../gdx/scenes/scene2d/ui/ImageButton.java | 191 +-
.../scenes/scene2d/ui/ImageToggleButton.java | 203 +-
.../badlogic/gdx/scenes/scene2d/ui/Label.java | 84 +-
.../badlogic/gdx/scenes/scene2d/ui/List.java | 176 +-
.../badlogic/gdx/scenes/scene2d/ui/Pane.java | 95 +-
.../gdx/scenes/scene2d/ui/ScrollPane.java | 310 +-
.../badlogic/gdx/scenes/scene2d/ui/Skin.java | 1181 +++----
.../gdx/scenes/scene2d/ui/Slider.java | 188 +-
.../gdx/scenes/scene2d/ui/SplitPane.java | 304 +-
.../gdx/scenes/scene2d/ui/TextField.java | 288 +-
.../gdx/scenes/scene2d/ui/ToggleButton.java | 164 +-
.../gdx/scenes/scene2d/ui/Widget.java | 81 +-
.../gdx/scenes/scene2d/ui/Window.java | 201 +-
.../scenes/scene2d/ui/tablelayout/Cell.java | 2 +-
.../scenes/scene2d/ui/tablelayout/Table.java | 1 -
.../scene2d/ui/tablelayout/Toolkit.java | 2 +-
.../scene2d/ui/utils/AndroidClipboard.java | 9 +-
.../scenes/scene2d/ui/utils/Clipboard.java | 35 +-
.../scene2d/ui/utils/DesktopClipboard.java | 18 +-
.../scenes/scene2d/ui/utils/ScissorStack.java | 116 +-
gdx/src/com/badlogic/gdx/utils/Array.java | 82 +-
.../com/badlogic/gdx/utils/AtomicQueue.java | 6 +-
.../com/badlogic/gdx/utils/Base64Coder.java | 224 +-
.../com/badlogic/gdx/utils/BufferUtils.java | 277 +-
.../badlogic/gdx/utils/ComparableTimSort.java | 166 +-
.../com/badlogic/gdx/utils/Disposable.java | 14 +-
.../com/badlogic/gdx/utils/FloatArray.java | 51 +-
.../badlogic/gdx/utils/GdxNativesLoader.java | 15 +-
.../gdx/utils/GdxRuntimeException.java | 8 +-
.../com/badlogic/gdx/utils/IdentityMap.java | 72 +-
gdx/src/com/badlogic/gdx/utils/IntArray.java | 51 +-
gdx/src/com/badlogic/gdx/utils/IntMap.java | 73 +-
.../gdx/utils/LittleEndianInputStream.java | 178 +-
gdx/src/com/badlogic/gdx/utils/Logger.java | 26 +-
gdx/src/com/badlogic/gdx/utils/LongArray.java | 51 +-
gdx/src/com/badlogic/gdx/utils/LongMap.java | 72 +-
.../com/badlogic/gdx/utils/NumberUtils.java | 19 +-
gdx/src/com/badlogic/gdx/utils/ObjectMap.java | 72 +-
.../badlogic/gdx/utils/PauseableThread.java | 30 +-
gdx/src/com/badlogic/gdx/utils/Pool.java | 45 +-
.../badlogic/gdx/utils/PooledLinkedList.java | 72 +-
.../com/badlogic/gdx/utils/ScreenUtils.java | 104 +-
gdx/src/com/badlogic/gdx/utils/Sort.java | 10 +-
.../com/badlogic/gdx/utils/SortedIntList.java | 131 +-
gdx/src/com/badlogic/gdx/utils/TimSort.java | 155 +-
gdx/src/com/badlogic/gdx/utils/XmlWriter.java | 4 +-
.../gdx/tests/android/AndroidTestStarter.java | 10 +-
.../gdx/tests/android/GdxTestActivity.java | 1 +
.../gdx/tests/android/MatrixTest.java | 34 +-
.../gdx/tests/android/MicroBenchmarks.java | 7 +-
.../gdx/tests/android/WindowedTest.java | 28 +-
.../gdx/tests/angle/AngleDebugStarter.java | 1 +
.../gdx/tests/angle/AngleTestStarter.java | 7 +-
.../gdx/tests/jogl/JoglDebugStarter.java | 7 +-
.../gdx/tests/jogl/JoglTestStarter.java | 4 +-
.../gdx/tests/lwjgl/LocalLwjglTest.java | 97 +-
.../gdx/tests/lwjgl/LwjglAppletTest.java | 1 +
.../gdx/tests/lwjgl/LwjglDebugStarter.java | 18 +-
.../gdx/tests/lwjgl/LwjglTestStarter.java | 4 +-
.../badlogic/gdx/tests/AccelerometerTest.java | 23 +-
.../gdx/tests/ActionSequenceTest.java | 27 +-
.../com/badlogic/gdx/tests/ActionTest.java | 147 +-
.../src/com/badlogic/gdx/tests/AlphaTest.java | 13 +-
.../com/badlogic/gdx/tests/AnimationTest.java | 54 +-
.../badlogic/gdx/tests/AssetManagerTest.java | 42 +-
.../badlogic/gdx/tests/AtlasIssueTest.java | 7 +-
.../badlogic/gdx/tests/AudioDeviceTest.java | 13 +-
.../badlogic/gdx/tests/AudioRecorderTest.java | 19 +-
.../gdx/tests/BitmapFontAlignmentTest.java | 13 +-
.../gdx/tests/BitmapFontFlipTest.java | 14 +-
.../badlogic/gdx/tests/BitmapFontTest.java | 6 +-
.../src/com/badlogic/gdx/tests/BobTest.java | 9 +-
.../gdx/tests/Box2DInitialOverlapTest.java | 28 +-
.../src/com/badlogic/gdx/tests/Box2DTest.java | 124 +-
.../gdx/tests/Box2DTestCollection.java | 34 +-
.../badlogic/gdx/tests/BufferUtilsTest.java | 319 +-
.../com/badlogic/gdx/tests/CompassTest.java | 35 +-
.../badlogic/gdx/tests/ComplexActionTest.java | 35 +-
.../src/com/badlogic/gdx/tests/CullTest.java | 47 +-
.../src/com/badlogic/gdx/tests/DecalTest.java | 51 +-
.../com/badlogic/gdx/tests/DeltaTimeTest.java | 18 +-
.../src/com/badlogic/gdx/tests/ETC1Test.java | 37 +-
.../badlogic/gdx/tests/EdgeDetectionTest.java | 62 +-
.../src/com/badlogic/gdx/tests/ExitTest.java | 23 +-
.../src/com/badlogic/gdx/tests/FFTTest.java | 1 +
.../src/com/badlogic/gdx/tests/FilesTest.java | 9 +-
.../com/badlogic/gdx/tests/FillrateTest.java | 36 +-
.../gdx/tests/FilterPerformanceTest.java | 38 +-
.../gdx/tests/FlickScrollPaneTest.java | 1 -
.../src/com/badlogic/gdx/tests/FloatTest.java | 20 +-
.../badlogic/gdx/tests/FrameBufferTest.java | 12 +-
.../gdx/tests/FramebufferToTextureTest.java | 47 +-
.../com/badlogic/gdx/tests/FrustumTest.java | 93 +-
.../badlogic/gdx/tests/FullscreenTest.java | 48 +-
.../src/com/badlogic/gdx/tests/Gdx2DTest.java | 138 +-
.../com/badlogic/gdx/tests/GroupFadeTest.java | 24 +-
.../tests/ImmediateModeRendererAlphaTest.java | 125 +-
.../gdx/tests/ImmediateModeRendererTest.java | 16 +-
.../gdx/tests/IndexBufferObjectClassTest.java | 19 +-
.../tests/IndexBufferObjectShaderTest.java | 82 +-
.../src/com/badlogic/gdx/tests/InputTest.java | 85 +-
.../gdx/tests/IntegerBitmapFontTest.java | 24 +-
.../gdx/tests/InverseKinematicsTest.java | 103 +-
.../com/badlogic/gdx/tests/IsoCamTest.java | 74 +-
.../badlogic/gdx/tests/IsometricTileTest.java | 14 +-
.../badlogic/gdx/tests/KinematicBodyTest.java | 4 +-
.../com/badlogic/gdx/tests/LifeCycleTest.java | 34 +-
.../badlogic/gdx/tests/LineDrawingTest.java | 40 +-
.../src/com/badlogic/gdx/tests/MD5Test.java | 43 +-
.../com/badlogic/gdx/tests/ManagedTest.java | 14 +-
.../badlogic/gdx/tests/ManualBindTest.java | 10 +-
.../com/badlogic/gdx/tests/MatrixJNITest.java | 89 +-
.../gdx/tests/MeshMultitextureTest.java | 38 +-
.../badlogic/gdx/tests/MeshShaderTest.java | 75 +-
.../src/com/badlogic/gdx/tests/MeshTest.java | 12 +-
.../com/badlogic/gdx/tests/MipMapTest.java | 80 +-
.../com/badlogic/gdx/tests/Mpg123Test.java | 7 +-
.../gdx/tests/MultiTouchActorTest.java | 82 +-
.../badlogic/gdx/tests/MultitouchTest.java | 46 +-
.../src/com/badlogic/gdx/tests/MusicTest.java | 56 +-
.../badlogic/gdx/tests/MyFirstTriangle.java | 25 +-
.../src/com/badlogic/gdx/tests/ObjTest.java | 39 +-
.../src/com/badlogic/gdx/tests/OldUITest.java | 50 +-
.../gdx/tests/OnscreenKeyboardTest.java | 52 +-
.../gdx/tests/OrthoCamBorderTest.java | 6 +-
.../com/badlogic/gdx/tests/ParallaxTest.java | 76 +-
.../gdx/tests/ParticleEmitterTest.java | 12 +-
.../com/badlogic/gdx/tests/PickingTest.java | 60 +-
.../badlogic/gdx/tests/PixelsPerInchTest.java | 10 +-
.../gdx/tests/PixmapBlendingTest.java | 11 +-
.../com/badlogic/gdx/tests/PixmapTest.java | 76 +-
.../src/com/badlogic/gdx/tests/Pong.java | 37 +-
.../badlogic/gdx/tests/PreferencesTest.java | 20 +-
.../com/badlogic/gdx/tests/ProjectTest.java | 52 +-
.../gdx/tests/ProjectiveTextureTest.java | 112 +-
.../com/badlogic/gdx/tests/RemoteTest.java | 80 +-
.../com/badlogic/gdx/tests/RotationTest.java | 18 +-
.../badlogic/gdx/tests/ScreenCaptureTest.java | 113 +-
.../gdx/tests/ShaderMultitextureTest.java | 48 +-
.../badlogic/gdx/tests/ShadowMappingTest.java | 182 +-
.../gdx/tests/SimpleAnimationTest.java | 138 +-
.../badlogic/gdx/tests/SimpleDecalTest.java | 46 +-
.../gdx/tests/SimpleStageCullingTest.java | 104 +-
.../com/badlogic/gdx/tests/SimpleTest.java | 43 +-
.../src/com/badlogic/gdx/tests/SoundTest.java | 34 +-
.../com/badlogic/gdx/tests/SplineTest.java | 84 +-
.../gdx/tests/SpriteBatchRotationTest.java | 13 +-
.../gdx/tests/SpriteBatchShaderTest.java | 25 +-
.../badlogic/gdx/tests/SpriteBatchTest.java | 44 +-
.../gdx/tests/SpriteCacheOffsetTest.java | 10 +-
.../badlogic/gdx/tests/SpriteCacheTest.java | 38 +-
.../gdx/tests/SpritePerformanceTest.java | 5 +-
.../gdx/tests/SpritePerformanteTest2.java | 51 +-
.../gdx/tests/StagePerformanceTest.java | 71 +-
.../src/com/badlogic/gdx/tests/StageTest.java | 51 +-
.../com/badlogic/gdx/tests/TerrainTest.java | 14 +-
.../gdx/tests/TextInputDialogTest.java | 26 +-
.../badlogic/gdx/tests/TextureAtlasTest.java | 3 +-
.../badlogic/gdx/tests/TextureDataTest.java | 8 +-
.../gdx/tests/TextureDownloadTest.java | 35 +-
.../badlogic/gdx/tests/TextureFormatTest.java | 22 +-
.../gdx/tests/TexturePackerAtlasTest.java | 1 +
.../badlogic/gdx/tests/TextureRenderTest.java | 12 +-
.../src/com/badlogic/gdx/tests/TileTest.java | 12 +-
.../com/badlogic/gdx/tests/TiledMapTest.java | 38 +-
.../gdx/tests/TransformationTest.java | 74 +-
.../src/com/badlogic/gdx/tests/UITest.java | 90 +-
.../src/com/badlogic/gdx/tests/VBOVATest.java | 15 +-
.../gdx/tests/VertexArrayClassTest.java | 16 +-
.../badlogic/gdx/tests/VertexArrayTest.java | 10 +-
.../tests/VertexBufferObjectClassTest.java | 19 +-
.../tests/VertexBufferObjectShaderTest.java | 73 +-
.../gdx/tests/VertexBufferObjectTest.java | 10 +-
.../com/badlogic/gdx/tests/VibratorTest.java | 19 +-
.../com/badlogic/gdx/tests/VorbisTest.java | 7 +-
.../com/badlogic/gdx/tests/WaterRipples.java | 34 +-
.../badlogic/gdx/tests/box2d/ApplyForce.java | 5 +-
.../badlogic/gdx/tests/box2d/BodyTypes.java | 13 +-
.../badlogic/gdx/tests/box2d/Box2DTest.java | 77 +-
.../com/badlogic/gdx/tests/box2d/Bridge.java | 3 +-
.../badlogic/gdx/tests/box2d/Cantilever.java | 3 +-
.../com/badlogic/gdx/tests/box2d/Chain.java | 3 +-
.../gdx/tests/box2d/CharacterCollision.java | 3 +-
.../gdx/tests/box2d/CollisionFiltering.java | 3 +-
.../gdx/tests/box2d/ContinuousTest.java | 3 +-
.../gdx/tests/box2d/DebugRendererTest.java | 3 +-
.../gdx/tests/box2d/OneSidedPlatform.java | 6 +-
.../badlogic/gdx/tests/box2d/Prismatic.java | 11 +-
.../com/badlogic/gdx/tests/box2d/Pyramid.java | 3 +-
.../badlogic/gdx/tests/box2d/SimpleTest.java | 3 +-
.../badlogic/gdx/tests/box2d/SphereStack.java | 3 +-
.../gdx/tests/box2d/VaryingRestitution.java | 3 +-
.../gdx/tests/box2d/VerticalStack.java | 10 +-
.../gdx/tests/gles2/HelloTriangle.java | 37 +-
.../badlogic/gdx/tests/gles2/MipMap2D.java | 109 +-
.../com/badlogic/gdx/tests/gles2/Shapes.java | 158 +-
.../gdx/tests/gles2/SimpleVertexShader.java | 39 +-
.../com/badlogic/gdx/tests/utils/GdxTest.java | 29 +-
.../badlogic/gdx/tests/utils/GdxTests.java | 138 +-
.../gdx/tests/utils/OrthoCamController.java | 22 +-
.../tests/utils/PerspectiveCamController.java | 75 +-
1005 files changed, 48756 insertions(+), 57890 deletions(-)
diff --git a/backends/gdx-backend-android/src/com/badlogic/gdx/backends/android/AndroidApplication.java b/backends/gdx-backend-android/src/com/badlogic/gdx/backends/android/AndroidApplication.java
index 0c130c66b1a..447a9b3754b 100644
--- a/backends/gdx-backend-android/src/com/badlogic/gdx/backends/android/AndroidApplication.java
+++ b/backends/gdx-backend-android/src/com/badlogic/gdx/backends/android/AndroidApplication.java
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
+
package com.badlogic.gdx.backends.android;
import java.util.ArrayList;
@@ -47,303 +48,291 @@
import com.badlogic.gdx.graphics.GL11;
import com.badlogic.gdx.utils.GdxNativesLoader;
-/**
- * An implementation of the {@link Application} interface for Android. Create an {@link Activity} that derives from this class. In
+/** An implementation of the {@link Application} interface for Android. Create an {@link Activity} that derives from this class. In
* the {@link Activity#onCreate(Bundle)} method call the {@link #initialize(ApplicationListener, boolean)} method specifying the
* configuration for the GLSurfaceView.
- *
- * @author mzechner
- */
+ *
+ * @author mzechner */
public class AndroidApplication extends Activity implements Application {
- static {
- GdxNativesLoader.load();
- }
-
- protected AndroidGraphics graphics;
- protected AndroidInput input;
- protected AndroidAudio audio;
- protected AndroidFiles files;
- protected ApplicationListener listener;
- protected Handler handler;
- protected boolean firstResume = true;
- protected final List runnables = new ArrayList();
- protected WakeLock wakeLock = null;
- protected int logLevel = LOG_INFO;
-
- /**
- * This method has to be called in the {@link Activity#onCreate(Bundle)} method. It sets up all the things necessary to get
- * input, render via OpenGL and so on. If useGL20IfAvailable is set the AndroidApplication will try to create an OpenGL ES 2.0
- * context which can then be used via {@link Graphics#getGL20()}. The {@link GL10} and {@link GL11} interfaces should not be
- * used when OpenGL ES 2.0 is enabled. To query whether enabling OpenGL ES 2.0 was successful use the
- * {@link Graphics#isGL20Available()} method. Uses a default {@link AndroidApplicationConfiguration}.
- *
- * @param listener the {@link ApplicationListener} implementing the program logic
- * @param useGL2IfAvailable whether to use OpenGL ES 2.0 if its available.
- */
- public void initialize(ApplicationListener listener, boolean useGL2IfAvailable) {
- AndroidApplicationConfiguration config = new AndroidApplicationConfiguration();
- config.useGL20 = useGL2IfAvailable;
- initialize(listener, config);
- }
-
-
- /**
- * This method has to be called in the {@link Activity#onCreate(Bundle)} method. It sets up all the things necessary to get
- * input, render via OpenGL and so on. If config.useGL20 is set the AndroidApplication will try to create an OpenGL ES 2.0
- * context which can then be used via {@link Graphics#getGL20()}. The {@link GL10} and {@link GL11} interfaces should not be
- * used when OpenGL ES 2.0 is enabled. To query whether enabling OpenGL ES 2.0 was successful use the
- * {@link Graphics#isGL20Available()} method. You can configure other aspects of the application with the rest of the fields
- * in the {@link AndroidApplicationConfiguration} instance.
- *
- * @param listener the {@link ApplicationListener} implementing the program logic
- * @param config the {@link AndroidApplicationConfiguration}, defining various settings of the application (use accelerometer, etc.).
- */
- public void initialize(ApplicationListener listener, AndroidApplicationConfiguration config) {
- graphics = new AndroidGraphics(this, config, config.resolutionStrategy==null?new FillResolutionStrategy():config.resolutionStrategy);
- input = new AndroidInput(this, graphics.view, config);
- audio = new AndroidAudio(this);
- files = new AndroidFiles(this.getAssets());
- this.listener = listener;
- this.handler = new Handler();
-
- Gdx.app = this;
- Gdx.input = this.getInput();
- Gdx.audio = this.getAudio();
- Gdx.files = this.getFiles();
- Gdx.graphics = this.getGraphics();
-
- try {
- requestWindowFeature(Window.FEATURE_NO_TITLE);
- } catch(Exception ex) {
- log("AndroidApplication", "Content already displayed, cannot request FEATURE_NO_TITLE", ex);
- }
- getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
- getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
- setContentView(graphics.getView(), createLayoutParams());
- createWakeLock(config);
- }
-
- protected FrameLayout.LayoutParams createLayoutParams() {
- FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(android.view.ViewGroup.LayoutParams.FILL_PARENT, android.view.ViewGroup.LayoutParams.FILL_PARENT);
- layoutParams.gravity = Gravity.CENTER;
- return layoutParams;
- }
-
- protected void createWakeLock(AndroidApplicationConfiguration config) {
- if(config.useWakelock) {
- PowerManager powerManager = (PowerManager)getSystemService(Context.POWER_SERVICE);
- wakeLock = powerManager.newWakeLock(PowerManager.FULL_WAKE_LOCK, "libgdx wakelock");
- }
- }
-
- /**
- * This method has to be called in the {@link Activity#onCreate(Bundle)} method. It sets up all the things necessary to get
- * input, render via OpenGL and so on. If useGL20IfAvailable is set the AndroidApplication will try to create an OpenGL ES 2.0
- * context which can then be used via {@link Graphics#getGL20()}. The {@link GL10} and {@link GL11} interfaces should not be
- * used when OpenGL ES 2.0 is enabled. To query whether enabling OpenGL ES 2.0 was successful use the
- * {@link Graphics#isGL20Available()} method. Uses a default {@link AndroidApplicationConfiguration}.
- *
- * Note: you have to add the returned view to your layout!
- *
- * @param listener the {@link ApplicationListener} implementing the program logic
- * @param useGL2IfAvailable whether to use OpenGL ES 2.0 if its available.
- * @return the GLSurfaceView of the application
- */
- public View initializeForView(ApplicationListener listener, boolean useGL2IfAvailable) {
- AndroidApplicationConfiguration config = new AndroidApplicationConfiguration();
- config.useGL20 = useGL2IfAvailable;
- return initializeForView(listener, config);
- }
-
- /**
- * This method has to be called in the {@link Activity#onCreate(Bundle)} method. It sets up all the things necessary to get
- * input, render via OpenGL and so on. If config.useGL20 is set the AndroidApplication will try to create an OpenGL ES 2.0
- * context which can then be used via {@link Graphics#getGL20()}. The {@link GL10} and {@link GL11} interfaces should not be
- * used when OpenGL ES 2.0 is enabled. To query whether enabling OpenGL ES 2.0 was successful use the
- * {@link Graphics#isGL20Available()} method. You can configure other aspects of the application with the rest of the fields
- * in the {@link AndroidApplicationConfiguration} instance.
- *
- * Note: you have to add the returned view to your layout!
- *
- * @param listener the {@link ApplicationListener} implementing the program logic
- * @param config the {@link AndroidApplicationConfiguration}, defining various settings of the application (use accelerometer, etc.).
- * @return the GLSurfaceView of the application
- */
- public View initializeForView(ApplicationListener listener, AndroidApplicationConfiguration config) {
- graphics = new AndroidGraphics(this, config, config.resolutionStrategy==null?new FillResolutionStrategy():config.resolutionStrategy);
- input = new AndroidInput(this, graphics.view, config);
- audio = new AndroidAudio(this);
- files = new AndroidFiles(this.getAssets());
- this.listener = listener;
- this.handler = new Handler();
-
- Gdx.app = this;
- Gdx.input = this.getInput();
- Gdx.audio = this.getAudio();
- Gdx.files = this.getFiles();
- Gdx.graphics = this.getGraphics();
-
- createWakeLock(config);
- return graphics.getView();
- }
-
- @Override
- protected void onPause() {
- if(wakeLock != null) wakeLock.release();
- graphics.pause();
-
- input.unregisterSensorListeners();
- // erase pointer ids. this sucks donkeyballs...
- int[] realId = input.realId;
- for(int i = 0; i < realId.length; i++) realId[i] = -1;
-
- if (isFinishing()) {
- graphics.clearManagedCaches();
- graphics.destroy();
- }
-
- if (graphics != null && graphics.view != null) {
- if (graphics.view instanceof GLSurfaceViewCupcake) ((GLSurfaceViewCupcake) graphics.view).onPause();
- if (graphics.view instanceof android.opengl.GLSurfaceView)
- ((android.opengl.GLSurfaceView) graphics.view).onPause();
- }
-
- super.onPause();
- }
-
- @Override
- protected void onResume() {
- if(wakeLock != null) wakeLock.acquire();
- Gdx.app = this;
- Gdx.input = this.getInput();
- Gdx.audio = this.getAudio();
- Gdx.files = this.getFiles();
- Gdx.graphics = this.getGraphics();
-
- ((AndroidInput)getInput()).registerSensorListeners();
- if (audio != null) audio.resume();
-
- if (graphics != null && graphics.view != null) {
- if (graphics.view instanceof GLSurfaceViewCupcake) ((GLSurfaceViewCupcake) graphics.view).onResume();
- if (graphics.view instanceof android.opengl.GLSurfaceView)
- ((android.opengl.GLSurfaceView) graphics.view).onResume();
- }
-
- if (!firstResume)
- graphics.resume();
- else
- firstResume = false;
- super.onResume();
- }
-
- @Override
- protected void onDestroy() {
- super.onDestroy();
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public Audio getAudio() {
- return audio;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public Files getFiles() {
- return files;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public Graphics getGraphics() {
- return graphics;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public Input getInput() {
- return input;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public ApplicationType getType() {
- return ApplicationType.Android;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public int getVersion() {
- return Integer.parseInt(android.os.Build.VERSION.SDK);
- }
-
- @Override
- public long getJavaHeap() {
- return Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory();
- }
-
- @Override
- public long getNativeHeap() {
- return Debug.getNativeHeapAllocatedSize();
- }
-
- @Override public Preferences getPreferences (String name) {
+ static {
+ GdxNativesLoader.load();
+ }
+
+ protected AndroidGraphics graphics;
+ protected AndroidInput input;
+ protected AndroidAudio audio;
+ protected AndroidFiles files;
+ protected ApplicationListener listener;
+ protected Handler handler;
+ protected boolean firstResume = true;
+ protected final List runnables = new ArrayList();
+ protected WakeLock wakeLock = null;
+ protected int logLevel = LOG_INFO;
+
+ /** This method has to be called in the {@link Activity#onCreate(Bundle)} method. It sets up all the things necessary to get
+ * input, render via OpenGL and so on. If useGL20IfAvailable is set the AndroidApplication will try to create an OpenGL ES 2.0
+ * context which can then be used via {@link Graphics#getGL20()}. The {@link GL10} and {@link GL11} interfaces should not be
+ * used when OpenGL ES 2.0 is enabled. To query whether enabling OpenGL ES 2.0 was successful use the
+ * {@link Graphics#isGL20Available()} method. Uses a default {@link AndroidApplicationConfiguration}.
+ *
+ * @param listener the {@link ApplicationListener} implementing the program logic
+ * @param useGL2IfAvailable whether to use OpenGL ES 2.0 if its available. */
+ public void initialize (ApplicationListener listener, boolean useGL2IfAvailable) {
+ AndroidApplicationConfiguration config = new AndroidApplicationConfiguration();
+ config.useGL20 = useGL2IfAvailable;
+ initialize(listener, config);
+ }
+
+ /** This method has to be called in the {@link Activity#onCreate(Bundle)} method. It sets up all the things necessary to get
+ * input, render via OpenGL and so on. If config.useGL20 is set the AndroidApplication will try to create an OpenGL ES 2.0
+ * context which can then be used via {@link Graphics#getGL20()}. The {@link GL10} and {@link GL11} interfaces should not be
+ * used when OpenGL ES 2.0 is enabled. To query whether enabling OpenGL ES 2.0 was successful use the
+ * {@link Graphics#isGL20Available()} method. You can configure other aspects of the application with the rest of the fields in
+ * the {@link AndroidApplicationConfiguration} instance.
+ *
+ * @param listener the {@link ApplicationListener} implementing the program logic
+ * @param config the {@link AndroidApplicationConfiguration}, defining various settings of the application (use accelerometer,
+ * etc.). */
+ public void initialize (ApplicationListener listener, AndroidApplicationConfiguration config) {
+ graphics = new AndroidGraphics(this, config, config.resolutionStrategy == null ? new FillResolutionStrategy()
+ : config.resolutionStrategy);
+ input = new AndroidInput(this, graphics.view, config);
+ audio = new AndroidAudio(this);
+ files = new AndroidFiles(this.getAssets());
+ this.listener = listener;
+ this.handler = new Handler();
+
+ Gdx.app = this;
+ Gdx.input = this.getInput();
+ Gdx.audio = this.getAudio();
+ Gdx.files = this.getFiles();
+ Gdx.graphics = this.getGraphics();
+
+ try {
+ requestWindowFeature(Window.FEATURE_NO_TITLE);
+ } catch (Exception ex) {
+ log("AndroidApplication", "Content already displayed, cannot request FEATURE_NO_TITLE", ex);
+ }
+ getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
+ getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
+ setContentView(graphics.getView(), createLayoutParams());
+ createWakeLock(config);
+ }
+
+ protected FrameLayout.LayoutParams createLayoutParams () {
+ FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(android.view.ViewGroup.LayoutParams.FILL_PARENT,
+ android.view.ViewGroup.LayoutParams.FILL_PARENT);
+ layoutParams.gravity = Gravity.CENTER;
+ return layoutParams;
+ }
+
+ protected void createWakeLock (AndroidApplicationConfiguration config) {
+ if (config.useWakelock) {
+ PowerManager powerManager = (PowerManager)getSystemService(Context.POWER_SERVICE);
+ wakeLock = powerManager.newWakeLock(PowerManager.FULL_WAKE_LOCK, "libgdx wakelock");
+ }
+ }
+
+ /** This method has to be called in the {@link Activity#onCreate(Bundle)} method. It sets up all the things necessary to get
+ * input, render via OpenGL and so on. If useGL20IfAvailable is set the AndroidApplication will try to create an OpenGL ES 2.0
+ * context which can then be used via {@link Graphics#getGL20()}. The {@link GL10} and {@link GL11} interfaces should not be
+ * used when OpenGL ES 2.0 is enabled. To query whether enabling OpenGL ES 2.0 was successful use the
+ * {@link Graphics#isGL20Available()} method. Uses a default {@link AndroidApplicationConfiguration}.
+ *
+ * Note: you have to add the returned view to your layout!
+ *
+ * @param listener the {@link ApplicationListener} implementing the program logic
+ * @param useGL2IfAvailable whether to use OpenGL ES 2.0 if its available.
+ * @return the GLSurfaceView of the application */
+ public View initializeForView (ApplicationListener listener, boolean useGL2IfAvailable) {
+ AndroidApplicationConfiguration config = new AndroidApplicationConfiguration();
+ config.useGL20 = useGL2IfAvailable;
+ return initializeForView(listener, config);
+ }
+
+ /** This method has to be called in the {@link Activity#onCreate(Bundle)} method. It sets up all the things necessary to get
+ * input, render via OpenGL and so on. If config.useGL20 is set the AndroidApplication will try to create an OpenGL ES 2.0
+ * context which can then be used via {@link Graphics#getGL20()}. The {@link GL10} and {@link GL11} interfaces should not be
+ * used when OpenGL ES 2.0 is enabled. To query whether enabling OpenGL ES 2.0 was successful use the
+ * {@link Graphics#isGL20Available()} method. You can configure other aspects of the application with the rest of the fields in
+ * the {@link AndroidApplicationConfiguration} instance.
+ *
+ * Note: you have to add the returned view to your layout!
+ *
+ * @param listener the {@link ApplicationListener} implementing the program logic
+ * @param config the {@link AndroidApplicationConfiguration}, defining various settings of the application (use accelerometer,
+ * etc.).
+ * @return the GLSurfaceView of the application */
+ public View initializeForView (ApplicationListener listener, AndroidApplicationConfiguration config) {
+ graphics = new AndroidGraphics(this, config, config.resolutionStrategy == null ? new FillResolutionStrategy()
+ : config.resolutionStrategy);
+ input = new AndroidInput(this, graphics.view, config);
+ audio = new AndroidAudio(this);
+ files = new AndroidFiles(this.getAssets());
+ this.listener = listener;
+ this.handler = new Handler();
+
+ Gdx.app = this;
+ Gdx.input = this.getInput();
+ Gdx.audio = this.getAudio();
+ Gdx.files = this.getFiles();
+ Gdx.graphics = this.getGraphics();
+
+ createWakeLock(config);
+ return graphics.getView();
+ }
+
+ @Override
+ protected void onPause () {
+ if (wakeLock != null) wakeLock.release();
+ graphics.pause();
+
+ input.unregisterSensorListeners();
+ // erase pointer ids. this sucks donkeyballs...
+ int[] realId = input.realId;
+ for (int i = 0; i < realId.length; i++)
+ realId[i] = -1;
+
+ if (isFinishing()) {
+ graphics.clearManagedCaches();
+ graphics.destroy();
+ }
+
+ if (graphics != null && graphics.view != null) {
+ if (graphics.view instanceof GLSurfaceViewCupcake) ((GLSurfaceViewCupcake)graphics.view).onPause();
+ if (graphics.view instanceof android.opengl.GLSurfaceView) ((android.opengl.GLSurfaceView)graphics.view).onPause();
+ }
+
+ super.onPause();
+ }
+
+ @Override
+ protected void onResume () {
+ if (wakeLock != null) wakeLock.acquire();
+ Gdx.app = this;
+ Gdx.input = this.getInput();
+ Gdx.audio = this.getAudio();
+ Gdx.files = this.getFiles();
+ Gdx.graphics = this.getGraphics();
+
+ ((AndroidInput)getInput()).registerSensorListeners();
+ if (audio != null) audio.resume();
+
+ if (graphics != null && graphics.view != null) {
+ if (graphics.view instanceof GLSurfaceViewCupcake) ((GLSurfaceViewCupcake)graphics.view).onResume();
+ if (graphics.view instanceof android.opengl.GLSurfaceView) ((android.opengl.GLSurfaceView)graphics.view).onResume();
+ }
+
+ if (!firstResume)
+ graphics.resume();
+ else
+ firstResume = false;
+ super.onResume();
+ }
+
+ @Override
+ protected void onDestroy () {
+ super.onDestroy();
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public Audio getAudio () {
+ return audio;
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public Files getFiles () {
+ return files;
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public Graphics getGraphics () {
+ return graphics;
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public Input getInput () {
+ return input;
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public ApplicationType getType () {
+ return ApplicationType.Android;
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public int getVersion () {
+ return Integer.parseInt(android.os.Build.VERSION.SDK);
+ }
+
+ @Override
+ public long getJavaHeap () {
+ return Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory();
+ }
+
+ @Override
+ public long getNativeHeap () {
+ return Debug.getNativeHeapAllocatedSize();
+ }
+
+ @Override
+ public Preferences getPreferences (String name) {
return new AndroidPreferences(getSharedPreferences(name, Context.MODE_PRIVATE));
}
- @Override public void postRunnable (Runnable runnable) {
- synchronized(runnables) {
+ @Override
+ public void postRunnable (Runnable runnable) {
+ synchronized (runnables) {
runnables.add(runnable);
}
}
-
- @Override public void onConfigurationChanged(Configuration config) {
+
+ @Override
+ public void onConfigurationChanged (Configuration config) {
super.onConfigurationChanged(config);
boolean keyboardAvailable = false;
- if(config.keyboardHidden == Configuration.HARDKEYBOARDHIDDEN_NO) keyboardAvailable = true;
+ if (config.keyboardHidden == Configuration.HARDKEYBOARDHIDDEN_NO) keyboardAvailable = true;
input.keyboardAvailable = keyboardAvailable;
}
- @Override public void exit () {
+ @Override
+ public void exit () {
handler.post(new Runnable() {
- @Override public void run () {
- AndroidApplication.this.finish();
- }
+ @Override
+ public void run () {
+ AndroidApplication.this.finish();
+ }
});
}
-
- @Override
- public void log(String tag, String message) {
- if(logLevel >= LOG_INFO) Log.i(tag, message);
- }
-
- @Override public void log (String tag, String message, Exception exception) {
- if(logLevel >= LOG_INFO) Log.i(tag, message, exception);
- }
-
- @Override public void error (String tag, String message) {
- if(logLevel >= LOG_ERROR) Log.e(tag, message);
+
+ @Override
+ public void log (String tag, String message) {
+ if (logLevel >= LOG_INFO) Log.i(tag, message);
}
+ @Override
+ public void log (String tag, String message, Exception exception) {
+ if (logLevel >= LOG_INFO) Log.i(tag, message, exception);
+ }
- @Override public void error (String tag, String message, Exception exception) {
- if(logLevel >= LOG_ERROR) Log.e(tag, message, exception);
+ @Override
+ public void error (String tag, String message) {
+ if (logLevel >= LOG_ERROR) Log.e(tag, message);
}
+ @Override
+ public void error (String tag, String message, Exception exception) {
+ if (logLevel >= LOG_ERROR) Log.e(tag, message, exception);
+ }
- @Override public void setLogLevel (int logLevel) {
+ @Override
+ public void setLogLevel (int logLevel) {
this.logLevel = logLevel;
}
}
diff --git a/backends/gdx-backend-android/src/com/badlogic/gdx/backends/android/AndroidApplicationConfiguration.java b/backends/gdx-backend-android/src/com/badlogic/gdx/backends/android/AndroidApplicationConfiguration.java
index a7670c5d2b1..6dbe477ac23 100644
--- a/backends/gdx-backend-android/src/com/badlogic/gdx/backends/android/AndroidApplicationConfiguration.java
+++ b/backends/gdx-backend-android/src/com/badlogic/gdx/backends/android/AndroidApplicationConfiguration.java
@@ -1,3 +1,4 @@
+
package com.badlogic.gdx.backends.android;
import android.os.PowerManager.WakeLock;
@@ -5,40 +6,36 @@
import com.badlogic.gdx.backends.android.surfaceview.FillResolutionStrategy;
import com.badlogic.gdx.backends.android.surfaceview.ResolutionStrategy;
-/**
- * Class defining the configuration of an {@link AndroidApplication}. Allows you
- * to disable the use of the accelerometer to save battery among other things.
- * @author mzechner
- *
- */
+/** Class defining the configuration of an {@link AndroidApplication}. Allows you to disable the use of the accelerometer to save
+ * battery among other things.
+ * @author mzechner */
public class AndroidApplicationConfiguration {
/** whether to use OpenGL ES 2.0 or not. default: false **/
public boolean useGL20 = false;
-
+
/** number of bits per color channel **/
public int r = 5, g = 6, b = 5, a = 0;
-
+
/** number of bits for depth and stencil buffer **/
- public int depth = 16, stencil = 0;
-
+ public int depth = 16, stencil = 0;
+
/** number of samples for CSAA/MSAA, 2 is a good value **/
public int numSamples = 0;
-
+
/** whether to use the accelerometer. default: true **/
public boolean useAccelerometer = true;
-
+
/** whether to use the compass. default: true **/
- public boolean useCompass = true;
-
- /** the time in milliseconds to sleep after each event in the touch handler, set this
- * to 16ms to get rid of touch flooding on pre Android 2.0 devices. default: 0 **/
+ public boolean useCompass = true;
+
+ /** the time in milliseconds to sleep after each event in the touch handler, set this to 16ms to get rid of touch flooding on
+ * pre Android 2.0 devices. default: 0 **/
public int touchSleepTime = 0;
-
- /** whether to use a {@link WakeLock} or not. In case this is true you have to
- * add the permission "android.permission.WAKE_LOCK" to your manifest file. default: false
- */
+
+ /** whether to use a {@link WakeLock} or not. In case this is true you have to add the permission "android.permission.WAKE_LOCK"
+ * to your manifest file. default: false */
public boolean useWakelock = false;
-
+
/** the {@link ResolutionStrategy}. default: {@link FillResolutionStrategy} **/
public ResolutionStrategy resolutionStrategy = new FillResolutionStrategy();
}
diff --git a/backends/gdx-backend-android/src/com/badlogic/gdx/backends/android/AndroidAudio.java b/backends/gdx-backend-android/src/com/badlogic/gdx/backends/android/AndroidAudio.java
index 2d81bf7432a..4a1a9fcb2ab 100644
--- a/backends/gdx-backend-android/src/com/badlogic/gdx/backends/android/AndroidAudio.java
+++ b/backends/gdx-backend-android/src/com/badlogic/gdx/backends/android/AndroidAudio.java
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
+
package com.badlogic.gdx.backends.android;
import java.io.IOException;
@@ -35,12 +36,9 @@
import com.badlogic.gdx.files.FileHandle;
import com.badlogic.gdx.utils.GdxRuntimeException;
-/**
- * An implementation of the {@link Audio} interface for Android.
- *
- * @author mzechner
+/** An implementation of the {@link Audio} interface for Android.
*
- */
+ * @author mzechner */
public final class AndroidAudio implements Audio {
private SoundPool soundPool;
private final AudioManager manager;
@@ -54,7 +52,7 @@ public AndroidAudio (Activity context) {
}
protected void pause () {
- synchronized(musics) {
+ synchronized (musics) {
wasPlaying.clear();
for (AndroidMusic music : musics) {
if (music.isPlaying()) {
@@ -67,24 +65,22 @@ protected void pause () {
}
protected void resume () {
- synchronized(musics) {
+ synchronized (musics) {
for (int i = 0; i < musics.size(); i++) {
if (wasPlaying.get(i)) musics.get(i).play();
}
}
}
- /**
- * {@inheritDoc}
- */
- @Override public AudioDevice newAudioDevice (int samplingRate, boolean isMono) {
+ /** {@inheritDoc} */
+ @Override
+ public AudioDevice newAudioDevice (int samplingRate, boolean isMono) {
return new AndroidAudioDevice(samplingRate, isMono);
}
- /**
- * {@inheritDoc}
- */
- @Override public Music newMusic (FileHandle file) {
+ /** {@inheritDoc} */
+ @Override
+ public Music newMusic (FileHandle file) {
AndroidFileHandle aHandle = (AndroidFileHandle)file;
MediaPlayer mediaPlayer = new MediaPlayer();
@@ -96,7 +92,7 @@ protected void resume () {
descriptor.close();
mediaPlayer.prepare();
AndroidMusic music = new AndroidMusic(this, mediaPlayer);
- synchronized(musics) {
+ synchronized (musics) {
musics.add(music);
}
return music;
@@ -109,7 +105,7 @@ protected void resume () {
mediaPlayer.setDataSource(aHandle.path());
mediaPlayer.prepare();
AndroidMusic music = new AndroidMusic(this, mediaPlayer);
- synchronized(musics) {
+ synchronized (musics) {
musics.add(music);
}
return music;
@@ -120,10 +116,9 @@ protected void resume () {
}
- /**
- * {@inheritDoc}
- */
- @Override public Sound newSound (FileHandle file) {
+ /** {@inheritDoc} */
+ @Override
+ public Sound newSound (FileHandle file) {
AndroidFileHandle aHandle = (AndroidFileHandle)file;
if (aHandle.type() == FileType.Internal) {
try {
@@ -144,23 +139,20 @@ protected void resume () {
}
}
- /**
- * {@inheritDoc}
- */
- @Override public AudioRecorder newAudioRecoder (int samplingRate, boolean isMono) {
+ /** {@inheritDoc} */
+ @Override
+ public AudioRecorder newAudioRecoder (int samplingRate, boolean isMono) {
return new AndroidAudioRecorder(samplingRate, isMono);
}
- /**
- * Kills the soundpool and all other resources
- */
+ /** Kills the soundpool and all other resources */
public void dispose () {
- synchronized(musics) {
+ synchronized (musics) {
// gah i hate myself.... music.dispose() removes the music from the list...
ArrayList musicsCopy = new ArrayList(musics);
for (AndroidMusic music : musicsCopy) {
music.dispose();
- }
+ }
}
soundPool.release();
}
diff --git a/backends/gdx-backend-android/src/com/badlogic/gdx/backends/android/AndroidAudioDevice.java b/backends/gdx-backend-android/src/com/badlogic/gdx/backends/android/AndroidAudioDevice.java
index 0c0483f3b9b..aec6ea0a765 100644
--- a/backends/gdx-backend-android/src/com/badlogic/gdx/backends/android/AndroidAudioDevice.java
+++ b/backends/gdx-backend-android/src/com/badlogic/gdx/backends/android/AndroidAudioDevice.java
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
+
package com.badlogic.gdx.backends.android;
import android.media.AudioFormat;
@@ -21,12 +22,9 @@
import com.badlogic.gdx.audio.AudioDevice;
-/**
- * Implementation of the {@link AudioDevice} interface for Android using the AudioTrack class. You will need to set the permission
+/** Implementation of the {@link AudioDevice} interface for Android using the AudioTrack class. You will need to set the permission
* android.permission.RECORD_AUDIO in your manifest file.
- * @author mzechner
- *
- */
+ * @author mzechner */
class AndroidAudioDevice implements AudioDevice {
/** the audio track **/
private final AudioTrack track;
@@ -36,7 +34,7 @@ class AndroidAudioDevice implements AudioDevice {
/** whether this device is in mono or stereo mode **/
private final boolean isMono;
-
+
/** the latency in samples **/
private final int latency;
@@ -47,25 +45,29 @@ class AndroidAudioDevice implements AudioDevice {
track = new AudioTrack(AudioManager.STREAM_MUSIC, samplingRate, isMono ? AudioFormat.CHANNEL_CONFIGURATION_MONO
: AudioFormat.CHANNEL_CONFIGURATION_STEREO, AudioFormat.ENCODING_PCM_16BIT, minSize, AudioTrack.MODE_STREAM);
track.play();
- latency = minSize / (isMono?1:2);
+ latency = minSize / (isMono ? 1 : 2);
}
- @Override public void dispose () {
+ @Override
+ public void dispose () {
track.stop();
track.release();
}
- @Override public boolean isMono () {
+ @Override
+ public boolean isMono () {
return isMono;
}
- @Override public void writeSamples (short[] samples, int offset, int numSamples) {
+ @Override
+ public void writeSamples (short[] samples, int offset, int numSamples) {
int writtenSamples = track.write(samples, offset, numSamples);
while (writtenSamples != numSamples)
writtenSamples += track.write(samples, offset + writtenSamples, numSamples - writtenSamples);
}
- @Override public void writeSamples (float[] samples, int offset, int numSamples) {
+ @Override
+ public void writeSamples (float[] samples, int offset, int numSamples) {
if (buffer.length < samples.length) buffer = new short[samples.length];
int bound = offset + numSamples;
@@ -82,7 +84,8 @@ class AndroidAudioDevice implements AudioDevice {
writtenSamples += track.write(buffer, writtenSamples, numSamples - writtenSamples);
}
- @Override public int getLatency () {
+ @Override
+ public int getLatency () {
return latency;
}
}
diff --git a/backends/gdx-backend-android/src/com/badlogic/gdx/backends/android/AndroidAudioRecorder.java b/backends/gdx-backend-android/src/com/badlogic/gdx/backends/android/AndroidAudioRecorder.java
index 2ae89b0d4d9..0d1ab2a7f9d 100644
--- a/backends/gdx-backend-android/src/com/badlogic/gdx/backends/android/AndroidAudioRecorder.java
+++ b/backends/gdx-backend-android/src/com/badlogic/gdx/backends/android/AndroidAudioRecorder.java
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
+
package com.badlogic.gdx.backends.android;
import android.media.AudioFormat;
@@ -21,11 +22,8 @@
import com.badlogic.gdx.audio.AudioRecorder;
-/**
- * {@link AudioRecorder} implementation for the android system based on AudioRecord
- * @author badlogicgames@gmail.com
- *
- */
+/** {@link AudioRecorder} implementation for the android system based on AudioRecord
+ * @author badlogicgames@gmail.com */
public class AndroidAudioRecorder implements AudioRecorder {
/** the audio track we read samples from **/
private AudioRecord recorder;
@@ -38,12 +36,14 @@ public AndroidAudioRecorder (int samplingRate, boolean isMono) {
recorder.startRecording();
}
- @Override public void dispose () {
+ @Override
+ public void dispose () {
recorder.stop();
recorder.release();
}
- @Override public void read (short[] samples, int offset, int numSamples) {
+ @Override
+ public void read (short[] samples, int offset, int numSamples) {
int read = 0;
while (read != numSamples) {
read += recorder.read(samples, offset + read, numSamples - read);
diff --git a/backends/gdx-backend-android/src/com/badlogic/gdx/backends/android/AndroidFileHandle.java b/backends/gdx-backend-android/src/com/badlogic/gdx/backends/android/AndroidFileHandle.java
index 62d0421d045..c283ec1e7ea 100644
--- a/backends/gdx-backend-android/src/com/badlogic/gdx/backends/android/AndroidFileHandle.java
+++ b/backends/gdx-backend-android/src/com/badlogic/gdx/backends/android/AndroidFileHandle.java
@@ -26,10 +26,8 @@
import com.badlogic.gdx.files.FileHandle;
import com.badlogic.gdx.utils.GdxRuntimeException;
-/**
- * @author mzechner
- * @author Nathan Sweet
- */
+/** @author mzechner
+ * @author Nathan Sweet */
public class AndroidFileHandle extends FileHandle {
// The asset manager, or null if this is not an internal file.
final AssetManager assets;
diff --git a/backends/gdx-backend-android/src/com/badlogic/gdx/backends/android/AndroidFiles.java b/backends/gdx-backend-android/src/com/badlogic/gdx/backends/android/AndroidFiles.java
index 3d6b686a6ac..ec65cd20bc0 100644
--- a/backends/gdx-backend-android/src/com/badlogic/gdx/backends/android/AndroidFiles.java
+++ b/backends/gdx-backend-android/src/com/badlogic/gdx/backends/android/AndroidFiles.java
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
+
package com.badlogic.gdx.backends.android;
import android.content.res.AssetManager;
@@ -21,10 +22,8 @@
import com.badlogic.gdx.Files;
import com.badlogic.gdx.files.FileHandle;
-/**
- * @author mzechner
- * @author Nathan Sweet
- */
+/** @author mzechner
+ * @author Nathan Sweet */
public class AndroidFiles implements Files {
protected final String sdcard = Environment.getExternalStorageDirectory().getAbsolutePath() + "/";
protected final AssetManager assets;
@@ -33,31 +32,38 @@ public AndroidFiles (AssetManager assets) {
this.assets = assets;
}
- @Override public FileHandle getFileHandle (String path, FileType type) {
+ @Override
+ public FileHandle getFileHandle (String path, FileType type) {
return new AndroidFileHandle(type == FileType.Internal ? assets : null, path, type);
}
- @Override public FileHandle classpath (String path) {
+ @Override
+ public FileHandle classpath (String path) {
return new AndroidFileHandle(null, path, FileType.Classpath);
}
- @Override public FileHandle internal (String path) {
+ @Override
+ public FileHandle internal (String path) {
return new AndroidFileHandle(assets, path, FileType.Internal);
}
- @Override public FileHandle external (String path) {
+ @Override
+ public FileHandle external (String path) {
return new AndroidFileHandle(null, path, FileType.External);
}
- @Override public FileHandle absolute (String path) {
+ @Override
+ public FileHandle absolute (String path) {
return new AndroidFileHandle(null, path, FileType.Absolute);
}
- @Override public String getExternalStoragePath () {
+ @Override
+ public String getExternalStoragePath () {
return sdcard;
}
- @Override public boolean isExternalStorageAvailable () {
+ @Override
+ public boolean isExternalStorageAvailable () {
return Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED);
}
}
diff --git a/backends/gdx-backend-android/src/com/badlogic/gdx/backends/android/AndroidGL10.java b/backends/gdx-backend-android/src/com/badlogic/gdx/backends/android/AndroidGL10.java
index 963d3c0824c..7fbbcf6463c 100644
--- a/backends/gdx-backend-android/src/com/badlogic/gdx/backends/android/AndroidGL10.java
+++ b/backends/gdx-backend-android/src/com/badlogic/gdx/backends/android/AndroidGL10.java
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
+
package com.badlogic.gdx.backends.android;
import java.nio.Buffer;
@@ -21,11 +22,8 @@
import com.badlogic.gdx.graphics.GL10;
-/**
- * An implementation of the {@link GL10} interface for Android.
- * @author mzechner
- *
- */
+/** An implementation of the {@link GL10} interface for Android.
+ * @author mzechner */
class AndroidGL10 implements GL10 {
final javax.microedition.khronos.opengles.GL10 gl;
@@ -33,361 +31,447 @@ public AndroidGL10 (javax.microedition.khronos.opengles.GL10 gl) {
this.gl = gl;
}
- @Override public final void glActiveTexture (int texture) {
+ @Override
+ public final void glActiveTexture (int texture) {
gl.glActiveTexture(texture);
}
- @Override public final void glAlphaFunc (int func, float ref) {
+ @Override
+ public final void glAlphaFunc (int func, float ref) {
gl.glAlphaFunc(func, ref);
}
- @Override public final void glBindTexture (int target, int texture) {
+ @Override
+ public final void glBindTexture (int target, int texture) {
gl.glBindTexture(target, texture);
}
- @Override public final void glBlendFunc (int sfactor, int dfactor) {
+ @Override
+ public final void glBlendFunc (int sfactor, int dfactor) {
gl.glBlendFunc(sfactor, dfactor);
}
- @Override public final void glClear (int mask) {
+ @Override
+ public final void glClear (int mask) {
gl.glClear(mask);
}
- @Override public final void glClearColor (float red, float green, float blue, float alpha) {
+ @Override
+ public final void glClearColor (float red, float green, float blue, float alpha) {
gl.glClearColor(red, green, blue, alpha);
}
- @Override public final void glClearDepthf (float depth) {
+ @Override
+ public final void glClearDepthf (float depth) {
gl.glClearDepthf(depth);
}
- @Override public final void glClearStencil (int s) {
+ @Override
+ public final void glClearStencil (int s) {
gl.glClearStencil(s);
}
- @Override public final void glClientActiveTexture (int texture) {
+ @Override
+ public final void glClientActiveTexture (int texture) {
gl.glClientActiveTexture(texture);
}
- @Override public final void glColor4f (float red, float green, float blue, float alpha) {
+ @Override
+ public final void glColor4f (float red, float green, float blue, float alpha) {
gl.glColor4f(red, green, blue, alpha);
}
- @Override public final void glColorMask (boolean red, boolean green, boolean blue, boolean alpha) {
+ @Override
+ public final void glColorMask (boolean red, boolean green, boolean blue, boolean alpha) {
gl.glColorMask(red, green, blue, alpha);
}
- @Override public final void glColorPointer (int size, int type, int stride, Buffer pointer) {
+ @Override
+ public final void glColorPointer (int size, int type, int stride, Buffer pointer) {
gl.glColorPointer(size, type, stride, pointer);
}
- @Override public final void glCompressedTexImage2D (int target, int level, int internalformat, int width, int height,
- int border, int imageSize, Buffer data) {
+ @Override
+ public final void glCompressedTexImage2D (int target, int level, int internalformat, int width, int height, int border,
+ int imageSize, Buffer data) {
gl.glCompressedTexImage2D(target, level, internalformat, width, height, border, imageSize, data);
}
- @Override public final void glCompressedTexSubImage2D (int target, int level, int xoffset, int yoffset, int width, int height,
+ @Override
+ public final void glCompressedTexSubImage2D (int target, int level, int xoffset, int yoffset, int width, int height,
int format, int imageSize, Buffer data) {
gl.glCompressedTexSubImage2D(target, level, xoffset, yoffset, width, height, format, imageSize, data);
}
- @Override public final void glCopyTexImage2D (int target, int level, int internalformat, int x, int y, int width, int height,
- int border) {
+ @Override
+ public final void glCopyTexImage2D (int target, int level, int internalformat, int x, int y, int width, int height, int border) {
gl.glCopyTexImage2D(target, level, internalformat, x, y, width, height, border);
}
- @Override public final void glCopyTexSubImage2D (int target, int level, int xoffset, int yoffset, int x, int y, int width,
- int height) {
+ @Override
+ public final void glCopyTexSubImage2D (int target, int level, int xoffset, int yoffset, int x, int y, int width, int height) {
gl.glCopyTexSubImage2D(target, level, xoffset, yoffset, x, y, width, height);
}
- @Override public final void glCullFace (int mode) {
+ @Override
+ public final void glCullFace (int mode) {
gl.glCullFace(mode);
}
- @Override public final void glDeleteTextures (int n, IntBuffer textures) {
+ @Override
+ public final void glDeleteTextures (int n, IntBuffer textures) {
gl.glDeleteTextures(n, textures);
}
- @Override public final void glDepthFunc (int func) {
+ @Override
+ public final void glDepthFunc (int func) {
gl.glDepthFunc(func);
}
- @Override public final void glDepthMask (boolean flag) {
+ @Override
+ public final void glDepthMask (boolean flag) {
gl.glDepthMask(flag);
}
- @Override public final void glDepthRangef (float zNear, float zFar) {
+ @Override
+ public final void glDepthRangef (float zNear, float zFar) {
gl.glDepthRangef(zNear, zFar);
}
- @Override public final void glDisable (int cap) {
+ @Override
+ public final void glDisable (int cap) {
gl.glDisable(cap);
}
- @Override public final void glDisableClientState (int array) {
+ @Override
+ public final void glDisableClientState (int array) {
gl.glDisableClientState(array);
}
- @Override public final void glDrawArrays (int mode, int first, int count) {
+ @Override
+ public final void glDrawArrays (int mode, int first, int count) {
gl.glDrawArrays(mode, first, count);
}
- @Override public final void glDrawElements (int mode, int count, int type, Buffer indices) {
+ @Override
+ public final void glDrawElements (int mode, int count, int type, Buffer indices) {
gl.glDrawElements(mode, count, type, indices);
}
- @Override public final void glEnable (int cap) {
+ @Override
+ public final void glEnable (int cap) {
gl.glEnable(cap);
}
- @Override public final void glEnableClientState (int array) {
+ @Override
+ public final void glEnableClientState (int array) {
gl.glEnableClientState(array);
}
- @Override public final void glFinish () {
+ @Override
+ public final void glFinish () {
gl.glFinish();
}
- @Override public final void glFlush () {
+ @Override
+ public final void glFlush () {
gl.glFlush();
}
- @Override public final void glFogf (int pname, float param) {
+ @Override
+ public final void glFogf (int pname, float param) {
gl.glFogf(pname, param);
}
- @Override public final void glFogfv (int pname, FloatBuffer params) {
+ @Override
+ public final void glFogfv (int pname, FloatBuffer params) {
gl.glFogfv(pname, params);
}
- @Override public final void glFrontFace (int mode) {
+ @Override
+ public final void glFrontFace (int mode) {
gl.glFrontFace(mode);
}
- @Override public final void glFrustumf (float left, float right, float bottom, float top, float zNear, float zFar) {
+ @Override
+ public final void glFrustumf (float left, float right, float bottom, float top, float zNear, float zFar) {
gl.glFrustumf(left, right, bottom, top, zNear, zFar);
}
- @Override public final void glGenTextures (int n, IntBuffer textures) {
+ @Override
+ public final void glGenTextures (int n, IntBuffer textures) {
gl.glGenTextures(n, textures);
}
- @Override public final int glGetError () {
+ @Override
+ public final int glGetError () {
return gl.glGetError();
}
- @Override public final void glGetIntegerv (int pname, IntBuffer params) {
+ @Override
+ public final void glGetIntegerv (int pname, IntBuffer params) {
gl.glGetIntegerv(pname, params);
}
- @Override public final String glGetString (int name) {
+ @Override
+ public final String glGetString (int name) {
return gl.glGetString(name);
}
- @Override public final void glHint (int target, int mode) {
+ @Override
+ public final void glHint (int target, int mode) {
gl.glHint(target, mode);
}
- @Override public final void glLightModelf (int pname, float param) {
+ @Override
+ public final void glLightModelf (int pname, float param) {
gl.glLightModelf(pname, param);
}
- @Override public final void glLightModelfv (int pname, FloatBuffer params) {
+ @Override
+ public final void glLightModelfv (int pname, FloatBuffer params) {
gl.glLightModelfv(pname, params);
}
- @Override public final void glLightf (int light, int pname, float param) {
+ @Override
+ public final void glLightf (int light, int pname, float param) {
gl.glLightf(light, pname, param);
}
- @Override public final void glLightfv (int light, int pname, FloatBuffer params) {
+ @Override
+ public final void glLightfv (int light, int pname, FloatBuffer params) {
gl.glLightfv(light, pname, params);
}
- @Override public final void glLineWidth (float width) {
+ @Override
+ public final void glLineWidth (float width) {
gl.glLineWidth(width);
}
- @Override public final void glLoadIdentity () {
+ @Override
+ public final void glLoadIdentity () {
gl.glLoadIdentity();
}
- @Override public final void glLoadMatrixf (FloatBuffer m) {
+ @Override
+ public final void glLoadMatrixf (FloatBuffer m) {
gl.glLoadMatrixf(m);
}
- @Override public final void glLogicOp (int opcode) {
+ @Override
+ public final void glLogicOp (int opcode) {
gl.glLogicOp(opcode);
}
- @Override public final void glMaterialf (int face, int pname, float param) {
+ @Override
+ public final void glMaterialf (int face, int pname, float param) {
gl.glMaterialf(face, pname, param);
}
- @Override public final void glMaterialfv (int face, int pname, FloatBuffer params) {
+ @Override
+ public final void glMaterialfv (int face, int pname, FloatBuffer params) {
gl.glMaterialfv(face, pname, params);
}
- @Override public final void glMatrixMode (int mode) {
+ @Override
+ public final void glMatrixMode (int mode) {
gl.glMatrixMode(mode);
}
- @Override public final void glMultMatrixf (FloatBuffer m) {
+ @Override
+ public final void glMultMatrixf (FloatBuffer m) {
gl.glMultMatrixf(m);
}
- @Override public final void glMultiTexCoord4f (int target, float s, float t, float r, float q) {
+ @Override
+ public final void glMultiTexCoord4f (int target, float s, float t, float r, float q) {
gl.glMultiTexCoord4f(target, s, t, r, q);
}
- @Override public final void glNormal3f (float nx, float ny, float nz) {
+ @Override
+ public final void glNormal3f (float nx, float ny, float nz) {
gl.glNormal3f(nx, ny, nz);
}
- @Override public final void glNormalPointer (int type, int stride, Buffer pointer) {
+ @Override
+ public final void glNormalPointer (int type, int stride, Buffer pointer) {
gl.glNormalPointer(type, stride, pointer);
}
- @Override public final void glOrthof (float left, float right, float bottom, float top, float zNear, float zFar) {
+ @Override
+ public final void glOrthof (float left, float right, float bottom, float top, float zNear, float zFar) {
gl.glOrthof(left, right, bottom, top, zNear, zFar);
}
- @Override public final void glPixelStorei (int pname, int param) {
+ @Override
+ public final void glPixelStorei (int pname, int param) {
gl.glPixelStorei(pname, param);
}
- @Override public final void glPointSize (float size) {
+ @Override
+ public final void glPointSize (float size) {
gl.glPointSize(size);
}
- @Override public final void glPolygonOffset (float factor, float units) {
+ @Override
+ public final void glPolygonOffset (float factor, float units) {
gl.glPolygonOffset(factor, units);
}
- @Override public final void glPopMatrix () {
+ @Override
+ public final void glPopMatrix () {
gl.glPopMatrix();
}
- @Override public final void glPushMatrix () {
+ @Override
+ public final void glPushMatrix () {
gl.glPushMatrix();
}
- @Override public final void glReadPixels (int x, int y, int width, int height, int format, int type, Buffer pixels) {
+ @Override
+ public final void glReadPixels (int x, int y, int width, int height, int format, int type, Buffer pixels) {
gl.glReadPixels(x, y, width, height, format, type, pixels);
}
- @Override public final void glRotatef (float angle, float x, float y, float z) {
+ @Override
+ public final void glRotatef (float angle, float x, float y, float z) {
gl.glRotatef(angle, x, y, z);
}
- @Override public final void glSampleCoverage (float value, boolean invert) {
+ @Override
+ public final void glSampleCoverage (float value, boolean invert) {
gl.glSampleCoverage(value, invert);
}
- @Override public final void glScalef (float x, float y, float z) {
+ @Override
+ public final void glScalef (float x, float y, float z) {
gl.glScalef(x, y, z);
}
- @Override public final void glScissor (int x, int y, int width, int height) {
+ @Override
+ public final void glScissor (int x, int y, int width, int height) {
gl.glScissor(x, y, width, height);
}
- @Override public final void glShadeModel (int mode) {
+ @Override
+ public final void glShadeModel (int mode) {
gl.glShadeModel(mode);
}
- @Override public final void glStencilFunc (int func, int ref, int mask) {
+ @Override
+ public final void glStencilFunc (int func, int ref, int mask) {
gl.glStencilFunc(func, ref, mask);
}
- @Override public final void glStencilMask (int mask) {
+ @Override
+ public final void glStencilMask (int mask) {
gl.glStencilMask(mask);
}
- @Override public final void glStencilOp (int fail, int zfail, int zpass) {
+ @Override
+ public final void glStencilOp (int fail, int zfail, int zpass) {
gl.glStencilOp(fail, zfail, zpass);
}
- @Override public final void glTexCoordPointer (int size, int type, int stride, Buffer pointer) {
+ @Override
+ public final void glTexCoordPointer (int size, int type, int stride, Buffer pointer) {
gl.glTexCoordPointer(size, type, stride, pointer);
}
- @Override public final void glTexEnvf (int target, int pname, float param) {
+ @Override
+ public final void glTexEnvf (int target, int pname, float param) {
gl.glTexEnvf(target, pname, param);
}
- @Override public final void glTexEnvfv (int target, int pname, FloatBuffer params) {
+ @Override
+ public final void glTexEnvfv (int target, int pname, FloatBuffer params) {
gl.glTexEnvfv(target, pname, params);
}
- @Override public final void glTexImage2D (int target, int level, int internalformat, int width, int height, int border,
- int format, int type, Buffer pixels) {
+ @Override
+ public final void glTexImage2D (int target, int level, int internalformat, int width, int height, int border, int format,
+ int type, Buffer pixels) {
gl.glTexImage2D(target, level, internalformat, width, height, border, format, type, pixels);
}
- @Override public final void glTexParameterf (int target, int pname, float param) {
+ @Override
+ public final void glTexParameterf (int target, int pname, float param) {
gl.glTexParameterf(target, pname, param);
}
- @Override public final void glTexSubImage2D (int target, int level, int xoffset, int yoffset, int width, int height,
- int format, int type, Buffer pixels) {
+ @Override
+ public final void glTexSubImage2D (int target, int level, int xoffset, int yoffset, int width, int height, int format,
+ int type, Buffer pixels) {
gl.glTexSubImage2D(target, level, xoffset, yoffset, width, height, format, type, pixels);
}
- @Override public final void glTranslatef (float x, float y, float z) {
+ @Override
+ public final void glTranslatef (float x, float y, float z) {
gl.glTranslatef(x, y, z);
}
- @Override public final void glVertexPointer (int size, int type, int stride, Buffer pointer) {
+ @Override
+ public final void glVertexPointer (int size, int type, int stride, Buffer pointer) {
gl.glVertexPointer(size, type, stride, pointer);
}
- @Override public final void glViewport (int x, int y, int width, int height) {
+ @Override
+ public final void glViewport (int x, int y, int width, int height) {
gl.glViewport(x, y, width, height);
}
- @Override public final void glDeleteTextures (int n, int[] textures, int offset) {
+ @Override
+ public final void glDeleteTextures (int n, int[] textures, int offset) {
gl.glDeleteTextures(n, textures, offset);
}
- @Override public final void glFogfv (int pname, float[] params, int offset) {
+ @Override
+ public final void glFogfv (int pname, float[] params, int offset) {
gl.glFogfv(pname, params, offset);
}
- @Override public final void glGenTextures (int n, int[] textures, int offset) {
+ @Override
+ public final void glGenTextures (int n, int[] textures, int offset) {
gl.glGenTextures(n, textures, offset);
}
- @Override public final void glGetIntegerv (int pname, int[] params, int offset) {
+ @Override
+ public final void glGetIntegerv (int pname, int[] params, int offset) {
gl.glGetIntegerv(pname, params, offset);
}
- @Override public final void glLightModelfv (int pname, float[] params, int offset) {
+ @Override
+ public final void glLightModelfv (int pname, float[] params, int offset) {
gl.glLightModelfv(pname, params, offset);
}
- @Override public final void glLightfv (int light, int pname, float[] params, int offset) {
+ @Override
+ public final void glLightfv (int light, int pname, float[] params, int offset) {
gl.glLightfv(light, pname, params, offset);
}
- @Override public final void glLoadMatrixf (float[] m, int offset) {
+ @Override
+ public final void glLoadMatrixf (float[] m, int offset) {
gl.glLoadMatrixf(m, offset);
}
- @Override public final void glMaterialfv (int face, int pname, float[] params, int offset) {
+ @Override
+ public final void glMaterialfv (int face, int pname, float[] params, int offset) {
gl.glMaterialfv(face, pname, params, offset);
}
- @Override public final void glMultMatrixf (float[] m, int offset) {
+ @Override
+ public final void glMultMatrixf (float[] m, int offset) {
gl.glMultMatrixf(m, offset);
}
- @Override public final void glTexEnvfv (int target, int pname, float[] params, int offset) {
+ @Override
+ public final void glTexEnvfv (int target, int pname, float[] params, int offset) {
gl.glTexEnvfv(target, pname, params, offset);
}
- @Override public void glPolygonMode (int face, int mode) {
+ @Override
+ public void glPolygonMode (int face, int mode) {
// throw new UnsupportedOperationException( "not available in OpenGL ES" );
}
}
diff --git a/backends/gdx-backend-android/src/com/badlogic/gdx/backends/android/AndroidGL11.java b/backends/gdx-backend-android/src/com/badlogic/gdx/backends/android/AndroidGL11.java
index d023f99c53f..441ac9baed6 100644
--- a/backends/gdx-backend-android/src/com/badlogic/gdx/backends/android/AndroidGL11.java
+++ b/backends/gdx-backend-android/src/com/badlogic/gdx/backends/android/AndroidGL11.java
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
+
package com.badlogic.gdx.backends.android;
import java.nio.Buffer;
@@ -23,12 +24,9 @@
import com.badlogic.gdx.graphics.GL11;
-/**
- * An implementation of the {@link GL11} interface for Android
- *
- * @author mzechner
+/** An implementation of the {@link GL11} interface for Android
*
- */
+ * @author mzechner */
final class AndroidGL11 extends AndroidGL10 implements GL11 {
private final javax.microedition.khronos.opengles.GL11 gl;
@@ -37,199 +35,248 @@ public AndroidGL11 (GL10 gl) {
this.gl = (javax.microedition.khronos.opengles.GL11)gl;
}
- @Override public void glBindBuffer (int target, int buffer) {
+ @Override
+ public void glBindBuffer (int target, int buffer) {
gl.glBindBuffer(target, buffer);
}
- @Override public void glBufferData (int target, int size, Buffer data, int usage) {
+ @Override
+ public void glBufferData (int target, int size, Buffer data, int usage) {
gl.glBufferData(target, size, data, usage);
}
- @Override public void glBufferSubData (int target, int offset, int size, Buffer data) {
+ @Override
+ public void glBufferSubData (int target, int offset, int size, Buffer data) {
gl.glBufferSubData(target, offset, size, data);
}
- @Override public void glClipPlanef (int plane, FloatBuffer equation) {
+ @Override
+ public void glClipPlanef (int plane, FloatBuffer equation) {
gl.glClipPlanef(plane, equation);
}
- @Override public void glColor4ub (byte red, byte green, byte blue, byte alpha) {
+ @Override
+ public void glColor4ub (byte red, byte green, byte blue, byte alpha) {
gl.glColor4ub(red, green, blue, alpha);
}
- @Override public void glDeleteBuffers (int n, IntBuffer buffers) {
+ @Override
+ public void glDeleteBuffers (int n, IntBuffer buffers) {
gl.glDeleteBuffers(n, buffers);
}
- @Override public void glGenBuffers (int n, IntBuffer buffers) {
+ @Override
+ public void glGenBuffers (int n, IntBuffer buffers) {
gl.glGenBuffers(n, buffers);
}
- @Override public void glGetBooleanv (int pname, IntBuffer params) {
+ @Override
+ public void glGetBooleanv (int pname, IntBuffer params) {
gl.glGetBooleanv(pname, params);
}
- @Override public void glGetBufferParameteriv (int target, int pname, IntBuffer params) {
+ @Override
+ public void glGetBufferParameteriv (int target, int pname, IntBuffer params) {
gl.glGetBufferParameteriv(target, pname, params);
}
- @Override public void glGetClipPlanef (int pname, FloatBuffer eqn) {
+ @Override
+ public void glGetClipPlanef (int pname, FloatBuffer eqn) {
gl.glGetClipPlanef(pname, eqn);
}
- @Override public void glGetFloatv (int pname, FloatBuffer params) {
+ @Override
+ public void glGetFloatv (int pname, FloatBuffer params) {
gl.glGetFloatv(pname, params);
}
- @Override public void glGetLightfv (int light, int pname, FloatBuffer params) {
+ @Override
+ public void glGetLightfv (int light, int pname, FloatBuffer params) {
gl.glGetLightfv(light, pname, params);
}
- @Override public void glGetMaterialfv (int face, int pname, FloatBuffer params) {
+ @Override
+ public void glGetMaterialfv (int face, int pname, FloatBuffer params) {
gl.glGetMaterialfv(face, pname, params);
}
- @Override public void glGetPointerv (int pname, Buffer[] params) {
+ @Override
+ public void glGetPointerv (int pname, Buffer[] params) {
gl.glGetPointerv(pname, params);
}
- @Override public void glGetTexEnviv (int env, int pname, IntBuffer params) {
+ @Override
+ public void glGetTexEnviv (int env, int pname, IntBuffer params) {
gl.glGetTexEnviv(env, pname, params);
}
- @Override public void glGetTexParameterfv (int target, int pname, FloatBuffer params) {
+ @Override
+ public void glGetTexParameterfv (int target, int pname, FloatBuffer params) {
gl.glGetTexParameterfv(target, pname, params);
}
- @Override public void glGetTexParameteriv (int target, int pname, IntBuffer params) {
+ @Override
+ public void glGetTexParameteriv (int target, int pname, IntBuffer params) {
gl.glGetTexParameteriv(target, pname, params);
}
- @Override public boolean glIsBuffer (int buffer) {
+ @Override
+ public boolean glIsBuffer (int buffer) {
return gl.glIsBuffer(buffer);
}
- @Override public boolean glIsEnabled (int cap) {
+ @Override
+ public boolean glIsEnabled (int cap) {
return gl.glIsEnabled(cap);
}
- @Override public boolean glIsTexture (int texture) {
+ @Override
+ public boolean glIsTexture (int texture) {
return gl.glIsTexture(texture);
}
- @Override public void glPointParameterf (int pname, float param) {
+ @Override
+ public void glPointParameterf (int pname, float param) {
gl.glPointParameterf(pname, param);
}
- @Override public void glPointParameterfv (int pname, FloatBuffer params) {
+ @Override
+ public void glPointParameterfv (int pname, FloatBuffer params) {
gl.glPointParameterfv(pname, params);
}
- @Override public void glPointSizePointerOES (int type, int stride, Buffer pointer) {
+ @Override
+ public void glPointSizePointerOES (int type, int stride, Buffer pointer) {
gl.glPointSizePointerOES(type, stride, pointer);
}
- @Override public void glTexEnvi (int target, int pname, int param) {
+ @Override
+ public void glTexEnvi (int target, int pname, int param) {
gl.glTexEnvi(target, pname, param);
}
- @Override public void glTexEnviv (int target, int pname, IntBuffer params) {
+ @Override
+ public void glTexEnviv (int target, int pname, IntBuffer params) {
gl.glTexEnviv(target, pname, params);
}
- @Override public void glTexParameterfv (int target, int pname, FloatBuffer params) {
+ @Override
+ public void glTexParameterfv (int target, int pname, FloatBuffer params) {
gl.glTexParameterfv(target, pname, params);
}
- @Override public void glTexParameteri (int target, int pname, int param) {
+ @Override
+ public void glTexParameteri (int target, int pname, int param) {
gl.glTexParameteri(target, pname, param);
}
- @Override public void glTexParameteriv (int target, int pname, IntBuffer params) {
+ @Override
+ public void glTexParameteriv (int target, int pname, IntBuffer params) {
gl.glTexParameteriv(target, pname, params);
}
- @Override public void glClipPlanef (int plane, float[] equation, int offset) {
+ @Override
+ public void glClipPlanef (int plane, float[] equation, int offset) {
gl.glClipPlanef(plane, equation, offset);
}
- @Override public void glDeleteBuffers (int n, int[] buffers, int offset) {
+ @Override
+ public void glDeleteBuffers (int n, int[] buffers, int offset) {
gl.glDeleteBuffers(n, buffers, offset);
}
- @Override public void glGenBuffers (int n, int[] buffers, int offset) {
+ @Override
+ public void glGenBuffers (int n, int[] buffers, int offset) {
gl.glGenBuffers(n, buffers, offset);
}
- @Override public void glGetBooleanv (int pname, boolean[] params, int offset) {
+ @Override
+ public void glGetBooleanv (int pname, boolean[] params, int offset) {
gl.glGetBooleanv(pname, params, offset);
}
- @Override public void glGetBufferParameteriv (int target, int pname, int[] params, int offset) {
+ @Override
+ public void glGetBufferParameteriv (int target, int pname, int[] params, int offset) {
gl.glGetBufferParameteriv(target, pname, params, offset);
}
- @Override public void glGetClipPlanef (int pname, float[] eqn, int offset) {
+ @Override
+ public void glGetClipPlanef (int pname, float[] eqn, int offset) {
gl.glGetClipPlanef(pname, eqn, offset);
}
- @Override public void glGetFloatv (int pname, float[] params, int offset) {
+ @Override
+ public void glGetFloatv (int pname, float[] params, int offset) {
gl.glGetFloatv(pname, params, offset);
}
- @Override public void glGetLightfv (int light, int pname, float[] params, int offset) {
+ @Override
+ public void glGetLightfv (int light, int pname, float[] params, int offset) {
gl.glGetLightfv(light, pname, params, offset);
}
- @Override public void glGetMaterialfv (int face, int pname, float[] params, int offset) {
+ @Override
+ public void glGetMaterialfv (int face, int pname, float[] params, int offset) {
gl.glGetMaterialfv(face, pname, params, offset);
}
- @Override public void glGetTexEnviv (int env, int pname, int[] params, int offset) {
+ @Override
+ public void glGetTexEnviv (int env, int pname, int[] params, int offset) {
gl.glGetTexEnviv(env, pname, params, offset);
}
- @Override public void glGetTexParameterfv (int target, int pname, float[] params, int offset) {
+ @Override
+ public void glGetTexParameterfv (int target, int pname, float[] params, int offset) {
gl.glGetTexParameterfv(target, pname, params, offset);
}
- @Override public void glGetTexParameteriv (int target, int pname, int[] params, int offset) {
+ @Override
+ public void glGetTexParameteriv (int target, int pname, int[] params, int offset) {
gl.glGetTexParameteriv(target, pname, params, offset);
}
- @Override public void glPointParameterfv (int pname, float[] params, int offset) {
+ @Override
+ public void glPointParameterfv (int pname, float[] params, int offset) {
gl.glPointParameterfv(pname, params, offset);
}
- @Override public void glTexEnviv (int target, int pname, int[] params, int offset) {
+ @Override
+ public void glTexEnviv (int target, int pname, int[] params, int offset) {
gl.glTexEnviv(target, pname, params, offset);
}
- @Override public void glTexParameterfv (int target, int pname, float[] params, int offset) {
+ @Override
+ public void glTexParameterfv (int target, int pname, float[] params, int offset) {
gl.glTexParameterfv(target, pname, params, offset);
}
- @Override public void glTexParameteriv (int target, int pname, int[] params, int offset) {
+ @Override
+ public void glTexParameteriv (int target, int pname, int[] params, int offset) {
gl.glTexParameteriv(target, pname, params, offset);
}
- @Override public void glColorPointer (int size, int type, int stride, int pointer) {
+ @Override
+ public void glColorPointer (int size, int type, int stride, int pointer) {
gl.glColorPointer(size, type, stride, pointer);
}
- @Override public void glNormalPointer (int type, int stride, int pointer) {
+ @Override
+ public void glNormalPointer (int type, int stride, int pointer) {
gl.glNormalPointer(type, stride, pointer);
}
- @Override public void glTexCoordPointer (int size, int type, int stride, int pointer) {
+ @Override
+ public void glTexCoordPointer (int size, int type, int stride, int pointer) {
gl.glTexCoordPointer(size, type, stride, pointer);
}
- @Override public void glVertexPointer (int size, int type, int stride, int pointer) {
+ @Override
+ public void glVertexPointer (int size, int type, int stride, int pointer) {
gl.glVertexPointer(size, type, stride, pointer);
}
- @Override public void glDrawElements (int mode, int count, int type, int indices) {
+ @Override
+ public void glDrawElements (int mode, int count, int type, int indices) {
gl.glDrawElements(mode, count, type, indices);
}
}
diff --git a/backends/gdx-backend-android/src/com/badlogic/gdx/backends/android/AndroidGL20.java b/backends/gdx-backend-android/src/com/badlogic/gdx/backends/android/AndroidGL20.java
index 6b6f2b800e6..6c796a68263 100644
--- a/backends/gdx-backend-android/src/com/badlogic/gdx/backends/android/AndroidGL20.java
+++ b/backends/gdx-backend-android/src/com/badlogic/gdx/backends/android/AndroidGL20.java
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
+
package com.badlogic.gdx.backends.android;
import java.nio.Buffer;
diff --git a/backends/gdx-backend-android/src/com/badlogic/gdx/backends/android/AndroidGLU.java b/backends/gdx-backend-android/src/com/badlogic/gdx/backends/android/AndroidGLU.java
index f2f2eecd072..bea7c5f7b65 100644
--- a/backends/gdx-backend-android/src/com/badlogic/gdx/backends/android/AndroidGLU.java
+++ b/backends/gdx-backend-android/src/com/badlogic/gdx/backends/android/AndroidGLU.java
@@ -13,35 +13,43 @@
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
+
package com.badlogic.gdx.backends.android;
import com.badlogic.gdx.graphics.GL10;
import com.badlogic.gdx.graphics.GLU;
-public class AndroidGLU implements GLU {
-
- @Override public void gluLookAt (GL10 gl, float eyeX, float eyeY, float eyeZ, float centerX, float centerY, float centerZ,
- float upX, float upY, float upZ) {
+public class AndroidGLU implements GLU {
+
+ @Override
+ public void gluLookAt (GL10 gl, float eyeX, float eyeY, float eyeZ, float centerX, float centerY, float centerZ, float upX,
+ float upY, float upZ) {
android.opengl.GLU.gluLookAt(((AndroidGL10)gl).gl, eyeX, eyeY, eyeZ, centerX, centerY, centerZ, upX, upY, upZ);
}
- @Override public void gluOrtho2D (GL10 gl, float left, float right, float bottom, float top) {
+ @Override
+ public void gluOrtho2D (GL10 gl, float left, float right, float bottom, float top) {
android.opengl.GLU.gluOrtho2D(((AndroidGL10)gl).gl, left, right, bottom, top);
}
- @Override public void gluPerspective (GL10 gl, float fovy, float aspect, float zNear, float zFar) {
+ @Override
+ public void gluPerspective (GL10 gl, float fovy, float aspect, float zNear, float zFar) {
android.opengl.GLU.gluPerspective(((AndroidGL10)gl).gl, fovy, aspect, zNear, zFar);
}
- @Override public boolean gluProject (float objX, float objY, float objZ, float[] model, int modelOffset, float[] project,
+ @Override
+ public boolean gluProject (float objX, float objY, float objZ, float[] model, int modelOffset, float[] project,
int projectOffset, int[] view, int viewOffset, float[] win, int winOffset) {
- int result = android.opengl.GLU.gluProject(objX, objY, objZ, model, modelOffset, project, projectOffset, view, viewOffset, win, winOffset);
+ int result = android.opengl.GLU.gluProject(objX, objY, objZ, model, modelOffset, project, projectOffset, view, viewOffset,
+ win, winOffset);
return result == GL10.GL_TRUE;
}
- @Override public boolean gluUnProject (float winX, float winY, float winZ, float[] model, int modelOffset, float[] project,
+ @Override
+ public boolean gluUnProject (float winX, float winY, float winZ, float[] model, int modelOffset, float[] project,
int projectOffset, int[] view, int viewOffset, float[] obj, int objOffset) {
- int result = android.opengl.GLU.gluUnProject(winX, winY, winZ, model, modelOffset, project, projectOffset, view, viewOffset, obj, objOffset);
+ int result = android.opengl.GLU.gluUnProject(winX, winY, winZ, model, modelOffset, project, projectOffset, view,
+ viewOffset, obj, objOffset);
return result == GL10.GL_TRUE;
}
diff --git a/backends/gdx-backend-android/src/com/badlogic/gdx/backends/android/AndroidGraphics.java b/backends/gdx-backend-android/src/com/badlogic/gdx/backends/android/AndroidGraphics.java
index b8b4e58bd72..a33217076da 100644
--- a/backends/gdx-backend-android/src/com/badlogic/gdx/backends/android/AndroidGraphics.java
+++ b/backends/gdx-backend-android/src/com/badlogic/gdx/backends/android/AndroidGraphics.java
@@ -47,11 +47,9 @@
import com.badlogic.gdx.graphics.glutils.ShaderProgram;
import com.badlogic.gdx.math.WindowedMean;
-/**
- * An implementation of {@link Graphics} for Android.
+/** An implementation of {@link Graphics} for Android.
*
- * @author mzechner
- */
+ * @author mzechner */
public final class AndroidGraphics implements Graphics, Renderer {
final View view;
int width;
@@ -86,7 +84,8 @@ public final class AndroidGraphics implements Graphics, Renderer {
private final AndroidApplicationConfiguration config;
private BufferFormat bufferFormat = new BufferFormat(5, 6, 5, 0, 16, 0, 0, false);
- public AndroidGraphics (AndroidApplication activity, AndroidApplicationConfiguration config, ResolutionStrategy resolutionStrategy) {
+ public AndroidGraphics (AndroidApplication activity, AndroidApplicationConfiguration config,
+ ResolutionStrategy resolutionStrategy) {
this.config = config;
view = createGLSurfaceView(activity, config.useGL20, resolutionStrategy);
view.setFocusable(true);
@@ -94,51 +93,58 @@ public AndroidGraphics (AndroidApplication activity, AndroidApplicationConfigura
this.app = activity;
}
- private View createGLSurfaceView(Activity activity, boolean useGL2, ResolutionStrategy resolutionStrategy) {
- EGLConfigChooser configChooser = getEglConfigChooser();
-
- if (useGL2 && checkGL20()) {
- GLSurfaceView20 view = new GLSurfaceView20(activity, resolutionStrategy);
- if (configChooser != null) view.setEGLConfigChooser(configChooser);
- else view.setEGLConfigChooser(config.r, config.g, config.b, config.a, config.depth, config.stencil);
- view.setRenderer(this);
- return view;
- } else {
- if (Integer.parseInt(android.os.Build.VERSION.SDK) <= 4) {
- GLSurfaceViewCupcake view = new GLSurfaceViewCupcake(activity, resolutionStrategy);
- if (configChooser != null) view.setEGLConfigChooser(configChooser);
- else view.setEGLConfigChooser(config.r, config.g, config.b, config.a, config.depth, config.stencil);
- view.setRenderer(this);
- return view;
- } else {
- android.opengl.GLSurfaceView view = new DefaultGLSurfaceView(activity, resolutionStrategy);
- if (configChooser != null) view.setEGLConfigChooser(configChooser);
- else view.setEGLConfigChooser(config.r, config.g, config.b, config.a, config.depth, config.stencil);
- view.setRenderer(this);
- return view;
- }
- }
- }
+ private View createGLSurfaceView (Activity activity, boolean useGL2, ResolutionStrategy resolutionStrategy) {
+ EGLConfigChooser configChooser = getEglConfigChooser();
+
+ if (useGL2 && checkGL20()) {
+ GLSurfaceView20 view = new GLSurfaceView20(activity, resolutionStrategy);
+ if (configChooser != null)
+ view.setEGLConfigChooser(configChooser);
+ else
+ view.setEGLConfigChooser(config.r, config.g, config.b, config.a, config.depth, config.stencil);
+ view.setRenderer(this);
+ return view;
+ } else {
+ if (Integer.parseInt(android.os.Build.VERSION.SDK) <= 4) {
+ GLSurfaceViewCupcake view = new GLSurfaceViewCupcake(activity, resolutionStrategy);
+ if (configChooser != null)
+ view.setEGLConfigChooser(configChooser);
+ else
+ view.setEGLConfigChooser(config.r, config.g, config.b, config.a, config.depth, config.stencil);
+ view.setRenderer(this);
+ return view;
+ } else {
+ android.opengl.GLSurfaceView view = new DefaultGLSurfaceView(activity, resolutionStrategy);
+ if (configChooser != null)
+ view.setEGLConfigChooser(configChooser);
+ else
+ view.setEGLConfigChooser(config.r, config.g, config.b, config.a, config.depth, config.stencil);
+ view.setRenderer(this);
+ return view;
+ }
+ }
+ }
private EGLConfigChooser getEglConfigChooser () {
- return new GdxEglConfigChooser(config.r, config.g, config.b, config.a, config.depth, config.stencil, config.numSamples, config.useGL20);
-
-// if (!Build.DEVICE.equalsIgnoreCase("GT-I7500"))
-// return null;
-// else
-// return new android.opengl.GLSurfaceView.EGLConfigChooser() {
+ return new GdxEglConfigChooser(config.r, config.g, config.b, config.a, config.depth, config.stencil, config.numSamples,
+ config.useGL20);
+
+// if (!Build.DEVICE.equalsIgnoreCase("GT-I7500"))
+// return null;
+// else
+// return new android.opengl.GLSurfaceView.EGLConfigChooser() {
//
-// public EGLConfig chooseConfig (EGL10 egl, EGLDisplay display) {
+// public EGLConfig chooseConfig (EGL10 egl, EGLDisplay display) {
//
-// // Ensure that we get a 16bit depth-buffer. Otherwise, we'll fall
-// // back to Pixelflinger on some device (read: Samsung I7500)
-// int[] attributes = new int[] {EGL10.EGL_DEPTH_SIZE, 16, EGL10.EGL_NONE};
-// EGLConfig[] configs = new EGLConfig[1];
-// int[] result = new int[1];
-// egl.eglChooseConfig(display, attributes, configs, 1, result);
-// return configs[0];
-// }
-// };
+// // Ensure that we get a 16bit depth-buffer. Otherwise, we'll fall
+// // back to Pixelflinger on some device (read: Samsung I7500)
+// int[] attributes = new int[] {EGL10.EGL_DEPTH_SIZE, 16, EGL10.EGL_NONE};
+// EGLConfig[] configs = new EGLConfig[1];
+// int[] result = new int[1];
+// egl.eglChooseConfig(display, attributes, configs, 1, result);
+// return configs[0];
+// }
+// };
}
private void updatePpi () {
@@ -170,52 +176,45 @@ private boolean checkGL20 () {
return num_config[0] > 0;
}
- /**
- * {@inheritDoc}
- */
- @Override public GL10 getGL10 () {
+ /** {@inheritDoc} */
+ @Override
+ public GL10 getGL10 () {
return gl10;
}
- /**
- * {@inheritDoc}
- */
- @Override public GL11 getGL11 () {
+ /** {@inheritDoc} */
+ @Override
+ public GL11 getGL11 () {
return gl11;
}
- /**
- * {@inheritDoc}
- */
- @Override public GL20 getGL20 () {
+ /** {@inheritDoc} */
+ @Override
+ public GL20 getGL20 () {
return gl20;
}
- /**
- * {@inheritDoc}
- */
- @Override public int getHeight () {
+ /** {@inheritDoc} */
+ @Override
+ public int getHeight () {
return height;
}
- /**
- * {@inheritDoc}
- */
- @Override public int getWidth () {
+ /** {@inheritDoc} */
+ @Override
+ public int getWidth () {
return width;
}
- /**
- * {@inheritDoc}
- */
- @Override public boolean isGL11Available () {
+ /** {@inheritDoc} */
+ @Override
+ public boolean isGL11Available () {
return gl11 != null;
}
- /**
- * {@inheritDoc}
- */
- @Override public boolean isGL20Available () {
+ /** {@inheritDoc} */
+ @Override
+ public boolean isGL20Available () {
return gl20 != null;
}
@@ -223,13 +222,11 @@ private static boolean isPowerOfTwo (int value) {
return ((value != 0) && (value & (value - 1)) == 0);
}
- /**
- * This instantiates the GL10, GL11 and GL20 instances. Includes the check for certain devices that pretend to support GL11 but
+ /** This instantiates the GL10, GL11 and GL20 instances. Includes the check for certain devices that pretend to support GL11 but
* fuck up vertex buffer objects. This includes the pixelflinger which segfaults when buffers are deleted as well as the
* Motorola CLIQ and the Samsung Behold II.
*
- * @param gl
- */
+ * @param gl */
private void setupGL (javax.microedition.khronos.opengles.GL10 gl) {
if (gl10 != null || gl20 != null) return;
@@ -266,7 +263,8 @@ private void setupGL (javax.microedition.khronos.opengles.GL10 gl) {
Gdx.app.log("AndroidGraphics", "OGL extensions: " + gl.glGetString(GL10.GL_EXTENSIONS));
}
- @Override public void onSurfaceChanged (javax.microedition.khronos.opengles.GL10 gl, int width, int height) {
+ @Override
+ public void onSurfaceChanged (javax.microedition.khronos.opengles.GL10 gl, int width, int height) {
this.width = width;
this.height = height;
updatePpi();
@@ -281,7 +279,8 @@ private void setupGL (javax.microedition.khronos.opengles.GL10 gl) {
app.listener.resize(width, height);
}
- @Override public void onSurfaceCreated (javax.microedition.khronos.opengles.GL10 gl, EGLConfig config) {
+ @Override
+ public void onSurfaceCreated (javax.microedition.khronos.opengles.GL10 gl, EGLConfig config) {
setupGL(gl);
logConfig(config);
updatePpi();
@@ -313,9 +312,9 @@ private void logConfig (EGLConfig config) {
int b = getAttrib(egl, display, config, EGL10.EGL_BLUE_SIZE, 0);
int a = getAttrib(egl, display, config, EGL10.EGL_ALPHA_SIZE, 0);
int d = getAttrib(egl, display, config, EGL10.EGL_DEPTH_SIZE, 0);
- int s = getAttrib(egl, display, config, EGL10.EGL_STENCIL_SIZE, 0);
+ int s = getAttrib(egl, display, config, EGL10.EGL_STENCIL_SIZE, 0);
int samples = Math.max(getAttrib(egl, display, config, EGL10.EGL_SAMPLES, 0),
- getAttrib(egl, display, config, GdxEglConfigChooser.EGL_COVERAGE_SAMPLES_NV, 0));
+ getAttrib(egl, display, config, GdxEglConfigChooser.EGL_COVERAGE_SAMPLES_NV, 0));
boolean coverageSample = getAttrib(egl, display, config, GdxEglConfigChooser.EGL_COVERAGE_SAMPLES_NV, 0) != 0;
Gdx.app.log("AndroidGraphics", "framebuffer: (" + r + ", " + g + ", " + b + ", " + a + ")");
@@ -373,7 +372,8 @@ void destroy () {
}
}
- @Override public void onDrawFrame (javax.microedition.khronos.opengles.GL10 gl) {
+ @Override
+ public void onDrawFrame (javax.microedition.khronos.opengles.GL10 gl) {
long time = System.nanoTime();
deltaTime = (time - lastFrameTime) / 1000000000.0f;
lastFrameTime = time;
@@ -442,24 +442,21 @@ void destroy () {
frames++;
}
- /**
- * {@inheritDoc}
- */
- @Override public float getDeltaTime () {
+ /** {@inheritDoc} */
+ @Override
+ public float getDeltaTime () {
return mean.getMean() == 0 ? deltaTime : mean.getMean();
}
- /**
- * {@inheritDoc}
- */
- @Override public GraphicsType getType () {
+ /** {@inheritDoc} */
+ @Override
+ public GraphicsType getType () {
return GraphicsType.AndroidGL;
}
- /**
- * {@inheritDoc}
- */
- @Override public int getFramesPerSecond () {
+ /** {@inheritDoc} */
+ @Override
+ public int getFramesPerSecond () {
return fps;
}
@@ -479,58 +476,69 @@ public View getView () {
return view;
}
- /**
- * {@inheritDoc}
- */
- @Override public GLCommon getGLCommon () {
+ /** {@inheritDoc} */
+ @Override
+ public GLCommon getGLCommon () {
return gl;
}
- @Override public float getPpiX () {
+ @Override
+ public float getPpiX () {
return ppiX;
}
- @Override public float getPpiY () {
+ @Override
+ public float getPpiY () {
return ppiY;
}
- @Override public float getPpcX () {
+ @Override
+ public float getPpcX () {
return ppcX;
}
- @Override public float getPpcY () {
+ @Override
+ public float getPpcY () {
return ppcY;
}
-
- @Override public float getDensity () {
+
+ @Override
+ public float getDensity () {
return density;
}
- @Override public GLU getGLU () {
+ @Override
+ public GLU getGLU () {
return glu;
}
- @Override public boolean supportsDisplayModeChange () {
+ @Override
+ public boolean supportsDisplayModeChange () {
return false;
}
- @Override public boolean setDisplayMode (DisplayMode displayMode) {
+ @Override
+ public boolean setDisplayMode (DisplayMode displayMode) {
return false;
}
- @Override public DisplayMode[] getDisplayModes () {
+ @Override
+ public DisplayMode[] getDisplayModes () {
return new DisplayMode[] {getDesktopDisplayMode()};
}
- @Override public boolean setDisplayMode (int width, int height, boolean fullscreen) {
+ @Override
+ public boolean setDisplayMode (int width, int height, boolean fullscreen) {
return false;
}
- @Override public void setTitle (String title) {
+ @Override
+ public void setTitle (String title) {
}
- @Override public void setIcon (Pixmap pixmap) {
+ @Override
+ public void setIcon (Pixmap pixmap) {
}
@@ -540,21 +548,25 @@ protected AndroidDisplayMode (int width, int height, int refreshRate, int bitsPe
}
}
- @Override public DisplayMode getDesktopDisplayMode () {
+ @Override
+ public DisplayMode getDesktopDisplayMode () {
DisplayMetrics metrics = new DisplayMetrics();
app.getWindowManager().getDefaultDisplay().getMetrics(metrics);
return new AndroidDisplayMode(metrics.widthPixels, metrics.heightPixels, 0, 0);
}
- @Override public BufferFormat getBufferFormat () {
+ @Override
+ public BufferFormat getBufferFormat () {
return bufferFormat;
}
- @Override public void setVSync (boolean vsync) {
+ @Override
+ public void setVSync (boolean vsync) {
}
- @Override public boolean supportsExtension (String extension) {
- if(extensions == null) extensions = Gdx.gl.glGetString(GL10.GL_EXTENSIONS);
+ @Override
+ public boolean supportsExtension (String extension) {
+ if (extensions == null) extensions = Gdx.gl.glGetString(GL10.GL_EXTENSIONS);
return extensions.contains(extension);
}
}
diff --git a/backends/gdx-backend-android/src/com/badlogic/gdx/backends/android/AndroidInput.java b/backends/gdx-backend-android/src/com/badlogic/gdx/backends/android/AndroidInput.java
index d4503761e22..3a0b7f670b1 100644
--- a/backends/gdx-backend-android/src/com/badlogic/gdx/backends/android/AndroidInput.java
+++ b/backends/gdx-backend-android/src/com/badlogic/gdx/backends/android/AndroidInput.java
@@ -29,13 +29,11 @@
import android.hardware.SensorManager;
import android.os.Handler;
import android.os.Vibrator;
-import android.view.Display;
import android.view.MotionEvent;
import android.view.Surface;
import android.view.View;
import android.view.View.OnKeyListener;
import android.view.View.OnTouchListener;
-import android.view.WindowManager;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;
@@ -45,12 +43,9 @@
import com.badlogic.gdx.InputProcessor;
import com.badlogic.gdx.utils.Pool;
-/**
- * An implementation of the {@link Input} interface for Android.
+/** An implementation of the {@link Input} interface for Android.
*
- * @author mzechner
- *
- */
+ * @author mzechner */
public final class AndroidInput implements Input, OnKeyListener, OnTouchListener, SensorEventListener {
class KeyEvent {
static final int KEY_DOWN = 0;
@@ -143,30 +138,34 @@ public AndroidInput (AndroidApplication activity, View view, AndroidApplicationC
hasMultitouch = touchHandler.supportsMultitouch(app);
vibrator = (Vibrator)activity.getSystemService(Context.VIBRATOR_SERVICE);
-
+
int rotation = getRotation();
DisplayMode mode = app.graphics.getDesktopDisplayMode();
- if(((rotation == 0 || rotation == 180) && (mode.width >= mode.height)) ||
- ((rotation == 90 || rotation == 270) && (mode.width <= mode.height))) {
+ if (((rotation == 0 || rotation == 180) && (mode.width >= mode.height))
+ || ((rotation == 90 || rotation == 270) && (mode.width <= mode.height))) {
nativeOrientation = Orientation.Landscape;
} else {
nativeOrientation = Orientation.Portrait;
- }
+ }
}
- @Override public float getAccelerometerX () {
+ @Override
+ public float getAccelerometerX () {
return accelerometerValues[0];
}
- @Override public float getAccelerometerY () {
+ @Override
+ public float getAccelerometerY () {
return accelerometerValues[1];
}
- @Override public float getAccelerometerZ () {
+ @Override
+ public float getAccelerometerZ () {
return accelerometerValues[2];
}
- @Override public void getTextInput (final TextInputListener listener, final String title, final String text) {
+ @Override
+ public void getTextInput (final TextInputListener listener, final String title, final String text) {
handle.post(new Runnable() {
public void run () {
AlertDialog.Builder alert = new AlertDialog.Builder(AndroidInput.this.app);
@@ -181,7 +180,8 @@ public void onClick (DialogInterface dialog, int whichButton) {
}
});
alert.setOnCancelListener(new OnCancelListener() {
- @Override public void onCancel (DialogInterface arg0) {
+ @Override
+ public void onCancel (DialogInterface arg0) {
listener.canceled();
}
});
@@ -190,25 +190,29 @@ public void onClick (DialogInterface dialog, int whichButton) {
});
}
- @Override public int getX () {
+ @Override
+ public int getX () {
synchronized (this) {
return touchX[0];
}
}
- @Override public int getY () {
+ @Override
+ public int getY () {
synchronized (this) {
return touchY[0];
}
}
- @Override public int getX (int pointer) {
+ @Override
+ public int getX (int pointer) {
synchronized (this) {
return touchX[pointer];
}
}
- @Override public int getY (int pointer) {
+ @Override
+ public int getY (int pointer) {
synchronized (this) {
return touchY[pointer];
}
@@ -220,7 +224,8 @@ public boolean isTouched (int pointer) {
}
}
- @Override public boolean isKeyPressed (int key) {
+ @Override
+ public boolean isKeyPressed (int key) {
synchronized (this) {
if (key == Input.Keys.ANY_KEY)
return keys.size() > 0;
@@ -229,7 +234,8 @@ public boolean isTouched (int pointer) {
}
}
- @Override public boolean isTouched () {
+ @Override
+ public boolean isTouched () {
synchronized (this) {
return touched[0];
}
@@ -293,9 +299,9 @@ void processEvents () {
usedKeyEvents.free(keyEvents.get(i));
}
}
-
- if(touchEvents.size() == 0) {
- for(int i = 0; i < deltaX.length; i++) {
+
+ if (touchEvents.size() == 0) {
+ for (int i = 0; i < deltaX.length; i++) {
deltaX[0] = 0;
deltaY[0] = 0;
}
@@ -308,7 +314,8 @@ void processEvents () {
boolean requestFocus = true;
- @Override public boolean onTouch (View view, MotionEvent event) {
+ @Override
+ public boolean onTouch (View view, MotionEvent event) {
if (requestFocus) {
view.requestFocus();
view.requestFocusFromTouch();
@@ -327,7 +334,8 @@ void processEvents () {
return true;
}
- @Override public boolean onKey (View v, int keyCode, android.view.KeyEvent e) {
+ @Override
+ public boolean onKey (View v, int keyCode, android.view.KeyEvent e) {
synchronized (this) {
char character = (char)e.getUnicodeChar();
// Android doesn't report a unicode char for back space. hrm...
@@ -375,13 +383,15 @@ void processEvents () {
return false;
}
- @Override public void onAccuracyChanged (Sensor arg0, int arg1) {
+ @Override
+ public void onAccuracyChanged (Sensor arg0, int arg1) {
}
- @Override public void onSensorChanged (SensorEvent event) {
+ @Override
+ public void onSensorChanged (SensorEvent event) {
if (event.sensor.getType() == Sensor.TYPE_ACCELEROMETER) {
- if(nativeOrientation == Orientation.Portrait) {
+ if (nativeOrientation == Orientation.Portrait) {
System.arraycopy(event.values, 0, accelerometerValues, 0, accelerometerValues.length);
} else {
accelerometerValues[0] = event.values[1];
@@ -394,7 +404,8 @@ void processEvents () {
}
}
- @Override public void setOnscreenKeyboardVisible (final boolean visible) {
+ @Override
+ public void setOnscreenKeyboardVisible (final boolean visible) {
handle.post(new Runnable() {
public void run () {
InputMethodManager manager = (InputMethodManager)app.getSystemService(Context.INPUT_METHOD_SERVICE);
@@ -410,31 +421,38 @@ public void run () {
});
}
- @Override public void setCatchBackKey (boolean catchBack) {
+ @Override
+ public void setCatchBackKey (boolean catchBack) {
this.catchBack = catchBack;
}
-
- @Override public void setCatchMenuKey (boolean catchMenu) {
+
+ @Override
+ public void setCatchMenuKey (boolean catchMenu) {
this.catchMenu = catchMenu;
}
- @Override public void vibrate (int milliseconds) {
+ @Override
+ public void vibrate (int milliseconds) {
vibrator.vibrate(milliseconds);
}
- @Override public void vibrate (long[] pattern, int repeat) {
+ @Override
+ public void vibrate (long[] pattern, int repeat) {
vibrator.vibrate(pattern, repeat);
}
- @Override public void cancelVibrate () {
+ @Override
+ public void cancelVibrate () {
vibrator.cancel();
}
- @Override public boolean justTouched () {
+ @Override
+ public boolean justTouched () {
return justTouched;
}
- @Override public boolean isButtonPressed (int button) {
+ @Override
+ public boolean isButtonPressed (int button) {
if (button == Buttons.LEFT)
return isTouched();
else
@@ -453,21 +471,24 @@ private void updateOrientation () {
}
}
- @Override public float getAzimuth () {
+ @Override
+ public float getAzimuth () {
if (!compassAvailable) return 0;
updateOrientation();
return azimuth;
}
- @Override public float getPitch () {
+ @Override
+ public float getPitch () {
if (!compassAvailable) return 0;
updateOrientation();
return pitch;
}
- @Override public float getRoll () {
+ @Override
+ public float getRoll () {
if (!compassAvailable) return 0;
updateOrientation();
@@ -510,11 +531,13 @@ void unregisterSensorListeners () {
Gdx.app.log("AndroidInput", "sensor listener tear down");
}
- @Override public InputProcessor getInputProcessor () {
+ @Override
+ public InputProcessor getInputProcessor () {
return this.processor;
}
- @Override public boolean isPeripheralAvailable (Peripheral peripheral) {
+ @Override
+ public boolean isPeripheralAvailable (Peripheral peripheral) {
if (peripheral == Peripheral.Accelerometer) return accelerometerAvailable;
if (peripheral == Peripheral.Compass) return compassAvailable;
if (peripheral == Peripheral.HardwareKeyboard) return keyboardAvailable;
@@ -550,7 +573,8 @@ public int lookUpPointerIndex (int pointerId) {
return -1;
}
- @Override public int getRotation () {
+ @Override
+ public int getRotation () {
int orientation = app.getWindowManager().getDefaultDisplay().getOrientation();
switch (orientation) {
case Surface.ROTATION_0:
@@ -566,33 +590,41 @@ public int lookUpPointerIndex (int pointerId) {
}
}
- @Override public Orientation getNativeOrientation () {
+ @Override
+ public Orientation getNativeOrientation () {
return nativeOrientation;
}
- @Override public void setCursorCatched (boolean catched) {
+ @Override
+ public void setCursorCatched (boolean catched) {
}
- @Override public boolean isCursorCatched () {
+ @Override
+ public boolean isCursorCatched () {
return false;
}
- @Override public int getDeltaX () {
+ @Override
+ public int getDeltaX () {
return deltaX[0];
}
- @Override public int getDeltaX (int pointer) {
+ @Override
+ public int getDeltaX (int pointer) {
return deltaX[pointer];
}
- @Override public int getDeltaY () {
+ @Override
+ public int getDeltaY () {
return deltaY[0];
}
- @Override public int getDeltaY (int pointer) {
+ @Override
+ public int getDeltaY (int pointer) {
return deltaY[pointer];
}
- @Override public void setCursorPosition (int x, int y) {
- }
+ @Override
+ public void setCursorPosition (int x, int y) {
+ }
}
diff --git a/backends/gdx-backend-android/src/com/badlogic/gdx/backends/android/AndroidMultiTouchHandler.java b/backends/gdx-backend-android/src/com/badlogic/gdx/backends/android/AndroidMultiTouchHandler.java
index 2204c97a11a..c89e9d3f1e1 100644
--- a/backends/gdx-backend-android/src/com/badlogic/gdx/backends/android/AndroidMultiTouchHandler.java
+++ b/backends/gdx-backend-android/src/com/badlogic/gdx/backends/android/AndroidMultiTouchHandler.java
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
+
package com.badlogic.gdx.backends.android;
import android.view.MotionEvent;
@@ -20,27 +21,24 @@
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.backends.android.AndroidInput.TouchEvent;
-/**
- * Multitouch handler for devices running Android >= 2.0. If device is capable of (fake) multitouch this will report additional
+/** Multitouch handler for devices running Android >= 2.0. If device is capable of (fake) multitouch this will report additional
* pointers.
*
- * @author badlogicgames@gmail.com
- *
- */
+ * @author badlogicgames@gmail.com */
public class AndroidMultiTouchHandler implements AndroidTouchHandler {
public void onTouch (MotionEvent event, AndroidInput input) {
final int action = event.getAction() & MotionEvent.ACTION_MASK;
int pointerIndex = (event.getAction() & MotionEvent.ACTION_POINTER_ID_MASK) >> MotionEvent.ACTION_POINTER_ID_SHIFT;
- int pointerId = event.getPointerId(pointerIndex);
-
+ int pointerId = event.getPointerId(pointerIndex);
+
int x = 0, y = 0;
int realPointerIndex = 0;
-// logAction(action, pointerId);
- synchronized(input) { // FUCK
+// logAction(action, pointerId);
+ synchronized (input) { // FUCK
switch (action) {
- case MotionEvent.ACTION_DOWN:
- case MotionEvent.ACTION_POINTER_DOWN:
+ case MotionEvent.ACTION_DOWN:
+ case MotionEvent.ACTION_POINTER_DOWN:
realPointerIndex = input.getFreePointerIndex(); // get a free pointer index as reported by Input.getX() etc.
input.realId[realPointerIndex] = pointerId;
x = (int)event.getX(pointerIndex);
@@ -52,13 +50,13 @@ public void onTouch (MotionEvent event, AndroidInput input) {
input.deltaY[realPointerIndex] = 0;
input.touched[realPointerIndex] = true;
break;
-
+
case MotionEvent.ACTION_UP:
case MotionEvent.ACTION_POINTER_UP:
case MotionEvent.ACTION_OUTSIDE:
- case MotionEvent.ACTION_CANCEL:
+ case MotionEvent.ACTION_CANCEL:
realPointerIndex = input.lookUpPointerIndex(pointerId);
- if(realPointerIndex == -1) break;
+ if (realPointerIndex == -1) break;
input.realId[realPointerIndex] = -1;
x = (int)event.getX(pointerIndex);
y = (int)event.getY(pointerIndex);
@@ -69,7 +67,7 @@ public void onTouch (MotionEvent event, AndroidInput input) {
input.deltaY[realPointerIndex] = 0;
input.touched[realPointerIndex] = false;
break;
-
+
case MotionEvent.ACTION_MOVE:
int pointerCount = event.getPointerCount();
for (int i = 0; i < pointerCount; i++) {
@@ -78,7 +76,7 @@ public void onTouch (MotionEvent event, AndroidInput input) {
x = (int)event.getX(pointerIndex);
y = (int)event.getY(pointerIndex);
realPointerIndex = input.lookUpPointerIndex(pointerId);
- if(realPointerIndex == -1) continue;
+ if (realPointerIndex == -1) continue;
postTouchEvent(input, TouchEvent.TOUCH_DRAGGED, x, y, realPointerIndex);
input.deltaX[realPointerIndex] = x - input.touchX[realPointerIndex];
input.deltaY[realPointerIndex] = y - input.touchY[realPointerIndex];
@@ -90,28 +88,36 @@ public void onTouch (MotionEvent event, AndroidInput input) {
}
}
- private void logAction(int action, int pointer) {
+ private void logAction (int action, int pointer) {
String actionStr = "";
- if(action == MotionEvent.ACTION_DOWN) actionStr = "DOWN";
- else if(action == MotionEvent.ACTION_POINTER_DOWN) actionStr = "POINTER DOWN";
- else if(action == MotionEvent.ACTION_UP) actionStr = "UP";
- else if(action == MotionEvent.ACTION_POINTER_UP) actionStr = "POINTER UP";
- else if(action == MotionEvent.ACTION_OUTSIDE) actionStr = "OUTSIDE";
- else if(action == MotionEvent.ACTION_CANCEL) actionStr = "CANCEL";
- else if(action == MotionEvent.ACTION_MOVE) actionStr = "MOVE";
- else actionStr = "UNKNOWN (" + action + ")";
+ if (action == MotionEvent.ACTION_DOWN)
+ actionStr = "DOWN";
+ else if (action == MotionEvent.ACTION_POINTER_DOWN)
+ actionStr = "POINTER DOWN";
+ else if (action == MotionEvent.ACTION_UP)
+ actionStr = "UP";
+ else if (action == MotionEvent.ACTION_POINTER_UP)
+ actionStr = "POINTER UP";
+ else if (action == MotionEvent.ACTION_OUTSIDE)
+ actionStr = "OUTSIDE";
+ else if (action == MotionEvent.ACTION_CANCEL)
+ actionStr = "CANCEL";
+ else if (action == MotionEvent.ACTION_MOVE)
+ actionStr = "MOVE";
+ else
+ actionStr = "UNKNOWN (" + action + ")";
Gdx.app.log("AndroidMultiTouchHandler", "action " + actionStr + ", Android pointer id: " + pointer);
}
-
+
private void postTouchEvent (AndroidInput input, int type, int x, int y, int pointer) {
- long timeStamp = System.nanoTime();
+ long timeStamp = System.nanoTime();
TouchEvent event = input.usedTouchEvents.obtain();
event.timeStamp = timeStamp;
event.pointer = pointer;
event.x = x;
event.y = y;
event.type = type;
- input.touchEvents.add(event);
+ input.touchEvents.add(event);
}
public boolean supportsMultitouch (AndroidApplication activity) {
diff --git a/backends/gdx-backend-android/src/com/badlogic/gdx/backends/android/AndroidMusic.java b/backends/gdx-backend-android/src/com/badlogic/gdx/backends/android/AndroidMusic.java
index 5ec243b201d..eed7ab082cf 100644
--- a/backends/gdx-backend-android/src/com/badlogic/gdx/backends/android/AndroidMusic.java
+++ b/backends/gdx-backend-android/src/com/badlogic/gdx/backends/android/AndroidMusic.java
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
+
package com.badlogic.gdx.backends.android;
import java.io.IOException;
@@ -32,34 +33,39 @@ public class AndroidMusic implements Music {
this.player = player;
}
- @Override public void dispose () {
- if(player == null) return;
+ @Override
+ public void dispose () {
+ if (player == null) return;
try {
if (player.isPlaying()) player.stop();
player.release();
- } catch(Throwable t) {
+ } catch (Throwable t) {
Gdx.app.log("AndroidMusic", "error while disposing AndroidMusic instance, non-fatal");
} finally {
player = null;
- synchronized(audio.musics) {
+ synchronized (audio.musics) {
audio.musics.remove(this);
}
}
}
- @Override public boolean isLooping () {
+ @Override
+ public boolean isLooping () {
return player.isLooping();
}
- @Override public boolean isPlaying () {
+ @Override
+ public boolean isPlaying () {
return player.isPlaying();
}
- @Override public void pause () {
+ @Override
+ public void pause () {
if (player.isPlaying()) player.pause();
}
- @Override public void play () {
+ @Override
+ public void play () {
if (player.isPlaying()) return;
try {
@@ -75,19 +81,22 @@ public class AndroidMusic implements Music {
}
}
- @Override public void setLooping (boolean isLooping) {
+ @Override
+ public void setLooping (boolean isLooping) {
player.setLooping(isLooping);
}
- @Override public void setVolume (float volume) {
+ @Override
+ public void setVolume (float volume) {
player.setVolume(volume, volume);
}
- @Override public void stop () {
- if(isPrepared) {
+ @Override
+ public void stop () {
+ if (isPrepared) {
player.seekTo(0);
}
- player.stop();
+ player.stop();
isPrepared = false;
}
diff --git a/backends/gdx-backend-android/src/com/badlogic/gdx/backends/android/AndroidPreferences.java b/backends/gdx-backend-android/src/com/badlogic/gdx/backends/android/AndroidPreferences.java
index ccba6730dd9..e1748458b56 100644
--- a/backends/gdx-backend-android/src/com/badlogic/gdx/backends/android/AndroidPreferences.java
+++ b/backends/gdx-backend-android/src/com/badlogic/gdx/backends/android/AndroidPreferences.java
@@ -13,9 +13,9 @@
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
+
package com.badlogic.gdx.backends.android;
-import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
@@ -26,112 +26,127 @@
public class AndroidPreferences implements Preferences {
SharedPreferences sharedPrefs;
-
- public AndroidPreferences(SharedPreferences preferences) {
+
+ public AndroidPreferences (SharedPreferences preferences) {
this.sharedPrefs = preferences;
}
- @Override public void putBoolean (String key, boolean val) {
+ @Override
+ public void putBoolean (String key, boolean val) {
Editor edit = this.sharedPrefs.edit();
edit.putBoolean(key, val);
edit.commit();
}
- @Override public void putInteger (String key, int val) {
+ @Override
+ public void putInteger (String key, int val) {
Editor edit = this.sharedPrefs.edit();
edit.putInt(key, val);
edit.commit();
}
- @Override public void putLong (String key, long val) {
+ @Override
+ public void putLong (String key, long val) {
Editor edit = this.sharedPrefs.edit();
edit.putLong(key, val);
edit.commit();
}
- @Override public void putFloat (String key, float val) {
+ @Override
+ public void putFloat (String key, float val) {
Editor edit = this.sharedPrefs.edit();
edit.putFloat(key, val);
edit.commit();
}
-
- @Override public void putString(String key, String val) {
+
+ @Override
+ public void putString (String key, String val) {
Editor edit = this.sharedPrefs.edit();
edit.putString(key, val);
edit.commit();
}
- @Override public void put (Map vals) {
+ @Override
+ public void put (Map vals) {
Editor edit = this.sharedPrefs.edit();
- for(Entry val: vals.entrySet()) {
- if(val.getValue() instanceof Boolean)
- putBoolean(val.getKey(), (Boolean)val.getValue());
- if(val.getValue() instanceof Integer)
- putInteger(val.getKey(), (Integer)val.getValue());
- if(val.getValue() instanceof Long)
- putLong(val.getKey(), (Long)val.getValue());
- if(val.getValue() instanceof String)
- putString(val.getKey(), (String)val.getValue());
- if(val.getValue() instanceof Float)
- putFloat(val.getKey(), (Float)val.getValue());
+ for (Entry val : vals.entrySet()) {
+ if (val.getValue() instanceof Boolean) putBoolean(val.getKey(), (Boolean)val.getValue());
+ if (val.getValue() instanceof Integer) putInteger(val.getKey(), (Integer)val.getValue());
+ if (val.getValue() instanceof Long) putLong(val.getKey(), (Long)val.getValue());
+ if (val.getValue() instanceof String) putString(val.getKey(), (String)val.getValue());
+ if (val.getValue() instanceof Float) putFloat(val.getKey(), (Float)val.getValue());
}
edit.commit();
}
- @Override public boolean getBoolean (String key) {
+ @Override
+ public boolean getBoolean (String key) {
return sharedPrefs.getBoolean(key, false);
}
- @Override public int getInteger (String key) {
+ @Override
+ public int getInteger (String key) {
return sharedPrefs.getInt(key, 0);
}
- @Override public long getLong (String key) {
+ @Override
+ public long getLong (String key) {
return sharedPrefs.getLong(key, 0);
}
- @Override public float getFloat (String key) {
+ @Override
+ public float getFloat (String key) {
return sharedPrefs.getFloat(key, 0);
}
- @Override public String getString (String key) {
+ @Override
+ public String getString (String key) {
return sharedPrefs.getString(key, "");
}
- @Override public boolean getBoolean (String key, boolean defValue) {
+ @Override
+ public boolean getBoolean (String key, boolean defValue) {
return sharedPrefs.getBoolean(key, defValue);
}
- @Override public int getInteger (String key, int defValue) {
+ @Override
+ public int getInteger (String key, int defValue) {
return sharedPrefs.getInt(key, defValue);
}
- @Override public long getLong (String key, long defValue) {
+ @Override
+ public long getLong (String key, long defValue) {
return sharedPrefs.getLong(key, defValue);
}
- @Override public float getFloat (String key, float defValue) {
+ @Override
+ public float getFloat (String key, float defValue) {
return sharedPrefs.getFloat(key, defValue);
}
- @Override public String getString (String key, String defValue) {
+ @Override
+ public String getString (String key, String defValue) {
return sharedPrefs.getString(key, defValue);
}
- @Override public Map get () {
- return sharedPrefs.getAll();
+ @Override
+ public Map get () {
+ return sharedPrefs.getAll();
}
- @Override public boolean contains (String key) {
+ @Override
+ public boolean contains (String key) {
return sharedPrefs.contains(key);
}
- @Override public void clear () {
+ @Override
+ public void clear () {
Editor edit = sharedPrefs.edit();
edit.clear();
edit.commit();
}
-
- @Override public void flush () {
+
+ @Override
+ public void flush () {
}
}
diff --git a/backends/gdx-backend-android/src/com/badlogic/gdx/backends/android/AndroidSingleTouchHandler.java b/backends/gdx-backend-android/src/com/badlogic/gdx/backends/android/AndroidSingleTouchHandler.java
index dd41ce486d0..00e1d420d78 100644
--- a/backends/gdx-backend-android/src/com/badlogic/gdx/backends/android/AndroidSingleTouchHandler.java
+++ b/backends/gdx-backend-android/src/com/badlogic/gdx/backends/android/AndroidSingleTouchHandler.java
@@ -13,18 +13,16 @@
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
+
package com.badlogic.gdx.backends.android;
import android.view.MotionEvent;
import com.badlogic.gdx.backends.android.AndroidInput.TouchEvent;
-/**
- * Single touch handler for devices running <= 1.6
- *
- * @author badlogicgames@gmail.com
+/** Single touch handler for devices running <= 1.6
*
- */
+ * @author badlogicgames@gmail.com */
public class AndroidSingleTouchHandler implements AndroidTouchHandler {
public void onTouch (MotionEvent event, AndroidInput input) {
int x = (int)event.getX();
@@ -39,17 +37,17 @@ public void onTouch (MotionEvent event, AndroidInput input) {
input.touched[0] = true;
input.deltaX[0] = 0;
input.deltaY[0] = 0;
- }else if (event.getAction() == MotionEvent.ACTION_MOVE) {
+ } else if (event.getAction() == MotionEvent.ACTION_MOVE) {
postTouchEvent(input, TouchEvent.TOUCH_DRAGGED, x, y, 0);
input.touched[0] = true;
input.deltaX[0] = x - oldX;
input.deltaY[0] = y - oldY;
- }else if (event.getAction() == MotionEvent.ACTION_UP) {
+ } else if (event.getAction() == MotionEvent.ACTION_UP) {
postTouchEvent(input, TouchEvent.TOUCH_UP, x, y, 0);
input.touched[0] = false;
input.deltaX[0] = 0;
input.deltaY[0] = 0;
- }else if (event.getAction() == MotionEvent.ACTION_CANCEL) {
+ } else if (event.getAction() == MotionEvent.ACTION_CANCEL) {
postTouchEvent(input, TouchEvent.TOUCH_UP, x, y, 0);
input.touched[0] = false;
input.deltaX[0] = 0;
@@ -69,7 +67,7 @@ private void postTouchEvent (AndroidInput input, int type, int x, int y, int poi
input.touchEvents.add(event);
}
}
-
+
public boolean supportsMultitouch (AndroidApplication activity) {
return false;
}
diff --git a/backends/gdx-backend-android/src/com/badlogic/gdx/backends/android/AndroidSound.java b/backends/gdx-backend-android/src/com/badlogic/gdx/backends/android/AndroidSound.java
index a146471d1e4..6ee9789a4fc 100644
--- a/backends/gdx-backend-android/src/com/badlogic/gdx/backends/android/AndroidSound.java
+++ b/backends/gdx-backend-android/src/com/badlogic/gdx/backends/android/AndroidSound.java
@@ -34,15 +34,18 @@ final class AndroidSound implements Sound {
this.soundId = soundId;
}
- @Override public void dispose () {
+ @Override
+ public void dispose () {
soundPool.unload(soundId);
}
- @Override public void play () {
+ @Override
+ public void play () {
play(1);
}
- @Override public void play (float volume) {
+ @Override
+ public void play (float volume) {
if (streamIds.size == 8) streamIds.pop();
streamIds.add(soundPool.play(soundId, volume, volume, 1, 0, 1));
}
diff --git a/backends/gdx-backend-android/src/com/badlogic/gdx/backends/android/AndroidTouchHandler.java b/backends/gdx-backend-android/src/com/badlogic/gdx/backends/android/AndroidTouchHandler.java
index 633ffade136..eb9b0771465 100644
--- a/backends/gdx-backend-android/src/com/badlogic/gdx/backends/android/AndroidTouchHandler.java
+++ b/backends/gdx-backend-android/src/com/badlogic/gdx/backends/android/AndroidTouchHandler.java
@@ -13,12 +13,13 @@
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
+
package com.badlogic.gdx.backends.android;
-import android.content.Context;
import android.view.MotionEvent;
public interface AndroidTouchHandler {
public void onTouch (MotionEvent event, AndroidInput input);
- public boolean supportsMultitouch(AndroidApplication app);
+
+ public boolean supportsMultitouch (AndroidApplication app);
}
diff --git a/backends/gdx-backend-android/src/com/badlogic/gdx/backends/android/surfaceview/DefaultGLSurfaceView.java b/backends/gdx-backend-android/src/com/badlogic/gdx/backends/android/surfaceview/DefaultGLSurfaceView.java
index b3f680ca1c2..53591db6e38 100644
--- a/backends/gdx-backend-android/src/com/badlogic/gdx/backends/android/surfaceview/DefaultGLSurfaceView.java
+++ b/backends/gdx-backend-android/src/com/badlogic/gdx/backends/android/surfaceview/DefaultGLSurfaceView.java
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
+
package com.badlogic.gdx.backends.android.surfaceview;
import android.content.Context;
@@ -21,22 +22,21 @@
public class DefaultGLSurfaceView extends GLSurfaceView {
+ final ResolutionStrategy resolutionStrategy;
- final ResolutionStrategy resolutionStrategy;
-
- public DefaultGLSurfaceView(Context context, ResolutionStrategy resolutionStrategy) {
- super(context);
- this.resolutionStrategy = resolutionStrategy;
- }
+ public DefaultGLSurfaceView (Context context, ResolutionStrategy resolutionStrategy) {
+ super(context);
+ this.resolutionStrategy = resolutionStrategy;
+ }
- public DefaultGLSurfaceView(Context context, AttributeSet attrs, ResolutionStrategy resolutionStrategy) {
- super(context, attrs);
- this.resolutionStrategy = resolutionStrategy;
- }
+ public DefaultGLSurfaceView (Context context, AttributeSet attrs, ResolutionStrategy resolutionStrategy) {
+ super(context, attrs);
+ this.resolutionStrategy = resolutionStrategy;
+ }
- @Override
- protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
- ResolutionStrategy.MeasuredDimension measures = resolutionStrategy.calcMeasures(widthMeasureSpec, heightMeasureSpec);
- setMeasuredDimension(measures.width, measures.height);
- }
+ @Override
+ protected void onMeasure (int widthMeasureSpec, int heightMeasureSpec) {
+ ResolutionStrategy.MeasuredDimension measures = resolutionStrategy.calcMeasures(widthMeasureSpec, heightMeasureSpec);
+ setMeasuredDimension(measures.width, measures.height);
+ }
}
diff --git a/backends/gdx-backend-android/src/com/badlogic/gdx/backends/android/surfaceview/FillResolutionStrategy.java b/backends/gdx-backend-android/src/com/badlogic/gdx/backends/android/surfaceview/FillResolutionStrategy.java
index e9cb9f1ca1f..52e3a216b59 100644
--- a/backends/gdx-backend-android/src/com/badlogic/gdx/backends/android/surfaceview/FillResolutionStrategy.java
+++ b/backends/gdx-backend-android/src/com/badlogic/gdx/backends/android/surfaceview/FillResolutionStrategy.java
@@ -15,21 +15,18 @@
import android.view.View;
-/**
- * This {@link ResolutionStrategy} will stretch the GLSurfaceView to full screen.
- * FillResolutionStrategy is the default {@link ResolutionStrategy} if none is specified.
- *
- * @author christoph widulle
- */
+/** This {@link ResolutionStrategy} will stretch the GLSurfaceView to full screen. FillResolutionStrategy is the default
+ * {@link ResolutionStrategy} if none is specified.
+ *
+ * @author christoph widulle */
public class FillResolutionStrategy implements ResolutionStrategy {
+ @Override
+ public MeasuredDimension calcMeasures (int widthMeasureSpec, int heightMeasureSpec) {
- @Override
- public MeasuredDimension calcMeasures(int widthMeasureSpec, int heightMeasureSpec) {
-
- final int width = View.MeasureSpec.getSize(widthMeasureSpec);
- final int height = View.MeasureSpec.getSize(heightMeasureSpec);
+ final int width = View.MeasureSpec.getSize(widthMeasureSpec);
+ final int height = View.MeasureSpec.getSize(heightMeasureSpec);
- return new MeasuredDimension(width, height);
- }
+ return new MeasuredDimension(width, height);
+ }
}
diff --git a/backends/gdx-backend-android/src/com/badlogic/gdx/backends/android/surfaceview/FixedResolutionStrategy.java b/backends/gdx-backend-android/src/com/badlogic/gdx/backends/android/surfaceview/FixedResolutionStrategy.java
index f86ed012b6a..aa84a3d6259 100644
--- a/backends/gdx-backend-android/src/com/badlogic/gdx/backends/android/surfaceview/FixedResolutionStrategy.java
+++ b/backends/gdx-backend-android/src/com/badlogic/gdx/backends/android/surfaceview/FixedResolutionStrategy.java
@@ -13,23 +13,21 @@
package com.badlogic.gdx.backends.android.surfaceview;
-/**
- * This {@link ResolutionStrategy} will place the GLSurfaceView with the given height and width in the center the screen.
- *
- * @author christoph widulle
- */
+/** This {@link ResolutionStrategy} will place the GLSurfaceView with the given height and width in the center the screen.
+ *
+ * @author christoph widulle */
public class FixedResolutionStrategy implements ResolutionStrategy {
- private final int width;
- private final int height;
+ private final int width;
+ private final int height;
- public FixedResolutionStrategy(int width, int height) {
- this.width = width;
- this.height = height;
- }
+ public FixedResolutionStrategy (int width, int height) {
+ this.width = width;
+ this.height = height;
+ }
- @Override
- public MeasuredDimension calcMeasures(int widthMeasureSpec, int heightMeasureSpec) {
- return new MeasuredDimension(width, height);
- }
+ @Override
+ public MeasuredDimension calcMeasures (int widthMeasureSpec, int heightMeasureSpec) {
+ return new MeasuredDimension(width, height);
+ }
}
diff --git a/backends/gdx-backend-android/src/com/badlogic/gdx/backends/android/surfaceview/GLBaseSurfaceView.java b/backends/gdx-backend-android/src/com/badlogic/gdx/backends/android/surfaceview/GLBaseSurfaceView.java
index 4a3587490ef..a59a410519b 100644
--- a/backends/gdx-backend-android/src/com/badlogic/gdx/backends/android/surfaceview/GLBaseSurfaceView.java
+++ b/backends/gdx-backend-android/src/com/badlogic/gdx/backends/android/surfaceview/GLBaseSurfaceView.java
@@ -31,8 +31,7 @@
import android.util.Log;
import android.view.SurfaceHolder;
-/**
- * An implementation of SurfaceView that uses the dedicated surface for displaying OpenGL rendering.
+/** An implementation of SurfaceView that uses the dedicated surface for displaying OpenGL rendering.
*
* A GLSurfaceView provides the following features:
*
@@ -125,59 +124,46 @@
*
*
*
- *
*
- */
+ * */
public class GLBaseSurfaceView extends GLSurfaceView implements SurfaceHolder.Callback {
private final static boolean LOG_THREADS = false;
private final static boolean LOG_SURFACE = false;
private final static boolean LOG_RENDERER = false;
// Work-around for bug 2263168
private final static boolean DRAW_TWICE_AFTER_SIZE_CHANGED = true;
- /**
- * The renderer only renders when the surface is created, or when {@link #requestRender} is called.
+ /** The renderer only renders when the surface is created, or when {@link #requestRender} is called.
*
* @see #getRenderMode()
- * @see #setRenderMode(int)
- */
+ * @see #setRenderMode(int) */
public final static int RENDERMODE_WHEN_DIRTY = 0;
- /**
- * The renderer is called continuously to re-render the scene.
+ /** The renderer is called continuously to re-render the scene.
*
* @see #getRenderMode()
* @see #setRenderMode(int)
- * @see #requestRender()
- */
+ * @see #requestRender() */
public final static int RENDERMODE_CONTINUOUSLY = 1;
- /**
- * Check glError() after every GL call and throw an exception if glError indicates that an error has occurred. This can be used
+ /** Check glError() after every GL call and throw an exception if glError indicates that an error has occurred. This can be used
* to help track down which OpenGL ES call is causing an error.
*
* @see #getDebugFlags
- * @see #setDebugFlags
- */
+ * @see #setDebugFlags */
public final static int DEBUG_CHECK_GL_ERROR = 1;
- /**
- * Log GL calls to the system log at "verbose" level with tag "GLSurfaceView".
+ /** Log GL calls to the system log at "verbose" level with tag "GLSurfaceView".
*
* @see #getDebugFlags
- * @see #setDebugFlags
- */
+ * @see #setDebugFlags */
public final static int DEBUG_LOG_GL_CALLS = 2;
- /**
- * Standard View constructor. In order to render something, you must call {@link #setRenderer} to register a renderer.
- */
+ /** Standard View constructor. In order to render something, you must call {@link #setRenderer} to register a renderer. */
public GLBaseSurfaceView (Context context) {
super(context);
init();
}
- /**
- * Standard View constructor. In order to render something, you must call {@link #setRenderer} to register a renderer.
- */
+ /** Standard View constructor. In order to render something, you must call {@link #setRenderer} to register a renderer. */
public GLBaseSurfaceView (Context context, AttributeSet attrs) {
super(context, attrs);
init();
@@ -190,41 +176,34 @@ private void init () {
holder.addCallback(this);
}
- /**
- * Set the glWrapper. If the glWrapper is not null, its {@link GLWrapper#wrap(GL)} method is called whenever a surface is
+ /** Set the glWrapper. If the glWrapper is not null, its {@link GLWrapper#wrap(GL)} method is called whenever a surface is
* created. A GLWrapper can be used to wrap the GL object that's passed to the renderer. Wrapping a GL object enables examining
* and modifying the behavior of the GL calls made by the renderer.
*
* Wrapping is typically used for debugging purposes.
*
* The default value is null.
- * @param glWrapper the new GLWrapper
- */
+ * @param glWrapper the new GLWrapper */
public void setGLWrapper (GLWrapper glWrapper) {
mGLWrapper = glWrapper;
}
- /**
- * Set the debug flags to a new value. The value is constructed by OR-together zero or more of the DEBUG_CHECK_* constants. The
+ /** Set the debug flags to a new value. The value is constructed by OR-together zero or more of the DEBUG_CHECK_* constants. The
* debug flags take effect whenever a surface is created. The default value is zero.
* @param debugFlags the new debug flags
* @see #DEBUG_CHECK_GL_ERROR
- * @see #DEBUG_LOG_GL_CALLS
- */
+ * @see #DEBUG_LOG_GL_CALLS */
public void setDebugFlags (int debugFlags) {
mDebugFlags = debugFlags;
}
- /**
- * Get the current value of the debug flags.
- * @return the current value of the debug flags.
- */
+ /** Get the current value of the debug flags.
+ * @return the current value of the debug flags. */
public int getDebugFlags () {
return mDebugFlags;
}
- /**
- * Set the renderer associated with this view. Also starts the thread that will call the renderer, which in turn causes the
+ /** Set the renderer associated with this view. Also starts the thread that will call the renderer, which in turn causes the
* rendering to start.
*
* This method should be called once and only once in the life-cycle of a GLSurfaceView.
@@ -246,8 +225,7 @@ public int getDebugFlags () {
*
{@link #setRenderMode(int)}
*
*
- * @param renderer the renderer to use to perform OpenGL drawing.
- */
+ * @param renderer the renderer to use to perform OpenGL drawing. */
public void setRenderer (Renderer renderer) {
checkRenderThreadState();
if (mEGLConfigChooser == null) {
@@ -263,47 +241,40 @@ public void setRenderer (Renderer renderer) {
mGLThread.start();
}
- /**
- * Install a custom EGLContextFactory.
+ /** Install a custom EGLContextFactory.
*
* If this method is called, it must be called before {@link #setRenderer(Renderer)} is called.
*
* If this method is not called, then by default a context will be created with no shared context and with a null attribute
- * list.
- */
+ * list. */
public void setEGLContextFactory (EGLContextFactory factory) {
checkRenderThreadState();
mEGLContextFactory = factory;
}
- /**
- * Install a custom EGLWindowSurfaceFactory.
+ /** Install a custom EGLWindowSurfaceFactory.
*
* If this method is called, it must be called before {@link #setRenderer(Renderer)} is called.
*
- * If this method is not called, then by default a window surface will be created with a null attribute list.
- */
+ * If this method is not called, then by default a window surface will be created with a null attribute list. */
public void setEGLWindowSurfaceFactory (EGLWindowSurfaceFactory factory) {
checkRenderThreadState();
mEGLWindowSurfaceFactory = factory;
}
- /**
- * Install a custom EGLConfigChooser.
+ /** Install a custom EGLConfigChooser.
*
* If this method is called, it must be called before {@link #setRenderer(Renderer)} is called.
*
* If no setEGLConfigChooser method is called, then by default the view will choose a config as close to 16-bit RGB as
* possible, with a depth buffer as close to 16 bits as possible.
- * @param configChooser
- */
+ * @param configChooser */
public void setEGLConfigChooser (EGLConfigChooser configChooser) {
checkRenderThreadState();
mEGLConfigChooser = configChooser;
}
- /**
- * Install a config chooser which will choose a config as close to 16-bit RGB as possible, with or without an optional depth
+ /** Install a config chooser which will choose a config as close to 16-bit RGB as possible, with or without an optional depth
* buffer as close to 16-bits as possible.
*
* If this method is called, it must be called before {@link #setRenderer(Renderer)} is called.
@@ -311,28 +282,23 @@ public void setEGLConfigChooser (EGLConfigChooser configChooser) {
* If no setEGLConfigChooser method is called, then by default the view will choose a config as close to 16-bit RGB as
* possible, with a depth buffer as close to 16 bits as possible.
*
- * @param needDepth
- */
+ * @param needDepth */
public void setEGLConfigChooser (boolean needDepth) {
setEGLConfigChooser(new SimpleEGLConfigChooser(needDepth));
}
- /**
- * Install a config chooser which will choose a config with at least the specified component sizes, and as close to the
+ /** Install a config chooser which will choose a config with at least the specified component sizes, and as close to the
* specified component sizes as possible.
*
* If this method is called, it must be called before {@link #setRenderer(Renderer)} is called.
*
* If no setEGLConfigChooser method is called, then by default the view will choose a config as close to 16-bit RGB as
- * possible, with a depth buffer as close to 16 bits as possible.
- *
- */
+ * possible, with a depth buffer as close to 16 bits as possible. */
public void setEGLConfigChooser (int redSize, int greenSize, int blueSize, int alphaSize, int depthSize, int stencilSize) {
setEGLConfigChooser(new ComponentSizeChooser(redSize, greenSize, blueSize, alphaSize, depthSize, stencilSize));
}
- /**
- * Set the rendering mode. When renderMode is RENDERMODE_CONTINUOUSLY, the renderer is called repeatedly to re-render the
+ /** Set the rendering mode. When renderMode is RENDERMODE_CONTINUOUSLY, the renderer is called repeatedly to re-render the
* scene. When renderMode is RENDERMODE_WHEN_DIRTY, the renderer only rendered when the surface is created, or when
* {@link #requestRender} is called. Defaults to RENDERMODE_CONTINUOUSLY.
*
@@ -343,95 +309,76 @@ public void setEGLConfigChooser (int redSize, int greenSize, int blueSize, int a
*
* @param renderMode one of the RENDERMODE_X constants
* @see #RENDERMODE_CONTINUOUSLY
- * @see #RENDERMODE_WHEN_DIRTY
- */
+ * @see #RENDERMODE_WHEN_DIRTY */
public void setRenderMode (int renderMode) {
mGLThread.setRenderMode(renderMode);
}
- /**
- * Get the current rendering mode. May be called from any thread. Must not be called before a renderer has been set.
+ /** Get the current rendering mode. May be called from any thread. Must not be called before a renderer has been set.
* @return the current rendering mode.
* @see #RENDERMODE_CONTINUOUSLY
- * @see #RENDERMODE_WHEN_DIRTY
- */
+ * @see #RENDERMODE_WHEN_DIRTY */
public int getRenderMode () {
return mGLThread.getRenderMode();
}
- /**
- * Request that the renderer render a frame. This method is typically used when the render mode has been set to
+ /** Request that the renderer render a frame. This method is typically used when the render mode has been set to
* {@link #RENDERMODE_WHEN_DIRTY}, so that frames are only rendered on demand. May be called from any thread. Must not be
- * called before a renderer has been set.
- */
+ * called before a renderer has been set. */
public void requestRender () {
mGLThread.requestRender();
}
- /**
- * This method is part of the SurfaceHolder.Callback interface, and is not normally called or subclassed by clients of
- * GLSurfaceView.
- */
+ /** This method is part of the SurfaceHolder.Callback interface, and is not normally called or subclassed by clients of
+ * GLSurfaceView. */
public void surfaceCreated (SurfaceHolder holder) {
mGLThread.surfaceCreated();
}
- /**
- * This method is part of the SurfaceHolder.Callback interface, and is not normally called or subclassed by clients of
- * GLSurfaceView.
- */
+ /** This method is part of the SurfaceHolder.Callback interface, and is not normally called or subclassed by clients of
+ * GLSurfaceView. */
public void surfaceDestroyed (SurfaceHolder holder) {
// Surface will be destroyed when we return
mGLThread.surfaceDestroyed();
}
- /**
- * This method is part of the SurfaceHolder.Callback interface, and is not normally called or subclassed by clients of
- * GLSurfaceView.
- */
+ /** This method is part of the SurfaceHolder.Callback interface, and is not normally called or subclassed by clients of
+ * GLSurfaceView. */
public void surfaceChanged (SurfaceHolder holder, int format, int w, int h) {
mGLThread.onWindowResize(w, h);
}
- /**
- * Inform the view that the activity is paused. The owner of this view must call this method when the activity is paused.
- * Calling this method will pause the rendering thread. Must not be called before a renderer has been set.
- */
+ /** Inform the view that the activity is paused. The owner of this view must call this method when the activity is paused.
+ * Calling this method will pause the rendering thread. Must not be called before a renderer has been set. */
public void onPause () {
mGLThread.onPause();
}
- /**
- * Inform the view that the activity is resumed. The owner of this view must call this method when the activity is resumed.
+ /** Inform the view that the activity is resumed. The owner of this view must call this method when the activity is resumed.
* Calling this method will recreate the OpenGL display and resume the rendering thread. Must not be called before a renderer
- * has been set.
- */
+ * has been set. */
public void onResume () {
mGLThread.onResume();
}
- /**
- * Queue a runnable to be run on the GL rendering thread. This can be used to communicate with the Renderer on the rendering
+ /** Queue a runnable to be run on the GL rendering thread. This can be used to communicate with the Renderer on the rendering
* thread. Must not be called before a renderer has been set.
- * @param r the runnable to be run on the GL rendering thread.
- */
+ * @param r the runnable to be run on the GL rendering thread. */
public void queueEvent (Runnable r) {
mGLThread.queueEvent(r);
}
- /**
- * This method is used as part of the View class and is not normally called or subclassed by clients of GLSurfaceView. Must not
- * be called before a renderer has been set.
- */
- @Override protected void onDetachedFromWindow () {
+ /** This method is used as part of the View class and is not normally called or subclassed by clients of GLSurfaceView. Must not
+ * be called before a renderer has been set. */
+ @Override
+ protected void onDetachedFromWindow () {
super.onDetachedFromWindow();
mGLThread.requestExitAndWait();
}
// ----------------------------------------------------------------------
- /**
- * An interface used to wrap a GL interface.
+ /** An interface used to wrap a GL interface.
*
* Typically used for implementing debugging and tracing on top of the default GL interface. You would typically use this by
* creating your own class that implemented all the GL methods by delegating to another GL instance. Then you could add your
@@ -448,23 +395,18 @@ public void queueEvent (Runnable r) {
* }
* }
*
- * @see #setGLWrapper(GLWrapper)
- */
+ * @see #setGLWrapper(GLWrapper) */
public interface GLWrapper {
- /**
- * Wraps a gl interface in another gl interface.
+ /** Wraps a gl interface in another gl interface.
* @param gl a GL interface that is to be wrapped.
- * @return either the input argument or another GL object that wraps the input argument.
- */
+ * @return either the input argument or another GL object that wraps the input argument. */
GL wrap (GL gl);
}
- /**
- * An interface for customizing the eglCreateContext and eglDestroyContext calls.
+ /** An interface for customizing the eglCreateContext and eglDestroyContext calls.
*
* This interface must be implemented by clients wishing to call
- * {@link GLBaseSurfaceView#setEGLContextFactory(EGLContextFactory)}
- */
+ * {@link GLBaseSurfaceView#setEGLContextFactory(EGLContextFactory)} */
public interface EGLContextFactory {
EGLContext createContext (EGL10 egl, EGLDisplay display, EGLConfig eglConfig);
@@ -482,12 +424,10 @@ public void destroyContext (EGL10 egl, EGLDisplay display, EGLContext context) {
}
}
- /**
- * An interface for customizing the eglCreateWindowSurface and eglDestroySurface calls.
+ /** An interface for customizing the eglCreateWindowSurface and eglDestroySurface calls.
*
* This interface must be implemented by clients wishing to call
- * {@link GLBaseSurfaceView#setEGLWindowSurfaceFactory(EGLWindowSurfaceFactory)}
- */
+ * {@link GLBaseSurfaceView#setEGLWindowSurfaceFactory(EGLWindowSurfaceFactory)} */
public interface EGLWindowSurfaceFactory {
EGLSurface createWindowSurface (EGL10 egl, EGLDisplay display, EGLConfig config, Object nativeWindow);
@@ -549,7 +489,8 @@ public ComponentSizeChooser (int redSize, int greenSize, int blueSize, int alpha
mStencilSize = stencilSize;
}
- @Override public EGLConfig chooseConfig (EGL10 egl, EGLDisplay display, EGLConfig[] configs) {
+ @Override
+ public EGLConfig chooseConfig (EGL10 egl, EGLDisplay display, EGLConfig[] configs) {
EGLConfig closestConfig = null;
int closestDistance = 1000;
for (EGLConfig config : configs) {
@@ -589,10 +530,7 @@ private int findConfigAttrib (EGL10 egl, EGLDisplay display, EGLConfig config, i
protected int mStencilSize;
}
- /**
- * This class will choose a supported surface as close to RGB565 as possible, with or without a depth buffer.
- *
- */
+ /** This class will choose a supported surface as close to RGB565 as possible, with or without a depth buffer. */
private static class SimpleEGLConfigChooser extends ComponentSizeChooser {
public SimpleEGLConfigChooser (boolean withDepthBuffer) {
super(4, 4, 4, 0, withDepthBuffer ? 16 : 0, 0);
@@ -604,18 +542,14 @@ public SimpleEGLConfigChooser (boolean withDepthBuffer) {
}
}
- /**
- * An EGL helper class.
- */
+ /** An EGL helper class. */
private class EglHelper {
public EglHelper () {
}
- /**
- * Initialize EGL for a given configuration spec.
- */
+ /** Initialize EGL for a given configuration spec. */
public void start () {
/*
* Get an EGL instance
@@ -696,10 +630,8 @@ public GL createSurface (SurfaceHolder holder) {
return gl;
}
- /**
- * Display the current render surface.
- * @return false if the context has been lost.
- */
+ /** Display the current render surface.
+ * @return false if the context has been lost. */
public boolean swap () {
mEgl.eglSwapBuffers(mEglDisplay, mEglSurface);
@@ -740,14 +672,11 @@ private void throwEglException (String function) {
EGLContext mEglContext;
}
- /**
- * A generic GL Thread. Takes care of initializing EGL and GL. Delegates to a Renderer instance to do the actual drawing. Can
+ /** A generic GL Thread. Takes care of initializing EGL and GL. Delegates to a Renderer instance to do the actual drawing. Can
* be configured to render continuously or on request.
*
* All potentially blocking synchronization is done through the sGLThreadManager object. This avoids multiple-lock ordering
- * issues.
- *
- */
+ * issues. */
class GLThread extends Thread {
GLThread (Renderer renderer) {
super();
@@ -758,7 +687,8 @@ class GLThread extends Thread {
mRenderer = renderer;
}
- @Override public void run () {
+ @Override
+ public void run () {
setName("GLThread " + getId());
if (LOG_THREADS) {
Log.i("GLThread", "starting tid=" + getId());
@@ -1040,10 +970,8 @@ public void requestExitAndWait () {
}
}
- /**
- * Queue an "event" to be run on the GL rendering thread.
- * @param r the runnable to be run on the GL rendering thread.
- */
+ /** Queue an "event" to be run on the GL rendering thread.
+ * @param r the runnable to be run on the GL rendering thread. */
public void queueEvent (Runnable r) {
if (r == null) {
throw new IllegalArgumentException("r must not be null");
@@ -1076,15 +1004,18 @@ public void queueEvent (Runnable r) {
static class LogWriter extends Writer {
- @Override public void close () {
+ @Override
+ public void close () {
flushBuilder();
}
- @Override public void flush () {
+ @Override
+ public void flush () {
flushBuilder();
}
- @Override public void write (char[] buf, int offset, int count) {
+ @Override
+ public void write (char[] buf, int offset, int count) {
for (int i = 0; i < count; i++) {
char c = buf[offset + i];
if (c == '\n') {
diff --git a/backends/gdx-backend-android/src/com/badlogic/gdx/backends/android/surfaceview/GLDebugHelper.java b/backends/gdx-backend-android/src/com/badlogic/gdx/backends/android/surfaceview/GLDebugHelper.java
index 73050b2ac79..8ce82ed2a3b 100644
--- a/backends/gdx-backend-android/src/com/badlogic/gdx/backends/android/surfaceview/GLDebugHelper.java
+++ b/backends/gdx-backend-android/src/com/badlogic/gdx/backends/android/surfaceview/GLDebugHelper.java
@@ -18,16 +18,12 @@
import javax.microedition.khronos.egl.EGL;
import javax.microedition.khronos.opengles.GL;
-/**
- * A helper class for debugging OpenGL ES applications.
+/** A helper class for debugging OpenGL ES applications.
*
- * Wraps the supplied GL interface with a new GL interface that adds support for error checking and logging.
- *
- */
+ * Wraps the supplied GL interface with a new GL interface that adds support for error checking and logging. */
public class GLDebugHelper {
- /**
- * Wrap an existing GL interface in a new GL interface that adds support for error checking and/or logging.
+ /** Wrap an existing GL interface in a new GL interface that adds support for error checking and/or logging.
*
* Wrapping means that the GL instance that is passed in to this method is wrapped inside a new GL instance that optionally
* performs additional operations before and after calling the wrapped GL instance.
@@ -41,28 +37,19 @@ public class GLDebugHelper {
* @param gl the existing GL interface. Must implement GL and GL10. May optionally implement GL11 as well.
* @param configFlags A bitmask of error checking flags.
* @param log - null to disable logging, non-null to enable logging.
- * @return the wrapped GL instance.
- */
+ * @return the wrapped GL instance. */
- /**
- * Check glError() after every call.
- */
+ /** Check glError() after every call. */
public static final int CONFIG_CHECK_GL_ERROR = (1 << 0);
- /**
- * Check if all calls are on the same thread.
- */
+ /** Check if all calls are on the same thread. */
public static final int CONFIG_CHECK_THREAD = (1 << 1);
- /**
- * Print argument names when logging GL Calls.
- */
+ /** Print argument names when logging GL Calls. */
public static final int CONFIG_LOG_ARGUMENT_NAMES = (1 << 2);
- /**
- * The Error number used in the GLException that is thrown if CONFIG_CHECK_THREAD is enabled and you call OpenGL ES on the a
- * different thread.
- */
+ /** The Error number used in the GLException that is thrown if CONFIG_CHECK_THREAD is enabled and you call OpenGL ES on the a
+ * different thread. */
public static final int ERROR_WRONG_THREAD = 0x7000;
public static GL wrap (GL gl, int configFlags, Writer log) {
@@ -76,13 +63,11 @@ public static GL wrap (GL gl, int configFlags, Writer log) {
return gl;
}
- /**
- * Wrap an existing EGL interface in a new EGL interface that adds support for error checking and/or logging.
+ /** Wrap an existing EGL interface in a new EGL interface that adds support for error checking and/or logging.
* @param egl the existing GL interface. Must implement EGL and EGL10. May optionally implement EGL11 as well.
* @param configFlags A bitmask of error checking flags.
* @param log - null to disable logging, non-null to enable logging.
- * @return the wrapped EGL interface.
- */
+ * @return the wrapped EGL interface. */
public static EGL wrap (EGL egl, int configFlags, Writer log) {
if (log != null) {
egl = new EGLLogWrapper(egl, configFlags, log);
diff --git a/backends/gdx-backend-android/src/com/badlogic/gdx/backends/android/surfaceview/GLErrorWrapper.java b/backends/gdx-backend-android/src/com/badlogic/gdx/backends/android/surfaceview/GLErrorWrapper.java
index 77affb55f88..933a96ae6ec 100644
--- a/backends/gdx-backend-android/src/com/badlogic/gdx/backends/android/surfaceview/GLErrorWrapper.java
+++ b/backends/gdx-backend-android/src/com/badlogic/gdx/backends/android/surfaceview/GLErrorWrapper.java
@@ -20,11 +20,9 @@
import javax.microedition.khronos.opengles.GL;
-/**
- * Implement an error checking wrapper. The wrapper will automatically call glError after each GL operation, and throw a
+/** Implement an error checking wrapper. The wrapper will automatically call glError after each GL operation, and throw a
* GLException if an error occurs. (By design, calling glError itself will not cause an exception to be thrown.) Enabling error
- * checking is an alternative to manually calling glError after every GL operation.
- */
+ * checking is an alternative to manually calling glError after every GL operation. */
class GLErrorWrapper extends GLWrapperBase {
boolean mCheckError;
boolean mCheckThread;
diff --git a/backends/gdx-backend-android/src/com/badlogic/gdx/backends/android/surfaceview/GLException.java b/backends/gdx-backend-android/src/com/badlogic/gdx/backends/android/surfaceview/GLException.java
index cad8f8c5c5c..8fced7fe070 100644
--- a/backends/gdx-backend-android/src/com/badlogic/gdx/backends/android/surfaceview/GLException.java
+++ b/backends/gdx-backend-android/src/com/badlogic/gdx/backends/android/surfaceview/GLException.java
@@ -15,11 +15,9 @@
import android.opengl.GLU;
-/**
- * An exception class for OpenGL errors.
- *
- */
-@SuppressWarnings("serial") public class GLException extends RuntimeException {
+/** An exception class for OpenGL errors. */
+@SuppressWarnings("serial")
+public class GLException extends RuntimeException {
public GLException (final int error) {
super(getErrorString(error));
mError = error;
diff --git a/backends/gdx-backend-android/src/com/badlogic/gdx/backends/android/surfaceview/GLLogWrapper.java b/backends/gdx-backend-android/src/com/badlogic/gdx/backends/android/surfaceview/GLLogWrapper.java
index d929305735c..64a2ba39d2b 100644
--- a/backends/gdx-backend-android/src/com/badlogic/gdx/backends/android/surfaceview/GLLogWrapper.java
+++ b/backends/gdx-backend-android/src/com/badlogic/gdx/backends/android/surfaceview/GLLogWrapper.java
@@ -28,10 +28,7 @@
import javax.microedition.khronos.opengles.GL;
-/**
- * A wrapper that logs all GL calls (and results) in human-readable form.
- *
- */
+/** A wrapper that logs all GL calls (and results) in human-readable form. */
class GLLogWrapper extends GLWrapperBase {
private static final int FORMAT_INT = 0;
private static final int FORMAT_FLOAT = 1;
@@ -682,7 +679,7 @@ private int getIntegerStateSize (int pname) {
case GL_BLUE_BITS:
return 1;
case GL_COMPRESSED_TEXTURE_FORMATS:
- // Have to ask the implementation for the size
+ // Have to ask the implementation for the size
{
int[] buffer = new int[1];
mgl.glGetIntegerv(GL_NUM_COMPRESSED_TEXTURE_FORMATS, buffer, 0);
@@ -2954,17 +2951,11 @@ public void glTexParameterxv (int target, int pname, IntBuffer params) {
}
private class PointerInfo {
- /**
- * The number of coordinates per vertex. 1..4
- */
+ /** The number of coordinates per vertex. 1..4 */
public int mSize;
- /**
- * The type of each coordinate.
- */
+ /** The type of each coordinate. */
public int mType;
- /**
- * The byte offset between consecutive vertices. 0 means mSize * sizeof(mType)
- */
+ /** The byte offset between consecutive vertices. 0 means mSize * sizeof(mType) */
public int mStride;
public Buffer mPointer;
public ByteBuffer mTempByteBuffer; // Only valid during glDrawXXX calls
diff --git a/backends/gdx-backend-android/src/com/badlogic/gdx/backends/android/surfaceview/GLSurfaceView20.java b/backends/gdx-backend-android/src/com/badlogic/gdx/backends/android/surfaceview/GLSurfaceView20.java
index 7e627b8d1e6..129294449be 100644
--- a/backends/gdx-backend-android/src/com/badlogic/gdx/backends/android/surfaceview/GLSurfaceView20.java
+++ b/backends/gdx-backend-android/src/com/badlogic/gdx/backends/android/surfaceview/GLSurfaceView20.java
@@ -26,18 +26,17 @@
* governing permissions and limitations under the License.
*/
-import android.content.Context;
-import android.graphics.PixelFormat;
-import android.opengl.GLSurfaceView;
-import android.util.Log;
-
import javax.microedition.khronos.egl.EGL10;
import javax.microedition.khronos.egl.EGLConfig;
import javax.microedition.khronos.egl.EGLContext;
import javax.microedition.khronos.egl.EGLDisplay;
-/**
- * A simple GLSurfaceView sub-class that demonstrate how to perform OpenGL ES 2.0 rendering into a GL Surface. Note the following
+import android.content.Context;
+import android.graphics.PixelFormat;
+import android.opengl.GLSurfaceView;
+import android.util.Log;
+
+/** A simple GLSurfaceView sub-class that demonstrate how to perform OpenGL ES 2.0 rendering into a GL Surface. Note the following
* important details:
*
* - The class must use a custom context factory to enable 2.0 rendering. See ContextFactory class definition below.
@@ -47,209 +46,207 @@
* flag set. See ConfigChooser class definition below.
*
* - The class must select the surface's format, then choose an EGLConfig that matches it exactly (with regards to
- * red/green/blue/alpha channels bit depths). Failure to do so would result in an EGL_BAD_MATCH error.
- */
+ * red/green/blue/alpha channels bit depths). Failure to do so would result in an EGL_BAD_MATCH error. */
public class GLSurfaceView20 extends GLSurfaceView {
- static String TAG = "GL2JNIView";
- private static final boolean DEBUG = false;
-
- final ResolutionStrategy resolutionStrategy;
-
- public GLSurfaceView20(Context context, ResolutionStrategy resolutionStrategy) {
- super(context);
- this.resolutionStrategy = resolutionStrategy;
- init(false, 16, 0);
- }
-
- public GLSurfaceView20(Context context, boolean translucent, int depth, int stencil, ResolutionStrategy resolutionStrategy) {
- super(context);
- this.resolutionStrategy = resolutionStrategy;
- init(translucent, depth, stencil);
-
- }
-
- @Override
- protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
- ResolutionStrategy.MeasuredDimension measures = resolutionStrategy.calcMeasures(widthMeasureSpec, heightMeasureSpec);
- setMeasuredDimension(measures.width, measures.height);
- }
-
- private void init(boolean translucent, int depth, int stencil) {
-
- /*
- * By default, GLSurfaceView() creates a RGB_565 opaque surface. If we want a translucent one, we should change the
- * surface's format here, using PixelFormat.TRANSLUCENT for GL Surfaces is interpreted as any 32-bit surface with alpha by
- * SurfaceFlinger.
- */
- if (translucent) {
- this.getHolder().setFormat(PixelFormat.TRANSLUCENT);
- }
-
- /*
- * Setup the context factory for 2.0 rendering. See ContextFactory class definition below
- */
- setEGLContextFactory(new ContextFactory());
-
- /*
- * We need to choose an EGLConfig that matches the format of our surface exactly. This is going to be done in our custom
- * config chooser. See ConfigChooser class definition below.
- */
- setEGLConfigChooser(translucent ? new ConfigChooser(8, 8, 8, 8, depth, stencil) : new ConfigChooser(5, 6, 5, 0, depth,
- stencil));
-
- /* Set the renderer responsible for frame rendering */
- }
-
-
- static class ContextFactory implements GLSurfaceView.EGLContextFactory {
- private static int EGL_CONTEXT_CLIENT_VERSION = 0x3098;
-
- public EGLContext createContext(EGL10 egl, EGLDisplay display, EGLConfig eglConfig) {
- Log.w(TAG, "creating OpenGL ES 2.0 context");
- checkEglError("Before eglCreateContext", egl);
- int[] attrib_list = {EGL_CONTEXT_CLIENT_VERSION, 2, EGL10.EGL_NONE};
- EGLContext context = egl.eglCreateContext(display, eglConfig, EGL10.EGL_NO_CONTEXT, attrib_list);
- checkEglError("After eglCreateContext", egl);
- return context;
- }
-
- public void destroyContext(EGL10 egl, EGLDisplay display, EGLContext context) {
- egl.eglDestroyContext(display, context);
- }
- }
-
- static void checkEglError(String prompt, EGL10 egl) {
- int error;
- while ((error = egl.eglGetError()) != EGL10.EGL_SUCCESS) {
- Log.e(TAG, String.format("%s: EGL error: 0x%x", prompt, error));
- }
- }
-
- private static class ConfigChooser implements GLSurfaceView.EGLConfigChooser {
-
- public ConfigChooser(int r, int g, int b, int a, int depth, int stencil) {
- mRedSize = r;
- mGreenSize = g;
- mBlueSize = b;
- mAlphaSize = a;
- mDepthSize = depth;
- mStencilSize = stencil;
- }
-
- /*
- * This EGL config specification is used to specify 2.0 rendering. We use a minimum size of 4 bits for red/green/blue, but
- * will perform actual matching in chooseConfig() below.
- */
- private static int EGL_OPENGL_ES2_BIT = 4;
- private static int[] s_configAttribs2 = {EGL10.EGL_RED_SIZE, 4, EGL10.EGL_GREEN_SIZE, 4, EGL10.EGL_BLUE_SIZE, 4,
- EGL10.EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, EGL10.EGL_NONE};
-
- public EGLConfig chooseConfig(EGL10 egl, EGLDisplay display) {
-
- /*
- * Get the number of minimally matching EGL configurations
- */
- int[] num_config = new int[1];
- egl.eglChooseConfig(display, s_configAttribs2, null, 0, num_config);
-
- int numConfigs = num_config[0];
-
- if (numConfigs <= 0) {
- throw new IllegalArgumentException("No configs match configSpec");
- }
-
- /*
- * Allocate then read the array of minimally matching EGL configs
- */
- EGLConfig[] configs = new EGLConfig[numConfigs];
- egl.eglChooseConfig(display, s_configAttribs2, configs, numConfigs, num_config);
-
- if (DEBUG) {
- printConfigs(egl, display, configs);
- }
- /*
- * Now return the "best" one
- */
- return chooseConfig(egl, display, configs);
- }
-
- public EGLConfig chooseConfig(EGL10 egl, EGLDisplay display, EGLConfig[] configs) {
- for (EGLConfig config : configs) {
- int d = findConfigAttrib(egl, display, config, EGL10.EGL_DEPTH_SIZE, 0);
- int s = findConfigAttrib(egl, display, config, EGL10.EGL_STENCIL_SIZE, 0);
-
- // We need at least mDepthSize and mStencilSize bits
- if (d < mDepthSize || s < mStencilSize) continue;
-
- // We want an *exact* match for red/green/blue/alpha
- int r = findConfigAttrib(egl, display, config, EGL10.EGL_RED_SIZE, 0);
- int g = findConfigAttrib(egl, display, config, EGL10.EGL_GREEN_SIZE, 0);
- int b = findConfigAttrib(egl, display, config, EGL10.EGL_BLUE_SIZE, 0);
- int a = findConfigAttrib(egl, display, config, EGL10.EGL_ALPHA_SIZE, 0);
-
- if (r == mRedSize && g == mGreenSize && b == mBlueSize && a == mAlphaSize) return config;
- }
- return null;
- }
-
- private int findConfigAttrib(EGL10 egl, EGLDisplay display, EGLConfig config, int attribute, int defaultValue) {
-
- if (egl.eglGetConfigAttrib(display, config, attribute, mValue)) {
- return mValue[0];
- }
- return defaultValue;
- }
-
- private void printConfigs(EGL10 egl, EGLDisplay display, EGLConfig[] configs) {
- int numConfigs = configs.length;
- Log.w(TAG, String.format("%d configurations", numConfigs));
- for (int i = 0; i < numConfigs; i++) {
- Log.w(TAG, String.format("Configuration %d:\n", i));
- printConfig(egl, display, configs[i]);
- }
- }
-
- private void printConfig(EGL10 egl, EGLDisplay display, EGLConfig config) {
- int[] attributes = {EGL10.EGL_BUFFER_SIZE, EGL10.EGL_ALPHA_SIZE, EGL10.EGL_BLUE_SIZE, EGL10.EGL_GREEN_SIZE,
- EGL10.EGL_RED_SIZE, EGL10.EGL_DEPTH_SIZE, EGL10.EGL_STENCIL_SIZE, EGL10.EGL_CONFIG_CAVEAT, EGL10.EGL_CONFIG_ID,
- EGL10.EGL_LEVEL, EGL10.EGL_MAX_PBUFFER_HEIGHT, EGL10.EGL_MAX_PBUFFER_PIXELS, EGL10.EGL_MAX_PBUFFER_WIDTH,
- EGL10.EGL_NATIVE_RENDERABLE, EGL10.EGL_NATIVE_VISUAL_ID, EGL10.EGL_NATIVE_VISUAL_TYPE,
- 0x3030, // EGL10.EGL_PRESERVED_RESOURCES,
- EGL10.EGL_SAMPLES, EGL10.EGL_SAMPLE_BUFFERS, EGL10.EGL_SURFACE_TYPE, EGL10.EGL_TRANSPARENT_TYPE,
- EGL10.EGL_TRANSPARENT_RED_VALUE, EGL10.EGL_TRANSPARENT_GREEN_VALUE, EGL10.EGL_TRANSPARENT_BLUE_VALUE, 0x3039, // EGL10.EGL_BIND_TO_TEXTURE_RGB,
- 0x303A, // EGL10.EGL_BIND_TO_TEXTURE_RGBA,
- 0x303B, // EGL10.EGL_MIN_SWAP_INTERVAL,
- 0x303C, // EGL10.EGL_MAX_SWAP_INTERVAL,
- EGL10.EGL_LUMINANCE_SIZE, EGL10.EGL_ALPHA_MASK_SIZE, EGL10.EGL_COLOR_BUFFER_TYPE, EGL10.EGL_RENDERABLE_TYPE, 0x3042 // EGL10.EGL_CONFORMANT
- };
- String[] names = {"EGL_BUFFER_SIZE", "EGL_ALPHA_SIZE", "EGL_BLUE_SIZE", "EGL_GREEN_SIZE", "EGL_RED_SIZE",
- "EGL_DEPTH_SIZE", "EGL_STENCIL_SIZE", "EGL_CONFIG_CAVEAT", "EGL_CONFIG_ID", "EGL_LEVEL", "EGL_MAX_PBUFFER_HEIGHT",
- "EGL_MAX_PBUFFER_PIXELS", "EGL_MAX_PBUFFER_WIDTH", "EGL_NATIVE_RENDERABLE", "EGL_NATIVE_VISUAL_ID",
- "EGL_NATIVE_VISUAL_TYPE", "EGL_PRESERVED_RESOURCES", "EGL_SAMPLES", "EGL_SAMPLE_BUFFERS", "EGL_SURFACE_TYPE",
- "EGL_TRANSPARENT_TYPE", "EGL_TRANSPARENT_RED_VALUE", "EGL_TRANSPARENT_GREEN_VALUE", "EGL_TRANSPARENT_BLUE_VALUE",
- "EGL_BIND_TO_TEXTURE_RGB", "EGL_BIND_TO_TEXTURE_RGBA", "EGL_MIN_SWAP_INTERVAL", "EGL_MAX_SWAP_INTERVAL",
- "EGL_LUMINANCE_SIZE", "EGL_ALPHA_MASK_SIZE", "EGL_COLOR_BUFFER_TYPE", "EGL_RENDERABLE_TYPE", "EGL_CONFORMANT"};
- int[] value = new int[1];
- for (int i = 0; i < attributes.length; i++) {
- int attribute = attributes[i];
- String name = names[i];
- if (egl.eglGetConfigAttrib(display, config, attribute, value)) {
- Log.w(TAG, String.format(" %s: %d\n", name, value[0]));
- } else {
- // Log.w(TAG, String.format(" %s: failed\n", name));
- while (egl.eglGetError() != EGL10.EGL_SUCCESS)
- ;
- }
- }
- }
-
- // Subclasses can adjust these values:
- protected int mRedSize;
- protected int mGreenSize;
- protected int mBlueSize;
- protected int mAlphaSize;
- protected int mDepthSize;
- protected int mStencilSize;
- private int[] mValue = new int[1];
- }
+ static String TAG = "GL2JNIView";
+ private static final boolean DEBUG = false;
+
+ final ResolutionStrategy resolutionStrategy;
+
+ public GLSurfaceView20 (Context context, ResolutionStrategy resolutionStrategy) {
+ super(context);
+ this.resolutionStrategy = resolutionStrategy;
+ init(false, 16, 0);
+ }
+
+ public GLSurfaceView20 (Context context, boolean translucent, int depth, int stencil, ResolutionStrategy resolutionStrategy) {
+ super(context);
+ this.resolutionStrategy = resolutionStrategy;
+ init(translucent, depth, stencil);
+
+ }
+
+ @Override
+ protected void onMeasure (int widthMeasureSpec, int heightMeasureSpec) {
+ ResolutionStrategy.MeasuredDimension measures = resolutionStrategy.calcMeasures(widthMeasureSpec, heightMeasureSpec);
+ setMeasuredDimension(measures.width, measures.height);
+ }
+
+ private void init (boolean translucent, int depth, int stencil) {
+
+ /*
+ * By default, GLSurfaceView() creates a RGB_565 opaque surface. If we want a translucent one, we should change the
+ * surface's format here, using PixelFormat.TRANSLUCENT for GL Surfaces is interpreted as any 32-bit surface with alpha by
+ * SurfaceFlinger.
+ */
+ if (translucent) {
+ this.getHolder().setFormat(PixelFormat.TRANSLUCENT);
+ }
+
+ /*
+ * Setup the context factory for 2.0 rendering. See ContextFactory class definition below
+ */
+ setEGLContextFactory(new ContextFactory());
+
+ /*
+ * We need to choose an EGLConfig that matches the format of our surface exactly. This is going to be done in our custom
+ * config chooser. See ConfigChooser class definition below.
+ */
+ setEGLConfigChooser(translucent ? new ConfigChooser(8, 8, 8, 8, depth, stencil) : new ConfigChooser(5, 6, 5, 0, depth,
+ stencil));
+
+ /* Set the renderer responsible for frame rendering */
+ }
+
+ static class ContextFactory implements GLSurfaceView.EGLContextFactory {
+ private static int EGL_CONTEXT_CLIENT_VERSION = 0x3098;
+
+ public EGLContext createContext (EGL10 egl, EGLDisplay display, EGLConfig eglConfig) {
+ Log.w(TAG, "creating OpenGL ES 2.0 context");
+ checkEglError("Before eglCreateContext", egl);
+ int[] attrib_list = {EGL_CONTEXT_CLIENT_VERSION, 2, EGL10.EGL_NONE};
+ EGLContext context = egl.eglCreateContext(display, eglConfig, EGL10.EGL_NO_CONTEXT, attrib_list);
+ checkEglError("After eglCreateContext", egl);
+ return context;
+ }
+
+ public void destroyContext (EGL10 egl, EGLDisplay display, EGLContext context) {
+ egl.eglDestroyContext(display, context);
+ }
+ }
+
+ static void checkEglError (String prompt, EGL10 egl) {
+ int error;
+ while ((error = egl.eglGetError()) != EGL10.EGL_SUCCESS) {
+ Log.e(TAG, String.format("%s: EGL error: 0x%x", prompt, error));
+ }
+ }
+
+ private static class ConfigChooser implements GLSurfaceView.EGLConfigChooser {
+
+ public ConfigChooser (int r, int g, int b, int a, int depth, int stencil) {
+ mRedSize = r;
+ mGreenSize = g;
+ mBlueSize = b;
+ mAlphaSize = a;
+ mDepthSize = depth;
+ mStencilSize = stencil;
+ }
+
+ /*
+ * This EGL config specification is used to specify 2.0 rendering. We use a minimum size of 4 bits for red/green/blue, but
+ * will perform actual matching in chooseConfig() below.
+ */
+ private static int EGL_OPENGL_ES2_BIT = 4;
+ private static int[] s_configAttribs2 = {EGL10.EGL_RED_SIZE, 4, EGL10.EGL_GREEN_SIZE, 4, EGL10.EGL_BLUE_SIZE, 4,
+ EGL10.EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, EGL10.EGL_NONE};
+
+ public EGLConfig chooseConfig (EGL10 egl, EGLDisplay display) {
+
+ /*
+ * Get the number of minimally matching EGL configurations
+ */
+ int[] num_config = new int[1];
+ egl.eglChooseConfig(display, s_configAttribs2, null, 0, num_config);
+
+ int numConfigs = num_config[0];
+
+ if (numConfigs <= 0) {
+ throw new IllegalArgumentException("No configs match configSpec");
+ }
+
+ /*
+ * Allocate then read the array of minimally matching EGL configs
+ */
+ EGLConfig[] configs = new EGLConfig[numConfigs];
+ egl.eglChooseConfig(display, s_configAttribs2, configs, numConfigs, num_config);
+
+ if (DEBUG) {
+ printConfigs(egl, display, configs);
+ }
+ /*
+ * Now return the "best" one
+ */
+ return chooseConfig(egl, display, configs);
+ }
+
+ public EGLConfig chooseConfig (EGL10 egl, EGLDisplay display, EGLConfig[] configs) {
+ for (EGLConfig config : configs) {
+ int d = findConfigAttrib(egl, display, config, EGL10.EGL_DEPTH_SIZE, 0);
+ int s = findConfigAttrib(egl, display, config, EGL10.EGL_STENCIL_SIZE, 0);
+
+ // We need at least mDepthSize and mStencilSize bits
+ if (d < mDepthSize || s < mStencilSize) continue;
+
+ // We want an *exact* match for red/green/blue/alpha
+ int r = findConfigAttrib(egl, display, config, EGL10.EGL_RED_SIZE, 0);
+ int g = findConfigAttrib(egl, display, config, EGL10.EGL_GREEN_SIZE, 0);
+ int b = findConfigAttrib(egl, display, config, EGL10.EGL_BLUE_SIZE, 0);
+ int a = findConfigAttrib(egl, display, config, EGL10.EGL_ALPHA_SIZE, 0);
+
+ if (r == mRedSize && g == mGreenSize && b == mBlueSize && a == mAlphaSize) return config;
+ }
+ return null;
+ }
+
+ private int findConfigAttrib (EGL10 egl, EGLDisplay display, EGLConfig config, int attribute, int defaultValue) {
+
+ if (egl.eglGetConfigAttrib(display, config, attribute, mValue)) {
+ return mValue[0];
+ }
+ return defaultValue;
+ }
+
+ private void printConfigs (EGL10 egl, EGLDisplay display, EGLConfig[] configs) {
+ int numConfigs = configs.length;
+ Log.w(TAG, String.format("%d configurations", numConfigs));
+ for (int i = 0; i < numConfigs; i++) {
+ Log.w(TAG, String.format("Configuration %d:\n", i));
+ printConfig(egl, display, configs[i]);
+ }
+ }
+
+ private void printConfig (EGL10 egl, EGLDisplay display, EGLConfig config) {
+ int[] attributes = {EGL10.EGL_BUFFER_SIZE, EGL10.EGL_ALPHA_SIZE, EGL10.EGL_BLUE_SIZE, EGL10.EGL_GREEN_SIZE,
+ EGL10.EGL_RED_SIZE, EGL10.EGL_DEPTH_SIZE, EGL10.EGL_STENCIL_SIZE, EGL10.EGL_CONFIG_CAVEAT, EGL10.EGL_CONFIG_ID,
+ EGL10.EGL_LEVEL, EGL10.EGL_MAX_PBUFFER_HEIGHT, EGL10.EGL_MAX_PBUFFER_PIXELS, EGL10.EGL_MAX_PBUFFER_WIDTH,
+ EGL10.EGL_NATIVE_RENDERABLE, EGL10.EGL_NATIVE_VISUAL_ID, EGL10.EGL_NATIVE_VISUAL_TYPE,
+ 0x3030, // EGL10.EGL_PRESERVED_RESOURCES,
+ EGL10.EGL_SAMPLES, EGL10.EGL_SAMPLE_BUFFERS, EGL10.EGL_SURFACE_TYPE, EGL10.EGL_TRANSPARENT_TYPE,
+ EGL10.EGL_TRANSPARENT_RED_VALUE, EGL10.EGL_TRANSPARENT_GREEN_VALUE, EGL10.EGL_TRANSPARENT_BLUE_VALUE, 0x3039, // EGL10.EGL_BIND_TO_TEXTURE_RGB,
+ 0x303A, // EGL10.EGL_BIND_TO_TEXTURE_RGBA,
+ 0x303B, // EGL10.EGL_MIN_SWAP_INTERVAL,
+ 0x303C, // EGL10.EGL_MAX_SWAP_INTERVAL,
+ EGL10.EGL_LUMINANCE_SIZE, EGL10.EGL_ALPHA_MASK_SIZE, EGL10.EGL_COLOR_BUFFER_TYPE, EGL10.EGL_RENDERABLE_TYPE, 0x3042 // EGL10.EGL_CONFORMANT
+ };
+ String[] names = {"EGL_BUFFER_SIZE", "EGL_ALPHA_SIZE", "EGL_BLUE_SIZE", "EGL_GREEN_SIZE", "EGL_RED_SIZE",
+ "EGL_DEPTH_SIZE", "EGL_STENCIL_SIZE", "EGL_CONFIG_CAVEAT", "EGL_CONFIG_ID", "EGL_LEVEL", "EGL_MAX_PBUFFER_HEIGHT",
+ "EGL_MAX_PBUFFER_PIXELS", "EGL_MAX_PBUFFER_WIDTH", "EGL_NATIVE_RENDERABLE", "EGL_NATIVE_VISUAL_ID",
+ "EGL_NATIVE_VISUAL_TYPE", "EGL_PRESERVED_RESOURCES", "EGL_SAMPLES", "EGL_SAMPLE_BUFFERS", "EGL_SURFACE_TYPE",
+ "EGL_TRANSPARENT_TYPE", "EGL_TRANSPARENT_RED_VALUE", "EGL_TRANSPARENT_GREEN_VALUE", "EGL_TRANSPARENT_BLUE_VALUE",
+ "EGL_BIND_TO_TEXTURE_RGB", "EGL_BIND_TO_TEXTURE_RGBA", "EGL_MIN_SWAP_INTERVAL", "EGL_MAX_SWAP_INTERVAL",
+ "EGL_LUMINANCE_SIZE", "EGL_ALPHA_MASK_SIZE", "EGL_COLOR_BUFFER_TYPE", "EGL_RENDERABLE_TYPE", "EGL_CONFORMANT"};
+ int[] value = new int[1];
+ for (int i = 0; i < attributes.length; i++) {
+ int attribute = attributes[i];
+ String name = names[i];
+ if (egl.eglGetConfigAttrib(display, config, attribute, value)) {
+ Log.w(TAG, String.format(" %s: %d\n", name, value[0]));
+ } else {
+ // Log.w(TAG, String.format(" %s: failed\n", name));
+ while (egl.eglGetError() != EGL10.EGL_SUCCESS)
+ ;
+ }
+ }
+ }
+
+ // Subclasses can adjust these values:
+ protected int mRedSize;
+ protected int mGreenSize;
+ protected int mBlueSize;
+ protected int mAlphaSize;
+ protected int mDepthSize;
+ protected int mStencilSize;
+ private int[] mValue = new int[1];
+ }
}
diff --git a/backends/gdx-backend-android/src/com/badlogic/gdx/backends/android/surfaceview/GLSurfaceViewCupcake.java b/backends/gdx-backend-android/src/com/badlogic/gdx/backends/android/surfaceview/GLSurfaceViewCupcake.java
index e9f183be75a..2bf1574c9ad 100644
--- a/backends/gdx-backend-android/src/com/badlogic/gdx/backends/android/surfaceview/GLSurfaceViewCupcake.java
+++ b/backends/gdx-backend-android/src/com/badlogic/gdx/backends/android/surfaceview/GLSurfaceViewCupcake.java
@@ -34,8 +34,7 @@
import android.view.SurfaceHolder;
import android.view.SurfaceView;
-/**
- * An implementation of SurfaceView that uses the dedicated surface for displaying OpenGL rendering.
+/** An implementation of SurfaceView that uses the dedicated surface for displaying OpenGL rendering.
*
* A GLSurfaceView provides the following features:
*
@@ -128,69 +127,55 @@
*
*
*
- *
*
- */
+ * */
public class GLSurfaceViewCupcake extends SurfaceView implements SurfaceHolder.Callback {
- /**
- * The renderer only renders when the surface is created, or when {@link #requestRender} is called.
+ /** The renderer only renders when the surface is created, or when {@link #requestRender} is called.
*
* @see #getRenderMode()
- * @see #setRenderMode(int)
- */
+ * @see #setRenderMode(int) */
public final static int RENDERMODE_WHEN_DIRTY = 0;
- /**
- * The renderer is called continuously to re-render the scene.
+ /** The renderer is called continuously to re-render the scene.
*
* @see #getRenderMode()
* @see #setRenderMode(int)
- * @see #requestRender()
- */
+ * @see #requestRender() */
public final static int RENDERMODE_CONTINUOUSLY = 1;
- /**
- * Check glError() after every GL call and throw an exception if glError indicates that an error has occurred. This can be used
+ /** Check glError() after every GL call and throw an exception if glError indicates that an error has occurred. This can be used
* to help track down which OpenGL ES call is causing an error.
*
* @see #getDebugFlags
- * @see #setDebugFlags
- */
+ * @see #setDebugFlags */
public final static int DEBUG_CHECK_GL_ERROR = 1;
- /**
- * Log GL calls to the system log at "verbose" level with tag "GLSurfaceView".
+ /** Log GL calls to the system log at "verbose" level with tag "GLSurfaceView".
*
* @see #getDebugFlags
- * @see #setDebugFlags
- */
+ * @see #setDebugFlags */
public final static int DEBUG_LOG_GL_CALLS = 2;
- final ResolutionStrategy resolutionStrategy;
+ final ResolutionStrategy resolutionStrategy;
- /**
- * Standard View constructor. In order to render something, you must call {@link #setRenderer} to register a renderer.
- */
+ /** Standard View constructor. In order to render something, you must call {@link #setRenderer} to register a renderer. */
public GLSurfaceViewCupcake (Context context, ResolutionStrategy resolutionStrategy) {
super(context);
- this.resolutionStrategy = resolutionStrategy;
+ this.resolutionStrategy = resolutionStrategy;
init();
}
- /**
- * Standard View constructor. In order to render something, you must call {@link #setRenderer} to register a renderer.
- */
+ /** Standard View constructor. In order to render something, you must call {@link #setRenderer} to register a renderer. */
public GLSurfaceViewCupcake (Context context, AttributeSet attrs, ResolutionStrategy resolutionStrategy) {
super(context, attrs);
- this.resolutionStrategy = resolutionStrategy;
+ this.resolutionStrategy = resolutionStrategy;
init();
}
-
- @Override
- protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
- ResolutionStrategy.MeasuredDimension measures = resolutionStrategy.calcMeasures(widthMeasureSpec, heightMeasureSpec);
- setMeasuredDimension(measures.width, measures.height);
- }
+ @Override
+ protected void onMeasure (int widthMeasureSpec, int heightMeasureSpec) {
+ ResolutionStrategy.MeasuredDimension measures = resolutionStrategy.calcMeasures(widthMeasureSpec, heightMeasureSpec);
+ setMeasuredDimension(measures.width, measures.height);
+ }
private void init () {
// Install a SurfaceHolder.Callback so we get notified when the
@@ -201,41 +186,34 @@ private void init () {
mRenderMode = RENDERMODE_CONTINUOUSLY;
}
- /**
- * Set the glWrapper. If the glWrapper is not null, its {@link GLWrapper#wrap(GL)} method is called whenever a surface is
+ /** Set the glWrapper. If the glWrapper is not null, its {@link GLWrapper#wrap(GL)} method is called whenever a surface is
* created. A GLWrapper can be used to wrap the GL object that's passed to the renderer. Wrapping a GL object enables examining
* and modifying the behavior of the GL calls made by the renderer.
*
* Wrapping is typically used for debugging purposes.
*
* The default value is null.
- * @param glWrapper the new GLWrapper
- */
+ * @param glWrapper the new GLWrapper */
public void setGLWrapper (GLWrapper glWrapper) {
mGLWrapper = glWrapper;
}
- /**
- * Set the debug flags to a new value. The value is constructed by OR-together zero or more of the DEBUG_CHECK_* constants. The
+ /** Set the debug flags to a new value. The value is constructed by OR-together zero or more of the DEBUG_CHECK_* constants. The
* debug flags take effect whenever a surface is created. The default value is zero.
* @param debugFlags the new debug flags
* @see #DEBUG_CHECK_GL_ERROR
- * @see #DEBUG_LOG_GL_CALLS
- */
+ * @see #DEBUG_LOG_GL_CALLS */
public void setDebugFlags (int debugFlags) {
mDebugFlags = debugFlags;
}
- /**
- * Get the current value of the debug flags.
- * @return the current value of the debug flags.
- */
+ /** Get the current value of the debug flags.
+ * @return the current value of the debug flags. */
public int getDebugFlags () {
return mDebugFlags;
}
- /**
- * Set the renderer associated with this view. Also starts the thread that will call the renderer, which in turn causes the
+ /** Set the renderer associated with this view. Also starts the thread that will call the renderer, which in turn causes the
* rendering to start.
*
* This method should be called once and only once in the life-cycle of a GLSurfaceView.
@@ -257,8 +235,7 @@ public int getDebugFlags () {
*
{@link #setRenderMode(int)}
*
*
- * @param renderer the renderer to use to perform OpenGL drawing.
- */
+ * @param renderer the renderer to use to perform OpenGL drawing. */
public void setRenderer (Renderer renderer) {
if (mRenderer != null) {
throw new IllegalStateException("setRenderer has already been called for this instance.");
@@ -267,15 +244,13 @@ public void setRenderer (Renderer renderer) {
mRenderer = renderer;
}
- /**
- * Install a custom EGLConfigChooser.
+ /** Install a custom EGLConfigChooser.
*
* If this method is called, it must be called before {@link #setRenderer(Renderer)} is called.
*
* If no setEGLConfigChooser method is called, then by default the view will choose a config as close to 16-bit RGB as
* possible, with a depth buffer as close to 16 bits as possible.
- * @param configChooser
- */
+ * @param configChooser */
public void setEGLConfigChooser (EGLConfigChooser configChooser) {
if (mRenderer != null) {
throw new IllegalStateException("setRenderer has already been called for this instance.");
@@ -283,8 +258,7 @@ public void setEGLConfigChooser (EGLConfigChooser configChooser) {
mEGLConfigChooser = configChooser;
}
- /**
- * Install a config chooser which will choose a config as close to 16-bit RGB as possible, with or without an optional depth
+ /** Install a config chooser which will choose a config as close to 16-bit RGB as possible, with or without an optional depth
* buffer as close to 16-bits as possible.
*
* If this method is called, it must be called before {@link #setRenderer(Renderer)} is called.
@@ -292,28 +266,23 @@ public void setEGLConfigChooser (EGLConfigChooser configChooser) {
* If no setEGLConfigChooser method is called, then by default the view will choose a config as close to 16-bit RGB as
* possible, with a depth buffer as close to 16 bits as possible.
*
- * @param needDepth
- */
+ * @param needDepth */
public void setEGLConfigChooser (boolean needDepth) {
setEGLConfigChooser(new SimpleEGLConfigChooser(needDepth));
}
- /**
- * Install a config chooser which will choose a config with at least the specified component sizes, and as close to the
+ /** Install a config chooser which will choose a config with at least the specified component sizes, and as close to the
* specified component sizes as possible.
*
* If this method is called, it must be called before {@link #setRenderer(Renderer)} is called.
*
* If no setEGLConfigChooser method is called, then by default the view will choose a config as close to 16-bit RGB as
- * possible, with a depth buffer as close to 16 bits as possible.
- *
- */
+ * possible, with a depth buffer as close to 16 bits as possible. */
public void setEGLConfigChooser (int redSize, int greenSize, int blueSize, int alphaSize, int depthSize, int stencilSize) {
setEGLConfigChooser(new ComponentSizeChooser(redSize, greenSize, blueSize, alphaSize, depthSize, stencilSize));
}
- /**
- * Set the rendering mode. When renderMode is RENDERMODE_CONTINUOUSLY, the renderer is called repeatedly to re-render the
+ /** Set the rendering mode. When renderMode is RENDERMODE_CONTINUOUSLY, the renderer is called repeatedly to re-render the
* scene. When renderMode is RENDERMODE_WHEN_DIRTY, the renderer only rendered when the surface is created, or when
* {@link #requestRender} is called. Defaults to RENDERMODE_CONTINUOUSLY.
*
@@ -324,8 +293,7 @@ public void setEGLConfigChooser (int redSize, int greenSize, int blueSize, int a
*
* @param renderMode one of the RENDERMODE_X constants
* @see #RENDERMODE_CONTINUOUSLY
- * @see #RENDERMODE_WHEN_DIRTY
- */
+ * @see #RENDERMODE_WHEN_DIRTY */
public void setRenderMode (int renderMode) {
mRenderMode = renderMode;
if (mGLThread != null) {
@@ -333,29 +301,23 @@ public void setRenderMode (int renderMode) {
}
}
- /**
- * Get the current rendering mode. May be called from any thread. Must not be called before a renderer has been set.
+ /** Get the current rendering mode. May be called from any thread. Must not be called before a renderer has been set.
* @return the current rendering mode.
* @see #RENDERMODE_CONTINUOUSLY
- * @see #RENDERMODE_WHEN_DIRTY
- */
+ * @see #RENDERMODE_WHEN_DIRTY */
public int getRenderMode () {
return mRenderMode;
}
- /**
- * Request that the renderer render a frame. This method is typically used when the render mode has been set to
+ /** Request that the renderer render a frame. This method is typically used when the render mode has been set to
* {@link #RENDERMODE_WHEN_DIRTY}, so that frames are only rendered on demand. May be called from any thread. Must be called
- * after onResume() and before onPause().
- */
+ * after onResume() and before onPause(). */
public void requestRender () {
mGLThread.requestRender();
}
- /**
- * This method is part of the SurfaceHolder.Callback interface, and is not normally called or subclassed by clients of
- * GLSurfaceView.
- */
+ /** This method is part of the SurfaceHolder.Callback interface, and is not normally called or subclassed by clients of
+ * GLSurfaceView. */
public void surfaceCreated (SurfaceHolder holder) {
if (mGLThread != null) {
mGLThread.surfaceCreated();
@@ -363,10 +325,8 @@ public void surfaceCreated (SurfaceHolder holder) {
mHasSurface = true;
}
- /**
- * This method is part of the SurfaceHolder.Callback interface, and is not normally called or subclassed by clients of
- * GLSurfaceView.
- */
+ /** This method is part of the SurfaceHolder.Callback interface, and is not normally called or subclassed by clients of
+ * GLSurfaceView. */
public void surfaceDestroyed (SurfaceHolder holder) {
// Surface will be destroyed when we return
if (mGLThread != null) {
@@ -375,10 +335,8 @@ public void surfaceDestroyed (SurfaceHolder holder) {
mHasSurface = false;
}
- /**
- * This method is part of the SurfaceHolder.Callback interface, and is not normally called or subclassed by clients of
- * GLSurfaceView.
- */
+ /** This method is part of the SurfaceHolder.Callback interface, and is not normally called or subclassed by clients of
+ * GLSurfaceView. */
public void surfaceChanged (SurfaceHolder holder, int format, int w, int h) {
if (mGLThread != null) {
mGLThread.onWindowResize(w, h);
@@ -387,21 +345,17 @@ public void surfaceChanged (SurfaceHolder holder, int format, int w, int h) {
mSurfaceHeight = h;
}
- /**
- * Inform the view that the activity is paused. The owner of this view must call this method when the activity is paused.
- * Calling this method will pause the rendering thread. Must not be called before a renderer has been set.
- */
+ /** Inform the view that the activity is paused. The owner of this view must call this method when the activity is paused.
+ * Calling this method will pause the rendering thread. Must not be called before a renderer has been set. */
public void onPause () {
mGLThread.onPause();
mGLThread.requestExitAndWait();
mGLThread = null;
}
- /**
- * Inform the view that the activity is resumed. The owner of this view must call this method when the activity is resumed.
+ /** Inform the view that the activity is resumed. The owner of this view must call this method when the activity is resumed.
* Calling this method will recreate the OpenGL display and resume the rendering thread. Must not be called before a renderer
- * has been set.
- */
+ * has been set. */
public void onResume () {
if (mEGLConfigChooser == null) {
mEGLConfigChooser = new SimpleEGLConfigChooser(true);
@@ -418,11 +372,9 @@ public void onResume () {
mGLThread.onResume();
}
- /**
- * Queue a runnable to be run on the GL rendering thread. This can be used to communicate with the Renderer on the rendering
+ /** Queue a runnable to be run on the GL rendering thread. This can be used to communicate with the Renderer on the rendering
* thread. Must be called after onResume() and before onPause().
- * @param r the runnable to be run on the GL rendering thread.
- */
+ * @param r the runnable to be run on the GL rendering thread. */
public void queueEvent (Runnable r) {
if (mGLThread != null) {
mGLThread.queueEvent(r);
@@ -431,8 +383,7 @@ public void queueEvent (Runnable r) {
// ----------------------------------------------------------------------
- /**
- * An interface used to wrap a GL interface.
+ /** An interface used to wrap a GL interface.
*
* Typically used for implementing debugging and tracing on top of the default GL interface. You would typically use this by
* creating your own class that implemented all the GL methods by delegating to another GL instance. Then you could add your
@@ -449,14 +400,11 @@ public void queueEvent (Runnable r) {
* }
* }
*
- * @see #setGLWrapper(GLWrapper)
- */
+ * @see #setGLWrapper(GLWrapper) */
public interface GLWrapper {
- /**
- * Wraps a gl interface in another gl interface.
+ /** Wraps a gl interface in another gl interface.
* @param gl a GL interface that is to be wrapped.
- * @return either the input argument or another GL object that wraps the input argument.
- */
+ * @return either the input argument or another GL object that wraps the input argument. */
GL wrap (GL gl);
}
@@ -504,7 +452,8 @@ public ComponentSizeChooser (int redSize, int greenSize, int blueSize, int alpha
mStencilSize = stencilSize;
}
- @Override public EGLConfig chooseConfig (EGL10 egl, EGLDisplay display, EGLConfig[] configs) {
+ @Override
+ public EGLConfig chooseConfig (EGL10 egl, EGLDisplay display, EGLConfig[] configs) {
EGLConfig closestConfig = null;
int closestDistance = 1000;
for (EGLConfig config : configs) {
@@ -542,10 +491,7 @@ private int findConfigAttrib (EGL10 egl, EGLDisplay display, EGLConfig config, i
protected int mStencilSize;
}
- /**
- * This class will choose a supported surface as close to RGB565 as possible, with or without a depth buffer.
- *
- */
+ /** This class will choose a supported surface as close to RGB565 as possible, with or without a depth buffer. */
private static class SimpleEGLConfigChooser extends ComponentSizeChooser {
public SimpleEGLConfigChooser (boolean withDepthBuffer) {
super(4, 4, 4, 0, withDepthBuffer ? 16 : 0, 0);
@@ -557,18 +503,14 @@ public SimpleEGLConfigChooser (boolean withDepthBuffer) {
}
}
- /**
- * An EGL helper class.
- */
+ /** An EGL helper class. */
private class EglHelper {
public EglHelper () {
}
- /**
- * Initialize EGL for a given configuration spec.
- */
+ /** Initialize EGL for a given configuration spec. */
public void start () {
/*
* Get an EGL instance
@@ -635,10 +577,8 @@ public GL createSurface (SurfaceHolder holder) {
return gl;
}
- /**
- * Display the current render surface.
- * @return false if the context has been lost.
- */
+ /** Display the current render surface.
+ * @return false if the context has been lost. */
public boolean swap () {
mEgl.eglSwapBuffers(mEglDisplay, mEglSurface);
@@ -672,11 +612,8 @@ public void finish () {
EGLContext mEglContext;
}
- /**
- * A generic GL Thread. Takes care of initializing EGL and GL. Delegates to a Renderer instance to do the actual drawing. Can
- * be configured to render continuously or on request.
- *
- */
+ /** A generic GL Thread. Takes care of initializing EGL and GL. Delegates to a Renderer instance to do the actual drawing. Can
+ * be configured to render continuously or on request. */
class GLThread extends Thread {
GLThread (Renderer renderer) {
super();
@@ -690,7 +627,8 @@ class GLThread extends Thread {
setName("GLThread");
}
- @Override public void run () {
+ @Override
+ public void run () {
/*
* When the android framework launches a second instance of an activity, the new instance's onCreate() method may be
* called before the first instance returns from onDestroy().
@@ -876,10 +814,8 @@ public void requestExitAndWait () {
}
}
- /**
- * Queue an "event" to be run on the GL rendering thread.
- * @param r the runnable to be run on the GL rendering thread.
- */
+ /** Queue an "event" to be run on the GL rendering thread.
+ * @param r the runnable to be run on the GL rendering thread. */
public void queueEvent (Runnable r) {
synchronized (this) {
mEventQueue.add(r);
@@ -911,15 +847,18 @@ private Runnable getEvent () {
static class LogWriter extends Writer {
- @Override public void close () {
+ @Override
+ public void close () {
flushBuilder();
}
- @Override public void flush () {
+ @Override
+ public void flush () {
flushBuilder();
}
- @Override public void write (char[] buf, int offset, int count) {
+ @Override
+ public void write (char[] buf, int offset, int count) {
for (int i = 0; i < count; i++) {
char c = buf[offset + i];
if (c == '\n') {
diff --git a/backends/gdx-backend-android/src/com/badlogic/gdx/backends/android/surfaceview/GLWrapperBase.java b/backends/gdx-backend-android/src/com/badlogic/gdx/backends/android/surfaceview/GLWrapperBase.java
index 49c8a07a1d3..b5fdf626ad5 100644
--- a/backends/gdx-backend-android/src/com/badlogic/gdx/backends/android/surfaceview/GLWrapperBase.java
+++ b/backends/gdx-backend-android/src/com/badlogic/gdx/backends/android/surfaceview/GLWrapperBase.java
@@ -24,9 +24,7 @@
import javax.microedition.khronos.opengles.GL11Ext;
import javax.microedition.khronos.opengles.GL11ExtensionPack;
-/**
- * The abstract base class for a GL wrapper. Provides some convenient instance variables and default implementations.
- */
+/** The abstract base class for a GL wrapper. Provides some convenient instance variables and default implementations. */
abstract class GLWrapperBase implements GL, GL10, GL10Ext, GL11, GL11Ext {
public GLWrapperBase (GL gl) {
mgl = (GL10)gl;
diff --git a/backends/gdx-backend-android/src/com/badlogic/gdx/backends/android/surfaceview/GdxEglConfigChooser.java b/backends/gdx-backend-android/src/com/badlogic/gdx/backends/android/surfaceview/GdxEglConfigChooser.java
index 733d3d3f515..3b73c0b473f 100644
--- a/backends/gdx-backend-android/src/com/badlogic/gdx/backends/android/surfaceview/GdxEglConfigChooser.java
+++ b/backends/gdx-backend-android/src/com/badlogic/gdx/backends/android/surfaceview/GdxEglConfigChooser.java
@@ -21,16 +21,13 @@
import android.opengl.GLSurfaceView.EGLConfigChooser;
import android.util.Log;
-/**
- * {@link EGLConfigChooser} implementation for GLES 1.x and 2.0. Let's hope this really works for all devices. Includes MSAA/CSAA
+/** {@link EGLConfigChooser} implementation for GLES 1.x and 2.0. Let's hope this really works for all devices. Includes MSAA/CSAA
* config selection if requested. Taken from GLSurfaceView20, heavily modified to accommodate MSAA/CSAA.
- * @author mzechner
- *
- */
+ * @author mzechner */
public class GdxEglConfigChooser implements GLSurfaceView.EGLConfigChooser {
private static final int EGL_OPENGL_ES2_BIT = 4;
public static final int EGL_COVERAGE_BUFFERS_NV = 0x30E0;
- public static final int EGL_COVERAGE_SAMPLES_NV = 0x30E1;
+ public static final int EGL_COVERAGE_SAMPLES_NV = 0x30E1;
private static final String TAG = "GdxEglConfigChooser";
protected int mRedSize;
@@ -55,16 +52,10 @@ public GdxEglConfigChooser (int r, int g, int b, int a, int depth, int stencil,
mUseGL20 = useGL20;
if (useGL20) {
- mConfigAttribs = new int[] {EGL10.EGL_RED_SIZE, 4,
- EGL10.EGL_GREEN_SIZE, 4,
- EGL10.EGL_BLUE_SIZE, 4,
- EGL10.EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
- EGL10.EGL_NONE};
+ mConfigAttribs = new int[] {EGL10.EGL_RED_SIZE, 4, EGL10.EGL_GREEN_SIZE, 4, EGL10.EGL_BLUE_SIZE, 4,
+ EGL10.EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, EGL10.EGL_NONE};
} else {
- mConfigAttribs = new int[] {EGL10.EGL_RED_SIZE, 4,
- EGL10.EGL_GREEN_SIZE, 4,
- EGL10.EGL_BLUE_SIZE, 4,
- EGL10.EGL_NONE};
+ mConfigAttribs = new int[] {EGL10.EGL_RED_SIZE, 4, EGL10.EGL_GREEN_SIZE, 4, EGL10.EGL_BLUE_SIZE, 4, EGL10.EGL_NONE};
}
}
@@ -78,26 +69,26 @@ public EGLConfig chooseConfig (EGL10 egl, EGLDisplay display) {
if (numConfigs <= 0) {
throw new IllegalArgumentException("No configs match configSpec");
}
-
+
// now actually read the configurations.
EGLConfig[] configs = new EGLConfig[numConfigs];
egl.eglChooseConfig(display, mConfigAttribs, configs, numConfigs, num_config);
-
+
// FIXME remove this.
- //printConfigs(egl, display, configs);
-
+ // printConfigs(egl, display, configs);
+
// chose the best one, taking into account multi sampling.
EGLConfig config = chooseConfig(egl, display, configs);
-
+
// FIXME print the chosen config
- //printConfigs(egl, display, new EGLConfig[] { config });
+ // printConfigs(egl, display, new EGLConfig[] { config });
return config;
}
public EGLConfig chooseConfig (EGL10 egl, EGLDisplay display, EGLConfig[] configs) {
EGLConfig best = null;
EGLConfig bestAA = null;
-
+
for (EGLConfig config : configs) {
int d = findConfigAttrib(egl, display, config, EGL10.EGL_DEPTH_SIZE, 0);
int s = findConfigAttrib(egl, display, config, EGL10.EGL_STENCIL_SIZE, 0);
@@ -115,39 +106,43 @@ public EGLConfig chooseConfig (EGL10 egl, EGLDisplay display, EGLConfig[] config
// isn't set already.
if (best == null && r == mRedSize && g == mGreenSize && b == mBlueSize && a == mAlphaSize) {
best = config;
-
+
// if no AA is requested we can bail out here.
- if(mNumSamples == 0) {
+ if (mNumSamples == 0) {
break;
- }
+ }
}
-
+
// now check for MSAA support
int hasSampleBuffers = findConfigAttrib(egl, display, config, EGL10.EGL_SAMPLE_BUFFERS, 0);
- int numSamples = findConfigAttrib(egl, display, config, EGL10.EGL_SAMPLES, 0);
-
+ int numSamples = findConfigAttrib(egl, display, config, EGL10.EGL_SAMPLES, 0);
+
// We take the first sort of matching config, thank you.
- if(bestAA == null && hasSampleBuffers == 1 && numSamples >= mNumSamples && r == mRedSize && g == mGreenSize && b == mBlueSize && a == mAlphaSize) {
+ if (bestAA == null && hasSampleBuffers == 1 && numSamples >= mNumSamples && r == mRedSize && g == mGreenSize
+ && b == mBlueSize && a == mAlphaSize) {
bestAA = config;
continue;
}
-
+
// for this to work we need to call the extension glCoverageMaskNV which is not
// exposed in the Android bindings. We'd have to link agains the NVidia SDK and
// that is simply not going to happen.
-// // still no luck, let's try CSAA support
+// // still no luck, let's try CSAA support
hasSampleBuffers = findConfigAttrib(egl, display, config, EGL_COVERAGE_BUFFERS_NV, 0);
numSamples = findConfigAttrib(egl, display, config, EGL_COVERAGE_SAMPLES_NV, 0);
-
+
// We take the first sort of matching config, thank you.
- if(bestAA == null && hasSampleBuffers == 1 && numSamples >= mNumSamples && r == mRedSize && g == mGreenSize && b == mBlueSize && a == mAlphaSize) {
+ if (bestAA == null && hasSampleBuffers == 1 && numSamples >= mNumSamples && r == mRedSize && g == mGreenSize
+ && b == mBlueSize && a == mAlphaSize) {
bestAA = config;
continue;
}
}
-
- if(bestAA != null) return bestAA;
- else return best;
+
+ if (bestAA != null)
+ return bestAA;
+ else
+ return best;
}
private int findConfigAttrib (EGL10 egl, EGLDisplay display, EGLConfig config, int attribute, int defaultValue) {
@@ -180,15 +175,15 @@ private void printConfig (EGL10 egl, EGLDisplay display, EGLConfig config) {
EGL10.EGL_LUMINANCE_SIZE, EGL10.EGL_ALPHA_MASK_SIZE, EGL10.EGL_COLOR_BUFFER_TYPE, EGL10.EGL_RENDERABLE_TYPE, 0x3042,
// EGL10.EGL_CONFORMANT
EGL_COVERAGE_BUFFERS_NV, /* true */
- EGL_COVERAGE_SAMPLES_NV
- };
+ EGL_COVERAGE_SAMPLES_NV};
String[] names = {"EGL_BUFFER_SIZE", "EGL_ALPHA_SIZE", "EGL_BLUE_SIZE", "EGL_GREEN_SIZE", "EGL_RED_SIZE", "EGL_DEPTH_SIZE",
"EGL_STENCIL_SIZE", "EGL_CONFIG_CAVEAT", "EGL_CONFIG_ID", "EGL_LEVEL", "EGL_MAX_PBUFFER_HEIGHT",
"EGL_MAX_PBUFFER_PIXELS", "EGL_MAX_PBUFFER_WIDTH", "EGL_NATIVE_RENDERABLE", "EGL_NATIVE_VISUAL_ID",
"EGL_NATIVE_VISUAL_TYPE", "EGL_PRESERVED_RESOURCES", "EGL_SAMPLES", "EGL_SAMPLE_BUFFERS", "EGL_SURFACE_TYPE",
"EGL_TRANSPARENT_TYPE", "EGL_TRANSPARENT_RED_VALUE", "EGL_TRANSPARENT_GREEN_VALUE", "EGL_TRANSPARENT_BLUE_VALUE",
"EGL_BIND_TO_TEXTURE_RGB", "EGL_BIND_TO_TEXTURE_RGBA", "EGL_MIN_SWAP_INTERVAL", "EGL_MAX_SWAP_INTERVAL",
- "EGL_LUMINANCE_SIZE", "EGL_ALPHA_MASK_SIZE", "EGL_COLOR_BUFFER_TYPE", "EGL_RENDERABLE_TYPE", "EGL_CONFORMANT", "EGL_COVERAGE_BUFFERS_NV", "EGL_COVERAGE_SAMPLES_NV"};
+ "EGL_LUMINANCE_SIZE", "EGL_ALPHA_MASK_SIZE", "EGL_COLOR_BUFFER_TYPE", "EGL_RENDERABLE_TYPE", "EGL_CONFORMANT",
+ "EGL_COVERAGE_BUFFERS_NV", "EGL_COVERAGE_SAMPLES_NV"};
int[] value = new int[1];
for (int i = 0; i < attributes.length; i++) {
int attribute = attributes[i];
@@ -198,8 +193,8 @@ private void printConfig (EGL10 egl, EGLDisplay display, EGLConfig config) {
} else {
// Log.w(TAG, String.format(" %s: failed\n", name));
egl.eglGetError();
-// while (egl.eglGetError() != EGL10.EGL_SUCCESS)
-// ;
+// while (egl.eglGetError() != EGL10.EGL_SUCCESS)
+// ;
}
}
}
diff --git a/backends/gdx-backend-android/src/com/badlogic/gdx/backends/android/surfaceview/RatioResolutionStrategy.java b/backends/gdx-backend-android/src/com/badlogic/gdx/backends/android/surfaceview/RatioResolutionStrategy.java
index 853afc058a2..ccb2a2362d4 100644
--- a/backends/gdx-backend-android/src/com/badlogic/gdx/backends/android/surfaceview/RatioResolutionStrategy.java
+++ b/backends/gdx-backend-android/src/com/badlogic/gdx/backends/android/surfaceview/RatioResolutionStrategy.java
@@ -13,46 +13,46 @@
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
+
package com.badlogic.gdx.backends.android.surfaceview;
import android.view.View;
-/**
- * This {@link ResolutionStrategy} will maintain a given aspect ratio and stretch the GLSurfaceView to the maximum available screen size.
- *
- * @author christoph widulle
- */
+/** This {@link ResolutionStrategy} will maintain a given aspect ratio and stretch the GLSurfaceView to the maximum available
+ * screen size.
+ *
+ * @author christoph widulle */
public class RatioResolutionStrategy implements ResolutionStrategy {
- private final float ratio;
+ private final float ratio;
- public RatioResolutionStrategy(float ratio) {
- this.ratio = ratio;
- }
+ public RatioResolutionStrategy (float ratio) {
+ this.ratio = ratio;
+ }
- public RatioResolutionStrategy(final float width, final float height) {
- this.ratio = width / height;
- }
+ public RatioResolutionStrategy (final float width, final float height) {
+ this.ratio = width / height;
+ }
- @Override
- public MeasuredDimension calcMeasures(int widthMeasureSpec, int heightMeasureSpec) {
+ @Override
+ public MeasuredDimension calcMeasures (int widthMeasureSpec, int heightMeasureSpec) {
- final int specWidth = View.MeasureSpec.getSize(widthMeasureSpec);
- final int specHeight = View.MeasureSpec.getSize(heightMeasureSpec);
+ final int specWidth = View.MeasureSpec.getSize(widthMeasureSpec);
+ final int specHeight = View.MeasureSpec.getSize(heightMeasureSpec);
- final float desiredRatio = ratio;
- final float realRatio = (float) specWidth / specHeight;
+ final float desiredRatio = ratio;
+ final float realRatio = (float)specWidth / specHeight;
- int width;
- int height;
- if (realRatio < desiredRatio) {
- width = specWidth;
- height = Math.round(width / desiredRatio);
- } else {
- height = specHeight;
- width = Math.round(height * desiredRatio);
- }
+ int width;
+ int height;
+ if (realRatio < desiredRatio) {
+ width = specWidth;
+ height = Math.round(width / desiredRatio);
+ } else {
+ height = specHeight;
+ width = Math.round(height * desiredRatio);
+ }
- return new MeasuredDimension(width, height);
- }
+ return new MeasuredDimension(width, height);
+ }
}
diff --git a/backends/gdx-backend-android/src/com/badlogic/gdx/backends/android/surfaceview/ResolutionStrategy.java b/backends/gdx-backend-android/src/com/badlogic/gdx/backends/android/surfaceview/ResolutionStrategy.java
index ff5f34b2522..cd17d41831e 100644
--- a/backends/gdx-backend-android/src/com/badlogic/gdx/backends/android/surfaceview/ResolutionStrategy.java
+++ b/backends/gdx-backend-android/src/com/badlogic/gdx/backends/android/surfaceview/ResolutionStrategy.java
@@ -13,33 +13,26 @@
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
-package com.badlogic.gdx.backends.android.surfaceview;
+package com.badlogic.gdx.backends.android.surfaceview;
-/**
- * Will manipulate the GLSurfaceView. Gravity is always center.
- * The width and height of the View will be determinded by the classes implementing {@link ResolutionStrategy}.
- *
- * @author christoph widulle
- */
+/** Will manipulate the GLSurfaceView. Gravity is always center. The width and height of the View will be determinded by the
+ * classes implementing {@link ResolutionStrategy}.
+ *
+ * @author christoph widulle */
public interface ResolutionStrategy {
+ public MeasuredDimension calcMeasures (final int widthMeasureSpec, final int heightMeasureSpec);
- public MeasuredDimension calcMeasures( final int widthMeasureSpec, final int heightMeasureSpec);
-
-
- public static class MeasuredDimension {
- public final int width;
- public final int height;
-
- public MeasuredDimension(int width, int height) {
- this.width = width;
- this.height = height;
- }
-
- }
-
+ public static class MeasuredDimension {
+ public final int width;
+ public final int height;
+ public MeasuredDimension (int width, int height) {
+ this.width = width;
+ this.height = height;
+ }
+ }
}
diff --git a/backends/gdx-backend-jogl/src/com/badlogic/gdx/backends/jogl/JoglAnimator.java b/backends/gdx-backend-jogl/src/com/badlogic/gdx/backends/jogl/JoglAnimator.java
index 58c5e571142..89d993d4fbe 100644
--- a/backends/gdx-backend-jogl/src/com/badlogic/gdx/backends/jogl/JoglAnimator.java
+++ b/backends/gdx-backend-jogl/src/com/badlogic/gdx/backends/jogl/JoglAnimator.java
@@ -48,16 +48,14 @@
import javax.swing.RepaintManager;
import javax.swing.SwingUtilities;
-/**
- *
+/**
* An Animator can be attached to one or more {@link GLAutoDrawable}s to drive their display() methods in a loop.
*
*
*
* The Animator class creates a background thread in which the calls to display()
are performed. After each drawable
* has been redrawn, a brief pause is performed to avoid swamping the CPU, unless {@link #setRunAsFastAsPossible} has been called.
- *
- */
+ *
*/
public class JoglAnimator {
volatile ArrayList/* */drawables = new ArrayList();
@@ -98,42 +96,32 @@ public synchronized void remove (GLAutoDrawable drawable) {
drawables = newList;
}
- /**
- * Returns an iterator over the drawables managed by this Animator.
- */
+ /** Returns an iterator over the drawables managed by this Animator. */
public Iterator/* */drawableIterator () {
return drawables.iterator();
}
- /**
- * Sets a flag causing this Animator to ignore exceptions produced while redrawing the drawables. By default this flag is set
- * to false, causing any exception thrown to halt the Animator.
- */
+ /** Sets a flag causing this Animator to ignore exceptions produced while redrawing the drawables. By default this flag is set
+ * to false, causing any exception thrown to halt the Animator. */
public void setIgnoreExceptions (boolean ignoreExceptions) {
this.ignoreExceptions = ignoreExceptions;
}
- /**
- * Sets a flag indicating that when exceptions are being ignored by this Animator (see {@link #setIgnoreExceptions}), to print
- * the exceptions' stack traces for diagnostic information. Defaults to false.
- */
+ /** Sets a flag indicating that when exceptions are being ignored by this Animator (see {@link #setIgnoreExceptions}), to print
+ * the exceptions' stack traces for diagnostic information. Defaults to false. */
public void setPrintExceptions (boolean printExceptions) {
this.printExceptions = printExceptions;
}
- /**
- * Sets a flag in this Animator indicating that it is to run as fast as possible. By default there is a brief pause in the
- * animation loop which prevents the CPU from getting swamped. This method may not have an effect on subclasses.
- */
+ /** Sets a flag in this Animator indicating that it is to run as fast as possible. By default there is a brief pause in the
+ * animation loop which prevents the CPU from getting swamped. This method may not have an effect on subclasses. */
public final void setRunAsFastAsPossible (boolean runFast) {
runAsFastAsPossible = runFast;
}
- /**
- * Called every frame to cause redrawing of all of the GLAutoDrawables this Animator manages. Subclasses should call this to
+ /** Called every frame to cause redrawing of all of the GLAutoDrawables this Animator manages. Subclasses should call this to
* get the most optimized painting behavior for the set of components this Animator manages, in particular when multiple
- * lightweight widgets are continually being redrawn.
- */
+ * lightweight widgets are continually being redrawn. */
protected void display () {
Iterator iter = drawableIterator();
while (iter.hasNext()) {
@@ -211,18 +199,14 @@ public synchronized void start () {
thread.start();
}
- /**
- * Indicates whether this animator is currently running. This should only be used as a heuristic to applications because in
- * some circumstances the Animator may be in the process of shutting down and this method will still return true.
- */
+ /** Indicates whether this animator is currently running. This should only be used as a heuristic to applications because in
+ * some circumstances the Animator may be in the process of shutting down and this method will still return true. */
public synchronized boolean isAnimating () {
return (thread != null);
}
- /**
- * Stops this animator. In most situations this method blocks until completion, except when called from the animation thread
- * itself or in some cases from an implementation-internal thread like the AWT event queue thread.
- */
+ /** Stops this animator. In most situations this method blocks until completion, except when called from the animation thread
+ * itself or in some cases from an implementation-internal thread like the AWT event queue thread. */
public synchronized void stop () {
shouldStop = true;
notifyAll();
diff --git a/backends/gdx-backend-jogl/src/com/badlogic/gdx/backends/jogl/JoglApplication.java b/backends/gdx-backend-jogl/src/com/badlogic/gdx/backends/jogl/JoglApplication.java
index 6212eb74ba8..f8916632be0 100644
--- a/backends/gdx-backend-jogl/src/com/badlogic/gdx/backends/jogl/JoglApplication.java
+++ b/backends/gdx-backend-jogl/src/com/badlogic/gdx/backends/jogl/JoglApplication.java
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
+
package com.badlogic.gdx.backends.jogl;
import java.awt.BorderLayout;
@@ -43,13 +44,10 @@
import com.badlogic.gdx.backends.openal.OpenALAudio;
import com.badlogic.gdx.utils.GdxRuntimeException;
-/**
- * An implemenation of the {@link Application} interface based on Jogl for Windows, Linux and Mac. Instantiate this class with
+/** An implemenation of the {@link Application} interface based on Jogl for Windows, Linux and Mac. Instantiate this class with
* apropriate parameters and then register {@link ApplicationListener} or {@link InputProcessor} instances.
*
- * @author mzechner
- *
- */
+ * @author mzechner */
public final class JoglApplication implements Application {
JoglGraphics graphics;
JoglInput input;
@@ -59,8 +57,7 @@ public final class JoglApplication implements Application {
List runnables = new ArrayList();
int logLevel = LOG_INFO;
- /**
- * Creates a new {@link JoglApplication} with the given title and dimensions. If useGL20IfAvailable is set the JoglApplication
+ /** Creates a new {@link JoglApplication} with the given title and dimensions. If useGL20IfAvailable is set the JoglApplication
* will try to create an OpenGL 2.0 context which can then be used via JoglApplication.getGraphics().getGL20(). To query
* whether enabling OpenGL 2.0 was successful use the JoglApplication.getGraphics().isGL20Available() method.
*
@@ -68,8 +65,7 @@ public final class JoglApplication implements Application {
* @param title the title of the application
* @param width the width of the surface in pixels
* @param height the height of the surface in pixels
- * @param useGL20IfAvailable wheter to use OpenGL 2.0 if it is available or not
- */
+ * @param useGL20IfAvailable wheter to use OpenGL 2.0 if it is available or not */
public JoglApplication (final ApplicationListener listener, final String title, final int width, final int height,
final boolean useGL20IfAvailable) {
final JoglApplicationConfiguration config = new JoglApplicationConfiguration();
@@ -77,24 +73,24 @@ public JoglApplication (final ApplicationListener listener, final String title,
config.width = width;
config.height = height;
config.useGL20 = useGL20IfAvailable;
-
+
if (!SwingUtilities.isEventDispatchThread()) {
try {
SwingUtilities.invokeAndWait(new Runnable() {
- public void run () {
+ public void run () {
initialize(listener, config);
}
});
} catch (Exception e) {
throw new GdxRuntimeException("Creating window failed", e);
}
- } else {
+ } else {
config.useGL20 = useGL20IfAvailable;
initialize(listener, config);
}
}
- public JoglApplication(final ApplicationListener listener, final JoglApplicationConfiguration config) {
+ public JoglApplication (final ApplicationListener listener, final JoglApplicationConfiguration config) {
if (!SwingUtilities.isEventDispatchThread()) {
try {
SwingUtilities.invokeAndWait(new Runnable() {
@@ -109,7 +105,7 @@ public void run () {
initialize(listener, config);
}
}
-
+
void initialize (ApplicationListener listener, JoglApplicationConfiguration config) {
JoglNativesLoader.load();
graphics = new JoglGraphics(listener, config);
@@ -123,16 +119,16 @@ void initialize (ApplicationListener listener, JoglApplicationConfiguration conf
Gdx.audio = JoglApplication.this.getAudio();
Gdx.files = JoglApplication.this.getFiles();
- if(!config.fullscreen) {
+ if (!config.fullscreen) {
frame = new JFrame(config.title);
graphics.getCanvas().setPreferredSize(new Dimension(config.width, config.height));
- frame.setSize(config.width + frame.getInsets().left + frame.getInsets().right, frame.getInsets().top + frame.getInsets().bottom
- + config.height);
+ frame.setSize(config.width + frame.getInsets().left + frame.getInsets().right, frame.getInsets().top
+ + frame.getInsets().bottom + config.height);
frame.add(graphics.getCanvas(), BorderLayout.CENTER);
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
frame.setLocationRelativeTo(null);
frame.addWindowListener(windowListener);
-
+
frame.pack();
frame.setVisible(true);
graphics.create();
@@ -141,8 +137,8 @@ void initialize (ApplicationListener listener, JoglApplicationConfiguration conf
GraphicsDevice device = genv.getDefaultScreenDevice();
frame = new JFrame(config.title);
graphics.getCanvas().setPreferredSize(new Dimension(config.width, config.height));
- frame.setSize(config.width + frame.getInsets().left + frame.getInsets().right, frame.getInsets().top + frame.getInsets().bottom
- + config.height);
+ frame.setSize(config.width + frame.getInsets().left + frame.getInsets().right, frame.getInsets().top
+ + frame.getInsets().bottom + config.height);
frame.add(graphics.getCanvas(), BorderLayout.CENTER);
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
frame.setLocationRelativeTo(null);
@@ -155,10 +151,11 @@ void initialize (ApplicationListener listener, JoglApplicationConfiguration conf
try {
device.setFullScreenWindow(frame);
JoglDisplayMode mode = graphics.findBestMatch(config.width, config.height);
- if(mode == null) throw new GdxRuntimeException("Couldn't set fullscreen mode " + config.width + "x" + config.height);
+ if (mode == null)
+ throw new GdxRuntimeException("Couldn't set fullscreen mode " + config.width + "x" + config.height);
device.setDisplayMode(mode.mode);
- } catch(Throwable e) {
- e.printStackTrace();
+ } catch (Throwable e) {
+ e.printStackTrace();
device.setDisplayMode(desktopMode);
device.setFullScreenWindow(null);
frame.dispose();
@@ -168,20 +165,24 @@ void initialize (ApplicationListener listener, JoglApplicationConfiguration conf
graphics.create();
}
}
-
+
final WindowAdapter windowListener = new WindowAdapter() {
- @Override public void windowOpened (WindowEvent arg0) {
+ @Override
+ public void windowOpened (WindowEvent arg0) {
graphics.getCanvas().requestFocus();
graphics.getCanvas().requestFocusInWindow();
}
- @Override public void windowIconified (WindowEvent arg0) {
+ @Override
+ public void windowIconified (WindowEvent arg0) {
}
- @Override public void windowDeiconified (WindowEvent arg0) {
+ @Override
+ public void windowDeiconified (WindowEvent arg0) {
}
- @Override public void windowClosing (WindowEvent arg0) {
+ @Override
+ public void windowClosing (WindowEvent arg0) {
graphics.pause();
graphics.destroy();
audio.dispose();
@@ -189,71 +190,66 @@ void initialize (ApplicationListener listener, JoglApplicationConfiguration conf
}
};
- /**
- * {@inheritDoc}
- */
- @Override public Audio getAudio () {
+ /** {@inheritDoc} */
+ @Override
+ public Audio getAudio () {
return audio;
}
- /**
- * {@inheritDoc}
- */
- @Override public Files getFiles () {
+ /** {@inheritDoc} */
+ @Override
+ public Files getFiles () {
return files;
}
- /**
- * {@inheritDoc}
- */
- @Override public Graphics getGraphics () {
+ /** {@inheritDoc} */
+ @Override
+ public Graphics getGraphics () {
return graphics;
}
- /**
- * {@inheritDoc}
- */
- @Override public Input getInput () {
+ /** {@inheritDoc} */
+ @Override
+ public Input getInput () {
return input;
}
-
- /**
- * {@inheritDoc}
- */
- @Override public ApplicationType getType () {
+ /** {@inheritDoc} */
+ @Override
+ public ApplicationType getType () {
return ApplicationType.Desktop;
}
- @Override public int getVersion () {
+ @Override
+ public int getVersion () {
return 0;
}
- @Override public long getJavaHeap () {
+ @Override
+ public long getJavaHeap () {
return Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory();
}
- @Override public long getNativeHeap () {
+ @Override
+ public long getNativeHeap () {
return getJavaHeap();
}
-
- /**
- * @return the JFrame of the application.
- */
- public JFrame getJFrame() {
+
+ /** @return the JFrame of the application. */
+ public JFrame getJFrame () {
return frame;
}
-
- /**
- * @return the GLCanvas of the application.
- */
- public GLCanvas getGLCanvas() {
+
+ /** @return the GLCanvas of the application. */
+ public GLCanvas getGLCanvas () {
return graphics.canvas;
}
Map preferences = new HashMap();
- @Override public Preferences getPreferences (String name) {
- if(preferences.containsKey(name)) {
+
+ @Override
+ public Preferences getPreferences (String name) {
+ if (preferences.containsKey(name)) {
return preferences.get(name);
} else {
Preferences prefs = new JoglPreferences(name);
@@ -262,51 +258,56 @@ public GLCanvas getGLCanvas() {
}
}
- @Override public void postRunnable (Runnable runnable) {
- synchronized(runnables) {
+ @Override
+ public void postRunnable (Runnable runnable) {
+ synchronized (runnables) {
runnables.add(runnable);
}
}
- public void log(String tag, String message) {
- if(logLevel >= LOG_INFO) {
- System.out.println(tag + ":" + message);
+ public void log (String tag, String message) {
+ if (logLevel >= LOG_INFO) {
+ System.out.println(tag + ":" + message);
}
- }
+ }
- @Override public void log (String tag, String message, Exception exception) {
- if(logLevel >= LOG_INFO) {
+ @Override
+ public void log (String tag, String message, Exception exception) {
+ if (logLevel >= LOG_INFO) {
System.out.println(tag + ":" + message);
exception.printStackTrace(System.out);
}
}
-
- @Override public void error (String tag, String message) {
- if(logLevel >= LOG_ERROR) {
- System.err.println(tag + ":" + message);
+
+ @Override
+ public void error (String tag, String message) {
+ if (logLevel >= LOG_ERROR) {
+ System.err.println(tag + ":" + message);
}
}
-
- @Override public void error (String tag, String message, Exception exception) {
- if(logLevel >= LOG_ERROR) {
+ @Override
+ public void error (String tag, String message, Exception exception) {
+ if (logLevel >= LOG_ERROR) {
System.err.println(tag + ":" + message);
exception.printStackTrace(System.err);
}
}
-
- @Override public void setLogLevel (int logLevel) {
+ @Override
+ public void setLogLevel (int logLevel) {
this.logLevel = logLevel;
}
-
- @Override public void exit () {
+
+ @Override
+ public void exit () {
postRunnable(new Runnable() {
- @Override public void run () {
+ @Override
+ public void run () {
JoglApplication.this.graphics.listener.pause();
JoglApplication.this.graphics.listener.dispose();
System.exit(-1);
- }
+ }
});
}
}
diff --git a/backends/gdx-backend-jogl/src/com/badlogic/gdx/backends/jogl/JoglApplicationConfiguration.java b/backends/gdx-backend-jogl/src/com/badlogic/gdx/backends/jogl/JoglApplicationConfiguration.java
index 48992f1316a..1e1caad10ae 100644
--- a/backends/gdx-backend-jogl/src/com/badlogic/gdx/backends/jogl/JoglApplicationConfiguration.java
+++ b/backends/gdx-backend-jogl/src/com/badlogic/gdx/backends/jogl/JoglApplicationConfiguration.java
@@ -1,3 +1,4 @@
+
package com.badlogic.gdx.backends.jogl;
import java.awt.GraphicsDevice;
@@ -10,7 +11,7 @@
public class JoglApplicationConfiguration {
/** whether to use OpenGL ES 2.0 or not. default: false **/
- public boolean useGL20 = false;
+ public boolean useGL20 = false;
/** number of bits per color channel **/
public int r = 8, g = 8, b = 8, a = 8;
/** number of bits for depth and stencil buffer **/
@@ -24,29 +25,26 @@ public class JoglApplicationConfiguration {
/** whether to enable vsync, can be changed at runtime via {@link Graphics#setVSync(boolean)} **/
public boolean vSyncEnabled = false;
/** title of application **/
- public String title = "Jogl Application";
-
- /**
- * Sets the r, g, b and a bits per channel based on the given
- * {@link DisplayMode} and sets the fullscreen flag to true.
- * @param mode
- */
- public void setFromDisplayMode(DisplayMode mode) {
+ public String title = "Jogl Application";
+
+ /** Sets the r, g, b and a bits per channel based on the given {@link DisplayMode} and sets the fullscreen flag to true.
+ * @param mode */
+ public void setFromDisplayMode (DisplayMode mode) {
this.width = mode.width;
this.height = mode.height;
- if(mode.bitsPerPixel == 16) {
+ if (mode.bitsPerPixel == 16) {
this.r = 5;
this.g = 6;
this.b = 5;
this.a = 0;
}
- if(mode.bitsPerPixel == 24) {
+ if (mode.bitsPerPixel == 24) {
this.r = 8;
this.g = 8;
this.b = 8;
this.a = 0;
}
- if(mode.bitsPerPixel == 32) {
+ if (mode.bitsPerPixel == 32) {
this.r = 8;
this.g = 8;
this.b = 8;
@@ -54,36 +52,35 @@ public void setFromDisplayMode(DisplayMode mode) {
}
this.fullscreen = true;
}
-
+
public static DisplayMode getDesktopDisplayMode () {
GraphicsEnvironment genv = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice device = genv.getDefaultScreenDevice();
java.awt.DisplayMode mode = device.getDisplayMode();
return new JoglDisplayMode(mode.getWidth(), mode.getHeight(), mode.getRefreshRate(), mode.getBitDepth(), mode);
}
-
- public static DisplayMode[] getDisplayModes() {
+
+ public static DisplayMode[] getDisplayModes () {
GraphicsEnvironment genv = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice device = genv.getDefaultScreenDevice();
java.awt.DisplayMode desktopMode = device.getDisplayMode();
java.awt.DisplayMode[] displayModes = device.getDisplayModes();
ArrayList modes = new ArrayList();
int idx = 0;
- for(java.awt.DisplayMode mode: displayModes) {
+ for (java.awt.DisplayMode mode : displayModes) {
boolean duplicate = false;
- for(int i = 0; i < modes.size(); i++) {
- if(modes.get(i).width == mode.getWidth() &&
- modes.get(i).height == mode.getHeight() &&
- modes.get(i).bitsPerPixel == mode.getBitDepth()) {
+ for (int i = 0; i < modes.size(); i++) {
+ if (modes.get(i).width == mode.getWidth() && modes.get(i).height == mode.getHeight()
+ && modes.get(i).bitsPerPixel == mode.getBitDepth()) {
duplicate = true;
break;
}
}
- if(duplicate) continue;
- if(mode.getBitDepth() != desktopMode.getBitDepth()) continue;
+ if (duplicate) continue;
+ if (mode.getBitDepth() != desktopMode.getBitDepth()) continue;
modes.add(new JoglDisplayMode(mode.getWidth(), mode.getHeight(), mode.getRefreshRate(), mode.getBitDepth(), mode));
}
-
+
return modes.toArray(new DisplayMode[modes.size()]);
}
}
diff --git a/backends/gdx-backend-jogl/src/com/badlogic/gdx/backends/jogl/JoglFileHandle.java b/backends/gdx-backend-jogl/src/com/badlogic/gdx/backends/jogl/JoglFileHandle.java
index 15999bc3e39..2effd9a8779 100644
--- a/backends/gdx-backend-jogl/src/com/badlogic/gdx/backends/jogl/JoglFileHandle.java
+++ b/backends/gdx-backend-jogl/src/com/badlogic/gdx/backends/jogl/JoglFileHandle.java
@@ -21,10 +21,8 @@
import com.badlogic.gdx.Files.FileType;
import com.badlogic.gdx.files.FileHandle;
-/**
- * @author mzechner
- * @author Nathan Sweet
- */
+/** @author mzechner
+ * @author Nathan Sweet */
public class JoglFileHandle extends FileHandle {
JoglFileHandle (String fileName, FileType type) {
super(fileName, type);
diff --git a/backends/gdx-backend-jogl/src/com/badlogic/gdx/backends/jogl/JoglFiles.java b/backends/gdx-backend-jogl/src/com/badlogic/gdx/backends/jogl/JoglFiles.java
index 1dfb7b4301a..98ff652fd88 100644
--- a/backends/gdx-backend-jogl/src/com/badlogic/gdx/backends/jogl/JoglFiles.java
+++ b/backends/gdx-backend-jogl/src/com/badlogic/gdx/backends/jogl/JoglFiles.java
@@ -13,43 +13,49 @@
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
+
package com.badlogic.gdx.backends.jogl;
import com.badlogic.gdx.Files;
import com.badlogic.gdx.files.FileHandle;
-/**
- * @author mzechner
- * @author Nathan Sweet
- */
+/** @author mzechner
+ * @author Nathan Sweet */
final class JoglFiles implements Files {
private final String externalPath = System.getProperty("user.home") + "/";
- @Override public FileHandle getFileHandle (String fileName, FileType type) {
+ @Override
+ public FileHandle getFileHandle (String fileName, FileType type) {
return new JoglFileHandle(fileName, type);
}
- @Override public FileHandle classpath (String path) {
+ @Override
+ public FileHandle classpath (String path) {
return new JoglFileHandle(path, FileType.Classpath);
}
- @Override public FileHandle internal (String path) {
+ @Override
+ public FileHandle internal (String path) {
return new JoglFileHandle(path, FileType.Internal);
}
- @Override public FileHandle external (String path) {
+ @Override
+ public FileHandle external (String path) {
return new JoglFileHandle(path, FileType.External);
}
- @Override public FileHandle absolute (String path) {
+ @Override
+ public FileHandle absolute (String path) {
return new JoglFileHandle(path, FileType.Absolute);
}
- @Override public String getExternalStoragePath () {
+ @Override
+ public String getExternalStoragePath () {
return externalPath;
}
- @Override public boolean isExternalStorageAvailable () {
+ @Override
+ public boolean isExternalStorageAvailable () {
return true;
}
}
diff --git a/backends/gdx-backend-jogl/src/com/badlogic/gdx/backends/jogl/JoglGL10.java b/backends/gdx-backend-jogl/src/com/badlogic/gdx/backends/jogl/JoglGL10.java
index 7a873a17860..ab9cac04d27 100644
--- a/backends/gdx-backend-jogl/src/com/badlogic/gdx/backends/jogl/JoglGL10.java
+++ b/backends/gdx-backend-jogl/src/com/badlogic/gdx/backends/jogl/JoglGL10.java
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
+
package com.badlogic.gdx.backends.jogl;
import java.nio.Buffer;
@@ -23,12 +24,9 @@
import com.badlogic.gdx.graphics.GL10;
-/**
- * An implementation of the {@link GL10} interface based on Jogl. Fixed point vertex arrays are emulated.
- *
- * @author mzechner
+/** An implementation of the {@link GL10} interface based on Jogl. Fixed point vertex arrays are emulated.
*
- */
+ * @author mzechner */
class JoglGL10 implements GL10 {
protected final javax.media.opengl.GL gl;
@@ -36,39 +34,48 @@ public JoglGL10 (javax.media.opengl.GL gl) {
this.gl = gl;
}
- @Override public final void glActiveTexture (int texture) {
+ @Override
+ public final void glActiveTexture (int texture) {
gl.glActiveTexture(texture);
}
- @Override public final void glAlphaFunc (int func, float ref) {
+ @Override
+ public final void glAlphaFunc (int func, float ref) {
gl.glAlphaFunc(func, ref);
}
- @Override public final void glBindTexture (int target, int texture) {
+ @Override
+ public final void glBindTexture (int target, int texture) {
gl.glBindTexture(target, texture);
}
- @Override public final void glBlendFunc (int sfactor, int dfactor) {
+ @Override
+ public final void glBlendFunc (int sfactor, int dfactor) {
gl.glBlendFunc(sfactor, dfactor);
}
- @Override public final void glClear (int mask) {
+ @Override
+ public final void glClear (int mask) {
gl.glClear(mask);
}
- @Override public final void glClearColor (float red, float green, float blue, float alpha) {
+ @Override
+ public final void glClearColor (float red, float green, float blue, float alpha) {
gl.glClearColor(red, green, blue, alpha);
}
- @Override public final void glClearDepthf (float depth) {
+ @Override
+ public final void glClearDepthf (float depth) {
gl.glClearDepth(depth);
}
- @Override public final void glClearStencil (int s) {
+ @Override
+ public final void glClearStencil (int s) {
gl.glClearStencil(s);
}
- @Override public final void glClientActiveTexture (int texture) {
+ @Override
+ public final void glClientActiveTexture (int texture) {
try {
gl.glClientActiveTexture(texture);
} catch (Throwable ex) {
@@ -76,328 +83,405 @@ public JoglGL10 (javax.media.opengl.GL gl) {
}
}
- @Override public final void glColor4f (float red, float green, float blue, float alpha) {
+ @Override
+ public final void glColor4f (float red, float green, float blue, float alpha) {
gl.glColor4f(red, green, blue, alpha);
}
- @Override public final void glColorMask (boolean red, boolean green, boolean blue, boolean alpha) {
+ @Override
+ public final void glColorMask (boolean red, boolean green, boolean blue, boolean alpha) {
gl.glColorMask(red, green, blue, alpha);
}
- @Override public final void glColorPointer (int size, int type, int stride, Buffer pointer) {
+ @Override
+ public final void glColorPointer (int size, int type, int stride, Buffer pointer) {
gl.glColorPointer(size, type, stride, pointer);
}
- @Override public final void glCompressedTexImage2D (int target, int level, int internalformat, int width, int height,
- int border, int imageSize, Buffer data) {
+ @Override
+ public final void glCompressedTexImage2D (int target, int level, int internalformat, int width, int height, int border,
+ int imageSize, Buffer data) {
gl.glCompressedTexImage2D(target, level, internalformat, width, height, border, imageSize, data);
}
- @Override public final void glCompressedTexSubImage2D (int target, int level, int xoffset, int yoffset, int width, int height,
+ @Override
+ public final void glCompressedTexSubImage2D (int target, int level, int xoffset, int yoffset, int width, int height,
int format, int imageSize, Buffer data) {
gl.glCompressedTexSubImage2D(target, level, xoffset, yoffset, width, height, format, imageSize, data);
}
- @Override public final void glCopyTexImage2D (int target, int level, int internalformat, int x, int y, int width, int height,
- int border) {
+ @Override
+ public final void glCopyTexImage2D (int target, int level, int internalformat, int x, int y, int width, int height, int border) {
gl.glCopyTexImage2D(target, level, internalformat, x, y, width, height, border);
}
- @Override public final void glCopyTexSubImage2D (int target, int level, int xoffset, int yoffset, int x, int y, int width,
- int height) {
+ @Override
+ public final void glCopyTexSubImage2D (int target, int level, int xoffset, int yoffset, int x, int y, int width, int height) {
gl.glCopyTexSubImage2D(target, level, xoffset, yoffset, x, y, width, height);
}
- @Override public final void glCullFace (int mode) {
+ @Override
+ public final void glCullFace (int mode) {
gl.glCullFace(mode);
}
- @Override public final void glDeleteTextures (int n, IntBuffer textures) {
+ @Override
+ public final void glDeleteTextures (int n, IntBuffer textures) {
gl.glDeleteTextures(n, textures);
}
- @Override public final void glDepthFunc (int func) {
+ @Override
+ public final void glDepthFunc (int func) {
gl.glDepthFunc(func);
}
- @Override public final void glDepthMask (boolean flag) {
+ @Override
+ public final void glDepthMask (boolean flag) {
gl.glDepthMask(flag);
}
- @Override public final void glDepthRangef (float zNear, float zFar) {
+ @Override
+ public final void glDepthRangef (float zNear, float zFar) {
gl.glDepthRange(zNear, zFar);
}
- @Override public final void glDisable (int cap) {
+ @Override
+ public final void glDisable (int cap) {
gl.glDisable(cap);
}
- @Override public final void glDisableClientState (int array) {
+ @Override
+ public final void glDisableClientState (int array) {
gl.glDisableClientState(array);
}
- @Override public final void glDrawArrays (int mode, int first, int count) {
+ @Override
+ public final void glDrawArrays (int mode, int first, int count) {
gl.glDrawArrays(mode, first, count);
}
- @Override public final void glDrawElements (int mode, int count, int type, Buffer indices) {
+ @Override
+ public final void glDrawElements (int mode, int count, int type, Buffer indices) {
// nothing to do here per documentation
gl.glDrawElements(mode, count, type, indices);
}
- @Override public final void glEnable (int cap) {
+ @Override
+ public final void glEnable (int cap) {
gl.glEnable(cap);
}
- @Override public final void glEnableClientState (int array) {
+ @Override
+ public final void glEnableClientState (int array) {
gl.glEnableClientState(array);
}
- @Override public final void glFinish () {
+ @Override
+ public final void glFinish () {
gl.glFinish();
}
- @Override public final void glFlush () {
+ @Override
+ public final void glFlush () {
gl.glFlush();
}
- @Override public final void glFogf (int pname, float param) {
+ @Override
+ public final void glFogf (int pname, float param) {
gl.glFogf(pname, param);
}
- @Override public final void glFogfv (int pname, FloatBuffer params) {
+ @Override
+ public final void glFogfv (int pname, FloatBuffer params) {
gl.glFogfv(pname, params);
}
- @Override public final void glFrontFace (int mode) {
+ @Override
+ public final void glFrontFace (int mode) {
gl.glFrontFace(mode);
}
- @Override public final void glFrustumf (float left, float right, float bottom, float top, float zNear, float zFar) {
+ @Override
+ public final void glFrustumf (float left, float right, float bottom, float top, float zNear, float zFar) {
gl.glFrustum(left, right, bottom, top, zNear, zFar);
}
- @Override public final void glGenTextures (int n, IntBuffer textures) {
+ @Override
+ public final void glGenTextures (int n, IntBuffer textures) {
gl.glGenTextures(n, textures);
}
- @Override public final int glGetError () {
+ @Override
+ public final int glGetError () {
return gl.glGetError();
}
- @Override public final void glGetIntegerv (int pname, IntBuffer params) {
+ @Override
+ public final void glGetIntegerv (int pname, IntBuffer params) {
gl.glGetIntegerv(pname, params);
}
- @Override public final String glGetString (int name) {
+ @Override
+ public final String glGetString (int name) {
return gl.glGetString(name);
}
- @Override public final void glHint (int target, int mode) {
+ @Override
+ public final void glHint (int target, int mode) {
gl.glHint(target, mode);
}
- @Override public final void glLightModelf (int pname, float param) {
+ @Override
+ public final void glLightModelf (int pname, float param) {
gl.glLightModelf(pname, param);
}
- @Override public final void glLightModelfv (int pname, FloatBuffer params) {
+ @Override
+ public final void glLightModelfv (int pname, FloatBuffer params) {
gl.glLightModelfv(pname, params);
}
- @Override public final void glLightf (int light, int pname, float param) {
+ @Override
+ public final void glLightf (int light, int pname, float param) {
gl.glLightf(light, pname, param);
}
- @Override public final void glLightfv (int light, int pname, FloatBuffer params) {
+ @Override
+ public final void glLightfv (int light, int pname, FloatBuffer params) {
gl.glLightfv(light, pname, params);
}
- @Override public final void glLineWidth (float width) {
+ @Override
+ public final void glLineWidth (float width) {
gl.glLineWidth(width);
}
- @Override public final void glLoadIdentity () {
+ @Override
+ public final void glLoadIdentity () {
gl.glLoadIdentity();
}
- @Override public final void glLoadMatrixf (FloatBuffer m) {
+ @Override
+ public final void glLoadMatrixf (FloatBuffer m) {
gl.glLoadMatrixf(m);
}
- @Override public final void glLogicOp (int opcode) {
+ @Override
+ public final void glLogicOp (int opcode) {
gl.glLogicOp(opcode);
}
- @Override public final void glMaterialf (int face, int pname, float param) {
+ @Override
+ public final void glMaterialf (int face, int pname, float param) {
gl.glMaterialf(face, pname, param);
}
- @Override public final void glMaterialfv (int face, int pname, FloatBuffer params) {
+ @Override
+ public final void glMaterialfv (int face, int pname, FloatBuffer params) {
gl.glMaterialfv(face, pname, params);
}
- @Override public final void glMatrixMode (int mode) {
+ @Override
+ public final void glMatrixMode (int mode) {
gl.glMatrixMode(mode);
}
- @Override public final void glMultMatrixf (FloatBuffer m) {
+ @Override
+ public final void glMultMatrixf (FloatBuffer m) {
gl.glMultMatrixf(m);
}
- @Override public final void glMultiTexCoord4f (int target, float s, float t, float r, float q) {
+ @Override
+ public final void glMultiTexCoord4f (int target, float s, float t, float r, float q) {
gl.glMultiTexCoord4f(target, s, t, r, q);
}
- @Override public final void glNormal3f (float nx, float ny, float nz) {
+ @Override
+ public final void glNormal3f (float nx, float ny, float nz) {
gl.glNormal3f(nx, ny, nz);
}
- @Override public final void glNormalPointer (int type, int stride, Buffer pointer) {
+ @Override
+ public final void glNormalPointer (int type, int stride, Buffer pointer) {
gl.glNormalPointer(type, stride, pointer);
}
- @Override public final void glOrthof (float left, float right, float bottom, float top, float zNear, float zFar) {
+ @Override
+ public final void glOrthof (float left, float right, float bottom, float top, float zNear, float zFar) {
gl.glOrtho(left, right, bottom, top, zNear, zFar);
}
- @Override public final void glPixelStorei (int pname, int param) {
+ @Override
+ public final void glPixelStorei (int pname, int param) {
gl.glPixelStorei(pname, param);
}
- @Override public final void glPointSize (float size) {
+ @Override
+ public final void glPointSize (float size) {
gl.glPointSize(size);
}
- @Override public final void glPolygonOffset (float factor, float units) {
+ @Override
+ public final void glPolygonOffset (float factor, float units) {
gl.glPolygonOffset(factor, units);
}
- @Override public final void glPopMatrix () {
+ @Override
+ public final void glPopMatrix () {
gl.glPopMatrix();
}
- @Override public final void glPushMatrix () {
+ @Override
+ public final void glPushMatrix () {
gl.glPushMatrix();
}
- @Override public final void glReadPixels (int x, int y, int width, int height, int format, int type, Buffer pixels) {
+ @Override
+ public final void glReadPixels (int x, int y, int width, int height, int format, int type, Buffer pixels) {
gl.glReadPixels(x, y, width, height, format, type, pixels);
}
- @Override public final void glRotatef (float angle, float x, float y, float z) {
+ @Override
+ public final void glRotatef (float angle, float x, float y, float z) {
gl.glRotatef(angle, x, y, z);
}
- @Override public final void glSampleCoverage (float value, boolean invert) {
+ @Override
+ public final void glSampleCoverage (float value, boolean invert) {
gl.glSampleCoverage(value, invert);
}
- @Override public final void glScalef (float x, float y, float z) {
+ @Override
+ public final void glScalef (float x, float y, float z) {
gl.glScalef(x, y, z);
}
- @Override public final void glScissor (int x, int y, int width, int height) {
+ @Override
+ public final void glScissor (int x, int y, int width, int height) {
gl.glScissor(x, y, width, height);
}
- @Override public final void glShadeModel (int mode) {
+ @Override
+ public final void glShadeModel (int mode) {
gl.glShadeModel(mode);
}
- @Override public final void glStencilFunc (int func, int ref, int mask) {
+ @Override
+ public final void glStencilFunc (int func, int ref, int mask) {
gl.glStencilFunc(func, ref, mask);
}
- @Override public final void glStencilMask (int mask) {
+ @Override
+ public final void glStencilMask (int mask) {
gl.glStencilMask(mask);
}
- @Override public final void glStencilOp (int fail, int zfail, int zpass) {
+ @Override
+ public final void glStencilOp (int fail, int zfail, int zpass) {
gl.glStencilOp(fail, zfail, zpass);
}
- @Override public final void glTexCoordPointer (int size, int type, int stride, Buffer pointer) {
+ @Override
+ public final void glTexCoordPointer (int size, int type, int stride, Buffer pointer) {
gl.glTexCoordPointer(size, type, stride, pointer);
}
- @Override public final void glTexEnvf (int target, int pname, float param) {
+ @Override
+ public final void glTexEnvf (int target, int pname, float param) {
gl.glTexEnvf(target, pname, param);
}
- @Override public final void glTexEnvfv (int target, int pname, FloatBuffer params) {
+ @Override
+ public final void glTexEnvfv (int target, int pname, FloatBuffer params) {
gl.glTexEnvfv(target, pname, params);
}
- @Override public final void glTexImage2D (int target, int level, int internalformat, int width, int height, int border,
- int format, int type, Buffer pixels) {
+ @Override
+ public final void glTexImage2D (int target, int level, int internalformat, int width, int height, int border, int format,
+ int type, Buffer pixels) {
gl.glTexImage2D(target, level, internalformat, width, height, border, format, type, pixels);
}
- @Override public final void glTexParameterf (int target, int pname, float param) {
+ @Override
+ public final void glTexParameterf (int target, int pname, float param) {
// JoglGL10.major is should to be 1 if we are in JoglGL10.
if (JoglGraphics.minor < 2 && param == GL.GL_CLAMP_TO_EDGE) param = GL.GL_CLAMP;
gl.glTexParameterf(target, pname, param);
}
- @Override public final void glTexSubImage2D (int target, int level, int xoffset, int yoffset, int width, int height,
- int format, int type, Buffer pixels) {
+ @Override
+ public final void glTexSubImage2D (int target, int level, int xoffset, int yoffset, int width, int height, int format,
+ int type, Buffer pixels) {
gl.glTexSubImage2D(target, level, xoffset, yoffset, width, height, format, type, pixels);
}
- @Override public final void glTranslatef (float x, float y, float z) {
+ @Override
+ public final void glTranslatef (float x, float y, float z) {
gl.glTranslatef(x, y, z);
}
- @Override public final void glVertexPointer (int size, int type, int stride, Buffer pointer) {
+ @Override
+ public final void glVertexPointer (int size, int type, int stride, Buffer pointer) {
gl.glVertexPointer(size, GL10.GL_FLOAT, stride, pointer);
}
- @Override public final void glViewport (int x, int y, int width, int height) {
+ @Override
+ public final void glViewport (int x, int y, int width, int height) {
gl.glViewport(x, y, width, height);
}
- @Override public final void glDeleteTextures (int n, int[] textures, int offset) {
+ @Override
+ public final void glDeleteTextures (int n, int[] textures, int offset) {
gl.glDeleteTextures(n, textures, offset);
}
- @Override public final void glFogfv (int pname, float[] params, int offset) {
+ @Override
+ public final void glFogfv (int pname, float[] params, int offset) {
gl.glFogfv(pname, params, offset);
}
- @Override public final void glGenTextures (int n, int[] textures, int offset) {
+ @Override
+ public final void glGenTextures (int n, int[] textures, int offset) {
gl.glGenTextures(n, textures, offset);
}
- @Override public final void glGetIntegerv (int pname, int[] params, int offset) {
+ @Override
+ public final void glGetIntegerv (int pname, int[] params, int offset) {
gl.glGetIntegerv(pname, params, offset);
}
- @Override public final void glLightModelfv (int pname, float[] params, int offset) {
+ @Override
+ public final void glLightModelfv (int pname, float[] params, int offset) {
gl.glLightModelfv(pname, params, offset);
}
- @Override public final void glLightfv (int light, int pname, float[] params, int offset) {
+ @Override
+ public final void glLightfv (int light, int pname, float[] params, int offset) {
gl.glLightfv(light, pname, params, offset);
}
- @Override public final void glLoadMatrixf (float[] m, int offset) {
+ @Override
+ public final void glLoadMatrixf (float[] m, int offset) {
gl.glLoadMatrixf(m, offset);
}
- @Override public final void glMaterialfv (int face, int pname, float[] params, int offset) {
+ @Override
+ public final void glMaterialfv (int face, int pname, float[] params, int offset) {
gl.glMaterialfv(face, pname, params, offset);
}
- @Override public final void glMultMatrixf (float[] m, int offset) {
+ @Override
+ public final void glMultMatrixf (float[] m, int offset) {
gl.glMultMatrixf(m, offset);
}
- @Override public final void glTexEnvfv (int target, int pname, float[] params, int offset) {
+ @Override
+ public final void glTexEnvfv (int target, int pname, float[] params, int offset) {
gl.glTexEnvfv(target, pname, params, offset);
}
- @Override public void glPolygonMode (int face, int mode) {
+ @Override
+ public void glPolygonMode (int face, int mode) {
gl.glPolygonMode(face, mode);
}
}
diff --git a/backends/gdx-backend-jogl/src/com/badlogic/gdx/backends/jogl/JoglGL11.java b/backends/gdx-backend-jogl/src/com/badlogic/gdx/backends/jogl/JoglGL11.java
index 0f6544e814b..402e3650c26 100644
--- a/backends/gdx-backend-jogl/src/com/badlogic/gdx/backends/jogl/JoglGL11.java
+++ b/backends/gdx-backend-jogl/src/com/badlogic/gdx/backends/jogl/JoglGL11.java
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
+
package com.badlogic.gdx.backends.jogl;
import java.nio.Buffer;
@@ -23,212 +24,258 @@
import com.badlogic.gdx.graphics.GL11;
-/**
- * An implementation of the {@link GL11} interface based on Jogl. Fixed point vertex arrays are emulated. Some glGetXXX methods
+/** An implementation of the {@link GL11} interface based on Jogl. Fixed point vertex arrays are emulated. Some glGetXXX methods
* are not implemented.
*
- * @author mzechner
- *
- */
+ * @author mzechner */
public final class JoglGL11 extends JoglGL10 implements GL11 {
public JoglGL11 (GL gl) {
super(gl);
}
- @Override public void glBindBuffer (int target, int buffer) {
+ @Override
+ public void glBindBuffer (int target, int buffer) {
gl.glBindBuffer(target, buffer);
}
- @Override public void glBufferData (int target, int size, Buffer data, int usage) {
+ @Override
+ public void glBufferData (int target, int size, Buffer data, int usage) {
gl.glBufferData(target, size, data, usage);
}
- @Override public void glBufferSubData (int target, int offset, int size, Buffer data) {
+ @Override
+ public void glBufferSubData (int target, int offset, int size, Buffer data) {
gl.glBufferSubData(target, offset, size, data);
}
- @Override public void glClipPlanef (int plane, float[] equation, int offset) {
+ @Override
+ public void glClipPlanef (int plane, float[] equation, int offset) {
throw new UnsupportedOperationException("not implemented");
}
- @Override public void glClipPlanef (int plane, FloatBuffer equation) {
+ @Override
+ public void glClipPlanef (int plane, FloatBuffer equation) {
throw new UnsupportedOperationException("not implemented");
}
- @Override public void glColor4ub (byte red, byte green, byte blue, byte alpha) {
+ @Override
+ public void glColor4ub (byte red, byte green, byte blue, byte alpha) {
throw new UnsupportedOperationException("not implemented");
}
- @Override public void glDeleteBuffers (int n, int[] buffers, int offset) {
+ @Override
+ public void glDeleteBuffers (int n, int[] buffers, int offset) {
gl.glDeleteBuffers(n, buffers, offset);
}
- @Override public void glDeleteBuffers (int n, IntBuffer buffers) {
+ @Override
+ public void glDeleteBuffers (int n, IntBuffer buffers) {
gl.glDeleteBuffers(n, buffers);
}
- @Override public void glGenBuffers (int n, int[] buffers, int offset) {
+ @Override
+ public void glGenBuffers (int n, int[] buffers, int offset) {
gl.glGenBuffers(n, buffers, offset);
}
- @Override public void glGenBuffers (int n, IntBuffer buffers) {
+ @Override
+ public void glGenBuffers (int n, IntBuffer buffers) {
gl.glGenBuffers(n, buffers);
}
- @Override public void glGetBooleanv (int pname, boolean[] params, int offset) {
+ @Override
+ public void glGetBooleanv (int pname, boolean[] params, int offset) {
throw new UnsupportedOperationException("not implemented");
}
- @Override public void glGetBooleanv (int pname, IntBuffer params) {
+ @Override
+ public void glGetBooleanv (int pname, IntBuffer params) {
throw new UnsupportedOperationException("not implemented");
}
- @Override public void glGetBufferParameteriv (int target, int pname, int[] params, int offset) {
+ @Override
+ public void glGetBufferParameteriv (int target, int pname, int[] params, int offset) {
gl.glGetBufferParameteriv(target, pname, params, offset);
}
- @Override public void glGetBufferParameteriv (int target, int pname, IntBuffer params) {
+ @Override
+ public void glGetBufferParameteriv (int target, int pname, IntBuffer params) {
gl.glGetBufferParameteriv(target, pname, params);
}
- @Override public void glGetClipPlanef (int pname, float[] eqn, int offset) {
+ @Override
+ public void glGetClipPlanef (int pname, float[] eqn, int offset) {
throw new UnsupportedOperationException("not implemented");
}
- @Override public void glGetClipPlanef (int pname, FloatBuffer eqn) {
+ @Override
+ public void glGetClipPlanef (int pname, FloatBuffer eqn) {
throw new UnsupportedOperationException("not implemented");
}
- @Override public void glGetFloatv (int pname, float[] params, int offset) {
+ @Override
+ public void glGetFloatv (int pname, float[] params, int offset) {
gl.glGetFloatv(pname, params, offset);
}
- @Override public void glGetFloatv (int pname, FloatBuffer params) {
+ @Override
+ public void glGetFloatv (int pname, FloatBuffer params) {
gl.glGetFloatv(pname, params);
}
- @Override public void glGetLightfv (int light, int pname, float[] params, int offset) {
+ @Override
+ public void glGetLightfv (int light, int pname, float[] params, int offset) {
gl.glGetLightfv(light, pname, params, offset);
}
- @Override public void glGetLightfv (int light, int pname, FloatBuffer params) {
+ @Override
+ public void glGetLightfv (int light, int pname, FloatBuffer params) {
gl.glGetLightfv(light, pname, params);
}
- @Override public void glGetMaterialfv (int face, int pname, float[] params, int offset) {
+ @Override
+ public void glGetMaterialfv (int face, int pname, float[] params, int offset) {
gl.glGetMaterialfv(face, pname, params, offset);
}
- @Override public void glGetMaterialfv (int face, int pname, FloatBuffer params) {
+ @Override
+ public void glGetMaterialfv (int face, int pname, FloatBuffer params) {
gl.glGetMaterialfv(face, pname, params);
}
- @Override public void glGetPointerv (int pname, Buffer[] params) {
+ @Override
+ public void glGetPointerv (int pname, Buffer[] params) {
throw new UnsupportedOperationException("not implemented");
}
- @Override public void glGetTexEnviv (int env, int pname, int[] params, int offset) {
+ @Override
+ public void glGetTexEnviv (int env, int pname, int[] params, int offset) {
gl.glGetTexEnviv(env, pname, params, offset);
}
- @Override public void glGetTexEnviv (int env, int pname, IntBuffer params) {
+ @Override
+ public void glGetTexEnviv (int env, int pname, IntBuffer params) {
gl.glGetTexEnviv(env, pname, params);
}
- @Override public void glGetTexParameterfv (int target, int pname, float[] params, int offset) {
+ @Override
+ public void glGetTexParameterfv (int target, int pname, float[] params, int offset) {
gl.glGetTexParameterfv(target, pname, params, offset);
}
- @Override public void glGetTexParameterfv (int target, int pname, FloatBuffer params) {
+ @Override
+ public void glGetTexParameterfv (int target, int pname, FloatBuffer params) {
gl.glGetTexParameterfv(target, pname, params);
}
- @Override public void glGetTexParameteriv (int target, int pname, int[] params, int offset) {
+ @Override
+ public void glGetTexParameteriv (int target, int pname, int[] params, int offset) {
gl.glGetTexParameteriv(target, pname, params, offset);
}
- @Override public void glGetTexParameteriv (int target, int pname, IntBuffer params) {
+ @Override
+ public void glGetTexParameteriv (int target, int pname, IntBuffer params) {
gl.glGetTexParameteriv(target, pname, params);
}
- @Override public boolean glIsBuffer (int buffer) {
+ @Override
+ public boolean glIsBuffer (int buffer) {
return gl.glIsBuffer(buffer);
}
- @Override public boolean glIsEnabled (int cap) {
+ @Override
+ public boolean glIsEnabled (int cap) {
return gl.glIsEnabled(cap);
}
- @Override public boolean glIsTexture (int texture) {
+ @Override
+ public boolean glIsTexture (int texture) {
return gl.glIsTexture(texture);
}
- @Override public void glPointParameterf (int pname, float param) {
+ @Override
+ public void glPointParameterf (int pname, float param) {
gl.glPointParameterf(pname, param);
}
- @Override public void glPointParameterfv (int pname, float[] params, int offset) {
+ @Override
+ public void glPointParameterfv (int pname, float[] params, int offset) {
gl.glPointParameterfv(pname, params, offset);
}
- @Override public void glPointParameterfv (int pname, FloatBuffer params) {
+ @Override
+ public void glPointParameterfv (int pname, FloatBuffer params) {
gl.glPointParameterfv(pname, params);
}
- @Override public void glPointSizePointerOES (int type, int stride, Buffer pointer) {
+ @Override
+ public void glPointSizePointerOES (int type, int stride, Buffer pointer) {
throw new UnsupportedOperationException("not implemented");
}
- @Override public void glTexEnvi (int target, int pname, int param) {
+ @Override
+ public void glTexEnvi (int target, int pname, int param) {
gl.glTexEnvi(target, pname, param);
}
- @Override public void glTexEnviv (int target, int pname, int[] params, int offset) {
+ @Override
+ public void glTexEnviv (int target, int pname, int[] params, int offset) {
gl.glTexEnviv(target, pname, params, offset);
}
- @Override public void glTexEnviv (int target, int pname, IntBuffer params) {
+ @Override
+ public void glTexEnviv (int target, int pname, IntBuffer params) {
gl.glTexEnviv(target, pname, params);
}
- @Override public void glTexParameterfv (int target, int pname, float[] params, int offset) {
+ @Override
+ public void glTexParameterfv (int target, int pname, float[] params, int offset) {
gl.glTexParameterfv(target, pname, params, offset);
}
- @Override public void glTexParameterfv (int target, int pname, FloatBuffer params) {
+ @Override
+ public void glTexParameterfv (int target, int pname, FloatBuffer params) {
gl.glTexParameterfv(target, pname, params);
}
- @Override public void glTexParameteri (int target, int pname, int param) {
+ @Override
+ public void glTexParameteri (int target, int pname, int param) {
gl.glTexParameteri(target, pname, param);
}
- @Override public void glTexParameteriv (int target, int pname, int[] params, int offset) {
+ @Override
+ public void glTexParameteriv (int target, int pname, int[] params, int offset) {
gl.glTexParameteriv(target, pname, params, offset);
}
- @Override public void glTexParameteriv (int target, int pname, IntBuffer params) {
+ @Override
+ public void glTexParameteriv (int target, int pname, IntBuffer params) {
gl.glTexParameteriv(target, pname, params);
}
- @Override public void glColorPointer (int size, int type, int stride, int pointer) {
+ @Override
+ public void glColorPointer (int size, int type, int stride, int pointer) {
gl.glColorPointer(size, type, stride, pointer);
}
- @Override public void glNormalPointer (int type, int stride, int pointer) {
+ @Override
+ public void glNormalPointer (int type, int stride, int pointer) {
gl.glNormalPointer(type, stride, pointer);
}
- @Override public void glTexCoordPointer (int size, int type, int stride, int pointer) {
+ @Override
+ public void glTexCoordPointer (int size, int type, int stride, int pointer) {
gl.glTexCoordPointer(size, type, stride, pointer);
}
- @Override public void glVertexPointer (int size, int type, int stride, int pointer) {
+ @Override
+ public void glVertexPointer (int size, int type, int stride, int pointer) {
gl.glVertexPointer(size, type, stride, pointer);
}
- @Override public void glDrawElements (int mode, int count, int type, int indices) {
+ @Override
+ public void glDrawElements (int mode, int count, int type, int indices) {
gl.glDrawElements(mode, count, type, indices);
}
}
diff --git a/backends/gdx-backend-jogl/src/com/badlogic/gdx/backends/jogl/JoglGL20.java b/backends/gdx-backend-jogl/src/com/badlogic/gdx/backends/jogl/JoglGL20.java
index 4bdc1d1eb0b..25cd0c5c701 100644
--- a/backends/gdx-backend-jogl/src/com/badlogic/gdx/backends/jogl/JoglGL20.java
+++ b/backends/gdx-backend-jogl/src/com/badlogic/gdx/backends/jogl/JoglGL20.java
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
+
package com.badlogic.gdx.backends.jogl;
import java.nio.Buffer;
@@ -25,13 +26,10 @@
import com.badlogic.gdx.graphics.GL20;
-/**
- * An implementation of the {@link GL20} interface based on Jogl. Note that Jogl shaders and OpenGL ES shaders will not be 100%
+/** An implementation of the {@link GL20} interface based on Jogl. Note that Jogl shaders and OpenGL ES shaders will not be 100%
* compatible. Some glGetXXX methods are not implemented.
*
- * @author mzechner
- *
- */
+ * @author mzechner */
final class JoglGL20 implements GL20 {
private final GL gl;
@@ -39,282 +37,346 @@ public JoglGL20 (GL gl) {
this.gl = gl;
}
- @Override public void glActiveTexture (int texture) {
+ @Override
+ public void glActiveTexture (int texture) {
gl.glActiveTexture(texture);
}
- @Override public void glAttachShader (int program, int shader) {
+ @Override
+ public void glAttachShader (int program, int shader) {
gl.glAttachShader(program, shader);
}
- @Override public void glBindAttribLocation (int program, int index, String name) {
+ @Override
+ public void glBindAttribLocation (int program, int index, String name) {
gl.glBindAttribLocation(program, index, name);
}
- @Override public void glBindBuffer (int target, int buffer) {
+ @Override
+ public void glBindBuffer (int target, int buffer) {
gl.glBindBuffer(target, buffer);
}
- @Override public void glBindFramebuffer (int target, int framebuffer) {
+ @Override
+ public void glBindFramebuffer (int target, int framebuffer) {
gl.glBindFramebufferEXT(target, framebuffer);
}
- @Override public void glBindRenderbuffer (int target, int renderbuffer) {
+ @Override
+ public void glBindRenderbuffer (int target, int renderbuffer) {
gl.glBindRenderbufferEXT(target, renderbuffer);
}
- @Override public void glBindTexture (int target, int texture) {
+ @Override
+ public void glBindTexture (int target, int texture) {
gl.glBindTexture(target, texture);
}
- @Override public void glBlendColor (float red, float green, float blue, float alpha) {
+ @Override
+ public void glBlendColor (float red, float green, float blue, float alpha) {
gl.glBlendColor(red, green, blue, alpha);
}
- @Override public void glBlendEquation (int mode) {
+ @Override
+ public void glBlendEquation (int mode) {
gl.glBlendEquation(mode);
}
- @Override public void glBlendEquationSeparate (int modeRGB, int modeAlpha) {
+ @Override
+ public void glBlendEquationSeparate (int modeRGB, int modeAlpha) {
gl.glBlendEquationSeparate(modeRGB, modeAlpha);
}
- @Override public void glBlendFunc (int sfactor, int dfactor) {
+ @Override
+ public void glBlendFunc (int sfactor, int dfactor) {
gl.glBlendFunc(sfactor, dfactor);
}
- @Override public void glBlendFuncSeparate (int srcRGB, int dstRGB, int srcAlpha, int dstAlpha) {
+ @Override
+ public void glBlendFuncSeparate (int srcRGB, int dstRGB, int srcAlpha, int dstAlpha) {
gl.glBlendFuncSeparate(srcRGB, dstRGB, srcAlpha, dstAlpha);
}
- @Override public void glBufferData (int target, int size, Buffer data, int usage) {
+ @Override
+ public void glBufferData (int target, int size, Buffer data, int usage) {
gl.glBufferData(target, size, data, usage);
}
- @Override public void glBufferSubData (int target, int offset, int size, Buffer data) {
+ @Override
+ public void glBufferSubData (int target, int offset, int size, Buffer data) {
gl.glBufferSubData(target, offset, size, data);
}
- @Override public int glCheckFramebufferStatus (int target) {
+ @Override
+ public int glCheckFramebufferStatus (int target) {
return gl.glCheckFramebufferStatusEXT(target);
}
- @Override public void glClear (int mask) {
+ @Override
+ public void glClear (int mask) {
gl.glClear(mask);
}
- @Override public void glClearColor (float red, float green, float blue, float alpha) {
+ @Override
+ public void glClearColor (float red, float green, float blue, float alpha) {
gl.glClearColor(red, green, blue, alpha);
}
- @Override public void glClearDepthf (float depth) {
+ @Override
+ public void glClearDepthf (float depth) {
gl.glClearDepth(depth);
}
- @Override public void glClearStencil (int s) {
+ @Override
+ public void glClearStencil (int s) {
gl.glClearStencil(s);
}
- @Override public void glColorMask (boolean red, boolean green, boolean blue, boolean alpha) {
+ @Override
+ public void glColorMask (boolean red, boolean green, boolean blue, boolean alpha) {
gl.glColorMask(red, green, blue, alpha);
}
- @Override public void glCompileShader (int shader) {
+ @Override
+ public void glCompileShader (int shader) {
gl.glCompileShader(shader);
}
- @Override public void glCompressedTexImage2D (int target, int level, int internalformat, int width, int height, int border,
+ @Override
+ public void glCompressedTexImage2D (int target, int level, int internalformat, int width, int height, int border,
int imageSize, Buffer data) {
gl.glCompressedTexImage2D(target, level, internalformat, width, height, border, imageSize, data);
}
- @Override public void glCompressedTexSubImage2D (int target, int level, int xoffset, int yoffset, int width, int height,
- int format, int imageSize, Buffer data) {
+ @Override
+ public void glCompressedTexSubImage2D (int target, int level, int xoffset, int yoffset, int width, int height, int format,
+ int imageSize, Buffer data) {
gl.glCompressedTexSubImage2D(target, level, xoffset, yoffset, width, height, format, imageSize, data);
}
- @Override public void glCopyTexImage2D (int target, int level, int internalformat, int x, int y, int width, int height,
- int border) {
+ @Override
+ public void glCopyTexImage2D (int target, int level, int internalformat, int x, int y, int width, int height, int border) {
gl.glCopyTexImage2D(target, level, internalformat, x, y, width, height, border);
}
- @Override public void glCopyTexSubImage2D (int target, int level, int xoffset, int yoffset, int x, int y, int width, int height) {
+ @Override
+ public void glCopyTexSubImage2D (int target, int level, int xoffset, int yoffset, int x, int y, int width, int height) {
gl.glCopyTexSubImage2D(target, level, xoffset, yoffset, x, y, width, height);
}
- @Override public int glCreateProgram () {
+ @Override
+ public int glCreateProgram () {
return gl.glCreateProgram();
}
- @Override public int glCreateShader (int type) {
+ @Override
+ public int glCreateShader (int type) {
return gl.glCreateShader(type);
}
- @Override public void glCullFace (int mode) {
+ @Override
+ public void glCullFace (int mode) {
gl.glCullFace(mode);
}
- @Override public void glDeleteBuffers (int n, IntBuffer buffers) {
+ @Override
+ public void glDeleteBuffers (int n, IntBuffer buffers) {
gl.glDeleteBuffers(n, buffers);
}
- @Override public void glDeleteFramebuffers (int n, IntBuffer framebuffers) {
+ @Override
+ public void glDeleteFramebuffers (int n, IntBuffer framebuffers) {
gl.glDeleteFramebuffersEXT(n, framebuffers);
}
- @Override public void glDeleteProgram (int program) {
+ @Override
+ public void glDeleteProgram (int program) {
gl.glDeleteProgram(program);
}
- @Override public void glDeleteRenderbuffers (int n, IntBuffer renderbuffers) {
+ @Override
+ public void glDeleteRenderbuffers (int n, IntBuffer renderbuffers) {
gl.glDeleteRenderbuffersEXT(n, renderbuffers);
}
- @Override public void glDeleteShader (int shader) {
+ @Override
+ public void glDeleteShader (int shader) {
gl.glDeleteShader(shader);
}
- @Override public void glDeleteTextures (int n, IntBuffer textures) {
+ @Override
+ public void glDeleteTextures (int n, IntBuffer textures) {
gl.glDeleteTextures(n, textures);
}
- @Override public void glDepthFunc (int func) {
+ @Override
+ public void glDepthFunc (int func) {
gl.glDepthFunc(func);
}
- @Override public void glDepthMask (boolean flag) {
+ @Override
+ public void glDepthMask (boolean flag) {
gl.glDepthMask(flag);
}
- @Override public void glDepthRangef (float zNear, float zFar) {
+ @Override
+ public void glDepthRangef (float zNear, float zFar) {
gl.glDepthRange(zNear, zFar);
}
- @Override public void glDetachShader (int program, int shader) {
+ @Override
+ public void glDetachShader (int program, int shader) {
gl.glDetachShader(program, shader);
}
- @Override public void glDisable (int cap) {
+ @Override
+ public void glDisable (int cap) {
gl.glDisable(cap);
}
- @Override public void glDisableVertexAttribArray (int index) {
+ @Override
+ public void glDisableVertexAttribArray (int index) {
gl.glDisableVertexAttribArray(index);
}
- @Override public void glDrawArrays (int mode, int first, int count) {
+ @Override
+ public void glDrawArrays (int mode, int first, int count) {
gl.glDrawArrays(mode, first, count);
}
- @Override public void glDrawElements (int mode, int count, int type, Buffer indices) {
+ @Override
+ public void glDrawElements (int mode, int count, int type, Buffer indices) {
gl.glDrawElements(mode, count, type, indices);
}
- @Override public void glEnable (int cap) {
+ @Override
+ public void glEnable (int cap) {
gl.glEnable(cap);
}
- @Override public void glEnableVertexAttribArray (int index) {
+ @Override
+ public void glEnableVertexAttribArray (int index) {
gl.glEnableVertexAttribArray(index);
}
- @Override public void glFinish () {
+ @Override
+ public void glFinish () {
gl.glFinish();
}
- @Override public void glFlush () {
+ @Override
+ public void glFlush () {
gl.glFlush();
}
- @Override public void glFramebufferRenderbuffer (int target, int attachment, int renderbuffertarget, int renderbuffer) {
+ @Override
+ public void glFramebufferRenderbuffer (int target, int attachment, int renderbuffertarget, int renderbuffer) {
gl.glFramebufferRenderbufferEXT(target, attachment, renderbuffertarget, renderbuffer);
}
- @Override public void glFramebufferTexture2D (int target, int attachment, int textarget, int texture, int level) {
+ @Override
+ public void glFramebufferTexture2D (int target, int attachment, int textarget, int texture, int level) {
gl.glFramebufferTexture2DEXT(target, attachment, textarget, texture, level);
}
- @Override public void glFrontFace (int mode) {
+ @Override
+ public void glFrontFace (int mode) {
gl.glFrontFace(mode);
}
- @Override public void glGenBuffers (int n, IntBuffer buffers) {
+ @Override
+ public void glGenBuffers (int n, IntBuffer buffers) {
gl.glGenBuffers(n, buffers);
}
- @Override public void glGenFramebuffers (int n, IntBuffer framebuffers) {
+ @Override
+ public void glGenFramebuffers (int n, IntBuffer framebuffers) {
gl.glGenFramebuffersEXT(n, framebuffers);
}
- @Override public void glGenRenderbuffers (int n, IntBuffer renderbuffers) {
+ @Override
+ public void glGenRenderbuffers (int n, IntBuffer renderbuffers) {
gl.glGenRenderbuffersEXT(n, renderbuffers);
}
- @Override public void glGenTextures (int n, IntBuffer textures) {
+ @Override
+ public void glGenTextures (int n, IntBuffer textures) {
gl.glGenTextures(n, textures);
}
- @Override public void glGenerateMipmap (int target) {
+ @Override
+ public void glGenerateMipmap (int target) {
gl.glGenerateMipmapEXT(target);
}
- @Override public String glGetActiveAttrib (int program, int index, IntBuffer size, Buffer type) {
+ @Override
+ public String glGetActiveAttrib (int program, int index, IntBuffer size, Buffer type) {
int[] length = new int[1];
int[] sizeTmp = new int[2];
int[] typeTmp = new int[1];
byte[] name = new byte[256];
gl.glGetActiveAttrib(program, index, 256, length, 0, sizeTmp, 0, typeTmp, 0, name, 0);
-
+
size.put(sizeTmp[0]);
- if(type instanceof IntBuffer) ((IntBuffer)type).put(typeTmp[0]);
+ if (type instanceof IntBuffer) ((IntBuffer)type).put(typeTmp[0]);
return new String(name, 0, length[0]);
}
- @Override public String glGetActiveUniform (int program, int index, IntBuffer size, Buffer type) {
+ @Override
+ public String glGetActiveUniform (int program, int index, IntBuffer size, Buffer type) {
int[] length = new int[1];
int[] sizeTmp = new int[2];
int[] typeTmp = new int[1];
byte[] name = new byte[256];
gl.glGetActiveUniform(program, index, 256, length, 0, sizeTmp, 0, typeTmp, 0, name, 0);
-
+
size.put(sizeTmp[0]);
- if(type instanceof IntBuffer) ((IntBuffer)type).put(typeTmp[0]);
+ if (type instanceof IntBuffer) ((IntBuffer)type).put(typeTmp[0]);
return new String(name, 0, length[0]);
}
- @Override public void glGetAttachedShaders (int program, int maxcount, Buffer count, IntBuffer shaders) {
+ @Override
+ public void glGetAttachedShaders (int program, int maxcount, Buffer count, IntBuffer shaders) {
gl.glGetAttachedShaders(program, maxcount, (IntBuffer)count, shaders);
}
- @Override public int glGetAttribLocation (int program, String name) {
+ @Override
+ public int glGetAttribLocation (int program, String name) {
return gl.glGetAttribLocation(program, name);
}
- @Override public void glGetBooleanv (int pname, Buffer params) {
+ @Override
+ public void glGetBooleanv (int pname, Buffer params) {
throw new UnsupportedOperationException("not implemented"); // FIXME
}
- @Override public void glGetBufferParameteriv (int target, int pname, IntBuffer params) {
+ @Override
+ public void glGetBufferParameteriv (int target, int pname, IntBuffer params) {
gl.glGetBufferParameteriv(target, pname, params);
}
- @Override public int glGetError () {
+ @Override
+ public int glGetError () {
return gl.glGetError();
}
- @Override public void glGetFloatv (int pname, FloatBuffer params) {
+ @Override
+ public void glGetFloatv (int pname, FloatBuffer params) {
gl.glGetFloatv(pname, params);
}
- @Override public void glGetFramebufferAttachmentParameteriv (int target, int attachment, int pname, IntBuffer params) {
+ @Override
+ public void glGetFramebufferAttachmentParameteriv (int target, int attachment, int pname, IntBuffer params) {
gl.glGetFramebufferAttachmentParameterivEXT(target, attachment, pname, params);
}
- @Override public void glGetIntegerv (int pname, IntBuffer params) {
+ @Override
+ public void glGetIntegerv (int pname, IntBuffer params) {
gl.glGetIntegerv(pname, params);
}
- @Override public String glGetProgramInfoLog (int program) {
+ @Override
+ public String glGetProgramInfoLog (int program) {
ByteBuffer buffer = ByteBuffer.allocateDirect(1024 * 10);
buffer.order(ByteOrder.nativeOrder());
ByteBuffer tmp = ByteBuffer.allocateDirect(4);
@@ -328,15 +390,18 @@ public JoglGL20 (GL gl) {
return new String(bytes);
}
- @Override public void glGetProgramiv (int program, int pname, IntBuffer params) {
+ @Override
+ public void glGetProgramiv (int program, int pname, IntBuffer params) {
gl.glGetProgramiv(program, pname, params);
}
- @Override public void glGetRenderbufferParameteriv (int target, int pname, IntBuffer params) {
+ @Override
+ public void glGetRenderbufferParameteriv (int target, int pname, IntBuffer params) {
gl.glGetRenderbufferParameterivEXT(target, pname, params);
}
- @Override public String glGetShaderInfoLog (int shader) {
+ @Override
+ public String glGetShaderInfoLog (int shader) {
ByteBuffer buffer = ByteBuffer.allocateDirect(1024 * 10);
buffer.order(ByteOrder.nativeOrder());
ByteBuffer tmp = ByteBuffer.allocateDirect(4);
@@ -350,310 +415,386 @@ public JoglGL20 (GL gl) {
return new String(bytes);
}
- @Override public void glGetShaderPrecisionFormat (int shadertype, int precisiontype, IntBuffer range, IntBuffer precision) {
+ @Override
+ public void glGetShaderPrecisionFormat (int shadertype, int precisiontype, IntBuffer range, IntBuffer precision) {
throw new UnsupportedOperationException("unsupported, won't implement");
}
- @Override public void glGetShaderSource (int shader, int bufsize, Buffer length, String source) {
+ @Override
+ public void glGetShaderSource (int shader, int bufsize, Buffer length, String source) {
throw new UnsupportedOperationException("unsupported, won't implement.");
}
- @Override public void glGetShaderiv (int shader, int pname, IntBuffer params) {
+ @Override
+ public void glGetShaderiv (int shader, int pname, IntBuffer params) {
gl.glGetShaderiv(shader, pname, params);
}
- @Override public String glGetString (int name) {
+ @Override
+ public String glGetString (int name) {
return gl.glGetString(name);
}
- @Override public void glGetTexParameterfv (int target, int pname, FloatBuffer params) {
+ @Override
+ public void glGetTexParameterfv (int target, int pname, FloatBuffer params) {
gl.glGetTexParameterfv(target, pname, params);
}
- @Override public void glGetTexParameteriv (int target, int pname, IntBuffer params) {
+ @Override
+ public void glGetTexParameteriv (int target, int pname, IntBuffer params) {
gl.glGetTexParameteriv(target, pname, params);
}
- @Override public int glGetUniformLocation (int program, String name) {
+ @Override
+ public int glGetUniformLocation (int program, String name) {
return gl.glGetUniformLocation(program, name);
}
- @Override public void glGetUniformfv (int program, int location, FloatBuffer params) {
+ @Override
+ public void glGetUniformfv (int program, int location, FloatBuffer params) {
gl.glGetUniformfv(program, location, params);
}
- @Override public void glGetUniformiv (int program, int location, IntBuffer params) {
+ @Override
+ public void glGetUniformiv (int program, int location, IntBuffer params) {
gl.glGetUniformiv(program, location, params);
}
- @Override public void glGetVertexAttribPointerv (int index, int pname, Buffer pointer) {
+ @Override
+ public void glGetVertexAttribPointerv (int index, int pname, Buffer pointer) {
throw new UnsupportedOperationException("unsupported, won't implement");
}
- @Override public void glGetVertexAttribfv (int index, int pname, FloatBuffer params) {
+ @Override
+ public void glGetVertexAttribfv (int index, int pname, FloatBuffer params) {
gl.glGetVertexAttribfv(index, pname, params);
}
- @Override public void glGetVertexAttribiv (int index, int pname, IntBuffer params) {
+ @Override
+ public void glGetVertexAttribiv (int index, int pname, IntBuffer params) {
gl.glGetVertexAttribiv(index, pname, params);
}
- @Override public void glHint (int target, int mode) {
+ @Override
+ public void glHint (int target, int mode) {
gl.glHint(target, mode);
}
- @Override public boolean glIsBuffer (int buffer) {
+ @Override
+ public boolean glIsBuffer (int buffer) {
return gl.glIsBuffer(buffer);
}
- @Override public boolean glIsEnabled (int cap) {
+ @Override
+ public boolean glIsEnabled (int cap) {
return gl.glIsEnabled(cap);
}
- @Override public boolean glIsFramebuffer (int framebuffer) {
+ @Override
+ public boolean glIsFramebuffer (int framebuffer) {
return gl.glIsFramebufferEXT(framebuffer);
}
- @Override public boolean glIsProgram (int program) {
+ @Override
+ public boolean glIsProgram (int program) {
return gl.glIsProgram(program);
}
- @Override public boolean glIsRenderbuffer (int renderbuffer) {
+ @Override
+ public boolean glIsRenderbuffer (int renderbuffer) {
return gl.glIsRenderbufferEXT(renderbuffer);
}
- @Override public boolean glIsShader (int shader) {
+ @Override
+ public boolean glIsShader (int shader) {
return gl.glIsShader(shader);
}
- @Override public boolean glIsTexture (int texture) {
+ @Override
+ public boolean glIsTexture (int texture) {
return gl.glIsTexture(texture);
}
- @Override public void glLineWidth (float width) {
+ @Override
+ public void glLineWidth (float width) {
gl.glLineWidth(width);
}
- @Override public void glLinkProgram (int program) {
+ @Override
+ public void glLinkProgram (int program) {
gl.glLinkProgram(program);
}
- @Override public void glPixelStorei (int pname, int param) {
+ @Override
+ public void glPixelStorei (int pname, int param) {
gl.glPixelStorei(pname, param);
}
- @Override public void glPolygonOffset (float factor, float units) {
+ @Override
+ public void glPolygonOffset (float factor, float units) {
gl.glPolygonOffset(factor, units);
}
- @Override public void glReadPixels (int x, int y, int width, int height, int format, int type, Buffer pixels) {
+ @Override
+ public void glReadPixels (int x, int y, int width, int height, int format, int type, Buffer pixels) {
gl.glReadPixels(x, y, width, height, format, type, pixels);
}
- @Override public void glReleaseShaderCompiler () {
+ @Override
+ public void glReleaseShaderCompiler () {
// nothing to do here
}
- @Override public void glRenderbufferStorage (int target, int internalformat, int width, int height) {
+ @Override
+ public void glRenderbufferStorage (int target, int internalformat, int width, int height) {
gl.glRenderbufferStorageEXT(target, internalformat, width, height);
}
- @Override public void glSampleCoverage (float value, boolean invert) {
+ @Override
+ public void glSampleCoverage (float value, boolean invert) {
gl.glSampleCoverage(value, invert);
}
- @Override public void glScissor (int x, int y, int width, int height) {
+ @Override
+ public void glScissor (int x, int y, int width, int height) {
gl.glScissor(x, y, width, height);
}
- @Override public void glShaderBinary (int n, IntBuffer shaders, int binaryformat, Buffer binary, int length) {
+ @Override
+ public void glShaderBinary (int n, IntBuffer shaders, int binaryformat, Buffer binary, int length) {
throw new UnsupportedOperationException("unsupported, won't implement");
}
- @Override public void glShaderSource (int shader, String string) {
+ @Override
+ public void glShaderSource (int shader, String string) {
gl.glShaderSource(shader, 1, new String[] {string}, null, 0);
}
- @Override public void glStencilFunc (int func, int ref, int mask) {
+ @Override
+ public void glStencilFunc (int func, int ref, int mask) {
gl.glStencilFunc(func, ref, mask);
}
- @Override public void glStencilFuncSeparate (int face, int func, int ref, int mask) {
+ @Override
+ public void glStencilFuncSeparate (int face, int func, int ref, int mask) {
gl.glStencilFuncSeparate(face, func, ref, mask);
}
- @Override public void glStencilMask (int mask) {
+ @Override
+ public void glStencilMask (int mask) {
gl.glStencilMask(mask);
}
- @Override public void glStencilMaskSeparate (int face, int mask) {
+ @Override
+ public void glStencilMaskSeparate (int face, int mask) {
gl.glStencilMaskSeparate(face, mask);
}
- @Override public void glStencilOp (int fail, int zfail, int zpass) {
+ @Override
+ public void glStencilOp (int fail, int zfail, int zpass) {
gl.glStencilOp(fail, zfail, zpass);
}
- @Override public void glStencilOpSeparate (int face, int fail, int zfail, int zpass) {
+ @Override
+ public void glStencilOpSeparate (int face, int fail, int zfail, int zpass) {
gl.glStencilOpSeparate(face, fail, zfail, zpass);
}
- @Override public void glTexImage2D (int target, int level, int internalformat, int width, int height, int border, int format,
- int type, Buffer pixels) {
+ @Override
+ public void glTexImage2D (int target, int level, int internalformat, int width, int height, int border, int format, int type,
+ Buffer pixels) {
gl.glTexImage2D(target, level, internalformat, width, height, border, format, type, pixels);
}
- @Override public void glTexParameterf (int target, int pname, float param) {
+ @Override
+ public void glTexParameterf (int target, int pname, float param) {
gl.glTexParameterf(target, pname, param);
}
- @Override public void glTexParameterfv (int target, int pname, FloatBuffer params) {
+ @Override
+ public void glTexParameterfv (int target, int pname, FloatBuffer params) {
gl.glTexParameterfv(target, pname, params);
}
- @Override public void glTexParameteri (int target, int pname, int param) {
+ @Override
+ public void glTexParameteri (int target, int pname, int param) {
gl.glTexParameteri(target, pname, param);
}
- @Override public void glTexParameteriv (int target, int pname, IntBuffer params) {
+ @Override
+ public void glTexParameteriv (int target, int pname, IntBuffer params) {
gl.glTexParameteriv(target, pname, params);
}
- @Override public void glTexSubImage2D (int target, int level, int xoffset, int yoffset, int width, int height, int format,
- int type, Buffer pixels) {
+ @Override
+ public void glTexSubImage2D (int target, int level, int xoffset, int yoffset, int width, int height, int format, int type,
+ Buffer pixels) {
gl.glTexSubImage2D(target, level, xoffset, yoffset, width, height, format, type, pixels);
}
- @Override public void glUniform1f (int location, float x) {
+ @Override
+ public void glUniform1f (int location, float x) {
gl.glUniform1f(location, x);
}
- @Override public void glUniform1fv (int location, int count, FloatBuffer v) {
+ @Override
+ public void glUniform1fv (int location, int count, FloatBuffer v) {
gl.glUniform1fv(location, count, v);
}
- @Override public void glUniform1i (int location, int x) {
+ @Override
+ public void glUniform1i (int location, int x) {
gl.glUniform1i(location, x);
}
- @Override public void glUniform1iv (int location, int count, IntBuffer v) {
+ @Override
+ public void glUniform1iv (int location, int count, IntBuffer v) {
gl.glUniform1iv(location, count, v);
}
- @Override public void glUniform2f (int location, float x, float y) {
+ @Override
+ public void glUniform2f (int location, float x, float y) {
gl.glUniform2f(location, x, y);
}
- @Override public void glUniform2fv (int location, int count, FloatBuffer v) {
+ @Override
+ public void glUniform2fv (int location, int count, FloatBuffer v) {
gl.glUniform2fv(location, count, v);
}
- @Override public void glUniform2i (int location, int x, int y) {
+ @Override
+ public void glUniform2i (int location, int x, int y) {
gl.glUniform2i(location, x, y);
}
- @Override public void glUniform2iv (int location, int count, IntBuffer v) {
+ @Override
+ public void glUniform2iv (int location, int count, IntBuffer v) {
gl.glUniform2iv(location, count, v);
}
- @Override public void glUniform3f (int location, float x, float y, float z) {
+ @Override
+ public void glUniform3f (int location, float x, float y, float z) {
gl.glUniform3f(location, x, y, z);
}
- @Override public void glUniform3fv (int location, int count, FloatBuffer v) {
+ @Override
+ public void glUniform3fv (int location, int count, FloatBuffer v) {
gl.glUniform3fv(location, count, v);
}
- @Override public void glUniform3i (int location, int x, int y, int z) {
+ @Override
+ public void glUniform3i (int location, int x, int y, int z) {
gl.glUniform3i(location, x, y, z);
}
- @Override public void glUniform3iv (int location, int count, IntBuffer v) {
+ @Override
+ public void glUniform3iv (int location, int count, IntBuffer v) {
gl.glUniform3iv(location, count, v);
}
- @Override public void glUniform4f (int location, float x, float y, float z, float w) {
+ @Override
+ public void glUniform4f (int location, float x, float y, float z, float w) {
gl.glUniform4f(location, x, y, z, w);
}
- @Override public void glUniform4fv (int location, int count, FloatBuffer v) {
+ @Override
+ public void glUniform4fv (int location, int count, FloatBuffer v) {
gl.glUniform4fv(location, count, v);
}
- @Override public void glUniform4i (int location, int x, int y, int z, int w) {
+ @Override
+ public void glUniform4i (int location, int x, int y, int z, int w) {
gl.glUniform4i(location, x, y, z, w);
}
- @Override public void glUniform4iv (int location, int count, IntBuffer v) {
+ @Override
+ public void glUniform4iv (int location, int count, IntBuffer v) {
gl.glUniform4iv(location, count, v);
}
- @Override public void glUniformMatrix2fv (int location, int count, boolean transpose, FloatBuffer value) {
+ @Override
+ public void glUniformMatrix2fv (int location, int count, boolean transpose, FloatBuffer value) {
gl.glUniformMatrix2fv(location, count, transpose, value);
}
- @Override public void glUniformMatrix3fv (int location, int count, boolean transpose, FloatBuffer value) {
+ @Override
+ public void glUniformMatrix3fv (int location, int count, boolean transpose, FloatBuffer value) {
gl.glUniformMatrix3fv(location, count, transpose, value);
}
- @Override public void glUniformMatrix4fv (int location, int count, boolean transpose, FloatBuffer value) {
+ @Override
+ public void glUniformMatrix4fv (int location, int count, boolean transpose, FloatBuffer value) {
gl.glUniformMatrix4fv(location, count, transpose, value);
}
- @Override public void glUseProgram (int program) {
+ @Override
+ public void glUseProgram (int program) {
gl.glUseProgram(program);
}
- @Override public void glValidateProgram (int program) {
+ @Override
+ public void glValidateProgram (int program) {
gl.glValidateProgram(program);
}
- @Override public void glVertexAttrib1f (int indx, float x) {
+ @Override
+ public void glVertexAttrib1f (int indx, float x) {
gl.glVertexAttrib1f(indx, x);
}
- @Override public void glVertexAttrib1fv (int indx, FloatBuffer values) {
+ @Override
+ public void glVertexAttrib1fv (int indx, FloatBuffer values) {
gl.glVertexAttrib1fv(indx, values);
}
- @Override public void glVertexAttrib2f (int indx, float x, float y) {
+ @Override
+ public void glVertexAttrib2f (int indx, float x, float y) {
gl.glVertexAttrib2f(indx, x, y);
}
- @Override public void glVertexAttrib2fv (int indx, FloatBuffer values) {
+ @Override
+ public void glVertexAttrib2fv (int indx, FloatBuffer values) {
gl.glVertexAttrib2fv(indx, values);
}
- @Override public void glVertexAttrib3f (int indx, float x, float y, float z) {
+ @Override
+ public void glVertexAttrib3f (int indx, float x, float y, float z) {
gl.glVertexAttrib3f(indx, x, y, z);
}
- @Override public void glVertexAttrib3fv (int indx, FloatBuffer values) {
+ @Override
+ public void glVertexAttrib3fv (int indx, FloatBuffer values) {
gl.glVertexAttrib3fv(indx, values);
}
- @Override public void glVertexAttrib4f (int indx, float x, float y, float z, float w) {
+ @Override
+ public void glVertexAttrib4f (int indx, float x, float y, float z, float w) {
gl.glVertexAttrib4f(indx, x, y, z, w);
}
- @Override public void glVertexAttrib4fv (int indx, FloatBuffer values) {
+ @Override
+ public void glVertexAttrib4fv (int indx, FloatBuffer values) {
gl.glVertexAttrib4fv(indx, values);
}
- @Override public void glVertexAttribPointer (int indx, int size, int type, boolean normalized, int stride, Buffer ptr) {
+ @Override
+ public void glVertexAttribPointer (int indx, int size, int type, boolean normalized, int stride, Buffer ptr) {
gl.glVertexAttribPointer(indx, size, type, normalized, stride, ptr);
}
- @Override public void glViewport (int x, int y, int width, int height) {
+ @Override
+ public void glViewport (int x, int y, int width, int height) {
gl.glViewport(x, y, width, height);
}
- @Override public void glDrawElements (int mode, int count, int type, int indices) {
+ @Override
+ public void glDrawElements (int mode, int count, int type, int indices) {
gl.glDrawElements(mode, count, type, indices);
}
- @Override public void glVertexAttribPointer (int indx, int size, int type, boolean normalized, int stride, int ptr) {
+ @Override
+ public void glVertexAttribPointer (int indx, int size, int type, boolean normalized, int stride, int ptr) {
gl.glVertexAttribPointer(indx, size, type, normalized, stride, ptr);
}
diff --git a/backends/gdx-backend-jogl/src/com/badlogic/gdx/backends/jogl/JoglGLU.java b/backends/gdx-backend-jogl/src/com/badlogic/gdx/backends/jogl/JoglGLU.java
index 53ce2feb976..511acff842f 100644
--- a/backends/gdx-backend-jogl/src/com/badlogic/gdx/backends/jogl/JoglGLU.java
+++ b/backends/gdx-backend-jogl/src/com/badlogic/gdx/backends/jogl/JoglGLU.java
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
+
package com.badlogic.gdx.backends.jogl;
import javax.media.opengl.glu.GLU;
@@ -25,20 +26,24 @@ public class JoglGLU implements com.badlogic.gdx.graphics.GLU {
double projectd[] = new double[16];
double wind[] = new double[3];
- @Override public void gluLookAt (GL10 gl, float eyeX, float eyeY, float eyeZ, float centerX, float centerY, float centerZ,
- float upX, float upY, float upZ) {
+ @Override
+ public void gluLookAt (GL10 gl, float eyeX, float eyeY, float eyeZ, float centerX, float centerY, float centerZ, float upX,
+ float upY, float upZ) {
glu.gluLookAt(eyeX, eyeY, eyeZ, centerX, centerY, centerZ, upX, upY, upZ);
}
- @Override public void gluOrtho2D (GL10 gl, float left, float right, float bottom, float top) {
+ @Override
+ public void gluOrtho2D (GL10 gl, float left, float right, float bottom, float top) {
glu.gluOrtho2D(left, right, bottom, top);
}
- @Override public void gluPerspective (GL10 gl, float fovy, float aspect, float zNear, float zFar) {
+ @Override
+ public void gluPerspective (GL10 gl, float fovy, float aspect, float zNear, float zFar) {
glu.gluPerspective(fovy, aspect, zNear, zFar);
}
- @Override public boolean gluProject (float objX, float objY, float objZ, float[] model, int modelOffset, float[] project,
+ @Override
+ public boolean gluProject (float objX, float objY, float objZ, float[] model, int modelOffset, float[] project,
int projectOffset, int[] view, int viewOffset, float[] win, int winOffset) {
for (int i = 0; i < 16; i++) {
modeld[i] = model[modelOffset + i];
@@ -51,7 +56,8 @@ public class JoglGLU implements com.badlogic.gdx.graphics.GLU {
return result;
}
- @Override public boolean gluUnProject (float winX, float winY, float winZ, float[] model, int modelOffset, float[] project,
+ @Override
+ public boolean gluUnProject (float winX, float winY, float winZ, float[] model, int modelOffset, float[] project,
int projectOffset, int[] view, int viewOffset, float[] obj, int objOffset) {
for (int i = 0; i < 16; i++) {
modeld[i] = model[modelOffset + i];
diff --git a/backends/gdx-backend-jogl/src/com/badlogic/gdx/backends/jogl/JoglGraphics.java b/backends/gdx-backend-jogl/src/com/badlogic/gdx/backends/jogl/JoglGraphics.java
index cfe8ceb5afc..ae9d49a1cfe 100644
--- a/backends/gdx-backend-jogl/src/com/badlogic/gdx/backends/jogl/JoglGraphics.java
+++ b/backends/gdx-backend-jogl/src/com/badlogic/gdx/backends/jogl/JoglGraphics.java
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
+
package com.badlogic.gdx.backends.jogl;
import java.awt.BorderLayout;
@@ -25,7 +26,6 @@
import java.awt.Toolkit;
import java.util.List;
-import javax.media.opengl.GL;
import javax.media.opengl.GLAutoDrawable;
import javax.media.opengl.GLCanvas;
import javax.media.opengl.GLCapabilities;
@@ -41,19 +41,16 @@
import com.badlogic.gdx.graphics.Pixmap;
import com.badlogic.gdx.utils.GdxRuntimeException;
-/**
- * Implements the {@link Graphics} interface with Jogl.
- *
- * @author mzechner
+/** Implements the {@link Graphics} interface with Jogl.
*
- */
+ * @author mzechner */
public class JoglGraphics extends JoglGraphicsBase implements GLEventListener {
ApplicationListener listener = null;
boolean useGL2;
- boolean created = false;
+ boolean created = false;
boolean exclusiveMode = false;
final JoglDisplayMode desktopMode;
- final JoglApplicationConfiguration config;
+ final JoglApplicationConfiguration config;
String extensions;
public JoglGraphics (ApplicationListener listener, JoglApplicationConfiguration config) {
@@ -61,12 +58,12 @@ public JoglGraphics (ApplicationListener listener, JoglApplicationConfiguration
if (listener == null) throw new GdxRuntimeException("RenderListener must not be null");
this.listener = listener;
this.config = config;
-
+
desktopMode = (JoglDisplayMode)JoglApplicationConfiguration.getDesktopDisplayMode();
}
public void create () {
- super.create();
+ super.create();
}
public void pause () {
@@ -81,10 +78,11 @@ public void resume () {
super.resume();
}
- @Override public void init (GLAutoDrawable drawable) {
+ @Override
+ public void init (GLAutoDrawable drawable) {
initializeGLInstances(drawable);
setVSync(config.vSyncEnabled);
-
+
if (!created) {
listener.create();
synchronized (this) {
@@ -94,17 +92,19 @@ public void resume () {
}
}
- @Override public void reshape (GLAutoDrawable drawable, int x, int y, int width, int height) {
- listener.resize(width, height);
+ @Override
+ public void reshape (GLAutoDrawable drawable, int x, int y, int width, int height) {
+ listener.resize(width, height);
}
- @Override public void display (GLAutoDrawable arg0) {
+ @Override
+ public void display (GLAutoDrawable arg0) {
synchronized (this) {
if (!paused) {
updateTimes();
synchronized (((JoglApplication)Gdx.app).runnables) {
List runnables = ((JoglApplication)Gdx.app).runnables;
- for(int i = 0; i < runnables.size(); i++) {
+ for (int i = 0; i < runnables.size(); i++) {
runnables.get(i).run();
}
runnables.clear();
@@ -116,7 +116,8 @@ public void resume () {
}
}
- @Override public void displayChanged (GLAutoDrawable arg0, boolean arg1, boolean arg2) {
+ @Override
+ public void displayChanged (GLAutoDrawable arg0, boolean arg1, boolean arg2) {
}
@@ -128,49 +129,57 @@ public void destroy () {
device.setFullScreenWindow(null);
}
- @Override public float getPpiX () {
+ @Override
+ public float getPpiX () {
return Toolkit.getDefaultToolkit().getScreenResolution();
}
- @Override public float getPpiY () {
+ @Override
+ public float getPpiY () {
return Toolkit.getDefaultToolkit().getScreenResolution();
}
- @Override public float getPpcX () {
+ @Override
+ public float getPpcX () {
return (Toolkit.getDefaultToolkit().getScreenResolution() / 2.54f);
}
- @Override public float getPpcY () {
+ @Override
+ public float getPpcY () {
return (Toolkit.getDefaultToolkit().getScreenResolution() / 2.54f);
}
-
- @Override public float getDensity () {
+
+ @Override
+ public float getDensity () {
return (Toolkit.getDefaultToolkit().getScreenResolution() / 160f);
}
-
- @Override public boolean supportsDisplayModeChange () {
+
+ @Override
+ public boolean supportsDisplayModeChange () {
GraphicsEnvironment genv = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice device = genv.getDefaultScreenDevice();
- return device.isFullScreenSupported() && (Gdx.app instanceof JoglApplication);
+ return device.isFullScreenSupported() && (Gdx.app instanceof JoglApplication);
}
-
+
protected static class JoglDisplayMode extends DisplayMode {
final java.awt.DisplayMode mode;
-
+
protected JoglDisplayMode (int width, int height, int refreshRate, int bitsPerPixel, java.awt.DisplayMode mode) {
super(width, height, refreshRate, bitsPerPixel);
this.mode = mode;
- }
+ }
}
-
- @Override public DisplayMode[] getDisplayModes () {
+
+ @Override
+ public DisplayMode[] getDisplayModes () {
return JoglApplicationConfiguration.getDisplayModes();
}
- @Override public void setTitle (String title) {
+ @Override
+ public void setTitle (String title) {
Container parent = canvas.getParent();
- while(parent != null) {
- if(parent instanceof JFrame) {
+ while (parent != null) {
+ if (parent instanceof JFrame) {
((JFrame)parent).setTitle(title);
return;
}
@@ -178,167 +187,180 @@ protected JoglDisplayMode (int width, int height, int refreshRate, int bitsPerPi
}
}
- @Override public void setIcon (Pixmap pixmap) {
-
+ @Override
+ public void setIcon (Pixmap pixmap) {
+
}
- @Override public DisplayMode getDesktopDisplayMode () {
+ @Override
+ public DisplayMode getDesktopDisplayMode () {
return desktopMode;
}
-
-
- @Override public boolean setDisplayMode (int width, int height, boolean fullscreen) {
- if(!supportsDisplayModeChange()) return false;
-
- if(!fullscreen) {
- setWindowedMode(width, height);
+
+ @Override
+ public boolean setDisplayMode (int width, int height, boolean fullscreen) {
+ if (!supportsDisplayModeChange()) return false;
+
+ if (!fullscreen) {
+ setWindowedMode(width, height);
} else {
DisplayMode mode = findBestMatch(width, height);
- if(mode == null) return false;
+ if (mode == null) return false;
setDisplayMode(mode);
}
return false;
}
-
- protected JoglDisplayMode findBestMatch(int width, int height) {
+
+ protected JoglDisplayMode findBestMatch (int width, int height) {
DisplayMode[] modes = getDisplayModes();
int maxBitDepth = 0;
DisplayMode best = null;
- for(DisplayMode mode: modes) {
- if(mode.width == width && mode.height == height && mode.bitsPerPixel == desktopMode.bitsPerPixel) {
+ for (DisplayMode mode : modes) {
+ if (mode.width == width && mode.height == height && mode.bitsPerPixel == desktopMode.bitsPerPixel) {
maxBitDepth = mode.bitsPerPixel;
- best = mode;
+ best = mode;
}
}
return (JoglDisplayMode)best;
}
-
- @Override public boolean setDisplayMode (DisplayMode displayMode) {
- if(!supportsDisplayModeChange()) return false;
-
+
+ @Override
+ public boolean setDisplayMode (DisplayMode displayMode) {
+ if (!supportsDisplayModeChange()) return false;
+
GraphicsEnvironment genv = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice device = genv.getDefaultScreenDevice();
final JFrame frame = findJFrame(canvas);
- if(frame == null) return false;
-
+ if (frame == null) return false;
+
// create new canvas, sharing the rendering context with the old canvas
// and pause the animator
- super.pause();
+ super.pause();
GLCanvas newCanvas = new GLCanvas(canvas.getChosenGLCapabilities(), null, canvas.getContext(), device);
newCanvas.addGLEventListener(this);
-
- JFrame newframe = new JFrame(frame.getTitle());
+
+ JFrame newframe = new JFrame(frame.getTitle());
newframe.setUndecorated(true);
newframe.setResizable(false);
newframe.add(newCanvas, BorderLayout.CENTER);
newframe.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
newframe.setLocationRelativeTo(null);
newframe.pack();
- newframe.setVisible(true);
-
+ newframe.setVisible(true);
+
device.setFullScreenWindow(newframe);
- device.setDisplayMode(((JoglDisplayMode)displayMode).mode);
-
+ device.setDisplayMode(((JoglDisplayMode)displayMode).mode);
+
initializeGLInstances(canvas);
- this.canvas = newCanvas;
+ this.canvas = newCanvas;
((JoglInput)Gdx.input).setListeners(canvas);
- canvas.requestFocus();
+ canvas.requestFocus();
newframe.addWindowListener(((JoglApplication)Gdx.app).windowListener);
((JoglApplication)Gdx.app).frame = newframe;
resume();
-
+
Gdx.app.postRunnable(new Runnable() {
- public void run() {
+ public void run () {
SwingUtilities.invokeLater(new Runnable() {
- @Override public void run () {
+ @Override
+ public void run () {
frame.dispose();
- }
+ }
});
}
- });
-
- return true;
+ });
+
+ return true;
}
-
- private boolean setWindowedMode(int width, int height) {
-
+
+ private boolean setWindowedMode (int width, int height) {
+
GraphicsEnvironment genv = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice device = genv.getDefaultScreenDevice();
- if(device.isDisplayChangeSupported()) {
+ if (device.isDisplayChangeSupported()) {
device.setDisplayMode(desktopMode.mode);
- device.setFullScreenWindow(null);
-
+ device.setFullScreenWindow(null);
+
final JFrame frame = findJFrame(canvas);
- if(frame == null) return false;
-
+ if (frame == null) return false;
+
// create new canvas, sharing the rendering context with the old canvas
// and pause the animator
- super.pause();
+ super.pause();
GLCanvas newCanvas = new GLCanvas(canvas.getChosenGLCapabilities(), null, canvas.getContext(), device);
newCanvas.setBackground(Color.BLACK);
- newCanvas.setPreferredSize(new Dimension(width, height));
+ newCanvas.setPreferredSize(new Dimension(width, height));
newCanvas.addGLEventListener(this);
-
- JFrame newframe = new JFrame(frame.getTitle());
+
+ JFrame newframe = new JFrame(frame.getTitle());
newframe.setUndecorated(false);
newframe.setResizable(true);
- newframe.setSize(width + newframe.getInsets().left + newframe.getInsets().right, newframe.getInsets().top + newframe.getInsets().bottom + height);
+ newframe.setSize(width + newframe.getInsets().left + newframe.getInsets().right,
+ newframe.getInsets().top + newframe.getInsets().bottom + height);
newframe.add(newCanvas, BorderLayout.CENTER);
newframe.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
newframe.setLocationRelativeTo(null);
newframe.pack();
- newframe.setVisible(true);
-
+ newframe.setVisible(true);
+
initializeGLInstances(canvas);
- this.canvas = newCanvas;
+ this.canvas = newCanvas;
((JoglInput)Gdx.input).setListeners(canvas);
- canvas.requestFocus();
+ canvas.requestFocus();
newframe.addWindowListener(((JoglApplication)Gdx.app).windowListener);
((JoglApplication)Gdx.app).frame = newframe;
resume();
-
+
Gdx.app.postRunnable(new Runnable() {
- public void run() {
+ public void run () {
SwingUtilities.invokeLater(new Runnable() {
- @Override public void run () {
+ @Override
+ public void run () {
frame.dispose();
- }
+ }
});
}
- });
+ });
} else {
final JFrame frame = findJFrame(canvas);
- if(frame == null) return false;
- frame.setSize(width + frame.getInsets().left + frame.getInsets().right, frame.getInsets().top + frame.getInsets().bottom + height);
+ if (frame == null) return false;
+ frame.setSize(width + frame.getInsets().left + frame.getInsets().right, frame.getInsets().top + frame.getInsets().bottom
+ + height);
}
-
- return true;
+
+ return true;
}
-
- protected static JFrame findJFrame(Component component) {
+
+ protected static JFrame findJFrame (Component component) {
Container parent = component.getParent();
- while(parent != null) {
- if(parent instanceof JFrame) {
+ while (parent != null) {
+ if (parent instanceof JFrame) {
return (JFrame)parent;
}
parent = parent.getParent();
}
-
+
return null;
}
- @Override public void setVSync (boolean vsync) {
- if(vsync) canvas.getGL().setSwapInterval(1);
- else canvas.getGL().setSwapInterval(0);
+ @Override
+ public void setVSync (boolean vsync) {
+ if (vsync)
+ canvas.getGL().setSwapInterval(1);
+ else
+ canvas.getGL().setSwapInterval(0);
}
- @Override public BufferFormat getBufferFormat () {
+ @Override
+ public BufferFormat getBufferFormat () {
GLCapabilities caps = canvas.getChosenGLCapabilities();
- return new BufferFormat(caps.getRedBits(), caps.getGreenBits(), caps.getBlueBits(), caps.getAlphaBits(), caps.getDepthBits(), caps.getStencilBits(), caps.getNumSamples(), false);
+ return new BufferFormat(caps.getRedBits(), caps.getGreenBits(), caps.getBlueBits(), caps.getAlphaBits(),
+ caps.getDepthBits(), caps.getStencilBits(), caps.getNumSamples(), false);
}
-
- @Override public boolean supportsExtension (String extension) {
- if(extensions == null) extensions = Gdx.gl.glGetString(GL10.GL_EXTENSIONS);
- return extensions.contains(extension);
+
+ @Override
+ public boolean supportsExtension (String extension) {
+ if (extensions == null) extensions = Gdx.gl.glGetString(GL10.GL_EXTENSIONS);
+ return extensions.contains(extension);
}
}
diff --git a/backends/gdx-backend-jogl/src/com/badlogic/gdx/backends/jogl/JoglGraphicsBase.java b/backends/gdx-backend-jogl/src/com/badlogic/gdx/backends/jogl/JoglGraphicsBase.java
index 659e5e2c9f4..9b26ae7d097 100644
--- a/backends/gdx-backend-jogl/src/com/badlogic/gdx/backends/jogl/JoglGraphicsBase.java
+++ b/backends/gdx-backend-jogl/src/com/badlogic/gdx/backends/jogl/JoglGraphicsBase.java
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
+
package com.badlogic.gdx.backends.jogl;
import java.awt.Color;
@@ -30,10 +31,6 @@
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.GLCommon;
import com.badlogic.gdx.graphics.GLU;
-import com.badlogic.gdx.graphics.Texture;
-import com.badlogic.gdx.graphics.Pixmap.Format;
-import com.badlogic.gdx.math.MathUtils;
-import com.badlogic.gdx.math.WindowedMean;
public abstract class JoglGraphicsBase implements Graphics, GLEventListener {
static int major, minor;
@@ -43,10 +40,10 @@ public abstract class JoglGraphicsBase implements Graphics, GLEventListener {
boolean useGL2;
long frameStart = System.nanoTime();
long lastFrameTime = System.nanoTime();
- float deltaTime = 0;
+ float deltaTime = 0;
int fps;
int frames;
- boolean paused = true;
+ boolean paused = true;
GLCommon gl;
GL10 gl10;
@@ -72,7 +69,7 @@ void initialize (JoglApplicationConfiguration config) {
this.useGL2 = config.useGL20;
this.glu = new JoglGLU();
Gdx.glu = glu;
-
+
}
GLCanvas getCanvas () {
@@ -82,7 +79,7 @@ GLCanvas getCanvas () {
void create () {
frameStart = System.nanoTime();
lastFrameTime = frameStart;
- deltaTime = 0;
+ deltaTime = 0;
animator = new JoglAnimator(canvas);
animator.start();
}
@@ -98,7 +95,7 @@ void resume () {
paused = false;
frameStart = System.nanoTime();
lastFrameTime = frameStart;
- deltaTime = 0;
+ deltaTime = 0;
animator = new JoglAnimator(canvas);
animator.setRunAsFastAsPossible(true);
animator.start();
@@ -114,7 +111,7 @@ void initializeGLInstances (GLAutoDrawable drawable) {
gl20 = new JoglGL20(drawable.getGL());
gl = gl20;
} else {
-
+
if (major == 1 && minor < 5 || renderer.equals("Mirage Graphics3")) {
gl10 = new JoglGL10(drawable.getGL());
} else {
@@ -132,7 +129,7 @@ void initializeGLInstances (GLAutoDrawable drawable) {
void updateTimes () {
deltaTime = (System.nanoTime() - lastFrameTime) / 1000000000.0f;
- lastFrameTime = System.nanoTime();
+ lastFrameTime = System.nanoTime();
if (System.nanoTime() - frameStart > 1000000000) {
fps = frames;
@@ -142,51 +139,63 @@ void updateTimes () {
frames++;
}
- @Override public float getDeltaTime () {
+ @Override
+ public float getDeltaTime () {
return deltaTime;
}
- @Override public int getFramesPerSecond () {
+ @Override
+ public int getFramesPerSecond () {
return fps;
}
- @Override public int getHeight () {
+ @Override
+ public int getHeight () {
return canvas.getHeight();
}
- @Override public int getWidth () {
+ @Override
+ public int getWidth () {
return canvas.getWidth();
}
- @Override public GL10 getGL10 () {
+ @Override
+ public GL10 getGL10 () {
return gl10;
}
- @Override public GL11 getGL11 () {
+ @Override
+ public GL11 getGL11 () {
return gl11;
}
- @Override public GL20 getGL20 () {
+ @Override
+ public GL20 getGL20 () {
return gl20;
}
- @Override public GLCommon getGLCommon () {
+ @Override
+ public GLCommon getGLCommon () {
return gl;
}
- @Override public GLU getGLU() {
+ @Override
+ public GLU getGLU () {
return glu;
}
-
- @Override public boolean isGL11Available () {
+
+ @Override
+ public boolean isGL11Available () {
return gl11 != null;
}
- @Override public boolean isGL20Available () {
+ @Override
+ public boolean isGL20Available () {
return gl20 != null;
}
- @Override public GraphicsType getType () {
+ @Override
+ public GraphicsType getType () {
return GraphicsType.JoglGL;
- }
+ }
}
diff --git a/backends/gdx-backend-jogl/src/com/badlogic/gdx/backends/jogl/JoglInput.java b/backends/gdx-backend-jogl/src/com/badlogic/gdx/backends/jogl/JoglInput.java
index aaf4db4a50f..21e79f76caf 100644
--- a/backends/gdx-backend-jogl/src/com/badlogic/gdx/backends/jogl/JoglInput.java
+++ b/backends/gdx-backend-jogl/src/com/badlogic/gdx/backends/jogl/JoglInput.java
@@ -13,9 +13,9 @@
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
+
package com.badlogic.gdx.backends.jogl;
-import java.awt.AWTEvent;
import java.awt.AWTException;
import java.awt.Cursor;
import java.awt.GraphicsEnvironment;
@@ -24,7 +24,6 @@
import java.awt.Point;
import java.awt.Robot;
import java.awt.Toolkit;
-import java.awt.event.AWTEventListener;
import java.awt.event.KeyListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
@@ -96,8 +95,8 @@ protected TouchEvent newObject () {
Set pressedButtons = new HashSet();
InputProcessor processor;
GLCanvas canvas;
- boolean catched = false;
- Robot robot = null;
+ boolean catched = false;
+ Robot robot = null;
public JoglInput (GLCanvas canvas) {
setListeners(canvas);
@@ -105,73 +104,83 @@ public JoglInput (GLCanvas canvas) {
robot = new Robot(GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice());
} catch (HeadlessException e) {
} catch (AWTException e) {
- }
+ }
}
-
- public void setListeners(GLCanvas canvas) {
- if(this.canvas != null) {
+
+ public void setListeners (GLCanvas canvas) {
+ if (this.canvas != null) {
canvas.removeMouseListener(this);
canvas.removeMouseMotionListener(this);
canvas.removeMouseWheelListener(this);
canvas.removeKeyListener(this);
JFrame frame = JoglGraphics.findJFrame(canvas);
-
+
}
canvas.addMouseListener(this);
canvas.addMouseMotionListener(this);
canvas.addMouseWheelListener(this);
- canvas.addKeyListener(this);
+ canvas.addKeyListener(this);
this.canvas = canvas;
}
- @Override public float getAccelerometerX () {
+ @Override
+ public float getAccelerometerX () {
return 0;
}
- @Override public float getAccelerometerY () {
+ @Override
+ public float getAccelerometerY () {
return 0;
}
- @Override public float getAccelerometerZ () {
+ @Override
+ public float getAccelerometerZ () {
return 0;
}
- @Override public void getTextInput (final TextInputListener listener, final String title, final String text) {
+ @Override
+ public void getTextInput (final TextInputListener listener, final String title, final String text) {
SwingUtilities.invokeLater(new Runnable() {
- @Override public void run () {
+ @Override
+ public void run () {
String output = JOptionPane.showInputDialog(null, title, text);
- if (output != null)
+ if (output != null)
listener.input(output);
else
listener.canceled();
-
+
}
});
}
- @Override public int getX () {
+ @Override
+ public int getX () {
return touchX;
}
- @Override public int getX (int pointer) {
+ @Override
+ public int getX (int pointer) {
if (pointer == 0)
return touchX;
else
return 0;
}
- @Override public int getY () {
+ @Override
+ public int getY () {
return touchY;
}
- @Override public int getY (int pointer) {
+ @Override
+ public int getY (int pointer) {
if (pointer == 0)
return touchY;
else
return 0;
}
- @Override public boolean isKeyPressed (int key) {
+ @Override
+ public boolean isKeyPressed (int key) {
synchronized (this) {
if (key == Input.Keys.ANY_KEY)
return keys.size() > 0;
@@ -180,21 +189,23 @@ public void setListeners(GLCanvas canvas) {
}
}
- @Override public boolean isTouched () {
+ @Override
+ public boolean isTouched () {
return touchDown;
}
- @Override public boolean isTouched (int pointer) {
+ @Override
+ public boolean isTouched (int pointer) {
if (pointer == 0)
return touchDown;
else
return false;
}
- void processEvents () {
+ void processEvents () {
synchronized (this) {
justTouched = false;
-
+
if (processor != null) {
InputProcessor processor = this.processor;
@@ -219,11 +230,11 @@ void processEvents () {
TouchEvent e = touchEvents.get(i);
switch (e.type) {
case TouchEvent.TOUCH_DOWN:
- processor.touchDown(e.x, e.y, e.pointer, e.button);
- justTouched = true;
+ processor.touchDown(e.x, e.y, e.pointer, e.button);
+ justTouched = true;
break;
case TouchEvent.TOUCH_UP:
- processor.touchUp(e.x, e.y, e.pointer, e.button);
+ processor.touchUp(e.x, e.y, e.pointer, e.button);
break;
case TouchEvent.TOUCH_DRAGGED:
processor.touchDragged(e.x, e.y, e.pointer);
@@ -241,8 +252,7 @@ void processEvents () {
int len = touchEvents.size();
for (int i = 0; i < len; i++) {
TouchEvent event = touchEvents.get(i);
- if(event.type == TouchEvent.TOUCH_DOWN)
- justTouched = true;
+ if (event.type == TouchEvent.TOUCH_DOWN) justTouched = true;
usedTouchEvents.free(event);
}
@@ -252,25 +262,28 @@ void processEvents () {
}
}
- if(touchEvents.size() == 0) {
+ if (touchEvents.size() == 0) {
deltaX = 0;
deltaY = 0;
}
-
+
keyEvents.clear();
touchEvents.clear();
- }
+ }
}
- @Override public void setCatchBackKey (boolean catchBack) {
+ @Override
+ public void setCatchBackKey (boolean catchBack) {
}
- @Override public void setOnscreenKeyboardVisible (boolean visible) {
+ @Override
+ public void setOnscreenKeyboardVisible (boolean visible) {
}
- @Override public void mouseDragged (MouseEvent e) {
+ @Override
+ public void mouseDragged (MouseEvent e) {
synchronized (this) {
TouchEvent event = usedTouchEvents.obtain();
event.pointer = 0;
@@ -287,9 +300,10 @@ void processEvents () {
}
}
- @Override public void mouseMoved (MouseEvent e) {
+ @Override
+ public void mouseMoved (MouseEvent e) {
synchronized (this) {
- TouchEvent event = usedTouchEvents.obtain();
+ TouchEvent event = usedTouchEvents.obtain();
event.pointer = 0;
event.x = e.getX();
event.y = e.getY();
@@ -299,47 +313,48 @@ void processEvents () {
deltaX = event.x - touchX;
deltaY = event.y - touchY;
touchX = event.x;
- touchY = event.y;
+ touchY = event.y;
checkCatched(e);
}
}
- @Override public void mouseClicked (MouseEvent arg0) {
+ @Override
+ public void mouseClicked (MouseEvent arg0) {
}
- @Override public void mouseEntered (MouseEvent e) {
+ @Override
+ public void mouseEntered (MouseEvent e) {
touchX = e.getX();
- touchY = e.getY();
+ touchY = e.getY();
checkCatched(e);
}
- @Override public void mouseExited (MouseEvent e) {
+ @Override
+ public void mouseExited (MouseEvent e) {
checkCatched(e);
}
-
- private void checkCatched(MouseEvent e) {
- if(catched && robot != null && canvas.isShowing()) {
+
+ private void checkCatched (MouseEvent e) {
+ if (catched && robot != null && canvas.isShowing()) {
int x = Math.max(0, Math.min(e.getX(), canvas.getWidth()) - 1) + canvas.getLocationOnScreen().x;
int y = Math.max(0, Math.min(e.getY(), canvas.getHeight()) - 1) + canvas.getLocationOnScreen().y;
deltaX = e.getLocationOnScreen().x - x;
deltaY = e.getLocationOnScreen().y - y;
- if(e.getX() < 0 || e.getX() >= canvas.getWidth() || e.getY() < 0 || e.getY() >= canvas.getHeight()) {
+ if (e.getX() < 0 || e.getX() >= canvas.getWidth() || e.getY() < 0 || e.getY() >= canvas.getHeight()) {
robot.mouseMove(x - deltaX, y - deltaY);
- }
+ }
}
}
- private int toGdxButton(int swingButton) {
- if(swingButton == MouseEvent.BUTTON1)
- return Buttons.LEFT;
- if(swingButton == MouseEvent.BUTTON2)
- return Buttons.MIDDLE;
- if(swingButton == MouseEvent.BUTTON3)
- return Buttons.RIGHT;
+ private int toGdxButton (int swingButton) {
+ if (swingButton == MouseEvent.BUTTON1) return Buttons.LEFT;
+ if (swingButton == MouseEvent.BUTTON2) return Buttons.MIDDLE;
+ if (swingButton == MouseEvent.BUTTON3) return Buttons.RIGHT;
return Buttons.LEFT;
}
-
- @Override public void mousePressed (MouseEvent e) {
+
+ @Override
+ public void mousePressed (MouseEvent e) {
synchronized (this) {
TouchEvent event = usedTouchEvents.obtain();
event.pointer = 0;
@@ -352,13 +367,14 @@ private int toGdxButton(int swingButton) {
deltaX = event.x - touchX;
deltaY = event.y - touchY;
touchX = event.x;
- touchY = event.y;
+ touchY = event.y;
touchDown = true;
- pressedButtons.add(event.button);
+ pressedButtons.add(event.button);
}
}
- @Override public void mouseReleased (MouseEvent e) {
+ @Override
+ public void mouseReleased (MouseEvent e) {
synchronized (this) {
TouchEvent event = usedTouchEvents.obtain();
event.pointer = 0;
@@ -366,29 +382,30 @@ private int toGdxButton(int swingButton) {
event.y = e.getY();
event.button = toGdxButton(e.getButton());
event.type = TouchEvent.TOUCH_UP;
- touchEvents.add(event);
+ touchEvents.add(event);
deltaX = event.x - touchX;
deltaY = event.y - touchY;
touchX = event.x;
- touchY = event.y;
+ touchY = event.y;
pressedButtons.remove(event.button);
- if(pressedButtons.size()==0)
- touchDown = false;
+ if (pressedButtons.size() == 0) touchDown = false;
}
}
-
- @Override public void mouseWheelMoved (MouseWheelEvent e) {
+
+ @Override
+ public void mouseWheelMoved (MouseWheelEvent e) {
synchronized (this) {
TouchEvent event = usedTouchEvents.obtain();
- event.pointer = 0;
+ event.pointer = 0;
event.type = TouchEvent.TOUCH_SCROLLED;
event.scrollAmount = e.getWheelRotation();
- touchEvents.add(event);
+ touchEvents.add(event);
}
}
- @Override public void keyPressed (java.awt.event.KeyEvent e) {
+ @Override
+ public void keyPressed (java.awt.event.KeyEvent e) {
synchronized (this) {
KeyEvent event = usedKeyEvents.obtain();
event.keyChar = 0;
@@ -399,18 +416,20 @@ private int toGdxButton(int swingButton) {
}
}
- @Override public void keyReleased (java.awt.event.KeyEvent e) {
+ @Override
+ public void keyReleased (java.awt.event.KeyEvent e) {
synchronized (this) {
KeyEvent event = usedKeyEvents.obtain();
event.keyChar = 0;
event.keyCode = translateKeyCode(e.getKeyCode());
event.type = KeyEvent.KEY_UP;
keyEvents.add(event);
- keys.remove(event.keyCode);
+ keys.remove(event.keyCode);
}
}
- @Override public void keyTyped (java.awt.event.KeyEvent e) {
+ @Override
+ public void keyTyped (java.awt.event.KeyEvent e) {
synchronized (this) {
KeyEvent event = usedKeyEvents.obtain();
event.keyChar = e.getKeyChar();
@@ -422,7 +441,7 @@ private int toGdxButton(int swingButton) {
protected static int translateKeyCode (int keyCode) {
if (keyCode == java.awt.event.KeyEvent.VK_ADD) return Input.Keys.PLUS;
- if (keyCode == java.awt.event.KeyEvent.VK_SUBTRACT) return Input.Keys.MINUS;
+ if (keyCode == java.awt.event.KeyEvent.VK_SUBTRACT) return Input.Keys.MINUS;
if (keyCode == java.awt.event.KeyEvent.VK_0) return Input.Keys.NUM_0;
if (keyCode == java.awt.event.KeyEvent.VK_1) return Input.Keys.NUM_1;
if (keyCode == java.awt.event.KeyEvent.VK_2) return Input.Keys.NUM_2;
@@ -489,79 +508,93 @@ protected static int translateKeyCode (int keyCode) {
if (keyCode == java.awt.event.KeyEvent.VK_F1) return Input.Keys.F1;
if (keyCode == java.awt.event.KeyEvent.VK_F2) return Input.Keys.F2;
if (keyCode == java.awt.event.KeyEvent.VK_F3) return Input.Keys.F3;
- if (keyCode == java.awt.event.KeyEvent.VK_F4) return Input.Keys.F4;
+ if (keyCode == java.awt.event.KeyEvent.VK_F4) return Input.Keys.F4;
if (keyCode == java.awt.event.KeyEvent.VK_F5) return Input.Keys.F5;
if (keyCode == java.awt.event.KeyEvent.VK_F6) return Input.Keys.F6;
if (keyCode == java.awt.event.KeyEvent.VK_F7) return Input.Keys.F7;
if (keyCode == java.awt.event.KeyEvent.VK_F8) return Input.Keys.F8;
- if (keyCode == java.awt.event.KeyEvent.VK_F9) return Input.Keys.F9;
+ if (keyCode == java.awt.event.KeyEvent.VK_F9) return Input.Keys.F9;
if (keyCode == java.awt.event.KeyEvent.VK_F10) return Input.Keys.F10;
if (keyCode == java.awt.event.KeyEvent.VK_F11) return Input.Keys.F11;
if (keyCode == java.awt.event.KeyEvent.VK_F12) return Input.Keys.F12;
- if (keyCode == java.awt.event.KeyEvent.VK_COLON) return Input.Keys.COLON;
+ if (keyCode == java.awt.event.KeyEvent.VK_COLON) return Input.Keys.COLON;
return Input.Keys.UNKNOWN;
}
- @Override public void setInputProcessor (InputProcessor processor) {
+ @Override
+ public void setInputProcessor (InputProcessor processor) {
synchronized (this) {
this.processor = processor;
}
}
-
- @Override public InputProcessor getInputProcessor() {
+
+ @Override
+ public InputProcessor getInputProcessor () {
return this.processor;
}
- @Override public void vibrate (int milliseconds) {
+ @Override
+ public void vibrate (int milliseconds) {
}
- @Override public boolean justTouched () {
+ @Override
+ public boolean justTouched () {
return justTouched;
}
- @Override public boolean isButtonPressed (int button) {
+ @Override
+ public boolean isButtonPressed (int button) {
return pressedButtons.contains(button);
}
- @Override public void vibrate (long[] pattern, int repeat) {
+ @Override
+ public void vibrate (long[] pattern, int repeat) {
}
- @Override public void cancelVibrate () {
+ @Override
+ public void cancelVibrate () {
}
- @Override public float getAzimuth () {
+ @Override
+ public float getAzimuth () {
return 0;
}
- @Override public float getPitch () {
+ @Override
+ public float getPitch () {
return 0;
}
- @Override public float getRoll () {
+ @Override
+ public float getRoll () {
return 0;
}
-
- @Override public boolean isPeripheralAvailable (Peripheral peripheral) {
- if(peripheral == Peripheral.HardwareKeyboard) return true;
+
+ @Override
+ public boolean isPeripheralAvailable (Peripheral peripheral) {
+ if (peripheral == Peripheral.HardwareKeyboard) return true;
return false;
}
- @Override public int getRotation () {
+ @Override
+ public int getRotation () {
return 0;
}
- @Override public Orientation getNativeOrientation () {
+ @Override
+ public Orientation getNativeOrientation () {
return Orientation.Landscape;
}
- @Override public void setCursorCatched (boolean catched) {
+ @Override
+ public void setCursorCatched (boolean catched) {
this.catched = catched;
showCursor(!catched);
}
-
- private void showCursor(boolean visible) {
- if(!visible) {
+
+ private void showCursor (boolean visible) {
+ if (!visible) {
Toolkit t = Toolkit.getDefaultToolkit();
Image i = new BufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB);
Cursor noCursor = t.createCustomCursor(i, new Point(0, 0), "none");
@@ -573,37 +606,43 @@ private void showCursor(boolean visible) {
}
}
- @Override public boolean isCursorCatched () {
+ @Override
+ public boolean isCursorCatched () {
return catched;
}
- @Override public int getDeltaX () {
+ @Override
+ public int getDeltaX () {
return deltaX;
}
- @Override public int getDeltaX (int pointer) {
- if(pointer == 0) return deltaX;
+ @Override
+ public int getDeltaX (int pointer) {
+ if (pointer == 0) return deltaX;
return 0;
}
- @Override public int getDeltaY () {
+ @Override
+ public int getDeltaY () {
return deltaY;
}
- @Override public int getDeltaY (int pointer) {
- if(pointer == 0) return deltaY;
+ @Override
+ public int getDeltaY (int pointer) {
+ if (pointer == 0) return deltaY;
return 0;
}
- @Override public void setCursorPosition (int x, int y) {
- if(robot != null) {
+ @Override
+ public void setCursorPosition (int x, int y) {
+ if (robot != null) {
robot.mouseMove(canvas.getLocationOnScreen().x + x, canvas.getLocationOnScreen().y + y);
}
}
@Override
- public void setCatchMenuKey(boolean catchMenu) {
+ public void setCatchMenuKey (boolean catchMenu) {
// TODO Auto-generated method stub
-
+
}
}
diff --git a/backends/gdx-backend-jogl/src/com/badlogic/gdx/backends/jogl/JoglNativesLoader.java b/backends/gdx-backend-jogl/src/com/badlogic/gdx/backends/jogl/JoglNativesLoader.java
index 70b1433c934..749962f3995 100644
--- a/backends/gdx-backend-jogl/src/com/badlogic/gdx/backends/jogl/JoglNativesLoader.java
+++ b/backends/gdx-backend-jogl/src/com/badlogic/gdx/backends/jogl/JoglNativesLoader.java
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
+
package com.badlogic.gdx.backends.jogl;
import com.badlogic.gdx.utils.GdxNativesLoader;
@@ -23,12 +24,10 @@
public class JoglNativesLoader {
static private boolean nativesLoaded = false;
- /**
- * loads the necessary libraries depending on the operating system
- */
+ /** loads the necessary libraries depending on the operating system */
public static void load () {
GdxNativesLoader.load();
- if(GdxNativesLoader.disableNativesLoading) return;
+ if (GdxNativesLoader.disableNativesLoading) return;
if (nativesLoaded) return;
diff --git a/backends/gdx-backend-jogl/src/com/badlogic/gdx/backends/jogl/JoglPreferences.java b/backends/gdx-backend-jogl/src/com/badlogic/gdx/backends/jogl/JoglPreferences.java
index 9e602649126..3480dc683a1 100644
--- a/backends/gdx-backend-jogl/src/com/badlogic/gdx/backends/jogl/JoglPreferences.java
+++ b/backends/gdx-backend-jogl/src/com/badlogic/gdx/backends/jogl/JoglPreferences.java
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
+
package com.badlogic.gdx.backends.jogl;
import java.io.BufferedInputStream;
@@ -31,133 +32,151 @@ public class JoglPreferences implements Preferences {
private final String name;
private final Properties properties = new Properties();
- JoglPreferences(String name) {
+ JoglPreferences (String name) {
this.name = name;
InputStream in = null;
try {
in = new BufferedInputStream(Gdx.files.external(name).read());
properties.loadFromXML(in);
- } catch(Throwable t) {
+ } catch (Throwable t) {
} finally {
- if(in != null) try { in.close(); } catch(Exception e) { }
+ if (in != null) try {
+ in.close();
+ } catch (Exception e) {
+ }
}
-
+
Runtime.getRuntime().addShutdownHook(new Thread() {
- @Override public void run() {
+ @Override
+ public void run () {
flush();
}
});
- }
-
- @Override public void putBoolean (String key, boolean val) {
+ }
+
+ @Override
+ public void putBoolean (String key, boolean val) {
properties.put(key, Boolean.toString(val));
}
- @Override public void putInteger (String key, int val) {
+ @Override
+ public void putInteger (String key, int val) {
properties.put(key, Integer.toString(val));
}
- @Override public void putLong (String key, long val) {
+ @Override
+ public void putLong (String key, long val) {
properties.put(key, Long.toString(val));
}
- @Override public void putFloat (String key, float val) {
+ @Override
+ public void putFloat (String key, float val) {
properties.put(key, Float.toString(val));
}
- @Override public void putString (String key, String val) {
+ @Override
+ public void putString (String key, String val) {
properties.put(key, val);
}
- @Override public void put (Map vals) {
- for(Entry val: vals.entrySet()) {
- if(val.getValue() instanceof Boolean)
- putBoolean(val.getKey(), (Boolean)val.getValue());
- if(val.getValue() instanceof Integer)
- putInteger(val.getKey(), (Integer)val.getValue());
- if(val.getValue() instanceof Long)
- putLong(val.getKey(), (Long)val.getValue());
- if(val.getValue() instanceof String)
- putString(val.getKey(), (String)val.getValue());
- if(val.getValue() instanceof Float)
- putFloat(val.getKey(), (Float)val.getValue());
+ @Override
+ public void put (Map vals) {
+ for (Entry val : vals.entrySet()) {
+ if (val.getValue() instanceof Boolean) putBoolean(val.getKey(), (Boolean)val.getValue());
+ if (val.getValue() instanceof Integer) putInteger(val.getKey(), (Integer)val.getValue());
+ if (val.getValue() instanceof Long) putLong(val.getKey(), (Long)val.getValue());
+ if (val.getValue() instanceof String) putString(val.getKey(), (String)val.getValue());
+ if (val.getValue() instanceof Float) putFloat(val.getKey(), (Float)val.getValue());
}
}
- @Override public boolean getBoolean (String key) {
+ @Override
+ public boolean getBoolean (String key) {
return getBoolean(key, false);
}
- @Override public int getInteger (String key) {
+ @Override
+ public int getInteger (String key) {
return getInteger(key, 0);
}
- @Override public long getLong (String key) {
+ @Override
+ public long getLong (String key) {
return getLong(key, 0);
}
- @Override public float getFloat (String key) {
+ @Override
+ public float getFloat (String key) {
return getFloat(key, 0);
}
- @Override public String getString (String key) {
+ @Override
+ public String getString (String key) {
return getString(key, "");
}
- @Override public boolean getBoolean (String key, boolean defValue) {
+ @Override
+ public boolean getBoolean (String key, boolean defValue) {
return Boolean.parseBoolean(properties.getProperty(key, Boolean.toString(defValue)));
}
- @Override public int getInteger (String key, int defValue) {
+ @Override
+ public int getInteger (String key, int defValue) {
return Integer.parseInt(properties.getProperty(key, Integer.toString(defValue)));
}
- @Override public long getLong (String key, long defValue) {
+ @Override
+ public long getLong (String key, long defValue) {
return Long.parseLong(properties.getProperty(key, Long.toString(defValue)));
}
- @Override public float getFloat (String key, float defValue) {
+ @Override
+ public float getFloat (String key, float defValue) {
return Float.parseFloat(properties.getProperty(key, Float.toString(defValue)));
}
- @Override public String getString (String key, String defValue) {
+ @Override
+ public String getString (String key, String defValue) {
return properties.getProperty(key, defValue);
}
- @Override public Map get () {
+ @Override
+ public Map get () {
Map map = new HashMap();
- for(Entry val: properties.entrySet()) {
- if(val.getValue() instanceof Boolean)
- map.put((String)val.getKey(), (Boolean)Boolean.parseBoolean((String)val.getValue()));
- if(val.getValue() instanceof Integer)
- map.put((String)val.getKey(), (Integer)Integer.parseInt((String)val.getValue()));
- if(val.getValue() instanceof Long)
- map.put((String)val.getKey(), (Long)Long.parseLong((String)val.getValue()));
- if(val.getValue() instanceof String)
- map.put((String)val.getKey(), (String)val.getValue());
- if(val.getValue() instanceof Float)
- map.put((String)val.getKey(), (Float)Float.parseFloat((String)val.getValue()));
+ for (Entry val : properties.entrySet()) {
+ if (val.getValue() instanceof Boolean)
+ map.put((String)val.getKey(), (Boolean)Boolean.parseBoolean((String)val.getValue()));
+ if (val.getValue() instanceof Integer) map.put((String)val.getKey(), (Integer)Integer.parseInt((String)val.getValue()));
+ if (val.getValue() instanceof Long) map.put((String)val.getKey(), (Long)Long.parseLong((String)val.getValue()));
+ if (val.getValue() instanceof String) map.put((String)val.getKey(), (String)val.getValue());
+ if (val.getValue() instanceof Float) map.put((String)val.getKey(), (Float)Float.parseFloat((String)val.getValue()));
}
-
+
return map;
}
- @Override public boolean contains (String key) {
+ @Override
+ public boolean contains (String key) {
return properties.containsKey(key);
}
- @Override public void clear () {
+ @Override
+ public void clear () {
properties.clear();
}
-
- @Override public void flush () {
+
+ @Override
+ public void flush () {
OutputStream out = null;
try {
out = new BufferedOutputStream(Gdx.files.external(JoglPreferences.this.name).write(false));
properties.storeToXML(out, null);
- } catch(Throwable t) {
+ } catch (Throwable t) {
} finally {
- if(out != null) try { out.close(); } catch(Exception e) { }
+ if (out != null) try {
+ out.close();
+ } catch (Exception e) {
+ }
}
}
}
diff --git a/backends/gdx-backend-lwjgl/src/com/badlogic/gdx/backends/lwjgl/LwjglApplet.java b/backends/gdx-backend-lwjgl/src/com/badlogic/gdx/backends/lwjgl/LwjglApplet.java
index 295cd316018..e842e3396a4 100644
--- a/backends/gdx-backend-lwjgl/src/com/badlogic/gdx/backends/lwjgl/LwjglApplet.java
+++ b/backends/gdx-backend-lwjgl/src/com/badlogic/gdx/backends/lwjgl/LwjglApplet.java
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
+
package com.badlogic.gdx.backends.lwjgl;
import java.applet.Applet;
@@ -21,10 +22,8 @@
import com.badlogic.gdx.ApplicationListener;
-/**
- * An OpenGL surface in an applet.
- * @author Nathan Sweet
- */
+/** An OpenGL surface in an applet.
+ * @author Nathan Sweet */
public class LwjglApplet extends Applet {
final Canvas canvas;
LwjglApplication app;
@@ -32,14 +31,15 @@ public class LwjglApplet extends Applet {
class LwjglAppletApplication extends LwjglApplication {
public LwjglAppletApplication (ApplicationListener listener, boolean useGL2, Canvas canvas) {
- super(listener, useGL2, canvas);
+ super(listener, useGL2, canvas);
}
-
- @Override public ApplicationType getType() {
+
+ @Override
+ public ApplicationType getType () {
return ApplicationType.Applet;
}
}
-
+
public LwjglApplet (final ApplicationListener listener, final boolean useGL2) {
LwjglNativesLoader.load = false;
canvas = new Canvas() {
diff --git a/backends/gdx-backend-lwjgl/src/com/badlogic/gdx/backends/lwjgl/LwjglApplication.java b/backends/gdx-backend-lwjgl/src/com/badlogic/gdx/backends/lwjgl/LwjglApplication.java
index 30f6cc104ca..811794fe7b6 100644
--- a/backends/gdx-backend-lwjgl/src/com/badlogic/gdx/backends/lwjgl/LwjglApplication.java
+++ b/backends/gdx-backend-lwjgl/src/com/badlogic/gdx/backends/lwjgl/LwjglApplication.java
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
+
package com.badlogic.gdx.backends.lwjgl;
import java.awt.Canvas;
@@ -23,7 +24,6 @@
import org.lwjgl.LWJGLException;
import org.lwjgl.opengl.Display;
-import org.lwjgl.opengl.GL11;
import com.badlogic.gdx.Application;
import com.badlogic.gdx.ApplicationListener;
@@ -34,12 +34,9 @@
import com.badlogic.gdx.Input;
import com.badlogic.gdx.Preferences;
import com.badlogic.gdx.backends.openal.OpenALAudio;
-import com.badlogic.gdx.graphics.GL10;
import com.badlogic.gdx.utils.GdxRuntimeException;
-/**
- * An OpenGL surface fullscreen or in a lightweight window.
- */
+/** An OpenGL surface fullscreen or in a lightweight window. */
public class LwjglApplication implements Application {
LwjglGraphics graphics;
OpenALAudio audio;
@@ -73,23 +70,23 @@ public LwjglApplication (ApplicationListener listener, String title, int width,
Gdx.input = input;
initialize();
}
-
+
public LwjglApplication (ApplicationListener listener, LwjglApplicationConfiguration config) {
LwjglNativesLoader.load();
-
+
graphics = new LwjglGraphics(config);
audio = new OpenALAudio();
files = new LwjglFiles();
input = new LwjglInput();
- this.listener = listener;
-
+ this.listener = listener;
+
Gdx.app = this;
Gdx.graphics = graphics;
Gdx.audio = audio;
Gdx.files = files;
Gdx.input = input;
initialize();
-
+
}
public LwjglApplication (ApplicationListener listener, boolean useGL2, Canvas canvas) {
@@ -111,7 +108,8 @@ public LwjglApplication (ApplicationListener listener, boolean useGL2, Canvas ca
private void initialize () {
mainLoopThread = new Thread("LWJGL Application") {
- @SuppressWarnings("synthetic-access") public void run () {
+ @SuppressWarnings("synthetic-access")
+ public void run () {
graphics.setVSync(graphics.config.vSyncEnabled);
LwjglApplication.this.mainLoop();
}
@@ -131,21 +129,21 @@ private void mainLoop () {
graphics.resize = false;
int lastWidth = graphics.getWidth();
- int lastHeight = graphics.getHeight();
-
+ int lastHeight = graphics.getHeight();
+
graphics.lastTime = System.nanoTime();
while (running) {
- if(Display.isCloseRequested()) {
+ if (Display.isCloseRequested()) {
exit();
}
-
+
graphics.updateTime();
- if(graphics.resize) {
+ if (graphics.resize) {
graphics.resize = false;
listener.resize(graphics.getWidth(), graphics.getHeight());
}
- synchronized(runnables) {
- for(int i = 0; i < runnables.size(); i++) {
+ synchronized (runnables) {
+ for (int i = 0; i < runnables.size(); i++) {
runnables.get(i).run();
}
runnables.clear();
@@ -166,7 +164,7 @@ private void mainLoop () {
listener.render();
audio.update();
Display.update();
- if (graphics.vsync && graphics.config.useCPUSynch) {
+ if (graphics.vsync && graphics.config.useCPUSynch) {
Display.sync(60);
}
}
@@ -175,30 +173,36 @@ private void mainLoop () {
listener.dispose();
Display.destroy();
audio.dispose();
- if(graphics.config.forceExit) System.exit(-1);
+ if (graphics.config.forceExit) System.exit(-1);
}
- @Override public Audio getAudio () {
+ @Override
+ public Audio getAudio () {
return audio;
}
- @Override public Files getFiles () {
+ @Override
+ public Files getFiles () {
return files;
}
- @Override public Graphics getGraphics () {
+ @Override
+ public Graphics getGraphics () {
return graphics;
}
- @Override public Input getInput () {
+ @Override
+ public Input getInput () {
return input;
}
- @Override public ApplicationType getType () {
+ @Override
+ public ApplicationType getType () {
return ApplicationType.Desktop;
}
- @Override public int getVersion () {
+ @Override
+ public int getVersion () {
return 0;
}
@@ -210,17 +214,21 @@ public void stop () {
}
}
- @Override public long getJavaHeap () {
+ @Override
+ public long getJavaHeap () {
return Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory();
}
- @Override public long getNativeHeap () {
+ @Override
+ public long getNativeHeap () {
return getJavaHeap();
}
Map preferences = new HashMap();
- @Override public Preferences getPreferences (String name) {
- if(preferences.containsKey(name)) {
+
+ @Override
+ public Preferences getPreferences (String name) {
+ if (preferences.containsKey(name)) {
return preferences.get(name);
} else {
Preferences prefs = new LwjglPreferences(name);
@@ -229,49 +237,54 @@ public void stop () {
}
}
- @Override public void postRunnable (Runnable runnable) {
+ @Override
+ public void postRunnable (Runnable runnable) {
synchronized (runnables) {
runnables.add(runnable);
}
}
-
- public void log(String tag, String message) {
- if(logLevel >= LOG_INFO) {
- System.out.println(tag + ":" + message);
+
+ public void log (String tag, String message) {
+ if (logLevel >= LOG_INFO) {
+ System.out.println(tag + ":" + message);
}
- }
+ }
- @Override public void log (String tag, String message, Exception exception) {
- if(logLevel >= LOG_INFO) {
+ @Override
+ public void log (String tag, String message, Exception exception) {
+ if (logLevel >= LOG_INFO) {
System.out.println(tag + ":" + message);
exception.printStackTrace(System.out);
}
}
-
- @Override public void error (String tag, String message) {
- if(logLevel >= LOG_ERROR) {
- System.err.println(tag + ":" + message);
+
+ @Override
+ public void error (String tag, String message) {
+ if (logLevel >= LOG_ERROR) {
+ System.err.println(tag + ":" + message);
}
}
-
- @Override public void error (String tag, String message, Exception exception) {
- if(logLevel >= LOG_ERROR) {
+ @Override
+ public void error (String tag, String message, Exception exception) {
+ if (logLevel >= LOG_ERROR) {
System.err.println(tag + ":" + message);
exception.printStackTrace(System.err);
}
}
-
- @Override public void setLogLevel (int logLevel) {
+ @Override
+ public void setLogLevel (int logLevel) {
this.logLevel = logLevel;
}
-
- @Override public void exit () {
+
+ @Override
+ public void exit () {
postRunnable(new Runnable() {
- @Override public void run () {
+ @Override
+ public void run () {
running = false;
- }
+ }
});
}
}
diff --git a/backends/gdx-backend-lwjgl/src/com/badlogic/gdx/backends/lwjgl/LwjglApplicationConfiguration.java b/backends/gdx-backend-lwjgl/src/com/badlogic/gdx/backends/lwjgl/LwjglApplicationConfiguration.java
index cd18487af3e..f47e3073acc 100644
--- a/backends/gdx-backend-lwjgl/src/com/badlogic/gdx/backends/lwjgl/LwjglApplicationConfiguration.java
+++ b/backends/gdx-backend-lwjgl/src/com/badlogic/gdx/backends/lwjgl/LwjglApplicationConfiguration.java
@@ -1,3 +1,4 @@
+
package com.badlogic.gdx.backends.lwjgl;
import java.awt.GraphicsDevice;
@@ -9,7 +10,7 @@
public class LwjglApplicationConfiguration {
/** whether to use OpenGL ES 2.0 or not. default: false **/
- public boolean useGL20 = false;
+ public boolean useGL20 = false;
/** number of bits per color channel **/
public int r = 8, g = 8, b = 8, a = 8;
/** number of bits for depth and stencil buffer **/
@@ -27,29 +28,26 @@ public class LwjglApplicationConfiguration {
/** title of application **/
public String title = "Lwjgl Application";
/** whether to call System.exit() on tear-down. Needed for Webstarts on some versions of Mac OS X it seems **/
- public boolean forceExit = true;
-
- /**
- * Sets the r, g, b and a bits per channel based on the given
- * {@link DisplayMode} and sets the fullscreen flag to true.
- * @param mode
- */
- public void setFromDisplayMode(DisplayMode mode) {
+ public boolean forceExit = true;
+
+ /** Sets the r, g, b and a bits per channel based on the given {@link DisplayMode} and sets the fullscreen flag to true.
+ * @param mode */
+ public void setFromDisplayMode (DisplayMode mode) {
this.width = mode.width;
this.height = mode.height;
- if(mode.bitsPerPixel == 16) {
+ if (mode.bitsPerPixel == 16) {
this.r = 5;
this.g = 6;
this.b = 5;
this.a = 0;
}
- if(mode.bitsPerPixel == 24) {
+ if (mode.bitsPerPixel == 24) {
this.r = 8;
this.g = 8;
this.b = 8;
this.a = 0;
}
- if(mode.bitsPerPixel == 32) {
+ if (mode.bitsPerPixel == 32) {
this.r = 8;
this.g = 8;
this.b = 8;
@@ -57,42 +55,43 @@ public void setFromDisplayMode(DisplayMode mode) {
}
this.fullscreen = true;
}
-
+
protected static class LwjglApplicationConfigurationDisplayMode extends DisplayMode {
protected LwjglApplicationConfigurationDisplayMode (int width, int height, int refreshRate, int bitsPerPixel) {
super(width, height, refreshRate, bitsPerPixel);
- }
+ }
}
-
+
public static DisplayMode getDesktopDisplayMode () {
GraphicsEnvironment genv = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice device = genv.getDefaultScreenDevice();
java.awt.DisplayMode mode = device.getDisplayMode();
- return new LwjglApplicationConfigurationDisplayMode(mode.getWidth(), mode.getHeight(), mode.getRefreshRate(), mode.getBitDepth());
+ return new LwjglApplicationConfigurationDisplayMode(mode.getWidth(), mode.getHeight(), mode.getRefreshRate(),
+ mode.getBitDepth());
}
-
- public static DisplayMode[] getDisplayModes() {
+
+ public static DisplayMode[] getDisplayModes () {
GraphicsEnvironment genv = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice device = genv.getDefaultScreenDevice();
java.awt.DisplayMode desktopMode = device.getDisplayMode();
java.awt.DisplayMode[] displayModes = device.getDisplayModes();
ArrayList modes = new ArrayList();
int idx = 0;
- for(java.awt.DisplayMode mode: displayModes) {
+ for (java.awt.DisplayMode mode : displayModes) {
boolean duplicate = false;
- for(int i = 0; i < modes.size(); i++) {
- if(modes.get(i).width == mode.getWidth() &&
- modes.get(i).height == mode.getHeight() &&
- modes.get(i).bitsPerPixel == mode.getBitDepth()) {
+ for (int i = 0; i < modes.size(); i++) {
+ if (modes.get(i).width == mode.getWidth() && modes.get(i).height == mode.getHeight()
+ && modes.get(i).bitsPerPixel == mode.getBitDepth()) {
duplicate = true;
break;
}
}
- if(duplicate) continue;
- if(mode.getBitDepth() != desktopMode.getBitDepth()) continue;
- modes.add(new LwjglApplicationConfigurationDisplayMode(mode.getWidth(), mode.getHeight(), mode.getRefreshRate(), mode.getBitDepth()));
+ if (duplicate) continue;
+ if (mode.getBitDepth() != desktopMode.getBitDepth()) continue;
+ modes.add(new LwjglApplicationConfigurationDisplayMode(mode.getWidth(), mode.getHeight(), mode.getRefreshRate(), mode
+ .getBitDepth()));
}
-
+
return modes.toArray(new DisplayMode[modes.size()]);
}
}
diff --git a/backends/gdx-backend-lwjgl/src/com/badlogic/gdx/backends/lwjgl/LwjglCanvas.java b/backends/gdx-backend-lwjgl/src/com/badlogic/gdx/backends/lwjgl/LwjglCanvas.java
index 78a0c6aee98..9ecb3098bab 100644
--- a/backends/gdx-backend-lwjgl/src/com/badlogic/gdx/backends/lwjgl/LwjglCanvas.java
+++ b/backends/gdx-backend-lwjgl/src/com/badlogic/gdx/backends/lwjgl/LwjglCanvas.java
@@ -25,7 +25,6 @@
import java.util.Map;
import org.lwjgl.LWJGLException;
-import org.lwjgl.input.Keyboard;
import org.lwjgl.opengl.Display;
import com.badlogic.gdx.Application;
diff --git a/backends/gdx-backend-lwjgl/src/com/badlogic/gdx/backends/lwjgl/LwjglFileHandle.java b/backends/gdx-backend-lwjgl/src/com/badlogic/gdx/backends/lwjgl/LwjglFileHandle.java
index e304adc4a21..1fced99486e 100644
--- a/backends/gdx-backend-lwjgl/src/com/badlogic/gdx/backends/lwjgl/LwjglFileHandle.java
+++ b/backends/gdx-backend-lwjgl/src/com/badlogic/gdx/backends/lwjgl/LwjglFileHandle.java
@@ -21,10 +21,8 @@
import com.badlogic.gdx.Files.FileType;
import com.badlogic.gdx.files.FileHandle;
-/**
- * @author mzechner
- * @author Nathan Sweet
- */
+/** @author mzechner
+ * @author Nathan Sweet */
public final class LwjglFileHandle extends FileHandle {
public LwjglFileHandle (String fileName, FileType type) {
super(fileName, type);
diff --git a/backends/gdx-backend-lwjgl/src/com/badlogic/gdx/backends/lwjgl/LwjglFiles.java b/backends/gdx-backend-lwjgl/src/com/badlogic/gdx/backends/lwjgl/LwjglFiles.java
index bf9e439454b..1efd17cf47c 100644
--- a/backends/gdx-backend-lwjgl/src/com/badlogic/gdx/backends/lwjgl/LwjglFiles.java
+++ b/backends/gdx-backend-lwjgl/src/com/badlogic/gdx/backends/lwjgl/LwjglFiles.java
@@ -13,43 +13,49 @@
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
+
package com.badlogic.gdx.backends.lwjgl;
import com.badlogic.gdx.Files;
import com.badlogic.gdx.files.FileHandle;
-/**
- * @author mzechner
- * @author Nathan Sweet
- */
+/** @author mzechner
+ * @author Nathan Sweet */
public final class LwjglFiles implements Files {
private final String externalPath = System.getProperty("user.home") + "/";
- @Override public FileHandle getFileHandle (String fileName, FileType type) {
+ @Override
+ public FileHandle getFileHandle (String fileName, FileType type) {
return new LwjglFileHandle(fileName, type);
}
- @Override public FileHandle classpath (String path) {
+ @Override
+ public FileHandle classpath (String path) {
return new LwjglFileHandle(path, FileType.Classpath);
}
- @Override public FileHandle internal (String path) {
+ @Override
+ public FileHandle internal (String path) {
return new LwjglFileHandle(path, FileType.Internal);
}
- @Override public FileHandle external (String path) {
+ @Override
+ public FileHandle external (String path) {
return new LwjglFileHandle(path, FileType.External);
}
- @Override public FileHandle absolute (String path) {
+ @Override
+ public FileHandle absolute (String path) {
return new LwjglFileHandle(path, FileType.Absolute);
}
- @Override public String getExternalStoragePath () {
+ @Override
+ public String getExternalStoragePath () {
return externalPath;
}
- @Override public boolean isExternalStorageAvailable () {
+ @Override
+ public boolean isExternalStorageAvailable () {
return true;
}
}
diff --git a/backends/gdx-backend-lwjgl/src/com/badlogic/gdx/backends/lwjgl/LwjglFrame.java b/backends/gdx-backend-lwjgl/src/com/badlogic/gdx/backends/lwjgl/LwjglFrame.java
index bbe7c86e01f..633ad4a65ed 100644
--- a/backends/gdx-backend-lwjgl/src/com/badlogic/gdx/backends/lwjgl/LwjglFrame.java
+++ b/backends/gdx-backend-lwjgl/src/com/badlogic/gdx/backends/lwjgl/LwjglFrame.java
@@ -7,7 +7,6 @@
import javax.swing.JFrame;
import com.badlogic.gdx.ApplicationListener;
-import com.badlogic.gdx.Gdx;
/** Wraps an {@link LwjglCanvas} in a resizable {@link JFrame}. */
public class LwjglFrame extends JFrame {
diff --git a/backends/gdx-backend-lwjgl/src/com/badlogic/gdx/backends/lwjgl/LwjglGL10.java b/backends/gdx-backend-lwjgl/src/com/badlogic/gdx/backends/lwjgl/LwjglGL10.java
index f133edb07da..d85aa209590 100644
--- a/backends/gdx-backend-lwjgl/src/com/badlogic/gdx/backends/lwjgl/LwjglGL10.java
+++ b/backends/gdx-backend-lwjgl/src/com/badlogic/gdx/backends/lwjgl/LwjglGL10.java
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
+
package com.badlogic.gdx.backends.lwjgl;
import java.nio.Buffer;
@@ -30,12 +31,9 @@
import com.badlogic.gdx.graphics.GL10;
import com.badlogic.gdx.utils.GdxRuntimeException;
-/**
- * An implementation of the {@link GL10} interface based on Jogl. Fixed point vertex arrays are emulated.
- *
- * @author mzechner
+/** An implementation of the {@link GL10} interface based on Jogl. Fixed point vertex arrays are emulated.
*
- */
+ * @author mzechner */
class LwjglGL10 implements GL10 {
private IntBuffer tempInt;
private FloatBuffer tempFloat;
@@ -493,12 +491,13 @@ public final void glGenTextures (int n, int[] textures, int offset) {
textures[i] = GL11.glGenTextures();
}
- IntBuffer getBuffer = BufferUtils.createIntBuffer(100);
- public final void glGetIntegerv (int pname, int[] params, int offset) {
+ IntBuffer getBuffer = BufferUtils.createIntBuffer(100);
+
+ public final void glGetIntegerv (int pname, int[] params, int offset) {
GL11.glGetInteger(pname, getBuffer);
- // FIXME Yeah, so. This sucks as well :D LWJGL does not set pos/lim.
- for(int i = offset, j = 0; i < params.length; i++, j++) {
- if(j == getBuffer.capacity()) return;
+ // FIXME Yeah, so. This sucks as well :D LWJGL does not set pos/lim.
+ for (int i = offset, j = 0; i < params.length; i++, j++) {
+ if (j == getBuffer.capacity()) return;
params[i] = getBuffer.get(j);
}
}
diff --git a/backends/gdx-backend-lwjgl/src/com/badlogic/gdx/backends/lwjgl/LwjglGL11.java b/backends/gdx-backend-lwjgl/src/com/badlogic/gdx/backends/lwjgl/LwjglGL11.java
index 4cb20b4e969..cd6b62a0b8d 100644
--- a/backends/gdx-backend-lwjgl/src/com/badlogic/gdx/backends/lwjgl/LwjglGL11.java
+++ b/backends/gdx-backend-lwjgl/src/com/badlogic/gdx/backends/lwjgl/LwjglGL11.java
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
+
package com.badlogic.gdx.backends.lwjgl;
import java.nio.Buffer;
@@ -28,13 +29,10 @@
import org.lwjgl.opengl.GL14;
import org.lwjgl.opengl.GL15;
-/**
- * An implementation of the {@link GL11} interface based on Jogl. Fixed point vertex arrays are emulated. Some glGetXXX methods
+/** An implementation of the {@link GL11} interface based on Jogl. Fixed point vertex arrays are emulated. Some glGetXXX methods
* are not implemented.
*
- * @author mzechner
- *
- */
+ * @author mzechner */
final class LwjglGL11 extends LwjglGL10 implements com.badlogic.gdx.graphics.GL11 {
private IntBuffer tempInt;
private FloatBuffer tempFloat;
diff --git a/backends/gdx-backend-lwjgl/src/com/badlogic/gdx/backends/lwjgl/LwjglGL20.java b/backends/gdx-backend-lwjgl/src/com/badlogic/gdx/backends/lwjgl/LwjglGL20.java
index 217c8d80c1b..c9fb9b8ba00 100644
--- a/backends/gdx-backend-lwjgl/src/com/badlogic/gdx/backends/lwjgl/LwjglGL20.java
+++ b/backends/gdx-backend-lwjgl/src/com/badlogic/gdx/backends/lwjgl/LwjglGL20.java
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
+
package com.badlogic.gdx.backends.lwjgl;
import java.nio.Buffer;
@@ -34,13 +35,10 @@
import com.badlogic.gdx.graphics.GL10;
import com.badlogic.gdx.utils.GdxRuntimeException;
-/**
- * An implementation of the {@link GL20} interface based on Jogl. Note that Jogl shaders and OpenGL ES shaders will not be 100%
+/** An implementation of the {@link GL20} interface based on Jogl. Note that Jogl shaders and OpenGL ES shaders will not be 100%
* compatible. Some glGetXXX methods are not implemented.
*
- * @author mzechner
- *
- */
+ * @author mzechner */
final class LwjglGL20 implements com.badlogic.gdx.graphics.GL20 {
public void glActiveTexture (int texture) {
GL13.glActiveTexture(texture);
@@ -287,18 +285,18 @@ public void glGenerateMipmap (int target) {
}
public String glGetActiveAttrib (int program, int index, IntBuffer size, Buffer type) {
- // FIXME this is less than ideal of course...
- IntBuffer typeTmp = BufferUtils.createIntBuffer(2);
+ // FIXME this is less than ideal of course...
+ IntBuffer typeTmp = BufferUtils.createIntBuffer(2);
String name = GL20.glGetActiveAttrib(program, index, 256, typeTmp);
- if(type instanceof IntBuffer) ((IntBuffer)type).put(typeTmp.get(0));
+ if (type instanceof IntBuffer) ((IntBuffer)type).put(typeTmp.get(0));
return name;
}
public String glGetActiveUniform (int program, int index, IntBuffer size, Buffer type) {
- // FIXME this is less than ideal of course...
- IntBuffer typeTmp = BufferUtils.createIntBuffer(2);
+ // FIXME this is less than ideal of course...
+ IntBuffer typeTmp = BufferUtils.createIntBuffer(2);
String name = GL20.glGetActiveUniform(program, index, 256, typeTmp);
- if(type instanceof IntBuffer) ((IntBuffer)type).put(typeTmp.get(0));
+ if (type instanceof IntBuffer) ((IntBuffer)type).put(typeTmp.get(0));
return name;
}
diff --git a/backends/gdx-backend-lwjgl/src/com/badlogic/gdx/backends/lwjgl/LwjglGLU.java b/backends/gdx-backend-lwjgl/src/com/badlogic/gdx/backends/lwjgl/LwjglGLU.java
index 31d68e8b6a5..3290184bb8d 100644
--- a/backends/gdx-backend-lwjgl/src/com/badlogic/gdx/backends/lwjgl/LwjglGLU.java
+++ b/backends/gdx-backend-lwjgl/src/com/badlogic/gdx/backends/lwjgl/LwjglGLU.java
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
+
package com.badlogic.gdx.backends.lwjgl;
import java.nio.FloatBuffer;
@@ -24,57 +25,68 @@
import com.badlogic.gdx.graphics.GLU;
public class LwjglGLU implements GLU {
-
+
FloatBuffer modelb;
FloatBuffer projectb;
IntBuffer viewb;
FloatBuffer winb;
-
- public LwjglGLU() {
+
+ public LwjglGLU () {
modelb = BufferUtils.createFloatBuffer(16);
projectb = BufferUtils.createFloatBuffer(16);
viewb = BufferUtils.createIntBuffer(4);
winb = BufferUtils.createFloatBuffer(3);
}
- @Override public void gluLookAt (GL10 gl, float eyeX, float eyeY, float eyeZ, float centerX, float centerY, float centerZ,
- float upX, float upY, float upZ) {
+ @Override
+ public void gluLookAt (GL10 gl, float eyeX, float eyeY, float eyeZ, float centerX, float centerY, float centerZ, float upX,
+ float upY, float upZ) {
org.lwjgl.util.glu.GLU.gluLookAt(eyeX, eyeY, eyeZ, centerX, centerY, centerZ, upX, upY, upZ);
}
- @Override public void gluOrtho2D (GL10 gl, float left, float right, float bottom, float top) {
+ @Override
+ public void gluOrtho2D (GL10 gl, float left, float right, float bottom, float top) {
org.lwjgl.util.glu.GLU.gluOrtho2D(left, right, bottom, top);
}
- @Override public void gluPerspective (GL10 gl, float fovy, float aspect, float zNear, float zFar) {
+ @Override
+ public void gluPerspective (GL10 gl, float fovy, float aspect, float zNear, float zFar) {
org.lwjgl.util.glu.GLU.gluPerspective(fovy, aspect, zNear, zFar);
}
- @Override public boolean gluProject (float objX, float objY, float objZ, float[] model, int modelOffset, float[] project,
+ @Override
+ public boolean gluProject (float objX, float objY, float objZ, float[] model, int modelOffset, float[] project,
int projectOffset, int[] view, int viewOffset, float[] win, int winOffset) {
- modelb.clear(); modelb.put(model, modelOffset, 16);
- projectb.clear(); projectb.put(project, projectOffset, 16);
- viewb.clear(); viewb.put(view, viewOffset, 4);
+ modelb.clear();
+ modelb.put(model, modelOffset, 16);
+ projectb.clear();
+ projectb.put(project, projectOffset, 16);
+ viewb.clear();
+ viewb.put(view, viewOffset, 4);
winb.clear();
-
+
boolean result = org.lwjgl.util.glu.GLU.gluProject(objX, objY, objZ, modelb, projectb, viewb, winb);
win[winOffset] = winb.get(0);
- win[winOffset+1] = winb.get(1);
- win[winOffset+2] = winb.get(2);
+ win[winOffset + 1] = winb.get(1);
+ win[winOffset + 2] = winb.get(2);
return result;
}
- @Override public boolean gluUnProject (float winX, float winY, float winZ, float[] model, int modelOffset, float[] project,
+ @Override
+ public boolean gluUnProject (float winX, float winY, float winZ, float[] model, int modelOffset, float[] project,
int projectOffset, int[] view, int viewOffset, float[] obj, int objOffset) {
- modelb.clear(); modelb.put(model, modelOffset, 16);
- projectb.clear(); projectb.put(project, projectOffset, 16);
- viewb.clear(); viewb.put(view, viewOffset, 4);
+ modelb.clear();
+ modelb.put(model, modelOffset, 16);
+ projectb.clear();
+ projectb.put(project, projectOffset, 16);
+ viewb.clear();
+ viewb.put(view, viewOffset, 4);
winb.clear();
-
+
boolean result = org.lwjgl.util.glu.GLU.gluUnProject(winX, winY, winZ, modelb, projectb, viewb, winb);
obj[objOffset] = winb.get(0);
- obj[objOffset+1] = winb.get(1);
- obj[objOffset+2] = winb.get(2);
+ obj[objOffset + 1] = winb.get(1);
+ obj[objOffset + 2] = winb.get(2);
return result;
}
}
diff --git a/backends/gdx-backend-lwjgl/src/com/badlogic/gdx/backends/lwjgl/LwjglGraphics.java b/backends/gdx-backend-lwjgl/src/com/badlogic/gdx/backends/lwjgl/LwjglGraphics.java
index 33c237c3ff5..0f3f8457a41 100644
--- a/backends/gdx-backend-lwjgl/src/com/badlogic/gdx/backends/lwjgl/LwjglGraphics.java
+++ b/backends/gdx-backend-lwjgl/src/com/badlogic/gdx/backends/lwjgl/LwjglGraphics.java
@@ -34,10 +34,8 @@
import com.badlogic.gdx.graphics.Pixmap;
import com.badlogic.gdx.utils.GdxRuntimeException;
-/**
- * An implementation of the {@link Graphics} interface based on Lwjgl.
- * @author mzechner
- */
+/** An implementation of the {@link Graphics} interface based on Lwjgl.
+ * @author mzechner */
public final class LwjglGraphics implements Graphics {
static int major, minor;
@@ -45,12 +43,12 @@ public final class LwjglGraphics implements Graphics {
GL10 gl10;
GL11 gl11;
GL20 gl20;
- GLU glu;
+ GLU glu;
float deltaTime = 0;
long frameStart = 0;
int frames = 0;
int fps;
- long lastTime = System.nanoTime();
+ long lastTime = System.nanoTime();
Canvas canvas;
boolean vsync = false;
boolean resize = false;
@@ -58,7 +56,7 @@ public final class LwjglGraphics implements Graphics {
BufferFormat bufferFormat = new BufferFormat(8, 8, 8, 8, 16, 8, 0, false);
String extensions;
- LwjglGraphics (LwjglApplicationConfiguration config) {
+ LwjglGraphics (LwjglApplicationConfiguration config) {
this.config = config;
}
@@ -120,7 +118,8 @@ public int getFramesPerSecond () {
return fps;
}
- @Override public GLCommon getGLCommon () {
+ @Override
+ public GLCommon getGLCommon () {
return gl;
}
@@ -141,43 +140,45 @@ void setupDisplay () throws LWJGLException {
if (canvas != null) {
Display.setParent(canvas);
} else {
- if(!setDisplayMode(config.width, config.height, config.fullscreen))
- throw new GdxRuntimeException("Couldn't set display mode " + config.width + "x" + config.height + ", fullscreen: " + config.fullscreen);
+ if (!setDisplayMode(config.width, config.height, config.fullscreen))
+ throw new GdxRuntimeException("Couldn't set display mode " + config.width + "x" + config.height + ", fullscreen: "
+ + config.fullscreen);
}
Display.setTitle(config.title);
- createDisplayPixelFormat();
+ createDisplayPixelFormat();
initiateGLInstances();
}
-
- private void createDisplayPixelFormat() {
+
+ private void createDisplayPixelFormat () {
int samples = 0;
try {
Display.create(new PixelFormat(config.r + config.g + config.b, config.a, config.depth, config.stencil, config.samples));
- bufferFormat = new BufferFormat(config.r, config.g, config.b, config.a, config.depth, config.stencil, config.samples, false);
+ bufferFormat = new BufferFormat(config.r, config.g, config.b, config.a, config.depth, config.stencil, config.samples,
+ false);
} catch (Exception ex) {
Display.destroy();
try {
Display.create(new PixelFormat(0, 16, 8));
- if(getDesktopDisplayMode().bitsPerPixel == 16) {
+ if (getDesktopDisplayMode().bitsPerPixel == 16) {
bufferFormat = new BufferFormat(5, 6, 5, 0, 16, 8, 0, false);
}
- if(getDesktopDisplayMode().bitsPerPixel == 24) {
+ if (getDesktopDisplayMode().bitsPerPixel == 24) {
bufferFormat = new BufferFormat(8, 8, 8, 0, 16, 8, 0, false);
}
- if(getDesktopDisplayMode().bitsPerPixel == 32) {
+ if (getDesktopDisplayMode().bitsPerPixel == 32) {
bufferFormat = new BufferFormat(8, 8, 8, 8, 16, 8, 0, false);
}
} catch (Exception ex2) {
Display.destroy();
try {
Display.create(new PixelFormat());
- if(getDesktopDisplayMode().bitsPerPixel == 16) {
+ if (getDesktopDisplayMode().bitsPerPixel == 16) {
bufferFormat = new BufferFormat(5, 6, 5, 0, 8, 0, 0, false);
}
- if(getDesktopDisplayMode().bitsPerPixel == 24) {
+ if (getDesktopDisplayMode().bitsPerPixel == 24) {
bufferFormat = new BufferFormat(8, 8, 8, 0, 8, 0, 0, false);
}
- if(getDesktopDisplayMode().bitsPerPixel == 32) {
+ if (getDesktopDisplayMode().bitsPerPixel == 32) {
bufferFormat = new BufferFormat(8, 8, 8, 8, 8, 0, 0, false);
}
} catch (Exception ex3) {
@@ -216,42 +217,48 @@ private void initiateGLInstances () {
Gdx.gl20 = gl20;
}
- @Override public float getPpiX () {
+ @Override
+ public float getPpiX () {
return Toolkit.getDefaultToolkit().getScreenResolution();
}
- @Override public float getPpiY () {
+ @Override
+ public float getPpiY () {
return Toolkit.getDefaultToolkit().getScreenResolution();
}
- @Override public float getPpcX () {
+ @Override
+ public float getPpcX () {
return (Toolkit.getDefaultToolkit().getScreenResolution() / 2.54f);
}
- @Override public float getPpcY () {
+ @Override
+ public float getPpcY () {
return (Toolkit.getDefaultToolkit().getScreenResolution() / 2.54f);
}
-
- @Override public float getDensity () {
+
+ @Override
+ public float getDensity () {
return (Toolkit.getDefaultToolkit().getScreenResolution() / 160f);
}
- @Override public boolean supportsDisplayModeChange () {
+ @Override
+ public boolean supportsDisplayModeChange () {
return true;
}
private class LwjglDisplayMode extends DisplayMode {
org.lwjgl.opengl.DisplayMode mode;
- public LwjglDisplayMode (int width, int height, int refreshRate, int bitsPerPixel,
- org.lwjgl.opengl.DisplayMode mode) {
+ public LwjglDisplayMode (int width, int height, int refreshRate, int bitsPerPixel, org.lwjgl.opengl.DisplayMode mode) {
super(width, height, refreshRate, bitsPerPixel);
this.mode = mode;
}
}
- @Override public boolean setDisplayMode (DisplayMode displayMode) {
+ @Override
+ public boolean setDisplayMode (DisplayMode displayMode) {
org.lwjgl.opengl.DisplayMode mode = ((LwjglDisplayMode)displayMode).mode;
try {
if (!mode.isFullscreenCapable()) {
@@ -259,7 +266,7 @@ public LwjglDisplayMode (int width, int height, int refreshRate, int bitsPerPixe
} else {
Display.setDisplayModeAndFullscreen(mode);
}
- if(Gdx.gl != null) Gdx.gl.glViewport(0, 0, displayMode.width, displayMode.height);
+ if (Gdx.gl != null) Gdx.gl.glViewport(0, 0, displayMode.width, displayMode.height);
config.width = displayMode.width;
config.height = displayMode.height;
resize = true;
@@ -269,10 +276,9 @@ public LwjglDisplayMode (int width, int height, int refreshRate, int bitsPerPixe
}
}
- /**
- * Kindly stolen from http://lwjgl.org/wiki/index.php?title=LWJGL_Basics_5_(Fullscreen), not perfect but will do.
- */
- @Override public boolean setDisplayMode (int width, int height, boolean fullscreen) {
+ /** Kindly stolen from http://lwjgl.org/wiki/index.php?title=LWJGL_Basics_5_(Fullscreen), not perfect but will do. */
+ @Override
+ public boolean setDisplayMode (int width, int height, boolean fullscreen) {
if ((Display.getDisplayMode().getWidth() == width) && (Display.getDisplayMode().getHeight() == height)
&& (Display.isFullscreen() == fullscreen)) {
return true;
@@ -310,13 +316,13 @@ public LwjglDisplayMode (int width, int height, int refreshRate, int bitsPerPixe
targetDisplayMode = new org.lwjgl.opengl.DisplayMode(width, height);
}
- if (targetDisplayMode == null) {
+ if (targetDisplayMode == null) {
return false;
}
Display.setDisplayMode(targetDisplayMode);
Display.setFullscreen(fullscreen);
- if(Gdx.gl != null) Gdx.gl.glViewport(0, 0, targetDisplayMode.getWidth(), targetDisplayMode.getHeight());
+ if (Gdx.gl != null) Gdx.gl.glViewport(0, 0, targetDisplayMode.getWidth(), targetDisplayMode.getHeight());
config.width = targetDisplayMode.getWidth();
config.height = targetDisplayMode.getHeight();
resize = true;
@@ -326,15 +332,17 @@ public LwjglDisplayMode (int width, int height, int refreshRate, int bitsPerPixe
}
}
- @Override public DisplayMode[] getDisplayModes () {
+ @Override
+ public DisplayMode[] getDisplayModes () {
try {
org.lwjgl.opengl.DisplayMode[] availableDisplayModes = Display.getAvailableDisplayModes();
DisplayMode[] modes = new DisplayMode[availableDisplayModes.length];
int idx = 0;
for (org.lwjgl.opengl.DisplayMode mode : availableDisplayModes) {
- if(mode.isFullscreenCapable()) {
- modes[idx++] = new LwjglDisplayMode(mode.getWidth(), mode.getHeight(), mode.getFrequency(), mode.getBitsPerPixel(), mode);
+ if (mode.isFullscreenCapable()) {
+ modes[idx++] = new LwjglDisplayMode(mode.getWidth(), mode.getHeight(), mode.getFrequency(),
+ mode.getBitsPerPixel(), mode);
}
}
@@ -343,32 +351,38 @@ public LwjglDisplayMode (int width, int height, int refreshRate, int bitsPerPixe
throw new GdxRuntimeException("Couldn't fetch available display modes", e);
}
}
-
- @Override public DisplayMode getDesktopDisplayMode() {
+
+ @Override
+ public DisplayMode getDesktopDisplayMode () {
org.lwjgl.opengl.DisplayMode mode = Display.getDesktopDisplayMode();
return new LwjglDisplayMode(mode.getWidth(), mode.getHeight(), mode.getFrequency(), mode.getBitsPerPixel(), mode);
}
- @Override public void setTitle (String title) {
+ @Override
+ public void setTitle (String title) {
Display.setTitle(title);
}
- @Override public void setIcon (Pixmap pixmap) {
- Display.setIcon(new ByteBuffer[] { pixmap.getPixels().duplicate() } );
+ @Override
+ public void setIcon (Pixmap pixmap) {
+ Display.setIcon(new ByteBuffer[] {pixmap.getPixels().duplicate()});
}
- @Override public BufferFormat getBufferFormat () {
+ @Override
+ public BufferFormat getBufferFormat () {
return bufferFormat;
}
- @Override public void setVSync (boolean vsync) {
+ @Override
+ public void setVSync (boolean vsync) {
this.vsync = vsync;
- if(vsync && !config.useCPUSynch) Display.setVSyncEnabled(true);
- if(!vsync && !config.useCPUSynch) Display.setVSyncEnabled(false);
+ if (vsync && !config.useCPUSynch) Display.setVSyncEnabled(true);
+ if (!vsync && !config.useCPUSynch) Display.setVSyncEnabled(false);
}
-
- @Override public boolean supportsExtension (String extension) {
- if(extensions == null) extensions = Gdx.gl.glGetString(GL10.GL_EXTENSIONS);
+
+ @Override
+ public boolean supportsExtension (String extension) {
+ if (extensions == null) extensions = Gdx.gl.glGetString(GL10.GL_EXTENSIONS);
return extensions.contains(extension);
}
}
diff --git a/backends/gdx-backend-lwjgl/src/com/badlogic/gdx/backends/lwjgl/LwjglInput.java b/backends/gdx-backend-lwjgl/src/com/badlogic/gdx/backends/lwjgl/LwjglInput.java
index 47dec0bef8a..c53b91c7d54 100644
--- a/backends/gdx-backend-lwjgl/src/com/badlogic/gdx/backends/lwjgl/LwjglInput.java
+++ b/backends/gdx-backend-lwjgl/src/com/badlogic/gdx/backends/lwjgl/LwjglInput.java
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
+
package com.badlogic.gdx.backends.lwjgl;
import java.util.ArrayList;
@@ -29,16 +30,11 @@
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Input;
import com.badlogic.gdx.InputProcessor;
-import com.badlogic.gdx.Input.Orientation;
-import com.badlogic.gdx.Input.Peripheral;
import com.badlogic.gdx.utils.Pool;
-/**
- * An implementation of the {@link Input} interface hooking a Jogl panel for input.
- *
- * @author mzechner
+/** An implementation of the {@link Input} interface hooking a Jogl panel for input.
*
- */
+ * @author mzechner */
final class LwjglInput implements Input {
class KeyEvent {
static final int KEY_DOWN = 0;
@@ -59,7 +55,7 @@ class TouchEvent {
int type;
int x;
- int y;
+ int y;
int scrollAmount;
int button;
int pointer;
@@ -82,7 +78,7 @@ protected TouchEvent newObject () {
boolean mousePressed = false;
int mouseX, mouseY;
int deltaX, deltaY;
- int pressedKeys = 0;
+ int pressedKeys = 0;
boolean justTouched = false;
Set pressedButtons = new HashSet();
InputProcessor processor;
@@ -110,7 +106,7 @@ public void getTextInput (final TextInputListener listener, final String title,
SwingUtilities.invokeLater(new Runnable() {
public void run () {
String output = JOptionPane.showInputDialog(null, title, text);
- if(output != null)
+ if (output != null)
listener.input(output);
else
listener.canceled();
@@ -167,11 +163,13 @@ public boolean supportsMultitouch () {
return false;
}
- @Override public void setOnscreenKeyboardVisible (boolean visible) {
+ @Override
+ public void setOnscreenKeyboardVisible (boolean visible) {
}
- @Override public void setCatchBackKey (boolean catchBack) {
+ @Override
+ public void setCatchBackKey (boolean catchBack) {
}
@@ -235,84 +233,162 @@ void processEvents () {
public static int getGdxKeyCode (int lwjglKeyCode) {
switch (lwjglKeyCode) {
- case Keyboard.KEY_0: return Input.Keys.NUM_0;
- case Keyboard.KEY_1: return Input.Keys.NUM_1;
- case Keyboard.KEY_2: return Input.Keys.NUM_2;
- case Keyboard.KEY_3: return Input.Keys.NUM_3;
- case Keyboard.KEY_4: return Input.Keys.NUM_4;
- case Keyboard.KEY_5: return Input.Keys.NUM_5;
- case Keyboard.KEY_6: return Input.Keys.NUM_6;
- case Keyboard.KEY_7: return Input.Keys.NUM_7;
- case Keyboard.KEY_8: return Input.Keys.NUM_8;
- case Keyboard.KEY_9: return Input.Keys.NUM_9;
- case Keyboard.KEY_A: return Input.Keys.A;
- case Keyboard.KEY_B: return Input.Keys.B;
- case Keyboard.KEY_C: return Input.Keys.C;
- case Keyboard.KEY_D: return Input.Keys.D;
- case Keyboard.KEY_E: return Input.Keys.E;
- case Keyboard.KEY_F: return Input.Keys.F;
- case Keyboard.KEY_G: return Input.Keys.G;
- case Keyboard.KEY_H: return Input.Keys.H;
- case Keyboard.KEY_I: return Input.Keys.I;
- case Keyboard.KEY_J: return Input.Keys.J;
- case Keyboard.KEY_K: return Input.Keys.K;
- case Keyboard.KEY_L: return Input.Keys.L;
- case Keyboard.KEY_M: return Input.Keys.M;
- case Keyboard.KEY_N: return Input.Keys.N;
- case Keyboard.KEY_O: return Input.Keys.O;
- case Keyboard.KEY_P: return Input.Keys.P;
- case Keyboard.KEY_Q: return Input.Keys.Q;
- case Keyboard.KEY_R: return Input.Keys.R;
- case Keyboard.KEY_S: return Input.Keys.S;
- case Keyboard.KEY_T: return Input.Keys.T;
- case Keyboard.KEY_U: return Input.Keys.U;
- case Keyboard.KEY_V: return Input.Keys.V;
- case Keyboard.KEY_W: return Input.Keys.W;
- case Keyboard.KEY_X: return Input.Keys.X;
- case Keyboard.KEY_Y: return Input.Keys.Y;
- case Keyboard.KEY_Z: return Input.Keys.Z;
- case Keyboard.KEY_LMENU: return Input.Keys.ALT_LEFT;
- case Keyboard.KEY_RMENU: return Input.Keys.ALT_RIGHT;
- case Keyboard.KEY_BACKSLASH: return Input.Keys.BACKSLASH;
- case Keyboard.KEY_COMMA: return Input.Keys.COMMA;
- case Keyboard.KEY_DELETE: return Input.Keys.FORWARD_DEL;
- case Keyboard.KEY_LEFT: return Input.Keys.DPAD_LEFT;
- case Keyboard.KEY_RIGHT: return Input.Keys.DPAD_RIGHT;
- case Keyboard.KEY_UP: return Input.Keys.DPAD_UP;
- case Keyboard.KEY_DOWN: return Input.Keys.DPAD_DOWN;
- case Keyboard.KEY_RETURN: return Input.Keys.ENTER;
- case Keyboard.KEY_HOME: return Input.Keys.HOME;
- case Keyboard.KEY_MINUS: return Input.Keys.MINUS;
- case Keyboard.KEY_PERIOD: return Input.Keys.PERIOD;
- case Keyboard.KEY_ADD: return Input.Keys.PLUS;
- case Keyboard.KEY_SEMICOLON: return Input.Keys.SEMICOLON;
- case Keyboard.KEY_LSHIFT: return Input.Keys.SHIFT_LEFT;
- case Keyboard.KEY_RSHIFT: return Input.Keys.SHIFT_RIGHT;
- case Keyboard.KEY_SLASH: return Input.Keys.SLASH;
- case Keyboard.KEY_SPACE: return Input.Keys.SPACE;
- case Keyboard.KEY_TAB: return Input.Keys.TAB;
- case Keyboard.KEY_LCONTROL: return Input.Keys.CONTROL_LEFT;
- case Keyboard.KEY_RCONTROL: return Input.Keys.CONTROL_RIGHT;
- case Keyboard.KEY_ESCAPE: return Input.Keys.ESCAPE;
- case Keyboard.KEY_END: return Input.Keys.END;
- case Keyboard.KEY_INSERT: return Input.Keys.INSERT;
- case Keyboard.KEY_NUMPAD5: return Input.Keys.DPAD_CENTER;
- case Keyboard.KEY_BACK: return Input.Keys.DEL;
- case Keyboard.KEY_SUBTRACT: return Input.Keys.MINUS;
- case Keyboard.KEY_APOSTROPHE: return Input.Keys.APOSTROPHE;
- case Keyboard.KEY_F1: return Input.Keys.F1;
- case Keyboard.KEY_F2: return Input.Keys.F2;
- case Keyboard.KEY_F3: return Input.Keys.F3;
- case Keyboard.KEY_F4: return Input.Keys.F4;
- case Keyboard.KEY_F5: return Input.Keys.F5;
- case Keyboard.KEY_F6: return Input.Keys.F6;
- case Keyboard.KEY_F7: return Input.Keys.F7;
- case Keyboard.KEY_F8: return Input.Keys.F8;
- case Keyboard.KEY_F9: return Input.Keys.F9;
- case Keyboard.KEY_F10: return Input.Keys.F10;
- case Keyboard.KEY_F11: return Input.Keys.F11;
- case Keyboard.KEY_F12: return Input.Keys.F12;
- case Keyboard.KEY_COLON: return Input.Keys.COLON;
+ case Keyboard.KEY_0:
+ return Input.Keys.NUM_0;
+ case Keyboard.KEY_1:
+ return Input.Keys.NUM_1;
+ case Keyboard.KEY_2:
+ return Input.Keys.NUM_2;
+ case Keyboard.KEY_3:
+ return Input.Keys.NUM_3;
+ case Keyboard.KEY_4:
+ return Input.Keys.NUM_4;
+ case Keyboard.KEY_5:
+ return Input.Keys.NUM_5;
+ case Keyboard.KEY_6:
+ return Input.Keys.NUM_6;
+ case Keyboard.KEY_7:
+ return Input.Keys.NUM_7;
+ case Keyboard.KEY_8:
+ return Input.Keys.NUM_8;
+ case Keyboard.KEY_9:
+ return Input.Keys.NUM_9;
+ case Keyboard.KEY_A:
+ return Input.Keys.A;
+ case Keyboard.KEY_B:
+ return Input.Keys.B;
+ case Keyboard.KEY_C:
+ return Input.Keys.C;
+ case Keyboard.KEY_D:
+ return Input.Keys.D;
+ case Keyboard.KEY_E:
+ return Input.Keys.E;
+ case Keyboard.KEY_F:
+ return Input.Keys.F;
+ case Keyboard.KEY_G:
+ return Input.Keys.G;
+ case Keyboard.KEY_H:
+ return Input.Keys.H;
+ case Keyboard.KEY_I:
+ return Input.Keys.I;
+ case Keyboard.KEY_J:
+ return Input.Keys.J;
+ case Keyboard.KEY_K:
+ return Input.Keys.K;
+ case Keyboard.KEY_L:
+ return Input.Keys.L;
+ case Keyboard.KEY_M:
+ return Input.Keys.M;
+ case Keyboard.KEY_N:
+ return Input.Keys.N;
+ case Keyboard.KEY_O:
+ return Input.Keys.O;
+ case Keyboard.KEY_P:
+ return Input.Keys.P;
+ case Keyboard.KEY_Q:
+ return Input.Keys.Q;
+ case Keyboard.KEY_R:
+ return Input.Keys.R;
+ case Keyboard.KEY_S:
+ return Input.Keys.S;
+ case Keyboard.KEY_T:
+ return Input.Keys.T;
+ case Keyboard.KEY_U:
+ return Input.Keys.U;
+ case Keyboard.KEY_V:
+ return Input.Keys.V;
+ case Keyboard.KEY_W:
+ return Input.Keys.W;
+ case Keyboard.KEY_X:
+ return Input.Keys.X;
+ case Keyboard.KEY_Y:
+ return Input.Keys.Y;
+ case Keyboard.KEY_Z:
+ return Input.Keys.Z;
+ case Keyboard.KEY_LMENU:
+ return Input.Keys.ALT_LEFT;
+ case Keyboard.KEY_RMENU:
+ return Input.Keys.ALT_RIGHT;
+ case Keyboard.KEY_BACKSLASH:
+ return Input.Keys.BACKSLASH;
+ case Keyboard.KEY_COMMA:
+ return Input.Keys.COMMA;
+ case Keyboard.KEY_DELETE:
+ return Input.Keys.FORWARD_DEL;
+ case Keyboard.KEY_LEFT:
+ return Input.Keys.DPAD_LEFT;
+ case Keyboard.KEY_RIGHT:
+ return Input.Keys.DPAD_RIGHT;
+ case Keyboard.KEY_UP:
+ return Input.Keys.DPAD_UP;
+ case Keyboard.KEY_DOWN:
+ return Input.Keys.DPAD_DOWN;
+ case Keyboard.KEY_RETURN:
+ return Input.Keys.ENTER;
+ case Keyboard.KEY_HOME:
+ return Input.Keys.HOME;
+ case Keyboard.KEY_MINUS:
+ return Input.Keys.MINUS;
+ case Keyboard.KEY_PERIOD:
+ return Input.Keys.PERIOD;
+ case Keyboard.KEY_ADD:
+ return Input.Keys.PLUS;
+ case Keyboard.KEY_SEMICOLON:
+ return Input.Keys.SEMICOLON;
+ case Keyboard.KEY_LSHIFT:
+ return Input.Keys.SHIFT_LEFT;
+ case Keyboard.KEY_RSHIFT:
+ return Input.Keys.SHIFT_RIGHT;
+ case Keyboard.KEY_SLASH:
+ return Input.Keys.SLASH;
+ case Keyboard.KEY_SPACE:
+ return Input.Keys.SPACE;
+ case Keyboard.KEY_TAB:
+ return Input.Keys.TAB;
+ case Keyboard.KEY_LCONTROL:
+ return Input.Keys.CONTROL_LEFT;
+ case Keyboard.KEY_RCONTROL:
+ return Input.Keys.CONTROL_RIGHT;
+ case Keyboard.KEY_ESCAPE:
+ return Input.Keys.ESCAPE;
+ case Keyboard.KEY_END:
+ return Input.Keys.END;
+ case Keyboard.KEY_INSERT:
+ return Input.Keys.INSERT;
+ case Keyboard.KEY_NUMPAD5:
+ return Input.Keys.DPAD_CENTER;
+ case Keyboard.KEY_BACK:
+ return Input.Keys.DEL;
+ case Keyboard.KEY_SUBTRACT:
+ return Input.Keys.MINUS;
+ case Keyboard.KEY_APOSTROPHE:
+ return Input.Keys.APOSTROPHE;
+ case Keyboard.KEY_F1:
+ return Input.Keys.F1;
+ case Keyboard.KEY_F2:
+ return Input.Keys.F2;
+ case Keyboard.KEY_F3:
+ return Input.Keys.F3;
+ case Keyboard.KEY_F4:
+ return Input.Keys.F4;
+ case Keyboard.KEY_F5:
+ return Input.Keys.F5;
+ case Keyboard.KEY_F6:
+ return Input.Keys.F6;
+ case Keyboard.KEY_F7:
+ return Input.Keys.F7;
+ case Keyboard.KEY_F8:
+ return Input.Keys.F8;
+ case Keyboard.KEY_F9:
+ return Input.Keys.F9;
+ case Keyboard.KEY_F10:
+ return Input.Keys.F10;
+ case Keyboard.KEY_F11:
+ return Input.Keys.F11;
+ case Keyboard.KEY_F12:
+ return Input.Keys.F12;
+ case Keyboard.KEY_COLON:
+ return Input.Keys.COLON;
default:
return Input.Keys.UNKNOWN;
}
@@ -440,19 +516,32 @@ public static int getLwjglKeyCode (int gdxKeyCode) {
return Keyboard.KEY_RCONTROL;
case Input.Keys.ESCAPE:
return Keyboard.KEY_ESCAPE;
- case Input.Keys.F1: return Keyboard.KEY_F1;
- case Input.Keys.F2: return Keyboard.KEY_F2;
- case Input.Keys.F3: return Keyboard.KEY_F3;
- case Input.Keys.F4: return Keyboard.KEY_F4;
- case Input.Keys.F5: return Keyboard.KEY_F5;
- case Input.Keys.F6: return Keyboard.KEY_F6;
- case Input.Keys.F7: return Keyboard.KEY_F7;
- case Input.Keys.F8: return Keyboard.KEY_F8;
- case Input.Keys.F9: return Keyboard.KEY_F9;
- case Input.Keys.F10: return Keyboard.KEY_F10;
- case Input.Keys.F11: return Keyboard.KEY_F11;
- case Input.Keys.F12: return Keyboard.KEY_F12;
- case Input.Keys.COLON: return Keyboard.KEY_COLON;
+ case Input.Keys.F1:
+ return Keyboard.KEY_F1;
+ case Input.Keys.F2:
+ return Keyboard.KEY_F2;
+ case Input.Keys.F3:
+ return Keyboard.KEY_F3;
+ case Input.Keys.F4:
+ return Keyboard.KEY_F4;
+ case Input.Keys.F5:
+ return Keyboard.KEY_F5;
+ case Input.Keys.F6:
+ return Keyboard.KEY_F6;
+ case Input.Keys.F7:
+ return Keyboard.KEY_F7;
+ case Input.Keys.F8:
+ return Keyboard.KEY_F8;
+ case Input.Keys.F9:
+ return Keyboard.KEY_F9;
+ case Input.Keys.F10:
+ return Keyboard.KEY_F10;
+ case Input.Keys.F11:
+ return Keyboard.KEY_F11;
+ case Input.Keys.F12:
+ return Keyboard.KEY_F12;
+ case Input.Keys.COLON:
+ return Keyboard.KEY_COLON;
default:
return Keyboard.KEY_NONE;
}
@@ -463,17 +552,14 @@ public void update () {
updateKeyboard();
}
- private int toGdxButton(int button) {
- if(button == 0)
- return Buttons.LEFT;
- if(button == 1)
- return Buttons.RIGHT;
- if(button == 2)
- return Buttons.MIDDLE;
+ private int toGdxButton (int button) {
+ if (button == 0) return Buttons.LEFT;
+ if (button == 1) return Buttons.RIGHT;
+ if (button == 2) return Buttons.MIDDLE;
return Buttons.LEFT;
-
+
}
-
+
void updateMouse () {
justTouched = false;
if (Mouse.isCreated()) {
@@ -483,26 +569,26 @@ void updateMouse () {
int x = Mouse.getEventX();
int y = Gdx.graphics.getHeight() - Mouse.getEventY() - 1;
int button = Mouse.getEventButton();
-
+
TouchEvent event = usedTouchEvents.obtain();
event.x = x;
event.y = y;
event.button = toGdxButton(button);
event.pointer = 0;
-
+
// could be drag, scroll or move
- if(button == -1) {
- if(Mouse.getEventDWheel() != 0) {
+ if (button == -1) {
+ if (Mouse.getEventDWheel() != 0) {
event.type = TouchEvent.TOUCH_SCROLLED;
event.scrollAmount = (int)-Math.signum(Mouse.getEventDWheel());
- } else if(pressedButtons .size() > 0) {
- event.type = TouchEvent.TOUCH_DRAGGED;
+ } else if (pressedButtons.size() > 0) {
+ event.type = TouchEvent.TOUCH_DRAGGED;
} else {
event.type = TouchEvent.TOUCH_MOVED;
}
} else {
// nope, it's a down or up event.
- if(Mouse.getEventButtonState()) {
+ if (Mouse.getEventButtonState()) {
event.type = TouchEvent.TOUCH_DOWN;
pressedButtons.add(event.button);
justTouched = true;
@@ -511,15 +597,15 @@ void updateMouse () {
pressedButtons.remove(event.button);
}
}
-
+
touchEvents.add(event);
mouseX = event.x;
mouseY = event.y;
deltaX = Mouse.getEventDX();
deltaY = Mouse.getEventDY();
}
-
- if(events == 0) {
+
+ if (events == 0) {
deltaX = 0;
deltaY = 0;
}
@@ -551,7 +637,7 @@ void updateKeyboard () {
event.keyChar = 0;
event.type = KeyEvent.KEY_DOWN;
keyEvents.add(event);
-
+
event = usedKeyEvents.obtain();
event.keyCode = 0;
event.keyChar = keyChar;
@@ -577,99 +663,120 @@ void updateKeyboard () {
}
}
- @Override public void setInputProcessor (InputProcessor processor) {
+ @Override
+ public void setInputProcessor (InputProcessor processor) {
this.processor = processor;
}
-
- @Override public InputProcessor getInputProcessor() {
+
+ @Override
+ public InputProcessor getInputProcessor () {
return this.processor;
}
- @Override public void vibrate (int milliseconds) {
+ @Override
+ public void vibrate (int milliseconds) {
}
- @Override public boolean justTouched () {
+ @Override
+ public boolean justTouched () {
return justTouched;
}
-
- private int toLwjglButton(int button) {
- if(button == Buttons.LEFT)
- return 0;
- if(button == Buttons.RIGHT)
- return 1;
- if(button == Buttons.MIDDLE)
- return 2;
+
+ private int toLwjglButton (int button) {
+ if (button == Buttons.LEFT) return 0;
+ if (button == Buttons.RIGHT) return 1;
+ if (button == Buttons.MIDDLE) return 2;
return 0;
}
- @Override public boolean isButtonPressed (int button) {
+ @Override
+ public boolean isButtonPressed (int button) {
return Mouse.isButtonDown(toLwjglButton(button));
}
- @Override public void vibrate (long[] pattern, int repeat) {
+ @Override
+ public void vibrate (long[] pattern, int repeat) {
}
- @Override public void cancelVibrate () {
+ @Override
+ public void cancelVibrate () {
}
- @Override public float getAzimuth () {
+ @Override
+ public float getAzimuth () {
return 0;
}
- @Override public float getPitch () {
+ @Override
+ public float getPitch () {
return 0;
}
- @Override public float getRoll () {
+ @Override
+ public float getRoll () {
return 0;
}
-
- @Override public boolean isPeripheralAvailable (Peripheral peripheral) {
- if(peripheral == Peripheral.HardwareKeyboard) return true;
+
+ @Override
+ public boolean isPeripheralAvailable (Peripheral peripheral) {
+ if (peripheral == Peripheral.HardwareKeyboard) return true;
return false;
}
- @Override public int getRotation () {
+ @Override
+ public int getRotation () {
return 0;
}
- @Override public Orientation getNativeOrientation () {
+ @Override
+ public Orientation getNativeOrientation () {
return Orientation.Landscape;
}
- @Override public void setCursorCatched (boolean catched) {
+ @Override
+ public void setCursorCatched (boolean catched) {
Mouse.setGrabbed(catched);
}
- @Override public boolean isCursorCatched () {
+ @Override
+ public boolean isCursorCatched () {
return Mouse.isGrabbed();
}
- @Override public int getDeltaX () {
+ @Override
+ public int getDeltaX () {
return deltaX;
}
- @Override public int getDeltaX (int pointer) {
- if(pointer == 0) return deltaX;
- else return 0;
+ @Override
+ public int getDeltaX (int pointer) {
+ if (pointer == 0)
+ return deltaX;
+ else
+ return 0;
}
- @Override public int getDeltaY () {
+ @Override
+ public int getDeltaY () {
return deltaY;
}
- @Override public int getDeltaY (int pointer) {
- if(pointer == 0) return deltaY;
- else return 0;
+ @Override
+ public int getDeltaY (int pointer) {
+ if (pointer == 0)
+ return deltaY;
+ else
+ return 0;
}
- @Override public void setCursorPosition (int x, int y) {
+ @Override
+ public void setCursorPosition (int x, int y) {
Mouse.setCursorPosition(x, y);
}
@Override
- public void setCatchMenuKey(boolean catchMenu) {
+ public void setCatchMenuKey (boolean catchMenu) {
// TODO Auto-generated method stub
-
+
}
}
diff --git a/backends/gdx-backend-lwjgl/src/com/badlogic/gdx/backends/lwjgl/LwjglNativesLoader.java b/backends/gdx-backend-lwjgl/src/com/badlogic/gdx/backends/lwjgl/LwjglNativesLoader.java
index 17e8d3fb4f3..45a6b7d4518 100644
--- a/backends/gdx-backend-lwjgl/src/com/badlogic/gdx/backends/lwjgl/LwjglNativesLoader.java
+++ b/backends/gdx-backend-lwjgl/src/com/badlogic/gdx/backends/lwjgl/LwjglNativesLoader.java
@@ -13,15 +13,11 @@
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
+
package com.badlogic.gdx.backends.lwjgl;
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
import java.lang.reflect.Method;
-import com.badlogic.gdx.Version;
import com.badlogic.gdx.utils.GdxNativesLoader;
import static com.badlogic.gdx.utils.GdxNativesLoader.*;
@@ -43,7 +39,7 @@ final class LwjglNativesLoader {
static void load () {
GdxNativesLoader.load();
- if(GdxNativesLoader.disableNativesLoading) return;
+ if (GdxNativesLoader.disableNativesLoading) return;
if (!load) return;
if (isWindows) {
extractLibrary("OpenAL32.dll", "OpenAL64.dll");
diff --git a/backends/gdx-backend-lwjgl/src/com/badlogic/gdx/backends/lwjgl/LwjglPreferences.java b/backends/gdx-backend-lwjgl/src/com/badlogic/gdx/backends/lwjgl/LwjglPreferences.java
index 41e556c51ad..84d7e20ef66 100644
--- a/backends/gdx-backend-lwjgl/src/com/badlogic/gdx/backends/lwjgl/LwjglPreferences.java
+++ b/backends/gdx-backend-lwjgl/src/com/badlogic/gdx/backends/lwjgl/LwjglPreferences.java
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
+
package com.badlogic.gdx.backends.lwjgl;
import java.io.BufferedInputStream;
@@ -31,133 +32,151 @@ public class LwjglPreferences implements Preferences {
private final String name;
private final Properties properties = new Properties();
- LwjglPreferences(String name) {
+ LwjglPreferences (String name) {
this.name = name;
InputStream in = null;
try {
in = new BufferedInputStream(Gdx.files.external(name).read());
properties.loadFromXML(in);
- } catch(Throwable t) {
+ } catch (Throwable t) {
} finally {
- if(in != null) try { in.close(); } catch(Exception e) { }
+ if (in != null) try {
+ in.close();
+ } catch (Exception e) {
+ }
}
-
+
Runtime.getRuntime().addShutdownHook(new Thread() {
- @Override public void run() {
+ @Override
+ public void run () {
flush();
}
});
- }
-
- @Override public void putBoolean (String key, boolean val) {
+ }
+
+ @Override
+ public void putBoolean (String key, boolean val) {
properties.put(key, Boolean.toString(val));
}
- @Override public void putInteger (String key, int val) {
+ @Override
+ public void putInteger (String key, int val) {
properties.put(key, Integer.toString(val));
}
- @Override public void putLong (String key, long val) {
+ @Override
+ public void putLong (String key, long val) {
properties.put(key, Long.toString(val));
}
- @Override public void putFloat (String key, float val) {
+ @Override
+ public void putFloat (String key, float val) {
properties.put(key, Float.toString(val));
}
- @Override public void putString (String key, String val) {
+ @Override
+ public void putString (String key, String val) {
properties.put(key, val);
}
- @Override public void put (Map vals) {
- for(Entry val: vals.entrySet()) {
- if(val.getValue() instanceof Boolean)
- putBoolean(val.getKey(), (Boolean)val.getValue());
- if(val.getValue() instanceof Integer)
- putInteger(val.getKey(), (Integer)val.getValue());
- if(val.getValue() instanceof Long)
- putLong(val.getKey(), (Long)val.getValue());
- if(val.getValue() instanceof String)
- putString(val.getKey(), (String)val.getValue());
- if(val.getValue() instanceof Float)
- putFloat(val.getKey(), (Float)val.getValue());
+ @Override
+ public void put (Map vals) {
+ for (Entry val : vals.entrySet()) {
+ if (val.getValue() instanceof Boolean) putBoolean(val.getKey(), (Boolean)val.getValue());
+ if (val.getValue() instanceof Integer) putInteger(val.getKey(), (Integer)val.getValue());
+ if (val.getValue() instanceof Long) putLong(val.getKey(), (Long)val.getValue());
+ if (val.getValue() instanceof String) putString(val.getKey(), (String)val.getValue());
+ if (val.getValue() instanceof Float) putFloat(val.getKey(), (Float)val.getValue());
}
}
- @Override public boolean getBoolean (String key) {
+ @Override
+ public boolean getBoolean (String key) {
return getBoolean(key, false);
}
- @Override public int getInteger (String key) {
+ @Override
+ public int getInteger (String key) {
return getInteger(key, 0);
}
- @Override public long getLong (String key) {
+ @Override
+ public long getLong (String key) {
return getLong(key, 0);
}
- @Override public float getFloat (String key) {
+ @Override
+ public float getFloat (String key) {
return getFloat(key, 0);
}
- @Override public String getString (String key) {
+ @Override
+ public String getString (String key) {
return getString(key, "");
}
- @Override public boolean getBoolean (String key, boolean defValue) {
+ @Override
+ public boolean getBoolean (String key, boolean defValue) {
return Boolean.parseBoolean(properties.getProperty(key, Boolean.toString(defValue)));
}
- @Override public int getInteger (String key, int defValue) {
+ @Override
+ public int getInteger (String key, int defValue) {
return Integer.parseInt(properties.getProperty(key, Integer.toString(defValue)));
}
- @Override public long getLong (String key, long defValue) {
+ @Override
+ public long getLong (String key, long defValue) {
return Long.parseLong(properties.getProperty(key, Long.toString(defValue)));
}
- @Override public float getFloat (String key, float defValue) {
+ @Override
+ public float getFloat (String key, float defValue) {
return Float.parseFloat(properties.getProperty(key, Float.toString(defValue)));
}
- @Override public String getString (String key, String defValue) {
+ @Override
+ public String getString (String key, String defValue) {
return properties.getProperty(key, defValue);
}
- @Override public Map get () {
+ @Override
+ public Map get () {
Map map = new HashMap();
- for(Entry val: properties.entrySet()) {
- if(val.getValue() instanceof Boolean)
- map.put((String)val.getKey(), (Boolean)Boolean.parseBoolean((String)val.getValue()));
- if(val.getValue() instanceof Integer)
- map.put((String)val.getKey(), (Integer)Integer.parseInt((String)val.getValue()));
- if(val.getValue() instanceof Long)
- map.put((String)val.getKey(), (Long)Long.parseLong((String)val.getValue()));
- if(val.getValue() instanceof String)
- map.put((String)val.getKey(), (String)val.getValue());
- if(val.getValue() instanceof Float)
- map.put((String)val.getKey(), (Float)Float.parseFloat((String)val.getValue()));
+ for (Entry val : properties.entrySet()) {
+ if (val.getValue() instanceof Boolean)
+ map.put((String)val.getKey(), (Boolean)Boolean.parseBoolean((String)val.getValue()));
+ if (val.getValue() instanceof Integer) map.put((String)val.getKey(), (Integer)Integer.parseInt((String)val.getValue()));
+ if (val.getValue() instanceof Long) map.put((String)val.getKey(), (Long)Long.parseLong((String)val.getValue()));
+ if (val.getValue() instanceof String) map.put((String)val.getKey(), (String)val.getValue());
+ if (val.getValue() instanceof Float) map.put((String)val.getKey(), (Float)Float.parseFloat((String)val.getValue()));
}
-
+
return map;
}
- @Override public boolean contains (String key) {
+ @Override
+ public boolean contains (String key) {
return properties.containsKey(key);
}
- @Override public void clear () {
+ @Override
+ public void clear () {
properties.clear();
}
-
- @Override public void flush () {
+
+ @Override
+ public void flush () {
OutputStream out = null;
try {
out = new BufferedOutputStream(Gdx.files.external(LwjglPreferences.this.name).write(false));
properties.storeToXML(out, null);
- } catch(Throwable t) {
+ } catch (Throwable t) {
} finally {
- if(out != null) try { out.close(); } catch(Exception e) { }
+ if (out != null) try {
+ out.close();
+ } catch (Exception e) {
+ }
}
}
}
diff --git a/backends/gdx-backends-angle/src/com/badlogic/gdx/backends/angle/AngleApplication.java b/backends/gdx-backends-angle/src/com/badlogic/gdx/backends/angle/AngleApplication.java
index 78b15a0d8c1..63377c29fd0 100644
--- a/backends/gdx-backends-angle/src/com/badlogic/gdx/backends/angle/AngleApplication.java
+++ b/backends/gdx-backends-angle/src/com/badlogic/gdx/backends/angle/AngleApplication.java
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
+
package com.badlogic.gdx.backends.angle;
import java.util.ArrayList;
@@ -68,59 +69,71 @@ public void run () {
}).run();
}
- @Override public Graphics getGraphics () {
+ @Override
+ public Graphics getGraphics () {
return graphics;
}
- @Override public Audio getAudio () {
+ @Override
+ public Audio getAudio () {
return audio;
}
- @Override public Input getInput () {
+ @Override
+ public Input getInput () {
return input;
}
- @Override public Files getFiles () {
+ @Override
+ public Files getFiles () {
return files;
}
- @Override public ApplicationType getType () {
+ @Override
+ public ApplicationType getType () {
return ApplicationType.Desktop;
}
- @Override public int getVersion () {
+ @Override
+ public int getVersion () {
return 0;
}
- @Override public long getJavaHeap () {
+ @Override
+ public long getJavaHeap () {
return Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory();
}
- @Override public long getNativeHeap () {
+ @Override
+ public long getNativeHeap () {
return getJavaHeap();
}
- @Override public void onKey (int action, int key, int keyCode) {
+ @Override
+ public void onKey (int action, int key, int keyCode) {
input.registerKeyEvent(action, key, keyCode);
}
- @Override public void onMouse (int action, int x, int y, int button) {
+ @Override
+ public void onMouse (int action, int x, int y, int button) {
input.registerMouseEvent(action, x, y, button);
}
- @Override public void quit () {
+ @Override
+ public void quit () {
listener.pause();
listener.dispose();
}
- @Override public void render () {
+ @Override
+ public void render () {
graphics.updateTime();
if (!created) {
- listener.create();
+ listener.create();
created = true;
}
synchronized (runnables) {
- for(int i = 0; i < runnables.size(); i++) {
+ for (int i = 0; i < runnables.size(); i++) {
runnables.get(i).run();
}
runnables.clear();
@@ -130,15 +143,18 @@ public void run () {
input.justTouched = false;
}
- @Override public void resize (int width, int height) {
+ @Override
+ public void resize (int width, int height) {
graphics.width = width;
graphics.height = height;
if (!created) listener.resize(width, height);
}
Map preferences = new HashMap();
- @Override public Preferences getPreferences (String name) {
- if(preferences.containsKey(name)) {
+
+ @Override
+ public Preferences getPreferences (String name) {
+ if (preferences.containsKey(name)) {
return preferences.get(name);
} else {
Preferences prefs = new AnglePreferences(name);
@@ -147,52 +163,57 @@ public void run () {
}
}
- @Override public void postRunnable (Runnable runnable) {
- synchronized(runnables) {
+ @Override
+ public void postRunnable (Runnable runnable) {
+ synchronized (runnables) {
runnables.add(runnable);
- }
+ }
}
-
- @Override
- public void log(String tag, String message) {
- if(logLevel >= LOG_INFO) {
- System.out.println(tag + ":" + message);
+
+ @Override
+ public void log (String tag, String message) {
+ if (logLevel >= LOG_INFO) {
+ System.out.println(tag + ":" + message);
}
- }
+ }
- @Override public void log (String tag, String message, Exception exception) {
- if(logLevel >= LOG_INFO) {
+ @Override
+ public void log (String tag, String message, Exception exception) {
+ if (logLevel >= LOG_INFO) {
System.out.println(tag + ":" + message);
exception.printStackTrace(System.out);
}
}
-
- @Override public void error (String tag, String message) {
- if(logLevel >= LOG_ERROR) {
- System.err.println(tag + ":" + message);
+
+ @Override
+ public void error (String tag, String message) {
+ if (logLevel >= LOG_ERROR) {
+ System.err.println(tag + ":" + message);
}
}
-
- @Override public void error (String tag, String message, Exception exception) {
- if(logLevel >= LOG_ERROR) {
+ @Override
+ public void error (String tag, String message, Exception exception) {
+ if (logLevel >= LOG_ERROR) {
System.err.println(tag + ":" + message);
exception.printStackTrace(System.err);
}
}
-
- @Override public void setLogLevel (int logLevel) {
+ @Override
+ public void setLogLevel (int logLevel) {
this.logLevel = logLevel;
}
- @Override public void exit () {
+ @Override
+ public void exit () {
postRunnable(new Runnable() {
- @Override public void run () {
+ @Override
+ public void run () {
AngleApplication.this.listener.pause();
AngleApplication.this.listener.dispose();
System.exit(-1);
- }
+ }
});
}
}
diff --git a/backends/gdx-backends-angle/src/com/badlogic/gdx/backends/angle/AngleAudio.java b/backends/gdx-backends-angle/src/com/badlogic/gdx/backends/angle/AngleAudio.java
index 9fa517f114a..f8b5a6146a4 100644
--- a/backends/gdx-backends-angle/src/com/badlogic/gdx/backends/angle/AngleAudio.java
+++ b/backends/gdx-backends-angle/src/com/badlogic/gdx/backends/angle/AngleAudio.java
@@ -44,12 +44,9 @@
import com.badlogic.gdx.files.FileHandle;
import com.badlogic.gdx.utils.GdxRuntimeException;
-/**
- * An implementation of the {@link Audio} interface for the desktop.
+/** An implementation of the {@link Audio} interface for the desktop.
*
- * @author mzechner
- *
- */
+ * @author mzechner */
final class AngleAudio implements Audio, Runnable {
/** the audio line for sound effects **/
private SourceDataLine line;
@@ -62,12 +59,9 @@ final class AngleAudio implements Audio, Runnable {
private volatile boolean run = false;
- /**
- * Helper class for playing back sound effects concurrently.
- *
- * @author mzechner
+ /** Helper class for playing back sound effects concurrently.
*
- */
+ * @author mzechner */
class AngleSoundBuffer {
private final float[] samples;
private final AudioFormat format;
@@ -80,10 +74,8 @@ public AngleSoundBuffer (AngleSound sound, float volume) throws Exception {
this.volume = volume;
}
- /**
- * Writes the next numFrames frames to the line for playback
- * @return whether playback is done or not.
- */
+ /** Writes the next numFrames frames to the line for playback
+ * @return whether playback is done or not. */
public boolean writeSamples (int numSamples, float[] buffer) {
if (format.getChannels() == 1) {
int remainingSamples = Math.min(samples.length, writtenSamples + numSamples / 2);
diff --git a/backends/gdx-backends-angle/src/com/badlogic/gdx/backends/angle/AngleAudioDevice.java b/backends/gdx-backends-angle/src/com/badlogic/gdx/backends/angle/AngleAudioDevice.java
index d0192747c32..beac2faea43 100644
--- a/backends/gdx-backends-angle/src/com/badlogic/gdx/backends/angle/AngleAudioDevice.java
+++ b/backends/gdx-backends-angle/src/com/badlogic/gdx/backends/angle/AngleAudioDevice.java
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
+
package com.badlogic.gdx.backends.angle;
import javax.sound.sampled.AudioFormat;
@@ -22,12 +23,9 @@
import com.badlogic.gdx.audio.AudioDevice;
import com.badlogic.gdx.utils.GdxRuntimeException;
-/**
- * Implementation of the {@link AudioDevice} interface for the desktop using Java Sound.
- *
- * @author mzechner
+/** Implementation of the {@link AudioDevice} interface for the desktop using Java Sound.
*
- */
+ * @author mzechner */
final class AngleAudioDevice implements AudioDevice {
/** the audio line **/
private SourceDataLine line;
@@ -91,7 +89,8 @@ public void writeSamples (float[] samples, int offset, int numSamples) {
writtenBytes += line.write(bytes, writtenBytes, numSamples * 2 - writtenBytes);
}
- @Override public int getLatency () {
+ @Override
+ public int getLatency () {
return 0;
}
}
diff --git a/backends/gdx-backends-angle/src/com/badlogic/gdx/backends/angle/AngleAudioRecorder.java b/backends/gdx-backends-angle/src/com/badlogic/gdx/backends/angle/AngleAudioRecorder.java
index 9f5270de441..c056ebc0857 100644
--- a/backends/gdx-backends-angle/src/com/badlogic/gdx/backends/angle/AngleAudioRecorder.java
+++ b/backends/gdx-backends-angle/src/com/badlogic/gdx/backends/angle/AngleAudioRecorder.java
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
+
package com.badlogic.gdx.backends.angle;
import javax.sound.sampled.AudioFormat;
@@ -23,12 +24,9 @@
import com.badlogic.gdx.audio.AudioRecorder;
import com.badlogic.gdx.utils.GdxRuntimeException;
-/**
- * {@link AudioRecorder} implementation for the desktop using the java sound API.
- *
- * @author badlogicgames@gmail.com
+/** {@link AudioRecorder} implementation for the desktop using the java sound API.
*
- */
+ * @author badlogicgames@gmail.com */
final class AngleAudioRecorder implements AudioRecorder {
/** the line we read the audio from **/
private TargetDataLine line;
diff --git a/backends/gdx-backends-angle/src/com/badlogic/gdx/backends/angle/AngleFileHandle.java b/backends/gdx-backends-angle/src/com/badlogic/gdx/backends/angle/AngleFileHandle.java
index d36176cd29d..630099719ac 100644
--- a/backends/gdx-backends-angle/src/com/badlogic/gdx/backends/angle/AngleFileHandle.java
+++ b/backends/gdx-backends-angle/src/com/badlogic/gdx/backends/angle/AngleFileHandle.java
@@ -34,10 +34,8 @@
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.files.FileHandle;
-/**
- * @author mzechner
- * @author Nathan Sweet
- */
+/** @author mzechner
+ * @author Nathan Sweet */
final class AngleFileHandle extends FileHandle {
AngleFileHandle (String fileName, FileType type) {
super(fileName, type);
diff --git a/backends/gdx-backends-angle/src/com/badlogic/gdx/backends/angle/AngleFiles.java b/backends/gdx-backends-angle/src/com/badlogic/gdx/backends/angle/AngleFiles.java
index ae37f6a2aa4..1fbb35a82e5 100644
--- a/backends/gdx-backends-angle/src/com/badlogic/gdx/backends/angle/AngleFiles.java
+++ b/backends/gdx-backends-angle/src/com/badlogic/gdx/backends/angle/AngleFiles.java
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
+
package com.badlogic.gdx.backends.angle;
import com.badlogic.gdx.Files;
@@ -21,31 +22,38 @@
public class AngleFiles implements Files {
private final String externalPath = System.getProperty("user.home") + "/";
- @Override public FileHandle getFileHandle (String fileName, FileType type) {
+ @Override
+ public FileHandle getFileHandle (String fileName, FileType type) {
return new AngleFileHandle(fileName, type);
}
- @Override public FileHandle classpath (String path) {
+ @Override
+ public FileHandle classpath (String path) {
return new AngleFileHandle(path, FileType.Classpath);
}
- @Override public FileHandle internal (String path) {
+ @Override
+ public FileHandle internal (String path) {
return new AngleFileHandle(path, FileType.Internal);
}
- @Override public FileHandle external (String path) {
+ @Override
+ public FileHandle external (String path) {
return new AngleFileHandle(path, FileType.External);
}
- @Override public FileHandle absolute (String path) {
+ @Override
+ public FileHandle absolute (String path) {
return new AngleFileHandle(path, FileType.Absolute);
}
- @Override public String getExternalStoragePath () {
+ @Override
+ public String getExternalStoragePath () {
return externalPath;
}
- @Override public boolean isExternalStorageAvailable () {
+ @Override
+ public boolean isExternalStorageAvailable () {
return true;
}
}
diff --git a/backends/gdx-backends-angle/src/com/badlogic/gdx/backends/angle/AngleGLES0.java b/backends/gdx-backends-angle/src/com/badlogic/gdx/backends/angle/AngleGLES0.java
index 50464a0c536..6ffb7ceb01a 100644
--- a/backends/gdx-backends-angle/src/com/badlogic/gdx/backends/angle/AngleGLES0.java
+++ b/backends/gdx-backends-angle/src/com/badlogic/gdx/backends/angle/AngleGLES0.java
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
+
package com.badlogic.gdx.backends.angle;
import java.nio.Buffer;
diff --git a/backends/gdx-backends-angle/src/com/badlogic/gdx/backends/angle/AngleGLU.java b/backends/gdx-backends-angle/src/com/badlogic/gdx/backends/angle/AngleGLU.java
index 51ca6016a74..ecd7936f0cf 100644
--- a/backends/gdx-backends-angle/src/com/badlogic/gdx/backends/angle/AngleGLU.java
+++ b/backends/gdx-backends-angle/src/com/badlogic/gdx/backends/angle/AngleGLU.java
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
+
package com.badlogic.gdx.backends.angle;
import java.nio.FloatBuffer;
@@ -22,58 +23,69 @@
import com.badlogic.gdx.graphics.GLU;
import com.badlogic.gdx.utils.BufferUtils;
-public class AngleGLU implements GLU{
-
+public class AngleGLU implements GLU {
+
FloatBuffer modelb;
FloatBuffer projectb;
IntBuffer viewb;
FloatBuffer winb;
-
- public AngleGLU() {
+
+ public AngleGLU () {
modelb = BufferUtils.newFloatBuffer(16);
projectb = BufferUtils.newFloatBuffer(16);
viewb = BufferUtils.newIntBuffer(4);
winb = BufferUtils.newFloatBuffer(3);
}
- @Override public void gluLookAt (GL10 gl, float eyeX, float eyeY, float eyeZ, float centerX, float centerY, float centerZ,
- float upX, float upY, float upZ) {
+ @Override
+ public void gluLookAt (GL10 gl, float eyeX, float eyeY, float eyeZ, float centerX, float centerY, float centerZ, float upX,
+ float upY, float upZ) {
throw new UnsupportedOperationException();
}
- @Override public void gluOrtho2D (GL10 gl, float left, float right, float bottom, float top) {
+ @Override
+ public void gluOrtho2D (GL10 gl, float left, float right, float bottom, float top) {
throw new UnsupportedOperationException();
}
- @Override public void gluPerspective (GL10 gl, float fovy, float aspect, float zNear, float zFar) {
+ @Override
+ public void gluPerspective (GL10 gl, float fovy, float aspect, float zNear, float zFar) {
throw new UnsupportedOperationException();
}
- @Override public boolean gluProject (float objX, float objY, float objZ, float[] model, int modelOffset, float[] project,
+ @Override
+ public boolean gluProject (float objX, float objY, float objZ, float[] model, int modelOffset, float[] project,
int projectOffset, int[] view, int viewOffset, float[] win, int winOffset) {
- modelb.clear(); modelb.put(model, modelOffset, 16);
- projectb.clear(); projectb.put(project, projectOffset, 16);
- viewb.clear(); viewb.put(view, viewOffset, 4);
+ modelb.clear();
+ modelb.put(model, modelOffset, 16);
+ projectb.clear();
+ projectb.put(project, projectOffset, 16);
+ viewb.clear();
+ viewb.put(view, viewOffset, 4);
winb.clear();
-
+
boolean result = org.lwjgl.util.glu.GLU.gluProject(objX, objY, objZ, modelb, projectb, viewb, winb);
win[winOffset] = winb.get(0);
- win[winOffset+1] = winb.get(1);
- win[winOffset+2] = winb.get(2);
+ win[winOffset + 1] = winb.get(1);
+ win[winOffset + 2] = winb.get(2);
return result;
}
- @Override public boolean gluUnProject (float winX, float winY, float winZ, float[] model, int modelOffset, float[] project,
+ @Override
+ public boolean gluUnProject (float winX, float winY, float winZ, float[] model, int modelOffset, float[] project,
int projectOffset, int[] view, int viewOffset, float[] obj, int objOffset) {
- modelb.clear(); modelb.put(model, modelOffset, 16);
- projectb.clear(); projectb.put(project, projectOffset, 16);
- viewb.clear(); viewb.put(view, viewOffset, 4);
+ modelb.clear();
+ modelb.put(model, modelOffset, 16);
+ projectb.clear();
+ projectb.put(project, projectOffset, 16);
+ viewb.clear();
+ viewb.put(view, viewOffset, 4);
winb.clear();
-
+
boolean result = org.lwjgl.util.glu.GLU.gluUnProject(winX, winY, winZ, modelb, projectb, viewb, winb);
obj[objOffset] = winb.get(0);
- obj[objOffset+1] = winb.get(1);
- obj[objOffset+2] = winb.get(2);
+ obj[objOffset + 1] = winb.get(1);
+ obj[objOffset + 2] = winb.get(2);
return result;
}
}
diff --git a/backends/gdx-backends-angle/src/com/badlogic/gdx/backends/angle/AngleGraphics.java b/backends/gdx-backends-angle/src/com/badlogic/gdx/backends/angle/AngleGraphics.java
index c64120bf96e..5f3189268a5 100644
--- a/backends/gdx-backends-angle/src/com/badlogic/gdx/backends/angle/AngleGraphics.java
+++ b/backends/gdx-backends-angle/src/com/badlogic/gdx/backends/angle/AngleGraphics.java
@@ -13,13 +13,13 @@
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
+
package com.badlogic.gdx.backends.angle;
import java.awt.Toolkit;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Graphics;
-import com.badlogic.gdx.Graphics.DisplayMode;
import com.badlogic.gdx.graphics.GL10;
import com.badlogic.gdx.graphics.GL11;
import com.badlogic.gdx.graphics.GL20;
@@ -44,67 +44,83 @@ public class AngleGraphics implements Graphics {
glu = new AngleGLU();
}
- @Override public boolean isGL11Available () {
+ @Override
+ public boolean isGL11Available () {
return false;
}
- @Override public boolean isGL20Available () {
+ @Override
+ public boolean isGL20Available () {
return true;
}
- @Override public GLCommon getGLCommon () {
+ @Override
+ public GLCommon getGLCommon () {
return gl;
}
- @Override public GL10 getGL10 () {
+ @Override
+ public GL10 getGL10 () {
return null;
}
- @Override public GL11 getGL11 () {
+ @Override
+ public GL11 getGL11 () {
return null;
}
- @Override public GL20 getGL20 () {
+ @Override
+ public GL20 getGL20 () {
return gl;
}
-
- @Override public GLU getGLU() {
+
+ @Override
+ public GLU getGLU () {
return glu;
}
- @Override public int getWidth () {
+ @Override
+ public int getWidth () {
return width;
}
- @Override public int getHeight () {
+ @Override
+ public int getHeight () {
return height;
}
- @Override public float getDeltaTime () {
+ @Override
+ public float getDeltaTime () {
return deltaTime;
}
- @Override public int getFramesPerSecond () {
+ @Override
+ public int getFramesPerSecond () {
return fps;
}
- @Override public GraphicsType getType () {
+ @Override
+ public GraphicsType getType () {
return GraphicsType.Angle;
}
- @Override public float getPpiX () {
+ @Override
+ public float getPpiX () {
return Toolkit.getDefaultToolkit().getScreenResolution();
}
- @Override public float getPpiY () {
+ @Override
+ public float getPpiY () {
return Toolkit.getDefaultToolkit().getScreenResolution();
}
- @Override public float getPpcX () {
+ @Override
+ public float getPpcX () {
return (Toolkit.getDefaultToolkit().getScreenResolution() / 2.54f);
}
- @Override public float getPpcY () {
+ @Override
+ public float getPpcY () {
return (Toolkit.getDefaultToolkit().getScreenResolution() / 2.54f);
}
@@ -121,50 +137,60 @@ void updateTime () {
frames++;
}
- @Override public boolean supportsDisplayModeChange () {
+ @Override
+ public boolean supportsDisplayModeChange () {
return false;
}
- @Override public boolean setDisplayMode (DisplayMode displayMode) {
+ @Override
+ public boolean setDisplayMode (DisplayMode displayMode) {
return false;
}
-
- @Override public DisplayMode[] getDisplayModes () {
+
+ @Override
+ public DisplayMode[] getDisplayModes () {
return new DisplayMode[0];
}
- @Override public void setTitle (String title) {
-
+ @Override
+ public void setTitle (String title) {
+
}
- @Override public void setIcon (Pixmap pixmap) {
-
+ @Override
+ public void setIcon (Pixmap pixmap) {
+
}
- @Override public DisplayMode getDesktopDisplayMode () {
+ @Override
+ public DisplayMode getDesktopDisplayMode () {
return null;
}
- @Override public boolean setDisplayMode (int width, int height, boolean fullscreen) {
+ @Override
+ public boolean setDisplayMode (int width, int height, boolean fullscreen) {
return false;
}
- @Override public void setVSync (boolean vsync) {
+ @Override
+ public void setVSync (boolean vsync) {
// TODO Auto-generated method stub
-
+
}
- @Override public BufferFormat getBufferFormat () {
+ @Override
+ public BufferFormat getBufferFormat () {
return null;
}
-
- @Override public boolean supportsExtension (String extension) {
- if(extensions == null) extensions = Gdx.gl.glGetString(GL10.GL_EXTENSIONS);
+
+ @Override
+ public boolean supportsExtension (String extension) {
+ if (extensions == null) extensions = Gdx.gl.glGetString(GL10.GL_EXTENSIONS);
return extensions.contains(extension);
}
@Override
- public float getDensity() {
+ public float getDensity () {
return (Toolkit.getDefaultToolkit().getScreenResolution() / 160f);
}
}
diff --git a/backends/gdx-backends-angle/src/com/badlogic/gdx/backends/angle/AngleInput.java b/backends/gdx-backends-angle/src/com/badlogic/gdx/backends/angle/AngleInput.java
index 5eb29ce7946..d870ef62a81 100644
--- a/backends/gdx-backends-angle/src/com/badlogic/gdx/backends/angle/AngleInput.java
+++ b/backends/gdx-backends-angle/src/com/badlogic/gdx/backends/angle/AngleInput.java
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
+
package com.badlogic.gdx.backends.angle;
import java.util.ArrayList;
@@ -98,7 +99,7 @@ public void run () {
});
}
- public int getX () {
+ public int getX () {
return mouseY;
}
@@ -111,7 +112,7 @@ public boolean isAccelerometerAvailable () {
}
public boolean isKeyPressed (int key) {
- if(key == Keys.ANY_KEY)
+ if (key == Keys.ANY_KEY)
return pressedKeys.size() > 0;
else
return pressedKeys.contains(key);
@@ -146,18 +147,20 @@ public boolean supportsMultitouch () {
return false;
}
- @Override public void setOnscreenKeyboardVisible (boolean visible) {
+ @Override
+ public void setOnscreenKeyboardVisible (boolean visible) {
}
- @Override public void setCatchBackKey (boolean catchBack) {
+ @Override
+ public void setCatchBackKey (boolean catchBack) {
}
void processEvents () {
synchronized (this) {
justTouched = false;
-
+
if (processor != null) {
InputProcessor processor = this.processor;
int len = keyEvents.size();
@@ -203,8 +206,9 @@ void processEvents () {
int len = touchEvents.size();
for (int i = 0; i < len; i++) {
TouchEvent event = touchEvents.get(i);
- if(event.type == TouchEvent.TOUCH_DOWN);
- justTouched = true;
+ if (event.type == TouchEvent.TOUCH_DOWN)
+ ;
+ justTouched = true;
usedTouchEvents.free(event);
}
@@ -223,11 +227,13 @@ boolean isButtonPressed () {
return mousePressed;
}
- @Override public void setInputProcessor (InputProcessor processor) {
+ @Override
+ public void setInputProcessor (InputProcessor processor) {
this.processor = processor;
}
-
- @Override public InputProcessor getInputProcessor() {
+
+ @Override
+ public InputProcessor getInputProcessor () {
return this.processor;
}
@@ -248,7 +254,7 @@ void registerKeyEvent (int action, int key, int uniCode) {
break;
case ESLoop.ES_KEY_TYPED:
event.type = KeyEvent.KEY_TYPED;
- break;
+ break;
}
keyEvents.add(event);
@@ -267,15 +273,15 @@ void registerMouseEvent (int action, int x, int y, int button) {
event.type = TouchEvent.TOUCH_DOWN;
mousePressed = true;
justTouched = true;
- if((button & ESLoop.ES_MOUSE_LBUTTON) != 0) {
+ if ((button & ESLoop.ES_MOUSE_LBUTTON) != 0) {
pressedButtons.add(Buttons.LEFT);
event.button = Buttons.LEFT;
}
- if((button & ESLoop.ES_MOUSE_RBUTTON) != 0) {
+ if ((button & ESLoop.ES_MOUSE_RBUTTON) != 0) {
pressedButtons.add(Buttons.RIGHT);
event.button = Buttons.RIGHT;
}
- if((button & ESLoop.ES_MOUSE_MBUTTON) != 0) {
+ if ((button & ESLoop.ES_MOUSE_MBUTTON) != 0) {
pressedButtons.add(Buttons.MIDDLE);
event.button = Buttons.MIDDLE;
}
@@ -283,195 +289,286 @@ void registerMouseEvent (int action, int x, int y, int button) {
case ESLoop.ES_MOUSE_UP:
event.type = TouchEvent.TOUCH_UP;
mousePressed = false;
- if((button & ESLoop.ES_MOUSE_LBUTTON) != 0) {
+ if ((button & ESLoop.ES_MOUSE_LBUTTON) != 0) {
pressedButtons.remove(Buttons.LEFT);
- event.button = Buttons.LEFT;
+ event.button = Buttons.LEFT;
}
- if((button & ESLoop.ES_MOUSE_RBUTTON) != 0) {
+ if ((button & ESLoop.ES_MOUSE_RBUTTON) != 0) {
pressedButtons.remove(Buttons.RIGHT);
event.button = Buttons.RIGHT;
}
- if((button & ESLoop.ES_MOUSE_MBUTTON) != 0) {
+ if ((button & ESLoop.ES_MOUSE_MBUTTON) != 0) {
pressedButtons.remove(Buttons.MIDDLE);
event.button = Buttons.MIDDLE;
}
break;
case ESLoop.ES_MOUSE_MOVE:
- if(!mousePressed)
+ if (!mousePressed)
event.type = TouchEvent.TOUCH_MOVED;
else
event.type = TouchEvent.TOUCH_DRAGGED;
- break;
+ break;
case ESLoop.ES_MOUSE_WHEEL:
event.type = TouchEvent.TOUCH_SCROLL;
event.scrollAmount = -(int)Math.signum(x);
break;
}
-
+
touchEvents.add(event);
}
}
int toGdxKeyCode (int keyCode) {
- switch(keyCode) {
- case 0x08: return Keys.BACK;
- case 0x09: return Keys.TAB;
- case 0x0d: return Keys.ENTER;
- case 0x10: return Keys.SHIFT_LEFT;
- case 0x11: return Keys.CONTROL_LEFT;
- case 0x12: return Keys.ALT_LEFT;
-// case 0x13: return Keys.KEYCODE_PAUSE;
-// case 0x14: return Keys.KEYCODE_CAPS;
- case 0x18: return Keys.ESCAPE;
- case 0x20: return Keys.SPACE;
- case 0x23: return Keys.END;
- case 0x24: return Keys.HOME;
- case 0x25: return Keys.DPAD_LEFT;
- case 0x26: return Keys.DPAD_UP;
- case 0x27: return Keys.DPAD_RIGHT;
- case 0x28: return Keys.DPAD_DOWN;
- case 0x2d: return Keys.INSERT;
- case 0x2e: return Keys.DEL;
- case 0x30: return Keys.NUM_0;
- case 0x31: return Keys.NUM_1;
- case 0x32: return Keys.NUM_2;
- case 0x33: return Keys.NUM_3;
- case 0x34: return Keys.NUM_4;
- case 0x35: return Keys.NUM_5;
- case 0x36: return Keys.NUM_6;
- case 0x37: return Keys.NUM_7;
- case 0x38: return Keys.NUM_8;
- case 0x39: return Keys.NUM_9;
- case 0x41: return Keys.A;
- case 0x42: return Keys.B;
- case 0x43: return Keys.C;
- case 0x44: return Keys.D;
- case 0x45: return Keys.E;
- case 0x46: return Keys.F;
- case 0x47: return Keys.G;
- case 0x48: return Keys.H;
- case 0x49: return Keys.I;
- case 0x4a: return Keys.J;
- case 0x4b: return Keys.K;
- case 0x4c: return Keys.L;
- case 0x4d: return Keys.M;
- case 0x4e: return Keys.N;
- case 0x4f: return Keys.O;
- case 0x50: return Keys.P;
- case 0x51: return Keys.Q;
- case 0x52: return Keys.R;
- case 0x53: return Keys.S;
- case 0x54: return Keys.T;
- case 0x55: return Keys.U;
- case 0x56: return Keys.V;
- case 0x57: return Keys.W;
- case 0x58: return Keys.X;
- case 0x59: return Keys.Y;
- case 0x5a: return Keys.Z;
- case 0x60: return Keys.NUM_0;
- case 0x61: return Keys.NUM_1;
- case 0x62: return Keys.NUM_2;
- case 0x63: return Keys.NUM_3;
- case 0x64: return Keys.NUM_4;
- case 0x65: return Keys.NUM_5;
- case 0x66: return Keys.NUM_6;
- case 0x67: return Keys.NUM_7;
- case 0x68: return Keys.NUM_8;
- case 0x69: return Keys.NUM_9;
- case 0x6a: return Keys.STAR;
- case 0x6b: return Keys.PLUS;
- case 0x6d: return Keys.MINUS;
- case 0x6e: return Keys.PERIOD;
- case 0x6f: return Keys.SLASH;
- case 0xa0: return Keys.SHIFT_LEFT;
- case 0xa1: return Keys.SHIFT_RIGHT;
- case 0xa2: return Keys.CONTROL_LEFT;
- case 0xa3: return Keys.CONTROL_RIGHT;
- case 0xae: return Keys.VOLUME_DOWN;
- case 0xaf: return Keys.VOLUME_UP;
- default:
- return Keys.UNKNOWN;
- }
- }
-
- @Override public void vibrate (int milliseconds) {
-
- }
-
- @Override public boolean justTouched () {
+ switch (keyCode) {
+ case 0x08:
+ return Keys.BACK;
+ case 0x09:
+ return Keys.TAB;
+ case 0x0d:
+ return Keys.ENTER;
+ case 0x10:
+ return Keys.SHIFT_LEFT;
+ case 0x11:
+ return Keys.CONTROL_LEFT;
+ case 0x12:
+ return Keys.ALT_LEFT;
+// case 0x13: return Keys.KEYCODE_PAUSE;
+// case 0x14: return Keys.KEYCODE_CAPS;
+ case 0x18:
+ return Keys.ESCAPE;
+ case 0x20:
+ return Keys.SPACE;
+ case 0x23:
+ return Keys.END;
+ case 0x24:
+ return Keys.HOME;
+ case 0x25:
+ return Keys.DPAD_LEFT;
+ case 0x26:
+ return Keys.DPAD_UP;
+ case 0x27:
+ return Keys.DPAD_RIGHT;
+ case 0x28:
+ return Keys.DPAD_DOWN;
+ case 0x2d:
+ return Keys.INSERT;
+ case 0x2e:
+ return Keys.DEL;
+ case 0x30:
+ return Keys.NUM_0;
+ case 0x31:
+ return Keys.NUM_1;
+ case 0x32:
+ return Keys.NUM_2;
+ case 0x33:
+ return Keys.NUM_3;
+ case 0x34:
+ return Keys.NUM_4;
+ case 0x35:
+ return Keys.NUM_5;
+ case 0x36:
+ return Keys.NUM_6;
+ case 0x37:
+ return Keys.NUM_7;
+ case 0x38:
+ return Keys.NUM_8;
+ case 0x39:
+ return Keys.NUM_9;
+ case 0x41:
+ return Keys.A;
+ case 0x42:
+ return Keys.B;
+ case 0x43:
+ return Keys.C;
+ case 0x44:
+ return Keys.D;
+ case 0x45:
+ return Keys.E;
+ case 0x46:
+ return Keys.F;
+ case 0x47:
+ return Keys.G;
+ case 0x48:
+ return Keys.H;
+ case 0x49:
+ return Keys.I;
+ case 0x4a:
+ return Keys.J;
+ case 0x4b:
+ return Keys.K;
+ case 0x4c:
+ return Keys.L;
+ case 0x4d:
+ return Keys.M;
+ case 0x4e:
+ return Keys.N;
+ case 0x4f:
+ return Keys.O;
+ case 0x50:
+ return Keys.P;
+ case 0x51:
+ return Keys.Q;
+ case 0x52:
+ return Keys.R;
+ case 0x53:
+ return Keys.S;
+ case 0x54:
+ return Keys.T;
+ case 0x55:
+ return Keys.U;
+ case 0x56:
+ return Keys.V;
+ case 0x57:
+ return Keys.W;
+ case 0x58:
+ return Keys.X;
+ case 0x59:
+ return Keys.Y;
+ case 0x5a:
+ return Keys.Z;
+ case 0x60:
+ return Keys.NUM_0;
+ case 0x61:
+ return Keys.NUM_1;
+ case 0x62:
+ return Keys.NUM_2;
+ case 0x63:
+ return Keys.NUM_3;
+ case 0x64:
+ return Keys.NUM_4;
+ case 0x65:
+ return Keys.NUM_5;
+ case 0x66:
+ return Keys.NUM_6;
+ case 0x67:
+ return Keys.NUM_7;
+ case 0x68:
+ return Keys.NUM_8;
+ case 0x69:
+ return Keys.NUM_9;
+ case 0x6a:
+ return Keys.STAR;
+ case 0x6b:
+ return Keys.PLUS;
+ case 0x6d:
+ return Keys.MINUS;
+ case 0x6e:
+ return Keys.PERIOD;
+ case 0x6f:
+ return Keys.SLASH;
+ case 0xa0:
+ return Keys.SHIFT_LEFT;
+ case 0xa1:
+ return Keys.SHIFT_RIGHT;
+ case 0xa2:
+ return Keys.CONTROL_LEFT;
+ case 0xa3:
+ return Keys.CONTROL_RIGHT;
+ case 0xae:
+ return Keys.VOLUME_DOWN;
+ case 0xaf:
+ return Keys.VOLUME_UP;
+ default:
+ return Keys.UNKNOWN;
+ }
+ }
+
+ @Override
+ public void vibrate (int milliseconds) {
+
+ }
+
+ @Override
+ public boolean justTouched () {
return justTouched;
- }
-
- @Override public boolean isButtonPressed (int button) {
+ }
+
+ @Override
+ public boolean isButtonPressed (int button) {
return pressedButtons.contains(button);
}
- @Override public void vibrate (long[] pattern, int repeat) {
+ @Override
+ public void vibrate (long[] pattern, int repeat) {
}
- @Override public void cancelVibrate () {
+ @Override
+ public void cancelVibrate () {
}
- @Override public float getAzimuth () {
+ @Override
+ public float getAzimuth () {
return 0;
}
- @Override public float getPitch () {
+ @Override
+ public float getPitch () {
return 0;
}
- @Override public float getRoll () {
+ @Override
+ public float getRoll () {
return 0;
}
-
- @Override public boolean isPeripheralAvailable (Peripheral peripheral) {
- if(peripheral == Peripheral.HardwareKeyboard) return true;
+
+ @Override
+ public boolean isPeripheralAvailable (Peripheral peripheral) {
+ if (peripheral == Peripheral.HardwareKeyboard) return true;
return false;
}
- @Override public int getRotation () {
+ @Override
+ public int getRotation () {
return 0;
}
- @Override public Orientation getNativeOrientation () {
+ @Override
+ public Orientation getNativeOrientation () {
return Orientation.Landscape;
}
- @Override public void setCursorCatched (boolean catched) {
+ @Override
+ public void setCursorCatched (boolean catched) {
}
- @Override public boolean isCursorCatched () {
+ @Override
+ public boolean isCursorCatched () {
return false;
}
- @Override public int getDeltaX () {
+ @Override
+ public int getDeltaX () {
// TODO Auto-generated method stub
return 0;
}
- @Override public int getDeltaX (int pointer) {
+ @Override
+ public int getDeltaX (int pointer) {
// TODO Auto-generated method stub
return 0;
}
- @Override public int getDeltaY () {
+ @Override
+ public int getDeltaY () {
// TODO Auto-generated method stub
return 0;
}
- @Override public int getDeltaY (int pointer) {
+ @Override
+ public int getDeltaY (int pointer) {
// TODO Auto-generated method stub
return 0;
}
- @Override public void setCursorPosition (int x, int y) {
+ @Override
+ public void setCursorPosition (int x, int y) {
// TODO Auto-generated method stub
-
+
}
@Override
- public void setCatchMenuKey(boolean catchMenu) {
+ public void setCatchMenuKey (boolean catchMenu) {
// TODO Auto-generated method stub
-
- }
+
+ }
}
diff --git a/backends/gdx-backends-angle/src/com/badlogic/gdx/backends/angle/AngleMusic.java b/backends/gdx-backends-angle/src/com/badlogic/gdx/backends/angle/AngleMusic.java
index 44e4efeb521..e7f01b5e1fb 100644
--- a/backends/gdx-backends-angle/src/com/badlogic/gdx/backends/angle/AngleMusic.java
+++ b/backends/gdx-backends-angle/src/com/badlogic/gdx/backends/angle/AngleMusic.java
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
+
package com.badlogic.gdx.backends.angle;
import java.io.BufferedInputStream;
@@ -71,7 +72,8 @@ private void openAudioInputStream () throws UnsupportedAudioFileException, IOExc
ain = AudioSystem.getAudioInputStream(decodedFormat, ain);
}
- @Override public void dispose () {
+ @Override
+ public void dispose () {
disposed = true;
try {
thread.join();
@@ -82,31 +84,38 @@ private void openAudioInputStream () throws UnsupportedAudioFileException, IOExc
}
}
- @Override public boolean isLooping () {
+ @Override
+ public boolean isLooping () {
return looping.get();
}
- @Override public boolean isPlaying () {
+ @Override
+ public boolean isPlaying () {
return state.get() == Playing;
}
- @Override public void pause () {
+ @Override
+ public void pause () {
state.compareAndSet(Playing, Paused);
}
- @Override public void play () {
+ @Override
+ public void play () {
state.set(Playing);
}
- @Override public void stop () {
+ @Override
+ public void stop () {
state.set(Stopped);
}
- @Override public void setLooping (boolean isLooping) {
+ @Override
+ public void setLooping (boolean isLooping) {
looping.set(isLooping);
}
- @Override public void setVolume (float volume) {
+ @Override
+ public void setVolume (float volume) {
try {
volume = Math.min(1, volume);
volume = Math.max(0, volume);
@@ -117,7 +126,8 @@ private void openAudioInputStream () throws UnsupportedAudioFileException, IOExc
}
}
- @Override public void run () {
+ @Override
+ public void run () {
int readBytes = 0;
long readSamples = 0;
diff --git a/backends/gdx-backends-angle/src/com/badlogic/gdx/backends/angle/AnglePreferences.java b/backends/gdx-backends-angle/src/com/badlogic/gdx/backends/angle/AnglePreferences.java
index d03b1226926..5b39b54dea8 100644
--- a/backends/gdx-backends-angle/src/com/badlogic/gdx/backends/angle/AnglePreferences.java
+++ b/backends/gdx-backends-angle/src/com/badlogic/gdx/backends/angle/AnglePreferences.java
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
+
package com.badlogic.gdx.backends.angle;
import java.io.BufferedInputStream;
@@ -21,8 +22,8 @@
import java.io.OutputStream;
import java.util.HashMap;
import java.util.Map;
-import java.util.Properties;
import java.util.Map.Entry;
+import java.util.Properties;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Preferences;
@@ -31,134 +32,152 @@ public class AnglePreferences implements Preferences {
private final String name;
private final Properties properties = new Properties();
- AnglePreferences(String name) {
+ AnglePreferences (String name) {
this.name = name;
InputStream in = null;
try {
in = new BufferedInputStream(Gdx.files.external(name).read());
properties.loadFromXML(in);
- } catch(Throwable t) {
+ } catch (Throwable t) {
} finally {
- if(in != null) try { in.close(); } catch(Exception e) { }
+ if (in != null) try {
+ in.close();
+ } catch (Exception e) {
+ }
}
-
+
Runtime.getRuntime().addShutdownHook(new Thread() {
- @Override public void run() {
+ @Override
+ public void run () {
flush();
}
});
- }
-
- @Override public void putBoolean (String key, boolean val) {
+ }
+
+ @Override
+ public void putBoolean (String key, boolean val) {
properties.put(key, Boolean.toString(val));
}
- @Override public void putInteger (String key, int val) {
+ @Override
+ public void putInteger (String key, int val) {
properties.put(key, Integer.toString(val));
}
- @Override public void putLong (String key, long val) {
+ @Override
+ public void putLong (String key, long val) {
properties.put(key, Long.toString(val));
}
- @Override public void putFloat (String key, float val) {
+ @Override
+ public void putFloat (String key, float val) {
properties.put(key, Float.toString(val));
}
- @Override public void putString (String key, String val) {
+ @Override
+ public void putString (String key, String val) {
properties.put(key, val);
}
- @Override public void put (Map vals) {
- for(Entry val: vals.entrySet()) {
- if(val.getValue() instanceof Boolean)
- putBoolean(val.getKey(), (Boolean)val.getValue());
- if(val.getValue() instanceof Integer)
- putInteger(val.getKey(), (Integer)val.getValue());
- if(val.getValue() instanceof Long)
- putLong(val.getKey(), (Long)val.getValue());
- if(val.getValue() instanceof String)
- putString(val.getKey(), (String)val.getValue());
- if(val.getValue() instanceof Float)
- putFloat(val.getKey(), (Float)val.getValue());
+ @Override
+ public void put (Map vals) {
+ for (Entry val : vals.entrySet()) {
+ if (val.getValue() instanceof Boolean) putBoolean(val.getKey(), (Boolean)val.getValue());
+ if (val.getValue() instanceof Integer) putInteger(val.getKey(), (Integer)val.getValue());
+ if (val.getValue() instanceof Long) putLong(val.getKey(), (Long)val.getValue());
+ if (val.getValue() instanceof String) putString(val.getKey(), (String)val.getValue());
+ if (val.getValue() instanceof Float) putFloat(val.getKey(), (Float)val.getValue());
}
}
- @Override public boolean getBoolean (String key) {
+ @Override
+ public boolean getBoolean (String key) {
return getBoolean(key, false);
}
- @Override public int getInteger (String key) {
+ @Override
+ public int getInteger (String key) {
return getInteger(key, 0);
}
- @Override public long getLong (String key) {
+ @Override
+ public long getLong (String key) {
return getLong(key, 0);
}
- @Override public float getFloat (String key) {
+ @Override
+ public float getFloat (String key) {
return getFloat(key, 0);
}
- @Override public String getString (String key) {
+ @Override
+ public String getString (String key) {
return getString(key, "");
}
- @Override public boolean getBoolean (String key, boolean defValue) {
+ @Override
+ public boolean getBoolean (String key, boolean defValue) {
return Boolean.parseBoolean(properties.getProperty(key, Boolean.toString(defValue)));
}
- @Override public int getInteger (String key, int defValue) {
+ @Override
+ public int getInteger (String key, int defValue) {
return Integer.parseInt(properties.getProperty(key, Integer.toString(defValue)));
}
- @Override public long getLong (String key, long defValue) {
+ @Override
+ public long getLong (String key, long defValue) {
return Long.parseLong(properties.getProperty(key, Long.toString(defValue)));
}
- @Override public float getFloat (String key, float defValue) {
+ @Override
+ public float getFloat (String key, float defValue) {
return Float.parseFloat(properties.getProperty(key, Float.toString(defValue)));
}
- @Override public String getString (String key, String defValue) {
+ @Override
+ public String getString (String key, String defValue) {
return properties.getProperty(key, defValue);
}
- @Override public Map get () {
+ @Override
+ public Map get () {
Map map = new HashMap();
- for(Entry val: properties.entrySet()) {
- if(val.getValue() instanceof Boolean)
- map.put((String)val.getKey(), (Boolean)Boolean.parseBoolean((String)val.getValue()));
- if(val.getValue() instanceof Integer)
- map.put((String)val.getKey(), (Integer)Integer.parseInt((String)val.getValue()));
- if(val.getValue() instanceof Long)
- map.put((String)val.getKey(), (Long)Long.parseLong((String)val.getValue()));
- if(val.getValue() instanceof String)
- map.put((String)val.getKey(), (String)val.getValue());
- if(val.getValue() instanceof Float)
- map.put((String)val.getKey(), (Float)Float.parseFloat((String)val.getValue()));
+ for (Entry val : properties.entrySet()) {
+ if (val.getValue() instanceof Boolean)
+ map.put((String)val.getKey(), (Boolean)Boolean.parseBoolean((String)val.getValue()));
+ if (val.getValue() instanceof Integer) map.put((String)val.getKey(), (Integer)Integer.parseInt((String)val.getValue()));
+ if (val.getValue() instanceof Long) map.put((String)val.getKey(), (Long)Long.parseLong((String)val.getValue()));
+ if (val.getValue() instanceof String) map.put((String)val.getKey(), (String)val.getValue());
+ if (val.getValue() instanceof Float) map.put((String)val.getKey(), (Float)Float.parseFloat((String)val.getValue()));
}
-
+
return map;
}
- @Override public boolean contains (String key) {
+ @Override
+ public boolean contains (String key) {
return properties.containsKey(key);
}
- @Override public void clear () {
+ @Override
+ public void clear () {
properties.clear();
}
-
- @Override public void flush() {
+
+ @Override
+ public void flush () {
OutputStream out = null;
try {
out = new BufferedOutputStream(Gdx.files.external(AnglePreferences.this.name).write(false));
properties.storeToXML(out, null);
- } catch(Throwable t) {
+ } catch (Throwable t) {
} finally {
- if(out != null) try { out.close(); } catch(Exception e) { }
+ if (out != null) try {
+ out.close();
+ } catch (Exception e) {
+ }
}
}
}
diff --git a/backends/gdx-backends-angle/src/com/badlogic/gdx/backends/angle/AngleSound.java b/backends/gdx-backends-angle/src/com/badlogic/gdx/backends/angle/AngleSound.java
index df2761d4a2e..dfedfaffc49 100644
--- a/backends/gdx-backends-angle/src/com/badlogic/gdx/backends/angle/AngleSound.java
+++ b/backends/gdx-backends-angle/src/com/badlogic/gdx/backends/angle/AngleSound.java
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
+
package com.badlogic.gdx.backends.angle;
import java.io.BufferedInputStream;
@@ -31,11 +32,8 @@
import com.badlogic.gdx.audio.Sound;
-/**
- * Implements the {@link Sound} interface for the desktop using {@link Clip}s internally.
- * @author mzechner
- *
- */
+/** Implements the {@link Sound} interface for the desktop using {@link Clip}s internally.
+ * @author mzechner */
final class AngleSound implements Sound {
/** the audio format **/
private final AudioFormat format;
@@ -148,16 +146,12 @@ public void stop () {
throw new UnsupportedOperationException("Upgrade Angle to OpenAL.");
}
- /**
- * @return the {@link AudioFormat} of the audio data
- */
+ /** @return the {@link AudioFormat} of the audio data */
public AudioFormat getAudioFormat () {
return format;
}
- /**
- * @return the audio samples in form of a byte array
- */
+ /** @return the audio samples in form of a byte array */
public float[] getAudioData () {
return samples;
}
diff --git a/backends/gdx-backends-angle/src/com/badlogic/gdx/backends/angle/PNGDecoder.java b/backends/gdx-backends-angle/src/com/badlogic/gdx/backends/angle/PNGDecoder.java
index 4ec9b962539..2e4f8b64cda 100644
--- a/backends/gdx-backends-angle/src/com/badlogic/gdx/backends/angle/PNGDecoder.java
+++ b/backends/gdx-backends-angle/src/com/badlogic/gdx/backends/angle/PNGDecoder.java
@@ -32,12 +32,10 @@
import java.util.zip.DataFormatException;
import java.util.zip.Inflater;
-/**
- * Decodes A PNG directly a ByteBuffer.
+/** Decodes A PNG directly a ByteBuffer.
*
* @author Matthias Mann
- * @author Nathan Sweet (minor edits to avoid allocation)
- */
+ * @author Nathan Sweet (minor edits to avoid allocation) */
final class PNGDecoder {
public enum Format {
ALPHA(1, true), LUMINANCE(1, false), LUMINANCE_ALPHA(2, true), RGB(3, false), RGBA(4, true), BGRA(4, true), ABGR(4, true);
@@ -144,13 +142,11 @@ public boolean isRGB () {
return colorType == COLOR_TRUEALPHA || colorType == COLOR_TRUECOLOR || colorType == COLOR_INDEXED;
}
- /**
- * Computes the implemented format conversion for the desired format.
+ /** Computes the implemented format conversion for the desired format.
*
* @param fmt the desired format
* @return format which best matches the desired format
- * @throws UnsupportedOperationException if this PNG file can't be decoded
- */
+ * @throws UnsupportedOperationException if this PNG file can't be decoded */
public Format decideTextureFormat (Format fmt) {
switch (colorType) {
case COLOR_TRUECOLOR:
diff --git a/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/GdxGwtTest.java b/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/GdxGwtTest.java
index c5a995abbf9..84aaf19ffbd 100644
--- a/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/GdxGwtTest.java
+++ b/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/GdxGwtTest.java
@@ -1,3 +1,4 @@
+
package com.badlogic.gdx.backends.gwt;
import com.badlogic.gdx.ApplicationListener;
@@ -6,40 +7,40 @@
public class GdxGwtTest extends GwtApplication implements ApplicationListener {
@Override
- public GwtApplicationConfiguration getConfig() {
+ public GwtApplicationConfiguration getConfig () {
return new GwtApplicationConfiguration(500, 500);
}
@Override
- public ApplicationListener getApplicationListener() {
+ public ApplicationListener getApplicationListener () {
return this;
}
@Override
- public void create() {
+ public void create () {
}
@Override
- public void resume() {
+ public void resume () {
}
@Override
- public void render() {
+ public void render () {
Gdx.gl.glClearColor(1, (float)Math.random(), 0, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
-
+
Gdx.app.log("GdxGwtTest", "fps:" + Gdx.graphics.getFramesPerSecond() + ", " + Gdx.graphics.getDeltaTime());
}
@Override
- public void resize(int width, int height) {
+ public void resize (int width, int height) {
}
@Override
- public void pause() {
+ public void pause () {
}
@Override
- public void dispose() {
+ public void dispose () {
}
}
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 191d450775c..75052a058d0 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
@@ -1,3 +1,4 @@
+
package com.badlogic.gdx.backends.gwt;
import gwt.g2d.client.util.FpsTimer;
@@ -29,43 +30,43 @@ public abstract class GwtApplication implements EntryPoint, Application {
private TextArea log = null;
private int logLevel = LOG_ERROR;
private List runnables = new ArrayList();
-
+
@Override
- public void onModuleLoad() {
+ public void onModuleLoad () {
this.listener = getApplicationListener();
this.config = getConfig();
- this.root = config.rootPanel != null? config.rootPanel: RootPanel.get();
+ this.root = config.rootPanel != null ? config.rootPanel : RootPanel.get();
graphics = new GwtGraphics(root, config);
-
+
Gdx.app = this;
Gdx.graphics = graphics;
Gdx.gl20 = graphics.getGL20();
Gdx.gl = graphics.getGLCommon();
-
+
setupLoop();
}
-
- private void setupLoop() {
+
+ private void setupLoop () {
// tell listener about app creation
listener.create();
listener.resize(graphics.getWidth(), graphics.getHeight());
-
+
// add resize handler
graphics.surface.addHandler(new ResizeHandler() {
@Override
- public void onResize(ResizeEvent event) {
+ public void onResize (ResizeEvent event) {
GwtApplication.this.listener.resize(event.getWidth(), event.getHeight());
}
}, ResizeEvent.getType());
-
+
// setup rendering timer
FpsTimer timer = new FpsTimer(config.fps) {
@Override
- public void update() {
+ public void update () {
graphics.setFps(this.getFps());
-
- for(int i = 0; i < runnables.size(); i++) {
+
+ for (int i = 0; i < runnables.size(); i++) {
runnables.get(i).run();
}
runnables.clear();
@@ -75,44 +76,45 @@ public void update() {
timer.start();
}
- public abstract GwtApplicationConfiguration getConfig();
- public abstract ApplicationListener getApplicationListener();
+ public abstract GwtApplicationConfiguration getConfig ();
+
+ public abstract ApplicationListener getApplicationListener ();
@Override
- public Graphics getGraphics() {
+ public Graphics getGraphics () {
return graphics;
}
@Override
- public Audio getAudio() {
+ public Audio getAudio () {
// FIXME
throw new GdxRuntimeException("not implemented");
}
@Override
- public Input getInput() {
+ public Input getInput () {
// FIXME
throw new GdxRuntimeException("not implemented");
}
@Override
- public Files getFiles() {
+ public Files getFiles () {
// FIXME
throw new GdxRuntimeException("not implemented");
}
- private void checkLogLabel() {
- if(log == null) {
+ private void checkLogLabel () {
+ if (log == null) {
log = new TextArea();
log.setSize(graphics.getWidth() + "px", "150px");
log.setReadOnly(true);
root.add(log);
}
}
-
+
@Override
- public void log(String tag, String message) {
- if(logLevel >= LOG_INFO) {
+ public void log (String tag, String message) {
+ if (logLevel >= LOG_INFO) {
checkLogLabel();
log.setText(log.getText() + "\n" + tag + ": " + message);
log.setCursorPos(log.getText().length() - 1);
@@ -120,17 +122,17 @@ public void log(String tag, String message) {
}
@Override
- public void log(String tag, String message, Exception exception) {
- if(logLevel >= LOG_INFO) {
+ public void log (String tag, String message, Exception exception) {
+ if (logLevel >= LOG_INFO) {
checkLogLabel();
log.setText(log.getText() + "\n" + tag + ": " + message + "\n" + exception.getMessage());
log.setCursorPos(log.getText().length() - 1);
- }
+ }
}
@Override
- public void error(String tag, String message) {
- if(logLevel >= LOG_ERROR) {
+ public void error (String tag, String message) {
+ if (logLevel >= LOG_ERROR) {
checkLogLabel();
log.setText(log.getText() + "\n" + tag + ": " + message);
log.setCursorPos(log.getText().length() - 1);
@@ -138,51 +140,51 @@ public void error(String tag, String message) {
}
@Override
- public void error(String tag, String message, Exception exception) {
- if(logLevel >= LOG_ERROR) {
+ public void error (String tag, String message, Exception exception) {
+ if (logLevel >= LOG_ERROR) {
checkLogLabel();
log.setText(log.getText() + "\n" + tag + ": " + message + "\n" + exception.getMessage());
log.setCursorPos(log.getText().length() - 1);
- }
+ }
}
@Override
- public void setLogLevel(int logLevel) {
+ public void setLogLevel (int logLevel) {
this.logLevel = logLevel;
}
@Override
- public ApplicationType getType() {
+ public ApplicationType getType () {
return ApplicationType.WebGL;
}
@Override
- public int getVersion() {
+ public int getVersion () {
return 0;
}
@Override
- public long getJavaHeap() {
+ public long getJavaHeap () {
return 0;
}
@Override
- public long getNativeHeap() {
+ public long getNativeHeap () {
return 0;
}
@Override
- public Preferences getPreferences(String name) {
+ public Preferences getPreferences (String name) {
// FIXME
throw new GdxRuntimeException("not implemented");
}
@Override
- public void postRunnable(Runnable runnable) {
+ public void postRunnable (Runnable runnable) {
runnables.add(runnable);
}
@Override
- public void exit() {
+ public void exit () {
}
}
diff --git a/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/GwtApplicationConfiguration.java b/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/GwtApplicationConfiguration.java
index ed1915b6062..17334adf5a8 100644
--- a/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/GwtApplicationConfiguration.java
+++ b/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/GwtApplicationConfiguration.java
@@ -1,3 +1,4 @@
+
package com.badlogic.gdx.backends.gwt;
import com.google.gwt.user.client.ui.Panel;
@@ -11,8 +12,8 @@ public class GwtApplicationConfiguration {
public int fps = 60;
public Panel rootPanel;
public TextArea log;
-
- public GwtApplicationConfiguration(int width, int height) {
+
+ public GwtApplicationConfiguration (int width, int height) {
this.width = width;
this.height = height;
}
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 d44ddf72be7..27c20c6d9f6 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
@@ -1,3 +1,4 @@
+
package com.badlogic.gdx.backends.gwt;
import gwt.g3d.client.Surface3D;
@@ -36,869 +37,849 @@
public class GwtGL20 implements GL20 {
final Surface3D surface;
final GL2 gl;
-
- protected GwtGL20(Surface3D surface) {
+
+ protected GwtGL20 (Surface3D surface) {
this.surface = surface;
this.gl = surface.getGL();
}
@Override
- public void glActiveTexture(int texture) {
+ public void glActiveTexture (int texture) {
gl.activeTexture(TextureUnit.parseTextureUnit(texture));
}
@Override
- public void glBindTexture(int target, int texture) {
+ public void glBindTexture (int target, int texture) {
// FIXME
throw new GdxRuntimeException("not implemented");
-// gl.bindTexture(TextureTarget.parseTextureTarget(target), );
+// gl.bindTexture(TextureTarget.parseTextureTarget(target), );
}
@Override
- public void glBlendFunc(int sfactor, int dfactor) {
+ public void glBlendFunc (int sfactor, int dfactor) {
gl.blendFunc(BlendingFactorSrc.parseBlendingFactorSrc(sfactor), BlendingFactorDest.parseBlendingFactorDest(dfactor));
}
@Override
- public void glClear(int mask) {
- if((mask & GL20.GL_COLOR_BUFFER_BIT) != 0 && (mask & GL20.GL_DEPTH_BUFFER_BIT) != 0 && (mask & GL20.GL_STENCIL_BUFFER_BIT) != 0) {
+ public void glClear (int mask) {
+ if ((mask & GL20.GL_COLOR_BUFFER_BIT) != 0 && (mask & GL20.GL_DEPTH_BUFFER_BIT) != 0
+ && (mask & GL20.GL_STENCIL_BUFFER_BIT) != 0) {
gl.clear(ClearBufferMask.COLOR_BUFFER_BIT, ClearBufferMask.DEPTH_BUFFER_BIT, ClearBufferMask.STENCIL_BUFFER_BIT);
}
-
- if((mask & GL20.GL_COLOR_BUFFER_BIT) != 0 && (mask & GL20.GL_DEPTH_BUFFER_BIT) != 0) {
+
+ if ((mask & GL20.GL_COLOR_BUFFER_BIT) != 0 && (mask & GL20.GL_DEPTH_BUFFER_BIT) != 0) {
gl.clear(ClearBufferMask.COLOR_BUFFER_BIT, ClearBufferMask.DEPTH_BUFFER_BIT);
}
-
- if((mask & GL20.GL_DEPTH_BUFFER_BIT) != 0 && (mask & GL20.GL_STENCIL_BUFFER_BIT) != 0) {
+
+ if ((mask & GL20.GL_DEPTH_BUFFER_BIT) != 0 && (mask & GL20.GL_STENCIL_BUFFER_BIT) != 0) {
gl.clear(ClearBufferMask.DEPTH_BUFFER_BIT, ClearBufferMask.STENCIL_BUFFER_BIT);
}
-
- if((mask & GL20.GL_COLOR_BUFFER_BIT) != 0 && (mask & GL20.GL_STENCIL_BUFFER_BIT) != 0) {
+
+ if ((mask & GL20.GL_COLOR_BUFFER_BIT) != 0 && (mask & GL20.GL_STENCIL_BUFFER_BIT) != 0) {
gl.clear(ClearBufferMask.COLOR_BUFFER_BIT, ClearBufferMask.STENCIL_BUFFER_BIT);
}
-
- if((mask & GL20.GL_COLOR_BUFFER_BIT) != 0) {
+
+ if ((mask & GL20.GL_COLOR_BUFFER_BIT) != 0) {
gl.clear(ClearBufferMask.COLOR_BUFFER_BIT);
}
-
- if((mask & GL20.GL_DEPTH_BUFFER_BIT) != 0) {
+
+ if ((mask & GL20.GL_DEPTH_BUFFER_BIT) != 0) {
gl.clear(ClearBufferMask.DEPTH_BUFFER_BIT);
}
-
- if((mask & GL20.GL_STENCIL_BUFFER_BIT) != 0) {
+
+ if ((mask & GL20.GL_STENCIL_BUFFER_BIT) != 0) {
gl.clear(ClearBufferMask.STENCIL_BUFFER_BIT);
}
}
@Override
- public void glClearColor(float red, float green, float blue, float alpha) {
+ public void glClearColor (float red, float green, float blue, float alpha) {
gl.clearColor(red, green, blue, alpha);
}
@Override
- public void glClearDepthf(float depth) {
+ public void glClearDepthf (float depth) {
gl.clearDepth(depth);
}
@Override
- public void glClearStencil(int s) {
+ public void glClearStencil (int s) {
gl.clearStencil(s);
}
@Override
- public void glColorMask(boolean red, boolean green, boolean blue,
- boolean alpha) {
+ public void glColorMask (boolean red, boolean green, boolean blue, boolean alpha) {
gl.colorMask(red, green, blue, alpha);
}
@Override
- public void glCompressedTexImage2D(int target, int level,
- int internalformat, int width, int height, int border,
- int imageSize, Buffer data) {
+ public void glCompressedTexImage2D (int target, int level, int internalformat, int width, int height, int border,
+ int imageSize, Buffer data) {
throw new GdxRuntimeException("compressed textures not supported by GWT WebGL backend");
}
@Override
- public void glCompressedTexSubImage2D(int target, int level, int xoffset,
- int yoffset, int width, int height, int format, int imageSize,
- Buffer data) {
- throw new GdxRuntimeException("compressed textures not supported by GWT WebGL backend");
+ public void glCompressedTexSubImage2D (int target, int level, int xoffset, int yoffset, int width, int height, int format,
+ int imageSize, Buffer data) {
+ throw new GdxRuntimeException("compressed textures not supported by GWT WebGL backend");
}
@Override
- public void glCopyTexImage2D(int target, int level, int internalformat,
- int x, int y, int width, int height, int border) {
- gl.copyTexImage2D(TextureTarget.parseTextureTarget(target), level, PixelInternalFormat.parsePixelInternalFormat(internalformat), x, y, width, height, border);
+ public void glCopyTexImage2D (int target, int level, int internalformat, int x, int y, int width, int height, int border) {
+ gl.copyTexImage2D(TextureTarget.parseTextureTarget(target), level,
+ PixelInternalFormat.parsePixelInternalFormat(internalformat), x, y, width, height, border);
}
@Override
- public void glCopyTexSubImage2D(int target, int level, int xoffset,
- int yoffset, int x, int y, int width, int height) {
+ public void glCopyTexSubImage2D (int target, int level, int xoffset, int yoffset, int x, int y, int width, int height) {
gl.copyTexSubImage2D(TextureTarget.parseTextureTarget(target), level, xoffset, yoffset, x, y, width, height);
}
@Override
- public void glCullFace(int mode) {
+ public void glCullFace (int mode) {
gl.cullFace(CullFaceMode.parseCullFaceMode(mode));
}
@Override
- public void glDeleteTextures(int n, IntBuffer textures) {
+ public void glDeleteTextures (int n, IntBuffer textures) {
// FIXME
throw new GdxRuntimeException("not implemented");
}
@Override
- public void glDepthFunc(int func) {
+ public void glDepthFunc (int func) {
gl.depthFunc(DepthFunction.parseDepthFunction(func));
}
@Override
- public void glDepthMask(boolean flag) {
+ public void glDepthMask (boolean flag) {
gl.depthMask(flag);
}
@Override
- public void glDepthRangef(float zNear, float zFar) {
+ public void glDepthRangef (float zNear, float zFar) {
gl.depthRange(zNear, zFar);
}
@Override
- public void glDisable(int cap) {
+ public void glDisable (int cap) {
gl.disable(EnableCap.parseEnableCap(cap));
}
@Override
- public void glDrawArrays(int mode, int first, int count) {
+ public void glDrawArrays (int mode, int first, int count) {
gl.drawArrays(BeginMode.parseBeginMode(mode), first, count);
}
@Override
- public void glDrawElements(int mode, int count, int type, Buffer indices) {
+ public void glDrawElements (int mode, int count, int type, Buffer indices) {
// FIXME
throw new GdxRuntimeException("not implemented");
-// gl.drawElements(BeginMode.parseBeginMode(mode), count, type, offset)
+// gl.drawElements(BeginMode.parseBeginMode(mode), count, type, offset)
}
@Override
- public void glEnable(int cap) {
+ public void glEnable (int cap) {
gl.enable(EnableCap.parseEnableCap(cap));
}
@Override
- public void glFinish() {
+ public void glFinish () {
gl.finish();
}
@Override
- public void glFlush() {
+ public void glFlush () {
gl.flush();
}
@Override
- public void glFrontFace(int mode) {
+ public void glFrontFace (int mode) {
gl.frontFace(FrontFaceDirection.parseFrontFaceDirection(mode));
}
@Override
- public void glGenTextures(int n, IntBuffer textures) {
+ public void glGenTextures (int n, IntBuffer textures) {
// FIXME
throw new GdxRuntimeException("not implemented");
}
@Override
- public int glGetError() {
+ public int glGetError () {
return gl.getError().getValue();
}
@Override
- public void glGetIntegerv(int pname, IntBuffer params) {
+ public void glGetIntegerv (int pname, IntBuffer params) {
throw new GdxRuntimeException("glGetInteger not supported by GWT WebGL backend");
}
@Override
- public String glGetString(int name) {
+ public String glGetString (int name) {
return gl.getString(StringName.parseStringName(name));
}
@Override
- public void glHint(int target, int mode) {
+ public void glHint (int target, int mode) {
gl.hint(HintTarget.parseHintTarget(target), HintMode.parseHintMode(mode));
}
@Override
- public void glLineWidth(float width) {
+ public void glLineWidth (float width) {
gl.lineWidth(width);
}
@Override
- public void glPixelStorei(int pname, int param) {
+ public void glPixelStorei (int pname, int param) {
gl.pixelStorei(PixelStoreParameter.parsePixelStoreParameter(pname), param);
}
@Override
- public void glPolygonOffset(float factor, float units) {
+ public void glPolygonOffset (float factor, float units) {
gl.polygonOffset(factor, units);
}
@Override
- public void glReadPixels(int x, int y, int width, int height, int format,
- int type, Buffer pixels) {
+ public void glReadPixels (int x, int y, int width, int height, int format, int type, Buffer pixels) {
// FIXME
throw new GdxRuntimeException("not implemented");
}
@Override
- public void glScissor(int x, int y, int width, int height) {
+ public void glScissor (int x, int y, int width, int height) {
gl.scissor(x, y, width, height);
}
@Override
- public void glStencilFunc(int func, int ref, int mask) {
+ public void glStencilFunc (int func, int ref, int mask) {
gl.stencilFunc(StencilFunction.parseStencilFunction(func), ref, mask);
}
@Override
- public void glStencilMask(int mask) {
+ public void glStencilMask (int mask) {
gl.stencilMask(mask);
}
@Override
- public void glStencilOp(int fail, int zfail, int zpass) {
+ public void glStencilOp (int fail, int zfail, int zpass) {
gl.stencilOp(StencilOp.parseStencilOp(fail), StencilOp.parseStencilOp(zfail), StencilOp.parseStencilOp(zpass));
}
@Override
- public void glTexImage2D(int target, int level, int internalformat,
- int width, int height, int border, int format, int type,
- Buffer pixels) {
+ public void glTexImage2D (int target, int level, int internalformat, int width, int height, int border, int format, int type,
+ Buffer pixels) {
// FIXME
throw new GdxRuntimeException("not implemented");
}
@Override
- public void glTexParameterf(int target, int pname, float param) {
+ public void glTexParameterf (int target, int pname, float param) {
gl.texParameterf(TextureTarget.parseTextureTarget(target), TextureParameterName.parseTextureParameterName(pname), param);
}
@Override
- public void glTexSubImage2D(int target, int level, int xoffset,
- int yoffset, int width, int height, int format, int type,
- Buffer pixels) {
+ public void glTexSubImage2D (int target, int level, int xoffset, int yoffset, int width, int height, int format, int type,
+ Buffer pixels) {
// FIXME
throw new GdxRuntimeException("not implemented");
}
@Override
- public void glViewport(int x, int y, int width, int height) {
+ public void glViewport (int x, int y, int width, int height) {
gl.viewport(x, y, width, height);
}
@Override
- public void glAttachShader(int program, int shader) {
- // FIXME
+ public void glAttachShader (int program, int shader) {
+ // FIXME
throw new GdxRuntimeException("not implemented");
}
@Override
- public void glBindAttribLocation(int program, int index, String name) {
- // FIXME
+ public void glBindAttribLocation (int program, int index, String name) {
+ // FIXME
throw new GdxRuntimeException("not implemented");
}
@Override
- public void glBindBuffer(int target, int buffer) {
+ public void glBindBuffer (int target, int buffer) {
// FIXME
throw new GdxRuntimeException("not implemented");
}
@Override
- public void glBindFramebuffer(int target, int framebuffer) {
- // FIXME
+ public void glBindFramebuffer (int target, int framebuffer) {
+ // FIXME
throw new GdxRuntimeException("not implemented");
}
@Override
- public void glBindRenderbuffer(int target, int renderbuffer) {
- // FIXME
- throw new GdxRuntimeException("not implemented");
+ public void glBindRenderbuffer (int target, int renderbuffer) {
+ // FIXME
+ throw new GdxRuntimeException("not implemented");
}
@Override
- public void glBlendColor(float red, float green, float blue, float alpha) {
+ public void glBlendColor (float red, float green, float blue, float alpha) {
gl.blendColor(red, green, blue, alpha);
}
@Override
- public void glBlendEquation(int mode) {
+ public void glBlendEquation (int mode) {
gl.blendEquation(BlendEquationMode.parseBlendEquationMode(mode));
}
@Override
- public void glBlendEquationSeparate(int modeRGB, int modeAlpha) {
- gl.blendEquationSeparate(BlendEquationMode.parseBlendEquationMode(modeRGB), BlendEquationMode.parseBlendEquationMode(modeAlpha));
+ public void glBlendEquationSeparate (int modeRGB, int modeAlpha) {
+ gl.blendEquationSeparate(BlendEquationMode.parseBlendEquationMode(modeRGB),
+ BlendEquationMode.parseBlendEquationMode(modeAlpha));
}
@Override
- public void glBlendFuncSeparate(int srcRGB, int dstRGB, int srcAlpha,
- int dstAlpha) {
- gl.blendFuncSeparate(BlendingFactorSrc.parseBlendingFactorSrc(srcRGB),
- BlendingFactorDest.parseBlendingFactorDest(dstRGB),
- BlendingFactorSrc.parseBlendingFactorSrc(srcAlpha),
- BlendingFactorDest.parseBlendingFactorDest(dstAlpha));
+ public void glBlendFuncSeparate (int srcRGB, int dstRGB, int srcAlpha, int dstAlpha) {
+ gl.blendFuncSeparate(BlendingFactorSrc.parseBlendingFactorSrc(srcRGB), BlendingFactorDest.parseBlendingFactorDest(dstRGB),
+ BlendingFactorSrc.parseBlendingFactorSrc(srcAlpha), BlendingFactorDest.parseBlendingFactorDest(dstAlpha));
}
@Override
- public void glBufferData(int target, int size, Buffer data, int usage) {
- // FIXME
+ public void glBufferData (int target, int size, Buffer data, int usage) {
+ // FIXME
throw new GdxRuntimeException("not implemented");
}
@Override
- public void glBufferSubData(int target, int offset, int size, Buffer data) {
- // FIXME
- throw new GdxRuntimeException("not implemented");
+ public void glBufferSubData (int target, int offset, int size, Buffer data) {
+ // FIXME
+ throw new GdxRuntimeException("not implemented");
}
@Override
- public int glCheckFramebufferStatus(int target) {
+ public int glCheckFramebufferStatus (int target) {
return gl.checkFramebufferStatus(FramebufferTarget.parseFramebufferTarget(target)).getValue();
}
@Override
- public void glCompileShader(int shader) {
- // FIXME
- throw new GdxRuntimeException("not implemented");
+ public void glCompileShader (int shader) {
+ // FIXME
+ throw new GdxRuntimeException("not implemented");
}
@Override
- public int glCreateProgram() {
- // FIXME
+ public int glCreateProgram () {
+ // FIXME
throw new GdxRuntimeException("not implemented");
}
@Override
- public int glCreateShader(int type) {
- // FIXME
+ public int glCreateShader (int type) {
+ // FIXME
throw new GdxRuntimeException("not implemented");
}
@Override
- public void glDeleteBuffers(int n, IntBuffer buffers) {
- // FIXME
- throw new GdxRuntimeException("not implemented");
+ public void glDeleteBuffers (int n, IntBuffer buffers) {
+ // FIXME
+ throw new GdxRuntimeException("not implemented");
}
@Override
- public void glDeleteFramebuffers(int n, IntBuffer framebuffers) {
- // FIXME
- throw new GdxRuntimeException("not implemented");
+ public void glDeleteFramebuffers (int n, IntBuffer framebuffers) {
+ // FIXME
+ throw new GdxRuntimeException("not implemented");
}
@Override
- public void glDeleteProgram(int program) {
- // FIXME
- throw new GdxRuntimeException("not implemented");
+ public void glDeleteProgram (int program) {
+ // FIXME
+ throw new GdxRuntimeException("not implemented");
}
@Override
- public void glDeleteRenderbuffers(int n, IntBuffer renderbuffers) {
- // FIXME
- throw new GdxRuntimeException("not implemented");
+ public void glDeleteRenderbuffers (int n, IntBuffer renderbuffers) {
+ // FIXME
+ throw new GdxRuntimeException("not implemented");
}
@Override
- public void glDeleteShader(int shader) {
- // FIXME
- throw new GdxRuntimeException("not implemented");
+ public void glDeleteShader (int shader) {
+ // FIXME
+ throw new GdxRuntimeException("not implemented");
}
@Override
- public void glDetachShader(int program, int shader) {
- // FIXME
- throw new GdxRuntimeException("not implemented");
+ public void glDetachShader (int program, int shader) {
+ // FIXME
+ throw new GdxRuntimeException("not implemented");
}
@Override
- public void glDisableVertexAttribArray(int index) {
+ public void glDisableVertexAttribArray (int index) {
gl.disableVertexAttribArray(index);
}
@Override
- public void glDrawElements(int mode, int count, int type, int indices) {
+ public void glDrawElements (int mode, int count, int type, int indices) {
gl.drawElements(BeginMode.parseBeginMode(mode), count, DrawElementsType.parseDataType(type), indices);
}
@Override
- public void glEnableVertexAttribArray(int index) {
+ public void glEnableVertexAttribArray (int index) {
gl.enableVertexAttribArray(index);
}
@Override
- public void glFramebufferRenderbuffer(int target, int attachment,
- int renderbuffertarget, int renderbuffer) {
- // FIXME
+ public void glFramebufferRenderbuffer (int target, int attachment, int renderbuffertarget, int renderbuffer) {
+ // FIXME
throw new GdxRuntimeException("not implemented");
}
@Override
- public void glFramebufferTexture2D(int target, int attachment,
- int textarget, int texture, int level) {
- // FIXME
+ public void glFramebufferTexture2D (int target, int attachment, int textarget, int texture, int level) {
+ // FIXME
throw new GdxRuntimeException("not implemented");
}
@Override
- public void glGenBuffers(int n, IntBuffer buffers) {
- // FIXME
- throw new GdxRuntimeException("not implemented");
+ public void glGenBuffers (int n, IntBuffer buffers) {
+ // FIXME
+ throw new GdxRuntimeException("not implemented");
}
@Override
- public void glGenerateMipmap(int target) {
+ public void glGenerateMipmap (int target) {
gl.generateMipmap(TextureTarget.parseTextureTarget(target));
}
@Override
- public void glGenFramebuffers(int n, IntBuffer framebuffers) {
- // FIXME
- throw new GdxRuntimeException("not implemented");
+ public void glGenFramebuffers (int n, IntBuffer framebuffers) {
+ // FIXME
+ throw new GdxRuntimeException("not implemented");
}
@Override
- public void glGenRenderbuffers(int n, IntBuffer renderbuffers) {
- // FIXME
- throw new GdxRuntimeException("not implemented");
+ public void glGenRenderbuffers (int n, IntBuffer renderbuffers) {
+ // FIXME
+ throw new GdxRuntimeException("not implemented");
}
@Override
- public String glGetActiveAttrib(int program, int index, IntBuffer size,
- Buffer type) {
- // FIXME
+ public String glGetActiveAttrib (int program, int index, IntBuffer size, Buffer type) {
+ // FIXME
throw new GdxRuntimeException("not implemented");
}
@Override
- public String glGetActiveUniform(int program, int index, IntBuffer size,
- Buffer type) {
- // FIXME
+ public String glGetActiveUniform (int program, int index, IntBuffer size, Buffer type) {
+ // FIXME
throw new GdxRuntimeException("not implemented");
}
@Override
- public void glGetAttachedShaders(int program, int maxcount, Buffer count,
- IntBuffer shaders) {
- // FIXME
- throw new GdxRuntimeException("not implemented");
+ public void glGetAttachedShaders (int program, int maxcount, Buffer count, IntBuffer shaders) {
+ // FIXME
+ throw new GdxRuntimeException("not implemented");
}
@Override
- public int glGetAttribLocation(int program, String name) {
- // FIXME
+ public int glGetAttribLocation (int program, String name) {
+ // FIXME
throw new GdxRuntimeException("not implemented");
}
@Override
- public void glGetBooleanv(int pname, Buffer params) {
+ public void glGetBooleanv (int pname, Buffer params) {
throw new GdxRuntimeException("glGetBoolean not supported by GWT WebGL backend");
}
@Override
- public void glGetBufferParameteriv(int target, int pname, IntBuffer params) {
- // FIXME
+ public void glGetBufferParameteriv (int target, int pname, IntBuffer params) {
+ // FIXME
throw new GdxRuntimeException("not implemented");
}
@Override
- public void glGetFloatv(int pname, FloatBuffer params) {
+ public void glGetFloatv (int pname, FloatBuffer params) {
throw new GdxRuntimeException("glGetFloat not supported by GWT WebGL backend");
}
@Override
- public void glGetFramebufferAttachmentParameteriv(int target,
- int attachment, int pname, IntBuffer params) {
- // FIXME
+ public void glGetFramebufferAttachmentParameteriv (int target, int attachment, int pname, IntBuffer params) {
+ // FIXME
throw new GdxRuntimeException("not implemented");
}
@Override
- public void glGetProgramiv(int program, int pname, IntBuffer params) {
+ public void glGetProgramiv (int program, int pname, IntBuffer params) {
throw new GdxRuntimeException("glGetProgram not supported by GWT WebGL backend");
}
@Override
- public String glGetProgramInfoLog(int program) {
- // FIXME
+ public String glGetProgramInfoLog (int program) {
+ // FIXME
throw new GdxRuntimeException("not implemented");
}
@Override
- public void glGetRenderbufferParameteriv(int target, int pname,
- IntBuffer params) {
- // FIXME
- throw new GdxRuntimeException("not implemented");
+ public void glGetRenderbufferParameteriv (int target, int pname, IntBuffer params) {
+ // FIXME
+ throw new GdxRuntimeException("not implemented");
}
@Override
- public void glGetShaderiv(int shader, int pname, IntBuffer params) {
+ public void glGetShaderiv (int shader, int pname, IntBuffer params) {
throw new GdxRuntimeException("glGetShader not supported by GWT WebGL backend");
}
@Override
- public String glGetShaderInfoLog(int shader) {
- // FIXME
+ public String glGetShaderInfoLog (int shader) {
+ // FIXME
throw new GdxRuntimeException("not implemented");
}
@Override
- public void glGetShaderPrecisionFormat(int shadertype, int precisiontype,
- IntBuffer range, IntBuffer precision) {
+ public void glGetShaderPrecisionFormat (int shadertype, int precisiontype, IntBuffer range, IntBuffer precision) {
throw new GdxRuntimeException("glGetShaderPrecisionFormat not supported by GWT WebGL backend");
}
@Override
- public void glGetShaderSource(int shader, int bufsize, Buffer length,
- String source) {
+ public void glGetShaderSource (int shader, int bufsize, Buffer length, String source) {
throw new GdxRuntimeException("glGetShaderSource not supported by GWT WebGL backend");
}
@Override
- public void glGetTexParameterfv(int target, int pname, FloatBuffer params) {
+ public void glGetTexParameterfv (int target, int pname, FloatBuffer params) {
throw new GdxRuntimeException("glGetTexParameter not supported by GWT WebGL backend");
}
@Override
- public void glGetTexParameteriv(int target, int pname, IntBuffer params) {
+ public void glGetTexParameteriv (int target, int pname, IntBuffer params) {
throw new GdxRuntimeException("glGetTexParameter not supported by GWT WebGL backend");
}
@Override
- public void glGetUniformfv(int program, int location, FloatBuffer params) {
- // FIXME
+ public void glGetUniformfv (int program, int location, FloatBuffer params) {
+ // FIXME
throw new GdxRuntimeException("not implemented");
}
@Override
- public void glGetUniformiv(int program, int location, IntBuffer params) {
- // FIXME
- throw new GdxRuntimeException("not implemented");
+ public void glGetUniformiv (int program, int location, IntBuffer params) {
+ // FIXME
+ throw new GdxRuntimeException("not implemented");
}
@Override
- public int glGetUniformLocation(int program, String name) {
- // FIXME
+ public int glGetUniformLocation (int program, String name) {
+ // FIXME
throw new GdxRuntimeException("not implemented");
}
@Override
- public void glGetVertexAttribfv(int index, int pname, FloatBuffer params) {
- // FIXME
+ public void glGetVertexAttribfv (int index, int pname, FloatBuffer params) {
+ // FIXME
throw new GdxRuntimeException("not implemented");
}
@Override
- public void glGetVertexAttribiv(int index, int pname, IntBuffer params) {
- // FIXME
+ public void glGetVertexAttribiv (int index, int pname, IntBuffer params) {
+ // FIXME
throw new GdxRuntimeException("not implemented");
}
@Override
- public void glGetVertexAttribPointerv(int index, int pname, Buffer pointer) {
+ public void glGetVertexAttribPointerv (int index, int pname, Buffer pointer) {
throw new GdxRuntimeException("glGetVertexAttribPointer not supported by GWT WebGL backend");
}
@Override
- public boolean glIsBuffer(int buffer) {
- // FIXME
+ public boolean glIsBuffer (int buffer) {
+ // FIXME
throw new GdxRuntimeException("not implemented");
}
@Override
- public boolean glIsEnabled(int cap) {
+ public boolean glIsEnabled (int cap) {
return gl.isEnabled(EnableCap.parseEnableCap(cap));
}
@Override
- public boolean glIsFramebuffer(int framebuffer) {
- // FIXME
+ public boolean glIsFramebuffer (int framebuffer) {
+ // FIXME
throw new GdxRuntimeException("not implemented");
}
@Override
- public boolean glIsProgram(int program) {
- // FIXME
+ public boolean glIsProgram (int program) {
+ // FIXME
throw new GdxRuntimeException("not implemented");
}
@Override
- public boolean glIsRenderbuffer(int renderbuffer) {
- // FIXME
+ public boolean glIsRenderbuffer (int renderbuffer) {
+ // FIXME
throw new GdxRuntimeException("not implemented");
}
@Override
- public boolean glIsShader(int shader) {
- // FIXME
+ public boolean glIsShader (int shader) {
+ // FIXME
throw new GdxRuntimeException("not implemented");
}
@Override
- public boolean glIsTexture(int texture) {
- // FIXME
+ public boolean glIsTexture (int texture) {
+ // FIXME
throw new GdxRuntimeException("not implemented");
}
@Override
- public void glLinkProgram(int program) {
- // FIXME
- throw new GdxRuntimeException("not implemented");
+ public void glLinkProgram (int program) {
+ // FIXME
+ throw new GdxRuntimeException("not implemented");
}
@Override
- public void glReleaseShaderCompiler() {
+ public void glReleaseShaderCompiler () {
throw new GdxRuntimeException("glReleaseShaderCompiler not supported by GWT WebGL backend");
}
@Override
- public void glRenderbufferStorage(int target, int internalformat,
- int width, int height) {
- gl.renderbufferStorage(RenderbufferTarget.parseRenderbufferTarget(target), RenderbufferInternalFormat.parseRenderbufferInternalFormat(internalformat), width, height);
+ public void glRenderbufferStorage (int target, int internalformat, int width, int height) {
+ gl.renderbufferStorage(RenderbufferTarget.parseRenderbufferTarget(target),
+ RenderbufferInternalFormat.parseRenderbufferInternalFormat(internalformat), width, height);
}
@Override
- public void glSampleCoverage(float value, boolean invert) {
+ public void glSampleCoverage (float value, boolean invert) {
gl.sampleCoverage(value, invert);
}
@Override
- public void glShaderBinary(int n, IntBuffer shaders, int binaryformat,
- Buffer binary, int length) {
+ public void glShaderBinary (int n, IntBuffer shaders, int binaryformat, Buffer binary, int length) {
throw new GdxRuntimeException("glShaderBinary not supported by GWT WebGL backend");
}
@Override
- public void glShaderSource(int shader, String string) {
- // FIXME
+ public void glShaderSource (int shader, String string) {
+ // FIXME
throw new GdxRuntimeException("not implemented");
}
@Override
- public void glStencilFuncSeparate(int face, int func, int ref, int mask) {
+ public void glStencilFuncSeparate (int face, int func, int ref, int mask) {
gl.stencilFuncSeparate(CullFaceMode.parseCullFaceMode(face), StencilFunction.parseStencilFunction(func), ref, mask);
}
@Override
- public void glStencilMaskSeparate(int face, int mask) {
+ public void glStencilMaskSeparate (int face, int mask) {
gl.stencilMaskSeparate(CullFaceMode.parseCullFaceMode(face), mask);
}
@Override
- public void glStencilOpSeparate(int face, int fail, int zfail, int zpass) {
- gl.stencilOpSeparate(CullFaceMode.parseCullFaceMode(face), StencilOp.parseStencilOp(fail), StencilOp.parseStencilOp(zfail), StencilOp.parseStencilOp(zpass));
+ public void glStencilOpSeparate (int face, int fail, int zfail, int zpass) {
+ gl.stencilOpSeparate(CullFaceMode.parseCullFaceMode(face), StencilOp.parseStencilOp(fail), StencilOp.parseStencilOp(zfail),
+ StencilOp.parseStencilOp(zpass));
}
@Override
- public void glTexParameterfv(int target, int pname, FloatBuffer params) {
- gl.texParameterf(TextureTarget.parseTextureTarget(target), TextureParameterName.parseTextureParameterName(pname), params.get());
+ public void glTexParameterfv (int target, int pname, FloatBuffer params) {
+ gl.texParameterf(TextureTarget.parseTextureTarget(target), TextureParameterName.parseTextureParameterName(pname),
+ params.get());
}
@Override
- public void glTexParameteri(int target, int pname, int param) {
+ public void glTexParameteri (int target, int pname, int param) {
gl.texParameterf(TextureTarget.parseTextureTarget(target), TextureParameterName.parseTextureParameterName(pname), param);
}
@Override
- public void glTexParameteriv(int target, int pname, IntBuffer params) {
- gl.texParameterf(TextureTarget.parseTextureTarget(target), TextureParameterName.parseTextureParameterName(pname), params.get());
+ public void glTexParameteriv (int target, int pname, IntBuffer params) {
+ gl.texParameterf(TextureTarget.parseTextureTarget(target), TextureParameterName.parseTextureParameterName(pname),
+ params.get());
}
@Override
- public void glUniform1f(int location, float x) {
- // FIXME
+ public void glUniform1f (int location, float x) {
+ // FIXME
throw new GdxRuntimeException("not implemented");
}
@Override
- public void glUniform1fv(int location, int count, FloatBuffer v) {
- // FIXME
- throw new GdxRuntimeException("not implemented");
+ public void glUniform1fv (int location, int count, FloatBuffer v) {
+ // FIXME
+ throw new GdxRuntimeException("not implemented");
}
@Override
- public void glUniform1i(int location, int x) {
- // FIXME
- throw new GdxRuntimeException("not implemented");
+ public void glUniform1i (int location, int x) {
+ // FIXME
+ throw new GdxRuntimeException("not implemented");
}
@Override
- public void glUniform1iv(int location, int count, IntBuffer v) {
- // FIXME
- throw new GdxRuntimeException("not implemented");
+ public void glUniform1iv (int location, int count, IntBuffer v) {
+ // FIXME
+ throw new GdxRuntimeException("not implemented");
}
@Override
- public void glUniform2f(int location, float x, float y) {
- // FIXME
- throw new GdxRuntimeException("not implemented");
+ public void glUniform2f (int location, float x, float y) {
+ // FIXME
+ throw new GdxRuntimeException("not implemented");
}
@Override
- public void glUniform2fv(int location, int count, FloatBuffer v) {
- // FIXME
- throw new GdxRuntimeException("not implemented");
+ public void glUniform2fv (int location, int count, FloatBuffer v) {
+ // FIXME
+ throw new GdxRuntimeException("not implemented");
}
@Override
- public void glUniform2i(int location, int x, int y) {
- // FIXME
- throw new GdxRuntimeException("not implemented");
+ public void glUniform2i (int location, int x, int y) {
+ // FIXME
+ throw new GdxRuntimeException("not implemented");
}
@Override
- public void glUniform2iv(int location, int count, IntBuffer v) {
- // FIXME
- throw new GdxRuntimeException("not implemented");
+ public void glUniform2iv (int location, int count, IntBuffer v) {
+ // FIXME
+ throw new GdxRuntimeException("not implemented");
}
@Override
- public void glUniform3f(int location, float x, float y, float z) {
- // FIXME
- throw new GdxRuntimeException("not implemented");
+ public void glUniform3f (int location, float x, float y, float z) {
+ // FIXME
+ throw new GdxRuntimeException("not implemented");
}
@Override
- public void glUniform3fv(int location, int count, FloatBuffer v) {
- // FIXME
- throw new GdxRuntimeException("not implemented");
+ public void glUniform3fv (int location, int count, FloatBuffer v) {
+ // FIXME
+ throw new GdxRuntimeException("not implemented");
}
@Override
- public void glUniform3i(int location, int x, int y, int z) {
- // FIXME
- throw new GdxRuntimeException("not implemented");
+ public void glUniform3i (int location, int x, int y, int z) {
+ // FIXME
+ throw new GdxRuntimeException("not implemented");
}
@Override
- public void glUniform3iv(int location, int count, IntBuffer v) {
- // FIXME
- throw new GdxRuntimeException("not implemented");
+ public void glUniform3iv (int location, int count, IntBuffer v) {
+ // FIXME
+ throw new GdxRuntimeException("not implemented");
}
@Override
- public void glUniform4f(int location, float x, float y, float z, float w) {
- // FIXME
- throw new GdxRuntimeException("not implemented");
+ public void glUniform4f (int location, float x, float y, float z, float w) {
+ // FIXME
+ throw new GdxRuntimeException("not implemented");
}
@Override
- public void glUniform4fv(int location, int count, FloatBuffer v) {
- // FIXME
- throw new GdxRuntimeException("not implemented");
+ public void glUniform4fv (int location, int count, FloatBuffer v) {
+ // FIXME
+ throw new GdxRuntimeException("not implemented");
}
@Override
- public void glUniform4i(int location, int x, int y, int z, int w) {
- // FIXME
- throw new GdxRuntimeException("not implemented");
+ public void glUniform4i (int location, int x, int y, int z, int w) {
+ // FIXME
+ throw new GdxRuntimeException("not implemented");
}
@Override
- public void glUniform4iv(int location, int count, IntBuffer v) {
- // FIXME
- throw new GdxRuntimeException("not implemented");
+ public void glUniform4iv (int location, int count, IntBuffer v) {
+ // FIXME
+ throw new GdxRuntimeException("not implemented");
}
@Override
- public void glUniformMatrix2fv(int location, int count, boolean transpose,
- FloatBuffer value) {
- // FIXME
- throw new GdxRuntimeException("not implemented");
+ public void glUniformMatrix2fv (int location, int count, boolean transpose, FloatBuffer value) {
+ // FIXME
+ throw new GdxRuntimeException("not implemented");
}
@Override
- public void glUniformMatrix3fv(int location, int count, boolean transpose,
- FloatBuffer value) {
- // FIXME
- throw new GdxRuntimeException("not implemented");
+ public void glUniformMatrix3fv (int location, int count, boolean transpose, FloatBuffer value) {
+ // FIXME
+ throw new GdxRuntimeException("not implemented");
}
@Override
- public void glUniformMatrix4fv(int location, int count, boolean transpose,
- FloatBuffer value) {
- // FIXME
- throw new GdxRuntimeException("not implemented");
+ public void glUniformMatrix4fv (int location, int count, boolean transpose, FloatBuffer value) {
+ // FIXME
+ throw new GdxRuntimeException("not implemented");
}
@Override
- public void glUseProgram(int program) {
- // FIXME
- throw new GdxRuntimeException("not implemented");
+ public void glUseProgram (int program) {
+ // FIXME
+ throw new GdxRuntimeException("not implemented");
}
@Override
- public void glValidateProgram(int program) {
- // FIXME
- throw new GdxRuntimeException("not implemented");
+ public void glValidateProgram (int program) {
+ // FIXME
+ throw new GdxRuntimeException("not implemented");
}
@Override
- public void glVertexAttrib1f(int indx, float x) {
- // FIXME
- throw new GdxRuntimeException("not implemented");
+ public void glVertexAttrib1f (int indx, float x) {
+ // FIXME
+ throw new GdxRuntimeException("not implemented");
}
@Override
- public void glVertexAttrib1fv(int indx, FloatBuffer values) {
- // FIXME
- throw new GdxRuntimeException("not implemented");
+ public void glVertexAttrib1fv (int indx, FloatBuffer values) {
+ // FIXME
+ throw new GdxRuntimeException("not implemented");
}
@Override
- public void glVertexAttrib2f(int indx, float x, float y) {
- // FIXME
- throw new GdxRuntimeException("not implemented");
+ public void glVertexAttrib2f (int indx, float x, float y) {
+ // FIXME
+ throw new GdxRuntimeException("not implemented");
}
@Override
- public void glVertexAttrib2fv(int indx, FloatBuffer values) {
- // FIXME
- throw new GdxRuntimeException("not implemented");
+ public void glVertexAttrib2fv (int indx, FloatBuffer values) {
+ // FIXME
+ throw new GdxRuntimeException("not implemented");
}
@Override
- public void glVertexAttrib3f(int indx, float x, float y, float z) {
- // FIXME
- throw new GdxRuntimeException("not implemented");
+ public void glVertexAttrib3f (int indx, float x, float y, float z) {
+ // FIXME
+ throw new GdxRuntimeException("not implemented");
}
@Override
- public void glVertexAttrib3fv(int indx, FloatBuffer values) {
- // FIXME
- throw new GdxRuntimeException("not implemented");
+ public void glVertexAttrib3fv (int indx, FloatBuffer values) {
+ // FIXME
+ throw new GdxRuntimeException("not implemented");
}
@Override
- public void glVertexAttrib4f(int indx, float x, float y, float z, float w) {
- // FIXME
- throw new GdxRuntimeException("not implemented");
+ public void glVertexAttrib4f (int indx, float x, float y, float z, float w) {
+ // FIXME
+ throw new GdxRuntimeException("not implemented");
}
@Override
- public void glVertexAttrib4fv(int indx, FloatBuffer values) {
- // FIXME
- throw new GdxRuntimeException("not implemented");
+ public void glVertexAttrib4fv (int indx, FloatBuffer values) {
+ // FIXME
+ throw new GdxRuntimeException("not implemented");
}
@Override
- public void glVertexAttribPointer(int indx, int size, int type,
- boolean normalized, int stride, Buffer ptr) {
- throw new GdxRuntimeException("not implemented");
+ public void glVertexAttribPointer (int indx, int size, int type, boolean normalized, int stride, Buffer ptr) {
+ throw new GdxRuntimeException("not implemented");
}
@Override
- public void glVertexAttribPointer(int indx, int size, int type,
- boolean normalized, int stride, int ptr) {
- // FIXME
+ public void glVertexAttribPointer (int indx, int size, int type, boolean normalized, int stride, int ptr) {
+ // FIXME
throw new GdxRuntimeException("not implemented");
}
}
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 678dd71ad71..c44c0aa39a3 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
@@ -1,3 +1,4 @@
+
package com.badlogic.gdx.backends.gwt;
import gwt.g3d.client.Surface3D;
@@ -22,163 +23,163 @@ public class GwtGraphics implements Graphics {
float fps = 0;
long lastTimeStamp = System.currentTimeMillis();
float deltaTime = 0;
-
- public GwtGraphics(Panel root, GwtApplicationConfiguration config) {
+
+ public GwtGraphics (Panel root, GwtApplicationConfiguration config) {
// create surface per configuration
WebGLContextAttributes contextAttribs = new WebGLContextAttributes();
contextAttribs.setStencilEnable(config.stencil);
contextAttribs.setAntialiasEnable(config.antialiasing);
surface = new Surface3D(config.width, config.height, contextAttribs);
root.add(surface);
-
+
// check whether WebGL is supported
GL2 gl = surface.getGL();
if (gl == null) {
throw new GdxRuntimeException("WebGL not supported");
}
-
+
this.gl = new GwtGL20(surface);
-
+
// set initial viewport to cover entire surface and
- gl.viewport(0, 0, surface.getWidth(), surface.getHeight());
+ gl.viewport(0, 0, surface.getWidth(), surface.getHeight());
}
-
- public Surface3D getSurface() {
+
+ public Surface3D getSurface () {
return surface;
}
-
+
@Override
- public boolean isGL11Available() {
+ public boolean isGL11Available () {
return false;
}
@Override
- public boolean isGL20Available() {
+ public boolean isGL20Available () {
return true;
}
@Override
- public GLCommon getGLCommon() {
+ public GLCommon getGLCommon () {
return gl;
}
@Override
- public GL10 getGL10() {
+ public GL10 getGL10 () {
return null;
}
@Override
- public GL11 getGL11() {
+ public GL11 getGL11 () {
return null;
}
@Override
- public GL20 getGL20() {
+ public GL20 getGL20 () {
return gl;
}
@Override
- public GLU getGLU() {
+ public GLU getGLU () {
return null;
}
@Override
- public int getWidth() {
+ public int getWidth () {
return surface.getWidth();
}
@Override
- public int getHeight() {
+ public int getHeight () {
return surface.getHeight();
}
@Override
- public float getDeltaTime() {
+ public float getDeltaTime () {
return deltaTime;
}
@Override
- public int getFramesPerSecond() {
+ public int getFramesPerSecond () {
return (int)fps;
}
@Override
- public GraphicsType getType() {
+ public GraphicsType getType () {
return GraphicsType.WebGL;
}
@Override
- public float getPpiX() {
+ public float getPpiX () {
return 0;
}
@Override
- public float getPpiY() {
+ public float getPpiY () {
return 0;
}
@Override
- public float getPpcX() {
+ public float getPpcX () {
return 0;
}
@Override
- public float getPpcY() {
+ public float getPpcY () {
return 0;
}
@Override
- public boolean supportsDisplayModeChange() {
+ public boolean supportsDisplayModeChange () {
return false;
}
@Override
- public DisplayMode[] getDisplayModes() {
+ public DisplayMode[] getDisplayModes () {
return null;
}
@Override
- public DisplayMode getDesktopDisplayMode() {
+ public DisplayMode getDesktopDisplayMode () {
return null;
}
@Override
- public boolean setDisplayMode(DisplayMode displayMode) {
+ public boolean setDisplayMode (DisplayMode displayMode) {
return false;
}
@Override
- public boolean setDisplayMode(int width, int height, boolean fullscreen) {
+ public boolean setDisplayMode (int width, int height, boolean fullscreen) {
return false;
}
@Override
- public void setTitle(String title) {
-
+ public void setTitle (String title) {
+
}
@Override
- public void setIcon(Pixmap pixmap) {
-
+ public void setIcon (Pixmap pixmap) {
+
}
@Override
- public void setVSync(boolean vsync) {
-
+ public void setVSync (boolean vsync) {
+
}
@Override
- public BufferFormat getBufferFormat() {
+ public BufferFormat getBufferFormat () {
return null;
}
@Override
- public boolean supportsExtension(String extension) {
- if(extensions == null) extensions = Gdx.gl.glGetString(GL10.GL_EXTENSIONS);
+ public boolean supportsExtension (String extension) {
+ if (extensions == null) extensions = Gdx.gl.glGetString(GL10.GL_EXTENSIONS);
return extensions.contains(extension);
}
- public void setFps(float fps) {
+ public void setFps (float fps) {
long currTimeStamp = System.currentTimeMillis();
deltaTime = (currTimeStamp - lastTimeStamp) / 1000.0f;
lastTimeStamp = currTimeStamp;
@@ -186,7 +187,7 @@ public void setFps(float fps) {
}
@Override
- public float getDensity() {
+ public float getDensity () {
throw new GdxRuntimeException("No supported");
}
}
diff --git a/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/PlainTest.java b/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/PlainTest.java
index 709900ce1a2..e1e4e9ff6d2 100644
--- a/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/PlainTest.java
+++ b/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/PlainTest.java
@@ -1,3 +1,4 @@
+
package com.badlogic.gdx.backends.gwt;
import gwt.g2d.client.util.FpsTimer;
@@ -6,14 +7,11 @@
import gwt.g3d.client.gl2.WebGLContextAttributes;
import gwt.g3d.client.gl2.enums.ClearBufferMask;
-import com.google.gwt.core.client.EntryPoint;
-import com.google.gwt.user.client.ui.RootPanel;
-
public class PlainTest implements EntryPoint {
private Surface3D surface;
@Override
- public void onModuleLoad() {
+ public void onModuleLoad () {
// create surface per configuration
WebGLContextAttributes contextAttribs = new WebGLContextAttributes();
surface = new Surface3D(500, 500, contextAttribs);
@@ -30,11 +28,11 @@ public void onModuleLoad() {
setupLoop();
}
- private void setupLoop() {
+ private void setupLoop () {
// setup rendering timer
FpsTimer timer = new FpsTimer(60) {
@Override
- public void update() {
+ public void update () {
GL2 gl = surface.getGL();
gl.clearColor((float)Math.random(), 0, 0, 1);
gl.clear(ClearBufferMask.COLOR_BUFFER_BIT);
diff --git a/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/com/badlogic/gdx/files/FileHandle.java b/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/com/badlogic/gdx/files/FileHandle.java
index 928a8769acb..4e9c31e3729 100644
--- a/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/com/badlogic/gdx/files/FileHandle.java
+++ b/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/com/badlogic/gdx/files/FileHandle.java
@@ -1,3 +1,4 @@
+
package com.badlogic.gdx.files;
public class FileHandle {
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 c8d2aca490d..14323af3b3f 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
@@ -1,3 +1,4 @@
+
package com.badlogic.gdx.graphics;
import com.badlogic.gdx.utils.Disposable;
@@ -5,6 +6,6 @@
public class Pixmap implements Disposable {
@Override
- public void dispose() {
+ public void dispose () {
}
}
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 5196c465ddf..4a177928d2e 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
@@ -1,3 +1,4 @@
+
package com.badlogic.gdx.graphics;
import com.badlogic.gdx.utils.Disposable;
@@ -5,6 +6,6 @@
public class Texture implements Disposable {
@Override
- public void dispose() {
+ public void dispose () {
}
}
diff --git a/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/com/badlogic/gdx/utils/NumberUtils.java b/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/com/badlogic/gdx/utils/NumberUtils.java
index 2c58fc8acaf..5682f430409 100644
--- a/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/com/badlogic/gdx/utils/NumberUtils.java
+++ b/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/com/badlogic/gdx/utils/NumberUtils.java
@@ -1,27 +1,28 @@
+
package com.badlogic.gdx.utils;
import com.google.gwt.corp.compatibility.CompatibilityImpl;
public class NumberUtils {
static CompatibilityImpl impl = new CompatibilityImpl();
-
- public static int floatToIntBits(float value) {
+
+ public static int floatToIntBits (float value) {
return impl.floatToIntBits(value);
}
-
- public static int floatToRawIntBits(float value) {
+
+ public static int floatToRawIntBits (float value) {
return impl.floatToIntBits(value);
}
-
- public static float intBitsToFloat(int value) {
+
+ public static float intBitsToFloat (int value) {
return impl.intBitsToFloat(value);
}
-
- public static long doubleToLongBits(double value) {
+
+ public static long doubleToLongBits (double value) {
return 0; // FIXME
}
-
- public static double longBitsToDouble(long value) {
+
+ public static double longBitsToDouble (long value) {
return 0; // FIXME
}
}
diff --git a/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/com/google/gwt/corp/compatibility/Compatibility.java b/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/com/google/gwt/corp/compatibility/Compatibility.java
index 656a6ba1f29..7a2312d38e8 100644
--- a/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/com/google/gwt/corp/compatibility/Compatibility.java
+++ b/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/com/google/gwt/corp/compatibility/Compatibility.java
@@ -18,90 +18,96 @@ of the License, or (at your option) any later version.
*/
/* Modifications
- Copyright 2003-2004 Bytonic Software
- Copyright 2010 Google Inc.
-*/
+ Copyright 2003-2004 Bytonic Software
+ Copyright 2010 Google Inc.
+ */
+
package com.google.gwt.corp.compatibility;
import java.io.UnsupportedEncodingException;
public class Compatibility {
public interface Impl {
- int floatToIntBits(float f);
- float intBitsToFloat(int i);
- String createString(byte[] b, int ofs, int length);
- String getOriginatingServerAddress();
- void printStackTrace(Throwable e);
- String createString(byte[] b, String encoding);
- void sleep(int i);
+ int floatToIntBits (float f);
+
+ float intBitsToFloat (int i);
+
+ String createString (byte[] b, int ofs, int length);
+
+ String getOriginatingServerAddress ();
+
+ void printStackTrace (Throwable e);
+
+ String createString (byte[] b, String encoding);
+
+ void sleep (int i);
}
-
+
public static Impl impl;
-
- public static int floatToIntBits(float f) {
+
+ public static int floatToIntBits (float f) {
return impl.floatToIntBits(f);
}
-
- public static float intBitsToFloat(int i) {
+
+ public static float intBitsToFloat (int i) {
return impl.intBitsToFloat(i);
}
- public static String newString(byte[] b) {
+ public static String newString (byte[] b) {
return impl.createString(b, 0, b.length);
}
-
- public static String newString(byte[] b, int s, int l) {
+
+ public static String newString (byte[] b, int s, int l) {
return impl.createString(b, s, l);
}
-
- public static String newString(byte[] b, String encoding) throws UnsupportedEncodingException {
+
+ public static String newString (byte[] b, String encoding) throws UnsupportedEncodingException {
return impl.createString(b, encoding);
}
-
- public static String getOriginatingServerAddress() {
+
+ public static String getOriginatingServerAddress () {
return impl.getOriginatingServerAddress();
}
- public static void printStackTrace(Throwable e) {
+ public static void printStackTrace (Throwable e) {
impl.printStackTrace(e);
}
- public static void sleep(int i) {
- impl.sleep(i);
+ public static void sleep (int i) {
+ impl.sleep(i);
}
- public static String bytesToString(byte[] data, int len) {
+ public static String bytesToString (byte[] data, int len) {
char[] chars = new char[len];
for (int i = 0; i < len; i++) {
- chars[i] = (char) data[i];
+ chars[i] = (char)data[i];
}
return new String(chars);
}
-
- public static int stringToBytes(String s, byte[] data) {
+
+ public static int stringToBytes (String s, byte[] data) {
int len = s.length();
for (int i = 0; i < len; i++) {
- data[i] = (byte) s.charAt(i);
+ data[i] = (byte)s.charAt(i);
}
return len;
}
-
- public static String bytesToHex(byte[] data, int len) {
- char[] hex = new char[len * 2];
- for (int i = 0; i < len; i++) {
- int di = data[i];
- hex[i << 1] = Character.forDigit((di >> 4) & 15, 16);
- hex[(i << 1) + 1] = Character.forDigit(di & 15, 16);
- }
- return new String(hex);
- }
-
- public static int hexToBytes(String hex, byte[] data) {
- int len = hex.length();
- for (int i = 0; i < len; i +=2) {
- data[i >> 1] = (byte) ((Character.digit(hex.charAt(i), 16) << 4) |
- Character.digit(hex.charAt(i + 1), 16));
- }
- return len / 2;
- }
+
+ public static String bytesToHex (byte[] data, int len) {
+ char[] hex = new char[len * 2];
+ for (int i = 0; i < len; i++) {
+ int di = data[i];
+ hex[i << 1] = Character.forDigit((di >> 4) & 15, 16);
+ hex[(i << 1) + 1] = Character.forDigit(di & 15, 16);
+ }
+ return new String(hex);
+ }
+
+ public static int hexToBytes (String hex, byte[] data) {
+ int len = hex.length();
+ for (int i = 0; i < len; i += 2) {
+ data[i >> 1] = (byte)((Character.digit(hex.charAt(i), 16) << 4) | Character.digit(hex.charAt(i + 1), 16));
+ }
+ return len / 2;
+ }
}
diff --git a/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/com/google/gwt/corp/compatibility/CompatibilityImpl.java b/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/com/google/gwt/corp/compatibility/CompatibilityImpl.java
index e96640499bc..a99a0a30fa3 100644
--- a/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/com/google/gwt/corp/compatibility/CompatibilityImpl.java
+++ b/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/com/google/gwt/corp/compatibility/CompatibilityImpl.java
@@ -15,67 +15,66 @@ of the License, or (at your option) any later version.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-*/
-package com.google.gwt.corp.compatibility;
+ */
+package com.google.gwt.corp.compatibility;
public class CompatibilityImpl implements Compatibility.Impl {
- public CompatibilityImpl() {
+ public CompatibilityImpl () {
ConsolePrintStream cps;
cps = new ConsolePrintStream();
System.setOut(cps);
System.setErr(cps);
-
+
System.out.println("Test for System.out.println()");
new Throwable("Exception test").printStackTrace();
System.out.println("Did the exception test appear above?");
-
+
}
-
- public int floatToIntBits(float f) {
+
+ public int floatToIntBits (float f) {
return Numbers.floatToIntBits(f);
}
- public float intBitsToFloat(int i) {
+ public float intBitsToFloat (int i) {
return Numbers.intBitsToFloat(i);
}
- public String createString(byte[] b, int ofs, int length) {
+ public String createString (byte[] b, int ofs, int length) {
StringBuffer sb = new StringBuffer(length);
for (int i = 0; i < length; i++) {
- sb.append((char) b[ofs + i]);
+ sb.append((char)b[ofs + i]);
}
return sb.toString();
}
-
- public String getOriginatingServerAddress() {
-// String moduleUrl = GWT.getModuleBaseURL();
-// return getDomain(moduleUrl);// + ":" + getServerPort();
+ public String getOriginatingServerAddress () {
+// String moduleUrl = GWT.getModuleBaseURL();
+// return getDomain(moduleUrl);// + ":" + getServerPort();
return getServerAddress();
}
- private static native String getServerAddress() /*-{
- if ($wnd.__serverAddress) {
- return $wnd.__serverAddress;
- }
- return "127.0.0.1";
- }-*/;
+ private static native String getServerAddress () /*-{
+ if ($wnd.__serverAddress) {
+ return $wnd.__serverAddress;
+ }
+ return "127.0.0.1";
+ }-*/;
- public void printStackTrace(Throwable e) {
+ public void printStackTrace (Throwable e) {
System.out.println("" + e);
- for (StackTraceElement ste : e.getStackTrace()) {
- System.out.println(" at " + ste);
- }
+ for (StackTraceElement ste : e.getStackTrace()) {
+ System.out.println(" at " + ste);
+ }
}
- public String createString(byte[] b, String encoding) {
+ public String createString (byte[] b, String encoding) {
return createString(b, 0, b.length);
}
- public void sleep(int i) {
+ public void sleep (int i) {
// TODO Auto-generated method stub
-
+
}
}
diff --git a/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/com/google/gwt/corp/compatibility/ConsolePrintStream.java b/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/com/google/gwt/corp/compatibility/ConsolePrintStream.java
index eff8ba28762..8055a4d65d8 100644
--- a/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/com/google/gwt/corp/compatibility/ConsolePrintStream.java
+++ b/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/com/google/gwt/corp/compatibility/ConsolePrintStream.java
@@ -13,60 +13,59 @@
* License for the specific language governing permissions and limitations under
* the License.
*/
+
package com.google.gwt.corp.compatibility;
import java.io.OutputStream;
import java.io.PrintStream;
-/**
- * Print stream for GWT that prints to the browser console.
+/** Print stream for GWT that prints to the browser console.
*
- * @author Stefan Haustein
- */
+ * @author Stefan Haustein */
public class ConsolePrintStream extends PrintStream {
-
+
StringBuilder buf = new StringBuilder();
-
- public ConsolePrintStream() {
- super((OutputStream) null);
+
+ public ConsolePrintStream () {
+ super((OutputStream)null);
}
-
- public void print(String s) {
-
- while(true) {
+
+ public void print (String s) {
+
+ while (true) {
int cut = s.indexOf('\n');
- if(cut == -1) {
+ if (cut == -1) {
break;
}
println(s.substring(0, cut));
s = s.substring(cut + 1);
}
-
+
buf.append(s);
}
-
- public native void consoleLog(String msg) /*-{
- if (window.console) {
- window.console.log(msg);
- } else {
- document.title = "LOG:" + msg;
- }
- }-*/;
- public void print(char c) {
+ public native void consoleLog (String msg) /*-{
+ if (window.console) {
+ window.console.log(msg);
+ } else {
+ document.title = "LOG:" + msg;
+ }
+ }-*/;
+
+ public void print (char c) {
if (c == '\n') {
println("");
} else {
buf.append(c);
}
}
-
- public void println() {
+
+ public void println () {
println("");
}
-
+
@Override
- public void println(String s) {
+ public void println (String s) {
buf.append(s);
consoleLog(buf.toString());
buf.setLength(0);
diff --git a/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/com/google/gwt/corp/compatibility/Endianness.java b/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/com/google/gwt/corp/compatibility/Endianness.java
index ed8d49ef770..d4a15894290 100644
--- a/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/com/google/gwt/corp/compatibility/Endianness.java
+++ b/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/com/google/gwt/corp/compatibility/Endianness.java
@@ -18,5 +18,5 @@
package com.google.gwt.corp.compatibility;
public enum Endianness {
- BIG_ENDIAN, LITTLE_ENDIAN
+ BIG_ENDIAN, LITTLE_ENDIAN
}
diff --git a/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/com/google/gwt/corp/compatibility/Numbers.java b/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/com/google/gwt/corp/compatibility/Numbers.java
index ea63e7107c4..b9a6e89df91 100644
--- a/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/com/google/gwt/corp/compatibility/Numbers.java
+++ b/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/com/google/gwt/corp/compatibility/Numbers.java
@@ -13,6 +13,7 @@
* License for the specific language governing permissions and limitations under
* the License.
*/
+
package com.google.gwt.corp.compatibility;
import gwt.g3d.client.gl2.array.Float32Array;
@@ -20,89 +21,87 @@
import gwt.g3d.client.gl2.array.Int8Array;
public class Numbers {
-
- static final double LN2 = Math.log(2);
-
- public static final int floatToIntBits(float f) {
- wfa.set(0, f);
- return wia.get(0);
-
-// if (Float.isNaN(f)) {
-// return 0x7f800001;
-// }
-// int signBit;
-// if (f == 0) {
-// return (1/f == Float.NEGATIVE_INFINITY) ? 0x80000000 : 0;
-// } else if (f < 0) {
-// f = -f;
-// signBit = 0x80000000;
-// } else {
-// signBit = 0;
-// }
-// if (f == Float.POSITIVE_INFINITY) {
-// return signBit | 0x7f800000;
-// }
-//
-// int exponent = (int) (Math.log(f) / LN2);
-// if (exponent < -126) {
-// exponent = -126;
-// }
-// int significand = (int) (0.5 + f * Math.exp(-(exponent - 23) * LN2));
-//
-// // Handle exponent rounding issues & denorm
-// if ((significand & 0x01000000) != 0) {
-// significand >>= 1;
-// exponent++;
-// } else if ((significand & 0x00800000) == 0) {
-// if (exponent == -126) {
-// return signBit | significand;
-// } else {
-// significand <<= 1;
-// exponent--;
-// }
-// }
-//
-// return signBit | ((exponent + 127) << 23) | (significand & 0x007fffff);
- }
-
- static Int8Array wba = Int8Array.create(4);
- static Int32Array wia = Int32Array.create(wba.getBuffer(), 0, 1);
- static Float32Array wfa = Float32Array.create(wba.getBuffer(), 0, 1);
-
- public static final float intBitsToFloat(int i) {
-// wba.set(0, (byte) (i >> 24));
-// wba.set(1, (byte) (i >> 16));
-// wba.set(2, (byte) (i >> 8));
-// wba.set(3, (byte) (i));
- wia.set(0, i);
- return wfa.get(0);
-//
-//
-// int exponent = (i >>> 23) & 255;
-// int significand = i & 0x007fffff;
-// float result;
-// if (exponent == 0) {
-// result = (float) (Math.exp((-126 - 23) * LN2) * significand);
-// } else if (exponent == 255) {
-// result = significand == 0 ? Float.POSITIVE_INFINITY : Float.NaN;
-// } else {
-// result = (float) (Math.exp((exponent - 127 - 23) * LN2) * (0x00800000 | significand));
-// }
-//
-// return (i & 0x80000000) == 0 ? result : -result;
- }
-
- public static final long doubleToLongBits(Double d) {
- throw new RuntimeException("NYI");
- }
-
- public static final double longBitsToDouble(long l) {
- throw new RuntimeException("NYI");
- }
+ static final double LN2 = Math.log(2);
+
+ public static final int floatToIntBits (float f) {
+ wfa.set(0, f);
+ return wia.get(0);
+
+// if (Float.isNaN(f)) {
+// return 0x7f800001;
+// }
+// int signBit;
+// if (f == 0) {
+// return (1/f == Float.NEGATIVE_INFINITY) ? 0x80000000 : 0;
+// } else if (f < 0) {
+// f = -f;
+// signBit = 0x80000000;
+// } else {
+// signBit = 0;
+// }
+// if (f == Float.POSITIVE_INFINITY) {
+// return signBit | 0x7f800000;
+// }
+//
+// int exponent = (int) (Math.log(f) / LN2);
+// if (exponent < -126) {
+// exponent = -126;
+// }
+// int significand = (int) (0.5 + f * Math.exp(-(exponent - 23) * LN2));
+//
+// // Handle exponent rounding issues & denorm
+// if ((significand & 0x01000000) != 0) {
+// significand >>= 1;
+// exponent++;
+// } else if ((significand & 0x00800000) == 0) {
+// if (exponent == -126) {
+// return signBit | significand;
+// } else {
+// significand <<= 1;
+// exponent--;
+// }
+// }
+//
+// return signBit | ((exponent + 127) << 23) | (significand & 0x007fffff);
+ }
+
+ static Int8Array wba = Int8Array.create(4);
+ static Int32Array wia = Int32Array.create(wba.getBuffer(), 0, 1);
+ static Float32Array wfa = Float32Array.create(wba.getBuffer(), 0, 1);
+
+ public static final float intBitsToFloat (int i) {
+// wba.set(0, (byte) (i >> 24));
+// wba.set(1, (byte) (i >> 16));
+// wba.set(2, (byte) (i >> 8));
+// wba.set(3, (byte) (i));
+ wia.set(0, i);
+ return wfa.get(0);
+//
+//
+// int exponent = (i >>> 23) & 255;
+// int significand = i & 0x007fffff;
+// float result;
+// if (exponent == 0) {
+// result = (float) (Math.exp((-126 - 23) * LN2) * significand);
+// } else if (exponent == 255) {
+// result = significand == 0 ? Float.POSITIVE_INFINITY : Float.NaN;
+// } else {
+// result = (float) (Math.exp((exponent - 127 - 23) * LN2) * (0x00800000 | significand));
+// }
+//
+// return (i & 0x80000000) == 0 ? result : -result;
+ }
+
+ public static final long doubleToLongBits (Double d) {
+ throw new RuntimeException("NYI");
+ }
+ public static final double longBitsToDouble (long l) {
+ throw new RuntimeException("NYI");
+ }
- public static long doubleToRawLongBits(double value) {
- throw new RuntimeException("NYI: Numbers.doubleToRawLongBits");
- }
+ public static long doubleToRawLongBits (double value) {
+ throw new RuntimeException("NYI: Numbers.doubleToRawLongBits");
+ }
}
diff --git a/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/com/google/gwt/corp/compatibility/StringToByteBuffer.java b/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/com/google/gwt/corp/compatibility/StringToByteBuffer.java
index 81ba3d50754..7ecaec653d2 100644
--- a/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/com/google/gwt/corp/compatibility/StringToByteBuffer.java
+++ b/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/com/google/gwt/corp/compatibility/StringToByteBuffer.java
@@ -18,9 +18,10 @@ of the License, or (at your option) any later version.
*/
/* Modifications
- Copyright 2003-2004 Bytonic Software
- Copyright 2010 Google Inc.
-*/
+ Copyright 2003-2004 Bytonic Software
+ Copyright 2010 Google Inc.
+ */
+
package com.google.gwt.corp.compatibility;
import java.nio.ByteBuffer;
@@ -28,5 +29,5 @@ of the License, or (at your option) any later version.
/** Ugly hack to get gwt internal stuff into nio, see StringByteBuffer in nio */
public interface StringToByteBuffer {
- ByteBuffer stringToByteBuffer(String s);
+ ByteBuffer stringToByteBuffer (String s);
}
diff --git a/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/java/nio/BaseByteBuffer.java b/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/java/nio/BaseByteBuffer.java
index 3b120f73021..9c78c2a6d8c 100644
--- a/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/java/nio/BaseByteBuffer.java
+++ b/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/java/nio/BaseByteBuffer.java
@@ -16,61 +16,56 @@
package java.nio;
-
-/**
- * Serves as the root of other byte buffer impl classes, implements common
- * methods that can be shared by child classes.
- *
- */
+/** Serves as the root of other byte buffer impl classes, implements common methods that can be shared by child classes. */
abstract class BaseByteBuffer extends ByteBuffer {
- protected BaseByteBuffer(int capacity) {
- super(capacity);
- }
+ protected BaseByteBuffer (int capacity) {
+ super(capacity);
+ }
+
+ @Override
+ public CharBuffer asCharBuffer () {
+ return CharToByteBufferAdapter.wrap(this);
+ }
+
+ @Override
+ public DoubleBuffer asDoubleBuffer () {
+ return DoubleToByteBufferAdapter.wrap(this);
+ }
+
+ @Override
+ public FloatBuffer asFloatBuffer () {
+ return FloatToByteBufferAdapter.wrap(this);
+ }
+
+ @Override
+ public IntBuffer asIntBuffer () {
+ return IntToByteBufferAdapter.wrap(this);
+ }
+
+ @Override
+ public LongBuffer asLongBuffer () {
+ return LongToByteBufferAdapter.wrap(this);
+ }
+
+ @Override
+ public ShortBuffer asShortBuffer () {
+ return ShortToByteBufferAdapter.wrap(this);
+ }
- @Override
- public CharBuffer asCharBuffer() {
- return CharToByteBufferAdapter.wrap(this);
- }
-
- @Override
- public DoubleBuffer asDoubleBuffer() {
- return DoubleToByteBufferAdapter.wrap(this);
- }
-
- @Override
- public FloatBuffer asFloatBuffer() {
- return FloatToByteBufferAdapter.wrap(this);
- }
-
- @Override
- public IntBuffer asIntBuffer() {
- return IntToByteBufferAdapter.wrap(this);
- }
-
- @Override
- public LongBuffer asLongBuffer() {
- return LongToByteBufferAdapter.wrap(this);
- }
-
- @Override
- public ShortBuffer asShortBuffer() {
- return ShortToByteBufferAdapter.wrap(this);
- }
-
- public final char getChar() {
- return (char) getShort();
- }
+ public final char getChar () {
+ return (char)getShort();
+ }
- public final char getChar(int index) {
- return (char) getShort(index);
- }
+ public final char getChar (int index) {
+ return (char)getShort(index);
+ }
- public final ByteBuffer putChar(char value) {
- return putShort((short) value);
- }
+ public final ByteBuffer putChar (char value) {
+ return putShort((short)value);
+ }
- public final ByteBuffer putChar(int index, char value) {
- return putShort(index, (short) value);
- }
+ public final ByteBuffer putChar (int index, char value) {
+ return putShort(index, (short)value);
+ }
}
diff --git a/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/java/nio/Buffer.java b/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/java/nio/Buffer.java
index 96b59e8387a..9e36157fa50 100644
--- a/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/java/nio/Buffer.java
+++ b/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/java/nio/Buffer.java
@@ -16,285 +16,217 @@
package java.nio;
-
-/**
- * A buffer is a list of elements of a specific primitive type.
+/** A buffer is a list of elements of a specific primitive type.
*
* A buffer can be described by the following properties:
*
- * Capacity: the number of elements a buffer can hold. Capacity may not be
- * negative and never changes.
- * Position: a cursor of this buffer. Elements are read or written at the
- * position if you do not specify an index explicitly. Position may not be
- * negative and not greater than the limit.
- * Limit: controls the scope of accessible elements. You can only read or
- * write elements from index zero to limit - 1
. Accessing
- * elements out of the scope will cause an exception. Limit may not be negative
- * and not greater than capacity.
- * Mark: used to remember the current position, so that you can reset the
- * position later. Mark may not be negative and no greater than position.
- * A buffer can be read-only or read-write. Trying to modify the elements
- * of a read-only buffer will cause a ReadOnlyBufferException
,
- * while changing the position, limit and mark of a read-only buffer is OK.
- * A buffer can be direct or indirect. A direct buffer will try its best to
- * take advantage of native memory APIs and it may not stay in the Java heap,
- * thus it is not affected by garbage collection.
+ * Capacity: the number of elements a buffer can hold. Capacity may not be negative and never changes.
+ * Position: a cursor of this buffer. Elements are read or written at the position if you do not specify an index explicitly.
+ * Position may not be negative and not greater than the limit.
+ * Limit: controls the scope of accessible elements. You can only read or write elements from index zero to
+ * limit - 1
. Accessing elements out of the scope will cause an exception. Limit may not be negative and not greater
+ * than capacity.
+ * Mark: used to remember the current position, so that you can reset the position later. Mark may not be negative and no
+ * greater than position.
+ * A buffer can be read-only or read-write. Trying to modify the elements of a read-only buffer will cause a
+ * ReadOnlyBufferException
, while changing the position, limit and mark of a read-only buffer is OK.
+ * A buffer can be direct or indirect. A direct buffer will try its best to take advantage of native memory APIs and it may
+ * not stay in the Java heap, thus it is not affected by garbage collection.
*
*
*
- * Buffers are not thread-safe. If concurrent access to a buffer instance is
- * required, then the callers are responsible to take care of the
- * synchronization issues.
+ * Buffers are not thread-safe. If concurrent access to a buffer instance is required, then the callers are responsible to take
+ * care of the synchronization issues.
*
*
- * @since Android 1.0
- */
+ * @since Android 1.0 */
public abstract class Buffer {
- /**
- * UNSET_MARK
means the mark has not been set.
- */
- final static int UNSET_MARK = -1;
-
- /**
- * The capacity of this buffer, which never change.
- */
- final int capacity;
-
- /**
- * limit - 1
is the last element that can be read or written.
- * Limit must be no less than zero and no greater than capacity
.
- */
- int limit;
-
- /**
- * Mark is where position will be set when reset()
is called.
- * Mark is not set by default. Mark is always no less than zero and no
- * greater than position
.
- */
- int mark = UNSET_MARK;
-
- /**
- * The current position of this buffer. Position is always no less than zero
- * and no greater than limit
.
- */
- int position = 0;
-
- /**
- * Construct a buffer with the specified capacity.
- *
- * @param capacity
- * the capacity of this buffer.
- */
- Buffer(int capacity) {
- super();
- if (capacity < 0) {
- throw new IllegalArgumentException();
- }
- this.capacity = this.limit = capacity;
- }
-
- /**
- * Returns the capacity of this buffer.
- *
- * @return the number of elements that are contained in this buffer.
- * @since Android 1.0
- */
- public final int capacity() {
- return capacity;
- }
-
- /**
- * Clears this buffer.
- *
- * While the content of this buffer is not changed, the following internal
- * changes take place: the current position is reset back to the start of
- * the buffer, the value of the buffer limit is made equal to the capacity
- * and mark is cleared.
- *
- *
- * @return this buffer.
- * @since Android 1.0
- */
- public final Buffer clear() {
- position = 0;
- mark = UNSET_MARK;
- limit = capacity;
- return this;
- }
-
- /**
- * Flips this buffer.
- *
- * The limit is set to the current position, then the position is set to
- * zero, and the mark is cleared.
- *
- *
- * The content of this buffer is not changed.
- *
- *
- * @return this buffer.
- * @since Android 1.0
- */
- public final Buffer flip() {
- limit = position;
- position = 0;
- mark = UNSET_MARK;
- return this;
- }
-
- /**
- * Indicates if there are elements remaining in this buffer, that is if
- * {@code position < limit}.
- *
- * @return {@code true} if there are elements remaining in this buffer,
- * {@code false} otherwise.
- * @since Android 1.0
- */
- public final boolean hasRemaining() {
- return position < limit;
- }
-
- /**
- * Indicates whether this buffer is read-only.
- *
- * @return {@code true} if this buffer is read-only, {@code false}
- * otherwise.
- * @since Android 1.0
- */
- public abstract boolean isReadOnly();
-
- /**
- * Returns the limit of this buffer.
- *
- * @return the limit of this buffer.
- * @since Android 1.0
- */
- public final int limit() {
- return limit;
- }
-
- /**
- * Sets the limit of this buffer.
- *
- * If the current position in the buffer is in excess of
- * newLimit
then, on returning from this call, it will have
- * been adjusted to be equivalent to newLimit
. If the mark
- * is set and is greater than the new limit, then it is cleared.
- *
- *
- * @param newLimit
- * the new limit, must not be negative and not greater than
- * capacity.
- * @return this buffer.
- * @exception IllegalArgumentException
- * if newLimit
is invalid.
- * @since Android 1.0
- */
- public final Buffer limit(int newLimit) {
- if (newLimit < 0 || newLimit > capacity) {
- throw new IllegalArgumentException();
- }
-
- limit = newLimit;
- if (position > newLimit) {
- position = newLimit;
- }
- if ((mark != UNSET_MARK) && (mark > newLimit)) {
- mark = UNSET_MARK;
- }
- return this;
- }
-
- /**
- * Marks the current position, so that the position may return to this point
- * later by calling reset()
.
- *
- * @return this buffer.
- * @since Android 1.0
- */
- public final Buffer mark() {
- mark = position;
- return this;
- }
-
- /**
- * Returns the position of this buffer.
- *
- * @return the value of this buffer's current position.
- * @since Android 1.0
- */
- public final int position() {
- return position;
- }
-
- /**
- * Sets the position of this buffer.
- *
- * If the mark is set and it is greater than the new position, then it is
- * cleared.
- *
- *
- * @param newPosition
- * the new position, must be not negative and not greater than
- * limit.
- * @return this buffer.
- * @exception IllegalArgumentException
- * if newPosition
is invalid.
- * @since Android 1.0
- */
- public final Buffer position(int newPosition) {
- if (newPosition < 0 || newPosition > limit) {
- throw new IllegalArgumentException();
- }
-
- position = newPosition;
- if ((mark != UNSET_MARK) && (mark > position)) {
- mark = UNSET_MARK;
- }
- return this;
- }
-
- /**
- * Returns the number of remaining elements in this buffer, that is
- * {@code limit - position}.
- *
- * @return the number of remaining elements in this buffer.
- * @since Android 1.0
- */
- public final int remaining() {
- return limit - position;
- }
-
- /**
- * Resets the position of this buffer to the mark
.
- *
- * @return this buffer.
- * @exception InvalidMarkException
- * if the mark is not set.
- * @since Android 1.0
- */
- public final Buffer reset() {
- if (mark == UNSET_MARK) {
- throw new InvalidMarkException();
- }
- position = mark;
- return this;
- }
-
- /**
- * Rewinds this buffer.
- *
- * The position is set to zero, and the mark is cleared. The content of this
- * buffer is not changed.
- *
- *
- * @return this buffer.
- * @since Android 1.0
- */
- public final Buffer rewind() {
- position = 0;
- mark = UNSET_MARK;
- return this;
- }
+ /** UNSET_MARK
means the mark has not been set. */
+ final static int UNSET_MARK = -1;
+
+ /** The capacity of this buffer, which never change. */
+ final int capacity;
+
+ /** limit - 1
is the last element that can be read or written. Limit must be no less than zero and no greater than
+ * capacity
. */
+ int limit;
+
+ /** Mark is where position will be set when reset()
is called. Mark is not set by default. Mark is always no less
+ * than zero and no greater than position
. */
+ int mark = UNSET_MARK;
+
+ /** The current position of this buffer. Position is always no less than zero and no greater than limit
. */
+ int position = 0;
+
+ /** Construct a buffer with the specified capacity.
+ *
+ * @param capacity the capacity of this buffer. */
+ Buffer (int capacity) {
+ super();
+ if (capacity < 0) {
+ throw new IllegalArgumentException();
+ }
+ this.capacity = this.limit = capacity;
+ }
+
+ /** Returns the capacity of this buffer.
+ *
+ * @return the number of elements that are contained in this buffer.
+ * @since Android 1.0 */
+ public final int capacity () {
+ return capacity;
+ }
+
+ /** Clears this buffer.
+ *
+ * While the content of this buffer is not changed, the following internal changes take place: the current position is reset
+ * back to the start of the buffer, the value of the buffer limit is made equal to the capacity and mark is cleared.
+ *
+ *
+ * @return this buffer.
+ * @since Android 1.0 */
+ public final Buffer clear () {
+ position = 0;
+ mark = UNSET_MARK;
+ limit = capacity;
+ return this;
+ }
+
+ /** Flips this buffer.
+ *
+ * The limit is set to the current position, then the position is set to zero, and the mark is cleared.
+ *
+ *
+ * The content of this buffer is not changed.
+ *
+ *
+ * @return this buffer.
+ * @since Android 1.0 */
+ public final Buffer flip () {
+ limit = position;
+ position = 0;
+ mark = UNSET_MARK;
+ return this;
+ }
+
+ /** Indicates if there are elements remaining in this buffer, that is if {@code position < limit}.
+ *
+ * @return {@code true} if there are elements remaining in this buffer, {@code false} otherwise.
+ * @since Android 1.0 */
+ public final boolean hasRemaining () {
+ return position < limit;
+ }
+
+ /** Indicates whether this buffer is read-only.
+ *
+ * @return {@code true} if this buffer is read-only, {@code false} otherwise.
+ * @since Android 1.0 */
+ public abstract boolean isReadOnly ();
+
+ /** Returns the limit of this buffer.
+ *
+ * @return the limit of this buffer.
+ * @since Android 1.0 */
+ public final int limit () {
+ return limit;
+ }
+
+ /** Sets the limit of this buffer.
+ *
+ * If the current position in the buffer is in excess of newLimit
then, on returning from this call, it will have
+ * been adjusted to be equivalent to newLimit
. If the mark is set and is greater than the new limit, then it is
+ * cleared.
+ *
+ *
+ * @param newLimit the new limit, must not be negative and not greater than capacity.
+ * @return this buffer.
+ * @exception IllegalArgumentException if newLimit
is invalid.
+ * @since Android 1.0 */
+ public final Buffer limit (int newLimit) {
+ if (newLimit < 0 || newLimit > capacity) {
+ throw new IllegalArgumentException();
+ }
+
+ limit = newLimit;
+ if (position > newLimit) {
+ position = newLimit;
+ }
+ if ((mark != UNSET_MARK) && (mark > newLimit)) {
+ mark = UNSET_MARK;
+ }
+ return this;
+ }
+
+ /** Marks the current position, so that the position may return to this point later by calling reset()
.
+ *
+ * @return this buffer.
+ * @since Android 1.0 */
+ public final Buffer mark () {
+ mark = position;
+ return this;
+ }
+
+ /** Returns the position of this buffer.
+ *
+ * @return the value of this buffer's current position.
+ * @since Android 1.0 */
+ public final int position () {
+ return position;
+ }
+
+ /** Sets the position of this buffer.
+ *
+ * If the mark is set and it is greater than the new position, then it is cleared.
+ *
+ *
+ * @param newPosition the new position, must be not negative and not greater than limit.
+ * @return this buffer.
+ * @exception IllegalArgumentException if newPosition
is invalid.
+ * @since Android 1.0 */
+ public final Buffer position (int newPosition) {
+ if (newPosition < 0 || newPosition > limit) {
+ throw new IllegalArgumentException();
+ }
+
+ position = newPosition;
+ if ((mark != UNSET_MARK) && (mark > position)) {
+ mark = UNSET_MARK;
+ }
+ return this;
+ }
+
+ /** Returns the number of remaining elements in this buffer, that is {@code limit - position}.
+ *
+ * @return the number of remaining elements in this buffer.
+ * @since Android 1.0 */
+ public final int remaining () {
+ return limit - position;
+ }
+
+ /** Resets the position of this buffer to the mark
.
+ *
+ * @return this buffer.
+ * @exception InvalidMarkException if the mark is not set.
+ * @since Android 1.0 */
+ public final Buffer reset () {
+ if (mark == UNSET_MARK) {
+ throw new InvalidMarkException();
+ }
+ position = mark;
+ return this;
+ }
+
+ /** Rewinds this buffer.
+ *
+ * The position is set to zero, and the mark is cleared. The content of this buffer is not changed.
+ *
+ *
+ * @return this buffer.
+ * @since Android 1.0 */
+ public final Buffer rewind () {
+ position = 0;
+ mark = UNSET_MARK;
+ return this;
+ }
}
diff --git a/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/java/nio/BufferFactory.java b/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/java/nio/BufferFactory.java
index 6db6c1ee80a..8f58ee96961 100644
--- a/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/java/nio/BufferFactory.java
+++ b/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/java/nio/BufferFactory.java
@@ -17,192 +17,139 @@
package java.nio;
-
-/**
- * Provide factory service of buffer classes.
+/** Provide factory service of buffer classes.
*
- * Since all buffer impl classes are package private (except DirectByteBuffer),
- * this factory is the only entrance to access buffer functions from outside of
- * the impl package.
- *
- *
- */
+ * Since all buffer impl classes are package private (except DirectByteBuffer), this factory is the only entrance to access buffer
+ * functions from outside of the impl package.
+ * */
final class BufferFactory {
- /**
- * Returns a new byte buffer based on the specified byte array.
- *
- * @param array
- * The byte array
- * @return A new byte buffer based on the specified byte array.
- */
- public static ByteBuffer newByteBuffer(byte array[]) {
- return new ReadWriteHeapByteBuffer(array);
- }
-
- /**
- * Returns a new array based byte buffer with the specified capacity.
- *
- * @param capacity
- * The capacity of the new buffer
- * @return A new array based byte buffer with the specified capacity.
- */
- public static ByteBuffer newByteBuffer(int capacity) {
- return new ReadWriteHeapByteBuffer(capacity);
- }
-
- /**
- * Returns a new char buffer based on the specified char array.
- *
- * @param array
- * The char array
- * @return A new char buffer based on the specified char array.
- */
- public static CharBuffer newCharBuffer(char array[]) {
- return new ReadWriteCharArrayBuffer(array);
- }
-
- /**
- * Returns a new readonly char buffer based on the specified char sequence.
- *
- * @param chseq
- * The char sequence
- * @return A new readonly char buffer based on the specified char sequence.
- */
- public static CharBuffer newCharBuffer(CharSequence chseq) {
- return new CharSequenceAdapter(chseq);
- }
-
- /**
- * Returns a new array based char buffer with the specified capacity.
- *
- * @param capacity
- * The capacity of the new buffer
- * @return A new array based char buffer with the specified capacity.
- */
- public static CharBuffer newCharBuffer(int capacity) {
- return new ReadWriteCharArrayBuffer(capacity);
- }
-
- /**
- * Returns a new direct byte buffer with the specified capacity.
- *
- * @param capacity
- * The capacity of the new buffer
- * @return A new direct byte buffer with the specified capacity.
- */
- public static ByteBuffer newDirectByteBuffer(int capacity) {
- return new DirectReadWriteByteBuffer(capacity);
- }
-
- /**
- * Returns a new double buffer based on the specified double array.
- *
- * @param array
- * The double array
- * @return A new double buffer based on the specified double array.
- */
- public static DoubleBuffer newDoubleBuffer(double array[]) {
- return new ReadWriteDoubleArrayBuffer(array);
- }
-
- /**
- * Returns a new array based double buffer with the specified capacity.
- *
- * @param capacity
- * The capacity of the new buffer
- * @return A new array based double buffer with the specified capacity.
- */
- public static DoubleBuffer newDoubleBuffer(int capacity) {
- return new ReadWriteDoubleArrayBuffer(capacity);
- }
-
- /**
- * Returns a new float buffer based on the specified float array.
- *
- * @param array
- * The float array
- * @return A new float buffer based on the specified float array.
- */
- public static FloatBuffer newFloatBuffer(float array[]) {
- return new ReadWriteFloatArrayBuffer(array);
- }
-
- /**
- * Returns a new array based float buffer with the specified capacity.
- *
- * @param capacity
- * The capacity of the new buffer
- * @return A new array based float buffer with the specified capacity.
- */
- public static FloatBuffer newFloatBuffer(int capacity) {
- return new ReadWriteFloatArrayBuffer(capacity);
- }
-
- /**
- * Returns a new array based int buffer with the specified capacity.
- *
- * @param capacity
- * The capacity of the new buffer
- * @return A new array based int buffer with the specified capacity.
- */
- public static IntBuffer newIntBuffer(int capacity) {
- return new ReadWriteIntArrayBuffer(capacity);
- }
-
- /**
- * Returns a new int buffer based on the specified int array.
- *
- * @param array
- * The int array
- * @return A new int buffer based on the specified int array.
- */
- public static IntBuffer newIntBuffer(int array[]) {
- return new ReadWriteIntArrayBuffer(array);
- }
-
- /**
- * Returns a new array based long buffer with the specified capacity.
- *
- * @param capacity
- * The capacity of the new buffer
- * @return A new array based long buffer with the specified capacity.
- */
- public static LongBuffer newLongBuffer(int capacity) {
- return new ReadWriteLongArrayBuffer(capacity);
- }
-
- /**
- * Returns a new long buffer based on the specified long array.
- *
- * @param array
- * The long array
- * @return A new long buffer based on the specified long array.
- */
- public static LongBuffer newLongBuffer(long array[]) {
- return new ReadWriteLongArrayBuffer(array);
- }
-
- /**
- * Returns a new array based short buffer with the specified capacity.
- *
- * @param capacity
- * The capacity of the new buffer
- * @return A new array based short buffer with the specified capacity.
- */
- public static ShortBuffer newShortBuffer(int capacity) {
- return new ReadWriteShortArrayBuffer(capacity);
- }
-
- /**
- * Returns a new short buffer based on the specified short array.
- *
- * @param array
- * The short array
- * @return A new short buffer based on the specified short array.
- */
- public static ShortBuffer newShortBuffer(short array[]) {
- return new ReadWriteShortArrayBuffer(array);
- }
+ /** Returns a new byte buffer based on the specified byte array.
+ *
+ * @param array The byte array
+ * @return A new byte buffer based on the specified byte array. */
+ public static ByteBuffer newByteBuffer (byte array[]) {
+ return new ReadWriteHeapByteBuffer(array);
+ }
+
+ /** Returns a new array based byte buffer with the specified capacity.
+ *
+ * @param capacity The capacity of the new buffer
+ * @return A new array based byte buffer with the specified capacity. */
+ public static ByteBuffer newByteBuffer (int capacity) {
+ return new ReadWriteHeapByteBuffer(capacity);
+ }
+
+ /** Returns a new char buffer based on the specified char array.
+ *
+ * @param array The char array
+ * @return A new char buffer based on the specified char array. */
+ public static CharBuffer newCharBuffer (char array[]) {
+ return new ReadWriteCharArrayBuffer(array);
+ }
+
+ /** Returns a new readonly char buffer based on the specified char sequence.
+ *
+ * @param chseq The char sequence
+ * @return A new readonly char buffer based on the specified char sequence. */
+ public static CharBuffer newCharBuffer (CharSequence chseq) {
+ return new CharSequenceAdapter(chseq);
+ }
+
+ /** Returns a new array based char buffer with the specified capacity.
+ *
+ * @param capacity The capacity of the new buffer
+ * @return A new array based char buffer with the specified capacity. */
+ public static CharBuffer newCharBuffer (int capacity) {
+ return new ReadWriteCharArrayBuffer(capacity);
+ }
+
+ /** Returns a new direct byte buffer with the specified capacity.
+ *
+ * @param capacity The capacity of the new buffer
+ * @return A new direct byte buffer with the specified capacity. */
+ public static ByteBuffer newDirectByteBuffer (int capacity) {
+ return new DirectReadWriteByteBuffer(capacity);
+ }
+
+ /** Returns a new double buffer based on the specified double array.
+ *
+ * @param array The double array
+ * @return A new double buffer based on the specified double array. */
+ public static DoubleBuffer newDoubleBuffer (double array[]) {
+ return new ReadWriteDoubleArrayBuffer(array);
+ }
+
+ /** Returns a new array based double buffer with the specified capacity.
+ *
+ * @param capacity The capacity of the new buffer
+ * @return A new array based double buffer with the specified capacity. */
+ public static DoubleBuffer newDoubleBuffer (int capacity) {
+ return new ReadWriteDoubleArrayBuffer(capacity);
+ }
+
+ /** Returns a new float buffer based on the specified float array.
+ *
+ * @param array The float array
+ * @return A new float buffer based on the specified float array. */
+ public static FloatBuffer newFloatBuffer (float array[]) {
+ return new ReadWriteFloatArrayBuffer(array);
+ }
+
+ /** Returns a new array based float buffer with the specified capacity.
+ *
+ * @param capacity The capacity of the new buffer
+ * @return A new array based float buffer with the specified capacity. */
+ public static FloatBuffer newFloatBuffer (int capacity) {
+ return new ReadWriteFloatArrayBuffer(capacity);
+ }
+
+ /** Returns a new array based int buffer with the specified capacity.
+ *
+ * @param capacity The capacity of the new buffer
+ * @return A new array based int buffer with the specified capacity. */
+ public static IntBuffer newIntBuffer (int capacity) {
+ return new ReadWriteIntArrayBuffer(capacity);
+ }
+
+ /** Returns a new int buffer based on the specified int array.
+ *
+ * @param array The int array
+ * @return A new int buffer based on the specified int array. */
+ public static IntBuffer newIntBuffer (int array[]) {
+ return new ReadWriteIntArrayBuffer(array);
+ }
+
+ /** Returns a new array based long buffer with the specified capacity.
+ *
+ * @param capacity The capacity of the new buffer
+ * @return A new array based long buffer with the specified capacity. */
+ public static LongBuffer newLongBuffer (int capacity) {
+ return new ReadWriteLongArrayBuffer(capacity);
+ }
+
+ /** Returns a new long buffer based on the specified long array.
+ *
+ * @param array The long array
+ * @return A new long buffer based on the specified long array. */
+ public static LongBuffer newLongBuffer (long array[]) {
+ return new ReadWriteLongArrayBuffer(array);
+ }
+
+ /** Returns a new array based short buffer with the specified capacity.
+ *
+ * @param capacity The capacity of the new buffer
+ * @return A new array based short buffer with the specified capacity. */
+ public static ShortBuffer newShortBuffer (int capacity) {
+ return new ReadWriteShortArrayBuffer(capacity);
+ }
+
+ /** Returns a new short buffer based on the specified short array.
+ *
+ * @param array The short array
+ * @return A new short buffer based on the specified short array. */
+ public static ShortBuffer newShortBuffer (short array[]) {
+ return new ReadWriteShortArrayBuffer(array);
+ }
}
diff --git a/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/java/nio/BufferOverflowException.java b/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/java/nio/BufferOverflowException.java
index a9ec60d6bc7..923808ec71c 100644
--- a/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/java/nio/BufferOverflowException.java
+++ b/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/java/nio/BufferOverflowException.java
@@ -16,23 +16,18 @@
package java.nio;
-
-/**
- * A BufferOverflowException
is thrown when elements are written
- * to a buffer but there is not enough remaining space in the buffer.
+/** A BufferOverflowException
is thrown when elements are written to a buffer but there is not enough remaining space
+ * in the buffer.
*
- * @since Android 1.0
- */
+ * @since Android 1.0 */
public class BufferOverflowException extends RuntimeException {
- private static final long serialVersionUID = -5484897634319144535L;
+ private static final long serialVersionUID = -5484897634319144535L;
- /**
- * Constructs a BufferOverflowException
.
- *
- * @since Android 1.0
- */
- public BufferOverflowException() {
- super();
- }
+ /** Constructs a BufferOverflowException
.
+ *
+ * @since Android 1.0 */
+ public BufferOverflowException () {
+ super();
+ }
}
diff --git a/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/java/nio/BufferUnderflowException.java b/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/java/nio/BufferUnderflowException.java
index f15a8db0c72..1d3251ee340 100644
--- a/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/java/nio/BufferUnderflowException.java
+++ b/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/java/nio/BufferUnderflowException.java
@@ -16,23 +16,18 @@
package java.nio;
-
-/**
- * A BufferUnderflowException
is thrown when elements are read
- * from a buffer but there are not enough remaining elements in the buffer.
+/** A BufferUnderflowException
is thrown when elements are read from a buffer but there are not enough remaining
+ * elements in the buffer.
*
- * @since Android 1.0
- */
+ * @since Android 1.0 */
public class BufferUnderflowException extends RuntimeException {
- private static final long serialVersionUID = -1713313658691622206L;
+ private static final long serialVersionUID = -1713313658691622206L;
- /**
- * Constructs a BufferUnderflowException
.
- *
- * @since Android 1.0
- */
- public BufferUnderflowException() {
- super();
- }
+ /** Constructs a BufferUnderflowException
.
+ *
+ * @since Android 1.0 */
+ public BufferUnderflowException () {
+ super();
+ }
}
diff --git a/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/java/nio/ByteBuffer.java b/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/java/nio/ByteBuffer.java
index 81277ea0fd2..76a218d63ea 100644
--- a/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/java/nio/ByteBuffer.java
+++ b/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/java/nio/ByteBuffer.java
@@ -20,1157 +20,818 @@
import com.google.gwt.corp.compatibility.Endianness;
import com.google.gwt.corp.compatibility.StringToByteBuffer;
-
-
-/**
- * A buffer for bytes.
+/** A buffer for bytes.
*
* A byte buffer can be created in either one of the following ways:
*
*
- * {@link #allocate(int) Allocate} a new byte array and create a buffer
- * based on it;
- * {@link #allocateDirect(int) Allocate} a memory block and create a direct
- * buffer based on it;
- * {@link #wrap(byte[]) Wrap} an existing byte array to create a new
- * buffer.
+ * {@link #allocate(int) Allocate} a new byte array and create a buffer based on it;
+ * {@link #allocateDirect(int) Allocate} a memory block and create a direct buffer based on it;
+ * {@link #wrap(byte[]) Wrap} an existing byte array to create a new buffer.
*
- * @since Android 1.0
- */
+ * @since Android 1.0 */
public abstract class ByteBuffer extends Buffer implements Comparable, StringToByteBuffer {
-
- /**
- * Creates a byte buffer based on a newly allocated byte array.
- *
- * @param capacity
- * the capacity of the new buffer
- * @return the created byte buffer.
- * @throws IllegalArgumentException
- * if {@code capacity < 0}.
- * @since Android 1.0
- */
- public static ByteBuffer allocate(int capacity) {
- if (capacity < 0) {
- throw new IllegalArgumentException();
- }
- return BufferFactory.newByteBuffer(capacity);
- }
-
- /**
- * Creates a direct byte buffer based on a newly allocated memory block.
- *
- * @param capacity
- * the capacity of the new buffer
- * @return the created byte buffer.
- * @throws IllegalArgumentException
- * if {@code capacity < 0}.
- * @since Android 1.0
- */
- public static ByteBuffer allocateDirect(int capacity) {
- if (capacity < 0) {
- throw new IllegalArgumentException();
- }
- return BufferFactory.newDirectByteBuffer(capacity);
- }
-
- /**
- * Creates a new byte buffer by wrapping the given byte array.
- *
- * Calling this method has the same effect as
- * {@code wrap(array, 0, array.length)}.
- *
- *
- * @param array
- * the byte array which the new buffer will be based on
- * @return the created byte buffer.
- * @since Android 1.0
- */
- public static ByteBuffer wrap(byte[] array) {
- return BufferFactory.newByteBuffer(array);
- }
-
- /**
- * Creates a new byte buffer by wrapping the given byte array.
- *
- * The new buffer's position will be {@code start}, limit will be
- * {@code start + len}, capacity will be the length of the array.
- *
- *
- * @param array
- * the byte array which the new buffer will be based on.
- * @param start
- * the start index, must not be negative and not greater than
- * {@code array.length}.
- * @param len
- * the length, must not be negative and not greater than
- * {@code array.length - start}.
- * @return the created byte buffer.
- * @exception IndexOutOfBoundsException
- * if either {@code start} or {@code len} is invalid.
- * @since Android 1.0
- */
- public static ByteBuffer wrap(byte[] array, int start, int len) {
- int length = array.length;
- if ((start < 0) || (len < 0) || ((long) start + (long) len > length)) {
- throw new IndexOutOfBoundsException();
- }
-
- ByteBuffer buf = BufferFactory.newByteBuffer(array);
- buf.position = start;
- buf.limit = start + len;
-
- return buf;
- }
-
- /**
- * The byte order of this buffer, default is {@code BIG_ENDIAN}.
- */
- Endianness order = Endianness.BIG_ENDIAN;
-
- /**
- * Constructs a {@code ByteBuffer} with given capacity.
- *
- * @param capacity
- * the capacity of the buffer.
- */
- ByteBuffer(int capacity) {
- super(capacity);
- }
-
- /**
- * Returns the byte array which this buffer is based on, if there is one.
- *
- * @return the byte array which this buffer is based on.
- * @exception ReadOnlyBufferException
- * if this buffer is based on a read-only array.
- * @exception UnsupportedOperationException
- * if this buffer is not based on an array.
- * @since Android 1.0
- */
- public final byte[] array() {
- return protectedArray();
- }
-
- /**
- * Returns the offset of the byte array which this buffer is based on, if
- * there is one.
- *
- * The offset is the index of the array which corresponds to the zero
- * position of the buffer.
- *
- *
- * @return the offset of the byte array which this buffer is based on.
- * @exception ReadOnlyBufferException
- * if this buffer is based on a read-only array.
- * @exception UnsupportedOperationException
- * if this buffer is not based on an array.
- * @since Android 1.0
- */
- public final int arrayOffset() {
- return protectedArrayOffset();
- }
-
-
- /**
- * Returns a char buffer which is based on the remaining content of this
- * byte buffer.
- *
- * The new buffer's position is zero, its limit and capacity is the number
- * of remaining bytes divided by two, and its mark is not set. The new
- * buffer's read-only property and byte order are the same as this buffer's.
- * The new buffer is direct if this byte buffer is direct.
- *
- *
- * The new buffer shares its content with this buffer, which means either
- * buffer's change of content will be visible to the other. The two buffer's
- * position, limit and mark are independent.
- *
- *
- * @return a char buffer which is based on the content of this byte buffer.
- * @since Android 1.0
- */
- public abstract CharBuffer asCharBuffer();
-
- /**
- * Returns a double buffer which is based on the remaining content of this
- * byte buffer.
- *
- * The new buffer's position is zero, its limit and capacity is the number
- * of remaining bytes divided by eight, and its mark is not set. The new
- * buffer's read-only property and byte order are the same as this buffer's.
- * The new buffer is direct if this byte buffer is direct.
- *
- *
- * The new buffer shares its content with this buffer, which means either
- * buffer's change of content will be visible to the other. The two buffer's
- * position, limit and mark are independent.
- *
- *
- * @return a double buffer which is based on the content of this byte
- * buffer.
- * @since Android 1.0
- */
- public abstract DoubleBuffer asDoubleBuffer();
-
- /**
- * Returns a float buffer which is based on the remaining content of this
- * byte buffer.
- *
- * The new buffer's position is zero, its limit and capacity is the number
- * of remaining bytes divided by four, and its mark is not set. The new
- * buffer's read-only property and byte order are the same as this buffer's.
- * The new buffer is direct if this byte buffer is direct.
- *
- *
- * The new buffer shares its content with this buffer, which means either
- * buffer's change of content will be visible to the other. The two buffer's
- * position, limit and mark are independent.
- *
- *
- * @return a float buffer which is based on the content of this byte buffer.
- * @since Android 1.0
- */
- public abstract FloatBuffer asFloatBuffer();
-
- /**
- * Returns a int buffer which is based on the remaining content of this byte
- * buffer.
- *
- * The new buffer's position is zero, its limit and capacity is the number
- * of remaining bytes divided by four, and its mark is not set. The new
- * buffer's read-only property and byte order are the same as this buffer's.
- * The new buffer is direct if this byte buffer is direct.
- *
- *
- * The new buffer shares its content with this buffer, which means either
- * buffer's change of content will be visible to the other. The two buffer's
- * position, limit and mark are independent.
- *
- *
- * @return a int buffer which is based on the content of this byte buffer.
- * @since Android 1.0
- */
- public abstract IntBuffer asIntBuffer();
-
- /**
- * Returns a long buffer which is based on the remaining content of this
- * byte buffer.
- *
- * The new buffer's position is zero, its limit and capacity is the number
- * of remaining bytes divided by eight, and its mark is not set. The new
- * buffer's read-only property and byte order are the same as this buffer's.
- * The new buffer is direct if this byte buffer is direct.
- *
- *
- * The new buffer shares its content with this buffer, which means either
- * buffer's change of content will be visible to the other. The two buffer's
- * position, limit and mark are independent.
- *
- *
- * @return a long buffer which is based on the content of this byte buffer.
- * @since Android 1.0
- */
- public abstract LongBuffer asLongBuffer();
-
- /**
- * Returns a read-only buffer that shares its content with this buffer.
- *
- * The returned buffer is guaranteed to be a new instance, even if this
- * buffer is read-only itself. The new buffer's position, limit, capacity
- * and mark are the same as this buffer.
- *
- *
- * The new buffer shares its content with this buffer, which means this
- * buffer's change of content will be visible to the new buffer. The two
- * buffer's position, limit and mark are independent.
- *
- *
- * @return a read-only version of this buffer.
- * @since Android 1.0
- */
- public abstract ByteBuffer asReadOnlyBuffer();
-
- /**
- * Returns a short buffer which is based on the remaining content of this
- * byte buffer.
- *
- * The new buffer's position is zero, its limit and capacity is the number
- * of remaining bytes divided by two, and its mark is not set. The new
- * buffer's read-only property and byte order are the same as this buffer's.
- * The new buffer is direct if this byte buffer is direct.
- *
- *
- * The new buffer shares its content with this buffer, which means either
- * buffer's change of content will be visible to the other. The two buffer's
- * position, limit and mark are independent.
- *
- *
- * @return a short buffer which is based on the content of this byte buffer.
- * @since Android 1.0
- */
- public abstract ShortBuffer asShortBuffer();
-
- /**
- * Compacts this byte buffer.
- *
- * The remaining bytes will be moved to the head of the
- * buffer, starting from position zero. Then the position is set to
- * {@code remaining()}; the limit is set to capacity; the mark is
- * cleared.
- *
- *
- * @return this buffer.
- * @exception ReadOnlyBufferException
- * if no changes may be made to the contents of this buffer.
- * @since Android 1.0
- */
- public abstract ByteBuffer compact();
-
- /**
- * Compares the remaining bytes of this buffer to another byte buffer's
- * remaining bytes.
- *
- * @param otherBuffer
- * another byte buffer.
- * @return a negative value if this is less than {@code other}; 0 if this
- * equals to {@code other}; a positive value if this is greater
- * than {@code other}.
- * @exception ClassCastException
- * if {@code other} is not a byte buffer.
- * @since Android 1.0
- */
- public int compareTo(ByteBuffer otherBuffer) {
- int compareRemaining = (remaining() < otherBuffer.remaining()) ? remaining()
- : otherBuffer.remaining();
- int thisPos = position;
- int otherPos = otherBuffer.position;
- byte thisByte, otherByte;
- while (compareRemaining > 0) {
- thisByte = get(thisPos);
- otherByte = otherBuffer.get(otherPos);
- if (thisByte != otherByte) {
- return thisByte < otherByte ? -1 : 1;
- }
- thisPos++;
- otherPos++;
- compareRemaining--;
- }
- return remaining() - otherBuffer.remaining();
- }
-
- /**
- * Returns a duplicated buffer that shares its content with this buffer.
- *
- * The duplicated buffer's position, limit, capacity and mark are the same
- * as this buffer's. The duplicated buffer's read-only property and byte
- * order are the same as this buffer's too.
- *
- *
- * The new buffer shares its content with this buffer, which means either
- * buffer's change of content will be visible to the other. The two buffer's
- * position, limit and mark are independent.
- *
- *
- * @return a duplicated buffer that shares its content with this buffer.
- * @since Android 1.0
- */
- public abstract ByteBuffer duplicate();
-
- /**
- * Checks whether this byte buffer is equal to another object.
- *
- * If {@code other} is not a byte buffer then {@code false} is returned. Two
- * byte buffers are equal if and only if their remaining bytes are exactly
- * the same. Position, limit, capacity and mark are not considered.
- *
- *
- * @param other
- * the object to compare with this byte buffer.
- * @return {@code true} if this byte buffer is equal to {@code other},
- * {@code false} otherwise.
- * @since Android 1.0
- */
- public boolean equals(Object other) {
- if (!(other instanceof ByteBuffer)) {
- return false;
- }
- ByteBuffer otherBuffer = (ByteBuffer) other;
-
- if (remaining() != otherBuffer.remaining()) {
- return false;
- }
-
- int myPosition = position;
- int otherPosition = otherBuffer.position;
- boolean equalSoFar = true;
- while (equalSoFar && (myPosition < limit)) {
- equalSoFar = get(myPosition++) == otherBuffer.get(otherPosition++);
- }
-
- return equalSoFar;
- }
-
- /**
- * Returns the byte at the current position and increases the position by 1.
- *
- * @return the byte at the current position.
- * @exception BufferUnderflowException
- * if the position is equal or greater than limit.
- * @since Android 1.0
- */
- public abstract byte get();
-
- /**
- * Reads bytes from the current position into the specified byte array and
- * increases the position by the number of bytes read.
- *
- * Calling this method has the same effect as
- * {@code get(dest, 0, dest.length)}.
- *
- *
- * @param dest
- * the destination byte array.
- * @return this buffer.
- * @exception BufferUnderflowException
- * if {@code dest.length} is greater than {@code remaining()}.
- * @since Android 1.0
- */
- public ByteBuffer get(byte[] dest) {
- return get(dest, 0, dest.length);
- }
-
- /**
- * Reads bytes from the current position into the specified byte array,
- * starting at the specified offset, and increases the position by the
- * number of bytes read.
- *
- * @param dest
- * the target byte array.
- * @param off
- * the offset of the byte array, must not be negative and
- * not greater than {@code dest.length}.
- * @param len
- * the number of bytes to read, must not be negative and not
- * greater than {@code dest.length - off}
- * @return this buffer.
- * @exception IndexOutOfBoundsException
- * if either {@code off} or {@code len} is invalid.
- * @exception BufferUnderflowException
- * if {@code len} is greater than {@code remaining()}.
- * @since Android 1.0
- */
- public ByteBuffer get(byte[] dest, int off, int len) {
- int length = dest.length;
- if ((off < 0 ) || (len < 0) || ((long)off + (long)len > length)) {
- throw new IndexOutOfBoundsException();
- }
-
- if (len > remaining()) {
- throw new BufferUnderflowException();
- }
- for (int i = off; i < off + len; i++) {
- dest[i] = get();
- }
- return this;
- }
-
- /**
- * Returns the byte at the specified index and does not change the position.
- *
- * @param index
- * the index, must not be negative and less than limit.
- * @return the byte at the specified index.
- * @exception IndexOutOfBoundsException
- * if index is invalid.
- * @since Android 1.0
- */
- public abstract byte get(int index);
-
- /**
- * Returns the char at the current position and increases the position by 2.
- *
- * The 2 bytes starting at the current position are composed into a char
- * according to the current byte order and returned.
- *
- *
- * @return the char at the current position.
- * @exception BufferUnderflowException
- * if the position is greater than {@code limit - 2}.
- * @since Android 1.0
- */
- public abstract char getChar();
-
- /**
- * Returns the char at the specified index.
- *
- * The 2 bytes starting from the specified index are composed into a char
- * according to the current byte order and returned. The position is not
- * changed.
- *
- *
- * @param index
- * the index, must not be negative and equal or less than
- * {@code limit - 2}.
- * @return the char at the specified index.
- * @exception IndexOutOfBoundsException
- * if {@code index} is invalid.
- * @since Android 1.0
- */
- public abstract char getChar(int index);
-
- /**
- * Returns the double at the current position and increases the position by
- * 8.
- *
- * The 8 bytes starting from the current position are composed into a double
- * according to the current byte order and returned.
- *
- *
- * @return the double at the current position.
- * @exception BufferUnderflowException
- * if the position is greater than {@code limit - 8}.
- * @since Android 1.0
- */
- public abstract double getDouble();
-
- /**
- * Returns the double at the specified index.
- *
- * The 8 bytes starting at the specified index are composed into a double
- * according to the current byte order and returned. The position is not
- * changed.
- *
- *
- * @param index
- * the index, must not be negative and equal or less than
- * {@code limit - 8}.
- * @return the double at the specified index.
- * @exception IndexOutOfBoundsException
- * if {@code index} is invalid.
- * @since Android 1.0
- */
- public abstract double getDouble(int index);
-
- /**
- * Returns the float at the current position and increases the position by
- * 4.
- *
- * The 4 bytes starting at the current position are composed into a float
- * according to the current byte order and returned.
- *
- *
- * @return the float at the current position.
- * @exception BufferUnderflowException
- * if the position is greater than {@code limit - 4}.
- * @since Android 1.0
- */
- public abstract float getFloat();
-
- /**
- * Returns the float at the specified index.
- *
- * The 4 bytes starting at the specified index are composed into a float
- * according to the current byte order and returned. The position is not
- * changed.
- *
- *
- * @param index
- * the index, must not be negative and equal or less than
- * {@code limit - 4}.
- * @return the float at the specified index.
- * @exception IndexOutOfBoundsException
- * if {@code index} is invalid.
- * @since Android 1.0
- */
- public abstract float getFloat(int index);
-
- /**
- * Returns the int at the current position and increases the position by 4.
- *
- * The 4 bytes starting at the current position are composed into a int
- * according to the current byte order and returned.
- *
- *
- * @return the int at the current position.
- * @exception BufferUnderflowException
- * if the position is greater than {@code limit - 4}.
- * @since Android 1.0
- */
- public abstract int getInt();
-
- /**
- * Returns the int at the specified index.
- *
- * The 4 bytes starting at the specified index are composed into a int
- * according to the current byte order and returned. The position is not
- * changed.
- *
- *
- * @param index
- * the index, must not be negative and equal or less than
- * {@code limit - 4}.
- * @return the int at the specified index.
- * @exception IndexOutOfBoundsException
- * if {@code index} is invalid.
- * @since Android 1.0
- */
- public abstract int getInt(int index);
-
- /**
- * Returns the long at the current position and increases the position by 8.
- *
- * The 8 bytes starting at the current position are composed into a long
- * according to the current byte order and returned.
- *
- *
- * @return the long at the current position.
- * @exception BufferUnderflowException
- * if the position is greater than {@code limit - 8}.
- * @since Android 1.0
- */
- public abstract long getLong();
-
- /**
- * Returns the long at the specified index.
- *
- * The 8 bytes starting at the specified index are composed into a long
- * according to the current byte order and returned. The position is not
- * changed.
- *
- *
- * @param index
- * the index, must not be negative and equal or less than
- * {@code limit - 8}.
- * @return the long at the specified index.
- * @exception IndexOutOfBoundsException
- * if {@code index} is invalid.
- * @since Android 1.0
- */
- public abstract long getLong(int index);
-
- /**
- * Returns the short at the current position and increases the position by 2.
- *
- * The 2 bytes starting at the current position are composed into a short
- * according to the current byte order and returned.
- *
- *
- * @return the short at the current position.
- * @exception BufferUnderflowException
- * if the position is greater than {@code limit - 2}.
- * @since Android 1.0
- */
- public abstract short getShort();
-
- /**
- * Returns the short at the specified index.
- *
- * The 2 bytes starting at the specified index are composed into a short
- * according to the current byte order and returned. The position is not
- * changed.
- *
- *
- * @param index
- * the index, must not be negative and equal or less than
- * {@code limit - 2}.
- * @return the short at the specified index.
- * @exception IndexOutOfBoundsException
- * if {@code index} is invalid.
- * @since Android 1.0
- */
- public abstract short getShort(int index);
-
- /**
- * Indicates whether this buffer is based on a byte array and provides
- * read/write access.
- *
- * @return {@code true} if this buffer is based on a byte array and provides
- * read/write access, {@code false} otherwise.
- * @since Android 1.0
- */
- public final boolean hasArray() {
- return protectedHasArray();
- }
-
- /**
- * Calculates this buffer's hash code from the remaining chars. The
- * position, limit, capacity and mark don't affect the hash code.
- *
- * @return the hash code calculated from the remaining bytes.
- * @since Android 1.0
- */
- public int hashCode() {
- int myPosition = position;
- int hash = 0;
- while (myPosition < limit) {
- hash = hash + get(myPosition++);
- }
- return hash;
- }
-
- /**
- * Indicates whether this buffer is direct.
- *
- * @return {@code true} if this buffer is direct, {@code false} otherwise.
- * @since Android 1.0
- */
- public abstract boolean isDirect();
-
- /**
- * Returns the byte order used by this buffer when converting bytes from/to
- * other primitive types.
- *
- * The default byte order of byte buffer is always
- * {@link ByteOrder#BIG_ENDIAN BIG_ENDIAN}
- *
- *
- * @return the byte order used by this buffer when converting bytes from/to
- * other primitive types.
- * @since Android 1.0
- */
- public final ByteOrder order() {
- return order == Endianness.BIG_ENDIAN ? ByteOrder.BIG_ENDIAN
- : ByteOrder.LITTLE_ENDIAN;
- }
-
- /**
- * Sets the byte order of this buffer.
- *
- * @param byteOrder
- * the byte order to set. If {@code null} then the order
- * will be {@link ByteOrder#LITTLE_ENDIAN LITTLE_ENDIAN}.
- * @return this buffer.
- * @see ByteOrder
- * @since Android 1.0
- */
- public final ByteBuffer order(ByteOrder byteOrder) {
- return orderImpl(byteOrder);
- }
-
- ByteBuffer orderImpl(ByteOrder byteOrder) {
- order = byteOrder == ByteOrder.BIG_ENDIAN ? Endianness.BIG_ENDIAN
- : Endianness.LITTLE_ENDIAN;
- return this;
- }
-
- /**
- * Child class implements this method to realize {@code array()}.
- *
- * @see #array()
- * @since Android 1.0
- */
- abstract byte[] protectedArray();
-
- /**
- * Child class implements this method to realize {@code arrayOffset()}.
- *
- * @see #arrayOffset()
- * @since Android 1.0
- */
- abstract int protectedArrayOffset();
-
- /**
- * Child class implements this method to realize {@code hasArray()}.
- *
- * @see #hasArray()
- * @since Android 1.0
- */
- abstract boolean protectedHasArray();
-
- /**
- * Writes the given byte to the current position and increases the position
- * by 1.
- *
- * @param b
- * the byte to write.
- * @return this buffer.
- * @exception BufferOverflowException
- * if position is equal or greater than limit.
- * @exception ReadOnlyBufferException
- * if no changes may be made to the contents of this buffer.
- * @since Android 1.0
- */
- public abstract ByteBuffer put(byte b);
-
- /**
- * Writes bytes in the given byte array to the current position and
- * increases the position by the number of bytes written.
- *
- * Calling this method has the same effect as
- * {@code put(src, 0, src.length)}.
- *
- *
- * @param src
- * the source byte array.
- * @return this buffer.
- * @exception BufferOverflowException
- * if {@code remaining()} is less than {@code src.length}.
- * @exception ReadOnlyBufferException
- * if no changes may be made to the contents of this buffer.
- * @since Android 1.0
- */
- public final ByteBuffer put(byte[] src) {
- return put(src, 0, src.length);
- }
-
- /**
- * Writes bytes in the given byte array, starting from the specified offset,
- * to the current position and increases the position by the number of bytes
- * written.
- *
- * @param src
- * the source byte array.
- * @param off
- * the offset of byte array, must not be negative and not greater
- * than {@code src.length}.
- * @param len
- * the number of bytes to write, must not be negative and not
- * greater than {@code src.length - off}.
- * @return this buffer.
- * @exception BufferOverflowException
- * if {@code remaining()} is less than {@code len}.
- * @exception IndexOutOfBoundsException
- * if either {@code off} or {@code len} is invalid.
- * @exception ReadOnlyBufferException
- * if no changes may be made to the contents of this buffer.
- * @since Android 1.0
- */
- public ByteBuffer put(byte[] src, int off, int len) {
- int length = src.length;
- if ((off < 0 ) || (len < 0) || ((long)off + (long)len > length)) {
- throw new IndexOutOfBoundsException();
- }
-
- if (len > remaining()) {
- throw new BufferOverflowException();
- }
- for (int i = off; i < off + len; i++) {
- put(src[i]);
- }
- return this;
- }
-
- /**
- * Writes all the remaining bytes of the {@code src} byte buffer to this
- * buffer's current position, and increases both buffers' position by the
- * number of bytes copied.
- *
- * @param src
- * the source byte buffer.
- * @return this buffer.
- * @exception BufferOverflowException
- * if {@code src.remaining()} is greater than this buffer's
- * {@code remaining()}.
- * @exception IllegalArgumentException
- * if {@code src} is this buffer.
- * @exception ReadOnlyBufferException
- * if no changes may be made to the contents of this buffer.
- * @since Android 1.0
- */
- public ByteBuffer put(ByteBuffer src) {
- if (src == this) {
- throw new IllegalArgumentException();
- }
- if (src.remaining() > remaining()) {
- throw new BufferOverflowException();
- }
- byte[] contents = new byte[src.remaining()];
- src.get(contents);
- put(contents);
- return this;
- }
-
- /**
- * Write a byte to the specified index of this buffer without changing the
- * position.
- *
- * @param index
- * the index, must not be negative and less than the limit.
- * @param b
- * the byte to write.
- * @return this buffer.
- * @exception IndexOutOfBoundsException
- * if {@code index} is invalid.
- * @exception ReadOnlyBufferException
- * if no changes may be made to the contents of this buffer.
- * @since Android 1.0
- */
- public abstract ByteBuffer put(int index, byte b);
-
- /**
- * Writes the given char to the current position and increases the position
- * by 2.
- *
- * The char is converted to bytes using the current byte order.
- *
- *
- * @param value
- * the char to write.
- * @return this buffer.
- * @exception BufferOverflowException
- * if position is greater than {@code limit - 2}.
- * @exception ReadOnlyBufferException
- * if no changes may be made to the contents of this buffer.
- * @since Android 1.0
- */
- public abstract ByteBuffer putChar(char value);
-
- /**
- * Writes the given char to the specified index of this buffer.
- *
- * The char is converted to bytes using the current byte order. The position
- * is not changed.
- *
- *
- * @param index
- * the index, must not be negative and equal or less than
- * {@code limit - 2}.
- * @param value
- * the char to write.
- * @return this buffer.
- * @exception IndexOutOfBoundsException
- * if {@code index} is invalid.
- * @exception ReadOnlyBufferException
- * if no changes may be made to the contents of this buffer.
- * @since Android 1.0
- */
- public abstract ByteBuffer putChar(int index, char value);
-
- /**
- * Writes the given double to the current position and increases the position
- * by 8.
- *
- * The double is converted to bytes using the current byte order.
- *
- *
- * @param value
- * the double to write.
- * @return this buffer.
- * @exception BufferOverflowException
- * if position is greater than {@code limit - 8}.
- * @exception ReadOnlyBufferException
- * if no changes may be made to the contents of this buffer.
- * @since Android 1.0
- */
- public abstract ByteBuffer putDouble(double value);
-
- /**
- * Writes the given double to the specified index of this buffer.
- *
- * The double is converted to bytes using the current byte order. The
- * position is not changed.
- *
- *
- * @param index
- * the index, must not be negative and equal or less than
- * {@code limit - 8}.
- * @param value
- * the double to write.
- * @return this buffer.
- * @exception IndexOutOfBoundsException
- * if {@code index} is invalid.
- * @exception ReadOnlyBufferException
- * if no changes may be made to the contents of this buffer.
- * @since Android 1.0
- */
- public abstract ByteBuffer putDouble(int index, double value);
-
- /**
- * Writes the given float to the current position and increases the position
- * by 4.
- *
- * The float is converted to bytes using the current byte order.
- *
- *
- * @param value
- * the float to write.
- * @return this buffer.
- * @exception BufferOverflowException
- * if position is greater than {@code limit - 4}.
- * @exception ReadOnlyBufferException
- * if no changes may be made to the contents of this buffer.
- * @since Android 1.0
- */
- public abstract ByteBuffer putFloat(float value);
-
- /**
- * Writes the given float to the specified index of this buffer.
- *
- * The float is converted to bytes using the current byte order. The
- * position is not changed.
- *
- *
- * @param index
- * the index, must not be negative and equal or less than
- * {@code limit - 4}.
- * @param value
- * the float to write.
- * @return this buffer.
- * @exception IndexOutOfBoundsException
- * if {@code index} is invalid.
- * @exception ReadOnlyBufferException
- * if no changes may be made to the contents of this buffer.
- * @since Android 1.0
- */
- public abstract ByteBuffer putFloat(int index, float value);
-
- /**
- * Writes the given int to the current position and increases the position by
- * 4.
- *
- * The int is converted to bytes using the current byte order.
- *
- *
- * @param value
- * the int to write.
- * @return this buffer.
- * @exception BufferOverflowException
- * if position is greater than {@code limit - 4}.
- * @exception ReadOnlyBufferException
- * if no changes may be made to the contents of this buffer.
- * @since Android 1.0
- */
- public abstract ByteBuffer putInt(int value);
-
- /**
- * Writes the given int to the specified index of this buffer.
- *
- * The int is converted to bytes using the current byte order. The position
- * is not changed.
- *
- *
- * @param index
- * the index, must not be negative and equal or less than
- * {@code limit - 4}.
- * @param value
- * the int to write.
- * @return this buffer.
- * @exception IndexOutOfBoundsException
- * if {@code index} is invalid.
- * @exception ReadOnlyBufferException
- * if no changes may be made to the contents of this buffer.
- * @since Android 1.0
- */
- public abstract ByteBuffer putInt(int index, int value);
-
- /**
- * Writes the given long to the current position and increases the position
- * by 8.
- *
- * The long is converted to bytes using the current byte order.
- *
- *
- * @param value
- * the long to write.
- * @return this buffer.
- * @exception BufferOverflowException
- * if position is greater than {@code limit - 8}.
- * @exception ReadOnlyBufferException
- * if no changes may be made to the contents of this buffer.
- * @since Android 1.0
- */
- public abstract ByteBuffer putLong(long value);
-
- /**
- * Writes the given long to the specified index of this buffer.
- *
- * The long is converted to bytes using the current byte order. The position
- * is not changed.
- *
- *
- * @param index
- * the index, must not be negative and equal or less than
- * {@code limit - 8}.
- * @param value
- * the long to write.
- * @return this buffer.
- * @exception IndexOutOfBoundsException
- * if {@code index} is invalid.
- * @exception ReadOnlyBufferException
- * if no changes may be made to the contents of this buffer.
- * @since Android 1.0
- */
- public abstract ByteBuffer putLong(int index, long value);
-
- /**
- * Writes the given short to the current position and increases the position
- * by 2.
- *
- * The short is converted to bytes using the current byte order.
- *
- *
- * @param value
- * the short to write.
- * @return this buffer.
- * @exception BufferOverflowException
- * if position is greater than {@code limit - 2}.
- * @exception ReadOnlyBufferException
- * if no changes may be made to the contents of this buffer.
- * @since Android 1.0
- */
- public abstract ByteBuffer putShort(short value);
-
- /**
- * Writes the given short to the specified index of this buffer.
- *
- * The short is converted to bytes using the current byte order. The
- * position is not changed.
- *
- *
- * @param index
- * the index, must not be negative and equal or less than
- * {@code limit - 2}.
- * @param value
- * the short to write.
- * @return this buffer.
- * @exception IndexOutOfBoundsException
- * if {@code index} is invalid.
- * @exception ReadOnlyBufferException
- * if no changes may be made to the contents of this buffer.
- * @since Android 1.0
- */
- public abstract ByteBuffer putShort(int index, short value);
-
- /**
- * Returns a sliced buffer that shares its content with this buffer.
- *
- * The sliced buffer's capacity will be this buffer's
- * {@code remaining()}, and it's zero position will correspond to
- * this buffer's current position. The new buffer's position will be 0,
- * limit will be its capacity, and its mark is cleared. The new buffer's
- * read-only property and byte order are the same as this buffer's.
- *
- *
- * The new buffer shares its content with this buffer, which means either
- * buffer's change of content will be visible to the other. The two buffer's
- * position, limit and mark are independent.
- *
- *
- * @return a sliced buffer that shares its content with this buffer.
- * @since Android 1.0
- */
- public abstract ByteBuffer slice();
-
- /**
- * Returns a string representing the state of this byte buffer.
- *
- * @return a string representing the state of this byte buffer.
- * @since Android 1.0
- */
- public String toString() {
- StringBuffer buf = new StringBuffer();
- buf.append(getClass().getName());
- buf.append(", status: capacity="); //$NON-NLS-1$
- buf.append(capacity());
- buf.append(" position="); //$NON-NLS-1$
- buf.append(position());
- buf.append(" limit="); //$NON-NLS-1$
- buf.append(limit());
- return buf.toString();
- }
-
- public ByteBuffer stringToByteBuffer(String s) {
- return new StringByteBuffer(s);
- }
+ /** Creates a byte buffer based on a newly allocated byte array.
+ *
+ * @param capacity the capacity of the new buffer
+ * @return the created byte buffer.
+ * @throws IllegalArgumentException if {@code capacity < 0}.
+ * @since Android 1.0 */
+ public static ByteBuffer allocate (int capacity) {
+ if (capacity < 0) {
+ throw new IllegalArgumentException();
+ }
+ return BufferFactory.newByteBuffer(capacity);
+ }
+
+ /** Creates a direct byte buffer based on a newly allocated memory block.
+ *
+ * @param capacity the capacity of the new buffer
+ * @return the created byte buffer.
+ * @throws IllegalArgumentException if {@code capacity < 0}.
+ * @since Android 1.0 */
+ public static ByteBuffer allocateDirect (int capacity) {
+ if (capacity < 0) {
+ throw new IllegalArgumentException();
+ }
+ return BufferFactory.newDirectByteBuffer(capacity);
+ }
+
+ /** Creates a new byte buffer by wrapping the given byte array.
+ *
+ * Calling this method has the same effect as {@code wrap(array, 0, array.length)}.
+ *
+ *
+ * @param array the byte array which the new buffer will be based on
+ * @return the created byte buffer.
+ * @since Android 1.0 */
+ public static ByteBuffer wrap (byte[] array) {
+ return BufferFactory.newByteBuffer(array);
+ }
+
+ /** Creates a new byte buffer by wrapping the given byte array.
+ *
+ * The new buffer's position will be {@code start}, limit will be {@code start + len}, capacity will be the length of the
+ * array.
+ *
+ *
+ * @param array the byte array which the new buffer will be based on.
+ * @param start the start index, must not be negative and not greater than {@code array.length}.
+ * @param len the length, must not be negative and not greater than {@code array.length - start}.
+ * @return the created byte buffer.
+ * @exception IndexOutOfBoundsException if either {@code start} or {@code len} is invalid.
+ * @since Android 1.0 */
+ public static ByteBuffer wrap (byte[] array, int start, int len) {
+ int length = array.length;
+ if ((start < 0) || (len < 0) || ((long)start + (long)len > length)) {
+ throw new IndexOutOfBoundsException();
+ }
+
+ ByteBuffer buf = BufferFactory.newByteBuffer(array);
+ buf.position = start;
+ buf.limit = start + len;
+
+ return buf;
+ }
+
+ /** The byte order of this buffer, default is {@code BIG_ENDIAN}. */
+ Endianness order = Endianness.BIG_ENDIAN;
+
+ /** Constructs a {@code ByteBuffer} with given capacity.
+ *
+ * @param capacity the capacity of the buffer. */
+ ByteBuffer (int capacity) {
+ super(capacity);
+ }
+
+ /** Returns the byte array which this buffer is based on, if there is one.
+ *
+ * @return the byte array which this buffer is based on.
+ * @exception ReadOnlyBufferException if this buffer is based on a read-only array.
+ * @exception UnsupportedOperationException if this buffer is not based on an array.
+ * @since Android 1.0 */
+ public final byte[] array () {
+ return protectedArray();
+ }
+
+ /** Returns the offset of the byte array which this buffer is based on, if there is one.
+ *
+ * The offset is the index of the array which corresponds to the zero position of the buffer.
+ *
+ *
+ * @return the offset of the byte array which this buffer is based on.
+ * @exception ReadOnlyBufferException if this buffer is based on a read-only array.
+ * @exception UnsupportedOperationException if this buffer is not based on an array.
+ * @since Android 1.0 */
+ public final int arrayOffset () {
+ return protectedArrayOffset();
+ }
+
+ /** Returns a char buffer which is based on the remaining content of this byte buffer.
+ *
+ * The new buffer's position is zero, its limit and capacity is the number of remaining bytes divided by two, and its mark is
+ * not set. The new buffer's read-only property and byte order are the same as this buffer's. The new buffer is direct if this
+ * byte buffer is direct.
+ *
+ *
+ * The new buffer shares its content with this buffer, which means either buffer's change of content will be visible to the
+ * other. The two buffer's position, limit and mark are independent.
+ *
+ *
+ * @return a char buffer which is based on the content of this byte buffer.
+ * @since Android 1.0 */
+ public abstract CharBuffer asCharBuffer ();
+
+ /** Returns a double buffer which is based on the remaining content of this byte buffer.
+ *
+ * The new buffer's position is zero, its limit and capacity is the number of remaining bytes divided by eight, and its mark is
+ * not set. The new buffer's read-only property and byte order are the same as this buffer's. The new buffer is direct if this
+ * byte buffer is direct.
+ *
+ *
+ * The new buffer shares its content with this buffer, which means either buffer's change of content will be visible to the
+ * other. The two buffer's position, limit and mark are independent.
+ *
+ *
+ * @return a double buffer which is based on the content of this byte buffer.
+ * @since Android 1.0 */
+ public abstract DoubleBuffer asDoubleBuffer ();
+
+ /** Returns a float buffer which is based on the remaining content of this byte buffer.
+ *
+ * The new buffer's position is zero, its limit and capacity is the number of remaining bytes divided by four, and its mark is
+ * not set. The new buffer's read-only property and byte order are the same as this buffer's. The new buffer is direct if this
+ * byte buffer is direct.
+ *
+ *
+ * The new buffer shares its content with this buffer, which means either buffer's change of content will be visible to the
+ * other. The two buffer's position, limit and mark are independent.
+ *
+ *
+ * @return a float buffer which is based on the content of this byte buffer.
+ * @since Android 1.0 */
+ public abstract FloatBuffer asFloatBuffer ();
+
+ /** Returns a int buffer which is based on the remaining content of this byte buffer.
+ *
+ * The new buffer's position is zero, its limit and capacity is the number of remaining bytes divided by four, and its mark is
+ * not set. The new buffer's read-only property and byte order are the same as this buffer's. The new buffer is direct if this
+ * byte buffer is direct.
+ *
+ *
+ * The new buffer shares its content with this buffer, which means either buffer's change of content will be visible to the
+ * other. The two buffer's position, limit and mark are independent.
+ *
+ *
+ * @return a int buffer which is based on the content of this byte buffer.
+ * @since Android 1.0 */
+ public abstract IntBuffer asIntBuffer ();
+
+ /** Returns a long buffer which is based on the remaining content of this byte buffer.
+ *
+ * The new buffer's position is zero, its limit and capacity is the number of remaining bytes divided by eight, and its mark is
+ * not set. The new buffer's read-only property and byte order are the same as this buffer's. The new buffer is direct if this
+ * byte buffer is direct.
+ *
+ *
+ * The new buffer shares its content with this buffer, which means either buffer's change of content will be visible to the
+ * other. The two buffer's position, limit and mark are independent.
+ *
+ *
+ * @return a long buffer which is based on the content of this byte buffer.
+ * @since Android 1.0 */
+ public abstract LongBuffer asLongBuffer ();
+
+ /** Returns a read-only buffer that shares its content with this buffer.
+ *
+ * The returned buffer is guaranteed to be a new instance, even if this buffer is read-only itself. The new buffer's position,
+ * limit, capacity and mark are the same as this buffer.
+ *
+ *
+ * The new buffer shares its content with this buffer, which means this buffer's change of content will be visible to the new
+ * buffer. The two buffer's position, limit and mark are independent.
+ *
+ *
+ * @return a read-only version of this buffer.
+ * @since Android 1.0 */
+ public abstract ByteBuffer asReadOnlyBuffer ();
+
+ /** Returns a short buffer which is based on the remaining content of this byte buffer.
+ *
+ * The new buffer's position is zero, its limit and capacity is the number of remaining bytes divided by two, and its mark is
+ * not set. The new buffer's read-only property and byte order are the same as this buffer's. The new buffer is direct if this
+ * byte buffer is direct.
+ *
+ *
+ * The new buffer shares its content with this buffer, which means either buffer's change of content will be visible to the
+ * other. The two buffer's position, limit and mark are independent.
+ *
+ *
+ * @return a short buffer which is based on the content of this byte buffer.
+ * @since Android 1.0 */
+ public abstract ShortBuffer asShortBuffer ();
+
+ /** Compacts this byte buffer.
+ *
+ * The remaining bytes will be moved to the head of the buffer, starting from position zero. Then the position is set to
+ * {@code remaining()}; the limit is set to capacity; the mark is cleared.
+ *
+ *
+ * @return this buffer.
+ * @exception ReadOnlyBufferException if no changes may be made to the contents of this buffer.
+ * @since Android 1.0 */
+ public abstract ByteBuffer compact ();
+
+ /** Compares the remaining bytes of this buffer to another byte buffer's remaining bytes.
+ *
+ * @param otherBuffer another byte buffer.
+ * @return a negative value if this is less than {@code other}; 0 if this equals to {@code other}; a positive value if this is
+ * greater than {@code other}.
+ * @exception ClassCastException if {@code other} is not a byte buffer.
+ * @since Android 1.0 */
+ public int compareTo (ByteBuffer otherBuffer) {
+ int compareRemaining = (remaining() < otherBuffer.remaining()) ? remaining() : otherBuffer.remaining();
+ int thisPos = position;
+ int otherPos = otherBuffer.position;
+ byte thisByte, otherByte;
+ while (compareRemaining > 0) {
+ thisByte = get(thisPos);
+ otherByte = otherBuffer.get(otherPos);
+ if (thisByte != otherByte) {
+ return thisByte < otherByte ? -1 : 1;
+ }
+ thisPos++;
+ otherPos++;
+ compareRemaining--;
+ }
+ return remaining() - otherBuffer.remaining();
+ }
+
+ /** Returns a duplicated buffer that shares its content with this buffer.
+ *
+ * The duplicated buffer's position, limit, capacity and mark are the same as this buffer's. The duplicated buffer's read-only
+ * property and byte order are the same as this buffer's too.
+ *
+ *
+ * The new buffer shares its content with this buffer, which means either buffer's change of content will be visible to the
+ * other. The two buffer's position, limit and mark are independent.
+ *
+ *
+ * @return a duplicated buffer that shares its content with this buffer.
+ * @since Android 1.0 */
+ public abstract ByteBuffer duplicate ();
+
+ /** Checks whether this byte buffer is equal to another object.
+ *
+ * If {@code other} is not a byte buffer then {@code false} is returned. Two byte buffers are equal if and only if their
+ * remaining bytes are exactly the same. Position, limit, capacity and mark are not considered.
+ *
+ *
+ * @param other the object to compare with this byte buffer.
+ * @return {@code true} if this byte buffer is equal to {@code other}, {@code false} otherwise.
+ * @since Android 1.0 */
+ public boolean equals (Object other) {
+ if (!(other instanceof ByteBuffer)) {
+ return false;
+ }
+ ByteBuffer otherBuffer = (ByteBuffer)other;
+
+ if (remaining() != otherBuffer.remaining()) {
+ return false;
+ }
+
+ int myPosition = position;
+ int otherPosition = otherBuffer.position;
+ boolean equalSoFar = true;
+ while (equalSoFar && (myPosition < limit)) {
+ equalSoFar = get(myPosition++) == otherBuffer.get(otherPosition++);
+ }
+
+ return equalSoFar;
+ }
+
+ /** Returns the byte at the current position and increases the position by 1.
+ *
+ * @return the byte at the current position.
+ * @exception BufferUnderflowException if the position is equal or greater than limit.
+ * @since Android 1.0 */
+ public abstract byte get ();
+
+ /** Reads bytes from the current position into the specified byte array and increases the position by the number of bytes read.
+ *
+ * Calling this method has the same effect as {@code get(dest, 0, dest.length)}.
+ *
+ *
+ * @param dest the destination byte array.
+ * @return this buffer.
+ * @exception BufferUnderflowException if {@code dest.length} is greater than {@code remaining()}.
+ * @since Android 1.0 */
+ public ByteBuffer get (byte[] dest) {
+ return get(dest, 0, dest.length);
+ }
+
+ /** Reads bytes from the current position into the specified byte array, starting at the specified offset, and increases the
+ * position by the number of bytes read.
+ *
+ * @param dest the target byte array.
+ * @param off the offset of the byte array, must not be negative and not greater than {@code dest.length}.
+ * @param len the number of bytes to read, must not be negative and not greater than {@code dest.length - off}
+ * @return this buffer.
+ * @exception IndexOutOfBoundsException if either {@code off} or {@code len} is invalid.
+ * @exception BufferUnderflowException if {@code len} is greater than {@code remaining()}.
+ * @since Android 1.0 */
+ public ByteBuffer get (byte[] dest, int off, int len) {
+ int length = dest.length;
+ if ((off < 0) || (len < 0) || ((long)off + (long)len > length)) {
+ throw new IndexOutOfBoundsException();
+ }
+
+ if (len > remaining()) {
+ throw new BufferUnderflowException();
+ }
+ for (int i = off; i < off + len; i++) {
+ dest[i] = get();
+ }
+ return this;
+ }
+
+ /** Returns the byte at the specified index and does not change the position.
+ *
+ * @param index the index, must not be negative and less than limit.
+ * @return the byte at the specified index.
+ * @exception IndexOutOfBoundsException if index is invalid.
+ * @since Android 1.0 */
+ public abstract byte get (int index);
+
+ /** Returns the char at the current position and increases the position by 2.
+ *
+ * The 2 bytes starting at the current position are composed into a char according to the current byte order and returned.
+ *
+ *
+ * @return the char at the current position.
+ * @exception BufferUnderflowException if the position is greater than {@code limit - 2}.
+ * @since Android 1.0 */
+ public abstract char getChar ();
+
+ /** Returns the char at the specified index.
+ *
+ * The 2 bytes starting from the specified index are composed into a char according to the current byte order and returned. The
+ * position is not changed.
+ *
+ *
+ * @param index the index, must not be negative and equal or less than {@code limit - 2}.
+ * @return the char at the specified index.
+ * @exception IndexOutOfBoundsException if {@code index} is invalid.
+ * @since Android 1.0 */
+ public abstract char getChar (int index);
+
+ /** Returns the double at the current position and increases the position by 8.
+ *
+ * The 8 bytes starting from the current position are composed into a double according to the current byte order and returned.
+ *
+ *
+ * @return the double at the current position.
+ * @exception BufferUnderflowException if the position is greater than {@code limit - 8}.
+ * @since Android 1.0 */
+ public abstract double getDouble ();
+
+ /** Returns the double at the specified index.
+ *
+ * The 8 bytes starting at the specified index are composed into a double according to the current byte order and returned. The
+ * position is not changed.
+ *
+ *
+ * @param index the index, must not be negative and equal or less than {@code limit - 8}.
+ * @return the double at the specified index.
+ * @exception IndexOutOfBoundsException if {@code index} is invalid.
+ * @since Android 1.0 */
+ public abstract double getDouble (int index);
+
+ /** Returns the float at the current position and increases the position by 4.
+ *
+ * The 4 bytes starting at the current position are composed into a float according to the current byte order and returned.
+ *
+ *
+ * @return the float at the current position.
+ * @exception BufferUnderflowException if the position is greater than {@code limit - 4}.
+ * @since Android 1.0 */
+ public abstract float getFloat ();
+
+ /** Returns the float at the specified index.
+ *
+ * The 4 bytes starting at the specified index are composed into a float according to the current byte order and returned. The
+ * position is not changed.
+ *
+ *
+ * @param index the index, must not be negative and equal or less than {@code limit - 4}.
+ * @return the float at the specified index.
+ * @exception IndexOutOfBoundsException if {@code index} is invalid.
+ * @since Android 1.0 */
+ public abstract float getFloat (int index);
+
+ /** Returns the int at the current position and increases the position by 4.
+ *
+ * The 4 bytes starting at the current position are composed into a int according to the current byte order and returned.
+ *
+ *
+ * @return the int at the current position.
+ * @exception BufferUnderflowException if the position is greater than {@code limit - 4}.
+ * @since Android 1.0 */
+ public abstract int getInt ();
+
+ /** Returns the int at the specified index.
+ *
+ * The 4 bytes starting at the specified index are composed into a int according to the current byte order and returned. The
+ * position is not changed.
+ *
+ *
+ * @param index the index, must not be negative and equal or less than {@code limit - 4}.
+ * @return the int at the specified index.
+ * @exception IndexOutOfBoundsException if {@code index} is invalid.
+ * @since Android 1.0 */
+ public abstract int getInt (int index);
+
+ /** Returns the long at the current position and increases the position by 8.
+ *
+ * The 8 bytes starting at the current position are composed into a long according to the current byte order and returned.
+ *
+ *
+ * @return the long at the current position.
+ * @exception BufferUnderflowException if the position is greater than {@code limit - 8}.
+ * @since Android 1.0 */
+ public abstract long getLong ();
+
+ /** Returns the long at the specified index.
+ *
+ * The 8 bytes starting at the specified index are composed into a long according to the current byte order and returned. The
+ * position is not changed.
+ *
+ *
+ * @param index the index, must not be negative and equal or less than {@code limit - 8}.
+ * @return the long at the specified index.
+ * @exception IndexOutOfBoundsException if {@code index} is invalid.
+ * @since Android 1.0 */
+ public abstract long getLong (int index);
+
+ /** Returns the short at the current position and increases the position by 2.
+ *
+ * The 2 bytes starting at the current position are composed into a short according to the current byte order and returned.
+ *
+ *
+ * @return the short at the current position.
+ * @exception BufferUnderflowException if the position is greater than {@code limit - 2}.
+ * @since Android 1.0 */
+ public abstract short getShort ();
+
+ /** Returns the short at the specified index.
+ *
+ * The 2 bytes starting at the specified index are composed into a short according to the current byte order and returned. The
+ * position is not changed.
+ *
+ *
+ * @param index the index, must not be negative and equal or less than {@code limit - 2}.
+ * @return the short at the specified index.
+ * @exception IndexOutOfBoundsException if {@code index} is invalid.
+ * @since Android 1.0 */
+ public abstract short getShort (int index);
+
+ /** Indicates whether this buffer is based on a byte array and provides read/write access.
+ *
+ * @return {@code true} if this buffer is based on a byte array and provides read/write access, {@code false} otherwise.
+ * @since Android 1.0 */
+ public final boolean hasArray () {
+ return protectedHasArray();
+ }
+
+ /** Calculates this buffer's hash code from the remaining chars. The position, limit, capacity and mark don't affect the hash
+ * code.
+ *
+ * @return the hash code calculated from the remaining bytes.
+ * @since Android 1.0 */
+ public int hashCode () {
+ int myPosition = position;
+ int hash = 0;
+ while (myPosition < limit) {
+ hash = hash + get(myPosition++);
+ }
+ return hash;
+ }
+
+ /** Indicates whether this buffer is direct.
+ *
+ * @return {@code true} if this buffer is direct, {@code false} otherwise.
+ * @since Android 1.0 */
+ public abstract boolean isDirect ();
+
+ /** Returns the byte order used by this buffer when converting bytes from/to other primitive types.
+ *
+ * The default byte order of byte buffer is always {@link ByteOrder#BIG_ENDIAN BIG_ENDIAN}
+ *
+ *
+ * @return the byte order used by this buffer when converting bytes from/to other primitive types.
+ * @since Android 1.0 */
+ public final ByteOrder order () {
+ return order == Endianness.BIG_ENDIAN ? ByteOrder.BIG_ENDIAN : ByteOrder.LITTLE_ENDIAN;
+ }
+
+ /** Sets the byte order of this buffer.
+ *
+ * @param byteOrder the byte order to set. If {@code null} then the order will be {@link ByteOrder#LITTLE_ENDIAN LITTLE_ENDIAN}
+ * .
+ * @return this buffer.
+ * @see ByteOrder
+ * @since Android 1.0 */
+ public final ByteBuffer order (ByteOrder byteOrder) {
+ return orderImpl(byteOrder);
+ }
+
+ ByteBuffer orderImpl (ByteOrder byteOrder) {
+ order = byteOrder == ByteOrder.BIG_ENDIAN ? Endianness.BIG_ENDIAN : Endianness.LITTLE_ENDIAN;
+ return this;
+ }
+
+ /** Child class implements this method to realize {@code array()}.
+ *
+ * @see #array()
+ * @since Android 1.0 */
+ abstract byte[] protectedArray ();
+
+ /** Child class implements this method to realize {@code arrayOffset()}.
+ *
+ * @see #arrayOffset()
+ * @since Android 1.0 */
+ abstract int protectedArrayOffset ();
+
+ /** Child class implements this method to realize {@code hasArray()}.
+ *
+ * @see #hasArray()
+ * @since Android 1.0 */
+ abstract boolean protectedHasArray ();
+
+ /** Writes the given byte to the current position and increases the position by 1.
+ *
+ * @param b the byte to write.
+ * @return this buffer.
+ * @exception BufferOverflowException if position is equal or greater than limit.
+ * @exception ReadOnlyBufferException if no changes may be made to the contents of this buffer.
+ * @since Android 1.0 */
+ public abstract ByteBuffer put (byte b);
+
+ /** Writes bytes in the given byte array to the current position and increases the position by the number of bytes written.
+ *
+ * Calling this method has the same effect as {@code put(src, 0, src.length)}.
+ *
+ *
+ * @param src the source byte array.
+ * @return this buffer.
+ * @exception BufferOverflowException if {@code remaining()} is less than {@code src.length}.
+ * @exception ReadOnlyBufferException if no changes may be made to the contents of this buffer.
+ * @since Android 1.0 */
+ public final ByteBuffer put (byte[] src) {
+ return put(src, 0, src.length);
+ }
+
+ /** Writes bytes in the given byte array, starting from the specified offset, to the current position and increases the position
+ * by the number of bytes written.
+ *
+ * @param src the source byte array.
+ * @param off the offset of byte array, must not be negative and not greater than {@code src.length}.
+ * @param len the number of bytes to write, must not be negative and not greater than {@code src.length - off}.
+ * @return this buffer.
+ * @exception BufferOverflowException if {@code remaining()} is less than {@code len}.
+ * @exception IndexOutOfBoundsException if either {@code off} or {@code len} is invalid.
+ * @exception ReadOnlyBufferException if no changes may be made to the contents of this buffer.
+ * @since Android 1.0 */
+ public ByteBuffer put (byte[] src, int off, int len) {
+ int length = src.length;
+ if ((off < 0) || (len < 0) || ((long)off + (long)len > length)) {
+ throw new IndexOutOfBoundsException();
+ }
+
+ if (len > remaining()) {
+ throw new BufferOverflowException();
+ }
+ for (int i = off; i < off + len; i++) {
+ put(src[i]);
+ }
+ return this;
+ }
+
+ /** Writes all the remaining bytes of the {@code src} byte buffer to this buffer's current position, and increases both buffers'
+ * position by the number of bytes copied.
+ *
+ * @param src the source byte buffer.
+ * @return this buffer.
+ * @exception BufferOverflowException if {@code src.remaining()} is greater than this buffer's {@code remaining()}.
+ * @exception IllegalArgumentException if {@code src} is this buffer.
+ * @exception ReadOnlyBufferException if no changes may be made to the contents of this buffer.
+ * @since Android 1.0 */
+ public ByteBuffer put (ByteBuffer src) {
+ if (src == this) {
+ throw new IllegalArgumentException();
+ }
+ if (src.remaining() > remaining()) {
+ throw new BufferOverflowException();
+ }
+ byte[] contents = new byte[src.remaining()];
+ src.get(contents);
+ put(contents);
+ return this;
+ }
+
+ /** Write a byte to the specified index of this buffer without changing the position.
+ *
+ * @param index the index, must not be negative and less than the limit.
+ * @param b the byte to write.
+ * @return this buffer.
+ * @exception IndexOutOfBoundsException if {@code index} is invalid.
+ * @exception ReadOnlyBufferException if no changes may be made to the contents of this buffer.
+ * @since Android 1.0 */
+ public abstract ByteBuffer put (int index, byte b);
+
+ /** Writes the given char to the current position and increases the position by 2.
+ *
+ * The char is converted to bytes using the current byte order.
+ *
+ *
+ * @param value the char to write.
+ * @return this buffer.
+ * @exception BufferOverflowException if position is greater than {@code limit - 2}.
+ * @exception ReadOnlyBufferException if no changes may be made to the contents of this buffer.
+ * @since Android 1.0 */
+ public abstract ByteBuffer putChar (char value);
+
+ /** Writes the given char to the specified index of this buffer.
+ *
+ * The char is converted to bytes using the current byte order. The position is not changed.
+ *
+ *
+ * @param index the index, must not be negative and equal or less than {@code limit - 2}.
+ * @param value the char to write.
+ * @return this buffer.
+ * @exception IndexOutOfBoundsException if {@code index} is invalid.
+ * @exception ReadOnlyBufferException if no changes may be made to the contents of this buffer.
+ * @since Android 1.0 */
+ public abstract ByteBuffer putChar (int index, char value);
+
+ /** Writes the given double to the current position and increases the position by 8.
+ *
+ * The double is converted to bytes using the current byte order.
+ *
+ *
+ * @param value the double to write.
+ * @return this buffer.
+ * @exception BufferOverflowException if position is greater than {@code limit - 8}.
+ * @exception ReadOnlyBufferException if no changes may be made to the contents of this buffer.
+ * @since Android 1.0 */
+ public abstract ByteBuffer putDouble (double value);
+
+ /** Writes the given double to the specified index of this buffer.
+ *
+ * The double is converted to bytes using the current byte order. The position is not changed.
+ *
+ *
+ * @param index the index, must not be negative and equal or less than {@code limit - 8}.
+ * @param value the double to write.
+ * @return this buffer.
+ * @exception IndexOutOfBoundsException if {@code index} is invalid.
+ * @exception ReadOnlyBufferException if no changes may be made to the contents of this buffer.
+ * @since Android 1.0 */
+ public abstract ByteBuffer putDouble (int index, double value);
+
+ /** Writes the given float to the current position and increases the position by 4.
+ *
+ * The float is converted to bytes using the current byte order.
+ *
+ *
+ * @param value the float to write.
+ * @return this buffer.
+ * @exception BufferOverflowException if position is greater than {@code limit - 4}.
+ * @exception ReadOnlyBufferException if no changes may be made to the contents of this buffer.
+ * @since Android 1.0 */
+ public abstract ByteBuffer putFloat (float value);
+
+ /** Writes the given float to the specified index of this buffer.
+ *
+ * The float is converted to bytes using the current byte order. The position is not changed.
+ *
+ *
+ * @param index the index, must not be negative and equal or less than {@code limit - 4}.
+ * @param value the float to write.
+ * @return this buffer.
+ * @exception IndexOutOfBoundsException if {@code index} is invalid.
+ * @exception ReadOnlyBufferException if no changes may be made to the contents of this buffer.
+ * @since Android 1.0 */
+ public abstract ByteBuffer putFloat (int index, float value);
+
+ /** Writes the given int to the current position and increases the position by 4.
+ *
+ * The int is converted to bytes using the current byte order.
+ *
+ *
+ * @param value the int to write.
+ * @return this buffer.
+ * @exception BufferOverflowException if position is greater than {@code limit - 4}.
+ * @exception ReadOnlyBufferException if no changes may be made to the contents of this buffer.
+ * @since Android 1.0 */
+ public abstract ByteBuffer putInt (int value);
+
+ /** Writes the given int to the specified index of this buffer.
+ *
+ * The int is converted to bytes using the current byte order. The position is not changed.
+ *
+ *
+ * @param index the index, must not be negative and equal or less than {@code limit - 4}.
+ * @param value the int to write.
+ * @return this buffer.
+ * @exception IndexOutOfBoundsException if {@code index} is invalid.
+ * @exception ReadOnlyBufferException if no changes may be made to the contents of this buffer.
+ * @since Android 1.0 */
+ public abstract ByteBuffer putInt (int index, int value);
+
+ /** Writes the given long to the current position and increases the position by 8.
+ *
+ * The long is converted to bytes using the current byte order.
+ *
+ *
+ * @param value the long to write.
+ * @return this buffer.
+ * @exception BufferOverflowException if position is greater than {@code limit - 8}.
+ * @exception ReadOnlyBufferException if no changes may be made to the contents of this buffer.
+ * @since Android 1.0 */
+ public abstract ByteBuffer putLong (long value);
+
+ /** Writes the given long to the specified index of this buffer.
+ *
+ * The long is converted to bytes using the current byte order. The position is not changed.
+ *
+ *
+ * @param index the index, must not be negative and equal or less than {@code limit - 8}.
+ * @param value the long to write.
+ * @return this buffer.
+ * @exception IndexOutOfBoundsException if {@code index} is invalid.
+ * @exception ReadOnlyBufferException if no changes may be made to the contents of this buffer.
+ * @since Android 1.0 */
+ public abstract ByteBuffer putLong (int index, long value);
+
+ /** Writes the given short to the current position and increases the position by 2.
+ *
+ * The short is converted to bytes using the current byte order.
+ *
+ *
+ * @param value the short to write.
+ * @return this buffer.
+ * @exception BufferOverflowException if position is greater than {@code limit - 2}.
+ * @exception ReadOnlyBufferException if no changes may be made to the contents of this buffer.
+ * @since Android 1.0 */
+ public abstract ByteBuffer putShort (short value);
+
+ /** Writes the given short to the specified index of this buffer.
+ *
+ * The short is converted to bytes using the current byte order. The position is not changed.
+ *
+ *
+ * @param index the index, must not be negative and equal or less than {@code limit - 2}.
+ * @param value the short to write.
+ * @return this buffer.
+ * @exception IndexOutOfBoundsException if {@code index} is invalid.
+ * @exception ReadOnlyBufferException if no changes may be made to the contents of this buffer.
+ * @since Android 1.0 */
+ public abstract ByteBuffer putShort (int index, short value);
+
+ /** Returns a sliced buffer that shares its content with this buffer.
+ *
+ * The sliced buffer's capacity will be this buffer's {@code remaining()}, and it's zero position will correspond to this
+ * buffer's current position. The new buffer's position will be 0, limit will be its capacity, and its mark is cleared. The new
+ * buffer's read-only property and byte order are the same as this buffer's.
+ *
+ *
+ * The new buffer shares its content with this buffer, which means either buffer's change of content will be visible to the
+ * other. The two buffer's position, limit and mark are independent.
+ *
+ *
+ * @return a sliced buffer that shares its content with this buffer.
+ * @since Android 1.0 */
+ public abstract ByteBuffer slice ();
+
+ /** Returns a string representing the state of this byte buffer.
+ *
+ * @return a string representing the state of this byte buffer.
+ * @since Android 1.0 */
+ public String toString () {
+ StringBuffer buf = new StringBuffer();
+ buf.append(getClass().getName());
+ buf.append(", status: capacity="); //$NON-NLS-1$
+ buf.append(capacity());
+ buf.append(" position="); //$NON-NLS-1$
+ buf.append(position());
+ buf.append(" limit="); //$NON-NLS-1$
+ buf.append(limit());
+ return buf.toString();
+ }
+
+ public ByteBuffer stringToByteBuffer (String s) {
+ return new StringByteBuffer(s);
+ }
}
diff --git a/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/java/nio/ByteBufferWrapper.java b/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/java/nio/ByteBufferWrapper.java
index 455a7bcab76..a8654af4e3c 100644
--- a/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/java/nio/ByteBufferWrapper.java
+++ b/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/java/nio/ByteBufferWrapper.java
@@ -13,10 +13,9 @@
* License for the specific language governing permissions and limitations under
* the License.
*/
-package java.nio;
-import java.nio.ByteBuffer;
+package java.nio;
public interface ByteBufferWrapper {
- ByteBuffer getByteBuffer();
+ ByteBuffer getByteBuffer ();
}
diff --git a/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/java/nio/ByteOrder.java b/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/java/nio/ByteOrder.java
index 70c2d910685..a5b0f470653 100644
--- a/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/java/nio/ByteOrder.java
+++ b/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/java/nio/ByteOrder.java
@@ -16,67 +16,54 @@
package java.nio;
-
//import org.apache.harmony.luni.platform.Platform;
-/**
- * Defines byte order constants.
+/** Defines byte order constants.
*
- * @since Android 1.0
- */
+ * @since Android 1.0 */
public final class ByteOrder {
- /**
- * This constant represents big endian.
- *
- * @since Android 1.0
- */
- public static final ByteOrder BIG_ENDIAN = new ByteOrder("BIG_ENDIAN"); //$NON-NLS-1$
+ /** This constant represents big endian.
+ *
+ * @since Android 1.0 */
+ public static final ByteOrder BIG_ENDIAN = new ByteOrder("BIG_ENDIAN"); //$NON-NLS-1$
- /**
- * This constant represents little endian.
- *
- * @since Android 1.0
- */
- public static final ByteOrder LITTLE_ENDIAN = new ByteOrder("LITTLE_ENDIAN"); //$NON-NLS-1$
+ /** This constant represents little endian.
+ *
+ * @since Android 1.0 */
+ public static final ByteOrder LITTLE_ENDIAN = new ByteOrder("LITTLE_ENDIAN"); //$NON-NLS-1$
- private static final ByteOrder NATIVE_ORDER;
+ private static final ByteOrder NATIVE_ORDER;
- static {
-// if (Platform.getMemorySystem().isLittleEndian()) {
- NATIVE_ORDER = LITTLE_ENDIAN;
-// } else {
-// NATIVE_ORDER = BIG_ENDIAN;
-// }
- }
+ static {
+// if (Platform.getMemorySystem().isLittleEndian()) {
+ NATIVE_ORDER = LITTLE_ENDIAN;
+// } else {
+// NATIVE_ORDER = BIG_ENDIAN;
+// }
+ }
- /**
- * Returns the current platform byte order.
- *
- * @return the byte order object, which is either LITTLE_ENDIAN or
- * BIG_ENDIAN.
- * @since Android 1.0
- */
- public static ByteOrder nativeOrder() {
- return NATIVE_ORDER;
- }
+ /** Returns the current platform byte order.
+ *
+ * @return the byte order object, which is either LITTLE_ENDIAN or BIG_ENDIAN.
+ * @since Android 1.0 */
+ public static ByteOrder nativeOrder () {
+ return NATIVE_ORDER;
+ }
- private final String name;
+ private final String name;
- private ByteOrder(String name) {
- super();
- this.name = name;
- }
+ private ByteOrder (String name) {
+ super();
+ this.name = name;
+ }
- /**
- * Returns a string that describes this object.
- *
- * @return "BIG_ENDIAN" for {@link #BIG_ENDIAN ByteOrder.BIG_ENDIAN}
- * objects, "LITTLE_ENDIAN" for
- * {@link #LITTLE_ENDIAN ByteOrder.LITTLE_ENDIAN} objects.
- * @since Android 1.0
- */
- public String toString() {
- return name;
- }
+ /** Returns a string that describes this object.
+ *
+ * @return "BIG_ENDIAN" for {@link #BIG_ENDIAN ByteOrder.BIG_ENDIAN} objects, "LITTLE_ENDIAN" for {@link #LITTLE_ENDIAN
+ * ByteOrder.LITTLE_ENDIAN} objects.
+ * @since Android 1.0 */
+ public String toString () {
+ return name;
+ }
}
diff --git a/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/java/nio/CharArrayBuffer.java b/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/java/nio/CharArrayBuffer.java
index 516aada5176..17a0522b464 100644
--- a/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/java/nio/CharArrayBuffer.java
+++ b/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/java/nio/CharArrayBuffer.java
@@ -17,85 +17,80 @@
package java.nio;
-/**
- * CharArrayBuffer, ReadWriteCharArrayBuffer and ReadOnlyCharArrayBuffer compose
- * the implementation of array based char buffers.
+/** CharArrayBuffer, ReadWriteCharArrayBuffer and ReadOnlyCharArrayBuffer compose the implementation of array based char buffers.
*
- * CharArrayBuffer implements all the shared readonly methods and is extended by
- * the other two classes.
+ * CharArrayBuffer implements all the shared readonly methods and is extended by the other two classes.
*
*
* All methods are marked final for runtime performance.
- *
- *
- */
+ * */
abstract class CharArrayBuffer extends CharBuffer {
- protected final char[] backingArray;
+ protected final char[] backingArray;
+
+ protected final int offset;
+
+ CharArrayBuffer (char[] array) {
+ this(array.length, array, 0);
+ }
- protected final int offset;
+ CharArrayBuffer (int capacity) {
+ this(capacity, new char[capacity], 0);
+ }
- CharArrayBuffer(char[] array) {
- this(array.length, array, 0);
- }
+ CharArrayBuffer (int capacity, char[] backingArray, int offset) {
+ super(capacity);
+ this.backingArray = backingArray;
+ this.offset = offset;
+ }
- CharArrayBuffer(int capacity) {
- this(capacity, new char[capacity], 0);
- }
+ public final char get () {
+ if (position == limit) {
+ throw new BufferUnderflowException();
+ }
+ return backingArray[offset + position++];
+ }
- CharArrayBuffer(int capacity, char[] backingArray, int offset) {
- super(capacity);
- this.backingArray = backingArray;
- this.offset = offset;
- }
+ public final char get (int index) {
+ if (index < 0 || index >= limit) {
+ throw new IndexOutOfBoundsException();
+ }
+ return backingArray[offset + index];
+ }
- public final char get() {
- if (position == limit) {
- throw new BufferUnderflowException();
- }
- return backingArray[offset + position++];
- }
+ public final CharBuffer get (char[] dest, int off, int len) {
+ int length = dest.length;
+ if ((off < 0) || (len < 0) || (long)off + (long)len > length) {
+ throw new IndexOutOfBoundsException();
+ }
+ if (len > remaining()) {
+ throw new BufferUnderflowException();
+ }
+ System.arraycopy(backingArray, offset + position, dest, off, len);
+ position += len;
+ return this;
+ }
- public final char get(int index) {
- if (index < 0 || index >= limit) {
- throw new IndexOutOfBoundsException();
- }
- return backingArray[offset + index];
- }
+ public final boolean isDirect () {
+ return false;
+ }
- public final CharBuffer get(char[] dest, int off, int len) {
- int length = dest.length;
- if ((off < 0 ) || (len < 0) || (long)off + (long)len > length) {
- throw new IndexOutOfBoundsException();
- }
- if (len > remaining()) {
- throw new BufferUnderflowException();
- }
- System.arraycopy(backingArray, offset+position, dest, off, len);
- position += len;
- return this;
- }
-
- public final boolean isDirect() {
- return false;
- }
+ public final ByteOrder order () {
+ return ByteOrder.nativeOrder();
+ }
- public final ByteOrder order() {
- return ByteOrder.nativeOrder();
- }
+ public final CharSequence subSequence (int start, int end) {
+ if (start < 0 || end < start || end > remaining()) {
+ throw new IndexOutOfBoundsException();
+ }
- public final CharSequence subSequence(int start, int end) {
- if (start < 0 || end < start || end > remaining()) {
- throw new IndexOutOfBoundsException();
- }
-
- CharBuffer result = duplicate();
- result.limit(position + end);
- result.position(position + start);
- return result;
- }
+ CharBuffer result = duplicate();
+ result.limit(position + end);
+ result.position(position + start);
+ return result;
+ }
- public final String toString() {
- return String.copyValueOf(backingArray, offset + position, remaining());
- }
+ public final String toString () {
+ return String.copyValueOf(backingArray, offset + position, remaining());
+ }
}
diff --git a/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/java/nio/CharBuffer.java b/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/java/nio/CharBuffer.java
index 2fc8c2a82b0..e5c4dad4c5e 100644
--- a/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/java/nio/CharBuffer.java
+++ b/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/java/nio/CharBuffer.java
@@ -19,838 +19,605 @@
import java.io.IOException;
-/**
- * A buffer of chars.
+/** A buffer of chars.
*
* A char buffer can be created in either one of the following ways:
*
*
- * {@link #allocate(int) Allocate} a new char array and create a buffer
- * based on it;
- * {@link #wrap(char[]) Wrap} an existing char array to create a new
- * buffer;
- * {@link #wrap(CharSequence) Wrap} an existing char sequence to create a
- * new buffer;
- * Use {@link java.nio.ByteBuffer#asCharBuffer() ByteBuffer.asCharBuffer}
- * to create a char buffer based on a byte buffer.
+ * {@link #allocate(int) Allocate} a new char array and create a buffer based on it;
+ * {@link #wrap(char[]) Wrap} an existing char array to create a new buffer;
+ * {@link #wrap(CharSequence) Wrap} an existing char sequence to create a new buffer;
+ * Use {@link java.nio.ByteBuffer#asCharBuffer() ByteBuffer.asCharBuffer} to create a char buffer based on a byte buffer.
*
*
- * @since Android 1.0
- */
-public abstract class CharBuffer extends Buffer implements Comparable,
- CharSequence, Appendable {//, Readable {
-
- /**
- * Creates a char buffer based on a newly allocated char array.
- *
- * @param capacity
- * the capacity of the new buffer.
- * @return the created char buffer.
- * @throws IllegalArgumentException
- * if {@code capacity} is less than zero.
- * @since Android 1.0
- */
- public static CharBuffer allocate(int capacity) {
- if (capacity < 0) {
- throw new IllegalArgumentException();
- }
- return BufferFactory.newCharBuffer(capacity);
- }
-
- /**
- * Creates a new char buffer by wrapping the given char array.
- *
- * Calling this method has the same effect as
- * {@code wrap(array, 0, array.length)}.
- *
- *
- * @param array
- * the char array which the new buffer will be based on.
- * @return the created char buffer.
- * @since Android 1.0
- */
- public static CharBuffer wrap(char[] array) {
- return wrap(array, 0, array.length);
- }
-
- /**
- * Creates a new char buffer by wrapping the given char array.
- *
- * The new buffer's position will be {@code start}, limit will be
- * {@code start + len}, capacity will be the length of the array.
- *
- *
- * @param array
- * the char array which the new buffer will be based on.
- * @param start
- * the start index, must not be negative and not greater than
- * {@code array.length}.
- * @param len
- * the length, must not be negative and not greater than
- * {@code array.length - start}.
- * @return the created char buffer.
- * @exception IndexOutOfBoundsException
- * if either {@code start} or {@code len} is invalid.
- * @since Android 1.0
- */
- public static CharBuffer wrap(char[] array, int start, int len) {
- int length = array.length;
- if ((start < 0) || (len < 0)
- || (long) start + (long) len > length) {
- throw new IndexOutOfBoundsException();
- }
-
- CharBuffer buf = BufferFactory.newCharBuffer(array);
- buf.position = start;
- buf.limit = start + len;
-
- return buf;
- }
-
- /**
- * Creates a new char buffer by wrapping the given char sequence.
- *
- * Calling this method has the same effect as
- * {@code wrap(chseq, 0, chseq.length())}.
- *
- *
- * @param chseq
- * the char sequence which the new buffer will be based on.
- * @return the created char buffer.
- * @since Android 1.0
- */
- public static CharBuffer wrap(CharSequence chseq) {
- return BufferFactory.newCharBuffer(chseq);
- }
-
- /**
- * Creates a new char buffer by wrapping the given char sequence.
- *
- * The new buffer's position will be {@code start}, limit will be
- * {@code end}, capacity will be the length of the char sequence. The new
- * buffer is read-only.
- *
- *
- * @param chseq
- * the char sequence which the new buffer will be based on.
- * @param start
- * the start index, must not be negative and not greater than
- * {@code chseq.length()}.
- * @param end
- * the end index, must be no less than {@code start} and no
- * greater than {@code chseq.length()}.
- * @return the created char buffer.
- * @exception IndexOutOfBoundsException
- * if either {@code start} or {@code end} is invalid.
- * @since Android 1.0
- */
- public static CharBuffer wrap(CharSequence chseq, int start, int end) {
- if (chseq == null) {
- throw new NullPointerException();
- }
- if (start < 0 || end < start || end > chseq.length()) {
- throw new IndexOutOfBoundsException();
- }
-
- CharBuffer result = BufferFactory.newCharBuffer(chseq);
- result.position = start;
- result.limit = end;
- return result;
- }
-
- /**
- * Constructs a {@code CharBuffer} with given capacity.
- *
- * @param capacity
- * the capacity of the buffer.
- * @since Android 1.0
- */
- CharBuffer(int capacity) {
- super(capacity);
- }
-
- /**
- * Returns the char array which this buffer is based on, if there is one.
- *
- * @return the char array which this buffer is based on.
- * @exception ReadOnlyBufferException
- * if this buffer is based on an array, but it is read-only.
- * @exception UnsupportedOperationException
- * if this buffer is not based on an array.
- * @since Android 1.0
- */
- public final char[] array() {
- return protectedArray();
- }
-
- /**
- * Returns the offset of the char array which this buffer is based on, if
- * there is one.
- *
- * The offset is the index of the array corresponds to the zero position of
- * the buffer.
- *
- *
- * @return the offset of the char array which this buffer is based on.
- * @exception ReadOnlyBufferException
- * if this buffer is based on an array but it is read-only.
- * @exception UnsupportedOperationException
- * if this buffer is not based on an array.
- * @since Android 1.0
- */
- public final int arrayOffset() {
- return protectedArrayOffset();
- }
-
- /**
- * Returns a read-only buffer that shares its content with this buffer.
- *
- * The returned buffer is guaranteed to be a new instance, even if this
- * buffer is read-only itself. The new buffer's position, limit, capacity
- * and mark are the same as this buffer's.
- *
- *
- * The new buffer shares its content with this buffer, which means this
- * buffer's change of content will be visible to the new buffer. The two
- * buffer's position, limit and mark are independent.
- *
- *
- * @return a read-only version of this buffer.
- * @since Android 1.0
- */
- public abstract CharBuffer asReadOnlyBuffer();
-
- /**
- * Returns the character located at the specified index in the buffer. The
- * index value is referenced from the current buffer position.
- *
- * @param index
- * the index referenced from the current buffer position. It must
- * not be less than zero but less than the value obtained from a
- * call to {@code remaining()}.
- * @return the character located at the specified index (referenced from the
- * current position) in the buffer.
- * @exception IndexOutOfBoundsException
- * if the index is invalid.
- * @since Android 1.0
- */
- public final char charAt(int index) {
- if (index < 0 || index >= remaining()) {
- throw new IndexOutOfBoundsException();
- }
- return get(position + index);
- }
-
- /**
- * Compacts this char buffer.
- *
- * The remaining chars will be moved to the head of the buffer,
- * starting from position zero. Then the position is set to
- * {@code remaining()}; the limit is set to capacity; the mark is cleared.
- *
- *
- * @return this buffer.
- * @exception ReadOnlyBufferException
- * if no changes may be made to the contents of this buffer.
- * @since Android 1.0
- */
- public abstract CharBuffer compact();
-
- /**
- * Compare the remaining chars of this buffer to another char
- * buffer's remaining chars.
- *
- * @param otherBuffer
- * another char buffer.
- * @return a negative value if this is less than {@code otherBuffer}; 0 if
- * this equals to {@code otherBuffer}; a positive value if this is
- * greater than {@code otherBuffer}.
- * @exception ClassCastException
- * if {@code otherBuffer} is not a char buffer.
- * @since Android 1.0
- */
- public int compareTo(CharBuffer otherBuffer) {
- int compareRemaining = (remaining() < otherBuffer.remaining()) ? remaining()
- : otherBuffer.remaining();
- int thisPos = position;
- int otherPos = otherBuffer.position;
- char thisByte, otherByte;
- while (compareRemaining > 0) {
- thisByte = get(thisPos);
- otherByte = otherBuffer.get(otherPos);
- if (thisByte != otherByte) {
- return thisByte < otherByte ? -1 : 1;
- }
- thisPos++;
- otherPos++;
- compareRemaining--;
- }
- return remaining() - otherBuffer.remaining();
- }
-
- /**
- * Returns a duplicated buffer that shares its content with this buffer.
- *
- * The duplicated buffer's initial position, limit, capacity and mark are
- * the same as this buffer's. The duplicated buffer's read-only property and
- * byte order are the same as this buffer's, too.
- *
- *
- * The new buffer shares its content with this buffer, which means either
- * buffer's change of content will be visible to the other. The two buffer's
- * position, limit and mark are independent.
- *
- *
- * @return a duplicated buffer that shares its content with this buffer.
- * @since Android 1.0
- */
- public abstract CharBuffer duplicate();
-
- /**
- * Checks whether this char buffer is equal to another object.
- *
- * If {@code other} is not a char buffer then {@code false} is returned. Two
- * char buffers are equal if and only if their remaining chars are exactly
- * the same. Position, limit, capacity and mark are not considered.
- *
- *
- * @param other
- * the object to compare with this char buffer.
- * @return {@code true} if this char buffer is equal to {@code other},
- * {@code false} otherwise.
- * @since Android 1.0
- */
- public boolean equals(Object other) {
- if (!(other instanceof CharBuffer)) {
- return false;
- }
- CharBuffer otherBuffer = (CharBuffer) other;
-
- if (remaining() != otherBuffer.remaining()) {
- return false;
- }
-
- int myPosition = position;
- int otherPosition = otherBuffer.position;
- boolean equalSoFar = true;
- while (equalSoFar && (myPosition < limit)) {
- equalSoFar = get(myPosition++) == otherBuffer.get(otherPosition++);
- }
-
- return equalSoFar;
- }
-
- /**
- * Returns the char at the current position and increases the position by 1.
- *
- * @return the char at the current position.
- * @exception BufferUnderflowException
- * if the position is equal or greater than limit.
- * @since Android 1.0
- */
- public abstract char get();
-
- /**
- * Reads chars from the current position into the specified char array and
- * increases the position by the number of chars read.
- *
- * Calling this method has the same effect as
- * {@code get(dest, 0, dest.length)}.
- *
- *
- * @param dest
- * the destination char array.
- * @return this buffer.
- * @exception BufferUnderflowException
- * if {@code dest.length} is greater than {@code remaining()}.
- * @since Android 1.0
- */
- public CharBuffer get(char[] dest) {
- return get(dest, 0, dest.length);
- }
-
- /**
- * Reads chars from the current position into the specified char array,
- * starting from the specified offset, and increases the position by the
- * number of chars read.
- *
- * @param dest
- * the target char array.
- * @param off
- * the offset of the char array, must not be negative and not
- * greater than {@code dest.length}.
- * @param len
- * The number of chars to read, must be no less than zero and no
- * greater than {@code dest.length - off}.
- * @return this buffer.
- * @exception IndexOutOfBoundsException
- * if either {@code off} or {@code len} is invalid.
- * @exception BufferUnderflowException
- * if {@code len} is greater than {@code remaining()}.
- * @since Android 1.0
- */
- public CharBuffer get(char[] dest, int off, int len) {
- int length = dest.length;
- if ((off < 0 ) || (len < 0) || (long)off + (long)len > length) {
- throw new IndexOutOfBoundsException();
- }
-
- if (len > remaining()) {
- throw new BufferUnderflowException();
- }
- for (int i = off; i < off + len; i++) {
- dest[i] = get();
- }
- return this;
- }
-
- /**
- * Returns a char at the specified index; the position is not changed.
- *
- * @param index
- * the index, must not be negative and less than limit.
- * @return a char at the specified index.
- * @exception IndexOutOfBoundsException
- * if index is invalid.
- * @since Android 1.0
- */
- public abstract char get(int index);
-
- /**
- * Indicates whether this buffer is based on a char array and is read/write.
- *
- * @return {@code true} if this buffer is based on a byte array and provides
- * read/write access, {@code false} otherwise.
- * @since Android 1.0
- */
- public final boolean hasArray() {
- return protectedHasArray();
- }
-
- /**
- * Calculates this buffer's hash code from the remaining chars. The
- * position, limit, capacity and mark don't affect the hash code.
- *
- * @return the hash code calculated from the remaining chars.
- * @since Android 1.0
- */
- public int hashCode() {
- int myPosition = position;
- int hash = 0;
- while (myPosition < limit) {
- hash = hash + get(myPosition++);
- }
- return hash;
- }
-
- /**
- * Indicates whether this buffer is direct. A direct buffer will try its
- * best to take advantage of native memory APIs and it may not stay in the
- * Java heap, so it is not affected by garbage collection.
- *
- * A char buffer is direct if it is based on a byte buffer and the byte
- * buffer is direct.
- *
- *
- * @return {@code true} if this buffer is direct, {@code false} otherwise.
- * @since Android 1.0
- */
- public abstract boolean isDirect();
-
- /**
- * Returns the number of remaining chars.
- *
- * @return the number of remaining chars.
- * @since Android 1.0
- */
- public final int length() {
- return remaining();
- }
-
- /**
- * Returns the byte order used by this buffer when converting chars from/to
- * bytes.
- *
- * If this buffer is not based on a byte buffer, then this always returns
- * the platform's native byte order.
- *
- *
- * @return the byte order used by this buffer when converting chars from/to
- * bytes.
- * @since Android 1.0
- */
- public abstract ByteOrder order();
-
- /**
- * Child class implements this method to realize {@code array()}.
- *
- * @see #array()
- */
- abstract char[] protectedArray();
-
- /**
- * Child class implements this method to realize {@code arrayOffset()}.
- *
- * @see #arrayOffset()
- */
- abstract int protectedArrayOffset();
-
- /**
- * Child class implements this method to realize {@code hasArray()}.
- *
- * @see #hasArray()
- */
- abstract boolean protectedHasArray();
-
- /**
- * Writes the given char to the current position and increases the position
- * by 1.
- *
- * @param c
- * the char to write.
- * @return this buffer.
- * @exception BufferOverflowException
- * if position is equal or greater than limit.
- * @exception ReadOnlyBufferException
- * if no changes may be made to the contents of this buffer.
- * @since Android 1.0
- */
- public abstract CharBuffer put(char c);
-
- /**
- * Writes chars from the given char array to the current position and
- * increases the position by the number of chars written.
- *
- * Calling this method has the same effect as
- * {@code put(src, 0, src.length)}.
- *
- *
- * @param src
- * the source char array.
- * @return this buffer.
- * @exception BufferOverflowException
- * if {@code remaining()} is less than {@code src.length}.
- * @exception ReadOnlyBufferException
- * if no changes may be made to the contents of this buffer.
- * @since Android 1.0
- */
- public final CharBuffer put(char[] src) {
- return put(src, 0, src.length);
- }
-
- /**
- * Writes chars from the given char array, starting from the specified offset,
- * to the current position and increases the position by the number of chars
- * written.
- *
- * @param src
- * the source char array.
- * @param off
- * the offset of char array, must not be negative and not greater
- * than {@code src.length}.
- * @param len
- * the number of chars to write, must be no less than zero and no
- * greater than {@code src.length - off}.
- * @return this buffer.
- * @exception BufferOverflowException
- * if {@code remaining()} is less than {@code len}.
- * @exception IndexOutOfBoundsException
- * if either {@code off} or {@code len} is invalid.
- * @exception ReadOnlyBufferException
- * if no changes may be made to the contents of this buffer.
- * @since Android 1.0
- */
- public CharBuffer put(char[] src, int off, int len) {
- int length = src.length;
- if ((off < 0 ) || (len < 0) || (long)off + (long)len > length) {
- throw new IndexOutOfBoundsException();
- }
-
- if (len > remaining()) {
- throw new BufferOverflowException();
- }
- for (int i = off; i < off + len; i++) {
- put(src[i]);
- }
- return this;
- }
-
- /**
- * Writes all the remaining chars of the {@code src} char buffer to this
- * buffer's current position, and increases both buffers' position by the
- * number of chars copied.
- *
- * @param src
- * the source char buffer.
- * @return this buffer.
- * @exception BufferOverflowException
- * if {@code src.remaining()} is greater than this buffer's
- * {@code remaining()}.
- * @exception IllegalArgumentException
- * if {@code src} is this buffer.
- * @exception ReadOnlyBufferException
- * if no changes may be made to the contents of this buffer.
- * @since Android 1.0
- */
- public CharBuffer put(CharBuffer src) {
- if (src == this) {
- throw new IllegalArgumentException();
- }
- if (src.remaining() > remaining()) {
- throw new BufferOverflowException();
- }
-
- char[] contents = new char[src.remaining()];
- src.get(contents);
- put(contents);
- return this;
- }
-
- /**
- * Writes a char to the specified index of this buffer; the position is not
- * changed.
- *
- * @param index
- * the index, must be no less than zero and less than the limit.
- * @param c
- * the char to write.
- * @return this buffer.
- * @exception IndexOutOfBoundsException
- * if index is invalid.
- * @exception ReadOnlyBufferException
- * if no changes may be made to the contents of this buffer.
- * @since Android 1.0
- */
- public abstract CharBuffer put(int index, char c);
-
- /**
- * Writes all chars of the given string to the current position of this
- * buffer, and increases the position by the length of string.
- *
- * Calling this method has the same effect as
- * {@code put(str, 0, str.length())}.
- *
- *
- * @param str
- * the string to write.
- * @return this buffer.
- * @exception BufferOverflowException
- * if {@code remaining()} is less than the length of string.
- * @exception ReadOnlyBufferException
- * if no changes may be made to the contents of this buffer.
- * @since Android 1.0
- */
- public final CharBuffer put(String str) {
- return put(str, 0, str.length());
- }
-
- /**
- * Writes chars of the given string to the current position of this buffer,
- * and increases the position by the number of chars written.
- *
- * @param str
- * the string to write.
- * @param start
- * the first char to write, must not be negative and not greater
- * than {@code str.length()}.
- * @param end
- * the last char to write (excluding), must be less than
- * {@code start} and not greater than {@code str.length()}.
- * @return this buffer.
- * @exception BufferOverflowException
- * if {@code remaining()} is less than {@code end - start}.
- * @exception IndexOutOfBoundsException
- * if either {@code start} or {@code end} is invalid.
- * @exception ReadOnlyBufferException
- * if no changes may be made to the contents of this buffer.
- * @since Android 1.0
- */
- public CharBuffer put(String str, int start, int end) {
- int length = str.length();
- if (start < 0 || end < start || end > length) {
- throw new IndexOutOfBoundsException();
- }
-
- if (end - start > remaining()) {
- throw new BufferOverflowException();
- }
- for (int i = start; i < end; i++) {
- put(str.charAt(i));
- }
- return this;
- }
-
- /**
- * Returns a sliced buffer that shares its content with this buffer.
- *
- * The sliced buffer's capacity will be this buffer's {@code remaining()},
- * and its zero position will correspond to this buffer's current position.
- * The new buffer's position will be 0, limit will be its capacity, and its
- * mark is cleared. The new buffer's read-only property and byte order are
- * same as this buffer.
- *
- *
- * The new buffer shares its content with this buffer, which means either
- * buffer's change of content will be visible to the other. The two buffer's
- * position, limit and mark are independent.
- *
- *
- * @return a sliced buffer that shares its content with this buffer.
- * @since Android 1.0
- */
- public abstract CharBuffer slice();
-
- /**
- * Returns a new char buffer representing a sub-sequence of this buffer's
- * current remaining content.
- *
- * The new buffer's position will be {@code position() + start}, limit will
- * be {@code position() + end}, capacity will be the same as this buffer.
- * The new buffer's read-only property and byte order are the same as this
- * buffer.
- *
- *
- * The new buffer shares its content with this buffer, which means either
- * buffer's change of content will be visible to the other. The two buffer's
- * position, limit and mark are independent.
- *
- *
- * @param start
- * the start index of the sub-sequence, referenced from the
- * current buffer position. Must not be less than zero and not
- * greater than the value obtained from a call to
- * {@code remaining()}.
- * @param end
- * the end index of the sub-sequence, referenced from the current
- * buffer position. Must not be less than {@code start} and not
- * be greater than the value obtained from a call to
- * {@code remaining()}.
- * @return a new char buffer represents a sub-sequence of this buffer's
- * current remaining content.
- * @exception IndexOutOfBoundsException
- * if either {@code start} or {@code end} is invalid.
- * @since Android 1.0
- */
- public abstract CharSequence subSequence(int start, int end);
-
- /**
- * Returns a string representing the current remaining chars of this buffer.
- *
- * @return a string representing the current remaining chars of this buffer.
- * @since Android 1.0
- */
- public String toString() {
- StringBuffer strbuf = new StringBuffer();
- for (int i = position; i < limit; i++) {
- strbuf.append(get(i));
- }
- return strbuf.toString();
- }
-
- /**
- * Writes the given char to the current position and increases the position
- * by 1.
- *
- * @param c
- * the char to write.
- * @return this buffer.
- * @exception BufferOverflowException
- * if position is equal or greater than limit.
- * @exception ReadOnlyBufferException
- * if no changes may be made to the contents of this buffer.
- * @since Android 1.0
- */
- public CharBuffer append(char c){
- return put(c);
- }
-
- /**
- * Writes all chars of the given character sequence {@code csq} to the
- * current position of this buffer, and increases the position by the length
- * of the csq.
- *
- * Calling this method has the same effect as {@code append(csq.toString())}.
- *
- * If the {@code CharSequence} is {@code null} the string "null" will be
- * written to the buffer.
- *
- * @param csq
- * the {@code CharSequence} to write.
- * @return this buffer.
- * @exception BufferOverflowException
- * if {@code remaining()} is less than the length of csq.
- * @exception ReadOnlyBufferException
- * if no changes may be made to the contents of this buffer.
- * @since Android 1.0
- */
- public CharBuffer append(CharSequence csq){
- if (csq != null) {
- return put(csq.toString());
- }
- return put("null"); //$NON-NLS-1$
- }
-
- /**
- * Writes chars of the given {@code CharSequence} to the current position of
- * this buffer, and increases the position by the number of chars written.
- *
- * @param csq
- * the {@code CharSequence} to write.
- * @param start
- * the first char to write, must not be negative and not greater
- * than {@code csq.length()}.
- * @param end
- * the last char to write (excluding), must be less than
- * {@code start} and not greater than {@code csq.length()}.
- * @return this buffer.
- * @exception BufferOverflowException
- * if {@code remaining()} is less than {@code end - start}.
- * @exception IndexOutOfBoundsException
- * if either {@code start} or {@code end} is invalid.
- * @exception ReadOnlyBufferException
- * if no changes may be made to the contents of this buffer.
- * @since Android 1.0
- */
- public CharBuffer append(CharSequence csq, int start, int end){
- if (csq == null) {
- csq = "null"; //$NON-NLS-1$
- }
- CharSequence cs = csq.subSequence(start, end);
- if (cs.length() > 0) {
- return put(cs.toString());
- }
- return this;
- }
-
- /**
- * Reads characters from this buffer and puts them into {@code target}. The
- * number of chars that are copied is either the number of remaining chars
- * in this buffer or the number of remaining chars in {@code target},
- * whichever is smaller.
- *
- * @param target
- * the target char buffer.
- * @throws IllegalArgumentException
- * if {@code target} is this buffer.
- * @throws IOException
- * if an I/O error occurs.
- * @throws ReadOnlyBufferException
- * if no changes may be made to the contents of {@code target}.
- * @return the number of chars copied or -1 if there are no chars left to be
- * read from this buffer.
- * @since Android 1.0
- */
- public int read(CharBuffer target) throws IOException {
- if(target == this){
- throw new IllegalArgumentException();
- }
- if (remaining() == 0) {
- return target.remaining()==0?0:-1;
- }
- int result = Math.min(target.remaining(), remaining());
- char[] chars = new char[result];
- get(chars);
- target.put(chars);
- return result;
- }
+ * @since Android 1.0 */
+public abstract class CharBuffer extends Buffer implements Comparable, CharSequence, Appendable {// , Readable {
+
+ /** Creates a char buffer based on a newly allocated char array.
+ *
+ * @param capacity the capacity of the new buffer.
+ * @return the created char buffer.
+ * @throws IllegalArgumentException if {@code capacity} is less than zero.
+ * @since Android 1.0 */
+ public static CharBuffer allocate (int capacity) {
+ if (capacity < 0) {
+ throw new IllegalArgumentException();
+ }
+ return BufferFactory.newCharBuffer(capacity);
+ }
+
+ /** Creates a new char buffer by wrapping the given char array.
+ *
+ * Calling this method has the same effect as {@code wrap(array, 0, array.length)}.
+ *
+ *
+ * @param array the char array which the new buffer will be based on.
+ * @return the created char buffer.
+ * @since Android 1.0 */
+ public static CharBuffer wrap (char[] array) {
+ return wrap(array, 0, array.length);
+ }
+
+ /** Creates a new char buffer by wrapping the given char array.
+ *
+ * The new buffer's position will be {@code start}, limit will be {@code start + len}, capacity will be the length of the
+ * array.
+ *
+ *
+ * @param array the char array which the new buffer will be based on.
+ * @param start the start index, must not be negative and not greater than {@code array.length}.
+ * @param len the length, must not be negative and not greater than {@code array.length - start}.
+ * @return the created char buffer.
+ * @exception IndexOutOfBoundsException if either {@code start} or {@code len} is invalid.
+ * @since Android 1.0 */
+ public static CharBuffer wrap (char[] array, int start, int len) {
+ int length = array.length;
+ if ((start < 0) || (len < 0) || (long)start + (long)len > length) {
+ throw new IndexOutOfBoundsException();
+ }
+
+ CharBuffer buf = BufferFactory.newCharBuffer(array);
+ buf.position = start;
+ buf.limit = start + len;
+
+ return buf;
+ }
+
+ /** Creates a new char buffer by wrapping the given char sequence.
+ *
+ * Calling this method has the same effect as {@code wrap(chseq, 0, chseq.length())}.
+ *
+ *
+ * @param chseq the char sequence which the new buffer will be based on.
+ * @return the created char buffer.
+ * @since Android 1.0 */
+ public static CharBuffer wrap (CharSequence chseq) {
+ return BufferFactory.newCharBuffer(chseq);
+ }
+
+ /** Creates a new char buffer by wrapping the given char sequence.
+ *
+ * The new buffer's position will be {@code start}, limit will be {@code end}, capacity will be the length of the char
+ * sequence. The new buffer is read-only.
+ *
+ *
+ * @param chseq the char sequence which the new buffer will be based on.
+ * @param start the start index, must not be negative and not greater than {@code chseq.length()}.
+ * @param end the end index, must be no less than {@code start} and no greater than {@code chseq.length()}.
+ * @return the created char buffer.
+ * @exception IndexOutOfBoundsException if either {@code start} or {@code end} is invalid.
+ * @since Android 1.0 */
+ public static CharBuffer wrap (CharSequence chseq, int start, int end) {
+ if (chseq == null) {
+ throw new NullPointerException();
+ }
+ if (start < 0 || end < start || end > chseq.length()) {
+ throw new IndexOutOfBoundsException();
+ }
+
+ CharBuffer result = BufferFactory.newCharBuffer(chseq);
+ result.position = start;
+ result.limit = end;
+ return result;
+ }
+
+ /** Constructs a {@code CharBuffer} with given capacity.
+ *
+ * @param capacity the capacity of the buffer.
+ * @since Android 1.0 */
+ CharBuffer (int capacity) {
+ super(capacity);
+ }
+
+ /** Returns the char array which this buffer is based on, if there is one.
+ *
+ * @return the char array which this buffer is based on.
+ * @exception ReadOnlyBufferException if this buffer is based on an array, but it is read-only.
+ * @exception UnsupportedOperationException if this buffer is not based on an array.
+ * @since Android 1.0 */
+ public final char[] array () {
+ return protectedArray();
+ }
+
+ /** Returns the offset of the char array which this buffer is based on, if there is one.
+ *
+ * The offset is the index of the array corresponds to the zero position of the buffer.
+ *
+ *
+ * @return the offset of the char array which this buffer is based on.
+ * @exception ReadOnlyBufferException if this buffer is based on an array but it is read-only.
+ * @exception UnsupportedOperationException if this buffer is not based on an array.
+ * @since Android 1.0 */
+ public final int arrayOffset () {
+ return protectedArrayOffset();
+ }
+
+ /** Returns a read-only buffer that shares its content with this buffer.
+ *
+ * The returned buffer is guaranteed to be a new instance, even if this buffer is read-only itself. The new buffer's position,
+ * limit, capacity and mark are the same as this buffer's.
+ *
+ *
+ * The new buffer shares its content with this buffer, which means this buffer's change of content will be visible to the new
+ * buffer. The two buffer's position, limit and mark are independent.
+ *
+ *
+ * @return a read-only version of this buffer.
+ * @since Android 1.0 */
+ public abstract CharBuffer asReadOnlyBuffer ();
+
+ /** Returns the character located at the specified index in the buffer. The index value is referenced from the current buffer
+ * position.
+ *
+ * @param index the index referenced from the current buffer position. It must not be less than zero but less than the value
+ * obtained from a call to {@code remaining()}.
+ * @return the character located at the specified index (referenced from the current position) in the buffer.
+ * @exception IndexOutOfBoundsException if the index is invalid.
+ * @since Android 1.0 */
+ public final char charAt (int index) {
+ if (index < 0 || index >= remaining()) {
+ throw new IndexOutOfBoundsException();
+ }
+ return get(position + index);
+ }
+
+ /** Compacts this char buffer.
+ *
+ * The remaining chars will be moved to the head of the buffer, starting from position zero. Then the position is set to
+ * {@code remaining()}; the limit is set to capacity; the mark is cleared.
+ *
+ *
+ * @return this buffer.
+ * @exception ReadOnlyBufferException if no changes may be made to the contents of this buffer.
+ * @since Android 1.0 */
+ public abstract CharBuffer compact ();
+
+ /** Compare the remaining chars of this buffer to another char buffer's remaining chars.
+ *
+ * @param otherBuffer another char buffer.
+ * @return a negative value if this is less than {@code otherBuffer}; 0 if this equals to {@code otherBuffer}; a positive value
+ * if this is greater than {@code otherBuffer}.
+ * @exception ClassCastException if {@code otherBuffer} is not a char buffer.
+ * @since Android 1.0 */
+ public int compareTo (CharBuffer otherBuffer) {
+ int compareRemaining = (remaining() < otherBuffer.remaining()) ? remaining() : otherBuffer.remaining();
+ int thisPos = position;
+ int otherPos = otherBuffer.position;
+ char thisByte, otherByte;
+ while (compareRemaining > 0) {
+ thisByte = get(thisPos);
+ otherByte = otherBuffer.get(otherPos);
+ if (thisByte != otherByte) {
+ return thisByte < otherByte ? -1 : 1;
+ }
+ thisPos++;
+ otherPos++;
+ compareRemaining--;
+ }
+ return remaining() - otherBuffer.remaining();
+ }
+
+ /** Returns a duplicated buffer that shares its content with this buffer.
+ *
+ * The duplicated buffer's initial position, limit, capacity and mark are the same as this buffer's. The duplicated buffer's
+ * read-only property and byte order are the same as this buffer's, too.
+ *
+ *
+ * The new buffer shares its content with this buffer, which means either buffer's change of content will be visible to the
+ * other. The two buffer's position, limit and mark are independent.
+ *
+ *
+ * @return a duplicated buffer that shares its content with this buffer.
+ * @since Android 1.0 */
+ public abstract CharBuffer duplicate ();
+
+ /** Checks whether this char buffer is equal to another object.
+ *
+ * If {@code other} is not a char buffer then {@code false} is returned. Two char buffers are equal if and only if their
+ * remaining chars are exactly the same. Position, limit, capacity and mark are not considered.
+ *
+ *
+ * @param other the object to compare with this char buffer.
+ * @return {@code true} if this char buffer is equal to {@code other}, {@code false} otherwise.
+ * @since Android 1.0 */
+ public boolean equals (Object other) {
+ if (!(other instanceof CharBuffer)) {
+ return false;
+ }
+ CharBuffer otherBuffer = (CharBuffer)other;
+
+ if (remaining() != otherBuffer.remaining()) {
+ return false;
+ }
+
+ int myPosition = position;
+ int otherPosition = otherBuffer.position;
+ boolean equalSoFar = true;
+ while (equalSoFar && (myPosition < limit)) {
+ equalSoFar = get(myPosition++) == otherBuffer.get(otherPosition++);
+ }
+
+ return equalSoFar;
+ }
+
+ /** Returns the char at the current position and increases the position by 1.
+ *
+ * @return the char at the current position.
+ * @exception BufferUnderflowException if the position is equal or greater than limit.
+ * @since Android 1.0 */
+ public abstract char get ();
+
+ /** Reads chars from the current position into the specified char array and increases the position by the number of chars read.
+ *
+ * Calling this method has the same effect as {@code get(dest, 0, dest.length)}.
+ *
+ *
+ * @param dest the destination char array.
+ * @return this buffer.
+ * @exception BufferUnderflowException if {@code dest.length} is greater than {@code remaining()}.
+ * @since Android 1.0 */
+ public CharBuffer get (char[] dest) {
+ return get(dest, 0, dest.length);
+ }
+
+ /** Reads chars from the current position into the specified char array, starting from the specified offset, and increases the
+ * position by the number of chars read.
+ *
+ * @param dest the target char array.
+ * @param off the offset of the char array, must not be negative and not greater than {@code dest.length}.
+ * @param len The number of chars to read, must be no less than zero and no greater than {@code dest.length - off}.
+ * @return this buffer.
+ * @exception IndexOutOfBoundsException if either {@code off} or {@code len} is invalid.
+ * @exception BufferUnderflowException if {@code len} is greater than {@code remaining()}.
+ * @since Android 1.0 */
+ public CharBuffer get (char[] dest, int off, int len) {
+ int length = dest.length;
+ if ((off < 0) || (len < 0) || (long)off + (long)len > length) {
+ throw new IndexOutOfBoundsException();
+ }
+
+ if (len > remaining()) {
+ throw new BufferUnderflowException();
+ }
+ for (int i = off; i < off + len; i++) {
+ dest[i] = get();
+ }
+ return this;
+ }
+
+ /** Returns a char at the specified index; the position is not changed.
+ *
+ * @param index the index, must not be negative and less than limit.
+ * @return a char at the specified index.
+ * @exception IndexOutOfBoundsException if index is invalid.
+ * @since Android 1.0 */
+ public abstract char get (int index);
+
+ /** Indicates whether this buffer is based on a char array and is read/write.
+ *
+ * @return {@code true} if this buffer is based on a byte array and provides read/write access, {@code false} otherwise.
+ * @since Android 1.0 */
+ public final boolean hasArray () {
+ return protectedHasArray();
+ }
+
+ /** Calculates this buffer's hash code from the remaining chars. The position, limit, capacity and mark don't affect the hash
+ * code.
+ *
+ * @return the hash code calculated from the remaining chars.
+ * @since Android 1.0 */
+ public int hashCode () {
+ int myPosition = position;
+ int hash = 0;
+ while (myPosition < limit) {
+ hash = hash + get(myPosition++);
+ }
+ return hash;
+ }
+
+ /** Indicates whether this buffer is direct. A direct buffer will try its best to take advantage of native memory APIs and it
+ * may not stay in the Java heap, so it is not affected by garbage collection.
+ *
+ * A char buffer is direct if it is based on a byte buffer and the byte buffer is direct.
+ *
+ *
+ * @return {@code true} if this buffer is direct, {@code false} otherwise.
+ * @since Android 1.0 */
+ public abstract boolean isDirect ();
+
+ /** Returns the number of remaining chars.
+ *
+ * @return the number of remaining chars.
+ * @since Android 1.0 */
+ public final int length () {
+ return remaining();
+ }
+
+ /** Returns the byte order used by this buffer when converting chars from/to bytes.
+ *
+ * If this buffer is not based on a byte buffer, then this always returns the platform's native byte order.
+ *
+ *
+ * @return the byte order used by this buffer when converting chars from/to bytes.
+ * @since Android 1.0 */
+ public abstract ByteOrder order ();
+
+ /** Child class implements this method to realize {@code array()}.
+ *
+ * @see #array() */
+ abstract char[] protectedArray ();
+
+ /** Child class implements this method to realize {@code arrayOffset()}.
+ *
+ * @see #arrayOffset() */
+ abstract int protectedArrayOffset ();
+
+ /** Child class implements this method to realize {@code hasArray()}.
+ *
+ * @see #hasArray() */
+ abstract boolean protectedHasArray ();
+
+ /** Writes the given char to the current position and increases the position by 1.
+ *
+ * @param c the char to write.
+ * @return this buffer.
+ * @exception BufferOverflowException if position is equal or greater than limit.
+ * @exception ReadOnlyBufferException if no changes may be made to the contents of this buffer.
+ * @since Android 1.0 */
+ public abstract CharBuffer put (char c);
+
+ /** Writes chars from the given char array to the current position and increases the position by the number of chars written.
+ *
+ * Calling this method has the same effect as {@code put(src, 0, src.length)}.
+ *
+ *
+ * @param src the source char array.
+ * @return this buffer.
+ * @exception BufferOverflowException if {@code remaining()} is less than {@code src.length}.
+ * @exception ReadOnlyBufferException if no changes may be made to the contents of this buffer.
+ * @since Android 1.0 */
+ public final CharBuffer put (char[] src) {
+ return put(src, 0, src.length);
+ }
+
+ /** Writes chars from the given char array, starting from the specified offset, to the current position and increases the
+ * position by the number of chars written.
+ *
+ * @param src the source char array.
+ * @param off the offset of char array, must not be negative and not greater than {@code src.length}.
+ * @param len the number of chars to write, must be no less than zero and no greater than {@code src.length - off}.
+ * @return this buffer.
+ * @exception BufferOverflowException if {@code remaining()} is less than {@code len}.
+ * @exception IndexOutOfBoundsException if either {@code off} or {@code len} is invalid.
+ * @exception ReadOnlyBufferException if no changes may be made to the contents of this buffer.
+ * @since Android 1.0 */
+ public CharBuffer put (char[] src, int off, int len) {
+ int length = src.length;
+ if ((off < 0) || (len < 0) || (long)off + (long)len > length) {
+ throw new IndexOutOfBoundsException();
+ }
+
+ if (len > remaining()) {
+ throw new BufferOverflowException();
+ }
+ for (int i = off; i < off + len; i++) {
+ put(src[i]);
+ }
+ return this;
+ }
+
+ /** Writes all the remaining chars of the {@code src} char buffer to this buffer's current position, and increases both buffers'
+ * position by the number of chars copied.
+ *
+ * @param src the source char buffer.
+ * @return this buffer.
+ * @exception BufferOverflowException if {@code src.remaining()} is greater than this buffer's {@code remaining()}.
+ * @exception IllegalArgumentException if {@code src} is this buffer.
+ * @exception ReadOnlyBufferException if no changes may be made to the contents of this buffer.
+ * @since Android 1.0 */
+ public CharBuffer put (CharBuffer src) {
+ if (src == this) {
+ throw new IllegalArgumentException();
+ }
+ if (src.remaining() > remaining()) {
+ throw new BufferOverflowException();
+ }
+
+ char[] contents = new char[src.remaining()];
+ src.get(contents);
+ put(contents);
+ return this;
+ }
+
+ /** Writes a char to the specified index of this buffer; the position is not changed.
+ *
+ * @param index the index, must be no less than zero and less than the limit.
+ * @param c the char to write.
+ * @return this buffer.
+ * @exception IndexOutOfBoundsException if index is invalid.
+ * @exception ReadOnlyBufferException if no changes may be made to the contents of this buffer.
+ * @since Android 1.0 */
+ public abstract CharBuffer put (int index, char c);
+
+ /** Writes all chars of the given string to the current position of this buffer, and increases the position by the length of
+ * string.
+ *
+ * Calling this method has the same effect as {@code put(str, 0, str.length())}.
+ *
+ *
+ * @param str the string to write.
+ * @return this buffer.
+ * @exception BufferOverflowException if {@code remaining()} is less than the length of string.
+ * @exception ReadOnlyBufferException if no changes may be made to the contents of this buffer.
+ * @since Android 1.0 */
+ public final CharBuffer put (String str) {
+ return put(str, 0, str.length());
+ }
+
+ /** Writes chars of the given string to the current position of this buffer, and increases the position by the number of chars
+ * written.
+ *
+ * @param str the string to write.
+ * @param start the first char to write, must not be negative and not greater than {@code str.length()}.
+ * @param end the last char to write (excluding), must be less than {@code start} and not greater than {@code str.length()}.
+ * @return this buffer.
+ * @exception BufferOverflowException if {@code remaining()} is less than {@code end - start}.
+ * @exception IndexOutOfBoundsException if either {@code start} or {@code end} is invalid.
+ * @exception ReadOnlyBufferException if no changes may be made to the contents of this buffer.
+ * @since Android 1.0 */
+ public CharBuffer put (String str, int start, int end) {
+ int length = str.length();
+ if (start < 0 || end < start || end > length) {
+ throw new IndexOutOfBoundsException();
+ }
+
+ if (end - start > remaining()) {
+ throw new BufferOverflowException();
+ }
+ for (int i = start; i < end; i++) {
+ put(str.charAt(i));
+ }
+ return this;
+ }
+
+ /** Returns a sliced buffer that shares its content with this buffer.
+ *
+ * The sliced buffer's capacity will be this buffer's {@code remaining()}, and its zero position will correspond to this
+ * buffer's current position. The new buffer's position will be 0, limit will be its capacity, and its mark is cleared. The new
+ * buffer's read-only property and byte order are same as this buffer.
+ *
+ *
+ * The new buffer shares its content with this buffer, which means either buffer's change of content will be visible to the
+ * other. The two buffer's position, limit and mark are independent.
+ *
+ *
+ * @return a sliced buffer that shares its content with this buffer.
+ * @since Android 1.0 */
+ public abstract CharBuffer slice ();
+
+ /** Returns a new char buffer representing a sub-sequence of this buffer's current remaining content.
+ *
+ * The new buffer's position will be {@code position() + start}, limit will be {@code position() + end}, capacity will be the
+ * same as this buffer. The new buffer's read-only property and byte order are the same as this buffer.
+ *
+ *
+ * The new buffer shares its content with this buffer, which means either buffer's change of content will be visible to the
+ * other. The two buffer's position, limit and mark are independent.
+ *
+ *
+ * @param start the start index of the sub-sequence, referenced from the current buffer position. Must not be less than zero
+ * and not greater than the value obtained from a call to {@code remaining()}.
+ * @param end the end index of the sub-sequence, referenced from the current buffer position. Must not be less than
+ * {@code start} and not be greater than the value obtained from a call to {@code remaining()}.
+ * @return a new char buffer represents a sub-sequence of this buffer's current remaining content.
+ * @exception IndexOutOfBoundsException if either {@code start} or {@code end} is invalid.
+ * @since Android 1.0 */
+ public abstract CharSequence subSequence (int start, int end);
+
+ /** Returns a string representing the current remaining chars of this buffer.
+ *
+ * @return a string representing the current remaining chars of this buffer.
+ * @since Android 1.0 */
+ public String toString () {
+ StringBuffer strbuf = new StringBuffer();
+ for (int i = position; i < limit; i++) {
+ strbuf.append(get(i));
+ }
+ return strbuf.toString();
+ }
+
+ /** Writes the given char to the current position and increases the position by 1.
+ *
+ * @param c the char to write.
+ * @return this buffer.
+ * @exception BufferOverflowException if position is equal or greater than limit.
+ * @exception ReadOnlyBufferException if no changes may be made to the contents of this buffer.
+ * @since Android 1.0 */
+ public CharBuffer append (char c) {
+ return put(c);
+ }
+
+ /** Writes all chars of the given character sequence {@code csq} to the current position of this buffer, and increases the
+ * position by the length of the csq.
+ *
+ * Calling this method has the same effect as {@code append(csq.toString())}.
+ *
+ * If the {@code CharSequence} is {@code null} the string "null" will be written to the buffer.
+ *
+ * @param csq the {@code CharSequence} to write.
+ * @return this buffer.
+ * @exception BufferOverflowException if {@code remaining()} is less than the length of csq.
+ * @exception ReadOnlyBufferException if no changes may be made to the contents of this buffer.
+ * @since Android 1.0 */
+ public CharBuffer append (CharSequence csq) {
+ if (csq != null) {
+ return put(csq.toString());
+ }
+ return put("null"); //$NON-NLS-1$
+ }
+
+ /** Writes chars of the given {@code CharSequence} to the current position of this buffer, and increases the position by the
+ * number of chars written.
+ *
+ * @param csq the {@code CharSequence} to write.
+ * @param start the first char to write, must not be negative and not greater than {@code csq.length()}.
+ * @param end the last char to write (excluding), must be less than {@code start} and not greater than {@code csq.length()}.
+ * @return this buffer.
+ * @exception BufferOverflowException if {@code remaining()} is less than {@code end - start}.
+ * @exception IndexOutOfBoundsException if either {@code start} or {@code end} is invalid.
+ * @exception ReadOnlyBufferException if no changes may be made to the contents of this buffer.
+ * @since Android 1.0 */
+ public CharBuffer append (CharSequence csq, int start, int end) {
+ if (csq == null) {
+ csq = "null"; //$NON-NLS-1$
+ }
+ CharSequence cs = csq.subSequence(start, end);
+ if (cs.length() > 0) {
+ return put(cs.toString());
+ }
+ return this;
+ }
+
+ /** Reads characters from this buffer and puts them into {@code target}. The number of chars that are copied is either the
+ * number of remaining chars in this buffer or the number of remaining chars in {@code target}, whichever is smaller.
+ *
+ * @param target the target char buffer.
+ * @throws IllegalArgumentException if {@code target} is this buffer.
+ * @throws IOException if an I/O error occurs.
+ * @throws ReadOnlyBufferException if no changes may be made to the contents of {@code target}.
+ * @return the number of chars copied or -1 if there are no chars left to be read from this buffer.
+ * @since Android 1.0 */
+ public int read (CharBuffer target) throws IOException {
+ if (target == this) {
+ throw new IllegalArgumentException();
+ }
+ if (remaining() == 0) {
+ return target.remaining() == 0 ? 0 : -1;
+ }
+ int result = Math.min(target.remaining(), remaining());
+ char[] chars = new char[result];
+ get(chars);
+ target.put(chars);
+ return result;
+ }
}
diff --git a/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/java/nio/CharSequenceAdapter.java b/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/java/nio/CharSequenceAdapter.java
index 32edc18bb8e..45b7e77ef9e 100644
--- a/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/java/nio/CharSequenceAdapter.java
+++ b/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/java/nio/CharSequenceAdapter.java
@@ -17,136 +17,133 @@
package java.nio;
-/**
- * This class wraps a char sequence to be a char buffer.
+/** This class wraps a char sequence to be a char buffer.
*
* Implementation notice:
*
* Char sequence based buffer is always readonly.
*
- *
- *
- */
+ * */
final class CharSequenceAdapter extends CharBuffer {
- static CharSequenceAdapter copy(CharSequenceAdapter other) {
- CharSequenceAdapter buf = new CharSequenceAdapter(other.sequence);
- buf.limit = other.limit;
- buf.position = other.position;
- buf.mark = other.mark;
- return buf;
- }
-
- final CharSequence sequence;
-
- CharSequenceAdapter(CharSequence chseq) {
- super(chseq.length());
- sequence = chseq;
- }
-
- public CharBuffer asReadOnlyBuffer() {
- return duplicate();
- }
-
- public CharBuffer compact() {
- throw new ReadOnlyBufferException();
- }
-
- public CharBuffer duplicate() {
- return copy(this);
- }
-
- public char get() {
- if (position == limit) {
- throw new BufferUnderflowException();
- }
- return sequence.charAt(position++);
- }
-
- public char get(int index) {
- if (index < 0 || index >= limit) {
- throw new IndexOutOfBoundsException();
- }
- return sequence.charAt(index);
- }
-
- public final CharBuffer get(char[] dest, int off, int len) {
- int length = dest.length;
- if ((off < 0 ) || (len < 0) || (long)off + (long)len > length) {
- throw new IndexOutOfBoundsException();
- }
- if (len > remaining()) {
- throw new BufferUnderflowException();
- }
- int newPosition = position + len;
- sequence.toString().getChars(position, newPosition, dest, off);
- position = newPosition;
- return this;
- }
-
- public boolean isDirect() {
- return false;
- }
-
- public boolean isReadOnly() {
- return true;
- }
-
- public ByteOrder order() {
- return ByteOrder.nativeOrder();
- }
-
- protected char[] protectedArray() {
- throw new UnsupportedOperationException();
- }
-
- protected int protectedArrayOffset() {
- throw new UnsupportedOperationException();
- }
-
- protected boolean protectedHasArray() {
- return false;
- }
-
- public CharBuffer put(char c) {
- throw new ReadOnlyBufferException();
- }
-
- public CharBuffer put(int index, char c) {
- throw new ReadOnlyBufferException();
- }
-
- public final CharBuffer put(char[] src, int off, int len) {
- if ((off < 0 ) || (len < 0) || (long)off + (long)len > src.length) {
- throw new IndexOutOfBoundsException();
- }
-
- if (len > remaining()) {
- throw new BufferOverflowException();
- }
-
- throw new ReadOnlyBufferException();
- }
-
- public CharBuffer put(String src, int start, int end) {
- if ((start < 0 ) || (end < 0) || (long)start + (long)end > src.length()) {
- throw new IndexOutOfBoundsException();
- }
- throw new ReadOnlyBufferException();
- }
-
- public CharBuffer slice() {
- return new CharSequenceAdapter(sequence.subSequence(position, limit));
- }
-
- public CharSequence subSequence(int start, int end) {
- if (end < start || start < 0 || end > remaining()) {
- throw new IndexOutOfBoundsException();
- }
-
- CharSequenceAdapter result = copy(this);
- result.position = position + start;
- result.limit = position + end;
- return result;
- }
+ static CharSequenceAdapter copy (CharSequenceAdapter other) {
+ CharSequenceAdapter buf = new CharSequenceAdapter(other.sequence);
+ buf.limit = other.limit;
+ buf.position = other.position;
+ buf.mark = other.mark;
+ return buf;
+ }
+
+ final CharSequence sequence;
+
+ CharSequenceAdapter (CharSequence chseq) {
+ super(chseq.length());
+ sequence = chseq;
+ }
+
+ public CharBuffer asReadOnlyBuffer () {
+ return duplicate();
+ }
+
+ public CharBuffer compact () {
+ throw new ReadOnlyBufferException();
+ }
+
+ public CharBuffer duplicate () {
+ return copy(this);
+ }
+
+ public char get () {
+ if (position == limit) {
+ throw new BufferUnderflowException();
+ }
+ return sequence.charAt(position++);
+ }
+
+ public char get (int index) {
+ if (index < 0 || index >= limit) {
+ throw new IndexOutOfBoundsException();
+ }
+ return sequence.charAt(index);
+ }
+
+ public final CharBuffer get (char[] dest, int off, int len) {
+ int length = dest.length;
+ if ((off < 0) || (len < 0) || (long)off + (long)len > length) {
+ throw new IndexOutOfBoundsException();
+ }
+ if (len > remaining()) {
+ throw new BufferUnderflowException();
+ }
+ int newPosition = position + len;
+ sequence.toString().getChars(position, newPosition, dest, off);
+ position = newPosition;
+ return this;
+ }
+
+ public boolean isDirect () {
+ return false;
+ }
+
+ public boolean isReadOnly () {
+ return true;
+ }
+
+ public ByteOrder order () {
+ return ByteOrder.nativeOrder();
+ }
+
+ protected char[] protectedArray () {
+ throw new UnsupportedOperationException();
+ }
+
+ protected int protectedArrayOffset () {
+ throw new UnsupportedOperationException();
+ }
+
+ protected boolean protectedHasArray () {
+ return false;
+ }
+
+ public CharBuffer put (char c) {
+ throw new ReadOnlyBufferException();
+ }
+
+ public CharBuffer put (int index, char c) {
+ throw new ReadOnlyBufferException();
+ }
+
+ public final CharBuffer put (char[] src, int off, int len) {
+ if ((off < 0) || (len < 0) || (long)off + (long)len > src.length) {
+ throw new IndexOutOfBoundsException();
+ }
+
+ if (len > remaining()) {
+ throw new BufferOverflowException();
+ }
+
+ throw new ReadOnlyBufferException();
+ }
+
+ public CharBuffer put (String src, int start, int end) {
+ if ((start < 0) || (end < 0) || (long)start + (long)end > src.length()) {
+ throw new IndexOutOfBoundsException();
+ }
+ throw new ReadOnlyBufferException();
+ }
+
+ public CharBuffer slice () {
+ return new CharSequenceAdapter(sequence.subSequence(position, limit));
+ }
+
+ public CharSequence subSequence (int start, int end) {
+ if (end < start || start < 0 || end > remaining()) {
+ throw new IndexOutOfBoundsException();
+ }
+
+ CharSequenceAdapter result = copy(this);
+ result.position = position + start;
+ result.limit = position + end;
+ return result;
+ }
}
diff --git a/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/java/nio/CharToByteBufferAdapter.java b/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/java/nio/CharToByteBufferAdapter.java
index 26ec475ce76..0f65cd43b41 100644
--- a/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/java/nio/CharToByteBufferAdapter.java
+++ b/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/java/nio/CharToByteBufferAdapter.java
@@ -19,198 +19,193 @@
//import org.apache.harmony.nio.internal.DirectBuffer;
//import org.apache.harmony.luni.platform.PlatformAddress;
-/**
- * This class wraps a byte buffer to be a char buffer.
+/** This class wraps a byte buffer to be a char buffer.
*
* Implementation notice:
*
- * After a byte buffer instance is wrapped, it becomes privately owned by
- * the adapter. It must NOT be accessed outside the adapter any more.
- * The byte buffer's position and limit are NOT linked with the adapter.
- * The adapter extends Buffer, thus has its own position and limit.
+ * After a byte buffer instance is wrapped, it becomes privately owned by the adapter. It must NOT be accessed outside the
+ * adapter any more.
+ * The byte buffer's position and limit are NOT linked with the adapter. The adapter extends Buffer, thus has its own position
+ * and limit.
*
- *
- *
- */
-final class CharToByteBufferAdapter extends CharBuffer { //implements DirectBuffer {
-
- static CharBuffer wrap(ByteBuffer byteBuffer) {
- return new CharToByteBufferAdapter(byteBuffer.slice());
- }
-
- private final ByteBuffer byteBuffer;
-
- CharToByteBufferAdapter(ByteBuffer byteBuffer) {
- super((byteBuffer.capacity() >> 1));
- this.byteBuffer = byteBuffer;
- this.byteBuffer.clear();
- }
-
-// public int getByteCapacity() {
-// if (byteBuffer instanceof DirectBuffer) {
-// return ((DirectBuffer) byteBuffer).getByteCapacity();
-// }
-// assert false : byteBuffer;
-// return -1;
-// }
+ * */
+final class CharToByteBufferAdapter extends CharBuffer { // implements DirectBuffer {
+
+ static CharBuffer wrap (ByteBuffer byteBuffer) {
+ return new CharToByteBufferAdapter(byteBuffer.slice());
+ }
+
+ private final ByteBuffer byteBuffer;
+
+ CharToByteBufferAdapter (ByteBuffer byteBuffer) {
+ super((byteBuffer.capacity() >> 1));
+ this.byteBuffer = byteBuffer;
+ this.byteBuffer.clear();
+ }
+
+// public int getByteCapacity() {
+// if (byteBuffer instanceof DirectBuffer) {
+// return ((DirectBuffer) byteBuffer).getByteCapacity();
+// }
+// assert false : byteBuffer;
+// return -1;
+// }
//
-// public PlatformAddress getEffectiveAddress() {
-// if (byteBuffer instanceof DirectBuffer) {
-// return ((DirectBuffer) byteBuffer).getEffectiveAddress();
-// }
-// assert false : byteBuffer;
-// return null;
-// }
+// public PlatformAddress getEffectiveAddress() {
+// if (byteBuffer instanceof DirectBuffer) {
+// return ((DirectBuffer) byteBuffer).getEffectiveAddress();
+// }
+// assert false : byteBuffer;
+// return null;
+// }
//
-// public PlatformAddress getBaseAddress() {
-// if (byteBuffer instanceof DirectBuffer) {
-// return ((DirectBuffer) byteBuffer).getBaseAddress();
-// }
-// assert false : byteBuffer;
-// return null;
-// }
+// public PlatformAddress getBaseAddress() {
+// if (byteBuffer instanceof DirectBuffer) {
+// return ((DirectBuffer) byteBuffer).getBaseAddress();
+// }
+// assert false : byteBuffer;
+// return null;
+// }
//
-// public boolean isAddressValid() {
-// if (byteBuffer instanceof DirectBuffer) {
-// return ((DirectBuffer) byteBuffer).isAddressValid();
-// }
-// assert false : byteBuffer;
-// return false;
-// }
+// public boolean isAddressValid() {
+// if (byteBuffer instanceof DirectBuffer) {
+// return ((DirectBuffer) byteBuffer).isAddressValid();
+// }
+// assert false : byteBuffer;
+// return false;
+// }
//
-// public void addressValidityCheck() {
-// if (byteBuffer instanceof DirectBuffer) {
-// ((DirectBuffer) byteBuffer).addressValidityCheck();
-// } else {
-// assert false : byteBuffer;
-// }
-// }
+// public void addressValidityCheck() {
+// if (byteBuffer instanceof DirectBuffer) {
+// ((DirectBuffer) byteBuffer).addressValidityCheck();
+// } else {
+// assert false : byteBuffer;
+// }
+// }
//
-// public void free() {
-// if (byteBuffer instanceof DirectBuffer) {
-// ((DirectBuffer) byteBuffer).free();
-// } else {
-// assert false : byteBuffer;
-// }
-// }
-
- @Override
- public CharBuffer asReadOnlyBuffer() {
- CharToByteBufferAdapter buf = new CharToByteBufferAdapter(byteBuffer
- .asReadOnlyBuffer());
- buf.limit = limit;
- buf.position = position;
- buf.mark = mark;
- return buf;
- }
-
- @Override
- public CharBuffer compact() {
- if (byteBuffer.isReadOnly()) {
- throw new ReadOnlyBufferException();
- }
- byteBuffer.limit(limit << 1);
- byteBuffer.position(position << 1);
- byteBuffer.compact();
- byteBuffer.clear();
- position = limit - position;
- limit = capacity;
- mark = UNSET_MARK;
- return this;
- }
-
- @Override
- public CharBuffer duplicate() {
- CharToByteBufferAdapter buf = new CharToByteBufferAdapter(byteBuffer
- .duplicate());
- buf.limit = limit;
- buf.position = position;
- buf.mark = mark;
- return buf;
- }
-
- @Override
- public char get() {
- if (position == limit) {
- throw new BufferUnderflowException();
- }
- return byteBuffer.getChar(position++ << 1);
- }
-
- @Override
- public char get(int index) {
- if (index < 0 || index >= limit) {
- throw new IndexOutOfBoundsException();
- }
- return byteBuffer.getChar(index << 1);
- }
-
- @Override
- public boolean isDirect() {
- return byteBuffer.isDirect();
- }
-
- @Override
- public boolean isReadOnly() {
- return byteBuffer.isReadOnly();
- }
-
- @Override
- public ByteOrder order() {
- return byteBuffer.order();
- }
-
- @Override
- protected char[] protectedArray() {
- throw new UnsupportedOperationException();
- }
-
- @Override
- protected int protectedArrayOffset() {
- throw new UnsupportedOperationException();
- }
-
- @Override
- protected boolean protectedHasArray() {
- return false;
- }
-
- @Override
- public CharBuffer put(char c) {
- if (position == limit) {
- throw new BufferOverflowException();
- }
- byteBuffer.putChar(position++ << 1, c);
- return this;
- }
-
- @Override
- public CharBuffer put(int index, char c) {
- if (index < 0 || index >= limit) {
- throw new IndexOutOfBoundsException();
- }
- byteBuffer.putChar(index << 1, c);
- return this;
- }
-
- @Override
- public CharBuffer slice() {
- byteBuffer.limit(limit << 1);
- byteBuffer.position(position << 1);
- CharBuffer result = new CharToByteBufferAdapter(byteBuffer.slice());
- byteBuffer.clear();
- return result;
- }
-
- @Override
- public CharSequence subSequence(int start, int end) {
- if (start < 0 || end < start || end > remaining()) {
- throw new IndexOutOfBoundsException();
- }
-
- CharBuffer result = duplicate();
- result.limit(position + end);
- result.position(position + start);
- return result;
- }
+// public void free() {
+// if (byteBuffer instanceof DirectBuffer) {
+// ((DirectBuffer) byteBuffer).free();
+// } else {
+// assert false : byteBuffer;
+// }
+// }
+
+ @Override
+ public CharBuffer asReadOnlyBuffer () {
+ CharToByteBufferAdapter buf = new CharToByteBufferAdapter(byteBuffer.asReadOnlyBuffer());
+ buf.limit = limit;
+ buf.position = position;
+ buf.mark = mark;
+ return buf;
+ }
+
+ @Override
+ public CharBuffer compact () {
+ if (byteBuffer.isReadOnly()) {
+ throw new ReadOnlyBufferException();
+ }
+ byteBuffer.limit(limit << 1);
+ byteBuffer.position(position << 1);
+ byteBuffer.compact();
+ byteBuffer.clear();
+ position = limit - position;
+ limit = capacity;
+ mark = UNSET_MARK;
+ return this;
+ }
+
+ @Override
+ public CharBuffer duplicate () {
+ CharToByteBufferAdapter buf = new CharToByteBufferAdapter(byteBuffer.duplicate());
+ buf.limit = limit;
+ buf.position = position;
+ buf.mark = mark;
+ return buf;
+ }
+
+ @Override
+ public char get () {
+ if (position == limit) {
+ throw new BufferUnderflowException();
+ }
+ return byteBuffer.getChar(position++ << 1);
+ }
+
+ @Override
+ public char get (int index) {
+ if (index < 0 || index >= limit) {
+ throw new IndexOutOfBoundsException();
+ }
+ return byteBuffer.getChar(index << 1);
+ }
+
+ @Override
+ public boolean isDirect () {
+ return byteBuffer.isDirect();
+ }
+
+ @Override
+ public boolean isReadOnly () {
+ return byteBuffer.isReadOnly();
+ }
+
+ @Override
+ public ByteOrder order () {
+ return byteBuffer.order();
+ }
+
+ @Override
+ protected char[] protectedArray () {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ protected int protectedArrayOffset () {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ protected boolean protectedHasArray () {
+ return false;
+ }
+
+ @Override
+ public CharBuffer put (char c) {
+ if (position == limit) {
+ throw new BufferOverflowException();
+ }
+ byteBuffer.putChar(position++ << 1, c);
+ return this;
+ }
+
+ @Override
+ public CharBuffer put (int index, char c) {
+ if (index < 0 || index >= limit) {
+ throw new IndexOutOfBoundsException();
+ }
+ byteBuffer.putChar(index << 1, c);
+ return this;
+ }
+
+ @Override
+ public CharBuffer slice () {
+ byteBuffer.limit(limit << 1);
+ byteBuffer.position(position << 1);
+ CharBuffer result = new CharToByteBufferAdapter(byteBuffer.slice());
+ byteBuffer.clear();
+ return result;
+ }
+
+ @Override
+ public CharSequence subSequence (int start, int end) {
+ if (start < 0 || end < start || end > remaining()) {
+ throw new IndexOutOfBoundsException();
+ }
+
+ CharBuffer result = duplicate();
+ result.limit(position + end);
+ result.position(position + start);
+ return result;
+ }
}
diff --git a/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/java/nio/DirectByteBuffer.java b/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/java/nio/DirectByteBuffer.java
index 522e56e1f14..6eda3eec27e 100644
--- a/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/java/nio/DirectByteBuffer.java
+++ b/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/java/nio/DirectByteBuffer.java
@@ -24,231 +24,226 @@
import com.google.gwt.corp.compatibility.Endianness;
import com.google.gwt.corp.compatibility.Numbers;
-/**
- * DirectByteBuffer, DirectReadWriteByteBuffer and DirectReadOnlyHeapByteBuffer compose
- * the implementation of direct byte buffers.
+/** DirectByteBuffer, DirectReadWriteByteBuffer and DirectReadOnlyHeapByteBuffer compose the implementation of direct byte buffers.
*
- * DirectByteBuffer implements all the shared readonly methods and is extended by
- * the other two classes.
+ * DirectByteBuffer implements all the shared readonly methods and is extended by the other two classes.
*
*
* All methods are marked final for runtime performance.
- *
- *
- */
+ * */
abstract class DirectByteBuffer extends BaseByteBuffer implements HasArrayBufferView {
Int8Array byteArray;
- DirectByteBuffer(int capacity) {
- this(ArrayBuffer.create(capacity), capacity, 0);
- }
+ DirectByteBuffer (int capacity) {
+ this(ArrayBuffer.create(capacity), capacity, 0);
+ }
+
+ DirectByteBuffer (ArrayBuffer buf) {
+ this(buf, buf.getByteLength(), 0);
+ }
- DirectByteBuffer(ArrayBuffer buf) {
- this(buf, buf.getByteLength(), 0);
- }
-
- DirectByteBuffer(ArrayBuffer buffer, int capacity, int offset) {
- super(capacity);
- byteArray = Int8Array.create(buffer, offset, capacity);
- }
+ DirectByteBuffer (ArrayBuffer buffer, int capacity, int offset) {
+ super(capacity);
+ byteArray = Int8Array.create(buffer, offset, capacity);
+ }
- public ArrayBufferView getTypedArray() {
+ public ArrayBufferView getTypedArray () {
return byteArray;
}
-
- public int getElementSize() {
+
+ public int getElementSize () {
return 1;
}
- /*
- * Override ByteBuffer.get(byte[], int, int) to improve performance.
- *
- * (non-Javadoc)
- *
- * @see java.nio.ByteBuffer#get(byte[], int, int)
- */
- public final ByteBuffer get(byte[] dest, int off, int len) {
- int length = dest.length;
- if (off < 0 || len < 0 || (long)off + (long)len > length) {
- throw new IndexOutOfBoundsException();
- }
- if (len > remaining()) {
- throw new BufferUnderflowException();
- }
-
- for (int i = 0; i < len; i++) {
- dest[i + off] = get(position + i);
- }
-
- position += len;
- return this;
- }
-
- public final byte get() {
-// if (position == limit) {
-// throw new BufferUnderflowException();
-// }
- return (byte)byteArray.get(position++);
- }
-
- public final byte get(int index) {
-// if (index < 0 || index >= limit) {
-// throw new IndexOutOfBoundsException();
-// }
- return (byte)byteArray.get(index);
- }
-
- public final double getDouble() {
- return Numbers.longBitsToDouble(getLong());
- }
-
- public final double getDouble(int index) {
- return Numbers.longBitsToDouble(getLong(index));
- }
-
- public final float getFloat() {
- return Numbers.intBitsToFloat(getInt());
- }
-
- public final float getFloat(int index) {
- return Numbers.intBitsToFloat(getInt(index));
- }
-
- public final int getInt() {
- int newPosition = position + 4;
-// if (newPosition > limit) {
-// throw new BufferUnderflowException();
-// }
- int result = loadInt(position);
- position = newPosition;
- return result;
- }
-
- public final int getInt(int index) {
-// if (index < 0 || index + 4 > limit) {
-// throw new IndexOutOfBoundsException();
-// }
- return loadInt(index);
- }
-
- public final long getLong() {
- int newPosition = position + 8;
-// if (newPosition > limit) {
-// throw new BufferUnderflowException();
-// }
- long result = loadLong(position);
- position = newPosition;
- return result;
- }
-
- public final long getLong(int index) {
-// if (index < 0 || index + 8 > limit) {
-// throw new IndexOutOfBoundsException();
-// }
- return loadLong(index);
- }
-
- public final short getShort() {
- int newPosition = position + 2;
-// if (newPosition > limit) {
-// throw new BufferUnderflowException();
-// }
- short result = loadShort(position);
- position = newPosition;
- return result;
- }
-
- public final short getShort(int index) {
-// if (index < 0 || index + 2 > limit) {
-// throw new IndexOutOfBoundsException();
-// }
- return loadShort(index);
- }
-
- public final boolean isDirect() {
- return false;
- }
-
- protected final int loadInt(int baseOffset) {
- int bytes = 0;
- if(order == Endianness.BIG_ENDIAN){
- for (int i = 0; i < 4; i++) {
- bytes = bytes << 8;
- bytes = bytes | (byteArray.get(baseOffset + i) & 0xFF);
- }
- }else{
- for (int i = 3; i >= 0; i--) {
- bytes = bytes << 8;
- bytes = bytes | (byteArray.get(baseOffset + i) & 0xFF);
- }
- }
- return bytes;
- }
-
- protected final long loadLong(int baseOffset) {
- long bytes = 0;
- if(order == Endianness.BIG_ENDIAN){
- for (int i = 0; i < 8; i++) {
- bytes = bytes << 8;
- bytes = bytes | (byteArray.get(baseOffset + i) & 0xFF);
- }
- }else{
- for (int i = 7; i >= 0; i--) {
- bytes = bytes << 8;
- bytes = bytes | (byteArray.get(baseOffset + i) & 0xFF);
- }
- }
- return bytes;
- }
-
- protected final short loadShort(int baseOffset) {
- short bytes = 0;
- if(order == Endianness.BIG_ENDIAN){
- bytes = (short) (byteArray.get(baseOffset) << 8);
- bytes |= (byteArray.get(baseOffset + 1) & 0xFF);
- }else{
- bytes = (short) (byteArray.get(baseOffset+1) << 8);
- bytes |= (byteArray.get(baseOffset) & 0xFF);
- }
- return bytes;
- }
-
- protected final void store(int baseOffset, int value) {
- if (order == Endianness.BIG_ENDIAN) {
- for (int i = 3; i >= 0; i--) {
- byteArray.set(baseOffset + i, (byte) (value & 0xFF));
- value = value >> 8;
- }
- } else {
- for (int i = 0; i <= 3; i++) {
- byteArray.set(baseOffset + i, (byte) (value & 0xFF));
- value = value >> 8;
- }
- }
- }
-
- protected final void store(int baseOffset, long value) {
- if (order == Endianness.BIG_ENDIAN) {
- for (int i = 7; i >= 0; i--) {
- byteArray.set(baseOffset + i, (byte) (value & 0xFF));
- value = value >> 8;
- }
- } else {
- for (int i = 0; i <= 7; i++) {
- byteArray.set(baseOffset + i, (byte) (value & 0xFF));
- value = value >> 8;
- }
- }
- }
-
- protected final void store(int baseOffset, short value) {
- if (order == Endianness.BIG_ENDIAN) {
- byteArray.set(baseOffset, (byte) ((value >> 8) & 0xFF));
- byteArray.set(baseOffset + 1, (byte) (value & 0xFF));
- } else {
- byteArray.set(baseOffset+1, (byte) ((value >> 8) & 0xFF));
- byteArray.set(baseOffset, (byte) (value & 0xFF));
- }
- }
-}
\ No newline at end of file
+ /*
+ * Override ByteBuffer.get(byte[], int, int) to improve performance.
+ *
+ * (non-Javadoc)
+ *
+ * @see java.nio.ByteBuffer#get(byte[], int, int)
+ */
+ public final ByteBuffer get (byte[] dest, int off, int len) {
+ int length = dest.length;
+ if (off < 0 || len < 0 || (long)off + (long)len > length) {
+ throw new IndexOutOfBoundsException();
+ }
+ if (len > remaining()) {
+ throw new BufferUnderflowException();
+ }
+
+ for (int i = 0; i < len; i++) {
+ dest[i + off] = get(position + i);
+ }
+
+ position += len;
+ return this;
+ }
+
+ public final byte get () {
+// if (position == limit) {
+// throw new BufferUnderflowException();
+// }
+ return (byte)byteArray.get(position++);
+ }
+
+ public final byte get (int index) {
+// if (index < 0 || index >= limit) {
+// throw new IndexOutOfBoundsException();
+// }
+ return (byte)byteArray.get(index);
+ }
+
+ public final double getDouble () {
+ return Numbers.longBitsToDouble(getLong());
+ }
+
+ public final double getDouble (int index) {
+ return Numbers.longBitsToDouble(getLong(index));
+ }
+
+ public final float getFloat () {
+ return Numbers.intBitsToFloat(getInt());
+ }
+
+ public final float getFloat (int index) {
+ return Numbers.intBitsToFloat(getInt(index));
+ }
+
+ public final int getInt () {
+ int newPosition = position + 4;
+// if (newPosition > limit) {
+// throw new BufferUnderflowException();
+// }
+ int result = loadInt(position);
+ position = newPosition;
+ return result;
+ }
+
+ public final int getInt (int index) {
+// if (index < 0 || index + 4 > limit) {
+// throw new IndexOutOfBoundsException();
+// }
+ return loadInt(index);
+ }
+
+ public final long getLong () {
+ int newPosition = position + 8;
+// if (newPosition > limit) {
+// throw new BufferUnderflowException();
+// }
+ long result = loadLong(position);
+ position = newPosition;
+ return result;
+ }
+
+ public final long getLong (int index) {
+// if (index < 0 || index + 8 > limit) {
+// throw new IndexOutOfBoundsException();
+// }
+ return loadLong(index);
+ }
+
+ public final short getShort () {
+ int newPosition = position + 2;
+// if (newPosition > limit) {
+// throw new BufferUnderflowException();
+// }
+ short result = loadShort(position);
+ position = newPosition;
+ return result;
+ }
+
+ public final short getShort (int index) {
+// if (index < 0 || index + 2 > limit) {
+// throw new IndexOutOfBoundsException();
+// }
+ return loadShort(index);
+ }
+
+ public final boolean isDirect () {
+ return false;
+ }
+
+ protected final int loadInt (int baseOffset) {
+ int bytes = 0;
+ if (order == Endianness.BIG_ENDIAN) {
+ for (int i = 0; i < 4; i++) {
+ bytes = bytes << 8;
+ bytes = bytes | (byteArray.get(baseOffset + i) & 0xFF);
+ }
+ } else {
+ for (int i = 3; i >= 0; i--) {
+ bytes = bytes << 8;
+ bytes = bytes | (byteArray.get(baseOffset + i) & 0xFF);
+ }
+ }
+ return bytes;
+ }
+
+ protected final long loadLong (int baseOffset) {
+ long bytes = 0;
+ if (order == Endianness.BIG_ENDIAN) {
+ for (int i = 0; i < 8; i++) {
+ bytes = bytes << 8;
+ bytes = bytes | (byteArray.get(baseOffset + i) & 0xFF);
+ }
+ } else {
+ for (int i = 7; i >= 0; i--) {
+ bytes = bytes << 8;
+ bytes = bytes | (byteArray.get(baseOffset + i) & 0xFF);
+ }
+ }
+ return bytes;
+ }
+
+ protected final short loadShort (int baseOffset) {
+ short bytes = 0;
+ if (order == Endianness.BIG_ENDIAN) {
+ bytes = (short)(byteArray.get(baseOffset) << 8);
+ bytes |= (byteArray.get(baseOffset + 1) & 0xFF);
+ } else {
+ bytes = (short)(byteArray.get(baseOffset + 1) << 8);
+ bytes |= (byteArray.get(baseOffset) & 0xFF);
+ }
+ return bytes;
+ }
+
+ protected final void store (int baseOffset, int value) {
+ if (order == Endianness.BIG_ENDIAN) {
+ for (int i = 3; i >= 0; i--) {
+ byteArray.set(baseOffset + i, (byte)(value & 0xFF));
+ value = value >> 8;
+ }
+ } else {
+ for (int i = 0; i <= 3; i++) {
+ byteArray.set(baseOffset + i, (byte)(value & 0xFF));
+ value = value >> 8;
+ }
+ }
+ }
+
+ protected final void store (int baseOffset, long value) {
+ if (order == Endianness.BIG_ENDIAN) {
+ for (int i = 7; i >= 0; i--) {
+ byteArray.set(baseOffset + i, (byte)(value & 0xFF));
+ value = value >> 8;
+ }
+ } else {
+ for (int i = 0; i <= 7; i++) {
+ byteArray.set(baseOffset + i, (byte)(value & 0xFF));
+ value = value >> 8;
+ }
+ }
+ }
+
+ protected final void store (int baseOffset, short value) {
+ if (order == Endianness.BIG_ENDIAN) {
+ byteArray.set(baseOffset, (byte)((value >> 8) & 0xFF));
+ byteArray.set(baseOffset + 1, (byte)(value & 0xFF));
+ } else {
+ byteArray.set(baseOffset + 1, (byte)((value >> 8) & 0xFF));
+ byteArray.set(baseOffset, (byte)(value & 0xFF));
+ }
+ }
+}
diff --git a/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/java/nio/DirectReadOnlyByteBuffer.java b/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/java/nio/DirectReadOnlyByteBuffer.java
index 9033dc734c2..6ff797e908b 100644
--- a/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/java/nio/DirectReadOnlyByteBuffer.java
+++ b/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/java/nio/DirectReadOnlyByteBuffer.java
@@ -19,138 +19,129 @@
import gwt.g3d.client.gl2.array.ArrayBuffer;
-/**
- * HeapByteBuffer, ReadWriteHeapByteBuffer and ReadOnlyHeapByteBuffer compose
- * the implementation of array based byte buffers.
+/** HeapByteBuffer, ReadWriteHeapByteBuffer and ReadOnlyHeapByteBuffer compose the implementation of array based byte buffers.
*
- * ReadOnlyHeapByteBuffer extends HeapByteBuffer with all the write methods
- * throwing read only exception.
+ * ReadOnlyHeapByteBuffer extends HeapByteBuffer with all the write methods throwing read only exception.
*
*
* This class is marked final for runtime performance.
- *
- *
- */
+ * */
final class DirectReadOnlyByteBuffer extends DirectByteBuffer {
- static DirectReadOnlyByteBuffer copy(DirectByteBuffer other, int markOfOther) {
- DirectReadOnlyByteBuffer buf = new DirectReadOnlyByteBuffer(
- other.byteArray.getBuffer(), other.capacity(), other.byteArray.getByteOffset());
- buf.limit = other.limit();
- buf.position = other.position();
- buf.mark = markOfOther;
- buf.order(other.order());
- return buf;
- }
-
- DirectReadOnlyByteBuffer(ArrayBuffer backingArray, int capacity, int arrayOffset) {
- super(backingArray, capacity, arrayOffset);
- }
-
- public ByteBuffer asReadOnlyBuffer() {
- return copy(this, mark);
- }
-
- public ByteBuffer compact() {
- throw new ReadOnlyBufferException();
- }
-
- public ByteBuffer duplicate() {
- return copy(this, mark);
- }
-
- public boolean isReadOnly() {
- return true;
- }
-
- protected byte[] protectedArray() {
- throw new ReadOnlyBufferException();
- }
-
- protected int protectedArrayOffset() {
- throw new ReadOnlyBufferException();
- }
-
- protected boolean protectedHasArray() {
- return false;
- }
-
- public FloatBuffer asFloatBuffer() {
- return DirectReadOnlyFloatBufferAdapter.wrap(this);
- }
-
- public IntBuffer asIntBuffer() {
- return order() == ByteOrder.nativeOrder()
- ? DirectReadOnlyIntBufferAdapter.wrap(this)
- : super.asIntBuffer();
- }
-
- public ShortBuffer asShortBuffer() {
- return order() == ByteOrder.nativeOrder()
- ? DirectReadOnlyShortBufferAdapter.wrap(this)
- : super.asShortBuffer();
- }
-
- public ByteBuffer put(byte b) {
- throw new ReadOnlyBufferException();
- }
-
- public ByteBuffer put(int index, byte b) {
- throw new ReadOnlyBufferException();
- }
-
- public ByteBuffer put(byte[] src, int off, int len) {
- throw new ReadOnlyBufferException();
- }
-
- public ByteBuffer putDouble(double value) {
- throw new ReadOnlyBufferException();
- }
-
- public ByteBuffer putDouble(int index, double value) {
- throw new ReadOnlyBufferException();
- }
-
- public ByteBuffer putFloat(float value) {
- throw new ReadOnlyBufferException();
- }
-
- public ByteBuffer putFloat(int index, float value) {
- throw new ReadOnlyBufferException();
- }
-
- public ByteBuffer putInt(int value) {
- throw new ReadOnlyBufferException();
- }
-
- public ByteBuffer putInt(int index, int value) {
- throw new ReadOnlyBufferException();
- }
-
- public ByteBuffer putLong(int index, long value) {
- throw new ReadOnlyBufferException();
- }
-
- public ByteBuffer putLong(long value) {
- throw new ReadOnlyBufferException();
- }
-
- public ByteBuffer putShort(int index, short value) {
- throw new ReadOnlyBufferException();
- }
-
- public ByteBuffer putShort(short value) {
- throw new ReadOnlyBufferException();
- }
-
- public ByteBuffer put(ByteBuffer buf) {
- throw new ReadOnlyBufferException();
- }
-
- public ByteBuffer slice() {
- DirectReadOnlyByteBuffer slice = new DirectReadOnlyByteBuffer(byteArray.getBuffer(),
- remaining(), byteArray.getByteOffset() + position);
- slice.order = order;
- return slice;
- }
+ static DirectReadOnlyByteBuffer copy (DirectByteBuffer other, int markOfOther) {
+ DirectReadOnlyByteBuffer buf = new DirectReadOnlyByteBuffer(other.byteArray.getBuffer(), other.capacity(),
+ other.byteArray.getByteOffset());
+ buf.limit = other.limit();
+ buf.position = other.position();
+ buf.mark = markOfOther;
+ buf.order(other.order());
+ return buf;
+ }
+
+ DirectReadOnlyByteBuffer (ArrayBuffer backingArray, int capacity, int arrayOffset) {
+ super(backingArray, capacity, arrayOffset);
+ }
+
+ public ByteBuffer asReadOnlyBuffer () {
+ return copy(this, mark);
+ }
+
+ public ByteBuffer compact () {
+ throw new ReadOnlyBufferException();
+ }
+
+ public ByteBuffer duplicate () {
+ return copy(this, mark);
+ }
+
+ public boolean isReadOnly () {
+ return true;
+ }
+
+ protected byte[] protectedArray () {
+ throw new ReadOnlyBufferException();
+ }
+
+ protected int protectedArrayOffset () {
+ throw new ReadOnlyBufferException();
+ }
+
+ protected boolean protectedHasArray () {
+ return false;
+ }
+
+ public FloatBuffer asFloatBuffer () {
+ return DirectReadOnlyFloatBufferAdapter.wrap(this);
+ }
+
+ public IntBuffer asIntBuffer () {
+ return order() == ByteOrder.nativeOrder() ? DirectReadOnlyIntBufferAdapter.wrap(this) : super.asIntBuffer();
+ }
+
+ public ShortBuffer asShortBuffer () {
+ return order() == ByteOrder.nativeOrder() ? DirectReadOnlyShortBufferAdapter.wrap(this) : super.asShortBuffer();
+ }
+
+ public ByteBuffer put (byte b) {
+ throw new ReadOnlyBufferException();
+ }
+
+ public ByteBuffer put (int index, byte b) {
+ throw new ReadOnlyBufferException();
+ }
+
+ public ByteBuffer put (byte[] src, int off, int len) {
+ throw new ReadOnlyBufferException();
+ }
+
+ public ByteBuffer putDouble (double value) {
+ throw new ReadOnlyBufferException();
+ }
+
+ public ByteBuffer putDouble (int index, double value) {
+ throw new ReadOnlyBufferException();
+ }
+
+ public ByteBuffer putFloat (float value) {
+ throw new ReadOnlyBufferException();
+ }
+
+ public ByteBuffer putFloat (int index, float value) {
+ throw new ReadOnlyBufferException();
+ }
+
+ public ByteBuffer putInt (int value) {
+ throw new ReadOnlyBufferException();
+ }
+
+ public ByteBuffer putInt (int index, int value) {
+ throw new ReadOnlyBufferException();
+ }
+
+ public ByteBuffer putLong (int index, long value) {
+ throw new ReadOnlyBufferException();
+ }
+
+ public ByteBuffer putLong (long value) {
+ throw new ReadOnlyBufferException();
+ }
+
+ public ByteBuffer putShort (int index, short value) {
+ throw new ReadOnlyBufferException();
+ }
+
+ public ByteBuffer putShort (short value) {
+ throw new ReadOnlyBufferException();
+ }
+
+ public ByteBuffer put (ByteBuffer buf) {
+ throw new ReadOnlyBufferException();
+ }
+
+ public ByteBuffer slice () {
+ DirectReadOnlyByteBuffer slice = new DirectReadOnlyByteBuffer(byteArray.getBuffer(), remaining(), byteArray.getByteOffset()
+ + position);
+ slice.order = order;
+ return slice;
+ }
}
diff --git a/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/java/nio/DirectReadOnlyFloatBufferAdapter.java b/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/java/nio/DirectReadOnlyFloatBufferAdapter.java
index cc50b094e32..f33e8fa6197 100644
--- a/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/java/nio/DirectReadOnlyFloatBufferAdapter.java
+++ b/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/java/nio/DirectReadOnlyFloatBufferAdapter.java
@@ -19,131 +19,126 @@
import gwt.g3d.client.gl2.array.ArrayBufferView;
import gwt.g3d.client.gl2.array.Float32Array;
-/**
- * This class wraps a byte buffer to be a float buffer.
+/** This class wraps a byte buffer to be a float buffer.
*
* Implementation notice:
*
- * After a byte buffer instance is wrapped, it becomes privately owned by
- * the adapter. It must NOT be accessed outside the adapter any more.
- * The byte buffer's position and limit are NOT linked with the adapter.
- * The adapter extends Buffer, thus has its own position and limit.
+ * After a byte buffer instance is wrapped, it becomes privately owned by the adapter. It must NOT be accessed outside the
+ * adapter any more.
+ * The byte buffer's position and limit are NOT linked with the adapter. The adapter extends Buffer, thus has its own position
+ * and limit.
*
- *
- *
- */
+ * */
final class DirectReadOnlyFloatBufferAdapter extends FloatBuffer implements HasArrayBufferView {
-//implements DirectBuffer {
-
- static FloatBuffer wrap(DirectByteBuffer byteBuffer) {
- return new DirectReadOnlyFloatBufferAdapter((DirectByteBuffer) byteBuffer.slice());
- }
-
- private final DirectByteBuffer byteBuffer;
- private final Float32Array floatArray;
-
- DirectReadOnlyFloatBufferAdapter(DirectByteBuffer byteBuffer) {
- super((byteBuffer.capacity() >> 2));
- this.byteBuffer = byteBuffer;
- this.byteBuffer.clear();
- this.floatArray = Float32Array.create(byteBuffer.byteArray.getBuffer(),
- byteBuffer.byteArray.getByteOffset(),
- capacity);
- }
-
- @Override
- public FloatBuffer asReadOnlyBuffer() {
- DirectReadOnlyFloatBufferAdapter buf = new DirectReadOnlyFloatBufferAdapter(byteBuffer);
- buf.limit = limit;
- buf.position = position;
- buf.mark = mark;
- return buf;
- }
-
- @Override
- public FloatBuffer compact() {
- throw new ReadOnlyBufferException();
- }
-
- @Override
- public FloatBuffer duplicate() {
- DirectReadOnlyFloatBufferAdapter buf = new DirectReadOnlyFloatBufferAdapter(
- (DirectByteBuffer) byteBuffer.duplicate());
- buf.limit = limit;
- buf.position = position;
- buf.mark = mark;
- return buf;
- }
-
- @Override
- public float get() {
-// if (position == limit) {
-// throw new BufferUnderflowException();
-// }
- return floatArray.get(position++);
- }
-
- @Override
- public float get(int index) {
-// if (index < 0 || index >= limit) {
-// throw new IndexOutOfBoundsException();
-// }
- return floatArray.get(index);
- }
-
- @Override
- public boolean isDirect() {
- return true;
- }
-
- @Override
- public boolean isReadOnly() {
- return true;
- }
-
- @Override
- public ByteOrder order() {
- return byteBuffer.order();
- }
-
- @Override
- float[] protectedArray() {
- throw new UnsupportedOperationException();
- }
-
- @Override
- int protectedArrayOffset() {
- throw new UnsupportedOperationException();
- }
-
- @Override boolean protectedHasArray() {
- return false;
- }
-
- @Override
- public FloatBuffer put(float c) {
- throw new ReadOnlyBufferException();
- }
-
- @Override
- public FloatBuffer put(int index, float c) {
- throw new ReadOnlyBufferException();
- }
-
- @Override
- public FloatBuffer slice() {
- byteBuffer.limit(limit << 2);
- byteBuffer.position(position << 2);
- FloatBuffer result = new DirectReadOnlyFloatBufferAdapter((DirectByteBuffer) byteBuffer.slice());
- byteBuffer.clear();
- return result;
- }
-
- public ArrayBufferView getTypedArray() {
+// implements DirectBuffer {
+
+ static FloatBuffer wrap (DirectByteBuffer byteBuffer) {
+ return new DirectReadOnlyFloatBufferAdapter((DirectByteBuffer)byteBuffer.slice());
+ }
+
+ private final DirectByteBuffer byteBuffer;
+ private final Float32Array floatArray;
+
+ DirectReadOnlyFloatBufferAdapter (DirectByteBuffer byteBuffer) {
+ super((byteBuffer.capacity() >> 2));
+ this.byteBuffer = byteBuffer;
+ this.byteBuffer.clear();
+ this.floatArray = Float32Array.create(byteBuffer.byteArray.getBuffer(), byteBuffer.byteArray.getByteOffset(), capacity);
+ }
+
+ @Override
+ public FloatBuffer asReadOnlyBuffer () {
+ DirectReadOnlyFloatBufferAdapter buf = new DirectReadOnlyFloatBufferAdapter(byteBuffer);
+ buf.limit = limit;
+ buf.position = position;
+ buf.mark = mark;
+ return buf;
+ }
+
+ @Override
+ public FloatBuffer compact () {
+ throw new ReadOnlyBufferException();
+ }
+
+ @Override
+ public FloatBuffer duplicate () {
+ DirectReadOnlyFloatBufferAdapter buf = new DirectReadOnlyFloatBufferAdapter((DirectByteBuffer)byteBuffer.duplicate());
+ buf.limit = limit;
+ buf.position = position;
+ buf.mark = mark;
+ return buf;
+ }
+
+ @Override
+ public float get () {
+// if (position == limit) {
+// throw new BufferUnderflowException();
+// }
+ return floatArray.get(position++);
+ }
+
+ @Override
+ public float get (int index) {
+// if (index < 0 || index >= limit) {
+// throw new IndexOutOfBoundsException();
+// }
+ return floatArray.get(index);
+ }
+
+ @Override
+ public boolean isDirect () {
+ return true;
+ }
+
+ @Override
+ public boolean isReadOnly () {
+ return true;
+ }
+
+ @Override
+ public ByteOrder order () {
+ return byteBuffer.order();
+ }
+
+ @Override
+ float[] protectedArray () {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ int protectedArrayOffset () {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ boolean protectedHasArray () {
+ return false;
+ }
+
+ @Override
+ public FloatBuffer put (float c) {
+ throw new ReadOnlyBufferException();
+ }
+
+ @Override
+ public FloatBuffer put (int index, float c) {
+ throw new ReadOnlyBufferException();
+ }
+
+ @Override
+ public FloatBuffer slice () {
+ byteBuffer.limit(limit << 2);
+ byteBuffer.position(position << 2);
+ FloatBuffer result = new DirectReadOnlyFloatBufferAdapter((DirectByteBuffer)byteBuffer.slice());
+ byteBuffer.clear();
+ return result;
+ }
+
+ public ArrayBufferView getTypedArray () {
return floatArray;
}
- public int getElementSize() {
+ public int getElementSize () {
return 4;
}
}
diff --git a/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/java/nio/DirectReadOnlyIntBufferAdapter.java b/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/java/nio/DirectReadOnlyIntBufferAdapter.java
index 05ae39ea08c..745366132f9 100644
--- a/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/java/nio/DirectReadOnlyIntBufferAdapter.java
+++ b/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/java/nio/DirectReadOnlyIntBufferAdapter.java
@@ -19,132 +19,126 @@
import gwt.g3d.client.gl2.array.ArrayBufferView;
import gwt.g3d.client.gl2.array.Int32Array;
-/**
- * This class wraps a byte buffer to be a int buffer.
+/** This class wraps a byte buffer to be a int buffer.
*
* Implementation notice:
*
- * After a byte buffer instance is wrapped, it becomes privately owned by
- * the adapter. It must NOT be accessed outside the adapter any more.
- * The byte buffer's position and limit are NOT linked with the adapter.
- * The adapter extends Buffer, thus has its own position and limit.
+ * After a byte buffer instance is wrapped, it becomes privately owned by the adapter. It must NOT be accessed outside the
+ * adapter any more.
+ * The byte buffer's position and limit are NOT linked with the adapter. The adapter extends Buffer, thus has its own position
+ * and limit.
*
- *
- *
- */
+ * */
final class DirectReadOnlyIntBufferAdapter extends IntBuffer implements HasArrayBufferView {
-//implements DirectBuffer {
-
- static IntBuffer wrap(DirectByteBuffer byteBuffer) {
- return new DirectReadOnlyIntBufferAdapter((DirectByteBuffer) byteBuffer.slice());
- }
-
- private final DirectByteBuffer byteBuffer;
- private final Int32Array intArray;
-
- DirectReadOnlyIntBufferAdapter(DirectByteBuffer byteBuffer) {
- super((byteBuffer.capacity() >> 2));
- this.byteBuffer = byteBuffer;
- this.byteBuffer.clear();
- this.intArray = Int32Array.create(byteBuffer.byteArray.getBuffer(),
- byteBuffer.byteArray.getByteOffset(),
- capacity);
- }
-
- @Override
- public IntBuffer asReadOnlyBuffer() {
- DirectReadOnlyIntBufferAdapter buf = new DirectReadOnlyIntBufferAdapter(byteBuffer);
- buf.limit = limit;
- buf.position = position;
- buf.mark = mark;
- return buf;
- }
-
- @Override
- public IntBuffer compact() {
- throw new ReadOnlyBufferException();
- }
-
- @Override
- public IntBuffer duplicate() {
- DirectReadOnlyIntBufferAdapter buf = new DirectReadOnlyIntBufferAdapter(
- (DirectByteBuffer) byteBuffer.duplicate());
- buf.limit = limit;
- buf.position = position;
- buf.mark = mark;
- return buf;
- }
-
- @Override
- public int get() {
-// if (position == limit) {
-// throw new BufferUnderflowException();
-// }
- return intArray.get(position++);
- }
-
- @Override
- public int get(int index) {
- if (index < 0 || index >= limit) {
- throw new IndexOutOfBoundsException();
- }
- return intArray.get(index);
- }
-
- @Override
- public boolean isDirect() {
- return true;
- }
-
- @Override
- public boolean isReadOnly() {
- return true;
- }
-
- @Override
- public ByteOrder order() {
- return byteBuffer.order();
- }
-
- @Override
- protected int[] protectedArray() {
- throw new UnsupportedOperationException();
- }
-
- @Override
- protected int protectedArrayOffset() {
- throw new UnsupportedOperationException();
- }
-
- @Override
- protected boolean protectedHasArray() {
- return false;
- }
-
- @Override
- public IntBuffer put(int c) {
- throw new ReadOnlyBufferException();
- }
-
- @Override
- public IntBuffer put(int index, int c) {
- throw new ReadOnlyBufferException();
- }
-
- @Override
- public IntBuffer slice() {
- byteBuffer.limit(limit << 2);
- byteBuffer.position(position << 2);
- IntBuffer result = new DirectReadOnlyIntBufferAdapter((DirectByteBuffer) byteBuffer.slice());
- byteBuffer.clear();
- return result;
- }
-
- public ArrayBufferView getTypedArray() {
+// implements DirectBuffer {
+
+ static IntBuffer wrap (DirectByteBuffer byteBuffer) {
+ return new DirectReadOnlyIntBufferAdapter((DirectByteBuffer)byteBuffer.slice());
+ }
+
+ private final DirectByteBuffer byteBuffer;
+ private final Int32Array intArray;
+
+ DirectReadOnlyIntBufferAdapter (DirectByteBuffer byteBuffer) {
+ super((byteBuffer.capacity() >> 2));
+ this.byteBuffer = byteBuffer;
+ this.byteBuffer.clear();
+ this.intArray = Int32Array.create(byteBuffer.byteArray.getBuffer(), byteBuffer.byteArray.getByteOffset(), capacity);
+ }
+
+ @Override
+ public IntBuffer asReadOnlyBuffer () {
+ DirectReadOnlyIntBufferAdapter buf = new DirectReadOnlyIntBufferAdapter(byteBuffer);
+ buf.limit = limit;
+ buf.position = position;
+ buf.mark = mark;
+ return buf;
+ }
+
+ @Override
+ public IntBuffer compact () {
+ throw new ReadOnlyBufferException();
+ }
+
+ @Override
+ public IntBuffer duplicate () {
+ DirectReadOnlyIntBufferAdapter buf = new DirectReadOnlyIntBufferAdapter((DirectByteBuffer)byteBuffer.duplicate());
+ buf.limit = limit;
+ buf.position = position;
+ buf.mark = mark;
+ return buf;
+ }
+
+ @Override
+ public int get () {
+// if (position == limit) {
+// throw new BufferUnderflowException();
+// }
+ return intArray.get(position++);
+ }
+
+ @Override
+ public int get (int index) {
+ if (index < 0 || index >= limit) {
+ throw new IndexOutOfBoundsException();
+ }
+ return intArray.get(index);
+ }
+
+ @Override
+ public boolean isDirect () {
+ return true;
+ }
+
+ @Override
+ public boolean isReadOnly () {
+ return true;
+ }
+
+ @Override
+ public ByteOrder order () {
+ return byteBuffer.order();
+ }
+
+ @Override
+ protected int[] protectedArray () {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ protected int protectedArrayOffset () {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ protected boolean protectedHasArray () {
+ return false;
+ }
+
+ @Override
+ public IntBuffer put (int c) {
+ throw new ReadOnlyBufferException();
+ }
+
+ @Override
+ public IntBuffer put (int index, int c) {
+ throw new ReadOnlyBufferException();
+ }
+
+ @Override
+ public IntBuffer slice () {
+ byteBuffer.limit(limit << 2);
+ byteBuffer.position(position << 2);
+ IntBuffer result = new DirectReadOnlyIntBufferAdapter((DirectByteBuffer)byteBuffer.slice());
+ byteBuffer.clear();
+ return result;
+ }
+
+ public ArrayBufferView getTypedArray () {
return intArray;
}
- public int getElementSize() {
+ public int getElementSize () {
return 4;
}
}
diff --git a/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/java/nio/DirectReadOnlyShortBufferAdapter.java b/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/java/nio/DirectReadOnlyShortBufferAdapter.java
index 8aed5da4c73..0ba252522a2 100644
--- a/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/java/nio/DirectReadOnlyShortBufferAdapter.java
+++ b/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/java/nio/DirectReadOnlyShortBufferAdapter.java
@@ -19,131 +19,125 @@
import gwt.g3d.client.gl2.array.ArrayBufferView;
import gwt.g3d.client.gl2.array.Int16Array;
-/**
- * This class wraps a byte buffer to be a short buffer.
+/** This class wraps a byte buffer to be a short buffer.
*
* Implementation notice:
*
- * After a byte buffer instance is wrapped, it becomes privately owned by
- * the adapter. It must NOT be accessed outside the adapter any more.
- * The byte buffer's position and limit are NOT linked with the adapter.
- * The adapter extends Buffer, thus has its own position and limit.
+ * After a byte buffer instance is wrapped, it becomes privately owned by the adapter. It must NOT be accessed outside the
+ * adapter any more.
+ * The byte buffer's position and limit are NOT linked with the adapter. The adapter extends Buffer, thus has its own position
+ * and limit.
*
- *
- *
- */
+ * */
final class DirectReadOnlyShortBufferAdapter extends ShortBuffer implements HasArrayBufferView {
- static ShortBuffer wrap(DirectByteBuffer byteBuffer) {
- return new DirectReadOnlyShortBufferAdapter((DirectByteBuffer) byteBuffer.slice());
- }
-
- private final DirectByteBuffer byteBuffer;
- private final Int16Array shortArray;
-
- DirectReadOnlyShortBufferAdapter(DirectByteBuffer byteBuffer) {
- super((byteBuffer.capacity() >> 1));
- this.byteBuffer = byteBuffer;
- this.byteBuffer.clear();
- this.shortArray = Int16Array.create(byteBuffer.byteArray.getBuffer(),
- byteBuffer.byteArray.getByteOffset(),
- capacity);
- }
-
- @Override
- public ShortBuffer asReadOnlyBuffer() {
- DirectReadOnlyShortBufferAdapter buf = new DirectReadOnlyShortBufferAdapter(byteBuffer);
- buf.limit = limit;
- buf.position = position;
- buf.mark = mark;
- return buf;
- }
-
- @Override
- public ShortBuffer compact() {
- throw new ReadOnlyBufferException();
- }
-
- @Override
- public ShortBuffer duplicate() {
- DirectReadOnlyShortBufferAdapter buf = new DirectReadOnlyShortBufferAdapter(
- (DirectByteBuffer) byteBuffer.duplicate());
- buf.limit = limit;
- buf.position = position;
- buf.mark = mark;
- return buf;
- }
-
- @Override
- public short get() {
-// if (position == limit) {
-// throw new BufferUnderflowException();
-// }
- return (short)shortArray.get(position++);
- }
-
- @Override
- public short get(int index) {
-// if (index < 0 || index >= limit) {
-// throw new IndexOutOfBoundsException();
-// }
- return (short)shortArray.get(index);
- }
-
- @Override
- public boolean isDirect() {
- return true;
- }
-
- @Override
- public boolean isReadOnly() {
- return true;
- }
-
- @Override
- public ByteOrder order() {
- return byteBuffer.order();
- }
-
- @Override
- protected short[] protectedArray() {
- throw new UnsupportedOperationException();
- }
-
- @Override
- protected int protectedArrayOffset() {
- throw new UnsupportedOperationException();
- }
-
- @Override
- protected boolean protectedHasArray() {
- return false;
- }
-
- @Override
- public ShortBuffer put(short c) {
- throw new ReadOnlyBufferException();
- }
-
- @Override
- public ShortBuffer put(int index, short c) {
- throw new ReadOnlyBufferException();
- }
-
- @Override
- public ShortBuffer slice() {
- byteBuffer.limit(limit << 1);
- byteBuffer.position(position << 1);
- ShortBuffer result = new DirectReadOnlyShortBufferAdapter((DirectByteBuffer) byteBuffer.slice());
- byteBuffer.clear();
- return result;
- }
-
- public ArrayBufferView getTypedArray() {
+ static ShortBuffer wrap (DirectByteBuffer byteBuffer) {
+ return new DirectReadOnlyShortBufferAdapter((DirectByteBuffer)byteBuffer.slice());
+ }
+
+ private final DirectByteBuffer byteBuffer;
+ private final Int16Array shortArray;
+
+ DirectReadOnlyShortBufferAdapter (DirectByteBuffer byteBuffer) {
+ super((byteBuffer.capacity() >> 1));
+ this.byteBuffer = byteBuffer;
+ this.byteBuffer.clear();
+ this.shortArray = Int16Array.create(byteBuffer.byteArray.getBuffer(), byteBuffer.byteArray.getByteOffset(), capacity);
+ }
+
+ @Override
+ public ShortBuffer asReadOnlyBuffer () {
+ DirectReadOnlyShortBufferAdapter buf = new DirectReadOnlyShortBufferAdapter(byteBuffer);
+ buf.limit = limit;
+ buf.position = position;
+ buf.mark = mark;
+ return buf;
+ }
+
+ @Override
+ public ShortBuffer compact () {
+ throw new ReadOnlyBufferException();
+ }
+
+ @Override
+ public ShortBuffer duplicate () {
+ DirectReadOnlyShortBufferAdapter buf = new DirectReadOnlyShortBufferAdapter((DirectByteBuffer)byteBuffer.duplicate());
+ buf.limit = limit;
+ buf.position = position;
+ buf.mark = mark;
+ return buf;
+ }
+
+ @Override
+ public short get () {
+// if (position == limit) {
+// throw new BufferUnderflowException();
+// }
+ return (short)shortArray.get(position++);
+ }
+
+ @Override
+ public short get (int index) {
+// if (index < 0 || index >= limit) {
+// throw new IndexOutOfBoundsException();
+// }
+ return (short)shortArray.get(index);
+ }
+
+ @Override
+ public boolean isDirect () {
+ return true;
+ }
+
+ @Override
+ public boolean isReadOnly () {
+ return true;
+ }
+
+ @Override
+ public ByteOrder order () {
+ return byteBuffer.order();
+ }
+
+ @Override
+ protected short[] protectedArray () {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ protected int protectedArrayOffset () {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ protected boolean protectedHasArray () {
+ return false;
+ }
+
+ @Override
+ public ShortBuffer put (short c) {
+ throw new ReadOnlyBufferException();
+ }
+
+ @Override
+ public ShortBuffer put (int index, short c) {
+ throw new ReadOnlyBufferException();
+ }
+
+ @Override
+ public ShortBuffer slice () {
+ byteBuffer.limit(limit << 1);
+ byteBuffer.position(position << 1);
+ ShortBuffer result = new DirectReadOnlyShortBufferAdapter((DirectByteBuffer)byteBuffer.slice());
+ byteBuffer.clear();
+ return result;
+ }
+
+ public ArrayBufferView getTypedArray () {
return shortArray;
}
- public int getElementSize() {
+ public int getElementSize () {
return 2;
}
}
diff --git a/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/java/nio/DirectReadWriteByteBuffer.java b/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/java/nio/DirectReadWriteByteBuffer.java
index 9cf19a04514..f5959278fce 100644
--- a/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/java/nio/DirectReadWriteByteBuffer.java
+++ b/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/java/nio/DirectReadWriteByteBuffer.java
@@ -20,210 +20,202 @@
import com.google.gwt.corp.compatibility.Numbers;
-/**
- * DirectByteBuffer, DirectReadWriteByteBuffer and DirectReadOnlyByteBuffer compose
- * the implementation of direct byte buffers.
+/** DirectByteBuffer, DirectReadWriteByteBuffer and DirectReadOnlyByteBuffer compose the implementation of direct byte buffers.
*
* DirectReadWriteByteBuffer extends DirectByteBuffer with all the write methods.
*
*
* This class is marked final for runtime performance.
- *
- *
- */
+ * */
final class DirectReadWriteByteBuffer extends DirectByteBuffer {
- static DirectReadWriteByteBuffer copy(DirectByteBuffer other, int markOfOther) {
- DirectReadWriteByteBuffer buf = new DirectReadWriteByteBuffer(
- other.byteArray.getBuffer(), other.capacity(), other.byteArray.getByteOffset());
- buf.limit = other.limit();
- buf.position = other.position();
- buf.mark = markOfOther;
- buf.order(other.order());
- return buf;
- }
-
- DirectReadWriteByteBuffer(ArrayBuffer backingArray) {
- super(backingArray);
- }
-
- DirectReadWriteByteBuffer(int capacity) {
- super(capacity);
- }
-
- DirectReadWriteByteBuffer(ArrayBuffer backingArray, int capacity, int arrayOffset) {
- super(backingArray, capacity, arrayOffset);
- }
-
- public FloatBuffer asFloatBuffer() {
- return DirectReadWriteFloatBufferAdapter.wrap(this);
- }
-
- public IntBuffer asIntBuffer() {
- return order() == ByteOrder.nativeOrder()
- ? DirectReadWriteIntBufferAdapter.wrap(this)
- : super.asIntBuffer();
- }
-
- public ShortBuffer asShortBuffer() {
- return order() == ByteOrder.nativeOrder()
- ? DirectReadWriteShortBufferAdapter.wrap(this)
- : super.asShortBuffer();
- }
-
- public ByteBuffer asReadOnlyBuffer() {
- return DirectReadOnlyByteBuffer.copy(this, mark);
- }
-
- public ByteBuffer compact() {
-// System.arraycopy(backingArray, position + offset, backingArray, offset,
-// remaining());
-
- int rem = remaining();
- for (int i = 0; i < rem; i++) {
- byteArray.set(i, byteArray.get(position + i));
- }
-
- position = limit - position;
- limit = capacity;
- mark = UNSET_MARK;
- return this;
- }
-
- public ByteBuffer duplicate() {
- return copy(this, mark);
- }
-
- public boolean isReadOnly() {
- return false;
- }
-
- protected byte[] protectedArray() {
- throw new UnsupportedOperationException();
- }
-
- protected int protectedArrayOffset() {
- throw new UnsupportedOperationException();
- }
-
- protected boolean protectedHasArray() {
- return true;
- }
-
- public ByteBuffer put(byte b) {
-// if (position == limit) {
-// throw new BufferOverflowException();
-// }
- byteArray.set(position++, b);
- return this;
- }
-
- public ByteBuffer put(int index, byte b) {
-// if (index < 0 || index >= limit) {
-// throw new IndexOutOfBoundsException();
-// }
- byteArray.set(index, b);
- return this;
- }
-
- /*
- * Override ByteBuffer.put(byte[], int, int) to improve performance.
- *
- * (non-Javadoc)
- *
- * @see java.nio.ByteBuffer#put(byte[], int, int)
- */
- public ByteBuffer put(byte[] src, int off, int len) {
- if (off < 0 || len < 0 || (long)off + (long)len > src.length) {
- throw new IndexOutOfBoundsException();
- }
- if (len > remaining()) {
- throw new BufferOverflowException();
- }
- if (isReadOnly()) {
- throw new ReadOnlyBufferException();
- }
- for (int i = 0; i < len; i++) {
- byteArray.set(i + position, src[off + i]);
- }
- position += len;
- return this;
- }
-
- public ByteBuffer putDouble(double value) {
- return putLong(Numbers.doubleToRawLongBits(value));
- }
-
- public ByteBuffer putDouble(int index, double value) {
- return putLong(index, Numbers.doubleToRawLongBits(value));
- }
-
- public ByteBuffer putFloat(float value) {
- return putInt(Numbers.floatToIntBits(value));
- }
-
- public ByteBuffer putFloat(int index, float value) {
- return putInt(index, Numbers.floatToIntBits(value));
- }
-
- public ByteBuffer putInt(int value) {
- int newPosition = position + 4;
-// if (newPosition > limit) {
-// throw new BufferOverflowException();
-// }
- store(position, value);
- position = newPosition;
- return this;
- }
-
- public ByteBuffer putInt(int index, int value) {
-// if (index < 0 || (long)index + 4 > limit) {
-// throw new IndexOutOfBoundsException();
-// }
- store(index, value);
- return this;
- }
-
- public ByteBuffer putLong(int index, long value) {
-// if (index < 0 || (long)index + 8 > limit) {
-// throw new IndexOutOfBoundsException();
-// }
- store(index, value);
- return this;
- }
-
- public ByteBuffer putLong(long value) {
- int newPosition = position + 8;
-// if (newPosition > limit) {
-// throw new BufferOverflowException();
-// }
- store(position, value);
- position = newPosition;
- return this;
- }
-
- public ByteBuffer putShort(int index, short value) {
-// if (index < 0 || (long)index + 2 > limit) {
-// throw new IndexOutOfBoundsException();
-// }
- store(index, value);
- return this;
- }
-
- public ByteBuffer putShort(short value) {
- int newPosition = position + 2;
-// if (newPosition > limit) {
-// throw new BufferOverflowException();
-// }
- store(position, value);
- position = newPosition;
- return this;
- }
-
- public ByteBuffer slice() {
- DirectReadWriteByteBuffer slice = new DirectReadWriteByteBuffer(
- byteArray.getBuffer(), remaining(), byteArray.getByteOffset() + position);
- slice.order = order;
- return slice;
- }
+ static DirectReadWriteByteBuffer copy (DirectByteBuffer other, int markOfOther) {
+ DirectReadWriteByteBuffer buf = new DirectReadWriteByteBuffer(other.byteArray.getBuffer(), other.capacity(),
+ other.byteArray.getByteOffset());
+ buf.limit = other.limit();
+ buf.position = other.position();
+ buf.mark = markOfOther;
+ buf.order(other.order());
+ return buf;
+ }
+
+ DirectReadWriteByteBuffer (ArrayBuffer backingArray) {
+ super(backingArray);
+ }
+
+ DirectReadWriteByteBuffer (int capacity) {
+ super(capacity);
+ }
+
+ DirectReadWriteByteBuffer (ArrayBuffer backingArray, int capacity, int arrayOffset) {
+ super(backingArray, capacity, arrayOffset);
+ }
+
+ public FloatBuffer asFloatBuffer () {
+ return DirectReadWriteFloatBufferAdapter.wrap(this);
+ }
+
+ public IntBuffer asIntBuffer () {
+ return order() == ByteOrder.nativeOrder() ? DirectReadWriteIntBufferAdapter.wrap(this) : super.asIntBuffer();
+ }
+
+ public ShortBuffer asShortBuffer () {
+ return order() == ByteOrder.nativeOrder() ? DirectReadWriteShortBufferAdapter.wrap(this) : super.asShortBuffer();
+ }
+
+ public ByteBuffer asReadOnlyBuffer () {
+ return DirectReadOnlyByteBuffer.copy(this, mark);
+ }
+
+ public ByteBuffer compact () {
+// System.arraycopy(backingArray, position + offset, backingArray, offset,
+// remaining());
+
+ int rem = remaining();
+ for (int i = 0; i < rem; i++) {
+ byteArray.set(i, byteArray.get(position + i));
+ }
+
+ position = limit - position;
+ limit = capacity;
+ mark = UNSET_MARK;
+ return this;
+ }
+
+ public ByteBuffer duplicate () {
+ return copy(this, mark);
+ }
+
+ public boolean isReadOnly () {
+ return false;
+ }
+
+ protected byte[] protectedArray () {
+ throw new UnsupportedOperationException();
+ }
+
+ protected int protectedArrayOffset () {
+ throw new UnsupportedOperationException();
+ }
+
+ protected boolean protectedHasArray () {
+ return true;
+ }
+
+ public ByteBuffer put (byte b) {
+// if (position == limit) {
+// throw new BufferOverflowException();
+// }
+ byteArray.set(position++, b);
+ return this;
+ }
+
+ public ByteBuffer put (int index, byte b) {
+// if (index < 0 || index >= limit) {
+// throw new IndexOutOfBoundsException();
+// }
+ byteArray.set(index, b);
+ return this;
+ }
+
+ /*
+ * Override ByteBuffer.put(byte[], int, int) to improve performance.
+ *
+ * (non-Javadoc)
+ *
+ * @see java.nio.ByteBuffer#put(byte[], int, int)
+ */
+ public ByteBuffer put (byte[] src, int off, int len) {
+ if (off < 0 || len < 0 || (long)off + (long)len > src.length) {
+ throw new IndexOutOfBoundsException();
+ }
+ if (len > remaining()) {
+ throw new BufferOverflowException();
+ }
+ if (isReadOnly()) {
+ throw new ReadOnlyBufferException();
+ }
+ for (int i = 0; i < len; i++) {
+ byteArray.set(i + position, src[off + i]);
+ }
+ position += len;
+ return this;
+ }
+
+ public ByteBuffer putDouble (double value) {
+ return putLong(Numbers.doubleToRawLongBits(value));
+ }
+
+ public ByteBuffer putDouble (int index, double value) {
+ return putLong(index, Numbers.doubleToRawLongBits(value));
+ }
+
+ public ByteBuffer putFloat (float value) {
+ return putInt(Numbers.floatToIntBits(value));
+ }
+
+ public ByteBuffer putFloat (int index, float value) {
+ return putInt(index, Numbers.floatToIntBits(value));
+ }
+
+ public ByteBuffer putInt (int value) {
+ int newPosition = position + 4;
+// if (newPosition > limit) {
+// throw new BufferOverflowException();
+// }
+ store(position, value);
+ position = newPosition;
+ return this;
+ }
+
+ public ByteBuffer putInt (int index, int value) {
+// if (index < 0 || (long)index + 4 > limit) {
+// throw new IndexOutOfBoundsException();
+// }
+ store(index, value);
+ return this;
+ }
+
+ public ByteBuffer putLong (int index, long value) {
+// if (index < 0 || (long)index + 8 > limit) {
+// throw new IndexOutOfBoundsException();
+// }
+ store(index, value);
+ return this;
+ }
+
+ public ByteBuffer putLong (long value) {
+ int newPosition = position + 8;
+// if (newPosition > limit) {
+// throw new BufferOverflowException();
+// }
+ store(position, value);
+ position = newPosition;
+ return this;
+ }
+
+ public ByteBuffer putShort (int index, short value) {
+// if (index < 0 || (long)index + 2 > limit) {
+// throw new IndexOutOfBoundsException();
+// }
+ store(index, value);
+ return this;
+ }
+
+ public ByteBuffer putShort (short value) {
+ int newPosition = position + 2;
+// if (newPosition > limit) {
+// throw new BufferOverflowException();
+// }
+ store(position, value);
+ position = newPosition;
+ return this;
+ }
+
+ public ByteBuffer slice () {
+ DirectReadWriteByteBuffer slice = new DirectReadWriteByteBuffer(byteArray.getBuffer(), remaining(),
+ byteArray.getByteOffset() + position);
+ slice.order = order;
+ return slice;
+ }
}
diff --git a/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/java/nio/DirectReadWriteFloatBufferAdapter.java b/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/java/nio/DirectReadWriteFloatBufferAdapter.java
index cc4878027bf..ad208eae637 100644
--- a/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/java/nio/DirectReadWriteFloatBufferAdapter.java
+++ b/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/java/nio/DirectReadWriteFloatBufferAdapter.java
@@ -19,149 +19,143 @@
import gwt.g3d.client.gl2.array.ArrayBufferView;
import gwt.g3d.client.gl2.array.Float32Array;
-/**
- * This class wraps a byte buffer to be a float buffer.
+/** This class wraps a byte buffer to be a float buffer.
*
* Implementation notice:
*
- * After a byte buffer instance is wrapped, it becomes privately owned by
- * the adapter. It must NOT be accessed outside the adapter any more.
- * The byte buffer's position and limit are NOT linked with the adapter.
- * The adapter extends Buffer, thus has its own position and limit.
+ * After a byte buffer instance is wrapped, it becomes privately owned by the adapter. It must NOT be accessed outside the
+ * adapter any more.
+ * The byte buffer's position and limit are NOT linked with the adapter. The adapter extends Buffer, thus has its own position
+ * and limit.
*
- *
- *
- */
+ * */
final class DirectReadWriteFloatBufferAdapter extends FloatBuffer implements HasArrayBufferView {
-//implements DirectBuffer {
-
- static FloatBuffer wrap(DirectReadWriteByteBuffer byteBuffer) {
- return new DirectReadWriteFloatBufferAdapter((DirectReadWriteByteBuffer) byteBuffer.slice());
- }
-
- private final DirectReadWriteByteBuffer byteBuffer;
- private final Float32Array floatArray;
-
- DirectReadWriteFloatBufferAdapter(DirectReadWriteByteBuffer byteBuffer) {
- super((byteBuffer.capacity() >> 2));
- this.byteBuffer = byteBuffer;
- this.byteBuffer.clear();
- this.floatArray = Float32Array.create(byteBuffer.byteArray.getBuffer(),
- byteBuffer.byteArray.getByteOffset(),
- capacity);
- }
-
- // TODO(haustein) This will be slow
- @Override
- public FloatBuffer asReadOnlyBuffer() {
- DirectReadOnlyFloatBufferAdapter buf = new DirectReadOnlyFloatBufferAdapter(byteBuffer);
- buf.limit = limit;
- buf.position = position;
- buf.mark = mark;
- return buf;
- }
-
- @Override
- public FloatBuffer compact() {
- byteBuffer.limit(limit << 2);
- byteBuffer.position(position << 2);
- byteBuffer.compact();
- byteBuffer.clear();
- position = limit - position;
- limit = capacity;
- mark = UNSET_MARK;
- return this;
- }
-
- @Override
- public FloatBuffer duplicate() {
- DirectReadWriteFloatBufferAdapter buf = new DirectReadWriteFloatBufferAdapter(
- (DirectReadWriteByteBuffer) byteBuffer.duplicate());
- buf.limit = limit;
- buf.position = position;
- buf.mark = mark;
- return buf;
- }
-
- @Override
- public float get() {
-// if (position == limit) {
-// throw new BufferUnderflowException();
-// }
- return floatArray.get(position++);
- }
-
- @Override
- public float get(int index) {
-// if (index < 0 || index >= limit) {
-// throw new IndexOutOfBoundsException();
-// }
- return floatArray.get(index);
- }
-
- @Override
- public boolean isDirect() {
- return true;
- }
-
- @Override
- public boolean isReadOnly() {
- return false;
- }
-
- @Override
- public ByteOrder order() {
- return byteBuffer.order();
- }
-
- @Override
- protected float[] protectedArray() {
- throw new UnsupportedOperationException();
- }
-
- @Override
- protected int protectedArrayOffset() {
- throw new UnsupportedOperationException();
- }
-
- @Override
- protected boolean protectedHasArray() {
- return false;
- }
-
- @Override
- public FloatBuffer put(float c) {
-// if (position == limit) {
-// throw new BufferOverflowException();
-// }
- floatArray.set(position++, c);
- return this;
- }
-
- @Override
- public FloatBuffer put(int index, float c) {
-// if (index < 0 || index >= limit) {
-// throw new IndexOutOfBoundsException();
-// }
- floatArray.set(index, c);
- return this;
- }
-
- @Override
- public FloatBuffer slice() {
- byteBuffer.limit(limit << 2);
- byteBuffer.position(position << 2);
- FloatBuffer result = new DirectReadWriteFloatBufferAdapter((DirectReadWriteByteBuffer)
- byteBuffer.slice());
- byteBuffer.clear();
- return result;
- }
-
- public ArrayBufferView getTypedArray() {
+// implements DirectBuffer {
+
+ static FloatBuffer wrap (DirectReadWriteByteBuffer byteBuffer) {
+ return new DirectReadWriteFloatBufferAdapter((DirectReadWriteByteBuffer)byteBuffer.slice());
+ }
+
+ private final DirectReadWriteByteBuffer byteBuffer;
+ private final Float32Array floatArray;
+
+ DirectReadWriteFloatBufferAdapter (DirectReadWriteByteBuffer byteBuffer) {
+ super((byteBuffer.capacity() >> 2));
+ this.byteBuffer = byteBuffer;
+ this.byteBuffer.clear();
+ this.floatArray = Float32Array.create(byteBuffer.byteArray.getBuffer(), byteBuffer.byteArray.getByteOffset(), capacity);
+ }
+
+ // TODO(haustein) This will be slow
+ @Override
+ public FloatBuffer asReadOnlyBuffer () {
+ DirectReadOnlyFloatBufferAdapter buf = new DirectReadOnlyFloatBufferAdapter(byteBuffer);
+ buf.limit = limit;
+ buf.position = position;
+ buf.mark = mark;
+ return buf;
+ }
+
+ @Override
+ public FloatBuffer compact () {
+ byteBuffer.limit(limit << 2);
+ byteBuffer.position(position << 2);
+ byteBuffer.compact();
+ byteBuffer.clear();
+ position = limit - position;
+ limit = capacity;
+ mark = UNSET_MARK;
+ return this;
+ }
+
+ @Override
+ public FloatBuffer duplicate () {
+ DirectReadWriteFloatBufferAdapter buf = new DirectReadWriteFloatBufferAdapter(
+ (DirectReadWriteByteBuffer)byteBuffer.duplicate());
+ buf.limit = limit;
+ buf.position = position;
+ buf.mark = mark;
+ return buf;
+ }
+
+ @Override
+ public float get () {
+// if (position == limit) {
+// throw new BufferUnderflowException();
+// }
+ return floatArray.get(position++);
+ }
+
+ @Override
+ public float get (int index) {
+// if (index < 0 || index >= limit) {
+// throw new IndexOutOfBoundsException();
+// }
+ return floatArray.get(index);
+ }
+
+ @Override
+ public boolean isDirect () {
+ return true;
+ }
+
+ @Override
+ public boolean isReadOnly () {
+ return false;
+ }
+
+ @Override
+ public ByteOrder order () {
+ return byteBuffer.order();
+ }
+
+ @Override
+ protected float[] protectedArray () {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ protected int protectedArrayOffset () {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ protected boolean protectedHasArray () {
+ return false;
+ }
+
+ @Override
+ public FloatBuffer put (float c) {
+// if (position == limit) {
+// throw new BufferOverflowException();
+// }
+ floatArray.set(position++, c);
+ return this;
+ }
+
+ @Override
+ public FloatBuffer put (int index, float c) {
+// if (index < 0 || index >= limit) {
+// throw new IndexOutOfBoundsException();
+// }
+ floatArray.set(index, c);
+ return this;
+ }
+
+ @Override
+ public FloatBuffer slice () {
+ byteBuffer.limit(limit << 2);
+ byteBuffer.position(position << 2);
+ FloatBuffer result = new DirectReadWriteFloatBufferAdapter((DirectReadWriteByteBuffer)byteBuffer.slice());
+ byteBuffer.clear();
+ return result;
+ }
+
+ public ArrayBufferView getTypedArray () {
return floatArray;
}
- public int getElementSize() {
+ public int getElementSize () {
return 4;
}
}
diff --git a/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/java/nio/DirectReadWriteIntBufferAdapter.java b/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/java/nio/DirectReadWriteIntBufferAdapter.java
index c3f6bddd12c..c79da9f6dc9 100644
--- a/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/java/nio/DirectReadWriteIntBufferAdapter.java
+++ b/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/java/nio/DirectReadWriteIntBufferAdapter.java
@@ -19,149 +19,141 @@
import gwt.g3d.client.gl2.array.ArrayBufferView;
import gwt.g3d.client.gl2.array.Int32Array;
-/**
- * This class wraps a byte buffer to be a int buffer.
+/** This class wraps a byte buffer to be a int buffer.
*
* Implementation notice:
*
- * After a byte buffer instance is wrapped, it becomes privately owned by
- * the adapter. It must NOT be accessed outside the adapter any more.
- * The byte buffer's position and limit are NOT linked with the adapter.
- * The adapter extends Buffer, thus has its own position and limit.
+ * After a byte buffer instance is wrapped, it becomes privately owned by the adapter. It must NOT be accessed outside the
+ * adapter any more.
+ * The byte buffer's position and limit are NOT linked with the adapter. The adapter extends Buffer, thus has its own position
+ * and limit.
*
- *
- *
- */
+ * */
final class DirectReadWriteIntBufferAdapter extends IntBuffer implements HasArrayBufferView {
- static IntBuffer wrap(DirectReadWriteByteBuffer byteBuffer) {
- return new DirectReadWriteIntBufferAdapter((DirectReadWriteByteBuffer) byteBuffer.slice());
- }
-
- private final DirectReadWriteByteBuffer byteBuffer;
- private final Int32Array intArray;
-
- DirectReadWriteIntBufferAdapter(DirectReadWriteByteBuffer byteBuffer) {
- super((byteBuffer.capacity() >> 2));
- this.byteBuffer = byteBuffer;
- this.byteBuffer.clear();
- this.intArray = Int32Array.create(byteBuffer.byteArray.getBuffer(),
- byteBuffer.byteArray.getByteOffset(),
- capacity);
- }
-
- // TODO(haustein) This will be slow
- @Override
- public IntBuffer asReadOnlyBuffer() {
- DirectReadOnlyIntBufferAdapter buf = new DirectReadOnlyIntBufferAdapter(byteBuffer);
- buf.limit = limit;
- buf.position = position;
- buf.mark = mark;
- return buf;
- }
-
- @Override
- public IntBuffer compact() {
- byteBuffer.limit(limit << 2);
- byteBuffer.position(position << 2);
- byteBuffer.compact();
- byteBuffer.clear();
- position = limit - position;
- limit = capacity;
- mark = UNSET_MARK;
- return this;
- }
-
- @Override
- public IntBuffer duplicate() {
- DirectReadWriteIntBufferAdapter buf = new DirectReadWriteIntBufferAdapter(
- (DirectReadWriteByteBuffer) byteBuffer.duplicate());
- buf.limit = limit;
- buf.position = position;
- buf.mark = mark;
- return buf;
- }
-
- @Override
- public int get() {
-// if (position == limit) {
-// throw new BufferUnderflowException();
-// }
- return intArray.get(position++);
- }
-
- @Override
- public int get(int index) {
-// if (index < 0 || index >= limit) {
-// throw new IndexOutOfBoundsException();
-// }
- return intArray.get(index);
- }
-
- @Override
- public boolean isDirect() {
- return true;
- }
-
- @Override
- public boolean isReadOnly() {
- return false;
- }
-
- @Override
- public ByteOrder order() {
- return byteBuffer.order();
- }
-
- @Override
- protected int[] protectedArray() {
- throw new UnsupportedOperationException();
- }
-
- @Override
- protected int protectedArrayOffset() {
- throw new UnsupportedOperationException();
- }
-
- @Override
- protected boolean protectedHasArray() {
- return false;
- }
-
- @Override
- public IntBuffer put(int c) {
-// if (position == limit) {
-// throw new BufferOverflowException();
-// }
- intArray.set(position++, c);
- return this;
- }
-
- @Override
- public IntBuffer put(int index, int c) {
-// if (index < 0 || index >= limit) {
-// throw new IndexOutOfBoundsException();
-// }
- intArray.set(index, c);
- return this;
- }
-
- @Override
- public IntBuffer slice() {
- byteBuffer.limit(limit << 2);
- byteBuffer.position(position << 2);
- IntBuffer result = new DirectReadWriteIntBufferAdapter((DirectReadWriteByteBuffer)
- byteBuffer.slice());
- byteBuffer.clear();
- return result;
- }
-
- public ArrayBufferView getTypedArray() {
- return intArray;
+ static IntBuffer wrap (DirectReadWriteByteBuffer byteBuffer) {
+ return new DirectReadWriteIntBufferAdapter((DirectReadWriteByteBuffer)byteBuffer.slice());
+ }
+
+ private final DirectReadWriteByteBuffer byteBuffer;
+ private final Int32Array intArray;
+
+ DirectReadWriteIntBufferAdapter (DirectReadWriteByteBuffer byteBuffer) {
+ super((byteBuffer.capacity() >> 2));
+ this.byteBuffer = byteBuffer;
+ this.byteBuffer.clear();
+ this.intArray = Int32Array.create(byteBuffer.byteArray.getBuffer(), byteBuffer.byteArray.getByteOffset(), capacity);
+ }
+
+ // TODO(haustein) This will be slow
+ @Override
+ public IntBuffer asReadOnlyBuffer () {
+ DirectReadOnlyIntBufferAdapter buf = new DirectReadOnlyIntBufferAdapter(byteBuffer);
+ buf.limit = limit;
+ buf.position = position;
+ buf.mark = mark;
+ return buf;
+ }
+
+ @Override
+ public IntBuffer compact () {
+ byteBuffer.limit(limit << 2);
+ byteBuffer.position(position << 2);
+ byteBuffer.compact();
+ byteBuffer.clear();
+ position = limit - position;
+ limit = capacity;
+ mark = UNSET_MARK;
+ return this;
+ }
+
+ @Override
+ public IntBuffer duplicate () {
+ DirectReadWriteIntBufferAdapter buf = new DirectReadWriteIntBufferAdapter((DirectReadWriteByteBuffer)byteBuffer.duplicate());
+ buf.limit = limit;
+ buf.position = position;
+ buf.mark = mark;
+ return buf;
+ }
+
+ @Override
+ public int get () {
+// if (position == limit) {
+// throw new BufferUnderflowException();
+// }
+ return intArray.get(position++);
+ }
+
+ @Override
+ public int get (int index) {
+// if (index < 0 || index >= limit) {
+// throw new IndexOutOfBoundsException();
+// }
+ return intArray.get(index);
+ }
+
+ @Override
+ public boolean isDirect () {
+ return true;
}
+ @Override
+ public boolean isReadOnly () {
+ return false;
+ }
+
+ @Override
+ public ByteOrder order () {
+ return byteBuffer.order();
+ }
+
+ @Override
+ protected int[] protectedArray () {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ protected int protectedArrayOffset () {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ protected boolean protectedHasArray () {
+ return false;
+ }
+
+ @Override
+ public IntBuffer put (int c) {
+// if (position == limit) {
+// throw new BufferOverflowException();
+// }
+ intArray.set(position++, c);
+ return this;
+ }
+
+ @Override
+ public IntBuffer put (int index, int c) {
+// if (index < 0 || index >= limit) {
+// throw new IndexOutOfBoundsException();
+// }
+ intArray.set(index, c);
+ return this;
+ }
+
+ @Override
+ public IntBuffer slice () {
+ byteBuffer.limit(limit << 2);
+ byteBuffer.position(position << 2);
+ IntBuffer result = new DirectReadWriteIntBufferAdapter((DirectReadWriteByteBuffer)byteBuffer.slice());
+ byteBuffer.clear();
+ return result;
+ }
+
+ public ArrayBufferView getTypedArray () {
+ return intArray;
+ }
- public int getElementSize() {
+ public int getElementSize () {
return 4;
}
}
diff --git a/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/java/nio/DirectReadWriteShortBufferAdapter.java b/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/java/nio/DirectReadWriteShortBufferAdapter.java
index 153b00c039c..b04b7c12155 100644
--- a/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/java/nio/DirectReadWriteShortBufferAdapter.java
+++ b/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/java/nio/DirectReadWriteShortBufferAdapter.java
@@ -19,150 +19,143 @@
import gwt.g3d.client.gl2.array.ArrayBufferView;
import gwt.g3d.client.gl2.array.Int16Array;
-/**
- * This class wraps a byte buffer to be a short buffer.
+/** This class wraps a byte buffer to be a short buffer.
*
* Implementation notice:
*
- * After a byte buffer instance is wrapped, it becomes privately owned by
- * the adapter. It must NOT be accessed outside the adapter any more.
- * The byte buffer's position and limit are NOT linked with the adapter.
- * The adapter extends Buffer, thus has its own position and limit.
+ * After a byte buffer instance is wrapped, it becomes privately owned by the adapter. It must NOT be accessed outside the
+ * adapter any more.
+ * The byte buffer's position and limit are NOT linked with the adapter. The adapter extends Buffer, thus has its own position
+ * and limit.
*
- *
- *
- */
+ * */
final class DirectReadWriteShortBufferAdapter extends ShortBuffer implements HasArrayBufferView {
-//implements DirectBuffer {
-
- static ShortBuffer wrap(DirectReadWriteByteBuffer byteBuffer) {
- return new DirectReadWriteShortBufferAdapter((DirectReadWriteByteBuffer) byteBuffer.slice());
- }
-
- private final DirectReadWriteByteBuffer byteBuffer;
- private final Int16Array shortArray;
-
- DirectReadWriteShortBufferAdapter(DirectReadWriteByteBuffer byteBuffer) {
- super((byteBuffer.capacity() >> 1));
- this.byteBuffer = byteBuffer;
- this.byteBuffer.clear();
- this.shortArray = Int16Array.create(byteBuffer.byteArray.getBuffer(),
- byteBuffer.byteArray.getByteOffset(),
- capacity);
- }
-
- // TODO(haustein) This will be slow
- @Override
- public ShortBuffer asReadOnlyBuffer() {
- DirectReadOnlyShortBufferAdapter buf = new DirectReadOnlyShortBufferAdapter(byteBuffer);
- buf.limit = limit;
- buf.position = position;
- buf.mark = mark;
- return buf;
- }
-
- @Override
- public ShortBuffer compact() {
- byteBuffer.limit(limit << 1);
- byteBuffer.position(position << 1);
- byteBuffer.compact();
- byteBuffer.clear();
- position = limit - position;
- limit = capacity;
- mark = UNSET_MARK;
- return this;
- }
-
- @Override
- public ShortBuffer duplicate() {
- DirectReadWriteShortBufferAdapter buf = new DirectReadWriteShortBufferAdapter(
- (DirectReadWriteByteBuffer) byteBuffer.duplicate());
- buf.limit = limit;
- buf.position = position;
- buf.mark = mark;
- return buf;
- }
-
- @Override
- public short get() {
-// if (position == limit) {
-// throw new BufferUnderflowException();
-// }
- return (short)shortArray.get(position++);
- }
-
- @Override
- public short get(int index) {
-// if (index < 0 || index >= limit) {
-// throw new IndexOutOfBoundsException();
-// }
- return (short)shortArray.get(index);
- }
-
- @Override
- public boolean isDirect() {
- return true;
- }
-
- @Override
- public boolean isReadOnly() {
- return false;
- }
-
- @Override
- public ByteOrder order() {
- return byteBuffer.order();
- }
-
- @Override
- protected short[] protectedArray() {
- throw new UnsupportedOperationException();
- }
-
- @Override
- protected int protectedArrayOffset() {
- throw new UnsupportedOperationException();
- }
-
- @Override
- protected boolean protectedHasArray() {
- return false;
- }
-
- @Override
- public ShortBuffer put(short c) {
-// if (position == limit) {
-// throw new BufferOverflowException();
-// }
- shortArray.set(position++, c);
- return this;
- }
-
- @Override
- public ShortBuffer put(int index, short c) {
-// if (index < 0 || index >= limit) {
-// throw new IndexOutOfBoundsException();
-// }
- shortArray.set(index, c);
- return this;
- }
-
- @Override
- public ShortBuffer slice() {
- byteBuffer.limit(limit << 1);
- byteBuffer.position(position << 1);
- ShortBuffer result = new DirectReadWriteShortBufferAdapter((DirectReadWriteByteBuffer)
- byteBuffer.slice());
- byteBuffer.clear();
- return result;
- }
-
- public ArrayBufferView getTypedArray() {
+// implements DirectBuffer {
+
+ static ShortBuffer wrap (DirectReadWriteByteBuffer byteBuffer) {
+ return new DirectReadWriteShortBufferAdapter((DirectReadWriteByteBuffer)byteBuffer.slice());
+ }
+
+ private final DirectReadWriteByteBuffer byteBuffer;
+ private final Int16Array shortArray;
+
+ DirectReadWriteShortBufferAdapter (DirectReadWriteByteBuffer byteBuffer) {
+ super((byteBuffer.capacity() >> 1));
+ this.byteBuffer = byteBuffer;
+ this.byteBuffer.clear();
+ this.shortArray = Int16Array.create(byteBuffer.byteArray.getBuffer(), byteBuffer.byteArray.getByteOffset(), capacity);
+ }
+
+ // TODO(haustein) This will be slow
+ @Override
+ public ShortBuffer asReadOnlyBuffer () {
+ DirectReadOnlyShortBufferAdapter buf = new DirectReadOnlyShortBufferAdapter(byteBuffer);
+ buf.limit = limit;
+ buf.position = position;
+ buf.mark = mark;
+ return buf;
+ }
+
+ @Override
+ public ShortBuffer compact () {
+ byteBuffer.limit(limit << 1);
+ byteBuffer.position(position << 1);
+ byteBuffer.compact();
+ byteBuffer.clear();
+ position = limit - position;
+ limit = capacity;
+ mark = UNSET_MARK;
+ return this;
+ }
+
+ @Override
+ public ShortBuffer duplicate () {
+ DirectReadWriteShortBufferAdapter buf = new DirectReadWriteShortBufferAdapter(
+ (DirectReadWriteByteBuffer)byteBuffer.duplicate());
+ buf.limit = limit;
+ buf.position = position;
+ buf.mark = mark;
+ return buf;
+ }
+
+ @Override
+ public short get () {
+// if (position == limit) {
+// throw new BufferUnderflowException();
+// }
+ return (short)shortArray.get(position++);
+ }
+
+ @Override
+ public short get (int index) {
+// if (index < 0 || index >= limit) {
+// throw new IndexOutOfBoundsException();
+// }
+ return (short)shortArray.get(index);
+ }
+
+ @Override
+ public boolean isDirect () {
+ return true;
+ }
+
+ @Override
+ public boolean isReadOnly () {
+ return false;
+ }
+
+ @Override
+ public ByteOrder order () {
+ return byteBuffer.order();
+ }
+
+ @Override
+ protected short[] protectedArray () {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ protected int protectedArrayOffset () {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ protected boolean protectedHasArray () {
+ return false;
+ }
+
+ @Override
+ public ShortBuffer put (short c) {
+// if (position == limit) {
+// throw new BufferOverflowException();
+// }
+ shortArray.set(position++, c);
+ return this;
+ }
+
+ @Override
+ public ShortBuffer put (int index, short c) {
+// if (index < 0 || index >= limit) {
+// throw new IndexOutOfBoundsException();
+// }
+ shortArray.set(index, c);
+ return this;
+ }
+
+ @Override
+ public ShortBuffer slice () {
+ byteBuffer.limit(limit << 1);
+ byteBuffer.position(position << 1);
+ ShortBuffer result = new DirectReadWriteShortBufferAdapter((DirectReadWriteByteBuffer)byteBuffer.slice());
+ byteBuffer.clear();
+ return result;
+ }
+
+ public ArrayBufferView getTypedArray () {
return shortArray;
}
-
- public int getElementSize() {
+ public int getElementSize () {
return 2;
}
diff --git a/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/java/nio/DoubleArrayBuffer.java b/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/java/nio/DoubleArrayBuffer.java
index ad488eac13c..f7270be8d95 100644
--- a/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/java/nio/DoubleArrayBuffer.java
+++ b/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/java/nio/DoubleArrayBuffer.java
@@ -15,74 +15,69 @@
* limitations under the License.
*/
-package java.nio;
+package java.nio;
-/**
- * DoubleArrayBuffer, ReadWriteDoubleArrayBuffer and ReadOnlyDoubleArrayBuffer
- * compose the implementation of array based double buffers.
+/** DoubleArrayBuffer, ReadWriteDoubleArrayBuffer and ReadOnlyDoubleArrayBuffer compose the implementation of array based double
+ * buffers.
*
- * DoubleArrayBuffer implements all the shared readonly methods and is extended
- * by the other two classes.
+ * DoubleArrayBuffer implements all the shared readonly methods and is extended by the other two classes.
*
*
* All methods are marked final for runtime performance.
- *
- *
- */
+ * */
abstract class DoubleArrayBuffer extends DoubleBuffer {
- protected final double[] backingArray;
+ protected final double[] backingArray;
+
+ protected final int offset;
- protected final int offset;
+ DoubleArrayBuffer (double[] array) {
+ this(array.length, array, 0);
+ }
- DoubleArrayBuffer(double[] array) {
- this(array.length, array, 0);
- }
+ DoubleArrayBuffer (int capacity) {
+ this(capacity, new double[capacity], 0);
+ }
- DoubleArrayBuffer(int capacity) {
- this(capacity, new double[capacity], 0);
- }
+ DoubleArrayBuffer (int capacity, double[] backingArray, int offset) {
+ super(capacity);
+ this.backingArray = backingArray;
+ this.offset = offset;
+ }
- DoubleArrayBuffer(int capacity, double[] backingArray, int offset) {
- super(capacity);
- this.backingArray = backingArray;
- this.offset = offset;
- }
+ public final double get () {
+ if (position == limit) {
+ throw new BufferUnderflowException();
+ }
+ return backingArray[offset + position++];
+ }
- public final double get() {
- if (position == limit) {
- throw new BufferUnderflowException();
- }
- return backingArray[offset + position++];
- }
+ public final double get (int index) {
+ if (index < 0 || index >= limit) {
+ throw new IndexOutOfBoundsException();
+ }
+ return backingArray[offset + index];
+ }
- public final double get(int index) {
- if (index < 0 || index >= limit) {
- throw new IndexOutOfBoundsException();
- }
- return backingArray[offset + index];
- }
+ public final DoubleBuffer get (double[] dest, int off, int len) {
+ int length = dest.length;
+ if (off < 0 || len < 0 || (long)off + (long)len > length) {
+ throw new IndexOutOfBoundsException();
+ }
+ if (len > remaining()) {
+ throw new BufferUnderflowException();
+ }
+ System.arraycopy(backingArray, offset + position, dest, off, len);
+ position += len;
+ return this;
+ }
- public final DoubleBuffer get(double[] dest, int off, int len) {
- int length = dest.length;
- if (off < 0 || len < 0 || (long)off + (long)len > length) {
- throw new IndexOutOfBoundsException();
- }
- if (len > remaining()) {
- throw new BufferUnderflowException();
- }
- System.arraycopy(backingArray, offset + position, dest,
- off, len);
- position += len;
- return this;
- }
-
- public final boolean isDirect() {
- return false;
- }
+ public final boolean isDirect () {
+ return false;
+ }
- public final ByteOrder order() {
- return ByteOrder.nativeOrder();
- }
+ public final ByteOrder order () {
+ return ByteOrder.nativeOrder();
+ }
}
diff --git a/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/java/nio/DoubleBuffer.java b/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/java/nio/DoubleBuffer.java
index ac19f0ba08a..861b4ee3dc3 100644
--- a/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/java/nio/DoubleBuffer.java
+++ b/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/java/nio/DoubleBuffer.java
@@ -17,566 +17,420 @@
package java.nio;
-/**
- * A buffer of doubles.
+/** A buffer of doubles.
*
* A double buffer can be created in either one of the following ways:
*
*
- * {@link #allocate(int) Allocate} a new double array and create a buffer
- * based on it;
- * {@link #wrap(double[]) Wrap} an existing double array to create a new
- * buffer;
- * Use
- * {@link java.nio.ByteBuffer#asDoubleBuffer() ByteBuffer.asDoubleBuffer} to
- * create a double buffer based on a byte buffer.
+ * {@link #allocate(int) Allocate} a new double array and create a buffer based on it;
+ * {@link #wrap(double[]) Wrap} an existing double array to create a new buffer;
+ * Use {@link java.nio.ByteBuffer#asDoubleBuffer() ByteBuffer.asDoubleBuffer} to create a double buffer based on a byte
+ * buffer.
*
*
- * @since Android 1.0
- */
+ * @since Android 1.0 */
public abstract class DoubleBuffer extends Buffer implements Comparable {
- /**
- * Creates a double buffer based on a newly allocated double array.
- *
- * @param capacity
- * the capacity of the new buffer.
- * @return the created double buffer.
- * @throws IllegalArgumentException
- * if {@code capacity} is less than zero.
- * @since Android 1.0
- */
- public static DoubleBuffer allocate(int capacity) {
- if (capacity < 0) {
- throw new IllegalArgumentException();
- }
- return BufferFactory.newDoubleBuffer(capacity);
- }
-
- /**
- * Creates a new double buffer by wrapping the given double array.
- *
- * Calling this method has the same effect as
- * {@code wrap(array, 0, array.length)}.
- *
- *
- * @param array
- * the double array which the new buffer will be based on.
- * @return the created double buffer.
- * @since Android 1.0
- */
- public static DoubleBuffer wrap(double[] array) {
- return wrap(array, 0, array.length);
- }
-
- /**
- * Creates a new double buffer by wrapping the given double array.
- *
- * The new buffer's position will be {@code start}, limit will be
- * {@code start + len}, capacity will be the length of the array.
- *
- *
- * @param array
- * the double array which the new buffer will be based on.
- * @param start
- * the start index, must not be negative and not greater than
- * {@code array.length}.
- * @param len
- * the length, must not be negative and not greater than
- * {@code array.length - start}.
- * @return the created double buffer.
- * @exception IndexOutOfBoundsException
- * if either {@code start} or {@code len} is invalid.
- * @since Android 1.0
- */
- public static DoubleBuffer wrap(double[] array, int start, int len) {
- int length = array.length;
- if (start < 0 || len < 0 || (long)start + (long)len > length) {
- throw new IndexOutOfBoundsException();
- }
-
- DoubleBuffer buf = BufferFactory.newDoubleBuffer(array);
- buf.position = start;
- buf.limit = start + len;
-
- return buf;
- }
-
- /**
- * Constructs a {@code DoubleBuffer} with given capacity.
- *
- * @param capacity
- * the capacity of the buffer.
- */
- DoubleBuffer(int capacity) {
- super(capacity);
- }
-
- /**
- * Returns the double array which this buffer is based on, if there is one.
- *
- * @return the double array which this buffer is based on.
- * @exception ReadOnlyBufferException
- * if this buffer is based on an array but it is read-only.
- * @exception UnsupportedOperationException
- * if this buffer is not based on an array.
- * @since Android 1.0
- */
- public final double[] array() {
- return protectedArray();
- }
-
- /**
- * Returns the offset of the double array which this buffer is based on, if
- * there is one.
- *
- * The offset is the index of the array corresponding to the zero position
- * of the buffer.
- *
- *
- * @return the offset of the double array which this buffer is based on.
- * @exception ReadOnlyBufferException
- * if this buffer is based on an array, but it is read-only.
- * @exception UnsupportedOperationException
- * if this buffer is not based on an array.
- * @since Android 1.0
- */
- public final int arrayOffset() {
- return protectedArrayOffset();
- }
-
- /**
- * Returns a read-only buffer that shares its content with this buffer.
- *
- * The returned buffer is guaranteed to be a new instance, even if this
- * buffer is read-only itself. The new buffer's position, limit, capacity
- * and mark are the same as this buffer's.
- *
- *
- * The new buffer shares its content with this buffer, which means that this
- * buffer's change of content will be visible to the new buffer. The two
- * buffer's position, limit and mark are independent.
- *
- *
- * @return a read-only version of this buffer.
- * @since Android 1.0
- */
- public abstract DoubleBuffer asReadOnlyBuffer();
-
- /**
- * Compacts this double buffer.
- *
- * The remaining doubles will be moved to the head of the buffer, staring
- * from position zero. Then the position is set to {@code remaining()}; the
- * limit is set to capacity; the mark is cleared.
- *
- *
- * @return this buffer.
- * @exception ReadOnlyBufferException
- * if no changes may be made to the contents of this buffer.
- * @since Android 1.0
- */
- public abstract DoubleBuffer compact();
-
- /**
- * Compare the remaining doubles of this buffer to another double buffer's
- * remaining doubles.
- *
- * @param otherBuffer
- * another double buffer.
- * @return a negative value if this is less than {@code other}; 0 if this
- * equals to {@code other}; a positive value if this is greater
- * than {@code other}.
- * @exception ClassCastException
- * if {@code other} is not a double buffer.
- * @since Android 1.0
- */
- public int compareTo(DoubleBuffer otherBuffer) {
- int compareRemaining = (remaining() < otherBuffer.remaining()) ? remaining()
- : otherBuffer.remaining();
- int thisPos = position;
- int otherPos = otherBuffer.position;
- // BEGIN android-changed
- double thisDouble, otherDouble;
- while (compareRemaining > 0) {
- thisDouble = get(thisPos);
- otherDouble = otherBuffer.get(otherPos);
- // checks for double and NaN inequality
- if ((thisDouble != otherDouble)
- && ((thisDouble == thisDouble) || (otherDouble == otherDouble))) {
- return thisDouble < otherDouble ? -1 : 1;
- }
- thisPos++;
- otherPos++;
- compareRemaining--;
- }
- // END android-changed
- return remaining() - otherBuffer.remaining();
- }
-
- /**
- * Returns a duplicated buffer that shares its content with this buffer.
- *
- * The duplicated buffer's position, limit, capacity and mark are the same
- * as this buffer's. The duplicated buffer's read-only property and byte
- * order are the same as this buffer's, too.
- *
- *
- * The new buffer shares its content with this buffer, which means either
- * buffer's change of content will be visible to the other. The two buffer's
- * position, limit and mark are independent.
- *
- *
- * @return a duplicated buffer that shares its content with this buffer.
- * @since Android 1.0
- */
- public abstract DoubleBuffer duplicate();
-
- /**
- * Checks whether this double buffer is equal to another object.
- *
- * If {@code other} is not a double buffer then {@code false} is returned.
- * Two double buffers are equal if and only if their remaining doubles are
- * exactly the same. Position, limit, capacity and mark are not considered.
- *
- *
- * @param other
- * the object to compare with this double buffer.
- * @return {@code true} if this double buffer is equal to {@code other},
- * {@code false} otherwise.
- * @since Android 1.0
- */
- public boolean equals(Object other) {
- if (!(other instanceof DoubleBuffer)) {
- return false;
- }
- DoubleBuffer otherBuffer = (DoubleBuffer) other;
-
- if (remaining() != otherBuffer.remaining()) {
- return false;
- }
-
- int myPosition = position;
- int otherPosition = otherBuffer.position;
- boolean equalSoFar = true;
- while (equalSoFar && (myPosition < limit)) {
- equalSoFar = get(myPosition++) == otherBuffer.get(otherPosition++);
- }
-
- return equalSoFar;
- }
-
- /**
- * Returns the double at the current position and increases the position by
- * 1.
- *
- * @return the double at the current position.
- * @exception BufferUnderflowException
- * if the position is equal or greater than limit.
- * @since Android 1.0
- */
- public abstract double get();
-
- /**
- * Reads doubles from the current position into the specified double array
- * and increases the position by the number of doubles read.
- *
- * Calling this method has the same effect as
- * {@code get(dest, 0, dest.length)}.
- *
- *
- * @param dest
- * the destination double array.
- * @return this buffer.
- * @exception BufferUnderflowException
- * if {@code dest.length} is greater than {@code remaining()}.
- * @since Android 1.0
- */
- public DoubleBuffer get(double[] dest) {
- return get(dest, 0, dest.length);
- }
-
- /**
- * Reads doubles from the current position into the specified double array,
- * starting from the specified offset, and increases the position by the
- * number of doubles read.
- *
- * @param dest
- * the target double array.
- * @param off
- * the offset of the double array, must not be negative and not
- * greater than {@code dest.length}.
- * @param len
- * the number of doubles to read, must be no less than zero and
- * not greater than {@code dest.length - off}.
- * @return this buffer.
- * @exception IndexOutOfBoundsException
- * if either {@code off} or {@code len} is invalid.
- * @exception BufferUnderflowException
- * if {@code len} is greater than {@code remaining()}.
- * @since Android 1.0
- */
- public DoubleBuffer get(double[] dest, int off, int len) {
- int length = dest.length;
- if (off < 0 || len < 0 || (long)off + (long)len > length) {
- throw new IndexOutOfBoundsException();
- }
-
- if (len > remaining()) {
- throw new BufferUnderflowException();
- }
- for (int i = off; i < off + len; i++) {
- dest[i] = get();
- }
- return this;
- }
-
- /**
- * Returns a double at the specified index; the position is not changed.
- *
- * @param index
- * the index, must not be negative and less than limit.
- * @return a double at the specified index.
- * @exception IndexOutOfBoundsException
- * if index is invalid.
- * @since Android 1.0
- */
- public abstract double get(int index);
-
- /**
- * Indicates whether this buffer is based on a double array and is
- * read/write.
- *
- * @return {@code true} if this buffer is based on a double array and
- * provides read/write access, {@code false} otherwise.
- * @since Android 1.0
- */
- public final boolean hasArray() {
- return protectedHasArray();
- }
-
-// /**
-// * Calculates this buffer's hash code from the remaining chars. The
-// * position, limit, capacity and mark don't affect the hash code.
-// *
-// * @return the hash code calculated from the remaining chars.
-// * @since Android 1.0
-// */
-// public int hashCode() {
-// int myPosition = position;
-// int hash = 0;
-// long l;
-// while (myPosition < limit) {
-// l = Double.doubleToLongBits(get(myPosition++));
-// hash = hash + ((int) l) ^ ((int) (l >> 32));
-// }
-// return hash;
-// }
-
- /**
- * Indicates whether this buffer is direct. A direct buffer will try its
- * best to take advantage of native memory APIs and it may not stay in the
- * Java heap, so it is not affected by garbage collection.
- *
- * A double buffer is direct if it is based on a byte buffer and the byte
- * buffer is direct.
- *
- *
- * @return {@code true} if this buffer is direct, {@code false} otherwise.
- * @since Android 1.0
- */
- public abstract boolean isDirect();
-
- /**
- * Returns the byte order used by this buffer when converting doubles
- * from/to bytes.
- *
- * If this buffer is not based on a byte buffer, then this always returns
- * the platform's native byte order.
- *
- *
- * @return the byte order used by this buffer when converting doubles
- * from/to bytes.
- * @since Android 1.0
- */
- public abstract ByteOrder order();
-
- /**
- * Child class implements this method to realize {@code array()}.
- *
- * @see #array()
- */
- abstract double[] protectedArray();
-
- /**
- * Child class implements this method to realize {@code arrayOffset()}.
- *
- * @see #arrayOffset()
- */
- abstract int protectedArrayOffset();
-
- /**
- * Child class implements this method to realize {@code hasArray()}.
- *
- * @see #hasArray()
- */
- abstract boolean protectedHasArray();
-
- /**
- * Writes the given double to the current position and increases the
- * position by 1.
- *
- * @param d
- * the double to write.
- * @return this buffer.
- * @exception BufferOverflowException
- * if position is equal or greater than limit.
- * @exception ReadOnlyBufferException
- * if no changes may be made to the contents of this buffer.
- * @since Android 1.0
- */
- public abstract DoubleBuffer put(double d);
-
- /**
- * Writes doubles from the given double array to the current position and
- * increases the position by the number of doubles written.
- *
- * Calling this method has the same effect as
- * {@code put(src, 0, src.length)}.
- *
- *
- * @param src
- * the source double array.
- * @return this buffer.
- * @exception BufferOverflowException
- * if {@code remaining()} is less than {@code src.length}.
- * @exception ReadOnlyBufferException
- * if no changes may be made to the contents of this buffer.
- * @since Android 1.0
- */
- public final DoubleBuffer put(double[] src) {
- return put(src, 0, src.length);
- }
-
- /**
- * Writes doubles from the given double array, starting from the specified
- * offset, to the current position and increases the position by the number
- * of doubles written.
- *
- * @param src
- * the source double array.
- * @param off
- * the offset of double array, must not be negative and not
- * greater than {@code src.length}.
- * @param len
- * the number of doubles to write, must be no less than zero and
- * not greater than {@code src.length - off}.
- * @return this buffer.
- * @exception BufferOverflowException
- * if {@code remaining()} is less than {@code len}.
- * @exception IndexOutOfBoundsException
- * if either {@code off} or {@code len} is invalid.
- * @exception ReadOnlyBufferException
- * if no changes may be made to the contents of this buffer.
- * @since Android 1.0
- */
- public DoubleBuffer put(double[] src, int off, int len) {
- int length = src.length;
- if (off < 0 || len < 0 || (long)off + (long)len > length) {
- throw new IndexOutOfBoundsException();
- }
-
- if (len > remaining()) {
- throw new BufferOverflowException();
- }
- for (int i = off; i < off + len; i++) {
- put(src[i]);
- }
- return this;
- }
-
- /**
- * Writes all the remaining doubles of the {@code src} double buffer to this
- * buffer's current position, and increases both buffers' position by the
- * number of doubles copied.
- *
- * @param src
- * the source double buffer.
- * @return this buffer.
- * @exception BufferOverflowException
- * if {@code src.remaining()} is greater than this buffer's
- * {@code remaining()}.
- * @exception IllegalArgumentException
- * if {@code src} is this buffer.
- * @exception ReadOnlyBufferException
- * if no changes may be made to the contents of this buffer.
- * @since Android 1.0
- */
- public DoubleBuffer put(DoubleBuffer src) {
- if (src == this) {
- throw new IllegalArgumentException();
- }
- if (src.remaining() > remaining()) {
- throw new BufferOverflowException();
- }
- double[] doubles = new double[src.remaining()];
- src.get(doubles);
- put(doubles);
- return this;
- }
-
- /**
- * Write a double to the specified index of this buffer and the position is
- * not changed.
- *
- * @param index
- * the index, must not be negative and less than the limit.
- * @param d
- * the double to write.
- * @return this buffer.
- * @exception IndexOutOfBoundsException
- * if index is invalid.
- * @exception ReadOnlyBufferException
- * if no changes may be made to the contents of this buffer.
- * @since Android 1.0
- */
- public abstract DoubleBuffer put(int index, double d);
-
- /**
- * Returns a sliced buffer that shares its content with this buffer.
- *
- * The sliced buffer's capacity will be this buffer's {@code remaining()},
- * and its zero position will correspond to this buffer's current position.
- * The new buffer's position will be 0, limit will be its capacity, and its
- * mark is cleared. The new buffer's read-only property and byte order are
- * the same as this buffer's.
- *
- *
- * The new buffer shares its content with this buffer, which means either
- * buffer's change of content will be visible to the other. The two buffer's
- * position, limit and mark are independent.
- *
- *
- * @return a sliced buffer that shares its content with this buffer.
- * @since Android 1.0
- */
- public abstract DoubleBuffer slice();
-
- /**
- * Returns a string representing the state of this double buffer.
- *
- * @return A string representing the state of this double buffer.
- * @since Android 1.0
- */
- public String toString() {
- StringBuffer buf = new StringBuffer();
- buf.append(getClass().getName());
- buf.append(", status: capacity="); //$NON-NLS-1$
- buf.append(capacity());
- buf.append(" position="); //$NON-NLS-1$
- buf.append(position());
- buf.append(" limit="); //$NON-NLS-1$
- buf.append(limit());
- return buf.toString();
- }
+ /** Creates a double buffer based on a newly allocated double array.
+ *
+ * @param capacity the capacity of the new buffer.
+ * @return the created double buffer.
+ * @throws IllegalArgumentException if {@code capacity} is less than zero.
+ * @since Android 1.0 */
+ public static DoubleBuffer allocate (int capacity) {
+ if (capacity < 0) {
+ throw new IllegalArgumentException();
+ }
+ return BufferFactory.newDoubleBuffer(capacity);
+ }
+
+ /** Creates a new double buffer by wrapping the given double array.
+ *
+ * Calling this method has the same effect as {@code wrap(array, 0, array.length)}.
+ *
+ *
+ * @param array the double array which the new buffer will be based on.
+ * @return the created double buffer.
+ * @since Android 1.0 */
+ public static DoubleBuffer wrap (double[] array) {
+ return wrap(array, 0, array.length);
+ }
+
+ /** Creates a new double buffer by wrapping the given double array.
+ *
+ * The new buffer's position will be {@code start}, limit will be {@code start + len}, capacity will be the length of the
+ * array.
+ *
+ *
+ * @param array the double array which the new buffer will be based on.
+ * @param start the start index, must not be negative and not greater than {@code array.length}.
+ * @param len the length, must not be negative and not greater than {@code array.length - start}.
+ * @return the created double buffer.
+ * @exception IndexOutOfBoundsException if either {@code start} or {@code len} is invalid.
+ * @since Android 1.0 */
+ public static DoubleBuffer wrap (double[] array, int start, int len) {
+ int length = array.length;
+ if (start < 0 || len < 0 || (long)start + (long)len > length) {
+ throw new IndexOutOfBoundsException();
+ }
+
+ DoubleBuffer buf = BufferFactory.newDoubleBuffer(array);
+ buf.position = start;
+ buf.limit = start + len;
+
+ return buf;
+ }
+
+ /** Constructs a {@code DoubleBuffer} with given capacity.
+ *
+ * @param capacity the capacity of the buffer. */
+ DoubleBuffer (int capacity) {
+ super(capacity);
+ }
+
+ /** Returns the double array which this buffer is based on, if there is one.
+ *
+ * @return the double array which this buffer is based on.
+ * @exception ReadOnlyBufferException if this buffer is based on an array but it is read-only.
+ * @exception UnsupportedOperationException if this buffer is not based on an array.
+ * @since Android 1.0 */
+ public final double[] array () {
+ return protectedArray();
+ }
+
+ /** Returns the offset of the double array which this buffer is based on, if there is one.
+ *
+ * The offset is the index of the array corresponding to the zero position of the buffer.
+ *
+ *
+ * @return the offset of the double array which this buffer is based on.
+ * @exception ReadOnlyBufferException if this buffer is based on an array, but it is read-only.
+ * @exception UnsupportedOperationException if this buffer is not based on an array.
+ * @since Android 1.0 */
+ public final int arrayOffset () {
+ return protectedArrayOffset();
+ }
+
+ /** Returns a read-only buffer that shares its content with this buffer.
+ *
+ * The returned buffer is guaranteed to be a new instance, even if this buffer is read-only itself. The new buffer's position,
+ * limit, capacity and mark are the same as this buffer's.
+ *
+ *
+ * The new buffer shares its content with this buffer, which means that this buffer's change of content will be visible to the
+ * new buffer. The two buffer's position, limit and mark are independent.
+ *
+ *
+ * @return a read-only version of this buffer.
+ * @since Android 1.0 */
+ public abstract DoubleBuffer asReadOnlyBuffer ();
+
+ /** Compacts this double buffer.
+ *
+ * The remaining doubles will be moved to the head of the buffer, staring from position zero. Then the position is set to
+ * {@code remaining()}; the limit is set to capacity; the mark is cleared.
+ *
+ *
+ * @return this buffer.
+ * @exception ReadOnlyBufferException if no changes may be made to the contents of this buffer.
+ * @since Android 1.0 */
+ public abstract DoubleBuffer compact ();
+
+ /** Compare the remaining doubles of this buffer to another double buffer's remaining doubles.
+ *
+ * @param otherBuffer another double buffer.
+ * @return a negative value if this is less than {@code other}; 0 if this equals to {@code other}; a positive value if this is
+ * greater than {@code other}.
+ * @exception ClassCastException if {@code other} is not a double buffer.
+ * @since Android 1.0 */
+ public int compareTo (DoubleBuffer otherBuffer) {
+ int compareRemaining = (remaining() < otherBuffer.remaining()) ? remaining() : otherBuffer.remaining();
+ int thisPos = position;
+ int otherPos = otherBuffer.position;
+ // BEGIN android-changed
+ double thisDouble, otherDouble;
+ while (compareRemaining > 0) {
+ thisDouble = get(thisPos);
+ otherDouble = otherBuffer.get(otherPos);
+ // checks for double and NaN inequality
+ if ((thisDouble != otherDouble) && ((thisDouble == thisDouble) || (otherDouble == otherDouble))) {
+ return thisDouble < otherDouble ? -1 : 1;
+ }
+ thisPos++;
+ otherPos++;
+ compareRemaining--;
+ }
+ // END android-changed
+ return remaining() - otherBuffer.remaining();
+ }
+
+ /** Returns a duplicated buffer that shares its content with this buffer.
+ *
+ * The duplicated buffer's position, limit, capacity and mark are the same as this buffer's. The duplicated buffer's read-only
+ * property and byte order are the same as this buffer's, too.
+ *
+ *
+ * The new buffer shares its content with this buffer, which means either buffer's change of content will be visible to the
+ * other. The two buffer's position, limit and mark are independent.
+ *
+ *
+ * @return a duplicated buffer that shares its content with this buffer.
+ * @since Android 1.0 */
+ public abstract DoubleBuffer duplicate ();
+
+ /** Checks whether this double buffer is equal to another object.
+ *
+ * If {@code other} is not a double buffer then {@code false} is returned. Two double buffers are equal if and only if their
+ * remaining doubles are exactly the same. Position, limit, capacity and mark are not considered.
+ *
+ *
+ * @param other the object to compare with this double buffer.
+ * @return {@code true} if this double buffer is equal to {@code other}, {@code false} otherwise.
+ * @since Android 1.0 */
+ public boolean equals (Object other) {
+ if (!(other instanceof DoubleBuffer)) {
+ return false;
+ }
+ DoubleBuffer otherBuffer = (DoubleBuffer)other;
+
+ if (remaining() != otherBuffer.remaining()) {
+ return false;
+ }
+
+ int myPosition = position;
+ int otherPosition = otherBuffer.position;
+ boolean equalSoFar = true;
+ while (equalSoFar && (myPosition < limit)) {
+ equalSoFar = get(myPosition++) == otherBuffer.get(otherPosition++);
+ }
+
+ return equalSoFar;
+ }
+
+ /** Returns the double at the current position and increases the position by 1.
+ *
+ * @return the double at the current position.
+ * @exception BufferUnderflowException if the position is equal or greater than limit.
+ * @since Android 1.0 */
+ public abstract double get ();
+
+ /** Reads doubles from the current position into the specified double array and increases the position by the number of doubles
+ * read.
+ *
+ * Calling this method has the same effect as {@code get(dest, 0, dest.length)}.
+ *
+ *
+ * @param dest the destination double array.
+ * @return this buffer.
+ * @exception BufferUnderflowException if {@code dest.length} is greater than {@code remaining()}.
+ * @since Android 1.0 */
+ public DoubleBuffer get (double[] dest) {
+ return get(dest, 0, dest.length);
+ }
+
+ /** Reads doubles from the current position into the specified double array, starting from the specified offset, and increases
+ * the position by the number of doubles read.
+ *
+ * @param dest the target double array.
+ * @param off the offset of the double array, must not be negative and not greater than {@code dest.length}.
+ * @param len the number of doubles to read, must be no less than zero and not greater than {@code dest.length - off}.
+ * @return this buffer.
+ * @exception IndexOutOfBoundsException if either {@code off} or {@code len} is invalid.
+ * @exception BufferUnderflowException if {@code len} is greater than {@code remaining()}.
+ * @since Android 1.0 */
+ public DoubleBuffer get (double[] dest, int off, int len) {
+ int length = dest.length;
+ if (off < 0 || len < 0 || (long)off + (long)len > length) {
+ throw new IndexOutOfBoundsException();
+ }
+
+ if (len > remaining()) {
+ throw new BufferUnderflowException();
+ }
+ for (int i = off; i < off + len; i++) {
+ dest[i] = get();
+ }
+ return this;
+ }
+
+ /** Returns a double at the specified index; the position is not changed.
+ *
+ * @param index the index, must not be negative and less than limit.
+ * @return a double at the specified index.
+ * @exception IndexOutOfBoundsException if index is invalid.
+ * @since Android 1.0 */
+ public abstract double get (int index);
+
+ /** Indicates whether this buffer is based on a double array and is read/write.
+ *
+ * @return {@code true} if this buffer is based on a double array and provides read/write access, {@code false} otherwise.
+ * @since Android 1.0 */
+ public final boolean hasArray () {
+ return protectedHasArray();
+ }
+
+// /**
+// * Calculates this buffer's hash code from the remaining chars. The
+// * position, limit, capacity and mark don't affect the hash code.
+// *
+// * @return the hash code calculated from the remaining chars.
+// * @since Android 1.0
+// */
+// public int hashCode() {
+// int myPosition = position;
+// int hash = 0;
+// long l;
+// while (myPosition < limit) {
+// l = Double.doubleToLongBits(get(myPosition++));
+// hash = hash + ((int) l) ^ ((int) (l >> 32));
+// }
+// return hash;
+// }
+
+ /** Indicates whether this buffer is direct. A direct buffer will try its best to take advantage of native memory APIs and it
+ * may not stay in the Java heap, so it is not affected by garbage collection.
+ *
+ * A double buffer is direct if it is based on a byte buffer and the byte buffer is direct.
+ *
+ *
+ * @return {@code true} if this buffer is direct, {@code false} otherwise.
+ * @since Android 1.0 */
+ public abstract boolean isDirect ();
+
+ /** Returns the byte order used by this buffer when converting doubles from/to bytes.
+ *
+ * If this buffer is not based on a byte buffer, then this always returns the platform's native byte order.
+ *
+ *
+ * @return the byte order used by this buffer when converting doubles from/to bytes.
+ * @since Android 1.0 */
+ public abstract ByteOrder order ();
+
+ /** Child class implements this method to realize {@code array()}.
+ *
+ * @see #array() */
+ abstract double[] protectedArray ();
+
+ /** Child class implements this method to realize {@code arrayOffset()}.
+ *
+ * @see #arrayOffset() */
+ abstract int protectedArrayOffset ();
+
+ /** Child class implements this method to realize {@code hasArray()}.
+ *
+ * @see #hasArray() */
+ abstract boolean protectedHasArray ();
+
+ /** Writes the given double to the current position and increases the position by 1.
+ *
+ * @param d the double to write.
+ * @return this buffer.
+ * @exception BufferOverflowException if position is equal or greater than limit.
+ * @exception ReadOnlyBufferException if no changes may be made to the contents of this buffer.
+ * @since Android 1.0 */
+ public abstract DoubleBuffer put (double d);
+
+ /** Writes doubles from the given double array to the current position and increases the position by the number of doubles
+ * written.
+ *
+ * Calling this method has the same effect as {@code put(src, 0, src.length)}.
+ *
+ *
+ * @param src the source double array.
+ * @return this buffer.
+ * @exception BufferOverflowException if {@code remaining()} is less than {@code src.length}.
+ * @exception ReadOnlyBufferException if no changes may be made to the contents of this buffer.
+ * @since Android 1.0 */
+ public final DoubleBuffer put (double[] src) {
+ return put(src, 0, src.length);
+ }
+
+ /** Writes doubles from the given double array, starting from the specified offset, to the current position and increases the
+ * position by the number of doubles written.
+ *
+ * @param src the source double array.
+ * @param off the offset of double array, must not be negative and not greater than {@code src.length}.
+ * @param len the number of doubles to write, must be no less than zero and not greater than {@code src.length - off}.
+ * @return this buffer.
+ * @exception BufferOverflowException if {@code remaining()} is less than {@code len}.
+ * @exception IndexOutOfBoundsException if either {@code off} or {@code len} is invalid.
+ * @exception ReadOnlyBufferException if no changes may be made to the contents of this buffer.
+ * @since Android 1.0 */
+ public DoubleBuffer put (double[] src, int off, int len) {
+ int length = src.length;
+ if (off < 0 || len < 0 || (long)off + (long)len > length) {
+ throw new IndexOutOfBoundsException();
+ }
+
+ if (len > remaining()) {
+ throw new BufferOverflowException();
+ }
+ for (int i = off; i < off + len; i++) {
+ put(src[i]);
+ }
+ return this;
+ }
+
+ /** Writes all the remaining doubles of the {@code src} double buffer to this buffer's current position, and increases both
+ * buffers' position by the number of doubles copied.
+ *
+ * @param src the source double buffer.
+ * @return this buffer.
+ * @exception BufferOverflowException if {@code src.remaining()} is greater than this buffer's {@code remaining()}.
+ * @exception IllegalArgumentException if {@code src} is this buffer.
+ * @exception ReadOnlyBufferException if no changes may be made to the contents of this buffer.
+ * @since Android 1.0 */
+ public DoubleBuffer put (DoubleBuffer src) {
+ if (src == this) {
+ throw new IllegalArgumentException();
+ }
+ if (src.remaining() > remaining()) {
+ throw new BufferOverflowException();
+ }
+ double[] doubles = new double[src.remaining()];
+ src.get(doubles);
+ put(doubles);
+ return this;
+ }
+
+ /** Write a double to the specified index of this buffer and the position is not changed.
+ *
+ * @param index the index, must not be negative and less than the limit.
+ * @param d the double to write.
+ * @return this buffer.
+ * @exception IndexOutOfBoundsException if index is invalid.
+ * @exception ReadOnlyBufferException if no changes may be made to the contents of this buffer.
+ * @since Android 1.0 */
+ public abstract DoubleBuffer put (int index, double d);
+
+ /** Returns a sliced buffer that shares its content with this buffer.
+ *
+ * The sliced buffer's capacity will be this buffer's {@code remaining()}, and its zero position will correspond to this
+ * buffer's current position. The new buffer's position will be 0, limit will be its capacity, and its mark is cleared. The new
+ * buffer's read-only property and byte order are the same as this buffer's.
+ *
+ *
+ * The new buffer shares its content with this buffer, which means either buffer's change of content will be visible to the
+ * other. The two buffer's position, limit and mark are independent.
+ *
+ *
+ * @return a sliced buffer that shares its content with this buffer.
+ * @since Android 1.0 */
+ public abstract DoubleBuffer slice ();
+
+ /** Returns a string representing the state of this double buffer.
+ *
+ * @return A string representing the state of this double buffer.
+ * @since Android 1.0 */
+ public String toString () {
+ StringBuffer buf = new StringBuffer();
+ buf.append(getClass().getName());
+ buf.append(", status: capacity="); //$NON-NLS-1$
+ buf.append(capacity());
+ buf.append(" position="); //$NON-NLS-1$
+ buf.append(position());
+ buf.append(" limit="); //$NON-NLS-1$
+ buf.append(limit());
+ return buf.toString();
+ }
}
diff --git a/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/java/nio/DoubleToByteBufferAdapter.java b/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/java/nio/DoubleToByteBufferAdapter.java
index c8d73dfeb1d..10c9ad9d423 100644
--- a/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/java/nio/DoubleToByteBufferAdapter.java
+++ b/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/java/nio/DoubleToByteBufferAdapter.java
@@ -19,188 +19,183 @@
//import org.apache.harmony.nio.internal.DirectBuffer;
//import org.apache.harmony.luni.platform.PlatformAddress;
-/**
- * This class wraps a byte buffer to be a double buffer.
+/** This class wraps a byte buffer to be a double buffer.
*
* Implementation notice:
*
- * After a byte buffer instance is wrapped, it becomes privately owned by
- * the adapter. It must NOT be accessed outside the adapter any more.
- * The byte buffer's position and limit are NOT linked with the adapter.
- * The adapter extends Buffer, thus has its own position and limit.
+ * After a byte buffer instance is wrapped, it becomes privately owned by the adapter. It must NOT be accessed outside the
+ * adapter any more.
+ * The byte buffer's position and limit are NOT linked with the adapter. The adapter extends Buffer, thus has its own position
+ * and limit.
*
- *
- *
- */
-final class DoubleToByteBufferAdapter extends DoubleBuffer {
- //implements DirectBuffer {
-
- static DoubleBuffer wrap(ByteBuffer byteBuffer) {
- return new DoubleToByteBufferAdapter(byteBuffer.slice());
- }
-
- private final ByteBuffer byteBuffer;
-
- DoubleToByteBufferAdapter(ByteBuffer byteBuffer) {
- super((byteBuffer.capacity() >> 3));
- this.byteBuffer = byteBuffer;
- this.byteBuffer.clear();
- }
-
-// public int getByteCapacity() {
-// if (byteBuffer instanceof DirectBuffer) {
-// return ((DirectBuffer) byteBuffer).getByteCapacity();
-// }
-// assert false : byteBuffer;
-// return -1;
-// }
+ * */
+final class DoubleToByteBufferAdapter extends DoubleBuffer {
+ // implements DirectBuffer {
+
+ static DoubleBuffer wrap (ByteBuffer byteBuffer) {
+ return new DoubleToByteBufferAdapter(byteBuffer.slice());
+ }
+
+ private final ByteBuffer byteBuffer;
+
+ DoubleToByteBufferAdapter (ByteBuffer byteBuffer) {
+ super((byteBuffer.capacity() >> 3));
+ this.byteBuffer = byteBuffer;
+ this.byteBuffer.clear();
+ }
+
+// public int getByteCapacity() {
+// if (byteBuffer instanceof DirectBuffer) {
+// return ((DirectBuffer) byteBuffer).getByteCapacity();
+// }
+// assert false : byteBuffer;
+// return -1;
+// }
//
-// public PlatformAddress getEffectiveAddress() {
-// if (byteBuffer instanceof DirectBuffer) {
-// return ((DirectBuffer) byteBuffer).getEffectiveAddress();
-// }
-// assert false : byteBuffer;
-// return null;
-// }
+// public PlatformAddress getEffectiveAddress() {
+// if (byteBuffer instanceof DirectBuffer) {
+// return ((DirectBuffer) byteBuffer).getEffectiveAddress();
+// }
+// assert false : byteBuffer;
+// return null;
+// }
//
-// public PlatformAddress getBaseAddress() {
-// if (byteBuffer instanceof DirectBuffer) {
-// return ((DirectBuffer) byteBuffer).getBaseAddress();
-// }
-// assert false : byteBuffer;
-// return null;
-// }
+// public PlatformAddress getBaseAddress() {
+// if (byteBuffer instanceof DirectBuffer) {
+// return ((DirectBuffer) byteBuffer).getBaseAddress();
+// }
+// assert false : byteBuffer;
+// return null;
+// }
//
-// public boolean isAddressValid() {
-// if (byteBuffer instanceof DirectBuffer) {
-// return ((DirectBuffer) byteBuffer).isAddressValid();
-// }
-// assert false : byteBuffer;
-// return false;
-// }
+// public boolean isAddressValid() {
+// if (byteBuffer instanceof DirectBuffer) {
+// return ((DirectBuffer) byteBuffer).isAddressValid();
+// }
+// assert false : byteBuffer;
+// return false;
+// }
//
-// public void addressValidityCheck() {
-// if (byteBuffer instanceof DirectBuffer) {
-// ((DirectBuffer) byteBuffer).addressValidityCheck();
-// } else {
-// assert false : byteBuffer;
-// }
-// }
+// public void addressValidityCheck() {
+// if (byteBuffer instanceof DirectBuffer) {
+// ((DirectBuffer) byteBuffer).addressValidityCheck();
+// } else {
+// assert false : byteBuffer;
+// }
+// }
//
-// public void free() {
-// if (byteBuffer instanceof DirectBuffer) {
-// ((DirectBuffer) byteBuffer).free();
-// } else {
-// assert false : byteBuffer;
-// }
-// }
-
- @Override
- public DoubleBuffer asReadOnlyBuffer() {
- DoubleToByteBufferAdapter buf = new DoubleToByteBufferAdapter(
- byteBuffer.asReadOnlyBuffer());
- buf.limit = limit;
- buf.position = position;
- buf.mark = mark;
- return buf;
- }
-
- @Override
- public DoubleBuffer compact() {
- if (byteBuffer.isReadOnly()) {
- throw new ReadOnlyBufferException();
- }
- byteBuffer.limit(limit << 3);
- byteBuffer.position(position << 3);
- byteBuffer.compact();
- byteBuffer.clear();
- position = limit - position;
- limit = capacity;
- mark = UNSET_MARK;
- return this;
- }
-
- @Override
- public DoubleBuffer duplicate() {
- DoubleToByteBufferAdapter buf = new DoubleToByteBufferAdapter(
- byteBuffer.duplicate());
- buf.limit = limit;
- buf.position = position;
- buf.mark = mark;
- return buf;
- }
-
- @Override
- public double get() {
- if (position == limit) {
- throw new BufferUnderflowException();
- }
- return byteBuffer.getDouble(position++ << 3);
- }
-
- @Override
- public double get(int index) {
- if (index < 0 || index >= limit) {
- throw new IndexOutOfBoundsException();
- }
- return byteBuffer.getDouble(index << 3);
- }
-
- @Override
- public boolean isDirect() {
- return byteBuffer.isDirect();
- }
-
- @Override
- public boolean isReadOnly() {
- return byteBuffer.isReadOnly();
- }
-
- @Override
- public ByteOrder order() {
- return byteBuffer.order();
- }
-
- @Override
- protected double[] protectedArray() {
- throw new UnsupportedOperationException();
- }
-
- @Override
- protected int protectedArrayOffset() {
- throw new UnsupportedOperationException();
- }
-
- @Override
- protected boolean protectedHasArray() {
- return false;
- }
-
- @Override
- public DoubleBuffer put(double c) {
- if (position == limit) {
- throw new BufferOverflowException();
- }
- byteBuffer.putDouble(position++ << 3, c);
- return this;
- }
-
- @Override
- public DoubleBuffer put(int index, double c) {
- if (index < 0 || index >= limit) {
- throw new IndexOutOfBoundsException();
- }
- byteBuffer.putDouble(index << 3, c);
- return this;
- }
-
- @Override
- public DoubleBuffer slice() {
- byteBuffer.limit(limit << 3);
- byteBuffer.position(position << 3);
- DoubleBuffer result = new DoubleToByteBufferAdapter(byteBuffer.slice());
- byteBuffer.clear();
- return result;
- }
+// public void free() {
+// if (byteBuffer instanceof DirectBuffer) {
+// ((DirectBuffer) byteBuffer).free();
+// } else {
+// assert false : byteBuffer;
+// }
+// }
+
+ @Override
+ public DoubleBuffer asReadOnlyBuffer () {
+ DoubleToByteBufferAdapter buf = new DoubleToByteBufferAdapter(byteBuffer.asReadOnlyBuffer());
+ buf.limit = limit;
+ buf.position = position;
+ buf.mark = mark;
+ return buf;
+ }
+
+ @Override
+ public DoubleBuffer compact () {
+ if (byteBuffer.isReadOnly()) {
+ throw new ReadOnlyBufferException();
+ }
+ byteBuffer.limit(limit << 3);
+ byteBuffer.position(position << 3);
+ byteBuffer.compact();
+ byteBuffer.clear();
+ position = limit - position;
+ limit = capacity;
+ mark = UNSET_MARK;
+ return this;
+ }
+
+ @Override
+ public DoubleBuffer duplicate () {
+ DoubleToByteBufferAdapter buf = new DoubleToByteBufferAdapter(byteBuffer.duplicate());
+ buf.limit = limit;
+ buf.position = position;
+ buf.mark = mark;
+ return buf;
+ }
+
+ @Override
+ public double get () {
+ if (position == limit) {
+ throw new BufferUnderflowException();
+ }
+ return byteBuffer.getDouble(position++ << 3);
+ }
+
+ @Override
+ public double get (int index) {
+ if (index < 0 || index >= limit) {
+ throw new IndexOutOfBoundsException();
+ }
+ return byteBuffer.getDouble(index << 3);
+ }
+
+ @Override
+ public boolean isDirect () {
+ return byteBuffer.isDirect();
+ }
+
+ @Override
+ public boolean isReadOnly () {
+ return byteBuffer.isReadOnly();
+ }
+
+ @Override
+ public ByteOrder order () {
+ return byteBuffer.order();
+ }
+
+ @Override
+ protected double[] protectedArray () {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ protected int protectedArrayOffset () {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ protected boolean protectedHasArray () {
+ return false;
+ }
+
+ @Override
+ public DoubleBuffer put (double c) {
+ if (position == limit) {
+ throw new BufferOverflowException();
+ }
+ byteBuffer.putDouble(position++ << 3, c);
+ return this;
+ }
+
+ @Override
+ public DoubleBuffer put (int index, double c) {
+ if (index < 0 || index >= limit) {
+ throw new IndexOutOfBoundsException();
+ }
+ byteBuffer.putDouble(index << 3, c);
+ return this;
+ }
+
+ @Override
+ public DoubleBuffer slice () {
+ byteBuffer.limit(limit << 3);
+ byteBuffer.position(position << 3);
+ DoubleBuffer result = new DoubleToByteBufferAdapter(byteBuffer.slice());
+ byteBuffer.clear();
+ return result;
+ }
}
diff --git a/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/java/nio/FloatArrayBuffer.java b/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/java/nio/FloatArrayBuffer.java
index bb07e977a24..4c6eca80c6b 100644
--- a/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/java/nio/FloatArrayBuffer.java
+++ b/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/java/nio/FloatArrayBuffer.java
@@ -17,71 +17,67 @@
package java.nio;
-/**
- * FloatArrayBuffer, ReadWriteFloatArrayBuffer and ReadOnlyFloatArrayBuffer
- * compose the implementation of array based float buffers.
+/** FloatArrayBuffer, ReadWriteFloatArrayBuffer and ReadOnlyFloatArrayBuffer compose the implementation of array based float
+ * buffers.
*
- * FloatArrayBuffer implements all the shared readonly methods and is extended
- * by the other two classes.
+ * FloatArrayBuffer implements all the shared readonly methods and is extended by the other two classes.
*
*
* All methods are marked final for runtime performance.
- *
- *
- */
+ * */
abstract class FloatArrayBuffer extends FloatBuffer {
- protected final float[] backingArray;
+ protected final float[] backingArray;
+
+ protected final int offset;
- protected final int offset;
+ FloatArrayBuffer (float[] array) {
+ this(array.length, array, 0);
+ }
- FloatArrayBuffer(float[] array) {
- this(array.length, array, 0);
- }
+ FloatArrayBuffer (int capacity) {
+ this(capacity, new float[capacity], 0);
+ }
- FloatArrayBuffer(int capacity) {
- this(capacity, new float[capacity], 0);
- }
+ FloatArrayBuffer (int capacity, float[] backingArray, int offset) {
+ super(capacity);
+ this.backingArray = backingArray;
+ this.offset = offset;
+ }
- FloatArrayBuffer(int capacity, float[] backingArray, int offset) {
- super(capacity);
- this.backingArray = backingArray;
- this.offset = offset;
- }
+ public final float get () {
+ if (position == limit) {
+ throw new BufferUnderflowException();
+ }
+ return backingArray[offset + position++];
+ }
- public final float get() {
- if (position == limit) {
- throw new BufferUnderflowException();
- }
- return backingArray[offset + position++];
- }
+ public final float get (int index) {
+ if (index < 0 || index >= limit) {
+ throw new IndexOutOfBoundsException();
+ }
+ return backingArray[offset + index];
+ }
- public final float get(int index) {
- if (index < 0 || index >= limit) {
- throw new IndexOutOfBoundsException();
- }
- return backingArray[offset + index];
- }
+ public final FloatBuffer get (float[] dest, int off, int len) {
+ int length = dest.length;
+ if (off < 0 || len < 0 || (long)off + (long)len > length) {
+ throw new IndexOutOfBoundsException();
+ }
+ if (len > remaining()) {
+ throw new BufferUnderflowException();
+ }
+ System.arraycopy(backingArray, offset + position, dest, off, len);
+ position += len;
+ return this;
+ }
- public final FloatBuffer get(float[] dest, int off, int len) {
- int length = dest.length;
- if (off < 0 || len < 0 || (long)off + (long)len > length) {
- throw new IndexOutOfBoundsException();
- }
- if (len > remaining()) {
- throw new BufferUnderflowException();
- }
- System.arraycopy(backingArray, offset+position, dest, off, len);
- position += len;
- return this;
- }
-
- public final boolean isDirect() {
- return false;
- }
+ public final boolean isDirect () {
+ return false;
+ }
- public final ByteOrder order() {
- return ByteOrder.nativeOrder();
- }
+ public final ByteOrder order () {
+ return ByteOrder.nativeOrder();
+ }
}
diff --git a/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/java/nio/FloatBuffer.java b/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/java/nio/FloatBuffer.java
index e6103061444..6d3f39073f6 100644
--- a/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/java/nio/FloatBuffer.java
+++ b/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/java/nio/FloatBuffer.java
@@ -17,566 +17,419 @@
package java.nio;
-/**
- * A buffer of floats.
+/** A buffer of floats.
*
* A float buffer can be created in either of the following ways:
*
*
- * {@link #allocate(int) Allocate} a new float array and create a buffer
- * based on it;
- * {@link #wrap(float[]) Wrap} an existing float array to create a new
- * buffer;
- * Use {@link java.nio.ByteBuffer#asFloatBuffer() ByteBuffer.asFloatBuffer}
- * to create a float buffer based on a byte buffer.
+ * {@link #allocate(int) Allocate} a new float array and create a buffer based on it;
+ * {@link #wrap(float[]) Wrap} an existing float array to create a new buffer;
+ * Use {@link java.nio.ByteBuffer#asFloatBuffer() ByteBuffer.asFloatBuffer} to create a float buffer based on a byte buffer.
*
*
- * @since Android 1.0
- */
+ * @since Android 1.0 */
public abstract class FloatBuffer extends Buffer implements Comparable {
- /**
- * Creates a float buffer based on a newly allocated float array.
- *
- * @param capacity
- * the capacity of the new buffer.
- * @return the created float buffer.
- * @throws IllegalArgumentException
- * if {@code capacity} is less than zero.
- * @since Android 1.0
- */
- public static FloatBuffer allocate(int capacity) {
- if (capacity < 0) {
- throw new IllegalArgumentException();
- }
- return BufferFactory.newFloatBuffer(capacity);
- }
-
- /**
- * Creates a new float buffer by wrapping the given float array.
- *
- * Calling this method has the same effect as
- * {@code wrap(array, 0, array.length)}.
- *
- *
- * @param array
- * the float array which the new buffer will be based on.
- * @return the created float buffer.
- * @since Android 1.0
- */
- public static FloatBuffer wrap(float[] array) {
- return wrap(array, 0, array.length);
- }
-
- /**
- * Creates a new float buffer by wrapping the given float array.
- *
- * The new buffer's position will be {@code start}, limit will be
- * {@code start + len}, capacity will be the length of the array.
- *
- *
- * @param array
- * the float array which the new buffer will be based on.
- * @param start
- * the start index, must not be negative and not greater than
- * {@code array.length}.
- * @param len
- * the length, must not be negative and not greater than
- * {@code array.length - start}.
- * @return the created float buffer.
- * @exception IndexOutOfBoundsException
- * if either {@code start} or {@code len} is invalid.
- * @exception NullPointerException
- * if {@code array} is null.
- * @since Android 1.0
- */
- public static FloatBuffer wrap(float[] array, int start, int len) {
- if (array == null) {
- throw new NullPointerException();
- }
- if (start < 0 || len < 0 || (long)start + (long)len > array.length) {
- throw new IndexOutOfBoundsException();
- }
-
- FloatBuffer buf = BufferFactory.newFloatBuffer(array);
- buf.position = start;
- buf.limit = start + len;
-
- return buf;
- }
-
- /**
- * Constructs a {@code FloatBuffer} with given capacity.
- *
- * @param capacity The capacity of the buffer
- */
- FloatBuffer(int capacity) {
- super(capacity);
- }
-
- /**
- * Returns the float array which this buffer is based on, if there is one.
- *
- * @return the float array which this buffer is based on.
- * @exception ReadOnlyBufferException
- * if this buffer is based on an array, but it is read-only.
- * @exception UnsupportedOperationException
- * if this buffer is not based on an array.
- * @since Android 1.0
- */
- public final float[] array() {
- return protectedArray();
- }
-
- /**
- * Returns the offset of the float array which this buffer is based on, if
- * there is one.
- *
- * The offset is the index of the array and corresponds to the zero position
- * of the buffer.
- *
- *
- * @return the offset of the float array which this buffer is based on.
- * @exception ReadOnlyBufferException
- * if this buffer is based on an array, but it is read-only.
- * @exception UnsupportedOperationException
- * if this buffer is not based on an array.
- * @since Android 1.0
- */
- public final int arrayOffset() {
- return protectedArrayOffset();
- }
-
- /**
- * Returns a read-only buffer that shares its content with this buffer.
- *
- * The returned buffer is guaranteed to be a new instance, even if this
- * buffer is read-only itself. The new buffer's position, limit, capacity
- * and mark are the same as this buffer.
- *
- *
- * The new buffer shares its content with this buffer, which means this
- * buffer's change of content will be visible to the new buffer. The two
- * buffer's position, limit and mark are independent.
- *
- *
- * @return a read-only version of this buffer.
- * @since Android 1.0
- */
- public abstract FloatBuffer asReadOnlyBuffer();
-
- /**
- * Compacts this float buffer.
- *
- * The remaining floats will be moved to the head of the buffer, starting
- * from position zero. Then the position is set to {@code remaining()}; the
- * limit is set to capacity; the mark is cleared.
- *
- *
- * @return this buffer.
- * @exception ReadOnlyBufferException
- * if no changes may be made to the contents of this buffer.
- * @since Android 1.0
- */
- public abstract FloatBuffer compact();
-
- /**
- * Compare the remaining floats of this buffer to another float buffer's
- * remaining floats.
- *
- * @param otherBuffer
- * another float buffer.
- * @return a negative value if this is less than {@code otherBuffer}; 0 if
- * this equals to {@code otherBuffer}; a positive value if this is
- * greater than {@code otherBuffer}.
- * @exception ClassCastException
- * if {@code otherBuffer} is not a float buffer.
- * @since Android 1.0
- */
- public int compareTo(FloatBuffer otherBuffer) {
- int compareRemaining = (remaining() < otherBuffer.remaining()) ? remaining()
- : otherBuffer.remaining();
- int thisPos = position;
- int otherPos = otherBuffer.position;
- // BEGIN android-changed
- float thisFloat, otherFloat;
- while (compareRemaining > 0) {
- thisFloat = get(thisPos);
- otherFloat = otherBuffer.get(otherPos);
- // checks for float and NaN inequality
- if ((thisFloat != otherFloat)
- && ((thisFloat == thisFloat) || (otherFloat == otherFloat))) {
- return thisFloat < otherFloat ? -1 : 1;
- }
- thisPos++;
- otherPos++;
- compareRemaining--;
- }
- // END android-changed
- return remaining() - otherBuffer.remaining();
- }
-
- /**
- * Returns a duplicated buffer that shares its content with this buffer.
- *
- * The duplicated buffer's position, limit, capacity and mark are the same
- * as this buffer. The duplicated buffer's read-only property and byte order
- * are same as this buffer too.
- *
- *
- * The new buffer shares its content with this buffer, which means either
- * buffer's change of content will be visible to the other. The two buffer's
- * position, limit and mark are independent.
- *
- *
- * @return a duplicated buffer that shares its content with this buffer.
- * @since Android 1.0
- */
- public abstract FloatBuffer duplicate();
-
- /**
- * Checks whether this float buffer is equal to another object.
- *
- * If {@code other} is not a float buffer then {@code false} is returned.
- * Two float buffers are equal if and only if their remaining floats are
- * exactly the same. Position, limit, capacity and mark are not considered.
- *
- *
- * @param other
- * the object to compare with this float buffer.
- * @return {@code true} if this float buffer is equal to {@code other},
- * {@code false} otherwise.
- * @since Android 1.0
- */
- public boolean equals(Object other) {
- if (!(other instanceof FloatBuffer)) {
- return false;
- }
- FloatBuffer otherBuffer = (FloatBuffer) other;
-
- if (remaining() != otherBuffer.remaining()) {
- return false;
- }
-
- int myPosition = position;
- int otherPosition = otherBuffer.position;
- boolean equalSoFar = true;
- while (equalSoFar && (myPosition < limit)) {
- equalSoFar = get(myPosition++) == otherBuffer.get(otherPosition++);
- }
-
- return equalSoFar;
- }
-
- /**
- * Returns the float at the current position and increases the position by
- * 1.
- *
- * @return the float at the current position.
- * @exception BufferUnderflowException
- * if the position is equal or greater than limit.
- * @since Android 1.0
- */
- public abstract float get();
-
- /**
- * Reads floats from the current position into the specified float array and
- * increases the position by the number of floats read.
- *
- * Calling this method has the same effect as
- * {@code get(dest, 0, dest.length)}.
- *
- *
- * @param dest
- * the destination float array.
- * @return this buffer.
- * @exception BufferUnderflowException
- * if {@code dest.length} is greater than {@code remaining()}.
- * @since Android 1.0
- */
- public FloatBuffer get(float[] dest) {
- return get(dest, 0, dest.length);
- }
-
- /**
- * Reads floats from the current position into the specified float array,
- * starting from the specified offset, and increases the position by the
- * number of floats read.
- *
- * @param dest
- * the target float array.
- * @param off
- * the offset of the float array, must not be negative and no
- * greater than {@code dest.length}.
- * @param len
- * the number of floats to read, must be no less than zero and no
- * greater than {@code dest.length - off}.
- * @return this buffer.
- * @exception IndexOutOfBoundsException
- * if either {@code off} or {@code len} is invalid.
- * @exception BufferUnderflowException
- * if {@code len} is greater than {@code remaining()}.
- * @since Android 1.0
- */
- public FloatBuffer get(float[] dest, int off, int len) {
- int length = dest.length;
- if (off < 0 || len < 0 || (long)off + (long)len > length) {
- throw new IndexOutOfBoundsException();
- }
-
- if (len > remaining()) {
- throw new BufferUnderflowException();
- }
- for (int i = off; i < off + len; i++) {
- dest[i] = get();
- }
- return this;
- }
-
- /**
- * Returns a float at the specified index; the position is not changed.
- *
- * @param index
- * the index, must not be negative and less than limit.
- * @return a float at the specified index.
- * @exception IndexOutOfBoundsException
- * if index is invalid.
- * @since Android 1.0
- */
- public abstract float get(int index);
-
- /**
- * Indicates whether this buffer is based on a float array and is
- * read/write.
- *
- * @return {@code true} if this buffer is based on a float array and
- * provides read/write access, {@code false} otherwise.
- * @since Android 1.0
- */
- public final boolean hasArray() {
- return protectedHasArray();
- }
-
-// /**
-// * Calculates this buffer's hash code from the remaining chars. The
-// * position, limit, capacity and mark don't affect the hash code.
-// *
-// * @return the hash code calculated from the remaining floats.
-// * @since Android 1.0
-// */
-// public int hashCode() {
-// int myPosition = position;
-// int hash = 0;
-// while (myPosition < limit) {
-// hash = hash + Float.floatToIntBits(get(myPosition++));
-// }
-// return hash;
-// }
-
- /**
- * Indicates whether this buffer is direct. A direct buffer will try its
- * best to take advantage of native memory APIs and it may not stay in the
- * Java heap, so it is not affected by garbage collection.
- *
- * A float buffer is direct if it is based on a byte buffer and the byte
- * buffer is direct.
- *
- *
- * @return {@code true} if this buffer is direct, {@code false} otherwise.
- * @since Android 1.0
- */
- public abstract boolean isDirect();
-
- /**
- * Returns the byte order used by this buffer when converting floats from/to
- * bytes.
- *
- * If this buffer is not based on a byte buffer, then always return the
- * platform's native byte order.
- *
- *
- * @return the byte order used by this buffer when converting floats from/to
- * bytes.
- * @since Android 1.0
- */
- public abstract ByteOrder order();
-
- /**
- * Child class implements this method to realize {@code array()}.
- *
- * @return see {@code array()}
- */
- abstract float[] protectedArray();
-
- /**
- * Child class implements this method to realize {@code arrayOffset()}.
- *
- * @return see {@code arrayOffset()}
- */
- abstract int protectedArrayOffset();
-
- /**
- * Child class implements this method to realize {@code hasArray()}.
- *
- * @return see {@code hasArray()}
- */
- abstract boolean protectedHasArray();
-
- /**
- * Writes the given float to the current position and increases the position
- * by 1.
- *
- * @param f
- * the float to write.
- * @return this buffer.
- * @exception BufferOverflowException
- * if position is equal or greater than limit.
- * @exception ReadOnlyBufferException
- * if no changes may be made to the contents of this buffer.
- * @since Android 1.0
- */
- public abstract FloatBuffer put(float f);
-
- /**
- * Writes floats from the given float array to the current position and
- * increases the position by the number of floats written.
- *
- * Calling this method has the same effect as
- * {@code put(src, 0, src.length)}.
- *
- *
- * @param src
- * the source float array.
- * @return this buffer.
- * @exception BufferOverflowException
- * if {@code remaining()} is less than {@code src.length}.
- * @exception ReadOnlyBufferException
- * if no changes may be made to the contents of this buffer.
- * @since Android 1.0
- */
- public final FloatBuffer put(float[] src) {
- return put(src, 0, src.length);
- }
-
- /**
- * Writes floats from the given float array, starting from the specified
- * offset, to the current position and increases the position by the number
- * of floats written.
- *
- * @param src
- * the source float array.
- * @param off
- * the offset of float array, must not be negative and not
- * greater than {@code src.length}.
- * @param len
- * the number of floats to write, must be no less than zero and
- * no greater than {@code src.length - off}.
- * @return this buffer.
- * @exception BufferOverflowException
- * if {@code remaining()} is less than {@code len}.
- * @exception IndexOutOfBoundsException
- * if either {@code off} or {@code len} is invalid.
- * @exception ReadOnlyBufferException
- * if no changes may be made to the contents of this buffer.
- * @since Android 1.0
- */
- public FloatBuffer put(float[] src, int off, int len) {
- int length = src.length;
- if (off < 0 || len < 0 || (long)off + (long)len > length) {
- throw new IndexOutOfBoundsException();
- }
-
- if (len > remaining()) {
- throw new BufferOverflowException();
- }
- for (int i = off; i < off + len; i++) {
- put(src[i]);
- }
- return this;
- }
-
- /**
- * Writes all the remaining floats of the {@code src} float buffer to this
- * buffer's current position, and increases both buffers' position by the
- * number of floats copied.
- *
- * @param src
- * the source float buffer.
- * @return this buffer.
- * @exception BufferOverflowException
- * if {@code src.remaining()} is greater than this buffer's
- * {@code remaining()}.
- * @exception IllegalArgumentException
- * if {@code src} is this buffer.
- * @exception ReadOnlyBufferException
- * if no changes may be made to the contents of this buffer.
- * @since Android 1.0
- */
- public FloatBuffer put(FloatBuffer src) {
- if (src == this) {
- throw new IllegalArgumentException();
- }
- if (src.remaining() > remaining()) {
- throw new BufferOverflowException();
- }
- float[] contents = new float[src.remaining()];
- src.get(contents);
- put(contents);
- return this;
- }
-
- /**
- * Writes a float to the specified index of this buffer; the position is not
- * changed.
- *
- * @param index
- * the index, must not be negative and less than the limit.
- * @param f
- * the float to write.
- * @return this buffer.
- * @exception IndexOutOfBoundsException
- * if index is invalid.
- * @exception ReadOnlyBufferException
- * if no changes may be made to the contents of this buffer.
- * @since Android 1.0
- */
- public abstract FloatBuffer put(int index, float f);
-
- /**
- * Returns a sliced buffer that shares its content with this buffer.
- *
- * The sliced buffer's capacity will be this buffer's {@code remaining()},
- * and its zero position will correspond to this buffer's current position.
- * The new buffer's position will be 0, limit will be its capacity, and its
- * mark is cleared. The new buffer's read-only property and byte order are
- * same as this buffer's.
- *
- *
- * The new buffer shares its content with this buffer, which means either
- * buffer's change of content will be visible to the other. The two buffer's
- * position, limit and mark are independent.
- *
- *
- * @return a sliced buffer that shares its content with this buffer.
- * @since Android 1.0
- */
- public abstract FloatBuffer slice();
-
- /**
- * Returns a string representing the state of this float buffer.
- *
- * @return a string representing the state of this float buffer.
- * @since Android 1.0
- */
- public String toString() {
- StringBuffer buf = new StringBuffer();
- buf.append(getClass().getName());
- buf.append(", status: capacity="); //$NON-NLS-1$
- buf.append(capacity());
- buf.append(" position="); //$NON-NLS-1$
- buf.append(position());
- buf.append(" limit="); //$NON-NLS-1$
- buf.append(limit());
- return buf.toString();
- }
+ /** Creates a float buffer based on a newly allocated float array.
+ *
+ * @param capacity the capacity of the new buffer.
+ * @return the created float buffer.
+ * @throws IllegalArgumentException if {@code capacity} is less than zero.
+ * @since Android 1.0 */
+ public static FloatBuffer allocate (int capacity) {
+ if (capacity < 0) {
+ throw new IllegalArgumentException();
+ }
+ return BufferFactory.newFloatBuffer(capacity);
+ }
+
+ /** Creates a new float buffer by wrapping the given float array.
+ *
+ * Calling this method has the same effect as {@code wrap(array, 0, array.length)}.
+ *
+ *
+ * @param array the float array which the new buffer will be based on.
+ * @return the created float buffer.
+ * @since Android 1.0 */
+ public static FloatBuffer wrap (float[] array) {
+ return wrap(array, 0, array.length);
+ }
+
+ /** Creates a new float buffer by wrapping the given float array.
+ *
+ * The new buffer's position will be {@code start}, limit will be {@code start + len}, capacity will be the length of the
+ * array.
+ *
+ *
+ * @param array the float array which the new buffer will be based on.
+ * @param start the start index, must not be negative and not greater than {@code array.length}.
+ * @param len the length, must not be negative and not greater than {@code array.length - start}.
+ * @return the created float buffer.
+ * @exception IndexOutOfBoundsException if either {@code start} or {@code len} is invalid.
+ * @exception NullPointerException if {@code array} is null.
+ * @since Android 1.0 */
+ public static FloatBuffer wrap (float[] array, int start, int len) {
+ if (array == null) {
+ throw new NullPointerException();
+ }
+ if (start < 0 || len < 0 || (long)start + (long)len > array.length) {
+ throw new IndexOutOfBoundsException();
+ }
+
+ FloatBuffer buf = BufferFactory.newFloatBuffer(array);
+ buf.position = start;
+ buf.limit = start + len;
+
+ return buf;
+ }
+
+ /** Constructs a {@code FloatBuffer} with given capacity.
+ *
+ * @param capacity The capacity of the buffer */
+ FloatBuffer (int capacity) {
+ super(capacity);
+ }
+
+ /** Returns the float array which this buffer is based on, if there is one.
+ *
+ * @return the float array which this buffer is based on.
+ * @exception ReadOnlyBufferException if this buffer is based on an array, but it is read-only.
+ * @exception UnsupportedOperationException if this buffer is not based on an array.
+ * @since Android 1.0 */
+ public final float[] array () {
+ return protectedArray();
+ }
+
+ /** Returns the offset of the float array which this buffer is based on, if there is one.
+ *
+ * The offset is the index of the array and corresponds to the zero position of the buffer.
+ *
+ *
+ * @return the offset of the float array which this buffer is based on.
+ * @exception ReadOnlyBufferException if this buffer is based on an array, but it is read-only.
+ * @exception UnsupportedOperationException if this buffer is not based on an array.
+ * @since Android 1.0 */
+ public final int arrayOffset () {
+ return protectedArrayOffset();
+ }
+
+ /** Returns a read-only buffer that shares its content with this buffer.
+ *
+ * The returned buffer is guaranteed to be a new instance, even if this buffer is read-only itself. The new buffer's position,
+ * limit, capacity and mark are the same as this buffer.
+ *
+ *
+ * The new buffer shares its content with this buffer, which means this buffer's change of content will be visible to the new
+ * buffer. The two buffer's position, limit and mark are independent.
+ *
+ *
+ * @return a read-only version of this buffer.
+ * @since Android 1.0 */
+ public abstract FloatBuffer asReadOnlyBuffer ();
+
+ /** Compacts this float buffer.
+ *
+ * The remaining floats will be moved to the head of the buffer, starting from position zero. Then the position is set to
+ * {@code remaining()}; the limit is set to capacity; the mark is cleared.
+ *
+ *
+ * @return this buffer.
+ * @exception ReadOnlyBufferException if no changes may be made to the contents of this buffer.
+ * @since Android 1.0 */
+ public abstract FloatBuffer compact ();
+
+ /** Compare the remaining floats of this buffer to another float buffer's remaining floats.
+ *
+ * @param otherBuffer another float buffer.
+ * @return a negative value if this is less than {@code otherBuffer}; 0 if this equals to {@code otherBuffer}; a positive value
+ * if this is greater than {@code otherBuffer}.
+ * @exception ClassCastException if {@code otherBuffer} is not a float buffer.
+ * @since Android 1.0 */
+ public int compareTo (FloatBuffer otherBuffer) {
+ int compareRemaining = (remaining() < otherBuffer.remaining()) ? remaining() : otherBuffer.remaining();
+ int thisPos = position;
+ int otherPos = otherBuffer.position;
+ // BEGIN android-changed
+ float thisFloat, otherFloat;
+ while (compareRemaining > 0) {
+ thisFloat = get(thisPos);
+ otherFloat = otherBuffer.get(otherPos);
+ // checks for float and NaN inequality
+ if ((thisFloat != otherFloat) && ((thisFloat == thisFloat) || (otherFloat == otherFloat))) {
+ return thisFloat < otherFloat ? -1 : 1;
+ }
+ thisPos++;
+ otherPos++;
+ compareRemaining--;
+ }
+ // END android-changed
+ return remaining() - otherBuffer.remaining();
+ }
+
+ /** Returns a duplicated buffer that shares its content with this buffer.
+ *
+ * The duplicated buffer's position, limit, capacity and mark are the same as this buffer. The duplicated buffer's read-only
+ * property and byte order are same as this buffer too.
+ *
+ *
+ * The new buffer shares its content with this buffer, which means either buffer's change of content will be visible to the
+ * other. The two buffer's position, limit and mark are independent.
+ *
+ *
+ * @return a duplicated buffer that shares its content with this buffer.
+ * @since Android 1.0 */
+ public abstract FloatBuffer duplicate ();
+
+ /** Checks whether this float buffer is equal to another object.
+ *
+ * If {@code other} is not a float buffer then {@code false} is returned. Two float buffers are equal if and only if their
+ * remaining floats are exactly the same. Position, limit, capacity and mark are not considered.
+ *
+ *
+ * @param other the object to compare with this float buffer.
+ * @return {@code true} if this float buffer is equal to {@code other}, {@code false} otherwise.
+ * @since Android 1.0 */
+ public boolean equals (Object other) {
+ if (!(other instanceof FloatBuffer)) {
+ return false;
+ }
+ FloatBuffer otherBuffer = (FloatBuffer)other;
+
+ if (remaining() != otherBuffer.remaining()) {
+ return false;
+ }
+
+ int myPosition = position;
+ int otherPosition = otherBuffer.position;
+ boolean equalSoFar = true;
+ while (equalSoFar && (myPosition < limit)) {
+ equalSoFar = get(myPosition++) == otherBuffer.get(otherPosition++);
+ }
+
+ return equalSoFar;
+ }
+
+ /** Returns the float at the current position and increases the position by 1.
+ *
+ * @return the float at the current position.
+ * @exception BufferUnderflowException if the position is equal or greater than limit.
+ * @since Android 1.0 */
+ public abstract float get ();
+
+ /** Reads floats from the current position into the specified float array and increases the position by the number of floats
+ * read.
+ *
+ * Calling this method has the same effect as {@code get(dest, 0, dest.length)}.
+ *
+ *
+ * @param dest the destination float array.
+ * @return this buffer.
+ * @exception BufferUnderflowException if {@code dest.length} is greater than {@code remaining()}.
+ * @since Android 1.0 */
+ public FloatBuffer get (float[] dest) {
+ return get(dest, 0, dest.length);
+ }
+
+ /** Reads floats from the current position into the specified float array, starting from the specified offset, and increases the
+ * position by the number of floats read.
+ *
+ * @param dest the target float array.
+ * @param off the offset of the float array, must not be negative and no greater than {@code dest.length}.
+ * @param len the number of floats to read, must be no less than zero and no greater than {@code dest.length - off}.
+ * @return this buffer.
+ * @exception IndexOutOfBoundsException if either {@code off} or {@code len} is invalid.
+ * @exception BufferUnderflowException if {@code len} is greater than {@code remaining()}.
+ * @since Android 1.0 */
+ public FloatBuffer get (float[] dest, int off, int len) {
+ int length = dest.length;
+ if (off < 0 || len < 0 || (long)off + (long)len > length) {
+ throw new IndexOutOfBoundsException();
+ }
+
+ if (len > remaining()) {
+ throw new BufferUnderflowException();
+ }
+ for (int i = off; i < off + len; i++) {
+ dest[i] = get();
+ }
+ return this;
+ }
+
+ /** Returns a float at the specified index; the position is not changed.
+ *
+ * @param index the index, must not be negative and less than limit.
+ * @return a float at the specified index.
+ * @exception IndexOutOfBoundsException if index is invalid.
+ * @since Android 1.0 */
+ public abstract float get (int index);
+
+ /** Indicates whether this buffer is based on a float array and is read/write.
+ *
+ * @return {@code true} if this buffer is based on a float array and provides read/write access, {@code false} otherwise.
+ * @since Android 1.0 */
+ public final boolean hasArray () {
+ return protectedHasArray();
+ }
+
+// /**
+// * Calculates this buffer's hash code from the remaining chars. The
+// * position, limit, capacity and mark don't affect the hash code.
+// *
+// * @return the hash code calculated from the remaining floats.
+// * @since Android 1.0
+// */
+// public int hashCode() {
+// int myPosition = position;
+// int hash = 0;
+// while (myPosition < limit) {
+// hash = hash + Float.floatToIntBits(get(myPosition++));
+// }
+// return hash;
+// }
+
+ /** Indicates whether this buffer is direct. A direct buffer will try its best to take advantage of native memory APIs and it
+ * may not stay in the Java heap, so it is not affected by garbage collection.
+ *
+ * A float buffer is direct if it is based on a byte buffer and the byte buffer is direct.
+ *
+ *
+ * @return {@code true} if this buffer is direct, {@code false} otherwise.
+ * @since Android 1.0 */
+ public abstract boolean isDirect ();
+
+ /** Returns the byte order used by this buffer when converting floats from/to bytes.
+ *
+ * If this buffer is not based on a byte buffer, then always return the platform's native byte order.
+ *
+ *
+ * @return the byte order used by this buffer when converting floats from/to bytes.
+ * @since Android 1.0 */
+ public abstract ByteOrder order ();
+
+ /** Child class implements this method to realize {@code array()}.
+ *
+ * @return see {@code array()} */
+ abstract float[] protectedArray ();
+
+ /** Child class implements this method to realize {@code arrayOffset()}.
+ *
+ * @return see {@code arrayOffset()} */
+ abstract int protectedArrayOffset ();
+
+ /** Child class implements this method to realize {@code hasArray()}.
+ *
+ * @return see {@code hasArray()} */
+ abstract boolean protectedHasArray ();
+
+ /** Writes the given float to the current position and increases the position by 1.
+ *
+ * @param f the float to write.
+ * @return this buffer.
+ * @exception BufferOverflowException if position is equal or greater than limit.
+ * @exception ReadOnlyBufferException if no changes may be made to the contents of this buffer.
+ * @since Android 1.0 */
+ public abstract FloatBuffer put (float f);
+
+ /** Writes floats from the given float array to the current position and increases the position by the number of floats written.
+ *
+ * Calling this method has the same effect as {@code put(src, 0, src.length)}.
+ *
+ *
+ * @param src the source float array.
+ * @return this buffer.
+ * @exception BufferOverflowException if {@code remaining()} is less than {@code src.length}.
+ * @exception ReadOnlyBufferException if no changes may be made to the contents of this buffer.
+ * @since Android 1.0 */
+ public final FloatBuffer put (float[] src) {
+ return put(src, 0, src.length);
+ }
+
+ /** Writes floats from the given float array, starting from the specified offset, to the current position and increases the
+ * position by the number of floats written.
+ *
+ * @param src the source float array.
+ * @param off the offset of float array, must not be negative and not greater than {@code src.length}.
+ * @param len the number of floats to write, must be no less than zero and no greater than {@code src.length - off}.
+ * @return this buffer.
+ * @exception BufferOverflowException if {@code remaining()} is less than {@code len}.
+ * @exception IndexOutOfBoundsException if either {@code off} or {@code len} is invalid.
+ * @exception ReadOnlyBufferException if no changes may be made to the contents of this buffer.
+ * @since Android 1.0 */
+ public FloatBuffer put (float[] src, int off, int len) {
+ int length = src.length;
+ if (off < 0 || len < 0 || (long)off + (long)len > length) {
+ throw new IndexOutOfBoundsException();
+ }
+
+ if (len > remaining()) {
+ throw new BufferOverflowException();
+ }
+ for (int i = off; i < off + len; i++) {
+ put(src[i]);
+ }
+ return this;
+ }
+
+ /** Writes all the remaining floats of the {@code src} float buffer to this buffer's current position, and increases both
+ * buffers' position by the number of floats copied.
+ *
+ * @param src the source float buffer.
+ * @return this buffer.
+ * @exception BufferOverflowException if {@code src.remaining()} is greater than this buffer's {@code remaining()}.
+ * @exception IllegalArgumentException if {@code src} is this buffer.
+ * @exception ReadOnlyBufferException if no changes may be made to the contents of this buffer.
+ * @since Android 1.0 */
+ public FloatBuffer put (FloatBuffer src) {
+ if (src == this) {
+ throw new IllegalArgumentException();
+ }
+ if (src.remaining() > remaining()) {
+ throw new BufferOverflowException();
+ }
+ float[] contents = new float[src.remaining()];
+ src.get(contents);
+ put(contents);
+ return this;
+ }
+
+ /** Writes a float to the specified index of this buffer; the position is not changed.
+ *
+ * @param index the index, must not be negative and less than the limit.
+ * @param f the float to write.
+ * @return this buffer.
+ * @exception IndexOutOfBoundsException if index is invalid.
+ * @exception ReadOnlyBufferException if no changes may be made to the contents of this buffer.
+ * @since Android 1.0 */
+ public abstract FloatBuffer put (int index, float f);
+
+ /** Returns a sliced buffer that shares its content with this buffer.
+ *
+ * The sliced buffer's capacity will be this buffer's {@code remaining()}, and its zero position will correspond to this
+ * buffer's current position. The new buffer's position will be 0, limit will be its capacity, and its mark is cleared. The new
+ * buffer's read-only property and byte order are same as this buffer's.
+ *
+ *
+ * The new buffer shares its content with this buffer, which means either buffer's change of content will be visible to the
+ * other. The two buffer's position, limit and mark are independent.
+ *
+ *
+ * @return a sliced buffer that shares its content with this buffer.
+ * @since Android 1.0 */
+ public abstract FloatBuffer slice ();
+
+ /** Returns a string representing the state of this float buffer.
+ *
+ * @return a string representing the state of this float buffer.
+ * @since Android 1.0 */
+ public String toString () {
+ StringBuffer buf = new StringBuffer();
+ buf.append(getClass().getName());
+ buf.append(", status: capacity="); //$NON-NLS-1$
+ buf.append(capacity());
+ buf.append(" position="); //$NON-NLS-1$
+ buf.append(position());
+ buf.append(" limit="); //$NON-NLS-1$
+ buf.append(limit());
+ return buf.toString();
+ }
}
diff --git a/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/java/nio/FloatToByteBufferAdapter.java b/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/java/nio/FloatToByteBufferAdapter.java
index 0c19d8fd191..c0722b7ae3d 100644
--- a/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/java/nio/FloatToByteBufferAdapter.java
+++ b/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/java/nio/FloatToByteBufferAdapter.java
@@ -19,188 +19,183 @@
//import org.apache.harmony.nio.internal.DirectBuffer;
//import org.apache.harmony.luni.platform.PlatformAddress;
-/**
- * This class wraps a byte buffer to be a float buffer.
+/** This class wraps a byte buffer to be a float buffer.
*
* Implementation notice:
*
- * After a byte buffer instance is wrapped, it becomes privately owned by
- * the adapter. It must NOT be accessed outside the adapter any more.
- * The byte buffer's position and limit are NOT linked with the adapter.
- * The adapter extends Buffer, thus has its own position and limit.
+ * After a byte buffer instance is wrapped, it becomes privately owned by the adapter. It must NOT be accessed outside the
+ * adapter any more.
+ * The byte buffer's position and limit are NOT linked with the adapter. The adapter extends Buffer, thus has its own position
+ * and limit.
*
- *
- *
- */
+ * */
final class FloatToByteBufferAdapter extends FloatBuffer {
-// implements DirectBuffer {
-
- static FloatBuffer wrap(ByteBuffer byteBuffer) {
- return new FloatToByteBufferAdapter(byteBuffer.slice());
- }
-
- private final ByteBuffer byteBuffer;
-
- FloatToByteBufferAdapter(ByteBuffer byteBuffer) {
- super((byteBuffer.capacity() >> 2));
- this.byteBuffer = byteBuffer;
- this.byteBuffer.clear();
- }
-
-// public int getByteCapacity() {
-// if (byteBuffer instanceof DirectBuffer) {
-// return ((DirectBuffer) byteBuffer).getByteCapacity();
-// }
-// assert false : byteBuffer;
-// return -1;
-// }
+// implements DirectBuffer {
+
+ static FloatBuffer wrap (ByteBuffer byteBuffer) {
+ return new FloatToByteBufferAdapter(byteBuffer.slice());
+ }
+
+ private final ByteBuffer byteBuffer;
+
+ FloatToByteBufferAdapter (ByteBuffer byteBuffer) {
+ super((byteBuffer.capacity() >> 2));
+ this.byteBuffer = byteBuffer;
+ this.byteBuffer.clear();
+ }
+
+// public int getByteCapacity() {
+// if (byteBuffer instanceof DirectBuffer) {
+// return ((DirectBuffer) byteBuffer).getByteCapacity();
+// }
+// assert false : byteBuffer;
+// return -1;
+// }
//
-// public PlatformAddress getEffectiveAddress() {
-// if (byteBuffer instanceof DirectBuffer) {
-// return ((DirectBuffer) byteBuffer).getEffectiveAddress();
-// }
-// assert false : byteBuffer;
-// return null;
-// }
+// public PlatformAddress getEffectiveAddress() {
+// if (byteBuffer instanceof DirectBuffer) {
+// return ((DirectBuffer) byteBuffer).getEffectiveAddress();
+// }
+// assert false : byteBuffer;
+// return null;
+// }
//
-// public PlatformAddress getBaseAddress() {
-// if (byteBuffer instanceof DirectBuffer) {
-// return ((DirectBuffer) byteBuffer).getBaseAddress();
-// }
-// assert false : byteBuffer;
-// return null;
-// }
+// public PlatformAddress getBaseAddress() {
+// if (byteBuffer instanceof DirectBuffer) {
+// return ((DirectBuffer) byteBuffer).getBaseAddress();
+// }
+// assert false : byteBuffer;
+// return null;
+// }
//
-// public boolean isAddressValid() {
-// if (byteBuffer instanceof DirectBuffer) {
-// return ((DirectBuffer) byteBuffer).isAddressValid();
-// }
-// assert false : byteBuffer;
-// return false;
-// }
+// public boolean isAddressValid() {
+// if (byteBuffer instanceof DirectBuffer) {
+// return ((DirectBuffer) byteBuffer).isAddressValid();
+// }
+// assert false : byteBuffer;
+// return false;
+// }
//
-// public void addressValidityCheck() {
-// if (byteBuffer instanceof DirectBuffer) {
-// ((DirectBuffer) byteBuffer).addressValidityCheck();
-// } else {
-// assert false : byteBuffer;
-// }
-// }
+// public void addressValidityCheck() {
+// if (byteBuffer instanceof DirectBuffer) {
+// ((DirectBuffer) byteBuffer).addressValidityCheck();
+// } else {
+// assert false : byteBuffer;
+// }
+// }
//
-// public void free() {
-// if (byteBuffer instanceof DirectBuffer) {
-// ((DirectBuffer) byteBuffer).free();
-// } else {
-// assert false : byteBuffer;
-// }
-// }
-
- @Override
- public FloatBuffer asReadOnlyBuffer() {
- FloatToByteBufferAdapter buf = new FloatToByteBufferAdapter(byteBuffer
- .asReadOnlyBuffer());
- buf.limit = limit;
- buf.position = position;
- buf.mark = mark;
- return buf;
- }
-
- @Override
- public FloatBuffer compact() {
- if (byteBuffer.isReadOnly()) {
- throw new ReadOnlyBufferException();
- }
- byteBuffer.limit(limit << 2);
- byteBuffer.position(position << 2);
- byteBuffer.compact();
- byteBuffer.clear();
- position = limit - position;
- limit = capacity;
- mark = UNSET_MARK;
- return this;
- }
-
- @Override
- public FloatBuffer duplicate() {
- FloatToByteBufferAdapter buf = new FloatToByteBufferAdapter(byteBuffer
- .duplicate());
- buf.limit = limit;
- buf.position = position;
- buf.mark = mark;
- return buf;
- }
-
- @Override
- public float get() {
- if (position == limit) {
- throw new BufferUnderflowException();
- }
- return byteBuffer.getFloat(position++ << 2);
- }
-
- @Override
- public float get(int index) {
- if (index < 0 || index >= limit) {
- throw new IndexOutOfBoundsException();
- }
- return byteBuffer.getFloat(index << 2);
- }
-
- @Override
- public boolean isDirect() {
- return byteBuffer.isDirect();
- }
-
- @Override
- public boolean isReadOnly() {
- return byteBuffer.isReadOnly();
- }
-
- @Override
- public ByteOrder order() {
- return byteBuffer.order();
- }
-
- @Override
- protected float[] protectedArray() {
- throw new UnsupportedOperationException();
- }
-
- @Override
- protected int protectedArrayOffset() {
- throw new UnsupportedOperationException();
- }
-
- @Override
- protected boolean protectedHasArray() {
- return false;
- }
-
- @Override
- public FloatBuffer put(float c) {
- if (position == limit) {
- throw new BufferOverflowException();
- }
- byteBuffer.putFloat(position++ << 2, c);
- return this;
- }
-
- @Override
- public FloatBuffer put(int index, float c) {
- if (index < 0 || index >= limit) {
- throw new IndexOutOfBoundsException();
- }
- byteBuffer.putFloat(index << 2, c);
- return this;
- }
-
- @Override
- public FloatBuffer slice() {
- byteBuffer.limit(limit << 2);
- byteBuffer.position(position << 2);
- FloatBuffer result = new FloatToByteBufferAdapter(byteBuffer.slice());
- byteBuffer.clear();
- return result;
- }
+// public void free() {
+// if (byteBuffer instanceof DirectBuffer) {
+// ((DirectBuffer) byteBuffer).free();
+// } else {
+// assert false : byteBuffer;
+// }
+// }
+
+ @Override
+ public FloatBuffer asReadOnlyBuffer () {
+ FloatToByteBufferAdapter buf = new FloatToByteBufferAdapter(byteBuffer.asReadOnlyBuffer());
+ buf.limit = limit;
+ buf.position = position;
+ buf.mark = mark;
+ return buf;
+ }
+
+ @Override
+ public FloatBuffer compact () {
+ if (byteBuffer.isReadOnly()) {
+ throw new ReadOnlyBufferException();
+ }
+ byteBuffer.limit(limit << 2);
+ byteBuffer.position(position << 2);
+ byteBuffer.compact();
+ byteBuffer.clear();
+ position = limit - position;
+ limit = capacity;
+ mark = UNSET_MARK;
+ return this;
+ }
+
+ @Override
+ public FloatBuffer duplicate () {
+ FloatToByteBufferAdapter buf = new FloatToByteBufferAdapter(byteBuffer.duplicate());
+ buf.limit = limit;
+ buf.position = position;
+ buf.mark = mark;
+ return buf;
+ }
+
+ @Override
+ public float get () {
+ if (position == limit) {
+ throw new BufferUnderflowException();
+ }
+ return byteBuffer.getFloat(position++ << 2);
+ }
+
+ @Override
+ public float get (int index) {
+ if (index < 0 || index >= limit) {
+ throw new IndexOutOfBoundsException();
+ }
+ return byteBuffer.getFloat(index << 2);
+ }
+
+ @Override
+ public boolean isDirect () {
+ return byteBuffer.isDirect();
+ }
+
+ @Override
+ public boolean isReadOnly () {
+ return byteBuffer.isReadOnly();
+ }
+
+ @Override
+ public ByteOrder order () {
+ return byteBuffer.order();
+ }
+
+ @Override
+ protected float[] protectedArray () {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ protected int protectedArrayOffset () {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ protected boolean protectedHasArray () {
+ return false;
+ }
+
+ @Override
+ public FloatBuffer put (float c) {
+ if (position == limit) {
+ throw new BufferOverflowException();
+ }
+ byteBuffer.putFloat(position++ << 2, c);
+ return this;
+ }
+
+ @Override
+ public FloatBuffer put (int index, float c) {
+ if (index < 0 || index >= limit) {
+ throw new IndexOutOfBoundsException();
+ }
+ byteBuffer.putFloat(index << 2, c);
+ return this;
+ }
+
+ @Override
+ public FloatBuffer slice () {
+ byteBuffer.limit(limit << 2);
+ byteBuffer.position(position << 2);
+ FloatBuffer result = new FloatToByteBufferAdapter(byteBuffer.slice());
+ byteBuffer.clear();
+ return result;
+ }
}
diff --git a/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/java/nio/HasArrayBufferView.java b/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/java/nio/HasArrayBufferView.java
index 14a9bef24eb..16afdfe0350 100644
--- a/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/java/nio/HasArrayBufferView.java
+++ b/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/java/nio/HasArrayBufferView.java
@@ -1,9 +1,11 @@
+
package java.nio;
import gwt.g3d.client.gl2.array.ArrayBufferView;
public interface HasArrayBufferView {
- public ArrayBufferView getTypedArray();
- public int getElementSize();
+ public ArrayBufferView getTypedArray ();
+
+ public int getElementSize ();
}
diff --git a/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/java/nio/HeapByteBuffer.java b/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/java/nio/HeapByteBuffer.java
index e0fb524f75f..3c90ff87642 100644
--- a/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/java/nio/HeapByteBuffer.java
+++ b/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/java/nio/HeapByteBuffer.java
@@ -20,232 +20,227 @@
import com.google.gwt.corp.compatibility.Endianness;
import com.google.gwt.corp.compatibility.Numbers;
-/**
- * HeapByteBuffer, ReadWriteHeapByteBuffer and ReadOnlyHeapByteBuffer compose
- * the implementation of array based byte buffers.
+/** HeapByteBuffer, ReadWriteHeapByteBuffer and ReadOnlyHeapByteBuffer compose the implementation of array based byte buffers.
*
- * HeapByteBuffer implements all the shared readonly methods and is extended by
- * the other two classes.
+ * HeapByteBuffer implements all the shared readonly methods and is extended by the other two classes.
*
*
* All methods are marked final for runtime performance.
- *
- *
- */
+ * */
abstract class HeapByteBuffer extends BaseByteBuffer {
- protected final byte[] backingArray;
-
- protected final int offset;
-
- HeapByteBuffer(byte[] backingArray) {
- this(backingArray, backingArray.length, 0);
- }
-
- HeapByteBuffer(int capacity) {
- this(new byte[capacity], capacity, 0);
- }
-
- HeapByteBuffer(byte[] backingArray, int capacity, int offset) {
- super(capacity);
- this.backingArray = backingArray;
- this.offset = offset;
-
- if (offset + capacity > backingArray.length) {
- throw new IndexOutOfBoundsException();
- }
- }
-
- /*
- * Override ByteBuffer.get(byte[], int, int) to improve performance.
- *
- * (non-Javadoc)
- *
- * @see java.nio.ByteBuffer#get(byte[], int, int)
- */
- public final ByteBuffer get(byte[] dest, int off, int len) {
- int length = dest.length;
- if (off < 0 || len < 0 || (long)off + (long)len > length) {
- throw new IndexOutOfBoundsException();
- }
- if (len > remaining()) {
- throw new BufferUnderflowException();
- }
- System.arraycopy(backingArray, offset + position, dest, off, len);
- position += len;
- return this;
- }
-
- public final byte get() {
- if (position == limit) {
- throw new BufferUnderflowException();
- }
- return backingArray[offset + position++];
- }
-
- public final byte get(int index) {
- if (index < 0 || index >= limit) {
- throw new IndexOutOfBoundsException();
- }
- return backingArray[offset + index];
- }
-
- public final double getDouble() {
- return Numbers.longBitsToDouble(getLong());
- }
-
- public final double getDouble(int index) {
- return Numbers.longBitsToDouble(getLong(index));
- }
-
- public final float getFloat() {
- return Numbers.intBitsToFloat(getInt());
- }
-
- public final float getFloat(int index) {
- return Numbers.intBitsToFloat(getInt(index));
- }
-
- public final int getInt() {
- int newPosition = position + 4;
- if (newPosition > limit) {
- throw new BufferUnderflowException();
- }
- int result = loadInt(position);
- position = newPosition;
- return result;
- }
-
- public final int getInt(int index) {
- if (index < 0 || index + 4 > limit) {
- throw new IndexOutOfBoundsException();
- }
- return loadInt(index);
- }
-
- public final long getLong() {
- int newPosition = position + 8;
- if (newPosition > limit) {
- throw new BufferUnderflowException();
- }
- long result = loadLong(position);
- position = newPosition;
- return result;
- }
-
- public final long getLong(int index) {
- if (index < 0 || index + 8 > limit) {
- throw new IndexOutOfBoundsException();
- }
- return loadLong(index);
- }
-
- public final short getShort() {
- int newPosition = position + 2;
- if (newPosition > limit) {
- throw new BufferUnderflowException();
- }
- short result = loadShort(position);
- position = newPosition;
- return result;
- }
-
- public final short getShort(int index) {
- if (index < 0 || index + 2 > limit) {
- throw new IndexOutOfBoundsException();
- }
- return loadShort(index);
- }
-
- public final boolean isDirect() {
- return false;
- }
-
- protected final int loadInt(int index) {
- int baseOffset = offset + index;
- int bytes = 0;
- if(order == Endianness.BIG_ENDIAN){
- for (int i = 0; i < 4; i++) {
- bytes = bytes << 8;
- bytes = bytes | (backingArray[baseOffset + i] & 0xFF);
- }
- }else{
- for (int i = 3; i >= 0; i--) {
- bytes = bytes << 8;
- bytes = bytes | (backingArray[baseOffset + i] & 0xFF);
- }
- }
- return bytes;
- }
-
- protected final long loadLong(int index) {
- int baseOffset = offset + index;
- long bytes = 0;
- if(order == Endianness.BIG_ENDIAN){
- for (int i = 0; i < 8; i++) {
- bytes = bytes << 8;
- bytes = bytes | (backingArray[baseOffset + i] & 0xFF);
- }
- }else{
- for (int i = 7; i >= 0; i--) {
- bytes = bytes << 8;
- bytes = bytes | (backingArray[baseOffset + i] & 0xFF);
- }
- }
- return bytes;
- }
-
- protected final short loadShort(int index) {
- int baseOffset = offset + index;
- short bytes = 0;
- if(order == Endianness.BIG_ENDIAN){
- bytes = (short) (backingArray[baseOffset] << 8);
- bytes |= (backingArray[baseOffset + 1] & 0xFF);
- }else{
- bytes = (short) (backingArray[baseOffset+1] << 8);
- bytes |= (backingArray[baseOffset] & 0xFF);
- }
- return bytes;
- }
-
- protected final void store(int index, int value) {
- int baseOffset = offset + index;
- if (order == Endianness.BIG_ENDIAN) {
- for (int i = 3; i >= 0; i--) {
- backingArray[baseOffset + i] = (byte) (value & 0xFF);
- value = value >> 8;
- }
- } else {
- for (int i = 0; i <= 3; i++) {
- backingArray[baseOffset + i] = (byte) (value & 0xFF);
- value = value >> 8;
- }
- }
- }
-
- protected final void store(int index, long value) {
- int baseOffset = offset + index;
- if (order == Endianness.BIG_ENDIAN) {
- for (int i = 7; i >= 0; i--) {
- backingArray[baseOffset + i] = (byte) (value & 0xFF);
- value = value >> 8;
- }
- } else {
- for (int i = 0; i <= 7; i++) {
- backingArray[baseOffset + i] = (byte) (value & 0xFF);
- value = value >> 8;
- }
- }
- }
-
- protected final void store(int index, short value) {
- int baseOffset = offset + index;
- if (order == Endianness.BIG_ENDIAN) {
- backingArray[baseOffset] = (byte) ((value >> 8) & 0xFF);
- backingArray[baseOffset + 1] = (byte) (value & 0xFF);
- } else {
- backingArray[baseOffset+1] = (byte) ((value >> 8) & 0xFF);
- backingArray[baseOffset] = (byte) (value & 0xFF);
- }
- }
+ protected final byte[] backingArray;
+
+ protected final int offset;
+
+ HeapByteBuffer (byte[] backingArray) {
+ this(backingArray, backingArray.length, 0);
+ }
+
+ HeapByteBuffer (int capacity) {
+ this(new byte[capacity], capacity, 0);
+ }
+
+ HeapByteBuffer (byte[] backingArray, int capacity, int offset) {
+ super(capacity);
+ this.backingArray = backingArray;
+ this.offset = offset;
+
+ if (offset + capacity > backingArray.length) {
+ throw new IndexOutOfBoundsException();
+ }
+ }
+
+ /*
+ * Override ByteBuffer.get(byte[], int, int) to improve performance.
+ *
+ * (non-Javadoc)
+ *
+ * @see java.nio.ByteBuffer#get(byte[], int, int)
+ */
+ public final ByteBuffer get (byte[] dest, int off, int len) {
+ int length = dest.length;
+ if (off < 0 || len < 0 || (long)off + (long)len > length) {
+ throw new IndexOutOfBoundsException();
+ }
+ if (len > remaining()) {
+ throw new BufferUnderflowException();
+ }
+ System.arraycopy(backingArray, offset + position, dest, off, len);
+ position += len;
+ return this;
+ }
+
+ public final byte get () {
+ if (position == limit) {
+ throw new BufferUnderflowException();
+ }
+ return backingArray[offset + position++];
+ }
+
+ public final byte get (int index) {
+ if (index < 0 || index >= limit) {
+ throw new IndexOutOfBoundsException();
+ }
+ return backingArray[offset + index];
+ }
+
+ public final double getDouble () {
+ return Numbers.longBitsToDouble(getLong());
+ }
+
+ public final double getDouble (int index) {
+ return Numbers.longBitsToDouble(getLong(index));
+ }
+
+ public final float getFloat () {
+ return Numbers.intBitsToFloat(getInt());
+ }
+
+ public final float getFloat (int index) {
+ return Numbers.intBitsToFloat(getInt(index));
+ }
+
+ public final int getInt () {
+ int newPosition = position + 4;
+ if (newPosition > limit) {
+ throw new BufferUnderflowException();
+ }
+ int result = loadInt(position);
+ position = newPosition;
+ return result;
+ }
+
+ public final int getInt (int index) {
+ if (index < 0 || index + 4 > limit) {
+ throw new IndexOutOfBoundsException();
+ }
+ return loadInt(index);
+ }
+
+ public final long getLong () {
+ int newPosition = position + 8;
+ if (newPosition > limit) {
+ throw new BufferUnderflowException();
+ }
+ long result = loadLong(position);
+ position = newPosition;
+ return result;
+ }
+
+ public final long getLong (int index) {
+ if (index < 0 || index + 8 > limit) {
+ throw new IndexOutOfBoundsException();
+ }
+ return loadLong(index);
+ }
+
+ public final short getShort () {
+ int newPosition = position + 2;
+ if (newPosition > limit) {
+ throw new BufferUnderflowException();
+ }
+ short result = loadShort(position);
+ position = newPosition;
+ return result;
+ }
+
+ public final short getShort (int index) {
+ if (index < 0 || index + 2 > limit) {
+ throw new IndexOutOfBoundsException();
+ }
+ return loadShort(index);
+ }
+
+ public final boolean isDirect () {
+ return false;
+ }
+
+ protected final int loadInt (int index) {
+ int baseOffset = offset + index;
+ int bytes = 0;
+ if (order == Endianness.BIG_ENDIAN) {
+ for (int i = 0; i < 4; i++) {
+ bytes = bytes << 8;
+ bytes = bytes | (backingArray[baseOffset + i] & 0xFF);
+ }
+ } else {
+ for (int i = 3; i >= 0; i--) {
+ bytes = bytes << 8;
+ bytes = bytes | (backingArray[baseOffset + i] & 0xFF);
+ }
+ }
+ return bytes;
+ }
+
+ protected final long loadLong (int index) {
+ int baseOffset = offset + index;
+ long bytes = 0;
+ if (order == Endianness.BIG_ENDIAN) {
+ for (int i = 0; i < 8; i++) {
+ bytes = bytes << 8;
+ bytes = bytes | (backingArray[baseOffset + i] & 0xFF);
+ }
+ } else {
+ for (int i = 7; i >= 0; i--) {
+ bytes = bytes << 8;
+ bytes = bytes | (backingArray[baseOffset + i] & 0xFF);
+ }
+ }
+ return bytes;
+ }
+
+ protected final short loadShort (int index) {
+ int baseOffset = offset + index;
+ short bytes = 0;
+ if (order == Endianness.BIG_ENDIAN) {
+ bytes = (short)(backingArray[baseOffset] << 8);
+ bytes |= (backingArray[baseOffset + 1] & 0xFF);
+ } else {
+ bytes = (short)(backingArray[baseOffset + 1] << 8);
+ bytes |= (backingArray[baseOffset] & 0xFF);
+ }
+ return bytes;
+ }
+
+ protected final void store (int index, int value) {
+ int baseOffset = offset + index;
+ if (order == Endianness.BIG_ENDIAN) {
+ for (int i = 3; i >= 0; i--) {
+ backingArray[baseOffset + i] = (byte)(value & 0xFF);
+ value = value >> 8;
+ }
+ } else {
+ for (int i = 0; i <= 3; i++) {
+ backingArray[baseOffset + i] = (byte)(value & 0xFF);
+ value = value >> 8;
+ }
+ }
+ }
+
+ protected final void store (int index, long value) {
+ int baseOffset = offset + index;
+ if (order == Endianness.BIG_ENDIAN) {
+ for (int i = 7; i >= 0; i--) {
+ backingArray[baseOffset + i] = (byte)(value & 0xFF);
+ value = value >> 8;
+ }
+ } else {
+ for (int i = 0; i <= 7; i++) {
+ backingArray[baseOffset + i] = (byte)(value & 0xFF);
+ value = value >> 8;
+ }
+ }
+ }
+
+ protected final void store (int index, short value) {
+ int baseOffset = offset + index;
+ if (order == Endianness.BIG_ENDIAN) {
+ backingArray[baseOffset] = (byte)((value >> 8) & 0xFF);
+ backingArray[baseOffset + 1] = (byte)(value & 0xFF);
+ } else {
+ backingArray[baseOffset + 1] = (byte)((value >> 8) & 0xFF);
+ backingArray[baseOffset] = (byte)(value & 0xFF);
+ }
+ }
}
diff --git a/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/java/nio/IntArrayBuffer.java b/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/java/nio/IntArrayBuffer.java
index d77268e4566..10a62ad4289 100644
--- a/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/java/nio/IntArrayBuffer.java
+++ b/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/java/nio/IntArrayBuffer.java
@@ -15,73 +15,68 @@
* limitations under the License.
*/
-package java.nio;
+package java.nio;
-/**
- * IntArrayBuffer, ReadWriteIntArrayBuffer and ReadOnlyIntArrayBuffer compose
- * the implementation of array based int buffers.
+/** IntArrayBuffer, ReadWriteIntArrayBuffer and ReadOnlyIntArrayBuffer compose the implementation of array based int buffers.
*
- * IntArrayBuffer implements all the shared readonly methods and is extended by
- * the other two classes.
+ * IntArrayBuffer implements all the shared readonly methods and is extended by the other two classes.
*
*
* All methods are marked final for runtime performance.
- *
- *
- */
+ * */
abstract class IntArrayBuffer extends IntBuffer {
- protected final int[] backingArray;
+ protected final int[] backingArray;
+
+ protected final int offset;
- protected final int offset;
+ IntArrayBuffer (int[] array) {
+ this(array.length, array, 0);
+ }
- IntArrayBuffer(int[] array) {
- this(array.length, array, 0);
- }
+ IntArrayBuffer (int capacity) {
+ this(capacity, new int[capacity], 0);
+ }
- IntArrayBuffer(int capacity) {
- this(capacity, new int[capacity], 0);
- }
+ IntArrayBuffer (int capacity, int[] backingArray, int offset) {
+ super(capacity);
+ this.backingArray = backingArray;
+ this.offset = offset;
+ }
- IntArrayBuffer(int capacity, int[] backingArray, int offset) {
- super(capacity);
- this.backingArray = backingArray;
- this.offset = offset;
- }
+ public final int get () {
+ if (position == limit) {
+ throw new BufferUnderflowException();
+ }
+ return backingArray[offset + position++];
+ }
- public final int get() {
- if (position == limit) {
- throw new BufferUnderflowException();
- }
- return backingArray[offset + position++];
- }
+ public final int get (int index) {
+ if (index < 0 || index >= limit) {
+ throw new IndexOutOfBoundsException();
+ }
+ return backingArray[offset + index];
+ }
- public final int get(int index) {
- if (index < 0 || index >= limit) {
- throw new IndexOutOfBoundsException();
- }
- return backingArray[offset + index];
- }
+ public final IntBuffer get (int[] dest, int off, int len) {
+ int length = dest.length;
+ if (off < 0 || len < 0 || (long)len + (long)off > length) {
+ throw new IndexOutOfBoundsException();
+ }
+ if (len > remaining()) {
+ throw new BufferUnderflowException();
+ }
+ System.arraycopy(backingArray, offset + position, dest, off, len);
+ position += len;
+ return this;
+ }
- public final IntBuffer get(int[] dest, int off, int len) {
- int length = dest.length;
- if (off < 0 || len < 0 || (long)len + (long)off > length) {
- throw new IndexOutOfBoundsException();
- }
- if (len > remaining()) {
- throw new BufferUnderflowException();
- }
- System.arraycopy(backingArray, offset+position, dest, off, len);
- position += len;
- return this;
- }
-
- public final boolean isDirect() {
- return false;
- }
+ public final boolean isDirect () {
+ return false;
+ }
- public final ByteOrder order() {
- return ByteOrder.nativeOrder();
- }
+ public final ByteOrder order () {
+ return ByteOrder.nativeOrder();
+ }
}
diff --git a/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/java/nio/IntBuffer.java b/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/java/nio/IntBuffer.java
index 60f8a0263b4..b88e59ed07f 100644
--- a/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/java/nio/IntBuffer.java
+++ b/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/java/nio/IntBuffer.java
@@ -17,559 +17,413 @@
package java.nio;
-/**
- * A buffer of ints.
+/** A buffer of ints.
*
* A int buffer can be created in either of the following ways:
*
*
- * {@link #allocate(int) Allocate} a new int array and create a buffer
- * based on it;
+ * {@link #allocate(int) Allocate} a new int array and create a buffer based on it;
* {@link #wrap(int[]) Wrap} an existing int array to create a new buffer;
- * Use {@link java.nio.ByteBuffer#asIntBuffer() ByteBuffer.asIntBuffer} to
- * create a int buffer based on a byte buffer.
+ * Use {@link java.nio.ByteBuffer#asIntBuffer() ByteBuffer.asIntBuffer} to create a int buffer based on a byte buffer.
*
*
- * @since Android 1.0
- */
+ * @since Android 1.0 */
public abstract class IntBuffer extends Buffer implements Comparable {
- /**
- * Creates an int buffer based on a newly allocated int array.
- *
- * @param capacity
- * the capacity of the new buffer.
- * @return the created int buffer.
- * @throws IllegalArgumentException
- * if {@code capacity} is less than zero.
- * @since Android 1.0
- */
- public static IntBuffer allocate(int capacity) {
- if (capacity < 0) {
- throw new IllegalArgumentException();
- }
- return BufferFactory.newIntBuffer(capacity);
- }
-
- /**
- * Creates a new int buffer by wrapping the given int array.
- *
- * Calling this method has the same effect as
- * {@code wrap(array, 0, array.length)}.
- *
- *
- * @param array
- * the int array which the new buffer will be based on.
- * @return the created int buffer.
- * @since Android 1.0
- */
- public static IntBuffer wrap(int[] array) {
- return wrap(array, 0, array.length);
- }
-
- /**
- * Creates a new int buffer by wrapping the given int array.
- *
- * The new buffer's position will be {@code start}, limit will be
- * {@code start + len}, capacity will be the length of the array.
- *
- *
- * @param array
- * the int array which the new buffer will be based on.
- * @param start
- * the start index, must not be negative and not greater than
- * {@code array.length}
- * @param len
- * the length, must not be negative and not greater than
- * {@code array.length - start}.
- * @return the created int buffer.
- * @exception IndexOutOfBoundsException
- * if either {@code start} or {@code len} is invalid.
- * @since Android 1.0
- */
- public static IntBuffer wrap(int[] array, int start, int len) {
- if (array == null) {
- throw new NullPointerException();
- }
- if (start < 0 || len < 0 || (long)len + (long)start > array.length) {
- throw new IndexOutOfBoundsException();
- }
-
- IntBuffer buf = BufferFactory.newIntBuffer(array);
- buf.position = start;
- buf.limit = start + len;
-
- return buf;
- }
-
- /**
- * Constructs a {@code IntBuffer} with given capacity.
- *
- * @param capacity
- * the capacity of the buffer.
- */
- IntBuffer(int capacity) {
- super(capacity);
- }
-
- /**
- * Returns the int array which this buffer is based on, if there is one.
- *
- * @return the int array which this buffer is based on.
- * @exception ReadOnlyBufferException
- * if this buffer is based on an array, but it is read-only.
- * @exception UnsupportedOperationException
- * if this buffer is not based on an array.
- * @since Android 1.0
- */
- public final int[] array() {
- return protectedArray();
- }
-
- /**
- * Returns the offset of the int array which this buffer is based on, if
- * there is one.
- *
- * The offset is the index of the array corresponds to the zero position of
- * the buffer.
- *
- *
- * @return the offset of the int array which this buffer is based on.
- * @exception ReadOnlyBufferException
- * if this buffer is based on an array, but it is read-only.
- * @exception UnsupportedOperationException
- * if this buffer is not based on an array.
- * @since Android 1.0
- */
- public final int arrayOffset() {
- return protectedArrayOffset();
- }
-
- /**
- * Returns a read-only buffer that shares its content with this buffer.
- *
- * The returned buffer is guaranteed to be a new instance, even this buffer
- * is read-only itself. The new buffer's position, limit, capacity and mark
- * are the same as this buffer's.
- *
- *
- * The new buffer shares its content with this buffer, which means this
- * buffer's change of content will be visible to the new buffer. The two
- * buffer's position, limit and mark are independent.
- *
- *
- * @return a read-only version of this buffer.
- * @since Android 1.0
- */
- public abstract IntBuffer asReadOnlyBuffer();
-
- /**
- * Compacts this int buffer.
- *
- * The remaining ints will be moved to the head of the buffer, starting from
- * position zero. Then the position is set to {@code remaining()}; the
- * limit is set to capacity; the mark is cleared.
- *
- *
- * @return this buffer.
- * @exception ReadOnlyBufferException
- * if no changes may be made to the contents of this buffer.
- * @since Android 1.0
- */
- public abstract IntBuffer compact();
-
- /**
- * Compares the remaining ints of this buffer to another int buffer's
- * remaining ints.
- *
- * @param otherBuffer
- * another int buffer.
- * @return a negative value if this is less than {@code other}; 0 if this
- * equals to {@code other}; a positive value if this is greater
- * than {@code other}.
- * @exception ClassCastException
- * if {@code other} is not an int buffer.
- * @since Android 1.0
- */
- public int compareTo(IntBuffer otherBuffer) {
- int compareRemaining = (remaining() < otherBuffer.remaining()) ? remaining()
- : otherBuffer.remaining();
- int thisPos = position;
- int otherPos = otherBuffer.position;
- // BEGIN android-changed
- int thisInt, otherInt;
- while (compareRemaining > 0) {
- thisInt = get(thisPos);
- otherInt = otherBuffer.get(otherPos);
- if (thisInt != otherInt) {
- return thisInt < otherInt ? -1 : 1;
- }
- thisPos++;
- otherPos++;
- compareRemaining--;
- }
- // END android-changed
- return remaining() - otherBuffer.remaining();
- }
-
- /**
- * Returns a duplicated buffer that shares its content with this buffer.
- *
- * The duplicated buffer's position, limit, capacity and mark are the same
- * as this buffer. The duplicated buffer's read-only property and byte order
- * are the same as this buffer's.
- *
- *
- * The new buffer shares its content with this buffer, which means either
- * buffer's change of content will be visible to the other. The two buffer's
- * position, limit and mark are independent.
- *
- *
- * @return a duplicated buffer that shares its content with this buffer.
- * @since Android 1.0
- */
- public abstract IntBuffer duplicate();
-
- /**
- * Checks whether this int buffer is equal to another object.
- *
- * If {@code other} is not a int buffer then {@code false} is returned. Two
- * int buffers are equal if and only if their remaining ints are exactly the
- * same. Position, limit, capacity and mark are not considered.
- *
- *
- * @param other
- * the object to compare with this int buffer.
- * @return {@code true} if this int buffer is equal to {@code other},
- * {@code false} otherwise.
- * @since Android 1.0
- */
- public boolean equals(Object other) {
- if (!(other instanceof IntBuffer)) {
- return false;
- }
- IntBuffer otherBuffer = (IntBuffer) other;
-
- if (remaining() != otherBuffer.remaining()) {
- return false;
- }
-
- int myPosition = position;
- int otherPosition = otherBuffer.position;
- boolean equalSoFar = true;
- while (equalSoFar && (myPosition < limit)) {
- equalSoFar = get(myPosition++) == otherBuffer.get(otherPosition++);
- }
-
- return equalSoFar;
- }
-
- /**
- * Returns the int at the current position and increases the position by 1.
- *
- * @return the int at the current position.
- * @exception BufferUnderflowException
- * if the position is equal or greater than limit.
- * @since Android 1.0
- */
- public abstract int get();
-
- /**
- * Reads ints from the current position into the specified int array and
- * increases the position by the number of ints read.
- *
- * Calling this method has the same effect as
- * {@code get(dest, 0, dest.length)}.
- *
- *
- * @param dest
- * the destination int array.
- * @return this buffer.
- * @exception BufferUnderflowException
- * if {@code dest.length} is greater than {@code remaining()}.
- * @since Android 1.0
- */
- public IntBuffer get(int[] dest) {
- return get(dest, 0, dest.length);
- }
-
- /**
- * Reads ints from the current position into the specified int array,
- * starting from the specified offset, and increases the position by the
- * number of ints read.
- *
- * @param dest
- * the target int array.
- * @param off
- * the offset of the int array, must not be negative and not
- * greater than {@code dest.length}.
- * @param len
- * the number of ints to read, must be no less than zero and not
- * greater than {@code dest.length - off}.
- * @return this buffer.
- * @exception IndexOutOfBoundsException
- * if either {@code off} or {@code len} is invalid.
- * @exception BufferUnderflowException
- * if {@code len} is greater than {@code remaining()}.
- * @since Android 1.0
- */
- public IntBuffer get(int[] dest, int off, int len) {
- int length = dest.length;
- if (off < 0 || len < 0 || (long)len + (long)off > length) {
- throw new IndexOutOfBoundsException();
- }
- if (len > remaining()) {
- throw new BufferUnderflowException();
- }
- for (int i = off; i < off + len; i++) {
- dest[i] = get();
- }
- return this;
- }
-
- /**
- * Returns an int at the specified index; the position is not changed.
- *
- * @param index
- * the index, must not be negative and less than limit.
- * @return an int at the specified index.
- * @exception IndexOutOfBoundsException
- * if index is invalid.
- * @since Android 1.0
- */
- public abstract int get(int index);
-
- /**
- * Indicates whether this buffer is based on a int array and is read/write.
- *
- * @return {@code true} if this buffer is based on a int array and provides
- * read/write access, {@code false} otherwise.
- * @since Android 1.0
- */
- public final boolean hasArray() {
- return protectedHasArray();
- }
-
- /**
- * Calculates this buffer's hash code from the remaining chars. The
- * position, limit, capacity and mark don't affect the hash code.
- *
- * @return the hash code calculated from the remaining ints.
- * @since Android 1.0
- */
- public int hashCode() {
- int myPosition = position;
- int hash = 0;
- while (myPosition < limit) {
- hash = hash + get(myPosition++);
- }
- return hash;
- }
-
- /**
- * Indicates whether this buffer is direct. A direct buffer will try its
- * best to take advantage of native memory APIs and it may not stay in the
- * Java heap, so it is not affected by garbage collection.
- *
- * An int buffer is direct if it is based on a byte buffer and the byte
- * buffer is direct.
- *
- *
- * @return {@code true} if this buffer is direct, {@code false} otherwise.
- * @since Android 1.0
- */
- public abstract boolean isDirect();
-
- /**
- * Returns the byte order used by this buffer when converting ints from/to
- * bytes.
- *
- * If this buffer is not based on a byte buffer, then always return the
- * platform's native byte order.
- *
- *
- * @return the byte order used by this buffer when converting ints from/to
- * bytes.
- * @since Android 1.0
- */
- public abstract ByteOrder order();
-
- /**
- * Child class implements this method to realize {@code array()}.
- *
- * @return see {@code array()}
- */
- protected abstract int[] protectedArray();
-
- /**
- * Child class implements this method to realize {@code arrayOffset()}.
- *
- * @return see {@code arrayOffset()}
- */
- protected abstract int protectedArrayOffset();
-
- /**
- * Child class implements this method to realize {@code hasArray()}.
- *
- * @return see {@code hasArray()}
- */
- protected abstract boolean protectedHasArray();
-
- /**
- * Writes the given int to the current position and increases the position
- * by 1.
- *
- * @param i
- * the int to write.
- * @return this buffer.
- * @exception BufferOverflowException
- * if position is equal or greater than limit.
- * @exception ReadOnlyBufferException
- * if no changes may be made to the contents of this buffer.
- * @since Android 1.0
- */
- public abstract IntBuffer put(int i);
-
- /**
- * Writes ints from the given int array to the current position and
- * increases the position by the number of ints written.
- *
- * Calling this method has the same effect as
- * {@code put(src, 0, src.length)}.
- *
- *
- * @param src
- * the source int array.
- * @return this buffer.
- * @exception BufferOverflowException
- * if {@code remaining()} is less than {@code src.length}.
- * @exception ReadOnlyBufferException
- * if no changes may be made to the contents of this buffer.
- * @since Android 1.0
- */
- public final IntBuffer put(int[] src) {
- return put(src, 0, src.length);
- }
-
- /**
- * Writes ints from the given int array, starting from the specified offset,
- * to the current position and increases the position by the number of ints
- * written.
- *
- * @param src
- * the source int array.
- * @param off
- * the offset of int array, must not be negative and not greater
- * than {@code src.length}.
- * @param len
- * the number of ints to write, must be no less than zero and not
- * greater than {@code src.length - off}.
- * @return this buffer.
- * @exception BufferOverflowException
- * if {@code remaining()} is less than {@code len}.
- * @exception IndexOutOfBoundsException
- * if either {@code off} or {@code len} is invalid.
- * @exception ReadOnlyBufferException
- * if no changes may be made to the contents of this buffer.
- * @since Android 1.0
- */
- public IntBuffer put(int[] src, int off, int len) {
- int length = src.length;
- if (off < 0 || len < 0 || (long)len + (long)off > length) {
- throw new IndexOutOfBoundsException();
- }
-
- if (len > remaining()) {
- throw new BufferOverflowException();
- }
- for (int i = off; i < off + len; i++) {
- put(src[i]);
- }
- return this;
- }
-
- /**
- * Writes all the remaining ints of the {@code src} int buffer to this
- * buffer's current position, and increases both buffers' position by the
- * number of ints copied.
- *
- * @param src
- * the source int buffer.
- * @return this buffer.
- * @exception BufferOverflowException
- * if {@code src.remaining()} is greater than this buffer's
- * {@code remaining()}.
- * @exception IllegalArgumentException
- * if {@code src} is this buffer.
- * @exception ReadOnlyBufferException
- * if no changes may be made to the contents of this buffer.
- * @since Android 1.0
- */
- public IntBuffer put(IntBuffer src) {
- if (src == this) {
- throw new IllegalArgumentException();
- }
- if (src.remaining() > remaining()) {
- throw new BufferOverflowException();
- }
- int[] contents = new int[src.remaining()];
- src.get(contents);
- put(contents);
- return this;
- }
-
- /**
- * Write a int to the specified index of this buffer; the position is not
- * changed.
- *
- * @param index
- * the index, must not be negative and less than the limit.
- * @param i
- * the int to write.
- * @return this buffer.
- * @exception IndexOutOfBoundsException
- * if index is invalid.
- * @exception ReadOnlyBufferException
- * if no changes may be made to the contents of this buffer.
- * @since Android 1.0
- */
- public abstract IntBuffer put(int index, int i);
-
- /**
- * Returns a sliced buffer that shares its content with this buffer.
- *
- * The sliced buffer's capacity will be this buffer's {@code remaining()},
- * and its zero position will correspond to this buffer's current position.
- * The new buffer's position will be 0, limit will be its capacity, and its
- * mark is cleared. The new buffer's read-only property and byte order are
- * same as this buffer's.
- *
- *
- * The new buffer shares its content with this buffer, which means either
- * buffer's change of content will be visible to the other. The two buffer's
- * position, limit and mark are independent.
- *
- *
- * @return a sliced buffer that shares its content with this buffer.
- * @since Android 1.0
- */
- public abstract IntBuffer slice();
-
- /**
- * Returns a string represents of the state of this int buffer.
- *
- * @return a string represents of the state of this int buffer.
- * @since Android 1.0
- */
- public String toString() {
- StringBuffer buf = new StringBuffer();
- buf.append(getClass().getName());
- buf.append(", status: capacity="); //$NON-NLS-1$
- buf.append(capacity());
- buf.append(" position="); //$NON-NLS-1$
- buf.append(position());
- buf.append(" limit="); //$NON-NLS-1$
- buf.append(limit());
- return buf.toString();
- }
+ /** Creates an int buffer based on a newly allocated int array.
+ *
+ * @param capacity the capacity of the new buffer.
+ * @return the created int buffer.
+ * @throws IllegalArgumentException if {@code capacity} is less than zero.
+ * @since Android 1.0 */
+ public static IntBuffer allocate (int capacity) {
+ if (capacity < 0) {
+ throw new IllegalArgumentException();
+ }
+ return BufferFactory.newIntBuffer(capacity);
+ }
+
+ /** Creates a new int buffer by wrapping the given int array.
+ *
+ * Calling this method has the same effect as {@code wrap(array, 0, array.length)}.
+ *
+ *
+ * @param array the int array which the new buffer will be based on.
+ * @return the created int buffer.
+ * @since Android 1.0 */
+ public static IntBuffer wrap (int[] array) {
+ return wrap(array, 0, array.length);
+ }
+
+ /** Creates a new int buffer by wrapping the given int array.
+ *
+ * The new buffer's position will be {@code start}, limit will be {@code start + len}, capacity will be the length of the
+ * array.
+ *
+ *
+ * @param array the int array which the new buffer will be based on.
+ * @param start the start index, must not be negative and not greater than {@code array.length}
+ * @param len the length, must not be negative and not greater than {@code array.length - start}.
+ * @return the created int buffer.
+ * @exception IndexOutOfBoundsException if either {@code start} or {@code len} is invalid.
+ * @since Android 1.0 */
+ public static IntBuffer wrap (int[] array, int start, int len) {
+ if (array == null) {
+ throw new NullPointerException();
+ }
+ if (start < 0 || len < 0 || (long)len + (long)start > array.length) {
+ throw new IndexOutOfBoundsException();
+ }
+
+ IntBuffer buf = BufferFactory.newIntBuffer(array);
+ buf.position = start;
+ buf.limit = start + len;
+
+ return buf;
+ }
+
+ /** Constructs a {@code IntBuffer} with given capacity.
+ *
+ * @param capacity the capacity of the buffer. */
+ IntBuffer (int capacity) {
+ super(capacity);
+ }
+
+ /** Returns the int array which this buffer is based on, if there is one.
+ *
+ * @return the int array which this buffer is based on.
+ * @exception ReadOnlyBufferException if this buffer is based on an array, but it is read-only.
+ * @exception UnsupportedOperationException if this buffer is not based on an array.
+ * @since Android 1.0 */
+ public final int[] array () {
+ return protectedArray();
+ }
+
+ /** Returns the offset of the int array which this buffer is based on, if there is one.
+ *
+ * The offset is the index of the array corresponds to the zero position of the buffer.
+ *
+ *
+ * @return the offset of the int array which this buffer is based on.
+ * @exception ReadOnlyBufferException if this buffer is based on an array, but it is read-only.
+ * @exception UnsupportedOperationException if this buffer is not based on an array.
+ * @since Android 1.0 */
+ public final int arrayOffset () {
+ return protectedArrayOffset();
+ }
+
+ /** Returns a read-only buffer that shares its content with this buffer.
+ *
+ * The returned buffer is guaranteed to be a new instance, even this buffer is read-only itself. The new buffer's position,
+ * limit, capacity and mark are the same as this buffer's.
+ *
+ *
+ * The new buffer shares its content with this buffer, which means this buffer's change of content will be visible to the new
+ * buffer. The two buffer's position, limit and mark are independent.
+ *
+ *
+ * @return a read-only version of this buffer.
+ * @since Android 1.0 */
+ public abstract IntBuffer asReadOnlyBuffer ();
+
+ /** Compacts this int buffer.
+ *
+ * The remaining ints will be moved to the head of the buffer, starting from position zero. Then the position is set to
+ * {@code remaining()}; the limit is set to capacity; the mark is cleared.
+ *
+ *
+ * @return this buffer.
+ * @exception ReadOnlyBufferException if no changes may be made to the contents of this buffer.
+ * @since Android 1.0 */
+ public abstract IntBuffer compact ();
+
+ /** Compares the remaining ints of this buffer to another int buffer's remaining ints.
+ *
+ * @param otherBuffer another int buffer.
+ * @return a negative value if this is less than {@code other}; 0 if this equals to {@code other}; a positive value if this is
+ * greater than {@code other}.
+ * @exception ClassCastException if {@code other} is not an int buffer.
+ * @since Android 1.0 */
+ public int compareTo (IntBuffer otherBuffer) {
+ int compareRemaining = (remaining() < otherBuffer.remaining()) ? remaining() : otherBuffer.remaining();
+ int thisPos = position;
+ int otherPos = otherBuffer.position;
+ // BEGIN android-changed
+ int thisInt, otherInt;
+ while (compareRemaining > 0) {
+ thisInt = get(thisPos);
+ otherInt = otherBuffer.get(otherPos);
+ if (thisInt != otherInt) {
+ return thisInt < otherInt ? -1 : 1;
+ }
+ thisPos++;
+ otherPos++;
+ compareRemaining--;
+ }
+ // END android-changed
+ return remaining() - otherBuffer.remaining();
+ }
+
+ /** Returns a duplicated buffer that shares its content with this buffer.
+ *
+ * The duplicated buffer's position, limit, capacity and mark are the same as this buffer. The duplicated buffer's read-only
+ * property and byte order are the same as this buffer's.
+ *
+ *
+ * The new buffer shares its content with this buffer, which means either buffer's change of content will be visible to the
+ * other. The two buffer's position, limit and mark are independent.
+ *
+ *
+ * @return a duplicated buffer that shares its content with this buffer.
+ * @since Android 1.0 */
+ public abstract IntBuffer duplicate ();
+
+ /** Checks whether this int buffer is equal to another object.
+ *
+ * If {@code other} is not a int buffer then {@code false} is returned. Two int buffers are equal if and only if their
+ * remaining ints are exactly the same. Position, limit, capacity and mark are not considered.
+ *
+ *
+ * @param other the object to compare with this int buffer.
+ * @return {@code true} if this int buffer is equal to {@code other}, {@code false} otherwise.
+ * @since Android 1.0 */
+ public boolean equals (Object other) {
+ if (!(other instanceof IntBuffer)) {
+ return false;
+ }
+ IntBuffer otherBuffer = (IntBuffer)other;
+
+ if (remaining() != otherBuffer.remaining()) {
+ return false;
+ }
+
+ int myPosition = position;
+ int otherPosition = otherBuffer.position;
+ boolean equalSoFar = true;
+ while (equalSoFar && (myPosition < limit)) {
+ equalSoFar = get(myPosition++) == otherBuffer.get(otherPosition++);
+ }
+
+ return equalSoFar;
+ }
+
+ /** Returns the int at the current position and increases the position by 1.
+ *
+ * @return the int at the current position.
+ * @exception BufferUnderflowException if the position is equal or greater than limit.
+ * @since Android 1.0 */
+ public abstract int get ();
+
+ /** Reads ints from the current position into the specified int array and increases the position by the number of ints read.
+ *
+ * Calling this method has the same effect as {@code get(dest, 0, dest.length)}.
+ *
+ *
+ * @param dest the destination int array.
+ * @return this buffer.
+ * @exception BufferUnderflowException if {@code dest.length} is greater than {@code remaining()}.
+ * @since Android 1.0 */
+ public IntBuffer get (int[] dest) {
+ return get(dest, 0, dest.length);
+ }
+
+ /** Reads ints from the current position into the specified int array, starting from the specified offset, and increases the
+ * position by the number of ints read.
+ *
+ * @param dest the target int array.
+ * @param off the offset of the int array, must not be negative and not greater than {@code dest.length}.
+ * @param len the number of ints to read, must be no less than zero and not greater than {@code dest.length - off}.
+ * @return this buffer.
+ * @exception IndexOutOfBoundsException if either {@code off} or {@code len} is invalid.
+ * @exception BufferUnderflowException if {@code len} is greater than {@code remaining()}.
+ * @since Android 1.0 */
+ public IntBuffer get (int[] dest, int off, int len) {
+ int length = dest.length;
+ if (off < 0 || len < 0 || (long)len + (long)off > length) {
+ throw new IndexOutOfBoundsException();
+ }
+ if (len > remaining()) {
+ throw new BufferUnderflowException();
+ }
+ for (int i = off; i < off + len; i++) {
+ dest[i] = get();
+ }
+ return this;
+ }
+
+ /** Returns an int at the specified index; the position is not changed.
+ *
+ * @param index the index, must not be negative and less than limit.
+ * @return an int at the specified index.
+ * @exception IndexOutOfBoundsException if index is invalid.
+ * @since Android 1.0 */
+ public abstract int get (int index);
+
+ /** Indicates whether this buffer is based on a int array and is read/write.
+ *
+ * @return {@code true} if this buffer is based on a int array and provides read/write access, {@code false} otherwise.
+ * @since Android 1.0 */
+ public final boolean hasArray () {
+ return protectedHasArray();
+ }
+
+ /** Calculates this buffer's hash code from the remaining chars. The position, limit, capacity and mark don't affect the hash
+ * code.
+ *
+ * @return the hash code calculated from the remaining ints.
+ * @since Android 1.0 */
+ public int hashCode () {
+ int myPosition = position;
+ int hash = 0;
+ while (myPosition < limit) {
+ hash = hash + get(myPosition++);
+ }
+ return hash;
+ }
+
+ /** Indicates whether this buffer is direct. A direct buffer will try its best to take advantage of native memory APIs and it
+ * may not stay in the Java heap, so it is not affected by garbage collection.
+ *
+ * An int buffer is direct if it is based on a byte buffer and the byte buffer is direct.
+ *
+ *
+ * @return {@code true} if this buffer is direct, {@code false} otherwise.
+ * @since Android 1.0 */
+ public abstract boolean isDirect ();
+
+ /** Returns the byte order used by this buffer when converting ints from/to bytes.
+ *
+ * If this buffer is not based on a byte buffer, then always return the platform's native byte order.
+ *
+ *
+ * @return the byte order used by this buffer when converting ints from/to bytes.
+ * @since Android 1.0 */
+ public abstract ByteOrder order ();
+
+ /** Child class implements this method to realize {@code array()}.
+ *
+ * @return see {@code array()} */
+ protected abstract int[] protectedArray ();
+
+ /** Child class implements this method to realize {@code arrayOffset()}.
+ *
+ * @return see {@code arrayOffset()} */
+ protected abstract int protectedArrayOffset ();
+
+ /** Child class implements this method to realize {@code hasArray()}.
+ *
+ * @return see {@code hasArray()} */
+ protected abstract boolean protectedHasArray ();
+
+ /** Writes the given int to the current position and increases the position by 1.
+ *
+ * @param i the int to write.
+ * @return this buffer.
+ * @exception BufferOverflowException if position is equal or greater than limit.
+ * @exception ReadOnlyBufferException if no changes may be made to the contents of this buffer.
+ * @since Android 1.0 */
+ public abstract IntBuffer put (int i);
+
+ /** Writes ints from the given int array to the current position and increases the position by the number of ints written.
+ *
+ * Calling this method has the same effect as {@code put(src, 0, src.length)}.
+ *
+ *
+ * @param src the source int array.
+ * @return this buffer.
+ * @exception BufferOverflowException if {@code remaining()} is less than {@code src.length}.
+ * @exception ReadOnlyBufferException if no changes may be made to the contents of this buffer.
+ * @since Android 1.0 */
+ public final IntBuffer put (int[] src) {
+ return put(src, 0, src.length);
+ }
+
+ /** Writes ints from the given int array, starting from the specified offset, to the current position and increases the position
+ * by the number of ints written.
+ *
+ * @param src the source int array.
+ * @param off the offset of int array, must not be negative and not greater than {@code src.length}.
+ * @param len the number of ints to write, must be no less than zero and not greater than {@code src.length - off}.
+ * @return this buffer.
+ * @exception BufferOverflowException if {@code remaining()} is less than {@code len}.
+ * @exception IndexOutOfBoundsException if either {@code off} or {@code len} is invalid.
+ * @exception ReadOnlyBufferException if no changes may be made to the contents of this buffer.
+ * @since Android 1.0 */
+ public IntBuffer put (int[] src, int off, int len) {
+ int length = src.length;
+ if (off < 0 || len < 0 || (long)len + (long)off > length) {
+ throw new IndexOutOfBoundsException();
+ }
+
+ if (len > remaining()) {
+ throw new BufferOverflowException();
+ }
+ for (int i = off; i < off + len; i++) {
+ put(src[i]);
+ }
+ return this;
+ }
+
+ /** Writes all the remaining ints of the {@code src} int buffer to this buffer's current position, and increases both buffers'
+ * position by the number of ints copied.
+ *
+ * @param src the source int buffer.
+ * @return this buffer.
+ * @exception BufferOverflowException if {@code src.remaining()} is greater than this buffer's {@code remaining()}.
+ * @exception IllegalArgumentException if {@code src} is this buffer.
+ * @exception ReadOnlyBufferException if no changes may be made to the contents of this buffer.
+ * @since Android 1.0 */
+ public IntBuffer put (IntBuffer src) {
+ if (src == this) {
+ throw new IllegalArgumentException();
+ }
+ if (src.remaining() > remaining()) {
+ throw new BufferOverflowException();
+ }
+ int[] contents = new int[src.remaining()];
+ src.get(contents);
+ put(contents);
+ return this;
+ }
+
+ /** Write a int to the specified index of this buffer; the position is not changed.
+ *
+ * @param index the index, must not be negative and less than the limit.
+ * @param i the int to write.
+ * @return this buffer.
+ * @exception IndexOutOfBoundsException if index is invalid.
+ * @exception ReadOnlyBufferException if no changes may be made to the contents of this buffer.
+ * @since Android 1.0 */
+ public abstract IntBuffer put (int index, int i);
+
+ /** Returns a sliced buffer that shares its content with this buffer.
+ *
+ * The sliced buffer's capacity will be this buffer's {@code remaining()}, and its zero position will correspond to this
+ * buffer's current position. The new buffer's position will be 0, limit will be its capacity, and its mark is cleared. The new
+ * buffer's read-only property and byte order are same as this buffer's.
+ *
+ *
+ * The new buffer shares its content with this buffer, which means either buffer's change of content will be visible to the
+ * other. The two buffer's position, limit and mark are independent.
+ *
+ *
+ * @return a sliced buffer that shares its content with this buffer.
+ * @since Android 1.0 */
+ public abstract IntBuffer slice ();
+
+ /** Returns a string represents of the state of this int buffer.
+ *
+ * @return a string represents of the state of this int buffer.
+ * @since Android 1.0 */
+ public String toString () {
+ StringBuffer buf = new StringBuffer();
+ buf.append(getClass().getName());
+ buf.append(", status: capacity="); //$NON-NLS-1$
+ buf.append(capacity());
+ buf.append(" position="); //$NON-NLS-1$
+ buf.append(position());
+ buf.append(" limit="); //$NON-NLS-1$
+ buf.append(limit());
+ return buf.toString();
+ }
}
diff --git a/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/java/nio/IntToByteBufferAdapter.java b/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/java/nio/IntToByteBufferAdapter.java
index 98faca97e1c..f2151ff5e77 100644
--- a/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/java/nio/IntToByteBufferAdapter.java
+++ b/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/java/nio/IntToByteBufferAdapter.java
@@ -16,195 +16,189 @@
package java.nio;
-
//import org.apache.harmony.nio.internal.DirectBuffer;
//import org.apache.harmony.luni.platform.PlatformAddress;
-/**
- * This class wraps a byte buffer to be a int buffer.
+/** This class wraps a byte buffer to be a int buffer.
*
* Implementation notice:
*
- * After a byte buffer instance is wrapped, it becomes privately owned by
- * the adapter. It must NOT be accessed outside the adapter any more.
- * The byte buffer's position and limit are NOT linked with the adapter.
- * The adapter extends Buffer, thus has its own position and limit.
+ * After a byte buffer instance is wrapped, it becomes privately owned by the adapter. It must NOT be accessed outside the
+ * adapter any more.
+ * The byte buffer's position and limit are NOT linked with the adapter. The adapter extends Buffer, thus has its own position
+ * and limit.
*
- *
- *
- */
+ * */
final class IntToByteBufferAdapter extends IntBuffer implements ByteBufferWrapper {
-//implements DirectBuffer {
-
- static IntBuffer wrap(ByteBuffer byteBuffer) {
- return new IntToByteBufferAdapter(byteBuffer.slice());
- }
-
- private final ByteBuffer byteBuffer;
-
- IntToByteBufferAdapter(ByteBuffer byteBuffer) {
- super((byteBuffer.capacity() >> 2));
- this.byteBuffer = byteBuffer;
- this.byteBuffer.clear();
- }
-
-// public int getByteCapacity() {
-// if (byteBuffer instanceof DirectBuffer) {
-// return ((DirectBuffer) byteBuffer).getByteCapacity();
-// }
-// assert false : byteBuffer;
-// return -1;
-// }
+// implements DirectBuffer {
+
+ static IntBuffer wrap (ByteBuffer byteBuffer) {
+ return new IntToByteBufferAdapter(byteBuffer.slice());
+ }
+
+ private final ByteBuffer byteBuffer;
+
+ IntToByteBufferAdapter (ByteBuffer byteBuffer) {
+ super((byteBuffer.capacity() >> 2));
+ this.byteBuffer = byteBuffer;
+ this.byteBuffer.clear();
+ }
+
+// public int getByteCapacity() {
+// if (byteBuffer instanceof DirectBuffer) {
+// return ((DirectBuffer) byteBuffer).getByteCapacity();
+// }
+// assert false : byteBuffer;
+// return -1;
+// }
//
-// public PlatformAddress getEffectiveAddress() {
-// if (byteBuffer instanceof DirectBuffer) {
-// return ((DirectBuffer) byteBuffer).getEffectiveAddress();
-// }
-// assert false : byteBuffer;
-// return null;
-// }
+// public PlatformAddress getEffectiveAddress() {
+// if (byteBuffer instanceof DirectBuffer) {
+// return ((DirectBuffer) byteBuffer).getEffectiveAddress();
+// }
+// assert false : byteBuffer;
+// return null;
+// }
//
-// public PlatformAddress getBaseAddress() {
-// if (byteBuffer instanceof DirectBuffer) {
-// return ((DirectBuffer) byteBuffer).getBaseAddress();
-// }
-// assert false : byteBuffer;
-// return null;
-// }
+// public PlatformAddress getBaseAddress() {
+// if (byteBuffer instanceof DirectBuffer) {
+// return ((DirectBuffer) byteBuffer).getBaseAddress();
+// }
+// assert false : byteBuffer;
+// return null;
+// }
//
-// public boolean isAddressValid() {
-// if (byteBuffer instanceof DirectBuffer) {
-// return ((DirectBuffer) byteBuffer).isAddressValid();
-// }
-// assert false : byteBuffer;
-// return false;
-// }
+// public boolean isAddressValid() {
+// if (byteBuffer instanceof DirectBuffer) {
+// return ((DirectBuffer) byteBuffer).isAddressValid();
+// }
+// assert false : byteBuffer;
+// return false;
+// }
//
-// public void addressValidityCheck() {
-// if (byteBuffer instanceof DirectBuffer) {
-// ((DirectBuffer) byteBuffer).addressValidityCheck();
-// } else {
-// assert false : byteBuffer;
-// }
-// }
+// public void addressValidityCheck() {
+// if (byteBuffer instanceof DirectBuffer) {
+// ((DirectBuffer) byteBuffer).addressValidityCheck();
+// } else {
+// assert false : byteBuffer;
+// }
+// }
//
-// public void free() {
-// if (byteBuffer instanceof DirectBuffer) {
-// ((DirectBuffer) byteBuffer).free();
-// } else {
-// assert false : byteBuffer;
-// }
-// }
-
- @Override
- public IntBuffer asReadOnlyBuffer() {
- IntToByteBufferAdapter buf = new IntToByteBufferAdapter(byteBuffer
- .asReadOnlyBuffer());
- buf.limit = limit;
- buf.position = position;
- buf.mark = mark;
- return buf;
- }
-
- @Override
- public IntBuffer compact() {
- if (byteBuffer.isReadOnly()) {
- throw new ReadOnlyBufferException();
- }
- byteBuffer.limit(limit << 2);
- byteBuffer.position(position << 2);
- byteBuffer.compact();
- byteBuffer.clear();
- position = limit - position;
- limit = capacity;
- mark = UNSET_MARK;
- return this;
- }
-
- @Override
- public IntBuffer duplicate() {
- IntToByteBufferAdapter buf = new IntToByteBufferAdapter(byteBuffer
- .duplicate());
- buf.limit = limit;
- buf.position = position;
- buf.mark = mark;
- return buf;
- }
-
- @Override
- public int get() {
- if (position == limit) {
- throw new BufferUnderflowException();
- }
- return byteBuffer.getInt(position++ << 2);
- }
-
- @Override
- public int get(int index) {
- if (index < 0 || index >= limit) {
- throw new IndexOutOfBoundsException();
- }
- return byteBuffer.getInt(index << 2);
- }
-
- @Override
- public boolean isDirect() {
- return byteBuffer.isDirect();
- }
-
- @Override
- public boolean isReadOnly() {
- return byteBuffer.isReadOnly();
- }
-
- @Override
- public ByteOrder order() {
- return byteBuffer.order();
- }
-
- @Override
- protected int[] protectedArray() {
- throw new UnsupportedOperationException();
- }
-
- @Override
- protected int protectedArrayOffset() {
- throw new UnsupportedOperationException();
- }
-
- @Override
- protected boolean protectedHasArray() {
- return false;
- }
-
- @Override
- public IntBuffer put(int c) {
- if (position == limit) {
- throw new BufferOverflowException();
- }
- byteBuffer.putInt(position++ << 2, c);
- return this;
- }
-
- @Override
- public IntBuffer put(int index, int c) {
- if (index < 0 || index >= limit) {
- throw new IndexOutOfBoundsException();
- }
- byteBuffer.putInt(index << 2, c);
- return this;
- }
-
- @Override
- public IntBuffer slice() {
- byteBuffer.limit(limit << 2);
- byteBuffer.position(position << 2);
- IntBuffer result = new IntToByteBufferAdapter(byteBuffer.slice());
- byteBuffer.clear();
- return result;
- }
-
- public ByteBuffer getByteBuffer() {
+// public void free() {
+// if (byteBuffer instanceof DirectBuffer) {
+// ((DirectBuffer) byteBuffer).free();
+// } else {
+// assert false : byteBuffer;
+// }
+// }
+
+ @Override
+ public IntBuffer asReadOnlyBuffer () {
+ IntToByteBufferAdapter buf = new IntToByteBufferAdapter(byteBuffer.asReadOnlyBuffer());
+ buf.limit = limit;
+ buf.position = position;
+ buf.mark = mark;
+ return buf;
+ }
+
+ @Override
+ public IntBuffer compact () {
+ if (byteBuffer.isReadOnly()) {
+ throw new ReadOnlyBufferException();
+ }
+ byteBuffer.limit(limit << 2);
+ byteBuffer.position(position << 2);
+ byteBuffer.compact();
+ byteBuffer.clear();
+ position = limit - position;
+ limit = capacity;
+ mark = UNSET_MARK;
+ return this;
+ }
+
+ @Override
+ public IntBuffer duplicate () {
+ IntToByteBufferAdapter buf = new IntToByteBufferAdapter(byteBuffer.duplicate());
+ buf.limit = limit;
+ buf.position = position;
+ buf.mark = mark;
+ return buf;
+ }
+
+ @Override
+ public int get () {
+ if (position == limit) {
+ throw new BufferUnderflowException();
+ }
+ return byteBuffer.getInt(position++ << 2);
+ }
+
+ @Override
+ public int get (int index) {
+ if (index < 0 || index >= limit) {
+ throw new IndexOutOfBoundsException();
+ }
+ return byteBuffer.getInt(index << 2);
+ }
+
+ @Override
+ public boolean isDirect () {
+ return byteBuffer.isDirect();
+ }
+
+ @Override
+ public boolean isReadOnly () {
+ return byteBuffer.isReadOnly();
+ }
+
+ @Override
+ public ByteOrder order () {
+ return byteBuffer.order();
+ }
+
+ @Override
+ protected int[] protectedArray () {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ protected int protectedArrayOffset () {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ protected boolean protectedHasArray () {
+ return false;
+ }
+
+ @Override
+ public IntBuffer put (int c) {
+ if (position == limit) {
+ throw new BufferOverflowException();
+ }
+ byteBuffer.putInt(position++ << 2, c);
+ return this;
+ }
+
+ @Override
+ public IntBuffer put (int index, int c) {
+ if (index < 0 || index >= limit) {
+ throw new IndexOutOfBoundsException();
+ }
+ byteBuffer.putInt(index << 2, c);
+ return this;
+ }
+
+ @Override
+ public IntBuffer slice () {
+ byteBuffer.limit(limit << 2);
+ byteBuffer.position(position << 2);
+ IntBuffer result = new IntToByteBufferAdapter(byteBuffer.slice());
+ byteBuffer.clear();
+ return result;
+ }
+
+ public ByteBuffer getByteBuffer () {
return byteBuffer;
}
diff --git a/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/java/nio/InvalidMarkException.java b/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/java/nio/InvalidMarkException.java
index 530d9cfad00..a523dc5bcb4 100644
--- a/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/java/nio/InvalidMarkException.java
+++ b/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/java/nio/InvalidMarkException.java
@@ -16,23 +16,17 @@
package java.nio;
-
-/**
- * An {@code InvalidMarkException} is thrown when {@code reset()} is called on a
- * buffer, but no mark has been set previously.
+/** An {@code InvalidMarkException} is thrown when {@code reset()} is called on a buffer, but no mark has been set previously.
*
- * @since Android 1.0
- */
+ * @since Android 1.0 */
public class InvalidMarkException extends IllegalStateException {
- private static final long serialVersionUID = 1698329710438510774L;
+ private static final long serialVersionUID = 1698329710438510774L;
- /**
- * Constructs an {@code InvalidMarkException}.
- *
- * @since Android 1.0
- */
- public InvalidMarkException() {
- super();
- }
+ /** Constructs an {@code InvalidMarkException}.
+ *
+ * @since Android 1.0 */
+ public InvalidMarkException () {
+ super();
+ }
}
diff --git a/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/java/nio/LongArrayBuffer.java b/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/java/nio/LongArrayBuffer.java
index efd259cc0fa..73c9be06a78 100644
--- a/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/java/nio/LongArrayBuffer.java
+++ b/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/java/nio/LongArrayBuffer.java
@@ -17,71 +17,66 @@
package java.nio;
-/**
- * LongArrayBuffer, ReadWriteLongArrayBuffer and ReadOnlyLongArrayBuffer compose
- * the implementation of array based long buffers.
+/** LongArrayBuffer, ReadWriteLongArrayBuffer and ReadOnlyLongArrayBuffer compose the implementation of array based long buffers.
*
- * LongArrayBuffer implements all the shared readonly methods and is extended by
- * the other two classes.
+ * LongArrayBuffer implements all the shared readonly methods and is extended by the other two classes.
*
*
* All methods are marked final for runtime performance.
- *
- *
- */
+ * */
abstract class LongArrayBuffer extends LongBuffer {
- protected final long[] backingArray;
+ protected final long[] backingArray;
+
+ protected final int offset;
- protected final int offset;
+ LongArrayBuffer (long[] array) {
+ this(array.length, array, 0);
+ }
- LongArrayBuffer(long[] array) {
- this(array.length, array, 0);
- }
+ LongArrayBuffer (int capacity) {
+ this(capacity, new long[capacity], 0);
+ }
- LongArrayBuffer(int capacity) {
- this(capacity, new long[capacity], 0);
- }
+ LongArrayBuffer (int capacity, long[] backingArray, int offset) {
+ super(capacity);
+ this.backingArray = backingArray;
+ this.offset = offset;
+ }
- LongArrayBuffer(int capacity, long[] backingArray, int offset) {
- super(capacity);
- this.backingArray = backingArray;
- this.offset = offset;
- }
+ public final long get () {
+ if (position == limit) {
+ throw new BufferUnderflowException();
+ }
+ return backingArray[offset + position++];
+ }
- public final long get() {
- if (position == limit) {
- throw new BufferUnderflowException();
- }
- return backingArray[offset + position++];
- }
+ public final long get (int index) {
+ if (index < 0 || index >= limit) {
+ throw new IndexOutOfBoundsException();
+ }
+ return backingArray[offset + index];
+ }
- public final long get(int index) {
- if (index < 0 || index >= limit) {
- throw new IndexOutOfBoundsException();
- }
- return backingArray[offset + index];
- }
+ public final LongBuffer get (long[] dest, int off, int len) {
+ int length = dest.length;
+ if (off < 0 || len < 0 || (long)len + (long)off > length) {
+ throw new IndexOutOfBoundsException();
+ }
+ if (len > remaining()) {
+ throw new BufferUnderflowException();
+ }
+ System.arraycopy(backingArray, offset + position, dest, off, len);
+ position += len;
+ return this;
+ }
- public final LongBuffer get(long[] dest, int off, int len) {
- int length = dest.length;
- if (off < 0 || len < 0 || (long)len + (long)off > length) {
- throw new IndexOutOfBoundsException();
- }
- if (len > remaining()) {
- throw new BufferUnderflowException();
- }
- System.arraycopy(backingArray, offset+position, dest, off, len);
- position += len;
- return this;
- }
-
- public final boolean isDirect() {
- return false;
- }
+ public final boolean isDirect () {
+ return false;
+ }
- public final ByteOrder order() {
- return ByteOrder.nativeOrder();
- }
+ public final ByteOrder order () {
+ return ByteOrder.nativeOrder();
+ }
}
diff --git a/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/java/nio/LongBuffer.java b/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/java/nio/LongBuffer.java
index 022db5bfeec..97a8a12be15 100644
--- a/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/java/nio/LongBuffer.java
+++ b/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/java/nio/LongBuffer.java
@@ -17,563 +17,416 @@
package java.nio;
-/**
- * A buffer of longs.
+/** A buffer of longs.
*
* A long buffer can be created in either of the following ways:
*
*
- * {@link #allocate(int) Allocate} a new long array and create a buffer
- * based on it;
- * {@link #wrap(long[]) Wrap} an existing long array to create a new
- * buffer;
- * Use {@link java.nio.ByteBuffer#asLongBuffer() ByteBuffer.asLongBuffer}
- * to create a long buffer based on a byte buffer.
+ * {@link #allocate(int) Allocate} a new long array and create a buffer based on it;
+ * {@link #wrap(long[]) Wrap} an existing long array to create a new buffer;
+ * Use {@link java.nio.ByteBuffer#asLongBuffer() ByteBuffer.asLongBuffer} to create a long buffer based on a byte buffer.
*
*
- * @since Android 1.0
- */
+ * @since Android 1.0 */
public abstract class LongBuffer extends Buffer implements Comparable {
- /**
- * Creates a long buffer based on a newly allocated long array.
- *
- * @param capacity
- * the capacity of the new buffer.
- * @return the created long buffer.
- * @throws IllegalArgumentException
- * if {@code capacity} is less than zero.
- * @since Android 1.0
- */
- public static LongBuffer allocate(int capacity) {
- if (capacity < 0) {
- throw new IllegalArgumentException();
- }
- return BufferFactory.newLongBuffer(capacity);
- }
-
- /**
- * Creates a new long buffer by wrapping the given long array.
- *
- * Calling this method has the same effect as
- * {@code wrap(array, 0, array.length)}.
- *
- *
- * @param array
- * the long array which the new buffer will be based on.
- * @return the created long buffer.
- * @since Android 1.0
- */
- public static LongBuffer wrap(long[] array) {
- return wrap(array, 0, array.length);
- }
-
- /**
- * Creates a new long buffer by wrapping the given long array.
- *
- * The new buffer's position will be {@code start}, limit will be
- * {@code start + len}, capacity will be the length of the array.
- *
- *
- * @param array
- * the long array which the new buffer will be based on.
- * @param start
- * the start index, must not be negative and not greater than
- * {@code array.length}.
- * @param len
- * the length, must not be negative and not greater than
- * {@code array.length - start}.
- * @return the created long buffer.
- * @exception IndexOutOfBoundsException
- * if either {@code start} or {@code len} is invalid.
- * @since Android 1.0
- */
- public static LongBuffer wrap(long[] array, int start, int len) {
- if (array == null) {
- throw new NullPointerException();
- }
- if (start < 0 || len < 0 || (long)len + (long)start > array.length) {
- throw new IndexOutOfBoundsException();
- }
-
- LongBuffer buf = BufferFactory.newLongBuffer(array);
- buf.position = start;
- buf.limit = start + len;
-
- return buf;
- }
-
- /**
- * Constructs a {@code LongBuffer} with given capacity.
- *
- * @param capacity
- * The capacity of the buffer
- */
- LongBuffer(int capacity) {
- super(capacity);
- }
-
- /**
- * Returns the long array which this buffer is based on, if there is one.
- *
- * @return the long array which this buffer is based on.
- * @exception ReadOnlyBufferException
- * if this buffer is based on an array, but it is read-only.
- * @exception UnsupportedOperationException
- * if this buffer is not based on an array.
- * @since Android 1.0
- */
- public final long[] array() {
- return protectedArray();
- }
-
- /**
- * Returns the offset of the long array which this buffer is based on, if
- * there is one.
- *
- * The offset is the index of the array and corresponds to the zero position
- * of the buffer.
- *
- *
- * @return the offset of the long array which this buffer is based on.
- * @exception ReadOnlyBufferException
- * if this buffer is based on an array, but it is read-only.
- * @exception UnsupportedOperationException
- * if this buffer is not based on an array.
- * @since Android 1.0
- */
- public final int arrayOffset() {
- return protectedArrayOffset();
- }
-
- /**
- * Returns a read-only buffer that shares its content with this buffer.
- *
- * The returned buffer is guaranteed to be a new instance, even if this
- * buffer is read-only itself. The new buffer's position, limit, capacity
- * and mark are the same as this buffer's.
- *
- *
- * The new buffer shares its content with this buffer, which means this
- * buffer's change of content will be visible to the new buffer. The two
- * buffer's position, limit and mark are independent.
- *
- *
- * @return a read-only version of this buffer.
- * @since Android 1.0
- */
- public abstract LongBuffer asReadOnlyBuffer();
-
- /**
- * Compacts this long buffer.
- *
- * The remaining longs will be moved to the head of the buffer, staring from
- * position zero. Then the position is set to {@code remaining()}; the
- * limit is set to capacity; the mark is cleared.
- *
- *
- * @return this buffer.
- * @exception ReadOnlyBufferException
- * if no changes may be made to the contents of this buffer.
- * @since Android 1.0
- */
- public abstract LongBuffer compact();
-
- /**
- * Compare the remaining longs of this buffer to another long buffer's
- * remaining longs.
- *
- * @param otherBuffer
- * another long buffer.
- * @return a negative value if this is less than {@code otherBuffer}; 0 if
- * this equals to {@code otherBuffer}; a positive value if this is
- * greater than {@code otherBuffer}
- * @exception ClassCastException
- * if {@code otherBuffer} is not a long buffer.
- * @since Android 1.0
- */
- public int compareTo(LongBuffer otherBuffer) {
- int compareRemaining = (remaining() < otherBuffer.remaining()) ? remaining()
- : otherBuffer.remaining();
- int thisPos = position;
- int otherPos = otherBuffer.position;
- // BEGIN android-changed
- long thisLong, otherLong;
- while (compareRemaining > 0) {
- thisLong = get(thisPos);
- otherLong = otherBuffer.get(otherPos);
- if (thisLong != otherLong) {
- return thisLong < otherLong ? -1 : 1;
- }
- thisPos++;
- otherPos++;
- compareRemaining--;
- }
- // END android-changed
- return remaining() - otherBuffer.remaining();
- }
-
- /**
- * Returns a duplicated buffer that shares its content with this buffer.
- *
- * The duplicated buffer's position, limit, capacity and mark are the same
- * as this buffer. The duplicated buffer's read-only property and byte order
- * are same as this buffer's, too.
- *
- *
- * The new buffer shares its content with this buffer, which means either
- * buffer's change of content will be visible to the other. The two buffer's
- * position, limit and mark are independent.
- *
- *
- * @return a duplicated buffer that shares its content with this buffer.
- * @since Android 1.0
- */
- public abstract LongBuffer duplicate();
-
- /**
- * Checks whether this long buffer is equal to another object.
- *
- * If {@code other} is not a long buffer then {@code false} is returned. Two
- * long buffers are equal if and only if their remaining longs are exactly
- * the same. Position, limit, capacity and mark are not considered.
- *
- *
- * @param other
- * the object to compare with this long buffer.
- * @return {@code true} if this long buffer is equal to {@code other},
- * {@code false} otherwise.
- * @since Android 1.0
- */
- public boolean equals(Object other) {
- if (!(other instanceof LongBuffer)) {
- return false;
- }
- LongBuffer otherBuffer = (LongBuffer) other;
-
- if (remaining() != otherBuffer.remaining()) {
- return false;
- }
-
- int myPosition = position;
- int otherPosition = otherBuffer.position;
- boolean equalSoFar = true;
- while (equalSoFar && (myPosition < limit)) {
- equalSoFar = get(myPosition++) == otherBuffer.get(otherPosition++);
- }
-
- return equalSoFar;
- }
-
- /**
- * Returns the long at the current position and increase the position by 1.
- *
- * @return the long at the current position.
- * @exception BufferUnderflowException
- * if the position is equal or greater than limit.
- * @since Android 1.0
- */
- public abstract long get();
-
- /**
- * Reads longs from the current position into the specified long array and
- * increases the position by the number of longs read.
- *
- * Calling this method has the same effect as
- * {@code get(dest, 0, dest.length)}.
- *
- *
- * @param dest
- * the destination long array.
- * @return this buffer.
- * @exception BufferUnderflowException
- * if {@code dest.length} is greater than {@code remaining()}.
- * @since Android 1.0
- */
- public LongBuffer get(long[] dest) {
- return get(dest, 0, dest.length);
- }
-
- /**
- * Reads longs from the current position into the specified long array,
- * starting from the specified offset, and increase the position by the
- * number of longs read.
- *
- * @param dest
- * the target long array.
- * @param off
- * the offset of the long array, must not be negative and not
- * greater than {@code dest.length}.
- * @param len
- * the number of longs to read, must be no less than zero and not
- * greater than {@code dest.length - off}.
- * @return this buffer.
- * @exception IndexOutOfBoundsException
- * if either {@code off} or {@code len} is invalid.
- * @exception BufferUnderflowException
- * if {@code len} is greater than {@code remaining()}.
- * @since Android 1.0
- */
- public LongBuffer get(long[] dest, int off, int len) {
- int length = dest.length;
- if (off < 0 || len < 0 || (long)len + (long)off > length) {
- throw new IndexOutOfBoundsException();
- }
-
- if (len > remaining()) {
- throw new BufferUnderflowException();
- }
- for (int i = off; i < off + len; i++) {
- dest[i] = get();
- }
- return this;
- }
-
- /**
- * Returns the long at the specified index; the position is not changed.
- *
- * @param index
- * the index, must not be negative and less than limit.
- * @return the long at the specified index.
- * @exception IndexOutOfBoundsException
- * if index is invalid.
- * @since Android 1.0
- */
- public abstract long get(int index);
-
- /**
- * Indicates whether this buffer is based on a long array and is read/write.
- *
- * @return {@code true} if this buffer is based on a long array and provides
- * read/write access, {@code false} otherwise.
- * @since Android 1.0
- */
- public final boolean hasArray() {
- return protectedHasArray();
- }
-
- /**
- * Calculates this buffer's hash code from the remaining chars. The
- * position, limit, capacity and mark don't affect the hash code.
- *
- * @return the hash code calculated from the remaining longs.
- * @since Android 1.0
- */
- public int hashCode() {
- int myPosition = position;
- int hash = 0;
- long l;
- while (myPosition < limit) {
- l = get(myPosition++);
- hash = hash + ((int) l) ^ ((int) (l >> 32));
- }
- return hash;
- }
-
- /**
- * Indicates whether this buffer is direct. A direct buffer will try its
- * best to take advantage of native memory APIs and it may not stay in the
- * Java heap, so it is not affected by garbage collection.
- *
- * A long buffer is direct if it is based on a byte buffer and the byte
- * buffer is direct.
- *
- *
- * @return {@code true} if this buffer is direct, {@code false} otherwise.
- * @since Android 1.0
- */
- public abstract boolean isDirect();
-
- /**
- * Returns the byte order used by this buffer when converting longs from/to
- * bytes.
- *
- * If this buffer is not based on a byte buffer, then always return the
- * platform's native byte order.
- *
- *
- * @return the byte order used by this buffer when converting longs from/to
- * bytes.
- * @since Android 1.0
- */
- public abstract ByteOrder order();
-
- /**
- * Child class implements this method to realize {@code array()}.
- *
- * @return see {@code array()}
- */
- abstract long[] protectedArray();
-
- /**
- * Child class implements this method to realize {@code arrayOffset()}.
- *
- * @return see {@code arrayOffset()}
- */
- abstract int protectedArrayOffset();
-
- /**
- * Child class implements this method to realize {@code hasArray()}.
- *
- * @return see {@code hasArray()}
- */
- abstract boolean protectedHasArray();
-
- /**
- * Writes the given long to the current position and increases the position
- * by 1.
- *
- * @param l
- * the long to write.
- * @return this buffer.
- * @exception BufferOverflowException
- * if position is equal or greater than limit.
- * @exception ReadOnlyBufferException
- * if no changes may be made to the contents of this buffer.
- * @since Android 1.0
- */
- public abstract LongBuffer put(long l);
-
- /**
- * Writes longs from the given long array to the current position and
- * increases the position by the number of longs written.
- *
- * Calling this method has the same effect as
- * {@code put(src, 0, src.length)}.
- *
- *
- * @param src
- * the source long array.
- * @return this buffer.
- * @exception BufferOverflowException
- * if {@code remaining()} is less than {@code src.length}.
- * @exception ReadOnlyBufferException
- * if no changes may be made to the contents of this buffer.
- * @since Android 1.0
- */
- public final LongBuffer put(long[] src) {
- return put(src, 0, src.length);
- }
-
- /**
- * Writes longs from the given long array, starting from the specified
- * offset, to the current position and increases the position by the number
- * of longs written.
- *
- * @param src
- * the source long array.
- * @param off
- * the offset of long array, must not be negative and not greater
- * than {@code src.length}.
- * @param len
- * the number of longs to write, must be no less than zero and
- * not greater than {@code src.length - off}.
- * @return this buffer.
- * @exception BufferOverflowException
- * if {@code remaining()} is less than {@code len}.
- * @exception IndexOutOfBoundsException
- * if either {@code off} or {@code len} is invalid.
- * @exception ReadOnlyBufferException
- * if no changes may be made to the contents of this buffer.
- * @since Android 1.0
- */
- public LongBuffer put(long[] src, int off, int len) {
- int length = src.length;
- if (off < 0 || len < 0 || (long)len + (long)off > length) {
- throw new IndexOutOfBoundsException();
- }
-
- if (len > remaining()) {
- throw new BufferOverflowException();
- }
- for (int i = off; i < off + len; i++) {
- put(src[i]);
- }
- return this;
- }
-
- /**
- * Writes all the remaining longs of the {@code src} long buffer to this
- * buffer's current position, and increases both buffers' position by the
- * number of longs copied.
- *
- * @param src
- * the source long buffer.
- * @return this buffer.
- * @exception BufferOverflowException
- * if {@code src.remaining()} is greater than this buffer's
- * {@code remaining()}.
- * @exception IllegalArgumentException
- * if {@code src} is this buffer.
- * @exception ReadOnlyBufferException
- * if no changes may be made to the contents of this buffer.
- * @since Android 1.0
- */
- public LongBuffer put(LongBuffer src) {
- if (src == this) {
- throw new IllegalArgumentException();
- }
- if (src.remaining() > remaining()) {
- throw new BufferOverflowException();
- }
- long[] contents = new long[src.remaining()];
- src.get(contents);
- put(contents);
- return this;
- }
-
- /**
- * Writes a long to the specified index of this buffer; the position is not
- * changed.
- *
- * @param index
- * the index, must not be negative and less than the limit.
- * @param l
- * the long to write.
- * @return this buffer.
- * @exception IndexOutOfBoundsException
- * if index is invalid.
- * @exception ReadOnlyBufferException
- * if no changes may be made to the contents of this buffer.
- * @since Android 1.0
- */
- public abstract LongBuffer put(int index, long l);
-
- /**
- * Returns a sliced buffer that shares its content with this buffer.
- *
- * The sliced buffer's capacity will be this buffer's {@code remaining()},
- * and its zero position will correspond to this buffer's current position.
- * The new buffer's position will be 0, limit will be its capacity, and its
- * mark is cleared. The new buffer's read-only property and byte order are
- * same as this buffer's.
- *
- *
- * The new buffer shares its content with this buffer, which means either
- * buffer's change of content will be visible to the other. The two buffer's
- * position, limit and mark are independent.
- *
- *
- * @return a sliced buffer that shares its content with this buffer.
- * @since Android 1.0
- */
- public abstract LongBuffer slice();
-
- /**
- * Returns a string representing the state of this long buffer.
- *
- * @return a string representing the state of this long buffer.
- * @since Android 1.0
- */
- public String toString() {
- StringBuffer buf = new StringBuffer();
- buf.append(getClass().getName());
- buf.append(", status: capacity="); //$NON-NLS-1$
- buf.append(capacity());
- buf.append(" position="); //$NON-NLS-1$
- buf.append(position());
- buf.append(" limit="); //$NON-NLS-1$
- buf.append(limit());
- return buf.toString();
- }
+ /** Creates a long buffer based on a newly allocated long array.
+ *
+ * @param capacity the capacity of the new buffer.
+ * @return the created long buffer.
+ * @throws IllegalArgumentException if {@code capacity} is less than zero.
+ * @since Android 1.0 */
+ public static LongBuffer allocate (int capacity) {
+ if (capacity < 0) {
+ throw new IllegalArgumentException();
+ }
+ return BufferFactory.newLongBuffer(capacity);
+ }
+
+ /** Creates a new long buffer by wrapping the given long array.
+ *
+ * Calling this method has the same effect as {@code wrap(array, 0, array.length)}.
+ *
+ *
+ * @param array the long array which the new buffer will be based on.
+ * @return the created long buffer.
+ * @since Android 1.0 */
+ public static LongBuffer wrap (long[] array) {
+ return wrap(array, 0, array.length);
+ }
+
+ /** Creates a new long buffer by wrapping the given long array.
+ *
+ * The new buffer's position will be {@code start}, limit will be {@code start + len}, capacity will be the length of the
+ * array.
+ *
+ *
+ * @param array the long array which the new buffer will be based on.
+ * @param start the start index, must not be negative and not greater than {@code array.length}.
+ * @param len the length, must not be negative and not greater than {@code array.length - start}.
+ * @return the created long buffer.
+ * @exception IndexOutOfBoundsException if either {@code start} or {@code len} is invalid.
+ * @since Android 1.0 */
+ public static LongBuffer wrap (long[] array, int start, int len) {
+ if (array == null) {
+ throw new NullPointerException();
+ }
+ if (start < 0 || len < 0 || (long)len + (long)start > array.length) {
+ throw new IndexOutOfBoundsException();
+ }
+
+ LongBuffer buf = BufferFactory.newLongBuffer(array);
+ buf.position = start;
+ buf.limit = start + len;
+
+ return buf;
+ }
+
+ /** Constructs a {@code LongBuffer} with given capacity.
+ *
+ * @param capacity The capacity of the buffer */
+ LongBuffer (int capacity) {
+ super(capacity);
+ }
+
+ /** Returns the long array which this buffer is based on, if there is one.
+ *
+ * @return the long array which this buffer is based on.
+ * @exception ReadOnlyBufferException if this buffer is based on an array, but it is read-only.
+ * @exception UnsupportedOperationException if this buffer is not based on an array.
+ * @since Android 1.0 */
+ public final long[] array () {
+ return protectedArray();
+ }
+
+ /** Returns the offset of the long array which this buffer is based on, if there is one.
+ *
+ * The offset is the index of the array and corresponds to the zero position of the buffer.
+ *
+ *
+ * @return the offset of the long array which this buffer is based on.
+ * @exception ReadOnlyBufferException if this buffer is based on an array, but it is read-only.
+ * @exception UnsupportedOperationException if this buffer is not based on an array.
+ * @since Android 1.0 */
+ public final int arrayOffset () {
+ return protectedArrayOffset();
+ }
+
+ /** Returns a read-only buffer that shares its content with this buffer.
+ *
+ * The returned buffer is guaranteed to be a new instance, even if this buffer is read-only itself. The new buffer's position,
+ * limit, capacity and mark are the same as this buffer's.
+ *
+ *
+ * The new buffer shares its content with this buffer, which means this buffer's change of content will be visible to the new
+ * buffer. The two buffer's position, limit and mark are independent.
+ *
+ *
+ * @return a read-only version of this buffer.
+ * @since Android 1.0 */
+ public abstract LongBuffer asReadOnlyBuffer ();
+
+ /** Compacts this long buffer.
+ *
+ * The remaining longs will be moved to the head of the buffer, staring from position zero. Then the position is set to
+ * {@code remaining()}; the limit is set to capacity; the mark is cleared.
+ *
+ *
+ * @return this buffer.
+ * @exception ReadOnlyBufferException if no changes may be made to the contents of this buffer.
+ * @since Android 1.0 */
+ public abstract LongBuffer compact ();
+
+ /** Compare the remaining longs of this buffer to another long buffer's remaining longs.
+ *
+ * @param otherBuffer another long buffer.
+ * @return a negative value if this is less than {@code otherBuffer}; 0 if this equals to {@code otherBuffer}; a positive value
+ * if this is greater than {@code otherBuffer}
+ * @exception ClassCastException if {@code otherBuffer} is not a long buffer.
+ * @since Android 1.0 */
+ public int compareTo (LongBuffer otherBuffer) {
+ int compareRemaining = (remaining() < otherBuffer.remaining()) ? remaining() : otherBuffer.remaining();
+ int thisPos = position;
+ int otherPos = otherBuffer.position;
+ // BEGIN android-changed
+ long thisLong, otherLong;
+ while (compareRemaining > 0) {
+ thisLong = get(thisPos);
+ otherLong = otherBuffer.get(otherPos);
+ if (thisLong != otherLong) {
+ return thisLong < otherLong ? -1 : 1;
+ }
+ thisPos++;
+ otherPos++;
+ compareRemaining--;
+ }
+ // END android-changed
+ return remaining() - otherBuffer.remaining();
+ }
+
+ /** Returns a duplicated buffer that shares its content with this buffer.
+ *
+ * The duplicated buffer's position, limit, capacity and mark are the same as this buffer. The duplicated buffer's read-only
+ * property and byte order are same as this buffer's, too.
+ *
+ *
+ * The new buffer shares its content with this buffer, which means either buffer's change of content will be visible to the
+ * other. The two buffer's position, limit and mark are independent.
+ *
+ *
+ * @return a duplicated buffer that shares its content with this buffer.
+ * @since Android 1.0 */
+ public abstract LongBuffer duplicate ();
+
+ /** Checks whether this long buffer is equal to another object.
+ *
+ * If {@code other} is not a long buffer then {@code false} is returned. Two long buffers are equal if and only if their
+ * remaining longs are exactly the same. Position, limit, capacity and mark are not considered.
+ *
+ *
+ * @param other the object to compare with this long buffer.
+ * @return {@code true} if this long buffer is equal to {@code other}, {@code false} otherwise.
+ * @since Android 1.0 */
+ public boolean equals (Object other) {
+ if (!(other instanceof LongBuffer)) {
+ return false;
+ }
+ LongBuffer otherBuffer = (LongBuffer)other;
+
+ if (remaining() != otherBuffer.remaining()) {
+ return false;
+ }
+
+ int myPosition = position;
+ int otherPosition = otherBuffer.position;
+ boolean equalSoFar = true;
+ while (equalSoFar && (myPosition < limit)) {
+ equalSoFar = get(myPosition++) == otherBuffer.get(otherPosition++);
+ }
+
+ return equalSoFar;
+ }
+
+ /** Returns the long at the current position and increase the position by 1.
+ *
+ * @return the long at the current position.
+ * @exception BufferUnderflowException if the position is equal or greater than limit.
+ * @since Android 1.0 */
+ public abstract long get ();
+
+ /** Reads longs from the current position into the specified long array and increases the position by the number of longs read.
+ *
+ * Calling this method has the same effect as {@code get(dest, 0, dest.length)}.
+ *
+ *
+ * @param dest the destination long array.
+ * @return this buffer.
+ * @exception BufferUnderflowException if {@code dest.length} is greater than {@code remaining()}.
+ * @since Android 1.0 */
+ public LongBuffer get (long[] dest) {
+ return get(dest, 0, dest.length);
+ }
+
+ /** Reads longs from the current position into the specified long array, starting from the specified offset, and increase the
+ * position by the number of longs read.
+ *
+ * @param dest the target long array.
+ * @param off the offset of the long array, must not be negative and not greater than {@code dest.length}.
+ * @param len the number of longs to read, must be no less than zero and not greater than {@code dest.length - off}.
+ * @return this buffer.
+ * @exception IndexOutOfBoundsException if either {@code off} or {@code len} is invalid.
+ * @exception BufferUnderflowException if {@code len} is greater than {@code remaining()}.
+ * @since Android 1.0 */
+ public LongBuffer get (long[] dest, int off, int len) {
+ int length = dest.length;
+ if (off < 0 || len < 0 || (long)len + (long)off > length) {
+ throw new IndexOutOfBoundsException();
+ }
+
+ if (len > remaining()) {
+ throw new BufferUnderflowException();
+ }
+ for (int i = off; i < off + len; i++) {
+ dest[i] = get();
+ }
+ return this;
+ }
+
+ /** Returns the long at the specified index; the position is not changed.
+ *
+ * @param index the index, must not be negative and less than limit.
+ * @return the long at the specified index.
+ * @exception IndexOutOfBoundsException if index is invalid.
+ * @since Android 1.0 */
+ public abstract long get (int index);
+
+ /** Indicates whether this buffer is based on a long array and is read/write.
+ *
+ * @return {@code true} if this buffer is based on a long array and provides read/write access, {@code false} otherwise.
+ * @since Android 1.0 */
+ public final boolean hasArray () {
+ return protectedHasArray();
+ }
+
+ /** Calculates this buffer's hash code from the remaining chars. The position, limit, capacity and mark don't affect the hash
+ * code.
+ *
+ * @return the hash code calculated from the remaining longs.
+ * @since Android 1.0 */
+ public int hashCode () {
+ int myPosition = position;
+ int hash = 0;
+ long l;
+ while (myPosition < limit) {
+ l = get(myPosition++);
+ hash = hash + ((int)l) ^ ((int)(l >> 32));
+ }
+ return hash;
+ }
+
+ /** Indicates whether this buffer is direct. A direct buffer will try its best to take advantage of native memory APIs and it
+ * may not stay in the Java heap, so it is not affected by garbage collection.
+ *
+ * A long buffer is direct if it is based on a byte buffer and the byte buffer is direct.
+ *
+ *
+ * @return {@code true} if this buffer is direct, {@code false} otherwise.
+ * @since Android 1.0 */
+ public abstract boolean isDirect ();
+
+ /** Returns the byte order used by this buffer when converting longs from/to bytes.
+ *
+ * If this buffer is not based on a byte buffer, then always return the platform's native byte order.
+ *
+ *
+ * @return the byte order used by this buffer when converting longs from/to bytes.
+ * @since Android 1.0 */
+ public abstract ByteOrder order ();
+
+ /** Child class implements this method to realize {@code array()}.
+ *
+ * @return see {@code array()} */
+ abstract long[] protectedArray ();
+
+ /** Child class implements this method to realize {@code arrayOffset()}.
+ *
+ * @return see {@code arrayOffset()} */
+ abstract int protectedArrayOffset ();
+
+ /** Child class implements this method to realize {@code hasArray()}.
+ *
+ * @return see {@code hasArray()} */
+ abstract boolean protectedHasArray ();
+
+ /** Writes the given long to the current position and increases the position by 1.
+ *
+ * @param l the long to write.
+ * @return this buffer.
+ * @exception BufferOverflowException if position is equal or greater than limit.
+ * @exception ReadOnlyBufferException if no changes may be made to the contents of this buffer.
+ * @since Android 1.0 */
+ public abstract LongBuffer put (long l);
+
+ /** Writes longs from the given long array to the current position and increases the position by the number of longs written.
+ *
+ * Calling this method has the same effect as {@code put(src, 0, src.length)}.
+ *
+ *
+ * @param src the source long array.
+ * @return this buffer.
+ * @exception BufferOverflowException if {@code remaining()} is less than {@code src.length}.
+ * @exception ReadOnlyBufferException if no changes may be made to the contents of this buffer.
+ * @since Android 1.0 */
+ public final LongBuffer put (long[] src) {
+ return put(src, 0, src.length);
+ }
+
+ /** Writes longs from the given long array, starting from the specified offset, to the current position and increases the
+ * position by the number of longs written.
+ *
+ * @param src the source long array.
+ * @param off the offset of long array, must not be negative and not greater than {@code src.length}.
+ * @param len the number of longs to write, must be no less than zero and not greater than {@code src.length - off}.
+ * @return this buffer.
+ * @exception BufferOverflowException if {@code remaining()} is less than {@code len}.
+ * @exception IndexOutOfBoundsException if either {@code off} or {@code len} is invalid.
+ * @exception ReadOnlyBufferException if no changes may be made to the contents of this buffer.
+ * @since Android 1.0 */
+ public LongBuffer put (long[] src, int off, int len) {
+ int length = src.length;
+ if (off < 0 || len < 0 || (long)len + (long)off > length) {
+ throw new IndexOutOfBoundsException();
+ }
+
+ if (len > remaining()) {
+ throw new BufferOverflowException();
+ }
+ for (int i = off; i < off + len; i++) {
+ put(src[i]);
+ }
+ return this;
+ }
+
+ /** Writes all the remaining longs of the {@code src} long buffer to this buffer's current position, and increases both buffers'
+ * position by the number of longs copied.
+ *
+ * @param src the source long buffer.
+ * @return this buffer.
+ * @exception BufferOverflowException if {@code src.remaining()} is greater than this buffer's {@code remaining()}.
+ * @exception IllegalArgumentException if {@code src} is this buffer.
+ * @exception ReadOnlyBufferException if no changes may be made to the contents of this buffer.
+ * @since Android 1.0 */
+ public LongBuffer put (LongBuffer src) {
+ if (src == this) {
+ throw new IllegalArgumentException();
+ }
+ if (src.remaining() > remaining()) {
+ throw new BufferOverflowException();
+ }
+ long[] contents = new long[src.remaining()];
+ src.get(contents);
+ put(contents);
+ return this;
+ }
+
+ /** Writes a long to the specified index of this buffer; the position is not changed.
+ *
+ * @param index the index, must not be negative and less than the limit.
+ * @param l the long to write.
+ * @return this buffer.
+ * @exception IndexOutOfBoundsException if index is invalid.
+ * @exception ReadOnlyBufferException if no changes may be made to the contents of this buffer.
+ * @since Android 1.0 */
+ public abstract LongBuffer put (int index, long l);
+
+ /** Returns a sliced buffer that shares its content with this buffer.
+ *
+ * The sliced buffer's capacity will be this buffer's {@code remaining()}, and its zero position will correspond to this
+ * buffer's current position. The new buffer's position will be 0, limit will be its capacity, and its mark is cleared. The new
+ * buffer's read-only property and byte order are same as this buffer's.
+ *
+ *
+ * The new buffer shares its content with this buffer, which means either buffer's change of content will be visible to the
+ * other. The two buffer's position, limit and mark are independent.
+ *
+ *
+ * @return a sliced buffer that shares its content with this buffer.
+ * @since Android 1.0 */
+ public abstract LongBuffer slice ();
+
+ /** Returns a string representing the state of this long buffer.
+ *
+ * @return a string representing the state of this long buffer.
+ * @since Android 1.0 */
+ public String toString () {
+ StringBuffer buf = new StringBuffer();
+ buf.append(getClass().getName());
+ buf.append(", status: capacity="); //$NON-NLS-1$
+ buf.append(capacity());
+ buf.append(" position="); //$NON-NLS-1$
+ buf.append(position());
+ buf.append(" limit="); //$NON-NLS-1$
+ buf.append(limit());
+ return buf.toString();
+ }
}
diff --git a/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/java/nio/LongToByteBufferAdapter.java b/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/java/nio/LongToByteBufferAdapter.java
index b4e6b9d733a..410b3b30f88 100644
--- a/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/java/nio/LongToByteBufferAdapter.java
+++ b/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/java/nio/LongToByteBufferAdapter.java
@@ -19,187 +19,182 @@
//import org.apache.harmony.nio.internal.DirectBuffer;
//import org.apache.harmony.luni.platform.PlatformAddress;
-/**
- * This class wraps a byte buffer to be a long buffer.
+/** This class wraps a byte buffer to be a long buffer.
*
* Implementation notice:
*
- * After a byte buffer instance is wrapped, it becomes privately owned by
- * the adapter. It must NOT be accessed outside the adapter any more.
- * The byte buffer's position and limit are NOT linked with the adapter.
- * The adapter extends Buffer, thus has its own position and limit.
+ * After a byte buffer instance is wrapped, it becomes privately owned by the adapter. It must NOT be accessed outside the
+ * adapter any more.
+ * The byte buffer's position and limit are NOT linked with the adapter. The adapter extends Buffer, thus has its own position
+ * and limit.
*
- *
- *
- */
-final class LongToByteBufferAdapter extends LongBuffer {//implements DirectBuffer {
-
- static LongBuffer wrap(ByteBuffer byteBuffer) {
- return new LongToByteBufferAdapter(byteBuffer.slice());
- }
-
- private final ByteBuffer byteBuffer;
-
- LongToByteBufferAdapter(ByteBuffer byteBuffer) {
- super((byteBuffer.capacity() >> 3));
- this.byteBuffer = byteBuffer;
- this.byteBuffer.clear();
- }
-
-// public int getByteCapacity() {
-// if (byteBuffer instanceof DirectBuffer) {
-// return ((DirectBuffer) byteBuffer).getByteCapacity();
-// }
-// assert false : byteBuffer;
-// return -1;
-// }
+ * */
+final class LongToByteBufferAdapter extends LongBuffer {// implements DirectBuffer {
+
+ static LongBuffer wrap (ByteBuffer byteBuffer) {
+ return new LongToByteBufferAdapter(byteBuffer.slice());
+ }
+
+ private final ByteBuffer byteBuffer;
+
+ LongToByteBufferAdapter (ByteBuffer byteBuffer) {
+ super((byteBuffer.capacity() >> 3));
+ this.byteBuffer = byteBuffer;
+ this.byteBuffer.clear();
+ }
+
+// public int getByteCapacity() {
+// if (byteBuffer instanceof DirectBuffer) {
+// return ((DirectBuffer) byteBuffer).getByteCapacity();
+// }
+// assert false : byteBuffer;
+// return -1;
+// }
//
-// public PlatformAddress getEffectiveAddress() {
-// if (byteBuffer instanceof DirectBuffer) {
-// return ((DirectBuffer) byteBuffer).getEffectiveAddress();
-// }
-// assert false : byteBuffer;
-// return null;
-// }
+// public PlatformAddress getEffectiveAddress() {
+// if (byteBuffer instanceof DirectBuffer) {
+// return ((DirectBuffer) byteBuffer).getEffectiveAddress();
+// }
+// assert false : byteBuffer;
+// return null;
+// }
//
-// public PlatformAddress getBaseAddress() {
-// if (byteBuffer instanceof DirectBuffer) {
-// return ((DirectBuffer) byteBuffer).getBaseAddress();
-// }
-// assert false : byteBuffer;
-// return null;
-// }
+// public PlatformAddress getBaseAddress() {
+// if (byteBuffer instanceof DirectBuffer) {
+// return ((DirectBuffer) byteBuffer).getBaseAddress();
+// }
+// assert false : byteBuffer;
+// return null;
+// }
//
-// public boolean isAddressValid() {
-// if (byteBuffer instanceof DirectBuffer) {
-// return ((DirectBuffer) byteBuffer).isAddressValid();
-// }
-// assert false : byteBuffer;
-// return false;
-// }
+// public boolean isAddressValid() {
+// if (byteBuffer instanceof DirectBuffer) {
+// return ((DirectBuffer) byteBuffer).isAddressValid();
+// }
+// assert false : byteBuffer;
+// return false;
+// }
//
-// public void addressValidityCheck() {
-// if (byteBuffer instanceof DirectBuffer) {
-// ((DirectBuffer) byteBuffer).addressValidityCheck();
-// } else {
-// assert false : byteBuffer;
-// }
-// }
+// public void addressValidityCheck() {
+// if (byteBuffer instanceof DirectBuffer) {
+// ((DirectBuffer) byteBuffer).addressValidityCheck();
+// } else {
+// assert false : byteBuffer;
+// }
+// }
//
-// public void free() {
-// if (byteBuffer instanceof DirectBuffer) {
-// ((DirectBuffer) byteBuffer).free();
-// } else {
-// assert false : byteBuffer;
-// }
-// }
-
- @Override
- public LongBuffer asReadOnlyBuffer() {
- LongToByteBufferAdapter buf = new LongToByteBufferAdapter(byteBuffer
- .asReadOnlyBuffer());
- buf.limit = limit;
- buf.position = position;
- buf.mark = mark;
- return buf;
- }
-
- @Override
- public LongBuffer compact() {
- if (byteBuffer.isReadOnly()) {
- throw new ReadOnlyBufferException();
- }
- byteBuffer.limit(limit << 3);
- byteBuffer.position(position << 3);
- byteBuffer.compact();
- byteBuffer.clear();
- position = limit - position;
- limit = capacity;
- mark = UNSET_MARK;
- return this;
- }
-
- @Override
- public LongBuffer duplicate() {
- LongToByteBufferAdapter buf = new LongToByteBufferAdapter(byteBuffer
- .duplicate());
- buf.limit = limit;
- buf.position = position;
- buf.mark = mark;
- return buf;
- }
-
- @Override
- public long get() {
- if (position == limit) {
- throw new BufferUnderflowException();
- }
- return byteBuffer.getLong(position++ << 3);
- }
-
- @Override
- public long get(int index) {
- if (index < 0 || index >= limit) {
- throw new IndexOutOfBoundsException();
- }
- return byteBuffer.getLong(index << 3);
- }
-
- @Override
- public boolean isDirect() {
- return byteBuffer.isDirect();
- }
-
- @Override
- public boolean isReadOnly() {
- return byteBuffer.isReadOnly();
- }
-
- @Override
- public ByteOrder order() {
- return byteBuffer.order();
- }
-
- @Override
- protected long[] protectedArray() {
- throw new UnsupportedOperationException();
- }
-
- @Override
- protected int protectedArrayOffset() {
- throw new UnsupportedOperationException();
- }
-
- @Override
- protected boolean protectedHasArray() {
- return false;
- }
-
- @Override
- public LongBuffer put(long c) {
- if (position == limit) {
- throw new BufferOverflowException();
- }
- byteBuffer.putLong(position++ << 3, c);
- return this;
- }
-
- @Override
- public LongBuffer put(int index, long c) {
- if (index < 0 || index >= limit) {
- throw new IndexOutOfBoundsException();
- }
- byteBuffer.putLong(index << 3, c);
- return this;
- }
-
- @Override
- public LongBuffer slice() {
- byteBuffer.limit(limit << 3);
- byteBuffer.position(position << 3);
- LongBuffer result = new LongToByteBufferAdapter(byteBuffer.slice());
- byteBuffer.clear();
- return result;
- }
+// public void free() {
+// if (byteBuffer instanceof DirectBuffer) {
+// ((DirectBuffer) byteBuffer).free();
+// } else {
+// assert false : byteBuffer;
+// }
+// }
+
+ @Override
+ public LongBuffer asReadOnlyBuffer () {
+ LongToByteBufferAdapter buf = new LongToByteBufferAdapter(byteBuffer.asReadOnlyBuffer());
+ buf.limit = limit;
+ buf.position = position;
+ buf.mark = mark;
+ return buf;
+ }
+
+ @Override
+ public LongBuffer compact () {
+ if (byteBuffer.isReadOnly()) {
+ throw new ReadOnlyBufferException();
+ }
+ byteBuffer.limit(limit << 3);
+ byteBuffer.position(position << 3);
+ byteBuffer.compact();
+ byteBuffer.clear();
+ position = limit - position;
+ limit = capacity;
+ mark = UNSET_MARK;
+ return this;
+ }
+
+ @Override
+ public LongBuffer duplicate () {
+ LongToByteBufferAdapter buf = new LongToByteBufferAdapter(byteBuffer.duplicate());
+ buf.limit = limit;
+ buf.position = position;
+ buf.mark = mark;
+ return buf;
+ }
+
+ @Override
+ public long get () {
+ if (position == limit) {
+ throw new BufferUnderflowException();
+ }
+ return byteBuffer.getLong(position++ << 3);
+ }
+
+ @Override
+ public long get (int index) {
+ if (index < 0 || index >= limit) {
+ throw new IndexOutOfBoundsException();
+ }
+ return byteBuffer.getLong(index << 3);
+ }
+
+ @Override
+ public boolean isDirect () {
+ return byteBuffer.isDirect();
+ }
+
+ @Override
+ public boolean isReadOnly () {
+ return byteBuffer.isReadOnly();
+ }
+
+ @Override
+ public ByteOrder order () {
+ return byteBuffer.order();
+ }
+
+ @Override
+ protected long[] protectedArray () {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ protected int protectedArrayOffset () {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ protected boolean protectedHasArray () {
+ return false;
+ }
+
+ @Override
+ public LongBuffer put (long c) {
+ if (position == limit) {
+ throw new BufferOverflowException();
+ }
+ byteBuffer.putLong(position++ << 3, c);
+ return this;
+ }
+
+ @Override
+ public LongBuffer put (int index, long c) {
+ if (index < 0 || index >= limit) {
+ throw new IndexOutOfBoundsException();
+ }
+ byteBuffer.putLong(index << 3, c);
+ return this;
+ }
+
+ @Override
+ public LongBuffer slice () {
+ byteBuffer.limit(limit << 3);
+ byteBuffer.position(position << 3);
+ LongBuffer result = new LongToByteBufferAdapter(byteBuffer.slice());
+ byteBuffer.clear();
+ return result;
+ }
}
diff --git a/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/java/nio/ReadOnlyBufferException.java b/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/java/nio/ReadOnlyBufferException.java
index 62e2d5ff908..100ce78be31 100644
--- a/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/java/nio/ReadOnlyBufferException.java
+++ b/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/java/nio/ReadOnlyBufferException.java
@@ -16,23 +16,17 @@
package java.nio;
-
-/**
- * A {@code ReadOnlyBufferException} is thrown when some write operation is
- * called on a read-only buffer.
+/** A {@code ReadOnlyBufferException} is thrown when some write operation is called on a read-only buffer.
*
- * @since Android 1.0
- */
+ * @since Android 1.0 */
public class ReadOnlyBufferException extends UnsupportedOperationException {
- private static final long serialVersionUID = -1210063976496234090L;
+ private static final long serialVersionUID = -1210063976496234090L;
- /**
- * Constructs a {@code ReadOnlyBufferException}.
- *
- * @since Android 1.0
- */
- public ReadOnlyBufferException() {
- super();
- }
+ /** Constructs a {@code ReadOnlyBufferException}.
+ *
+ * @since Android 1.0 */
+ public ReadOnlyBufferException () {
+ super();
+ }
}
diff --git a/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/java/nio/ReadOnlyCharArrayBuffer.java b/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/java/nio/ReadOnlyCharArrayBuffer.java
index 461ea4f70c9..773ab12deba 100644
--- a/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/java/nio/ReadOnlyCharArrayBuffer.java
+++ b/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/java/nio/ReadOnlyCharArrayBuffer.java
@@ -17,86 +17,79 @@
package java.nio;
-/**
- * CharArrayBuffer, ReadWriteCharArrayBuffer and ReadOnlyCharArrayBuffer compose
- * the implementation of array based char buffers.
+/** CharArrayBuffer, ReadWriteCharArrayBuffer and ReadOnlyCharArrayBuffer compose the implementation of array based char buffers.
*
- * ReadOnlyCharArrayBuffer extends CharArrayBuffer with all the write methods
- * throwing read only exception.
+ * ReadOnlyCharArrayBuffer extends CharArrayBuffer with all the write methods throwing read only exception.
*
*
* This class is marked final for runtime performance.
- *
- *
- */
+ * */
final class ReadOnlyCharArrayBuffer extends CharArrayBuffer {
- static ReadOnlyCharArrayBuffer copy(CharArrayBuffer other, int markOfOther) {
- ReadOnlyCharArrayBuffer buf = new ReadOnlyCharArrayBuffer(other
- .capacity(), other.backingArray, other.offset);
- buf.limit = other.limit();
- buf.position = other.position();
- buf.mark = markOfOther;
- return buf;
- }
-
- ReadOnlyCharArrayBuffer(int capacity, char[] backingArray, int arrayOffset) {
- super(capacity, backingArray, arrayOffset);
- }
-
- public CharBuffer asReadOnlyBuffer() {
- return duplicate();
- }
-
- public CharBuffer compact() {
- throw new ReadOnlyBufferException();
- }
-
- public CharBuffer duplicate() {
- return copy(this, mark);
- }
-
- public boolean isReadOnly() {
- return true;
- }
-
- protected char[] protectedArray() {
- throw new ReadOnlyBufferException();
- }
-
- protected int protectedArrayOffset() {
- throw new ReadOnlyBufferException();
- }
-
- protected boolean protectedHasArray() {
- return false;
- }
-
- public CharBuffer put(char c) {
- throw new ReadOnlyBufferException();
- }
-
- public CharBuffer put(int index, char c) {
- throw new ReadOnlyBufferException();
- }
-
- public final CharBuffer put(char[] src, int off, int len) {
- throw new ReadOnlyBufferException();
- }
-
- public final CharBuffer put(CharBuffer src) {
- throw new ReadOnlyBufferException();
- }
-
- public CharBuffer put(String src, int start, int end) {
- if ((start < 0 ) || (end < 0) || (long)start + (long)end > src.length()) {
- throw new IndexOutOfBoundsException();
- }
- throw new ReadOnlyBufferException();
- }
-
- public CharBuffer slice() {
- return new ReadOnlyCharArrayBuffer(remaining(), backingArray, offset
- + position);
- }
+ static ReadOnlyCharArrayBuffer copy (CharArrayBuffer other, int markOfOther) {
+ ReadOnlyCharArrayBuffer buf = new ReadOnlyCharArrayBuffer(other.capacity(), other.backingArray, other.offset);
+ buf.limit = other.limit();
+ buf.position = other.position();
+ buf.mark = markOfOther;
+ return buf;
+ }
+
+ ReadOnlyCharArrayBuffer (int capacity, char[] backingArray, int arrayOffset) {
+ super(capacity, backingArray, arrayOffset);
+ }
+
+ public CharBuffer asReadOnlyBuffer () {
+ return duplicate();
+ }
+
+ public CharBuffer compact () {
+ throw new ReadOnlyBufferException();
+ }
+
+ public CharBuffer duplicate () {
+ return copy(this, mark);
+ }
+
+ public boolean isReadOnly () {
+ return true;
+ }
+
+ protected char[] protectedArray () {
+ throw new ReadOnlyBufferException();
+ }
+
+ protected int protectedArrayOffset () {
+ throw new ReadOnlyBufferException();
+ }
+
+ protected boolean protectedHasArray () {
+ return false;
+ }
+
+ public CharBuffer put (char c) {
+ throw new ReadOnlyBufferException();
+ }
+
+ public CharBuffer put (int index, char c) {
+ throw new ReadOnlyBufferException();
+ }
+
+ public final CharBuffer put (char[] src, int off, int len) {
+ throw new ReadOnlyBufferException();
+ }
+
+ public final CharBuffer put (CharBuffer src) {
+ throw new ReadOnlyBufferException();
+ }
+
+ public CharBuffer put (String src, int start, int end) {
+ if ((start < 0) || (end < 0) || (long)start + (long)end > src.length()) {
+ throw new IndexOutOfBoundsException();
+ }
+ throw new ReadOnlyBufferException();
+ }
+
+ public CharBuffer slice () {
+ return new ReadOnlyCharArrayBuffer(remaining(), backingArray, offset + position);
+ }
}
diff --git a/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/java/nio/ReadOnlyDoubleArrayBuffer.java b/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/java/nio/ReadOnlyDoubleArrayBuffer.java
index 4f0b5d2d9bc..372ac4e305a 100644
--- a/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/java/nio/ReadOnlyDoubleArrayBuffer.java
+++ b/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/java/nio/ReadOnlyDoubleArrayBuffer.java
@@ -17,82 +17,74 @@
package java.nio;
-/**
- * DoubleArrayBuffer, ReadWriteDoubleArrayBuffer and ReadOnlyDoubleArrayBuffer
- * compose the implementation of array based double buffers.
+/** DoubleArrayBuffer, ReadWriteDoubleArrayBuffer and ReadOnlyDoubleArrayBuffer compose the implementation of array based double
+ * buffers.
*
- * ReadOnlyDoubleArrayBuffer extends DoubleArrayBuffer with all the write
- * methods throwing read only exception.
+ * ReadOnlyDoubleArrayBuffer extends DoubleArrayBuffer with all the write methods throwing read only exception.
*
*
* This class is marked final for runtime performance.
- *
- *
- */
+ * */
final class ReadOnlyDoubleArrayBuffer extends DoubleArrayBuffer {
- static ReadOnlyDoubleArrayBuffer copy(DoubleArrayBuffer other,
- int markOfOther) {
- ReadOnlyDoubleArrayBuffer buf = new ReadOnlyDoubleArrayBuffer(other
- .capacity(), other.backingArray, other.offset);
- buf.limit = other.limit();
- buf.position = other.position();
- buf.mark = markOfOther;
- return buf;
- }
-
- ReadOnlyDoubleArrayBuffer(int capacity, double[] backingArray,
- int arrayOffset) {
- super(capacity, backingArray, arrayOffset);
- }
-
- public DoubleBuffer asReadOnlyBuffer() {
- return duplicate();
- }
-
- public DoubleBuffer compact() {
- throw new ReadOnlyBufferException();
- }
-
- public DoubleBuffer duplicate() {
- return copy(this, mark);
- }
-
- public boolean isReadOnly() {
- return true;
- }
-
- protected double[] protectedArray() {
- throw new ReadOnlyBufferException();
- }
-
- protected int protectedArrayOffset() {
- throw new ReadOnlyBufferException();
- }
-
- protected boolean protectedHasArray() {
- return false;
- }
-
- public DoubleBuffer put(double c) {
- throw new ReadOnlyBufferException();
- }
-
- public DoubleBuffer put(int index, double c) {
- throw new ReadOnlyBufferException();
- }
-
- public final DoubleBuffer put(double[] src, int off, int len) {
- throw new ReadOnlyBufferException();
- }
-
- public final DoubleBuffer put(DoubleBuffer buf) {
- throw new ReadOnlyBufferException();
- }
-
- public DoubleBuffer slice() {
- return new ReadOnlyDoubleArrayBuffer(remaining(), backingArray, offset
- + position);
- }
+ static ReadOnlyDoubleArrayBuffer copy (DoubleArrayBuffer other, int markOfOther) {
+ ReadOnlyDoubleArrayBuffer buf = new ReadOnlyDoubleArrayBuffer(other.capacity(), other.backingArray, other.offset);
+ buf.limit = other.limit();
+ buf.position = other.position();
+ buf.mark = markOfOther;
+ return buf;
+ }
+
+ ReadOnlyDoubleArrayBuffer (int capacity, double[] backingArray, int arrayOffset) {
+ super(capacity, backingArray, arrayOffset);
+ }
+
+ public DoubleBuffer asReadOnlyBuffer () {
+ return duplicate();
+ }
+
+ public DoubleBuffer compact () {
+ throw new ReadOnlyBufferException();
+ }
+
+ public DoubleBuffer duplicate () {
+ return copy(this, mark);
+ }
+
+ public boolean isReadOnly () {
+ return true;
+ }
+
+ protected double[] protectedArray () {
+ throw new ReadOnlyBufferException();
+ }
+
+ protected int protectedArrayOffset () {
+ throw new ReadOnlyBufferException();
+ }
+
+ protected boolean protectedHasArray () {
+ return false;
+ }
+
+ public DoubleBuffer put (double c) {
+ throw new ReadOnlyBufferException();
+ }
+
+ public DoubleBuffer put (int index, double c) {
+ throw new ReadOnlyBufferException();
+ }
+
+ public final DoubleBuffer put (double[] src, int off, int len) {
+ throw new ReadOnlyBufferException();
+ }
+
+ public final DoubleBuffer put (DoubleBuffer buf) {
+ throw new ReadOnlyBufferException();
+ }
+
+ public DoubleBuffer slice () {
+ return new ReadOnlyDoubleArrayBuffer(remaining(), backingArray, offset + position);
+ }
}
diff --git a/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/java/nio/ReadOnlyFloatArrayBuffer.java b/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/java/nio/ReadOnlyFloatArrayBuffer.java
index 7559ffa9782..9bb46e2c4e1 100644
--- a/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/java/nio/ReadOnlyFloatArrayBuffer.java
+++ b/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/java/nio/ReadOnlyFloatArrayBuffer.java
@@ -17,80 +17,74 @@
package java.nio;
-/**
- * FloatArrayBuffer, ReadWriteFloatArrayBuffer and ReadOnlyFloatArrayBuffer
- * compose the implementation of array based float buffers.
+/** FloatArrayBuffer, ReadWriteFloatArrayBuffer and ReadOnlyFloatArrayBuffer compose the implementation of array based float
+ * buffers.
*
- * ReadOnlyFloatArrayBuffer extends FloatArrayBuffer with all the write methods
- * throwing read only exception.
+ * ReadOnlyFloatArrayBuffer extends FloatArrayBuffer with all the write methods throwing read only exception.
*
*
* This class is marked final for runtime performance.
- *
- *
- */
+ * */
final class ReadOnlyFloatArrayBuffer extends FloatArrayBuffer {
- static ReadOnlyFloatArrayBuffer copy(FloatArrayBuffer other, int markOfOther) {
- ReadOnlyFloatArrayBuffer buf = new ReadOnlyFloatArrayBuffer(other
- .capacity(), other.backingArray, other.offset);
- buf.limit = other.limit();
- buf.position = other.position();
- buf.mark = markOfOther;
- return buf;
- }
-
- ReadOnlyFloatArrayBuffer(int capacity, float[] backingArray, int arrayOffset) {
- super(capacity, backingArray, arrayOffset);
- }
-
- public FloatBuffer asReadOnlyBuffer() {
- return duplicate();
- }
-
- public FloatBuffer compact() {
- throw new ReadOnlyBufferException();
- }
-
- public FloatBuffer duplicate() {
- return copy(this, mark);
- }
-
- public boolean isReadOnly() {
- return true;
- }
-
- protected float[] protectedArray() {
- throw new ReadOnlyBufferException();
- }
-
- protected int protectedArrayOffset() {
- throw new ReadOnlyBufferException();
- }
-
- protected boolean protectedHasArray() {
- return false;
- }
-
- public FloatBuffer put(float c) {
- throw new ReadOnlyBufferException();
- }
-
- public FloatBuffer put(int index, float c) {
- throw new ReadOnlyBufferException();
- }
-
- public FloatBuffer put(FloatBuffer buf) {
- throw new ReadOnlyBufferException();
- }
-
- public final FloatBuffer put(float[] src, int off, int len) {
- throw new ReadOnlyBufferException();
- }
-
- public FloatBuffer slice() {
- return new ReadOnlyFloatArrayBuffer(remaining(), backingArray, offset
- + position);
- }
+ static ReadOnlyFloatArrayBuffer copy (FloatArrayBuffer other, int markOfOther) {
+ ReadOnlyFloatArrayBuffer buf = new ReadOnlyFloatArrayBuffer(other.capacity(), other.backingArray, other.offset);
+ buf.limit = other.limit();
+ buf.position = other.position();
+ buf.mark = markOfOther;
+ return buf;
+ }
+
+ ReadOnlyFloatArrayBuffer (int capacity, float[] backingArray, int arrayOffset) {
+ super(capacity, backingArray, arrayOffset);
+ }
+
+ public FloatBuffer asReadOnlyBuffer () {
+ return duplicate();
+ }
+
+ public FloatBuffer compact () {
+ throw new ReadOnlyBufferException();
+ }
+
+ public FloatBuffer duplicate () {
+ return copy(this, mark);
+ }
+
+ public boolean isReadOnly () {
+ return true;
+ }
+
+ protected float[] protectedArray () {
+ throw new ReadOnlyBufferException();
+ }
+
+ protected int protectedArrayOffset () {
+ throw new ReadOnlyBufferException();
+ }
+
+ protected boolean protectedHasArray () {
+ return false;
+ }
+
+ public FloatBuffer put (float c) {
+ throw new ReadOnlyBufferException();
+ }
+
+ public FloatBuffer put (int index, float c) {
+ throw new ReadOnlyBufferException();
+ }
+
+ public FloatBuffer put (FloatBuffer buf) {
+ throw new ReadOnlyBufferException();
+ }
+
+ public final FloatBuffer put (float[] src, int off, int len) {
+ throw new ReadOnlyBufferException();
+ }
+
+ public FloatBuffer slice () {
+ return new ReadOnlyFloatArrayBuffer(remaining(), backingArray, offset + position);
+ }
}
diff --git a/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/java/nio/ReadOnlyHeapByteBuffer.java b/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/java/nio/ReadOnlyHeapByteBuffer.java
index 857ecff0b9f..5e6a467147c 100644
--- a/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/java/nio/ReadOnlyHeapByteBuffer.java
+++ b/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/java/nio/ReadOnlyHeapByteBuffer.java
@@ -17,122 +17,115 @@
package java.nio;
-/**
- * HeapByteBuffer, ReadWriteHeapByteBuffer and ReadOnlyHeapByteBuffer compose
- * the implementation of array based byte buffers.
+/** HeapByteBuffer, ReadWriteHeapByteBuffer and ReadOnlyHeapByteBuffer compose the implementation of array based byte buffers.
*
- * ReadOnlyHeapByteBuffer extends HeapByteBuffer with all the write methods
- * throwing read only exception.
+ * ReadOnlyHeapByteBuffer extends HeapByteBuffer with all the write methods throwing read only exception.
*
*
* This class is marked final for runtime performance.
- *
- *
- */
+ * */
final class ReadOnlyHeapByteBuffer extends HeapByteBuffer {
- static ReadOnlyHeapByteBuffer copy(HeapByteBuffer other, int markOfOther) {
- ReadOnlyHeapByteBuffer buf = new ReadOnlyHeapByteBuffer(
- other.backingArray, other.capacity(), other.offset);
- buf.limit = other.limit();
- buf.position = other.position();
- buf.mark = markOfOther;
- buf.order(other.order());
- return buf;
- }
-
- ReadOnlyHeapByteBuffer(byte[] backingArray, int capacity, int arrayOffset) {
- super(backingArray, capacity, arrayOffset);
- }
-
- public ByteBuffer asReadOnlyBuffer() {
- return copy(this, mark);
- }
-
- public ByteBuffer compact() {
- throw new ReadOnlyBufferException();
- }
-
- public ByteBuffer duplicate() {
- return copy(this, mark);
- }
-
- public boolean isReadOnly() {
- return true;
- }
-
- protected byte[] protectedArray() {
- throw new ReadOnlyBufferException();
- }
-
- protected int protectedArrayOffset() {
- throw new ReadOnlyBufferException();
- }
-
- protected boolean protectedHasArray() {
- return false;
- }
-
- public ByteBuffer put(byte b) {
- throw new ReadOnlyBufferException();
- }
-
- public ByteBuffer put(int index, byte b) {
- throw new ReadOnlyBufferException();
- }
-
- public ByteBuffer put(byte[] src, int off, int len) {
- throw new ReadOnlyBufferException();
- }
-
- public ByteBuffer putDouble(double value) {
- throw new ReadOnlyBufferException();
- }
-
- public ByteBuffer putDouble(int index, double value) {
- throw new ReadOnlyBufferException();
- }
-
- public ByteBuffer putFloat(float value) {
- throw new ReadOnlyBufferException();
- }
-
- public ByteBuffer putFloat(int index, float value) {
- throw new ReadOnlyBufferException();
- }
-
- public ByteBuffer putInt(int value) {
- throw new ReadOnlyBufferException();
- }
-
- public ByteBuffer putInt(int index, int value) {
- throw new ReadOnlyBufferException();
- }
-
- public ByteBuffer putLong(int index, long value) {
- throw new ReadOnlyBufferException();
- }
-
- public ByteBuffer putLong(long value) {
- throw new ReadOnlyBufferException();
- }
-
- public ByteBuffer putShort(int index, short value) {
- throw new ReadOnlyBufferException();
- }
-
- public ByteBuffer putShort(short value) {
- throw new ReadOnlyBufferException();
- }
-
- public ByteBuffer put(ByteBuffer buf) {
- throw new ReadOnlyBufferException();
- }
-
- public ByteBuffer slice() {
- ReadOnlyHeapByteBuffer slice = new ReadOnlyHeapByteBuffer(backingArray,
- remaining(), offset + position);
- slice.order = order;
- return slice;
- }
+ static ReadOnlyHeapByteBuffer copy (HeapByteBuffer other, int markOfOther) {
+ ReadOnlyHeapByteBuffer buf = new ReadOnlyHeapByteBuffer(other.backingArray, other.capacity(), other.offset);
+ buf.limit = other.limit();
+ buf.position = other.position();
+ buf.mark = markOfOther;
+ buf.order(other.order());
+ return buf;
+ }
+
+ ReadOnlyHeapByteBuffer (byte[] backingArray, int capacity, int arrayOffset) {
+ super(backingArray, capacity, arrayOffset);
+ }
+
+ public ByteBuffer asReadOnlyBuffer () {
+ return copy(this, mark);
+ }
+
+ public ByteBuffer compact () {
+ throw new ReadOnlyBufferException();
+ }
+
+ public ByteBuffer duplicate () {
+ return copy(this, mark);
+ }
+
+ public boolean isReadOnly () {
+ return true;
+ }
+
+ protected byte[] protectedArray () {
+ throw new ReadOnlyBufferException();
+ }
+
+ protected int protectedArrayOffset () {
+ throw new ReadOnlyBufferException();
+ }
+
+ protected boolean protectedHasArray () {
+ return false;
+ }
+
+ public ByteBuffer put (byte b) {
+ throw new ReadOnlyBufferException();
+ }
+
+ public ByteBuffer put (int index, byte b) {
+ throw new ReadOnlyBufferException();
+ }
+
+ public ByteBuffer put (byte[] src, int off, int len) {
+ throw new ReadOnlyBufferException();
+ }
+
+ public ByteBuffer putDouble (double value) {
+ throw new ReadOnlyBufferException();
+ }
+
+ public ByteBuffer putDouble (int index, double value) {
+ throw new ReadOnlyBufferException();
+ }
+
+ public ByteBuffer putFloat (float value) {
+ throw new ReadOnlyBufferException();
+ }
+
+ public ByteBuffer putFloat (int index, float value) {
+ throw new ReadOnlyBufferException();
+ }
+
+ public ByteBuffer putInt (int value) {
+ throw new ReadOnlyBufferException();
+ }
+
+ public ByteBuffer putInt (int index, int value) {
+ throw new ReadOnlyBufferException();
+ }
+
+ public ByteBuffer putLong (int index, long value) {
+ throw new ReadOnlyBufferException();
+ }
+
+ public ByteBuffer putLong (long value) {
+ throw new ReadOnlyBufferException();
+ }
+
+ public ByteBuffer putShort (int index, short value) {
+ throw new ReadOnlyBufferException();
+ }
+
+ public ByteBuffer putShort (short value) {
+ throw new ReadOnlyBufferException();
+ }
+
+ public ByteBuffer put (ByteBuffer buf) {
+ throw new ReadOnlyBufferException();
+ }
+
+ public ByteBuffer slice () {
+ ReadOnlyHeapByteBuffer slice = new ReadOnlyHeapByteBuffer(backingArray, remaining(), offset + position);
+ slice.order = order;
+ return slice;
+ }
}
diff --git a/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/java/nio/ReadOnlyIntArrayBuffer.java b/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/java/nio/ReadOnlyIntArrayBuffer.java
index ba9380e0ce8..228db222f4a 100644
--- a/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/java/nio/ReadOnlyIntArrayBuffer.java
+++ b/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/java/nio/ReadOnlyIntArrayBuffer.java
@@ -17,80 +17,73 @@
package java.nio;
-/**
- * IntArrayBuffer, ReadWriteIntArrayBuffer and ReadOnlyIntArrayBuffer compose
- * the implementation of array based int buffers.
+/** IntArrayBuffer, ReadWriteIntArrayBuffer and ReadOnlyIntArrayBuffer compose the implementation of array based int buffers.
*
- * ReadOnlyIntArrayBuffer extends IntArrayBuffer with all the write methods
- * throwing read only exception.
+ * ReadOnlyIntArrayBuffer extends IntArrayBuffer with all the write methods throwing read only exception.
*
*
* This class is marked final for runtime performance.
- *
- *
- */
+ * */
final class ReadOnlyIntArrayBuffer extends IntArrayBuffer {
- static ReadOnlyIntArrayBuffer copy(IntArrayBuffer other, int markOfOther) {
- ReadOnlyIntArrayBuffer buf = new ReadOnlyIntArrayBuffer(other
- .capacity(), other.backingArray, other.offset);
- buf.limit = other.limit();
- buf.position = other.position();
- buf.mark = markOfOther;
- return buf;
- }
-
- ReadOnlyIntArrayBuffer(int capacity, int[] backingArray, int arrayOffset) {
- super(capacity, backingArray, arrayOffset);
- }
-
- public IntBuffer asReadOnlyBuffer() {
- return duplicate();
- }
-
- public IntBuffer compact() {
- throw new ReadOnlyBufferException();
- }
-
- public IntBuffer duplicate() {
- return copy(this, mark);
- }
-
- public boolean isReadOnly() {
- return true;
- }
-
- protected int[] protectedArray() {
- throw new ReadOnlyBufferException();
- }
-
- protected int protectedArrayOffset() {
- throw new ReadOnlyBufferException();
- }
-
- protected boolean protectedHasArray() {
- return false;
- }
-
- public IntBuffer put(int c) {
- throw new ReadOnlyBufferException();
- }
-
- public IntBuffer put(int index, int c) {
- throw new ReadOnlyBufferException();
- }
-
- public IntBuffer put(IntBuffer buf) {
- throw new ReadOnlyBufferException();
- }
-
- public final IntBuffer put(int[] src, int off, int len) {
- throw new ReadOnlyBufferException();
- }
-
- public IntBuffer slice() {
- return new ReadOnlyIntArrayBuffer(remaining(), backingArray, offset
- + position);
- }
+ static ReadOnlyIntArrayBuffer copy (IntArrayBuffer other, int markOfOther) {
+ ReadOnlyIntArrayBuffer buf = new ReadOnlyIntArrayBuffer(other.capacity(), other.backingArray, other.offset);
+ buf.limit = other.limit();
+ buf.position = other.position();
+ buf.mark = markOfOther;
+ return buf;
+ }
+
+ ReadOnlyIntArrayBuffer (int capacity, int[] backingArray, int arrayOffset) {
+ super(capacity, backingArray, arrayOffset);
+ }
+
+ public IntBuffer asReadOnlyBuffer () {
+ return duplicate();
+ }
+
+ public IntBuffer compact () {
+ throw new ReadOnlyBufferException();
+ }
+
+ public IntBuffer duplicate () {
+ return copy(this, mark);
+ }
+
+ public boolean isReadOnly () {
+ return true;
+ }
+
+ protected int[] protectedArray () {
+ throw new ReadOnlyBufferException();
+ }
+
+ protected int protectedArrayOffset () {
+ throw new ReadOnlyBufferException();
+ }
+
+ protected boolean protectedHasArray () {
+ return false;
+ }
+
+ public IntBuffer put (int c) {
+ throw new ReadOnlyBufferException();
+ }
+
+ public IntBuffer put (int index, int c) {
+ throw new ReadOnlyBufferException();
+ }
+
+ public IntBuffer put (IntBuffer buf) {
+ throw new ReadOnlyBufferException();
+ }
+
+ public final IntBuffer put (int[] src, int off, int len) {
+ throw new ReadOnlyBufferException();
+ }
+
+ public IntBuffer slice () {
+ return new ReadOnlyIntArrayBuffer(remaining(), backingArray, offset + position);
+ }
}
diff --git a/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/java/nio/ReadOnlyLongArrayBuffer.java b/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/java/nio/ReadOnlyLongArrayBuffer.java
index 76c1a4adb44..bca9209b007 100644
--- a/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/java/nio/ReadOnlyLongArrayBuffer.java
+++ b/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/java/nio/ReadOnlyLongArrayBuffer.java
@@ -17,80 +17,73 @@
package java.nio;
-/**
- * LongArrayBuffer, ReadWriteLongArrayBuffer and ReadOnlyLongArrayBuffer compose
- * the implementation of array based long buffers.
+/** LongArrayBuffer, ReadWriteLongArrayBuffer and ReadOnlyLongArrayBuffer compose the implementation of array based long buffers.
*
- * ReadOnlyLongArrayBuffer extends LongArrayBuffer with all the write methods
- * throwing read only exception.
+ * ReadOnlyLongArrayBuffer extends LongArrayBuffer with all the write methods throwing read only exception.
*
*
* This class is marked final for runtime performance.
- *
- *
- */
+ * */
final class ReadOnlyLongArrayBuffer extends LongArrayBuffer {
- static ReadOnlyLongArrayBuffer copy(LongArrayBuffer other, int markOfOther) {
- ReadOnlyLongArrayBuffer buf = new ReadOnlyLongArrayBuffer(other
- .capacity(), other.backingArray, other.offset);
- buf.limit = other.limit();
- buf.position = other.position();
- buf.mark = markOfOther;
- return buf;
- }
-
- ReadOnlyLongArrayBuffer(int capacity, long[] backingArray, int arrayOffset) {
- super(capacity, backingArray, arrayOffset);
- }
-
- public LongBuffer asReadOnlyBuffer() {
- return duplicate();
- }
-
- public LongBuffer compact() {
- throw new ReadOnlyBufferException();
- }
-
- public LongBuffer duplicate() {
- return copy(this, mark);
- }
-
- public boolean isReadOnly() {
- return true;
- }
-
- protected long[] protectedArray() {
- throw new ReadOnlyBufferException();
- }
-
- protected int protectedArrayOffset() {
- throw new ReadOnlyBufferException();
- }
-
- protected boolean protectedHasArray() {
- return false;
- }
-
- public LongBuffer put(long c) {
- throw new ReadOnlyBufferException();
- }
-
- public LongBuffer put(int index, long c) {
- throw new ReadOnlyBufferException();
- }
-
- public LongBuffer put(LongBuffer buf) {
- throw new ReadOnlyBufferException();
- }
-
- public final LongBuffer put(long[] src, int off, int len) {
- throw new ReadOnlyBufferException();
- }
-
- public LongBuffer slice() {
- return new ReadOnlyLongArrayBuffer(remaining(), backingArray, offset
- + position);
- }
+ static ReadOnlyLongArrayBuffer copy (LongArrayBuffer other, int markOfOther) {
+ ReadOnlyLongArrayBuffer buf = new ReadOnlyLongArrayBuffer(other.capacity(), other.backingArray, other.offset);
+ buf.limit = other.limit();
+ buf.position = other.position();
+ buf.mark = markOfOther;
+ return buf;
+ }
+
+ ReadOnlyLongArrayBuffer (int capacity, long[] backingArray, int arrayOffset) {
+ super(capacity, backingArray, arrayOffset);
+ }
+
+ public LongBuffer asReadOnlyBuffer () {
+ return duplicate();
+ }
+
+ public LongBuffer compact () {
+ throw new ReadOnlyBufferException();
+ }
+
+ public LongBuffer duplicate () {
+ return copy(this, mark);
+ }
+
+ public boolean isReadOnly () {
+ return true;
+ }
+
+ protected long[] protectedArray () {
+ throw new ReadOnlyBufferException();
+ }
+
+ protected int protectedArrayOffset () {
+ throw new ReadOnlyBufferException();
+ }
+
+ protected boolean protectedHasArray () {
+ return false;
+ }
+
+ public LongBuffer put (long c) {
+ throw new ReadOnlyBufferException();
+ }
+
+ public LongBuffer put (int index, long c) {
+ throw new ReadOnlyBufferException();
+ }
+
+ public LongBuffer put (LongBuffer buf) {
+ throw new ReadOnlyBufferException();
+ }
+
+ public final LongBuffer put (long[] src, int off, int len) {
+ throw new ReadOnlyBufferException();
+ }
+
+ public LongBuffer slice () {
+ return new ReadOnlyLongArrayBuffer(remaining(), backingArray, offset + position);
+ }
}
diff --git a/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/java/nio/ReadOnlyShortArrayBuffer.java b/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/java/nio/ReadOnlyShortArrayBuffer.java
index 1a3bfd3a09a..7d9dbda5427 100644
--- a/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/java/nio/ReadOnlyShortArrayBuffer.java
+++ b/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/java/nio/ReadOnlyShortArrayBuffer.java
@@ -17,80 +17,74 @@
package java.nio;
-/**
- * ShortArrayBuffer, ReadWriteShortArrayBuffer and ReadOnlyShortArrayBuffer
- * compose the implementation of array based short buffers.
+/** ShortArrayBuffer, ReadWriteShortArrayBuffer and ReadOnlyShortArrayBuffer compose the implementation of array based short
+ * buffers.
*
- * ReadOnlyShortArrayBuffer extends ShortArrayBuffer with all the write methods
- * throwing read only exception.
+ * ReadOnlyShortArrayBuffer extends ShortArrayBuffer with all the write methods throwing read only exception.
*
*
* This class is marked final for runtime performance.
- *
- *
- */
+ * */
final class ReadOnlyShortArrayBuffer extends ShortArrayBuffer {
- static ReadOnlyShortArrayBuffer copy(ShortArrayBuffer other, int markOfOther) {
- ReadOnlyShortArrayBuffer buf = new ReadOnlyShortArrayBuffer(other
- .capacity(), other.backingArray, other.offset);
- buf.limit = other.limit();
- buf.position = other.position();
- buf.mark = markOfOther;
- return buf;
- }
-
- ReadOnlyShortArrayBuffer(int capacity, short[] backingArray, int arrayOffset) {
- super(capacity, backingArray, arrayOffset);
- }
-
- public ShortBuffer asReadOnlyBuffer() {
- return duplicate();
- }
-
- public ShortBuffer compact() {
- throw new ReadOnlyBufferException();
- }
-
- public ShortBuffer duplicate() {
- return copy(this, mark);
- }
-
- public boolean isReadOnly() {
- return true;
- }
-
- protected short[] protectedArray() {
- throw new ReadOnlyBufferException();
- }
-
- protected int protectedArrayOffset() {
- throw new ReadOnlyBufferException();
- }
-
- protected boolean protectedHasArray() {
- return false;
- }
-
- public ShortBuffer put(ShortBuffer buf) {
- throw new ReadOnlyBufferException();
- }
-
- public ShortBuffer put(short c) {
- throw new ReadOnlyBufferException();
- }
-
- public ShortBuffer put(int index, short c) {
- throw new ReadOnlyBufferException();
- }
-
- public final ShortBuffer put(short[] src, int off, int len) {
- throw new ReadOnlyBufferException();
- }
-
- public ShortBuffer slice() {
- return new ReadOnlyShortArrayBuffer(remaining(), backingArray, offset
- + position);
- }
+ static ReadOnlyShortArrayBuffer copy (ShortArrayBuffer other, int markOfOther) {
+ ReadOnlyShortArrayBuffer buf = new ReadOnlyShortArrayBuffer(other.capacity(), other.backingArray, other.offset);
+ buf.limit = other.limit();
+ buf.position = other.position();
+ buf.mark = markOfOther;
+ return buf;
+ }
+
+ ReadOnlyShortArrayBuffer (int capacity, short[] backingArray, int arrayOffset) {
+ super(capacity, backingArray, arrayOffset);
+ }
+
+ public ShortBuffer asReadOnlyBuffer () {
+ return duplicate();
+ }
+
+ public ShortBuffer compact () {
+ throw new ReadOnlyBufferException();
+ }
+
+ public ShortBuffer duplicate () {
+ return copy(this, mark);
+ }
+
+ public boolean isReadOnly () {
+ return true;
+ }
+
+ protected short[] protectedArray () {
+ throw new ReadOnlyBufferException();
+ }
+
+ protected int protectedArrayOffset () {
+ throw new ReadOnlyBufferException();
+ }
+
+ protected boolean protectedHasArray () {
+ return false;
+ }
+
+ public ShortBuffer put (ShortBuffer buf) {
+ throw new ReadOnlyBufferException();
+ }
+
+ public ShortBuffer put (short c) {
+ throw new ReadOnlyBufferException();
+ }
+
+ public ShortBuffer put (int index, short c) {
+ throw new ReadOnlyBufferException();
+ }
+
+ public final ShortBuffer put (short[] src, int off, int len) {
+ throw new ReadOnlyBufferException();
+ }
+
+ public ShortBuffer slice () {
+ return new ReadOnlyShortArrayBuffer(remaining(), backingArray, offset + position);
+ }
}
diff --git a/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/java/nio/ReadWriteCharArrayBuffer.java b/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/java/nio/ReadWriteCharArrayBuffer.java
index 08f79b21540..3c1b55e4adc 100644
--- a/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/java/nio/ReadWriteCharArrayBuffer.java
+++ b/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/java/nio/ReadWriteCharArrayBuffer.java
@@ -17,105 +17,98 @@
package java.nio;
-/**
- * CharArrayBuffer, ReadWriteCharArrayBuffer and ReadOnlyCharArrayBuffer compose
- * the implementation of array based char buffers.
+/** CharArrayBuffer, ReadWriteCharArrayBuffer and ReadOnlyCharArrayBuffer compose the implementation of array based char buffers.
*
* ReadWriteCharArrayBuffer extends CharArrayBuffer with all the write methods.
*
*
* This class is marked final for runtime performance.
- *
- *
- */
+ * */
final class ReadWriteCharArrayBuffer extends CharArrayBuffer {
- static ReadWriteCharArrayBuffer copy(CharArrayBuffer other, int markOfOther) {
- ReadWriteCharArrayBuffer buf = new ReadWriteCharArrayBuffer(other
- .capacity(), other.backingArray, other.offset);
- buf.limit = other.limit();
- buf.position = other.position();
- buf.mark = markOfOther;
- return buf;
- }
-
- ReadWriteCharArrayBuffer(char[] array) {
- super(array);
- }
-
- ReadWriteCharArrayBuffer(int capacity) {
- super(capacity);
- }
-
- ReadWriteCharArrayBuffer(int capacity, char[] backingArray, int arrayOffset) {
- super(capacity, backingArray, arrayOffset);
- }
-
- public CharBuffer asReadOnlyBuffer() {
- return ReadOnlyCharArrayBuffer.copy(this, mark);
- }
-
- public CharBuffer compact() {
- System.arraycopy(backingArray, position + offset, backingArray, offset,
- remaining());
- position = limit - position;
- limit = capacity;
- mark = UNSET_MARK;
- return this;
- }
-
- public CharBuffer duplicate() {
- return copy(this, mark);
- }
-
- public boolean isReadOnly() {
- return false;
- }
-
- protected char[] protectedArray() {
- return backingArray;
- }
-
- protected int protectedArrayOffset() {
- return offset;
- }
-
- protected boolean protectedHasArray() {
- return true;
- }
-
- public CharBuffer put(char c) {
- if (position == limit) {
- throw new BufferOverflowException();
- }
- backingArray[offset + position++] = c;
- return this;
- }
-
- public CharBuffer put(int index, char c) {
- if (index < 0 || index >= limit) {
- throw new IndexOutOfBoundsException();
- }
- backingArray[offset + index] = c;
- return this;
- }
-
- public CharBuffer put(char[] src, int off, int len) {
- int length = src.length;
- if (off < 0 || len < 0 || (long)len + (long)off > length) {
- throw new IndexOutOfBoundsException();
- }
- if (len > remaining()) {
- throw new BufferOverflowException();
- }
- System.arraycopy(src, off, backingArray, offset+position, len);
- position += len;
- return this;
- }
-
- public CharBuffer slice() {
- return new ReadWriteCharArrayBuffer(remaining(), backingArray, offset
- + position);
- }
+ static ReadWriteCharArrayBuffer copy (CharArrayBuffer other, int markOfOther) {
+ ReadWriteCharArrayBuffer buf = new ReadWriteCharArrayBuffer(other.capacity(), other.backingArray, other.offset);
+ buf.limit = other.limit();
+ buf.position = other.position();
+ buf.mark = markOfOther;
+ return buf;
+ }
+
+ ReadWriteCharArrayBuffer (char[] array) {
+ super(array);
+ }
+
+ ReadWriteCharArrayBuffer (int capacity) {
+ super(capacity);
+ }
+
+ ReadWriteCharArrayBuffer (int capacity, char[] backingArray, int arrayOffset) {
+ super(capacity, backingArray, arrayOffset);
+ }
+
+ public CharBuffer asReadOnlyBuffer () {
+ return ReadOnlyCharArrayBuffer.copy(this, mark);
+ }
+
+ public CharBuffer compact () {
+ System.arraycopy(backingArray, position + offset, backingArray, offset, remaining());
+ position = limit - position;
+ limit = capacity;
+ mark = UNSET_MARK;
+ return this;
+ }
+
+ public CharBuffer duplicate () {
+ return copy(this, mark);
+ }
+
+ public boolean isReadOnly () {
+ return false;
+ }
+
+ protected char[] protectedArray () {
+ return backingArray;
+ }
+
+ protected int protectedArrayOffset () {
+ return offset;
+ }
+
+ protected boolean protectedHasArray () {
+ return true;
+ }
+
+ public CharBuffer put (char c) {
+ if (position == limit) {
+ throw new BufferOverflowException();
+ }
+ backingArray[offset + position++] = c;
+ return this;
+ }
+
+ public CharBuffer put (int index, char c) {
+ if (index < 0 || index >= limit) {
+ throw new IndexOutOfBoundsException();
+ }
+ backingArray[offset + index] = c;
+ return this;
+ }
+
+ public CharBuffer put (char[] src, int off, int len) {
+ int length = src.length;
+ if (off < 0 || len < 0 || (long)len + (long)off > length) {
+ throw new IndexOutOfBoundsException();
+ }
+ if (len > remaining()) {
+ throw new BufferOverflowException();
+ }
+ System.arraycopy(src, off, backingArray, offset + position, len);
+ position += len;
+ return this;
+ }
+
+ public CharBuffer slice () {
+ return new ReadWriteCharArrayBuffer(remaining(), backingArray, offset + position);
+ }
}
diff --git a/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/java/nio/ReadWriteDoubleArrayBuffer.java b/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/java/nio/ReadWriteDoubleArrayBuffer.java
index 2933178e35c..336a001068e 100644
--- a/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/java/nio/ReadWriteDoubleArrayBuffer.java
+++ b/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/java/nio/ReadWriteDoubleArrayBuffer.java
@@ -17,109 +17,99 @@
package java.nio;
-/**
- * DoubleArrayBuffer, ReadWriteDoubleArrayBuffer and ReadOnlyDoubleArrayBuffer
- * compose the implementation of array based double buffers.
+/** DoubleArrayBuffer, ReadWriteDoubleArrayBuffer and ReadOnlyDoubleArrayBuffer compose the implementation of array based double
+ * buffers.
*
- * ReadWriteDoubleArrayBuffer extends DoubleArrayBuffer with all the write
- * methods.
+ * ReadWriteDoubleArrayBuffer extends DoubleArrayBuffer with all the write methods.
*
*
* This class is marked final for runtime performance.
- *
- *
- */
+ * */
final class ReadWriteDoubleArrayBuffer extends DoubleArrayBuffer {
- static ReadWriteDoubleArrayBuffer copy(DoubleArrayBuffer other,
- int markOfOther) {
- ReadWriteDoubleArrayBuffer buf = new ReadWriteDoubleArrayBuffer(other
- .capacity(), other.backingArray, other.offset);
- buf.limit = other.limit();
- buf.position = other.position();
- buf.mark = markOfOther;
- return buf;
- }
-
- ReadWriteDoubleArrayBuffer(double[] array) {
- super(array);
- }
-
- ReadWriteDoubleArrayBuffer(int capacity) {
- super(capacity);
- }
-
- ReadWriteDoubleArrayBuffer(int capacity, double[] backingArray,
- int arrayOffset) {
- super(capacity, backingArray, arrayOffset);
- }
-
- public DoubleBuffer asReadOnlyBuffer() {
- return ReadOnlyDoubleArrayBuffer.copy(this, mark);
- }
-
- public DoubleBuffer compact() {
- System.arraycopy(backingArray, position + offset, backingArray, offset,
- remaining());
- position = limit - position;
- limit = capacity;
- mark = UNSET_MARK;
- return this;
- }
-
- public DoubleBuffer duplicate() {
- return copy(this, mark);
- }
-
- public boolean isReadOnly() {
- return false;
- }
-
- protected double[] protectedArray() {
- return backingArray;
- }
-
- protected int protectedArrayOffset() {
- return offset;
- }
-
- protected boolean protectedHasArray() {
- return true;
- }
-
- public DoubleBuffer put(double c) {
- if (position == limit) {
- throw new BufferOverflowException();
- }
- backingArray[offset + position++] = c;
- return this;
- }
-
- public DoubleBuffer put(int index, double c) {
- if (index < 0 || index >= limit) {
- throw new IndexOutOfBoundsException();
- }
- backingArray[offset + index] = c;
- return this;
- }
-
- public DoubleBuffer put(double[] src, int off, int len) {
- int length = src.length;
- if (off < 0 || len < 0 || (long)off + (long)len > length) {
- throw new IndexOutOfBoundsException();
- }
- if (len > remaining()) {
- throw new BufferOverflowException();
- }
- System.arraycopy(src, off, backingArray, offset
- + position, len);
- position += len;
- return this;
- }
-
- public DoubleBuffer slice() {
- return new ReadWriteDoubleArrayBuffer(remaining(), backingArray, offset
- + position);
- }
+ static ReadWriteDoubleArrayBuffer copy (DoubleArrayBuffer other, int markOfOther) {
+ ReadWriteDoubleArrayBuffer buf = new ReadWriteDoubleArrayBuffer(other.capacity(), other.backingArray, other.offset);
+ buf.limit = other.limit();
+ buf.position = other.position();
+ buf.mark = markOfOther;
+ return buf;
+ }
+
+ ReadWriteDoubleArrayBuffer (double[] array) {
+ super(array);
+ }
+
+ ReadWriteDoubleArrayBuffer (int capacity) {
+ super(capacity);
+ }
+
+ ReadWriteDoubleArrayBuffer (int capacity, double[] backingArray, int arrayOffset) {
+ super(capacity, backingArray, arrayOffset);
+ }
+
+ public DoubleBuffer asReadOnlyBuffer () {
+ return ReadOnlyDoubleArrayBuffer.copy(this, mark);
+ }
+
+ public DoubleBuffer compact () {
+ System.arraycopy(backingArray, position + offset, backingArray, offset, remaining());
+ position = limit - position;
+ limit = capacity;
+ mark = UNSET_MARK;
+ return this;
+ }
+
+ public DoubleBuffer duplicate () {
+ return copy(this, mark);
+ }
+
+ public boolean isReadOnly () {
+ return false;
+ }
+
+ protected double[] protectedArray () {
+ return backingArray;
+ }
+
+ protected int protectedArrayOffset () {
+ return offset;
+ }
+
+ protected boolean protectedHasArray () {
+ return true;
+ }
+
+ public DoubleBuffer put (double c) {
+ if (position == limit) {
+ throw new BufferOverflowException();
+ }
+ backingArray[offset + position++] = c;
+ return this;
+ }
+
+ public DoubleBuffer put (int index, double c) {
+ if (index < 0 || index >= limit) {
+ throw new IndexOutOfBoundsException();
+ }
+ backingArray[offset + index] = c;
+ return this;
+ }
+
+ public DoubleBuffer put (double[] src, int off, int len) {
+ int length = src.length;
+ if (off < 0 || len < 0 || (long)off + (long)len > length) {
+ throw new IndexOutOfBoundsException();
+ }
+ if (len > remaining()) {
+ throw new BufferOverflowException();
+ }
+ System.arraycopy(src, off, backingArray, offset + position, len);
+ position += len;
+ return this;
+ }
+
+ public DoubleBuffer slice () {
+ return new ReadWriteDoubleArrayBuffer(remaining(), backingArray, offset + position);
+ }
}
diff --git a/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/java/nio/ReadWriteFloatArrayBuffer.java b/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/java/nio/ReadWriteFloatArrayBuffer.java
index 49b0b11bb07..506976c6c7e 100644
--- a/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/java/nio/ReadWriteFloatArrayBuffer.java
+++ b/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/java/nio/ReadWriteFloatArrayBuffer.java
@@ -17,109 +17,99 @@
package java.nio;
-/**
- * FloatArrayBuffer, ReadWriteFloatArrayBuffer and ReadOnlyFloatArrayBuffer
- * compose the implementation of array based float buffers.
+/** FloatArrayBuffer, ReadWriteFloatArrayBuffer and ReadOnlyFloatArrayBuffer compose the implementation of array based float
+ * buffers.
*
- * ReadWriteFloatArrayBuffer extends FloatArrayBuffer with all the write
- * methods.
+ * ReadWriteFloatArrayBuffer extends FloatArrayBuffer with all the write methods.
*
*
* This class is marked final for runtime performance.
- *
- *
- */
+ * */
final class ReadWriteFloatArrayBuffer extends FloatArrayBuffer {
- static ReadWriteFloatArrayBuffer copy(FloatArrayBuffer other,
- int markOfOther) {
- ReadWriteFloatArrayBuffer buf = new ReadWriteFloatArrayBuffer(other
- .capacity(), other.backingArray, other.offset);
- buf.limit = other.limit();
- buf.position = other.position();
- buf.mark = markOfOther;
- return buf;
- }
-
- ReadWriteFloatArrayBuffer(float[] array) {
- super(array);
- }
-
- ReadWriteFloatArrayBuffer(int capacity) {
- super(capacity);
- }
-
- ReadWriteFloatArrayBuffer(int capacity, float[] backingArray,
- int arrayOffset) {
- super(capacity, backingArray, arrayOffset);
- }
-
- public FloatBuffer asReadOnlyBuffer() {
- return ReadOnlyFloatArrayBuffer.copy(this, mark);
- }
-
- public FloatBuffer compact() {
- System.arraycopy(backingArray, position + offset, backingArray, offset,
- remaining());
- position = limit - position;
- limit = capacity;
- mark = UNSET_MARK;
- return this;
- }
-
- public FloatBuffer duplicate() {
- return copy(this, mark);
- }
-
- public boolean isReadOnly() {
- return false;
- }
-
- protected float[] protectedArray() {
- return backingArray;
- }
-
- protected int protectedArrayOffset() {
- return offset;
- }
-
- protected boolean protectedHasArray() {
- return true;
- }
-
- public FloatBuffer put(float c) {
- if (position == limit) {
- throw new BufferOverflowException();
- }
- backingArray[offset + position++] = c;
- return this;
- }
-
- public FloatBuffer put(int index, float c) {
- if (index < 0 || index >= limit) {
- throw new IndexOutOfBoundsException();
- }
- backingArray[offset + index] = c;
- return this;
- }
-
- public FloatBuffer put(float[] src, int off, int len) {
- int length = src.length;
- if (off < 0 || len < 0 || (long)off + (long)len > length) {
- throw new IndexOutOfBoundsException();
- }
- if (len > remaining()) {
- throw new BufferOverflowException();
- }
- System.arraycopy(src, off, backingArray, offset
- + position, len);
- position += len;
- return this;
- }
-
- public FloatBuffer slice() {
- return new ReadWriteFloatArrayBuffer(remaining(), backingArray, offset
- + position);
- }
+ static ReadWriteFloatArrayBuffer copy (FloatArrayBuffer other, int markOfOther) {
+ ReadWriteFloatArrayBuffer buf = new ReadWriteFloatArrayBuffer(other.capacity(), other.backingArray, other.offset);
+ buf.limit = other.limit();
+ buf.position = other.position();
+ buf.mark = markOfOther;
+ return buf;
+ }
+
+ ReadWriteFloatArrayBuffer (float[] array) {
+ super(array);
+ }
+
+ ReadWriteFloatArrayBuffer (int capacity) {
+ super(capacity);
+ }
+
+ ReadWriteFloatArrayBuffer (int capacity, float[] backingArray, int arrayOffset) {
+ super(capacity, backingArray, arrayOffset);
+ }
+
+ public FloatBuffer asReadOnlyBuffer () {
+ return ReadOnlyFloatArrayBuffer.copy(this, mark);
+ }
+
+ public FloatBuffer compact () {
+ System.arraycopy(backingArray, position + offset, backingArray, offset, remaining());
+ position = limit - position;
+ limit = capacity;
+ mark = UNSET_MARK;
+ return this;
+ }
+
+ public FloatBuffer duplicate () {
+ return copy(this, mark);
+ }
+
+ public boolean isReadOnly () {
+ return false;
+ }
+
+ protected float[] protectedArray () {
+ return backingArray;
+ }
+
+ protected int protectedArrayOffset () {
+ return offset;
+ }
+
+ protected boolean protectedHasArray () {
+ return true;
+ }
+
+ public FloatBuffer put (float c) {
+ if (position == limit) {
+ throw new BufferOverflowException();
+ }
+ backingArray[offset + position++] = c;
+ return this;
+ }
+
+ public FloatBuffer put (int index, float c) {
+ if (index < 0 || index >= limit) {
+ throw new IndexOutOfBoundsException();
+ }
+ backingArray[offset + index] = c;
+ return this;
+ }
+
+ public FloatBuffer put (float[] src, int off, int len) {
+ int length = src.length;
+ if (off < 0 || len < 0 || (long)off + (long)len > length) {
+ throw new IndexOutOfBoundsException();
+ }
+ if (len > remaining()) {
+ throw new BufferOverflowException();
+ }
+ System.arraycopy(src, off, backingArray, offset + position, len);
+ position += len;
+ return this;
+ }
+
+ public FloatBuffer slice () {
+ return new ReadWriteFloatArrayBuffer(remaining(), backingArray, offset + position);
+ }
}
diff --git a/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/java/nio/ReadWriteHeapByteBuffer.java b/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/java/nio/ReadWriteHeapByteBuffer.java
index cc5696e1cfc..5f58e38c217 100644
--- a/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/java/nio/ReadWriteHeapByteBuffer.java
+++ b/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/java/nio/ReadWriteHeapByteBuffer.java
@@ -18,187 +18,179 @@
import com.google.gwt.corp.compatibility.Numbers;
-/**
- * HeapByteBuffer, ReadWriteHeapByteBuffer and ReadOnlyHeapByteBuffer compose
- * the implementation of array based byte buffers.
+/** HeapByteBuffer, ReadWriteHeapByteBuffer and ReadOnlyHeapByteBuffer compose the implementation of array based byte buffers.
*
* ReadWriteHeapByteBuffer extends HeapByteBuffer with all the write methods.
*
*
* This class is marked final for runtime performance.
- *
- *
- */
+ * */
final class ReadWriteHeapByteBuffer extends HeapByteBuffer {
- static ReadWriteHeapByteBuffer copy(HeapByteBuffer other, int markOfOther) {
- ReadWriteHeapByteBuffer buf = new ReadWriteHeapByteBuffer(
- other.backingArray, other.capacity(), other.offset);
- buf.limit = other.limit();
- buf.position = other.position();
- buf.mark = markOfOther;
- buf.order(other.order());
- return buf;
- }
-
- ReadWriteHeapByteBuffer(byte[] backingArray) {
- super(backingArray);
- }
-
- ReadWriteHeapByteBuffer(int capacity) {
- super(capacity);
- }
-
- ReadWriteHeapByteBuffer(byte[] backingArray, int capacity, int arrayOffset) {
- super(backingArray, capacity, arrayOffset);
- }
-
- public ByteBuffer asReadOnlyBuffer() {
- return ReadOnlyHeapByteBuffer.copy(this, mark);
- }
-
- public ByteBuffer compact() {
- System.arraycopy(backingArray, position + offset, backingArray, offset,
- remaining());
- position = limit - position;
- limit = capacity;
- mark = UNSET_MARK;
- return this;
- }
-
- public ByteBuffer duplicate() {
- return copy(this, mark);
- }
-
- public boolean isReadOnly() {
- return false;
- }
-
- protected byte[] protectedArray() {
- return backingArray;
- }
-
- protected int protectedArrayOffset() {
- return offset;
- }
-
- protected boolean protectedHasArray() {
- return true;
- }
-
- public ByteBuffer put(byte b) {
- if (position == limit) {
- throw new BufferOverflowException();
- }
- backingArray[offset + position++] = b;
- return this;
- }
-
- public ByteBuffer put(int index, byte b) {
- if (index < 0 || index >= limit) {
- throw new IndexOutOfBoundsException();
- }
- backingArray[offset + index] = b;
- return this;
- }
-
- /*
- * Override ByteBuffer.put(byte[], int, int) to improve performance.
- *
- * (non-Javadoc)
- *
- * @see java.nio.ByteBuffer#put(byte[], int, int)
- */
- public ByteBuffer put(byte[] src, int off, int len) {
- if (off < 0 || len < 0 || (long)off + (long)len > src.length) {
- throw new IndexOutOfBoundsException();
- }
- if (len > remaining()) {
- throw new BufferOverflowException();
- }
- if (isReadOnly()) {
- throw new ReadOnlyBufferException();
- }
- System.arraycopy(src, off, backingArray, offset
- + position, len);
- position += len;
- return this;
- }
-
- public ByteBuffer putDouble(double value) {
- return putLong(Numbers.doubleToRawLongBits(value));
- }
-
- public ByteBuffer putDouble(int index, double value) {
- return putLong(index, Numbers.doubleToRawLongBits(value));
- }
-
- public ByteBuffer putFloat(float value) {
- return putInt(Numbers.floatToIntBits(value));
- }
-
- public ByteBuffer putFloat(int index, float value) {
- return putInt(index, Numbers.floatToIntBits(value));
- }
-
- public ByteBuffer putInt(int value) {
- int newPosition = position + 4;
- if (newPosition > limit) {
- throw new BufferOverflowException();
- }
- store(position, value);
- position = newPosition;
- return this;
- }
-
- public ByteBuffer putInt(int index, int value) {
- if (index < 0 || (long)index + 4 > limit) {
- throw new IndexOutOfBoundsException();
- }
- store(index, value);
- return this;
- }
-
- public ByteBuffer putLong(int index, long value) {
- if (index < 0 || (long)index + 8 > limit) {
- throw new IndexOutOfBoundsException();
- }
- store(index, value);
- return this;
- }
-
- public ByteBuffer putLong(long value) {
- int newPosition = position + 8;
- if (newPosition > limit) {
- throw new BufferOverflowException();
- }
- store(position, value);
- position = newPosition;
- return this;
- }
-
- public ByteBuffer putShort(int index, short value) {
- if (index < 0 || (long)index + 2 > limit) {
- throw new IndexOutOfBoundsException();
- }
- store(index, value);
- return this;
- }
-
- public ByteBuffer putShort(short value) {
- int newPosition = position + 2;
- if (newPosition > limit) {
- throw new BufferOverflowException();
- }
- store(position, value);
- position = newPosition;
- return this;
- }
-
- public ByteBuffer slice() {
- ReadWriteHeapByteBuffer slice = new ReadWriteHeapByteBuffer(
- backingArray, remaining(), offset + position);
- slice.order = order;
- return slice;
- }
+ static ReadWriteHeapByteBuffer copy (HeapByteBuffer other, int markOfOther) {
+ ReadWriteHeapByteBuffer buf = new ReadWriteHeapByteBuffer(other.backingArray, other.capacity(), other.offset);
+ buf.limit = other.limit();
+ buf.position = other.position();
+ buf.mark = markOfOther;
+ buf.order(other.order());
+ return buf;
+ }
+
+ ReadWriteHeapByteBuffer (byte[] backingArray) {
+ super(backingArray);
+ }
+
+ ReadWriteHeapByteBuffer (int capacity) {
+ super(capacity);
+ }
+
+ ReadWriteHeapByteBuffer (byte[] backingArray, int capacity, int arrayOffset) {
+ super(backingArray, capacity, arrayOffset);
+ }
+
+ public ByteBuffer asReadOnlyBuffer () {
+ return ReadOnlyHeapByteBuffer.copy(this, mark);
+ }
+
+ public ByteBuffer compact () {
+ System.arraycopy(backingArray, position + offset, backingArray, offset, remaining());
+ position = limit - position;
+ limit = capacity;
+ mark = UNSET_MARK;
+ return this;
+ }
+
+ public ByteBuffer duplicate () {
+ return copy(this, mark);
+ }
+
+ public boolean isReadOnly () {
+ return false;
+ }
+
+ protected byte[] protectedArray () {
+ return backingArray;
+ }
+
+ protected int protectedArrayOffset () {
+ return offset;
+ }
+
+ protected boolean protectedHasArray () {
+ return true;
+ }
+
+ public ByteBuffer put (byte b) {
+ if (position == limit) {
+ throw new BufferOverflowException();
+ }
+ backingArray[offset + position++] = b;
+ return this;
+ }
+
+ public ByteBuffer put (int index, byte b) {
+ if (index < 0 || index >= limit) {
+ throw new IndexOutOfBoundsException();
+ }
+ backingArray[offset + index] = b;
+ return this;
+ }
+
+ /*
+ * Override ByteBuffer.put(byte[], int, int) to improve performance.
+ *
+ * (non-Javadoc)
+ *
+ * @see java.nio.ByteBuffer#put(byte[], int, int)
+ */
+ public ByteBuffer put (byte[] src, int off, int len) {
+ if (off < 0 || len < 0 || (long)off + (long)len > src.length) {
+ throw new IndexOutOfBoundsException();
+ }
+ if (len > remaining()) {
+ throw new BufferOverflowException();
+ }
+ if (isReadOnly()) {
+ throw new ReadOnlyBufferException();
+ }
+ System.arraycopy(src, off, backingArray, offset + position, len);
+ position += len;
+ return this;
+ }
+
+ public ByteBuffer putDouble (double value) {
+ return putLong(Numbers.doubleToRawLongBits(value));
+ }
+
+ public ByteBuffer putDouble (int index, double value) {
+ return putLong(index, Numbers.doubleToRawLongBits(value));
+ }
+
+ public ByteBuffer putFloat (float value) {
+ return putInt(Numbers.floatToIntBits(value));
+ }
+
+ public ByteBuffer putFloat (int index, float value) {
+ return putInt(index, Numbers.floatToIntBits(value));
+ }
+
+ public ByteBuffer putInt (int value) {
+ int newPosition = position + 4;
+ if (newPosition > limit) {
+ throw new BufferOverflowException();
+ }
+ store(position, value);
+ position = newPosition;
+ return this;
+ }
+
+ public ByteBuffer putInt (int index, int value) {
+ if (index < 0 || (long)index + 4 > limit) {
+ throw new IndexOutOfBoundsException();
+ }
+ store(index, value);
+ return this;
+ }
+
+ public ByteBuffer putLong (int index, long value) {
+ if (index < 0 || (long)index + 8 > limit) {
+ throw new IndexOutOfBoundsException();
+ }
+ store(index, value);
+ return this;
+ }
+
+ public ByteBuffer putLong (long value) {
+ int newPosition = position + 8;
+ if (newPosition > limit) {
+ throw new BufferOverflowException();
+ }
+ store(position, value);
+ position = newPosition;
+ return this;
+ }
+
+ public ByteBuffer putShort (int index, short value) {
+ if (index < 0 || (long)index + 2 > limit) {
+ throw new IndexOutOfBoundsException();
+ }
+ store(index, value);
+ return this;
+ }
+
+ public ByteBuffer putShort (short value) {
+ int newPosition = position + 2;
+ if (newPosition > limit) {
+ throw new BufferOverflowException();
+ }
+ store(position, value);
+ position = newPosition;
+ return this;
+ }
+
+ public ByteBuffer slice () {
+ ReadWriteHeapByteBuffer slice = new ReadWriteHeapByteBuffer(backingArray, remaining(), offset + position);
+ slice.order = order;
+ return slice;
+ }
}
diff --git a/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/java/nio/ReadWriteIntArrayBuffer.java b/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/java/nio/ReadWriteIntArrayBuffer.java
index 005e45b4dd4..34592717e56 100644
--- a/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/java/nio/ReadWriteIntArrayBuffer.java
+++ b/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/java/nio/ReadWriteIntArrayBuffer.java
@@ -17,106 +17,98 @@
package java.nio;
-/**
- * IntArrayBuffer, ReadWriteIntArrayBuffer and ReadOnlyIntArrayBuffer compose
- * the implementation of array based int buffers.
+/** IntArrayBuffer, ReadWriteIntArrayBuffer and ReadOnlyIntArrayBuffer compose the implementation of array based int buffers.
*
* ReadWriteIntArrayBuffer extends IntArrayBuffer with all the write methods.
*
*
* This class is marked final for runtime performance.
- *
- *
- */
+ * */
final class ReadWriteIntArrayBuffer extends IntArrayBuffer {
- static ReadWriteIntArrayBuffer copy(IntArrayBuffer other, int markOfOther) {
- ReadWriteIntArrayBuffer buf = new ReadWriteIntArrayBuffer(other
- .capacity(), other.backingArray, other.offset);
- buf.limit = other.limit();
- buf.position = other.position();
- buf.mark = markOfOther;
- return buf;
- }
-
- ReadWriteIntArrayBuffer(int[] array) {
- super(array);
- }
-
- ReadWriteIntArrayBuffer(int capacity) {
- super(capacity);
- }
-
- ReadWriteIntArrayBuffer(int capacity, int[] backingArray, int arrayOffset) {
- super(capacity, backingArray, arrayOffset);
- }
-
- public IntBuffer asReadOnlyBuffer() {
- return ReadOnlyIntArrayBuffer.copy(this, mark);
- }
-
- public IntBuffer compact() {
- System.arraycopy(backingArray, position + offset, backingArray, offset,
- remaining());
- position = limit - position;
- limit = capacity;
- mark = UNSET_MARK;
- return this;
- }
-
- public IntBuffer duplicate() {
- return copy(this, mark);
- }
-
- public boolean isReadOnly() {
- return false;
- }
-
- protected int[] protectedArray() {
- return backingArray;
- }
-
- protected int protectedArrayOffset() {
- return offset;
- }
-
- protected boolean protectedHasArray() {
- return true;
- }
-
- public IntBuffer put(int c) {
- if (position == limit) {
- throw new BufferOverflowException();
- }
- backingArray[offset + position++] = c;
- return this;
- }
-
- public IntBuffer put(int index, int c) {
- if (index < 0 || index >= limit) {
- throw new IndexOutOfBoundsException();
- }
- backingArray[offset + index] = c;
- return this;
- }
-
- public IntBuffer put(int[] src, int off, int len) {
- int length = src.length;
- if (off < 0 || len < 0 || (long)off + (long)len > length) {
- throw new IndexOutOfBoundsException();
- }
- if (len > remaining()) {
- throw new BufferOverflowException();
- }
- System.arraycopy(src, off, backingArray, offset
- + position, len);
- position += len;
- return this;
- }
-
- public IntBuffer slice() {
- return new ReadWriteIntArrayBuffer(remaining(), backingArray, offset
- + position);
- }
+ static ReadWriteIntArrayBuffer copy (IntArrayBuffer other, int markOfOther) {
+ ReadWriteIntArrayBuffer buf = new ReadWriteIntArrayBuffer(other.capacity(), other.backingArray, other.offset);
+ buf.limit = other.limit();
+ buf.position = other.position();
+ buf.mark = markOfOther;
+ return buf;
+ }
+
+ ReadWriteIntArrayBuffer (int[] array) {
+ super(array);
+ }
+
+ ReadWriteIntArrayBuffer (int capacity) {
+ super(capacity);
+ }
+
+ ReadWriteIntArrayBuffer (int capacity, int[] backingArray, int arrayOffset) {
+ super(capacity, backingArray, arrayOffset);
+ }
+
+ public IntBuffer asReadOnlyBuffer () {
+ return ReadOnlyIntArrayBuffer.copy(this, mark);
+ }
+
+ public IntBuffer compact () {
+ System.arraycopy(backingArray, position + offset, backingArray, offset, remaining());
+ position = limit - position;
+ limit = capacity;
+ mark = UNSET_MARK;
+ return this;
+ }
+
+ public IntBuffer duplicate () {
+ return copy(this, mark);
+ }
+
+ public boolean isReadOnly () {
+ return false;
+ }
+
+ protected int[] protectedArray () {
+ return backingArray;
+ }
+
+ protected int protectedArrayOffset () {
+ return offset;
+ }
+
+ protected boolean protectedHasArray () {
+ return true;
+ }
+
+ public IntBuffer put (int c) {
+ if (position == limit) {
+ throw new BufferOverflowException();
+ }
+ backingArray[offset + position++] = c;
+ return this;
+ }
+
+ public IntBuffer put (int index, int c) {
+ if (index < 0 || index >= limit) {
+ throw new IndexOutOfBoundsException();
+ }
+ backingArray[offset + index] = c;
+ return this;
+ }
+
+ public IntBuffer put (int[] src, int off, int len) {
+ int length = src.length;
+ if (off < 0 || len < 0 || (long)off + (long)len > length) {
+ throw new IndexOutOfBoundsException();
+ }
+ if (len > remaining()) {
+ throw new BufferOverflowException();
+ }
+ System.arraycopy(src, off, backingArray, offset + position, len);
+ position += len;
+ return this;
+ }
+
+ public IntBuffer slice () {
+ return new ReadWriteIntArrayBuffer(remaining(), backingArray, offset + position);
+ }
}
diff --git a/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/java/nio/ReadWriteLongArrayBuffer.java b/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/java/nio/ReadWriteLongArrayBuffer.java
index ff2c5886daf..bff78528e9c 100644
--- a/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/java/nio/ReadWriteLongArrayBuffer.java
+++ b/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/java/nio/ReadWriteLongArrayBuffer.java
@@ -17,106 +17,98 @@
package java.nio;
-/**
- * LongArrayBuffer, ReadWriteLongArrayBuffer and ReadOnlyLongArrayBuffer compose
- * the implementation of array based long buffers.
+/** LongArrayBuffer, ReadWriteLongArrayBuffer and ReadOnlyLongArrayBuffer compose the implementation of array based long buffers.
*
* ReadWriteLongArrayBuffer extends LongArrayBuffer with all the write methods.
*
*
* This class is marked final for runtime performance.
- *
- *
- */
+ * */
final class ReadWriteLongArrayBuffer extends LongArrayBuffer {
- static ReadWriteLongArrayBuffer copy(LongArrayBuffer other, int markOfOther) {
- ReadWriteLongArrayBuffer buf = new ReadWriteLongArrayBuffer(other
- .capacity(), other.backingArray, other.offset);
- buf.limit = other.limit();
- buf.position = other.position();
- buf.mark = markOfOther;
- return buf;
- }
-
- ReadWriteLongArrayBuffer(long[] array) {
- super(array);
- }
-
- ReadWriteLongArrayBuffer(int capacity) {
- super(capacity);
- }
-
- ReadWriteLongArrayBuffer(int capacity, long[] backingArray, int arrayOffset) {
- super(capacity, backingArray, arrayOffset);
- }
-
- public LongBuffer asReadOnlyBuffer() {
- return ReadOnlyLongArrayBuffer.copy(this, mark);
- }
-
- public LongBuffer compact() {
- System.arraycopy(backingArray, position + offset, backingArray, offset,
- remaining());
- position = limit - position;
- limit = capacity;
- mark = UNSET_MARK;
- return this;
- }
-
- public LongBuffer duplicate() {
- return copy(this, mark);
- }
-
- public boolean isReadOnly() {
- return false;
- }
-
- protected long[] protectedArray() {
- return backingArray;
- }
-
- protected int protectedArrayOffset() {
- return offset;
- }
-
- protected boolean protectedHasArray() {
- return true;
- }
-
- public LongBuffer put(long c) {
- if (position == limit) {
- throw new BufferOverflowException();
- }
- backingArray[offset + position++] = c;
- return this;
- }
-
- public LongBuffer put(int index, long c) {
- if (index < 0 || index >= limit) {
- throw new IndexOutOfBoundsException();
- }
- backingArray[offset + index] = c;
- return this;
- }
-
- public LongBuffer put(long[] src, int off, int len) {
- int length = src.length;
- if (off < 0 || len < 0 || (long)off + (long)len > length) {
- throw new IndexOutOfBoundsException();
- }
- if (len > remaining()) {
- throw new BufferOverflowException();
- }
- System.arraycopy(src, off, backingArray, offset
- + position, len);
- position += len;
- return this;
- }
-
- public LongBuffer slice() {
- return new ReadWriteLongArrayBuffer(remaining(), backingArray, offset
- + position);
- }
+ static ReadWriteLongArrayBuffer copy (LongArrayBuffer other, int markOfOther) {
+ ReadWriteLongArrayBuffer buf = new ReadWriteLongArrayBuffer(other.capacity(), other.backingArray, other.offset);
+ buf.limit = other.limit();
+ buf.position = other.position();
+ buf.mark = markOfOther;
+ return buf;
+ }
+
+ ReadWriteLongArrayBuffer (long[] array) {
+ super(array);
+ }
+
+ ReadWriteLongArrayBuffer (int capacity) {
+ super(capacity);
+ }
+
+ ReadWriteLongArrayBuffer (int capacity, long[] backingArray, int arrayOffset) {
+ super(capacity, backingArray, arrayOffset);
+ }
+
+ public LongBuffer asReadOnlyBuffer () {
+ return ReadOnlyLongArrayBuffer.copy(this, mark);
+ }
+
+ public LongBuffer compact () {
+ System.arraycopy(backingArray, position + offset, backingArray, offset, remaining());
+ position = limit - position;
+ limit = capacity;
+ mark = UNSET_MARK;
+ return this;
+ }
+
+ public LongBuffer duplicate () {
+ return copy(this, mark);
+ }
+
+ public boolean isReadOnly () {
+ return false;
+ }
+
+ protected long[] protectedArray () {
+ return backingArray;
+ }
+
+ protected int protectedArrayOffset () {
+ return offset;
+ }
+
+ protected boolean protectedHasArray () {
+ return true;
+ }
+
+ public LongBuffer put (long c) {
+ if (position == limit) {
+ throw new BufferOverflowException();
+ }
+ backingArray[offset + position++] = c;
+ return this;
+ }
+
+ public LongBuffer put (int index, long c) {
+ if (index < 0 || index >= limit) {
+ throw new IndexOutOfBoundsException();
+ }
+ backingArray[offset + index] = c;
+ return this;
+ }
+
+ public LongBuffer put (long[] src, int off, int len) {
+ int length = src.length;
+ if (off < 0 || len < 0 || (long)off + (long)len > length) {
+ throw new IndexOutOfBoundsException();
+ }
+ if (len > remaining()) {
+ throw new BufferOverflowException();
+ }
+ System.arraycopy(src, off, backingArray, offset + position, len);
+ position += len;
+ return this;
+ }
+
+ public LongBuffer slice () {
+ return new ReadWriteLongArrayBuffer(remaining(), backingArray, offset + position);
+ }
}
diff --git a/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/java/nio/ReadWriteShortArrayBuffer.java b/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/java/nio/ReadWriteShortArrayBuffer.java
index 193bdb314cf..7c32bcceec1 100644
--- a/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/java/nio/ReadWriteShortArrayBuffer.java
+++ b/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/java/nio/ReadWriteShortArrayBuffer.java
@@ -17,108 +17,99 @@
package java.nio;
-/**
- * ShortArrayBuffer, ReadWriteShortArrayBuffer and ReadOnlyShortArrayBuffer
- * compose the implementation of array based short buffers.
+/** ShortArrayBuffer, ReadWriteShortArrayBuffer and ReadOnlyShortArrayBuffer compose the implementation of array based short
+ * buffers.
*
- * ReadWriteShortArrayBuffer extends ShortArrayBuffer with all the write
- * methods.
+ * ReadWriteShortArrayBuffer extends ShortArrayBuffer with all the write methods.
*
*
* This class is marked final for runtime performance.
- *
- *
- */
+ * */
final class ReadWriteShortArrayBuffer extends ShortArrayBuffer {
- static ReadWriteShortArrayBuffer copy(ShortArrayBuffer other,
- int markOfOther) {
- ReadWriteShortArrayBuffer buf = new ReadWriteShortArrayBuffer(other
- .capacity(), other.backingArray, other.offset);
- buf.limit = other.limit();
- buf.position = other.position();
- buf.mark = markOfOther;
- return buf;
- }
-
- ReadWriteShortArrayBuffer(short[] array) {
- super(array);
- }
-
- ReadWriteShortArrayBuffer(int capacity) {
- super(capacity);
- }
-
- ReadWriteShortArrayBuffer(int capacity, short[] backingArray,
- int arrayOffset) {
- super(capacity, backingArray, arrayOffset);
- }
-
- public ShortBuffer asReadOnlyBuffer() {
- return ReadOnlyShortArrayBuffer.copy(this, mark);
- }
-
- public ShortBuffer compact() {
- System.arraycopy(backingArray, position + offset, backingArray, offset,
- remaining());
- position = limit - position;
- limit = capacity;
- mark = UNSET_MARK;
- return this;
- }
-
- public ShortBuffer duplicate() {
- return copy(this, mark);
- }
-
- public boolean isReadOnly() {
- return false;
- }
-
- protected short[] protectedArray() {
- return backingArray;
- }
-
- protected int protectedArrayOffset() {
- return offset;
- }
-
- protected boolean protectedHasArray() {
- return true;
- }
-
- public ShortBuffer put(short c) {
- if (position == limit) {
- throw new BufferOverflowException();
- }
- backingArray[offset + position++] = c;
- return this;
- }
-
- public ShortBuffer put(int index, short c) {
- if (index < 0 || index >= limit) {
- throw new IndexOutOfBoundsException();
- }
- backingArray[offset + index] = c;
- return this;
- }
-
- public ShortBuffer put(short[] src, int off, int len) {
- int length = src.length;
- if (off < 0 || len < 0 || (long)off + (long)len > length) {
- throw new IndexOutOfBoundsException();
- }
- if (len > remaining()) {
- throw new BufferOverflowException();
- }
- System.arraycopy(src, off, backingArray, offset+position, len);
- position += len;
- return this;
- }
-
- public ShortBuffer slice() {
- return new ReadWriteShortArrayBuffer(remaining(), backingArray, offset
- + position);
- }
+ static ReadWriteShortArrayBuffer copy (ShortArrayBuffer other, int markOfOther) {
+ ReadWriteShortArrayBuffer buf = new ReadWriteShortArrayBuffer(other.capacity(), other.backingArray, other.offset);
+ buf.limit = other.limit();
+ buf.position = other.position();
+ buf.mark = markOfOther;
+ return buf;
+ }
+
+ ReadWriteShortArrayBuffer (short[] array) {
+ super(array);
+ }
+
+ ReadWriteShortArrayBuffer (int capacity) {
+ super(capacity);
+ }
+
+ ReadWriteShortArrayBuffer (int capacity, short[] backingArray, int arrayOffset) {
+ super(capacity, backingArray, arrayOffset);
+ }
+
+ public ShortBuffer asReadOnlyBuffer () {
+ return ReadOnlyShortArrayBuffer.copy(this, mark);
+ }
+
+ public ShortBuffer compact () {
+ System.arraycopy(backingArray, position + offset, backingArray, offset, remaining());
+ position = limit - position;
+ limit = capacity;
+ mark = UNSET_MARK;
+ return this;
+ }
+
+ public ShortBuffer duplicate () {
+ return copy(this, mark);
+ }
+
+ public boolean isReadOnly () {
+ return false;
+ }
+
+ protected short[] protectedArray () {
+ return backingArray;
+ }
+
+ protected int protectedArrayOffset () {
+ return offset;
+ }
+
+ protected boolean protectedHasArray () {
+ return true;
+ }
+
+ public ShortBuffer put (short c) {
+ if (position == limit) {
+ throw new BufferOverflowException();
+ }
+ backingArray[offset + position++] = c;
+ return this;
+ }
+
+ public ShortBuffer put (int index, short c) {
+ if (index < 0 || index >= limit) {
+ throw new IndexOutOfBoundsException();
+ }
+ backingArray[offset + index] = c;
+ return this;
+ }
+
+ public ShortBuffer put (short[] src, int off, int len) {
+ int length = src.length;
+ if (off < 0 || len < 0 || (long)off + (long)len > length) {
+ throw new IndexOutOfBoundsException();
+ }
+ if (len > remaining()) {
+ throw new BufferOverflowException();
+ }
+ System.arraycopy(src, off, backingArray, offset + position, len);
+ position += len;
+ return this;
+ }
+
+ public ShortBuffer slice () {
+ return new ReadWriteShortArrayBuffer(remaining(), backingArray, offset + position);
+ }
}
diff --git a/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/java/nio/ShortArrayBuffer.java b/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/java/nio/ShortArrayBuffer.java
index 54f8adb45d1..fce335dfecd 100644
--- a/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/java/nio/ShortArrayBuffer.java
+++ b/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/java/nio/ShortArrayBuffer.java
@@ -17,72 +17,67 @@
package java.nio;
-/**
- * ShortArrayBuffer, ReadWriteShortArrayBuffer and ReadOnlyShortArrayBuffer
- * compose the implementation of array based short buffers.
+/** ShortArrayBuffer, ReadWriteShortArrayBuffer and ReadOnlyShortArrayBuffer compose the implementation of array based short
+ * buffers.
*
- * ShortArrayBuffer implements all the shared readonly methods and is extended
- * by the other two classes.
+ * ShortArrayBuffer implements all the shared readonly methods and is extended by the other two classes.
*
*
* All methods are marked final for runtime performance.
- *
- *
- */
+ * */
abstract class ShortArrayBuffer extends ShortBuffer {
- protected final short[] backingArray;
+ protected final short[] backingArray;
+
+ protected final int offset;
- protected final int offset;
+ ShortArrayBuffer (short[] array) {
+ this(array.length, array, 0);
+ }
- ShortArrayBuffer(short[] array) {
- this(array.length, array, 0);
- }
+ ShortArrayBuffer (int capacity) {
+ this(capacity, new short[capacity], 0);
+ }
- ShortArrayBuffer(int capacity) {
- this(capacity, new short[capacity], 0);
- }
+ ShortArrayBuffer (int capacity, short[] backingArray, int offset) {
+ super(capacity);
+ this.backingArray = backingArray;
+ this.offset = offset;
+ }
- ShortArrayBuffer(int capacity, short[] backingArray, int offset) {
- super(capacity);
- this.backingArray = backingArray;
- this.offset = offset;
- }
+ public final short get () {
+ if (position == limit) {
+ throw new BufferUnderflowException();
+ }
+ return backingArray[offset + position++];
+ }
- public final short get() {
- if (position == limit) {
- throw new BufferUnderflowException();
- }
- return backingArray[offset + position++];
- }
+ public final short get (int index) {
+ if (index < 0 || index >= limit) {
+ throw new IndexOutOfBoundsException();
+ }
+ return backingArray[offset + index];
+ }
- public final short get(int index) {
- if (index < 0 || index >= limit) {
- throw new IndexOutOfBoundsException();
- }
- return backingArray[offset + index];
- }
+ public final ShortBuffer get (short[] dest, int off, int len) {
+ int length = dest.length;
+ if (off < 0 || len < 0 || (long)off + (long)len > length) {
+ throw new IndexOutOfBoundsException();
+ }
+ if (len > remaining()) {
+ throw new BufferUnderflowException();
+ }
+ System.arraycopy(backingArray, offset + position, dest, off, len);
+ position += len;
+ return this;
+ }
- public final ShortBuffer get(short[] dest, int off, int len) {
- int length = dest.length;
- if (off < 0 || len < 0 || (long)off + (long)len > length) {
- throw new IndexOutOfBoundsException();
- }
- if (len > remaining()) {
- throw new BufferUnderflowException();
- }
- System.arraycopy(backingArray, offset + position, dest,
- off, len);
- position += len;
- return this;
- }
-
- public final boolean isDirect() {
- return false;
- }
+ public final boolean isDirect () {
+ return false;
+ }
- public final ByteOrder order() {
- return ByteOrder.nativeOrder();
- }
+ public final ByteOrder order () {
+ return ByteOrder.nativeOrder();
+ }
}
diff --git a/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/java/nio/ShortBuffer.java b/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/java/nio/ShortBuffer.java
index 200af2f6c14..6ab2eda7bdc 100644
--- a/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/java/nio/ShortBuffer.java
+++ b/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/java/nio/ShortBuffer.java
@@ -17,560 +17,412 @@
package java.nio;
-/**
- * A buffer of shorts.
+/** A buffer of shorts.
*
* A short buffer can be created in either of the following ways:
*
*
- * {@link #allocate(int) Allocate} a new short array and create a buffer
- * based on it;
- * {@link #wrap(short[]) Wrap} an existing short array to create a new
- * buffer;
- * Use {@link java.nio.ByteBuffer#asShortBuffer() ByteBuffer.asShortBuffer}
- * to create a short buffer based on a byte buffer.
+ * {@link #allocate(int) Allocate} a new short array and create a buffer based on it;
+ * {@link #wrap(short[]) Wrap} an existing short array to create a new buffer;
+ * Use {@link java.nio.ByteBuffer#asShortBuffer() ByteBuffer.asShortBuffer} to create a short buffer based on a byte buffer.
*
*
- * @since Android 1.0
- */
+ * @since Android 1.0 */
public abstract class ShortBuffer extends Buffer implements Comparable {
- /**
- * Creates a short buffer based on a newly allocated short array.
- *
- * @param capacity
- * the capacity of the new buffer.
- * @return the created short buffer.
- * @throws IllegalArgumentException
- * if {@code capacity} is less than zero.
- * @since Android 1.0
- */
- public static ShortBuffer allocate(int capacity) {
- if (capacity < 0) {
- throw new IllegalArgumentException();
- }
- return BufferFactory.newShortBuffer(capacity);
- }
-
- /**
- * Creates a new short buffer by wrapping the given short array.
- *
- * Calling this method has the same effect as
- * {@code wrap(array, 0, array.length)}.
- *
- *
- * @param array
- * the short array which the new buffer will be based on.
- * @return the created short buffer.
- * @since Android 1.0
- */
- public static ShortBuffer wrap(short[] array) {
- return wrap(array, 0, array.length);
- }
-
- /**
- * Creates a new short buffer by wrapping the given short array.
- *
- * The new buffer's position will be {@code start}, limit will be
- * {@code start + len}, capacity will be the length of the array.
- *
- *
- * @param array
- * the short array which the new buffer will be based on.
- * @param start
- * the start index, must not be negative and not greater than
- * {@code array.length}.
- * @param len
- * the length, must not be negative and not greater than
- * {@code array.length - start}.
- * @return the created short buffer.
- * @exception IndexOutOfBoundsException
- * if either {@code start} or {@code len} is invalid.
- * @since Android 1.0
- */
- public static ShortBuffer wrap(short[] array, int start, int len) {
- if (array == null) {
- throw new NullPointerException();
- }
- if (start< 0 || len < 0 || (long)start + (long)len > array.length) {
- throw new IndexOutOfBoundsException();
- }
-
- ShortBuffer buf = BufferFactory.newShortBuffer(array);
- buf.position = start;
- buf.limit = start + len;
-
- return buf;
- }
-
- /**
- * Constructs a {@code ShortBuffer} with given capacity.
- *
- * @param capacity
- * The capacity of the buffer
- */
- ShortBuffer(int capacity) {
- super(capacity);
- }
-
- /**
- * Returns the short array which this buffer is based on, if there is one.
- *
- * @return the short array which this buffer is based on.
- * @exception ReadOnlyBufferException
- * if this buffer is based on an array, but it is read-only.
- * @exception UnsupportedOperationException
- * if this buffer is not based on an array.
- * @since Android 1.0
- */
- public final short[] array() {
- return protectedArray();
- }
-
- /**
- * Returns the offset of the short array which this buffer is based on, if
- * there is one.
- *
- * The offset is the index of the array corresponding to the zero position
- * of the buffer.
- *
- *
- * @return the offset of the short array which this buffer is based on.
- * @exception ReadOnlyBufferException
- * if this buffer is based on an array, but it is read-only.
- * @exception UnsupportedOperationException
- * if this buffer is not based on an array.
- * @since Android 1.0
- */
- public final int arrayOffset() {
- return protectedArrayOffset();
- }
-
- /**
- * Returns a read-only buffer that shares its content with this buffer.
- *
- * The returned buffer is guaranteed to be a new instance, even if this
- * buffer is read-only itself. The new buffer's position, limit, capacity
- * and mark are the same as this buffer's.
- *
- *
- * The new buffer shares its content with this buffer, which means this
- * buffer's change of content will be visible to the new buffer. The two
- * buffer's position, limit and mark are independent.
- *
- *
- * @return a read-only version of this buffer.
- * @since Android 1.0
- */
- public abstract ShortBuffer asReadOnlyBuffer();
-
- /**
- * Compacts this short buffer.
- *
- * The remaining shorts will be moved to the head of the buffer, starting
- * from position zero. Then the position is set to {@code remaining()}; the
- * limit is set to capacity; the mark is cleared.
- *
- *
- * @return this buffer.
- * @exception ReadOnlyBufferException
- * if no changes may be made to the contents of this buffer.
- * @since Android 1.0
- */
- public abstract ShortBuffer compact();
-
- /**
- * Compare the remaining shorts of this buffer to another short buffer's
- * remaining shorts.
- *
- * @param otherBuffer
- * another short buffer.
- * @return a negative value if this is less than {@code otherBuffer}; 0 if
- * this equals to {@code otherBuffer}; a positive value if this is
- * greater than {@code otherBuffer}.
- * @exception ClassCastException
- * if {@code otherBuffer} is not a short buffer.
- * @since Android 1.0
- */
- public int compareTo(ShortBuffer otherBuffer) {
- int compareRemaining = (remaining() < otherBuffer.remaining()) ? remaining()
- : otherBuffer.remaining();
- int thisPos = position;
- int otherPos = otherBuffer.position;
- short thisByte, otherByte;
- while (compareRemaining > 0) {
- thisByte = get(thisPos);
- otherByte = otherBuffer.get(otherPos);
- if (thisByte != otherByte) {
- return thisByte < otherByte ? -1 : 1;
- }
- thisPos++;
- otherPos++;
- compareRemaining--;
- }
- return remaining() - otherBuffer.remaining();
- }
-
- /**
- * Returns a duplicated buffer that shares its content with this buffer.
- *
- * The duplicated buffer's position, limit, capacity and mark are the same
- * as this buffer. The duplicated buffer's read-only property and byte order
- * are the same as this buffer's.
- *
- *
- * The new buffer shares its content with this buffer, which means either
- * buffer's change of content will be visible to the other. The two buffer's
- * position, limit and mark are independent.
- *
- *
- * @return a duplicated buffer that shares its content with this buffer.
- * @since Android 1.0
- */
- public abstract ShortBuffer duplicate();
-
- /**
- * Checks whether this short buffer is equal to another object.
- *
- * If {@code other} is not a short buffer then {@code false} is returned.
- * Two short buffers are equal if and only if their remaining shorts are
- * exactly the same. Position, limit, capacity and mark are not considered.
- *
- *
- * @param other
- * the object to compare with this short buffer.
- * @return {@code true} if this short buffer is equal to {@code other},
- * {@code false} otherwise.
- * @since Android 1.0
- */
- public boolean equals(Object other) {
- if (!(other instanceof ShortBuffer)) {
- return false;
- }
- ShortBuffer otherBuffer = (ShortBuffer) other;
-
- if (remaining() != otherBuffer.remaining()) {
- return false;
- }
-
- int myPosition = position;
- int otherPosition = otherBuffer.position;
- boolean equalSoFar = true;
- while (equalSoFar && (myPosition < limit)) {
- equalSoFar = get(myPosition++) == otherBuffer.get(otherPosition++);
- }
-
- return equalSoFar;
- }
-
- /**
- * Returns the short at the current position and increases the position by
- * 1.
- *
- * @return the short at the current position.
- * @exception BufferUnderflowException
- * if the position is equal or greater than limit.
- * @since Android 1.0
- */
- public abstract short get();
-
- /**
- * Reads shorts from the current position into the specified short array and
- * increases the position by the number of shorts read.
- *
- * Calling this method has the same effect as
- * {@code get(dest, 0, dest.length)}.
- *
- *
- * @param dest
- * the destination short array.
- * @return this buffer.
- * @exception BufferUnderflowException
- * if {@code dest.length} is greater than {@code remaining()}.
- * @since Android 1.0
- */
- public ShortBuffer get(short[] dest) {
- return get(dest, 0, dest.length);
- }
-
- /**
- * Reads shorts from the current position into the specified short array,
- * starting from the specified offset, and increases the position by the
- * number of shorts read.
- *
- * @param dest
- * the target short array.
- * @param off
- * the offset of the short array, must not be negative and not
- * greater than {@code dest.length}.
- * @param len
- * the number of shorts to read, must be no less than zero and
- * not greater than {@code dest.length - off}.
- * @return this buffer.
- * @exception IndexOutOfBoundsException
- * if either {@code off} or {@code len} is invalid.
- * @exception BufferUnderflowException
- * if {@code len} is greater than {@code remaining()}.
- * @since Android 1.0
- */
- public ShortBuffer get(short[] dest, int off, int len) {
- int length = dest.length;
- if (off < 0 || len < 0 || (long)off + (long)len > length) {
- throw new IndexOutOfBoundsException();
- }
- if (len > remaining()) {
- throw new BufferUnderflowException();
- }
- for (int i = off; i < off + len; i++) {
- dest[i] = get();
- }
- return this;
- }
-
- /**
- * Returns the short at the specified index; the position is not changed.
- *
- * @param index
- * the index, must not be negative and less than limit.
- * @return a short at the specified index.
- * @exception IndexOutOfBoundsException
- * if index is invalid.
- * @since Android 1.0
- */
- public abstract short get(int index);
-
- /**
- * Indicates whether this buffer is based on a short array and is
- * read/write.
- *
- * @return {@code true} if this buffer is based on a short array and
- * provides read/write access, {@code false} otherwise.
- * @since Android 1.0
- */
- public final boolean hasArray() {
- return protectedHasArray();
- }
-
- /**
- * Calculates this buffer's hash code from the remaining chars. The
- * position, limit, capacity and mark don't affect the hash code.
- *
- * @return the hash code calculated from the remaining shorts.
- * @since Android 1.0
- */
- public int hashCode() {
- int myPosition = position;
- int hash = 0;
- while (myPosition < limit) {
- hash = hash + get(myPosition++);
- }
- return hash;
- }
-
- /**
- * Indicates whether this buffer is direct. A direct buffer will try its
- * best to take advantage of native memory APIs and it may not stay in the
- * Java heap, so it is not affected by garbage collection.
- *
- * A short buffer is direct if it is based on a byte buffer and the byte
- * buffer is direct.
- *
- *
- * @return {@code true} if this buffer is direct, {@code false} otherwise.
- * @since Android 1.0
- */
- public abstract boolean isDirect();
-
- /**
- * Returns the byte order used by this buffer when converting shorts from/to
- * bytes.
- *
- * If this buffer is not based on a byte buffer, then always return the
- * platform's native byte order.
- *
- *
- * @return the byte order used by this buffer when converting shorts from/to
- * bytes.
- * @since Android 1.0
- */
- public abstract ByteOrder order();
-
- /**
- * Child class implements this method to realize {@code array()}.
- *
- * @return see {@code array()}
- */
- abstract short[] protectedArray();
-
- /**
- * Child class implements this method to realize {@code arrayOffset()}.
- *
- * @return see {@code arrayOffset()}
- */
- abstract int protectedArrayOffset();
-
- /**
- * Child class implements this method to realize {@code hasArray()}.
- *
- * @return see {@code hasArray()}
- */
- abstract boolean protectedHasArray();
-
- /**
- * Writes the given short to the current position and increases the position
- * by 1.
- *
- * @param s
- * the short to write.
- * @return this buffer.
- * @exception BufferOverflowException
- * if position is equal or greater than limit.
- * @exception ReadOnlyBufferException
- * if no changes may be made to the contents of this buffer.
- * @since Android 1.0
- */
- public abstract ShortBuffer put(short s);
-
- /**
- * Writes shorts from the given short array to the current position and
- * increases the position by the number of shorts written.
- *
- * Calling this method has the same effect as
- * {@code put(src, 0, src.length)}.
- *
- *
- * @param src
- * the source short array.
- * @return this buffer.
- * @exception BufferOverflowException
- * if {@code remaining()} is less than {@code src.length}.
- * @exception ReadOnlyBufferException
- * if no changes may be made to the contents of this buffer.
- * @since Android 1.0
- */
- public final ShortBuffer put(short[] src) {
- return put(src, 0, src.length);
- }
-
- /**
- * Writes shorts from the given short array, starting from the specified
- * offset, to the current position and increases the position by the number
- * of shorts written.
- *
- * @param src
- * the source short array.
- * @param off
- * the offset of short array, must not be negative and not
- * greater than {@code src.length}.
- * @param len
- * the number of shorts to write, must be no less than zero and
- * not greater than {@code src.length - off}.
- * @return this buffer.
- * @exception BufferOverflowException
- * if {@code remaining()} is less than {@code len}.
- * @exception IndexOutOfBoundsException
- * if either {@code off} or {@code len} is invalid.
- * @exception ReadOnlyBufferException
- * if no changes may be made to the contents of this buffer.
- * @since Android 1.0
- */
- public ShortBuffer put(short[] src, int off, int len) {
- int length = src.length;
- if (off < 0 || len < 0 || (long)off + (long)len > length) {
- throw new IndexOutOfBoundsException();
- }
-
- if (len > remaining()) {
- throw new BufferOverflowException();
- }
- for (int i = off; i < off + len; i++) {
- put(src[i]);
- }
- return this;
- }
-
- /**
- * Writes all the remaining shorts of the {@code src} short buffer to this
- * buffer's current position, and increases both buffers' position by the
- * number of shorts copied.
- *
- * @param src
- * the source short buffer.
- * @return this buffer.
- * @exception BufferOverflowException
- * if {@code src.remaining()} is greater than this buffer's
- * {@code remaining()}.
- * @exception IllegalArgumentException
- * if {@code src} is this buffer.
- * @exception ReadOnlyBufferException
- * if no changes may be made to the contents of this buffer.
- * @since Android 1.0
- */
- public ShortBuffer put(ShortBuffer src) {
- if (src == this) {
- throw new IllegalArgumentException();
- }
- if (src.remaining() > remaining()) {
- throw new BufferOverflowException();
- }
- short[] contents = new short[src.remaining()];
- src.get(contents);
- put(contents);
- return this;
- }
-
- /**
- * Writes a short to the specified index of this buffer; the position is not
- * changed.
- *
- * @param index
- * the index, must not be negative and less than the limit.
- * @param s
- * the short to write.
- * @return this buffer.
- * @exception IndexOutOfBoundsException
- * if index is invalid.
- * @exception ReadOnlyBufferException
- * if no changes may be made to the contents of this buffer.
- * @since Android 1.0
- */
- public abstract ShortBuffer put(int index, short s);
-
- /**
- * Returns a sliced buffer that shares its content with this buffer.
- *
- * The sliced buffer's capacity will be this buffer's {@code remaining()},
- * and its zero position will correspond to this buffer's current position.
- * The new buffer's position will be 0, limit will be its capacity, and its
- * mark is cleared. The new buffer's read-only property and byte order are
- * same as this buffer's.
- *
- *
- * The new buffer shares its content with this buffer, which means either
- * buffer's change of content will be visible to the other. The two buffer's
- * position, limit and mark are independent.
- *
- *
- * @return a sliced buffer that shares its content with this buffer.
- * @since Android 1.0
- */
- public abstract ShortBuffer slice();
-
- /**
- * Returns a string representing the state of this short buffer.
- *
- * @return a string representing the state of this short buffer.
- * @since Android 1.0
- */
- public String toString() {
- StringBuffer buf = new StringBuffer();
- buf.append(getClass().getName());
- buf.append(", status: capacity="); //$NON-NLS-1$
- buf.append(capacity());
- buf.append(" position="); //$NON-NLS-1$
- buf.append(position());
- buf.append(" limit="); //$NON-NLS-1$
- buf.append(limit());
- return buf.toString();
- }
+ /** Creates a short buffer based on a newly allocated short array.
+ *
+ * @param capacity the capacity of the new buffer.
+ * @return the created short buffer.
+ * @throws IllegalArgumentException if {@code capacity} is less than zero.
+ * @since Android 1.0 */
+ public static ShortBuffer allocate (int capacity) {
+ if (capacity < 0) {
+ throw new IllegalArgumentException();
+ }
+ return BufferFactory.newShortBuffer(capacity);
+ }
+
+ /** Creates a new short buffer by wrapping the given short array.
+ *
+ * Calling this method has the same effect as {@code wrap(array, 0, array.length)}.
+ *
+ *
+ * @param array the short array which the new buffer will be based on.
+ * @return the created short buffer.
+ * @since Android 1.0 */
+ public static ShortBuffer wrap (short[] array) {
+ return wrap(array, 0, array.length);
+ }
+
+ /** Creates a new short buffer by wrapping the given short array.
+ *
+ * The new buffer's position will be {@code start}, limit will be {@code start + len}, capacity will be the length of the
+ * array.
+ *
+ *
+ * @param array the short array which the new buffer will be based on.
+ * @param start the start index, must not be negative and not greater than {@code array.length}.
+ * @param len the length, must not be negative and not greater than {@code array.length - start}.
+ * @return the created short buffer.
+ * @exception IndexOutOfBoundsException if either {@code start} or {@code len} is invalid.
+ * @since Android 1.0 */
+ public static ShortBuffer wrap (short[] array, int start, int len) {
+ if (array == null) {
+ throw new NullPointerException();
+ }
+ if (start < 0 || len < 0 || (long)start + (long)len > array.length) {
+ throw new IndexOutOfBoundsException();
+ }
+
+ ShortBuffer buf = BufferFactory.newShortBuffer(array);
+ buf.position = start;
+ buf.limit = start + len;
+
+ return buf;
+ }
+
+ /** Constructs a {@code ShortBuffer} with given capacity.
+ *
+ * @param capacity The capacity of the buffer */
+ ShortBuffer (int capacity) {
+ super(capacity);
+ }
+
+ /** Returns the short array which this buffer is based on, if there is one.
+ *
+ * @return the short array which this buffer is based on.
+ * @exception ReadOnlyBufferException if this buffer is based on an array, but it is read-only.
+ * @exception UnsupportedOperationException if this buffer is not based on an array.
+ * @since Android 1.0 */
+ public final short[] array () {
+ return protectedArray();
+ }
+
+ /** Returns the offset of the short array which this buffer is based on, if there is one.
+ *
+ * The offset is the index of the array corresponding to the zero position of the buffer.
+ *
+ *
+ * @return the offset of the short array which this buffer is based on.
+ * @exception ReadOnlyBufferException if this buffer is based on an array, but it is read-only.
+ * @exception UnsupportedOperationException if this buffer is not based on an array.
+ * @since Android 1.0 */
+ public final int arrayOffset () {
+ return protectedArrayOffset();
+ }
+
+ /** Returns a read-only buffer that shares its content with this buffer.
+ *
+ * The returned buffer is guaranteed to be a new instance, even if this buffer is read-only itself. The new buffer's position,
+ * limit, capacity and mark are the same as this buffer's.
+ *
+ *
+ * The new buffer shares its content with this buffer, which means this buffer's change of content will be visible to the new
+ * buffer. The two buffer's position, limit and mark are independent.
+ *
+ *
+ * @return a read-only version of this buffer.
+ * @since Android 1.0 */
+ public abstract ShortBuffer asReadOnlyBuffer ();
+
+ /** Compacts this short buffer.
+ *
+ * The remaining shorts will be moved to the head of the buffer, starting from position zero. Then the position is set to
+ * {@code remaining()}; the limit is set to capacity; the mark is cleared.
+ *
+ *
+ * @return this buffer.
+ * @exception ReadOnlyBufferException if no changes may be made to the contents of this buffer.
+ * @since Android 1.0 */
+ public abstract ShortBuffer compact ();
+
+ /** Compare the remaining shorts of this buffer to another short buffer's remaining shorts.
+ *
+ * @param otherBuffer another short buffer.
+ * @return a negative value if this is less than {@code otherBuffer}; 0 if this equals to {@code otherBuffer}; a positive value
+ * if this is greater than {@code otherBuffer}.
+ * @exception ClassCastException if {@code otherBuffer} is not a short buffer.
+ * @since Android 1.0 */
+ public int compareTo (ShortBuffer otherBuffer) {
+ int compareRemaining = (remaining() < otherBuffer.remaining()) ? remaining() : otherBuffer.remaining();
+ int thisPos = position;
+ int otherPos = otherBuffer.position;
+ short thisByte, otherByte;
+ while (compareRemaining > 0) {
+ thisByte = get(thisPos);
+ otherByte = otherBuffer.get(otherPos);
+ if (thisByte != otherByte) {
+ return thisByte < otherByte ? -1 : 1;
+ }
+ thisPos++;
+ otherPos++;
+ compareRemaining--;
+ }
+ return remaining() - otherBuffer.remaining();
+ }
+
+ /** Returns a duplicated buffer that shares its content with this buffer.
+ *
+ * The duplicated buffer's position, limit, capacity and mark are the same as this buffer. The duplicated buffer's read-only
+ * property and byte order are the same as this buffer's.
+ *
+ *
+ * The new buffer shares its content with this buffer, which means either buffer's change of content will be visible to the
+ * other. The two buffer's position, limit and mark are independent.
+ *
+ *
+ * @return a duplicated buffer that shares its content with this buffer.
+ * @since Android 1.0 */
+ public abstract ShortBuffer duplicate ();
+
+ /** Checks whether this short buffer is equal to another object.
+ *
+ * If {@code other} is not a short buffer then {@code false} is returned. Two short buffers are equal if and only if their
+ * remaining shorts are exactly the same. Position, limit, capacity and mark are not considered.
+ *
+ *
+ * @param other the object to compare with this short buffer.
+ * @return {@code true} if this short buffer is equal to {@code other}, {@code false} otherwise.
+ * @since Android 1.0 */
+ public boolean equals (Object other) {
+ if (!(other instanceof ShortBuffer)) {
+ return false;
+ }
+ ShortBuffer otherBuffer = (ShortBuffer)other;
+
+ if (remaining() != otherBuffer.remaining()) {
+ return false;
+ }
+
+ int myPosition = position;
+ int otherPosition = otherBuffer.position;
+ boolean equalSoFar = true;
+ while (equalSoFar && (myPosition < limit)) {
+ equalSoFar = get(myPosition++) == otherBuffer.get(otherPosition++);
+ }
+
+ return equalSoFar;
+ }
+
+ /** Returns the short at the current position and increases the position by 1.
+ *
+ * @return the short at the current position.
+ * @exception BufferUnderflowException if the position is equal or greater than limit.
+ * @since Android 1.0 */
+ public abstract short get ();
+
+ /** Reads shorts from the current position into the specified short array and increases the position by the number of shorts
+ * read.
+ *
+ * Calling this method has the same effect as {@code get(dest, 0, dest.length)}.
+ *
+ *
+ * @param dest the destination short array.
+ * @return this buffer.
+ * @exception BufferUnderflowException if {@code dest.length} is greater than {@code remaining()}.
+ * @since Android 1.0 */
+ public ShortBuffer get (short[] dest) {
+ return get(dest, 0, dest.length);
+ }
+
+ /** Reads shorts from the current position into the specified short array, starting from the specified offset, and increases the
+ * position by the number of shorts read.
+ *
+ * @param dest the target short array.
+ * @param off the offset of the short array, must not be negative and not greater than {@code dest.length}.
+ * @param len the number of shorts to read, must be no less than zero and not greater than {@code dest.length - off}.
+ * @return this buffer.
+ * @exception IndexOutOfBoundsException if either {@code off} or {@code len} is invalid.
+ * @exception BufferUnderflowException if {@code len} is greater than {@code remaining()}.
+ * @since Android 1.0 */
+ public ShortBuffer get (short[] dest, int off, int len) {
+ int length = dest.length;
+ if (off < 0 || len < 0 || (long)off + (long)len > length) {
+ throw new IndexOutOfBoundsException();
+ }
+ if (len > remaining()) {
+ throw new BufferUnderflowException();
+ }
+ for (int i = off; i < off + len; i++) {
+ dest[i] = get();
+ }
+ return this;
+ }
+
+ /** Returns the short at the specified index; the position is not changed.
+ *
+ * @param index the index, must not be negative and less than limit.
+ * @return a short at the specified index.
+ * @exception IndexOutOfBoundsException if index is invalid.
+ * @since Android 1.0 */
+ public abstract short get (int index);
+
+ /** Indicates whether this buffer is based on a short array and is read/write.
+ *
+ * @return {@code true} if this buffer is based on a short array and provides read/write access, {@code false} otherwise.
+ * @since Android 1.0 */
+ public final boolean hasArray () {
+ return protectedHasArray();
+ }
+
+ /** Calculates this buffer's hash code from the remaining chars. The position, limit, capacity and mark don't affect the hash
+ * code.
+ *
+ * @return the hash code calculated from the remaining shorts.
+ * @since Android 1.0 */
+ public int hashCode () {
+ int myPosition = position;
+ int hash = 0;
+ while (myPosition < limit) {
+ hash = hash + get(myPosition++);
+ }
+ return hash;
+ }
+
+ /** Indicates whether this buffer is direct. A direct buffer will try its best to take advantage of native memory APIs and it
+ * may not stay in the Java heap, so it is not affected by garbage collection.
+ *
+ * A short buffer is direct if it is based on a byte buffer and the byte buffer is direct.
+ *
+ *
+ * @return {@code true} if this buffer is direct, {@code false} otherwise.
+ * @since Android 1.0 */
+ public abstract boolean isDirect ();
+
+ /** Returns the byte order used by this buffer when converting shorts from/to bytes.
+ *
+ * If this buffer is not based on a byte buffer, then always return the platform's native byte order.
+ *
+ *
+ * @return the byte order used by this buffer when converting shorts from/to bytes.
+ * @since Android 1.0 */
+ public abstract ByteOrder order ();
+
+ /** Child class implements this method to realize {@code array()}.
+ *
+ * @return see {@code array()} */
+ abstract short[] protectedArray ();
+
+ /** Child class implements this method to realize {@code arrayOffset()}.
+ *
+ * @return see {@code arrayOffset()} */
+ abstract int protectedArrayOffset ();
+
+ /** Child class implements this method to realize {@code hasArray()}.
+ *
+ * @return see {@code hasArray()} */
+ abstract boolean protectedHasArray ();
+
+ /** Writes the given short to the current position and increases the position by 1.
+ *
+ * @param s the short to write.
+ * @return this buffer.
+ * @exception BufferOverflowException if position is equal or greater than limit.
+ * @exception ReadOnlyBufferException if no changes may be made to the contents of this buffer.
+ * @since Android 1.0 */
+ public abstract ShortBuffer put (short s);
+
+ /** Writes shorts from the given short array to the current position and increases the position by the number of shorts written.
+ *
+ * Calling this method has the same effect as {@code put(src, 0, src.length)}.
+ *
+ *
+ * @param src the source short array.
+ * @return this buffer.
+ * @exception BufferOverflowException if {@code remaining()} is less than {@code src.length}.
+ * @exception ReadOnlyBufferException if no changes may be made to the contents of this buffer.
+ * @since Android 1.0 */
+ public final ShortBuffer put (short[] src) {
+ return put(src, 0, src.length);
+ }
+
+ /** Writes shorts from the given short array, starting from the specified offset, to the current position and increases the
+ * position by the number of shorts written.
+ *
+ * @param src the source short array.
+ * @param off the offset of short array, must not be negative and not greater than {@code src.length}.
+ * @param len the number of shorts to write, must be no less than zero and not greater than {@code src.length - off}.
+ * @return this buffer.
+ * @exception BufferOverflowException if {@code remaining()} is less than {@code len}.
+ * @exception IndexOutOfBoundsException if either {@code off} or {@code len} is invalid.
+ * @exception ReadOnlyBufferException if no changes may be made to the contents of this buffer.
+ * @since Android 1.0 */
+ public ShortBuffer put (short[] src, int off, int len) {
+ int length = src.length;
+ if (off < 0 || len < 0 || (long)off + (long)len > length) {
+ throw new IndexOutOfBoundsException();
+ }
+
+ if (len > remaining()) {
+ throw new BufferOverflowException();
+ }
+ for (int i = off; i < off + len; i++) {
+ put(src[i]);
+ }
+ return this;
+ }
+
+ /** Writes all the remaining shorts of the {@code src} short buffer to this buffer's current position, and increases both
+ * buffers' position by the number of shorts copied.
+ *
+ * @param src the source short buffer.
+ * @return this buffer.
+ * @exception BufferOverflowException if {@code src.remaining()} is greater than this buffer's {@code remaining()}.
+ * @exception IllegalArgumentException if {@code src} is this buffer.
+ * @exception ReadOnlyBufferException if no changes may be made to the contents of this buffer.
+ * @since Android 1.0 */
+ public ShortBuffer put (ShortBuffer src) {
+ if (src == this) {
+ throw new IllegalArgumentException();
+ }
+ if (src.remaining() > remaining()) {
+ throw new BufferOverflowException();
+ }
+ short[] contents = new short[src.remaining()];
+ src.get(contents);
+ put(contents);
+ return this;
+ }
+
+ /** Writes a short to the specified index of this buffer; the position is not changed.
+ *
+ * @param index the index, must not be negative and less than the limit.
+ * @param s the short to write.
+ * @return this buffer.
+ * @exception IndexOutOfBoundsException if index is invalid.
+ * @exception ReadOnlyBufferException if no changes may be made to the contents of this buffer.
+ * @since Android 1.0 */
+ public abstract ShortBuffer put (int index, short s);
+
+ /** Returns a sliced buffer that shares its content with this buffer.
+ *
+ * The sliced buffer's capacity will be this buffer's {@code remaining()}, and its zero position will correspond to this
+ * buffer's current position. The new buffer's position will be 0, limit will be its capacity, and its mark is cleared. The new
+ * buffer's read-only property and byte order are same as this buffer's.
+ *
+ *
+ * The new buffer shares its content with this buffer, which means either buffer's change of content will be visible to the
+ * other. The two buffer's position, limit and mark are independent.
+ *
+ *
+ * @return a sliced buffer that shares its content with this buffer.
+ * @since Android 1.0 */
+ public abstract ShortBuffer slice ();
+
+ /** Returns a string representing the state of this short buffer.
+ *
+ * @return a string representing the state of this short buffer.
+ * @since Android 1.0 */
+ public String toString () {
+ StringBuffer buf = new StringBuffer();
+ buf.append(getClass().getName());
+ buf.append(", status: capacity="); //$NON-NLS-1$
+ buf.append(capacity());
+ buf.append(" position="); //$NON-NLS-1$
+ buf.append(position());
+ buf.append(" limit="); //$NON-NLS-1$
+ buf.append(limit());
+ return buf.toString();
+ }
}
diff --git a/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/java/nio/ShortToByteBufferAdapter.java b/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/java/nio/ShortToByteBufferAdapter.java
index 325d7eaec90..868072cddd4 100644
--- a/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/java/nio/ShortToByteBufferAdapter.java
+++ b/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/java/nio/ShortToByteBufferAdapter.java
@@ -16,194 +16,189 @@
package java.nio;
-
//import org.apache.harmony.nio.internal.DirectBuffer;
//import org.apache.harmony.luni.platform.PlatformAddress;
-/**
- * This class wraps a byte buffer to be a short buffer.
+/** This class wraps a byte buffer to be a short buffer.
*
* Implementation notice:
*
- * After a byte buffer instance is wrapped, it becomes privately owned by
- * the adapter. It must NOT be accessed outside the adapter any more.
- * The byte buffer's position and limit are NOT linked with the adapter.
- * The adapter extends Buffer, thus has its own position and limit.
+ * After a byte buffer instance is wrapped, it becomes privately owned by the adapter. It must NOT be accessed outside the
+ * adapter any more.
+ * The byte buffer's position and limit are NOT linked with the adapter. The adapter extends Buffer, thus has its own position
+ * and limit.
*
- *
- */
+ * */
final class ShortToByteBufferAdapter extends ShortBuffer implements ByteBufferWrapper {
-//implements DirectBuffer {
-
- static ShortBuffer wrap(ByteBuffer byteBuffer) {
- return new ShortToByteBufferAdapter(byteBuffer.slice());
- }
-
- private final ByteBuffer byteBuffer;
-
- ShortToByteBufferAdapter(ByteBuffer byteBuffer) {
- super((byteBuffer.capacity() >> 1));
- this.byteBuffer = byteBuffer;
- this.byteBuffer.clear();
- }
-
-// public int getByteCapacity() {
-// if (byteBuffer instanceof DirectBuffer) {
-// return ((DirectBuffer) byteBuffer).getByteCapacity();
-// }
-// assert false : byteBuffer;
-// return -1;
-// }
+// implements DirectBuffer {
+
+ static ShortBuffer wrap (ByteBuffer byteBuffer) {
+ return new ShortToByteBufferAdapter(byteBuffer.slice());
+ }
+
+ private final ByteBuffer byteBuffer;
+
+ ShortToByteBufferAdapter (ByteBuffer byteBuffer) {
+ super((byteBuffer.capacity() >> 1));
+ this.byteBuffer = byteBuffer;
+ this.byteBuffer.clear();
+ }
+
+// public int getByteCapacity() {
+// if (byteBuffer instanceof DirectBuffer) {
+// return ((DirectBuffer) byteBuffer).getByteCapacity();
+// }
+// assert false : byteBuffer;
+// return -1;
+// }
//
-// public PlatformAddress getEffectiveAddress() {
-// if (byteBuffer instanceof DirectBuffer) {
-// return ((DirectBuffer) byteBuffer).getEffectiveAddress();
-// }
-// assert false : byteBuffer;
-// return null;
-// }
+// public PlatformAddress getEffectiveAddress() {
+// if (byteBuffer instanceof DirectBuffer) {
+// return ((DirectBuffer) byteBuffer).getEffectiveAddress();
+// }
+// assert false : byteBuffer;
+// return null;
+// }
//
-// public PlatformAddress getBaseAddress() {
-// if (byteBuffer instanceof DirectBuffer) {
-// return ((DirectBuffer) byteBuffer).getBaseAddress();
-// }
-// assert false : byteBuffer;
-// return null;
-// }
+// public PlatformAddress getBaseAddress() {
+// if (byteBuffer instanceof DirectBuffer) {
+// return ((DirectBuffer) byteBuffer).getBaseAddress();
+// }
+// assert false : byteBuffer;
+// return null;
+// }
//
-// public boolean isAddressValid() {
-// if (byteBuffer instanceof DirectBuffer) {
-// return ((DirectBuffer) byteBuffer).isAddressValid();
-// }
-// assert false : byteBuffer;
-// return false;
-// }
+// public boolean isAddressValid() {
+// if (byteBuffer instanceof DirectBuffer) {
+// return ((DirectBuffer) byteBuffer).isAddressValid();
+// }
+// assert false : byteBuffer;
+// return false;
+// }
//
-// public void addressValidityCheck() {
-// if (byteBuffer instanceof DirectBuffer) {
-// ((DirectBuffer) byteBuffer).addressValidityCheck();
-// } else {
-// assert false : byteBuffer;
-// }
-// }
+// public void addressValidityCheck() {
+// if (byteBuffer instanceof DirectBuffer) {
+// ((DirectBuffer) byteBuffer).addressValidityCheck();
+// } else {
+// assert false : byteBuffer;
+// }
+// }
//
-// public void free() {
-// if (byteBuffer instanceof DirectBuffer) {
-// ((DirectBuffer) byteBuffer).free();
-// } else {
-// assert false : byteBuffer;
-// }
-// }
-
- @Override
- public ShortBuffer asReadOnlyBuffer() {
- ShortToByteBufferAdapter buf = new ShortToByteBufferAdapter(byteBuffer
- .asReadOnlyBuffer());
- buf.limit = limit;
- buf.position = position;
- buf.mark = mark;
- return buf;
- }
-
- @Override
- public ShortBuffer compact() {
- if (byteBuffer.isReadOnly()) {
- throw new ReadOnlyBufferException();
- }
- byteBuffer.limit(limit << 1);
- byteBuffer.position(position << 1);
- byteBuffer.compact();
- byteBuffer.clear();
- position = limit - position;
- limit = capacity;
- mark = UNSET_MARK;
- return this;
- }
-
- @Override
- public ShortBuffer duplicate() {
- ShortToByteBufferAdapter buf = new ShortToByteBufferAdapter(byteBuffer
- .duplicate());
- buf.limit = limit;
- buf.position = position;
- buf.mark = mark;
- return buf;
- }
-
- @Override
- public short get() {
- if (position == limit) {
- throw new BufferUnderflowException();
- }
- return byteBuffer.getShort(position++ << 1);
- }
-
- @Override
- public short get(int index) {
- if (index < 0 || index >= limit) {
- throw new IndexOutOfBoundsException();
- }
- return byteBuffer.getShort(index << 1);
- }
-
- @Override
- public boolean isDirect() {
- return byteBuffer.isDirect();
- }
-
- @Override
- public boolean isReadOnly() {
- return byteBuffer.isReadOnly();
- }
-
- @Override
- public ByteOrder order() {
- return byteBuffer.order();
- }
-
- @Override
- protected short[] protectedArray() {
- throw new UnsupportedOperationException();
- }
-
- @Override
- protected int protectedArrayOffset() {
- throw new UnsupportedOperationException();
- }
-
- @Override
- protected boolean protectedHasArray() {
- return false;
- }
-
- @Override
- public ShortBuffer put(short c) {
- if (position == limit) {
- throw new BufferOverflowException();
- }
- byteBuffer.putShort(position++ << 1, c);
- return this;
- }
-
- @Override
- public ShortBuffer put(int index, short c) {
- if (index < 0 || index >= limit) {
- throw new IndexOutOfBoundsException();
- }
- byteBuffer.putShort(index << 1, c);
- return this;
- }
-
- @Override
- public ShortBuffer slice() {
- byteBuffer.limit(limit << 1);
- byteBuffer.position(position << 1);
- ShortBuffer result = new ShortToByteBufferAdapter(byteBuffer.slice());
- byteBuffer.clear();
- return result;
- }
-
- public ByteBuffer getByteBuffer() {
+// public void free() {
+// if (byteBuffer instanceof DirectBuffer) {
+// ((DirectBuffer) byteBuffer).free();
+// } else {
+// assert false : byteBuffer;
+// }
+// }
+
+ @Override
+ public ShortBuffer asReadOnlyBuffer () {
+ ShortToByteBufferAdapter buf = new ShortToByteBufferAdapter(byteBuffer.asReadOnlyBuffer());
+ buf.limit = limit;
+ buf.position = position;
+ buf.mark = mark;
+ return buf;
+ }
+
+ @Override
+ public ShortBuffer compact () {
+ if (byteBuffer.isReadOnly()) {
+ throw new ReadOnlyBufferException();
+ }
+ byteBuffer.limit(limit << 1);
+ byteBuffer.position(position << 1);
+ byteBuffer.compact();
+ byteBuffer.clear();
+ position = limit - position;
+ limit = capacity;
+ mark = UNSET_MARK;
+ return this;
+ }
+
+ @Override
+ public ShortBuffer duplicate () {
+ ShortToByteBufferAdapter buf = new ShortToByteBufferAdapter(byteBuffer.duplicate());
+ buf.limit = limit;
+ buf.position = position;
+ buf.mark = mark;
+ return buf;
+ }
+
+ @Override
+ public short get () {
+ if (position == limit) {
+ throw new BufferUnderflowException();
+ }
+ return byteBuffer.getShort(position++ << 1);
+ }
+
+ @Override
+ public short get (int index) {
+ if (index < 0 || index >= limit) {
+ throw new IndexOutOfBoundsException();
+ }
+ return byteBuffer.getShort(index << 1);
+ }
+
+ @Override
+ public boolean isDirect () {
+ return byteBuffer.isDirect();
+ }
+
+ @Override
+ public boolean isReadOnly () {
+ return byteBuffer.isReadOnly();
+ }
+
+ @Override
+ public ByteOrder order () {
+ return byteBuffer.order();
+ }
+
+ @Override
+ protected short[] protectedArray () {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ protected int protectedArrayOffset () {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ protected boolean protectedHasArray () {
+ return false;
+ }
+
+ @Override
+ public ShortBuffer put (short c) {
+ if (position == limit) {
+ throw new BufferOverflowException();
+ }
+ byteBuffer.putShort(position++ << 1, c);
+ return this;
+ }
+
+ @Override
+ public ShortBuffer put (int index, short c) {
+ if (index < 0 || index >= limit) {
+ throw new IndexOutOfBoundsException();
+ }
+ byteBuffer.putShort(index << 1, c);
+ return this;
+ }
+
+ @Override
+ public ShortBuffer slice () {
+ byteBuffer.limit(limit << 1);
+ byteBuffer.position(position << 1);
+ ShortBuffer result = new ShortToByteBufferAdapter(byteBuffer.slice());
+ byteBuffer.clear();
+ return result;
+ }
+
+ public ByteBuffer getByteBuffer () {
return byteBuffer;
}
diff --git a/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/java/nio/StringByteBuffer.java b/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/java/nio/StringByteBuffer.java
index f342cae24e0..a5a4885946c 100644
--- a/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/java/nio/StringByteBuffer.java
+++ b/backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/java/nio/StringByteBuffer.java
@@ -1,202 +1,203 @@
+
package java.nio;
import com.google.gwt.corp.compatibility.Numbers;
class StringByteBuffer extends BaseByteBuffer {
- private String s;
-
- StringByteBuffer(String s) {
- super(s.length());
- this.s = s;
- order(ByteOrder.LITTLE_ENDIAN);
- }
-
- StringByteBuffer(String s, int position, int limit) {
- this(s);
- this.position = position;
- this.limit = limit;
- }
-
- public ByteBuffer asReadOnlyBuffer() {
- return this;
- }
-
- byte[] protectedArray() {
- throw new UnsupportedOperationException();
- }
-
- int protectedArrayOffset() {
- throw new UnsupportedOperationException();
- }
-
- boolean protectedHasArray() {
- throw new UnsupportedOperationException();
- }
-
- @Override
- public ByteBuffer compact() {
- return this;
- }
-
- @Override
- public ByteBuffer duplicate() {
- return this;
- }
-
- @Override
- public byte get() {
- return get(position++);
- }
-
- @Override
- public byte get(int index) {
- return get(s, index);
- }
-
- public final double getDouble() {
- return Numbers.longBitsToDouble(getLong());
- }
-
- public final double getDouble(int index) {
- return Numbers.longBitsToDouble(getLong(index));
- }
-
- public final float getFloat() {
- return Numbers.intBitsToFloat(getInt());
- }
-
- public final float getFloat(int index) {
- return Numbers.intBitsToFloat(getInt(index));
- }
-
- public final int getInt() {
- int newPosition = position + 4;
- int result = loadInt(position);
- position = newPosition;
- return result;
- }
-
- public final int getInt(int index) {
- return loadInt(index);
- }
-
- public final long getLong() {
- throw new UnsupportedOperationException();
- }
-
- public final long getLong(int index) {
- throw new UnsupportedOperationException();
- }
-
- public final short getShort() {
- int newPosition = position + 2;
- short result = loadShort(position);
- position = newPosition;
- return result;
- }
-
- public final short getShort(int index) {
- return loadShort(index);
- }
-
- @Override
- public boolean isDirect() {
- return false;
- }
-
- @Override
- public ByteBuffer put(byte b) {
- throw new UnsupportedOperationException();
- }
-
- @Override
- public ByteBuffer put(int index, byte b) {
- throw new UnsupportedOperationException();
- }
-
- @Override
- public ByteBuffer putDouble(double value) {
- throw new UnsupportedOperationException();
- }
-
- @Override
- public ByteBuffer putDouble(int index, double value) {
- throw new UnsupportedOperationException();
- }
-
- @Override
- public ByteBuffer putFloat(float value) {
- throw new UnsupportedOperationException();
- }
-
- @Override
- public ByteBuffer putFloat(int index, float value) {
- throw new UnsupportedOperationException();
- }
-
- @Override
- public ByteBuffer putInt(int value) {
- throw new UnsupportedOperationException();
- }
-
- @Override
- public ByteBuffer putInt(int index, int value) {
- throw new UnsupportedOperationException();
- }
-
- @Override
- public ByteBuffer putLong(long value) {
- throw new UnsupportedOperationException();
- }
-
- @Override
- public ByteBuffer putLong(int index, long value) {
- throw new UnsupportedOperationException();
- }
-
- @Override
- public ByteBuffer putShort(short value) {
- throw new UnsupportedOperationException();
- }
-
- @Override
- public ByteBuffer putShort(int index, short value) {
- throw new UnsupportedOperationException();
- }
-
- @Override
- public ByteBuffer slice() {
- // TODO(jgw): I don't think this is right, but might work for our purposes.
- StringByteBuffer slice = new StringByteBuffer(s, position, limit);
- slice.order = order;
- return slice;
- }
-
- @Override
- public boolean isReadOnly() {
- return true;
- }
-
- private native byte get(String s, int i) /*-{
- var x = s.charCodeAt(i) & 0xff;
- if (x > 127) x -= 256;
- return x;
- }-*/;
-
- protected final int loadInt(int baseOffset) {
- int bytes = 0;
- for (int i = 3; i >= 0; i--) {
- bytes = bytes << 8;
- bytes = bytes | (get(baseOffset + i) & 0xFF);
- }
- return bytes;
- }
-
- protected final short loadShort(int baseOffset) {
- short bytes = 0;
- bytes = (short) (get(baseOffset + 1) << 8);
- bytes |= (get(baseOffset) & 0xFF);
- return bytes;
- }
+ private String s;
+
+ StringByteBuffer (String s) {
+ super(s.length());
+ this.s = s;
+ order(ByteOrder.LITTLE_ENDIAN);
+ }
+
+ StringByteBuffer (String s, int position, int limit) {
+ this(s);
+ this.position = position;
+ this.limit = limit;
+ }
+
+ public ByteBuffer asReadOnlyBuffer () {
+ return this;
+ }
+
+ byte[] protectedArray () {
+ throw new UnsupportedOperationException();
+ }
+
+ int protectedArrayOffset () {
+ throw new UnsupportedOperationException();
+ }
+
+ boolean protectedHasArray () {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public ByteBuffer compact () {
+ return this;
+ }
+
+ @Override
+ public ByteBuffer duplicate () {
+ return this;
+ }
+
+ @Override
+ public byte get () {
+ return get(position++);
+ }
+
+ @Override
+ public byte get (int index) {
+ return get(s, index);
+ }
+
+ public final double getDouble () {
+ return Numbers.longBitsToDouble(getLong());
+ }
+
+ public final double getDouble (int index) {
+ return Numbers.longBitsToDouble(getLong(index));
+ }
+
+ public final float getFloat () {
+ return Numbers.intBitsToFloat(getInt());
+ }
+
+ public final float getFloat (int index) {
+ return Numbers.intBitsToFloat(getInt(index));
+ }
+
+ public final int getInt () {
+ int newPosition = position + 4;
+ int result = loadInt(position);
+ position = newPosition;
+ return result;
+ }
+
+ public final int getInt (int index) {
+ return loadInt(index);
+ }
+
+ public final long getLong () {
+ throw new UnsupportedOperationException();
+ }
+
+ public final long getLong (int index) {
+ throw new UnsupportedOperationException();
+ }
+
+ public final short getShort () {
+ int newPosition = position + 2;
+ short result = loadShort(position);
+ position = newPosition;
+ return result;
+ }
+
+ public final short getShort (int index) {
+ return loadShort(index);
+ }
+
+ @Override
+ public boolean isDirect () {
+ return false;
+ }
+
+ @Override
+ public ByteBuffer put (byte b) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public ByteBuffer put (int index, byte b) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public ByteBuffer putDouble (double value) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public ByteBuffer putDouble (int index, double value) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public ByteBuffer putFloat (float value) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public ByteBuffer putFloat (int index, float value) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public ByteBuffer putInt (int value) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public ByteBuffer putInt (int index, int value) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public ByteBuffer putLong (long value) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public ByteBuffer putLong (int index, long value) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public ByteBuffer putShort (short value) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public ByteBuffer putShort (int index, short value) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public ByteBuffer slice () {
+ // TODO(jgw): I don't think this is right, but might work for our purposes.
+ StringByteBuffer slice = new StringByteBuffer(s, position, limit);
+ slice.order = order;
+ return slice;
+ }
+
+ @Override
+ public boolean isReadOnly () {
+ return true;
+ }
+
+ private native byte get (String s, int i) /*-{
+ var x = s.charCodeAt(i) & 0xff;
+ if (x > 127) x -= 256;
+ return x;
+ }-*/;
+
+ protected final int loadInt (int baseOffset) {
+ int bytes = 0;
+ for (int i = 3; i >= 0; i--) {
+ bytes = bytes << 8;
+ bytes = bytes | (get(baseOffset + i) & 0xFF);
+ }
+ return bytes;
+ }
+
+ protected final short loadShort (int baseOffset) {
+ short bytes = 0;
+ bytes = (short)(get(baseOffset + 1) << 8);
+ bytes |= (get(baseOffset) & 0xFF);
+ return bytes;
+ }
}
diff --git a/backends/gdx-openal/src/com/badlogic/gdx/backends/openal/JavaSoundAudioDevice.java b/backends/gdx-openal/src/com/badlogic/gdx/backends/openal/JavaSoundAudioDevice.java
index 9f1ad3478ce..30c57f046f3 100644
--- a/backends/gdx-openal/src/com/badlogic/gdx/backends/openal/JavaSoundAudioDevice.java
+++ b/backends/gdx-openal/src/com/badlogic/gdx/backends/openal/JavaSoundAudioDevice.java
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
+
package com.badlogic.gdx.backends.openal;
import javax.sound.sampled.AudioFormat;
@@ -22,9 +23,7 @@
import com.badlogic.gdx.audio.AudioDevice;
import com.badlogic.gdx.utils.GdxRuntimeException;
-/**
- * @author mzechner
- */
+/** @author mzechner */
public class JavaSoundAudioDevice implements AudioDevice {
private SourceDataLine line;
private final boolean isMono;
@@ -58,7 +57,7 @@ public void writeSamples (short[] samples, int offset, int numSamples) {
for (int i = offset, j = 0; i < offset + numSamples; i++, j += 2) {
short value = samples[i];
bytes[j] = (byte)(value & 0xff);
- bytes[j+1] = (byte)(value >> 8);
+ bytes[j + 1] = (byte)(value >> 8);
}
int writtenBytes = line.write(bytes, 0, numSamples * 2);
@@ -83,7 +82,8 @@ public void writeSamples (float[] samples, int offset, int numSamples) {
writtenBytes += line.write(bytes, writtenBytes, numSamples * 2 - writtenBytes);
}
- @Override public int getLatency () {
+ @Override
+ public int getLatency () {
return 0;
}
}
diff --git a/backends/gdx-openal/src/com/badlogic/gdx/backends/openal/JavaSoundAudioRecorder.java b/backends/gdx-openal/src/com/badlogic/gdx/backends/openal/JavaSoundAudioRecorder.java
index 0fb088bf775..20b29382ba4 100644
--- a/backends/gdx-openal/src/com/badlogic/gdx/backends/openal/JavaSoundAudioRecorder.java
+++ b/backends/gdx-openal/src/com/badlogic/gdx/backends/openal/JavaSoundAudioRecorder.java
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
+
package com.badlogic.gdx.backends.openal;
import javax.sound.sampled.AudioFormat;
@@ -23,9 +24,7 @@
import com.badlogic.gdx.audio.AudioRecorder;
import com.badlogic.gdx.utils.GdxRuntimeException;
-/**
- * @author mzechner
- */
+/** @author mzechner */
public class JavaSoundAudioRecorder implements AudioRecorder {
private TargetDataLine line;
private byte[] buffer = new byte[1024 * 4];
diff --git a/backends/gdx-openal/src/com/badlogic/gdx/backends/openal/Mp3.java b/backends/gdx-openal/src/com/badlogic/gdx/backends/openal/Mp3.java
index acfe066e556..40aaf0041cf 100644
--- a/backends/gdx-openal/src/com/badlogic/gdx/backends/openal/Mp3.java
+++ b/backends/gdx-openal/src/com/badlogic/gdx/backends/openal/Mp3.java
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
+
package com.badlogic.gdx.backends.openal;
import java.io.ByteArrayOutputStream;
@@ -26,9 +27,7 @@
import com.badlogic.gdx.files.FileHandle;
import com.badlogic.gdx.utils.GdxRuntimeException;
-/**
- * @author Nathan Sweet
- */
+/** @author Nathan Sweet */
public class Mp3 {
static public class Music extends OpenALMusic {
// Note: This uses a slightly modified version of JLayer.
@@ -43,12 +42,12 @@ public Music (OpenALAudio audio, FileHandle file) {
decoder = new MP3Decoder();
try {
Header header = bitstream.readFrame();
- if (header == null) throw new GdxRuntimeException("empty ogg");
+ if (header == null) throw new GdxRuntimeException("empty ogg");
int channels = header.mode() == Header.SINGLE_CHANNEL ? 1 : 2;
outputBuffer = new OutputBuffer(channels, false);
decoder.setOutputBuffer(outputBuffer);
- setup(channels, header.getSampleRate());
- } catch(BitstreamException e) {
+ setup(channels, header.getSampleRate());
+ } catch (BitstreamException e) {
throw new GdxRuntimeException("error while preloading mp3", e);
}
}
diff --git a/backends/gdx-openal/src/com/badlogic/gdx/backends/openal/Ogg.java b/backends/gdx-openal/src/com/badlogic/gdx/backends/openal/Ogg.java
index 1d82cc122e1..fca46199812 100644
--- a/backends/gdx-openal/src/com/badlogic/gdx/backends/openal/Ogg.java
+++ b/backends/gdx-openal/src/com/badlogic/gdx/backends/openal/Ogg.java
@@ -13,15 +13,14 @@
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
+
package com.badlogic.gdx.backends.openal;
import java.io.ByteArrayOutputStream;
import com.badlogic.gdx.files.FileHandle;
-/**
- * @author Nathan Sweet
- */
+/** @author Nathan Sweet */
public class Ogg {
static public class Music extends OpenALMusic {
private OggInputStream input;
diff --git a/backends/gdx-openal/src/com/badlogic/gdx/backends/openal/OggInputStream.java b/backends/gdx-openal/src/com/badlogic/gdx/backends/openal/OggInputStream.java
index 2a42fccb2e7..30c135de2bd 100644
--- a/backends/gdx-openal/src/com/badlogic/gdx/backends/openal/OggInputStream.java
+++ b/backends/gdx-openal/src/com/badlogic/gdx/backends/openal/OggInputStream.java
@@ -40,10 +40,8 @@
import com.jcraft.jorbis.DspState;
import com.jcraft.jorbis.Info;
-/**
- * An input stream to read Ogg Vorbis.
- * @author kevin
- */
+/** An input stream to read Ogg Vorbis.
+ * @author kevin */
public class OggInputStream extends InputStream {
/** The conversion buffer size */
private int convsize = 4096 * 4;
@@ -90,11 +88,9 @@ public class OggInputStream extends InputStream {
/** The total number of bytes */
private int total;
- /**
- * Create a new stream to decode OGG data
+ /** Create a new stream to decode OGG data
*
- * @param input The input stream from which to read the OGG file
- */
+ * @param input The input stream from which to read the OGG file */
public OggInputStream (InputStream input) {
this.input = input;
try {
@@ -106,11 +102,9 @@ public OggInputStream (InputStream input) {
init();
}
- /**
- * Get the number of bytes on the stream
+ /** Get the number of bytes on the stream
*
- * @return The number of the bytes on the stream
- */
+ * @return The number of the bytes on the stream */
public int getLength () {
return total;
}
@@ -123,33 +117,25 @@ public int getSampleRate () {
return oggInfo.rate;
}
- /**
- * Initialise the streams and thread involved in the streaming of OGG data
- */
+ /** Initialise the streams and thread involved in the streaming of OGG data */
private void init () {
initVorbis();
readPCM();
}
- /**
- * @see java.io.InputStream#available()
- */
+ /** @see java.io.InputStream#available() */
public int available () {
return endOfStream ? 0 : 1;
}
- /**
- * Initialise the vorbis decoding
- */
+ /** Initialise the vorbis decoding */
private void initVorbis () {
syncState.init();
}
- /**
- * Get a page and packet from that page
+ /** Get a page and packet from that page
*
- * @return True if there was a page available
- */
+ * @return True if there was a page available */
private boolean getPageAndPacket () {
// grab some data at the head of the stream. We want the first page
// (which is guaranteed to be small and only contain the Vorbis
@@ -274,9 +260,7 @@ private boolean getPageAndPacket () {
return true;
}
- /**
- * Decode the OGG file as shown in the jogg/jorbis examples
- */
+ /** Decode the OGG file as shown in the jogg/jorbis examples */
private void readPCM () {
boolean wrote = false;
diff --git a/backends/gdx-openal/src/com/badlogic/gdx/backends/openal/OpenALAudio.java b/backends/gdx-openal/src/com/badlogic/gdx/backends/openal/OpenALAudio.java
index ffde054388e..77e333bc1d7 100644
--- a/backends/gdx-openal/src/com/badlogic/gdx/backends/openal/OpenALAudio.java
+++ b/backends/gdx-openal/src/com/badlogic/gdx/backends/openal/OpenALAudio.java
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
+
package com.badlogic.gdx.backends.openal;
import java.nio.FloatBuffer;
@@ -29,13 +30,10 @@
import com.badlogic.gdx.utils.GdxRuntimeException;
import com.badlogic.gdx.utils.IntArray;
import com.badlogic.gdx.utils.ObjectMap;
-import com.badlogic.gdx.utils.Pool;
import static org.lwjgl.openal.AL10.*;
-/**
- * @author Nathan Sweet
- */
+/** @author Nathan Sweet */
public class OpenALAudio implements Audio {
private IntArray idleSources, allSources;
private ObjectMap> extensionToSoundClass = new ObjectMap();
diff --git a/backends/gdx-openal/src/com/badlogic/gdx/backends/openal/OpenALSound.java b/backends/gdx-openal/src/com/badlogic/gdx/backends/openal/OpenALSound.java
index dffce53e7d1..5d75b16b6ce 100644
--- a/backends/gdx-openal/src/com/badlogic/gdx/backends/openal/OpenALSound.java
+++ b/backends/gdx-openal/src/com/badlogic/gdx/backends/openal/OpenALSound.java
@@ -13,20 +13,17 @@
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
+
package com.badlogic.gdx.backends.openal;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
-import org.lwjgl.openal.AL11;
-
import com.badlogic.gdx.audio.Sound;
import static org.lwjgl.openal.AL10.*;
-/**
- * @author Nathan Sweet
- */
+/** @author Nathan Sweet */
public class OpenALSound implements Sound {
private int bufferID = -1;
private final OpenALAudio audio;
diff --git a/backends/gdx-openal/src/com/badlogic/gdx/backends/openal/Wav.java b/backends/gdx-openal/src/com/badlogic/gdx/backends/openal/Wav.java
index ee6e602f9ac..2c0101b8bf6 100644
--- a/backends/gdx-openal/src/com/badlogic/gdx/backends/openal/Wav.java
+++ b/backends/gdx-openal/src/com/badlogic/gdx/backends/openal/Wav.java
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
+
package com.badlogic.gdx.backends.openal;
import java.io.ByteArrayOutputStream;
diff --git a/demos/cuboc/cuboc-android/src/com/badlogic/cuboc/Cuboc.java b/demos/cuboc/cuboc-android/src/com/badlogic/cuboc/Cuboc.java
index 18f18f752a5..dc504b8b263 100644
--- a/demos/cuboc/cuboc-android/src/com/badlogic/cuboc/Cuboc.java
+++ b/demos/cuboc/cuboc-android/src/com/badlogic/cuboc/Cuboc.java
@@ -1,3 +1,4 @@
+
package com.badlogic.cuboc;
import android.os.Bundle;
@@ -7,14 +8,14 @@
import com.badlogic.gdx.backends.android.AndroidApplicationConfiguration;
public class Cuboc extends AndroidApplication {
- /** Called when the activity is first created. */
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- AndroidApplicationConfiguration config = new AndroidApplicationConfiguration();
- config.useAccelerometer = false;
- config.useCompass = false;
- config.useWakelock = true;
- initialize(new Cubocy(), config);
- }
-}
\ No newline at end of file
+ /** Called when the activity is first created. */
+ @Override
+ public void onCreate (Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ AndroidApplicationConfiguration config = new AndroidApplicationConfiguration();
+ config.useAccelerometer = false;
+ config.useCompass = false;
+ config.useWakelock = true;
+ initialize(new Cubocy(), config);
+ }
+}
diff --git a/demos/cuboc/cuboc/src/com/badlogic/cubocy/Bob.java b/demos/cuboc/cuboc/src/com/badlogic/cubocy/Bob.java
index 8c0948535ab..4a44fe94bb7 100644
--- a/demos/cuboc/cuboc/src/com/badlogic/cubocy/Bob.java
+++ b/demos/cuboc/cuboc/src/com/badlogic/cubocy/Bob.java
@@ -12,7 +12,7 @@ public class Bob {
static final int JUMP = 2;
static final int SPAWN = 3;
static final int DYING = 4;
- static final int DEAD = 5;
+ static final int DEAD = 5;
static final int LEFT = -1;
static final int RIGHT = 1;
static final float ACCELERATION = 20f;
@@ -32,7 +32,7 @@ public class Bob {
Map map;
boolean grounded = false;
- public Bob (Map map, float x, float y) {
+ public Bob (Map map, float x, float y) {
this.map = map;
pos.x = x;
pos.y = y;
@@ -47,52 +47,50 @@ public Bob (Map map, float x, float y) {
public void update (float deltaTime) {
processKeys();
- accel.y = -GRAVITY;
+ accel.y = -GRAVITY;
accel.mul(deltaTime);
vel.add(accel.x, accel.y);
- if(accel.x == 0) vel.x *= DAMP;
+ if (accel.x == 0) vel.x *= DAMP;
if (vel.x > MAX_VEL) vel.x = MAX_VEL;
- if (vel.x < -MAX_VEL) vel.x = -MAX_VEL;
- vel.mul(deltaTime);
- tryMove();
+ if (vel.x < -MAX_VEL) vel.x = -MAX_VEL;
+ vel.mul(deltaTime);
+ tryMove();
vel.mul(1.0f / deltaTime);
-
- if(state == SPAWN) {
- if(stateTime > 0.4f) {
+
+ if (state == SPAWN) {
+ if (stateTime > 0.4f) {
state = IDLE;
- }
+ }
}
-
- if(state == DYING) {
- if(stateTime > 0.4f) {
+
+ if (state == DYING) {
+ if (stateTime > 0.4f) {
state = DEAD;
- }
- }
-
- stateTime += deltaTime;
+ }
+ }
+
+ stateTime += deltaTime;
}
private void processKeys () {
- if(map.cube.state == Cube.CONTROLLED || state == SPAWN || state == DYING) return;
-
+ if (map.cube.state == Cube.CONTROLLED || state == SPAWN || state == DYING) return;
+
float x0 = (Gdx.input.getX(0) / (float)Gdx.graphics.getWidth()) * 480;
float x1 = (Gdx.input.getX(1) / (float)Gdx.graphics.getWidth()) * 480;
float y0 = 320 - (Gdx.input.getY(0) / (float)Gdx.graphics.getHeight()) * 320;
float y1 = 320 - (Gdx.input.getY(1) / (float)Gdx.graphics.getHeight()) * 320;
-
- boolean leftButton = (Gdx.input.isTouched(0) && x0 < 70) ||
- (Gdx.input.isTouched(1) && x1 < 70);
- boolean rightButton = (Gdx.input.isTouched(0) && x0 > 70 && x0 < 134) ||
- (Gdx.input.isTouched(1) && x1 > 70 && x1 < 134);
- boolean jumpButton = (Gdx.input.isTouched(0) && x0 > 416 && x0 < 480 && y0 < 64) ||
- (Gdx.input.isTouched(1) && x1 > 416 && x1 < 480 && y0 < 64);
-
- if ((Gdx.input.isKeyPressed(Keys.W) || jumpButton)&& state != JUMP) {
+
+ boolean leftButton = (Gdx.input.isTouched(0) && x0 < 70) || (Gdx.input.isTouched(1) && x1 < 70);
+ boolean rightButton = (Gdx.input.isTouched(0) && x0 > 70 && x0 < 134) || (Gdx.input.isTouched(1) && x1 > 70 && x1 < 134);
+ boolean jumpButton = (Gdx.input.isTouched(0) && x0 > 416 && x0 < 480 && y0 < 64)
+ || (Gdx.input.isTouched(1) && x1 > 416 && x1 < 480 && y0 < 64);
+
+ if ((Gdx.input.isKeyPressed(Keys.W) || jumpButton) && state != JUMP) {
state = JUMP;
- vel.y = JUMP_VELOCITY;
+ vel.y = JUMP_VELOCITY;
grounded = false;
}
-
+
if (Gdx.input.isKeyPressed(Keys.A) || leftButton) {
if (state != JUMP) state = RUN;
dir = LEFT;
@@ -107,40 +105,42 @@ private void processKeys () {
}
}
- Rectangle[] r = { new Rectangle(), new Rectangle(), new Rectangle(), new Rectangle(), new Rectangle() };
+ Rectangle[] r = {new Rectangle(), new Rectangle(), new Rectangle(), new Rectangle(), new Rectangle()};
- private void tryMove () {
+ private void tryMove () {
bounds.x += vel.x;
fetchCollidableRects();
- for(int i = 0; i < r.length; i++) {
+ for (int i = 0; i < r.length; i++) {
Rectangle rect = r[i];
- if(bounds.overlaps(rect)) {
- if(vel.x < 0) bounds.x = rect.x + rect.width + 0.01f;
- else bounds.x = rect.x - bounds.width - 0.01f;
+ if (bounds.overlaps(rect)) {
+ if (vel.x < 0)
+ bounds.x = rect.x + rect.width + 0.01f;
+ else
+ bounds.x = rect.x - bounds.width - 0.01f;
vel.x = 0;
}
- }
-
- bounds.y += vel.y;
+ }
+
+ bounds.y += vel.y;
fetchCollidableRects();
- for(int i = 0; i < r.length; i++) {
+ for (int i = 0; i < r.length; i++) {
Rectangle rect = r[i];
- if(bounds.overlaps(rect)) {
- if(vel.y < 0) {
- bounds.y = rect.y + rect.height + 0.01f;
+ if (bounds.overlaps(rect)) {
+ if (vel.y < 0) {
+ bounds.y = rect.y + rect.height + 0.01f;
grounded = true;
- if(state != DYING && state != SPAWN) state = Math.abs(accel.x) > 0.1f?RUN:IDLE;
- }
- else bounds.y = rect.y - bounds.height - 0.01f;
+ if (state != DYING && state != SPAWN) state = Math.abs(accel.x) > 0.1f ? RUN : IDLE;
+ } else
+ bounds.y = rect.y - bounds.height - 0.01f;
vel.y = 0;
}
- }
-
+ }
+
pos.x = bounds.x - 0.2f;
- pos.y = bounds.y;
+ pos.y = bounds.y;
}
-
- private void fetchCollidableRects() {
+
+ private void fetchCollidableRects () {
int p1x = (int)bounds.x;
int p1y = (int)Math.floor(bounds.y);
int p2x = (int)(bounds.x + bounds.width);
@@ -156,11 +156,11 @@ private void fetchCollidableRects() {
int tile3 = tiles[p3x][map.tiles[0].length - 1 - p3y];
int tile4 = tiles[p4x][map.tiles[0].length - 1 - p4y];
- if(state != DYING && (map.isDeadly(tile1) || map.isDeadly(tile2) || map.isDeadly(tile3) || map.isDeadly(tile4))) {
- state = DYING;
- stateTime = 0;
+ if (state != DYING && (map.isDeadly(tile1) || map.isDeadly(tile2) || map.isDeadly(tile3) || map.isDeadly(tile4))) {
+ state = DYING;
+ stateTime = 0;
}
-
+
if (tile1 == Map.TILE)
r[0].set(p1x, p1y, 1, 1);
else
@@ -177,14 +177,13 @@ private void fetchCollidableRects() {
r[3].set(p4x, p4y, 1, 1);
else
r[3].set(-1, -1, 0, 0);
-
- if(map.cube.state == Cube.FIXED) {
+
+ if (map.cube.state == Cube.FIXED) {
r[4].x = map.cube.bounds.x;
r[4].y = map.cube.bounds.y;
r[4].width = map.cube.bounds.width;
- r[4].height = map.cube.bounds.height;
- }
- else
- r[4].set(-1, -1, 0, 0);
+ r[4].height = map.cube.bounds.height;
+ } else
+ r[4].set(-1, -1, 0, 0);
}
}
diff --git a/demos/cuboc/cuboc/src/com/badlogic/cubocy/Cube.java b/demos/cuboc/cuboc/src/com/badlogic/cubocy/Cube.java
index e214336e9f7..e64b4626ed9 100644
--- a/demos/cuboc/cuboc/src/com/badlogic/cubocy/Cube.java
+++ b/demos/cuboc/cuboc/src/com/badlogic/cubocy/Cube.java
@@ -1,8 +1,6 @@
-package com.badlogic.cubocy;
-import org.lwjgl.opengl.Display;
+package com.badlogic.cubocy;
-import com.badlogic.gdx.Application.ApplicationType;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Input.Keys;
import com.badlogic.gdx.math.Rectangle;
@@ -15,8 +13,8 @@ public class Cube {
static final int DEAD = 3;
static final float ACCELERATION = 20;
static final float MAX_VELOCITY = 4;
- static final float DAMP = 0.80f;
-
+ static final float DAMP = 0.80f;
+
Map map;
Vector2 pos = new Vector2();
Vector2 accel = new Vector2();
@@ -24,11 +22,11 @@ public class Cube {
Rectangle bounds = new Rectangle();
int state = FOLLOW;
float stateTime = 0;
- Rectangle controllButtonRect = new Rectangle(480-64, 320-64, 64, 64);
- Rectangle followButtonRect = new Rectangle(480-64, 320-138, 64, 64);
+ Rectangle controllButtonRect = new Rectangle(480 - 64, 320 - 64, 64, 64);
+ Rectangle followButtonRect = new Rectangle(480 - 64, 320 - 138, 64, 64);
Rectangle dpadRect = new Rectangle(0, 0, 128, 128);
-
- public Cube(Map map, float x, float y) {
+
+ public Cube (Map map, float x, float y) {
this.map = map;
this.pos.x = x;
this.pos.y = y;
@@ -36,110 +34,111 @@ public Cube(Map map, float x, float y) {
this.bounds.y = pos.y + 0.2f;
this.bounds.width = this.bounds.height = 1.0f;
}
-
+
Vector2 target = new Vector2();
- public void update(float deltaTime) {
+
+ public void update (float deltaTime) {
processKeys();
-
- if(state == FOLLOW) {
+
+ if (state == FOLLOW) {
target.set(map.bob.pos);
- if(map.bob.dir == Bob.RIGHT) target.x--;
- if(map.bob.dir == Bob.LEFT) target.x++;
+ if (map.bob.dir == Bob.RIGHT) target.x--;
+ if (map.bob.dir == Bob.LEFT) target.x++;
target.y += 0.2f;
-
+
vel.set(target).sub(pos).mul(Math.min(4, pos.dst(target)) * deltaTime);
- if(vel.len() > MAX_VELOCITY) vel.nor().mul(MAX_VELOCITY);
+ if (vel.len() > MAX_VELOCITY) vel.nor().mul(MAX_VELOCITY);
tryMove();
}
-
- if(state == CONTROLLED) {
+
+ if (state == CONTROLLED) {
accel.mul(deltaTime);
vel.add(accel.x, accel.y);
- if(accel.x == 0) vel.x *= DAMP;
- if(accel.y == 0) vel.y *= DAMP;
+ if (accel.x == 0) vel.x *= DAMP;
+ if (accel.y == 0) vel.y *= DAMP;
if (vel.x > MAX_VELOCITY) vel.x = MAX_VELOCITY;
if (vel.x < -MAX_VELOCITY) vel.x = -MAX_VELOCITY;
if (vel.y > MAX_VELOCITY) vel.y = MAX_VELOCITY;
if (vel.y < -MAX_VELOCITY) vel.y = -MAX_VELOCITY;
- vel.mul(deltaTime);
- tryMove();
+ vel.mul(deltaTime);
+ tryMove();
vel.mul(1.0f / deltaTime);
}
-
- if(state == FIXED) {
-// if(stateTime > 5.0f) {
-// stateTime = 0;
-// state = FOLLOW;
-// }
+
+ if (state == FIXED) {
+// if(stateTime > 5.0f) {
+// stateTime = 0;
+// state = FOLLOW;
+// }
}
-
+
stateTime += deltaTime;
}
-
+
private void processKeys () {
float x0 = (Gdx.input.getX(0) / (float)Gdx.graphics.getWidth()) * 480;
float x1 = (Gdx.input.getX(1) / (float)Gdx.graphics.getWidth()) * 480;
float y0 = 320 - (Gdx.input.getY(0) / (float)Gdx.graphics.getHeight()) * 320;
float y1 = 320 - (Gdx.input.getY(1) / (float)Gdx.graphics.getHeight()) * 320;
- boolean controlButton = (Gdx.input.isTouched(0) && controllButtonRect.contains(x0, y0)) ||
- (Gdx.input.isTouched(1) && controllButtonRect.contains(x1, y1));
- boolean followButton = (Gdx.input.isTouched(0) && followButtonRect.contains(x0, y0)) ||
- (Gdx.input.isTouched(1) && followButtonRect.contains(x1, y1));
-
- if((Gdx.input.isKeyPressed(Keys.SPACE) || controlButton) && state == FOLLOW && stateTime > 0.5f) {
+ boolean controlButton = (Gdx.input.isTouched(0) && controllButtonRect.contains(x0, y0))
+ || (Gdx.input.isTouched(1) && controllButtonRect.contains(x1, y1));
+ boolean followButton = (Gdx.input.isTouched(0) && followButtonRect.contains(x0, y0))
+ || (Gdx.input.isTouched(1) && followButtonRect.contains(x1, y1));
+
+ if ((Gdx.input.isKeyPressed(Keys.SPACE) || controlButton) && state == FOLLOW && stateTime > 0.5f) {
stateTime = 0;
state = CONTROLLED;
return;
- }
-
- if((Gdx.input.isKeyPressed(Keys.SPACE) || controlButton) && state == CONTROLLED && stateTime > 0.5f) {
+ }
+
+ if ((Gdx.input.isKeyPressed(Keys.SPACE) || controlButton) && state == CONTROLLED && stateTime > 0.5f) {
stateTime = 0;
state = FIXED;
return;
}
-
- if((Gdx.input.isKeyPressed(Keys.SPACE) || controlButton) && state == FIXED && stateTime > 0.5f) {
+
+ if ((Gdx.input.isKeyPressed(Keys.SPACE) || controlButton) && state == FIXED && stateTime > 0.5f) {
stateTime = 0;
state = CONTROLLED;
return;
- }
-
- if((Gdx.input.isKeyPressed(Keys.F) || followButton) && stateTime > 0.5f) {
+ }
+
+ if ((Gdx.input.isKeyPressed(Keys.F) || followButton) && stateTime > 0.5f) {
stateTime = 0;
state = FOLLOW;
return;
- }
-
+ }
+
boolean touch0 = Gdx.input.isTouched(0);
boolean touch1 = Gdx.input.isTouched(1);
boolean left = (touch0 && x0 < 60) || (touch1 && x1 < 60);
boolean right = (touch0 && (x0 > 80 && x0 < 128)) || (touch1 && (x1 > 80 && x1 < 128));
boolean down = (touch0 && (y0 < 60)) || (touch1 && (y1 < 60));
- boolean up = (touch0 && (y0 > 80 && x0 < 128)) || (touch1 && (y1 > 80 && y1 < 128));
-
- if(state == CONTROLLED) {
- if (Gdx.input.isKeyPressed(Keys.A)) {
+ boolean up = (touch0 && (y0 > 80 && x0 < 128)) || (touch1 && (y1 > 80 && y1 < 128));
+
+ if (state == CONTROLLED) {
+ if (Gdx.input.isKeyPressed(Keys.A)) {
accel.x = -ACCELERATION;
- } else if (Gdx.input.isKeyPressed(Keys.D) || right ) {
+ } else if (Gdx.input.isKeyPressed(Keys.D) || right) {
accel.x = ACCELERATION;
- } else {
+ } else {
accel.x = 0;
}
-
- if (Gdx.input.isKeyPressed(Keys.W) || up) {
+
+ if (Gdx.input.isKeyPressed(Keys.W) || up) {
accel.y = ACCELERATION;
- } else if (Gdx.input.isKeyPressed(Keys.S) || down) {
+ } else if (Gdx.input.isKeyPressed(Keys.S) || down) {
accel.y = -ACCELERATION;
- } else {
+ } else {
accel.y = 0;
}
-
- if(touch0) {
- if(dpadRect.contains(x0, y0)) {
+
+ if (touch0) {
+ if (dpadRect.contains(x0, y0)) {
float x = (x0 - 64) / 64;
float y = (y0 - 64) / 64;
- float len = (float)Math.sqrt(x*x + y*y);
- if(len != 0) {
+ float len = (float)Math.sqrt(x * x + y * y);
+ if (len != 0) {
x /= len;
y /= len;
} else {
@@ -152,40 +151,44 @@ private void processKeys () {
accel.x = 0;
accel.y = 0;
}
- }
+ }
}
}
-
- Rectangle[] r = { new Rectangle(), new Rectangle(), new Rectangle(), new Rectangle() };
- private void tryMove () {
+ Rectangle[] r = {new Rectangle(), new Rectangle(), new Rectangle(), new Rectangle()};
+
+ private void tryMove () {
bounds.x += vel.x;
fetchCollidableRects();
- for(int i = 0; i < r.length; i++) {
+ for (int i = 0; i < r.length; i++) {
Rectangle rect = r[i];
- if(bounds.overlaps(rect)) {
- if(vel.x < 0) bounds.x = rect.x + rect.width + 0.01f;
- else bounds.x = rect.x - bounds.width - 0.01f;
+ if (bounds.overlaps(rect)) {
+ if (vel.x < 0)
+ bounds.x = rect.x + rect.width + 0.01f;
+ else
+ bounds.x = rect.x - bounds.width - 0.01f;
vel.x = 0;
}
- }
-
- bounds.y += vel.y;
+ }
+
+ bounds.y += vel.y;
fetchCollidableRects();
- for(int i = 0; i < r.length; i++) {
+ for (int i = 0; i < r.length; i++) {
Rectangle rect = r[i];
- if(bounds.overlaps(rect)) {
- if(vel.y < 0) { bounds.y = rect.y + rect.height + 0.01f; }
- else bounds.y = rect.y - bounds.height - 0.01f;
+ if (bounds.overlaps(rect)) {
+ if (vel.y < 0) {
+ bounds.y = rect.y + rect.height + 0.01f;
+ } else
+ bounds.y = rect.y - bounds.height - 0.01f;
vel.y = 0;
}
- }
-
+ }
+
pos.x = bounds.x - 0.2f;
- pos.y = bounds.y - 0.2f;
+ pos.y = bounds.y - 0.2f;
}
-
- private void fetchCollidableRects() {
+
+ private void fetchCollidableRects () {
int p1x = (int)bounds.x;
int p1y = (int)Math.floor(bounds.y);
int p2x = (int)(bounds.x + bounds.width);
@@ -218,9 +221,9 @@ private void fetchCollidableRects() {
else
r[3].set(-1, -1, 0, 0);
}
-
- public void setControlled() {
- if(state == FOLLOW) {
+
+ public void setControlled () {
+ if (state == FOLLOW) {
state = CONTROLLED;
stateTime = 0;
}
diff --git a/demos/cuboc/cuboc/src/com/badlogic/cubocy/Cubocy.java b/demos/cuboc/cuboc/src/com/badlogic/cubocy/Cubocy.java
index bbb06953b47..d2245f3c823 100644
--- a/demos/cuboc/cuboc/src/com/badlogic/cubocy/Cubocy.java
+++ b/demos/cuboc/cuboc/src/com/badlogic/cubocy/Cubocy.java
@@ -1,17 +1,17 @@
+
package com.badlogic.cubocy;
import com.badlogic.cubocy.screens.GameScreen;
import com.badlogic.gdx.Game;
-import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.backends.lwjgl.LwjglApplication;
-import com.badlogic.gdx.input.RemoteInput;
-public class Cubocy extends Game {
- public static void main(String[] argv) {
+public class Cubocy extends Game {
+ public static void main (String[] argv) {
new LwjglApplication(new Cubocy(), "Cubocy", 480, 320, false);
}
- @Override public void create () {
+ @Override
+ public void create () {
setScreen(new GameScreen(this));
}
}
diff --git a/demos/cuboc/cuboc/src/com/badlogic/cubocy/Dispenser.java b/demos/cuboc/cuboc/src/com/badlogic/cubocy/Dispenser.java
index adad814ffa5..0e9e14801f0 100644
--- a/demos/cuboc/cuboc/src/com/badlogic/cubocy/Dispenser.java
+++ b/demos/cuboc/cuboc/src/com/badlogic/cubocy/Dispenser.java
@@ -1,12 +1,13 @@
+
package com.badlogic.cubocy;
import com.badlogic.gdx.math.Rectangle;
-public class Dispenser {
+public class Dispenser {
Rectangle bounds = new Rectangle();
boolean active = false;
-
- public Dispenser(float x, float y) {
+
+ public Dispenser (float x, float y) {
bounds.x = x;
bounds.y = y;
bounds.width = bounds.height = 1;
diff --git a/demos/cuboc/cuboc/src/com/badlogic/cubocy/EndDoor.java b/demos/cuboc/cuboc/src/com/badlogic/cubocy/EndDoor.java
index edd21365238..0c11a77af0a 100644
--- a/demos/cuboc/cuboc/src/com/badlogic/cubocy/EndDoor.java
+++ b/demos/cuboc/cuboc/src/com/badlogic/cubocy/EndDoor.java
@@ -1,11 +1,12 @@
+
package com.badlogic.cubocy;
import com.badlogic.gdx.math.Rectangle;
public class EndDoor {
public Rectangle bounds = new Rectangle();
-
- public EndDoor(float x, float y) {
+
+ public EndDoor (float x, float y) {
this.bounds.x = x;
this.bounds.y = y;
this.bounds.width = this.bounds.height = 1;
diff --git a/demos/cuboc/cuboc/src/com/badlogic/cubocy/Laser.java b/demos/cuboc/cuboc/src/com/badlogic/cubocy/Laser.java
index 90807c37bb6..b54fb491bd7 100644
--- a/demos/cuboc/cuboc/src/com/badlogic/cubocy/Laser.java
+++ b/demos/cuboc/cuboc/src/com/badlogic/cubocy/Laser.java
@@ -1,3 +1,4 @@
+
package com.badlogic.cubocy;
import com.badlogic.gdx.math.Rectangle;
@@ -8,143 +9,144 @@ public class Laser {
static final int BACKWARD = -1;
static final float FORWARD_VEL = 10;
static final float BACKWARD_VEL = 4;
-
+
int state = FORWARD;
-
- Map map;
+
+ Map map;
Vector2 pos = new Vector2();
Vector2 endPoint = new Vector2();
Vector2 cappedEndPoint = new Vector2();
- float angle = 0;
-
- public Laser(Map map, float x, float y) {
+ float angle = 0;
+
+ public Laser (Map map, float x, float y) {
this.map = map;
pos.x = x;
pos.y = y;
}
-
- public void init() {
+
+ public void init () {
int ix = (int)pos.x;
int iy = map.tiles[0].length - 1 - (int)pos.y;
-
- int left = map.tiles[ix-1][iy];
- int right = map.tiles[ix+1][iy];
+
+ int left = map.tiles[ix - 1][iy];
+ int right = map.tiles[ix + 1][iy];
int top = map.tiles[ix][iy - 1];
int bottom = map.tiles[ix][iy + 1];
-
- if(left == Map.TILE) {
+
+ if (left == Map.TILE) {
angle = -90;
- for(int x = ix; x < map.tiles.length; x++) {
- if(map.tiles[x][iy] == Map.TILE) {
+ for (int x = ix; x < map.tiles.length; x++) {
+ if (map.tiles[x][iy] == Map.TILE) {
endPoint.set(x, pos.y);
break;
}
}
}
- if(right == Map.TILE) {
+ if (right == Map.TILE) {
angle = 90;
- for(int x = ix; x >= 0; x--) {
- if(map.tiles[x][iy] == Map.TILE) {
+ for (int x = ix; x >= 0; x--) {
+ if (map.tiles[x][iy] == Map.TILE) {
endPoint.set(x, pos.y);
break;
}
}
}
- if(top == Map.TILE) {
+ if (top == Map.TILE) {
angle = 180;
- for(int y = iy; y < map.tiles[0].length; y++) {
- if(map.tiles[ix][y] == Map.TILE) {
+ for (int y = iy; y < map.tiles[0].length; y++) {
+ if (map.tiles[ix][y] == Map.TILE) {
endPoint.set(pos.x, map.tiles[0].length - y - 1);
break;
}
}
}
- if(bottom == Map.TILE) {
+ if (bottom == Map.TILE) {
angle = 0;
- for(int y = iy; y >= 0; y--) {
- if(map.tiles[ix][y] == Map.TILE) {
+ for (int y = iy; y >= 0; y--) {
+ if (map.tiles[ix][y] == Map.TILE) {
endPoint.set(pos.x, map.tiles[0].length - y - 1);
break;
}
}
}
- }
-
+ }
+
Vector2 startPoint = new Vector2();
- public void update() {
+
+ public void update () {
startPoint.set(pos).add(0.5f, 0.5f);
cappedEndPoint.set(endPoint).add(0.5f, 0.5f);
-
+
Rectangle cbounds = map.cube.bounds;
Rectangle bbounds = map.bob.bounds;
-
+
boolean kill = false;
-
- if(angle == -90) {
- if(startPoint.x < cbounds.x && endPoint.x > cbounds.x) {
- if(cbounds.y < startPoint.y && cbounds.y + cbounds.height > startPoint.y) {
+
+ if (angle == -90) {
+ if (startPoint.x < cbounds.x && endPoint.x > cbounds.x) {
+ if (cbounds.y < startPoint.y && cbounds.y + cbounds.height > startPoint.y) {
cappedEndPoint.x = cbounds.x;
- }
+ }
}
}
- if(angle == 90) {
- if(startPoint.x > cbounds.x && endPoint.x < cbounds.x) {
- if(cbounds.y < startPoint.y && cbounds.y + cbounds.height > startPoint.y) {
+ if (angle == 90) {
+ if (startPoint.x > cbounds.x && endPoint.x < cbounds.x) {
+ if (cbounds.y < startPoint.y && cbounds.y + cbounds.height > startPoint.y) {
cappedEndPoint.x = cbounds.x + cbounds.width;
- }
+ }
}
}
-
- if(angle == 0) {
- if(startPoint.y < cbounds.y && endPoint.y > cbounds.y) {
- if(cbounds.x < startPoint.x && cbounds.x + cbounds.width > startPoint.x) {
+
+ if (angle == 0) {
+ if (startPoint.y < cbounds.y && endPoint.y > cbounds.y) {
+ if (cbounds.x < startPoint.x && cbounds.x + cbounds.width > startPoint.x) {
cappedEndPoint.y = cbounds.y;
}
}
}
-
- if(angle == 180) {
- if(startPoint.y > cbounds.y && endPoint.y < cbounds.y ) {
- if(cbounds.x < startPoint.x && cbounds.x + cbounds.width > startPoint.x) {
+
+ if (angle == 180) {
+ if (startPoint.y > cbounds.y && endPoint.y < cbounds.y) {
+ if (cbounds.x < startPoint.x && cbounds.x + cbounds.width > startPoint.x) {
cappedEndPoint.y = cbounds.y + cbounds.height;
- }
+ }
}
}
-
- if(angle == -90) {
- if(startPoint.x < bbounds.x) {
- if(bbounds.y < startPoint.y && bbounds.y + bbounds.height > startPoint.y) {
- if(cappedEndPoint.x > bbounds.x) kill = true;
- }
+
+ if (angle == -90) {
+ if (startPoint.x < bbounds.x) {
+ if (bbounds.y < startPoint.y && bbounds.y + bbounds.height > startPoint.y) {
+ if (cappedEndPoint.x > bbounds.x) kill = true;
+ }
}
}
- if(angle == 90) {
- if(startPoint.x > bbounds.x) {
- if(bbounds.y < startPoint.y && bbounds.y + bbounds.height > startPoint.y) {
- if(cappedEndPoint.x < bbounds.x + bbounds.width) kill = true;
- }
+ if (angle == 90) {
+ if (startPoint.x > bbounds.x) {
+ if (bbounds.y < startPoint.y && bbounds.y + bbounds.height > startPoint.y) {
+ if (cappedEndPoint.x < bbounds.x + bbounds.width) kill = true;
+ }
}
}
-
- if(angle == 0) {
- if(pos.y < bbounds.y) {
- if(bbounds.x < startPoint.x && bbounds.x + bbounds.width > startPoint.x) {
- if(cappedEndPoint.y > bbounds.y) kill = true;
+
+ if (angle == 0) {
+ if (pos.y < bbounds.y) {
+ if (bbounds.x < startPoint.x && bbounds.x + bbounds.width > startPoint.x) {
+ if (cappedEndPoint.y > bbounds.y) kill = true;
}
}
}
-
- if(angle == 180) {
- if(pos.y > bbounds.y) {
- if(bbounds.x < startPoint.x && bbounds.x + bbounds.width > startPoint.x) {
- if(cappedEndPoint.y < bbounds.y + bbounds.height) kill = true;
- }
+
+ if (angle == 180) {
+ if (pos.y > bbounds.y) {
+ if (bbounds.x < startPoint.x && bbounds.x + bbounds.width > startPoint.x) {
+ if (cappedEndPoint.y < bbounds.y + bbounds.height) kill = true;
+ }
}
}
-
- if(kill && map.bob.state != Bob.DYING) {
+
+ if (kill && map.bob.state != Bob.DYING) {
map.bob.state = Bob.DYING;
map.bob.stateTime = 0;
}
- }
+ }
}
diff --git a/demos/cuboc/cuboc/src/com/badlogic/cubocy/Map.java b/demos/cuboc/cuboc/src/com/badlogic/cubocy/Map.java
index ff82b0a261f..f00e956d595 100644
--- a/demos/cuboc/cuboc/src/com/badlogic/cubocy/Map.java
+++ b/demos/cuboc/cuboc/src/com/badlogic/cubocy/Map.java
@@ -1,3 +1,4 @@
+
package com.badlogic.cubocy;
import com.badlogic.gdx.Gdx;
@@ -14,8 +15,8 @@ public class Map {
static int ROCKET = 0x0000ff;
static int MOVING_SPIKES = 0xffff00;
static int LASER = 0x00ffff;
-
- int[][] tiles;
+
+ int[][] tiles;
public Bob bob;
Cube cube;
Array dispensers = new Array();
@@ -24,14 +25,14 @@ public class Map {
Array movingSpikes = new Array();
Array lasers = new Array();
public EndDoor endDoor;
-
- public Map() {
+
+ public Map () {
Pixmap pixmap = new Pixmap(Gdx.files.internal("data/levels.png"));
- tiles = new int[pixmap.getWidth()][pixmap.getHeight()];
- for(int y = 0; y < pixmap.getHeight(); y++) {
- for(int x = 0; x < pixmap.getWidth(); x++) {
+ tiles = new int[pixmap.getWidth()][pixmap.getHeight()];
+ for (int y = 0; y < pixmap.getHeight(); y++) {
+ for (int x = 0; x < pixmap.getWidth(); x++) {
int pix = pixmap.getPixel(x, y) >>> 8;
- if(pix == START) {
+ if (pix == START) {
Dispenser dispenser = new Dispenser(x, pixmap.getHeight() - 1 - y);
dispensers.add(dispenser);
activeDispenser = dispenser;
@@ -39,61 +40,56 @@ public Map() {
bob.state = Bob.SPAWN;
cube = new Cube(this, activeDispenser.bounds.x, activeDispenser.bounds.y);
cube.state = Cube.DEAD;
- } else
- if(pix == DISPENSER) {
+ } else if (pix == DISPENSER) {
Dispenser dispenser = new Dispenser(x, pixmap.getHeight() - 1 - y);
- dispensers.add(dispenser);
- } else
- if(pix == ROCKET) {
+ dispensers.add(dispenser);
+ } else if (pix == ROCKET) {
Rocket rocket = new Rocket(this, x, pixmap.getHeight() - 1 - y);
rockets.add(rocket);
- } else
- if(pix == MOVING_SPIKES) {
- movingSpikes.add(new MovingSpikes(this, x, pixmap.getHeight() - 1 - y));
- } else
- if(pix == LASER) {
+ } else if (pix == MOVING_SPIKES) {
+ movingSpikes.add(new MovingSpikes(this, x, pixmap.getHeight() - 1 - y));
+ } else if (pix == LASER) {
lasers.add(new Laser(this, x, pixmap.getHeight() - 1 - y));
- } else
- if(pix == END) {
+ } else if (pix == END) {
endDoor = new EndDoor(x, pixmap.getHeight() - 1 - y);
} else {
tiles[x][y] = pix;
}
}
- }
-
- for(int i = 0; i < movingSpikes.size; i++) {
+ }
+
+ for (int i = 0; i < movingSpikes.size; i++) {
movingSpikes.get(i).init();
}
- for(int i = 0; i < lasers.size; i++) {
+ for (int i = 0; i < lasers.size; i++) {
lasers.get(i).init();
}
}
-
- public void update(float deltaTime) {
+
+ public void update (float deltaTime) {
bob.update(deltaTime);
- if(bob.state == Bob.DEAD) bob = new Bob(this, activeDispenser.bounds.x, activeDispenser.bounds.y);
+ if (bob.state == Bob.DEAD) bob = new Bob(this, activeDispenser.bounds.x, activeDispenser.bounds.y);
cube.update(deltaTime);
- if(cube.state == Cube.DEAD) cube = new Cube(this, bob.bounds.x, bob.bounds.y);
- for(int i = 0; i < dispensers.size; i++) {
- if(bob.bounds.overlaps(dispensers.get(i).bounds)) {
+ if (cube.state == Cube.DEAD) cube = new Cube(this, bob.bounds.x, bob.bounds.y);
+ for (int i = 0; i < dispensers.size; i++) {
+ if (bob.bounds.overlaps(dispensers.get(i).bounds)) {
activeDispenser = dispensers.get(i);
}
}
- for(int i = 0; i < rockets.size; i++) {
+ for (int i = 0; i < rockets.size; i++) {
Rocket rocket = rockets.get(i);
rocket.update(deltaTime);
}
- for(int i = 0; i < movingSpikes.size; i++) {
+ for (int i = 0; i < movingSpikes.size; i++) {
MovingSpikes spikes = movingSpikes.get(i);
spikes.update(deltaTime);
}
- for(int i = 0; i < lasers.size; i++) {
+ for (int i = 0; i < lasers.size; i++) {
lasers.get(i).update();
}
- }
-
- public boolean isDeadly(int tileId) {
- return tileId == SPIKES;
+ }
+
+ public boolean isDeadly (int tileId) {
+ return tileId == SPIKES;
}
}
diff --git a/demos/cuboc/cuboc/src/com/badlogic/cubocy/MapRenderer.java b/demos/cuboc/cuboc/src/com/badlogic/cubocy/MapRenderer.java
index 48a6a782a17..055d6b26958 100644
--- a/demos/cuboc/cuboc/src/com/badlogic/cubocy/MapRenderer.java
+++ b/demos/cuboc/cuboc/src/com/badlogic/cubocy/MapRenderer.java
@@ -1,3 +1,4 @@
+
package com.badlogic.cubocy;
import com.badlogic.gdx.Gdx;
@@ -12,21 +13,21 @@
import com.badlogic.gdx.graphics.glutils.ImmediateModeRenderer10;
import com.badlogic.gdx.math.Vector3;
-public class MapRenderer {
+public class MapRenderer {
Map map;
- OrthographicCamera cam;
+ OrthographicCamera cam;
SpriteCache cache;
SpriteBatch batch = new SpriteBatch(10000);
- ImmediateModeRenderer10 renderer = new ImmediateModeRenderer10(2000*2);
+ ImmediateModeRenderer10 renderer = new ImmediateModeRenderer10(2000 * 2);
int[][] blocks;
- TextureRegion tile;
+ TextureRegion tile;
Animation bobLeft;
Animation bobRight;
Animation bobJumpLeft;
Animation bobJumpRight;
Animation bobIdleLeft;
Animation bobIdleRight;
- Animation bobDead;
+ Animation bobDead;
Animation zap;
TextureRegion cube;
Animation cubeFixed;
@@ -42,47 +43,47 @@ public class MapRenderer {
TextureRegion movingSpikes;
TextureRegion laser;
FPSLogger fps = new FPSLogger();
-
- public MapRenderer(Map map) {
+
+ public MapRenderer (Map map) {
this.map = map;
this.cam = new OrthographicCamera(24, 16);
this.cam.position.set(map.bob.pos.x, map.bob.pos.y, 0);
this.cache = new SpriteCache(this.map.tiles.length * this.map.tiles[0].length, false);
- this.blocks = new int[(int)Math.ceil(this.map.tiles.length / 24.0f)]
- [(int)Math.ceil(this.map.tiles[0].length / 16.0f)];
-
- createAnimations();
- createBlocks();
+ this.blocks = new int[(int)Math.ceil(this.map.tiles.length / 24.0f)][(int)Math.ceil(this.map.tiles[0].length / 16.0f)];
+
+ createAnimations();
+ createBlocks();
}
-
- private void createBlocks() {
+
+ private void createBlocks () {
int width = map.tiles.length;
int height = map.tiles[0].length;
- for(int blockY = 0; blockY < blocks[0].length; blockY++) {
- for(int blockX = 0; blockX < blocks.length; blockX++) {
+ for (int blockY = 0; blockY < blocks[0].length; blockY++) {
+ for (int blockX = 0; blockX < blocks.length; blockX++) {
cache.beginCache();
- for(int y = blockY * 16; y < blockY * 16 + 16; y++) {
- for(int x = blockX * 24; x < blockX * 24 + 24; x++) {
- if(x > width) continue;
- if(y > height) continue;
+ for (int y = blockY * 16; y < blockY * 16 + 16; y++) {
+ for (int x = blockX * 24; x < blockX * 24 + 24; x++) {
+ if (x > width) continue;
+ if (y > height) continue;
int posX = x;
int posY = height - y - 1;
- if(map.tiles[x][y] == Map.TILE) cache.add(tile, posX, posY, 1, 1);
- if(map.tiles[x][y] == Map.SPIKES) cache.add(spikes, posX, posY, 1, 1);
+ if (map.tiles[x][y] == Map.TILE) cache.add(tile, posX, posY, 1, 1);
+ if (map.tiles[x][y] == Map.SPIKES) cache.add(spikes, posX, posY, 1, 1);
}
}
- blocks[blockX][blockY] = cache.endCache();
- }
+ blocks[blockX][blockY] = cache.endCache();
+ }
}
System.out.println("blocks created");
}
-
- private void createAnimations() {
+
+ private void createAnimations () {
this.tile = new TextureRegion(new Texture(Gdx.files.internal("data/tile.png")), 0, 0, 20, 20);
Texture bobTexture = new Texture(Gdx.files.internal("data/bob.png"));
TextureRegion[] split = new TextureRegion(bobTexture).split(20, 20)[0];
- TextureRegion[] mirror = new TextureRegion(bobTexture).split(20,20)[0];
- for(TextureRegion region: mirror) region.flip(true, false);
+ TextureRegion[] mirror = new TextureRegion(bobTexture).split(20, 20)[0];
+ for (TextureRegion region : mirror)
+ region.flip(true, false);
spikes = split[5];
bobRight = new Animation(0.1f, split[0], split[1]);
bobLeft = new Animation(0.1f, mirror[0], mirror[1]);
@@ -104,29 +105,30 @@ private void createAnimations() {
rocketPad = split[4];
split = new TextureRegion(bobTexture).split(20, 20)[4];
rocketExplosion = new Animation(0.1f, split[0], split[1], split[2], split[3], split[4], split[4]);
- split = new TextureRegion(bobTexture).split(20,20)[5];
+ split = new TextureRegion(bobTexture).split(20, 20)[5];
endDoor = split[2];
movingSpikes = split[0];
laser = split[1];
}
-
+
float stateTime = 0;
Vector3 lerpTarget = new Vector3();
- public void render(float deltaTime) {
- if(map.cube.state != Cube.CONTROLLED)
+
+ public void render (float deltaTime) {
+ if (map.cube.state != Cube.CONTROLLED)
cam.position.lerp(lerpTarget.set(map.bob.pos.x, map.bob.pos.y, 0), 2f * deltaTime);
else
cam.position.lerp(lerpTarget.set(map.cube.pos.x, map.cube.pos.y, 0), 2f * deltaTime);
- cam.update();
-
+ cam.update();
+
renderLaserBeams();
-
+
cache.setProjectionMatrix(cam.combined);
Gdx.gl.glDisable(GL10.GL_BLEND);
- cache.begin();
+ cache.begin();
int b = 0;
- for(int blockY = 0; blockY < 4; blockY++) {
- for(int blockX = 0; blockX < 6; blockX++) {
+ for (int blockY = 0; blockY < 4; blockY++) {
+ for (int blockX = 0; blockX < 6; blockX++) {
cache.draw(blocks[blockX][blockY]);
b++;
}
@@ -137,86 +139,96 @@ public void render(float deltaTime) {
batch.setProjectionMatrix(cam.combined);
batch.begin();
renderDispensers();
- if(map.endDoor != null) batch.draw(endDoor, map.endDoor.bounds.x, map.endDoor.bounds.y, 1, 1);
+ if (map.endDoor != null) batch.draw(endDoor, map.endDoor.bounds.x, map.endDoor.bounds.y, 1, 1);
renderLasers();
renderMovingSpikes();
renderBob();
- renderCube();
+ renderCube();
renderRockets();
batch.end();
- renderLaserBeams();
-
+ renderLaserBeams();
+
fps.log();
- }
+ }
- private void renderBob() {
+ private void renderBob () {
Animation anim = null;
boolean loop = true;
- if(map.bob.state == Bob.RUN) {
- if(map.bob.dir == Bob.LEFT) anim = bobLeft; else anim = bobRight;
- }
- if(map.bob.state == Bob.IDLE) {
- if(map.bob.dir == Bob.LEFT) anim = bobIdleLeft; else anim = bobIdleRight;
- }
- if(map.bob.state == Bob.JUMP) {
- if(map.bob.dir == Bob.LEFT) anim = bobJumpLeft; else anim = bobJumpRight;
- }
- if(map.bob.state == Bob.SPAWN) {
+ if (map.bob.state == Bob.RUN) {
+ if (map.bob.dir == Bob.LEFT)
+ anim = bobLeft;
+ else
+ anim = bobRight;
+ }
+ if (map.bob.state == Bob.IDLE) {
+ if (map.bob.dir == Bob.LEFT)
+ anim = bobIdleLeft;
+ else
+ anim = bobIdleRight;
+ }
+ if (map.bob.state == Bob.JUMP) {
+ if (map.bob.dir == Bob.LEFT)
+ anim = bobJumpLeft;
+ else
+ anim = bobJumpRight;
+ }
+ if (map.bob.state == Bob.SPAWN) {
anim = spawn;
loop = false;
}
- if(map.bob.state == Bob.DYING) {
+ if (map.bob.state == Bob.DYING) {
anim = dying;
loop = false;
}
batch.draw(anim.getKeyFrame(map.bob.stateTime, loop), map.bob.pos.x, map.bob.pos.y, 1, 1);
}
-
- private void renderCube() {
- if(map.cube.state == Cube.FOLLOW) batch.draw(cube, map.cube.pos.x, map.cube.pos.y, 1.5f, 1.5f);
- if(map.cube.state == Cube.FIXED) batch.draw(cubeFixed.getKeyFrame(map.cube.stateTime, false), map.cube.pos.x, map.cube.pos.y, 1.5f, 1.5f);
- if(map.cube.state == Cube.CONTROLLED) batch.draw(cubeControlled, map.cube.pos.x, map.cube.pos.y, 1.5f, 1.5f);
+
+ private void renderCube () {
+ if (map.cube.state == Cube.FOLLOW) batch.draw(cube, map.cube.pos.x, map.cube.pos.y, 1.5f, 1.5f);
+ if (map.cube.state == Cube.FIXED)
+ batch.draw(cubeFixed.getKeyFrame(map.cube.stateTime, false), map.cube.pos.x, map.cube.pos.y, 1.5f, 1.5f);
+ if (map.cube.state == Cube.CONTROLLED) batch.draw(cubeControlled, map.cube.pos.x, map.cube.pos.y, 1.5f, 1.5f);
}
-
- private void renderRockets() {
- for(int i = 0; i < map.rockets.size; i++) {
+
+ private void renderRockets () {
+ for (int i = 0; i < map.rockets.size; i++) {
Rocket rocket = map.rockets.get(i);
- if(rocket.state == Rocket.FLYING) {
- TextureRegion frame = this.rocket.getKeyFrame(rocket.stateTime, true);
+ if (rocket.state == Rocket.FLYING) {
+ TextureRegion frame = this.rocket.getKeyFrame(rocket.stateTime, true);
batch.draw(frame, rocket.pos.x, rocket.pos.y, 0.5f, 0.5f, 1, 1, 1, 1, rocket.vel.angle());
} else {
TextureRegion frame = this.rocketExplosion.getKeyFrame(rocket.stateTime, false);
batch.draw(frame, rocket.pos.x, rocket.pos.y, 1, 1);
}
batch.draw(rocketPad, rocket.startPos.x, rocket.startPos.y, 1, 1);
- }
+ }
}
-
- private void renderDispensers() {
- for(int i = 0; i < map.dispensers.size; i++) {
+
+ private void renderDispensers () {
+ for (int i = 0; i < map.dispensers.size; i++) {
Dispenser dispenser = map.dispensers.get(i);
batch.draw(this.dispenser, dispenser.bounds.x, dispenser.bounds.y, 1, 1);
- }
+ }
}
-
- private void renderMovingSpikes() {
- for(int i = 0; i < map.movingSpikes.size; i++) {
+
+ private void renderMovingSpikes () {
+ for (int i = 0; i < map.movingSpikes.size; i++) {
MovingSpikes spikes = map.movingSpikes.get(i);
batch.draw(movingSpikes, spikes.pos.x, spikes.pos.y, 0.5f, 0.5f, 1, 1, 1, 1, spikes.angle);
}
}
-
- private void renderLasers() {
- for(int i = 0; i < map.lasers.size; i++) {
+
+ private void renderLasers () {
+ for (int i = 0; i < map.lasers.size; i++) {
Laser laser = map.lasers.get(i);
batch.draw(this.laser, laser.pos.x, laser.pos.y, 0.5f, 0.5f, 1, 1, 1, 1, laser.angle);
}
}
-
+
private void renderLaserBeams () {
cam.apply(Gdx.gl10);
renderer.begin(GL10.GL_LINES);
- for(int i = 0; i < map.lasers.size; i++) {
+ for (int i = 0; i < map.lasers.size; i++) {
Laser laser = map.lasers.get(i);
float sx = laser.startPoint.x, sy = laser.startPoint.y;
float ex = laser.cappedEndPoint.x, ey = laser.cappedEndPoint.y;
@@ -234,4 +246,4 @@ public void dispose () {
tile.getTexture().dispose();
cube.getTexture().dispose();
}
-}
\ No newline at end of file
+}
diff --git a/demos/cuboc/cuboc/src/com/badlogic/cubocy/MovingSpikes.java b/demos/cuboc/cuboc/src/com/badlogic/cubocy/MovingSpikes.java
index 6c2511798ed..9e391c0ea86 100644
--- a/demos/cuboc/cuboc/src/com/badlogic/cubocy/MovingSpikes.java
+++ b/demos/cuboc/cuboc/src/com/badlogic/cubocy/MovingSpikes.java
@@ -1,3 +1,4 @@
+
package com.badlogic.cubocy;
import com.badlogic.gdx.math.Rectangle;
@@ -8,9 +9,9 @@ public class MovingSpikes {
static final int BACKWARD = -1;
static final float FORWARD_VEL = 10;
static final float BACKWARD_VEL = 4;
-
+
int state = FORWARD;
-
+
Map map;
Rectangle bounds = new Rectangle();
Vector2 vel = new Vector2();
@@ -20,60 +21,75 @@ public class MovingSpikes {
int fy = 0;
int bx = 0;
int by = 0;
-
-
- public MovingSpikes(Map map, float x, float y) {
+
+ public MovingSpikes (Map map, float x, float y) {
this.map = map;
pos.x = x;
pos.y = y;
bounds.x = x;
bounds.y = y;
- bounds.width = bounds.height = 1;
+ bounds.width = bounds.height = 1;
}
-
- public void init() {
+
+ public void init () {
int ix = (int)pos.x;
int iy = (int)pos.y;
-
- int left = map.tiles[ix-1][map.tiles[0].length - 1 - iy];
- int right = map.tiles[ix+1][map.tiles[0].length - 1 - iy];
+
+ int left = map.tiles[ix - 1][map.tiles[0].length - 1 - iy];
+ int right = map.tiles[ix + 1][map.tiles[0].length - 1 - iy];
int top = map.tiles[ix][map.tiles[0].length - 1 - iy - 1];
int bottom = map.tiles[ix][map.tiles[0].length - 1 - iy + 1];
-
- if(left == Map.TILE) { vel.x = FORWARD_VEL; angle = -90; fx = 1; }
- if(right == Map.TILE) { vel.x = -FORWARD_VEL; angle = 90; bx = 1; }
- if(top == Map.TILE) { vel.y = -FORWARD_VEL; angle = 180; by = -1;}
- if(bottom == Map.TILE) { vel.y = FORWARD_VEL; angle = 0; fy = -1; }
+
+ if (left == Map.TILE) {
+ vel.x = FORWARD_VEL;
+ angle = -90;
+ fx = 1;
+ }
+ if (right == Map.TILE) {
+ vel.x = -FORWARD_VEL;
+ angle = 90;
+ bx = 1;
+ }
+ if (top == Map.TILE) {
+ vel.y = -FORWARD_VEL;
+ angle = 180;
+ by = -1;
+ }
+ if (bottom == Map.TILE) {
+ vel.y = FORWARD_VEL;
+ angle = 0;
+ fy = -1;
+ }
}
-
- public void update(float deltaTime) {
+
+ public void update (float deltaTime) {
pos.add(vel.x * deltaTime, vel.y * deltaTime);
boolean change = false;
- if(state == FORWARD) {
+ if (state == FORWARD) {
change = map.tiles[(int)pos.x + fx][map.tiles[0].length - 1 - (int)pos.y + fy] == Map.TILE;
} else {
change = map.tiles[(int)pos.x + bx][map.tiles[0].length - 1 - (int)pos.y + by] == Map.TILE;
}
- if(change) {
+ if (change) {
pos.x -= vel.x * deltaTime;
pos.y -= vel.y * deltaTime;
state = -state;
vel.mul(-1);
- if(state == FORWARD) vel.nor().mul(FORWARD_VEL);
- if(state == BACKWARD) vel.nor().mul(BACKWARD_VEL);
+ if (state == FORWARD) vel.nor().mul(FORWARD_VEL);
+ if (state == BACKWARD) vel.nor().mul(BACKWARD_VEL);
}
-
- bounds.x = pos.x;
+
+ bounds.x = pos.x;
bounds.y = pos.y;
-
- if(map.bob.bounds.overlaps(bounds)) {
- if(map.bob.state != Bob.DYING) {
+
+ if (map.bob.bounds.overlaps(bounds)) {
+ if (map.bob.state != Bob.DYING) {
map.bob.state = Bob.DYING;
map.bob.stateTime = 0;
}
}
-
- if(map.cube.bounds.overlaps(bounds)) {
+
+ if (map.cube.bounds.overlaps(bounds)) {
map.cube.state = Cube.DEAD;
map.cube.stateTime = 0;
}
diff --git a/demos/cuboc/cuboc/src/com/badlogic/cubocy/OnscreenControlRenderer.java b/demos/cuboc/cuboc/src/com/badlogic/cubocy/OnscreenControlRenderer.java
index d99269f1b90..50fd84a022a 100644
--- a/demos/cuboc/cuboc/src/com/badlogic/cubocy/OnscreenControlRenderer.java
+++ b/demos/cuboc/cuboc/src/com/badlogic/cubocy/OnscreenControlRenderer.java
@@ -1,7 +1,8 @@
+
package com.badlogic.cubocy;
-import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Application.ApplicationType;
+import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
@@ -15,45 +16,45 @@ public class OnscreenControlRenderer {
TextureRegion jump;
TextureRegion cubeControl;
TextureRegion cubeFollow;
-
- public OnscreenControlRenderer(Map map) {
+
+ public OnscreenControlRenderer (Map map) {
this.map = map;
loadAssets();
}
-
- private void loadAssets() {
+
+ private void loadAssets () {
Texture texture = new Texture(Gdx.files.internal("data/controls.png"));
TextureRegion[] buttons = TextureRegion.split(texture, 64, 64)[0];
left = buttons[0];
right = buttons[1];
jump = buttons[2];
cubeControl = buttons[3];
- cubeFollow = TextureRegion.split(texture, 64, 64)[1][2];
- dpad = new TextureRegion(texture, 0, 64, 128, 128);
+ cubeFollow = TextureRegion.split(texture, 64, 64)[1][2];
+ dpad = new TextureRegion(texture, 0, 64, 128, 128);
batch = new SpriteBatch();
batch.getProjectionMatrix().setToOrtho2D(0, 0, 480, 320);
}
-
- public void render() {
- if(Gdx.app.getType() != ApplicationType.Android) return;
- if(map.cube.state != Cube.CONTROLLED) {
+
+ public void render () {
+ if (Gdx.app.getType() != ApplicationType.Android) return;
+ if (map.cube.state != Cube.CONTROLLED) {
batch.begin();
batch.draw(left, 0, 0);
- batch.draw(right, 70, 0);
- batch.draw(cubeControl, 480-64, 320-64);
- batch.draw(cubeFollow, 480-64, 320-138);
- batch.draw(jump, 480-64, 0);
+ batch.draw(right, 70, 0);
+ batch.draw(cubeControl, 480 - 64, 320 - 64);
+ batch.draw(cubeFollow, 480 - 64, 320 - 138);
+ batch.draw(jump, 480 - 64, 0);
batch.end();
- } else {
+ } else {
batch.begin();
batch.draw(dpad, 0, 0);
- batch.draw(cubeFollow, 480-64, 320-138);
- batch.draw(cubeControl, 480-64, 320-64);
+ batch.draw(cubeFollow, 480 - 64, 320 - 138);
+ batch.draw(cubeControl, 480 - 64, 320 - 64);
batch.end();
}
}
-
- public void dispose() {
+
+ public void dispose () {
dpad.getTexture().dispose();
batch.dispose();
}
diff --git a/demos/cuboc/cuboc/src/com/badlogic/cubocy/Rocket.java b/demos/cuboc/cuboc/src/com/badlogic/cubocy/Rocket.java
index d883455a929..e9fee5f2210 100644
--- a/demos/cuboc/cuboc/src/com/badlogic/cubocy/Rocket.java
+++ b/demos/cuboc/cuboc/src/com/badlogic/cubocy/Rocket.java
@@ -1,3 +1,4 @@
+
package com.badlogic.cubocy;
import com.badlogic.gdx.math.Rectangle;
@@ -8,7 +9,7 @@ public class Rocket {
static final int EXPLODING = 1;
static final int DEAD = 2;
static final float VELOCITY = 6;
-
+
Map map;
float stateTime = 0;
int state = FLYING;
@@ -16,8 +17,8 @@ public class Rocket {
Vector2 pos = new Vector2();
Vector2 vel = new Vector2();
Rectangle bounds = new Rectangle();
-
- public Rocket(Map map, float x, float y) {
+
+ public Rocket (Map map, float x, float y) {
this.map = map;
this.startPos.set(x, y);
this.pos.set(x, y);
@@ -27,61 +28,61 @@ public Rocket(Map map, float x, float y) {
this.bounds.height = 0.6f;
this.vel.set(-VELOCITY, 0);
}
-
- public void update(float deltaTime) {
- if(state == FLYING) {
-// if(pos.dst(map.bob.pos) < pos.dst(map.cube.pos)) vel.set(map.bob.pos);
-// else vel.set(map.cube.pos);
+
+ public void update (float deltaTime) {
+ if (state == FLYING) {
+// if(pos.dst(map.bob.pos) < pos.dst(map.cube.pos)) vel.set(map.bob.pos);
+// else vel.set(map.cube.pos);
vel.set(map.bob.pos);
vel.sub(pos).nor().mul(VELOCITY);
pos.add(vel.x * deltaTime, vel.y * deltaTime);
bounds.x = pos.x + 0.2f;
- bounds.y = pos.y + 0.2f;
- if(checkHit()) {
+ bounds.y = pos.y + 0.2f;
+ if (checkHit()) {
state = EXPLODING;
stateTime = 0;
}
}
-
- if(state == EXPLODING) {
- if(stateTime > 0.6f) {
+
+ if (state == EXPLODING) {
+ if (stateTime > 0.6f) {
state = FLYING;
stateTime = 0;
pos.set(startPos);
bounds.x = pos.x + 0.2f;
bounds.y = pos.y + 0.2f;
}
- }
-
+ }
+
stateTime += deltaTime;
- }
-
- Rectangle[] r = { new Rectangle(), new Rectangle(), new Rectangle(), new Rectangle() };
+ }
+
+ Rectangle[] r = {new Rectangle(), new Rectangle(), new Rectangle(), new Rectangle()};
- private boolean checkHit () {
+ private boolean checkHit () {
fetchCollidableRects();
- for(int i = 0; i < r.length; i++) {
- if(bounds.overlaps(r[i])) {
+ for (int i = 0; i < r.length; i++) {
+ if (bounds.overlaps(r[i])) {
return true;
- }
+ }
}
-
- if(bounds.overlaps(map.bob.bounds)) {
- if(map.bob.state != Bob.DYING) {
+
+ if (bounds.overlaps(map.bob.bounds)) {
+ if (map.bob.state != Bob.DYING) {
map.bob.state = Bob.DYING;
map.bob.stateTime = 0;
}
return true;
}
-
- if(bounds.overlaps(map.cube.bounds)) {
+
+ if (bounds.overlaps(map.cube.bounds)) {
return true;
}
-
+
return false;
}
-
- private void fetchCollidableRects() {
+
+ private void fetchCollidableRects () {
int p1x = (int)bounds.x;
int p1y = (int)Math.floor(bounds.y);
int p2x = (int)(bounds.x + bounds.width);
diff --git a/demos/cuboc/cuboc/src/com/badlogic/cubocy/screens/CubocScreen.java b/demos/cuboc/cuboc/src/com/badlogic/cubocy/screens/CubocScreen.java
index e21820500cc..2093ab36f0b 100644
--- a/demos/cuboc/cuboc/src/com/badlogic/cubocy/screens/CubocScreen.java
+++ b/demos/cuboc/cuboc/src/com/badlogic/cubocy/screens/CubocScreen.java
@@ -1,3 +1,4 @@
+
package com.badlogic.cubocy.screens;
import com.badlogic.gdx.Game;
@@ -5,29 +6,32 @@
public abstract class CubocScreen implements Screen {
Game game;
-
- public CubocScreen(Game game) {
+
+ public CubocScreen (Game game) {
this.game = game;
}
-
- @Override public void resize (int width, int height) {
+ @Override
+ public void resize (int width, int height) {
// TODO Auto-generated method stub
-
+
}
- @Override public void pause () {
+ @Override
+ public void pause () {
// TODO Auto-generated method stub
-
+
}
- @Override public void resume () {
+ @Override
+ public void resume () {
// TODO Auto-generated method stub
-
+
}
- @Override public void dispose () {
+ @Override
+ public void dispose () {
// TODO Auto-generated method stub
-
+
}
}
diff --git a/demos/cuboc/cuboc/src/com/badlogic/cubocy/screens/GameOverScreen.java b/demos/cuboc/cuboc/src/com/badlogic/cubocy/screens/GameOverScreen.java
index c832ea4ba07..ccb6a7732c6 100644
--- a/demos/cuboc/cuboc/src/com/badlogic/cubocy/screens/GameOverScreen.java
+++ b/demos/cuboc/cuboc/src/com/badlogic/cubocy/screens/GameOverScreen.java
@@ -1,3 +1,4 @@
+
package com.badlogic.cubocy.screens;
import com.badlogic.gdx.Game;
@@ -12,32 +13,35 @@ public class GameOverScreen extends CubocScreen {
TextureRegion intro;
SpriteBatch batch;
float time = 0;
-
- public GameOverScreen(Game game) {
+
+ public GameOverScreen (Game game) {
super(game);
}
- @Override public void show () {
+ @Override
+ public void show () {
intro = new TextureRegion(new Texture(Gdx.files.internal("data/gameover.png")), 0, 0, 480, 320);
batch = new SpriteBatch();
batch.getProjectionMatrix().setToOrtho2D(0, 0, 480, 320);
}
-
- @Override public void render (float delta) {
+
+ @Override
+ public void render (float delta) {
Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
batch.begin();
batch.draw(intro, 0, 0);
batch.end();
-
+
time += delta;
- if(time > 1) {
- if(Gdx.input.isKeyPressed(Keys.ANY_KEY) || Gdx.input.justTouched()) {
+ if (time > 1) {
+ if (Gdx.input.isKeyPressed(Keys.ANY_KEY) || Gdx.input.justTouched()) {
game.setScreen(new MainMenu(game));
}
}
}
- @Override public void hide () {
+ @Override
+ public void hide () {
System.out.println("dispose intro");
batch.dispose();
intro.getTexture().dispose();
diff --git a/demos/cuboc/cuboc/src/com/badlogic/cubocy/screens/GameScreen.java b/demos/cuboc/cuboc/src/com/badlogic/cubocy/screens/GameScreen.java
index dc37a13f96d..05d87108688 100644
--- a/demos/cuboc/cuboc/src/com/badlogic/cubocy/screens/GameScreen.java
+++ b/demos/cuboc/cuboc/src/com/badlogic/cubocy/screens/GameScreen.java
@@ -1,3 +1,4 @@
+
package com.badlogic.cubocy.screens;
import com.badlogic.cubocy.Map;
@@ -12,37 +13,40 @@ public class GameScreen extends CubocScreen {
Map map;
MapRenderer renderer;
OnscreenControlRenderer controlRenderer;
-
- public GameScreen(Game game) {
+
+ public GameScreen (Game game) {
super(game);
}
-
- @Override public void show () {
+
+ @Override
+ public void show () {
map = new Map();
renderer = new MapRenderer(map);
controlRenderer = new OnscreenControlRenderer(map);
}
-
- @Override public void render (float delta) {
+
+ @Override
+ public void render (float delta) {
delta = Math.min(0.06f, Gdx.graphics.getDeltaTime());
- map.update(delta);
+ map.update(delta);
Gdx.gl.glClearColor(0.1f, 0.1f, 0.1f, 1);
- Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
+ Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
renderer.render(delta);
controlRenderer.render();
-
- if(map.bob.bounds.overlaps(map.endDoor.bounds)) {
+
+ if (map.bob.bounds.overlaps(map.endDoor.bounds)) {
game.setScreen(new GameOverScreen(game));
}
-
- if(Gdx.input.isKeyPressed(Keys.ESCAPE)) {
+
+ if (Gdx.input.isKeyPressed(Keys.ESCAPE)) {
game.setScreen(new MainMenu(game));
}
}
-
- @Override public void hide () {
+
+ @Override
+ public void hide () {
System.out.println("dispose game screen");
renderer.dispose();
controlRenderer.dispose();
- }
+ }
}
diff --git a/demos/cuboc/cuboc/src/com/badlogic/cubocy/screens/IntroScreen.java b/demos/cuboc/cuboc/src/com/badlogic/cubocy/screens/IntroScreen.java
index 75c3e199105..371d31f7875 100644
--- a/demos/cuboc/cuboc/src/com/badlogic/cubocy/screens/IntroScreen.java
+++ b/demos/cuboc/cuboc/src/com/badlogic/cubocy/screens/IntroScreen.java
@@ -1,3 +1,4 @@
+
package com.badlogic.cubocy.screens;
import com.badlogic.gdx.Game;
@@ -12,35 +13,38 @@ public class IntroScreen extends CubocScreen {
TextureRegion intro;
SpriteBatch batch;
float time = 0;
-
- public IntroScreen(Game game) {
+
+ public IntroScreen (Game game) {
super(game);
}
- @Override public void show () {
+ @Override
+ public void show () {
intro = new TextureRegion(new Texture(Gdx.files.internal("data/intro.png")), 0, 0, 480, 320);
batch = new SpriteBatch();
batch.getProjectionMatrix().setToOrtho2D(0, 0, 480, 320);
}
-
- @Override public void render (float delta) {
+
+ @Override
+ public void render (float delta) {
Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
batch.begin();
batch.draw(intro, 0, 0);
batch.end();
-
+
time += delta;
- if(time > 1) {
- if(Gdx.input.isKeyPressed(Keys.ANY_KEY) || Gdx.input.justTouched()) {
+ if (time > 1) {
+ if (Gdx.input.isKeyPressed(Keys.ANY_KEY) || Gdx.input.justTouched()) {
game.setScreen(new GameScreen(game));
}
}
}
- @Override public void hide () {
+ @Override
+ public void hide () {
System.out.println("dispose intro");
batch.dispose();
intro.getTexture().dispose();
}
-
+
}
diff --git a/demos/cuboc/cuboc/src/com/badlogic/cubocy/screens/MainMenu.java b/demos/cuboc/cuboc/src/com/badlogic/cubocy/screens/MainMenu.java
index c3cefeacbf8..89edcce490b 100644
--- a/demos/cuboc/cuboc/src/com/badlogic/cubocy/screens/MainMenu.java
+++ b/demos/cuboc/cuboc/src/com/badlogic/cubocy/screens/MainMenu.java
@@ -1,3 +1,4 @@
+
package com.badlogic.cubocy.screens;
import com.badlogic.gdx.Game;
@@ -12,32 +13,35 @@ public class MainMenu extends CubocScreen {
TextureRegion title;
SpriteBatch batch;
float time = 0;
-
- public MainMenu(Game game) {
+
+ public MainMenu (Game game) {
super(game);
}
-
- @Override public void show () {
+
+ @Override
+ public void show () {
title = new TextureRegion(new Texture(Gdx.files.internal("data/title.png")), 0, 0, 480, 320);
batch = new SpriteBatch();
batch.getProjectionMatrix().setToOrtho2D(0, 0, 480, 320);
}
-
- @Override public void render (float delta) {
+
+ @Override
+ public void render (float delta) {
Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
batch.begin();
batch.draw(title, 0, 0);
batch.end();
-
+
time += delta;
- if(time > 1) {
- if(Gdx.input.isKeyPressed(Keys.ANY_KEY) || Gdx.input.justTouched()) {
+ if (time > 1) {
+ if (Gdx.input.isKeyPressed(Keys.ANY_KEY) || Gdx.input.justTouched()) {
game.setScreen(new IntroScreen(game));
}
}
}
- @Override public void hide () {
+ @Override
+ public void hide () {
System.out.println("dispose main menu");
batch.dispose();
title.getTexture().dispose();
diff --git a/demos/helloworld/gdx-helloworld-android/src/com/badlogic/gdx/HelloWorldAndroid.java b/demos/helloworld/gdx-helloworld-android/src/com/badlogic/gdx/HelloWorldAndroid.java
index 406701b9088..570ec566116 100644
--- a/demos/helloworld/gdx-helloworld-android/src/com/badlogic/gdx/HelloWorldAndroid.java
+++ b/demos/helloworld/gdx-helloworld-android/src/com/badlogic/gdx/HelloWorldAndroid.java
@@ -34,8 +34,9 @@
import com.badlogic.gdx.helloworld.HelloWorld;
public class HelloWorldAndroid extends AndroidApplication {
- @Override public void onCreate (Bundle savedInstanceState) {
+ @Override
+ public void onCreate (Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
- initialize(new HelloWorld(), false);
+ initialize(new HelloWorld(), false);
}
}
diff --git a/demos/helloworld/gdx-helloworld/src/com/badlogic/gdx/helloworld/HelloWorld.java b/demos/helloworld/gdx-helloworld/src/com/badlogic/gdx/helloworld/HelloWorld.java
index 849eed1d4bb..7624e3c8966 100644
--- a/demos/helloworld/gdx-helloworld/src/com/badlogic/gdx/helloworld/HelloWorld.java
+++ b/demos/helloworld/gdx-helloworld/src/com/badlogic/gdx/helloworld/HelloWorld.java
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
+
package com.badlogic.gdx.helloworld;
import com.badlogic.gdx.ApplicationListener;
@@ -22,7 +23,6 @@
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
-import com.badlogic.gdx.math.Rectangle;
import com.badlogic.gdx.math.Vector2;
public class HelloWorld implements ApplicationListener {
@@ -32,66 +32,70 @@ public class HelloWorld implements ApplicationListener {
Vector2 textPosition = new Vector2(100, 100);
Vector2 textDirection = new Vector2(1, 1);
- @Override public void create () {
+ @Override
+ public void create () {
font = new BitmapFont();
font.setColor(Color.RED);
texture = new Texture(Gdx.files.internal("data/badlogic.jpg"));
- spriteBatch = new SpriteBatch();
+ spriteBatch = new SpriteBatch();
}
- @Override public void render () {
+ @Override
+ public void render () {
int centerX = Gdx.graphics.getWidth() / 2;
int centerY = Gdx.graphics.getHeight() / 2;
Gdx.graphics.getGL10().glClear(GL10.GL_COLOR_BUFFER_BIT);
-
+
// more fun but confusing :)
- //textPosition.add(textDirection.tmp().mul(Gdx.graphics.getDeltaTime()).mul(60));
+ // textPosition.add(textDirection.tmp().mul(Gdx.graphics.getDeltaTime()).mul(60));
textPosition.x += textDirection.x * Gdx.graphics.getDeltaTime() * 60;
textPosition.y += textDirection.y * Gdx.graphics.getDeltaTime() * 60;
- if (textPosition.x < 0 ) {
+ if (textPosition.x < 0) {
textDirection.x = -textDirection.x;
textPosition.x = 0;
}
- if(textPosition.x > Gdx.graphics.getWidth()) {
+ if (textPosition.x > Gdx.graphics.getWidth()) {
textDirection.x = -textDirection.x;
textPosition.x = Gdx.graphics.getWidth();
}
if (textPosition.y < 0) {
textDirection.y = -textDirection.y;
- textPosition.y = 0;
+ textPosition.y = 0;
}
if (textPosition.y > Gdx.graphics.getHeight()) {
textDirection.y = -textDirection.y;
- textPosition.y = Gdx.graphics.getHeight();
+ textPosition.y = Gdx.graphics.getHeight();
}
spriteBatch.begin();
spriteBatch.setColor(Color.WHITE);
- spriteBatch.draw(texture,
- centerX - texture.getWidth() / 2,
- centerY - texture.getHeight() / 2,
- 0, 0, texture.getWidth(), texture.getHeight());
+ spriteBatch.draw(texture, centerX - texture.getWidth() / 2, centerY - texture.getHeight() / 2, 0, 0, texture.getWidth(),
+ texture.getHeight());
font.draw(spriteBatch, "Hello World!", (int)textPosition.x, (int)textPosition.y);
spriteBatch.end();
}
- @Override public void resize (int width, int height) {
+ @Override
+ public void resize (int width, int height) {
spriteBatch.getProjectionMatrix().setToOrtho2D(0, 0, width, height);
textPosition.set(0, 0);
}
- @Override public void pause () {
+ @Override
+ public void pause () {
}
- @Override public void resume () {
+ @Override
+ public void resume () {
}
-
- @Override public void dispose () {
+
+ @Override
+ public void dispose () {
}
-
+
}
diff --git a/demos/helloworld/gdx-helloworld/src/com/badlogic/gdx/helloworld/HelloWorldDesktop.java b/demos/helloworld/gdx-helloworld/src/com/badlogic/gdx/helloworld/HelloWorldDesktop.java
index 013c41bc830..ce2ede929f3 100644
--- a/demos/helloworld/gdx-helloworld/src/com/badlogic/gdx/helloworld/HelloWorldDesktop.java
+++ b/demos/helloworld/gdx-helloworld/src/com/badlogic/gdx/helloworld/HelloWorldDesktop.java
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
+
package com.badlogic.gdx.helloworld;
import com.badlogic.gdx.backends.jogl.JoglApplication;
diff --git a/demos/invaders/gdx-invaders-android/src/com/badlogic/gdxinvaders/GdxInvadersAndroid.java b/demos/invaders/gdx-invaders-android/src/com/badlogic/gdxinvaders/GdxInvadersAndroid.java
index b5e06e4a858..0fec2d95809 100644
--- a/demos/invaders/gdx-invaders-android/src/com/badlogic/gdxinvaders/GdxInvadersAndroid.java
+++ b/demos/invaders/gdx-invaders-android/src/com/badlogic/gdxinvaders/GdxInvadersAndroid.java
@@ -9,11 +9,12 @@
public class GdxInvadersAndroid extends AndroidApplication {
/** Called when the activity is first created. */
- @Override public void onCreate (Bundle savedInstanceState) {
+ @Override
+ public void onCreate (Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
AndroidApplicationConfiguration config = new AndroidApplicationConfiguration();
- config.useWakelock = true;
- initialize(new GdxInvaders(),config);
+ config.useWakelock = true;
+ initialize(new GdxInvaders(), config);
}
}
diff --git a/demos/invaders/gdx-invaders/src/com/badlogic/gdxinvaders/GdxInvaders.java b/demos/invaders/gdx-invaders/src/com/badlogic/gdxinvaders/GdxInvaders.java
index ade6a19a9b9..ccf99ada77a 100644
--- a/demos/invaders/gdx-invaders/src/com/badlogic/gdxinvaders/GdxInvaders.java
+++ b/demos/invaders/gdx-invaders/src/com/badlogic/gdxinvaders/GdxInvaders.java
@@ -15,8 +15,8 @@
import com.badlogic.gdx.Application;
import com.badlogic.gdx.ApplicationListener;
-import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Files.FileType;
+import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.audio.Music;
import com.badlogic.gdxinvaders.screens.GameLoop;
import com.badlogic.gdxinvaders.screens.GameOver;
@@ -30,11 +30,13 @@ public class GdxInvaders implements ApplicationListener {
/** the current screen **/
private Screen screen;
- @Override public void dispose () {
+ @Override
+ public void dispose () {
}
- @Override public void render () {
+ @Override
+ public void render () {
Application app = Gdx.app;
// update the screen
@@ -65,11 +67,13 @@ public class GdxInvaders implements ApplicationListener {
}
}
- @Override public void resize (int width, int height) {
+ @Override
+ public void resize (int width, int height) {
}
- @Override public void create () {
+ @Override
+ public void create () {
if (!isInitialized) {
screen = new MainMenu(Gdx.app);
Music music = Gdx.audio.newMusic(Gdx.files.getFileHandle("data/8.12.mp3", FileType.Internal));
@@ -80,13 +84,13 @@ public class GdxInvaders implements ApplicationListener {
}
@Override
- public void pause() {
+ public void pause () {
// TODO Auto-generated method stub
-
+
}
@Override
- public void resume() {
+ public void resume () {
// TODO Auto-generated method stub
System.out.println("resume");
}
diff --git a/demos/invaders/gdx-invaders/src/com/badlogic/gdxinvaders/GdxInvadersDesktop.java b/demos/invaders/gdx-invaders/src/com/badlogic/gdxinvaders/GdxInvadersDesktop.java
index 2344f37a26d..6d9f30e03f8 100644
--- a/demos/invaders/gdx-invaders/src/com/badlogic/gdxinvaders/GdxInvadersDesktop.java
+++ b/demos/invaders/gdx-invaders/src/com/badlogic/gdxinvaders/GdxInvadersDesktop.java
@@ -15,13 +15,10 @@
import com.badlogic.gdx.backends.jogl.JoglApplication;
-/**
- * Entry point for desktop version of Gdx Invaders. Constructs a JoglApplication and registers the renderer.
- * @author mzechner
- *
- */
+/** Entry point for desktop version of Gdx Invaders. Constructs a JoglApplication and registers the renderer.
+ * @author mzechner */
public class GdxInvadersDesktop {
public static void main (String[] argv) {
- new JoglApplication(new GdxInvaders(),"Gdx Invaders", 800, 480, false);
+ new JoglApplication(new GdxInvaders(), "Gdx Invaders", 800, 480, false);
}
}
diff --git a/demos/invaders/gdx-invaders/src/com/badlogic/gdxinvaders/Renderer.java b/demos/invaders/gdx-invaders/src/com/badlogic/gdxinvaders/Renderer.java
index d396b09aa1a..d584e078cdb 100644
--- a/demos/invaders/gdx-invaders/src/com/badlogic/gdxinvaders/Renderer.java
+++ b/demos/invaders/gdx-invaders/src/com/badlogic/gdxinvaders/Renderer.java
@@ -23,8 +23,8 @@
import com.badlogic.gdx.graphics.GL10;
import com.badlogic.gdx.graphics.Mesh;
import com.badlogic.gdx.graphics.PerspectiveCamera;
-import com.badlogic.gdx.graphics.Texture;
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.VertexAttribute;
import com.badlogic.gdx.graphics.VertexAttributes.Usage;
@@ -40,11 +40,8 @@
import com.badlogic.gdxinvaders.simulation.Shot;
import com.badlogic.gdxinvaders.simulation.Simulation;
-/**
- * The renderer receives a simulation and renders it.
- * @author mzechner
- *
- */
+/** The renderer receives a simulation and renders it.
+ * @author mzechner */
public class Renderer {
/** sprite batch to draw text **/
private SpriteBatch spriteBatch;
@@ -105,7 +102,7 @@ public Renderer (Application app) {
in.close();
shipTexture = new Texture(Gdx.files.internal("data/ship.png"), Format.RGB565, true);
- shipTexture.setFilter(TextureFilter.MipMap, TextureFilter.Linear);
+ shipTexture.setFilter(TextureFilter.MipMap, TextureFilter.Linear);
invaderTexture = new Texture(Gdx.files.internal("data/invader.png"), Format.RGB565, true);
invaderTexture.setFilter(TextureFilter.MipMap, TextureFilter.Linear);
backgroundTexture = new Texture(Gdx.files.internal("data/planet.jpg"), Format.RGB565, true);
@@ -113,8 +110,8 @@ public Renderer (Application app) {
explosionTexture = new Texture(Gdx.files.internal("data/explode.png"), Format.RGBA4444, true);
explosionTexture.setFilter(TextureFilter.MipMap, TextureFilter.Linear);
- explosionMesh = new Mesh(true, 4 * 16, 0, new VertexAttribute(Usage.Position, 3, "a_position"),
- new VertexAttribute(Usage.TextureCoordinates, 2, "a_texCoord"));
+ explosionMesh = new Mesh(true, 4 * 16, 0, new VertexAttribute(Usage.Position, 3, "a_position"), new VertexAttribute(
+ Usage.TextureCoordinates, 2, "a_texCoord"));
float[] vertices = new float[4 * 16 * (3 + 2)];
int idx = 0;
@@ -149,7 +146,7 @@ public Renderer (Application app) {
explosionMesh.setVertices(vertices);
font = new BitmapFont(Gdx.files.internal("data/font10.fnt"), Gdx.files.internal("data/font10.png"), false);
- camera = new PerspectiveCamera(67, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
+ camera = new PerspectiveCamera(67, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
} catch (Exception ex) {
ex.printStackTrace();
}
@@ -197,7 +194,7 @@ public void render (Application app, Simulation simulation) {
}
spriteBatch.enableBlending();
spriteBatch.setBlendFunction(GL10.GL_ONE, GL10.GL_ONE_MINUS_SRC_ALPHA);
- font.draw(spriteBatch, status, 0, 320);
+ font.draw(spriteBatch, status, 0, 320);
spriteBatch.end();
invaderAngle += app.getGraphics().getDeltaTime() * 90;
@@ -219,9 +216,9 @@ private void renderBackground (GL10 gl) {
private void setProjectionAndCamera (Graphics graphics, Ship ship, Application app) {
camera.position.set(ship.position.x, 6, 2);
- camera.direction.set(ship.position.x, 0, -4).sub(camera.position).nor();
+ camera.direction.set(ship.position.x, 0, -4).sub(camera.position).nor();
camera.update();
- camera.apply(Gdx.gl10);
+ camera.apply(Gdx.gl10);
}
float[] direction = {1, 0.5f, 0, 0};
diff --git a/demos/invaders/gdx-invaders/src/com/badlogic/gdxinvaders/screens/GameLoop.java b/demos/invaders/gdx-invaders/src/com/badlogic/gdxinvaders/screens/GameLoop.java
index 102d21c3156..517d5ee2a2e 100644
--- a/demos/invaders/gdx-invaders/src/com/badlogic/gdxinvaders/screens/GameLoop.java
+++ b/demos/invaders/gdx-invaders/src/com/badlogic/gdxinvaders/screens/GameLoop.java
@@ -41,22 +41,26 @@ public GameLoop (Application app) {
shot = app.getAudio().newSound(app.getFiles().getFileHandle("data/shot.ogg", FileType.Internal));
}
- @Override public void dispose () {
+ @Override
+ public void dispose () {
renderer.dispose();
shot.dispose();
explosion.dispose();
}
- @Override public boolean isDone () {
+ @Override
+ public boolean isDone () {
return simulation.ship.lives == 0;
}
- @Override public void render (Application app) {
+ @Override
+ public void render (Application app) {
app.getGraphics().getGL10().glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
renderer.render(app, simulation);
}
- @Override public void update (Application app) {
+ @Override
+ public void update (Application app) {
simulation.update(app.getGraphics().getDeltaTime());
Input input = app.getInput();
@@ -71,11 +75,13 @@ public GameLoop (Application app) {
if (input.isTouched() || input.isKeyPressed(Keys.SPACE)) simulation.shot();
}
- @Override public void explosion () {
+ @Override
+ public void explosion () {
explosion.play();
}
- @Override public void shot () {
+ @Override
+ public void shot () {
shot.play();
}
}
diff --git a/demos/invaders/gdx-invaders/src/com/badlogic/gdxinvaders/screens/GameOver.java b/demos/invaders/gdx-invaders/src/com/badlogic/gdxinvaders/screens/GameOver.java
index 5e41cd41665..bc0afc5ad66 100644
--- a/demos/invaders/gdx-invaders/src/com/badlogic/gdxinvaders/screens/GameOver.java
+++ b/demos/invaders/gdx-invaders/src/com/badlogic/gdxinvaders/screens/GameOver.java
@@ -14,26 +14,21 @@
package com.badlogic.gdxinvaders.screens;
import com.badlogic.gdx.Application;
-import com.badlogic.gdx.Files.FileType;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.GL10;
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.g2d.BitmapFont;
import com.badlogic.gdx.graphics.g2d.BitmapFont.HAlignment;
import com.badlogic.gdx.graphics.g2d.BitmapFont.TextBounds;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.math.Matrix4;
-/**
- * The game over screen displays the final score and a game over text and waits for the user to touch the screen in which case it
+/** The game over screen displays the final score and a game over text and waits for the user to touch the screen in which case it
* will signal that it is done to the orchestrating GdxInvaders class.
*
- * @author mzechner
- *
- */
+ * @author mzechner */
public class GameOver implements Screen {
/** the SpriteBatch used to draw the background, logo and text **/
private final SpriteBatch spriteBatch;
@@ -60,18 +55,21 @@ public GameOver (Application app) {
font = new BitmapFont(Gdx.files.internal("data/font16.fnt"), Gdx.files.internal("data/font16.png"), false);
}
- @Override public void dispose () {
+ @Override
+ public void dispose () {
spriteBatch.dispose();
background.dispose();
logo.dispose();
font.dispose();
}
- @Override public boolean isDone () {
+ @Override
+ public boolean isDone () {
return isDone;
}
- @Override public void render (Application app) {
+ @Override
+ public void render (Application app) {
app.getGraphics().getGL10().glClear(GL10.GL_COLOR_BUFFER_BIT);
viewMatrix.setToOrtho2D(0, 0, 480, 320);
@@ -82,15 +80,16 @@ public GameOver (Application app) {
spriteBatch.setColor(Color.WHITE);
spriteBatch.draw(background, 0, 0, 480, 320, 0, 0, 512, 512, false, false);
spriteBatch.enableBlending();
- spriteBatch.draw(logo, 0, 320-128, 480, 128, 0, 256, 512, 256, false, false);
+ spriteBatch.draw(logo, 0, 320 - 128, 480, 128, 0, 256, 512, 256, false, false);
String text = "It is the end my friend.\nTouch to continue!";
TextBounds bounds = font.getMultiLineBounds(text);
spriteBatch.setBlendFunction(GL10.GL_ONE, GL10.GL_ONE_MINUS_SRC_ALPHA);
- font.drawMultiLine(spriteBatch, text, 0, 160 + bounds.height / 2, 480, HAlignment.CENTER);
+ font.drawMultiLine(spriteBatch, text, 0, 160 + bounds.height / 2, 480, HAlignment.CENTER);
spriteBatch.end();
}
- @Override public void update (Application app) {
+ @Override
+ public void update (Application app) {
isDone = app.getInput().isTouched();
}
diff --git a/demos/invaders/gdx-invaders/src/com/badlogic/gdxinvaders/screens/MainMenu.java b/demos/invaders/gdx-invaders/src/com/badlogic/gdxinvaders/screens/MainMenu.java
index 4346752e8bc..bf49287da61 100644
--- a/demos/invaders/gdx-invaders/src/com/badlogic/gdxinvaders/screens/MainMenu.java
+++ b/demos/invaders/gdx-invaders/src/com/badlogic/gdxinvaders/screens/MainMenu.java
@@ -14,24 +14,19 @@
package com.badlogic.gdxinvaders.screens;
import com.badlogic.gdx.Application;
-import com.badlogic.gdx.Files.FileType;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.GL10;
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.g2d.BitmapFont;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.math.Matrix4;
-/**
- * The main menu screen showing a background, the logo of the game and a label telling the user to touch the screen to start the
+/** The main menu screen showing a background, the logo of the game and a label telling the user to touch the screen to start the
* game. Waits for the touch and returns isDone() == true when it's done so that the ochestrating GdxInvaders class can switch to
* the next screen.
- * @author mzechner
- *
- */
+ * @author mzechner */
public class MainMenu implements Screen {
/** the SpriteBatch used to draw the background, logo and text **/
private final SpriteBatch spriteBatch;
@@ -50,7 +45,7 @@ public class MainMenu implements Screen {
public MainMenu (Application app) {
spriteBatch = new SpriteBatch();
background = new Texture(Gdx.files.internal("data/planet.jpg"));
- background.setFilter(TextureFilter.Linear, TextureFilter.Linear);
+ background.setFilter(TextureFilter.Linear, TextureFilter.Linear);
logo = new Texture(Gdx.files.internal("data/title.png"));
logo.setFilter(TextureFilter.Linear, TextureFilter.Linear);
@@ -58,7 +53,8 @@ public MainMenu (Application app) {
font = new BitmapFont(Gdx.files.internal("data/font16.fnt"), Gdx.files.internal("data/font16.png"), false);
}
- @Override public void render (Application app) {
+ @Override
+ public void render (Application app) {
app.getGraphics().getGL10().glClear(GL10.GL_COLOR_BUFFER_BIT);
viewMatrix.setToOrtho2D(0, 0, 480, 320);
@@ -66,26 +62,29 @@ public MainMenu (Application app) {
spriteBatch.setTransformMatrix(transformMatrix);
spriteBatch.begin();
spriteBatch.disableBlending();
- spriteBatch.setColor(Color.WHITE);
+ spriteBatch.setColor(Color.WHITE);
spriteBatch.draw(background, 0, 0, 480, 320, 0, 0, 512, 512, false, false);
spriteBatch.enableBlending();
- spriteBatch.draw(logo, 0, 320-128, 480, 128, 0, 0, 512, 256, false, false);
+ spriteBatch.draw(logo, 0, 320 - 128, 480, 128, 0, 0, 512, 256, false, false);
spriteBatch.setBlendFunction(GL10.GL_ONE, GL10.GL_ONE_MINUS_SRC_ALPHA);
String text = "Touch screen to start!";
- float width = font.getBounds(text).width;
+ float width = font.getBounds(text).width;
font.draw(spriteBatch, text, 240 - width / 2, 128);
spriteBatch.end();
}
- @Override public void update (Application app) {
+ @Override
+ public void update (Application app) {
isDone = app.getInput().isTouched();
}
- @Override public boolean isDone () {
+ @Override
+ public boolean isDone () {
return isDone;
}
- @Override public void dispose () {
+ @Override
+ public void dispose () {
spriteBatch.dispose();
background.dispose();
logo.dispose();
diff --git a/demos/invaders/gdx-invaders/src/com/badlogic/gdxinvaders/screens/Screen.java b/demos/invaders/gdx-invaders/src/com/badlogic/gdxinvaders/screens/Screen.java
index 2da1fc7b660..9455d137f5b 100644
--- a/demos/invaders/gdx-invaders/src/com/badlogic/gdxinvaders/screens/Screen.java
+++ b/demos/invaders/gdx-invaders/src/com/badlogic/gdxinvaders/screens/Screen.java
@@ -15,34 +15,23 @@
import com.badlogic.gdx.Application;
-/**
- * Interface for a game screen, e.g. main menu, game loop, game over screen and so on.
- * @author mzechner
- *
- */
+/** Interface for a game screen, e.g. main menu, game loop, game over screen and so on.
+ * @author mzechner */
public interface Screen {
- /**
- * Called when the screen should update itself, e.g. continue a simulation etc.
+ /** Called when the screen should update itself, e.g. continue a simulation etc.
*
- * @param app the Application
- */
+ * @param app the Application */
public void update (Application app);
- /**
- * Called when a screen should render itself
- * @param app
- */
+ /** Called when a screen should render itself
+ * @param app */
public void render (Application app);
- /**
- * Called by GdxInvaders to check whether the screen is done.
+ /** Called by GdxInvaders to check whether the screen is done.
*
- * @return true when the screen is done, false otherwise
- */
+ * @return true when the screen is done, false otherwise */
public boolean isDone ();
- /**
- * Cleans up all resources of the screen, e.g. meshes, textures etc.
- */
+ /** Cleans up all resources of the screen, e.g. meshes, textures etc. */
public void dispose ();
}
diff --git a/demos/metagun/metagun-android/src/com/badlogic/metagun/MetagunAndroid.java b/demos/metagun/metagun-android/src/com/badlogic/metagun/MetagunAndroid.java
index f800f340b81..3ed83a93e58 100644
--- a/demos/metagun/metagun-android/src/com/badlogic/metagun/MetagunAndroid.java
+++ b/demos/metagun/metagun-android/src/com/badlogic/metagun/MetagunAndroid.java
@@ -1,3 +1,4 @@
+
package com.badlogic.metagun;
import android.os.Bundle;
@@ -6,10 +7,10 @@
import com.mojang.metagun.Metagun;
public class MetagunAndroid extends AndroidApplication {
- /** Called when the activity is first created. */
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- initialize(new Metagun(), false);
- }
-}
\ No newline at end of file
+ /** Called when the activity is first created. */
+ @Override
+ public void onCreate (Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ initialize(new Metagun(), false);
+ }
+}
diff --git a/demos/metagun/metagun-desktop/src/com/mojang/metagun/Art.java b/demos/metagun/metagun-desktop/src/com/mojang/metagun/Art.java
index 9c8f240b478..5b6b7b5284d 100644
--- a/demos/metagun/metagun-desktop/src/com/mojang/metagun/Art.java
+++ b/demos/metagun/metagun-desktop/src/com/mojang/metagun/Art.java
@@ -16,7 +16,7 @@ public class Art {
public static Pixmap level;
public static TextureRegion titleScreen;
public static TextureRegion shot;
- public static TextureRegion[][] buttons;
+ public static TextureRegion[][] buttons;
public static TextureRegion winScreen1;
public static TextureRegion winScreen2;
@@ -35,7 +35,7 @@ public static void load () {
winScreen1 = load("res/winscreen1.png", 320, 240);
winScreen2 = load("res/winscreen2.png", 320, 240);
}
-
+
private static TextureRegion[][] split (String name, int width, int height) {
return split(name, width, height, false);
}
@@ -61,30 +61,30 @@ public static TextureRegion load (String name, int width, int height) {
return region;
}
-// private static BufferedImage scale (BufferedImage src, int scale) {
-// int w = src.getWidth() * scale;
-// int h = src.getHeight() * scale;
-// BufferedImage res = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
-// Graphics g = res.getGraphics();
-// g.drawImage(src.getScaledInstance(w, h, Image.SCALE_AREA_AVERAGING), 0, 0, null);
-// g.dispose();
-// return res;
-// }
+// private static BufferedImage scale (BufferedImage src, int scale) {
+// int w = src.getWidth() * scale;
+// int h = src.getHeight() * scale;
+// BufferedImage res = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
+// Graphics g = res.getGraphics();
+// g.drawImage(src.getScaledInstance(w, h, Image.SCALE_AREA_AVERAGING), 0, 0, null);
+// g.dispose();
+// return res;
+// }
//
-// private static BufferedImage[][] mirrorsplit (BufferedImage src, int xs, int ys) {
-// int xSlices = src.getWidth() / xs;
-// int ySlices = src.getHeight() / ys;
-// BufferedImage[][] res = new BufferedImage[xSlices][ySlices];
-// for (int x = 0; x < xSlices; x++) {
-// for (int y = 0; y < ySlices; y++) {
-// res[x][y] = new BufferedImage(xs, ys, BufferedImage.TYPE_INT_ARGB);
-// Graphics g = res[x][y].getGraphics();
-// g.drawImage(src, xs, 0, 0, ys, x * xs, y * ys, (x + 1) * xs, (y + 1) * ys, null);
-// g.dispose();
-// }
-// }
-// return res;
-// }
+// private static BufferedImage[][] mirrorsplit (BufferedImage src, int xs, int ys) {
+// int xSlices = src.getWidth() / xs;
+// int ySlices = src.getHeight() / ys;
+// BufferedImage[][] res = new BufferedImage[xSlices][ySlices];
+// for (int x = 0; x < xSlices; x++) {
+// for (int y = 0; y < ySlices; y++) {
+// res[x][y] = new BufferedImage(xs, ys, BufferedImage.TYPE_INT_ARGB);
+// Graphics g = res[x][y].getGraphics();
+// g.drawImage(src, xs, 0, 0, ys, x * xs, y * ys, (x + 1) * xs, (y + 1) * ys, null);
+// g.dispose();
+// }
+// }
+// return res;
+// }
// private static BufferedImage[][] split(BufferedImage src, int xs, int ys) {
// int xSlices = src.getWidth() / xs;
diff --git a/demos/metagun/metagun-desktop/src/com/mojang/metagun/Input.java b/demos/metagun/metagun-desktop/src/com/mojang/metagun/Input.java
index f22d5a616ba..7072656b9dd 100644
--- a/demos/metagun/metagun-desktop/src/com/mojang/metagun/Input.java
+++ b/demos/metagun/metagun-desktop/src/com/mojang/metagun/Input.java
@@ -1,3 +1,4 @@
+
package com.mojang.metagun;
import com.badlogic.gdx.Application.ApplicationType;
@@ -6,134 +7,138 @@
import com.badlogic.gdx.InputProcessor;
public class Input implements InputProcessor {
- public static final int UP = 0;
- public static final int DOWN = 1;
- public static final int LEFT = 2;
- public static final int RIGHT = 3;
-
- public static final int JUMP = 4;
- public static final int SHOOT = 5;
-
- public static final int ESCAPE = 6;
-
- public boolean[] buttons = new boolean[64];
- public boolean[] oldButtons = new boolean[64];
-
- public void set(int key, boolean down) {
- int button = -1;
-
- if (key == Keys.DPAD_UP) button = UP;
- if (key == Keys.DPAD_LEFT) button = LEFT;
- if (key == Keys.DPAD_DOWN) button = DOWN;
- if (key == Keys.DPAD_RIGHT) button = RIGHT;
-
- if (key == Keys.Y) button = JUMP;
- if (key == Keys.Z) button = JUMP;
- if (key == Keys.X) button = SHOOT;
- if (key == Keys.C) button = JUMP;
- if (key == Keys.A) button = JUMP;
- if (key == Keys.S) button = SHOOT;
- if (key == Keys.D) button = JUMP;
-
- if (key == Keys.ESCAPE ||
- key == Keys.MENU) button = ESCAPE;
-
- if (button >= 0) {
- buttons[button] = down;
- }
- }
-
- public void tick() {
- for (int i = 0; i < buttons.length; i++) {
- oldButtons[i] = buttons[i];
- }
-
- if(Gdx.app.getType() == ApplicationType.Android) {
- boolean left = false;
- boolean right = false;
- boolean z = false;
- boolean s = false;
-
- for(int i = 0; i < 2; i++) {
- int x = (int)((Gdx.input.getX(i) / (float)Gdx.graphics.getWidth()) * 320);
- if(!Gdx.input.isTouched(i)) continue;
- if(x < 32) {
- set(Keys.DPAD_LEFT, true);
- left |= true;
- }
- if(x > 32 && x < 90) {
- set(Keys.DPAD_RIGHT, true);
- right |= true;
- }
- if(x > 320-64 && x < 320-32) {
- set(Keys.Z, true);
- z |= true;
- }
- if(x > 320-32 && x < 320) {
- set(Keys.X, true);
- s |= true;
- }
- }
-
- if(left==false) set(Keys.DPAD_LEFT, false);
- if(right==false) set(Keys.DPAD_RIGHT, false);
- if(z==false) set(Keys.Z, false);
- if(s==false) set(Keys.X, false);
- }
- }
-
-
- public void releaseAllKeys() {
- for (int i = 0; i < buttons.length; i++) {
- if(i == UP || i == DOWN) continue;
- buttons[i] = false;
- }
- }
-
- @Override public boolean keyDown (int keycode) {
+ public static final int UP = 0;
+ public static final int DOWN = 1;
+ public static final int LEFT = 2;
+ public static final int RIGHT = 3;
+
+ public static final int JUMP = 4;
+ public static final int SHOOT = 5;
+
+ public static final int ESCAPE = 6;
+
+ public boolean[] buttons = new boolean[64];
+ public boolean[] oldButtons = new boolean[64];
+
+ public void set (int key, boolean down) {
+ int button = -1;
+
+ if (key == Keys.DPAD_UP) button = UP;
+ if (key == Keys.DPAD_LEFT) button = LEFT;
+ if (key == Keys.DPAD_DOWN) button = DOWN;
+ if (key == Keys.DPAD_RIGHT) button = RIGHT;
+
+ if (key == Keys.Y) button = JUMP;
+ if (key == Keys.Z) button = JUMP;
+ if (key == Keys.X) button = SHOOT;
+ if (key == Keys.C) button = JUMP;
+ if (key == Keys.A) button = JUMP;
+ if (key == Keys.S) button = SHOOT;
+ if (key == Keys.D) button = JUMP;
+
+ if (key == Keys.ESCAPE || key == Keys.MENU) button = ESCAPE;
+
+ if (button >= 0) {
+ buttons[button] = down;
+ }
+ }
+
+ public void tick () {
+ for (int i = 0; i < buttons.length; i++) {
+ oldButtons[i] = buttons[i];
+ }
+
+ if (Gdx.app.getType() == ApplicationType.Android) {
+ boolean left = false;
+ boolean right = false;
+ boolean z = false;
+ boolean s = false;
+
+ for (int i = 0; i < 2; i++) {
+ int x = (int)((Gdx.input.getX(i) / (float)Gdx.graphics.getWidth()) * 320);
+ if (!Gdx.input.isTouched(i)) continue;
+ if (x < 32) {
+ set(Keys.DPAD_LEFT, true);
+ left |= true;
+ }
+ if (x > 32 && x < 90) {
+ set(Keys.DPAD_RIGHT, true);
+ right |= true;
+ }
+ if (x > 320 - 64 && x < 320 - 32) {
+ set(Keys.Z, true);
+ z |= true;
+ }
+ if (x > 320 - 32 && x < 320) {
+ set(Keys.X, true);
+ s |= true;
+ }
+ }
+
+ if (left == false) set(Keys.DPAD_LEFT, false);
+ if (right == false) set(Keys.DPAD_RIGHT, false);
+ if (z == false) set(Keys.Z, false);
+ if (s == false) set(Keys.X, false);
+ }
+ }
+
+ public void releaseAllKeys () {
+ for (int i = 0; i < buttons.length; i++) {
+ if (i == UP || i == DOWN) continue;
+ buttons[i] = false;
+ }
+ }
+
+ @Override
+ public boolean keyDown (int keycode) {
set(keycode, true);
return false;
}
- @Override public boolean keyUp (int keycode) {
+ @Override
+ public boolean keyUp (int keycode) {
set(keycode, false);
return false;
}
- @Override public boolean keyTyped (char character) {
+ @Override
+ public boolean keyTyped (char character) {
// TODO Auto-generated method stub
return false;
}
- @Override public boolean touchDown (int x, int y, int pointer, int button) {
- return false;
- }
+ @Override
+ public boolean touchDown (int x, int y, int pointer, int button) {
+ return false;
+ }
- @Override public boolean touchUp (int x, int y, int pointer, int button) {
+ @Override
+ public boolean touchUp (int x, int y, int pointer, int button) {
x = (int)(x / (float)Gdx.graphics.getWidth() * 320);
- if(x > 160 - 32 && x < 160) {
+ if (x > 160 - 32 && x < 160) {
set(Keys.DPAD_UP, !buttons[UP]);
- if(buttons[UP])
- buttons[DOWN] = false;
+ if (buttons[UP]) buttons[DOWN] = false;
}
- if(x > 160 && x < 160 + 32) {
+ if (x > 160 && x < 160 + 32) {
set(Keys.DPAD_DOWN, !buttons[DOWN]);
- if(buttons[DOWN])
- buttons[UP] = false;
+ if (buttons[DOWN]) buttons[UP] = false;
}
System.out.println("buttons: " + buttons[UP] + ", " + buttons[DOWN]);
return false;
}
- @Override public boolean touchDragged (int x, int y, int pointer) {
+ @Override
+ public boolean touchDragged (int x, int y, int pointer) {
return false;
}
- @Override public boolean touchMoved (int x, int y) {
+ @Override
+ public boolean touchMoved (int x, int y) {
return false;
}
- @Override public boolean scrolled (int amount) {
+ @Override
+ public boolean scrolled (int amount) {
return false;
- }
+ }
}
diff --git a/demos/metagun/metagun-desktop/src/com/mojang/metagun/Metagun.java b/demos/metagun/metagun-desktop/src/com/mojang/metagun/Metagun.java
index cf6d50217e2..143a4b4fe91 100644
--- a/demos/metagun/metagun-desktop/src/com/mojang/metagun/Metagun.java
+++ b/demos/metagun/metagun-desktop/src/com/mojang/metagun/Metagun.java
@@ -1,12 +1,9 @@
-package com.mojang.metagun;
+package com.mojang.metagun;
import com.badlogic.gdx.ApplicationListener;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.GL10;
-import com.badlogic.gdx.graphics.g2d.BitmapFont;
-import com.badlogic.gdx.graphics.g2d.SpriteBatch;
-import com.mojang.metagun.screen.GameScreen;
import com.mojang.metagun.screen.Screen;
import com.mojang.metagun.screen.TitleScreen;
@@ -22,54 +19,52 @@ public class Metagun implements ApplicationListener {
private Input input = new Input();
private boolean started = false;
private float accum = 0;
-
- public void create() {
+
+ public void create () {
Art.load();
Sound.load();
- Gdx.input.setInputProcessor(input);
+ Gdx.input.setInputProcessor(input);
running = true;
setScreen(new TitleScreen());
-// setScreen(new GameScreen());
+// setScreen(new GameScreen());
}
- public void pause() {
+ public void pause () {
running = false;
}
- public void resume() {
+ public void resume () {
running = true;
}
- public void setScreen(Screen newScreen) {
- if (screen != null)
- screen.removed();
+ public void setScreen (Screen newScreen) {
+ if (screen != null) screen.removed();
screen = newScreen;
- if (screen != null)
- screen.init(this);
+ if (screen != null) screen.init(this);
}
- public void render() {
+ public void render () {
Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
accum += Gdx.graphics.getDeltaTime();
- while(accum > 1.0f / 60.0f) {
- screen.tick(input);
+ while (accum > 1.0f / 60.0f) {
+ screen.tick(input);
input.tick();
accum -= 1.0f / 60.0f;
}
- screen.render();
-// batch.begin();
-// font.draw(batch, "fps: " + Gdx.graphics.getFramesPerSecond(), 10, 30);
-// batch.end();
+ screen.render();
+// batch.begin();
+// font.draw(batch, "fps: " + Gdx.graphics.getFramesPerSecond(), 10, 30);
+// batch.end();
}
-
+
@Override
- public void resize(int width, int height) {
+ public void resize (int width, int height) {
// TODO Auto-generated method stub
}
@Override
- public void dispose() {
+ public void dispose () {
// TODO Auto-generated method stub
}
diff --git a/demos/metagun/metagun-desktop/src/com/mojang/metagun/MetagunDesktop.java b/demos/metagun/metagun-desktop/src/com/mojang/metagun/MetagunDesktop.java
index e1313c3e7dc..03410906045 100644
--- a/demos/metagun/metagun-desktop/src/com/mojang/metagun/MetagunDesktop.java
+++ b/demos/metagun/metagun-desktop/src/com/mojang/metagun/MetagunDesktop.java
@@ -1,9 +1,10 @@
+
package com.mojang.metagun;
import com.badlogic.gdx.backends.jogl.JoglApplication;
public class MetagunDesktop {
- public static void main(String[] argv) {
+ public static void main (String[] argv) {
new JoglApplication(new Metagun(), "Metagun", 320, 240, false);
}
}
diff --git a/demos/metagun/metagun-desktop/src/com/mojang/metagun/Sound.java b/demos/metagun/metagun-desktop/src/com/mojang/metagun/Sound.java
index 27838da4d44..b51573e8097 100644
--- a/demos/metagun/metagun-desktop/src/com/mojang/metagun/Sound.java
+++ b/demos/metagun/metagun-desktop/src/com/mojang/metagun/Sound.java
@@ -1,34 +1,35 @@
+
package com.mojang.metagun;
import com.badlogic.gdx.Gdx;
public class Sound {
-
- public static com.badlogic.gdx.audio.Sound boom;
- public static com.badlogic.gdx.audio.Sound hit;
- public static com.badlogic.gdx.audio.Sound splat;
- public static com.badlogic.gdx.audio.Sound launch;
- public static com.badlogic.gdx.audio.Sound pew;
- public static com.badlogic.gdx.audio.Sound oof;
- public static com.badlogic.gdx.audio.Sound gethat;
- public static com.badlogic.gdx.audio.Sound death;
- public static com.badlogic.gdx.audio.Sound startgame;
- public static com.badlogic.gdx.audio.Sound jump;
- public static void load() {
- boom = load("res/boom.wav");
- hit = load("res/hit.wav");
- splat = load("res/splat.wav");
- launch = load("res/launch.wav");
- pew = load("res/pew.wav");
- oof = load("res/oof.wav");
- gethat = load("res/gethat.wav");
- death = load("res/death.wav");
- startgame = load("res/startgame.wav");
- jump = load("res/jump.wav");
- }
-
- private static com.badlogic.gdx.audio.Sound load(String name) {
- return Gdx.audio.newSound(Gdx.files.internal(name));
- }
+ public static com.badlogic.gdx.audio.Sound boom;
+ public static com.badlogic.gdx.audio.Sound hit;
+ public static com.badlogic.gdx.audio.Sound splat;
+ public static com.badlogic.gdx.audio.Sound launch;
+ public static com.badlogic.gdx.audio.Sound pew;
+ public static com.badlogic.gdx.audio.Sound oof;
+ public static com.badlogic.gdx.audio.Sound gethat;
+ public static com.badlogic.gdx.audio.Sound death;
+ public static com.badlogic.gdx.audio.Sound startgame;
+ public static com.badlogic.gdx.audio.Sound jump;
+
+ public static void load () {
+ boom = load("res/boom.wav");
+ hit = load("res/hit.wav");
+ splat = load("res/splat.wav");
+ launch = load("res/launch.wav");
+ pew = load("res/pew.wav");
+ oof = load("res/oof.wav");
+ gethat = load("res/gethat.wav");
+ death = load("res/death.wav");
+ startgame = load("res/startgame.wav");
+ jump = load("res/jump.wav");
+ }
+
+ private static com.badlogic.gdx.audio.Sound load (String name) {
+ return Gdx.audio.newSound(Gdx.files.internal(name));
+ }
}
diff --git a/demos/metagun/metagun-desktop/src/com/mojang/metagun/Stats.java b/demos/metagun/metagun-desktop/src/com/mojang/metagun/Stats.java
index 9292cb20149..ccf495f7289 100644
--- a/demos/metagun/metagun-desktop/src/com/mojang/metagun/Stats.java
+++ b/demos/metagun/metagun-desktop/src/com/mojang/metagun/Stats.java
@@ -1,55 +1,56 @@
+
package com.mojang.metagun;
public class Stats {
- public static Stats instance = new Stats();
-
- public int deaths = 0;
- public int shots = 0;
- public int kills = 0;
- public int jumps = 0;
- public int time = 0;
- public int hats = 0;
-
- public static void reset() {
- Stats.instance = new Stats();
- }
-
- private Stats() {
- }
-
- public int getSpeedScore() {
- int seconds = time/60;
- int speedScore = (60*10-seconds)*100;
- if (speedScore<0) speedScore = 0;
- return speedScore;
- }
-
- public int getDeathScore() {
- int deathScore = 10000-deaths*100;
- if (deathScore<0) deathScore = 0;
- return deathScore;
- }
-
- public int getHatScore() {
- int hatScore = hats*5000;
- return hatScore;
- }
-
- public int getShotScore() {
- return shots/10;
- }
-
- public int getFinalScore() {
- return getSpeedScore()+getDeathScore()+getHatScore()+getShotScore();
- }
-
- public String getTimeString() {
- int seconds = time/60;
- int minutes = seconds/60;
- seconds%=60;
- String str = minutes+":";
- if (seconds<10) str+="0";
- str+=seconds;
- return str;
- }
-}
\ No newline at end of file
+ public static Stats instance = new Stats();
+
+ public int deaths = 0;
+ public int shots = 0;
+ public int kills = 0;
+ public int jumps = 0;
+ public int time = 0;
+ public int hats = 0;
+
+ public static void reset () {
+ Stats.instance = new Stats();
+ }
+
+ private Stats () {
+ }
+
+ public int getSpeedScore () {
+ int seconds = time / 60;
+ int speedScore = (60 * 10 - seconds) * 100;
+ if (speedScore < 0) speedScore = 0;
+ return speedScore;
+ }
+
+ public int getDeathScore () {
+ int deathScore = 10000 - deaths * 100;
+ if (deathScore < 0) deathScore = 0;
+ return deathScore;
+ }
+
+ public int getHatScore () {
+ int hatScore = hats * 5000;
+ return hatScore;
+ }
+
+ public int getShotScore () {
+ return shots / 10;
+ }
+
+ public int getFinalScore () {
+ return getSpeedScore() + getDeathScore() + getHatScore() + getShotScore();
+ }
+
+ public String getTimeString () {
+ int seconds = time / 60;
+ int minutes = seconds / 60;
+ seconds %= 60;
+ String str = minutes + ":";
+ if (seconds < 10) str += "0";
+ str += seconds;
+ return str;
+ }
+}
diff --git a/demos/metagun/metagun-desktop/src/com/mojang/metagun/entity/Boss.java b/demos/metagun/metagun-desktop/src/com/mojang/metagun/entity/Boss.java
index 99250dbf246..ef81e8051be 100644
--- a/demos/metagun/metagun-desktop/src/com/mojang/metagun/entity/Boss.java
+++ b/demos/metagun/metagun-desktop/src/com/mojang/metagun/entity/Boss.java
@@ -1,3 +1,4 @@
+
package com.mojang.metagun.entity;
import com.mojang.metagun.Art;
@@ -6,91 +7,91 @@
import com.mojang.metagun.screen.Screen;
public class Boss extends BossPart {
- private static final int MAX_TEMPERATURE = 80 * 5;
- private int temperature = 0;
- public int slamTime = 0;
- private double xo, yo;
- public int time = 0;
+ private static final int MAX_TEMPERATURE = 80 * 5;
+ private int temperature = 0;
+ public int slamTime = 0;
+ private double xo, yo;
+ public int time = 0;
- public Boss(int x, int y) {
- this.x = x;
- this.y = y;
- w = 14;
- h = 14;
- bounce = 0;
- }
+ public Boss (int x, int y) {
+ this.x = x;
+ this.y = y;
+ w = 14;
+ h = 14;
+ bounce = 0;
+ }
- public void tick() {
- if (dieIn > 0) {
- if (--dieIn == 0) die();
- }
- xa = x - xo;
- ya = y - yo;
- time++;
- if (time % 60 == 0) {
- for (int i = 0; i < 16; i++) {
- double xxa = Math.sin(i * Math.PI * 2 / 16);
- double yya = Math.cos(i * Math.PI * 2 / 16);
- level.add(new Gunner(x + xxa * 4, y + yya * 4, xa * 0.2 + xxa, ya * 0.2 + yya - 1));
- }
- } else if (time%60>20 && time%60<40 && time%4==0) {
- double xd = (level.player.x + level.player.w / 2) - (x + w / 2);
- double yd = (level.player.y + level.player.h / 2) - (y + h / 2);
- double dd = Math.sqrt(xd * xd + yd * yd);
- xd /= dd;
- yd /= dd;
- Sound.hit.play();
- level.add(new Bullet(this, x + 2, y + 2, xd, yd));
- }
- xo = x;
- yo = y;
+ public void tick () {
+ if (dieIn > 0) {
+ if (--dieIn == 0) die();
+ }
+ xa = x - xo;
+ ya = y - yo;
+ time++;
+ if (time % 60 == 0) {
+ for (int i = 0; i < 16; i++) {
+ double xxa = Math.sin(i * Math.PI * 2 / 16);
+ double yya = Math.cos(i * Math.PI * 2 / 16);
+ level.add(new Gunner(x + xxa * 4, y + yya * 4, xa * 0.2 + xxa, ya * 0.2 + yya - 1));
+ }
+ } else if (time % 60 > 20 && time % 60 < 40 && time % 4 == 0) {
+ double xd = (level.player.x + level.player.w / 2) - (x + w / 2);
+ double yd = (level.player.y + level.player.h / 2) - (y + h / 2);
+ double dd = Math.sqrt(xd * xd + yd * yd);
+ xd /= dd;
+ yd /= dd;
+ Sound.hit.play();
+ level.add(new Bullet(this, x + 2, y + 2, xd, yd));
+ }
+ xo = x;
+ yo = y;
- java.util.List entities = level.getEntities((int) x + 4, (int) y + 4, w - 8, h - 4);
- for (int i = 0; i < entities.size(); i++) {
- entities.get(i).collideMonster(this);
- }
- }
+ java.util.List entities = level.getEntities((int)x + 4, (int)y + 4, w - 8, h - 4);
+ for (int i = 0; i < entities.size(); i++) {
+ entities.get(i).collideMonster(this);
+ }
+ }
- public void render(Screen screen, Camera camera) {
- int xp = (int) x - 2;
- int yp = (int) y - 2;
- screen.draw(Art.gremlins[3][1], xp, yp);
- //FIXME
-// g.setColor(Color.BLACK);
-// yp += 2;
-// xp -= 7;
-// g.fillRect(xp + 5, yp - 8, 20, 3);
-// g.setColor(Color.RED);
-// g.fillRect(xp + 5, yp - 8, 20 - (20 * temperature / MAX_TEMPERATURE), 2);
- }
+ public void render (Screen screen, Camera camera) {
+ int xp = (int)x - 2;
+ int yp = (int)y - 2;
+ screen.draw(Art.gremlins[3][1], xp, yp);
+ // FIXME
+// g.setColor(Color.BLACK);
+// yp += 2;
+// xp -= 7;
+// g.fillRect(xp + 5, yp - 8, 20, 3);
+// g.setColor(Color.RED);
+// g.fillRect(xp + 5, yp - 8, 20 - (20 * temperature / MAX_TEMPERATURE), 2);
+ }
- public void hitSpikes() {
- }
+ public void hitSpikes () {
+ }
- private void die() {
- Sound.death.play();
- for (int i = 0; i < 32; i++) {
- level.add(new PlayerGore(x + random.nextDouble() * w, y + random.nextDouble() * h));
- }
- Sound.boom.play();
- for (int i = 0; i < 32; i++) {
- double dir = i * Math.PI * 2 / 8.0;
- double xa = Math.sin(dir);
- double ya = Math.cos(dir);
- double dist = ((i / 8) + 1);
- level.add(new Explosion(1, i * 3, x + w / 2 + xa * dist, y + h / 2 + ya * dist, xa, ya));
- }
- remove();
- }
+ private void die () {
+ Sound.death.play();
+ for (int i = 0; i < 32; i++) {
+ level.add(new PlayerGore(x + random.nextDouble() * w, y + random.nextDouble() * h));
+ }
+ Sound.boom.play();
+ for (int i = 0; i < 32; i++) {
+ double dir = i * Math.PI * 2 / 8.0;
+ double xa = Math.sin(dir);
+ double ya = Math.cos(dir);
+ double dist = ((i / 8) + 1);
+ level.add(new Explosion(1, i * 3, x + w / 2 + xa * dist, y + h / 2 + ya * dist, xa, ya));
+ }
+ remove();
+ }
- public boolean shot(Bullet bullet) {
- return true;
- }
+ public boolean shot (Bullet bullet) {
+ return true;
+ }
- public void explode(Explosion explosion) {
- if (explosion.power > 0) {
- die();
- }
- }
+ public void explode (Explosion explosion) {
+ if (explosion.power > 0) {
+ die();
+ }
+ }
}
diff --git a/demos/metagun/metagun-desktop/src/com/mojang/metagun/entity/BossNeck.java b/demos/metagun/metagun-desktop/src/com/mojang/metagun/entity/BossNeck.java
index 308a03e7432..ea42ad4528d 100644
--- a/demos/metagun/metagun-desktop/src/com/mojang/metagun/entity/BossNeck.java
+++ b/demos/metagun/metagun-desktop/src/com/mojang/metagun/entity/BossNeck.java
@@ -1,3 +1,4 @@
+
package com.mojang.metagun.entity;
import com.mojang.metagun.Art;
@@ -5,79 +6,79 @@
import com.mojang.metagun.screen.Screen;
public class BossNeck extends BossPart {
- public int slamTime = 0;
- public BossPart child;
- public double baseRot = Math.PI * 1.25;
- public double rot = 0, rota = 0;
- public int time = 0;
+ public int slamTime = 0;
+ public BossPart child;
+ public double baseRot = Math.PI * 1.25;
+ public double rot = 0, rota = 0;
+ public int time = 0;
- public BossNeck(int x, int y, BossPart child) {
- this.child = child;
- this.x = x;
- this.y = y;
- w = 12;
- h = 12;
- bounce = 0;
- }
+ public BossNeck (int x, int y, BossPart child) {
+ this.child = child;
+ this.x = x;
+ this.y = y;
+ w = 12;
+ h = 12;
+ bounce = 0;
+ }
- public void tick() {
- if (dieIn>0) {
- if (--dieIn==0) die();
- }
- time++;
+ public void tick () {
+ if (dieIn > 0) {
+ if (--dieIn == 0) die();
+ }
+ time++;
- rot = Math.sin(time / 40.0) * Math.cos(time / 13.0) * 0.5;
- rota *= 0.9;
- rot *= 0.9;
- double rr = baseRot + rot;
- double xa = Math.sin(rr);
- double ya = Math.cos(rr);
- child.x = x + xa * 8;
- child.y = y + ya * 8;
- child.setRot(rr);
+ rot = Math.sin(time / 40.0) * Math.cos(time / 13.0) * 0.5;
+ rota *= 0.9;
+ rot *= 0.9;
+ double rr = baseRot + rot;
+ double xa = Math.sin(rr);
+ double ya = Math.cos(rr);
+ child.x = x + xa * 8;
+ child.y = y + ya * 8;
+ child.setRot(rr);
- java.util.List entities = level.getEntities((int) x + 4, (int) y + 4, w - 8, h - 4);
- for (int i = 0; i < entities.size(); i++) {
- entities.get(i).collideMonster(this);
- }
- }
+ java.util.List entities = level.getEntities((int)x + 4, (int)y + 4, w - 8, h - 4);
+ for (int i = 0; i < entities.size(); i++) {
+ entities.get(i).collideMonster(this);
+ }
+ }
- public void setRot(double rot) {
- baseRot = rot;
- }
+ public void setRot (double rot) {
+ baseRot = rot;
+ }
- public void render(Screen screen, Camera camera) {
- int xp = (int) x - 1;
- int yp = (int) y - 1;
- screen.draw(Art.gremlins[4][1], xp, yp);
- }
+ public void render (Screen screen, Camera camera) {
+ int xp = (int)x - 1;
+ int yp = (int)y - 1;
+ screen.draw(Art.gremlins[4][1], xp, yp);
+ }
- public void hitSpikes() {
- die();
- }
+ public void hitSpikes () {
+ die();
+ }
- private void die() {
- child.dieIn = 5;
- for (int i = 0; i < 4; i++) {
- level.add(new PlayerGore(x + random.nextDouble() * w, y + random.nextDouble() * h));
- }
- for (int i = 0; i < 4; i++) {
- double dir = i * Math.PI * 2 / 8.0;
- double xa = Math.sin(dir);
- double ya = Math.cos(dir);
- double dist = ((i / 8) + 1);
- level.add(new Explosion(1, i * 3, x + w / 2 + xa * dist, y + h / 2 + ya * dist, xa, ya));
- }
- remove();
- }
+ private void die () {
+ child.dieIn = 5;
+ for (int i = 0; i < 4; i++) {
+ level.add(new PlayerGore(x + random.nextDouble() * w, y + random.nextDouble() * h));
+ }
+ for (int i = 0; i < 4; i++) {
+ double dir = i * Math.PI * 2 / 8.0;
+ double xa = Math.sin(dir);
+ double ya = Math.cos(dir);
+ double dist = ((i / 8) + 1);
+ level.add(new Explosion(1, i * 3, x + w / 2 + xa * dist, y + h / 2 + ya * dist, xa, ya));
+ }
+ remove();
+ }
- public boolean shot(Bullet bullet) {
- return true;
- }
+ public boolean shot (Bullet bullet) {
+ return true;
+ }
- public void explode(Explosion explosion) {
- if (explosion.power > 0) {
- die();
- }
- }
+ public void explode (Explosion explosion) {
+ if (explosion.power > 0) {
+ die();
+ }
+ }
}
diff --git a/demos/metagun/metagun-desktop/src/com/mojang/metagun/entity/BossPart.java b/demos/metagun/metagun-desktop/src/com/mojang/metagun/entity/BossPart.java
index 32c04dd1fc4..d0dee4597b1 100644
--- a/demos/metagun/metagun-desktop/src/com/mojang/metagun/entity/BossPart.java
+++ b/demos/metagun/metagun-desktop/src/com/mojang/metagun/entity/BossPart.java
@@ -1,12 +1,12 @@
-package com.mojang.metagun.entity;
+package com.mojang.metagun.entity;
public abstract class BossPart extends Entity {
- public int dieIn = 0;
+ public int dieIn = 0;
- public void setRot(double rot) {
- }
+ public void setRot (double rot) {
+ }
- public void outOfBounds() {
- }
-}
\ No newline at end of file
+ public void outOfBounds () {
+ }
+}
diff --git a/demos/metagun/metagun-desktop/src/com/mojang/metagun/entity/Bullet.java b/demos/metagun/metagun-desktop/src/com/mojang/metagun/entity/Bullet.java
index f20095133ce..bda95907046 100644
--- a/demos/metagun/metagun-desktop/src/com/mojang/metagun/entity/Bullet.java
+++ b/demos/metagun/metagun-desktop/src/com/mojang/metagun/entity/Bullet.java
@@ -1,82 +1,82 @@
-package com.mojang.metagun.entity;
+package com.mojang.metagun.entity;
import com.mojang.metagun.Art;
-import com.mojang.metagun.level.*;
+import com.mojang.metagun.level.Camera;
import com.mojang.metagun.screen.Screen;
public class Bullet extends Entity {
- public Entity source;
- public int noHitTime = 10;
- private int tick = 0;
+ public Entity source;
+ public int noHitTime = 10;
+ private int tick = 0;
- public Bullet(Entity source, double x, double y, double xa, double ya) {
- this.source = source;
- this.x = x;
- this.y = y;
- this.w = 1;
- this.h = 1;
- this.xa = xa + (random.nextDouble() - random.nextDouble()) * 0.1;
- this.ya = ya + (random.nextDouble() - random.nextDouble()) * 0.1;
+ public Bullet (Entity source, double x, double y, double xa, double ya) {
+ this.source = source;
+ this.x = x;
+ this.y = y;
+ this.w = 1;
+ this.h = 1;
+ this.xa = xa + (random.nextDouble() - random.nextDouble()) * 0.1;
+ this.ya = ya + (random.nextDouble() - random.nextDouble()) * 0.1;
- interactsWithWorld = true;
- }
+ interactsWithWorld = true;
+ }
- public void tick() {
- tick++;
- tryMove(xa, ya);
+ public void tick () {
+ tick++;
+ tryMove(xa, ya);
- if (noHitTime > 0) {
- noHitTime--;
- return;
- }
- java.util.List entities = level.getEntities((int) x, (int) y, 1, 1);
- for (int i = 0; i < entities.size(); i++) {
- Entity e = entities.get(i);
- if (source==e) continue;
+ if (noHitTime > 0) {
+ noHitTime--;
+ return;
+ }
+ java.util.List entities = level.getEntities((int)x, (int)y, 1, 1);
+ for (int i = 0; i < entities.size(); i++) {
+ Entity e = entities.get(i);
+ if (source == e) continue;
- if (e.shot(this)) {
- remove();
- }
- }
- }
+ if (e.shot(this)) {
+ remove();
+ }
+ }
+ }
- protected void hitWall(double xa, double ya) {
- for (int i = 0; i < 3; i++) {
- level.add(new Spark(x, y, 0, 0));
- }
- remove();
- }
+ protected void hitWall (double xa, double ya) {
+ for (int i = 0; i < 3; i++) {
+ level.add(new Spark(x, y, 0, 0));
+ }
+ remove();
+ }
- public void render(Screen g, Camera camera) {
- // FIXME
-// if (tick % 2 == 0) {
-// g.setColor(Color.YELLOW);
-// int x1 = (int) (x + w / 2 - xa * 3);
-// int y1 = (int) (y + h / 2 - ya * 3);
-// int x2 = (int) (x + w / 2);
-// int y2 = (int) (y + h / 2);
+ public void render (Screen g, Camera camera) {
+ // FIXME
+// if (tick % 2 == 0) {
+// g.setColor(Color.YELLOW);
+// int x1 = (int) (x + w / 2 - xa * 3);
+// int y1 = (int) (y + h / 2 - ya * 3);
+// int x2 = (int) (x + w / 2);
+// int y2 = (int) (y + h / 2);
//
-// g.drawLine(x1, y1, x2, y2);
-// g.setColor(Color.WHITE);
+// g.drawLine(x1, y1, x2, y2);
+// g.setColor(Color.WHITE);
//
-// x1 = (int) (x + w / 2 - xa);
-// y1 = (int) (y + h / 2 - ya);
-// x2 = (int) (x + w / 2 + xa);
-// y2 = (int) (y + h / 2 + ya);
+// x1 = (int) (x + w / 2 - xa);
+// y1 = (int) (y + h / 2 - ya);
+// x2 = (int) (x + w / 2 + xa);
+// y2 = (int) (y + h / 2 + ya);
//
-// g.drawLine(x1, y1, x2, y2);
-// } else {
-// g.setColor(Color.YELLOW);
-// int x1 = (int) (x + w / 2 - xa);
-// int y1 = (int) (y + h / 2 - ya);
-// int x2 = (int) (x + w / 2 + xa);
-// int y2 = (int) (y + h / 2 + ya);
+// g.drawLine(x1, y1, x2, y2);
+// } else {
+// g.setColor(Color.YELLOW);
+// int x1 = (int) (x + w / 2 - xa);
+// int y1 = (int) (y + h / 2 - ya);
+// int x2 = (int) (x + w / 2 + xa);
+// int y2 = (int) (y + h / 2 + ya);
//
-// g.drawLine(x1, y1, x2, y2);
-// }
+// g.drawLine(x1, y1, x2, y2);
+// }
- g.draw(Art.shot, (int)x, (int)y);
- // g.fillRect(xp, yp, w, h);
- }
+ g.draw(Art.shot, (int)x, (int)y);
+ // g.fillRect(xp, yp, w, h);
+ }
}
diff --git a/demos/metagun/metagun-desktop/src/com/mojang/metagun/entity/Entity.java b/demos/metagun/metagun-desktop/src/com/mojang/metagun/entity/Entity.java
index 7d3b0d9dd4b..88a352cc60a 100644
--- a/demos/metagun/metagun-desktop/src/com/mojang/metagun/entity/Entity.java
+++ b/demos/metagun/metagun-desktop/src/com/mojang/metagun/entity/Entity.java
@@ -1,3 +1,4 @@
+
package com.mojang.metagun.entity;
import java.util.Random;
@@ -7,91 +8,91 @@
import com.mojang.metagun.screen.Screen;
public abstract class Entity {
- protected boolean onGround = false;
- protected static Random random = new Random();
-
- public double xa, ya;
- public double x, y;
- protected double bounce = 0.05;
- public int w = 10, h = 10;
-
- protected Level level;
- public boolean removed = false;
- public int xSlot, ySlot;
-
- public boolean interactsWithWorld = false;
-
- public void init(Level level) {
- this.level = level;
- }
-
- public void tryMove(double xa, double ya) {
- onGround = false;
- if (level.isFree(this, x + xa, y, w, h, xa, 0)) {
- x += xa;
- } else {
- hitWall(xa, 0);
- if (xa < 0) {
- double xx = x / 10;
- xa = -(xx - ((int) xx)) * 10;
- } else {
- double xx = (x + w) / 10;
- xa = 10 - (xx - ((int) xx)) * 10;
- }
- if (level.isFree(this, x + xa, y, w, h, xa, 0)) {
- x += xa;
- }
- this.xa *= -bounce;
- }
- if (level.isFree(this, x, y + ya, w, h, 0, ya)) {
- y += ya;
- } else {
- if (ya > 0) onGround = true;
- hitWall(0, ya);
- if (ya < 0) {
- double yy = y / 10;
- ya = -(yy - ((int) yy)) * 10;
- } else {
- double yy = (y + h) / 10;
- ya = 10 - (yy - ((int) yy)) * 10;
- }
- if (level.isFree(this, x, y + ya, w, h, 0, ya)) {
- y += ya;
- }
- this.ya *= -bounce;
- }
- }
-
- protected void hitWall(double xa, double ya) {
- }
-
- public void remove() {
- removed = true;
- }
-
- public void tick() {
- }
-
- public abstract void render(Screen screen, Camera camera);
-
- public boolean shot(Bullet bullet) {
- return false;
- }
-
- public void hitSpikes() {
- }
-
- public void shove(Gunner enemy) {
- }
-
- public void outOfBounds() {
- if (y < 0) return;
- remove();
- }
-
- public void explode(Explosion explosion) {
- }
-
- public void collideMonster(Entity e) {
- }
+ protected boolean onGround = false;
+ protected static Random random = new Random();
+
+ public double xa, ya;
+ public double x, y;
+ protected double bounce = 0.05;
+ public int w = 10, h = 10;
+
+ protected Level level;
+ public boolean removed = false;
+ public int xSlot, ySlot;
+
+ public boolean interactsWithWorld = false;
+
+ public void init (Level level) {
+ this.level = level;
+ }
+
+ public void tryMove (double xa, double ya) {
+ onGround = false;
+ if (level.isFree(this, x + xa, y, w, h, xa, 0)) {
+ x += xa;
+ } else {
+ hitWall(xa, 0);
+ if (xa < 0) {
+ double xx = x / 10;
+ xa = -(xx - ((int)xx)) * 10;
+ } else {
+ double xx = (x + w) / 10;
+ xa = 10 - (xx - ((int)xx)) * 10;
+ }
+ if (level.isFree(this, x + xa, y, w, h, xa, 0)) {
+ x += xa;
+ }
+ this.xa *= -bounce;
+ }
+ if (level.isFree(this, x, y + ya, w, h, 0, ya)) {
+ y += ya;
+ } else {
+ if (ya > 0) onGround = true;
+ hitWall(0, ya);
+ if (ya < 0) {
+ double yy = y / 10;
+ ya = -(yy - ((int)yy)) * 10;
+ } else {
+ double yy = (y + h) / 10;
+ ya = 10 - (yy - ((int)yy)) * 10;
+ }
+ if (level.isFree(this, x, y + ya, w, h, 0, ya)) {
+ y += ya;
+ }
+ this.ya *= -bounce;
+ }
+ }
+
+ protected void hitWall (double xa, double ya) {
+ }
+
+ public void remove () {
+ removed = true;
+ }
+
+ public void tick () {
+ }
+
+ public abstract void render (Screen screen, Camera camera);
+
+ public boolean shot (Bullet bullet) {
+ return false;
+ }
+
+ public void hitSpikes () {
+ }
+
+ public void shove (Gunner enemy) {
+ }
+
+ public void outOfBounds () {
+ if (y < 0) return;
+ remove();
+ }
+
+ public void explode (Explosion explosion) {
+ }
+
+ public void collideMonster (Entity e) {
+ }
}
diff --git a/demos/metagun/metagun-desktop/src/com/mojang/metagun/entity/Explosion.java b/demos/metagun/metagun-desktop/src/com/mojang/metagun/entity/Explosion.java
index 7ada851c05b..aa18aabdddc 100644
--- a/demos/metagun/metagun-desktop/src/com/mojang/metagun/entity/Explosion.java
+++ b/demos/metagun/metagun-desktop/src/com/mojang/metagun/entity/Explosion.java
@@ -1,3 +1,4 @@
+
package com.mojang.metagun.entity;
import com.mojang.metagun.Art;
@@ -6,59 +7,59 @@
import com.mojang.metagun.screen.Screen;
public class Explosion extends Entity {
- private int life, delay, color;
- private int duration;
- public int power;
+ private int life, delay, color;
+ private int duration;
+ public int power;
- public Explosion(int power, int delay, double x, double y, double xa, double ya) {
- this.power = power;
- this.x = x;
- this.y = y;
- this.w = 1;
- this.h = 1;
- bounce = 0.2;
- this.xa = (xa + (random.nextDouble() - random.nextDouble()) * 0.2);
- this.ya = (ya + (random.nextDouble() - random.nextDouble()) * 0.2);
+ public Explosion (int power, int delay, double x, double y, double xa, double ya) {
+ this.power = power;
+ this.x = x;
+ this.y = y;
+ this.w = 1;
+ this.h = 1;
+ bounce = 0.2;
+ this.xa = (xa + (random.nextDouble() - random.nextDouble()) * 0.2);
+ this.ya = (ya + (random.nextDouble() - random.nextDouble()) * 0.2);
- color = random.nextInt(3);
+ color = random.nextInt(3);
- duration = random.nextInt(20) + 10;
- life = 0;
- }
+ duration = random.nextInt(20) + 10;
+ life = 0;
+ }
- public void tick() {
- if (delay > 0) {
- delay--;
- return;
- }
- if (life++ >= duration) remove();
- interactsWithWorld = (life > 10);
- onGround = false;
- // tryMove(xa, ya);
- x += xa;
- y += ya;
+ public void tick () {
+ if (delay > 0) {
+ delay--;
+ return;
+ }
+ if (life++ >= duration) remove();
+ interactsWithWorld = (life > 10);
+ onGround = false;
+ // tryMove(xa, ya);
+ x += xa;
+ y += ya;
- level.isFree(this, x, y, w, h, 0, 0);
- xa *= 0.95;
- ya *= 0.95;
- ya -= Level.GRAVITY * 0.15;
+ level.isFree(this, x, y, w, h, 0, 0);
+ xa *= 0.95;
+ ya *= 0.95;
+ ya -= Level.GRAVITY * 0.15;
- if (interactsWithWorld && life < duration*0.75) {
- java.util.List entities = level.getEntities((int) x, (int) y, 1, 1);
- for (int i = 0; i < entities.size(); i++) {
- entities.get(i).explode(this);
- }
- }
- }
+ if (interactsWithWorld && life < duration * 0.75) {
+ java.util.List entities = level.getEntities((int)x, (int)y, 1, 1);
+ for (int i = 0; i < entities.size(); i++) {
+ entities.get(i).explode(this);
+ }
+ }
+ }
- protected void hitWall(double xa, double ya) {
- this.xa *= 0.4;
- this.ya *= 0.4;
- }
+ protected void hitWall (double xa, double ya) {
+ this.xa *= 0.4;
+ this.ya *= 0.4;
+ }
- public void render(Screen g, Camera camera) {
- int xp = (int) x;
- int yp = (int) y;
- g.draw(Art.guys[(life - 1) * 8 / duration][4 + color], xp - 3, yp - 3);
- }
+ public void render (Screen g, Camera camera) {
+ int xp = (int)x;
+ int yp = (int)y;
+ g.draw(Art.guys[(life - 1) * 8 / duration][4 + color], xp - 3, yp - 3);
+ }
}
diff --git a/demos/metagun/metagun-desktop/src/com/mojang/metagun/entity/Gore.java b/demos/metagun/metagun-desktop/src/com/mojang/metagun/entity/Gore.java
index 728c19187c6..9eab5bf2982 100644
--- a/demos/metagun/metagun-desktop/src/com/mojang/metagun/entity/Gore.java
+++ b/demos/metagun/metagun-desktop/src/com/mojang/metagun/entity/Gore.java
@@ -1,3 +1,4 @@
+
package com.mojang.metagun.entity;
import com.mojang.metagun.Art;
@@ -6,38 +7,38 @@
import com.mojang.metagun.screen.Screen;
public class Gore extends Entity {
- private int life;
-
- public Gore(double x, double y, double xa, double ya) {
- this.x = x;
- this.y = y;
- this.w = 1;
- this.h = 1;
- bounce = 0.2;
- this.xa = (xa + (random.nextDouble() - random.nextDouble()) * 1)*0.2;
- this.ya = (ya + (random.nextDouble() - random.nextDouble()) * 1)*0.2;
-
- life = random.nextInt(20) + 10;
- }
-
- public void tick() {
- if (life-- <= 0) remove();
- onGround = false;
- tryMove(xa, ya);
-
- xa *= 0.999;
- ya *= 0.999;
- ya += Level.GRAVITY*0.15;
- }
-
- protected void hitWall(double xa, double ya) {
- this.xa *= 0.4;
- this.ya *= 0.4;
- }
-
- public void render(Screen g, Camera camera) {
- int xp = (int) x;
- int yp = (int) y;
- g.draw(Art.guys[7][1], xp, yp);
- }
+ private int life;
+
+ public Gore (double x, double y, double xa, double ya) {
+ this.x = x;
+ this.y = y;
+ this.w = 1;
+ this.h = 1;
+ bounce = 0.2;
+ this.xa = (xa + (random.nextDouble() - random.nextDouble()) * 1) * 0.2;
+ this.ya = (ya + (random.nextDouble() - random.nextDouble()) * 1) * 0.2;
+
+ life = random.nextInt(20) + 10;
+ }
+
+ public void tick () {
+ if (life-- <= 0) remove();
+ onGround = false;
+ tryMove(xa, ya);
+
+ xa *= 0.999;
+ ya *= 0.999;
+ ya += Level.GRAVITY * 0.15;
+ }
+
+ protected void hitWall (double xa, double ya) {
+ this.xa *= 0.4;
+ this.ya *= 0.4;
+ }
+
+ public void render (Screen g, Camera camera) {
+ int xp = (int)x;
+ int yp = (int)y;
+ g.draw(Art.guys[7][1], xp, yp);
+ }
}
diff --git a/demos/metagun/metagun-desktop/src/com/mojang/metagun/entity/Gremlin.java b/demos/metagun/metagun-desktop/src/com/mojang/metagun/entity/Gremlin.java
index 638ed958ba5..1ac2e3b0f00 100644
--- a/demos/metagun/metagun-desktop/src/com/mojang/metagun/entity/Gremlin.java
+++ b/demos/metagun/metagun-desktop/src/com/mojang/metagun/entity/Gremlin.java
@@ -1,3 +1,4 @@
+
package com.mojang.metagun.entity;
import com.mojang.metagun.Art;
@@ -7,114 +8,114 @@
import com.mojang.metagun.screen.Screen;
public class Gremlin extends Entity {
- private static final int MAX_TEMPERATURE = 80 * 5;
- private int temperature = 0;
- public int jumpDelay = 0;
- private int power = 0;
+ private static final int MAX_TEMPERATURE = 80 * 5;
+ private int temperature = 0;
+ public int jumpDelay = 0;
+ private int power = 0;
- public Gremlin(int power, int x, int y) {
- this.power = power;
- this.x = x;
- this.y = y;
- w = 30;
- h = 30;
- bounce = 0;
- }
+ public Gremlin (int power, int x, int y) {
+ this.power = power;
+ this.x = x;
+ this.y = y;
+ w = 30;
+ h = 30;
+ bounce = 0;
+ }
- public void tick() {
- if (temperature > 0) {
- temperature--;
- for (int i = 0; i < 1; i++) {
- if (random.nextInt(MAX_TEMPERATURE) <= temperature) {
- double xd = (random.nextDouble() - random.nextDouble()) * 0.2;
- double yd = (random.nextDouble() - random.nextDouble()) * 0.2;
- level.add(new Spark(x + random.nextDouble() * w, y + random.nextDouble() * h, xa * 0.2 + xd, ya * 0.2 + yd));
- }
- }
- }
- tryMove(xa, ya);
- xa *= 0.4;
- ya *= Level.FRICTION;
- ya += Level.GRAVITY;
+ public void tick () {
+ if (temperature > 0) {
+ temperature--;
+ for (int i = 0; i < 1; i++) {
+ if (random.nextInt(MAX_TEMPERATURE) <= temperature) {
+ double xd = (random.nextDouble() - random.nextDouble()) * 0.2;
+ double yd = (random.nextDouble() - random.nextDouble()) * 0.2;
+ level.add(new Spark(x + random.nextDouble() * w, y + random.nextDouble() * h, xa * 0.2 + xd, ya * 0.2 + yd));
+ }
+ }
+ }
+ tryMove(xa, ya);
+ xa *= 0.4;
+ ya *= Level.FRICTION;
+ ya += Level.GRAVITY;
- if (onGround) {
- if (power==1 && jumpDelay <= 19) {
- if (jumpDelay % 2 == 0) {
- if (jumpDelay % 4 == 0) {
- Sound.hit.play();
- }
- double dir = jumpDelay / 32.0f * Math.PI * 2+0.1;
- double xa = Math.cos(dir);
- double ya = -Math.sin(dir);
- level.add(new Bullet(this, x + 15, y + 10, xa, ya));
- }
- }
- if (jumpDelay++ > 60) {
- ya = -2;
- jumpDelay = 0;
- }
- }
+ if (onGround) {
+ if (power == 1 && jumpDelay <= 19) {
+ if (jumpDelay % 2 == 0) {
+ if (jumpDelay % 4 == 0) {
+ Sound.hit.play();
+ }
+ double dir = jumpDelay / 32.0f * Math.PI * 2 + 0.1;
+ double xa = Math.cos(dir);
+ double ya = -Math.sin(dir);
+ level.add(new Bullet(this, x + 15, y + 10, xa, ya));
+ }
+ }
+ if (jumpDelay++ > 60) {
+ ya = -2;
+ jumpDelay = 0;
+ }
+ }
- java.util.List entities = level.getEntities((int) x+4, (int) y+4, w-8, h-4);
- for (int i = 0; i < entities.size(); i++) {
- entities.get(i).collideMonster(this);
- }
- }
+ java.util.List entities = level.getEntities((int)x + 4, (int)y + 4, w - 8, h - 4);
+ for (int i = 0; i < entities.size(); i++) {
+ entities.get(i).collideMonster(this);
+ }
+ }
- public void render(Screen g, Camera camera) {
- int xp = (int) x;
- int yp = (int) y;
- if (onGround) {
- g.draw(Art.gremlins[0][power], xp, yp);
- } else {
- g.draw(Art.gremlins[ya > 0 ? 2 : 1][power], xp, yp);
- }
- // FIXME
-// g.setColor(Color.BLACK);
-// g.fillRect(xp + 5, yp - 8, 20, 3);
-// g.setColor(Color.RED);
-// g.fillRect(xp + 5, yp - 8, 20 - (20 * temperature / MAX_TEMPERATURE), 2);
- }
+ public void render (Screen g, Camera camera) {
+ int xp = (int)x;
+ int yp = (int)y;
+ if (onGround) {
+ g.draw(Art.gremlins[0][power], xp, yp);
+ } else {
+ g.draw(Art.gremlins[ya > 0 ? 2 : 1][power], xp, yp);
+ }
+ // FIXME
+// g.setColor(Color.BLACK);
+// g.fillRect(xp + 5, yp - 8, 20, 3);
+// g.setColor(Color.RED);
+// g.fillRect(xp + 5, yp - 8, 20 - (20 * temperature / MAX_TEMPERATURE), 2);
+ }
- public void hitSpikes() {
- die();
- }
+ public void hitSpikes () {
+ die();
+ }
- private void die() {
- Sound.death.play();
- for (int i = 0; i < 16; i++) {
- level.add(new PlayerGore(x + random.nextDouble() * w, y + random.nextDouble() * h));
- }
- Sound.boom.play();
- for (int i = 0; i < 32; i++) {
- double dir = i * Math.PI * 2 / 8.0;
- double xa = Math.sin(dir);
- double ya = Math.cos(dir);
- double dist = ((i / 8) + 1);
- level.add(new Explosion(0, i * 3, x + w / 2 + xa * dist, y + h / 2 + ya * dist, xa, ya));
- }
- remove();
- }
+ private void die () {
+ Sound.death.play();
+ for (int i = 0; i < 16; i++) {
+ level.add(new PlayerGore(x + random.nextDouble() * w, y + random.nextDouble() * h));
+ }
+ Sound.boom.play();
+ for (int i = 0; i < 32; i++) {
+ double dir = i * Math.PI * 2 / 8.0;
+ double xa = Math.sin(dir);
+ double ya = Math.cos(dir);
+ double dist = ((i / 8) + 1);
+ level.add(new Explosion(0, i * 3, x + w / 2 + xa * dist, y + h / 2 + ya * dist, xa, ya));
+ }
+ remove();
+ }
- public boolean shot(Bullet bullet) {
- Sound.pew.play();
- for (int i = 0; i < 4; i++) {
- double xd = (random.nextDouble() - random.nextDouble()) * 4 - bullet.xa * 3;
- double yd = (random.nextDouble() - random.nextDouble()) * 4 - bullet.ya * 3;
- level.add(new Gore(bullet.x, bullet.y, xa + xd, ya + yd));
- }
- Sound.oof.play();
- temperature += 80;
- if (temperature >= MAX_TEMPERATURE) {
- die();
- } else {
- level.add(new PlayerGore(bullet.x, bullet.y));
- }
+ public boolean shot (Bullet bullet) {
+ Sound.pew.play();
+ for (int i = 0; i < 4; i++) {
+ double xd = (random.nextDouble() - random.nextDouble()) * 4 - bullet.xa * 3;
+ double yd = (random.nextDouble() - random.nextDouble()) * 4 - bullet.ya * 3;
+ level.add(new Gore(bullet.x, bullet.y, xa + xd, ya + yd));
+ }
+ Sound.oof.play();
+ temperature += 80;
+ if (temperature >= MAX_TEMPERATURE) {
+ die();
+ } else {
+ level.add(new PlayerGore(bullet.x, bullet.y));
+ }
- return true;
- }
+ return true;
+ }
- public void explode(Explosion explosion) {
- die();
- }
+ public void explode (Explosion explosion) {
+ die();
+ }
}
diff --git a/demos/metagun/metagun-desktop/src/com/mojang/metagun/entity/Gunner.java b/demos/metagun/metagun-desktop/src/com/mojang/metagun/entity/Gunner.java
index 48921756a1d..b2953c3ddca 100644
--- a/demos/metagun/metagun-desktop/src/com/mojang/metagun/entity/Gunner.java
+++ b/demos/metagun/metagun-desktop/src/com/mojang/metagun/entity/Gunner.java
@@ -1,3 +1,4 @@
+
package com.mojang.metagun.entity;
import com.mojang.metagun.Art;
@@ -7,152 +8,150 @@
import com.mojang.metagun.screen.Screen;
public class Gunner extends Entity {
- public static final int CHARGE_DURATION = 100;
- public int chargeTime = 0;
- private int sliding = 0;
-
- public Gunner(double x, double y, double xa, double ya) {
- this.x = x;
- this.y = y;
- this.w = 6;
- this.h = 6;
- bounce = -0.1;
- this.xa = xa + (random.nextDouble() - random.nextDouble()) * 0.5;
- this.ya = ya + (random.nextDouble() - random.nextDouble()) * 0.5;
- }
-
- public void tick() {
- onGround = false;
- tryMove(xa, ya);
-
- if ((onGround || sliding != 0) && xa * xa < 0.01) {
- if (chargeTime++ >= CHARGE_DURATION) {
- chargeTime = 0;
- double xd = (level.player.x + level.player.w / 2) - (x + w / 2);
- double yd = (level.player.y + level.player.h / 2) - (y + h / 2);
- double dd = Math.sqrt(xd * xd + yd * yd);
- xd /= dd;
- yd /= dd;
- Sound.hit.play();
- level.add(new Bullet(this, x + 2, y + 2, xd, yd));
- }
- }
- xa *= Level.FRICTION;
- ya *= Level.FRICTION;
- ya += Level.GRAVITY;
- }
-
- protected void hitWall(double xa, double ya) {
- sliding = 0;
- if (xa != 0) {
- if (xa > 0) {
- this.xa = 1;
- sliding = 1;
- }
- if (xa < 0) {
- this.xa = -1;
- sliding = -1;
- }
- }
- this.xa *= 0.4;
- this.ya *= 0.4;
- }
-
-
- public void render(Screen g, Camera camera) {
- // g.setColor(Color.red);
- int xp = (int) x;
- int yp = (int) y;
- // g.fillRect(xp, yp, w, h);
-
- int xFrame = 0;
- int yFrame = 0;
- if (onGround) {
- double xd = (level.player.x + level.player.w / 2) - (x + w / 2);
- double yd = (level.player.y + level.player.h / 2) - (y + h / 2);
- double dd = Math.sqrt(xd * xd + yd * yd);
- xd /= dd;
- yd /= dd;
- xFrame = 3;
- yFrame = 2;
- double s = 0.3;
- if (xd > s) xFrame++;
- if (xd < -s) xFrame--;
- if (yd > s) yFrame++;
- if (yd < -s) yFrame--;
- } else if (sliding != 0) {
- double xd = (level.player.x + level.player.w / 2) - (x + w / 2);
- double yd = (level.player.y + level.player.h / 2) - (y + h / 2);
- double dd = Math.sqrt(xd * xd + yd * yd);
- xd /= dd;
- yd /= dd;
- xFrame = 0;
- yFrame = 2;
- if (sliding > 0) xFrame = 1;
- double s = 0.3;
- if (yd > s) yFrame++;
- if (yd < -s) yFrame--;
- } else {
- xFrame = (int) (1 - Math.floor(ya * 0.1));
- if (xFrame < 0) xFrame = 0;
- if (xFrame > 2) xFrame = 2;
- yFrame = 0;
- }
-
-
- g.draw(Art.guys[xFrame][yFrame], xp, yp);
-
- java.util.List entities = level.getEntities((int) x, (int) y, 1, 1);
- for (int i = 0; i < entities.size(); i++) {
- entities.get(i).shove(this);
- }
- }
-
- public boolean shot(Bullet bullet) {
- die();
- return true;
- }
-
- public void hitSpikes() {
- die();
- }
-
- protected void die() {
- Sound.splat.play();
- level.add(new HeadGore(x+2, y));
- for (int i=0; i<10; i++) {
- double xd = (random.nextDouble()-random.nextDouble())*4;
- double yd = (random.nextDouble()-random.nextDouble())*4;
-
- level.add(new Gore(x+2+random.nextDouble(), y+random.nextDouble()*6, xa+xd, ya+yd));
- }
- remove();
- }
-
- public void shove(Gunner enemy) {
-
- double xd = enemy.x-x;
- if (xd<0) {
- xd = -0.01;
- } else if (xd>0) {
- xd = 0.01;
- } else {
- if (random.nextBoolean()) {
- xd = -0.01;
- } else {
- xd = 0.01;
- }
- }
-
- enemy.xa+=xd;
- xa-=xd;
- }
-
- public void explode(Explosion explosion) {
- die();
- }
-
- public void collideMonster(Entity e) {
- die();
- }
+ public static final int CHARGE_DURATION = 100;
+ public int chargeTime = 0;
+ private int sliding = 0;
+
+ public Gunner (double x, double y, double xa, double ya) {
+ this.x = x;
+ this.y = y;
+ this.w = 6;
+ this.h = 6;
+ bounce = -0.1;
+ this.xa = xa + (random.nextDouble() - random.nextDouble()) * 0.5;
+ this.ya = ya + (random.nextDouble() - random.nextDouble()) * 0.5;
+ }
+
+ public void tick () {
+ onGround = false;
+ tryMove(xa, ya);
+
+ if ((onGround || sliding != 0) && xa * xa < 0.01) {
+ if (chargeTime++ >= CHARGE_DURATION) {
+ chargeTime = 0;
+ double xd = (level.player.x + level.player.w / 2) - (x + w / 2);
+ double yd = (level.player.y + level.player.h / 2) - (y + h / 2);
+ double dd = Math.sqrt(xd * xd + yd * yd);
+ xd /= dd;
+ yd /= dd;
+ Sound.hit.play();
+ level.add(new Bullet(this, x + 2, y + 2, xd, yd));
+ }
+ }
+ xa *= Level.FRICTION;
+ ya *= Level.FRICTION;
+ ya += Level.GRAVITY;
+ }
+
+ protected void hitWall (double xa, double ya) {
+ sliding = 0;
+ if (xa != 0) {
+ if (xa > 0) {
+ this.xa = 1;
+ sliding = 1;
+ }
+ if (xa < 0) {
+ this.xa = -1;
+ sliding = -1;
+ }
+ }
+ this.xa *= 0.4;
+ this.ya *= 0.4;
+ }
+
+ public void render (Screen g, Camera camera) {
+ // g.setColor(Color.red);
+ int xp = (int)x;
+ int yp = (int)y;
+ // g.fillRect(xp, yp, w, h);
+
+ int xFrame = 0;
+ int yFrame = 0;
+ if (onGround) {
+ double xd = (level.player.x + level.player.w / 2) - (x + w / 2);
+ double yd = (level.player.y + level.player.h / 2) - (y + h / 2);
+ double dd = Math.sqrt(xd * xd + yd * yd);
+ xd /= dd;
+ yd /= dd;
+ xFrame = 3;
+ yFrame = 2;
+ double s = 0.3;
+ if (xd > s) xFrame++;
+ if (xd < -s) xFrame--;
+ if (yd > s) yFrame++;
+ if (yd < -s) yFrame--;
+ } else if (sliding != 0) {
+ double xd = (level.player.x + level.player.w / 2) - (x + w / 2);
+ double yd = (level.player.y + level.player.h / 2) - (y + h / 2);
+ double dd = Math.sqrt(xd * xd + yd * yd);
+ xd /= dd;
+ yd /= dd;
+ xFrame = 0;
+ yFrame = 2;
+ if (sliding > 0) xFrame = 1;
+ double s = 0.3;
+ if (yd > s) yFrame++;
+ if (yd < -s) yFrame--;
+ } else {
+ xFrame = (int)(1 - Math.floor(ya * 0.1));
+ if (xFrame < 0) xFrame = 0;
+ if (xFrame > 2) xFrame = 2;
+ yFrame = 0;
+ }
+
+ g.draw(Art.guys[xFrame][yFrame], xp, yp);
+
+ java.util.List entities = level.getEntities((int)x, (int)y, 1, 1);
+ for (int i = 0; i < entities.size(); i++) {
+ entities.get(i).shove(this);
+ }
+ }
+
+ public boolean shot (Bullet bullet) {
+ die();
+ return true;
+ }
+
+ public void hitSpikes () {
+ die();
+ }
+
+ protected void die () {
+ Sound.splat.play();
+ level.add(new HeadGore(x + 2, y));
+ for (int i = 0; i < 10; i++) {
+ double xd = (random.nextDouble() - random.nextDouble()) * 4;
+ double yd = (random.nextDouble() - random.nextDouble()) * 4;
+
+ level.add(new Gore(x + 2 + random.nextDouble(), y + random.nextDouble() * 6, xa + xd, ya + yd));
+ }
+ remove();
+ }
+
+ public void shove (Gunner enemy) {
+
+ double xd = enemy.x - x;
+ if (xd < 0) {
+ xd = -0.01;
+ } else if (xd > 0) {
+ xd = 0.01;
+ } else {
+ if (random.nextBoolean()) {
+ xd = -0.01;
+ } else {
+ xd = 0.01;
+ }
+ }
+
+ enemy.xa += xd;
+ xa -= xd;
+ }
+
+ public void explode (Explosion explosion) {
+ die();
+ }
+
+ public void collideMonster (Entity e) {
+ die();
+ }
}
diff --git a/demos/metagun/metagun-desktop/src/com/mojang/metagun/entity/Hat.java b/demos/metagun/metagun-desktop/src/com/mojang/metagun/entity/Hat.java
index df2ce001e04..5fc23e789b6 100644
--- a/demos/metagun/metagun-desktop/src/com/mojang/metagun/entity/Hat.java
+++ b/demos/metagun/metagun-desktop/src/com/mojang/metagun/entity/Hat.java
@@ -1,3 +1,4 @@
+
package com.mojang.metagun.entity;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
@@ -8,77 +9,78 @@
import com.mojang.metagun.screen.Screen;
public class Hat extends Entity {
- double time = 0;
- int noTakeTime = 30;
- private int xPos, yPos;
- public double xxa;
+ double time = 0;
+ int noTakeTime = 30;
+ private int xPos, yPos;
+ public double xxa;
- public Hat(double x, double y) {
- this(x, y, -1, -1);
- }
+ public Hat (double x, double y) {
+ this(x, y, -1, -1);
+ }
- public Hat(double x, double y, int xPos, int yPos) {
- this.x = x;
- this.y = y;
- this.xPos = xPos;
- this.yPos = yPos;
- w = 6;
- h = 3;
- bounce = 0;
- ya = -1;
- time = Math.PI * 0.5;
- }
+ public Hat (double x, double y, int xPos, int yPos) {
+ this.x = x;
+ this.y = y;
+ this.xPos = xPos;
+ this.yPos = yPos;
+ w = 6;
+ h = 3;
+ bounce = 0;
+ ya = -1;
+ time = Math.PI * 0.5;
+ }
- public void tick() {
- tryMove(xa, ya);
- if (onGround) {
- time = 0;
- } else {
- time++;
- }
+ public void tick () {
+ tryMove(xa, ya);
+ if (onGround) {
+ time = 0;
+ } else {
+ time++;
+ }
- xa = xxa+Math.sin(time * 0.05) * 0.2;
- xxa*=0.95;
- ya *= 0.95;
- ya += Level.GRAVITY * 0.1;
+ xa = xxa + Math.sin(time * 0.05) * 0.2;
+ xxa *= 0.95;
+ ya *= 0.95;
+ ya += Level.GRAVITY * 0.1;
- if (noTakeTime > 0) noTakeTime--;
- else {
- java.util.List entities = level.getEntities((int) x, (int) y, w, h);
- for (int i = 0; i < entities.size(); i++) {
- Entity e = entities.get(i);
- if (e instanceof Player) {
- Player player = (Player) e;
- player.hatCount++;
+ if (noTakeTime > 0)
+ noTakeTime--;
+ else {
+ java.util.List entities = level.getEntities((int)x, (int)y, w, h);
+ for (int i = 0; i < entities.size(); i++) {
+ Entity e = entities.get(i);
+ if (e instanceof Player) {
+ Player player = (Player)e;
+ player.hatCount++;
- if (xPos >= 0 && yPos >= 0) {
- Art.level.setColor(0, 0, 0, 0);
- Art.level.drawPixel(xPos, yPos);
- }
- Sound.gethat.play();
- remove();
- }
- }
- }
- }
+ if (xPos >= 0 && yPos >= 0) {
+ Art.level.setColor(0, 0, 0, 0);
+ Art.level.drawPixel(xPos, yPos);
+ }
+ Sound.gethat.play();
+ remove();
+ }
+ }
+ }
+ }
- public void render(Screen g, Camera camera) {
- int dir = 1;
- int xp = (int) x - (16 - w) / 2;
- int yp = (int) y - 2;
- TextureRegion[][] sheet = dir == 1 ? Art.player1 : Art.player2;
+ public void render (Screen g, Camera camera) {
+ int dir = 1;
+ int xp = (int)x - (16 - w) / 2;
+ int yp = (int)y - 2;
+ TextureRegion[][] sheet = dir == 1 ? Art.player1 : Art.player2;
- int xFrame = (int) (xa * 10);
- if (xFrame < -1) xFrame = -1;
- if (xFrame > +1) xFrame = +1;
- g.draw(sheet[1 + xFrame][1], xp, yp);
- }
+ int xFrame = (int)(xa * 10);
+ if (xFrame < -1) xFrame = -1;
+ if (xFrame > +1) xFrame = +1;
+ g.draw(sheet[1 + xFrame][1], xp, yp);
+ }
- public boolean shot(Bullet bullet) {
- Sound.hit.play();
- xa += bullet.xa * 0.5;
- ya += bullet.ya * 0.5;
+ public boolean shot (Bullet bullet) {
+ Sound.hit.play();
+ xa += bullet.xa * 0.5;
+ ya += bullet.ya * 0.5;
- return true;
- }
+ return true;
+ }
}
diff --git a/demos/metagun/metagun-desktop/src/com/mojang/metagun/entity/HeadGore.java b/demos/metagun/metagun-desktop/src/com/mojang/metagun/entity/HeadGore.java
index 4b5c2993e35..6beca8b6a3f 100644
--- a/demos/metagun/metagun-desktop/src/com/mojang/metagun/entity/HeadGore.java
+++ b/demos/metagun/metagun-desktop/src/com/mojang/metagun/entity/HeadGore.java
@@ -1,3 +1,4 @@
+
package com.mojang.metagun.entity;
import com.mojang.metagun.Art;
@@ -6,49 +7,49 @@
import com.mojang.metagun.screen.Screen;
public class HeadGore extends Entity {
- private int life;
-
- public HeadGore(double x, double y) {
- this.x = x;
- this.y = y;
- this.w = 2;
- this.h = 2;
- bounce = 0.2;
- this.xa = 0 + (random.nextDouble() - random.nextDouble()) * 0.5;
- this.ya = -1 + (random.nextDouble() - random.nextDouble()) * 0.5;
-
- life = random.nextInt(60) + 20;
- }
-
- public void tick() {
- if (life-- <= 0) remove();
- onGround = false;
- tryMove(xa, ya);
-
- xa *= Level.FRICTION;
- ya *= Level.FRICTION;
- ya += Level.GRAVITY*0.5;
- level.add(new Gore(x+random.nextDouble(), y+random.nextDouble()-1, xa, ya));
- }
-
- protected void hitWall(double xa, double ya) {
- this.xa *= 0.8;
- this.ya *= 0.8;
- }
-
- public void render(Screen g, Camera camera) {
- int xp = (int) x;
- int yp = (int) y;
- g.draw(Art.guys[6][1], xp, yp);
- }
-
- public void hitSpikes() {
- for (int i = 0; i < 4; i++) {
- xa = (random.nextFloat()-random.nextFloat())*6;
- ya = (random.nextFloat()-random.nextFloat())*6;
- level.add(new Gore(x + random.nextDouble(), y + random.nextDouble() - 1, xa, ya));
- }
- remove();
- }
-
+ private int life;
+
+ public HeadGore (double x, double y) {
+ this.x = x;
+ this.y = y;
+ this.w = 2;
+ this.h = 2;
+ bounce = 0.2;
+ this.xa = 0 + (random.nextDouble() - random.nextDouble()) * 0.5;
+ this.ya = -1 + (random.nextDouble() - random.nextDouble()) * 0.5;
+
+ life = random.nextInt(60) + 20;
+ }
+
+ public void tick () {
+ if (life-- <= 0) remove();
+ onGround = false;
+ tryMove(xa, ya);
+
+ xa *= Level.FRICTION;
+ ya *= Level.FRICTION;
+ ya += Level.GRAVITY * 0.5;
+ level.add(new Gore(x + random.nextDouble(), y + random.nextDouble() - 1, xa, ya));
+ }
+
+ protected void hitWall (double xa, double ya) {
+ this.xa *= 0.8;
+ this.ya *= 0.8;
+ }
+
+ public void render (Screen g, Camera camera) {
+ int xp = (int)x;
+ int yp = (int)y;
+ g.draw(Art.guys[6][1], xp, yp);
+ }
+
+ public void hitSpikes () {
+ for (int i = 0; i < 4; i++) {
+ xa = (random.nextFloat() - random.nextFloat()) * 6;
+ ya = (random.nextFloat() - random.nextFloat()) * 6;
+ level.add(new Gore(x + random.nextDouble(), y + random.nextDouble() - 1, xa, ya));
+ }
+ remove();
+ }
+
}
diff --git a/demos/metagun/metagun-desktop/src/com/mojang/metagun/entity/Jabberwocky.java b/demos/metagun/metagun-desktop/src/com/mojang/metagun/entity/Jabberwocky.java
index 32f2efdae2b..9da5a579820 100644
--- a/demos/metagun/metagun-desktop/src/com/mojang/metagun/entity/Jabberwocky.java
+++ b/demos/metagun/metagun-desktop/src/com/mojang/metagun/entity/Jabberwocky.java
@@ -1,3 +1,4 @@
+
package com.mojang.metagun.entity;
import com.mojang.metagun.Art;
@@ -7,85 +8,85 @@
import com.mojang.metagun.screen.Screen;
public class Jabberwocky extends Entity {
- private static final int MAX_TEMPERATURE = 80 * 5;
- private int temperature = 0;
- public int slamTime = 0;
+ private static final int MAX_TEMPERATURE = 80 * 5;
+ private int temperature = 0;
+ public int slamTime = 0;
- public Jabberwocky(int x, int y) {
- this.x = x;
- this.y = y;
- w = 30;
- h = 20;
- bounce = 0;
- }
+ public Jabberwocky (int x, int y) {
+ this.x = x;
+ this.y = y;
+ w = 30;
+ h = 20;
+ bounce = 0;
+ }
- public void tick() {
- slamTime++;
- if (temperature > 0) {
- temperature--;
- for (int i = 0; i < 1; i++) {
- if (random.nextInt(MAX_TEMPERATURE) <= temperature) {
- double xd = (random.nextDouble() - random.nextDouble()) * 0.2;
- double yd = (random.nextDouble() - random.nextDouble()) * 0.2;
- level.add(new Spark(x + random.nextDouble() * w, y + random.nextDouble() * h, xa * 0.2 + xd, ya * 0.2 + yd));
- }
- }
- }
- tryMove(xa, ya);
- xa *= Level.FRICTION;
- ya *= Level.FRICTION;
- ya += Level.GRAVITY;
+ public void tick () {
+ slamTime++;
+ if (temperature > 0) {
+ temperature--;
+ for (int i = 0; i < 1; i++) {
+ if (random.nextInt(MAX_TEMPERATURE) <= temperature) {
+ double xd = (random.nextDouble() - random.nextDouble()) * 0.2;
+ double yd = (random.nextDouble() - random.nextDouble()) * 0.2;
+ level.add(new Spark(x + random.nextDouble() * w, y + random.nextDouble() * h, xa * 0.2 + xd, ya * 0.2 + yd));
+ }
+ }
+ }
+ tryMove(xa, ya);
+ xa *= Level.FRICTION;
+ ya *= Level.FRICTION;
+ ya += Level.GRAVITY;
- java.util.List entities = level.getEntities((int) x + 4, (int) y + 4, w - 8, h - 4);
- for (int i = 0; i < entities.size(); i++) {
- Entity e = entities.get(i);
- if (e instanceof Gunner) {
- temperature += 10;
- if (temperature >= MAX_TEMPERATURE) {
- die();
- }
- }
- e.collideMonster(this);
- }
- }
+ java.util.List entities = level.getEntities((int)x + 4, (int)y + 4, w - 8, h - 4);
+ for (int i = 0; i < entities.size(); i++) {
+ Entity e = entities.get(i);
+ if (e instanceof Gunner) {
+ temperature += 10;
+ if (temperature >= MAX_TEMPERATURE) {
+ die();
+ }
+ }
+ e.collideMonster(this);
+ }
+ }
- public void render(Screen g, Camera camera) {
- int xp = (int) x;
- int yp = (int) y-10;
- g.draw(Art.gremlins[3+(slamTime/10%5==2?1:0)][0], xp, yp);
- // FIXME
-// g.setColor(Color.BLACK);
-// yp+=10;
-// g.fillRect(xp + 5, yp - 8, 20, 3);
-// g.setColor(Color.RED);
-// g.fillRect(xp + 5, yp - 8, (20 * temperature / MAX_TEMPERATURE), 2);
- }
+ public void render (Screen g, Camera camera) {
+ int xp = (int)x;
+ int yp = (int)y - 10;
+ g.draw(Art.gremlins[3 + (slamTime / 10 % 5 == 2 ? 1 : 0)][0], xp, yp);
+ // FIXME
+// g.setColor(Color.BLACK);
+// yp+=10;
+// g.fillRect(xp + 5, yp - 8, 20, 3);
+// g.setColor(Color.RED);
+// g.fillRect(xp + 5, yp - 8, (20 * temperature / MAX_TEMPERATURE), 2);
+ }
- public void hitSpikes() {
- die();
- }
+ public void hitSpikes () {
+ die();
+ }
- private void die() {
- Sound.death.play();
- for (int i = 0; i < 16; i++) {
- level.add(new PlayerGore(x + random.nextDouble() * w, y + random.nextDouble() * h));
- }
- Sound.boom.play();
- for (int i = 0; i < 32; i++) {
- double dir = i * Math.PI * 2 / 8.0;
- double xa = Math.sin(dir);
- double ya = Math.cos(dir);
- double dist = ((i / 8) + 1);
- level.add(new Explosion(0, i * 3, x + w / 2 + xa * dist, y + h / 2 + ya * dist, xa, ya));
- }
- remove();
- }
+ private void die () {
+ Sound.death.play();
+ for (int i = 0; i < 16; i++) {
+ level.add(new PlayerGore(x + random.nextDouble() * w, y + random.nextDouble() * h));
+ }
+ Sound.boom.play();
+ for (int i = 0; i < 32; i++) {
+ double dir = i * Math.PI * 2 / 8.0;
+ double xa = Math.sin(dir);
+ double ya = Math.cos(dir);
+ double dist = ((i / 8) + 1);
+ level.add(new Explosion(0, i * 3, x + w / 2 + xa * dist, y + h / 2 + ya * dist, xa, ya));
+ }
+ remove();
+ }
- public boolean shot(Bullet bullet) {
- return true;
- }
+ public boolean shot (Bullet bullet) {
+ return true;
+ }
- public void explode(Explosion explosion) {
- die();
- }
+ public void explode (Explosion explosion) {
+ die();
+ }
}
diff --git a/demos/metagun/metagun-desktop/src/com/mojang/metagun/entity/Player.java b/demos/metagun/metagun-desktop/src/com/mojang/metagun/entity/Player.java
index 15d6289302b..fcb3207f320 100644
--- a/demos/metagun/metagun-desktop/src/com/mojang/metagun/entity/Player.java
+++ b/demos/metagun/metagun-desktop/src/com/mojang/metagun/entity/Player.java
@@ -1,3 +1,4 @@
+
package com.mojang.metagun.entity;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
@@ -10,229 +11,229 @@
import com.mojang.metagun.screen.Screen;
public class Player extends Entity {
- private int dir = 1;
- private int yAim = 0;
- private int frame = 0;
- public int hatCount = 1;
- public int damage = 0;
- private int noHurtTime = 0;
- public int gunLevel = 0;
- public boolean readSign = false;
- private int shootTime = 0;
-
- public Player(int x, int y) {
- this.x = x;
- this.y = y;
- w = 8;
- h = 18;
- bounce = 0;
- }
-
- public void tick() {
- }
-
- public void render(Screen g, Camera camera) {
- // g.setColor(Color.GREEN);
- int xp = (int) x - (16 - w) / 2;
- int yp = (int) y - 2;
- // g.fillRect(xp, yp, w, h);
-
- int stepFrame = frame / 4 % 4;
-
- TextureRegion[][] sheet = dir == 1 ? Art.player1 : Art.player2;
- if (!onGround) {
- int yya = (int) Math.round(-ya);
- stepFrame = 4;
- if (yya < -1) stepFrame = 5;
- yp += yya;
- }
- g.draw(sheet[3 + stepFrame][hatCount > 0 ? 0 : 1], xp, yp);
-
-
- yp += (stepFrame == 3 ? 1 : 0);
- for (int i = 1; i < hatCount; i++) {
- g.draw(sheet[0][1], xp, yp - i * 2);
- }
-
- if (gunLevel > 0) {
- if (!onGround) {
- int yya = (int) Math.round(-ya);
- if (yya < -1) yya = -1;
- if (yya > 1) yya = 1;
- yp += yya;
- }
- g.draw(sheet[1 + yAim][(gunLevel - 1) * 2], xp, yp);
- }
- }
-
- public void tick(Input input) {
- readSign = true; //onGround && input.buttons[Input.UP] && !input.oldButtons[Input.UP];
- if (noHurtTime > 0) noHurtTime--;
- double speed = 0.4;
- double aimAngle = -0.2;
- yAim = 0;
- if (input.buttons[Input.UP]) {
- aimAngle -= 0.8;
- yAim--;
- }
- if (input.buttons[Input.DOWN]) {
- aimAngle += 0.8;
- yAim++;
- }
- boolean walk = false;
- if (input.buttons[Input.LEFT]) {
- walk = true;
- xa -= speed;
- dir = -1;
- }
- if (input.buttons[Input.RIGHT]) {
- walk = true;
- xa += speed;
- dir = 1;
- }
- if (walk) frame++;
- else frame = 0;
- if (input.buttons[Input.JUMP] && !input.oldButtons[Input.JUMP] && onGround) {
- Sound.jump.play();
- ya -= 2 + Math.abs(xa) * 0.5;
- }
-
- tryMove(xa, ya);
-
- xa *= 0.7;
- if (ya < 0 && input.buttons[Input.JUMP]) {
- ya *= 0.992;
- ya += Level.GRAVITY * 0.5;
- } else {
- ya *= Level.FRICTION;
- ya += Level.GRAVITY;
- }
-
-
- boolean shooting = false;
- if (gunLevel > 0 && input.buttons[Input.SHOOT] && !input.oldButtons[Input.SHOOT]) shooting = true;
- if (gunLevel > 1 && input.buttons[Input.SHOOT] && (!input.oldButtons[Input.SHOOT] || shootTime>0)) {
- shooting = shootTime++%3==0;
- } else {
- shootTime = 0;
- }
- if (shooting) {
- double pow = 3;
- Sound.launch.play();
-
- double xx = x + w / 2.0 - 2.5 + dir * 7;
- double yy = y + h / 2.0 - 2.5 + yAim * 2;
- for (int i = 0; i < 4; i++) {
- double xAim = Math.cos(aimAngle + 0.2) * dir * pow;
- double yAim = Math.sin(aimAngle + 0.2) * pow;
- double xxa = xa + xAim * 0.2;
- double yya = ya + yAim * 0.2;
- level.add(new Spark(xx, yy + (-2 + i) * 0.5, xxa, yya));
- }
- double xAim = Math.cos(aimAngle) * dir * pow;
- double yAim = Math.sin(aimAngle) * pow;
- double xxa = xa + xAim;
- double yya = ya + yAim;
- if (gunLevel==2) {
- xa-=xAim*0.1;
- ya-=yAim*0.1;
- }
- xx = x + w / 2.0 - 2.5;
- Stats.instance.shots++;
- level.add(new Gunner(xx, yy, xxa, yya));
- }
-
- if (y < 5) level.transition(0, -1);
- if (y > 240 - w + 10 - 5) level.transition(0, 1);
- if (x < 0 + 5) level.transition(-1, 0);
- if (x > 320 - h + 10 - 5) level.transition(1, 0);
- }
-
- public void hitSpikes() {
- die();
- }
-
- public void die() {
- if (removed) return;
- if (hatCount > 0) {
- level.add(new Hat(x, y - hatCount * 2));
- hatCount--;
- }
- Sound.death.play();
- for (int i = 0; i < 16; i++) {
- level.add(new PlayerGore(x + random.nextDouble() * w, y + random.nextDouble() * h));
- }
- Stats.instance.deaths++;
- remove();
- }
-
- public boolean shot(Bullet bullet) {
- Sound.pew.play();
- xa += bullet.xa * 0.5;
- ya += bullet.ya * 0.5;
- for (int i = 0; i < 4; i++) {
- double xd = (random.nextDouble() - random.nextDouble()) * 4 - bullet.xa * 3;
- double yd = (random.nextDouble() - random.nextDouble()) * 4 - bullet.ya * 3;
- level.add(new Gore(bullet.x, bullet.y, xa + xd, ya + yd));
- }
- if (noHurtTime != 0) return true;
-
- if (hatCount > 0) {
- while (hatCount>0) {
- Hat hat = new Hat(x, y);
- hat.ya-=hatCount*0.05;
- hat.xxa=(random.nextFloat()-random.nextFloat())*(hatCount-1)*0.5;
- hat.time+=hatCount*6;
- level.add(hat);
- hat.tryMove(0, -hatCount*2);
- hatCount--;
- }
- noHurtTime = 20;
- } else {
- Sound.oof.play();
- damage++;
- noHurtTime = 20;
- if (damage == 4) {
- Sound.death.play();
- for (int i = 0; i < 16; i++) {
- level.add(new PlayerGore(x + random.nextDouble() * w, y + random.nextDouble() * h));
- }
- remove();
- } else {
- level.add(new PlayerGore(bullet.x, bullet.y));
- }
- }
-
- return true;
- }
-
- public void readSign(Sign sign) {
- if (sign.autoRead || readSign) {
- sign.autoRead = false;
- if (sign.id == 6) {
- sign.remove();
- gunLevel = 1;
- level.getGun(1);
- }
- if (sign.id == 15) {
- sign.remove();
- gunLevel = 2;
- level.getGun(2);
- }
- level.readSign(sign);
- }
- sign.remove();
- }
-
- public void outOfBounds() {
- }
-
- public void explode(Explosion explosion) {
- die();
- }
-
- public void collideMonster(Entity e) {
- die();
- }
+ private int dir = 1;
+ private int yAim = 0;
+ private int frame = 0;
+ public int hatCount = 1;
+ public int damage = 0;
+ private int noHurtTime = 0;
+ public int gunLevel = 0;
+ public boolean readSign = false;
+ private int shootTime = 0;
+
+ public Player (int x, int y) {
+ this.x = x;
+ this.y = y;
+ w = 8;
+ h = 18;
+ bounce = 0;
+ }
+
+ public void tick () {
+ }
+
+ public void render (Screen g, Camera camera) {
+ // g.setColor(Color.GREEN);
+ int xp = (int)x - (16 - w) / 2;
+ int yp = (int)y - 2;
+ // g.fillRect(xp, yp, w, h);
+
+ int stepFrame = frame / 4 % 4;
+
+ TextureRegion[][] sheet = dir == 1 ? Art.player1 : Art.player2;
+ if (!onGround) {
+ int yya = (int)Math.round(-ya);
+ stepFrame = 4;
+ if (yya < -1) stepFrame = 5;
+ yp += yya;
+ }
+ g.draw(sheet[3 + stepFrame][hatCount > 0 ? 0 : 1], xp, yp);
+
+ yp += (stepFrame == 3 ? 1 : 0);
+ for (int i = 1; i < hatCount; i++) {
+ g.draw(sheet[0][1], xp, yp - i * 2);
+ }
+
+ if (gunLevel > 0) {
+ if (!onGround) {
+ int yya = (int)Math.round(-ya);
+ if (yya < -1) yya = -1;
+ if (yya > 1) yya = 1;
+ yp += yya;
+ }
+ g.draw(sheet[1 + yAim][(gunLevel - 1) * 2], xp, yp);
+ }
+ }
+
+ public void tick (Input input) {
+ readSign = true; // onGround && input.buttons[Input.UP] && !input.oldButtons[Input.UP];
+ if (noHurtTime > 0) noHurtTime--;
+ double speed = 0.4;
+ double aimAngle = -0.2;
+ yAim = 0;
+ if (input.buttons[Input.UP]) {
+ aimAngle -= 0.8;
+ yAim--;
+ }
+ if (input.buttons[Input.DOWN]) {
+ aimAngle += 0.8;
+ yAim++;
+ }
+ boolean walk = false;
+ if (input.buttons[Input.LEFT]) {
+ walk = true;
+ xa -= speed;
+ dir = -1;
+ }
+ if (input.buttons[Input.RIGHT]) {
+ walk = true;
+ xa += speed;
+ dir = 1;
+ }
+ if (walk)
+ frame++;
+ else
+ frame = 0;
+ if (input.buttons[Input.JUMP] && !input.oldButtons[Input.JUMP] && onGround) {
+ Sound.jump.play();
+ ya -= 2 + Math.abs(xa) * 0.5;
+ }
+
+ tryMove(xa, ya);
+
+ xa *= 0.7;
+ if (ya < 0 && input.buttons[Input.JUMP]) {
+ ya *= 0.992;
+ ya += Level.GRAVITY * 0.5;
+ } else {
+ ya *= Level.FRICTION;
+ ya += Level.GRAVITY;
+ }
+
+ boolean shooting = false;
+ if (gunLevel > 0 && input.buttons[Input.SHOOT] && !input.oldButtons[Input.SHOOT]) shooting = true;
+ if (gunLevel > 1 && input.buttons[Input.SHOOT] && (!input.oldButtons[Input.SHOOT] || shootTime > 0)) {
+ shooting = shootTime++ % 3 == 0;
+ } else {
+ shootTime = 0;
+ }
+ if (shooting) {
+ double pow = 3;
+ Sound.launch.play();
+
+ double xx = x + w / 2.0 - 2.5 + dir * 7;
+ double yy = y + h / 2.0 - 2.5 + yAim * 2;
+ for (int i = 0; i < 4; i++) {
+ double xAim = Math.cos(aimAngle + 0.2) * dir * pow;
+ double yAim = Math.sin(aimAngle + 0.2) * pow;
+ double xxa = xa + xAim * 0.2;
+ double yya = ya + yAim * 0.2;
+ level.add(new Spark(xx, yy + (-2 + i) * 0.5, xxa, yya));
+ }
+ double xAim = Math.cos(aimAngle) * dir * pow;
+ double yAim = Math.sin(aimAngle) * pow;
+ double xxa = xa + xAim;
+ double yya = ya + yAim;
+ if (gunLevel == 2) {
+ xa -= xAim * 0.1;
+ ya -= yAim * 0.1;
+ }
+ xx = x + w / 2.0 - 2.5;
+ Stats.instance.shots++;
+ level.add(new Gunner(xx, yy, xxa, yya));
+ }
+
+ if (y < 5) level.transition(0, -1);
+ if (y > 240 - w + 10 - 5) level.transition(0, 1);
+ if (x < 0 + 5) level.transition(-1, 0);
+ if (x > 320 - h + 10 - 5) level.transition(1, 0);
+ }
+
+ public void hitSpikes () {
+ die();
+ }
+
+ public void die () {
+ if (removed) return;
+ if (hatCount > 0) {
+ level.add(new Hat(x, y - hatCount * 2));
+ hatCount--;
+ }
+ Sound.death.play();
+ for (int i = 0; i < 16; i++) {
+ level.add(new PlayerGore(x + random.nextDouble() * w, y + random.nextDouble() * h));
+ }
+ Stats.instance.deaths++;
+ remove();
+ }
+
+ public boolean shot (Bullet bullet) {
+ Sound.pew.play();
+ xa += bullet.xa * 0.5;
+ ya += bullet.ya * 0.5;
+ for (int i = 0; i < 4; i++) {
+ double xd = (random.nextDouble() - random.nextDouble()) * 4 - bullet.xa * 3;
+ double yd = (random.nextDouble() - random.nextDouble()) * 4 - bullet.ya * 3;
+ level.add(new Gore(bullet.x, bullet.y, xa + xd, ya + yd));
+ }
+ if (noHurtTime != 0) return true;
+
+ if (hatCount > 0) {
+ while (hatCount > 0) {
+ Hat hat = new Hat(x, y);
+ hat.ya -= hatCount * 0.05;
+ hat.xxa = (random.nextFloat() - random.nextFloat()) * (hatCount - 1) * 0.5;
+ hat.time += hatCount * 6;
+ level.add(hat);
+ hat.tryMove(0, -hatCount * 2);
+ hatCount--;
+ }
+ noHurtTime = 20;
+ } else {
+ Sound.oof.play();
+ damage++;
+ noHurtTime = 20;
+ if (damage == 4) {
+ Sound.death.play();
+ for (int i = 0; i < 16; i++) {
+ level.add(new PlayerGore(x + random.nextDouble() * w, y + random.nextDouble() * h));
+ }
+ remove();
+ } else {
+ level.add(new PlayerGore(bullet.x, bullet.y));
+ }
+ }
+
+ return true;
+ }
+
+ public void readSign (Sign sign) {
+ if (sign.autoRead || readSign) {
+ sign.autoRead = false;
+ if (sign.id == 6) {
+ sign.remove();
+ gunLevel = 1;
+ level.getGun(1);
+ }
+ if (sign.id == 15) {
+ sign.remove();
+ gunLevel = 2;
+ level.getGun(2);
+ }
+ level.readSign(sign);
+ }
+ sign.remove();
+ }
+
+ public void outOfBounds () {
+ }
+
+ public void explode (Explosion explosion) {
+ die();
+ }
+
+ public void collideMonster (Entity e) {
+ die();
+ }
}
diff --git a/demos/metagun/metagun-desktop/src/com/mojang/metagun/entity/PlayerGore.java b/demos/metagun/metagun-desktop/src/com/mojang/metagun/entity/PlayerGore.java
index c970637f11e..84e705edf29 100644
--- a/demos/metagun/metagun-desktop/src/com/mojang/metagun/entity/PlayerGore.java
+++ b/demos/metagun/metagun-desktop/src/com/mojang/metagun/entity/PlayerGore.java
@@ -1,3 +1,4 @@
+
package com.mojang.metagun.entity;
import com.mojang.metagun.Art;
@@ -6,48 +7,48 @@
import com.mojang.metagun.screen.Screen;
public class PlayerGore extends Entity {
- private int life;
-
- public PlayerGore(double x, double y) {
- this.x = x;
- this.y = y;
- this.w = 2;
- this.h = 2;
- bounce = 0.8;
- this.xa = 0 + (random.nextDouble() - random.nextDouble()) * 1.5;
- this.ya = -1 + (random.nextDouble() - random.nextDouble()) * 1.5;
-
- life = random.nextInt(90) + 60;
- }
-
- public void tick() {
- if (life-- <= 0) remove();
- onGround = false;
- tryMove(xa, ya);
-
- xa *= Level.FRICTION;
- ya *= Level.FRICTION;
- ya += Level.GRAVITY * 0.5;
- level.add(new Gore(x + random.nextDouble(), y + random.nextDouble() - 1, xa, ya));
- }
-
- protected void hitWall(double xa, double ya) {
- this.xa *= 0.9;
- this.ya *= 0.9;
- }
-
- public void render(Screen g, Camera camera) {
- int xp = (int) x;
- int yp = (int) y;
- g.draw(Art.guys[6][1], xp, yp);
- }
-
- public void hitSpikes() {
- for (int i = 0; i < 4; i++) {
- xa = (random.nextFloat()-random.nextFloat())*6;
- ya = (random.nextFloat()-random.nextFloat())*6;
- level.add(new Gore(x + random.nextDouble(), y + random.nextDouble() - 1, xa, ya));
- }
- remove();
- }
+ private int life;
+
+ public PlayerGore (double x, double y) {
+ this.x = x;
+ this.y = y;
+ this.w = 2;
+ this.h = 2;
+ bounce = 0.8;
+ this.xa = 0 + (random.nextDouble() - random.nextDouble()) * 1.5;
+ this.ya = -1 + (random.nextDouble() - random.nextDouble()) * 1.5;
+
+ life = random.nextInt(90) + 60;
+ }
+
+ public void tick () {
+ if (life-- <= 0) remove();
+ onGround = false;
+ tryMove(xa, ya);
+
+ xa *= Level.FRICTION;
+ ya *= Level.FRICTION;
+ ya += Level.GRAVITY * 0.5;
+ level.add(new Gore(x + random.nextDouble(), y + random.nextDouble() - 1, xa, ya));
+ }
+
+ protected void hitWall (double xa, double ya) {
+ this.xa *= 0.9;
+ this.ya *= 0.9;
+ }
+
+ public void render (Screen g, Camera camera) {
+ int xp = (int)x;
+ int yp = (int)y;
+ g.draw(Art.guys[6][1], xp, yp);
+ }
+
+ public void hitSpikes () {
+ for (int i = 0; i < 4; i++) {
+ xa = (random.nextFloat() - random.nextFloat()) * 6;
+ ya = (random.nextFloat() - random.nextFloat()) * 6;
+ level.add(new Gore(x + random.nextDouble(), y + random.nextDouble() - 1, xa, ya));
+ }
+ remove();
+ }
}
diff --git a/demos/metagun/metagun-desktop/src/com/mojang/metagun/entity/Sign.java b/demos/metagun/metagun-desktop/src/com/mojang/metagun/entity/Sign.java
index 0aa9783a183..7758562c48c 100644
--- a/demos/metagun/metagun-desktop/src/com/mojang/metagun/entity/Sign.java
+++ b/demos/metagun/metagun-desktop/src/com/mojang/metagun/entity/Sign.java
@@ -1,3 +1,4 @@
+
package com.mojang.metagun.entity;
import com.mojang.metagun.Art;
@@ -5,43 +6,43 @@
import com.mojang.metagun.screen.Screen;
public class Sign extends Entity {
- public int id;
- public boolean autoRead = false;
+ public int id;
+ public boolean autoRead = false;
- public Sign(int x, int y, int id) {
- this.x = x;
- this.y = y;
- this.w = 6;
- this.h = 6;
- xa = ya = 0;
- this.id = id;
- autoRead = id == 1;
- if (id==6) autoRead = true;
- if (id==15) autoRead = true;
- }
+ public Sign (int x, int y, int id) {
+ this.x = x;
+ this.y = y;
+ this.w = 6;
+ this.h = 6;
+ xa = ya = 0;
+ this.id = id;
+ autoRead = id == 1;
+ if (id == 6) autoRead = true;
+ if (id == 15) autoRead = true;
+ }
- public void tick() {
- if (id==6 && level.player.gunLevel>=1) remove();
- if (id==15 && level.player.gunLevel>=2) remove();
- java.util.List entities = level.getEntities((int) x, (int) y, 6, 6);
- for (int i = 0; i < entities.size(); i++) {
- Entity e = entities.get(i);
- if (e instanceof Player) {
- Player player = (Player) e;
- player.readSign(this);
- }
- }
- }
+ public void tick () {
+ if (id == 6 && level.player.gunLevel >= 1) remove();
+ if (id == 15 && level.player.gunLevel >= 2) remove();
+ java.util.List entities = level.getEntities((int)x, (int)y, 6, 6);
+ for (int i = 0; i < entities.size(); i++) {
+ Entity e = entities.get(i);
+ if (e instanceof Player) {
+ Player player = (Player)e;
+ player.readSign(this);
+ }
+ }
+ }
- public void render(Screen g, Camera camera) {
- if (id==6 && level.player.gunLevel>=1) return;
- if (id==15 && level.player.gunLevel>=2) return;
- if (id==6) {
- g.draw(Art.walls[5][0], (int)x, (int)y);
- } else if (id==15) {
- g.draw(Art.walls[6][0], (int)x, (int)y);
- } else {
- g.draw(Art.walls[4][0], (int)x, (int)y);
- }
- }
+ public void render (Screen g, Camera camera) {
+ if (id == 6 && level.player.gunLevel >= 1) return;
+ if (id == 15 && level.player.gunLevel >= 2) return;
+ if (id == 6) {
+ g.draw(Art.walls[5][0], (int)x, (int)y);
+ } else if (id == 15) {
+ g.draw(Art.walls[6][0], (int)x, (int)y);
+ } else {
+ g.draw(Art.walls[4][0], (int)x, (int)y);
+ }
+ }
}
diff --git a/demos/metagun/metagun-desktop/src/com/mojang/metagun/entity/Spark.java b/demos/metagun/metagun-desktop/src/com/mojang/metagun/entity/Spark.java
index f40adf9e2af..209d8d1cd2b 100644
--- a/demos/metagun/metagun-desktop/src/com/mojang/metagun/entity/Spark.java
+++ b/demos/metagun/metagun-desktop/src/com/mojang/metagun/entity/Spark.java
@@ -1,3 +1,4 @@
+
package com.mojang.metagun.entity;
import com.mojang.metagun.Art;
@@ -6,38 +7,38 @@
import com.mojang.metagun.screen.Screen;
public class Spark extends Entity {
- private int life;
-
- public Spark(double x, double y, double xa, double ya) {
- this.x = x;
- this.y = y;
- this.w = 1;
- this.h = 1;
- bounce = 0.2;
- this.xa = (xa + (random.nextDouble() - random.nextDouble()) * 0.2);
- this.ya = (ya + (random.nextDouble() - random.nextDouble()) * 0.2);
-
- life = random.nextInt(20) + 10;
- }
-
- public void tick() {
- if (life-- <= 0) remove();
- onGround = false;
- tryMove(xa, ya);
-
- xa *= 0.999;
- ya *= 0.999;
- ya += Level.GRAVITY*0.15;
- }
-
- protected void hitWall(double xa, double ya) {
- this.xa *= 0.4;
- this.ya *= 0.4;
- }
-
- public void render(Screen g, Camera camera) {
- int xp = (int) x;
- int yp = (int) y;
- g.draw(Art.guys[9][1], xp, yp);
- }
+ private int life;
+
+ public Spark (double x, double y, double xa, double ya) {
+ this.x = x;
+ this.y = y;
+ this.w = 1;
+ this.h = 1;
+ bounce = 0.2;
+ this.xa = (xa + (random.nextDouble() - random.nextDouble()) * 0.2);
+ this.ya = (ya + (random.nextDouble() - random.nextDouble()) * 0.2);
+
+ life = random.nextInt(20) + 10;
+ }
+
+ public void tick () {
+ if (life-- <= 0) remove();
+ onGround = false;
+ tryMove(xa, ya);
+
+ xa *= 0.999;
+ ya *= 0.999;
+ ya += Level.GRAVITY * 0.15;
+ }
+
+ protected void hitWall (double xa, double ya) {
+ this.xa *= 0.4;
+ this.ya *= 0.4;
+ }
+
+ public void render (Screen g, Camera camera) {
+ int xp = (int)x;
+ int yp = (int)y;
+ g.draw(Art.guys[9][1], xp, yp);
+ }
}
diff --git a/demos/metagun/metagun-desktop/src/com/mojang/metagun/level/Camera.java b/demos/metagun/metagun-desktop/src/com/mojang/metagun/level/Camera.java
index 927d1a856a8..118e36cb9a6 100644
--- a/demos/metagun/metagun-desktop/src/com/mojang/metagun/level/Camera.java
+++ b/demos/metagun/metagun-desktop/src/com/mojang/metagun/level/Camera.java
@@ -1,10 +1,11 @@
+
package com.mojang.metagun.level;
public class Camera {
- public int x, y, width, height;
-
- public Camera(int width, int height) {
- this.width = width;
- this.height = height;
- }
-}
\ No newline at end of file
+ public int x, y, width, height;
+
+ public Camera (int width, int height) {
+ this.width = width;
+ this.height = height;
+ }
+}
diff --git a/demos/metagun/metagun-desktop/src/com/mojang/metagun/level/Level.java b/demos/metagun/metagun-desktop/src/com/mojang/metagun/level/Level.java
index fe0c0a2d587..bd10aa25bff 100644
--- a/demos/metagun/metagun-desktop/src/com/mojang/metagun/level/Level.java
+++ b/demos/metagun/metagun-desktop/src/com/mojang/metagun/level/Level.java
@@ -37,13 +37,13 @@ public class Level {
// private int xo, yo;
private int tick;
- @SuppressWarnings("unchecked") public Level (GameScreen screen, int w, int h, int xo, int yo, int xSpawn, int ySpawn) {
+ @SuppressWarnings("unchecked")
+ public Level (GameScreen screen, int w, int h, int xo, int yo, int xSpawn, int ySpawn) {
this.screen = screen;
-// int[] pixels = new int[32 * 24];
+// int[] pixels = new int[32 * 24];
this.xSpawn = xSpawn;
this.ySpawn = ySpawn;
-
// Art.level.getRGB(xo * 31, yo * 23, 32, 24, pixels, 0, 32);
walls = new byte[w * h];
@@ -56,7 +56,7 @@ public class Level {
entityMap[x + y * w] = new ArrayList();
// int col = pixels[x + y * w] & 0xffffff;
- int col = (Art.level.getPixel(x + xo * 31, y + yo * 23) & 0xffffff00) >>> 8;
+ int col = (Art.level.getPixel(x + xo * 31, y + yo * 23) & 0xffffff00) >>> 8;
byte wall = 0;
if (col == 0xffffff)
@@ -117,8 +117,8 @@ else if (col == 0x83FFFF) {
add(e);
}
walls[x + y * w] = wall;
- }
- }
+ }
+ }
player = new Player(this.xSpawn, this.ySpawn);
add(player);
}
@@ -205,7 +205,7 @@ public void render (Screen screen, Camera camera) {
matrix.setToTranslation(camera.x, camera.y, 0);
screen.spriteBatch.setTransformMatrix(matrix);
screen.spriteBatch.begin();
- //g.translate(-camera.x, -camera.y);
+ // g.translate(-camera.x, -camera.y);
int xo = 0;
int yo = 0;
@@ -243,9 +243,8 @@ public void render (Screen screen, Camera camera) {
ximg = 3;
}
- if(w == 0)
- continue;
-
+ if (w == 0) continue;
+
screen.draw(Art.walls[ximg][yimg], x * 10, y * 10);
}
}
@@ -254,7 +253,7 @@ public void render (Screen screen, Camera camera) {
Entity e = entities.get(i);
e.render(screen, camera);
}
-
+
screen.spriteBatch.end();
}
diff --git a/demos/metagun/metagun-desktop/src/com/mojang/metagun/screen/ExpositionScreen.java b/demos/metagun/metagun-desktop/src/com/mojang/metagun/screen/ExpositionScreen.java
index 850cda88894..ade61503dc7 100644
--- a/demos/metagun/metagun-desktop/src/com/mojang/metagun/screen/ExpositionScreen.java
+++ b/demos/metagun/metagun-desktop/src/com/mojang/metagun/screen/ExpositionScreen.java
@@ -1,3 +1,4 @@
+
package com.mojang.metagun.screen;
import java.io.BufferedReader;
@@ -10,53 +11,53 @@
import com.mojang.metagun.Input;
public class ExpositionScreen extends Screen {
- private int time = 0;
-
- // "1234567890123456789012345678901234567890"
-
- private List lines = new ArrayList();
-
- public ExpositionScreen() {
- try {
- BufferedReader br = new BufferedReader(new InputStreamReader(Gdx.files.internal("res/exposition.txt").read()));
-
- String line = "";
- while ((line = br.readLine()) != null) {
- lines.add(line);
- }
- br.close();
- } catch (Exception e) {
- e.printStackTrace();
- }
-
- }
-
- public void render() {
- int w = -Art.bg.getRegionHeight();
- spriteBatch.begin();
- draw(Art.bg, 0, -(time / 8 % w));
- draw(Art.bg, 0, -(time / 8 % w) + w);
-
- int yo = time / 4;
- for (int y = 0; y <= 240 / 6; y++) {
- int yl = yo / 6 - 240 / 6+y;
- if (yl >= 0 && yl < lines.size()) {
- drawString(lines.get(yl), (320 - 40 * 6)/2, y * 6 - yo % 6);
- }
- }
- spriteBatch.end();
- }
-
- public void tick(Input input) {
- time++;
- if (time / 4 > lines.size() * 6 + 250) {
- setScreen(new TitleScreen());
- }
- if (input.buttons[Input.SHOOT] && !input.oldButtons[Input.SHOOT] || Gdx.input.isTouched()) {
- setScreen(new TitleScreen());
- }
- if (input.buttons[Input.ESCAPE] && !input.oldButtons[Input.ESCAPE]) {
- setScreen(new TitleScreen());
- }
- }
+ private int time = 0;
+
+ // "1234567890123456789012345678901234567890"
+
+ private List lines = new ArrayList();
+
+ public ExpositionScreen () {
+ try {
+ BufferedReader br = new BufferedReader(new InputStreamReader(Gdx.files.internal("res/exposition.txt").read()));
+
+ String line = "";
+ while ((line = br.readLine()) != null) {
+ lines.add(line);
+ }
+ br.close();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ }
+
+ public void render () {
+ int w = -Art.bg.getRegionHeight();
+ spriteBatch.begin();
+ draw(Art.bg, 0, -(time / 8 % w));
+ draw(Art.bg, 0, -(time / 8 % w) + w);
+
+ int yo = time / 4;
+ for (int y = 0; y <= 240 / 6; y++) {
+ int yl = yo / 6 - 240 / 6 + y;
+ if (yl >= 0 && yl < lines.size()) {
+ drawString(lines.get(yl), (320 - 40 * 6) / 2, y * 6 - yo % 6);
+ }
+ }
+ spriteBatch.end();
+ }
+
+ public void tick (Input input) {
+ time++;
+ if (time / 4 > lines.size() * 6 + 250) {
+ setScreen(new TitleScreen());
+ }
+ if (input.buttons[Input.SHOOT] && !input.oldButtons[Input.SHOOT] || Gdx.input.isTouched()) {
+ setScreen(new TitleScreen());
+ }
+ if (input.buttons[Input.ESCAPE] && !input.oldButtons[Input.ESCAPE]) {
+ setScreen(new TitleScreen());
+ }
+ }
}
diff --git a/demos/metagun/metagun-desktop/src/com/mojang/metagun/screen/GameScreen.java b/demos/metagun/metagun-desktop/src/com/mojang/metagun/screen/GameScreen.java
index 1b0c587b7cc..934cc1120b8 100644
--- a/demos/metagun/metagun-desktop/src/com/mojang/metagun/screen/GameScreen.java
+++ b/demos/metagun/metagun-desktop/src/com/mojang/metagun/screen/GameScreen.java
@@ -74,25 +74,25 @@ public void transition (int xa, int ya) {
public void render () {
spriteBatch.begin();
-// draw(Art.bg, -xLevel * 160, -yLevel * 120);
+// draw(Art.bg, -xLevel * 160, -yLevel * 120);
draw(Art.bg, 0, 0);
spriteBatch.end();
level.render(this, camera);
-
+
spriteBatch.begin();
if (mayRespawn) {
String msg = "PRESS X TO TRY AGAIN";
drawString(msg, 160 - msg.length() * 3, 120 - 3);
}
- if(Gdx.app.getType() == ApplicationType.Android) {
- draw(Art.buttons[0][0], 0, 240-32);
- draw(Art.buttons[1][0], 32, 240-32);
-
- draw(Art.buttons[4][0], 160-32, 240-32);
- draw(Art.buttons[5][0], 160, 240-32);
-
- draw(Art.buttons[2][0], 320-64, 240-32);
- draw(Art.buttons[3][0], 320-32, 240-32);
+ if (Gdx.app.getType() == ApplicationType.Android) {
+ draw(Art.buttons[0][0], 0, 240 - 32);
+ draw(Art.buttons[1][0], 32, 240 - 32);
+
+ draw(Art.buttons[4][0], 160 - 32, 240 - 32);
+ draw(Art.buttons[5][0], 160, 240 - 32);
+
+ draw(Art.buttons[2][0], 320 - 64, 240 - 32);
+ draw(Art.buttons[3][0], 320 - 32, 240 - 32);
}
spriteBatch.end();
}
diff --git a/demos/metagun/metagun-desktop/src/com/mojang/metagun/screen/LevelTransitionScreen.java b/demos/metagun/metagun-desktop/src/com/mojang/metagun/screen/LevelTransitionScreen.java
index c63a5f32024..264fbc219b4 100644
--- a/demos/metagun/metagun-desktop/src/com/mojang/metagun/screen/LevelTransitionScreen.java
+++ b/demos/metagun/metagun-desktop/src/com/mojang/metagun/screen/LevelTransitionScreen.java
@@ -31,23 +31,24 @@ public void tick (Input input) {
setScreen(parent);
}
}
-
- Camera c = new Camera(320, 240);
- public void render () {
+
+ Camera c = new Camera(320, 240);
+
+ public void render () {
double pow = time / (double)TRANSITION_DURATION;
-
+
spriteBatch.getTransformMatrix().idt();
- spriteBatch.begin();
-// draw(Art.bg, -xLevel * 160 - (int)(xa * 160 * pow), -yLevel * 120 - (int)(ya * 120 * pow));
+ spriteBatch.begin();
+// draw(Art.bg, -xLevel * 160 - (int)(xa * 160 * pow), -yLevel * 120 - (int)(ya * 120 * pow));
draw(Art.bg, 0, 0);
spriteBatch.end();
-
+
c.x = (int)(-xa * 320 * pow);
- c.y = (int)(-ya * 240 * pow);
- level1.render(this, c);
-
- c.x = (int)(xa * 320 * (1-pow));
- c.y = (int)(ya * 240 * (1-pow));
- level2.render(this, c);
+ c.y = (int)(-ya * 240 * pow);
+ level1.render(this, c);
+
+ c.x = (int)(xa * 320 * (1 - pow));
+ c.y = (int)(ya * 240 * (1 - pow));
+ level2.render(this, c);
}
}
diff --git a/demos/metagun/metagun-desktop/src/com/mojang/metagun/screen/PauseScreen.java b/demos/metagun/metagun-desktop/src/com/mojang/metagun/screen/PauseScreen.java
index 9aa9ccfa741..5cfb31d8ac6 100644
--- a/demos/metagun/metagun-desktop/src/com/mojang/metagun/screen/PauseScreen.java
+++ b/demos/metagun/metagun-desktop/src/com/mojang/metagun/screen/PauseScreen.java
@@ -1,79 +1,80 @@
+
package com.mojang.metagun.screen;
import com.mojang.metagun.Art;
import com.mojang.metagun.Input;
public class PauseScreen extends Screen {
- private GameScreen parent;
- private int selected = 0;
+ private GameScreen parent;
+ private int selected = 0;
+
+ private String[] options = {"BACK TO GAME", "AUTOMORTIS", "QUIT TO TITLE"};
- private String[] options = { "BACK TO GAME", "AUTOMORTIS", "QUIT TO TITLE" };
+ public PauseScreen (GameScreen parent) {
+ this.parent = parent;
+ }
- public PauseScreen(GameScreen parent) {
- this.parent = parent;
- }
+ public void render () {
+ parent.render();
- public void render() {
- parent.render();
-
- spriteBatch.begin();
- int xs = 0;
- int ys = options.length;
- for (int y = 0; y < options.length; y++) {
- int s = options[y].length();
- if (s > xs) xs = s;
- }
- xs += 1;
- int xp = 40;
- int yp = 40;
- for (int x = 0 - 1; x < xs + 1; x++) {
- for (int y = 0 - 1; y < ys + 1; y++) {
- int xf = 1;
- int yf = 12;
- if (x < 0) xf--;
- if (y < 0) yf--;
- if (x >= xs) xf++;
- if (y >= ys) yf++;
- draw(Art.guys[xf][yf], xp + x * 6, yp + y * 6);
- }
- }
- for (int y = 0; y < options.length; y++) {
- if (y == selected) {
- drawString("+", xp, yp + y * 6);
- }
- drawString(options[y], xp + 6, yp + y * 6);
- }
- spriteBatch.end();
- }
+ spriteBatch.begin();
+ int xs = 0;
+ int ys = options.length;
+ for (int y = 0; y < options.length; y++) {
+ int s = options[y].length();
+ if (s > xs) xs = s;
+ }
+ xs += 1;
+ int xp = 40;
+ int yp = 40;
+ for (int x = 0 - 1; x < xs + 1; x++) {
+ for (int y = 0 - 1; y < ys + 1; y++) {
+ int xf = 1;
+ int yf = 12;
+ if (x < 0) xf--;
+ if (y < 0) yf--;
+ if (x >= xs) xf++;
+ if (y >= ys) yf++;
+ draw(Art.guys[xf][yf], xp + x * 6, yp + y * 6);
+ }
+ }
+ for (int y = 0; y < options.length; y++) {
+ if (y == selected) {
+ drawString("+", xp, yp + y * 6);
+ }
+ drawString(options[y], xp + 6, yp + y * 6);
+ }
+ spriteBatch.end();
+ }
- public void tick(Input input) {
- if (!input.oldButtons[Input.ESCAPE] && input.buttons[Input.ESCAPE]) {
- setScreen(parent);
- return;
- }
- if (input.buttons[Input.UP] && !input.oldButtons[Input.UP]) {
- selected--;
- if (selected < 0) selected += options.length;
- }
- if (input.buttons[Input.DOWN] && !input.oldButtons[Input.DOWN]) {
- selected++;
- if (selected >= options.length) selected -= options.length;
- }
- if (input.buttons[Input.SHOOT] && !input.oldButtons[Input.SHOOT]) {
- if (selected==0) {
- setScreen(parent);
- } else if (selected==1) {
- parent.level.player.die();
- setScreen(parent);
- } else if (selected==2) {
- setScreen(new TitleScreen());
- } else if (selected==3) {
- setScreen(new WinScreen());
- }
- }
- // if (delay>0) delay--;
- // if (delay==0 && input.buttons[Input.SHOOT] && !input.oldButtons[Input.SHOOT]) {
- // setScreen(parent);
- // }
- }
+ public void tick (Input input) {
+ if (!input.oldButtons[Input.ESCAPE] && input.buttons[Input.ESCAPE]) {
+ setScreen(parent);
+ return;
+ }
+ if (input.buttons[Input.UP] && !input.oldButtons[Input.UP]) {
+ selected--;
+ if (selected < 0) selected += options.length;
+ }
+ if (input.buttons[Input.DOWN] && !input.oldButtons[Input.DOWN]) {
+ selected++;
+ if (selected >= options.length) selected -= options.length;
+ }
+ if (input.buttons[Input.SHOOT] && !input.oldButtons[Input.SHOOT]) {
+ if (selected == 0) {
+ setScreen(parent);
+ } else if (selected == 1) {
+ parent.level.player.die();
+ setScreen(parent);
+ } else if (selected == 2) {
+ setScreen(new TitleScreen());
+ } else if (selected == 3) {
+ setScreen(new WinScreen());
+ }
+ }
+ // if (delay>0) delay--;
+ // if (delay==0 && input.buttons[Input.SHOOT] && !input.oldButtons[Input.SHOOT]) {
+ // setScreen(parent);
+ // }
+ }
}
diff --git a/demos/metagun/metagun-desktop/src/com/mojang/metagun/screen/Screen.java b/demos/metagun/metagun-desktop/src/com/mojang/metagun/screen/Screen.java
index a99fde9d71a..bd5dfa1a4da 100644
--- a/demos/metagun/metagun-desktop/src/com/mojang/metagun/screen/Screen.java
+++ b/demos/metagun/metagun-desktop/src/com/mojang/metagun/screen/Screen.java
@@ -36,7 +36,7 @@ protected void setScreen (Screen screen) {
public void draw (TextureRegion region, int x, int y) {
int width = region.getRegionWidth();
- if(width <0) width = -width;
+ if (width < 0) width = -width;
spriteBatch.draw(region, x, y, width, -region.getRegionHeight());
}
diff --git a/demos/metagun/metagun-desktop/src/com/mojang/metagun/screen/SignReadScreen.java b/demos/metagun/metagun-desktop/src/com/mojang/metagun/screen/SignReadScreen.java
index 503956637a2..369d7473999 100644
--- a/demos/metagun/metagun-desktop/src/com/mojang/metagun/screen/SignReadScreen.java
+++ b/demos/metagun/metagun-desktop/src/com/mojang/metagun/screen/SignReadScreen.java
@@ -1,205 +1,81 @@
+
package com.mojang.metagun.screen;
-import com.badlogic.gdx.Gdx;
import com.mojang.metagun.Art;
import com.mojang.metagun.Input;
public class SignReadScreen extends Screen {
- private Screen parent;
-
- private String[][] signs = {
- {
- "READING",
- "",
- "PRESS UP TO READ SIGNS"
- },
- {
- "JUMPING",
- "",
- "PRESS Z TO JUMP",
- "YOU CAN JUMP HIGHER BY",
- "GETTING A RUNNING START",
- "OR HOLDING DOWN Z",
- },
- {
- "PROGRESSING",
- "",
- "LEAVE A ROOM THROUGH ANY",
- "EXIT TO CONTINUE YOUR",
- "ADVENTURE",
- },
- {
- "DYING",
- "",
- "IF YOU DIE, YOU RESTART",
- "AT THE BEGINNING OF THE",
- "CURRENT ROOM",
- },
- {
- "DODGING",
- "",
- "THE GUNNERS DON'T LIKE YOU",
- "AND SHOOT AT YOU.",
- "IT WOULD BE WISE TO STAY AWAY",
- },
- {
- "THE LAUNCHER",
- "",
- "AS YOU PICK UP THE LAUNCHER,",
- "YOU REALIZE IT'S NOT YOUR",
- "AVERAGE LAUNCHER.",
- "",
- "PRESS UP AND DOWN TO AIM",
- "PRESS X TO FIRE THE LAUNCHER",
- },
- {
- "JONESING",
- "",
- "DON'T FORGET YOUR FEDORA!",
- },
- {
- "EXPLODING",
- "",
- "TNT BLOCKS ARE HIGHLY",
- "EXPLOSIVE, AND WILL",
- "REACT POORLY TO BEING",
- "SHOT.",
- },
- {
- "PUSHING",
- "",
- "THE CAMARADERIE BOX IS",
- "SOMETHING SOMETHING",
- "",
- "IT'S FROM PORTAL.",
- },
- {
- "BATTLING",
- "",
- "THE GREMLIN IS LARGE",
- "AND IN YOUR WAY.",
- "OVERHEAT IT TO DESTROY",
- "IT AND CLAIM YOUR PRIZE",
- },
- {
- "EVADING",
- "",
- "THE GUNNERS SHOTS WILL",
- "PASS THROUGH GLASS.",
- "YOU, HOWEVER, WILL NOT",
- },
- {
- "SWEATING",
- "",
- "THESE SLIGHTLY MORE",
- "SOPHISTICATED GREMLINS",
- "HAVE LEARNED A NEW",
- "TRICK",
- },
- {
- "CONVEYING",
- "",
- "TIME TO BURN OFF SOME",
- "FAT AND HAVE FUN WHILE",
- "DOING IT!",
- },
- {
- "BOSSFIGHTING",
- "",
- "BEHIND THIS DOOR, MEGAN",
- "AWAITS! WHO IS MEGAN?",
- "ARE YOU MEGAN?",
- },
- {
- "THE NEW LAUNCHER",
- "",
- "WELL, THIS IS BAD."
- },
- {
- "FEEDING",
- "",
- "THE JABBERWOCKY IS",
- "HUNGRY, AND WILL EAT",
- "WAY MORE THAN IT SHOULD",
- "",
- "PLEASE DO NOT FEED!",
- },
- {
- "HOVERING",
- "",
- "THE RECOIL ON THE NEW",
- "LAUNCHER SURE IS",
- "POWERFUL!",
- },
- {
- "FLYING",
- "",
- "SERIOUSLY, THE RECOIL",
- "IS OUT OF THIS WORLD!",
- },
- {
- "WINNING",
- "",
- "YOUR FINAL CHALLENGE",
- "IS RIGHT DOWN THIS",
- "HALLWAY.",
- },
- {
- "FRESHERERST",
- "",
- "BIG ADAM, GIANT SISTER.",
- "IT IS KNOWN BY MANY NAMES",
- "BUT JUDITH 4HRPG BLUEBERRY.",
- "",
- "FISSION MAILED!",
- },
- };
-
- private int delay = 15;
- private int id;
- public SignReadScreen(Screen parent, int id) {
- this.parent = parent;
- this.id = id;
- }
-
- public void render() {
- parent.render();
- spriteBatch.begin();
- int xs = 0;
- int ys = signs[id].length+3;
- for (int y=0; yxs) xs = s;
- }
- int xp = 160-xs*3;
- int yp = 120-ys*3;
- for (int x=0-1; x=xs) xf++;
- if (y>=ys) yf++;
- draw(Art.guys[xf][yf], xp+x*6, yp+y*6);
- }
- }
- for (int y=0; y0) delay--;
- if (delay==0 && input.buttons[Input.SHOOT] && !input.oldButtons[Input.SHOOT]) {
- setScreen(parent);
- }
- }
+ private Screen parent;
+
+ private String[][] signs = {
+ {"READING", "", "PRESS UP TO READ SIGNS"},
+ {"JUMPING", "", "PRESS Z TO JUMP", "YOU CAN JUMP HIGHER BY", "GETTING A RUNNING START", "OR HOLDING DOWN Z",},
+ {"PROGRESSING", "", "LEAVE A ROOM THROUGH ANY", "EXIT TO CONTINUE YOUR", "ADVENTURE",},
+ {"DYING", "", "IF YOU DIE, YOU RESTART", "AT THE BEGINNING OF THE", "CURRENT ROOM",},
+ {"DODGING", "", "THE GUNNERS DON'T LIKE YOU", "AND SHOOT AT YOU.", "IT WOULD BE WISE TO STAY AWAY",},
+ {"THE LAUNCHER", "", "AS YOU PICK UP THE LAUNCHER,", "YOU REALIZE IT'S NOT YOUR", "AVERAGE LAUNCHER.", "",
+ "PRESS UP AND DOWN TO AIM", "PRESS X TO FIRE THE LAUNCHER",},
+ {"JONESING", "", "DON'T FORGET YOUR FEDORA!",},
+ {"EXPLODING", "", "TNT BLOCKS ARE HIGHLY", "EXPLOSIVE, AND WILL", "REACT POORLY TO BEING", "SHOT.",},
+ {"PUSHING", "", "THE CAMARADERIE BOX IS", "SOMETHING SOMETHING", "", "IT'S FROM PORTAL.",},
+ {"BATTLING", "", "THE GREMLIN IS LARGE", "AND IN YOUR WAY.", "OVERHEAT IT TO DESTROY", "IT AND CLAIM YOUR PRIZE",},
+ {"EVADING", "", "THE GUNNERS SHOTS WILL", "PASS THROUGH GLASS.", "YOU, HOWEVER, WILL NOT",},
+ {"SWEATING", "", "THESE SLIGHTLY MORE", "SOPHISTICATED GREMLINS", "HAVE LEARNED A NEW", "TRICK",},
+ {"CONVEYING", "", "TIME TO BURN OFF SOME", "FAT AND HAVE FUN WHILE", "DOING IT!",},
+ {"BOSSFIGHTING", "", "BEHIND THIS DOOR, MEGAN", "AWAITS! WHO IS MEGAN?", "ARE YOU MEGAN?",},
+ {"THE NEW LAUNCHER", "", "WELL, THIS IS BAD."},
+ {"FEEDING", "", "THE JABBERWOCKY IS", "HUNGRY, AND WILL EAT", "WAY MORE THAN IT SHOULD", "", "PLEASE DO NOT FEED!",},
+ {"HOVERING", "", "THE RECOIL ON THE NEW", "LAUNCHER SURE IS", "POWERFUL!",},
+ {"FLYING", "", "SERIOUSLY, THE RECOIL", "IS OUT OF THIS WORLD!",},
+ {"WINNING", "", "YOUR FINAL CHALLENGE", "IS RIGHT DOWN THIS", "HALLWAY.",},
+ {"FRESHERERST", "", "BIG ADAM, GIANT SISTER.", "IT IS KNOWN BY MANY NAMES", "BUT JUDITH 4HRPG BLUEBERRY.", "",
+ "FISSION MAILED!",},};
+
+ private int delay = 15;
+ private int id;
+
+ public SignReadScreen (Screen parent, int id) {
+ this.parent = parent;
+ this.id = id;
+ }
+
+ public void render () {
+ parent.render();
+ spriteBatch.begin();
+ int xs = 0;
+ int ys = signs[id].length + 3;
+ for (int y = 0; y < signs[id].length; y++) {
+ int s = signs[id][y].length();
+ if (s > xs) xs = s;
+ }
+ int xp = 160 - xs * 3;
+ int yp = 120 - ys * 3;
+ for (int x = 0 - 1; x < xs + 1; x++) {
+ for (int y = 0 - 1; y < ys + 1; y++) {
+ int xf = 1;
+ int yf = 12;
+ if (x < 0) xf--;
+ if (y < 0) yf--;
+ if (x >= xs) xf++;
+ if (y >= ys) yf++;
+ draw(Art.guys[xf][yf], xp + x * 6, yp + y * 6);
+ }
+ }
+ for (int y = 0; y < signs[id].length; y++) {
+ drawString(signs[id][y], xp, yp + y * 6);
+ }
+ if (delay == 0) drawString("PRESS X", xp + (xs - 8) * 6, yp + (signs[id].length + 2) * 6);
+ spriteBatch.end();
+ }
+
+ public void tick (Input input) {
+ if (!input.oldButtons[Input.ESCAPE] && input.buttons[Input.ESCAPE]) {
+ setScreen(parent);
+ return;
+ }
+ if (delay > 0) delay--;
+ if (delay == 0 && input.buttons[Input.SHOOT] && !input.oldButtons[Input.SHOOT]) {
+ setScreen(parent);
+ }
+ }
}
diff --git a/demos/metagun/metagun-desktop/src/com/mojang/metagun/screen/TitleScreen.java b/demos/metagun/metagun-desktop/src/com/mojang/metagun/screen/TitleScreen.java
index a5cd49d1fb5..f30ca84951f 100644
--- a/demos/metagun/metagun-desktop/src/com/mojang/metagun/screen/TitleScreen.java
+++ b/demos/metagun/metagun-desktop/src/com/mojang/metagun/screen/TitleScreen.java
@@ -1,3 +1,4 @@
+
package com.mojang.metagun.screen;
import com.badlogic.gdx.Application.ApplicationType;
@@ -7,41 +8,41 @@
import com.mojang.metagun.Sound;
public class TitleScreen extends Screen {
- private int time = 0;
-
- public void render() {
- int yOffs = 480 - time * 2;
- if (yOffs < 0) yOffs = 0;
- spriteBatch.begin();
- draw(Art.bg, 0, 0);
- draw(Art.titleScreen, 0, -yOffs);
- if (time > 240) {
- String msg = null;
- if(Gdx.app.getType()==ApplicationType.Android)
- msg = "TOUCH TO START";
- else
- msg = "PRESS X TO START";
- drawString(msg, 160 - msg.length() * 3, 140 - 3 - (int) (Math.abs(Math.sin(time * 0.1) * 10)));
+ private int time = 0;
+
+ public void render () {
+ int yOffs = 480 - time * 2;
+ if (yOffs < 0) yOffs = 0;
+ spriteBatch.begin();
+ draw(Art.bg, 0, 0);
+ draw(Art.titleScreen, 0, -yOffs);
+ if (time > 240) {
+ String msg = null;
+ if (Gdx.app.getType() == ApplicationType.Android)
+ msg = "TOUCH TO START";
+ else
+ msg = "PRESS X TO START";
+ drawString(msg, 160 - msg.length() * 3, 140 - 3 - (int)(Math.abs(Math.sin(time * 0.1) * 10)));
- }
- if (time >=0) {
- String msg = "COPYRIGHT MOJANG 2010";
- drawString(msg, 2, 240-6-2);
- }
- spriteBatch.end();
- }
+ }
+ if (time >= 0) {
+ String msg = "COPYRIGHT MOJANG 2010";
+ drawString(msg, 2, 240 - 6 - 2);
+ }
+ spriteBatch.end();
+ }
- public void tick(Input input) {
- time++;
- if (time > 240) {
- if (input.buttons[Input.SHOOT] && !input.oldButtons[Input.SHOOT] || Gdx.input.isTouched()) {
- Sound.startgame.play();
- setScreen(new GameScreen());
- input.releaseAllKeys();
- }
- }
- if (time > 60*10) {
- setScreen(new ExpositionScreen());
- }
- }
+ public void tick (Input input) {
+ time++;
+ if (time > 240) {
+ if (input.buttons[Input.SHOOT] && !input.oldButtons[Input.SHOOT] || Gdx.input.isTouched()) {
+ Sound.startgame.play();
+ setScreen(new GameScreen());
+ input.releaseAllKeys();
+ }
+ }
+ if (time > 60 * 10) {
+ setScreen(new ExpositionScreen());
+ }
+ }
}
diff --git a/demos/metagun/metagun-desktop/src/com/mojang/metagun/screen/WinScreen.java b/demos/metagun/metagun-desktop/src/com/mojang/metagun/screen/WinScreen.java
index 9bb3579d1a2..e5dcf7267ed 100644
--- a/demos/metagun/metagun-desktop/src/com/mojang/metagun/screen/WinScreen.java
+++ b/demos/metagun/metagun-desktop/src/com/mojang/metagun/screen/WinScreen.java
@@ -1,3 +1,4 @@
+
package com.mojang.metagun.screen;
import com.mojang.metagun.Art;
@@ -5,67 +6,67 @@
import com.mojang.metagun.Stats;
public class WinScreen extends Screen {
- private int time = 0;
-
- public void render() {
- spriteBatch.begin();
- int w = 240 * 8; //Art.bg.getHeight();
- draw(Art.bg, 0, -(time*2%w));
- draw(Art.bg, 0, -(time*2%w)+w);
+ private int time = 0;
+
+ public void render () {
+ spriteBatch.begin();
+ int w = 240 * 8; // Art.bg.getHeight();
+ draw(Art.bg, 0, -(time * 2 % w));
+ draw(Art.bg, 0, -(time * 2 % w) + w);
+
+ int offs0 = 500 - time * 10;
+ if (offs0 < 0) offs0 = 0;
+ int offs1 = 1200 - time * 16;
+ if (offs1 < 0) offs1 = 0;
+ int yOffs = 600 - time * 5;
+ if (yOffs < -120) yOffs = -120;
+ if (yOffs > 0) yOffs = 0;
+ draw(Art.winScreen1, offs0, yOffs + 30);
+ draw(Art.winScreen2, -offs1, yOffs * 2 / 3 + 30);
+
+ int tt = time - (60 * 2 + 30);
+ int yo = 130;
+ int xo = 120 - 8 * 3;
+ if (tt >= 0) {
+ drawString(" TIME: " + Stats.instance.getTimeString(), xo, yo + 0 * 6);
+ drawString(" DEATHS: " + Stats.instance.deaths, xo, yo + 1 * 6);
+ drawString(" FEDORAS: " + Stats.instance.hats + "/" + 7, xo, yo + 2 * 6);
+ drawString("SHOTS FIRED: " + Stats.instance.shots, xo, yo + 3 * 6);
+ drawString("FINAL SCORE: " + timeScale(Stats.instance.getFinalScore(), tt - 30 * 5), xo, yo + 5 * 6);
+
+ drawString(timeHideScale(Stats.instance.getSpeedScore(), tt - 30 * 1), xo + 20 * 6, yo + 0 * 6);
+ drawString(timeHideScale(Stats.instance.getDeathScore(), tt - 30 * 2), xo + 20 * 6, yo + 1 * 6);
+ drawString(timeHideScale(Stats.instance.getHatScore(), tt - 30 * 3), xo + 20 * 6, yo + 2 * 6);
+ drawString(timeHideScale(Stats.instance.getShotScore(), tt - 30 * 4), xo + 20 * 6, yo + 3 * 6);
+ }
+
+ if (time > 60 * 7 && (time / 30 % 2 == 0)) {
+ String msg = "PRESS X TO RESET THE GAME";
+ drawString(msg, 160 - msg.length() * 3, yo + 10 * 6);
+ }
+ spriteBatch.end();
+ }
- int offs0 = 500-time*10;
- if (offs0<0) offs0=0;
- int offs1 = 1200-time*16;
- if (offs1<0) offs1=0;
- int yOffs = 600-time*5;
- if (yOffs<-120) yOffs = -120;
- if (yOffs>0) yOffs = 0;
- draw(Art.winScreen1, offs0, yOffs+30);
- draw(Art.winScreen2, -offs1, yOffs*2/3+30);
-
- int tt = time-(60*2+30);
- int yo = 130;
- int xo = 120-8*3;
- if (tt>=0) {
- drawString(" TIME: "+Stats.instance.getTimeString(), xo, yo+0*6);
- drawString(" DEATHS: "+Stats.instance.deaths, xo, yo+1*6);
- drawString(" FEDORAS: "+Stats.instance.hats+"/"+7, xo, yo+2*6);
- drawString("SHOTS FIRED: "+Stats.instance.shots, xo, yo+3*6);
- drawString("FINAL SCORE: "+timeScale(Stats.instance.getFinalScore(), tt-30*5), xo, yo+5*6);
+ private String timeHideScale (int val, int time) {
+ if (time < 10) return "";
+// if (time>60+60) return "";
+ if (time < 0) time = 0;
+ if (time > 60) time = 60;
+ return "+" + val * time / 60;
+ }
- drawString(timeHideScale(Stats.instance.getSpeedScore(), tt-30*1), xo+20*6, yo+0*6);
- drawString(timeHideScale(Stats.instance.getDeathScore(), tt-30*2), xo+20*6, yo+1*6);
- drawString(timeHideScale(Stats.instance.getHatScore(), tt-30*3), xo+20*6, yo+2*6);
- drawString(timeHideScale(Stats.instance.getShotScore(), tt-30*4), xo+20*6, yo+3*6);
- }
-
- if (time>60*7 && (time/30%2==0)) {
- String msg = "PRESS X TO RESET THE GAME";
- drawString(msg, 160-msg.length()*3, yo+10*6);
- }
- spriteBatch.end();
- }
-
- private String timeHideScale(int val, int time) {
- if (time<10) return "";
-// if (time>60+60) return "";
- if (time<0) time = 0;
- if (time>60) time = 60;
- return "+"+val*time/60;
- }
+ private String timeScale (int val, int time) {
+ if (time < 0) time = 0;
+ if (time > 60) time = 60;
+ return "" + val * time / 60;
+ }
- private String timeScale(int val, int time) {
- if (time<0) time = 0;
- if (time>60) time = 60;
- return ""+val*time/60;
- }
-
- public void tick(Input input) {
- time++;
- if (time>60*7) {
- if (input.buttons[Input.SHOOT] && !input.oldButtons[Input.SHOOT]) {
- setScreen(new TitleScreen());
- }
- }
- }
+ public void tick (Input input) {
+ time++;
+ if (time > 60 * 7) {
+ if (input.buttons[Input.SHOOT] && !input.oldButtons[Input.SHOOT]) {
+ setScreen(new TitleScreen());
+ }
+ }
+ }
}
diff --git a/demos/returntomarchfeld/rtm-android/src/com/badlogic/rtm/Rtm.java b/demos/returntomarchfeld/rtm-android/src/com/badlogic/rtm/Rtm.java
index 9d33493d5e7..2e89d281a99 100644
--- a/demos/returntomarchfeld/rtm-android/src/com/badlogic/rtm/Rtm.java
+++ b/demos/returntomarchfeld/rtm-android/src/com/badlogic/rtm/Rtm.java
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
+
package com.badlogic.rtm;
import android.content.pm.ActivityInfo;
@@ -21,7 +22,8 @@
import com.badlogic.gdx.backends.android.AndroidApplication;
public class Rtm extends AndroidApplication {
- @Override public void onCreate (Bundle savedInstanceState) {
+ @Override
+ public void onCreate (Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
initialize(new LevelRenderer(), false);
diff --git a/demos/returntomarchfeld/rtm/src/com/badlogic/rtm/LevelRenderer.java b/demos/returntomarchfeld/rtm/src/com/badlogic/rtm/LevelRenderer.java
index cbd949f7216..7b8675469ee 100644
--- a/demos/returntomarchfeld/rtm/src/com/badlogic/rtm/LevelRenderer.java
+++ b/demos/returntomarchfeld/rtm/src/com/badlogic/rtm/LevelRenderer.java
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
+
package com.badlogic.rtm;
import java.io.BufferedReader;
@@ -46,10 +47,11 @@ public class LevelRenderer implements ApplicationListener {
ImmediateModeRenderer10 renderer;
float angle = -90;
- @Override public void create () {
+ @Override
+ public void create () {
camera = new PerspectiveCamera(67, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
camera.near = 1;
- camera.far = 2000;
+ camera.far = 2000;
batch = new SpriteBatch();
font = new BitmapFont();
@@ -180,17 +182,19 @@ private void load () {
}
}
- @Override public void resume () {
+ @Override
+ public void resume () {
}
- @Override public void render () {
+ @Override
+ public void render () {
GL10 gl = Gdx.gl10;
gl.glViewport(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
gl.glEnable(GL10.GL_DEPTH_TEST);
gl.glEnable(GL10.GL_TEXTURE_2D);
-
+
camera.update();
camera.apply(gl);
@@ -232,15 +236,18 @@ private void processInput () {
camera.direction.set((float)Math.cos(Math.toRadians(angle)), 0, (float)Math.sin(Math.toRadians(angle)));
}
- @Override public void resize (int width, int height) {
+ @Override
+ public void resize (int width, int height) {
}
- @Override public void pause () {
+ @Override
+ public void pause () {
}
- @Override public void dispose () {
+ @Override
+ public void dispose () {
}
}
diff --git a/demos/returntomarchfeld/rtm/src/com/badlogic/rtm/RtmDesktop.java b/demos/returntomarchfeld/rtm/src/com/badlogic/rtm/RtmDesktop.java
index 58caf4115db..7a24ed5accf 100644
--- a/demos/returntomarchfeld/rtm/src/com/badlogic/rtm/RtmDesktop.java
+++ b/demos/returntomarchfeld/rtm/src/com/badlogic/rtm/RtmDesktop.java
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
+
package com.badlogic.rtm;
import com.badlogic.gdx.backends.jogl.JoglApplication;
diff --git a/demos/superjumper/superjumper-android/src/com/badlogicgames/superjumper/SuperJumperAndroid.java b/demos/superjumper/superjumper-android/src/com/badlogicgames/superjumper/SuperJumperAndroid.java
index db3b8983174..00ee7ea4157 100644
--- a/demos/superjumper/superjumper-android/src/com/badlogicgames/superjumper/SuperJumperAndroid.java
+++ b/demos/superjumper/superjumper-android/src/com/badlogicgames/superjumper/SuperJumperAndroid.java
@@ -13,18 +13,18 @@
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
+
package com.badlogicgames.superjumper;
import android.os.Bundle;
import com.badlogic.gdx.backends.android.AndroidApplication;
-import com.badlogicgames.superjumper.SuperJumper;
public class SuperJumperAndroid extends AndroidApplication {
- /** Called when the activity is first created. */
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- initialize(new SuperJumper(), false);
- }
-}
\ No newline at end of file
+ /** Called when the activity is first created. */
+ @Override
+ public void onCreate (Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ initialize(new SuperJumper(), false);
+ }
+}
diff --git a/demos/superjumper/superjumper/src/com/badlogicgames/superjumper/Animation.java b/demos/superjumper/superjumper/src/com/badlogicgames/superjumper/Animation.java
index c802e911544..4985a588f9d 100644
--- a/demos/superjumper/superjumper/src/com/badlogicgames/superjumper/Animation.java
+++ b/demos/superjumper/superjumper/src/com/badlogicgames/superjumper/Animation.java
@@ -13,31 +13,31 @@
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
+
package com.badlogicgames.superjumper;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
-
public class Animation {
- public static final int ANIMATION_LOOPING = 0;
- public static final int ANIMATION_NONLOOPING = 1;
-
- final TextureRegion[] keyFrames;
- final float frameDuration;
-
- public Animation(float frameDuration, TextureRegion ... keyFrames) {
- this.frameDuration = frameDuration;
- this.keyFrames = keyFrames;
- }
-
- public TextureRegion getKeyFrame(float stateTime, int mode) {
- int frameNumber = (int)(stateTime / frameDuration);
-
- if(mode == ANIMATION_NONLOOPING) {
- frameNumber = Math.min(keyFrames.length-1, frameNumber);
- } else {
- frameNumber = frameNumber % keyFrames.length;
- }
- return keyFrames[frameNumber];
- }
+ public static final int ANIMATION_LOOPING = 0;
+ public static final int ANIMATION_NONLOOPING = 1;
+
+ final TextureRegion[] keyFrames;
+ final float frameDuration;
+
+ public Animation (float frameDuration, TextureRegion... keyFrames) {
+ this.frameDuration = frameDuration;
+ this.keyFrames = keyFrames;
+ }
+
+ public TextureRegion getKeyFrame (float stateTime, int mode) {
+ int frameNumber = (int)(stateTime / frameDuration);
+
+ if (mode == ANIMATION_NONLOOPING) {
+ frameNumber = Math.min(keyFrames.length - 1, frameNumber);
+ } else {
+ frameNumber = frameNumber % keyFrames.length;
+ }
+ return keyFrames[frameNumber];
+ }
}
diff --git a/demos/superjumper/superjumper/src/com/badlogicgames/superjumper/Assets.java b/demos/superjumper/superjumper/src/com/badlogicgames/superjumper/Assets.java
index 1cbb56c45a6..97c85299d81 100644
--- a/demos/superjumper/superjumper/src/com/badlogicgames/superjumper/Assets.java
+++ b/demos/superjumper/superjumper/src/com/badlogicgames/superjumper/Assets.java
@@ -13,110 +13,95 @@
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
+
package com.badlogicgames.superjumper;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.audio.Music;
import com.badlogic.gdx.audio.Sound;
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.g2d.BitmapFont;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
public class Assets {
- public static Texture background;
- public static TextureRegion backgroundRegion;
-
- public static Texture items;
- public static TextureRegion mainMenu;
- public static TextureRegion pauseMenu;
- public static TextureRegion ready;
- public static TextureRegion gameOver;
- public static TextureRegion highScoresRegion;
- public static TextureRegion logo;
- public static TextureRegion soundOn;
- public static TextureRegion soundOff;
- public static TextureRegion arrow;
- public static TextureRegion pause;
- public static TextureRegion spring;
- public static TextureRegion castle;
- public static Animation coinAnim;
- public static Animation bobJump;
- public static Animation bobFall;
- public static TextureRegion bobHit;
- public static Animation squirrelFly;
- public static TextureRegion platform;
- public static Animation brakingPlatform;
- public static BitmapFont font;
-
- public static Music music;
- public static Sound jumpSound;
- public static Sound highJumpSound;
- public static Sound hitSound;
- public static Sound coinSound;
- public static Sound clickSound;
-
- public static Texture loadTexture(String file) {
- return new Texture(Gdx.files.internal(file));
- }
-
- public static void load() {
- background = loadTexture("data/background.png");
- backgroundRegion = new TextureRegion(background, 0, 0, 320, 480);
-
- items = loadTexture("data/items.png");
- mainMenu = new TextureRegion(items, 0, 224, 300, 110);
- pauseMenu = new TextureRegion(items, 224, 128, 192, 96);
- ready = new TextureRegion(items, 320, 224, 192, 32);
- gameOver = new TextureRegion(items, 352, 256, 160, 96);
- highScoresRegion = new TextureRegion(Assets.items, 0, 257, 300, 110 / 3);
- logo = new TextureRegion(items, 0, 352, 274, 142);
- soundOff = new TextureRegion(items, 0, 0, 64, 64);
- soundOn = new TextureRegion(items, 64, 0, 64, 64);
- arrow = new TextureRegion(items, 0, 64, 64, 64);
- pause = new TextureRegion(items, 64, 64, 64, 64);
-
- spring = new TextureRegion(items, 128, 0, 32, 32);
- castle = new TextureRegion(items, 128, 64, 64, 64);
- coinAnim = new Animation(0.2f,
- new TextureRegion(items, 128, 32, 32, 32),
- new TextureRegion(items, 160, 32, 32, 32),
- new TextureRegion(items, 192, 32, 32, 32),
- new TextureRegion(items, 160, 32, 32, 32));
- bobJump = new Animation(0.2f,
- new TextureRegion(items, 0, 128, 32, 32),
- new TextureRegion(items, 32, 128, 32, 32));
- bobFall = new Animation(0.2f,
- new TextureRegion(items, 64, 128, 32, 32),
- new TextureRegion(items, 96, 128, 32, 32));
- bobHit = new TextureRegion(items, 128, 128, 32, 32);
- squirrelFly = new Animation(0.2f,
- new TextureRegion(items, 0, 160, 32, 32),
- new TextureRegion(items, 32, 160, 32, 32));
- platform = new TextureRegion(items, 64, 160, 64, 16);
- brakingPlatform = new Animation(0.2f,
- new TextureRegion(items, 64, 160, 64, 16),
- new TextureRegion(items, 64, 176, 64, 16),
- new TextureRegion(items, 64, 192, 64, 16),
- new TextureRegion(items, 64, 208, 64, 16));
-
- font = new BitmapFont(Gdx.files.internal("data/font.fnt"), Gdx.files.internal("data/font.png"), false);
-
- music = Gdx.audio.newMusic(Gdx.files.internal("data/music.mp3"));
- music.setLooping(true);
- music.setVolume(0.5f);
- if(Settings.soundEnabled)
- music.play();
- jumpSound = Gdx.audio.newSound(Gdx.files.internal("data/jump.ogg"));
- highJumpSound = Gdx.audio.newSound(Gdx.files.internal("data/highjump.ogg"));
- hitSound = Gdx.audio.newSound(Gdx.files.internal("data/hit.ogg"));
- coinSound = Gdx.audio.newSound(Gdx.files.internal("data/coin.ogg"));
- clickSound = Gdx.audio.newSound(Gdx.files.internal("data/click.ogg"));
- }
-
- public static void playSound(Sound sound) {
- if(Settings.soundEnabled)
- sound.play(1);
- }
+ public static Texture background;
+ public static TextureRegion backgroundRegion;
+
+ public static Texture items;
+ public static TextureRegion mainMenu;
+ public static TextureRegion pauseMenu;
+ public static TextureRegion ready;
+ public static TextureRegion gameOver;
+ public static TextureRegion highScoresRegion;
+ public static TextureRegion logo;
+ public static TextureRegion soundOn;
+ public static TextureRegion soundOff;
+ public static TextureRegion arrow;
+ public static TextureRegion pause;
+ public static TextureRegion spring;
+ public static TextureRegion castle;
+ public static Animation coinAnim;
+ public static Animation bobJump;
+ public static Animation bobFall;
+ public static TextureRegion bobHit;
+ public static Animation squirrelFly;
+ public static TextureRegion platform;
+ public static Animation brakingPlatform;
+ public static BitmapFont font;
+
+ public static Music music;
+ public static Sound jumpSound;
+ public static Sound highJumpSound;
+ public static Sound hitSound;
+ public static Sound coinSound;
+ public static Sound clickSound;
+
+ public static Texture loadTexture (String file) {
+ return new Texture(Gdx.files.internal(file));
+ }
+
+ public static void load () {
+ background = loadTexture("data/background.png");
+ backgroundRegion = new TextureRegion(background, 0, 0, 320, 480);
+
+ items = loadTexture("data/items.png");
+ mainMenu = new TextureRegion(items, 0, 224, 300, 110);
+ pauseMenu = new TextureRegion(items, 224, 128, 192, 96);
+ ready = new TextureRegion(items, 320, 224, 192, 32);
+ gameOver = new TextureRegion(items, 352, 256, 160, 96);
+ highScoresRegion = new TextureRegion(Assets.items, 0, 257, 300, 110 / 3);
+ logo = new TextureRegion(items, 0, 352, 274, 142);
+ soundOff = new TextureRegion(items, 0, 0, 64, 64);
+ soundOn = new TextureRegion(items, 64, 0, 64, 64);
+ arrow = new TextureRegion(items, 0, 64, 64, 64);
+ pause = new TextureRegion(items, 64, 64, 64, 64);
+
+ spring = new TextureRegion(items, 128, 0, 32, 32);
+ castle = new TextureRegion(items, 128, 64, 64, 64);
+ coinAnim = new Animation(0.2f, new TextureRegion(items, 128, 32, 32, 32), new TextureRegion(items, 160, 32, 32, 32),
+ new TextureRegion(items, 192, 32, 32, 32), new TextureRegion(items, 160, 32, 32, 32));
+ bobJump = new Animation(0.2f, new TextureRegion(items, 0, 128, 32, 32), new TextureRegion(items, 32, 128, 32, 32));
+ bobFall = new Animation(0.2f, new TextureRegion(items, 64, 128, 32, 32), new TextureRegion(items, 96, 128, 32, 32));
+ bobHit = new TextureRegion(items, 128, 128, 32, 32);
+ squirrelFly = new Animation(0.2f, new TextureRegion(items, 0, 160, 32, 32), new TextureRegion(items, 32, 160, 32, 32));
+ platform = new TextureRegion(items, 64, 160, 64, 16);
+ brakingPlatform = new Animation(0.2f, new TextureRegion(items, 64, 160, 64, 16), new TextureRegion(items, 64, 176, 64, 16),
+ new TextureRegion(items, 64, 192, 64, 16), new TextureRegion(items, 64, 208, 64, 16));
+
+ font = new BitmapFont(Gdx.files.internal("data/font.fnt"), Gdx.files.internal("data/font.png"), false);
+
+ music = Gdx.audio.newMusic(Gdx.files.internal("data/music.mp3"));
+ music.setLooping(true);
+ music.setVolume(0.5f);
+ if (Settings.soundEnabled) music.play();
+ jumpSound = Gdx.audio.newSound(Gdx.files.internal("data/jump.ogg"));
+ highJumpSound = Gdx.audio.newSound(Gdx.files.internal("data/highjump.ogg"));
+ hitSound = Gdx.audio.newSound(Gdx.files.internal("data/hit.ogg"));
+ coinSound = Gdx.audio.newSound(Gdx.files.internal("data/coin.ogg"));
+ clickSound = Gdx.audio.newSound(Gdx.files.internal("data/click.ogg"));
+ }
+
+ public static void playSound (Sound sound) {
+ if (Settings.soundEnabled) sound.play(1);
+ }
}
diff --git a/demos/superjumper/superjumper/src/com/badlogicgames/superjumper/Bob.java b/demos/superjumper/superjumper/src/com/badlogicgames/superjumper/Bob.java
index 48aa7e459da..e3782a843d9 100644
--- a/demos/superjumper/superjumper/src/com/badlogicgames/superjumper/Bob.java
+++ b/demos/superjumper/superjumper/src/com/badlogicgames/superjumper/Bob.java
@@ -13,69 +13,68 @@
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
+
package com.badlogicgames.superjumper;
-public class Bob extends DynamicGameObject{
- public static final int BOB_STATE_JUMP = 0;
- public static final int BOB_STATE_FALL = 1;
- public static final int BOB_STATE_HIT = 2;
- public static final float BOB_JUMP_VELOCITY = 11;
- public static final float BOB_MOVE_VELOCITY = 20;
- public static final float BOB_WIDTH = 0.8f;
- public static final float BOB_HEIGHT = 0.8f;
-
- int state;
- float stateTime;
+public class Bob extends DynamicGameObject {
+ public static final int BOB_STATE_JUMP = 0;
+ public static final int BOB_STATE_FALL = 1;
+ public static final int BOB_STATE_HIT = 2;
+ public static final float BOB_JUMP_VELOCITY = 11;
+ public static final float BOB_MOVE_VELOCITY = 20;
+ public static final float BOB_WIDTH = 0.8f;
+ public static final float BOB_HEIGHT = 0.8f;
+
+ int state;
+ float stateTime;
+
+ public Bob (float x, float y) {
+ super(x, y, BOB_WIDTH, BOB_HEIGHT);
+ state = BOB_STATE_FALL;
+ stateTime = 0;
+ }
+
+ public void update (float deltaTime) {
+ velocity.add(World.gravity.x * deltaTime, World.gravity.y * deltaTime);
+ position.add(velocity.x * deltaTime, velocity.y * deltaTime);
+ bounds.x = position.x - bounds.width / 2;
+ bounds.y = position.y - bounds.height / 2;
+
+ if (velocity.y > 0 && state != BOB_STATE_HIT) {
+ if (state != BOB_STATE_JUMP) {
+ state = BOB_STATE_JUMP;
+ stateTime = 0;
+ }
+ }
+
+ if (velocity.y < 0 && state != BOB_STATE_HIT) {
+ if (state != BOB_STATE_FALL) {
+ state = BOB_STATE_FALL;
+ stateTime = 0;
+ }
+ }
+
+ if (position.x < 0) position.x = World.WORLD_WIDTH;
+ if (position.x > World.WORLD_WIDTH) position.x = 0;
+
+ stateTime += deltaTime;
+ }
- public Bob(float x, float y) {
- super(x, y, BOB_WIDTH, BOB_HEIGHT);
- state = BOB_STATE_FALL;
- stateTime = 0;
- }
+ public void hitSquirrel () {
+ velocity.set(0, 0);
+ state = BOB_STATE_HIT;
+ stateTime = 0;
+ }
- public void update(float deltaTime) {
- velocity.add(World.gravity.x * deltaTime, World.gravity.y * deltaTime);
- position.add(velocity.x * deltaTime, velocity.y * deltaTime);
- bounds.x = position.x - bounds.width / 2;
- bounds.y = position.y - bounds.height / 2;
-
- if(velocity.y > 0 && state != BOB_STATE_HIT) {
- if(state != BOB_STATE_JUMP) {
- state = BOB_STATE_JUMP;
- stateTime = 0;
- }
- }
-
- if(velocity.y < 0 && state != BOB_STATE_HIT) {
- if(state != BOB_STATE_FALL) {
- state = BOB_STATE_FALL;
- stateTime = 0;
- }
- }
-
- if(position.x < 0)
- position.x = World.WORLD_WIDTH;
- if(position.x > World.WORLD_WIDTH)
- position.x = 0;
-
- stateTime += deltaTime;
- }
-
- public void hitSquirrel() {
- velocity.set(0,0);
- state = BOB_STATE_HIT;
- stateTime = 0;
- }
-
- public void hitPlatform() {
- velocity.y = BOB_JUMP_VELOCITY;
- state = BOB_STATE_JUMP;
- stateTime = 0;
- }
+ public void hitPlatform () {
+ velocity.y = BOB_JUMP_VELOCITY;
+ state = BOB_STATE_JUMP;
+ stateTime = 0;
+ }
- public void hitSpring() {
- velocity.y = BOB_JUMP_VELOCITY * 1.5f;
- state = BOB_STATE_JUMP;
- stateTime = 0;
- }
+ public void hitSpring () {
+ velocity.y = BOB_JUMP_VELOCITY * 1.5f;
+ state = BOB_STATE_JUMP;
+ stateTime = 0;
+ }
}
diff --git a/demos/superjumper/superjumper/src/com/badlogicgames/superjumper/Castle.java b/demos/superjumper/superjumper/src/com/badlogicgames/superjumper/Castle.java
index b72f39a96e3..0d262abafc5 100644
--- a/demos/superjumper/superjumper/src/com/badlogicgames/superjumper/Castle.java
+++ b/demos/superjumper/superjumper/src/com/badlogicgames/superjumper/Castle.java
@@ -13,15 +13,15 @@
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
-package com.badlogicgames.superjumper;
+package com.badlogicgames.superjumper;
public class Castle extends GameObject {
- public static float CASTLE_WIDTH = 1.7f;
- public static float CASTLE_HEIGHT = 1.7f;
+ public static float CASTLE_WIDTH = 1.7f;
+ public static float CASTLE_HEIGHT = 1.7f;
- public Castle(float x, float y) {
- super(x, y, CASTLE_WIDTH, CASTLE_HEIGHT);
- }
+ public Castle (float x, float y) {
+ super(x, y, CASTLE_WIDTH, CASTLE_HEIGHT);
+ }
}
diff --git a/demos/superjumper/superjumper/src/com/badlogicgames/superjumper/Coin.java b/demos/superjumper/superjumper/src/com/badlogicgames/superjumper/Coin.java
index 88722b9e0c9..e67aa3a6f0d 100644
--- a/demos/superjumper/superjumper/src/com/badlogicgames/superjumper/Coin.java
+++ b/demos/superjumper/superjumper/src/com/badlogicgames/superjumper/Coin.java
@@ -13,21 +13,22 @@
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
-package com.badlogicgames.superjumper;
+package com.badlogicgames.superjumper;
public class Coin extends GameObject {
- public static final float COIN_WIDTH = 0.5f;
- public static final float COIN_HEIGHT = 0.8f;
- public static final int COIN_SCORE = 10;
+ public static final float COIN_WIDTH = 0.5f;
+ public static final float COIN_HEIGHT = 0.8f;
+ public static final int COIN_SCORE = 10;
+
+ float stateTime;
+
+ public Coin (float x, float y) {
+ super(x, y, COIN_WIDTH, COIN_HEIGHT);
+ stateTime = 0;
+ }
- float stateTime;
- public Coin(float x, float y) {
- super(x, y, COIN_WIDTH, COIN_HEIGHT);
- stateTime = 0;
- }
-
- public void update(float deltaTime) {
- stateTime += deltaTime;
- }
+ public void update (float deltaTime) {
+ stateTime += deltaTime;
+ }
}
diff --git a/demos/superjumper/superjumper/src/com/badlogicgames/superjumper/DynamicGameObject.java b/demos/superjumper/superjumper/src/com/badlogicgames/superjumper/DynamicGameObject.java
index 8a39b68bc7a..152e1bcadf8 100644
--- a/demos/superjumper/superjumper/src/com/badlogicgames/superjumper/DynamicGameObject.java
+++ b/demos/superjumper/superjumper/src/com/badlogicgames/superjumper/DynamicGameObject.java
@@ -13,17 +13,18 @@
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
+
package com.badlogicgames.superjumper;
import com.badlogic.gdx.math.Vector2;
public class DynamicGameObject extends GameObject {
- public final Vector2 velocity;
- public final Vector2 accel;
-
- public DynamicGameObject(float x, float y, float width, float height) {
- super(x, y, width, height);
- velocity = new Vector2();
- accel = new Vector2();
- }
+ public final Vector2 velocity;
+ public final Vector2 accel;
+
+ public DynamicGameObject (float x, float y, float width, float height) {
+ super(x, y, width, height);
+ velocity = new Vector2();
+ accel = new Vector2();
+ }
}
diff --git a/demos/superjumper/superjumper/src/com/badlogicgames/superjumper/Game.java b/demos/superjumper/superjumper/src/com/badlogicgames/superjumper/Game.java
index 4975e1a9bf0..c01b89700f4 100644
--- a/demos/superjumper/superjumper/src/com/badlogicgames/superjumper/Game.java
+++ b/demos/superjumper/superjumper/src/com/badlogicgames/superjumper/Game.java
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
+
package com.badlogicgames.superjumper;
import com.badlogic.gdx.ApplicationListener;
@@ -20,37 +21,43 @@
public abstract class Game implements ApplicationListener {
Screen screen;
-
+
public void setScreen (Screen helpScreen2) {
screen.pause();
screen.dispose();
screen = helpScreen2;
}
-
- public abstract Screen getStartScreen();
-
- @Override public void create () {
+
+ public abstract Screen getStartScreen ();
+
+ @Override
+ public void create () {
screen = getStartScreen();
}
- @Override public void resume () {
+ @Override
+ public void resume () {
screen.resume();
}
- @Override public void render () {
+ @Override
+ public void render () {
screen.update(Gdx.graphics.getDeltaTime());
screen.present(Gdx.graphics.getDeltaTime());
}
- @Override public void resize (int width, int height) {
-
+ @Override
+ public void resize (int width, int height) {
+
}
- @Override public void pause () {
+ @Override
+ public void pause () {
screen.pause();
}
- @Override public void dispose () {
+ @Override
+ public void dispose () {
screen.dispose();
}
}
diff --git a/demos/superjumper/superjumper/src/com/badlogicgames/superjumper/GameObject.java b/demos/superjumper/superjumper/src/com/badlogicgames/superjumper/GameObject.java
index a5226620bd7..f0e31702907 100644
--- a/demos/superjumper/superjumper/src/com/badlogicgames/superjumper/GameObject.java
+++ b/demos/superjumper/superjumper/src/com/badlogicgames/superjumper/GameObject.java
@@ -13,17 +13,18 @@
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
+
package com.badlogicgames.superjumper;
import com.badlogic.gdx.math.Rectangle;
import com.badlogic.gdx.math.Vector2;
public class GameObject {
- public final Vector2 position;
- public final Rectangle bounds;
-
- public GameObject(float x, float y, float width, float height) {
- this.position = new Vector2(x,y);
- this.bounds = new Rectangle(x-width/2, y-height/2, width, height);
- }
+ public final Vector2 position;
+ public final Rectangle bounds;
+
+ public GameObject (float x, float y, float width, float height) {
+ this.position = new Vector2(x, y);
+ this.bounds = new Rectangle(x - width / 2, y - height / 2, width, height);
+ }
}
diff --git a/demos/superjumper/superjumper/src/com/badlogicgames/superjumper/GameScreen.java b/demos/superjumper/superjumper/src/com/badlogicgames/superjumper/GameScreen.java
index 6316cac80fd..25e7309319f 100644
--- a/demos/superjumper/superjumper/src/com/badlogicgames/superjumper/GameScreen.java
+++ b/demos/superjumper/superjumper/src/com/badlogicgames/superjumper/GameScreen.java
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
+
package com.badlogicgames.superjumper;
import com.badlogic.gdx.Application;
@@ -49,24 +50,28 @@ public class GameScreen extends Screen {
public GameScreen (Game game) {
super(game);
state = GAME_READY;
- guiCam = new OrthographicCamera(320, 480);
+ guiCam = new OrthographicCamera(320, 480);
guiCam.position.set(320 / 2, 480 / 2, 0);
touchPoint = new Vector3();
batcher = new SpriteBatch();
worldListener = new WorldListener() {
- @Override public void jump () {
+ @Override
+ public void jump () {
Assets.playSound(Assets.jumpSound);
}
- @Override public void highJump () {
+ @Override
+ public void highJump () {
Assets.playSound(Assets.highJumpSound);
}
- @Override public void hit () {
+ @Override
+ public void hit () {
Assets.playSound(Assets.hitSound);
}
- @Override public void coin () {
+ @Override
+ public void coin () {
Assets.playSound(Assets.coinSound);
}
};
@@ -79,7 +84,8 @@ public GameScreen (Game game) {
scoreString = "SCORE: 0";
}
- @Override public void update (float deltaTime) {
+ @Override
+ public void update (float deltaTime) {
if (deltaTime > 0.1f) deltaTime = 0.1f;
switch (state) {
@@ -109,7 +115,7 @@ private void updateReady () {
private void updateRunning (float deltaTime) {
if (Gdx.input.justTouched()) {
- guiCam.unproject(touchPoint.set(Gdx.input.getX(), Gdx.input.getY(), 0));
+ guiCam.unproject(touchPoint.set(Gdx.input.getX(), Gdx.input.getY(), 0));
if (OverlapTester.pointInRectangle(pauseBounds, touchPoint.x, touchPoint.y)) {
Assets.playSound(Assets.clickSound);
@@ -118,15 +124,12 @@ private void updateRunning (float deltaTime) {
}
}
- if(Gdx.app.getType() == Application.ApplicationType.Android) {
+ if (Gdx.app.getType() == Application.ApplicationType.Android) {
world.update(deltaTime, Gdx.input.getAccelerometerX());
- }
- else {
+ } else {
float accel = 0;
- if(Gdx.input.isKeyPressed(Keys.DPAD_LEFT))
- accel = 5f;
- if(Gdx.input.isKeyPressed(Keys.DPAD_RIGHT))
- accel = -5f;
+ if (Gdx.input.isKeyPressed(Keys.DPAD_LEFT)) accel = 5f;
+ if (Gdx.input.isKeyPressed(Keys.DPAD_RIGHT)) accel = -5f;
world.update(deltaTime, accel);
}
if (world.score != lastScore) {
@@ -167,7 +170,7 @@ private void updatePaused () {
}
private void updateLevelEnd () {
- if(Gdx.input.justTouched()) {
+ if (Gdx.input.justTouched()) {
world = new World(worldListener);
renderer = new WorldRenderer(batcher, world);
world.score = lastScore;
@@ -176,12 +179,13 @@ private void updateLevelEnd () {
}
private void updateGameOver () {
- if(Gdx.input.justTouched()) {
+ if (Gdx.input.justTouched()) {
game.setScreen(new MainMenuScreen(game));
}
}
- @Override public void present (float deltaTime) {
+ @Override
+ public void present (float deltaTime) {
GLCommon gl = Gdx.gl;
gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
gl.glEnable(GL10.GL_TEXTURE_2D);
@@ -189,9 +193,9 @@ private void updateGameOver () {
renderer.render();
guiCam.update();
- batcher.setProjectionMatrix(guiCam.combined);
+ batcher.setProjectionMatrix(guiCam.combined);
batcher.enableBlending();
- batcher.begin();
+ batcher.begin();
switch (state) {
case GAME_READY:
presentReady();
@@ -209,7 +213,7 @@ private void updateGameOver () {
presentGameOver();
break;
}
- batcher.end();
+ batcher.end();
}
private void presentReady () {
@@ -222,7 +226,7 @@ private void presentRunning () {
}
private void presentPaused () {
- batcher.draw( Assets.pauseMenu, 160 - 192 / 2, 240 - 96 / 2, 192, 96);
+ batcher.draw(Assets.pauseMenu, 160 - 192 / 2, 240 - 96 / 2, 192, 96);
Assets.font.draw(batcher, scoreString, 16, 480 - 20);
}
@@ -241,13 +245,16 @@ private void presentGameOver () {
Assets.font.draw(batcher, scoreString, 160 - scoreWidth / 2, 480 - 20);
}
- @Override public void pause () {
+ @Override
+ public void pause () {
if (state == GAME_RUNNING) state = GAME_PAUSED;
}
- @Override public void resume () {
+ @Override
+ public void resume () {
}
- @Override public void dispose () {
+ @Override
+ public void dispose () {
}
}
diff --git a/demos/superjumper/superjumper/src/com/badlogicgames/superjumper/HelpScreen.java b/demos/superjumper/superjumper/src/com/badlogicgames/superjumper/HelpScreen.java
index 27776b6c07e..a9cb16cb1a7 100644
--- a/demos/superjumper/superjumper/src/com/badlogicgames/superjumper/HelpScreen.java
+++ b/demos/superjumper/superjumper/src/com/badlogicgames/superjumper/HelpScreen.java
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
+
package com.badlogicgames.superjumper;
import com.badlogic.gdx.Gdx;
@@ -26,70 +27,70 @@
import com.badlogic.gdx.math.Vector3;
public class HelpScreen extends Screen {
- OrthographicCamera guiCam;
- SpriteBatch batcher;
- Rectangle nextBounds;
- Vector3 touchPoint;
- Texture helpImage;
- TextureRegion helpRegion;
-
- public HelpScreen(Game game) {
- super(game);
-
- guiCam = new OrthographicCamera(320, 480);
- guiCam.position.set(320 / 2, 480 / 2, 0);
- nextBounds = new Rectangle(320 - 64, 0, 64, 64);
- touchPoint = new Vector3();
- batcher = new SpriteBatch();
- helpImage = Assets.loadTexture("data/help1.png" );
- helpRegion = new TextureRegion(helpImage, 0, 0, 320, 480);
- }
-
- @Override
- public void resume() {
- }
-
- @Override
- public void pause() {
- helpImage.dispose();
- }
+ OrthographicCamera guiCam;
+ SpriteBatch batcher;
+ Rectangle nextBounds;
+ Vector3 touchPoint;
+ Texture helpImage;
+ TextureRegion helpRegion;
+
+ public HelpScreen (Game game) {
+ super(game);
+
+ guiCam = new OrthographicCamera(320, 480);
+ guiCam.position.set(320 / 2, 480 / 2, 0);
+ nextBounds = new Rectangle(320 - 64, 0, 64, 64);
+ touchPoint = new Vector3();
+ batcher = new SpriteBatch();
+ helpImage = Assets.loadTexture("data/help1.png");
+ helpRegion = new TextureRegion(helpImage, 0, 0, 320, 480);
+ }
+
+ @Override
+ public void resume () {
+ }
+
+ @Override
+ public void pause () {
+ helpImage.dispose();
+ }
+
+ @Override
+ public void update (float deltaTime) {
+ if (Gdx.input.justTouched()) {
+ guiCam.unproject(touchPoint.set(Gdx.input.getX(), Gdx.input.getY(), 0));
+
+ if (OverlapTester.pointInRectangle(nextBounds, touchPoint.x, touchPoint.y)) {
+ Assets.playSound(Assets.clickSound);
+ game.setScreen(new HelpScreen2(game));
+ return;
+ }
+ }
+ }
+
+ @Override
+ public void present (float deltaTime) {
+ GLCommon gl = Gdx.gl;
+ gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
+ guiCam.update();
+ guiCam.apply(Gdx.gl10);
+
+ gl.glEnable(GL10.GL_TEXTURE_2D);
+
+ batcher.disableBlending();
+ batcher.begin();
+ batcher.draw(helpRegion, 0, 0, 320, 480);
+ batcher.end();
- @Override
- public void update(float deltaTime) {
- if(Gdx.input.justTouched()) {
- guiCam.unproject(touchPoint.set(Gdx.input.getX(), Gdx.input.getY(), 0));
-
- if(OverlapTester.pointInRectangle(nextBounds, touchPoint.x, touchPoint.y)) {
- Assets.playSound(Assets.clickSound);
- game.setScreen(new HelpScreen2(game));
- return;
- }
- }
- }
+ batcher.enableBlending();
+ batcher.begin();
+ batcher.draw(Assets.arrow, 320, 0, -64, 64);
+ batcher.end();
- @Override
- public void present(float deltaTime) {
- GLCommon gl = Gdx.gl;
- gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
- guiCam.update();
- guiCam.apply(Gdx.gl10);
-
- gl.glEnable(GL10.GL_TEXTURE_2D);
-
- batcher.disableBlending();
- batcher.begin();
- batcher.draw(helpRegion, 0, 0, 320, 480);
- batcher.end();
-
- batcher.enableBlending();
- batcher.begin();
- batcher.draw(Assets.arrow, 320, 0, -64, 64);
- batcher.end();
-
- gl.glDisable(GL10.GL_BLEND);
- }
+ gl.glDisable(GL10.GL_BLEND);
+ }
- @Override
- public void dispose() {
- }
+ @Override
+ public void dispose () {
+ }
}
diff --git a/demos/superjumper/superjumper/src/com/badlogicgames/superjumper/HelpScreen2.java b/demos/superjumper/superjumper/src/com/badlogicgames/superjumper/HelpScreen2.java
index 3c4c4e11f83..ff5cf1669a2 100644
--- a/demos/superjumper/superjumper/src/com/badlogicgames/superjumper/HelpScreen2.java
+++ b/demos/superjumper/superjumper/src/com/badlogicgames/superjumper/HelpScreen2.java
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
+
package com.badlogicgames.superjumper;
import com.badlogic.gdx.Gdx;
@@ -27,70 +28,69 @@
public class HelpScreen2 extends Screen {
OrthographicCamera guiCam;
- SpriteBatch batcher;
- Rectangle nextBounds;
- Vector3 touchPoint;
- Texture helpImage;
- TextureRegion helpRegion;
-
- public HelpScreen2(Game game) {
- super(game);
-
- guiCam = new OrthographicCamera(320, 480);
- guiCam.position.set(320 / 2, 480 / 2, 0);
- nextBounds = new Rectangle(320 - 64, 0, 64, 64);
- touchPoint = new Vector3();
- batcher = new SpriteBatch();
- helpImage = Assets.loadTexture("data/help2.png" );
- helpRegion = new TextureRegion(helpImage, 0, 0, 320, 480);
- }
-
- @Override
- public void resume() {
- }
-
- @Override
- public void pause() {
- helpImage.dispose();
- }
+ SpriteBatch batcher;
+ Rectangle nextBounds;
+ Vector3 touchPoint;
+ Texture helpImage;
+ TextureRegion helpRegion;
- @Override
- public void update(float deltaTime) {
- if(Gdx.input.justTouched()) {
- guiCam.unproject(touchPoint.set(Gdx.input.getX(), Gdx.input.getY(), 0));
-
- if(OverlapTester.pointInRectangle(nextBounds, touchPoint.x, touchPoint.y)) {
- Assets.playSound(Assets.clickSound);
- game.setScreen(new HelpScreen3(game));
- return;
- }
- }
- }
+ public HelpScreen2 (Game game) {
+ super(game);
- @Override
- public void present(float deltaTime) {
- GLCommon gl = Gdx.gl;
- gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
- guiCam.update();
- guiCam.apply(Gdx.gl10);
-
- gl.glEnable(GL10.GL_TEXTURE_2D);
-
- batcher.disableBlending();
- batcher.begin();
- batcher.draw(helpRegion, 0, 0, 320, 480);
- batcher.end();
-
- batcher.enableBlending();
- batcher.begin();
- batcher.draw(Assets.arrow, 320, 0, -64, 64);
- batcher.end();
-
- gl.glDisable(GL10.GL_BLEND);
- }
+ guiCam = new OrthographicCamera(320, 480);
+ guiCam.position.set(320 / 2, 480 / 2, 0);
+ nextBounds = new Rectangle(320 - 64, 0, 64, 64);
+ touchPoint = new Vector3();
+ batcher = new SpriteBatch();
+ helpImage = Assets.loadTexture("data/help2.png");
+ helpRegion = new TextureRegion(helpImage, 0, 0, 320, 480);
+ }
- @Override
- public void dispose() {
- }
-}
+ @Override
+ public void resume () {
+ }
+
+ @Override
+ public void pause () {
+ helpImage.dispose();
+ }
+
+ @Override
+ public void update (float deltaTime) {
+ if (Gdx.input.justTouched()) {
+ guiCam.unproject(touchPoint.set(Gdx.input.getX(), Gdx.input.getY(), 0));
+
+ if (OverlapTester.pointInRectangle(nextBounds, touchPoint.x, touchPoint.y)) {
+ Assets.playSound(Assets.clickSound);
+ game.setScreen(new HelpScreen3(game));
+ return;
+ }
+ }
+ }
+
+ @Override
+ public void present (float deltaTime) {
+ GLCommon gl = Gdx.gl;
+ gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
+ guiCam.update();
+ guiCam.apply(Gdx.gl10);
+ gl.glEnable(GL10.GL_TEXTURE_2D);
+
+ batcher.disableBlending();
+ batcher.begin();
+ batcher.draw(helpRegion, 0, 0, 320, 480);
+ batcher.end();
+
+ batcher.enableBlending();
+ batcher.begin();
+ batcher.draw(Assets.arrow, 320, 0, -64, 64);
+ batcher.end();
+
+ gl.glDisable(GL10.GL_BLEND);
+ }
+
+ @Override
+ public void dispose () {
+ }
+}
diff --git a/demos/superjumper/superjumper/src/com/badlogicgames/superjumper/HelpScreen3.java b/demos/superjumper/superjumper/src/com/badlogicgames/superjumper/HelpScreen3.java
index 1d461bc74de..07a689a1a1b 100644
--- a/demos/superjumper/superjumper/src/com/badlogicgames/superjumper/HelpScreen3.java
+++ b/demos/superjumper/superjumper/src/com/badlogicgames/superjumper/HelpScreen3.java
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
+
package com.badlogicgames.superjumper;
import com.badlogic.gdx.Gdx;
@@ -27,70 +28,69 @@
public class HelpScreen3 extends Screen {
OrthographicCamera guiCam;
- SpriteBatch batcher;
- Rectangle nextBounds;
- Vector3 touchPoint;
- Texture helpImage;
- TextureRegion helpRegion;
-
- public HelpScreen3(Game game) {
- super(game);
-
- guiCam = new OrthographicCamera(320, 480);
- guiCam.position.set(320 / 2, 480 / 2, 0);
- nextBounds = new Rectangle(320 - 64, 0, 64, 64);
- touchPoint = new Vector3();
- batcher = new SpriteBatch();
- helpImage = Assets.loadTexture("data/help3.png" );
- helpRegion = new TextureRegion(helpImage, 0, 0, 320, 480);
- }
-
- @Override
- public void resume() {
- }
-
- @Override
- public void pause() {
- helpImage.dispose();
- }
+ SpriteBatch batcher;
+ Rectangle nextBounds;
+ Vector3 touchPoint;
+ Texture helpImage;
+ TextureRegion helpRegion;
- @Override
- public void update(float deltaTime) {
- if(Gdx.input.justTouched()) {
- guiCam.unproject(touchPoint.set(Gdx.input.getX(), Gdx.input.getY(), 0));
-
- if(OverlapTester.pointInRectangle(nextBounds, touchPoint.x, touchPoint.y)) {
- Assets.playSound(Assets.clickSound);
- game.setScreen(new HelpScreen4(game));
- return;
- }
- }
- }
+ public HelpScreen3 (Game game) {
+ super(game);
- @Override
- public void present(float deltaTime) {
- GLCommon gl = Gdx.gl;
- gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
- guiCam.update();
- guiCam.apply(Gdx.gl10);
-
- gl.glEnable(GL10.GL_TEXTURE_2D);
-
- batcher.disableBlending();
- batcher.begin();
- batcher.draw(helpRegion, 0, 0, 320, 480);
- batcher.end();
-
- batcher.enableBlending();
- batcher.begin();
- batcher.draw(Assets.arrow, 320, 0, -64, 64);
- batcher.end();
-
- gl.glDisable(GL10.GL_BLEND);
- }
+ guiCam = new OrthographicCamera(320, 480);
+ guiCam.position.set(320 / 2, 480 / 2, 0);
+ nextBounds = new Rectangle(320 - 64, 0, 64, 64);
+ touchPoint = new Vector3();
+ batcher = new SpriteBatch();
+ helpImage = Assets.loadTexture("data/help3.png");
+ helpRegion = new TextureRegion(helpImage, 0, 0, 320, 480);
+ }
- @Override
- public void dispose() {
- }
-}
+ @Override
+ public void resume () {
+ }
+
+ @Override
+ public void pause () {
+ helpImage.dispose();
+ }
+
+ @Override
+ public void update (float deltaTime) {
+ if (Gdx.input.justTouched()) {
+ guiCam.unproject(touchPoint.set(Gdx.input.getX(), Gdx.input.getY(), 0));
+
+ if (OverlapTester.pointInRectangle(nextBounds, touchPoint.x, touchPoint.y)) {
+ Assets.playSound(Assets.clickSound);
+ game.setScreen(new HelpScreen4(game));
+ return;
+ }
+ }
+ }
+
+ @Override
+ public void present (float deltaTime) {
+ GLCommon gl = Gdx.gl;
+ gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
+ guiCam.update();
+ guiCam.apply(Gdx.gl10);
+ gl.glEnable(GL10.GL_TEXTURE_2D);
+
+ batcher.disableBlending();
+ batcher.begin();
+ batcher.draw(helpRegion, 0, 0, 320, 480);
+ batcher.end();
+
+ batcher.enableBlending();
+ batcher.begin();
+ batcher.draw(Assets.arrow, 320, 0, -64, 64);
+ batcher.end();
+
+ gl.glDisable(GL10.GL_BLEND);
+ }
+
+ @Override
+ public void dispose () {
+ }
+}
diff --git a/demos/superjumper/superjumper/src/com/badlogicgames/superjumper/HelpScreen4.java b/demos/superjumper/superjumper/src/com/badlogicgames/superjumper/HelpScreen4.java
index 4b396d0eb9e..f1ed03f697c 100644
--- a/demos/superjumper/superjumper/src/com/badlogicgames/superjumper/HelpScreen4.java
+++ b/demos/superjumper/superjumper/src/com/badlogicgames/superjumper/HelpScreen4.java
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
+
package com.badlogicgames.superjumper;
import com.badlogic.gdx.Gdx;
@@ -27,69 +28,69 @@
public class HelpScreen4 extends Screen {
OrthographicCamera guiCam;
- SpriteBatch batcher;
- Rectangle nextBounds;
- Vector3 touchPoint;
- Texture helpImage;
- TextureRegion helpRegion;
-
- public HelpScreen4(Game game) {
- super(game);
-
- guiCam = new OrthographicCamera(320, 480);
- guiCam.position.set(320 / 2, 480 / 2, 0);
- nextBounds = new Rectangle(320 - 64, 0, 64, 64);
- touchPoint = new Vector3();
- batcher = new SpriteBatch();
- helpImage = Assets.loadTexture("data/help4.png" );
- helpRegion = new TextureRegion(helpImage, 0, 0, 320, 480);
- }
-
- @Override
- public void resume() {
- }
-
- @Override
- public void pause() {
- helpImage.dispose();
- }
+ SpriteBatch batcher;
+ Rectangle nextBounds;
+ Vector3 touchPoint;
+ Texture helpImage;
+ TextureRegion helpRegion;
+
+ public HelpScreen4 (Game game) {
+ super(game);
+
+ guiCam = new OrthographicCamera(320, 480);
+ guiCam.position.set(320 / 2, 480 / 2, 0);
+ nextBounds = new Rectangle(320 - 64, 0, 64, 64);
+ touchPoint = new Vector3();
+ batcher = new SpriteBatch();
+ helpImage = Assets.loadTexture("data/help4.png");
+ helpRegion = new TextureRegion(helpImage, 0, 0, 320, 480);
+ }
+
+ @Override
+ public void resume () {
+ }
+
+ @Override
+ public void pause () {
+ helpImage.dispose();
+ }
+
+ @Override
+ public void update (float deltaTime) {
+ if (Gdx.input.justTouched()) {
+ guiCam.unproject(touchPoint.set(Gdx.input.getX(), Gdx.input.getY(), 0));
+
+ if (OverlapTester.pointInRectangle(nextBounds, touchPoint.x, touchPoint.y)) {
+ Assets.playSound(Assets.clickSound);
+ game.setScreen(new HelpScreen5(game));
+ return;
+ }
+ }
+ }
+
+ @Override
+ public void present (float deltaTime) {
+ GLCommon gl = Gdx.gl;
+ gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
+ guiCam.update();
+ guiCam.apply(Gdx.gl10);
+
+ gl.glEnable(GL10.GL_TEXTURE_2D);
+
+ batcher.disableBlending();
+ batcher.begin();
+ batcher.draw(helpRegion, 0, 0, 320, 480);
+ batcher.end();
- @Override
- public void update(float deltaTime) {
- if(Gdx.input.justTouched()) {
- guiCam.unproject(touchPoint.set(Gdx.input.getX(), Gdx.input.getY(), 0));
-
- if(OverlapTester.pointInRectangle(nextBounds, touchPoint.x, touchPoint.y)) {
- Assets.playSound(Assets.clickSound);
- game.setScreen(new HelpScreen5(game));
- return;
- }
- }
- }
+ batcher.enableBlending();
+ batcher.begin();
+ batcher.draw(Assets.arrow, 320, 0, -64, 64);
+ batcher.end();
- @Override
- public void present(float deltaTime) {
- GLCommon gl = Gdx.gl;
- gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
- guiCam.update();
- guiCam.apply(Gdx.gl10);
-
- gl.glEnable(GL10.GL_TEXTURE_2D);
-
- batcher.disableBlending();
- batcher.begin();
- batcher.draw(helpRegion, 0, 0, 320, 480);
- batcher.end();
-
- batcher.enableBlending();
- batcher.begin();
- batcher.draw(Assets.arrow, 320, 0, -64, 64);
- batcher.end();
-
- gl.glDisable(GL10.GL_BLEND);
- }
+ gl.glDisable(GL10.GL_BLEND);
+ }
- @Override
- public void dispose() {
- }
+ @Override
+ public void dispose () {
+ }
}
diff --git a/demos/superjumper/superjumper/src/com/badlogicgames/superjumper/HelpScreen5.java b/demos/superjumper/superjumper/src/com/badlogicgames/superjumper/HelpScreen5.java
index b5363c26809..5bcdfabd059 100644
--- a/demos/superjumper/superjumper/src/com/badlogicgames/superjumper/HelpScreen5.java
+++ b/demos/superjumper/superjumper/src/com/badlogicgames/superjumper/HelpScreen5.java
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
+
package com.badlogicgames.superjumper;
import com.badlogic.gdx.Gdx;
@@ -27,70 +28,69 @@
public class HelpScreen5 extends Screen {
OrthographicCamera guiCam;
- SpriteBatch batcher;
- Rectangle nextBounds;
- Vector3 touchPoint;
- Texture helpImage;
- TextureRegion helpRegion;
-
- public HelpScreen5(Game game) {
- super(game);
-
- guiCam = new OrthographicCamera(320, 480);
- guiCam.position.set(320 / 2, 480 / 2, 0);
- nextBounds = new Rectangle(320 - 64, 0, 64, 64);
- touchPoint = new Vector3();
- batcher = new SpriteBatch();
- helpImage = Assets.loadTexture("data/help5.png" );
- helpRegion = new TextureRegion(helpImage, 0, 0, 320, 480);
- }
-
- @Override
- public void resume() {
- }
-
- @Override
- public void pause() {
- helpImage.dispose();
- }
+ SpriteBatch batcher;
+ Rectangle nextBounds;
+ Vector3 touchPoint;
+ Texture helpImage;
+ TextureRegion helpRegion;
- @Override
- public void update(float deltaTime) {
- if(Gdx.input.justTouched()) {
- guiCam.unproject(touchPoint.set(Gdx.input.getX(), Gdx.input.getY(), 0));
-
- if(OverlapTester.pointInRectangle(nextBounds, touchPoint.x, touchPoint.y)) {
- Assets.playSound(Assets.clickSound);
- game.setScreen(new MainMenuScreen(game));
- return;
- }
- }
- }
+ public HelpScreen5 (Game game) {
+ super(game);
- @Override
- public void present(float deltaTime) {
- GLCommon gl = Gdx.gl;
- gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
- guiCam.update();
- guiCam.apply(Gdx.gl10);
-
- gl.glEnable(GL10.GL_TEXTURE_2D);
-
- batcher.disableBlending();
- batcher.begin();
- batcher.draw(helpRegion, 0, 0, 320, 480);
- batcher.end();
-
- batcher.enableBlending();
- batcher.begin();
- batcher.draw(Assets.arrow, 320, 0, -64, 64);
- batcher.end();
-
- gl.glDisable(GL10.GL_BLEND);
- }
+ guiCam = new OrthographicCamera(320, 480);
+ guiCam.position.set(320 / 2, 480 / 2, 0);
+ nextBounds = new Rectangle(320 - 64, 0, 64, 64);
+ touchPoint = new Vector3();
+ batcher = new SpriteBatch();
+ helpImage = Assets.loadTexture("data/help5.png");
+ helpRegion = new TextureRegion(helpImage, 0, 0, 320, 480);
+ }
- @Override
- public void dispose() {
- }
-}
+ @Override
+ public void resume () {
+ }
+
+ @Override
+ public void pause () {
+ helpImage.dispose();
+ }
+
+ @Override
+ public void update (float deltaTime) {
+ if (Gdx.input.justTouched()) {
+ guiCam.unproject(touchPoint.set(Gdx.input.getX(), Gdx.input.getY(), 0));
+
+ if (OverlapTester.pointInRectangle(nextBounds, touchPoint.x, touchPoint.y)) {
+ Assets.playSound(Assets.clickSound);
+ game.setScreen(new MainMenuScreen(game));
+ return;
+ }
+ }
+ }
+
+ @Override
+ public void present (float deltaTime) {
+ GLCommon gl = Gdx.gl;
+ gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
+ guiCam.update();
+ guiCam.apply(Gdx.gl10);
+ gl.glEnable(GL10.GL_TEXTURE_2D);
+
+ batcher.disableBlending();
+ batcher.begin();
+ batcher.draw(helpRegion, 0, 0, 320, 480);
+ batcher.end();
+
+ batcher.enableBlending();
+ batcher.begin();
+ batcher.draw(Assets.arrow, 320, 0, -64, 64);
+ batcher.end();
+
+ gl.glDisable(GL10.GL_BLEND);
+ }
+
+ @Override
+ public void dispose () {
+ }
+}
diff --git a/demos/superjumper/superjumper/src/com/badlogicgames/superjumper/HighscoresScreen.java b/demos/superjumper/superjumper/src/com/badlogicgames/superjumper/HighscoresScreen.java
index a92c0566326..15b2392d30d 100644
--- a/demos/superjumper/superjumper/src/com/badlogicgames/superjumper/HighscoresScreen.java
+++ b/demos/superjumper/superjumper/src/com/badlogicgames/superjumper/HighscoresScreen.java
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
+
package com.badlogicgames.superjumper;
import com.badlogic.gdx.Gdx;
@@ -34,7 +35,7 @@ public class HighscoresScreen extends Screen {
public HighscoresScreen (Game game) {
super(game);
- guiCam = new OrthographicCamera(320, 480);
+ guiCam = new OrthographicCamera(320, 480);
guiCam.position.set(320 / 2, 480 / 2, 0);
backBounds = new Rectangle(0, 0, 64, 64);
touchPoint = new Vector3();
@@ -47,10 +48,11 @@ public HighscoresScreen (Game game) {
xOffset = 160 - xOffset / 2 + Assets.font.getSpaceWidth() / 2;
}
- @Override public void update (float deltaTime) {
+ @Override
+ public void update (float deltaTime) {
if (Gdx.input.justTouched()) {
guiCam.unproject(touchPoint.set(Gdx.input.getX(), Gdx.input.getY(), 0));
-
+
if (OverlapTester.pointInRectangle(backBounds, touchPoint.x, touchPoint.y)) {
Assets.playSound(Assets.clickSound);
game.setScreen(new MainMenuScreen(game));
@@ -59,7 +61,8 @@ public HighscoresScreen (Game game) {
}
}
- @Override public void present (float deltaTime) {
+ @Override
+ public void present (float deltaTime) {
GLCommon gl = Gdx.gl;
gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
guiCam.update();
@@ -71,7 +74,7 @@ public HighscoresScreen (Game game) {
batcher.begin();
batcher.draw(Assets.backgroundRegion, 0, 0, 320, 480);
batcher.end();
-
+
batcher.enableBlending();
batcher.begin();
batcher.draw(Assets.highScoresRegion, 10, 360 - 16, 300, 33);
@@ -83,15 +86,18 @@ public HighscoresScreen (Game game) {
}
batcher.draw(Assets.arrow, 0, 0, 64, 64);
- batcher.end();
+ batcher.end();
}
- @Override public void resume () {
+ @Override
+ public void resume () {
}
- @Override public void pause () {
+ @Override
+ public void pause () {
}
- @Override public void dispose () {
+ @Override
+ public void dispose () {
}
}
diff --git a/demos/superjumper/superjumper/src/com/badlogicgames/superjumper/MainMenuScreen.java b/demos/superjumper/superjumper/src/com/badlogicgames/superjumper/MainMenuScreen.java
index 6b721eb13b5..d11b4e113bc 100644
--- a/demos/superjumper/superjumper/src/com/badlogicgames/superjumper/MainMenuScreen.java
+++ b/demos/superjumper/superjumper/src/com/badlogicgames/superjumper/MainMenuScreen.java
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
+
package com.badlogicgames.superjumper;
import com.badlogic.gdx.Gdx;
@@ -34,7 +35,7 @@ public class MainMenuScreen extends Screen {
public MainMenuScreen (Game game) {
super(game);
- guiCam = new OrthographicCamera(320, 480);
+ guiCam = new OrthographicCamera(320, 480);
guiCam.position.set(320 / 2, 480 / 2, 0);
batcher = new SpriteBatch();
soundBounds = new Rectangle(0, 0, 64, 64);
@@ -44,7 +45,8 @@ public MainMenuScreen (Game game) {
touchPoint = new Vector3();
}
- @Override public void update (float deltaTime) {
+ @Override
+ public void update (float deltaTime) {
if (Gdx.input.justTouched()) {
guiCam.unproject(touchPoint.set(Gdx.input.getX(), Gdx.input.getY(), 0));
@@ -74,12 +76,13 @@ public MainMenuScreen (Game game) {
}
}
- @Override public void present (float deltaTime) {
+ @Override
+ public void present (float deltaTime) {
GLCommon gl = Gdx.gl;
gl.glClearColor(1, 0, 0, 1);
gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
guiCam.update();
- batcher.setProjectionMatrix(guiCam.combined);
+ batcher.setProjectionMatrix(guiCam.combined);
batcher.disableBlending();
batcher.begin();
@@ -91,16 +94,19 @@ public MainMenuScreen (Game game) {
batcher.draw(Assets.logo, 160 - 274 / 2, 480 - 10 - 142, 274, 142);
batcher.draw(Assets.mainMenu, 10, (int)(200 - 110 / 2), 300, 110);
batcher.draw(Settings.soundEnabled ? Assets.soundOn : Assets.soundOff, 0, 0, 64, 64);
- batcher.end();
+ batcher.end();
}
- @Override public void pause () {
+ @Override
+ public void pause () {
Settings.save();
}
- @Override public void resume () {
+ @Override
+ public void resume () {
}
- @Override public void dispose () {
+ @Override
+ public void dispose () {
}
}
diff --git a/demos/superjumper/superjumper/src/com/badlogicgames/superjumper/OverlapTester.java b/demos/superjumper/superjumper/src/com/badlogicgames/superjumper/OverlapTester.java
index 247f0e36c21..02319a51ec9 100644
--- a/demos/superjumper/superjumper/src/com/badlogicgames/superjumper/OverlapTester.java
+++ b/demos/superjumper/superjumper/src/com/badlogicgames/superjumper/OverlapTester.java
@@ -13,29 +13,25 @@
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
+
package com.badlogicgames.superjumper;
import com.badlogic.gdx.math.Rectangle;
import com.badlogic.gdx.math.Vector2;
-public class OverlapTester {
- public static boolean overlapRectangles(Rectangle r1, Rectangle r2) {
- if(r1.x < r2.x + r2.width &&
- r1.x + r1.width > r2.x &&
- r1.y < r2.y + r2.height &&
- r1.y + r1.height > r2.y)
- return true;
- else
- return false;
- }
-
- public static boolean pointInRectangle(Rectangle r, Vector2 p) {
- return r.x <= p.x && r.x + r.width >= p.x &&
- r.y <= p.y && r.y + r.height >= p.y;
- }
-
- public static boolean pointInRectangle(Rectangle r, float x, float y) {
- return r.x <= x && r.x + r.width >= x &&
- r.y <= y && r.y + r.height >= y;
- }
+public class OverlapTester {
+ public static boolean overlapRectangles (Rectangle r1, Rectangle r2) {
+ if (r1.x < r2.x + r2.width && r1.x + r1.width > r2.x && r1.y < r2.y + r2.height && r1.y + r1.height > r2.y)
+ return true;
+ else
+ return false;
+ }
+
+ public static boolean pointInRectangle (Rectangle r, Vector2 p) {
+ return r.x <= p.x && r.x + r.width >= p.x && r.y <= p.y && r.y + r.height >= p.y;
+ }
+
+ public static boolean pointInRectangle (Rectangle r, float x, float y) {
+ return r.x <= x && r.x + r.width >= x && r.y <= y && r.y + r.height >= y;
+ }
}
diff --git a/demos/superjumper/superjumper/src/com/badlogicgames/superjumper/Platform.java b/demos/superjumper/superjumper/src/com/badlogicgames/superjumper/Platform.java
index 591c012ded8..da6c756abf1 100644
--- a/demos/superjumper/superjumper/src/com/badlogicgames/superjumper/Platform.java
+++ b/demos/superjumper/superjumper/src/com/badlogicgames/superjumper/Platform.java
@@ -13,54 +13,55 @@
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
+
package com.badlogicgames.superjumper;
public class Platform extends DynamicGameObject {
- public static final float PLATFORM_WIDTH = 2;
- public static final float PLATFORM_HEIGHT = 0.5f;
- public static final int PLATFORM_TYPE_STATIC = 0;
- public static final int PLATFORM_TYPE_MOVING = 1;
- public static final int PLATFORM_STATE_NORMAL = 0;
- public static final int PLATFORM_STATE_PULVERIZING = 1;
- public static final float PLATFORM_PULVERIZE_TIME = 0.2f * 4;
- public static final float PLATFORM_VELOCITY = 2;
-
- int type;
- int state;
- float stateTime;
-
- public Platform(int type, float x, float y) {
- super(x, y, PLATFORM_WIDTH, PLATFORM_HEIGHT);
- this.type = type;
- this.state = PLATFORM_STATE_NORMAL;
- this.stateTime = 0;
- if(type == PLATFORM_TYPE_MOVING) {
- velocity.x = PLATFORM_VELOCITY;
- }
- }
-
- public void update(float deltaTime) {
- if(type == PLATFORM_TYPE_MOVING) {
- position.add(velocity.x * deltaTime, 0);
- bounds.x = position.x - PLATFORM_WIDTH / 2;
- bounds.y = position.y - PLATFORM_HEIGHT / 2;
-
- if(position.x < PLATFORM_WIDTH / 2) {
- velocity.x = -velocity.x;
- position.x = PLATFORM_WIDTH / 2;
- }
- if(position.x > World.WORLD_WIDTH - PLATFORM_WIDTH / 2) {
- velocity.x = -velocity.x;
- position.x = World.WORLD_WIDTH - PLATFORM_WIDTH / 2;
- }
- }
-
- stateTime += deltaTime;
- }
-
- public void pulverize() {
- state = PLATFORM_STATE_PULVERIZING;
- stateTime = 0;
- velocity.x = 0;
- }
+ public static final float PLATFORM_WIDTH = 2;
+ public static final float PLATFORM_HEIGHT = 0.5f;
+ public static final int PLATFORM_TYPE_STATIC = 0;
+ public static final int PLATFORM_TYPE_MOVING = 1;
+ public static final int PLATFORM_STATE_NORMAL = 0;
+ public static final int PLATFORM_STATE_PULVERIZING = 1;
+ public static final float PLATFORM_PULVERIZE_TIME = 0.2f * 4;
+ public static final float PLATFORM_VELOCITY = 2;
+
+ int type;
+ int state;
+ float stateTime;
+
+ public Platform (int type, float x, float y) {
+ super(x, y, PLATFORM_WIDTH, PLATFORM_HEIGHT);
+ this.type = type;
+ this.state = PLATFORM_STATE_NORMAL;
+ this.stateTime = 0;
+ if (type == PLATFORM_TYPE_MOVING) {
+ velocity.x = PLATFORM_VELOCITY;
+ }
+ }
+
+ public void update (float deltaTime) {
+ if (type == PLATFORM_TYPE_MOVING) {
+ position.add(velocity.x * deltaTime, 0);
+ bounds.x = position.x - PLATFORM_WIDTH / 2;
+ bounds.y = position.y - PLATFORM_HEIGHT / 2;
+
+ if (position.x < PLATFORM_WIDTH / 2) {
+ velocity.x = -velocity.x;
+ position.x = PLATFORM_WIDTH / 2;
+ }
+ if (position.x > World.WORLD_WIDTH - PLATFORM_WIDTH / 2) {
+ velocity.x = -velocity.x;
+ position.x = World.WORLD_WIDTH - PLATFORM_WIDTH / 2;
+ }
+ }
+
+ stateTime += deltaTime;
+ }
+
+ public void pulverize () {
+ state = PLATFORM_STATE_PULVERIZING;
+ stateTime = 0;
+ velocity.x = 0;
+ }
}
diff --git a/demos/superjumper/superjumper/src/com/badlogicgames/superjumper/Screen.java b/demos/superjumper/superjumper/src/com/badlogicgames/superjumper/Screen.java
index ef9cad9126a..72ec88bf8fe 100644
--- a/demos/superjumper/superjumper/src/com/badlogicgames/superjumper/Screen.java
+++ b/demos/superjumper/superjumper/src/com/badlogicgames/superjumper/Screen.java
@@ -13,22 +13,23 @@
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
+
package com.badlogicgames.superjumper;
public abstract class Screen {
Game game;
-
- public Screen(Game game) {
+
+ public Screen (Game game) {
this.game = game;
}
-
- public abstract void update(float deltaTime);
-
- public abstract void present(float deltaTime);
-
- public abstract void pause();
-
- public abstract void resume();
-
- public abstract void dispose();
+
+ public abstract void update (float deltaTime);
+
+ public abstract void present (float deltaTime);
+
+ public abstract void pause ();
+
+ public abstract void resume ();
+
+ public abstract void dispose ();
}
diff --git a/demos/superjumper/superjumper/src/com/badlogicgames/superjumper/Settings.java b/demos/superjumper/superjumper/src/com/badlogicgames/superjumper/Settings.java
index 0a14dc374a6..9887e38fd20 100644
--- a/demos/superjumper/superjumper/src/com/badlogicgames/superjumper/Settings.java
+++ b/demos/superjumper/superjumper/src/com/badlogicgames/superjumper/Settings.java
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
+
package com.badlogicgames.superjumper;
import java.io.BufferedReader;
@@ -23,58 +24,55 @@
import com.badlogic.gdx.Gdx;
-
public class Settings {
- public static boolean soundEnabled = true;
- public final static int[] highscores = new int[] { 100, 80, 50, 30, 10 };
- public final static String file = ".superjumper";
+ public static boolean soundEnabled = true;
+ public final static int[] highscores = new int[] {100, 80, 50, 30, 10};
+ public final static String file = ".superjumper";
- public static void load() {
- BufferedReader in = null;
- try {
- in = new BufferedReader(new InputStreamReader(Gdx.files.external(file).read()));
- soundEnabled = Boolean.parseBoolean(in.readLine());
- for(int i = 0; i < 5; i++) {
- highscores[i] = Integer.parseInt(in.readLine());
- }
- } catch (Throwable e) {
- // :( It's ok we have defaults
- } finally {
- try {
- if (in != null)
- in.close();
- } catch (IOException e) {
- }
- }
- }
+ public static void load () {
+ BufferedReader in = null;
+ try {
+ in = new BufferedReader(new InputStreamReader(Gdx.files.external(file).read()));
+ soundEnabled = Boolean.parseBoolean(in.readLine());
+ for (int i = 0; i < 5; i++) {
+ highscores[i] = Integer.parseInt(in.readLine());
+ }
+ } catch (Throwable e) {
+ // :( It's ok we have defaults
+ } finally {
+ try {
+ if (in != null) in.close();
+ } catch (IOException e) {
+ }
+ }
+ }
- public static void save() {
- BufferedWriter out = null;
- try {
- out = new BufferedWriter(new OutputStreamWriter(Gdx.files.external(file).write(false)));
- out.write(Boolean.toString(soundEnabled));
- for(int i = 0; i < 5; i++) {
- out.write(Integer.toString(highscores[i]));
- }
+ public static void save () {
+ BufferedWriter out = null;
+ try {
+ out = new BufferedWriter(new OutputStreamWriter(Gdx.files.external(file).write(false)));
+ out.write(Boolean.toString(soundEnabled));
+ for (int i = 0; i < 5; i++) {
+ out.write(Integer.toString(highscores[i]));
+ }
- } catch (Throwable e) {
- } finally {
- try {
- if (out != null)
- out.close();
- } catch (IOException e) {
- }
- }
- }
+ } catch (Throwable e) {
+ } finally {
+ try {
+ if (out != null) out.close();
+ } catch (IOException e) {
+ }
+ }
+ }
- public static void addScore(int score) {
- for(int i=0; i < 5; i++) {
- if(highscores[i] < score) {
- for(int j= 4; j > i; j--)
- highscores[j] = highscores[j-1];
- highscores[i] = score;
- break;
- }
- }
- }
+ public static void addScore (int score) {
+ for (int i = 0; i < 5; i++) {
+ if (highscores[i] < score) {
+ for (int j = 4; j > i; j--)
+ highscores[j] = highscores[j - 1];
+ highscores[i] = score;
+ break;
+ }
+ }
+ }
}
diff --git a/demos/superjumper/superjumper/src/com/badlogicgames/superjumper/Spring.java b/demos/superjumper/superjumper/src/com/badlogicgames/superjumper/Spring.java
index c01c63569d2..842e0a76c55 100644
--- a/demos/superjumper/superjumper/src/com/badlogicgames/superjumper/Spring.java
+++ b/demos/superjumper/superjumper/src/com/badlogicgames/superjumper/Spring.java
@@ -13,14 +13,14 @@
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
-package com.badlogicgames.superjumper;
+package com.badlogicgames.superjumper;
public class Spring extends GameObject {
- public static float SPRING_WIDTH = 0.3f;
- public static float SPRING_HEIGHT = 0.3f;
-
- public Spring(float x, float y) {
- super(x, y, SPRING_WIDTH, SPRING_HEIGHT);
- }
+ public static float SPRING_WIDTH = 0.3f;
+ public static float SPRING_HEIGHT = 0.3f;
+
+ public Spring (float x, float y) {
+ super(x, y, SPRING_WIDTH, SPRING_HEIGHT);
+ }
}
diff --git a/demos/superjumper/superjumper/src/com/badlogicgames/superjumper/Squirrel.java b/demos/superjumper/superjumper/src/com/badlogicgames/superjumper/Squirrel.java
index b52946ea201..a848d151e21 100644
--- a/demos/superjumper/superjumper/src/com/badlogicgames/superjumper/Squirrel.java
+++ b/demos/superjumper/superjumper/src/com/badlogicgames/superjumper/Squirrel.java
@@ -13,33 +13,34 @@
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
+
package com.badlogicgames.superjumper;
public class Squirrel extends DynamicGameObject {
- public static final float SQUIRREL_WIDTH = 1;
- public static final float SQUIRREL_HEIGHT = 0.6f;
- public static final float SQUIRREL_VELOCITY = 3f;
-
- float stateTime = 0;
-
- public Squirrel(float x, float y) {
- super(x, y, SQUIRREL_WIDTH, SQUIRREL_HEIGHT);
- velocity.set(SQUIRREL_VELOCITY, 0);
- }
-
- public void update(float deltaTime) {
- position.add(velocity.x * deltaTime, velocity.y * deltaTime);
- bounds.x = position.x - SQUIRREL_WIDTH / 2;
- bounds.y = position.y - SQUIRREL_HEIGHT / 2;
-
- if(position.x < SQUIRREL_WIDTH / 2 ) {
- position.x = SQUIRREL_WIDTH / 2;
- velocity.x = SQUIRREL_VELOCITY;
- }
- if(position.x > World.WORLD_WIDTH - SQUIRREL_WIDTH / 2) {
- position.x = World.WORLD_WIDTH - SQUIRREL_WIDTH / 2;
- velocity.x = -SQUIRREL_VELOCITY;
- }
- stateTime += deltaTime;
- }
+ public static final float SQUIRREL_WIDTH = 1;
+ public static final float SQUIRREL_HEIGHT = 0.6f;
+ public static final float SQUIRREL_VELOCITY = 3f;
+
+ float stateTime = 0;
+
+ public Squirrel (float x, float y) {
+ super(x, y, SQUIRREL_WIDTH, SQUIRREL_HEIGHT);
+ velocity.set(SQUIRREL_VELOCITY, 0);
+ }
+
+ public void update (float deltaTime) {
+ position.add(velocity.x * deltaTime, velocity.y * deltaTime);
+ bounds.x = position.x - SQUIRREL_WIDTH / 2;
+ bounds.y = position.y - SQUIRREL_HEIGHT / 2;
+
+ if (position.x < SQUIRREL_WIDTH / 2) {
+ position.x = SQUIRREL_WIDTH / 2;
+ velocity.x = SQUIRREL_VELOCITY;
+ }
+ if (position.x > World.WORLD_WIDTH - SQUIRREL_WIDTH / 2) {
+ position.x = World.WORLD_WIDTH - SQUIRREL_WIDTH / 2;
+ velocity.x = -SQUIRREL_VELOCITY;
+ }
+ stateTime += deltaTime;
+ }
}
diff --git a/demos/superjumper/superjumper/src/com/badlogicgames/superjumper/SuperJumper.java b/demos/superjumper/superjumper/src/com/badlogicgames/superjumper/SuperJumper.java
index ebfeafa817d..3914cb567bc 100644
--- a/demos/superjumper/superjumper/src/com/badlogicgames/superjumper/SuperJumper.java
+++ b/demos/superjumper/superjumper/src/com/badlogicgames/superjumper/SuperJumper.java
@@ -13,21 +13,21 @@
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
-package com.badlogicgames.superjumper;
+package com.badlogicgames.superjumper;
public class SuperJumper extends Game {
- boolean firstTimeCreate = true;
-
- @Override
- public Screen getStartScreen() {
- return new MainMenuScreen(this);
- }
-
- @Override
- public void create() {
- Settings.load();
- Assets.load();
- super.create();
- }
+ boolean firstTimeCreate = true;
+
+ @Override
+ public Screen getStartScreen () {
+ return new MainMenuScreen(this);
+ }
+
+ @Override
+ public void create () {
+ Settings.load();
+ Assets.load();
+ super.create();
+ }
}
diff --git a/demos/superjumper/superjumper/src/com/badlogicgames/superjumper/SuperJumperDesktop.java b/demos/superjumper/superjumper/src/com/badlogicgames/superjumper/SuperJumperDesktop.java
index 78d6e2b8aeb..ac7cc8498f6 100644
--- a/demos/superjumper/superjumper/src/com/badlogicgames/superjumper/SuperJumperDesktop.java
+++ b/demos/superjumper/superjumper/src/com/badlogicgames/superjumper/SuperJumperDesktop.java
@@ -13,12 +13,13 @@
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
+
package com.badlogicgames.superjumper;
import com.badlogic.gdx.backends.jogl.JoglApplication;
public class SuperJumperDesktop {
- public static void main(String[] argv) {
+ public static void main (String[] argv) {
new JoglApplication(new SuperJumper(), "Super Jumper", 320, 480, false);
}
}
diff --git a/demos/superjumper/superjumper/src/com/badlogicgames/superjumper/World.java b/demos/superjumper/superjumper/src/com/badlogicgames/superjumper/World.java
index d15e42f587f..505272fd8a4 100644
--- a/demos/superjumper/superjumper/src/com/badlogicgames/superjumper/World.java
+++ b/demos/superjumper/superjumper/src/com/badlogicgames/superjumper/World.java
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
+
package com.badlogicgames.superjumper;
import java.util.ArrayList;
@@ -22,218 +23,203 @@
import com.badlogic.gdx.math.Vector2;
public class World {
- public interface WorldListener {
- public void jump();
-
- public void highJump();
-
- public void hit();
-
- public void coin();
- }
-
- public static final float WORLD_WIDTH = 10;
- public static final float WORLD_HEIGHT = 15 * 20;
- public static final int WORLD_STATE_RUNNING = 0;
- public static final int WORLD_STATE_NEXT_LEVEL = 1;
- public static final int WORLD_STATE_GAME_OVER = 2;
- public static final Vector2 gravity = new Vector2(0, -12);
-
- public final Bob bob;
- public final List platforms;
- public final List springs;
- public final List squirrels;
- public final List coins;
- public Castle castle;
- public final WorldListener listener;
- public final Random rand;
-
- public float heightSoFar;
- public int score;
- public int state;
-
- public World(WorldListener listener) {
- this.bob = new Bob(5, 1);
- this.platforms = new ArrayList();
- this.springs = new ArrayList();
- this.squirrels = new ArrayList();
- this.coins = new ArrayList();
- this.listener = listener;
- rand = new Random();
- generateLevel();
-
- this.heightSoFar = 0;
- this.score = 0;
- this.state = WORLD_STATE_RUNNING;
- }
-
- private void generateLevel() {
- float y = Platform.PLATFORM_HEIGHT / 2;
- float maxJumpHeight = Bob.BOB_JUMP_VELOCITY * Bob.BOB_JUMP_VELOCITY
- / (2 * -gravity.y);
- while (y < WORLD_HEIGHT - WORLD_WIDTH / 2) {
- int type = rand.nextFloat() > 0.8f ? Platform.PLATFORM_TYPE_MOVING
- : Platform.PLATFORM_TYPE_STATIC;
- float x = rand.nextFloat()
- * (WORLD_WIDTH - Platform.PLATFORM_WIDTH)
- + Platform.PLATFORM_WIDTH / 2;
-
- Platform platform = new Platform(type, x, y);
- platforms.add(platform);
-
- if (rand.nextFloat() > 0.9f
- && type != Platform.PLATFORM_TYPE_MOVING) {
- Spring spring = new Spring(platform.position.x,
- platform.position.y + Platform.PLATFORM_HEIGHT / 2
- + Spring.SPRING_HEIGHT / 2);
- springs.add(spring);
- }
-
- if (y > WORLD_HEIGHT / 3 && rand.nextFloat() > 0.8f) {
- Squirrel squirrel = new Squirrel(platform.position.x
- + rand.nextFloat(), platform.position.y
- + Squirrel.SQUIRREL_HEIGHT + rand.nextFloat() * 2);
- squirrels.add(squirrel);
- }
-
- if (rand.nextFloat() > 0.6f) {
- Coin coin = new Coin(platform.position.x + rand.nextFloat(),
- platform.position.y + Coin.COIN_HEIGHT
- + rand.nextFloat() * 3);
- coins.add(coin);
- }
-
- y += (maxJumpHeight - 0.5f);
- y -= rand.nextFloat() * (maxJumpHeight / 3);
- }
-
- castle = new Castle(WORLD_WIDTH / 2, y);
- }
-
- public void update(float deltaTime, float accelX) {
- updateBob(deltaTime, accelX);
- updatePlatforms(deltaTime);
- updateSquirrels(deltaTime);
- updateCoins(deltaTime);
- if (bob.state != Bob.BOB_STATE_HIT)
- checkCollisions();
- checkGameOver();
- }
-
- private void updateBob(float deltaTime, float accelX) {
- if (bob.state != Bob.BOB_STATE_HIT && bob.position.y <= 0.5f)
- bob.hitPlatform();
- if (bob.state != Bob.BOB_STATE_HIT)
- bob.velocity.x = -accelX / 10 * Bob.BOB_MOVE_VELOCITY;
- bob.update(deltaTime);
- heightSoFar = Math.max(bob.position.y, heightSoFar);
- }
-
- private void updatePlatforms(float deltaTime) {
- int len = platforms.size();
- for (int i = 0; i < len; i++) {
- Platform platform = platforms.get(i);
- platform.update(deltaTime);
- if (platform.state == Platform.PLATFORM_STATE_PULVERIZING
- && platform.stateTime > Platform.PLATFORM_PULVERIZE_TIME) {
- platforms.remove(platform);
- len = platforms.size();
- }
- }
- }
-
- private void updateSquirrels(float deltaTime) {
- int len = squirrels.size();
- for (int i = 0; i < len; i++) {
- Squirrel squirrel = squirrels.get(i);
- squirrel.update(deltaTime);
- }
- }
-
- private void updateCoins(float deltaTime) {
- int len = coins.size();
- for (int i = 0; i < len; i++) {
- Coin coin = coins.get(i);
- coin.update(deltaTime);
- }
- }
-
- private void checkCollisions() {
- checkPlatformCollisions();
- checkSquirrelCollisions();
- checkItemCollisions();
- checkCastleCollisions();
- }
-
- private void checkPlatformCollisions() {
- if (bob.velocity.y > 0)
- return;
-
- int len = platforms.size();
- for (int i = 0; i < len; i++) {
- Platform platform = platforms.get(i);
- if (bob.position.y > platform.position.y) {
- if (OverlapTester
- .overlapRectangles(bob.bounds, platform.bounds)) {
- bob.hitPlatform();
- listener.jump();
- if (rand.nextFloat() > 0.5f) {
- platform.pulverize();
- }
- break;
- }
- }
- }
- }
-
- private void checkSquirrelCollisions() {
- int len = squirrels.size();
- for (int i = 0; i < len; i++) {
- Squirrel squirrel = squirrels.get(i);
- if (OverlapTester.overlapRectangles(squirrel.bounds, bob.bounds)) {
- bob.hitSquirrel();
- listener.hit();
- }
- }
- }
-
- private void checkItemCollisions() {
- int len = coins.size();
- for (int i = 0; i < len; i++) {
- Coin coin = coins.get(i);
- if (OverlapTester.overlapRectangles(bob.bounds, coin.bounds)) {
- coins.remove(coin);
- len = coins.size();
- listener.coin();
- score += Coin.COIN_SCORE;
- }
-
- }
-
- if (bob.velocity.y > 0)
- return;
-
- len = springs.size();
- for (int i = 0; i < len; i++) {
- Spring spring = springs.get(i);
- if (bob.position.y > spring.position.y) {
- if (OverlapTester.overlapRectangles(bob.bounds, spring.bounds)) {
- bob.hitSpring();
- listener.highJump();
- }
- }
- }
- }
-
- private void checkCastleCollisions() {
- if (OverlapTester.overlapRectangles(castle.bounds, bob.bounds)) {
- state = WORLD_STATE_NEXT_LEVEL;
- }
- }
-
- private void checkGameOver() {
- if (heightSoFar - 7.5f > bob.position.y) {
- state = WORLD_STATE_GAME_OVER;
- }
- }
+ public interface WorldListener {
+ public void jump ();
+
+ public void highJump ();
+
+ public void hit ();
+
+ public void coin ();
+ }
+
+ public static final float WORLD_WIDTH = 10;
+ public static final float WORLD_HEIGHT = 15 * 20;
+ public static final int WORLD_STATE_RUNNING = 0;
+ public static final int WORLD_STATE_NEXT_LEVEL = 1;
+ public static final int WORLD_STATE_GAME_OVER = 2;
+ public static final Vector2 gravity = new Vector2(0, -12);
+
+ public final Bob bob;
+ public final List platforms;
+ public final List springs;
+ public final List squirrels;
+ public final List coins;
+ public Castle castle;
+ public final WorldListener listener;
+ public final Random rand;
+
+ public float heightSoFar;
+ public int score;
+ public int state;
+
+ public World (WorldListener listener) {
+ this.bob = new Bob(5, 1);
+ this.platforms = new ArrayList();
+ this.springs = new ArrayList();
+ this.squirrels = new ArrayList();
+ this.coins = new ArrayList();
+ this.listener = listener;
+ rand = new Random();
+ generateLevel();
+
+ this.heightSoFar = 0;
+ this.score = 0;
+ this.state = WORLD_STATE_RUNNING;
+ }
+
+ private void generateLevel () {
+ float y = Platform.PLATFORM_HEIGHT / 2;
+ float maxJumpHeight = Bob.BOB_JUMP_VELOCITY * Bob.BOB_JUMP_VELOCITY / (2 * -gravity.y);
+ while (y < WORLD_HEIGHT - WORLD_WIDTH / 2) {
+ int type = rand.nextFloat() > 0.8f ? Platform.PLATFORM_TYPE_MOVING : Platform.PLATFORM_TYPE_STATIC;
+ float x = rand.nextFloat() * (WORLD_WIDTH - Platform.PLATFORM_WIDTH) + Platform.PLATFORM_WIDTH / 2;
+
+ Platform platform = new Platform(type, x, y);
+ platforms.add(platform);
+
+ if (rand.nextFloat() > 0.9f && type != Platform.PLATFORM_TYPE_MOVING) {
+ Spring spring = new Spring(platform.position.x, platform.position.y + Platform.PLATFORM_HEIGHT / 2
+ + Spring.SPRING_HEIGHT / 2);
+ springs.add(spring);
+ }
+
+ if (y > WORLD_HEIGHT / 3 && rand.nextFloat() > 0.8f) {
+ Squirrel squirrel = new Squirrel(platform.position.x + rand.nextFloat(), platform.position.y
+ + Squirrel.SQUIRREL_HEIGHT + rand.nextFloat() * 2);
+ squirrels.add(squirrel);
+ }
+
+ if (rand.nextFloat() > 0.6f) {
+ Coin coin = new Coin(platform.position.x + rand.nextFloat(), platform.position.y + Coin.COIN_HEIGHT
+ + rand.nextFloat() * 3);
+ coins.add(coin);
+ }
+
+ y += (maxJumpHeight - 0.5f);
+ y -= rand.nextFloat() * (maxJumpHeight / 3);
+ }
+
+ castle = new Castle(WORLD_WIDTH / 2, y);
+ }
+
+ public void update (float deltaTime, float accelX) {
+ updateBob(deltaTime, accelX);
+ updatePlatforms(deltaTime);
+ updateSquirrels(deltaTime);
+ updateCoins(deltaTime);
+ if (bob.state != Bob.BOB_STATE_HIT) checkCollisions();
+ checkGameOver();
+ }
+
+ private void updateBob (float deltaTime, float accelX) {
+ if (bob.state != Bob.BOB_STATE_HIT && bob.position.y <= 0.5f) bob.hitPlatform();
+ if (bob.state != Bob.BOB_STATE_HIT) bob.velocity.x = -accelX / 10 * Bob.BOB_MOVE_VELOCITY;
+ bob.update(deltaTime);
+ heightSoFar = Math.max(bob.position.y, heightSoFar);
+ }
+
+ private void updatePlatforms (float deltaTime) {
+ int len = platforms.size();
+ for (int i = 0; i < len; i++) {
+ Platform platform = platforms.get(i);
+ platform.update(deltaTime);
+ if (platform.state == Platform.PLATFORM_STATE_PULVERIZING && platform.stateTime > Platform.PLATFORM_PULVERIZE_TIME) {
+ platforms.remove(platform);
+ len = platforms.size();
+ }
+ }
+ }
+
+ private void updateSquirrels (float deltaTime) {
+ int len = squirrels.size();
+ for (int i = 0; i < len; i++) {
+ Squirrel squirrel = squirrels.get(i);
+ squirrel.update(deltaTime);
+ }
+ }
+
+ private void updateCoins (float deltaTime) {
+ int len = coins.size();
+ for (int i = 0; i < len; i++) {
+ Coin coin = coins.get(i);
+ coin.update(deltaTime);
+ }
+ }
+
+ private void checkCollisions () {
+ checkPlatformCollisions();
+ checkSquirrelCollisions();
+ checkItemCollisions();
+ checkCastleCollisions();
+ }
+
+ private void checkPlatformCollisions () {
+ if (bob.velocity.y > 0) return;
+
+ int len = platforms.size();
+ for (int i = 0; i < len; i++) {
+ Platform platform = platforms.get(i);
+ if (bob.position.y > platform.position.y) {
+ if (OverlapTester.overlapRectangles(bob.bounds, platform.bounds)) {
+ bob.hitPlatform();
+ listener.jump();
+ if (rand.nextFloat() > 0.5f) {
+ platform.pulverize();
+ }
+ break;
+ }
+ }
+ }
+ }
+
+ private void checkSquirrelCollisions () {
+ int len = squirrels.size();
+ for (int i = 0; i < len; i++) {
+ Squirrel squirrel = squirrels.get(i);
+ if (OverlapTester.overlapRectangles(squirrel.bounds, bob.bounds)) {
+ bob.hitSquirrel();
+ listener.hit();
+ }
+ }
+ }
+
+ private void checkItemCollisions () {
+ int len = coins.size();
+ for (int i = 0; i < len; i++) {
+ Coin coin = coins.get(i);
+ if (OverlapTester.overlapRectangles(bob.bounds, coin.bounds)) {
+ coins.remove(coin);
+ len = coins.size();
+ listener.coin();
+ score += Coin.COIN_SCORE;
+ }
+
+ }
+
+ if (bob.velocity.y > 0) return;
+
+ len = springs.size();
+ for (int i = 0; i < len; i++) {
+ Spring spring = springs.get(i);
+ if (bob.position.y > spring.position.y) {
+ if (OverlapTester.overlapRectangles(bob.bounds, spring.bounds)) {
+ bob.hitSpring();
+ listener.highJump();
+ }
+ }
+ }
+ }
+
+ private void checkCastleCollisions () {
+ if (OverlapTester.overlapRectangles(castle.bounds, bob.bounds)) {
+ state = WORLD_STATE_NEXT_LEVEL;
+ }
+ }
+
+ private void checkGameOver () {
+ if (heightSoFar - 7.5f > bob.position.y) {
+ state = WORLD_STATE_GAME_OVER;
+ }
+ }
}
diff --git a/demos/superjumper/superjumper/src/com/badlogicgames/superjumper/WorldRenderer.java b/demos/superjumper/superjumper/src/com/badlogicgames/superjumper/WorldRenderer.java
index 613b4ab317d..b88246e42dc 100644
--- a/demos/superjumper/superjumper/src/com/badlogicgames/superjumper/WorldRenderer.java
+++ b/demos/superjumper/superjumper/src/com/badlogicgames/superjumper/WorldRenderer.java
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
+
package com.badlogicgames.superjumper;
import com.badlogic.gdx.graphics.OrthographicCamera;
@@ -29,7 +30,7 @@ public class WorldRenderer {
public WorldRenderer (SpriteBatch batch, World world) {
this.world = world;
- this.cam = new OrthographicCamera(FRUSTUM_WIDTH, FRUSTUM_HEIGHT);
+ this.cam = new OrthographicCamera(FRUSTUM_WIDTH, FRUSTUM_HEIGHT);
this.cam.position.set(FRUSTUM_WIDTH / 2, FRUSTUM_HEIGHT / 2, 0);
this.batch = batch;
}
@@ -45,11 +46,12 @@ public void render () {
public void renderBackground () {
batch.disableBlending();
batch.begin();
- batch.draw(Assets.backgroundRegion, cam.position.x - FRUSTUM_WIDTH / 2, cam.position.y - FRUSTUM_HEIGHT / 2, FRUSTUM_WIDTH, FRUSTUM_HEIGHT);
+ batch.draw(Assets.backgroundRegion, cam.position.x - FRUSTUM_WIDTH / 2, cam.position.y - FRUSTUM_HEIGHT / 2, FRUSTUM_WIDTH,
+ FRUSTUM_HEIGHT);
batch.end();
}
- public void renderObjects () {
+ public void renderObjects () {
batch.enableBlending();
batch.begin();
renderBob();
@@ -57,7 +59,7 @@ public void renderObjects () {
renderItems();
renderSquirrels();
renderCastle();
- batch.end();
+ batch.end();
}
private void renderBob () {
@@ -75,7 +77,7 @@ private void renderBob () {
}
float side = world.bob.velocity.x < 0 ? -1 : 1;
- if(side < 0)
+ if (side < 0)
batch.draw(keyFrame, world.bob.position.x + 0.5f, world.bob.position.y - 0.5f, side * 1, 1);
else
batch.draw(keyFrame, world.bob.position.x - 0.5f, world.bob.position.y - 0.5f, side * 1, 1);
@@ -115,7 +117,7 @@ private void renderSquirrels () {
Squirrel squirrel = world.squirrels.get(i);
TextureRegion keyFrame = Assets.squirrelFly.getKeyFrame(squirrel.stateTime, Animation.ANIMATION_LOOPING);
float side = squirrel.velocity.x < 0 ? -1 : 1;
- if(side < 0 )
+ if (side < 0)
batch.draw(keyFrame, squirrel.position.x + 0.5f, squirrel.position.y - 0.5f, side * 1, 1);
else
batch.draw(keyFrame, squirrel.position.x - 0.5f, squirrel.position.y - 0.5f, side * 1, 1);
diff --git a/demos/vector-pinball/gdx-vectorpinball-android/src/com/dozingcatsoftware/bouncy/BouncyAndroid.java b/demos/vector-pinball/gdx-vectorpinball-android/src/com/dozingcatsoftware/bouncy/BouncyAndroid.java
index 00c5f23836a..85b3f9ccffd 100644
--- a/demos/vector-pinball/gdx-vectorpinball-android/src/com/dozingcatsoftware/bouncy/BouncyAndroid.java
+++ b/demos/vector-pinball/gdx-vectorpinball-android/src/com/dozingcatsoftware/bouncy/BouncyAndroid.java
@@ -4,11 +4,11 @@
import android.os.Bundle;
import com.badlogic.gdx.backends.android.AndroidApplication;
-import com.badlogic.gdx.backends.android.surfaceview.FillResolutionStrategy;
public class BouncyAndroid extends AndroidApplication {
/** Called when the activity is first created. */
- @Override public void onCreate (Bundle savedInstanceState) {
+ @Override
+ public void onCreate (Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
initialize(new Bouncy(), false);
}
diff --git a/demos/vector-pinball/gdx-vectorpinball/src/com/dozingcatsoftware/bouncy/BaseFieldDelegate.java b/demos/vector-pinball/gdx-vectorpinball/src/com/dozingcatsoftware/bouncy/BaseFieldDelegate.java
index 1d94056189f..c6e0534aa7a 100644
--- a/demos/vector-pinball/gdx-vectorpinball/src/com/dozingcatsoftware/bouncy/BaseFieldDelegate.java
+++ b/demos/vector-pinball/gdx-vectorpinball/src/com/dozingcatsoftware/bouncy/BaseFieldDelegate.java
@@ -7,38 +7,45 @@
import com.dozingcatsoftware.bouncy.elements.RolloverGroupElement;
import com.dozingcatsoftware.bouncy.elements.SensorElement;
-/**
- * This class implements the Field.Delegate interface and does nothing for each of the interface methods. Real delegates can
+/** This class implements the Field.Delegate interface and does nothing for each of the interface methods. Real delegates can
* subclass this class to avoid having to create empty implementations for events they don't care about. If a field definition
* doesn't specify a delegate class, an instance of this class will be used as a placeholder delegate.
- * @author brian
- */
+ * @author brian */
public class BaseFieldDelegate implements Field.Delegate {
- @Override public void allDropTargetsInGroupHit (Field field, DropTargetGroupElement targetGroup) {
+ @Override
+ public void allDropTargetsInGroupHit (Field field, DropTargetGroupElement targetGroup) {
}
- @Override public void allRolloversInGroupActivated (Field field, RolloverGroupElement rolloverGroup) {
+ @Override
+ public void allRolloversInGroupActivated (Field field, RolloverGroupElement rolloverGroup) {
}
- @Override public void flipperActivated (Field field) {
+ @Override
+ public void flipperActivated (Field field) {
}
- @Override public void processCollision (Field field, FieldElement element, Body hitBody, Body ball) {
+ @Override
+ public void processCollision (Field field, FieldElement element, Body hitBody, Body ball) {
}
- @Override public void gameStarted (Field field) {
+ @Override
+ public void gameStarted (Field field) {
}
- @Override public void ballLost (Field field) {
+ @Override
+ public void ballLost (Field field) {
}
- @Override public void gameEnded (Field field) {
+ @Override
+ public void gameEnded (Field field) {
}
- @Override public void tick (Field field, long msecs) {
+ @Override
+ public void tick (Field field, long msecs) {
}
- @Override public void ballInSensorRange (Field field, SensorElement sensor) {
+ @Override
+ public void ballInSensorRange (Field field, SensorElement sensor) {
}
}
diff --git a/demos/vector-pinball/gdx-vectorpinball/src/com/dozingcatsoftware/bouncy/Bouncy.java b/demos/vector-pinball/gdx-vectorpinball/src/com/dozingcatsoftware/bouncy/Bouncy.java
index e69775d7da2..ce4a5796f9c 100644
--- a/demos/vector-pinball/gdx-vectorpinball/src/com/dozingcatsoftware/bouncy/Bouncy.java
+++ b/demos/vector-pinball/gdx-vectorpinball/src/com/dozingcatsoftware/bouncy/Bouncy.java
@@ -19,7 +19,8 @@ public class Bouncy extends InputAdapter implements ApplicationListener {
WindowedMean renderMean = new WindowedMean(10);
long startTime = System.nanoTime();
- @Override public void create () {
+ @Override
+ public void create () {
Thread.currentThread().setPriority(Thread.MAX_PRIORITY);
cam = new OrthographicCamera(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
renderer = new GLFieldRenderer();
@@ -28,11 +29,13 @@ public class Bouncy extends InputAdapter implements ApplicationListener {
Gdx.input.setInputProcessor(this);
}
- @Override public void resume () {
+ @Override
+ public void resume () {
}
- @Override public void render () {
+ @Override
+ public void render () {
GLCommon gl = Gdx.gl;
long startPhysics = System.nanoTime();
@@ -67,32 +70,38 @@ public class Bouncy extends InputAdapter implements ApplicationListener {
}
}
- @Override public void resize (int width, int height) {
+ @Override
+ public void resize (int width, int height) {
}
- @Override public void pause () {
+ @Override
+ public void pause () {
}
- @Override public void dispose () {
+ @Override
+ public void dispose () {
}
- @Override public boolean touchDown (int x, int y, int pointer, int button) {
+ @Override
+ public boolean touchDown (int x, int y, int pointer, int button) {
field.removeDeadBalls();
if (field.getBalls().size() != 0) field.setAllFlippersEngaged(true);
return false;
}
- @Override public boolean touchUp (int x, int y, int pointer, int button) {
+ @Override
+ public boolean touchUp (int x, int y, int pointer, int button) {
field.removeDeadBalls();
if (field.getBalls().size() == 0) field.launchBall();
field.setAllFlippersEngaged(false);
return false;
}
- @Override public boolean touchDragged (int x, int y, int pointer) {
+ @Override
+ public boolean touchDragged (int x, int y, int pointer) {
if (field.getBalls().size() != 0) field.setAllFlippersEngaged(true);
return false;
}
diff --git a/demos/vector-pinball/gdx-vectorpinball/src/com/dozingcatsoftware/bouncy/Field.java b/demos/vector-pinball/gdx-vectorpinball/src/com/dozingcatsoftware/bouncy/Field.java
index 73752740097..994b479fa54 100644
--- a/demos/vector-pinball/gdx-vectorpinball/src/com/dozingcatsoftware/bouncy/Field.java
+++ b/demos/vector-pinball/gdx-vectorpinball/src/com/dozingcatsoftware/bouncy/Field.java
@@ -75,18 +75,17 @@ static class ScheduledAction implements Comparable {
Long actionTime;
Runnable action;
- @Override public int compareTo (ScheduledAction another) {
+ @Override
+ public int compareTo (ScheduledAction another) {
// sort by action time so these objects can be added to a PriorityQueue in the right order
return actionTime.compareTo(another.actionTime);
}
}
- /**
- * Creates Box2D world, reads layout definitions for the given level (currently only one), and initializes the game to the
+ /** Creates Box2D world, reads layout definitions for the given level (currently only one), and initializes the game to the
* starting state.
* @param context
- * @param level
- */
+ * @param level */
public void resetForLevel (int level) {
Vector2 gravity = new Vector2(0.0f, -1.0f);
boolean doSleep = true;
@@ -142,18 +141,14 @@ public void startGame () {
getDelegate().gameStarted(this);
}
- /**
- * Returns the FieldElement with the given value for its "id" attribute, or null if there is no such element.
- */
+ /** Returns the FieldElement with the given value for its "id" attribute, or null if there is no such element. */
public FieldElement getFieldElementByID (String elementID) {
return fieldElements.get(elementID);
}
- /**
- * Called to advance the game's state by the specified number of milliseconds. iters is the number of times to call the Box2D
+ /** Called to advance the game's state by the specified number of milliseconds. iters is the number of times to call the Box2D
* World.step method; more iterations produce better accuracy. After updating physics, processes element collisions, calls
- * tick() on every FieldElement, and performs scheduled actions.
- */
+ * tick() on every FieldElement, and performs scheduled actions. */
void tick (long msecs, int iters) {
float dt = (msecs / 1000.0f) / iters;
@@ -171,9 +166,7 @@ void tick (long msecs, int iters) {
getDelegate().tick(this, msecs);
}
- /**
- * Calls the tick() method of every FieldElement in the layout.
- */
+ /** Calls the tick() method of every FieldElement in the layout. */
void processElementTicks () {
int size = fieldElementsToTick.length;
for (int i = 0; i < size; i++) {
@@ -181,9 +174,7 @@ void processElementTicks () {
}
}
- /**
- * Runs actions that were scheduled with scheduleAction and whose execution time has arrived.
- */
+ /** Runs actions that were scheduled with scheduleAction and whose execution time has arrived. */
void processScheduledActions () {
while (true) {
ScheduledAction nextAction = scheduledActions.peek();
@@ -196,9 +187,7 @@ void processScheduledActions () {
}
}
- /**
- * Schedules an action to be run after the given interval in milliseconds has elapsed. Interval is in game time, not real time.
- */
+ /** Schedules an action to be run after the given interval in milliseconds has elapsed. Interval is in game time, not real time. */
public void scheduleAction (long interval, Runnable action) {
ScheduledAction sa = new ScheduledAction();
sa.actionTime = gameTime + interval;
@@ -206,9 +195,7 @@ public void scheduleAction (long interval, Runnable action) {
scheduledActions.add(sa);
}
- /**
- * Launches a new ball. The position and velocity of the ball are controlled by the "launch" key in the field layout JSON.
- */
+ /** Launches a new ball. The position and velocity of the ball are controlled by the "launch" key in the field layout JSON. */
public Body launchBall () {
List position = layout.getLaunchPosition();
List velocity = layout.getLaunchVelocity();
@@ -221,9 +208,7 @@ public Body launchBall () {
return ball;
}
- /**
- * Removes a ball from play. If this results in no balls remaining on the field, calls doBallLost.
- */
+ /** Removes a ball from play. If this results in no balls remaining on the field, calls doBallLost. */
public void removeBall (Body ball) {
world.destroyBody(ball);
this.balls.remove(ball);
@@ -232,10 +217,8 @@ public void removeBall (Body ball) {
}
}
- /**
- * Called when a ball has ended. Ends the game if that was the last ball, otherwise updates GameState to the next ball. Shows a
- * game message to indicate the ball number or game over.
- */
+ /** Called when a ball has ended. Ends the game if that was the last ball, otherwise updates GameState to the next ball. Shows a
+ * game message to indicate the ball number or game over. */
public void doBallLost () {
boolean hasExtraBall = (this.gameState.getExtraBalls() > 0);
this.gameState.doNextBall();
@@ -260,10 +243,8 @@ public void run () {
getDelegate().ballLost(this);
}
- /**
- * Returns true if there are active elements in motion. Returns false if there are no active elements, indicating that tick()
- * can be called with larger time steps, less frequently, or not at all.
- */
+ /** Returns true if there are active elements in motion. Returns false if there are no active elements, indicating that tick()
+ * can be called with larger time steps, less frequently, or not at all. */
public boolean hasActiveElements () {
// HACK: to allow flippers to drop properly at beginning of game, we need accurate simulation
if (this.gameTime < 500) return true;
@@ -273,9 +254,7 @@ public boolean hasActiveElements () {
ArrayList deadBalls = new ArrayList();
- /**
- * Removes balls that are not in play, currently defined as those having a y position of less than 1.
- */
+ /** Removes balls that are not in play, currently defined as those having a y position of less than 1. */
public void removeDeadBalls () {
int len = balls.size();
deadBalls.clear();
@@ -293,9 +272,7 @@ public void removeDeadBalls () {
}
}
- /**
- * Called by FieldView to draw the balls currently in play.
- */
+ /** Called by FieldView to draw the balls currently in play. */
public void drawBalls (IFieldRenderer renderer) {
List color = layout.getBallColor();
int len = balls.size();
@@ -307,10 +284,8 @@ public void drawBalls (IFieldRenderer renderer) {
}
}
- /**
- * Called to engage or disengage all flippers. If called with an argument of true, and all flippers were not previously
- * engaged, calls the flipperActivated methods of all field elements and the field's delegate.
- */
+ /** Called to engage or disengage all flippers. If called with an argument of true, and all flippers were not previously
+ * engaged, calls the flipperActivated methods of all field elements and the field's delegate. */
public void setAllFlippersEngaged (boolean engaged) {
boolean allFlippersPreviouslyActive = true;
for (FlipperElement flipper : this.getFlipperElements()) {
@@ -326,10 +301,8 @@ public void setAllFlippersEngaged (boolean engaged) {
}
}
- /**
- * Ends a game in progress by removing all balls in play, calling setGameInProgress(false) on the GameState, and setting a
- * "Game Over" message for display by the score view.
- */
+ /** Ends a game in progress by removing all balls in play, calling setGameInProgress(false) on the GameState, and setting a
+ * "Game Over" message for display by the score view. */
public void endGame () {
int len = balls.size();
for (int i = 0; i < len; i++) {
@@ -341,9 +314,7 @@ public void endGame () {
getDelegate().gameEnded(this);
}
- /**
- * Adjusts gravity in response to the device being tilted; not currently used.
- */
+ /** Adjusts gravity in response to the device being tilted; not currently used. */
public void receivedOrientationValues (float azimuth, float pitch, float roll) {
double angle = roll - Math.PI / 2;
float gravity = layout.getGravity();
@@ -359,9 +330,7 @@ void clearBallContacts () {
ballContacts.clear();
}
- /**
- * Called after Box2D world step method, to notify FieldElements that the ball collided with.
- */
+ /** Called after Box2D world step method, to notify FieldElements that the ball collided with. */
void processBallContacts () {
int len = balls.size();
for (int i = 0; i < len; i++) {
@@ -386,11 +355,13 @@ void processBallContacts () {
}
// ContactListener methods
- @Override public void beginContact (Contact contact) {
+ @Override
+ public void beginContact (Contact contact) {
// nothing here, contact is recorded in endContact()
}
- @Override public void endContact (Contact contact) {
+ @Override
+ public void endContact (Contact contact) {
// A ball can have multiple contacts (e.g. against two walls), so store list of contacted fixtures
Body ball = null;
Fixture fixture = null;
@@ -413,10 +384,8 @@ void processBallContacts () {
// end ContactListener methods
- /**
- * Displays a message in the score view for the specified duration in milliseconds. Duration is in real world time, not
- * simulated game time.
- */
+ /** Displays a message in the score view for the specified duration in milliseconds. Duration is in real world time, not
+ * simulated game time. */
public void showGameMessage (String text, long duration) {
gameMessage = new GameMessage();
gameMessage.text = text;
@@ -433,9 +402,7 @@ void processGameMessages () {
}
}
- /**
- * Adds the given value to the game score. The value is multiplied by the GameState's current multipler.
- */
+ /** Adds the given value to the game score. The value is multiplied by the GameState's current multipler. */
public void addScore (long s) {
gameState.addScore(s);
}
@@ -490,14 +457,14 @@ public Delegate getDelegate () {
}
@Override
- public void preSolve(Contact contact, Manifold oldManifold) {
+ public void preSolve (Contact contact, Manifold oldManifold) {
// TODO Auto-generated method stub
-
+
}
@Override
- public void postSolve(Contact contact, ContactImpulse impulse) {
+ public void postSolve (Contact contact, ContactImpulse impulse) {
// TODO Auto-generated method stub
-
+
}
}
diff --git a/demos/vector-pinball/gdx-vectorpinball/src/com/dozingcatsoftware/bouncy/FieldLayout.java b/demos/vector-pinball/gdx-vectorpinball/src/com/dozingcatsoftware/bouncy/FieldLayout.java
index 00e133d462f..de4ff20d5d4 100644
--- a/demos/vector-pinball/gdx-vectorpinball/src/com/dozingcatsoftware/bouncy/FieldLayout.java
+++ b/demos/vector-pinball/gdx-vectorpinball/src/com/dozingcatsoftware/bouncy/FieldLayout.java
@@ -143,10 +143,8 @@ public float getHeight () {
return height;
}
- /**
- * Returns the desired ratio between real world time and simulation time. The application should adjust the frame rate and/or
- * time interval passed to Field.tick() to keep the ratio as close to this value as possible.
- */
+ /** Returns the desired ratio between real world time and simulation time. The application should adjust the frame rate and/or
+ * time interval passed to Field.tick() to keep the ratio as close to this value as possible. */
public float getTargetTimeRatio () {
return targetTimeRatio;
}
diff --git a/demos/vector-pinball/gdx-vectorpinball/src/com/dozingcatsoftware/bouncy/GLFieldRenderer.java b/demos/vector-pinball/gdx-vectorpinball/src/com/dozingcatsoftware/bouncy/GLFieldRenderer.java
index 1c5157f49d7..f1e47d62ab5 100644
--- a/demos/vector-pinball/gdx-vectorpinball/src/com/dozingcatsoftware/bouncy/GLFieldRenderer.java
+++ b/demos/vector-pinball/gdx-vectorpinball/src/com/dozingcatsoftware/bouncy/GLFieldRenderer.java
@@ -26,7 +26,8 @@ public void begin () {
renderer.begin(GL10.GL_LINES);
}
- @Override public void drawLine (float x1, float y1, float x2, float y2, int r, int g, int b) {
+ @Override
+ public void drawLine (float x1, float y1, float x2, float y2, int r, int g, int b) {
float fr = r / 255f;
float fg = g / 255f;
float fb = b / 255f;
@@ -36,7 +37,8 @@ public void begin () {
renderer.vertex(x2, y2, 0);
}
- @Override public void fillCircle (float cx, float cy, float radius, int r, int g, int b) {
+ @Override
+ public void fillCircle (float cx, float cy, float radius, int r, int g, int b) {
end();
renderer.begin(GL10.GL_TRIANGLE_FAN);
float fr = r / 255f;
@@ -58,7 +60,8 @@ public void begin () {
begin();
}
- @Override public void frameCircle (float cx, float cy, float radius, int r, int g, int b) {
+ @Override
+ public void frameCircle (float cx, float cy, float radius, int r, int g, int b) {
float fr = r / 255f;
float fg = g / 255f;
float fb = b / 255f;
diff --git a/demos/vector-pinball/gdx-vectorpinball/src/com/dozingcatsoftware/bouncy/GameMessage.java b/demos/vector-pinball/gdx-vectorpinball/src/com/dozingcatsoftware/bouncy/GameMessage.java
index 121faaed347..156f4aefb7e 100644
--- a/demos/vector-pinball/gdx-vectorpinball/src/com/dozingcatsoftware/bouncy/GameMessage.java
+++ b/demos/vector-pinball/gdx-vectorpinball/src/com/dozingcatsoftware/bouncy/GameMessage.java
@@ -1,9 +1,7 @@
package com.dozingcatsoftware.bouncy;
-/**
- * Simple class to hold a message displayed in the ScoreView above the game field.
- */
+/** Simple class to hold a message displayed in the ScoreView above the game field. */
public class GameMessage {
public String text;
diff --git a/demos/vector-pinball/gdx-vectorpinball/src/com/dozingcatsoftware/bouncy/IFieldRenderer.java b/demos/vector-pinball/gdx-vectorpinball/src/com/dozingcatsoftware/bouncy/IFieldRenderer.java
index c53b7387877..16141e9fc78 100644
--- a/demos/vector-pinball/gdx-vectorpinball/src/com/dozingcatsoftware/bouncy/IFieldRenderer.java
+++ b/demos/vector-pinball/gdx-vectorpinball/src/com/dozingcatsoftware/bouncy/IFieldRenderer.java
@@ -1,10 +1,8 @@
package com.dozingcatsoftware.bouncy;
-/**
- * This interface defines methods that draw graphical elements such as lines as circles to display the field. An implementation of
- * this interface is passed to FieldElement objects so they can draw themselves without depending directly on Android UI classes.
- */
+/** This interface defines methods that draw graphical elements such as lines as circles to display the field. An implementation of
+ * this interface is passed to FieldElement objects so they can draw themselves without depending directly on Android UI classes. */
public interface IFieldRenderer {
diff --git a/demos/vector-pinball/gdx-vectorpinball/src/com/dozingcatsoftware/bouncy/elements/Box2DFactory.java b/demos/vector-pinball/gdx-vectorpinball/src/com/dozingcatsoftware/bouncy/elements/Box2DFactory.java
index 244ca2d7899..7ac09724e9a 100644
--- a/demos/vector-pinball/gdx-vectorpinball/src/com/dozingcatsoftware/bouncy/elements/Box2DFactory.java
+++ b/demos/vector-pinball/gdx-vectorpinball/src/com/dozingcatsoftware/bouncy/elements/Box2DFactory.java
@@ -9,16 +9,12 @@
import com.badlogic.gdx.physics.box2d.PolygonShape;
import com.badlogic.gdx.physics.box2d.World;
-/**
- * Methods to create Box2D shapes.
- * @author brian
- */
+/** Methods to create Box2D shapes.
+ * @author brian */
public class Box2DFactory {
- /**
- * Creates a circle object with the given position and radius. Resitution defaults to 0.6.
- */
+ /** Creates a circle object with the given position and radius. Resitution defaults to 0.6. */
public static Body createCircle (World world, float x, float y, float radius, boolean isStatic) {
CircleShape sd = new CircleShape();
sd.setRadius(radius);
@@ -43,18 +39,14 @@ public static Body createCircle (World world, float x, float y, float radius, bo
return body;
}
- /**
- * Creates a wall by constructing a rectangle whose corners are (xmin,ymin) and (xmax,ymax), and rotating the box
- * counterclockwise through the given angle. Restitution defaults to 0.5.
- */
+ /** Creates a wall by constructing a rectangle whose corners are (xmin,ymin) and (xmax,ymax), and rotating the box
+ * counterclockwise through the given angle. Restitution defaults to 0.5. */
public static Body createWall (World world, float xmin, float ymin, float xmax, float ymax, float angle) {
return createWall(world, xmin, ymin, xmax, ymax, angle, 0f);
}
- /**
- * Creates a wall by constructing a rectangle whose corners are (xmin,ymin) and (xmax,ymax), and rotating the box
- * counterclockwise through the given angle, with specified restitution.
- */
+ /** Creates a wall by constructing a rectangle whose corners are (xmin,ymin) and (xmax,ymax), and rotating the box
+ * counterclockwise through the given angle, with specified restitution. */
public static Body createWall (World world, float xmin, float ymin, float xmax, float ymax, float angle, float restitution) {
float cx = (xmin + xmax) / 2;
float cy = (ymin + ymax) / 2;
diff --git a/demos/vector-pinball/gdx-vectorpinball/src/com/dozingcatsoftware/bouncy/elements/BumperElement.java b/demos/vector-pinball/gdx-vectorpinball/src/com/dozingcatsoftware/bouncy/elements/BumperElement.java
index 67849a6c416..b74a1a4dda9 100644
--- a/demos/vector-pinball/gdx-vectorpinball/src/com/dozingcatsoftware/bouncy/elements/BumperElement.java
+++ b/demos/vector-pinball/gdx-vectorpinball/src/com/dozingcatsoftware/bouncy/elements/BumperElement.java
@@ -14,10 +14,8 @@
import static com.dozingcatsoftware.bouncy.util.MathUtils.*;
-/**
- * This FieldElement subclass represents a bumper that applies an impulse to a ball when it hits. The impulse magnitude is
- * controlled by the "kick" parameter in the configuration map.
- */
+/** This FieldElement subclass represents a bumper that applies an impulse to a ball when it hits. The impulse magnitude is
+ * controlled by the "kick" parameter in the configuration map. */
public class BumperElement extends FieldElement {
@@ -39,11 +37,13 @@ public void finishCreate (Map params, World world) {
pegBodySet = Collections.singleton(pegBody);
}
- @Override public Collection getBodies () {
+ @Override
+ public Collection getBodies () {
return pegBodySet;
}
- @Override public boolean shouldCallTick () {
+ @Override
+ public boolean shouldCallTick () {
// needs to call tick to decrement flash counter (but can use superclass tick() implementation)
return true;
}
@@ -59,7 +59,8 @@ Vector2 impulseForBall (Body ball) {
return new Vector2(ix * scale, iy * scale);
}
- @Override public void handleCollision (Body ball, Body bodyHit, Field field) {
+ @Override
+ public void handleCollision (Body ball, Body bodyHit, Field field) {
Vector2 impulse = this.impulseForBall(ball);
if (impulse != null) {
ball.applyLinearImpulse(impulse, ball.getWorldCenter());
@@ -67,7 +68,8 @@ Vector2 impulseForBall (Body ball) {
}
}
- @Override public void draw (IFieldRenderer renderer) {
+ @Override
+ public void draw (IFieldRenderer renderer) {
renderer.fillCircle(cx, cy, radius, redColorComponent(0), greenColorComponent(0), blueColorComponent(255));
}
}
diff --git a/demos/vector-pinball/gdx-vectorpinball/src/com/dozingcatsoftware/bouncy/elements/DropTargetGroupElement.java b/demos/vector-pinball/gdx-vectorpinball/src/com/dozingcatsoftware/bouncy/elements/DropTargetGroupElement.java
index 509e975a300..50c37708474 100644
--- a/demos/vector-pinball/gdx-vectorpinball/src/com/dozingcatsoftware/bouncy/elements/DropTargetGroupElement.java
+++ b/demos/vector-pinball/gdx-vectorpinball/src/com/dozingcatsoftware/bouncy/elements/DropTargetGroupElement.java
@@ -14,11 +14,9 @@
import static com.dozingcatsoftware.bouncy.util.MathUtils.*;
-/**
- * This FieldElement subclass represents a set of drop targets, which are segments that disappear when hit. When all targets are
+/** This FieldElement subclass represents a set of drop targets, which are segments that disappear when hit. When all targets are
* hit, the Field delegate is notified, and if the reset parameter is set, the targets will reappear after a delay.
- * @author brian
- */
+ * @author brian */
public class DropTargetGroupElement extends FieldElement {
@@ -26,7 +24,8 @@ public class DropTargetGroupElement extends FieldElement {
List allBodies = new ArrayList();
Map bodyPositions = new HashMap();
- @Override public void finishCreate (Map params, World world) {
+ @Override
+ public void finishCreate (Map params, World world) {
// individual targets are specified in "positions" list
List positions = (List)params.get("positions");
for (List pos : positions) {
@@ -38,7 +37,8 @@ public class DropTargetGroupElement extends FieldElement {
}
}
- @Override public Collection getBodies () {
+ @Override
+ public Collection getBodies () {
return allBodies;
}
@@ -50,7 +50,8 @@ public boolean allTargetsHit () {
return true;
}
- @Override public void handleCollision (Body ball, Body bodyHit, final Field field) {
+ @Override
+ public void handleCollision (Body ball, Body bodyHit, final Field field) {
bodyHit.setActive(false);
// if all hit, notify delegate and check for reset parameter
if (allTargetsHit()) {
@@ -74,7 +75,8 @@ public void makeAllTargetsVisible (Field field) {
}
}
- @Override public void draw (IFieldRenderer renderer) {
+ @Override
+ public void draw (IFieldRenderer renderer) {
// draw line for each target
int r = redColorComponent(0);
int g = greenColorComponent(255);
diff --git a/demos/vector-pinball/gdx-vectorpinball/src/com/dozingcatsoftware/bouncy/elements/FieldElement.java b/demos/vector-pinball/gdx-vectorpinball/src/com/dozingcatsoftware/bouncy/elements/FieldElement.java
index cd91addac5f..37c9e5aae42 100644
--- a/demos/vector-pinball/gdx-vectorpinball/src/com/dozingcatsoftware/bouncy/elements/FieldElement.java
+++ b/demos/vector-pinball/gdx-vectorpinball/src/com/dozingcatsoftware/bouncy/elements/FieldElement.java
@@ -10,10 +10,8 @@
import com.dozingcatsoftware.bouncy.Field;
import com.dozingcatsoftware.bouncy.IFieldRenderer;
-/**
- * Abstract superclass of all elements in the pinball field, such as walls, bumpers, and flippers.
- * @author brian
- */
+/** Abstract superclass of all elements in the pinball field, such as walls, bumpers, and flippers.
+ * @author brian */
public abstract class FieldElement {
@@ -30,11 +28,9 @@ public abstract class FieldElement {
static int DEFAULT_WALL_GREEN = 64;
static int DEFAULT_WALL_BLUE = 160;
- /**
- * Creates and returns a FieldElement object from the given map of parameters. The default class to instantiate is an argument
+ /** Creates and returns a FieldElement object from the given map of parameters. The default class to instantiate is an argument
* to this method, and can be overridden by the "class" property of the parameter map. Calls the no-argument constructor of the
- * default or custom class, and then calls initialize() passing the parameter map and World.
- */
+ * default or custom class, and then calls initialize() passing the parameter map and World. */
public static FieldElement createFromParameters (Map params, World world, Class defaultClass) {
try {
if (params.containsKey("class")) {
@@ -54,10 +50,8 @@ public static FieldElement createFromParameters (Map params, World world, Class
}
}
- /**
- * Extracts common values from the definition parameter map, and calls finishCreate to allow subclasses to further initialize
- * themselves. Subclasses should override finishCreate, and should not override this method.
- */
+ /** Extracts common values from the definition parameter map, and calls finishCreate to allow subclasses to further initialize
+ * themselves. Subclasses should override finishCreate, and should not override this method. */
public void initialize (Map params, World world) {
this.parameters = params;
this.box2dWorld = world;
@@ -75,80 +69,58 @@ public void initialize (Map params, World world) {
this.finishCreate(params, world);
}
- /**
- * Called after creation to determine if tick() needs to be called after every frame is simulated. Default returns false,
+ /** Called after creation to determine if tick() needs to be called after every frame is simulated. Default returns false,
* subclasses must override to return true in order for tick() to be called. This is an optimization to avoid needless method
- * calls in the game loop.
- */
+ * calls in the game loop. */
public boolean shouldCallTick () {
return false;
}
- /**
- * Called on every update from Field.tick. Default implementation decrements flash counter if active, subclasses can override
+ /** Called on every update from Field.tick. Default implementation decrements flash counter if active, subclasses can override
* to perform additional processing, e.g. RolloverGroupElement checking for balls within radius of rollovers. Subclasses should
- * call super.tick(field).
- */
+ * call super.tick(field). */
public void tick (Field field) {
if (flashCounter > 0) flashCounter--;
}
- /**
- * Called when the player activates one or more flippers. The default implementation does nothing; subclasses can override.
- */
+ /** Called when the player activates one or more flippers. The default implementation does nothing; subclasses can override. */
public void flipperActivated (Field field) {
}
- /**
- * Causes the colors returned by red/blue/greenColorComponent methods to be inverted for the given number of frames. This can
- * be used to flash an element when it is hit by a ball, see PegElement.
- */
+ /** Causes the colors returned by red/blue/greenColorComponent methods to be inverted for the given number of frames. This can
+ * be used to flash an element when it is hit by a ball, see PegElement. */
public void flashForFrames (int frames) {
flashCounter = frames;
}
- /**
- * Must be overridden by subclasses, which should perform any setup required after creation.
- */
+ /** Must be overridden by subclasses, which should perform any setup required after creation. */
public abstract void finishCreate (Map params, World world);
- /**
- * Must be overridden by subclasses to return a collection of all Box2D bodies which make up this element.
- */
+ /** Must be overridden by subclasses to return a collection of all Box2D bodies which make up this element. */
public abstract Collection getBodies ();
- /**
- * Must be overridden by subclasses to draw the element, using IFieldRenderer methods.
- */
+ /** Must be overridden by subclasses to draw the element, using IFieldRenderer methods. */
public abstract void draw (IFieldRenderer renderer);
- /**
- * Called when a ball collides with a Body in this element. The default implementation does nothing (allowing objects to bounce
- * off each other normally), subclasses can override (e.g. to apply extra force)
- */
+ /** Called when a ball collides with a Body in this element. The default implementation does nothing (allowing objects to bounce
+ * off each other normally), subclasses can override (e.g. to apply extra force) */
public void handleCollision (Body ball, Body bodyHit, Field field) {
}
- /**
- * Returns this element's ID as specified in the JSON definition, or null if the ID is not specified.
- */
+ /** Returns this element's ID as specified in the JSON definition, or null if the ID is not specified. */
public String getElementID () {
return elementID;
}
- /**
- * Returns the parameter map from which this element was created.
- */
+ /** Returns the parameter map from which this element was created. */
public Map getParameters () {
return parameters;
}
- /**
- * Returns the "score" value for this element. The score is automatically added when the element is hit by a ball, and elements
+ /** Returns the "score" value for this element. The score is automatically added when the element is hit by a ball, and elements
* may apply scores under other conditions, e.g. RolloverGroupElement adds the score when a ball comes within range of a
- * rollover.
- */
+ * rollover. */
public long getScore () {
return score;
}
@@ -160,26 +132,20 @@ protected int colorComponent (int index, int defvalue) {
return (flashCounter > 0) ? 255 - value : value;
}
- /**
- * Returns the red component of this element's base color, taken from the "color" parameter. If there is no color parameter,
- * the default argument is returned.
- */
+ /** Returns the red component of this element's base color, taken from the "color" parameter. If there is no color parameter,
+ * the default argument is returned. */
protected int redColorComponent (int defvalue) {
return colorComponent(0, defvalue);
}
- /**
- * Returns the green component of this element's base color, taken from the "color" parameter. If there is no color parameter,
- * the default argument is returned.
- */
+ /** Returns the green component of this element's base color, taken from the "color" parameter. If there is no color parameter,
+ * the default argument is returned. */
protected int greenColorComponent (int defvalue) {
return colorComponent(1, defvalue);
}
- /**
- * Returns the blue component of this element's base color, taken from the "color" parameter. If there is no color parameter,
- * the default argument is returned.
- */
+ /** Returns the blue component of this element's base color, taken from the "color" parameter. If there is no color parameter,
+ * the default argument is returned. */
protected int blueColorComponent (int defvalue) {
return colorComponent(2, defvalue);
}
diff --git a/demos/vector-pinball/gdx-vectorpinball/src/com/dozingcatsoftware/bouncy/elements/FlipperElement.java b/demos/vector-pinball/gdx-vectorpinball/src/com/dozingcatsoftware/bouncy/elements/FlipperElement.java
index 99099b60784..a47e155a910 100644
--- a/demos/vector-pinball/gdx-vectorpinball/src/com/dozingcatsoftware/bouncy/elements/FlipperElement.java
+++ b/demos/vector-pinball/gdx-vectorpinball/src/com/dozingcatsoftware/bouncy/elements/FlipperElement.java
@@ -17,16 +17,14 @@
import static com.dozingcatsoftware.bouncy.util.MathUtils.*;
-/**
- * FieldElement subclass for a flipper that is controlled by the player. A flipper consists of a Box2D RevoluteJoint where a thin
+/** FieldElement subclass for a flipper that is controlled by the player. A flipper consists of a Box2D RevoluteJoint where a thin
* wall rotates around an invisible anchor. Flippers are defined in the layout JSON as follows: { "class": "FlipperElement",
* "position": [5.5, 10], // x,y of fixed end of flipper which it rotates around "length": 2.5, // length of the flipper. Negative
* if the flipper rotates around its right end. "minangle": -20, // minimum angle from the horizontal. Negative angles are below
* horizontal. "maxangle": 20, // maximum angle from the horizontal. "upspeed": 7, // rate at which the flipper rotates up when
* activated (in radians/sec?) "downspeed": 3 // rate at which the flipper rotates down when not activated (in radians/sec?) }
*
- * @author brian
- */
+ * @author brian */
public class FlipperElement extends FieldElement {
@@ -41,7 +39,8 @@ public class FlipperElement extends FieldElement {
float minangle, maxangle;
float cx, cy;
- @Override public void finishCreate (Map params, World world) {
+ @Override
+ public void finishCreate (Map params, World world) {
List pos = (List)params.get("position");
this.cx = asFloat(pos.get(0));
@@ -94,15 +93,18 @@ void setEffectiveMotorSpeed (float speed) {
joint.setMotorSpeed(speed);
}
- @Override public Collection getBodies () {
+ @Override
+ public Collection getBodies () {
return flipperBodySet;
}
- @Override public boolean shouldCallTick () {
+ @Override
+ public boolean shouldCallTick () {
return true;
}
- @Override public void tick (Field field) {
+ @Override
+ public void tick (Field field) {
super.tick(field);
// if angle is at maximum, reduce speed so that the ball won't fly off when it hits
@@ -138,7 +140,8 @@ public Body getAnchorBody () {
return anchorBody;
}
- @Override public void draw (IFieldRenderer renderer) {
+ @Override
+ public void draw (IFieldRenderer renderer) {
// draw single line segment from anchor point
Vector2 position = anchorBody.getPosition();
float angle = joint.getJointAngle();
diff --git a/demos/vector-pinball/gdx-vectorpinball/src/com/dozingcatsoftware/bouncy/elements/RolloverGroupElement.java b/demos/vector-pinball/gdx-vectorpinball/src/com/dozingcatsoftware/bouncy/elements/RolloverGroupElement.java
index 14869885a32..228558e3db4 100644
--- a/demos/vector-pinball/gdx-vectorpinball/src/com/dozingcatsoftware/bouncy/elements/RolloverGroupElement.java
+++ b/demos/vector-pinball/gdx-vectorpinball/src/com/dozingcatsoftware/bouncy/elements/RolloverGroupElement.java
@@ -15,13 +15,11 @@
import static com.dozingcatsoftware.bouncy.util.MathUtils.*;
-/**
- * This class represents a collection of rollover elements, such as the rollovers in the top lanes. They are activated (and
+/** This class represents a collection of rollover elements, such as the rollovers in the top lanes. They are activated (and
* optionally deactivated) when a ball passes over them. Individual rollovers in the group are represented by instances of the
* Rollover nested class, which specify center, radius, and color. Parameters at the collection level control whether the
* rollovers should cycle when flippers are activated, and whether rollovers can toggle from on to off.
- * @author brian
- */
+ * @author brian */
public class RolloverGroupElement extends FieldElement {
@@ -44,7 +42,8 @@ static class Rollover {
List rolloversHitOnPreviousTick = new ArrayList();
- @Override public void finishCreate (Map params, World world) {
+ @Override
+ public void finishCreate (Map params, World world) {
this.canToggleOff = Boolean.TRUE.equals(params.get("toggleOff"));
this.cycleOnFlipper = Boolean.TRUE.equals(params.get("cycleOnFlipper"));
this.ignoreBall = Boolean.TRUE.equals(params.get("ignoreBall"));
@@ -69,7 +68,8 @@ static class Rollover {
}
}
- @Override public Collection getBodies () {
+ @Override
+ public Collection getBodies () {
return Collections.EMPTY_SET;
}
@@ -106,9 +106,7 @@ public boolean allRolloversActive () {
return activeRollovers.size() == rollovers.size();
}
- /**
- * Activates the first unactivated rollover in the group. Has no effect if all are active.
- */
+ /** Activates the first unactivated rollover in the group. Has no effect if all are active. */
public void activateFirstUnactivatedRollover () {
int len = rollovers.size();
for (int i = 0; i < len; i++) {
@@ -120,12 +118,14 @@ public void activateFirstUnactivatedRollover () {
}
}
- @Override public boolean shouldCallTick () {
+ @Override
+ public boolean shouldCallTick () {
return true;
}
- @Override public void tick (Field field) {
+ @Override
+ public void tick (Field field) {
if (this.ignoreBall) return;
boolean allActivePrevious = this.allRolloversActive();
@@ -164,7 +164,8 @@ public void run () {
}
}
- @Override public void flipperActivated (Field field) {
+ @Override
+ public void flipperActivated (Field field) {
if (this.cycleOnFlipper) {
this.cycleRollovers();
}
@@ -172,11 +173,9 @@ public void run () {
List newActiveRollovers = new ArrayList();
- /**
- * Cycles the states of all rollover elements by "rotating" right. For example, if this group has three rollovers whose states
+ /** Cycles the states of all rollover elements by "rotating" right. For example, if this group has three rollovers whose states
* are (on, on, off), after calling this method the states will be (off, on, on). The state of the last rollover wraps around
- * to the first, so (off, off, on) -> (on, off, off).
- */
+ * to the first, so (off, off, on) -> (on, off, off). */
public void cycleRollovers () {
newActiveRollovers.clear();
for (int i = 0; i < this.rollovers.size(); i++) {
@@ -189,9 +188,7 @@ public void cycleRollovers () {
this.activeRollovers.addAll(newActiveRollovers);
}
- /**
- * Sets all rollovers to be active or inactive according to the boolean argument.
- */
+ /** Sets all rollovers to be active or inactive according to the boolean argument. */
public void setAllRolloversActivated (boolean active) {
activeRollovers.clear();
if (active) {
@@ -199,7 +196,8 @@ public void setAllRolloversActivated (boolean active) {
}
}
- @Override public void draw (IFieldRenderer renderer) {
+ @Override
+ public void draw (IFieldRenderer renderer) {
// default color defined at the group level
int defaultRed = this.redColorComponent(0);
int defaultGreen = this.greenColorComponent(255);
diff --git a/demos/vector-pinball/gdx-vectorpinball/src/com/dozingcatsoftware/bouncy/elements/SensorElement.java b/demos/vector-pinball/gdx-vectorpinball/src/com/dozingcatsoftware/bouncy/elements/SensorElement.java
index acc44340577..d321151c523 100644
--- a/demos/vector-pinball/gdx-vectorpinball/src/com/dozingcatsoftware/bouncy/elements/SensorElement.java
+++ b/demos/vector-pinball/gdx-vectorpinball/src/com/dozingcatsoftware/bouncy/elements/SensorElement.java
@@ -14,15 +14,12 @@
import static com.dozingcatsoftware.bouncy.util.MathUtils.*;
-/**
- * This FieldElement subclass is used to identify areas on the table that should cause custom behavior when the ball enters.
+/** This FieldElement subclass is used to identify areas on the table that should cause custom behavior when the ball enters.
* SensorElements have no bodies and don't draw anything. The area they monitor can be a rectangle defined by the "rect" parameter
* as a [xmin,ymin,xmax,ymax] list, a circle defined by the "center" and "radius" parameters. During every tick() invocation, a
* sensor determines if any of the field's balls are within its area, and if so calls the field delegate's ballInSensorRange
* method.
- * @author brian
- *
- */
+ * @author brian */
public class SensorElement extends FieldElement {
@@ -31,7 +28,8 @@ public class SensorElement extends FieldElement {
float cx, cy; // center for circular areas
float radiusSquared;
- @Override public void finishCreate (Map params, World world) {
+ @Override
+ public void finishCreate (Map params, World world) {
if (params.containsKey("center") && params.containsKey("radius")) {
this.circular = true;
List centerPos = (List)params.get("center");
@@ -53,7 +51,8 @@ public class SensorElement extends FieldElement {
}
}
- @Override public boolean shouldCallTick () {
+ @Override
+ public boolean shouldCallTick () {
return true;
}
@@ -71,7 +70,8 @@ boolean ballInRange (Body ball) {
return true;
}
- @Override public void tick (Field field) {
+ @Override
+ public void tick (Field field) {
int len = field.getBalls().size();
for (int i = 0; i < len; i++) {
Body ball = field.getBalls().get(i);
@@ -82,11 +82,13 @@ boolean ballInRange (Body ball) {
}
}
- @Override public Collection getBodies () {
+ @Override
+ public Collection getBodies () {
return Collections.EMPTY_SET;
}
- @Override public void draw (IFieldRenderer renderer) {
+ @Override
+ public void draw (IFieldRenderer renderer) {
// no UI
}
diff --git a/demos/vector-pinball/gdx-vectorpinball/src/com/dozingcatsoftware/bouncy/elements/WallArcElement.java b/demos/vector-pinball/gdx-vectorpinball/src/com/dozingcatsoftware/bouncy/elements/WallArcElement.java
index 1f99cd7b449..b77a4caeecc 100644
--- a/demos/vector-pinball/gdx-vectorpinball/src/com/dozingcatsoftware/bouncy/elements/WallArcElement.java
+++ b/demos/vector-pinball/gdx-vectorpinball/src/com/dozingcatsoftware/bouncy/elements/WallArcElement.java
@@ -12,8 +12,7 @@
import static com.dozingcatsoftware.bouncy.util.MathUtils.*;
-/**
- * This FieldElement subclass approximates a circular wall with a series of straight wall segments whose endpoints lie on a circle
+/** This FieldElement subclass approximates a circular wall with a series of straight wall segments whose endpoints lie on a circle
* or ellipse. These elements are defined in the layout JSON as follows: { "class": "WallArcElement", "center": [5.5, 10], //
* center of circle or ellipse "xradius": 2.5, // radius in the horizontal direction "yradius": 2, // radius in the y direction
* "minangle": 45, // starting angle in degrees, 0 is to the right of the center, 90 is up. "maxangle": 135, // ending angle in
@@ -22,8 +21,7 @@
*
* For circular walls, the "radius" attribute can be used instead of xradius and yradius.
*
- * @author brian
- */
+ * @author brian */
public class WallArcElement extends FieldElement {
@@ -64,11 +62,13 @@ public void finishCreate (Map params, World world) {
}
}
- @Override public Collection getBodies () {
+ @Override
+ public Collection getBodies () {
return wallBodies;
}
- @Override public void draw (IFieldRenderer renderer) {
+ @Override
+ public void draw (IFieldRenderer renderer) {
int len = lineSegments.size();
for (int i = 0; i < len; i++) {
float[] segment = lineSegments.get(i);
diff --git a/demos/vector-pinball/gdx-vectorpinball/src/com/dozingcatsoftware/bouncy/elements/WallElement.java b/demos/vector-pinball/gdx-vectorpinball/src/com/dozingcatsoftware/bouncy/elements/WallElement.java
index d3011841752..93eeeaa6316 100644
--- a/demos/vector-pinball/gdx-vectorpinball/src/com/dozingcatsoftware/bouncy/elements/WallElement.java
+++ b/demos/vector-pinball/gdx-vectorpinball/src/com/dozingcatsoftware/bouncy/elements/WallElement.java
@@ -14,8 +14,7 @@
import static com.dozingcatsoftware.bouncy.util.MathUtils.*;
-/**
- * FieldElement subclass that represents a straight wall. Its position is specified by the "position" parameter with 4 values,
+/** FieldElement subclass that represents a straight wall. Its position is specified by the "position" parameter with 4 values,
* which are [start x, start y, end x, end y]. There are several optional parameters to customize the wall's behavior: "kick":
* impulse to apply when a ball hits the wall, used for kickers and ball savers. "kill": if true, the ball is lost when it hits
* the wall. Used for invisible wall below the flippers. "retractWhenHit": if true, the wall is removed when hit by a ball. Used
@@ -24,9 +23,7 @@
*
* Walls can be removed from the field by calling setRetracted(field, true), and restored with setRetracted(field, false).
*
- * @author brian
- *
- */
+ * @author brian */
public class WallElement extends FieldElement {
@@ -38,7 +35,8 @@ public class WallElement extends FieldElement {
boolean killBall;
boolean retractWhenHit;
- @Override public void finishCreate (Map params, World world) {
+ @Override
+ public void finishCreate (Map params, World world) {
List pos = (List)params.get("position");
this.x1 = asFloat(pos.get(0));
this.y1 = asFloat(pos.get(1));
@@ -69,11 +67,13 @@ public void setRetracted (boolean retracted) {
}
}
- @Override public Collection getBodies () {
+ @Override
+ public Collection getBodies () {
return bodySet;
}
- @Override public boolean shouldCallTick () {
+ @Override
+ public boolean shouldCallTick () {
// tick() only needs to be called if this wall provides a kick which makes it flash
return (this.kick > 0.01f);
}
@@ -99,7 +99,8 @@ Vector2 impulseForBall (Body ball) {
return new Vector2(ix, iy);
}
- @Override public void handleCollision (Body ball, Body bodyHit, Field field) {
+ @Override
+ public void handleCollision (Body ball, Body bodyHit, Field field) {
if (retractWhenHit) {
this.setRetracted(true);
}
@@ -115,7 +116,8 @@ Vector2 impulseForBall (Body ball) {
}
}
- @Override public void draw (IFieldRenderer renderer) {
+ @Override
+ public void draw (IFieldRenderer renderer) {
if (isRetracted()) return;
renderer.drawLine(x1, y1, x2, y2, redColorComponent(DEFAULT_WALL_RED), greenColorComponent(DEFAULT_WALL_GREEN),
blueColorComponent(DEFAULT_WALL_BLUE));
diff --git a/demos/vector-pinball/gdx-vectorpinball/src/com/dozingcatsoftware/bouncy/elements/WallPathElement.java b/demos/vector-pinball/gdx-vectorpinball/src/com/dozingcatsoftware/bouncy/elements/WallPathElement.java
index 5309933d536..01b43e95adb 100644
--- a/demos/vector-pinball/gdx-vectorpinball/src/com/dozingcatsoftware/bouncy/elements/WallPathElement.java
+++ b/demos/vector-pinball/gdx-vectorpinball/src/com/dozingcatsoftware/bouncy/elements/WallPathElement.java
@@ -12,12 +12,10 @@
import static com.dozingcatsoftware.bouncy.util.MathUtils.*;
-/**
- * FieldElement subclass which represents a series of wall segments. The segments are defined in the "positions" parameter as a
+/** FieldElement subclass which represents a series of wall segments. The segments are defined in the "positions" parameter as a
* list of [x,y] values, for example: { "class": "WallPathElement", "positions": [[5,5], [5,10], [8,10], [5, 15]] }
*
- * @author brian
- */
+ * @author brian */
public class WallPathElement extends FieldElement {
@@ -40,11 +38,13 @@ public void finishCreate (Map params, World world) {
}
}
- @Override public Collection getBodies () {
+ @Override
+ public Collection getBodies () {
return wallBodies;
}
- @Override public void draw (IFieldRenderer renderer) {
+ @Override
+ public void draw (IFieldRenderer renderer) {
int len = lineSegments.size();
for (int i = 0; i < len; i++) {
float[] segment = lineSegments.get(i);
diff --git a/demos/vector-pinball/gdx-vectorpinball/src/com/dozingcatsoftware/bouncy/fields/Field1Delegate.java b/demos/vector-pinball/gdx-vectorpinball/src/com/dozingcatsoftware/bouncy/fields/Field1Delegate.java
index cc0c8e99167..125b5775435 100644
--- a/demos/vector-pinball/gdx-vectorpinball/src/com/dozingcatsoftware/bouncy/fields/Field1Delegate.java
+++ b/demos/vector-pinball/gdx-vectorpinball/src/com/dozingcatsoftware/bouncy/fields/Field1Delegate.java
@@ -10,7 +10,8 @@
public class Field1Delegate extends BaseFieldDelegate {
- @Override public void allRolloversInGroupActivated (Field field, RolloverGroupElement rolloverGroup) {
+ @Override
+ public void allRolloversInGroupActivated (Field field, RolloverGroupElement rolloverGroup) {
// rollover groups increment field multiplier when all rollovers are activated, also reset to inactive
rolloverGroup.setAllRolloversActivated(false);
field.getGameState().incrementScoreMultiplier();
@@ -28,7 +29,8 @@ public class Field1Delegate extends BaseFieldDelegate {
}
- @Override public void allDropTargetsInGroupHit (Field field, DropTargetGroupElement targetGroup) {
+ @Override
+ public void allDropTargetsInGroupHit (Field field, DropTargetGroupElement targetGroup) {
// activate ball saver for left and right groups
String id = targetGroup.getElementID();
if ("DropTargetLeftSave".equals(id)) {
@@ -54,18 +56,21 @@ void setLaunchBarrierEnabled (Field field, boolean enabled) {
barrier.setRetracted(!enabled);
}
- @Override public void ballInSensorRange (Field field, SensorElement sensor) {
+ @Override
+ public void ballInSensorRange (Field field, SensorElement sensor) {
// enable launch barrier
if ("LaunchBarrierSensor".equals(sensor.getElementID())) {
setLaunchBarrierEnabled(field, true);
}
}
- @Override public void gameStarted (Field field) {
+ @Override
+ public void gameStarted (Field field) {
setLaunchBarrierEnabled(field, false);
}
- @Override public void ballLost (Field field) {
+ @Override
+ public void ballLost (Field field) {
setLaunchBarrierEnabled(field, false);
}
diff --git a/demos/vector-pinball/gdx-vectorpinball/src/com/dozingcatsoftware/bouncy/util/JSONArray.java b/demos/vector-pinball/gdx-vectorpinball/src/com/dozingcatsoftware/bouncy/util/JSONArray.java
index 1c63998d9f6..2fa3ec3d198 100644
--- a/demos/vector-pinball/gdx-vectorpinball/src/com/dozingcatsoftware/bouncy/util/JSONArray.java
+++ b/demos/vector-pinball/gdx-vectorpinball/src/com/dozingcatsoftware/bouncy/util/JSONArray.java
@@ -1,28 +1,29 @@
+
package com.dozingcatsoftware.bouncy.util;
/*
-Copyright (c) 2002 JSON.org
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in all
-copies or substantial portions of the Software.
-
-The Software shall be used for Good, not Evil.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
-SOFTWARE.
-*/
+ Copyright (c) 2002 JSON.org
+
+ Permission is hereby granted, free of charge, to any person obtaining a copy
+ of this software and associated documentation files (the "Software"), to deal
+ in the Software without restriction, including without limitation the rights
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ copies of the Software, and to permit persons to whom the Software is
+ furnished to do so, subject to the following conditions:
+
+ The above copyright notice and this permission notice shall be included in all
+ copies or substantial portions of the Software.
+
+ The Software shall be used for Good, not Evil.
+
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ SOFTWARE.
+ */
import java.io.IOException;
import java.io.Writer;
@@ -32,885 +33,648 @@ of this software and associated documentation files (the "Software"), to deal
import java.util.Iterator;
import java.util.Map;
-/**
- * A JSONArray is an ordered sequence of values. Its external text form is a
- * string wrapped in square brackets with commas separating the values. The
- * internal form is an object having get
and opt
- * methods for accessing the values by index, and put
methods for
- * adding or replacing values. The values can be any of these types:
- * Boolean
, JSONArray
, JSONObject
,
- * Number
, String
, or the
+/** A JSONArray is an ordered sequence of values. Its external text form is a string wrapped in square brackets with commas
+ * separating the values. The internal form is an object having get
and opt
methods for accessing the
+ * values by index, and put
methods for adding or replacing values. The values can be any of these types:
+ * Boolean
, JSONArray
, JSONObject
, Number
, String
, or the
* JSONObject.NULL object
.
*
- * The constructor can convert a JSON text into a Java object. The
- * toString
method converts to JSON text.
+ * The constructor can convert a JSON text into a Java object. The toString
method converts to JSON text.
*
- * A get
method returns a value if one can be found, and throws an
- * exception if one cannot be found. An opt
method returns a
- * default value instead of throwing an exception, and so is useful for
- * obtaining optional values.
+ * A get
method returns a value if one can be found, and throws an exception if one cannot be found. An
+ * opt
method returns a default value instead of throwing an exception, and so is useful for obtaining optional
+ * values.
*
- * The generic get()
and opt()
methods return an
- * object which you can cast or query for type. There are also typed
- * get
and opt
methods that do type checking and type
- * coercion for you.
+ * The generic get()
and opt()
methods return an object which you can cast or query for type. There are
+ * also typed get
and opt
methods that do type checking and type coercion for you.
*
- * The texts produced by the toString
methods strictly conform to
- * JSON syntax rules. The constructors are more forgiving in the texts they will
- * accept:
+ * The texts produced by the toString
methods strictly conform to JSON syntax rules. The constructors are more
+ * forgiving in the texts they will accept:
*
- * An extra ,
(comma) may appear just
- * before the closing bracket.
- * The null
value will be inserted when there
- * is ,
(comma) elision.
- * Strings may be quoted with '
(single
- * quote) .
- * Strings do not need to be quoted at all if they do not begin with a quote
- * or single quote, and if they do not contain leading or trailing spaces,
- * and if they do not contain any of these characters:
- * { } [ ] / \ : , = ; #
and if they do not look like numbers
- * and if they are not the reserved words true
,
- * false
, or null
.
- * Values can be separated by ;
(semicolon) as
- * well as by ,
(comma) .
- * Numbers may have the
- * 0x-
(hex) prefix.
+ * An extra ,
(comma) may appear just before the closing bracket.
+ * The null
value will be inserted when there is ,
(comma) elision.
+ * Strings may be quoted with '
(single quote) .
+ * Strings do not need to be quoted at all if they do not begin with a quote or single quote, and if they do not contain
+ * leading or trailing spaces, and if they do not contain any of these characters: { } [ ] / \ : , = ; #
and if they
+ * do not look like numbers and if they are not the reserved words true
, false
, or null
.
+ * Values can be separated by ;
(semicolon) as well as by ,
(comma) .
+ * Numbers may have the 0x-
(hex) prefix.
*
-
+ *
* @author JSON.org
- * @version 2010-12-28
- */
+ * @version 2010-12-28 */
public class JSONArray {
+ /** The arrayList where the JSONArray's properties are kept. */
+ private ArrayList myArrayList;
- /**
- * The arrayList where the JSONArray's properties are kept.
- */
- private ArrayList myArrayList;
-
-
- /**
- * Construct an empty JSONArray.
- */
- public JSONArray() {
- this.myArrayList = new ArrayList();
- }
-
- /**
- * Construct a JSONArray from a JSONTokener.
- * @param x A JSONTokener
- * @throws JSONException If there is a syntax error.
- */
- public JSONArray(JSONTokener x) throws JSONException {
- this();
- if (x.nextClean() != '[') {
- throw x.syntaxError("A JSONArray text must start with '['");
- }
- if (x.nextClean() != ']') {
- x.back();
- for (;;) {
- if (x.nextClean() == ',') {
- x.back();
- this.myArrayList.add(JSONObject.NULL);
- } else {
- x.back();
- this.myArrayList.add(x.nextValue());
- }
- switch (x.nextClean()) {
- case ';':
- case ',':
- if (x.nextClean() == ']') {
- return;
- }
- x.back();
- break;
- case ']':
- return;
- default:
- throw x.syntaxError("Expected a ',' or ']'");
- }
- }
- }
- }
-
-
- /**
- * Construct a JSONArray from a source JSON text.
- * @param source A string that begins with
- * [
(left bracket)
- * and ends with ]
(right bracket) .
- * @throws JSONException If there is a syntax error.
- */
- public JSONArray(String source) throws JSONException {
- this(new JSONTokener(source));
- }
-
-
- /**
- * Construct a JSONArray from a Collection.
- * @param collection A Collection.
- */
- public JSONArray(Collection collection) {
+ /** Construct an empty JSONArray. */
+ public JSONArray () {
+ this.myArrayList = new ArrayList();
+ }
+
+ /** Construct a JSONArray from a JSONTokener.
+ * @param x A JSONTokener
+ * @throws JSONException If there is a syntax error. */
+ public JSONArray (JSONTokener x) throws JSONException {
+ this();
+ if (x.nextClean() != '[') {
+ throw x.syntaxError("A JSONArray text must start with '['");
+ }
+ if (x.nextClean() != ']') {
+ x.back();
+ for (;;) {
+ if (x.nextClean() == ',') {
+ x.back();
+ this.myArrayList.add(JSONObject.NULL);
+ } else {
+ x.back();
+ this.myArrayList.add(x.nextValue());
+ }
+ switch (x.nextClean()) {
+ case ';':
+ case ',':
+ if (x.nextClean() == ']') {
+ return;
+ }
+ x.back();
+ break;
+ case ']':
+ return;
+ default:
+ throw x.syntaxError("Expected a ',' or ']'");
+ }
+ }
+ }
+ }
+
+ /** Construct a JSONArray from a source JSON text.
+ * @param source A string that begins with [
(left bracket) and ends with ]
+ * (right bracket) .
+ * @throws JSONException If there is a syntax error. */
+ public JSONArray (String source) throws JSONException {
+ this(new JSONTokener(source));
+ }
+
+ /** Construct a JSONArray from a Collection.
+ * @param collection A Collection. */
+ public JSONArray (Collection collection) {
this.myArrayList = new ArrayList();
if (collection != null) {
Iterator iter = collection.iterator();
while (iter.hasNext()) {
- this.myArrayList.add(JSONObject.wrap(iter.next()));
+ this.myArrayList.add(JSONObject.wrap(iter.next()));
+ }
+ }
+ }
+
+ /** Construct a JSONArray from an array
+ * @throws JSONException If not an array. */
+ public JSONArray (Object array) throws JSONException {
+ this();
+ if (array.getClass().isArray()) {
+ int length = Array.getLength(array);
+ for (int i = 0; i < length; i += 1) {
+ this.put(JSONObject.wrap(Array.get(array, i)));
+ }
+ } else {
+ throw new JSONException("JSONArray initial value should be a string or collection or array.");
+ }
+ }
+
+ /** Get the object value associated with an index.
+ * @param index The index must be between 0 and length() - 1.
+ * @return An object value.
+ * @throws JSONException If there is no value for the index. */
+ public Object get (int index) throws JSONException {
+ Object object = opt(index);
+ if (object == null) {
+ throw new JSONException("JSONArray[" + index + "] not found.");
+ }
+ return object;
+ }
+
+ /** Get the boolean value associated with an index. The string values "true" and "false" are converted to boolean.
+ *
+ * @param index The index must be between 0 and length() - 1.
+ * @return The truth.
+ * @throws JSONException If there is no value for the index or if the value is not convertible to boolean. */
+ public boolean getBoolean (int index) throws JSONException {
+ Object object = get(index);
+ if (object.equals(Boolean.FALSE) || (object instanceof String && ((String)object).equalsIgnoreCase("false"))) {
+ return false;
+ } else if (object.equals(Boolean.TRUE) || (object instanceof String && ((String)object).equalsIgnoreCase("true"))) {
+ return true;
+ }
+ throw new JSONException("JSONArray[" + index + "] is not a boolean.");
+ }
+
+ /** Get the double value associated with an index.
+ *
+ * @param index The index must be between 0 and length() - 1.
+ * @return The value.
+ * @throws JSONException If the key is not found or if the value cannot be converted to a number. */
+ public double getDouble (int index) throws JSONException {
+ Object object = get(index);
+ try {
+ return object instanceof Number ? ((Number)object).doubleValue() : Double.parseDouble((String)object);
+ } catch (Exception e) {
+ throw new JSONException("JSONArray[" + index + "] is not a number.");
+ }
+ }
+
+ /** Get the int value associated with an index.
+ *
+ * @param index The index must be between 0 and length() - 1.
+ * @return The value.
+ * @throws JSONException If the key is not found or if the value is not a number. */
+ public int getInt (int index) throws JSONException {
+ Object object = get(index);
+ try {
+ return object instanceof Number ? ((Number)object).intValue() : Integer.parseInt((String)object);
+ } catch (Exception e) {
+ throw new JSONException("JSONArray[" + index + "] is not a number.");
+ }
+ }
+
+ /** Get the JSONArray associated with an index.
+ * @param index The index must be between 0 and length() - 1.
+ * @return A JSONArray value.
+ * @throws JSONException If there is no value for the index. or if the value is not a JSONArray */
+ public JSONArray getJSONArray (int index) throws JSONException {
+ Object object = get(index);
+ if (object instanceof JSONArray) {
+ return (JSONArray)object;
+ }
+ throw new JSONException("JSONArray[" + index + "] is not a JSONArray.");
+ }
+
+ /** Get the JSONObject associated with an index.
+ * @param index subscript
+ * @return A JSONObject value.
+ * @throws JSONException If there is no value for the index or if the value is not a JSONObject */
+ public JSONObject getJSONObject (int index) throws JSONException {
+ Object object = get(index);
+ if (object instanceof JSONObject) {
+ return (JSONObject)object;
+ }
+ throw new JSONException("JSONArray[" + index + "] is not a JSONObject.");
+ }
+
+ /** Get the long value associated with an index.
+ *
+ * @param index The index must be between 0 and length() - 1.
+ * @return The value.
+ * @throws JSONException If the key is not found or if the value cannot be converted to a number. */
+ public long getLong (int index) throws JSONException {
+ Object object = get(index);
+ try {
+ return object instanceof Number ? ((Number)object).longValue() : Long.parseLong((String)object);
+ } catch (Exception e) {
+ throw new JSONException("JSONArray[" + index + "] is not a number.");
+ }
+ }
+
+ /** Get the string associated with an index.
+ * @param index The index must be between 0 and length() - 1.
+ * @return A string value.
+ * @throws JSONException If there is no value for the index. */
+ public String getString (int index) throws JSONException {
+ Object object = get(index);
+ return object == JSONObject.NULL ? null : object.toString();
+ }
+
+ /** Determine if the value is null.
+ * @param index The index must be between 0 and length() - 1.
+ * @return true if the value at the index is null, or if there is no value. */
+ public boolean isNull (int index) {
+ return JSONObject.NULL.equals(opt(index));
+ }
+
+ /** Make a string from the contents of this JSONArray. The separator
string is inserted between each element.
+ * Warning: This method assumes that the data structure is acyclical.
+ * @param separator A string that will be inserted between the elements.
+ * @return a string.
+ * @throws JSONException If the array contains an invalid number. */
+ public String join (String separator) throws JSONException {
+ int len = length();
+ StringBuffer sb = new StringBuffer();
+
+ for (int i = 0; i < len; i += 1) {
+ if (i > 0) {
+ sb.append(separator);
+ }
+ sb.append(JSONObject.valueToString(this.myArrayList.get(i)));
+ }
+ return sb.toString();
+ }
+
+ /** Get the number of elements in the JSONArray, included nulls.
+ *
+ * @return The length (or size). */
+ public int length () {
+ return this.myArrayList.size();
+ }
+
+ /** Get the optional object value associated with an index.
+ * @param index The index must be between 0 and length() - 1.
+ * @return An object value, or null if there is no object at that index. */
+ public Object opt (int index) {
+ return (index < 0 || index >= length()) ? null : this.myArrayList.get(index);
+ }
+
+ /** Get the optional boolean value associated with an index. It returns false if there is no value at that index, or if the
+ * value is not Boolean.TRUE or the String "true".
+ *
+ * @param index The index must be between 0 and length() - 1.
+ * @return The truth. */
+ public boolean optBoolean (int index) {
+ return optBoolean(index, false);
+ }
+
+ /** Get the optional boolean value associated with an index. It returns the defaultValue if there is no value at that index or
+ * if it is not a Boolean or the String "true" or "false" (case insensitive).
+ *
+ * @param index The index must be between 0 and length() - 1.
+ * @param defaultValue A boolean default.
+ * @return The truth. */
+ public boolean optBoolean (int index, boolean defaultValue) {
+ try {
+ return getBoolean(index);
+ } catch (Exception e) {
+ return defaultValue;
+ }
+ }
+
+ /** Get the optional double value associated with an index. NaN is returned if there is no value for the index, or if the value
+ * is not a number and cannot be converted to a number.
+ *
+ * @param index The index must be between 0 and length() - 1.
+ * @return The value. */
+ public double optDouble (int index) {
+ return optDouble(index, Double.NaN);
+ }
+
+ /** Get the optional double value associated with an index. The defaultValue is returned if there is no value for the index, or
+ * if the value is not a number and cannot be converted to a number.
+ *
+ * @param index subscript
+ * @param defaultValue The default value.
+ * @return The value. */
+ public double optDouble (int index, double defaultValue) {
+ try {
+ return getDouble(index);
+ } catch (Exception e) {
+ return defaultValue;
+ }
+ }
+
+ /** Get the optional int value associated with an index. Zero is returned if there is no value for the index, or if the value is
+ * not a number and cannot be converted to a number.
+ *
+ * @param index The index must be between 0 and length() - 1.
+ * @return The value. */
+ public int optInt (int index) {
+ return optInt(index, 0);
+ }
+
+ /** Get the optional int value associated with an index. The defaultValue is returned if there is no value for the index, or if
+ * the value is not a number and cannot be converted to a number.
+ * @param index The index must be between 0 and length() - 1.
+ * @param defaultValue The default value.
+ * @return The value. */
+ public int optInt (int index, int defaultValue) {
+ try {
+ return getInt(index);
+ } catch (Exception e) {
+ return defaultValue;
+ }
+ }
+
+ /** Get the optional JSONArray associated with an index.
+ * @param index subscript
+ * @return A JSONArray value, or null if the index has no value, or if the value is not a JSONArray. */
+ public JSONArray optJSONArray (int index) {
+ Object o = opt(index);
+ return o instanceof JSONArray ? (JSONArray)o : null;
+ }
+
+ /** Get the optional JSONObject associated with an index. Null is returned if the key is not found, or null if the index has no
+ * value, or if the value is not a JSONObject.
+ *
+ * @param index The index must be between 0 and length() - 1.
+ * @return A JSONObject value. */
+ public JSONObject optJSONObject (int index) {
+ Object o = opt(index);
+ return o instanceof JSONObject ? (JSONObject)o : null;
+ }
+
+ /** Get the optional long value associated with an index. Zero is returned if there is no value for the index, or if the value
+ * is not a number and cannot be converted to a number.
+ *
+ * @param index The index must be between 0 and length() - 1.
+ * @return The value. */
+ public long optLong (int index) {
+ return optLong(index, 0);
+ }
+
+ /** Get the optional long value associated with an index. The defaultValue is returned if there is no value for the index, or if
+ * the value is not a number and cannot be converted to a number.
+ * @param index The index must be between 0 and length() - 1.
+ * @param defaultValue The default value.
+ * @return The value. */
+ public long optLong (int index, long defaultValue) {
+ try {
+ return getLong(index);
+ } catch (Exception e) {
+ return defaultValue;
+ }
+ }
+
+ /** Get the optional string value associated with an index. It returns an empty string if there is no value at that index. If
+ * the value is not a string and is not null, then it is coverted to a string.
+ *
+ * @param index The index must be between 0 and length() - 1.
+ * @return A String value. */
+ public String optString (int index) {
+ return optString(index, "");
+ }
+
+ /** Get the optional string associated with an index. The defaultValue is returned if the key is not found.
+ *
+ * @param index The index must be between 0 and length() - 1.
+ * @param defaultValue The default value.
+ * @return A String value. */
+ public String optString (int index, String defaultValue) {
+ Object object = opt(index);
+ return object != null ? object.toString() : defaultValue;
+ }
+
+ /** Append a boolean value. This increases the array's length by one.
+ *
+ * @param value A boolean value.
+ * @return this. */
+ public JSONArray put (boolean value) {
+ put(value ? Boolean.TRUE : Boolean.FALSE);
+ return this;
+ }
+
+ /** Put a value in the JSONArray, where the value will be a JSONArray which is produced from a Collection.
+ * @param value A Collection value.
+ * @return this. */
+ public JSONArray put (Collection value) {
+ put(new JSONArray(value));
+ return this;
+ }
+
+ /** Append a double value. This increases the array's length by one.
+ *
+ * @param value A double value.
+ * @throws JSONException if the value is not finite.
+ * @return this. */
+ public JSONArray put (double value) throws JSONException {
+ Double d = new Double(value);
+ JSONObject.testValidity(d);
+ put(d);
+ return this;
+ }
+
+ /** Append an int value. This increases the array's length by one.
+ *
+ * @param value An int value.
+ * @return this. */
+ public JSONArray put (int value) {
+ put(new Integer(value));
+ return this;
+ }
+
+ /** Append an long value. This increases the array's length by one.
+ *
+ * @param value A long value.
+ * @return this. */
+ public JSONArray put (long value) {
+ put(new Long(value));
+ return this;
+ }
+
+ /** Put a value in the JSONArray, where the value will be a JSONObject which is produced from a Map.
+ * @param value A Map value.
+ * @return this. */
+ public JSONArray put (Map value) {
+ put(new JSONObject(value));
+ return this;
+ }
+
+ /** Append an object value. This increases the array's length by one.
+ * @param value An object value. The value should be a Boolean, Double, Integer, JSONArray, JSONObject, Long, or String, or the
+ * JSONObject.NULL object.
+ * @return this. */
+ public JSONArray put (Object value) {
+ this.myArrayList.add(value);
+ return this;
+ }
+
+ /** Put or replace a boolean value in the JSONArray. If the index is greater than the length of the JSONArray, then null
+ * elements will be added as necessary to pad it out.
+ * @param index The subscript.
+ * @param value A boolean value.
+ * @return this.
+ * @throws JSONException If the index is negative. */
+ public JSONArray put (int index, boolean value) throws JSONException {
+ put(index, value ? Boolean.TRUE : Boolean.FALSE);
+ return this;
+ }
+
+ /** Put a value in the JSONArray, where the value will be a JSONArray which is produced from a Collection.
+ * @param index The subscript.
+ * @param value A Collection value.
+ * @return this.
+ * @throws JSONException If the index is negative or if the value is not finite. */
+ public JSONArray put (int index, Collection value) throws JSONException {
+ put(index, new JSONArray(value));
+ return this;
+ }
+
+ /** Put or replace a double value. If the index is greater than the length of the JSONArray, then null elements will be added as
+ * necessary to pad it out.
+ * @param index The subscript.
+ * @param value A double value.
+ * @return this.
+ * @throws JSONException If the index is negative or if the value is not finite. */
+ public JSONArray put (int index, double value) throws JSONException {
+ put(index, new Double(value));
+ return this;
+ }
+
+ /** Put or replace an int value. If the index is greater than the length of the JSONArray, then null elements will be added as
+ * necessary to pad it out.
+ * @param index The subscript.
+ * @param value An int value.
+ * @return this.
+ * @throws JSONException If the index is negative. */
+ public JSONArray put (int index, int value) throws JSONException {
+ put(index, new Integer(value));
+ return this;
+ }
+
+ /** Put or replace a long value. If the index is greater than the length of the JSONArray, then null elements will be added as
+ * necessary to pad it out.
+ * @param index The subscript.
+ * @param value A long value.
+ * @return this.
+ * @throws JSONException If the index is negative. */
+ public JSONArray put (int index, long value) throws JSONException {
+ put(index, new Long(value));
+ return this;
+ }
+
+ /** Put a value in the JSONArray, where the value will be a JSONObject which is produced from a Map.
+ * @param index The subscript.
+ * @param value The Map value.
+ * @return this.
+ * @throws JSONException If the index is negative or if the the value is an invalid number. */
+ public JSONArray put (int index, Map value) throws JSONException {
+ put(index, new JSONObject(value));
+ return this;
+ }
+
+ /** Put or replace an object value in the JSONArray. If the index is greater than the length of the JSONArray, then null
+ * elements will be added as necessary to pad it out.
+ * @param index The subscript.
+ * @param value The value to put into the array. The value should be a Boolean, Double, Integer, JSONArray, JSONObject, Long,
+ * or String, or the JSONObject.NULL object.
+ * @return this.
+ * @throws JSONException If the index is negative or if the the value is an invalid number. */
+ public JSONArray put (int index, Object value) throws JSONException {
+ JSONObject.testValidity(value);
+ if (index < 0) {
+ throw new JSONException("JSONArray[" + index + "] not found.");
+ }
+ if (index < length()) {
+ this.myArrayList.set(index, value);
+ } else {
+ while (index != length()) {
+ put(JSONObject.NULL);
+ }
+ put(value);
+ }
+ return this;
+ }
+
+ /** Remove an index and close the hole.
+ * @param index The index of the element to be removed.
+ * @return The value that was associated with the index, or null if there was no value. */
+ public Object remove (int index) {
+ Object o = opt(index);
+ this.myArrayList.remove(index);
+ return o;
+ }
+
+ /** Produce a JSONObject by combining a JSONArray of names with the values of this JSONArray.
+ * @param names A JSONArray containing a list of key strings. These will be paired with the values.
+ * @return A JSONObject, or null if there are no names or if this JSONArray has no values.
+ * @throws JSONException If any of the names are null. */
+ public JSONObject toJSONObject (JSONArray names) throws JSONException {
+ if (names == null || names.length() == 0 || length() == 0) {
+ return null;
+ }
+ JSONObject jo = new JSONObject();
+ for (int i = 0; i < names.length(); i += 1) {
+ jo.put(names.getString(i), this.opt(i));
+ }
+ return jo;
+ }
+
+ /** Make a JSON text of this JSONArray. For compactness, no unnecessary whitespace is added. If it is not possible to produce a
+ * syntactically correct JSON text then null will be returned instead. This could occur if the array contains an invalid
+ * number.
+ *
+ * Warning: This method assumes that the data structure is acyclical.
+ *
+ * @return a printable, displayable, transmittable representation of the array. */
+ public String toString () {
+ try {
+ return '[' + join(",") + ']';
+ } catch (Exception e) {
+ return null;
+ }
+ }
+
+ /** Make a prettyprinted JSON text of this JSONArray. Warning: This method assumes that the data structure is acyclical.
+ * @param indentFactor The number of spaces to add to each level of indentation.
+ * @return a printable, displayable, transmittable representation of the object, beginning with [
+ * (left bracket) and ending with ]
(right bracket) .
+ * @throws JSONException */
+ public String toString (int indentFactor) throws JSONException {
+ return toString(indentFactor, 0);
+ }
+
+ /** Make a prettyprinted JSON text of this JSONArray. Warning: This method assumes that the data structure is acyclical.
+ * @param indentFactor The number of spaces to add to each level of indentation.
+ * @param indent The indention of the top level.
+ * @return a printable, displayable, transmittable representation of the array.
+ * @throws JSONException */
+ String toString (int indentFactor, int indent) throws JSONException {
+ int len = length();
+ if (len == 0) {
+ return "[]";
+ }
+ int i;
+ StringBuffer sb = new StringBuffer("[");
+ if (len == 1) {
+ sb.append(JSONObject.valueToString(this.myArrayList.get(0), indentFactor, indent));
+ } else {
+ int newindent = indent + indentFactor;
+ sb.append('\n');
+ for (i = 0; i < len; i += 1) {
+ if (i > 0) {
+ sb.append(",\n");
+ }
+ for (int j = 0; j < newindent; j += 1) {
+ sb.append(' ');
+ }
+ sb.append(JSONObject.valueToString(this.myArrayList.get(i), indentFactor, newindent));
+ }
+ sb.append('\n');
+ for (i = 0; i < indent; i += 1) {
+ sb.append(' ');
+ }
+ }
+ sb.append(']');
+ return sb.toString();
+ }
+
+ /** Write the contents of the JSONArray as JSON text to a writer. For compactness, no whitespace is added.
+ *
+ * Warning: This method assumes that the data structure is acyclical.
+ *
+ * @return The writer.
+ * @throws JSONException */
+ public Writer write (Writer writer) throws JSONException {
+ try {
+ boolean b = false;
+ int len = length();
+
+ writer.write('[');
+
+ for (int i = 0; i < len; i += 1) {
+ if (b) {
+ writer.write(',');
+ }
+ Object v = this.myArrayList.get(i);
+ if (v instanceof JSONObject) {
+ ((JSONObject)v).write(writer);
+ } else if (v instanceof JSONArray) {
+ ((JSONArray)v).write(writer);
+ } else {
+ writer.write(JSONObject.valueToString(v));
+ }
+ b = true;
}
+ writer.write(']');
+ return writer;
+ } catch (IOException e) {
+ throw new JSONException(e);
}
- }
-
-
- /**
- * Construct a JSONArray from an array
- * @throws JSONException If not an array.
- */
- public JSONArray(Object array) throws JSONException {
- this();
- if (array.getClass().isArray()) {
- int length = Array.getLength(array);
- for (int i = 0; i < length; i += 1) {
- this.put(JSONObject.wrap(Array.get(array, i)));
- }
- } else {
- throw new JSONException(
-"JSONArray initial value should be a string or collection or array.");
- }
- }
-
-
- /**
- * Get the object value associated with an index.
- * @param index
- * The index must be between 0 and length() - 1.
- * @return An object value.
- * @throws JSONException If there is no value for the index.
- */
- public Object get(int index) throws JSONException {
- Object object = opt(index);
- if (object == null) {
- throw new JSONException("JSONArray[" + index + "] not found.");
- }
- return object;
- }
-
-
- /**
- * Get the boolean value associated with an index.
- * The string values "true" and "false" are converted to boolean.
- *
- * @param index The index must be between 0 and length() - 1.
- * @return The truth.
- * @throws JSONException If there is no value for the index or if the
- * value is not convertible to boolean.
- */
- public boolean getBoolean(int index) throws JSONException {
- Object object = get(index);
- if (object.equals(Boolean.FALSE) ||
- (object instanceof String &&
- ((String)object).equalsIgnoreCase("false"))) {
- return false;
- } else if (object.equals(Boolean.TRUE) ||
- (object instanceof String &&
- ((String)object).equalsIgnoreCase("true"))) {
- return true;
- }
- throw new JSONException("JSONArray[" + index + "] is not a boolean.");
- }
-
-
- /**
- * Get the double value associated with an index.
- *
- * @param index The index must be between 0 and length() - 1.
- * @return The value.
- * @throws JSONException If the key is not found or if the value cannot
- * be converted to a number.
- */
- public double getDouble(int index) throws JSONException {
- Object object = get(index);
- try {
- return object instanceof Number ?
- ((Number)object).doubleValue() :
- Double.parseDouble((String)object);
- } catch (Exception e) {
- throw new JSONException("JSONArray[" + index +
- "] is not a number.");
- }
- }
-
-
- /**
- * Get the int value associated with an index.
- *
- * @param index The index must be between 0 and length() - 1.
- * @return The value.
- * @throws JSONException If the key is not found or if the value is not a number.
- */
- public int getInt(int index) throws JSONException {
- Object object = get(index);
- try {
- return object instanceof Number ?
- ((Number)object).intValue() :
- Integer.parseInt((String)object);
- } catch (Exception e) {
- throw new JSONException("JSONArray[" + index +
- "] is not a number.");
- }
- }
-
-
- /**
- * Get the JSONArray associated with an index.
- * @param index The index must be between 0 and length() - 1.
- * @return A JSONArray value.
- * @throws JSONException If there is no value for the index. or if the
- * value is not a JSONArray
- */
- public JSONArray getJSONArray(int index) throws JSONException {
- Object object = get(index);
- if (object instanceof JSONArray) {
- return (JSONArray)object;
- }
- throw new JSONException("JSONArray[" + index +
- "] is not a JSONArray.");
- }
-
-
- /**
- * Get the JSONObject associated with an index.
- * @param index subscript
- * @return A JSONObject value.
- * @throws JSONException If there is no value for the index or if the
- * value is not a JSONObject
- */
- public JSONObject getJSONObject(int index) throws JSONException {
- Object object = get(index);
- if (object instanceof JSONObject) {
- return (JSONObject)object;
- }
- throw new JSONException("JSONArray[" + index +
- "] is not a JSONObject.");
- }
-
-
- /**
- * Get the long value associated with an index.
- *
- * @param index The index must be between 0 and length() - 1.
- * @return The value.
- * @throws JSONException If the key is not found or if the value cannot
- * be converted to a number.
- */
- public long getLong(int index) throws JSONException {
- Object object = get(index);
- try {
- return object instanceof Number ?
- ((Number)object).longValue() :
- Long.parseLong((String)object);
- } catch (Exception e) {
- throw new JSONException("JSONArray[" + index +
- "] is not a number.");
- }
- }
-
-
- /**
- * Get the string associated with an index.
- * @param index The index must be between 0 and length() - 1.
- * @return A string value.
- * @throws JSONException If there is no value for the index.
- */
- public String getString(int index) throws JSONException {
- Object object = get(index);
- return object == JSONObject.NULL ? null : object.toString();
- }
-
-
- /**
- * Determine if the value is null.
- * @param index The index must be between 0 and length() - 1.
- * @return true if the value at the index is null, or if there is no value.
- */
- public boolean isNull(int index) {
- return JSONObject.NULL.equals(opt(index));
- }
-
-
- /**
- * Make a string from the contents of this JSONArray. The
- * separator
string is inserted between each element.
- * Warning: This method assumes that the data structure is acyclical.
- * @param separator A string that will be inserted between the elements.
- * @return a string.
- * @throws JSONException If the array contains an invalid number.
- */
- public String join(String separator) throws JSONException {
- int len = length();
- StringBuffer sb = new StringBuffer();
-
- for (int i = 0; i < len; i += 1) {
- if (i > 0) {
- sb.append(separator);
- }
- sb.append(JSONObject.valueToString(this.myArrayList.get(i)));
- }
- return sb.toString();
- }
-
-
- /**
- * Get the number of elements in the JSONArray, included nulls.
- *
- * @return The length (or size).
- */
- public int length() {
- return this.myArrayList.size();
- }
-
-
- /**
- * Get the optional object value associated with an index.
- * @param index The index must be between 0 and length() - 1.
- * @return An object value, or null if there is no
- * object at that index.
- */
- public Object opt(int index) {
- return (index < 0 || index >= length()) ?
- null : this.myArrayList.get(index);
- }
-
-
- /**
- * Get the optional boolean value associated with an index.
- * It returns false if there is no value at that index,
- * or if the value is not Boolean.TRUE or the String "true".
- *
- * @param index The index must be between 0 and length() - 1.
- * @return The truth.
- */
- public boolean optBoolean(int index) {
- return optBoolean(index, false);
- }
-
-
- /**
- * Get the optional boolean value associated with an index.
- * It returns the defaultValue if there is no value at that index or if
- * it is not a Boolean or the String "true" or "false" (case insensitive).
- *
- * @param index The index must be between 0 and length() - 1.
- * @param defaultValue A boolean default.
- * @return The truth.
- */
- public boolean optBoolean(int index, boolean defaultValue) {
- try {
- return getBoolean(index);
- } catch (Exception e) {
- return defaultValue;
- }
- }
-
-
- /**
- * Get the optional double value associated with an index.
- * NaN is returned if there is no value for the index,
- * or if the value is not a number and cannot be converted to a number.
- *
- * @param index The index must be between 0 and length() - 1.
- * @return The value.
- */
- public double optDouble(int index) {
- return optDouble(index, Double.NaN);
- }
-
-
- /**
- * Get the optional double value associated with an index.
- * The defaultValue is returned if there is no value for the index,
- * or if the value is not a number and cannot be converted to a number.
- *
- * @param index subscript
- * @param defaultValue The default value.
- * @return The value.
- */
- public double optDouble(int index, double defaultValue) {
- try {
- return getDouble(index);
- } catch (Exception e) {
- return defaultValue;
- }
- }
-
-
- /**
- * Get the optional int value associated with an index.
- * Zero is returned if there is no value for the index,
- * or if the value is not a number and cannot be converted to a number.
- *
- * @param index The index must be between 0 and length() - 1.
- * @return The value.
- */
- public int optInt(int index) {
- return optInt(index, 0);
- }
-
-
- /**
- * Get the optional int value associated with an index.
- * The defaultValue is returned if there is no value for the index,
- * or if the value is not a number and cannot be converted to a number.
- * @param index The index must be between 0 and length() - 1.
- * @param defaultValue The default value.
- * @return The value.
- */
- public int optInt(int index, int defaultValue) {
- try {
- return getInt(index);
- } catch (Exception e) {
- return defaultValue;
- }
- }
-
-
- /**
- * Get the optional JSONArray associated with an index.
- * @param index subscript
- * @return A JSONArray value, or null if the index has no value,
- * or if the value is not a JSONArray.
- */
- public JSONArray optJSONArray(int index) {
- Object o = opt(index);
- return o instanceof JSONArray ? (JSONArray)o : null;
- }
-
-
- /**
- * Get the optional JSONObject associated with an index.
- * Null is returned if the key is not found, or null if the index has
- * no value, or if the value is not a JSONObject.
- *
- * @param index The index must be between 0 and length() - 1.
- * @return A JSONObject value.
- */
- public JSONObject optJSONObject(int index) {
- Object o = opt(index);
- return o instanceof JSONObject ? (JSONObject)o : null;
- }
-
-
- /**
- * Get the optional long value associated with an index.
- * Zero is returned if there is no value for the index,
- * or if the value is not a number and cannot be converted to a number.
- *
- * @param index The index must be between 0 and length() - 1.
- * @return The value.
- */
- public long optLong(int index) {
- return optLong(index, 0);
- }
-
-
- /**
- * Get the optional long value associated with an index.
- * The defaultValue is returned if there is no value for the index,
- * or if the value is not a number and cannot be converted to a number.
- * @param index The index must be between 0 and length() - 1.
- * @param defaultValue The default value.
- * @return The value.
- */
- public long optLong(int index, long defaultValue) {
- try {
- return getLong(index);
- } catch (Exception e) {
- return defaultValue;
- }
- }
-
-
- /**
- * Get the optional string value associated with an index. It returns an
- * empty string if there is no value at that index. If the value
- * is not a string and is not null, then it is coverted to a string.
- *
- * @param index The index must be between 0 and length() - 1.
- * @return A String value.
- */
- public String optString(int index) {
- return optString(index, "");
- }
-
-
- /**
- * Get the optional string associated with an index.
- * The defaultValue is returned if the key is not found.
- *
- * @param index The index must be between 0 and length() - 1.
- * @param defaultValue The default value.
- * @return A String value.
- */
- public String optString(int index, String defaultValue) {
- Object object = opt(index);
- return object != null ? object.toString() : defaultValue;
- }
-
-
- /**
- * Append a boolean value. This increases the array's length by one.
- *
- * @param value A boolean value.
- * @return this.
- */
- public JSONArray put(boolean value) {
- put(value ? Boolean.TRUE : Boolean.FALSE);
- return this;
- }
-
-
- /**
- * Put a value in the JSONArray, where the value will be a
- * JSONArray which is produced from a Collection.
- * @param value A Collection value.
- * @return this.
- */
- public JSONArray put(Collection value) {
- put(new JSONArray(value));
- return this;
- }
-
-
- /**
- * Append a double value. This increases the array's length by one.
- *
- * @param value A double value.
- * @throws JSONException if the value is not finite.
- * @return this.
- */
- public JSONArray put(double value) throws JSONException {
- Double d = new Double(value);
- JSONObject.testValidity(d);
- put(d);
- return this;
- }
-
-
- /**
- * Append an int value. This increases the array's length by one.
- *
- * @param value An int value.
- * @return this.
- */
- public JSONArray put(int value) {
- put(new Integer(value));
- return this;
- }
-
-
- /**
- * Append an long value. This increases the array's length by one.
- *
- * @param value A long value.
- * @return this.
- */
- public JSONArray put(long value) {
- put(new Long(value));
- return this;
- }
-
-
- /**
- * Put a value in the JSONArray, where the value will be a
- * JSONObject which is produced from a Map.
- * @param value A Map value.
- * @return this.
- */
- public JSONArray put(Map value) {
- put(new JSONObject(value));
- return this;
- }
-
-
- /**
- * Append an object value. This increases the array's length by one.
- * @param value An object value. The value should be a
- * Boolean, Double, Integer, JSONArray, JSONObject, Long, or String, or the
- * JSONObject.NULL object.
- * @return this.
- */
- public JSONArray put(Object value) {
- this.myArrayList.add(value);
- return this;
- }
-
-
- /**
- * Put or replace a boolean value in the JSONArray. If the index is greater
- * than the length of the JSONArray, then null elements will be added as
- * necessary to pad it out.
- * @param index The subscript.
- * @param value A boolean value.
- * @return this.
- * @throws JSONException If the index is negative.
- */
- public JSONArray put(int index, boolean value) throws JSONException {
- put(index, value ? Boolean.TRUE : Boolean.FALSE);
- return this;
- }
-
-
- /**
- * Put a value in the JSONArray, where the value will be a
- * JSONArray which is produced from a Collection.
- * @param index The subscript.
- * @param value A Collection value.
- * @return this.
- * @throws JSONException If the index is negative or if the value is
- * not finite.
- */
- public JSONArray put(int index, Collection value) throws JSONException {
- put(index, new JSONArray(value));
- return this;
- }
-
-
- /**
- * Put or replace a double value. If the index is greater than the length of
- * the JSONArray, then null elements will be added as necessary to pad
- * it out.
- * @param index The subscript.
- * @param value A double value.
- * @return this.
- * @throws JSONException If the index is negative or if the value is
- * not finite.
- */
- public JSONArray put(int index, double value) throws JSONException {
- put(index, new Double(value));
- return this;
- }
-
-
- /**
- * Put or replace an int value. If the index is greater than the length of
- * the JSONArray, then null elements will be added as necessary to pad
- * it out.
- * @param index The subscript.
- * @param value An int value.
- * @return this.
- * @throws JSONException If the index is negative.
- */
- public JSONArray put(int index, int value) throws JSONException {
- put(index, new Integer(value));
- return this;
- }
-
-
- /**
- * Put or replace a long value. If the index is greater than the length of
- * the JSONArray, then null elements will be added as necessary to pad
- * it out.
- * @param index The subscript.
- * @param value A long value.
- * @return this.
- * @throws JSONException If the index is negative.
- */
- public JSONArray put(int index, long value) throws JSONException {
- put(index, new Long(value));
- return this;
- }
-
-
- /**
- * Put a value in the JSONArray, where the value will be a
- * JSONObject which is produced from a Map.
- * @param index The subscript.
- * @param value The Map value.
- * @return this.
- * @throws JSONException If the index is negative or if the the value is
- * an invalid number.
- */
- public JSONArray put(int index, Map value) throws JSONException {
- put(index, new JSONObject(value));
- return this;
- }
-
-
- /**
- * Put or replace an object value in the JSONArray. If the index is greater
- * than the length of the JSONArray, then null elements will be added as
- * necessary to pad it out.
- * @param index The subscript.
- * @param value The value to put into the array. The value should be a
- * Boolean, Double, Integer, JSONArray, JSONObject, Long, or String, or the
- * JSONObject.NULL object.
- * @return this.
- * @throws JSONException If the index is negative or if the the value is
- * an invalid number.
- */
- public JSONArray put(int index, Object value) throws JSONException {
- JSONObject.testValidity(value);
- if (index < 0) {
- throw new JSONException("JSONArray[" + index + "] not found.");
- }
- if (index < length()) {
- this.myArrayList.set(index, value);
- } else {
- while (index != length()) {
- put(JSONObject.NULL);
- }
- put(value);
- }
- return this;
- }
-
-
- /**
- * Remove an index and close the hole.
- * @param index The index of the element to be removed.
- * @return The value that was associated with the index,
- * or null if there was no value.
- */
- public Object remove(int index) {
- Object o = opt(index);
- this.myArrayList.remove(index);
- return o;
- }
-
-
- /**
- * Produce a JSONObject by combining a JSONArray of names with the values
- * of this JSONArray.
- * @param names A JSONArray containing a list of key strings. These will be
- * paired with the values.
- * @return A JSONObject, or null if there are no names or if this JSONArray
- * has no values.
- * @throws JSONException If any of the names are null.
- */
- public JSONObject toJSONObject(JSONArray names) throws JSONException {
- if (names == null || names.length() == 0 || length() == 0) {
- return null;
- }
- JSONObject jo = new JSONObject();
- for (int i = 0; i < names.length(); i += 1) {
- jo.put(names.getString(i), this.opt(i));
- }
- return jo;
- }
-
-
- /**
- * Make a JSON text of this JSONArray. For compactness, no
- * unnecessary whitespace is added. If it is not possible to produce a
- * syntactically correct JSON text then null will be returned instead. This
- * could occur if the array contains an invalid number.
- *
- * Warning: This method assumes that the data structure is acyclical.
- *
- * @return a printable, displayable, transmittable
- * representation of the array.
- */
- public String toString() {
- try {
- return '[' + join(",") + ']';
- } catch (Exception e) {
- return null;
- }
- }
-
-
- /**
- * Make a prettyprinted JSON text of this JSONArray.
- * Warning: This method assumes that the data structure is acyclical.
- * @param indentFactor The number of spaces to add to each level of
- * indentation.
- * @return a printable, displayable, transmittable
- * representation of the object, beginning
- * with [
(left bracket) and ending
- * with ]
(right bracket) .
- * @throws JSONException
- */
- public String toString(int indentFactor) throws JSONException {
- return toString(indentFactor, 0);
- }
-
-
- /**
- * Make a prettyprinted JSON text of this JSONArray.
- * Warning: This method assumes that the data structure is acyclical.
- * @param indentFactor The number of spaces to add to each level of
- * indentation.
- * @param indent The indention of the top level.
- * @return a printable, displayable, transmittable
- * representation of the array.
- * @throws JSONException
- */
- String toString(int indentFactor, int indent) throws JSONException {
- int len = length();
- if (len == 0) {
- return "[]";
- }
- int i;
- StringBuffer sb = new StringBuffer("[");
- if (len == 1) {
- sb.append(JSONObject.valueToString(this.myArrayList.get(0),
- indentFactor, indent));
- } else {
- int newindent = indent + indentFactor;
- sb.append('\n');
- for (i = 0; i < len; i += 1) {
- if (i > 0) {
- sb.append(",\n");
- }
- for (int j = 0; j < newindent; j += 1) {
- sb.append(' ');
- }
- sb.append(JSONObject.valueToString(this.myArrayList.get(i),
- indentFactor, newindent));
- }
- sb.append('\n');
- for (i = 0; i < indent; i += 1) {
- sb.append(' ');
- }
- }
- sb.append(']');
- return sb.toString();
- }
-
-
- /**
- * Write the contents of the JSONArray as JSON text to a writer.
- * For compactness, no whitespace is added.
- *
- * Warning: This method assumes that the data structure is acyclical.
- *
- * @return The writer.
- * @throws JSONException
- */
- public Writer write(Writer writer) throws JSONException {
- try {
- boolean b = false;
- int len = length();
-
- writer.write('[');
-
- for (int i = 0; i < len; i += 1) {
- if (b) {
- writer.write(',');
- }
- Object v = this.myArrayList.get(i);
- if (v instanceof JSONObject) {
- ((JSONObject)v).write(writer);
- } else if (v instanceof JSONArray) {
- ((JSONArray)v).write(writer);
- } else {
- writer.write(JSONObject.valueToString(v));
- }
- b = true;
- }
- writer.write(']');
- return writer;
- } catch (IOException e) {
- throw new JSONException(e);
- }
- }
-}
\ No newline at end of file
+ }
+}
diff --git a/demos/vector-pinball/gdx-vectorpinball/src/com/dozingcatsoftware/bouncy/util/JSONException.java b/demos/vector-pinball/gdx-vectorpinball/src/com/dozingcatsoftware/bouncy/util/JSONException.java
index 7483d0bbbb9..58514f06185 100644
--- a/demos/vector-pinball/gdx-vectorpinball/src/com/dozingcatsoftware/bouncy/util/JSONException.java
+++ b/demos/vector-pinball/gdx-vectorpinball/src/com/dozingcatsoftware/bouncy/util/JSONException.java
@@ -1,28 +1,25 @@
+
package com.dozingcatsoftware.bouncy.util;
-/**
- * The JSONException is thrown by the JSON.org classes when things are amiss.
+/** The JSONException is thrown by the JSON.org classes when things are amiss.
* @author JSON.org
- * @version 2010-12-24
- */
+ * @version 2010-12-24 */
public class JSONException extends Exception {
private static final long serialVersionUID = 0;
private Throwable cause;
- /**
- * Constructs a JSONException with an explanatory message.
- * @param message Detail about the reason for the exception.
- */
- public JSONException(String message) {
- super(message);
- }
+ /** Constructs a JSONException with an explanatory message.
+ * @param message Detail about the reason for the exception. */
+ public JSONException (String message) {
+ super(message);
+ }
- public JSONException(Throwable cause) {
- super(cause.getMessage());
- this.cause = cause;
- }
+ public JSONException (Throwable cause) {
+ super(cause.getMessage());
+ this.cause = cause;
+ }
- public Throwable getCause() {
- return this.cause;
- }
+ public Throwable getCause () {
+ return this.cause;
+ }
}
diff --git a/demos/vector-pinball/gdx-vectorpinball/src/com/dozingcatsoftware/bouncy/util/JSONObject.java b/demos/vector-pinball/gdx-vectorpinball/src/com/dozingcatsoftware/bouncy/util/JSONObject.java
index de3ffde9f01..519023c5b3d 100644
--- a/demos/vector-pinball/gdx-vectorpinball/src/com/dozingcatsoftware/bouncy/util/JSONObject.java
+++ b/demos/vector-pinball/gdx-vectorpinball/src/com/dozingcatsoftware/bouncy/util/JSONObject.java
@@ -1,34 +1,35 @@
+
package com.dozingcatsoftware.bouncy.util;
/*
-Copyright (c) 2002 JSON.org
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in all
-copies or substantial portions of the Software.
-
-The Software shall be used for Good, not Evil.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
-SOFTWARE.
-*/
+ Copyright (c) 2002 JSON.org
+
+ Permission is hereby granted, free of charge, to any person obtaining a copy
+ of this software and associated documentation files (the "Software"), to deal
+ in the Software without restriction, including without limitation the rights
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ copies of the Software, and to permit persons to whom the Software is
+ furnished to do so, subject to the following conditions:
+
+ The above copyright notice and this permission notice shall be included in all
+ copies or substantial portions of the Software.
+
+ The Software shall be used for Good, not Evil.
+
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ SOFTWARE.
+ */
import java.io.IOException;
import java.io.Writer;
import java.lang.reflect.Field;
-import java.lang.reflect.Modifier;
import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
import java.util.Collection;
import java.util.Enumeration;
import java.util.HashMap;
@@ -37,1584 +38,1238 @@ of this software and associated documentation files (the "Software"), to deal
import java.util.Map;
import java.util.ResourceBundle;
-/**
- * A JSONObject is an unordered collection of name/value pairs. Its
- * external form is a string wrapped in curly braces with colons between the
- * names and values, and commas between the values and names. The internal form
- * is an object having get
and opt
methods for
- * accessing the values by name, and put
methods for adding or
- * replacing values by name. The values can be any of these types:
- * Boolean
, JSONArray
, JSONObject
,
- * Number
, String
, or the JSONObject.NULL
- * object. A JSONObject constructor can be used to convert an external form
- * JSON text into an internal form whose values can be retrieved with the
- * get
and opt
methods, or to convert values into a
- * JSON text using the put
and toString
methods.
- * A get
method returns a value if one can be found, and throws an
- * exception if one cannot be found. An opt
method returns a
- * default value instead of throwing an exception, and so is useful for
- * obtaining optional values.
+/** A JSONObject is an unordered collection of name/value pairs. Its external form is a string wrapped in curly braces with colons
+ * between the names and values, and commas between the values and names. The internal form is an object having get
+ * and opt
methods for accessing the values by name, and put
methods for adding or replacing values by
+ * name. The values can be any of these types: Boolean
, JSONArray
, JSONObject
,
+ * Number
, String
, or the JSONObject.NULL
object. A JSONObject constructor can be used to
+ * convert an external form JSON text into an internal form whose values can be retrieved with the get
and
+ * opt
methods, or to convert values into a JSON text using the put
and toString
methods. A
+ * get
method returns a value if one can be found, and throws an exception if one cannot be found. An
+ * opt
method returns a default value instead of throwing an exception, and so is useful for obtaining optional
+ * values.
*
- * The generic get()
and opt()
methods return an
- * object, which you can cast or query for type. There are also typed
- * get
and opt
methods that do type checking and type
- * coercion for you. The opt methods differ from the get methods in that they
- * do not throw. Instead, they return a specified value, such as null.
+ * The generic get()
and opt()
methods return an object, which you can cast or query for type. There are
+ * also typed get
and opt
methods that do type checking and type coercion for you. The opt methods
+ * differ from the get methods in that they do not throw. Instead, they return a specified value, such as null.
*
- * The put
methods add or replace values in an object. For example,
- *
myString = new JSONObject().put("JSON", "Hello, World!").toString();
+ * The put
methods add or replace values in an object. For example,
+ *
+ *
+ * myString = new JSONObject().put("JSON", "Hello, World!").toString();
+ *
+ *
* produces the string {"JSON": "Hello, World"}
.
*
- * The texts produced by the toString
methods strictly conform to
- * the JSON syntax rules.
- * The constructors are more forgiving in the texts they will accept:
+ * The texts produced by the toString
methods strictly conform to the JSON syntax rules. The constructors are more
+ * forgiving in the texts they will accept:
*
- * An extra ,
(comma) may appear just
- * before the closing brace.
- * Strings may be quoted with '
(single
- * quote) .
- * Strings do not need to be quoted at all if they do not begin with a quote
- * or single quote, and if they do not contain leading or trailing spaces,
- * and if they do not contain any of these characters:
- * { } [ ] / \ : , = ; #
and if they do not look like numbers
- * and if they are not the reserved words true
,
- * false
, or null
.
- * Keys can be followed by =
or =>
as well as
- * by :
.
- * Values can be followed by ;
(semicolon) as
- * well as by ,
(comma) .
+ * An extra ,
(comma) may appear just before the closing brace.
+ * Strings may be quoted with '
(single quote) .
+ * Strings do not need to be quoted at all if they do not begin with a quote or single quote, and if they do not contain
+ * leading or trailing spaces, and if they do not contain any of these characters: { } [ ] / \ : , = ; #
and if they
+ * do not look like numbers and if they are not the reserved words true
, false
, or null
.
+ * Keys can be followed by =
or =>
as well as by :
.
+ * Values can be followed by ;
(semicolon) as well as by ,
(comma) .
* Numbers may have the 0x-
(hex) prefix.
*
* @author JSON.org
- * @version 2011-01-31
- */
+ * @version 2011-01-31 */
public class JSONObject {
- /**
- * JSONObject.NULL is equivalent to the value that JavaScript calls null,
- * whilst Java's null is equivalent to the value that JavaScript calls
- * undefined.
- */
- private static final class Null {
-
- /**
- * There is only intended to be a single instance of the NULL object,
- * so the clone method returns itself.
- * @return NULL.
- */
- protected final Object clone() {
- return this;
- }
-
- /**
- * A Null object is equal to the null value and to itself.
- * @param object An object to test for nullness.
- * @return true if the object parameter is the JSONObject.NULL object
- * or null.
- */
- public boolean equals(Object object) {
- return object == null || object == this;
- }
-
- /**
- * Get the "null" string value.
- * @return The string "null".
- */
- public String toString() {
- return "null";
- }
- }
-
-
- /**
- * The map where the JSONObject's properties are kept.
- */
- private Map map;
-
-
- /**
- * It is sometimes more convenient and less ambiguous to have a
- * NULL
object than to use Java's null
value.
- * JSONObject.NULL.equals(null)
returns true
.
- * JSONObject.NULL.toString()
returns "null"
.
- */
- public static final Object NULL = new Null();
-
-
- /**
- * Construct an empty JSONObject.
- */
- public JSONObject() {
- this.map = new HashMap();
- }
-
-
- /**
- * Construct a JSONObject from a subset of another JSONObject.
- * An array of strings is used to identify the keys that should be copied.
- * Missing keys are ignored.
- * @param jo A JSONObject.
- * @param names An array of strings.
- * @throws JSONException
- * @exception JSONException If a value is a non-finite number or if a name is duplicated.
- */
- public JSONObject(JSONObject jo, String[] names) {
- this();
- for (int i = 0; i < names.length; i += 1) {
- try {
- putOnce(names[i], jo.opt(names[i]));
- } catch (Exception ignore) {
- }
- }
- }
-
-
- /**
- * Construct a JSONObject from a JSONTokener.
- * @param x A JSONTokener object containing the source string.
- * @throws JSONException If there is a syntax error in the source string
- * or a duplicated key.
- */
- public JSONObject(JSONTokener x) throws JSONException {
- this();
- char c;
- String key;
-
- if (x.nextClean() != '{') {
- throw x.syntaxError("A JSONObject text must begin with '{'");
- }
- for (;;) {
- c = x.nextClean();
- switch (c) {
- case 0:
- throw x.syntaxError("A JSONObject text must end with '}'");
- case '}':
- return;
- default:
- x.back();
- key = x.nextValue().toString();
- }
+ /** JSONObject.NULL is equivalent to the value that JavaScript calls null, whilst Java's null is equivalent to the value that
+ * JavaScript calls undefined. */
+ private static final class Null {
+
+ /** There is only intended to be a single instance of the NULL object, so the clone method returns itself.
+ * @return NULL. */
+ protected final Object clone () {
+ return this;
+ }
+
+ /** A Null object is equal to the null value and to itself.
+ * @param object An object to test for nullness.
+ * @return true if the object parameter is the JSONObject.NULL object or null. */
+ public boolean equals (Object object) {
+ return object == null || object == this;
+ }
+
+ /** Get the "null" string value.
+ * @return The string "null". */
+ public String toString () {
+ return "null";
+ }
+ }
+
+ /** The map where the JSONObject's properties are kept. */
+ private Map map;
+
+ /** It is sometimes more convenient and less ambiguous to have a NULL
object than to use Java's null
+ * value. JSONObject.NULL.equals(null)
returns true
. JSONObject.NULL.toString()
returns
+ * "null"
. */
+ public static final Object NULL = new Null();
+
+ /** Construct an empty JSONObject. */
+ public JSONObject () {
+ this.map = new HashMap();
+ }
+
+ /** Construct a JSONObject from a subset of another JSONObject. An array of strings is used to identify the keys that should be
+ * copied. Missing keys are ignored.
+ * @param jo A JSONObject.
+ * @param names An array of strings.
+ * @throws JSONException
+ * @exception JSONException If a value is a non-finite number or if a name is duplicated. */
+ public JSONObject (JSONObject jo, String[] names) {
+ this();
+ for (int i = 0; i < names.length; i += 1) {
+ try {
+ putOnce(names[i], jo.opt(names[i]));
+ } catch (Exception ignore) {
+ }
+ }
+ }
+
+ /** Construct a JSONObject from a JSONTokener.
+ * @param x A JSONTokener object containing the source string.
+ * @throws JSONException If there is a syntax error in the source string or a duplicated key. */
+ public JSONObject (JSONTokener x) throws JSONException {
+ this();
+ char c;
+ String key;
+
+ if (x.nextClean() != '{') {
+ throw x.syntaxError("A JSONObject text must begin with '{'");
+ }
+ for (;;) {
+ c = x.nextClean();
+ switch (c) {
+ case 0:
+ throw x.syntaxError("A JSONObject text must end with '}'");
+ case '}':
+ return;
+ default:
+ x.back();
+ key = x.nextValue().toString();
+ }
// The key is followed by ':'. We will also tolerate '=' or '=>'.
- c = x.nextClean();
- if (c == '=') {
- if (x.next() != '>') {
- x.back();
- }
- } else if (c != ':') {
- throw x.syntaxError("Expected a ':' after a key");
- }
- putOnce(key, x.nextValue());
+ c = x.nextClean();
+ if (c == '=') {
+ if (x.next() != '>') {
+ x.back();
+ }
+ } else if (c != ':') {
+ throw x.syntaxError("Expected a ':' after a key");
+ }
+ putOnce(key, x.nextValue());
// Pairs are separated by ','. We will also tolerate ';'.
- switch (x.nextClean()) {
- case ';':
- case ',':
- if (x.nextClean() == '}') {
- return;
- }
- x.back();
- break;
- case '}':
- return;
- default:
- throw x.syntaxError("Expected a ',' or '}'");
- }
- }
- }
-
-
- /**
- * Construct a JSONObject from a Map.
- *
- * @param map A map object that can be used to initialize the contents of
- * the JSONObject.
- * @throws JSONException
- */
- public JSONObject(Map map) {
- this.map = new HashMap();
- if (map != null) {
- Iterator i = map.entrySet().iterator();
- while (i.hasNext()) {
- Map.Entry e = (Map.Entry)i.next();
- Object value = e.getValue();
- if (value != null) {
- this.map.put(e.getKey(), wrap(value));
- }
- }
- }
- }
-
-
- /**
- * Construct a JSONObject from an Object using bean getters.
- * It reflects on all of the public methods of the object.
- * For each of the methods with no parameters and a name starting
- * with "get"
or "is"
followed by an uppercase letter,
- * the method is invoked, and a key and the value returned from the getter method
- * are put into the new JSONObject.
- *
- * The key is formed by removing the "get"
or "is"
prefix.
- * If the second remaining character is not upper case, then the first
- * character is converted to lower case.
- *
- * For example, if an object has a method named "getName"
, and
- * if the result of calling object.getName()
is "Larry Fine"
,
- * then the JSONObject will contain "name": "Larry Fine"
.
- *
- * @param bean An object that has getter methods that should be used
- * to make a JSONObject.
- */
- public JSONObject(Object bean) {
- this();
- populateMap(bean);
- }
-
-
- /**
- * Construct a JSONObject from an Object, using reflection to find the
- * public members. The resulting JSONObject's keys will be the strings
- * from the names array, and the values will be the field values associated
- * with those keys in the object. If a key is not found or not visible,
- * then it will not be copied into the new JSONObject.
- * @param object An object that has fields that should be used to make a
- * JSONObject.
- * @param names An array of strings, the names of the fields to be obtained
- * from the object.
- */
- public JSONObject(Object object, String names[]) {
- this();
- Class c = object.getClass();
- for (int i = 0; i < names.length; i += 1) {
- String name = names[i];
- try {
- putOpt(name, c.getField(name).get(object));
- } catch (Exception ignore) {
- }
- }
- }
-
-
- /**
- * Construct a JSONObject from a source JSON text string.
- * This is the most commonly used JSONObject constructor.
- * @param source A string beginning
- * with {
(left brace) and ending
- * with }
(right brace) .
- * @exception JSONException If there is a syntax error in the source
- * string or a duplicated key.
- */
- public JSONObject(String source) throws JSONException {
- this(new JSONTokener(source));
- }
-
-
- /**
- * Construct a JSONObject from a ResourceBundle.
- * @param baseName The ResourceBundle base name.
- * @param locale The Locale to load the ResourceBundle for.
- * @throws JSONException If any JSONExceptions are detected.
- */
- public JSONObject(String baseName, Locale locale) throws JSONException {
- this();
- ResourceBundle bundle = ResourceBundle.getBundle(baseName, locale,
- Thread.currentThread().getContextClassLoader());
+ switch (x.nextClean()) {
+ case ';':
+ case ',':
+ if (x.nextClean() == '}') {
+ return;
+ }
+ x.back();
+ break;
+ case '}':
+ return;
+ default:
+ throw x.syntaxError("Expected a ',' or '}'");
+ }
+ }
+ }
+
+ /** Construct a JSONObject from a Map.
+ *
+ * @param map A map object that can be used to initialize the contents of the JSONObject.
+ * @throws JSONException */
+ public JSONObject (Map map) {
+ this.map = new HashMap();
+ if (map != null) {
+ Iterator i = map.entrySet().iterator();
+ while (i.hasNext()) {
+ Map.Entry e = (Map.Entry)i.next();
+ Object value = e.getValue();
+ if (value != null) {
+ this.map.put(e.getKey(), wrap(value));
+ }
+ }
+ }
+ }
+
+ /** Construct a JSONObject from an Object using bean getters. It reflects on all of the public methods of the object. For each
+ * of the methods with no parameters and a name starting with "get"
or "is"
followed by an uppercase
+ * letter, the method is invoked, and a key and the value returned from the getter method are put into the new JSONObject.
+ *
+ * The key is formed by removing the "get"
or "is"
prefix. If the second remaining character is not
+ * upper case, then the first character is converted to lower case.
+ *
+ * For example, if an object has a method named "getName"
, and if the result of calling
+ * object.getName()
is "Larry Fine"
, then the JSONObject will contain
+ * "name": "Larry Fine"
.
+ *
+ * @param bean An object that has getter methods that should be used to make a JSONObject. */
+ public JSONObject (Object bean) {
+ this();
+ populateMap(bean);
+ }
+
+ /** Construct a JSONObject from an Object, using reflection to find the public members. The resulting JSONObject's keys will be
+ * the strings from the names array, and the values will be the field values associated with those keys in the object. If a key
+ * is not found or not visible, then it will not be copied into the new JSONObject.
+ * @param object An object that has fields that should be used to make a JSONObject.
+ * @param names An array of strings, the names of the fields to be obtained from the object. */
+ public JSONObject (Object object, String names[]) {
+ this();
+ Class c = object.getClass();
+ for (int i = 0; i < names.length; i += 1) {
+ String name = names[i];
+ try {
+ putOpt(name, c.getField(name).get(object));
+ } catch (Exception ignore) {
+ }
+ }
+ }
+
+ /** Construct a JSONObject from a source JSON text string. This is the most commonly used JSONObject constructor.
+ * @param source A string beginning with {
(left brace) and ending with }
+ * (right brace) .
+ * @exception JSONException If there is a syntax error in the source string or a duplicated key. */
+ public JSONObject (String source) throws JSONException {
+ this(new JSONTokener(source));
+ }
+
+ /** Construct a JSONObject from a ResourceBundle.
+ * @param baseName The ResourceBundle base name.
+ * @param locale The Locale to load the ResourceBundle for.
+ * @throws JSONException If any JSONExceptions are detected. */
+ public JSONObject (String baseName, Locale locale) throws JSONException {
+ this();
+ ResourceBundle bundle = ResourceBundle.getBundle(baseName, locale, Thread.currentThread().getContextClassLoader());
// Iterate through the keys in the bundle.
-
- Enumeration keys = bundle.getKeys();
- while (keys.hasMoreElements()) {
- Object key = keys.nextElement();
- if (key instanceof String) {
-
-// Go through the path, ensuring that there is a nested JSONObject for each
+
+ Enumeration keys = bundle.getKeys();
+ while (keys.hasMoreElements()) {
+ Object key = keys.nextElement();
+ if (key instanceof String) {
+
+// Go through the path, ensuring that there is a nested JSONObject for each
// segment except the last. Add the value using the last segment's name into
// the deepest nested JSONObject.
-
- String[] path = ((String)key).split("\\.");
- int last = path.length - 1;
- JSONObject target = this;
- for (int i = 0; i < last; i += 1) {
- String segment = path[i];
- JSONObject nextTarget = target.optJSONObject(segment);
- if (nextTarget == null) {
- nextTarget = new JSONObject();
- target.put(segment, nextTarget);
- }
- target = nextTarget;
- }
- target.put(path[last], bundle.getString((String)key));
- }
- }
- }
-
-
- /**
- * Accumulate values under a key. It is similar to the put method except
- * that if there is already an object stored under the key then a
- * JSONArray is stored under the key to hold all of the accumulated values.
- * If there is already a JSONArray, then the new value is appended to it.
- * In contrast, the put method replaces the previous value.
- *
- * If only one value is accumulated that is not a JSONArray, then the
- * result will be the same as using put. But if multiple values are
- * accumulated, then the result will be like append.
- * @param key A key string.
- * @param value An object to be accumulated under the key.
- * @return this.
- * @throws JSONException If the value is an invalid number
- * or if the key is null.
- */
- public JSONObject accumulate(String key, Object value)
- throws JSONException {
- testValidity(value);
- Object object = opt(key);
- if (object == null) {
- put(key, value instanceof JSONArray ?
- new JSONArray().put(value) : value);
- } else if (object instanceof JSONArray) {
- ((JSONArray)object).put(value);
- } else {
- put(key, new JSONArray().put(object).put(value));
- }
- return this;
- }
-
-
- /**
- * Append values to the array under a key. If the key does not exist in the
- * JSONObject, then the key is put in the JSONObject with its value being a
- * JSONArray containing the value parameter. If the key was already
- * associated with a JSONArray, then the value parameter is appended to it.
- * @param key A key string.
- * @param value An object to be accumulated under the key.
- * @return this.
- * @throws JSONException If the key is null or if the current value
- * associated with the key is not a JSONArray.
- */
- public JSONObject append(String key, Object value) throws JSONException {
- testValidity(value);
- Object object = opt(key);
- if (object == null) {
- put(key, new JSONArray().put(value));
- } else if (object instanceof JSONArray) {
- put(key, ((JSONArray)object).put(value));
- } else {
- throw new JSONException("JSONObject[" + key +
- "] is not a JSONArray.");
- }
- return this;
- }
-
-
- /**
- * Produce a string from a double. The string "null" will be returned if
- * the number is not finite.
- * @param d A double.
- * @return A String.
- */
- public static String doubleToString(double d) {
- if (Double.isInfinite(d) || Double.isNaN(d)) {
- return "null";
- }
+
+ String[] path = ((String)key).split("\\.");
+ int last = path.length - 1;
+ JSONObject target = this;
+ for (int i = 0; i < last; i += 1) {
+ String segment = path[i];
+ JSONObject nextTarget = target.optJSONObject(segment);
+ if (nextTarget == null) {
+ nextTarget = new JSONObject();
+ target.put(segment, nextTarget);
+ }
+ target = nextTarget;
+ }
+ target.put(path[last], bundle.getString((String)key));
+ }
+ }
+ }
+
+ /** Accumulate values under a key. It is similar to the put method except that if there is already an object stored under the
+ * key then a JSONArray is stored under the key to hold all of the accumulated values. If there is already a JSONArray, then
+ * the new value is appended to it. In contrast, the put method replaces the previous value.
+ *
+ * If only one value is accumulated that is not a JSONArray, then the result will be the same as using put. But if multiple
+ * values are accumulated, then the result will be like append.
+ * @param key A key string.
+ * @param value An object to be accumulated under the key.
+ * @return this.
+ * @throws JSONException If the value is an invalid number or if the key is null. */
+ public JSONObject accumulate (String key, Object value) throws JSONException {
+ testValidity(value);
+ Object object = opt(key);
+ if (object == null) {
+ put(key, value instanceof JSONArray ? new JSONArray().put(value) : value);
+ } else if (object instanceof JSONArray) {
+ ((JSONArray)object).put(value);
+ } else {
+ put(key, new JSONArray().put(object).put(value));
+ }
+ return this;
+ }
+
+ /** Append values to the array under a key. If the key does not exist in the JSONObject, then the key is put in the JSONObject
+ * with its value being a JSONArray containing the value parameter. If the key was already associated with a JSONArray, then
+ * the value parameter is appended to it.
+ * @param key A key string.
+ * @param value An object to be accumulated under the key.
+ * @return this.
+ * @throws JSONException If the key is null or if the current value associated with the key is not a JSONArray. */
+ public JSONObject append (String key, Object value) throws JSONException {
+ testValidity(value);
+ Object object = opt(key);
+ if (object == null) {
+ put(key, new JSONArray().put(value));
+ } else if (object instanceof JSONArray) {
+ put(key, ((JSONArray)object).put(value));
+ } else {
+ throw new JSONException("JSONObject[" + key + "] is not a JSONArray.");
+ }
+ return this;
+ }
+
+ /** Produce a string from a double. The string "null" will be returned if the number is not finite.
+ * @param d A double.
+ * @return A String. */
+ public static String doubleToString (double d) {
+ if (Double.isInfinite(d) || Double.isNaN(d)) {
+ return "null";
+ }
// Shave off trailing zeros and decimal point, if possible.
- String string = Double.toString(d);
- if (string.indexOf('.') > 0 && string.indexOf('e') < 0 &&
- string.indexOf('E') < 0) {
- while (string.endsWith("0")) {
- string = string.substring(0, string.length() - 1);
- }
- if (string.endsWith(".")) {
- string = string.substring(0, string.length() - 1);
- }
- }
- return string;
- }
-
-
- /**
- * Get the value object associated with a key.
- *
- * @param key A key string.
- * @return The object associated with the key.
- * @throws JSONException if the key is not found.
- */
- public Object get(String key) throws JSONException {
- if (key == null) {
- throw new JSONException("Null key.");
- }
- Object object = opt(key);
- if (object == null) {
- throw new JSONException("JSONObject[" + quote(key) +
- "] not found.");
- }
- return object;
- }
-
-
- /**
- * Get the boolean value associated with a key.
- *
- * @param key A key string.
- * @return The truth.
- * @throws JSONException
- * if the value is not a Boolean or the String "true" or "false".
- */
- public boolean getBoolean(String key) throws JSONException {
- Object object = get(key);
- if (object.equals(Boolean.FALSE) ||
- (object instanceof String &&
- ((String)object).equalsIgnoreCase("false"))) {
- return false;
- } else if (object.equals(Boolean.TRUE) ||
- (object instanceof String &&
- ((String)object).equalsIgnoreCase("true"))) {
- return true;
- }
- throw new JSONException("JSONObject[" + quote(key) +
- "] is not a Boolean.");
- }
-
-
- /**
- * Get the double value associated with a key.
- * @param key A key string.
- * @return The numeric value.
- * @throws JSONException if the key is not found or
- * if the value is not a Number object and cannot be converted to a number.
- */
- public double getDouble(String key) throws JSONException {
- Object object = get(key);
- try {
- return object instanceof Number ?
- ((Number)object).doubleValue() :
- Double.parseDouble((String)object);
- } catch (Exception e) {
- throw new JSONException("JSONObject[" + quote(key) +
- "] is not a number.");
- }
- }
-
-
- /**
- * Get the int value associated with a key.
- *
- * @param key A key string.
- * @return The integer value.
- * @throws JSONException if the key is not found or if the value cannot
- * be converted to an integer.
- */
- public int getInt(String key) throws JSONException {
- Object object = get(key);
- try {
- return object instanceof Number ?
- ((Number)object).intValue() :
- Integer.parseInt((String)object);
- } catch (Exception e) {
- throw new JSONException("JSONObject[" + quote(key) +
- "] is not an int.");
- }
- }
-
-
- /**
- * Get the JSONArray value associated with a key.
- *
- * @param key A key string.
- * @return A JSONArray which is the value.
- * @throws JSONException if the key is not found or
- * if the value is not a JSONArray.
- */
- public JSONArray getJSONArray(String key) throws JSONException {
- Object object = get(key);
- if (object instanceof JSONArray) {
- return (JSONArray)object;
- }
- throw new JSONException("JSONObject[" + quote(key) +
- "] is not a JSONArray.");
- }
-
-
- /**
- * Get the JSONObject value associated with a key.
- *
- * @param key A key string.
- * @return A JSONObject which is the value.
- * @throws JSONException if the key is not found or
- * if the value is not a JSONObject.
- */
- public JSONObject getJSONObject(String key) throws JSONException {
- Object object = get(key);
- if (object instanceof JSONObject) {
- return (JSONObject)object;
- }
- throw new JSONException("JSONObject[" + quote(key) +
- "] is not a JSONObject.");
- }
-
-
- /**
- * Get the long value associated with a key.
- *
- * @param key A key string.
- * @return The long value.
- * @throws JSONException if the key is not found or if the value cannot
- * be converted to a long.
- */
- public long getLong(String key) throws JSONException {
- Object object = get(key);
- try {
- return object instanceof Number ?
- ((Number)object).longValue() :
- Long.parseLong((String)object);
- } catch (Exception e) {
- throw new JSONException("JSONObject[" + quote(key) +
- "] is not a long.");
- }
- }
-
-
- /**
- * Get an array of field names from a JSONObject.
- *
- * @return An array of field names, or null if there are no names.
- */
- public static String[] getNames(JSONObject jo) {
- int length = jo.length();
- if (length == 0) {
- return null;
- }
- Iterator iterator = jo.keys();
- String[] names = new String[length];
- int i = 0;
- while (iterator.hasNext()) {
- names[i] = (String)iterator.next();
- i += 1;
- }
- return names;
- }
-
-
- /**
- * Get an array of field names from an Object.
- *
- * @return An array of field names, or null if there are no names.
- */
- public static String[] getNames(Object object) {
- if (object == null) {
- return null;
- }
- Class klass = object.getClass();
- Field[] fields = klass.getFields();
- int length = fields.length;
- if (length == 0) {
- return null;
- }
- String[] names = new String[length];
- for (int i = 0; i < length; i += 1) {
- names[i] = fields[i].getName();
- }
- return names;
- }
-
-
- /**
- * Get the string associated with a key.
- *
- * @param key A key string.
- * @return A string which is the value.
- * @throws JSONException if the key is not found.
- */
- public String getString(String key) throws JSONException {
- Object object = get(key);
- return object == NULL ? null : object.toString();
- }
-
-
- /**
- * Determine if the JSONObject contains a specific key.
- * @param key A key string.
- * @return true if the key exists in the JSONObject.
- */
- public boolean has(String key) {
- return this.map.containsKey(key);
- }
-
-
- /**
- * Increment a property of a JSONObject. If there is no such property,
- * create one with a value of 1. If there is such a property, and if
- * it is an Integer, Long, Double, or Float, then add one to it.
- * @param key A key string.
- * @return this.
- * @throws JSONException If there is already a property with this name
- * that is not an Integer, Long, Double, or Float.
- */
- public JSONObject increment(String key) throws JSONException {
- Object value = opt(key);
- if (value == null) {
- put(key, 1);
- } else if (value instanceof Integer) {
- put(key, ((Integer)value).intValue() + 1);
- } else if (value instanceof Long) {
- put(key, ((Long)value).longValue() + 1);
- } else if (value instanceof Double) {
- put(key, ((Double)value).doubleValue() + 1);
- } else if (value instanceof Float) {
- put(key, ((Float)value).floatValue() + 1);
- } else {
- throw new JSONException("Unable to increment [" + quote(key) + "].");
- }
- return this;
- }
-
-
- /**
- * Determine if the value associated with the key is null or if there is
- * no value.
- * @param key A key string.
- * @return true if there is no value associated with the key or if
- * the value is the JSONObject.NULL object.
- */
- public boolean isNull(String key) {
- return JSONObject.NULL.equals(opt(key));
- }
-
-
- /**
- * Get an enumeration of the keys of the JSONObject.
- *
- * @return An iterator of the keys.
- */
- public Iterator keys() {
- return this.map.keySet().iterator();
- }
-
-
- /**
- * Get the number of keys stored in the JSONObject.
- *
- * @return The number of keys in the JSONObject.
- */
- public int length() {
- return this.map.size();
- }
-
-
- /**
- * Produce a JSONArray containing the names of the elements of this
- * JSONObject.
- * @return A JSONArray containing the key strings, or null if the JSONObject
- * is empty.
- */
- public JSONArray names() {
- JSONArray ja = new JSONArray();
- Iterator keys = this.keys();
- while (keys.hasNext()) {
- ja.put(keys.next());
- }
- return ja.length() == 0 ? null : ja;
- }
-
- /**
- * Produce a string from a Number.
- * @param number A Number
- * @return A String.
- * @throws JSONException If n is a non-finite number.
- */
- public static String numberToString(Number number)
- throws JSONException {
- if (number == null) {
- throw new JSONException("Null pointer");
- }
- testValidity(number);
+ String string = Double.toString(d);
+ if (string.indexOf('.') > 0 && string.indexOf('e') < 0 && string.indexOf('E') < 0) {
+ while (string.endsWith("0")) {
+ string = string.substring(0, string.length() - 1);
+ }
+ if (string.endsWith(".")) {
+ string = string.substring(0, string.length() - 1);
+ }
+ }
+ return string;
+ }
+
+ /** Get the value object associated with a key.
+ *
+ * @param key A key string.
+ * @return The object associated with the key.
+ * @throws JSONException if the key is not found. */
+ public Object get (String key) throws JSONException {
+ if (key == null) {
+ throw new JSONException("Null key.");
+ }
+ Object object = opt(key);
+ if (object == null) {
+ throw new JSONException("JSONObject[" + quote(key) + "] not found.");
+ }
+ return object;
+ }
+
+ /** Get the boolean value associated with a key.
+ *
+ * @param key A key string.
+ * @return The truth.
+ * @throws JSONException if the value is not a Boolean or the String "true" or "false". */
+ public boolean getBoolean (String key) throws JSONException {
+ Object object = get(key);
+ if (object.equals(Boolean.FALSE) || (object instanceof String && ((String)object).equalsIgnoreCase("false"))) {
+ return false;
+ } else if (object.equals(Boolean.TRUE) || (object instanceof String && ((String)object).equalsIgnoreCase("true"))) {
+ return true;
+ }
+ throw new JSONException("JSONObject[" + quote(key) + "] is not a Boolean.");
+ }
+
+ /** Get the double value associated with a key.
+ * @param key A key string.
+ * @return The numeric value.
+ * @throws JSONException if the key is not found or if the value is not a Number object and cannot be converted to a number. */
+ public double getDouble (String key) throws JSONException {
+ Object object = get(key);
+ try {
+ return object instanceof Number ? ((Number)object).doubleValue() : Double.parseDouble((String)object);
+ } catch (Exception e) {
+ throw new JSONException("JSONObject[" + quote(key) + "] is not a number.");
+ }
+ }
+
+ /** Get the int value associated with a key.
+ *
+ * @param key A key string.
+ * @return The integer value.
+ * @throws JSONException if the key is not found or if the value cannot be converted to an integer. */
+ public int getInt (String key) throws JSONException {
+ Object object = get(key);
+ try {
+ return object instanceof Number ? ((Number)object).intValue() : Integer.parseInt((String)object);
+ } catch (Exception e) {
+ throw new JSONException("JSONObject[" + quote(key) + "] is not an int.");
+ }
+ }
+
+ /** Get the JSONArray value associated with a key.
+ *
+ * @param key A key string.
+ * @return A JSONArray which is the value.
+ * @throws JSONException if the key is not found or if the value is not a JSONArray. */
+ public JSONArray getJSONArray (String key) throws JSONException {
+ Object object = get(key);
+ if (object instanceof JSONArray) {
+ return (JSONArray)object;
+ }
+ throw new JSONException("JSONObject[" + quote(key) + "] is not a JSONArray.");
+ }
+
+ /** Get the JSONObject value associated with a key.
+ *
+ * @param key A key string.
+ * @return A JSONObject which is the value.
+ * @throws JSONException if the key is not found or if the value is not a JSONObject. */
+ public JSONObject getJSONObject (String key) throws JSONException {
+ Object object = get(key);
+ if (object instanceof JSONObject) {
+ return (JSONObject)object;
+ }
+ throw new JSONException("JSONObject[" + quote(key) + "] is not a JSONObject.");
+ }
+
+ /** Get the long value associated with a key.
+ *
+ * @param key A key string.
+ * @return The long value.
+ * @throws JSONException if the key is not found or if the value cannot be converted to a long. */
+ public long getLong (String key) throws JSONException {
+ Object object = get(key);
+ try {
+ return object instanceof Number ? ((Number)object).longValue() : Long.parseLong((String)object);
+ } catch (Exception e) {
+ throw new JSONException("JSONObject[" + quote(key) + "] is not a long.");
+ }
+ }
+
+ /** Get an array of field names from a JSONObject.
+ *
+ * @return An array of field names, or null if there are no names. */
+ public static String[] getNames (JSONObject jo) {
+ int length = jo.length();
+ if (length == 0) {
+ return null;
+ }
+ Iterator iterator = jo.keys();
+ String[] names = new String[length];
+ int i = 0;
+ while (iterator.hasNext()) {
+ names[i] = (String)iterator.next();
+ i += 1;
+ }
+ return names;
+ }
+
+ /** Get an array of field names from an Object.
+ *
+ * @return An array of field names, or null if there are no names. */
+ public static String[] getNames (Object object) {
+ if (object == null) {
+ return null;
+ }
+ Class klass = object.getClass();
+ Field[] fields = klass.getFields();
+ int length = fields.length;
+ if (length == 0) {
+ return null;
+ }
+ String[] names = new String[length];
+ for (int i = 0; i < length; i += 1) {
+ names[i] = fields[i].getName();
+ }
+ return names;
+ }
+
+ /** Get the string associated with a key.
+ *
+ * @param key A key string.
+ * @return A string which is the value.
+ * @throws JSONException if the key is not found. */
+ public String getString (String key) throws JSONException {
+ Object object = get(key);
+ return object == NULL ? null : object.toString();
+ }
+
+ /** Determine if the JSONObject contains a specific key.
+ * @param key A key string.
+ * @return true if the key exists in the JSONObject. */
+ public boolean has (String key) {
+ return this.map.containsKey(key);
+ }
+
+ /** Increment a property of a JSONObject. If there is no such property, create one with a value of 1. If there is such a
+ * property, and if it is an Integer, Long, Double, or Float, then add one to it.
+ * @param key A key string.
+ * @return this.
+ * @throws JSONException If there is already a property with this name that is not an Integer, Long, Double, or Float. */
+ public JSONObject increment (String key) throws JSONException {
+ Object value = opt(key);
+ if (value == null) {
+ put(key, 1);
+ } else if (value instanceof Integer) {
+ put(key, ((Integer)value).intValue() + 1);
+ } else if (value instanceof Long) {
+ put(key, ((Long)value).longValue() + 1);
+ } else if (value instanceof Double) {
+ put(key, ((Double)value).doubleValue() + 1);
+ } else if (value instanceof Float) {
+ put(key, ((Float)value).floatValue() + 1);
+ } else {
+ throw new JSONException("Unable to increment [" + quote(key) + "].");
+ }
+ return this;
+ }
+
+ /** Determine if the value associated with the key is null or if there is no value.
+ * @param key A key string.
+ * @return true if there is no value associated with the key or if the value is the JSONObject.NULL object. */
+ public boolean isNull (String key) {
+ return JSONObject.NULL.equals(opt(key));
+ }
+
+ /** Get an enumeration of the keys of the JSONObject.
+ *
+ * @return An iterator of the keys. */
+ public Iterator keys () {
+ return this.map.keySet().iterator();
+ }
+
+ /** Get the number of keys stored in the JSONObject.
+ *
+ * @return The number of keys in the JSONObject. */
+ public int length () {
+ return this.map.size();
+ }
+
+ /** Produce a JSONArray containing the names of the elements of this JSONObject.
+ * @return A JSONArray containing the key strings, or null if the JSONObject is empty. */
+ public JSONArray names () {
+ JSONArray ja = new JSONArray();
+ Iterator keys = this.keys();
+ while (keys.hasNext()) {
+ ja.put(keys.next());
+ }
+ return ja.length() == 0 ? null : ja;
+ }
+
+ /** Produce a string from a Number.
+ * @param number A Number
+ * @return A String.
+ * @throws JSONException If n is a non-finite number. */
+ public static String numberToString (Number number) throws JSONException {
+ if (number == null) {
+ throw new JSONException("Null pointer");
+ }
+ testValidity(number);
// Shave off trailing zeros and decimal point, if possible.
- String string = number.toString();
- if (string.indexOf('.') > 0 && string.indexOf('e') < 0 &&
- string.indexOf('E') < 0) {
- while (string.endsWith("0")) {
- string = string.substring(0, string.length() - 1);
- }
- if (string.endsWith(".")) {
- string = string.substring(0, string.length() - 1);
- }
- }
- return string;
- }
-
-
- /**
- * Get an optional value associated with a key.
- * @param key A key string.
- * @return An object which is the value, or null if there is no value.
- */
- public Object opt(String key) {
- return key == null ? null : this.map.get(key);
- }
-
-
- /**
- * Get an optional boolean associated with a key.
- * It returns false if there is no such key, or if the value is not
- * Boolean.TRUE or the String "true".
- *
- * @param key A key string.
- * @return The truth.
- */
- public boolean optBoolean(String key) {
- return optBoolean(key, false);
- }
-
-
- /**
- * Get an optional boolean associated with a key.
- * It returns the defaultValue if there is no such key, or if it is not
- * a Boolean or the String "true" or "false" (case insensitive).
- *
- * @param key A key string.
- * @param defaultValue The default.
- * @return The truth.
- */
- public boolean optBoolean(String key, boolean defaultValue) {
- try {
- return getBoolean(key);
- } catch (Exception e) {
- return defaultValue;
- }
- }
-
-
- /**
- * Get an optional double associated with a key,
- * or NaN if there is no such key or if its value is not a number.
- * If the value is a string, an attempt will be made to evaluate it as
- * a number.
- *
- * @param key A string which is the key.
- * @return An object which is the value.
- */
- public double optDouble(String key) {
- return optDouble(key, Double.NaN);
- }
-
-
- /**
- * Get an optional double associated with a key, or the
- * defaultValue if there is no such key or if its value is not a number.
- * If the value is a string, an attempt will be made to evaluate it as
- * a number.
- *
- * @param key A key string.
- * @param defaultValue The default.
- * @return An object which is the value.
- */
- public double optDouble(String key, double defaultValue) {
- try {
- return getDouble(key);
- } catch (Exception e) {
- return defaultValue;
- }
- }
-
-
- /**
- * Get an optional int value associated with a key,
- * or zero if there is no such key or if the value is not a number.
- * If the value is a string, an attempt will be made to evaluate it as
- * a number.
- *
- * @param key A key string.
- * @return An object which is the value.
- */
- public int optInt(String key) {
- return optInt(key, 0);
- }
-
-
- /**
- * Get an optional int value associated with a key,
- * or the default if there is no such key or if the value is not a number.
- * If the value is a string, an attempt will be made to evaluate it as
- * a number.
- *
- * @param key A key string.
- * @param defaultValue The default.
- * @return An object which is the value.
- */
- public int optInt(String key, int defaultValue) {
- try {
- return getInt(key);
- } catch (Exception e) {
- return defaultValue;
- }
- }
-
-
- /**
- * Get an optional JSONArray associated with a key.
- * It returns null if there is no such key, or if its value is not a
- * JSONArray.
- *
- * @param key A key string.
- * @return A JSONArray which is the value.
- */
- public JSONArray optJSONArray(String key) {
- Object o = opt(key);
- return o instanceof JSONArray ? (JSONArray)o : null;
- }
-
-
- /**
- * Get an optional JSONObject associated with a key.
- * It returns null if there is no such key, or if its value is not a
- * JSONObject.
- *
- * @param key A key string.
- * @return A JSONObject which is the value.
- */
- public JSONObject optJSONObject(String key) {
- Object object = opt(key);
- return object instanceof JSONObject ? (JSONObject)object : null;
- }
-
-
- /**
- * Get an optional long value associated with a key,
- * or zero if there is no such key or if the value is not a number.
- * If the value is a string, an attempt will be made to evaluate it as
- * a number.
- *
- * @param key A key string.
- * @return An object which is the value.
- */
- public long optLong(String key) {
- return optLong(key, 0);
- }
-
-
- /**
- * Get an optional long value associated with a key,
- * or the default if there is no such key or if the value is not a number.
- * If the value is a string, an attempt will be made to evaluate it as
- * a number.
- *
- * @param key A key string.
- * @param defaultValue The default.
- * @return An object which is the value.
- */
- public long optLong(String key, long defaultValue) {
- try {
- return getLong(key);
- } catch (Exception e) {
- return defaultValue;
- }
- }
-
-
- /**
- * Get an optional string associated with a key.
- * It returns an empty string if there is no such key. If the value is not
- * a string and is not null, then it is converted to a string.
- *
- * @param key A key string.
- * @return A string which is the value.
- */
- public String optString(String key) {
- return optString(key, "");
- }
-
-
- /**
- * Get an optional string associated with a key.
- * It returns the defaultValue if there is no such key.
- *
- * @param key A key string.
- * @param defaultValue The default.
- * @return A string which is the value.
- */
- public String optString(String key, String defaultValue) {
- Object object = opt(key);
- return NULL.equals(object) ? defaultValue : object.toString();
- }
-
-
- private void populateMap(Object bean) {
- Class klass = bean.getClass();
-
-// If klass is a System class then set includeSuperClass to false.
-
- boolean includeSuperClass = klass.getClassLoader() != null;
-
- Method[] methods = (includeSuperClass) ?
- klass.getMethods() : klass.getDeclaredMethods();
- for (int i = 0; i < methods.length; i += 1) {
- try {
- Method method = methods[i];
- if (Modifier.isPublic(method.getModifiers())) {
- String name = method.getName();
- String key = "";
- if (name.startsWith("get")) {
- if (name.equals("getClass") ||
- name.equals("getDeclaringClass")) {
- key = "";
- } else {
- key = name.substring(3);
- }
- } else if (name.startsWith("is")) {
- key = name.substring(2);
- }
- if (key.length() > 0 &&
- Character.isUpperCase(key.charAt(0)) &&
- method.getParameterTypes().length == 0) {
- if (key.length() == 1) {
- key = key.toLowerCase();
- } else if (!Character.isUpperCase(key.charAt(1))) {
- key = key.substring(0, 1).toLowerCase() +
- key.substring(1);
- }
-
- Object result = method.invoke(bean, (Object[])null);
- if (result != null) {
- map.put(key, wrap(result));
- }
- }
- }
- } catch (Exception ignore) {
- }
- }
- }
-
-
- /**
- * Put a key/boolean pair in the JSONObject.
- *
- * @param key A key string.
- * @param value A boolean which is the value.
- * @return this.
- * @throws JSONException If the key is null.
- */
- public JSONObject put(String key, boolean value) throws JSONException {
- put(key, value ? Boolean.TRUE : Boolean.FALSE);
- return this;
- }
-
-
- /**
- * Put a key/value pair in the JSONObject, where the value will be a
- * JSONArray which is produced from a Collection.
- * @param key A key string.
- * @param value A Collection value.
- * @return this.
- * @throws JSONException
- */
- public JSONObject put(String key, Collection value) throws JSONException {
- put(key, new JSONArray(value));
- return this;
- }
-
-
- /**
- * Put a key/double pair in the JSONObject.
- *
- * @param key A key string.
- * @param value A double which is the value.
- * @return this.
- * @throws JSONException If the key is null or if the number is invalid.
- */
- public JSONObject put(String key, double value) throws JSONException {
- put(key, new Double(value));
- return this;
- }
-
-
- /**
- * Put a key/int pair in the JSONObject.
- *
- * @param key A key string.
- * @param value An int which is the value.
- * @return this.
- * @throws JSONException If the key is null.
- */
- public JSONObject put(String key, int value) throws JSONException {
- put(key, new Integer(value));
- return this;
- }
-
-
- /**
- * Put a key/long pair in the JSONObject.
- *
- * @param key A key string.
- * @param value A long which is the value.
- * @return this.
- * @throws JSONException If the key is null.
- */
- public JSONObject put(String key, long value) throws JSONException {
- put(key, new Long(value));
- return this;
- }
-
-
- /**
- * Put a key/value pair in the JSONObject, where the value will be a
- * JSONObject which is produced from a Map.
- * @param key A key string.
- * @param value A Map value.
- * @return this.
- * @throws JSONException
- */
- public JSONObject put(String key, Map value) throws JSONException {
- put(key, new JSONObject(value));
- return this;
- }
-
-
- /**
- * Put a key/value pair in the JSONObject. If the value is null,
- * then the key will be removed from the JSONObject if it is present.
- * @param key A key string.
- * @param value An object which is the value. It should be of one of these
- * types: Boolean, Double, Integer, JSONArray, JSONObject, Long, String,
- * or the JSONObject.NULL object.
- * @return this.
- * @throws JSONException If the value is non-finite number
- * or if the key is null.
- */
- public JSONObject put(String key, Object value) throws JSONException {
- if (key == null) {
- throw new JSONException("Null key.");
- }
- if (value != null) {
- testValidity(value);
- this.map.put(key, value);
- } else {
- remove(key);
- }
- return this;
- }
-
-
- /**
- * Put a key/value pair in the JSONObject, but only if the key and the
- * value are both non-null, and only if there is not already a member
- * with that name.
- * @param key
- * @param value
- * @return his.
- * @throws JSONException if the key is a duplicate
- */
- public JSONObject putOnce(String key, Object value) throws JSONException {
- if (key != null && value != null) {
- if (opt(key) != null) {
- throw new JSONException("Duplicate key \"" + key + "\"");
- }
- put(key, value);
- }
- return this;
- }
-
-
- /**
- * Put a key/value pair in the JSONObject, but only if the
- * key and the value are both non-null.
- * @param key A key string.
- * @param value An object which is the value. It should be of one of these
- * types: Boolean, Double, Integer, JSONArray, JSONObject, Long, String,
- * or the JSONObject.NULL object.
- * @return this.
- * @throws JSONException If the value is a non-finite number.
- */
- public JSONObject putOpt(String key, Object value) throws JSONException {
- if (key != null && value != null) {
- put(key, value);
- }
- return this;
- }
-
-
- /**
- * Produce a string in double quotes with backslash sequences in all the
- * right places. A backslash will be inserted within , producing <\/,
- * allowing JSON text to be delivered in HTML. In JSON text, a string
- * cannot contain a control character or an unescaped quote or backslash.
- * @param string A String
- * @return A String correctly formatted for insertion in a JSON text.
- */
- public static String quote(String string) {
- if (string == null || string.length() == 0) {
- return "\"\"";
- }
-
- char b;
- char c = 0;
- String hhhh;
- int i;
- int len = string.length();
- StringBuffer sb = new StringBuffer(len + 4);
-
- sb.append('"');
- for (i = 0; i < len; i += 1) {
- b = c;
- c = string.charAt(i);
- switch (c) {
- case '\\':
- case '"':
- sb.append('\\');
- sb.append(c);
- break;
- case '/':
- if (b == '<') {
- sb.append('\\');
- }
- sb.append(c);
- break;
- case '\b':
- sb.append("\\b");
- break;
- case '\t':
- sb.append("\\t");
- break;
- case '\n':
- sb.append("\\n");
- break;
- case '\f':
- sb.append("\\f");
- break;
- case '\r':
- sb.append("\\r");
- break;
- default:
- if (c < ' ' || (c >= '\u0080' && c < '\u00a0') ||
- (c >= '\u2000' && c < '\u2100')) {
- hhhh = "000" + Integer.toHexString(c);
- sb.append("\\u" + hhhh.substring(hhhh.length() - 4));
- } else {
- sb.append(c);
- }
- }
- }
- sb.append('"');
- return sb.toString();
- }
-
- /**
- * Remove a name and its value, if present.
- * @param key The name to be removed.
- * @return The value that was associated with the name,
- * or null if there was no value.
- */
- public Object remove(String key) {
- return this.map.remove(key);
- }
-
- /**
- * Try to convert a string into a number, boolean, or null. If the string
- * can't be converted, return the string.
- * @param string A String.
- * @return A simple JSON value.
- */
- public static Object stringToValue(String string) {
- if (string.equals("")) {
- return string;
- }
- if (string.equalsIgnoreCase("true")) {
- return Boolean.TRUE;
- }
- if (string.equalsIgnoreCase("false")) {
- return Boolean.FALSE;
- }
- if (string.equalsIgnoreCase("null")) {
- return JSONObject.NULL;
- }
-
- /*
- * If it might be a number, try converting it.
- * We support the non-standard 0x- convention.
- * If a number cannot be produced, then the value will just
- * be a string. Note that the 0x-, plus, and implied string
- * conventions are non-standard. A JSON parser may accept
- * non-JSON forms as long as it accepts all correct JSON forms.
- */
-
- char b = string.charAt(0);
- if ((b >= '0' && b <= '9') || b == '.' || b == '-' || b == '+') {
- if (b == '0' && string.length() > 2 &&
- (string.charAt(1) == 'x' || string.charAt(1) == 'X')) {
- try {
- return new Integer(Integer.parseInt(string.substring(2), 16));
- } catch (Exception ignore) {
- }
- }
- try {
- if (string.indexOf('.') > -1 ||
- string.indexOf('e') > -1 || string.indexOf('E') > -1) {
- return Double.valueOf(string);
- } else {
- Long myLong = new Long(string);
- if (myLong.longValue() == myLong.intValue()) {
- return new Integer(myLong.intValue());
- } else {
- return myLong;
- }
- }
- } catch (Exception ignore) {
- }
- }
- return string;
- }
-
-
- /**
- * Throw an exception if the object is a NaN or infinite number.
- * @param o The object to test.
- * @throws JSONException If o is a non-finite number.
- */
- public static void testValidity(Object o) throws JSONException {
- if (o != null) {
- if (o instanceof Double) {
- if (((Double)o).isInfinite() || ((Double)o).isNaN()) {
- throw new JSONException(
- "JSON does not allow non-finite numbers.");
- }
- } else if (o instanceof Float) {
- if (((Float)o).isInfinite() || ((Float)o).isNaN()) {
- throw new JSONException(
- "JSON does not allow non-finite numbers.");
- }
- }
- }
- }
-
-
- /**
- * Produce a JSONArray containing the values of the members of this
- * JSONObject.
- * @param names A JSONArray containing a list of key strings. This
- * determines the sequence of the values in the result.
- * @return A JSONArray of values.
- * @throws JSONException If any of the values are non-finite numbers.
- */
- public JSONArray toJSONArray(JSONArray names) throws JSONException {
- if (names == null || names.length() == 0) {
- return null;
- }
- JSONArray ja = new JSONArray();
- for (int i = 0; i < names.length(); i += 1) {
- ja.put(this.opt(names.getString(i)));
- }
- return ja;
- }
-
- /**
- * Make a JSON text of this JSONObject. For compactness, no whitespace
- * is added. If this would not result in a syntactically correct JSON text,
- * then null will be returned instead.
- *
- * Warning: This method assumes that the data structure is acyclical.
- *
- * @return a printable, displayable, portable, transmittable
- * representation of the object, beginning
- * with {
(left brace) and ending
- * with }
(right brace) .
- */
- public String toString() {
- try {
- Iterator keys = this.keys();
- StringBuffer sb = new StringBuffer("{");
-
- while (keys.hasNext()) {
- if (sb.length() > 1) {
- sb.append(',');
- }
- Object o = keys.next();
- sb.append(quote(o.toString()));
- sb.append(':');
- sb.append(valueToString(this.map.get(o)));
- }
- sb.append('}');
- return sb.toString();
- } catch (Exception e) {
- return null;
- }
- }
-
-
- /**
- * Make a prettyprinted JSON text of this JSONObject.
- *
- * Warning: This method assumes that the data structure is acyclical.
- * @param indentFactor The number of spaces to add to each level of
- * indentation.
- * @return a printable, displayable, portable, transmittable
- * representation of the object, beginning
- * with {
(left brace) and ending
- * with }
(right brace) .
- * @throws JSONException If the object contains an invalid number.
- */
- public String toString(int indentFactor) throws JSONException {
- return toString(indentFactor, 0);
- }
-
-
- /**
- * Make a prettyprinted JSON text of this JSONObject.
- *
- * Warning: This method assumes that the data structure is acyclical.
- * @param indentFactor The number of spaces to add to each level of
- * indentation.
- * @param indent The indentation of the top level.
- * @return a printable, displayable, transmittable
- * representation of the object, beginning
- * with {
(left brace) and ending
- * with }
(right brace) .
- * @throws JSONException If the object contains an invalid number.
- */
- String toString(int indentFactor, int indent) throws JSONException {
- int i;
- int length = this.length();
- if (length == 0) {
- return "{}";
- }
- Iterator keys = this.keys();
- int newindent = indent + indentFactor;
- Object object;
- StringBuffer sb = new StringBuffer("{");
- if (length == 1) {
- object = keys.next();
- sb.append(quote(object.toString()));
- sb.append(": ");
- sb.append(valueToString(this.map.get(object), indentFactor,
- indent));
- } else {
- while (keys.hasNext()) {
- object = keys.next();
- if (sb.length() > 1) {
- sb.append(",\n");
- } else {
- sb.append('\n');
- }
- for (i = 0; i < newindent; i += 1) {
- sb.append(' ');
- }
- sb.append(quote(object.toString()));
- sb.append(": ");
- sb.append(valueToString(this.map.get(object), indentFactor,
- newindent));
- }
- if (sb.length() > 1) {
- sb.append('\n');
- for (i = 0; i < indent; i += 1) {
- sb.append(' ');
- }
- }
- }
- sb.append('}');
- return sb.toString();
- }
-
-
- /**
- * Make a JSON text of an Object value. If the object has an
- * value.toJSONString() method, then that method will be used to produce
- * the JSON text. The method is required to produce a strictly
- * conforming text. If the object does not contain a toJSONString
- * method (which is the most common case), then a text will be
- * produced by other means. If the value is an array or Collection,
- * then a JSONArray will be made from it and its toJSONString method
- * will be called. If the value is a MAP, then a JSONObject will be made
- * from it and its toJSONString method will be called. Otherwise, the
- * value's toString method will be called, and the result will be quoted.
- *
- *
- * Warning: This method assumes that the data structure is acyclical.
- * @param value The value to be serialized.
- * @return a printable, displayable, transmittable
- * representation of the object, beginning
- * with {
(left brace) and ending
- * with }
(right brace) .
- * @throws JSONException If the value is or contains an invalid number.
- */
- public static String valueToString(Object value) throws JSONException {
- if (value == null || value.equals(null)) {
- return "null";
- }
- if (value instanceof JSONString) {
- Object object;
- try {
- object = ((JSONString)value).toJSONString();
- } catch (Exception e) {
- throw new JSONException(e);
- }
- if (object instanceof String) {
- return (String)object;
- }
- throw new JSONException("Bad value from toJSONString: " + object);
- }
- if (value instanceof Number) {
- return numberToString((Number) value);
- }
- if (value instanceof Boolean || value instanceof JSONObject ||
- value instanceof JSONArray) {
- return value.toString();
- }
- if (value instanceof Map) {
- return new JSONObject((Map)value).toString();
- }
- if (value instanceof Collection) {
- return new JSONArray((Collection)value).toString();
- }
- if (value.getClass().isArray()) {
- return new JSONArray(value).toString();
- }
- return quote(value.toString());
- }
-
-
- /**
- * Make a prettyprinted JSON text of an object value.
- *
- * Warning: This method assumes that the data structure is acyclical.
- * @param value The value to be serialized.
- * @param indentFactor The number of spaces to add to each level of
- * indentation.
- * @param indent The indentation of the top level.
- * @return a printable, displayable, transmittable
- * representation of the object, beginning
- * with {
(left brace) and ending
- * with }
(right brace) .
- * @throws JSONException If the object contains an invalid number.
- */
- static String valueToString(Object value, int indentFactor, int indent)
- throws JSONException {
- if (value == null || value.equals(null)) {
- return "null";
- }
- try {
- if (value instanceof JSONString) {
- Object o = ((JSONString)value).toJSONString();
- if (o instanceof String) {
- return (String)o;
- }
- }
- } catch (Exception ignore) {
- }
- if (value instanceof Number) {
- return numberToString((Number) value);
- }
- if (value instanceof Boolean) {
- return value.toString();
- }
- if (value instanceof JSONObject) {
- return ((JSONObject)value).toString(indentFactor, indent);
- }
- if (value instanceof JSONArray) {
- return ((JSONArray)value).toString(indentFactor, indent);
- }
- if (value instanceof Map) {
- return new JSONObject((Map)value).toString(indentFactor, indent);
- }
- if (value instanceof Collection) {
- return new JSONArray((Collection)value).toString(indentFactor, indent);
- }
- if (value.getClass().isArray()) {
- return new JSONArray(value).toString(indentFactor, indent);
- }
- return quote(value.toString());
- }
-
-
- /**
- * Wrap an object, if necessary. If the object is null, return the NULL
- * object. If it is an array or collection, wrap it in a JSONArray. If
- * it is a map, wrap it in a JSONObject. If it is a standard property
- * (Double, String, et al) then it is already wrapped. Otherwise, if it
- * comes from one of the java packages, turn it into a string. And if
- * it doesn't, try to wrap it in a JSONObject. If the wrapping fails,
- * then null is returned.
- *
- * @param object The object to wrap
- * @return The wrapped value
- */
- public static Object wrap(Object object) {
- try {
- if (object == null) {
- return NULL;
- }
- if (object instanceof JSONObject || object instanceof JSONArray ||
- NULL.equals(object) || object instanceof JSONString ||
- object instanceof Byte || object instanceof Character ||
- object instanceof Short || object instanceof Integer ||
- object instanceof Long || object instanceof Boolean ||
- object instanceof Float || object instanceof Double ||
- object instanceof String) {
- return object;
- }
-
- if (object instanceof Collection) {
- return new JSONArray((Collection)object);
- }
- if (object.getClass().isArray()) {
- return new JSONArray(object);
- }
- if (object instanceof Map) {
- return new JSONObject((Map)object);
- }
- Package objectPackage = object.getClass().getPackage();
- String objectPackageName = ( objectPackage != null ? objectPackage.getName() : "" );
- if (objectPackageName.startsWith("java.") ||
- objectPackageName.startsWith("javax.") ||
- object.getClass().getClassLoader() == null) {
- return object.toString();
- }
- return new JSONObject(object);
- } catch(Exception exception) {
- return null;
- }
- }
-
-
- /**
- * Write the contents of the JSONObject as JSON text to a writer.
- * For compactness, no whitespace is added.
- *
- * Warning: This method assumes that the data structure is acyclical.
- *
- * @return The writer.
- * @throws JSONException
- */
- public Writer write(Writer writer) throws JSONException {
- try {
- boolean commanate = false;
- Iterator keys = this.keys();
- writer.write('{');
-
- while (keys.hasNext()) {
- if (commanate) {
- writer.write(',');
- }
- Object key = keys.next();
- writer.write(quote(key.toString()));
- writer.write(':');
- Object value = this.map.get(key);
- if (value instanceof JSONObject) {
- ((JSONObject)value).write(writer);
- } else if (value instanceof JSONArray) {
- ((JSONArray)value).write(writer);
- } else {
- writer.write(valueToString(value));
- }
- commanate = true;
- }
- writer.write('}');
- return writer;
- } catch (IOException exception) {
- throw new JSONException(exception);
- }
- }
-}
\ No newline at end of file
+ String string = number.toString();
+ if (string.indexOf('.') > 0 && string.indexOf('e') < 0 && string.indexOf('E') < 0) {
+ while (string.endsWith("0")) {
+ string = string.substring(0, string.length() - 1);
+ }
+ if (string.endsWith(".")) {
+ string = string.substring(0, string.length() - 1);
+ }
+ }
+ return string;
+ }
+
+ /** Get an optional value associated with a key.
+ * @param key A key string.
+ * @return An object which is the value, or null if there is no value. */
+ public Object opt (String key) {
+ return key == null ? null : this.map.get(key);
+ }
+
+ /** Get an optional boolean associated with a key. It returns false if there is no such key, or if the value is not Boolean.TRUE
+ * or the String "true".
+ *
+ * @param key A key string.
+ * @return The truth. */
+ public boolean optBoolean (String key) {
+ return optBoolean(key, false);
+ }
+
+ /** Get an optional boolean associated with a key. It returns the defaultValue if there is no such key, or if it is not a
+ * Boolean or the String "true" or "false" (case insensitive).
+ *
+ * @param key A key string.
+ * @param defaultValue The default.
+ * @return The truth. */
+ public boolean optBoolean (String key, boolean defaultValue) {
+ try {
+ return getBoolean(key);
+ } catch (Exception e) {
+ return defaultValue;
+ }
+ }
+
+ /** Get an optional double associated with a key, or NaN if there is no such key or if its value is not a number. If the value
+ * is a string, an attempt will be made to evaluate it as a number.
+ *
+ * @param key A string which is the key.
+ * @return An object which is the value. */
+ public double optDouble (String key) {
+ return optDouble(key, Double.NaN);
+ }
+
+ /** Get an optional double associated with a key, or the defaultValue if there is no such key or if its value is not a number.
+ * If the value is a string, an attempt will be made to evaluate it as a number.
+ *
+ * @param key A key string.
+ * @param defaultValue The default.
+ * @return An object which is the value. */
+ public double optDouble (String key, double defaultValue) {
+ try {
+ return getDouble(key);
+ } catch (Exception e) {
+ return defaultValue;
+ }
+ }
+
+ /** Get an optional int value associated with a key, or zero if there is no such key or if the value is not a number. If the
+ * value is a string, an attempt will be made to evaluate it as a number.
+ *
+ * @param key A key string.
+ * @return An object which is the value. */
+ public int optInt (String key) {
+ return optInt(key, 0);
+ }
+
+ /** Get an optional int value associated with a key, or the default if there is no such key or if the value is not a number. If
+ * the value is a string, an attempt will be made to evaluate it as a number.
+ *
+ * @param key A key string.
+ * @param defaultValue The default.
+ * @return An object which is the value. */
+ public int optInt (String key, int defaultValue) {
+ try {
+ return getInt(key);
+ } catch (Exception e) {
+ return defaultValue;
+ }
+ }
+
+ /** Get an optional JSONArray associated with a key. It returns null if there is no such key, or if its value is not a
+ * JSONArray.
+ *
+ * @param key A key string.
+ * @return A JSONArray which is the value. */
+ public JSONArray optJSONArray (String key) {
+ Object o = opt(key);
+ return o instanceof JSONArray ? (JSONArray)o : null;
+ }
+
+ /** Get an optional JSONObject associated with a key. It returns null if there is no such key, or if its value is not a
+ * JSONObject.
+ *
+ * @param key A key string.
+ * @return A JSONObject which is the value. */
+ public JSONObject optJSONObject (String key) {
+ Object object = opt(key);
+ return object instanceof JSONObject ? (JSONObject)object : null;
+ }
+
+ /** Get an optional long value associated with a key, or zero if there is no such key or if the value is not a number. If the
+ * value is a string, an attempt will be made to evaluate it as a number.
+ *
+ * @param key A key string.
+ * @return An object which is the value. */
+ public long optLong (String key) {
+ return optLong(key, 0);
+ }
+
+ /** Get an optional long value associated with a key, or the default if there is no such key or if the value is not a number. If
+ * the value is a string, an attempt will be made to evaluate it as a number.
+ *
+ * @param key A key string.
+ * @param defaultValue The default.
+ * @return An object which is the value. */
+ public long optLong (String key, long defaultValue) {
+ try {
+ return getLong(key);
+ } catch (Exception e) {
+ return defaultValue;
+ }
+ }
+
+ /** Get an optional string associated with a key. It returns an empty string if there is no such key. If the value is not a
+ * string and is not null, then it is converted to a string.
+ *
+ * @param key A key string.
+ * @return A string which is the value. */
+ public String optString (String key) {
+ return optString(key, "");
+ }
+
+ /** Get an optional string associated with a key. It returns the defaultValue if there is no such key.
+ *
+ * @param key A key string.
+ * @param defaultValue The default.
+ * @return A string which is the value. */
+ public String optString (String key, String defaultValue) {
+ Object object = opt(key);
+ return NULL.equals(object) ? defaultValue : object.toString();
+ }
+
+ private void populateMap (Object bean) {
+ Class klass = bean.getClass();
+
+// If klass is a System class then set includeSuperClass to false.
+
+ boolean includeSuperClass = klass.getClassLoader() != null;
+
+ Method[] methods = (includeSuperClass) ? klass.getMethods() : klass.getDeclaredMethods();
+ for (int i = 0; i < methods.length; i += 1) {
+ try {
+ Method method = methods[i];
+ if (Modifier.isPublic(method.getModifiers())) {
+ String name = method.getName();
+ String key = "";
+ if (name.startsWith("get")) {
+ if (name.equals("getClass") || name.equals("getDeclaringClass")) {
+ key = "";
+ } else {
+ key = name.substring(3);
+ }
+ } else if (name.startsWith("is")) {
+ key = name.substring(2);
+ }
+ if (key.length() > 0 && Character.isUpperCase(key.charAt(0)) && method.getParameterTypes().length == 0) {
+ if (key.length() == 1) {
+ key = key.toLowerCase();
+ } else if (!Character.isUpperCase(key.charAt(1))) {
+ key = key.substring(0, 1).toLowerCase() + key.substring(1);
+ }
+
+ Object result = method.invoke(bean, (Object[])null);
+ if (result != null) {
+ map.put(key, wrap(result));
+ }
+ }
+ }
+ } catch (Exception ignore) {
+ }
+ }
+ }
+
+ /** Put a key/boolean pair in the JSONObject.
+ *
+ * @param key A key string.
+ * @param value A boolean which is the value.
+ * @return this.
+ * @throws JSONException If the key is null. */
+ public JSONObject put (String key, boolean value) throws JSONException {
+ put(key, value ? Boolean.TRUE : Boolean.FALSE);
+ return this;
+ }
+
+ /** Put a key/value pair in the JSONObject, where the value will be a JSONArray which is produced from a Collection.
+ * @param key A key string.
+ * @param value A Collection value.
+ * @return this.
+ * @throws JSONException */
+ public JSONObject put (String key, Collection value) throws JSONException {
+ put(key, new JSONArray(value));
+ return this;
+ }
+
+ /** Put a key/double pair in the JSONObject.
+ *
+ * @param key A key string.
+ * @param value A double which is the value.
+ * @return this.
+ * @throws JSONException If the key is null or if the number is invalid. */
+ public JSONObject put (String key, double value) throws JSONException {
+ put(key, new Double(value));
+ return this;
+ }
+
+ /** Put a key/int pair in the JSONObject.
+ *
+ * @param key A key string.
+ * @param value An int which is the value.
+ * @return this.
+ * @throws JSONException If the key is null. */
+ public JSONObject put (String key, int value) throws JSONException {
+ put(key, new Integer(value));
+ return this;
+ }
+
+ /** Put a key/long pair in the JSONObject.
+ *
+ * @param key A key string.
+ * @param value A long which is the value.
+ * @return this.
+ * @throws JSONException If the key is null. */
+ public JSONObject put (String key, long value) throws JSONException {
+ put(key, new Long(value));
+ return this;
+ }
+
+ /** Put a key/value pair in the JSONObject, where the value will be a JSONObject which is produced from a Map.
+ * @param key A key string.
+ * @param value A Map value.
+ * @return this.
+ * @throws JSONException */
+ public JSONObject put (String key, Map value) throws JSONException {
+ put(key, new JSONObject(value));
+ return this;
+ }
+
+ /** Put a key/value pair in the JSONObject. If the value is null, then the key will be removed from the JSONObject if it is
+ * present.
+ * @param key A key string.
+ * @param value An object which is the value. It should be of one of these types: Boolean, Double, Integer, JSONArray,
+ * JSONObject, Long, String, or the JSONObject.NULL object.
+ * @return this.
+ * @throws JSONException If the value is non-finite number or if the key is null. */
+ public JSONObject put (String key, Object value) throws JSONException {
+ if (key == null) {
+ throw new JSONException("Null key.");
+ }
+ if (value != null) {
+ testValidity(value);
+ this.map.put(key, value);
+ } else {
+ remove(key);
+ }
+ return this;
+ }
+
+ /** Put a key/value pair in the JSONObject, but only if the key and the value are both non-null, and only if there is not
+ * already a member with that name.
+ * @param key
+ * @param value
+ * @return his.
+ * @throws JSONException if the key is a duplicate */
+ public JSONObject putOnce (String key, Object value) throws JSONException {
+ if (key != null && value != null) {
+ if (opt(key) != null) {
+ throw new JSONException("Duplicate key \"" + key + "\"");
+ }
+ put(key, value);
+ }
+ return this;
+ }
+
+ /** Put a key/value pair in the JSONObject, but only if the key and the value are both non-null.
+ * @param key A key string.
+ * @param value An object which is the value. It should be of one of these types: Boolean, Double, Integer, JSONArray,
+ * JSONObject, Long, String, or the JSONObject.NULL object.
+ * @return this.
+ * @throws JSONException If the value is a non-finite number. */
+ public JSONObject putOpt (String key, Object value) throws JSONException {
+ if (key != null && value != null) {
+ put(key, value);
+ }
+ return this;
+ }
+
+ /** Produce a string in double quotes with backslash sequences in all the right places. A backslash will be inserted within ,
+ * producing <\/, allowing JSON text to be delivered in HTML. In JSON text, a string cannot contain a control character or an
+ * unescaped quote or backslash.
+ * @param string A String
+ * @return A String correctly formatted for insertion in a JSON text. */
+ public static String quote (String string) {
+ if (string == null || string.length() == 0) {
+ return "\"\"";
+ }
+
+ char b;
+ char c = 0;
+ String hhhh;
+ int i;
+ int len = string.length();
+ StringBuffer sb = new StringBuffer(len + 4);
+
+ sb.append('"');
+ for (i = 0; i < len; i += 1) {
+ b = c;
+ c = string.charAt(i);
+ switch (c) {
+ case '\\':
+ case '"':
+ sb.append('\\');
+ sb.append(c);
+ break;
+ case '/':
+ if (b == '<') {
+ sb.append('\\');
+ }
+ sb.append(c);
+ break;
+ case '\b':
+ sb.append("\\b");
+ break;
+ case '\t':
+ sb.append("\\t");
+ break;
+ case '\n':
+ sb.append("\\n");
+ break;
+ case '\f':
+ sb.append("\\f");
+ break;
+ case '\r':
+ sb.append("\\r");
+ break;
+ default:
+ if (c < ' ' || (c >= '\u0080' && c < '\u00a0') || (c >= '\u2000' && c < '\u2100')) {
+ hhhh = "000" + Integer.toHexString(c);
+ sb.append("\\u" + hhhh.substring(hhhh.length() - 4));
+ } else {
+ sb.append(c);
+ }
+ }
+ }
+ sb.append('"');
+ return sb.toString();
+ }
+
+ /** Remove a name and its value, if present.
+ * @param key The name to be removed.
+ * @return The value that was associated with the name, or null if there was no value. */
+ public Object remove (String key) {
+ return this.map.remove(key);
+ }
+
+ /** Try to convert a string into a number, boolean, or null. If the string can't be converted, return the string.
+ * @param string A String.
+ * @return A simple JSON value. */
+ public static Object stringToValue (String string) {
+ if (string.equals("")) {
+ return string;
+ }
+ if (string.equalsIgnoreCase("true")) {
+ return Boolean.TRUE;
+ }
+ if (string.equalsIgnoreCase("false")) {
+ return Boolean.FALSE;
+ }
+ if (string.equalsIgnoreCase("null")) {
+ return JSONObject.NULL;
+ }
+
+ /*
+ * If it might be a number, try converting it. We support the non-standard 0x- convention. If a number cannot be produced,
+ * then the value will just be a string. Note that the 0x-, plus, and implied string conventions are non-standard. A JSON
+ * parser may accept non-JSON forms as long as it accepts all correct JSON forms.
+ */
+
+ char b = string.charAt(0);
+ if ((b >= '0' && b <= '9') || b == '.' || b == '-' || b == '+') {
+ if (b == '0' && string.length() > 2 && (string.charAt(1) == 'x' || string.charAt(1) == 'X')) {
+ try {
+ return new Integer(Integer.parseInt(string.substring(2), 16));
+ } catch (Exception ignore) {
+ }
+ }
+ try {
+ if (string.indexOf('.') > -1 || string.indexOf('e') > -1 || string.indexOf('E') > -1) {
+ return Double.valueOf(string);
+ } else {
+ Long myLong = new Long(string);
+ if (myLong.longValue() == myLong.intValue()) {
+ return new Integer(myLong.intValue());
+ } else {
+ return myLong;
+ }
+ }
+ } catch (Exception ignore) {
+ }
+ }
+ return string;
+ }
+
+ /** Throw an exception if the object is a NaN or infinite number.
+ * @param o The object to test.
+ * @throws JSONException If o is a non-finite number. */
+ public static void testValidity (Object o) throws JSONException {
+ if (o != null) {
+ if (o instanceof Double) {
+ if (((Double)o).isInfinite() || ((Double)o).isNaN()) {
+ throw new JSONException("JSON does not allow non-finite numbers.");
+ }
+ } else if (o instanceof Float) {
+ if (((Float)o).isInfinite() || ((Float)o).isNaN()) {
+ throw new JSONException("JSON does not allow non-finite numbers.");
+ }
+ }
+ }
+ }
+
+ /** Produce a JSONArray containing the values of the members of this JSONObject.
+ * @param names A JSONArray containing a list of key strings. This determines the sequence of the values in the result.
+ * @return A JSONArray of values.
+ * @throws JSONException If any of the values are non-finite numbers. */
+ public JSONArray toJSONArray (JSONArray names) throws JSONException {
+ if (names == null || names.length() == 0) {
+ return null;
+ }
+ JSONArray ja = new JSONArray();
+ for (int i = 0; i < names.length(); i += 1) {
+ ja.put(this.opt(names.getString(i)));
+ }
+ return ja;
+ }
+
+ /** Make a JSON text of this JSONObject. For compactness, no whitespace is added. If this would not result in a syntactically
+ * correct JSON text, then null will be returned instead.
+ *
+ * Warning: This method assumes that the data structure is acyclical.
+ *
+ * @return a printable, displayable, portable, transmittable representation of the object, beginning with {
+ * (left brace) and ending with }
(right brace) . */
+ public String toString () {
+ try {
+ Iterator keys = this.keys();
+ StringBuffer sb = new StringBuffer("{");
+
+ while (keys.hasNext()) {
+ if (sb.length() > 1) {
+ sb.append(',');
+ }
+ Object o = keys.next();
+ sb.append(quote(o.toString()));
+ sb.append(':');
+ sb.append(valueToString(this.map.get(o)));
+ }
+ sb.append('}');
+ return sb.toString();
+ } catch (Exception e) {
+ return null;
+ }
+ }
+
+ /** Make a prettyprinted JSON text of this JSONObject.
+ *
+ * Warning: This method assumes that the data structure is acyclical.
+ * @param indentFactor The number of spaces to add to each level of indentation.
+ * @return a printable, displayable, portable, transmittable representation of the object, beginning with {
+ * (left brace) and ending with }
(right brace) .
+ * @throws JSONException If the object contains an invalid number. */
+ public String toString (int indentFactor) throws JSONException {
+ return toString(indentFactor, 0);
+ }
+
+ /** Make a prettyprinted JSON text of this JSONObject.
+ *
+ * Warning: This method assumes that the data structure is acyclical.
+ * @param indentFactor The number of spaces to add to each level of indentation.
+ * @param indent The indentation of the top level.
+ * @return a printable, displayable, transmittable representation of the object, beginning with {
+ * (left brace) and ending with }
(right brace) .
+ * @throws JSONException If the object contains an invalid number. */
+ String toString (int indentFactor, int indent) throws JSONException {
+ int i;
+ int length = this.length();
+ if (length == 0) {
+ return "{}";
+ }
+ Iterator keys = this.keys();
+ int newindent = indent + indentFactor;
+ Object object;
+ StringBuffer sb = new StringBuffer("{");
+ if (length == 1) {
+ object = keys.next();
+ sb.append(quote(object.toString()));
+ sb.append(": ");
+ sb.append(valueToString(this.map.get(object), indentFactor, indent));
+ } else {
+ while (keys.hasNext()) {
+ object = keys.next();
+ if (sb.length() > 1) {
+ sb.append(",\n");
+ } else {
+ sb.append('\n');
+ }
+ for (i = 0; i < newindent; i += 1) {
+ sb.append(' ');
+ }
+ sb.append(quote(object.toString()));
+ sb.append(": ");
+ sb.append(valueToString(this.map.get(object), indentFactor, newindent));
+ }
+ if (sb.length() > 1) {
+ sb.append('\n');
+ for (i = 0; i < indent; i += 1) {
+ sb.append(' ');
+ }
+ }
+ }
+ sb.append('}');
+ return sb.toString();
+ }
+
+ /** Make a JSON text of an Object value. If the object has an value.toJSONString() method, then that method will be used to
+ * produce the JSON text. The method is required to produce a strictly conforming text. If the object does not contain a
+ * toJSONString method (which is the most common case), then a text will be produced by other means. If the value is an array
+ * or Collection, then a JSONArray will be made from it and its toJSONString method will be called. If the value is a MAP, then
+ * a JSONObject will be made from it and its toJSONString method will be called. Otherwise, the value's toString method will be
+ * called, and the result will be quoted.
+ *
+ *
+ * Warning: This method assumes that the data structure is acyclical.
+ * @param value The value to be serialized.
+ * @return a printable, displayable, transmittable representation of the object, beginning with {
+ * (left brace) and ending with }
(right brace) .
+ * @throws JSONException If the value is or contains an invalid number. */
+ public static String valueToString (Object value) throws JSONException {
+ if (value == null || value.equals(null)) {
+ return "null";
+ }
+ if (value instanceof JSONString) {
+ Object object;
+ try {
+ object = ((JSONString)value).toJSONString();
+ } catch (Exception e) {
+ throw new JSONException(e);
+ }
+ if (object instanceof String) {
+ return (String)object;
+ }
+ throw new JSONException("Bad value from toJSONString: " + object);
+ }
+ if (value instanceof Number) {
+ return numberToString((Number)value);
+ }
+ if (value instanceof Boolean || value instanceof JSONObject || value instanceof JSONArray) {
+ return value.toString();
+ }
+ if (value instanceof Map) {
+ return new JSONObject((Map)value).toString();
+ }
+ if (value instanceof Collection) {
+ return new JSONArray((Collection)value).toString();
+ }
+ if (value.getClass().isArray()) {
+ return new JSONArray(value).toString();
+ }
+ return quote(value.toString());
+ }
+
+ /** Make a prettyprinted JSON text of an object value.
+ *
+ * Warning: This method assumes that the data structure is acyclical.
+ * @param value The value to be serialized.
+ * @param indentFactor The number of spaces to add to each level of indentation.
+ * @param indent The indentation of the top level.
+ * @return a printable, displayable, transmittable representation of the object, beginning with {
+ * (left brace) and ending with }
(right brace) .
+ * @throws JSONException If the object contains an invalid number. */
+ static String valueToString (Object value, int indentFactor, int indent) throws JSONException {
+ if (value == null || value.equals(null)) {
+ return "null";
+ }
+ try {
+ if (value instanceof JSONString) {
+ Object o = ((JSONString)value).toJSONString();
+ if (o instanceof String) {
+ return (String)o;
+ }
+ }
+ } catch (Exception ignore) {
+ }
+ if (value instanceof Number) {
+ return numberToString((Number)value);
+ }
+ if (value instanceof Boolean) {
+ return value.toString();
+ }
+ if (value instanceof JSONObject) {
+ return ((JSONObject)value).toString(indentFactor, indent);
+ }
+ if (value instanceof JSONArray) {
+ return ((JSONArray)value).toString(indentFactor, indent);
+ }
+ if (value instanceof Map) {
+ return new JSONObject((Map)value).toString(indentFactor, indent);
+ }
+ if (value instanceof Collection) {
+ return new JSONArray((Collection)value).toString(indentFactor, indent);
+ }
+ if (value.getClass().isArray()) {
+ return new JSONArray(value).toString(indentFactor, indent);
+ }
+ return quote(value.toString());
+ }
+
+ /** Wrap an object, if necessary. If the object is null, return the NULL object. If it is an array or collection, wrap it in a
+ * JSONArray. If it is a map, wrap it in a JSONObject. If it is a standard property (Double, String, et al) then it is already
+ * wrapped. Otherwise, if it comes from one of the java packages, turn it into a string. And if it doesn't, try to wrap it in a
+ * JSONObject. If the wrapping fails, then null is returned.
+ *
+ * @param object The object to wrap
+ * @return The wrapped value */
+ public static Object wrap (Object object) {
+ try {
+ if (object == null) {
+ return NULL;
+ }
+ if (object instanceof JSONObject || object instanceof JSONArray || NULL.equals(object) || object instanceof JSONString
+ || object instanceof Byte || object instanceof Character || object instanceof Short || object instanceof Integer
+ || object instanceof Long || object instanceof Boolean || object instanceof Float || object instanceof Double
+ || object instanceof String) {
+ return object;
+ }
+
+ if (object instanceof Collection) {
+ return new JSONArray((Collection)object);
+ }
+ if (object.getClass().isArray()) {
+ return new JSONArray(object);
+ }
+ if (object instanceof Map) {
+ return new JSONObject((Map)object);
+ }
+ Package objectPackage = object.getClass().getPackage();
+ String objectPackageName = (objectPackage != null ? objectPackage.getName() : "");
+ if (objectPackageName.startsWith("java.") || objectPackageName.startsWith("javax.")
+ || object.getClass().getClassLoader() == null) {
+ return object.toString();
+ }
+ return new JSONObject(object);
+ } catch (Exception exception) {
+ return null;
+ }
+ }
+
+ /** Write the contents of the JSONObject as JSON text to a writer. For compactness, no whitespace is added.
+ *
+ * Warning: This method assumes that the data structure is acyclical.
+ *
+ * @return The writer.
+ * @throws JSONException */
+ public Writer write (Writer writer) throws JSONException {
+ try {
+ boolean commanate = false;
+ Iterator keys = this.keys();
+ writer.write('{');
+
+ while (keys.hasNext()) {
+ if (commanate) {
+ writer.write(',');
+ }
+ Object key = keys.next();
+ writer.write(quote(key.toString()));
+ writer.write(':');
+ Object value = this.map.get(key);
+ if (value instanceof JSONObject) {
+ ((JSONObject)value).write(writer);
+ } else if (value instanceof JSONArray) {
+ ((JSONArray)value).write(writer);
+ } else {
+ writer.write(valueToString(value));
+ }
+ commanate = true;
+ }
+ writer.write('}');
+ return writer;
+ } catch (IOException exception) {
+ throw new JSONException(exception);
+ }
+ }
+}
diff --git a/demos/vector-pinball/gdx-vectorpinball/src/com/dozingcatsoftware/bouncy/util/JSONString.java b/demos/vector-pinball/gdx-vectorpinball/src/com/dozingcatsoftware/bouncy/util/JSONString.java
index 7c8d30be266..6a68285870c 100644
--- a/demos/vector-pinball/gdx-vectorpinball/src/com/dozingcatsoftware/bouncy/util/JSONString.java
+++ b/demos/vector-pinball/gdx-vectorpinball/src/com/dozingcatsoftware/bouncy/util/JSONString.java
@@ -1,18 +1,13 @@
+
package com.dozingcatsoftware.bouncy.util;
-/**
- * The JSONString
interface allows a toJSONString()
- * method so that a class can change the behavior of
- * JSONObject.toString()
, JSONArray.toString()
,
- * and JSONWriter.value(
Object)
. The
- * toJSONString
method will be used instead of the default behavior
- * of using the Object's toString()
method and quoting the result.
- */
+
+/** The JSONString
interface allows a toJSONString()
method so that a class can change the behavior of
+ * JSONObject.toString()
, JSONArray.toString()
, and JSONWriter.value(
Object)
.
+ * The toJSONString
method will be used instead of the default behavior of using the Object's toString()
+ * method and quoting the result. */
public interface JSONString {
- /**
- * The toJSONString
method allows a class to produce its own JSON
- * serialization.
+ /** The toJSONString
method allows a class to produce its own JSON serialization.
*
- * @return A strictly syntactically correct JSON text.
- */
- public String toJSONString();
+ * @return A strictly syntactically correct JSON text. */
+ public String toJSONString ();
}
diff --git a/demos/vector-pinball/gdx-vectorpinball/src/com/dozingcatsoftware/bouncy/util/JSONStringer.java b/demos/vector-pinball/gdx-vectorpinball/src/com/dozingcatsoftware/bouncy/util/JSONStringer.java
index 6b6b3749809..5248d57d48c 100644
--- a/demos/vector-pinball/gdx-vectorpinball/src/com/dozingcatsoftware/bouncy/util/JSONStringer.java
+++ b/demos/vector-pinball/gdx-vectorpinball/src/com/dozingcatsoftware/bouncy/util/JSONStringer.java
@@ -1,78 +1,68 @@
+
package com.dozingcatsoftware.bouncy.util;
/*
-Copyright (c) 2006 JSON.org
+ Copyright (c) 2006 JSON.org
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
+ Permission is hereby granted, free of charge, to any person obtaining a copy
+ of this software and associated documentation files (the "Software"), to deal
+ in the Software without restriction, including without limitation the rights
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ copies of the Software, and to permit persons to whom the Software is
+ furnished to do so, subject to the following conditions:
-The above copyright notice and this permission notice shall be included in all
-copies or substantial portions of the Software.
+ The above copyright notice and this permission notice shall be included in all
+ copies or substantial portions of the Software.
-The Software shall be used for Good, not Evil.
+ The Software shall be used for Good, not Evil.
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
-SOFTWARE.
-*/
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ SOFTWARE.
+ */
import java.io.StringWriter;
-/**
- * JSONStringer provides a quick and convenient way of producing JSON text.
- * The texts produced strictly conform to JSON syntax rules. No whitespace is
- * added, so the results are ready for transmission or storage. Each instance of
- * JSONStringer can produce one JSON text.
+/** JSONStringer provides a quick and convenient way of producing JSON text. The texts produced strictly conform to JSON syntax
+ * rules. No whitespace is added, so the results are ready for transmission or storage. Each instance of JSONStringer can produce
+ * one JSON text.
*
- * A JSONStringer instance provides a value
method for appending
- * values to the
- * text, and a key
- * method for adding keys before values in objects. There are array
- * and endArray
methods that make and bound array values, and
- * object
and endObject
methods which make and bound
- * object values. All of these methods return the JSONWriter instance,
- * permitting cascade style. For example,
- * myString = new JSONStringer()
- * .object()
- * .key("JSON")
- * .value("Hello, World!")
- * .endObject()
- * .toString(); which produces the string
- * {"JSON":"Hello, World!"}
+ * A JSONStringer instance provides a value
method for appending values to the text, and a key
method
+ * for adding keys before values in objects. There are array
and endArray
methods that make and bound
+ * array values, and object
and endObject
methods which make and bound object values. All of these
+ * methods return the JSONWriter instance, permitting cascade style. For example,
+ *
+ *
+ * myString = new JSONStringer().object().key("JSON").value("Hello, World!").endObject().toString();
+ *
+ *
+ * which produces the string
+ *
+ *
+ * {"JSON":"Hello, World!"}
+ *
*
- * The first method called must be array
or object
.
- * There are no methods for adding commas or colons. JSONStringer adds them for
- * you. Objects and arrays can be nested up to 20 levels deep.
+ * The first method called must be array
or object
. There are no methods for adding commas or colons.
+ * JSONStringer adds them for you. Objects and arrays can be nested up to 20 levels deep.
*
* This can sometimes be easier than using a JSONObject to build a string.
* @author JSON.org
- * @version 2008-09-18
- */
+ * @version 2008-09-18 */
public class JSONStringer extends JSONWriter {
- /**
- * Make a fresh JSONStringer. It can be used to build one JSON text.
- */
- public JSONStringer() {
- super(new StringWriter());
- }
+ /** Make a fresh JSONStringer. It can be used to build one JSON text. */
+ public JSONStringer () {
+ super(new StringWriter());
+ }
- /**
- * Return the JSON text. This method is used to obtain the product of the
- * JSONStringer instance. It will return null
if there was a
- * problem in the construction of the JSON text (such as the calls to
- * array
were not properly balanced with calls to
- * endArray
).
- * @return The JSON text.
- */
- public String toString() {
- return this.mode == 'd' ? this.writer.toString() : null;
- }
+ /** Return the JSON text. This method is used to obtain the product of the JSONStringer instance. It will return
+ * null
if there was a problem in the construction of the JSON text (such as the calls to array
were
+ * not properly balanced with calls to endArray
).
+ * @return The JSON text. */
+ public String toString () {
+ return this.mode == 'd' ? this.writer.toString() : null;
+ }
}
diff --git a/demos/vector-pinball/gdx-vectorpinball/src/com/dozingcatsoftware/bouncy/util/JSONTokener.java b/demos/vector-pinball/gdx-vectorpinball/src/com/dozingcatsoftware/bouncy/util/JSONTokener.java
index b8e152bee3f..a7e88c5e37b 100644
--- a/demos/vector-pinball/gdx-vectorpinball/src/com/dozingcatsoftware/bouncy/util/JSONTokener.java
+++ b/demos/vector-pinball/gdx-vectorpinball/src/com/dozingcatsoftware/bouncy/util/JSONTokener.java
@@ -1,3 +1,4 @@
+
package com.dozingcatsoftware.bouncy.util;
import java.io.BufferedReader;
@@ -8,438 +9,366 @@
import java.io.StringReader;
/*
-Copyright (c) 2002 JSON.org
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in all
-copies or substantial portions of the Software.
-
-The Software shall be used for Good, not Evil.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
-SOFTWARE.
-*/
-
-/**
- * A JSONTokener takes a source string and extracts characters and tokens from
- * it. It is used by the JSONObject and JSONArray constructors to parse
- * JSON source strings.
- * @author JSON.org
- * @version 2010-12-24
+ Copyright (c) 2002 JSON.org
+
+ Permission is hereby granted, free of charge, to any person obtaining a copy
+ of this software and associated documentation files (the "Software"), to deal
+ in the Software without restriction, including without limitation the rights
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ copies of the Software, and to permit persons to whom the Software is
+ furnished to do so, subject to the following conditions:
+
+ The above copyright notice and this permission notice shall be included in all
+ copies or substantial portions of the Software.
+
+ The Software shall be used for Good, not Evil.
+
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ SOFTWARE.
*/
+
+/** A JSONTokener takes a source string and extracts characters and tokens from it. It is used by the JSONObject and JSONArray
+ * constructors to parse JSON source strings.
+ * @author JSON.org
+ * @version 2010-12-24 */
public class JSONTokener {
- private int character;
+ private int character;
private boolean eof;
- private int index;
- private int line;
- private char previous;
- private Reader reader;
- private boolean usePrevious;
-
-
- /**
- * Construct a JSONTokener from a Reader.
- *
- * @param reader A reader.
- */
- public JSONTokener(Reader reader) {
- this.reader = reader.markSupported() ?
- reader : new BufferedReader(reader);
- this.eof = false;
- this.usePrevious = false;
- this.previous = 0;
- this.index = 0;
- this.character = 1;
- this.line = 1;
- }
-
-
- /**
- * Construct a JSONTokener from an InputStream.
- */
- public JSONTokener(InputStream inputStream) throws JSONException {
- this(new InputStreamReader(inputStream));
- }
-
-
- /**
- * Construct a JSONTokener from a string.
- *
- * @param s A source string.
- */
- public JSONTokener(String s) {
- this(new StringReader(s));
- }
-
-
- /**
- * Back up one character. This provides a sort of lookahead capability,
- * so that you can test for a digit or letter before attempting to parse
- * the next number or identifier.
- */
- public void back() throws JSONException {
- if (usePrevious || index <= 0) {
- throw new JSONException("Stepping back two steps is not supported");
- }
- this.index -= 1;
- this.character -= 1;
- this.usePrevious = true;
- this.eof = false;
- }
-
-
- /**
- * Get the hex value of a character (base16).
- * @param c A character between '0' and '9' or between 'A' and 'F' or
- * between 'a' and 'f'.
- * @return An int between 0 and 15, or -1 if c was not a hex digit.
- */
- public static int dehexchar(char c) {
- if (c >= '0' && c <= '9') {
- return c - '0';
- }
- if (c >= 'A' && c <= 'F') {
- return c - ('A' - 10);
- }
- if (c >= 'a' && c <= 'f') {
- return c - ('a' - 10);
- }
- return -1;
- }
-
- public boolean end() {
- return eof && !usePrevious;
- }
-
-
- /**
- * Determine if the source string still contains characters that next()
- * can consume.
- * @return true if not yet at the end of the source.
- */
- public boolean more() throws JSONException {
- next();
- if (end()) {
- return false;
- }
- back();
- return true;
- }
-
-
- /**
- * Get the next character in the source string.
- *
- * @return The next character, or 0 if past the end of the source string.
- */
- public char next() throws JSONException {
- int c;
- if (this.usePrevious) {
- this.usePrevious = false;
- c = this.previous;
- } else {
- try {
- c = this.reader.read();
- } catch (IOException exception) {
- throw new JSONException(exception);
- }
-
- if (c <= 0) { // End of stream
- this.eof = true;
- c = 0;
- }
- }
- this.index += 1;
- if (this.previous == '\r') {
- this.line += 1;
- this.character = c == '\n' ? 0 : 1;
- } else if (c == '\n') {
- this.line += 1;
- this.character = 0;
- } else {
- this.character += 1;
- }
- this.previous = (char) c;
- return this.previous;
- }
-
-
- /**
- * Consume the next character, and check that it matches a specified
- * character.
- * @param c The character to match.
- * @return The character.
- * @throws JSONException if the character does not match.
- */
- public char next(char c) throws JSONException {
- char n = next();
- if (n != c) {
- throw syntaxError("Expected '" + c + "' and instead saw '" +
- n + "'");
- }
- return n;
- }
-
-
- /**
- * Get the next n characters.
- *
- * @param n The number of characters to take.
- * @return A string of n characters.
- * @throws JSONException
- * Substring bounds error if there are not
- * n characters remaining in the source string.
- */
- public String next(int n) throws JSONException {
- if (n == 0) {
- return "";
- }
-
- char[] chars = new char[n];
- int pos = 0;
-
- while (pos < n) {
- chars[pos] = next();
- if (end()) {
- throw syntaxError("Substring bounds error");
- }
- pos += 1;
- }
- return new String(chars);
- }
-
-
- /**
- * Get the next char in the string, skipping whitespace.
- * @throws JSONException
- * @return A character, or 0 if there are no more characters.
- */
- public char nextClean() throws JSONException {
- for (;;) {
- char c = next();
- if (c == 0 || c > ' ') {
- return c;
- }
- }
- }
-
-
- /**
- * Return the characters up to the next close quote character.
- * Backslash processing is done. The formal JSON format does not
- * allow strings in single quotes, but an implementation is allowed to
- * accept them.
- * @param quote The quoting character, either
- * "
(double quote) or
- * '
(single quote) .
- * @return A String.
- * @throws JSONException Unterminated string.
- */
- public String nextString(char quote) throws JSONException {
- char c;
- StringBuffer sb = new StringBuffer();
- for (;;) {
- c = next();
- switch (c) {
- case 0:
- case '\n':
- case '\r':
- throw syntaxError("Unterminated string");
- case '\\':
- c = next();
- switch (c) {
- case 'b':
- sb.append('\b');
- break;
- case 't':
- sb.append('\t');
- break;
- case 'n':
- sb.append('\n');
- break;
- case 'f':
- sb.append('\f');
- break;
- case 'r':
- sb.append('\r');
- break;
- case 'u':
- sb.append((char)Integer.parseInt(next(4), 16));
- break;
- case '"':
- case '\'':
- case '\\':
- case '/':
- sb.append(c);
- break;
- default:
- throw syntaxError("Illegal escape.");
- }
- break;
- default:
- if (c == quote) {
- return sb.toString();
- }
- sb.append(c);
- }
- }
- }
-
-
- /**
- * Get the text up but not including the specified character or the
- * end of line, whichever comes first.
- * @param delimiter A delimiter character.
- * @return A string.
- */
- public String nextTo(char delimiter) throws JSONException {
- StringBuffer sb = new StringBuffer();
- for (;;) {
- char c = next();
- if (c == delimiter || c == 0 || c == '\n' || c == '\r') {
- if (c != 0) {
- back();
- }
- return sb.toString().trim();
- }
- sb.append(c);
- }
- }
-
-
- /**
- * Get the text up but not including one of the specified delimiter
- * characters or the end of line, whichever comes first.
- * @param delimiters A set of delimiter characters.
- * @return A string, trimmed.
- */
- public String nextTo(String delimiters) throws JSONException {
- char c;
- StringBuffer sb = new StringBuffer();
- for (;;) {
- c = next();
- if (delimiters.indexOf(c) >= 0 || c == 0 ||
- c == '\n' || c == '\r') {
- if (c != 0) {
- back();
- }
- return sb.toString().trim();
- }
- sb.append(c);
- }
- }
-
-
- /**
- * Get the next value. The value can be a Boolean, Double, Integer,
- * JSONArray, JSONObject, Long, or String, or the JSONObject.NULL object.
- * @throws JSONException If syntax error.
- *
- * @return An object.
- */
- public Object nextValue() throws JSONException {
- char c = nextClean();
- String string;
-
- switch (c) {
- case '"':
- case '\'':
- return nextString(c);
- case '{':
- back();
- return new JSONObject(this);
- case '[':
- back();
- return new JSONArray(this);
- }
-
- /*
- * Handle unquoted text. This could be the values true, false, or
- * null, or it can be a number. An implementation (such as this one)
- * is allowed to also accept non-standard forms.
- *
- * Accumulate characters until we reach the end of the text or a
- * formatting character.
- */
-
- StringBuffer sb = new StringBuffer();
- while (c >= ' ' && ",:]}/\\\"[{;=#".indexOf(c) < 0) {
- sb.append(c);
- c = next();
- }
- back();
-
- string = sb.toString().trim();
- if (string.equals("")) {
- throw syntaxError("Missing value");
- }
- return JSONObject.stringToValue(string);
- }
-
-
- /**
- * Skip characters until the next character is the requested character.
- * If the requested character is not found, no characters are skipped.
- * @param to A character to skip to.
- * @return The requested character, or zero if the requested character
- * is not found.
- */
- public char skipTo(char to) throws JSONException {
- char c;
- try {
- int startIndex = this.index;
- int startCharacter = this.character;
- int startLine = this.line;
- reader.mark(Integer.MAX_VALUE);
- do {
- c = next();
- if (c == 0) {
- reader.reset();
- this.index = startIndex;
- this.character = startCharacter;
- this.line = startLine;
- return c;
- }
- } while (c != to);
- } catch (IOException exc) {
- throw new JSONException(exc);
- }
-
- back();
- return c;
- }
-
-
- /**
- * Make a JSONException to signal a syntax error.
- *
- * @param message The error message.
- * @return A JSONException object, suitable for throwing
- */
- public JSONException syntaxError(String message) {
- return new JSONException(message + toString());
- }
-
-
- /**
- * Make a printable string of this JSONTokener.
- *
- * @return " at {index} [character {character} line {line}]"
- */
- public String toString() {
- return " at " + index + " [character " + this.character + " line " +
- this.line + "]";
- }
-}
\ No newline at end of file
+ private int index;
+ private int line;
+ private char previous;
+ private Reader reader;
+ private boolean usePrevious;
+
+ /** Construct a JSONTokener from a Reader.
+ *
+ * @param reader A reader. */
+ public JSONTokener (Reader reader) {
+ this.reader = reader.markSupported() ? reader : new BufferedReader(reader);
+ this.eof = false;
+ this.usePrevious = false;
+ this.previous = 0;
+ this.index = 0;
+ this.character = 1;
+ this.line = 1;
+ }
+
+ /** Construct a JSONTokener from an InputStream. */
+ public JSONTokener (InputStream inputStream) throws JSONException {
+ this(new InputStreamReader(inputStream));
+ }
+
+ /** Construct a JSONTokener from a string.
+ *
+ * @param s A source string. */
+ public JSONTokener (String s) {
+ this(new StringReader(s));
+ }
+
+ /** Back up one character. This provides a sort of lookahead capability, so that you can test for a digit or letter before
+ * attempting to parse the next number or identifier. */
+ public void back () throws JSONException {
+ if (usePrevious || index <= 0) {
+ throw new JSONException("Stepping back two steps is not supported");
+ }
+ this.index -= 1;
+ this.character -= 1;
+ this.usePrevious = true;
+ this.eof = false;
+ }
+
+ /** Get the hex value of a character (base16).
+ * @param c A character between '0' and '9' or between 'A' and 'F' or between 'a' and 'f'.
+ * @return An int between 0 and 15, or -1 if c was not a hex digit. */
+ public static int dehexchar (char c) {
+ if (c >= '0' && c <= '9') {
+ return c - '0';
+ }
+ if (c >= 'A' && c <= 'F') {
+ return c - ('A' - 10);
+ }
+ if (c >= 'a' && c <= 'f') {
+ return c - ('a' - 10);
+ }
+ return -1;
+ }
+
+ public boolean end () {
+ return eof && !usePrevious;
+ }
+
+ /** Determine if the source string still contains characters that next() can consume.
+ * @return true if not yet at the end of the source. */
+ public boolean more () throws JSONException {
+ next();
+ if (end()) {
+ return false;
+ }
+ back();
+ return true;
+ }
+
+ /** Get the next character in the source string.
+ *
+ * @return The next character, or 0 if past the end of the source string. */
+ public char next () throws JSONException {
+ int c;
+ if (this.usePrevious) {
+ this.usePrevious = false;
+ c = this.previous;
+ } else {
+ try {
+ c = this.reader.read();
+ } catch (IOException exception) {
+ throw new JSONException(exception);
+ }
+
+ if (c <= 0) { // End of stream
+ this.eof = true;
+ c = 0;
+ }
+ }
+ this.index += 1;
+ if (this.previous == '\r') {
+ this.line += 1;
+ this.character = c == '\n' ? 0 : 1;
+ } else if (c == '\n') {
+ this.line += 1;
+ this.character = 0;
+ } else {
+ this.character += 1;
+ }
+ this.previous = (char)c;
+ return this.previous;
+ }
+
+ /** Consume the next character, and check that it matches a specified character.
+ * @param c The character to match.
+ * @return The character.
+ * @throws JSONException if the character does not match. */
+ public char next (char c) throws JSONException {
+ char n = next();
+ if (n != c) {
+ throw syntaxError("Expected '" + c + "' and instead saw '" + n + "'");
+ }
+ return n;
+ }
+
+ /** Get the next n characters.
+ *
+ * @param n The number of characters to take.
+ * @return A string of n characters.
+ * @throws JSONException Substring bounds error if there are not n characters remaining in the source string. */
+ public String next (int n) throws JSONException {
+ if (n == 0) {
+ return "";
+ }
+
+ char[] chars = new char[n];
+ int pos = 0;
+
+ while (pos < n) {
+ chars[pos] = next();
+ if (end()) {
+ throw syntaxError("Substring bounds error");
+ }
+ pos += 1;
+ }
+ return new String(chars);
+ }
+
+ /** Get the next char in the string, skipping whitespace.
+ * @throws JSONException
+ * @return A character, or 0 if there are no more characters. */
+ public char nextClean () throws JSONException {
+ for (;;) {
+ char c = next();
+ if (c == 0 || c > ' ') {
+ return c;
+ }
+ }
+ }
+
+ /** Return the characters up to the next close quote character. Backslash processing is done. The formal JSON format does not
+ * allow strings in single quotes, but an implementation is allowed to accept them.
+ * @param quote The quoting character, either "
(double quote) or '
+ * (single quote) .
+ * @return A String.
+ * @throws JSONException Unterminated string. */
+ public String nextString (char quote) throws JSONException {
+ char c;
+ StringBuffer sb = new StringBuffer();
+ for (;;) {
+ c = next();
+ switch (c) {
+ case 0:
+ case '\n':
+ case '\r':
+ throw syntaxError("Unterminated string");
+ case '\\':
+ c = next();
+ switch (c) {
+ case 'b':
+ sb.append('\b');
+ break;
+ case 't':
+ sb.append('\t');
+ break;
+ case 'n':
+ sb.append('\n');
+ break;
+ case 'f':
+ sb.append('\f');
+ break;
+ case 'r':
+ sb.append('\r');
+ break;
+ case 'u':
+ sb.append((char)Integer.parseInt(next(4), 16));
+ break;
+ case '"':
+ case '\'':
+ case '\\':
+ case '/':
+ sb.append(c);
+ break;
+ default:
+ throw syntaxError("Illegal escape.");
+ }
+ break;
+ default:
+ if (c == quote) {
+ return sb.toString();
+ }
+ sb.append(c);
+ }
+ }
+ }
+
+ /** Get the text up but not including the specified character or the end of line, whichever comes first.
+ * @param delimiter A delimiter character.
+ * @return A string. */
+ public String nextTo (char delimiter) throws JSONException {
+ StringBuffer sb = new StringBuffer();
+ for (;;) {
+ char c = next();
+ if (c == delimiter || c == 0 || c == '\n' || c == '\r') {
+ if (c != 0) {
+ back();
+ }
+ return sb.toString().trim();
+ }
+ sb.append(c);
+ }
+ }
+
+ /** Get the text up but not including one of the specified delimiter characters or the end of line, whichever comes first.
+ * @param delimiters A set of delimiter characters.
+ * @return A string, trimmed. */
+ public String nextTo (String delimiters) throws JSONException {
+ char c;
+ StringBuffer sb = new StringBuffer();
+ for (;;) {
+ c = next();
+ if (delimiters.indexOf(c) >= 0 || c == 0 || c == '\n' || c == '\r') {
+ if (c != 0) {
+ back();
+ }
+ return sb.toString().trim();
+ }
+ sb.append(c);
+ }
+ }
+
+ /** Get the next value. The value can be a Boolean, Double, Integer, JSONArray, JSONObject, Long, or String, or the
+ * JSONObject.NULL object.
+ * @throws JSONException If syntax error.
+ *
+ * @return An object. */
+ public Object nextValue () throws JSONException {
+ char c = nextClean();
+ String string;
+
+ switch (c) {
+ case '"':
+ case '\'':
+ return nextString(c);
+ case '{':
+ back();
+ return new JSONObject(this);
+ case '[':
+ back();
+ return new JSONArray(this);
+ }
+
+ /*
+ * Handle unquoted text. This could be the values true, false, or null, or it can be a number. An implementation (such as
+ * this one) is allowed to also accept non-standard forms.
+ *
+ * Accumulate characters until we reach the end of the text or a formatting character.
+ */
+
+ StringBuffer sb = new StringBuffer();
+ while (c >= ' ' && ",:]}/\\\"[{;=#".indexOf(c) < 0) {
+ sb.append(c);
+ c = next();
+ }
+ back();
+
+ string = sb.toString().trim();
+ if (string.equals("")) {
+ throw syntaxError("Missing value");
+ }
+ return JSONObject.stringToValue(string);
+ }
+
+ /** Skip characters until the next character is the requested character. If the requested character is not found, no characters
+ * are skipped.
+ * @param to A character to skip to.
+ * @return The requested character, or zero if the requested character is not found. */
+ public char skipTo (char to) throws JSONException {
+ char c;
+ try {
+ int startIndex = this.index;
+ int startCharacter = this.character;
+ int startLine = this.line;
+ reader.mark(Integer.MAX_VALUE);
+ do {
+ c = next();
+ if (c == 0) {
+ reader.reset();
+ this.index = startIndex;
+ this.character = startCharacter;
+ this.line = startLine;
+ return c;
+ }
+ } while (c != to);
+ } catch (IOException exc) {
+ throw new JSONException(exc);
+ }
+
+ back();
+ return c;
+ }
+
+ /** Make a JSONException to signal a syntax error.
+ *
+ * @param message The error message.
+ * @return A JSONException object, suitable for throwing */
+ public JSONException syntaxError (String message) {
+ return new JSONException(message + toString());
+ }
+
+ /** Make a printable string of this JSONTokener.
+ *
+ * @return " at {index} [character {character} line {line}]" */
+ public String toString () {
+ return " at " + index + " [character " + this.character + " line " + this.line + "]";
+ }
+}
diff --git a/demos/vector-pinball/gdx-vectorpinball/src/com/dozingcatsoftware/bouncy/util/JSONUtils.java b/demos/vector-pinball/gdx-vectorpinball/src/com/dozingcatsoftware/bouncy/util/JSONUtils.java
index aeb632db574..51e2cbc600b 100644
--- a/demos/vector-pinball/gdx-vectorpinball/src/com/dozingcatsoftware/bouncy/util/JSONUtils.java
+++ b/demos/vector-pinball/gdx-vectorpinball/src/com/dozingcatsoftware/bouncy/util/JSONUtils.java
@@ -9,10 +9,8 @@
public class JSONUtils {
- /**
- * If argument is a JSONArray or JSONObject, returns the equivalent List or Map. If argument is JSONObject.NULL, returns null.
- * Otherwise, returns the argument unchanged.
- */
+ /** If argument is a JSONArray or JSONObject, returns the equivalent List or Map. If argument is JSONObject.NULL, returns null.
+ * Otherwise, returns the argument unchanged. */
public static Object objectFromJSONItem (Object jsonItem) {
if (jsonItem == JSONObject.NULL) {
return null;
@@ -26,10 +24,8 @@ public static Object objectFromJSONItem (Object jsonItem) {
return jsonItem;
}
- /**
- * Returns a List with the same objects in the same order as jsonArray. Recursively converts nested JSONArray and JSONObject
- * values to List and Map objects.
- */
+ /** Returns a List with the same objects in the same order as jsonArray. Recursively converts nested JSONArray and JSONObject
+ * values to List and Map objects. */
public static List listFromJSONArray (JSONArray jsonArray) {
List result = new ArrayList();
try {
@@ -43,10 +39,8 @@ public static List listFromJSONArray (JSONArray jsonArray) {
return result;
}
- /**
- * Returns a List with the same keys and values as jsonObject. Recursively converts nested JSONArray and JSONObject values to
- * List and Map objects.
- */
+ /** Returns a List with the same keys and values as jsonObject. Recursively converts nested JSONArray and JSONObject values to
+ * List and Map objects. */
public static Map mapFromJSONObject (JSONObject jsonObject) {
Map result = new HashMap();
try {
@@ -61,9 +55,7 @@ public static Map mapFromJSONObject (JSONObject jsonObject) {
return result;
}
- /**
- * Returns a List created by parsing the string argument as a JSON array and calling listFromJSONArray.
- */
+ /** Returns a List created by parsing the string argument as a JSON array and calling listFromJSONArray. */
public static List listFromJSONString (String jsonString) {
try {
return listFromJSONArray(new JSONArray(jsonString));
@@ -72,9 +64,7 @@ public static List listFromJSONString (String jsonString) {
}
}
- /**
- * Returns a Map created by parsing the string argument as a JSON object and calling mapFromJSONObject.
- */
+ /** Returns a Map created by parsing the string argument as a JSON object and calling mapFromJSONObject. */
public static Map mapFromJSONString (String jsonString) {
try {
return mapFromJSONObject(new JSONObject(jsonString));
diff --git a/demos/vector-pinball/gdx-vectorpinball/src/com/dozingcatsoftware/bouncy/util/JSONWriter.java b/demos/vector-pinball/gdx-vectorpinball/src/com/dozingcatsoftware/bouncy/util/JSONWriter.java
index 67572475494..0b2cfdbf787 100644
--- a/demos/vector-pinball/gdx-vectorpinball/src/com/dozingcatsoftware/bouncy/util/JSONWriter.java
+++ b/demos/vector-pinball/gdx-vectorpinball/src/com/dozingcatsoftware/bouncy/util/JSONWriter.java
@@ -1,323 +1,261 @@
+
package com.dozingcatsoftware.bouncy.util;
import java.io.IOException;
import java.io.Writer;
/*
-Copyright (c) 2006 JSON.org
+ Copyright (c) 2006 JSON.org
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
+ Permission is hereby granted, free of charge, to any person obtaining a copy
+ of this software and associated documentation files (the "Software"), to deal
+ in the Software without restriction, including without limitation the rights
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ copies of the Software, and to permit persons to whom the Software is
+ furnished to do so, subject to the following conditions:
-The above copyright notice and this permission notice shall be included in all
-copies or substantial portions of the Software.
+ The above copyright notice and this permission notice shall be included in all
+ copies or substantial portions of the Software.
-The Software shall be used for Good, not Evil.
+ The Software shall be used for Good, not Evil.
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
-SOFTWARE.
-*/
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ SOFTWARE.
+ */
-/**
- * JSONWriter provides a quick and convenient way of producing JSON text.
- * The texts produced strictly conform to JSON syntax rules. No whitespace is
- * added, so the results are ready for transmission or storage. Each instance of
- * JSONWriter can produce one JSON text.
+/** JSONWriter provides a quick and convenient way of producing JSON text. The texts produced strictly conform to JSON syntax
+ * rules. No whitespace is added, so the results are ready for transmission or storage. Each instance of JSONWriter can produce
+ * one JSON text.
*
- * A JSONWriter instance provides a value
method for appending
- * values to the
- * text, and a key
- * method for adding keys before values in objects. There are array
- * and endArray
methods that make and bound array values, and
- * object
and endObject
methods which make and bound
- * object values. All of these methods return the JSONWriter instance,
- * permitting a cascade style. For example,
- * new JSONWriter(myWriter)
- * .object()
- * .key("JSON")
- * .value("Hello, World!")
- * .endObject(); which writes
- * {"JSON":"Hello, World!"}
+ * A JSONWriter instance provides a value
method for appending values to the text, and a key
method for
+ * adding keys before values in objects. There are array
and endArray
methods that make and bound array
+ * values, and object
and endObject
methods which make and bound object values. All of these methods
+ * return the JSONWriter instance, permitting a cascade style. For example,
+ *
+ *
+ * new JSONWriter(myWriter).object().key("JSON").value("Hello, World!").endObject();
+ *
+ *
+ * which writes
+ *
+ *
+ * {"JSON":"Hello, World!"}
+ *
*
- * The first method called must be array
or object
.
- * There are no methods for adding commas or colons. JSONWriter adds them for
- * you. Objects and arrays can be nested up to 20 levels deep.
+ * The first method called must be array
or object
. There are no methods for adding commas or colons.
+ * JSONWriter adds them for you. Objects and arrays can be nested up to 20 levels deep.
*
* This can sometimes be easier than using a JSONObject to build a string.
* @author JSON.org
- * @version 2010-12-24
- */
+ * @version 2010-12-24 */
public class JSONWriter {
- private static final int maxdepth = 20;
-
- /**
- * The comma flag determines if a comma should be output before the next
- * value.
- */
- private boolean comma;
-
- /**
- * The current mode. Values:
- * 'a' (array),
- * 'd' (done),
- * 'i' (initial),
- * 'k' (key),
- * 'o' (object).
- */
- protected char mode;
-
- /**
- * The object/array stack.
- */
- private JSONObject stack[];
-
- /**
- * The stack top index. A value of 0 indicates that the stack is empty.
- */
- private int top;
+ private static final int maxdepth = 20;
- /**
- * The writer that will receive the output.
- */
- protected Writer writer;
+ /** The comma flag determines if a comma should be output before the next value. */
+ private boolean comma;
- /**
- * Make a fresh JSONWriter. It can be used to build one JSON text.
- */
- public JSONWriter(Writer w) {
- this.comma = false;
- this.mode = 'i';
- this.stack = new JSONObject[maxdepth];
- this.top = 0;
- this.writer = w;
- }
+ /** The current mode. Values: 'a' (array), 'd' (done), 'i' (initial), 'k' (key), 'o' (object). */
+ protected char mode;
- /**
- * Append a value.
- * @param string A string value.
- * @return this
- * @throws JSONException If the value is out of sequence.
- */
- private JSONWriter append(String string) throws JSONException {
- if (string == null) {
- throw new JSONException("Null pointer");
- }
- if (this.mode == 'o' || this.mode == 'a') {
- try {
- if (this.comma && this.mode == 'a') {
- this.writer.write(',');
- }
- this.writer.write(string);
- } catch (IOException e) {
- throw new JSONException(e);
- }
- if (this.mode == 'o') {
- this.mode = 'k';
- }
- this.comma = true;
- return this;
- }
- throw new JSONException("Value out of sequence.");
- }
+ /** The object/array stack. */
+ private JSONObject stack[];
- /**
- * Begin appending a new array. All values until the balancing
- * endArray
will be appended to this array. The
- * endArray
method must be called to mark the array's end.
- * @return this
- * @throws JSONException If the nesting is too deep, or if the object is
- * started in the wrong place (for example as a key or after the end of the
- * outermost array or object).
- */
- public JSONWriter array() throws JSONException {
- if (this.mode == 'i' || this.mode == 'o' || this.mode == 'a') {
- this.push(null);
- this.append("[");
- this.comma = false;
- return this;
- }
- throw new JSONException("Misplaced array.");
- }
+ /** The stack top index. A value of 0 indicates that the stack is empty. */
+ private int top;
- /**
- * End something.
- * @param mode Mode
- * @param c Closing character
- * @return this
- * @throws JSONException If unbalanced.
- */
- private JSONWriter end(char mode, char c) throws JSONException {
- if (this.mode != mode) {
- throw new JSONException(mode == 'a' ? "Misplaced endArray." :
- "Misplaced endObject.");
- }
- this.pop(mode);
- try {
- this.writer.write(c);
- } catch (IOException e) {
- throw new JSONException(e);
- }
- this.comma = true;
- return this;
- }
+ /** The writer that will receive the output. */
+ protected Writer writer;
- /**
- * End an array. This method most be called to balance calls to
- * array
.
- * @return this
- * @throws JSONException If incorrectly nested.
- */
- public JSONWriter endArray() throws JSONException {
- return this.end('a', ']');
- }
+ /** Make a fresh JSONWriter. It can be used to build one JSON text. */
+ public JSONWriter (Writer w) {
+ this.comma = false;
+ this.mode = 'i';
+ this.stack = new JSONObject[maxdepth];
+ this.top = 0;
+ this.writer = w;
+ }
- /**
- * End an object. This method most be called to balance calls to
- * object
.
- * @return this
- * @throws JSONException If incorrectly nested.
- */
- public JSONWriter endObject() throws JSONException {
- return this.end('k', '}');
- }
+ /** Append a value.
+ * @param string A string value.
+ * @return this
+ * @throws JSONException If the value is out of sequence. */
+ private JSONWriter append (String string) throws JSONException {
+ if (string == null) {
+ throw new JSONException("Null pointer");
+ }
+ if (this.mode == 'o' || this.mode == 'a') {
+ try {
+ if (this.comma && this.mode == 'a') {
+ this.writer.write(',');
+ }
+ this.writer.write(string);
+ } catch (IOException e) {
+ throw new JSONException(e);
+ }
+ if (this.mode == 'o') {
+ this.mode = 'k';
+ }
+ this.comma = true;
+ return this;
+ }
+ throw new JSONException("Value out of sequence.");
+ }
- /**
- * Append a key. The key will be associated with the next value. In an
- * object, every value must be preceded by a key.
- * @param string A key string.
- * @return this
- * @throws JSONException If the key is out of place. For example, keys
- * do not belong in arrays or if the key is null.
- */
- public JSONWriter key(String string) throws JSONException {
- if (string == null) {
- throw new JSONException("Null key.");
- }
- if (this.mode == 'k') {
- try {
- stack[top - 1].putOnce(string, Boolean.TRUE);
- if (this.comma) {
- this.writer.write(',');
- }
- this.writer.write(JSONObject.quote(string));
- this.writer.write(':');
- this.comma = false;
- this.mode = 'o';
- return this;
- } catch (IOException e) {
- throw new JSONException(e);
- }
- }
- throw new JSONException("Misplaced key.");
- }
+ /** Begin appending a new array. All values until the balancing endArray
will be appended to this array. The
+ * endArray
method must be called to mark the array's end.
+ * @return this
+ * @throws JSONException If the nesting is too deep, or if the object is started in the wrong place (for example as a key or
+ * after the end of the outermost array or object). */
+ public JSONWriter array () throws JSONException {
+ if (this.mode == 'i' || this.mode == 'o' || this.mode == 'a') {
+ this.push(null);
+ this.append("[");
+ this.comma = false;
+ return this;
+ }
+ throw new JSONException("Misplaced array.");
+ }
+ /** End something.
+ * @param mode Mode
+ * @param c Closing character
+ * @return this
+ * @throws JSONException If unbalanced. */
+ private JSONWriter end (char mode, char c) throws JSONException {
+ if (this.mode != mode) {
+ throw new JSONException(mode == 'a' ? "Misplaced endArray." : "Misplaced endObject.");
+ }
+ this.pop(mode);
+ try {
+ this.writer.write(c);
+ } catch (IOException e) {
+ throw new JSONException(e);
+ }
+ this.comma = true;
+ return this;
+ }
- /**
- * Begin appending a new object. All keys and values until the balancing
- * endObject
will be appended to this object. The
- * endObject
method must be called to mark the object's end.
- * @return this
- * @throws JSONException If the nesting is too deep, or if the object is
- * started in the wrong place (for example as a key or after the end of the
- * outermost array or object).
- */
- public JSONWriter object() throws JSONException {
- if (this.mode == 'i') {
- this.mode = 'o';
- }
- if (this.mode == 'o' || this.mode == 'a') {
- this.append("{");
- this.push(new JSONObject());
- this.comma = false;
- return this;
- }
- throw new JSONException("Misplaced object.");
+ /** End an array. This method most be called to balance calls to array
.
+ * @return this
+ * @throws JSONException If incorrectly nested. */
+ public JSONWriter endArray () throws JSONException {
+ return this.end('a', ']');
+ }
- }
+ /** End an object. This method most be called to balance calls to object
.
+ * @return this
+ * @throws JSONException If incorrectly nested. */
+ public JSONWriter endObject () throws JSONException {
+ return this.end('k', '}');
+ }
+ /** Append a key. The key will be associated with the next value. In an object, every value must be preceded by a key.
+ * @param string A key string.
+ * @return this
+ * @throws JSONException If the key is out of place. For example, keys do not belong in arrays or if the key is null. */
+ public JSONWriter key (String string) throws JSONException {
+ if (string == null) {
+ throw new JSONException("Null key.");
+ }
+ if (this.mode == 'k') {
+ try {
+ stack[top - 1].putOnce(string, Boolean.TRUE);
+ if (this.comma) {
+ this.writer.write(',');
+ }
+ this.writer.write(JSONObject.quote(string));
+ this.writer.write(':');
+ this.comma = false;
+ this.mode = 'o';
+ return this;
+ } catch (IOException e) {
+ throw new JSONException(e);
+ }
+ }
+ throw new JSONException("Misplaced key.");
+ }
- /**
- * Pop an array or object scope.
- * @param c The scope to close.
- * @throws JSONException If nesting is wrong.
- */
- private void pop(char c) throws JSONException {
- if (this.top <= 0) {
- throw new JSONException("Nesting error.");
- }
- char m = this.stack[this.top - 1] == null ? 'a' : 'k';
- if (m != c) {
- throw new JSONException("Nesting error.");
- }
- this.top -= 1;
- this.mode = this.top == 0 ?
- 'd' : this.stack[this.top - 1] == null ? 'a' : 'k';
- }
+ /** Begin appending a new object. All keys and values until the balancing endObject
will be appended to this
+ * object. The endObject
method must be called to mark the object's end.
+ * @return this
+ * @throws JSONException If the nesting is too deep, or if the object is started in the wrong place (for example as a key or
+ * after the end of the outermost array or object). */
+ public JSONWriter object () throws JSONException {
+ if (this.mode == 'i') {
+ this.mode = 'o';
+ }
+ if (this.mode == 'o' || this.mode == 'a') {
+ this.append("{");
+ this.push(new JSONObject());
+ this.comma = false;
+ return this;
+ }
+ throw new JSONException("Misplaced object.");
- /**
- * Push an array or object scope.
- * @param c The scope to open.
- * @throws JSONException If nesting is too deep.
- */
- private void push(JSONObject jo) throws JSONException {
- if (this.top >= maxdepth) {
- throw new JSONException("Nesting too deep.");
- }
- this.stack[this.top] = jo;
- this.mode = jo == null ? 'a' : 'k';
- this.top += 1;
- }
+ }
+ /** Pop an array or object scope.
+ * @param c The scope to close.
+ * @throws JSONException If nesting is wrong. */
+ private void pop (char c) throws JSONException {
+ if (this.top <= 0) {
+ throw new JSONException("Nesting error.");
+ }
+ char m = this.stack[this.top - 1] == null ? 'a' : 'k';
+ if (m != c) {
+ throw new JSONException("Nesting error.");
+ }
+ this.top -= 1;
+ this.mode = this.top == 0 ? 'd' : this.stack[this.top - 1] == null ? 'a' : 'k';
+ }
- /**
- * Append either the value true
or the value
- * false
.
- * @param b A boolean.
- * @return this
- * @throws JSONException
- */
- public JSONWriter value(boolean b) throws JSONException {
- return this.append(b ? "true" : "false");
- }
+ /** Push an array or object scope.
+ * @param c The scope to open.
+ * @throws JSONException If nesting is too deep. */
+ private void push (JSONObject jo) throws JSONException {
+ if (this.top >= maxdepth) {
+ throw new JSONException("Nesting too deep.");
+ }
+ this.stack[this.top] = jo;
+ this.mode = jo == null ? 'a' : 'k';
+ this.top += 1;
+ }
- /**
- * Append a double value.
- * @param d A double.
- * @return this
- * @throws JSONException If the number is not finite.
- */
- public JSONWriter value(double d) throws JSONException {
- return this.value(new Double(d));
- }
+ /** Append either the value true
or the value false
.
+ * @param b A boolean.
+ * @return this
+ * @throws JSONException */
+ public JSONWriter value (boolean b) throws JSONException {
+ return this.append(b ? "true" : "false");
+ }
- /**
- * Append a long value.
- * @param l A long.
- * @return this
- * @throws JSONException
- */
- public JSONWriter value(long l) throws JSONException {
- return this.append(Long.toString(l));
- }
+ /** Append a double value.
+ * @param d A double.
+ * @return this
+ * @throws JSONException If the number is not finite. */
+ public JSONWriter value (double d) throws JSONException {
+ return this.value(new Double(d));
+ }
+ /** Append a long value.
+ * @param l A long.
+ * @return this
+ * @throws JSONException */
+ public JSONWriter value (long l) throws JSONException {
+ return this.append(Long.toString(l));
+ }
- /**
- * Append an object value.
- * @param object The object to append. It can be null, or a Boolean, Number,
- * String, JSONObject, or JSONArray, or an object that implements JSONString.
- * @return this
- * @throws JSONException If the value is out of sequence.
- */
- public JSONWriter value(Object object) throws JSONException {
- return this.append(JSONObject.valueToString(object));
- }
+ /** Append an object value.
+ * @param object The object to append. It can be null, or a Boolean, Number, String, JSONObject, or JSONArray, or an object
+ * that implements JSONString.
+ * @return this
+ * @throws JSONException If the value is out of sequence. */
+ public JSONWriter value (Object object) throws JSONException {
+ return this.append(JSONObject.valueToString(object));
+ }
}
diff --git a/demos/very-angry-robots/very-angry-robots-android/src/com/badlydrawngames/veryangryrobots/android/VeryAngryRobotsActivity.java b/demos/very-angry-robots/very-angry-robots-android/src/com/badlydrawngames/veryangryrobots/android/VeryAngryRobotsActivity.java
index bfaac804e7b..cb9d149c975 100644
--- a/demos/very-angry-robots/very-angry-robots-android/src/com/badlydrawngames/veryangryrobots/android/VeryAngryRobotsActivity.java
+++ b/demos/very-angry-robots/very-angry-robots-android/src/com/badlydrawngames/veryangryrobots/android/VeryAngryRobotsActivity.java
@@ -1,3 +1,4 @@
+
package com.badlydrawngames.veryangryrobots.android;
import android.os.Bundle;
@@ -7,15 +8,15 @@
import com.badlydrawngames.veryangryrobots.VeryAngryRobotsGame;
public class VeryAngryRobotsActivity extends AndroidApplication {
- /** Called when the activity is first created. */
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- AndroidApplicationConfiguration config = new AndroidApplicationConfiguration();
- config.useCompass = false;
- config.useAccelerometer = false;
- config.useGL20 = false;
- VeryAngryRobotsGame game = new VeryAngryRobotsGame();
- initialize(game, config);
- }
+ /** Called when the activity is first created. */
+ @Override
+ public void onCreate (Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ AndroidApplicationConfiguration config = new AndroidApplicationConfiguration();
+ config.useCompass = false;
+ config.useAccelerometer = false;
+ config.useGL20 = false;
+ VeryAngryRobotsGame game = new VeryAngryRobotsGame();
+ initialize(game, config);
+ }
}
diff --git a/demos/very-angry-robots/very-angry-robots/src/com/badlydrawngames/general/CameraHelper.java b/demos/very-angry-robots/very-angry-robots/src/com/badlydrawngames/general/CameraHelper.java
index 7a6c10966c6..72e8ffcabae 100644
--- a/demos/very-angry-robots/very-angry-robots/src/com/badlydrawngames/general/CameraHelper.java
+++ b/demos/very-angry-robots/very-angry-robots/src/com/badlydrawngames/general/CameraHelper.java
@@ -18,50 +18,46 @@
import com.badlogic.gdx.math.Vector2;
public final class CameraHelper {
-
- private CameraHelper() {}
- /**
- * Creates an orthographic camera where the "play area" has the given viewport size. The viewport will either be
- * stretched to fill the entire window, or it will be scaled to maintain the aspect ratio.
+ private CameraHelper () {
+ }
+
+ /** Creates an orthographic camera where the "play area" has the given viewport size. The viewport will either be stretched to
+ * fill the entire window, or it will be scaled to maintain the aspect ratio.
*
* @param isStretched true if the "play area" is stretched to fill the entire window.
* @param virtualWidth the width of the game screen in virtual pixels.
* @param virtualHeight the height of the game screen in virtual pixels.
- * @return the new camera.
- */
- public static OrthographicCamera createCamera(boolean isStretched, float virtualWidth, float virtualHeight) {
+ * @return the new camera. */
+ public static OrthographicCamera createCamera (boolean isStretched, float virtualWidth, float virtualHeight) {
// Get the viewport size.
Vector2 viewportSize = viewportSize(isStretched, virtualWidth, virtualHeight);
float viewportWidth = viewportSize.x;
float viewportHeight = viewportSize.y;
-
+
// Create the camera, placing the origin at the bottom left of the viewport.
OrthographicCamera camera = new OrthographicCamera(viewportWidth, viewportHeight);
float xOrg = (viewportWidth - virtualWidth) / 2;
- float yOrg = (viewportHeight - virtualHeight) / 2;
+ float yOrg = (viewportHeight - virtualHeight) / 2;
camera.position.set(viewportWidth / 2 - xOrg, viewportHeight / 2 - yOrg, 0);
camera.update();
return camera;
}
- /**
- * Calculates the dimensions of the viewport required to support the given virtual coordinates.
+ /** Calculates the dimensions of the viewport required to support the given virtual coordinates.
*
* @param isStretched true if the viewport should be stretched to fill the entire window.
* @param virtualWidth the width of the viewport in virtual units.
* @param virtualHeight the height of the viewport in virtual units.
- * @return the viewport's dimensions.
- */
- public static Vector2 viewportSize(boolean isStretched, float virtualWidth, float virtualHeight) {
+ * @return the viewport's dimensions. */
+ public static Vector2 viewportSize (boolean isStretched, float virtualWidth, float virtualHeight) {
float viewportWidth;
float viewportHeight;
if (isStretched) {
// Stretch the camera to fill the entire screen.
viewportWidth = virtualWidth;
viewportHeight = virtualHeight;
- }
- else {
+ } else {
// Maintain the aspect ratio by letterboxing.
float aspect = virtualWidth / virtualHeight;
float physicalWidth = Gdx.graphics.getWidth();
@@ -70,8 +66,7 @@ public static Vector2 viewportSize(boolean isStretched, float virtualWidth, floa
// Letterbox left and right.
viewportHeight = virtualHeight;
viewportWidth = viewportHeight * physicalWidth / physicalHeight;
- }
- else {
+ } else {
// Letterbox above and below.
viewportWidth = virtualWidth;
viewportHeight = viewportWidth * physicalHeight / physicalWidth;
@@ -79,29 +74,28 @@ public static Vector2 viewportSize(boolean isStretched, float virtualWidth, floa
}
return new Vector2(viewportWidth, viewportHeight);
}
-
+
public static enum ViewportMode {
- PIXEL_PERFECT,
- STRETCH_TO_ASPECT,
- STRETCH_TO_SCREEN
+ PIXEL_PERFECT, STRETCH_TO_ASPECT, STRETCH_TO_SCREEN
}
-
- public static OrthographicCamera createCamera2(ViewportMode viewportMode, float virtualWidth, float virtualHeight, float density) {
+
+ public static OrthographicCamera createCamera2 (ViewportMode viewportMode, float virtualWidth, float virtualHeight,
+ float density) {
// Get the viewport size.
Vector2 viewportSize = sizeToDensity(viewportMode, virtualWidth, virtualHeight, density);
float viewportWidth = viewportSize.x;
float viewportHeight = viewportSize.y;
-
+
// Create the camera, placing the origin at the bottom left of the viewport.
OrthographicCamera camera = new OrthographicCamera(viewportWidth, viewportHeight);
float xOrg = (viewportWidth - virtualWidth) / 2;
- float yOrg = (viewportHeight - virtualHeight) / 2;
+ float yOrg = (viewportHeight - virtualHeight) / 2;
camera.position.set(viewportWidth / 2 - xOrg, viewportHeight / 2 - yOrg, 0);
camera.update();
return camera;
}
-
- public static Vector2 sizeToDensity(ViewportMode viewportMode, float virtualWidth, float virtualHeight, float density) {
+
+ public static Vector2 sizeToDensity (ViewportMode viewportMode, float virtualWidth, float virtualHeight, float density) {
float viewportWidth = virtualWidth;
float viewportHeight = virtualHeight;
float physicalWidth = Gdx.graphics.getWidth();
@@ -111,15 +105,13 @@ public static Vector2 sizeToDensity(ViewportMode viewportMode, float virtualWidt
float heightAtDensity = viewportHeight * density;
viewportWidth *= (physicalWidth / widthAtDensity);
viewportHeight *= (physicalHeight / heightAtDensity);
- }
- else if (viewportMode == ViewportMode.STRETCH_TO_ASPECT) {
+ } else if (viewportMode == ViewportMode.STRETCH_TO_ASPECT) {
float aspect = virtualWidth / virtualHeight;
if (physicalWidth / physicalHeight >= aspect) {
// Letterbox left and right.
viewportHeight = virtualHeight;
viewportWidth = viewportHeight * physicalWidth / physicalHeight;
- }
- else {
+ } else {
// Letterbox above and below.
viewportWidth = virtualWidth;
viewportHeight = viewportWidth * physicalHeight / physicalWidth;
@@ -127,8 +119,8 @@ else if (viewportMode == ViewportMode.STRETCH_TO_ASPECT) {
}
return new Vector2(viewportWidth, viewportHeight);
}
-
- public static float bestDensity(float virtualWidth, float virtualHeight, float[] densities) {
+
+ public static float bestDensity (float virtualWidth, float virtualHeight, float[] densities) {
// TODO: Spell out that densities is assumed to be in ascending order.
float bestDensity = densities[0];
float physicalWidth = Gdx.graphics.getWidth();
diff --git a/demos/very-angry-robots/very-angry-robots/src/com/badlydrawngames/general/Colliders.java b/demos/very-angry-robots/very-angry-robots/src/com/badlydrawngames/general/Colliders.java
index 8f7c3c06964..ece2a061c7e 100644
--- a/demos/very-angry-robots/very-angry-robots/src/com/badlydrawngames/general/Colliders.java
+++ b/demos/very-angry-robots/very-angry-robots/src/com/badlydrawngames/general/Colliders.java
@@ -18,45 +18,38 @@
import com.badlogic.gdx.utils.Pool;
import com.badlydrawngames.veryangryrobots.mobiles.GameObject;
-/**
- * Functions that are useful for collision detection.
- * @author Rod
- *
- */
+/** Functions that are useful for collision detection.
+ * @author Rod */
public final class Colliders {
-
+
public static interface RemovalHandler {
- void onRemove(T t);
+ void onRemove (T t);
}
-
+
public static interface ColliderHandler {
- void onCollision(T t, U u);
+ void onCollision (T t, U u);
}
-
+
public static interface SceneryHandler {
- void onCollision(T t, Rectangle r);
+ void onCollision (T t, Rectangle r);
}
-
- private Colliders() {}
-
- /**
- * Returns true if two rectangles intersect.
+
+ private Colliders () {
+ }
+
+ /** Returns true if two rectangles intersect.
* @param a the first rectangle.
* @param b the second rectangle.
- * @return true if the rectangles intersect, otherwise false.
- */
- public static boolean intersects(Rectangle a, Rectangle b) {
- return (a.x + a.width > b.x) && (a.x < b.x + b.width) &&
- (a.y + a.height > b.y) && (a.y < b.y + b.height);
+ * @return true if the rectangles intersect, otherwise false. */
+ public static boolean intersects (Rectangle a, Rectangle b) {
+ return (a.x + a.width > b.x) && (a.x < b.x + b.width) && (a.y + a.height > b.y) && (a.y < b.y + b.height);
}
-
- /**
- * Returns true if a rectangle intersects with any rectangles in an array.
+
+ /** Returns true if a rectangle intersects with any rectangles in an array.
* @param a the rectangle.
* @param rects the array of rectangles.
- * @return true if they intersect, otherwise false.
- */
- public static boolean intersects(Rectangle a, Array rects) {
+ * @return true if they intersect, otherwise false. */
+ public static boolean intersects (Rectangle a, Array rects) {
for (int i = rects.size - 1; i >= 0; i--) {
Rectangle b = rects.get(i);
if (intersects(a, b)) {
@@ -65,16 +58,18 @@ public static boolean intersects(Rectangle a, Array rects) {
}
return false;
}
-
- public static void collide(T a, U b, ColliderHandler callback) {
+
+ public static void collide (T a, U b,
+ ColliderHandler callback) {
if (a != b) {
if (a.intersects(b)) {
callback.onCollision(a, b);
}
}
}
-
- public static void collide(T go, Array gos, ColliderHandler callback) {
+
+ public static void collide (T go, Array gos,
+ ColliderHandler callback) {
for (int i = gos.size - 1; i >= 0; i--) {
U other = gos.get(i);
if (go.intersects(other)) {
@@ -83,7 +78,7 @@ public static void collide(Array a, ColliderHandler callback) {
+ public static void collide (Array a, ColliderHandler callback) {
for (int i = a.size - 1; i >= 0; i--) {
T go = a.get(i);
for (int j = i - 1; j >= 0; j--) {
@@ -96,26 +91,27 @@ public static void collide(Array a, Colli
}
@SuppressWarnings("unchecked")
- public static void collide(Array a, Array b, ColliderHandler callback) {
+ public static void collide (Array a, Array b,
+ ColliderHandler callback) {
if (a != b) {
for (int i = a.size - 1; i >= 0; i--) {
T go = a.get(i);
collide(go, b, callback);
}
- }
- else {
- collide(a, (ColliderHandler) callback);
+ } else {
+ collide(a, (ColliderHandler)callback);
}
}
- public static void collide(Array gos, Array rects, SceneryHandler callback) {
+ public static void collide (Array gos, Array rects,
+ SceneryHandler callback) {
for (int i = gos.size - 1; i >= 0; i--) {
T go = gos.get(i);
collide(go, rects, callback);
}
}
-
- public static void collide(T go, Array rects, SceneryHandler callback) {
+
+ public static void collide (T go, Array rects, SceneryHandler callback) {
for (int i = 0; i < rects.size && !go.inCollision; i++) {
Rectangle r = rects.get(i);
if (go.intersects(r)) {
@@ -123,19 +119,18 @@ public static void collide(T go, Array the base class of the object.
- * @param a more specific class of the object.
+ * @param a more specific class of the object.
* @param pool the pool to which the object belongs.
* @param gos the array of game objects to check.
- * @param handler the collision handler callback.
- */
- public static void removeMarkedCollisions(Pool pool, Array gos, RemovalHandler handler) {
+ * @param handler the collision handler callback. */
+ public static void removeMarkedCollisions (Pool pool, Array gos,
+ RemovalHandler handler) {
// The "U extends T" allows for shotHandler to cope with both PlayerShot and RobotShot, because they both
// extend BaseShot.
for (int i = gos.size - 1; i >= 0; i--) {
@@ -148,14 +143,12 @@ public static void removeMarkedCollisions(Po
}
}
- /**
- * Removes game objects that are outside of the given rectangular bounds.
+ /** Removes game objects that are outside of the given rectangular bounds.
* @param the object's class.
* @param pool the pool to which the object belongs.
* @param gos the array of game objects to check.
- * @param bounds the rectangular bounds.
- */
- public static void removeOutOfBounds(Pool pool, Array gos, Rectangle bounds) {
+ * @param bounds the rectangular bounds. */
+ public static void removeOutOfBounds (Pool pool, Array gos, Rectangle bounds) {
float minX = bounds.x;
float maxX = minX + bounds.width;
float minY = bounds.y;
diff --git a/demos/very-angry-robots/very-angry-robots/src/com/badlydrawngames/general/CollisionGeometry.java b/demos/very-angry-robots/very-angry-robots/src/com/badlydrawngames/general/CollisionGeometry.java
index c337e3d3ebd..15483149fbb 100644
--- a/demos/very-angry-robots/very-angry-robots/src/com/badlydrawngames/general/CollisionGeometry.java
+++ b/demos/very-angry-robots/very-angry-robots/src/com/badlydrawngames/general/CollisionGeometry.java
@@ -13,32 +13,28 @@
package com.badlydrawngames.general;
-import static com.badlydrawngames.general.Rectangles.setRectangle;
-
import com.badlogic.gdx.math.Rectangle;
import com.badlogic.gdx.utils.Array;
+import static com.badlydrawngames.general.Rectangles.*;
+
public class CollisionGeometry {
private final Array runs;
private final Rectangle r;
- /**
- * Creates this collision geometry.
- * @param runs the model-space rectangles that make up this object's collision geometry.
- */
- public CollisionGeometry(Array runs) {
+ /** Creates this collision geometry.
+ * @param runs the model-space rectangles that make up this object's collision geometry. */
+ public CollisionGeometry (Array runs) {
this.runs = runs;
r = new Rectangle();
}
- /**
- * Tests if this collision geometry would collide with a rectangle if it was at the given coordinates.
+ /** Tests if this collision geometry would collide with a rectangle if it was at the given coordinates.
* @param other the rectangle to test against.
* @param x the x coordinate of this collision geometry.
* @param y the y coordinate of this collision geometry.
- * @return true if in collision otherwise false.
- */
- public boolean intersects(Rectangle other, float x, float y) {
+ * @return true if in collision otherwise false. */
+ public boolean intersects (Rectangle other, float x, float y) {
boolean result = false;
for (int i = 0; i < runs.size; i++) {
Rectangle run = runs.get(i);
@@ -51,16 +47,14 @@ public boolean intersects(Rectangle other, float x, float y) {
return result;
}
- /**
- * Tests if this collision geometry is in collision with another.
+ /** Tests if this collision geometry is in collision with another.
* @param x this collision geometry's x coordinate.
* @param y this collision geometry's y coordinate.
* @param other the other collision geometry.
* @param otherX the other collision geometry's x coordinate.
* @param otherY the other collision geometry's y coordinate.
- * @return true if in collision otherwise false.
- */
- public boolean intersects(float x, float y, CollisionGeometry other, float otherX, float otherY) {
+ * @return true if in collision otherwise false. */
+ public boolean intersects (float x, float y, CollisionGeometry other, float otherX, float otherY) {
boolean result = false;
for (int i = 0; i < runs.size; i++) {
Rectangle run = runs.get(i);
diff --git a/demos/very-angry-robots/very-angry-robots/src/com/badlydrawngames/general/Config.java b/demos/very-angry-robots/very-angry-robots/src/com/badlydrawngames/general/Config.java
index 14df248eabb..f575059a90c 100644
--- a/demos/very-angry-robots/very-angry-robots/src/com/badlydrawngames/general/Config.java
+++ b/demos/very-angry-robots/very-angry-robots/src/com/badlydrawngames/general/Config.java
@@ -20,54 +20,50 @@
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.files.FileHandle;
-/**
- * Provides a simple way to tweak the game configuration via attributes. Ideally this would be backed with a
+/** Provides a simple way to tweak the game configuration via attributes. Ideally this would be backed with a
* ConfigProvider
or similar.
- * @author Rod
- *
- */
+ * @author Rod */
public class Config {
-
+
private static final String PROPERTIES_FILE = "data/veryangryrobots.properties";
private static Properties properties;
-
- private Config() {}
-
- private static Properties instance() {
+
+ private Config () {
+ }
+
+ private static Properties instance () {
if (null == properties) {
properties = new Properties();
- FileHandle fh = Gdx.files.internal(PROPERTIES_FILE);
+ FileHandle fh = Gdx.files.internal(PROPERTIES_FILE);
InputStream inStream = fh.read();
try {
properties.load(inStream);
inStream.close();
- }
- catch (IOException e) {
+ } catch (IOException e) {
if (inStream != null) {
try {
- inStream.close();
- }
- catch (IOException ex) {
+ inStream.close();
+ } catch (IOException ex) {
}
}
}
}
return properties;
}
-
- public static int asInt(String name, int fallback) {
+
+ public static int asInt (String name, int fallback) {
String v = instance().getProperty(name);
if (v == null) return fallback;
return Integer.parseInt(v);
}
- public static float asFloat(String name, float fallback) {
+ public static float asFloat (String name, float fallback) {
String v = instance().getProperty(name);
if (v == null) return fallback;
return Float.parseFloat(v);
}
-
- public static String asString(String name, String fallback) {
+
+ public static String asString (String name, String fallback) {
String v = instance().getProperty(name);
if (v == null) return fallback;
return v;
diff --git a/demos/very-angry-robots/very-angry-robots/src/com/badlydrawngames/general/GameScreen.java b/demos/very-angry-robots/very-angry-robots/src/com/badlydrawngames/general/GameScreen.java
index a882827d86c..f3e6c1581ca 100644
--- a/demos/very-angry-robots/very-angry-robots/src/com/badlydrawngames/general/GameScreen.java
+++ b/demos/very-angry-robots/very-angry-robots/src/com/badlydrawngames/general/GameScreen.java
@@ -17,36 +17,36 @@
public class GameScreen implements Screen {
protected T game;
-
- public GameScreen(T game) {
+
+ public GameScreen (T game) {
this.game = game;
}
@Override
- public void dispose() {
+ public void dispose () {
}
@Override
- public void hide() {
+ public void hide () {
}
@Override
- public void pause() {
+ public void pause () {
}
@Override
- public void render(float delta) {
+ public void render (float delta) {
}
@Override
- public void resize(int width, int height) {
+ public void resize (int width, int height) {
}
@Override
- public void resume() {
+ public void resume () {
}
@Override
- public void show() {
+ public void show () {
}
}
diff --git a/demos/very-angry-robots/very-angry-robots/src/com/badlydrawngames/general/Grid.java b/demos/very-angry-robots/very-angry-robots/src/com/badlydrawngames/general/Grid.java
index b5d06e8fffc..bfa7820b754 100644
--- a/demos/very-angry-robots/very-angry-robots/src/com/badlydrawngames/general/Grid.java
+++ b/demos/very-angry-robots/very-angry-robots/src/com/badlydrawngames/general/Grid.java
@@ -13,12 +13,11 @@
package com.badlydrawngames.general;
-import static com.badlydrawngames.general.MathUtils.max;
-import static com.badlydrawngames.general.MathUtils.min;
-
import com.badlogic.gdx.math.Rectangle;
import com.badlogic.gdx.utils.Array;
+import static com.badlydrawngames.general.MathUtils.*;
+
public class Grid {
private final int cols;
@@ -28,7 +27,7 @@ public class Grid {
private final Array> grid;
private Array result;
- public Grid(int cols, int rows, float width, float height) {
+ public Grid (int cols, int rows, float width, float height) {
this.cols = cols;
this.rows = rows;
this.cellWidth = width / cols;
@@ -39,14 +38,14 @@ public Grid(int cols, int rows, float width, float height) {
}
this.result = new Array();
}
-
- public void clear() {
+
+ public void clear () {
for (Array v : grid) {
v.clear();
}
}
-
- public void add(Rectangle r) {
+
+ public void add (Rectangle r) {
int minX = max(0, cellX(r.x));
int maxX = min(cols - 1, cellX(r.x + r.width));
int minY = max(0, cellY(r.y));
@@ -59,8 +58,8 @@ public void add(Rectangle r) {
}
}
}
-
- public Array get(Rectangle r) {
+
+ public Array get (Rectangle r) {
result.clear();
int minX = max(0, cellX(r.x));
int maxX = min(cols - 1, cellX(r.x + r.width));
@@ -74,16 +73,16 @@ public Array get(Rectangle r) {
}
return result;
}
-
- private int cellX(float x) {
- return (int) (x / cellWidth);
+
+ private int cellX (float x) {
+ return (int)(x / cellWidth);
}
-
- private int cellY(float y) {
- return (int) (y / cellHeight);
+
+ private int cellY (float y) {
+ return (int)(y / cellHeight);
}
-
- private int getGridCell(int x, int y) {
+
+ private int getGridCell (int x, int y) {
return x + y * cols;
}
}
diff --git a/demos/very-angry-robots/very-angry-robots/src/com/badlydrawngames/general/MathUtils.java b/demos/very-angry-robots/very-angry-robots/src/com/badlydrawngames/general/MathUtils.java
index a9a93bd1910..44f9c62ca76 100644
--- a/demos/very-angry-robots/very-angry-robots/src/com/badlydrawngames/general/MathUtils.java
+++ b/demos/very-angry-robots/very-angry-robots/src/com/badlydrawngames/general/MathUtils.java
@@ -14,11 +14,11 @@
package com.badlydrawngames.general;
public class MathUtils {
- public static float abs(float n) {
+ public static float abs (float n) {
return (n >= 0.0f) ? n : -n;
}
-
- public static float sgn(float n) {
+
+ public static float sgn (float n) {
if (n > 0.0f)
return 1.0f;
else if (n < 0.0f)
@@ -27,19 +27,19 @@ else if (n < 0.0f)
return 0.0f;
}
- public static float min(float a, float b) {
+ public static float min (float a, float b) {
return (a < b) ? a : b;
}
-
- public static float max(float a, float b) {
+
+ public static float max (float a, float b) {
return (a > b) ? a : b;
}
-
- public static int min(int a, int b) {
+
+ public static int min (int a, int b) {
return (a < b) ? a : b;
}
-
- public static int max(int a, int b) {
+
+ public static int max (int a, int b) {
return (a > b) ? a : b;
}
}
diff --git a/demos/very-angry-robots/very-angry-robots/src/com/badlydrawngames/general/Particle.java b/demos/very-angry-robots/very-angry-robots/src/com/badlydrawngames/general/Particle.java
index d5d8a785eb9..b031126984b 100644
--- a/demos/very-angry-robots/very-angry-robots/src/com/badlydrawngames/general/Particle.java
+++ b/demos/very-angry-robots/very-angry-robots/src/com/badlydrawngames/general/Particle.java
@@ -13,21 +13,17 @@
package com.badlydrawngames.general;
-import static com.badlogic.gdx.math.MathUtils.PI;
-import static com.badlogic.gdx.math.MathUtils.cos;
-import static com.badlogic.gdx.math.MathUtils.random;
-import static com.badlogic.gdx.math.MathUtils.sin;
-import static com.badlydrawngames.general.MathUtils.max;
-import static com.badlydrawngames.general.MathUtils.min;
-
import com.badlogic.gdx.graphics.Color;
+import static com.badlogic.gdx.math.MathUtils.*;
+import static com.badlydrawngames.general.MathUtils.*;
+
public class Particle {
-
+
private final float MIN_SPEED = 3.125f;
private final float MAX_SPEED = 6.25f;
private final float DECAY = 2.0f;
-
+
public boolean active;
public float x;
public float y;
@@ -41,13 +37,13 @@ public class Particle {
float b;
float a;
- public Particle(float size) {
+ public Particle (float size) {
this.color = new Color();
this.size = size;
this.halfSize = size / 2;
}
-
- public void spawn(Color c, float x, float y) {
+
+ public void spawn (Color c, float x, float y) {
this.active = true;
this.x = x - halfSize;
this.y = y - halfSize;
@@ -56,13 +52,13 @@ public void spawn(Color c, float x, float y) {
g = c.g;
b = c.b;
a = 3.0f;
- float direction = random((float) -PI, PI);
+ float direction = random((float)-PI, PI);
float speed = random(MIN_SPEED, MAX_SPEED);
dx = cos(direction) * speed;
dy = sin(direction) * speed;
}
-
- public void update(float delta) {
+
+ public void update (float delta) {
x += dx * delta;
y += dy * delta;
dx *= (1.0 - DECAY * delta * 0.5f);
diff --git a/demos/very-angry-robots/very-angry-robots/src/com/badlydrawngames/general/ParticleManager.java b/demos/very-angry-robots/very-angry-robots/src/com/badlydrawngames/general/ParticleManager.java
index 8291d7de4dc..ab9fab75aec 100644
--- a/demos/very-angry-robots/very-angry-robots/src/com/badlydrawngames/general/ParticleManager.java
+++ b/demos/very-angry-robots/very-angry-robots/src/com/badlydrawngames/general/ParticleManager.java
@@ -17,12 +17,12 @@
import com.badlogic.gdx.utils.Array;
public class ParticleManager {
-
+
private final Array particles;
private final int maxParticles;
private int index;
- public ParticleManager(int maxParticles, float size) {
+ public ParticleManager (int maxParticles, float size) {
particles = new Array(maxParticles);
this.maxParticles = maxParticles;
for (int i = 0; i < maxParticles; i++) {
@@ -31,17 +31,17 @@ public ParticleManager(int maxParticles, float size) {
index = 0;
}
- public Array getParticles() {
+ public Array getParticles () {
return particles;
}
-
- public void clear() {
+
+ public void clear () {
for (Particle particle : particles) {
particle.active = false;
}
}
- public void add(float x, float y, int n, Color c) {
+ public void add (float x, float y, int n, Color c) {
for (int i = 0; i < n; i++) {
particles.get(index).spawn(c, x, y);
if (++index == maxParticles) {
@@ -49,8 +49,8 @@ public void add(float x, float y, int n, Color c) {
}
}
}
-
- public void update(float delta) {
+
+ public void update (float delta) {
for (Particle particle : particles) {
if (particle.active) {
particle.update(delta);
diff --git a/demos/very-angry-robots/very-angry-robots/src/com/badlydrawngames/general/Pools.java b/demos/very-angry-robots/very-angry-robots/src/com/badlydrawngames/general/Pools.java
index 1858621098e..3a8ab8b97de 100644
--- a/demos/very-angry-robots/very-angry-robots/src/com/badlydrawngames/general/Pools.java
+++ b/demos/very-angry-robots/very-angry-robots/src/com/badlydrawngames/general/Pools.java
@@ -16,42 +16,35 @@
import com.badlogic.gdx.utils.Array;
import com.badlogic.gdx.utils.Pool;
-/**
- * Pool helper functions.
- * @author Rod
- *
- */
+/** Pool helper functions.
+ * @author Rod */
public class Pools {
- private Pools() {};
-
- /**
- * Frees the items in an array to a pool.
+ private Pools () {
+ };
+
+ /** Frees the items in an array to a pool.
* @param the type of item allocated in the array.
* @param array the array of items to free.
- * @param pool the pool that the items are to be released to.
- */
- public static void freeArrayToPool(Array array, Pool pool) {
+ * @param pool the pool that the items are to be released to. */
+ public static void freeArrayToPool (Array array, Pool pool) {
pool.free(array);
array.clear();
}
-
- /**
- * Creates an array from a pool, freeing its items if it already exists.
+
+ /** Creates an array from a pool, freeing its items if it already exists.
* @param the type of item allocated in the array.
* @param array the array of items to (re)create.
* @param pool the pool that the items are to be allocated from / released to.
* @param size the array's capacity.
- * @return
- */
+ * @return */
@SuppressWarnings("unchecked")
- public static Array makeArrayFromPool(Array array, Pool pool, int size) {
+ public static Array makeArrayFromPool (Array array, Pool pool, int size) {
if (array == null) {
// Do this so that array.items can be used.
T t = pool.obtain();
- array = new Array(false, size, (Class) t.getClass());
+ array = new Array(false, size, (Class)t.getClass());
pool.free(t);
- }
- else {
+ } else {
freeArrayToPool(array, pool);
}
return array;
diff --git a/demos/very-angry-robots/very-angry-robots/src/com/badlydrawngames/general/Rectangles.java b/demos/very-angry-robots/very-angry-robots/src/com/badlydrawngames/general/Rectangles.java
index 60e0a0deed9..5a5d277db0f 100644
--- a/demos/very-angry-robots/very-angry-robots/src/com/badlydrawngames/general/Rectangles.java
+++ b/demos/very-angry-robots/very-angry-robots/src/com/badlydrawngames/general/Rectangles.java
@@ -13,23 +13,23 @@
package com.badlydrawngames.general;
-import static com.badlydrawngames.general.MathUtils.max;
-import static com.badlydrawngames.general.MathUtils.min;
-
import com.badlogic.gdx.math.Rectangle;
+import static com.badlydrawngames.general.MathUtils.*;
+
public class Rectangles {
-
- private Rectangles() {}
-
- public static void setRectangle(Rectangle r, float x, float y, float w, float h) {
+
+ private Rectangles () {
+ }
+
+ public static void setRectangle (Rectangle r, float x, float y, float w, float h) {
r.x = x;
r.y = y;
r.width = w;
r.height = h;
}
-
- public static Rectangle union(Rectangle a, Rectangle b, Rectangle result) {
+
+ public static Rectangle union (Rectangle a, Rectangle b, Rectangle result) {
result.x = min(a.x, b.x);
result.y = min(a.y, b.y);
result.width = max(a.x + a.width, b.x + b.width) - result.x;
diff --git a/demos/very-angry-robots/very-angry-robots/src/com/badlydrawngames/general/ScoreString.java b/demos/very-angry-robots/very-angry-robots/src/com/badlydrawngames/general/ScoreString.java
index d180152e563..cf9864e5c4d 100644
--- a/demos/very-angry-robots/very-angry-robots/src/com/badlydrawngames/general/ScoreString.java
+++ b/demos/very-angry-robots/very-angry-robots/src/com/badlydrawngames/general/ScoreString.java
@@ -13,26 +13,23 @@
package com.badlydrawngames.general;
-/**
- * A ScoreString
exists to prevent calls to {@link String#format(String, Object...)} as this seems to be
- * rather profligate at allocating memory, which in turns leads to garbage collection. Given that we can't manage that
- * directly we do our own thing.
+/** A ScoreString
exists to prevent calls to {@link String#format(String, Object...)} as this seems to be rather
+ * profligate at allocating memory, which in turns leads to garbage collection. Given that we can't manage that directly we do our
+ * own thing.
*
- * @author Rod
- *
- */
+ * @author Rod */
public class ScoreString implements CharSequence {
public static final int DEFAULT_CHARS = 6;
-
+
private final char[] score;
private final int start;
-
- public ScoreString() {
+
+ public ScoreString () {
this(DEFAULT_CHARS);
}
-
- public ScoreString(int numChars) {
+
+ public ScoreString (int numChars) {
score = new char[numChars];
int n = 1;
for (int i = 0; i < numChars - 1; i++) {
@@ -40,32 +37,30 @@ public ScoreString(int numChars) {
}
start = n;
}
-
+
@Override
- public char charAt(int index) {
+ public char charAt (int index) {
return score[index];
}
@Override
- public int length() {
+ public int length () {
return score.length;
}
@Override
- public CharSequence subSequence(int start, int end) {
+ public CharSequence subSequence (int start, int end) {
// Don't care. Call at your own risk.
- return null;
+ return null;
}
- /**
- * Sets this ScoreString
to hold the given integer value.
+ /** Sets this ScoreString
to hold the given integer value.
*
- * @param v the value that the ScoreString will hold.
- */
- public void setScore(int v) {
+ * @param v the value that the ScoreString will hold. */
+ public void setScore (int v) {
for (int n = start, i = 0; i < score.length; n /= 10, i++) {
int j = (v / n) % 10;
- score[i] = (char) ('0' + j);
+ score[i] = (char)('0' + j);
}
}
}
diff --git a/demos/very-angry-robots/very-angry-robots/src/com/badlydrawngames/general/SimpleButton.java b/demos/very-angry-robots/very-angry-robots/src/com/badlydrawngames/general/SimpleButton.java
index 61440822bb9..2b916fa7d86 100644
--- a/demos/very-angry-robots/very-angry-robots/src/com/badlydrawngames/general/SimpleButton.java
+++ b/demos/very-angry-robots/very-angry-robots/src/com/badlydrawngames/general/SimpleButton.java
@@ -15,9 +15,9 @@
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
-import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.g2d.BitmapFont.HAlignment;
import com.badlogic.gdx.graphics.g2d.BitmapFont.TextBounds;
+import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlydrawngames.veryangryrobots.Assets;
public class SimpleButton {
@@ -33,8 +33,8 @@ public class SimpleButton {
private BitmapFont font;
private float textWidth;
private float textHeight;
-
- public SimpleButton(String text, BitmapFont font) {
+
+ public SimpleButton (String text, BitmapFont font) {
this.text = text;
this.wasPressed = false;
this.activated = false;
@@ -47,54 +47,50 @@ public SimpleButton(String text, BitmapFont font) {
h = bounds.height * 2;
alignment = HAlignment.CENTER;
}
-
- public void setWidth(float width) {
+
+ public void setWidth (float width) {
w = width;
}
-
- public void setHeight(float height) {
+
+ public void setHeight (float height) {
h = height;
}
-
- public void setAlignment(HAlignment alignment) {
+
+ public void setAlignment (HAlignment alignment) {
this.alignment = alignment;
}
-
- public void update(float delta, boolean justTouched, boolean isTouched, boolean justReleased, float x, float y) {
+
+ public void update (float delta, boolean justTouched, boolean isTouched, boolean justReleased, float x, float y) {
wasPressed = false;
if (justTouched && inBounds(x, y)) {
activated = true;
down = true;
- }
- else if (isTouched) {
+ } else if (isTouched) {
down = activated && inBounds(x, y);
- }
- else if (justReleased) {
+ } else if (justReleased) {
wasPressed = activated && inBounds(x, y);
activated = false;
down = false;
- }
- else {
+ } else {
activated = false;
}
}
-
- private boolean inBounds(float x, float y) {
+
+ private boolean inBounds (float x, float y) {
return x >= this.x && x < this.x + this.w && y >= this.y && y < this.y + this.h;
}
-
- public void draw(SpriteBatch spriteBatch) {
+
+ public void draw (SpriteBatch spriteBatch) {
Color oldColor = font.getColor();
if (down) {
spriteBatch.setColor(Color.RED);
- }
- else {
+ } else {
spriteBatch.setColor(Color.BLUE);
}
spriteBatch.draw(Assets.pureWhiteTextureRegion, x, y, w, h);
spriteBatch.setColor(Color.WHITE);
if (down) {
- font.setColor(oldColor.r/2, oldColor.g/2, oldColor.b/2, oldColor.a);
+ font.setColor(oldColor.r / 2, oldColor.g / 2, oldColor.b / 2, oldColor.a);
}
float textX = x;
float textY = y + h;
@@ -102,32 +98,32 @@ public void draw(SpriteBatch spriteBatch) {
font.drawWrapped(spriteBatch, text, textX, textY, w, alignment);
font.setColor(oldColor);
}
-
- public boolean wasPressed() {
+
+ public boolean wasPressed () {
return this.wasPressed;
}
-
- public void rightOn(float right) {
+
+ public void rightOn (float right) {
x = right - w;
}
-
- public void leftOn(float left) {
+
+ public void leftOn (float left) {
x = left;
}
-
- public void centerHorizontallyOn(float centerX) {
- x = centerX - w/2;
+
+ public void centerHorizontallyOn (float centerX) {
+ x = centerX - w / 2;
}
-
- public void bottomOn(float bottom) {
+
+ public void bottomOn (float bottom) {
y = bottom;
}
-
- public void topOn(float top) {
+
+ public void topOn (float top) {
y = top - h;
}
-
- public void centerVerticallyOn(float centerY) {
- y = centerY - h/2;
+
+ public void centerVerticallyOn (float centerY) {
+ y = centerY - h / 2;
}
}
diff --git a/demos/very-angry-robots/very-angry-robots/src/com/badlydrawngames/veryangryrobots/AchievementsListener.java b/demos/very-angry-robots/very-angry-robots/src/com/badlydrawngames/veryangryrobots/AchievementsListener.java
index 698211ba1ef..37012d19aac 100644
--- a/demos/very-angry-robots/very-angry-robots/src/com/badlydrawngames/veryangryrobots/AchievementsListener.java
+++ b/demos/very-angry-robots/very-angry-robots/src/com/badlydrawngames/veryangryrobots/AchievementsListener.java
@@ -16,5 +16,5 @@
import com.badlydrawngames.veryangryrobots.StatusManager.Achievements;
public interface AchievementsListener {
- void onAttained(Achievements achievement);
+ void onAttained (Achievements achievement);
}
diff --git a/demos/very-angry-robots/very-angry-robots/src/com/badlydrawngames/veryangryrobots/AchievementsNotifier.java b/demos/very-angry-robots/very-angry-robots/src/com/badlydrawngames/veryangryrobots/AchievementsNotifier.java
index f4506f43999..183c8d44b74 100644
--- a/demos/very-angry-robots/very-angry-robots/src/com/badlydrawngames/veryangryrobots/AchievementsNotifier.java
+++ b/demos/very-angry-robots/very-angry-robots/src/com/badlydrawngames/veryangryrobots/AchievementsNotifier.java
@@ -19,17 +19,17 @@
public class AchievementsNotifier implements AchievementsListener {
private final Array listeners;
-
- public AchievementsNotifier() {
+
+ public AchievementsNotifier () {
this.listeners = new Array();
}
- public void addListener(AchievementsListener listener) {
+ public void addListener (AchievementsListener listener) {
listeners.add(listener);
}
-
+
@Override
- public void onAttained(Achievements achievement) {
+ public void onAttained (Achievements achievement) {
for (AchievementsListener listener : listeners) {
listener.onAttained(achievement);
}
diff --git a/demos/very-angry-robots/very-angry-robots/src/com/badlydrawngames/veryangryrobots/Assets.java b/demos/very-angry-robots/very-angry-robots/src/com/badlydrawngames/veryangryrobots/Assets.java
index eed411e5f66..4ee79b0e6ed 100644
--- a/demos/very-angry-robots/very-angry-robots/src/com/badlydrawngames/veryangryrobots/Assets.java
+++ b/demos/very-angry-robots/very-angry-robots/src/com/badlydrawngames/veryangryrobots/Assets.java
@@ -13,8 +13,6 @@
package com.badlydrawngames.veryangryrobots;
-import static com.badlydrawngames.general.Rectangles.setRectangle;
-
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.audio.Sound;
import com.badlogic.gdx.files.FileHandle;
@@ -29,29 +27,31 @@
import com.badlydrawngames.general.CollisionGeometry;
import com.badlydrawngames.general.Config;
+import static com.badlydrawngames.general.Rectangles.*;
+
public class Assets {
private static final String FLYUP_FONT = Config.asString("Global.flyupFont", "ocr_a_small.fnt");
private static final String SCORE_FONT = Config.asString("Global.scoreFont", "wellbutrin.fnt");
private static final String TEXT_FONT = Config.asString("Global.textFont", "ocr_a.fnt");
-
+
private static final float PLAYER_BORDER_WIDTH = Config.asFloat("Player.borderWidthPercent", 25.0f);
private static final float PLAYER_BORDER_HEIGHT = Config.asFloat("Player.borderHeightPercent", 6.7f);
private static final float PLAYER_FRAME_DURATION = Config.asFloat("Player.frameDuration", 0.2f);
- private static final float ROBOT_FRAME_DURATION = Config.asFloat("Robot.frameDuration", 0.1f);
+ private static final float ROBOT_FRAME_DURATION = Config.asFloat("Robot.frameDuration", 0.1f);
private static final float CAPTAIN_BORDER_WIDTH = Config.asFloat("Captain.borderWidthPercent", 16.7f);
private static final float CAPTAIN_BORDER_HEIGHT = Config.asFloat("Captain.borderHeightPercent", 16.7f);
private static final float CAPTAIN_FRAME_DURATION = Config.asFloat("Captain.frameDuration", 0.1f);
-
+
private static final float PARTICLE_SIZE = Config.asFloat("particle.size", 0.1875f);
-
+
private static TextureAtlas atlas;
public static final float VIRTUAL_WIDTH = 30.0f;
public static final float VIRTUAL_HEIGHT = 20.0f;
-
+
public static TextureRegion pureWhiteTextureRegion;
public static TextureRegion playerWalkingRight1;
public static TextureRegion playerWalkingRight2;
@@ -74,20 +74,20 @@ public class Assets {
public static TextureRegion nemesis1;
public static TextureRegion nemesis2;
public static TextureRegion pauseButton;
-
+
public static Animation playerWalkingRightAnimation;
public static Animation playerWalkingLeftAnimation;
public static Animation robotWalkingLeftAnimation;
public static Animation robotWalkingRightAnimation;
public static Animation robotScanningAnimation;
-
+
public static Animation nemesisAnimation;
public static BitmapFont scoreFont;
public static BitmapFont textFont;
public static BitmapFont flyupFont;
-
+
public static Sound[] chickenTaunts;
public static Sound[] standardTaunts;
public static Sound extraLifeSound;
@@ -117,15 +117,15 @@ public class Assets {
public static float robotShotHeight;
public static float particleWidth;
public static float particleHeight;
-
+
public static CollisionGeometry playerGeometry;
public static CollisionGeometry captainGeometry;
-
+
public static float pixelDensity;
-
- public static void load() {
+
+ public static void load () {
pixelDensity = calculatePixelDensity();
- String textureDir = "data/textures/" + (int) pixelDensity;
+ String textureDir = "data/textures/" + (int)pixelDensity;
String textureFile = textureDir + "/pack";
atlas = new TextureAtlas(Gdx.files.internal(textureFile), Gdx.files.internal(textureDir));
loadTextures();
@@ -134,8 +134,8 @@ public static void load() {
loadSounds();
initialiseGeometries();
}
-
- private static void loadTextures() {
+
+ private static void loadTextures () {
pureWhiteTextureRegion = atlas.findRegion("8x8");
playerWalkingRight1 = atlas.findRegion("HeroRight1");
playerWalkingRight2 = atlas.findRegion("HeroRight2");
@@ -160,7 +160,7 @@ private static void loadTextures() {
pauseButton = atlas.findRegion("pause");
}
- private static float calculatePixelDensity() {
+ private static float calculatePixelDensity () {
FileHandle textureDir = Gdx.files.internal("data/textures");
FileHandle[] availableDensities = textureDir.list();
FloatArray densities = new FloatArray(availableDensities.length);
@@ -171,51 +171,34 @@ private static float calculatePixelDensity() {
densities.sort();
return CameraHelper.bestDensity(VIRTUAL_WIDTH, VIRTUAL_HEIGHT, densities.items);
}
-
- private static void createAnimations() {
+
+ private static void createAnimations () {
playerWalkingRightAnimation = new Animation(PLAYER_FRAME_DURATION, Assets.playerWalkingRight1, Assets.playerWalkingRight2);
playerWalkingLeftAnimation = new Animation(PLAYER_FRAME_DURATION, Assets.playerWalkingLeft1, Assets.playerWalkingLeft2);
-
- robotWalkingLeftAnimation = new Animation(ROBOT_FRAME_DURATION,
- robotLeft1,
- robotLeft2,
- robotLeft3,
- robotLeft4,
- robotLeft3,
- robotLeft2);
- robotWalkingRightAnimation = new Animation(ROBOT_FRAME_DURATION,
- robotRight1,
- robotRight2,
- robotRight3,
- robotRight4,
- robotRight3,
- robotRight2);
- robotScanningAnimation = new Animation(ROBOT_FRAME_DURATION,
- robotScan1,
- robotScan2,
- robotScan3,
- robotScan4,
- robotScan3,
- robotScan2);
-
- nemesisAnimation = new Animation(CAPTAIN_FRAME_DURATION,
- nemesis1,
- nemesis2);
+
+ robotWalkingLeftAnimation = new Animation(ROBOT_FRAME_DURATION, robotLeft1, robotLeft2, robotLeft3, robotLeft4, robotLeft3,
+ robotLeft2);
+ robotWalkingRightAnimation = new Animation(ROBOT_FRAME_DURATION, robotRight1, robotRight2, robotRight3, robotRight4,
+ robotRight3, robotRight2);
+ robotScanningAnimation = new Animation(ROBOT_FRAME_DURATION, robotScan1, robotScan2, robotScan3, robotScan4, robotScan3,
+ robotScan2);
+
+ nemesisAnimation = new Animation(CAPTAIN_FRAME_DURATION, nemesis1, nemesis2);
}
-
- private static void loadFonts() {
- String fontDir = "data/fonts/" + (int) pixelDensity + "/";
+
+ private static void loadFonts () {
+ String fontDir = "data/fonts/" + (int)pixelDensity + "/";
scoreFont = new BitmapFont(Gdx.files.internal(fontDir + SCORE_FONT), false);
textFont = new BitmapFont(Gdx.files.internal(fontDir + TEXT_FONT), false);
flyupFont = new BitmapFont(Gdx.files.internal(fontDir + FLYUP_FONT), false);
-
+
scoreFont.setScale(1.0f / pixelDensity);
textFont.setScale(1.0f / pixelDensity);
flyupFont.setScale(1.0f / pixelDensity);
}
- private static void loadSounds() {
+ private static void loadSounds () {
standardTaunts = loadSounds("standard_taunts");
chickenTaunts = loadSounds("chicken_taunts");
achievementSound = loadSound("achievement.ogg");
@@ -232,8 +215,8 @@ private static void loadSounds() {
killLastRobotSound = loadSound("hit03.ogg");
extraLifeSound = loadSound("pickup.ogg");
}
-
- private static Sound[] loadSounds(String dir) {
+
+ private static Sound[] loadSounds (String dir) {
FileHandle dh = Gdx.files.internal("data/sounds/" + dir);
FileHandle[] fhs = dh.list();
Sound[] sounds = new Sound[fhs.length];
@@ -242,16 +225,16 @@ private static Sound[] loadSounds(String dir) {
}
return sounds;
}
-
- private static Sound loadSound(String filename) {
+
+ private static Sound loadSound (String filename) {
return Gdx.audio.newSound(Gdx.files.internal("data/sounds/" + filename));
}
-
- private static void initialiseGeometries() {
+
+ private static void initialiseGeometries () {
playerWidth = toWidth(playerWalkingRight1);
playerHeight = toHeight(playerWalkingRight1);
- robotWidth = toWidth(robotRight1);
+ robotWidth = toWidth(robotRight1);
robotHeight = toHeight(robotRight1);
captainWidth = toWidth(nemesis1);
captainHeight = toHeight(nemesis1);
@@ -261,11 +244,11 @@ private static void initialiseGeometries() {
robotShotHeight = toHeight(robotShot);
particleWidth = PARTICLE_SIZE;
particleHeight = PARTICLE_SIZE;
-
+
// TODO: The below is a complete hack just to provide the player and captain with some collision geometry
// so that he doesn't die when he's clearly not in contact with a wall, bullet or enemy. Ideally it would
// be generated from the bitmap, or loaded.
-
+
// Configure player collision geometry.
Array playerRectangles = new Array();
Rectangle r = new Rectangle();
@@ -276,7 +259,7 @@ private static void initialiseGeometries() {
setRectangle(r, x, y, w, h);
playerRectangles.add(r);
playerGeometry = new CollisionGeometry(playerRectangles);
-
+
// Configure "captain" collision geometry.
Array captainRectangles = new Array();
r = new Rectangle();
@@ -289,15 +272,15 @@ private static void initialiseGeometries() {
captainGeometry = new CollisionGeometry(captainRectangles);
}
- private static float toWidth(TextureRegion region) {
+ private static float toWidth (TextureRegion region) {
return region.getRegionWidth() / pixelDensity;
}
-
- private static float toHeight(TextureRegion region) {
+
+ private static float toHeight (TextureRegion region) {
return region.getRegionHeight() / pixelDensity;
}
-
- public static void playSound(Sound sound) {
+
+ public static void playSound (Sound sound) {
sound.play(1);
}
}
diff --git a/demos/very-angry-robots/very-angry-robots/src/com/badlydrawngames/veryangryrobots/DesktopStarter.java b/demos/very-angry-robots/very-angry-robots/src/com/badlydrawngames/veryangryrobots/DesktopStarter.java
index 5e8f14b4736..4110e94b213 100644
--- a/demos/very-angry-robots/very-angry-robots/src/com/badlydrawngames/veryangryrobots/DesktopStarter.java
+++ b/demos/very-angry-robots/very-angry-robots/src/com/badlydrawngames/veryangryrobots/DesktopStarter.java
@@ -19,8 +19,8 @@ public class DesktopStarter {
private final static int WINDOW_WIDTH = 800;
private final static int WINDOW_HEIGHT = 480;
-
- public static void main(String[] args) {
+
+ public static void main (String[] args) {
new JoglApplication(new VeryAngryRobotsGame(), "Very Angry Robots", WINDOW_WIDTH, WINDOW_HEIGHT, false);
}
}
diff --git a/demos/very-angry-robots/very-angry-robots/src/com/badlydrawngames/veryangryrobots/DifficultyManager.java b/demos/very-angry-robots/very-angry-robots/src/com/badlydrawngames/veryangryrobots/DifficultyManager.java
index c77a60df5e3..e8fe118c69a 100644
--- a/demos/very-angry-robots/very-angry-robots/src/com/badlydrawngames/veryangryrobots/DifficultyManager.java
+++ b/demos/very-angry-robots/very-angry-robots/src/com/badlydrawngames/veryangryrobots/DifficultyManager.java
@@ -16,8 +16,11 @@
import com.badlogic.gdx.graphics.Color;
public interface DifficultyManager {
- Color getRobotColor();
- int getNumberOfRobots();
- int getNumberOfRobotShots();
- float getRobotShotSpeed();
+ Color getRobotColor ();
+
+ int getNumberOfRobots ();
+
+ int getNumberOfRobotShots ();
+
+ float getRobotShotSpeed ();
}
diff --git a/demos/very-angry-robots/very-angry-robots/src/com/badlydrawngames/veryangryrobots/Flyup.java b/demos/very-angry-robots/very-angry-robots/src/com/badlydrawngames/veryangryrobots/Flyup.java
index 3e97163c03d..f65e3e67d46 100644
--- a/demos/very-angry-robots/very-angry-robots/src/com/badlydrawngames/veryangryrobots/Flyup.java
+++ b/demos/very-angry-robots/very-angry-robots/src/com/badlydrawngames/veryangryrobots/Flyup.java
@@ -1,3 +1,4 @@
+
package com.badlydrawngames.veryangryrobots;
import com.badlydrawngames.general.Config;
@@ -9,24 +10,24 @@ public class Flyup {
private static final float X_OFFSET = (Assets.flyupFont.getBounds("888").width / 2) / Assets.pixelDensity;
private static final float Y_OFFSET = (Assets.flyupFont.getBounds("888").height) / Assets.pixelDensity;
private static final float SPEED = Config.asFloat("flyup.speed", 25.0f);
-
+
public final ScoreString scoreString;
public boolean active;
public float x;
public float y;
private float stateTime;
- public Flyup() {
+ public Flyup () {
scoreString = new ScoreString(3);
}
-
- public void update(float delta) {
+
+ public void update (float delta) {
stateTime += delta;
active = stateTime < LIFE_TIME;
y += SPEED * delta;
}
- public void spawn(float x, float y, int points) {
+ public void spawn (float x, float y, int points) {
active = true;
stateTime = 0.0f;
scoreString.setScore(points);
diff --git a/demos/very-angry-robots/very-angry-robots/src/com/badlydrawngames/veryangryrobots/FlyupManager.java b/demos/very-angry-robots/very-angry-robots/src/com/badlydrawngames/veryangryrobots/FlyupManager.java
index 100b23625d0..7873d9522be 100644
--- a/demos/very-angry-robots/very-angry-robots/src/com/badlydrawngames/veryangryrobots/FlyupManager.java
+++ b/demos/very-angry-robots/very-angry-robots/src/com/badlydrawngames/veryangryrobots/FlyupManager.java
@@ -1,3 +1,4 @@
+
package com.badlydrawngames.veryangryrobots;
import com.badlogic.gdx.utils.Array;
@@ -5,27 +6,27 @@
public class FlyupManager implements ScoringEventListener {
private static final int MAX_FLYUPS = 16;
-
+
final Array flyups;
private int index;
-
- public FlyupManager() {
+
+ public FlyupManager () {
flyups = new Array(MAX_FLYUPS);
for (int i = 0; i < MAX_FLYUPS; i++) {
flyups.add(new Flyup());
}
index = 0;
}
-
+
@Override
- public void onScoringEvent(float x, float y, int points) {
+ public void onScoringEvent (float x, float y, int points) {
flyups.get(index).spawn(x, y, points);
if (++index == MAX_FLYUPS) {
index = 0;
}
}
- public void update(float delta) {
+ public void update (float delta) {
for (Flyup flyup : flyups) {
if (flyup.active) {
flyup.update(delta);
diff --git a/demos/very-angry-robots/very-angry-robots/src/com/badlydrawngames/veryangryrobots/IShowScores.java b/demos/very-angry-robots/very-angry-robots/src/com/badlydrawngames/veryangryrobots/IShowScores.java
index 2582ab4d9f3..04669b5193d 100644
--- a/demos/very-angry-robots/very-angry-robots/src/com/badlydrawngames/veryangryrobots/IShowScores.java
+++ b/demos/very-angry-robots/very-angry-robots/src/com/badlydrawngames/veryangryrobots/IShowScores.java
@@ -1,5 +1,6 @@
+
package com.badlydrawngames.veryangryrobots;
public interface IShowScores {
- void showScores();
+ void showScores ();
}
diff --git a/demos/very-angry-robots/very-angry-robots/src/com/badlydrawngames/veryangryrobots/ISubmitScores.java b/demos/very-angry-robots/very-angry-robots/src/com/badlydrawngames/veryangryrobots/ISubmitScores.java
index 9a70f35157c..b054e4eb029 100644
--- a/demos/very-angry-robots/very-angry-robots/src/com/badlydrawngames/veryangryrobots/ISubmitScores.java
+++ b/demos/very-angry-robots/very-angry-robots/src/com/badlydrawngames/veryangryrobots/ISubmitScores.java
@@ -1,5 +1,6 @@
+
package com.badlydrawngames.veryangryrobots;
public interface ISubmitScores {
- void submitScore(final int score);
+ void submitScore (final int score);
}
diff --git a/demos/very-angry-robots/very-angry-robots/src/com/badlydrawngames/veryangryrobots/MainMenuScreen.java b/demos/very-angry-robots/very-angry-robots/src/com/badlydrawngames/veryangryrobots/MainMenuScreen.java
index c5f851eab48..ac2df75b7ba 100644
--- a/demos/very-angry-robots/very-angry-robots/src/com/badlydrawngames/veryangryrobots/MainMenuScreen.java
+++ b/demos/very-angry-robots/very-angry-robots/src/com/badlydrawngames/veryangryrobots/MainMenuScreen.java
@@ -13,9 +13,6 @@
package com.badlydrawngames.veryangryrobots;
-import static com.badlydrawngames.veryangryrobots.Assets.VIRTUAL_HEIGHT;
-import static com.badlydrawngames.veryangryrobots.Assets.VIRTUAL_WIDTH;
-
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.audio.Sound;
import com.badlogic.gdx.graphics.Color;
@@ -29,6 +26,8 @@
import com.badlydrawngames.general.GameScreen;
import com.badlydrawngames.general.SimpleButton;
+import static com.badlydrawngames.veryangryrobots.Assets.*;
+
public class MainMenuScreen extends GameScreen {
final String TITLE = "VERY ANGRY ROBOTS";
@@ -39,8 +38,8 @@ public class MainMenuScreen extends GameScreen {
private SimpleButton scoresButton;
private Vector3 touchPoint;
private boolean wasTouched;
-
- public MainMenuScreen(VeryAngryRobotsGame game) {
+
+ public MainMenuScreen (VeryAngryRobotsGame game) {
super(game);
menuCam = CameraHelper.createCamera2(ViewportMode.PIXEL_PERFECT, VIRTUAL_WIDTH, VIRTUAL_HEIGHT, Assets.pixelDensity);
spriteBatch = new SpriteBatch();
@@ -49,72 +48,70 @@ public MainMenuScreen(VeryAngryRobotsGame game) {
createButtons();
}
- private void createButtons() {
+ private void createButtons () {
playButton = createPlayButton();
- playButton.setWidth(VIRTUAL_WIDTH/4);
- playButton.setHeight(VIRTUAL_HEIGHT/4);
+ playButton.setWidth(VIRTUAL_WIDTH / 4);
+ playButton.setHeight(VIRTUAL_HEIGHT / 4);
if (game.canShowScores()) {
scoresButton = createShowScoresButton();
- scoresButton.setWidth(VIRTUAL_WIDTH/4);
- scoresButton.setHeight(VIRTUAL_HEIGHT/4);
+ scoresButton.setWidth(VIRTUAL_WIDTH / 4);
+ scoresButton.setHeight(VIRTUAL_HEIGHT / 4);
scoresButton.rightOn(VIRTUAL_WIDTH);
scoresButton.bottomOn(1.0f);
playButton.leftOn(0);
playButton.bottomOn(1.0f);
- }
- else {
+ } else {
playButton.bottomOn(1.0f);
playButton.centerHorizontallyOn(VIRTUAL_WIDTH / 2);
}
}
-
- private SimpleButton createPlayButton() {
- return new SimpleButton("Play", Assets.textFont);
+
+ private SimpleButton createPlayButton () {
+ return new SimpleButton("Play", Assets.textFont);
}
- private SimpleButton createShowScoresButton() {
+ private SimpleButton createShowScoresButton () {
return new SimpleButton("Scores", Assets.textFont);
}
@Override
- public void render(float delta) {
+ public void render (float delta) {
updateButtons(delta);
-
+
if (playButton.wasPressed()) {
playButtonSound();
startGame();
- }
- else if (game.canShowScores() && scoresButton.wasPressed()) {
+ } else if (game.canShowScores() && scoresButton.wasPressed()) {
playButtonSound();
showScores();
- }
- else {
+ } else {
Gdx.gl.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
spriteBatch.begin();
Assets.scoreFont.setColor(Color.WHITE);
float y = VIRTUAL_HEIGHT - Assets.scoreFont.getCapHeight() / 2.0f;
Assets.scoreFont.drawWrapped(spriteBatch, TITLE, 0, y, VIRTUAL_WIDTH, HAlignment.CENTER);
- Assets.textFont.drawWrapped(spriteBatch, JIBBER_JABBER, VIRTUAL_WIDTH / 8, 3 * VIRTUAL_HEIGHT / 4, 3 * VIRTUAL_WIDTH / 4, HAlignment.CENTER);
+ Assets.textFont.drawWrapped(spriteBatch, JIBBER_JABBER, VIRTUAL_WIDTH / 8, 3 * VIRTUAL_HEIGHT / 4,
+ 3 * VIRTUAL_WIDTH / 4, HAlignment.CENTER);
drawButtons();
spriteBatch.end();
}
}
- private void playButtonSound() {
+ private void playButtonSound () {
Sound buttonPressedSound = Assets.buttonSound;
Assets.playSound(buttonPressedSound);
}
-
- private void startGame() {
+
+ private void startGame () {
game.setScreen(game.playingScreen);
}
-
- private void showScores() {
+
+ private void showScores () {
game.showScores();
}
- private void updateButtons(float delta) {
+ private void updateButtons (float delta) {
touchPoint = screenToViewport(Gdx.input.getX(), Gdx.input.getY());
boolean justTouched = Gdx.input.justTouched();
boolean isTouched = Gdx.input.isTouched();
@@ -125,15 +122,15 @@ private void updateButtons(float delta) {
scoresButton.update(delta, justTouched, isTouched, justReleased, touchPoint.x, touchPoint.y);
}
}
-
- private void drawButtons() {
+
+ private void drawButtons () {
playButton.draw(spriteBatch);
if (game.canShowScores()) {
scoresButton.draw(spriteBatch);
}
}
- private Vector3 screenToViewport(float x, float y) {
+ private Vector3 screenToViewport (float x, float y) {
menuCam.unproject(touchPoint.set(Gdx.input.getX(), Gdx.input.getY(), 0));
return touchPoint;
}
diff --git a/demos/very-angry-robots/very-angry-robots/src/com/badlydrawngames/veryangryrobots/MazeGenerator.java b/demos/very-angry-robots/very-angry-robots/src/com/badlydrawngames/veryangryrobots/MazeGenerator.java
index 926997ab2c1..8ab5b33483e 100644
--- a/demos/very-angry-robots/very-angry-robots/src/com/badlydrawngames/veryangryrobots/MazeGenerator.java
+++ b/demos/very-angry-robots/very-angry-robots/src/com/badlydrawngames/veryangryrobots/MazeGenerator.java
@@ -13,25 +13,22 @@
package com.badlydrawngames.veryangryrobots;
-import static com.badlogic.gdx.math.MathUtils.random;
-
import com.badlogic.gdx.utils.IntArray;
+import static com.badlogic.gdx.math.MathUtils.*;
-/**
- * This class makes a maze using the recursive division method described on Wikipedia.
- * {@link http://en.wikipedia.org/wiki/Maze_generation_algorithm}
- */
+/** This class makes a maze using the recursive division method described on Wikipedia. {@link http
+ * ://en.wikipedia.org/wiki/Maze_generation_algorithm} */
public final class MazeGenerator {
-
+
private int width;
private int height;
private int doorPos;
-
+
private IntArray walls;
private IntArray doors;
- public MazeGenerator(int width, int height) {
+ public MazeGenerator (int width, int height) {
// Pre: width is odd
// Pre: height is odd
// Pre: width > 2
@@ -42,33 +39,33 @@ public MazeGenerator(int width, int height) {
doors = new IntArray();
}
- public MazeGenerator rebuild(int doorPos) {
+ public MazeGenerator rebuild (int doorPos) {
createMaze(doorPos);
this.doorPos = doorPos;
return this;
}
-
- public int getWidth() {
+
+ public int getWidth () {
return width;
}
-
- public int getHeight() {
+
+ public int getHeight () {
return height;
}
-
- public int getDoorPos() {
+
+ public int getDoorPos () {
return doorPos;
}
-
- public IntArray getWalls() {
+
+ public IntArray getWalls () {
return walls;
}
- public IntArray getDoors() {
+ public IntArray getDoors () {
return doors;
}
-
- private void createMaze(int doorPos) {
+
+ private void createMaze (int doorPos) {
walls.clear();
doors.clear();
addOuterWalls();
@@ -76,36 +73,36 @@ private void createMaze(int doorPos) {
subdivideChamber(0, 0, width, height);
}
- private void addOuterWalls() {
- addHWall(0, width/2, 0);
- addHWall(width/2+1, width, 0);
- addHWall(0, width/2, height);
- addHWall(width/2+1, width, height);
- addVWall(0, 0, height/2);
- addVWall(0, height/2+1, height);
- addVWall(width, 0, height/2);
- addVWall(width, height/2+1, height);
+ private void addOuterWalls () {
+ addHWall(0, width / 2, 0);
+ addHWall(width / 2 + 1, width, 0);
+ addHWall(0, width / 2, height);
+ addHWall(width / 2 + 1, width, height);
+ addVWall(0, 0, height / 2);
+ addVWall(0, height / 2 + 1, height);
+ addVWall(width, 0, height / 2);
+ addVWall(width, height / 2 + 1, height);
}
- private void subdivideChamber(int x1, int y1, int x2, int y2) {
+ private void subdivideChamber (int x1, int y1, int x2, int y2) {
// Get the size of the chamber and bail if it is too small to divide.
int w = x2 - x1;
int h = y2 - y1;
if (w < 2 || h < 2) return;
-
+
// Pick a point in the middle of the chamber.
int cx = random(x1 + 1, x2 - 1);
int cy = random(y1 + 1, y2 - 1);
-
+
// Choose the solid wall.
int solid = random(0, 3);
-
+
// Add the internal walls.
addHWall(x1, cx, cy, solid == 0);
addHWall(cx, x2, cy, solid == 1);
addVWall(cx, y1, cy, solid == 2);
addVWall(cx, cy, y2, solid == 3);
-
+
// Create the subchambers.
subdivideChamber(x1, y1, cx, cy);
subdivideChamber(cx, y1, x2, cy);
@@ -113,73 +110,71 @@ private void subdivideChamber(int x1, int y1, int x2, int y2) {
subdivideChamber(cx, cy, x2, y2);
}
- private void addHWall(int x1, int x2, int y, boolean solid) {
+ private void addHWall (int x1, int x2, int y, boolean solid) {
int length = x2 - x1;
if (length < 2) return;
if (!solid) {
int x = random(x1, x2 - 1);
addHWall(x1, x, y);
addHWall(x + 1, x2, y);
- }
- else {
+ } else {
addHWall(x1, x2, y);
}
}
- private void addHWall(int x1, int x2, int y) {
+ private void addHWall (int x1, int x2, int y) {
if (x2 <= x1) return;
addWall(x1, y, x2, y);
}
- private void addVWall(int x, int y1, int y2, boolean solid) {
+ private void addVWall (int x, int y1, int y2, boolean solid) {
int length = y2 - y1;
if (length < 2) return;
if (!solid) {
int y = random(y1, y2 - 1);
addVWall(x, y1, y);
addVWall(x, y + 1, y2);
- }
- else {
+ } else {
addVWall(x, y1, y2);
}
}
- private void addVWall(int x, int y1, int y2) {
+ private void addVWall (int x, int y1, int y2) {
if (y2 <= y1) return;
addWall(x, y1, x, y2);
}
- private void addWall(int x1, int y1, int x2, int y2) {
+ private void addWall (int x1, int y1, int x2, int y2) {
walls.add(x1);
walls.add(y1);
walls.add(x2);
walls.add(y2);
}
-
- private void addDoors(int doorPos) {
+
+ private void addDoors (int doorPos) {
if ((doorPos & DoorPositions.MIN_Y) == DoorPositions.MIN_Y) {
- addHDoor(width/2, 0);
+ addHDoor(width / 2, 0);
}
if ((doorPos & DoorPositions.MAX_Y) == DoorPositions.MAX_Y) {
- addHDoor(width/2, height);
+ addHDoor(width / 2, height);
}
if ((doorPos & DoorPositions.MIN_X) == DoorPositions.MIN_X) {
- addVDoor(0, height/2);
+ addVDoor(0, height / 2);
}
if ((doorPos & DoorPositions.MAX_X) == DoorPositions.MAX_X) {
- addVDoor(width, height/2);
+ addVDoor(width, height / 2);
}
}
- private void addHDoor(int x, int y) {
+ private void addHDoor (int x, int y) {
addDoor(x, y, x + 1, y);
}
- private void addVDoor(int x, int y) {
+ private void addVDoor (int x, int y) {
addDoor(x, y, x, y + 1);
}
-
- private void addDoor(int x1, int y1, int x2, int y2) {
+
+ private void addDoor (int x1, int y1, int x2, int y2) {
doors.add(x1);
doors.add(y1);
doors.add(x2);
diff --git a/demos/very-angry-robots/very-angry-robots/src/com/badlydrawngames/veryangryrobots/ParticleAdapter.java b/demos/very-angry-robots/very-angry-robots/src/com/badlydrawngames/veryangryrobots/ParticleAdapter.java
index 0fdfcbd1df4..293249c4ae2 100644
--- a/demos/very-angry-robots/very-angry-robots/src/com/badlydrawngames/veryangryrobots/ParticleAdapter.java
+++ b/demos/very-angry-robots/very-angry-robots/src/com/badlydrawngames/veryangryrobots/ParticleAdapter.java
@@ -22,33 +22,33 @@
class ParticleAdapter implements WorldListener {
final int PARTICLES = 32;
-
+
final private World world;
final private ParticleManager particleManager;
private Color robotColor;
private Color shotExplosionColor;
-
- public ParticleAdapter(World world, ParticleManager particleManager) {
+
+ public ParticleAdapter (World world, ParticleManager particleManager) {
this.world = world;
this.particleManager = particleManager;
shotExplosionColor = new Color(1.0f, 0.5f, 0.0f, 1.0f);
}
-
- public void setRobotColor(Color color) {
+
+ public void setRobotColor (Color color) {
this.robotColor = color;
}
- public void update(float delta) {
+ public void update (float delta) {
particleManager.update(delta);
}
-
+
@Override
- public void onEnteredRoom(float time, int robots) {
+ public void onEnteredRoom (float time, int robots) {
particleManager.clear();
}
@Override
- public void onPlayerHit() {
+ public void onPlayerHit () {
Player player = world.getPlayer();
float x = player.x + player.width / 2;
float y = player.y + player.height / 2;
@@ -56,45 +56,45 @@ public void onPlayerHit() {
}
@Override
- public void onRobotDestroyed(Robot robot) {
+ public void onRobotDestroyed (Robot robot) {
float x = robot.x + robot.width / 2;
float y = robot.y + robot.height / 2;
particleManager.add(x, y, PARTICLES, robotColor);
}
-
+
@Override
- public void onShotDestroyed(BaseShot shot) {
+ public void onShotDestroyed (BaseShot shot) {
float x = shot.x + shot.width / 2;
float y = shot.y + shot.height / 2;
particleManager.add(x, y, PARTICLES / 8, shotExplosionColor);
}
@Override
- public void onCaptainActivated(float time) {
+ public void onCaptainActivated (float time) {
}
@Override
- public void onExitedRoom(float time, int robots) {
+ public void onExitedRoom (float time, int robots) {
}
@Override
- public void onPlayerFired() {
+ public void onPlayerFired () {
}
@Override
- public void onPlayerSpawned() {
+ public void onPlayerSpawned () {
}
@Override
- public void onRobotFired(Robot robot) {
+ public void onRobotFired (Robot robot) {
}
@Override
- public void onRobotHit(Robot robot) {
+ public void onRobotHit (Robot robot) {
}
@Override
- public void onWorldReset() {
+ public void onWorldReset () {
}
-
+
}
diff --git a/demos/very-angry-robots/very-angry-robots/src/com/badlydrawngames/veryangryrobots/RoomBuilder.java b/demos/very-angry-robots/very-angry-robots/src/com/badlydrawngames/veryangryrobots/RoomBuilder.java
index 6556e38fdb7..6213c04efe4 100644
--- a/demos/very-angry-robots/very-angry-robots/src/com/badlydrawngames/veryangryrobots/RoomBuilder.java
+++ b/demos/very-angry-robots/very-angry-robots/src/com/badlydrawngames/veryangryrobots/RoomBuilder.java
@@ -27,45 +27,45 @@ public class RoomBuilder {
private static final int MAX_RECTANGLES = 256;
private static final int MAX_DOORS = 4;
private static final int MAX_WALLS = MAX_RECTANGLES - MAX_DOORS;
-
+
private final MazeGenerator mazeGenerator;
private final Pool rectanglePool;
private Array doorRects;
private Array wallRects;
private final int hcells;
private final int vcells;
-
- public RoomBuilder(int hcells, int vcells) {
+
+ public RoomBuilder (int hcells, int vcells) {
this.hcells = hcells;
this.vcells = vcells;
mazeGenerator = new MazeGenerator(hcells, vcells);
rectanglePool = new Pool(MAX_RECTANGLES) {
@Override
- protected Rectangle newObject() {
+ protected Rectangle newObject () {
return new Rectangle();
}
};
}
- public void build(int doorPosition) {
+ public void build (int doorPosition) {
mazeGenerator.rebuild(doorPosition);
createWallsAndDoors();
}
-
- public Array getWalls() {
+
+ public Array getWalls () {
return wallRects;
}
-
- public Array getDoors() {
+
+ public Array getDoors () {
return doorRects;
}
-
- private void createWallsAndDoors() {
+
+ private void createWallsAndDoors () {
createWalls();
createDoors();
}
- private void createWalls() {
+ private void createWalls () {
IntArray wallDefs = mazeGenerator.getWalls();
int n = wallDefs.size / 4;
wallRects = Pools.makeArrayFromPool(wallRects, rectanglePool, MAX_WALLS);
@@ -75,17 +75,17 @@ private void createWalls() {
}
}
- private void createDoors() {
+ private void createDoors () {
IntArray doorDefs = mazeGenerator.getDoors();
- int n = doorDefs.size/ 4;
+ int n = doorDefs.size / 4;
doorRects = Pools.makeArrayFromPool(doorRects, rectanglePool, MAX_DOORS);
for (int i = 0, j = 0; i < n; i++, j += 4) {
- Rectangle doorRect = createDoor(doorDefs, j);
+ Rectangle doorRect = createDoor(doorDefs, j);
doorRects.add(doorRect);
}
}
- private Rectangle createWall(IntArray wallDefs, int i) {
+ private Rectangle createWall (IntArray wallDefs, int i) {
int x1 = wallDefs.get(i);
int y1 = wallDefs.get(i + 1);
int x2 = wallDefs.get(i + 2);
@@ -93,7 +93,7 @@ private Rectangle createWall(IntArray wallDefs, int i) {
return (x1 == x2) ? createVWall(x1, y1, y2) : createHWall(x1, x2, y1);
}
- private Rectangle createHWall(int x1, int x2, int y1) {
+ private Rectangle createHWall (int x1, int x2, int y1) {
float x = coordMinusHalfHeight(x1, hcells);
float y = coordMinusHalfHeight(y1, vcells);
float t = coordMinusHalfHeight(x2, hcells);
@@ -101,8 +101,8 @@ private Rectangle createHWall(int x1, int x2, int y1) {
float h = WALL_HEIGHT;
return newRectangle(x, y, w, h);
}
-
- private Rectangle createVWall(int x1, int y1, int y2) {
+
+ private Rectangle createVWall (int x1, int y1, int y2) {
float x = coordMinusHalfHeight(x1, hcells);
float y = coordMinusHalfHeight(y1, vcells);
float t = coordMinusHalfHeight(y2, vcells);
@@ -110,62 +110,58 @@ private Rectangle createVWall(int x1, int y1, int y2) {
float h = (t - y) + WALL_HEIGHT;
return newRectangle(x, y, w, h);
}
-
- private Rectangle createDoor(IntArray doorDefs, int i) {
+
+ private Rectangle createDoor (IntArray doorDefs, int i) {
int x1 = doorDefs.get(i);
int y1 = doorDefs.get(i + 1);
int x2 = doorDefs.get(i + 2);
return (x1 == x2) ? createVDoor(x1, y1) : createHDoor(x1, y1);
}
-
- private Rectangle createHDoor(int x1, int y1) {
+
+ private Rectangle createHDoor (int x1, int y1) {
float x = coordPlusHalfHeight(x1, hcells);
float y = coordMinusHalfHeight(y1, vcells);
float w = WALL_WIDTH - WALL_HEIGHT;
float h = WALL_HEIGHT;
return newRectangle(x, y, w, h);
}
-
- private Rectangle createVDoor(int x1, int y1) {
+
+ private Rectangle createVDoor (int x1, int y1) {
float x = coordMinusHalfHeight(x1, hcells);
float y = coordPlusHalfHeight(y1, vcells);
float w = WALL_HEIGHT;
float h = WALL_WIDTH - WALL_HEIGHT;
return newRectangle(x, y, w, h);
}
-
- private float coordPlusHalfHeight(int c, int limit) {
+
+ private float coordPlusHalfHeight (int c, int limit) {
float n = ADJUSTMENT;
if (c == 0) {
- return n + HALF_HEIGHT;
- }
- else if (c < limit) {
+ return n + HALF_HEIGHT;
+ } else if (c < limit) {
return n + WALL_WIDTH - ADJUSTMENT + ((c - 1) * WALL_WIDTH) + HALF_HEIGHT;
- }
- else {
+ } else {
return n + 2 * (WALL_WIDTH - ADJUSTMENT) + ((c - 2) * WALL_WIDTH) + HALF_HEIGHT;
}
}
-
- private float coordMinusHalfHeight(int c, int limit) {
+
+ private float coordMinusHalfHeight (int c, int limit) {
float n = ADJUSTMENT;
if (c == 0) {
- return n - HALF_HEIGHT;
- }
- else if (c < limit) {
+ return n - HALF_HEIGHT;
+ } else if (c < limit) {
return n + WALL_WIDTH - ADJUSTMENT + ((c - 1) * WALL_WIDTH) - HALF_HEIGHT;
- }
- else {
+ } else {
return n + 2 * (WALL_WIDTH - ADJUSTMENT) + ((c - 2) * WALL_WIDTH) - HALF_HEIGHT;
}
}
-
- private Rectangle newRectangle(float x, float y, float w, float h) {
+
+ private Rectangle newRectangle (float x, float y, float w, float h) {
Rectangle r = rectanglePool.obtain();
r.x = x;
r.y = y;
r.width = w;
r.height = h;
return r;
- }
+ }
}
diff --git a/demos/very-angry-robots/very-angry-robots/src/com/badlydrawngames/veryangryrobots/ScoreBasedDifficultyManager.java b/demos/very-angry-robots/very-angry-robots/src/com/badlydrawngames/veryangryrobots/ScoreBasedDifficultyManager.java
index 8bc0fe7f52b..a03fe76b00c 100644
--- a/demos/very-angry-robots/very-angry-robots/src/com/badlydrawngames/veryangryrobots/ScoreBasedDifficultyManager.java
+++ b/demos/very-angry-robots/very-angry-robots/src/com/badlydrawngames/veryangryrobots/ScoreBasedDifficultyManager.java
@@ -21,11 +21,11 @@ public class ScoreBasedDifficultyManager implements DifficultyManager, ScoreList
// Robot numbers.
private static final int MAX_ROBOTS = Config.asInt("Global.maxRobots", 12);
private static final int INITIAL_ROBOTS = Config.asInt("Global.initialRobots", 6);
-
+
// Shot speeds.
private static final float SLOW_SHOT_SPEED = Config.asFloat("RobotShot.slowSpeed", 75.0f);
private static final float FAST_SHOT_SPEED = Config.asFloat("RobotShot.fastSpeed", 125.0f);
-
+
// Level progression.
private static final int ROBOT_INCREMENT = Config.asInt("Level.robotIncrement", 3);
private static final int LEVEL_0_ROBOT_SHOTS = Config.asInt("Level.0.robotShots", 0);
@@ -62,109 +62,98 @@ public class ScoreBasedDifficultyManager implements DifficultyManager, ScoreList
private static final Color WHITE = Color.WHITE;
private static final Color LIGHT_PURPLE = new Color(1.0f, 0.0f, 1.0f, 1.0f);
private static final Color GREY = new Color(0.75f, 0.75f, 0.75f, 1.0f);
-
+
private boolean dirty;
private int score;
private Color robotColor;
private int numRobots;
private int numRobotShots;
private float robotShotSpeed;
-
+
@Override
- public Color getRobotColor() {
+ public Color getRobotColor () {
updateIfDirty();
return robotColor;
}
@Override
- public int getNumberOfRobots() {
+ public int getNumberOfRobots () {
updateIfDirty();
return numRobots;
}
@Override
- public int getNumberOfRobotShots() {
+ public int getNumberOfRobotShots () {
updateIfDirty();
return numRobotShots;
}
-
+
@Override
- public float getRobotShotSpeed() {
+ public float getRobotShotSpeed () {
updateIfDirty();
return robotShotSpeed;
}
@Override
- public void onScoreChanged(int score) {
+ public void onScoreChanged (int score) {
dirty = true;
this.score = score;
}
@Override
- public void onLivesChanged(int lives) {
+ public void onLivesChanged (int lives) {
}
-
- private void updateIfDirty() {
+
+ private void updateIfDirty () {
if (!dirty) return;
dirty = false;
-
+
Color lastRobotColor = robotColor;
if (score < LEVEL_1_SCORE) {
robotColor = DARK_YELLOW;
numRobotShots = LEVEL_0_ROBOT_SHOTS;
robotShotSpeed = SLOW_SHOT_SPEED;
- }
- else if (score < LEVEL_2_SCORE) {
+ } else if (score < LEVEL_2_SCORE) {
robotColor = RED;
numRobotShots = LEVEL_1_ROBOT_SHOTS;
robotShotSpeed = SLOW_SHOT_SPEED;
- }
- else if (score < LEVEL_3_SCORE) {
+ } else if (score < LEVEL_3_SCORE) {
robotColor = DARK_CYAN;
numRobotShots = LEVEL_2_ROBOT_SHOTS;
robotShotSpeed = SLOW_SHOT_SPEED;
- }
- else if (score < LEVEL_4_SCORE) {
+ } else if (score < LEVEL_4_SCORE) {
robotColor = GREEN;
numRobotShots = LEVEL_3_ROBOT_SHOTS;
robotShotSpeed = SLOW_SHOT_SPEED;
- }
- else if (score < LEVEL_5_SCORE) {
+ } else if (score < LEVEL_5_SCORE) {
robotColor = DARK_PURPLE;
numRobotShots = LEVEL_4_ROBOT_SHOTS;
robotShotSpeed = SLOW_SHOT_SPEED;
- }
- else if (score < LEVEL_6_SCORE) {
+ } else if (score < LEVEL_6_SCORE) {
robotColor = LIGHT_YELLOW;
numRobotShots = LEVEL_5_ROBOT_SHOTS;
robotShotSpeed = SLOW_SHOT_SPEED;
- }
- else if (score < LEVEL_7_SCORE) {
+ } else if (score < LEVEL_7_SCORE) {
robotColor = WHITE;
numRobotShots = LEVEL_6_ROBOT_SHOTS;
robotShotSpeed = FAST_SHOT_SPEED;
- }
- else if (score < LEVEL_8_SCORE) {
+ } else if (score < LEVEL_8_SCORE) {
robotColor = DARK_CYAN;
numRobotShots = LEVEL_7_ROBOT_SHOTS;
robotShotSpeed = FAST_SHOT_SPEED;
- }
- else if (score < LEVEL_9_SCORE) {
+ } else if (score < LEVEL_9_SCORE) {
robotColor = LIGHT_PURPLE;
numRobotShots = LEVEL_8_ROBOT_SHOTS;
robotShotSpeed = FAST_SHOT_SPEED;
- }
- else if (score < LEVEL_10_SCORE) {
+ } else if (score < LEVEL_10_SCORE) {
robotColor = GREY;
numRobotShots = LEVEL_9_ROBOT_SHOTS;
robotShotSpeed = FAST_SHOT_SPEED;
- }
- else if (score < LEVEL_11_SCORE) {
+ } else if (score < LEVEL_11_SCORE) {
robotColor = DARK_YELLOW;
numRobotShots = LEVEL_10_ROBOT_SHOTS;
robotShotSpeed = FAST_SHOT_SPEED;
- }
- else {
+ } else {
robotColor = RED;
numRobotShots = LEVEL_11_ROBOT_SHOTS;
robotShotSpeed = FAST_SHOT_SPEED;
@@ -174,8 +163,7 @@ else if (score < LEVEL_11_SCORE) {
if (numRobots < MAX_ROBOTS) {
numRobots += ROBOT_INCREMENT;
}
- }
- else {
+ } else {
numRobots = INITIAL_ROBOTS;
}
}
diff --git a/demos/very-angry-robots/very-angry-robots/src/com/badlydrawngames/veryangryrobots/ScoreListener.java b/demos/very-angry-robots/very-angry-robots/src/com/badlydrawngames/veryangryrobots/ScoreListener.java
index 2899bd5677d..b753ea0f896 100644
--- a/demos/very-angry-robots/very-angry-robots/src/com/badlydrawngames/veryangryrobots/ScoreListener.java
+++ b/demos/very-angry-robots/very-angry-robots/src/com/badlydrawngames/veryangryrobots/ScoreListener.java
@@ -14,6 +14,7 @@
package com.badlydrawngames.veryangryrobots;
public interface ScoreListener {
- void onScoreChanged(int score);
- void onLivesChanged(int lives);
+ void onScoreChanged (int score);
+
+ void onLivesChanged (int lives);
}
diff --git a/demos/very-angry-robots/very-angry-robots/src/com/badlydrawngames/veryangryrobots/ScoreNotifier.java b/demos/very-angry-robots/very-angry-robots/src/com/badlydrawngames/veryangryrobots/ScoreNotifier.java
index 85b52e055c0..21c02363593 100644
--- a/demos/very-angry-robots/very-angry-robots/src/com/badlydrawngames/veryangryrobots/ScoreNotifier.java
+++ b/demos/very-angry-robots/very-angry-robots/src/com/badlydrawngames/veryangryrobots/ScoreNotifier.java
@@ -18,24 +18,24 @@
public class ScoreNotifier implements ScoreListener {
private Array listeners;
-
- public ScoreNotifier() {
+
+ public ScoreNotifier () {
listeners = new Array();
}
-
- public void addListener(ScoreListener listener) {
+
+ public void addListener (ScoreListener listener) {
listeners.add(listener);
}
-
+
@Override
- public void onScoreChanged(int score) {
+ public void onScoreChanged (int score) {
for (ScoreListener listener : listeners) {
listener.onScoreChanged(score);
}
}
@Override
- public void onLivesChanged(int lives) {
+ public void onLivesChanged (int lives) {
for (ScoreListener listener : listeners) {
listener.onLivesChanged(lives);
}
diff --git a/demos/very-angry-robots/very-angry-robots/src/com/badlydrawngames/veryangryrobots/ScoresScreen.java b/demos/very-angry-robots/very-angry-robots/src/com/badlydrawngames/veryangryrobots/ScoresScreen.java
index 2e59e156c06..e52773baef2 100644
--- a/demos/very-angry-robots/very-angry-robots/src/com/badlydrawngames/veryangryrobots/ScoresScreen.java
+++ b/demos/very-angry-robots/very-angry-robots/src/com/badlydrawngames/veryangryrobots/ScoresScreen.java
@@ -13,9 +13,6 @@
package com.badlydrawngames.veryangryrobots;
-import static com.badlydrawngames.veryangryrobots.Assets.VIRTUAL_HEIGHT;
-import static com.badlydrawngames.veryangryrobots.Assets.VIRTUAL_WIDTH;
-
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Preferences;
import com.badlogic.gdx.graphics.Color;
@@ -29,14 +26,16 @@
import com.badlydrawngames.general.GameScreen;
import com.badlydrawngames.general.ScoreString;
+import static com.badlydrawngames.veryangryrobots.Assets.*;
+
public class ScoresScreen extends GameScreen {
-
+
private static final String LAST_SCORE = "Score:";
private static final String TOP_SCORE = "Best: ";
private static final String VERY_ANGRY_ROBOTS = "VeryAngryRobots";
private static final String TOP_SCORE_PREF = "top score";
private static final String TAP_TO_CONTINUE = "Tap to continue";
-
+
private ScoreString scoreString;
private ScoreString topScoreString;
private OrthographicCamera scoreCam;
@@ -46,7 +45,7 @@ public class ScoresScreen extends GameScreen {
private final Preferences preferences;
private float stateTime;
- public ScoresScreen(VeryAngryRobotsGame game) {
+ public ScoresScreen (VeryAngryRobotsGame game) {
super(game);
scoreCam = CameraHelper.createCamera2(ViewportMode.PIXEL_PERFECT, VIRTUAL_WIDTH, VIRTUAL_HEIGHT, Assets.pixelDensity);
spriteBatch = new SpriteBatch();
@@ -58,8 +57,8 @@ public ScoresScreen(VeryAngryRobotsGame game) {
topScoreString.setScore(topScore);
stateTime = 0.0f;
}
-
- public void setScore(int score) {
+
+ public void setScore (int score) {
scoreString.setScore(score);
if (score > topScore) {
topScore = score;
@@ -68,18 +67,16 @@ public void setScore(int score) {
topScoreString.setScore(score);
}
}
-
+
@Override
- public void render(float delta) {
+ public void render (float delta) {
stateTime += delta;
if (Gdx.input.justTouched()) {
touched = true;
- }
- else if (touched && !Gdx.input.isTouched()) {
+ } else if (touched && !Gdx.input.isTouched()) {
touched = false;
game.setScreen(game.mainMenuScreen);
- }
- else {
+ } else {
Gdx.gl.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
spriteBatch.begin();
@@ -93,7 +90,7 @@ else if (touched && !Gdx.input.isTouched()) {
Assets.scoreFont.setColor(Color.WHITE);
Assets.scoreFont.draw(spriteBatch, TOP_SCORE, x, y);
Assets.scoreFont.draw(spriteBatch, topScoreString, x + w, y);
-
+
b = Assets.scoreFont.getBounds(TOP_SCORE);
w = b.width + Assets.scoreFont.getSpaceWidth();
b = Assets.scoreFont.getBounds(topScoreString);
@@ -102,28 +99,28 @@ else if (touched && !Gdx.input.isTouched()) {
y += 2 * b.height;
Assets.scoreFont.draw(spriteBatch, LAST_SCORE, x, y);
Assets.scoreFont.draw(spriteBatch, scoreString, x + w, y);
-
+
if (stateTime % 1.0f < 0.5f) {
Assets.textFont.setColor(Color.WHITE);
- Assets.textFont.drawWrapped(spriteBatch, TAP_TO_CONTINUE, 0, VIRTUAL_HEIGHT/4, VIRTUAL_WIDTH, HAlignment.CENTER);
+ Assets.textFont.drawWrapped(spriteBatch, TAP_TO_CONTINUE, 0, VIRTUAL_HEIGHT / 4, VIRTUAL_WIDTH, HAlignment.CENTER);
}
spriteBatch.end();
}
}
-
+
@Override
- public void show() {
+ public void show () {
Gdx.input.setCatchBackKey(true);
stateTime = 0.0f;
}
-
+
@Override
- public void hide() {
+ public void hide () {
Gdx.input.setCatchBackKey(false);
}
-
+
@Override
- public void resume() {
+ public void resume () {
Gdx.input.setCatchBackKey(true);
}
}
diff --git a/demos/very-angry-robots/very-angry-robots/src/com/badlydrawngames/veryangryrobots/ScoringEventListener.java b/demos/very-angry-robots/very-angry-robots/src/com/badlydrawngames/veryangryrobots/ScoringEventListener.java
index 7e1c8054eb8..f232c7447a9 100644
--- a/demos/very-angry-robots/very-angry-robots/src/com/badlydrawngames/veryangryrobots/ScoringEventListener.java
+++ b/demos/very-angry-robots/very-angry-robots/src/com/badlydrawngames/veryangryrobots/ScoringEventListener.java
@@ -14,5 +14,5 @@
package com.badlydrawngames.veryangryrobots;
public interface ScoringEventListener {
- void onScoringEvent(float x, float y, int points);
+ void onScoringEvent (float x, float y, int points);
}
diff --git a/demos/very-angry-robots/very-angry-robots/src/com/badlydrawngames/veryangryrobots/ScoringEventNotifier.java b/demos/very-angry-robots/very-angry-robots/src/com/badlydrawngames/veryangryrobots/ScoringEventNotifier.java
index 7dde62b9d49..a7bc2356e8b 100644
--- a/demos/very-angry-robots/very-angry-robots/src/com/badlydrawngames/veryangryrobots/ScoringEventNotifier.java
+++ b/demos/very-angry-robots/very-angry-robots/src/com/badlydrawngames/veryangryrobots/ScoringEventNotifier.java
@@ -1,3 +1,4 @@
+
package com.badlydrawngames.veryangryrobots;
import com.badlogic.gdx.utils.Array;
@@ -5,17 +6,17 @@
public class ScoringEventNotifier implements ScoringEventListener {
private final Array listeners;
-
- public ScoringEventNotifier() {
+
+ public ScoringEventNotifier () {
listeners = new Array();
}
-
- public void addListener(ScoringEventListener listener) {
+
+ public void addListener (ScoringEventListener listener) {
listeners.add(listener);
}
-
+
@Override
- public void onScoringEvent(float x, float y, int points) {
+ public void onScoringEvent (float x, float y, int points) {
for (ScoringEventListener listener : listeners) {
listener.onScoringEvent(x, y, points);
}
diff --git a/demos/very-angry-robots/very-angry-robots/src/com/badlydrawngames/veryangryrobots/SoundManager.java b/demos/very-angry-robots/very-angry-robots/src/com/badlydrawngames/veryangryrobots/SoundManager.java
index 82307e918d0..2ed059bd9db 100644
--- a/demos/very-angry-robots/very-angry-robots/src/com/badlydrawngames/veryangryrobots/SoundManager.java
+++ b/demos/very-angry-robots/very-angry-robots/src/com/badlydrawngames/veryangryrobots/SoundManager.java
@@ -13,17 +13,17 @@
package com.badlydrawngames.veryangryrobots;
-import static com.badlogic.gdx.math.MathUtils.random;
-
import com.badlogic.gdx.audio.Sound;
import com.badlydrawngames.veryangryrobots.StatusManager.Achievements;
import com.badlydrawngames.veryangryrobots.mobiles.BaseShot;
import com.badlydrawngames.veryangryrobots.mobiles.Robot;
+import static com.badlogic.gdx.math.MathUtils.*;
+
public class SoundManager implements WorldListener, AchievementsListener, ScoreListener {
private static final float MIN_TAUNT_INTERVAL = 2.5f;
private static final float MAX_TAUNT_INTERVAL = 15.0f;
-
+
private float now;
private float nextTauntTime;
private float lastRobotFireTime;
@@ -34,32 +34,32 @@ public class SoundManager implements WorldListener, AchievementsListener, ScoreL
private int lives;
@Override
- public void onEnteredRoom(float time, int robots) {
+ public void onEnteredRoom (float time, int robots) {
Assets.playSound(Assets.spawnPlayerSound);
}
-
+
@Override
- public void onExitedRoom(float time, int robots) {
- isChicken = robots > 0;
+ public void onExitedRoom (float time, int robots) {
+ isChicken = robots > 0;
if (isChicken) {
Assets.playSound(Assets.exitRoomAsChickenSpeech);
}
canTaunt = false;
}
-
+
@Override
- public void onPlayerSpawned() {
+ public void onPlayerSpawned () {
canTaunt = true;
scheduleTaunt();
}
-
+
@Override
- public void onPlayerFired() {
+ public void onPlayerFired () {
Assets.playSound(Assets.playerShotSound);
}
@Override
- public void onRobotFired(Robot robot) {
+ public void onRobotFired (Robot robot) {
if (lastRobotFireTime != now) {
Assets.playSound(Assets.robotShotSound);
lastRobotFireTime = now;
@@ -67,7 +67,7 @@ public void onRobotFired(Robot robot) {
}
@Override
- public void onPlayerHit() {
+ public void onPlayerHit () {
if (lastPlayerHitTime != now) {
canTaunt = false;
Assets.playSound(Assets.killPlayerSound);
@@ -76,41 +76,41 @@ public void onPlayerHit() {
}
@Override
- public void onRobotDestroyed(Robot robot) {
+ public void onRobotDestroyed (Robot robot) {
if (lastRobotHitTime != now) {
Assets.playSound(Assets.killRobotSound);
lastRobotHitTime = now;
}
}
-
+
@Override
- public void onCaptainActivated(float time) {
+ public void onCaptainActivated (float time) {
Assets.playSound(Assets.captainEnterRoomSpeech);
// We can't do much about any speech going on, but we can make sure nothing else talks over the top of this
// one.
scheduleTaunt();
}
-
+
@Override
- public void onRobotHit(Robot robot) {
+ public void onRobotHit (Robot robot) {
}
@Override
- public void onShotDestroyed(BaseShot shot) {
+ public void onShotDestroyed (BaseShot shot) {
}
@Override
- public void onWorldReset() {
+ public void onWorldReset () {
isChicken = false;
lives = 0;
}
@Override
- public void onAttained(Achievements achievement) {
+ public void onAttained (Achievements achievement) {
Assets.playSound(Assets.achievementSound);
}
-
- public void update(float delta) {
+
+ public void update (float delta) {
now += delta;
if (canTaunt && now >= nextTauntTime) {
Sound[] sounds = isChicken ? Assets.chickenTaunts : Assets.standardTaunts;
@@ -118,17 +118,17 @@ public void update(float delta) {
scheduleTaunt();
}
}
-
- private void scheduleTaunt() {
+
+ private void scheduleTaunt () {
nextTauntTime = now + random(MIN_TAUNT_INTERVAL, MAX_TAUNT_INTERVAL);
}
@Override
- public void onScoreChanged(int score) {
+ public void onScoreChanged (int score) {
}
@Override
- public void onLivesChanged(int lives) {
+ public void onLivesChanged (int lives) {
if (lives - 1 == this.lives) {
Assets.playSound(Assets.extraLifeSound);
}
diff --git a/demos/very-angry-robots/very-angry-robots/src/com/badlydrawngames/veryangryrobots/StatusManager.java b/demos/very-angry-robots/very-angry-robots/src/com/badlydrawngames/veryangryrobots/StatusManager.java
index 862523d6879..b1bc14ed90c 100644
--- a/demos/very-angry-robots/very-angry-robots/src/com/badlydrawngames/veryangryrobots/StatusManager.java
+++ b/demos/very-angry-robots/very-angry-robots/src/com/badlydrawngames/veryangryrobots/StatusManager.java
@@ -23,27 +23,30 @@
public class StatusManager implements WorldListener {
public enum Achievements {
- PERFECTIONIST("Perfectionist", "Clear " + CLEAN_ROOMS + " rooms in a row."),
- PERFECT_SHOT("Perfect Shot", "Clear a room by shooting everything."),
- PACIFICIST("Pacifist", "Clear a room without shooting anything."),
- DAREDEVIL("Daredevil", "Survive for " + DAREDEVIL_SECONDS + " seconds after the captain enters the room."),
- COWARD("Coward", "Run from " + CHICKEN_ROOMS + " rooms in a row."),
- ADDICT("Addict", "Play " + ADDICT_GAMES + " games."),
- LUCKY_JIM("Lucky Jim", "Survive for " + LUCKY_JIM_ROOMS + " rooms without being hit."),
- ROBOCIDE("Robocide", "Destroyed " + ROBOCIDE_ROBOTS + " robots");
+ PERFECTIONIST("Perfectionist", "Clear " + CLEAN_ROOMS + " rooms in a row."), PERFECT_SHOT("Perfect Shot",
+ "Clear a room by shooting everything."), PACIFICIST("Pacifist", "Clear a room without shooting anything."), DAREDEVIL(
+ "Daredevil", "Survive for " + DAREDEVIL_SECONDS + " seconds after the captain enters the room."), COWARD("Coward",
+ "Run from " + CHICKEN_ROOMS + " rooms in a row."), ADDICT("Addict", "Play " + ADDICT_GAMES + " games."), LUCKY_JIM(
+ "Lucky Jim", "Survive for " + LUCKY_JIM_ROOMS + " rooms without being hit."), ROBOCIDE("Robocide", "Destroyed "
+ + ROBOCIDE_ROBOTS + " robots");
private final String summary;
private final String text;
-
- private Achievements(String summary, String text) {
+
+ private Achievements (String summary, String text) {
this.summary = summary;
this.text = text;
}
-
- public String summary() { return this.summary; }
- public String text() { return this.text; }
+
+ public String summary () {
+ return this.summary;
+ }
+
+ public String text () {
+ return this.text;
+ }
}
-
+
// Achievements.
private static final int CLEAN_ROOMS = Config.asInt("achievements.cleanRoomsForPerfectionist", 5);
private static final int ROBOCIDE_ROBOTS = Config.asInt("achievements.robotsForRobocide", 50);
@@ -51,7 +54,7 @@ private Achievements(String summary, String text) {
private static final int CHICKEN_ROOMS = Config.asInt("achievements.roomsForChicken", 5);
private static final int ADDICT_GAMES = Config.asInt("achievements.gamesForAddict", 5);
private static final float DAREDEVIL_SECONDS = Config.asInt("achievements.daredevilSeconds", 10);
-
+
// Lives and scoring.
private static final int INITIAL_LIVES = Config.asInt("Player.lives", 3);
private static final int ROBOT_SCORE = Config.asInt("Robot.score", 50);
@@ -63,55 +66,55 @@ private Achievements(String summary, String text) {
private final ScoringEventNotifier scoringEventNotifier;
private final AchievementsNotifier achievementsNotifier;
private final EnumSet achieved;
-
+
/** The number of lives that the player has. */
private int lives;
-
+
/** The player's score. */
private int score;
-
+
/** The number of games that the player has played. */
private int numGames;
-
+
/** The number of robots that have been shot in this room. */
private int robotsShot;
-
+
/** The number of robots that have been destroyed in this room (including those that have been shot). */
private int robotsDestroyed;
-
+
/** The number of times the player has been hit in this room. */
private int playerHits;
/** The number of rooms entered in this game. */
private int gameRoomsEntered;
-
+
/** The number of rooms exited in this game. */
private int gameRoomsExited;
-
+
/** The number of robots that have been shot during this game. */
private int gameRobotsShot;
-
+
/** The number of robots that have been destroyed in this game (including those that have been shot). */
private int gameRobotsDestroyed;
-
+
/** The number of times the player has been hit in this game. */
private int gamePlayerHits;
-
+
/** The number of times the player has cleared a room during this game. */
private int gameCleanRooms;
-
+
/** The number of times the player has cleared a room in a row. */
private int cleanRooms;
-
+
/** The number of rooms that the player has got through without dying. */
private int gameRoomsWithoutDying;
-
+
/** The number of robots in the room. */
private int numRobots;
-
+
/** The number of times the player has fled from a room in a row. */
private int chickenRooms;
-
+
/** The number of times the player has fled from a room during this game. */
private int gameChickenRooms;
@@ -122,61 +125,60 @@ private Achievements(String summary, String text) {
private boolean isPlayerHit;
private float now;
-
- public StatusManager() {
+
+ public StatusManager () {
scoreNotifier = new ScoreNotifier();
achievementsNotifier = new AchievementsNotifier();
scoringEventNotifier = new ScoringEventNotifier();
achieved = EnumSet.noneOf(Achievements.class);
}
-
- public void update(float delta) {
+
+ public void update (float delta) {
now += delta;
if (daredevilTime != 0.0f && now >= daredevilTime) {
achievement(Achievements.DAREDEVIL);
daredevilTime = 0.0f;
}
}
-
- public void addScoreListener(ScoreListener listener) {
+
+ public void addScoreListener (ScoreListener listener) {
scoreNotifier.addListener(listener);
}
-
- public void addAchievementsListener(AchievementsListener listener) {
+
+ public void addAchievementsListener (AchievementsListener listener) {
achievementsNotifier.addListener(listener);
}
-
- public void addScoringEventListener(ScoringEventListener listener) {
+
+ public void addScoringEventListener (ScoringEventListener listener) {
scoringEventNotifier.addListener(listener);
}
- private void setLives(int lives) {
+ private void setLives (int lives) {
this.lives = lives;
scoreNotifier.onLivesChanged(lives);
}
-
- private void addLives(int inc) {
+
+ private void addLives (int inc) {
setLives(lives + inc);
}
- private void setScore(int newScore) {
+ private void setScore (int newScore) {
this.score = newScore;
scoreNotifier.onScoreChanged(newScore);
}
-
- private void addScore(int inc) {
+
+ private void addScore (int inc) {
int oldScore = score;
setScore(score + inc);
if (oldScore < EXTRA_LIFE_SCORE_1 && score >= EXTRA_LIFE_SCORE_1) {
addLives(1);
- }
- else if (oldScore < EXTRA_LIFE_SCORE_2 && score >= EXTRA_LIFE_SCORE_2) {
+ } else if (oldScore < EXTRA_LIFE_SCORE_2 && score >= EXTRA_LIFE_SCORE_2) {
addLives(1);
}
}
@Override
- public void onWorldReset() {
+ public void onWorldReset () {
numGames++;
achieved.clear();
if (numGames == ADDICT_GAMES) {
@@ -199,7 +201,7 @@ public void onWorldReset() {
}
@Override
- public void onEnteredRoom(float time, int robots) {
+ public void onEnteredRoom (float time, int robots) {
robotsShot = 0;
robotsDestroyed = 0;
playerHits = 0;
@@ -209,7 +211,7 @@ public void onEnteredRoom(float time, int robots) {
}
@Override
- public void onExitedRoom(float time, int robots) {
+ public void onExitedRoom (float time, int robots) {
gameRoomsExited++;
if (robots == 0) {
chickenRooms = 0;
@@ -217,12 +219,10 @@ public void onExitedRoom(float time, int robots) {
gameCleanRooms++;
if (cleanRooms == CLEAN_ROOMS) {
achievement(Achievements.PERFECTIONIST);
- }
- else if (robotsShot == 0) {
+ } else if (robotsShot == 0) {
achievement(Achievements.PACIFICIST);
}
- }
- else {
+ } else {
cleanRooms = 0;
chickenRooms++;
gameChickenRooms++;
@@ -235,24 +235,23 @@ else if (robotsShot == 0) {
if (gameRoomsWithoutDying == LUCKY_JIM_ROOMS) {
achievement(Achievements.LUCKY_JIM);
}
- }
- else {
+ } else {
gameRoomsWithoutDying = 0;
}
Gdx.app.log("Metrics", "FPS = " + Gdx.graphics.getFramesPerSecond());
}
-
+
@Override
- public void onRobotHit(Robot robot) {
+ public void onRobotHit (Robot robot) {
robotsShot++;
gameRobotsShot++;
if (robotsShot == numRobots) {
achievement(Achievements.PERFECT_SHOT);
}
}
-
+
@Override
- public void onRobotDestroyed(Robot robot) {
+ public void onRobotDestroyed (Robot robot) {
robotsDestroyed++;
gameRobotsDestroyed++;
int robotScore = ROBOT_SCORE;
@@ -265,9 +264,9 @@ public void onRobotDestroyed(Robot robot) {
achievement(Achievements.ROBOCIDE);
}
}
-
+
@Override
- public void onPlayerHit() {
+ public void onPlayerHit () {
daredevilTime = 0.0f;
playerHits++;
gamePlayerHits++;
@@ -275,16 +274,16 @@ public void onPlayerHit() {
}
@Override
- public void onCaptainActivated(float time) {
+ public void onCaptainActivated (float time) {
daredevilTime = now + DAREDEVIL_SECONDS;
}
-
+
@Override
- public void onPlayerFired() {
+ public void onPlayerFired () {
}
@Override
- public void onPlayerSpawned() {
+ public void onPlayerSpawned () {
if (isPlayerHit) {
addLives(-1);
isPlayerHit = false;
@@ -292,14 +291,14 @@ public void onPlayerSpawned() {
}
@Override
- public void onRobotFired(Robot robot) {
+ public void onRobotFired (Robot robot) {
}
@Override
- public void onShotDestroyed(BaseShot shot) {
+ public void onShotDestroyed (BaseShot shot) {
}
-
- private void achievement(Achievements achievement) {
+
+ private void achievement (Achievements achievement) {
if (!achieved.contains(achievement)) {
achieved.add(achievement);
achievementsNotifier.onAttained(achievement);
diff --git a/demos/very-angry-robots/very-angry-robots/src/com/badlydrawngames/veryangryrobots/StatusView.java b/demos/very-angry-robots/very-angry-robots/src/com/badlydrawngames/veryangryrobots/StatusView.java
index d5364e3f10e..79b9fb39450 100644
--- a/demos/very-angry-robots/very-angry-robots/src/com/badlydrawngames/veryangryrobots/StatusView.java
+++ b/demos/very-angry-robots/very-angry-robots/src/com/badlydrawngames/veryangryrobots/StatusView.java
@@ -13,9 +13,6 @@
package com.badlydrawngames.veryangryrobots;
-import static com.badlydrawngames.veryangryrobots.Assets.VIRTUAL_HEIGHT;
-import static com.badlydrawngames.veryangryrobots.Assets.VIRTUAL_WIDTH;
-
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.g2d.BitmapFont.HAlignment;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
@@ -25,15 +22,17 @@
import com.badlydrawngames.general.ScoreString;
import com.badlydrawngames.veryangryrobots.StatusManager.Achievements;
+import static com.badlydrawngames.veryangryrobots.Assets.*;
+
public class StatusView implements ScoreListener, AchievementsListener {
-
+
private static final float ACHIEVEMENT_DISPLAY_TIME = Config.asFloat("status.achievementDisplayTime", 10.0f);
private static final float ACHIEVEMENT_FLASH_CYCLE = Config.asFloat("status.achievementFlashCycleLength", 1.0f);
private static final float ACHIEVEMENT_FLASH_ON_PERCENT = Config.asFloat("status.achievementFlashOnPercent", 50.0f);
private static final float ACHIEVEMENT_FLASH_ON_TIME = ACHIEVEMENT_FLASH_CYCLE * ACHIEVEMENT_FLASH_ON_PERCENT / 100.0f;
private static final String RESUME_TEXT = "Tap to resume or press <> to quit";
-
+
private final World world;
private final OrthographicCamera statusCam;
private final SpriteBatch spriteBatch;
@@ -43,15 +42,15 @@ public class StatusView implements ScoreListener, AchievementsListener {
private float achievementTime;
private float now;
- public StatusView(World world) {
+ public StatusView (World world) {
this.world = world;
scoreString = new ScoreString();
statusCam = CameraHelper.createCamera2(ViewportMode.PIXEL_PERFECT, VIRTUAL_WIDTH, VIRTUAL_HEIGHT, Assets.pixelDensity);
spriteBatch = new SpriteBatch();
spriteBatch.setProjectionMatrix(statusCam.combined);
}
-
- public void render(float delta) {
+
+ public void render (float delta) {
now += delta;
spriteBatch.begin();
if (!world.isPaused()) {
@@ -59,27 +58,27 @@ public void render(float delta) {
drawScore();
drawAchievements();
drawLives();
- }
- else {
+ } else {
drawPaused();
}
spriteBatch.end();
}
- private void drawPauseButton() {
+ private void drawPauseButton () {
float w = Assets.pauseButton.getRegionWidth() / Assets.pixelDensity;
float h = Assets.pauseButton.getRegionHeight() / Assets.pixelDensity;
float y = VIRTUAL_HEIGHT - h;
float x = 0.0f;
spriteBatch.draw(Assets.pauseButton, x, y, w, h);
}
-
- private void drawScore() {
+
+ private void drawScore () {
Assets.scoreFont.setColor(1.0f, 1.0f, 1.0f, 1.0f);
- Assets.scoreFont.draw(spriteBatch, scoreString, 2, VIRTUAL_HEIGHT);;
+ Assets.scoreFont.draw(spriteBatch, scoreString, 2, VIRTUAL_HEIGHT);
+ ;
}
-
- private void drawAchievements() {
+
+ private void drawAchievements () {
if (achievement != null) {
float elapsed = now - achievementTime;
if (elapsed < ACHIEVEMENT_DISPLAY_TIME) {
@@ -90,25 +89,24 @@ private void drawAchievements() {
float y = VIRTUAL_HEIGHT - 1 + Assets.textFont.getCapHeight() / 2;
Assets.textFont.drawWrapped(spriteBatch, summary, x, y, w, HAlignment.LEFT);
}
- }
- else {
+ } else {
achievement = null;
}
}
}
-
- private void drawLives() {
+
+ private void drawLives () {
float h = Assets.playerWalkingRight1.getRegionHeight() / Assets.pixelDensity;
float y = VIRTUAL_HEIGHT - h;
float w = Assets.playerWalkingRight1.getRegionWidth() / Assets.pixelDensity;
float x = VIRTUAL_WIDTH - w;
- for (int i = 0; i < lives - 1; i++) {
+ for (int i = 0; i < lives - 1; i++) {
spriteBatch.draw(Assets.playerWalkingRight1, x, y, w, h);
x -= w;
}
}
-
- private void drawPaused() {
+
+ private void drawPaused () {
if (world.getPausedTime() % 1.0f < 0.5f) {
float y = VIRTUAL_HEIGHT - 1 + Assets.scoreFont.getCapHeight() / 2;
Assets.textFont.setColor(1.0f, 1.0f, 1.0f, 1.0f);
@@ -117,17 +115,17 @@ private void drawPaused() {
}
@Override
- public void onScoreChanged(int score) {
+ public void onScoreChanged (int score) {
scoreString.setScore(score);
}
@Override
- public void onLivesChanged(int lives) {
+ public void onLivesChanged (int lives) {
this.lives = lives;
}
@Override
- public void onAttained(Achievements achievement) {
+ public void onAttained (Achievements achievement) {
this.achievement = achievement;
this.achievementTime = now;
}
diff --git a/demos/very-angry-robots/very-angry-robots/src/com/badlydrawngames/veryangryrobots/VeryAngryRobotsGame.java b/demos/very-angry-robots/very-angry-robots/src/com/badlydrawngames/veryangryrobots/VeryAngryRobotsGame.java
index 4e01ace7835..f0f3d16da32 100644
--- a/demos/very-angry-robots/very-angry-robots/src/com/badlydrawngames/veryangryrobots/VeryAngryRobotsGame.java
+++ b/demos/very-angry-robots/very-angry-robots/src/com/badlydrawngames/veryangryrobots/VeryAngryRobotsGame.java
@@ -25,51 +25,49 @@ public class VeryAngryRobotsGame extends Game implements AchievementsListener {
IShowScores scoreDisplayer;
ISubmitScores scoreSubmitter;
AchievementsListener achievementsListener;
-
- /**
- * Creates all the screens that the game will need, then switches to the main menu.
- */
+
+ /** Creates all the screens that the game will need, then switches to the main menu. */
@Override
- public void create() {
+ public void create () {
Assets.load();
mainMenuScreen = new MainMenuScreen(this);
playingScreen = new WorldPresenter(this);
scoresScreen = new ScoresScreen(this);
setScreen(mainMenuScreen);
}
-
- public void submitScore(int score) {
+
+ public void submitScore (int score) {
if (scoreSubmitter != null) {
scoreSubmitter.submitScore(score);
}
}
-
- public void showScores() {
+
+ public void showScores () {
if (scoreDisplayer != null) {
scoreDisplayer.showScores();
}
}
-
+
@Override
- public void onAttained(Achievements achievement) {
+ public void onAttained (Achievements achievement) {
if (achievementsListener != null) {
achievementsListener.onAttained(achievement);
}
}
-
- public void setScoreDisplayer(IShowScores scoreDisplayer) {
+
+ public void setScoreDisplayer (IShowScores scoreDisplayer) {
this.scoreDisplayer = scoreDisplayer;
}
- public void setScoreSubmitter(ISubmitScores scoreSubmitter) {
+ public void setScoreSubmitter (ISubmitScores scoreSubmitter) {
this.scoreSubmitter = scoreSubmitter;
}
- public void setAchievementsListener(AchievementsListener listener) {
+ public void setAchievementsListener (AchievementsListener listener) {
this.achievementsListener = listener;
}
- public boolean canShowScores() {
+ public boolean canShowScores () {
return scoreDisplayer != null;
}
}
diff --git a/demos/very-angry-robots/very-angry-robots/src/com/badlydrawngames/veryangryrobots/World.java b/demos/very-angry-robots/very-angry-robots/src/com/badlydrawngames/veryangryrobots/World.java
index 700a3cc4e97..270b1e34791 100644
--- a/demos/very-angry-robots/very-angry-robots/src/com/badlydrawngames/veryangryrobots/World.java
+++ b/demos/very-angry-robots/very-angry-robots/src/com/badlydrawngames/veryangryrobots/World.java
@@ -13,9 +13,6 @@
package com.badlydrawngames.veryangryrobots;
-import static com.badlogic.gdx.math.MathUtils.random;
-import static com.badlydrawngames.general.MathUtils.max;
-
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.math.Rectangle;
import com.badlogic.gdx.math.Vector2;
@@ -36,31 +33,25 @@
import com.badlydrawngames.veryangryrobots.mobiles.Robot;
import com.badlydrawngames.veryangryrobots.mobiles.RobotShot;
-/**
- * The World
is the representation of the game world of Very Angry Robots . It knows nothing about
- * how it will be displayed, neither does it know about how the player is controlled, particle effects, sounds, nor
- * anything else. It purely knows about the {@link Player}, {@link Robot}s and the walls of the room that the player
- * is in.
+import static com.badlogic.gdx.math.MathUtils.*;
+import static com.badlydrawngames.general.MathUtils.*;
+
+/** The World
is the representation of the game world of Very Angry Robots . It knows nothing about how it will
+ * be displayed, neither does it know about how the player is controlled, particle effects, sounds, nor anything else. It purely
+ * knows about the {@link Player}, {@link Robot}s and the walls of the room that the player is in.
*
- * @author Rod
- *
- */
+ * @author Rod */
public class World {
- /**
- * The FireCommand
interface is how the {@link World} is told that a {@link GameObject} wants to
- * fire.
- */
+ /** The FireCommand
interface is how the {@link World} is told that a {@link GameObject} wants to fire. */
public static interface FireCommand {
- /**
- * Tells the {@link World} that a {@link GameObject} wants to fire. Note that dx
and
- * dy
must be normalised. The World does not have to fire just because it is asked to.
+ /** Tells the {@link World} that a {@link GameObject} wants to fire. Note that dx
and dy
must be
+ * normalised. The World does not have to fire just because it is asked to.
*
* @param firer the {@link GameObject} that wants to fire.
* @param dx the horizontal component of the bullet's direction.
- * @param dy the vertical component of the bullet's direction.
- */
- void fire(GameObject firer, float dx, float dy);
+ * @param dy the vertical component of the bullet's direction. */
+ void fire (GameObject firer, float dx, float dy);
}
// Maze proportions.
@@ -87,13 +78,13 @@ public static interface FireCommand {
public static final int ENTERED_ROOM = 2;
public static final int PLAYING = 3;
public static final int PLAYER_DEAD = 4;
-
+
private final Pool shotPool;
private final Pool