From 8e2732c60ee34f9665d373a28eeb34bd66beee0a Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Fri, 2 Jul 2010 17:30:26 +0200 Subject: [PATCH] local scripts are now run every frame (running scripts itself is not implemented yet) --- apps/openmw/engine.cpp | 62 ++++++++++++++++++++---------------------- apps/openmw/engine.hpp | 12 +++++--- 2 files changed, 37 insertions(+), 37 deletions(-) diff --git a/apps/openmw/engine.cpp b/apps/openmw/engine.cpp index 3baccdc6e9..526e316c74 100644 --- a/apps/openmw/engine.cpp +++ b/apps/openmw/engine.cpp @@ -13,29 +13,41 @@ #include "world.hpp" -class ProcessCommandsHook : public Ogre::FrameListener -{ -public: - ProcessCommandsHook(OMW::Engine* pEngine) : mpEngine (pEngine) {} - virtual bool frameStarted(const Ogre::FrameEvent& evt) - { - mpEngine->processCommands(); - return true; - } -protected: - OMW::Engine* mpEngine; -}; - void OMW::Engine::executeLocalScripts() { for (World::ScriptList::const_iterator iter (mWorld->getLocalScripts().begin()); iter!=mWorld->getLocalScripts().end(); ++iter) { mScriptManager->run (iter->first, *iter->second); - } } +bool OMW::Engine::frameStarted(const Ogre::FrameEvent& evt) +{ + // console + processCommands(); + + // local scripts + executeLocalScripts(); + + return true; +} + +void OMW::Engine::processCommands() +{ + Command cmd; + while (mCommandQueue.try_pop_front(cmd)) + { + ///\todo Add actual processing of the received command strings + std::cout << "Command: '" << cmd.mCommand << "'" << std::endl; + + ///\todo Replace with real output. For now, echo back the string in uppercase + std::string reply(cmd.mCommand); + std::transform(reply.begin(), reply.end(), reply.begin(), toupper); + cmd.mReplyFunction(reply); + } +} + OMW::Engine::Engine() : mWorld(NULL), mDebug (false), mScriptManager (0), mScriptContext (0) { @@ -116,21 +128,6 @@ void OMW::Engine::enableVerboseScripts() { mVerboseScripts = true; } - -void OMW::Engine::processCommands() -{ - Command cmd; - while (mCommandQueue.try_pop_front(cmd)) - { - ///\todo Add actual processing of the received command strings - std::cout << "Command: '" << cmd.mCommand << "'" << std::endl; - - ///\todo Replace with real output. For now, echo back the string in uppercase - std::string reply(cmd.mCommand); - std::transform(reply.begin(), reply.end(), reply.begin(), toupper); - cmd.mReplyFunction(reply); - } -} // Initialise and enter main loop. @@ -166,9 +163,7 @@ void OMW::Engine::go() mScriptManager = new MWScript::ScriptManager (mWorld->getStore(), mVerboseScripts, *mScriptContext); - - executeLocalScripts(); // TODO move into a framelistener - + std::cout << "Setting up input system\n"; // Sets up the input system @@ -177,10 +172,11 @@ void OMW::Engine::go() // Launch the console server std::cout << "Starting command server on port " << kCommandServerPort << std::endl; mspCommandServer->start(); - mOgre.getRoot()->addFrameListener( new ProcessCommandsHook(this) ); std::cout << "\nStart! Press Q/ESC or close window to exit.\n"; + mOgre.getRoot()->addFrameListener (this); + // Start the main rendering loop mOgre.start(); diff --git a/apps/openmw/engine.hpp b/apps/openmw/engine.hpp index 84b675af9f..be560a1723 100644 --- a/apps/openmw/engine.hpp +++ b/apps/openmw/engine.hpp @@ -5,6 +5,8 @@ #include +#include + #include "components/engine/ogre/renderer.hpp" #include "components/misc/tsdeque.hpp" #include "components/commandserver/server.hpp" @@ -28,7 +30,7 @@ namespace OMW /// \brief Main engine class, that brings together all the components of OpenMW - class Engine + class Engine : private Ogre::FrameListener { enum { kCommandServerPort = 27917 }; @@ -59,6 +61,11 @@ namespace OMW void executeLocalScripts(); + virtual bool frameStarted(const Ogre::FrameEvent& evt); + + /// Process pending commands + void processCommands(); + public: Engine(); @@ -83,9 +90,6 @@ namespace OMW /// Enable verbose script output void enableVerboseScripts(); - /// Process pending commands - void processCommands(); - /// Initialise and enter main loop. void go(); };