2012-01-06 23:29:45 +01:00
|
|
|
/* ResidualVM - A 3D game interpreter
|
2011-05-08 12:34:15 +02:00
|
|
|
*
|
2012-01-06 23:29:45 +01:00
|
|
|
* ResidualVM is the legal property of its developers, whose names
|
2011-05-08 12:34:15 +02:00
|
|
|
* are too numerous to list here. Please refer to the COPYRIGHT
|
|
|
|
* file distributed with this source distribution.
|
|
|
|
*
|
2012-12-19 23:15:43 +01:00
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
2014-04-05 18:18:42 +02:00
|
|
|
*
|
2012-12-19 23:15:43 +01:00
|
|
|
* This program is distributed in the hope that it will be useful,
|
2011-05-08 12:34:15 +02:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2012-12-19 23:15:43 +01:00
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
2014-04-05 18:18:42 +02:00
|
|
|
*
|
2012-12-19 23:15:43 +01:00
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2011-05-08 12:34:15 +02:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "engines/grim/grim.h"
|
2011-10-12 17:42:40 +02:00
|
|
|
#include "engines/grim/lua_v1.h"
|
2011-05-13 17:55:14 -07:00
|
|
|
#include "engines/grim/resource.h"
|
|
|
|
#include "engines/grim/bitmap.h"
|
|
|
|
#include "engines/grim/primitives.h"
|
2011-07-17 18:17:07 +02:00
|
|
|
#include "engines/grim/iris.h"
|
2011-07-22 22:40:49 +02:00
|
|
|
#include "engines/grim/gfx_base.h"
|
2013-01-08 00:33:59 +01:00
|
|
|
#include "engines/grim/set.h"
|
2013-01-11 12:39:12 +01:00
|
|
|
#include "actor.h"
|
2011-05-08 12:34:15 +02:00
|
|
|
|
2011-05-14 12:11:53 +02:00
|
|
|
#include "engines/grim/movie/movie.h"
|
2011-05-08 12:34:15 +02:00
|
|
|
|
2011-10-13 20:25:50 +02:00
|
|
|
#include "engines/grim/lua/lua.h"
|
|
|
|
|
2011-05-08 12:34:15 +02:00
|
|
|
namespace Grim {
|
|
|
|
|
2011-10-13 15:41:22 +02:00
|
|
|
void Lua_V1::GetImage() {
|
2011-05-08 12:34:15 +02:00
|
|
|
lua_Object nameObj = lua_getparam(1);
|
|
|
|
if (!lua_isstring(nameObj)) {
|
|
|
|
lua_pushnil();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const char *bitmapName = lua_getstring(nameObj);
|
2012-02-02 09:34:53 -08:00
|
|
|
Bitmap *b = Bitmap::create(bitmapName);
|
2011-05-08 12:34:15 +02:00
|
|
|
lua_pushusertag(b->getId(), MKTAG('V','B','U','F'));
|
|
|
|
}
|
|
|
|
|
2011-10-13 15:41:22 +02:00
|
|
|
void Lua_V1::FreeImage() {
|
2011-05-08 12:34:15 +02:00
|
|
|
lua_Object param = lua_getparam(1);
|
|
|
|
if (!lua_isuserdata(param) || lua_tag(param) != MKTAG('V','B','U','F'))
|
|
|
|
return;
|
2011-11-21 22:07:12 +01:00
|
|
|
Bitmap *bitmap = getbitmap(param);
|
2011-05-09 22:14:23 +02:00
|
|
|
delete bitmap;
|
2011-05-08 12:34:15 +02:00
|
|
|
}
|
|
|
|
|
2011-10-13 15:41:22 +02:00
|
|
|
void Lua_V1::BlastImage() {
|
2011-05-08 12:34:15 +02:00
|
|
|
lua_Object param = lua_getparam(1);
|
|
|
|
if (!lua_isuserdata(param) || lua_tag(param) != MKTAG('V','B','U','F'))
|
|
|
|
return;
|
2011-11-21 22:07:12 +01:00
|
|
|
Bitmap *bitmap = getbitmap(param);
|
2011-05-08 12:34:15 +02:00
|
|
|
lua_Object xObj = lua_getparam(2);
|
|
|
|
lua_Object yObj = lua_getparam(3);
|
|
|
|
if (!lua_isnumber(xObj) || !lua_isnumber(yObj))
|
|
|
|
return;
|
|
|
|
|
|
|
|
int x = (int)lua_getnumber(xObj);
|
|
|
|
int y = (int)lua_getnumber(yObj);
|
|
|
|
// bool transparent = getbool(4); // TODO transparent/masked copy into display
|
2012-02-02 09:34:53 -08:00
|
|
|
bitmap->draw(x, y);
|
2011-05-08 12:34:15 +02:00
|
|
|
}
|
|
|
|
|
2011-10-13 15:41:22 +02:00
|
|
|
void Lua_V1::CleanBuffer() {
|
2011-05-08 12:34:15 +02:00
|
|
|
g_driver->copyStoredToDisplay();
|
|
|
|
}
|
|
|
|
|
2011-10-13 15:41:22 +02:00
|
|
|
void Lua_V1::StartFullscreenMovie() {
|
2011-05-08 12:34:15 +02:00
|
|
|
lua_Object name = lua_getparam(1);
|
|
|
|
if (!lua_isstring(name)) {
|
|
|
|
lua_pushnil();
|
|
|
|
return;
|
|
|
|
}
|
2011-10-13 15:41:22 +02:00
|
|
|
Lua_V1::CleanBuffer();
|
2011-10-04 22:01:24 +02:00
|
|
|
|
|
|
|
GrimEngine::EngineMode prevEngineMode = g_grim->getMode();
|
|
|
|
g_grim->setMode(GrimEngine::SmushMode);
|
2014-05-29 15:35:46 -07:00
|
|
|
g_grim->setMovieSubtitle(nullptr);
|
2011-10-04 22:01:24 +02:00
|
|
|
bool looping = getbool(2);
|
|
|
|
bool result = g_movie->play(lua_getstring(name), looping, 0, 0);
|
2011-05-26 00:25:03 +08:00
|
|
|
if (!result)
|
2011-10-04 22:01:24 +02:00
|
|
|
g_grim->setMode(prevEngineMode);
|
2011-05-25 18:27:46 +08:00
|
|
|
pushbool(result);
|
2011-05-08 12:34:15 +02:00
|
|
|
}
|
|
|
|
|
2011-10-13 15:41:22 +02:00
|
|
|
void Lua_V1::StartMovie() {
|
2011-05-08 12:34:15 +02:00
|
|
|
lua_Object name = lua_getparam(1);
|
|
|
|
if (!lua_isstring(name)) {
|
|
|
|
lua_pushnil();
|
|
|
|
return;
|
|
|
|
}
|
2011-10-04 22:01:24 +02:00
|
|
|
int x = 0, y = 0;
|
2011-05-08 12:34:15 +02:00
|
|
|
if (!lua_isnil(lua_getparam(3)))
|
|
|
|
x = (int)lua_getnumber(lua_getparam(3));
|
|
|
|
if (!lua_isnil(lua_getparam(4)))
|
|
|
|
y = (int)lua_getnumber(lua_getparam(4));
|
|
|
|
|
2011-10-04 22:01:24 +02:00
|
|
|
GrimEngine::EngineMode prevEngineMode = g_grim->getMode();
|
|
|
|
g_grim->setMode(GrimEngine::NormalMode);
|
|
|
|
|
|
|
|
bool looping = getbool(2);
|
|
|
|
bool result = g_movie->play(lua_getstring(name), looping, x, y);
|
2013-01-08 00:33:59 +01:00
|
|
|
g_grim->setMovieSetup();
|
2011-05-26 00:25:03 +08:00
|
|
|
if (!result)
|
2011-10-04 22:01:24 +02:00
|
|
|
g_grim->setMode(prevEngineMode);
|
2011-05-25 18:27:46 +08:00
|
|
|
pushbool(result);
|
2011-05-08 12:34:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Fullscreen movie playing query and normal movie
|
|
|
|
* query should actually detect correctly and not
|
|
|
|
* just return true whenever ANY movie is playing
|
|
|
|
*/
|
2011-10-13 15:41:22 +02:00
|
|
|
void Lua_V1::IsFullscreenMoviePlaying() {
|
2011-07-20 17:59:47 +02:00
|
|
|
pushbool(g_movie->isPlaying());
|
2011-05-08 12:34:15 +02:00
|
|
|
}
|
|
|
|
|
2011-10-13 15:41:22 +02:00
|
|
|
void Lua_V1::IsMoviePlaying() {
|
2011-08-23 15:48:58 +02:00
|
|
|
// Previously, if the game was *not* the demo, this checked also if the mode
|
2011-10-04 22:01:24 +02:00
|
|
|
// was GrimEngine::NormalMode. This doesn't seem to be what original does, and causes
|
2011-08-23 15:48:58 +02:00
|
|
|
// bug #301 because the movie eldepot.snm is played before legslide.snm ends.
|
|
|
|
pushbool(g_movie->isPlaying());
|
2011-05-08 12:34:15 +02:00
|
|
|
}
|
|
|
|
|
2011-10-13 15:41:22 +02:00
|
|
|
void Lua_V1::StopMovie() {
|
2011-05-14 12:11:53 +02:00
|
|
|
g_movie->stop();
|
2012-03-09 16:46:08 +01:00
|
|
|
// Delete subtitles that may have not expired.
|
2014-05-29 15:35:46 -07:00
|
|
|
g_grim->setMovieSubtitle(nullptr);
|
2011-05-08 12:34:15 +02:00
|
|
|
}
|
|
|
|
|
2011-10-13 15:41:22 +02:00
|
|
|
void Lua_V1::PauseMovie() {
|
2011-05-14 12:11:53 +02:00
|
|
|
g_movie->pause(lua_isnil(lua_getparam(1)) == 0);
|
2011-05-08 12:34:15 +02:00
|
|
|
}
|
|
|
|
|
2011-10-13 15:41:22 +02:00
|
|
|
void Lua_V1::PurgePrimitiveQueue() {
|
2011-11-21 22:07:12 +01:00
|
|
|
PrimitiveObject::getPool().deleteObjects();
|
2011-05-08 12:34:15 +02:00
|
|
|
}
|
|
|
|
|
2011-10-13 15:41:22 +02:00
|
|
|
void Lua_V1::DrawPolygon() {
|
2011-05-08 12:34:15 +02:00
|
|
|
lua_Object tableObj1 = lua_getparam(1);
|
|
|
|
if (!lua_istable(tableObj1)) {
|
|
|
|
lua_pushnil();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-04-12 02:54:10 +02:00
|
|
|
//int layer = 2;
|
2014-08-04 19:37:03 -04:00
|
|
|
Color color;
|
2011-05-08 12:34:15 +02:00
|
|
|
lua_Object tableObj2 = lua_getparam(2);
|
|
|
|
if (lua_istable(tableObj2)) {
|
|
|
|
lua_pushobject(tableObj2);
|
|
|
|
lua_pushstring("color");
|
|
|
|
lua_Object colorObj = lua_gettable();
|
|
|
|
if (lua_isuserdata(colorObj) && lua_tag(colorObj) == MKTAG('C','O','L','R')) {
|
|
|
|
color = getcolor(colorObj);
|
|
|
|
}
|
|
|
|
lua_pushobject(tableObj2);
|
|
|
|
lua_pushstring("layer");
|
|
|
|
lua_Object layerObj = lua_gettable();
|
|
|
|
if (lua_isnumber(layerObj))
|
2012-04-12 02:54:10 +02:00
|
|
|
/*layer = (int)*/lua_getnumber(layerObj);
|
2011-05-08 12:34:15 +02:00
|
|
|
}
|
|
|
|
|
2014-08-04 19:37:03 -04:00
|
|
|
// This code only supports 4 point polygons because the game doesn't
|
|
|
|
// use other than that. However, the original engine can support
|
|
|
|
// many points per polygon
|
|
|
|
lua_Object pointObj;
|
|
|
|
Common::Point p[4];
|
|
|
|
for (int i = 0; i < 4; i++) {
|
|
|
|
// Get X
|
|
|
|
lua_pushobject(tableObj1);
|
2014-11-02 13:37:19 +01:00
|
|
|
lua_pushnumber(i * 2 + 1);
|
2014-08-04 19:37:03 -04:00
|
|
|
pointObj = lua_gettable();
|
|
|
|
if (!lua_isnumber(pointObj)) {
|
2014-11-02 13:37:19 +01:00
|
|
|
warning("Lua_V1::DrawPolygon: %i Point Parameter X isn't a number!", i * 2 + 1);
|
2014-08-04 19:37:03 -04:00
|
|
|
return;
|
|
|
|
}
|
2014-08-04 19:51:37 -04:00
|
|
|
if (g_grim->getGameType() == GType_GRIM)
|
|
|
|
p[i].x = (int)lua_getnumber(pointObj);
|
|
|
|
else
|
|
|
|
p[i].x = (int)((lua_getnumber(pointObj) + 1) * 320);
|
2014-08-04 19:37:03 -04:00
|
|
|
|
|
|
|
// Get Y
|
|
|
|
lua_pushobject(tableObj1);
|
2014-11-02 13:37:19 +01:00
|
|
|
lua_pushnumber(i * 2 + 2);
|
2014-08-04 19:37:03 -04:00
|
|
|
pointObj = lua_gettable();
|
|
|
|
if (!lua_isnumber(pointObj)) {
|
2014-11-02 13:37:19 +01:00
|
|
|
warning("Lua_V1::DrawPolygon: %i Point Parameter Y isn't a number!", i * 2 + 2);
|
2014-08-04 19:37:03 -04:00
|
|
|
return;
|
|
|
|
}
|
2014-08-04 19:51:37 -04:00
|
|
|
if (g_grim->getGameType() == GType_GRIM)
|
|
|
|
p[i].y = (int)lua_getnumber(pointObj);
|
|
|
|
else
|
|
|
|
p[i].y = (int)((1 - lua_getnumber(pointObj)) * 240);
|
2014-08-04 19:37:03 -04:00
|
|
|
}
|
2011-05-08 12:34:15 +02:00
|
|
|
|
2014-08-04 19:37:03 -04:00
|
|
|
PrimitiveObject *prim = new PrimitiveObject();
|
2014-08-14 07:51:13 +02:00
|
|
|
prim->createPolygon(p[0], p[1], p[2], p[3], color);
|
2014-08-04 19:37:03 -04:00
|
|
|
lua_pushusertag(prim->getId(), MKTAG('P','R','I','M'));
|
2011-05-08 12:34:15 +02:00
|
|
|
}
|
|
|
|
|
2011-10-13 15:41:22 +02:00
|
|
|
void Lua_V1::DrawLine() {
|
2011-05-08 12:34:15 +02:00
|
|
|
Common::Point p1, p2;
|
2012-01-27 11:47:28 -08:00
|
|
|
Color color;
|
2011-05-08 12:34:15 +02:00
|
|
|
lua_Object x1Obj = lua_getparam(1);
|
|
|
|
lua_Object y1Obj = lua_getparam(2);
|
|
|
|
lua_Object x2Obj = lua_getparam(3);
|
|
|
|
lua_Object y2Obj = lua_getparam(4);
|
|
|
|
lua_Object tableObj = lua_getparam(5);
|
|
|
|
|
|
|
|
if (!lua_isnumber(x1Obj) || !lua_isnumber(y1Obj) || !lua_isnumber(x2Obj) || !lua_isnumber(y2Obj)) {
|
|
|
|
lua_pushnil();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-08-04 19:51:37 -04:00
|
|
|
if (g_grim->getGameType() == GType_GRIM) {
|
|
|
|
p1.x = (int)lua_getnumber(x1Obj);
|
|
|
|
p1.y = (int)lua_getnumber(y1Obj);
|
|
|
|
p2.x = (int)lua_getnumber(x2Obj);
|
|
|
|
p2.y = (int)lua_getnumber(y2Obj);
|
|
|
|
} else {
|
|
|
|
p1.x = (int)((lua_getnumber(x1Obj) + 1) * 320);
|
|
|
|
p1.y = (int)((1 - lua_getnumber(y1Obj)) * 240);
|
|
|
|
p2.x = (int)((lua_getnumber(x2Obj) + 1) * 320);
|
|
|
|
p2.y = (int)((1 - lua_getnumber(y2Obj)) * 240);
|
|
|
|
}
|
2011-05-08 12:34:15 +02:00
|
|
|
|
2012-04-12 02:54:10 +02:00
|
|
|
//int layer = 2;
|
2011-05-08 12:34:15 +02:00
|
|
|
if (lua_istable(tableObj)) {
|
|
|
|
lua_pushobject(tableObj);
|
|
|
|
lua_pushstring("color");
|
|
|
|
lua_Object colorObj = lua_gettable();
|
|
|
|
if (lua_isuserdata(colorObj) && lua_tag(colorObj) == MKTAG('C','O','L','R')) {
|
|
|
|
color = getcolor(colorObj);
|
|
|
|
}
|
|
|
|
lua_pushobject(tableObj);
|
|
|
|
lua_pushstring("layer");
|
|
|
|
lua_Object layerObj = lua_gettable();
|
|
|
|
if (lua_isnumber(layerObj))
|
2012-04-12 02:54:10 +02:00
|
|
|
/*layer = (int)*/lua_getnumber(layerObj);
|
2011-05-08 12:34:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
PrimitiveObject *p = new PrimitiveObject();
|
|
|
|
p->createLine(p1, p2, color); // TODO Add layer support
|
|
|
|
lua_pushusertag(p->getId(), MKTAG('P','R','I','M'));
|
|
|
|
}
|
|
|
|
|
2011-10-13 15:41:22 +02:00
|
|
|
void Lua_V1::ChangePrimitive() {
|
2011-05-08 12:34:15 +02:00
|
|
|
lua_Object param1 = lua_getparam(1);
|
|
|
|
if (!lua_isuserdata(param1) || lua_tag(param1) != MKTAG('P','R','I','M'))
|
|
|
|
return;
|
|
|
|
|
|
|
|
lua_Object tableObj = lua_getparam(2);
|
|
|
|
if (!lua_istable(tableObj))
|
|
|
|
return;
|
|
|
|
|
2012-01-28 12:38:32 +01:00
|
|
|
PrimitiveObject *pmodify = getprimitive(param1);
|
2011-05-08 12:34:15 +02:00
|
|
|
assert(pmodify);
|
|
|
|
|
2012-01-28 12:38:32 +01:00
|
|
|
Color color;
|
2011-05-08 12:34:15 +02:00
|
|
|
lua_pushobject(tableObj);
|
|
|
|
lua_pushstring("color");
|
|
|
|
lua_Object colorObj = lua_gettable();
|
|
|
|
if (lua_isuserdata(colorObj) && lua_tag(colorObj) == MKTAG('C','O','L','R')) {
|
|
|
|
color = getcolor(colorObj);
|
|
|
|
pmodify->setColor(color);
|
|
|
|
}
|
|
|
|
|
|
|
|
lua_pushobject(tableObj);
|
|
|
|
lua_pushstring("layer");
|
|
|
|
lua_Object layer = lua_gettable();
|
|
|
|
if (lua_isnumber(layer)) {
|
|
|
|
// TODO pmodify->setLayer(lua_getnumber(layer));
|
|
|
|
warning("Not implemented: PrimitiveObject::setLayer. Layer: %d", (int)lua_getnumber(layer));
|
|
|
|
}
|
|
|
|
|
|
|
|
lua_pushobject(tableObj);
|
|
|
|
lua_pushstring("xoffset");
|
2014-08-04 19:37:03 -04:00
|
|
|
lua_Object xObj = lua_gettable();
|
2011-05-08 12:34:15 +02:00
|
|
|
lua_pushobject(tableObj);
|
|
|
|
lua_pushstring("yoffset");
|
2014-08-04 19:37:03 -04:00
|
|
|
lua_Object yObj = lua_gettable();
|
|
|
|
if (lua_isnumber(xObj) || lua_isnumber(yObj)) {
|
2012-04-12 02:54:10 +02:00
|
|
|
//int x = 0;
|
|
|
|
//int y = 0;
|
2014-08-04 19:37:03 -04:00
|
|
|
if (lua_isnumber(xObj))
|
|
|
|
/*x = (int)*/lua_getnumber(xObj);
|
|
|
|
if (lua_isnumber(yObj))
|
|
|
|
/*y = (int)*/lua_getnumber(yObj);
|
2011-05-08 12:34:15 +02:00
|
|
|
// TODO pmodify->setOffets(x, y);
|
|
|
|
assert(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
lua_pushobject(tableObj);
|
|
|
|
lua_pushstring("x");
|
2014-08-04 19:37:03 -04:00
|
|
|
xObj = lua_gettable();
|
2011-05-08 12:34:15 +02:00
|
|
|
lua_pushobject(tableObj);
|
|
|
|
lua_pushstring("y");
|
2014-08-04 19:37:03 -04:00
|
|
|
yObj = lua_gettable();
|
|
|
|
if (lua_isnumber(xObj) || lua_isnumber(yObj)) {
|
2011-05-08 12:34:15 +02:00
|
|
|
int x = -1;
|
|
|
|
int y = -1;
|
2014-08-04 19:51:37 -04:00
|
|
|
if (lua_isnumber(xObj)) {
|
|
|
|
if (g_grim->getGameType() == GType_GRIM)
|
|
|
|
x = (int)lua_getnumber(xObj);
|
|
|
|
else
|
|
|
|
x = (int)((lua_getnumber(xObj) + 1) * 320);
|
|
|
|
}
|
|
|
|
if (lua_isnumber(yObj)) {
|
|
|
|
if (g_grim->getGameType() == GType_GRIM)
|
|
|
|
y = (int)lua_getnumber(yObj);
|
|
|
|
else
|
|
|
|
y = (int)((1 - lua_getnumber(yObj)) * 240);
|
|
|
|
}
|
2011-05-08 12:34:15 +02:00
|
|
|
pmodify->setPos(x, y);
|
|
|
|
}
|
|
|
|
|
|
|
|
lua_pushobject(tableObj);
|
|
|
|
lua_pushstring("x2");
|
2014-08-04 19:37:03 -04:00
|
|
|
xObj = lua_gettable();
|
2011-05-08 12:34:15 +02:00
|
|
|
lua_pushobject(tableObj);
|
|
|
|
lua_pushstring("y2");
|
2014-08-04 19:37:03 -04:00
|
|
|
yObj = lua_gettable();
|
|
|
|
if (lua_isnumber(xObj) || lua_isnumber(yObj)) {
|
2014-06-05 07:48:40 -07:00
|
|
|
int x = -1;
|
|
|
|
int y = -1;
|
2014-08-04 19:51:37 -04:00
|
|
|
if (lua_isnumber(xObj)) {
|
|
|
|
if (g_grim->getGameType() == GType_GRIM)
|
|
|
|
x = (int)lua_getnumber(xObj);
|
|
|
|
else
|
|
|
|
x = (int)((lua_getnumber(xObj) + 1) * 320);
|
|
|
|
}
|
|
|
|
if (lua_isnumber(yObj)) {
|
|
|
|
if (g_grim->getGameType() == GType_GRIM)
|
|
|
|
y = (int)lua_getnumber(yObj);
|
|
|
|
else
|
|
|
|
y = (int)((1 - lua_getnumber(yObj)) * 240);
|
|
|
|
}
|
2014-06-05 07:48:40 -07:00
|
|
|
pmodify->setEndpoint(x, y);
|
2011-05-08 12:34:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
lua_pushobject(tableObj);
|
|
|
|
lua_pushstring("width");
|
|
|
|
lua_Object width = lua_gettable();
|
|
|
|
lua_pushobject(tableObj);
|
|
|
|
lua_pushstring("height");
|
|
|
|
lua_Object height = lua_gettable();
|
|
|
|
if (lua_isnumber(width) || lua_isnumber(height)) {
|
2012-04-12 02:54:10 +02:00
|
|
|
//int x = -1;
|
|
|
|
//int y = -1;
|
2011-05-08 12:34:15 +02:00
|
|
|
if (lua_isnumber(width))
|
2012-04-12 02:54:10 +02:00
|
|
|
/*x = (int)*/lua_getnumber(width);
|
2011-05-08 12:34:15 +02:00
|
|
|
if (lua_isnumber(height))
|
2012-04-12 02:54:10 +02:00
|
|
|
/*y = (int)*/lua_getnumber(height);
|
2011-05-08 12:34:15 +02:00
|
|
|
// TODO pmodify->setSize(x, y);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-10-13 15:41:22 +02:00
|
|
|
void Lua_V1::DrawRectangle() {
|
2011-05-08 12:34:15 +02:00
|
|
|
Common::Point p1, p2;
|
2012-01-27 11:47:28 -08:00
|
|
|
Color color;
|
2014-08-04 19:37:03 -04:00
|
|
|
lua_Object x1Obj = lua_getparam(1);
|
|
|
|
lua_Object y1Obj = lua_getparam(2);
|
|
|
|
lua_Object x2Obj = lua_getparam(3);
|
|
|
|
lua_Object y2Obj = lua_getparam(4);
|
2011-05-08 12:34:15 +02:00
|
|
|
lua_Object tableObj = lua_getparam(5);
|
|
|
|
|
2014-08-04 19:37:03 -04:00
|
|
|
if (!lua_isnumber(x1Obj) || !lua_isnumber(y1Obj) || !lua_isnumber(x2Obj) || !lua_isnumber(y2Obj)) {
|
2011-05-08 12:34:15 +02:00
|
|
|
lua_pushnil();
|
|
|
|
return;
|
|
|
|
}
|
2014-08-04 19:51:37 -04:00
|
|
|
|
|
|
|
if (g_grim->getGameType() == GType_GRIM) {
|
|
|
|
p1.x = (int)lua_getnumber(x1Obj);
|
|
|
|
p1.y = (int)lua_getnumber(y1Obj);
|
|
|
|
p2.x = (int)lua_getnumber(x2Obj);
|
|
|
|
p2.y = (int)lua_getnumber(y2Obj);
|
|
|
|
} else {
|
|
|
|
p1.x = (int)((lua_getnumber(x1Obj) + 1) * 320);
|
|
|
|
p1.y = (int)((1 - lua_getnumber(y1Obj)) * 240);
|
|
|
|
p2.x = (int)((lua_getnumber(x2Obj) + 1) * 320);
|
|
|
|
p2.y = (int)((1 - lua_getnumber(y2Obj)) * 240);
|
|
|
|
}
|
2011-05-08 12:34:15 +02:00
|
|
|
bool filled = false;
|
|
|
|
|
2013-07-09 21:12:55 +02:00
|
|
|
if (lua_istable(tableObj)) {
|
2011-05-08 12:34:15 +02:00
|
|
|
lua_pushobject(tableObj);
|
|
|
|
lua_pushstring("color");
|
|
|
|
lua_Object colorObj = lua_gettable();
|
|
|
|
if (lua_isuserdata(colorObj) && lua_tag(colorObj) == MKTAG('C','O','L','R')) {
|
|
|
|
color = getcolor(colorObj);
|
|
|
|
}
|
|
|
|
|
|
|
|
lua_pushobject(tableObj);
|
|
|
|
lua_pushstring("filled");
|
|
|
|
lua_Object objFilled = lua_gettable();
|
|
|
|
if (!lua_isnil(objFilled))
|
|
|
|
filled = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
PrimitiveObject *p = new PrimitiveObject();
|
|
|
|
p->createRectangle(p1, p2, color, filled);
|
|
|
|
lua_pushusertag(p->getId(), MKTAG('P','R','I','M')); // FIXME: we use PRIM usetag here
|
|
|
|
}
|
|
|
|
|
2011-10-13 15:41:22 +02:00
|
|
|
void Lua_V1::BlastRect() {
|
2011-05-08 12:34:15 +02:00
|
|
|
Common::Point p1, p2;
|
2012-01-27 11:47:28 -08:00
|
|
|
Color color;
|
2014-08-04 19:37:03 -04:00
|
|
|
lua_Object x1Obj = lua_getparam(1);
|
|
|
|
lua_Object y1Obj = lua_getparam(2);
|
|
|
|
lua_Object x2Obj = lua_getparam(3);
|
|
|
|
lua_Object y2Obj = lua_getparam(4);
|
2011-05-08 12:34:15 +02:00
|
|
|
lua_Object tableObj = lua_getparam(5);
|
|
|
|
|
2014-08-04 19:37:03 -04:00
|
|
|
if (!lua_isnumber(x1Obj) || !lua_isnumber(y1Obj) || !lua_isnumber(x2Obj) || !lua_isnumber(y2Obj)) {
|
2011-05-08 12:34:15 +02:00
|
|
|
lua_pushnil();
|
|
|
|
return;
|
|
|
|
}
|
2014-08-04 19:51:37 -04:00
|
|
|
if (g_grim->getGameType() == GType_GRIM) {
|
|
|
|
p1.x = (int)lua_getnumber(x1Obj);
|
|
|
|
p1.y = (int)lua_getnumber(y1Obj);
|
|
|
|
p2.x = (int)lua_getnumber(x2Obj);
|
|
|
|
p2.y = (int)lua_getnumber(y2Obj);
|
|
|
|
} else {
|
|
|
|
p1.x = (int)((lua_getnumber(x1Obj) + 1) * 320);
|
|
|
|
p1.y = (int)((1 - lua_getnumber(y1Obj)) * 240);
|
|
|
|
p2.x = (int)((lua_getnumber(x2Obj) + 1) * 320);
|
|
|
|
p2.y = (int)((1 - lua_getnumber(y2Obj)) * 240);
|
|
|
|
}
|
2011-05-08 12:34:15 +02:00
|
|
|
bool filled = false;
|
|
|
|
|
2013-07-09 21:12:55 +02:00
|
|
|
if (lua_istable(tableObj)) {
|
2011-05-08 12:34:15 +02:00
|
|
|
lua_pushobject(tableObj);
|
|
|
|
lua_pushstring("color");
|
|
|
|
lua_Object colorObj = lua_gettable();
|
|
|
|
if (lua_isuserdata(colorObj) && lua_tag(colorObj) == MKTAG('C','O','L','R')) {
|
|
|
|
color = getcolor(colorObj);
|
|
|
|
}
|
|
|
|
|
|
|
|
lua_pushobject(tableObj);
|
|
|
|
lua_pushstring("filled");
|
|
|
|
lua_Object objFilled = lua_gettable();
|
|
|
|
if (!lua_isnil(objFilled))
|
|
|
|
filled = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
PrimitiveObject *p = new PrimitiveObject();
|
|
|
|
p->createRectangle(p1, p2, color, filled);
|
|
|
|
p->draw();
|
|
|
|
delete p;
|
|
|
|
}
|
|
|
|
|
2011-10-13 15:41:22 +02:00
|
|
|
void Lua_V1::KillPrimitive() {
|
2011-05-08 12:34:15 +02:00
|
|
|
lua_Object primObj = lua_getparam(1);
|
|
|
|
|
|
|
|
if (!lua_isuserdata(primObj) || lua_tag(primObj) != MKTAG('P','R','I','M'))
|
|
|
|
return;
|
|
|
|
|
|
|
|
PrimitiveObject *prim = getprimitive(primObj);
|
|
|
|
delete prim;
|
|
|
|
}
|
|
|
|
|
2011-10-13 15:41:22 +02:00
|
|
|
void Lua_V1::DimScreen() {
|
2011-05-19 09:17:57 +08:00
|
|
|
g_driver->storeDisplay();
|
2011-05-08 12:34:15 +02:00
|
|
|
g_driver->dimScreen();
|
|
|
|
}
|
|
|
|
|
2011-10-13 15:41:22 +02:00
|
|
|
void Lua_V1::DimRegion() {
|
2011-05-08 12:34:15 +02:00
|
|
|
int x = (int)lua_getnumber(lua_getparam(1));
|
|
|
|
int y = (int)lua_getnumber(lua_getparam(2));
|
|
|
|
int w = (int)lua_getnumber(lua_getparam(3));
|
|
|
|
int h = (int)lua_getnumber(lua_getparam(4));
|
|
|
|
float level = lua_getnumber(lua_getparam(5));
|
|
|
|
g_driver->dimRegion(x, y, w, h, level);
|
|
|
|
}
|
|
|
|
|
2011-10-13 15:41:22 +02:00
|
|
|
void Lua_V1::ScreenShot() {
|
2011-05-08 12:34:15 +02:00
|
|
|
int width = (int)lua_getnumber(lua_getparam(1));
|
|
|
|
int height = (int)lua_getnumber(lua_getparam(2));
|
2011-10-04 22:01:24 +02:00
|
|
|
GrimEngine::EngineMode mode = g_grim->getMode();
|
|
|
|
g_grim->setMode(GrimEngine::NormalMode);
|
2011-05-08 12:34:15 +02:00
|
|
|
g_grim->updateDisplayScene();
|
2014-06-30 22:46:50 +02:00
|
|
|
Bitmap *screenshot = g_driver->getScreenshot(width, height, false);
|
2011-05-08 12:34:15 +02:00
|
|
|
g_grim->setMode(mode);
|
|
|
|
if (screenshot) {
|
|
|
|
lua_pushusertag(screenshot->getId(), MKTAG('V','B','U','F'));
|
|
|
|
} else {
|
|
|
|
lua_pushnil();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-10-13 15:41:22 +02:00
|
|
|
void Lua_V1::SetGamma() {
|
2011-05-09 11:48:52 +02:00
|
|
|
lua_Object levelObj = lua_getparam(1);
|
|
|
|
|
|
|
|
if (!lua_isnumber(levelObj))
|
|
|
|
return;
|
2014-05-31 09:26:31 +02:00
|
|
|
double level = lua_getnumber(levelObj);
|
2011-05-09 11:48:52 +02:00
|
|
|
|
|
|
|
// FIXME: func(level)
|
2014-05-31 09:26:31 +02:00
|
|
|
warning("Lua_V1::SetGamma, implement opcode, level: %f", level);
|
2011-05-08 12:34:15 +02:00
|
|
|
}
|
|
|
|
|
2011-10-13 15:41:22 +02:00
|
|
|
void Lua_V1::Display() {
|
2011-05-08 12:34:15 +02:00
|
|
|
if (g_grim->getFlipEnable()) {
|
|
|
|
g_driver->flipBuffer();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-10-13 15:41:22 +02:00
|
|
|
void Lua_V1::EngineDisplay() {
|
2011-05-08 12:34:15 +02:00
|
|
|
// it enable/disable updating display
|
2017-04-25 13:05:38 +00:00
|
|
|
g_grim->setFlipEnable((bool)lua_getnumber(lua_getparam(1)));
|
2011-05-08 12:34:15 +02:00
|
|
|
}
|
|
|
|
|
2011-10-13 15:41:22 +02:00
|
|
|
void Lua_V1::ForceRefresh() {
|
GRIM: Drop off-screen buffers
These were present to implement actor freezing in software rendering mode
in the way original engine was intended for performance reason.
In residualvm, software rendering will generalise the principle through
dirty-rectangles management, so off-screen buffers should not be needed.
Also, properly implementing them requires invasive changes (move previous
draw call list from global OpenGL context to individual off-screen buffers,
along with associated linear vertex allocator, adding a new draw call to
track requested buffer changes until final on-screen frame buffer
presentation).
So instead of such added complexity, lie to lua API about actor not being
in set but keep it in so it is part of normal redraw sequence.
Fixes disappearing actors in cn, bi.
Likely also fixes at, ly, sh, mn, dd which uses free/thaw lua API, but
which I did not check.
2017-04-25 00:00:33 +00:00
|
|
|
// Nothing to do, no off-screen buffers
|
2011-05-08 12:34:15 +02:00
|
|
|
}
|
|
|
|
|
2011-10-13 15:41:22 +02:00
|
|
|
void Lua_V1::RenderModeUser() {
|
2011-05-08 12:34:15 +02:00
|
|
|
lua_Object param1 = lua_getparam(1);
|
2011-10-04 22:01:24 +02:00
|
|
|
if (!lua_isnil(param1) && g_grim->getMode() != GrimEngine::DrawMode) {
|
2011-05-08 12:34:15 +02:00
|
|
|
g_grim->setPreviousMode(g_grim->getMode());
|
2011-05-14 12:11:53 +02:00
|
|
|
g_movie->pause(true);
|
2011-10-04 22:01:24 +02:00
|
|
|
g_grim->setMode(GrimEngine::DrawMode);
|
|
|
|
} else if (lua_isnil(param1) && g_grim->getMode() == GrimEngine::DrawMode) {
|
2011-05-14 12:11:53 +02:00
|
|
|
g_movie->pause(false);
|
2011-05-08 12:34:15 +02:00
|
|
|
g_grim->setMode(g_grim->getPreviousMode());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-10-13 15:41:22 +02:00
|
|
|
void Lua_V1::IrisUp() {
|
2011-07-17 18:17:07 +02:00
|
|
|
lua_Object xObj = lua_getparam(1);
|
|
|
|
lua_Object yObj = lua_getparam(2);
|
|
|
|
lua_Object timeObj = lua_getparam(3);
|
|
|
|
|
|
|
|
g_grim->playIrisAnimation(Iris::Open, (int)lua_getnumber(xObj), (int)lua_getnumber(yObj), (int)lua_getnumber(timeObj));
|
|
|
|
}
|
|
|
|
|
2011-10-13 15:41:22 +02:00
|
|
|
void Lua_V1::IrisDown() {
|
2011-07-17 18:17:07 +02:00
|
|
|
lua_Object xObj = lua_getparam(1);
|
|
|
|
lua_Object yObj = lua_getparam(2);
|
|
|
|
lua_Object timeObj = lua_getparam(3);
|
|
|
|
|
|
|
|
g_grim->playIrisAnimation(Iris::Close, (int)lua_getnumber(xObj), (int)lua_getnumber(yObj), (int)lua_getnumber(timeObj));
|
|
|
|
}
|
|
|
|
|
2011-10-13 15:41:22 +02:00
|
|
|
void Lua_V1::PreRender() {
|
2011-07-29 23:02:52 +02:00
|
|
|
g_driver->renderBitmaps(getbool(1));
|
|
|
|
g_driver->renderZBitmaps(getbool(2));
|
|
|
|
}
|
|
|
|
|
2011-05-08 12:34:15 +02:00
|
|
|
} // end of namespace Grim
|