RedCore
Loading...
Searching...
No Matches
ProfileReplaceBuilder.h
Go to the documentation of this file.
1
#
pragma
once
2
3
#
include
<
concepts
>
4
5
#
include
<
actor
/
ProfileInfo
.
h
>
6
#
include
<
actor
/
Actor
.
h
>
7
#
include
<
red
/
registry
/
builder
/
ProfileBuilder
.
h
>
8
#
include
<
red
/
public
/
Profile
.
h
>
9
#
include
<
red
/
profile
/
ProfileEx
.
h
>
10
#
include
<
red
/
event
/
StaticInitEvent
.
h
>
11
#
include
<
telkin
/
Privilege
.
h
>
12
13
namespace
red
{
14
15
/**
16
* @brief Builder for replacing a vanilla profile with a custom one by its numeric ID.
17
* @tparam T Actor class that the profile will now instantiate.
18
* @tparam ID The target profile ID to replace.
19
*/
20
template
<
class
T
,
s32
ID
>
requires
std
::
derived_from
<
T
,
ActorBase
>
21
class
ProfileReplaceBuilder
:
public
ProfileBuilder
<
ProfileReplaceBuilder
<
T
,
ID
>> {
22
public
:
23
static_assert
(
ID
<=
ProfileInfo
::
cProfileID_Max
,
"ERROR: Attempting to replace an invalid vanilla profile ID."
);
24
25
ProfileReplaceBuilder
()
26
:
ProfileBuilder
<
ProfileReplaceBuilder
<
T
,
ID
>>()
27
{ }
28
29
/**
30
* @brief Completes the builder by replacing the vanilla profile.
31
* @return The profile which now contains the replaced data.
32
*/
33
Profile
*
build
() {
34
static
bool
instantiated
=
false
;
35
if
(
instantiated
) {
36
tk
::
fatal
(
"Cannot reuse the same template instanciation for two replacements."
);
37
}
38
instantiated
=
true
;
39
40
// defer until the vanilla profile is inited so we have the final say
41
static
const
struct
{
42
const
ActorCreateInfo
*
mCreateInfo
;
43
Profile
::
Flag
mFlag
;
44
s16
mDrawPriority
;
45
s16
mExecutePriority
;
46
sead
::
SafeString
*
mResources
;
47
u8
mResourceCount
;
48
s8
mResourceType
;
49
}
sSnapshot
= {
50
.
mCreateInfo
=
this
->
mCreateInfo
,
51
.
mFlag
=
this
->
mFlag
,
52
.
mDrawPriority
=
this
->
mDrawPriority
,
53
.
mExecutePriority
=
this
->
mExecutePriority
,
54
.
mResources
=
this
->
mResources
,
55
.
mResourceCount
=
this
->
mResourceCount
,
56
.
mResourceType
=
this
->
mResourceType
57
};
58
59
static
red
::
StaticInitEvent
::
Listener
listener
([](
red
::
StaticInitEvent
&) {
60
pub
::
Profile
*
profile
=
static_cast
<
pub
::
Profile
*>(
Profile
::
get
(
ID
));
61
62
profile
->
mFactory
= &
TActorFactory
<
T
>;
63
profile
->
mActorCreateInfo
=
sSnapshot
.
mCreateInfo
!=
nullptr
?
sSnapshot
.
mCreateInfo
: &
ActorCreateInfo
::
cDefault
;
64
profile
->
mIsResLoaded
=
false
;
65
profile
->
mFlag
=
sSnapshot
.
mFlag
;
66
67
tk
::
privilegedWrite
(&
ProfileInfo
::
cDrawPriority
[
ID
], &
sSnapshot
.
mDrawPriority
,
sizeof
(
ProfileInfo
::
cDrawPriority
[
ID
]));
68
tk
::
privilegedWrite
(&
ProfileInfo
::
cResList
[
ID
], &
sSnapshot
.
mResources
,
sizeof
(
ProfileInfo
::
cResList
[
ID
]));
// NOLINT
69
tk
::
privilegedWrite
(&
ProfileInfo
::
cResNum
[
ID
], &
sSnapshot
.
mResourceCount
,
sizeof
(
ProfileInfo
::
cResNum
[
ID
]));
70
tk
::
privilegedWrite
(&
ProfileInfo
::
cResType
[
ID
], &
sSnapshot
.
mResourceType
,
sizeof
(
ProfileInfo
::
cResType
[
ID
]));
71
72
ProfileEx
::
setExecutePriority
(
ID
,
sSnapshot
.
mExecutePriority
);
73
});
74
75
return
ProfileEx
::
get
(
ID
);
76
}
77
};
78
79
}
red
Definition
ActorDonutBlock.h:5
include
red
registry
builder
ProfileReplaceBuilder.h
Generated by
1.14.0