added World interface class; cleanup of World interface

actorid
Marc Zinnschlag 13 years ago
parent 7fcd41c69d
commit 035c1c4b6e

@ -64,7 +64,7 @@ add_openmw_dir (mwmechanics
) )
add_openmw_dir (mwbase add_openmw_dir (mwbase
environment environment world
) )
# Main executable # Main executable

@ -0,0 +1,245 @@
#ifndef GAME_MWBASE_WORLD_H
#define GAME_MWBASE_WORLD_H
#include <string>
#include <map>
#include <vector>
#include <components/settings/settings.hpp>
#include "../mwworld/globals.hpp"
namespace Ogre
{
class Vector2;
class Vector3;
}
namespace OEngine
{
namespace Render
{
class Fader;
}
}
namespace ESM
{
class ESMReader;
struct Position;
struct Cell;
struct Class;
struct Potion;
}
namespace ESMS
{
struct ESMStore;
}
namespace MWWorld
{
class CellStore;
class Player;
class LocalScripts;
class Ptr;
class TimeStamp;
}
namespace MWBase
{
class World
{
World (const World&);
///< not implemented
World& operator= (const World&);
///< not implemented
public:
enum RenderMode
{
Render_CollisionDebug,
Render_Wireframe,
Render_Pathgrid,
Render_Compositors
};
World() {}
virtual ~World() {}
virtual OEngine::Render::Fader* getFader() = 0;
///< \ŧodo remove this function. Rendering details should not be exposed.
virtual MWWorld::CellStore *getExterior (int x, int y) = 0;
virtual MWWorld::CellStore *getInterior (const std::string& name) = 0;
virtual void setWaterHeight(const float height) = 0;
virtual void toggleWater() = 0;
virtual void adjustSky() = 0;
virtual void getTriangleBatchCount(unsigned int &triangles, unsigned int &batches) = 0;
virtual void setFallbackValues (const std::map<std::string, std::string>& fallbackMap) = 0;
virtual std::string getFallback (const std::string& key) const = 0;
virtual std::string getFallback (const std::string& key, const std::string& def) const = 0;
virtual MWWorld::Player& getPlayer() = 0;
virtual const ESMS::ESMStore& getStore() const = 0;
virtual ESM::ESMReader& getEsmReader() = 0;
virtual MWWorld::LocalScripts& getLocalScripts() = 0;
virtual bool hasCellChanged() const = 0;
///< Has the player moved to a different cell, since the last frame?
virtual bool isCellExterior() const = 0;
virtual bool isCellQuasiExterior() const = 0;
virtual Ogre::Vector2 getNorthVector (MWWorld::CellStore* cell) = 0;
///< get north vector (OGRE coordinates) for given interior cell
virtual MWWorld::Globals::Data& getGlobalVariable (const std::string& name) = 0;
virtual MWWorld::Globals::Data getGlobalVariable (const std::string& name) const = 0;
virtual char getGlobalVariableType (const std::string& name) const = 0;
///< Return ' ', if there is no global variable with this name.
virtual MWWorld::Ptr getPtr (const std::string& name, bool activeOnly) = 0;
///< Return a pointer to a liveCellRef with the given name.
/// \param activeOnly do non search inactive cells.
virtual MWWorld::Ptr getPtrViaHandle (const std::string& handle) = 0;
///< Return a pointer to a liveCellRef with the given Ogre handle.
/// \todo enable reference in the OGRE scene
virtual void enable (const MWWorld::Ptr& ptr) = 0;
/// \todo disable reference in the OGRE scene
virtual void disable (const MWWorld::Ptr& ptr) = 0;
virtual void advanceTime (double hours) = 0;
///< Advance in-game time.
virtual void setHour (double hour) = 0;
///< Set in-game time hour.
virtual void setMonth (int month) = 0;
///< Set in-game time month.
virtual void setDay (int day) = 0;
///< Set in-game time day.
virtual MWWorld::TimeStamp getTimeStamp() const = 0;
///< Return current in-game time stamp.
virtual bool toggleSky() = 0;
///< \return Resulting mode
virtual void changeWeather(const std::string& region, unsigned int id) = 0;
virtual int getCurrentWeather() const = 0;
virtual int getMasserPhase() const = 0;
virtual int getSecundaPhase() const = 0;
virtual void setMoonColour (bool red) = 0;
virtual float getTimeScaleFactor() const = 0;
virtual void changeToInteriorCell (const std::string& cellName,
const ESM::Position& position) = 0;
///< Move to interior cell.
virtual void changeToExteriorCell (const ESM::Position& position) = 0;
///< Move to exterior cell.
virtual const ESM::Cell *getExterior (const std::string& cellName) const = 0;
///< Return a cell matching the given name or a 0-pointer, if there is no such cell.
virtual void markCellAsUnchanged() = 0;
virtual std::string getFacedHandle() = 0;
///< Return handle of the object the player is looking at
virtual void deleteObject (const MWWorld::Ptr& ptr) = 0;
virtual void moveObject (const MWWorld::Ptr& ptr, float x, float y, float z) = 0;
virtual void indexToPosition (int cellX, int cellY, float &x, float &y, bool centre = false)
const = 0;
///< Convert cell numbers to position.
virtual void positionToIndex (float x, float y, int &cellX, int &cellY) const = 0;
///< Convert position to cell numbers
virtual void doPhysics (const std::vector<std::pair<std::string, Ogre::Vector3> >& actors,
float duration) = 0;
///< Run physics simulation and modify \a world accordingly.
virtual bool toggleCollisionMode() = 0;
///< Toggle collision mode for player. If disabled player object should ignore
/// collisions and gravity.
///< \return Resulting mode
virtual bool toggleRenderMode (RenderMode mode) = 0;
///< Toggle a render mode.
///< \return Resulting mode
virtual std::pair<std::string, const ESM::Potion *> createRecord (const ESM::Potion& record)
= 0;
///< Create a new recrod (of type potion) in the ESM store.
/// \return ID, pointer to created record
virtual std::pair<std::string, const ESM::Class *> createRecord (const ESM::Class& record)
= 0;
///< Create a new recrod (of type class) in the ESM store.
/// \return ID, pointer to created record
virtual const ESM::Cell *createRecord (const ESM::Cell& record) = 0;
///< Create a new recrod (of type cell) in the ESM store.
/// \return ID, pointer to created record
virtual void playAnimationGroup (const MWWorld::Ptr& ptr, const std::string& groupName,
int mode, int number = 1) = 0;
///< Run animation for a MW-reference. Calls to this function for references that are
/// currently not in the rendered scene should be ignored.
///
/// \param mode: 0 normal, 1 immediate start, 2 immediate loop
/// \param number How offen the animation should be run
virtual void skipAnimation (const MWWorld::Ptr& ptr) = 0;
///< Skip the animation for the given MW-reference for one frame. Calls to this function for
/// references that are currently not in the rendered scene should be ignored.
virtual void update (float duration) = 0;
virtual bool placeObject(const MWWorld::Ptr& object, float cursorX, float cursorY) = 0;
///< place an object into the gameworld at the specified cursor position
/// @param object
/// @param cursor X (relative 0-1)
/// @param cursor Y (relative 0-1)
/// @return true if the object was placed, or false if it was rejected because the position is too far away
virtual void dropObjectOnGround (const MWWorld::Ptr& object) = 0;
virtual bool canPlaceObject (float cursorX, float cursorY) = 0;
///< @return true if it is possible to place on object at specified cursor location
virtual void processChangedSettings (const Settings::CategorySettingVector& settings) = 0;
};
}
#endif

@ -154,19 +154,19 @@ namespace MWWorld
mRendering->skyDisable(); mRendering->skyDisable();
} }
void World::setFallbackValues(std::map<std::string,std::string> fallbackMap) void World::setFallbackValues (const std::map<std::string,std::string>& fallbackMap)
{ {
mFallback = fallbackMap; mFallback = fallbackMap;
} }
std::string World::getFallback(std::string key) std::string World::getFallback (const std::string& key) const
{ {
return getFallback(key, ""); return getFallback(key, "");
} }
std::string World::getFallback(std::string key, std::string def) std::string World::getFallback (const std::string& key, const std::string& def) const
{ {
std::map<std::string,std::string>::iterator it; std::map<std::string,std::string>::const_iterator it;
if((it = mFallback.find(key)) == mFallback.end()) if((it = mFallback.find(key)) == mFallback.end())
{ {
return def; return def;
@ -351,7 +351,7 @@ namespace MWWorld
throw std::runtime_error ("unknown Ogre handle: " + handle); throw std::runtime_error ("unknown Ogre handle: " + handle);
} }
void World::enable (Ptr reference) void World::enable (const Ptr& reference)
{ {
if (!reference.getRefData().isEnabled()) if (!reference.getRefData().isEnabled())
{ {
@ -362,7 +362,7 @@ namespace MWWorld
} }
} }
void World::disable (Ptr reference) void World::disable (const Ptr& reference)
{ {
if (reference.getRefData().isEnabled()) if (reference.getRefData().isEnabled())
{ {
@ -537,7 +537,7 @@ namespace MWWorld
} }
} }
void World::deleteObject (Ptr ptr) void World::deleteObject (const Ptr& ptr)
{ {
if (ptr.getRefData().getCount()>0) if (ptr.getRefData().getCount()>0)
{ {
@ -552,7 +552,7 @@ namespace MWWorld
} }
} }
bool World::moveObjectImp (Ptr ptr, float x, float y, float z) bool World::moveObjectImp (const Ptr& ptr, float x, float y, float z)
{ {
bool ret = false; bool ret = false;
ptr.getRefData().getPosition().pos[0] = x; ptr.getRefData().getPosition().pos[0] = x;
@ -590,7 +590,7 @@ namespace MWWorld
return ret; return ret;
} }
void World::moveObject (Ptr ptr, float x, float y, float z) void World::moveObject (const Ptr& ptr, float x, float y, float z)
{ {
moveObjectImp(ptr, x, y, z); moveObjectImp(ptr, x, y, z);
@ -753,6 +753,8 @@ namespace MWWorld
void World::update (float duration) void World::update (float duration)
{ {
/// \todo split this function up into subfunctions
mWorldScene->update (duration); mWorldScene->update (duration);
mWeatherManager->update (duration); mWeatherManager->update (duration);
@ -959,7 +961,7 @@ namespace MWWorld
return mRendering->getFader(); return mRendering->getFader();
} }
Ogre::Vector2 World::getNorthVector(Ptr::CellStore* cell) Ogre::Vector2 World::getNorthVector (CellStore* cell)
{ {
MWWorld::CellRefList<ESM::Static> statics = cell->statics; MWWorld::CellRefList<ESM::Static> statics = cell->statics;
MWWorld::LiveCellRef<ESM::Static>* ref = statics.find("northmarker"); MWWorld::LiveCellRef<ESM::Static>* ref = statics.find("northmarker");
@ -981,14 +983,14 @@ namespace MWWorld
mRendering->toggleWater(); mRendering->toggleWater();
} }
bool World::placeObject(MWWorld::Ptr object, float cursorX, float cursorY) bool World::placeObject (const Ptr& object, float cursorX, float cursorY)
{ {
std::pair<bool, Ogre::Vector3> result = mPhysics->castRay(cursorX, cursorY); std::pair<bool, Ogre::Vector3> result = mPhysics->castRay(cursorX, cursorY);
if (!result.first) if (!result.first)
return false; return false;
MWWorld::Ptr::CellStore* cell; CellStore* cell;
if (isCellExterior()) if (isCellExterior())
{ {
int cellX, cellY; int cellX, cellY;
@ -1021,7 +1023,7 @@ namespace MWWorld
return true; return true;
} }
void World::dropObjectOnGround(MWWorld::Ptr object) void World::dropObjectOnGround (const Ptr& object)
{ {
MWWorld::Ptr::CellStore* cell = getPlayer().getPlayer().getCell(); MWWorld::Ptr::CellStore* cell = getPlayer().getPlayer().getCell();

@ -25,6 +25,8 @@
#include <OgreTimer.h> #include <OgreTimer.h>
#include "../mwbase/world.hpp"
namespace Ogre namespace Ogre
{ {
class Vector3; class Vector3;
@ -58,20 +60,8 @@ namespace MWWorld
/// \brief The game world and its visual representation /// \brief The game world and its visual representation
class World class World : public MWBase::World
{ {
public:
enum RenderMode
{
Render_CollisionDebug,
Render_Wireframe,
Render_Pathgrid,
Render_Compositors
};
private:
MWRender::RenderingManager* mRendering; MWRender::RenderingManager* mRendering;
MWWorld::WeatherManager* mWeatherManager; MWWorld::WeatherManager* mWeatherManager;
@ -109,180 +99,183 @@ namespace MWWorld
int getDaysPerMonth (int month) const; int getDaysPerMonth (int month) const;
bool moveObjectImp (Ptr ptr, float x, float y, float z); bool moveObjectImp (const Ptr& ptr, float x, float y, float z);
///< @return true if the active cell (cell player is in) changed ///< @return true if the active cell (cell player is in) changed
public: public:
World (OEngine::Render::OgreRenderer& renderer, World (OEngine::Render::OgreRenderer& renderer,
const Files::Collections& fileCollections, const Files::Collections& fileCollections,
const std::string& master, const boost::filesystem::path& resDir, bool newGame, const std::string& master, const boost::filesystem::path& resDir, bool newGame,
const std::string& encoding, std::map<std::string,std::string> fallbackMap); const std::string& encoding, std::map<std::string,std::string> fallbackMap);
~World(); virtual ~World();
virtual OEngine::Render::Fader* getFader();
///< \ŧodo remove this function. Rendering details should not be exposed.
OEngine::Render::Fader* getFader(); virtual CellStore *getExterior (int x, int y);
Ptr::CellStore *getExterior (int x, int y); virtual CellStore *getInterior (const std::string& name);
Ptr::CellStore *getInterior (const std::string& name); virtual void setWaterHeight(const float height);
void setWaterHeight(const float height); virtual void toggleWater();
void toggleWater();
void adjustSky(); virtual void adjustSky();
void getTriangleBatchCount(unsigned int &triangles, unsigned int &batches); virtual void getTriangleBatchCount(unsigned int &triangles, unsigned int &batches);
void setFallbackValues(std::map<std::string,std::string> fallbackMap); virtual void setFallbackValues (const std::map<std::string,std::string>& fallbackMap);
std::string getFallback(std::string key); virtual std::string getFallback (const std::string& key) const;
std::string getFallback(std::string key, std::string def); virtual std::string getFallback (const std::string& key, const std::string& def) const;
MWWorld::Player& getPlayer(); virtual Player& getPlayer();
const ESMS::ESMStore& getStore() const; virtual const ESMS::ESMStore& getStore() const;
ESM::ESMReader& getEsmReader(); virtual ESM::ESMReader& getEsmReader();
LocalScripts& getLocalScripts(); virtual LocalScripts& getLocalScripts();
bool hasCellChanged() const; virtual bool hasCellChanged() const;
///< Has the player moved to a different cell, since the last frame? ///< Has the player moved to a different cell, since the last frame?
bool isCellExterior() const; virtual bool isCellExterior() const;
bool isCellQuasiExterior() const;
virtual bool isCellQuasiExterior() const;
Ogre::Vector2 getNorthVector(Ptr::CellStore* cell); virtual Ogre::Vector2 getNorthVector (CellStore* cell);
///< get north vector (OGRE coordinates) for given interior cell ///< get north vector (OGRE coordinates) for given interior cell
Globals::Data& getGlobalVariable (const std::string& name); virtual Globals::Data& getGlobalVariable (const std::string& name);
Globals::Data getGlobalVariable (const std::string& name) const; virtual Globals::Data getGlobalVariable (const std::string& name) const;
char getGlobalVariableType (const std::string& name) const; virtual char getGlobalVariableType (const std::string& name) const;
///< Return ' ', if there is no global variable with this name. ///< Return ' ', if there is no global variable with this name.
Ptr getPtr (const std::string& name, bool activeOnly); virtual Ptr getPtr (const std::string& name, bool activeOnly);
///< Return a pointer to a liveCellRef with the given name. ///< Return a pointer to a liveCellRef with the given name.
/// \param activeOnly do non search inactive cells. /// \param activeOnly do non search inactive cells.
Ptr getPtrViaHandle (const std::string& handle); virtual Ptr getPtrViaHandle (const std::string& handle);
///< Return a pointer to a liveCellRef with the given Ogre handle. ///< Return a pointer to a liveCellRef with the given Ogre handle.
/// \todo enable reference in the OGRE scene virtual void enable (const Ptr& ptr);
void enable (Ptr reference);
/// \todo 5disable reference in the OGRE scene virtual void disable (const Ptr& ptr);
void disable (Ptr reference);
void advanceTime (double hours); virtual void advanceTime (double hours);
///< Advance in-game time. ///< Advance in-game time.
void setHour (double hour); virtual void setHour (double hour);
///< Set in-game time hour. ///< Set in-game time hour.
void setMonth (int month); virtual void setMonth (int month);
///< Set in-game time month. ///< Set in-game time month.
void setDay (int day); virtual void setDay (int day);
///< Set in-game time day. ///< Set in-game time day.
TimeStamp getTimeStamp() const; virtual TimeStamp getTimeStamp() const;
///< Return current in-game time stamp. ///< Return current in-game time stamp.
bool toggleSky(); virtual bool toggleSky();
///< \return Resulting mode ///< \return Resulting mode
void changeWeather(const std::string& region, const unsigned int id); virtual void changeWeather (const std::string& region, const unsigned int id);
int getCurrentWeather() const; virtual int getCurrentWeather() const;
int getMasserPhase() const; virtual int getMasserPhase() const;
int getSecundaPhase() const; virtual int getSecundaPhase() const;
void setMoonColour (bool red); virtual void setMoonColour (bool red);
float getTimeScaleFactor() const; virtual float getTimeScaleFactor() const;
void changeToInteriorCell (const std::string& cellName, const ESM::Position& position); virtual void changeToInteriorCell (const std::string& cellName,
const ESM::Position& position);
///< Move to interior cell. ///< Move to interior cell.
void changeToExteriorCell (const ESM::Position& position); virtual void changeToExteriorCell (const ESM::Position& position);
///< Move to exterior cell. ///< Move to exterior cell.
const ESM::Cell *getExterior (const std::string& cellName) const; virtual const ESM::Cell *getExterior (const std::string& cellName) const;
///< Return a cell matching the given name or a 0-pointer, if there is no such cell. ///< Return a cell matching the given name or a 0-pointer, if there is no such cell.
void markCellAsUnchanged(); virtual void markCellAsUnchanged();
std::string getFacedHandle(); virtual std::string getFacedHandle();
///< Return handle of the object the player is looking at ///< Return handle of the object the player is looking at
void deleteObject (Ptr ptr); virtual void deleteObject (const Ptr& ptr);
void moveObject (Ptr ptr, float x, float y, float z); virtual void moveObject (const Ptr& ptr, float x, float y, float z);
void indexToPosition (int cellX, int cellY, float &x, float &y, bool centre = false) const; virtual void indexToPosition (int cellX, int cellY, float &x, float &y, bool centre = false)
const;
///< Convert cell numbers to position. ///< Convert cell numbers to position.
void positionToIndex (float x, float y, int &cellX, int &cellY) const; virtual void positionToIndex (float x, float y, int &cellX, int &cellY) const;
///< Convert position to cell numbers ///< Convert position to cell numbers
void doPhysics (const std::vector<std::pair<std::string, Ogre::Vector3> >& actors, virtual void doPhysics (const std::vector<std::pair<std::string, Ogre::Vector3> >& actors,
float duration); float duration);
///< Run physics simulation and modify \a world accordingly. ///< Run physics simulation and modify \a world accordingly.
bool toggleCollisionMode(); virtual bool toggleCollisionMode();
///< Toggle collision mode for player. If disabled player object should ignore ///< Toggle collision mode for player. If disabled player object should ignore
/// collisions and gravity. /// collisions and gravity.
///< \return Resulting mode ///< \return Resulting mode
bool toggleRenderMode (RenderMode mode); virtual bool toggleRenderMode (RenderMode mode);
///< Toggle a render mode. ///< Toggle a render mode.
///< \return Resulting mode ///< \return Resulting mode
std::pair<std::string, const ESM::Potion *> createRecord (const ESM::Potion& record); virtual std::pair<std::string, const ESM::Potion *> createRecord (const ESM::Potion& record);
///< Create a new recrod (of type potion) in the ESM store. ///< Create a new recrod (of type potion) in the ESM store.
/// \return ID, pointer to created record /// \return ID, pointer to created record
std::pair<std::string, const ESM::Class *> createRecord (const ESM::Class& record); virtual std::pair<std::string, const ESM::Class *> createRecord (const ESM::Class& record);
///< Create a new recrod (of type class) in the ESM store. ///< Create a new recrod (of type class) in the ESM store.
/// \return ID, pointer to created record /// \return ID, pointer to created record
const ESM::Cell *createRecord (const ESM::Cell& record); virtual const ESM::Cell *createRecord (const ESM::Cell& record);
///< Create a new recrod (of type cell) in the ESM store. ///< Create a new recrod (of type cell) in the ESM store.
/// \return ID, pointer to created record /// \return ID, pointer to created record
void playAnimationGroup (const MWWorld::Ptr& ptr, const std::string& groupName, int mode, virtual void playAnimationGroup (const MWWorld::Ptr& ptr, const std::string& groupName,
int number = 1); int mode, int number = 1);
///< Run animation for a MW-reference. Calls to this function for references that are ///< Run animation for a MW-reference. Calls to this function for references that are
/// currently not in the rendered scene should be ignored. /// currently not in the rendered scene should be ignored.
/// ///
/// \param mode: 0 normal, 1 immediate start, 2 immediate loop /// \param mode: 0 normal, 1 immediate start, 2 immediate loop
/// \param number How offen the animation should be run /// \param number How offen the animation should be run
void skipAnimation (const MWWorld::Ptr& ptr); virtual void skipAnimation (const MWWorld::Ptr& ptr);
///< Skip the animation for the given MW-reference for one frame. Calls to this function for ///< Skip the animation for the given MW-reference for one frame. Calls to this function for
/// references that are currently not in the rendered scene should be ignored. /// references that are currently not in the rendered scene should be ignored.
void update (float duration); virtual void update (float duration);
bool placeObject(MWWorld::Ptr object, float cursorX, float cursorY); virtual bool placeObject (const Ptr& object, float cursorX, float cursorY);
///< place an object into the gameworld at the specified cursor position ///< place an object into the gameworld at the specified cursor position
/// @param object /// @param object
/// @param cursor X (relative 0-1) /// @param cursor X (relative 0-1)
/// @param cursor Y (relative 0-1) /// @param cursor Y (relative 0-1)
/// @return true if the object was placed, or false if it was rejected because the position is too far away /// @return true if the object was placed, or false if it was rejected because the position is too far away
void dropObjectOnGround(MWWorld::Ptr object); virtual void dropObjectOnGround (const Ptr& object);
bool canPlaceObject(float cursorX, float cursorY); virtual bool canPlaceObject(float cursorX, float cursorY);
///< @return true if it is possible to place on object at specified cursor location ///< @return true if it is possible to place on object at specified cursor location
void processChangedSettings(const Settings::CategorySettingVector& settings); virtual void processChangedSettings(const Settings::CategorySettingVector& settings);
}; };
} }

Loading…
Cancel
Save