doom3-gpl
Doom 3 GPL source release
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
PlayerIcon.cpp
Go to the documentation of this file.
1 /*
2 ===========================================================================
3 
4 Doom 3 GPL Source Code
5 Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
6 
7 This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?).
8 
9 Doom 3 Source Code is free software: you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation, either version 3 of the License, or
12 (at your option) any later version.
13 
14 Doom 3 Source Code is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18 
19 You should have received a copy of the GNU General Public License
20 along with Doom 3 Source Code. If not, see <http://www.gnu.org/licenses/>.
21 
22 In addition, the Doom 3 Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 Source Code. If not, please request a copy in writing from id Software at the address below.
23 
24 If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
25 
26 ===========================================================================
27 */
28 
29 #include "../idlib/precompiled.h"
30 #pragma hdrstop
31 
32 #include "Game_local.h"
33 #include "PlayerIcon.h"
34 
35 static const char * iconKeys[ ICON_NONE ] = {
36  "mtr_icon_lag",
37  "mtr_icon_chat"
38 #ifdef CTF
39  ,"mtr_icon_redteam",
40  "mtr_icon_blueteam"
41 #endif
42 };
43 
44 /*
45 ===============
46 idPlayerIcon::idPlayerIcon
47 ===============
48 */
50  iconHandle = -1;
52 }
53 
54 /*
55 ===============
56 idPlayerIcon::~idPlayerIcon
57 ===============
58 */
60  FreeIcon();
61 }
62 
63 /*
64 ===============
65 idPlayerIcon::Draw
66 ===============
67 */
69  idVec3 origin;
70  idMat3 axis;
71 
72  if ( joint == INVALID_JOINT ) {
73  FreeIcon();
74  return;
75  }
76 
77  player->GetJointWorldTransform( joint, gameLocal.time, origin, axis );
78  origin.z += 16.0f;
79 
80  Draw( player, origin );
81 }
82 
83 /*
84 ===============
85 idPlayerIcon::Draw
86 ===============
87 */
88 void idPlayerIcon::Draw( idPlayer *player, const idVec3 &origin ) {
89  idPlayer *localPlayer = gameLocal.GetLocalPlayer();
90  if ( !localPlayer || !localPlayer->GetRenderView() ) {
91  FreeIcon();
92  return;
93  }
94 
95  idMat3 axis = localPlayer->GetRenderView()->viewaxis;
96 
97  if ( player->isLagged && !player->spectating ) {
98  // create the icon if necessary, or update if already created
99  if ( !CreateIcon( player, ICON_LAG, origin, axis ) ) {
100  UpdateIcon( player, origin, axis );
101  }
102  } else if ( player->isChatting && !player->spectating ) {
103  if ( !CreateIcon( player, ICON_CHAT, origin, axis ) ) {
104  UpdateIcon( player, origin, axis );
105  }
106 #ifdef CTF
107  } else if ( g_CTFArrows.GetBool() && gameLocal.mpGame.IsGametypeFlagBased() && gameLocal.GetLocalPlayer() && player->team == gameLocal.GetLocalPlayer()->team && !player->IsHidden() && !player->AI_DEAD ) {
108  int icon = ICON_TEAM_RED + player->team;
109 
110  if ( icon != ICON_TEAM_RED && icon != ICON_TEAM_BLUE )
111  return;
112 
113  if ( !CreateIcon( player, ( playerIconType_t )icon, origin, axis ) ) {
114  UpdateIcon( player, origin, axis );
115  }
116 #endif
117  } else {
118  FreeIcon();
119  }
120 }
121 
122 /*
123 ===============
124 idPlayerIcon::FreeIcon
125 ===============
126 */
128  if ( iconHandle != - 1 ) {
130  iconHandle = -1;
131  }
133 }
134 
135 /*
136 ===============
137 idPlayerIcon::CreateIcon
138 ===============
139 */
141  assert( type != ICON_NONE );
142  const char *mtr = player->spawnArgs.GetString( iconKeys[ type ], "_default" );
143  return CreateIcon( player, type, mtr, origin, axis );
144 }
145 
146 /*
147 ===============
148 idPlayerIcon::CreateIcon
149 ===============
150 */
151 bool idPlayerIcon::CreateIcon( idPlayer *player, playerIconType_t type, const char *mtr, const idVec3 &origin, const idMat3 &axis ) {
152  assert( type != ICON_NONE );
153 
154  if ( type == iconType ) {
155  return false;
156  }
157 
158  FreeIcon();
159 
160  memset( &renderEnt, 0, sizeof( renderEnt ) );
161  renderEnt.origin = origin;
162  renderEnt.axis = axis;
171  renderEnt.numJoints = 0;
173  renderEnt.customSkin = 0;
174  renderEnt.noShadow = true;
175  renderEnt.noSelfShadow = true;
179 
181  iconType = type;
182 
183  return true;
184 }
185 
186 /*
187 ===============
188 idPlayerIcon::UpdateIcon
189 ===============
190 */
191 void idPlayerIcon::UpdateIcon( idPlayer *player, const idVec3 &origin, const idMat3 &axis ) {
192  assert( iconHandle >= 0 );
193 
194  renderEnt.origin = origin;
195  renderEnt.axis = axis;
197 }
198 
jointHandle_t
Definition: Model.h:156
idPlayer * GetLocalPlayer() const
assert(prefInfo.fullscreenBtn)
virtual qhandle_t AddEntityDef(const renderEntity_t *re)=0
const idMaterial * referenceShader
Definition: RenderWorld.h:124
float z
Definition: Vector.h:320
const int SHADERPARM_SPRITE_WIDTH
Definition: RenderWorld.h:68
Definition: Vector.h:316
const int SHADERPARM_GREEN
Definition: RenderWorld.h:47
int team
Definition: Actor.h:115
GLuint GLuint GLsizei GLenum type
Definition: glext.h:2845
void UpdateIcon(idPlayer *player, const idVec3 &origin, const idMat3 &axis)
Definition: PlayerIcon.cpp:191
virtual const idMaterial * FindMaterial(const char *name, bool makeDefault=true)=0
idDict spawnArgs
Definition: Entity.h:122
playerIconType_t
Definition: PlayerIcon.h:32
deferredEntityCallback_t callback
Definition: RenderWorld.h:96
const idMaterial * customShader
Definition: RenderWorld.h:123
const int SHADERPARM_ALPHA
Definition: RenderWorld.h:49
playerIconType_t iconType
Definition: PlayerIcon.h:53
bool IsHidden(void) const
Definition: Entity.cpp:1217
const int SHADERPARM_BLUE
Definition: RenderWorld.h:48
virtual void FreeEntityDef(qhandle_t entityHandle)=0
bool CreateIcon(idPlayer *player, playerIconType_t type, const char *mtr, const idVec3 &origin, const idMat3 &axis)
Definition: PlayerIcon.cpp:151
const char * GetString(const char *key, const char *defaultString="") const
Definition: Dict.h:240
idJointMat * joints
Definition: RenderWorld.h:135
#define NULL
Definition: Lib.h:88
const idDeclSkin * customSkin
Definition: RenderWorld.h:125
virtual idRenderModel * FindModel(const char *modelName)=0
void FreeIcon(void)
Definition: PlayerIcon.cpp:127
renderView_t * GetRenderView(void)
renderEntity_t renderEnt
Definition: PlayerIcon.h:54
virtual void UpdateEntityDef(qhandle_t entityHandle, const renderEntity_t *re)=0
idGameLocal gameLocal
Definition: Game_local.cpp:64
idRenderModel * hModel
Definition: RenderWorld.h:81
virtual idBounds Bounds(const struct renderEntity_s *ent=NULL) const =0
idDeclManager * declManager
bool isLagged
Definition: Player.h:361
qhandle_t iconHandle
Definition: PlayerIcon.h:55
idScriptBool AI_DEAD
Definition: Player.h:279
idRenderModelManager * renderModelManager
Definition: Matrix.h:333
const int SHADERPARM_RED
Definition: RenderWorld.h:46
const int SHADERPARM_SPRITE_HEIGHT
Definition: RenderWorld.h:69
bool IsGametypeFlagBased(void)
bool GetJointWorldTransform(jointHandle_t jointHandle, int currentTime, idVec3 &offset, idMat3 &axis)
Definition: Entity.cpp:5248
idBounds bounds
Definition: RenderWorld.h:95
void Draw(idPlayer *player, jointHandle_t joint)
Definition: PlayerIcon.cpp:68
idRenderWorld * gameRenderWorld
Definition: Game_local.cpp:55
idMultiplayerGame mpGame
Definition: Game_local.h:305
idPlayer * player
Definition: PlayerView.h:417
idMat3 viewaxis
Definition: RenderWorld.h:216
float shaderParms[MAX_ENTITY_SHADER_PARMS]
Definition: RenderWorld.h:127
bool spectating
Definition: Player.h:340
bool isChatting
Definition: Player.h:362