From a43e52a3849f5951432a991f6ad1ebe2ad86916a Mon Sep 17 00:00:00 2001 From: "sha..rd" Date: Sat, 25 Jun 2011 23:26:48 +0000 Subject: [PATCH] * XMLImporter can now read directly from file * XML representation of savable now writes version (no reading yet) * Initial attempt of fixing "frozen after app restart" bug * Fixed NVIDIA shininess bug (!!!) - No longer need to set m_Shininess on materials! git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@7734 75d07b2b-3a1a-0410-a2c5-0572b91ccdca --- .../Common/MatDefs/Light/Lighting.frag | 6 +++--- .../com/jme3/export/binary/BinaryExporter.java | 14 +------------- .../core/com/jme3/export/SavableClassUtil.java | 18 ++++++++++++++++-- .../system/lwjgl/LwjglAbstractDisplay.java | 2 +- .../com/jme3/system/lwjgl/LwjglDisplay.java | 16 +++++++++++----- .../com/jme3/export/xml/DOMOutputCapsule.java | 13 +++++++++++++ .../xml/com/jme3/export/xml/XMLExporter.java | 4 ++-- .../xml/com/jme3/export/xml/XMLImporter.java | 14 +++++++++++++- 8 files changed, 60 insertions(+), 27 deletions(-) diff --git a/engine/src/core-data/Common/MatDefs/Light/Lighting.frag b/engine/src/core-data/Common/MatDefs/Light/Lighting.frag index 579ee86f5..0a7a02b12 100644 --- a/engine/src/core-data/Common/MatDefs/Light/Lighting.frag +++ b/engine/src/core-data/Common/MatDefs/Light/Lighting.frag @@ -77,6 +77,9 @@ float lightComputeDiffuse(in vec3 norm, in vec3 lightdir, in vec3 viewdir){ } float lightComputeSpecular(in vec3 norm, in vec3 viewdir, in vec3 lightdir, in float shiny){ + if (shiny <= 1.0){ + return 0.0; + } #ifdef LOW_QUALITY // Blinn-Phong // Note: preferably, H should be computed in the vertex shader @@ -102,9 +105,6 @@ vec2 computeLighting(in vec3 wvPos, in vec3 wvNorm, in vec3 wvViewDir, in vec3 w float diffuseFactor = lightComputeDiffuse(wvNorm, wvLightDir, wvViewDir); float specularFactor = lightComputeSpecular(wvNorm, wvViewDir, wvLightDir, m_Shininess); - // if shininess is == 0, spec == 0, if shininess > 1, spec == 1 - specularFactor *= min(1.0, m_Shininess); - #ifdef HQ_ATTENUATION float att = clamp(1.0 - g_LightPosition.w * length(lightVec), 0.0, 1.0); #else diff --git a/engine/src/core-plugins/com/jme3/export/binary/BinaryExporter.java b/engine/src/core-plugins/com/jme3/export/binary/BinaryExporter.java index b4e30457e..c5ce66eb5 100644 --- a/engine/src/core-plugins/com/jme3/export/binary/BinaryExporter.java +++ b/engine/src/core-plugins/com/jme3/export/binary/BinaryExporter.java @@ -350,19 +350,7 @@ public class BinaryExporter implements JmeExporter { BinaryClassObject bco = new BinaryClassObject(); bco.alias = generateTag(); bco.nameFields = new HashMap(); - - ArrayList versionList = new ArrayList(); - Class superclass = clazz; - do { - versionList.add(SavableClassUtil.getSavableVersion(superclass)); - superclass = superclass.getSuperclass(); - } while (superclass != null && SavableClassUtil.isImplementingSavable(superclass)); - - int[] versions = new int[versionList.size()]; - for (int i = 0; i < versionList.size(); i++){ - versions[i] = versionList.get(i); - } - bco.classHierarchyVersions = versions; + bco.classHierarchyVersions = SavableClassUtil.getSavableVersions(clazz); classes.put(clazz.getName(), bco); diff --git a/engine/src/core/com/jme3/export/SavableClassUtil.java b/engine/src/core/com/jme3/export/SavableClassUtil.java index 33f8d1d1e..a4c9c960c 100644 --- a/engine/src/core/com/jme3/export/SavableClassUtil.java +++ b/engine/src/core/com/jme3/export/SavableClassUtil.java @@ -42,9 +42,8 @@ import java.util.logging.Level; import java.util.logging.Logger; import com.jme3.material.MatParamTexture; -import com.jme3.scene.Spatial; import java.lang.reflect.Field; -import java.lang.reflect.Type; +import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -95,6 +94,21 @@ public class SavableClassUtil { return false; } + public static int[] getSavableVersions(Class clazz) throws IOException{ + ArrayList versionList = new ArrayList(); + Class superclass = clazz; + do { + versionList.add(getSavableVersion(superclass)); + superclass = superclass.getSuperclass(); + } while (superclass != null && SavableClassUtil.isImplementingSavable(superclass)); + + int[] versions = new int[versionList.size()]; + for (int i = 0; i < versionList.size(); i++){ + versions[i] = versionList.get(i); + } + return versions; + } + public static int getSavableVersion(Class clazz) throws IOException{ try { Field field = clazz.getField("SAVABLE_VERSION"); diff --git a/engine/src/lwjgl-ogl/com/jme3/system/lwjgl/LwjglAbstractDisplay.java b/engine/src/lwjgl-ogl/com/jme3/system/lwjgl/LwjglAbstractDisplay.java index 9087db2c4..5ec0a68be 100644 --- a/engine/src/lwjgl-ogl/com/jme3/system/lwjgl/LwjglAbstractDisplay.java +++ b/engine/src/lwjgl-ogl/com/jme3/system/lwjgl/LwjglAbstractDisplay.java @@ -142,7 +142,7 @@ public abstract class LwjglAbstractDisplay extends LwjglContext implements Runna throw new IllegalStateException(); listener.update(); - + // All this does is call swap buffers // If the canvas is not active, there's no need to waste time // doing that .. diff --git a/engine/src/lwjgl-ogl/com/jme3/system/lwjgl/LwjglDisplay.java b/engine/src/lwjgl-ogl/com/jme3/system/lwjgl/LwjglDisplay.java index 6fd803265..bd38bd2e1 100644 --- a/engine/src/lwjgl-ogl/com/jme3/system/lwjgl/LwjglDisplay.java +++ b/engine/src/lwjgl-ogl/com/jme3/system/lwjgl/LwjglDisplay.java @@ -32,7 +32,6 @@ package com.jme3.system.lwjgl; -import com.jme3.input.TouchInput; import com.jme3.system.JmeContext.Type; import org.lwjgl.LWJGLException; import org.lwjgl.opengl.Display; @@ -110,14 +109,21 @@ public class LwjglDisplay extends LwjglAbstractDisplay { pixelFormat = pf; Display.setTitle(settings.getTitle()); - if (displayMode != null) - Display.setDisplayMode(displayMode); + if (displayMode != null){ + if (settings.isFullscreen()){ + Display.setDisplayModeAndFullscreen(displayMode); + }else{ + Display.setFullscreen(false); + Display.setDisplayMode(displayMode); + } + }else{ + Display.setFullscreen(settings.isFullscreen()); + } if (settings.getIcons() != null) { Display.setIcon(imagesToByteBuffers(settings.getIcons())); } - - Display.setFullscreen(settings.isFullscreen()); + Display.setVSyncEnabled(settings.isVSync()); if (!created.get() || pixelFormatChanged){ diff --git a/engine/src/xml/com/jme3/export/xml/DOMOutputCapsule.java b/engine/src/xml/com/jme3/export/xml/DOMOutputCapsule.java index 037576f54..20ff3eb9d 100644 --- a/engine/src/xml/com/jme3/export/xml/DOMOutputCapsule.java +++ b/engine/src/xml/com/jme3/export/xml/DOMOutputCapsule.java @@ -36,6 +36,7 @@ import com.jme3.export.JmeExporter; import com.jme3.export.OutputCapsule; import com.jme3.export.Savable; import com.jme3.export.Savable; +import com.jme3.export.SavableClassUtil; import com.jme3.util.IntMap; import com.jme3.util.IntMap.Entry; import java.io.IOException; @@ -484,6 +485,18 @@ public class DOMOutputCapsule implements OutputCapsule { el.setAttribute("ref", refID); } else { el = appendElement(name); + + // jME3 NEW: Append version number(s) + int[] versions = SavableClassUtil.getSavableVersions(object.getClass()); + StringBuilder sb = new StringBuilder(); + for (int i = 0; i < versions.length; i++){ + sb.append(versions[i]); + if (i != versions.length - 1){ + sb.append(", "); + } + } + el.setAttribute("savable_version", sb.toString()); + writtenSavables.put(object, el); object.write(exporter); } diff --git a/engine/src/xml/com/jme3/export/xml/XMLExporter.java b/engine/src/xml/com/jme3/export/xml/XMLExporter.java index dccb15d71..46d5b452d 100644 --- a/engine/src/xml/com/jme3/export/xml/XMLExporter.java +++ b/engine/src/xml/com/jme3/export/xml/XMLExporter.java @@ -63,8 +63,8 @@ public class XMLExporter implements JmeExporter{ public boolean save(Savable object, OutputStream f) throws IOException { try { - //Initialize Document when saving so we don't retain state of previous exports - this.domOut = new DOMOutputCapsule(DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument(), this); + //Initialize Document when saving so we don't retain state of previous exports + this.domOut = new DOMOutputCapsule(DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument(), this); domOut.write(object, object.getClass().getName(), null); DOMSerializer serializer = new DOMSerializer(); serializer.serialize(domOut.getDoc(), f); diff --git a/engine/src/xml/com/jme3/export/xml/XMLImporter.java b/engine/src/xml/com/jme3/export/xml/XMLImporter.java index 50ae5c4ed..9a73ed7dd 100644 --- a/engine/src/xml/com/jme3/export/xml/XMLImporter.java +++ b/engine/src/xml/com/jme3/export/xml/XMLImporter.java @@ -37,6 +37,8 @@ import com.jme3.asset.AssetManager; import com.jme3.export.JmeImporter; import com.jme3.export.InputCapsule; import com.jme3.export.Savable; +import java.io.File; +import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import javax.xml.parsers.DocumentBuilderFactory; @@ -56,7 +58,6 @@ public class XMLImporter implements JmeImporter { public XMLImporter() { } -// TODO: ....... public int getFormatVersion() { return 0; } @@ -76,6 +77,17 @@ public class XMLImporter implements JmeImporter { in.close(); return obj; } + + public Savable load(File f) throws IOException { + FileInputStream fis = null; + try { + fis = new FileInputStream(f); + Savable sav = load(fis); + return sav; + } finally { + if (fis != null) fis.close(); + } + } public Savable load(InputStream f) throws IOException { try {