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

Method OnLoaded

Source/Engine/Scripting/BinaryModule.cpp:906–998  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

904}
905
906void ManagedBinaryModule::OnLoaded(MAssembly* assembly)
907{
908#if !COMPILE_WITHOUT_CSHARP
909 PROFILE_CPU();
910 PROFILE_MEM(ScriptingCSharp);
911 ASSERT(ClassToTypeIndex.IsEmpty());
912 ScopeLock lock(Locker);
913
914 const auto& classes = assembly->GetClasses();
915
916 // Cache managed types information
917 ClassToTypeIndex.EnsureCapacity(Types.Count());
918 for (int32 typeIndex = 0; typeIndex < Types.Count(); typeIndex++)
919 {
920 ScriptingType& type = Types[typeIndex];
921 ASSERT(type.ManagedClass == nullptr);
922
923 // Cache class
924 const StringAnsi typeName(type.Fullname.Get(), type.Fullname.Length());
925 classes.TryGet(typeName, type.ManagedClass);
926 if (type.ManagedClass == nullptr)
927 {
928 LOG(Error, "Missing class {0} from assembly {1}.", type.ToString(), assembly->ToString());
929 continue;
930 }
931
932 // Cache klass -> type index lookup
933 MClass* klass = type.ManagedClass;
934#if !BUILD_RELEASE
935 if (ClassToTypeIndex.ContainsKey(klass))
936 {
937 LOG(Error, "Duplicated native types for class {0} from assembly {1}.", type.ToString(), assembly->ToString());
938 continue;
939 }
940#endif
941 ClassToTypeIndex[klass] = typeIndex;
942 }
943
944 // Cache types for managed-only types that can be used in the engine
945 _firstManagedTypeIndex = Types.Count();
946 NativeBinaryModule* flaxEngine = (NativeBinaryModule*)GetBinaryModuleFlaxEngine();
947 if (flaxEngine->Assembly->IsLoaded())
948 {
949 // TODO: check only assemblies that references FlaxEngine.CSharp.dll
950 MClass* scriptingObjectType = this == flaxEngine ? classes["FlaxEngine.Object"] : ScriptingObject::GetStaticClass();
951 for (auto i = classes.Begin(); i.IsNotEnd(); ++i)
952 {
953 MClass* mclass = i->Value;
954
955 // Check if C# class inherits from C++ object class it has no C++ representation
956 if (mclass->IsStatic() ||
957 mclass->IsInterface() ||
958 !mclass->IsSubClassOf(scriptingObjectType)
959 )
960 {
961 continue;
962 }
963

Callers

nothing calls this directly

Calls 15

IsStaticMethod · 0.80
StringFunction · 0.50
IsEmptyMethod · 0.45
EnsureCapacityMethod · 0.45
CountMethod · 0.45
GetMethod · 0.45
LengthMethod · 0.45
TryGetMethod · 0.45
ToStringMethod · 0.45
ContainsKeyMethod · 0.45
IsLoadedMethod · 0.45
BeginMethod · 0.45

Tested by

no test coverage detected