aboutsummaryrefslogtreecommitdiffstats
path: root/src/classes/share
diff options
context:
space:
mode:
authorHarvey Harrison <[email protected]>2012-03-03 14:33:05 -0800
committerHarvey Harrison <[email protected]>2012-03-03 14:53:31 -0800
commit414c861df0f72ce5c90cf3106798c103fcc07a76 (patch)
tree039f973aee55de74ee7791b321c6a0ce48fdcdaa /src/classes/share
parentef7c7458b9166abf83756e16aa29bf93b7dd2c3a (diff)
j3dcore: change getViewPlatformList() to never return null and remove checks
Also, consistently lock the cached array using the List it caches. Signed-off-by: Harvey Harrison <[email protected]>
Diffstat (limited to 'src/classes/share')
-rw-r--r--src/classes/share/javax/media/j3d/BehaviorStructure.java27
-rw-r--r--src/classes/share/javax/media/j3d/VirtualUniverse.java75
2 files changed, 37 insertions, 65 deletions
diff --git a/src/classes/share/javax/media/j3d/BehaviorStructure.java b/src/classes/share/javax/media/j3d/BehaviorStructure.java
index fc46103..d817c07 100644
--- a/src/classes/share/javax/media/j3d/BehaviorStructure.java
+++ b/src/classes/share/javax/media/j3d/BehaviorStructure.java
@@ -36,7 +36,6 @@ import java.awt.event.ComponentEvent;
import java.awt.event.FocusEvent;
import java.awt.event.KeyEvent;
import java.awt.event.MouseEvent;
-import java.util.ArrayList;
import java.util.Arrays;
import javax.vecmath.Point3d;
@@ -1269,26 +1268,26 @@ class BehaviorStructure extends J3dStructure {
}
- void reEvaluatePhysicalEnvironments() {
+void reEvaluatePhysicalEnvironments() {
// we can't just add or remove from the list since
// physicalEnvironment may be share by multiple view
- View v;
- View views[];
- ArrayList<ViewPlatformRetained> vpList = universe.viewPlatforms;
+ ViewPlatformRetained[] vpr = universe.getViewPlatformList();
physicalEnvironments.clear();
- for (int i=vpList.size()-1; i>=0; i--) {
- views = 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);
+ for (int i = vpr.length - 1; i >= 0; i--) {
+ View[] views = vpr[i].getViewList();
+ for (int j = views.length - 1; j >= 0; j--) {
+ View v = views[j];
+ if (!v.active)
+ continue;
+
+ if (!physicalEnvironments.contains(v.physicalEnvironment)) {
+ physicalEnvironments.add(v.physicalEnvironment);
+ }
}
- }
}
- }
+}
void checkSensorEntryExit() {
int i, idx;
diff --git a/src/classes/share/javax/media/j3d/VirtualUniverse.java b/src/classes/share/javax/media/j3d/VirtualUniverse.java
index 4b55459..8cf8df3 100644
--- a/src/classes/share/javax/media/j3d/VirtualUniverse.java
+++ b/src/classes/share/javax/media/j3d/VirtualUniverse.java
@@ -81,14 +81,10 @@ public class VirtualUniverse extends Object {
// A list of locales that are contained within this universe
Vector<Locale> listOfLocales = new Vector<Locale>();
-// The list of view platforms.
-ArrayList<ViewPlatformRetained> viewPlatforms = new ArrayList<ViewPlatformRetained>();
-
-// The cached list of vp's
-ViewPlatformRetained[] viewPlatformList = null;
-
- // A flag that indicates that the list of view platforms has changed
- boolean vpChanged = false;
+// The list of view platforms, a changed flag and a cached array
+private ArrayList<ViewPlatformRetained> viewPlatforms = new ArrayList<ViewPlatformRetained>();
+private boolean vpChanged = false;
+private ViewPlatformRetained[] viewPlatformList = new ViewPlatformRetained[0];
// The list of backgrounds
Vector backgrounds = new Vector();
@@ -661,22 +657,29 @@ public Enumeration<Locale> getAllLocales() {
}
}
- void addViewPlatform(ViewPlatformRetained vp) {
- vpChanged = true;
- viewPlatforms.add(vp);
- }
+void addViewPlatform(ViewPlatformRetained vp) {
+ synchronized (viewPlatforms) {
+ vpChanged = true;
+ viewPlatforms.add(vp);
+ }
+}
- void removeViewPlatform(ViewPlatformRetained vp) {
- vpChanged = true;
- viewPlatforms.remove(viewPlatforms.indexOf(vp));
- }
+void removeViewPlatform(ViewPlatformRetained vp) {
+ synchronized (viewPlatforms) {
+ if (viewPlatforms.remove(vp))
+ vpChanged = true;
+ }
+}
+
+ViewPlatformRetained[] getViewPlatformList() {
+ synchronized (viewPlatforms) {
+ if (vpChanged) {
+ viewPlatformList = viewPlatforms.toArray(new ViewPlatformRetained[viewPlatforms.size()]);
+ vpChanged = false;
+ }
-synchronized ViewPlatformRetained[] getViewPlatformList() {
- if (vpChanged) {
- viewPlatformList = viewPlatforms.toArray(new ViewPlatformRetained[viewPlatforms.size()]);
- vpChanged = false;
+ return viewPlatformList;
}
- return viewPlatformList;
}
void checkForEnableEvents() {
@@ -702,9 +705,6 @@ void disableFocusEvents() {
ViewPlatformRetained[] vps = getViewPlatformList();
enableFocus = false;
- if (vps == null)
- return;
-
for (int i = 0; i < vps.length; i++) {
View[] views = vps[i].getViewList();
for (int j = views.length - 1; j >= 0; j--) {
@@ -723,9 +723,6 @@ void enableFocusEvents() {
ViewPlatformRetained[] vps = getViewPlatformList();
enableFocus = true;
- if (vps == null)
- return;
-
for (int i = 0; i < vps.length; i++) {
View[] views = vps[i].getViewList();
for (int j = views.length - 1; j >= 0; j--) {
@@ -744,9 +741,6 @@ void disableKeyEvents() {
ViewPlatformRetained[] vps = getViewPlatformList();
enableKey = false;
- if (vps == null)
- return;
-
for (int i = 0; i < vps.length; i++) {
View[] views = vps[i].getViewList();
for (int j = views.length - 1; j >= 0; j--) {
@@ -765,9 +759,6 @@ void enableKeyEvents() {
ViewPlatformRetained[] vps = getViewPlatformList();
enableKey = true;
- if (vps == null)
- return;
-
for (int i = 0; i < vps.length; i++) {
View[] views = vps[i].getViewList();
for (int j = views.length - 1; j >= 0; j--) {
@@ -786,9 +777,6 @@ void disableMouseEvents() {
ViewPlatformRetained[] vps = getViewPlatformList();
enableMouse = false;
- if (vps == null)
- return;
-
for (int i = 0; i < vps.length; i++) {
View[] views = vps[i].getViewList();
for (int j = views.length - 1; j >= 0; j--) {
@@ -807,9 +795,6 @@ void enableMouseEvents() {
ViewPlatformRetained[] vps = getViewPlatformList();
enableMouse = true;
- if (vps == null)
- return;
-
for (int i = 0; i < vps.length; i++) {
View[] views = vps[i].getViewList();
for (int j = views.length - 1; j >= 0; j--) {
@@ -828,9 +813,6 @@ void disableMouseMotionEvents() {
ViewPlatformRetained[] vps = getViewPlatformList();
enableMouseMotion = false;
- if (vps == null)
- return;
-
for (int i = 0; i < vps.length; i++) {
View[] views = vps[i].getViewList();
for (int j = views.length - 1; j >= 0; j--) {
@@ -849,9 +831,6 @@ void enableMouseMotionEvents() {
ViewPlatformRetained[] vps = getViewPlatformList();
enableMouseMotion = true;
- if (vps == null)
- return;
-
for (int i = 0; i < vps.length; i++) {
View[] views = vps[i].getViewList();
for (int j = views.length - 1; j >= 0; j--) {
@@ -870,9 +849,6 @@ void disableMouseWheelEvents() {
ViewPlatformRetained[] vps = getViewPlatformList();
enableMouseWheel = false;
- if (vps == null)
- return;
-
for (int i = 0; i < vps.length; i++) {
View[] views = vps[i].getViewList();
for (int j = views.length - 1; j >= 0; j--) {
@@ -891,9 +867,6 @@ void enableMouseWheelEvents() {
ViewPlatformRetained[] vps = getViewPlatformList();
enableMouseWheel = true;
- if (vps == null)
- return;
-
for (int i = 0; i < vps.length; i++) {
View[] views = vps[i].getViewList();
for (int j = views.length - 1; j >= 0; j--) {