diff options
author | Aki <please@ignore.pl> | 2022-05-21 00:26:44 +0200 |
---|---|---|
committer | Aki <please@ignore.pl> | 2022-05-21 00:30:05 +0200 |
commit | de8d7a812c4da9f0375dc47626c0e836ba728207 (patch) | |
tree | 80596e335b7f816f79b7554b868b977d792e72ba /Reader.cpp | |
parent | 0e0358af887336d3466ac408e0404fbc806611f0 (diff) | |
download | derelict-de8d7a812c4da9f0375dc47626c0e836ba728207.zip derelict-de8d7a812c4da9f0375dc47626c0e836ba728207.tar.gz derelict-de8d7a812c4da9f0375dc47626c0e836ba728207.tar.bz2 |
Find start and end dates in Reader
Diffstat (limited to 'Reader.cpp')
-rw-r--r-- | Reader.cpp | 43 |
1 files changed, 43 insertions, 0 deletions
@@ -1,6 +1,8 @@ #include "Reader.h" +#include <ctime> #include <vector> +#include <limits> #include "Grid.h" #include "LongVector3.h" @@ -14,13 +16,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> Reader::read(Source& source) { std::vector<Grid> grids; + std::tm start = end_of_time(); + std::tm end = {}; for (auto& km : source.killmails()) { + if (earlier(km.time, start)) start = km.time; + if (earlier(end, km.time)) end = km.time; auto& grid = find_grid_for(grids, km.position); grid.wrecks.push_back(Wreck{Vector3{0, 0, 0}, km}); } @@ -44,6 +52,8 @@ Reader::read(Source& source) } grid.origin = average; } + (void) start; + (void) end; return grids; } @@ -58,3 +68,36 @@ 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; +} |