side by side
lines around each change
Show the changes in full context
White space changes
2009-11-15 13:08:38 (
Component scripts support ''hotloading'': while the game is running, you can edit and save a script file, and it will be immediately reloaded and used in the game with no need to stop or restart. (The data associated with each component will not be changed at all, only the code.)
== Interfaces ==
Most entities will behave similarly to each other, but there are a few cases where we would like to have differing implementations of one type of component.
For example, most entities should have some kind of `Position` component, which responds to `MoveTo` calls during a simulation update and can be queried by the renderer for the location in the current frame. (Frames are much more frequent than simulation updates). For entities that move smoothly, the component should typically respond to the renderer by interpolating from its position in the previous simulation turn to the current turn, and therefore it needs to remembers its previous position at the start of each turn. For entities that are not expected to move in straight lines (e.g. ballistic units like arrows), linear interpolation will be inaccurate. For entities that are not expected to move at all (e.g. trees), remembering the previous position every turn is wastefully inefficient.
It would be possible for a position component implementation to have a flag that switches between linear and parabolic interpolation, but the code would become increasingly complex as more special cases were added, and it would not be able to optimise the storage and computation of positions for non-moving entities (of which there might be tens of thousands).
Instead, we define `Position` as an '''interface'''. An interface does not define any code or data, but does define a list of methods (e.g. `MoveTo` and `GetInterpolatedPosition`). We then define a number of '''component types''' that implement the interface, providing the code and data - e.g. the `PositionInterpolated` and `PositionStatic` component types both implement the `Position` interface. A component is an instance of a component type.
An entity can only have (at most) one component that implements a particular interface (that is, it cannot have both `PositionInterpolated` and `PositionStatic`). Any code that interacts with the entity cannot tell what component types it uses - the code can only use `QueryInterface` to get a pointer to whatever component implements the `Position` interface, and call the common methods declared by that interface.
== TODO ==
Things to talk about:
* Message passing
* The details of actually writing code