1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129
|
#include "Doom3AasFileLoader.h"
#include "itextstream.h"
#include "parser/DefTokeniser.h"
#include "string/convert.h"
#include "Doom3AasFile.h"
#include "module/StaticModule.h"
namespace map
{
namespace
{
const float DEWM3_AAS_VERSION = 1.07f;
}
const std::string& Doom3AasFileLoader::getAasFormatName() const
{
static std::string _name = "Doom 3 AAS";
return _name;
}
const std::string& Doom3AasFileLoader::getGameType() const
{
static std::string _gameType = "doom3";
return _gameType;
}
bool Doom3AasFileLoader::canLoad(std::istream& stream) const
{
// Instantiate a tokeniser to read the first few tokens
parser::BasicDefTokeniser<std::istream> tok(stream);
try
{
parseVersion(tok);
}
catch (parser::ParseException&)
{
return false;
}
catch (std::invalid_argument&)
{
return false;
}
return true;
}
IAasFilePtr Doom3AasFileLoader::loadFromStream(std::istream& stream)
{
Doom3AasFilePtr aasFile = std::make_shared<Doom3AasFile>();
// We assume that the stream is rewound to the beginning
// Instantiate a tokeniser to read the version tag
parser::BasicDefTokeniser<std::istream> tok(stream);
try
{
// File header
parseVersion(tok);
// Checksum (will throw if the string conversion fails)
string::convert<long>(tok.nextToken());
aasFile->parseFromTokens(tok);
}
catch (parser::ParseException& ex)
{
rError() << "Failure parsing AAS file: " << ex.what() << std::endl;
return IAasFilePtr();
}
catch (std::invalid_argument& ex)
{
rError() << "Conversion error while parsing AAS file: " << ex.what() << std::endl;
return IAasFilePtr();
}
return aasFile;
}
void Doom3AasFileLoader::parseVersion(parser::DefTokeniser& tok) const
{
// Require a "Version" token
tok.assertNextToken("DewmAAS");
// Require specific version, return true on success
if (std::stof(tok.nextToken()) != DEWM3_AAS_VERSION)
{
throw parser::ParseException("AAS File version mismatch");
}
}
const std::string& Doom3AasFileLoader::getName() const
{
static std::string _name("Doom3AasFileLoader");
return _name;
}
const StringSet& Doom3AasFileLoader::getDependencies() const
{
static StringSet _dependencies;
if (_dependencies.empty())
{
_dependencies.insert(MODULE_AASFILEMANAGER);
}
return _dependencies;
}
void Doom3AasFileLoader::initialiseModule(const IApplicationContext& ctx)
{
// Register ourselves as aas format
GlobalAasFileManager().registerLoader(shared_from_this());
}
void Doom3AasFileLoader::shutdownModule()
{
// Unregister now that we're shutting down
GlobalAasFileManager().unregisterLoader(shared_from_this());
}
// Static module instances
module::StaticModuleRegistration<Doom3AasFileLoader> d3AasModule;
}
|