npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

lipstick-ecs

v0.2.6

Published

A tiny and easy to use entity-component-system framework

Downloads

27

Readme

Build Status NpmVersion NpmDownload NpmLicense Coverage Status maintainability

lipstick-ECS

$ npm install lipstick-ecs --save

Introduction

lipstick-ECS is a tiny ECS framework for js or ts especially. It is easy to use because of good generic constraints implemented by full use of Generics of Typescript.

I try to make it support iteration of complex component combinations and keep it performant as possible. But there are still some unsatisfactory currently:

  • If the number of entities exceeds 100k, it is better not to choose lipstick-ecs at present.
  • The most consumptive operation is assigning a being watched component.
  • Assigning 22k being watched components takes 70ms.(10ms to create 22k component object)
  • Test in CPU: 3.40GHz Node: v10.11.0

Getting Started

Example Code

import { EntityAdmin, System, Component, IFilter } from "lipstick-ecs";

class Position extends Component {
    public x: number;
    public y: number;

    constructor(x: number, y: number) {
        super();
        this.x = x;
        this.y = y;
    }
}

class Velocity extends Component {
    public vx: number = 0;
    public vy: number = 0;
}

class Color extends Component { }
class Shape extends Component { }
class PlayerID extends Component { }
class PlayerName extends Component { }
class HiddenDisplay extends Component { }

const Match: IFilter = {
    all_of: [Position, Color, Shape],
    any_of: [PlayerID, PlayerName],
    none_of: [HiddenDisplay],
};

class MovementSystem extends System {
    public static Update(admin: EntityAdmin, deltatime: number): void {
        for (const pos of admin.GetComponentsByTuple(Position, Velocity)) {
            const vel: Velocity = pos.SureSibling(Velocity);
            pos.x += vel.vx * deltatime;
            pos.y += vel.vy * deltatime;
        }
    }
}

class RendererSystem extends System {
    public static Update(admin: EntityAdmin, deltatime: number): void {
        for (const ent of admin.GetEnttsByFilter(Match)) {
            const pos: Position = admin.SureComponentByEntity(ent, Position);
            const color: Color = admin.SureComponentByEntity(ent, Color);
            const shape: Shape = pos.SureSibling(Shape);
            if (admin.HasComponent(ent, HiddenDisplay)) {
                console.log("won't print this message...");
            } else {
                console.log("yes, the entity has not HiddenDisplay components.");
            }
            // do something for RendererSystem ...
            if (pos.x > 6) {
                // ...
            }
        }
    }
}

const admin = new EntityAdmin();
admin.AddWatchings(Match);
admin.AddSystem(MovementSystem);
admin.AddSystem(RendererSystem);
admin.start();

admin.CreateEntity(new Position(22, 33), new Color(), new Shape(), new PlayerID());
admin.CreateEntity(new PlayerID());
const ent = admin.CreateEntity();
admin.AssignComponents(ent, new Shape(), new Color());
admin.DeleteEntity(ent);

setInterval(() => { admin.UpdateSystems(); }, 200);

Future

I'm going to refactor code to improve performance of lipstick-ecs. And it's interfaces won't be changed as possible.