Add improvements for native interfaces usage
This commit is contained in:
@@ -212,8 +212,8 @@ Asset::LoadResult JsonAsset::loadAsset()
|
|||||||
case ScriptingTypes::Class:
|
case ScriptingTypes::Class:
|
||||||
{
|
{
|
||||||
// Ensure that object can deserialized
|
// Ensure that object can deserialized
|
||||||
const ScriptingType::InterfaceImplementation* interfaces = type.GetInterface(&ISerializable::TypeInitializer);
|
const ScriptingType::InterfaceImplementation* interface = type.GetInterface(ISerializable::TypeInitializer);
|
||||||
if (!interfaces)
|
if (!interface)
|
||||||
{
|
{
|
||||||
LOG(Warning, "Cannot deserialize {0} from Json Asset because it doesn't implement ISerializable interface.", type.ToString());
|
LOG(Warning, "Cannot deserialize {0} from Json Asset because it doesn't implement ISerializable interface.", type.ToString());
|
||||||
break;
|
break;
|
||||||
@@ -231,7 +231,7 @@ Asset::LoadResult JsonAsset::loadAsset()
|
|||||||
// Deserialize object
|
// Deserialize object
|
||||||
auto modifier = Cache::ISerializeModifier.Get();
|
auto modifier = Cache::ISerializeModifier.Get();
|
||||||
modifier->EngineBuild = DataEngineBuild;
|
modifier->EngineBuild = DataEngineBuild;
|
||||||
((ISerializable*)((byte*)instance + interfaces->VTableOffset))->Deserialize(*Data, modifier.Value);
|
((ISerializable*)((byte*)instance + interface->VTableOffset))->Deserialize(*Data, modifier.Value);
|
||||||
// TODO: delete object when containing BinaryModule gets unloaded
|
// TODO: delete object when containing BinaryModule gets unloaded
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -309,14 +309,14 @@ ScriptingObject* ScriptingType::GetDefaultInstance() const
|
|||||||
return Script.DefaultInstance;
|
return Script.DefaultInstance;
|
||||||
}
|
}
|
||||||
|
|
||||||
const ScriptingType::InterfaceImplementation* ScriptingType::GetInterface(const ScriptingTypeInitializer* interfaceType) const
|
const ScriptingType::InterfaceImplementation* ScriptingType::GetInterface(const ScriptingTypeHandle& interfaceType) const
|
||||||
{
|
{
|
||||||
const InterfaceImplementation* interfaces = Interfaces;
|
const InterfaceImplementation* interfaces = Interfaces;
|
||||||
if (interfaces)
|
if (interfaces)
|
||||||
{
|
{
|
||||||
while (interfaces->InterfaceType)
|
while (interfaces->InterfaceType)
|
||||||
{
|
{
|
||||||
if (interfaces->InterfaceType == interfaceType)
|
if (*interfaces->InterfaceType == interfaceType)
|
||||||
return interfaces;
|
return interfaces;
|
||||||
interfaces++;
|
interfaces++;
|
||||||
}
|
}
|
||||||
@@ -639,8 +639,6 @@ void ManagedBinaryModule::OnLoaded(MAssembly* assembly)
|
|||||||
for (int32 typeIndex = 0; typeIndex < Types.Count(); typeIndex++)
|
for (int32 typeIndex = 0; typeIndex < Types.Count(); typeIndex++)
|
||||||
{
|
{
|
||||||
ScriptingType& type = Types[typeIndex];
|
ScriptingType& type = Types[typeIndex];
|
||||||
if (type.Type == ScriptingTypes::Interface)
|
|
||||||
continue; // TODO: generate C# class for interfaces in API
|
|
||||||
ASSERT(type.ManagedClass == nullptr);
|
ASSERT(type.ManagedClass == nullptr);
|
||||||
|
|
||||||
// Cache class
|
// Cache class
|
||||||
|
|||||||
@@ -121,7 +121,7 @@ struct FLAXENGINE_API ScriptingType
|
|||||||
struct InterfaceImplementation
|
struct InterfaceImplementation
|
||||||
{
|
{
|
||||||
// Pointer to the type of the implemented interface.
|
// Pointer to the type of the implemented interface.
|
||||||
const ScriptingTypeInitializer* InterfaceType;
|
const ScriptingTypeHandle* InterfaceType;
|
||||||
|
|
||||||
// The offset (in bytes) from the object pointer to the interface implementation. Used for casting object to the interface.
|
// The offset (in bytes) from the object pointer to the interface implementation. Used for casting object to the interface.
|
||||||
int16 VTableOffset;
|
int16 VTableOffset;
|
||||||
@@ -290,7 +290,7 @@ struct FLAXENGINE_API ScriptingType
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the pointer to the implementation of the given interface type for this scripting type (including base types). Returns null if given interface is not implemented.
|
/// Gets the pointer to the implementation of the given interface type for this scripting type (including base types). Returns null if given interface is not implemented.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
const InterfaceImplementation* GetInterface(const ScriptingTypeInitializer* interfaceType) const;
|
const InterfaceImplementation* GetInterface(const ScriptingTypeHandle& interfaceType) const;
|
||||||
|
|
||||||
String ToString() const;
|
String ToString() const;
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user