diff options
author | Jacek Antonelli | 2009-04-30 13:04:20 -0500 |
---|---|---|
committer | Jacek Antonelli | 2009-04-30 13:07:16 -0500 |
commit | ca8149ca6d157eb4b5fc8ba0e5ba3a6e56f72e7e (patch) | |
tree | 8348301d0ac44a524f1819b777686bf086907d76 /linden/indra/lscript/lscript_execute/llscriptresource.cpp | |
parent | Second Life viewer sources 1.22.11 (diff) | |
download | meta-impy-ca8149ca6d157eb4b5fc8ba0e5ba3a6e56f72e7e.zip meta-impy-ca8149ca6d157eb4b5fc8ba0e5ba3a6e56f72e7e.tar.gz meta-impy-ca8149ca6d157eb4b5fc8ba0e5ba3a6e56f72e7e.tar.bz2 meta-impy-ca8149ca6d157eb4b5fc8ba0e5ba3a6e56f72e7e.tar.xz |
Second Life viewer sources 1.23.0-RC
Diffstat (limited to 'linden/indra/lscript/lscript_execute/llscriptresource.cpp')
-rw-r--r-- | linden/indra/lscript/lscript_execute/llscriptresource.cpp | 97 |
1 files changed, 97 insertions, 0 deletions
diff --git a/linden/indra/lscript/lscript_execute/llscriptresource.cpp b/linden/indra/lscript/lscript_execute/llscriptresource.cpp new file mode 100644 index 0000000..6c4776c --- /dev/null +++ b/linden/indra/lscript/lscript_execute/llscriptresource.cpp | |||
@@ -0,0 +1,97 @@ | |||
1 | /** | ||
2 | * @file llscriptresource.cpp | ||
3 | * @brief LLScriptResource class implementation for managing limited resources | ||
4 | * | ||
5 | * $LicenseInfo:firstyear=2008&license=viewergpl$ | ||
6 | * | ||
7 | * Copyright (c) 2008-2009, 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 | ||
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 "llscriptresource.h" | ||
34 | #include "llerror.h" | ||
35 | |||
36 | LLScriptResource::LLScriptResource() | ||
37 | : mTotal(0), | ||
38 | mUsed(0) | ||
39 | { | ||
40 | } | ||
41 | |||
42 | bool LLScriptResource::request(S32 amount /* = 1 */) | ||
43 | { | ||
44 | if (mUsed + amount <= mTotal) | ||
45 | { | ||
46 | mUsed += amount; | ||
47 | return true; | ||
48 | } | ||
49 | |||
50 | return false; | ||
51 | } | ||
52 | |||
53 | bool LLScriptResource::release(S32 amount /* = 1 */) | ||
54 | { | ||
55 | if (mUsed >= amount) | ||
56 | { | ||
57 | mUsed -= amount; | ||
58 | return true; | ||
59 | } | ||
60 | |||
61 | return false; | ||
62 | } | ||
63 | |||
64 | S32 LLScriptResource::getAvailable() const | ||
65 | { | ||
66 | if (mUsed > mTotal) | ||
67 | { | ||
68 | // It is possible after a parcel ownership change for more than total to be used | ||
69 | // In this case the user of this class just wants to know | ||
70 | // whether or not they can use a resource | ||
71 | return 0; | ||
72 | } | ||
73 | return (mTotal - mUsed); | ||
74 | } | ||
75 | |||
76 | void LLScriptResource::setTotal(S32 amount) | ||
77 | { | ||
78 | // This may cause this resource to be over spent | ||
79 | // such that more are in use than total allowed | ||
80 | // Until those resources are released getAvailable will return 0. | ||
81 | mTotal = amount; | ||
82 | } | ||
83 | |||
84 | S32 LLScriptResource::getTotal() const | ||
85 | { | ||
86 | return mTotal; | ||
87 | } | ||
88 | |||
89 | S32 LLScriptResource::getUsed() const | ||
90 | { | ||
91 | return mUsed; | ||
92 | } | ||
93 | |||
94 | bool LLScriptResource::isOverLimit() const | ||
95 | { | ||
96 | return (mUsed > mTotal); | ||
97 | } | ||