giovedì 7 luglio 2016

Day 140: Component System finally completed!

Yesterday I decided to quit the idea of refactoring the component system, but today I really felt like that was to be done, so i did.
Now every component inherits from Script, and the class GameObject has only a list of scripts and a transform. A script can be added with:

game_object.add_script();

and retrieved in a similar way. Everything is handled by template functions, and the system feels very user-friendly and Unity-like. This also allows to have multiple scripts of the same type, which was impossible with the previous approach.
Also, each script overrides two functions: bool is_unique() and bool is_copyable(). This allows to put constraint on the uniqueness or the possibility to copy a script.


The main reason that made me do this refactoring is the upcoming physical engine: maybe each object will need more than one collider, and this is fairly straightforward now.

Nessun commento:

Posta un commento