diff --git a/Source/Engine/Core/Types/LayersMask.cs b/Source/Engine/Core/Types/LayersMask.cs index 2838e7219..7d5c57066 100644 --- a/Source/Engine/Core/Types/LayersMask.cs +++ b/Source/Engine/Core/Types/LayersMask.cs @@ -32,7 +32,7 @@ namespace FlaxEngine /// /// Determines whether the specified layer is set in the mask. /// - /// Name of the layer (from layers settings). + /// Name of the layer (from Layers settings). /// true if the specified layer is set; otherwise, false. public bool HasLayer(string layerName) { @@ -42,21 +42,19 @@ namespace FlaxEngine /// /// Gets a layer mask based on a specific layer names. /// - /// The names of the layers (from layers settings). - /// A layer mask with the mask set to the layers found. Returns a mask with 0 if not found. + /// The names of the layers (from Layers settings). + /// A layer mask with the mask set to the layers found. Returns a mask with 0 if not found. public static LayersMask GetMask(params string[] layerNames) { LayersMask mask = new LayersMask(); foreach (var layerName in layerNames) { // Ignore blank entries - if (layerName.Length == 0) + if (string.IsNullOrEmpty(layerName)) continue; int index = Level.GetLayerIndex(layerName); - if (index != -1 && !mask.HasLayer(index)) - { + if (index != -1) mask.Mask |= (uint)(1 << index); - } } return mask; } diff --git a/Source/Engine/Core/Types/LayersMask.h b/Source/Engine/Core/Types/LayersMask.h index 3f175773e..25edbc05b 100644 --- a/Source/Engine/Core/Types/LayersMask.h +++ b/Source/Engine/Core/Types/LayersMask.h @@ -40,16 +40,16 @@ public: /// /// Determines whether the specified layer name is set in the mask. /// - /// Name of the layer (from layers settings). + /// Name of the layer (from Layers settings). /// true if the specified layer is set; otherwise, false. - bool HasLayer(const StringView& layerName); + bool HasLayer(const StringView& layerName) const; /// /// Gets a layers mask from a specific layer name. /// - /// The layer names. + /// The names of the layers (from Layers settings). /// A layers mask with the Mask set to the same Mask as the layer name passed in. Returns a LayersMask with a mask of 0 if no layer found. - static LayersMask GetMask(StringView layerNames[]); + static LayersMask GetMask(Span layerNames); operator uint32() const { diff --git a/Source/Engine/Level/Level.cpp b/Source/Engine/Level/Level.cpp index 1ff7d2cad..3db39144d 100644 --- a/Source/Engine/Level/Level.cpp +++ b/Source/Engine/Level/Level.cpp @@ -60,27 +60,22 @@ void LargeWorlds::UpdateOrigin(Vector3& origin, const Vector3& position) } } -bool LayersMask::HasLayer(const StringView& layerName) +bool LayersMask::HasLayer(const StringView& layerName) const { return HasLayer(Level::GetLayerIndex(layerName)); } -LayersMask LayersMask::GetMask(StringView layerNames[]) +LayersMask LayersMask::GetMask(Span layerNames) { LayersMask mask(0); - if (layerNames == nullptr) - return mask; - for (int i = 0; i < layerNames->Length(); i++) + for (StringView& layerName : layerNames) { - StringView& layerName = layerNames[i]; // Ignore blank entries if (layerName.Length() == 0) continue; - int index = Level::GetLayerIndex(layerName); - if (index != -1 && !mask.HasLayer(index)) - { - mask.Mask |= static_cast(1 << index); - } + int32 index = Level::GetLayerIndex(layerName); + if (index != -1) + mask.Mask |= (uint32)(1 << index); } return mask; }