cstrike里最重要的几个数据结构(一) cl_entity_s
说明:本文讨论的内容大部分来自Valve公司公开的HL SDK,关于cstrike的一切数据结构相关的知识产权归Valve所有,本文仅对这些结构中的一些文字进行解释
1.cl_entity_s
struct cl_entity_s 8
{
int index; // Index into cl_entities ( should match actual slot, but not necessarily )
qboolean player; // True if this entity is a "player"
entity_state_t baseline; // The original state from which to delta during an uncompressed message
entity_state_t prevstate; // The state information from the penultimate message received from the server ;
entity_state_t curstate; // The state information from the last message received from server
int current_position; // Last received history update index
position_history_t ph[ HISTORY_MAX ]; // History of position and angle updates for this player
mouth_t mouth; // For synchronizing mouth movements. S&<gAAU8
latchedvars_t latched; // Variables used by studio model rendering routines
// Information based on interplocation, extrapolation, prediction, or just copied from last msg received.
//
float lastmove;
// Actual render position and angles
vec3_t origin;
vec3_t angles;
// Attachment points
vec3_t attachment[4];
// Other entity local information
int trivial_accept;
struct model_s *model; // cl.model_precache[ curstate.modelindes ]; all visible entities have a model
struct efrag_s *efrag; // linked list of efrags
struct mnode_s *topnode; // for bmodels, first world node that splits bmodel, or NULL if not split
float syncbase; // for client-side animations -- used by obsolete alias animation system, remove? UPw-y'
int visframe; // last frame this entity was found in an active leaf
colorVec cvFloorColor;
可以说这个结构是cstrike最重要结构,从字面上看,entity是“实体”的意思,事实上,所有cstrike游戏里,玩家、木仓、灯等等都是一个entity,这个cl_entity_s的结构保存了cstrike游戏里这些"实体"的重要信息,而我们最关心的内容,是vect3_t orgin和vect3_t angles,vect3_t其实就是一个float类型3维数组,origin保存了实体的x,y,z的坐标,angles保存了xyz上个方向上的角度,有了这两个信息,就可以计算出来每个对象在屏幕上的位置了,其实3D游戏最终是在2D的屏幕上显示,欺骗眼睛和人的大脑罢了。(如果你技术够牛逼,那你把人物改成虚体看看,那样的话cs无敌外挂就出来了)
cstrike把所有的这些对象保存在一个cl_entity_s的数组中,而且表示是玩家的entity,总是在下标为1-32这32个元素中,因此cstrike游戏,只能有最多32个玩家。