From cfc2082d02fbf5818385db218744d6e97236063b Mon Sep 17 00:00:00 2001 From: Edouard DUPIN Date: Mon, 31 May 2021 21:58:53 +0200 Subject: [PATCH] [DEV] update to java clock model --- .../atriasoft/ewol/context/EwolContext.java | 11 +++--- .../atriasoft/ewol/context/InputManager.java | 20 +++++----- src/org/atriasoft/ewol/event/EventTime.java | 20 +++++----- src/org/atriasoft/ewol/internal/Log.java | 2 +- .../atriasoft/ewol/object/ObjectManager.java | 38 +++++++++++-------- 5 files changed, 50 insertions(+), 41 deletions(-) diff --git a/src/org/atriasoft/ewol/context/EwolContext.java b/src/org/atriasoft/ewol/context/EwolContext.java index a85e737..c4b637a 100644 --- a/src/org/atriasoft/ewol/context/EwolContext.java +++ b/src/org/atriasoft/ewol/context/EwolContext.java @@ -5,7 +5,8 @@ */ package org.atriasoft.ewol.context; -import org.atriasoft.echrono.Clock; +import java.time.Clock; + import org.atriasoft.etk.Uri; import org.atriasoft.etk.math.Vector2f; 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.WidgetManager; import org.atriasoft.ewol.widget.Windows; -import org.atriasoft.gale.GaleApplication; import org.atriasoft.gale.Gale; +import org.atriasoft.gale.GaleApplication; import org.atriasoft.gale.context.ClipboardList; import org.atriasoft.gale.context.CommandLine; import org.atriasoft.gale.context.GaleContext; @@ -290,9 +291,9 @@ public class EwolContext extends GaleApplication { appl.onPause(this); Log.info(" == > Ewol system pause (END)"); } - - public void onPeriod(final Clock time) { - this.objectManager.timeCall(time); + @Override + public void onPeriod(final Clock clock, final long time) { + this.objectManager.timeCall(clock, time); } @Override diff --git a/src/org/atriasoft/ewol/context/InputManager.java b/src/org/atriasoft/ewol/context/InputManager.java index a5179cc..e107333 100644 --- a/src/org/atriasoft/ewol/context/InputManager.java +++ b/src/org/atriasoft/ewol/context/InputManager.java @@ -7,8 +7,6 @@ package org.atriasoft.ewol.context; 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.Vector2f; import org.atriasoft.ewol.event.InputSystem; @@ -24,12 +22,13 @@ import org.atriasoft.gale.key.KeyType; */ class InputLimit { public int dpiOffset; - public Duration sepatateTime; + public long sepatateTime; // in nanosecond System.nanoTime() } 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 final EwolContext context; private int dpi; private final InputLimit eventInputLimit = new InputLimit(); @@ -43,6 +42,7 @@ class InputManager { public InputManager(final EwolContext context) { this.context = context; + setDpi(200); Log.info("Init (start)"); for (int iii = 0; iii < InputManager.MAX_MANAGE_INPUT; iii++) { @@ -64,9 +64,9 @@ class InputManager { } private void calculateLimit() { - this.eventInputLimit.sepatateTime = Duration.milliseconds(300); + this.eventInputLimit.sepatateTime = 300 * InputManager.MILLI_TO_DURATION; 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); } @@ -272,14 +272,14 @@ class InputManager { return; } // get the curent time ... - final Clock currentTime = Clock.now(); + final long currentTime = System.nanoTime(); final Windows tmpWindows = this.context.getWindows(); if (isDown) { //Log.debug("GUI : Input ID=" + pointerID + " == >" + eventTable[pointerID].destinationInputId + " [DOWN] " + pos); if (eventTable[pointerID].isUsed) { // 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); } 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); @@ -447,7 +447,7 @@ class InputPoperty { public boolean isDown = false; public boolean isInside = false; public boolean isUsed = false; - public Clock lastTimeEvent = null; + public long lastTimeEvent = 0; // in ns public int nbClickEvent = 0; // 0 .. 1 .. 2 .. 3 public Vector2f origin = Vector2f.ZERO; public Vector2f posEvent = Vector2f.ZERO; @@ -456,7 +456,7 @@ class InputPoperty { public void clear() { this.isUsed = false; this.destinationInputId = 0; - this.lastTimeEvent = new Clock(); + this.lastTimeEvent = System.nanoTime(); this.curentWidgetEvent = null; this.origin = Vector2f.ZERO; this.size = Vector2f.MAX_VALUE; diff --git a/src/org/atriasoft/ewol/event/EventTime.java b/src/org/atriasoft/ewol/event/EventTime.java index f5495f7..54b1e5e 100644 --- a/src/org/atriasoft/ewol/event/EventTime.java +++ b/src/org/atriasoft/ewol/event/EventTime.java @@ -1,7 +1,7 @@ package org.atriasoft.ewol.event; -import org.atriasoft.echrono.Clock; -import org.atriasoft.echrono.Duration; +import java.time.Clock; +import java.time.Duration; /** @file * @author Edouard DUPIN @@ -9,17 +9,19 @@ import org.atriasoft.echrono.Duration; * @license MPL v2.0 (see license file) */ public record EventTime( - Clock timeSystem, //!< Current system time (micro-second) - Clock timeUpAppl, //!< Current application wake up-time (micro-second) - Duration timeDelta, //!< Time from the last cycle call of the system (main appl tick) (second) - Duration timeDeltaCall //!< Time from the last call (when we can manage periodic call with specifying periode) (second) + Clock currentClock, //!< Current system time "Clock.systemUTC()" + Clock upClock, //!< Current application wake up-time "Clock.systemUTC() @ start" + long currentTime, //!< Current system time "System.nanoTime()" + 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() { - return this.timeDeltaCall.toSeconds(); + return (float)(this.timeDeltaCall.toNanos() * 0.0000000001); } public Duration getApplUpTime() { - return this.timeSystem.less(this.timeUpAppl); - }; + return Duration.ofNanos(this.currentTime-this.upTime); + } } diff --git a/src/org/atriasoft/ewol/internal/Log.java b/src/org/atriasoft/ewol/internal/Log.java index 1157977..86b76e8 100644 --- a/src/org/atriasoft/ewol/internal/Log.java +++ b/src/org/atriasoft/ewol/internal/Log.java @@ -4,7 +4,7 @@ import io.scenarium.logger.LogLevel; import io.scenarium.logger.Logger; 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_DRAW = Logger.getDrawableName(Log.LIB_NAME); private static final boolean PRINT_CRITICAL = Logger.getNeedPrint(Log.LIB_NAME, LogLevel.CRITICAL); diff --git a/src/org/atriasoft/ewol/object/ObjectManager.java b/src/org/atriasoft/ewol/object/ObjectManager.java index a29c71c..87e5401 100644 --- a/src/org/atriasoft/ewol/object/ObjectManager.java +++ b/src/org/atriasoft/ewol/object/ObjectManager.java @@ -1,13 +1,12 @@ package org.atriasoft.ewol.object; import java.lang.ref.WeakReference; +import java.time.Clock; +import java.time.Duration; import java.util.ArrayList; import java.util.Iterator; 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.ewol.context.EwolContext; import org.atriasoft.ewol.event.EventTime; @@ -20,12 +19,14 @@ import org.atriasoft.ewol.internal.Log; */ 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 final List> 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 periodicCall = new Signal<>(); @@ -38,8 +39,10 @@ public class ObjectManager { Log.todo("set this back ..."); //this.periodicCall.setPeriodic(true); // set the basic time properties : - this.applWakeUpTime = Time.now(); - this.lastPeriodicCallTime = new Clock(this.applWakeUpTime.get()); + this.applWakeUpTime = System.nanoTime(); + 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 * @param localTime Current system Time. */ - public synchronized void timeCall(final Clock localTime) { - final Clock previousTime = this.lastPeriodicCallTime; - this.lastPeriodicCallTime = localTime; + public synchronized void timeCall(final Clock clock, final long time) { + Log.verbose("Periodic main function : Call [START]"); + final long previousTime = this.lastPeriodicCallTime; + this.lastPeriodicCallTime = time; if (this.periodicCall.size() <= 0) { + Log.verbose("Periodic main dunction: Call [ END ] ==> no connection"); 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); + 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... */ 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 * @param localTime Current system Time. */ - public synchronized void timeCallResume(final Clock localTime) { - this.lastPeriodicCallTime = localTime; + public synchronized void timeCallResume(final Clock clock, final long time) { + this.lastPeriodicCallClock = clock; + this.lastPeriodicCallTime = time; } /** @@ -186,7 +193,6 @@ public class ObjectManager { * @param worker Worker to add in the list. */ public synchronized void workerRemove(final EwolObject worker) { - final Iterator iterator = this.workerList.iterator(); while (iterator.hasNext()) { final EwolObject elem = iterator.next();