This repository has been archived by the owner on Sep 13, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Hjs_StdLib_Implement.cpp
69 lines (62 loc) · 1.86 KB
/
Hjs_StdLib_Implement.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/** @brief Implementation of my StdLib
* @author Henry J Schmale
* @date Sept 25, 2014
* @file Hjs_StdLib_Implement.cpp
*
* This has no class implementation just the implementation of functions
* defined in `Hjs_StdLib.h`. These are mostly general functions for
* checking various things, and logging. The logging functionallity is
* removed if `DEBUG_BUILD` is not defined, as it speeds up execution of
* the program, because `cout`/`cerr` is extremely slow on MS Windows.
*/
#include "Hjs_StdLib.h"
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <ios>
/// Variables that are for internal use by Hjs_StdLib
time_t startTime; // time in program execution lib was init'd
bool bLibIsInit = false; // Is the lib init'd
bool bMainThreadActive = true; // Is the main thread still active
/// Initiates my library
void hjs::init_Hjs_StdLib()
{
// check if lib is not init'd, because this should only be called once
if(!bLibIsInit)
{
std::setprecision(5);
bLibIsInit = true;
startTime = clock();
#ifdef DEBUG_BUILD
hjs::logToConsole("HjsStdLib Initiated");
#endif // DEBUG_BUILD
}
}
void hjs::logTimeToConsole()
{
#ifndef NDEBUG
time_t t = clock(); // Get the Time
float elaps = (float(t) - startTime) / CLOCKS_PER_SEC;
fprintf(stderr, "[%4f]\t", elaps);
#endif // NDEBUG
}
/// Logs a message to stdOutput with the time since execution begin
void hjs::logToConsole(const char * ch)
{
#ifndef NDEBUG
// output time
logTimeToConsole();
puts(ch);
#endif // NDEBUG
}
/// Allows the any thread to end the whole program by calling this function
void hjs::endGame()
{
hjs::logToConsole("GAME OVER!");
bMainThreadActive = false;
}
/// All subthreads should be in while loop testing for this to turn false
bool hjs::gameIsActive()
{
return bMainThreadActive;
}