123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191 |
- #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"
- ,"mtr_icon_redteam",
- "mtr_icon_blueteam"
- };
- idPlayerIcon::idPlayerIcon() {
- iconHandle = -1;
- iconType = ICON_NONE;
- }
- idPlayerIcon::~idPlayerIcon() {
- FreeIcon();
- }
- 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 );
- }
- 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 ) {
-
- if ( !CreateIcon( player, ICON_LAG, origin, axis ) ) {
- UpdateIcon( player, origin, axis );
- }
- } 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 );
- }
- } else {
- FreeIcon();
- }
- }
- void idPlayerIcon::FreeIcon() {
- if ( iconHandle != - 1 ) {
- gameRenderWorld->FreeEntityDef( iconHandle );
- iconHandle = -1;
- }
- iconType = ICON_NONE;
- }
- 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 );
- }
- 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;
- }
- void idPlayerIcon::UpdateIcon( idPlayer *player, const idVec3 &origin, const idMat3 &axis ) {
- assert( iconHandle >= 0 );
- renderEnt.origin = origin;
- renderEnt.axis = axis;
- gameRenderWorld->UpdateEntityDef( iconHandle, &renderEnt );
- }
|