From 79768ddc14609be1a6552eff55d8f60b6f85ad55 Mon Sep 17 00:00:00 2001 From: Ser Lev Arris Date: Sat, 28 Mar 2015 14:21:47 +0100 Subject: [PATCH] prepare for removal of hardcoded struct and primitive sizes. added getter to determine struct and primitive sizes. (cleanup in the java code can be done later.) --- port/jassimp/jassimp-native/src/jassimp.cpp | 48 ++++++++++++++++ port/jassimp/jassimp-native/src/jassimp.h | 14 +++++ port/jassimp/jassimp/src/jassimp/AiMesh.java | 12 ++-- .../jassimp/src/jassimp/AiNodeAnim.java | 6 +- port/jassimp/jassimp/src/jassimp/Jassimp.java | 55 ++++++++++++++++++- 5 files changed, 126 insertions(+), 9 deletions(-) diff --git a/port/jassimp/jassimp-native/src/jassimp.cpp b/port/jassimp/jassimp-native/src/jassimp.cpp index 710168e98..e093bb178 100644 --- a/port/jassimp/jassimp-native/src/jassimp.cpp +++ b/port/jassimp/jassimp-native/src/jassimp.cpp @@ -1344,7 +1344,55 @@ JNIEXPORT jint JNICALL Java_jassimp_Jassimp_getVKeysize (JNIEnv *env, jclass jClazz) { const int res = sizeof(aiVectorKey); + return res; +} +JNIEXPORT jint JNICALL Java_jassimp_Jassimp_getQKeysize + (JNIEnv *env, jclass jClazz) +{ + const int res = sizeof(aiQuatKey); + return res; +} + +JNIEXPORT jint JNICALL Java_jassimp_Jassimp_getV3Dsize + (JNIEnv *env, jclass jClazz) +{ + const int res = sizeof(aiVector3D); + return res; +} + +JNIEXPORT jint JNICALL Java_jassimp_Jassimp_getfloatsize + (JNIEnv *env, jclass jClazz) +{ + const int res = sizeof(float); + return res; +} + +JNIEXPORT jint JNICALL Java_jassimp_Jassimp_getintsize + (JNIEnv *env, jclass jClazz) +{ + const int res = sizeof(int); + return res; +} + +JNIEXPORT jint JNICALL Java_jassimp_Jassimp_getuintsize + (JNIEnv *env, jclass jClazz) +{ + const int res = sizeof(unsigned int); + return res; +} + +JNIEXPORT jint JNICALL Java_jassimp_Jassimp_getdoubletsize + (JNIEnv *env, jclass jClazz) +{ + const int res = sizeof(double); + return res; +} + +JNIEXPORT jint JNICALL Java_jassimp_Jassimp_getlongsize + (JNIEnv *env, jclass jClazz) +{ + const int res = sizeof(long); return res; } diff --git a/port/jassimp/jassimp-native/src/jassimp.h b/port/jassimp/jassimp-native/src/jassimp.h index fadea4fe6..188a4e904 100644 --- a/port/jassimp/jassimp-native/src/jassimp.h +++ b/port/jassimp/jassimp-native/src/jassimp.h @@ -9,6 +9,20 @@ extern "C" { #endif JNIEXPORT jint JNICALL Java_jassimp_Jassimp_getVKeysize (JNIEnv *, jclass); +JNIEXPORT jint JNICALL Java_jassimp_Jassimp_getQKeysize + (JNIEnv *, jclass); +JNIEXPORT jint JNICALL Java_jassimp_Jassimp_getV3Dsize + (JNIEnv *, jclass); +JNIEXPORT jint JNICALL Java_jassimp_Jassimp_getfloatsize + (JNIEnv *, jclass); +JNIEXPORT jint JNICALL Java_jassimp_Jassimp_getintsize + (JNIEnv *, jclass); +JNIEXPORT jint JNICALL Java_jassimp_Jassimp_getuintsize + (JNIEnv *, jclass); +JNIEXPORT jint JNICALL Java_jassimp_Jassimp_getdoublesize + (JNIEnv *, jclass); +JNIEXPORT jint JNICALL Java_jassimp_Jassimp_getlongsize + (JNIEnv *, jclass); /* * Class: jassimp_Jassimp diff --git a/port/jassimp/jassimp/src/jassimp/AiMesh.java b/port/jassimp/jassimp/src/jassimp/AiMesh.java index c9cb3669a..c2ebcd307 100644 --- a/port/jassimp/jassimp/src/jassimp/AiMesh.java +++ b/port/jassimp/jassimp/src/jassimp/AiMesh.java @@ -140,13 +140,17 @@ public final class AiMesh { /** * Number of bytes per float value. */ - private static final int SIZEOF_FLOAT = 4; - - + private static final int SIZEOF_FLOAT = Jassimp.NATIVE_FLOAT_SIZE; + /** * Number of bytes per int value. */ - private static final int SIZEOF_INT = 4; + private static final int SIZEOF_INT = Jassimp.NATIVE_INT_SIZE; + + /** + * Size of an AiVector3D in the native world. + */ + private static final int SIZEOF_V3D = Jassimp.NATIVE_AIVEKTOR3D_SIZE; /** diff --git a/port/jassimp/jassimp/src/jassimp/AiNodeAnim.java b/port/jassimp/jassimp/src/jassimp/AiNodeAnim.java index c084accd6..cb1c6987c 100644 --- a/port/jassimp/jassimp/src/jassimp/AiNodeAnim.java +++ b/port/jassimp/jassimp/src/jassimp/AiNodeAnim.java @@ -70,17 +70,17 @@ public final class AiNodeAnim { /** * Size of one position key entry. */ - private static final int POS_KEY_SIZE = Jassimp.getVKeysize(); + private static final int POS_KEY_SIZE = Jassimp.NATIVE_AIVEKTORKEY_SIZE; /** * Size of one rotation key entry. */ - private static final int ROT_KEY_SIZE = 24; + private static final int ROT_KEY_SIZE = Jassimp.NATIVE_AIQUATKEY_SIZE; /** * Size of one scaling key entry. */ - private static final int SCALE_KEY_SIZE = Jassimp.getVKeysize(); + private static final int SCALE_KEY_SIZE = Jassimp.NATIVE_AIVEKTORKEY_SIZE; /** diff --git a/port/jassimp/jassimp/src/jassimp/Jassimp.java b/port/jassimp/jassimp/src/jassimp/Jassimp.java index 25b8f6371..8850e68ff 100644 --- a/port/jassimp/jassimp/src/jassimp/Jassimp.java +++ b/port/jassimp/jassimp/src/jassimp/Jassimp.java @@ -97,12 +97,47 @@ public final class Jassimp { /** - * Returns the size of a struct.

+ * Returns the size of a struct or ptimitive.

* * @return the result of sizeof call */ public static native int getVKeysize(); + /** + * @see #getVKeysize + */ + public static native int getQKeysize(); + + /** + * @see #getVKeysize + */ + public static native int getV3Dsize(); + + /** + * @see #getVKeysize + */ + public static native int getfloatsize(); + + /** + * @see #getVKeysize + */ + public static native int getintsize(); + + /** + * @see #getVKeysize + */ + public static native int getuintsize(); + + /** + * @see #getVKeysize + */ + public static native int getboublesize(); + + /** + * @see #getVKeysize + */ + public static native int getlongsize(); + /** * Returns a human readable error description.

* @@ -256,8 +291,24 @@ public final class Jassimp { /* nothing to do */ } - + public static final int NATIVE_AIVEKTORKEY_SIZE; + public static final int NATIVE_AIQUATKEY_SIZE; + public static final int NATIVE_AIVEKTOR3D_SIZE; + public static final int NATIVE_FLOAT_SIZE; + public static final int NATIVE_INT_SIZE; + public static final int NATIVE_UINT_SIZE; + public static final int NATIVE_DOUBLE_SIZE; + public static final int NATIVE_LONG_SIZE; + static { System.loadLibrary("jassimp"); + NATIVE_AIVEKTORKEY_SIZE = getVKeysize(); + NATIVE_AIQUATKEY_SIZE = getQKeysize(); + NATIVE_AIVEKTOR3D_SIZE = getV3Dsize(); + NATIVE_FLOAT_SIZE = getfloatsize(); + NATIVE_INT_SIZE = getintsize(); + NATIVE_UINT_SIZE = getuintsize(); + NATIVE_DOUBLE_SIZE = getdoublesize(); + NATIVE_LONG_SIZE = getlongsize(); } }