, integer0(0)
, integer1(0)
, vector0(0, 0)
-, vector1(0, 0) {
+, vector1(0, 0)
+, compare(0) {
}
case Script::CODE_RAND_I1:
integer1 = std::rand();
break;
+ case Script::CODE_CMP_I0:
+ Compare(integer0, PopInt());
+ break;
+ case Script::CODE_CMP_I1:
+ Compare(integer1, PopInt());
+ break;
+ case Script::CODE_CMP_I0_I1:
+ Compare(integer0, integer1);
+ break;
+ case Script::CODE_JUMP:
+ cursor = PopInt();
+ break;
+ case Script::CODE_JUMP_EQUAL: {
+ int addr(PopInt());
+ if (compare == COMPARE_EQUAL) {
+ cursor = addr;
+ }
+ break;
+ }
+ case Script::CODE_JUMP_NOT_EQUAL: {
+ int addr(PopInt());
+ if (compare != COMPARE_EQUAL) {
+ cursor = addr;
+ }
+ break;
+ }
+ case Script::CODE_JUMP_LESS: {
+ int addr(PopInt());
+ if (compare == COMPARE_LESS) {
+ cursor = addr;
+ }
+ break;
+ }
+ case Script::CODE_JUMP_LESS_EQUAL: {
+ int addr(PopInt());
+ if (compare != COMPARE_GREATER) {
+ cursor = addr;
+ }
+ break;
+ }
+ case Script::CODE_JUMP_GREATER: {
+ int addr(PopInt());
+ if (compare == COMPARE_GREATER) {
+ cursor = addr;
+ }
+ break;
+ }
+ case Script::CODE_JUMP_GREATER_EQUAL: {
+ int addr(PopInt());
+ if (compare != COMPARE_LESS) {
+ cursor = addr;
+ }
+ break;
+ }
case Script::CODE_SYSCALL:
host->HandleSyscall(*this);
break;
return *vec;
}
+void ScriptRunner::Compare(int lhs, int rhs) {
+ if (lhs < rhs) {
+ compare = COMPARE_LESS;
+ } else if (lhs > rhs) {
+ compare = COMPARE_GREATER;
+ } else {
+ compare = COMPARE_EQUAL;
+ }
+}
+
}
#include "fwd.h"
#include "../geometry/Vector.h"
+#include <SDL.h>
+
namespace common {
class ScriptRunner {
int PopInt();
const geometry::Vector<int> &PopVector();
+ void Compare(int, int);
+
+ enum CompareFlags {
+ COMPARE_EQUAL = 0,
+ COMPARE_LESS = 1,
+ COMPARE_GREATER = 2,
+ };
+
private:
ScriptHost *host;
const Script *script;
geometry::Vector<int> vector0;
geometry::Vector<int> vector1;
+ Uint8 compare;
+
};
}