[Orxonox-commit 3275] r7966 - in code/branches/usability/src: libraries/core libraries/tools orxonox orxonox/gamestates orxonox/graphics
landauf at orxonox.net
landauf at orxonox.net
Sat Feb 26 17:00:18 CET 2011
Author: landauf
Date: 2011-02-26 17:00:17 +0100 (Sat, 26 Feb 2011)
New Revision: 7966
Added:
code/branches/usability/src/libraries/core/ViewportEventListener.cc
code/branches/usability/src/libraries/core/ViewportEventListener.h
Modified:
code/branches/usability/src/libraries/core/CMakeLists.txt
code/branches/usability/src/libraries/core/CorePrereqs.h
code/branches/usability/src/libraries/core/GraphicsManager.cc
code/branches/usability/src/libraries/tools/Shader.cc
code/branches/usability/src/libraries/tools/Shader.h
code/branches/usability/src/orxonox/CameraManager.cc
code/branches/usability/src/orxonox/CameraManager.h
code/branches/usability/src/orxonox/gamestates/GSMainMenu.cc
code/branches/usability/src/orxonox/graphics/Camera.cc
Log:
some changes related to camera switching:
- added ViewportEventListener (currently only listens to camera changes in a viewport)
- Shader now correctly updates its visibility if the camera changes the scene
- (the same lines of code also fix the weird Ogre behavior which was originally fixed in CameraManager)
- GraphicsManager also updates the GUIManager's camera
- if all cameras are destroyed, CameraManager now officially switches to NULL camera
Modified: code/branches/usability/src/libraries/core/CMakeLists.txt
===================================================================
--- code/branches/usability/src/libraries/core/CMakeLists.txt 2011-02-26 10:06:36 UTC (rev 7965)
+++ code/branches/usability/src/libraries/core/CMakeLists.txt 2011-02-26 16:00:17 UTC (rev 7966)
@@ -34,7 +34,6 @@
ObjectListBase.cc
OrxonoxClass.cc
Resource.cc
- WindowEventListener.cc
# hierarchy
Identifier.cc
@@ -48,7 +47,12 @@
NamespaceNode.cc
Template.cc
XMLPort.cc
+
+COMPILATION_BEGIN ListenerCompilation.cc
+ ViewportEventListener.cc
+ WindowEventListener.cc
XMLNameListener.cc
+COMPILATION_END
COMPILATION_BEGIN FilesystemCompilation.cc
command/ArgumentCompletionFunctions.cc
Modified: code/branches/usability/src/libraries/core/CorePrereqs.h
===================================================================
--- code/branches/usability/src/libraries/core/CorePrereqs.h 2011-02-26 10:06:36 UTC (rev 7965)
+++ code/branches/usability/src/libraries/core/CorePrereqs.h 2011-02-26 16:00:17 UTC (rev 7966)
@@ -181,6 +181,7 @@
class Template;
class Thread;
class ThreadPool;
+ class ViewportEventListener;
template <class T>
class WeakPtr;
class WindowEventListener;
Modified: code/branches/usability/src/libraries/core/GraphicsManager.cc
===================================================================
--- code/branches/usability/src/libraries/core/GraphicsManager.cc 2011-02-26 10:06:36 UTC (rev 7965)
+++ code/branches/usability/src/libraries/core/GraphicsManager.cc 2011-02-26 16:00:17 UTC (rev 7966)
@@ -56,9 +56,11 @@
#include "Core.h"
#include "Game.h"
#include "GameMode.h"
+#include "GUIManager.h"
#include "Loader.h"
#include "MemoryArchive.h"
#include "PathConfig.h"
+#include "ViewportEventListener.h"
#include "WindowEventListener.h"
#include "XMLFile.h"
#include "command/ConsoleCommand.h"
@@ -380,7 +382,13 @@
void GraphicsManager::setCamera(Ogre::Camera* camera)
{
+ Ogre::Camera* oldCamera = this->viewport_->getCamera();
+
this->viewport_->setCamera(camera);
+ GUIManager::getInstance().setCamera(camera);
+
+ for (ObjectList<ViewportEventListener>::iterator it = ObjectList<ViewportEventListener>::begin(); it != ObjectList<ViewportEventListener>::end(); ++it)
+ it->cameraChanged(this->viewport_, oldCamera);
}
/**
Added: code/branches/usability/src/libraries/core/ViewportEventListener.cc
===================================================================
--- code/branches/usability/src/libraries/core/ViewportEventListener.cc (rev 0)
+++ code/branches/usability/src/libraries/core/ViewportEventListener.cc 2011-02-26 16:00:17 UTC (rev 7966)
@@ -0,0 +1,38 @@
+/*
+ * ORXONOX - the hottest 3D action shooter ever to exist
+ * > www.orxonox.net <
+ *
+ *
+ * License notice:
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Author:
+ * Fabian 'x3n' Landau
+ * Co-authors:
+ * ...
+ *
+ */
+
+#include "ViewportEventListener.h"
+#include "CoreIncludes.h"
+
+namespace orxonox
+{
+ ViewportEventListener::ViewportEventListener()
+ {
+ RegisterRootObject(ViewportEventListener);
+ }
+}
Property changes on: code/branches/usability/src/libraries/core/ViewportEventListener.cc
___________________________________________________________________
Added: svn:eol-style
+ native
Added: code/branches/usability/src/libraries/core/ViewportEventListener.h
===================================================================
--- code/branches/usability/src/libraries/core/ViewportEventListener.h (rev 0)
+++ code/branches/usability/src/libraries/core/ViewportEventListener.h 2011-02-26 16:00:17 UTC (rev 7966)
@@ -0,0 +1,50 @@
+/*
+ * ORXONOX - the hottest 3D action shooter ever to exist
+ * > www.orxonox.net <
+ *
+ *
+ * License notice:
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Author:
+ * Fabian 'x3n' Landau
+ * Co-authors:
+ * ...
+ *
+ */
+
+#ifndef _ViewportEventListener_H__
+#define _ViewportEventListener_H__
+
+#include "util/OgreForwardRefs.h"
+
+#include "CorePrereqs.h"
+#include "OrxonoxClass.h"
+
+namespace orxonox
+{
+ class _CoreExport ViewportEventListener : virtual public OrxonoxClass
+ {
+ public:
+ virtual void cameraChanged(Ogre::Viewport* viewport, Ogre::Camera* oldCamera) {}
+
+ protected:
+ ViewportEventListener();
+ virtual ~ViewportEventListener() {}
+ };
+}
+
+#endif /* _ViewportEventListener_H__ */
Property changes on: code/branches/usability/src/libraries/core/ViewportEventListener.h
___________________________________________________________________
Added: svn:eol-style
+ native
Modified: code/branches/usability/src/libraries/tools/Shader.cc
===================================================================
--- code/branches/usability/src/libraries/tools/Shader.cc 2011-02-26 10:06:36 UTC (rev 7965)
+++ code/branches/usability/src/libraries/tools/Shader.cc 2011-02-26 16:00:17 UTC (rev 7966)
@@ -55,7 +55,7 @@
this->compositorInstance_ = 0;
this->bVisible_ = true;
this->bLoadCompositor_ = GameMode::showsGraphics();
- this->bViewportInitialized_ = false;
+ this->bViewportInitialized_ = true;
if (this->bLoadCompositor_ && Ogre::Root::getSingletonPtr())
{
@@ -88,9 +88,33 @@
void Shader::setSceneManager(Ogre::SceneManager* scenemanager)
{
this->scenemanager_ = scenemanager;
- this->bViewportInitialized_ = false;
+// this->bViewportInitialized_ = false;
}
+ void Shader::cameraChanged(Ogre::Viewport* viewport, Ogre::Camera* oldCamera)
+ {
+ if (!this->scenemanager_ || (viewport != this->scenemanager_->getCurrentViewport() && this->scenemanager_->getCurrentViewport() != NULL))
+ return;
+
+ // update compositor in viewport (shader should only be active if the current camera is in the same scene as the shader)
+
+ // Note:
+ // The shader needs also to be switched off and on after changing the camera in the
+ // same scene to avoid weird behaviour with active compositors while switching the
+ // camera (like freezing the image)
+ //
+ // Last known Ogre version needing this workaround:
+ // 1.4.8
+ // 1.7.2
+
+
+ if (oldCamera && this->scenemanager_ == oldCamera->getSceneManager())
+ Ogre::CompositorManager::getSingleton().setCompositorEnabled(viewport, this->compositor_, false);
+
+ if (viewport->getCamera() && this->scenemanager_ == viewport->getCamera()->getSceneManager())
+ Ogre::CompositorManager::getSingleton().setCompositorEnabled(viewport, this->compositor_, this->isVisible());
+ }
+/*
void Shader::tick(float dt)
{
SUPER(Shader, tick, dt);
@@ -101,7 +125,7 @@
this->updateVisibility();
}
}
-
+*/
void Shader::changedCompositor()
{
if (this->bLoadCompositor_)
@@ -118,7 +142,7 @@
this->compositorInstance_ = Ogre::CompositorManager::getSingleton().addCompositor(viewport, this->compositor_);
if (!this->compositorInstance_)
COUT(2) << "Warning: Couldn't load compositor with name \"" << this->compositor_ << "\"." << std::endl;
- Ogre::CompositorManager::getSingleton().setCompositorEnabled(viewport, this->compositor_, this->bViewportInitialized_ && this->isVisible());
+ //Ogre::CompositorManager::getSingleton().setCompositorEnabled(viewport, this->compositor_, this->bViewportInitialized_ && this->isVisible());
}
this->oldcompositor_ = this->compositor_;
}
Modified: code/branches/usability/src/libraries/tools/Shader.h
===================================================================
--- code/branches/usability/src/libraries/tools/Shader.h 2011-02-26 10:06:36 UTC (rev 7965)
+++ code/branches/usability/src/libraries/tools/Shader.h 2011-02-26 16:00:17 UTC (rev 7966)
@@ -36,11 +36,11 @@
#include <vector>
#include "util/OgreForwardRefs.h"
-#include "tools/interfaces/Tickable.h"
+#include "core/ViewportEventListener.h"
namespace orxonox
{
- class _ToolsExport Shader : public Tickable
+ class _ToolsExport Shader : public ViewportEventListener
{
typedef std::pair<bool, void*> ParameterPointer;
typedef std::map<std::string, ParameterPointer> ParameterMap;
@@ -52,8 +52,6 @@
Shader(Ogre::SceneManager* scenemanager = 0);
virtual ~Shader();
- virtual void tick(float dt);
-
inline void setVisible(bool bVisible)
{
if (this->bVisible_ != bVisible)
@@ -82,6 +80,8 @@
inline Ogre::SceneManager* getSceneManager() const
{ return this->scenemanager_; }
+ virtual void cameraChanged(Ogre::Viewport* viewport, Ogre::Camera* oldCamera);
+
void setParameter(const std::string& material, size_t technique, size_t pass, const std::string& parameter, float value);
void setParameter(const std::string& material, size_t technique, size_t pass, const std::string& parameter, int value);
Modified: code/branches/usability/src/orxonox/CameraManager.cc
===================================================================
--- code/branches/usability/src/orxonox/CameraManager.cc 2011-02-26 10:06:36 UTC (rev 7965)
+++ code/branches/usability/src/orxonox/CameraManager.cc 2011-02-26 16:00:17 UTC (rev 7966)
@@ -28,33 +28,30 @@
#include "CameraManager.h"
+#include <cassert>
+
#include <OgreSceneManager.h>
#include <OgreViewport.h>
#include <OgreCompositorManager.h>
-#include "util/StringUtils.h"
#include "util/ScopedSingletonManager.h"
#include "core/GameMode.h"
#include "core/GraphicsManager.h"
-#include "core/GUIManager.h"
#include "core/ObjectList.h"
#include "tools/Shader.h"
#include "graphics/Camera.h"
-#include "Scene.h"
namespace orxonox
{
ManageScopedSingleton(CameraManager, ScopeID::Graphics, false);
CameraManager::CameraManager()
- : viewport_(GraphicsManager::getInstance().getViewport())
{
assert(GameMode::showsGraphics());
}
CameraManager::~CameraManager()
{
- GUIManager::getInstance().setCamera(0);
}
Camera* CameraManager::getActiveCamera() const
@@ -94,6 +91,8 @@
// set new focus if possible
if (!this->cameraList_.empty())
this->cameraList_.front()->setFocus();
+ else
+ this->useCamera(NULL);
}
else
this->cameraList_.remove(camera);
@@ -101,27 +100,6 @@
void CameraManager::useCamera(Ogre::Camera* camera)
{
- // This workaround is needed to avoid weird behaviour with active compositors while
- // switching the camera (like freezing the image)
- //
- // Last known Ogre version needing this workaround:
- // 1.4.8
- // 1.7.2
-
- // deactivate all compositors
- {
- Ogre::ResourceManager::ResourceMapIterator iterator = Ogre::CompositorManager::getSingleton().getResourceIterator();
- while (iterator.hasMoreElements())
- Ogre::CompositorManager::getSingleton().setCompositorEnabled(this->viewport_, iterator.getNext()->getName(), false);
- }
-
- this->viewport_->setCamera(camera);
- GUIManager::getInstance().setCamera(camera);
-
- // reactivate all visible compositors
- {
- for (ObjectList<Shader>::iterator it = ObjectList<Shader>::begin(); it != ObjectList<Shader>::end(); ++it)
- it->updateVisibility();
- }
+ GraphicsManager::getInstance().setCamera(camera);
}
}
Modified: code/branches/usability/src/orxonox/CameraManager.h
===================================================================
--- code/branches/usability/src/orxonox/CameraManager.h 2011-02-26 10:06:36 UTC (rev 7965)
+++ code/branches/usability/src/orxonox/CameraManager.h 2011-02-26 16:00:17 UTC (rev 7966)
@@ -37,12 +37,10 @@
#include "OrxonoxPrereqs.h"
-#include <cassert>
#include <list>
#include "util/OgreForwardRefs.h"
#include "util/Singleton.h"
#include "core/OrxonoxClass.h"
-#include "core/SmartPtr.h"
namespace orxonox
{
@@ -64,7 +62,6 @@
CameraManager(const CameraManager&); // don't use
std::list<Camera*> cameraList_;
- Ogre::Viewport* viewport_;
static CameraManager* singletonPtr_s;
};
Modified: code/branches/usability/src/orxonox/gamestates/GSMainMenu.cc
===================================================================
--- code/branches/usability/src/orxonox/gamestates/GSMainMenu.cc 2011-02-26 10:06:36 UTC (rev 7965)
+++ code/branches/usability/src/orxonox/gamestates/GSMainMenu.cc 2011-02-26 16:00:17 UTC (rev 7966)
@@ -95,10 +95,9 @@
void GSMainMenu::activate()
{
// show main menu
+ GraphicsManager::getInstance().setCamera(this->camera_);
GUIManager::getInstance().showGUI("MainMenu", true);
- GUIManager::getInstance().setCamera(this->camera_);
GUIManager::getInstance().setBackgroundImage("MainMenuBackground", "Background");
- GraphicsManager::getInstance().setCamera(this->camera_);
InputManager::getInstance().enterState("MainMenuHackery");
@@ -128,10 +127,9 @@
InputManager::getInstance().leaveState("MainMenuHackery");
- GUIManager::getInstance().setCamera(0);
+ GraphicsManager::getInstance().setCamera(0);
GUIManager::getInstance().setBackgroundImage("");
GUIManager::hideGUI("MainMenu");
- GraphicsManager::getInstance().setCamera(0);
ModifyConsoleCommand(__CC_startStandalone_name).deactivate();
ModifyConsoleCommand(__CC_startServer_name ).deactivate();
Modified: code/branches/usability/src/orxonox/graphics/Camera.cc
===================================================================
--- code/branches/usability/src/orxonox/graphics/Camera.cc 2011-02-26 10:06:36 UTC (rev 7965)
+++ code/branches/usability/src/orxonox/graphics/Camera.cc 2011-02-26 16:00:17 UTC (rev 7966)
@@ -81,8 +81,6 @@
{
if (this->isInitialized())
{
- if (GUIManager::getInstance().getCamera() == this->camera_)
- GUIManager::getInstance().setCamera(NULL);
this->releaseFocus();
this->cameraNode_->detachAllObjects();
More information about the Orxonox-commit
mailing list