Cleanup: Add comments to simulation state header #107744
|
@ -18,23 +18,15 @@ class SimulationStateItem {
|
||||||
};
|
};
|
||||||
|
|
||||||
class GeometrySimulationStateItem : public SimulationStateItem {
|
class GeometrySimulationStateItem : public SimulationStateItem {
|
||||||
private:
|
|
||||||
GeometrySet geometry_;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
GeometrySimulationStateItem(GeometrySet geometry);
|
GeometrySet geometry;
|
||||||
|
|
||||||
const GeometrySet &geometry() const
|
|
||||||
{
|
|
||||||
return geometry_;
|
|
||||||
}
|
|
||||||
|
|
||||||
GeometrySet &geometry()
|
|
||||||
{
|
|
||||||
return geometry_;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* References a field input/output that becomes an attribute as part of the simulation state.
|
||||||
|
* The attribute is actually stored in a #GeometrySimulationStateItem, so this just references
|
||||||
|
* the attribute's name.
|
||||||
|
*/
|
||||||
class AttributeSimulationStateItem : public SimulationStateItem {
|
class AttributeSimulationStateItem : public SimulationStateItem {
|
||||||
private:
|
private:
|
||||||
std::string name_;
|
std::string name_;
|
||||||
|
@ -48,6 +40,7 @@ class AttributeSimulationStateItem : public SimulationStateItem {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/** Storage for a single value of a trivial type like `float`, `int`, etc. */
|
||||||
class PrimitiveSimulationStateItem : public SimulationStateItem {
|
class PrimitiveSimulationStateItem : public SimulationStateItem {
|
||||||
private:
|
private:
|
||||||
const CPPType &type_;
|
const CPPType &type_;
|
||||||
|
@ -81,12 +74,19 @@ class StringSimulationStateItem : public SimulationStateItem {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Storage of values for a single simulation input and output node pair.
|
||||||
|
* Used as a cache to allow random access in time, and as an intermediate form before data is
|
||||||
|
* baked.
|
||||||
|
*/
|
||||||
class SimulationZoneState {
|
class SimulationZoneState {
|
||||||
public:
|
public:
|
||||||
Map<int, std::unique_ptr<SimulationStateItem>> item_by_identifier;
|
Map<int, std::unique_ptr<SimulationStateItem>> item_by_identifier;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/** Identifies a simulation zone (input and output node pair) used by a modifier. */
|
||||||
struct SimulationZoneID {
|
struct SimulationZoneID {
|
||||||
|
/** Every node identifier in the hierarchy of compute contexts. */
|
||||||
|
|||||||
Vector<int> node_ids;
|
Vector<int> node_ids;
|
||||||
|
|
||||||
uint64_t hash() const
|
uint64_t hash() const
|
||||||
|
@ -100,6 +100,10 @@ struct SimulationZoneID {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Stores a single frame of simulation states for all simulation zones in a modifier's node
|
||||||
|
* hierarchy.
|
||||||
|
*/
|
||||||
class ModifierSimulationState {
|
class ModifierSimulationState {
|
||||||
private:
|
private:
|
||||||
mutable bool bake_loaded_;
|
mutable bool bake_loaded_;
|
||||||
|
@ -108,7 +112,9 @@ class ModifierSimulationState {
|
||||||
ModifierSimulationCache *owner_;
|
ModifierSimulationCache *owner_;
|
||||||
mutable std::mutex mutex_;
|
mutable std::mutex mutex_;
|
||||||
Map<SimulationZoneID, std::unique_ptr<SimulationZoneState>> zone_states_;
|
Map<SimulationZoneID, std::unique_ptr<SimulationZoneState>> zone_states_;
|
||||||
|
/** File path to folder containing baked meta-data. */
|
||||||
std::optional<std::string> meta_path_;
|
std::optional<std::string> meta_path_;
|
||||||
|
/** File path to folder containing baked data. */
|
||||||
std::optional<std::string> bdata_dir_;
|
std::optional<std::string> bdata_dir_;
|
||||||
|
|
||||||
const SimulationZoneState *get_zone_state(const SimulationZoneID &zone_id) const;
|
const SimulationZoneState *get_zone_state(const SimulationZoneID &zone_id) const;
|
||||||
|
@ -122,8 +128,14 @@ struct ModifierSimulationStateAtFrame {
|
||||||
};
|
};
|
||||||
|
|
||||||
enum class CacheState {
|
enum class CacheState {
|
||||||
|
/** The cache is up-to-date with the inputs. */
|
||||||
Valid,
|
Valid,
|
||||||
|
/**
|
||||||
|
* Nodes or input values have changed since the cache was created, i.e. the output would be
|
||||||
|
* different if the simulation was run again.
|
||||||
|
*/
|
||||||
Invalid,
|
Invalid,
|
||||||
|
/** The cache has been baked and will not be invalidated by changing inputs. */
|
||||||
Baked,
|
Baked,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -136,6 +148,10 @@ struct StatesAroundFrame {
|
||||||
class ModifierSimulationCache {
|
class ModifierSimulationCache {
|
||||||
private:
|
private:
|
||||||
Vector<std::unique_ptr<ModifierSimulationStateAtFrame>> states_at_frames_;
|
Vector<std::unique_ptr<ModifierSimulationStateAtFrame>> states_at_frames_;
|
||||||
Jacques Lucke
commented
Also used for reading. Also used for reading.
|
|||||||
|
/**
|
||||||
|
* Used for baking to deduplicate arrays when writing and writing from storage. Sharing info
|
||||||
|
* must be kept alive for multiple frames to detect if each data array's version has changed.
|
||||||
|
*/
|
||||||
std::unique_ptr<BDataSharing> bdata_sharing_;
|
std::unique_ptr<BDataSharing> bdata_sharing_;
|
||||||
|
|
||||||
friend ModifierSimulationState;
|
friend ModifierSimulationState;
|
||||||
|
|
|
@ -15,11 +15,6 @@
|
||||||
|
|
||||||
namespace blender::bke::sim {
|
namespace blender::bke::sim {
|
||||||
|
|
||||||
GeometrySimulationStateItem::GeometrySimulationStateItem(GeometrySet geometry)
|
|
||||||
: geometry_(std::move(geometry))
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
PrimitiveSimulationStateItem::PrimitiveSimulationStateItem(const CPPType &type, const void *value)
|
PrimitiveSimulationStateItem::PrimitiveSimulationStateItem(const CPPType &type, const void *value)
|
||||||
: type_(type)
|
: type_(type)
|
||||||
{
|
{
|
||||||
|
|
|
@ -835,8 +835,7 @@ void serialize_modifier_simulation_state(const ModifierSimulationState &state,
|
||||||
{
|
{
|
||||||
io_state_item->append_str("type", "GEOMETRY");
|
io_state_item->append_str("type", "GEOMETRY");
|
||||||
|
|
||||||
const GeometrySet &geometry = geometry_state_item->geometry();
|
const GeometrySet &geometry = geometry_state_item->geometry;
|
||||||
|
|
||||||
auto io_geometry = serialize_geometry_set(geometry, bdata_writer, bdata_sharing);
|
auto io_geometry = serialize_geometry_set(geometry, bdata_writer, bdata_sharing);
|
||||||
io_state_item->append("data", io_geometry);
|
io_state_item->append("data", io_geometry);
|
||||||
}
|
}
|
||||||
|
|
|
@ -181,7 +181,7 @@ void simulation_state_to_values(const Span<NodeSimulationItem> node_simulation_i
|
||||||
if (const auto *geo_state_item =
|
if (const auto *geo_state_item =
|
||||||
dynamic_cast<const bke::sim::GeometrySimulationStateItem *>(&state_item))
|
dynamic_cast<const bke::sim::GeometrySimulationStateItem *>(&state_item))
|
||||||
{
|
{
|
||||||
GeometrySet *geometry = new (r_output_value) GeometrySet(geo_state_item->geometry());
|
GeometrySet *geometry = new (r_output_value) GeometrySet(geo_state_item->geometry);
|
||||||
geometries.append(geometry);
|
geometries.append(geometry);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -282,7 +282,7 @@ void values_to_simulation_state(const Span<NodeSimulationItem> node_simulation_i
|
||||||
GeometrySet &geometry = *static_cast<GeometrySet *>(input_value);
|
GeometrySet &geometry = *static_cast<GeometrySet *>(input_value);
|
||||||
auto geometry_state_item = std::make_unique<bke::sim::GeometrySimulationStateItem>(
|
auto geometry_state_item = std::make_unique<bke::sim::GeometrySimulationStateItem>(
|
||||||
std::move(geometry));
|
std::move(geometry));
|
||||||
stored_geometries.append(&geometry_state_item->geometry());
|
stored_geometries.append(&geometry_state_item->geometry);
|
||||||
state_item = std::move(geometry_state_item);
|
state_item = std::move(geometry_state_item);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
typo