Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Jul 23, 2008, 3:37:29 PM (16 years ago)
Author:
rgrieder
Message:
  • changed the static interface of the InputManager to a member one with getInstance()
  • converted InputManager and InGameConsole to Ogre Singletons (c'tor and d'tor public, but assert in c'tor to prevent multiple instances at runtime)
  • added toluabind_orxonox files to tolua folder that contains a pimped version of tolua (I'll write a little cmake project soon to automate it; Currently that only works with msvc)
  • commented out Loader::unload() from Orxonox destructor because that deleted the ParticleSpawners, which were using a method of a sceneNode that belonged to a already destroyed SpaceShip. —> Results in a memory leak. Previously Loader::unload() was called for all BaseObjects (now calling unload(level_)). And since 'P' from ParticleSpawner comes before 'S' like SpaceShip, the order was correct.
  • Added factory feature for InputStates (can now be created by string if there is Factory entry for it)
  • Created factory entries for SimpleInputState and ExtendedInputState
Location:
code/branches/gui/src/orxonox/overlays/console
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • code/branches/gui/src/orxonox/overlays/console/InGameConsole.cc

    r1641 r1642  
    5858    SetConsoleCommand(InGameConsole, closeConsole, true);
    5959
     60    InGameConsole* InGameConsole::singletonRef_s = 0;
     61
    6062    /**
    6163        @brief Constructor: Creates and initializes the InGameConsole.
     
    7173        RegisterObject(InGameConsole);
    7274
     75        assert(singletonRef_s == 0);
     76        singletonRef_s = this;
     77
    7378        this->bActive_ = false;
    7479        this->cursor_ = 0.0f;
     
    8792    InGameConsole::~InGameConsole(void)
    8893    {
    89         this->destroy();
    90     }
    91 
    92     /**
    93         @brief Returns a reference to the only existing instance of InGameConsole.
    94     */
    95     InGameConsole& InGameConsole::getInstance()
    96     {
    97         static InGameConsole instance;
    98         return instance;
    99     }
    100 
    101     /**
    102         @brief Sets the config values, describing the size of the console.
    103     */
    104     void InGameConsole::setConfigValues()
    105     {
    106         SetConfigValue(relativeWidth, 0.8);
    107         SetConfigValue(relativeHeight, 0.4);
    108         SetConfigValue(blinkTime, 0.5);
    109         SetConfigValue(scrollSpeed_, 3.0f);
    110         SetConfigValue(noiseSize_, 1.0f);
    111         SetConfigValue(cursorSymbol_, '|');
    112     }
    113 
    114     /**
    115         @brief Initializes the InGameConsole.
    116     */
    117     void InGameConsole::initialise()
    118     {
    119         // create the corresponding input state
    120         InputManager::createSimpleInputState("console", 40)->setKeyHandler(Shell::getInstance().getInputBuffer());
    121 
    122         // create overlay and elements
    123         Ogre::OverlayManager* ovMan = Ogre::OverlayManager::getSingletonPtr();
    124 
    125         // create actual overlay
    126         this->consoleOverlay_ = ovMan->create("InGameConsoleConsole");
    127 
    128         // create a container
    129         this->consoleOverlayContainer_ = static_cast<Ogre::OverlayContainer*>(ovMan->createOverlayElement("Panel", "InGameConsoleContainer"));
    130         this->consoleOverlayContainer_->setMetricsMode(Ogre::GMM_RELATIVE);
    131         this->consoleOverlayContainer_->setPosition((1 - this->relativeWidth) / 2, 0);
    132         this->consoleOverlayContainer_->setDimensions(this->relativeWidth, this->relativeHeight);
    133         this->consoleOverlay_->add2D(this->consoleOverlayContainer_);
    134 
    135         // create BorderPanel
    136         this->consoleOverlayBorder_ = static_cast<Ogre::BorderPanelOverlayElement*>(ovMan->createOverlayElement("BorderPanel", "InGameConsoleBorderPanel"));
    137         this->consoleOverlayBorder_->setMetricsMode(Ogre::GMM_PIXELS);
    138         this->consoleOverlayBorder_->setMaterialName("ConsoleCenter");
    139         this->consoleOverlayBorder_->setBorderSize(16, 16, 0, 16);
    140         this->consoleOverlayBorder_->setBorderMaterialName("ConsoleBorder");
    141         this->consoleOverlayBorder_->setLeftBorderUV(0.0, 0.49, 0.5, 0.51);
    142         this->consoleOverlayBorder_->setRightBorderUV(0.5, 0.49, 1.0, 0.5);
    143         this->consoleOverlayBorder_->setBottomBorderUV(0.49, 0.5, 0.51, 1.0);
    144         this->consoleOverlayBorder_->setBottomLeftBorderUV(0.0, 0.5, 0.5, 1.0);
    145         this->consoleOverlayBorder_->setBottomRightBorderUV(0.5, 0.5, 1.0, 1.0);
    146         this->consoleOverlayContainer_->addChild(this->consoleOverlayBorder_);
    147 
    148         // create a new font to match the requested size exactly
    149         Ogre::FontPtr font = static_cast<Ogre::FontPtr>
    150             (Ogre::FontManager::getSingleton().create("MonofurConsole", "General"));
    151         font->setType(Ogre::FT_TRUETYPE);
    152         font->setSource("Monofur.ttf");
    153         font->setTrueTypeSize(18);
    154         // reto: I don't know why, but setting the resolution twice as high makes the font look a lot clearer
    155         font->setTrueTypeResolution(192);
    156         font->addCodePointRange(Ogre::Font::CodePointRange(33, 126));
    157         font->addCodePointRange(Ogre::Font::CodePointRange(161, 255));
    158 
    159         // create the text lines
    160         this->consoleOverlayTextAreas_ = new Ogre::TextAreaOverlayElement*[LINES];
    161         for (int i = 0; i < LINES; i++)
    162         {
    163             this->consoleOverlayTextAreas_[i] = static_cast<Ogre::TextAreaOverlayElement*>(ovMan->createOverlayElement("TextArea", "InGameConsoleTextArea" + convertToString(i)));
    164             this->consoleOverlayTextAreas_[i]->setMetricsMode(Ogre::GMM_PIXELS);
    165             this->consoleOverlayTextAreas_[i]->setFontName("MonofurConsole");
    166             this->consoleOverlayTextAreas_[i]->setCharHeight(18);
    167             this->consoleOverlayTextAreas_[i]->setParameter("colour_top", "0.21 0.69 0.21");
    168             this->consoleOverlayTextAreas_[i]->setLeft(8);
    169             this->consoleOverlayTextAreas_[i]->setCaption("");
    170             this->consoleOverlayContainer_->addChild(this->consoleOverlayTextAreas_[i]);
    171         }
    172 
    173         // create cursor (also a text area overlay element)
    174         this->consoleOverlayCursor_ = static_cast<Ogre::TextAreaOverlayElement*>(ovMan->createOverlayElement("TextArea", "InGameConsoleCursor"));
    175         this->consoleOverlayCursor_->setMetricsMode(Ogre::GMM_PIXELS);
    176         this->consoleOverlayCursor_->setFontName("MonofurConsole");
    177         this->consoleOverlayCursor_->setCharHeight(18);
    178         this->consoleOverlayCursor_->setParameter("colour_top", "0.21 0.69 0.21");
    179         this->consoleOverlayCursor_->setLeft(7);
    180         this->consoleOverlayCursor_->setCaption(std::string(this->cursorSymbol_, 1));
    181         this->consoleOverlayContainer_->addChild(this->consoleOverlayCursor_);
    182 
    183         // create noise
    184         this->consoleOverlayNoise_ = static_cast<Ogre::PanelOverlayElement*>(ovMan->createOverlayElement("Panel", "InGameConsoleNoise"));
    185         this->consoleOverlayNoise_->setMetricsMode(Ogre::GMM_PIXELS);
    186         this->consoleOverlayNoise_->setPosition(5,0);
    187         this->consoleOverlayNoise_->setMaterialName("ConsoleNoiseSmall");
    188         // comment following line to disable noise
    189         this->consoleOverlayContainer_->addChild(this->consoleOverlayNoise_);
    190 
    191         this->windowResized(GraphicsEngine::getSingleton().getWindowWidth(), GraphicsEngine::getSingleton().getWindowHeight());
    192 
    193         // move overlay "above" the top edge of the screen
    194         // we take -1.2 because the border makes the panel bigger
    195         this->consoleOverlayContainer_->setTop(-1.2 * this->relativeHeight);
    196 
    197         Shell::getInstance().addOutputLevel(true);
    198 
    199         COUT(4) << "Info: InGameConsole initialized" << std::endl;
    200     }
    201 
    202     /**
    203         @brief Destroys all the elements if necessary.
    204     */
    205     void InGameConsole::destroy()
    206     {
    20794        this->deactivate();
    20895
    209         // destroy the input state previously created
    210         SimpleInputState * inputState = dynamic_cast<SimpleInputState*>(InputManager::getState("console"));
    211         if (inputState)
    212             InputManager::destroyState("console");
     96        // destroy the input state previously created (InputBuffer gets destroyed by the Shell)
     97        InputManager::getInstance().destroyState("console");
    21398
    21499        Ogre::OverlayManager* ovMan = Ogre::OverlayManager::getSingletonPtr();
     
    239124            this->consoleOverlayTextAreas_ = 0;
    240125        }
     126
     127        singletonRef_s = 0;
     128    }
     129
     130    /**
     131        @brief Sets the config values, describing the size of the console.
     132    */
     133    void InGameConsole::setConfigValues()
     134    {
     135        SetConfigValue(relativeWidth, 0.8);
     136        SetConfigValue(relativeHeight, 0.4);
     137        SetConfigValue(blinkTime, 0.5);
     138        SetConfigValue(scrollSpeed_, 3.0f);
     139        SetConfigValue(noiseSize_, 1.0f);
     140        SetConfigValue(cursorSymbol_, '|');
     141    }
     142
     143    /**
     144        @brief Initializes the InGameConsole.
     145    */
     146    void InGameConsole::initialise()
     147    {
     148        // create the corresponding input state
     149        InputManager::getInstance().createSimpleInputState("console", 40)
     150            ->setKeyHandler(Shell::getInstance().getInputBuffer());
     151
     152        // create overlay and elements
     153        Ogre::OverlayManager* ovMan = Ogre::OverlayManager::getSingletonPtr();
     154
     155        // create actual overlay
     156        this->consoleOverlay_ = ovMan->create("InGameConsoleConsole");
     157
     158        // create a container
     159        this->consoleOverlayContainer_ = static_cast<Ogre::OverlayContainer*>(ovMan->createOverlayElement("Panel", "InGameConsoleContainer"));
     160        this->consoleOverlayContainer_->setMetricsMode(Ogre::GMM_RELATIVE);
     161        this->consoleOverlayContainer_->setPosition((1 - this->relativeWidth) / 2, 0);
     162        this->consoleOverlayContainer_->setDimensions(this->relativeWidth, this->relativeHeight);
     163        this->consoleOverlay_->add2D(this->consoleOverlayContainer_);
     164
     165        // create BorderPanel
     166        this->consoleOverlayBorder_ = static_cast<Ogre::BorderPanelOverlayElement*>(ovMan->createOverlayElement("BorderPanel", "InGameConsoleBorderPanel"));
     167        this->consoleOverlayBorder_->setMetricsMode(Ogre::GMM_PIXELS);
     168        this->consoleOverlayBorder_->setMaterialName("ConsoleCenter");
     169        this->consoleOverlayBorder_->setBorderSize(16, 16, 0, 16);
     170        this->consoleOverlayBorder_->setBorderMaterialName("ConsoleBorder");
     171        this->consoleOverlayBorder_->setLeftBorderUV(0.0, 0.49, 0.5, 0.51);
     172        this->consoleOverlayBorder_->setRightBorderUV(0.5, 0.49, 1.0, 0.5);
     173        this->consoleOverlayBorder_->setBottomBorderUV(0.49, 0.5, 0.51, 1.0);
     174        this->consoleOverlayBorder_->setBottomLeftBorderUV(0.0, 0.5, 0.5, 1.0);
     175        this->consoleOverlayBorder_->setBottomRightBorderUV(0.5, 0.5, 1.0, 1.0);
     176        this->consoleOverlayContainer_->addChild(this->consoleOverlayBorder_);
     177
     178        // create a new font to match the requested size exactly
     179        Ogre::FontPtr font = static_cast<Ogre::FontPtr>
     180            (Ogre::FontManager::getSingleton().create("MonofurConsole", "General"));
     181        font->setType(Ogre::FT_TRUETYPE);
     182        font->setSource("Monofur.ttf");
     183        font->setTrueTypeSize(18);
     184        // reto: I don't know why, but setting the resolution twice as high makes the font look a lot clearer
     185        font->setTrueTypeResolution(192);
     186        font->addCodePointRange(Ogre::Font::CodePointRange(33, 126));
     187        font->addCodePointRange(Ogre::Font::CodePointRange(161, 255));
     188
     189        // create the text lines
     190        this->consoleOverlayTextAreas_ = new Ogre::TextAreaOverlayElement*[LINES];
     191        for (int i = 0; i < LINES; i++)
     192        {
     193            this->consoleOverlayTextAreas_[i] = static_cast<Ogre::TextAreaOverlayElement*>(ovMan->createOverlayElement("TextArea", "InGameConsoleTextArea" + convertToString(i)));
     194            this->consoleOverlayTextAreas_[i]->setMetricsMode(Ogre::GMM_PIXELS);
     195            this->consoleOverlayTextAreas_[i]->setFontName("MonofurConsole");
     196            this->consoleOverlayTextAreas_[i]->setCharHeight(18);
     197            this->consoleOverlayTextAreas_[i]->setParameter("colour_top", "0.21 0.69 0.21");
     198            this->consoleOverlayTextAreas_[i]->setLeft(8);
     199            this->consoleOverlayTextAreas_[i]->setCaption("");
     200            this->consoleOverlayContainer_->addChild(this->consoleOverlayTextAreas_[i]);
     201        }
     202
     203        // create cursor (also a text area overlay element)
     204        this->consoleOverlayCursor_ = static_cast<Ogre::TextAreaOverlayElement*>(ovMan->createOverlayElement("TextArea", "InGameConsoleCursor"));
     205        this->consoleOverlayCursor_->setMetricsMode(Ogre::GMM_PIXELS);
     206        this->consoleOverlayCursor_->setFontName("MonofurConsole");
     207        this->consoleOverlayCursor_->setCharHeight(18);
     208        this->consoleOverlayCursor_->setParameter("colour_top", "0.21 0.69 0.21");
     209        this->consoleOverlayCursor_->setLeft(7);
     210        this->consoleOverlayCursor_->setCaption(std::string(this->cursorSymbol_, 1));
     211        this->consoleOverlayContainer_->addChild(this->consoleOverlayCursor_);
     212
     213        // create noise
     214        this->consoleOverlayNoise_ = static_cast<Ogre::PanelOverlayElement*>(ovMan->createOverlayElement("Panel", "InGameConsoleNoise"));
     215        this->consoleOverlayNoise_->setMetricsMode(Ogre::GMM_PIXELS);
     216        this->consoleOverlayNoise_->setPosition(5,0);
     217        this->consoleOverlayNoise_->setMaterialName("ConsoleNoiseSmall");
     218        // comment following line to disable noise
     219        this->consoleOverlayContainer_->addChild(this->consoleOverlayNoise_);
     220
     221        this->windowResized(GraphicsEngine::getSingleton().getWindowWidth(), GraphicsEngine::getSingleton().getWindowHeight());
     222
     223        // move overlay "above" the top edge of the screen
     224        // we take -1.2 because the border makes the panel bigger
     225        this->consoleOverlayContainer_->setTop(-1.2 * this->relativeHeight);
     226
     227        Shell::getInstance().addOutputLevel(true);
     228
     229        COUT(4) << "Info: InGameConsole initialized" << std::endl;
    241230    }
    242231
     
    491480        {
    492481            this->bActive_ = true;
    493             InputManager::requestEnterState("console");
     482            InputManager::getInstance().requestEnterState("console");
    494483            Shell::getInstance().registerListener(this);
    495484
     
    513502        {
    514503            this->bActive_ = false;
    515             InputManager::requestLeaveState("console");
     504            InputManager::getInstance().requestLeaveState("console");
    516505            Shell::getInstance().unregisterListener(this);
    517506
  • code/branches/gui/src/orxonox/overlays/console/InGameConsole.h

    r1641 r1642  
    4646    {
    4747    public: // functions
     48        InGameConsole();
     49        ~InGameConsole();
     50
    4851        void initialise();
    4952        void destroy();
     
    5255        void tick(float dt);
    5356
    54         static InGameConsole& getInstance();
     57        static InGameConsole& getInstance() { assert(singletonRef_s); return *singletonRef_s; }
     58        static InGameConsole* getInstancePtr() { return singletonRef_s; }
    5559
    5660        static void openConsole();
     
    5862
    5963    private: // functions
    60         InGameConsole();
    6164        InGameConsole(const InGameConsole& other) {}
    62         ~InGameConsole();
    6365
    6466        void activate();
     
    107109        float noiseSize_;
    108110        char cursorSymbol_;
     111
     112        static InGameConsole* singletonRef_s;
    109113    };
    110114}
Note: See TracChangeset for help on using the changeset viewer.