Feel free to join the next Helmholtz Hacky Hour #26 on Wednesday, April 21, 2021 from 2PM to 3PM!

Commit 411cfec3 authored by Martin Lange's avatar Martin Lange

Merge branch 'feature/setup-yarner-project' into 'master'

Set up a Yarner project

See merge request !1
parents 8d1bdc89 c5536242
Pipeline #11976 passed with stage
in 1 minute and 22 seconds
image: rust
before_script:
- export CARGO_HOME="$CI_PROJECT_DIR/cargo"
- export PATH="$CARGO_HOME/bin:$PATH"
- cargo install --git https://github.com/mlange-42/yarner.git yarner --features bin
build:
script:
- yarner
artifacts:
paths:
- code/
- docs/
# ECS Tutorial with Java and Artemis-odb
This projects demonstrates the use of an Entity-Component-System for the implementation of an individual-based model (IBM). We use Java and the ECS library [Artemis-odb](https://github.com/junkdog/artemis-odb) to build a simple model.
## Components
```java
/// file:src/main/java/ecs_tutorial/Position.java
package ecs_tutorial;
import com.artemis.*;
public class Position extends Component {
int x;
int y;
}
```
## Resources
```java
/// file:src/main/java/ecs_tutorial/Randomness.java
package ecs_tutorial;
import java.util.Random;
public class Randomness {
final Random rng;
public Randomness(long seed) {
rng = new Random(seed);
}
}
```
## Systems
```java
/// file:src/main/java/ecs_tutorial/RandomWalkSystem.java
package ecs_tutorial;
import com.artemis.ComponentMapper;
import com.artemis.annotations.All;
import com.artemis.annotations.Wire;
import com.artemis.systems.IteratingSystem;
@All(Position.class)
public class RandomWalkSystem extends IteratingSystem {
protected ComponentMapper<Position> mPosition;
@Wire
Randomness randomness;
@Override
protected void process(int id) {
var pos = mPosition.get(id);
pos.x += randomness.rng.nextInt(3) - 1;
pos.y += randomness.rng.nextInt(3) - 1;
System.out.println(pos.x+" "+pos.y);
}
}
```
## Putting it together
```java
/// file:src/main/java/ecs_tutorial/Main.java
package ecs_tutorial;
import com.artemis.*;
public class Main {
public static void main(String[] args) {
WorldConfiguration setup = new WorldConfigurationBuilder()
.with(new RandomWalkSystem())
.build()
.register(new Randomness(0));
var world = new World(setup);
int entityId = world.create();
world.edit(entityId).create(Position.class);
for (int i=0; i < 10; i++) {
world.process();
}
}
}
```
## Appendix
### Dependencies with Gradle
```groovy
/// file:build.gradle
apply plugin: 'application'
sourceCompatibility = 11
targetCompatibility = 11
repositories {
mavenCentral()
}
dependencies {
implementation group: 'net.onedaybeard.artemis', name: 'artemis-odb', version: '2.3.0'
}
application {
mainClassName = 'ecs_tutorial.Main'
}
```
```groovy
/// file:settings.gradle
rootProject.name = 'ECS-Tutorial'
```
### Git ignore file
```
/// file:.gitignore
.gradle
build
```
[md]
# The sequence that identifies the start and end of a fenced code block
fence_sequence = "```"
# Alternative sequence that identifies the start and end of a fenced code block.
# Allows for normal Markdown fences in code blocks
fence_sequence_alt = "~~~"
# The sequence that separates the language from the name of the code block after the fence
block_name_start = " - "
# Parsed comments are stripped from the code and written to an `<aside></aside>` block after the code when printing.
# If false, the comments are just written back into the code.
comments_as_aside = false
# The sequence to identify a comment which should be omitted from the compiled code,
# and may be rendered as an `<aside>` if `comments_as_aside` is set.
comment_start = "///"
# The sequence to identify the start of a meta variable interpolation.
interpolation_start = "@{"
# The sequence to identify the end of a meta variable interpolation.
interpolation_end = "}"
# The sequence to identify the start of a macro invocation.
macro_start = "// ==> "
# The sequence to identify the end of a macro invocation.
macro_end = "."
# The sequence to identify the start of a transclusion.
transclusion_start = "@{{"
# The sequence to identify the end of a transclusion.
transclusion_end = "}}"
# The sequence to split variables into name and value.
variable_sep = ":"
# Prefix for file-specific entry points.
file_prefix = "file:"
# Name prefix for code blocks not shown in the docs.
hidden_prefix = "hidden:"
## The language to set if there was no automatically detected language. Optional.
# default_language = "java"
[paths]
# Code output path.
code = "code/"
# Docs output path.
docs = "docs/"
# The input source file(s) as glob pattern(s).
files = ["README.md"]
## File(s) to include in code output (unprocessed), as glob pattern(s).
# code_files = ["**/*.java"]
## File(s) to include in docs output (unprocessed), as glob pattern(s).
# doc_files = ["**/*.png", "**/*.jpg"]
## Entrypoint block name. Optional. If not supplied, unnamed code blocks are used.
entrypoint = "Main"
## Language-sprcific settings. Optional. Required for reverse mode.
## The language is determined by the extension of code output files.
## Example language settings for Rust:
# [language.java]
## Start of comments. Can be start of line or block comments.
# comment_start = "//"
### End of comments. Optional, only for block comments
## comment_end = "*/"
## Start of block labels.
# block_start = "<@"
## End of block labels.
# block_end = "@>"
## Replaces lines containing only whitespaces by blank lines, in code output. Defaults to true.
# clear_blank_lines = true
## Enforces code files to always end with a blank line. Defaults to true.
# eof_newline = true
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment