Terraria
v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
Asset.cs
Go to the documentation of this file.
1
using
System
;
2
using
System.Threading
;
3
using
ReLogic.Content.Sources
;
4
5
namespace
ReLogic.Content
;
6
7
public
sealed
class
Asset
<T> :
IAsset
,
IDisposable
where T : class
8
{
9
public
static
readonly
Asset<T>
Empty
=
new
Asset<T>
(
""
);
10
11
private
T
ownValue
;
12
13
public
static
T
DefaultValue
{
get
;
set
; }
14
15
public
string
Name
{
get
;
private
set
; }
16
17
public
bool
IsLoaded
=> State ==
AssetState
.Loaded;
18
19
public
AssetState
State {
get
;
private
set
; }
20
21
public
bool
IsDisposed
{
get
;
private
set
; }
22
23
public
IContentSource
Source
{
get
;
private
set
; }
24
25
public
T
Value
26
{
27
get
28
{
29
if
(!
IsLoaded
)
30
{
31
return
DefaultValue
;
32
}
33
return
ownValue
;
34
}
35
}
36
37
internal
Action
Continuation
{
get
;
set
; }
38
39
Action IAsset.Continuation
40
{
41
set
42
{
43
Continuation
=
value
;
44
}
45
}
46
47
public
Action
Wait
{
get
;
internal
set
; }
48
49
internal
Asset
(
string
name)
50
{
51
State =
AssetState
.NotLoaded;
52
Name
= name;
53
}
54
55
public
static
explicit
operator
T
(
Asset<T>
asset)
56
{
57
return
asset.
Value
;
58
}
59
60
internal
void
Unload
()
61
{
62
(
ownValue
as
IDisposable
)?.
Dispose
();
63
State =
AssetState
.NotLoaded;
64
ownValue
=
null
;
65
Source
=
null
;
66
}
67
68
internal
void
SubmitLoadedContent
(T
value
,
IContentSource
source
)
69
{
70
if
(
value
==
null
)
71
{
72
throw
new
ArgumentNullException
(
"value"
);
73
}
74
(
ownValue
as
IDisposable
)?.
Dispose
();
75
ownValue
=
value
;
76
Source
=
source
;
77
Thread
.
MemoryBarrier
();
78
State =
AssetState
.Loaded;
79
}
80
81
internal
void
SetToLoadingState
()
82
{
83
State =
AssetState
.Loading;
84
}
85
86
private
void
Dispose
(
bool
disposing)
87
{
88
if
(
IsDisposed
)
89
{
90
return
;
91
}
92
if
(disposing &&
ownValue
!=
null
)
93
{
94
IDisposable
disposable =
ownValue
as
IDisposable
;
95
if
(
IsLoaded
)
96
{
97
disposable?.
Dispose
();
98
}
99
ownValue
=
null
;
100
}
101
IsDisposed
=
true
;
102
}
103
104
public
void
Dispose
()
105
{
106
Dispose
(disposing:
true
);
107
}
108
}
ReLogic.Content.Asset.Dispose
void Dispose()
Definition
Asset.cs:104
ReLogic.Content.Asset.SubmitLoadedContent
void SubmitLoadedContent(T value, IContentSource source)
Definition
Asset.cs:68
ReLogic.Content.Asset.Value
T Value
Definition
Asset.cs:26
ReLogic.Content.Asset.DefaultValue
static T DefaultValue
Definition
Asset.cs:13
ReLogic.Content.Asset.IsDisposed
bool IsDisposed
Definition
Asset.cs:21
ReLogic.Content.Asset.Source
IContentSource Source
Definition
Asset.cs:23
ReLogic.Content.Asset.IsLoaded
bool IsLoaded
Definition
Asset.cs:17
ReLogic.Content.Asset.Unload
void Unload()
Definition
Asset.cs:60
ReLogic.Content.Asset.Wait
Action Wait
Definition
Asset.cs:47
ReLogic.Content.Asset.Asset
Asset(string name)
Definition
Asset.cs:49
ReLogic.Content.Asset.ownValue
T ownValue
Definition
Asset.cs:11
ReLogic.Content.Asset.Dispose
void Dispose(bool disposing)
Definition
Asset.cs:86
ReLogic.Content.Asset.Name
string Name
Definition
Asset.cs:15
ReLogic.Content.Asset.Continuation
Action Continuation
Definition
Asset.cs:37
ReLogic.Content.Asset.SetToLoadingState
void SetToLoadingState()
Definition
Asset.cs:81
ReLogic.Content.Asset
Definition
Asset.cs:8
System.ArgumentNullException
Definition
ArgumentNullException.cs:10
System.Empty
Definition
Empty.cs:4
System.Threading.Thread.MemoryBarrier
static void MemoryBarrier()
Definition
Thread.cs:827
System.Threading.Thread
Definition
Thread.cs:13
ReLogic.Content.IAsset
Definition
IAsset.cs:7
ReLogic.Content.Sources.IContentSource
Definition
IContentSource.cs:8
System.IDisposable.Dispose
void Dispose()
System.IDisposable
Definition
IDisposable.cs:4
ReLogic.Content.Sources
Definition
ContentSource.cs:6
ReLogic.Content.AssetState
AssetState
Definition
AssetState.cs:4
ReLogic.Content
Definition
IAssetReader.cs:5
System.Threading
Definition
TaskToApm.cs:3
System.ExceptionArgument.value
@ value
System.ExceptionArgument.source
@ source
System.ConsoleKey.T
@ T
System
Definition
BlockingCollection.cs:8
source
ReLogic
ReLogic.Content
Asset.cs
Generated by
1.10.0