Changes between Version 3 and Version 4 of SimulationArchitecture


Ignore:
Timestamp:
Nov 15, 2009, 2:08:38 PM (15 years ago)
Author:
Philip Taylor
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • SimulationArchitecture

    v3 v4  
    2424
    2525Component 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.)
     26
     27== Interfaces ==
     28
     29Most 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.
     30
     31For 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.
     32
     33It 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).
     34
     35Instead, 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.
     36
     37An 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.
     38
     39== TODO ==
     40
     41Things to talk about:
     42 * Message passing
     43 * Serialization
     44 * SYSTEM_ENTITY
     45 * The details of actually writing code