MCPcopy Create free account
hub / github.com/FlaxEngine/FlaxEngine / CacheScriptingType

Method CacheScriptingType

Source/Engine/Content/Assets/VisualScript.cpp:1595–1698  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1593}
1594
1595void VisualScript::CacheScriptingType()
1596{
1597 PROFILE_MEM(ScriptingVisual);
1598 ScopeLock lock(VisualScriptingBinaryModule::Locker);
1599 auto& binaryModule = VisualScriptingModule;
1600
1601 // Find base type
1602 const StringAnsi baseTypename(Meta.BaseTypename);
1603 const ScriptingTypeHandle baseType = Scripting::FindScriptingType(baseTypename);
1604 if (baseType)
1605 {
1606 // Find first native base C++ class of this Visual Script class
1607 ScriptingTypeHandle nativeType = baseType;
1608 while (nativeType && nativeType.GetType().Script.ScriptVTable)
1609 {
1610 nativeType = nativeType.GetType().GetBaseType();
1611 }
1612 if (!nativeType)
1613 {
1614 LOG(Error, "Missing native base class for {0}", ToString());
1615 return;
1616 }
1617
1618 // Create scripting type
1619 if (_scriptingTypeHandleCached)
1620 {
1621 // Reuse cached slot (already created objects with that type handle can use the new type info eg. after asset reload when editing script in editor)
1622 ASSERT(_scriptingTypeHandleCached.GetType().Fullname == _typename);
1623 _scriptingTypeHandle = _scriptingTypeHandleCached;
1624 _scriptingTypeHandleCached = ScriptingTypeHandle();
1625 auto& type = VisualScriptingModule.Types[_scriptingTypeHandle.TypeIndex];
1626 type.~ScriptingType();
1627 new(&type)ScriptingType(_typename, &binaryModule, baseType.GetType().Size, ScriptingType::DefaultInitRuntime, VisualScriptingBinaryModule::VisualScriptObjectSpawn, baseType);
1628 binaryModule.Scripts[_scriptingTypeHandle.TypeIndex] = this;
1629 }
1630 else
1631 {
1632 // Allocate new slot
1633 const int32 typeIndex = binaryModule.Types.Count();
1634 binaryModule.Types.AddUninitialized();
1635 new(binaryModule.Types.Get() + binaryModule.Types.Count() - 1)ScriptingType(_typename, &binaryModule, baseType.GetType().Size, ScriptingType::DefaultInitRuntime, VisualScriptingBinaryModule::VisualScriptObjectSpawn, baseType);
1636 binaryModule.TypeNameToTypeIndex[_typename] = typeIndex;
1637 _scriptingTypeHandle = ScriptingTypeHandle(&binaryModule, typeIndex);
1638 binaryModule.Scripts.Add(this);
1639
1640 // Special initialization when the first Visual Script gets loaded
1641 if (typeIndex == 0)
1642 {
1643#if USE_EDITOR
1644 // Register for other modules unload to clear runtime execution cache
1645 Scripting::ScriptsReloading.Bind<VisualScriptingBinaryModule, &VisualScriptingBinaryModule::OnScriptsReloading>(&binaryModule);
1646#endif
1647
1648 // Register for scripting events
1649 ScriptingEvents::Event.Bind(VisualScriptingBinaryModule::OnEvent);
1650 }
1651 }
1652 auto& type = _scriptingTypeHandle.Module->Types[_scriptingTypeHandle.TypeIndex];

Callers

nothing calls this directly

Calls 15

FindScriptingTypeFunction · 0.85
~ScriptingTypeMethod · 0.80
AddUninitializedMethod · 0.80
SetupScriptVTableMethod · 0.80
ToStringFunction · 0.50
ScriptingTypeHandleClass · 0.50
FindMethodFunction · 0.50
ParseFunction · 0.50
GetTypeMethod · 0.45
CountMethod · 0.45
GetMethod · 0.45
AddMethod · 0.45

Tested by

no test coverage detected