Commit c9259249 authored by scrawl's avatar scrawl

OpenMW: create a window and render the starting cell(s)

parent a0b43f42
......@@ -127,8 +127,7 @@ int main(int argc, char** argv)
osg::Group* newNode = new osg::Group;
NifOsg::Loader loader;
Resource::TextureManager texMgr(&resourceMgr);
loader.mTextureManager = &texMgr;
newNode->addChild(loader.load(nif));
newNode->addChild(loader.load(nif, &texMgr));
osg::PositionAttitudeTransform* trans = new osg::PositionAttitudeTransform;
root->addChild(trans);
......
......@@ -20,8 +20,8 @@ set(GAME_HEADER
source_group(game FILES ${GAME} ${GAME_HEADER})
add_openmw_dir (mwrender
actors objects
# renderingmanager debugging sky camera animation npcanimation creatureanimation activatoranimation
actors objects renderingmanager animation
# debugging sky camera npcanimation creatureanimation activatoranimation
# renderinginterface localmap occlusionquery water shadows
# characterpreview globalmap ripplesimulation refraction
# terrainstorage renderconst effectmanager weaponanimation
......@@ -129,6 +129,7 @@ target_link_libraries(openmw
${OENGINE_LIBRARY}
${OGRE_LIBRARIES}
${OGRE_STATIC_PLUGINS}
${OPENSCENEGRAPH_LIBRARIES}
${Boost_LIBRARIES}
${OPENAL_LIBRARY}
${SOUND_INPUT_LIBRARY}
......
......@@ -3,15 +3,23 @@
#include <stdexcept>
#include <iomanip>
#include <OgreRoot.h>
#include <OgreRenderWindow.h>
#include <osgGA/TrackballManipulator>
#include <osgViewer/ViewerEventHandlers>
#include <osgUtil/IncrementalCompileOperation>
#include <MyGUI_WidgetManager.h>
#include <SDL.h>
// TODO: move to component
#include <openengine/misc/rng.hpp>
#include <components/vfs/manager.hpp>
#include <components/vfs/registerarchives.hpp>
#include <components/resource/resourcesystem.hpp>
#include <components/compiler/extensions0.hpp>
#include <components/files/configurationmanager.hpp>
......@@ -172,8 +180,7 @@ bool OMW::Engine::frameRenderingQueued (const Ogre::FrameEvent& evt)
}
OMW::Engine::Engine(Files::ConfigurationManager& configurationManager)
: mOgre (0)
, mVerboseScripts (false)
: mVerboseScripts (false)
, mSkipMenu (false)
, mUseSound (true)
, mCompileAll (false)
......@@ -220,10 +227,6 @@ void OMW::Engine::addResourcesDirectory (const boost::filesystem::path& path)
{
}
void OMW::Engine::addZipResource (const boost::filesystem::path& path)
{
}
void OMW::Engine::enableFSStrict(bool fsStrict)
{
mFSStrict = fsStrict;
......@@ -318,21 +321,27 @@ void OMW::Engine::prepareEngine (Settings::Manager & settings)
addResourcesDirectory(mResDir / "shadows");
addResourcesDirectory(mResDir / "materials");
OEngine::Render::WindowSettings windowSettings;
windowSettings.fullscreen = settings.getBool("fullscreen", "Video");
windowSettings.window_border = settings.getBool("window border", "Video");
windowSettings.window_x = settings.getInt("resolution x", "Video");
windowSettings.window_y = settings.getInt("resolution y", "Video");
windowSettings.screen = settings.getInt("screen", "Video");
windowSettings.vsync = settings.getBool("vsync", "Video");
windowSettings.icon = "openmw.png";
std::string aa = settings.getString("antialiasing", "Video");
windowSettings.fsaa = (aa.substr(0, 4) == "MSAA") ? aa.substr(5, aa.size()-5) : "0";
//OEngine::Render::WindowSettings windowSettings;
//windowSettings.fullscreen = settings.getBool("fullscreen", "Video");
//windowSettings.window_border = settings.getBool("window border", "Video");
//windowSettings.vsync = settings.getBool("vsync", "Video");
//windowSettings.icon = "openmw.png";
//std::string aa = settings.getString("antialiasing", "Video");
//windowSettings.fsaa = (aa.substr(0, 4) == "MSAA") ? aa.substr(5, aa.size()-5) : "0";
SDL_SetHint(SDL_HINT_VIDEO_MINIMIZE_ON_FOCUS_LOSS,
settings.getBool("minimize on focus loss", "Video") ? "1" : "0");
//Bsa::registerResources (mFileCollections, mArchives, true, mFSStrict);
// not handling fullscreen yet, we should figure this out when adding SDL to the mix
mViewer.setUpViewInWindow(0, 0, settings.getInt("resolution x", "Video"), settings.getInt("resolution y", "Video"), settings.getInt("screen", "Video"));
osg::ref_ptr<osg::Group> rootNode (new osg::Group);
mViewer.setSceneData(rootNode);
mVFS.reset(new VFS::Manager(mFSStrict));
VFS::registerArchives(mVFS.get(), mFileCollections, mArchives, true);
mResourceSystem.reset(new Resource::ResourceSystem(mVFS.get()));
// Create input and UI first to set up a bootstrapping environment for
// showing a loading screen and keeping the window responsive while doing so
......@@ -378,8 +387,8 @@ void OMW::Engine::prepareEngine (Settings::Manager & settings)
}
// Create the world
mEnvironment.setWorld( new MWWorld::World (mFileCollections, mContentFiles,
mResDir, mCfgMgr.getCachePath(), mEncoder, mFallbackMap,
mEnvironment.setWorld( new MWWorld::World (mViewer, rootNode, mResourceSystem.get(),
mFileCollections, mContentFiles, mEncoder, mFallbackMap,
mActivationDistanceOverride, mCellName, mStartupScript));
MWBase::Environment::get().getWorld()->setupPlayer();
//input->setPlayer(&mEnvironment.getWorld()->getPlayer());
......@@ -460,7 +469,7 @@ void OMW::Engine::go()
{
MWBase::Environment::get().getStateManager()->loadGame(mSaveGameFile);
}
else if (!mSkipMenu)
else if (0)// !mSkipMenu)
{
// start in main menu
MWBase::Environment::get().getWindowManager()->pushGuiMode (MWGui::GM_MainMenu);
......@@ -481,6 +490,22 @@ void OMW::Engine::go()
}
// Start the main rendering loop
mViewer.setCameraManipulator(new osgGA::TrackballManipulator);
mViewer.addEventHandler(new osgViewer::StatsHandler);
osg::Timer timer;
//osgUtil::IncrementalCompileOperation* ico = new osgUtil::IncrementalCompileOperation;
//ico->compileAllForNextFrame(1);
//mViewer.setRealizeOperation(ico);
mViewer.realize();
std::cout << "realize took " << timer.time_m() << std::endl;
while (!mViewer.done())
{
MWBase::Environment::get().getWorld()->update(0.f, false);
mViewer.frame(/*simulationTime*/);
}
/*
Ogre::Timer timer;
while (!MWBase::Environment::get().getStateManager()->hasQuitRequest())
......
......@@ -9,11 +9,23 @@
#include <components/settings/settings.hpp>
#include <components/nifcache/nifcache.hpp>
#include <osgViewer/Viewer>
#include "mwbase/environment.hpp"
#include "mwworld/ptr.hpp"
namespace Resource
{
class ResourceSystem;
}
namespace VFS
{
class Manager;
}
namespace Compiler
{
class Context;
......@@ -39,19 +51,6 @@ namespace MWGui
class WindowManager;
}
namespace OEngine
{
namespace GUI
{
class MyGUIManager;
}
namespace Render
{
class OgreRenderer;
}
}
namespace Files
{
struct ConfigurationManager;
......@@ -62,13 +61,15 @@ namespace OMW
/// \brief Main engine class, that brings together all the components of OpenMW
class Engine : private Ogre::FrameListener
{
std::auto_ptr<VFS::Manager> mVFS;
std::auto_ptr<Resource::ResourceSystem> mResourceSystem;
MWBase::Environment mEnvironment;
ToUTF8::FromType mEncoding;
ToUTF8::Utf8Encoder* mEncoder;
Files::PathContainer mDataDirs;
std::vector<std::string> mArchives;
boost::filesystem::path mResDir;
OEngine::Render::OgreRenderer *mOgre;
osgViewer::Viewer mViewer;
std::string mCellName;
std::vector<std::string> mContentFiles;
bool mVerboseScripts;
......@@ -108,9 +109,6 @@ namespace OMW
/// \note This function works recursively.
void addResourcesDirectory (const boost::filesystem::path& path);
/// add a .zip resource
void addZipResource (const boost::filesystem::path& path);
void executeLocalScripts();
virtual bool frameRenderingQueued (const Ogre::FrameEvent& evt);
......
......@@ -16,7 +16,7 @@
#include "../mwworld/failedaction.hpp"
#include "../mwworld/nullaction.hpp"
#include "../mwrender/actors.hpp"
#include "../mwrender/objects.hpp"
#include "../mwrender/renderinginterface.hpp"
#include "../mwgui/tooltips.hpp"
......@@ -34,8 +34,7 @@ namespace MWClass
void Activator::insertObjectRendering (const MWWorld::Ptr& ptr, const std::string& model, MWRender::RenderingInterface& renderingInterface) const
{
if (!model.empty()) {
MWRender::Actors& actors = renderingInterface.getActors();
actors.insertActivator(ptr, model);
renderingInterface.getObjects().insertModel(ptr, model, true);
}
}
......
......@@ -23,7 +23,7 @@
#include "../mwgui/tooltips.hpp"
#include "../mwrender/actors.hpp"
#include "../mwrender/objects.hpp"
#include "../mwrender/renderinginterface.hpp"
#include "../mwmechanics/npcstats.hpp"
......@@ -93,8 +93,7 @@ namespace MWClass
void Container::insertObjectRendering (const MWWorld::Ptr& ptr, const std::string& model, MWRender::RenderingInterface& renderingInterface) const
{
if (!model.empty()) {
MWRender::Actors& actors = renderingInterface.getActors();
actors.insertActivator(ptr, model);
renderingInterface.getObjects().insertModel(ptr, model, true);
}
}
......
......@@ -29,7 +29,7 @@
#include "../mwworld/cellstore.hpp"
#include "../mwrender/renderinginterface.hpp"
#include "../mwrender/actors.hpp"
#include "../mwrender/objects.hpp"
#include "../mwgui/tooltips.hpp"
......@@ -163,10 +163,10 @@ namespace MWClass
void Creature::insertObjectRendering (const MWWorld::Ptr& ptr, const std::string& model, MWRender::RenderingInterface& renderingInterface) const
{
//MWWorld::LiveCellRef<ESM::Creature> *ref = ptr.get<ESM::Creature>();
MWWorld::LiveCellRef<ESM::Creature> *ref = ptr.get<ESM::Creature>();
//MWRender::Actors& actors = renderingInterface.getActors();
//actors.insertCreature(ptr, model, (ref->mBase->mFlags & ESM::Creature::Weapon) != 0);
MWRender::Objects& objects = renderingInterface.getObjects();
objects.insertCreature(ptr, model, (ref->mBase->mFlags & ESM::Creature::Weapon) != 0);
}
void Creature::insertObject(const MWWorld::Ptr& ptr, const std::string& model, MWWorld::PhysicsSystem& physics) const
......
......@@ -24,7 +24,7 @@
#include "../mwgui/tooltips.hpp"
#include "../mwrender/actors.hpp"
#include "../mwrender/objects.hpp"
#include "../mwrender/renderinginterface.hpp"
namespace
......@@ -52,8 +52,7 @@ namespace MWClass
void Door::insertObjectRendering (const MWWorld::Ptr& ptr, const std::string& model, MWRender::RenderingInterface& renderingInterface) const
{
if (!model.empty()) {
MWRender::Actors& actors = renderingInterface.getActors();
actors.insertActivator(ptr, model);
renderingInterface.getObjects().insertModel(ptr, model, true);
}
}
......
......@@ -23,7 +23,6 @@
#include "../mwgui/tooltips.hpp"
#include "../mwrender/objects.hpp"
#include "../mwrender/actors.hpp"
#include "../mwrender/renderinginterface.hpp"
namespace MWClass
......@@ -39,8 +38,7 @@ namespace MWClass
ptr.get<ESM::Light>();
// Insert even if model is empty, so that the light is added
MWRender::Actors& actors = renderingInterface.getActors();
actors.insertActivator(ptr, model, !(ref->mBase->mData.mFlags & ESM::Light::OffDefault));
renderingInterface.getObjects().insertModel(ptr, model, true, !(ref->mBase->mData.mFlags & ESM::Light::OffDefault));
}
void Light::insertObject(const MWWorld::Ptr& ptr, const std::string& model, MWWorld::PhysicsSystem& physics) const
......
......@@ -35,7 +35,7 @@
#include "../mwworld/physicssystem.hpp"
#include "../mwworld/cellstore.hpp"
#include "../mwrender/actors.hpp"
#include "../mwrender/objects.hpp"
#include "../mwrender/renderinginterface.hpp"
#include "../mwgui/tooltips.hpp"
......@@ -409,7 +409,7 @@ namespace MWClass
void Npc::insertObjectRendering (const MWWorld::Ptr& ptr, const std::string& model, MWRender::RenderingInterface& renderingInterface) const
{
renderingInterface.getActors().insertNPC(ptr);
renderingInterface.getObjects().insertNPC(ptr);
}
void Npc::insertObject(const MWWorld::Ptr& ptr, const std::string& model, MWWorld::PhysicsSystem& physics) const
......
......@@ -1702,6 +1702,7 @@ namespace MWGui
void WindowManager::playVideo(const std::string &name, bool allowSkipping)
{
return;
mVideoWidget->playVideo("video\\" + name);
mVideoWidget->eventKeyButtonPressed.clear();
......
......@@ -474,7 +474,7 @@ namespace MWMechanics
Ogre::Vector3 dir = playerPos - actorPos;
Ogre::Radian faceAngle = Ogre::Math::ATan2(dir.x,dir.y);
Ogre::Radian actorAngle = actor.getRefData().getBaseNode()->getOrientation().getRoll();
Ogre::Radian actorAngle = actor.getRefData().getBaseNodeOld()->getOrientation().getRoll();
// an attempt at reducing the turning animation glitch
if( Ogre::Math::Abs( faceAngle - actorAngle ) >= Ogre::Degree(5) ) // TODO: is there a better way?
{
......
......@@ -75,7 +75,7 @@ namespace MWMechanics
return false;
Ogre::Degree angle = signedAngle (Ogre::Vector3(attacker.getRefData().getPosition().pos) - Ogre::Vector3(blocker.getRefData().getPosition().pos),
blocker.getRefData().getBaseNode()->getOrientation().yAxis(), Ogre::Vector3(0,0,1));
blocker.getRefData().getBaseNodeOld()->getOrientation().yAxis(), Ogre::Vector3(0,0,1));
const MWWorld::Store<ESM::GameSetting>& gmst = MWBase::Environment::get().getWorld()->getStore().get<ESM::GameSetting>();
if (angle.valueDegrees() < gmst.find("fCombatBlockLeftAngle")->getFloat())
......
......@@ -3,6 +3,8 @@
#include <openengine/misc/rng.hpp>
#include <iostream>
#include "../mwworld/ptr.hpp"
#include "../mwworld/esmstore.hpp"
#include "../mwworld/manualref.hpp"
......
......@@ -1385,7 +1385,7 @@ namespace MWMechanics
static float fSneakViewMult = store.find("fSneakViewMult")->getFloat();
float y = 0;
Ogre::Vector3 vec = pos1 - pos2;
Ogre::Radian angle = observer.getRefData().getBaseNode()->getOrientation().yAxis().angleBetween(vec);
Ogre::Radian angle = observer.getRefData().getBaseNodeOld()->getOrientation().yAxis().angleBetween(vec);
if (angle < Ogre::Degree(90))
y = obsTerm * observerStats.getFatigueTerm() * fSneakNoViewMult;
else
......
......@@ -418,7 +418,7 @@ namespace MWMechanics
absorbed = (OEngine::Misc::Rng::roll0to99() < absorb);
if (absorbed)
{
const ESM::Static* absorbStatic = MWBase::Environment::get().getWorld()->getStore().get<ESM::Static>().find ("VFX_Absorb");
//const ESM::Static* absorbStatic = MWBase::Environment::get().getWorld()->getStore().get<ESM::Static>().find ("VFX_Absorb");
//MWBase::Environment::get().getWorld()->getAnimation(target)->addEffect(
// "meshes\\" + absorbStatic->mModel, ESM::MagicEffect::SpellAbsorption, false, "");
// Magicka is increased by cost of spell
......@@ -466,7 +466,7 @@ namespace MWMechanics
bool isReflected = (OEngine::Misc::Rng::roll0to99() < reflect);
if (isReflected)
{
const ESM::Static* reflectStatic = MWBase::Environment::get().getWorld()->getStore().get<ESM::Static>().find ("VFX_Reflect");
//const ESM::Static* reflectStatic = MWBase::Environment::get().getWorld()->getStore().get<ESM::Static>().find ("VFX_Reflect");
//MWBase::Environment::get().getWorld()->getAnimation(target)->addEffect(
// "meshes\\" + reflectStatic->mModel, ESM::MagicEffect::Reflect, false, "");
reflectedEffects.mList.push_back(*effectIt);
......@@ -565,7 +565,7 @@ namespace MWMechanics
}
// Add VFX
const ESM::Static* castStatic;
/*const ESM::Static* castStatic;
if (!magicEffect->mHit.empty())
castStatic = MWBase::Environment::get().getWorld()->getStore().get<ESM::Static>().find (magicEffect->mHit);
else
......@@ -574,9 +574,10 @@ namespace MWMechanics
// TODO: VFX are no longer active after saving/reloading the game
bool loop = (magicEffect->mData.mFlags & ESM::MagicEffect::ContinuousVfx) != 0;
// Note: in case of non actor, a free effect should be fine as well
//MWRender::Animation* anim = MWBase::Environment::get().getWorld()->getAnimation(target);
//if (anim)
// anim->addEffect("meshes\\" + castStatic->mModel, magicEffect->mIndex, loop, "");
MWRender::Animation* anim = MWBase::Environment::get().getWorld()->getAnimation(target);
if (anim)
anim->addEffect("meshes\\" + castStatic->mModel, magicEffect->mIndex, loop, "");
*/
}
}
}
......
#ifndef GAME_RENDER_ACTORS_H
#define GAME_RENDER_ACTORS_H
//#include <openengine/ogre/renderer.hpp>
#include <string>
namespace OEngine
......
This diff is collapsed.
......@@ -4,15 +4,20 @@
#include <OgreController.h>
#include <OgreVector3.h>
#include <components/nifogre/ogrenifloader.hpp>
#include "../mwworld/ptr.hpp"
#include <components/nifosg/controller.hpp>
namespace ESM
{
struct Light;
}
namespace Resource
{
class ResourceSystem;
}
namespace MWRender
{
class Camera;
......@@ -69,20 +74,18 @@ protected:
virtual void setValue(Ogre::Real value);
};
class NullAnimationTime : public Ogre::ControllerValue<Ogre::Real>
class NullAnimationTime : public NifOsg::ControllerSource
{
public:
virtual Ogre::Real getValue() const
{ return 0.0f; }
virtual void setValue(Ogre::Real value)
{ }
virtual float getValue(osg::NodeVisitor *nv)
{
return 0.f;
}
};
struct AnimSource : public Ogre::AnimationAlloc {
NifOgre::TextKeyMap mTextKeys;
//NifOgre::TextKeyMap mTextKeys;
std::vector<Ogre::Controller<Ogre::Real> > mControllers[sNumGroups];
};
typedef std::vector< Ogre::SharedPtr<AnimSource> > AnimSourceList;
......@@ -113,106 +116,71 @@ protected:
typedef std::map<Ogre::MovableObject*,std::string> ObjectAttachMap;
struct EffectParams
{
std::string mModelName; // Just here so we don't add the same effect twice
NifOgre::ObjectScenePtr mObjects;
int mEffectId;
bool mLoop;
std::string mBoneName;
};
osg::ref_ptr<osg::Group> mInsert;
std::vector<EffectParams> mEffects;
osg::ref_ptr<osg::Node> mObjectRoot;
MWWorld::Ptr mPtr;
Ogre::Light* mGlowLight;
Ogre::SceneNode *mInsert;
Ogre::Entity *mSkelBase;
NifOgre::ObjectScenePtr mObjectRoot;
AnimSourceList mAnimSources;
Ogre::Node *mAccumRoot;
Ogre::Node *mNonAccumRoot;
NifOgre::NodeTargetValue<Ogre::Real> *mNonAccumCtrl;
Ogre::Vector3 mAccumulate;
AnimStateMap mStates;
Ogre::SharedPtr<AnimationTime> mAnimationTimePtr[sNumGroups];
Ogre::SharedPtr<NullAnimationTime> mNullAnimationTimePtr;
ObjectAttachMap mAttachedObjects;
Resource::ResourceSystem* mResourceSystem;
/* Sets the appropriate animations on the bone groups based on priority.
*/
void resetActiveGroups();
//void resetActiveGroups();
static size_t detectAnimGroup(const Ogre::Node *node);
//static size_t detectAnimGroup(const Ogre::Node *node);
/*
static float calcAnimVelocity(const NifOgre::TextKeyMap &keys,
NifOgre::NodeTargetValue<Ogre::Real> *nonaccumctrl,
const Ogre::Vector3 &accum,
const std::string &groupname);
/* Updates a skeleton instance so that all bones matching the source skeleton (based on
* bone names) are positioned identically. */
void updateSkeletonInstance(const Ogre::SkeletonInstance *skelsrc, Ogre::SkeletonInstance *skel);
*/
/* Updates the position of the accum root node for the given time, and
* returns the wanted movement vector from the previous time. */
void updatePosition(float oldtime, float newtime, Ogre::Vector3 &position);
//void updatePosition(float oldtime, float newtime, Ogre::Vector3 &position);
static NifOgre::TextKeyMap::const_iterator findGroupStart(const NifOgre::TextKeyMap &keys, const std::string &groupname);
//static NifOgre::TextKeyMap::const_iterator findGroupStart(const NifOgre::TextKeyMap &keys, const std::string &groupname);
/* Resets the animation to the time of the specified start marker, without
* moving anything, and set the end time to the specified stop marker. If
* the marker is not found, or if the markers are the same, it returns
* false.
*/
bool reset(AnimState &state, const NifOgre::TextKeyMap &keys,
const std::string &groupname, const std::string &start, const std::string &stop,
float startpoint, bool loopfallback);
//bool reset(AnimState &state, const NifOgre::TextKeyMap &keys,
// const std::string &groupname, const std::string &start, const std::string &stop,
// float startpoint, bool loopfallback);
void handleTextKey(AnimState &state, const std::string &groupname, const NifOgre::TextKeyMap::const_iterator &key,
const NifOgre::TextKeyMap& map);
//void handleTextKey(AnimState &state, const std::string &groupname, const NifOgre::TextKeyMap::const_iterator &key,
// const NifOgre::TextKeyMap& map);
/* Sets the root model of the object. If 'baseonly' is true, then any meshes or particle
* systems in the model are ignored (useful for NPCs, where only the skeleton is needed for
* the root).
/* Sets the root model of the object.
*
* Note that you must make sure all animation sources are cleared before reseting the object
* root. All nodes previously retrieved with getNode will also become invalidated.
*/
void setObjectRoot(const std::string &model, bool baseonly);
void setObjectRoot(const std::string &model);
/* Adds the keyframe controllers in the specified model as a new animation source. Note that
* the filename portion of the provided model name will be prepended with 'x', and the .nif
* extension will be replaced with .kf. */
void addAnimSource(const std::string &model);
//void addAnimSource(const std::string &model);
/** Adds an additional light to the given object list using the specified ESM record. */
void addExtraLight(Ogre::SceneManager *sceneMgr, NifOgre::ObjectScenePtr objlist, const ESM::Light *light);
void clearAnimSources();
//void addExtraLight(Ogre::SceneManager *sceneMgr, NifOgre::ObjectScenePtr objlist, const ESM::Light *light);