⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 behaviorstructure.java

📁 JAVA3D矩陈的相关类
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
    void reEvaluatePhysicalEnvironments() {	// we can't just add or remove from the list since	// physicalEnvironment may be share by multiple view	View v;	View views[];	ViewPlatform vp;	ArrayList vpList = universe.viewPlatforms;	physicalEnvironments.clear();	for (int i=vpList.size()-1; i>=0; i--) {	    views = ((ViewPlatformRetained) vpList.get(i)).getViewList();	    for (int j=views.length-1; j>=0; j--) {		v = views[j];		if (v.active && 		    !physicalEnvironments.contains(v.physicalEnvironment)) {		    physicalEnvironments.add(v.physicalEnvironment);		}	    }	}    }    void checkSensorEntryExit() {	int i, idx;	Sensor target;	// handle WakeupOnSensorEntry	WakeupOnSensorEntry wentry;	WakeupOnSensorEntry wentryArr[] = (WakeupOnSensorEntry []) 	                                    wakeupOnSensorEntry.toArray();		for (i=wakeupOnSensorEntry.arraySize()-1; i>=0; i--) {	    wentry = wentryArr[i];	    idx = currentSensorEntryList.indexOf(wentry);	    wentry.updateTransformRegion();	    target = sensorIntersect(wentry.transformedRegion);	    if (target != null) {		if (idx < 0) {		    currentSensorEntryList.add(wentry);		    wentry.setTarget(target);		    wentry.setTriggered();		}	    } else {		if (idx >= 0) {		    currentSensorEntryList.remove(idx);		}	    }	}	// handle WakeupOnSensorExit	WakeupOnSensorExit wexit;	WakeupOnSensorExit wexitArr[] = (WakeupOnSensorExit []) 	                                    wakeupOnSensorExit.toArray();		for (i=wakeupOnSensorExit.arraySize()-1; i>=0; i--) {	    wexit = wexitArr[i];	    idx = currentSensorExitList.indexOf(wexit);	    wexit.updateTransformRegion();	    target = sensorIntersect(wexit.transformedRegion);	    if (target != null) {		if (idx < 0) {		    currentSensorExitList.add(wexit);		    wexit.setTarget(target);		}	    } else {		if (idx >= 0) {		    currentSensorExitList.remove(idx);		    wexit.setTriggered();		}	    }	}    }    /**     * return the Senor that intersect with behregion or null     */    Sensor sensorIntersect(Bounds behregion) {	if (behregion == null)	    return null;	PhysicalEnvironment env[] = (PhysicalEnvironment []) 	                               physicalEnvironments.toArray(false);	Sensor sensors[];	Sensor s;	View v;	for (int i=physicalEnvironments.arraySize()-1; i>=0; i--) {	    if (env[i].activeViewRef > 0) {		sensors = env[i].getSensorList();	    		if (sensors != null) {		    for (int j= env[i].users.size()-1; j>=0; j--) {			v = (View) env[i].users.get(j);			synchronized (sensors) {			    for (int k=sensors.length-1; k >=0; k--) {				s = sensors[k];				if (s != null) {				    v.getSensorToVworld(s, sensorTransform);				    sensorTransform.get(sensorLoc);				    ptSensorLoc.set(sensorLoc);				    if (behregion.intersect(ptSensorLoc)) {					return s;				    }				}			    }			}		    }		}	    }	}	return null;    }    /**     * return true if one of ViewPlatforms intersect behregion     */    final boolean intersectVPRegion(Bounds behregion) {	if (behregion == null) {	    return false;	}	ViewPlatformRetained vp;	ViewPlatformRetained vpLists[] = (ViewPlatformRetained [])	                                    viewPlatforms.toArray(false);	for (int i=viewPlatforms.arraySize()- 1; i>=0; i--) {	    vp = vpLists[i];	    if (vp.isActiveViewPlatform() && 		vp.schedSphere.intersect(behregion)) {		return true;	    }	}	return false;    }    /**     * return true if one of ViewPlatforms center intersect behregion     */    final ViewPlatformRetained intersectVPCenter(Bounds behregion) {	if (behregion == null) {	    return null;	}	ViewPlatformRetained vp;	ViewPlatformRetained vpLists[] = (ViewPlatformRetained [])	                                    viewPlatforms.toArray(false);	for (int i=viewPlatforms.arraySize()- 1; i>=0; i--) {	    vp = vpLists[i];	    if (vp.isActiveViewPlatform() && 		behregion.intersect(vp.center)) {		return vp;	    }	}	return null;    }    void notifyDeactivationCondition(BehaviorRetained behav) {	WakeupOnDeactivation wakeup;	WakeupOnDeactivation wakeupConds[] = (WakeupOnDeactivation [])	                                  wakeupOnDeactivation.toArray(false);	for (int i=wakeupOnDeactivation.arraySize()-1; i>=0; i--) {	    wakeup = wakeupConds[i];	    if (wakeup.behav == behav) {		wakeup.setTriggered();	    }	}    }    void notifyActivationCondition(BehaviorRetained behav) {	WakeupOnActivation wakeup;	WakeupOnActivation wakeupConds[] = (WakeupOnActivation [])	                                  wakeupOnActivation.toArray(false);		for (int i=wakeupOnActivation.arraySize()-1; i>=0; i--) {	    wakeup = wakeupConds[i];	    if (wakeup.behav == behav) {		wakeup.setTriggered();	    }	}    }    void processSwitchChanged(J3dMessage m) {        int i,j;        UnorderList arrList;        int size;        Object[] nodes, nodesArr;        UpdateTargets targets = (UpdateTargets)m.args[0];        arrList = targets.targetList[Targets.VPF_TARGETS];        if (arrList != null) {	    ViewPlatformRetained vp;            size = arrList.size();            nodesArr = arrList.toArray(false);            for (j=0; j<size; j++) {                nodes = (Object[])nodesArr[j];                for (i=nodes.length-1; i>=0; i--) {                    vp = (ViewPlatformRetained) nodes[i];		    vp.processSwitchChanged();                }            }        }        arrList = targets.targetList[Targets.BEH_TARGETS];        if (arrList != null) {	    BehaviorRetained behav;            size = arrList.size();            nodesArr = arrList.toArray(false);            for (j=0; j<size; j++) {                nodes = (Object[])nodesArr[j];                for (i=nodes.length-1; i>=0; i--) {                    behav = (BehaviorRetained) nodes[i];                    if (behav.switchState.currentSwitchOn) {                        addToScheduleList(behav);                    } else {                        removeFromScheduleList(behav);                    }                }            }        }        arrList = targets.targetList[Targets.BLN_TARGETS];        if (arrList != null) {            size = arrList.size();            nodesArr = arrList.toArray(false);            Object[] objArr = (Object[])m.args[1];            Object[] obj;            BoundingLeafRetained mbleaf;            for (int h=0; h<size; h++) {                nodes = (Object[])nodesArr[h];                obj = (Object[])objArr[h];                for (i=nodes.length-1; i>=0; i--) {                    Object[] users = (Object[])obj[i];                    Object[] leafObj = new Object[1];                    mbleaf = (BoundingLeafRetained)nodes[i];                    for (j = 0; j < users.length; j++) {                        if (users[j] instanceof BehaviorRetained) {                            leafObj[0] = users[j];                            processTransformChanged(leafObj);                        }                    }                }            }        }    }    void processBoundingLeafChanged(Object users[],				    Bounds bound) {	Object leaf;	BehaviorRetained behav;	for (int i=users.length-1; i>=0; i--) {	    leaf = users[i];	    if (leaf instanceof BehaviorRetained) {		behav = (BehaviorRetained) leaf;		behav.updateTransformRegion(bound);		processBehaviorTransform(behav);	    }	}    }    final void removeFromScheduleList(BehaviorRetained behav) {	if (behav.active) {	    if ((behav.wakeupMask & 		 BehaviorRetained.WAKEUP_DEACTIVATE) != 0) {		notifyDeactivationCondition(behav);	    }	    scheduleList.remove(behav);	    behav.active = false;	    if (behav.universe != universe) {		J3dMessage m = new J3dMessage();		m.threads = J3dThread.UPDATE_BEHAVIOR;		m.type = J3dMessage.BEHAVIOR_REEVALUATE;		m.universe = behav.universe;		m.args[0] = behav;		VirtualUniverse.mc.processMessage(m);	    }	}    }    final void addToScheduleList(BehaviorRetained behav) {		if (!behav.inCallback &&	    !behav.active &&	    behav.enable &&	    behav.switchState.currentSwitchOn &&	    (behav.wakeupCondition != null) &&	    ((Behavior) behav.source).isLive() &&	    intersectVPRegion(behav.transformedRegion)) {	    scheduleList.add(behav);	    behav.active = true;	    if ((behav.wakeupMask & 		 BehaviorRetained.WAKEUP_ACTIVATE) != 0) {		notifyActivationCondition(behav);	    }	    if (behav.wakeupCondition != null) {		// This reset the conditionMet, otherwise 		// if conditionMet is true then WakeupCondition		// will never post message to BehaviorStructure		behav.wakeupCondition.conditionMet = false;	    }	}    }    /**     * This prevents wakeupCondition sent out message and sets     * conditionMet to true, but the     * BehaviorStructure/BehaviorScheduler is not fast enough to     * process the message and reset conditionMet to false     * when view deactivate/unregister.     */    void resetConditionMet() {	resetConditionMet(wakeupOnAWTEvent);	resetConditionMet(wakeupOnActivation);	resetConditionMet(wakeupOnDeactivation);		resetConditionMet(wakeupOnBehaviorPost);		resetConditionMet(wakeupOnElapsedFrames);		resetConditionMet(wakeupOnViewPlatformEntry);	resetConditionMet(wakeupOnViewPlatformExit);	resetConditionMet(wakeupOnSensorEntry);	resetConditionMet(wakeupOnSensorExit);    }    static void resetConditionMet(WakeupIndexedList list) {	WakeupCondition wakeups[] = (WakeupCondition []) list.toArray(false);	int i = list.size()-1;	while (i >= 0) {	    wakeups[i--].conditionMet = false;	}    }    void reEvaluateWakeupCount() {	WakeupOnElapsedFrames wakeupConds[] = (WakeupOnElapsedFrames [])	                          wakeupOnElapsedFrames.toArray(true);	int size = wakeupOnElapsedFrames.arraySize();	int i = 0;	WakeupOnElapsedFrames cond; 		activeWakeupOnFrameCount = 0;	while (i < size) {	    cond = wakeupConds[i++];	    if (!cond.passive && 		(cond.behav != null) && 		cond.behav.enable) {		activeWakeupOnFrameCount++;	    }        }  	activeWakeupOnSensorCount = 0;	WakeupOnSensorEntry wentry;	WakeupOnSensorEntry wentryArr[] = (WakeupOnSensorEntry []) 	                                    wakeupOnSensorEntry.toArray();		for (i=wakeupOnSensorEntry.arraySize()-1; i>=0; i--) {	    wentry = wentryArr[i];	    if ((wentry.behav != null) &&		(wentry.behav.enable)) {		activeWakeupOnSensorCount++;	    }	}	WakeupOnSensorExit wexit;	WakeupOnSensorExit wexitArr[] = (WakeupOnSensorExit []) 	                                    wakeupOnSensorExit.toArray();		for (i=wakeupOnSensorExit.arraySize()-1; i>=0; i--) {	    wexit = wexitArr[i];	    if ((wexit.behav != null) &&		(wexit.behav.enable)) {		activeWakeupOnSensorCount++;	    }	}    }    void cleanup() {	behaviors.clear();	viewPlatforms.clear();	scheduleList.clear();	boundsEntryList.clear();	boundsExitList.clear();		currentSensorEntryList.clear();	currentSensorExitList.clear();	wakeupOnAWTEvent.clear();	wakeupOnActivation.clear();	wakeupOnDeactivation.clear();	wakeupOnBehaviorPost.clear();	wakeupOnElapsedFrames.clear();	wakeupOnViewPlatformEntry.clear();	wakeupOnViewPlatformExit.clear();	wakeupOnSensorEntry.clear();	wakeupOnSensorExit.clear();    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -