UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
VVMTaskNativeHook.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
5#if WITH_VERSE_VM || defined(__INTELLISENSE__)
6
7#include "VerseVM/VVMCell.h"
10
11namespace Verse
12{
13
14struct VTask;
15struct FAccessContext;
16struct VEmergentType;
17
19{
22
23 // If desired, this can point to the hook added after this one
25
26 // The lambda can be mutable, therefore invocation is not const
27 void Invoke(FAllocationContext Context, VTask* Task)
28 {
29 Invoker(Context, this, Task);
30 }
31 void InvokeTransactionally(FAllocationContext Context, VTask* Task)
32 {
34 }
35
36 // WARNING 1: The destructor of the lambda passed in must be thread safe since it can be invoked on the GC thread
37 // WARNING 2: Any VCells or UObjects captured by the lambda will not be visited during GC
38 template <
39 typename FunctorType,
40 typename FunctorTypeDecayed = std::decay_t<FunctorType>
42 !TIsTFunction<FunctorTypeDecayed>::Value && std::is_invocable_r_v<void, FunctorTypeDecayed, FAllocationContext, VTask*>)>
43 static VTaskNativeHook& New(FAllocationContext Context, FunctorType&& Func);
44
45 template <
46 typename FunctorType,
47 typename FunctorTypeDecayed = std::decay_t<FunctorType>
49 !TIsTFunction<FunctorTypeDecayed>::Value && std::is_invocable_r_v<void, FunctorTypeDecayed, FAllocationContext, VTask*>)>
50 static VTaskNativeHook& NewOpen(FAllocationContext Context, FunctorType&& Func);
51
52protected:
53 using InvokerType = void (*)(FAllocationContext, VTaskNativeHook*, VTask*);
55
60 , Destructor(InDestructor)
61 {
62 }
63
65 {
66 Destructor(this);
67 }
68
69 template <typename HookType>
70 static VTaskNativeHook& NewInternal(FAllocationContext Context, typename HookType::FunctorTypeDecayed&& Func);
71
72private:
75 DestructorType Destructor;
76};
77
79template <typename TFunctorTypeDecayed>
81{
83
86 Context,
87 /*InInvoker*/ [](FAllocationContext Context, VTaskNativeHook* This, VTask* Task) { static_cast<TTaskNativeHookClosed*>(This)->Func(Context, Task); },
88 /*InTransactionalInvoker*/ [](FAllocationContext Context, VTaskNativeHook* This, VTask* Task) {
89 AutoRTFM::EContextStatus Status = AutoRTFM::Close([&] {
90 static_cast<TTaskNativeHookClosed*>(This)->Func(Context, Task);
91 });
92 V_DIE_UNLESS(Status == AutoRTFM::EContextStatus::OnTrack); },
93 /*InDestructor*/ [](VTaskNativeHook* This) {
94 // Destroy only what's not already contained in the base class
95 static_cast<TTaskNativeHookClosed*>(This)->Func.~FunctorTypeDecayed(); })
97 {
98 }
99
101};
102
104template <typename TFunctorTypeDecayed>
106{
108
111 Context,
112 /*InInvoker*/ [](FAllocationContext Context, VTaskNativeHook* This, VTask* Task) { static_cast<TTaskNativeHookOpen*>(This)->Func(Context, Task); },
113 /*InTransactionalInvoker*/ [](FAllocationContext Context, VTaskNativeHook* This, VTask* Task) { static_cast<TTaskNativeHookOpen*>(This)->Func(Context, Task); },
114 /*InDestructor*/ [](VTaskNativeHook* This) {
115 // Destroy only what's not already contained in the base class
116 static_cast<TTaskNativeHookOpen*>(This)->Func.~FunctorTypeDecayed(); })
118 {
119 }
120
122};
123
124template <typename HookType>
125VTaskNativeHook& VTaskNativeHook::NewInternal(FAllocationContext Context, typename HookType::FunctorTypeDecayed&& Func)
126{
127 std::byte* Allocation = std::is_trivially_destructible_v<typename HookType::FunctorTypeDecayed>
128 ? Context.AllocateFastCell(sizeof(HookType))
129 : Context.Allocate(FHeap::DestructorSpace, sizeof(HookType));
130
131 return *new (Allocation) HookType(Context, Forward<typename HookType::FunctorTypeDecayed>(Func));
132}
133
134template <
135 typename FunctorType,
136 typename FunctorTypeDecayed
138 !TIsTFunction<FunctorTypeDecayed>::Value && std::is_invocable_r_v<void, FunctorTypeDecayed, FAllocationContext, VTask*>)>
139VTaskNativeHook& VTaskNativeHook::New(FAllocationContext Context, FunctorType&& Func)
140{
142}
143
144template <
145 typename FunctorType,
146 typename FunctorTypeDecayed
148 !TIsTFunction<FunctorTypeDecayed>::Value && std::is_invocable_r_v<void, FunctorTypeDecayed, FAllocationContext, VTask*>)>
149VTaskNativeHook& VTaskNativeHook::NewOpen(FAllocationContext Context, FunctorType&& Func)
150{
152}
153
154} // namespace Verse
155
156#endif
OODEFFUNC typedef void(OODLE_CALLBACK t_fp_OodleCore_Plugin_Free)(void *ptr)
#define AUTORTFM_INFER
Definition AutoRTFMDefines.h:121
AUTORTFM_INFER UE_FORCEINLINE_HINT constexpr auto Invoke(FuncType &&Func, ArgTypes &&... Args) -> decltype(((FuncType &&) Func)((ArgTypes &&) Args...))
Definition Invoke.h:44
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
T * New(FMemStackBase &Mem, int32 Count=1, int32 Align=DEFAULT_ALIGNMENT)
Definition MemStack.h:259
#define UE_REQUIRES(...)
Definition Requires.h:86
FORCEINLINE T * Get(const FObjectPtr &ObjectPtr)
Definition ObjectPtr.h:426
Definition Archive.h:36
Definition FunctionFwd.h:32