Giter VIP home page Giter VIP logo

makr's Introduction

makr

Fast HTML5 Entity-Component-System library

NPM version Build Status Coveralls Status

Install

npm install --save makr

Usage

var makr = require('makr')
var em = makr(Position, Motion, Display /* … component types */)

makr's People

Contributors

ooflorent avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

makr's Issues

Query performance optimization

At the moment the speed of querying depends on the amount of entities. As this should be one of the most common operations performed I think it should be optimized. I did a little experiment where I'd store all entities with the same mask in an array which could be accessed by their mask through a hashmap.

var hashMap = {}

hashMap[0] = [] //All entities with mask 0 stored here
hashMap[5] = [] //All entities with mask 5 stored here

...etc

The entities then move around based on their mask. This lets us get a constant query time no matter the amount of entities by simply testing the query mask against each index in the hashmap. Initial tests gave ~5mil queries per second no matter the amount of entities (with hardly any optimizations applied).

var result = []

var entityMasks = Object.keys(hashMap)
for (var index = 0; index < entityMasks.length; index++) {
  var entityMask = entityMasks[index]
  if ((entityMask & mask) === mask) {
    Array.prototype.push.apply(result, this._entityCache[entityMask])
  }
}

The problem is that you'd have to keep track of each entitys index in its hashMap[entityMask] array to remove it from there when its mask changes or it is destroyed. You'd also have to update the indices of the other entities in the mask array which would in turn make any operation that changes the mask of entities slower (the speed would now be determined by the amount of entities with the same mask and the index of the entity that was removed).

Thoughts? Or perhaps other ideas on how to do it? If something was unclear I'll explain it better.

Unknown component type 'undefined'

Not sure if I'm being dense, but I've attempted to use this library with both rollup and webpack to no avail. With both of those build tools I'm getting the same error: Unknown component type 'undefined'.

import makr from 'makr';

class Body {
  constructor(x, y) {
    this.x = x
    this.y = y
    this.dx = 0
    this.dy = 0
  }
}

class Display {
  constructor(img) {
    this.img = img
  }
}

// Create the entity manager
const em = makr(Body, Display)

const entity = em.create();
entity.add(Body); // error
entity.add(Display);

I should also mention that I'm using Babel 6 to transpile. I'm going to attempt to use 6to5 as I read in a forum post that you were using that.

Edit: Nevermind, it seems that 6to5 is actally Babel. Didn't realise that.

Events / Messages?

I think you mention somewhere that events are not needed in your library, I am new to ECS - can you show some example of how you handle communication between systems? Do events not help keep each system, behaviour without interdependencies?

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.