A game framework written with osu! in mind.

Remove AtomicCounter to reduce draw node object allocations slightly

+5 -31
+5 -5
osu.Framework/Graphics/DrawNode.cs
··· 1 // Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. 2 // See the LICENCE file in the repository root for full licence text. 3 4 - using osu.Framework.Graphics.OpenGL; 5 using System; 6 using System.Runtime.CompilerServices; 7 using osu.Framework.Graphics.Batches; 8 using osu.Framework.Graphics.Colour; 9 using osu.Framework.Graphics.OpenGL.Buffers; 10 using osu.Framework.Graphics.OpenGL.Textures; 11 using osu.Framework.Graphics.OpenGL.Vertices; 12 using osu.Framework.Graphics.Primitives; 13 using osu.Framework.Graphics.Textures; 14 - using osu.Framework.Threading; 15 using osu.Framework.Utils; 16 using osuTK; 17 ··· 45 /// </summary> 46 protected IDrawable Source { get; private set; } 47 48 - private readonly AtomicCounter referenceCount = new AtomicCounter(); 49 50 /// <summary> 51 /// The depth at which drawing should take place. ··· 282 /// <remarks> 283 /// All <see cref="DrawNode"/>s start with a reference count of 1. 284 /// </remarks> 285 - internal void Reference() => referenceCount.Increment(); 286 287 protected internal bool IsDisposed { get; private set; } 288 289 public void Dispose() 290 { 291 - if (referenceCount.Decrement() != 0) 292 return; 293 294 GLWrapper.ScheduleDisposal(() => Dispose(true));
··· 1 // Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. 2 // See the LICENCE file in the repository root for full licence text. 3 4 using System; 5 using System.Runtime.CompilerServices; 6 + using System.Threading; 7 using osu.Framework.Graphics.Batches; 8 using osu.Framework.Graphics.Colour; 9 + using osu.Framework.Graphics.OpenGL; 10 using osu.Framework.Graphics.OpenGL.Buffers; 11 using osu.Framework.Graphics.OpenGL.Textures; 12 using osu.Framework.Graphics.OpenGL.Vertices; 13 using osu.Framework.Graphics.Primitives; 14 using osu.Framework.Graphics.Textures; 15 using osu.Framework.Utils; 16 using osuTK; 17 ··· 45 /// </summary> 46 protected IDrawable Source { get; private set; } 47 48 + private long referenceCount; 49 50 /// <summary> 51 /// The depth at which drawing should take place. ··· 282 /// <remarks> 283 /// All <see cref="DrawNode"/>s start with a reference count of 1. 284 /// </remarks> 285 + internal void Reference() => Interlocked.Increment(ref referenceCount); 286 287 protected internal bool IsDisposed { get; private set; } 288 289 public void Dispose() 290 { 291 + if (Interlocked.Decrement(ref referenceCount) != 0) 292 return; 293 294 GLWrapper.ScheduleDisposal(() => Dispose(true));
-26
osu.Framework/Threading/AtomicCounter.cs
··· 1 - // Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. 2 - // See the LICENCE file in the repository root for full licence text. 3 - 4 - using System.Threading; 5 - 6 - namespace osu.Framework.Threading 7 - { 8 - public class AtomicCounter 9 - { 10 - private long count; 11 - 12 - public long Increment() => Interlocked.Increment(ref count); 13 - 14 - public long Decrement() => Interlocked.Decrement(ref count); 15 - 16 - public long Add(long value) => Interlocked.Add(ref count, value); 17 - 18 - public long Reset() => Interlocked.Exchange(ref count, 0); 19 - 20 - public long Value 21 - { 22 - set => Interlocked.Exchange(ref count, value); 23 - get => Interlocked.Read(ref count); 24 - } 25 - } 26 - }
···