Skip to main content

ECS micro-engine

Library for python containing an interpretation of ECS design pattern.

Features

  1. Adding/removing entity's attributes causes dynamic addition/removal of the entity from the corresponding systems
  2. Systems with annotation-based syntax
  3. Asynchronous systems (yield skips a frame)
  4. Systems accept multiple arguments, preventing global mutable state issues
  5. Full compatibility with type hints

Interpretation

  1. Entity is a python object
  2. Component is entity's attribute
  3. System is an entity describing an interaction between cartesian product of entities
  4. Metasystem is a system that launches other systems
  5. MetasystemFacade encapsulates all general logic (add, remove, update)

Installation

pip install ecs-girvel

Usage

You can also see girvel/fallen, ecs is written for it.

from ecs import MetasystemFacade, System, Entity  # TODO NEXT fix demo
import time


# 1. You create a metasystem
ms = MetasystemFacade()

dt = 0.04

# 2. You create systems and add them to metasystem
class VerticalSpeed:
    vy: float

class GravityConstants:
    g: float

@ms.add
@System
def gravity(target: VerticalSpeed, constants: GravityConstants):
    target.vy += constants.g * dt

class Inert:
    x: float
    y: float
    vx: float
    vy: float

@ms.add
@System
def inertia(target: Inert):
    target.x += target.vx * dt
    target.y += target.vy * dt

class Displayable:
    x: float
    y: float
    name: str

@ms.add
@System
def output(target: Displayable):
    yield from range(int(1 / dt) - 1)  # skips 24 out of 25 frames
    print(f'{target.name}: {target.x:.2f}, {target.y:.2f}')


# 3. You create objects
class DynamicEntity(Entity):
    def __init__(self, **attributes):
        for key, value in attributes.items():
            setattr(self, key, value)

ms.add(DynamicEntity(name='falling_guy1', x=0, y=0, vx=0, vy=0))
ms.add(DynamicEntity(name='falling_guy2', x=100, y=0, vx=0, vy=0))
ms.add(DynamicEntity(g=10))


# 4. Game loop
if __name__ == "__main__":
    while True:
        ms.update()
        time.sleep(dt)

Metadata

Release files for ecs-girvel 3.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ecs-girvel 3.0.1
File Size Uploaded
ecs-girvel-3.0.1.tar.gz 5.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for ecs-girvel 3.0.1
File Interpreter ABI Platform
ecs_girvel-3.0.1-py3-none-any.whl Python 3 none any Details

Total release size: 11.2 kB

Release files / ecs-girvel-3.0.1.tar.gz

Download URL ecs-girvel-3.0.1.tar.gz
Size 5.5 kB
Tags Source
SHA-256 checksum
How to use checksums
0a9e02bb396cfa6a093fd94e2afbaac65f13467dc0a2cb906fc162b4e14189b5
BLAKE2b-256 checksum
How to use checksums
33cab54779d12148c8f0cc5e8d56a81f3df1014c7a3e86cc38ffb2aee626e2a4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.10.5

Release files / ecs_girvel-3.0.1-py3-none-any.whl

Download URL ecs_girvel-3.0.1-py3-none-any.whl
Size 5.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
47bf028a95325a56407b9d577db200e0a9446ff8b28446757cba71e0bb67cef2
BLAKE2b-256 checksum
How to use checksums
29ec2336dad36b0ba00a49e99b2900e51640b32690006980da776d35bf9f65e9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.10.5

Release history Release notifications | RSS feed

This release

3.0.1 This release

2 release files

3.0.0

2 release files

2.0.1

2 release files

2.0.0

2 release files

1.0.8

2 release files

1.0.7

2 release files

1.0.6

2 release files

1.0.5

2 release files

1.0.4

2 release files

1.0.3

2 release files

1.0.2

2 release files

1.0.1

2 release files

1.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page