diff options
author | Scott Barta <sbarta@google.com> | 2012-03-09 13:52:20 -0800 |
---|---|---|
committer | Scott Barta <sbarta@google.com> | 2012-03-09 14:13:24 -0800 |
commit | a6b44658eb1c55295f132a36233a11aa2bd8f9cf (patch) | |
tree | 4006b29d319de8635ca7cc2384782618f6c80ee7 /engine/src/core-plugins | |
parent | 59b2e6871c65f58fdad78cd7229c292f6a177578 (diff) | |
download | jmonkeyengine-a6b44658eb1c55295f132a36233a11aa2bd8f9cf.tar.gz |
New drop of the jmonkeyengine libraryHEADandroid-wear-n-preview-3android-wear-n-preview-2android-wear-n-preview-1android-sdk-support_r11android-sdk-4.4.2_r1.0.1android-sdk-4.4.2_r1android-n-preview-5android-n-preview-4android-n-preview-3android-n-preview-2android-n-preview-1android-n-mr2-preview-2android-n-mr2-preview-1android-n-mr1-preview-2android-n-mr1-preview-1android-n-iot-release-smart-display-r2android-n-iot-release-smart-displayandroid-n-iot-release-polk-at1android-n-iot-release-lg-thinq-wk7android-n-iot-release-ihome-igv1android-n-iot-preview-4android-l-preview_r2android-cts-6.0_r9android-cts-6.0_r8android-cts-6.0_r7android-cts-6.0_r6android-cts-6.0_r5android-cts-6.0_r4android-cts-6.0_r32android-cts-6.0_r31android-cts-6.0_r30android-cts-6.0_r3android-cts-6.0_r29android-cts-6.0_r28android-cts-6.0_r27android-cts-6.0_r26android-cts-6.0_r25android-cts-6.0_r24android-cts-6.0_r23android-cts-6.0_r22android-cts-6.0_r21android-cts-6.0_r20android-cts-6.0_r2android-cts-6.0_r19android-cts-6.0_r18android-cts-6.0_r17android-cts-6.0_r16android-cts-6.0_r15android-cts-6.0_r14android-cts-6.0_r13android-cts-6.0_r12android-cts-6.0_r1android-cts-4.4_r4android-cts-4.4_r1android-cts-4.2_r2android-cts-4.2_r1android-cts-4.1_r4android-cts-4.1_r2android-cts-4.1_r1android-7.1.2_r9android-7.1.2_r8android-7.1.2_r6android-7.1.2_r5android-7.1.2_r4android-7.1.2_r39android-7.1.2_r38android-7.1.2_r37android-7.1.2_r36android-7.1.2_r33android-7.1.2_r32android-7.1.2_r30android-7.1.2_r3android-7.1.2_r29android-7.1.2_r28android-7.1.2_r27android-7.1.2_r25android-7.1.2_r24android-7.1.2_r23android-7.1.2_r2android-7.1.2_r19android-7.1.2_r18android-7.1.2_r17android-7.1.2_r16android-7.1.2_r15android-7.1.2_r14android-7.1.2_r13android-7.1.2_r12android-7.1.2_r11android-7.1.2_r10android-7.1.2_r1android-6.0.1_r9android-6.0.1_r81android-6.0.1_r80android-6.0.1_r8android-6.0.1_r79android-6.0.1_r78android-6.0.1_r77android-6.0.1_r74android-6.0.1_r73android-6.0.1_r72android-6.0.1_r70android-6.0.1_r7android-6.0.1_r69android-6.0.1_r68android-6.0.1_r67android-6.0.1_r66android-6.0.1_r65android-6.0.1_r63android-6.0.1_r62android-6.0.1_r61android-6.0.1_r60android-6.0.1_r59android-6.0.1_r58android-6.0.1_r57android-6.0.1_r56android-6.0.1_r55android-6.0.1_r54android-6.0.1_r53android-6.0.1_r52android-6.0.1_r51android-6.0.1_r50android-6.0.1_r5android-6.0.1_r49android-6.0.1_r48android-6.0.1_r47android-6.0.1_r46android-6.0.1_r45android-6.0.1_r43android-6.0.1_r42android-6.0.1_r41android-6.0.1_r40android-6.0.1_r4android-6.0.1_r33android-6.0.1_r32android-6.0.1_r31android-6.0.1_r30android-6.0.1_r3android-6.0.1_r28android-6.0.1_r27android-6.0.1_r26android-6.0.1_r25android-6.0.1_r24android-6.0.1_r22android-6.0.1_r21android-6.0.1_r20android-6.0.1_r18android-6.0.1_r17android-6.0.1_r16android-6.0.1_r13android-6.0.1_r12android-6.0.1_r11android-6.0.1_r10android-6.0.1_r1android-6.0.0_r7android-6.0.0_r6android-6.0.0_r5android-6.0.0_r41android-6.0.0_r4android-6.0.0_r3android-6.0.0_r26android-6.0.0_r25android-6.0.0_r24android-6.0.0_r23android-6.0.0_r2android-6.0.0_r13android-6.0.0_r12android-6.0.0_r11android-6.0.0_r1android-4.4w_r1android-4.4_r1.2.0.1android-4.4_r1.2android-4.4_r1.1.0.1android-4.4_r1.1android-4.4_r1.0.1android-4.4_r1android-4.4_r0.9android-4.4_r0.8android-4.4_r0.7android-4.4.4_r2.0.1android-4.4.4_r2android-4.4.4_r1.0.1android-4.4.4_r1android-4.4.3_r1.1.0.1android-4.4.3_r1.1android-4.4.3_r1.0.1android-4.4.3_r1android-4.4.2_r2.0.1android-4.4.2_r2android-4.4.2_r1.0.1android-4.4.2_r1android-4.4.1_r1.0.1android-4.4.1_r1android-4.3_r3.1android-4.3_r3android-4.3_r2.3android-4.3_r2.2android-4.3_r2.1android-4.3_r2android-4.3_r1.1android-4.3_r1android-4.3_r0.9.1android-4.3_r0.9android-4.3.1_r1android-4.2_r1android-4.2.2_r1.2android-4.2.2_r1.1android-4.2.2_r1android-4.2.1_r1.2android-4.2.1_r1.1android-4.2.1_r1android-4.1.2_r2.1android-4.1.2_r2android-4.1.2_r1android-4.1.1_r6.1android-4.1.1_r6android-4.1.1_r5android-4.1.1_r4android-4.1.1_r3android-4.1.1_r2android-4.1.1_r1.1android-4.1.1_r1tools_r22.2tools_r22tools_r21nougat-mr2.3-releasenougat-mr2.2-releasenougat-mr2.1-releasenougat-mr2-security-releasenougat-mr2-releasenougat-mr2-pixel-releasenougat-mr2-devnougat-iot-releasen-iot-preview-4mastermarshmallow-releasemarshmallow-mr3-releasemarshmallow-mr2-releasemarshmallow-mr1-releasemarshmallow-mr1-devmarshmallow-dr1.6-releasemarshmallow-dr1.5-releasemarshmallow-dr1.5-devmarshmallow-dr-releasemarshmallow-dr-dragon-releasemarshmallow-dr-devmarshmallow-devmarshmallow-cts-releasemainl-previewkitkat-wearkitkat-releasekitkat-mr2.2-releasekitkat-mr2.1-releasekitkat-mr2-releasekitkat-mr1.1-releasekitkat-mr1-releasekitkat-devkitkat-cts-releasekitkat-cts-devjb-releasejb-mr2.0.0-releasejb-mr2.0-releasejb-mr2-releasejb-mr2-devjb-mr1.1-releasejb-mr1.1-dev-plus-aospjb-mr1.1-devjb-mr1-releasejb-mr1-dev-plus-aospjb-mr1-devjb-mr0-releasejb-devidea133-weekly-releaseidea133
A new drop of the jmonkeyengine library sources, based on a
2012-03-05 snapshot. Fixes a few unnecessary memory allocations in
the main rendering loop.
Change-Id: I51ac0942fe87204df102cfdce746b59a5cb5ff85
Diffstat (limited to 'engine/src/core-plugins')
-rw-r--r-- | engine/src/core-plugins/com/jme3/asset/plugins/HttpZipLocator.java~ | 355 | ||||
-rw-r--r-- | engine/src/core-plugins/com/jme3/scene/plugins/OBJLoader.java | 6 |
2 files changed, 3 insertions, 358 deletions
diff --git a/engine/src/core-plugins/com/jme3/asset/plugins/HttpZipLocator.java~ b/engine/src/core-plugins/com/jme3/asset/plugins/HttpZipLocator.java~ deleted file mode 100644 index f5fbfd1..0000000 --- a/engine/src/core-plugins/com/jme3/asset/plugins/HttpZipLocator.java~ +++ /dev/null @@ -1,355 +0,0 @@ -/* - * Copyright (c) 2009-2010 jMonkeyEngine - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * * Neither the name of 'jMonkeyEngine' nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED - * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -package com.jme3.asset.plugins; - -import com.jme3.asset.AssetInfo; -import com.jme3.asset.AssetKey; -import com.jme3.asset.AssetLocator; -import com.jme3.asset.AssetManager; -import java.io.IOException; -import java.io.InputStream; -import java.net.HttpURLConnection; -import java.net.URL; -import java.nio.ByteBuffer; -import java.nio.CharBuffer; -import java.nio.charset.CharacterCodingException; -import java.nio.charset.Charset; -import java.nio.charset.CharsetDecoder; -import java.nio.charset.CoderResult; -import java.util.HashMap; -import java.util.logging.Level; -import java.util.logging.Logger; -import java.util.zip.Inflater; -import java.util.zip.InflaterInputStream; -import java.util.zip.ZipEntry; - -public class HttpZipLocator implements AssetLocator { - - private static final Logger logger = Logger.getLogger(HttpZipLocator.class.getName()); - - private URL zipUrl; - private String rootPath = ""; - private int numEntries; - private int tableOffset; - private int tableLength; - private HashMap<String, ZipEntry2> entries; - - private static final ByteBuffer byteBuf = ByteBuffer.allocate(250); - private static final CharBuffer charBuf = CharBuffer.allocate(250); - private static final CharsetDecoder utf8Decoder; - - static { - Charset utf8 = Charset.forName("UTF-8"); - utf8Decoder = utf8.newDecoder(); - } - - private static class ZipEntry2 { - String name; - int length; - int offset; - int compSize; - long crc; - boolean deflate; - - @Override - public String toString(){ - return "ZipEntry[name=" + name + - ", length=" + length + - ", compSize=" + compSize + - ", offset=" + offset + "]"; - } - } - - private static int get16(byte[] b, int off) { - return (b[off++] & 0xff) | - ((b[off] & 0xff) << 8); - } - - private static int get32(byte[] b, int off) { - return (b[off++] & 0xff) | - ((b[off++] & 0xff) << 8) | - ((b[off++] & 0xff) << 16) | - ((b[off] & 0xff) << 24); - } - - private static long getu32(byte[] b, int off) throws IOException{ - return (b[off++]&0xff) | - ((b[off++]&0xff) << 8) | - ((b[off++]&0xff) << 16) | - (((long)(b[off]&0xff)) << 24); - } - - private static String getUTF8String(byte[] b, int off, int len) throws CharacterCodingException { - StringBuilder sb = new StringBuilder(); - - int read = 0; - while (read < len){ - // Either read n remaining bytes in b or 250 if n is higher. - int toRead = Math.min(len - read, byteBuf.capacity()); - - boolean endOfInput = toRead < byteBuf.capacity(); - - // read 'toRead' bytes into byteBuf - byteBuf.put(b, off + read, toRead); - - // set limit to position and set position to 0 - // so data can be decoded - byteBuf.flip(); - - // decode data in byteBuf - CoderResult result = utf8Decoder.decode(byteBuf, charBuf, endOfInput); - - // if the result is not an underflow its an error - // that cannot be handled. - // if the error is an underflow and its the end of input - // then the decoder expects more bytes but there are no more => error - if (!result.isUnderflow() || !endOfInput){ - result.throwException(); - } - - // flip the char buf to get the string just decoded - charBuf.flip(); - - // append the decoded data into the StringBuilder - sb.append(charBuf.toString()); - - // clear buffers for next use - byteBuf.clear(); - charBuf.clear(); - - read += toRead; - } - - return sb.toString(); - } - - private InputStream readData(int offset, int length) throws IOException{ - HttpURLConnection conn = (HttpURLConnection) zipUrl.openConnection(); - conn.setDoOutput(false); - conn.setUseCaches(false); - conn.setInstanceFollowRedirects(false); - String range = "-"; - if (offset != Integer.MAX_VALUE){ - range = offset + range; - } - if (length != Integer.MAX_VALUE){ - if (offset != Integer.MAX_VALUE){ - range = range + (offset + length - 1); - }else{ - range = range + length; - } - } - - conn.setRequestProperty("Range", "bytes=" + range); - conn.connect(); - if (conn.getResponseCode() == HttpURLConnection.HTTP_PARTIAL){ - return conn.getInputStream(); - }else if (conn.getResponseCode() == HttpURLConnection.HTTP_OK){ - throw new IOException("Your server does not support HTTP feature Content-Range. Please contact your server administrator."); - }else{ - throw new IOException(conn.getResponseCode() + " " + conn.getResponseMessage()); - } - } - - private int readTableEntry(byte[] table, int offset) throws IOException{ - if (get32(table, offset) != ZipEntry.CENSIG){ - throw new IOException("Central directory error, expected 'PK12'"); - } - - int nameLen = get16(table, offset + ZipEntry.CENNAM); - int extraLen = get16(table, offset + ZipEntry.CENEXT); - int commentLen = get16(table, offset + ZipEntry.CENCOM); - int newOffset = offset + ZipEntry.CENHDR + nameLen + extraLen + commentLen; - - int flags = get16(table, offset + ZipEntry.CENFLG); - if ((flags & 1) == 1){ - // ignore this entry, it uses encryption - return newOffset; - } - - int method = get16(table, offset + ZipEntry.CENHOW); - if (method != ZipEntry.DEFLATED && method != ZipEntry.STORED){ - // ignore this entry, it uses unknown compression method - return newOffset; - } - - String name = getUTF8String(table, offset + ZipEntry.CENHDR, nameLen); - if (name.charAt(name.length()-1) == '/'){ - // ignore this entry, it is directory node - // or it has no name (?) - return newOffset; - } - - ZipEntry2 entry = new ZipEntry2(); - entry.name = name; - entry.deflate = (method == ZipEntry.DEFLATED); - entry.crc = getu32(table, offset + ZipEntry.CENCRC); - entry.length = get32(table, offset + ZipEntry.CENLEN); - entry.compSize = get32(table, offset + ZipEntry.CENSIZ); - entry.offset = get32(table, offset + ZipEntry.CENOFF); - - // we want offset directly into file data .. - // move the offset forward to skip the LOC header - entry.offset += ZipEntry.LOCHDR + nameLen + extraLen; - - entries.put(entry.name, entry); - - return newOffset; - } - - private void fillByteArray(byte[] array, InputStream source) throws IOException{ - int total = 0; - int length = array.length; - while (total < length) { - int read = source.read(array, total, length - total); - if (read < 0) - throw new IOException("Failed to read entire array"); - - total += read; - } - } - - private void readCentralDirectory() throws IOException{ - InputStream in = readData(tableOffset, tableLength); - byte[] header = new byte[tableLength]; - - // Fix for "PK12 bug in town.zip": sometimes - // not entire byte array will be read with InputStream.read() - // (especially for big headers) - fillByteArray(header, in); - -// in.read(header); - in.close(); - - entries = new HashMap<String, ZipEntry2>(numEntries); - int offset = 0; - for (int i = 0; i < numEntries; i++){ - offset = readTableEntry(header, offset); - } - } - - private void readEndHeader() throws IOException{ - -// InputStream in = readData(Integer.MAX_VALUE, ZipEntry.ENDHDR); -// byte[] header = new byte[ZipEntry.ENDHDR]; -// fillByteArray(header, in); -// in.close(); -// -// if (get32(header, 0) != ZipEntry.ENDSIG){ -// throw new IOException("End header error, expected 'PK56'"); -// } - - // Fix for "PK56 bug in town.zip": - // If there's a zip comment inside the end header, - // PK56 won't appear in the -22 position relative to the end of the - // file! - // In that case, we have to search for it. - // Increase search space to 200 bytes - - InputStream in = readData(Integer.MAX_VALUE, 200); - byte[] header = new byte[200]; - fillByteArray(header, in); - in.close(); - - int offset = -1; - for (int i = 200 - 22; i >= 0; i--){ - if (header[i] == (byte) (ZipEntry.ENDSIG & 0xff) - && get32(header, i) == ZipEntry.ENDSIG){ - // found location - offset = i; - break; - } - } - if (offset == -1) - throw new IOException("Cannot find Zip End Header in file!"); - - numEntries = get16(header, offset + ZipEntry.ENDTOT); - tableLength = get32(header, offset + ZipEntry.ENDSIZ); - tableOffset = get32(header, offset + ZipEntry.ENDOFF); - } - - public void load(URL url) throws IOException { - if (!url.getProtocol().equals("http")) - throw new UnsupportedOperationException(); - - zipUrl = url; - readEndHeader(); - readCentralDirectory(); - } - - private InputStream openStream(ZipEntry2 entry) throws IOException{ - InputStream in = readData(entry.offset, entry.compSize); - if (entry.deflate){ - return new InflaterInputStream(in, new Inflater(true)); - } - return in; - } - - public InputStream openStream(String name) throws IOException{ - ZipEntry2 entry = entries.get(name); - if (entry == null) - throw new RuntimeException("Entry not found: "+name); - - return openStream(entry); - } - - public void setRootPath(String path){ - if (!rootPath.equals(path)){ - rootPath = path; - try { - load(new URL(path)); - } catch (IOException ex) { - logger.log(Level.WARNING, "Failed to set root path "+path, ex); - } - } - } - - public AssetInfo locate(AssetManager manager, AssetKey key){ - final ZipEntry2 entry = entries.get(key.getName()); - if (entry == null) - return null; - - return new AssetInfo(manager, key){ - @Override - public InputStream openStream() { - try { - return HttpZipLocator.this.openStream(entry); - } catch (IOException ex) { - logger.log(Level.WARNING, "Error retrieving "+entry.name, ex); - return null; - } - } - }; - } - -} diff --git a/engine/src/core-plugins/com/jme3/scene/plugins/OBJLoader.java b/engine/src/core-plugins/com/jme3/scene/plugins/OBJLoader.java index 3ce7f52..47165f6 100644 --- a/engine/src/core-plugins/com/jme3/scene/plugins/OBJLoader.java +++ b/engine/src/core-plugins/com/jme3/scene/plugins/OBJLoader.java @@ -454,9 +454,11 @@ public final class OBJLoader implements AssetLoader { if (hasNormals){ normBuf = BufferUtils.createFloatBuffer(vertIndexMap.size() * 3); + m.setBuffer(VertexBuffer.Type.Normal, 3, normBuf); } if (hasTexCoord){ tcBuf = BufferUtils.createFloatBuffer(vertIndexMap.size() * 2); + m.setBuffer(VertexBuffer.Type.TexCoord, 2, tcBuf); } IndexBuffer indexBuf = null; @@ -517,9 +519,7 @@ public final class OBJLoader implements AssetLoader { } m.setBuffer(VertexBuffer.Type.Position, 3, posBuf); - m.setBuffer(VertexBuffer.Type.Normal, 3, normBuf); - m.setBuffer(VertexBuffer.Type.TexCoord, 2, tcBuf); - // index buffer was set on creation + // index buffer and others were set on creation m.setStatic(); m.updateBound(); |