001: /*
002: * $RCSfile: StructureUpdateThread.java,v $
003: *
004: * Copyright 1998-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.5 $
028: * $Date: 2008/02/28 20:17:31 $
029: * $State: Exp $
030: */
031:
032: package javax.media.j3d;
033:
034: /**
035: * The StructureUpdateThread is thread that passes messages to its structure
036: */
037:
038: class StructureUpdateThread extends J3dThread {
039: /**
040: * The structure that this thread works for
041: */
042: J3dStructure structure;
043:
044: /**
045: * Some variables used to name threads correctly
046: */
047: private static int numInstances[] = new int[7];
048: private int instanceNum[] = new int[7];
049:
050: private synchronized int newInstanceNum(int idx) {
051: return (++numInstances[idx]);
052: }
053:
054: int getInstanceNum(int idx) {
055: if (instanceNum[idx] == 0)
056: instanceNum[idx] = newInstanceNum(idx);
057: return instanceNum[idx];
058: }
059:
060: /**
061: * Just saves the structure
062: */
063: StructureUpdateThread(ThreadGroup t, J3dStructure s, int threadType) {
064: super (t);
065: structure = s;
066: type = threadType;
067: classification = J3dThread.UPDATE_THREAD;
068:
069: switch (type) {
070: case J3dThread.UPDATE_GEOMETRY:
071: setName("J3D-GeometryStructureUpdateThread-"
072: + getInstanceNum(0));
073: break;
074: case J3dThread.UPDATE_RENDER:
075: setName("J3D-RenderStructureUpdateThread-"
076: + getInstanceNum(1));
077: break;
078: case J3dThread.UPDATE_BEHAVIOR:
079: setName("J3D-BehaviorStructureUpdateThread-"
080: + getInstanceNum(2));
081: break;
082: case J3dThread.UPDATE_SOUND:
083: setName("J3D-SoundStructureUpdateThread-"
084: + getInstanceNum(3));
085: break;
086: case J3dThread.UPDATE_RENDERING_ATTRIBUTES:
087: // Only one exists in Java3D system
088: setName("J3D-RenderingAttributesStructureUpdateThread");
089: break;
090: case J3dThread.UPDATE_RENDERING_ENVIRONMENT:
091: setName("J3D-RenderingEnvironmentStructureUpdateThread-"
092: + getInstanceNum(4));
093: break;
094: case J3dThread.UPDATE_TRANSFORM:
095: setName("J3D-TransformStructureUpdateThread-"
096: + getInstanceNum(5));
097: break;
098: case J3dThread.SOUND_SCHEDULER:
099: setName("J3D-SoundSchedulerUpdateThread-"
100: + getInstanceNum(6));
101: break;
102:
103: }
104:
105: }
106:
107: void doWork(long referenceTime) {
108: structure.processMessages(referenceTime);
109: }
110: }
|