aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/newview/llviewerparcelmediaautoplay.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'linden/indra/newview/llviewerparcelmediaautoplay.cpp')
-rw-r--r--linden/indra/newview/llviewerparcelmediaautoplay.cpp151
1 files changed, 151 insertions, 0 deletions
diff --git a/linden/indra/newview/llviewerparcelmediaautoplay.cpp b/linden/indra/newview/llviewerparcelmediaautoplay.cpp
new file mode 100644
index 0000000..854ba24
--- /dev/null
+++ b/linden/indra/newview/llviewerparcelmediaautoplay.cpp
@@ -0,0 +1,151 @@
1/**
2 * @file llviewerparcelmediaautoplay.cpp
3 * @brief timer to automatically play media in a parcel
4 *
5 * $LicenseInfo:firstyear=2007&license=viewergpl$
6 *
7 * Copyright (c) 2007-2008, Linden Research, Inc.
8 *
9 * Second Life Viewer Source Code
10 * The source code in this file ("Source Code") is provided by Linden Lab
11 * to you under the terms of the GNU General Public License, version 2.0
12 * ("GPL"), unless you have obtained a separate licensing agreement
13 * ("Other License"), formally executed by you and Linden Lab. Terms of
14 * the GPL can be found in doc/GPL-license.txt in this distribution, or
15 * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
16 *
17 * There are special exceptions to the terms and conditions of the GPL as
18 * it is applied to this Source Code. View the full text of the exception
19 * in the file doc/FLOSS-exception.txt in this software distribution, or
20 * online at http://secondlifegrid.net/programs/open_source/licensing/flossexception
21 *
22 * By copying, modifying or distributing this software, you acknowledge
23 * that you have read and understood your obligations described above,
24 * and agree to abide by those obligations.
25 *
26 * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
27 * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
28 * COMPLETENESS OR PERFORMANCE.
29 * $/LicenseInfo$
30 */
31
32#include "llviewerprecompiledheaders.h"
33#include "llviewerparcelmediaautoplay.h"
34#include "llviewerparcelmedia.h"
35#include "llviewercontrol.h"
36#include "llviewermedia.h"
37#include "llparcel.h"
38#include "llviewerparcelmgr.h"
39#include "lluuid.h"
40#include "message.h"
41#include "llviewerimagelist.h" // for texture stats
42#include "llagent.h"
43
44const F32 AUTOPLAY_TIME = 5; // how many seconds before we autoplay
45const F32 AUTOPLAY_SIZE = 24*24; // how big the texture must be (pixel area) before we autoplay
46const F32 AUTOPLAY_SPEED = 0.1f; // how slow should the agent be moving to autoplay
47
48LLViewerParcelMediaAutoPlay::LLViewerParcelMediaAutoPlay() :
49 LLEventTimer(1),
50 mPlayed(FALSE),
51 mTimeInParcel(0)
52{
53}
54
55static LLViewerParcelMediaAutoPlay *sAutoPlay = NULL;
56
57// static
58void LLViewerParcelMediaAutoPlay::initClass()
59{
60 if (!sAutoPlay)
61 sAutoPlay = new LLViewerParcelMediaAutoPlay;
62}
63
64// static
65void LLViewerParcelMediaAutoPlay::cleanupClass()
66{
67 if (sAutoPlay)
68 delete sAutoPlay;
69}
70
71// static
72void LLViewerParcelMediaAutoPlay::playStarted()
73{
74 if (sAutoPlay)
75 {
76 sAutoPlay->mPlayed = TRUE;
77 }
78}
79
80BOOL LLViewerParcelMediaAutoPlay::tick()
81{
82 LLParcel *this_parcel = NULL;
83 std::string this_media_url;
84 LLUUID this_media_texture_id;
85 S32 this_parcel_id = 0;
86
87 if (gParcelMgr)
88 {
89 this_parcel = gParcelMgr->getAgentParcel();
90 }
91
92 if (this_parcel)
93 {
94 this_media_url = std::string(this_parcel->getMediaURL());
95
96 this_media_texture_id = this_parcel->getMediaID();
97
98 this_parcel_id = this_parcel->getLocalID();
99 }
100
101 if (this_parcel_id != mLastParcelID)
102 {
103 // we've entered a new parcel
104 mPlayed = FALSE; // we haven't autoplayed yet
105 mTimeInParcel = 0; // reset our timer
106 mLastParcelID = this_parcel_id;
107 }
108
109 mTimeInParcel += mPeriod; // increase mTimeInParcel by the amount of time between ticks
110
111 if ((!mPlayed) && // if we've never played
112 (mTimeInParcel > AUTOPLAY_TIME) && // and if we've been here for so many seconds
113 (this_media_url.size() != 0) && // and if the parcel has media
114 (!LLViewerMedia::isMediaPlaying())) // and if the media is not already playing
115 {
116 if (this_media_texture_id.notNull()) // and if the media texture is good
117 {
118 LLViewerImage *image = gImageList.getImage(this_media_texture_id, FALSE);
119
120 F32 image_size = 0;
121
122 if (image)
123 {
124 image_size = image->mMaxVirtualSize;
125 }
126
127 if (gAgent.getVelocity().magVec() < AUTOPLAY_SPEED) // and if the agent is stopped (slow enough)
128 {
129 if (image_size > AUTOPLAY_SIZE) // and if the target texture is big enough on screen
130 {
131 if (this_parcel)
132 {
133 if (gSavedSettings.getBOOL("ParcelMediaAutoPlayEnable"))
134 {
135 // and last but not least, only play when autoplay is enabled
136 LLViewerParcelMedia::play(this_parcel);
137 }
138 }
139
140 mPlayed = TRUE;
141 }
142 }
143 }
144 }
145
146
147 return FALSE; // continue ticking forever please.
148}
149
150
151