-
Notifications
You must be signed in to change notification settings - Fork 2
1.1.2 ComponentTree and Component system
this engine use ComponentTree to manage Components. Component(class AbstractGameWindowComponent) is a "element" which can update, solveEvents, draw.
gameWindowComponentTree is a tree of GameWindowComponentTreeNode , and each node have a Component.
when the tree update, it calls the root's update. for each tree node, when it called update, it will call update on every nodes in its children, then update the component it holds.
when the tree draw, it calls the root's draw. for each tree node, when it called draw, it will draw the component it holds,then call draw on every nodes in its children. when draw, elder drawn will be covered by new drawn. which means the node deeper in the tree will draw on higher level.
when the tree process, it calls the root's process. process is a little more complex than update and draw. for each tree node, when it called process an event, it will first call process that event to every of its children. if any of them return true, then the function will return true. otherwise, this.getGameWindowComponent().process(event), and if the GameWindowComponent can not/shall not solve the event (like, the event is totally not relevant to the component), it will just return the event. if the event is totally solved by the component, then it shall return null if the event is solved by the component, but caused another event arise, then it shall return the new event.
that means every high level components will all receive every event first, and the event will goes deeper and deeper until it meet a component that can solve it. Or it will just go to the root finally. Be careful that even if the event is solved by one component, It might also be delivered down to the root if there be another node at another branch do this. And all the Events returned (except null and the original Event) will be add to the event list at the next loop.