mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-01-16 19:19:56 +00:00
Added rendering loop and keyboard listener
This commit is contained in:
parent
4cadf70abe
commit
edca830845
8 changed files with 126 additions and 34 deletions
|
@ -7,6 +7,7 @@
|
|||
#include "ogre/renderer.hpp"
|
||||
#include "tools/fileops.hpp"
|
||||
#include "input/oismanager.hpp"
|
||||
#include "input/listener.hpp"
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
@ -43,17 +44,26 @@ void maintest()
|
|||
// Create the window
|
||||
ogre.createWindow("OpenMW");
|
||||
|
||||
Render::MWScene scene;
|
||||
scene.setup(&ogre);
|
||||
cout << "\nSetting up cell rendering (not done)\n";
|
||||
|
||||
// Sets up camera, scene manager etc
|
||||
Render::MWScene scene(ogre);
|
||||
|
||||
// This doesn't do anything yet.
|
||||
Render::CellRender rend(cell);
|
||||
|
||||
Input::OISManager input;
|
||||
input.setup(&ogre);
|
||||
cout << "Setting up input system\n";
|
||||
|
||||
// Add the frame listener
|
||||
//root->addFrameListener(&mFrameListener);
|
||||
// Sets up the input system
|
||||
Input::OISManager input(ogre);
|
||||
|
||||
// Add the frame and input listener
|
||||
Input::ExitListener frame(ogre, input);
|
||||
|
||||
cout << "\nStart! Press Q/ESC or close window to exit.\n";
|
||||
|
||||
// Start the main rendering loop
|
||||
ogre.start();
|
||||
|
||||
cout << "\nThat's all for now!\n";
|
||||
}
|
||||
|
|
|
@ -5,13 +5,11 @@
|
|||
using namespace Render;
|
||||
using namespace Ogre;
|
||||
|
||||
void MWScene::setup(OgreRenderer *_rend)
|
||||
MWScene::MWScene(OgreRenderer &_rend)
|
||||
: rend(_rend)
|
||||
{
|
||||
rend = _rend;
|
||||
assert(rend);
|
||||
|
||||
Root *root = rend->getRoot();
|
||||
RenderWindow *window = rend->getWindow();
|
||||
Root *root = rend.getRoot();
|
||||
RenderWindow *window = rend.getWindow();
|
||||
|
||||
// Get the SceneManager, in this case a generic one
|
||||
sceneMgr = root->createSceneManager(ST_GENERIC);
|
||||
|
|
|
@ -6,10 +6,13 @@
|
|||
namespace Render
|
||||
{
|
||||
/** Class responsible for Morrowind-specific interfaces to OGRE.
|
||||
|
||||
This might be refactored partially into a non-mw specific
|
||||
counterpart in ogre/ at some point.
|
||||
*/
|
||||
class MWScene
|
||||
{
|
||||
OgreRenderer *rend;
|
||||
OgreRenderer &rend;
|
||||
Ogre::SceneManager *sceneMgr;
|
||||
Ogre::Camera *camera;
|
||||
Ogre::Viewport *vp;
|
||||
|
@ -20,7 +23,7 @@ namespace Render
|
|||
Ogre::SceneNode *mwRoot;
|
||||
|
||||
public:
|
||||
void setup(OgreRenderer *_rend);
|
||||
MWScene(OgreRenderer &_rend);
|
||||
};
|
||||
}
|
||||
|
||||
|
|
89
input/listener.hpp
Normal file
89
input/listener.hpp
Normal file
|
@ -0,0 +1,89 @@
|
|||
#ifndef _INPUT_LISTENER_H
|
||||
#define _INPUT_LISTENER_H
|
||||
|
||||
#include "oismanager.hpp"
|
||||
#include "ogre/renderer.hpp"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
namespace Input
|
||||
{
|
||||
struct ExitListener : Ogre::FrameListener,
|
||||
OIS::KeyListener,
|
||||
OIS::MouseListener
|
||||
{
|
||||
ExitListener(Render::OgreRenderer &rend,
|
||||
Input::OISManager &input)
|
||||
: doExit(false)
|
||||
{
|
||||
// Set up component pointers
|
||||
mWindow = rend.getWindow();
|
||||
mMouse = input.mouse;
|
||||
mKeyboard = input.keyboard;
|
||||
|
||||
// Add ourself to the managers
|
||||
rend.getRoot() -> addFrameListener(this);
|
||||
mKeyboard -> setEventCallback(this);
|
||||
mMouse -> setEventCallback(this);
|
||||
}
|
||||
|
||||
// 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 )
|
||||
{
|
||||
/*
|
||||
std::cout << "KeyPressed {" << arg.key
|
||||
<< ", " << ((OIS::Keyboard*)(arg.device))->getAsString(arg.key)
|
||||
<< "} || Character (" << (char)arg.text << ")\n";
|
||||
*/
|
||||
using namespace OIS;
|
||||
|
||||
if(arg.key == KC_Q ||
|
||||
arg.key == KC_ESCAPE)
|
||||
exitNow();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool keyReleased( const OIS::KeyEvent &arg )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
bool mouseMoved( const OIS::MouseEvent &arg )
|
||||
{
|
||||
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:
|
||||
|
||||
Ogre::RenderWindow *mWindow;
|
||||
OIS::Mouse *mMouse;
|
||||
OIS::Keyboard *mKeyboard;
|
||||
bool doExit;
|
||||
};
|
||||
}
|
||||
#endif
|
|
@ -10,11 +10,9 @@ using namespace OIS;
|
|||
#include <iostream>
|
||||
using namespace std;
|
||||
|
||||
void OISManager::setup(Render::OgreRenderer *rend)
|
||||
OISManager::OISManager(Render::OgreRenderer &rend)
|
||||
{
|
||||
assert(rend);
|
||||
|
||||
RenderWindow *window = rend->getWindow();
|
||||
RenderWindow *window = rend.getWindow();
|
||||
assert(window);
|
||||
|
||||
size_t windowHnd;
|
||||
|
@ -62,15 +60,9 @@ void OISManager::setup(Render::OgreRenderer *rend)
|
|||
const MouseState &ms = mouse->getMouseState();
|
||||
ms.width = window->getWidth();
|
||||
ms.height = window->getHeight();
|
||||
|
||||
/*
|
||||
// Register the input listener
|
||||
keyboard -> setEventCallback( &mInput );
|
||||
mouse -> setEventCallback( &mInput );
|
||||
*/
|
||||
}
|
||||
|
||||
void OISManager::cleanup()
|
||||
OISManager::~OISManager()
|
||||
{
|
||||
if(inputMgr == NULL) return;
|
||||
|
||||
|
|
|
@ -6,15 +6,14 @@
|
|||
|
||||
namespace Input
|
||||
{
|
||||
class OISManager
|
||||
struct OISManager
|
||||
{
|
||||
OIS::InputManager *inputMgr;
|
||||
OIS::Mouse *mouse;
|
||||
OIS::Keyboard *keyboard;
|
||||
|
||||
public:
|
||||
void setup(Render::OgreRenderer *rend);
|
||||
void cleanup();
|
||||
OISManager(Render::OgreRenderer &rend);
|
||||
~OISManager();
|
||||
};
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -33,7 +33,13 @@ namespace Render
|
|||
/// Kill the renderer.
|
||||
void cleanup();
|
||||
|
||||
/// Start the main rendering loop
|
||||
void start() { mRoot->startRendering(); }
|
||||
|
||||
/// Get the Root
|
||||
Ogre::Root *getRoot() { return mRoot; }
|
||||
|
||||
/// Get the rendering window
|
||||
Ogre::RenderWindow *getWindow() { return mWindow; }
|
||||
};
|
||||
}
|
||||
|
|
|
@ -148,11 +148,6 @@ extern "C" void ogre_setFog(float rf, float gf, float bf, // Fog color
|
|||
vp->setBackgroundColour(fogColor);
|
||||
}
|
||||
|
||||
extern "C" void ogre_startRendering()
|
||||
{
|
||||
mRoot->startRendering();
|
||||
}
|
||||
|
||||
// Copy a scene node and all its children
|
||||
void cloneNode(SceneNode *from, SceneNode *to, char* name)
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue