Skip to content

Commit 4b06be2

Browse files
committed
FIX improve aspectRatio hack so that it's set in reload
1 parent 909312a commit 4b06be2

File tree

4 files changed

+47
-20
lines changed

4 files changed

+47
-20
lines changed

src/registry/NodeRegistry.cpp

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -228,8 +228,8 @@ void NodeRegistry::prepare(
228228

229229
{
230230
m_layerInfos.resize(assets.layers.size());
231-
for (auto& layerInfo : m_layerInfos) {
232-
layerInfo = { glm::uvec2{0}, false };
231+
for (int index = 0; auto& layerInfo : m_layerInfos) {
232+
layerInfo = { index++, glm::uvec2{1, 1} };
233233
}
234234
}
235235

@@ -256,8 +256,6 @@ void NodeRegistry::updateWT(const UpdateContext& ctx)
256256
state.updateRootMatrix();
257257
}
258258

259-
const auto layerCount = m_layerInfos.size();
260-
261259
//std::lock_guard lock(m_lock);
262260
// NOTE KI nodes are in DAG order
263261
for (int sortedIndex = ID_NODE_INDEX + 1; sortedIndex < m_sortedNodes.size(); sortedIndex++)
@@ -274,13 +272,6 @@ void NodeRegistry::updateWT(const UpdateContext& ctx)
274272
const auto& parentState = m_states[m_parentIndeces[entityIndex]];
275273
auto* generator = node->m_generator.get();
276274

277-
if (node->m_layer < layerCount) {
278-
const auto& layerInfo = m_layerInfos[node->m_layer];
279-
if (layerInfo.second) {
280-
state.setAspectRatio(layerInfo.first);
281-
}
282-
}
283-
284275
state.updateModelMatrix(parentState);
285276

286277
if (generator) {
@@ -299,10 +290,6 @@ void NodeRegistry::updateWT(const UpdateContext& ctx)
299290
}
300291
}
301292
}
302-
303-
for (auto& layerInfo : m_layerInfos) {
304-
layerInfo.second = false;
305-
}
306293
}
307294

308295
void NodeRegistry::postUpdateWT(const UpdateContext& ctx)
@@ -1027,6 +1014,10 @@ void NodeRegistry::bindNode(
10271014
m_parentIndeces[entityIndex] = 0;
10281015
m_states[entityIndex] = state;
10291016

1017+
if (node->m_layer < m_layerInfos.size()) {
1018+
m_states[entityIndex].setAspectRatio(m_layerInfos[node->m_layer].m_aspectRatio);
1019+
}
1020+
10301021
m_nodeLevel++;
10311022

10321023
if (nodeHandle == m_rootHandle) {
@@ -1284,10 +1275,19 @@ void NodeRegistry::viewportChanged(
12841275
if (layer >= m_layerInfos.size()) return;
12851276

12861277
auto& info = m_layerInfos[layer];
1287-
if (info.first != aspectRatio)
1278+
info.m_aspectRatio = aspectRatio;
1279+
1280+
for (int sortedIndex = ID_NODE_INDEX + 1; sortedIndex < m_sortedNodes.size(); sortedIndex++)
12881281
{
1289-
info.first = aspectRatio;
1290-
info.second = true;
1282+
auto entityIndex = m_sortedNodes[sortedIndex];
1283+
auto& state = m_states[entityIndex];
1284+
1285+
auto* node = getCachedNodesWT()[entityIndex];
1286+
if (!node) continue;
1287+
1288+
if (node->m_layer == info.m_index) {
1289+
state.setAspectRatio(info.m_aspectRatio);
1290+
}
12911291
}
12921292
}
12931293

src/registry/NodeRegistry.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,12 @@ namespace mesh
4343
class MeshYype;
4444
}
4545

46+
struct NodeLayerInfo
47+
{
48+
int m_index;
49+
glm::uvec2 m_aspectRatio;
50+
};
51+
4652
class NodeRegistry final
4753
{
4854
friend class model::Node;
@@ -329,5 +335,5 @@ class NodeRegistry final
329335

330336
pool::NodeHandle m_activeNode{};
331337

332-
std::vector<std::pair<glm::uvec2, bool>> m_layerInfos;
338+
std::vector<NodeLayerInfo> m_layerInfos;
333339
};

src/scene/Scene.cpp

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ void Scene::prepareRT()
152152
event::Type::scene_loaded,
153153
dispatcherView,
154154
[this](const event::Event& e) {
155-
m_loaded = true;
155+
handleLoaded();
156156
});
157157

158158
m_listen_node_added.listen(
@@ -488,6 +488,25 @@ void Scene::updateViewRT(const UpdateViewContext& ctx)
488488
}
489489
}
490490

491+
void Scene::handleLoaded()
492+
{
493+
m_loaded = true;
494+
495+
//const auto& spec = m_uiRenderer->m_buffer->m_spec;
496+
//const glm::uvec2 aspectRatio = { spec.width, spec.height };
497+
//m_uiRenderer->m_aspectRatio = aspectRatio;
498+
499+
//const auto* layer = LayerInfo::findLayer(LAYER_UI);
500+
//if (layer && layer->m_enabled) {
501+
// event::Event evt{ event::Type::viewport_changed };
502+
// auto& body = evt.body.view = {
503+
// .layer = layer->m_index,
504+
// .aspectRatio = aspectRatio,
505+
// };
506+
// m_engine.getRegistry()->m_dispatcherWorker->send(evt);
507+
//}
508+
}
509+
491510
void Scene::handleNodeAdded(model::Node* node)
492511
{
493512
if (!node) return;

src/scene/Scene.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,8 @@ class Scene final
125125
const render::RenderContext& ctx,
126126
LayerRenderer* layerRenderer);
127127

128+
void handleLoaded();
129+
128130
void handleNodeAdded(model::Node* node);
129131
void handleNodeRemoved(model::Node* node);
130132

0 commit comments

Comments
 (0)