Revision: 6689
http://playerstage.svn.sourceforge.net/playerstage/?rev=6689&view=rev
Author: natepak
Date: 2008-06-25 19:30:22 -0700 (Wed, 25 Jun 2008)
Log Message:
-----------
Reimplementation of gui-less gazebo
Modified Paths:
--------------
code/gazebo/trunk/server/Simulator.cc
code/gazebo/trunk/server/Simulator.hh
code/gazebo/trunk/server/main.cc
code/gazebo/trunk/server/rendering/OgreAdaptor.cc
code/gazebo/trunk/server/rendering/OgreAdaptor.hh
code/gazebo/trunk/server/rendering/OgreCreator.cc
code/gazebo/trunk/server/rendering/OgreCreator.hh
Modified: code/gazebo/trunk/server/Simulator.cc
===================================================================
--- code/gazebo/trunk/server/Simulator.cc 2008-06-25 22:23:57 UTC (rev
6688)
+++ code/gazebo/trunk/server/Simulator.cc 2008-06-26 02:30:22 UTC (rev
6689)
@@ -64,7 +64,8 @@
userPause(false),
userStep(false),
userStepInc(false),
- userQuit(false)
+ userQuit(false),
+ guiEnabled(true)
{
}
@@ -133,30 +134,35 @@
OgreAdaptor::Instance()->Load(rootNode);
// Create and initialize the Gui
- try
+ if (this->guiEnabled)
{
- XMLConfigNode *childNode = rootNode->GetChild("gui");
-
- if (childNode)
+ try
{
- int width = childNode->GetTupleInt("size",0,640);
- int height = childNode->GetTupleInt("size",1,480);
- int x = childNode->GetTupleInt("pos",0,0);
- int y = childNode->GetTupleInt("pos",1,0);
- std::string type = childNode->GetString("type","fltk",1);
+ XMLConfigNode *childNode = rootNode->GetChild("gui");
- gzmsg(1) << "Creating GUI:\n\tType[" << type
- << "] Pos[" << x << " " << y
- << "] Size[" << width << " " << height << "]\n";
+ if (childNode)
+ {
+ int width = childNode->GetTupleInt("size",0,640);
+ int height = childNode->GetTupleInt("size",1,480);
+ int x = childNode->GetTupleInt("pos",0,0);
+ int y = childNode->GetTupleInt("pos",1,0);
+ std::string type = childNode->GetString("type","fltk",1);
- // Create the GUI
- this->gui = new Gui(x, y, width, height, type+"::Gazebo");
+ gzmsg(1) << "Creating GUI:\n\tType[" << type
+ << "] Pos[" << x << " " << y
+ << "] Size[" << width << " " << height << "]\n";
+
+ // Create the GUI
+ this->gui = new Gui(x, y, width, height, type+"::Gazebo");
+ }
}
+ catch (GazeboError e)
+ {
+ gzthrow( "Error loading the GUI\n" << e);
+ }
}
- catch (GazeboError e)
- {
- gzthrow( "Error loading the GUI\n" << e);
- }
+ else
+ this->gui = NULL;
//Initialize RenderEngine
try
@@ -192,7 +198,6 @@
/// Initialize the simulation
int Simulator::Init()
{
-
this->startTime = this->GetWallTime();
//Initialize the world
@@ -424,3 +429,18 @@
}
+////////////////////////////////////////////////////////////////////////////////
+// True if the gui is to be used
+void Simulator::SetGuiEnabled( bool enabled )
+{
+ this->guiEnabled = enabled;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+/// Return true if the gui is enabled
+bool Simulator::GetGuiEnabled() const
+{
+ return this->guiEnabled;
+}
+
+
Modified: code/gazebo/trunk/server/Simulator.hh
===================================================================
--- code/gazebo/trunk/server/Simulator.hh 2008-06-25 22:23:57 UTC (rev
6688)
+++ code/gazebo/trunk/server/Simulator.hh 2008-06-26 02:30:22 UTC (rev
6689)
@@ -142,6 +142,12 @@
/// \brief Set whether the step has incremented
public: void SetUserStepInc(bool step);
+ /// \brief True if the gui is to be used
+ public: void SetGuiEnabled( bool enabled );
+
+ /// \brief Return true if the gui is enabled
+ public: bool GetGuiEnabled() const;
+
///pointer to the XML Data
private: XMLConfig *xmlFile;
@@ -190,6 +196,9 @@
//The user has somewhat signaled the end of the program
private: bool userQuit;
+ /// True if the GUI is enabled
+ private: bool guiEnabled;
+
//Singleton implementation
private: friend class DestroyerT<Simulator>;
private: friend class SingletonT<Simulator>;
Modified: code/gazebo/trunk/server/main.cc
===================================================================
--- code/gazebo/trunk/server/main.cc 2008-06-25 22:23:57 UTC (rev 6688)
+++ code/gazebo/trunk/server/main.cc 2008-06-26 02:30:22 UTC (rev 6689)
@@ -114,6 +114,7 @@
const char *optLogFileName = NULL;
unsigned int optServerId = 0;
bool optServerForce = true;
+bool optGuiEnabled = true;
double optTimeout = -1;
unsigned int optMsgLevel = 1;
int optTimeControl = 1;
@@ -129,6 +130,7 @@
fprintf(stderr, " -f : Force usage of the server id (use with
caution)\n");
fprintf(stderr, " -d <-1:9> : Verbose mode: -1 = none, 0 = critical
(default), 9 = all)\n");
fprintf(stderr, " -t <sec> : Timeout and quit after <sec> seconds\n");
+ fprintf(stderr, " -g : Run without a GUI\n");
fprintf(stderr, " -l <logfile> : Log to indicated file.\n");
fprintf(stderr, " -n : Do not do any time control\n");
fprintf(stderr, " <worldfile> : load the the indicated world file\n");
@@ -153,7 +155,7 @@
{
FILE *tmpFile;
int ch;
- char *flags = (char*)("l:hd:s:fg:xt:nq");
+ char *flags = (char*)("l:hd:s:fgxt:nq");
// Get letter options
while ((ch = getopt(argc, argv, flags)) != -1)
@@ -184,10 +186,15 @@
// Timeout and quit after x seconds
optTimeout = atof(optarg);
break;
+
case 'n':
optTimeControl = 0;
break;
+ case 'g':
+ optGuiEnabled = false;
+ break;
+
case 'h':
default:
PrintUsage();
@@ -247,6 +254,8 @@
return -1;
}
+ gazebo::Simulator::Instance()->SetGuiEnabled( optGuiEnabled );
+
//Load the simulator
try
{
Modified: code/gazebo/trunk/server/rendering/OgreAdaptor.cc
===================================================================
--- code/gazebo/trunk/server/rendering/OgreAdaptor.cc 2008-06-25 22:23:57 UTC
(rev 6688)
+++ code/gazebo/trunk/server/rendering/OgreAdaptor.cc 2008-06-26 02:30:22 UTC
(rev 6689)
@@ -81,6 +81,13 @@
// GZ_DELETE (this->sceneMgr) //this objects seems to be destroyed by root
// GZ_DELETE (this->viewport)
+ if (this->dummyDisplay)
+ {
+ glXDestroyContext(this->dummyDisplay, this->dummyContext);
+ XDestroyWindow(this->dummyDisplay, this->dummyWindowId);
+ XCloseDisplay(this->dummyDisplay);
+ }
+
}
////////////////////////////////////////////////////////////////////////////////
@@ -156,6 +163,32 @@
node = rootNode->GetChild("ogre", "rendering");
+ /// Create a dummy rendering context if the GUI is disabled
+ if (!Simulator::Instance()->GetGuiEnabled())
+ {
+ this->dummyDisplay = XOpenDisplay(0);
+ if (!this->dummyDisplay)
+ gzthrow(std::string("Can't open display: ") + XDisplayName(0) + "\n");
+
+ int screen = DefaultScreen(this->dummyDisplay);
+
+ int attribList[8] = {GLX_RGBA, GLX_RED_SIZE, 8, GLX_GREEN_SIZE, 8,
+ GLX_BLUE_SIZE, 8, None};
+
+ this->dummyVisual = glXChooseVisual(this->dummyDisplay, screen,
+ (int *)attribList);
+
+ this->dummyWindowId = XCreateSimpleWindow(this->dummyDisplay,
+ RootWindow(this->dummyDisplay, screen), 0, 0, 1, 1, 0, 0, 0);
+
+ this->dummyContext = glXCreateContext(this->dummyDisplay,
+ this->dummyVisual, NULL, 1);
+
+ glXMakeCurrent(this->dummyDisplay, this->dummyWindowId,
this->dummyContext);
+ OgreCreator::CreateWindow((long)this->dummyDisplay, screen,
+ (long)this->dummyWindowId,1,1);
+ }
+
// Set default mipmap level (NB some APIs ignore this)
Ogre::TextureManager::getSingleton().setDefaultNumMipmaps( 5 );
Modified: code/gazebo/trunk/server/rendering/OgreAdaptor.hh
===================================================================
--- code/gazebo/trunk/server/rendering/OgreAdaptor.hh 2008-06-25 22:23:57 UTC
(rev 6688)
+++ code/gazebo/trunk/server/rendering/OgreAdaptor.hh 2008-06-26 02:30:22 UTC
(rev 6689)
@@ -29,6 +29,7 @@
#include <X11/Xlib.h>
#include <X11/Xutil.h>
+#include <GL/glx.h>
#include "SingletonT.hh"
@@ -87,9 +88,6 @@
/// \brief Save Ogre settings
public: void Save(XMLConfigNode *node);
- /// \brief Initialize Ogre Rendering engine
- public: void Init(Display *display, XVisualInfo *visual, Window windowId,
int width, int height);
-
/// \brief Get the desired update rate
public: double GetUpdateRate();
@@ -135,22 +133,21 @@
private: friend class DestroyerT<OgreAdaptor>;
private: friend class SingletonT<OgreAdaptor>;
-
+
+ /// ID for a dummy window. Used for gui-less operation
+ protected: Window dummyWindowId;
+
+ /// Pointer to the dummy Xvisual.Used for gui-less operation
+ protected: XVisualInfo *dummyVisual;
+
+ /// Pointer to the dummy display.Used for gui-less operation
+ protected: Display *dummyDisplay;
+
+ /// GLX context used to render the scenes.Used for gui-less operation
+ protected: GLXContext dummyContext;
};
- /*/// \brief
- class OgreGLXWindowInterface
- {
- public: virtual ~OgreGLXWindowInterface() = 0;
-
- // Call this with true when the window is mapped/visible, false when the
window is unmapped/invisible
- public: virtual void exposed(bool active) = 0;
-
- // Call this to notify the window was resized
- public: virtual void resized(size_t width, size_t height) = 0;
- };
- */
-
+
/// \}
}
Modified: code/gazebo/trunk/server/rendering/OgreCreator.cc
===================================================================
--- code/gazebo/trunk/server/rendering/OgreCreator.cc 2008-06-25 22:23:57 UTC
(rev 6688)
+++ code/gazebo/trunk/server/rendering/OgreCreator.cc 2008-06-26 02:30:22 UTC
(rev 6689)
@@ -23,8 +23,9 @@
* Date: 27 Dec 2007
*/
+#include <Ogre.h>
+
#include <math.h>
-#include <Ogre.h>
#include <iostream>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
@@ -490,30 +491,32 @@
// Create a window for Ogre
Ogre::RenderWindow *OgreCreator::CreateWindow(Fl_Window *flWindow, unsigned
int width, unsigned int height)
{
+ if (flWindow)
+ return OgreCreator::CreateWindow( (long)fl_display, fl_visual->screen,
+ (long)(Fl_X::i(flWindow)->xid), width, height);
+ else
+ return NULL;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// Create a window for Ogre
+Ogre::RenderWindow *OgreCreator::CreateWindow(long display, int screen,
+ long winId, unsigned int width,
+ unsigned int height)
+{
Ogre::StringVector paramsVector;
Ogre::NameValuePairList params;
Ogre::RenderWindow *window = NULL;
- if (flWindow)
- {
- Display *display;
- int screen;
- Window winId;
+ params["parentWindowHandle"] = Ogre::StringConverter::toString(display) +
":" + Ogre::StringConverter::toString(screen) + ":" +
Ogre::StringConverter::toString(winId);
- display = fl_display;
- screen = fl_visual->screen;
- winId = Fl_X::i(flWindow)->xid;
+ std::ostringstream stream;
+ stream << "OgreWindow(" << windowCounter++ << ")";
- params["parentWindowHandle"] =
Ogre::StringConverter::toString((long)display) + ":" +
Ogre::StringConverter::toString(screen) + ":" +
Ogre::StringConverter::toString((long)winId);
+ window = OgreAdaptor::Instance()->root->createRenderWindow( stream.str(),
width, height, false, ¶ms);
- std::ostringstream stream;
- stream << "OgreWindow(" << windowCounter++ << ")";
+ window->setActive(true);
+ window->setAutoUpdated(true);
- window = OgreAdaptor::Instance()->root->createRenderWindow( stream.str(),
width, height, false, ¶ms);
-
- window->setActive(true);
- window->setAutoUpdated(true);
- }
-
return window;
}
Modified: code/gazebo/trunk/server/rendering/OgreCreator.hh
===================================================================
--- code/gazebo/trunk/server/rendering/OgreCreator.hh 2008-06-25 22:23:57 UTC
(rev 6688)
+++ code/gazebo/trunk/server/rendering/OgreCreator.hh 2008-06-26 02:30:22 UTC
(rev 6689)
@@ -26,6 +26,10 @@
#ifndef OGRECREATOR
#define OGRECREATOR
+
+//#include <X11/Xlib.h>
+//#include <X11/Xutil.h>
+
#include <string>
namespace Ogre
@@ -87,6 +91,14 @@
public: static Ogre::RenderWindow *CreateWindow(Fl_Window *flWindow,
unsigned int width,
unsigned int height);
+
+
+ /// \brief Create a window for Ogre
+ public: static Ogre::RenderWindow *CreateWindow(long display,
+ int screen,
+ long winId,
+ unsigned int width,
+ unsigned int height);
/// \brief Draw the uniform grid pattern
public: static void DrawGrid();
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://sourceforge.net/services/buy/index.php
_______________________________________________
Playerstage-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/playerstage-commit