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

Method InitType

Source/Engine/Scripting/BinaryModule.cpp:1000–1149  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

998}
999
1000void ManagedBinaryModule::InitType(MClass* mclass)
1001{
1002#if !COMPILE_WITHOUT_CSHARP
1003 // Skip if already initialized
1004 const StringAnsiView typeName = mclass->GetFullName();
1005 if (TypeNameToTypeIndex.ContainsKey(typeName))
1006 return;
1007 PROFILE_MEM(ScriptingCSharp);
1008
1009 // Find first native base C++ class of this C# class
1010 MClass* baseClass = mclass->GetBaseClass();
1011 ScriptingTypeHandle baseType;
1012 baseType.Module = FindModule(baseClass);
1013 if (!baseClass)
1014 {
1015 LOG(Error, "Missing base class for managed class {0} from assembly {1}.", String(typeName), Assembly->ToString());
1016 return;
1017 }
1018 if (baseType.Module == this)
1019 InitType(baseClass); // Ensure base is initialized before
1020
1021 baseType.Module->TypeNameToTypeIndex.TryGet(baseClass->GetFullName(), *(int32*)&baseType.TypeIndex);
1022
1023 // So we must special case this flow of a generic class of which its possible the generic base class is not in the same module
1024 if (baseType.TypeIndex == -1 && baseClass->IsGeneric())
1025 {
1026 auto genericNameIndex = baseClass->GetFullName().FindLast('`');
1027 // we add 2 because of the way generic names work its `N
1028 auto genericClassName = baseClass->GetFullName().Substring(0, genericNameIndex + 2);
1029
1030 // We check for the generic class name instead of the baseclass fullname
1031 baseType.Module->TypeNameToTypeIndex.TryGet(genericClassName, *(int32*)&baseType.TypeIndex);
1032 }
1033
1034 if (baseType.TypeIndex == -1 || baseType.Module == nullptr)
1035 {
1036 if (baseType.Module)
1037 {
1038 LOG(Error, "Missing base class for managed class {0} from assembly {1}.", String(baseClass->GetFullName()), baseType.Module->GetName().ToString());
1039 }
1040 else
1041 {
1042 LOG(Error, "Missing base class for managed class {0} from unknown assembly.", String(baseClass->GetFullName()));
1043 }
1044 return;
1045 }
1046
1047 ScriptingTypeHandle nativeType = baseType;
1048 while (true)
1049 {
1050 auto& type = nativeType.GetType();
1051 if (type.Script.Spawn != &ManagedObjectSpawn)
1052 break;
1053 nativeType = type.GetBaseType();
1054 if (!nativeType)
1055 {
1056 LOG(Error, "Missing base class for managed class {0} from assembly {1}.", String(typeName), Assembly->ToString());
1057 return;

Callers

nothing calls this directly

Calls 15

MemoryClearFunction · 0.85
SubstringMethod · 0.80
AddUninitializedMethod · 0.80
SetupScriptVTableMethod · 0.80
FindMethodFunction · 0.70
StringFunction · 0.50
ContainsKeyMethod · 0.45
GetBaseClassMethod · 0.45
ToStringMethod · 0.45
TryGetMethod · 0.45
FindLastMethod · 0.45
GetNameMethod · 0.45

Tested by

no test coverage detected