LastOliveGames / becsy

A multithreaded Entity Component System (ECS) for TypeScript and JavaScript, inspired by ECSY and bitecs.
MIT License
196 stars 17 forks source link

🔨 Preemptively remove/overwrite extant components and systems when adding them to their type collections from @component and @system decorators #29

Open rubybrowncoat opened 2 weeks ago

rubybrowncoat commented 2 weeks ago

I'm opening this so we may discuss the approach to see if fits and holds up,

The repro repository for the hot-reloading issue is still at https://github.com/rubybrowncoat/becsy-hot-reloading but I pointed the @lastolivegames/becsy package to a local clone of the fork at https://github.com/rubybrowncoat/becsy that has been built with the changes.


This change is Reviewable

pkaminski commented 2 weeks ago

If I'm reading the changes correctly, this makes the decorators deduplicate component and system types by name. This is dangerous: if you accidentally have two different types with the same name (an easy mistake to make in a large project!), Becsy will silently drop one of them.

I believe the right way to handle the issue is to get a notification when a module is being unloaded and pull all the types it defines out of the arrays at that time.