Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 #include "quake/bsp/bsp.h"
00036
00037 #include <iostream>
00038
00039 #include "perf/perf.h"
00040 #include "util/file.h"
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050 static void
00051 doTest
00052 (
00053 IN const char * filename
00054 )
00055 {
00056 ASSERT(filename, "null");
00057
00058
00059 std::string parentDir;
00060 GetParentDirectory(filename, parentDir);
00061
00062 smart_ptr<nstream::Manager> mgr =
00063 nstream::getFilesystemManager(parentDir.c_str());
00064 ASSERT_THROW(mgr, "failed to get filesystem manager");
00065
00066 const char * name = GetFilename(filename);
00067
00068
00069 smart_ptr<nstream::Stream> stream =
00070 nstream::openNamedStream(mgr, name);
00071 ASSERT_THROW(stream, "failed to open named stream: " << name);
00072
00073
00074 smart_ptr<quake::Bsp> bsp = quake::Bsp::load(stream);
00075 ASSERT_THROW(bsp, "failed to load bsp");
00076
00077 DPRINTF("Just loaded bsp with name: '%s'", bsp->getName());
00078
00079
00080 const quake::vec_lump_type_t& lumps = bsp->getLumps();
00081 DPRINTF("Contains %d lumps", (int) lumps.size());
00082 for (quake::vec_lump_type_t::const_iterator i = lumps.begin();
00083 i != lumps.end(); ++i) {
00084 quake::eLumpType type = *i;
00085 const char * name = quake::getLumpName(type);
00086 ASSERT_THROW(name, "Name not found for type: " << type);
00087 DPRINTF("Reading lump: %s", name);
00088
00089 int nObjects = bsp->getLumpObjectCount(type);
00090 DPRINTF(" There are %d objects of this type", nObjects);
00091 if (!nObjects) {
00092 DPRINTF(" Lump is empty or does not exist!");
00093 continue;
00094 }
00095 if (nObjects < 0) {
00096 DPRINTF(" Variable number of objects in lump!");
00097 nObjects = 0x7ffff;
00098 }
00099
00100
00101 std::string timerName = "iterateAllLump";
00102 timerName += name;
00103
00104 {
00105 perf::Timer timer(timerName.c_str());
00106
00107 bsp->startLumpIteration(type);
00108 const quake::lump_object_t * obj = NULL;
00109 int j = 0;
00110 while (true) {
00111 obj = bsp->getNextLumpObject();
00112 if (!obj) {
00113
00114 break;
00115 }
00116 ASSERT_THROW(obj->index == j,
00117 "Iteration object has bad index " <<
00118 obj->index << " vs. correct index " << j);
00119 quake::eLumpType oType = obj->getType();
00120 ASSERT_THROW(oType == type,
00121 "Iteration object has bad type " << oType
00122 << " vs. correct type " << type);
00123 ++j;
00124 }
00125 DPRINTF(" Read %d total objects", j);
00126 }
00127 }
00128 }
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138 int
00139 main
00140 (
00141 IN int argc,
00142 IN const char * argv[]
00143 )
00144 {
00145 ASSERT(2 == argc, "usage: quake-bsp-test <bsp-filename>");
00146 const char * filename = argv[1];
00147
00148 int retval = 0;
00149 try {
00150 perf::Timer timer("test -- overall timer");
00151 doTest(filename);
00152
00153 } catch (std::exception& e) {
00154 DPRINTF("Exception: %s", e.what());
00155 retval = 1;
00156 } catch (...) {
00157 DPRINTF("Unknown exception!");
00158 retval = 2;
00159 }
00160 perf::dumpTimingSummary(std::cerr);
00161
00162 return retval;
00163 }
00164