forked from ncsoft/Unreal.js-core
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathJavascriptInstanceComponent.h
123 lines (87 loc) · 3.83 KB
/
JavascriptInstanceComponent.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#pragma once
#include "Components/ActorComponent.h"
#include "JavascriptInstanceHandler.h"
#include "JavascriptInstanceComponent.generated.h"
DECLARE_DYNAMIC_MULTICAST_DELEGATE(FJsInstBPNoParamDelegate);
DECLARE_DYNAMIC_DELEGATE(FJsInstNoParamDelegate);
DECLARE_DYNAMIC_DELEGATE_OneParam(FJsInstTickSignature, float, DeltaSeconds);
DECLARE_DYNAMIC_DELEGATE_TwoParams(FJsInstMessageSignature, FString, Name, FString, Message);
DECLARE_DYNAMIC_DELEGATE_TwoParams(FJsInstBytesMessageSignature, FString, Name, const TArray<uint8>&, Bytes);
//A javascript instance may re-use isolates and gives greater control over expose vs classical javascript component.
UCLASS(BlueprintType, ClassGroup = Script, meta = (BlueprintSpawnableComponent))
class V8_API UJavascriptInstanceComponent : public UActorComponent
{
GENERATED_UCLASS_BODY()
public:
//Blueprint notifications
//Called before script start
UPROPERTY(BlueprintAssignable)
FJsInstBPNoParamDelegate OnInstanceReady;
//Called just before a script gets run
UPROPERTY(BlueprintAssignable)
FJsInstBPNoParamDelegate OnScriptBegin;
//Called just after a script finished
UPROPERTY(BlueprintAssignable)
FJsInstBPNoParamDelegate OnScriptInitPassEnd;
//Called after instance shutdown (not necessarily a reload)
UPROPERTY(BlueprintAssignable)
FJsInstBPNoParamDelegate OnShutdownCompleteCallback;
//Called between shutdown and reload and start (non-fast reload)
UPROPERTY(BlueprintAssignable)
FJsInstBPNoParamDelegate OnInterReload;
//These are only called on javascript side
UPROPERTY()
FJsInstTickSignature OnTick;
UPROPERTY()
FJsInstNoParamDelegate OnBeginPlay;
UPROPERTY()
FJsInstNoParamDelegate OnEndPlay;
//Linked with EmitToJs
UPROPERTY()
FJsInstMessageSignature OnMessage;
UPROPERTY()
FJsInstBytesMessageSignature OnBytesMessage;
//Specify common domain/uniqueness etc of instance
UPROPERTY(BlueprintReadWrite, EditAnywhere, Category= "Javascript Instance Component")
FJSInstanceOptions InstanceOptions;
UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = "Javascript Instance Component")
FString DefaultScript;
UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = "Javascript Instance Inspector")
bool bCreateInspectorOnInstanceStartup;
UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = "Javascript Instance Inspector")
int32 InspectorPort;
UFUNCTION(BlueprintCallable, Category = "Js Functions")
void Expose(const FString& JsName, UObject* ObjectToExpose);
UFUNCTION(BlueprintCallable, Category = "Javascript")
void Emit(const FString& Name, const FString& Message);
UFUNCTION(BlueprintCallable, Category = "Javascript")
void EmitBytes(const FString& Name, const TArray<uint8>& Bytes);
//Slower version of instant update
UFUNCTION(BlueprintCallable, Category = "Javascript")
void Reload();
UFUNCTION(BlueprintCallable, Category = "Javascript")
void RunFile(const FString& FilePath);
/** Used to load a soft referenced class in Js for extension */
UFUNCTION(BlueprintCallable, Category = "Javascript")
UClass* ClassByName(const FString& ClassName);
UFUNCTION(BlueprintCallable, Category = "Javascript")
void CreateInspector(int32 Port);
// Begin UActorComponent interface.
virtual void InitializeComponent() override;
virtual void UninitializeComponent() override;
virtual void TickComponent(float DeltaTime, enum ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override;
// Begin UActorComponent interface.
protected:
void StartupInstanceAndRun();
void ShutDownInstance();
TSharedPtr<FJavascriptInstanceHandler> MainHandler;
TSharedPtr<FJavascriptInstance> Instance;
FThreadSafeBool bShouldScriptRun;
FThreadSafeBool bIsThreadRunning;
bool bIsScriptRunning;
UPROPERTY()
UJavascriptIsolate* IsolateReflection;
UPROPERTY()
UJavascriptContext* ContextReflection; //only used for console
};
//hideCategories = (ComponentReplication) Blueprintable