001: /*
002: * $RCSfile: Targets.java,v $
003: *
004: * Copyright 2001-2008 Sun Microsystems, Inc. All Rights Reserved.
005: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
006: *
007: * This code is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU General Public License version 2 only, as
009: * published by the Free Software Foundation. Sun designates this
010: * particular file as subject to the "Classpath" exception as provided
011: * by Sun in the LICENSE file that accompanied this code.
012: *
013: * This code is distributed in the hope that it will be useful, but WITHOUT
014: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
015: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
016: * version 2 for more details (a copy is included in the LICENSE file that
017: * accompanied this code).
018: *
019: * You should have received a copy of the GNU General Public License version
020: * 2 along with this work; if not, write to the Free Software Foundation,
021: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
022: *
023: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
024: * CA 95054 USA or visit www.sun.com if you need additional information or
025: * have any questions.
026: *
027: * $Revision: 1.6 $
028: * $Date: 2008/02/28 20:17:31 $
029: * $State: Exp $
030: */
031:
032: package javax.media.j3d;
033:
034: import java.util.ArrayList;
035:
036: class Targets {
037:
038: static final int MAX_NODELIST = 7;
039:
040: static final int GEO_TARGETS = 0; // For geometryAtoms.
041: static final int ENV_TARGETS = 1; // For enviroment nodes.
042: static final int BEH_TARGETS = 2; // For behavior nodes.
043: static final int SND_TARGETS = 3; // For sound nodes.
044: static final int VPF_TARGETS = 4; // For viewPlatform nodes.
045: static final int BLN_TARGETS = 5; // For boundingLeaf nodes.
046: static final int GRP_TARGETS = 6; // For group nodes.
047:
048: ArrayList[] targetList = new ArrayList[MAX_NODELIST];
049:
050: void addNode(NnuId node, int targetType) {
051: if (targetList[targetType] == null)
052: targetList[targetType] = new ArrayList(1);
053:
054: targetList[targetType].add(node);
055: }
056:
057: void addNodeArray(NnuId[] nodeArr, int targetType) {
058: if (targetList[targetType] == null)
059: targetList[targetType] = new ArrayList(1);
060:
061: targetList[targetType].add(nodeArr);
062: }
063:
064: void removeNode(int index, int targetType) {
065: if (targetList[targetType] != null) {
066: targetList[targetType].remove(index);
067: }
068: }
069:
070: void addNodes(ArrayList nodeList, int targetType) {
071: if (targetList[targetType] == null)
072: targetList[targetType] = new ArrayList(1);
073:
074: targetList[targetType].addAll(nodeList);
075: }
076:
077: void clearNodes() {
078: for (int i = 0; i < MAX_NODELIST; i++) {
079: if (targetList[i] != null) {
080: targetList[i].clear();
081: }
082: }
083: }
084:
085: CachedTargets snapShotInit() {
086:
087: CachedTargets cachedTargets = new CachedTargets();
088:
089: for (int i = 0; i < MAX_NODELIST; i++) {
090: if (targetList[i] != null) {
091: int size = targetList[i].size();
092: NnuId[] nArr = new NnuId[size];
093: targetList[i].toArray(nArr);
094: cachedTargets.targetArr[i] = nArr;
095: // System.err.println("Before sort : ");
096: // NnuIdManager.printIds(cachedTargets.targetArr[i]);
097: NnuIdManager.sort((NnuId[]) cachedTargets.targetArr[i]);
098: // System.err.println("After sort : ");
099: // NnuIdManager.printIds(cachedTargets.targetArr[i]);
100: } else {
101: cachedTargets.targetArr[i] = null;
102: }
103: }
104:
105: clearNodes();
106:
107: return cachedTargets;
108: }
109:
110: CachedTargets snapShotAdd(CachedTargets cachedTargets) {
111:
112: int i, size;
113:
114: CachedTargets newCachedTargets = new CachedTargets();
115:
116: for (i = 0; i < MAX_NODELIST; i++) {
117: if ((targetList[i] != null)
118: && (cachedTargets.targetArr[i] == null)) {
119: size = targetList[i].size();
120: NnuId[] nArr = new NnuId[size];
121: targetList[i].toArray(nArr);
122: newCachedTargets.targetArr[i] = nArr;
123: NnuIdManager.sort(newCachedTargets.targetArr[i]);
124:
125: } else if ((targetList[i] != null)
126: && (cachedTargets.targetArr[i] != null)) {
127:
128: size = targetList[i].size();
129: NnuId[] targetArr = new NnuId[size];
130: targetList[i].toArray(targetArr);
131: NnuIdManager.sort(targetArr);
132: newCachedTargets.targetArr[i] = NnuIdManager.merge(
133: cachedTargets.targetArr[i], targetArr);
134:
135: } else if ((targetList[i] == null)
136: && (cachedTargets.targetArr[i] != null)) {
137: newCachedTargets.targetArr[i] = cachedTargets.targetArr[i];
138: }
139: }
140:
141: clearNodes();
142:
143: return newCachedTargets;
144:
145: }
146:
147: CachedTargets snapShotRemove(CachedTargets cachedTargets) {
148:
149: int i, size;
150: NnuId[] targetArr;
151:
152: CachedTargets newCachedTargets = new CachedTargets();
153:
154: for (i = 0; i < MAX_NODELIST; i++) {
155:
156: if ((targetList[i] != null)
157: && (cachedTargets.targetArr[i] != null)) {
158: size = targetList[i].size();
159: targetArr = new NnuId[size];
160: targetList[i].toArray(targetArr);
161: NnuIdManager.sort(targetArr);
162: newCachedTargets.targetArr[i] = NnuIdManager.delete(
163: cachedTargets.targetArr[i], targetArr);
164:
165: } else if ((targetList[i] == null)
166: && (cachedTargets.targetArr[i] != null)) {
167: newCachedTargets.targetArr[i] = cachedTargets.targetArr[i];
168:
169: } else if ((targetList[i] != null)
170: && (cachedTargets.targetArr[i] == null)) {
171: System.err
172: .println("You can't remove something that isn't there");
173: }
174:
175: }
176:
177: clearNodes();
178:
179: return newCachedTargets;
180:
181: }
182:
183: boolean isEmpty() {
184: boolean empty = true;
185:
186: for (int i = 0; i < MAX_NODELIST; i++) {
187: if (targetList[i] != null) {
188: empty = false;
189: break;
190: }
191: }
192: return empty;
193: }
194:
195: void addCachedTargets(CachedTargets cachedTargets) {
196: for (int i = 0; i < MAX_NODELIST; i++) {
197: if (cachedTargets.targetArr[i] != null) {
198: addNodeArray(cachedTargets.targetArr[i], i);
199: }
200: }
201: }
202:
203: void dump() {
204: for (int i = 0; i < Targets.MAX_NODELIST; i++) {
205: if (targetList[i] != null) {
206: System.err.println(" " + CachedTargets.typeString[i]);
207: for (int j = 0; j < targetList[i].size(); j++) {
208: System.err.println(" " + targetList[i].get(j));
209: }
210: }
211: }
212: }
213: }
|