summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMatthias Schiffer <mschiffer@universe-factory.net>2015-02-03 18:39:58 +0100
committerMatthias Schiffer <mschiffer@universe-factory.net>2015-02-03 18:39:58 +0100
commit0162c236faa324b94ac61c9680c2a88e1915f0cc (patch)
tree18defdd9d6b0a3f43eb26b22d307716a0873fb3b /src
parent45a1915006d6a4c2d12aad4e7c9c6e650ead0b3b (diff)
downloadMinedMap-0162c236faa324b94ac61c9680c2a88e1915f0cc.tar
MinedMap-0162c236faa324b94ac61c9680c2a88e1915f0cc.zip
Nicer timespec operations
Diffstat (limited to 'src')
-rw-r--r--src/MinedMap.cpp30
1 files changed, 25 insertions, 5 deletions
diff --git a/src/MinedMap.cpp b/src/MinedMap.cpp
index 7782c5b..4ac39e1 100644
--- a/src/MinedMap.cpp
+++ b/src/MinedMap.cpp
@@ -52,6 +52,27 @@ namespace MinedMap {
static const size_t DIM = World::Region::SIZE*World::Chunk::SIZE;
+static inline bool operator<(const struct timespec &t1, const struct timespec &t2) {
+ return (t1.tv_sec < t2.tv_sec || (t1.tv_sec == t2.tv_sec && t1.tv_nsec < t2.tv_nsec));
+}
+
+static inline bool operator<=(const struct timespec &t1, const struct timespec &t2) {
+ return (t1.tv_sec < t2.tv_sec || (t1.tv_sec == t2.tv_sec && t1.tv_nsec <= t2.tv_nsec));
+}
+
+static inline bool operator>(const struct timespec &t1, const struct timespec &t2) {
+ return (t1.tv_sec > t2.tv_sec || (t1.tv_sec == t2.tv_sec && t1.tv_nsec > t2.tv_nsec));
+}
+
+static inline bool operator>=(const struct timespec &t1, const struct timespec &t2) {
+ return (t1.tv_sec >= t2.tv_sec || (t1.tv_sec == t2.tv_sec && t1.tv_nsec >= t2.tv_nsec));
+}
+
+static inline bool operator==(const struct timespec &t1, const struct timespec &t2) {
+ return (t1.tv_sec == t2.tv_sec && t1.tv_nsec == t2.tv_nsec);
+}
+
+
static void addChunk(uint32_t image[DIM*DIM], uint8_t lightmap[2*DIM*DIM], size_t X, size_t Z, const World::Chunk *chunk) {
World::Chunk::Blocks layer = chunk->getTopLayer();
@@ -96,11 +117,10 @@ static void doRegion(const std::string &input, const std::string &output, const
}
if (stat(output.c_str(), &outstat) == 0) {
- if (instat.st_mtim.tv_sec < outstat.st_mtim.tv_sec ||
- (instat.st_mtim.tv_sec == outstat.st_mtim.tv_sec && instat.st_mtim.tv_nsec <= outstat.st_mtim.tv_nsec)) {
- std::printf("%s is up-to-date.\n", output.c_str());
- return;
- }
+ if (instat.st_mtim <= outstat.st_mtim) {
+ std::printf("%s is up-to-date.\n", output.c_str());
+ return;
+ }
}
std::printf("Generating %s from %s...\n", output.c_str(), input.c_str());