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


Generated on Sat May 23 2020 05:00:32 for ResidualVM by doxygen 1.7.1
curved edge   curved edge