PageRenderTime 29ms CodeModel.GetById 16ms app.highlight 10ms RepoModel.GetById 1ms 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
  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
 27#include "llviewerprecompiledheaders.h"
 28#include "llviewerparcelmediaautoplay.h"
 29#include "llviewerparcelmedia.h"
 30#include "llviewercontrol.h"
 31#include "llviewermedia.h"
 32#include "llviewerregion.h"
 33#include "llparcel.h"
 34#include "llviewerparcelmgr.h"
 35#include "lluuid.h"
 36#include "message.h"
 37#include "llviewertexturelist.h"         // for texture stats
 38#include "llagent.h"
 39#include "llmimetypes.h"
 40
 41const F32 AUTOPLAY_TIME  = 5;          // how many seconds before we autoplay
 42const F32 AUTOPLAY_SIZE  = 24*24;      // how big the texture must be (pixel area) before we autoplay
 43const F32 AUTOPLAY_SPEED = 0.1f;        // how slow should the agent be moving to autoplay
 44
 45LLViewerParcelMediaAutoPlay::LLViewerParcelMediaAutoPlay() :
 46	LLEventTimer(1),
 47	
 48	mLastParcelID(-1),
 49	mPlayed(FALSE),
 50	mTimeInParcel(0)
 51{
 52}
 53
 54static LLViewerParcelMediaAutoPlay *sAutoPlay = NULL;
 55
 56// static
 57void LLViewerParcelMediaAutoPlay::initClass()
 58{
 59	if (!sAutoPlay)
 60		sAutoPlay = new LLViewerParcelMediaAutoPlay;
 61}
 62
 63// static
 64void LLViewerParcelMediaAutoPlay::cleanupClass()
 65{
 66	if (sAutoPlay)
 67		delete sAutoPlay;
 68}
 69
 70// static
 71void LLViewerParcelMediaAutoPlay::playStarted()
 72{
 73	if (sAutoPlay)
 74	{
 75		sAutoPlay->mPlayed = TRUE;
 76	}
 77}
 78
 79BOOL LLViewerParcelMediaAutoPlay::tick()
 80{
 81	LLParcel *this_parcel = NULL;
 82	LLViewerRegion *this_region = NULL;
 83	std::string this_media_url;
 84	std::string this_media_type;
 85	LLUUID this_media_texture_id;
 86	S32 this_parcel_id = 0;
 87	LLUUID this_region_id;
 88
 89	this_region = gAgent.getRegion();
 90	
 91	if (this_region)
 92	{
 93		this_region_id = this_region->getRegionID();
 94	}
 95
 96	this_parcel = LLViewerParcelMgr::getInstance()->getAgentParcel();
 97
 98	if (this_parcel)
 99	{
100		this_media_url = this_parcel->getMediaURL();
101		
102		this_media_type = this_parcel->getMediaType();
103
104		this_media_texture_id = this_parcel->getMediaID();
105
106		this_parcel_id = this_parcel->getLocalID();
107	}
108
109	if (this_parcel_id != mLastParcelID ||
110	    this_region_id != mLastRegionID)
111	{
112		// we've entered a new parcel
113		mPlayed    = FALSE;                   // we haven't autoplayed yet
114		mTimeInParcel = 0;                    // reset our timer
115		mLastParcelID = this_parcel_id;
116		mLastRegionID = this_region_id;
117	}
118
119	mTimeInParcel += mPeriod;					// increase mTimeInParcel by the amount of time between ticks
120
121	if ((!mPlayed) &&							// if we've never played
122		(mTimeInParcel > AUTOPLAY_TIME) &&		// and if we've been here for so many seconds
123		(!this_media_url.empty()) &&			// and if the parcel has media
124		(stricmp(this_media_type.c_str(), LLMIMETypes::getDefaultMimeType().c_str()) != 0) &&
125		(LLViewerParcelMedia::sMediaImpl.isNull()))	// and if the media is not already playing
126	{
127		if (this_media_texture_id.notNull())	// and if the media texture is good
128		{
129			LLViewerMediaTexture *image = LLViewerTextureManager::getMediaTexture(this_media_texture_id, FALSE) ;
130
131			F32 image_size = 0;
132
133			if (image)
134			{
135				image_size = image->getMaxVirtualSize() ;
136			}
137
138			if (gAgent.getVelocity().magVec() < AUTOPLAY_SPEED) // and if the agent is stopped (slow enough)
139			{
140				if (image_size > AUTOPLAY_SIZE)    // and if the target texture is big enough on screen
141				{
142					if (this_parcel)
143					{
144						if (gSavedSettings.getBOOL("ParcelMediaAutoPlayEnable"))
145						{
146							// and last but not least, only play when autoplay is enabled
147							LLViewerParcelMedia::play(this_parcel);
148						}
149					}
150
151					mPlayed = TRUE;
152				}
153			}
154		}
155	}
156
157
158	return FALSE; // continue ticking forever please.
159}
160
161
162