hannomalie / hpengine

MIT License
0 stars 0 forks source link

How to run the samples #3

Closed ThanosFisherman closed 11 months ago

ThanosFisherman commented 1 year ago

Hello,

I've been trying to run the demos from your engine (or even build the project itself) such as e.g the OceanDemo.kt but I get an error during compilation related to your other library struktgen

e: [ksp] java.lang.NullPointerException
    at de.hanno.strukt.generate.StruktGeneratorKt.isStrukt(StruktGenerator.kt:15)
    at de.hanno.strukt.generate.StruktGeneratorKt.access$isStrukt(StruktGenerator.kt:1)
    at de.hanno.strukt.generate.StruktGenerator$FindPropertiesVisitor.visitClassDeclaration(StruktGenerator.kt:255)
    at de.hanno.strukt.generate.StruktGenerator$FindPropertiesVisitor.visitClassDeclaration(StruktGenerator.kt:252)
    at com.google.devtools.ksp.symbol.impl.kotlin.KSClassDeclarationImpl.accept(KSClassDeclarationImpl.kt:136)
    at de.hanno.strukt.generate.StruktGenerator$FindPropertiesVisitor.visitFile(StruktGenerator.kt:261)
    at de.hanno.strukt.generate.StruktGenerator$FindPropertiesVisitor.visitFile(StruktGenerator.kt:252)
    at com.google.devtools.ksp.symbol.impl.kotlin.KSFileImpl.accept(KSFileImpl.kt:61)
    at de.hanno.strukt.generate.StruktGenerator.process(StruktGenerator.kt:44)
    at com.google.devtools.ksp.AbstractKotlinSymbolProcessingExtension$doAnalysis$6$1.invoke(KotlinSymbolProcessingExtension.kt:287)
    at com.google.devtools.ksp.AbstractKotlinSymbolProcessingExtension$doAnalysis$6$1.invoke(KotlinSymbolProcessingExtension.kt:285)
    at com.google.devtools.ksp.AbstractKotlinSymbolProcessingExtension.handleException(KotlinSymbolProcessingExtension.kt:390)
    at com.google.devtools.ksp.AbstractKotlinSymbolProcessingExtension.doAnalysis(KotlinSymbolProcessingExtension.kt:285)
    at org.jetbrains.kotlin.cli.jvm.compiler.TopDownAnalyzerFacadeForJVM.analyzeFilesWithJavaIntegration(TopDownAnalyzerFacadeForJVM.kt:124)
    at org.jetbrains.kotlin.cli.jvm.compiler.TopDownAnalyzerFacadeForJVM.analyzeFilesWithJavaIntegration$default(TopDownAnalyzerFacadeForJVM.kt:100)
    at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler$analyze$1.invoke(KotlinToJVMBytecodeCompiler.kt:265)
    at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler$analyze$1.invoke(KotlinToJVMBytecodeCompiler.kt:53)
    at org.jetbrains.kotlin.cli.common.messages.AnalyzerWithCompilerReport.analyzeAndReport(AnalyzerWithCompilerReport.kt:115)
    at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler.analyze(KotlinToJVMBytecodeCompiler.kt:256)
    at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler.compileModules$cli(KotlinToJVMBytecodeCompiler.kt:99)
    at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler.compileModules$cli$default(KotlinToJVMBytecodeCompiler.kt:58)
    at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.doExecute(K2JVMCompiler.kt:158)
    at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.doExecute(K2JVMCompiler.kt:53)
    at org.jetbrains.kotlin.cli.common.CLICompiler.execImpl(CLICompiler.kt:99)
    at org.jetbrains.kotlin.cli.common.CLICompiler.execImpl(CLICompiler.kt:47)
    at org.jetbrains.kotlin.cli.common.CLITool.exec(CLITool.kt:101)
    at org.jetbrains.kotlin.daemon.CompileServiceImpl.compile(CompileServiceImpl.kt:1645)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:357)
    at sun.rmi.transport.Transport$1.run(Transport.java:200)
    at sun.rmi.transport.Transport$1.run(Transport.java:197)
    at java.security.AccessController.doPrivileged(Native Method)
    at sun.rmi.transport.Transport.serviceCall(Transport.java:196)
    at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:573)
    at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:834)
    at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.lambda$run$0(TCPTransport.java:688)
    at java.security.AccessController.doPrivileged(Native Method)
    at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:687)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    at java.lang.Thread.run(Thread.java:750)

e: Error occurred in KSP, check log for detail

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':api:kspKotlin'.
> A failure occurred while executing org.jetbrains.kotlin.compilerRunner.GradleCompilerRunnerWithWorkers$GradleKotlinCompilerWorkAction
   > Compilation error. See log for more details

I'm most likely missing something but I don't know what

hannomalie commented 11 months ago

Oh big sorry for letting you wait sooo much! And thank you for your interest in my project, I didn't expect that at all :)

Sadly, I have very little time currently and the project is somewhat unstable. I am reshuffeling a loooooot of things that just got too bad over time.

I just use a composite build "includeBuild("../StruktGen")" in settings.gradle.kts and the version of StruktGen I am using is the branch "context-receivers" (https://github.com/hannomalie/StruktGen/tree/context-receivers)

So I guess you can just clone both projects in the same folder, check out the said branch and it should work (tm)

let me know if you have any trouble. and let me also know when you have any questions, want to have a chat, need help yourself, want me to maybe look at sth interesting you did etc :)

ThanosFisherman commented 11 months ago

No worries, thanks for getting back to me :) I just wanted to take a look as I recently jumped into the world of game dev.

I first came across your github because of your original structs on kotlin project which made a big impression on me as I was looking for something similar at that time.

I tried once again to clone your new StruktGen from the "context-receivers" branch as you suggested as well as this project itself. I opened hpengine on intellij but unfortunately now I got a different error while trying to build it. It originates again from StruktGen.

/home/thanos/IntellijProjects/StruktGen/api/build/libs/api-1.0.0-SNAPSHOT.jar!/META-INF/api.kotlin_module: Module was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.9.0, expected version is 1.7.1.

I tried several things such as changing the kotlin version but I had no luck.

hannomalie commented 11 months ago

Yeah, I am sorry that the experience is so horrible currently. I took some time to cleanup the whole build today and updated the readme, which was years outdated.

Try to use the latest master branch - everything should be working ootb now, dependencies from jitpack, no included builds etc. When you open it in IntelliJ, remember to do "New project -> Project from existing sources" and then import from the gradle model. Let me know when that now still doesn't work please :)

And thanks for the feedback on the good old structs library, much appreciated :) Did you find something similar in the meantime maybe from someone else? I did a second try on that topic, which is StruktGen. Performance is much better, ergonomics not so much. I will try to update structs (the old one) to the foreign memory api that is currently in preview as of java 21.

ThanosFisherman commented 11 months ago

The project builds fine now however when I try to run let's say the OceanDemoKt I it crashes with an error

Exception in thread "main" org.koin.core.error.InstanceCreationException: Could not create instance for [Singleton:'de.hanno.hpengine.physics.PhysicsManager',binds:com.artemis.BaseSystem,de.hanno.hpengine.graphics.RenderSystem,de.hanno.hpengine.physics.PhysicsManager]
    at org.koin.core.instance.InstanceFactory.create(InstanceFactory.kt:60)
    at org.koin.core.instance.SingleInstanceFactory.create(SingleInstanceFactory.kt:46)
    at org.koin.core.instance.SingleInstanceFactory$get$1.invoke(SingleInstanceFactory.kt:53)
    at org.koin.core.instance.SingleInstanceFactory$get$1.invoke(SingleInstanceFactory.kt:51)
    at org.koin.mp.KoinPlatformTools.synchronized(PlatformToolsJVM.kt:20)
    at org.koin.core.instance.SingleInstanceFactory.get(SingleInstanceFactory.kt:51)
    at org.koin.core.registry.InstanceRegistry.getAll$koin_core(InstanceRegistry.kt:137)
    at org.koin.core.scope.Scope.getAll(Scope.kt:330)
    at EngineFromKoinKt.invoke(EngineFromKoin.kt:70)
    at scenes.OceanDemoKt.main(OceanDemo.kt:44)
    at scenes.OceanDemoKt.main(OceanDemo.kt)
Caused by: org.koin.core.error.InstanceCreationException: Could not create instance for [Singleton:'de.hanno.hpengine.graphics.shader.OpenGlProgramManager',binds:de.hanno.hpengine.graphics.shader.ProgramManager,de.hanno.hpengine.graphics.shader.OpenGlProgramManager,com.artemis.BaseSystem]
    at org.koin.core.instance.InstanceFactory.create(InstanceFactory.kt:60)
    at org.koin.core.instance.SingleInstanceFactory.create(SingleInstanceFactory.kt:46)
    at org.koin.core.instance.SingleInstanceFactory$get$1.invoke(SingleInstanceFactory.kt:53)
    at org.koin.core.instance.SingleInstanceFactory$get$1.invoke(SingleInstanceFactory.kt:51)
    at org.koin.mp.KoinPlatformTools.synchronized(PlatformToolsJVM.kt:20)
    at org.koin.core.instance.SingleInstanceFactory.get(SingleInstanceFactory.kt:51)
    at org.koin.core.registry.InstanceRegistry.resolveInstance$koin_core(InstanceRegistry.kt:94)
    at org.koin.core.scope.Scope.resolveValue(Scope.kt:223)
    at org.koin.core.scope.Scope.resolveInstance(Scope.kt:211)
    at org.koin.core.scope.Scope.get(Scope.kt:193)
    at org.koin.ksp.generated.DefaultKt$defaultModule$1$13.invoke(Default.kt:37)
    at org.koin.ksp.generated.DefaultKt$defaultModule$1$13.invoke(Default.kt:21)
    at org.koin.core.instance.InstanceFactory.create(InstanceFactory.kt:53)
    ... 10 more
Caused by: java.lang.IllegalArgumentException: Cannot load file /tmp/hpengine/12823679225605373550/D:\workspace\hpengine\engine\src\main\resources\hp/shaders/heightmapping_vertex.glsl as it doesn't exist
    at de.hanno.hpengine.ressources.FileBasedCodeSource.<init>(CodeSource.kt:14)
    at de.hanno.hpengine.graphics.shader.OpenGlProgramManagerKt.getVertexShaderSource(OpenGlProgramManager.kt:130)
    at de.hanno.hpengine.graphics.shader.OpenGlProgramManagerKt.getFirstPassHeightMappingProgramDescription(OpenGlProgramManager.kt:120)
    at de.hanno.hpengine.graphics.shader.OpenGlProgramManagerKt.access$getFirstPassHeightMappingProgramDescription(OpenGlProgramManager.kt:1)
    at de.hanno.hpengine.graphics.shader.OpenGlProgramManager.<init>(OpenGlProgramManager.kt:39)
    at de.hanno.hpengine.opengl.OpenGLModule.openglProgramManager(OpenGLModule.kt:46)
    at org.koin.ksp.generated.OpenGLModuleGende_hanno_hpengine_openglKt$de_hanno_hpengine_opengl_OpenGLModule$1$4.invoke(OpenGLModuleGende$hanno$hpengine$opengl.kt:12)
    at org.koin.ksp.generated.OpenGLModuleGende_hanno_hpengine_openglKt$de_hanno_hpengine_opengl_OpenGLModule$1$4.invoke(OpenGLModuleGende$hanno$hpengine$opengl.kt:12)
    at org.koin.core.instance.InstanceFactory.create(InstanceFactory.kt:53)
    ... 22 more

I guess this is something related to dependency injection but since there's a lot of stuff in there I don't understand, I don't think I'm gonna be able to fix it on my own. Moreover I don't want to put a pressure on you since your time is limited. I'll keep an eye on this repo and meanwhile try to understand a few things in the code here and there :)

Regarding the structs no I didn't find anything similar from someone else. Only some people trying to achieve the same result using Unsafe but the idea with property delegates is really cool :)

Regards.

hannomalie commented 11 months ago

Oh, yes, I fear nobody else than me is able to understand the code yet, I really have a lot of work left to make it somewhat digestable by other people. You also don't put pressure on me, I appreciate your interest and benefit a lot from your input, as it shows me where i have to invest time. I personally hate when projects are complicated to set up - accessability on all levels is key to make good things.

In this case, not the dependency injection stuff is responsible for the error, but the fact that I didn't have a way to pass in configuration optionally into the program, which is why I temporarily hardcoded absolute paths to folders everywhere (shame on me). That's why it tries to load a file "/tmp/hpengine/12823679225605373550/D:\workspace\hpengine\engine\src\main\resources\hp/shaders/heightmapping_vertex.glsl as it doesn't exist at de.hanno.hpengine.ressources.FileBasedCodeSource.(CodeSource.kt:14)" which is of course silly.

If you would give the latest master another try, we could hope for the best, worked for me now, without any config, just hitting the run gutter icon in Ocean.kt

ThanosFisherman commented 11 months ago

Hey Hannes,

So I pull the latest changes from master and tried to run the samples from scenes package once again.

I still got errors about invalid paths

Caused by: java.lang.IllegalArgumentException: Cannot load file /tmp/hpengine/9800792674634211443/D:\workspace\hpengine\engine\src\main\resources\hp/shaders/heightmapping_vertex.glsl as it doesn't exist

This time I tried to fix those paths and make them point to the project resources dir. When I tried to run it again I then got an error from ImGui

Caused by: java.lang.UnsatisfiedLinkError: no imgui-java64 in java.library.path: /usr/java/packages/lib:/usr/lib64:/lib64:/lib:/usr/lib

Which I don't understand why imgui looks for native libs inside these folders. I'd expect it to look them up inside the project dir

Still no luck

hannomalie commented 11 months ago

Yeah i currently don't have a linux machine and not setup github actions to compensate for that with tests:)

My imgui usage is probably not os aware, i try to fix that later. Thanks for going through this with me! I will keep you updated.

hannomalie commented 11 months ago

Sooo... I forgot to actually push the latest changes yesterday :)

Now the path issues should be a thing of the past, as well as the imgui thing, I removed the ages old TODO to make the imgui natives selection os aware :)

Aaaaand another try, if you don't mind.

ThanosFisherman commented 11 months ago

Yay finally it works now. I was able to run the Ocean demo! I also ran the sponza but I didn't see anything there although it seems to run just fine!

hannomalie commented 11 months ago

Yaaaaay

Yeah there might still be an issue when you don't pass in those two directory paths, maybe the sponza scene causes issues because of its size, i noticed that as well, but thanks for the hint.

Now when you select the ocean component in the scene tree you can Play a bit with the parameters, but i think its a bit hard to control often Times.

On the skybox Material you can select different Environment Maps, there should be some preloaded ones.

Now all that effort for a mediocre demo yikes xD