Annotation of /trunk/indra/newview/llviewerparcelmediaautoplay.cpp
Parent Directory
|
Revision Log
Revision 137 - (view) (download)
| 1 : | mjm | 135 | /** |
| 2 : | * @file llviewerparcelmediaautoplay.cpp | ||
| 3 : | * @brief timer to automatically play media in a parcel | ||
| 4 : | * | ||
| 5 : | * $LicenseInfo:firstyear=2007&license=viewergpl$ | ||
| 6 : | * | ||
| 7 : | mjm | 137 | * Copyright (c) 2007-2010, Linden Research, Inc. |
| 8 : | mjm | 135 | * |
| 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 | ||
| 21 : | * http://secondlifegrid.net/programs/open_source/licensing/flossexception | ||
| 22 : | * | ||
| 23 : | * By copying, modifying or distributing this software, you acknowledge | ||
| 24 : | * that you have read and understood your obligations described above, | ||
| 25 : | * and agree to abide by those obligations. | ||
| 26 : | * | ||
| 27 : | * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO | ||
| 28 : | * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY, | ||
| 29 : | * COMPLETENESS OR PERFORMANCE. | ||
| 30 : | * $/LicenseInfo$ | ||
| 31 : | */ | ||
| 32 : | |||
| 33 : | #include "llviewerprecompiledheaders.h" | ||
| 34 : | #include "llviewerparcelmediaautoplay.h" | ||
| 35 : | #include "llviewerparcelmedia.h" | ||
| 36 : | #include "llviewercontrol.h" | ||
| 37 : | #include "llviewermedia.h" | ||
| 38 : | #include "llparcel.h" | ||
| 39 : | #include "llviewerparcelmgr.h" | ||
| 40 : | #include "lluuid.h" | ||
| 41 : | #include "message.h" | ||
| 42 : | #include "llviewerimagelist.h" | ||
| 43 : | #include "llagent.h" | ||
| 44 : | |||
| 45 : | const F32 AUTOPLAY_TIME = 5; // how many seconds before we autoplay | ||
| 46 : | const F32 AUTOPLAY_SIZE = 24*24; // how big the texture must be (pixel area) before we autoplay | ||
| 47 : | const F32 AUTOPLAY_SPEED = 0.1f; // how slow should the agent be moving to autoplay | ||
| 48 : | |||
| 49 : | LLViewerParcelMediaAutoPlay::LLViewerParcelMediaAutoPlay() : | ||
| 50 : | LLEventTimer(1), | ||
| 51 : | mPlayed(FALSE), | ||
| 52 : | mTimeInParcel(0) | ||
| 53 : | { | ||
| 54 : | } | ||
| 55 : | |||
| 56 : | static LLViewerParcelMediaAutoPlay *sAutoPlay = NULL; | ||
| 57 : | |||
| 58 : | // static | ||
| 59 : | void LLViewerParcelMediaAutoPlay::initClass() | ||
| 60 : | { | ||
| 61 : | if (!sAutoPlay) | ||
| 62 : | sAutoPlay = new LLViewerParcelMediaAutoPlay; | ||
| 63 : | } | ||
| 64 : | |||
| 65 : | // static | ||
| 66 : | void LLViewerParcelMediaAutoPlay::cleanupClass() | ||
| 67 : | { | ||
| 68 : | if (sAutoPlay) | ||
| 69 : | delete sAutoPlay; | ||
| 70 : | } | ||
| 71 : | |||
| 72 : | // static | ||
| 73 : | void LLViewerParcelMediaAutoPlay::playStarted() | ||
| 74 : | { | ||
| 75 : | if (sAutoPlay) | ||
| 76 : | { | ||
| 77 : | sAutoPlay->mPlayed = TRUE; | ||
| 78 : | } | ||
| 79 : | } | ||
| 80 : | |||
| 81 : | BOOL LLViewerParcelMediaAutoPlay::tick() | ||
| 82 : | { | ||
| 83 : | LLParcel *this_parcel = NULL; | ||
| 84 : | std::string this_media_url; | ||
| 85 : | LLUUID this_media_texture_id; | ||
| 86 : | S32 this_parcel_id = 0; | ||
| 87 : | |||
| 88 : | this_parcel = LLViewerParcelMgr::getInstance()->getAgentParcel(); | ||
| 89 : | |||
| 90 : | if (this_parcel) | ||
| 91 : | { | ||
| 92 : | this_media_url = std::string(this_parcel->getMediaURL()); | ||
| 93 : | |||
| 94 : | this_media_texture_id = this_parcel->getMediaID(); | ||
| 95 : | |||
| 96 : | this_parcel_id = this_parcel->getLocalID(); | ||
| 97 : | } | ||
| 98 : | |||
| 99 : | if (this_parcel_id != mLastParcelID) | ||
| 100 : | { | ||
| 101 : | // we've entered a new parcel | ||
| 102 : | mPlayed = FALSE; // we haven't autoplayed yet | ||
| 103 : | mTimeInParcel = 0; // reset our timer | ||
| 104 : | mLastParcelID = this_parcel_id; | ||
| 105 : | } | ||
| 106 : | |||
| 107 : | mTimeInParcel += mPeriod; // increase mTimeInParcel by the amount of time between ticks | ||
| 108 : | |||
| 109 : | if ((!mPlayed) && // if we've never played | ||
| 110 : | (mTimeInParcel > AUTOPLAY_TIME) && // and if we've been here for so many seconds | ||
| 111 : | (this_media_url.size() != 0) && // and if the parcel has media | ||
| 112 : | (!LLViewerMedia::isMediaPlaying())) // and if the media is not already playing | ||
| 113 : | { | ||
| 114 : | if (this_media_texture_id.notNull()) // and if the media texture is good | ||
| 115 : | { | ||
| 116 : | LLViewerImage *image = gImageList.getImage(this_media_texture_id, FALSE); | ||
| 117 : | |||
| 118 : | F32 image_size = 0; | ||
| 119 : | |||
| 120 : | if (image) | ||
| 121 : | { | ||
| 122 : | image_size = image->mMaxVirtualSize; | ||
| 123 : | } | ||
| 124 : | |||
| 125 : | if (gAgent.getVelocity().magVec() < AUTOPLAY_SPEED) // and if the agent is stopped (slow enough) | ||
| 126 : | { | ||
| 127 : | if (image_size > AUTOPLAY_SIZE) // and if the target texture is big enough on screen | ||
| 128 : | { | ||
| 129 : | if (this_parcel) | ||
| 130 : | { | ||
| 131 : | if (gSavedSettings.getBOOL("ParcelMediaAutoPlayEnable")) | ||
| 132 : | { | ||
| 133 : | // and last but not least, only play when autoplay is enabled | ||
| 134 : | LLViewerParcelMedia::play(this_parcel); | ||
| 135 : | } | ||
| 136 : | } | ||
| 137 : | |||
| 138 : | mPlayed = TRUE; | ||
| 139 : | } | ||
| 140 : | } | ||
| 141 : | } | ||
| 142 : | } | ||
| 143 : | |||
| 144 : | |||
| 145 : | return FALSE; // continue ticking forever please. | ||
| 146 : | } | ||
| 147 : | |||
| 148 : | |||
| 149 : |
| ViewVC Help | |
| Powered by ViewVC 1.0.0 |

