2023-06-14 16:52:36 +10:00
|
|
|
/* SPDX-FileCopyrightText: 2011-2022 Blender Foundation
|
|
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: Apache-2.0 */
|
2021-01-25 14:56:57 +01:00
|
|
|
|
2021-10-24 14:19:19 +02:00
|
|
|
#include "scene/procedural.h"
|
2021-10-24 14:19:19 +02:00
|
|
|
#include "scene/scene.h"
|
|
|
|
|
#include "scene/stats.h"
|
2021-01-25 14:56:57 +01:00
|
|
|
|
2021-10-24 14:19:19 +02:00
|
|
|
#include "util/progress.h"
|
2021-01-25 14:56:57 +01:00
|
|
|
|
|
|
|
|
CCL_NAMESPACE_BEGIN
|
|
|
|
|
|
|
|
|
|
NODE_ABSTRACT_DEFINE(Procedural)
|
|
|
|
|
{
|
2024-12-26 17:53:55 +01:00
|
|
|
NodeType *type = NodeType::add("procedural_base", nullptr);
|
2021-01-25 14:56:57 +01:00
|
|
|
return type;
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-29 16:50:54 +02:00
|
|
|
Procedural::Procedural(const NodeType *type) : Node(type) {}
|
2021-01-25 14:56:57 +01:00
|
|
|
|
2024-12-26 17:53:59 +01:00
|
|
|
Procedural::~Procedural() = default;
|
2021-01-25 14:56:57 +01:00
|
|
|
|
|
|
|
|
ProceduralManager::ProceduralManager()
|
|
|
|
|
{
|
|
|
|
|
need_update_ = true;
|
|
|
|
|
}
|
|
|
|
|
|
2024-12-26 17:53:59 +01:00
|
|
|
ProceduralManager::~ProceduralManager() = default;
|
2021-01-25 14:56:57 +01:00
|
|
|
|
|
|
|
|
void ProceduralManager::update(Scene *scene, Progress &progress)
|
|
|
|
|
{
|
|
|
|
|
if (!need_update()) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
progress.set_status("Updating Procedurals");
|
|
|
|
|
|
2024-12-29 17:32:00 +01:00
|
|
|
const scoped_callback_timer timer([scene](double time) {
|
2021-01-25 14:56:57 +01:00
|
|
|
if (scene->update_stats) {
|
|
|
|
|
scene->update_stats->procedurals.times.add_entry({"update", time});
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2024-12-26 19:41:25 +01:00
|
|
|
for (Procedural *procedural : scene->procedurals) {
|
2021-01-25 14:56:57 +01:00
|
|
|
if (progress.get_cancel()) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
procedural->generate(scene, progress);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (progress.get_cancel()) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
need_update_ = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ProceduralManager::tag_update()
|
|
|
|
|
{
|
|
|
|
|
need_update_ = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool ProceduralManager::need_update() const
|
|
|
|
|
{
|
|
|
|
|
return need_update_;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CCL_NAMESPACE_END
|