PitchHut logo
A minimalistic ECS framework for Python using numpy and raylib.
Pitch

MicroECS offers a lightweight and efficient entity component system for Python developers. With fewer than 400 lines of code, it integrates seamlessly with numpy, making it perfect for game development and simulations. The inclusion of raylib examples simplifies the learning process, enabling quick deployment of interactive graphics.

Description

MicroECS is a lightweight and efficient Entity Component System (ECS) implemented in Python, leveraging the power of NumPy for optimal performance and ease of use. This minimalistic, approximately 400 lines of code, solution is designed for developers looking to build modular and scalable applications, particularly in game development.

Key Features:

  • Efficient Components: Utilize Component classes that manage data using NumPy arrays, supporting essential data types like int32, float32, bool, and object. This design allows for efficient memory usage and fast data processing.
  • Dynamic Pools: The Pool structure handles collections of entities with the same component types, ensuring contiguous memory allocation for improved performance.
  • Query Capabilities: QueryResult facilitates advanced querying of entities within a World, offering a NumPy-like interface for smooth data manipulation and iteration.
  • World Management: The World class acts as the central manager for entities and their components, enabling easy migration and organization through lazy updates for mutable operations.

Getting Started

To use MicroECS, it can either be installed via pip or from source. For an example, see the basic usage:

pip install microecs

Example Usage

Here's a simple implementation showcasing component and system creation within the MicroECS framework:

from typing import Callable
import numpy as np
import raylib as rl
from microecs import World, Component

class HasPosition(Component):
    position: np.ndarray = field(metadata={"shape": (2,), "dtype": "float32"})
class HasVelocity(Component):
    velocity: np.ndarray = field(metadata={"shape": (2,), "dtype": "float32"})
class HasColor(Component):
    color: np.ndarray = field(metadata={"shape": (4,), "dtype": "int32"})

class RenderSystem:
    def __call__(self, world: World):
        query_result = world.query(HasPosition, HasColor)
        for position, color in zip(query_result.position, query_result.color):
            DrawEntity(position, color)

class MotionSystem:
    def __call__(self, world: World):
        qr = world.query(HasPosition, HasVelocity)
        qr.position[:] += qr.velocity * DT

# Main loop and further system management code...

Performance

MicroECS is particularly optimized for batch processing, outperforming traditional OOP designs. For instance, during a microbenchmark, MicroECS demonstrated speeds significantly faster than competing ECS implementations, showcasing its capability for handling high entity counts efficiently.

Documentation

Complete documentation is available at MicroECS Documentation. Here, you can explore more about the primitives, implementation details, and complex usage scenarios for building performant systems.

MicroECS serves as an excellent tool for developers aiming to implement an ECS architecture with minimal overhead, making data manipulation and entity management streamlined and efficient.

0 comments

No comments yet.

Sign in to be the first to comment.