llviewerparcelmediaautoplay.cpp

Go to the documentation of this file.
00001 
00032 #include "llviewerprecompiledheaders.h"
00033 #include "llviewerparcelmediaautoplay.h"
00034 #include "llviewerparcelmedia.h"
00035 #include "llviewercontrol.h"
00036 #include "llviewermedia.h"
00037 #include "llparcel.h"
00038 #include "llviewerparcelmgr.h"
00039 #include "lluuid.h"
00040 #include "message.h"
00041 #include "llviewerimagelist.h"         // for texture stats
00042 #include "llagent.h"
00043 
00044 const F32 AUTOPLAY_TIME  = 5;          // how many seconds before we autoplay
00045 const F32 AUTOPLAY_SIZE  = 24*24;      // how big the texture must be (pixel area) before we autoplay
00046 const F32 AUTOPLAY_SPEED = 0.1f;        // how slow should the agent be moving to autoplay
00047 
00048 LLViewerParcelMediaAutoPlay::LLViewerParcelMediaAutoPlay() :
00049         LLEventTimer(1),
00050         mPlayed(FALSE),
00051         mTimeInParcel(0)
00052 {
00053 }
00054 
00055 static LLViewerParcelMediaAutoPlay *sAutoPlay = NULL;
00056 
00057 // static
00058 void LLViewerParcelMediaAutoPlay::initClass()
00059 {
00060         if (!sAutoPlay)
00061                 sAutoPlay = new LLViewerParcelMediaAutoPlay;
00062 }
00063 
00064 // static
00065 void LLViewerParcelMediaAutoPlay::cleanupClass()
00066 {
00067         if (sAutoPlay)
00068                 delete sAutoPlay;
00069 }
00070 
00071 // static
00072 void LLViewerParcelMediaAutoPlay::playStarted()
00073 {
00074         if (sAutoPlay)
00075         {
00076                 sAutoPlay->mPlayed = TRUE;
00077         }
00078 }
00079 
00080 BOOL LLViewerParcelMediaAutoPlay::tick()
00081 {
00082         LLParcel *this_parcel = NULL;
00083         std::string this_media_url;
00084         LLUUID this_media_texture_id;
00085         S32 this_parcel_id = 0;
00086 
00087         this_parcel = LLViewerParcelMgr::getInstance()->getAgentParcel();
00088 
00089         if (this_parcel)
00090         {
00091                 this_media_url = std::string(this_parcel->getMediaURL());
00092 
00093                 this_media_texture_id = this_parcel->getMediaID();
00094 
00095                 this_parcel_id = this_parcel->getLocalID();
00096         }
00097 
00098         if (this_parcel_id != mLastParcelID)
00099         {
00100                 // we've entered a new parcel
00101                 mPlayed    = FALSE;                   // we haven't autoplayed yet
00102                 mTimeInParcel = 0;                    // reset our timer
00103                 mLastParcelID = this_parcel_id;
00104         }
00105 
00106         mTimeInParcel += mPeriod;                 // increase mTimeInParcel by the amount of time between ticks
00107 
00108         if ((!mPlayed) &&                         // if we've never played
00109                 (mTimeInParcel > AUTOPLAY_TIME) &&    // and if we've been here for so many seconds
00110                 (this_media_url.size() != 0) &&       // and if the parcel has media
00111                 (!LLViewerMedia::isMediaPlaying()))   // and if the media is not already playing
00112         {
00113                 if (this_media_texture_id.notNull())  // and if the media texture is good
00114                 {
00115                         LLViewerImage *image = gImageList.getImage(this_media_texture_id, FALSE);
00116 
00117                         F32 image_size = 0;
00118 
00119                         if (image)
00120                         {
00121                                 image_size = image->mMaxVirtualSize;
00122                         }
00123 
00124                         if (gAgent.getVelocity().magVec() < AUTOPLAY_SPEED) // and if the agent is stopped (slow enough)
00125                         {
00126                                 if (image_size > AUTOPLAY_SIZE)    // and if the target texture is big enough on screen
00127                                 {
00128                                         if (this_parcel)
00129                                         {
00130                                                 if (gSavedSettings.getBOOL("ParcelMediaAutoPlayEnable"))
00131                                                 {
00132                                                         // and last but not least, only play when autoplay is enabled
00133                                                         LLViewerParcelMedia::play(this_parcel);
00134                                                 }
00135                                         }
00136 
00137                                         mPlayed = TRUE;
00138                                 }
00139                         }
00140                 }
00141         }
00142 
00143 
00144         return FALSE; // continue ticking forever please.
00145 }
00146 
00147 
00148 

Generated on Fri May 16 08:34:15 2008 for SecondLife by  doxygen 1.5.5