IExplosionGenerator* CExplosionGeneratorHandler::LoadGenerator(const string& tag) { string klass; string::size_type seppos = tag.find(':'); if (seppos == string::npos) { klass = tag; } else { klass = tag.substr(0, seppos); } creg::Class* cls = generatorClasses.GetClass(klass); if (!cls->IsSubclassOf(IExplosionGenerator::StaticClass())) { throw content_error(klass + " is not a subclass of IExplosionGenerator"); } IExplosionGenerator* eg = (IExplosionGenerator*) cls->CreateInstance(); if (seppos != string::npos) { eg->Load(this, tag.substr(seppos + 1)); } return eg; }
IExplosionGenerator* CExplosionGeneratorHandler::LoadGenerator(const string& tag) { string prefix = tag; string postfix = ""; string::size_type seppos = tag.find(':'); if (seppos != string::npos) { // grab the "custom" prefix (the only supported value) prefix = tag.substr(0, seppos); postfix = tag.substr(seppos + 1); assert(prefix == "custom"); } creg::Class* cls = generatorClasses.GetClass(prefix); if (!cls->IsSubclassOf(IExplosionGenerator::StaticClass())) { throw content_error(prefix + " is not a subclass of IExplosionGenerator"); } IExplosionGenerator* explGen = (IExplosionGenerator*) cls->CreateInstance(); explGen->SetGeneratorID(++numLoadedGenerators); assert(gCEG != explGen); assert(gCEG->GetGeneratorID() == 0); if (seppos != string::npos) { explGen->Load(this, postfix); } explosionGenerators[explGen->GetGeneratorID()] = explGen; return explGen; }