From 1ac407f32b2abdc4998a0bc0bb40eb79a648baf7 Mon Sep 17 00:00:00 2001 From: Sebastian Fieber Date: Tue, 29 Apr 2025 01:42:38 +0200 Subject: [PATCH] fix rebase error --- apps/openmw/mwlua/corebindings.cpp | 124 ----------------------------- 1 file changed, 124 deletions(-) diff --git a/apps/openmw/mwlua/corebindings.cpp b/apps/openmw/mwlua/corebindings.cpp index ff1496fd40..2c3b0475ba 100644 --- a/apps/openmw/mwlua/corebindings.cpp +++ b/apps/openmw/mwlua/corebindings.cpp @@ -151,130 +151,6 @@ namespace MWLua }; } - api["getHeightAt"] = [](const osg::Vec3f& pos, sol::object cellOrName) { - ESM::RefId worldspace; - if (cellOrName.is()) - worldspace = cellOrName.as().mStore->getCell()->getWorldSpace(); - else if (cellOrName.is() && !cellOrName.as().empty()) - worldspace = MWBase::Environment::get() - .getWorldModel() - ->getCell(cellOrName.as()) - .getCell() - ->getWorldSpace(); - else - worldspace = ESM::Cell::sDefaultWorldspaceId; - - const float cellSize = ESM::getCellSize(worldspace); - int cellX = static_cast(std::floor(pos.x() / cellSize)); - int cellY = static_cast(std::floor(pos.y() / cellSize)); - - auto store = MWBase::Environment::get().getESMStore(); - auto landStore = store->get(); - auto land = landStore.search(cellX, cellY); - const ESM::Land::LandData* landData = nullptr; - if (land != nullptr) - { - landData = land->getLandData(ESM::Land::DATA_VHGT); - if (landData != nullptr) - { - // Ensure data is loaded if necessary - land->loadData(ESM::Land::DATA_VHGT); - landData = land->getLandData(ESM::Land::DATA_VHGT); - } - } - if (landData == nullptr) - { - // If we failed to load data, return the default height - return static_cast(ESM::Land::DEFAULT_HEIGHT); - } - return ESMTerrain::Storage::getHeightAt(landData->mHeights, landData->sLandSize, pos, cellSize); - }; - - api["getLandTextureAt"] = [lua = context.mLua](const osg::Vec3f& pos, sol::object cellOrName) { - sol::variadic_results values; - ESM::RefId worldspace; - if (cellOrName.is()) - worldspace = cellOrName.as().mStore->getCell()->getWorldSpace(); - else if (cellOrName.is() && !cellOrName.as().empty()) - worldspace = MWBase::Environment::get() - .getWorldModel() - ->getCell(cellOrName.as()) - .getCell() - ->getWorldSpace(); - else - worldspace = ESM::Cell::sDefaultWorldspaceId; - - const float cellSize = ESM::getCellSize(worldspace); - - int cellX = static_cast(std::floor(pos.x() / cellSize)); - int cellY = static_cast(std::floor(pos.y() / cellSize)); - - auto store = MWBase::Environment::get().getESMStore(); - // We need to read land twice. Once to get the amount of texture samples per cell edge, and the second time - // to get the actual data - auto landStore = store->get(); - auto land = landStore.search(cellX, cellY); - const ESM::Land::LandData* landData = nullptr; - if (land != nullptr) - { - landData = land->getLandData(ESM::Land::DATA_VTEX); - if (landData != nullptr) - { - // Ensure data is loaded if necessary - land->loadData(ESM::Land::DATA_VTEX); - landData = land->getLandData(ESM::Land::DATA_VTEX); - } - } - if (landData == nullptr) - { - // If we fail to preload land data, return, we need to be able to get *any* land to know how to correct - // the position used to sample terrain - return values; - } - - const osg::Vec3f correctedPos - = ESMTerrain::Storage::getTextureCorrectedWorldPos(pos, landData->sLandTextureSize, cellSize); - int correctedCellX = static_cast(std::floor(correctedPos.x() / cellSize)); - int correctedCellY = static_cast(std::floor(correctedPos.y() / cellSize)); - auto correctedLand = landStore.search(correctedCellX, correctedCellY); - const ESM::Land::LandData* correctedLandData = nullptr; - if (correctedLand != nullptr) - { - correctedLandData = correctedLand->getLandData(ESM::Land::DATA_VTEX); - if (correctedLandData != nullptr) - { - // Ensure data is loaded if necessary - land->loadData(ESM::Land::DATA_VTEX); - correctedLandData = correctedLand->getLandData(ESM::Land::DATA_VTEX); - } - } - if (correctedLandData == nullptr) - { - return values; - } - - // We're passing in sLandTextureSize, NOT sLandSize like with getHeightAt - const ESMTerrain::UniqueTextureId textureId - = ESMTerrain::Storage::getLandTextureAt(correctedLandData->mTextures, correctedLand->getPlugin(), - correctedLandData->sLandTextureSize, correctedPos, cellSize); - - // Need to check for 0, 0 so that we can safely subtract 1 later, as per documentation on UniqueTextureId - if (textureId.first != 0) - { - values.push_back(sol::make_object(lua->sol(), textureId.first - 1)); - values.push_back(sol::make_object(lua->sol(), textureId.second)); - - auto textureStore = store->get(); - const std::string* textureString = textureStore.search(textureId.first - 1, textureId.second); - if (textureString) - { - values.push_back(sol::make_object(lua->sol(), *textureString)); - } - } - - return values; - }; - sol::table readOnlyApi = LuaUtil::makeReadOnly(api); return context.setTypePackage(readOnlyApi, "openmw_core"); }