Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
AssetManager.AssetReference.cs
Go to the documentation of this file.
1 // Copyright (c) 2014 Silicon Studio Corp. (http://siliconstudio.co.jp)
2 // This file is distributed under GPL v3. See LICENSE.md for details.
3 using System;
4 using System.Collections.Generic;
5 using System.Linq;
6 using System.Text;
7 using System.Threading.Tasks;
8 using SiliconStudio.Core.Storage;
9 
10 namespace SiliconStudio.Core.Serialization.Assets
11 {
12  partial class AssetManager
13  {
14  /// <summary>
15  /// Internal object that represents a loaded asset, with its url and reference counts.
16  /// </summary>
17  internal class AssetReference
18  {
19  /// <summary>
20  /// The next item in the linked list.
21  /// </summary>
22  public AssetReference Next, Prev;
23 
24  /// <summary>
25  /// The object being referenced.
26  /// </summary>
27  public object Object;
28 
29  /// <summary>
30  /// The URL.
31  /// </summary>
32  public readonly string Url;
33 
34  /// <summary>
35  /// The URL.
36  /// </summary>
37  public readonly ObjectId ObjectId;
38 
39  /// <summary>
40  /// The public reference count (corresponding to AssetManager.Load/Unload).
41  /// </summary>
42  public int PublicReferenceCount;
43 
44  /// <summary>
45  /// The private reference count (corresponding to an object being referenced indirectly by other loaded objects).
46  /// </summary>
47  public int PrivateReferenceCount;
48 
49  // Used internally for GC (maybe we could just use higher byte of PrivateReferenceCount or something like that?)
50  public uint CollectIndex;
51 
52  // TODO: Lazily create this list?
53  public HashSet<AssetReference> References = new HashSet<AssetReference>();
54 
55  public AssetReference(ObjectId objectId, string url, bool publicReference)
56  {
57  ObjectId = objectId;
58  Url = url;
59  PublicReferenceCount = publicReference ? 1 : 0;
60  PrivateReferenceCount = publicReference ? 0 : 1;
61  CollectIndex = uint.MaxValue;
62  }
63 
64  public override string ToString()
65  {
66  return string.Format("{0}, references: {1} public(s), {2} private(s)", Object, PublicReferenceCount, PrivateReferenceCount);
67  }
68  }
69  }
70 }
A hash to uniquely identify data.
Definition: ObjectId.cs:13