Game.OptionalProperties
Assembly: Assembly-CSharp (inferred)
Namespace: Game.Rendering
Type: struct OptionalProperties
Base: IOptionalProperties
Summary:
OptionalProperties is a small value-type container used by the rendering pipeline to represent optional rendering requirements or capabilities. It stores a set of BatchFlags and a bitmask of MeshType values and provides helpers to test whether a given set of requirements is satisfied, to merge mesh-type requirements, and to compare two instances for equality. This struct is intended for use when deciding whether a rendering property or feature should be enabled for a given batch/mesh combination.
Fields
-
private BatchFlags m_Flags
Stores the BatchFlags bitmask representing the batch-level flags required or provided by this instance. Used as part of the enablement check and equality comparison. -
private MeshType m_MeshTypes
Bitmask of MeshType values representing which mesh types are relevant/required. Used to check mesh-type overlap with other requirement sets and is updated when merging requirements.
Properties
- This type exposes no public properties. All data is stored in private fields and manipulated via the provided methods.
Constructors
public OptionalProperties(BatchFlags flags, MeshType meshTypes)
Initializes a new OptionalProperties instance with the given batch flags and mesh-type bitmask. Both parameters are stored directly into the private fields.
Methods
public bool EnableProperty(OptionalProperties required)
Determines whether this OptionalProperties instance satisfies the supplied required requirements.
Behavior: - Returns false if this.m_Flags does not contain all bits set in required.m_Flags. - If flags are satisfied, it checks mesh-type overlap: if (this.m_MeshTypes & required.m_MeshTypes) != 0 then returns true. - If there is no mesh-type overlap, it returns true only if required.m_MeshTypes == 0 (i.e., the requirement does not specify any mesh types and is therefore satisfied on flags alone).
This method is effectively: flags must be a superset of required flags, and either there must be at least one common mesh type or the requirement specifies no mesh types.
public bool MergeRequirements(OptionalProperties other)
Merges mesh-type requirements from other into this instance by OR-ing the mesh-type bitmask:- this.m_MeshTypes |= other.m_MeshTypes;
- It then returns whether the batch flags are equal (this.m_Flags == other.m_Flags).
Note: MergeRequirements mutates the struct instance's m_MeshTypes.
public bool Equals(OptionalProperties other)
Implements value equality for the struct by returning true when both m_Flags and m_MeshTypes are equal.
Additionally, because the struct implements IEquatable
Usage Example
// Example values; replace BatchFlags.SomeFlag and MeshType.MeshA with actual enum members.
var a = new OptionalProperties(BatchFlags.SomeFlag, MeshType.MeshA | MeshType.MeshB);
var required = new OptionalProperties(BatchFlags.SomeFlag, MeshType.MeshA);
// Test whether 'a' satisfies the 'required' requirements
bool enabled = a.EnableProperty(required); // true if flags match and MeshA is present
// Merge required mesh types into 'a' (adds any mesh types from required)
bool flagsMatch = a.MergeRequirements(required); // returns whether m_Flags were equal; 'a' now has unioned mesh types
// Equality check
var b = new OptionalProperties(BatchFlags.SomeFlag, MeshType.MeshA | MeshType.MeshB);
bool equal = a.Equals(b); // true if same flags and mesh types
Notes and caveats: - OptionalProperties is a mutable value type (struct). Be careful with copies — calling MergeRequirements on a copy will not update the original instance. Also calling methods via an interface reference may cause boxing/copy semantics; prefer calling methods on the concrete struct variable to avoid surprises. - BatchFlags and MeshType are enum bitmasks defined elsewhere (Colossal.Rendering / Game.Prefabs). Ensure you use the correct enum values when constructing instances.