]> git.localhorst.tv Git - l2e.git/commitdiff
added compare and jump codes for scripts
authorDaniel Karbach <daniel.karbach@localhorst.tv>
Sun, 14 Oct 2012 21:07:07 +0000 (23:07 +0200)
committerDaniel Karbach <daniel.karbach@localhorst.tv>
Sun, 14 Oct 2012 21:07:07 +0000 (23:07 +0200)
src/common/Script.h
src/common/ScriptRunner.cpp
src/common/ScriptRunner.h

index 0dbaf4d3b7bad72866af810a2a13862102206a85..c203f4061e402cbf4b2f6d0a8724105092c0252f 100644 (file)
@@ -35,6 +35,18 @@ public:
                CODE_RAND_I0,
                CODE_RAND_I1,
 
+               CODE_CMP_I0,
+               CODE_CMP_I1,
+               CODE_CMP_I0_I1,
+
+               CODE_JUMP,
+               CODE_JUMP_EQUAL,
+               CODE_JUMP_NOT_EQUAL,
+               CODE_JUMP_LESS,
+               CODE_JUMP_LESS_EQUAL,
+               CODE_JUMP_GREATER,
+               CODE_JUMP_GREATER_EQUAL,
+
                CODE_SYSCALL,
        };
 
index c1022c4c1ed98c62047096ddc1c252ea273e9546..98fd4fbdc9a3dfec83b812e0d662377a5e600706 100644 (file)
@@ -25,7 +25,8 @@ ScriptRunner::ScriptRunner()
 , integer0(0)
 , integer1(0)
 , vector0(0, 0)
-, vector1(0, 0) {
+, vector1(0, 0)
+, compare(0) {
 
 }
 
@@ -105,6 +106,60 @@ void ScriptRunner::Exec(unsigned char code) {
                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;
@@ -129,4 +184,14 @@ const Vector<int> &ScriptRunner::PopVector() {
        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;
+       }
+}
+
 }
index 4751908960d3dc630922207df86a02abdac6d98b..9b0f1ac8aa037503bdce31580a2e4ae617512b96 100644 (file)
@@ -11,6 +11,8 @@
 #include "fwd.h"
 #include "../geometry/Vector.h"
 
+#include <SDL.h>
+
 namespace common {
 
 class ScriptRunner {
@@ -38,6 +40,14 @@ private:
        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;
@@ -50,6 +60,8 @@ private:
        geometry::Vector<int> vector0;
        geometry::Vector<int> vector1;
 
+       Uint8 compare;
+
 };
 
 }