PlayerIcon.cpp 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. /*
  2. ===========================================================================
  3. Doom 3 GPL Source Code
  4. Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
  5. This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?).
  6. Doom 3 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 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 Source Code. If not, see <http://www.gnu.org/licenses/>.
  16. 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.
  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. #ifdef CTF
  28. ,"mtr_icon_redteam",
  29. "mtr_icon_blueteam"
  30. #endif
  31. };
  32. /*
  33. ===============
  34. idPlayerIcon::idPlayerIcon
  35. ===============
  36. */
  37. idPlayerIcon::idPlayerIcon() {
  38. iconHandle = -1;
  39. iconType = ICON_NONE;
  40. }
  41. /*
  42. ===============
  43. idPlayerIcon::~idPlayerIcon
  44. ===============
  45. */
  46. idPlayerIcon::~idPlayerIcon() {
  47. FreeIcon();
  48. }
  49. /*
  50. ===============
  51. idPlayerIcon::Draw
  52. ===============
  53. */
  54. void idPlayerIcon::Draw( idPlayer *player, jointHandle_t joint ) {
  55. idVec3 origin;
  56. idMat3 axis;
  57. if ( joint == INVALID_JOINT ) {
  58. FreeIcon();
  59. return;
  60. }
  61. player->GetJointWorldTransform( joint, gameLocal.time, origin, axis );
  62. origin.z += 16.0f;
  63. Draw( player, origin );
  64. }
  65. /*
  66. ===============
  67. idPlayerIcon::Draw
  68. ===============
  69. */
  70. void idPlayerIcon::Draw( idPlayer *player, const idVec3 &origin ) {
  71. idPlayer *localPlayer = gameLocal.GetLocalPlayer();
  72. if ( !localPlayer || !localPlayer->GetRenderView() ) {
  73. FreeIcon();
  74. return;
  75. }
  76. idMat3 axis = localPlayer->GetRenderView()->viewaxis;
  77. if ( player->isLagged && !player->spectating ) {
  78. // create the icon if necessary, or update if already created
  79. if ( !CreateIcon( player, ICON_LAG, origin, axis ) ) {
  80. UpdateIcon( player, origin, axis );
  81. }
  82. } else if ( player->isChatting && !player->spectating ) {
  83. if ( !CreateIcon( player, ICON_CHAT, origin, axis ) ) {
  84. UpdateIcon( player, origin, axis );
  85. }
  86. #ifdef CTF
  87. } else if ( g_CTFArrows.GetBool() && gameLocal.mpGame.IsGametypeFlagBased() && gameLocal.GetLocalPlayer() && player->team == gameLocal.GetLocalPlayer()->team && !player->IsHidden() && !player->AI_DEAD ) {
  88. int icon = ICON_TEAM_RED + player->team;
  89. if ( icon != ICON_TEAM_RED && icon != ICON_TEAM_BLUE )
  90. return;
  91. if ( !CreateIcon( player, ( playerIconType_t )icon, origin, axis ) ) {
  92. UpdateIcon( player, origin, axis );
  93. }
  94. #endif
  95. } else {
  96. FreeIcon();
  97. }
  98. }
  99. /*
  100. ===============
  101. idPlayerIcon::FreeIcon
  102. ===============
  103. */
  104. void idPlayerIcon::FreeIcon( void ) {
  105. if ( iconHandle != - 1 ) {
  106. gameRenderWorld->FreeEntityDef( iconHandle );
  107. iconHandle = -1;
  108. }
  109. iconType = ICON_NONE;
  110. }
  111. /*
  112. ===============
  113. idPlayerIcon::CreateIcon
  114. ===============
  115. */
  116. bool idPlayerIcon::CreateIcon( idPlayer *player, playerIconType_t type, const idVec3 &origin, const idMat3 &axis ) {
  117. assert( type != ICON_NONE );
  118. const char *mtr = player->spawnArgs.GetString( iconKeys[ type ], "_default" );
  119. return CreateIcon( player, type, mtr, origin, axis );
  120. }
  121. /*
  122. ===============
  123. idPlayerIcon::CreateIcon
  124. ===============
  125. */
  126. bool idPlayerIcon::CreateIcon( idPlayer *player, playerIconType_t type, const char *mtr, const idVec3 &origin, const idMat3 &axis ) {
  127. assert( type != ICON_NONE );
  128. if ( type == iconType ) {
  129. return false;
  130. }
  131. FreeIcon();
  132. memset( &renderEnt, 0, sizeof( renderEnt ) );
  133. renderEnt.origin = origin;
  134. renderEnt.axis = axis;
  135. renderEnt.shaderParms[ SHADERPARM_RED ] = 1.0f;
  136. renderEnt.shaderParms[ SHADERPARM_GREEN ] = 1.0f;
  137. renderEnt.shaderParms[ SHADERPARM_BLUE ] = 1.0f;
  138. renderEnt.shaderParms[ SHADERPARM_ALPHA ] = 1.0f;
  139. renderEnt.shaderParms[ SHADERPARM_SPRITE_WIDTH ] = 16.0f;
  140. renderEnt.shaderParms[ SHADERPARM_SPRITE_HEIGHT ] = 16.0f;
  141. renderEnt.hModel = renderModelManager->FindModel( "_sprite" );
  142. renderEnt.callback = NULL;
  143. renderEnt.numJoints = 0;
  144. renderEnt.joints = NULL;
  145. renderEnt.customSkin = 0;
  146. renderEnt.noShadow = true;
  147. renderEnt.noSelfShadow = true;
  148. renderEnt.customShader = declManager->FindMaterial( mtr );
  149. renderEnt.referenceShader = 0;
  150. renderEnt.bounds = renderEnt.hModel->Bounds( &renderEnt );
  151. iconHandle = gameRenderWorld->AddEntityDef( &renderEnt );
  152. iconType = type;
  153. return true;
  154. }
  155. /*
  156. ===============
  157. idPlayerIcon::UpdateIcon
  158. ===============
  159. */
  160. void idPlayerIcon::UpdateIcon( idPlayer *player, const idVec3 &origin, const idMat3 &axis ) {
  161. assert( iconHandle >= 0 );
  162. renderEnt.origin = origin;
  163. renderEnt.axis = axis;
  164. gameRenderWorld->UpdateEntityDef( iconHandle, &renderEnt );
  165. }