Cleanup: Add comments to simulation state header #107744
|
@ -18,23 +18,15 @@ class SimulationStateItem {
|
|||
};
|
||||
|
||||
class GeometrySimulationStateItem : public SimulationStateItem {
|
||||
private:
|
||||
GeometrySet geometry_;
|
||||
|
||||
public:
|
||||
GeometrySimulationStateItem(GeometrySet geometry);
|
||||
|
||||
const GeometrySet &geometry() const
|
||||
{
|
||||
return geometry_;
|
||||
}
|
||||
|
||||
GeometrySet &geometry()
|
||||
{
|
||||
return geometry_;
|
||||
}
|
||||
GeometrySet 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 {
|
||||
private:
|
||||
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 {
|
||||
private:
|
||||
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 {
|
||||
public:
|
||||
Map<int, std::unique_ptr<SimulationStateItem>> item_by_identifier;
|
||||
};
|
||||
|
||||
/** Identifies a simulation zone (input and output node pair) used by a modifier. */
|
||||
struct SimulationZoneID {
|
||||
/** Every node identifier in the hierarchy of compute contexts. */
|
||||
|
||||
Vector<int> node_ids;
|
||||
|
||||
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 {
|
||||
private:
|
||||
mutable bool bake_loaded_;
|
||||
|
@ -108,7 +112,9 @@ class ModifierSimulationState {
|
|||
ModifierSimulationCache *owner_;
|
||||
mutable std::mutex mutex_;
|
||||
Map<SimulationZoneID, std::unique_ptr<SimulationZoneState>> zone_states_;
|
||||
/** File path to folder containing baked meta-data. */
|
||||
std::optional<std::string> meta_path_;
|
||||
/** File path to folder containing baked data. */
|
||||
std::optional<std::string> bdata_dir_;
|
||||
|
||||
const SimulationZoneState *get_zone_state(const SimulationZoneID &zone_id) const;
|
||||
|
@ -122,8 +128,14 @@ struct ModifierSimulationStateAtFrame {
|
|||
};
|
||||
|
||||
enum class CacheState {
|
||||
/** The cache is up-to-date with the inputs. */
|
||||
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,
|
||||
/** The cache has been baked and will not be invalidated by changing inputs. */
|
||||
Baked,
|
||||
};
|
||||
|
||||
|
@ -136,6 +148,10 @@ struct StatesAroundFrame {
|
|||
class ModifierSimulationCache {
|
||||
private:
|
||||
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_;
|
||||
|
||||
friend ModifierSimulationState;
|
||||
|
|
|
@ -15,11 +15,6 @@
|
|||
|
||||
namespace blender::bke::sim {
|
||||
|
||||
GeometrySimulationStateItem::GeometrySimulationStateItem(GeometrySet geometry)
|
||||
: geometry_(std::move(geometry))
|
||||
{
|
||||
}
|
||||
|
||||
PrimitiveSimulationStateItem::PrimitiveSimulationStateItem(const CPPType &type, const void *value)
|
||||
: type_(type)
|
||||
{
|
||||
|
|
|
@ -835,8 +835,7 @@ void serialize_modifier_simulation_state(const ModifierSimulationState &state,
|
|||
{
|
||||
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);
|
||||
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 =
|
||||
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);
|
||||
}
|
||||
else {
|
||||
|
@ -282,7 +282,7 @@ void values_to_simulation_state(const Span<NodeSimulationItem> node_simulation_i
|
|||
GeometrySet &geometry = *static_cast<GeometrySet *>(input_value);
|
||||
auto geometry_state_item = std::make_unique<bke::sim::GeometrySimulationStateItem>(
|
||||
std::move(geometry));
|
||||
stored_geometries.append(&geometry_state_item->geometry());
|
||||
stored_geometries.append(&geometry_state_item->geometry);
|
||||
state_item = std::move(geometry_state_item);
|
||||
break;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
typo