class Viewer: public RegisteredApplication<Viewer>
{
private:
+ struct Options
+ {
+ list<string> resource_locations;
+ string animation_name;
+ string renderable_name;
+
+ Options(int, char **);
+ };
+
class Resources: public GL::Resources
{
private:
void add_pack(const string &);
};
+ Options opts;
Graphics::SimpleGLWindow window;
Input::Mouse mouse;
Resources resources;
};
+Viewer::Options::Options(int argc, char **argv)
+{
+ GetOpt getopt;
+ getopt.add_option('r', "resources", resource_locations, GetOpt::REQUIRED_ARG);
+ getopt.add_option('a', "animation", animation_name, GetOpt::REQUIRED_ARG);
+ getopt.add_argument("renderable", renderable_name);
+ getopt(argc, argv);
+}
+
Viewer::Viewer(int argc, char **argv):
+ opts(argc, argv),
window(1024, 768, false),
mouse(window),
view(window, window.get_gl_context()),
light_pitch(0),
dragging(0)
{
- list<string> resource_locations;
- string animation_name;
- string renderable_name;
- GetOpt getopt;
- getopt.add_option('r', "resources", resource_locations, GetOpt::REQUIRED_ARG);
- getopt.add_option('a', "animation", animation_name, GetOpt::REQUIRED_ARG);
- getopt.add_argument("renderable", renderable_name);
- getopt(argc, argv);
-
- for(list<string>::const_iterator i=resource_locations.begin(); i!=resource_locations.end(); ++i)
+ for(list<string>::const_iterator i=opts.resource_locations.begin(); i!=opts.resource_locations.end(); ++i)
{
if(FS::is_dir(*i))
resources.add_directory(*i);
GL::Object *object = 0;
- string ext = FS::extpart(renderable_name);
+ string ext = FS::extpart(opts.renderable_name);
if(ext==".mesh")
{
GL::Mesh *mesh = 0;
- if(FS::exists(renderable_name))
+ if(FS::exists(opts.renderable_name))
{
mesh = new GL::Mesh;
- DataFile::load(*mesh, renderable_name);
- resources.add("__"+renderable_name, mesh);
+ DataFile::load(*mesh, opts.renderable_name);
+ resources.add("__"+opts.renderable_name, mesh);
}
else
- mesh = &resources.get<GL::Mesh>(renderable_name);
+ mesh = &resources.get<GL::Mesh>(opts.renderable_name);
object = new GL::Object;
GL::Technique *tech = new GL::Technique;
resources.add("__.object", object);
}
else if(ext==".object")
- renderable = load<GL::Object>(renderable_name);
+ renderable = load<GL::Object>(opts.renderable_name);
else if(ext==".scene")
{
GL::SimpleScene *scene = new GL::SimpleScene;
- DataFile::load(*scene, renderable_name, resources);
+ DataFile::load(*scene, opts.renderable_name, resources);
renderable = scene;
}
else
throw usage_error("Unknown renderable type");
- if(!animation_name.empty())
+ if(!opts.animation_name.empty())
{
if(!object)
throw usage_error("Must have an object to animate");
- GL::Animation *anim = load<GL::Animation>(animation_name);
+ GL::Animation *anim = load<GL::Animation>(opts.animation_name);
anim_player = new GL::AnimationPlayer;
anim_object = new GL::AnimatedObject(*object);
anim_player->play(*anim_object, *anim);