summaryrefslogtreecommitdiffstats
path: root/src/javax/media/j3d/Targets.java
blob: d15175697c100620f2dc1fb1ac5d159e99fb72c6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
/*
 * Copyright 2001-2008 Sun Microsystems, Inc.  All Rights Reserved.
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * This code is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License version 2 only, as
 * published by the Free Software Foundation.  Sun designates this
 * particular file as subject to the "Classpath" exception as provided
 * by Sun in the LICENSE file that accompanied this code.
 *
 * This code is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 * version 2 for more details (a copy is included in the LICENSE file that
 * accompanied this code).
 *
 * You should have received a copy of the GNU General Public License version
 * 2 along with this work; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 *
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
 * CA 95054 USA or visit www.sun.com if you need additional information or
 * have any questions.
 *
 */

package javax.media.j3d;

import java.util.ArrayList;

class Targets {

    static final int MAX_NODELIST = 7;

    static final int GEO_TARGETS = 0; // For geometryAtoms.
    static final int ENV_TARGETS = 1; // For enviroment nodes.
    static final int BEH_TARGETS = 2; // For behavior nodes.
    static final int SND_TARGETS = 3; // For sound nodes.
    static final int VPF_TARGETS = 4; // For viewPlatform nodes.
    static final int BLN_TARGETS = 5; // For boundingLeaf nodes.
    static final int GRP_TARGETS = 6; // For group nodes.

    ArrayList<NnuId>[] targetList = new ArrayList[MAX_NODELIST];

    void addNode(NnuId node, int targetType) {
	if(targetList[targetType] == null)
	    targetList[targetType] = new ArrayList<NnuId>(1);

	targetList[targetType].add(node);
    }

    void removeNode(int index, int targetType) {
        if(targetList[targetType] != null) {
            targetList[targetType].remove(index);
	}
    }


    void addNodes(ArrayList<NnuId> nodeList, int targetType) {
	if(targetList[targetType] == null)
	    targetList[targetType] = new ArrayList<NnuId>(1);

	targetList[targetType].addAll(nodeList);
    }


    void clearNodes() {
	for(int i=0; i<MAX_NODELIST; i++) {
	    if (targetList[i] != null) {
	        targetList[i].clear();
	    }
	}
    }

    CachedTargets snapShotInit() {

	CachedTargets cachedTargets = new CachedTargets();


	for(int i=0; i<MAX_NODELIST; i++) {
	    if(targetList[i] != null) {
		int size = targetList[i].size();
		NnuId[] nArr = new NnuId[size];
		targetList[i].toArray(nArr);
		cachedTargets.targetArr[i] = nArr;
		// System.err.println("Before sort : ");
		// NnuIdManager.printIds(cachedTargets.targetArr[i]);
		NnuIdManager.sort(cachedTargets.targetArr[i]);
		// System.err.println("After sort : ");
		// NnuIdManager.printIds(cachedTargets.targetArr[i]);
	    } else {
		cachedTargets.targetArr[i] = null;
	    }
	}

	clearNodes();

	return cachedTargets;
    }


    CachedTargets snapShotAdd(CachedTargets cachedTargets) {

	int i, size;

	CachedTargets newCachedTargets = new CachedTargets();

	for(i=0; i<MAX_NODELIST; i++) {
	    if((targetList[i] != null) && (cachedTargets.targetArr[i] == null)) {
		size = targetList[i].size();
		NnuId[] nArr = new NnuId[size];
		targetList[i].toArray(nArr);
		newCachedTargets.targetArr[i] = nArr;
		NnuIdManager.sort(newCachedTargets.targetArr[i]);

	    }
	    else if((targetList[i] != null) && (cachedTargets.targetArr[i] != null)) {

		size = targetList[i].size();
		NnuId[] targetArr = new NnuId[size];
		targetList[i].toArray(targetArr);
		NnuIdManager.sort(targetArr);
		newCachedTargets.targetArr[i] =
		    NnuIdManager.merge(cachedTargets.targetArr[i], targetArr);

	    }
	    else if((targetList[i] == null) && (cachedTargets.targetArr[i] != null)) {
		newCachedTargets.targetArr[i] = cachedTargets.targetArr[i];
	    }
	}

	clearNodes();

	return 	newCachedTargets;

    }


    CachedTargets snapShotRemove(CachedTargets cachedTargets) {

	int i, size;
	NnuId[] targetArr;


	CachedTargets newCachedTargets = new CachedTargets();

	for(i=0; i<MAX_NODELIST; i++) {

	    if((targetList[i] != null) && (cachedTargets.targetArr[i] != null)) {
		size = targetList[i].size();
		targetArr = new NnuId[size];
		targetList[i].toArray(targetArr);
		NnuIdManager.sort(targetArr);
		newCachedTargets.targetArr[i] =
		    NnuIdManager.delete(cachedTargets.targetArr[i], targetArr);

	    }
	    else if((targetList[i] == null) && (cachedTargets.targetArr[i] != null)) {
		newCachedTargets.targetArr[i] = cachedTargets.targetArr[i];

	    }
	    else if((targetList[i] != null) && (cachedTargets.targetArr[i] == null)) {
		System.err.println("You can't remove something that isn't there");
	    }

	}

	clearNodes();

	return 	newCachedTargets;

    }

    boolean isEmpty() {
	boolean empty = true;

        for (int i=0; i < MAX_NODELIST; i++) {
            if (targetList[i] != null) {
                empty = false;
		break;
            }
        }
	return empty;
    }

    void dump() {
        for(int i=0; i<Targets.MAX_NODELIST; i++) {
            if (targetList[i] != null) {
                System.err.println("  " + CachedTargets.typeString[i]);
                for(int j=0; j<targetList[i].size(); j++) {
                    System.err.println("  " + targetList[i].get(j));
                }
            }
        }
    }
}