-
Notifications
You must be signed in to change notification settings - Fork 36
Integrate Fleks ECS into korge + example #472
Conversation
Instantiation of generic classes is not possible in Kotlin multiplatform. Thus, instead of instantiating a generic class in the SystemService the system function gets a factory method for calling the constructor of the system.
First version which works.
The component listener will be added together with registering the component in the world configuration. That was done because when registering the component listener the base type of the component is needed. Without reflections that is not possible to detect it from the component listener template type. Thus, adding component and listener objects together is the most elegant workaround - I guess.
The spawner should be able to spawn objects which can spawn objects themselves. This is needed for the meteor object. It spawns fire trails.
- It is now possible to spawn objects which themselves spawn another objects. - Added variation of acceleration which makes the animation of the file trails looking more dynamic.
In case of injection of multiple dependencies with the same type it is now possible to specify the type name on injection to the world configuration. When passing that dependency in a system or component listener than the type name can be given as an argument to Inject.dependency() function call. Updated the readme to reflect that injection of dependencies is possible by providing an optional type name as parameter together with the depencency object.
Rigidbody and destruct components were added which are use to control movement and destruction of entities. For that a new system called DestructSystem was added. With it the destruction of an entity can triger creation of new objects like explosions, etc. Rigidbody component details will control how an entity is influenced by gravity, friction or damping. This still needs to be implemented yet in the MoveSystem.
Source code for Fleks ECS was moved under korge-fleks to decouple it from the example code. Updated fleks-ecs example code with source comments.
😲 Awesome! I'll check in detail later this week, since this is pretty big! In the mean time, CI seems to be broken somehow: Maybe it is using junit 5, while the korlibs are using kotlin/test with junit 4? |
@soywiz I am using Kotlin test 1.6.0 dependency with the useJUnitPlatform configuration as seen in the build.gradle file: https://github.com/Quillraven/Fleks/blob/master/build.gradle.kts I personally have no preference about which testing framework is used. So it can be changed to whatever is compatible with KorGE but do you know which adjustments need to be done in the Gradle file? Also, I have almost no experience with KMP and I think @jobe-m has little Gradle experience. Do you know someone who could help with setting up the build file properly and the sourcesets to correctly publish it to maven? I already commented it in the KMP issue of the repository but at the moment I have little time to get more familiar with the KMP specifics :( |
Thanks for already taking a look at my PR guys :) |
I fixed some issues in the module tests. But it looks that there are still exceptions when running the tests for Kotlin native. I guess the problem is on the code side. Not in the unit tests. Because when I try to compile and run the fleks example on Kotlin native than running the kexe crashes. EDIT: Ok, I guess, I found it. The problem is with the Inject singleton object which is immutable on Kotlin native when not defined as ThreadLocal. So, looks I will need to rewrite the injection a bit again ;-) |
@jobe-m for InvalidMutability exception, you have to mark global variables with |
if (other == null) return false | ||
if (this === other) return true | ||
|
||
other as BitArray |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will fail instead of returning false, in the case other
is from another type, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will check :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Really nice!
BTW. Is the PR ready to merge, or something is missing? (it is still in draft)
Could you move the ImageAnimation.Direction.ONCE_*
functionality to another PR?
So in the next release appears as new functionality not tied only to fleks?
Yes, good idea. I will do it, too. EDIT: Created another PR #488 |
The equal function of BitArray was unsafe regarding comparing objects of different type. Added unit tests to avoid regression.
YES :) |
korge-fleks/src/commonMain/kotlin/com/github/quillraven/fleks/collection/bitArray.kt
Outdated
Show resolved
Hide resolved
88eb177
to
1aaa952
Compare
@soywiz the PR should be now ready to merge :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! 🚀
Wow, finally it's ready and usable from Korge. Thanks to @Quillraven for creating Fleks and sharing it with us all :) |
Yeah +1. Thanks @Quillraven & thanks @jobe-m ! |
Just triggered 2.6.3 with this: https://github.com/korlibs/korge-next/releases/tag/v2.6.3 |
That's really cool, thanks guys! @jobe-m can you please create another PR for Fleks with the important changes? I think I will make a "next" branch for the next version that combines KMP and the JVM version. We can put your changes then already in this branch for now. |
This PR integrates the Entity Component System Fleks as a sub-"module" korge-fleks into the Korge landscape. I have choosen that way because currently it is not possible to add Fleks as an (external) import to the example code.
The Fleks repo (https://github.com/Quillraven/Fleks) contains a branch "kmp" which in principle contains the same code as under "korge-fleks" in this PR. The kmp branch was pushed by me into Fleks. It contains all necessary changes to get the Fleks codebase usable with Korge (and Kotlin multiplatform in general - I guess). But Fleks is currently exported in a "multiplatform" incompatible way to maven and therefore it can not yet be used in a Korge project.
The Fleks repo and also "Korge-fleks" contains unit tests which were also adapted to the changes for mulitplatform.
The added example "fleks-ecs" shows the ECS system in action :) It creates a lot of objects which are drawn out from one sprite animation. I hope that it shows how to use Fleks in a game. When I have time I will update the example sources with more comments and descriptions. Maybe we can also create a section for Fleks on the Korge documentation pages.
Currently I only have one problem. It looks like that the sources from korge-fleks are not exported properly to maven-local. Thus I cannot use Fleks in my own game project. Maybe there is some configuration in gradle missing which would properly export Fleks from Korge-fleks into maven so that it can be used in stand alone projects by just adding Korge as a dependency.This is fixed.Also I don't know if you want to keep Fleks as part of Korge for long time or if you would like to have it externalized (in its own origin git repo from Quillraven). The benefit of having Fleks in Korge would be that we could adapt, optimize and integrate it further to be a companion to Korge. E.g. writing Systems which are integrated into Korges animation/image views, etc. So that anybody who wants to use the ECS with Korge do not need to write an "Animation" or "Sprite system" by its own.