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

lua_v2.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 "common/endian.h"
00024 #include "common/foreach.h"
00025 #include "common/savefile.h"
00026 
00027 #include "engines/grim/emi/lua_v2.h"
00028 #include "engines/grim/emi/emi_registry.h"
00029 #include "engines/grim/emi/sound/emisound.h"
00030 #include "engines/grim/lua/lauxlib.h"
00031 #include "graphics/pixelbuffer.h"
00032 
00033 #include "engines/grim/resource.h"
00034 #include "engines/grim/set.h"
00035 #include "engines/grim/grim.h"
00036 #include "engines/grim/gfx_base.h"
00037 #include "engines/grim/font.h"
00038 
00039 #include "engines/grim/emi/layer.h"
00040 #include "engines/grim/emi/emi.h"
00041 
00042 #include "engines/grim/movie/movie.h"
00043 
00044 namespace Grim {
00045 
00046 void Lua_V2::UndimAll() {
00047     g_driver->setDimLevel(0);
00048     warning("Lua_V2::UndimAll: stub");
00049 }
00050 
00051 void Lua_V2::UndimRegion() {
00052     lua_Object regionObj = lua_getparam(1);
00053 
00054     if (lua_isnumber(regionObj)) {
00055         int region = (int)lua_getnumber(regionObj);
00056         // FIXME func(region);
00057         warning("Lua_V2::UndimRegion: region: %d", region);
00058     } else {
00059         lua_pushnil();
00060         // HACK: The demo uses this to undim the intro-screen.
00061         // thus UndimRegion(nil) might mean UndimScreen.
00062         g_driver->setDimLevel(0);
00063     }
00064 }
00065 
00066 void Lua_V2::DimScreen() {
00067     lua_Object dimObj = lua_getparam(1);
00068     float dim = 0.6999f;
00069 
00070     if (lua_isnumber(dimObj))
00071         dim = lua_getnumber(dimObj);
00072 
00073     g_driver->setDimLevel(dim);
00074     // FIXME func(dim);
00075     warning("Lua_V2::DimScreen: dim: %f", dim);
00076 }
00077 
00078 void Lua_V2::MakeCurrentSetup() {
00079     lua_Object setupObj = lua_getparam(1);
00080     if (lua_isnumber(setupObj)) {
00081         int num = (int)lua_getnumber(setupObj);
00082         g_grim->makeCurrentSetup(num);
00083     } else if (lua_isstring(setupObj)) {
00084         const char *setupName = lua_getstring(setupObj);
00085         error("Lua_V2::MakeCurrentSetup: Not implemented case: setup: %s", setupName);
00086     }
00087 }
00088 
00089 void Lua_V2::LockBackground() {
00090     lua_Object filenameObj = lua_getparam(1);
00091 
00092     if (!lua_isstring(filenameObj)) {
00093         lua_pushnil();
00094         return;
00095     }
00096     const char *filename = lua_getstring(filenameObj);
00097     warning("Lua_V2::LockBackground, filename: %s", filename);
00098     // FIXME: implement missing rest part of code
00099 }
00100 
00101 void Lua_V2::UnLockBackground() {
00102     lua_Object filenameObj = lua_getparam(1);
00103 
00104     if (!lua_isstring(filenameObj)) {
00105         lua_pushnil();
00106         return;
00107     }
00108 
00109     const char *filename = lua_getstring(filenameObj);
00110     // FIXME: implement missin code
00111     warning("Lua_V2::UnLockBackground: stub, filename: %s", filename);
00112 }
00113 
00114 void Lua_V2::MakeScreenTextures() {
00115     lua_Object indexObj = lua_getparam(1);
00116 
00117     if (!lua_isnil(indexObj) && lua_isnumber(indexObj)) {
00118         /*int index = (int)lua_getnumber(indexObj);*/
00119         // The index does not seem to matter
00120 
00121         g_driver->makeScreenTextures();
00122         lua_pushnumber(1.0);
00123     } else {
00124         lua_pushnil();
00125     }
00126 }
00127 
00128 void Lua_V2::ClearSpecialtyTexture() {
00129     //This seems to be used in the save/load menu
00130     //Not sure why the specialty textures need to be cleared.
00131     warning("Lua_V2::ClearSpecialtyTexture: stub");
00132 }
00133 
00134 void Lua_V2::LoadBundle() {
00135     lua_Object paramObj = lua_getparam(1);
00136     if (lua_isstring(paramObj) || lua_isnil(paramObj)) {
00137         const char *name = lua_getstring(paramObj);
00138         // FIXME: implement missing function
00139 /*      if (!func(name))
00140             lua_pushnil();
00141         else*/
00142             lua_pushnumber(1.0);
00143         warning("Lua_V2::LoadBundle: stub, name: %s", name);
00144     }
00145 }
00146 
00147 void Lua_V2::AreWeInternational() {
00148     if (g_grim->getGameLanguage() != Common::EN_ANY)
00149         lua_pushnumber(1.0);
00150 }
00151 
00152 void Lua_V2::GetCPUSpeed() {
00153     lua_pushnumber(500); // anything above 333 make best configuration
00154 }
00155 
00156 // This should be correct, judging by the Demo
00157 // the only real difference from L1 is the lack of looping
00158 void Lua_V2::StartMovie() {
00159     lua_Object name = lua_getparam(1);
00160     lua_Object subtitlesObj = lua_getparam(2);
00161 
00162     if (!lua_isstring(name)) {
00163         lua_pushnil();
00164         return;
00165     }
00166     Lua_V1::CleanBuffer();
00167 
00168     bool showSubtitles = false;
00169     if (lua_isnumber(subtitlesObj)) {
00170         if ((int)lua_getnumber(subtitlesObj)) {
00171             showSubtitles = true;
00172         }
00173     }
00174 
00175     GrimEngine::EngineMode prevEngineMode = g_grim->getMode();
00176     g_grim->setMode(GrimEngine::SmushMode);
00177     g_grim->setMovieSubtitle(nullptr);
00178     bool result = g_movie->play(lua_getstring(name), false, 0, 0, true, showSubtitles);
00179     if (!result)
00180         g_grim->setMode(prevEngineMode);
00181     pushbool(result);
00182 
00183     // The following line causes issues after 9547a9b61674546077301bf09f89a2d120046d8e
00184     //g_grim->setMode(GrimEngine::SmushMode);
00185 }
00186 
00187 void Lua_V2::EscapeMovie() {
00188     g_movie->stop();
00189 }
00190 
00191 void Lua_V2::IsMoviePlaying() {
00192     pushbool(g_movie->isPlaying());
00193 }
00194 
00195 void Lua_V2::SetActiveCD() {
00196     lua_Object cdObj = lua_getparam(1);
00197     int cd = (int)lua_getnumber(cdObj);
00198 
00199     if (cd == 1 || cd == 2) {
00200         warning("Lua_V2::GetActiveCD: set to CD: %d", cd);
00201         // FIXME
00202         lua_pushnumber(1.0);
00203     }
00204 }
00205 
00206 void Lua_V2::GetActiveCD() {
00207     // FIXME: return current CD number 1 or 2, original can also avoid push any numer
00208     warning("Lua_V2::GetActiveCD: return const CD 1");
00209     lua_pushnumber(1);
00210 }
00211 
00212 void Lua_V2::PurgeText() {
00213     g_emi->purgeText();
00214 }
00215 
00216 void Lua_V2::GetFontDimensions() {
00217     lua_Object fontObj = lua_getparam(1);
00218     if (!lua_isstring(fontObj))
00219         return;
00220 
00221     const char *fontName = lua_getstring(fontObj);
00222 
00223     Font *font = nullptr;
00224     foreach (Font *f, Font::getPool()) {
00225         if (f->getFilename() == fontName) {
00226             font = f;
00227         }
00228     }
00229     if (!font) {
00230         font = g_resourceloader->loadFont(fontName);
00231     }
00232     if (font) {
00233         int32 h = font->getBaseOffsetY();
00234         int32 w = font->getCharKernedWidth('w');
00235         lua_pushnumber(w);
00236         lua_pushnumber(h);
00237     } else {
00238         warning("Lua_V2::GetFontDimensions for font '%s': returns 0,0", fontName);
00239         lua_pushnumber(0.f);
00240         lua_pushnumber(0.f);
00241     }
00242 }
00243 
00244 void Lua_V2::GetTextCharPosition() {
00245     lua_Object textObj = lua_getparam(1);
00246     lua_Object posObj = lua_getparam(2);
00247     if (lua_isuserdata(textObj) && lua_tag(textObj) == MKTAG('T', 'E', 'X', 'T')) {
00248         TextObject *textObject = gettextobject(textObj);
00249         int pos = (int)lua_getnumber(posObj);
00250         float textPos = textObject->getTextCharPosition(pos);
00251         lua_pushnumber(textPos / 320.f);
00252     }
00253 }
00254 
00255 void Lua_V2::GetTextObjectDimensions() {
00256     lua_Object textObj = lua_getparam(1);
00257 
00258     if (lua_isuserdata(textObj) && lua_tag(textObj) == MKTAG('T', 'E', 'X', 'T')) {
00259         TextObject *textObject = gettextobject(textObj);
00260         lua_pushnumber(textObject->getBitmapWidth() / 320.f);
00261         lua_pushnumber(textObject->getBitmapHeight() / 240.f);
00262     }
00263 }
00264 
00265 void Lua_V2::ToggleOverworld() {
00266     lua_Object boolObj = lua_getparam(1);
00267     bool backToNormal = (lua_isnil(boolObj) == 0);
00268     if (backToNormal) {
00269         GrimEngine::EngineMode previous = g_grim->getPreviousMode();
00270         g_grim->setPreviousMode(GrimEngine::OverworldMode);
00271         // HACK: ToggleOverworld is only called after we load a save game.
00272         //       However, the engine saved PreviousMode as OverworldMode.
00273         //       Reset it to normal here.
00274         if (previous == GrimEngine::OverworldMode)
00275             previous = GrimEngine::NormalMode;
00276         g_grim->setMode(previous);
00277     } else {
00278         GrimEngine::EngineMode previous = g_grim->getMode();
00279         g_grim->setPreviousMode(previous);
00280         g_grim->setMode(GrimEngine::OverworldMode);
00281     }
00282 }
00283 
00284 void Lua_V2::ClearOverworld() {
00285     warning("Lua_V2::ClearOverworld: implement opcode");
00286 }
00287 
00288 void Lua_V2::ScreenshotForSavegame() {
00289     g_emi->temporaryStoreSaveGameImage();
00290 }
00291 
00292 void Lua_V2::EngineDisplay() {
00293     // dummy
00294 }
00295 
00296 void Lua_V2::SetAmbientLight() {
00297     // dummy
00298 }
00299 
00300 void Lua_V2::Display() {
00301     // dummy
00302 }
00303 
00304 void Lua_V2::GetCameraPosition() {
00305     Set::Setup *setup = g_grim->getCurrSet()->getCurrSetup();
00306     lua_pushnumber(setup->_pos.x());
00307     lua_pushnumber(setup->_pos.y());
00308     lua_pushnumber(setup->_pos.z());
00309 }
00310 
00311 void Lua_V2::GetCameraPitch() {
00312     Set *set = g_grim->getCurrSet();
00313     if (set == nullptr) {
00314         lua_pushnil();
00315         return;
00316     }
00317 
00318     Set::Setup *setup = set->getCurrSetup();
00319     float pitch;
00320     if (g_grim->getGameType() == GType_MONKEY4) {
00321         setup->getRotation(nullptr, nullptr, &pitch);
00322     } else {
00323         setup->getRotation(nullptr, &pitch, nullptr);
00324     }
00325     lua_pushnumber(pitch);
00326 }
00327 
00328 void Lua_V2::GetCameraYaw() {
00329     Set *set = g_grim->getCurrSet();
00330     if (set == nullptr) {
00331         lua_pushnil();
00332         return;
00333     }
00334 
00335     Set::Setup *setup = set->getCurrSetup();
00336     float yaw;
00337     if (g_grim->getGameType() == GType_MONKEY4) {
00338         setup->getRotation(nullptr, &yaw, nullptr);
00339     } else {
00340         setup->getRotation(&yaw, nullptr, nullptr);
00341     }
00342     lua_pushnumber(yaw);
00343 }
00344 
00345 void Lua_V2::GetCameraRoll() {
00346     Set *set = g_grim->getCurrSet();
00347     if (set == nullptr) {
00348         lua_pushnil();
00349         return;
00350     }
00351 
00352     Set::Setup *setup = set->getCurrSetup();
00353     float roll;
00354     if (g_grim->getGameType() == GType_MONKEY4) {
00355         setup->getRotation(&roll, nullptr, nullptr);
00356     } else {
00357         setup->getRotation(nullptr, nullptr, &roll);
00358     }
00359     lua_pushnumber(roll);
00360 }
00361 
00362 void Lua_V2::PitchCamera() {
00363     lua_Object pitchObj = lua_getparam(1);
00364     if (!lua_isnumber(pitchObj)) {
00365         error("Lua_V2::PitchCamera - Parameter is not a number!");
00366         return;
00367     }
00368 
00369     Set *set = g_grim->getCurrSet();
00370     if (set == nullptr)
00371         return;
00372 
00373     Set::Setup *setup = set->getCurrSetup();
00374     setup->setPitch(Math::Angle(lua_getnumber(pitchObj)));
00375 }
00376 
00377 void Lua_V2::YawCamera() {
00378     lua_Object yawObj = lua_getparam(1);
00379     if (!lua_isnumber(yawObj)) {
00380         error("Lua_V2::YawCamera - Parameter is not a number!");
00381         return;
00382     }
00383 
00384     Set *set = g_grim->getCurrSet();
00385     if (set == nullptr)
00386         return;
00387 
00388     Set::Setup *setup = set->getCurrSetup();
00389     setup->setYaw(Math::Angle(lua_getnumber(yawObj)));
00390 }
00391 
00392 void Lua_V2::RollCamera() {
00393     lua_Object rollObj = lua_getparam(1);
00394     if (!lua_isnumber(rollObj)) {
00395         error("Lua_V2::RollCamera - Parameter is not a number!");
00396         return;
00397     }
00398 
00399     Set *set = g_grim->getCurrSet();
00400     if (set == nullptr)
00401         return;
00402 
00403     Set::Setup *setup = set->getCurrSetup();
00404     setup->setRoll(Math::Angle(lua_getnumber(rollObj)));
00405 }
00406 
00407 void Lua_V2::PushText() {
00408     g_emi->pushText();
00409 }
00410 
00411 void Lua_V2::PopText() {
00412     g_emi->popText();
00413 }
00414 
00415 void Lua_V2::GetSectorName() {
00416     lua_Object xObj = lua_getparam(1);
00417     lua_Object yObj = lua_getparam(2);
00418     lua_Object zObj = lua_getparam(3);
00419 
00420     if (!lua_isnumber(xObj) || !lua_isnumber(yObj) || !lua_isnumber(zObj)) {
00421         lua_pushnil();
00422         return;
00423     }
00424     float x, y, z;
00425     x = lua_getnumber(xObj);
00426     y = lua_getnumber(yObj);
00427     z = lua_getnumber(zObj);
00428 
00429     Math::Vector3d pos(x, y, z);
00430     Set *set = g_grim->getCurrSet();
00431     Sector *sector = set->findPointSector(pos, Sector::NoneType);
00432     if (sector) {
00433         lua_pushstring(sector->getName().c_str());
00434     }
00435 }
00436 
00437 void Lua_V2::GammaEnabled() {
00438     warning("Lua_V2::GammaEnabled: implement opcode, pushing nil");
00439     lua_pushnil();
00440 }
00441 
00442 void Lua_V2::FileFindFirst() {
00443     lua_Object extObj = lua_getparam(1);
00444     if (!lua_isstring(extObj)) {
00445         lua_pushnil();
00446         return;
00447     }
00448 
00449     FileFindDispose();
00450 
00451     const char *extension = lua_getstring(extObj);
00452     if (0 == strncmp(extension, "Saves/", 6))
00453         extension += 6;
00454 
00455     // _menus.lua: saveload_menu.get_file_list searches for *.gsv.
00456     // This avoids conflicts with grim saves.
00457     if (0 == strcmp(extension, "*.gsv"))
00458         extension = "efmi###.gsv";
00459 
00460     Common::SaveFileManager *saveFileMan = g_system->getSavefileManager();
00461     g_grim->_listFiles = saveFileMan->listSavefiles(extension);
00462     Common::sort(g_grim->_listFiles.begin(), g_grim->_listFiles.end());
00463     g_grim->_listFilesIter = g_grim->_listFiles.begin();
00464 
00465     if (g_grim->_listFilesIter == g_grim->_listFiles.end())
00466         lua_pushnil();
00467     else
00468         FileFindNext();
00469 }
00470 
00471 void Lua_V2::ThumbnailFromFile() {
00472     lua_Object texIdObj = lua_getparam(1);
00473     lua_Object filenameObj = lua_getparam(2);
00474 
00475     if (!lua_isnumber(texIdObj) || !lua_isstring(filenameObj)) {
00476         warning("Lua_V2::ThumbnailFromFile: wrong parameters");
00477         return;
00478     }
00479     int index = (int)lua_getnumber(texIdObj);
00480     Common::String filename(lua_getstring(filenameObj));
00481     
00482     if (g_grim->getGameType() == GType_MONKEY4 &&
00483         g_grim->getGamePlatform() == Common::kPlatformPS2) {
00484         filename += ".ps2";
00485     }
00486 
00487     int width = 256, height = 128;
00488 
00489     SaveGame *savedState = SaveGame::openForLoading(filename);
00490     if (!savedState || !savedState->isCompatible()) {
00491         delete savedState;
00492         warning("Lua_V2::ThumbnailFromFile: savegame %s not compatible", filename.c_str());
00493         lua_pushnil();
00494         return;
00495     }
00496     int dataSize = savedState->beginSection('SIMG');
00497     if (dataSize != width * height * 2) {
00498         warning("Lua_V2::ThumbnailFromFile: savegame uses unexpected thumbnail size, ignore it");
00499         lua_pushnil();
00500         delete savedState;
00501         return;
00502     }
00503     uint16 *data = new uint16[dataSize / 2];
00504     for (int l = 0; l < dataSize / 2; l++) {
00505         data[l] = savedState->readLEUint16();
00506     }
00507     Graphics::PixelBuffer buf(Graphics::createPixelFormat<565>(), (byte *)data);
00508     Bitmap *screenshot = new Bitmap(buf, width, height, "screenshot");
00509     if (!screenshot) {
00510         lua_pushnil();
00511         warning("Lua_V2::ThumbnailFromFile: Could not restore screenshot from file %s", filename.c_str());
00512         delete screenshot;
00513         delete[] data;
00514         delete savedState;
00515         return;
00516     }
00517 
00518     screenshot->_data->convertToColorFormat(Graphics::PixelFormat(4, 8, 8, 8, 8, 0, 8, 16, 24));
00519     g_driver->createSpecialtyTexture(index, screenshot->getData(0).getRawBuffer(), width, height);
00520     delete screenshot;
00521     delete[] data;
00522     savedState->endSection();
00523     delete savedState;
00524 
00525     pushbool(true);
00526 }
00527 
00528 void Lua_V2::GetMemoryCardId() {
00529     // 0 - No mem card
00530     // 1 - Not formatted
00531     // 2 - Not enough space
00532     // 3 - Error occured
00533     lua_pushnumber(4);
00534 }
00535 
00536 void Lua_V2::SetReplayMode() {
00537     lua_Object intObj = lua_getparam(1);
00538     lua_Object strObj = lua_getparam(2);
00539 
00540     if (!lua_isnumber(intObj) || (!lua_isnil(strObj) && !lua_isstring(strObj))) {
00541         warning("Lua_V2::SetReplayMode: wrong parameters");
00542         return;
00543     }
00544 
00545     int num = lua_getnumber(intObj);
00546     if (lua_isstring(strObj)) {
00547         const char *str = lua_getstring(strObj);
00548         warning("SetReplayMode(%d, %s)", num, str);
00549     } else {
00550         warning("SetReplayMode(%d)", num);
00551     }
00552 }
00553 
00554 void Lua_V2::LocalizeString() {
00555     char msgId[50], buf[1000];
00556     lua_Object strObj = lua_getparam(1);
00557     msgId[0] = 0;
00558 
00559     if (lua_isstring(strObj)) {
00560         const char *str = lua_getstring(strObj);
00561         Common::String msg = parseMsgText(str, msgId);
00562         sprintf(buf, "/%s/%s", msgId, msg.c_str());
00563 
00564         lua_pushstring(buf);
00565     }
00566 }
00567 
00568 void Lua_V2::OverWorldToScreen() { // TODO
00569     lua_Object param1 = lua_getparam(1);
00570     lua_Object param2 = lua_getparam(2);
00571     lua_Object param3 = lua_getparam(3);
00572 
00573     float x = 0, y = 0, z = 0;
00574     if (!lua_isnumber(param1) || !lua_isnumber(param2) || !lua_isnumber(param3)) {
00575         error("Param not a number for OverWorldToScreen");
00576     } else {
00577         x = lua_getnumber(param1);
00578         y = lua_getnumber(param2);
00579         z = lua_getnumber(param3);
00580     }
00581 
00582     warning("Stub function: OverWorldToScreen(%f, %f, %f) - returning 0,0", x, y, z);
00583 
00584     lua_pushnumber(0);
00585     lua_pushnumber(0);
00586 }
00587 
00588 void Lua_V2::WorldToScreen() {
00589     lua_Object xObj = lua_getparam(1);
00590     lua_Object yObj = lua_getparam(2);
00591     lua_Object zObj = lua_getparam(3);
00592     if (!lua_isnumber(xObj) || !lua_isnumber(yObj) || !lua_isnumber(zObj)) {
00593         lua_pushnumber(0.0);
00594         lua_pushnumber(0.0);
00595         return;
00596     }
00597 
00598     float x = lua_getnumber(xObj);
00599     float y = lua_getnumber(yObj);
00600     float z = lua_getnumber(zObj);
00601     Math::Vector3d pos = Math::Vector3d(x, y, z);
00602 
00603     const Set::Setup *setup = g_emi->getCurrSet()->getCurrSetup();
00604     Math::Matrix4 view = setup->_rot;
00605     view.transpose();
00606 
00607     pos -= setup->_pos;
00608     pos = view.getRotation() * pos;
00609     pos.z() = -pos.z();
00610 
00611     Math::Matrix4 proj = GfxBase::makeProjMatrix(setup->_fov, setup->_nclip, setup->_fclip);
00612     proj.transpose();
00613     Math::Vector4d screen = proj * Math::Vector4d(pos.x(), pos.y(), pos.z(), 1.0);
00614     screen /= screen.w();
00615 
00616     lua_pushnumber(screen.x());
00617     lua_pushnumber(screen.y());
00618 }
00619 
00620 void Lua_V2::NewLayer() {
00621     lua_Object param1 = lua_getparam(1);
00622     lua_Object param2 = lua_getparam(2);
00623     lua_Object param3 = lua_getparam(3);
00624 
00625     const char *til = nullptr;
00626     int sortorder = 0; // zero = 0;
00627     if (lua_isstring(param1) && lua_isnumber(param2) && lua_isnumber(param3)) {
00628         til = lua_getstring(param1);
00629         sortorder = (int)lua_getnumber(param2);
00630 
00631         //This one is always specified, but also always 0...
00632         //zero = (int)lua_getnumber(param3);
00633 
00634         Layer *layer = new Layer(til, sortorder);
00635 
00636         // Need to return something that can be looked up later
00637         lua_pushusertag(layer->getId(), MKTAG('L','A','Y','R'));
00638     }
00639 }
00640 
00641 void Lua_V2::FreeLayer() {
00642     lua_Object param1 = lua_getparam(1);
00643     if (lua_isuserdata(param1) && lua_tag(param1) == MKTAG('L','A','Y','R')) {
00644         int layer = (int)lua_getuserdata(param1);
00645         Layer *l = Layer::getPool().getObject(layer);
00646         delete l;
00647     }
00648 }
00649 
00650 void Lua_V2::AdvanceLayerFrame() {
00651     lua_Object param1 = lua_getparam(1);
00652     lua_Object param2 = lua_getparam(2);
00653     if (lua_isuserdata(param1) && lua_tag(param1) == MKTAG('L','A','Y','R') && lua_isnumber(param2)) {
00654         int layer = (int)lua_getuserdata(param1);
00655         int one = (int)lua_getnumber(param2);
00656         Layer *l = Layer::getPool().getObject(layer);
00657         if (!l) {
00658             warning("Lua_V2::AdvanceLayerFrame: no layer found");
00659             return;
00660         }
00661         l->advanceFrame(one);
00662     }
00663 }
00664 
00665 void Lua_V2::SetLayerFrame() {
00666     lua_Object param1 = lua_getparam(1);
00667     lua_Object param2 = lua_getparam(2);
00668     if (lua_isuserdata(param1) && lua_tag(param1) == MKTAG('L','A','Y','R') && lua_isnumber(param2)) {
00669         int layer = (int)lua_getuserdata(param1);
00670         int one = (int)lua_getnumber(param2);
00671         Layer *l = Layer::getPool().getObject(layer);
00672         l->setFrame(one);
00673     }
00674 }
00675 
00676 void Lua_V2::SetLayerSortOrder() {
00677     lua_Object param1 = lua_getparam(1);
00678     lua_Object param2 = lua_getparam(2);
00679     if (lua_isuserdata(param1) && lua_tag(param1) == MKTAG('L','A','Y','R') && lua_isnumber(param2)) {
00680         int layer = (int)lua_getuserdata(param1);
00681         int sortorder = (int)lua_getnumber(param2);
00682         Layer *l = Layer::getPool().getObject(layer);
00683         l->setSortOrder(sortorder);
00684     } else {
00685         warning("Lua_V2::SetLayerSortOrder: wrong parameters");
00686     }
00687 }
00688 
00689 // Stub function for builtin functions not yet implemented
00690 /*static void stubWarning(const char *funcName) {
00691     warning("Stub function: %s", funcName);
00692 }*/
00693 
00694 static void stubError(const char *funcName) {
00695     error("Stub function: %s", funcName);
00696 }
00697 
00698 #define STUB_FUNC(name) void name() { stubWarning(#name); }
00699 #define STUB_FUNC2(name) void name() { stubError(#name); }
00700 
00701 // Opcodes more or less differ to Grim Lua_V1::* LUA_OPCODEs
00702 // STUB_FUNC2(Lua_V2::SetActorWalkChore)
00703 // STUB_FUNC2(Lua_V2::SetActorTurnChores)
00704 // STUB_FUNC2(Lua_V2::SetActorRestChore)
00705 // STUB_FUNC2(Lua_V2::SetActorMumblechore)
00706 // STUB_FUNC2(Lua_V2::SetActorTalkChore)
00707 // STUB_FUNC2(Lua_V2::SetActorLookRate)
00708 // STUB_FUNC2(Lua_V2::GetActorLookRate)
00709 // STUB_FUNC2(Lua_V2::GetVisibleThings)
00710 // STUB_FUNC2(Lua_V2::GetActorRot)
00711 // STUB_FUNC2(Lua_V2::LockSet)
00712 // STUB_FUNC2(Lua_V2::UnLockSet)
00713 // STUB_FUNC2(Lua_V2::PlaySound)
00714 // STUB_FUNC2(Lua_V2::IsSoundPlaying)
00715 // STUB_FUNC2(Lua_V2::MakeSectorActive)
00716 // STUB_FUNC2(Lua_V2::TurnActorTo)
00717 // STUB_FUNC2(Lua_V2::GetAngleBetweenActors)
00718 // STUB_FUNC2(Lua_V2::ImStartSound)
00719 // STUB_FUNC2(Lua_V2::ImGetSfxVol)
00720 // STUB_FUNC2(Lua_V2::ImGetVoiceVol)
00721 // STUB_FUNC2(Lua_V2::ImGetMusicVol)
00722 // STUB_FUNC2(Lua_V2::ImSetSequence)
00723 // STUB_FUNC2(Lua_V2::ChangeTextObject)
00724 // STUB_FUNC2(Lua_V2::GetTextCharPosition)
00725 // STUB_FUNC2(Lua_V2::SetOffscreenTextPos)
00726 // STUB_FUNC2(Lua_V2::FadeInChore)
00727 // STUB_FUNC2(Lua_V2::FadeOutChore)
00728 // STUB_FUNC2(Lua_V2::SetLightPosition)
00729 // STUB_FUNC2(Lua_V2::GetAngleBetweenVectors)
00730 // STUB_FUNC2(Lua_V2::IsPointInSector)
00731 
00732 // Stubbed functions with semi-known arguments:
00733 // TODO: Verify and implement these: (And add type-checking), also rename params
00734 void Lua_V2::NukeAllScriptLocks() {
00735     warning("Lua_V2::NukeAllScriptLocks() - TODO: Implement opcode");
00736 }
00737 
00738 void Lua_V2::FRUTEY_Begin() {
00739     lua_Object param1 = lua_getparam(1);
00740 
00741     if (!lua_isstring(param1))
00742         error("Lua_V2::FRUTEY_Begin - Unknown parameters");
00743 
00744     const char *paramText = lua_getstring(param1);
00745     error("Lua_V2::FRUTEY_Begin(%s) - TODO: Implement opcode", paramText);
00746 }
00747 
00748 void Lua_V2::FRUTEY_End() {
00749     error("Lua_V2::FRUTEY_End() - TODO: Implement opcode");
00750 }
00751 
00752 void Lua_V2::RenderModeUser() {
00753     lua_Object param1 = lua_getparam(1);
00754     if (!lua_isnil(param1) && g_grim->getMode() != GrimEngine::DrawMode) {
00755         g_grim->setPreviousMode(g_grim->getMode());
00756         g_movie->pause(true);
00757         g_emiSound->pause(true);
00758         g_grim->setMode(GrimEngine::DrawMode);
00759     } else if (lua_isnil(param1) && g_grim->getMode() == GrimEngine::DrawMode) {
00760         g_movie->pause(false);
00761         g_emiSound->pause(false);
00762         g_grim->setMode(g_grim->getPreviousMode());
00763     }
00764 }
00765 
00766 // Monkey specific LUA_OPCODEs
00767 STUB_FUNC2(Lua_V2::ToggleDebugDraw)
00768 STUB_FUNC2(Lua_V2::ToggleDrawCameras)
00769 STUB_FUNC2(Lua_V2::ToggleDrawLights)
00770 STUB_FUNC2(Lua_V2::ToggleDrawSectors)
00771 STUB_FUNC2(Lua_V2::ToggleDrawBBoxes)
00772 STUB_FUNC2(Lua_V2::ToggleDrawFPS)
00773 STUB_FUNC2(Lua_V2::ToggleDrawPerformance)
00774 STUB_FUNC2(Lua_V2::ToggleDrawActorStats)
00775 STUB_FUNC2(Lua_V2::SectEditSelect)
00776 STUB_FUNC2(Lua_V2::SectEditPlace)
00777 STUB_FUNC2(Lua_V2::SectEditDelete)
00778 STUB_FUNC2(Lua_V2::SectEditInsert)
00779 STUB_FUNC2(Lua_V2::SectEditSortAdd)
00780 STUB_FUNC2(Lua_V2::SectEditForgetIt)
00781 
00782 // ResidualVM-hacks:
00783 void Lua_V2::GetResidualVMPreference() {
00784     lua_Object keyObj = lua_getparam(1);
00785 
00786     if (lua_isstring(keyObj)) {
00787         const Common::String key = lua_getstring(keyObj);
00788 
00789         float value;
00790         if (g_emiregistry->Get(key, value))
00791             lua_pushnumber(value);
00792         else
00793             lua_pushnil();
00794     } else
00795         lua_pushnil();
00796 }
00797 
00798 void Lua_V2::SetResidualVMPreference()  {
00799     lua_Object keyObj = lua_getparam(1);
00800     lua_Object valueObj = lua_getparam(2);
00801 
00802     if (lua_isstring(keyObj) && lua_isnumber(valueObj)) {
00803         const Common::String key = lua_getstring(keyObj);
00804         float value = lua_getnumber(valueObj);
00805 
00806         g_emiregistry->Set(key, value);
00807     }
00808 }
00809 
00810 struct luaL_reg monkeyMainOpcodes[] = {
00811     // Monkey specific LUA_OPCODEs:
00812     { "ScreenshotForSavegame", LUA_OPCODE(Lua_V2, ScreenshotForSavegame) },
00813     { "GetActorWorldPos", LUA_OPCODE(Lua_V2, GetActorWorldPos) },
00814     { "SetActiveCD", LUA_OPCODE(Lua_V2, SetActiveCD) },
00815     { "GetActiveCD", LUA_OPCODE(Lua_V2, GetActiveCD) },
00816     { "AreWeInternational", LUA_OPCODE(Lua_V2, AreWeInternational) },
00817     { "MakeScreenTextures", LUA_OPCODE(Lua_V2, MakeScreenTextures) },
00818     { "ThumbnailFromFile", LUA_OPCODE(Lua_V2, ThumbnailFromFile) },
00819     { "ClearSpecialtyTexture", LUA_OPCODE(Lua_V2, ClearSpecialtyTexture) },
00820     { "UnloadActor", LUA_OPCODE(Lua_V2, UnloadActor) },
00821     { "PutActorInOverworld", LUA_OPCODE(Lua_V2, PutActorInOverworld) },
00822     { "RemoveActorFromOverworld", LUA_OPCODE(Lua_V2, RemoveActorFromOverworld) },
00823     { "ClearOverworld", LUA_OPCODE(Lua_V2, ClearOverworld) },
00824     { "ToggleOverworld", LUA_OPCODE(Lua_V2, ToggleOverworld) },
00825     { "ActorStopMoving", LUA_OPCODE(Lua_V2, ActorStopMoving) },
00826     { "SetActorFOV", LUA_OPCODE(Lua_V2, SetActorFOV) },
00827     { "SetActorLighting", LUA_OPCODE(Lua_V2, SetActorLighting) },
00828     { "SetActorHeadLimits", LUA_OPCODE(Lua_V2, SetActorHeadLimits) },
00829     { "ActorActivateShadow", LUA_OPCODE(Lua_V2, ActorActivateShadow) },
00830     { "EnableActorPuck", LUA_OPCODE(Lua_V2, EnableActorPuck) },
00831     { "SetActorGlobalAlpha", LUA_OPCODE(Lua_V2, SetActorGlobalAlpha) },
00832     { "SetActorLocalAlpha", LUA_OPCODE(Lua_V2, SetActorLocalAlpha) },
00833     { "SetActorSortOrder", LUA_OPCODE(Lua_V2, SetActorSortOrder) },
00834     { "GetActorSortOrder", LUA_OPCODE(Lua_V2, GetActorSortOrder) },
00835     { "AttachActor", LUA_OPCODE(Lua_V2, AttachActor) },
00836     { "DetachActor", LUA_OPCODE(Lua_V2, DetachActor) },
00837     { "IsChoreValid", LUA_OPCODE(Lua_V2, IsChoreValid) },
00838     { "IsChorePlaying", LUA_OPCODE(Lua_V2, IsChorePlaying) },
00839     { "IsChoreLooping", LUA_OPCODE(Lua_V2, IsChoreLooping) },
00840     { "SetChoreLooping", LUA_OPCODE(Lua_V2, SetChoreLooping) },
00841     { "StopActorChores", LUA_OPCODE(Lua_V2, StopActorChores) },
00842     { "PlayChore", LUA_OPCODE(Lua_V2, PlayChore) },
00843     { "StopChore", LUA_OPCODE(Lua_V2, StopChore) },
00844     { "PauseChore", LUA_OPCODE(Lua_V2, PauseChore) },
00845     { "AdvanceChore", LUA_OPCODE(Lua_V2, AdvanceChore) },
00846     { "CompleteChore", LUA_OPCODE(Lua_V2, CompleteChore) },
00847     { "LockChore", LUA_OPCODE(Lua_V2, LockChore) },
00848     { "UnlockChore", LUA_OPCODE(Lua_V2, UnlockChore) },
00849     { "LockChoreSet", LUA_OPCODE(Lua_V2, LockChoreSet) },
00850     { "UnlockChoreSet", LUA_OPCODE(Lua_V2, UnlockChoreSet) },
00851     { "LockBackground", LUA_OPCODE(Lua_V2, LockBackground) },
00852     { "UnLockBackground", LUA_OPCODE(Lua_V2, UnLockBackground) },
00853     { "EscapeMovie", LUA_OPCODE(Lua_V2, EscapeMovie) },
00854     { "StopAllSounds", LUA_OPCODE(Lua_V2, StopAllSounds) },
00855     { "LoadSound", LUA_OPCODE(Lua_V2, LoadSound) },
00856     { "FreeSound", LUA_OPCODE(Lua_V2, FreeSound) },
00857     { "PlayLoadedSound", LUA_OPCODE(Lua_V2, PlayLoadedSound) },
00858     { "StopSound", LUA_OPCODE(Lua_V2, StopSound) },
00859     { "SetGroupVolume", LUA_OPCODE(Lua_V2, SetGroupVolume) },
00860     { "GetSoundVolume", LUA_OPCODE(Lua_V2, GetSoundVolume) },
00861     { "SetSoundVolume", LUA_OPCODE(Lua_V2, SetSoundVolume) },
00862     { "EnableAudioGroup", LUA_OPCODE(Lua_V2, EnableAudioGroup) },
00863     { "EnableVoiceFX", LUA_OPCODE(Lua_V2, EnableVoiceFX) },
00864     { "PlaySoundFrom", LUA_OPCODE(Lua_V2, PlaySoundFrom) },
00865     { "PlayLoadedSoundFrom", LUA_OPCODE(Lua_V2, PlayLoadedSoundFrom) },
00866     { "SetReverb", LUA_OPCODE(Lua_V2, SetReverb) },
00867     { "UpdateSoundPosition", LUA_OPCODE(Lua_V2, UpdateSoundPosition) },
00868     { "ImSelectSet", LUA_OPCODE(Lua_V2, ImSelectSet) },
00869     { "ImStateHasLooped", LUA_OPCODE(Lua_V2, ImStateHasLooped) },
00870     { "ImStateHasEnded", LUA_OPCODE(Lua_V2, ImStateHasEnded) },
00871     { "ImPushState", LUA_OPCODE(Lua_V2, ImPushState) },
00872     { "ImPopState", LUA_OPCODE(Lua_V2, ImPopState) },
00873     { "ImFlushStack", LUA_OPCODE(Lua_V2, ImFlushStack) },
00874     { "ImGetMillisecondPosition", LUA_OPCODE(Lua_V2, ImGetMillisecondPosition) },
00875     { "GetSectorName", LUA_OPCODE(Lua_V2, GetSectorName) },
00876     { "GetCameraYaw", LUA_OPCODE(Lua_V2, GetCameraYaw) },
00877     { "YawCamera", LUA_OPCODE(Lua_V2, YawCamera) },
00878     { "GetCameraPitch", LUA_OPCODE(Lua_V2, GetCameraPitch) },
00879     { "PitchCamera", LUA_OPCODE(Lua_V2, PitchCamera) },
00880     { "RollCamera", LUA_OPCODE(Lua_V2, RollCamera) },
00881     { "UndimAll", LUA_OPCODE(Lua_V2, UndimAll) },
00882     { "UndimRegion", LUA_OPCODE(Lua_V2, UndimRegion) },
00883     { "GetCPUSpeed", LUA_OPCODE(Lua_V2, GetCPUSpeed) },
00884     { "NewLayer", LUA_OPCODE(Lua_V2, NewLayer) },
00885     { "FreeLayer", LUA_OPCODE(Lua_V2, FreeLayer) },
00886     { "SetLayerSortOrder", LUA_OPCODE(Lua_V2, SetLayerSortOrder) },
00887     { "SetLayerFrame", LUA_OPCODE(Lua_V2, SetLayerFrame) },
00888     { "AdvanceLayerFrame", LUA_OPCODE(Lua_V2, AdvanceLayerFrame) },
00889     { "PushText", LUA_OPCODE(Lua_V2, PushText) },
00890     { "PopText", LUA_OPCODE(Lua_V2, PopText) },
00891     { "NukeAllScriptLocks", LUA_OPCODE(Lua_V2, NukeAllScriptLocks) },
00892     { "ToggleDebugDraw", LUA_OPCODE(Lua_V2, ToggleDebugDraw) },
00893     { "ToggleDrawCameras", LUA_OPCODE(Lua_V2, ToggleDrawCameras) },
00894     { "ToggleDrawLights", LUA_OPCODE(Lua_V2, ToggleDrawLights) },
00895     { "ToggleDrawSectors", LUA_OPCODE(Lua_V2, ToggleDrawSectors) },
00896     { "ToggleDrawBBoxes", LUA_OPCODE(Lua_V2, ToggleDrawBBoxes) },
00897     { "ToggleDrawFPS", LUA_OPCODE(Lua_V2, ToggleDrawFPS) },
00898     { "ToggleDrawPerformance", LUA_OPCODE(Lua_V2, ToggleDrawPerformance) },
00899     { "ToggleDrawActorStats", LUA_OPCODE(Lua_V2, ToggleDrawActorStats) },
00900     { "SectEditSelect", LUA_OPCODE(Lua_V2, SectEditSelect) },
00901     { "SectEditPlace", LUA_OPCODE(Lua_V2, SectEditPlace) },
00902     { "SectEditDelete", LUA_OPCODE(Lua_V2, SectEditDelete) },
00903     { "SectEditInsert", LUA_OPCODE(Lua_V2, SectEditInsert) },
00904     { "SectEditSortAdd", LUA_OPCODE(Lua_V2, SectEditSortAdd) },
00905     { "SectEditForgetIt", LUA_OPCODE(Lua_V2, SectEditForgetIt) },
00906     { "GammaEnabled", LUA_OPCODE(Lua_V2, GammaEnabled) },
00907     { "FRUTEY_Begin", LUA_OPCODE(Lua_V2, FRUTEY_Begin) },
00908     { "FRUTEY_End", LUA_OPCODE(Lua_V2, FRUTEY_End) },
00909     { "LocalizeString", LUA_OPCODE(Lua_V2, LocalizeString) },
00910 // PS2:
00911     { "GetMemoryCardId", LUA_OPCODE(Lua_V2, GetMemoryCardId) },
00912     { "OverWorldToScreen", LUA_OPCODE(Lua_V2, OverWorldToScreen) },
00913     { "SetReplayMode", LUA_OPCODE(Lua_V2, SetReplayMode) },
00914 // ResidualVM-hacks:
00915     { "GetResidualVMPreference", LUA_OPCODE(Lua_V2, GetResidualVMPreference) },
00916     { "SetResidualVMPreference", LUA_OPCODE(Lua_V2, SetResidualVMPreference) }
00917 };
00918 
00919 void Lua_V2::registerOpcodes() {
00920     Lua_V1::registerOpcodes();
00921 
00922     // Register main opcodes functions
00923     luaL_openlib(monkeyMainOpcodes, ARRAYSIZE(monkeyMainOpcodes));
00924 }
00925 
00926 } // end of namespace Grim


Generated on Sat Dec 7 2019 05:00:31 for ResidualVM by doxygen 1.7.1
curved edge   curved edge