forked from mirror/openmw-tes3mp
added Enable, Disable, GetDisabled
This commit is contained in:
parent
4ecb63203b
commit
592fa84e2d
22 changed files with 310 additions and 12 deletions
|
@ -120,6 +120,15 @@ namespace SAInterpreter
|
|||
return 0;
|
||||
}
|
||||
|
||||
bool Context::isDisabled() const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
void Context::enable() {}
|
||||
|
||||
void Context::disable() {}
|
||||
|
||||
void Context::report()
|
||||
{
|
||||
std::size_t i = 0;
|
||||
|
|
|
@ -62,6 +62,12 @@ namespace SAInterpreter
|
|||
|
||||
virtual float getSecondsPassed() const;
|
||||
|
||||
virtual bool isDisabled() const;
|
||||
|
||||
virtual void enable();
|
||||
|
||||
virtual void disable();
|
||||
|
||||
void report();
|
||||
///< Write state to std::cout
|
||||
};
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
#ifndef GAME_RENDER_CELL_H
|
||||
#define GAME_RENDER_CELL_H
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace MWRender
|
||||
{
|
||||
class CellRender
|
||||
|
@ -15,6 +17,12 @@ namespace MWRender
|
|||
/// Remove the cell from rendering, but don't remove it from
|
||||
/// memory.
|
||||
virtual void hide() = 0;
|
||||
|
||||
/// Make the reference with the given handle visible.
|
||||
virtual void enable (const std::string& handle) = 0;
|
||||
|
||||
/// Make the reference with the given handle invisible.
|
||||
virtual void disable (const std::string& handle) = 0;
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -13,7 +13,7 @@ void insertObj(CellRenderImp& cellRender, T& liveRef)
|
|||
{
|
||||
cellRender.insertBegin (liveRef.ref);
|
||||
cellRender.insertMesh ("meshes\\" + model);
|
||||
liveRef.mData.setHandle (cellRender.insertEnd());
|
||||
liveRef.mData.setHandle (cellRender.insertEnd (liveRef.mData.isEnabled()));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -36,7 +36,7 @@ void insertObj(CellRenderImp& cellRender, ESMS::LiveCellRef<ESM::Light, MWWorld:
|
|||
const float radius = float(liveRef.base->data.radius);
|
||||
cellRender.insertLight(r, g, b, radius);
|
||||
|
||||
liveRef.mData.setHandle (cellRender.insertEnd());
|
||||
liveRef.mData.setHandle (cellRender.insertEnd (liveRef.mData.isEnabled()));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -33,7 +33,7 @@ namespace MWRender
|
|||
virtual void insertLight(float r, float g, float b, float radius) = 0;
|
||||
|
||||
/// finish inserting a new reference and return a handle to it.
|
||||
virtual std::string insertEnd() = 0;
|
||||
virtual std::string insertEnd (bool Enable) = 0;
|
||||
|
||||
void insertCell(ESMS::CellStore<MWWorld::RefData> &cell);
|
||||
|
||||
|
|
|
@ -103,12 +103,15 @@ void InteriorCellRender::insertLight(float r, float g, float b, float radius)
|
|||
|
||||
// finish inserting a new reference and return a handle to it.
|
||||
|
||||
std::string InteriorCellRender::insertEnd()
|
||||
std::string InteriorCellRender::insertEnd (bool enable)
|
||||
{
|
||||
assert (insert);
|
||||
|
||||
std::string handle = insert->getName();
|
||||
|
||||
if (!enable)
|
||||
insert->setVisible (false);
|
||||
|
||||
insert = 0;
|
||||
|
||||
return handle;
|
||||
|
@ -219,6 +222,18 @@ void InteriorCellRender::toggleLight()
|
|||
setAmbientMode();
|
||||
}
|
||||
|
||||
void InteriorCellRender::enable (const std::string& handle)
|
||||
{
|
||||
if (!handle.empty())
|
||||
scene.getMgr()->getSceneNode (handle)->setVisible (true);
|
||||
}
|
||||
|
||||
void InteriorCellRender::disable (const std::string& handle)
|
||||
{
|
||||
if (!handle.empty())
|
||||
scene.getMgr()->getSceneNode (handle)->setVisible (false);
|
||||
}
|
||||
|
||||
// Magic function from the internets. Might need this later.
|
||||
/*
|
||||
void Scene::DestroyAllAttachedMovableObjects( SceneNode* i_pSceneNode )
|
||||
|
|
|
@ -66,7 +66,7 @@ namespace MWRender
|
|||
virtual void insertLight(float r, float g, float b, float radius);
|
||||
|
||||
/// finish inserting a new reference and return a handle to it.
|
||||
virtual std::string insertEnd();
|
||||
virtual std::string insertEnd (bool Enable);
|
||||
|
||||
/// configure lighting according to cell
|
||||
void configureAmbient();
|
||||
|
@ -88,13 +88,19 @@ namespace MWRender
|
|||
|
||||
/// Remove the cell from rendering, but don't remove it from
|
||||
/// memory.
|
||||
void hide();
|
||||
virtual void hide();
|
||||
|
||||
/// Destroy all rendering objects connected with this cell.
|
||||
void destroy(); // comment by Zini: shouldn't this go into the destructor?
|
||||
|
||||
/// Switch through lighting modes.
|
||||
void toggleLight();
|
||||
|
||||
/// Make the reference with the given handle visible.
|
||||
virtual void enable (const std::string& handle);
|
||||
|
||||
/// Make the reference with the given handle invisible.
|
||||
virtual void disable (const std::string& handle);
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -166,6 +166,36 @@ namespace MWScript
|
|||
return mEnvironment.mFrameDuration;
|
||||
}
|
||||
|
||||
bool InterpreterContext::isDisabled() const
|
||||
{
|
||||
if (mReference.isEmpty())
|
||||
throw std::runtime_error ("no implicit reference");
|
||||
|
||||
return !mReference.getRefData().isEnabled();
|
||||
}
|
||||
|
||||
void InterpreterContext::enable()
|
||||
{
|
||||
if (mReference.isEmpty())
|
||||
throw std::runtime_error ("no implicit reference");
|
||||
|
||||
std::pair<MWWorld::Ptr, MWWorld::World::CellStore *> ref
|
||||
(mReference, mEnvironment.mWorld->find (mReference));
|
||||
|
||||
mEnvironment.mWorld->enable (ref);
|
||||
}
|
||||
|
||||
void InterpreterContext::disable()
|
||||
{
|
||||
if (mReference.isEmpty())
|
||||
throw std::runtime_error ("no implicit reference");
|
||||
|
||||
std::pair<MWWorld::Ptr, MWWorld::World::CellStore *> ref
|
||||
(mReference, mEnvironment.mWorld->find (mReference));
|
||||
|
||||
mEnvironment.mWorld->disable (ref);
|
||||
}
|
||||
|
||||
MWGui::GuiManager& InterpreterContext::getGuiManager()
|
||||
{
|
||||
return *mEnvironment.mGuiManager;
|
||||
|
|
|
@ -73,6 +73,12 @@ namespace MWScript
|
|||
|
||||
virtual float getSecondsPassed() const;
|
||||
|
||||
virtual bool isDisabled() const;
|
||||
|
||||
virtual void enable();
|
||||
|
||||
virtual void disable();
|
||||
|
||||
MWWorld::World& getWorld();
|
||||
|
||||
MWSound::SoundManager& getSoundManager();
|
||||
|
|
|
@ -20,10 +20,11 @@ namespace MWWorld
|
|||
// object in the refdata of refs without a script,
|
||||
// we can make this a pointer later.
|
||||
bool mHasLocals;
|
||||
bool mEnabled;
|
||||
|
||||
public:
|
||||
|
||||
RefData() : mHasLocals (false) {}
|
||||
RefData() : mHasLocals (false), mEnabled (true) {}
|
||||
|
||||
std::string getHandle()
|
||||
{
|
||||
|
@ -48,6 +49,21 @@ namespace MWWorld
|
|||
{
|
||||
return mLocals;
|
||||
}
|
||||
|
||||
bool isEnabled() const
|
||||
{
|
||||
return mEnabled;
|
||||
}
|
||||
|
||||
void enable()
|
||||
{
|
||||
mEnabled = true;
|
||||
}
|
||||
|
||||
void disable()
|
||||
{
|
||||
mEnabled = true;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -9,6 +9,8 @@
|
|||
#include "apps/openmw/mwrender/sky.hpp"
|
||||
#include "apps/openmw/mwrender/interior.hpp"
|
||||
|
||||
#include "ptr.hpp"
|
||||
|
||||
namespace
|
||||
{
|
||||
template<typename T>
|
||||
|
@ -31,6 +33,20 @@ namespace
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
bool hasReference (ESMS::CellRefList<T, MWWorld::RefData>& cellRefList, const MWWorld::Ptr& ptr)
|
||||
{
|
||||
for (typename ESMS::CellRefList<T, MWWorld::RefData>::List::iterator iter (
|
||||
cellRefList.list.begin());
|
||||
iter!=cellRefList.list.end(); ++iter)
|
||||
{
|
||||
if (&iter->mData==&ptr.getRefData())
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
namespace MWWorld
|
||||
|
@ -121,6 +137,24 @@ namespace MWWorld
|
|||
return Ptr();
|
||||
}
|
||||
|
||||
MWRender::CellRender *World::searchRender (CellStore *store)
|
||||
{
|
||||
CellRenderCollection::iterator iter = mActiveCells.find (store);
|
||||
|
||||
if (iter!=mActiveCells.end())
|
||||
{
|
||||
return iter->second;
|
||||
}
|
||||
else
|
||||
{
|
||||
iter = mBufferedCells.find (store);
|
||||
if (iter!=mBufferedCells.end())
|
||||
return iter->second;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
World::World (Render::OgreRenderer& renderer, const boost::filesystem::path& dataDir,
|
||||
const std::string& master, const std::string& startCell, bool newGame)
|
||||
: mSkyManager (0), mScene (renderer), mPlayerPos (0)
|
||||
|
@ -245,4 +279,59 @@ namespace MWWorld
|
|||
|
||||
throw std::runtime_error ("unknown ID: " + name);
|
||||
}
|
||||
|
||||
void World::enable (std::pair<Ptr, CellStore *>& reference)
|
||||
{
|
||||
if (!reference.first.getRefData().isEnabled())
|
||||
{
|
||||
reference.first.getRefData().enable();
|
||||
|
||||
if (MWRender::CellRender *render = searchRender (reference.second))
|
||||
{
|
||||
render->enable (reference.first.getRefData().getHandle());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void World::disable (std::pair<Ptr, CellStore *>& reference)
|
||||
{
|
||||
if (!reference.first.getRefData().isEnabled())
|
||||
{
|
||||
reference.first.getRefData().enable();
|
||||
|
||||
if (MWRender::CellRender *render = searchRender (reference.second))
|
||||
{
|
||||
render->disable (reference.first.getRefData().getHandle());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
World::CellStore *World::find (const Ptr& ptr)
|
||||
{
|
||||
for (CellRenderCollection::iterator iter (mActiveCells.begin()); iter!=mActiveCells.end();
|
||||
++iter)
|
||||
{
|
||||
if (
|
||||
hasReference (iter->first->activators, ptr) ||
|
||||
hasReference (iter->first->potions, ptr) ||
|
||||
hasReference (iter->first->appas, ptr) ||
|
||||
hasReference (iter->first->armors, ptr) ||
|
||||
hasReference (iter->first->books, ptr) ||
|
||||
hasReference (iter->first->clothes, ptr) ||
|
||||
hasReference (iter->first->containers, ptr) ||
|
||||
hasReference (iter->first->creatures, ptr) ||
|
||||
hasReference (iter->first->doors, ptr) ||
|
||||
hasReference (iter->first->ingreds, ptr) ||
|
||||
hasReference (iter->first->lights, ptr) ||
|
||||
hasReference (iter->first->lockpicks, ptr) ||
|
||||
hasReference (iter->first->miscItems, ptr) ||
|
||||
hasReference (iter->first->npcs, ptr) ||
|
||||
hasReference (iter->first->probes, ptr) ||
|
||||
hasReference (iter->first->repairs, ptr) ||
|
||||
hasReference (iter->first->weapons, ptr))
|
||||
return iter->first;
|
||||
}
|
||||
|
||||
throw std::runtime_error ("failed to locate reference in active cell");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -61,6 +61,8 @@ namespace MWWorld
|
|||
|
||||
Ptr getPtr (const std::string& name, CellStore& cellStore);
|
||||
|
||||
MWRender::CellRender *searchRender (CellStore *store);
|
||||
|
||||
public:
|
||||
|
||||
World (Render::OgreRenderer& renderer, const boost::filesystem::path& master,
|
||||
|
@ -83,6 +85,13 @@ namespace MWWorld
|
|||
std::pair<Ptr, CellStore *> getPtr (const std::string& name, bool activeOnly);
|
||||
///< Return a pointer to a liveCellRef with the given name.
|
||||
/// \param activeOnly do non search inactive cells.
|
||||
|
||||
void enable (std::pair<Ptr, CellStore *>& reference);
|
||||
|
||||
void disable (std::pair<Ptr, CellStore *>& reference);
|
||||
|
||||
CellStore *find (const Ptr& ptr);
|
||||
///< Only active cells are searched.
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -346,7 +346,17 @@ namespace Compiler
|
|||
|
||||
mNextOperand = false;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else if (keyword==Scanner::K_getdisabled)
|
||||
{
|
||||
mTokenLoc = loc;
|
||||
|
||||
Generator::getDisabled (mCode);
|
||||
mOperands.push_back ('l');
|
||||
|
||||
mNextOperand = false;
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
// check for custom extensions
|
||||
|
|
|
@ -284,6 +284,22 @@ namespace
|
|||
{
|
||||
code.push_back (Compiler::Generator::segment5 (50));
|
||||
}
|
||||
|
||||
void opEnable (Compiler::Generator::CodeContainer& code)
|
||||
{
|
||||
code.push_back (Compiler::Generator::segment5 (51));
|
||||
}
|
||||
|
||||
void opDisable (Compiler::Generator::CodeContainer& code)
|
||||
{
|
||||
code.push_back (Compiler::Generator::segment5 (52));
|
||||
}
|
||||
|
||||
void opGetDisabled (Compiler::Generator::CodeContainer& code)
|
||||
{
|
||||
code.push_back (Compiler::Generator::segment5 (53));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
namespace Compiler
|
||||
|
@ -685,6 +701,21 @@ namespace Compiler
|
|||
{
|
||||
opGetSecondsPassed (code);
|
||||
}
|
||||
|
||||
void getDisabled (CodeContainer& code)
|
||||
{
|
||||
opGetDisabled (code);
|
||||
}
|
||||
|
||||
void enable (CodeContainer& code)
|
||||
{
|
||||
opEnable (code);
|
||||
}
|
||||
|
||||
void disable (CodeContainer& code)
|
||||
{
|
||||
opDisable (code);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -110,6 +110,12 @@ namespace Compiler
|
|||
void getDistance (CodeContainer& code);
|
||||
|
||||
void getSecondsPassed (CodeContainer& code);
|
||||
|
||||
void getDisabled (CodeContainer& code);
|
||||
|
||||
void enable (CodeContainer& code);
|
||||
|
||||
void disable (CodeContainer& code);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -162,7 +162,19 @@ namespace Compiler
|
|||
mExprParser.parseArguments ("c", scanner, mCode, true);
|
||||
Generator::stopScript (mCode);
|
||||
mState = EndState;
|
||||
return true;
|
||||
return true;
|
||||
|
||||
case Scanner::K_enable:
|
||||
|
||||
Generator::enable (mCode);
|
||||
mState = EndState;
|
||||
return true;
|
||||
|
||||
case Scanner::K_disable:
|
||||
|
||||
Generator::disable (mCode);
|
||||
mState = EndState;
|
||||
return true;
|
||||
}
|
||||
|
||||
// check for custom extensions
|
||||
|
|
|
@ -247,6 +247,7 @@ namespace Compiler
|
|||
"startscript", "stopscript", "scriptrunning",
|
||||
"getdistance",
|
||||
"getsecondspassed",
|
||||
"enable", "disable", "getdisabled",
|
||||
0
|
||||
};
|
||||
|
||||
|
|
|
@ -53,7 +53,8 @@ namespace Compiler
|
|||
K_random,
|
||||
K_startscript, K_stopscript, K_scriptrunning,
|
||||
K_getdistance,
|
||||
K_getsecondspassed
|
||||
K_getsecondspassed,
|
||||
K_enable, K_disable, K_getdisabled
|
||||
};
|
||||
|
||||
enum special
|
||||
|
|
|
@ -55,7 +55,13 @@ namespace Interpreter
|
|||
|
||||
virtual float getDistance (const std::string& name) const = 0;
|
||||
|
||||
virtual float getSecondsPassed() const = 0;
|
||||
virtual float getSecondsPassed() const = 0;
|
||||
|
||||
virtual bool isDisabled() const = 0;
|
||||
|
||||
virtual void enable() = 0;
|
||||
|
||||
virtual void disable() = 0;
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -109,6 +109,9 @@ op 47: start script stack[0] and pop
|
|||
op 48: stop script stack[0] and pop
|
||||
op 49: replace stack[0] with distance between implicit reference and a reference of ID stack[0]
|
||||
op 50: push frame duration (float)
|
||||
opcodes 51-33554431 unused
|
||||
op 51: enable implicit reference
|
||||
op 52: disable implicit reference
|
||||
op 53: push 1, if implicit reference is disabled, 0 else
|
||||
opcodes 54-33554431 unused
|
||||
opcodes 33554432-67108863 reserved for extensions
|
||||
|
||||
|
|
|
@ -89,6 +89,9 @@ namespace Interpreter
|
|||
interpreter.installSegment5 (38, new OpMenuMode);
|
||||
interpreter.installSegment5 (45, new OpRandom);
|
||||
interpreter.installSegment5 (50, new OpGetSecondsPassed);
|
||||
interpreter.installSegment5 (51, new OpEnable);
|
||||
interpreter.installSegment5 (52, new OpDisable);
|
||||
interpreter.installSegment5 (53, new OpGetDisabled);
|
||||
|
||||
// script control
|
||||
interpreter.installSegment5 (46, new OpScriptRunning);
|
||||
|
|
|
@ -130,6 +130,37 @@ namespace Interpreter
|
|||
runtime.push (*reinterpret_cast<Type_Data *> (&duration));
|
||||
}
|
||||
};
|
||||
|
||||
class OpEnable : public Opcode0
|
||||
{
|
||||
public:
|
||||
|
||||
virtual void execute (Runtime& runtime)
|
||||
{
|
||||
runtime.getContext().enable();
|
||||
}
|
||||
};
|
||||
|
||||
class OpDisable : public Opcode0
|
||||
{
|
||||
public:
|
||||
|
||||
virtual void execute (Runtime& runtime)
|
||||
{
|
||||
runtime.getContext().disable();
|
||||
}
|
||||
};
|
||||
|
||||
class OpGetDisabled : public Opcode0
|
||||
{
|
||||
public:
|
||||
|
||||
virtual void execute (Runtime& runtime)
|
||||
{
|
||||
runtime.push (runtime.getContext().isDisabled());
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in a new issue