ResidualVM logo ResidualVM website - Forums - Contact us BuildBot - Doxygen - Wiki curved edge

lua_v1_graphics.cpp

Go to the documentation of this file.
00001 /* ResidualVM - A 3D game interpreter
00002  *
00003  * ResidualVM is the legal property of its developers, whose names
00004  * are too numerous to list here. Please refer to the COPYRIGHT
00005  * file distributed with this source distribution.
00006  *
00007  * This program is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU General Public License
00009  * as published by the Free Software Foundation; either version 2
00010  * of the License, or (at your option) any later version.
00011  *
00012  * This program is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU General Public License
00018  * along with this program; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00020  *
00021  */
00022 
00023 #include "engines/grim/grim.h"
00024 #include "engines/grim/lua_v1.h"
00025 #include "engines/grim/resource.h"
00026 #include "engines/grim/bitmap.h"
00027 #include "engines/grim/primitives.h"
00028 #include "engines/grim/iris.h"
00029 #include "engines/grim/gfx_base.h"
00030 #include "engines/grim/set.h"
00031 #include "actor.h"
00032 
00033 #include "engines/grim/movie/movie.h"
00034 
00035 #include "engines/grim/lua/lua.h"
00036 
00037 namespace Grim {
00038 
00039 void Lua_V1::GetImage() {
00040     lua_Object nameObj = lua_getparam(1);
00041     if (!lua_isstring(nameObj)) {
00042         lua_pushnil();
00043         return;
00044     }
00045     const char *bitmapName = lua_getstring(nameObj);
00046     Bitmap *b = Bitmap::create(bitmapName);
00047     lua_pushusertag(b->getId(), MKTAG('V','B','U','F'));
00048 }
00049 
00050 void Lua_V1::FreeImage() {
00051     lua_Object param = lua_getparam(1);
00052     if (!lua_isuserdata(param) || lua_tag(param) != MKTAG('V','B','U','F'))
00053         return;
00054     Bitmap *bitmap = getbitmap(param);
00055     delete bitmap;
00056 }
00057 
00058 void Lua_V1::BlastImage() {
00059     lua_Object param = lua_getparam(1);
00060     if (!lua_isuserdata(param) || lua_tag(param) != MKTAG('V','B','U','F'))
00061         return;
00062     Bitmap *bitmap = getbitmap(param);
00063     lua_Object xObj = lua_getparam(2);
00064     lua_Object yObj = lua_getparam(3);
00065     if (!lua_isnumber(xObj) || !lua_isnumber(yObj))
00066         return;
00067 
00068     int x = (int)lua_getnumber(xObj);
00069     int y = (int)lua_getnumber(yObj);
00070 //  bool transparent = getbool(4); // TODO transparent/masked copy into display
00071     bitmap->draw(x, y);
00072 }
00073 
00074 void Lua_V1::CleanBuffer() {
00075     g_driver->copyStoredToDisplay();
00076 }
00077 
00078 void Lua_V1::StartFullscreenMovie() {
00079     lua_Object name = lua_getparam(1);
00080     if (!lua_isstring(name)) {
00081         lua_pushnil();
00082         return;
00083     }
00084     Lua_V1::CleanBuffer();
00085 
00086     GrimEngine::EngineMode prevEngineMode = g_grim->getMode();
00087     g_grim->setMode(GrimEngine::SmushMode);
00088     g_grim->setMovieSubtitle(nullptr);
00089     bool looping = getbool(2);
00090     bool result = g_movie->play(lua_getstring(name), looping, 0, 0);
00091     if (!result)
00092         g_grim->setMode(prevEngineMode);
00093     pushbool(result);
00094 }
00095 
00096 void Lua_V1::StartMovie() {
00097     lua_Object name = lua_getparam(1);
00098     if (!lua_isstring(name)) {
00099         lua_pushnil();
00100         return;
00101     }
00102     int x = 0, y = 0;
00103     if (!lua_isnil(lua_getparam(3)))
00104         x = (int)lua_getnumber(lua_getparam(3));
00105     if (!lua_isnil(lua_getparam(4)))
00106         y = (int)lua_getnumber(lua_getparam(4));
00107 
00108     GrimEngine::EngineMode prevEngineMode = g_grim->getMode();
00109     g_grim->setMode(GrimEngine::NormalMode);
00110 
00111     bool looping = getbool(2);
00112     bool result = g_movie->play(lua_getstring(name), looping, x, y);
00113     g_grim->setMovieSetup();
00114     if (!result)
00115         g_grim->setMode(prevEngineMode);
00116     pushbool(result);
00117 }
00118 
00119 /* Fullscreen movie playing query and normal movie
00120  * query should actually detect correctly and not
00121  * just return true whenever ANY movie is playing
00122  */
00123 void Lua_V1::IsFullscreenMoviePlaying() {
00124     pushbool(g_movie->isPlaying());
00125 }
00126 
00127 void Lua_V1::IsMoviePlaying() {
00128     // Previously, if the game was *not* the demo, this checked also if the mode
00129     // was GrimEngine::NormalMode. This doesn't seem to be what original does, and causes
00130     // bug #301 because the movie eldepot.snm is played before legslide.snm ends.
00131     pushbool(g_movie->isPlaying());
00132 }
00133 
00134 void Lua_V1::StopMovie() {
00135     g_movie->stop();
00136     // Delete subtitles that may have not expired.
00137     g_grim->setMovieSubtitle(nullptr);
00138 }
00139 
00140 void Lua_V1::PauseMovie() {
00141     g_movie->pause(lua_isnil(lua_getparam(1)) == 0);
00142 }
00143 
00144 void Lua_V1::PurgePrimitiveQueue() {
00145     PrimitiveObject::getPool().deleteObjects();
00146 }
00147 
00148 void Lua_V1::DrawPolygon() {
00149     lua_Object tableObj1 = lua_getparam(1);
00150     if (!lua_istable(tableObj1)) {
00151         lua_pushnil();
00152         return;
00153     }
00154 
00155     //int layer = 2;
00156     Color color;
00157     lua_Object tableObj2 = lua_getparam(2);
00158     if (lua_istable(tableObj2)) {
00159         lua_pushobject(tableObj2);
00160         lua_pushstring("color");
00161         lua_Object colorObj = lua_gettable();
00162         if (lua_isuserdata(colorObj) && lua_tag(colorObj) == MKTAG('C','O','L','R')) {
00163             color = getcolor(colorObj);
00164         }
00165         lua_pushobject(tableObj2);
00166         lua_pushstring("layer");
00167         lua_Object layerObj = lua_gettable();
00168         if (lua_isnumber(layerObj))
00169             /*layer = (int)*/lua_getnumber(layerObj);
00170     }
00171 
00172     // This code only supports 4 point polygons because the game doesn't
00173     // use other than that. However, the original engine can support 
00174     // many points per polygon
00175     lua_Object pointObj;
00176     Common::Point p[4];
00177     for (int i = 0; i < 4; i++) {
00178         // Get X
00179         lua_pushobject(tableObj1);
00180         lua_pushnumber(i * 2 + 1);
00181         pointObj = lua_gettable();
00182         if (!lua_isnumber(pointObj)) {
00183             warning("Lua_V1::DrawPolygon: %i Point Parameter X isn't a number!", i * 2 + 1);
00184             return;
00185         }
00186         if (g_grim->getGameType() == GType_GRIM)
00187             p[i].x = (int)lua_getnumber(pointObj);
00188         else
00189             p[i].x = (int)((lua_getnumber(pointObj) + 1) * 320);
00190 
00191         // Get Y
00192         lua_pushobject(tableObj1);
00193         lua_pushnumber(i * 2 + 2);
00194         pointObj = lua_gettable();
00195         if (!lua_isnumber(pointObj)) {
00196             warning("Lua_V1::DrawPolygon: %i Point Parameter Y isn't a number!", i * 2 + 2);
00197             return;
00198         }
00199         if (g_grim->getGameType() == GType_GRIM)
00200             p[i].y = (int)lua_getnumber(pointObj);
00201         else
00202             p[i].y = (int)((1 - lua_getnumber(pointObj)) * 240);
00203     }
00204 
00205     PrimitiveObject *prim = new PrimitiveObject();
00206     prim->createPolygon(p[0], p[1], p[2], p[3], color);
00207     lua_pushusertag(prim->getId(), MKTAG('P','R','I','M'));
00208 }
00209 
00210 void Lua_V1::DrawLine() {
00211     Common::Point p1, p2;
00212     Color color;
00213     lua_Object x1Obj = lua_getparam(1);
00214     lua_Object y1Obj = lua_getparam(2);
00215     lua_Object x2Obj = lua_getparam(3);
00216     lua_Object y2Obj = lua_getparam(4);
00217     lua_Object tableObj = lua_getparam(5);
00218 
00219     if (!lua_isnumber(x1Obj) || !lua_isnumber(y1Obj) || !lua_isnumber(x2Obj) || !lua_isnumber(y2Obj)) {
00220         lua_pushnil();
00221         return;
00222     }
00223 
00224     if (g_grim->getGameType() == GType_GRIM) {
00225         p1.x = (int)lua_getnumber(x1Obj);
00226         p1.y = (int)lua_getnumber(y1Obj);
00227         p2.x = (int)lua_getnumber(x2Obj);
00228         p2.y = (int)lua_getnumber(y2Obj);
00229     } else {
00230         p1.x = (int)((lua_getnumber(x1Obj) + 1) * 320);
00231         p1.y = (int)((1 - lua_getnumber(y1Obj)) * 240);
00232         p2.x = (int)((lua_getnumber(x2Obj) + 1) * 320);
00233         p2.y = (int)((1 - lua_getnumber(y2Obj)) * 240);
00234     }
00235 
00236     //int layer = 2;
00237     if (lua_istable(tableObj)) {
00238         lua_pushobject(tableObj);
00239         lua_pushstring("color");
00240         lua_Object colorObj = lua_gettable();
00241         if (lua_isuserdata(colorObj) && lua_tag(colorObj) == MKTAG('C','O','L','R')) {
00242             color = getcolor(colorObj);
00243         }
00244         lua_pushobject(tableObj);
00245         lua_pushstring("layer");
00246         lua_Object layerObj = lua_gettable();
00247         if (lua_isnumber(layerObj))
00248             /*layer = (int)*/lua_getnumber(layerObj);
00249     }
00250 
00251     PrimitiveObject *p = new PrimitiveObject();
00252     p->createLine(p1, p2, color); // TODO Add layer support
00253     lua_pushusertag(p->getId(), MKTAG('P','R','I','M'));
00254 }
00255 
00256 void Lua_V1::ChangePrimitive() {
00257     lua_Object param1 = lua_getparam(1);
00258     if (!lua_isuserdata(param1) || lua_tag(param1) != MKTAG('P','R','I','M'))
00259         return;
00260 
00261     lua_Object tableObj = lua_getparam(2);
00262     if (!lua_istable(tableObj))
00263         return;
00264 
00265     PrimitiveObject *pmodify = getprimitive(param1);
00266     assert(pmodify);
00267 
00268     Color color;
00269     lua_pushobject(tableObj);
00270     lua_pushstring("color");
00271     lua_Object colorObj = lua_gettable();
00272     if (lua_isuserdata(colorObj) && lua_tag(colorObj) == MKTAG('C','O','L','R')) {
00273         color = getcolor(colorObj);
00274         pmodify->setColor(color);
00275     }
00276 
00277     lua_pushobject(tableObj);
00278     lua_pushstring("layer");
00279     lua_Object layer = lua_gettable();
00280     if (lua_isnumber(layer)) {
00281         // TODO pmodify->setLayer(lua_getnumber(layer));
00282         warning("Not implemented: PrimitiveObject::setLayer. Layer: %d", (int)lua_getnumber(layer));
00283     }
00284 
00285     lua_pushobject(tableObj);
00286     lua_pushstring("xoffset");
00287     lua_Object xObj = lua_gettable();
00288     lua_pushobject(tableObj);
00289     lua_pushstring("yoffset");
00290     lua_Object yObj = lua_gettable();
00291     if (lua_isnumber(xObj) || lua_isnumber(yObj)) {
00292         //int x = 0;
00293         //int y = 0;
00294         if (lua_isnumber(xObj))
00295             /*x = (int)*/lua_getnumber(xObj);
00296         if (lua_isnumber(yObj))
00297             /*y = (int)*/lua_getnumber(yObj);
00298         // TODO pmodify->setOffets(x, y);
00299         assert(0);
00300     }
00301 
00302     lua_pushobject(tableObj);
00303     lua_pushstring("x");
00304     xObj = lua_gettable();
00305     lua_pushobject(tableObj);
00306     lua_pushstring("y");
00307     yObj = lua_gettable();
00308     if (lua_isnumber(xObj) || lua_isnumber(yObj)) {
00309         int x = -1;
00310         int y = -1;
00311         if (lua_isnumber(xObj)) {
00312             if (g_grim->getGameType() == GType_GRIM)
00313                 x = (int)lua_getnumber(xObj);
00314             else
00315                 x = (int)((lua_getnumber(xObj) + 1) * 320);
00316         }
00317         if (lua_isnumber(yObj)) {
00318             if (g_grim->getGameType() == GType_GRIM)
00319                 y = (int)lua_getnumber(yObj);
00320             else
00321                 y = (int)((1 - lua_getnumber(yObj)) * 240);
00322         }
00323         pmodify->setPos(x, y);
00324     }
00325 
00326     lua_pushobject(tableObj);
00327     lua_pushstring("x2");
00328     xObj = lua_gettable();
00329     lua_pushobject(tableObj);
00330     lua_pushstring("y2");
00331     yObj = lua_gettable();
00332     if (lua_isnumber(xObj) || lua_isnumber(yObj)) {
00333         int x = -1;
00334         int y = -1;
00335         if (lua_isnumber(xObj)) {
00336             if (g_grim->getGameType() == GType_GRIM)
00337                 x = (int)lua_getnumber(xObj);
00338             else
00339                 x = (int)((lua_getnumber(xObj) + 1) * 320);
00340         }
00341         if (lua_isnumber(yObj)) {
00342             if (g_grim->getGameType() == GType_GRIM)
00343                 y = (int)lua_getnumber(yObj);
00344             else
00345                 y = (int)((1 - lua_getnumber(yObj)) * 240);
00346         }
00347         pmodify->setEndpoint(x, y);
00348     }
00349 
00350     lua_pushobject(tableObj);
00351     lua_pushstring("width");
00352     lua_Object width = lua_gettable();
00353     lua_pushobject(tableObj);
00354     lua_pushstring("height");
00355     lua_Object height = lua_gettable();
00356     if (lua_isnumber(width) || lua_isnumber(height)) {
00357         //int x = -1;
00358         //int y = -1;
00359         if (lua_isnumber(width))
00360             /*x = (int)*/lua_getnumber(width);
00361         if (lua_isnumber(height))
00362             /*y = (int)*/lua_getnumber(height);
00363         // TODO pmodify->setSize(x, y);
00364         assert(0);
00365     }
00366 }
00367 
00368 void Lua_V1::DrawRectangle() {
00369     Common::Point p1, p2;
00370     Color color;
00371     lua_Object x1Obj = lua_getparam(1);
00372     lua_Object y1Obj = lua_getparam(2);
00373     lua_Object x2Obj = lua_getparam(3);
00374     lua_Object y2Obj = lua_getparam(4);
00375     lua_Object tableObj = lua_getparam(5);
00376 
00377     if (!lua_isnumber(x1Obj) || !lua_isnumber(y1Obj) || !lua_isnumber(x2Obj) || !lua_isnumber(y2Obj)) {
00378         lua_pushnil();
00379         return;
00380     }
00381 
00382     if (g_grim->getGameType() == GType_GRIM) {
00383         p1.x = (int)lua_getnumber(x1Obj);
00384         p1.y = (int)lua_getnumber(y1Obj);
00385         p2.x = (int)lua_getnumber(x2Obj);
00386         p2.y = (int)lua_getnumber(y2Obj);
00387     } else {
00388         p1.x = (int)((lua_getnumber(x1Obj) + 1) * 320);
00389         p1.y = (int)((1 - lua_getnumber(y1Obj)) * 240);
00390         p2.x = (int)((lua_getnumber(x2Obj) + 1) * 320);
00391         p2.y = (int)((1 - lua_getnumber(y2Obj)) * 240);
00392     }
00393     bool filled = false;
00394 
00395     if (lua_istable(tableObj)) {
00396         lua_pushobject(tableObj);
00397         lua_pushstring("color");
00398         lua_Object colorObj = lua_gettable();
00399         if (lua_isuserdata(colorObj) && lua_tag(colorObj) == MKTAG('C','O','L','R')) {
00400             color = getcolor(colorObj);
00401         }
00402 
00403         lua_pushobject(tableObj);
00404         lua_pushstring("filled");
00405         lua_Object objFilled = lua_gettable();
00406         if (!lua_isnil(objFilled))
00407             filled = true;
00408     }
00409 
00410     PrimitiveObject *p = new PrimitiveObject();
00411     p->createRectangle(p1, p2, color, filled);
00412     lua_pushusertag(p->getId(), MKTAG('P','R','I','M')); // FIXME: we use PRIM usetag here
00413 }
00414 
00415 void Lua_V1::BlastRect() {
00416     Common::Point p1, p2;
00417     Color color;
00418     lua_Object x1Obj = lua_getparam(1);
00419     lua_Object y1Obj = lua_getparam(2);
00420     lua_Object x2Obj = lua_getparam(3);
00421     lua_Object y2Obj = lua_getparam(4);
00422     lua_Object tableObj = lua_getparam(5);
00423 
00424     if (!lua_isnumber(x1Obj) || !lua_isnumber(y1Obj) || !lua_isnumber(x2Obj) || !lua_isnumber(y2Obj)) {
00425         lua_pushnil();
00426         return;
00427     }
00428     if (g_grim->getGameType() == GType_GRIM) {
00429         p1.x = (int)lua_getnumber(x1Obj);
00430         p1.y = (int)lua_getnumber(y1Obj);
00431         p2.x = (int)lua_getnumber(x2Obj);
00432         p2.y = (int)lua_getnumber(y2Obj);
00433     } else {
00434         p1.x = (int)((lua_getnumber(x1Obj) + 1) * 320);
00435         p1.y = (int)((1 - lua_getnumber(y1Obj)) * 240);
00436         p2.x = (int)((lua_getnumber(x2Obj) + 1) * 320);
00437         p2.y = (int)((1 - lua_getnumber(y2Obj)) * 240);
00438     }
00439     bool filled = false;
00440 
00441     if (lua_istable(tableObj)) {
00442         lua_pushobject(tableObj);
00443         lua_pushstring("color");
00444         lua_Object colorObj = lua_gettable();
00445         if (lua_isuserdata(colorObj) && lua_tag(colorObj) == MKTAG('C','O','L','R')) {
00446             color = getcolor(colorObj);
00447         }
00448 
00449         lua_pushobject(tableObj);
00450         lua_pushstring("filled");
00451         lua_Object objFilled = lua_gettable();
00452         if (!lua_isnil(objFilled))
00453             filled = true;
00454     }
00455 
00456     PrimitiveObject *p = new PrimitiveObject();
00457     p->createRectangle(p1, p2, color, filled);
00458     p->draw();
00459     delete p;
00460 }
00461 
00462 void Lua_V1::KillPrimitive() {
00463     lua_Object primObj = lua_getparam(1);
00464 
00465     if (!lua_isuserdata(primObj) || lua_tag(primObj) != MKTAG('P','R','I','M'))
00466         return;
00467 
00468     PrimitiveObject *prim = getprimitive(primObj);
00469     delete prim;
00470 }
00471 
00472 void Lua_V1::DimScreen() {
00473     g_driver->storeDisplay();
00474     g_driver->dimScreen();
00475 }
00476 
00477 void Lua_V1::DimRegion() {
00478     int x = (int)lua_getnumber(lua_getparam(1));
00479     int y = (int)lua_getnumber(lua_getparam(2));
00480     int w = (int)lua_getnumber(lua_getparam(3));
00481     int h = (int)lua_getnumber(lua_getparam(4));
00482     float level = lua_getnumber(lua_getparam(5));
00483     g_driver->dimRegion(x, y, w, h, level);
00484 }
00485 
00486 void Lua_V1::ScreenShot() {
00487     int width = (int)lua_getnumber(lua_getparam(1));
00488     int height = (int)lua_getnumber(lua_getparam(2));
00489     GrimEngine::EngineMode mode = g_grim->getMode();
00490     g_grim->setMode(GrimEngine::NormalMode);
00491     g_grim->updateDisplayScene();
00492     Bitmap *screenshot = g_driver->getScreenshot(width, height, false);
00493     g_grim->setMode(mode);
00494     if (screenshot) {
00495         lua_pushusertag(screenshot->getId(), MKTAG('V','B','U','F'));
00496     } else {
00497         lua_pushnil();
00498     }
00499 }
00500 
00501 void Lua_V1::SetGamma() {
00502     lua_Object levelObj = lua_getparam(1);
00503 
00504     if (!lua_isnumber(levelObj))
00505         return;
00506     double level = lua_getnumber(levelObj);
00507 
00508     // FIXME: func(level)
00509     warning("Lua_V1::SetGamma, implement opcode, level: %f", level);
00510 }
00511 
00512 void Lua_V1::Display() {
00513     if (g_grim->getFlipEnable()) {
00514         g_driver->flipBuffer();
00515     }
00516 }
00517 
00518 void Lua_V1::EngineDisplay() {
00519     // it enable/disable updating display
00520     g_grim->setFlipEnable((bool)lua_getnumber(lua_getparam(1)));
00521 }
00522 
00523 void Lua_V1::ForceRefresh() {
00524     // Nothing to do, no off-screen buffers
00525 }
00526 
00527 void Lua_V1::RenderModeUser() {
00528     lua_Object param1 = lua_getparam(1);
00529     if (!lua_isnil(param1) && g_grim->getMode() != GrimEngine::DrawMode) {
00530         g_grim->setPreviousMode(g_grim->getMode());
00531         g_movie->pause(true);
00532         g_grim->setMode(GrimEngine::DrawMode);
00533     } else if (lua_isnil(param1) && g_grim->getMode() == GrimEngine::DrawMode) {
00534         g_movie->pause(false);
00535         g_grim->setMode(g_grim->getPreviousMode());
00536     }
00537 }
00538 
00539 void Lua_V1::IrisUp() {
00540     lua_Object xObj = lua_getparam(1);
00541     lua_Object yObj = lua_getparam(2);
00542     lua_Object timeObj = lua_getparam(3);
00543 
00544     g_grim->playIrisAnimation(Iris::Open, (int)lua_getnumber(xObj), (int)lua_getnumber(yObj), (int)lua_getnumber(timeObj));
00545 }
00546 
00547 void Lua_V1::IrisDown() {
00548     lua_Object xObj = lua_getparam(1);
00549     lua_Object yObj = lua_getparam(2);
00550     lua_Object timeObj = lua_getparam(3);
00551 
00552     g_grim->playIrisAnimation(Iris::Close, (int)lua_getnumber(xObj), (int)lua_getnumber(yObj), (int)lua_getnumber(timeObj));
00553 }
00554 
00555 void Lua_V1::PreRender() {
00556     g_driver->renderBitmaps(getbool(1));
00557     g_driver->renderZBitmaps(getbool(2));
00558 }
00559 
00560 } // end of namespace Grim


Generated on Sat May 25 2019 05:00:48 for ResidualVM by doxygen 1.7.1
curved edge   curved edge