prepared InterpreterContext for activation implementation

pull/7/head
Marc Zinnschlag 15 years ago
parent 052d049a6c
commit 7ba6bdb56c

@ -50,7 +50,8 @@ namespace MWScript
InterpreterContext::InterpreterContext (MWWorld::Environment& environment, InterpreterContext::InterpreterContext (MWWorld::Environment& environment,
MWScript::Locals *locals, MWWorld::Ptr reference) MWScript::Locals *locals, MWWorld::Ptr reference)
: mEnvironment (environment), mLocals (locals), mReference (reference) : mEnvironment (environment), mLocals (locals), mReference (reference),
mActivationHandled (false)
{} {}
int InterpreterContext::getLocalShort (int index) const int InterpreterContext::getLocalShort (int index) const
@ -197,11 +198,46 @@ namespace MWScript
return std::sqrt (diff[0]*diff[0] + diff[1]*diff[1] + diff[2]*diff[2]); return std::sqrt (diff[0]*diff[0] + diff[1]*diff[1] + diff[2]*diff[2]);
} }
bool InterpreterContext::hasBeenActivated() const bool InterpreterContext::hasBeenActivated (const MWWorld::Ptr& ptr)
{ {
if (!mActivated.isEmpty() && mActivated==ptr)
{
mActivationHandled = true;
return true;
}
return false; return false;
} }
bool InterpreterContext::hasActivationBeenHandled() const
{
return mActivationHandled;
}
void InterpreterContext::activate (const MWWorld::Ptr& ptr,
boost::shared_ptr<MWWorld::Action> action)
{
mActivated = ptr;
mActivationHandled = false;
mAction = action;
}
void InterpreterContext::executeActivation()
{
if (!mAction.get())
throw std::runtime_error ("activation failed, because no action to perform");
mAction->execute (mEnvironment);
mActivationHandled = true;
}
void InterpreterContext::clearActivation()
{
mActivated = MWWorld::Ptr();
mActivationHandled = false;
mAction.reset();
}
float InterpreterContext::getSecondsPassed() const float InterpreterContext::getSecondsPassed() const
{ {
return mEnvironment.mFrameDuration; return mEnvironment.mFrameDuration;
@ -245,4 +281,3 @@ namespace MWScript
return getReference ("", true); return getReference ("", true);
} }
} }

@ -1,11 +1,14 @@
#ifndef GAME_SCRIPT_INTERPRETERCONTEXT_H #ifndef GAME_SCRIPT_INTERPRETERCONTEXT_H
#define GAME_SCRIPT_INTERPRETERCONTEXT_H #define GAME_SCRIPT_INTERPRETERCONTEXT_H
#include <boost/shared_ptr.hpp>
#include <components/interpreter/context.hpp> #include <components/interpreter/context.hpp>
#include "../mwworld/ptr.hpp" #include "../mwworld/ptr.hpp"
#include "../mwworld/environment.hpp" #include "../mwworld/environment.hpp"
#include "../mwworld/world.hpp" #include "../mwworld/world.hpp"
#include "../mwworld/action.hpp"
namespace MWSound namespace MWSound
{ {
@ -22,6 +25,9 @@ namespace MWScript
Locals *mLocals; Locals *mLocals;
MWWorld::Ptr mReference; MWWorld::Ptr mReference;
MWWorld::Ptr mActivated;
bool mActivationHandled;
boost::shared_ptr<MWWorld::Action> mAction;
MWWorld::Ptr getReference (const std::string& id, bool activeOnly); MWWorld::Ptr getReference (const std::string& id, bool activeOnly);
@ -70,7 +76,21 @@ namespace MWScript
virtual float getDistance (const std::string& name, const std::string& id = "") const; virtual float getDistance (const std::string& name, const std::string& id = "") const;
virtual bool hasBeenActivated() const; bool hasBeenActivated (const MWWorld::Ptr& ptr);
///< \attention Calling this function for the right reference will mark the action as
/// been handled.
bool hasActivationBeenHandled() const;
void activate (const MWWorld::Ptr& ptr, boost::shared_ptr<MWWorld::Action> action);
///< Store reference acted upon and action. The actual execution of the action does not
/// take place here.
void executeActivation();
///< Execute the action defined by the last activate call.
void clearActivation();
///< Discard the action defined by the last activate call.
virtual float getSecondsPassed() const; virtual float getSecondsPassed() const;
@ -92,5 +112,3 @@ namespace MWScript
} }
#endif #endif

@ -29,8 +29,12 @@ namespace MWScript
virtual void execute (Interpreter::Runtime& runtime) virtual void execute (Interpreter::Runtime& runtime)
{ {
runtime.push (static_cast<InterpreterContext&> ( InterpreterContext& context =
runtime.getContext()).hasBeenActivated()); static_cast<InterpreterContext&> (runtime.getContext());
MWWorld::Ptr ptr = context.getReference();
runtime.push (context.hasBeenActivated (ptr));
} }
}; };

Loading…
Cancel
Save