1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2026-01-31 20:48:29 +00:00

Add playerCellOnly option to extractLocalMaps

This commit is contained in:
Diject 2026-01-03 11:27:35 +03:00
parent 10933c5a4d
commit 34931d0159
6 changed files with 50 additions and 13 deletions

View file

@ -619,7 +619,7 @@ namespace MWBase
virtual void extractWorldMap() = 0;
///< Extract world map using path from options or default
virtual void extractLocalMaps() = 0;
virtual void extractLocalMaps(bool playerCellOnly = false) = 0;
///< Extract local maps using path from options or default
virtual bool isMapExtractionActive() const = 0;

View file

@ -259,11 +259,12 @@ namespace MWLua
"extractWorldMapAction");
};
api["extractLocalMaps"] = [context, lua = context.mLua]() {
api["extractLocalMaps"] = [context, lua = context.mLua](sol::optional<bool> playerCellOnly) {
checkGameInitialized(lua);
bool onlyPlayerCell = playerCellOnly.value_or(false);
context.mLuaManager->addAction(
[] {
MWBase::Environment::get().getWorld()->extractLocalMaps();
[onlyPlayerCell] {
MWBase::Environment::get().getWorld()->extractLocalMaps(onlyPlayerCell);
},
"extractLocalMapsAction");
};

View file

@ -3930,7 +3930,7 @@ namespace MWWorld
mMapExtractor->extractWorldMap();
}
void World::extractLocalMaps()
void World::extractLocalMaps(bool playerCellOnly)
{
if (!mMapExtractor)
{
@ -3942,9 +3942,39 @@ namespace MWWorld
{
mMapExtractor->setLocalMap(localMap);
}
const auto& activeCells = mWorldScene->getActiveCells();
std::vector<const MWWorld::CellStore*> cells(activeCells.begin(), activeCells.end());
mMapExtractor->extractLocalMaps(cells);
std::vector<const MWWorld::CellStore*> cells;
if (playerCellOnly)
{
MWWorld::Ptr player = getPlayerPtr();
if (!player.isEmpty() && player.isInCell())
{
MWWorld::CellStore* playerCell = player.getCell();
// Only extract for exterior cells
// Interior cells are always single, so no filtering needed
if (playerCell && playerCell->isExterior())
{
cells.push_back(playerCell);
}
else
{
cells.assign(activeCells.begin(), activeCells.end());
}
}
}
else
{
// Extract all active cells
cells.assign(activeCells.begin(), activeCells.end());
}
if (!cells.empty())
{
mMapExtractor->extractLocalMaps(cells);
}
}
bool World::isMapExtractionActive() const

View file

@ -693,7 +693,7 @@ namespace MWWorld
bool getOverwriteMaps() const override { return mOverwriteMaps; }
void extractWorldMap() override;
void extractLocalMaps() override;
void extractLocalMaps(bool playerCellOnly = false) override;
bool isMapExtractionActive() const override;
void saveToLocalMapDir(std::string_view filename, std::string_view stringData) override;

View file

@ -8,8 +8,9 @@ local visitedCells = {}
local cellCount = #world.cells
local i = cellCount
local lastTimestamp = core.getRealTime() - 100
local timeFromLast = 100
local lastTimestamp = core.getRealTime() - 50
local timeFromLast = 50
local onlyPlayerCell = false
local function getExCellId(gridX, gridY)
@ -66,7 +67,7 @@ local function processAndTeleport(skipExtraction)
local pl = world.players[1]
if not skipExtraction then
world.extractLocalMaps()
world.extractLocalMaps(onlyPlayerCell)
end
local function func()
@ -98,7 +99,7 @@ local function processAndTeleport(skipExtraction)
if not cell or not customCellId or visitedCells[customCellId] then goto continue end
visitedCells[customCellId] = true
if cell.isExterior then
if not onlyPlayerCell and cell.isExterior then
for j = cell.gridX - 1, cell.gridX + 1 do
for k = cell.gridY - 1, cell.gridY + 1 do
visitedCells[getExCellId(j, k)] = true

View file

@ -236,7 +236,12 @@
-- or defaults to "./textures/advanced_world_map/local" if not specified.
-- By default, existing maps are not overwritten. Use --overwrite-maps option to force overwriting.
-- @function [parent=#world] extractLocalMaps
-- @usage world.extractLocalMaps() -- Use path from option or default
-- @param #boolean playerCellOnly (optional, false by default) If true, extracts only the player's current cell.
-- For exterior cells, this extracts only the player's cell instead of all 9 loaded cells.
-- For interior cells, this has no effect as only one cell is loaded anyway.
-- @usage world.extractLocalMaps() -- Extract all active cells (default)
-- @usage world.extractLocalMaps(false) -- Same as above, extract all active cells
-- @usage world.extractLocalMaps(true) -- Extract only player's current cell (exterior only)
---
-- Enable extraction mode for map generation.