From 13d3f9c87eaf42661a61ddd50f72e0bfff556ba5 Mon Sep 17 00:00:00 2001 From: Nicolay Korslund Date: Fri, 16 Jul 2010 14:26:46 +0200 Subject: [PATCH] Integrated OpenEngine, replaces entire components/engine/ directory. --- CMakeLists.txt | 51 +++----- apps/mygui_dev/CMakeLists.txt | 4 +- apps/mygui_dev/main.cpp | 14 ++- apps/openmw/engine.hpp | 4 +- apps/openmw/mwinput/inputmanager.hpp | 57 ++++++--- apps/openmw/mwrender/interior.cpp | 5 +- apps/openmw/mwrender/mwscene.cpp | 2 +- apps/openmw/mwrender/mwscene.hpp | 6 +- apps/openmw/mwworld/world.cpp | 3 +- apps/openmw/mwworld/world.hpp | 2 +- components/engine/gui/layout.hpp | 118 ------------------ components/engine/gui/manager.cpp | 43 ------- components/engine/gui/manager.hpp | 33 ----- components/engine/input/dispatch_map.hpp | 75 ----------- components/engine/input/dispatcher.hpp | 44 ------- components/engine/input/func_binder.hpp | 104 --------------- components/engine/input/listener.hpp | 113 ----------------- components/engine/input/oismanager.cpp | 89 ------------- components/engine/input/oismanager.hpp | 19 --- components/engine/input/poller.hpp | 51 -------- components/engine/input/tests/.gitignore | 2 - components/engine/input/tests/Makefile | 12 -- .../engine/input/tests/dispatch_map_test.cpp | 54 -------- .../engine/input/tests/funcbind_test.cpp | 47 ------- .../input/tests/output/dispatch_map_test.out | 18 --- .../input/tests/output/funcbind_test.out | 15 --- components/engine/input/tests/test.sh | 18 --- components/engine/ogre/.gitignore | 1 - components/engine/ogre/renderer.cpp | 80 ------------ components/engine/ogre/renderer.hpp | 77 ------------ components/mw_gui/mw_layouts.hpp | 10 +- libs/openengine | 2 +- 32 files changed, 89 insertions(+), 1084 deletions(-) delete mode 100644 components/engine/gui/layout.hpp delete mode 100644 components/engine/gui/manager.cpp delete mode 100644 components/engine/gui/manager.hpp delete mode 100644 components/engine/input/dispatch_map.hpp delete mode 100644 components/engine/input/dispatcher.hpp delete mode 100644 components/engine/input/func_binder.hpp delete mode 100644 components/engine/input/listener.hpp delete mode 100644 components/engine/input/oismanager.cpp delete mode 100644 components/engine/input/oismanager.hpp delete mode 100644 components/engine/input/poller.hpp delete mode 100644 components/engine/input/tests/.gitignore delete mode 100644 components/engine/input/tests/Makefile delete mode 100644 components/engine/input/tests/dispatch_map_test.cpp delete mode 100644 components/engine/input/tests/funcbind_test.cpp delete mode 100644 components/engine/input/tests/output/dispatch_map_test.out delete mode 100644 components/engine/input/tests/output/funcbind_test.out delete mode 100755 components/engine/input/tests/test.sh delete mode 100644 components/engine/ogre/.gitignore delete mode 100644 components/engine/ogre/renderer.cpp delete mode 100644 components/engine/ogre/renderer.hpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 42efa8f77..381659c4d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -50,36 +50,11 @@ source_group(components\\esm_store FILES ${ESM_STORE} ${ESM_STORE_HEADER}) file(GLOB ESM_HEADER ${COMP_DIR}/esm/*.hpp) source_group(components\\esm FILES ${ESM_HEADER}) -set(OGRE - ${COMP_DIR}/engine/ogre/renderer.cpp) -set(OGRE_HEADER - ${COMP_DIR}/engine/ogre/renderer.hpp) -source_group(components\\engine\\ogre FILES ${OGRE} ${OGRE_HEADER}) - # components/mw_gui set(MWGUI_HEADER ${COMP_DIR}/mw_gui/mw_layouts.hpp) source_group(components\\mw_gui FILES ${MWGUI_HEADER}) -# components/engine/gui -set(EGUI - ${COMP_DIR}/engine/gui/manager.cpp) -set(EGUI_HEADER - ${COMP_DIR}/engine/gui/manager.hpp - ${COMP_DIR}/engine/gui/layout.hpp) -source_group(components\\engine\\gui FILES ${EGUI} ${EGUI_HEADER}) - -set(INPUT - ${COMP_DIR}/engine/input/oismanager.cpp) -set(INPUT_HEADER - ${COMP_DIR}/engine/input/oismanager.hpp - ${COMP_DIR}/engine/input/listener.hpp - ${COMP_DIR}/engine/input/func_binder.hpp - ${COMP_DIR}/engine/input/dispatch_map.hpp - ${COMP_DIR}/engine/input/dispatcher.hpp - ${COMP_DIR}/engine/input/poller.hpp) -source_group(components\\engine\\input FILES ${INPUT} ${INPUT_HEADER}) - set(COMMANDSERVER ${COMP_DIR}/commandserver/command.hpp ${COMP_DIR}/commandserver/server.hpp @@ -104,22 +79,35 @@ file(GLOB INTERPRETER ${COMP_DIR}/interpreter/*.cpp) file(GLOB INTERPRETER_HEADER ${COMP_DIR}/interpreter/*.hpp) source_group(components\\interpreter FILES ${INTERPRETER} ${INTERPRETER_HEADER}) -set(COMPONENTS ${BSA} ${NIF} ${NIFOGRE} ${ESM_STORE} ${OGRE} ${INPUT} ${MISC} - ${EGUI} +set(COMPONENTS ${BSA} ${NIF} ${NIFOGRE} ${ESM_STORE} ${MISC} ${COMMANDSERVER} ${COMPILER} ${INTERPRETER}) set(COMPONENTS_HEADER ${BSA_HEADER} ${NIF_HEADER} ${NIFOGRE_HEADER} ${ESM_STORE_HEADER} - ${ESM_HEADER} ${OGRE_HEADER} ${INPUT_HEADER} ${MISC_HEADER} ${COMPILER_HEADER} - ${INTERPRETER_HEADER} ${EGUI_HEADER} ${MWGUI_HEADER}) + ${ESM_HEADER} ${MISC_HEADER} ${COMPILER_HEADER} + ${INTERPRETER_HEADER} ${MWGUI_HEADER}) # source directory: libs set(LIBDIR ${CMAKE_SOURCE_DIR}/libs) + set(MANGLE_VFS ${LIBDIR}/mangle/vfs/servers/ogre_vfs.cpp) -source_group(libs\\mangle_vfs FILES ${MANGLE_VFS}) +set(MANGLE_INPUT ${LIBDIR}/mangle/input/servers/ois_driver.cpp) +set(MANGLE_ALL ${MANGLE_VFS} ${MANGLE_INPUT}) +source_group(libs\\mangle FILES ${MANGLE_ALL}) -set(OPENMW_LIBS ${MANGLE_VFS}) +set(OENGINE_OGRE + ${LIBDIR}/openengine/ogre/renderer.cpp + ${LIBDIR}/openengine/ogre/mouselook.cpp +) +set(OENGINE_GUI +# ${LIBDIR}/openengine/gui/events.cpp + ${LIBDIR}/openengine/gui/manager.cpp +) # Not yet included in main executable +set(OENGINE_ALL ${OENGINE_OGRE}) +source_group(libs\\openengine FILES ${OENGINE_ALL}) + +set(OPENMW_LIBS ${MANGLE_ALL} ${OENGINE_ALL}) set(OPENMW_LIBS_HEADER) # Platform specific @@ -142,6 +130,7 @@ include_directories("." ${CMAKE_HOME_DIRECTORY}/extern/caelum/include ${CMAKE_HOME_DIRECTORY}/extern/mygui_3.0.1/MyGUIEngine/include ${CMAKE_HOME_DIRECTORY}/extern/mygui_3.0.1/OgrePlatform/include + ${LIBDIR} ) diff --git a/apps/mygui_dev/CMakeLists.txt b/apps/mygui_dev/CMakeLists.txt index dd3ecb228..0219bd2c6 100644 --- a/apps/mygui_dev/CMakeLists.txt +++ b/apps/mygui_dev/CMakeLists.txt @@ -1,8 +1,8 @@ add_executable(mygui_test main.cpp ${BSA} ${BSA_HEADER} - ${OGRE} ${OGRE_HEADER} - ${EGUI} ${EGUI_HEADER} + ${OENGINE_OGRE} + ${OENGINE_GUI} ) target_link_libraries(mygui_test ${OGRE_LIBRARIES} diff --git a/apps/mygui_dev/main.cpp b/apps/mygui_dev/main.cpp index 1a8c4c6a1..96412e5fd 100644 --- a/apps/mygui_dev/main.cpp +++ b/apps/mygui_dev/main.cpp @@ -1,14 +1,16 @@ #include using namespace std; -#include +#include +#include + #include +#include -#include #include #include - -#include +#include +#include // Frame listener struct Listener : public Ogre::FrameListener @@ -40,7 +42,7 @@ struct Listener : public Ogre::FrameListener int main() { - Render::OgreRenderer ogre; + OEngine::Render::OgreRenderer ogre; ogre.configure(false, "plugins.cfg", false); ogre.createWindow("MyGUI test"); ogre.createScene(); @@ -60,7 +62,7 @@ int main() // Make sure you load the data paths BEFORE you initialize the // GUI. MyGUI depends on finding core.xml in resources/mygui/. cout << "Setting up MyGUI\n"; - GUI::MyGUIManager gui(ogre.getWindow(), ogre.getScene()); + OEngine::GUI::MyGUIManager gui(ogre.getWindow(), ogre.getScene()); int w = ogre.getWindow()->getWidth(); int h = ogre.getWindow()->getHeight(); diff --git a/apps/openmw/engine.hpp b/apps/openmw/engine.hpp index cf982ad0e..e4b6073cf 100644 --- a/apps/openmw/engine.hpp +++ b/apps/openmw/engine.hpp @@ -7,7 +7,7 @@ #include -#include +#include #include #include #include @@ -44,7 +44,7 @@ namespace OMW enum { kCommandServerPort = 27917 }; boost::filesystem::path mDataDir; - Render::OgreRenderer mOgre; + OEngine::Render::OgreRenderer mOgre; std::string mCellName; std::string mMaster; bool mDebug; diff --git a/apps/openmw/mwinput/inputmanager.hpp b/apps/openmw/mwinput/inputmanager.hpp index e1b22453a..b1cd82749 100644 --- a/apps/openmw/mwinput/inputmanager.hpp +++ b/apps/openmw/mwinput/inputmanager.hpp @@ -1,18 +1,24 @@ #ifndef _MWINPUT_MWINPUTMANAGER_H #define _MWINPUT_MWINPUTMANAGER_H -#include -#include +#include +#include -#include -#include +#include +#include +#include -#include +#include +#include #include #include #include "../mwrender/playerpos.hpp" +#include + +#include + namespace MWInput { enum Actions @@ -34,10 +40,12 @@ namespace MWInput // Class that handles all input and key bindings for OpenMW class MWInputManager : public Ogre::FrameListener { - Mangle::Input::EventPtr disp; - Render::OgreRenderer &ogre; + OEngine::Input::DispatcherPtr disp; + OEngine::Render::OgreRenderer &ogre; + OEngine::Render::ExitListener exit; Mangle::Input::OISDriver input; OEngine::Input::Poller poller; + OEngine::Render::MouseLookEventPtr mouse; MWRender::PlayerPos &player; // Count screenshots. TODO: We should move this functionality to @@ -59,35 +67,52 @@ namespace MWInput } public: - MWInputManager(Render::OgreRenderer &_ogre, + MWInputManager(OEngine::Render::OgreRenderer &_ogre, MWRender::PlayerPos &_player, bool debug) : ogre(_ogre), + exit(ogre.getWindow()), input(ogre.getWindow(), !debug), poller(input), player(_player), shotCount(0) { using namespace OEngine::Input; + using namespace OEngine::Render; + using namespace Mangle::Input; using namespace OIS; - disp = EventPtr(new Dispatcher(A_LAST)); + disp = DispatcherPtr(new Dispatcher(A_LAST)); // Bind MW-specific functions - disp->funcs.bind(A_Quit, boost::bind(&InputListener::exitNow, &listener), + disp->funcs.bind(A_Quit, boost::bind(&ExitListener::exitNow, &exit), "Quit program"); disp->funcs.bind(A_Screenshot, boost::bind(&MWInputManager::screenshot, this), "Screenshot"); - // Add ourselves as a frame listener, to catch movement keys + + // Add the exit listener + ogre.getRoot()->addFrameListener(&exit); + // Add ourselves as a frame listener to catch movement keys ogre.getRoot()->addFrameListener(this); - // Tell the input listener about the camera - listener.setCamera(player.getCamera()); + // Set up the mouse handler and tell it about the player camera + mouse = MouseLookEventPtr(new MouseLookEvent(player.getCamera())); + + // Hook 'mouse' and 'disp' up as event handlers into 'input' + // (the OIS driver and event source.) We do this through an + // EventList which dispatches the event to multiple handlers for + // us. + { + EventList *lst = new EventList; + input.setEvent(EventPtr(lst)); + lst->add(mouse,Event::EV_MouseMove); + lst->add(disp,Event::EV_KeyDown); + } // Key bindings - disp->bind(KC_Q, A_Quit); - disp->bind(KC_ESCAPE, A_Quit); - disp->bind(KC_SYSRQ, A_Screenshot); + disp->bind(A_Quit, KC_Q); + disp->bind(A_Quit, KC_ESCAPE); + disp->bind(A_Screenshot, KC_SYSRQ); // Key bindings for polled keys diff --git a/apps/openmw/mwrender/interior.cpp b/apps/openmw/mwrender/interior.cpp index a2f55880b..7f361141a 100644 --- a/apps/openmw/mwrender/interior.cpp +++ b/apps/openmw/mwrender/interior.cpp @@ -2,8 +2,11 @@ #include #include +#include +#include +#include -#include "components/nifogre/ogre_nif_loader.hpp" +#include #include "mwscene.hpp" using namespace MWRender; diff --git a/apps/openmw/mwrender/mwscene.cpp b/apps/openmw/mwrender/mwscene.cpp index 0424647e1..489b5f242 100644 --- a/apps/openmw/mwrender/mwscene.cpp +++ b/apps/openmw/mwrender/mwscene.cpp @@ -12,7 +12,7 @@ using namespace MWRender; using namespace Ogre; -MWScene::MWScene(Render::OgreRenderer &_rend) +MWScene::MWScene(OEngine::Render::OgreRenderer &_rend) : rend(_rend) { rend.createScene("PlayerCam", 55, 5); diff --git a/apps/openmw/mwrender/mwscene.hpp b/apps/openmw/mwrender/mwscene.hpp index d65b7944b..a7339e1c8 100644 --- a/apps/openmw/mwrender/mwscene.hpp +++ b/apps/openmw/mwrender/mwscene.hpp @@ -1,7 +1,7 @@ #ifndef _GAME_RENDER_MWSCENE_H #define _GAME_RENDER_MWSCENE_H -#include "components/engine/ogre/renderer.hpp" +#include namespace Ogre { @@ -20,7 +20,7 @@ namespace MWRender */ class MWScene { - Render::OgreRenderer &rend; + OEngine::Render::OgreRenderer &rend; // Root node for all objects added to the scene. This is rotated so // that the OGRE coordinate system matches that used internally in @@ -28,7 +28,7 @@ namespace MWRender Ogre::SceneNode *mwRoot; public: - MWScene(Render::OgreRenderer &_rend); + MWScene(OEngine::Render::OgreRenderer &_rend); Ogre::Camera *getCamera() { return rend.getCamera(); } Ogre::SceneNode *getRoot() { return mwRoot; } diff --git a/apps/openmw/mwworld/world.cpp b/apps/openmw/mwworld/world.cpp index 840a88d7d..a4c95fbf4 100644 --- a/apps/openmw/mwworld/world.cpp +++ b/apps/openmw/mwworld/world.cpp @@ -4,7 +4,6 @@ #include #include "components/bsa/bsa_archive.hpp" -#include "components/engine/ogre/renderer.hpp" #include "apps/openmw/mwrender/sky.hpp" #include "apps/openmw/mwrender/interior.hpp" @@ -142,7 +141,7 @@ namespace MWWorld return 0; } - World::World (Render::OgreRenderer& renderer, const boost::filesystem::path& dataDir, + World::World (OEngine::Render::OgreRenderer& renderer, const boost::filesystem::path& dataDir, const std::string& master, const std::string& startCell, bool newGame) : mSkyManager (0), mScene (renderer), mPlayerPos (0), mCurrentCell (0) { diff --git a/apps/openmw/mwworld/world.hpp b/apps/openmw/mwworld/world.hpp index d6df3b826..3a40d8da9 100644 --- a/apps/openmw/mwworld/world.hpp +++ b/apps/openmw/mwworld/world.hpp @@ -65,7 +65,7 @@ namespace MWWorld public: - World (Render::OgreRenderer& renderer, const boost::filesystem::path& master, + World (OEngine::Render::OgreRenderer& renderer, const boost::filesystem::path& master, const std::string& dataDir, const std::string& startCell, bool newGame); ~World(); diff --git a/components/engine/gui/layout.hpp b/components/engine/gui/layout.hpp deleted file mode 100644 index ddd6887eb..000000000 --- a/components/engine/gui/layout.hpp +++ /dev/null @@ -1,118 +0,0 @@ -#ifndef ENGINE_MYGUI_LAYOUT_H -#define ENGINE_MYGUI_LAYOUT_H - -#include -#include - -namespace GUI -{ - /** The Layout class is an utility class used to load MyGUI layouts - from xml files, and to manipulate member widgets. - */ - class Layout - { - public: - Layout(const std::string & _layout, MyGUI::WidgetPtr _parent = nullptr) - : mMainWidget(nullptr) - { initialise(_layout, _parent); } - virtual ~Layout() { shutdown(); } - - template - void getWidget(T * & _widget, const std::string & _name, bool _throw = true) - { - _widget = nullptr; - for (MyGUI::VectorWidgetPtr::iterator iter=mListWindowRoot.begin(); - iter!=mListWindowRoot.end(); ++iter) - { - MyGUI::WidgetPtr find = (*iter)->findWidget(mPrefix + _name); - if (nullptr != find) - { - T * cast = find->castType(false); - if (nullptr != cast) - _widget = cast; - else if (_throw) - { - MYGUI_EXCEPT("Error cast : dest type = '" << T::getClassTypeName() - << "' source name = '" << find->getName() - << "' source type = '" << find->getTypeName() << "' in layout '" << mLayoutName << "'"); - } - return; - } - } - MYGUI_ASSERT( ! _throw, "widget name '" << _name << "' in layout '" << mLayoutName << "' not found."); - } - - void initialise(const std::string & _layout, - MyGUI::WidgetPtr _parent = nullptr) - { - const std::string MAIN_WINDOW = "_Main"; - mLayoutName = _layout; - - if (mLayoutName.empty()) - mMainWidget = _parent; - else - { - mPrefix = MyGUI::utility::toString(this, "_"); - mListWindowRoot = MyGUI::LayoutManager::getInstance().loadLayout(mLayoutName, mPrefix, _parent); - - const std::string main_name = mPrefix + MAIN_WINDOW; - for (MyGUI::VectorWidgetPtr::iterator iter=mListWindowRoot.begin(); iter!=mListWindowRoot.end(); ++iter) - { - if ((*iter)->getName() == main_name) - { - mMainWidget = (*iter); - break; - } - } - MYGUI_ASSERT(mMainWidget, "root widget name '" << MAIN_WINDOW << "' in layout '" << mLayoutName << "' not found."); - } - } - - void shutdown() - { - MyGUI::LayoutManager::getInstance().unloadLayout(mListWindowRoot); - mListWindowRoot.clear(); - } - - void setCoord(int x, int y, int w, int h) - { - mMainWidget->setCoord(x,y,w,h); - } - - void setVisible(bool b) - { - mMainWidget->setVisible(b); - } - - void setText(const std::string& name, const std::string& caption) - { - MyGUI::WidgetPtr pt; - getWidget(pt, name); - pt->setCaption(caption); - } - - void setTextColor(const std::string& name, float r, float g, float b) - { - MyGUI::WidgetPtr pt; - getWidget(pt, name); - MyGUI::StaticText *st = dynamic_cast(pt); - if(st != NULL) - st->setTextColour(MyGUI::Colour(b,g,r)); - } - - void setImage(const std::string& name, const std::string& imgName) - { - MyGUI::StaticImagePtr pt; - getWidget(pt, name); - pt->setImageTexture(imgName); - } - - protected: - - MyGUI::WidgetPtr mMainWidget; - std::string mPrefix; - std::string mLayoutName; - MyGUI::VectorWidgetPtr mListWindowRoot; - }; -} -#endif diff --git a/components/engine/gui/manager.cpp b/components/engine/gui/manager.cpp deleted file mode 100644 index e5e01e7d7..000000000 --- a/components/engine/gui/manager.cpp +++ /dev/null @@ -1,43 +0,0 @@ -#include -#include -#include - -#include "manager.hpp" - -using namespace GUI; - -void MyGUIManager::setup(Ogre::RenderWindow *wnd, Ogre::SceneManager *mgr, bool logging) -{ - assert(wnd); - assert(mgr); - - using namespace MyGUI; - - // Enable/disable MyGUI logging to stdout. (Logging to MyGUI.log is - // still enabled.) In order to do this we have to initialize the log - // manager before the main gui system itself, otherwise the main - // object will get the chance to spit out a few messages before we - // can able to disable it. - LogManager::initialise(); - LogManager::setSTDOutputEnabled(logging); - - // Set up OGRE platform. We might make this more generic later. - mPlatform = new OgrePlatform(); - mPlatform->initialise(wnd, mgr); - - // Create GUI - mGui = new Gui(); - mGui->initialise(); -} - -void MyGUIManager::shutdown() -{ - if(mGui) delete mGui; - if(mPlatform) - { - mPlatform->shutdown(); - delete mPlatform; - } - mGui = NULL; - mPlatform = NULL; -} diff --git a/components/engine/gui/manager.hpp b/components/engine/gui/manager.hpp deleted file mode 100644 index 72843eccc..000000000 --- a/components/engine/gui/manager.hpp +++ /dev/null @@ -1,33 +0,0 @@ -#ifndef ENGINE_MYGUI_MANAGER_H -#define ENGINE_MYGUI_MANAGER_H - -namespace MyGUI -{ - class OgrePlatform; - class Gui; -} - -namespace Ogre -{ - class RenderWindow; - class SceneManager; -} - -namespace GUI -{ - class MyGUIManager - { - MyGUI::OgrePlatform *mPlatform; - MyGUI::Gui *mGui; - - public: - MyGUIManager() : mPlatform(NULL), mGui(NULL) {} - MyGUIManager(Ogre::RenderWindow *wnd, Ogre::SceneManager *mgr, bool logging=false) - { setup(wnd,mgr,logging); } - ~MyGUIManager() { shutdown(); } - - void setup(Ogre::RenderWindow *wnd, Ogre::SceneManager *mgr, bool logging=false); - void shutdown(); - }; -} -#endif diff --git a/components/engine/input/dispatch_map.hpp b/components/engine/input/dispatch_map.hpp deleted file mode 100644 index 356660e75..000000000 --- a/components/engine/input/dispatch_map.hpp +++ /dev/null @@ -1,75 +0,0 @@ -#ifndef _INPUT_DISPATCHMAP_H -#define _INPUT_DISPATCHMAP_H - -#include -#include -#include - -namespace Input { - -/** - DispatchMap is a simple connection system that connects incomming - signals with outgoing signals. - - The signals can be connected one-to-one, many-to-one, one-to-many - or many-to-many. - - The dispatch map is completely system agnostic. It is a pure data - structure and all signals are just integer indices. It does not - delegate any actions, but used together with Dispatcher it can be - used to build an event system. - */ -struct DispatchMap -{ - typedef std::set OutList; - typedef std::map InMap; - - typedef OutList::iterator Oit; - typedef InMap::iterator Iit; - - InMap map; - - void bind(int in, int out) - { - map[in].insert(out); - } - - void unbind(int in, int out) - { - Iit it = map.find(in); - if(it != map.end()) - { - it->second.erase(out); - - // If there are no more elements, then remove the entire list - if(it->second.empty()) - map.erase(it); - } - } - - /// Check if a given input is bound to anything - bool isBound(int in) const - { - return map.find(in) != map.end(); - } - - /** - Get the list of outputs bound to the given input. Only call this - on inputs that you know are bound to something. - - The returned set is only intended for immediate iteration. Do not - store references to it. - */ - const OutList &getList(int in) const - { - assert(isBound(in)); - InMap::const_iterator it = map.find(in); - assert(it != map.end()); - const OutList &out = it->second; - assert(!out.empty()); - return out; - } -}; - -} -#endif diff --git a/components/engine/input/dispatcher.hpp b/components/engine/input/dispatcher.hpp deleted file mode 100644 index a749783b1..000000000 --- a/components/engine/input/dispatcher.hpp +++ /dev/null @@ -1,44 +0,0 @@ -#ifndef _INPUT_DISPATCHER_H -#define _INPUT_DISPATCHER_H - -#include "dispatch_map.hpp" -#include "func_binder.hpp" - -namespace Input { - -struct Dispatcher -{ - DispatchMap map; - FuncBinder funcs; - - /** - Constructor. Takes the number of actions and passes it to - FuncBinder. - */ - Dispatcher(int actions) : funcs(actions) {} - - void bind(int in, int out) { map.bind(in, out); } - void unbind(int in, int out) { map.unbind(in, out); } - bool isBound(int in) const { return map.isBound(in); } - - /** - Instigate an event. It is translated through the dispatch map and - sent to the function bindings. - */ - typedef DispatchMap::OutList _O; - void event(int index, const void* p=NULL) const - { - // No bindings, nothing happens - if(!isBound(index)) - return; - - // Get the mapped actions and execute them - const _O &list = map.getList(index); - _O::const_iterator it; - for(it = list.begin(); it != list.end(); it++) - funcs.call(*it, p); - } -}; - -} -#endif diff --git a/components/engine/input/func_binder.hpp b/components/engine/input/func_binder.hpp deleted file mode 100644 index 20119b07b..000000000 --- a/components/engine/input/func_binder.hpp +++ /dev/null @@ -1,104 +0,0 @@ -#ifndef _INPUT_FUNCBINDER_H -#define _INPUT_FUNCBINDER_H - -#include -#include -#include -#include - -namespace Input { - -/** - An Action defines the user defined action corresponding to a - binding. - - The first parameter is the action index that invoked this call. You - can assign the same function to multiple actions, and this can help - you keep track of which action was invoked. - - The second parameter is an optional user-defined parameter, - represented by a void pointer. In many cases it is practical to - point this to temporaries (stack values), so make sure not to store - permanent references to it unless you've planning for this on the - calling side as well. - */ -typedef boost::function Action; - -/** - The FuncBinder is a simple struct that binds user-defined indices - to functions. It is useful for binding eg. keyboard events to - specific actions in your program, but can potentially have many - other uses as well. - */ -class FuncBinder -{ - struct FuncBinding - { - std::string name; - Action action; - }; - - std::vector bindings; - -public: - /** - Constructor. Initialize the struct by telling it how many action - indices you intend to bind. - - The indices you use should be 0 <= i < number. - */ - FuncBinder(int number) : bindings(number) {} - - /** - Bind an action to an index. - */ - void bind(int index, Action action, const std::string &name="") - { - assert(index >= 0 && index < (int)bindings.size()); - - FuncBinding &fb = bindings[index]; - fb.action = action; - fb.name = name; - } - - /** - Unbind an index, reverting a previous bind(). - */ - void unbind(int index) - { - assert(index >= 0 && index < (int)bindings.size()); - - bindings[index] = FuncBinding(); - } - - /** - Call a specific action. Takes an optional parameter that is - passed to the action. - */ - void call(int index, const void *p=NULL) const - { - assert(index >= 0 && index < (int)bindings.size()); - - const FuncBinding &fb = bindings[index]; - if(fb.action) fb.action(index, p); - } - - /// Check if a given index is bound to anything - bool isBound(int index) const - { - assert(index >= 0 && index < (int)bindings.size()); - - return !bindings[index].action.empty(); - } - - /// Return the name associated with an action (empty if not bound) - const std::string &getName(int index) const - { - assert(index >= 0 && index < (int)bindings.size()); - - return bindings[index].name; - } -}; - -} -#endif diff --git a/components/engine/input/listener.hpp b/components/engine/input/listener.hpp deleted file mode 100644 index ecc786f22..000000000 --- a/components/engine/input/listener.hpp +++ /dev/null @@ -1,113 +0,0 @@ -#ifndef _INPUT_LISTENER_H -#define _INPUT_LISTENER_H - -#include "oismanager.hpp" -#include "components/engine/ogre/renderer.hpp" -#include "dispatcher.hpp" - -#include -#include - -namespace Input -{ - struct InputListener : Ogre::FrameListener, - OIS::KeyListener, - OIS::MouseListener - { - InputListener(Render::OgreRenderer &rend, - Input::OISManager &input, - const Input::Dispatcher &_disp) - : disp(_disp), doExit(false) - { - // Set up component pointers - mWindow = rend.getWindow(); - mMouse = input.mouse; - mKeyboard = input.keyboard; - - assert(mKeyboard); - assert(mWindow); - - // Add ourself to the managers - rend.getRoot() -> addFrameListener(this); - mKeyboard -> setEventCallback(this); - mMouse -> setEventCallback(this); - } - - void setCamera(Ogre::Camera *cam) { camera = cam; } - - // Call this to exit the main loop - void exitNow() { doExit = true; } - - bool frameStarted(const Ogre::FrameEvent &evt) - { - if(mWindow->isClosed() || doExit) - return false; - - // Capture keyboard and mouse events - mKeyboard->capture(); - mMouse->capture(); - - return Ogre::FrameListener::frameStarted(evt); - } - - bool keyPressed( const OIS::KeyEvent &arg ) - { - // Pass the event to the dispatcher - disp.event(arg.key, &arg); - return true; - } - - bool keyReleased( const OIS::KeyEvent &arg ) - { - return true; - } - - bool mouseMoved( const OIS::MouseEvent &arg ) - { - using namespace Ogre; - assert(camera); - - // Mouse sensitivity. Should be a config option later. - const float MS = 0.2f; - - float x = arg.state.X.rel * MS; - float y = arg.state.Y.rel * MS; - - camera->yaw(Degree(-x)); - - // The camera before pitching - Quaternion nopitch = camera->getOrientation(); - - camera->pitch(Degree(-y)); - - // Apply some failsafe measures against the camera flipping - // upside down. Is the camera close to pointing straight up or - // down? - if(camera->getUp()[1] <= 0.1) - // If so, undo the last pitch - camera->setOrientation(nopitch); - - return true; - } - - bool mousePressed( const OIS::MouseEvent &arg, OIS::MouseButtonID id ) - { - return true; - } - - bool mouseReleased( const OIS::MouseEvent &arg, OIS::MouseButtonID id ) - { - return true; - } - - private: - - const Dispatcher &disp; - Ogre::RenderWindow *mWindow; - Ogre::Camera *camera; - OIS::Mouse *mMouse; - OIS::Keyboard *mKeyboard; - bool doExit; - }; -} -#endif diff --git a/components/engine/input/oismanager.cpp b/components/engine/input/oismanager.cpp deleted file mode 100644 index 5f872a29d..000000000 --- a/components/engine/input/oismanager.cpp +++ /dev/null @@ -1,89 +0,0 @@ -#include "oismanager.hpp" -#include -#include -#include -#include - -#include "OgreRenderWindow.h" - -#ifdef __APPLE_CC__ -#include -#endif - -using namespace Input; -using namespace Ogre; -using namespace OIS; - -using namespace std; - -OISManager::OISManager(Render::OgreRenderer &rend, bool debug) -{ - RenderWindow *window = rend.getWindow(); - assert(window); - - size_t windowHnd; - window->getCustomAttribute("WINDOW", &windowHnd); - - std::ostringstream windowHndStr; - ParamList pl; - - windowHndStr << windowHnd; - pl.insert(std::make_pair(std::string("WINDOW"), windowHndStr.str())); - - // Non-exclusive mouse and keyboard input in debug mode. Debug mode - // isn't implemented yet though. - if(debug) - { -#if defined OIS_WIN32_PLATFORM - pl.insert(std::make_pair(std::string("w32_mouse"), - std::string("DISCL_FOREGROUND" ))); - pl.insert(std::make_pair(std::string("w32_mouse"), - std::string("DISCL_NONEXCLUSIVE"))); - pl.insert(std::make_pair(std::string("w32_keyboard"), - std::string("DISCL_FOREGROUND"))); - pl.insert(std::make_pair(std::string("w32_keyboard"), - std::string("DISCL_NONEXCLUSIVE"))); -#elif defined OIS_LINUX_PLATFORM - pl.insert(std::make_pair(std::string("x11_mouse_grab"), - std::string("false"))); - pl.insert(std::make_pair(std::string("x11_mouse_hide"), - std::string("false"))); - pl.insert(std::make_pair(std::string("x11_keyboard_grab"), - std::string("false"))); - pl.insert(std::make_pair(std::string("XAutoRepeatOn"), - std::string("true"))); -#endif - } - -#ifdef __APPLE_CC__ - // Give the application window focus to receive input events - ProcessSerialNumber psn = { 0, kCurrentProcess }; - TransformProcessType(&psn, kProcessTransformToForegroundApplication); - SetFrontProcess(&psn); -#endif - - inputMgr = InputManager::createInputSystem( pl ); - - // Create all devices - keyboard = static_cast(inputMgr->createInputObject - ( OISKeyboard, true )); - mouse = static_cast(inputMgr->createInputObject - ( OISMouse, true )); - - // Set mouse region - const MouseState &ms = mouse->getMouseState(); - ms.width = window->getWidth(); - ms.height = window->getHeight(); -} - -OISManager::~OISManager() -{ - if(inputMgr == NULL) return; - - // Kill the input systems. This will reset input options such as key - // repetition. - inputMgr->destroyInputObject(keyboard); - inputMgr->destroyInputObject(mouse); - InputManager::destroyInputSystem(inputMgr); - inputMgr = NULL; -} diff --git a/components/engine/input/oismanager.hpp b/components/engine/input/oismanager.hpp deleted file mode 100644 index 05d0ac622..000000000 --- a/components/engine/input/oismanager.hpp +++ /dev/null @@ -1,19 +0,0 @@ -#ifndef _INPUT_OISMANAGER_H -#define _INPUT_OISMANAGER_H - -#include "components/engine/ogre/renderer.hpp" -#include - -namespace Input -{ - struct OISManager - { - OIS::InputManager *inputMgr; - OIS::Mouse *mouse; - OIS::Keyboard *keyboard; - - OISManager(Render::OgreRenderer &rend, bool debug); - ~OISManager(); - }; -} -#endif diff --git a/components/engine/input/poller.hpp b/components/engine/input/poller.hpp deleted file mode 100644 index e7d712b35..000000000 --- a/components/engine/input/poller.hpp +++ /dev/null @@ -1,51 +0,0 @@ -#ifndef _INPUT_POLLER_H -#define _INPUT_POLLER_H - -#include "dispatch_map.hpp" -#include "oismanager.hpp" - -namespace Input { - -/** The poller is used to check (poll) for keys rather than waiting - for events. TODO: Might make this OIS-independent later. */ -struct Poller -{ - DispatchMap map; - OIS::Keyboard *keyboard; - - Poller(Input::OISManager &ois) - { - keyboard = ois.keyboard; - assert(keyboard); - } - - /** Bind or unbind a given action with a key. The action is the first - parameter, the key is the second. - */ - void bind(int in, int out) { map.bind(in, out); } - void unbind(int in, int out) { map.unbind(in, out); } - bool isBound(int in) const { return map.isBound(in); } - - /// Check whether a given action button is currently pressed. - typedef DispatchMap::OutList _O; - bool isDown(int index) const - { - assert(keyboard); - - // No bindings, no action - if(!isBound(index)) - return false; - - // Get all the keys bound to this action, and check them. - const _O &list = map.getList(index); - _O::const_iterator it; - for(it = list.begin(); it != list.end(); it++) - // If there's any match, we're good to go. - if(keyboard->isKeyDown((OIS::KeyCode)*it)) return true; - - return false; - } -}; - -} -#endif diff --git a/components/engine/input/tests/.gitignore b/components/engine/input/tests/.gitignore deleted file mode 100644 index d736d3ec9..000000000 --- a/components/engine/input/tests/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -*_test - diff --git a/components/engine/input/tests/Makefile b/components/engine/input/tests/Makefile deleted file mode 100644 index a503af7e0..000000000 --- a/components/engine/input/tests/Makefile +++ /dev/null @@ -1,12 +0,0 @@ -GCC=g++ - -all: funcbind_test dispatch_map_test - -funcbind_test: funcbind_test.cpp ../func_binder.hpp - $(GCC) $< -o $@ - -dispatch_map_test: dispatch_map_test.cpp ../dispatch_map.hpp - $(GCC) $< -o $@ - -clean: - rm *_test diff --git a/components/engine/input/tests/dispatch_map_test.cpp b/components/engine/input/tests/dispatch_map_test.cpp deleted file mode 100644 index 5cc7e1ef2..000000000 --- a/components/engine/input/tests/dispatch_map_test.cpp +++ /dev/null @@ -1,54 +0,0 @@ -#include -using namespace std; - -#include "../dispatch_map.hpp" - -using namespace Input; - -typedef DispatchMap::OutList OutList; -typedef OutList::const_iterator Cit; - -void showList(const DispatchMap::OutList &out) -{ - for(Cit it = out.begin(); - it != out.end(); it++) - { - cout << " " << *it << endl; - } -} - -void showAll(DispatchMap &map) -{ - cout << "\nPrinting everything:\n"; - for(DispatchMap::Iit it = map.map.begin(); - it != map.map.end(); it++) - { - cout << it->first << ":\n"; - showList(map.getList(it->first)); - } -} - -int main() -{ - cout << "Testing the dispatch map\n"; - - DispatchMap dsp; - - dsp.bind(1,9); - dsp.bind(2,-5); - dsp.bind(2,9); - dsp.bind(3,10); - dsp.bind(3,12); - dsp.bind(3,10); - - showAll(dsp); - - dsp.unbind(1,9); - dsp.unbind(5,8); - dsp.unbind(3,11); - dsp.unbind(3,12); - dsp.unbind(3,12); - - showAll(dsp); - return 0; -} diff --git a/components/engine/input/tests/funcbind_test.cpp b/components/engine/input/tests/funcbind_test.cpp deleted file mode 100644 index 4716f8b81..000000000 --- a/components/engine/input/tests/funcbind_test.cpp +++ /dev/null @@ -1,47 +0,0 @@ -#include -using namespace std; - -#include "../func_binder.hpp" - -void f1(int i, const void *p) -{ - cout << " F1 i=" << i << endl; - - if(p) - cout << " Got a nice gift: " - << *((const float*)p) << endl; -} - -void f2(int i, const void *p) -{ - cout << " F2 i=" << i << endl; -} - -using namespace Input; - -int main() -{ - cout << "This will test the function binding system\n"; - - FuncBinder bnd(5); - - bnd.bind(0, &f1, "This is action 1"); - bnd.bind(1, &f2); - bnd.bind(2, &f1, "This is action 3"); - bnd.bind(3, &f2, "This is action 4"); - - bnd.unbind(2); - - for(int i=0; i<5; i++) - { - cout << "Calling " << i << ": '" << bnd.getName(i) << "'\n"; - bnd.call(i); - if(!bnd.isBound(i)) cout << " (not bound)\n"; - } - - cout << "\nCalling with parameter:\n"; - float f = 3.1415; - bnd.call(0, &f); - - return 0; -} diff --git a/components/engine/input/tests/output/dispatch_map_test.out b/components/engine/input/tests/output/dispatch_map_test.out deleted file mode 100644 index 01aa9d9d9..000000000 --- a/components/engine/input/tests/output/dispatch_map_test.out +++ /dev/null @@ -1,18 +0,0 @@ -Testing the dispatch map - -Printing everything: -1: - 9 -2: - -5 - 9 -3: - 10 - 12 - -Printing everything: -2: - -5 - 9 -3: - 10 diff --git a/components/engine/input/tests/output/funcbind_test.out b/components/engine/input/tests/output/funcbind_test.out deleted file mode 100644 index 862c5c972..000000000 --- a/components/engine/input/tests/output/funcbind_test.out +++ /dev/null @@ -1,15 +0,0 @@ -This will test the function binding system -Calling 0: 'This is action 1' - F1 i=0 -Calling 1: '' - F2 i=1 -Calling 2: '' - (not bound) -Calling 3: 'This is action 4' - F2 i=3 -Calling 4: '' - (not bound) - -Calling with parameter: - F1 i=0 - Got a nice gift: 3.1415 diff --git a/components/engine/input/tests/test.sh b/components/engine/input/tests/test.sh deleted file mode 100755 index 2d07708ad..000000000 --- a/components/engine/input/tests/test.sh +++ /dev/null @@ -1,18 +0,0 @@ -#!/bin/bash - -make || exit - -mkdir -p output - -PROGS=*_test - -for a in $PROGS; do - if [ -f "output/$a.out" ]; then - echo "Running $a:" - ./$a | diff output/$a.out - - else - echo "Creating $a.out" - ./$a > "output/$a.out" - git add "output/$a.out" - fi -done diff --git a/components/engine/ogre/.gitignore b/components/engine/ogre/.gitignore deleted file mode 100644 index 3367afdbb..000000000 --- a/components/engine/ogre/.gitignore +++ /dev/null @@ -1 +0,0 @@ -old diff --git a/components/engine/ogre/renderer.cpp b/components/engine/ogre/renderer.cpp deleted file mode 100644 index 982f0f050..000000000 --- a/components/engine/ogre/renderer.cpp +++ /dev/null @@ -1,80 +0,0 @@ -#include "renderer.hpp" - -#include "OgreRoot.h" -#include "OgreRenderWindow.h" -#include "OgreLogManager.h" -#include "OgreLog.h" - -#include - -using namespace Ogre; -using namespace Render; - -void OgreRenderer::cleanup() -{ - if(mRoot) - delete mRoot; - mRoot = NULL; -} - -void OgreRenderer::screenshot(const std::string &file) -{ - mWindow->writeContentsToFile(file); -} - -bool OgreRenderer::configure(bool showConfig, - const std::string &pluginCfg, - bool _logging) -{ - // Set up logging first - new LogManager; - Log *log = LogManager::getSingleton().createLog("Ogre.log"); - logging = _logging; - - if(logging) - // Full log detail - log->setLogDetail(LL_BOREME); - else - // Disable logging - log->setDebugOutputEnabled(false); - - mRoot = new Root(pluginCfg, "ogre.cfg", ""); - - // Show the configuration dialog and initialise the system, if the - // showConfig parameter is specified. The settings are stored in - // ogre.cfg. If showConfig is false, the settings are assumed to - // already exist in ogre.cfg. - int result; - if(showConfig) - result = mRoot->showConfigDialog(); - else - result = mRoot->restoreConfig(); - - return !result; -} - -void OgreRenderer::createWindow(const std::string &title) -{ - assert(mRoot); - // Initialize OGRE window - mWindow = mRoot->initialise(true, title, ""); -} - -void OgreRenderer::createScene(const std::string camName, float fov, float nearClip) -{ - assert(mRoot); - assert(mWindow); - // Get the SceneManager, in this case a generic one - mScene = mRoot->createSceneManager(ST_GENERIC); - - // Create the camera - mCamera = mScene->createCamera(camName); - mCamera->setNearClipDistance(nearClip); - mCamera->setFOVy(Degree(fov)); - - // Create one viewport, entire window - mView = mWindow->addViewport(mCamera); - - // Alter the camera aspect ratio to match the viewport - mCamera->setAspectRatio(Real(mView->getActualWidth()) / Real(mView->getActualHeight())); -} diff --git a/components/engine/ogre/renderer.hpp b/components/engine/ogre/renderer.hpp deleted file mode 100644 index 98c1a68d2..000000000 --- a/components/engine/ogre/renderer.hpp +++ /dev/null @@ -1,77 +0,0 @@ -#ifndef _OGRE_RENDERER_H -#define _OGRE_RENDERER_H - -/* - Ogre renderer class - */ - -#include -#include - -namespace Ogre -{ - class Root; - class RenderWindow; - class SceneManager; - class Camera; - class Viewport; -} - -namespace Render -{ - class OgreRenderer - { - Ogre::Root *mRoot; - Ogre::RenderWindow *mWindow; - Ogre::SceneManager *mScene; - Ogre::Camera *mCamera; - Ogre::Viewport *mView; - bool logging; - - public: - OgreRenderer() - : mRoot(NULL), mWindow(NULL), mScene(NULL) {} - ~OgreRenderer() { cleanup(); } - - /** Configure the renderer. This will load configuration files and - set up the Root and logging classes. */ - bool configure(bool showConfig, // Show config dialog box? - const std::string &pluginCfg, // plugin.cfg file - bool _logging); // Enable or disable logging - - /// Create a window with the given title - void createWindow(const std::string &title); - - /// Set up the scene manager, camera and viewport - void createScene(const std::string camName="Camera",// Camera name - float fov=55, // Field of view angle - float nearClip=5 // Near clip distance - ); - - /// Kill the renderer. - void cleanup(); - - /// Start the main rendering loop - void start() { mRoot->startRendering(); } - - /// Write a screenshot to file - void screenshot(const std::string &file); - - /// Get the Root - Ogre::Root *getRoot() { return mRoot; } - - /// Get the rendering window - Ogre::RenderWindow *getWindow() { return mWindow; } - - /// Get the scene manager - Ogre::SceneManager *getScene() { return mScene; } - - /// Camera - Ogre::Camera *getCamera() { return mCamera; } - - /// Viewport - Ogre::Viewport *getViewport() { return mView; } - }; -} - -#endif diff --git a/components/mw_gui/mw_layouts.hpp b/components/mw_gui/mw_layouts.hpp index 1b72833f0..79feb8062 100644 --- a/components/mw_gui/mw_layouts.hpp +++ b/components/mw_gui/mw_layouts.hpp @@ -1,7 +1,7 @@ #ifndef MWGUI_LAYOUTS_H #define MWGUI_LAYOUTS_H -#include +#include /* This file contains classes corresponding to all the window layouts @@ -18,7 +18,7 @@ namespace MWGUI { - class HUD : public GUI::Layout + class HUD : public OEngine::GUI::Layout { public: HUD(int width, int height) @@ -103,7 +103,7 @@ namespace MWGUI MyGUI::StaticImagePtr crosshair; }; - class MapWindow : public GUI::Layout + class MapWindow : public OEngine::GUI::Layout { public: MapWindow() @@ -123,7 +123,7 @@ namespace MWGUI } }; - class MainMenu : public GUI::Layout + class MainMenu : public OEngine::GUI::Layout { public: MainMenu(int w, int h) @@ -133,7 +133,7 @@ namespace MWGUI } }; - class StatsWindow : public GUI::Layout + class StatsWindow : public OEngine::GUI::Layout { public: void setBar(const char* name, const char* tname, int val, int max) diff --git a/libs/openengine b/libs/openengine index 5333b8e23..69a56e867 160000 --- a/libs/openengine +++ b/libs/openengine @@ -1 +1 @@ -Subproject commit 5333b8e230e285e9183b0639188283bdbc15af6c +Subproject commit 69a56e867749944dc0e86b9ef5c54bac4339b454