// __author__ = Juan Carlos De Abreu (jcabreur@gmail.com)

/**
 * TODO(jcabreur): write a general comment here
 */

// TODO: hacer los cambios necesarios para que la aplicacion corra
//       a la misma velocidad sin importar la maquina donde se ejecute

#ifndef UTIL_TIME_MANAGEMENT_H__
#define UTIL_TIME_MANAGEMENT_H__

#include "../../Includes/Basic.h"
#include "../../Base/Singleton.h"
#include "../../Base/Memory/Smartpointer.h"
#include "Time.h"

//#include "../../Scene Parser/Data.h"
#include "../../Scene Parser/DataStructures/DataTime.h"

BEGIN_TEG_NAMESPACE();

/*
// 
#define UPDATE_TIMERS() TimeManagement::GetInstance().update()
#define ADD_TIMER(t) TimeManagement::GetInstance().addTimer(t)

// 
class TimeManagement : public Singleton<TimeManagement> {
public:
	// Attibutes
	std::vector<Time> timers;
	//clock_t last;

	clock_t last;
	clock_t current;


	// Constructor
	TimeManagement();

	// Destructor
	~TimeManagement();

	// Methods
	inline void addTimer(const Time& t) { timers.push_back(t); }	// Method to add a timer
	void update();
};
*/

#define UPDATE_TIMERS() TimeManagement::GetInstance().update()
#define ADD_TIMER(t) TimeManagement::GetInstance().addTimer(t)

//class DATA;
/*
class DataTime : public DATA {
public:
	// TODO: tener un tiempo inicial para estadisticas
	// Attributes
	clock_t last;
	clock_t end;
	bool isRunning;			// is the clock running
	long interval;			// interval to do a task

	// Attributes
	SmartPointer<DataCallFunction> funcInterval;
	SmartPointer<DataCallFunction> funcEnd;

	// 
	DataTime(const std::vector<SmartPointer<DATA> >& params);
	~DataTime();

	// Methods
	AUTO_SIZE();
	void print() { }
	SmartPointer<DATA> resolve(std::map<std::string, SmartPointer<DATA>>& variables) { return NULL; }
};
*/
// 
class TimeManagement : public Singleton<TimeManagement> {
private:
  // Attibutes
  clock_t lastCallGarbageCollector;                  // Time of the last call to teh garbageCollector.
  static const long garbageCollectorInterval = 5000; // To call the garbageCollector each 5 secs.

public:
	std::vector<SmartPointer<DataTime> > timers;
	//clock_t last;

	clock_t last;
	clock_t current;


	// Constructor
	TimeManagement();

	// Destructor
	~TimeManagement();

	// Methods
	inline void addTimer(const SmartPointer<DataTime>& t) { timers.push_back(t); }	// Method to add a timer
	void update();
	
	void stopAllTimers(void);
	void pauseAllTimers(void);
	void startAllTimers(void);

	void release();
};

END_TEG_NAMESPACE();

#endif  // UTIL_TIME_MANAGEMENT_H__
