wip 2
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
#include "MyScript.h"
|
||||
|
||||
#include "Engine/Content/Content.h"
|
||||
#include "Engine/Level/Actor.h"
|
||||
#include "Engine/Core/Log.h"
|
||||
#include "Engine/Renderer/RenderList.h"
|
||||
@@ -9,6 +11,7 @@
|
||||
#include "Engine/Scripting/ManagedCLR/MMethod.h"
|
||||
#include "Engine/Level/Scene/Scene.h"
|
||||
#include "Engine/Core/Collections/Sorting.h"
|
||||
#include "Engine/Render2D/FontAsset.h"
|
||||
|
||||
#define NEW_VERSION 1
|
||||
|
||||
@@ -24,6 +27,7 @@
|
||||
#define TIMES3 (100*LONGER)
|
||||
#define TIMES4 (10*LONGER)
|
||||
#define TIMES5 (1*LONGER)
|
||||
#define TIMES_ONCE 1
|
||||
|
||||
MyScript2::MyScript2(const SpawnParams& params)
|
||||
: Script(params)
|
||||
@@ -237,7 +241,31 @@ MyScript::MyScript(const SpawnParams& params)
|
||||
LOG(Info, " - InvokeThunkOnly: {:.1f}ns ({:.0f}ms total {} times)", (results[resultsIndex] * (1.0 / static_cast<double>(freq)) * 1000000000 / chunkTimes), (elapsed2 * (1.0 / static_cast<double>(freq)) * 1000), times*chunkTimes);
|
||||
#define BENCHMARK_THUNK_END() \
|
||||
}
|
||||
|
||||
#define COVERAGE_CALL_ARGS2(FUNC, PARAM1, PARAM2) \
|
||||
{ \
|
||||
LOG(Info, #FUNC); \
|
||||
scriptTwo->FUNC(PARAM1, PARAM2); \
|
||||
}
|
||||
#define COVERAGE_CALL_ARGS3(FUNC, PARAM1, PARAM2, PARAM3) \
|
||||
{ \
|
||||
LOG(Info, #FUNC); \
|
||||
scriptTwo->FUNC(PARAM1, PARAM2, PARAM3); \
|
||||
}
|
||||
#define COVERAGE_CALL_ARGS4(FUNC, PARAM1, PARAM2, PARAM3, PARAM4) \
|
||||
{ \
|
||||
LOG(Info, #FUNC); \
|
||||
scriptTwo->FUNC(PARAM1, PARAM2, PARAM3, PARAM4); \
|
||||
}
|
||||
#define COVERAGE_CALL_ARGS5(FUNC, PARAM1, PARAM2, PARAM3, PARAM4, PARAM5) \
|
||||
{ \
|
||||
LOG(Info, #FUNC); \
|
||||
scriptTwo->FUNC(PARAM1, PARAM2, PARAM3, PARAM4, PARAM5); \
|
||||
}
|
||||
#define COVERAGE_CALL_ARGS6(FUNC, PARAM1, PARAM2, PARAM3, PARAM4, PARAM5, PARAM6) \
|
||||
{ \
|
||||
LOG(Info, #FUNC); \
|
||||
scriptTwo->FUNC(PARAM1, PARAM2, PARAM3, PARAM4, PARAM5, PARAM6); \
|
||||
}
|
||||
|
||||
void MyScript::OnStart()
|
||||
{
|
||||
@@ -246,6 +274,7 @@ void MyScript::OnStart()
|
||||
if (scriptTwo == nullptr)
|
||||
return;
|
||||
|
||||
bool coverageTests = false;
|
||||
bool otherTests = true;
|
||||
bool arrayTests = true;
|
||||
bool asRefTests = true;
|
||||
@@ -266,6 +295,41 @@ void MyScript::OnStart()
|
||||
TestStruct testStruct; testStruct.Object = actor; testStruct.SceneRef = sceneRef;
|
||||
Array<TestStruct> complexArray; for (int i=0; i<10; i++) complexArray.Add(testStruct);
|
||||
|
||||
|
||||
// Coverage
|
||||
if (coverageTests)
|
||||
{
|
||||
int32 integer = 1;
|
||||
bool boolean = true;
|
||||
Float3 f3(1.0f, 2.0f, 3.0f);
|
||||
Guid fontAssetGuid; Guid::Parse("ab96b25a49461d9f4f819484cf5c8213", fontAssetGuid);
|
||||
FontAsset* fontAsset = Content::LoadAsync<FontAsset>(fontAssetGuid);
|
||||
NetworkChannelType networkChannelType = NetworkChannelType::Reliable;
|
||||
OnlineLeaderboardSortModes onlineLeaderboardSortModes = OnlineLeaderboardSortModes::Ascending;
|
||||
OnlineLeaderboardValueFormats onlineLeaderboardValueFormats = OnlineLeaderboardValueFormats::Numeric;
|
||||
AssetReference<FontAsset> fontAssetRef(fontAsset);
|
||||
ModelLOD* lod = nullptr;
|
||||
|
||||
Array<int32> ints(&integer, 1);
|
||||
Array<bool> booleans(&boolean, 1);
|
||||
Array<Actor*> actors(&actor, 1);
|
||||
Array<String> strings(&shortString, 1);
|
||||
Array<StringAnsi> ansiStrings(&shortStringAnsi, 1);
|
||||
Array<Float3> float3s(&f3, 1);
|
||||
Array<ModelLOD*> lods(&lod, 1);
|
||||
|
||||
COVERAGE_CALL_ARGS6(CoverageTest1, integer, boolean, actor, shortString, shortStringAnsi, f3);
|
||||
COVERAGE_CALL_ARGS6(CoverageTest1Array, ints, booleans, actors, strings, ansiStrings, float3s);
|
||||
|
||||
COVERAGE_CALL_ARGS5(CoverageTest1ByRef, integer, boolean/*, actor*/, shortString, shortStringAnsi, f3);
|
||||
COVERAGE_CALL_ARGS5(CoverageTest1ArrayByRef, ints, booleans/*, actors*/, strings, ansiStrings, float3s);
|
||||
COVERAGE_CALL_ARGS4(CoverageTest2, fontAssetGuid, fontAssetRef, Array<Guid>(&fontAssetGuid, 1), Array<AssetReference<FontAsset>>(&fontAssetRef, 1));
|
||||
COVERAGE_CALL_ARGS2(CoverageTest3, lod, lods);
|
||||
COVERAGE_CALL_ARGS6(CoverageNamespaces1, networkChannelType, Array<NetworkChannelType>(&networkChannelType, 1), onlineLeaderboardSortModes, Array<OnlineLeaderboardSortModes>(&onlineLeaderboardSortModes, 1), onlineLeaderboardValueFormats, Array<OnlineLeaderboardValueFormats>(&onlineLeaderboardValueFormats, 1));
|
||||
|
||||
scriptTwo->ManagedCoverageTests();
|
||||
}
|
||||
|
||||
#if NEW_VERSION
|
||||
int64 allocationsBefore, deallocationsBefore;
|
||||
scriptTwo->GetStats(allocationsBefore, deallocationsBefore);
|
||||
@@ -313,8 +377,7 @@ void MyScript::OnStart()
|
||||
params[0] = MUtils::Box<StringAnsi>(shortStringAnsi, MCore::TypeCache::String);
|
||||
BENCHMARK_THUNK_CALL_ARGS1();
|
||||
#if NEW_VERSION
|
||||
auto __param0_handle = *(MGCHandle*)¶ms[0];
|
||||
MCore::GCHandle::Free(__param0_handle);
|
||||
MUtils::FreeManaged<StringAnsi>((MObject*)params[0]);
|
||||
#endif
|
||||
BENCHMARK_THUNK_END();
|
||||
}
|
||||
@@ -325,8 +388,7 @@ void MyScript::OnStart()
|
||||
params[0] = MUtils::Box<String>(shortString, MCore::TypeCache::String);
|
||||
BENCHMARK_THUNK_CALL_ARGS1();
|
||||
#if NEW_VERSION
|
||||
auto __param0_handle = *(MGCHandle*)¶ms[0];
|
||||
MCore::GCHandle::Free(__param0_handle);
|
||||
MUtils::FreeManaged<String>((MObject*)params[0]);
|
||||
#endif
|
||||
BENCHMARK_THUNK_END();
|
||||
}
|
||||
@@ -337,8 +399,7 @@ void MyScript::OnStart()
|
||||
params[0] = MUtils::Box<String>(shortString, MCore::TypeCache::String);
|
||||
BENCHMARK_THUNK_CALL_ARGS1();
|
||||
#if NEW_VERSION
|
||||
auto __param0_handle = *(MGCHandle*)¶ms[0];
|
||||
MCore::GCHandle::Free(__param0_handle);
|
||||
MUtils::FreeManaged<String>((MObject*)params[0]);
|
||||
#endif
|
||||
BENCHMARK_THUNK_END();
|
||||
}
|
||||
@@ -349,8 +410,7 @@ void MyScript::OnStart()
|
||||
params[0] = MUtils::Box<String>(shortString, MCore::TypeCache::String);
|
||||
BENCHMARK_THUNK_CALL_ARGS1();
|
||||
#if NEW_VERSION
|
||||
auto __param0_handle = *(MGCHandle*)¶ms[0];
|
||||
MCore::GCHandle::Free(__param0_handle);
|
||||
MUtils::FreeManaged<String>((MObject*)params[0]);
|
||||
#endif
|
||||
BENCHMARK_THUNK_END();
|
||||
}
|
||||
@@ -446,6 +506,7 @@ void MyScript::OnStart()
|
||||
ASSERT(context.Buffers == renderContext.Buffers);
|
||||
ASSERT(context.Task == renderContext.Task);
|
||||
#if NEW_VERSION
|
||||
context = MUtils::Unbox<RenderContext>(*(MObject**)params[0]);
|
||||
MUtils::FreeManaged<RenderContext>((MObject*)__param_context);
|
||||
if (__param_orig_context != __param_context)
|
||||
MUtils::FreeManaged<RenderContext>((MObject*)__param_orig_context);
|
||||
@@ -454,14 +515,14 @@ void MyScript::OnStart()
|
||||
}
|
||||
|
||||
|
||||
if (true || arrayTests)
|
||||
if (arrayTests)
|
||||
{
|
||||
BENCHMARK_CALL_ARGS1(TIMES4, SimpleArrayParam, simpleArray);
|
||||
BENCHMARK_THUNK_BEGIN_ARGS1(TIMES3, SimpleArrayParam);
|
||||
params[0] = MUtils::ToArray(simpleArray, MCore::TypeCache::Int32);
|
||||
BENCHMARK_THUNK_CALL_ARGS1();
|
||||
#if NEW_VERSION
|
||||
//TODO
|
||||
MUtils::FreeManagedArray<int>((MArray*)params[0]);
|
||||
#endif
|
||||
BENCHMARK_THUNK_END();
|
||||
}
|
||||
@@ -485,7 +546,9 @@ void MyScript::OnStart()
|
||||
ASSERT(arr.Count() == simpleArray.Count());
|
||||
for (int i=0; i<arr.Count(); i++) ASSERT(arr[i] == simpleArray[i]);
|
||||
#if NEW_VERSION
|
||||
//TODO
|
||||
MUtils::FreeManagedArray<int>(__param_arr); //fgfgh3
|
||||
if (__param_orig_arr != __param_arr)
|
||||
MUtils::FreeManagedArray<int>(__param_orig_arr); //fgfgh4
|
||||
#endif
|
||||
BENCHMARK_THUNK_END();*/
|
||||
}
|
||||
@@ -498,7 +561,7 @@ void MyScript::OnStart()
|
||||
params[0] = MUtils::ToArray(actorArray, Actor::TypeInitializer.GetClass());
|
||||
BENCHMARK_THUNK_CALL_ARGS1();
|
||||
#if NEW_VERSION
|
||||
//MUtils::FreeManaged<RenderContext>((MObject*)params[0]);
|
||||
MUtils::FreeManagedArray<Actor*>((MArray*)params[0]);
|
||||
#endif
|
||||
BENCHMARK_THUNK_END();
|
||||
}
|
||||
@@ -510,7 +573,7 @@ void MyScript::OnStart()
|
||||
params[0] = MUtils::ToArray(complexArray, TestStruct::TypeInitializer.GetClass());
|
||||
BENCHMARK_THUNK_CALL_ARGS1();
|
||||
#if NEW_VERSION
|
||||
//MUtils::FreeManaged<RenderContext>((MObject*)params[0]);
|
||||
MUtils::FreeManagedArray<TestStruct>((MArray*)params[0]);
|
||||
#endif
|
||||
BENCHMARK_THUNK_END();
|
||||
}
|
||||
@@ -535,7 +598,9 @@ void MyScript::OnStart()
|
||||
ASSERT(arr.Count() == complexArray.Count());
|
||||
for (int i = 0; i < arr.Count(); i++) ASSERT(arr[i] == complexArray[i]);
|
||||
#if NEW_VERSION
|
||||
//MUtils::FreeManaged<RenderContext>((MObject*)params[0]);
|
||||
MUtils::FreeManagedArray<TestStruct>(__param_arr);
|
||||
if (__param_orig_arr != __param_arr)
|
||||
MUtils::FreeManagedArray<TestStruct>(__param_orig_arr);
|
||||
#endif
|
||||
BENCHMARK_THUNK_END();*/
|
||||
}
|
||||
@@ -543,7 +608,10 @@ void MyScript::OnStart()
|
||||
#if NEW_VERSION
|
||||
int64 allocationsAfter, deallocationsAfter;
|
||||
scriptTwo->GetStats(allocationsAfter, deallocationsAfter);
|
||||
LOG(Info, "Total ManagedHandle allocations: {}, deallocations: {}", allocationsAfter-allocationsBefore, deallocationsAfter-deallocationsBefore);
|
||||
int64 allocationsDiff = allocationsAfter-allocationsBefore;
|
||||
int64 deallocationsDiff = deallocationsAfter-deallocationsBefore;
|
||||
int64 leftover = allocationsDiff - deallocationsDiff;
|
||||
LOG(Info, "Total ManagedHandle allocations: {}, deallocations: {}, leftover: {}", allocationsDiff, deallocationsDiff, leftover);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@@ -9,6 +9,10 @@
|
||||
#include "Engine/Graphics/Graphics.h"
|
||||
#include "Engine/Scripting/SoftTypeReference.h"
|
||||
#include "Engine/Content/SceneReference.h"
|
||||
#include "Engine/Content/Assets/Model.h"
|
||||
#include "Engine/Networking/NetworkChannelType.h"
|
||||
#include "Engine/Online/IOnlinePlatform.h"
|
||||
#include "Engine/Render2D/FontAsset.h"
|
||||
|
||||
API_STRUCT(NoDefault) struct TestStruct : public ISerializable
|
||||
{
|
||||
@@ -40,6 +44,16 @@ API_CLASS() class GAME_API MyScript2 : public Script
|
||||
|
||||
API_FUNCTION() virtual void GetStats(API_PARAM(Ref) int64& allocations, API_PARAM(Ref) int64& deallocations) {};
|
||||
|
||||
API_FUNCTION() virtual void ManagedCoverageTests() {};
|
||||
API_FUNCTION() virtual void CoverageTest1(int32 a, bool b, Actor* c, String& d, StringAnsi& e, Float3 f) {};
|
||||
API_FUNCTION() virtual void CoverageTest1Array(Array<int32> a, Array<bool> b, Array<Actor*> c, Array<String> d, Array<StringAnsi> e, Array<Float3> f) {};
|
||||
API_FUNCTION() virtual void CoverageTest1ByRef(API_PARAM(Ref) int32& a, API_PARAM(Ref) bool& b, API_PARAM(Ref) String& d, API_PARAM(Ref) StringAnsi& e, API_PARAM(Ref) Float3& f) {};
|
||||
API_FUNCTION() virtual void CoverageTest1ArrayByRef(API_PARAM(Ref) Array<int32>& a, API_PARAM(Ref) Array<bool>& b, API_PARAM(Ref) Array<String>& d, API_PARAM(Ref) Array<StringAnsi>& e, API_PARAM(Ref) Array<Float3>& f) {};
|
||||
API_FUNCTION() virtual void CoverageTest2(Guid a, AssetReference<FontAsset> b, Array<Guid> c, Array<AssetReference<FontAsset>> d) {};
|
||||
API_FUNCTION() virtual void CoverageTest3(ModelLOD* a, API_PARAM(Out) Array<ModelLOD*>& b) {};
|
||||
|
||||
API_FUNCTION() virtual void CoverageNamespaces1(NetworkChannelType a, Array<NetworkChannelType> b, OnlineLeaderboardSortModes c, Array<OnlineLeaderboardSortModes> d, OnlineLeaderboardValueFormats e, Array<OnlineLeaderboardValueFormats> f) {};
|
||||
|
||||
API_FUNCTION() virtual void SimpleCall() {};
|
||||
API_FUNCTION() virtual void SimpleParams(int32 a, float b, char c, double d, int64 e) {};
|
||||
API_FUNCTION() virtual void StringParamAnsi(StringAnsi str) {};
|
||||
@@ -59,7 +73,9 @@ API_CLASS() class GAME_API MyScript2 : public Script
|
||||
API_FUNCTION() virtual void ActorArrayParam(Array<Actor*> arr) {};
|
||||
API_FUNCTION() virtual void ActorArrayParamRef(Array<Actor*>& arr) {};
|
||||
API_FUNCTION() virtual void ActorArrayParamRefConst(const Array<Actor*>& arr) {};
|
||||
|
||||
//API_FUNCTION() virtual void ActorArrayParamAsRef(API_PARAM(Ref) Array<Actor*>& arr) {};
|
||||
|
||||
API_FUNCTION() virtual void ComplexArrayParam(Array<TestStruct> arr) {};
|
||||
API_FUNCTION() virtual void ComplexArrayParamRef(Array<TestStruct>& arr) {};
|
||||
API_FUNCTION() virtual void ComplexArrayParamRefConst(const Array<TestStruct>& arr) {};
|
||||
@@ -89,7 +105,14 @@ DECLARE_SCRIPTING_TYPE(MyScript);
|
||||
void OnDisable() override;
|
||||
void OnUpdate() override;
|
||||
|
||||
|
||||
API_FUNCTION() virtual void ManagedCoverageTests() {};
|
||||
API_FUNCTION() virtual void CoverageTest1(int32 a, bool b, Actor* c, String& d, StringAnsi& e, Float3 f) {};
|
||||
API_FUNCTION() virtual void CoverageTest1Array(Array<int32> a, Array<bool> b, Array<Actor*> c, Array<String> d, Array<StringAnsi> e, Array<Float3> f) {};
|
||||
API_FUNCTION() virtual void CoverageTest1ByRef(API_PARAM(Ref) int32& a, API_PARAM(Ref) bool& b, API_PARAM(Ref) String& d, API_PARAM(Ref) StringAnsi& e, API_PARAM(Ref) Float3& f) {};
|
||||
API_FUNCTION() virtual void CoverageTest1ArrayByRef(API_PARAM(Ref) Array<int32>& a, API_PARAM(Ref) Array<bool>& b, API_PARAM(Ref) Array<String>& d, API_PARAM(Ref) Array<StringAnsi>& e, API_PARAM(Ref) Array<Float3>& f) {};
|
||||
API_FUNCTION() virtual void CoverageTest2(Guid a, AssetReference<FontAsset> b, Array<Guid> c, Array<AssetReference<FontAsset>> d) {};
|
||||
API_FUNCTION() virtual void CoverageNamespaces1(NetworkChannelType a, Array<NetworkChannelType> b, OnlineLeaderboardSortModes c, Array<OnlineLeaderboardSortModes> d, OnlineLeaderboardValueFormats e, Array<OnlineLeaderboardValueFormats> f) {};
|
||||
|
||||
|
||||
//API_FUNCTION() void Test1(API_PARAM(REF) Array<TestTypeEnum>& eenums) {};
|
||||
//API_FUNCTION() BezierCurve<Transform>.Keyframe Test2(BezierCurve<Transform> kef) {};
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
using System.Collections.Generic;
|
||||
using FlaxEngine;
|
||||
using FlaxEngine.Interop;
|
||||
using FlaxEngine.Networking;
|
||||
using FlaxEngine.Online;
|
||||
|
||||
namespace Game;
|
||||
|
||||
@@ -35,10 +37,45 @@ public class MyScriptTwo : MyScript2
|
||||
|
||||
public override void GetStats(ref long allocations, ref long deallocations)
|
||||
{
|
||||
//allocations = ManagedHandle.Allocations;
|
||||
//deallocations = ManagedHandle.Deallocations;
|
||||
allocations = ManagedHandle.Allocations;
|
||||
deallocations = ManagedHandle.Deallocations;
|
||||
}
|
||||
|
||||
public override void ManagedCoverageTests()
|
||||
{
|
||||
Debug.LogWarning("ManagedCoverageTests");
|
||||
Actor actor = this.Actor;
|
||||
MyScript script = actor.GetScript<MyScript>();
|
||||
|
||||
string shortString = "Testing string parameter marshalling";
|
||||
Float3 f3 = new Float3(1, 2, 3);
|
||||
|
||||
|
||||
if (true)
|
||||
{
|
||||
int[] ints = { 1 };
|
||||
bool[] booleans = { true };
|
||||
Actor[] actors = { actor };
|
||||
string[] strings = { shortString };
|
||||
Float3[] float3s = { f3 };
|
||||
|
||||
script.CoverageTest1(1, true, actor, shortString, shortString, f3);
|
||||
script.CoverageTest1Array(ints, booleans, actors, strings, strings, float3s);
|
||||
script.CoverageTest1ByRef(ref ints[0], ref booleans[0]/*, ref actors[0]*/, ref strings[0], ref strings[0], ref float3s[0]);
|
||||
script.CoverageTest1ArrayByRef(ref ints, ref booleans/*, ref actors*/, ref strings, ref strings, ref float3s);
|
||||
//script.CoverageTest2(fontAssetGuid, fontAssetRef, Array<Guid>(&fontAssetGuid, 1), Array<AssetReference<FontAsset>>(&fontAssetRef, 1));
|
||||
//script.CoverageNamespaces1(networkChannelType, Array<NetworkChannelType>(&networkChannelType, 1), onlineLeaderboardSortModes, Array<OnlineLeaderboardSortModes>(&onlineLeaderboardSortModes, 1), onlineLeaderboardValueFormats, Array<OnlineLeaderboardValueFormats>(&onlineLeaderboardValueFormats, 1));
|
||||
}
|
||||
}
|
||||
|
||||
public override void CoverageTest1(int a, bool b, Actor c, String d, String e, Float3 f) {}
|
||||
public override void CoverageTest1Array(int[] a, bool[] b, Actor[] c, String[] d, String[] e, Float3[] f) {}
|
||||
public override void CoverageTest1ByRef(ref int a, ref bool b/*, ref Actor c*/, ref String d, ref String e, ref Float3 f) {}
|
||||
public override void CoverageTest1ArrayByRef(ref int[] a, ref bool[] b/*, ref Actor[] c*/, ref String[] d, ref String[] e, ref Float3[] f) {}
|
||||
public override void CoverageTest2(Guid a, FontAsset b, Guid[] c, FontAsset[] d) {}
|
||||
public override void CoverageTest3(ModelLOD a, out ModelLOD[] b) { b = null; }
|
||||
public override void CoverageNamespaces1(NetworkChannelType a, NetworkChannelType[] b, OnlineLeaderboardSortModes c, OnlineLeaderboardSortModes[] d, OnlineLeaderboardValueFormats e, OnlineLeaderboardValueFormats[] f) {}
|
||||
|
||||
public override void SimpleCall() {}
|
||||
public override void SimpleParams(int a, float b, sbyte c, double d, long e) {}
|
||||
public override void StringParamAnsi(string str) {}
|
||||
|
||||
Reference in New Issue
Block a user