Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions Engine/Collection/DrawnCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ namespace Altseed2
{
internal class DrawnCollection
{
public bool IsCollectionInForeach = false;
private SortedDictionary<int, HashSet<IDrawn>> _Drawns;
private SortedDictionary<int, SortedDictionary<int, HashSet<IDrawn>>> _Sorted;

Expand All @@ -19,6 +20,7 @@ internal DrawnCollection()
internal void Register(IDrawn node)
{
if (node == null) throw new ArgumentNullException(nameof(node));
if (IsCollectionInForeach) throw new InvalidOperationException();

{
if (!_Drawns.TryGetValue(node.ZOrder, out var set))
Expand All @@ -44,6 +46,7 @@ internal void Register(IDrawn node)
internal void Unregister(IDrawn node)
{
if (node == null) throw new ArgumentNullException(nameof(node));
if (IsCollectionInForeach) throw new InvalidOperationException();

_Drawns[node.ZOrder].Remove(node);

Expand All @@ -60,6 +63,7 @@ internal void Unregister(IDrawn node)
internal void UpdateCameraGroup(IDrawn node, ulong old)
{
if (node == null) throw new ArgumentNullException(nameof(node));
if (IsCollectionInForeach) throw new InvalidOperationException();

for (int i = 0; i < Engine.MaxCameraGroupCount; i++)
{
Expand Down Expand Up @@ -87,6 +91,7 @@ internal void UpdateCameraGroup(IDrawn node, ulong old)
internal void UpdateZOrder(IDrawn node, int old)
{
if (node == null) throw new ArgumentNullException(nameof(node));
if (IsCollectionInForeach) throw new InvalidOperationException();

{
_Drawns[old].Remove(node);
Expand Down
4 changes: 4 additions & 0 deletions Engine/Engine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,9 @@ internal static bool UpdateComponents(bool drawDefaultCameraGroup, bool drawCust
if (drawDefaultCameraGroup)
{
// カメラが 1 つもない場合はデフォルトカメラを使用
_DrawnCollection.IsCollectionInForeach = true;
DrawCameraGroup(_DefaultCamera, _DrawnCollection.GetDrawns());
_DrawnCollection.IsCollectionInForeach = false;
}

if (drawCustomCameraGroup)
Expand All @@ -194,7 +196,9 @@ internal static bool UpdateComponents(bool drawDefaultCameraGroup, bool drawCust
{
foreach (var camera in _CameraNodes[i])
{
_DrawnCollection.IsCollectionInForeach = true;
DrawCameraGroup(camera.RenderedCamera, _DrawnCollection[i]);
_DrawnCollection.IsCollectionInForeach = false;
}
}
}
Expand Down