📄 behaviorstructure.java
字号:
} // Since BehaviorScheduler will run after BehaviorStructure // (not in parallel). It is safe to do cleanup here. wakeupOnAWTEvent.clearMirror(); awtEventsBuffer.clearMirror(); wakeupOnBehaviorPost.clearMirror(); behaviorPostBuffer.clearMirror(); wakeupOnSensorEntry.clearMirror(); wakeupOnSensorExit.clearMirror(); branchDetach = true; if (behavRemove) { // disable AWT Event from Canvas3D WakeupOnAWTEvent awtConds[] = (WakeupOnAWTEvent []) wakeupOnAWTEvent.toArray(); int eventSize = wakeupOnAWTEvent.arraySize(); // Component Event always Enable boolean focusEnable = false; boolean keyEnable = false; boolean mouseMotionEnable = false; boolean mouseEnable = false; boolean mouseWheelEnable = false; WakeupOnAWTEvent awtCond; int awtId; long eventMask; boolean incTimestamp = false; for (int i=0; i < eventSize; i++) { awtCond = awtConds[i]; awtId = awtCond.AwtId; eventMask = awtCond.EventMask; if ((awtId >= FocusEvent.FOCUS_FIRST && awtId <= FocusEvent.FOCUS_LAST) || (eventMask & AWTEvent.FOCUS_EVENT_MASK) != 0) { focusEnable = true; } if ((awtId >= KeyEvent.KEY_FIRST && awtId <= KeyEvent.KEY_LAST) || (eventMask & AWTEvent.KEY_EVENT_MASK) != 0) { keyEnable = true; } if ((awtId >= MouseEvent.MOUSE_FIRST) && (awtId <= MouseEvent.MOUSE_LAST)) { if ((awtId == MouseEvent.MOUSE_DRAGGED) || (awtId == MouseEvent.MOUSE_MOVED)) { mouseMotionEnable = true; } else if ((awtId == MouseEvent.MOUSE_ENTERED) || (awtId == MouseEvent.MOUSE_EXITED) || (awtId == MouseEvent.MOUSE_CLICKED) || (awtId == MouseEvent.MOUSE_PRESSED) || (awtId == MouseEvent.MOUSE_RELEASED) ) { mouseEnable = true; } else if (awtId == MouseEvent.MOUSE_WHEEL) { mouseWheelEnable = true; } } else { if ((eventMask & AWTEvent.MOUSE_EVENT_MASK) != 0) { mouseEnable = true; } if ((eventMask & AWTEvent.MOUSE_MOTION_EVENT_MASK) != 0) { mouseMotionEnable = true; } if ((eventMask & AWTEvent.MOUSE_WHEEL_EVENT_MASK) != 0) { mouseWheelEnable = true; } } } if (!focusEnable && universe.enableFocus) { incTimestamp = true; universe.disableFocusEvents(); } if (!VirtualUniverse.mc.isD3D() && !keyEnable && universe.enableKey) { // key event use for toggle to fullscreen/window mode incTimestamp = true; universe.disableKeyEvents(); } if (!mouseWheelEnable && universe.enableMouseWheel) { incTimestamp = true; universe.disableMouseWheelEvents(); } if (!mouseMotionEnable && universe.enableMouseMotion) { incTimestamp = true; universe.disableMouseMotionEvents(); } if (!mouseEnable && universe.enableMouse) { incTimestamp = true; universe.disableMouseEvents(); } if (incTimestamp) { awtEventTimestamp++; } } } void removeViewPlatform(ViewPlatformRetained vp) { BehaviorRetained behav; int i; viewPlatforms.remove(vp); BehaviorRetained scheduleArr[] = (BehaviorRetained []) scheduleList.toArray(false); // handle Deactive for (i=scheduleList.arraySize()-1; i >=0 ; i--) { behav = scheduleArr[i]; // This vp may contribute to the reason that // behavior is in schedule list if (!intersectVPRegion(behav.transformedRegion)) { removeFromScheduleList(behav); } } // handle ViewPlatform Entry WakeupOnViewPlatformEntry boundsEntryArr[] = (WakeupOnViewPlatformEntry []) boundsEntryList.toArray(false); WakeupOnViewPlatformEntry wentry; ViewPlatformRetained triggeredVP; for (i=boundsEntryList.arraySize()-1; i >=0; i--) { wentry = boundsEntryArr[i]; // only this thread can modify wentry.transformedRegion, so // no need to getWithLock() triggeredVP = intersectVPCenter(wentry.transformedRegion); if (triggeredVP == null) { boundsEntryList.remove(wentry); } } // handle ViewPlatform Exit WakeupOnViewPlatformExit boundsExitArr[] = (WakeupOnViewPlatformExit []) boundsExitList.toArray(false); WakeupOnViewPlatformExit wexit; for (i=boundsExitList.arraySize()-1; i >=0; i--) { wexit = boundsExitArr[i]; // only this thread can modify wentry.transformedRegion, so // no need to getWithLock() triggeredVP = intersectVPCenter(wexit.transformedRegion); if (triggeredVP == null) { boundsExitList.remove(wexit); wexit.setTriggered(); } } } void removeBehavior(BehaviorRetained behav) { behaviors.remove(behav); if ((behav.wakeupCondition != null) && (behav.wakeupCondition.behav != null)) { behav.wakeupCondition.cleanTree(this); if (behav.universe == universe) { behav.conditionSet = false; } } // cleanup boundsEntryList // since we didn't remove it on removeVPEntryCondition WakeupOnViewPlatformEntry boundsEntryArr[] = (WakeupOnViewPlatformEntry []) boundsEntryList.toArray(false); WakeupOnViewPlatformEntry wentry; for (int i=boundsEntryList.arraySize()-1; i>=0; i--) { wentry = boundsEntryArr[i]; if (wentry.behav == behav) { boundsEntryList.remove(wentry); } } // cleanup boundsExitList // since we didn't remove it on removeVPExitCondition WakeupOnViewPlatformExit boundsExitArr[] = (WakeupOnViewPlatformExit []) boundsExitList.toArray(false); WakeupOnViewPlatformExit wexit; for (int i=boundsExitList.arraySize()-1; i>=0; i--) { wexit = boundsExitArr[i]; if (wexit.behav == behav) { boundsExitList.remove(wexit); } } // cleanup currentSensorEntryList // since we didn't remove it on removeSensorEntryCondition WakeupOnSensorEntry currentSensorEntryArr[] = (WakeupOnSensorEntry []) currentSensorEntryList.toArray(false); WakeupOnSensorEntry sentry; for (int i=currentSensorEntryList.arraySize()-1; i>=0; i--) { sentry = currentSensorEntryArr[i]; if (sentry.behav == behav) { currentSensorEntryList.remove(sentry); } } // cleanup currentSensorExitList // since we didn't remove it on removeSensorExitCondition WakeupOnSensorExit currentSensorExitArr[] = (WakeupOnSensorExit []) currentSensorExitList.toArray(false); WakeupOnSensorExit sexit; for (int i=currentSensorExitList.arraySize()-1; i>=0; i--) { sexit = currentSensorExitArr[i]; if (sexit.behav == behav) { currentSensorExitList.remove(sexit); } } removeFromScheduleList(behav); } void handleAWTEvent(AWTEvent evt) { awtEventsBuffer.add(evt); VirtualUniverse.mc.sendRunMessage(universe, J3dThread.BEHAVIOR_SCHEDULER); } /** * This routine takes the awt event list and gives then to the awt event * conditions */ void handleAWTEvent() { WakeupOnAWTEvent awtConds[] = (WakeupOnAWTEvent []) wakeupOnAWTEvent.toArray(); AWTEvent events[]; int eventSize = wakeupOnAWTEvent.arraySize(); int awtBufferSize; synchronized (awtEventsBuffer) { events = (AWTEvent []) awtEventsBuffer.toArray(); awtBufferSize = awtEventsBuffer.size(); awtEventsBuffer.clear(); } WakeupOnAWTEvent awtCond; AWTEvent evt; int id; for (int i=0; i < eventSize; i++) { awtCond = awtConds[i]; for (int j=0; j < awtBufferSize; j++) { evt = events[j]; id = evt.getID(); if (awtCond.AwtId != 0) { if (awtCond.AwtId == id) { // XXXX: how do we clone this event (do we need to?) // Bug: 4181321 awtCond.addAWTEvent(evt); } } else { if (id >= ComponentEvent.COMPONENT_FIRST && id <= ComponentEvent.COMPONENT_LAST && (awtCond.EventMask & AWTEvent.COMPONENT_EVENT_MASK) != 0) { awtCond.addAWTEvent(evt); } else if (id >= FocusEvent.FOCUS_FIRST && id <= FocusEvent.FOCUS_LAST && (awtCond.EventMask & AWTEvent.FOCUS_EVENT_MASK) != 0) { awtCond.addAWTEvent(evt); } else if (id >= KeyEvent.KEY_FIRST && id <= KeyEvent.KEY_LAST && (awtCond.EventMask & AWTEvent.KEY_EVENT_MASK) != 0) { awtCond.addAWTEvent(evt); } else if ((id == MouseEvent.MOUSE_CLICKED || id == MouseEvent.MOUSE_ENTERED || id == MouseEvent.MOUSE_EXITED || id == MouseEvent.MOUSE_PRESSED || id == MouseEvent.MOUSE_RELEASED) && (awtCond.EventMask & AWTEvent.MOUSE_EVENT_MASK) != 0) { awtCond.addAWTEvent(evt); } else if ((id == MouseEvent.MOUSE_DRAGGED || id == MouseEvent.MOUSE_MOVED) && (awtCond.EventMask & AWTEvent.MOUSE_MOTION_EVENT_MASK) != 0) { awtCond.addAWTEvent(evt); } else if ((id == MouseEvent.MOUSE_WHEEL) && (awtCond.EventMask & AWTEvent.MOUSE_WHEEL_EVENT_MASK) != 0) { awtCond.addAWTEvent(evt); } } } } } void handleBehaviorPost(Behavior behav, int postid) { synchronized (behaviorPostBuffer) { int size = behaviorPostBuffer.size(); if (postIDBuffer.length == size) { int oldbuffer[] = postIDBuffer; postIDBuffer = new int[size << 1]; System.arraycopy(oldbuffer, 0, postIDBuffer, 0, size); } postIDBuffer[size] = postid; behaviorPostBuffer.add(behav); } VirtualUniverse.mc.sendRunMessage(universe, J3dThread.BEHAVIOR_SCHEDULER); } /** * This goes through all of the criteria waiting for Behavior Posts * and notifys them. */ void handleBehaviorPost() { Behavior behav; int postid; WakeupOnBehaviorPost wakeup; WakeupOnBehaviorPost wakeupConds[] = (WakeupOnBehaviorPost []) wakeupOnBehaviorPost.toArray(); Behavior behavArr[]; int behavBufferSize; synchronized (behaviorPostBuffer) { behavArr = (Behavior []) behaviorPostBuffer.toArray(); behavBufferSize = behaviorPostBuffer.size(); if (clonePostIDBuffer.length < behavBufferSize) { clonePostIDBuffer = new int[behavBufferSize]; } System.arraycopy(postIDBuffer, 0, clonePostIDBuffer, 0, behavBufferSize); behaviorPostBuffer.clear(); } int size = wakeupOnBehaviorPost.arraySize(); for (int i=0; i < size; i++) { wakeup = wakeupConds[i]; for (int j=0; j < behavBufferSize; j++) { behav = behavArr[j]; postid = clonePostIDBuffer[j]; if ((wakeup.post == postid || wakeup.post == 0) && (behav == wakeup.armingBehavior || wakeup.armingBehavior == null)) { wakeup.triggeringBehavior = behav; wakeup.triggeringPost = postid; wakeup.setTriggered(); } } } } /** * This goes through all of the criteria waiting for Elapsed Frames * and notified them. */ void incElapsedFrames() { WakeupOnElapsedFrames wakeupConds[] = (WakeupOnElapsedFrames []) wakeupOnElapsedFrames.toArray(true); int size = wakeupOnElapsedFrames.arraySize(); int i = 0; while (i < size) { wakeupConds[i++].newFrame(); } if ( size > 0) { VirtualUniverse.mc.sendRunMessage(universe, J3dThread.BEHAVIOR_SCHEDULER|J3dThread.UPDATE_BEHAVIOR); } if (branchDetach) { // Since this procedure may call by immediate mode user // thread, we can't just clear it in removeNodes() wakeupOnElapsedFrames.clearMirror(); branchDetach = false; } } void removeVPEntryCondition(WakeupCondition w) { wakeupOnViewPlatformEntry.remove(w); // don't remove boundsEntryList, it is use next time // when addVPExitCondition invoke to determine whether to // trigger an event or not. } void addVPEntryCondition(WakeupOnViewPlatformEntry w) { boolean needTrigger = true; // see if the matching wakeupOnViewPlatformEntry // condition exists & do cleanup WakeupOnViewPlatformEntry boundsEntryArr[] = (WakeupOnViewPlatformEntry []) boundsEntryList.toArray(false); WakeupOnViewPlatformEntry wentry; for (int i=boundsEntryList.arraySize()-1; i>=0; i--) { wentry = boundsEntryArr[i]; if ((wentry.behav == w.behav) && (wentry.region.equals(w.region))) { boundsEntryList.remove(i); // Case where we wakeOr() both condition together. // we should avoid calling setTrigger() every time. needTrigger = false; break; } } wakeupOnViewPlatformEntry.add(w); ViewPlatformRetained triggeredVP = intersectVPCenter(w.transformedRegion);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -