Saturday, August 13, 2011

Component system for haXe (Macros pt.2)

Put together an experimental component system (Style is closer to that of an Entity System) for haXe over the last few days. I've had the idea for a while now, but never found a way to implement it. Once again, haXe macros save the day. The goal is to maintain the flexibility of a component system, while reducing the performance loss of messaging and component communication.

I'm a bit limited on time today, so no detailed post. Just a bit of code and a demo.

Demo:


The main application code:

Components:

Systems:

4 comments:

  1. EACH(identifier,{...block...}) is responsible for delegating entities to the system. It will loop through all the entities that contain components you access within the code block.

    [handle].[component].[property]
    entity.CVelocity.vy

    The GravitySystem for example is delegated all entities containing CVelocity.

    HAS functions much like an if statement, but causes no branching, and no conditionals.
    HAS([Component],{..true..},{..false..})

    ReplyDelete
  2. Looks somewhat similar to my Composure library (https://github.com/TomByrne/composure-hx).

    I love the implicit way everything is bound together.

    Do the Entities add themselves to the System?

    ReplyDelete
    Replies
    1. Systems do not maintain lists of entities. All entities are grouped by structure, and then each buffer of identical structures (entities) are sent to systems that want that particular set of data.

      There is no cost for fetching a "component", and it's very cache friendly.

      However, it pays heavily during modification of entity structure (add/remove component). There is also no way to point to an entity in memory. It has some disadvantages.

      Delete