Giter Site home page Giter Site logo

jawaff / ents Goto Github PK

View Code? Open in Web Editor NEW

This project forked from clickermonkey/ents

0.0 2.0 0.0 8.22 MB

A hybrid of the Entity-Component-System and Model-View-Controller patterns with new concepts developed specifically for games. Ents is easy to integrate into your game, is developed to be decoupled from a graphics library, and is very memory conscious compared to similar frameworks.

License: Open Software License 3.0

Java 100.00%

ents's Introduction

Ents for Java

Stable

Build

Complete Examples (+walkthroughs)

Simple Example

Component<Vector> POSITION = Ents.newComponent( "position", new Vector() );
Component<Vector> VELOCITY = Ents.newComponent( "velocity", new Vector() );

Controller PHYSICS = Ents.newController( "physics", new Control() {
  public void update( Entity e, Object updateState ) {
      float dt = (Float)updateState;
      Vector pos = e.get( POSITION );
      Vector vel = e.get( VELOCITY );
      pos.add( vel, dt );
  }
});

Template SPRITE = Ents.newTemplate( "sprite", new ComponentSet( POSITION, VELOCITY ), new ControllerSet( PHYSICS ) );

Entity e = new Entity( SPRITE );
e.get( POSITION ).set( 1.0f, 3.0f );
e.get( VELOCITY ).set( 0.0f, -6.0f );
e.update( 0.5f );

...

Component<Vector> ACCELERATION = Ents.newComponent( "acceleration", new Vector() );

Controller PHYSICS_ACCELERATION = Ents.newControllerAlternative( PHYSICS, new Control() {
  public void update( Entity e, Object updateState ) {
      float dt = (Float)updateState;
      Vector pos = e.get( POSITION );
      Vector vel = e.get( VELOCITY );
      Vector acc = e.get( ACCELERATION );
      vel.add( acc, dt );
      pos.add( vel, dt );
  }
});

...

e.put( ACCELERATION, new Vector (0.0f, -10.0f ) );
e.add( PHYSICS_ACCELERATION ); // overwrite existing PHYSICS controller with this alternative

assert e.has( PHYSICS );

e.update( 0.5f );

Entity-Component Methods

e.has( POSITION ); // returns true or false depending on whether the Entity has that component
e.get( POSITION ); // gets the value of the component. this assumes the Entity has the component, this is the fastest method for retrieving a component value
e.gets( POSITION ); // gets the value of the component safely, returning null of the Entity doesn't have the component
e.gets( POSITION, ZERO ); // gets the value of the component safely, returning ZERO (or whatever is passed in) if the component is missing
e.set( POSITION, pos ); // sets the value of the component. this assumes the Entity has the component, this is the fastest method for setting a component value
e.sets( POSITION, pos ); // sets the value of the component safely, if the Entity doesn't have the component then this will have no affect and false will be returned.
e.take( POSITION, out ); // sets out to the value of the component in this Entity, this assumes the Entity has the component
e.takes( POSITION, out ); // safely takes the component value and sets it to out and returns out, or returns null of the component doesn't exist
e.add( POSITION ); // adds the given component to the Entity if it doesn't have it already
e.add( POSITION, defaultValue ); // adds the given component to the Entity and then calls set directly afterward
e.put( POSITION, forcedValue ); // sets the component value, adding the component if it doesn't exist already
e.grab( POSITION ); // grabs the component value, adding the component if it doesn't exist

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.