Skip to content

Commit

Permalink
Update RTTs for all entities in their materials after setting rtt nam…
Browse files Browse the repository at this point in the history
…e in set_camera()
  • Loading branch information
Andrey2470T committed Feb 2, 2024
1 parent 6a50cc5 commit 4ce0693
Show file tree
Hide file tree
Showing 10 changed files with 97 additions and 5 deletions.
23 changes: 23 additions & 0 deletions src/client/activeobjectmgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include <log.h>
#include "profiler.h"
#include "activeobjectmgr.h"
#include "content_cao.h"

namespace client
{
Expand Down Expand Up @@ -105,6 +106,28 @@ void ActiveObjectMgr::getActiveObjects(const v3f &origin, f32 max_d,
}
}

void ActiveObjectMgr::updateRTTexturesOnDemand(const std::string &name)
{
if (m_active_objects.empty())
return;

u16 id = 1;

for (; id <= m_active_objects.size(); ++id) {
auto cao = getActiveObject(id);

if (!cao)
continue;

GenericCAO *generic_cao = dynamic_cast<GenericCAO*>(cao);

if (!generic_cao)
continue;

generic_cao->updateRTTextures(name);
}
}

std::vector<DistanceSortedActiveObject> ActiveObjectMgr::getActiveSelectableObjects(const core::line3d<f32> &shootline)
{
std::vector<DistanceSortedActiveObject> dest;
Expand Down
2 changes: 2 additions & 0 deletions src/client/activeobjectmgr.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ class ActiveObjectMgr final : public ::ActiveObjectMgr<ClientActiveObject>
void getActiveObjects(const v3f &origin, f32 max_d,
std::vector<DistanceSortedActiveObject> &dest);

void updateRTTexturesOnDemand(const std::string &name);

/// Gets all CAOs whose selection boxes may intersect the @p shootline.
/// @note CAOs without a selection box are not returned.
/// @note Distances are along the @p shootline.
Expand Down
8 changes: 6 additions & 2 deletions src/client/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2134,9 +2134,13 @@ const std::string &Client::getFormspecPrepend() const
return m_env.getLocalPlayer()->formspec_prepend;
}

void Client::demandReloadAndUpdateRTTs(const std::string &name)
void Client::demandUpdateRTTs(const std::string &name)
{
m_nodedef->reloadRTTexturesOnDemand(this, name);

getEnv().getClientMap().updateVisibleMapblocksMeshes();
ClientEnvironment &env = getEnv();

env.getClientMap().updateVisibleMapblocksMeshes();

env.updateRTTexturesOnDemand(name);
}
2 changes: 1 addition & 1 deletion src/client/client.h
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ class Client : public con::PeerHandler, public InventoryManager, public IGameDef
return m_mesh_grid;
}

void demandReloadAndUpdateRTTs(const std::string &name);
void demandUpdateRTTs(const std::string &name);

bool inhibit_inventory_revert = false;

Expand Down
2 changes: 2 additions & 0 deletions src/client/clientenvironment.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@ class ClientEnvironment : public Environment
return m_ao_manager.getActiveObjects(origin, max_d, dest);
}

void updateRTTexturesOnDemand(const std::string &name) { m_ao_manager.updateRTTexturesOnDemand(name); }

bool hasClientEnvEvents() const { return !m_client_event_queue.empty(); }

// Get event from queue. If queue is empty, it triggers an assertion failure.
Expand Down
53 changes: 53 additions & 0 deletions src/client/content_cao.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1510,6 +1510,59 @@ void GenericCAO::updateTextures(std::string mod)
updateMeshCulling();
}

void GenericCAO::updateRTTextures(const std::string &name)
{
ITextureSource *tsrc = m_client->tsrc();
video::ITexture *texture = tsrc->getTextureForMesh(name);

if (m_prop.textures.empty())
return;

if (m_spritenode) {
if (m_prop.visual == "sprite") {
if (m_prop.textures[0] == name) {
auto &material = m_spritenode->getMaterial(0);
material.setTexture(0, texture);
}
}
}
else if (m_animated_meshnode) {
if (m_prop.visual == "mesh") {
for (u32 i = 0; i < m_prop.textures.size(); ++i)
if (m_prop.textures[i] == name) {
auto &material = m_animated_meshnode->getMaterial(i);
material.setTexture(0,texture);
}
}
}
else if (m_meshnode) {
if (m_prop.visual == "cube") {
for (u32 i = 0; i < 6; ++i)
if (m_prop.textures[i] == name) {
auto &material = m_meshnode->getMaterial(i);
material.setTexture(0, texture);
material.getTextureMatrix(0).makeIdentity();
}
}
else if (m_prop.visual == "upright_sprite") {
if (m_prop.textures[0] == name) {
auto &material = m_meshnode->getMaterial(0);
material.setTexture(0, texture);
}

std::string next_texname = m_prop.textures[0];

if (m_prop.textures.size() >= 2)
next_texname = m_prop.textures[1];

if (next_texname == name) {
auto &material = m_meshnode->getMaterial(1);
material.setTexture(0, texture);
}
}
}
}

void GenericCAO::updateAnimation()
{
if (!m_animated_meshnode)
Expand Down
2 changes: 2 additions & 0 deletions src/client/content_cao.h
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,8 @@ class GenericCAO : public ClientActiveObject
// Reason: updateTextures(m_previous_texture_modifier);
void updateTextures(std::string mod);

void updateRTTextures(const std::string &name);

void updateAnimation();

void updateAnimationSpeed();
Expand Down
2 changes: 1 addition & 1 deletion src/client/universalcamera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ void UniversalCamera::step()

if (render_texture_updated) {
render_texture_updated = false;
m_env->getGameDef()->demandReloadAndUpdateRTTs(m_render_texture_name);
m_env->getGameDef()->demandUpdateRTTs(m_render_texture_name);
}

// Camera not attached to a parent
Expand Down
3 changes: 2 additions & 1 deletion src/nodedef.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -808,6 +808,7 @@ void ContentFeatures::updateTextures(ITextureSource *tsrc, IShaderSource *shdsrc
TileDef tdef_overlay[6];
for (u32 j = 0; j < 6; j++)
tdef_overlay[j] = tiledef_overlay[j];

// also the special tiles
TileDef tdef_spec[6];
for (u32 j = 0; j < CF_SPECIAL_COUNT; j++) {
Expand Down Expand Up @@ -1689,7 +1690,7 @@ void NodeDefManager::reloadRTTexturesOnDemand(IGameDef *gamedef, const std::stri
for (int i = 0; i < 6; i++) {
TileDef &tdef = f.tiledef[i];

if (tdef.rtt) {
if (tdef.rtt && tdef.name == name) {
TileLayer &layer = f.tiles[i].layers[0];
layer.texture = tsrc->getTextureForMesh(tdef.name, &layer.texture_id);
}
Expand Down
5 changes: 5 additions & 0 deletions src/nodedef.h
Original file line number Diff line number Diff line change
Expand Up @@ -757,6 +757,11 @@ class NodeDefManager {
*/
void resolveCrossrefs();

/*!
* Updates all RTTs in tile layers having name `name`.
* Actually it just attempts to take current generated textures from
* DynamicTextureSource mappings, otherwise loads/takes from cache as usually.
*/
void reloadRTTexturesOnDemand(IGameDef *gamedef, const std::string &name);

private:
Expand Down

0 comments on commit 4ce0693

Please sign in to comment.