Generalities On Entities: Difference between revisions
TomEdwards (talk | contribs) (→Think Functions: redirect section) |
m (minor tidy (small description?)) |
||
Line 1: | Line 1: | ||
== Introduction == | == Introduction == | ||
{{note|This article assumes that the reader has at least basic experience in C++}} | {{note|This article assumes that the reader has at least basic experience in C++}} | ||
Line 8: | Line 6: | ||
Every object, even the world, is an entity in the Source engine. All entities are derived from CBaseEntity. | Every object, even the world, is an entity in the Source engine. All entities are derived from CBaseEntity. | ||
== Naming | == Naming conventions == | ||
Within the Source SDK, server classes begin with a capital C (<code>C</code>), while client classes begin with a capital C followed by an underscore (<code>C_</code>) - this helps differentiate between the two code bases. | Within the Source SDK, server classes begin with a capital C (<code>C</code>), while client classes begin with a capital C followed by an underscore (<code>C_</code>) - this helps differentiate between the two code bases. | ||
Line 17: | Line 15: | ||
Client: C_MyEntity | Client: C_MyEntity | ||
The style of naming convention followed through the SDK code base is known as [[Wikipedia:Hungarian | The style of naming convention followed through the SDK code base is known as [[Wikipedia:Hungarian notation|Hungarian notation]]. Beginners are recommended to maintain the same style as used throughout the code base to save confusion. | ||
== Base | == Base classes == | ||
Every entity is based on <code>CBaseEntity</code>, however there are many derived classes. The following is a list of the more common derived classes. | Every entity is based on <code>CBaseEntity</code>, however there are many derived classes. The following is a list of the more common derived classes. | ||
Line 38: | Line 36: | ||
Every NPC & player are derived from this class. | Every NPC & player are derived from this class. | ||
== Think | == Think functions == | ||
{{main|Think()}} | |||
{{TODO|Add small description about '''think functions''' (avoid complete copy/paste material).}} | |||
== Macros == | == Macros == | ||
Badly set up macros will give cause errors messages, crash the game and cause erratic behavior. The following is a list of the more common macro definitions and some of the issues that surround them. | Badly set up macros will give cause errors messages, crash the game and cause erratic behavior. The following is a list of the more common macro definitions and some of the issues that surround them. | ||
===[[LINK_ENTITY_TO_CLASS]]()=== | === [[LINK_ENTITY_TO_CLASS]]() === | ||
This is one of the main macros. An entity cannot be created without this macro being used to define the entity's classname (as returned from <code>GetClassname()</code> on the server). However, on the client, an entity will not return it's classname unless there is a matching data description (<code>DATADESC</code>). | This is one of the main macros. An entity cannot be created without this macro being used to define the entity's classname (as returned from <code>GetClassname()</code> on the server). However, on the client, an entity will not return it's classname unless there is a matching data description (<code>DATADESC</code>). | ||
===[[PRECACHE_REGISTER]]()=== | === [[PRECACHE_REGISTER]]() === | ||
This is used to tell the engine that it needs to precache the entity when it loads. This is provided with the name of the entity (the same name as passed to [[LINK_ENTITY_TO_CLASS]]() ). | This is used to tell the engine that it needs to precache the entity when it loads. This is provided with the name of the entity (the same name as passed to [[LINK_ENTITY_TO_CLASS]]() ). | ||
===[[DECLARE_CLASS]]()=== | === [[DECLARE_CLASS]]() === | ||
This should be placed in the public section of an entities Class definition. This provides access to the BaseClass Macro. | This should be placed in the public section of an entities Class definition. This provides access to the BaseClass Macro. | ||
===DECLARE_[[DATADESC]](), BEGIN_[[DATADESC]](), END_[[DATADESC]](), and DEFINE_XXX()=== | === DECLARE_[[DATADESC]](), BEGIN_[[DATADESC]](), END_[[DATADESC]](), and DEFINE_XXX() === | ||
The Data Description macros provide for a number of different features; | The Data Description macros provide for a number of different features; | ||
Line 63: | Line 61: | ||
Further information is available on the [http://developer.valvesoftware.com/wiki/Data_Descriptions Data Descriptions] page. | Further information is available on the [http://developer.valvesoftware.com/wiki/Data_Descriptions Data Descriptions] page. | ||
===Networking | === Networking entities === | ||
See the [[:Category:Programming#Networking|Networking]] section for more information on networking entities, as that is outside the scope of this article. | See the [[:Category:Programming#Networking|Networking]] section for more information on networking entities, as that is outside the scope of this article. | ||
[[Category:Programming]] |
Revision as of 16:42, 23 February 2008
Introduction

This article is mainly about entities in the Source engine and will try to explain everything about entities.
Every object, even the world, is an entity in the Source engine. All entities are derived from CBaseEntity.
Naming conventions
Within the Source SDK, server classes begin with a capital C (C
), while client classes begin with a capital C followed by an underscore (C_
) - this helps differentiate between the two code bases.
For example:
Server: CMyEntity Client: C_MyEntity
The style of naming convention followed through the SDK code base is known as Hungarian notation. Beginners are recommended to maintain the same style as used throughout the code base to save confusion.
Base classes
Every entity is based on CBaseEntity
, however there are many derived classes. The following is a list of the more common derived classes.
CBaseAnimating
Every entity that has a model uses CBaseAnimating. Classes derived from CBaseAnimating can set a model and animate.

AddEFlags( EFL_FORCE_CHECK_TRANSMIT );
CBaseTrigger
Triggers are brush based entities that are generally placed during the map creation process.
CBasePlayer
This entity is the player itself. Every player-entity in the game is CBasePlayer or is derived from this entity.
CGameRules
This entity regulates the rules of the current game. It's mainly the gameplay.
CBaseCombatCharacter
Every NPC & player are derived from this class.
Think functions
Macros
Badly set up macros will give cause errors messages, crash the game and cause erratic behavior. The following is a list of the more common macro definitions and some of the issues that surround them.
LINK_ENTITY_TO_CLASS()
This is one of the main macros. An entity cannot be created without this macro being used to define the entity's classname (as returned from GetClassname()
on the server). However, on the client, an entity will not return it's classname unless there is a matching data description (DATADESC
).
PRECACHE_REGISTER()
This is used to tell the engine that it needs to precache the entity when it loads. This is provided with the name of the entity (the same name as passed to LINK_ENTITY_TO_CLASS() ).
DECLARE_CLASS()
This should be placed in the public section of an entities Class definition. This provides access to the BaseClass Macro.
DECLARE_DATADESC(), BEGIN_DATADESC(), END_DATADESC(), and DEFINE_XXX()
The Data Description macros provide for a number of different features;
- Specifying Think and Touch functions
- Providing Inputs and Outputs for mappers
- Providing external variable inputs (such as setting a model or the health of an item)
Further information is available on the Data Descriptions page.
Networking entities
See the Networking section for more information on networking entities, as that is outside the scope of this article.