Add project files.

This commit is contained in:
2018-06-25 21:48:45 -04:00
parent b04a25689b
commit 3c1b7d28e8
425 changed files with 35333 additions and 0 deletions
@@ -0,0 +1,144 @@
#include "cTiming.hpp"
/*** Custom Header Files ***/
#include "../UtilityEngine/cUtility.hpp"
using TimingEngine::cTiming;
using UtilityEngine::cUtility;
/*static*/ cTiming* cTiming::sp_inst = nullptr;
cTiming::cTiming( const unsigned long int ftp /*= 30*/ )
: m_ftp(ftp), m_rate(1000 / ftp), m_nextTime(0), m_start(SDL_GetTicks()), m_lastTime(0.0f), m_frameTime(0.0f)
{
Setup();
}
cTiming::~cTiming()
{
CleanUp();
}
cTiming& cTiming::operator=( const cTiming& copy )
{
if (this != &copy)
setFTP(copy.getFTP());
return *this;
}
///Functions
/*static*/ cTiming& cTiming::Inst()
{
if (sp_inst == nullptr)
sp_inst = new cTiming();
return *sp_inst;
}
/*static*/ void cTiming::Delete()
{
delete sp_inst;
sp_inst = nullptr;
}
const bool cTiming::Initialize() const
{
bool rtn = IsInit();
if (rtn == false) {
if( SDL_Init( SDL_INIT_TIMER ) == 0 ) {
cUtility::Inst().Message("Timer Initialized.");
rtn = true;
} else
cUtility::Inst().Message("Could not initialize timer. SDL_Init(SDL_INIT_TIMER):", __AT__, cUtility::eTypeSDL::SDL);
}
return rtn;
}
void cTiming::Setup()
{
m_nextTime = SDL_GetTicks();
AddTimeandRate();
}
void cTiming::CleanUp()
{}
void cTiming::Time()
{
SDL_Delay(TimeLeft());
AddTimeandRate();
m_frameTime = FrameTime();
//m_start = SDL_GetTicks();
}
const float/*unsigned long int*/ cTiming::FrameTime()
{
/*unsigned long int rtn = 0;
unsigned long int end = SDL_GetTicks();
rtn = end - m_start;
m_start = end;
return rtn;*/
/* for keeping track of timing */
unsigned long int thisTime = SDL_GetTicks();
m_lastTime = (float)thisTime - 30;
thisTime = SDL_GetTicks();
return (float)(thisTime - m_lastTime) / m_ftp;
}
///Sets
void cTiming::setFTP( const unsigned long int ftp /*= 30*/ )
{
m_ftp = ftp;
m_rate = 1000 / m_ftp;
Setup();
}
///Gets
const unsigned long int cTiming::getFTP() const
{
return m_ftp;
}
const bool cTiming::IsInit() const
{
bool rtn = false;
if (SDL_WasInit(SDL_INIT_TIMER) != 0) {
cUtility::Inst().Message("Timer is initialized");
rtn = true;
} else
cUtility::Inst().Message("Timer is not initialized.");
return rtn;
}
const float cTiming::getFrameTime() const
{
return m_frameTime;
}
///Private
///Functions
const unsigned long int cTiming::TimeLeft()
{
unsigned long int now = SDL_GetTicks();
if(m_nextTime <= now)
return 0;
else
return m_nextTime - now;
}
void cTiming::AddTimeandRate()
{
m_nextTime += m_rate;
}
@@ -0,0 +1,68 @@
#ifndef _CTIMING_HPP_
#define _CTIMING_HPP_
/*** SDL Header Files ***/
#include <SDL.h>
/*** DLL Header File ***/
#include <dllExport.h>
#define MAXIMUM_FRAME_RATE 120
#define MINIMUM_FRAME_RATE 15
#define UPDATE_INTERVAL (1.0 / MAXIMUM_FRAME_RATE)
#define MAX_CYCLES_PER_FRAME (MAXIMUM_FRAME_RATE / MINIMUM_FRAME_RATE)
namespace TimingEngine {
/* Singleton */
class EXPORT_FROM_MYDLL cTiming
{
private:
cTiming( const unsigned long int ftp = 30 );
~cTiming();
public:
cTiming& operator=( const cTiming& copy );
///Functions
static cTiming& Inst();
static void Delete();
const bool Initialize() const;
/* Sets up timing */
void Setup();
void CleanUp();
/* Sleeps if need */
void Time();
///Sets
void setFTP( const unsigned long int ftp = 30 );
///Gets
const unsigned long int getFTP() const;
/* Gets return true if Timer was initialized */
const bool IsInit() const;
const float getFrameTime() const;
private:
const unsigned long int TimeLeft();
void AddTimeandRate();
const float FrameTime();
private:
///Variables
unsigned long int m_nextTime;// = 0
unsigned long int m_rate;// = (1000 / m_ftp)
unsigned long int m_ftp;// = 30
static cTiming* sp_inst;// = nullptr
unsigned long int m_start;// = 0
float m_lastTime;// = 0.0
float m_frameTime;// = 0.0
};/// END CLASS DEFINITION cTiming
}/// END NAMESPACE DEFINITION TimingEngine
#endif/// END IFNDEF _CTIMING_HPP_