* Fix syntax errors due to JmeSystem/Platform changes
* Prevent stream closed exception when playing OGG music * Prevent UnsatisfiedLinkError when using audio effects on Mac * Add BitmapText caching to Nifty GUI. May improve FPS in guis with lots of text elements git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@8237 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
This commit is contained in:
parent
5ac90f46fa
commit
64c61c86e4
@ -178,7 +178,7 @@ public class OGLESShaderRenderer implements Renderer {
|
||||
if (versionStr == null || versionStr.equals("")) {
|
||||
glslVer = -1;
|
||||
throw new UnsupportedOperationException("GLSL and OpenGL2 is "
|
||||
+ "required for the LWJGL "
|
||||
+ "required for the OpenGL ES "
|
||||
+ "renderer!");
|
||||
}
|
||||
|
||||
|
@ -31,7 +31,6 @@
|
||||
*/
|
||||
package com.jme3.system;
|
||||
|
||||
import com.jme3.system.JmeSystem.Platform;
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
|
@ -245,7 +245,12 @@ public class OGGLoader implements AssetLoader {
|
||||
InputStream in = null;
|
||||
try {
|
||||
in = info.openStream();
|
||||
return load(in, readStream, streamCache);
|
||||
AudioData data = load(in, readStream, streamCache);
|
||||
if (data instanceof AudioStream){
|
||||
// audio streams must remain open
|
||||
in = null;
|
||||
}
|
||||
return data;
|
||||
} finally {
|
||||
if (in != null){
|
||||
in.close();
|
||||
|
@ -199,8 +199,6 @@ public class LwjglAudioRenderer implements AudioRenderer, Runnable {
|
||||
logger.log(Level.INFO, "AudioRenderer supports {0} channels", channels.length);
|
||||
|
||||
supportEfx = ALC10.alcIsExtensionPresent(device, "ALC_EXT_EFX");
|
||||
logger.log(Level.FINER, "Audio EFX support: {0}", supportEfx);
|
||||
|
||||
if (supportEfx){
|
||||
ib.position(0).limit(1);
|
||||
ALC10.alcGetInteger(device, EFX10.ALC_EFX_MAJOR_VERSION, ib);
|
||||
@ -227,6 +225,8 @@ public class LwjglAudioRenderer implements AudioRenderer, Runnable {
|
||||
|
||||
// attach reverb effect to effect slot
|
||||
// EFX10.alAuxiliaryEffectSloti(reverbFxSlot, EFX10.AL_EFFECTSLOT_EFFECT, reverbFx);
|
||||
}else{
|
||||
logger.log(Level.WARNING, "OpenAL EFX not available! Audio effects won't work.");
|
||||
}
|
||||
}
|
||||
|
||||
@ -348,7 +348,7 @@ public class LwjglAudioRenderer implements AudioRenderer, Runnable {
|
||||
alSourcef(id, AL_REFERENCE_DISTANCE, src.getRefDistance());
|
||||
break;
|
||||
case ReverbFilter:
|
||||
if (!src.isPositional() || !src.isReverbEnabled())
|
||||
if (!supportEfx || !src.isPositional() || !src.isReverbEnabled())
|
||||
return;
|
||||
|
||||
int filter = EFX10.AL_FILTER_NULL;
|
||||
@ -362,7 +362,7 @@ public class LwjglAudioRenderer implements AudioRenderer, Runnable {
|
||||
AL11.alSource3i(id, EFX10.AL_AUXILIARY_SEND_FILTER, reverbFxSlot, 0, filter);
|
||||
break;
|
||||
case ReverbEnabled:
|
||||
if (!src.isPositional())
|
||||
if (!supportEfx || !src.isPositional())
|
||||
return;
|
||||
|
||||
if (src.isReverbEnabled()){
|
||||
@ -418,6 +418,9 @@ public class LwjglAudioRenderer implements AudioRenderer, Runnable {
|
||||
}
|
||||
break;
|
||||
case DryFilter:
|
||||
if (!supportEfx)
|
||||
return;
|
||||
|
||||
if (src.getDryFilter() != null){
|
||||
Filter f = src.getDryFilter();
|
||||
if (f.isUpdateNeeded()){
|
||||
@ -459,7 +462,7 @@ public class LwjglAudioRenderer implements AudioRenderer, Runnable {
|
||||
alSourcef(id, AL_REFERENCE_DISTANCE, src.getRefDistance());
|
||||
alSourcei(id, AL_SOURCE_RELATIVE, AL_FALSE);
|
||||
|
||||
if (src.isReverbEnabled()){
|
||||
if (src.isReverbEnabled() && supportEfx){
|
||||
int filter = EFX10.AL_FILTER_NULL;
|
||||
if (src.getReverbFilter() != null){
|
||||
Filter f = src.getReverbFilter();
|
||||
@ -477,7 +480,7 @@ public class LwjglAudioRenderer implements AudioRenderer, Runnable {
|
||||
alSource3f(id, AL_VELOCITY, 0,0,0);
|
||||
}
|
||||
|
||||
if (src.getDryFilter() != null){
|
||||
if (src.getDryFilter() != null && supportEfx){
|
||||
Filter f = src.getDryFilter();
|
||||
if (f.isUpdateNeeded()){
|
||||
updateFilter(f);
|
||||
@ -589,7 +592,7 @@ public class LwjglAudioRenderer implements AudioRenderer, Runnable {
|
||||
} catch (InterruptedException ex) {
|
||||
}
|
||||
}
|
||||
if (audioDisabled)
|
||||
if (audioDisabled || !supportEfx)
|
||||
return;
|
||||
|
||||
EFX10.alEffectf(reverbFx, EFX10.AL_REVERB_DENSITY, env.getDensity());
|
||||
@ -706,13 +709,13 @@ public class LwjglAudioRenderer implements AudioRenderer, Runnable {
|
||||
alSourcei(sourceId, AL_BUFFER, 0);
|
||||
}
|
||||
|
||||
if (src.getDryFilter() != null){
|
||||
if (src.getDryFilter() != null && supportEfx){
|
||||
// detach filter
|
||||
alSourcei(sourceId, EFX10.AL_DIRECT_FILTER, EFX10.AL_FILTER_NULL);
|
||||
}
|
||||
if (src.isPositional()){
|
||||
AudioNode pas = (AudioNode) src;
|
||||
if (pas.isReverbEnabled()) {
|
||||
if (pas.isReverbEnabled() && supportEfx) {
|
||||
AL11.alSource3i(sourceId, EFX10.AL_AUXILIARY_SEND_FILTER, 0, 0, EFX10.AL_FILTER_NULL);
|
||||
}
|
||||
}
|
||||
|
@ -36,13 +36,12 @@ import com.jme3.system.AppSettings;
|
||||
import com.jme3.system.JmeCanvasContext;
|
||||
import com.jme3.system.JmeContext.Type;
|
||||
import com.jme3.system.JmeSystem;
|
||||
import com.jme3.system.JmeSystem.Platform;
|
||||
import com.jme3.system.Platform;
|
||||
import java.awt.Canvas;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import javax.swing.SwingUtilities;
|
||||
import org.lwjgl.LWJGLException;
|
||||
import org.lwjgl.LWJGLUtil;
|
||||
import org.lwjgl.input.Keyboard;
|
||||
import org.lwjgl.input.Mouse;
|
||||
import org.lwjgl.opengl.Display;
|
||||
|
@ -55,6 +55,7 @@ public class InputSystemJme implements InputSystem, RawInputListener {
|
||||
|
||||
private InputManager inputManager;
|
||||
|
||||
private boolean isDragging = false, niftyOwnsDragging = false;
|
||||
private boolean pressed = false;
|
||||
private int buttonIndex;
|
||||
private int x, y;
|
||||
@ -65,7 +66,6 @@ public class InputSystemJme implements InputSystem, RawInputListener {
|
||||
|
||||
private Nifty nifty;
|
||||
|
||||
|
||||
public InputSystemJme(InputManager inputManager){
|
||||
this.inputManager = inputManager;
|
||||
}
|
||||
@ -86,53 +86,50 @@ public class InputSystemJme implements InputSystem, RawInputListener {
|
||||
}
|
||||
|
||||
public void beginInput(){
|
||||
|
||||
}
|
||||
|
||||
public void endInput(){
|
||||
//requires nifty1.3
|
||||
boolean result = nifty.update();
|
||||
}
|
||||
|
||||
public void onJoyAxisEvent(JoyAxisEvent evt) {
|
||||
}
|
||||
|
||||
public void onJoyButtonEvent(JoyButtonEvent evt) {
|
||||
}
|
||||
|
||||
private void onMouseMotionEventQueued(MouseMotionEvent evt, NiftyInputConsumer nic) {
|
||||
x = evt.getX();
|
||||
y = height - evt.getY();
|
||||
nic.processMouseEvent(x, y, evt.getDeltaWheel(), buttonIndex, pressed);
|
||||
//MouseInputEvent niftyEvt = new MouseInputEvent(x, y, pressed);
|
||||
// if (nic.processMouseEvent(niftyEvt) /*|| nifty.getCurrentScreen().isMouseOverElement()*/){
|
||||
// Do not consume motion events
|
||||
//evt.setConsumed();
|
||||
// }
|
||||
}
|
||||
|
||||
public void onMouseMotionEvent(MouseMotionEvent evt) {
|
||||
// Only forward the event if there's actual motion involved.
|
||||
// No longer ignores mouse wheel
|
||||
if (inputManager.isCursorVisible() && (evt.getDX() != 0 ||
|
||||
evt.getDY() != 0 ||
|
||||
evt.getDeltaWheel() != 0)){
|
||||
inputQueue.add(evt);
|
||||
}
|
||||
}
|
||||
|
||||
private void onMouseButtonEventQueued(MouseButtonEvent evt, NiftyInputConsumer nic) {
|
||||
boolean wasPressed = pressed;
|
||||
boolean forwardToNifty = true;
|
||||
|
||||
buttonIndex = evt.getButtonIndex();
|
||||
pressed = evt.isPressed();
|
||||
|
||||
if (nic.processMouseEvent(x, y, 0, buttonIndex, pressed)){
|
||||
// Mouse button raised. End dragging
|
||||
if (wasPressed && !pressed){
|
||||
if (!niftyOwnsDragging){
|
||||
forwardToNifty = false;
|
||||
}
|
||||
isDragging = false;
|
||||
niftyOwnsDragging = false;
|
||||
}
|
||||
|
||||
boolean consumed = false;
|
||||
if (forwardToNifty){
|
||||
consumed = nic.processMouseEvent(x, y, 0, buttonIndex, pressed);
|
||||
if (consumed){
|
||||
evt.setConsumed();
|
||||
}
|
||||
}
|
||||
|
||||
public void onMouseButtonEvent(MouseButtonEvent evt) {
|
||||
if (inputManager.isCursorVisible() && evt.getButtonIndex() >= 0 || evt.getButtonIndex() <= 2){
|
||||
inputQueue.add(evt);
|
||||
// Mouse button pressed. Begin dragging
|
||||
if (!wasPressed && pressed){
|
||||
isDragging = true;
|
||||
niftyOwnsDragging = consumed;
|
||||
}
|
||||
}
|
||||
|
||||
@ -156,10 +153,34 @@ public class InputSystemJme implements InputSystem, RawInputListener {
|
||||
}
|
||||
}
|
||||
|
||||
public void onMouseMotionEvent(MouseMotionEvent evt) {
|
||||
// Only forward the event if there's actual motion involved.
|
||||
if (inputManager.isCursorVisible() && (evt.getDX() != 0 ||
|
||||
evt.getDY() != 0 ||
|
||||
evt.getDeltaWheel() != 0)){
|
||||
inputQueue.add(evt);
|
||||
}
|
||||
}
|
||||
|
||||
public void onMouseButtonEvent(MouseButtonEvent evt) {
|
||||
if (inputManager.isCursorVisible() && evt.getButtonIndex() >= 0 || evt.getButtonIndex() <= 2){
|
||||
inputQueue.add(evt);
|
||||
}
|
||||
}
|
||||
|
||||
public void onJoyAxisEvent(JoyAxisEvent evt) {
|
||||
}
|
||||
|
||||
public void onJoyButtonEvent(JoyButtonEvent evt) {
|
||||
}
|
||||
|
||||
public void onKeyEvent(KeyInputEvent evt) {
|
||||
inputQueue.add(evt);
|
||||
}
|
||||
|
||||
public void onTouchEvent(TouchEvent evt) {
|
||||
}
|
||||
|
||||
public void forwardEvents(NiftyInputConsumer nic) {
|
||||
int queueSize = inputQueue.size();
|
||||
|
||||
@ -177,6 +198,5 @@ public class InputSystemJme implements InputSystem, RawInputListener {
|
||||
inputQueue.clear();
|
||||
}
|
||||
|
||||
public void onTouchEvent(TouchEvent evt) {
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -53,6 +53,8 @@ import de.lessvoid.nifty.spi.render.*;
|
||||
import de.lessvoid.nifty.tools.Color;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.FloatBuffer;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class RenderDeviceJme implements RenderDevice {
|
||||
|
||||
@ -60,6 +62,9 @@ public class RenderDeviceJme implements RenderDevice {
|
||||
private RenderManager rm;
|
||||
private Renderer r;
|
||||
|
||||
private HashMap<String, BitmapText> textCacheLastFrame = new HashMap<String, BitmapText>();
|
||||
private HashMap<String, BitmapText> textCacheCurrentFrame = new HashMap<String, BitmapText>();
|
||||
|
||||
private final Quad quad = new Quad(1, -1, true);
|
||||
private final Geometry quadGeom = new Geometry("nifty-quad", quad);
|
||||
private final Material niftyMat;
|
||||
@ -120,6 +125,10 @@ public class RenderDeviceJme implements RenderDevice {
|
||||
}
|
||||
|
||||
public void endFrame() {
|
||||
HashMap<String, BitmapText> temp = textCacheLastFrame;
|
||||
textCacheLastFrame = textCacheCurrentFrame;
|
||||
textCacheCurrentFrame = temp;
|
||||
textCacheCurrentFrame.clear();
|
||||
}
|
||||
|
||||
public int getWidth() {
|
||||
@ -185,16 +194,20 @@ public class RenderDeviceJme implements RenderDevice {
|
||||
return;
|
||||
|
||||
RenderFontJme jmeFont = (RenderFontJme) font;
|
||||
BitmapText text = jmeFont.getText();
|
||||
|
||||
BitmapText text = textCacheLastFrame.get(str);
|
||||
if (text == null) {
|
||||
text = jmeFont.createText();
|
||||
text.setText(str);
|
||||
text.updateLogicalState(0);
|
||||
}
|
||||
textCacheCurrentFrame.put(str, text);
|
||||
|
||||
niftyMat.setColor("Color", convertColor(color, tempColor));
|
||||
niftyMat.setBoolean("UseTex", true);
|
||||
niftyMat.getAdditionalRenderState().setBlendMode(convertBlend());
|
||||
text.setMaterial(niftyMat);
|
||||
|
||||
text.setText(str);
|
||||
text.updateLogicalState(0);
|
||||
|
||||
float width = text.getLineWidth();
|
||||
float height = text.getLineHeight();
|
||||
|
||||
|
@ -58,6 +58,10 @@ public class RenderFontJme implements RenderFont {
|
||||
text.setSize(actualSize);
|
||||
}
|
||||
|
||||
public BitmapText createText() {
|
||||
return new BitmapText(font);
|
||||
}
|
||||
|
||||
public BitmapText getText(){
|
||||
return text;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user