summaryrefslogtreecommitdiffhomepage
path: root/Reader.cpp
diff options
context:
space:
mode:
authorAki <please@ignore.pl>2022-05-21 11:55:08 +0200
committerAki <please@ignore.pl>2022-05-21 11:55:08 +0200
commit7863e4caa1d07aef348a437fe0a662db68fd7ac3 (patch)
treebf52dfa7a7c45be1d1a696f5bf7c0c3f90beba68 /Reader.cpp
parentde8d7a812c4da9f0375dc47626c0e836ba728207 (diff)
downloadderelict-7863e4caa1d07aef348a437fe0a662db68fd7ac3.zip
derelict-7863e4caa1d07aef348a437fe0a662db68fd7ac3.tar.gz
derelict-7863e4caa1d07aef348a437fe0a662db68fd7ac3.tar.bz2
Added naive Timeline
Diffstat (limited to 'Reader.cpp')
-rw-r--r--Reader.cpp57
1 files changed, 12 insertions, 45 deletions
diff --git a/Reader.cpp b/Reader.cpp
index f14b837..165e049 100644
--- a/Reader.cpp
+++ b/Reader.cpp
@@ -1,12 +1,14 @@
#include "Reader.h"
#include <ctime>
-#include <vector>
#include <limits>
+#include <tuple>
+#include <vector>
#include "Grid.h"
#include "LongVector3.h"
#include "Source.h"
+#include "Timeline.h"
#include "Utils.h"
#include "Wreck.h"
@@ -16,21 +18,19 @@ static constexpr long double EXTENT {1000 * 50000};
static Grid& find_grid_for(std::vector<Grid>& grids, const LongVector3& position);
-static std::tm end_of_time();
-static bool earlier(const std::tm& lhs, const std::tm& rhs);
-std::vector<Grid>
+std::tuple<std::vector<Grid>, Timeline>
Reader::read(Source& source)
{
std::vector<Grid> grids;
- std::tm start = end_of_time();
- std::tm end = {};
+ std::time_t start {std::numeric_limits<std::time_t>::max()};
+ std::time_t end {0};
for (auto& km : source.killmails()) {
- if (earlier(km.time, start)) start = km.time;
- if (earlier(end, km.time)) end = km.time;
+ if (km.time < start) start = km.time;
+ if (end < km.time) end = km.time;
auto& grid = find_grid_for(grids, km.position);
- grid.wrecks.push_back(Wreck{Vector3{0, 0, 0}, km});
+ grid.wrecks.push_back(Wreck{Vector3{0, 0, 0}, km, 0});
}
for (auto& grid : grids) {
LongVector3 average {0, 0, 0};
@@ -49,12 +49,12 @@ Reader::read(Source& source)
static_cast<float>((wreck.killmail.position.y - average.y) * SCALE),
static_cast<float>((wreck.killmail.position.z - average.z) * SCALE),
};
+ wreck.time = static_cast<double>(wreck.killmail.time - start);
}
grid.origin = average;
}
- (void) start;
- (void) end;
- return grids;
+ Timeline timeline(start, end);
+ return {grids, timeline};
}
@@ -68,36 +68,3 @@ find_grid_for(std::vector<Grid>& grids, const LongVector3& position)
grids.push_back(Grid{});
return grids.back();
}
-
-
-std::tm
-end_of_time()
-{
- std::tm time {};
- time.tm_sec = 60;
- time.tm_min = 59;
- time.tm_hour = 23;
- time.tm_mday = 31;
- time.tm_mon = 11;
- time.tm_year = std::numeric_limits<decltype(time.tm_year)>::max();
- return time;
-}
-
-
-bool
-earlier(const std::tm& lhs, const std::tm& rhs)
-{
- if (lhs.tm_year > rhs.tm_year) return false;
- if (lhs.tm_year < rhs.tm_year) return true;
- if (lhs.tm_mon > rhs.tm_mon) return false;
- if (lhs.tm_mon < rhs.tm_mon) return true;
- if (lhs.tm_mday > rhs.tm_mday) return false;
- if (lhs.tm_mday < rhs.tm_mday) return true;
- if (lhs.tm_hour > rhs.tm_hour) return false;
- if (lhs.tm_hour < rhs.tm_hour) return true;
- if (lhs.tm_min > rhs.tm_min) return false;
- if (lhs.tm_min < rhs.tm_min) return true;
- if (lhs.tm_sec > rhs.tm_sec) return false;
- if (lhs.tm_sec < rhs.tm_sec) return true;
- return false;
-}