Merge branch 'master' of https://github.com/zinnschlag/openmw into journal

This commit is contained in:
scrawl 2013-05-03 18:17:27 +02:00
commit 1f58edb9db
34 changed files with 369 additions and 63 deletions

View file

@ -201,6 +201,8 @@ namespace MWBase
///< Hides dialog and schedules dialog to be deleted. ///< Hides dialog and schedules dialog to be deleted.
virtual void messageBox (const std::string& message, const std::vector<std::string>& buttons = std::vector<std::string>()) = 0; virtual void messageBox (const std::string& message, const std::vector<std::string>& buttons = std::vector<std::string>()) = 0;
virtual void staticMessageBox(const std::string& message) = 0;
virtual void removeStaticMessageBox() = 0;
virtual void enterPressed () = 0; virtual void enterPressed () = 0;
virtual int readPressedButton() = 0; virtual int readPressedButton() = 0;

View file

@ -331,6 +331,10 @@ namespace MWBase
virtual void activateDoor(const MWWorld::Ptr& door) = 0; virtual void activateDoor(const MWWorld::Ptr& door) = 0;
///< activate (open or close) an non-teleport door ///< activate (open or close) an non-teleport door
virtual bool getPlayerStandingOn (const MWWorld::Ptr& object) = 0; ///< @return true if the player is standing on \a object
virtual bool getActorStandingOn (const MWWorld::Ptr& object) = 0; ///< @return true if any actor is standing on \a object
virtual float getWindSpeed() = 0;
virtual void setupExternalRendering (MWRender::ExternalRendering& rendering) = 0; virtual void setupExternalRendering (MWRender::ExternalRendering& rendering) = 0;
virtual int canRest() = 0; virtual int canRest() = 0;

View file

@ -137,8 +137,7 @@ namespace MWClass
fJumpAcrobaticsBase = gmst.find("fJumpAcrobaticsBase"); fJumpAcrobaticsBase = gmst.find("fJumpAcrobaticsBase");
fJumpAcroMultiplier = gmst.find("fJumpAcroMultiplier"); fJumpAcroMultiplier = gmst.find("fJumpAcroMultiplier");
fJumpRunMultiplier = gmst.find("fJumpRunMultiplier"); fJumpRunMultiplier = gmst.find("fJumpRunMultiplier");
// Added in Tribunal/Bloodmoon, may not exist fWereWolfRunMult = gmst.find("fWereWolfRunMult");
fWereWolfRunMult = gmst.search("fWereWolfRunMult");
inited = true; inited = true;
} }

View file

@ -76,7 +76,7 @@ namespace MWGui
parent = mRightPage; parent = mRightPage;
MyGUI::Widget* pageWidget = parent->createWidgetReal<MyGUI::Widget>("", MyGUI::FloatCoord(0.0,0.0,1.0,1.0), MyGUI::Align::Default, "BookPage" + boost::lexical_cast<std::string>(i)); MyGUI::Widget* pageWidget = parent->createWidgetReal<MyGUI::Widget>("", MyGUI::FloatCoord(0.0,0.0,1.0,1.0), MyGUI::Align::Default, "BookPage" + boost::lexical_cast<std::string>(i));
parser.parse(*it, pageWidget, mLeftPage->getSize().width); parser.parsePage(*it, pageWidget, mLeftPage->getSize().width);
mPages.push_back(pageWidget); mPages.push_back(pageWidget);
++i; ++i;
} }
@ -157,6 +157,21 @@ namespace MWGui
} }
++i; ++i;
} }
//If it is the last page, hide the button "Next Page"
if ( (mCurrentPage+1)*2 == mPages.size()
|| (mCurrentPage+1)*2 == mPages.size() + 1)
{
mNextPageButton->setVisible(false);
} else {
mNextPageButton->setVisible(true);
}
//If it is the fist page, hide the button "Prev Page"
if (mCurrentPage == 0) {
mPrevPageButton->setVisible(false);
} else {
mPrevPageButton->setVisible(true);
}
} }
} }

View file

@ -6,7 +6,10 @@
#include <boost/algorithm/string/replace.hpp> #include <boost/algorithm/string/replace.hpp>
#include <boost/algorithm/string/predicate.hpp> #include <boost/algorithm/string/predicate.hpp>
#include <boost/algorithm/string/trim.hpp>
#include <boost/lexical_cast.hpp> #include <boost/lexical_cast.hpp>
#include <boost/range/adaptor/filtered.hpp>
#include <boost/range/algorithm/copy.hpp>
#include <OgreUTFString.h> #include <OgreUTFString.h>
namespace namespace
@ -74,6 +77,12 @@ namespace
Ogre::UTFString string(s); Ogre::UTFString string(s);
return string.getChar(0); return string.getChar(0);
} }
bool is_not_empty(const std::string s) {
std::string temp = s;
boost::algorithm::trim(temp);
return !temp.empty();
}
} }
namespace MWGui namespace MWGui
@ -88,6 +97,7 @@ namespace MWGui
utf8Text = Interpreter::fixDefinesBook(utf8Text, interpreterContext); utf8Text = Interpreter::fixDefinesBook(utf8Text, interpreterContext);
boost::algorithm::replace_all(utf8Text, "\n", ""); boost::algorithm::replace_all(utf8Text, "\n", "");
boost::algorithm::replace_all(utf8Text, "\r", "");
boost::algorithm::replace_all(utf8Text, "<BR>", "\n"); boost::algorithm::replace_all(utf8Text, "<BR>", "\n");
boost::algorithm::replace_all(utf8Text, "<P>", "\n\n"); boost::algorithm::replace_all(utf8Text, "<P>", "\n\n");
@ -106,6 +116,14 @@ namespace MWGui
size_t currentWordStart = 0; size_t currentWordStart = 0;
size_t index = 0; size_t index = 0;
{
std::string texToTrim = text.asUTF8();
boost::algorithm::trim( texToTrim );
text = UTFString(texToTrim);
}
while (currentHeight <= height - spacing && index < text.size()) while (currentHeight <= height - spacing && index < text.size())
{ {
const UTFString::unicode_char ch = text.getChar(index); const UTFString::unicode_char ch = text.getChar(index);
@ -176,8 +194,10 @@ namespace MWGui
result.push_back(text.substr(0, pageEnd).asUTF8()); result.push_back(text.substr(0, pageEnd).asUTF8());
text.erase(0, pageEnd); text.erase(0, pageEnd);
} }
return result; std::vector<std::string> nonEmptyPages;
boost::copy(result | boost::adaptors::filtered(is_not_empty), std::back_inserter(nonEmptyPages));
return nonEmptyPages;
} }
float BookTextParser::widthForCharGlyph(unsigned unicodeChar) const float BookTextParser::widthForCharGlyph(unsigned unicodeChar) const
@ -193,7 +213,30 @@ namespace MWGui
return MyGUI::FontManager::getInstance().getByName(fontName)->getDefaultHeight(); return MyGUI::FontManager::getInstance().getByName(fontName)->getDefaultHeight();
} }
MyGUI::IntSize BookTextParser::parse(std::string text, MyGUI::Widget* parent, const int width) MyGUI::IntSize BookTextParser::parsePage(std::string text, MyGUI::Widget* parent, const int width)
{
MWScript::InterpreterContext interpreterContext(NULL, MWWorld::Ptr()); // empty arguments, because there is no locals or actor
text = Interpreter::fixDefinesBook(text, interpreterContext);
mParent = parent;
mWidth = width;
mHeight = 0;
assert(mParent);
while (mParent->getChildCount())
{
MyGUI::Gui::getInstance().destroyWidget(mParent->getChildAt(0));
}
// remove trailing "
if (text[text.size()-1] == '\"')
text.erase(text.size()-1);
parseSubText(text);
return MyGUI::IntSize(mWidth, mHeight);
}
MyGUI::IntSize BookTextParser::parseScroll(std::string text, MyGUI::Widget* parent, const int width)
{ {
MWScript::InterpreterContext interpreterContext(NULL, MWWorld::Ptr()); // empty arguments, because there is no locals or actor MWScript::InterpreterContext interpreterContext(NULL, MWWorld::Ptr()); // empty arguments, because there is no locals or actor
text = Interpreter::fixDefinesBook(text, interpreterContext); text = Interpreter::fixDefinesBook(text, interpreterContext);
@ -209,12 +252,10 @@ namespace MWGui
} }
boost::algorithm::replace_all(text, "\n", ""); boost::algorithm::replace_all(text, "\n", "");
boost::algorithm::replace_all(text, "\r", "");
boost::algorithm::replace_all(text, "<BR>", "\n"); boost::algorithm::replace_all(text, "<BR>", "\n");
boost::algorithm::replace_all(text, "<P>", "\n\n"); boost::algorithm::replace_all(text, "<P>", "\n\n");
boost::algorithm::trim_left(text);
// remove leading newlines
// while (text[0] == '\n')
// text.erase(0);
// remove trailing " // remove trailing "
if (text[text.size()-1] == '\"') if (text[text.size()-1] == '\"')
@ -223,6 +264,7 @@ namespace MWGui
parseSubText(text); parseSubText(text);
return MyGUI::IntSize(mWidth, mHeight); return MyGUI::IntSize(mWidth, mHeight);
} }
void BookTextParser::parseImage(std::string tag, bool createWidget) void BookTextParser::parseImage(std::string tag, bool createWidget)
{ {
@ -309,7 +351,7 @@ namespace MWGui
parseImage(tag); parseImage(tag);
if (boost::algorithm::starts_with(tag, "FONT")) if (boost::algorithm::starts_with(tag, "FONT"))
parseFont(tag); parseFont(tag);
if (boost::algorithm::starts_with(tag, "DOV")) if (boost::algorithm::starts_with(tag, "DIV"))
parseDiv(tag); parseDiv(tag);
text.erase(0, tagEnd + 1); text.erase(0, tagEnd + 1);

View file

@ -32,7 +32,16 @@ namespace MWGui
* @param maximum width * @param maximum width
* @return size of the created widgets * @return size of the created widgets
*/ */
MyGUI::IntSize parse(std::string text, MyGUI::Widget* parent, const int width); MyGUI::IntSize parsePage(std::string text, MyGUI::Widget* parent, const int width);
/**
* Parse markup as MyGUI widgets
* @param markup to parse
* @param parent for the created widgets
* @param maximum width
* @return size of the created widgets
*/
MyGUI::IntSize parseScroll(std::string text, MyGUI::Widget* parent, const int width);
/** /**
* Split the specified text into pieces that fit in the area specified by width and height parameters * Split the specified text into pieces that fit in the area specified by width and height parameters

View file

@ -22,6 +22,7 @@ namespace MWGui
, mLastRenderTime(0.f) , mLastRenderTime(0.f)
, mLastWallpaperChangeTime(0.f) , mLastWallpaperChangeTime(0.f)
, mFirstLoad(true) , mFirstLoad(true)
, mTotalRefsLoading(0)
{ {
getWidget(mLoadingText, "LoadingText"); getWidget(mLoadingText, "LoadingText");
getWidget(mProgressBar, "ProgressBar"); getWidget(mProgressBar, "ProgressBar");

View file

@ -13,6 +13,7 @@ namespace MWGui
// defines // defines
mMessageBoxSpeed = 0.1; mMessageBoxSpeed = 0.1;
mInterMessageBoxe = NULL; mInterMessageBoxe = NULL;
mStaticMessageBox = NULL;
} }
void MessageBoxManager::onFrame (float frameDuration) void MessageBoxManager::onFrame (float frameDuration)
@ -68,11 +69,14 @@ namespace MWGui
} }
} }
void MessageBoxManager::createMessageBox (const std::string& message) void MessageBoxManager::createMessageBox (const std::string& message, bool stat)
{ {
MessageBox *box = new MessageBox(*this, message); MessageBox *box = new MessageBox(*this, message);
removeMessageBox(message.length()*mMessageBoxSpeed, box); if(stat)
mStaticMessageBox = box;
else
removeMessageBox(message.length()*mMessageBoxSpeed, box);
mMessageBoxes.push_back(box); mMessageBoxes.push_back(box);
std::vector<MessageBox*>::iterator it; std::vector<MessageBox*>::iterator it;
@ -90,6 +94,12 @@ namespace MWGui
} }
} }
void MessageBoxManager::removeStaticMessageBox ()
{
removeMessageBox(mStaticMessageBox);
mStaticMessageBox = NULL;
}
bool MessageBoxManager::createInteractiveMessageBox (const std::string& message, const std::vector<std::string>& buttons) bool MessageBoxManager::createInteractiveMessageBox (const std::string& message, const std::vector<std::string>& buttons)
{ {
if(mInterMessageBoxe != NULL) { if(mInterMessageBoxe != NULL) {

View file

@ -31,7 +31,8 @@ namespace MWGui
public: public:
MessageBoxManager (); MessageBoxManager ();
void onFrame (float frameDuration); void onFrame (float frameDuration);
void createMessageBox (const std::string& message); void createMessageBox (const std::string& message, bool stat = false);
void removeStaticMessageBox ();
bool createInteractiveMessageBox (const std::string& message, const std::vector<std::string>& buttons); bool createInteractiveMessageBox (const std::string& message, const std::vector<std::string>& buttons);
bool isInteractiveMessageBox (); bool isInteractiveMessageBox ();
@ -52,6 +53,7 @@ namespace MWGui
private: private:
std::vector<MessageBox*> mMessageBoxes; std::vector<MessageBox*> mMessageBoxes;
InteractiveMessageBox* mInterMessageBoxe; InteractiveMessageBox* mInterMessageBoxe;
MessageBox* mStaticMessageBox;
std::vector<MessageBoxManagerTimer> mTimers; std::vector<MessageBoxManagerTimer> mTimers;
float mMessageBoxSpeed; float mMessageBoxSpeed;
}; };

View file

@ -39,7 +39,7 @@ namespace MWGui
MWWorld::LiveCellRef<ESM::Book> *ref = mScroll.get<ESM::Book>(); MWWorld::LiveCellRef<ESM::Book> *ref = mScroll.get<ESM::Book>();
BookTextParser parser; BookTextParser parser;
MyGUI::IntSize size = parser.parse(ref->mBase->mText, mTextView, 390); MyGUI::IntSize size = parser.parseScroll(ref->mBase->mText, mTextView, 390);
if (size.height > mTextView->getSize().height) if (size.height > mTextView->getSize().height)
mTextView->setCanvasSize(MyGUI::IntSize(410, size.height)); mTextView->setCanvasSize(MyGUI::IntSize(410, size.height));

View file

@ -551,6 +551,8 @@ namespace MWGui
while (mControlsBox->getChildCount()) while (mControlsBox->getChildCount())
MyGUI::Gui::getInstance().destroyWidget(mControlsBox->getChildAt(0)); MyGUI::Gui::getInstance().destroyWidget(mControlsBox->getChildAt(0));
MWBase::Environment::get().getWindowManager ()->removeStaticMessageBox();
std::vector<int> actions = MWBase::Environment::get().getInputManager()->getActionSorting (); std::vector<int> actions = MWBase::Environment::get().getInputManager()->getActionSorting ();
const int h = 18; const int h = 18;
@ -585,7 +587,7 @@ namespace MWGui
static_cast<MyGUI::Button*>(_sender)->setCaptionWithReplacing("#{sNone}"); static_cast<MyGUI::Button*>(_sender)->setCaptionWithReplacing("#{sNone}");
MWBase::Environment::get().getWindowManager ()->messageBox ("#{sControlsMenu3}"); MWBase::Environment::get().getWindowManager ()->staticMessageBox ("#{sControlsMenu3}");
MWBase::Environment::get().getWindowManager ()->disallowMouse(); MWBase::Environment::get().getWindowManager ()->disallowMouse();
MWBase::Environment::get().getInputManager ()->enableDetectingBindingMode (actionId); MWBase::Environment::get().getInputManager ()->enableDetectingBindingMode (actionId);

View file

@ -603,6 +603,16 @@ namespace MWGui
} }
} }
void WindowManager::staticMessageBox(const std::string& message)
{
mMessageBoxManager->createMessageBox(message, true);
}
void WindowManager::removeStaticMessageBox()
{
mMessageBoxManager->removeStaticMessageBox();
}
void WindowManager::enterPressed () void WindowManager::enterPressed ()
{ {
mMessageBoxManager->enterPressed(); mMessageBoxManager->enterPressed();

View file

@ -192,6 +192,8 @@ namespace MWGui
virtual void removeDialog(OEngine::GUI::Layout* dialog); ///< Hides dialog and schedules dialog to be deleted. virtual void removeDialog(OEngine::GUI::Layout* dialog); ///< Hides dialog and schedules dialog to be deleted.
virtual void messageBox (const std::string& message, const std::vector<std::string>& buttons = std::vector<std::string>()); virtual void messageBox (const std::string& message, const std::vector<std::string>& buttons = std::vector<std::string>());
virtual void staticMessageBox(const std::string& message);
virtual void removeStaticMessageBox();
virtual void enterPressed (); virtual void enterPressed ();
virtual int readPressedButton (); ///< returns the index of the pressed button or -1 if no button was pressed (->MessageBoxmanager->InteractiveMessageBox) virtual int readPressedButton (); ///< returns the index of the pressed button or -1 if no button was pressed (->MessageBoxmanager->InteractiveMessageBox)

View file

@ -917,6 +917,10 @@ namespace MWInput
void InputManager::keyBindingDetected(ICS::InputControlSystem* ICS, ICS::Control* control void InputManager::keyBindingDetected(ICS::InputControlSystem* ICS, ICS::Control* control
, OIS::KeyCode key, ICS::Control::ControlChangingDirection direction) , OIS::KeyCode key, ICS::Control::ControlChangingDirection direction)
{ {
//Disallow binding escape key, and unassigned keys
if(key==OIS::KC_ESCAPE || key==OIS::KC_UNASSIGNED)
return
clearAllBindings(control); clearAllBindings(control);
ICS::DetectingBindingListener::keyBindingDetected (ICS, control, key, direction); ICS::DetectingBindingListener::keyBindingDetected (ICS, control, key, direction);
MWBase::Environment::get().getWindowManager ()->notifyInputActionBound (); MWBase::Environment::get().getWindowManager ()->notifyInputActionBound ();

View file

@ -104,7 +104,14 @@ static void getStateInfo(CharacterState state, std::string *group)
CharacterController::CharacterController(const MWWorld::Ptr &ptr, MWRender::Animation *anim, CharacterState state, bool loop) CharacterController::CharacterController(const MWWorld::Ptr &ptr, MWRender::Animation *anim, CharacterState state, bool loop)
: mPtr(ptr), mAnimation(anim), mCharState(state), mSkipAnim(false), mMovingAnim(false), mSecondsOfRunning(0), mSecondsOfSwimming(0) : mPtr(ptr)
, mAnimation(anim)
, mCharState(state)
, mSkipAnim(false)
, mMovingAnim(false)
, mSecondsOfRunning(0)
, mSecondsOfSwimming(0)
, mLooping(false)
{ {
if(!mAnimation) if(!mAnimation)
return; return;

View file

@ -49,6 +49,7 @@ namespace MWRender
TerrainMaterial::Profile::Profile(Ogre::TerrainMaterialGenerator* parent, const Ogre::String& name, const Ogre::String& desc) TerrainMaterial::Profile::Profile(Ogre::TerrainMaterialGenerator* parent, const Ogre::String& name, const Ogre::String& desc)
: Ogre::TerrainMaterialGenerator::Profile(parent, name, desc) : Ogre::TerrainMaterialGenerator::Profile(parent, name, desc)
, mGlobalColourMap(false) , mGlobalColourMap(false)
, mMaterial(0)
{ {
} }

View file

@ -41,7 +41,9 @@ namespace MWRender {
{ {
public: public:
Reflection(Ogre::SceneManager* sceneManager) Reflection(Ogre::SceneManager* sceneManager)
: mSceneMgr(sceneManager) {} : mSceneMgr(sceneManager)
, mIsUnderwater(false)
{}
virtual ~Reflection() {} virtual ~Reflection() {}
virtual void setHeight (float height) {} virtual void setHeight (float height) {}

View file

@ -331,5 +331,12 @@ op 0x2000208: MoveWorld
op 0x2000209: MoveWorld, explicit op 0x2000209: MoveWorld, explicit
op 0x200020a: Fall op 0x200020a: Fall
op 0x200020b: Fall, explicit op 0x200020b: Fall, explicit
op 0x200020c: GetStandingPC
op 0x200020d: GetStandingPC, explicit
op 0x200020e: GetStandingActor
op 0x200020f: GetStandingActor, explicit
op 0x2000210: GetStartingAngle
op 0x2000211: GetStartingAngle, explicit
op 0x2000212: GetWindSpeed
opcodes 0x200020c-0x3ffffff unused opcodes 0x2000213-0x3ffffff unused

View file

@ -565,6 +565,40 @@ namespace MWScript
} }
}; };
template <class R>
class OpGetStandingPc : public Interpreter::Opcode0
{
public:
virtual void execute (Interpreter::Runtime& runtime)
{
MWWorld::Ptr ptr = R()(runtime);
runtime.push (MWBase::Environment::get().getWorld()->getPlayerStandingOn(ptr));
}
};
template <class R>
class OpGetStandingActor : public Interpreter::Opcode0
{
public:
virtual void execute (Interpreter::Runtime& runtime)
{
MWWorld::Ptr ptr = R()(runtime);
runtime.push (MWBase::Environment::get().getWorld()->getActorStandingOn(ptr));
}
};
class OpGetWindSpeed : public Interpreter::Opcode0
{
public:
virtual void execute (Interpreter::Runtime& runtime)
{
runtime.push(MWBase::Environment::get().getWorld()->getWindSpeed());
}
};
const int opcodeXBox = 0x200000c; const int opcodeXBox = 0x200000c;
const int opcodeOnActivate = 0x200000d; const int opcodeOnActivate = 0x200000d;
const int opcodeActivate = 0x2000075; const int opcodeActivate = 0x2000075;
@ -608,6 +642,11 @@ namespace MWScript
const int opcodeGetSquareRoot = 0x20001e7; const int opcodeGetSquareRoot = 0x20001e7;
const int opcodeFall = 0x200020a; const int opcodeFall = 0x200020a;
const int opcodeFallExplicit = 0x200020b; const int opcodeFallExplicit = 0x200020b;
const int opcodeGetStandingPc = 0x200020c;
const int opcodeGetStandingPcExplicit = 0x200020d;
const int opcodeGetStandingActor = 0x200020e;
const int opcodeGetStandingActorExplicit = 0x200020f;
const int opcodeGetWindSpeed = 0x2000212;
const int opcodePlayBink = 0x20001f7; const int opcodePlayBink = 0x20001f7;
@ -650,6 +689,9 @@ namespace MWScript
extensions.registerInstruction ("setdelete", "l", opcodeSetDelete, opcodeSetDeleteExplicit); extensions.registerInstruction ("setdelete", "l", opcodeSetDelete, opcodeSetDeleteExplicit);
extensions.registerFunction ("getsquareroot", 'f', "f", opcodeGetSquareRoot); extensions.registerFunction ("getsquareroot", 'f', "f", opcodeGetSquareRoot);
extensions.registerInstruction ("fall", "", opcodeFall, opcodeFallExplicit); extensions.registerInstruction ("fall", "", opcodeFall, opcodeFallExplicit);
extensions.registerFunction ("getstandingpc", 'l', "", opcodeGetStandingPc, opcodeGetStandingPcExplicit);
extensions.registerFunction ("getstandingactor", 'l', "", opcodeGetStandingActor, opcodeGetStandingActorExplicit);
extensions.registerFunction ("getwindspeed", 'f', "", opcodeGetWindSpeed);
} }
void installOpcodes (Interpreter::Interpreter& interpreter) void installOpcodes (Interpreter::Interpreter& interpreter)
@ -698,7 +740,11 @@ namespace MWScript
interpreter.installSegment5 (opcodeGetSquareRoot, new OpGetSquareRoot); interpreter.installSegment5 (opcodeGetSquareRoot, new OpGetSquareRoot);
interpreter.installSegment5 (opcodeFall, new OpFall<ImplicitRef>); interpreter.installSegment5 (opcodeFall, new OpFall<ImplicitRef>);
interpreter.installSegment5 (opcodeFallExplicit, new OpFall<ExplicitRef>); interpreter.installSegment5 (opcodeFallExplicit, new OpFall<ExplicitRef>);
interpreter.installSegment5 (opcodeGetStandingPc, new OpGetStandingPc<ImplicitRef>);
interpreter.installSegment5 (opcodeGetStandingPcExplicit, new OpGetStandingPc<ExplicitRef>);
interpreter.installSegment5 (opcodeGetStandingActor, new OpGetStandingActor<ImplicitRef>);
interpreter.installSegment5 (opcodeGetStandingActorExplicit, new OpGetStandingActor<ExplicitRef>);
interpreter.installSegment5 (opcodeGetWindSpeed, new OpGetWindSpeed);
} }
} }
} }

View file

@ -247,15 +247,15 @@ namespace MWScript
if(axis == "x") if(axis == "x")
{ {
runtime.push(ptr.getRefData().getPosition().pos[0]); runtime.push(ptr.getCellRef().mPos.pos[0]);
} }
else if(axis == "y") else if(axis == "y")
{ {
runtime.push(ptr.getRefData().getPosition().pos[1]); runtime.push(ptr.getCellRef().mPos.pos[1]);
} }
else if(axis == "z") else if(axis == "z")
{ {
runtime.push(ptr.getRefData().getPosition().pos[2]); runtime.push(ptr.getCellRef().mPos.pos[2]);
} }
else else
throw std::runtime_error ("invalid axis: " + axis); throw std::runtime_error ("invalid axis: " + axis);
@ -721,6 +721,8 @@ namespace MWScript
const int opcodeSetPosExplicit = 0x2000193; const int opcodeSetPosExplicit = 0x2000193;
const int opcodeGetStartingPos = 0x2000194; const int opcodeGetStartingPos = 0x2000194;
const int opcodeGetStartingPosExplicit = 0x2000195; const int opcodeGetStartingPosExplicit = 0x2000195;
const int opcodeGetStartingAngle = 0x2000210;
const int opcodeGetStartingAngleExplicit = 0x2000211;
const int opcodePosition = 0x2000196; const int opcodePosition = 0x2000196;
const int opcodePositionExplicit = 0x2000197; const int opcodePositionExplicit = 0x2000197;
const int opcodePositionCell = 0x2000198; const int opcodePositionCell = 0x2000198;
@ -765,6 +767,7 @@ namespace MWScript
extensions.registerInstruction("setatstart","",opcodeSetAtStart,opcodeSetAtStartExplicit); extensions.registerInstruction("setatstart","",opcodeSetAtStart,opcodeSetAtStartExplicit);
extensions.registerInstruction("move","cf",opcodeMove,opcodeMoveExplicit); extensions.registerInstruction("move","cf",opcodeMove,opcodeMoveExplicit);
extensions.registerInstruction("moveworld","cf",opcodeMoveWorld,opcodeMoveWorldExplicit); extensions.registerInstruction("moveworld","cf",opcodeMoveWorld,opcodeMoveWorldExplicit);
extensions.registerFunction("getstartingangle",'f',"c",opcodeGetStartingAngle,opcodeGetStartingAngleExplicit);
} }
void installOpcodes (Interpreter::Interpreter& interpreter) void installOpcodes (Interpreter::Interpreter& interpreter)
@ -804,6 +807,8 @@ namespace MWScript
interpreter.installSegment5(opcodeMoveExplicit,new OpMove<ExplicitRef>); interpreter.installSegment5(opcodeMoveExplicit,new OpMove<ExplicitRef>);
interpreter.installSegment5(opcodeMoveWorld,new OpMoveWorld<ImplicitRef>); interpreter.installSegment5(opcodeMoveWorld,new OpMoveWorld<ImplicitRef>);
interpreter.installSegment5(opcodeMoveWorldExplicit,new OpMoveWorld<ExplicitRef>); interpreter.installSegment5(opcodeMoveWorldExplicit,new OpMoveWorld<ExplicitRef>);
interpreter.installSegment5(opcodeGetStartingAngle, new OpGetStartingAngle<ImplicitRef>);
interpreter.installSegment5(opcodeGetStartingAngleExplicit, new OpGetStartingAngle<ExplicitRef>);
} }
} }
} }

View file

@ -11,11 +11,11 @@ MWWorld::Ptr::CellStore *MWWorld::Cells::getCellStore (const ESM::Cell *cell)
{ {
if (cell->mData.mFlags & ESM::Cell::Interior) if (cell->mData.mFlags & ESM::Cell::Interior)
{ {
std::map<std::string, Ptr::CellStore>::iterator result = mInteriors.find (cell->mName); std::map<std::string, Ptr::CellStore>::iterator result = mInteriors.find (Misc::StringUtils::lowerCase(cell->mName));
if (result==mInteriors.end()) if (result==mInteriors.end())
{ {
result = mInteriors.insert (std::make_pair (cell->mName, Ptr::CellStore (cell))).first; result = mInteriors.insert (std::make_pair (Misc::StringUtils::lowerCase(cell->mName), Ptr::CellStore (cell))).first;
} }
return &result->second; return &result->second;

View file

@ -171,6 +171,25 @@ namespace MWWorld
return ptr; return ptr;
} }
template <class T>
const T *insertStatic(const T &x) {
Store<T> &store = const_cast<Store<T> &>(get<T>());
if (store.search(x.mId) != 0) {
std::ostringstream msg;
msg << "Try to override existing record '" << x.mId << "'";
throw std::runtime_error(msg.str());
}
T record = x;
T *ptr = store.insertStatic(record);
for (iterator it = mStores.begin(); it != mStores.end(); ++it) {
if (it->second == &store) {
mIds[ptr->mId] = it->first;
}
}
return ptr;
}
// This method must be called once, after loading all master/plugin files. This can only be done // This method must be called once, after loading all master/plugin files. This can only be done
// from the outside, so it must be public. // from the outside, so it must be public.
void setUp(); void setUp();

View file

@ -74,15 +74,6 @@ namespace MWWorld
mVariables.insert (std::make_pair (iter->mId, std::make_pair (type, value))); mVariables.insert (std::make_pair (iter->mId, std::make_pair (type, value)));
} }
if (mVariables.find ("dayspassed")==mVariables.end())
{
// vanilla Morrowind does not define dayspassed.
Data value;
value.mLong = 1; // but the addons start counting at 1 :(
mVariables.insert (std::make_pair ("dayspassed", std::make_pair ('l', value)));
}
} }
const Globals::Data& Globals::operator[] (const std::string& name) const const Globals::Data& Globals::operator[] (const std::string& name) const

View file

@ -501,7 +501,7 @@ namespace MWWorld
bool PhysicsSystem::toggleCollisionMode() bool PhysicsSystem::toggleCollisionMode()
{ {
for(std::map<std::string,OEngine::Physic::PhysicActor*>::iterator it = mEngine->PhysicActorMap.begin(); it != mEngine->PhysicActorMap.end();it++) for(std::map<std::string,OEngine::Physic::PhysicActor*>::iterator it = mEngine->mActorMap.begin(); it != mEngine->mActorMap.end();it++)
{ {
if (it->first=="player") if (it->first=="player")
{ {

View file

@ -92,6 +92,7 @@ namespace MWWorld
std::map<std::string, T> mDynamic; std::map<std::string, T> mDynamic;
typedef std::map<std::string, T> Dynamic; typedef std::map<std::string, T> Dynamic;
typedef std::map<std::string, T> Static;
friend class ESMStore; friend class ESMStore;
@ -183,6 +184,20 @@ namespace MWWorld
return ptr; return ptr;
} }
T *insertStatic(const T &item) {
std::string id = Misc::StringUtils::lowerCase(item.mId);
std::pair<typename Static::iterator, bool> result =
mStatic.insert(std::pair<std::string, T>(id, item));
T *ptr = &result.first->second;
if (result.second) {
mShared.push_back(ptr);
} else {
*ptr = item;
}
return ptr;
}
bool eraseStatic(const std::string &id) { bool eraseStatic(const std::string &id) {
T item; T item;
item.mId = Misc::StringUtils::lowerCase(id); item.mId = Misc::StringUtils::lowerCase(id);

View file

@ -65,7 +65,7 @@ WeatherManager::WeatherManager(MWRender::RenderingManager* rendering,MWWorld::Fa
mHour(14), mCurrentWeather("clear"), mFirstUpdate(true), mWeatherUpdateTime(0), mHour(14), mCurrentWeather("clear"), mFirstUpdate(true), mWeatherUpdateTime(0),
mThunderFlash(0), mThunderChance(0), mThunderChanceNeeded(50), mThunderSoundDelay(0), mThunderFlash(0), mThunderChance(0), mThunderChanceNeeded(50), mThunderSoundDelay(0),
mRemainingTransitionTime(0), mMonth(0), mDay(0), mRemainingTransitionTime(0), mMonth(0), mDay(0),
mTimePassed(0), mFallback(fallback) mTimePassed(0), mFallback(fallback), mWindSpeed(0.f)
{ {
mRendering = rendering; mRendering = rendering;
//Globals //Globals
@ -367,6 +367,8 @@ void WeatherManager::update(float duration)
else else
result = getResult(mCurrentWeather); result = getResult(mCurrentWeather);
mWindSpeed = result.mWindSpeed;
mRendering->configureFog(result.mFogDepth, result.mFogColor); mRendering->configureFog(result.mFogDepth, result.mFogColor);
// disable sun during night // disable sun during night
@ -653,3 +655,8 @@ void WeatherManager::changeWeather(const std::string& region, const unsigned int
if (Misc::StringUtils::ciEqual(region, playerRegion)) if (Misc::StringUtils::ciEqual(region, playerRegion))
setWeather(weather); setWeather(weather);
} }
float WeatherManager::getWindSpeed() const
{
return mWindSpeed;
}

View file

@ -131,6 +131,8 @@ namespace MWWorld
void setHour(const float hour); void setHour(const float hour);
float getWindSpeed() const;
void setDate(const int day, const int month); void setDate(const int day, const int month);
void advanceTime(double hours) void advanceTime(double hours)
@ -143,6 +145,7 @@ namespace MWWorld
private: private:
float mHour; float mHour;
int mDay, mMonth; int mDay, mMonth;
float mWindSpeed;
MWWorld::Fallback* mFallback; MWWorld::Fallback* mFallback;
void setFallbackWeather(Weather& weather,const std::string& name); void setFallbackWeather(Weather& weather,const std::string& name);
MWRender::RenderingManager* mRendering; MWRender::RenderingManager* mRendering;

View file

@ -211,6 +211,10 @@ namespace MWWorld
mStore.load (mEsm[idx]); mStore.load (mEsm[idx]);
} }
// insert records that may not be present in all versions of MW
if (mEsm[0].getFormat() == 0)
ensureNeededRecords();
mStore.setUp(); mStore.setUp();
// global variables // global variables
@ -230,6 +234,41 @@ namespace MWWorld
} }
void World::ensureNeededRecords()
{
if (!mStore.get<ESM::GameSetting>().search("sCompanionShare"))
{
ESM::GameSetting sCompanionShare;
sCompanionShare.mId = "sCompanionShare";
ESM::Variant value;
value.setType(ESM::VT_String);
value.setString("Companion Share");
sCompanionShare.mValue = value;
mStore.insertStatic(sCompanionShare);
}
if (!mStore.get<ESM::Global>().search("dayspassed"))
{
// vanilla Morrowind does not define dayspassed.
ESM::Global dayspassed;
dayspassed.mId = "dayspassed";
ESM::Variant value;
value.setType(ESM::VT_Long);
value.setInteger(1); // but the addons start counting at 1 :(
dayspassed.mValue = value;
mStore.insertStatic(dayspassed);
}
if (!mStore.get<ESM::GameSetting>().search("fWereWolfRunMult"))
{
ESM::GameSetting fWereWolfRunMult;
fWereWolfRunMult.mId = "fWereWolfRunMult";
ESM::Variant value;
value.setType(ESM::VT_Float);
value.setFloat(1.f);
fWereWolfRunMult.mValue = value;
mStore.insertStatic(fWereWolfRunMult);
}
}
World::~World() World::~World()
{ {
delete mWeatherManager; delete mWeatherManager;
@ -1583,4 +1622,28 @@ namespace MWWorld
return !mDoorStates[door]; // if currently opening or closing, then do the opposite return !mDoorStates[door]; // if currently opening or closing, then do the opposite
return door.getRefData().getLocalRotation().rot[2] == 0; return door.getRefData().getLocalRotation().rot[2] == 0;
} }
bool World::getPlayerStandingOn (const MWWorld::Ptr& object)
{
MWWorld::Ptr player = mPlayer->getPlayer();
if (!mPhysEngine->getCharacter("player")->getOnGround())
return false;
btVector3 from (player.getRefData().getPosition().pos[0], player.getRefData().getPosition().pos[1], player.getRefData().getPosition().pos[2]);
btVector3 to = from - btVector3(0,0,5);
std::pair<std::string, float> result = mPhysEngine->rayTest(from, to);
return result.first == object.getRefData().getBaseNode()->getName();
}
bool World::getActorStandingOn (const MWWorld::Ptr& object)
{
return mPhysEngine->isAnyActorStandingOn(object.getRefData().getBaseNode()->getName());
}
float World::getWindSpeed()
{
if (isCellExterior() || isCellQuasiExterior())
return mWeatherManager->getWindSpeed();
else
return 0.f;
}
} }

View file

@ -115,9 +115,11 @@ namespace MWWorld
void addContainerScripts(const Ptr& reference, Ptr::CellStore* cell); void addContainerScripts(const Ptr& reference, Ptr::CellStore* cell);
void PCDropped (const Ptr& item); void PCDropped (const Ptr& item);
virtual void processDoors(float duration); void processDoors(float duration);
///< Run physics simulation and modify \a world accordingly. ///< Run physics simulation and modify \a world accordingly.
void ensureNeededRecords();
public: public:
World (OEngine::Render::OgreRenderer& renderer, World (OEngine::Render::OgreRenderer& renderer,
@ -381,6 +383,10 @@ namespace MWWorld
virtual void activateDoor(const MWWorld::Ptr& door); virtual void activateDoor(const MWWorld::Ptr& door);
///< activate (open or close) an non-teleport door ///< activate (open or close) an non-teleport door
virtual bool getPlayerStandingOn (const MWWorld::Ptr& object); ///< @return true if the player is standing on \a object
virtual bool getActorStandingOn (const MWWorld::Ptr& object); ///< @return true if any actor is standing on \a object
virtual float getWindSpeed();
virtual void setupExternalRendering (MWRender::ExternalRendering& rendering); virtual void setupExternalRendering (MWRender::ExternalRendering& rendering);
virtual int canRest(); virtual int canRest();

View file

@ -98,10 +98,12 @@ namespace Compiler
if (type!=' ') if (type!=' ')
{ {
getErrorHandler().error ("catoLowern't re-declare local variable", loc); /// \todo add option to make re-declared local variables an error
getErrorHandler().warning ("can't re-declare local variable", loc);
SkipParser skip (getErrorHandler(), getContext()); SkipParser skip (getErrorHandler(), getContext());
scanner.scan (skip); scanner.scan (skip);
return false; mState = EndState;
return true;
} }
mLocals.declare (mState==ShortState ? 's' : (mState==LongState ? 'l' : 'f'), mLocals.declare (mState==ShortState ? 's' : (mState==LongState ? 'l' : 'f'),

View file

@ -428,7 +428,12 @@ namespace Compiler
if (get (c)) if (get (c))
{ {
if (c=='=') if (c=='=')
{
special = S_cmpLE; special = S_cmpLE;
if (get (c) && c!='=') // <== is a allowed as an alternative to <= :(
putback (c);
}
else else
{ {
putback (c); putback (c);
@ -443,7 +448,12 @@ namespace Compiler
if (get (c)) if (get (c))
{ {
if (c=='=') if (c=='=')
{
special = S_cmpGE; special = S_cmpGE;
if (get (c) && c!='=') // >== is a allowed as an alternative to >= :(
putback (c);
}
else else
{ {
putback (c); putback (c);

View file

@ -16,7 +16,7 @@
<Property key="Caption" value="#{sTransparency_Menu}"/> <Property key="Caption" value="#{sTransparency_Menu}"/>
</Widget> </Widget>
<Widget type="ScrollBar" skin="MW_HScroll" position="4 28 352 18" align="Left Top" name="MenuTransparencySlider"> <Widget type="ScrollBar" skin="MW_HScroll" position="4 28 352 18" align="Left Top" name="MenuTransparencySlider">
<Property key="Range" value="1000000"/> <Property key="Range" value="100"/>
</Widget> </Widget>
<Widget type="TextBox" skin="SandText" position="4 52 352 18" align="Left Top"> <Widget type="TextBox" skin="SandText" position="4 52 352 18" align="Left Top">
<Property key="Caption" value="#{sFull}"/> <Property key="Caption" value="#{sFull}"/>
@ -31,7 +31,7 @@
<Property key="Caption" value="#{sMenu_Help_Delay}"/> <Property key="Caption" value="#{sMenu_Help_Delay}"/>
</Widget> </Widget>
<Widget type="ScrollBar" skin="MW_HScroll" position="4 102 352 18" align="Left Top" name="ToolTipDelaySlider"> <Widget type="ScrollBar" skin="MW_HScroll" position="4 102 352 18" align="Left Top" name="ToolTipDelaySlider">
<Property key="Range" value="1000000"/> <Property key="Range" value="100"/>
</Widget> </Widget>
<Widget type="TextBox" skin="SandText" position="4 126 352 18" align="Left Top"> <Widget type="TextBox" skin="SandText" position="4 126 352 18" align="Left Top">
<Property key="Caption" value="#{sFast}"/> <Property key="Caption" value="#{sFast}"/>
@ -65,35 +65,35 @@
<Property key="Caption" value="#{sMaster}"/> <Property key="Caption" value="#{sMaster}"/>
</Widget> </Widget>
<Widget type="ScrollBar" skin="MW_HScroll" position="4 28 352 18" align="Left Top" name="MasterVolume"> <Widget type="ScrollBar" skin="MW_HScroll" position="4 28 352 18" align="Left Top" name="MasterVolume">
<Property key="Range" value="1000000"/> <Property key="Range" value="100"/>
</Widget> </Widget>
<Widget type="TextBox" skin="NormalText" position="4 54 352 18" align="Left Top"> <Widget type="TextBox" skin="NormalText" position="4 54 352 18" align="Left Top">
<Property key="Caption" value="#{sVoice}"/> <Property key="Caption" value="#{sVoice}"/>
</Widget> </Widget>
<Widget type="ScrollBar" skin="MW_HScroll" position="4 78 352 18" align="Left Top" name="VoiceVolume"> <Widget type="ScrollBar" skin="MW_HScroll" position="4 78 352 18" align="Left Top" name="VoiceVolume">
<Property key="Range" value="1000000"/> <Property key="Range" value="100"/>
</Widget> </Widget>
<Widget type="TextBox" skin="NormalText" position="4 104 352 18" align="Left Top"> <Widget type="TextBox" skin="NormalText" position="4 104 352 18" align="Left Top">
<Property key="Caption" value="#{sEffects}"/> <Property key="Caption" value="#{sEffects}"/>
</Widget> </Widget>
<Widget type="ScrollBar" skin="MW_HScroll" position="4 128 352 18" align="Left Top" name="EffectsVolume"> <Widget type="ScrollBar" skin="MW_HScroll" position="4 128 352 18" align="Left Top" name="EffectsVolume">
<Property key="Range" value="1000000"/> <Property key="Range" value="100"/>
</Widget> </Widget>
<Widget type="TextBox" skin="NormalText" position="4 154 352 18" align="Left Top"> <Widget type="TextBox" skin="NormalText" position="4 154 352 18" align="Left Top">
<Property key="Caption" value="#{sFootsteps}"/> <Property key="Caption" value="#{sFootsteps}"/>
</Widget> </Widget>
<Widget type="ScrollBar" skin="MW_HScroll" position="4 178 352 18" align="Left Top" name="FootstepsVolume"> <Widget type="ScrollBar" skin="MW_HScroll" position="4 178 352 18" align="Left Top" name="FootstepsVolume">
<Property key="Range" value="1000000"/> <Property key="Range" value="100"/>
</Widget> </Widget>
<Widget type="TextBox" skin="NormalText" position="4 204 352 18" align="Left Top"> <Widget type="TextBox" skin="NormalText" position="4 204 352 18" align="Left Top">
<Property key="Caption" value="#{sMusic}"/> <Property key="Caption" value="#{sMusic}"/>
</Widget> </Widget>
<Widget type="ScrollBar" skin="MW_HScroll" position="4 228 352 18" align="Left Top" name="MusicVolume"> <Widget type="ScrollBar" skin="MW_HScroll" position="4 228 352 18" align="Left Top" name="MusicVolume">
<Property key="Range" value="1000000"/> <Property key="Range" value="100"/>
</Widget> </Widget>
</Widget> </Widget>
<Widget type="TabItem" skin="" position="4 28 360 312"> <Widget type="TabItem" skin="" position="4 28 360 312">
@ -118,7 +118,7 @@
<Property key="Caption" value="UI cursor sensitivity"/> <Property key="Caption" value="UI cursor sensitivity"/>
</Widget> </Widget>
<Widget type="ScrollBar" skin="MW_HScroll" position="4 252 160 18" align="Left Top" name="UISensitivitySlider"> <Widget type="ScrollBar" skin="MW_HScroll" position="4 252 160 18" align="Left Top" name="UISensitivitySlider">
<Property key="Range" value="1000000"/> <Property key="Range" value="100"/>
</Widget> </Widget>
<Widget type="TextBox" skin="SandText" position="4 276 160 18" align="Left Top"> <Widget type="TextBox" skin="SandText" position="4 276 160 18" align="Left Top">
<Property key="Caption" value="#{sLow}"/> <Property key="Caption" value="#{sLow}"/>
@ -134,7 +134,7 @@
<Property key="Caption" value="Camera sensitivity"/> <Property key="Caption" value="Camera sensitivity"/>
</Widget> </Widget>
<Widget type="ScrollBar" skin="MW_HScroll" position="180 252 160 18" align="Left Top" name="CameraSensitivitySlider"> <Widget type="ScrollBar" skin="MW_HScroll" position="180 252 160 18" align="Left Top" name="CameraSensitivitySlider">
<Property key="Range" value="1000000"/> <Property key="Range" value="100"/>
</Widget> </Widget>
<Widget type="TextBox" skin="SandText" position="180 276 160 18" align="Left Top"> <Widget type="TextBox" skin="SandText" position="180 276 160 18" align="Left Top">
<Property key="Caption" value="#{sLow}"/> <Property key="Caption" value="#{sLow}"/>
@ -199,7 +199,7 @@
<Property key="Caption" value="Field of View"/> <Property key="Caption" value="Field of View"/>
</Widget> </Widget>
<Widget type="ScrollBar" skin="MW_HScroll" position="4 222 329 18" align="Left Top" name="FOVSlider"> <Widget type="ScrollBar" skin="MW_HScroll" position="4 222 329 18" align="Left Top" name="FOVSlider">
<Property key="Range" value="1000000"/> <Property key="Range" value="100"/>
</Widget> </Widget>
<Widget type="TextBox" skin="SandText" position="4 246 329 18" align="Left Top"> <Widget type="TextBox" skin="SandText" position="4 246 329 18" align="Left Top">
<Property key="Caption" value="#{sLow}"/> <Property key="Caption" value="#{sLow}"/>
@ -224,7 +224,7 @@
<Property key="Caption" value="Anisotropy"/> <Property key="Caption" value="Anisotropy"/>
</Widget> </Widget>
<Widget type="ScrollBar" skin="MW_HScroll" position="0 28 150 18" align="Left Top" name="AnisotropySlider"> <Widget type="ScrollBar" skin="MW_HScroll" position="0 28 150 18" align="Left Top" name="AnisotropySlider">
<Property key="Range" value="1000000"/> <Property key="Range" value="100"/>
</Widget> </Widget>
</Widget> </Widget>
@ -232,7 +232,7 @@
<Property key="Caption" value="#{sRender_Distance}"/> <Property key="Caption" value="#{sRender_Distance}"/>
</Widget> </Widget>
<Widget type="ScrollBar" skin="MW_HScroll" position="4 154 322 18" align="Left Top" name="ViewDistanceSlider"> <Widget type="ScrollBar" skin="MW_HScroll" position="4 154 322 18" align="Left Top" name="ViewDistanceSlider">
<Property key="Range" value="1000000"/> <Property key="Range" value="100"/>
</Widget> </Widget>
<Widget type="TextBox" skin="SandText" position="4 178 332 18" align="Left Top"> <Widget type="TextBox" skin="SandText" position="4 178 332 18" align="Left Top">
<Property key="Caption" value="#{sNear}"/> <Property key="Caption" value="#{sNear}"/>

View file

@ -267,8 +267,8 @@ namespace Physic
} }
} }
PhysicActorContainer::iterator pa_it = PhysicActorMap.begin(); PhysicActorContainer::iterator pa_it = mActorMap.begin();
for (; pa_it != PhysicActorMap.end(); ++pa_it) for (; pa_it != mActorMap.end(); ++pa_it)
{ {
if (pa_it->second != NULL) if (pa_it->second != NULL)
{ {
@ -567,13 +567,13 @@ namespace Physic
//dynamicsWorld->addAction( newActor->mCharacter ); //dynamicsWorld->addAction( newActor->mCharacter );
PhysicActorMap[name] = newActor; mActorMap[name] = newActor;
} }
void PhysicEngine::removeCharacter(const std::string &name) void PhysicEngine::removeCharacter(const std::string &name)
{ {
PhysicActorContainer::iterator it = PhysicActorMap.find(name); PhysicActorContainer::iterator it = mActorMap.find(name);
if (it != PhysicActorMap.end() ) if (it != mActorMap.end() )
{ {
PhysicActor* act = it->second; PhysicActor* act = it->second;
if(act != NULL) if(act != NULL)
@ -581,16 +581,16 @@ namespace Physic
delete act; delete act;
} }
PhysicActorMap.erase(it); mActorMap.erase(it);
} }
} }
PhysicActor* PhysicEngine::getCharacter(const std::string &name) PhysicActor* PhysicEngine::getCharacter(const std::string &name)
{ {
PhysicActorContainer::iterator it = PhysicActorMap.find(name); PhysicActorContainer::iterator it = mActorMap.find(name);
if (it != PhysicActorMap.end() ) if (it != mActorMap.end() )
{ {
PhysicActor* act = PhysicActorMap[name]; PhysicActor* act = mActorMap[name];
return act; return act;
} }
else else
@ -700,4 +700,22 @@ namespace Physic
max = btVector3(0,0,0); max = btVector3(0,0,0);
} }
} }
}}
bool PhysicEngine::isAnyActorStandingOn (const std::string& objectName)
{
for (PhysicActorContainer::iterator it = mActorMap.begin(); it != mActorMap.end(); ++it)
{
if (!it->second->getOnGround())
continue;
Ogre::Vector3 pos = it->second->getPosition();
btVector3 from (pos.x, pos.y, pos.z);
btVector3 to = from - btVector3(0,0,5);
std::pair<std::string, float> result = rayTest(from, to);
if (result.first == objectName)
return true;
}
return false;
}
}
}

View file

@ -288,6 +288,8 @@ namespace Physic
void setSceneManager(Ogre::SceneManager* sceneMgr); void setSceneManager(Ogre::SceneManager* sceneMgr);
bool isAnyActorStandingOn (const std::string& objectName);
/** /**
* Return the closest object hit by a ray. If there are no objects, it will return ("",-1). * Return the closest object hit by a ray. If there are no objects, it will return ("",-1).
*/ */
@ -329,7 +331,7 @@ namespace Physic
RigidBodyContainer mRaycastingObjectMap; RigidBodyContainer mRaycastingObjectMap;
typedef std::map<std::string, PhysicActor*> PhysicActorContainer; typedef std::map<std::string, PhysicActor*> PhysicActorContainer;
PhysicActorContainer PhysicActorMap; PhysicActorContainer mActorMap;
Ogre::SceneManager* mSceneMgr; Ogre::SceneManager* mSceneMgr;