SEED

From The DarkMod Wiki
Revision as of 13:54, 3 July 2010 by Tels (talk | contribs) (add note about scaling)
Jump to navigationJump to search
Note: This is a design document and not actually implemented or available yet!

Introduction

The new and improved LOD System for TDM v1.03 lets you place entities in your map that reduce their own complexity when being far away from the player. However, there are still some huge drawbacks to this technique:

  • manually placing thousands of entities is very tedious and error prone
  • 3000 entities "thinking" (deciding what LOD they have) takes about 7% of performance, even when they are not visible
  • The overall entity limit of 8192 entities - even if only ever 100 entities are visible to the player, you would not be able to create a forest with 10000 objects (trees, treestumps, flower patches and rocks etc.)

To overcome these limitations, the new LODE (Level Of Detail Entity manager) system was created by Tels in June/July 2010.

What is it

It is foremost an entity manager that can:

  • Create entities from "templates" (even multiple)
  • Place created entities on random positions with random rotations
  • Only creates the entities that are "near" the player (saving memory and CPU time)
  • Removes entities "far" from the player, thus overcomes the entity limit
  • Works entirely automatic

The system also includes support for inhibitors, e.g. areas that are clear of generated entities. This way a forest clearing can be specified with only two entities, instead of being pieced together from multiple generators.

How to use it

IMPORTANT
The current system only supports axis-aligned boxes. If you rotate the entity in DR, it will simply cover the area that the bounds of the rotated brush include! In addition, the placement of entities is relative to the origin of the LODE entity. If you resize the entity in the editor, the origin can move from the center to some side. In this case select the entity, press CTRL+v to enter Vertic Mode and then move the origin back to the center (which you can easily identify, because linked entities will be drawn with their link exactly from the center).


A LODE entity in the editor
An entity targeted by the LODE
  • In DarkRadiant, create a brush the size of the area you want to cover
  • With that brush still selected, Click the right mouse button and select Create entity and select Darkmod/Info/atdm:lode
Note:
If you want to resize the LODE entity after creating it, select it with SHIFT + Click the left mouse button and press TAB to select the brush, then resize it normally.
  • Now create the entities that you want to appear. Entities that use the LOD system should be prefered.
  • Link each entity from the LODE entity by selecting first the LODE, then the entity, and then press CTRL+K.
  • Put the entities at the hight you want them to appear. Alternatively, use the spawnarg "lode_floor" on the entity (see below for more spawnargs).
  • Remember to dmap whenever you add, delete or change the position/size of a LODE!

Area shape and blocking areas

A NO LODE entity blocking an area

At the moment the area covered by the entity is always treated as a (possible rotated) box. That means you cannot get f.i. triangle shaped areas (yet). However, it is possible to block some areas inside the covered area from getting any entities via Darkmod/Info/atdm:no_lode entities. With this "boolean subtract" you can create "holes" or even more complex shapes.

To get this to work, place atdm::no_lode entities and then link them from the LODE. If you want to have one LODE inhibitor to block more than one intersecting LODE, simply link it from both. See screenshot at right for an example.

Important note

The current system only supports axis-aligned boxes. If you rotate the entity in DR, it will simply cover the area that the bounds of the rotated brush include! In addition, the placement of entities is relative to the origin of the LODE entity. If you resize the entity in the editor, the origin can move from the center to some side. In this case select the entity, press CTRL+v to enter Vertic Mode and then move the origin back to the center (which you can easily identify, because linked entities will be drawn with their link exactly from the center).

GUI Setting

The current "Object detail" setting not only influences LOD distances, but also the density spawnarg, albeit only slightly.

We want to avoid overly complicated settings like some other games have, where you can control the density, the visibility distance, the texture quality etc all on their own. But rendering slightly less mushrooms for a playable framerate is still a good idea, so LOD distance and density are coupled.

Note: The GUI setting is currently only applied at map start, changing this setting during runtime will only change the LOD distances, but not change the amount of generated entities.

Spawnargs on the LODE

These spawnargs can be set on the LODE itself and set defaults or influence overall strategies:

seed

Default: 0. The random seed. If not set or set to 0, a random value will be used (this is the recommended way, as it generates different results every time you start the map anew, but still keeps the entities when you f.i. save and then load a game).

If set to > 0, the random number generator will always generate the same sequence, so you get still randomly distributed results, but they are always the same.

spacing

Default: 0. Defines a minimum distance between placed entities. If set to > 0, implies collision check at creation time between all entities.

cull_range

Default: 150 units. Entities further away from the player than hide_distance (as defined on each LOD entity) + cull_range will be removed from the game world. When they come closer to hide_distance + (cull_range / 2), they will respawn automatically.

max_entities

Default: 0. The maximum number of entities generated. If 0 (the default), then the number will be computed from the aprox. area the LODE covers, taking into account the density spawnarg.

density

Default: 1.0. A factor multiplied with the number of entities generated if max_entities is 0.

The density spawnarg controls how many entities are generated when max_entities is 0.

Note: The density is slightly influenced by the menu setting "Object Detail". Make sure you test your map with the "Normal" setting. If you can, test as well as the "Lowest" and "Highest" to get a feeling for the extremes that can appear.

falloff

Default: none. Defines a function that influences the probability that an entity will be generated further away from the center. If set to none, all positions are equally likely, resulting in a square shape. All other values create a ellipsoid-shape defined by the corners of the LODE and distribute the entities inside that shape.

Possible values:

  • none - entities all over the square, none outside
  • cutoff - no falloff, but entities rescricted inside ellipsoid formed by LODE corners
  • square - ellipsoid like cutoff, but square falloff from the center
  • exp - ellipsoid like even, but exponential falloff from the center
The falloff spawnarg controls the distribution of the entities.

bunching

Default: "0" (Off). Number from 0.0 to 1.0, giving the probability that a randomly created entities "bunches" up with an already existing entity. Can be overriden for each entity class with lode_bunching.


rotate_min/rotate_max

Default: 0 0 0 and 5 360 5. The range for each axis on how much the entity will be randomly rotated around it. In the order "Ymin Zmin Xmin" and "Ymax Zmax Xmax" (or pitch, yaw, roll (yzx), where the actual rotation order will be yaw, pitch, roll, e.g. "zyx").

The default makes entities yaw randomly between 0 and 360 degress around Z (turn), and pitch/roll between 0 and 5 degrees on the other two axes. Can also be overwritten on each class with lode_rotate_min and lode_rotate_max.

remove

Default: 0. Boolean, if set to 1, the LODE will spawn all entities immediately (instead of spawning only the ones that are visible to the player) and then remove itself.

Spawnargs on the Inhibitors (atdm:no_lode)

Spawnargs on Targets

These spawnargs can be set on the entities that the LODE targets:

lode_watch_brethren

Boolean, default: 0 (false).

If set, instead of taking this entity as a template to create new entities, this tells the LODE entity that all entities inside the LODE and of the same entityDefName as this one should be "watched" over by the LODE.

That means it will add these entities to its entity watch list, and do the LOD changes as well as cull/respawn them if nec.

The other "lode_*" spawnargs (like lode_floor, lode_spacing etc.) are ignored on the target entity. The only relevant spawnargs are lod_* and hide_distance - these cause the LOD system to kick in. Also, do not forget to put a hide_distance on the target entity, or the LODE will never cull the entities it watches.

lode_floor

Default: 0 (Off). If set to 1, all entities of this class will be floored, that is their position will be adjusted so that they touch whatever is under them. This works with dynamically created terrain or terrain consisting of irregular heights like when it was made from patches. See also lode_collide and lode_stack.

lode_score

Sets the score for this entity class. All scores will be summed together, and the score for each class will be the percentage of entities of this class to create. Some examples:

  • Entity A: 4, Entity B: 5: Sum: 9, 4/9 of all entities will be of class A, and 5/9 will be class B
  • Entity A: 1, Entity B: 2: Entity C: 7, Sum: 10, 1/9 of all entities will be of class A, 2/10 will be class B and 7/10 will be of class C

lode_spacing

Defines a minimum distance between placed entities of this class. Overrides the default setting from "spacing" on the LODE. If set to > 0, implies collision check at creation time between all entities of this class.

lode_rotate_min/lode_rotate_max

Default: Same as the LODE specifies (which defaults to 0 0 0 and 5 5 360).

The range for each axis on how much the entity will be randomly rotated around it. I the order "Ymin Zmin Xmin" and "Ymax Zmax Xmax" (or pitch, yaw, roll (yzx), where the actual rotation order will be yaw, pitch, roll, e.g. "zyx").

The default makes entities rotate randomly between 0 and 360 degress around Z (turn), and tilt between 0 and 5 degrees on the other two axes. Use 0 0 0 and 0 0 360 for entities that should be perfectly upright.

lode_bunching

Default: What the LODE specifies with bunching. Number from 0.0 to 1.0, giving the probability that a randomly created entities "bunches" up with an already existing entity. Can be override per entity class with lode_bunching.


lode_stack

Section not done yet.

lode_collide

Section not done yet.

Other LOD spawnargs

You can of course use other LOD spawnargs on the entities that the LODE creates. See LOD for a list.

Script events

There exist a few script events that can be used either from scripts, or by setting up a trigger that links to an atdm:target_callobjectfunction with the spawnarg call set to one of the script functions below:

Deactivate()

Deactivates the thinking of this LODE. Spawned entities stay where they are.

Activate()

Activates the LODE (e.g. it starts to think) again. If nec., the LODE will also spawn and unhide any entities that it needs.

CullAll()

Removes all entities under control of this LODE from the game. Only useful if either the player is very far away, or if you have called Deactivate() before - otherwise the entities might be spawned again in the next frame.


Ideas

Worth considering:

lode_strategy

How the entities will be placed. Default: "random", but can be "grid" (needs a way to specifiy grid-size, grid spacing, and random-offset from grid position).

See also