summaryrefslogtreecommitdiff
path: root/src/map/script.hpp
diff options
context:
space:
mode:
authorBen Longbons <b.r.longbons@gmail.com>2013-06-24 18:30:58 -0700
committerBen Longbons <b.r.longbons@gmail.com>2013-06-25 13:49:20 -0700
commitc9c81a610d97c95c15f938ecd07ceb71cb0cdfb1 (patch)
tree7637cf53216c6d0b8deadbfb8ea56faf4ff5bc85 /src/map/script.hpp
parentdbbfda0e96037da4f208ff8f00d181a5294484ae (diff)
downloadtmwa-c9c81a610d97c95c15f938ecd07ceb71cb0cdfb1.tar.gz
tmwa-c9c81a610d97c95c15f938ecd07ceb71cb0cdfb1.tar.bz2
tmwa-c9c81a610d97c95c15f938ecd07ceb71cb0cdfb1.tar.xz
tmwa-c9c81a610d97c95c15f938ecd07ceb71cb0cdfb1.zip
Fix bugs
Diffstat (limited to 'src/map/script.hpp')
-rw-r--r--src/map/script.hpp31
1 files changed, 30 insertions, 1 deletions
diff --git a/src/map/script.hpp b/src/map/script.hpp
index 171f8a3..0e63add 100644
--- a/src/map/script.hpp
+++ b/src/map/script.hpp
@@ -10,6 +10,8 @@
#include "../common/db.hpp"
#include "../common/dumb_ptr.hpp"
+#include "map.t.hpp"
+
enum class ByteCode : uint8_t;
struct str_data_t;
@@ -60,16 +62,43 @@ struct ScriptPointer
{
const char *rv = code->get_str(pos);
pos += strlen(rv);
+ ++pos;
return rv;
}
};
+// internal
+class SIR
+{
+ uint32_t impl;
+ SIR(SP v)
+ : impl(static_cast<uint32_t>(v))
+ {}
+ SIR(unsigned v, uint8_t i)
+ : impl((i << 24) | v)
+ {}
+public:
+ SIR() : impl() {}
+
+ unsigned base() const { return impl & 0x00ffffff; }
+ uint8_t index() const { return impl >> 24; }
+ SIR iplus(uint8_t i) const { return SIR(base(), index() + i); }
+ static SIR from(unsigned v, uint8_t i=0) { return SIR(v, i); }
+
+ SP sp() const { return static_cast<SP>(impl); }
+ static SIR from(SP v) { return SIR(v); }
+
+ friend bool operator == (SIR l, SIR r) { return l.impl == r.impl; }
+ friend bool operator < (SIR l, SIR r) { return l.impl < r.impl; }
+};
+
struct script_data
{
ByteCode type;
union uu
{
- int num;
+ SIR reg;
+ int numi;
dumb_string str;
// Not a ScriptPointer - pos is stored in a separate slot,
// to avoid exploding the struct for everyone.