-
Notifications
You must be signed in to change notification settings - Fork 3
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
Implicit world default parameter. #1
Comments
Almost all uses of the library will only ever need one World - perhaps creating a short-lived copy on-demand for serialization/deserialization. For normal usage, you never need to use an explicit World; that's why there's a default one.
from snecs import World
world = World()
new_entity = world.new_entity
add_component = world.add_component
... and reexport every method of every If it were the case that normal ECS usage requires multiple |
I can understand how performance could be a priority, but I don't like how the API suffers for it. If given the options I'd use the bound World methods even though I knew they were slower. I'm also not suggesting to remove the current functions if we know they're really faster. Attribute lookup overhead isn't the best example since it's a well known optimization to manually 'remove the dots' in performance critical loops which might be an even faster lookup than the current methods because then the functions are in the local namespace rather than global. You might also be implying that I'm using world = snecs.BoundWorld() # Suggesting an encapsulating class or subclass since adding the methods directly to World will likely cause import issues.
world.new_entity(...) # Normal/slow use.
new_entity = world.new_entity # Well known optimization.
# world.new_entity could return `functools.partial(snecs.new_entity, world=self)` instead of a regular bound method.
for ...:
new_entity(...) # Hot path, lookup in local namespace (assuming this is in a function.) Will there be a standard way to replace the implicit World with a new one that I've created? There is To disable the implicit parameter I'd also have to do |
You raise valid points; I'll need to think about this further. Acknowledging that I've read your comment, but I won't be able to mess with |
A lot of functions take a world parameter but if you ever forget to add it then an implicit default world will be used instead. I'm paranoid that I'll forget to add this parameter somewhere which will create a bug I can't track down easily.
Have you considered other ways of handling this? I see that other libraries often put all of their main functionality in methods of their world object instead of as separate objects, or removing the implicit world as a default parameter could be done instead, or another class could be added which encapsulates both the world and the ECS functions which use it.
The text was updated successfully, but these errors were encountered: