Concord
Concord copied to clipboard
Namespaced Events
This is an idea for now, but I plan to experiment around it.
The idea would be that from now on Systems have names like so:
-- System definition with a name
local RenderSystem = System("Render", {pool = {"position", "texture"}})
-- Event definition
function RenderSystem:draw ()
for _, entity in ipairs(self.pool) do
love.graphics.draw(entity.texture.image, entity.position.x, entity.position.y)
end
end
Now to emit the draw event we would usually call it like this
World:emit('draw', ...)
But this may also call other Systems that also define draw, if we only intended to call draw
on the Render
system we have no way to do so, with my proposal we would now call it like so:
World:emit('Render.draw', ...)
This means that now you have a way to call an event for a given System without calling events on other systems that may accidentally share the same name.
We can still target multiple systems if we don't specify the system name like so:
World:emit('draw', ...)
This makes the change backwards compatible, except for the addition of names for systems (which may also help with a debugger if we make one)
Something to keep in mind is that the arguments for beforeEmit
and afterEmit
will be changed as well.
Previously it was:
function World:beforeEmit (event, listeners, ...)
Now it will be
function World:beforeEmit (systemName, event, listeners, ...)
beforeEmit
and afterEmit
are fairly new and I expect more users to not use them in their code yet, plus the change is fairly small anyways so this shouldn't be a blocker to roll this feature out.