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