Add ScriptingObjectReference for Read/WriteStream and scripting interop as an array
This commit is contained in:
@@ -257,6 +257,38 @@ struct MConverter<T, typename TEnableIf<TIsBaseOf<class ScriptingObject, T>::Val
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Converter for ScriptingObject References.
|
||||||
|
template<typename T>
|
||||||
|
class ScriptingObjectReference;
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
struct MConverter<ScriptingObjectReference<T>>
|
||||||
|
{
|
||||||
|
MonoObject* Box(const ScriptingObjectReference<T>& data, MonoClass* klass)
|
||||||
|
{
|
||||||
|
return data.GetManagedInstance();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Unbox(ScriptingObjectReference<T>& result, MonoObject* data)
|
||||||
|
{
|
||||||
|
result = (T*)ScriptingObject::ToNative(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ToManagedArray(MonoArray* result, const Span<ScriptingObjectReference<T>>& data)
|
||||||
|
{
|
||||||
|
for (int32 i = 0; i < data.Length(); i++)
|
||||||
|
mono_array_setref(result, i, data[i].GetManagedInstance());
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename AllocationType = HeapAllocation>
|
||||||
|
void ToNativeArray(Array<ScriptingObjectReference<T>, AllocationType>& result, MonoArray* data, int32 length)
|
||||||
|
{
|
||||||
|
result.Resize(length);
|
||||||
|
for (int32 i = 0; i < length; i++)
|
||||||
|
result[i] = (T*)ScriptingObject::ToNative(mono_array_get(data, MonoObject*, i));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
// Converter for Asset References.
|
// Converter for Asset References.
|
||||||
template<typename T>
|
template<typename T>
|
||||||
class AssetReference;
|
class AssetReference;
|
||||||
|
|||||||
@@ -5,10 +5,6 @@
|
|||||||
#include "Stream.h"
|
#include "Stream.h"
|
||||||
#include "Engine/Core/Templates.h"
|
#include "Engine/Core/Templates.h"
|
||||||
|
|
||||||
struct CommonValue;
|
|
||||||
struct Variant;
|
|
||||||
struct VariantType;
|
|
||||||
class ISerializable;
|
|
||||||
extern FLAXENGINE_API class ScriptingObject* FindObject(const Guid& id, class MClass* type);
|
extern FLAXENGINE_API class ScriptingObject* FindObject(const Guid& id, class MClass* type);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -156,6 +152,14 @@ public:
|
|||||||
data = (T*)::FindObject(*(Guid*)id, T::GetStaticClass());
|
data = (T*)::FindObject(*(Guid*)id, T::GetStaticClass());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
FORCE_INLINE void Read(ScriptingObjectReference<T>& v)
|
||||||
|
{
|
||||||
|
T* ptr;
|
||||||
|
Read(ptr);
|
||||||
|
v = ptr;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Read data array
|
/// Read data array
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -8,9 +8,15 @@
|
|||||||
#define FILESTREAM_BUFFER_SIZE 4096
|
#define FILESTREAM_BUFFER_SIZE 4096
|
||||||
#define STREAM_MAX_STRING_LENGTH (4*1024) // 4 kB
|
#define STREAM_MAX_STRING_LENGTH (4*1024) // 4 kB
|
||||||
|
|
||||||
// Forward declarations
|
|
||||||
class ReadStream;
|
class ReadStream;
|
||||||
class WriteStream;
|
class WriteStream;
|
||||||
|
struct CommonValue;
|
||||||
|
struct Variant;
|
||||||
|
struct VariantType;
|
||||||
|
class ISerializable;
|
||||||
|
class ScriptingObject;
|
||||||
|
template<typename T>
|
||||||
|
class ScriptingObjectReference;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Base class for all data streams (memory streams, file streams etc.)
|
/// Base class for all data streams (memory streams, file streams etc.)
|
||||||
|
|||||||
@@ -5,12 +5,6 @@
|
|||||||
#include "Stream.h"
|
#include "Stream.h"
|
||||||
#include "Engine/Core/Templates.h"
|
#include "Engine/Core/Templates.h"
|
||||||
|
|
||||||
struct CommonValue;
|
|
||||||
struct Variant;
|
|
||||||
struct VariantType;
|
|
||||||
class ISerializable;
|
|
||||||
class ScriptingObject;
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Base class for all data write streams
|
/// Base class for all data write streams
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -177,6 +171,12 @@ public:
|
|||||||
WriteBytes(id, sizeof(id));
|
WriteBytes(id, sizeof(id));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
FORCE_INLINE void Write(const ScriptingObjectReference<T>& v)
|
||||||
|
{
|
||||||
|
Write(v.Get());
|
||||||
|
}
|
||||||
|
|
||||||
template<typename T, typename AllocationType = HeapAllocation>
|
template<typename T, typename AllocationType = HeapAllocation>
|
||||||
void Write(const Array<T, AllocationType>& data)
|
void Write(const Array<T, AllocationType>& data)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user