Added Override annotations, finals, some cleanup and better null checks (#1271)

* Added Override annotations, finals, some cleanup and better null checks

* More general null check

* Follow naming conventions
fix-openal-soft-deadlink
Toni Helenius 5 years ago committed by GitHub
parent 2023440acf
commit 427ae0a28b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 8
      jme3-niftygui/src/main/java/com/jme3/cinematic/events/GuiEvent.java
  2. 6
      jme3-niftygui/src/main/java/com/jme3/cinematic/events/GuiTrack.java
  3. 22
      jme3-niftygui/src/main/java/com/jme3/niftygui/InputSystemJme.java
  4. 103
      jme3-niftygui/src/main/java/com/jme3/niftygui/JmeBatchRenderBackend.java
  5. 19
      jme3-niftygui/src/main/java/com/jme3/niftygui/NiftyJmeDisplay.java
  6. 55
      jme3-niftygui/src/main/java/com/jme3/niftygui/RenderDeviceJme.java
  7. 14
      jme3-niftygui/src/main/java/com/jme3/niftygui/RenderFontJme.java
  8. 3
      jme3-niftygui/src/main/java/com/jme3/niftygui/RenderImageJme.java
  9. 4
      jme3-niftygui/src/main/java/com/jme3/niftygui/SoundDeviceJme.java
  10. 8
      jme3-niftygui/src/main/java/com/jme3/niftygui/SoundHandleJme.java

@ -37,6 +37,7 @@ import com.jme3.export.JmeExporter;
import com.jme3.export.JmeImporter; import com.jme3.export.JmeImporter;
import com.jme3.export.OutputCapsule; import com.jme3.export.OutputCapsule;
import de.lessvoid.nifty.Nifty; import de.lessvoid.nifty.Nifty;
import de.lessvoid.nifty.screen.Screen;
import java.io.IOException; import java.io.IOException;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
@ -51,7 +52,7 @@ public class GuiEvent extends AbstractCinematicEvent {
/** /**
* message logger for this class * message logger for this class
*/ */
static final Logger log = Logger.getLogger(GuiEvent.class.getName()); private static final Logger log = Logger.getLogger(GuiEvent.class.getName());
/** /**
* name of the associated Nifty screen(not null) * name of the associated Nifty screen(not null)
@ -135,8 +136,9 @@ public class GuiEvent extends AbstractCinematicEvent {
*/ */
@Override @Override
public void onStop() { public void onStop() {
if (nifty.getCurrentScreen() != null) { Screen currentScreen = nifty.getCurrentScreen();
nifty.getCurrentScreen().endScreen(null); if (currentScreen != null) {
currentScreen.endScreen(null);
} }
} }

@ -37,6 +37,7 @@ import com.jme3.export.JmeExporter;
import com.jme3.export.JmeImporter; import com.jme3.export.JmeImporter;
import com.jme3.export.OutputCapsule; import com.jme3.export.OutputCapsule;
import de.lessvoid.nifty.Nifty; import de.lessvoid.nifty.Nifty;
import de.lessvoid.nifty.screen.Screen;
import java.io.IOException; import java.io.IOException;
/** /**
@ -84,8 +85,9 @@ public class GuiTrack extends AbstractCinematicEvent {
@Override @Override
public void onStop() { public void onStop() {
if (nifty.getCurrentScreen() != null) { Screen currentScreen = nifty.getCurrentScreen();
nifty.getCurrentScreen().endScreen(null); if (currentScreen != null) {
currentScreen.endScreen(null);
} }
} }

@ -46,14 +46,15 @@ import de.lessvoid.nifty.input.keyboard.KeyboardInputEvent;
import de.lessvoid.nifty.spi.input.InputSystem; import de.lessvoid.nifty.spi.input.InputSystem;
import de.lessvoid.nifty.tools.resourceloader.NiftyResourceLoader; import de.lessvoid.nifty.tools.resourceloader.NiftyResourceLoader;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
public class InputSystemJme implements InputSystem, RawInputListener { public class InputSystemJme implements InputSystem, RawInputListener {
private final ArrayList<InputEvent> inputQueue = new ArrayList<InputEvent>(); private final List<InputEvent> inputQueue = new ArrayList<>();
private InputManager inputManager; private final InputManager inputManager;
private boolean[] niftyOwnsDragging = new boolean[3]; private final boolean[] niftyOwnsDragging = new boolean[3];
private int inputPointerId = -1; private int inputPointerId = -1;
private int x, y; private int x, y;
private int height; private int height;
@ -65,6 +66,7 @@ public class InputSystemJme implements InputSystem, RawInputListener {
this.inputManager = inputManager; this.inputManager = inputManager;
} }
@Override
public void setResourceLoader(NiftyResourceLoader niftyResourceLoader) { public void setResourceLoader(NiftyResourceLoader niftyResourceLoader) {
} }
@ -101,15 +103,18 @@ public class InputSystemJme implements InputSystem, RawInputListener {
this.height = height; this.height = height;
} }
@Override
public void setMousePosition(int x, int y) { public void setMousePosition(int x, int y) {
// TODO: When does nifty use this? // TODO: When does nifty use this?
} }
@Override
public void beginInput() { public void beginInput() {
} }
@Override
public void endInput() { public void endInput() {
boolean result = nifty.update(); nifty.update();
} }
private void handleMouseEvent(int button, boolean value, NiftyInputConsumer nic, InputEvent evt) { private void handleMouseEvent(int button, boolean value, NiftyInputConsumer nic, InputEvent evt) {
@ -251,6 +256,7 @@ public class InputSystemJme implements InputSystem, RawInputListener {
} }
} }
@Override
public void onMouseMotionEvent(MouseMotionEvent evt) { public void onMouseMotionEvent(MouseMotionEvent evt) {
// Only forward the event if there's actual motion involved. // Only forward the event if there's actual motion involved.
if (inputManager.isCursorVisible() && (evt.getDX() != 0 if (inputManager.isCursorVisible() && (evt.getDX() != 0
@ -260,6 +266,7 @@ public class InputSystemJme implements InputSystem, RawInputListener {
} }
} }
@Override
public void onMouseButtonEvent(MouseButtonEvent evt) { public void onMouseButtonEvent(MouseButtonEvent evt) {
if (evt.getButtonIndex() >= 0 && evt.getButtonIndex() <= 2) { if (evt.getButtonIndex() >= 0 && evt.getButtonIndex() <= 2) {
if (evt.isReleased() || inputManager.isCursorVisible()) { if (evt.isReleased() || inputManager.isCursorVisible()) {
@ -270,20 +277,25 @@ public class InputSystemJme implements InputSystem, RawInputListener {
} }
} }
@Override
public void onJoyAxisEvent(JoyAxisEvent evt) { public void onJoyAxisEvent(JoyAxisEvent evt) {
} }
@Override
public void onJoyButtonEvent(JoyButtonEvent evt) { public void onJoyButtonEvent(JoyButtonEvent evt) {
} }
@Override
public void onKeyEvent(KeyInputEvent evt) { public void onKeyEvent(KeyInputEvent evt) {
inputQueue.add(evt); inputQueue.add(evt);
} }
@Override
public void onTouchEvent(TouchEvent evt) { public void onTouchEvent(TouchEvent evt) {
inputQueue.add(evt); inputQueue.add(evt);
} }
@Override
public void forwardEvents(NiftyInputConsumer nic) { public void forwardEvents(NiftyInputConsumer nic) {
int queueSize = inputQueue.size(); int queueSize = inputQueue.size();
@ -317,6 +329,8 @@ public class InputSystemJme implements InputSystem, RawInputListener {
} }
softTextDialogInput.requestDialog(SoftTextDialogInput.TEXT_ENTRY_DIALOG, "Enter Text", initialValue, new SoftTextDialogInputListener() { softTextDialogInput.requestDialog(SoftTextDialogInput.TEXT_ENTRY_DIALOG, "Enter Text", initialValue, new SoftTextDialogInputListener() {
@Override
public void onSoftText(int action, String text) { public void onSoftText(int action, String text) {
if (action == SoftTextDialogInputListener.COMPLETE) { if (action == SoftTextDialogInputListener.COMPLETE) {
textField.setText(text); textField.setText(text);

@ -31,15 +31,6 @@
*/ */
package com.jme3.niftygui; package com.jme3.niftygui;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.FloatBuffer;
import java.nio.ShortBuffer;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import com.jme3.asset.TextureKey; import com.jme3.asset.TextureKey;
import com.jme3.material.Material; import com.jme3.material.Material;
import com.jme3.material.RenderState; import com.jme3.material.RenderState;
@ -54,41 +45,50 @@ import com.jme3.scene.VertexBuffer;
import com.jme3.scene.VertexBuffer.Type; import com.jme3.scene.VertexBuffer.Type;
import com.jme3.scene.VertexBuffer.Usage; import com.jme3.scene.VertexBuffer.Usage;
import com.jme3.texture.Image.Format; import com.jme3.texture.Image.Format;
import com.jme3.texture.image.ImageRaster;
import com.jme3.texture.Texture.MagFilter; import com.jme3.texture.Texture.MagFilter;
import com.jme3.texture.Texture.MinFilter; import com.jme3.texture.Texture.MinFilter;
import com.jme3.texture.Texture2D; import com.jme3.texture.Texture2D;
import com.jme3.texture.image.ColorSpace; import com.jme3.texture.image.ColorSpace;
import com.jme3.texture.image.ImageRaster;
import com.jme3.util.BufferUtils; import com.jme3.util.BufferUtils;
import de.lessvoid.nifty.render.batch.spi.BatchRenderBackend;
import de.lessvoid.nifty.render.BlendMode; import de.lessvoid.nifty.render.BlendMode;
import de.lessvoid.nifty.render.batch.spi.BatchRenderBackend;
import de.lessvoid.nifty.spi.render.MouseCursor; import de.lessvoid.nifty.spi.render.MouseCursor;
import de.lessvoid.nifty.tools.Color; import de.lessvoid.nifty.tools.Color;
import de.lessvoid.nifty.tools.Factory; import de.lessvoid.nifty.tools.Factory;
import de.lessvoid.nifty.tools.ObjectPool; import de.lessvoid.nifty.tools.ObjectPool;
import de.lessvoid.nifty.tools.resourceloader.NiftyResourceLoader; import de.lessvoid.nifty.tools.resourceloader.NiftyResourceLoader;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.FloatBuffer;
import java.nio.ShortBuffer;
import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
/** /**
* Nifty GUI BatchRenderBackend Implementation for jMonkeyEngine. * Nifty GUI BatchRenderBackend Implementation for jMonkeyEngine.
*
* @author void * @author void
*/ */
public class JmeBatchRenderBackend implements BatchRenderBackend { public class JmeBatchRenderBackend implements BatchRenderBackend {
private static Logger log = Logger.getLogger(JmeBatchRenderBackend.class.getName());
private static final Logger log = Logger.getLogger(JmeBatchRenderBackend.class.getName());
private final ObjectPool<Batch> batchPool; private final ObjectPool<Batch> batchPool;
private final List<Batch> batches = new ArrayList<Batch>(); private final List<Batch> batches = new ArrayList<>();
// a modify texture call needs a jme Renderer to execute. if we're called to modify a texture but don't // a modify texture call needs a jme Renderer to execute. if we're called to modify a texture but don't
// have a Renderer yet - since it was not initialized on the jme side - we'll cache the modify texture calls // have a Renderer yet - since it was not initialized on the jme side - we'll cache the modify texture calls
// in here and execute them later (at the next beginFrame() call). // in here and execute them later (at the next beginFrame() call).
private final List<ModifyTexture> modifyTextureCalls = new ArrayList<ModifyTexture>(); private final List<ModifyTexture> modifyTextureCalls = new ArrayList<>();
private RenderManager renderManager; private RenderManager renderManager;
private NiftyJmeDisplay display; private NiftyJmeDisplay display;
private Map<Integer, Texture2D> textures = new HashMap<Integer, Texture2D>(); private Map<Integer, Texture2D> textures = new HashMap<>();
private int textureAtlasId = 1; private int textureAtlasId = 1;
private Batch currentBatch; private Batch currentBatch;
private Matrix4f tempMat = new Matrix4f(); private Matrix4f tempMat = new Matrix4f();
@ -102,7 +102,8 @@ public class JmeBatchRenderBackend implements BatchRenderBackend {
public JmeBatchRenderBackend(final NiftyJmeDisplay display) { public JmeBatchRenderBackend(final NiftyJmeDisplay display) {
this.display = display; this.display = display;
this.batchPool = new ObjectPool<Batch>(new Factory<Batch>() { this.batchPool = new ObjectPool<>(new Factory<Batch>() {
@Override @Override
public Batch createNew() { public Batch createNew() {
return new Batch(); return new Batch();
@ -157,7 +158,6 @@ public class JmeBatchRenderBackend implements BatchRenderBackend {
} }
// TODO: Cursor support // TODO: Cursor support
@Override @Override
public MouseCursor createMouseCursor(final String filename, final int hotspotX, final int hotspotY) throws IOException { public MouseCursor createMouseCursor(final String filename, final int hotspotX, final int hotspotY) throws IOException {
return new MouseCursor() { return new MouseCursor() {
@ -337,9 +337,14 @@ public class JmeBatchRenderBackend implements BatchRenderBackend {
} }
/** /**
* Whether or not to render textures with high quality settings. Usually, setting to true will result in slower * Whether or not to render textures with high quality settings. Usually,
* performance, but nicer looking textures, and vice versa. How high quality textures are rendered versus low quality * setting to true will result in slower performance, but nicer looking
* textures will vary depending on the {@link de.lessvoid.nifty.render.batch.spi.BatchRenderBackend} implementation. * textures, and vice versa. How high quality textures are rendered versus
* low quality textures will vary depending on the
* {@link de.lessvoid.nifty.render.batch.spi.BatchRenderBackend}
* implementation
*
* @param shouldUseHighQualityTextures
*/ */
@Override @Override
public void useHighQualityTextures(final boolean shouldUseHighQualityTextures) { public void useHighQualityTextures(final boolean shouldUseHighQualityTextures) {
@ -349,9 +354,12 @@ public class JmeBatchRenderBackend implements BatchRenderBackend {
} }
/** /**
* Whether or not to overwrite previously used atlas space with blank data. Setting to true will result in slower * Whether or not to overwrite previously used atlas space with blank data.
* performance, but may be useful in debugging when visually inspecting the atlas, since there will not be portions * Setting to true will result in slower performance, but may be useful in
* of old images visible in currently unused atlas space. * debugging when visually inspecting the atlas, since there will not be
* portions of old images visible in currently unused atlas space.
*
* @param shouldFill
*/ */
@Override @Override
public void fillRemovedImagesInAtlas(final boolean shouldFill) { public void fillRemovedImagesInAtlas(final boolean shouldFill) {
@ -359,7 +367,6 @@ public class JmeBatchRenderBackend implements BatchRenderBackend {
} }
// internal implementations // internal implementations
private Texture2D createAtlasTextureInternal(final int width, final int height) throws Exception { private Texture2D createAtlasTextureInternal(final int width, final int height) throws Exception {
ByteBuffer initialData = BufferUtils.createByteBuffer(width * height * 4); ByteBuffer initialData = BufferUtils.createByteBuffer(width * height * 4);
for (int i = 0; i < width * height * 4; i++) { for (int i = 0; i < width * height * 4; i++) {
@ -400,12 +407,14 @@ public class JmeBatchRenderBackend implements BatchRenderBackend {
} }
/** /**
* Simple BatchRenderBackend.Image implementation that will transport the dimensions of an image as well as the * Simple BatchRenderBackend.Image implementation that will transport the
* actual bytes from the loadImage() to the addImageToTexture() method. * dimensions of an image as well as the actual bytes from the loadImage()
* to the addImageToTexture() method.
* *
* @author void * @author void
*/ */
private static class ImageImpl implements BatchRenderBackend.Image { private static class ImageImpl implements BatchRenderBackend.Image {
private final com.jme3.texture.Image image; private final com.jme3.texture.Image image;
public ImageImpl(final com.jme3.texture.Image image) { public ImageImpl(final com.jme3.texture.Image image) {
@ -432,14 +441,17 @@ public class JmeBatchRenderBackend implements BatchRenderBackend {
} }
/** /**
* Used to delay ModifyTexture calls in case we don't have a JME3 Renderer yet. * Used to delay ModifyTexture calls in case we don't have a JME3 Renderer
* yet.
*
* @author void * @author void
*/ */
private static class ModifyTexture { private static class ModifyTexture {
private Texture2D atlas;
private com.jme3.texture.Image image; private final Texture2D atlas;
private int x; private final com.jme3.texture.Image image;
private int y; private final int x;
private final int y;
private ModifyTexture(final Texture2D atlas, final com.jme3.texture.Image image, final int x, final int y) { private ModifyTexture(final Texture2D atlas, final com.jme3.texture.Image image, final int x, final int y) {
this.atlas = atlas; this.atlas = atlas;
@ -454,9 +466,10 @@ public class JmeBatchRenderBackend implements BatchRenderBackend {
} }
/** /**
* This class helps us to manage the batch data. We'll keep a bunch of instances of this class around that will be * This class helps us to manage the batch data. We'll keep a bunch of
* reused when needed. Each Batch instance provides room for a certain amount of vertices and we'll use a new Batch * instances of this class around that will be reused when needed. Each
* when we exceed this amount of data. * Batch instance provides room for a certain amount of vertices and we'll
* use a new Batch when we exceed this amount of data.
* *
* @author void * @author void
*/ */
@ -470,6 +483,7 @@ public class JmeBatchRenderBackend implements BatchRenderBackend {
// and an additional buffer for indexes // and an additional buffer for indexes
// //
// there is a fixed amount of primitives per batch. if we run out of vertices we'll start a new batch. // there is a fixed amount of primitives per batch. if we run out of vertices we'll start a new batch.
private final static int BATCH_MAX_QUADS = 2000; private final static int BATCH_MAX_QUADS = 2000;
private final static int BATCH_MAX_VERTICES = BATCH_MAX_QUADS * 4; private final static int BATCH_MAX_VERTICES = BATCH_MAX_QUADS * 4;
@ -483,10 +497,10 @@ public class JmeBatchRenderBackend implements BatchRenderBackend {
private final Geometry meshGeometry = new Geometry("nifty-quad", mesh); private final Geometry meshGeometry = new Geometry("nifty-quad", mesh);
private final RenderState renderState = new RenderState(); private final RenderState renderState = new RenderState();
private FloatBuffer vertexPosBuffer; private final FloatBuffer vertexPosBuffer;
private FloatBuffer vertexTexCoordBuffer; private final FloatBuffer vertexTexCoordBuffer;
private FloatBuffer vertexColorBuffer; private final FloatBuffer vertexColorBuffer;
private ShortBuffer indexBufferBuffer; private final ShortBuffer indexBufferBuffer;
// number of quads already added to this batch. // number of quads already added to this batch.
private int quadCount; private int quadCount;
@ -495,7 +509,7 @@ public class JmeBatchRenderBackend implements BatchRenderBackend {
// current blend mode // current blend mode
private BlendMode blendMode = BlendMode.BLEND; private BlendMode blendMode = BlendMode.BLEND;
private Texture2D texture; private Texture2D texture;
private Material material; private final Material material;
public Batch() { public Batch() {
// setup mesh // setup mesh
@ -566,14 +580,17 @@ public class JmeBatchRenderBackend implements BatchRenderBackend {
private RenderState.BlendMode convertBlend(final BlendMode blendMode) { private RenderState.BlendMode convertBlend(final BlendMode blendMode) {
if (blendMode == null) { if (blendMode == null) {
return RenderState.BlendMode.Off; return RenderState.BlendMode.Off;
} else if (blendMode == BlendMode.BLEND) { } else {
switch (blendMode) {
case BLEND:
return RenderState.BlendMode.Alpha; return RenderState.BlendMode.Alpha;
} else if (blendMode == BlendMode.MULIPLY) { case MULIPLY:
return RenderState.BlendMode.Alpha; return RenderState.BlendMode.Alpha;
} else { default:
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();
} }
} }
}
public boolean canAddQuad() { public boolean canAddQuad() {
return (quadCount + 1) < BATCH_MAX_QUADS; return (quadCount + 1) < BATCH_MAX_QUADS;

@ -31,9 +31,6 @@
*/ */
package com.jme3.niftygui; package com.jme3.niftygui;
import java.io.InputStream;
import java.net.URL;
import com.jme3.asset.AssetInfo; import com.jme3.asset.AssetInfo;
import com.jme3.asset.AssetKey; import com.jme3.asset.AssetKey;
import com.jme3.asset.AssetManager; import com.jme3.asset.AssetManager;
@ -48,12 +45,13 @@ import com.jme3.renderer.Renderer;
import com.jme3.renderer.ViewPort; import com.jme3.renderer.ViewPort;
import com.jme3.renderer.queue.RenderQueue; import com.jme3.renderer.queue.RenderQueue;
import com.jme3.texture.FrameBuffer; import com.jme3.texture.FrameBuffer;
import de.lessvoid.nifty.Nifty; import de.lessvoid.nifty.Nifty;
import de.lessvoid.nifty.render.batch.BatchRenderConfiguration; import de.lessvoid.nifty.render.batch.BatchRenderConfiguration;
import de.lessvoid.nifty.render.batch.BatchRenderDevice; import de.lessvoid.nifty.render.batch.BatchRenderDevice;
import de.lessvoid.nifty.spi.time.impl.AccurateTimeProvider; import de.lessvoid.nifty.spi.time.impl.AccurateTimeProvider;
import de.lessvoid.nifty.tools.resourceloader.ResourceLocation; import de.lessvoid.nifty.tools.resourceloader.ResourceLocation;
import java.io.InputStream;
import java.net.URL;
public class NiftyJmeDisplay implements SceneProcessor { public class NiftyJmeDisplay implements SceneProcessor {
@ -76,8 +74,9 @@ public class NiftyJmeDisplay implements SceneProcessor {
protected class ResourceLocationJme implements ResourceLocation { protected class ResourceLocationJme implements ResourceLocation {
@Override
public InputStream getResourceAsStream(String path) { public InputStream getResourceAsStream(String path) {
AssetKey<Object> key = new AssetKey<Object>(path); AssetKey<Object> key = new AssetKey<>(path);
AssetInfo info = assetManager.locateAsset(key); AssetInfo info = assetManager.locateAsset(key);
if (info != null) { if (info != null) {
return info.openStream(); return info.openStream();
@ -86,6 +85,7 @@ public class NiftyJmeDisplay implements SceneProcessor {
} }
} }
@Override
public URL getResource(String path) { public URL getResource(String path) {
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();
} }
@ -112,6 +112,7 @@ public class NiftyJmeDisplay implements SceneProcessor {
* @param inputManager jME InputManager * @param inputManager jME InputManager
* @param audioRenderer jME AudioRenderer * @param audioRenderer jME AudioRenderer
* @param viewport Viewport to use * @param viewport Viewport to use
* @return new NiftyJmeDisplay instance
*/ */
public static NiftyJmeDisplay newNiftyJmeDisplay( public static NiftyJmeDisplay newNiftyJmeDisplay(
final AssetManager assetManager, final AssetManager assetManager,
@ -142,6 +143,7 @@ public class NiftyJmeDisplay implements SceneProcessor {
* you can use to further configure batch rendering. If unsure you * you can use to further configure batch rendering. If unsure you
* can simply use new BatchRenderConfiguration() in here for the * can simply use new BatchRenderConfiguration() in here for the
* default configuration which should give you good default values. * default configuration which should give you good default values.
* @return new NiftyJmeDisplay instance
*/ */
public static NiftyJmeDisplay newNiftyJmeDisplay( public static NiftyJmeDisplay newNiftyJmeDisplay(
final AssetManager assetManager, final AssetManager assetManager,
@ -280,6 +282,7 @@ public class NiftyJmeDisplay implements SceneProcessor {
this.inputSys = new InputSystemJme(inputManager); this.inputSys = new InputSystemJme(inputManager);
} }
@Override
public void initialize(RenderManager rm, ViewPort vp) { public void initialize(RenderManager rm, ViewPort vp) {
this.renderManager = rm; this.renderManager = rm;
if (renderDev != null) { if (renderDev != null) {
@ -328,6 +331,7 @@ public class NiftyJmeDisplay implements SceneProcessor {
return renderer; return renderer;
} }
@Override
public void reshape(ViewPort vp, int w, int h) { public void reshape(ViewPort vp, int w, int h) {
this.w = w; this.w = w;
this.h = h; this.h = h;
@ -335,13 +339,16 @@ public class NiftyJmeDisplay implements SceneProcessor {
nifty.resolutionChanged(); nifty.resolutionChanged();
} }
@Override
public boolean isInitialized() { public boolean isInitialized() {
return inited; return inited;
} }
@Override
public void preFrame(float tpf) { public void preFrame(float tpf) {
} }
@Override
public void postQueue(RenderQueue rq) { public void postQueue(RenderQueue rq) {
// render nifty before anything else // render nifty before anything else
renderManager.setCamera(vp.getCamera(), true); renderManager.setCamera(vp.getCamera(), true);
@ -350,9 +357,11 @@ public class NiftyJmeDisplay implements SceneProcessor {
renderManager.setCamera(vp.getCamera(), false); renderManager.setCamera(vp.getCamera(), false);
} }
@Override
public void postFrame(FrameBuffer out) { public void postFrame(FrameBuffer out) {
} }
@Override
public void cleanup() { public void cleanup() {
inited = false; inited = false;
inputSys.reset(); inputSys.reset();

@ -57,27 +57,28 @@ import de.lessvoid.nifty.tools.resourceloader.NiftyResourceLoader;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.nio.FloatBuffer; import java.nio.FloatBuffer;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map;
public class RenderDeviceJme implements RenderDevice { public class RenderDeviceJme implements RenderDevice {
private NiftyJmeDisplay display; private final NiftyJmeDisplay display;
private RenderManager rm; private RenderManager rm;
private Renderer r; private Renderer r;
private HashMap<CachedTextKey, BitmapText> textCacheLastFrame = new HashMap<CachedTextKey, BitmapText>(); private Map<CachedTextKey, BitmapText> textCacheLastFrame = new HashMap<>();
private HashMap<CachedTextKey, BitmapText> textCacheCurrentFrame = new HashMap<CachedTextKey, BitmapText>(); private Map<CachedTextKey, BitmapText> textCacheCurrentFrame = new HashMap<>();
private final Quad quad = new Quad(1, -1, true); private final Quad quad = new Quad(1, -1, true);
private final Geometry quadGeom = new Geometry("nifty-quad", quad); private final Geometry quadGeom = new Geometry("nifty-quad", quad);
private boolean clipWasSet = false; private boolean clipWasSet = false;
private VertexBuffer quadDefaultTC = quad.getBuffer(Type.TexCoord); private final VertexBuffer quadDefaultTC = quad.getBuffer(Type.TexCoord);
private VertexBuffer quadModTC = quadDefaultTC.clone(); private final VertexBuffer quadModTC = quadDefaultTC.clone();
private VertexBuffer quadColor; private final VertexBuffer quadColor;
private Matrix4f tempMat = new Matrix4f(); private final Matrix4f tempMat = new Matrix4f();
private ColorRGBA tempColor = new ColorRGBA(); private final ColorRGBA tempColor = new ColorRGBA();
private RenderState renderState = new RenderState(); private final RenderState renderState = new RenderState();
private Material colorMaterial; private final Material colorMaterial;
private Material textureColorMaterial; private final Material textureColorMaterial;
private Material vertexColorMaterial; private final Material vertexColorMaterial;
private static class CachedTextKey { private static class CachedTextKey {
@ -138,6 +139,7 @@ public class RenderDeviceJme implements RenderDevice {
renderState.setDepthWrite(false); renderState.setDepthWrite(false);
} }
@Override
public void setResourceLoader(NiftyResourceLoader niftyResourceLoader) { public void setResourceLoader(NiftyResourceLoader niftyResourceLoader) {
} }
@ -147,8 +149,11 @@ public class RenderDeviceJme implements RenderDevice {
} }
// TODO: Cursor support // TODO: Cursor support
@Override
public MouseCursor createMouseCursor(String str, int x, int y) { public MouseCursor createMouseCursor(String str, int x, int y) {
return new MouseCursor() { return new MouseCursor() {
@Override
public void dispose() { public void dispose() {
} }
@ -162,43 +167,53 @@ public class RenderDeviceJme implements RenderDevice {
}; };
} }
@Override
public void enableMouseCursor(MouseCursor cursor) { public void enableMouseCursor(MouseCursor cursor) {
} }
@Override
public void disableMouseCursor() { public void disableMouseCursor() {
} }
@Override
public RenderImage createImage(String filename, boolean linear) { public RenderImage createImage(String filename, boolean linear) {
//System.out.println("createImage(" + filename + ", " + linear + ")"); //System.out.println("createImage(" + filename + ", " + linear + ")");
return new RenderImageJme(filename, linear, display); return new RenderImageJme(filename, linear, display);
} }
@Override
public RenderFont createFont(String filename) { public RenderFont createFont(String filename) {
return new RenderFontJme(filename, display); return new RenderFontJme(filename, display);
} }
@Override
public void beginFrame() { public void beginFrame() {
} }
@Override
public void endFrame() { public void endFrame() {
HashMap<CachedTextKey, BitmapText> temp = textCacheLastFrame; Map<CachedTextKey, BitmapText> temp = textCacheLastFrame;
textCacheLastFrame = textCacheCurrentFrame; textCacheLastFrame = textCacheCurrentFrame;
textCacheCurrentFrame = temp; textCacheCurrentFrame = temp;
textCacheCurrentFrame.clear(); textCacheCurrentFrame.clear();
rm.setForcedRenderState(null); rm.setForcedRenderState(null);
} }
@Override
public int getWidth() { public int getWidth() {
return display.getWidth(); return display.getWidth();
} }
@Override
public int getHeight() { public int getHeight() {
return display.getHeight(); return display.getHeight();
} }
@Override
public void clear() { public void clear() {
} }
@Override
public void setBlendMode(BlendMode blendMode) { public void setBlendMode(BlendMode blendMode) {
renderState.setBlendMode(convertBlend(blendMode)); renderState.setBlendMode(convertBlend(blendMode));
} }
@ -206,11 +221,13 @@ public class RenderDeviceJme implements RenderDevice {
private RenderState.BlendMode convertBlend(BlendMode blendMode) { private RenderState.BlendMode convertBlend(BlendMode blendMode) {
if (blendMode == null) { if (blendMode == null) {
return RenderState.BlendMode.Off; return RenderState.BlendMode.Off;
} else if (blendMode == BlendMode.BLEND) { } else
switch (blendMode) {
case BLEND:
return RenderState.BlendMode.Alpha; return RenderState.BlendMode.Alpha;
} else if (blendMode == BlendMode.MULIPLY) { case MULIPLY:
return RenderState.BlendMode.Alpha; return RenderState.BlendMode.Alpha;
} else { default:
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();
} }
} }
@ -264,6 +281,7 @@ public class RenderDeviceJme implements RenderDevice {
// System.out.format("renderFont(%s, %s, %d, %d, %s, %f, %f)\n", jmeFont.getFont(), str, x, y, color.toString(), sizeX, sizeY); // System.out.format("renderFont(%s, %s, %d, %d, %s, %f, %f)\n", jmeFont.getFont(), str, x, y, color.toString(), sizeX, sizeY);
} }
@Override
public void renderImage(RenderImage image, int x, int y, int w, int h, public void renderImage(RenderImage image, int x, int y, int w, int h,
int srcX, int srcY, int srcW, int srcH, int srcX, int srcY, int srcW, int srcH,
Color color, float scale, Color color, float scale,
@ -314,6 +332,7 @@ public class RenderDeviceJme implements RenderDevice {
// color.toString(), scale, centerX, centerY); // color.toString(), scale, centerX, centerY);
} }
@Override
public void renderImage(RenderImage image, int x, int y, int width, int height, public void renderImage(RenderImage image, int x, int y, int width, int height,
Color color, float imageScale) { Color color, float imageScale) {
@ -339,6 +358,7 @@ public class RenderDeviceJme implements RenderDevice {
//System.out.format("renderImage1(%s, %d, %d, %d, %d, %s, %f)\n", jmeImage.getTexture().getKey().toString(), x, y, width, height, color.toString(), imageScale); //System.out.format("renderImage1(%s, %d, %d, %d, %d, %s, %f)\n", jmeImage.getTexture().getKey().toString(), x, y, width, height, color.toString(), imageScale);
} }
@Override
public void renderQuad(int x, int y, int width, int height, Color color) { public void renderQuad(int x, int y, int width, int height, Color color) {
//We test for alpha >0 as an optimization to prevent the render of completely transparent quads. //We test for alpha >0 as an optimization to prevent the render of completely transparent quads.
//Nifty use layers that are often used for logical positionning and not rendering. //Nifty use layers that are often used for logical positionning and not rendering.
@ -360,6 +380,7 @@ public class RenderDeviceJme implements RenderDevice {
//System.out.format("renderQuad1(%d, %d, %d, %d, %s)\n", x, y, width, height, color.toString()); //System.out.format("renderQuad1(%d, %d, %d, %d, %s)\n", x, y, width, height, color.toString());
} }
@Override
public void renderQuad(int x, int y, int width, int height, public void renderQuad(int x, int y, int width, int height,
Color topLeft, Color topRight, Color bottomRight, Color bottomLeft) { Color topLeft, Color topRight, Color bottomRight, Color bottomLeft) {
@ -389,11 +410,13 @@ public class RenderDeviceJme implements RenderDevice {
// bottomLeft.toString()); // bottomLeft.toString());
} }
@Override
public void enableClip(int x0, int y0, int x1, int y1) { public void enableClip(int x0, int y0, int x1, int y1) {
clipWasSet = true; clipWasSet = true;
r.setClipRect(x0, getHeight() - y1, x1 - x0, y1 - y0); r.setClipRect(x0, getHeight() - y1, x1 - x0, y1 - y0);
} }
@Override
public void disableClip() { public void disableClip() {
if (clipWasSet) { if (clipWasSet) {
r.clearClipRect(); r.clearClipRect();

@ -37,17 +37,16 @@ import de.lessvoid.nifty.spi.render.RenderFont;
public class RenderFontJme implements RenderFont { public class RenderFontJme implements RenderFont {
private NiftyJmeDisplay display; private final BitmapFont font;
private BitmapFont font; private final BitmapText text;
private BitmapText text; private final float actualSize;
private float actualSize;
/** /**
* Initialize the font. * Initialize the font.
* @param name font filename * @param name font filename
* @param display
*/ */
public RenderFontJme(String name, NiftyJmeDisplay display) { public RenderFontJme(String name, NiftyJmeDisplay display) {
this.display = display;
font = display.getAssetManager().loadFont(name); font = display.getAssetManager().loadFont(name);
text = new BitmapText(font); text = new BitmapText(font);
actualSize = font.getPreferredSize(); actualSize = font.getPreferredSize();
@ -70,6 +69,7 @@ public class RenderFontJme implements RenderFont {
* get font height. * get font height.
* @return height * @return height
*/ */
@Override
public int getHeight() { public int getHeight() {
return (int) text.getLineHeight(); return (int) text.getLineHeight();
} }
@ -79,6 +79,7 @@ public class RenderFontJme implements RenderFont {
* @param str text * @param str text
* @return width of the given text for the current font * @return width of the given text for the current font
*/ */
@Override
public int getWidth(final String str) { public int getWidth(final String str) {
if (str.length() == 0) { if (str.length() == 0) {
return 0; return 0;
@ -98,6 +99,7 @@ public class RenderFontJme implements RenderFont {
return result; return result;
} }
@Override
public int getWidth(final String str, final float size) { public int getWidth(final String str, final float size) {
// Note: This is supposed to return the width of the String when scaled // Note: This is supposed to return the width of the String when scaled
// with the size factor. Since I don't know how to do that with // with the size factor. Since I don't know how to do that with
@ -113,10 +115,12 @@ public class RenderFontJme implements RenderFont {
* @param size font size * @param size font size
* @return width of the character or null when no information for the character is available * @return width of the character or null when no information for the character is available
*/ */
@Override
public int getCharacterAdvance(final char currentCharacter, final char nextCharacter, final float size) { public int getCharacterAdvance(final char currentCharacter, final char nextCharacter, final float size) {
return Math.round(font.getCharacterAdvance(currentCharacter, nextCharacter, size)); return Math.round(font.getCharacterAdvance(currentCharacter, nextCharacter, size));
} }
@Override
public void dispose() { public void dispose() {
} }
} }

@ -75,14 +75,17 @@ public class RenderImageJme implements RenderImage {
return texture; return texture;
} }
@Override
public int getWidth() { public int getWidth() {
return width; return width;
} }
@Override
public int getHeight() { public int getHeight() {
return height; return height;
} }
@Override
public void dispose() { public void dispose() {
} }
} }

@ -50,19 +50,23 @@ public class SoundDeviceJme implements SoundDevice {
this.ar = ar; this.ar = ar;
} }
@Override
public void setResourceLoader(NiftyResourceLoader niftyResourceLoader) { public void setResourceLoader(NiftyResourceLoader niftyResourceLoader) {
} }
@Override
public SoundHandle loadSound(SoundSystem soundSystem, String filename) { public SoundHandle loadSound(SoundSystem soundSystem, String filename) {
AudioNode an = new AudioNode(assetManager, filename, AudioData.DataType.Buffer); AudioNode an = new AudioNode(assetManager, filename, AudioData.DataType.Buffer);
an.setPositional(false); an.setPositional(false);
return new SoundHandleJme(ar, an); return new SoundHandleJme(ar, an);
} }
@Override
public SoundHandle loadMusic(SoundSystem soundSystem, String filename) { public SoundHandle loadMusic(SoundSystem soundSystem, String filename) {
return new SoundHandleJme(ar, assetManager, filename); return new SoundHandleJme(ar, assetManager, filename);
} }
@Override
public void update(int delta) { public void update(int delta) {
} }

@ -34,8 +34,8 @@ package com.jme3.niftygui;
import com.jme3.asset.AssetManager; import com.jme3.asset.AssetManager;
import com.jme3.audio.AudioData; import com.jme3.audio.AudioData;
import com.jme3.audio.AudioNode; import com.jme3.audio.AudioNode;
import com.jme3.audio.AudioSource.Status;
import com.jme3.audio.AudioRenderer; import com.jme3.audio.AudioRenderer;
import com.jme3.audio.AudioSource.Status;
import de.lessvoid.nifty.spi.sound.SoundHandle; import de.lessvoid.nifty.spi.sound.SoundHandle;
public class SoundHandleJme implements SoundHandle { public class SoundHandleJme implements SoundHandle {
@ -72,6 +72,7 @@ public class SoundHandleJme implements SoundHandle {
this.fileName = fileName; this.fileName = fileName;
} }
@Override
public void play() { public void play() {
if (fileName != null){ if (fileName != null){
if (node != null){ if (node != null){
@ -87,6 +88,7 @@ public class SoundHandleJme implements SoundHandle {
} }
} }
@Override
public void stop() { public void stop() {
if (node != null){ if (node != null){
node.stop(); node.stop();
@ -98,6 +100,7 @@ public class SoundHandleJme implements SoundHandle {
} }
} }
@Override
public void setVolume(float f) { public void setVolume(float f) {
if (node != null) { if (node != null) {
node.setVolume(f); node.setVolume(f);
@ -105,14 +108,17 @@ public class SoundHandleJme implements SoundHandle {
volume = f; volume = f;
} }
@Override
public float getVolume() { public float getVolume() {
return volume; return volume;
} }
@Override
public boolean isPlaying() { public boolean isPlaying() {
return node != null && node.getStatus() == Status.Playing; return node != null && node.getStatus() == Status.Playing;
} }
@Override
public void dispose() { public void dispose() {
} }
} }

Loading…
Cancel
Save