/***************************************************************************
 *            timer.h
 *
 *  Wed Jun  1 21:31:59 2005
 *  Copyright  2005  Joe Venzon
 *  joe@venzon.net
 ****************************************************************************/

/*
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU Library General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 */
 
#ifndef _TIMER_H

#ifdef __APPLE__ 
#include "definitions_mac.h" 
#else 
#include "definitions.h" 
#endif 

 
#include <stdio.h>			// Header File For Standard Input/Output
#include <GL/gl.h>
#include <GL/glu.h>
#include <SDL/SDL.h>
#ifdef __APPLE__
#include <SDL_image/SDL_image.h>
#else
#include <SDL/SDL_image.h>
#endif
#include <string>
#include <iostream>
#include <fstream>
#include <cmath>
#include <cassert>
#include <sstream>

using namespace std;

#include "font.h"
#include "utility.h"
#include "gamestate.h"
#include "settings.h"
#include "globals.h"
#include "configfile.h"

#define STAGING_TIME 4.0

class TIMER
{
private:
	void SecsToSecsMin(const double t, float & secs, int & min) const;
	void SaveRecords();
	void LoadCurrentTrackIfNotLoaded();

	TEXTURE_HANDLE timerbox;
	bool loaded;
	vector<double> time;
	vector<double> lastlap; //last lap time for opponents
	vector<double> bestlap; //best lap time for opponents
	vector<double> totaltime; //total time of a race for opponents
	vector<int> num_laps; // total number of laps for opponents
	double pretime;

	map <string, CONFIGFILE> trackrecords;

public:
	TIMER();
	~TIMER();
	
	void Load();
	void Clear();
	void Lap(const string & track, const string & carname, const int carid, const int prevsector, const int nextsector, const bool countit);
	void TickTimer(const float timefactor, const float fps);
	void Draw();
	void InitOpponentTimer(int number_of_opponent);
	double GetTotalTime(int i) { return totaltime[i]; }
	double GetBestLap(int i) { return bestlap[i]; }
	int GetNumLaps(int i) { return num_laps[i]; }

	//float GetTimer() {return time;}
	//void ResetBest();
	//void ResetLast();
	//void Reset();
};

#define _TIMER_H
#endif /* _TIMER_H */
