summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPaweł Redman <pawel.redman@gmail.com>2017-12-19 22:21:17 +0100
committerPaweł Redman <pawel.redman@gmail.com>2017-12-19 22:21:17 +0100
commit9628c2c097b10f22aafd4890ab8e98375b5740da (patch)
treec3ae35b5e7cd3f5e525ad85a3dad551f84996cfb /src
parent949eb704c7954ae3646895e4a3d957d0d219142a (diff)
Replace clock_gettime with std::chrono.
Diffstat (limited to 'src')
-rw-r--r--src/common.hpp2
-rw-r--r--src/game/interface.cpp6
-rw-r--r--src/game/text.cpp4
-rw-r--r--src/main.cpp7
4 files changed, 8 insertions, 11 deletions
diff --git a/src/common.hpp b/src/common.hpp
index f7435ca..656a370 100644
--- a/src/common.hpp
+++ b/src/common.hpp
@@ -27,7 +27,7 @@ along with Minitrem. If not, see <http://www.gnu.org/licenses/>.
#include <SFML/Graphics.hpp>
#include "math.hpp"
-#define count(A) (sizeof(A) / sizeof((A)[0]))
+#define COUNT(A) (sizeof(A) / sizeof((A)[0]))
extern bool debug_draw_cmodels;
extern bool debug_draw_paths;
diff --git a/src/game/interface.cpp b/src/game/interface.cpp
index 5e5dc70..1300e95 100644
--- a/src/game/interface.cpp
+++ b/src/game/interface.cpp
@@ -247,13 +247,13 @@ void state_t::render_to(render::state_t *render)
ss << render->stats.entities;
render->render_text(x, em, ss.str(), render::ALIGN_LEFT_TOP, sf::Color::White);
- perf_hist_index = (perf_hist_index + 1) % count(perf_hist);
+ perf_hist_index = (perf_hist_index + 1) % COUNT(perf_hist);
perf_hist[perf_hist_index] = 1.0 / render->dt;
fps = 0.0;
- for (size_t i = 0; i < count(perf_hist); i++)
+ for (size_t i = 0; i < COUNT(perf_hist); i++)
fps += perf_hist[i];
- fps /= count(perf_hist);
+ fps /= COUNT(perf_hist);
x[1] += em;
ss.str(std::string());
diff --git a/src/game/text.cpp b/src/game/text.cpp
index 6f684f0..b9cdd32 100644
--- a/src/game/text.cpp
+++ b/src/game/text.cpp
@@ -66,7 +66,7 @@ static std::string get_english(index_t index)
return "Spider";
case UNIT_NAME_SOLDIER:
- return soldier_names[rand() % count(soldier_names)];
+ return soldier_names[rand() % COUNT(soldier_names)];
case UNIT_NAME_NEST:
return "Nest";
@@ -144,7 +144,7 @@ static std::string get_polish(index_t index)
return "Pająk";
case UNIT_NAME_SOLDIER:
- return soldier_names[rand() % count(soldier_names)];
+ return soldier_names[rand() % COUNT(soldier_names)];
case UNIT_NAME_NEST:
return "Gniazdo";
diff --git a/src/main.cpp b/src/main.cpp
index f45fb24..71e47be 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -16,7 +16,7 @@ along with Minitrem. If not, see <http://www.gnu.org/licenses/>.
*/
#include "common.hpp"
-#include <ctime>
+#include <chrono>
bool debug_draw_cmodels = false;
bool debug_draw_paths = false;
@@ -26,10 +26,7 @@ render::state_t *debug_render;
uint64_t nano_clock(void)
{
- struct timespec ts;
-
- clock_gettime(CLOCK_MONOTONIC_RAW, &ts);
- return ts.tv_sec * 1000000000LLU + ts.tv_nsec;
+ return std::chrono::high_resolution_clock::now().time_since_epoch() / std::chrono::nanoseconds(1);
}
int main()