2 ===========================================================================
5 Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
7 This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?).
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.
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.
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/>.
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.
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.
26 ===========================================================================
29 #include "../idlib/precompiled.h"
32 #include "Game_local.h"
33 #include "PlayerIcon.h"
35 static const char * iconKeys[ ICON_NONE ] = {
46 idPlayerIcon::idPlayerIcon
49 idPlayerIcon::idPlayerIcon() {
56 idPlayerIcon::~idPlayerIcon
59 idPlayerIcon::~idPlayerIcon() {
68 void idPlayerIcon::Draw( idPlayer *player, jointHandle_t joint ) {
72 if ( joint == INVALID_JOINT ) {
77 player->GetJointWorldTransform( joint, gameLocal.time, origin, axis );
80 Draw( player, origin );
88 void idPlayerIcon::Draw( idPlayer *player, const idVec3 &origin ) {
89 idPlayer *localPlayer = gameLocal.GetLocalPlayer();
90 if ( !localPlayer || !localPlayer->GetRenderView() ) {
95 idMat3 axis = localPlayer->GetRenderView()->viewaxis;
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 );
102 } else if ( player->isChatting && !player->spectating ) {
103 if ( !CreateIcon( player, ICON_CHAT, origin, axis ) ) {
104 UpdateIcon( player, origin, axis );
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;
110 if ( icon != ICON_TEAM_RED && icon != ICON_TEAM_BLUE )
113 if ( !CreateIcon( player, ( playerIconType_t )icon, origin, axis ) ) {
114 UpdateIcon( player, origin, axis );
124 idPlayerIcon::FreeIcon
127 void idPlayerIcon::FreeIcon( void ) {
128 if ( iconHandle != - 1 ) {
129 gameRenderWorld->FreeEntityDef( iconHandle );
132 iconType = ICON_NONE;
137 idPlayerIcon::CreateIcon
140 bool idPlayerIcon::CreateIcon( idPlayer *player, playerIconType_t type, const idVec3 &origin, const idMat3 &axis ) {
141 assert( type != ICON_NONE );
142 const char *mtr = player->spawnArgs.GetString( iconKeys[ type ], "_default" );
143 return CreateIcon( player, type, mtr, origin, axis );
148 idPlayerIcon::CreateIcon
151 bool idPlayerIcon::CreateIcon( idPlayer *player, playerIconType_t type, const char *mtr, const idVec3 &origin, const idMat3 &axis ) {
152 assert( type != ICON_NONE );
154 if ( type == iconType ) {
160 memset( &renderEnt, 0, sizeof( renderEnt ) );
161 renderEnt.origin = origin;
162 renderEnt.axis = axis;
163 renderEnt.shaderParms[ SHADERPARM_RED ] = 1.0f;
164 renderEnt.shaderParms[ SHADERPARM_GREEN ] = 1.0f;
165 renderEnt.shaderParms[ SHADERPARM_BLUE ] = 1.0f;
166 renderEnt.shaderParms[ SHADERPARM_ALPHA ] = 1.0f;
167 renderEnt.shaderParms[ SHADERPARM_SPRITE_WIDTH ] = 16.0f;
168 renderEnt.shaderParms[ SHADERPARM_SPRITE_HEIGHT ] = 16.0f;
169 renderEnt.hModel = renderModelManager->FindModel( "_sprite" );
170 renderEnt.callback = NULL;
171 renderEnt.numJoints = 0;
172 renderEnt.joints = NULL;
173 renderEnt.customSkin = 0;
174 renderEnt.noShadow = true;
175 renderEnt.noSelfShadow = true;
176 renderEnt.customShader = declManager->FindMaterial( mtr );
177 renderEnt.referenceShader = 0;
178 renderEnt.bounds = renderEnt.hModel->Bounds( &renderEnt );
180 iconHandle = gameRenderWorld->AddEntityDef( &renderEnt );
188 idPlayerIcon::UpdateIcon
191 void idPlayerIcon::UpdateIcon( idPlayer *player, const idVec3 &origin, const idMat3 &axis ) {
192 assert( iconHandle >= 0 );
194 renderEnt.origin = origin;
195 renderEnt.axis = axis;
196 gameRenderWorld->UpdateEntityDef( iconHandle, &renderEnt );