001: /*
002: * $RCSfile: WakeupAndOfOrs.java,v $
003: *
004: * Copyright 1997-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:33 $
029: * $State: Exp $
030: */
031:
032: package javax.media.j3d;
033:
034: import java.util.Vector;
035:
036: /**
037: * Class specifying any number of OR wakeup conditions ANDed together.
038: * This WakeupCondition object specifies that Java 3D should awaken this
039: * Behavior when all of the WakeupCondition's constituent WakeupOr
040: * conditions become valid.
041: * <p>
042: * Note that a unique WakeupCriterion object must be used for each
043: * individual element in the set of arrays specified by the array of
044: * WakeupOr objects.
045: */
046:
047: public final class WakeupAndOfOrs extends WakeupCondition {
048:
049: WakeupOr conditions[];
050: boolean conditionsMet[];
051:
052: /**
053: * Constructs a new WakeupAndOfOrs criterion.
054: * @param conditions a vector of individual Wakeup conditions
055: */
056: public WakeupAndOfOrs(WakeupOr conditions[]) {
057: this .conditions = new WakeupOr[conditions.length];
058: this .conditionsMet = new boolean[conditions.length];
059:
060: for (int i = 0; i < conditions.length; i++) {
061: this .conditions[i] = conditions[i];
062: // conditionsMet is false by default when it is initilized
063: // this.conditionsMet[i] = false;
064: }
065: }
066:
067: /**
068: * This sets the bit for the given child, then checks if the full condition is met
069: */
070: void setConditionMet(int id, Boolean checkSchedulingRegion) {
071: conditionsMet[id] = true;
072:
073: for (int i = 0; i < this .conditionsMet.length; i++) {
074: if (!conditionsMet[i]) {
075: return;
076: }
077: }
078:
079: if (parent == null) {
080: super .setConditionMet(this .id, checkSchedulingRegion);
081: } else {
082: parent.setConditionMet(this .id, checkSchedulingRegion);
083: }
084: }
085:
086: /**
087: * This gets called when this condition is added to the AndOr tree.
088: */
089: void buildTree(WakeupCondition parent, int id, BehaviorRetained b) {
090:
091: super .buildTree(parent, id, b);
092:
093: for (int i = 0; i < conditions.length; i++) {
094: if (conditions[i] != null) {
095: conditions[i].buildTree(this , i, b);
096: }
097: }
098: }
099:
100: /**
101: * This goes through the AndOr tree to remove the various criterion from the
102: * BehaviorStructure lists
103: */
104: void cleanTree(BehaviorStructure bs) {
105: for (int i = 0; i < conditions.length; i++) {
106: conditions[i].cleanTree(bs);
107: conditionsMet[i] = false;
108: }
109: }
110:
111: void reInsertElapseTimeCond() {
112: super .reInsertElapseTimeCond();
113: for (int i = 0; i < conditions.length; i++) {
114: if (conditions[i] != null) {
115: conditions[i].reInsertElapseTimeCond();
116: }
117: }
118: }
119:
120: /**
121: * This goes through the AndOr tree to remove the various criterion from the
122: * BehaviorStructure.
123: */
124: void resetTree() {
125: super .resetTree();
126: for (int i = 0; i < conditions.length; i++) {
127: if (conditions[i] != null) {
128: conditions[i].resetTree();
129: }
130: }
131: }
132:
133: }
|