Annotation-based asynchronous ECS library
Project description
ECS library
This is a library for python containing an interpretation of ECS design pattern.
Features
- You can add components during the game and entity will be automatically registered to a system if needed
- You can write somewhat asynchronous systems (using yield to skip a frame)
Interpretation
- Entity is a javascript-style object (
entity.name == entity['name']
) - Component is entity's attribute
- System is an entity describing an interaction between N entities
- 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
Release history Release notifications | RSS feed
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.4.tar.gz
(6.7 kB
view details)
Built Distribution
File details
Details for the file ecs-girvel-1.0.4.tar.gz
.
File metadata
- Download URL: ecs-girvel-1.0.4.tar.gz
- Upload date:
- Size: 6.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.10.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 070dc907499f4d4ca8e690762462e5b93344026d75e423575d9983d3206a8d33 |
|
MD5 | b64aa0ce048ab877270c0cd5fe62a193 |
|
BLAKE2b-256 | 3ee427bedc0c4cca0747712f717b73eee4f771ded6d16fa5a9ac60352a26cd44 |
File details
Details for the file ecs_girvel-1.0.4-py3-none-any.whl
.
File metadata
- Download URL: ecs_girvel-1.0.4-py3-none-any.whl
- Upload date:
- Size: 6.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.10.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8609464b7813dbdacbc4e0eb234527c053f3a4769c87f343a765c5c952401562 |
|
MD5 | 64c61c2a0749c737c2b4001a03ab4fd7 |
|
BLAKE2b-256 | b486cc0120aecfd0753cdf290d49ae86a1fa060d1cb9c56c52ce75e70ccc7d08 |