aboutsummaryrefslogtreecommitdiff
path: root/js/helper-classes/RDGE/src/core/script/objectManager.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/helper-classes/RDGE/src/core/script/objectManager.js')
-rwxr-xr-xjs/helper-classes/RDGE/src/core/script/objectManager.js197
1 files changed, 99 insertions, 98 deletions
diff --git a/js/helper-classes/RDGE/src/core/script/objectManager.js b/js/helper-classes/RDGE/src/core/script/objectManager.js
index 66e06cde..d2f74472 100755
--- a/js/helper-classes/RDGE/src/core/script/objectManager.js
+++ b/js/helper-classes/RDGE/src/core/script/objectManager.js
@@ -1,98 +1,99 @@
1/* <copyright> 1/* <copyright>
2Copyright (c) 2012, Motorola Mobility, Inc 2Copyright (c) 2012, Motorola Mobility LLC.
3All Rights Reserved. 3All Rights Reserved.
4BSD License. 4
5 5Redistribution and use in source and binary forms, with or without
6Redistribution and use in source and binary forms, with or without 6modification, are permitted provided that the following conditions are met:
7modification, are permitted provided that the following conditions are met: 7
8 8* Redistributions of source code must retain the above copyright notice,
9 - Redistributions of source code must retain the above copyright notice, 9 this list of conditions and the following disclaimer.
10 this list of conditions and the following disclaimer. 10
11 - Redistributions in binary form must reproduce the above copyright 11* Redistributions in binary form must reproduce the above copyright notice,
12 notice, this list of conditions and the following disclaimer in the 12 this list of conditions and the following disclaimer in the documentation
13 documentation and/or other materials provided with the distribution. 13 and/or other materials provided with the distribution.
14 - Neither the name of Motorola Mobility nor the names of its contributors 14
15 may be used to endorse or promote products derived from this software 15* Neither the name of Motorola Mobility LLC nor the names of its
16 without specific prior written permission. 16 contributors may be used to endorse or promote products derived from this
17 17 software without specific prior written permission.
18THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18
19AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 21IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
23CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 25SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 26INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 27CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28POSSIBILITY OF SUCH DAMAGE. 28ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29</copyright> */ 29POSSIBILITY OF SUCH DAMAGE.
30 30</copyright> */
31// RDGE namespaces 31
32var RDGE = RDGE || {}; 32// RDGE namespaces
33 33var RDGE = RDGE || {};
34/* generic handle-based object manager */ 34
35RDGE.objectManager = function() { 35/* generic handle-based object manager */
36 this.guidCounter = 0; 36RDGE.objectManager = function() {
37 this.objects = []; 37 this.guidCounter = 0;
38 this.numObjects = 0; 38 this.objects = [];
39 this.freelist = []; 39 this.numObjects = 0;
40 40 this.freelist = [];
41 this.reset = function() { 41
42 this.objects = []; 42 this.reset = function() {
43 this.freelist = []; 43 this.objects = [];
44 this.guidCounter = 0; 44 this.freelist = [];
45 } 45 this.guidCounter = 0;
46 46 }
47 // validHandle 47
48 this.validHandle = function(h) { 48 // validHandle
49 return this.handleToIndex(h) != -1; 49 this.validHandle = function(h) {
50 } 50 return this.handleToIndex(h) != -1;
51 51 }
52 // handleToIndex 52
53 this.handleToIndex = function(h) { 53 // handleToIndex
54 var index = ( h >> 16 ) & 0xFFFF; 54 this.handleToIndex = function(h) {
55 if( this.objects[index] != null && h == this.objects[index].handle ) { 55 var index = ( h >> 16 ) & 0xFFFF;
56 return index; 56 if( this.objects[index] != null && h == this.objects[index].handle ) {
57 } 57 return index;
58 return -1; 58 }
59 } 59 return -1;
60 60 }
61 // handleToObject 61
62 this.handleToObject = function(h) { 62 // handleToObject
63 var index = this.handleToIndex( h ); 63 this.handleToObject = function(h) {
64 if( index != -1 ) { 64 var index = this.handleToIndex( h );
65 return this.objects[index]; 65 if( index != -1 ) {
66 } 66 return this.objects[index];
67 return null; 67 }
68 } 68 return null;
69 69 }
70 // add object 70
71 this.addObject = function(ob) { 71 // add object
72 var index = this.objects.length; 72 this.addObject = function(ob) {
73 73 var index = this.objects.length;
74 if( this.freelist.length > 0 ) { 74
75 index = this.freelist.pop(); 75 if( this.freelist.length > 0 ) {
76 } 76 index = this.freelist.pop();
77 if( ++this.guidCounter >= 0xFFFF ) { 77 }
78 // wrap the counter, zero is reserved for invalid handles. 78 if( ++this.guidCounter >= 0xFFFF ) {
79 this.guidCounter = 1; 79 // wrap the counter, zero is reserved for invalid handles.
80 } 80 this.guidCounter = 1;
81 ob.handle = ( index << 16 | ++this.guidCounter ); 81 }
82 this.objects[index] = ob; 82 ob.handle = ( index << 16 | ++this.guidCounter );
83 83 this.objects[index] = ob;
84 return ob.handle; 84
85 } 85 return ob.handle;
86 86 }
87 // remove object 87
88 this.removeObject = function(h) { 88 // remove object
89 var index = this.handleToIndex( h ); 89 this.removeObject = function(h) {
90 if( index != -1 ) { 90 var index = this.handleToIndex( h );
91 if( this.objects[index].onremove != undefined ) { 91 if( index != -1 ) {
92 this.objects[index].onremove(); 92 if( this.objects[index].onremove != undefined ) {
93 } 93 this.objects[index].onremove();
94 this.objects[index] = null; 94 }
95 this.freelist.push(index); 95 this.objects[index] = null;
96 } 96 this.freelist.push(index);
97 } 97 }
98} 98 }
99}