diff options
author | Ben Longbons <b.r.longbons@gmail.com> | 2014-06-10 15:31:24 -0700 |
---|---|---|
committer | Ben Longbons <b.r.longbons@gmail.com> | 2014-06-23 21:07:14 -0700 |
commit | 1c1752f40aac20bf9a5e56817951a013c2219bed (patch) | |
tree | d4ca348dd88ec08cf4edbdd37b72396b75a914a4 /src/net/timer.t.hpp | |
parent | 8ce2f240dba5bdd0ca47ac25f16f140d8d1744fc (diff) | |
download | tmwa-1c1752f40aac20bf9a5e56817951a013c2219bed.tar.gz tmwa-1c1752f40aac20bf9a5e56817951a013c2219bed.tar.bz2 tmwa-1c1752f40aac20bf9a5e56817951a013c2219bed.tar.xz tmwa-1c1752f40aac20bf9a5e56817951a013c2219bed.zip |
Generate the map server protocol
Sigh, map server will have no smart filters yet
Diffstat (limited to 'src/net/timer.t.hpp')
-rw-r--r-- | src/net/timer.t.hpp | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/src/net/timer.t.hpp b/src/net/timer.t.hpp index 91d4b74..be32872 100644 --- a/src/net/timer.t.hpp +++ b/src/net/timer.t.hpp @@ -26,6 +26,8 @@ # include <chrono> # include <functional> +# include "../ints/little.hpp" + # include "../generic/dumb_ptr.hpp" /// An implementation of the C++ "clock" concept, exposing @@ -49,6 +51,55 @@ typedef milli_clock::duration interval_t; /// (to get additional arguments, use std::bind or a lambda). typedef std::function<void (TimerData *, tick_t)> timer_func; +// 49.7 day problem +inline __attribute__((warn_unused_result)) +bool native_to_network(Little32 *net, tick_t nat) +{ + auto tmp = nat.time_since_epoch().count(); + return native_to_network(net, static_cast<uint32_t>(tmp)); +} + +inline __attribute__((warn_unused_result)) +bool network_to_native(tick_t *nat, Little32 net) +{ + (void)nat; + (void)net; + abort(); +} + +inline __attribute__((warn_unused_result)) +bool native_to_network(Little32 *net, interval_t nat) +{ + auto tmp = nat.count(); + return native_to_network(net, static_cast<uint32_t>(tmp)); +} + +inline __attribute__((warn_unused_result)) +bool network_to_native(interval_t *nat, Little32 net) +{ + uint32_t tmp; + bool rv = network_to_native(&tmp, net); + *nat = interval_t(tmp); + return rv; +} + +inline __attribute__((warn_unused_result)) +bool native_to_network(Little16 *net, interval_t nat) +{ + auto tmp = nat.count(); + return native_to_network(net, static_cast<uint16_t>(tmp)); +} + +inline __attribute__((warn_unused_result)) +bool network_to_native(interval_t *nat, Little16 net) +{ + uint16_t tmp; + bool rv = network_to_native(&tmp, net); + *nat = interval_t(tmp); + return rv; +} + + class Timer { friend struct TimerData; |