diff options
author | Eugene Sandulenko | 2016-07-02 22:01:26 +0200 |
---|---|---|
committer | Eugene Sandulenko | 2016-08-03 23:40:36 +0200 |
commit | 7327f0b86e53a2140ad8fd8d563871a8d54cb4ed (patch) | |
tree | afd3eb0a1824bb646f84a0454cce69dac373730e /engines | |
parent | e08f8bbe43079fef358985d1e6be637844e36e86 (diff) | |
download | scummvm-rg350-7327f0b86e53a2140ad8fd8d563871a8d54cb4ed.tar.gz scummvm-rg350-7327f0b86e53a2140ad8fd8d563871a8d54cb4ed.tar.bz2 scummvm-rg350-7327f0b86e53a2140ad8fd8d563871a8d54cb4ed.zip |
DIRECTOR: Lingo: Implement more built-in math functions
Diffstat (limited to 'engines')
-rw-r--r-- | engines/director/director.cpp | 2 | ||||
-rw-r--r-- | engines/director/lingo/lingo-builtins.cpp | 55 | ||||
-rw-r--r-- | engines/director/lingo/lingo.h | 6 |
3 files changed, 61 insertions, 2 deletions
diff --git a/engines/director/director.cpp b/engines/director/director.cpp index db218e449a..fa16502ec0 100644 --- a/engines/director/director.cpp +++ b/engines/director/director.cpp @@ -155,6 +155,8 @@ set z2 = z / z1\n\ put z\n\ put z1\n\ put z2\n\ +put integer(z2)\n\ +put cos(z2)\n\ ", kMovieScript, 2); _lingo->executeScript(kMovieScript, 2); diff --git a/engines/director/lingo/lingo-builtins.cpp b/engines/director/lingo/lingo-builtins.cpp index 311e774e0d..4bca9fd226 100644 --- a/engines/director/lingo/lingo-builtins.cpp +++ b/engines/director/lingo/lingo-builtins.cpp @@ -29,6 +29,12 @@ static struct BuiltinProto { void (*func)(void); int nparams; } builtins[] = { + { "abs", Lingo::b_abs, 1}, + { "atan", Lingo::b_atan, 1}, + { "cos", Lingo::b_cos, 1}, + { "exp", Lingo::b_exp, 1}, + { "integer",Lingo::b_integer, 1}, + { "log", Lingo::b_log, 1}, { "random", Lingo::b_random, 1}, { 0, 0, 0 } }; @@ -39,12 +45,57 @@ void Lingo::initBuiltIns() { } } +void Lingo::b_abs() { + Datum d = g_lingo->pop(); + + if (d.type == INT) + d.u.i = ABS(d.u.i); + else if (d.type == FLOAT) + d.u.f = ABS(d.u.f); + + g_lingo->push(d); +} + +void Lingo::b_atan() { + Datum d = g_lingo->pop(); + d.toFloat(); + d.u.f = atanf(d.u.f); + g_lingo->push(d); +} + +void Lingo::b_cos() { + Datum d = g_lingo->pop(); + d.toFloat(); + d.u.f = cos(d.u.f); + g_lingo->push(d); +} + +void Lingo::b_exp() { + Datum d = g_lingo->pop(); + d.toInt(); // Lingo uses int, so we're enforcing it + d.toFloat(); + d.u.f = expf(d.u.f); + g_lingo->push(d); +} + +void Lingo::b_integer() { + Datum d = g_lingo->pop(); + d.toInt(); + g_lingo->push(d); +} + +void Lingo::b_log() { + Datum d = g_lingo->pop(); + d.toFloat(); + d.u.f = logf(d.u.f); + g_lingo->push(d); +} + void Lingo::b_random() { Datum max = g_lingo->pop(); Datum res; - if (max.type != INT) - warning("Non-int type for rand: %d", max.type); + max.toInt(); res.u.i = g_lingo->_vm->_rnd.getRandomNumber(max.u.i); res.type = INT; diff --git a/engines/director/lingo/lingo.h b/engines/director/lingo/lingo.h index 11f84b28c2..8028425c9c 100644 --- a/engines/director/lingo/lingo.h +++ b/engines/director/lingo/lingo.h @@ -199,6 +199,12 @@ public: static void c_gotoprevious(); static void c_global(); + static void b_abs(); + static void b_atan(); + static void b_cos(); + static void b_exp(); + static void b_integer(); + static void b_log(); static void b_random(); void func_mci(Common::String &s); |