Skip to main content

Annotation-based asynchronous ECS library

Project description

ECS library

This is a library for python containing an interpretation of ECS design pattern.

Features

  1. You can add components during the game and entity will be automatically registered to a system if needed
  2. You can write somewhat asynchronous systems (using yield to skip a frame)

Interpretation

  1. Entity is a javascript-style object (entity.name == entity['name'])
  2. Component is entity's attribute
  3. System is an entity describing an interaction between N entities
  4. Metasystem is a system that launches other systems

Usage

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

from ecs import Metasystem, create_system
import time


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

dt = 0.04

# 2. You create systems and add them to metasystem
@ms.add
@create_system
def gravity(
    object: 'vy',  # object is any entity with 'vy' component
    constants: 'g',  # constants is any entity with 'g' component
):
    object.vy += constants.g * dt

@ms.add
@create_system
def inertion(object: 'x, y, vx, vy'):
    object.x += object.vx * dt
    object.y += object.vy * dt

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

# 3. You create objects
ms.create(name='falling_guy1', x=0, y=0, vx=0, vy=0)
ms.create(name='falling_guy2', x=100, y=0, vx=0, vy=0)
ms.create(g=10)

# 4. Game loop
while True:
    ms.update()
    time.sleep(dt)

Installation

I recommend you build from sources, version in pypi is old.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ecs-girvel-1.0.8.tar.gz (6.8 kB view details)

Uploaded Source

Built Distribution

ecs_girvel-1.0.8-py3-none-any.whl (6.6 kB view details)

Uploaded Python 3

File details

Details for the file ecs-girvel-1.0.8.tar.gz.

File metadata

  • Download URL: ecs-girvel-1.0.8.tar.gz
  • Upload date:
  • Size: 6.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.5

File hashes

Hashes for ecs-girvel-1.0.8.tar.gz
Algorithm Hash digest
SHA256 060dbd13b6a7e4dea9965921db6766e95f15fd25ddbf06f3d324fc738e3e25b1
MD5 703f4395c978a79ba3b4fe2656e3aef3
BLAKE2b-256 9da57e7c7360bc608b47fe022747d78148bf40e9faddd9c30eb5e90cb162a34a

See more details on using hashes here.

File details

Details for the file ecs_girvel-1.0.8-py3-none-any.whl.

File metadata

  • Download URL: ecs_girvel-1.0.8-py3-none-any.whl
  • Upload date:
  • Size: 6.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.5

File hashes

Hashes for ecs_girvel-1.0.8-py3-none-any.whl
Algorithm Hash digest
SHA256 47cdfebfd9319e40dbca02ccb5a8f4353a7724a29f304ddacc5729294b82d2be
MD5 5796c93f32db886ea4408d6163f85911
BLAKE2b-256 e9a080e29b9a36373fcc328ed57f8b32d4ea42a11d22d38577d9af96a2688c84

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page