/*
Solar Conquest
Copyright (C) 2006 Greg Beaman

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 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., 675 Mass Ave, Cambridge, MA 02139, USA.
*/

#define PROFILER_OBJ_UPDATES 0 //6ms so far
#define PROFILER_OBJ_UPDATE 1
#define PROFILER_OBJ_RENDERS 2
#define PROFILER_OBJ_RENDER 3
//not used, projectiles update during render
//#define PROFILER_PROJ_UPDATES 4
//#define PROFILER_PROJ_UPDATE 5
#define PROFILER_PROJ_RENDERS 6 //1ms so far
#define PROFILER_PROJ_RENDER 7
#define PROFILER_FACTORY_UPDATES 8 //1ms so far
#define PROFILER_FACTORY_UPDATE 9
#define PROFILER_FACTORY_RENDERS 10
#define PROFILER_FACTORY_RENDER 11
#define PROFILER_AIMIND_UPDATES 12
#define PROFILER_AIMIND_UPDATE 13
#define PROFILER_PARTICLE_UPDATES 14

#define PROFILER_COUNT 15

class CProfiler
{
private:
	LARGE_INTEGER timerStart[PROFILER_COUNT];
	LARGE_INTEGER timeSpent[PROFILER_COUNT];

public:
	CProfiler();
	~CProfiler();

	void ResetProfiler();
	void StartTimer(int profile);
	void StopTimer(int profile);

	bool ValidProfile(int profile);
};

CProfiler::CProfiler()
{
	ResetProfiler();
}

CProfiler::~CProfiler()
{
}

void CProfiler::ResetProfiler()
{
	for (int i=0; i < PROFILER_COUNT; i++)
	{
		timerStart[i].QuadPart = 0;
		timeSpent[i].QuadPart = 0;
	}
}

void CProfiler::StartTimer(int profile)
{
	if (!ValidProfile(profile))
		return;
	if (!QueryPerformanceCounter(&timerStart[profile]))
		return;
	else
	{
		int i = 0;
	}
}

void CProfiler::StopTimer(int profile)
{
	if (!ValidProfile(profile))
		return;
	LARGE_INTEGER ctime;
	QueryPerformanceCounter(&ctime);
	timeSpent[profile].QuadPart = ctime.QuadPart-timerStart[profile].QuadPart;
}

bool CProfiler::ValidProfile(int profile)
{
	if (profile < 0 || profile >= PROFILER_COUNT)
		return false;
	return true;
}