[Orxonox-commit 94] r2790 - in trunk/src: ogreceguirenderer orxonox/gamestates orxonox/gui

bknecht at orxonox.net bknecht at orxonox.net
Mon Mar 16 11:47:07 CET 2009


Author: bknecht
Date: 2009-03-16 10:47:06 +0000 (Mon, 16 Mar 2009)
New Revision: 2790

Modified:
   trunk/src/ogreceguirenderer/OgreCEGUIRenderer.cpp
   trunk/src/orxonox/gamestates/GSGUI.cc
   trunk/src/orxonox/gamestates/GSLevel.h
   trunk/src/orxonox/gamestates/GSStandalone.cc
   trunk/src/orxonox/gamestates/GSStandalone.h
   trunk/src/orxonox/gui/GUIManager.cc
   trunk/src/orxonox/gui/GUIManager.h
Log:
Ugly hack to use GUI ingame. Hack itself needs improvement AND of course it should be hackfree!

Modified: trunk/src/ogreceguirenderer/OgreCEGUIRenderer.cpp
===================================================================
--- trunk/src/ogreceguirenderer/OgreCEGUIRenderer.cpp	2009-03-16 01:11:14 UTC (rev 2789)
+++ trunk/src/ogreceguirenderer/OgreCEGUIRenderer.cpp	2009-03-16 10:47:06 UTC (rev 2790)
@@ -2,7 +2,7 @@
 	filename: 	OgreCEGUIRenderer.cpp
 	created:	11/5/2004
 	author:		Paul D Turner
-	
+
 	purpose:	Implementation of Renderer class for Ogre engine
 *************************************************************************/
 /*************************************************************************
@@ -53,7 +53,7 @@
 /*************************************************************************
 	Utility function to create a render operation and vertex buffer to render quads
 *************************************************************************/
-static void createQuadRenderOp(Ogre::RenderOperation &d_render_op, 
+static void createQuadRenderOp(Ogre::RenderOperation &d_render_op,
     Ogre::HardwareVertexBufferSharedPtr &d_buffer, size_t nquads)
 {
     using namespace Ogre;
@@ -71,7 +71,7 @@
 	vd->addElement(0, vd_offset, VET_FLOAT2, VES_TEXTURE_COORDINATES);
 
 	// create hardware vertex buffer
-	d_buffer = HardwareBufferManager::getSingleton().createVertexBuffer(vd->getVertexSize(0), nquads,  
+	d_buffer = HardwareBufferManager::getSingleton().createVertexBuffer(vd->getVertexSize(0), nquads,
         HardwareBuffer::HBU_DYNAMIC_WRITE_ONLY_DISCARDABLE, false);
 
 	// bind vertex buffer
@@ -82,7 +82,7 @@
 	d_render_op.useIndexes = false;
 }
 
-static void destroyQuadRenderOp(Ogre::RenderOperation &d_render_op, 
+static void destroyQuadRenderOp(Ogre::RenderOperation &d_render_op,
     Ogre::HardwareVertexBufferSharedPtr &d_buffer)
 {
     delete d_render_op.vertexData;
@@ -145,7 +145,7 @@
 	{
 		d_sorted = false;
 		QuadInfo quad;
-		
+
 		// set quad position, flipping y co-ordinates, and applying appropriate texel origin offset
 		quad.position.d_left	= dest_rect.d_left;
 		quad.position.d_right	= dest_rect.d_right;
@@ -169,7 +169,7 @@
 		quad.topRightCol	= colourToOgre(colours.d_bottom_right);
 		quad.bottomLeftCol	= colourToOgre(colours.d_top_left);
 		quad.bottomRightCol	= colourToOgre(colours.d_top_right);
-		
+
 		// set quad split mode
 		quad.splitMode = quad_split_mode;
 
@@ -228,9 +228,9 @@
                 buffmem->tu1 = quad.texPosition.d_left;
                 buffmem->tv1 = quad.texPosition.d_bottom;
                 ++buffmem;
-    
+
                 // setup Vertex 2...
-                
+
                 // top-left to bottom-right diagonal
                 if (quad.splitMode == TopLeftToBottomRight)
                 {
@@ -252,7 +252,7 @@
                     buffmem->tv1 = quad.texPosition.d_top;
                 }
                 ++buffmem;
-    
+
                 // setup Vertex 3...
                 buffmem->x = quad.position.d_left;
                 buffmem->y = quad.position.d_top;
@@ -261,7 +261,7 @@
                 buffmem->tu1 = quad.texPosition.d_left;
                 buffmem->tv1 = quad.texPosition.d_top;
                 ++buffmem;
-    
+
                 // setup Vertex 4...
                 buffmem->x = quad.position.d_right;
                 buffmem->y = quad.position.d_bottom;
@@ -270,7 +270,7 @@
                 buffmem->tu1 = quad.texPosition.d_right;
                 buffmem->tv1 = quad.texPosition.d_bottom;
                 ++buffmem;
-    
+
                 // setup Vertex 5...
                 buffmem->x = quad.position.d_right;
                 buffmem->y = quad.position.d_top;
@@ -279,9 +279,9 @@
                 buffmem->tu1 = quad.texPosition.d_right;
                 buffmem->tv1 = quad.texPosition.d_top;
                 ++buffmem;
-    
+
                 // setup Vertex 6...
-                
+
                 // top-left to bottom-right diagonal
                 if (quad.splitMode == TopLeftToBottomRight)
                 {
@@ -304,11 +304,11 @@
                 }
                 ++buffmem;
             }
-    
+
             // ensure we leave the buffer in the unlocked state
             d_buffer->unlock();
         }
-        
+
         /// Render the buffer
         d_bufferPos = 0;
 		bool first = true;
@@ -317,7 +317,7 @@
         QuadList::iterator i = d_quadlist.begin();
         while(i != d_quadlist.end())
         {
-            
+
             d_currTexture = i->texture;
             d_render_op.vertexData->vertexStart = d_bufferPos;
             for (; i != d_quadlist.end(); ++i)
@@ -425,7 +425,7 @@
 
 
 /*************************************************************************
-	setup states etc	
+	setup states etc
 *************************************************************************/
 void OgreCEGUIRenderer::initRenderStates(void)
 {
@@ -468,9 +468,9 @@
 }
 
 
- 
+
 /*************************************************************************
-	sort quads list according to texture	
+	sort quads list according to texture
 *************************************************************************/
 void OgreCEGUIRenderer::sortQuads(void)
 {
@@ -524,7 +524,7 @@
 		++buffmem;
 
 		// setup Vertex 2...
-		
+
 		// top-left to bottom-right diagonal
 		if (quad_split_mode == TopLeftToBottomRight)
 		{
@@ -576,7 +576,7 @@
 		++buffmem;
 
 		// setup Vertex 6...
-		
+
 		// top-left to bottom-right diagonal
 		if (quad_split_mode == TopLeftToBottomRight)
 		{
@@ -613,7 +613,7 @@
 
 /*************************************************************************
 	convert ARGB colour value to whatever the Ogre render system is
-	expecting.	
+	expecting.
 *************************************************************************/
 uint32 OgreCEGUIRenderer::colourToOgre(const colour& col) const
 {
@@ -627,7 +627,7 @@
 
 
 /*************************************************************************
-	Set the scene manager to be used for rendering the GUI.	
+	Set the scene manager to be used for rendering the GUI.
 *************************************************************************/
 void OgreCEGUIRenderer::setTargetSceneManager(Ogre::SceneManager* scene_manager)
 {
@@ -649,7 +649,7 @@
 
 
 /*************************************************************************
-	Set the target render queue for GUI rendering.	
+	Set the target render queue for GUI rendering.
 *************************************************************************/
 void OgreCEGUIRenderer::setTargetRenderQueue(Ogre::uint8 queue_id, bool post_queue)
 {
@@ -723,7 +723,7 @@
 
 
 /*************************************************************************
-	Create a texture from an existing Ogre::TexturePtr object	
+	Create a texture from an existing Ogre::TexturePtr object
 *************************************************************************/
 Texture* OgreCEGUIRenderer::createTexture(Ogre::TexturePtr& texture)
 {
@@ -748,7 +748,7 @@
 }
 
 /*************************************************************************
-Set the size of the display in pixels.	
+Set the size of the display in pixels.
 *************************************************************************/
 void OgreCEGUIRenderer::setDisplaySize(const Size& sz)
 {
@@ -766,7 +766,7 @@
 	Callback from Ogre invoked before other stuff in our target queue
 	is rendered
 *************************************************************************/
-void CEGUIRQListener::renderQueueStarted(Ogre::uint8 id, const Ogre::String& invocation, 
+void CEGUIRQListener::renderQueueStarted(Ogre::uint8 id, const Ogre::String& invocation,
 										 bool& skipThisQueue)
 {
 	if ((!d_post_queue) && (d_queue_id == id))

Modified: trunk/src/orxonox/gamestates/GSGUI.cc
===================================================================
--- trunk/src/orxonox/gamestates/GSGUI.cc	2009-03-16 01:11:14 UTC (rev 2789)
+++ trunk/src/orxonox/gamestates/GSGUI.cc	2009-03-16 10:47:06 UTC (rev 2790)
@@ -50,6 +50,7 @@
         guiManager_ = getParent()->getGUIManager();
 
         // show main menu
+        guiManager_->loadScene("MainMenu");
         guiManager_->showGUI("MainMenu", 0);
         getParent()->getViewport()->setCamera(guiManager_->getCamera());
     }

Modified: trunk/src/orxonox/gamestates/GSLevel.h
===================================================================
--- trunk/src/orxonox/gamestates/GSLevel.h	2009-03-16 01:11:14 UTC (rev 2789)
+++ trunk/src/orxonox/gamestates/GSLevel.h	2009-03-16 10:47:06 UTC (rev 2790)
@@ -42,6 +42,9 @@
         GSLevel();
         ~GSLevel();
 
+        // was private before (is public now because of console command in GSStandalone)
+        void setConfigValues();
+
     protected:
         void enter(Ogre::Viewport* viewport);
         void leave();
@@ -70,9 +73,6 @@
         ConsoleCommand*       ccKeybind_;
         ConsoleCommand*       ccTkeybind_;
 
-    private:
-        void setConfigValues();
-
     };
 }
 

Modified: trunk/src/orxonox/gamestates/GSStandalone.cc
===================================================================
--- trunk/src/orxonox/gamestates/GSStandalone.cc	2009-03-16 01:11:14 UTC (rev 2789)
+++ trunk/src/orxonox/gamestates/GSStandalone.cc	2009-03-16 10:47:06 UTC (rev 2790)
@@ -29,10 +29,18 @@
 #include "OrxonoxStableHeaders.h"
 #include "GSStandalone.h"
 
+#include <OgreViewport.h>
+#include <OgreCamera.h>
 #include "core/Core.h"
+#include "core/ConsoleCommand.h"
+#include "gui/GUIManager.h"
 
 namespace orxonox
 {
+    SetConsoleCommand(GSStandalone, showGUI, true).setAsInputCommand();
+
+    bool GSStandalone::guiShowing_s = false;
+
     GSStandalone::GSStandalone()
         : GameState<GSGraphics>("standalone")
     {
@@ -42,11 +50,20 @@
     {
     }
 
+    void GSStandalone::showGUI()
+    {
+        GSStandalone::guiShowing_s = true;
+    }
+
     void GSStandalone::enter()
     {
         Core::setIsStandalone(true);
 
         GSLevel::enter(this->getParent()->getViewport());
+
+        guiManager_ = getParent()->getGUIManager();
+        // not sure if necessary
+        // guiManager_->loadScene("IngameMenu");
     }
 
     void GSStandalone::leave()
@@ -58,6 +75,18 @@
 
     void GSStandalone::ticked(const Clock& time)
     {
+        if (guiShowing_s)
+        {
+            guiManager_->showGUI("IngameMenu", this->getParent()->getViewport()->getCamera()->getSceneManager());
+        }
+        else
+        {
+            if (guiManager_)
+                guiManager_->hideGUI();
+        }
+        // tick CEGUI
+        guiManager_->tick(time.getDeltaTime());
+
         GSLevel::ticked(time);
         this->tickChild(time);
     }

Modified: trunk/src/orxonox/gamestates/GSStandalone.h
===================================================================
--- trunk/src/orxonox/gamestates/GSStandalone.h	2009-03-16 01:11:14 UTC (rev 2789)
+++ trunk/src/orxonox/gamestates/GSStandalone.h	2009-03-16 10:47:06 UTC (rev 2790)
@@ -40,11 +40,15 @@
     public:
         GSStandalone();
         ~GSStandalone();
+        static void showGUI();
 
     private:
         void enter();
         void leave();
         void ticked(const Clock& time);
+
+        GUIManager*     guiManager_;
+        static bool     guiShowing_s;
     };
 }
 

Modified: trunk/src/orxonox/gui/GUIManager.cc
===================================================================
--- trunk/src/orxonox/gui/GUIManager.cc	2009-03-16 01:11:14 UTC (rev 2789)
+++ trunk/src/orxonox/gui/GUIManager.cc	2009-03-16 10:47:06 UTC (rev 2790)
@@ -171,7 +171,7 @@
                 state->setJoyStickHandler(&InputManager::EMPTY_HANDLER);
 
                 // load the background scene
-                loadScenes();
+                //loadScenes();
                 //CEGUI::KeyEventArgs e;
                 //e.codepoint
             }
@@ -191,6 +191,36 @@
         return true;
     }
 
+    void GUIManager::loadScene(const std::string& name)
+    {
+        if (name.compare("IngameMenu") == 0)
+        {
+            try
+            {
+                /*this->scriptModule_ = new LuaScriptModule();
+                this->luaState_ = this->scriptModule_->getLuaState();
+                this->guiSystem_ = new System(this->guiRenderer_, this->resourceProvider_, 0, this->scriptModule_);
+                tolua_Core_open(this->scriptModule_->getLuaState());
+                tolua_Orxonox_open(this->scriptModule_->getLuaState());
+                */
+                this->scriptModule_->executeScriptFile("ingameGUI.lua", "GUI");
+            }
+            catch (CEGUI::Exception& ex)
+            {
+#if CEGUI_VERSION_MINOR < 6
+                throw GeneralException(ex.getMessage().c_str());
+#else
+                throw GeneralException(ex.getMessage().c_str(), ex.getLine(),
+                                       ex.getFileName().c_str(), ex.getName().c_str());
+#endif
+            }
+        }
+        else
+        {
+            loadScenes();
+        }
+    }
+
     void GUIManager::loadScenes()
     {
         // first of all, we need to have our own SceneManager for the GUI. The reason
@@ -240,6 +270,7 @@
             COUT(3) << "Loading GUI " << name << std::endl;
             try
             {
+                COUT (0) << "************* sceneManager: " << sceneManager << std::endl;
                 if (!sceneManager)
                 {
                     // currently, only an image is loaded. We could do 3D, see loadBackground.
@@ -286,7 +317,8 @@
         if (this->state_ != OnDisplay)
             return;
         //this->viewport_->setCamera(0);
-        this->guiRenderer_->setTargetSceneManager(0);
+        // has no effect since you cannot assign 0 as SceneManager
+        //this->guiRenderer_->setTargetSceneManager(0);
         this->state_ = Ready;
         InputManager::getInstance().requestLeaveState("gui");
     }

Modified: trunk/src/orxonox/gui/GUIManager.h
===================================================================
--- trunk/src/orxonox/gui/GUIManager.h	2009-03-16 01:11:14 UTC (rev 2789)
+++ trunk/src/orxonox/gui/GUIManager.h	2009-03-16 10:47:06 UTC (rev 2790)
@@ -69,6 +69,7 @@
         ~GUIManager();
 
         bool initialise(Ogre::RenderWindow* renderWindow);
+        void loadScene(const std::string& name);
         void tick(float dt)
         {
             assert(guiSystem_);




More information about the Orxonox-commit mailing list