90 lines
1.9 KiB
C++
90 lines
1.9 KiB
C++
#include <cstdio>
|
|
#include <cstring>
|
|
#include <cerrno>
|
|
#include <cstdint>
|
|
#include <memory>
|
|
#include <limits>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include "common.hh"
|
|
#include "util.hh"
|
|
#include "MveDecoder.hh"
|
|
#include "render/Renderer.hh"
|
|
#include "game/GSMvePlay.hh"
|
|
|
|
using render::Renderer;
|
|
|
|
void usage(char *argv0) {
|
|
fprintf(stderr, "Usage: %s [-h] (tre-file name/crc)/iff-file\n", argv0);
|
|
fprintf(stderr, "\tAttempt to decode the movie stored in iff-file, or in the\n\tiff-object \"name\"/\"crc\" contained in tre-file\n");
|
|
fprintf(stderr, "\t-p [id]\tPlay branch id, or all branches if no id given\n");
|
|
fprintf(stderr, "\t-h\tPrint this help\n");
|
|
}
|
|
|
|
int main(int argc, char *argv[]) {
|
|
std::string inPath;
|
|
int branch = -1;
|
|
bool play = false;
|
|
{
|
|
int opt;
|
|
while ((opt = getopt(argc, argv, "hp::")) != -1) {
|
|
switch (opt) {
|
|
case 'h':
|
|
usage(argv[0]);
|
|
return 0;
|
|
case 'p':
|
|
play = true;
|
|
if (optarg) {
|
|
try {
|
|
branch = std::stoi(optarg, nullptr, 10);
|
|
} catch (std::invalid_argument &ex) {
|
|
} catch (std::out_of_range &ex) {
|
|
}
|
|
}
|
|
break;
|
|
default:
|
|
usage(argv[0]);
|
|
return 1;
|
|
}
|
|
}
|
|
|
|
if (optind != argc-1) {
|
|
usage(argv[0]);
|
|
return 1;
|
|
}
|
|
|
|
inPath = argv[optind];
|
|
}
|
|
|
|
try {
|
|
auto mve = std::make_unique<MveDecoder>(inPath);
|
|
|
|
if (play) {
|
|
Renderer renderer;
|
|
|
|
if (branch >= 0) {
|
|
auto movie = mve->open(branch);
|
|
renderer.pushGS(std::make_unique<game::GSMvePlay>(renderer, movie));
|
|
renderer.run();
|
|
} else {
|
|
for(unsigned i = 0;i < mve->numBranches();++i) {
|
|
auto movie = mve->open(i);
|
|
renderer.pushGS(std::make_unique<game::GSMvePlay>(renderer, movie));
|
|
renderer.run();
|
|
}
|
|
}
|
|
}
|
|
} catch (POSIXException &ex) {
|
|
fflush(stdout);
|
|
fprintf(stderr, "%s\n", ex.toString().c_str());
|
|
return 2;
|
|
} catch (Exception &ex) {
|
|
fflush(stdout);
|
|
fprintf(stderr, "%s\n", ex.toString().c_str());
|
|
return 3;
|
|
}
|
|
|
|
return 0;
|
|
}
|