Общее об энтити
Введение
Эта статья в основном о энтити в Source engine и будет пытаться объяснить все про энтити.
Каждый объект, даже мир, является энтити в Source Engine. Все энтити, являются производными от CBaseEntity.
Naming conventions
В Source SDK, класс server начинается с большой буквы С (C
), в то время как класс client начинается с большой буквы С с последующим подчеркиванием (C_
) - это помогает различать две базы кода.
Пример:
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.
Базовые классы
Каждая энтити основана на базовом классе CBaseEntity
, однако есть много производных классов. Ниже приведен список наиболее распространенных производных классов.
CBaseAnimating
Каждая энтити имеющая модель должна использовать класс CBaseAnimating
. Классы, производные от CBaseAnimating
могут использовать модели и анимацию.
Template:Note:ru
Template:Note:ru
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
Все энтити NPC и player являются производными от этого класса.
Think functions
Think functions are a group of functions comprising the main way to have an entity act without input. An entity's Think() is run once after it spawns, and can be told when to call itself again using SetNextThink(). Using SetThink() can change between several Think() functions, and GetLastThink() returns the time of the last think function. See Think() for detailed description.
Macros
Badly set up macros will give error 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 its 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.