split Player class into a MWWorld and a MWRender component

actorid
Marc Zinnschlag 14 years ago
parent 4f51391003
commit f01a3d5e35

@ -14,14 +14,18 @@ set(GAMEREND
mwrender/cellimp.cpp
mwrender/interior.cpp
mwrender/exterior.cpp
mwrender/sky.cpp)
mwrender/sky.cpp
mwrender/player.cpp
)
set(GAMEREND_HEADER
mwrender/cell.hpp
mwrender/cellimp.hpp
mwrender/mwscene.hpp
mwrender/interior.hpp
mwrender/exterior.hpp
mwrender/sky.hpp)
mwrender/sky.hpp
mwrender/player.hpp
)
source_group(apps\\openmw\\mwrender FILES ${GAMEREND} ${GAMEREND_HEADER})
set(GAMEINPUT

@ -20,6 +20,8 @@
#include "../mwworld/player.hpp"
#include "../mwrender/player.hpp"
#include <boost/bind.hpp>
#include <boost/filesystem.hpp>
#include <OgreRoot.h>
@ -165,7 +167,7 @@ namespace MWInput
ogre.getRoot()->addFrameListener(this);
// Set up the mouse handler and tell it about the player camera
mouse = MouseLookEventPtr(new MouseLookEvent(player.getCamera()));
mouse = MouseLookEventPtr(new MouseLookEvent(player.getRenderer()->getCamera()));
// This event handler pumps events into MyGUI
guiEvents = EventInjectorPtr(new EventInjector(windows.getGui()));
@ -278,7 +280,7 @@ namespace MWInput
{
// Start mouse-looking again. TODO: This should also allow
// for other ways to disable mouselook, like paralyzation.
mouse->setCamera(player.getCamera());
mouse->setCamera(player.getRenderer()->getCamera());
// Disable GUI events
guiEvents->enabled = false;

@ -13,6 +13,8 @@
#include "../mwworld/ptr.hpp"
#include <components/esm/loadstat.hpp>
#include "player.hpp"
using namespace MWRender;
using namespace Ogre;
@ -38,6 +40,13 @@ MWScene::MWScene(OEngine::Render::OgreRenderer &_rend)
//used to obtain ingame information of ogre objects (which are faced or selected)
mRaySceneQuery = rend.getScene()->createRayQuery(Ray());
mPlayer = new MWRender::Player (getCamera());
}
MWScene::~MWScene()
{
delete mPlayer;
}
std::pair<std::string, float> MWScene::getFacedHandle (MWWorld::World& world)

@ -20,36 +20,41 @@ namespace MWWorld
namespace MWRender
{
/** 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
{
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
// Morrowind.
Ogre::SceneNode *mwRoot;
Ogre::RaySceneQuery *mRaySceneQuery;
public:
MWScene(OEngine::Render::OgreRenderer &_rend);
Ogre::Camera *getCamera() { return rend.getCamera(); }
Ogre::SceneNode *getRoot() { return mwRoot; }
Ogre::SceneManager *getMgr() { return rend.getScene(); }
Ogre::Viewport *getViewport() { return rend.getViewport(); }
Ogre::RaySceneQuery *getRaySceneQuery() { return mRaySceneQuery; }
//gets the handle of the object the player is looking at
//pair<name, distance>
//name is empty and distance = -1 if there is no object which
//can be faced
std::pair<std::string, float> getFacedHandle (MWWorld::World& world);
};
class Player;
/// \brief 3D-scene (rendering and physics)
class MWScene
{
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
/// Morrowind.
Ogre::SceneNode *mwRoot;
Ogre::RaySceneQuery *mRaySceneQuery;
MWRender::Player *mPlayer;
public:
MWScene (OEngine::Render::OgreRenderer &_rend);
~MWScene();
Ogre::Camera *getCamera() { return rend.getCamera(); }
Ogre::SceneNode *getRoot() { return mwRoot; }
Ogre::SceneManager *getMgr() { return rend.getScene(); }
Ogre::Viewport *getViewport() { return rend.getViewport(); }
Ogre::RaySceneQuery *getRaySceneQuery() { return mRaySceneQuery; }
MWRender::Player *getPlayer() { return mPlayer; }
/// Gets the handle of the object the player is looking at
/// pair<name, distance>
/// name is empty and distance = -1 if there is no object which
/// can be faced
std::pair<std::string, float> getFacedHandle (MWWorld::World& world);
};
}
#endif

@ -0,0 +1,8 @@
#include "player.hpp"
namespace MWRender
{
Player::Player (Ogre::Camera *camera) : mCamera (camera)
{}
}

@ -0,0 +1,24 @@
#ifndef GAME_MWRENDER_PLAYER_H
#define GAME_MWRENDER_PLAYER_H
namespace Ogre
{
class Camera;
}
namespace MWRender
{
/// \brief Player character rendering and camera control
class Player
{
Ogre::Camera *mCamera;
public:
Player (Ogre::Camera *camera);
Ogre::Camera *getCamera() { return mCamera; }
};
}
#endif

@ -1,12 +1,14 @@
#include "player.hpp"
#include "../mwrender/player.hpp"
#include "world.hpp"
namespace MWWorld
{
Player::Player (Ogre::Camera *cam, const ESM::NPC *player, MWWorld::World& world) :
mCellStore (0), camera(cam), mWorld (world), mClass (0)
Player::Player (MWRender::Player *renderer, const ESM::NPC *player, MWWorld::World& world) :
mCellStore (0), mRenderer (renderer), mWorld (world), mClass (0)
{
mPlayer.base = player;
mName = player->name;
@ -26,7 +28,7 @@ namespace MWWorld
mWorld.moveObject (getPlayer(), x, y, z);
if (updateCamera)
camera->setPosition (Ogre::Vector3 (
mRenderer->getCamera()->setPosition (Ogre::Vector3 (
mPlayer.ref.pos.pos[0],
mPlayer.ref.pos.pos[2],
-mPlayer.ref.pos.pos[1]));
@ -35,13 +37,13 @@ namespace MWWorld
void Player::moveRel (float &relX, float &relY, float &relZ)
{
// Move camera relative to its own direction
camera->moveRelative (Ogre::Vector3(relX,0,relZ));
mRenderer->getCamera()->moveRelative (Ogre::Vector3(relX,0,relZ));
// Up/down movement is always done relative the world axis.
camera->move (Ogre::Vector3(0,relY,0));
mRenderer->getCamera()->move (Ogre::Vector3(0,relY,0));
// Get new camera position, converting back to MW coords.
Ogre::Vector3 pos = camera->getPosition();
Ogre::Vector3 pos = mRenderer->getCamera()->getPosition();
relX = pos[0];
relY = -pos[2];
relZ = pos[1];

@ -8,18 +8,21 @@
#include "../mwworld/refdata.hpp"
#include "../mwworld/ptr.hpp"
namespace MWWorld
namespace MWRender
{
class World;
class Player;
}
namespace MWWorld
{
class World;
/// \brief NPC object representing the player and additional player data
class Player
{
ESMS::LiveCellRef<ESM::NPC, MWWorld::RefData> mPlayer;
MWWorld::Ptr::CellStore *mCellStore;
Ogre::Camera *camera;
MWRender::Player *mRenderer;
MWWorld::World& mWorld;
std::string mName;
bool mMale;
@ -29,7 +32,7 @@ namespace MWWorld
public:
Player(Ogre::Camera *cam, const ESM::NPC *player, MWWorld::World& world);
Player(MWRender::Player *renderer, const ESM::NPC *player, MWWorld::World& world);
~Player();
@ -41,8 +44,6 @@ namespace MWWorld
mCellStore = cellStore;
}
Ogre::Camera *getCamera() { return camera; }
/// Move the player relative to her own position and
/// orientation. After the call, the new position is returned.
void moveRel (float &relX, float &relY, float &relZ);
@ -53,6 +54,8 @@ namespace MWWorld
return ptr;
}
MWRender::Player *getRenderer() { return mRenderer; }
void setName (const std::string& name)
{
mName = name;

@ -329,7 +329,7 @@ namespace MWWorld
mEsm.open (masterPath.file_string());
mStore.load (mEsm);
mPlayer = new MWWorld::Player (mScene.getCamera(), mStore.npcs.find ("player"), *this);
mPlayer = new MWWorld::Player (mScene.getPlayer(), mStore.npcs.find ("player"), *this);
// global variables
mGlobalVariables = new Globals (mStore);

Loading…
Cancel
Save