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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
|
//-----------------------------------------------------------------------------
// Name: asmodule.h
// Developer: Wolfire Games LLC
// Description:
// License: Read below
//-----------------------------------------------------------------------------
//
// Copyright 2022 Wolfire Games LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
//-----------------------------------------------------------------------------
#pragma once
#include <Asset/assets.h>
#include <Scripting/scriptfile.h>
#include <JSON/jsonhelper.h>
#include <Internal/integer.h>
#include <Logging/logdata.h>
#include <angelscript.h>
#include <string>
#include <vector>
#include <list>
#include <map>
class asIScriptModule;
class asIScriptEngine;
class asIScriptFunction;
struct AppObject;
struct ScriptObject;
struct TemplateObject;
enum VarStorageType {
_vs_unknown = 1,
_vs_bool = 2,
_vs_int8 = 3,
_vs_int32 = 4,
_vs_int64 = 5,
_vs_uint8 = 6,
_vs_uint32 = 7,
_vs_uint64 = 8,
_vs_float = 9,
_vs_enum = 10,
_vs_app_obj = 11,
_vs_script_obj = 12,
_vs_template = 13,
_vs_app_obj_handle = 14,
_vs_script_obj_handle = 15,
_vs_template_handle = 16,
_vs_int16 = 17,
_vs_uint16 = 18
};
enum ValueParent {
_vp_Global,
_vp_ScriptObject,
_vp_Array
};
enum AppObjectType {
_ao_vec3,
_ao_vec4,
_ao_ivec2,
_ao_ivec3,
_ao_ivec4,
_ao_string,
// -- Begin scenegraph objects --
_ao_ambient_sound_object,
_ao_camera_object,
_ao_decal_object,
_ao_dynamic_light_object,
_ao_env_object,
_ao_game_object,
_ao_group_object,
_ao_hotspot_object,
_ao_item_object,
_ao_light_probe_object,
_ao_light_volume_object,
_ao_movement_object,
_ao_navmesh_connection_object,
_ao_navmesh_hint_object,
_ao_navmesh_region_object,
_ao_path_point_object,
_ao_placeholder_object,
_ao_reflection_capture_object,
_ao_rigged_object,
_ao_terrain_object,
// -- End scenegraph objects --
_ao_attack_script_getter,
_ao_bone_transform,
_ao_quaternion,
_ao_vec2,
_ao_nav_path,
_ao_mat4,
_ao_json,
_ao_fontsetup,
_ao_modlevel,
_ao_textureassetref,
_ao_modid,
_ao_spawneritem,
_ao_IMFadeIn,
_ao_IMMoveIn,
_ao_IMChangeTextFadeOutIn,
_ao_IMChangeImageFadeOutIn,
_ao_IMPulseAlpha,
_ao_IMPulseBorderAlpha,
_ao_IMMouseOverMove,
_ao_IMMouseOverScale,
_ao_IMMouseOverShowBorder,
_ao_IMMouseOverPulseColor,
_ao_IMMouseOverPulseBorder,
_ao_IMMouseOverPulseBorderAlpha,
_ao_IMMouseOverFadeIn,
_ao_IMFixedMessageOnMouseOver,
_ao_IMFixedMessageOnClick,
_ao_IMMessage,
_ao_IMGUI,
_ao_IMElement,
_ao_IMContainer,
_ao_IMDivider,
_ao_IMImage,
_ao_IMText,
_ao_IMTextSelectionList,
_ao_IMSpacer,
_ao_IMUIImage,
_ao_IMUIText,
_ao_dictionary,
_ao_ignored,
_ao_unknown
};
struct VarStorage {
VarStorageType type;
int size;
std::string name;
std::string type_name;
void* var;
VarStorage();
void destroy();
std::string GetString(unsigned depth=0);
};
struct ScriptObjectInstance {
ScriptObjectInstance(uintptr_t ptr, VarStorage& var, bool from_script_obj_value);
void destroy();
uintptr_t ptr;
bool reconstructed;
bool from_script_obj_value; //This means there's a value version of this app object that all handles should re-refer to.
asIScriptObject* new_ptr; //New value generated
VarStorage var;
};
struct AppObject {
AppObjectType type;
void* original;
void* var;
AppObject();
void destroy();
};
struct AppObjectHandle {
AppObjectType type;
void* var;
AppObjectHandle();
void destroy();
};
enum TemplateObjectType {_to_array, _to_unknown};
struct TemplateObject {
TemplateObjectType type;
std::string sub_type_name;
void* var;
TemplateObject();
void destroy();
};
struct ScriptObject {
uintptr_t orig_ptr; //Original ptr.
std::string type_name;
std::string name_space;
std::list<VarStorage> storage;
void Populate( asIScriptObject * obj, std::list<ScriptObjectInstance>& handle_var_list, asIScriptModule *module );
void destroy();
};
struct ScriptObjectInstanceHandleRemap {
ValueParent var_type;
void* parent_ptr;
int parent_index;
uintptr_t orig_ptr;
};
class ASModule {
asIScriptModule *module_;
const ScriptFile* script_file_ptr_;
std::map<void*, void*> fast_var_ptr_map;
std::map<std::string, asIScriptFunction*> func_map_;
Path script_path_;
std::list<VarStorage> saved_vars_;
std::list<ScriptObjectInstance> saved_handle_vars_;
int64_t modified_;
std::string* active_angelscript_error_string;
ASModule(const ASModule&);
ASModule& operator=(const ASModule&);
public:
ASModule()
: active_angelscript_error_string(NULL)
{}
~ASModule();
void SetErrorStringDestination(std::string* error_string);
asIScriptModule* GetInternalScriptModule();
void AttachToEngine(asIScriptEngine* engine);
int CompileScript(const Path& path);
bool SourceChanged();
const Path& GetScriptPath();
LineFile GetCorrectedLine(int line);
void ResetGlobals();
void Recompile();
void PrintGlobalVars();
void PrintAllTypes();
void LogGlobalVars();
void PrintScriptClassVars(asIScriptObject* obj);
void GetGlobalVars(std::list<VarStorage> &storage,std::list<ScriptObjectInstance>& handle_var_list);
void SaveGlobalVars();
void LoadGlobalVars();
void LoadVar(ValueParent var_type, void* parent_ptr, int parent_index, const VarStorage &vs, void *ptr, std::list<ScriptObjectInstance>& handle_var_list, std::list<ScriptObjectInstanceHandleRemap>& app_obj_handle_offset, asIScriptModule* module);
asIScriptFunction* GetFunctionID( const std::string &function_name );
void *GetVarPtr(const char* name);
void *GetVarPtrCache(const char* name); // Only use if passing fixed const char*, not converted from string
int CompileScriptFromText(const std::string &text);
};
const char* AppObjectTypeString(enum AppObjectType aot);
std::string GetTypeIDString(int type_id);
|