forked from teamnwah/openmw-tes3coop
implemented getdistance with explicit references
This commit is contained in:
parent
c37b007be0
commit
69e607e140
11 changed files with 65 additions and 16 deletions
|
@ -110,7 +110,7 @@ namespace SAInterpreter
|
||||||
|
|
||||||
void Context::stopScript (const std::string& name) {}
|
void Context::stopScript (const std::string& name) {}
|
||||||
|
|
||||||
float Context::getDistance (const std::string& name) const
|
float Context::getDistance (const std::string& name, const std::string& id) const
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -58,7 +58,7 @@ namespace SAInterpreter
|
||||||
|
|
||||||
virtual void stopScript (const std::string& name);
|
virtual void stopScript (const std::string& name);
|
||||||
|
|
||||||
virtual float getDistance (const std::string& name) const;
|
virtual float getDistance (const std::string& name, const std::string& id = "") const;
|
||||||
|
|
||||||
virtual float getSecondsPassed() const;
|
virtual float getSecondsPassed() const;
|
||||||
|
|
||||||
|
|
|
@ -176,18 +176,18 @@ namespace MWScript
|
||||||
mEnvironment.mGlobalScripts->removeScript (name);
|
mEnvironment.mGlobalScripts->removeScript (name);
|
||||||
}
|
}
|
||||||
|
|
||||||
float InterpreterContext::getDistance (const std::string& name) const
|
float InterpreterContext::getDistance (const std::string& name, const std::string& id) const
|
||||||
{
|
{
|
||||||
if (mReference.isEmpty())
|
// TODO handle exterior cells (when ref and ref2 are located in different cells)
|
||||||
throw std::runtime_error ("no implicit reference");
|
CPtrWithCell ref2 = getReference (id, false);
|
||||||
|
|
||||||
std::pair<MWWorld::Ptr, MWWorld::World::CellStore *> ref =
|
std::pair<MWWorld::Ptr, MWWorld::World::CellStore *> ref =
|
||||||
mEnvironment.mWorld->getPtr (name, true);
|
mEnvironment.mWorld->getPtr (name, true);
|
||||||
|
|
||||||
double diff[3];
|
double diff[3];
|
||||||
|
|
||||||
for (int i=0; i<3; ++i)
|
for (int i=0; i<3; ++i)
|
||||||
diff[i] = ref.first.getCellRef().pos.pos[i] - mReference.getCellRef().pos.pos[i];
|
diff[i] = ref.first.getCellRef().pos.pos[i] - ref2.first.getCellRef().pos.pos[i];
|
||||||
|
|
||||||
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]);
|
||||||
}
|
}
|
||||||
|
|
|
@ -70,7 +70,7 @@ namespace MWScript
|
||||||
|
|
||||||
virtual void stopScript (const std::string& name);
|
virtual void stopScript (const std::string& name);
|
||||||
|
|
||||||
virtual float getDistance (const std::string& name) const;
|
virtual float getDistance (const std::string& name, const std::string& id = "") const;
|
||||||
|
|
||||||
virtual bool hasBeenActivated() const;
|
virtual bool hasBeenActivated() const;
|
||||||
|
|
||||||
|
|
|
@ -311,6 +311,19 @@ namespace Compiler
|
||||||
mNextOperand = false;
|
mNextOperand = false;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
else if (keyword==Scanner::K_getdistance)
|
||||||
|
{
|
||||||
|
mTokenLoc = loc;
|
||||||
|
parseArguments ("c", scanner);
|
||||||
|
|
||||||
|
Generator::getDistance (mCode, mLiterals, mExplicit);
|
||||||
|
mOperands.push_back ('f');
|
||||||
|
mExplicit.clear();
|
||||||
|
mRefOp = false;
|
||||||
|
|
||||||
|
mNextOperand = false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return Parser::parseKeyword (keyword, loc, scanner);
|
return Parser::parseKeyword (keyword, loc, scanner);
|
||||||
|
@ -360,18 +373,18 @@ namespace Compiler
|
||||||
|
|
||||||
mNextOperand = false;
|
mNextOperand = false;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else if (keyword==Scanner::K_getdistance)
|
else if (keyword==Scanner::K_getdistance)
|
||||||
{
|
{
|
||||||
mTokenLoc = loc;
|
mTokenLoc = loc;
|
||||||
parseArguments ("c", scanner);
|
parseArguments ("c", scanner);
|
||||||
|
|
||||||
Generator::getDistance (mCode);
|
Generator::getDistance (mCode, mLiterals, "");
|
||||||
mOperands.push_back ('f');
|
mOperands.push_back ('f');
|
||||||
|
|
||||||
mNextOperand = false;
|
mNextOperand = false;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else if (keyword==Scanner::K_getsecondspassed)
|
else if (keyword==Scanner::K_getsecondspassed)
|
||||||
{
|
{
|
||||||
mTokenLoc = loc;
|
mTokenLoc = loc;
|
||||||
|
|
|
@ -314,6 +314,11 @@ namespace
|
||||||
{
|
{
|
||||||
code.push_back (Compiler::Generator::segment5 (56));
|
code.push_back (Compiler::Generator::segment5 (56));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void opGetDistanceExplicit (Compiler::Generator::CodeContainer& code)
|
||||||
|
{
|
||||||
|
code.push_back (Compiler::Generator::segment5 (57));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace Compiler
|
namespace Compiler
|
||||||
|
@ -706,9 +711,18 @@ namespace Compiler
|
||||||
opStopScript (code);
|
opStopScript (code);
|
||||||
}
|
}
|
||||||
|
|
||||||
void getDistance (CodeContainer& code)
|
void getDistance (CodeContainer& code, Literals& literals, const std::string id)
|
||||||
{
|
{
|
||||||
opGetDistance (code);
|
if (id.empty())
|
||||||
|
{
|
||||||
|
opGetDistance (code);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
int index = literals.addString (id);
|
||||||
|
opPushInt (code, index);
|
||||||
|
opGetDistanceExplicit (code);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void getSecondsPassed (CodeContainer& code)
|
void getSecondsPassed (CodeContainer& code)
|
||||||
|
|
|
@ -107,7 +107,7 @@ namespace Compiler
|
||||||
|
|
||||||
void stopScript (CodeContainer& code);
|
void stopScript (CodeContainer& code);
|
||||||
|
|
||||||
void getDistance (CodeContainer& code);
|
void getDistance (CodeContainer& code, Literals& literals, const std::string id);
|
||||||
|
|
||||||
void getSecondsPassed (CodeContainer& code);
|
void getSecondsPassed (CodeContainer& code);
|
||||||
|
|
||||||
|
|
|
@ -53,7 +53,8 @@ namespace Interpreter
|
||||||
|
|
||||||
virtual void stopScript (const std::string& name) = 0;
|
virtual void stopScript (const std::string& name) = 0;
|
||||||
|
|
||||||
virtual float getDistance (const std::string& name) const = 0;
|
virtual float getDistance (const std::string& name, const std::string& id = "") const
|
||||||
|
= 0;
|
||||||
|
|
||||||
virtual float getSecondsPassed() const = 0;
|
virtual float getSecondsPassed() const = 0;
|
||||||
|
|
||||||
|
|
|
@ -115,6 +115,8 @@ op 53: push 1, if implicit reference is disabled, 0 else
|
||||||
op 54: explicit reference = stack[0]; pop; enable explicit reference
|
op 54: explicit reference = stack[0]; pop; enable explicit reference
|
||||||
op 55: explicit reference = stack[0]; pop; disable explicit reference
|
op 55: explicit reference = stack[0]; pop; disable explicit reference
|
||||||
op 56: explicit reference = stack[0]; pop; push 1, if explicit reference is disabled, 0 else
|
op 56: explicit reference = stack[0]; pop; push 1, if explicit reference is disabled, 0 else
|
||||||
opcodes 57-33554431 unused
|
op 57: explicit reference = stack[0]; pop;
|
||||||
|
replace stack[0] with distance between explicit reference and a reference of ID stack[0]
|
||||||
|
opcodes 58-33554431 unused
|
||||||
opcodes 33554432-67108863 reserved for extensions
|
opcodes 33554432-67108863 reserved for extensions
|
||||||
|
|
||||||
|
|
|
@ -103,6 +103,7 @@ namespace Interpreter
|
||||||
|
|
||||||
// spacial
|
// spacial
|
||||||
interpreter.installSegment5 (49, new OpGetDistance);
|
interpreter.installSegment5 (49, new OpGetDistance);
|
||||||
|
interpreter.installSegment5 (57, new OpGetDistanceExplicit);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -19,6 +19,24 @@ namespace Interpreter
|
||||||
runtime[0] = *reinterpret_cast<Type_Data *> (&distance);
|
runtime[0] = *reinterpret_cast<Type_Data *> (&distance);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class OpGetDistanceExplicit : public Opcode0
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
virtual void execute (Runtime& runtime)
|
||||||
|
{
|
||||||
|
int index = runtime[0];
|
||||||
|
runtime.pop();
|
||||||
|
std::string id = runtime.getStringLiteral (index);
|
||||||
|
|
||||||
|
std::string name = runtime.getStringLiteral (runtime[0]);
|
||||||
|
|
||||||
|
float distance = runtime.getContext().getDistance (name, id);
|
||||||
|
|
||||||
|
runtime[0] = *reinterpret_cast<Type_Data *> (&distance);
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in a new issue