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