local scripts are now run every frame (running scripts itself is not implemented yet)

pull/7/head
Marc Zinnschlag 15 years ago
parent 076b01559f
commit 8e2732c60e

@ -13,26 +13,38 @@
#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);
}
}
@ -117,21 +129,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.
void OMW::Engine::go()
@ -167,8 +164,6 @@ 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();

@ -5,6 +5,8 @@
#include <boost/filesystem.hpp>
#include <OgreFrameListener.h>
#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();
};

Loading…
Cancel
Save