aboutsummaryrefslogtreecommitdiffstats
path: root/src/classes
diff options
context:
space:
mode:
authorKevin Rushforth <[email protected]>2005-12-05 21:14:26 +0000
committerKevin Rushforth <[email protected]>2005-12-05 21:14:26 +0000
commitc6487f83fcbb54bf2a98914094e8813641f017e2 (patch)
tree76f207d15ba58d4833bc0c0e46bda458b29bf2ba /src/classes
parent2f6fd6914d73f213b6ff9a8055284605c2998fb9 (diff)
Fixed the following issues:
Issue 202: Need to upgrade to latest glext.h header file Issue 203: System.currentTimeMillis is too inaccurate on Windows for fine-grained timing git-svn-id: https://svn.java.net/svn/j3d-core~svn/trunk@475 ba19aa83-45c5-6ac9-afd3-db810772062c
Diffstat (limited to 'src/classes')
-rw-r--r--src/classes/share/javax/media/j3d/Alpha.java11
-rw-r--r--src/classes/share/javax/media/j3d/BehaviorScheduler.java4
-rw-r--r--src/classes/share/javax/media/j3d/GeometryDecompressor.java4
-rw-r--r--src/classes/share/javax/media/j3d/GeometryDecompressorRetained.java4
-rw-r--r--src/classes/share/javax/media/j3d/GeometryDecompressorShape3D.java4
-rw-r--r--src/classes/share/javax/media/j3d/Interpolator.java2
-rw-r--r--src/classes/share/javax/media/j3d/J3dClock.java72
-rw-r--r--src/classes/share/javax/media/j3d/MasterControl.java25
-rw-r--r--src/classes/share/javax/media/j3d/Renderer.java2
-rw-r--r--src/classes/share/javax/media/j3d/SensorRead.java2
-rw-r--r--src/classes/share/javax/media/j3d/SoundScheduler.java8
-rw-r--r--src/classes/share/javax/media/j3d/SoundSchedulerAtom.java2
-rw-r--r--src/classes/share/javax/media/j3d/TimerThread.java4
-rw-r--r--src/classes/share/javax/media/j3d/View.java2
-rw-r--r--src/classes/share/javax/media/j3d/WakeupOnElapsedTime.java6
15 files changed, 119 insertions, 33 deletions
diff --git a/src/classes/share/javax/media/j3d/Alpha.java b/src/classes/share/javax/media/j3d/Alpha.java
index 58fe903..0772cd6 100644
--- a/src/classes/share/javax/media/j3d/Alpha.java
+++ b/src/classes/share/javax/media/j3d/Alpha.java
@@ -127,8 +127,7 @@ public class Alpha extends NodeComponent {
// Stop time gets used only for loopCount > 0
private float stopTime;
- //long startTime = 0L; Convert it to Seconds
- // NOTE: Start Time is in milliseconds
+ // Start time in milliseconds
private long startTime = MasterControl.systemStartTime;
/**
@@ -300,7 +299,7 @@ public class Alpha extends NodeComponent {
* @since Java 3D 1.3
*/
public void pause() {
- pause(System.currentTimeMillis());
+ pause(J3dClock.currentTimeMillis());
}
/**
@@ -349,7 +348,7 @@ public class Alpha extends NodeComponent {
* @since Java 3D 1.3
*/
public void resume() {
- resume(System.currentTimeMillis());
+ resume(J3dClock.currentTimeMillis());
}
/**
@@ -420,7 +419,7 @@ public class Alpha extends NodeComponent {
* @return a value between 0.0 and 1.0 based on the current time
*/
public float value() {
- long currentTime = paused ? pauseTime : System.currentTimeMillis();
+ long currentTime = paused ? pauseTime : J3dClock.currentTimeMillis();
return this.value(currentTime);
}
@@ -961,7 +960,7 @@ public class Alpha extends NodeComponent {
* @return true if no longer looping, false otherwise
*/
public boolean finished() {
- long currentTime = paused ? pauseTime : System.currentTimeMillis();
+ long currentTime = paused ? pauseTime : J3dClock.currentTimeMillis();
return ((loopCount != -1) &&
((float)(currentTime - startTime) * .001f > stopTime));
}
diff --git a/src/classes/share/javax/media/j3d/BehaviorScheduler.java b/src/classes/share/javax/media/j3d/BehaviorScheduler.java
index 31e9d2d..a4887c5 100644
--- a/src/classes/share/javax/media/j3d/BehaviorScheduler.java
+++ b/src/classes/share/javax/media/j3d/BehaviorScheduler.java
@@ -111,7 +111,7 @@ class BehaviorScheduler extends J3dThread {
UnorderList list;
int i, size, interval;
- lastStartTime = System.currentTimeMillis();
+ lastStartTime = J3dClock.currentTimeMillis();
if (stopCount >= 0) {
VirtualUniverse.mc.sendRunMessage(univ, J3dThread.BEHAVIOR_SCHEDULER);
@@ -201,7 +201,7 @@ class BehaviorScheduler extends J3dThread {
behaviorStructure.handleAWTEvent();
behaviorStructure.handleBehaviorPost();
- lastStopTime = System.currentTimeMillis();
+ lastStopTime = J3dClock.currentTimeMillis();
}
diff --git a/src/classes/share/javax/media/j3d/GeometryDecompressor.java b/src/classes/share/javax/media/j3d/GeometryDecompressor.java
index ebbe6a4..895b5b6 100644
--- a/src/classes/share/javax/media/j3d/GeometryDecompressor.java
+++ b/src/classes/share/javax/media/j3d/GeometryDecompressor.java
@@ -1165,11 +1165,11 @@ abstract class GeometryDecompressor {
vertexCount = 0 ;
System.out.println(" GeometryDecompressor: decompressing " +
length + " bytes...") ;
- startTime = System.currentTimeMillis() ;
+ startTime = J3dClock.currentTimeMillis() ;
}
private void benchmarkPrint(int length) {
- float t = (System.currentTimeMillis() - startTime) / 1000.0f ;
+ float t = (J3dClock.currentTimeMillis() - startTime) / 1000.0f ;
System.out.println
(" done in " + t + " sec." + "\n" +
" decompressed " + vertexCount + " vertices at " +
diff --git a/src/classes/share/javax/media/j3d/GeometryDecompressorRetained.java b/src/classes/share/javax/media/j3d/GeometryDecompressorRetained.java
index e9cbdc8..0fb6597 100644
--- a/src/classes/share/javax/media/j3d/GeometryDecompressorRetained.java
+++ b/src/classes/share/javax/media/j3d/GeometryDecompressorRetained.java
@@ -307,11 +307,11 @@ class GeometryDecompressorRetained extends GeometryDecompressor {
if (boundsOnly) System.out.println(" computing bounds only") ;
if (positionsOnly) System.out.println(" computing positions only") ;
- startTime = System.currentTimeMillis() ;
+ startTime = J3dClock.currentTimeMillis() ;
}
private void endPrint() {
- endTime = System.currentTimeMillis() ;
+ endTime = J3dClock.currentTimeMillis() ;
if (benchmark || statistics)
printBench() ;
diff --git a/src/classes/share/javax/media/j3d/GeometryDecompressorShape3D.java b/src/classes/share/javax/media/j3d/GeometryDecompressorShape3D.java
index d9cf9ae..eb593e6 100644
--- a/src/classes/share/javax/media/j3d/GeometryDecompressorShape3D.java
+++ b/src/classes/share/javax/media/j3d/GeometryDecompressorShape3D.java
@@ -368,11 +368,11 @@ class GeometryDecompressorShape3D extends GeometryDecompressor {
triangleCount = 0 ;
origVertexCount = 0 ;
- startTime = System.currentTimeMillis() ;
+ startTime = J3dClock.currentTimeMillis() ;
}
private void endPrint() {
- endTime = System.currentTimeMillis() ;
+ endTime = J3dClock.currentTimeMillis() ;
if (benchmark || statistics)
printBench() ;
diff --git a/src/classes/share/javax/media/j3d/Interpolator.java b/src/classes/share/javax/media/j3d/Interpolator.java
index fd23403..0cd2898 100644
--- a/src/classes/share/javax/media/j3d/Interpolator.java
+++ b/src/classes/share/javax/media/j3d/Interpolator.java
@@ -85,7 +85,7 @@ public abstract class Interpolator extends Behavior {
*/
public void initialize() {
// Reset alpha
- //alpha.setStartTime(System.currentTimeMillis());
+ //alpha.setStartTime(J3dClock.currentTimeMillis());
// Insert wakeup condition into queue
wakeupOn(defaultWakeupCriterion);
diff --git a/src/classes/share/javax/media/j3d/J3dClock.java b/src/classes/share/javax/media/j3d/J3dClock.java
new file mode 100644
index 0000000..edd52bd
--- /dev/null
+++ b/src/classes/share/javax/media/j3d/J3dClock.java
@@ -0,0 +1,72 @@
+/*
+ * $RCSfile$
+ *
+ * Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved.
+ *
+ * Use is subject to license terms.
+ *
+ * $Revision$
+ * $Date$
+ * $State$
+ */
+
+package javax.media.j3d;
+
+/**
+ * Utility class to provide a more accurate replacement for
+ * System.currentTimeMillis().
+ */
+class J3dClock {
+
+ private static long deltaTime;
+ private static final long nsecPerMsec = 1000000;
+
+ /**
+ * Private constructor, since no instance should ever be created.
+ */
+ private J3dClock() {
+ }
+
+ /**
+ * Method to return a high-resolution timer value.
+ *
+ * NOTE: when we no longer support JDK 1.4.2 we can replace this
+ * method with System.nanoTime().
+ */
+ private static long getHiResTimerValue() {
+ return MasterControl.getNativeTimerValue();
+ }
+
+ /**
+ * Returns the current time in milliseconds. This is a more
+ * accurate version of System.currentTimeMillis and should be used in
+ * its place.
+ *
+ * @return the current time in milliseconds.
+ */
+ static long currentTimeMillis() {
+ return (getHiResTimerValue() / nsecPerMsec) + deltaTime;
+ }
+
+ static {
+ // Ensure that the native libraries are loaded (this can be removed
+ // once we switch to using System.nanoTime()
+ VirtualUniverse.loadLibraries();
+
+ // Call time methods once without using their values to ensure that
+ // the methods are "warmed up". We need to make sure that the actual
+ // calls that we use take place as close together as possible in time.
+ System.currentTimeMillis();
+ getHiResTimerValue();
+
+ // Compute deltaTime between System.currentTimeMillis()
+ // and the high-res timer, use a synchronized block to force both calls
+ // to be made before the integer divide
+ long baseTime, baseTimerValue;
+ synchronized (J3dClock.class) {
+ baseTime = System.currentTimeMillis();
+ baseTimerValue = getHiResTimerValue();
+ }
+ deltaTime = baseTime - (baseTimerValue / nsecPerMsec);
+ }
+}
diff --git a/src/classes/share/javax/media/j3d/MasterControl.java b/src/classes/share/javax/media/j3d/MasterControl.java
index 8e15f3f..c5ba916 100644
--- a/src/classes/share/javax/media/j3d/MasterControl.java
+++ b/src/classes/share/javax/media/j3d/MasterControl.java
@@ -290,9 +290,10 @@ class MasterControl {
/**
* This is the start time upon which alpha's and behaviors
- * are synchronized to.
+ * are synchronized to. It is initialized once, the first time
+ * that a MasterControl object is created.
*/
- static long systemStartTime = System.currentTimeMillis();
+ static long systemStartTime = 0L;
// The rendering API we are using
private int renderingAPI = RENDER_OPENGL_SOLARIS;
@@ -451,7 +452,7 @@ class MasterControl {
};
long awt;
- native long getAWT();
+ private native long getAWT();
// Method to initialize the native J3D library
private native boolean initializeJ3D(boolean disableXinerama);
@@ -466,6 +467,14 @@ class MasterControl {
private native void setThreadConcurrency(int newLevel);
private native int getThreadConcurrency();
+ // Native method to get the high-resolution timer value.
+ // This method is only called by the J3dClock.getHiResTimerValue.
+ // It is defined as a MasterControl method for convenience, so we don't
+ // have to have yet another class with native methods.
+ //
+ // NOTE: once we drop support for JDK 1.4.2, this method will go away.
+ static native long getNativeTimerValue();
+
// Maximum lights supported by the native API
private native int getMaximumLights();
int maxLights;
@@ -510,6 +519,12 @@ class MasterControl {
isD3DAPI = (renderingAPI == RENDER_DIRECT3D);
isWin32 = isD3DAPI || (renderingAPI == RENDER_OPENGL_WIN32);
+ // Initialize the start time upon which alpha's and behaviors
+ // are synchronized to (if it isn't already set).
+ if (systemStartTime == 0L) {
+ systemStartTime = J3dClock.currentTimeMillis();
+ }
+
if(J3dDebug.devPhase) {
// Check to see whether debug mode is allowed
J3dDebug.debug = getBooleanProperty("j3d.debug", false,
@@ -3363,7 +3378,7 @@ class MasterControl {
if ((thread.threadOpts & J3dThreadData.START_TIMER) != 0) {
view = (View)((Object[])thread.threadArgs)[2];
view.frameNumber++;
- view.startTime = System.currentTimeMillis();
+ view.startTime = J3dClock.currentTimeMillis();
}
@@ -3536,7 +3551,7 @@ class MasterControl {
if (nthread.type == J3dThread.RENDER_THREAD) {
View v = (View) nthread.args[3];
if (v != null) { // STOP_TIMER
- v.stopTime = System.currentTimeMillis();
+ v.stopTime = J3dClock.currentTimeMillis();
}
if (--renderPending == 0) {
diff --git a/src/classes/share/javax/media/j3d/Renderer.java b/src/classes/share/javax/media/j3d/Renderer.java
index bb61822..8abfe00 100644
--- a/src/classes/share/javax/media/j3d/Renderer.java
+++ b/src/classes/share/javax/media/j3d/Renderer.java
@@ -1348,7 +1348,7 @@ class Renderer extends J3dThread {
if (doTiming) {
numframes += 1.0f;
if (numframes >= 20.0f) {
- currtime = System.currentTimeMillis();
+ currtime = J3dClock.currentTimeMillis();
System.err.println(
numframes/((currtime-lasttime)/1000.0f) +
" frames per second");
diff --git a/src/classes/share/javax/media/j3d/SensorRead.java b/src/classes/share/javax/media/j3d/SensorRead.java
index f7f2839..af3849f 100644
--- a/src/classes/share/javax/media/j3d/SensorRead.java
+++ b/src/classes/share/javax/media/j3d/SensorRead.java
@@ -73,7 +73,7 @@ public class SensorRead {
this.buttonValues = new int[numButtons];
// Do this last
- this.time = System.currentTimeMillis();
+ this.time = J3dClock.currentTimeMillis();
}
final void set(SensorRead sensorRead) {
diff --git a/src/classes/share/javax/media/j3d/SoundScheduler.java b/src/classes/share/javax/media/j3d/SoundScheduler.java
index 15981b6..906eea3 100644
--- a/src/classes/share/javax/media/j3d/SoundScheduler.java
+++ b/src/classes/share/javax/media/j3d/SoundScheduler.java
@@ -1224,12 +1224,12 @@ class SoundScheduler extends J3dStructure {
nSelectedSScapes++;
if (debugFlag)
debugPrint(": region of intersection for "+
- "soundscape "+k+" found at "+System.currentTimeMillis());
+ "soundscape "+k+" found at "+J3dClock.currentTimeMillis());
} else {
if (debugFlag)
debugPrint(
": region of intersection for soundscape "+
- k + " not found at "+ System.currentTimeMillis());
+ k + " not found at "+ J3dClock.currentTimeMillis());
}
}
}
@@ -1638,7 +1638,7 @@ class SoundScheduler extends J3dStructure {
//
// test current time against endTime of sound to determine
// if sound is Completely finished playing
- long currentTime = System.currentTimeMillis();
+ long currentTime = J3dClock.currentTimeMillis();
if (soundAtom.endTime>0 && soundAtom.endTime<=currentTime) {
// sound's completed playing, force action
soundAtom.schedulingAction = SoundSchedulerAtom.COMPLETE;
@@ -1981,7 +1981,7 @@ class SoundScheduler extends J3dStructure {
* complete).
*/
long shortestTimeToFinish() {
- long currentTime = System.currentTimeMillis();
+ long currentTime = J3dClock.currentTimeMillis();
long shortestTime = -1L;
SoundSchedulerAtom soundAtom;
synchronized (prioritizedSounds) {
diff --git a/src/classes/share/javax/media/j3d/SoundSchedulerAtom.java b/src/classes/share/javax/media/j3d/SoundSchedulerAtom.java
index a4dcccc..0fbe61c 100644
--- a/src/classes/share/javax/media/j3d/SoundSchedulerAtom.java
+++ b/src/classes/share/javax/media/j3d/SoundSchedulerAtom.java
@@ -185,7 +185,7 @@ class SoundSchedulerAtom extends Object {
// sound is currently playing, then set endTime to
// play remaining portion of loop portion plus the
// release portion.
- long currentTime = System.currentTimeMillis();
+ long currentTime = J3dClock.currentTimeMillis();
endTime = currentTime + ( (loopLength -
((currentTime - startTime - attackLength) % loopLength)) +
releaseLength );
diff --git a/src/classes/share/javax/media/j3d/TimerThread.java b/src/classes/share/javax/media/j3d/TimerThread.java
index a5f8878..30c5d61 100644
--- a/src/classes/share/javax/media/j3d/TimerThread.java
+++ b/src/classes/share/javax/media/j3d/TimerThread.java
@@ -56,7 +56,7 @@ class TimerThread extends Thread {
void addInputDeviceSchedCond() {
inputDeviceSchedCond.triggeredTime =
InputDeviceScheduler.samplingTime +
- System.currentTimeMillis();
+ J3dClock.currentTimeMillis();
add(inputDeviceSchedCond);
}
@@ -87,7 +87,7 @@ class TimerThread extends Thread {
while (running) {
runMonitor(WAIT, waitTime);
- time = System.currentTimeMillis();
+ time = J3dClock.currentTimeMillis();
while (true) {
cond = null;
diff --git a/src/classes/share/javax/media/j3d/View.java b/src/classes/share/javax/media/j3d/View.java
index ff6a964..1c3f231 100644
--- a/src/classes/share/javax/media/j3d/View.java
+++ b/src/classes/share/javax/media/j3d/View.java
@@ -2688,7 +2688,7 @@ public class View extends Object {
sleepTime = 0;
} else {
sleepTime = minFrameCycleTime -
- (System.currentTimeMillis() - startTime);
+ (J3dClock.currentTimeMillis() - startTime);
isMinCycleTimeAchieve = (sleepTime <= 0);
}
}
diff --git a/src/classes/share/javax/media/j3d/WakeupOnElapsedTime.java b/src/classes/share/javax/media/j3d/WakeupOnElapsedTime.java
index 7b29328..a466bee 100644
--- a/src/classes/share/javax/media/j3d/WakeupOnElapsedTime.java
+++ b/src/classes/share/javax/media/j3d/WakeupOnElapsedTime.java
@@ -51,7 +51,7 @@ public final class WakeupOnElapsedTime extends WakeupCriterion {
* used to add wakeupCondition to behavior structure.
*/
void addBehaviorCondition(BehaviorStructure bs) {
- this.triggeredTime = wait + System.currentTimeMillis();
+ this.triggeredTime = wait + J3dClock.currentTimeMillis();
behav.wakeupArray[BehaviorRetained.WAKEUP_TIME_INDEX]++;
behav.wakeupMask |= BehaviorRetained.WAKEUP_TIME;
VirtualUniverse.mc.timerThread.add(this);
@@ -78,7 +78,7 @@ public final class WakeupOnElapsedTime extends WakeupCriterion {
*/
void reInsertElapseTimeCond() {
super.reInsertElapseTimeCond();
- this.triggeredTime = wait + System.currentTimeMillis();
+ this.triggeredTime = wait + J3dClock.currentTimeMillis();
VirtualUniverse.mc.timerThread.add(this);
}
@@ -88,7 +88,7 @@ public final class WakeupOnElapsedTime extends WakeupCriterion {
* set every time the condition met.
*/
void resetBehaviorCondition(BehaviorStructure bs) {
- this.triggeredTime = wait + System.currentTimeMillis();
+ this.triggeredTime = wait + J3dClock.currentTimeMillis();
VirtualUniverse.mc.timerThread.add(this);
}
}