PlayerIcon.cpp 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  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. };
  28. /*
  29. ===============
  30. idPlayerIcon::idPlayerIcon
  31. ===============
  32. */
  33. idPlayerIcon::idPlayerIcon() {
  34. iconHandle = -1;
  35. iconType = ICON_NONE;
  36. }
  37. /*
  38. ===============
  39. idPlayerIcon::~idPlayerIcon
  40. ===============
  41. */
  42. idPlayerIcon::~idPlayerIcon() {
  43. FreeIcon();
  44. }
  45. /*
  46. ===============
  47. idPlayerIcon::Draw
  48. ===============
  49. */
  50. void idPlayerIcon::Draw( idPlayer *player, jointHandle_t joint ) {
  51. idVec3 origin;
  52. idMat3 axis;
  53. if ( joint == INVALID_JOINT ) {
  54. FreeIcon();
  55. return;
  56. }
  57. player->GetJointWorldTransform( joint, gameLocal.time, origin, axis );
  58. origin.z += 16.0f;
  59. Draw( player, origin );
  60. }
  61. /*
  62. ===============
  63. idPlayerIcon::Draw
  64. ===============
  65. */
  66. void idPlayerIcon::Draw( idPlayer *player, const idVec3 &origin ) {
  67. idPlayer *localPlayer = gameLocal.GetLocalPlayer();
  68. if ( !localPlayer || !localPlayer->GetRenderView() ) {
  69. FreeIcon();
  70. return;
  71. }
  72. idMat3 axis = localPlayer->GetRenderView()->viewaxis;
  73. if ( player->isLagged ) {
  74. // create the icon if necessary, or update if already created
  75. if ( !CreateIcon( player, ICON_LAG, origin, axis ) ) {
  76. UpdateIcon( player, origin, axis );
  77. }
  78. } else if ( player->isChatting ) {
  79. if ( !CreateIcon( player, ICON_CHAT, origin, axis ) ) {
  80. UpdateIcon( player, origin, axis );
  81. }
  82. } else {
  83. FreeIcon();
  84. }
  85. }
  86. /*
  87. ===============
  88. idPlayerIcon::FreeIcon
  89. ===============
  90. */
  91. void idPlayerIcon::FreeIcon( void ) {
  92. if ( iconHandle != - 1 ) {
  93. gameRenderWorld->FreeEntityDef( iconHandle );
  94. iconHandle = -1;
  95. }
  96. iconType = ICON_NONE;
  97. }
  98. /*
  99. ===============
  100. idPlayerIcon::CreateIcon
  101. ===============
  102. */
  103. bool idPlayerIcon::CreateIcon( idPlayer *player, playerIconType_t type, const idVec3 &origin, const idMat3 &axis ) {
  104. assert( type != ICON_NONE );
  105. const char *mtr = player->spawnArgs.GetString( iconKeys[ type ], "_default" );
  106. return CreateIcon( player, type, mtr, origin, axis );
  107. }
  108. /*
  109. ===============
  110. idPlayerIcon::CreateIcon
  111. ===============
  112. */
  113. bool idPlayerIcon::CreateIcon( idPlayer *player, playerIconType_t type, const char *mtr, const idVec3 &origin, const idMat3 &axis ) {
  114. assert( type != ICON_NONE );
  115. if ( type == iconType ) {
  116. return false;
  117. }
  118. FreeIcon();
  119. memset( &renderEnt, 0, sizeof( renderEnt ) );
  120. renderEnt.origin = origin;
  121. renderEnt.axis = axis;
  122. renderEnt.shaderParms[ SHADERPARM_RED ] = 1.0f;
  123. renderEnt.shaderParms[ SHADERPARM_GREEN ] = 1.0f;
  124. renderEnt.shaderParms[ SHADERPARM_BLUE ] = 1.0f;
  125. renderEnt.shaderParms[ SHADERPARM_ALPHA ] = 1.0f;
  126. renderEnt.shaderParms[ SHADERPARM_SPRITE_WIDTH ] = 16.0f;
  127. renderEnt.shaderParms[ SHADERPARM_SPRITE_HEIGHT ] = 16.0f;
  128. renderEnt.hModel = renderModelManager->FindModel( "_sprite" );
  129. renderEnt.callback = NULL;
  130. renderEnt.numJoints = 0;
  131. renderEnt.joints = NULL;
  132. renderEnt.customSkin = 0;
  133. renderEnt.noShadow = true;
  134. renderEnt.noSelfShadow = true;
  135. renderEnt.customShader = declManager->FindMaterial( mtr );
  136. renderEnt.referenceShader = 0;
  137. renderEnt.bounds = renderEnt.hModel->Bounds( &renderEnt );
  138. iconHandle = gameRenderWorld->AddEntityDef( &renderEnt );
  139. iconType = type;
  140. return true;
  141. }
  142. /*
  143. ===============
  144. idPlayerIcon::UpdateIcon
  145. ===============
  146. */
  147. void idPlayerIcon::UpdateIcon( idPlayer *player, const idVec3 &origin, const idMat3 &axis ) {
  148. assert( iconHandle >= 0 );
  149. renderEnt.origin = origin;
  150. renderEnt.axis = axis;
  151. gameRenderWorld->UpdateEntityDef( iconHandle, &renderEnt );
  152. }