implement global texture swapping

This commit is contained in:
T1ti
2023-01-21 03:18:48 +01:00
parent ba3b01450f
commit 9adc98b3a7
8 changed files with 91 additions and 6 deletions

View File

@@ -1280,10 +1280,13 @@ int MapChunk::addTexture(scoped_blp_texture_reference texture)
return texture_set->addTexture(std::move (texture));
}
void MapChunk::switchTexture(scoped_blp_texture_reference const& oldTexture, scoped_blp_texture_reference newTexture)
bool MapChunk::switchTexture(scoped_blp_texture_reference const& oldTexture, scoped_blp_texture_reference newTexture)
{
texture_set->replace_texture(oldTexture, std::move (newTexture));
registerChunkUpdate(ChunkUpdateFlags::ALPHAMAP);
bool changed = texture_set->replace_texture(oldTexture, std::move (newTexture));
if (changed)
registerChunkUpdate(ChunkUpdateFlags::ALPHAMAP);
return changed;
}
bool MapChunk::paintTexture(glm::vec3 const& pos, Brush* brush, float strength, float pressure, scoped_blp_texture_reference texture)

View File

@@ -160,7 +160,7 @@ public:
bool replaceTexture(glm::vec3 const& pos, float radius, scoped_blp_texture_reference const& old_texture, scoped_blp_texture_reference new_texture, bool entire_chunk = false);
bool canPaintTexture(scoped_blp_texture_reference texture);
int addTexture(scoped_blp_texture_reference texture);
void switchTexture(scoped_blp_texture_reference const& oldTexture, scoped_blp_texture_reference newTexture);
bool switchTexture(scoped_blp_texture_reference const& oldTexture, scoped_blp_texture_reference newTexture);
void eraseTextures();
void eraseTexture(scoped_blp_texture_reference const& tex);
void change_texture_flag(scoped_blp_texture_reference const& tex, std::size_t flag, bool add);

View File

@@ -2031,6 +2031,51 @@ void World::swapTexture(glm::vec3 const& pos, scoped_blp_texture_reference tex)
}
}
void World::swapTextureGlobal(scoped_blp_texture_reference tex)
{
ZoneScoped;
if (!!Noggit::Ui::selected_texture::get())
{
for (size_t z = 0; z < 64; z++)
{
for (size_t x = 0; x < 64; x++)
{
TileIndex tile(x, z);
bool unload = !mapIndex.tileLoaded(tile) && !mapIndex.tileAwaitingLoading(tile);
MapTile* mTile = mapIndex.loadTile(tile);
if (mTile)
{
mTile->wait_until_loaded();
bool tile_changed = false;
for_all_chunks_on_tile(mTile, [&](MapChunk* chunk)
{
// NOGGIT_CUR_ACTION->registerChunkTextureChange(chunk);
bool swapped = chunk->switchTexture(tex, *Noggit::Ui::selected_texture::get());
if (swapped)
tile_changed = true;
});
if (tile_changed)
{
mTile->saveTile(this);
mapIndex.markOnDisc(tile, true);
mapIndex.unsetChanged(tile);
}
if (unload)
{
mapIndex.unloadTile(tile);
}
}
}
}
}
}
void World::removeTexture(glm::vec3 const& pos, scoped_blp_texture_reference tex)
{
ZoneScoped;

View File

@@ -191,6 +191,9 @@ public:
template<typename Fun>
void for_all_chunks_on_tile (glm::vec3 const& pos, Fun&&);
template<typename Fun>
void for_all_chunks_on_tile(MapTile* tile, Fun&& fun);
template<typename Fun>
void for_chunk_at(glm::vec3 const& pos, Fun&& fun);
template<typename Fun>
@@ -216,6 +219,7 @@ public:
void clear_shadows(glm::vec3 const& pos);
void clearTextures(glm::vec3 const& pos);
void swapTexture(glm::vec3 const& pos, scoped_blp_texture_reference tex);
void swapTextureGlobal(scoped_blp_texture_reference tex);
void removeTexture(glm::vec3 const& pos, scoped_blp_texture_reference tex);
void removeTexDuplicateOnADT(glm::vec3 const& pos);
void change_texture_flag(glm::vec3 const& pos, scoped_blp_texture_reference const& tex, std::size_t flag, bool add);

View File

@@ -25,6 +25,23 @@ void World::for_all_chunks_on_tile (glm::vec3 const& pos, Fun&& fun)
}
}
template<typename Fun>
void World::for_all_chunks_on_tile(MapTile* tile, Fun&& fun)
{
if (tile && tile->finishedLoading())
{
mapIndex.setChanged(tile);
for (size_t ty = 0; ty < 16; ++ty)
{
for (size_t tx = 0; tx < 16; ++tx)
{
fun(tile->getChunk(ty, tx));
}
}
}
}
template<typename Fun>
void World::for_chunk_at(glm::vec3 const& pos, Fun&& fun)
{

View File

@@ -87,7 +87,7 @@ int TextureSet::addTexture (scoped_blp_texture_reference texture)
return texLevel;
}
void TextureSet::replace_texture (scoped_blp_texture_reference const& texture_to_replace, scoped_blp_texture_reference replacement_texture)
bool TextureSet::replace_texture (scoped_blp_texture_reference const& texture_to_replace, scoped_blp_texture_reference replacement_texture)
{
int texture_to_replace_level = -1, replacement_texture_level = -1;
@@ -122,6 +122,11 @@ void TextureSet::replace_texture (scoped_blp_texture_reference const& texture_to
// merge_layers(texture_to_replace_level, replacement_texture_level);
}
}
if (texture_to_replace_level != -1 || replacement_texture_level != -1)
return true;
else
return false;
}
void TextureSet::swap_layers(int layer_1, int layer_2)

View File

@@ -45,7 +45,7 @@ public:
// return true if at least 1 texture has been erased
bool eraseUnusedTextures();
void swap_layers(int layer_1, int layer_2);
void replace_texture(scoped_blp_texture_reference const& texture_to_replace, scoped_blp_texture_reference replacement_texture);
bool replace_texture(scoped_blp_texture_reference const& texture_to_replace, scoped_blp_texture_reference replacement_texture);
bool paintTexture(float xbase, float zbase, float x, float z, Brush* brush, float strength, float pressure, scoped_blp_texture_reference texture);
bool stampTexture(float xbase, float zbase, float x, float z, Brush* brush, float strength, float pressure, scoped_blp_texture_reference texture, QImage* image, bool paint);
bool replace_texture( float xbase

View File

@@ -36,12 +36,14 @@ namespace Noggit
QPushButton* select = new QPushButton("Select", this);
QPushButton* swap_adt = new QPushButton("Swap ADT", this);
QPushButton* swap_global = new QPushButton("Swap Global(All ADTs)", this);
QPushButton* remove_text_adt = new QPushButton(tr("Remove this texture from ADT"), this);
layout->addRow(new QLabel("Texture to swap"));
layout->addRow(_texture_to_swap_display);
layout->addRow(select);
layout->addRow(swap_adt);
layout->addRow(swap_global);
layout->addRow(remove_text_adt);
_brush_mode_group = new QGroupBox("Brush mode", this);
@@ -89,6 +91,15 @@ namespace Noggit
}
});
connect(swap_global, &QPushButton::clicked, [this, camera_pos, map_view]() {
if (_texture_to_swap)
{
// ActionManager::instance()->beginAction(map_view, ActionFlags::eCHUNKS_TEXTURE);
_world->swapTextureGlobal(_texture_to_swap.value());
// ActionManager::instance()->endAction();
}
});
connect(remove_text_adt, &QPushButton::clicked, [this, camera_pos, map_view]() {
if (_texture_to_swap)
{