123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199 |
- /*
- ===========================================================================
- Doom 3 GPL Source Code
- Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
- This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?).
- Doom 3 Source Code is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
- Doom 3 Source Code is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
- You should have received a copy of the GNU General Public License
- along with Doom 3 Source Code. If not, see <http://www.gnu.org/licenses/>.
- 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.
- 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.
- ===========================================================================
- */
- #include "../idlib/precompiled.h"
- #pragma hdrstop
- #include "Game_local.h"
- #include "PlayerIcon.h"
- static const char * iconKeys[ ICON_NONE ] = {
- "mtr_icon_lag",
- "mtr_icon_chat"
- #ifdef CTF
- ,"mtr_icon_redteam",
- "mtr_icon_blueteam"
- #endif
- };
- /*
- ===============
- idPlayerIcon::idPlayerIcon
- ===============
- */
- idPlayerIcon::idPlayerIcon() {
- iconHandle = -1;
- iconType = ICON_NONE;
- }
- /*
- ===============
- idPlayerIcon::~idPlayerIcon
- ===============
- */
- idPlayerIcon::~idPlayerIcon() {
- FreeIcon();
- }
- /*
- ===============
- idPlayerIcon::Draw
- ===============
- */
- void idPlayerIcon::Draw( idPlayer *player, jointHandle_t joint ) {
- idVec3 origin;
- idMat3 axis;
- if ( joint == INVALID_JOINT ) {
- FreeIcon();
- return;
- }
- player->GetJointWorldTransform( joint, gameLocal.time, origin, axis );
- origin.z += 16.0f;
- Draw( player, origin );
- }
- /*
- ===============
- idPlayerIcon::Draw
- ===============
- */
- void idPlayerIcon::Draw( idPlayer *player, const idVec3 &origin ) {
- idPlayer *localPlayer = gameLocal.GetLocalPlayer();
- if ( !localPlayer || !localPlayer->GetRenderView() ) {
- FreeIcon();
- return;
- }
- idMat3 axis = localPlayer->GetRenderView()->viewaxis;
- if ( player->isLagged && !player->spectating ) {
- // create the icon if necessary, or update if already created
- if ( !CreateIcon( player, ICON_LAG, origin, axis ) ) {
- UpdateIcon( player, origin, axis );
- }
- } else if ( player->isChatting && !player->spectating ) {
- if ( !CreateIcon( player, ICON_CHAT, origin, axis ) ) {
- UpdateIcon( player, origin, axis );
- }
- #ifdef CTF
- } else if ( g_CTFArrows.GetBool() && gameLocal.mpGame.IsGametypeFlagBased() && gameLocal.GetLocalPlayer() && player->team == gameLocal.GetLocalPlayer()->team && !player->IsHidden() && !player->AI_DEAD ) {
- int icon = ICON_TEAM_RED + player->team;
- if ( icon != ICON_TEAM_RED && icon != ICON_TEAM_BLUE )
- return;
- if ( !CreateIcon( player, ( playerIconType_t )icon, origin, axis ) ) {
- UpdateIcon( player, origin, axis );
- }
- #endif
- } else {
- FreeIcon();
- }
- }
- /*
- ===============
- idPlayerIcon::FreeIcon
- ===============
- */
- void idPlayerIcon::FreeIcon( void ) {
- if ( iconHandle != - 1 ) {
- gameRenderWorld->FreeEntityDef( iconHandle );
- iconHandle = -1;
- }
- iconType = ICON_NONE;
- }
- /*
- ===============
- idPlayerIcon::CreateIcon
- ===============
- */
- bool idPlayerIcon::CreateIcon( idPlayer *player, playerIconType_t type, const idVec3 &origin, const idMat3 &axis ) {
- assert( type != ICON_NONE );
- const char *mtr = player->spawnArgs.GetString( iconKeys[ type ], "_default" );
- return CreateIcon( player, type, mtr, origin, axis );
- }
- /*
- ===============
- idPlayerIcon::CreateIcon
- ===============
- */
- bool idPlayerIcon::CreateIcon( idPlayer *player, playerIconType_t type, const char *mtr, const idVec3 &origin, const idMat3 &axis ) {
- assert( type != ICON_NONE );
- if ( type == iconType ) {
- return false;
- }
- FreeIcon();
- memset( &renderEnt, 0, sizeof( renderEnt ) );
- renderEnt.origin = origin;
- renderEnt.axis = axis;
- renderEnt.shaderParms[ SHADERPARM_RED ] = 1.0f;
- renderEnt.shaderParms[ SHADERPARM_GREEN ] = 1.0f;
- renderEnt.shaderParms[ SHADERPARM_BLUE ] = 1.0f;
- renderEnt.shaderParms[ SHADERPARM_ALPHA ] = 1.0f;
- renderEnt.shaderParms[ SHADERPARM_SPRITE_WIDTH ] = 16.0f;
- renderEnt.shaderParms[ SHADERPARM_SPRITE_HEIGHT ] = 16.0f;
- renderEnt.hModel = renderModelManager->FindModel( "_sprite" );
- renderEnt.callback = NULL;
- renderEnt.numJoints = 0;
- renderEnt.joints = NULL;
- renderEnt.customSkin = 0;
- renderEnt.noShadow = true;
- renderEnt.noSelfShadow = true;
- renderEnt.customShader = declManager->FindMaterial( mtr );
- renderEnt.referenceShader = 0;
- renderEnt.bounds = renderEnt.hModel->Bounds( &renderEnt );
- iconHandle = gameRenderWorld->AddEntityDef( &renderEnt );
- iconType = type;
- return true;
- }
- /*
- ===============
- idPlayerIcon::UpdateIcon
- ===============
- */
- void idPlayerIcon::UpdateIcon( idPlayer *player, const idVec3 &origin, const idMat3 &axis ) {
- assert( iconHandle >= 0 );
- renderEnt.origin = origin;
- renderEnt.axis = axis;
- gameRenderWorld->UpdateEntityDef( iconHandle, &renderEnt );
- }
|