-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Systems #2
Comments
What I did so far:
This kind of guarantees that a LuaSystem imitates a flecs system as much as it could. However, I'm currently trying to find ways to:
Regarding multithreading, I don't think Lua has support for multithreading. As far as I know, we'd need to have multiple |
Passing arrays without copying is premature optimization, I think the bigger problem is that if flecs-lua manages all the de/serialization everything will be a dumb table. It has to be aware which components need special metatables, e.g. If we solve that efficiently we could make the columns special arrays, initially we could push the elements as-is on access and read back the pushed elements at the end. There are many ways to do it which depend on the use case, which is why I don't want to get into it at this point, we could check for The API needs some changes for multithreading, I'll have something ready soon. |
A weird question. Would it be a bit dumb if we deviated a bit from the standard flecs API? What I have in mind is for the systems to work on each entity individually rather than on entire arrays. void ecs_lua_entrypoint(ecs_iter_t *it)
{
for(int i = 0; i < it->count; ++i)
{
lua_rawgeti(L, LUA_REGISTRYINDEX, (long)(it->param));
// TODO: Pass stuff
lua_pcall(L, 0, 0, 0);
}
} instead of this: void ecs_lua_entrypoint(ecs_iter_t *it)
{
lua_rawgeti(L, LUA_REGISTRYINDEX, (long)(it->param));
// TODO: Pass stuff
lua_pcall(L, 0, 0, 0);
} This way the lua system will be something like: function move(position, velocity)
position.x = position.x + velocity.x
position.y = position.y + velocity.y
return position, velocity
end instead of having to loop in Lua itself. |
To make multithreading work flecs-lua could create states per-system and issue a callback for the host to de/initialize the state. The registry would look like this:
I'm looking into the module API and how it could interact with scripts. |
There are situations where the opposite is preferable or even required, e.g. individual loops over with 2 components out of many one after the other, it's also possible to make API calls inside systems and create additional loops. Because this restricts access to just one cell of each column on each iteration it can't be made the default behavior. |
Yeah, makes sense. I was just thinking about how that would give a new level of parallelism in the systems, but it does seem to be quite limiting. |
This is a solved problem at this point. multithreading is tracked by #3. |
My thoughts so far on how systems should work:
ecs.system()
wraps the flecs function like the existing APIs we have so farThere has to be a dummy
ecs_lua_entrypoint(ecs_iter_t *it)
between the VM and flecsWhen the system is called from flecs it pushes each "argument" as an array of components, then copies it backs into flecs when it's finished
flecs-lua probably shouldn't "own" the lua_State, so it has be kept in mind that the VM can persist across frames and:
if a system has a
Init()
we definitely have to persist that VM untilDeInit()
anywaySome things that are not so obvious:
If there are multiple systems registered from a state, how do we figure out which Lua system is supposed to run?
Do we need a lua_State per system?
Can we make multithreading work?
How does it interact with host scripts that aren't modules/systems?
Can we still make "simple" scripts work where
sleep()
is possible?Reloading script/systems is kinda important, what changes in flecs-lua would that require?
The text was updated successfully, but these errors were encountered: