1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2026-01-24 15:30:54 +00:00

Add configurable tilemap downscale factor

This commit is contained in:
Diject 2026-01-02 19:52:04 +03:00
parent 9669b73233
commit bcd7cb2c85
6 changed files with 32 additions and 17 deletions

View file

@ -380,6 +380,7 @@ OMW::Engine::Engine(Files::ConfigurationManager& configurationManager)
, mCfgMgr(configurationManager)
, mGlMaxTextureImageUnits(0)
, mOverwriteMaps(false)
, mTilemapDownscaleFactor(4)
{
#if SDL_VERSION_ATLEAST(2, 24, 0)
SDL_SetHint(SDL_HINT_MAC_OPENGL_ASYNC_DISPATCH, "1");
@ -839,7 +840,7 @@ void OMW::Engine::prepareEngine()
// Create the world
mWorld = std::make_unique<MWWorld::World>(
mResourceSystem.get(), mActivationDistanceOverride, mCellName, mCfgMgr.getUserDataPath(),
mWorldMapOutput, mLocalMapOutput, mOverwriteMaps);
mWorldMapOutput, mLocalMapOutput, mOverwriteMaps, mTilemapDownscaleFactor);
mEnvironment.setWorld(*mWorld);
mEnvironment.setWorldModel(mWorld->getWorldModel());
mEnvironment.setESMStore(mWorld->getStore());
@ -1165,3 +1166,8 @@ void OMW::Engine::setOverwriteMaps(bool overwrite)
{
mOverwriteMaps = overwrite;
}
void OMW::Engine::setTilemapDownscaleFactor(int factor)
{
mTilemapDownscaleFactor = factor;
}

View file

@ -186,6 +186,7 @@ namespace OMW
std::string mWorldMapOutput;
std::string mLocalMapOutput;
bool mOverwriteMaps;
int mTilemapDownscaleFactor;
Files::ConfigurationManager& mCfgMgr;
int mGlMaxTextureImageUnits;
@ -274,7 +275,7 @@ namespace OMW
void setOverwriteMaps(bool overwrite);
void setExtractMaps(bool extract);
void setTilemapDownscaleFactor(int factor);
void setRecastMaxLogLevel(Debug::Level value) { mMaxRecastLogLevel = value; }
};

View file

@ -185,6 +185,7 @@ bool parseOptions(int argc, char** argv, OMW::Engine& engine, Files::Configurati
engine.setWorldMapOutput(worldMapOutput);
engine.setLocalMapOutput(localMapOutput);
engine.setOverwriteMaps(variables["overwrite-maps"].as<bool>());
engine.setTilemapDownscaleFactor(variables["tilemap-downscale-factor"].as<int>());
return true;
}

View file

@ -255,7 +255,7 @@ namespace MWWorld
}
World::World(Resource::ResourceSystem* resourceSystem, int activationDistanceOverride, const std::string& startCell,
const std::filesystem::path& userDataPath, const std::string& worldMapOutputPath, const std::string& localMapOutputPath, bool overwriteMaps)
const std::filesystem::path& userDataPath, const std::string& worldMapOutputPath, const std::string& localMapOutputPath, bool overwriteMaps, int tilemapDownscaleFactor)
: mResourceSystem(resourceSystem)
, mLocalScripts(mStore)
, mWorldModel(mStore, mReaders)
@ -270,6 +270,7 @@ namespace MWWorld
, mWorldMapOutputPath(worldMapOutputPath)
, mLocalMapOutputPath(localMapOutputPath)
, mOverwriteMaps(overwriteMaps)
, mTilemapDownscaleFactor(tilemapDownscaleFactor)
, mSwimHeightScale(0.f)
, mDistanceToFocusObject(-1.f)
, mTeleportEnabled(true)
@ -4047,8 +4048,9 @@ namespace MWWorld
Log(Debug::Info) << "Bounds: X=[" << minX << ", " << maxX << "], Y=[" << minY << ", " << maxY << "]";
// Step 2: Create the output image
const int width = (maxX - minX + 1) * 32;
const int height = (maxY - minY + 1) * 32;
const int targetSize = 256 / mTilemapDownscaleFactor;
const int width = (maxX - minX + 1) * targetSize;
const int height = (maxY - minY + 1) * targetSize;
osg::ref_ptr<osg::Image> tilemapImage = new osg::Image;
tilemapImage->allocateImage(width, height, 1, GL_RGB, GL_UNSIGNED_BYTE);
@ -4079,17 +4081,18 @@ namespace MWWorld
continue;
}
// Downscale from 256x256 to 32x32
// Downscale from 256x256 to target size based on downscale factor
const int targetSize = 256 / mTilemapDownscaleFactor;
osg::ref_ptr<osg::Image> scaledTile = new osg::Image;
scaledTile->allocateImage(32, 32, 1, tileImage->getPixelFormat(), tileImage->getDataType());
scaledTile->allocateImage(targetSize, targetSize, 1, tileImage->getPixelFormat(), tileImage->getDataType());
// Simple nearest-neighbor downscaling
for (int y = 0; y < 32; ++y)
for (int y = 0; y < targetSize; ++y)
{
for (int x = 0; x < 32; ++x)
for (int x = 0; x < targetSize; ++x)
{
int srcX = (x * tileImage->s()) / 32;
int srcY = (y * tileImage->t()) / 32;
int srcX = (x * tileImage->s()) / targetSize;
int srcY = (y * tileImage->t()) / targetSize;
unsigned char* srcPixel = tileImage->data(srcX, srcY);
unsigned char* dstPixel = scaledTile->data(x, y);
@ -4103,12 +4106,12 @@ namespace MWWorld
}
// Place scaled tile in output image
int destX = (gridX - minX) * 32;
int destY = (gridY - minY) * 32;
int destX = (gridX - minX) * targetSize;
int destY = (gridY - minY) * targetSize;
for (int y = 0; y < 32; ++y)
for (int y = 0; y < targetSize; ++y)
{
for (int x = 0; x < 32; ++x)
for (int x = 0; x < targetSize; ++x)
{
unsigned char* srcPixel = scaledTile->data(x, y);
unsigned char* dstPixel = tilemapImage->data(destX + x, destY + y);
@ -4144,7 +4147,7 @@ namespace MWWorld
return;
}
const int pixelsPerCell = 256 / 8; // Тайлы 32x32 при downscale factor = 8
const int pixelsPerCell = 256 / mTilemapDownscaleFactor;
infoFile << "width: " << width << "\n";
infoFile << "height: " << height << "\n";

View file

@ -124,6 +124,7 @@ namespace MWWorld
std::string mWorldMapOutputPath;
std::string mLocalMapOutputPath;
bool mOverwriteMaps;
int mTilemapDownscaleFactor;
float mSwimHeightScale;
@ -201,7 +202,7 @@ namespace MWWorld
void removeContainerScripts(const Ptr& reference) override;
World(Resource::ResourceSystem* resourceSystem, int activationDistanceOverride, const std::string& startCell,
const std::filesystem::path& userDataPath, const std::string& worldMapOutputPath, const std::string& localMapOutputPath, bool overwriteMaps);
const std::filesystem::path& userDataPath, const std::string& worldMapOutputPath, const std::string& localMapOutputPath, bool overwriteMaps, int tilemapDownscaleFactor);
void loadData(const Files::Collections& fileCollections, const std::vector<std::string>& contentFiles,
const std::vector<std::string>& groundcoverFiles, ToUTF8::Utf8Encoder* encoder,

View file

@ -104,6 +104,9 @@ namespace OpenMW
addOption("overwrite-maps", bpo::value<bool>()->implicit_value(true)->default_value(false),
"overwrite existing map files during extraction");
addOption("tilemap-downscale-factor", bpo::value<int>()->default_value(4),
"downscale factor for tilemap generation (must be power of 2, default: 4)");
return desc;
}
}