Difference between revisions of "Entity"
(2 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
Entity is a primitive type in quake-c language. They are essentially a struct which | Entity is a primitive type in quake-c language. They are essentially a struct which come into existence with their own individual set of member variables. | ||
Entities are the only collections of variables in quake-c. | |||
In this quake-c snippet the 'self' entity's 'pain_finished' variable is set | |||
<code>self.pain_finished = time + 2;</code> | |||
== Life Cycle == | |||
Some entities are created at level start and other entities are created afterwards. | |||
Entities created after the start of the level are created via the '[[spawn()]]' function: | |||
Entities can be removed from the game with the built-in function [[remove(entity)]] or sometimes SUB_Remove | |||
== Engine Callbacks == | == Engine Callbacks == | ||
Entities get [[ | Entities can get [[Engine Hooks|callbacks]] from the engine depending on how they are set up. At the start of the callback 'self' will be assigned to the current entity. | ||
=== touch === | === touch === | ||
Line 8: | Line 21: | ||
=== think === | === think === | ||
Think is called on the first game tick after 'nexttime' becomes less than or equal to 'time'. | Think is called on the first game tick after 'nexttime' becomes less than or equal to '[[time]]'. | ||
== Entity Variables == | == Entity Variables == |
Latest revision as of 05:15, 25 March 2022
Entity is a primitive type in quake-c language. They are essentially a struct which come into existence with their own individual set of member variables.
Entities are the only collections of variables in quake-c.
In this quake-c snippet the 'self' entity's 'pain_finished' variable is set
self.pain_finished = time + 2;
Life Cycle[edit | edit source]
Some entities are created at level start and other entities are created afterwards.
Entities created after the start of the level are created via the 'spawn()' function:
Entities can be removed from the game with the built-in function remove(entity) or sometimes SUB_Remove
Engine Callbacks[edit | edit source]
Entities can get callbacks from the engine depending on how they are set up. At the start of the callback 'self' will be assigned to the current entity.
touch[edit | edit source]
touch is called when the physics engine has detected a collision between entities or the world and the entity. Important note: The physics engine may not call the touch callback when an entity and the entity's 'owner' collide.
think[edit | edit source]
Think is called on the first game tick after 'nexttime' becomes less than or equal to 'time'.
Entity Variables[edit | edit source]
New entity variables can be defined much as in 'defs.qc'
The code:
.string deathtype;
defines the floating point variable 'deathtype' which can be accessed as in the if-statement below:
if (targ.deathtype == "falling")
Since all entities regardless of whether they are a projectile or a lamp or a monster each have the same set of member-variables to store things in, it is easy to make use of nonsensical fields to store properties for new behavior and has the benefit of not changing the memory footprint of every other entity created in the game.
There doesn't appear to be a limit on the number of variables that can be attached to an entity.
New entity variables can be declared anywhere in the code.
Trivia[edit | edit source]
Even in the 2021 release there are a limited number of entities that can be created in a given game
Entities can cause excessive network traffic and slow the game dramatically
Each entity is created the same with all entity-defined variables attached