[DEV] update to java clock model

This commit is contained in:
Edouard DUPIN 2021-05-31 21:58:53 +02:00
parent 04ce3868d5
commit cfc2082d02
5 changed files with 50 additions and 41 deletions

View File

@ -5,7 +5,8 @@
*/ */
package org.atriasoft.ewol.context; package org.atriasoft.ewol.context;
import org.atriasoft.echrono.Clock; import java.time.Clock;
import org.atriasoft.etk.Uri; import org.atriasoft.etk.Uri;
import org.atriasoft.etk.math.Vector2f; import org.atriasoft.etk.math.Vector2f;
import org.atriasoft.etk.math.Vector2i; import org.atriasoft.etk.math.Vector2i;
@ -16,8 +17,8 @@ import org.atriasoft.ewol.object.ObjectManager;
import org.atriasoft.ewol.widget.Widget; import org.atriasoft.ewol.widget.Widget;
import org.atriasoft.ewol.widget.WidgetManager; import org.atriasoft.ewol.widget.WidgetManager;
import org.atriasoft.ewol.widget.Windows; import org.atriasoft.ewol.widget.Windows;
import org.atriasoft.gale.GaleApplication;
import org.atriasoft.gale.Gale; import org.atriasoft.gale.Gale;
import org.atriasoft.gale.GaleApplication;
import org.atriasoft.gale.context.ClipboardList; import org.atriasoft.gale.context.ClipboardList;
import org.atriasoft.gale.context.CommandLine; import org.atriasoft.gale.context.CommandLine;
import org.atriasoft.gale.context.GaleContext; import org.atriasoft.gale.context.GaleContext;
@ -290,9 +291,9 @@ public class EwolContext extends GaleApplication {
appl.onPause(this); appl.onPause(this);
Log.info(" == > Ewol system pause (END)"); Log.info(" == > Ewol system pause (END)");
} }
@Override
public void onPeriod(final Clock time) { public void onPeriod(final Clock clock, final long time) {
this.objectManager.timeCall(time); this.objectManager.timeCall(clock, time);
} }
@Override @Override

View File

@ -7,8 +7,6 @@ package org.atriasoft.ewol.context;
import java.lang.ref.WeakReference; import java.lang.ref.WeakReference;
import org.atriasoft.echrono.Clock;
import org.atriasoft.echrono.Duration;
import org.atriasoft.etk.math.FMath; import org.atriasoft.etk.math.FMath;
import org.atriasoft.etk.math.Vector2f; import org.atriasoft.etk.math.Vector2f;
import org.atriasoft.ewol.event.InputSystem; import org.atriasoft.ewol.event.InputSystem;
@ -24,12 +22,13 @@ import org.atriasoft.gale.key.KeyType;
*/ */
class InputLimit { class InputLimit {
public int dpiOffset; public int dpiOffset;
public Duration sepatateTime; public long sepatateTime; // in nanosecond System.nanoTime()
} }
class InputManager { class InputManager {
private static final long MILLI_TO_DURATION = 1000000;
private static final long SECONDS_TO_DURATION = 1000000000;
private static final int MAX_MANAGE_INPUT = 15; private static final int MAX_MANAGE_INPUT = 15;
private final EwolContext context; private final EwolContext context;
private int dpi; private int dpi;
private final InputLimit eventInputLimit = new InputLimit(); private final InputLimit eventInputLimit = new InputLimit();
@ -43,6 +42,7 @@ class InputManager {
public InputManager(final EwolContext context) { public InputManager(final EwolContext context) {
this.context = context; this.context = context;
setDpi(200); setDpi(200);
Log.info("Init (start)"); Log.info("Init (start)");
for (int iii = 0; iii < InputManager.MAX_MANAGE_INPUT; iii++) { for (int iii = 0; iii < InputManager.MAX_MANAGE_INPUT; iii++) {
@ -64,9 +64,9 @@ class InputManager {
} }
private void calculateLimit() { private void calculateLimit() {
this.eventInputLimit.sepatateTime = Duration.milliseconds(300); this.eventInputLimit.sepatateTime = 300 * InputManager.MILLI_TO_DURATION;
this.eventInputLimit.dpiOffset = this.dpi * 100; this.eventInputLimit.dpiOffset = this.dpi * 100;
this.eventMouseLimit.sepatateTime = Duration.milliseconds(300); this.eventMouseLimit.sepatateTime = 300 * InputManager.MILLI_TO_DURATION;
this.eventMouseLimit.dpiOffset = (int) (this.dpi * 0.1f); this.eventMouseLimit.dpiOffset = (int) (this.dpi * 0.1f);
} }
@ -272,14 +272,14 @@ class InputManager {
return; return;
} }
// get the curent time ... // get the curent time ...
final Clock currentTime = Clock.now(); final long currentTime = System.nanoTime();
final Windows tmpWindows = this.context.getWindows(); final Windows tmpWindows = this.context.getWindows();
if (isDown) { if (isDown) {
//Log.debug("GUI : Input ID=" + pointerID + " == >" + eventTable[pointerID].destinationInputId + " [DOWN] " + pos); //Log.debug("GUI : Input ID=" + pointerID + " == >" + eventTable[pointerID].destinationInputId + " [DOWN] " + pos);
if (eventTable[pointerID].isUsed) { if (eventTable[pointerID].isUsed) {
// we have an event previously ... check delay between click and offset position // we have an event previously ... check delay between click and offset position
if (currentTime.less(eventTable[pointerID].lastTimeEvent).isGreaterThan(localLimit.sepatateTime)) { if (currentTime - eventTable[pointerID].lastTimeEvent > localLimit.sepatateTime) {
cleanElement(eventTable, pointerID); cleanElement(eventTable, pointerID);
} else if (FMath.abs(eventTable[pointerID].downStart.x() - pos.x()) >= localLimit.dpiOffset || FMath.abs(eventTable[pointerID].downStart.y() - pos.y()) >= localLimit.dpiOffset) { } else if (FMath.abs(eventTable[pointerID].downStart.x() - pos.x()) >= localLimit.dpiOffset || FMath.abs(eventTable[pointerID].downStart.y() - pos.y()) >= localLimit.dpiOffset) {
cleanElement(eventTable, pointerID); cleanElement(eventTable, pointerID);
@ -447,7 +447,7 @@ class InputPoperty {
public boolean isDown = false; public boolean isDown = false;
public boolean isInside = false; public boolean isInside = false;
public boolean isUsed = false; public boolean isUsed = false;
public Clock lastTimeEvent = null; public long lastTimeEvent = 0; // in ns
public int nbClickEvent = 0; // 0 .. 1 .. 2 .. 3 public int nbClickEvent = 0; // 0 .. 1 .. 2 .. 3
public Vector2f origin = Vector2f.ZERO; public Vector2f origin = Vector2f.ZERO;
public Vector2f posEvent = Vector2f.ZERO; public Vector2f posEvent = Vector2f.ZERO;
@ -456,7 +456,7 @@ class InputPoperty {
public void clear() { public void clear() {
this.isUsed = false; this.isUsed = false;
this.destinationInputId = 0; this.destinationInputId = 0;
this.lastTimeEvent = new Clock(); this.lastTimeEvent = System.nanoTime();
this.curentWidgetEvent = null; this.curentWidgetEvent = null;
this.origin = Vector2f.ZERO; this.origin = Vector2f.ZERO;
this.size = Vector2f.MAX_VALUE; this.size = Vector2f.MAX_VALUE;

View File

@ -1,7 +1,7 @@
package org.atriasoft.ewol.event; package org.atriasoft.ewol.event;
import org.atriasoft.echrono.Clock; import java.time.Clock;
import org.atriasoft.echrono.Duration; import java.time.Duration;
/** @file /** @file
* @author Edouard DUPIN * @author Edouard DUPIN
@ -9,17 +9,19 @@ import org.atriasoft.echrono.Duration;
* @license MPL v2.0 (see license file) * @license MPL v2.0 (see license file)
*/ */
public record EventTime( public record EventTime(
Clock timeSystem, //!< Current system time (micro-second) Clock currentClock, //!< Current system time "Clock.systemUTC()"
Clock timeUpAppl, //!< Current application wake up-time (micro-second) Clock upClock, //!< Current application wake up-time "Clock.systemUTC() @ start"
Duration timeDelta, //!< Time from the last cycle call of the system (main appl tick) (second) long currentTime, //!< Current system time "System.nanoTime()"
Duration timeDeltaCall //!< Time from the last call (when we can manage periodic call with specifying periode) (second) long upTime, //!< Current application wake up-time "System.nanoTime() @ start"
Duration timeDelta, //!< Time from the last cycle call of the system (main appl tick)
Duration timeDeltaCall //!< Time from the last call (when we can manage periodic call with specifying periode)
) { ) {
public float getTimeDeltaCallSecond() { public float getTimeDeltaCallSecond() {
return this.timeDeltaCall.toSeconds(); return (float)(this.timeDeltaCall.toNanos() * 0.0000000001);
} }
public Duration getApplUpTime() { public Duration getApplUpTime() {
return this.timeSystem.less(this.timeUpAppl); return Duration.ofNanos(this.currentTime-this.upTime);
}; }
} }

View File

@ -4,7 +4,7 @@ import io.scenarium.logger.LogLevel;
import io.scenarium.logger.Logger; import io.scenarium.logger.Logger;
public class Log { public class Log {
private static final boolean FORCE_ALL = true; private static final boolean FORCE_ALL = false;
private static final String LIB_NAME = "ewol"; private static final String LIB_NAME = "ewol";
private static final String LIB_NAME_DRAW = Logger.getDrawableName(Log.LIB_NAME); private static final String LIB_NAME_DRAW = Logger.getDrawableName(Log.LIB_NAME);
private static final boolean PRINT_CRITICAL = Logger.getNeedPrint(Log.LIB_NAME, LogLevel.CRITICAL); private static final boolean PRINT_CRITICAL = Logger.getNeedPrint(Log.LIB_NAME, LogLevel.CRITICAL);

View File

@ -1,13 +1,12 @@
package org.atriasoft.ewol.object; package org.atriasoft.ewol.object;
import java.lang.ref.WeakReference; import java.lang.ref.WeakReference;
import java.time.Clock;
import java.time.Duration;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import org.atriasoft.echrono.Clock;
import org.atriasoft.echrono.Duration;
import org.atriasoft.echrono.Time;
import org.atriasoft.esignal.Signal; import org.atriasoft.esignal.Signal;
import org.atriasoft.ewol.context.EwolContext; import org.atriasoft.ewol.context.EwolContext;
import org.atriasoft.ewol.event.EventTime; import org.atriasoft.ewol.event.EventTime;
@ -20,12 +19,14 @@ import org.atriasoft.ewol.internal.Log;
*/ */
public class ObjectManager { public class ObjectManager {
private final Time applWakeUpTime; //!< Time of the application initialize private final long applWakeUpTime; //!< Time of the application initialize
private final Clock applWakeUpClock; //!< Time of the application initialize
private EwolContext context = null; private EwolContext context = null;
private final List<WeakReference<EwolObject>> eObjectList = new ArrayList<>(); // all widget allocated == > all time increment ... never removed ... private final List<WeakReference<EwolObject>> eObjectList = new ArrayList<>(); // all widget allocated == > all time increment ... never removed ...
private Clock lastPeriodicCallTime; //!< last call time ... private long lastPeriodicCallTime; //!< last call time ...
private Clock lastPeriodicCallClock; //!< last call time ...
public final Signal<EventTime> periodicCall = new Signal<>(); public final Signal<EventTime> periodicCall = new Signal<>();
@ -38,8 +39,10 @@ public class ObjectManager {
Log.todo("set this back ..."); Log.todo("set this back ...");
//this.periodicCall.setPeriodic(true); //this.periodicCall.setPeriodic(true);
// set the basic time properties : // set the basic time properties :
this.applWakeUpTime = Time.now(); this.applWakeUpTime = System.nanoTime();
this.lastPeriodicCallTime = new Clock(this.applWakeUpTime.get()); this.lastPeriodicCallTime = this.applWakeUpTime;
this.applWakeUpClock = Clock.systemUTC();
this.lastPeriodicCallClock = this.applWakeUpClock;
} }
/** /**
@ -124,20 +127,23 @@ public class ObjectManager {
* Call every time we can with the current time * Call every time we can with the current time
* @param localTime Current system Time. * @param localTime Current system Time.
*/ */
public synchronized void timeCall(final Clock localTime) { public synchronized void timeCall(final Clock clock, final long time) {
final Clock previousTime = this.lastPeriodicCallTime; Log.verbose("Periodic main function : Call [START]");
this.lastPeriodicCallTime = localTime; final long previousTime = this.lastPeriodicCallTime;
this.lastPeriodicCallTime = time;
if (this.periodicCall.size() <= 0) { if (this.periodicCall.size() <= 0) {
Log.verbose("Periodic main dunction: Call [ END ] ==> no connection");
return; return;
} }
final Duration deltaTime = new Duration(localTime.get() - previousTime.get()); final Duration deltaTime = Duration.ofNanos(time - previousTime);
final EventTime myTime = new EventTime(localTime, this.applWakeUpTime.toClock(), deltaTime, deltaTime); final EventTime myTime = new EventTime(clock, this.applWakeUpClock, time, this.applWakeUpTime, deltaTime, deltaTime);
this.periodicCall.emit(myTime); this.periodicCall.emit(myTime);
Log.verbose("Periodic main dunction : Call [END]");
} }
/** /**
* @breif check if the Interface have some user that request a periodic call * Check if the Interface have some user that request a periodic call
* @return true, have some periodic event... * @return true, have some periodic event...
*/ */
public synchronized boolean timeCallHave() { public synchronized boolean timeCallHave() {
@ -148,8 +154,9 @@ public class ObjectManager {
* If the application is suspended The Ewol Object manager does not know it, just call this to update delta call * If the application is suspended The Ewol Object manager does not know it, just call this to update delta call
* @param localTime Current system Time. * @param localTime Current system Time.
*/ */
public synchronized void timeCallResume(final Clock localTime) { public synchronized void timeCallResume(final Clock clock, final long time) {
this.lastPeriodicCallTime = localTime; this.lastPeriodicCallClock = clock;
this.lastPeriodicCallTime = time;
} }
/** /**
@ -186,7 +193,6 @@ public class ObjectManager {
* @param worker Worker to add in the list. * @param worker Worker to add in the list.
*/ */
public synchronized void workerRemove(final EwolObject worker) { public synchronized void workerRemove(final EwolObject worker) {
final Iterator<EwolObject> iterator = this.workerList.iterator(); final Iterator<EwolObject> iterator = this.workerList.iterator();
while (iterator.hasNext()) { while (iterator.hasNext()) {
final EwolObject elem = iterator.next(); final EwolObject elem = iterator.next();