Factor stuff related to our_movie into separate file

This commit is contained in:
Ilari Liusvaara 2011-09-16 03:49:04 +03:00
parent 75e095b451
commit bbb4241f68
4 changed files with 149 additions and 133 deletions

View file

@ -1,7 +1,7 @@
FONT_SRC := unifontfull-5.1.20080820.hex
CC := g++-4.5
HOSTCC = $(CC)
OBJECTS = controllerdata.o fieldsplit.o memorymanip.o misc.o movie.o moviefile.o render.o rom.o zip.o fonts/font.o keymapper.o window.o window-sdl.o settings.o framerate.o mainloop.o rrdata.o specialframes.o png.o lsnesrc.o memorywatch.o command.o avsnoop.o
OBJECTS = controllerdata.o fieldsplit.o memorymanip.o misc.o movie.o moviefile.o render.o rom.o zip.o fonts/font.o keymapper.o window.o window-sdl.o settings.o framerate.o mainloop.o rrdata.o specialframes.o png.o lsnesrc.o memorywatch.o command.o avsnoop.o moviedata.o
#AVI dumper
OBJECTS += avidump/avidump-control.o avidump/avidump.o

View file

@ -1,6 +1,7 @@
#include "mainloop.hpp"
#include "avsnoop.hpp"
#include "command.hpp"
#include "moviedata.hpp"
#include <iomanip>
#include "framerate.hpp"
#include "memorywatch.hpp"
@ -10,7 +11,6 @@
#include "movie.hpp"
#include "moviefile.hpp"
#include "render.hpp"
#include "keymapper.hpp"
#include "window.hpp"
#include "settings.hpp"
#include "rom.hpp"
@ -19,9 +19,8 @@
#include <cassert>
#include <sstream>
#include "memorymanip.hpp"
#include "keymapper.hpp"
#include "render.hpp"
#include <iostream>
#include <set>
#include "lsnes.hpp"
#include <sys/time.h>
#include <snes/snes.hpp>
@ -87,8 +86,6 @@ namespace
bool cancel_advance;
//Our ROM.
struct loaded_rom* our_rom;
//Our movie file.
struct moviefile our_movie;
//Handle to the graphics system.
window* win;
//The SNES screen.
@ -724,11 +721,6 @@ namespace
} dumpwatch;
}
std::vector<char>& get_host_memory()
{
return our_movie.host_memory;
}
movie& get_movie()
{
return movb.get_movie();
@ -1173,63 +1165,6 @@ namespace
}
} setrwc;
class set_gamename_cmd : public command
{
public:
set_gamename_cmd() throw(std::bad_alloc) : command("set-gamename") {}
void invoke(const std::string& args, window* win) throw(std::bad_alloc, std::runtime_error)
{
our_movie.gamename = args;
out(win) << "Game name changed to '" << our_movie.gamename << "'" << std::endl;
}
std::string get_short_help() throw(std::bad_alloc) { return "Set the game name"; }
std::string get_long_help() throw(std::bad_alloc)
{
return "Syntax: set-gamename <name>\n"
"Sets the game name to <name>\n";
}
} setnamec;
class get_gamename_cmd : public command
{
public:
get_gamename_cmd() throw(std::bad_alloc) : command("get-gamename") {}
void invoke(const std::string& args, window* win) throw(std::bad_alloc, std::runtime_error)
{
if(args != "")
throw std::runtime_error("This command does not take parameters");
out(win) << "Game name is '" << our_movie.gamename << "'" << std::endl;
}
std::string get_short_help() throw(std::bad_alloc) { return "Get the game name"; }
std::string get_long_help() throw(std::bad_alloc)
{
return "Syntax: get-gamename\n"
"Prints the game name\n";
}
} getnamec;
class print_authors_cmd : public command
{
public:
print_authors_cmd() throw(std::bad_alloc) : command("show-authors") {}
void invoke(const std::string& args, window* win) throw(std::bad_alloc, std::runtime_error)
{
if(args != "")
throw std::runtime_error("This command does not take parameters");
size_t idx = 0;
for(auto i = our_movie.authors.begin(); i != our_movie.authors.end(); i++) {
out(win) << (idx++) << ": " << i->first << "|" << i->second << std::endl;
}
out(win) << "End of authors list" << std::endl;
}
std::string get_short_help() throw(std::bad_alloc) { return "Show the run authors"; }
std::string get_long_help() throw(std::bad_alloc)
{
return "Syntax: show-authors\n"
"Shows the run authors\n";
}
} getauthorc;
class repainter : public command
{
public:
@ -1248,79 +1183,22 @@ namespace
}
} repaintc;
class add_author_command : public command
class set_gamename_cmd : public command
{
public:
add_author_command() throw(std::bad_alloc) : command("add-author") {}
set_gamename_cmd() throw(std::bad_alloc) : command("set-gamename") {}
void invoke(const std::string& args, window* win) throw(std::bad_alloc, std::runtime_error)
{
tokensplitter t(args);
fieldsplitter f(t.tail());
std::string full = f;
std::string nick = f;
if(full == "" && nick == "")
throw std::runtime_error("Bad author name");
our_movie.authors.push_back(std::make_pair(full, nick));
out(win) << (our_movie.authors.size() - 1) << ": " << full << "|" << nick << std::endl;
our_movie.gamename = args;
out(win) << "Game name changed to '" << our_movie.gamename << "'" << std::endl;
}
std::string get_short_help() throw(std::bad_alloc) { return "Add an author"; }
std::string get_short_help() throw(std::bad_alloc) { return "Set the game name"; }
std::string get_long_help() throw(std::bad_alloc)
{
return "Syntax: add-author <fullname>\n"
"Syntax: add-author |<nickname>\n"
"Syntax: add-author <fullname>|<nickname>\n"
"Adds a new author\n";
return "Syntax: set-gamename <name>\n"
"Sets the game name to <name>\n";
}
} addauthorc;
class remove_author_command : public command
{
public:
remove_author_command() throw(std::bad_alloc) : command("remove-author") {}
void invoke(const std::string& args, window* win) throw(std::bad_alloc, std::runtime_error)
{
tokensplitter t(args);
uint64_t index = parse_value<uint64_t>(t.tail());
if(index >= our_movie.authors.size())
throw std::runtime_error("No such author");
our_movie.authors.erase(our_movie.authors.begin() + index);
}
std::string get_short_help() throw(std::bad_alloc) { return "Remove an author"; }
std::string get_long_help() throw(std::bad_alloc)
{
return "Syntax: remove-author <id>\n"
"Removes author with ID <id>\n";
}
} removeauthorc;
class edit_author_command : public command
{
public:
edit_author_command() throw(std::bad_alloc) : command("edit-author") {}
void invoke(const std::string& args, window* win) throw(std::bad_alloc, std::runtime_error)
{
tokensplitter t(args);
uint64_t index = parse_value<uint64_t>(t);
if(index >= our_movie.authors.size())
throw std::runtime_error("No such author");
fieldsplitter f(t.tail());
std::string full = f;
std::string nick = f;
if(full == "" && nick == "") {
out(win) << "syntax: edit-author <authornum> <author>" << std::endl;
return;
}
our_movie.authors[index] = std::make_pair(full, nick);
}
std::string get_short_help() throw(std::bad_alloc) { return "Edit an author"; }
std::string get_long_help() throw(std::bad_alloc)
{
return "Syntax: edit-author <authorid> <fullname>\n"
"Syntax: edit-author <authorid> |<nickname>\n"
"Syntax: edit-author <authorid> <fullname>|<nickname>\n"
"Edits author name\n";
}
} editauthorc;
} setnamec;
class add_watch_command : public command
{

127
moviedata.cpp Normal file
View file

@ -0,0 +1,127 @@
#include "moviedata.hpp"
#include "command.hpp"
struct moviefile our_movie;
std::vector<char>& get_host_memory()
{
return our_movie.host_memory;
}
namespace
{
class get_gamename_cmd : public command
{
public:
get_gamename_cmd() throw(std::bad_alloc) : command("get-gamename") {}
void invoke(const std::string& args, window* win) throw(std::bad_alloc, std::runtime_error)
{
if(args != "")
throw std::runtime_error("This command does not take parameters");
out(win) << "Game name is '" << our_movie.gamename << "'" << std::endl;
}
std::string get_short_help() throw(std::bad_alloc) { return "Get the game name"; }
std::string get_long_help() throw(std::bad_alloc)
{
return "Syntax: get-gamename\n"
"Prints the game name\n";
}
} getnamec;
class print_authors_cmd : public command
{
public:
print_authors_cmd() throw(std::bad_alloc) : command("show-authors") {}
void invoke(const std::string& args, window* win) throw(std::bad_alloc, std::runtime_error)
{
if(args != "")
throw std::runtime_error("This command does not take parameters");
size_t idx = 0;
for(auto i = our_movie.authors.begin(); i != our_movie.authors.end(); i++) {
out(win) << (idx++) << ": " << i->first << "|" << i->second << std::endl;
}
out(win) << "End of authors list" << std::endl;
}
std::string get_short_help() throw(std::bad_alloc) { return "Show the run authors"; }
std::string get_long_help() throw(std::bad_alloc)
{
return "Syntax: show-authors\n"
"Shows the run authors\n";
}
} getauthorc;
class add_author_command : public command
{
public:
add_author_command() throw(std::bad_alloc) : command("add-author") {}
void invoke(const std::string& args, window* win) throw(std::bad_alloc, std::runtime_error)
{
tokensplitter t(args);
fieldsplitter f(t.tail());
std::string full = f;
std::string nick = f;
if(full == "" && nick == "")
throw std::runtime_error("Bad author name");
our_movie.authors.push_back(std::make_pair(full, nick));
out(win) << (our_movie.authors.size() - 1) << ": " << full << "|" << nick << std::endl;
}
std::string get_short_help() throw(std::bad_alloc) { return "Add an author"; }
std::string get_long_help() throw(std::bad_alloc)
{
return "Syntax: add-author <fullname>\n"
"Syntax: add-author |<nickname>\n"
"Syntax: add-author <fullname>|<nickname>\n"
"Adds a new author\n";
}
} addauthorc;
class remove_author_command : public command
{
public:
remove_author_command() throw(std::bad_alloc) : command("remove-author") {}
void invoke(const std::string& args, window* win) throw(std::bad_alloc, std::runtime_error)
{
tokensplitter t(args);
uint64_t index = parse_value<uint64_t>(t.tail());
if(index >= our_movie.authors.size())
throw std::runtime_error("No such author");
our_movie.authors.erase(our_movie.authors.begin() + index);
}
std::string get_short_help() throw(std::bad_alloc) { return "Remove an author"; }
std::string get_long_help() throw(std::bad_alloc)
{
return "Syntax: remove-author <id>\n"
"Removes author with ID <id>\n";
}
} removeauthorc;
class edit_author_command : public command
{
public:
edit_author_command() throw(std::bad_alloc) : command("edit-author") {}
void invoke(const std::string& args, window* win) throw(std::bad_alloc, std::runtime_error)
{
tokensplitter t(args);
uint64_t index = parse_value<uint64_t>(t);
if(index >= our_movie.authors.size())
throw std::runtime_error("No such author");
fieldsplitter f(t.tail());
std::string full = f;
std::string nick = f;
if(full == "" && nick == "") {
out(win) << "syntax: edit-author <authornum> <author>" << std::endl;
return;
}
our_movie.authors[index] = std::make_pair(full, nick);
}
std::string get_short_help() throw(std::bad_alloc) { return "Edit an author"; }
std::string get_long_help() throw(std::bad_alloc)
{
return "Syntax: edit-author <authorid> <fullname>\n"
"Syntax: edit-author <authorid> |<nickname>\n"
"Syntax: edit-author <authorid> <fullname>|<nickname>\n"
"Edits author name\n";
}
} editauthorc;
}

11
moviedata.hpp Normal file
View file

@ -0,0 +1,11 @@
#ifndef _moviedata__hpp__included__
#define _moviedata__hpp__included__
#include "moviefile.hpp"
//Our movie file.
extern struct moviefile our_movie;
std::vector<char>& get_host_memory();
#endif