#ifndef DELTA_HANDLER_HPP
#define DELTA_HANDLER_HPP

#include <chrono>

// A minimalistic class that handles delta time and elapsed time using std::chrono.
// This can be used for most situations that need to capture the elapsed
// time between two events but is intended for frames in a game loop.
// All variables are initialized to the current point in time upon construction.
class DeltaHandler{
public:

    // Default initializes all variables to the current point in time.
    DeltaHandler();

    // Sets all the variables to the current point in time.
	void restart();

    // Update the delta. This should be called once per frame or event update.
	void updateDelta();

    // Returns the time between the two most recent calls to updateDelta.
    // If updateDelta has not been called since the last restart, this will return 0.
	double getDelta() const;

    // Returns the time between the most recent call to updateDelta and the most
    // recent call to restart. If updateDelta has not been called since the last
    // restart, this will return 0.
	double getTimeSinceRestart() const;

private:
    std::chrono::steady_clock::time_point start;
	std::chrono::steady_clock::time_point currentTime;
	std::chrono::steady_clock::time_point previousTime;
};

#endif // DELTA_HANDLER_HPP