PageRenderTime 146ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/indra/newview/llviewerparcelmediaautoplay.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 162 lines | 104 code | 28 blank | 30 comment | 16 complexity | abf96c6d1e474d84a3a1bf6695b5753b MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file llviewerparcelmediaautoplay.cpp
  3. * @brief timer to automatically play media in a parcel
  4. *
  5. * $LicenseInfo:firstyear=2007&license=viewerlgpl$
  6. * Second Life Viewer Source Code
  7. * Copyright (C) 2010, Linden Research, Inc.
  8. *
  9. * This library is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU Lesser General Public
  11. * License as published by the Free Software Foundation;
  12. * version 2.1 of the License only.
  13. *
  14. * This library is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. * Lesser General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Lesser General Public
  20. * License along with this library; if not, write to the Free Software
  21. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  22. *
  23. * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
  24. * $/LicenseInfo$
  25. */
  26. #include "llviewerprecompiledheaders.h"
  27. #include "llviewerparcelmediaautoplay.h"
  28. #include "llviewerparcelmedia.h"
  29. #include "llviewercontrol.h"
  30. #include "llviewermedia.h"
  31. #include "llviewerregion.h"
  32. #include "llparcel.h"
  33. #include "llviewerparcelmgr.h"
  34. #include "lluuid.h"
  35. #include "message.h"
  36. #include "llviewertexturelist.h" // for texture stats
  37. #include "llagent.h"
  38. #include "llmimetypes.h"
  39. const F32 AUTOPLAY_TIME = 5; // how many seconds before we autoplay
  40. const F32 AUTOPLAY_SIZE = 24*24; // how big the texture must be (pixel area) before we autoplay
  41. const F32 AUTOPLAY_SPEED = 0.1f; // how slow should the agent be moving to autoplay
  42. LLViewerParcelMediaAutoPlay::LLViewerParcelMediaAutoPlay() :
  43. LLEventTimer(1),
  44. mLastParcelID(-1),
  45. mPlayed(FALSE),
  46. mTimeInParcel(0)
  47. {
  48. }
  49. static LLViewerParcelMediaAutoPlay *sAutoPlay = NULL;
  50. // static
  51. void LLViewerParcelMediaAutoPlay::initClass()
  52. {
  53. if (!sAutoPlay)
  54. sAutoPlay = new LLViewerParcelMediaAutoPlay;
  55. }
  56. // static
  57. void LLViewerParcelMediaAutoPlay::cleanupClass()
  58. {
  59. if (sAutoPlay)
  60. delete sAutoPlay;
  61. }
  62. // static
  63. void LLViewerParcelMediaAutoPlay::playStarted()
  64. {
  65. if (sAutoPlay)
  66. {
  67. sAutoPlay->mPlayed = TRUE;
  68. }
  69. }
  70. BOOL LLViewerParcelMediaAutoPlay::tick()
  71. {
  72. LLParcel *this_parcel = NULL;
  73. LLViewerRegion *this_region = NULL;
  74. std::string this_media_url;
  75. std::string this_media_type;
  76. LLUUID this_media_texture_id;
  77. S32 this_parcel_id = 0;
  78. LLUUID this_region_id;
  79. this_region = gAgent.getRegion();
  80. if (this_region)
  81. {
  82. this_region_id = this_region->getRegionID();
  83. }
  84. this_parcel = LLViewerParcelMgr::getInstance()->getAgentParcel();
  85. if (this_parcel)
  86. {
  87. this_media_url = this_parcel->getMediaURL();
  88. this_media_type = this_parcel->getMediaType();
  89. this_media_texture_id = this_parcel->getMediaID();
  90. this_parcel_id = this_parcel->getLocalID();
  91. }
  92. if (this_parcel_id != mLastParcelID ||
  93. this_region_id != mLastRegionID)
  94. {
  95. // we've entered a new parcel
  96. mPlayed = FALSE; // we haven't autoplayed yet
  97. mTimeInParcel = 0; // reset our timer
  98. mLastParcelID = this_parcel_id;
  99. mLastRegionID = this_region_id;
  100. }
  101. mTimeInParcel += mPeriod; // increase mTimeInParcel by the amount of time between ticks
  102. if ((!mPlayed) && // if we've never played
  103. (mTimeInParcel > AUTOPLAY_TIME) && // and if we've been here for so many seconds
  104. (!this_media_url.empty()) && // and if the parcel has media
  105. (stricmp(this_media_type.c_str(), LLMIMETypes::getDefaultMimeType().c_str()) != 0) &&
  106. (LLViewerParcelMedia::sMediaImpl.isNull())) // and if the media is not already playing
  107. {
  108. if (this_media_texture_id.notNull()) // and if the media texture is good
  109. {
  110. LLViewerMediaTexture *image = LLViewerTextureManager::getMediaTexture(this_media_texture_id, FALSE) ;
  111. F32 image_size = 0;
  112. if (image)
  113. {
  114. image_size = image->getMaxVirtualSize() ;
  115. }
  116. if (gAgent.getVelocity().magVec() < AUTOPLAY_SPEED) // and if the agent is stopped (slow enough)
  117. {
  118. if (image_size > AUTOPLAY_SIZE) // and if the target texture is big enough on screen
  119. {
  120. if (this_parcel)
  121. {
  122. if (gSavedSettings.getBOOL("ParcelMediaAutoPlayEnable"))
  123. {
  124. // and last but not least, only play when autoplay is enabled
  125. LLViewerParcelMedia::play(this_parcel);
  126. }
  127. }
  128. mPlayed = TRUE;
  129. }
  130. }
  131. }
  132. }
  133. return FALSE; // continue ticking forever please.
  134. }