예제 #1
0
ticks next(ticks range) { return ticks(next(range.count())); }
예제 #2
0
 inline bool operator==(const ticks& a, const ticks& b)
 {
     return a.count() == b.count();
 }
예제 #3
0
 inline bool operator>(const ticks& a, const ticks& b)
 {
     return a.count() > b.count();
 }
예제 #4
0
 inline ticks operator*(const T& a, const ticks& b)
 {
     return ticks(static_cast<std::uint64_t>(a * b.count()));
 }
예제 #5
0
 inline ticks operator+(const ticks& a, const ticks& b)
 {
     return ticks(a.count() + b.count());
 }
예제 #6
0
void Starfield::move(ticks by_units) {
    if (!g.ship.get() || !g.ship->active) {
        return;
    }

    const Rect viewport    = antares::viewport();
    const Rect play_screen = antares::play_screen();

    const fixedPointType slowVelocity = {
            scale_by(g.ship->velocity.h * kSlowStarFraction * by_units.count(), gAbsoluteScale),
            scale_by(g.ship->velocity.v * kSlowStarFraction * by_units.count(), gAbsoluteScale),
    };

    const fixedPointType mediumVelocity = {
            scale_by(g.ship->velocity.h * kMediumStarFraction * by_units.count(), gAbsoluteScale),
            scale_by(g.ship->velocity.v * kMediumStarFraction * by_units.count(), gAbsoluteScale),
    };

    const fixedPointType fastVelocity = {
            scale_by(g.ship->velocity.h * kFastStarFraction * by_units.count(), gAbsoluteScale),
            scale_by(g.ship->velocity.v * kFastStarFraction * by_units.count(), gAbsoluteScale),
    };

    for (scrollStarType* star : range(_stars, _stars + kScrollStarNum)) {
        const fixedPointType* velocity;
        switch (star->speed) {
            case kSlowStarSpeed: velocity = &slowVelocity; break;
            case kMediumStarSpeed: velocity = &mediumVelocity; break;
            case kFastStarSpeed: velocity = &fastVelocity; break;
            default:
            case kNoStar: continue;
        }

        star->motionFraction.h += velocity->h;
        star->motionFraction.v += velocity->v;

        int32_t h;
        if (star->motionFraction.h >= Fixed::zero()) {
            h = more_evil_fixed_to_long(star->motionFraction.h + Fixed::from_float(0.5));
        } else {
            h = more_evil_fixed_to_long(star->motionFraction.h - Fixed::from_float(0.5)) + 1;
        }
        star->location.h += h;
        star->motionFraction.h -= Fixed::from_long(h);

        int32_t v;
        if (star->motionFraction.v >= Fixed::zero()) {
            v = more_evil_fixed_to_long(star->motionFraction.v + Fixed::from_float(0.5));
        } else {
            v = more_evil_fixed_to_long(star->motionFraction.v - Fixed::from_float(0.5)) + 1;
        }
        star->location.v += v;
        star->motionFraction.v -= Fixed::from_long(v);

        if ((star->location.h < viewport.left) && (star->oldLocation.h < viewport.left)) {
            star->location.h += play_screen.width() - 1;
            star->location.v       = Randomize(play_screen.height()) + viewport.top;
            star->motionFraction.h = star->motionFraction.v = Fixed::zero();
            star->speed                                     = RandomStarSpeed();
            star->age                                       = 0;
        } else if (
                (star->location.h >= viewport.right) && (star->oldLocation.h >= viewport.right)) {
            star->location.h -= play_screen.width();
            star->location.v       = Randomize(play_screen.height()) + viewport.top;
            star->motionFraction.h = star->motionFraction.v = Fixed::zero();
            star->speed                                     = RandomStarSpeed();
            star->age                                       = 0;
        } else if ((star->location.v < viewport.top) && (star->oldLocation.v < viewport.top)) {
            star->location.h = Randomize(play_screen.width()) + viewport.left;
            star->location.v += play_screen.height() - 1;
            star->motionFraction.h = star->motionFraction.v = Fixed::zero();
            star->speed                                     = RandomStarSpeed();
            star->age                                       = 0;
        } else if (
                (star->location.v >= play_screen.bottom) &&
                (star->oldLocation.v >= play_screen.bottom)) {
            star->location.h = Randomize(play_screen.width()) + viewport.left;
            star->location.v -= play_screen.height();
            star->motionFraction.h = star->motionFraction.v = Fixed::zero();
            star->speed                                     = RandomStarSpeed();
            star->age                                       = 0;
        }

        if (_warp_stars && (star->age == 0)) {
            switch (star->speed) {
                case kSlowStarSpeed: velocity = &slowVelocity; break;
                case kMediumStarSpeed: velocity = &mediumVelocity; break;
                case kFastStarSpeed: velocity = &fastVelocity; break;
                case kNoStar: throw std::runtime_error("invalid value of star->speed.");
            }
            star->location.h -= mFixedToLong(velocity->h);
            star->location.v -= mFixedToLong(velocity->v);
        }
    }

    for (scrollStarType* star : range(_stars + kSparkStarOffset, _stars + kAllStarNum)) {
        if (star->speed == kNoStar) {
            continue;
        }
        star->age -= star->speed * by_units.count();

        star->motionFraction.h += star->velocity.h * by_units.count() + slowVelocity.h;
        star->motionFraction.v += star->velocity.v * by_units.count() + slowVelocity.v;

        int32_t h;
        if (star->motionFraction.h >= Fixed::zero()) {
            h = more_evil_fixed_to_long(star->motionFraction.h + Fixed::from_float(0.5));
        } else {
            h = more_evil_fixed_to_long(star->motionFraction.h - Fixed::from_float(0.5)) + 1;
        }
        star->location.h += h;
        star->motionFraction.h -= Fixed::from_long(h);

        int32_t v;
        if (star->motionFraction.v >= Fixed::zero()) {
            v = more_evil_fixed_to_long(star->motionFraction.v + Fixed::from_float(0.5));
        } else {
            v = more_evil_fixed_to_long(star->motionFraction.v - Fixed::from_float(0.5)) + 1;
        }
        star->location.v += v;
        star->motionFraction.v -= Fixed::from_long(v);
    }
}