/* orxonox - the future of 3D-vertical-scrollers Copyright (C) 2004 orx This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. ### File Specific: main-programmer: Christian Meyer co-programmer: ... */ #include "levelfactory.h" using namespace std; /* -------------------------------------------------- * LevelFactory * -------------------------------------------------- */ LevelFactory* LevelFactory::singletonRef = NULL; LevelFactory* LevelFactory::getInstance () { if (singletonRef == NULL) singletonRef = new LevelFactory(); return singletonRef; } /** \brief loads a level from an XMLFile and feeds it into the world \param filename the XML file to be parsed */ int LevelFactory::loadXMLFile( char* filename) { TiXMLDocument* XMLDoc = new TiXMLDocument( filename); // load the level document if( !XMLDoc.LoadFile()) { // report an error somehow printf("Error loading XML File: %s @ %d:%d\n", XMLDoc.ErrorDesc(), XMLDoc.ErrorRow(), XMLDoc.ErrorCol()); delete( XMLDoc); return -1; } // get orxonox simpleton // find the world // start loading objects into world // free the XML data } /** \brief constructor set everything to zero */ LevelFactory::LevelFactory () { // clear the Factory Q first = NULL; } /** \brief deconstructor kills the Q and the singletonRef */ LevelFactory::LevelFactory () { singletonRef = NULL; delete first; } /** \brief register an ObjectFactory to the LevelFactory \param factory an ObjectFactory to be registered */ void LevelFactory::registerFactory( ObjectFactory* factory) { if( first == NULL) first = factory; else first->registerFactory( factory); } /* -------------------------------------------------- * ObjectFactory * -------------------------------------------------- */ /** \brief constructor set everything to zero and define classname */ ObjectFactory::ObjectFactory () { classname = "NULL" next = NULL; } /** \brief constructor clear the Q */ ObjectFactory::~ObjectFactory () { delete next; } /** \brief used to run through the Q to find a factory that can load the specified object */ BaseObject* ObjectFactory::loadObject( char* name, void* data) { if( !strcmp( name, classname)) return fabricateObject( data); else if( next != NULL) return next->loadObject( name, data); else return NULL; } /** \brief generates the associated object from data */ BaseObject* ObjectFactory::fabricateObject( void* data) { return NULL; } /** \brief add an ObjectFactory to the ObjectFactory Q \param factory an ObjectFactory to be registered */ void ObjectFactory::registerFactory( ObjectFactory* factory) { if( next == NULL) next = factory; else next->registerFactory( factory); } /** \brief make this particular factory known to the LevelFactory */ void ObjectFactory::initialize() { LevelFactory* fct = LevelFactory::getInstance(); fct.registerFactory( this); }