From 7863e4caa1d07aef348a437fe0a662db68fd7ac3 Mon Sep 17 00:00:00 2001 From: Aki Date: Sat, 21 May 2022 11:55:08 +0200 Subject: Added naive Timeline --- Reader.cpp | 57 ++++++++++++--------------------------------------------- 1 file changed, 12 insertions(+), 45 deletions(-) (limited to 'Reader.cpp') 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 -#include #include +#include +#include #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& grids, const LongVector3& position); -static std::tm end_of_time(); -static bool earlier(const std::tm& lhs, const std::tm& rhs); -std::vector +std::tuple, Timeline> Reader::read(Source& source) { std::vector grids; - std::tm start = end_of_time(); - std::tm end = {}; + std::time_t start {std::numeric_limits::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((wreck.killmail.position.y - average.y) * SCALE), static_cast((wreck.killmail.position.z - average.z) * SCALE), }; + wreck.time = static_cast(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& 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::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; -} -- cgit v1.1