Fixed formatting thanks to EmpirePhoenix

experimental
michael 10 years ago
parent a59f017710
commit 99d69d1d01
  1. 2
      .gitignore
  2. 22
      jme3-core/src/main/java/com/jme3/asset/cache/WeakRefCloneAssetCache.java
  3. 2
      jme3-core/src/main/java/com/jme3/material/TechniqueDef.java
  4. 1
      jme3-core/src/main/java/com/jme3/renderer/Caps.java
  5. 229
      jme3-core/src/plugins/java/com/jme3/material/plugins/J3MLoader.java

2
.gitignore vendored

@ -131,5 +131,3 @@
!/jme3-bullet-native/libs/native/osx/x86_64/libbulletjme.dylib
!/jme3-bullet-native/libs/native/linux/x86/libbulletjme.so
!/jme3-bullet-native/libs/native/linux/x86_64/libbulletjme.so
*.iml
/.idea/*

@ -33,7 +33,6 @@ package com.jme3.asset.cache;
import com.jme3.asset.AssetKey;
import com.jme3.asset.CloneableSmartAsset;
import java.lang.ref.PhantomReference;
import java.lang.ref.ReferenceQueue;
import java.lang.ref.WeakReference;
@ -49,7 +48,7 @@ import java.util.logging.Logger;
* when all clones of the original asset are collected, will cause the
* asset to be automatically removed from the cache.
*
* @author Kirill Vainer
* @author Kirill Vainer
*/
public class WeakRefCloneAssetCache implements AssetCache {
@ -103,16 +102,16 @@ public class WeakRefCloneAssetCache implements AssetCache {
}
};
private void removeCollectedAssets() {
private void removeCollectedAssets(){
int removedAssets = 0;
for (KeyRef ref; (ref = (KeyRef) refQueue.poll()) != null; ) {
for (KeyRef ref; (ref = (KeyRef)refQueue.poll()) != null;){
// (Cannot use ref.get() since it was just collected by GC!)
AssetKey key = ref.clonedKey;
// Asset was collected, note that at this point the asset cache
// might not even have this asset anymore, it is OK.
if (smartCache.remove(key) != null) {
removedAssets++;
if (smartCache.remove(key) != null){
removedAssets ++;
//System.out.println("WeakRefAssetCache: The asset " + ref.assetKey + " was purged from the cache");
}
}
@ -124,6 +123,7 @@ public class WeakRefCloneAssetCache implements AssetCache {
public <T> void addToCache(AssetKey<T> originalKey, T obj) {
// Make room for new asset
removeCollectedAssets();
CloneableSmartAsset asset = (CloneableSmartAsset) obj;
// No circular references, since the original asset is
@ -146,7 +146,7 @@ public class WeakRefCloneAssetCache implements AssetCache {
public <T> void registerAssetClone(AssetKey<T> key, T clone) {
ArrayList<AssetKey> loadStack = assetLoadStack.get();
((CloneableSmartAsset) clone).setKey(loadStack.remove(loadStack.size() - 1));
((CloneableSmartAsset)clone).setKey(loadStack.remove(loadStack.size() - 1));
}
public void notifyNoAssetClone() {
@ -156,7 +156,7 @@ public class WeakRefCloneAssetCache implements AssetCache {
public <T> T getFromCache(AssetKey<T> key) {
AssetRef smartInfo;
synchronized (smartCache) {
synchronized (smartCache){
smartInfo = smartCache.get(key);
}
@ -167,7 +167,7 @@ public class WeakRefCloneAssetCache implements AssetCache {
// can check this and determine that the asset clone
// belongs to the asset retrieved here.
AssetKey keyForTheClone = smartInfo.get();
if (keyForTheClone == null) {
if (keyForTheClone == null){
// The asset was JUST collected by GC
// (between here and smartCache.get)
return null;
@ -185,7 +185,7 @@ public class WeakRefCloneAssetCache implements AssetCache {
public boolean deleteFromCache(AssetKey key) {
ArrayList<AssetKey> loadStack = assetLoadStack.get();
if (!loadStack.isEmpty()) {
if (!loadStack.isEmpty()){
throw new UnsupportedOperationException("Cache cannot be modified"
+ "while assets are being loaded");
}
@ -196,7 +196,7 @@ public class WeakRefCloneAssetCache implements AssetCache {
public void clearCache() {
ArrayList<AssetKey> loadStack = assetLoadStack.get();
if (!loadStack.isEmpty()) {
if (!loadStack.isEmpty()){
throw new UnsupportedOperationException("Cache cannot be modified"
+ "while assets are being loaded");
}

@ -50,8 +50,6 @@ public class TechniqueDef implements Savable {
*/
public static final int SAVABLE_VERSION = 1;
/**
* Describes light rendering mode.
*/

@ -315,6 +315,7 @@ public enum Caps {
* Supports 32-bit index buffers.
*/
IntegerIndexBuffer,
/**
* Partial support for non-power-of-2 textures, typically found
* on OpenGL ES 2 devices.

@ -107,9 +107,9 @@ public class J3MLoader implements AssetLoader {
}
// LightMode <MODE>
private void readLightMode(String statement) throws IOException {
private void readLightMode(String statement) throws IOException{
String[] split = statement.split(whitespacePattern);
if (split.length != 2) {
if (split.length != 2){
throw new IOException("LightMode statement syntax incorrect");
}
LightMode lm = LightMode.valueOf(split[1]);
@ -117,29 +117,29 @@ public class J3MLoader implements AssetLoader {
}
// ShadowMode <MODE>
private void readShadowMode(String statement) throws IOException {
private void readShadowMode(String statement) throws IOException{
String[] split = statement.split(whitespacePattern);
if (split.length != 2) {
if (split.length != 2){
throw new IOException("ShadowMode statement syntax incorrect");
}
ShadowMode sm = ShadowMode.valueOf(split[1]);
technique.setShadowMode(sm);
}
private Object readValue(VarType type, String value) throws IOException {
if (type.isTextureType()) {
private Object readValue(VarType type, String value) throws IOException{
if (type.isTextureType()){
// String texturePath = readString("[\n;(//)(\\})]");
String texturePath = value.trim();
boolean flipY = false;
boolean repeat = false;
if (texturePath.startsWith("Flip Repeat ")) {
if (texturePath.startsWith("Flip Repeat ")){
texturePath = texturePath.substring(12).trim();
flipY = true;
repeat = true;
} else if (texturePath.startsWith("Flip ")) {
}else if (texturePath.startsWith("Flip ")){
texturePath = texturePath.substring(5).trim();
flipY = true;
} else if (texturePath.startsWith("Repeat ")) {
}else if (texturePath.startsWith("Repeat ")){
texturePath = texturePath.substring(7).trim();
repeat = true;
}
@ -161,45 +161,45 @@ public class J3MLoader implements AssetLoader {
Texture tex;
try {
tex = assetManager.loadTexture(texKey);
} catch (AssetNotFoundException ex) {
} catch (AssetNotFoundException ex){
logger.log(Level.WARNING, "Cannot locate {0} for material {1}", new Object[]{texKey, key});
tex = null;
}
if (tex != null) {
if (repeat) {
if (tex != null){
if (repeat){
tex.setWrap(WrapMode.Repeat);
}
} else {
}else{
tex = new Texture2D(PlaceholderAssets.getPlaceholderImage(assetManager));
if (repeat) {
if (repeat){
tex.setWrap(WrapMode.Repeat);
}
tex.setKey(texKey);
}
return tex;
} else {
}else{
String[] split = value.trim().split(whitespacePattern);
switch (type) {
switch (type){
case Float:
if (split.length != 1) {
if (split.length != 1){
throw new IOException("Float value parameter must have 1 entry: " + value);
}
return Float.parseFloat(split[0]);
case Vector2:
if (split.length != 2) {
if (split.length != 2){
throw new IOException("Vector2 value parameter must have 2 entries: " + value);
}
return new Vector2f(Float.parseFloat(split[0]),
Float.parseFloat(split[1]));
case Vector3:
if (split.length != 3) {
if (split.length != 3){
throw new IOException("Vector3 value parameter must have 3 entries: " + value);
}
return new Vector3f(Float.parseFloat(split[0]),
Float.parseFloat(split[1]),
Float.parseFloat(split[2]));
case Vector4:
if (split.length != 4) {
if (split.length != 4){
throw new IOException("Vector4 value parameter must have 4 entries: " + value);
}
return new ColorRGBA(Float.parseFloat(split[0]),
@ -207,23 +207,23 @@ public class J3MLoader implements AssetLoader {
Float.parseFloat(split[2]),
Float.parseFloat(split[3]));
case Int:
if (split.length != 1) {
if (split.length != 1){
throw new IOException("Int value parameter must have 1 entry: " + value);
}
return Integer.parseInt(split[0]);
case Boolean:
if (split.length != 1) {
if (split.length != 1){
throw new IOException("Boolean value parameter must have 1 entry: " + value);
}
return Boolean.parseBoolean(split[0]);
default:
throw new UnsupportedOperationException("Unknown type: " + type);
throw new UnsupportedOperationException("Unknown type: "+type);
}
}
}
// <TYPE> <NAME> [ "(" <FFBINDING> ")" ] [ ":" <DEFAULTVAL> ] [-LINEAR]
private void readParam(String statement) throws IOException {
// <TYPE> <NAME> [ "(" <FFBINDING> ")" ] [-LINEAR] [ ":" <DEFAULTVAL> ]
private void readParam(String statement) throws IOException{
String name;
String defaultVal = null;
ColorSpace colorSpace = null;
@ -231,15 +231,16 @@ public class J3MLoader implements AssetLoader {
String[] split = statement.split(":");
// Parse default val
if (split.length == 1) {
if (split.length == 1){
// Doesn't contain default value
} else {
if (split.length != 2) {
}else{
if (split.length != 2){
throw new IOException("Parameter statement syntax incorrect");
}
statement = split[0].trim();
defaultVal = split[1].trim();
}
if (statement.endsWith("-LINEAR")) {
colorSpace = ColorSpace.Linear;
statement = statement.substring(0, statement.length() - "-LINEAR".length());
@ -247,137 +248,137 @@ public class J3MLoader implements AssetLoader {
// Parse ffbinding
int startParen = statement.indexOf("(");
if (startParen != -1) {
if (startParen != -1){
// get content inside parentheses
int endParen = statement.indexOf(")", startParen);
String bindingStr = statement.substring(startParen + 1, endParen).trim();
String bindingStr = statement.substring(startParen+1, endParen).trim();
// don't care about bindingStr
statement = statement.substring(0, startParen);
}
// Parse type + name
split = statement.split(whitespacePattern);
if (split.length != 2) {
if (split.length != 2){
throw new IOException("Parameter statement syntax incorrect");
}
VarType type;
if (split[0].equals("Color")) {
if (split[0].equals("Color")){
type = VarType.Vector4;
} else {
}else{
type = VarType.valueOf(split[0]);
}
name = split[1];
Object defaultValObj = null;
if (defaultVal != null) {
if (defaultVal != null){
defaultValObj = readValue(type, defaultVal);
}
if (type.isTextureType()) {
if(type.isTextureType()){
materialDef.addMaterialParamTexture(type, name, colorSpace);
} else {
}else{
materialDef.addMaterialParam(type, name, defaultValObj);
}
}
private void readValueParam(String statement) throws IOException {
private void readValueParam(String statement) throws IOException{
// Use limit=1 incase filename contains colons
String[] split = statement.split(":", 2);
if (split.length != 2) {
if (split.length != 2){
throw new IOException("Value parameter statement syntax incorrect");
}
String name = split[0].trim();
// parse value
MatParam p = material.getMaterialDef().getMaterialParam(name);
if (p == null) {
throw new IOException("The material parameter: " + name + " is undefined.");
if (p == null){
throw new IOException("The material parameter: "+name+" is undefined.");
}
Object valueObj = readValue(p.getVarType(), split[1]);
if (p.getVarType().isTextureType()) {
if (p.getVarType().isTextureType()){
material.setTextureParam(name, p.getVarType(), (Texture) valueObj);
} else {
}else{
material.setParam(name, p.getVarType(), valueObj);
}
}
private void readMaterialParams(List<Statement> paramsList) throws IOException {
for (Statement statement : paramsList) {
private void readMaterialParams(List<Statement> paramsList) throws IOException{
for (Statement statement : paramsList){
readParam(statement.getLine());
}
}
private void readExtendingMaterialParams(List<Statement> paramsList) throws IOException {
for (Statement statement : paramsList) {
private void readExtendingMaterialParams(List<Statement> paramsList) throws IOException{
for (Statement statement : paramsList){
readValueParam(statement.getLine());
}
}
private void readWorldParams(List<Statement> worldParams) throws IOException {
for (Statement statement : worldParams) {
private void readWorldParams(List<Statement> worldParams) throws IOException{
for (Statement statement : worldParams){
technique.addWorldParam(statement.getLine());
}
}
private boolean parseBoolean(String word) {
private boolean parseBoolean(String word){
return word != null && word.equals("On");
}
private void readRenderStateStatement(Statement statement) throws IOException {
private void readRenderStateStatement(Statement statement) throws IOException{
String[] split = statement.getLine().split(whitespacePattern);
if (split[0].equals("Wireframe")) {
if (split[0].equals("Wireframe")){
renderState.setWireframe(parseBoolean(split[1]));
} else if (split[0].equals("FaceCull")) {
}else if (split[0].equals("FaceCull")){
renderState.setFaceCullMode(FaceCullMode.valueOf(split[1]));
} else if (split[0].equals("DepthWrite")) {
}else if (split[0].equals("DepthWrite")){
renderState.setDepthWrite(parseBoolean(split[1]));
} else if (split[0].equals("DepthTest")) {
}else if (split[0].equals("DepthTest")){
renderState.setDepthTest(parseBoolean(split[1]));
} else if (split[0].equals("Blend")) {
}else if (split[0].equals("Blend")){
renderState.setBlendMode(BlendMode.valueOf(split[1]));
} else if (split[0].equals("AlphaTestFalloff")) {
}else if (split[0].equals("AlphaTestFalloff")){
renderState.setAlphaTest(true);
renderState.setAlphaFallOff(Float.parseFloat(split[1]));
} else if (split[0].equals("PolyOffset")) {
}else if (split[0].equals("PolyOffset")){
float factor = Float.parseFloat(split[1]);
float units = Float.parseFloat(split[2]);
renderState.setPolyOffset(factor, units);
} else if (split[0].equals("ColorWrite")) {
}else if (split[0].equals("ColorWrite")){
renderState.setColorWrite(parseBoolean(split[1]));
} else if (split[0].equals("PointSprite")) {
}else if (split[0].equals("PointSprite")){
renderState.setPointSprite(parseBoolean(split[1]));
} else if (split[0].equals("DepthFunc")) {
}else if (split[0].equals("DepthFunc")){
renderState.setDepthFunc(RenderState.TestFunction.valueOf(split[1]));
} else if (split[0].equals("AlphaFunc")) {
}else if (split[0].equals("AlphaFunc")){
renderState.setAlphaFunc(RenderState.TestFunction.valueOf(split[1]));
} else {
throw new MatParseException(null, split[0], statement);
}
}
private void readAdditionalRenderState(List<Statement> renderStates) throws IOException {
private void readAdditionalRenderState(List<Statement> renderStates) throws IOException{
renderState = material.getAdditionalRenderState();
for (Statement statement : renderStates) {
for (Statement statement : renderStates){
readRenderStateStatement(statement);
}
renderState = null;
}
private void readRenderState(List<Statement> renderStates) throws IOException {
private void readRenderState(List<Statement> renderStates) throws IOException{
renderState = new RenderState();
for (Statement statement : renderStates) {
for (Statement statement : renderStates){
readRenderStateStatement(statement);
}
technique.setRenderState(renderState);
renderState = null;
}
private void readForcedRenderState(List<Statement> renderStates) throws IOException {
private void readForcedRenderState(List<Statement> renderStates) throws IOException{
renderState = new RenderState();
for (Statement statement : renderStates) {
for (Statement statement : renderStates){
readRenderStateStatement(statement);
}
technique.setForcedRenderState(renderState);
@ -385,26 +386,26 @@ public class J3MLoader implements AssetLoader {
}
// <DEFINENAME> [ ":" <PARAMNAME> ]
private void readDefine(String statement) throws IOException {
private void readDefine(String statement) throws IOException{
String[] split = statement.split(":");
if (split.length == 1) {
if (split.length == 1){
// add preset define
technique.addShaderPresetDefine(split[0].trim(), VarType.Boolean, true);
} else if (split.length == 2) {
}else if (split.length == 2){
technique.addShaderParamDefine(split[1].trim(), split[0].trim());
} else {
}else{
throw new IOException("Define syntax incorrect");
}
}
private void readDefines(List<Statement> defineList) throws IOException {
for (Statement statement : defineList) {
private void readDefines(List<Statement> defineList) throws IOException{
for (Statement statement : defineList){
readDefine(statement.getLine());
}
}
private void readTechniqueStatement(Statement statement) throws IOException {
private void readTechniqueStatement(Statement statement) throws IOException{
String[] split = statement.getLine().split("[ \\{]");
if (split[0].equals("VertexShader") ||
split[0].equals("FragmentShader") ||
@ -412,17 +413,17 @@ public class J3MLoader implements AssetLoader {
split[0].equals("TessellationControlShader") ||
split[0].equals("TessellationEvaluationShader")) {
readShaderStatement(statement.getLine());
} else if (split[0].equals("LightMode")) {
}else if (split[0].equals("LightMode")){
readLightMode(statement.getLine());
} else if (split[0].equals("ShadowMode")) {
}else if (split[0].equals("ShadowMode")){
readShadowMode(statement.getLine());
} else if (split[0].equals("WorldParameters")) {
}else if (split[0].equals("WorldParameters")){
readWorldParams(statement.getContents());
} else if (split[0].equals("RenderState")) {
}else if (split[0].equals("RenderState")){
readRenderState(statement.getContents());
} else if (split[0].equals("ForcedRenderState")) {
}else if (split[0].equals("ForcedRenderState")){
readForcedRenderState(statement.getContents());
} else if (split[0].equals("Defines")) {
}else if (split[0].equals("Defines")){
readDefines(statement.getContents());
} else if (split[0].equals("ShaderNodesDefinitions")) {
initNodesLoader();
@ -444,15 +445,15 @@ public class J3MLoader implements AssetLoader {
}
}
private void readTransparentStatement(String statement) throws IOException {
private void readTransparentStatement(String statement) throws IOException{
String[] split = statement.split(whitespacePattern);
if (split.length != 2) {
if (split.length != 2){
throw new IOException("Transparent statement syntax incorrect");
}
material.setTransparent(parseBoolean(split[1]));
}
private void readTechnique(Statement techStat) throws IOException {
private void readTechnique(Statement techStat) throws IOException{
isUseNodes = false;
String[] split = techStat.getLine().split(whitespacePattern);
if (split.length == 1) {
@ -464,11 +465,11 @@ public class J3MLoader implements AssetLoader {
throw new IOException("Technique statement syntax incorrect");
}
for (Statement statement : techStat.getContents()) {
for (Statement statement : techStat.getContents()){
readTechniqueStatement(statement);
}
if (isUseNodes) {
if(isUseNodes){
nodesLoaderDelegate.computeConditions();
//used for caching later, the shader here is not a file.
technique.setShaderFile(technique.hashCode() + "", technique.hashCode() + "", "GLSL100", "GLSL100");
@ -484,40 +485,40 @@ public class J3MLoader implements AssetLoader {
shaderName.clear();
}
private void loadFromRoot(List<Statement> roots) throws IOException {
if (roots.size() == 2) {
private void loadFromRoot(List<Statement> roots) throws IOException{
if (roots.size() == 2){
Statement exception = roots.get(0);
String line = exception.getLine();
if (line.startsWith("Exception")) {
if (line.startsWith("Exception")){
throw new AssetLoadException(line.substring("Exception ".length()));
} else {
}else{
throw new IOException("In multiroot material, expected first statement to be 'Exception'");
}
} else if (roots.size() != 1) {
}else if (roots.size() != 1){
throw new IOException("Too many roots in J3M/J3MD file");
}
boolean extending = false;
Statement materialStat = roots.get(0);
String materialName = materialStat.getLine();
if (materialName.startsWith("MaterialDef")) {
if (materialName.startsWith("MaterialDef")){
materialName = materialName.substring("MaterialDef ".length()).trim();
extending = false;
} else if (materialName.startsWith("Material")) {
}else if (materialName.startsWith("Material")){
materialName = materialName.substring("Material ".length()).trim();
extending = true;
} else {
}else{
throw new IOException("Specified file is not a Material file");
}
String[] split = materialName.split(":", 2);
if (materialName.equals("")) {
if (materialName.equals("")){
throw new MatParseException("Material name cannot be empty", materialStat);
}
if (split.length == 2) {
if (!extending) {
if (split.length == 2){
if (!extending){
throw new MatParseException("Must use 'Material' when extending.", materialStat);
}
@ -531,35 +532,35 @@ public class J3MLoader implements AssetLoader {
material = new Material(def);
material.setKey(key);
// material.setAssetName(fileName);
} else if (split.length == 1) {
if (extending) {
}else if (split.length == 1){
if (extending){
throw new MatParseException("Expected ':', got '{'", materialStat);
}
materialDef = new MaterialDef(assetManager, materialName);
// NOTE: pass file name for defs so they can be loaded later
materialDef.setAssetName(key.getName());
} else {
}else{
throw new MatParseException("Cannot use colon in material name/path", materialStat);
}
for (Statement statement : materialStat.getContents()) {
for (Statement statement : materialStat.getContents()){
split = statement.getLine().split("[ \\{]");
String statType = split[0];
if (extending) {
if (statType.equals("MaterialParameters")) {
if (extending){
if (statType.equals("MaterialParameters")){
readExtendingMaterialParams(statement.getContents());
} else if (statType.equals("AdditionalRenderState")) {
}else if (statType.equals("AdditionalRenderState")){
readAdditionalRenderState(statement.getContents());
} else if (statType.equals("Transparent")) {
}else if (statType.equals("Transparent")){
readTransparentStatement(statement.getLine());
}
} else {
if (statType.equals("Technique")) {
}else{
if (statType.equals("Technique")){
readTechnique(statement);
} else if (statType.equals("MaterialParameters")) {
}else if (statType.equals("MaterialParameters")){
readMaterialParams(statement.getContents());
} else {
throw new MatParseException("Expected material statement, got '" + statType + "'", statement);
}else{
throw new MatParseException("Expected material statement, got '"+statType+"'", statement);
}
}
}
@ -573,18 +574,18 @@ public class J3MLoader implements AssetLoader {
key = info.getKey();
loadFromRoot(BlockLanguageParser.parse(in));
} finally {
if (in != null) {
if (in != null){
in.close();
}
}
if (material != null) {
if (!(info.getKey() instanceof MaterialKey)) {
if (material != null){
if (!(info.getKey() instanceof MaterialKey)){
throw new IOException("Material instances must be loaded via MaterialKey");
}
// material implementation
return material;
} else {
}else{
// material definition
return materialDef;
}
@ -603,7 +604,7 @@ public class J3MLoader implements AssetLoader {
if (isUseNodes) {
if (nodesLoaderDelegate == null) {
nodesLoaderDelegate = new ShaderNodeLoaderDelegate();
} else {
}else{
nodesLoaderDelegate.clear();
}
nodesLoaderDelegate.setTechniqueDef(technique);

Loading…
Cancel
Save