PlayerIcon.cpp 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. /*
  2. ===========================================================================
  3. Doom 3 BFG Edition GPL Source Code
  4. Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company.
  5. This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code").
  6. Doom 3 BFG Edition Source Code is free software: you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation, either version 3 of the License, or
  9. (at your option) any later version.
  10. Doom 3 BFG Edition Source Code is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU General Public License for more details.
  14. You should have received a copy of the GNU General Public License
  15. along with Doom 3 BFG Edition Source Code. If not, see <http://www.gnu.org/licenses/>.
  16. In addition, the Doom 3 BFG Edition 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 BFG Edition Source Code. If not, please request a copy in writing from id Software at the address below.
  17. 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.
  18. ===========================================================================
  19. */
  20. #include "../idlib/precompiled.h"
  21. #pragma hdrstop
  22. #include "Game_local.h"
  23. #include "PlayerIcon.h"
  24. static const char * iconKeys[ ICON_NONE ] = {
  25. "mtr_icon_lag",
  26. "mtr_icon_chat"
  27. ,"mtr_icon_redteam",
  28. "mtr_icon_blueteam"
  29. };
  30. /*
  31. ===============
  32. idPlayerIcon::idPlayerIcon
  33. ===============
  34. */
  35. idPlayerIcon::idPlayerIcon() {
  36. iconHandle = -1;
  37. iconType = ICON_NONE;
  38. }
  39. /*
  40. ===============
  41. idPlayerIcon::~idPlayerIcon
  42. ===============
  43. */
  44. idPlayerIcon::~idPlayerIcon() {
  45. FreeIcon();
  46. }
  47. /*
  48. ===============
  49. idPlayerIcon::Draw
  50. ===============
  51. */
  52. void idPlayerIcon::Draw( idPlayer *player, jointHandle_t joint ) {
  53. idVec3 origin;
  54. idMat3 axis;
  55. if ( joint == INVALID_JOINT ) {
  56. FreeIcon();
  57. return;
  58. }
  59. player->GetJointWorldTransform( joint, gameLocal.time, origin, axis );
  60. origin.z += 16.0f;
  61. Draw( player, origin );
  62. }
  63. /*
  64. ===============
  65. idPlayerIcon::Draw
  66. ===============
  67. */
  68. void idPlayerIcon::Draw( idPlayer *player, const idVec3 &origin ) {
  69. idPlayer *localPlayer = gameLocal.GetLocalPlayer();
  70. if ( !localPlayer || !localPlayer->GetRenderView() ) {
  71. FreeIcon();
  72. return;
  73. }
  74. idMat3 axis = localPlayer->GetRenderView()->viewaxis;
  75. if ( player->isLagged && !player->spectating ) {
  76. // create the icon if necessary, or update if already created
  77. if ( !CreateIcon( player, ICON_LAG, origin, axis ) ) {
  78. UpdateIcon( player, origin, axis );
  79. }
  80. } else if ( g_CTFArrows.GetBool() && gameLocal.mpGame.IsGametypeFlagBased() && gameLocal.GetLocalPlayer() && player->team == gameLocal.GetLocalPlayer()->team && !player->IsHidden() && !player->AI_DEAD ) {
  81. int icon = ICON_TEAM_RED + player->team;
  82. if ( icon != ICON_TEAM_RED && icon != ICON_TEAM_BLUE )
  83. return;
  84. if ( !CreateIcon( player, ( playerIconType_t )icon, origin, axis ) ) {
  85. UpdateIcon( player, origin, axis );
  86. }
  87. } else {
  88. FreeIcon();
  89. }
  90. }
  91. /*
  92. ===============
  93. idPlayerIcon::FreeIcon
  94. ===============
  95. */
  96. void idPlayerIcon::FreeIcon() {
  97. if ( iconHandle != - 1 ) {
  98. gameRenderWorld->FreeEntityDef( iconHandle );
  99. iconHandle = -1;
  100. }
  101. iconType = ICON_NONE;
  102. }
  103. /*
  104. ===============
  105. idPlayerIcon::CreateIcon
  106. ===============
  107. */
  108. bool idPlayerIcon::CreateIcon( idPlayer *player, playerIconType_t type, const idVec3 &origin, const idMat3 &axis ) {
  109. assert( type < ICON_NONE );
  110. const char *mtr = player->spawnArgs.GetString( iconKeys[ type ], "_default" );
  111. return CreateIcon( player, type, mtr, origin, axis );
  112. }
  113. /*
  114. ===============
  115. idPlayerIcon::CreateIcon
  116. ===============
  117. */
  118. bool idPlayerIcon::CreateIcon( idPlayer *player, playerIconType_t type, const char *mtr, const idVec3 &origin, const idMat3 &axis ) {
  119. assert( type != ICON_NONE );
  120. if ( type == iconType ) {
  121. return false;
  122. }
  123. FreeIcon();
  124. memset( &renderEnt, 0, sizeof( renderEnt ) );
  125. renderEnt.origin = origin;
  126. renderEnt.axis = axis;
  127. renderEnt.shaderParms[ SHADERPARM_RED ] = 1.0f;
  128. renderEnt.shaderParms[ SHADERPARM_GREEN ] = 1.0f;
  129. renderEnt.shaderParms[ SHADERPARM_BLUE ] = 1.0f;
  130. renderEnt.shaderParms[ SHADERPARM_ALPHA ] = 1.0f;
  131. renderEnt.shaderParms[ SHADERPARM_SPRITE_WIDTH ] = 16.0f;
  132. renderEnt.shaderParms[ SHADERPARM_SPRITE_HEIGHT ] = 16.0f;
  133. renderEnt.hModel = renderModelManager->FindModel( "_sprite" );
  134. renderEnt.callback = NULL;
  135. renderEnt.numJoints = 0;
  136. renderEnt.joints = NULL;
  137. renderEnt.customSkin = 0;
  138. renderEnt.noShadow = true;
  139. renderEnt.noSelfShadow = true;
  140. renderEnt.customShader = declManager->FindMaterial( mtr );
  141. renderEnt.referenceShader = 0;
  142. renderEnt.bounds = renderEnt.hModel->Bounds( &renderEnt );
  143. iconHandle = gameRenderWorld->AddEntityDef( &renderEnt );
  144. iconType = type;
  145. return true;
  146. }
  147. /*
  148. ===============
  149. idPlayerIcon::UpdateIcon
  150. ===============
  151. */
  152. void idPlayerIcon::UpdateIcon( idPlayer *player, const idVec3 &origin, const idMat3 &axis ) {
  153. assert( iconHandle >= 0 );
  154. renderEnt.origin = origin;
  155. renderEnt.axis = axis;
  156. gameRenderWorld->UpdateEntityDef( iconHandle, &renderEnt );
  157. }