/** Returns the next value of the generator. */ result_type operator()() { // While it may seem wasteful to recalculate this // every time, both msvc and gcc can propagate // constants, resolving this at compile time. base_unsigned range = detail::subtract<base_result>()((_base.max)(), (_base.min)()); std::size_t m = (range == (std::numeric_limits<base_unsigned>::max)()) ? std::numeric_limits<base_unsigned>::digits : detail::integer_log2(range + 1); std::size_t n = (w + m - 1) / m; std::size_t w0, n0; base_unsigned y0, y1; base_unsigned y0_mask, y1_mask; calc_params(n, range, w0, n0, y0, y1, y0_mask, y1_mask); if(base_unsigned(range - y0 + 1) > y0 / n) { // increment n and try again. ++n; calc_params(n, range, w0, n0, y0, y1, y0_mask, y1_mask); } BOOST_ASSERT(n0*w0 + (n - n0)*(w0 + 1) == w); result_type S = 0; for(std::size_t k = 0; k < n0; ++k) { base_unsigned u; do { u = detail::subtract<base_result>()(_base(), (_base.min)()); } while(u > base_unsigned(y0 - 1)); S = (S << w0) + (u & y0_mask); } for(std::size_t k = 0; k < (n - n0); ++k) { base_unsigned u; do { u = detail::subtract<base_result>()(_base(), (_base.min)()); } while(u > base_unsigned(y1 - 1)); S = (S << (w0 + 1)) + (u & y1_mask); } return S; }
void xship_init(SDLData* d, XShip* s) { memset(s, 0, sizeof *s); _turrets(d, s); _reactors(d, s); _base(d, s); _cannon(d, s); s->ship.mxspd = 300; /* 300 */ s->ship.accel = 0.15; /* 0.15 */ s->ship.weight = 1.07; /* 1.07 */ s->ship.shtfq_max = 0.05; /* 0.05 */ s->ship.shtfq_lost = 1.1; s->ship.shtfq_curr = s->ship.shtfq_max; }
span_size_t footer_size(void) const noexcept { return element_header_size(_base()); }