scheduler uses neno seconds to mesure time and calculates slipping accurate
This commit is contained in:
parent
8ff5c9b59a
commit
7c89af5a42
@ -284,7 +284,7 @@
|
||||
<AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/>
|
||||
<AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/>
|
||||
<AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/>
|
||||
<AuxValue name="designerSize" type="java.awt.Dimension" value="-84,-19,0,5,115,114,0,18,106,97,118,97,46,97,119,116,46,68,105,109,101,110,115,105,111,110,65,-114,-39,-41,-84,95,68,20,2,0,2,73,0,6,104,101,105,103,104,116,73,0,5,119,105,100,116,104,120,112,0,0,2,-122,0,0,3,-71"/>
|
||||
<AuxValue name="designerSize" type="java.awt.Dimension" value="-84,-19,0,5,115,114,0,18,106,97,118,97,46,97,119,116,46,68,105,109,101,110,115,105,111,110,65,-114,-39,-41,-84,95,68,20,2,0,2,73,0,6,104,101,105,103,104,116,73,0,5,119,105,100,116,104,120,112,0,0,2,-122,0,0,3,29"/>
|
||||
</AuxValues>
|
||||
|
||||
<Layout class="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout"/>
|
||||
@ -305,7 +305,7 @@
|
||||
<Component id="jButton2" min="-2" pref="67" max="-2" attributes="0"/>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Component id="stopButton" min="-2" pref="63" max="-2" attributes="0"/>
|
||||
<EmptySpace pref="545" max="32767" attributes="0"/>
|
||||
<EmptySpace pref="389" max="32767" attributes="0"/>
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<Component id="clock" alignment="1" min="-2" max="-2" attributes="0"/>
|
||||
<Group type="102" alignment="1" attributes="0">
|
||||
@ -417,6 +417,9 @@
|
||||
</StringArray>
|
||||
</Property>
|
||||
</Properties>
|
||||
<Events>
|
||||
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="jComboBox1ActionPerformed"/>
|
||||
</Events>
|
||||
<AuxValues>
|
||||
<AuxValue name="JavaCodeGenerator_TypeParameters" type="java.lang.String" value="<String>"/>
|
||||
</AuxValues>
|
||||
|
@ -251,6 +251,11 @@ public class NewMDIApplication extends javax.swing.JFrame {
|
||||
});
|
||||
|
||||
jComboBox1.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "1x", "2x", "4x", "10x", "100x", "1000x", "max." }));
|
||||
jComboBox1.addActionListener(new java.awt.event.ActionListener() {
|
||||
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
||||
jComboBox1ActionPerformed(evt);
|
||||
}
|
||||
});
|
||||
|
||||
javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
|
||||
jPanel2.setLayout(jPanel2Layout);
|
||||
@ -262,7 +267,7 @@ public class NewMDIApplication extends javax.swing.JFrame {
|
||||
.addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 67, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addComponent(stopButton, javax.swing.GroupLayout.PREFERRED_SIZE, 63, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 545, Short.MAX_VALUE)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 389, Short.MAX_VALUE)
|
||||
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addComponent(clock, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
|
||||
@ -723,6 +728,10 @@ public class NewMDIApplication extends javax.swing.JFrame {
|
||||
}
|
||||
}//GEN-LAST:event_viewTraderListCheckBoxActionPerformed
|
||||
|
||||
private void jComboBox1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBox1ActionPerformed
|
||||
// TODO add your handling code here:
|
||||
}//GEN-LAST:event_jComboBox1ActionPerformed
|
||||
|
||||
/**
|
||||
* @param args the command line arguments
|
||||
* @throws java.lang.IllegalAccessException
|
||||
|
@ -46,7 +46,7 @@ import java.util.concurrent.atomic.AtomicInteger;
|
||||
*/
|
||||
public class Scheduler extends Thread {
|
||||
|
||||
private double acceleration = 0.0;
|
||||
private double acceleration = 1.0;
|
||||
|
||||
public void setAcceleration(double val) {
|
||||
|
||||
@ -108,16 +108,54 @@ public class Scheduler extends Thread {
|
||||
|
||||
Clock clock;
|
||||
|
||||
long last_nanos = System.nanoTime();
|
||||
double current_nanos = 0;
|
||||
|
||||
/**
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public long currentTimeMillis1() {
|
||||
|
||||
long cur = System.nanoTime();
|
||||
long diff = cur - last_nanos;
|
||||
last_nanos = cur;
|
||||
|
||||
if (pause) {
|
||||
return (long) this.current_time_millis;
|
||||
}
|
||||
|
||||
// this.cur_nano += (((double)diff_nano)/1000000.0)*this.acceleration;
|
||||
// return (long)(cur_nano/1000000.0);
|
||||
|
||||
|
||||
|
||||
|
||||
this.current_nanos += (double)diff * (double)this.acceleration;
|
||||
|
||||
// this.current_time_millis += ((double) diff) * this.acceleration;
|
||||
|
||||
this.current_time_millis = this.current_nanos/1000000.0;
|
||||
|
||||
return (long) this.current_time_millis;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public long currentTimeMillis1_old() {
|
||||
|
||||
long cur_nano = System.nanoTime();
|
||||
long diff_nano = cur_nano - last_nanos;
|
||||
last_nanos = cur_nano;
|
||||
|
||||
long cur = System.currentTimeMillis();
|
||||
|
||||
long diff = cur - last_time_millis;
|
||||
long diff = (cur - last_time_millis);
|
||||
|
||||
//System.out.printf("Diff Nanos: %d Diff Millis %d, ND: %d\n", diff_nano, diff, diff_nano/1000000);
|
||||
last_time_millis = cur;
|
||||
|
||||
// last_time_millis += diff;
|
||||
@ -127,11 +165,21 @@ public class Scheduler extends Thread {
|
||||
if (pause) {
|
||||
return (long) this.current_time_millis;
|
||||
}
|
||||
|
||||
// this.cur_nano += (((double)diff_nano)/1000000.0)*this.acceleration;
|
||||
// return (long)(cur_nano/1000000.0);
|
||||
double fac = (((double) diff) + 10.0) * this.acceleration;
|
||||
System.out.printf("Difdif: %f %f\n", fac, this.acceleration);
|
||||
this.current_time_millis += ((double) diff) * this.acceleration;
|
||||
return (long) this.current_time_millis;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public long currentTimeMillis() {
|
||||
// return (long)(cur_nano/1000000.0);
|
||||
return (long) this.current_time_millis;
|
||||
}
|
||||
|
||||
@ -226,7 +274,6 @@ public class Scheduler extends Thread {
|
||||
}
|
||||
|
||||
// HashMap<TimerTaskDef, Long> tasks = new HashMap<>();
|
||||
|
||||
private boolean addTimerTask(TimerTaskDef e) {
|
||||
|
||||
// long evtime = time + currentTimeMillis();
|
||||
@ -239,7 +286,6 @@ public class Scheduler extends Thread {
|
||||
e.curevtime = e.newevtime;
|
||||
|
||||
// tasks.put(e, e.evtime);
|
||||
|
||||
return s.add(e);
|
||||
}
|
||||
|
||||
@ -252,11 +298,9 @@ public class Scheduler extends Thread {
|
||||
private void cancelMy(TimerTaskDef e) {
|
||||
|
||||
// Long evtime = tasks.get(e.curevtime);
|
||||
|
||||
// if (evtime == null) {
|
||||
// return;
|
||||
// }
|
||||
|
||||
SortedSet<TimerTaskDef> s = event_queue.get(e.curevtime);
|
||||
if (s == null) {
|
||||
|
||||
@ -281,16 +325,26 @@ public class Scheduler extends Thread {
|
||||
|
||||
long t = event_queue.firstKey();
|
||||
long ct = currentTimeMillis1();
|
||||
ct = t;
|
||||
|
||||
|
||||
// ct = t;
|
||||
if (t > ct) {
|
||||
//if ((long) diff > 0) {
|
||||
// System.out.printf("Leave Event Queue in run events %d\n", Thread.currentThread().getId());
|
||||
System.out.printf("Sleeping somewat %d\n", (long) (t - this.currentTimeMillis() / this.acceleration));
|
||||
return (t - currentTimeMillis()) / (long) this.acceleration;
|
||||
// System.out.printf("Sleeping somewat %d\n", (long) (0.5 + (t - this.currentTimeMillis()) / this.acceleration));
|
||||
// return (long) diff;
|
||||
return (long) (((double)t - this.currentTimeMillis()) / this.acceleration );
|
||||
}
|
||||
|
||||
if (t<ct){
|
||||
// System.out.printf("Time is overslipping: %d\n",ct-t);
|
||||
this.current_time_millis = t;
|
||||
this.current_nanos=this.current_time_millis*1000000.0;
|
||||
|
||||
}
|
||||
|
||||
// if (t <= ct) {
|
||||
this.current_time_millis = t;
|
||||
|
||||
SortedSet s = event_queue.get(t);
|
||||
Object rc = event_queue.remove(t);
|
||||
Iterator<TimerTaskDef> it = s.iterator();
|
||||
@ -323,7 +377,7 @@ public class Scheduler extends Thread {
|
||||
|
||||
void initScheduler() {
|
||||
current_time_millis = 0.0;
|
||||
// this.startTimerTask(new EmptyCtr(), 0);
|
||||
this.startTimerTask(new EmptyCtr(), 0);
|
||||
terminate = false;
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user