]> icculus.org git repositories - icculus/iodoom3.git/blob - neo/d3xp/PlayerIcon.cpp
Various Mac OS X tweaks to get this to build. Probably breaking things.
[icculus/iodoom3.git] / neo / d3xp / PlayerIcon.cpp
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 */
49 idPlayerIcon::idPlayerIcon() {
50         iconHandle      = -1;
51         iconType        = ICON_NONE;
52 }
53
54 /*
55 ===============
56 idPlayerIcon::~idPlayerIcon
57 ===============
58 */
59 idPlayerIcon::~idPlayerIcon() {
60         FreeIcon();
61 }
62
63 /*
64 ===============
65 idPlayerIcon::Draw
66 ===============
67 */
68 void idPlayerIcon::Draw( idPlayer *player, jointHandle_t joint ) {
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 */
127 void idPlayerIcon::FreeIcon( void ) {
128         if ( iconHandle != - 1 ) {
129                 gameRenderWorld->FreeEntityDef( iconHandle );
130                 iconHandle = -1;
131         }
132         iconType = ICON_NONE;
133 }
134
135 /*
136 ===============
137 idPlayerIcon::CreateIcon
138 ===============
139 */
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 );
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;
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 );
179
180         iconHandle = gameRenderWorld->AddEntityDef( &renderEnt );
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;
196         gameRenderWorld->UpdateEntityDef( iconHandle, &renderEnt );
197 }
198