Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Dec 16, 2008, 6:01:13 PM (15 years ago)
Author:
landauf
Message:

Merged objecthierarchy2 into presentation branch

Couln't merge 2 lines in Gamestate.cc and a whole block of code in GSDedicated.cc (it seems like oli implemented in both branches something like a network-tick-limiter but with different approaches)

Not yet tested in network mode and with bots
The SpaceShips movement is also not yet fully adopted to the new physics (see Engine class)

Location:
code/branches/presentation
Files:
31 edited

Legend:

Unmodified
Added
Removed
  • code/branches/presentation

  • code/branches/presentation/src/core/BaseObject.cc

    r2171 r2485  
    3636#include "CoreIncludes.h"
    3737#include "EventIncludes.h"
     38#include "Functor.h"
    3839#include "XMLPort.h"
    3940#include "XMLFile.h"
     
    6061        this->oldGametype_ = 0;
    6162
     63        this->functorSetMainState_ = 0;
     64        this->functorGetMainState_ = 0;
     65
    6266        this->setCreator(creator);
    6367        if (this->creator_)
     
    8286    BaseObject::~BaseObject()
    8387    {
    84         for (std::list<BaseObject*>::const_iterator it = this->events_.begin(); it != this->events_.end(); ++it)
    85             (*it)->unregisterEventListener(this);
    86 
    87         for (std::map<BaseObject*, std::string>::const_iterator it = this->eventListeners_.begin(); it != this->eventListeners_.end(); ++it)
    88             it->first->removeEvent(this);
     88        if (this->isInitialized())
     89        {
     90            for (std::list<BaseObject*>::const_iterator it = this->events_.begin(); it != this->events_.end(); ++it)
     91                (*it)->unregisterEventListener(this);
     92
     93            for (std::map<BaseObject*, std::string>::const_iterator it = this->eventListeners_.begin(); it != this->eventListeners_.end(); ++it)
     94                it->first->removeEvent(this);
     95
     96            if (this->functorSetMainState_)
     97                delete this->functorSetMainState_;
     98            if (this->functorGetMainState_)
     99                delete this->functorGetMainState_;
     100        }
    89101    }
    90102
     
    100112        XMLPortParam(BaseObject, "visible", setVisible, isVisible, xmlelement, mode);
    101113        XMLPortParam(BaseObject, "active", setActive, isActive, xmlelement, mode);
     114        XMLPortParam(BaseObject, "mainstate", setMainStateName, getMainStateName, xmlelement, mode);
    102115
    103116        XMLPortObjectTemplate(BaseObject, Template, "templates", addTemplate, getTemplate, xmlelement, mode, Template*);
     
    109122            std::list<std::string> eventnames;
    110123
    111             if (mode == XMLPort::LoadObject)
     124            if (mode == XMLPort::LoadObject || mode == XMLPort::ExpandObject)
    112125            {
    113126                for (ticpp::Iterator<ticpp::Element> child = events->FirstChildElement(false); child != child.end(); child++)
     
    279292        SetEvent(BaseObject, "visibility", setVisible, event);
    280293    }
     294
     295    void BaseObject::setMainStateName(const std::string& name)
     296    {
     297        if (this->mainStateName_ != name)
     298        {
     299            this->mainStateName_ = name;
     300            if (this->functorSetMainState_)
     301                delete this->functorSetMainState_;
     302            if (this->functorGetMainState_)
     303                delete this->functorGetMainState_;
     304            this->changedMainState();
     305            if (!this->functorSetMainState_)
     306                COUT(2) << "Warning: \"" << name << "\" is not a valid MainState." << std::endl;
     307        }
     308    }
     309
     310    void BaseObject::setMainState(bool state)
     311    {
     312        if (this->functorSetMainState_)
     313            (*this->functorSetMainState_)(state);
     314        else
     315            COUT(2) << "Warning: No MainState defined in object \"" << this->getName() << "\" (" << this->getIdentifier()->getName() << ")" << std::endl;
     316    }
     317
     318    bool BaseObject::getMainState() const
     319    {
     320        if (this->functorGetMainState_)
     321        {
     322            (*this->functorGetMainState_)();
     323            return this->functorGetMainState_->getReturnvalue();
     324        }
     325        else
     326        {
     327            COUT(2) << "Warning: No MainState defined in object \"" << this->getName() << "\" (" << this->getIdentifier()->getName() << ")" << std::endl;
     328            return false;
     329        }
     330    }
     331
     332    void BaseObject::changedMainState()
     333    {
     334        SetMainState(BaseObject, "activity",   setActive,  isActive);
     335        SetMainState(BaseObject, "visibility", setVisible, isVisible);
     336    }
    281337}
  • code/branches/presentation/src/core/BaseObject.h

    r2171 r2485  
    3636#ifndef _BaseObject_H__
    3737#define _BaseObject_H__
     38
     39#define SetMainState(classname, statename, setfunction, getfunction) \
     40    if (this->getMainStateName() == statename) \
     41    { \
     42        this->functorSetMainState_ = createFunctor(&classname::setfunction)->setObject(this); \
     43        this->functorGetMainState_ = createFunctor(&classname::getfunction)->setObject(this); \
     44    }
    3845
    3946#include <map>
     
    100107            virtual void changedVisibility() {}
    101108
     109            void setMainState(bool state);
     110            bool getMainState() const;
     111
     112            void setMainStateName(const std::string& name);
     113            inline const std::string& getMainStateName() const { return this->mainStateName_; }
     114            virtual void changedMainState();
     115
    102116            /** @brief Sets a pointer to the xml file that loaded this object. @param file The pointer to the XMLFile */
    103117            inline void setFile(const XMLFile* file) { this->file_ = file; }
     
    121135            inline Scene* getScene() const { return this->scene_; }
    122136
    123             inline void setGametype(Gametype* gametype) { this->oldGametype_ = this->gametype_; this->gametype_ = gametype; this->changedGametype(); }
     137            inline void setGametype(Gametype* gametype)
     138            {
     139                if (gametype != this->gametype_)
     140                {
     141                    this->oldGametype_ = this->gametype_;
     142                    this->gametype_ = gametype;
     143                    this->changedGametype();
     144                }
     145            }
    124146            inline Gametype* getGametype() const { return this->gametype_; }
    125147            inline Gametype* getOldGametype() const { return this->oldGametype_; }
    126             virtual inline void changedGametype() {}
     148            virtual void changedGametype() {}
    127149
    128150            void fireEvent();
     
    153175            std::string name_;                          //!< The name of the object
    154176            std::string oldName_;                       //!< The old name of the object
    155             mbool bActive_;                             //!< True = the object is active
    156             mbool bVisible_;                            //!< True = the object is visible
     177            mbool       bActive_;                       //!< True = the object is active
     178            mbool       bVisible_;                      //!< True = the object is visible
     179            std::string mainStateName_;
     180            Functor*    functorSetMainState_;
     181            Functor*    functorGetMainState_;
    157182
    158183        private:
     
    160185            Template* getTemplate(unsigned int index) const;
    161186
    162             bool                  bInitialized_;         //!< True if the object was initialized (passed the object registration)
    163             const XMLFile*        file_;                 //!< The XMLFile that loaded this object
    164             std::string           loaderIndentation_;    //!< Indentation of the debug output in the Loader
    165             Namespace*            namespace_;
    166             BaseObject*           creator_;
    167             Scene*                scene_;
    168             Gametype*             gametype_;
    169             Gametype*             oldGametype_;
    170             std::set<Template*>   templates_;
    171             std::map<BaseObject*, std::string> eventListeners_;
     187            bool                   bInitialized_;         //!< True if the object was initialized (passed the object registration)
     188            const XMLFile*         file_;                 //!< The XMLFile that loaded this object
     189            std::string            loaderIndentation_;    //!< Indentation of the debug output in the Loader
     190            Namespace*             namespace_;
     191            BaseObject*            creator_;
     192            Scene*                 scene_;
     193            Gametype*              gametype_;
     194            Gametype*              oldGametype_;
     195            std::set<Template*>    templates_;
     196            std::map<BaseObject*,  std::string> eventListeners_;
    172197            std::list<BaseObject*> events_;
    173198            std::map<std::string, EventContainer*> eventContainers_;
     
    178203    SUPER_FUNCTION(3, BaseObject, changedVisibility, false);
    179204    SUPER_FUNCTION(4, BaseObject, processEvent, false);
     205    SUPER_FUNCTION(6, BaseObject, changedMainState, false);
     206    SUPER_FUNCTION(9, BaseObject, changedName, false);
     207    SUPER_FUNCTION(10, BaseObject, changedGametype, false);
    180208}
    181209
  • code/branches/presentation/src/core/CommandExecutor.cc

    r1784 r2485  
    5353    }
    5454
    55     ConsoleCommand& CommandExecutor::addConsoleCommandShortcut(ConsoleCommand* command)
     55    ConsoleCommand& CommandExecutor::addConsoleCommandShortcut(ConsoleCommand* command, bool bDeleteAtExit)
    5656    {
    5757        std::map<std::string, ConsoleCommand*>::const_iterator it = CommandExecutor::getInstance().consoleCommandShortcuts_.find(command->getName());
     
    6161        }
    6262
     63        // Make sure we can also delete the external ConsoleCommands that don't belong to an Identifier
     64        if (command && bDeleteAtExit)
     65        {
     66            CommandExecutor::getInstance().consoleCommandExternals_.insert(command);
     67        }
    6368
    6469        CommandExecutor::getInstance().consoleCommandShortcuts_[command->getName()] = command;
     
    647652        }
    648653    }
     654
     655    void CommandExecutor::destroyExternalCommands()
     656    {
     657        for (std::set<ConsoleCommand*>::const_iterator it = CommandExecutor::getInstance().consoleCommandExternals_.begin();
     658            it != CommandExecutor::getInstance().consoleCommandExternals_.end(); ++it)
     659            delete *it;
     660    }
    649661}
  • code/branches/presentation/src/core/CommandExecutor.h

    r1771 r2485  
    5151            static const CommandEvaluation& getLastEvaluation();
    5252
    53             static ConsoleCommand& addConsoleCommandShortcut(ConsoleCommand* command);
     53            static ConsoleCommand& addConsoleCommandShortcut(ConsoleCommand* command, bool bDeleteAtExit = false);
    5454            static ConsoleCommand* getConsoleCommandShortcut(const std::string& name);
    5555            static ConsoleCommand* getLowercaseConsoleCommandShortcut(const std::string& name);
     
    6868            /** @brief Returns a const_iterator to the end of the map that stores all console commands with their names in lowercase. @return The const_iterator */
    6969            static inline std::map<std::string, ConsoleCommand*>::const_iterator getLowercaseConsoleCommandShortcutMapEnd() { return CommandExecutor::getInstance().consoleCommandShortcuts_LC_.end(); }
     70
     71            static void destroyExternalCommands();
    7072
    7173        private:
     
    101103            std::map<std::string, ConsoleCommand*> consoleCommandShortcuts_;
    102104            std::map<std::string, ConsoleCommand*> consoleCommandShortcuts_LC_;
     105            std::set<ConsoleCommand*>              consoleCommandExternals_;
    103106    }; // tolua_export
    104107} // tolua_export
  • code/branches/presentation/src/core/CommandLine.cc

    r2105 r2485  
    8383    CommandLine::~CommandLine()
    8484    {
    85         for (std::map<std::string, CommandLineArgument*>::const_iterator it = cmdLineArgs_.begin();
    86             it != cmdLineArgs_.end(); ++it)
    87         {
    88             delete it->second;
    89         }
     85        CommandLine::destroyAllArguments();
    9086    }
    9187
     
    9894        static CommandLine instance;
    9995        return instance;
     96    }
     97
     98    /**
     99    @brief
     100        Destroys all command line arguments. This should be called at the end
     101        of main. Do not use before that.
     102    */
     103    void CommandLine::destroyAllArguments()
     104    {
     105        for (std::map<std::string, CommandLineArgument*>::const_iterator it = _getInstance().cmdLineArgs_.begin();
     106            it != _getInstance().cmdLineArgs_.end(); ++it)
     107            delete it->second;
     108        _getInstance().cmdLineArgs_.clear();
    100109    }
    101110
  • code/branches/presentation/src/core/CommandLine.h

    r2103 r2485  
    155155        }
    156156
     157        static void destroyAllArguments();
    157158
    158159    private:
     
    179180        //! Holds all pointers to the arguments and serves as a search map by name.
    180181        std::map<std::string, CommandLineArgument*> cmdLineArgs_;
    181         //! Search map by chortcut for the arguments.
     182        //! Search map by shortcut for the arguments.
    182183        std::map<std::string, CommandLineArgument*> cmdLineArgsShortcut_;
    183184    };
  • code/branches/presentation/src/core/ConsoleCommand.h

    r2087 r2485  
    6464
    6565#define SetConsoleCommandShortcutGeneric(fakevariable, command) \
    66     orxonox::ConsoleCommand& fakevariable = orxonox::CommandExecutor::addConsoleCommandShortcut(command)
     66    orxonox::ConsoleCommand& fakevariable = orxonox::CommandExecutor::addConsoleCommandShortcut(command, true)
    6767
    6868
  • code/branches/presentation/src/core/Core.cc

    r2171 r2485  
    4646    bool Core::bIsMaster_s      = false;
    4747
     48    Core* Core::singletonRef_s = 0;
     49
    4850    /**
    4951        @brief Constructor: Registers the object and sets the config-values.
     
    5355    {
    5456        RegisterRootObject(Core);
     57
     58        assert(Core::singletonRef_s == 0);
     59        Core::singletonRef_s = this;
     60        this->bInitializeRandomNumberGenerator_ = false;
     61
    5562        this->setConfigValues();
    56         isCreatingCoreSettings() = false;
    5763    }
    5864
     
    6268    Core::~Core()
    6369    {
    64         isCreatingCoreSettings() = true;
    65     }
    66 
    67     /**
    68         @brief Returns true if the Core instance is not yet ready and the static functions have to return a default value.
    69     */
    70     bool& Core::isCreatingCoreSettings()
    71     {
    72         static bool bCreatingCoreSettings = true;
    73         return bCreatingCoreSettings;
    74     }
    75 
    76     /**
    77         @brief Returns a unique instance of Core.
    78         @return The instance
    79     */
    80     Core& Core::getInstance()
    81     {
    82         // If bCreatingSoftDebugLevelObject is true, we're just about to create an instance of the DebugLevel class
    83         //if (Core::isCreatingCoreSettings())
    84         //{
    85         //    isCreatingCoreSettings() = false;
    86         //    //instance.setConfigValues();
    87         //}
    88 
    89         static bool firstTime = true;
    90         if (firstTime)
    91             isCreatingCoreSettings() = true;
    92 
    93         static Core instance;
    94         return instance;
     70        assert(Core::singletonRef_s);
     71        Core::singletonRef_s = 0;
    9572    }
    9673
     
    10481        SetConfigValue(softDebugLevelShell_, 1).description("The maximal level of debug output shown in the ingame shell").callback(this, &Core::debugLevelChanged);
    10582        SetConfigValue(language_, Language::getLanguage().defaultLanguage_).description("The language of the ingame text").callback(this, &Core::languageChanged);
     83        SetConfigValue(bInitializeRandomNumberGenerator_, true).description("If true, all random actions are different each time you start the game").callback(this, &Core::initializeRandomNumberGenerator);
    10684    }
    10785
     
    140118    int Core::getSoftDebugLevel(OutputHandler::OutputDevice device)
    141119    {
    142         if (!Core::isCreatingCoreSettings())
     120        switch (device)
    143121        {
    144             switch (device)
    145             {
    146             case OutputHandler::LD_All:
    147                 return Core::getInstance().softDebugLevel_;
    148             case OutputHandler::LD_Console:
    149                 return Core::getInstance().softDebugLevelConsole_;
    150             case OutputHandler::LD_Logfile:
    151                 return Core::getInstance().softDebugLevelLogfile_;
    152             case OutputHandler::LD_Shell:
    153                 return Core::getInstance().softDebugLevelShell_;
    154             default:
    155                 assert(0);
    156             }
     122        case OutputHandler::LD_All:
     123            return Core::getInstance().softDebugLevel_;
     124        case OutputHandler::LD_Console:
     125            return Core::getInstance().softDebugLevelConsole_;
     126        case OutputHandler::LD_Logfile:
     127            return Core::getInstance().softDebugLevelLogfile_;
     128        case OutputHandler::LD_Shell:
     129            return Core::getInstance().softDebugLevelShell_;
     130        default:
     131            assert(0);
     132            return 2;
    157133        }
    158 
    159         // Return a constant value while we're creating the object
    160         return 2;
    161134    }
    162135
     
    168141     void Core::setSoftDebugLevel(OutputHandler::OutputDevice device, int level)
    169142     {
    170         if (!Core::isCreatingCoreSettings())
    171         {
    172             if (device == OutputHandler::LD_All)
    173                 Core::getInstance().softDebugLevel_ = level;
    174             else if (device == OutputHandler::LD_Console)
    175                 Core::getInstance().softDebugLevelConsole_ = level;
    176             else if (device == OutputHandler::LD_Logfile)
    177                 Core::getInstance().softDebugLevelLogfile_ = level;
    178             else if (device == OutputHandler::LD_Shell)
    179                 Core::getInstance().softDebugLevelShell_ = level;
     143        if (device == OutputHandler::LD_All)
     144            Core::getInstance().softDebugLevel_ = level;
     145        else if (device == OutputHandler::LD_Console)
     146            Core::getInstance().softDebugLevelConsole_ = level;
     147        else if (device == OutputHandler::LD_Logfile)
     148            Core::getInstance().softDebugLevelLogfile_ = level;
     149        else if (device == OutputHandler::LD_Shell)
     150            Core::getInstance().softDebugLevelShell_ = level;
    180151
    181             OutputHandler::setSoftDebugLevel(device, level);
    182         }
     152        OutputHandler::setSoftDebugLevel(device, level);
    183153     }
    184154
     
    188158    const std::string& Core::getLanguage()
    189159    {
    190         if (!Core::isCreatingCoreSettings())
    191             return Core::getInstance().language_;
    192 
    193         return Language::getLanguage().defaultLanguage_;
     160        return Core::getInstance().language_;
    194161    }
    195162
     
    209176        ResetConfigValue(language_);
    210177    }
     178
     179    void Core::initializeRandomNumberGenerator()
     180    {
     181        static bool bInitialized = false;
     182        if (!bInitialized && this->bInitializeRandomNumberGenerator_)
     183        {
     184            srand(time(0));
     185            rand();
     186            bInitialized = true;
     187        }
     188    }
    211189}
  • code/branches/presentation/src/core/Core.h

    r2171 r2485  
    4040#include "CorePrereqs.h"
    4141
     42#include <cassert>
    4243#include "OrxonoxClass.h"
    4344#include "util/OutputHandler.h"
     
    4950    {
    5051        public:
    51             static Core& getInstance();
    52             static bool& isCreatingCoreSettings();
     52            Core();
     53            ~Core();
    5354            void setConfigValues();
    5455            void debugLevelChanged();
    5556            void languageChanged();
    5657
    57             static int getSoftDebugLevel(OutputHandler::OutputDevice device = OutputHandler::LD_All);
    58             static void setSoftDebugLevel(OutputHandler::OutputDevice device, int level);
     58            static Core& getInstance() { assert(Core::singletonRef_s); return *Core::singletonRef_s; }
     59
     60            static int   getSoftDebugLevel(OutputHandler::OutputDevice device = OutputHandler::LD_All);
     61            static void  setSoftDebugLevel(OutputHandler::OutputDevice device, int level);
    5962            static const std::string& getLanguage();
    60             static void resetLanguage();
     63            static void  resetLanguage();
    6164
    6265            // fast access global variables.
     
    7376
    7477        private:
     78            Core(const Core&);
    7579            void resetLanguageIntern();
    76 
    77             Core();
    78             Core(const Core& other);
    79             virtual ~Core();
     80            void initializeRandomNumberGenerator();
    8081
    8182            int softDebugLevel_;                            //!< The debug level
     
    8485            int softDebugLevelShell_;                       //!< The debug level for the ingame shell
    8586            std::string language_;                          //!< The language
     87            bool bInitializeRandomNumberGenerator_;          //!< If true, srand(time(0)) is called
    8688
    8789            static bool bShowsGraphics_s;                   //!< global variable that tells whether to show graphics
     
    9092            static bool bIsStandalone_s;
    9193            static bool bIsMaster_s;
     94
     95            static Core* singletonRef_s;
    9296    };
    9397}
  • code/branches/presentation/src/core/CorePrereqs.h

    r2087 r2485  
    6969    {
    7070      LoadObject,
    71       SaveObject
     71      SaveObject,
     72      ExpandObject
    7273    };
    7374  }
     
    132133  class LanguageEntry;
    133134  class Loader;
     135  class LuaBind;
    134136  class MetaObjectList;
    135137  class MetaObjectListElement;
  • code/branches/presentation/src/core/Functor.h

    r2087 r2485  
    167167            }
    168168
    169             FunctorMember* setObject(T* object)
     169            FunctorMember<T>* setObject(T* object)
    170170            {
    171171                this->bConstObject_ = false;
     
    174174            }
    175175
    176             FunctorMember* setObject(const T* object)
     176            FunctorMember<T>* setObject(const T* object)
    177177            {
    178178                this->bConstObject_ = true;
  • code/branches/presentation/src/core/Identifier.cc

    r2371 r2485  
    9393        for (std::map<std::string, XMLPortObjectContainer*>::iterator it = this->xmlportObjectContainers_.begin(); it != this->xmlportObjectContainers_.end(); ++it)
    9494            delete (it->second);
     95        for (std::vector<Functor*>::iterator it = this->constructionCallbacks_.begin(); it != this->constructionCallbacks_.end(); ++it)
     96            delete *it;
     97    }
     98
     99    /**
     100        @brief Returns the identifier map with the names as received by typeid(). This is only used internally.
     101    */
     102    std::map<std::string, Identifier*>& Identifier::getTypeIDIdentifierMap()
     103    {
     104        static std::map<std::string, Identifier*> identifiers;    //!< The map to store all Identifiers.
     105        return identifiers;
    95106    }
    96107
     
    103114    Identifier* Identifier::getIdentifierSingleton(const std::string& name, Identifier* proposal)
    104115    {
    105         static std::map<std::string, Identifier*> identifiers;    //!< The map to store all Identifiers.
    106         std::map<std::string, Identifier*>::const_iterator it = identifiers.find(name);
    107 
    108         if (it != identifiers.end())
     116        std::map<std::string, Identifier*>::const_iterator it = getTypeIDIdentifierMap().find(name);
     117
     118        if (it != getTypeIDIdentifierMap().end())
    109119        {
    110120            // There is already an entry: return it and delete the proposal
     
    115125        {
    116126            // There is no entry: put the proposal into the map and return it
    117             identifiers[name] = proposal;
     127            getTypeIDIdentifierMap()[name] = proposal;
    118128            return proposal;
    119129        }
     
    192202    void Identifier::destroyAllIdentifiers()
    193203    {
    194         for (std::map<std::string, Identifier*>::iterator it = Identifier::getIdentifierMapIntern().begin(); it != Identifier::getIdentifierMapIntern().end(); ++it)
     204        for (std::map<std::string, Identifier*>::iterator it = Identifier::getTypeIDIdentifierMap().begin(); it != Identifier::getTypeIDIdentifierMap().end(); ++it)
    195205            delete (it->second);
    196206    }
  • code/branches/presentation/src/core/Identifier.h

    r2371 r2485  
    258258            void initializeClassHierarchy(std::set<const Identifier*>* parents, bool bRootClass);
    259259
     260            static void destroyAllIdentifiers();
     261
    260262        protected:
    261263            Identifier();
     
    300302            }
    301303
     304            static std::map<std::string, Identifier*>& getTypeIDIdentifierMap();
     305
    302306            void initialize(std::set<const Identifier*>* parents);
    303 
    304             static void destroyAllIdentifiers();
    305307
    306308            std::set<const Identifier*> parents_;                          //!< The parents of the class the Identifier belongs to
  • code/branches/presentation/src/core/Language.cc

    r2171 r2485  
    8787    // ###        Language         ###
    8888    // ###############################
     89
     90    Language* Language::singletonRef_s = 0;
     91
    8992    /**
    9093        @brief Constructor: Reads the default language file and sets some values.
     
    9295    Language::Language()
    9396    {
     97        assert(singletonRef_s == 0);
     98        singletonRef_s = this;
     99
    94100        this->defaultLanguage_ = "default";
    95101        this->defaultLocalisation_ = "ERROR: LANGUAGE ENTRY DOESN'T EXIST!";
     
    106112        for (std::map<std::string, LanguageEntry*>::iterator it = this->languageEntries_.begin(); it != this->languageEntries_.end(); ++it)
    107113            delete (it->second);
    108     }
    109 
    110     /**
    111         @brief Returns a reference to the only existing instance of the Language class and calls the setConfigValues() function.
    112         @return The reference to the only existing instance
    113     */
    114     Language& Language::getLanguage()
    115     {
    116         static Language instance = Language();
    117         return instance;
     114
     115        assert(singletonRef_s);
     116        singletonRef_s = 0;
    118117    }
    119118
  • code/branches/presentation/src/core/Language.h

    r2171 r2485  
    5050#include <map>
    5151#include <string>
     52#include <cassert>
    5253
    5354#define AddLanguageEntry(label, fallbackstring) \
     
    116117
    117118        public:
    118             static Language& getLanguage();
     119            Language();
     120            ~Language();
     121
     122            static Language& getLanguage() { assert(singletonRef_s); return *singletonRef_s; }
    119123            void addEntry(const LanguageEntryLabel& label, const std::string& entry);
    120124            const std::string& getLocalisation(const LanguageEntryLabel& label) const;
    121125
    122126        private:
    123             Language();
    124             Language(const Language& language);     // don't copy
    125             virtual ~Language();
     127            Language(const Language&);
    126128
    127129            void readDefaultLanguageFile();
     
    134136            std::string defaultLocalisation_;                       //!< The returned string, if an entry unavailable entry is requested
    135137            std::map<std::string, LanguageEntry*> languageEntries_; //!< A map to store all LanguageEntry objects and their labels
     138
     139            static Language* singletonRef_s;
    136140    };
    137141}
  • code/branches/presentation/src/core/Loader.cc

    r2171 r2485  
    120120
    121121        // let Lua work this out:
    122         LuaBind* lua = LuaBind::getInstance();
    123         lua->clearLuaOutput();
    124         lua->loadFile(file->getFilename(), true);
    125         lua->run();
     122        LuaBind& lua = LuaBind::getInstance();
     123        lua.clearLuaOutput();
     124        lua.loadFile(file->getFilename(), true);
     125        lua.run();
    126126
    127127        try
     
    135135            ticpp::Document xmlfile;
    136136            //xmlfile.ToDocument();
    137             xmlfile.Parse(lua->getLuaOutput(), true);
     137            xmlfile.Parse(lua.getLuaOutput(), true);
    138138
    139139            ticpp::Element rootElement;
  • code/branches/presentation/src/core/LuaBind.cc

    r2087 r2485  
    4040namespace orxonox
    4141{
    42   LuaBind* LuaBind::singletonRef = NULL;
     42  LuaBind* LuaBind::singletonRef_s = NULL;
    4343
    4444  LuaBind::LuaBind()
    4545  {
     46    assert(LuaBind::singletonRef_s == 0);
     47    LuaBind::singletonRef_s = this;
     48
    4649    luaState_ = lua_open();
    4750    luaSource_ = "";
  • code/branches/presentation/src/core/LuaBind.h

    r2087 r2485  
    4242}
    4343
     44#include <cassert>
    4445#include <list>
    4546#include <string>
     
    5859
    5960    public:
    60       inline static LuaBind* getInstance() { if (!LuaBind::singletonRef) LuaBind::singletonRef = new LuaBind(); return LuaBind::singletonRef; } // tolua_export
    61       inline ~LuaBind() { LuaBind::singletonRef = NULL; };
     61      LuaBind();
     62      inline ~LuaBind() { assert(singletonRef_s); LuaBind::singletonRef_s = NULL; };
     63
     64      inline static LuaBind& getInstance() { assert(singletonRef_s); return *LuaBind::singletonRef_s; } // tolua_export
    6265
    6366    void loadFile(std::string filename, bool luaTags);
     
    8386
    8487    private:
    85       LuaBind();
    86       static LuaBind* singletonRef;
     88      static LuaBind* singletonRef_s;
    8789
    8890      std::string luaSource_;
  • code/branches/presentation/src/core/RootGameState.cc

    r2459 r2485  
    3131#include "util/Debug.h"
    3232#include "util/Exception.h"
    33 #include "Core.h"
    3433#include "Clock.h"
    3534#include "CommandLine.h"
     
    138137            Clock clock;
    139138
    140             // create the Core settings to configure the output level
    141             Core::getInstance();
    142 
    143139            this->activate();
    144140
  • code/branches/presentation/src/core/RootGameState.h

    r2103 r2485  
    4848        void gotoState(const std::string& name);
    4949
    50         std::string           stateRequest_;
     50        std::string stateRequest_;
    5151    };
    5252}
  • code/branches/presentation/src/core/Shell.cc

    r1792 r2485  
    7575
    7676        this->outputBuffer_.registerListener(this);
    77         OutputHandler::getOutStream().setOutputBuffer(this->outputBuffer_);
     77        OutputHandler::getOutStream().setOutputBuffer(&this->outputBuffer_);
    7878
    7979        this->setConfigValues();
     
    8484    Shell::~Shell()
    8585    {
     86        OutputHandler::getOutStream().setOutputBuffer(0);
    8687        if (this->inputBuffer_)
    8788            delete this->inputBuffer_;
  • code/branches/presentation/src/core/Super.h

    r2171 r2485  
    9999            \
    100100            static void apply(void* temp) {} \
     101            \
    101102            static void apply(baseclass* temp) \
    102103            { \
     
    104105                for (std::set<const Identifier*>::iterator it = identifier->getDirectChildrenIntern().begin(); it != identifier->getDirectChildrenIntern().end(); ++it) \
    105106                { \
     107                    if (((ClassIdentifier<T>*)(*it))->bSuperFunctionCaller_##functionname##_isFallback_ && ((ClassIdentifier<T>*)(*it))->superFunctionCaller_##functionname##_) \
     108                    { \
     109                        delete ((ClassIdentifier<T>*)(*it))->superFunctionCaller_##functionname##_; \
     110                        ((ClassIdentifier<T>*)(*it))->superFunctionCaller_##functionname##_ = 0; \
     111                        ((ClassIdentifier<T>*)(*it))->bSuperFunctionCaller_##functionname##_isFallback_ = false; \
     112                    } \
     113                    \
    106114                    if (!((ClassIdentifier<T>*)(*it))->superFunctionCaller_##functionname##_) \
    107115                    { \
     
    163171                for (std::set<const Identifier*>::iterator it = identifier->getDirectChildrenIntern().begin(); it != identifier->getDirectChildrenIntern().end(); ++it)
    164172                {
     173                    // Check if the caller is a fallback-caller
     174                    if (((ClassIdentifier<T>*)(*it))->bSuperFunctionCaller_##functionname##_isFallback_ && ((ClassIdentifier<T>*)(*it))->superFunctionCaller_##functionname##_)
     175                    {
     176                        // Delete the fallback caller an prepare to get a real caller
     177                        delete ((ClassIdentifier<T>*)(*it))->superFunctionCaller_##functionname##_;
     178                        ((ClassIdentifier<T>*)(*it))->superFunctionCaller_##functionname##_ = 0;
     179                        ((ClassIdentifier<T>*)(*it))->bSuperFunctionCaller_##functionname##_isFallback_ = false;
     180                    }
     181
    165182                    // Check if there's not already a caller
    166183                    if (!((ClassIdentifier<T>*)(*it))->superFunctionCaller_##functionname##_)
     
    183200        struct SuperFunctionCondition<functionnumber, baseclass, 0, templatehack2> \
    184201        { \
    185             // The check function just behaves like the fallback - it advances to the check for the next super-function (functionnumber + 1)
     202            // The check function acts like the fallback - it advances to the check for the next super-function (functionnumber + 1)
    186203            static void check() \
    187204            { \
     
    233250    #define SUPER_processEvent(classname, functionname, ...) \
    234251        SUPER_ARGS(classname, functionname, __VA_ARGS__)
     252
     253    #define SUPER_changedScale(classname, functionname, ...) \
     254        SUPER_NOARGS(classname, functionname)
     255
     256    #define SUPER_changedMainState(classname, functionname, ...) \
     257        SUPER_NOARGS(classname, functionname)
     258
     259    #define SUPER_changedOwner(classname, functionname, ...) \
     260        SUPER_NOARGS(classname, functionname)
     261
     262    #define SUPER_changedOverlayGroup(classname, functionname, ...) \
     263        SUPER_NOARGS(classname, functionname)
     264
     265    #define SUPER_changedName(classname, functionname, ...) \
     266        SUPER_NOARGS(classname, functionname)
     267
     268    #define SUPER_changedGametype(classname, functionname, ...) \
     269        SUPER_NOARGS(classname, functionname)
    235270    // (1/3) --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <--
    236271
     
    292327            }; \
    293328            \
     329            class _CoreExport SuperFunctionCaller_##functionname \
     330            { \
     331                public: \
     332                    virtual void operator()( SUPER_CALL_ARGUMENTS##hasarguments(__VA_ARGS__) ) = 0; \
     333                    virtual ~SuperFunctionCaller_##functionname () {} \
     334            }; \
     335            \
     336            template <class T> \
     337            class SuperFunctionClassCaller_purevirtualfallback_##functionname : public SuperFunctionCaller_##functionname \
     338            { \
     339                public: \
     340                    inline void operator()( SUPER_CALL_ARGUMENTS##hasarguments(__VA_ARGS__) ) \
     341                    { \
     342                    } \
     343            }; \
     344            \
    294345            template <class T> \
    295346            struct SuperFunctionInitialization<functionnumber, T> \
     
    297348                static void initialize(ClassIdentifier<T>* identifier) \
    298349                { \
    299                     identifier->superFunctionCaller_##functionname##_ = 0; \
     350                    identifier->superFunctionCaller_##functionname##_ = new SuperFunctionClassCaller_purevirtualfallback_##functionname <T>; \
     351                    identifier->bSuperFunctionCaller_##functionname##_isFallback_ = true; \
    300352                    SuperFunctionInitialization<functionnumber + 1, T>::initialize(identifier); \
    301353                } \
     
    313365            }; \
    314366            \
    315             class _CoreExport SuperFunctionCaller_##functionname \
    316             { \
    317                 public: \
    318                     virtual void operator()( SUPER_CALL_ARGUMENTS##hasarguments(__VA_ARGS__) ) = 0; \
    319                     virtual ~SuperFunctionCaller_##functionname () {} \
    320             }; \
    321             \
    322367            template <class T> \
    323368            class SuperFunctionClassCaller_##functionname : public SuperFunctionCaller_##functionname \
     
    366411        };
    367412
    368         // Initializes the SuperFunctionCaller-pointer with zero.
     413        // Baseclass of the super-function caller. The real call will be done by a
     414        // templatized subclass through the virtual () operator.
     415        class _CoreExport SuperFunctionCaller_##functionname
     416        {
     417            public:
     418                virtual void operator()( SUPER_CALL_ARGUMENTS##hasarguments(__VA_ARGS__) ) = 0;
     419                virtual ~SuperFunctionCaller_##functionname () {}
     420        };
     421
     422        // Fallback if the base is pure virtual
     423        template <class T>
     424        class SuperFunctionClassCaller_purevirtualfallback_##functionname : public SuperFunctionCaller_##functionname
     425        {
     426            public:
     427                // Fallback does nothing
     428                inline void operator()( SUPER_CALL_ARGUMENTS##hasarguments(__VA_ARGS__) )
     429                {
     430                }
     431        };
     432
     433        // Initializes the SuperFunctionCaller-pointer with a fallback caller in case the base function is pure virtual
    369434        template <class T>
    370435        struct SuperFunctionInitialization<functionnumber, T>
     
    372437            static void initialize(ClassIdentifier<T>* identifier)
    373438            {
    374                 identifier->superFunctionCaller_##functionname##_ = 0;
     439                identifier->superFunctionCaller_##functionname##_ = new SuperFunctionClassCaller_purevirtualfallback_##functionname <T>;
     440                identifier->bSuperFunctionCaller_##functionname##_isFallback_ = true;
    375441
    376442                // Calls the initialization of the next super-function (functionnumber + 1)
     
    391457                SuperFunctionDestruction<functionnumber + 1, T>::destroy(identifier);
    392458            }
    393         };
    394 
    395         // Baseclass of the super-function caller. The real call will be done by a
    396         // templatized subclass through the virtual () operator.
    397         class _CoreExport SuperFunctionCaller_##functionname
    398         {
    399             public:
    400                 virtual void operator()( SUPER_CALL_ARGUMENTS##hasarguments(__VA_ARGS__) ) = 0;
    401                 virtual ~SuperFunctionCaller_##functionname () {}
    402459        };
    403460
     
    441498            (event)
    442499        SUPER_FUNCTION_GLOBAL_DECLARATION_PART2;
     500
     501        SUPER_FUNCTION_GLOBAL_DECLARATION_PART1(5, changedScale, false)
     502            ()
     503        SUPER_FUNCTION_GLOBAL_DECLARATION_PART2;
     504
     505        SUPER_FUNCTION_GLOBAL_DECLARATION_PART1(6, changedMainState, false)
     506            ()
     507        SUPER_FUNCTION_GLOBAL_DECLARATION_PART2;
     508
     509        SUPER_FUNCTION_GLOBAL_DECLARATION_PART1(7, changedOwner, false)
     510            ()
     511        SUPER_FUNCTION_GLOBAL_DECLARATION_PART2;
     512
     513        SUPER_FUNCTION_GLOBAL_DECLARATION_PART1(8, changedOverlayGroup, false)
     514            ()
     515        SUPER_FUNCTION_GLOBAL_DECLARATION_PART2;
     516
     517        SUPER_FUNCTION_GLOBAL_DECLARATION_PART1(9, changedName, false)
     518            ()
     519        SUPER_FUNCTION_GLOBAL_DECLARATION_PART2;
     520
     521        SUPER_FUNCTION_GLOBAL_DECLARATION_PART1(10, changedGametype, false)
     522            ()
     523        SUPER_FUNCTION_GLOBAL_DECLARATION_PART2;
    443524        // (2/3) --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <--
    444525
     
    476557        #ifndef SUPER_INTRUSIVE_DECLARATION
    477558          #define SUPER_INTRUSIVE_DECLARATION(functionname) \
    478             SuperFunctionCaller_##functionname * superFunctionCaller_##functionname##_
     559            SuperFunctionCaller_##functionname * superFunctionCaller_##functionname##_; \
     560            bool bSuperFunctionCaller_##functionname##_isFallback_
    479561        #endif
    480562
     
    488570    SUPER_INTRUSIVE_DECLARATION(changedVisibility);
    489571    SUPER_INTRUSIVE_DECLARATION(processEvent);
     572    SUPER_INTRUSIVE_DECLARATION(changedScale);
     573    SUPER_INTRUSIVE_DECLARATION(changedMainState);
     574    SUPER_INTRUSIVE_DECLARATION(changedOwner);
     575    SUPER_INTRUSIVE_DECLARATION(changedOverlayGroup);
     576    SUPER_INTRUSIVE_DECLARATION(changedName);
     577    SUPER_INTRUSIVE_DECLARATION(changedGametype);
    490578    // (3/3) --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <--
    491579
  • code/branches/presentation/src/core/Template.cc

    r2459 r2485  
    4343
    4444        this->bIsLink_ = false;
     45        this->bLoadDefaults_ = true;
    4546        this->bIsReturningXMLElement_ = false;
    4647        this->baseclassIdentifier_ = 0;
     
    5657        SUPER(Template, XMLPort, xmlelement, mode);
    5758
    58         XMLPortParam(Template, "link", setLink, getLink, xmlelement, mode);
    59         XMLPortParam(Template, "baseclass", setBaseclass, getBaseclass, xmlelement, mode);
     59        XMLPortParam(Template, "link",      setLink,         getLink,         xmlelement, mode);
     60        XMLPortParam(Template, "baseclass", setBaseclass,    getBaseclass,    xmlelement, mode);
     61        XMLPortParam(Template, "defaults",  setLoadDefaults, getLoadDefaults, xmlelement, mode).defaultValues(true);
    6062
    6163        Element* element = xmlelement.FirstChildElement(false);
     
    7072    void Template::changedName()
    7173    {
     74        SUPER(Template, changedName);
     75
    7276        if (this->getName() != "")
    7377        {
     
    134138
    135139        Element temp = ((TiXmlElement*)&this->getXMLElement());
    136         object->XMLPort(temp, XMLPort::LoadObject);
     140
     141        if (this->bLoadDefaults_)
     142            object->XMLPort(temp, XMLPort::LoadObject);
     143        else
     144            object->XMLPort(temp, XMLPort::ExpandObject);
    137145    }
    138146
  • code/branches/presentation/src/core/Template.h

    r2459 r2485  
    5353                { return this->link_; }
    5454
     55            inline void setLoadDefaults(bool bLoadDefaults)
     56                { this->bLoadDefaults_ = bLoadDefaults; }
     57            inline bool getLoadDefaults() const
     58                { return this->bLoadDefaults_; }
     59
    5560            inline void setXMLElement(const TiXmlElement& xmlelement)
    5661                { this->xmlelement_ = xmlelement; }
     
    7580            Identifier* baseclassIdentifier_;
    7681            bool bIsLink_;
     82            bool bLoadDefaults_;
    7783            mutable bool bIsReturningXMLElement_;
    7884    };
  • code/branches/presentation/src/core/XMLFile.h

  • code/branches/presentation/src/core/XMLIncludes.h

    • Property svn:mergeinfo changed (with no actual effect on merging)
  • code/branches/presentation/src/core/XMLPort.h

    r2459 r2485  
    4343#include "CorePrereqs.h"
    4444
     45#include <cassert>
    4546#include "util/Debug.h"
    4647#include "util/Exception.h"
     
    369370            }
    370371
     372            ~XMLPortClassParamContainer()
     373            {
     374                assert(this->loadexecutor_);
     375                delete this->loadexecutor_;
     376                if (this->saveexecutor_)
     377                    delete this->saveexecutor_;
     378            }
     379
    371380            XMLPortParamContainer& port(BaseObject* owner, T* object, Element& xmlelement, XMLPort::Mode mode)
    372381            {
     
    376385                this->parseParams_.mode = mode;
    377386
    378                 if (mode == XMLPort::LoadObject)
     387                if ((mode == XMLPort::LoadObject) || (mode == XMLPort::ExpandObject))
    379388                {
    380389                    try
    381390                    {
    382391                        std::string attribute = xmlelement.GetAttribute(this->paramname_);
    383                         if ((attribute.size() > 0) || (this->loadexecutor_->allDefaultValuesSet()))
     392                        if ((attribute.size() > 0) || ((mode != XMLPort::ExpandObject) && this->loadexecutor_->allDefaultValuesSet()))
    384393                        {
    385394                            COUT(5) << this->owner_->getLoaderIndentation() << "Loading parameter " << this->paramname_ << " in " << this->identifier_->getName() << " (objectname " << this->owner_->getName() << ")." << std::endl << this->owner_->getLoaderIndentation();
    386                             if (this->loadexecutor_->parse(object, attribute, ","))
     395                            if (this->loadexecutor_->parse(object, attribute, ",") || (mode  == XMLPort::ExpandObject))
    387396                                this->parseResult_ = PR_finished;
    388397                            else
    389398                                this->parseResult_ = PR_waiting_for_default_values;
    390399                        }
     400                        else if (mode == XMLPort::ExpandObject)
     401                            this->parseResult_ = PR_finished;
    391402                        else
    392403                            this->parseResult_ = PR_waiting_for_default_values;
     
    511522            }
    512523
     524            ~XMLPortClassObjectContainer()
     525            {
     526                assert(this->loadexecutor_);
     527                delete this->loadexecutor_;
     528                if (this->saveexecutor_)
     529                    delete this->saveexecutor_;
     530            }
     531
    513532            XMLPortObjectContainer& port(T* object, Element& xmlelement, XMLPort::Mode mode)
    514533            {
    515                 if (mode == XMLPort::LoadObject)
     534                if ((mode == XMLPort::LoadObject) || (mode == XMLPort::ExpandObject))
    516535                {
    517536                    try
  • code/branches/presentation/src/core/input/Button.cc

    r2103 r2485  
    5959        nCommands_[1]=0;
    6060        nCommands_[2]=0;
     61        this->configContainer_ = 0;
    6162        clear();
    6263    }
     
    8081            }
    8182        }
     83
     84        if (this->configContainer_)
     85            delete this->configContainer_;
     86        this->configContainer_ = 0;
    8287    }
    8388
  • code/branches/presentation/src/core/input/InputBuffer.cc

    r1755 r2485  
    7373    }
    7474
     75    InputBuffer::~InputBuffer()
     76    {
     77        for (std::list<BaseInputBufferListenerTuple*>::const_iterator it = this->listeners_.begin();
     78            it != this->listeners_.end(); ++it)
     79            delete *it;
     80    }
     81
    7582    void InputBuffer::setConfigValues()
    7683    {
  • code/branches/presentation/src/core/input/InputBuffer.h

    r1887 r2485  
    7979        public:
    8080            InputBuffer();
     81            ~InputBuffer();
    8182            InputBuffer(const std::string allowedChars);
    8283
Note: See TracChangeset for help on using the changeset viewer.