mirror of
https://github.com/luanti-org/luanti.git
synced 2025-06-27 16:36:03 +00:00
Reduce exposure of various internals (#12885)
* refactoring(StaticObjectList): don't expose m_active and m_stored anymore This prevents our old crap code where anyone can access to StaticObjectList. use proper modifiers. It also permits to do a short cleanup on MapBlock using a helper * refactoring(MapBlock): reduce a bit exposed m_active_blocks variable * refactoring: MapBlock::m_node_timers is now private We already had various helpers to perform this privatization, just use it. Also factorize the MapBlock stepping code for timers using already existing code and importing them from ServerEnvironment to MapBlock. It's currently done pretty straight forward without any inheritance as MapBlock is just used everywhere, maybe in a future we'll have ServerMapBlock over MapBlock. Currently for a simple function let's just use proper objects and add a comment warning * refactoring(Server): fix duplicated function for add/remove node * refactoring(guiFormSpecMenu): add removeAll function to prevent duplicated code * refactoring(ShadowRenderer) + perf: code quality + increase performance * All callers are already using the point and we should never test a function with nullptr node, it's a bug. Removed workaround which was hacky and fix the bug * Drop clientmap lookup from shadowrendered, just use directly its pointer and forbid to push it in the generic list * Reduce memory pressure on the renderShadowObject by preventing deallocating and reallocating multiple vectors on each node * refactoring(MapBlock): reduce exposure of MapBlock::m_static_objects It's not complete as some parts of the code are pretty nested, but it's better than before :) * fix: better working on new functions & drop unwanted 2 lines Co-authored-by: Jude Melton-Houghton <jwmhjwmh@gmail.com> Co-authored-by: Jude Melton-Houghton <jwmhjwmh@gmail.com>
This commit is contained in:
parent
957a3e52fe
commit
322c8cf270
17 changed files with 296 additions and 290 deletions
|
@ -132,7 +132,7 @@ void ShadowRenderer::initialize()
|
|||
m_texture_format_color = m_shadow_map_texture_32bit
|
||||
? video::ECOLOR_FORMAT::ECF_G32R32F
|
||||
: video::ECOLOR_FORMAT::ECF_G16R16F;
|
||||
|
||||
|
||||
m_shadows_enabled &= m_shadows_supported;
|
||||
}
|
||||
|
||||
|
@ -176,16 +176,15 @@ void ShadowRenderer::setShadowIntensity(float shadow_intensity)
|
|||
void ShadowRenderer::addNodeToShadowList(
|
||||
scene::ISceneNode *node, E_SHADOW_MODE shadowMode)
|
||||
{
|
||||
if (!node)
|
||||
return;
|
||||
m_shadow_node_array.emplace_back(node, shadowMode);
|
||||
// node should never be ClientMap
|
||||
assert(strcmp(node->getName(), "ClientMap") != 0);
|
||||
|
||||
node->setMaterialTexture(TEXTURE_LAYER_SHADOW, shadowMapTextureFinal);
|
||||
}
|
||||
|
||||
void ShadowRenderer::removeNodeFromShadowList(scene::ISceneNode *node)
|
||||
{
|
||||
if (!node)
|
||||
return;
|
||||
node->setMaterialTexture(TEXTURE_LAYER_SHADOW, nullptr);
|
||||
for (auto it = m_shadow_node_array.begin(); it != m_shadow_node_array.end();) {
|
||||
if (it->node == node) {
|
||||
|
@ -286,7 +285,7 @@ void ShadowRenderer::updateSMTextures()
|
|||
cb->PerspectiveBiasZ = getPerspectiveBiasZ();
|
||||
cb->CameraPos = light.getFuturePlayerPos();
|
||||
}
|
||||
|
||||
|
||||
// set the Render Target
|
||||
// right now we can only render in usual RTT, not
|
||||
// Depth texture is available in irrlicth maybe we
|
||||
|
@ -349,7 +348,7 @@ void ShadowRenderer::update(video::ITexture *outputTarget)
|
|||
|
||||
for (DirectionalLight &light : m_light_list) {
|
||||
// Static shader values for entities are set in updateSMTextures
|
||||
// SM texture for entities is not updated incrementally and
|
||||
// SM texture for entities is not updated incrementally and
|
||||
// must by updated using current player position.
|
||||
m_shadow_depth_entity_cb->CameraPos = light.getPlayerPos();
|
||||
|
||||
|
@ -392,7 +391,7 @@ void ShadowRenderer::drawDebug()
|
|||
m_driver->draw2DImage(shadowMapClientMap,
|
||||
core::rect<s32>(0, 50 + 128, 128, 128 + 50 + 128),
|
||||
core::rect<s32>({0, 0}, shadowMapTextureFinal->getSize()));
|
||||
|
||||
|
||||
if (shadowMapTextureDynamicObjects)
|
||||
m_driver->draw2DImage(shadowMapTextureDynamicObjects,
|
||||
core::rect<s32>(0, 128 + 50 + 128, 128,
|
||||
|
@ -429,39 +428,32 @@ void ShadowRenderer::renderShadowMap(video::ITexture *target,
|
|||
m_driver->setTransform(video::ETS_VIEW, light.getFutureViewMatrix());
|
||||
m_driver->setTransform(video::ETS_PROJECTION, light.getFutureProjectionMatrix());
|
||||
|
||||
// Operate on the client map
|
||||
for (const auto &shadow_node : m_shadow_node_array) {
|
||||
if (strcmp(shadow_node.node->getName(), "ClientMap") != 0)
|
||||
continue;
|
||||
ClientMap &map_node = static_cast<ClientMap &>(m_client->getEnv().getMap());
|
||||
|
||||
ClientMap *map_node = static_cast<ClientMap *>(shadow_node.node);
|
||||
|
||||
video::SMaterial material;
|
||||
if (map_node->getMaterialCount() > 0) {
|
||||
// we only want the first material, which is the one with the albedo info
|
||||
material = map_node->getMaterial(0);
|
||||
}
|
||||
|
||||
material.BackfaceCulling = false;
|
||||
material.FrontfaceCulling = true;
|
||||
|
||||
if (m_shadow_map_colored && pass != scene::ESNRP_SOLID) {
|
||||
material.MaterialType = (video::E_MATERIAL_TYPE) depth_shader_trans;
|
||||
}
|
||||
else {
|
||||
material.MaterialType = (video::E_MATERIAL_TYPE) depth_shader;
|
||||
material.BlendOperation = video::EBO_MIN;
|
||||
}
|
||||
|
||||
m_driver->setTransform(video::ETS_WORLD,
|
||||
map_node->getAbsoluteTransformation());
|
||||
|
||||
int frame = m_force_update_shadow_map ? 0 : m_current_frame;
|
||||
int total_frames = m_force_update_shadow_map ? 1 : m_map_shadow_update_frames;
|
||||
|
||||
map_node->renderMapShadows(m_driver, material, pass, frame, total_frames);
|
||||
break;
|
||||
video::SMaterial material;
|
||||
if (map_node.getMaterialCount() > 0) {
|
||||
// we only want the first material, which is the one with the albedo info
|
||||
material = map_node.getMaterial(0);
|
||||
}
|
||||
|
||||
material.BackfaceCulling = false;
|
||||
material.FrontfaceCulling = true;
|
||||
|
||||
if (m_shadow_map_colored && pass != scene::ESNRP_SOLID) {
|
||||
material.MaterialType = (video::E_MATERIAL_TYPE) depth_shader_trans;
|
||||
}
|
||||
else {
|
||||
material.MaterialType = (video::E_MATERIAL_TYPE) depth_shader;
|
||||
material.BlendOperation = video::EBO_MIN;
|
||||
}
|
||||
|
||||
m_driver->setTransform(video::ETS_WORLD,
|
||||
map_node.getAbsoluteTransformation());
|
||||
|
||||
int frame = m_force_update_shadow_map ? 0 : m_current_frame;
|
||||
int total_frames = m_force_update_shadow_map ? 1 : m_map_shadow_update_frames;
|
||||
|
||||
map_node.renderMapShadows(m_driver, material, pass, frame, total_frames);
|
||||
}
|
||||
|
||||
void ShadowRenderer::renderShadowObjects(
|
||||
|
@ -472,8 +464,7 @@ void ShadowRenderer::renderShadowObjects(
|
|||
|
||||
for (const auto &shadow_node : m_shadow_node_array) {
|
||||
// we only take care of the shadow casters
|
||||
if (shadow_node.shadowMode == ESM_RECEIVE ||
|
||||
strcmp(shadow_node.node->getName(), "ClientMap") == 0)
|
||||
if (shadow_node.shadowMode == ESM_RECEIVE)
|
||||
continue;
|
||||
|
||||
// render other objects
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue