Commit dd8a45b1 authored by ebaum's avatar ebaum

[CHANGE #50,#51,#52]

- Moved GUI initialization to Kernel
- Integrated graphics engine into Kernel
- Integrated test Module into Kernel
- Added multithreading for Modules, graphics Engine and GUI
- Temporarily disabled WOptionHandler Code
parent f6d0b458
......@@ -100,7 +100,7 @@ IF ( NOT CMAKE_BUILD_TYPE STREQUAL "Static" )
ADD_SUBDIRECTORY( kernel )
ADD_SUBDIRECTORY( common )
ADD_EXECUTABLE( walnut OpenWalnut.cpp utils/WOptionHandler.cpp )
TARGET_LINK_LIBRARIES( walnut kernel guiqt4 ${Boost_LIBRARIES} ${OPENTHREADS_LIBRARY} )
TARGET_LINK_LIBRARIES( walnut kernel guiqt4 common ${Boost_LIBRARIES} ${OPENTHREADS_LIBRARY} )
ELSE ( NOT CMAKE_BUILD_TYPE STREQUAL "Static" )
FILE( GLOB_RECURSE ALL_SRC ${PROJECT_SOURCE_DIR}/*.cpp )
......
......@@ -23,12 +23,11 @@
#include <iostream>
#include "gui/qt4/WMainApplication.h"
#include "utils/WOptionHandler.h"
#include "common/WException.h"
#include "common/WSegmentationFault.h"
#include "kernel/WKernel.h"
/**
* The main routine starting up the whole application.
*
......@@ -49,7 +48,8 @@ int main( int argc, char* argv[] )
// install signal handler as early as possible
WSegmentationFault::installSignalHandler();
// start application
WOptionHandler h( argc, argv );
return h.takeActions();
// init the kernel
WKernel kernel = WKernel( argc, argv );
int code = kernel.run();
return code;
}
FILE( GLOB COMMON_SRC "*.cpp" "*.hpp" )
ADD_LIBRARY( common SHARED ${COMMON_SRC} )
TARGET_LINK_LIBRARIES( common ${Boost_LIBRARIES} )
# Unit tests
IF( CXXTEST_FOUND )
CXXTEST_ADD_TESTS_FROM_LIST( "${COMMON_SRC}"
"common" # no libs for linking required
${Boost_LIBRARIES}
"WSegmentationFault.cpp"
"WStringUtils.hpp" # since unit tests are already included via the .hpp file
)
......
//---------------------------------------------------------------------------
//
// Project: OpenWalnut
//
// Copyright 2009 SomeCopyrightowner
//
// This file is part of OpenWalnut.
//
// OpenWalnut is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// OpenWalnut is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
//
//---------------------------------------------------------------------------
#include <iostream>
#include "WThreadedRunner.h"
WThreadedRunner::WThreadedRunner()
{
// initialize members
m_FinishRequested = false;
m_Thread = NULL;
}
WThreadedRunner::~WThreadedRunner()
{
// cleanup
// XXX is this working if thread already has finished?
// wait( true ); <-- no
}
void WThreadedRunner::run()
{
m_Thread = new boost::thread( boost::bind( &WThreadedRunner::threadMain, this ) );
}
void WThreadedRunner::wait( bool requestFinish )
{
if( requestFinish )
{
m_FinishRequested = requestFinish;
}
m_Thread->join();
}
void WThreadedRunner::threadMain()
{
}
void WThreadedRunner::yield() const
{
m_Thread->yield();
}
void WThreadedRunner::sleep( const int t ) const
{
boost::this_thread::sleep( boost::posix_time::seconds( t ) );
}
//---------------------------------------------------------------------------
//
// Project: OpenWalnut
//
// Copyright 2009 SomeCopyrightowner
//
// This file is part of OpenWalnut.
//
// OpenWalnut is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// OpenWalnut is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
//
//---------------------------------------------------------------------------
#ifndef WTHREADEDRUNNER_H
#define WTHREADEDRUNNER_H
#include <boost/thread/thread.hpp>
/**
* \par Description:
* Base class for alle classes needing to be executed in a separate thread.
*/
class WThreadedRunner
{
public:
/**
* \par Description
* Default constructor.
*/
WThreadedRunner();
/**
* \par Description
* Destructor.
*/
virtual ~WThreadedRunner();
/**
* \par Description
* Run thread.
*/
void run();
/**
* \par Description
* Wait for the thread to be finished.
*
* \param requestFinish true if the thread should be notified.
*/
void wait( bool requestFinish = false );
protected:
/**
* \par Description
* Function that has to be overwritten for execution. It gets executed in a separate thread after run()
* has been called.
*/
virtual void threadMain();
/**
* \par Description
* Thread instance.
*/
boost::thread* m_Thread;
/**
* \par Description
* True if thread should end execution.
*/
bool m_FinishRequested;
/**
* \par Description
* Give remaining execution timeslice to another thread.
*/
void yield() const;
/**
* \par Description
* Sets thread asleep.
*
* \param t time to sleep in seconds.
*/
void sleep( const int t ) const;
private:
};
#endif // WTHREADEDRUNNER_H
//---------------------------------------------------------------------------
//
// Project: OpenWalnut
//
// Copyright 2009 SomeCopyrightowner
//
// This file is part of OpenWalnut.
//
// OpenWalnut is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// OpenWalnut is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
//
//---------------------------------------------------------------------------
#include "WGECamera.h"
WGECamera::WGECamera():
osg::Camera()
{
// initialize members
}
WGECamera::~WGECamera()
{
// cleanup
}
void WGECamera::setDefaultProjectionMode( WGECamera::ProjectionMode mode )
{
m_DefProjMode = mode;
}
WGECamera::ProjectionMode WGECamera::getDefaultProjectionMode()
{
return m_DefProjMode;
}
void WGECamera::reset()
{
// not yet implemented
}
//---------------------------------------------------------------------------
//
// Project: OpenWalnut
//
// Copyright 2009 SomeCopyrightowner
//
// This file is part of OpenWalnut.
//
// OpenWalnut is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// OpenWalnut is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
//
//---------------------------------------------------------------------------
#ifndef WGECAMERA_H
#define WGECAMERA_H
#include <osg/Camera>
/**
* \par Description:
* Class for wrapping around the OSG Camera class. It adds some utility functions for simply setting some
* camera defaults.
*/
class WGECamera: public osg::Camera
{
public:
/**
* \par Description
* List of possible camera modes.
*/
enum ProjectionMode
{
ORTHOGRAPHIC, PERSPECTIVE
};
/**
* \par Description
* Default constructor.
*/
WGECamera();
/**
* \par Description
* Sets the default projection mode used for cameras getting reset.
*
* \param mode the mode to set.
*/
void setDefaultProjectionMode( ProjectionMode mode );
/**
* \par Description
* Returns the current default projection mode.
*
* \return the currently set mode.
*/
ProjectionMode getDefaultProjectionMode();
/**
* \par Description
* Resets the camera and activates the prior set defaults.
*/
void reset();
// TODO(ebaum): add more default settings and camera setups here
protected:
/**
* \par Description
* Destructor. This desctructor is protected to avoid accidentally deleting a instance of WGECamera.
* This follows the philosophy of OSG to avoid problems in multithreaded environments, since these camera
* pointers are used deep in the OSG where an deletion could cause a segfault.
*/
virtual ~WGECamera();
/**
* \par Description
* The projection mode used as default.
*/
ProjectionMode m_DefProjMode;
private:
};
#endif // WGECAMERA_H
......@@ -21,15 +21,26 @@
//
//---------------------------------------------------------------------------
#include <iostream>
#include <osg/ShapeDrawable>
#include <osg/Group>
#include <osg/Geode>
#include "WGEScene.h"
WGEScene::WGEScene()
WGEScene::WGEScene():
osg::Group()
{
std::cout << "Initializing OpenSceneGraph Root Node" << std::endl;
// initialize members
}
WGEScene::~WGEScene()
{
std::cout << "Shutting down OpenSceneGraph Root Node" << std::endl;
// cleanup
}
......@@ -24,11 +24,13 @@
#ifndef WGESCENE_H
#define WGESCENE_H
#include <osg/Group>
/**
* \par Description:
* Class for managing the OpenSceneGraph root node. It can handle new nodes, removing nodes and so on.
*/
class WGEScene
class WGEScene: public osg::Group
{
public:
......
......@@ -34,11 +34,10 @@
#include <osgGA/StateSetManipulator>
#include <osgGA/AnimationPathManipulator>
#include <osgGA/TerrainManipulator>
#include <osgViewer/ViewerEventHandlers>
#include <osgDB/ReadFile>
#include <osgViewer/ViewerEventHandlers>
#include "exceptions/WGEInitFailed.h"
#include "WGEViewer.h"
......@@ -61,67 +60,12 @@ WGEViewer::WGEViewer( boost::shared_ptr<WindowData> wdata, int x, int y, int wid
m_View->addEventHandler( new osgViewer::StatsHandler );
// camera manipulator
m_Manipulator = new osgGA::TrackballManipulator();
m_View->setCameraManipulator( m_Manipulator );
m_View->setCameraManipulator( new osgGA::TrackballManipulator() );
// finally add view
// there is the possibility to use ONE single composite viewer instance for every view, but
// currently this possibility is not used.
m_Viewer->addView( m_View.get() );
// load the sample scene.
osg::Geode* sceneDataGeode = new osg::Geode();
// 20 units into the screen
sceneDataGeode->addDrawable(
new osg::ShapeDrawable( new osg::Box( osg::Vec3( -6, 5, -20 ), 1.0 ) ) );
sceneDataGeode->addDrawable(
new osg::ShapeDrawable( new osg::Sphere( osg::Vec3( -3, 5, -20 ), 1.0 ) ) );
sceneDataGeode->addDrawable(
new osg::ShapeDrawable( new osg::Cone( osg::Vec3( 0, 5, -20 ), 1.0, 1.0 ) ) );
sceneDataGeode->addDrawable(
new osg::ShapeDrawable( new osg::Cylinder( osg::Vec3( 3, 5, -20 ), 1.0, 1.0 ) ) );
sceneDataGeode->addDrawable(
new osg::ShapeDrawable( new osg::Capsule( osg::Vec3( 6, 5, -20 ), 1.0, 1.0 ) ) );
// 25 units into the screen
sceneDataGeode->addDrawable(
new osg::ShapeDrawable( new osg::Box( osg::Vec3( -6, 0, -25 ), 1.0 ) ) );
sceneDataGeode->addDrawable(
new osg::ShapeDrawable( new osg::Sphere( osg::Vec3( -3, 0, -25 ), 1.0 ) ) );
sceneDataGeode->addDrawable(
new osg::ShapeDrawable( new osg::Cone( osg::Vec3( 0, 0, -25 ), 1.0, 1.0 ) ) );
sceneDataGeode->addDrawable(
new osg::ShapeDrawable( new osg::Cylinder( osg::Vec3( 3, 0, -25 ), 1.0, 1.0 ) ) );
sceneDataGeode->addDrawable(
new osg::ShapeDrawable( new osg::Capsule( osg::Vec3( 6, 0, -25 ), 1.0, 1.0 ) ) );
// 30 units into the screen
sceneDataGeode->addDrawable(
new osg::ShapeDrawable( new osg::Box( osg::Vec3( -6, -5, -30 ), 1.0 ) ) );
sceneDataGeode->addDrawable(
new osg::ShapeDrawable( new osg::Sphere( osg::Vec3( -3, -5, -30 ), 1.0 ) ) );
sceneDataGeode->addDrawable(
new osg::ShapeDrawable( new osg::Cone( osg::Vec3( 0, -5, -30 ), 1.0, 1.0 ) ) );
sceneDataGeode->addDrawable(
new osg::ShapeDrawable( new osg::Cylinder( osg::Vec3( 3, -5, -30 ), 1.0, 1.0 ) ) );
sceneDataGeode->addDrawable(
new osg::ShapeDrawable( new osg::Capsule( osg::Vec3( 6, -5, -30 ), 1.0, 1.0 ) ) );
// 35 units into the screen
sceneDataGeode->addDrawable(
new osg::ShapeDrawable( new osg::Box( osg::Vec3( -6, -10, -35 ), 1.0 ) ) );
sceneDataGeode->addDrawable(
new osg::ShapeDrawable( new osg::Sphere( osg::Vec3( -3, -10, -35 ), 1.0 ) ) );
sceneDataGeode->addDrawable(
new osg::ShapeDrawable( new osg::Cone( osg::Vec3( 0, -10, -35 ), 1.0, 1.0 ) ) );
sceneDataGeode->addDrawable(
new osg::ShapeDrawable( new osg::Cylinder( osg::Vec3( 3, -10, -35 ), 1.0, 1.0 ) ) );
sceneDataGeode->addDrawable(
new osg::ShapeDrawable( new osg::Capsule( osg::Vec3( 6, -10, -35 ), 1.0, 1.0 ) ) );
m_View->setSceneData( sceneDataGeode );
}
catch( ... )
{
......@@ -141,13 +85,34 @@ boost::shared_ptr<osgViewer::CompositeViewer> WGEViewer::getViewer()
void WGEViewer::setCameraManipulator( osgGA::MatrixManipulator* manipulator )
{
m_Manipulator = manipulator;
m_View->setCameraManipulator( m_Manipulator );
m_View->setCameraManipulator( manipulator );
// redraw request?? no since it redraws permanently and uses the new settings
}
osgGA::MatrixManipulator* WGEViewer::getCameraManipulator()
{
return m_Manipulator;
return m_View->getCameraManipulator();
}
void WGEViewer::setCamera( osg::Camera* camera )
{
m_View->setCamera( camera );
// redraw request?? no since it redraws permanently and uses the new settings
}
osg::Camera* WGEViewer::getCamera()
{
return m_View->getCamera();
}
void WGEViewer::setScene( osg::Node* node )
{
m_View->setSceneData( node );
}
osg::Node* WGEViewer::getNode()
{
return m_View->getSceneData();
}
void WGEViewer::paint()
......
......@@ -24,6 +24,8 @@
#ifndef WGEVIEWER_H
#define WGEVIEWER_H
#include <osg/Node>
#include <osgGA/TrackballManipulator>
#include <osgGA/FlightManipulator>
#include <osgGA/DriveManipulator>
......@@ -106,6 +108,38 @@ public:
*/
osgGA::MatrixManipulator* getCameraManipulator();
/**
* \par Description
* Sets the current camera.
*
* \param camera the OSG camera instance.
*/
void setCamera( osg::Camera* camera );
/**
* \par Description
* Returns the camera currently in use.
*
* \return the camera currently in use.
*/
osg::Camera* getCamera();
/**
* \par Description
* Sets the scene graph node to be used for rendering.
*
* \param node part of the scene graph
*/
void setScene( osg::Node* node );
/**
* \par Description
* Returns the currently set OSG node.
*
* \return the node.
*/
osg::Node* getNode();
protected:
/**
......@@ -120,11 +154,6 @@ protected:
*/
boost::shared_ptr<osgViewer::View> m_View;
/**
* \par Description
* The manipulator currently acitve.
*/
osgGA::MatrixManipulator* m_Manipulator;
private:
};
......
......@@ -21,17 +21,26 @@
//
//---------------------------------------------------------------------------
#include <iostream>
#include "exceptions/WGEInitFailed.h"
#include "../kernel/WKernel.h"
#include "WGraphicsEngine.h"
WGraphicsEngine::WGraphicsEngine()
WGraphicsEngine::WGraphicsEngine():
WThreadedRunner()
{
std::cout << "Initializing Graphics Engine" << std::endl;
// initialize members
m_RootNode = new WGEScene();
}
WGraphicsEngine::~WGraphicsEngine()
{
// cleanup