mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-02-03 17:54:06 +00:00
redirecting output of expression evalutation to new report channel
This commit is contained in:
parent
125319c441
commit
861dc6a16e
@ -125,6 +125,11 @@ namespace
|
||||
code.push_back (Compiler::Generator::segment3 (0, buttons));
|
||||
}
|
||||
|
||||
void opReport (Compiler::Generator::CodeContainer& code)
|
||||
{
|
||||
code.push_back (Compiler::Generator::segment5 (58));
|
||||
}
|
||||
|
||||
void opFetchLocalShort (Compiler::Generator::CodeContainer& code)
|
||||
{
|
||||
code.push_back (Compiler::Generator::segment5 (21));
|
||||
@ -516,6 +521,14 @@ namespace Compiler
|
||||
opMessageBox (code, buttons);
|
||||
}
|
||||
|
||||
void report (CodeContainer& code, Literals& literals, const std::string& message)
|
||||
{
|
||||
int index = literals.addString (message);
|
||||
|
||||
opPushInt (code, index);
|
||||
opReport (code);
|
||||
}
|
||||
|
||||
void fetchLocal (CodeContainer& code, char localType, int localIndex)
|
||||
{
|
||||
opPushInt (code, localIndex);
|
||||
|
@ -81,6 +81,8 @@ namespace Compiler
|
||||
void message (CodeContainer& code, Literals& literals, const std::string& message,
|
||||
int buttons);
|
||||
|
||||
void report (CodeContainer& code, Literals& literals, const std::string& message);
|
||||
|
||||
void fetchLocal (CodeContainer& code, char localType, int localIndex);
|
||||
|
||||
void jump (CodeContainer& code, int offset);
|
||||
|
@ -30,12 +30,12 @@ namespace Compiler
|
||||
{
|
||||
case 'l':
|
||||
|
||||
Generator::message (mCode, mLiterals, "%g", 0);
|
||||
Generator::report (mCode, mLiterals, "%g");
|
||||
break;
|
||||
|
||||
case 'f':
|
||||
|
||||
Generator::message (mCode, mLiterals, "%f", 0);
|
||||
Generator::report (mCode, mLiterals, "%f");
|
||||
break;
|
||||
|
||||
default:
|
||||
|
@ -117,5 +117,9 @@ 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 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
|
||||
op 58: report string literal index in stack[0];
|
||||
additional arguments (if any) in stack[n]..stack[1];
|
||||
n is determined according to the message string
|
||||
all arguments are removed from stack
|
||||
opcodes 59-33554431 unused
|
||||
opcodes 33554432-67108863 reserved for extensions
|
||||
|
@ -95,6 +95,7 @@ namespace Interpreter
|
||||
interpreter.installSegment5 (54, new OpEnableExplicit);
|
||||
interpreter.installSegment5 (55, new OpDisableExplicit);
|
||||
interpreter.installSegment5 (56, new OpGetDisabledExplicit);
|
||||
interpreter.installSegment5 (58, new OpReport);
|
||||
|
||||
// script control
|
||||
interpreter.installSegment5 (46, new OpScriptRunning);
|
||||
@ -106,4 +107,3 @@ namespace Interpreter
|
||||
interpreter.installSegment5 (57, new OpGetDistanceExplicit);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -13,6 +13,66 @@
|
||||
|
||||
namespace Interpreter
|
||||
{
|
||||
inline std::string formatMessage (const std::string& message, Runtime& runtime)
|
||||
{
|
||||
std::string formattedMessage;
|
||||
|
||||
for (std::size_t i=0; i<message.size(); ++i)
|
||||
{
|
||||
char c = message[i];
|
||||
|
||||
if (c!='%')
|
||||
formattedMessage += c;
|
||||
else
|
||||
{
|
||||
++i;
|
||||
if (i<message.size())
|
||||
{
|
||||
c = message[i];
|
||||
|
||||
if (c=='S' || c=='s')
|
||||
{
|
||||
int index = runtime[0].mInteger;
|
||||
runtime.pop();
|
||||
formattedMessage += runtime.getStringLiteral (index);
|
||||
}
|
||||
else if (c=='g' || c=='G')
|
||||
{
|
||||
Type_Integer value = runtime[0].mInteger;
|
||||
runtime.pop();
|
||||
|
||||
std::ostringstream out;
|
||||
out << value;
|
||||
formattedMessage += out.str();
|
||||
}
|
||||
else if (c=='f' || c=='F' || c=='.')
|
||||
{
|
||||
while (c!='f' && i<message.size())
|
||||
{
|
||||
++i;
|
||||
}
|
||||
|
||||
float value = runtime[0].mFloat;
|
||||
runtime.pop();
|
||||
|
||||
std::ostringstream out;
|
||||
out << value;
|
||||
formattedMessage += out.str();
|
||||
}
|
||||
else if (c=='%')
|
||||
formattedMessage += "%";
|
||||
else
|
||||
{
|
||||
formattedMessage += "%";
|
||||
formattedMessage += c;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return formattedMessage;
|
||||
}
|
||||
|
||||
class OpMessageBox : public Opcode1
|
||||
{
|
||||
public:
|
||||
@ -36,66 +96,31 @@ namespace Interpreter
|
||||
|
||||
std::reverse (buttons.begin(), buttons.end());
|
||||
|
||||
// additional parameters
|
||||
std::string formattedMessage;
|
||||
|
||||
for (std::size_t i=0; i<message.size(); ++i)
|
||||
{
|
||||
char c = message[i];
|
||||
|
||||
if (c!='%')
|
||||
formattedMessage += c;
|
||||
else
|
||||
{
|
||||
++i;
|
||||
if (i<message.size())
|
||||
{
|
||||
c = message[i];
|
||||
|
||||
if (c=='S' || c=='s')
|
||||
{
|
||||
int index = runtime[0].mInteger;
|
||||
runtime.pop();
|
||||
formattedMessage += runtime.getStringLiteral (index);
|
||||
}
|
||||
else if (c=='g' || c=='G')
|
||||
{
|
||||
Type_Integer value = runtime[0].mInteger;
|
||||
runtime.pop();
|
||||
|
||||
std::ostringstream out;
|
||||
out << value;
|
||||
formattedMessage += out.str();
|
||||
}
|
||||
else if (c=='f' || c=='F' || c=='.')
|
||||
{
|
||||
while (c!='f' && i<message.size())
|
||||
{
|
||||
++i;
|
||||
}
|
||||
|
||||
float value = runtime[0].mFloat;
|
||||
runtime.pop();
|
||||
|
||||
std::ostringstream out;
|
||||
out << value;
|
||||
formattedMessage += out.str();
|
||||
}
|
||||
else if (c=='%')
|
||||
formattedMessage += "%";
|
||||
else
|
||||
{
|
||||
formattedMessage += "%";
|
||||
formattedMessage += c;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// handle additional parameters
|
||||
std::string formattedMessage = formatMessage (message, runtime);
|
||||
|
||||
runtime.getContext().messageBox (formattedMessage, buttons);
|
||||
}
|
||||
};
|
||||
|
||||
class OpReport : public Opcode0
|
||||
{
|
||||
public:
|
||||
|
||||
virtual void execute (Runtime& runtime)
|
||||
{
|
||||
// message
|
||||
int index = runtime[0].mInteger;
|
||||
runtime.pop();
|
||||
std::string message = runtime.getStringLiteral (index);
|
||||
|
||||
// handle additional parameters
|
||||
std::string formattedMessage = formatMessage (message, runtime);
|
||||
|
||||
runtime.getContext().report (formattedMessage);
|
||||
}
|
||||
};
|
||||
|
||||
class OpMenuMode : public Opcode0
|
||||
{
|
||||
public:
|
||||
|
Loading…
x
Reference in New Issue
Block a user