mirror of
https://github.com/OpenMW/openmw.git
synced 2025-02-05 14:15:40 +00:00
Merge remote-tracking branch 'zini/master' into animation2
This commit is contained in:
commit
a14132b5a0
24 changed files with 542 additions and 353 deletions
1
.gitmodules
vendored
1
.gitmodules
vendored
|
@ -1 +0,0 @@
|
||||||
|
|
|
@ -336,7 +336,8 @@ void OMW::Engine::go()
|
||||||
|
|
||||||
// Create the world
|
// Create the world
|
||||||
mEnvironment.setWorld (new MWWorld::World (*mOgre, mFileCollections, mMaster,
|
mEnvironment.setWorld (new MWWorld::World (*mOgre, mFileCollections, mMaster,
|
||||||
mResDir, mCfgMgr.getCachePath(), mNewGame, &encoder, mFallbackMap));
|
mResDir, mCfgMgr.getCachePath(), mNewGame, &encoder, mFallbackMap,
|
||||||
|
mActivationDistanceOverride));
|
||||||
|
|
||||||
//Load translation data
|
//Load translation data
|
||||||
mTranslationDataStorage.setEncoder(&encoder);
|
mTranslationDataStorage.setEncoder(&encoder);
|
||||||
|
@ -427,12 +428,7 @@ void OMW::Engine::activate()
|
||||||
if (MWBase::Environment::get().getWindowManager()->isGuiMode())
|
if (MWBase::Environment::get().getWindowManager()->isGuiMode())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
std::string handle = MWBase::Environment::get().getWorld()->getFacedHandle();
|
MWWorld::Ptr ptr = MWBase::Environment::get().getWorld()->getFacedObject();
|
||||||
|
|
||||||
if (handle.empty())
|
|
||||||
return;
|
|
||||||
|
|
||||||
MWWorld::Ptr ptr = MWBase::Environment::get().getWorld()->searchPtrViaHandle (handle);
|
|
||||||
|
|
||||||
if (ptr.isEmpty())
|
if (ptr.isEmpty())
|
||||||
return;
|
return;
|
||||||
|
@ -514,3 +510,9 @@ void OMW::Engine::setStartupScript (const std::string& path)
|
||||||
{
|
{
|
||||||
mStartupScript = path;
|
mStartupScript = path;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void OMW::Engine::setActivationDistanceOverride (int distance)
|
||||||
|
{
|
||||||
|
mActivationDistanceOverride = distance;
|
||||||
|
}
|
||||||
|
|
|
@ -76,6 +76,7 @@ namespace OMW
|
||||||
std::map<std::string,std::string> mFallbackMap;
|
std::map<std::string,std::string> mFallbackMap;
|
||||||
bool mScriptConsoleMode;
|
bool mScriptConsoleMode;
|
||||||
std::string mStartupScript;
|
std::string mStartupScript;
|
||||||
|
int mActivationDistanceOverride;
|
||||||
|
|
||||||
Compiler::Extensions mExtensions;
|
Compiler::Extensions mExtensions;
|
||||||
Compiler::Context *mScriptContext;
|
Compiler::Context *mScriptContext;
|
||||||
|
@ -167,6 +168,9 @@ namespace OMW
|
||||||
/// Set path for a script that is run on startup in the console.
|
/// Set path for a script that is run on startup in the console.
|
||||||
void setStartupScript (const std::string& path);
|
void setStartupScript (const std::string& path);
|
||||||
|
|
||||||
|
/// Override the game setting specified activation distance.
|
||||||
|
void setActivationDistanceOverride (int distance);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Files::ConfigurationManager& mCfgMgr;
|
Files::ConfigurationManager& mCfgMgr;
|
||||||
};
|
};
|
||||||
|
|
|
@ -149,6 +149,8 @@ bool parseOptions (int argc, char** argv, OMW::Engine& engine, Files::Configurat
|
||||||
("fallback", bpo::value<FallbackMap>()->default_value(FallbackMap(), "")
|
("fallback", bpo::value<FallbackMap>()->default_value(FallbackMap(), "")
|
||||||
->multitoken()->composing(), "fallback values")
|
->multitoken()->composing(), "fallback values")
|
||||||
|
|
||||||
|
("activate-dist", bpo::value <int> ()->default_value (-1), "activation distance override");
|
||||||
|
|
||||||
;
|
;
|
||||||
|
|
||||||
bpo::parsed_options valid_opts = bpo::command_line_parser(argc, argv)
|
bpo::parsed_options valid_opts = bpo::command_line_parser(argc, argv)
|
||||||
|
@ -236,6 +238,7 @@ bool parseOptions (int argc, char** argv, OMW::Engine& engine, Files::Configurat
|
||||||
engine.setFallbackValues(variables["fallback"].as<FallbackMap>().mMap);
|
engine.setFallbackValues(variables["fallback"].as<FallbackMap>().mMap);
|
||||||
engine.setScriptConsoleMode (variables["script-console"].as<bool>());
|
engine.setScriptConsoleMode (variables["script-console"].as<bool>());
|
||||||
engine.setStartupScript (variables["script-run"].as<std::string>());
|
engine.setStartupScript (variables["script-run"].as<std::string>());
|
||||||
|
engine.setActivationDistanceOverride (variables["activate-dist"].as<int>());
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -199,8 +199,8 @@ namespace MWBase
|
||||||
|
|
||||||
virtual void markCellAsUnchanged() = 0;
|
virtual void markCellAsUnchanged() = 0;
|
||||||
|
|
||||||
virtual std::string getFacedHandle() = 0;
|
virtual MWWorld::Ptr getFacedObject() = 0;
|
||||||
///< Return handle of the object the player is looking at
|
///< Return pointer to the object the player is looking at, if it is within activation range
|
||||||
|
|
||||||
virtual void deleteObject (const MWWorld::Ptr& ptr) = 0;
|
virtual void deleteObject (const MWWorld::Ptr& ptr) = 0;
|
||||||
|
|
||||||
|
|
|
@ -244,8 +244,7 @@ void HUD::onWorldClicked(MyGUI::Widget* _sender)
|
||||||
if ( (mode != GM_Console) && (mode != GM_Container) && (mode != GM_Inventory) )
|
if ( (mode != GM_Console) && (mode != GM_Container) && (mode != GM_Inventory) )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
std::string handle = MWBase::Environment::get().getWorld()->getFacedHandle();
|
MWWorld::Ptr object = MWBase::Environment::get().getWorld()->getFacedObject();
|
||||||
MWWorld::Ptr object = MWBase::Environment::get().getWorld()->searchPtrViaHandle(handle);
|
|
||||||
|
|
||||||
if (mode == GM_Console)
|
if (mode == GM_Console)
|
||||||
MWBase::Environment::get().getWindowManager()->getConsole()->setSelectedObject(object);
|
MWBase::Environment::get().getWindowManager()->getConsole()->setSelectedObject(object);
|
||||||
|
|
|
@ -67,7 +67,7 @@ namespace MWGui
|
||||||
|
|
||||||
setCoord(0, 342, 498, 258);
|
setCoord(0, 342, 498, 258);
|
||||||
|
|
||||||
MWBase::Environment::get().getWorld ()->setupExternalRendering (mPreview);
|
mPreview.setup();
|
||||||
|
|
||||||
MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayer().getPlayer();
|
MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayer().getPlayer();
|
||||||
openContainer(player);
|
openContainer(player);
|
||||||
|
|
|
@ -106,7 +106,7 @@ void RaceDialog::open()
|
||||||
updateSpellPowers();
|
updateSpellPowers();
|
||||||
|
|
||||||
mPreview = new MWRender::RaceSelectionPreview();
|
mPreview = new MWRender::RaceSelectionPreview();
|
||||||
MWBase::Environment::get().getWorld ()->setupExternalRendering (*mPreview);
|
mPreview->setup();
|
||||||
mPreview->update (0);
|
mPreview->update (0);
|
||||||
|
|
||||||
const ESM::NPC proto = mPreview->getPrototype();
|
const ESM::NPC proto = mPreview->getPrototype();
|
||||||
|
|
|
@ -80,9 +80,8 @@ void ToolTips::onFrame(float frameDuration)
|
||||||
|| (mWindowManager->getMode() == GM_Container)
|
|| (mWindowManager->getMode() == GM_Container)
|
||||||
|| (mWindowManager->getMode() == GM_Inventory)))
|
|| (mWindowManager->getMode() == GM_Inventory)))
|
||||||
{
|
{
|
||||||
std::string handle = MWBase::Environment::get().getWorld()->getFacedHandle();
|
mFocusObject = MWBase::Environment::get().getWorld()->getFacedObject();
|
||||||
|
|
||||||
mFocusObject = MWBase::Environment::get().getWorld()->searchPtrViaHandle(handle);
|
|
||||||
if (mFocusObject.isEmpty ())
|
if (mFocusObject.isEmpty ())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
|
|
||||||
#include <OgreSceneManager.h>
|
#include <OgreSceneManager.h>
|
||||||
|
#include <OgreRoot.h>
|
||||||
#include <OgreHardwarePixelBuffer.h>
|
#include <OgreHardwarePixelBuffer.h>
|
||||||
|
|
||||||
#include <libs/openengine/ogre/selectionbuffer.hpp>
|
#include <libs/openengine/ogre/selectionbuffer.hpp>
|
||||||
|
@ -36,13 +37,18 @@ namespace MWRender
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CharacterPreview::setup (Ogre::SceneManager *sceneManager)
|
void CharacterPreview::setup ()
|
||||||
{
|
{
|
||||||
mSceneMgr = sceneManager;
|
mSceneMgr = Ogre::Root::getSingleton().createSceneManager(Ogre::ST_GENERIC);
|
||||||
mCamera = mSceneMgr->createCamera (mName);
|
mCamera = mSceneMgr->createCamera (mName);
|
||||||
mCamera->setAspectRatio (float(mSizeX) / float(mSizeY));
|
mCamera->setAspectRatio (float(mSizeX) / float(mSizeY));
|
||||||
|
|
||||||
mNode = static_cast<Ogre::SceneNode*>(mSceneMgr->getRootSceneNode()->getChild("mwRoot"))->createChildSceneNode ();
|
Ogre::SceneNode* renderRoot = mSceneMgr->getRootSceneNode()->createChildSceneNode("renderRoot");
|
||||||
|
|
||||||
|
//we do this with mwRoot in renderingManager, do it here too.
|
||||||
|
renderRoot->pitch(Ogre::Degree(-90));
|
||||||
|
|
||||||
|
mNode = renderRoot->createChildSceneNode();
|
||||||
|
|
||||||
mAnimation = new NpcAnimation(mCharacter, mNode,
|
mAnimation = new NpcAnimation(mCharacter, mNode,
|
||||||
MWWorld::Class::get(mCharacter).getInventoryStore (mCharacter), RV_PlayerPreview);
|
MWWorld::Class::get(mCharacter).getInventoryStore (mCharacter), RV_PlayerPreview);
|
||||||
|
@ -80,6 +86,7 @@ namespace MWRender
|
||||||
//Ogre::TextureManager::getSingleton().remove(mName);
|
//Ogre::TextureManager::getSingleton().remove(mName);
|
||||||
mSceneMgr->destroyCamera (mName);
|
mSceneMgr->destroyCamera (mName);
|
||||||
delete mAnimation;
|
delete mAnimation;
|
||||||
|
Ogre::Root::getSingleton().destroySceneManager(mSceneMgr);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CharacterPreview::rebuild()
|
void CharacterPreview::rebuild()
|
||||||
|
|
|
@ -23,14 +23,14 @@ namespace MWRender
|
||||||
|
|
||||||
class NpcAnimation;
|
class NpcAnimation;
|
||||||
|
|
||||||
class CharacterPreview : public ExternalRendering
|
class CharacterPreview
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
CharacterPreview(MWWorld::Ptr character, int sizeX, int sizeY, const std::string& name,
|
CharacterPreview(MWWorld::Ptr character, int sizeX, int sizeY, const std::string& name,
|
||||||
Ogre::Vector3 position, Ogre::Vector3 lookAt);
|
Ogre::Vector3 position, Ogre::Vector3 lookAt);
|
||||||
virtual ~CharacterPreview();
|
virtual ~CharacterPreview();
|
||||||
|
|
||||||
virtual void setup (Ogre::SceneManager *sceneManager);
|
virtual void setup ();
|
||||||
virtual void onSetup();
|
virtual void onSetup();
|
||||||
|
|
||||||
virtual void rebuild();
|
virtual void rebuild();
|
||||||
|
|
|
@ -64,7 +64,8 @@ void Audiere_Decoder::open(const std::string &fname)
|
||||||
close();
|
close();
|
||||||
|
|
||||||
mSoundFile = audiere::FilePtr(new OgreFile(mResourceMgr.openResource(fname)));
|
mSoundFile = audiere::FilePtr(new OgreFile(mResourceMgr.openResource(fname)));
|
||||||
mSoundSource = audiere::OpenSampleSource(file);
|
mSoundSource = audiere::OpenSampleSource(mSoundFile);
|
||||||
|
mSoundFileName = fname;
|
||||||
|
|
||||||
int channels, srate;
|
int channels, srate;
|
||||||
audiere::SampleFormat format;
|
audiere::SampleFormat format;
|
||||||
|
@ -95,7 +96,7 @@ void Audiere_Decoder::close()
|
||||||
|
|
||||||
std::string Audiere_Decoder::getName()
|
std::string Audiere_Decoder::getName()
|
||||||
{
|
{
|
||||||
return mSoundFile->getName();
|
return mSoundFileName;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Audiere_Decoder::getInfo(int *samplerate, ChannelConfig *chans, SampleType *type)
|
void Audiere_Decoder::getInfo(int *samplerate, ChannelConfig *chans, SampleType *type)
|
||||||
|
|
|
@ -12,6 +12,7 @@ namespace MWSound
|
||||||
{
|
{
|
||||||
class Audiere_Decoder : public Sound_Decoder
|
class Audiere_Decoder : public Sound_Decoder
|
||||||
{
|
{
|
||||||
|
std::string mSoundFileName;
|
||||||
audiere::FilePtr mSoundFile;
|
audiere::FilePtr mSoundFile;
|
||||||
audiere::SampleSourcePtr mSoundSource;
|
audiere::SampleSourcePtr mSoundSource;
|
||||||
int mSampleRate;
|
int mSampleRate;
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
#include "../mwbase/environment.hpp"
|
#include "../mwbase/environment.hpp"
|
||||||
#include "../mwbase/world.hpp"
|
#include "../mwbase/world.hpp"
|
||||||
|
#include "../mwbase/windowmanager.hpp"
|
||||||
|
|
||||||
#include "inventorystore.hpp"
|
#include "inventorystore.hpp"
|
||||||
#include "player.hpp"
|
#include "player.hpp"
|
||||||
|
@ -15,8 +16,7 @@ namespace MWWorld
|
||||||
|
|
||||||
void ActionEquip::executeImp (const Ptr& actor)
|
void ActionEquip::executeImp (const Ptr& actor)
|
||||||
{
|
{
|
||||||
MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayer().getPlayer();
|
MWWorld::InventoryStore& invStore = MWWorld::Class::get(actor).getInventoryStore(actor);
|
||||||
MWWorld::InventoryStore& invStore = MWWorld::Class::get(player).getInventoryStore(player);
|
|
||||||
|
|
||||||
// slots that this item can be equipped in
|
// slots that this item can be equipped in
|
||||||
std::pair<std::vector<int>, bool> slots = MWWorld::Class::get(getTarget()).getEquipmentSlots(getTarget());
|
std::pair<std::vector<int>, bool> slots = MWWorld::Class::get(getTarget()).getEquipmentSlots(getTarget());
|
||||||
|
@ -33,10 +33,60 @@ namespace MWWorld
|
||||||
|
|
||||||
assert(it != invStore.end());
|
assert(it != invStore.end());
|
||||||
|
|
||||||
|
std::string npcRace = actor.get<ESM::NPC>()->mBase->mRace;
|
||||||
|
|
||||||
// equip the item in the first free slot
|
// equip the item in the first free slot
|
||||||
for (std::vector<int>::const_iterator slot=slots.first.begin();
|
for (std::vector<int>::const_iterator slot=slots.first.begin();
|
||||||
slot!=slots.first.end(); ++slot)
|
slot!=slots.first.end(); ++slot)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
// Beast races cannot equip shoes / boots, or full helms (head part vs hair part)
|
||||||
|
if(npcRace == "argonian" || npcRace == "khajiit")
|
||||||
|
{
|
||||||
|
if(*slot == MWWorld::InventoryStore::Slot_Helmet){
|
||||||
|
std::vector<ESM::PartReference> parts;
|
||||||
|
|
||||||
|
if(it.getType() == MWWorld::ContainerStore::Type_Clothing)
|
||||||
|
parts = it->get<ESM::Clothing>()->mBase->mParts.mParts;
|
||||||
|
else
|
||||||
|
parts = it->get<ESM::Armor>()->mBase->mParts.mParts;
|
||||||
|
|
||||||
|
bool allow = true;
|
||||||
|
for(std::vector<ESM::PartReference>::iterator itr = parts.begin(); itr != parts.end(); ++itr)
|
||||||
|
{
|
||||||
|
if((*itr).mPart == ESM::PartReferenceType::PRT_Head)
|
||||||
|
{
|
||||||
|
if(actor == MWBase::Environment::get().getWorld()->getPlayer().getPlayer() )
|
||||||
|
MWBase::Environment::get().getWindowManager()->messageBox ("#{sNotifyMessage13}", std::vector<std::string>());
|
||||||
|
|
||||||
|
allow = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!allow)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (*slot == MWWorld::InventoryStore::Slot_Boots)
|
||||||
|
{
|
||||||
|
// Only notify the player, not npcs
|
||||||
|
if(actor == MWBase::Environment::get().getWorld()->getPlayer().getPlayer() )
|
||||||
|
{
|
||||||
|
if(it.getType() == MWWorld::ContainerStore::Type_Clothing){ // It's shoes
|
||||||
|
MWBase::Environment::get().getWindowManager()->messageBox ("#{sNotifyMessage15}", std::vector<std::string>());
|
||||||
|
}
|
||||||
|
|
||||||
|
else // It's boots
|
||||||
|
{
|
||||||
|
MWBase::Environment::get().getWindowManager()->messageBox ("#{sNotifyMessage14}", std::vector<std::string>());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
// if all slots are occupied, replace the last slot
|
// if all slots are occupied, replace the last slot
|
||||||
if (slot == --slots.first.end())
|
if (slot == --slots.first.end())
|
||||||
{
|
{
|
||||||
|
|
|
@ -43,7 +43,7 @@ namespace MWWorld
|
||||||
return mEngine;
|
return mEngine;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::pair<std::string, float> PhysicsSystem::getFacedHandle (MWWorld::World& world)
|
std::pair<float, std::string> PhysicsSystem::getFacedHandle (MWWorld::World& world, float queryDistance)
|
||||||
{
|
{
|
||||||
btVector3 dir(0, 1, 0);
|
btVector3 dir(0, 1, 0);
|
||||||
dir = dir.rotate(btVector3(1, 0, 0), mPlayerData.pitch);
|
dir = dir.rotate(btVector3(1, 0, 0), mPlayerData.pitch);
|
||||||
|
@ -56,11 +56,14 @@ namespace MWWorld
|
||||||
mPlayerData.eyepos.z);
|
mPlayerData.eyepos.z);
|
||||||
origin += dir * 5;
|
origin += dir * 5;
|
||||||
|
|
||||||
btVector3 dest = origin + dir * 500;
|
btVector3 dest = origin + dir * queryDistance;
|
||||||
return mEngine->rayTest(origin, dest);
|
std::pair <std::string, float> result;
|
||||||
|
/*auto*/ result = mEngine->rayTest(origin, dest);
|
||||||
|
result.second *= queryDistance;
|
||||||
|
return std::make_pair (result.second, result.first);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector < std::pair <float, std::string> > PhysicsSystem::getFacedObjects ()
|
std::vector < std::pair <float, std::string> > PhysicsSystem::getFacedHandles (float queryDistance)
|
||||||
{
|
{
|
||||||
btVector3 dir(0, 1, 0);
|
btVector3 dir(0, 1, 0);
|
||||||
dir = dir.rotate(btVector3(1, 0, 0), mPlayerData.pitch);
|
dir = dir.rotate(btVector3(1, 0, 0), mPlayerData.pitch);
|
||||||
|
@ -73,22 +76,32 @@ namespace MWWorld
|
||||||
mPlayerData.eyepos.z);
|
mPlayerData.eyepos.z);
|
||||||
origin += dir * 5;
|
origin += dir * 5;
|
||||||
|
|
||||||
btVector3 dest = origin + dir * 500;
|
btVector3 dest = origin + dir * queryDistance;
|
||||||
return mEngine->rayTest2(origin, dest);
|
std::vector < std::pair <float, std::string> > results;
|
||||||
|
/* auto */ results = mEngine->rayTest2(origin, dest);
|
||||||
|
std::vector < std::pair <float, std::string> >::iterator i;
|
||||||
|
for (/* auto */ i = results.begin (); i != results.end (); ++i)
|
||||||
|
i->first *= queryDistance;
|
||||||
|
return results;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector < std::pair <float, std::string> > PhysicsSystem::getFacedObjects (float mouseX, float mouseY)
|
std::vector < std::pair <float, std::string> > PhysicsSystem::getFacedHandles (float mouseX, float mouseY, float queryDistance)
|
||||||
{
|
{
|
||||||
Ray ray = mRender.getCamera()->getCameraToViewportRay(mouseX, mouseY);
|
Ray ray = mRender.getCamera()->getCameraToViewportRay(mouseX, mouseY);
|
||||||
Ogre::Vector3 from = ray.getOrigin();
|
Ogre::Vector3 from = ray.getOrigin();
|
||||||
Ogre::Vector3 to = ray.getPoint(500); /// \todo make this distance (ray length) configurable
|
Ogre::Vector3 to = ray.getPoint(queryDistance);
|
||||||
|
|
||||||
btVector3 _from, _to;
|
btVector3 _from, _to;
|
||||||
// OGRE to MW coordinates
|
// OGRE to MW coordinates
|
||||||
_from = btVector3(from.x, -from.z, from.y);
|
_from = btVector3(from.x, -from.z, from.y);
|
||||||
_to = btVector3(to.x, -to.z, to.y);
|
_to = btVector3(to.x, -to.z, to.y);
|
||||||
|
|
||||||
return mEngine->rayTest2(_from,_to);
|
std::vector < std::pair <float, std::string> > results;
|
||||||
|
/* auto */ results = mEngine->rayTest2(_from,_to);
|
||||||
|
std::vector < std::pair <float, std::string> >::iterator i;
|
||||||
|
for (/* auto */ i = results.begin (); i != results.end (); ++i)
|
||||||
|
i->first *= queryDistance;
|
||||||
|
return results;
|
||||||
}
|
}
|
||||||
|
|
||||||
void PhysicsSystem::setCurrentWater(bool hasWater, int waterHeight)
|
void PhysicsSystem::setCurrentWater(bool hasWater, int waterHeight)
|
||||||
|
@ -110,7 +123,7 @@ namespace MWWorld
|
||||||
Ray centerRay = mRender.getCamera()->getCameraToViewportRay(
|
Ray centerRay = mRender.getCamera()->getCameraToViewportRay(
|
||||||
mRender.getViewport()->getWidth()/2,
|
mRender.getViewport()->getWidth()/2,
|
||||||
mRender.getViewport()->getHeight()/2);
|
mRender.getViewport()->getHeight()/2);
|
||||||
btVector3 result(centerRay.getPoint(500*extent).x,-centerRay.getPoint(500*extent).z,centerRay.getPoint(500*extent).y); /// \todo make this distance (ray length) configurable
|
btVector3 result(centerRay.getPoint(extent).x,-centerRay.getPoint(extent).z,centerRay.getPoint(extent).y);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -118,7 +131,7 @@ namespace MWWorld
|
||||||
{
|
{
|
||||||
//get a ray pointing to the center of the viewport
|
//get a ray pointing to the center of the viewport
|
||||||
Ray centerRay = mRender.getCamera()->getCameraToViewportRay(mouseX, mouseY);
|
Ray centerRay = mRender.getCamera()->getCameraToViewportRay(mouseX, mouseY);
|
||||||
btVector3 result(centerRay.getPoint(500*extent).x,-centerRay.getPoint(500*extent).z,centerRay.getPoint(500*extent).y); /// \todo make this distance (ray length) configurable
|
btVector3 result(centerRay.getPoint(extent).x,-centerRay.getPoint(extent).z,centerRay.getPoint(extent).y);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -41,14 +41,13 @@ namespace MWWorld
|
||||||
|
|
||||||
bool toggleCollisionMode();
|
bool toggleCollisionMode();
|
||||||
|
|
||||||
std::pair<std::string, float> getFacedHandle (MWWorld::World& world);
|
std::pair<float, std::string> getFacedHandle (MWWorld::World& world, float queryDistance);
|
||||||
|
std::vector < std::pair <float, std::string> > getFacedHandles (float queryDistance);
|
||||||
|
std::vector < std::pair <float, std::string> > getFacedHandles (float mouseX, float mouseY, float queryDistance);
|
||||||
|
|
||||||
btVector3 getRayPoint(float extent);
|
btVector3 getRayPoint(float extent);
|
||||||
btVector3 getRayPoint(float extent, float mouseX, float mouseY);
|
btVector3 getRayPoint(float extent, float mouseX, float mouseY);
|
||||||
|
|
||||||
std::vector < std::pair <float, std::string> > getFacedObjects ();
|
|
||||||
|
|
||||||
std::vector < std::pair <float, std::string> > getFacedObjects (float mouseX, float mouseY);
|
|
||||||
|
|
||||||
// cast ray, return true if it hit something
|
// cast ray, return true if it hit something
|
||||||
bool castRay(const Ogre::Vector3& from, const Ogre::Vector3& to);
|
bool castRay(const Ogre::Vector3& from, const Ogre::Vector3& to);
|
||||||
|
|
|
@ -170,10 +170,10 @@ namespace MWWorld
|
||||||
World::World (OEngine::Render::OgreRenderer& renderer,
|
World::World (OEngine::Render::OgreRenderer& renderer,
|
||||||
const Files::Collections& fileCollections,
|
const Files::Collections& fileCollections,
|
||||||
const std::string& master, const boost::filesystem::path& resDir, const boost::filesystem::path& cacheDir, bool newGame,
|
const std::string& master, const boost::filesystem::path& resDir, const boost::filesystem::path& cacheDir, bool newGame,
|
||||||
ToUTF8::Utf8Encoder* encoder, std::map<std::string,std::string> fallbackMap)
|
ToUTF8::Utf8Encoder* encoder, std::map<std::string,std::string> fallbackMap, int mActivationDistanceOverride)
|
||||||
: mPlayer (0), mLocalScripts (mStore), mGlobalVariables (0),
|
: mPlayer (0), mLocalScripts (mStore), mGlobalVariables (0),
|
||||||
mSky (true), mCells (mStore, mEsm),
|
mSky (true), mCells (mStore, mEsm),
|
||||||
mNumFacing(0)
|
mNumFacing(0), mActivationDistanceOverride (mActivationDistanceOverride)
|
||||||
{
|
{
|
||||||
mPhysics = new PhysicsSystem(renderer);
|
mPhysics = new PhysicsSystem(renderer);
|
||||||
mPhysEngine = mPhysics->getEngine();
|
mPhysEngine = mPhysics->getEngine();
|
||||||
|
@ -573,23 +573,55 @@ namespace MWWorld
|
||||||
return mWorldScene->markCellAsUnchanged();
|
return mWorldScene->markCellAsUnchanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string World::getFacedHandle()
|
float World::getMaxActivationDistance ()
|
||||||
{
|
{
|
||||||
|
if (mActivationDistanceOverride >= 0)
|
||||||
|
return mActivationDistanceOverride;
|
||||||
|
|
||||||
|
return (std::max) (getNpcActivationDistance (), getObjectActivationDistance ());
|
||||||
|
}
|
||||||
|
|
||||||
|
float World::getNpcActivationDistance ()
|
||||||
|
{
|
||||||
|
if (mActivationDistanceOverride >= 0)
|
||||||
|
return mActivationDistanceOverride;
|
||||||
|
|
||||||
|
return getStore().get<ESM::GameSetting>().find ("iMaxActivateDist")->getInt()*5/4;
|
||||||
|
}
|
||||||
|
|
||||||
|
float World::getObjectActivationDistance ()
|
||||||
|
{
|
||||||
|
if (mActivationDistanceOverride >= 0)
|
||||||
|
return mActivationDistanceOverride;
|
||||||
|
|
||||||
|
return getStore().get<ESM::GameSetting>().find ("iMaxActivateDist")->getInt();
|
||||||
|
}
|
||||||
|
|
||||||
|
MWWorld::Ptr World::getFacedObject()
|
||||||
|
{
|
||||||
|
std::pair<float, std::string> result;
|
||||||
|
|
||||||
if (!mRendering->occlusionQuerySupported())
|
if (!mRendering->occlusionQuerySupported())
|
||||||
{
|
result = mPhysics->getFacedHandle (*this, getMaxActivationDistance ());
|
||||||
std::pair<std::string, float> result = mPhysics->getFacedHandle (*this);
|
|
||||||
|
|
||||||
if (result.first.empty() ||
|
|
||||||
result.second>getStore().get<ESM::GameSetting>().find ("iMaxActivateDist")->getInt())
|
|
||||||
return "";
|
|
||||||
|
|
||||||
return result.first;
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
result = std::make_pair (mFacedDistance, mFacedHandle);
|
||||||
// updated every few frames in update()
|
|
||||||
return mFacedHandle;
|
if (result.second.empty())
|
||||||
}
|
return MWWorld::Ptr ();
|
||||||
|
|
||||||
|
MWWorld::Ptr object = searchPtrViaHandle (result.second);
|
||||||
|
|
||||||
|
float ActivationDistance;
|
||||||
|
|
||||||
|
if (object.getTypeName ().find("NPC") != std::string::npos)
|
||||||
|
ActivationDistance = getNpcActivationDistance ();
|
||||||
|
else
|
||||||
|
ActivationDistance = getObjectActivationDistance ();
|
||||||
|
|
||||||
|
if (result.first > ActivationDistance)
|
||||||
|
return MWWorld::Ptr ();
|
||||||
|
|
||||||
|
return object;
|
||||||
}
|
}
|
||||||
|
|
||||||
void World::deleteObject (const Ptr& ptr)
|
void World::deleteObject (const Ptr& ptr)
|
||||||
|
@ -884,8 +916,6 @@ namespace MWWorld
|
||||||
|
|
||||||
void World::update (float duration, bool paused)
|
void World::update (float duration, bool paused)
|
||||||
{
|
{
|
||||||
/// \todo split this function up into subfunctions
|
|
||||||
|
|
||||||
mWorldScene->update (duration, paused);
|
mWorldScene->update (duration, paused);
|
||||||
|
|
||||||
float pitch, yaw;
|
float pitch, yaw;
|
||||||
|
@ -895,8 +925,15 @@ namespace MWWorld
|
||||||
|
|
||||||
mWeatherManager->update (duration);
|
mWeatherManager->update (duration);
|
||||||
|
|
||||||
|
performUpdateSceneQueries ();
|
||||||
|
|
||||||
|
updateWindowManager ();
|
||||||
|
}
|
||||||
|
|
||||||
|
void World::updateWindowManager ()
|
||||||
|
{
|
||||||
// inform the GUI about focused object
|
// inform the GUI about focused object
|
||||||
MWWorld::Ptr object = searchPtrViaHandle(mFacedHandle);
|
MWWorld::Ptr object = getFacedObject ();
|
||||||
|
|
||||||
MWBase::Environment::get().getWindowManager()->setFocusObject(object);
|
MWBase::Environment::get().getWindowManager()->setFocusObject(object);
|
||||||
|
|
||||||
|
@ -918,7 +955,10 @@ namespace MWWorld
|
||||||
screenCoords[0], screenCoords[1], screenCoords[2], screenCoords[3]);
|
screenCoords[0], screenCoords[1], screenCoords[2], screenCoords[3]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void World::performUpdateSceneQueries ()
|
||||||
|
{
|
||||||
if (!mRendering->occlusionQuerySupported())
|
if (!mRendering->occlusionQuerySupported())
|
||||||
{
|
{
|
||||||
// cast a ray from player to sun to detect if the sun is visible
|
// cast a ray from player to sun to detect if the sun is visible
|
||||||
|
@ -936,20 +976,37 @@ namespace MWWorld
|
||||||
{
|
{
|
||||||
MWRender::OcclusionQuery* query = mRendering->getOcclusionQuery();
|
MWRender::OcclusionQuery* query = mRendering->getOcclusionQuery();
|
||||||
if (!query->occlusionTestPending())
|
if (!query->occlusionTestPending())
|
||||||
|
{
|
||||||
|
processFacedQueryResults (query);
|
||||||
|
beginFacedQueryProcess (query);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void World::processFacedQueryResults (MWRender::OcclusionQuery* query)
|
||||||
{
|
{
|
||||||
// get result of last query
|
// get result of last query
|
||||||
if (mNumFacing == 0) mFacedHandle = "";
|
if (mNumFacing == 0)
|
||||||
|
{
|
||||||
|
mFacedHandle = "";
|
||||||
|
mFacedDistance = FLT_MAX;
|
||||||
|
}
|
||||||
else if (mNumFacing == 1)
|
else if (mNumFacing == 1)
|
||||||
{
|
{
|
||||||
bool result = query->getTestResult();
|
bool result = query->getTestResult();
|
||||||
mFacedHandle = result ? mFaced1Name : "";
|
mFacedHandle = result ? mFaced1Name : "";
|
||||||
|
mFacedDistance = result ? mFaced1Distance : FLT_MAX;
|
||||||
}
|
}
|
||||||
else if (mNumFacing == 2)
|
else if (mNumFacing == 2)
|
||||||
{
|
{
|
||||||
bool result = query->getTestResult();
|
bool result = query->getTestResult();
|
||||||
mFacedHandle = result ? mFaced2Name : mFaced1Name;
|
mFacedHandle = result ? mFaced2Name : mFaced1Name;
|
||||||
|
mFacedDistance = result ? mFaced1Distance : mFaced1Distance;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void World::beginFacedQueryProcess (MWRender::OcclusionQuery* query)
|
||||||
|
{
|
||||||
// send new query
|
// send new query
|
||||||
// figure out which object we want to test against
|
// figure out which object we want to test against
|
||||||
std::vector < std::pair < float, std::string > > results;
|
std::vector < std::pair < float, std::string > > results;
|
||||||
|
@ -957,10 +1014,12 @@ namespace MWWorld
|
||||||
{
|
{
|
||||||
float x, y;
|
float x, y;
|
||||||
MWBase::Environment::get().getWindowManager()->getMousePosition(x, y);
|
MWBase::Environment::get().getWindowManager()->getMousePosition(x, y);
|
||||||
results = mPhysics->getFacedObjects(x, y);
|
results = mPhysics->getFacedHandles(x, y, getMaxActivationDistance ());
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
results = mPhysics->getFacedObjects();
|
{
|
||||||
|
results = mPhysics->getFacedHandles(getMaxActivationDistance ());
|
||||||
|
}
|
||||||
|
|
||||||
// ignore the player and other things we're not interested in
|
// ignore the player and other things we're not interested in
|
||||||
std::vector < std::pair < float, std::string > >::iterator it = results.begin();
|
std::vector < std::pair < float, std::string > >::iterator it = results.begin();
|
||||||
|
@ -980,9 +1039,20 @@ namespace MWWorld
|
||||||
mNumFacing = 0;
|
mNumFacing = 0;
|
||||||
}
|
}
|
||||||
else if (results.size() == 1)
|
else if (results.size() == 1)
|
||||||
|
{
|
||||||
|
beginSingleFacedQueryProcess (query, results);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
beginDoubleFacedQueryProcess (query, results);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void World::beginSingleFacedQueryProcess (MWRender::OcclusionQuery* query, std::vector < std::pair < float, std::string > > const & results)
|
||||||
{
|
{
|
||||||
mFaced1 = getPtrViaHandle(results.front().second);
|
mFaced1 = getPtrViaHandle(results.front().second);
|
||||||
mFaced1Name = results.front().second;
|
mFaced1Name = results.front().second;
|
||||||
|
mFaced1Distance = results.front().first;
|
||||||
mNumFacing = 1;
|
mNumFacing = 1;
|
||||||
|
|
||||||
btVector3 p;
|
btVector3 p;
|
||||||
|
@ -1002,12 +1072,15 @@ namespace MWWorld
|
||||||
|
|
||||||
query->occlusionTest(pos, node);
|
query->occlusionTest(pos, node);
|
||||||
}
|
}
|
||||||
else
|
|
||||||
|
void World::beginDoubleFacedQueryProcess (MWRender::OcclusionQuery* query, std::vector < std::pair < float, std::string > > const & results)
|
||||||
{
|
{
|
||||||
mFaced1Name = results.front().second;
|
mFaced1Name = results.at (0).second;
|
||||||
mFaced2Name = results[1].second;
|
mFaced2Name = results.at (1).second;
|
||||||
mFaced1 = getPtrViaHandle(results.front().second);
|
mFaced1Distance = results.at (0).first;
|
||||||
mFaced2 = getPtrViaHandle(results[1].second);
|
mFaced2Distance = results.at (1).first;
|
||||||
|
mFaced1 = getPtrViaHandle(results.at (0).second);
|
||||||
|
mFaced2 = getPtrViaHandle(results.at (1).second);
|
||||||
mNumFacing = 2;
|
mNumFacing = 2;
|
||||||
|
|
||||||
btVector3 p;
|
btVector3 p;
|
||||||
|
@ -1015,10 +1088,10 @@ namespace MWWorld
|
||||||
{
|
{
|
||||||
float x, y;
|
float x, y;
|
||||||
MWBase::Environment::get().getWindowManager()->getMousePosition(x, y);
|
MWBase::Environment::get().getWindowManager()->getMousePosition(x, y);
|
||||||
p = mPhysics->getRayPoint(results[1].first, x, y);
|
p = mPhysics->getRayPoint(results.at (1).first, x, y);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
p = mPhysics->getRayPoint(results[1].first);
|
p = mPhysics->getRayPoint(results.at (1).first);
|
||||||
Ogre::Vector3 pos(p.x(), p.z(), -p.y());
|
Ogre::Vector3 pos(p.x(), p.z(), -p.y());
|
||||||
Ogre::SceneNode* node1 = mFaced1.getRefData().getBaseNode();
|
Ogre::SceneNode* node1 = mFaced1.getRefData().getBaseNode();
|
||||||
Ogre::SceneNode* node2 = mFaced2.getRefData().getBaseNode();
|
Ogre::SceneNode* node2 = mFaced2.getRefData().getBaseNode();
|
||||||
|
@ -1027,6 +1100,7 @@ namespace MWWorld
|
||||||
if (!query->isPotentialOccluder(node1) && (mFaced1.getTypeName().find("Static") == std::string::npos))
|
if (!query->isPotentialOccluder(node1) && (mFaced1.getTypeName().find("Static") == std::string::npos))
|
||||||
{
|
{
|
||||||
mFacedHandle = mFaced1Name;
|
mFacedHandle = mFaced1Name;
|
||||||
|
mFacedDistance = mFaced1Distance;
|
||||||
//std::cout << "node1 Not an occluder" << std::endl;
|
//std::cout << "node1 Not an occluder" << std::endl;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -1035,6 +1109,7 @@ namespace MWWorld
|
||||||
if (mFaced2.getTypeName().find("Static") != std::string::npos)
|
if (mFaced2.getTypeName().find("Static") != std::string::npos)
|
||||||
{
|
{
|
||||||
mFacedHandle = mFaced1Name;
|
mFacedHandle = mFaced1Name;
|
||||||
|
mFacedDistance = mFaced1Distance;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1043,14 +1118,12 @@ namespace MWWorld
|
||||||
&& mFaced2.getTypeName().find("Door") != std::string::npos)
|
&& mFaced2.getTypeName().find("Door") != std::string::npos)
|
||||||
{
|
{
|
||||||
mFacedHandle = mFaced2Name;
|
mFacedHandle = mFaced2Name;
|
||||||
|
mFacedDistance = mFaced2Distance;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
query->occlusionTest(pos, node2);
|
query->occlusionTest(pos, node2);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool World::isCellExterior() const
|
bool World::isCellExterior() const
|
||||||
{
|
{
|
||||||
|
|
|
@ -71,11 +71,15 @@ namespace MWWorld
|
||||||
|
|
||||||
Ptr getPtrViaHandle (const std::string& handle, Ptr::CellStore& cellStore);
|
Ptr getPtrViaHandle (const std::string& handle, Ptr::CellStore& cellStore);
|
||||||
|
|
||||||
|
int mActivationDistanceOverride;
|
||||||
std::string mFacedHandle;
|
std::string mFacedHandle;
|
||||||
|
float mFacedDistance;
|
||||||
Ptr mFaced1;
|
Ptr mFaced1;
|
||||||
Ptr mFaced2;
|
Ptr mFaced2;
|
||||||
std::string mFaced1Name;
|
std::string mFaced1Name;
|
||||||
std::string mFaced2Name;
|
std::string mFaced2Name;
|
||||||
|
float mFaced1Distance;
|
||||||
|
float mFaced2Distance;
|
||||||
int mNumFacing;
|
int mNumFacing;
|
||||||
std::map<std::string,std::string> mFallback;
|
std::map<std::string,std::string> mFallback;
|
||||||
|
|
||||||
|
@ -90,12 +94,23 @@ namespace MWWorld
|
||||||
virtual void
|
virtual void
|
||||||
copyObjectToCell(const Ptr &ptr, CellStore &cell, const ESM::Position &pos);
|
copyObjectToCell(const Ptr &ptr, CellStore &cell, const ESM::Position &pos);
|
||||||
|
|
||||||
|
void updateWindowManager ();
|
||||||
|
void performUpdateSceneQueries ();
|
||||||
|
void processFacedQueryResults (MWRender::OcclusionQuery* query);
|
||||||
|
void beginFacedQueryProcess (MWRender::OcclusionQuery* query);
|
||||||
|
void beginSingleFacedQueryProcess (MWRender::OcclusionQuery* query, std::vector < std::pair < float, std::string > > const & results);
|
||||||
|
void beginDoubleFacedQueryProcess (MWRender::OcclusionQuery* query, std::vector < std::pair < float, std::string > > const & results);
|
||||||
|
|
||||||
|
float getMaxActivationDistance ();
|
||||||
|
float getNpcActivationDistance ();
|
||||||
|
float getObjectActivationDistance ();
|
||||||
|
|
||||||
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, const boost::filesystem::path& cacheDir, bool newGame,
|
const std::string& master, const boost::filesystem::path& resDir, const boost::filesystem::path& cacheDir, bool newGame,
|
||||||
ToUTF8::Utf8Encoder* encoder, std::map<std::string,std::string> fallbackMap);
|
ToUTF8::Utf8Encoder* encoder, std::map<std::string,std::string> fallbackMap, int mActivationDistanceOverride);
|
||||||
|
|
||||||
virtual ~World();
|
virtual ~World();
|
||||||
|
|
||||||
|
@ -217,8 +232,8 @@ namespace MWWorld
|
||||||
|
|
||||||
virtual void markCellAsUnchanged();
|
virtual void markCellAsUnchanged();
|
||||||
|
|
||||||
virtual std::string getFacedHandle();
|
virtual MWWorld::Ptr getFacedObject();
|
||||||
///< Return handle of the object the player is looking at
|
///< Return pointer to the object the player is looking at, if it is within activation range
|
||||||
|
|
||||||
virtual void deleteObject (const Ptr& ptr);
|
virtual void deleteObject (const Ptr& ptr);
|
||||||
|
|
||||||
|
|
|
@ -29,6 +29,8 @@
|
||||||
#include <OgreArchiveManager.h>
|
#include <OgreArchiveManager.h>
|
||||||
#include "bsa_file.hpp"
|
#include "bsa_file.hpp"
|
||||||
|
|
||||||
|
#include "../files/constrainedfiledatastream.hpp"
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
|
|
||||||
|
@ -60,104 +62,64 @@ public:
|
||||||
static bool fsstrict = false;
|
static bool fsstrict = false;
|
||||||
|
|
||||||
/// An OGRE Archive wrapping a BSAFile archive
|
/// An OGRE Archive wrapping a BSAFile archive
|
||||||
class DirArchive: public Ogre::FileSystemArchive
|
class DirArchive: public Ogre::Archive
|
||||||
{
|
{
|
||||||
boost::filesystem::path currentdir;
|
typedef std::map <std::string, std::string> index;
|
||||||
std::map<std::string, std::vector<std::string>, ciLessBoost> m;
|
|
||||||
unsigned int cutoff;
|
|
||||||
|
|
||||||
bool findFile(const String& filename, std::string& copy) const
|
index mIndex;
|
||||||
|
|
||||||
|
static char strict_normalize_char(char ch)
|
||||||
{
|
{
|
||||||
copy = filename;
|
return ch == '\\' ? '/' : ch;
|
||||||
std::replace(copy.begin(), copy.end(), '\\', '/');
|
|
||||||
|
|
||||||
if(copy.at(0) == '/')
|
|
||||||
copy.erase(0, 1);
|
|
||||||
|
|
||||||
if(fsstrict == true)
|
|
||||||
return true;
|
|
||||||
|
|
||||||
std::string folder;
|
|
||||||
//int delimiter = 0;
|
|
||||||
size_t lastSlash = copy.rfind('/');
|
|
||||||
if (lastSlash != std::string::npos)
|
|
||||||
{
|
|
||||||
folder = copy.substr(0, lastSlash);
|
|
||||||
//delimiter = lastSlash+1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<std::string> current;
|
static char nonstrict_normalize_char(char ch)
|
||||||
{
|
{
|
||||||
std::map<std::string,std::vector<std::string>,ciLessBoost>::const_iterator found = m.find(folder);
|
return ch == '\\' ? '/' : std::tolower (ch);
|
||||||
|
}
|
||||||
|
|
||||||
if (found == m.end())
|
static std::string normalize_path (std::string::const_iterator begin, std::string::const_iterator end)
|
||||||
{
|
{
|
||||||
return false;
|
std::string normalized;
|
||||||
}
|
normalized.reserve (end-begin);
|
||||||
else
|
char (*normalize_char) (char) = fsstrict ? &strict_normalize_char : &nonstrict_normalize_char;
|
||||||
current = found->second;
|
std::transform (begin, end, std::back_inserter (normalized), normalize_char);
|
||||||
|
return normalized;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<std::string>::iterator find = std::lower_bound(current.begin(), current.end(), copy, ciLessBoost());
|
index::const_iterator lookup_filename (std::string const & filename) const
|
||||||
if (find != current.end() && !ciLessBoost()(copy, current.front()))
|
|
||||||
{
|
{
|
||||||
if (!boost::iequals(copy, *find))
|
std::string normalized = normalize_path (filename.begin (), filename.end ());
|
||||||
if ((find = std::find_if(current.begin(), current.end(), pathComparer(copy))) == current.end()) //\todo Check if this line is actually needed
|
|
||||||
return false;
|
|
||||||
|
|
||||||
copy = *find;
|
return mIndex.find (normalized);
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
public:
|
||||||
}
|
|
||||||
|
|
||||||
public:
|
|
||||||
|
|
||||||
DirArchive(const String& name)
|
DirArchive(const String& name)
|
||||||
: FileSystemArchive(name, "Dir"), currentdir (name)
|
: Archive(name, "Dir")
|
||||||
{
|
{
|
||||||
mType = "Dir";
|
typedef boost::filesystem::recursive_directory_iterator directory_iterator;
|
||||||
std::string s = name;
|
|
||||||
cutoff = s.size() + 1;
|
|
||||||
if(fsstrict == false)
|
|
||||||
populateMap(currentdir);
|
|
||||||
|
|
||||||
}
|
directory_iterator end;
|
||||||
void populateMap(boost::filesystem::path d){
|
|
||||||
//need to cut off first
|
size_t prefix = name.size ();
|
||||||
boost::filesystem::directory_iterator dir_iter(d), dir_end;
|
|
||||||
std::vector<std::string> filesind;
|
if (name.size () > 0 && name [prefix - 1] != '\\' && name [prefix - 1] != '/')
|
||||||
for(;dir_iter != dir_end; dir_iter++)
|
++prefix;
|
||||||
|
|
||||||
|
for (directory_iterator i (name); i != end; ++i)
|
||||||
{
|
{
|
||||||
if(boost::filesystem::is_directory(*dir_iter))
|
if(boost::filesystem::is_directory (*i))
|
||||||
populateMap(*dir_iter);
|
continue;
|
||||||
else
|
|
||||||
{
|
|
||||||
std::string s = dir_iter->path().string();
|
|
||||||
std::replace(s.begin(), s.end(), '\\', '/');
|
|
||||||
|
|
||||||
std::string small;
|
std::string proper = i->path ().string ();
|
||||||
if(cutoff < s.size())
|
|
||||||
small = s.substr(cutoff, s.size() - cutoff);
|
|
||||||
else
|
|
||||||
small = s.substr(cutoff - 1, s.size() - cutoff);
|
|
||||||
|
|
||||||
filesind.push_back(small);
|
std::string searchable = normalize_path (proper.begin () + prefix, proper.end ());
|
||||||
|
|
||||||
|
mIndex.insert (std::make_pair (std::move (searchable), std::move (proper)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
std::sort(filesind.begin(), filesind.end(), ciLessBoost());
|
|
||||||
|
|
||||||
std::string small;
|
|
||||||
std::string original = d.string();
|
|
||||||
std::replace(original.begin(), original.end(), '\\', '/');
|
|
||||||
if(cutoff < original.size())
|
|
||||||
small = original.substr(cutoff, original.size() - cutoff);
|
|
||||||
else
|
|
||||||
small = original.substr(cutoff - 1, original.size() - cutoff);
|
|
||||||
|
|
||||||
m[small] = filesind;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool isCaseSensitive() const { return fsstrict; }
|
bool isCaseSensitive() const { return fsstrict; }
|
||||||
|
|
||||||
|
@ -165,26 +127,76 @@ class DirArchive: public Ogre::FileSystemArchive
|
||||||
void load() {}
|
void load() {}
|
||||||
void unload() {}
|
void unload() {}
|
||||||
|
|
||||||
bool exists(const String& filename) {
|
|
||||||
std::string copy;
|
|
||||||
|
|
||||||
if (findFile(filename, copy))
|
|
||||||
return FileSystemArchive::exists(copy);
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
DataStreamPtr open(const String& filename, bool readonly = true) const
|
DataStreamPtr open(const String& filename, bool readonly = true) const
|
||||||
{
|
{
|
||||||
std::string copy;
|
index::const_iterator i = lookup_filename (filename);
|
||||||
|
|
||||||
if (findFile(filename, copy))
|
if (i == mIndex.end ())
|
||||||
return FileSystemArchive::open(copy, readonly);
|
{
|
||||||
|
std::ostringstream os;
|
||||||
DataStreamPtr p;
|
os << "The file '" << filename << "' could not be found.";
|
||||||
return p;
|
throw std::runtime_error (os.str ());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return openConstrainedFileDataStream (i->second.c_str ());
|
||||||
|
}
|
||||||
|
|
||||||
|
StringVectorPtr list(bool recursive = true, bool dirs = false)
|
||||||
|
{
|
||||||
|
StringVectorPtr ptr = StringVectorPtr(new StringVector());
|
||||||
|
std::cout << "DirArchive<" << getName () << ">::list" << std::endl;
|
||||||
|
return ptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
FileInfoListPtr listFileInfo(bool recursive = true, bool dirs = false)
|
||||||
|
{
|
||||||
|
FileInfoListPtr ptr = FileInfoListPtr(new FileInfoList());
|
||||||
|
std::cout << "DirArchive<" << getName () << ">::listFileInfo" << std::endl;
|
||||||
|
return ptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
StringVectorPtr find(const String& pattern, bool recursive = true,
|
||||||
|
bool dirs = false)
|
||||||
|
{
|
||||||
|
StringVectorPtr ptr = StringVectorPtr(new StringVector());
|
||||||
|
|
||||||
|
if (pattern == "*")
|
||||||
|
for (index::const_iterator i = mIndex.begin (); i != mIndex.end (); ++i)
|
||||||
|
ptr->push_back (i->first);
|
||||||
|
|
||||||
|
return ptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool exists(const String& filename)
|
||||||
|
{
|
||||||
|
return lookup_filename (filename) != mIndex.end ();
|
||||||
|
}
|
||||||
|
|
||||||
|
time_t getModifiedTime(const String&) { return 0; }
|
||||||
|
|
||||||
|
FileInfoListPtr findFileInfo(const String& pattern, bool recursive = true,
|
||||||
|
bool dirs = false) const
|
||||||
|
{
|
||||||
|
FileInfoListPtr ptr = FileInfoListPtr(new FileInfoList());
|
||||||
|
|
||||||
|
index::const_iterator i = lookup_filename (pattern);
|
||||||
|
|
||||||
|
if (i != mIndex.end ())
|
||||||
|
{
|
||||||
|
FileInfo fi;
|
||||||
|
|
||||||
|
std::size_t npos = i->first.rfind ('/');
|
||||||
|
|
||||||
|
fi.archive = this;
|
||||||
|
fi.filename = npos != std::string::npos ? i->first.substr (npos) : i->first;
|
||||||
|
fi.path = npos != std::string::npos ? i->first.substr (0, npos) : "";
|
||||||
|
fi.compressedSize = fi.uncompressedSize = 0;
|
||||||
|
|
||||||
|
ptr->push_back(fi);
|
||||||
|
}
|
||||||
|
|
||||||
|
return ptr;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
class BSAArchive : public Archive
|
class BSAArchive : public Archive
|
||||||
|
@ -249,6 +261,13 @@ public:
|
||||||
//std::cout << "find(" << pattern << ", " << recursive
|
//std::cout << "find(" << pattern << ", " << recursive
|
||||||
// << ", " << dirs << ")\n";
|
// << ", " << dirs << ")\n";
|
||||||
StringVectorPtr ptr = StringVectorPtr(new StringVector());
|
StringVectorPtr ptr = StringVectorPtr(new StringVector());
|
||||||
|
|
||||||
|
BSAFile::FileList const & files = arc.getList ();
|
||||||
|
|
||||||
|
if (pattern == "*")
|
||||||
|
for (BSAFile::FileList::const_iterator i = files.begin (); i != files.end (); ++i)
|
||||||
|
ptr->push_back (i->name);
|
||||||
|
|
||||||
return ptr;
|
return ptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
3
extern/shiny/CMakeLists.txt
vendored
3
extern/shiny/CMakeLists.txt
vendored
|
@ -70,3 +70,6 @@ endif()
|
||||||
|
|
||||||
|
|
||||||
link_directories(${CMAKE_CURRENT_BINARY_DIR})
|
link_directories(${CMAKE_CURRENT_BINARY_DIR})
|
||||||
|
|
||||||
|
set(SHINY_LIBRARY ${SHINY_LIBRARY} PARENT_SCOPE)
|
||||||
|
set(SHINY_OGREPLATFORM_LIBRARY ${SHINY_OGREPLATFORM_LIBRARY} PARENT_SCOPE)
|
||||||
|
|
2
extern/shiny/Main/Factory.cpp
vendored
2
extern/shiny/Main/Factory.cpp
vendored
|
@ -224,7 +224,7 @@ namespace sh
|
||||||
if (!mShadersEnabled)
|
if (!mShadersEnabled)
|
||||||
newInstance.setShadersEnabled (false);
|
newInstance.setShadersEnabled (false);
|
||||||
|
|
||||||
newInstance.setSourceFile (it->second->m_fileName);
|
newInstance.setSourceFile (it->second->mFileName);
|
||||||
|
|
||||||
std::vector<ScriptNode*> props = it->second->getChildren();
|
std::vector<ScriptNode*> props = it->second->getChildren();
|
||||||
for (std::vector<ScriptNode*>::const_iterator propIt = props.begin(); propIt != props.end(); ++propIt)
|
for (std::vector<ScriptNode*>::const_iterator propIt = props.begin(); propIt != props.end(); ++propIt)
|
||||||
|
|
8
extern/shiny/Main/MaterialInstance.cpp
vendored
8
extern/shiny/Main/MaterialInstance.cpp
vendored
|
@ -72,6 +72,8 @@ namespace sh
|
||||||
allowFixedFunction = retrieveValue<BooleanValue>(getProperty("allow_fixed_function"), NULL).get();
|
allowFixedFunction = retrieveValue<BooleanValue>(getProperty("allow_fixed_function"), NULL).get();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool useShaders = mShadersEnabled || !allowFixedFunction;
|
||||||
|
|
||||||
// get passes of the top-most parent
|
// get passes of the top-most parent
|
||||||
PassVector passes = getPasses();
|
PassVector passes = getPasses();
|
||||||
if (passes.size() == 0)
|
if (passes.size() == 0)
|
||||||
|
@ -91,7 +93,7 @@ namespace sh
|
||||||
// create or retrieve shaders
|
// create or retrieve shaders
|
||||||
bool hasVertex = it->hasProperty("vertex_program");
|
bool hasVertex = it->hasProperty("vertex_program");
|
||||||
bool hasFragment = it->hasProperty("fragment_program");
|
bool hasFragment = it->hasProperty("fragment_program");
|
||||||
if (mShadersEnabled || !allowFixedFunction)
|
if (useShaders)
|
||||||
{
|
{
|
||||||
it->setContext(context);
|
it->setContext(context);
|
||||||
it->mShaderProperties.setContext(context);
|
it->mShaderProperties.setContext(context);
|
||||||
|
@ -144,7 +146,7 @@ namespace sh
|
||||||
bool foundVertex = std::find(usedTextureSamplersVertex.begin(), usedTextureSamplersVertex.end(), texIt->getName()) != usedTextureSamplersVertex.end();
|
bool foundVertex = std::find(usedTextureSamplersVertex.begin(), usedTextureSamplersVertex.end(), texIt->getName()) != usedTextureSamplersVertex.end();
|
||||||
bool foundFragment = std::find(usedTextureSamplersFragment.begin(), usedTextureSamplersFragment.end(), texIt->getName()) != usedTextureSamplersFragment.end();
|
bool foundFragment = std::find(usedTextureSamplersFragment.begin(), usedTextureSamplersFragment.end(), texIt->getName()) != usedTextureSamplersFragment.end();
|
||||||
if ( (foundVertex || foundFragment)
|
if ( (foundVertex || foundFragment)
|
||||||
|| (((!mShadersEnabled || (!hasVertex || !hasFragment)) && allowFixedFunction) && texIt->hasProperty("create_in_ffp") && retrieveValue<BooleanValue>(texIt->getProperty("create_in_ffp"), this).get()))
|
|| (((!useShaders || (!hasVertex || !hasFragment)) && allowFixedFunction) && texIt->hasProperty("create_in_ffp") && retrieveValue<BooleanValue>(texIt->getProperty("create_in_ffp"), this).get()))
|
||||||
{
|
{
|
||||||
boost::shared_ptr<TextureUnitState> texUnit = pass->createTextureUnitState ();
|
boost::shared_ptr<TextureUnitState> texUnit = pass->createTextureUnitState ();
|
||||||
texIt->copyAll (texUnit.get(), context);
|
texIt->copyAll (texUnit.get(), context);
|
||||||
|
@ -152,7 +154,7 @@ namespace sh
|
||||||
mTexUnits.push_back(texUnit);
|
mTexUnits.push_back(texUnit);
|
||||||
|
|
||||||
// set texture unit indices (required by GLSL)
|
// set texture unit indices (required by GLSL)
|
||||||
if (mShadersEnabled && ((hasVertex && foundVertex) || (hasFragment && foundFragment)) && mFactory->getCurrentLanguage () == Language_GLSL)
|
if (useShaders && ((hasVertex && foundVertex) || (hasFragment && foundFragment)) && mFactory->getCurrentLanguage () == Language_GLSL)
|
||||||
{
|
{
|
||||||
pass->setTextureUnitIndex (foundVertex ? GPT_Vertex : GPT_Fragment, texIt->getName(), i);
|
pass->setTextureUnitIndex (foundVertex ? GPT_Vertex : GPT_Fragment, texIt->getName(), i);
|
||||||
|
|
||||||
|
|
110
extern/shiny/Main/ScriptLoader.cpp
vendored
110
extern/shiny/Main/ScriptLoader.cpp
vendored
|
@ -14,9 +14,9 @@ namespace sh
|
||||||
for ( boost::filesystem::recursive_directory_iterator end, dir(path); dir != end; ++dir )
|
for ( boost::filesystem::recursive_directory_iterator end, dir(path); dir != end; ++dir )
|
||||||
{
|
{
|
||||||
boost::filesystem::path p(*dir);
|
boost::filesystem::path p(*dir);
|
||||||
if(p.extension() == c->m_fileEnding)
|
if(p.extension() == c->mFileEnding)
|
||||||
{
|
{
|
||||||
c->m_currentFileName = (*dir).path().string();
|
c->mCurrentFileName = (*dir).path().string();
|
||||||
std::ifstream in((*dir).path().string().c_str(), std::ios::binary);
|
std::ifstream in((*dir).path().string().c_str(), std::ios::binary);
|
||||||
c->parseScript(in);
|
c->parseScript(in);
|
||||||
}
|
}
|
||||||
|
@ -25,7 +25,7 @@ namespace sh
|
||||||
|
|
||||||
ScriptLoader::ScriptLoader(const std::string& fileEnding)
|
ScriptLoader::ScriptLoader(const std::string& fileEnding)
|
||||||
{
|
{
|
||||||
m_fileEnding = fileEnding;
|
mFileEnding = fileEnding;
|
||||||
}
|
}
|
||||||
|
|
||||||
ScriptLoader::~ScriptLoader()
|
ScriptLoader::~ScriptLoader()
|
||||||
|
@ -70,7 +70,7 @@ namespace sh
|
||||||
{
|
{
|
||||||
//Get first token
|
//Get first token
|
||||||
_nextToken(stream);
|
_nextToken(stream);
|
||||||
if (tok == TOKEN_EOF)
|
if (mToken == TOKEN_EOF)
|
||||||
{
|
{
|
||||||
stream.close();
|
stream.close();
|
||||||
return;
|
return;
|
||||||
|
@ -87,7 +87,7 @@ namespace sh
|
||||||
//EOF token
|
//EOF token
|
||||||
if (!stream.good())
|
if (!stream.good())
|
||||||
{
|
{
|
||||||
tok = TOKEN_EOF;
|
mToken = TOKEN_EOF;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -101,7 +101,7 @@ namespace sh
|
||||||
|
|
||||||
if (!stream.good())
|
if (!stream.good())
|
||||||
{
|
{
|
||||||
tok = TOKEN_EOF;
|
mToken = TOKEN_EOF;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -115,21 +115,21 @@ namespace sh
|
||||||
|
|
||||||
stream.unget();
|
stream.unget();
|
||||||
|
|
||||||
tok = TOKEN_NewLine;
|
mToken = TOKEN_NewLine;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
//Open brace token
|
//Open brace token
|
||||||
else if (ch == '{')
|
else if (ch == '{')
|
||||||
{
|
{
|
||||||
tok = TOKEN_OpenBrace;
|
mToken = TOKEN_OpenBrace;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
//Close brace token
|
//Close brace token
|
||||||
else if (ch == '}')
|
else if (ch == '}')
|
||||||
{
|
{
|
||||||
tok = TOKEN_CloseBrace;
|
mToken = TOKEN_CloseBrace;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -139,8 +139,8 @@ namespace sh
|
||||||
throw std::runtime_error("Parse Error: Invalid character, ConfigLoader::load()");
|
throw std::runtime_error("Parse Error: Invalid character, ConfigLoader::load()");
|
||||||
}
|
}
|
||||||
|
|
||||||
tokVal = "";
|
mTokenValue = "";
|
||||||
tok = TOKEN_Text;
|
mToken = TOKEN_Text;
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
//Skip comments
|
//Skip comments
|
||||||
|
@ -157,13 +157,13 @@ namespace sh
|
||||||
ch = stream.get();
|
ch = stream.get();
|
||||||
} while (ch != '\r' && ch != '\n' && !stream.eof());
|
} while (ch != '\r' && ch != '\n' && !stream.eof());
|
||||||
|
|
||||||
tok = TOKEN_NewLine;
|
mToken = TOKEN_NewLine;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//Add valid char to tokVal
|
//Add valid char to tokVal
|
||||||
tokVal += (char)ch;
|
mTokenValue += (char)ch;
|
||||||
|
|
||||||
//Next char
|
//Next char
|
||||||
ch = stream.get();
|
ch = stream.get();
|
||||||
|
@ -177,7 +177,7 @@ namespace sh
|
||||||
|
|
||||||
void ScriptLoader::_skipNewLines(std::ifstream &stream)
|
void ScriptLoader::_skipNewLines(std::ifstream &stream)
|
||||||
{
|
{
|
||||||
while (tok == TOKEN_NewLine)
|
while (mToken == TOKEN_NewLine)
|
||||||
{
|
{
|
||||||
_nextToken(stream);
|
_nextToken(stream);
|
||||||
}
|
}
|
||||||
|
@ -189,7 +189,7 @@ namespace sh
|
||||||
|
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
switch (tok)
|
switch (mToken)
|
||||||
{
|
{
|
||||||
//Node
|
//Node
|
||||||
case TOKEN_Text:
|
case TOKEN_Text:
|
||||||
|
@ -198,23 +198,23 @@ namespace sh
|
||||||
ScriptNode *newNode;
|
ScriptNode *newNode;
|
||||||
if (parent)
|
if (parent)
|
||||||
{
|
{
|
||||||
newNode = parent->addChild(tokVal);
|
newNode = parent->addChild(mTokenValue);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
newNode = new ScriptNode(0, tokVal);
|
newNode = new ScriptNode(0, mTokenValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
//Get values
|
//Get values
|
||||||
_nextToken(stream);
|
_nextToken(stream);
|
||||||
std::string valueStr;
|
std::string valueStr;
|
||||||
int i=0;
|
int i=0;
|
||||||
while (tok == TOKEN_Text)
|
while (mToken == TOKEN_Text)
|
||||||
{
|
{
|
||||||
if (i == 0)
|
if (i == 0)
|
||||||
valueStr += tokVal;
|
valueStr += mTokenValue;
|
||||||
else
|
else
|
||||||
valueStr += " " + tokVal;
|
valueStr += " " + mTokenValue;
|
||||||
_nextToken(stream);
|
_nextToken(stream);
|
||||||
++i;
|
++i;
|
||||||
}
|
}
|
||||||
|
@ -235,13 +235,13 @@ namespace sh
|
||||||
_skipNewLines(stream);
|
_skipNewLines(stream);
|
||||||
|
|
||||||
//Add any sub-nodes
|
//Add any sub-nodes
|
||||||
if (tok == TOKEN_OpenBrace)
|
if (mToken == TOKEN_OpenBrace)
|
||||||
{
|
{
|
||||||
//Parse nodes
|
//Parse nodes
|
||||||
_nextToken(stream);
|
_nextToken(stream);
|
||||||
_parseNodes(stream, newNode);
|
_parseNodes(stream, newNode);
|
||||||
//Check for matching closing brace
|
//Check for matching closing brace
|
||||||
if (tok != TOKEN_CloseBrace)
|
if (mToken != TOKEN_CloseBrace)
|
||||||
{
|
{
|
||||||
throw std::runtime_error("Parse Error: Expecting closing brace");
|
throw std::runtime_error("Parse Error: Expecting closing brace");
|
||||||
}
|
}
|
||||||
|
@ -249,7 +249,7 @@ namespace sh
|
||||||
_skipNewLines(stream);
|
_skipNewLines(stream);
|
||||||
}
|
}
|
||||||
|
|
||||||
newNode->m_fileName = m_currentFileName;
|
newNode->mFileName = mCurrentFileName;
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -276,16 +276,16 @@ namespace sh
|
||||||
|
|
||||||
ScriptNode::ScriptNode(ScriptNode *parent, const std::string &name)
|
ScriptNode::ScriptNode(ScriptNode *parent, const std::string &name)
|
||||||
{
|
{
|
||||||
m_name = name;
|
mName = name;
|
||||||
m_parent = parent;
|
mParent = parent;
|
||||||
_removeSelf = true; //For proper destruction
|
mRemoveSelf = true; //For proper destruction
|
||||||
m_lastChildFound = -1;
|
mLastChildFound = -1;
|
||||||
|
|
||||||
//Add self to parent's child list (unless this is the root node being created)
|
//Add self to parent's child list (unless this is the root node being created)
|
||||||
if (parent != NULL)
|
if (parent != NULL)
|
||||||
{
|
{
|
||||||
m_parent->m_children.push_back(this);
|
mParent->mChildren.push_back(this);
|
||||||
_iter = --(m_parent->m_children.end());
|
mIter = --(mParent->mChildren.end());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -293,18 +293,18 @@ namespace sh
|
||||||
{
|
{
|
||||||
//Delete all children
|
//Delete all children
|
||||||
std::vector<ScriptNode*>::iterator i;
|
std::vector<ScriptNode*>::iterator i;
|
||||||
for (i = m_children.begin(); i != m_children.end(); i++)
|
for (i = mChildren.begin(); i != mChildren.end(); i++)
|
||||||
{
|
{
|
||||||
ScriptNode *node = *i;
|
ScriptNode *node = *i;
|
||||||
node->_removeSelf = false;
|
node->mRemoveSelf = false;
|
||||||
delete node;
|
delete node;
|
||||||
}
|
}
|
||||||
m_children.clear();
|
mChildren.clear();
|
||||||
|
|
||||||
//Remove self from parent's child list
|
//Remove self from parent's child list
|
||||||
if (_removeSelf && m_parent != NULL)
|
if (mRemoveSelf && mParent != NULL)
|
||||||
{
|
{
|
||||||
m_parent->m_children.erase(_iter);
|
mParent->mChildren.erase(mIter);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -324,20 +324,20 @@ namespace sh
|
||||||
ScriptNode *ScriptNode::findChild(const std::string &name, bool recursive)
|
ScriptNode *ScriptNode::findChild(const std::string &name, bool recursive)
|
||||||
{
|
{
|
||||||
int indx, prevC, nextC;
|
int indx, prevC, nextC;
|
||||||
int childCount = (int)m_children.size();
|
int childCount = (int)mChildren.size();
|
||||||
|
|
||||||
if (m_lastChildFound != -1)
|
if (mLastChildFound != -1)
|
||||||
{
|
{
|
||||||
//If possible, try checking the nodes neighboring the last successful search
|
//If possible, try checking the nodes neighboring the last successful search
|
||||||
//(often nodes searched for in sequence, so this will boost search speeds).
|
//(often nodes searched for in sequence, so this will boost search speeds).
|
||||||
prevC = m_lastChildFound-1; if (prevC < 0) prevC = 0; else if (prevC >= childCount) prevC = childCount-1;
|
prevC = mLastChildFound-1; if (prevC < 0) prevC = 0; else if (prevC >= childCount) prevC = childCount-1;
|
||||||
nextC = m_lastChildFound+1; if (nextC < 0) nextC = 0; else if (nextC >= childCount) nextC = childCount-1;
|
nextC = mLastChildFound+1; if (nextC < 0) nextC = 0; else if (nextC >= childCount) nextC = childCount-1;
|
||||||
for (indx = prevC; indx <= nextC; ++indx)
|
for (indx = prevC; indx <= nextC; ++indx)
|
||||||
{
|
{
|
||||||
ScriptNode *node = m_children[indx];
|
ScriptNode *node = mChildren[indx];
|
||||||
if (node->m_name == name)
|
if (node->mName == name)
|
||||||
{
|
{
|
||||||
m_lastChildFound = indx;
|
mLastChildFound = indx;
|
||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -346,17 +346,17 @@ namespace sh
|
||||||
//already searched area above.
|
//already searched area above.
|
||||||
for (indx = nextC + 1; indx < childCount; ++indx)
|
for (indx = nextC + 1; indx < childCount; ++indx)
|
||||||
{
|
{
|
||||||
ScriptNode *node = m_children[indx];
|
ScriptNode *node = mChildren[indx];
|
||||||
if (node->m_name == name) {
|
if (node->mName == name) {
|
||||||
m_lastChildFound = indx;
|
mLastChildFound = indx;
|
||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (indx = 0; indx < prevC; ++indx)
|
for (indx = 0; indx < prevC; ++indx)
|
||||||
{
|
{
|
||||||
ScriptNode *node = m_children[indx];
|
ScriptNode *node = mChildren[indx];
|
||||||
if (node->m_name == name) {
|
if (node->mName == name) {
|
||||||
m_lastChildFound = indx;
|
mLastChildFound = indx;
|
||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -365,9 +365,9 @@ namespace sh
|
||||||
{
|
{
|
||||||
//Search for the node from start to finish
|
//Search for the node from start to finish
|
||||||
for (indx = 0; indx < childCount; ++indx){
|
for (indx = 0; indx < childCount; ++indx){
|
||||||
ScriptNode *node = m_children[indx];
|
ScriptNode *node = mChildren[indx];
|
||||||
if (node->m_name == name) {
|
if (node->mName == name) {
|
||||||
m_lastChildFound = indx;
|
mLastChildFound = indx;
|
||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -378,7 +378,7 @@ namespace sh
|
||||||
{
|
{
|
||||||
for (indx = 0; indx < childCount; ++indx)
|
for (indx = 0; indx < childCount; ++indx)
|
||||||
{
|
{
|
||||||
m_children[indx]->findChild(name, recursive);
|
mChildren[indx]->findChild(name, recursive);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -389,13 +389,13 @@ namespace sh
|
||||||
void ScriptNode::setParent(ScriptNode *newParent)
|
void ScriptNode::setParent(ScriptNode *newParent)
|
||||||
{
|
{
|
||||||
//Remove self from current parent
|
//Remove self from current parent
|
||||||
m_parent->m_children.erase(_iter);
|
mParent->mChildren.erase(mIter);
|
||||||
|
|
||||||
//Set new parent
|
//Set new parent
|
||||||
m_parent = newParent;
|
mParent = newParent;
|
||||||
|
|
||||||
//Add self to new parent
|
//Add self to new parent
|
||||||
m_parent->m_children.push_back(this);
|
mParent->mChildren.push_back(this);
|
||||||
_iter = --(m_parent->m_children.end());
|
mIter = --(mParent->mChildren.end());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
42
extern/shiny/Main/ScriptLoader.hpp
vendored
42
extern/shiny/Main/ScriptLoader.hpp
vendored
|
@ -23,7 +23,7 @@ namespace sh
|
||||||
ScriptLoader(const std::string& fileEnding);
|
ScriptLoader(const std::string& fileEnding);
|
||||||
virtual ~ScriptLoader();
|
virtual ~ScriptLoader();
|
||||||
|
|
||||||
std::string m_fileEnding;
|
std::string mFileEnding;
|
||||||
|
|
||||||
// For a line like
|
// For a line like
|
||||||
// entity animals/dog
|
// entity animals/dog
|
||||||
|
@ -38,11 +38,11 @@ namespace sh
|
||||||
|
|
||||||
void parseScript(std::ifstream &stream);
|
void parseScript(std::ifstream &stream);
|
||||||
|
|
||||||
std::string m_currentFileName;
|
std::string mCurrentFileName;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
float m_LoadOrder;
|
float mLoadOrder;
|
||||||
// like "*.object"
|
// like "*.object"
|
||||||
|
|
||||||
std::map <std::string, ScriptNode*> m_scriptList;
|
std::map <std::string, ScriptNode*> m_scriptList;
|
||||||
|
@ -56,8 +56,8 @@ namespace sh
|
||||||
TOKEN_EOF
|
TOKEN_EOF
|
||||||
};
|
};
|
||||||
|
|
||||||
Token tok, lastTok;
|
Token mToken, mLastToken;
|
||||||
std::string tokVal;
|
std::string mTokenValue;
|
||||||
|
|
||||||
void _parseNodes(std::ifstream &stream, ScriptNode *parent);
|
void _parseNodes(std::ifstream &stream, ScriptNode *parent);
|
||||||
void _nextToken(std::ifstream &stream);
|
void _nextToken(std::ifstream &stream);
|
||||||
|
@ -74,22 +74,22 @@ namespace sh
|
||||||
|
|
||||||
inline void setName(const std::string &name)
|
inline void setName(const std::string &name)
|
||||||
{
|
{
|
||||||
this->m_name = name;
|
this->mName = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline std::string &getName()
|
inline std::string &getName()
|
||||||
{
|
{
|
||||||
return m_name;
|
return mName;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void setValue(const std::string &value)
|
inline void setValue(const std::string &value)
|
||||||
{
|
{
|
||||||
m_value = value;
|
mValue = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline std::string &getValue()
|
inline std::string &getValue()
|
||||||
{
|
{
|
||||||
return m_value;
|
return mValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
ScriptNode *addChild(const std::string &name = "untitled", bool replaceExisting = false);
|
ScriptNode *addChild(const std::string &name = "untitled", bool replaceExisting = false);
|
||||||
|
@ -97,36 +97,36 @@ namespace sh
|
||||||
|
|
||||||
inline std::vector<ScriptNode*> &getChildren()
|
inline std::vector<ScriptNode*> &getChildren()
|
||||||
{
|
{
|
||||||
return m_children;
|
return mChildren;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline ScriptNode *getChild(unsigned int index = 0)
|
inline ScriptNode *getChild(unsigned int index = 0)
|
||||||
{
|
{
|
||||||
assert(index < m_children.size());
|
assert(index < mChildren.size());
|
||||||
return m_children[index];
|
return mChildren[index];
|
||||||
}
|
}
|
||||||
|
|
||||||
void setParent(ScriptNode *newParent);
|
void setParent(ScriptNode *newParent);
|
||||||
|
|
||||||
inline ScriptNode *getParent()
|
inline ScriptNode *getParent()
|
||||||
{
|
{
|
||||||
return m_parent;
|
return mParent;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string m_fileName;
|
std::string mFileName;
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::string m_name;
|
std::string mName;
|
||||||
std::string m_value;
|
std::string mValue;
|
||||||
std::vector<ScriptNode*> m_children;
|
std::vector<ScriptNode*> mChildren;
|
||||||
ScriptNode *m_parent;
|
ScriptNode *mParent;
|
||||||
|
|
||||||
|
|
||||||
int m_lastChildFound; //The last child node's index found with a call to findChild()
|
int mLastChildFound; //The last child node's index found with a call to findChild()
|
||||||
|
|
||||||
std::vector<ScriptNode*>::iterator _iter;
|
std::vector<ScriptNode*>::iterator mIter;
|
||||||
bool _removeSelf;
|
bool mRemoveSelf;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue