Cleanup / Reformat

This commit is contained in:
Charles J. Cliffe 2014-11-22 22:33:32 -05:00
parent 58708a720e
commit 39ba38b82a
10 changed files with 353 additions and 395 deletions

View File

@ -61,9 +61,9 @@ AppFrame::AppFrame() :
audioInputQueue = new AudioThreadInputQueue; audioInputQueue = new AudioThreadInputQueue;
audioThread = new AudioThread(audioInputQueue); audioThread = new AudioThread(audioInputQueue);
t1 = new std::thread(&AudioThread::threadMain, audioThread); threadAudio = new std::thread(&AudioThread::threadMain, audioThread);
demodulatorTest = demodMgr.newThread(this); demodulatorTest = demodMgr.newThread();
demodulatorTest->params.audioInputQueue = audioInputQueue; demodulatorTest->params.audioInputQueue = audioInputQueue;
demodulatorTest->init(); demodulatorTest->init();
@ -77,7 +77,7 @@ AppFrame::AppFrame() :
iqVisualQueue = new SDRThreadIQDataQueue; iqVisualQueue = new SDRThreadIQDataQueue;
sdrThread->setIQVisualQueue(iqVisualQueue); sdrThread->setIQVisualQueue(iqVisualQueue);
t_SDR = new std::thread(&SDRThread::threadMain, sdrThread); threadSDR = new std::thread(&SDRThread::threadMain, sdrThread);
// static const int attribs[] = { WX_GL_RGBA, WX_GL_DOUBLEBUFFER, 0 }; // static const int attribs[] = { WX_GL_RGBA, WX_GL_DOUBLEBUFFER, 0 };
// wxLogStatus("Double-buffered display %s supported", wxGLCanvas::IsDisplaySupported(attribs) ? "is" : "not"); // wxLogStatus("Double-buffered display %s supported", wxGLCanvas::IsDisplaySupported(attribs) ? "is" : "not");

View File

@ -16,10 +16,9 @@ class AppFrame: public wxFrame {
public: public:
AppFrame(); AppFrame();
~AppFrame(); ~AppFrame();
void OnThread (wxCommandEvent& event); void OnThread(wxCommandEvent& event);
void OnEventInput(wxThreadEvent& event); void OnEventInput(wxThreadEvent& event);
void setFrequency(unsigned int freq); void setFrequency(unsigned int freq);
int getFrequency(); int getFrequency();
@ -47,8 +46,8 @@ private:
SDRThreadIQDataQueue* iqVisualQueue; SDRThreadIQDataQueue* iqVisualQueue;
DemodulatorThreadOutputQueue* audioVisualQueue; DemodulatorThreadOutputQueue* audioVisualQueue;
std::thread *t1; std::thread *threadAudio;
std::thread *t_SDR; std::thread *threadSDR;
// event table // event table
wxDECLARE_EVENT_TABLE(); wxDECLARE_EVENT_TABLE();

View File

@ -44,6 +44,20 @@ static int audioCallback(const void *inputBuffer, void *outputBuffer, unsigned l
return paContinue; return paContinue;
} }
AudioThread::AudioThread(AudioThreadInputQueue *inputQueue) :
inputQueue(inputQueue), stream(NULL), audio_queue_ptr(0) {
}
AudioThread::~AudioThread() {
PaError err;
err = Pa_StopStream(stream);
err = Pa_CloseStream(stream);
Pa_Terminate();
std::cout << std::endl << "Audio Thread Done." << std::endl << std::endl;
}
void AudioThread::threadMain() { void AudioThread::threadMain() {
PaError err; PaError err;
err = Pa_Initialize(); err = Pa_Initialize();
@ -67,7 +81,7 @@ void AudioThread::threadMain() {
stream = NULL; stream = NULL;
err = Pa_OpenStream(&stream, NULL, &outputParameters, AUDIO_FREQUENCY, paFramesPerBufferUnspecified, err = Pa_OpenStream(&stream, NULL, &outputParameters, AUDIO_FREQUENCY, paFramesPerBufferUnspecified,
paPrimeOutputBuffersUsingStreamCallback | paClipOff, &audioCallback, this); paPrimeOutputBuffersUsingStreamCallback | paClipOff, &audioCallback, this);
err = Pa_StartStream(stream); err = Pa_StartStream(stream);
if (err != paNoError) { if (err != paNoError) {

View File

@ -33,19 +33,9 @@ public:
std::queue<std::vector<float> > audio_queue; std::queue<std::vector<float> > audio_queue;
unsigned int audio_queue_ptr; unsigned int audio_queue_ptr;
AudioThread(AudioThreadInputQueue *inputQueue) : AudioThread(AudioThreadInputQueue *inputQueue);
inputQueue(inputQueue), stream(NULL), audio_queue_ptr(0) {
} ~AudioThread();
~AudioThread() {
PaError err;
err = Pa_StopStream(stream);
err = Pa_CloseStream(stream);
Pa_Terminate();
std::cout << std::endl << "Audio Thread Done." << std::endl << std::endl;
}
void threadMain(); void threadMain();

View File

@ -0,0 +1,40 @@
#include <DemodulatorMgr.h>
DemodulatorInstance::DemodulatorInstance() :
t_Demod(NULL), threadQueueDemod(NULL), demodulatorThread(NULL) {
}
void DemodulatorInstance::setVisualOutputQueue(DemodulatorThreadOutputQueue *tQueue) {
demodulatorThread->setVisualOutputQueue(tQueue);
}
void DemodulatorInstance::init() {
if (threadQueueDemod) {
delete threadQueueDemod;
}
if (demodulatorThread) {
delete demodulatorThread;
}
threadQueueDemod = new DemodulatorThreadInputQueue;
demodulatorThread = new DemodulatorThread(threadQueueDemod, &params);
t_Demod = new std::thread(&DemodulatorThread::threadMain, demodulatorThread);
}
DemodulatorMgr::DemodulatorMgr() {
}
DemodulatorMgr::~DemodulatorMgr() {
while (demods.size()) {
DemodulatorInstance *d = demods.back();
demods.pop_back();
delete d;
}
}
DemodulatorInstance *DemodulatorMgr::newThread() {
DemodulatorInstance *newDemod = new DemodulatorInstance;
demods.push_back(newDemod);
return newDemod;
}

View File

@ -13,48 +13,18 @@ public:
DemodulatorThreadInputQueue* threadQueueDemod; DemodulatorThreadInputQueue* threadQueueDemod;
DemodulatorThreadParameters params; DemodulatorThreadParameters params;
DemodulatorInstance() : DemodulatorInstance();
t_Demod(NULL), threadQueueDemod(NULL), demodulatorThread(NULL) { void setVisualOutputQueue(DemodulatorThreadOutputQueue *tQueue);
} void init();
void setVisualOutputQueue(DemodulatorThreadOutputQueue *tQueue) {
demodulatorThread->setVisualOutputQueue(tQueue);
}
void init() {
if (threadQueueDemod) {
delete threadQueueDemod;
}
if (demodulatorThread) {
delete demodulatorThread;
}
threadQueueDemod = new DemodulatorThreadInputQueue;
demodulatorThread = new DemodulatorThread(threadQueueDemod, &params);
t_Demod = new std::thread(&DemodulatorThread::threadMain, demodulatorThread);
}
}; };
class DemodulatorMgr { class DemodulatorMgr {
public: public:
DemodulatorMgr() { DemodulatorMgr();
~DemodulatorMgr();
} DemodulatorInstance *newThread();
~DemodulatorMgr() {
while (demods.size()) {
DemodulatorInstance *d = demods.back();
demods.pop_back();
delete d;
}
}
DemodulatorInstance *newThread(wxEvtHandler* pParent) {
DemodulatorInstance *newDemod = new DemodulatorInstance;
demods.push_back(newDemod);
return newDemod;
}
private:
std::vector<DemodulatorInstance *> demods; std::vector<DemodulatorInstance *> demods;
}; };

View File

@ -3,7 +3,7 @@
#include <vector> #include <vector>
DemodulatorThread::DemodulatorThread(DemodulatorThreadInputQueue* pQueue, DemodulatorThreadParameters *params_in) : DemodulatorThread::DemodulatorThread(DemodulatorThreadInputQueue* pQueue, DemodulatorThreadParameters *params_in) :
m_pQueue(pQueue), visOutQueue(NULL) { inputQueue(pQueue), visOutQueue(NULL) {
DemodulatorThreadParameters defaultParams; DemodulatorThreadParameters defaultParams;
if (!params_in) { if (!params_in) {
@ -57,7 +57,7 @@ void DemodulatorThread::threadMain() {
while (1) { while (1) {
DemodulatorThreadIQData inp; DemodulatorThreadIQData inp;
m_pQueue->pop(inp); inputQueue->pop(inp);
std::vector<signed char> *data = &inp.data; std::vector<signed char> *data = &inp.data;
if (data->size()) { if (data->size()) {
@ -139,22 +139,6 @@ void DemodulatorThread::threadMain() {
if (visOutQueue != NULL) { if (visOutQueue != NULL) {
visOutQueue->push(ati); visOutQueue->push(ati);
} }
/*if (!TestDestroy()) {
DemodulatorThreadAudioData *audioOut = new DemodulatorThreadAudioData(task.data->frequency, params.audioSampleRate, newBuffer);
m_pQueue->sendAudioData(DemodulatorThreadTask::DEMOD_THREAD_AUDIO_DATA, audioOut);
if (params.audioInputQueue != NULL) {
AudioThreadInput ati;
ati.data = newBuffer;
params.audioInputQueue->push(ati);
// AudioThreadTask audio_task = AudioThreadTask(AudioThreadTask::AUDIO_THREAD_DATA);
// audio_task.data = new AudioThreadData(task.data->frequency, params.audioSampleRate, newBuffer);
// params.audioQueue->addTask(audio_task, AudioThreadQueue::AUDIO_PRIORITY_HIGHEST);
}
}*/
} }
} }
} }

View File

@ -102,7 +102,7 @@ public:
} }
protected: protected:
DemodulatorThreadInputQueue* m_pQueue; DemodulatorThreadInputQueue* inputQueue;
DemodulatorThreadOutputQueue* visOutQueue; DemodulatorThreadOutputQueue* visOutQueue;
firfilt_crcf fir_filter; firfilt_crcf fir_filter;

View File

@ -15,43 +15,37 @@
#include <cstdint> #include <cstdint>
#include <condition_variable> #include <condition_variable>
/** A thread-safe asynchronous queue */ /** A thread-safe asynchronous queue */
template <class T, class Container = std::list<T>> template<class T, class Container = std::list<T>>
class ThreadQueue class ThreadQueue {
{
typedef typename Container::value_type value_type; typedef typename Container::value_type value_type;
typedef typename Container::size_type size_type; typedef typename Container::size_type size_type;
typedef Container container_type; typedef Container container_type;
public: public:
/*! Create safe queue. */ /*! Create safe queue. */
ThreadQueue() = default; ThreadQueue() = default;
ThreadQueue (ThreadQueue&& sq) ThreadQueue(ThreadQueue&& sq) {
{ m_queue = std::move(sq.m_queue);
m_queue = std::move (sq.m_queue);
} }
ThreadQueue (const ThreadQueue& sq) ThreadQueue(const ThreadQueue& sq) {
{ std::lock_guard < std::mutex > lock(sq.m_mutex);
std::lock_guard<std::mutex> lock (sq.m_mutex); m_queue = sq.m_queue;
m_queue = sq.m_queue;
} }
/*! Destroy safe queue. */ /*! Destroy safe queue. */
~ThreadQueue() ~ThreadQueue() {
{ std::lock_guard < std::mutex > lock(m_mutex);
std::lock_guard<std::mutex> lock (m_mutex);
} }
/** /**
* Sets the maximum number of items in the queue. Defaults is 0: No limit * Sets the maximum number of items in the queue. Defaults is 0: No limit
* \param[in] item An item. * \param[in] item An item.
*/ */
void set_max_num_items (unsigned int max_num_items) void set_max_num_items(unsigned int max_num_items) {
{ m_max_num_items = max_num_items;
m_max_num_items = max_num_items;
} }
/** /**
@ -59,16 +53,15 @@ class ThreadQueue
* \param[in] item An item. * \param[in] item An item.
* \return true if an item was pushed into the queue * \return true if an item was pushed into the queue
*/ */
bool push (const value_type& item) bool push(const value_type& item) {
{ std::lock_guard < std::mutex > lock(m_mutex);
std::lock_guard<std::mutex> lock (m_mutex);
if (m_max_num_items > 0 && m_queue.size() > m_max_num_items) if (m_max_num_items > 0 && m_queue.size() > m_max_num_items)
return false; return false;
m_queue.push (item); m_queue.push(item);
m_condition.notify_one(); m_condition.notify_one();
return true; return true;
} }
/** /**
@ -76,31 +69,29 @@ class ThreadQueue
* \param[in] item An item. * \param[in] item An item.
* \return true if an item was pushed into the queue * \return true if an item was pushed into the queue
*/ */
bool push (const value_type&& item) bool push(const value_type&& item) {
{ std::lock_guard < std::mutex > lock(m_mutex);
std::lock_guard<std::mutex> lock (m_mutex);
if (m_max_num_items > 0 && m_queue.size() > m_max_num_items) if (m_max_num_items > 0 && m_queue.size() > m_max_num_items)
return false; return false;
m_queue.push (item); m_queue.push(item);
m_condition.notify_one(); m_condition.notify_one();
return true; return true;
} }
/** /**
* Pops item from the queue. If queue is empty, this function blocks until item becomes available. * Pops item from the queue. If queue is empty, this function blocks until item becomes available.
* \param[out] item The item. * \param[out] item The item.
*/ */
void pop (value_type& item) void pop(value_type& item) {
{ std::unique_lock < std::mutex > lock(m_mutex);
std::unique_lock<std::mutex> lock (m_mutex); m_condition.wait(lock, [this]() // Lambda funct
m_condition.wait (lock, [this]() // Lambda funct {
{ return !m_queue.empty();
return !m_queue.empty(); });
}); item = m_queue.front();
item = m_queue.front(); m_queue.pop();
m_queue.pop();
} }
/** /**
@ -109,15 +100,14 @@ class ThreadQueue
* If queue is empty, this function blocks until item becomes available. * If queue is empty, this function blocks until item becomes available.
* \param[out] item The item. * \param[out] item The item.
*/ */
void move_pop (value_type& item) void move_pop(value_type& item) {
{ std::unique_lock < std::mutex > lock(m_mutex);
std::unique_lock<std::mutex> lock (m_mutex); m_condition.wait(lock, [this]() // Lambda funct
m_condition.wait (lock, [this]() // Lambda funct {
{ return !m_queue.empty();
return !m_queue.empty(); });
}); item = std::move(m_queue.front());
item = std::move (m_queue.front()); m_queue.pop();
m_queue.pop();
} }
/** /**
@ -125,16 +115,15 @@ class ThreadQueue
* \param[out] item The item. * \param[out] item The item.
* \return False is returned if no item is available. * \return False is returned if no item is available.
*/ */
bool try_pop (value_type& item) bool try_pop(value_type& item) {
{ std::unique_lock < std::mutex > lock(m_mutex);
std::unique_lock<std::mutex> lock (m_mutex);
if (m_queue.empty()) if (m_queue.empty())
return false; return false;
item = m_queue.front(); item = m_queue.front();
m_queue.pop(); m_queue.pop();
return true; return true;
} }
/** /**
@ -143,16 +132,15 @@ class ThreadQueue
* \param[out] item The item. * \param[out] item The item.
* \return False is returned if no item is available. * \return False is returned if no item is available.
*/ */
bool try_move_pop (value_type& item) bool try_move_pop(value_type& item) {
{ std::unique_lock < std::mutex > lock(m_mutex);
std::unique_lock<std::mutex> lock (m_mutex);
if (m_queue.empty()) if (m_queue.empty())
return false; return false;
item = std::move (m_queue.front()); item = std::move(m_queue.front());
m_queue.pop(); m_queue.pop();
return true; return true;
} }
/** /**
@ -161,22 +149,20 @@ class ThreadQueue
* \param[in] timeout The number of microseconds to wait. * \param[in] timeout The number of microseconds to wait.
* \return true if get an item from the queue, false if no item is received before the timeout. * \return true if get an item from the queue, false if no item is received before the timeout.
*/ */
bool timeout_pop (value_type& item, std::uint64_t timeout) bool timeout_pop(value_type& item, std::uint64_t timeout) {
{ std::unique_lock < std::mutex > lock(m_mutex);
std::unique_lock<std::mutex> lock (m_mutex);
if (m_queue.empty()) if (m_queue.empty()) {
{ if (timeout == 0)
if (timeout == 0) return false;
return false;
if (m_condition.wait_for (lock, std::chrono::microseconds (timeout)) == std::cv_status::timeout) if (m_condition.wait_for(lock, std::chrono::microseconds(timeout)) == std::cv_status::timeout)
return false; return false;
} }
item = m_queue.front(); item = m_queue.front();
m_queue.pop(); m_queue.pop();
return true; return true;
} }
/** /**
@ -187,94 +173,85 @@ class ThreadQueue
* \param[in] timeout The number of microseconds to wait. * \param[in] timeout The number of microseconds to wait.
* \return true if get an item from the queue, false if no item is received before the timeout. * \return true if get an item from the queue, false if no item is received before the timeout.
*/ */
bool timeout_move_pop (value_type& item, std::uint64_t timeout) bool timeout_move_pop(value_type& item, std::uint64_t timeout) {
{ std::unique_lock < std::mutex > lock(m_mutex);
std::unique_lock<std::mutex> lock (m_mutex);
if (m_queue.empty()) if (m_queue.empty()) {
{ if (timeout == 0)
if (timeout == 0) return false;
return false;
if (m_condition.wait_for (lock, std::chrono::microseconds (timeout)) == std::cv_status::timeout) if (m_condition.wait_for(lock, std::chrono::microseconds(timeout)) == std::cv_status::timeout)
return false; return false;
} }
item = std::move (m_queue.front()); item = std::move(m_queue.front());
m_queue.pop(); m_queue.pop();
return true; return true;
} }
/** /**
* Gets the number of items in the queue. * Gets the number of items in the queue.
* \return Number of items in the queue. * \return Number of items in the queue.
*/ */
size_type size() const size_type size() const {
{ std::lock_guard < std::mutex > lock(m_mutex);
std::lock_guard<std::mutex> lock (m_mutex); return m_queue.size();
return m_queue.size();
} }
/** /**
* Check if the queue is empty. * Check if the queue is empty.
* \return true if queue is empty. * \return true if queue is empty.
*/ */
bool empty() const bool empty() const {
{ std::lock_guard < std::mutex > lock(m_mutex);
std::lock_guard<std::mutex> lock (m_mutex); return m_queue.empty();
return m_queue.empty();
} }
/** /**
* Swaps the contents. * Swaps the contents.
* \param[out] sq The ThreadQueue to swap with 'this'. * \param[out] sq The ThreadQueue to swap with 'this'.
*/ */
void swap (ThreadQueue& sq) void swap(ThreadQueue& sq) {
{ if (this != &sq) {
if (this != &sq) std::lock_guard < std::mutex > lock1(m_mutex);
{ std::lock_guard < std::mutex > lock2(sq.m_mutex);
std::lock_guard<std::mutex> lock1 (m_mutex); m_queue.swap(sq.m_queue);
std::lock_guard<std::mutex> lock2 (sq.m_mutex);
m_queue.swap (sq.m_queue);
if (!m_queue.empty()) if (!m_queue.empty())
m_condition.notify_all(); m_condition.notify_all();
if (!sq.m_queue.empty()) if (!sq.m_queue.empty())
sq.m_condition.notify_all(); sq.m_condition.notify_all();
} }
} }
/*! The copy assignment operator */ /*! The copy assignment operator */
ThreadQueue& operator= (const ThreadQueue& sq) ThreadQueue& operator=(const ThreadQueue& sq) {
{ if (this != &sq) {
if (this != &sq) std::lock_guard < std::mutex > lock1(m_mutex);
{ std::lock_guard < std::mutex > lock2(sq.m_mutex);
std::lock_guard<std::mutex> lock1 (m_mutex); std::queue<T, Container> temp { sq.m_queue };
std::lock_guard<std::mutex> lock2 (sq.m_mutex); m_queue.swap(temp);
std::queue<T, Container> temp {sq.m_queue};
m_queue.swap (temp);
if (!m_queue.empty()) if (!m_queue.empty())
m_condition.notify_all(); m_condition.notify_all();
} }
return *this; return *this;
} }
/*! The move assignment operator */ /*! The move assignment operator */
ThreadQueue& operator= (ThreadQueue && sq) ThreadQueue& operator=(ThreadQueue && sq) {
{ std::lock_guard < std::mutex > lock(m_mutex);
std::lock_guard<std::mutex> lock (m_mutex); m_queue = std::move(sq.m_queue);
m_queue = std::move (sq.m_queue);
if (!m_queue.empty()) m_condition.notify_all(); if (!m_queue.empty())
m_condition.notify_all();
return *this; return *this;
} }
private:
private:
std::queue<T, Container> m_queue; std::queue<T, Container> m_queue;
mutable std::mutex m_mutex; mutable std::mutex m_mutex;
@ -283,8 +260,7 @@ class ThreadQueue
}; };
/*! Swaps the contents of two ThreadQueue objects. */ /*! Swaps the contents of two ThreadQueue objects. */
template <class T, class Container> template<class T, class Container>
void swap (ThreadQueue<T, Container>& q1, ThreadQueue<T, Container>& q2) void swap(ThreadQueue<T, Container>& q1, ThreadQueue<T, Container>& q2) {
{ q1.swap(q2);
q1.swap (q2);
} }

View File

@ -1,4 +1,3 @@
#ifndef TIMER_H #ifndef TIMER_H
#define TIMER_H #define TIMER_H
@ -13,164 +12,150 @@
* Class provides high resolution timing and useful time control functions * Class provides high resolution timing and useful time control functions
*/ */
class Timer class Timer {
{
private: private:
unsigned long time_elapsed; unsigned long time_elapsed;
unsigned long system_milliseconds; unsigned long system_milliseconds;
unsigned long start_time; unsigned long start_time;
unsigned long end_time; unsigned long end_time;
unsigned long last_update; unsigned long last_update;
unsigned long num_updates; unsigned long num_updates;
unsigned long paused_time; unsigned long paused_time;
unsigned long offset; unsigned long offset;
#ifndef WIN32 #ifndef WIN32
struct timeval time_val; struct timeval time_val;
struct timezone time_zone; struct timezone time_zone;
#endif #endif
bool paused_state;
bool paused_state; bool lock_state;
bool lock_state; float lock_rate;
float lock_rate;
public: public:
/// Constructor /// Constructor
Timer(); Timer();
/// Start the timer /// Start the timer
/** /**
* Resets the timer to 0 and begins timing * Resets the timer to 0 and begins timing
*/ */
void start(void); void start(void);
/// Stop the timer /// Stop the timer
/** /**
* Stops the timer and records the end time * Stops the timer and records the end time
*/ */
void stop(void); void stop(void);
/// Locks the timer to a specified framerate (for recording / benchmarking purposes typically)
/**
* Locks the timer to a specified framerate (for recording / benchmarking purposes typically)
*/
void lockFramerate(float f_rate);
/// Locks the timer to a specified framerate (for recording / benchmarking purposes typically) /// Unlock any framerate lock that's been applied
/** /**
* Locks the timer to a specified framerate (for recording / benchmarking purposes typically) * Unlock any framerate lock that's been applied
*/ */
void lockFramerate(float f_rate); void unlock();
/// Check locked state
/**
* Check locked state
*/
bool locked();
/// Unlock any framerate lock that's been applied /// Reset the timer counter
/** /**
* Unlock any framerate lock that's been applied * Resetting the timer will reset the current time to 0
*/ */
void unlock(); void reset(void);
/// Timer update
/**
* Calling the update command will bring the timer value up to date, this is meant
* to be called at the begining of the frame to establish the time index which is being drawn.
*/
void update(void);
/// Check locked state /// Get the total time elapsed since the timer start, not counting paused time
/** /**
* Check locked state * Returns the total time elapsed in since the timer start() to the last update() but
*/ * does not count the time elapsed while the timer is paused().
bool locked(); * \return Total time elapsed since the timer start() to the last update() excluding time paused() in milliseconds
*/
unsigned long getMilliseconds(void);
/// Alias of getMilliseconds() which returns time in seconds
/**
* \return Total time elapsed since the timer start() to the last update() excluding time paused() in seconds
*/
double getSeconds(void);
/// Get the total time elapsed since the timer start
/**
* Returns the total time elapsed in since the timer start() to the last update()
* this includes any time accumulated during updates while paused()
* \return Total time elapsed since the timer start() to the last update() including time paused() in milliseconds
*/
unsigned long totalMilliseconds(void);
/// Alias of totalMilliseconds() which returns time in seconds
/**
* \return Total time elapsed since the timer start() to the last update() including time paused() in seconds
*/
double totalSeconds(void);
/// Reset the timer counter /// Set the amount of time elapsed
/** /**
* Resetting the timer will reset the current time to 0 * Force the timer duration to a specific value, useful for rolling forward or back in a system
*/ * based upon the timer.
void reset(void); * \param milliseconds_in Time to set timer to in milliseconds
*/
void setMilliseconds(unsigned long milliseconds_in);
/// alias of setMilliseconds() which accepts time in seconds
/**
* \param seconds_in Time to set timer to in seconds
*/
void setSeconds(double seconds_in);
/// Get the amount of times the update() command has been called
/**
* By using the number of times the update() command has been called you can easily determine
* an average frame rate. Also useful for merely determining how many frames have been drawn.
* \return Number of times update() has been called
*/
unsigned long getNumUpdates(void);
/// Timer update /// Get the timer duration during the last update
/** /**
* Calling the update command will bring the timer value up to date, this is meant * Useful for determining the amount of time which elapsed during the last update
* to be called at the begining of the frame to establish the time index which is being drawn. * can be used to accurately control values with a per-second rate or determine the current frame rate.
*/ * \return Duration of time between the last two calls to update() in milliseconds
void update(void); */
unsigned long lastUpdateMilliseconds(void);
/// Alias of lastUpdateMilliseconds() which returns time in seconds
/**
* \return Duration of time between the last two calls to update() in seconds
*/
double lastUpdateSeconds(void);
/// Set the timer pause state
/**
* Pause the timer, allowing for continued update() calls without an increment in timing but
* maintaining the update and total time count, useful for pausing a scene but allowing frame
* timing to resume.
* \param pause_in Value to set the current pause state to
*/
void paused(bool pause_in);
/// Get the total time elapsed since the timer start, not counting paused time /// Check if the timer is currently in a paused state
/** /**
* Returns the total time elapsed in since the timer start() to the last update() but * \return Current pause state, true if paused, false otherwise
* does not count the time elapsed while the timer is paused(). */
* \return Total time elapsed since the timer start() to the last update() excluding time paused() in milliseconds bool paused();
*/
unsigned long getMilliseconds(void);
/// Alias of getMilliseconds() which returns time in seconds
/**
* \return Total time elapsed since the timer start() to the last update() excluding time paused() in seconds
*/
double getSeconds(void);
/// Get the total time elapsed since the timer start
/**
* Returns the total time elapsed in since the timer start() to the last update()
* this includes any time accumulated during updates while paused()
* \return Total time elapsed since the timer start() to the last update() including time paused() in milliseconds
*/
unsigned long totalMilliseconds(void);
/// Alias of totalMilliseconds() which returns time in seconds
/**
* \return Total time elapsed since the timer start() to the last update() including time paused() in seconds
*/
double totalSeconds(void);
/// Set the amount of time elapsed
/**
* Force the timer duration to a specific value, useful for rolling forward or back in a system
* based upon the timer.
* \param milliseconds_in Time to set timer to in milliseconds
*/
void setMilliseconds(unsigned long milliseconds_in);
/// alias of setMilliseconds() which accepts time in seconds
/**
* \param seconds_in Time to set timer to in seconds
*/
void setSeconds(double seconds_in);
/// Get the amount of times the update() command has been called
/**
* By using the number of times the update() command has been called you can easily determine
* an average frame rate. Also useful for merely determining how many frames have been drawn.
* \return Number of times update() has been called
*/
unsigned long getNumUpdates(void);
/// Get the timer duration during the last update
/**
* Useful for determining the amount of time which elapsed during the last update
* can be used to accurately control values with a per-second rate or determine the current frame rate.
* \return Duration of time between the last two calls to update() in milliseconds
*/
unsigned long lastUpdateMilliseconds(void);
/// Alias of lastUpdateMilliseconds() which returns time in seconds
/**
* \return Duration of time between the last two calls to update() in seconds
*/
double lastUpdateSeconds(void);
/// Set the timer pause state
/**
* Pause the timer, allowing for continued update() calls without an increment in timing but
* maintaining the update and total time count, useful for pausing a scene but allowing frame
* timing to resume.
* \param pause_in Value to set the current pause state to
*/
void paused(bool pause_in);
/// Check if the timer is currently in a paused state
/**
* \return Current pause state, true if paused, false otherwise
*/
bool paused();
}; };
#endif #endif