Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Mission: We want entities to be rendered to show up on the screen.
- The simplest way to code this would be to first make a EntityListComponent that holds all the entities, and have it call the event 'render' on each entity it holds, every frame. We would then make a RenderComponent that has a drawing-method tied to 'render' on each entity, that simply draws the pixelsoup specified in the RenderData at the PositionData coordinates.
- On constructing the EntityListComponent
- *Make a list that can hold entities
- *Add the event 'render' on the world that invokes EntityListComponent.renderentities()
- *renderentities() loops over entity list and calls 'render' on each
- On constructing the Entity
- *Add entity to EntityListComponent's list
- On constructing the RenderComponent and giving it to an Entity
- *Find the PositionData and RenderData on this entity and cache them
- *Add the event 'render' on the entity that invokes RenderComponent.render()
- It would work, but it wouldn't be the fastest system, as EntityListComponent would dispatch an 'render' for each entity, which would look up the methods associated with 'render' and call them. For 100 entities that's 100 Hash.get() and 100 method() calls.
- However, with the newfound flexibility we can structure this differently. We don't even need a EntityListComponent anymore (we might need it for other things later, but let's drop it for now).
- On constructing the Entity
- *Nothing
- On constructing the RenderComponent and giving it to an Entity
- *Add rendercomponent to global static rendercomponent list
- *Add the event 'render' to the world that invokes a static global RenderComponent.renderall() method
- *renderall() loops the static rendercomponent list and draws their pixelsoups
- Now rendering all 100 has turned into 1 Hash.get(), 1 method(), and 1 while() loop. We were able to break out of the "per entity" thinking.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement