Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrating Unigine 3D Engine to Java #889

Open
eix128 opened this issue May 30, 2020 · 23 comments
Open

Migrating Unigine 3D Engine to Java #889

eix128 opened this issue May 30, 2020 · 23 comments

Comments

@eix128
Copy link

eix128 commented May 30, 2020

Hi , i have downloaded Unigine 3D Engine
https://unigine.com/get-unigine

Then i wanted to make Binding to Java
I have made the Java File
I got error on 3 files "UnigineString.h" , "UnigineType.h" , "UnigineVector.h"

//"UnigineString.h"
//UnigineString.h:334:Could not parse declaration at '(' 334

//"UnigineType.h"
//UnigineVector.h:1410:Unexpected token 'EOF'

//"UnigineVector.h"
//UnigineType.h:422:Unexpected token 'EOF'

import org.bytedeco.javacpp.;
import org.bytedeco.javacpp.annotation.
;
import org.bytedeco.javacpp.tools.*;
//"UnigineString.h"
//UnigineString.h:334:Could not parse declaration at '(' 334

//"UnigineType.h"
//UnigineVector.h:1410:Unexpected token 'EOF'

//"UnigineVector.h"
//UnigineType.h:422:Unexpected token 'EOF'

@properties(
value = @platform(
includepath = {"C:\Users\Administrator\Unigine SDK Browser\sdks\community_windows_2.11.0.2\include"},
// preloadpath = {"/path/to/deps/"},
linkpath = {"C:\Users\Administrator\Unigine SDK Browser\sdks\community_windows_2.11.0.2\lib"},
include = {"Unigine.h","UnigineApp.h","UnigineAsyncQueue.h","UnigineBase.h","UnigineBiMap.h","UnigineBounds.h",
"UnigineCallback.h","UnigineCamera.h","UnigineChecksum.h","UnigineCompress.h","UnigineConfig.h",
"UnigineConsole.h","UnigineControls.h","UnigineDecals.h","UnigineDir.h","UnigineEditor.h",
"UnigineEllipsoid.h","UnigineEngine.h","UnigineFactory.h","UnigineFfp.h","UnigineFields.h",
"UnigineFileSystem.h","UnigineFunction.h","UnigineGame.h","UnigineGeodetics.h",
"UnigineGeodeticsTransformer.h","UnigineGeometry.h","UnigineGui.h","UnigineGUID.h","UnigineHash.h",
"UnigineHashMap.h","UnigineHashSet.h","UnigineImage.h"
,"UnigineInput.h","UnigineInterface.h","UnigineInterpreter.h","UnigineJson.h","UnigineLights.h",
"UnigineLog.h","UnigineLogic.h","UnigineMap.h","UnigineMaterial.h","UnigineMaterials.h","UnigineMath2d.h",
"UnigineMathLib.h","UnigineMemory.h","UnigineMesh.h","UnigineMeshDynamic.h","UnigineNode.h","UnigineNodes.h",
"UnigineObjects.h","UniginePackageUng.h","UniginePair.h","UniginePath.h","UniginePathFinding.h",
"UniginePhysicals.h","UniginePhysics.h","UniginePlayers.h","UniginePlugin.h","UniginePrimitives.h",
"UnigineProfiler.h","UnigineProperties.h","UniginePtr.h","UnigineRegExp.h","UnigineRender.h",
"UnigineRenderContext.h","UnigineResource.h","UnigineSet.h","UnigineShader.h","UnigineSort.h","UnigineSounds.h",
"UnigineSplash.h","UnigineSplineGraph.h","UnigineStreams.h","UnigineSystemInfo.h","UnigineTextures.h",
"UnigineThread.h","UnigineTileset.h","UnigineTilesetFile.h","UnigineTimer.h","UnigineTree.h",
"UnigineUlon.h","UnigineUserInterface.h","UnigineUtils.h","UnigineViewport.h","UnigineVisualizer.h",
"UnigineWidgets.h","UnigineWorld.h","UnigineWorlds.h","UnigineXml.h"
},

            preload = {"Unigine_x64d.lib","UnigineWrapper_x64d.lib","EditorCore_x64d.lib"},
            link = {"NativeLibrary"}
    ),
    target = "NativeLibrary"

)
public class NativeLibraryConfig implements InfoMapper {
public void map(InfoMap infoMap) {
//infoMap.put(new Info("data::Blob").pointerTypes("FloatBlob"));
infoMap.put(new Info("UNIGINE_EXPORT").javaNames("processFloatBlob"));
infoMap.put(new Info("quat::RawValuesTag").javaNames("quatRawValuesTag"));
}
}

Here is the command i have tried:
java -jar javacpp-1.5.4-SNAPSHOT.jar NativeLibraryConfig.java -d out

Here is the patched some include files:

https://wetransfer.com/downloads/11afac9e45795c53f51413df62dbf13620200530235405/4485400d897c9ea18d7858a2aca7308720200530235428/e2c70f

I donno what to do ? How to fix "UnigineString.h" , "UnigineType.h" , "UnigineVector.h" files.
1.44 MB 1 big Java file i got out when i disable "UnigineString.h" , "UnigineType.h" , "UnigineVector.h"

But how to fix the issue ?
or i am at wrong way to convert the problem?

@saudet
Copy link
Member

saudet commented May 31, 2020

Please try to follow this guide: https://github.com/bytedeco/javacpp/wiki/Mapping-Recipes

And let me know where you are having problems with it. Thanks!

@eix128
Copy link
Author

eix128 commented Jun 3, 2020

Well okay i started with small includes now,
I got error on UnigineVector.h

D:\repo\javacpp\target>java -jar javacpp.jar NativeLibraryConfig.java
Info: javac -cp javacpp.jar;D:\repo\javacpp\target NativeLibraryConfig.java
Info: Targeting UnigineWrapper.java
Info: Parsing C:\Users\Administrator\Unigine SDK Browser\sdks\community_windows_2.11.0.2\include\UnigineBase.h
Info: Parsing C:\Users\Administrator\Unigine SDK Browser\sdks\community_windows_2.11.0.2\include\UnigineMemory.h
Info: Parsing C:\Users\Administrator\Unigine SDK Browser\sdks\community_windows_2.11.0.2\include\Unigine.h
Info: Parsing C:\Users\Administrator\Unigine SDK Browser\sdks\community_windows_2.11.0.2\include\UnigineApp.h
Info: Parsing C:\Users\Administrator\Unigine SDK Browser\sdks\community_windows_2.11.0.2\include\UnigineVector.h
Exception in thread "main" org.bytedeco.javacpp.tools.ParserException: C:\Users\Administrator\Unigine SDK Browser\sdks\community_windows_2.11.0.2\include\UnigineVector.h:1409:Unexpected token 'EOF'
at org.bytedeco.javacpp.tools.Token.expect(Token.java:112)
at org.bytedeco.javacpp.tools.Parser.template(Parser.java:499)
at org.bytedeco.javacpp.tools.Parser.declarations(Parser.java:3645)
at org.bytedeco.javacpp.tools.Parser.group(Parser.java:3120)
at org.bytedeco.javacpp.tools.Parser.declarations(Parser.java:3703)
at org.bytedeco.javacpp.tools.Parser.namespace(Parser.java:3605)
at org.bytedeco.javacpp.tools.Parser.declarations(Parser.java:3702)
at org.bytedeco.javacpp.tools.Parser.parse(Parser.java:3792)
at org.bytedeco.javacpp.tools.Parser.parse(Parser.java:3933)
at org.bytedeco.javacpp.tools.Builder.parse(Builder.java:107)
at org.bytedeco.javacpp.tools.Builder.build(Builder.java:1059)
at org.bytedeco.javacpp.tools.Builder.main(Builder.java:1361)`

UnigineVector.h file is here:
https://paste.ofcode.org/NjVmiiTJB4NWYSAzbTBD3y

Or you can get Unigine Free SDK.

Why EOF Error occurs ? I checked all braces.
There seems to be like no problem on file.

My generator file:

import org.bytedeco.javacpp.*;
import org.bytedeco.javacpp.annotation.*;
import org.bytedeco.javacpp.tools.*;
@Properties(
        value = @Platform(
                value = "windows-x86_64",
                includepath = {"C:\\Users\\Administrator\\Unigine SDK Browser\\sdks\\community_windows_2.11.0.2\\include"},
                linkpath = {"C:\\Users\\Administrator\\Unigine SDK Browser\\sdks\\community_windows_2.11.0.2\\lib"},

                include = {"UnigineBase.h","UnigineMemory.h","Unigine.h","UnigineApp.h","UnigineVector.h"},
                preload = {"Unigine_x64d","UnigineWrapper_x64d","EditorCore_x64d"},
                link = {"UnigineWin64"}
        ),
        target = "UnigineWrapper"
)
@Namespace("Unigine")
public class NativeLibraryConfig implements InfoMapper {
    public void map(InfoMap infoMap) {
        //infoMap.put(new Info("data::Blob<float>").pointerTypes("FloatBlob"));
        //infoMap.put(new Info("UNIGINE_EXPORT").javaNames("processFloatBlob"));
        //infoMap.put(new Info("quat::RawValuesTag").javaNames("quatRawValuesTag"));

        infoMap.put(new Info("Unigine::SystemDialog").pointerTypes("UnigineSystemDialogP"));
        infoMap.put(new Info("Unigine::SystemDialog").valueTypes("UnigineSystemDialog"));
        infoMap.put(new Info("Unigine::SystemDialog").javaNames("UnigineSystemDialogK"));
        infoMap.put(new Info("Unigine::SystemDialog").javaText("UnigineSystemDialog"));
        infoMap.put(new Info("UNIGINE_INLINE", "ZEXPORT", "z_const", "zlib_version").cppTypes().annotations());
    }
}

@saudet
Copy link
Member

saudet commented Jun 4, 2020

Might be caused by UNIGINE_ALIGNED4(), UNIGINE_ALIGNED8(), UNIGINE_ALIGNED16(), and UNIGINE_ALIGNED128(). Make sure that they don't expand to anything that has strange attributes.

@eix128
Copy link
Author

eix128 commented Jun 4, 2020

I have found the location of decleration on UnigineBasic.h

UNIGINE_ALIGNED4(), UNIGINE_ALIGNED8(), UNIGINE_ALIGNED16()
/*
*/
#define UNIGINE_IS_ALIGNED4(VALUE) (((size_t)(VALUE) & 3) == 0)
#define UNIGINE_IS_ALIGNED8(VALUE) (((size_t)(VALUE) & 7) == 0)
#define UNIGINE_IS_ALIGNED16(VALUE) (((size_t)(VALUE) & 15) == 0)
#define UNIGINE_IS_ALIGNED128(VALUE) (((size_t)(VALUE) & 127) == 0)
#define UNIGINE_ASSERT_ALIGNED4(VALUE) UNIGINE_ASSERT(UNIGINE_IS_ALIGNED4(VALUE))
#define UNIGINE_ASSERT_ALIGNED8(VALUE) UNIGINE_ASSERT(UNIGINE_IS_ALIGNED8(VALUE))
#define UNIGINE_ASSERT_ALIGNED16(VALUE) UNIGINE_ASSERT(UNIGINE_IS_ALIGNED16(VALUE))
#define UNIGINE_ASSERT_ALIGNED128(VALUE) UNIGINE_ASSERT(UNIGINE_IS_ALIGNED128(VALUE))

/*
*/
#ifdef _WIN32
#define UNIGINE_ALIGNED4(NAME) __declspec(align(4)) NAME
#define UNIGINE_ALIGNED8(NAME) __declspec(align(8)) NAME
#define UNIGINE_ALIGNED16(NAME) __declspec(align(16)) NAME
#define UNIGINE_ALIGNED128(NAME) __declspec(align(128)) NAME
#else
#define UNIGINE_ALIGNED4(NAME) NAME attribute ((aligned(4)))
#define UNIGINE_ALIGNED8(NAME) NAME attribute ((aligned(8)))
#define UNIGINE_ALIGNED16(NAME) NAME attribute ((aligned(16)))
#define UNIGINE_ALIGNED128(NAME) NAME attribute ((aligned(128)))
#endif

So i will try
infoMap.put(new Info("UNIGINE_ALIGNED4", "UNIGINE_ALIGNED8", "UNIGINE_ALIGNED16", "UNIGINE_ALIGNED128").cppTypes().annotations());

Right ?
Or is there any better solution ?

@saudet
Copy link
Member

saudet commented Jun 4, 2020

@eix128
Copy link
Author

eix128 commented Jun 4, 2020

I have tried this but same error :

    infoMap.put(new Info("UNIGINE_ALIGNED4").cppText("#define UNIGINE_ALIGNED4").cppTypes());
    infoMap.put(new Info("UNIGINE_ALIGNED8").cppText("#define UNIGINE_ALIGNED8").cppTypes());
    infoMap.put(new Info("UNIGINE_ALIGNED16").cppText("#define UNIGINE_ALIGNED16").cppTypes());
    infoMap.put(new Info("UNIGINE_ALIGNED128").cppText("#define UNIGINE_ALIGNED128").cppTypes());

Exception in thread "main" org.bytedeco.javacpp.tools.ParserException: C:\Users\Administrator\Unigine SDK Browser\sdks\community_windows_2.11.0.2\include\UnigineVector.h:1409:Unexpected token 'EOF'
at org.bytedeco.javacpp.tools.Token.expect(Token.java:112)
at org.bytedeco.javacpp.tools.Parser.template(Parser.java:499)
at org.bytedeco.javacpp.tools.Parser.declarations(Parser.java:3645)
at org.bytedeco.javacpp.tools.Parser.group(Parser.java:3120)
at org.bytedeco.javacpp.tools.Parser.declarations(Parser.java:3703)
at org.bytedeco.javacpp.tools.Parser.namespace(Parser.java:3605)
at org.bytedeco.javacpp.tools.Parser.declarations(Parser.java:3702)
at org.bytedeco.javacpp.tools.Parser.parse(Parser.java:3792)
at org.bytedeco.javacpp.tools.Parser.parse(Parser.java:3933)
at org.bytedeco.javacpp.tools.Builder.parse(Builder.java:107)
at org.bytedeco.javacpp.tools.Builder.build(Builder.java:1059)
at org.bytedeco.javacpp.tools.Builder.main(Builder.java:1361)

Do you have skype ? sorry

@eix128
Copy link
Author

eix128 commented Jun 4, 2020

The problem seems on VectorHelper class.
When i remove it from header.Error disappears.

Here is the problem class:

template<typename T>
struct VectorHelper<T, 1> {

	UNIGINE_INLINE static Type &construct(char *data, Counter pos) { return *(reinterpret_cast<Type *>(data) + pos); }
	UNIGINE_INLINE static void construct(char *data, Counter pos, const Type &v) { *(reinterpret_cast<Type *>(data) + pos) = v; }
	UNIGINE_INLINE static void construct(char *data, Counter pos, Type &&v) { *(reinterpret_cast<Type *>(data) + pos) = v; }

	template<typename ... Args>
	UNIGINE_INLINE static Type &construct_emplace(char *data, Counter pos, Args && ... args)
	{
		return *(reinterpret_cast<Type *>(data) + pos) = { std::forward<Args>(args)... };
	}

	template<typename ... Args>
	UNIGINE_INLINE static void set_emplace(char *data, Counter pos, Args && ... args)
	{
		*(reinterpret_cast<Type *>(data) + pos) = { std::forward<Args>(args)... };
	}

	UNIGINE_INLINE static Counter expand(char *data, Counter length, Counter new_length) { return new_length; }

	UNIGINE_INLINE static Counter expand(char *data, Counter length, Counter new_length, const Type &v)
	{
		for (Counter i = length; i < new_length; ++i)
			*(reinterpret_cast<Type *>(data) + i) = v;
		return new_length;
	}

	UNIGINE_INLINE static void insert(char *data, Counter pos, Counter length)
	{
		memmove(data + (pos + 1) * sizeof(Type), data + pos * sizeof(Type), (length - pos - 1) * sizeof(Type));
	}

	UNIGINE_INLINE static void copy(Type *dst, const Type *src, Counter length)
	{
		if (length)
			memcpy(dst, src, length * sizeof(Type));
	}

	UNIGINE_INLINE static void move(Type *dst, Type *src, Counter length)
	{
		if (length)
			memcpy(dst, src, length * sizeof(Type));
	}

	UNIGINE_INLINE static void shift(char *data, Counter from, Counter to)
	{
		if (to > from)
			memmove(data + from * sizeof(Type), data + (from + 1) * sizeof(Type), (to - from) * sizeof(Type));
		else
			memmove(data + (to + 1) * sizeof(Type), data + to * sizeof(Type), (from - to) * sizeof(Type));

	}
	UNIGINE_INLINE static void remove(char *data, Counter length, Counter pos, Counter size)
	{
		memmove(data + pos * sizeof(Type), data + (pos + size) * sizeof(Type), (length - pos - size) * sizeof(Type));
	}

	UNIGINE_INLINE static bool compare(char *data0,char *data1, Counter length)
	{
		return memcmp(data0, data1, length * sizeof(Type)) == 0;
	}

	UNIGINE_INLINE static void destruct(char *data, Counter length) {}
	UNIGINE_INLINE static void destructOne(char *data, Counter pos) {}
	UNIGINE_INLINE static void destruct(char *data, Counter pos, Counter size) {}
};

UNIGINE_INLINE Type &construct(char *d, Counter pos) { return VectorHelper<Type, __is_pod(Type)>::construct(d, pos); }
UNIGINE_INLINE void construct(char *d, Counter pos, const Type &v) { VectorHelper<Type, __is_pod(Type)>::construct(d, pos, v); }
UNIGINE_INLINE void construct(char *d, Counter pos, Type &&v) { VectorHelper<Type, __is_pod(Type)>::construct(d, pos, std::move(v)); }

template<typename ... Args>
UNIGINE_INLINE Type &construct_emplace(char *d, Counter pos, Args && ... args) { return VectorHelper<Type, __is_pod(Type)>::construct_emplace(d, pos, std::forward<Args>(args)...); }

template<typename ... Args>
UNIGINE_INLINE void set_emplace(char *d, Counter pos, Args && ... args) { VectorHelper<Type, __is_pod(Type)>::set_emplace(d, pos, std::forward<Args>(args)...); }

UNIGINE_INLINE Counter expand(Counter new_length) { return VectorHelper<Type, __is_pod(Type)>::expand(data, length, new_length); }
UNIGINE_INLINE Counter expand(Counter new_length, const Type &v) { return VectorHelper<Type, __is_pod(Type)>::expand(data, length, new_length, v); }

UNIGINE_INLINE void destruct() { VectorHelper<Type, __is_pod(Type)>::destruct(data, length); }
UNIGINE_INLINE void destruct(Counter pos) { VectorHelper<Type, __is_pod(Type)>::destructOne(data, pos); }
UNIGINE_INLINE void destruct(Counter pos, Counter size) { VectorHelper<Type, __is_pod(Type)>::destruct(data, pos, size); }

UNIGINE_INLINE void insert_internal(Counter pos) { VectorHelper<Type, __is_pod(Type)>::insert(data, pos, length); }
UNIGINE_INLINE void shift(Counter from, Counter to) { VectorHelper<Type, __is_pod(Type)>::shift(data, from, to); }
UNIGINE_INLINE void remove_internal(Counter pos, Counter size) { VectorHelper<Type, __is_pod(Type)>::remove(data, length, pos, size); }

UNIGINE_INLINE bool compare_internal(char *odata) const { return VectorHelper<Type, __is_pod(Type)>::compare(data, odata, length); }

UNIGINE_INLINE static void copy(Type *dst, const Type *src, Counter length) { VectorHelper<Type, __is_pod(Type)>::copy(dst, src, length); }
UNIGINE_INLINE static void move(Type *dst, Type *src, Counter length) { VectorHelper<Type, __is_pod(Type)>::move(dst, src, length); }

char *data;
Counter length;
Counter capacity;

};

@eix128
Copy link
Author

eix128 commented Jun 4, 2020

When i remove the VectorHelper class , error disappears but CPU Usage reached to %50
And project hanged on processing UnigineVector.h

D:\repo\javacpp\target>java -jar javacpp.jar NativeLibraryConfig.java Info: javac -cp javacpp.jar;D:\repo\javacpp\target NativeLibraryConfig.java Info: Targeting UnigineWrapper.java Info: Parsing C:\Users\Administrator\Unigine SDK Browser\sdks\community_windows_2.11.0.2\include\UnigineBase.h Info: Parsing C:\Users\Administrator\Unigine SDK Browser\sdks\community_windows_2.11.0.2\include\UnigineMemory.h Info: Parsing C:\Users\Administrator\Unigine SDK Browser\sdks\community_windows_2.11.0.2\include\Unigine.h Info: Parsing C:\Users\Administrator\Unigine SDK Browser\sdks\community_windows_2.11.0.2\include\UnigineApp.h Info: Parsing C:\Users\Administrator\Unigine SDK Browser\sdks\community_windows_2.11.0.2\include\UnigineVector.h

@saudet
Copy link
Member

saudet commented Jun 4, 2020

Could you try to isolate which line makes it fail?

@eix128
Copy link
Author

eix128 commented Jun 4, 2020

I got new UnigineVector.h
https://gist.github.com/eix128/4ef19375c73168dca8ad8c1f1882db43

It generated
https://gist.github.com/eix128/fe2f7ae09cc3a2d7fee56eb76559889e

The problem seems
template<typename T, int>
struct VectorHelper

I changed it to:
template< typename T >
struct VectorHelper

PATCH 2:

FROM:

template<typename T, int C, int>
struct Data { char data[C * sizeof(T)]; };

template<typename T, int C>
struct Data<T, C, 4> { UNIGINE_ALIGNED4(char) data[C * sizeof(T)]; };

template<typename T, int C>
struct Data<T, C, 8> { UNIGINE_ALIGNED8(char) data[C * sizeof(T)]; };

template<typename T, int C>
struct Data<T, C, 16> { UNIGINE_ALIGNED16(char) data[C * sizeof(T)]; };

template<typename T, int C>
struct Data<T, C, 128> { UNIGINE_ALIGNED128(char) data[C * sizeof(T)]; };



TO:



template<typename T, int C>
struct Data { char data[C * sizeof(T)]; };

template<typename T, int C>
struct Data<T, C> { char data[C * sizeof(T)]; };

template<typename T, int C>
struct Data<T, C> { char data[C * sizeof(T)]; };

template<typename T, int C>
struct Data<T, C> { char data[C * sizeof(T)]; };

template<typename T, int C>
struct Data<T, C> { char data[C * sizeof(T)]; };

This works but
But i dont see Vector class generated.
Something seems wrong.

@eix128
Copy link
Author

eix128 commented Jun 4, 2020

It would be good to make javacpp utils like modulating header files.
Seperating header implementation and prototypes.
And for finding error modulate header class files.
These utilities makes javacpp easier to port C++ projects.
More easy to find errors.

saudet added a commit to bytedeco/javacpp that referenced this issue Jun 5, 2020
@saudet
Copy link
Member

saudet commented Jun 5, 2020

The problem seems
template<typename T, int>
struct VectorHelper

Thanks! I fixed this issue in commit bytedeco/javacpp@6d84ea7.

This works but
But i dont see Vector class generated.
Something seems wrong.

You'll need create instances and give them valid names in Java:
https://github.com/bytedeco/javacpp/wiki/Mapping-Recipes#creating-instances-of-c-templates

It would be good to make javacpp utils like modulating header files.
Seperating header implementation and prototypes.
And for finding error modulate header class files.
These utilities makes javacpp easier to port C++ projects.
More easy to find errors.

I fully agree. We just need someone that has some time to work on this, see bytedeco/javacpp#51.

@eix128
Copy link
Author

eix128 commented Jun 5, 2020

Okay now , when i tried the Wrapper , I got error Unigine::SystemDialog put into generated Java code.How can i fix this kind of issues ? Why there is no filter? There is no keyword "::" in Java as we know , javacpp can replace automatically from
Unigine::SystemDialog
to
UnigineSystemDialog

also

PtrUnigine::SystemDialog
to
PtrUnigineSystemDialog

D:\repo\javacpp\target>java -jar javacpp.jar UnigineWrapper.java
Info: javac -cp javacpp.jar;D:\repo\javacpp\target UnigineWrapper.java
UnigineWrapper.java:404: error: > expected
public static native @byval PtrUnigine::SystemDialog create();
^
UnigineWrapper.java:404: error: ';' expected
public static native @byval PtrUnigine::SystemDialog create();
^
UnigineWrapper.java:404: error: illegal start of type
public static native @byval PtrUnigine::SystemDialog create();
^
UnigineWrapper.java:589: error: > expected
public static native int showSystemDialog(@const @ByRef PtrUnigine::SystemDialog dialog);
^
UnigineWrapper.java:589: error: ')' expected
public static native int showSystemDialog(@const @ByRef PtrUnigine::SystemDialog dialog);
^
UnigineWrapper.java:589: error: ';' expected
public static native int showSystemDialog(@const @ByRef PtrUnigine::SystemDialog dialog);
^
UnigineWrapper.java:589: error: expected
public static native int showSystemDialog(@const @ByRef PtrUnigine::SystemDialog dialog);
^
7 errors
Exception in thread "main" java.lang.RuntimeException: Could not compile UnigineWrapper.java: 1
at org.bytedeco.javacpp.tools.Builder.main(Builder.java:1341)

@saudet
Copy link
Member

saudet commented Jun 5, 2020

        //infoMap.put(new Info("data::Blob<float>").pointerTypes("FloatBlob"));
        //infoMap.put(new Info("UNIGINE_EXPORT").javaNames("processFloatBlob"));
        //infoMap.put(new Info("quat::RawValuesTag").javaNames("quatRawValuesTag"));

        infoMap.put(new Info("Unigine::SystemDialog").pointerTypes("UnigineSystemDialogP"));
        infoMap.put(new Info("Unigine::SystemDialog").valueTypes("UnigineSystemDialog"));
        infoMap.put(new Info("Unigine::SystemDialog").javaNames("UnigineSystemDialogK"));
        infoMap.put(new Info("Unigine::SystemDialog").javaText("UnigineSystemDialog"));
        infoMap.put(new Info("UNIGINE_INLINE", "ZEXPORT", "z_const", "zlib_version").cppTypes().annotations());

Redefining an Info like that 4 times will only end up with the last value being set. Make sure to set everything on the same line like this, if that makes sense, but it probably doesn't:

         infoMap.put(new Info("Unigine::SystemDialog").pointerTypes("UnigineSystemDialogP")
                                                      .valueTypes("UnigineSystemDialog")
                                                      .javaNames("UnigineSystemDialogK")
                                                      .javaText("UnigineSystemDialog"));

@eix128
Copy link
Author

eix128 commented Jun 5, 2020

Okay now ,
i just made like this:

public class NativeLibraryConfig implements InfoMapper {
public void map(InfoMap infoMap) {

    infoMap.put(new Info("Unigine::SystemDialog").pointerTypes("UnigineSystemDialogP")
            .valueTypes("UnigineSystemDialog")
            .javaNames("UnigineSystemDialogK")
            .javaText("UnigineSystemDialog"));
}

}

D:\repo\javacpp\target>java -jar javacpp.jar NativeLibraryConfig.java
Info: javac -cp javacpp.jar;D:\repo\javacpp\target NativeLibraryConfig.java
Info: Targeting UnigineWrapper.java
Info: Parsing C:\Users\Administrator\Unigine SDK Browser\sdks\community_windows_2.11.0.2\include\UnigineBase.h
Info: Parsing C:\Users\Administrator\Unigine SDK Browser\sdks\community_windows_2.11.0.2\include\UnigineMemory.h
Info: Parsing C:\Users\Administrator\Unigine SDK Browser\sdks\community_windows_2.11.0.2\include\Unigine.h
Info: Parsing C:\Users\Administrator\Unigine SDK Browser\sdks\community_windows_2.11.0.2\include\UnigineApp.h
Info: Parsing C:\Users\Administrator\Unigine SDK Browser\sdks\community_windows_2.11.0.2\include\UnigineVector.h

D:\repo\javacpp\target>java -jar javacpp.jar UnigineWrapper.java
Info: javac -cp javacpp.jar;D:\repo\javacpp\target UnigineWrapper.java
UnigineWrapper.java:544: error: > expected
public static native int showSystemDialog(@Const @ByRef Ptr<Unigine::SystemDialog> dialog);
^
UnigineWrapper.java:544: error: ')' expected
public static native int showSystemDialog(@Const @ByRef Ptr<Unigine::SystemDialog> dialog);
^
UnigineWrapper.java:544: error: ';' expected
public static native int showSystemDialog(@Const @ByRef Ptr<Unigine::SystemDialog> dialog);
^
UnigineWrapper.java:544: error: <identifier> expected
public static native int showSystemDialog(@Const @ByRef Ptr<Unigine::SystemDialog> dialog);
^
4 errors
Exception in thread "main" java.lang.RuntimeException: Could not compile UnigineWrapper.java: 1
at org.bytedeco.javacpp.tools.Builder.main(Builder.java:1341)

@saudet
Copy link
Member

saudet commented Jun 5, 2020

Ptr<Unigine::SystemDialog> is a template instance. You're going to need to give it a valid Java name:
https://github.com/bytedeco/javacpp/wiki/Mapping-Recipes#creating-instances-of-c-templates

@eix128
Copy link
Author

eix128 commented Jun 6, 2020

Okay now I have NativeLibrary.java
Here it is:
https://we.tl/t-qDC1Z5biE6

But , its 1MB , all classes generated into 1 file.
I want every class generation to seperate file.
So it will be modular and i will compile each module seperate for more easy fixing problems.

My NativeLibraryConfig.java :
https://gist.github.com/eix128/671d89f70c746bb073e14d3c08ce329a

@saudet
Copy link
Member

saudet commented Jun 6, 2020

Be sure to set the @Properties(global=...) value, for example, as shown here: https://github.com/bytedeco/javacpp-presets/wiki/Create-New-Presets

@eix128
Copy link
Author

eix128 commented Jun 7, 2020

Thanks it worked.
Now
generated invalid 2 methods
public class BodyWater extends Body {
...
public static native @byval PtrUnigine::BodyWater create();
public static native @byval PtrUnigine::BodyWater create(@const @ByRef PtrUnigine::Object object);
...
}

What to add to infoMap.put to fix it?

@saudet
Copy link
Member

saudet commented Jun 7, 2020

Give them valid names, see above #889 (comment)

@eix128
Copy link
Author

eix128 commented Jun 8, 2020

Nice , now
I have 3 questions :

@namespace("Unigine") @properties(inherit = org.unigine.presets.UnigineConfig.class)
public class Properties extends Pointer {
....
}

Properties class is Unigine::Properties class file
it collides with
import org.bytedeco.javacpp.annotation.Properties;

What to put to "infomap.put" rename class name from Properties to UnigineProperties ?

i put
infoMap.put(new Info("Unigine::Property").javaNames("UnigineProperty"));
but it didnt work

I got

public class APIInterface extends Pointer {
...
public native int isNull();
...
}

public native int isNull();
collides with org.bytedeco.javacpp.Pointer isNull method
How to remove colllision ?

i dont know how to fix method collision with javacpp and unigine

org.unigine.Node class

public native @ByVal vec3 getDirection(@ByVal(nullValue = "MathLib::AXIS(Unigine::Math::AXIS_NZ)") AXIS axis);

AXIS is undefined.
I have looked at it.Its enum type

I tried
infoMap.put(new Info("AXIS").javaNames("int"));

But this also didnt work.

in C++ side AXIS is defined in
UnigineMathLib.h

enum AXIS
{
AXIS_X = 0, // positive axes
AXIS_Y,
AXIS_Z,
AXIS_NX, // negative axes
AXIS_NY,
AXIS_NZ,
};

But JavaCPP cant get enum type

Thanks

@saudet
Copy link
Member

saudet commented Jun 8, 2020

@saudet
Copy link
Member

saudet commented Jun 14, 2020

To rename methods, we can use Info.javaNames, like this:
https://github.com/bytedeco/javacpp/wiki/Mapping-Recipes#specifying-names-to-use-in-java

You'll need to include "UnigineMathLib.h" in the @Platform(include=... list explicitly for JavaCPP to pick it up. But it's also possible to set it with Info.valueTypes, like this: https://github.com/bytedeco/javacpp/blob/master/src/main/java/org/bytedeco/javacpp/tools/InfoMap.java#L68

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants