Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #include <iostream>
00012 #include <fstream>
00013
00014 #include "i18n/i18n.h"
00015 #include "perf/perf.h"
00016 #include "physics-loader/physics-loader.h"
00017 #include "story/story.h"
00018 #include "typeinst/typeinst.h"
00019
00020
00021
00023
00024
00025
00027
00028
00030
00031
00032
00034
00035 int
00036 main
00037 (
00038 IN int argc,
00039 IN const char * argv[]
00040 )
00041 {
00042 ASSERT(3 == argc, "usage: typeinst-test <story-dir> <instance-file>");
00043 const char * storyDir = argv[1];
00044 const char * instanceFile = argv[2];
00045 DPRINTF("Using story directory: '%s'", storyDir);
00046 DPRINTF("Using instance file: '%s'", instanceFile);
00047
00048 int retval = 0;
00049
00050 try {
00051 perf::Timer timer("overall timer");
00052
00053 const char * locale = i18n::getHostLocale();
00054 ASSERT_THROW(locale, "failed to determine host locale?");
00055 DPRINTF("Using locale = '%s'", locale);
00056
00057
00058 smart_ptr<story::Story> story =
00059 story::Story::create(locale, storyDir);
00060 ASSERT(story, "null");
00061
00062
00063 aesop::initializeTypeInstanceLibrary(story);
00064
00065
00066 smart_ptr<aesop::TypeComponentLoader> tclPhysics =
00067 aesop::getPhysicsLoader();
00068 ASSERT(tclPhysics, "null");
00069
00070
00071 aesop::registerTypeComponentLoader(tclPhysics);
00072
00073
00074 std::ifstream infile(instanceFile);
00075 ASSERT_THROW(infile.good(), "Could not open file for reading: "
00076 << instanceFile);
00077
00078
00079 aesop::vec_instance_t instances;
00080 aesop::loadInstances(infile, instances);
00081 int nInstances = instances.size();
00082 DPRINTF("Loaded %d instances total", nInstances);
00083
00084
00085 for (int i = 0; i < nInstances; ++i) {
00086 DPRINTF("---- ---- ---- ---- Instance %d:", i);
00087 aesop::Instance * instance = instances[i];
00088 ASSERT_THROW(instance, "null instance in vector?");
00089 instance->dump("basic instance dump");
00090
00091
00092 smart_ptr<aesop::ComponentData> physics =
00093 instance->getComponentData("physics");
00094 if (!physics) {
00095 DPRINTF(" Contains no physics data?");
00096 continue;
00097 }
00098 physics->dump(" Physics data for instance");
00099 }
00100
00101 } catch (std::exception& e) {
00102 DPRINTF("Exception: %s", e.what());
00103 retval = 1;
00104 }
00105
00106 perf::dumpTimingSummary(std::cerr);
00107
00108 return retval;
00109 }
00110