Codestyle adjustments #3343

This commit is contained in:
Wojtek Figat
2025-08-24 13:46:53 +02:00
parent 4bd8ce37ac
commit df6f8fd8ae
3 changed files with 15 additions and 22 deletions

View File

@@ -32,7 +32,7 @@ namespace FlaxEngine
/// <summary> /// <summary>
/// Determines whether the specified layer is set in the mask. /// Determines whether the specified layer is set in the mask.
/// </summary> /// </summary>
/// <param name="layerName">Name of the layer (from layers settings).</param> /// <param name="layerName">Name of the layer (from Layers settings).</param>
/// <returns><c>true</c> if the specified layer is set; otherwise, <c>false</c>.</returns> /// <returns><c>true</c> if the specified layer is set; otherwise, <c>false</c>.</returns>
public bool HasLayer(string layerName) public bool HasLayer(string layerName)
{ {
@@ -42,22 +42,20 @@ namespace FlaxEngine
/// <summary> /// <summary>
/// Gets a layer mask based on a specific layer names. /// Gets a layer mask based on a specific layer names.
/// </summary> /// </summary>
/// <param name="layerNames">The names of the layers (from layers settings).</param> /// <param name="layerNames">The names of the layers (from Layers settings).</param>
/// <returns>A layer mask with the mask set to the layers found. Returns a mask with 0 if not found. </returns> /// <returns>A layer mask with the mask set to the layers found. Returns a mask with 0 if not found.</returns>
public static LayersMask GetMask(params string[] layerNames) public static LayersMask GetMask(params string[] layerNames)
{ {
LayersMask mask = new LayersMask(); LayersMask mask = new LayersMask();
foreach (var layerName in layerNames) foreach (var layerName in layerNames)
{ {
// Ignore blank entries // Ignore blank entries
if (layerName.Length == 0) if (string.IsNullOrEmpty(layerName))
continue; continue;
int index = Level.GetLayerIndex(layerName); int index = Level.GetLayerIndex(layerName);
if (index != -1 && !mask.HasLayer(index)) if (index != -1)
{
mask.Mask |= (uint)(1 << index); mask.Mask |= (uint)(1 << index);
} }
}
return mask; return mask;
} }

View File

@@ -40,16 +40,16 @@ public:
/// <summary> /// <summary>
/// Determines whether the specified layer name is set in the mask. /// Determines whether the specified layer name is set in the mask.
/// </summary> /// </summary>
/// <param name="layerName">Name of the layer (from layers settings).</param> /// <param name="layerName">Name of the layer (from Layers settings).</param>
/// <returns><c>true</c> if the specified layer is set; otherwise, <c>false</c>.</returns> /// <returns><c>true</c> if the specified layer is set; otherwise, <c>false</c>.</returns>
bool HasLayer(const StringView& layerName); bool HasLayer(const StringView& layerName) const;
/// <summary> /// <summary>
/// Gets a layers mask from a specific layer name. /// Gets a layers mask from a specific layer name.
/// </summary> /// </summary>
/// <param name="layerNames">The layer names.</param> /// <param name="layerNames">The names of the layers (from Layers settings).</param>
/// <returns>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.</returns> /// <returns>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.</returns>
static LayersMask GetMask(StringView layerNames[]); static LayersMask GetMask(Span<StringView> layerNames);
operator uint32() const operator uint32() const
{ {

View File

@@ -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)); return HasLayer(Level::GetLayerIndex(layerName));
} }
LayersMask LayersMask::GetMask(StringView layerNames[]) LayersMask LayersMask::GetMask(Span<StringView> layerNames)
{ {
LayersMask mask(0); LayersMask mask(0);
if (layerNames == nullptr) for (StringView& layerName : layerNames)
return mask;
for (int i = 0; i < layerNames->Length(); i++)
{ {
StringView& layerName = layerNames[i];
// Ignore blank entries // Ignore blank entries
if (layerName.Length() == 0) if (layerName.Length() == 0)
continue; continue;
int index = Level::GetLayerIndex(layerName); int32 index = Level::GetLayerIndex(layerName);
if (index != -1 && !mask.HasLayer(index)) if (index != -1)
{ mask.Mask |= (uint32)(1 << index);
mask.Mask |= static_cast<uint32>(1 << index);
}
} }
return mask; return mask;
} }