Пример #1
0
void main(int argc, char** argv) {
    args::Parser parser(argv[0], "Plays a replay into a set of images and a log of sounds");

    String replay_path(utf8::decode(argv[0]));
    parser.add_argument("replay", store(replay_path))
    .help("an Antares replay script")
    .required();

    Optional<String> output_dir;
    parser.add_argument("-o", "--output", store(output_dir))
    .help("place output in this directory");

    int interval = 60;
    int width = 640;
    int height = 480;
    parser.add_argument("-i", "--interval", store(interval))
    .help("take one screenshot per this many ticks (default: 60)");
    parser.add_argument("-w", "--width", store(width))
    .help("screen width (default: 640)");
    parser.add_argument("-h", "--height", store(height))
    .help("screen height (default: 480)");

    parser.add_argument("--help", help(parser, 0))
    .help("display this help screen");

    String error;
    if (!parser.parse_args(argc - 1, argv + 1, error)) {
        print(io::err, format("{0}: {1}\n", parser.name(), error));
        exit(1);
    }

    if (output_dir.has()) {
        makedirs(*output_dir, 0755);
    }

    Preferences::set_preferences(new Preferences);
    Preferences::preferences()->set_screen_size(Size(width, height));
    Preferences::preferences()->set_play_music_in_game(true);
    PrefsDriver::set_driver(new NullPrefsDriver);

    scoped_ptr<OffscreenVideoDriver> video(new OffscreenVideoDriver(
            Preferences::preferences()->screen_size(), output_dir));
    video->schedule_event(make_linked_ptr(new MouseMoveEvent(0, Point(320, 240))));
    // TODO(sfiera): add recurring snapshots to OffscreenVideoDriver.
    for (int64_t i = 1; i < 72000; i += interval) {
        video->schedule_snapshot(i);
    }
    VideoDriver::set_driver(video.release());

    if (output_dir.has()) {
        String out(format("{0}/sound.log", *output_dir));
        SoundDriver::set_driver(new LogSoundDriver(out));
    } else {
        SoundDriver::set_driver(new NullSoundDriver);
    }
    Ledger::set_ledger(new NullLedger);

    MappedFile replay_file(replay_path);
    VideoDriver::driver()->loop(new ReplayMaster(replay_file.data()));
}
Пример #2
0
/**
 * \brief Internal tcpreplay method to replay a given index
 *
 * This is used by tcpreplay_replay() to actually send the packets
 */
int 
tcpr_replay_index(tcpreplay_t *ctx)
{
    int rcode = 0;
    int idx;
    assert(ctx);

    /* only process a single file */
    if (! ctx->options->dualfile) {
        /* process each pcap file in order */
        for (idx = 0; idx < ctx->options->source_cnt && !ctx->abort; idx++) {
            /* reset cache markers for each iteration */
            ctx->cache_byte = 0;
            ctx->cache_bit = 0;
            switch(ctx->options->sources[idx].type) {
                case source_filename:
                    rcode = replay_file(ctx, idx);
                    break;
                case source_fd:
                    rcode = replay_fd(ctx, idx);
                    break;
                case source_cache:
                    rcode = replay_cache(ctx, idx);
                    break;
                default:
                    tcpreplay_seterr(ctx, "Invalid source type: %d", ctx->options->sources[idx].type);
                    rcode = -1;
            }
        }
    }

    /* dual file mode: two files, two interfaces */
    else {
        /* process each pcap file in order */
        for (idx = 0; idx < ctx->options->source_cnt && !ctx->abort; idx += 2) {
            if (ctx->options->sources[idx].type != ctx->options->sources[(idx+1)].type) {
                tcpreplay_seterr(ctx, "Both source indexes (%d, %d) must be of the same type", idx, (idx+1));
                return -1;
            }
            switch(ctx->options->sources[idx].type) {
                case source_filename:
                    rcode = replay_two_files(ctx, idx, (idx+1));
                    break;
                case source_fd:
                    rcode = replay_two_fds(ctx, idx, (idx+1));
                    break;
                case source_cache:
                    rcode = replay_two_caches(ctx, idx, (idx+1));
                    break;
                default:
                    tcpreplay_seterr(ctx, "Invalid source type: %d", ctx->options->sources[idx].type);
                    rcode = -1;
            }

        }

    }
    if (rcode < 0) {
        ctx->running = false;
        return -1;
    }

    return rcode;
}
Пример #3
0
void main(int argc, char** argv) {
    args::Parser parser(argv[0], "Plays a replay into a set of images and a log of sounds");

    String replay_path(utf8::decode(argv[0]));
    parser.add_argument("replay", store(replay_path)).help("an Antares replay script").required();

    Optional<String> output_dir;
    parser.add_argument("-o", "--output", store(output_dir))
            .help("place output in this directory");

    int  interval = 60;
    int  width    = 640;
    int  height   = 480;
    bool text     = false;
    bool smoke    = false;
    parser.add_argument("-i", "--interval", store(interval))
            .help("take one screenshot per this many ticks (default: 60)");
    parser.add_argument("-w", "--width", store(width)).help("screen width (default: 640)");
    parser.add_argument("-h", "--height", store(height)).help("screen height (default: 480)");
    parser.add_argument("-t", "--text", store_const(text, true)).help("produce text output");
    parser.add_argument("-s", "--smoke", store_const(smoke, true)).help("run as smoke text");

    parser.add_argument("--help", help(parser, 0)).help("display this help screen");

    String error;
    if (!parser.parse_args(argc - 1, argv + 1, error)) {
        print(io::err, format("{0}: {1}\n", parser.name(), error));
        exit(1);
    }

    if (output_dir.has()) {
        makedirs(*output_dir, 0755);
    }

    Preferences preferences;
    preferences.play_music_in_game = true;
    NullPrefsDriver prefs(preferences);

    EventScheduler scheduler;
    scheduler.schedule_event(unique_ptr<Event>(new MouseMoveEvent(wall_time(), Point(320, 240))));
    // TODO(sfiera): add recurring snapshots to OffscreenVideoDriver.
    for (int64_t i = 1; i < 72000; i += interval) {
        scheduler.schedule_snapshot(i);
    }

    unique_ptr<SoundDriver> sound;
    if (!smoke && output_dir.has()) {
        String out(format("{0}/sound.log", *output_dir));
        sound.reset(new LogSoundDriver(out));
    } else {
        sound.reset(new NullSoundDriver);
    }
    NullLedger ledger;

    MappedFile replay_file(replay_path);
    if (smoke) {
        TextVideoDriver video({width, height}, Optional<String>());
        video.loop(new ReplayMaster(replay_file.data(), output_dir), scheduler);
    } else if (text) {
        TextVideoDriver video({width, height}, output_dir);
        video.loop(new ReplayMaster(replay_file.data(), output_dir), scheduler);
    } else {
        OffscreenVideoDriver video({width, height}, output_dir);
        video.loop(new ReplayMaster(replay_file.data(), output_dir), scheduler);
    }
}