Skip to content

[Feature Request] Add the ability to pass parameters to the execute() function #34

@lynxLoad

Description

@lynxLoad

Hello! This is a really good ECS, and I would like to make a suggestion for improving the systems.

Problem

In the current implementation of the systems, the execute() function only accepts basic parameters (chunk, entity_list, entity_count). This limits the flexibility of the systems, especially when they need to access external data.

For example:

local MovementSystem = evolved.builder()
    :query(q)
    :execute(function(chunk, list, count)
        local st = chunk:components(state.id)
        local pos = chunk:components(position.id)
        local dir = chunk:components(direction.id)
        local spd = chunk:components(move_speed.id)

        for i = 1, count do
            if st[i] == "moving" then
                pos[i].x = pos[i].x + dir[i].x * spd[i] * get_delta()
                pos[i].y = pos[i].y + dir[i].y * spd[i] * get_delta()
            end
        end
    end)
    :build()

The system is tightly coupled with the global function get_delta(), which complicates testing and reuse. The code would be simpler and easier to maintain if it were possible to pass the delta as an argument.
An even clearer example:

local InputSystem = evolved.builder()
    :query(q)
    :execute(function(chunk, list, count)
        -- I want to know which keys are pressed right now!
    end)
    :build()

Proposed solution

Extend the evolved.process() API to support parameters:

evolved.process(MovementSystem, dt)
evolved.process(InputSystem, action)
local InputSystem = evolved.builder()
    :query(q)
    :execute(function(chunk, list, count, action)
        -- Happy!
    end)
    :build()

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions