Skip to content

Instantly share code, notes, and snippets.

@amirrajan
Last active May 26, 2021 01:39
Show Gist options
  • Save amirrajan/1c174462f25d0c28ad2b3ff7d32a58cf to your computer and use it in GitHub Desktop.
Save amirrajan/1c174462f25d0c28ad2b3ff7d32a58cf to your computer and use it in GitHub Desktop.
ECS comparison between Java and DragonRuby
// main.java
package my.game;
import com.artemis.*;
import my.game.components.Hello;
import my.game.systems.HelloWorldSystem;
public class GameLauncher {
public static void main( String[] args ) {
WorldConfiguration setup = new WorldConfigurationBuilder()
.with(new HelloWorldSystem())
.build();
World world = new World(setup);
int entityId = world.create();
world.edit(entityId).create(Hello.class).message = "\n\rHello world!\n\r";
world.process();
}
}
//systems/HelloWorldSystem.java
package my.game.systems;
import com.artemis.ComponentMapper;
import com.artemis.annotations.All;
import com.artemis.systems.IteratingSystem;
import my.game.components.Hello;
@All(Hello.class)
public class HelloWorldSystem extends IteratingSystem {
protected ComponentMapper<Hello> mHello;
@Override
protected void process(int id) {
System.out.print(mHello.get(id).message);
}
}
//components/Hello.java
package my.game.components;
import com.artemis.Component;
public class Hello extends Component {
public String message;
public void set(String message) {
this.message = message;
}
}
def tick args
args.state
.entities
.player ||= args.state
.new_entity(:player) do |entity|
entity.message = "Hello world"
entity.systems = [:hello_world_system]
end
args.state.entities.as_hash.each do |name, entity|
tick_hello_world_system entity
end
end
def tick_hello_world_system entity
return unless entity.systems.include? :hello_world_system
puts "#{entity.message}"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment