229Component type instances go through one of two lifecycles:
230
231@code
232CCmpExample();
233Init(paramNode);
234// any sequence of HandleMessage and Serialize and interface methods
235Deinit();
236~CCmpExample();
237@endcode
238
239@code
240CCmpExample();
241Deserialize(paramNode, deserialize);
242// any sequence of HandleMessage and Serialize and interface methods
243Deinit();
244~CCmpExample();
245@endcode
246
247The order of <code>Init</code>/<code>Deserialize</code>/<code>Deinit</code> between entities is mostly undefined,
248so they must not rely on other entities or components already existing; @em except that the @c SYSTEM_ENTITY is
249created before anything else and therefore may be used, and that the components for a single entity will be
250processed in the order determined by TypeList.h.
251
252In a typical component:
253
254- The constructor should do very little, other than perhaps initialising some member variables -
255 usually the default constructor is fine so there's no need to write one.
256- @c Init should parse the @c paramNode (the data from the entity template) and store any needed data in member variables.
257- @c Deserialize should often explicitly call @c Init first (to load the original template data), and then read any instance-specific data from the deserializer.
258- @c Deinit should clean up any resources allocated by @c Init / @c Deserialize.
259- The destructor should clean up any resources allocated by the constructor - usually there's no need to write one.
260
261
262@subsection schema Component XML schemas
263
264The @c paramNode passed to @c Init is constructed from XML entity template definition files.
265Components should define a schema, which is used for several purposes:
266
267- Documentation of the XML structure expected by the component.
268- Automatic error checking that the XML matches the expectation, so the component doesn't have to do error checking itself.
269- (Hopefully at some point in the future) Automatic generation of editing tool UI.
270
271@c GetSchema must return a Relax NG fragment, which will be used to construct a single global schema file.
272(You can run the game with the @c -dumpSchema command-line argument to see the schema. Do not forget to also specify the used mods with @c -mod=<mod>.).
273The <a href="http://relaxng.org/tutorial-20011203.html">official tutorial</a> describes most of the details
274of the RNG language.
275
276In simple cases, you would write something like:
316The <code><data></code> elements are native elements, while the <code><ref></code> elements are elements added for our engine. These non-native elements allow the definition of an operation that depends on the parent template. Possible operations are "add" and "mul", and can be applied as the example below.
317
318Say the parent template is
319@code
320<Entity>
321 <Example>
322 <Name>Semi-Humanoids</Name>
323 <Height>9000</Height>
324 <Eyes/>
325 </Example>
326 <!-- ... other components ... -->
327</Entity>
328@endcode
329and the child template appears like
330@code
331<Entity>
332 <Example>
333 <Name>Barney</Name>
334 <Height op="add">5</Height>
335 <Eyes/>
336 </Example>
337 <!-- ... other components ... -->
338</Entity>
339@endcode
340then Barney would have a height of 9005.
341
342Elements can be wrapped in <code><optional></code>.
343Groups of elements can be wrapped in <code><choice></code> to allow only one of them.
344The content of an <code><element></code> can be further nested elements, but note that
345elements may be reordered when loading an entity template:
346if you specify a sequence of elements it should be wrapped in <code><interleave></code>,
347so the schema checker will ignore reorderings of the sequence.
348
349For early development of a new component, you can set the schema to <code><ref name='anything'/></code> to allow any content.
350If you don't define @c GetSchema, then the default is <code><empty/></code> (i.e. there must be no elements).
351
352
353@subsection system-components System components
354
355System components are global singleton components of the @c SYSTEM_ENTITY.
356These are added to it in @c CComponentManager::AddSystemComponents, and