package com.lhkbob.entreri.task;

import com.lhkbob.entreri.EntitySystem;

public final class Timers {

    public static Task fixedDelta(double dt) {
        return new FixedDeltaTask(dt);
    }

    public static Task measuredDelta() {
        return new MeasuredDeltaTask();
    }

    private static class FixedDeltaTask implements Task {
        private final ElapsedTimeResult delta;

        public FixedDeltaTask(double dt) {
            delta = new ElapsedTimeResult(dt);
        }

        @Override
        public Task process(EntitySystem system, Job job) {
            job.report(delta);
            return null;
        }

        @Override
        public void reset(EntitySystem system) {
            // do nothing
        }
    }

    private static class MeasuredDeltaTask implements Task {
        private long lastStart = -1L;

        @Override
        public Task process(EntitySystem system, Job job) {
            long now = System.nanoTime();
            if (lastStart <= 0) {
                job.report(new ElapsedTimeResult(0));
            } else {
                job.report(new ElapsedTimeResult((now - lastStart) / 1e9));
            }
            lastStart = now;

            return null;
        }

        @Override
        public void reset(EntitySystem system) {
            // do nothing
        }
    }
}

@@ -27,16 +27,110 @@
 .task;%0A%0A
+import java.util.Collections;%0Aimport java.util.Set;%0A%0Aimport com.lhkbob.entreri.ComponentData;%0A
 import c
@@ -419,32 +419,47 @@
  implements Task
+, ParallelAware
  %7B%0A        priva
@@ -837,24 +837,278 @@
 ng%0A        %7D
+%0A%0A        @Override%0A        public Set%3CClass%3C? extends ComponentData%3C?%3E%3E%3E getAccessedComponents() %7B%0A            return Collections.emptySet();%0A        %7D%0A%0A        @Override%0A        public boolean isEntitySetModified() %7B%0A            return false;%0A        %7D
 %0A    %7D%0A%0A    
@@ -1161,16 +1161,31 @@
 nts Task
+, ParallelAware
  %7B%0A     
@@ -1701,21 +1701,275 @@
 ng%0A        %7D
+%0A%0A        @Override%0A        public Set%3CClass%3C? extends ComponentData%3C?%3E%3E%3E getAccessedComponents() %7B%0A            return Collections.emptySet();%0A        %7D%0A%0A        @Override%0A        public boolean isEntitySetModified() %7B%0A            return false;%0A        %7D
 %0A    %7D%0A%7D%0A

Make the timing tasks parallel aware.