https://github.com/juan-medina/kecs
Kontlin Entity component system
https://github.com/juan-medina/kecs
Last synced: 3 months ago
JSON representation
Kontlin Entity component system
- Host: GitHub
- URL: https://github.com/juan-medina/kecs
- Owner: juan-medina
- License: apache-2.0
- Created: 2020-08-01T15:03:39.000Z (almost 5 years ago)
- Default Branch: main
- Last Pushed: 2020-08-12T15:57:31.000Z (almost 5 years ago)
- Last Synced: 2025-01-12T23:12:21.125Z (5 months ago)
- Language: Kotlin
- Size: 1.25 MB
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# Kotlin Entity Component System
Kotlin Cross-platform Entity Component System
[](/LICENSE)
[](https://juan-medina.github.io/kecs/)
[](https://bintray.com/juan-medina/kecs/kecs/_latestVersion)
[](https://juan-medina.github.io/kecs/playground/)## Platforms




## Info
KECS is a Cross-platform Entity Component System design to create concurrent applications, such games,
more simple and without the need of using multiple threads neither fibers nor corutines.It allows separating data from behavior and get rid of deep object oriented inheritance.
Due to data-oriented design allow modern processors to highly optimize it for an over perform of more traditional
systems.If you like to learn more about what is an ECS we try to give some clarification on [this section](https://juan-medina.github.io/kecs/ecs/).
## Installation
Currently, KECS is available in jcenter, first we need to add the repositories,
if we do not have them.### Add jcenter to gradle
```groovy
repositories {
jcenter()
}
```### Add jcenter to maven
```xml
jcenter
bintray
https://jcenter.bintray.com
```
This will install the multi-platform module for all the platforms in your system.
### Multi-platform Gradle project
If you are creating a multi-platform project you need to add to the platforms that you need
```groovy
kotlin {
sourceSets {
jvmMain {
dependencies {
implementation kotlin('stdlib-common')
implementation 'com.juanmedina:kecs-jvm:1.0.2'
}
}
linuxMain {
dependencies {
implementation 'com.juanmedina:kecs-linux:1.0.2'
}
}
mingwMain {
dependencies {
implementation 'com.juanmedina:kecs-mingw:1.0.2'
}
}
}
}
```### Single-platform Gradle project
For just adding as dependency for a simple platform you could do this in gradle:
```groovy
dependencies {
implementation 'com.juanmedina:kecs-jvm:1.0.2'
}
```### Single-platform Maven project
If you use maven you need to include the dependencies of the platforms that you target:
```xmlcom.juanmedina
kecs-jvm
1.0.2```
## Basic Usage
This is a basic example, check the [user guide](https://juan-medina.github.io/kecs/guide/), the [advance example](https://juan-medina.github.io/kecs/example/), or the [API Documentation](https://juan-medina.github.io/kecs/packages/-k-e-c-s/)
for learning more about using KECS or try the [Playground](https://juan-medina.github.io/kecs/playground/) for practical experimentation.```Kotlin
data class Velocity(val x: Float, val y: Float)data class Position(var x: Float, var y: Float) {
operator fun plusAssign(velocity: Velocity) {
x += velocity.x
y += velocity.y
}
}class MoveSystem : System() {
override fun update(delta: Float, total: Float, world: World) {
world.pairs { (vel, pos) ->
pos += vel
}
}
}fun example() {
val world = world {
+MoveSystem()
}val ent1 = world.add {
+Position(0.0f, 0.0f)
+Velocity(1.0f, 2.0f)
}val ent2 = world.add {
+Position(0.0f, 0.0f)
+Velocity(1.5f, 2.5f)
}val ent3 = world.add {
+Position(0.0f, 0.0f)
}while(...) {
world.update()
}
}
```## License
```text
Copyright (C) 2020 Juan MedinaLicensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License athttp://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
```