6 Commits

Author SHA1 Message Date
856be55132 prog 2026-01-05 15:02:44 +02:00
8561d28642 invoke cleanup 2025-12-22 17:26:13 +02:00
3cfb7d319b wip 2 2025-12-21 17:46:25 +02:00
d1c73d6c74 _benchmode 2025-12-18 15:08:06 +02:00
e4cd76fdaf alloc tracking 2025-12-18 14:09:39 +02:00
43e1acacce interop tests 2025-12-09 21:57:25 +02:00
8 changed files with 1660 additions and 2 deletions

View File

@@ -0,0 +1,34 @@
{
"ID": "2a86c77242441f5ac25b4a8bbf4029a8",
"TypeName": "FlaxEngine.SceneAsset",
"EngineBuild": 6805,
"Data": [
{
"ID": "2a86c77242441f5ac25b4a8bbf4029a8",
"TypeName": "FlaxEngine.Scene",
"LightmapSettings": {
"IndirectLightingIntensity": 1.0,
"GlobalObjectsScale": 1.0,
"ChartsPadding": 3,
"AtlasSize": 1024,
"BounceCount": 1,
"CompressLightmaps": true,
"UseGeometryWithNoMaterials": true,
"Quality": 10
}
},
{
"ID": "5b51518c45ce815817a6f1978fec4699",
"TypeName": "Game.MyScript",
"ParentID": "2a86c77242441f5ac25b4a8bbf4029a8"
},
{
"ID": "efa3263d4596af098d5babb8fd6ea6fb",
"TypeName": "Game.MyScriptTwo",
"ParentID": "2a86c77242441f5ac25b4a8bbf4029a8",
"V": {
"Model": "50310067422bada39f9553b41c4869a4"
}
}
]
}

View File

@@ -3,6 +3,8 @@ using FlaxEngine;
using Console = Game.Console;
using System.Linq;
using System.Threading;
using FlaxEngine.Json;
#if FLAX_EDITOR
using FlaxEditor;
@@ -137,6 +139,9 @@ public class ConsoleEditorPlugin : EditorPlugin
private void OnPlayModeBegin()
{
if (!Level.Scenes.Any(x => x.ID == JsonSerializer.ParseID("194e05f445ece24ec5448d886e1334df"))) // MainScene
return;
//FlaxEditor.Editor.Instance.PlayModeBegin -= Instance_PlayModeBegin;
LoadConfig();
//GameMode.Connect();

View File

@@ -27,7 +27,13 @@ public class Game : GameModule
public override void Setup(BuildOptions options)
{
options.ScriptingAPI.IgnoreMissingDocumentationWarnings = true;
//options.CompileEnv.PreprocessorDefinitions.Add("COMPILE_WITH_CSG_BUILDER");
options.ScriptingAPI.IgnoreSpecificWarnings.Add("CS9191"); // ref with in parameters
options.ScriptingAPI.IgnoreSpecificWarnings.Add("CS1717"); // assignment with itself
options.ScriptingAPI.IgnoreSpecificWarnings.Add("CS0219"); // assignment unused
options.ScriptingAPI.IgnoreSpecificWarnings.Add("CS0414"); // assignment unused
options.ScriptingAPI.IgnoreSpecificWarnings.Add("CS0649"); // default value assignment
options.CompileEnv.PreprocessorDefinitions.Add("COMPILE_WITH_CSG_BUILDER");
//options.PublicDefinitions.Add("COMPILE_WITH_CSG_BUILDER");
base.Setup(options);
@@ -35,6 +41,8 @@ public class Game : GameModule
//Tags["Network"] = string.Empty;
//options.PublicDependencies.Add("Networking");
//options.PublicDependencies.Add("FidelityFXFSR");
//options.ScriptingAPI.FileReferences.Add(Path.Combine(Globals.EngineRoot, "Source", "Platforms", "DotNet", "Newtonsoft.Json.dll"));
@@ -50,7 +58,7 @@ public class Game : GameModule
options.ScriptingAPI.Defines.Add("COMPILE_WITH_FSR1");
#endif
options.PublicDependencies.Add("OnlinePlatformSteam");
//options.PublicDependencies.Add("OnlinePlatformSteam");
// Here you can modify the build options for your game module
// To reference another module use: options.PublicDependencies.Add("Audio");
// To add C++ define use: options.PublicDefinitions.Add("COMPILE_WITH_FLAX");

948
Source/Game/MyScript.cpp Normal file
View File

@@ -0,0 +1,948 @@
#include "MyScript.h"
#include "Engine/Content/Content.h"
#include "Engine/Level/Actor.h"
#include "Engine/Core/Log.h"
#include "Engine/Renderer/RenderList.h"
#include "Engine/Scripting/ManagedCLR/MUtils.h"
#include "Engine/Scripting/ManagedCLR/MCore.h"
#include "Engine/Scripting/ManagedCLR/MClass.h"
#include "Engine/Scripting/ManagedCLR/MEvent.h"
#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 0
#define TRACK_GCHANDLE_ALLOCS 1
#if NEW_VERSION
#define TRACK_GCHANDLE_ALLOCS 1
#endif
#if BUILD_DEBUG
#define LONGER 3
#define CHUNK_TIMES 100
#else
#define LONGER 10//*10
#define CHUNK_TIMES 1000
#endif
#define TIMES (10000*LONGER)
#define TIMES2 (1000*LONGER)
#define TIMES3 (100*LONGER)
#define TIMES4 (10*LONGER)
#define TIMES5 (1*LONGER)
#define TIMES_ONCE 1
MyScript2::MyScript2(const SpawnParams& params)
: Script(params)
{
// _tickUpdate = true;
}
MyScript::MyScript(const SpawnParams& params)
: Script(params)
{
// _tickUpdate = true;
}
double t95(int n) { return 1.96 + 2.4 / (n - 1.0); }
template<typename... TArgs>
void MyScript::BenchmarkCall(BenchmarkContext& context, void(MyScript2::* fun)(TArgs...),
TArgs... args)
{
long totalTimes = 0;
auto chunkTimes = CHUNK_TIMES;
const auto cycleTimes = 1 * LONGER;
const double minTime = 200;
const double maxMaxTime = 5000;
double maxTime = maxMaxTime;
const auto freq = Platform::GetClockFrequency();
context.results.Clear();
uint64 bestResult = UINT64_MAX;
{
auto start0 = Platform::GetTimeCycles();
for (int i = 0; i < 10; ++i)
(*context.scriptTwo.*fun)(args...);
auto end0 = Platform::GetTimeCycles();
auto elapsed0 = end0 - start0;
auto elapsed0ns = (elapsed0 * (1.0 / static_cast<double>(freq)) * 1000000000);
if (elapsed0 > 100000)
chunkTimes = CHUNK_TIMES / 50;
else if (elapsed0 > 80000)
chunkTimes = CHUNK_TIMES / 40;
else if (elapsed0 > 60000)
chunkTimes = CHUNK_TIMES / 30;
else if (elapsed0 > 30000)
chunkTimes = CHUNK_TIMES / 20;
else if (elapsed0 > 20000)
chunkTimes = CHUNK_TIMES / 10;
else if (elapsed0 > 10000)
chunkTimes = CHUNK_TIMES / 5;
else if (elapsed0 > 5000)
chunkTimes = CHUNK_TIMES / 2;
/*if (chunkTimes != CHUNK_TIMES)
LOG(Info, " - chunk times adjusted to {} (elapsed {})", chunkTimes, elapsed0);
else
LOG(Info, " - elapsed {}", elapsed0);*/
}
auto start1 = Platform::GetTimeCycles();
uint64 totaccum = 0;
while (true)
{
uint64 previousBest = bestResult;
uint64 currentBest = UINT64_MAX;
auto start2 = Platform::GetTimeCycles();
for (int i = 0; i < cycleTimes; ++i)
{
auto start = Platform::GetTimeCycles();
for (int j = 0; j < chunkTimes; ++j)
(*context.scriptTwo.*fun)(args...);
auto end = Platform::GetTimeCycles();
auto elapsed = end - start;
if (elapsed < currentBest)
currentBest = elapsed;
context.results.Add(elapsed);
totaccum += elapsed;
}
auto end2 = Platform::GetTimeCycles();
auto elapsed2 = end2 - start2;
auto elapsed2Ms = (elapsed2 * (1.0 / static_cast<double>(freq)) * 1000);
//Sorting::MergeSort(context.results);
totalTimes += cycleTimes * chunkTimes;
if (currentBest < bestResult)
bestResult = currentBest;
auto elapsed1 = Platform::GetTimeCycles() - start1;
auto elapsedMs = (elapsed1 * (1.0 / static_cast<double>(freq)) * 1000);
if (elapsedMs < minTime)
continue;
if (context.results.Count() > 20)
{
double avg = (double)totaccum / context.results.Count();
//avg = (avg * (1.0 / static_cast<double>(freq)) * 1000000000);
double stdev = 0;
{
auto n = context.results.Count();
double s = 0.0;
for (int i = 0; i < n; ++i) {
//double d = (context.results[i] * (1.0 / static_cast<double>(freq)) * 1000000000);
double d = (double)context.results[i];
d = d - avg;
s += d * d;
}
stdev = sqrt(s / (n - 1));
}
double ci = t95(context.results.Count()) * stdev / sqrt((double)context.results.Count());
double rel = (ci / avg) * 100;
if (rel < 1.0)
break;
}
if (elapsedMs >= maxTime)
break;
}
double avg = (double)totaccum / context.results.Count();
avg = (avg * (1.0 / static_cast<double>(freq)) * 1000000000);
double stdev = 0;
{
auto n = context.results.Count();
double s = 0.0;
for (int i = 0; i < n; ++i) {
double d = (context.results[i] * (1.0 / static_cast<double>(freq)) * 1000000000);
d = d - avg;
s += d * d;
}
stdev = sqrt(s / (n - 1));
}
double ci = t95(context.results.Count()) * stdev / sqrt((double)context.results.Count());
double rel = (ci / avg) * 100;
ci /= chunkTimes;
stdev /= chunkTimes;
avg /= chunkTimes;
auto elapsed1 = Platform::GetTimeCycles() - start1;
const auto bestResultNs = (bestResult * (1.0 / static_cast<double>(freq)) * 1000000000 / chunkTimes);
LOG(Info, " - VirtualCall: {:.1f}ns +-{:.1f}ns, std:{:.1f}ns, {:.1f}%, avg:{:.1f} ({:.0f}ms/{})", bestResultNs, ci, stdev, rel, avg, (elapsed1 * (1.0 / static_cast<double>(freq)) * 1000), totalTimes, ci);
}
void MyScript::OnStart()
{
LOG(Info, "C++ OnStart");
MyScript2* scriptTwo = (MyScript2*)GetActor()->GetScript(1);
if (scriptTwo == nullptr)
return;
bool callTests = true;
bool thunkTests = false;
bool invokeTests = false; // requires manual type conversion
bool coverageTests = false;
bool otherTests = true;
bool arrayTests = true;
bool asRefTests = true;
Array<uint64> results(TIMES);
auto CyclesToSeconds = 1.0 / static_cast<double>(Platform::GetClockFrequency());
LOG(Info, "CyclesToSeconds: {}, freq: {}", CyclesToSeconds, Platform::GetClockFrequency());
String shortString = TEXT("Testing string parameter marshalling");
StringAnsi shortStringAnsi = "Testing string parameter marshalling";
Actor* actor = GetActor();
SceneReference sceneRef; sceneRef.ID = actor->GetScene()->GetID();
BehaviorUpdateContext behaviorUpdateContext = {};
RenderContext renderContext = MainRenderTask::Instance;
renderContext.List = RenderList::GetFromPool();
Array<int> simpleArray; for (int i=0; i<10; i++) simpleArray.Add(i);
Array<Actor*> actorArray; for (int i=0; i<10; i++) actorArray.Add(actor);
TestStruct testStruct; testStruct.Object = actor; testStruct.SceneRef = sceneRef;
Array<TestStruct> complexArray; for (int i=0; i<10; i++) complexArray.Add(testStruct);
StringStruct stringStruct;
Array<StringStruct> stringStructArray; for (int i = 0; i < 10; i++) stringStructArray.Add(stringStruct);
BenchmarkContext benchmarkContext;
benchmarkContext.scriptTwo = scriptTwo;
benchmarkContext.results = results;
// 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);
BytesContainer bytes;
bytes.Append((byte*)&f3, sizeof(Float3));
BytesContainer bytesOut;
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_ARGS2(CoverageTest4, bytes, bytesOut);
COVERAGE_CALL_ARGS6(CoverageNamespaces1, networkChannelType, Array<NetworkChannelType>(&networkChannelType, 1), onlineLeaderboardSortModes, Array<OnlineLeaderboardSortModes>(&onlineLeaderboardSortModes, 1), onlineLeaderboardValueFormats, Array<OnlineLeaderboardValueFormats>(&onlineLeaderboardValueFormats, 1));
scriptTwo->ManagedCoverageTests();
}
// Warmup busy-loop
{
const auto freq = Platform::GetClockFrequency();
auto startt = Platform::GetTimeCycles();
auto elapsedMs = ((Platform::GetTimeCycles() - startt) * (1.0 / static_cast<double>(freq)) * 1000);
while (elapsedMs > 2000)
{
elapsedMs = ((Platform::GetTimeCycles() - startt) * (1.0 / static_cast<double>(freq)) * 1000);
}
}
#if TRACK_GCHANDLE_ALLOCS
int64 allocationsBefore, deallocationsBefore;
scriptTwo->GetStats(allocationsBefore, deallocationsBefore);
#endif
if (otherTests)
{
LOG_TEST(SimpleCall);
if (callTests)
{
BenchmarkCall(benchmarkContext, &MyScript2::SimpleCall);
}
if (thunkTests)
{
BENCHMARK_THUNK_BEGIN_ARGS0(TIMES2, SimpleCall);
BENCHMARK_THUNK_CALL_ARGS0();
BENCHMARK_THUNK_END();
}
//else
// LOG(Info, " - InvokeThunkOnly: skipped");
if (invokeTests)
{
BENCHMARK_INVOKE_ARGS0(TIMES2, SimpleCall);
}
}
if (otherTests)
{
LOG_TEST(SimpleParams);
if (callTests)
{
BenchmarkCall(benchmarkContext, &MyScript2::SimpleParams, (int32)1, (float)2, '3', (double)4, (int64)5);
}
if (thunkTests)
{
BENCHMARK_THUNK_BEGIN_ARGS5(TIMES3, SimpleParams);
params[0] = MUtils::Box<int>(1, MCore::TypeCache::Int32);
params[1] = MUtils::Box<float>(2, MCore::TypeCache::Single);
params[2] = MUtils::Box<char>('3', MCore::TypeCache::SByte);
params[3] = MUtils::Box<double>(4, MCore::TypeCache::Double);
params[4] = MUtils::Box<long>(5, MCore::TypeCache::Int64);
BENCHMARK_THUNK_CALL_ARGS5();
#if NEW_VERSION
auto __param0_handle = *(MGCHandle*)&params[0];
MCore::GCHandle::Free(__param0_handle);
auto __param1_handle = *(MGCHandle*)&params[1];
MCore::GCHandle::Free(__param1_handle);
auto __param2_handle = *(MGCHandle*)&params[2];
MCore::GCHandle::Free(__param2_handle);
auto __param3_handle = *(MGCHandle*)&params[3];
MCore::GCHandle::Free(__param3_handle);
auto __param4_handle = *(MGCHandle*)&params[4];
MCore::GCHandle::Free(__param4_handle);
#endif
BENCHMARK_THUNK_END();
}
//else
// LOG(Info, " - InvokeThunkOnly: skipped");
if (invokeTests)
{
//#if NEW_VERSION
/*BENCHMARK_INVOKE_ARGS5(TIMES3, SimpleParams,
(int32)1,
(float)2,
(char)'3',
(double)4,
(int64)5);*/
//#else
int32 a = 1;
float b = 2;
char c = 3;
double d = 4;
int64 e = 5;
BENCHMARK_INVOKE_ARGS5(TIMES3, SimpleParams,
(void*)&a,
(void*)&b,
(void*)&c,
(void*)&d,
(void*)&e);
//#endif
/*void* params[5];
{
auto klass = MyScript2::GetStaticClass();
auto method = klass->GetMethod("SimpleParams", 5);
auto instance = scriptTwo->GetManagedInstance();
MObject* exception = nullptr;
const auto times = (100 * 3);
const auto chunkTimes = 100;
const auto freq = Platform::GetClockFrequency();
params[0] = MUtils::Box<int32>(1, MCore::TypeCache::Int32);
params[1] = MUtils::Box<float>(2, MCore::TypeCache::Single);
params[2] = MUtils::Box<char>('3', MCore::TypeCache::SByte);
params[3] = MUtils::Box<double>(4, MCore::TypeCache::Double);
params[4] = MUtils::Box<int64>(5, MCore::TypeCache::Int64);
results.Clear();
auto start2 = Platform::GetTimeCycles();
for (int i = 0; i < times; ++i)
{
auto start = Platform::GetTimeCycles();
for (int j = 0; j < chunkTimes; ++j) method->Invoke(instance, params, &exception);
auto end = Platform::GetTimeCycles();
auto elapsed = end - start;
results.Add(elapsed);
}
auto end2 = Platform::GetTimeCycles();
auto elapsed2 = end2 - start2;
Sorting::MergeSort(results);
const auto resultsIndex = 0;
Log::Logger::Write(LogType::Info, ::String::Format(L" - InvokeOnly: {:.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));
};*/
#if NEW_VERSION
auto __param0_handle = *(MGCHandle*)&params[0];
MCore::GCHandle::Free(__param0_handle);
auto __param1_handle = *(MGCHandle*)&params[1];
MCore::GCHandle::Free(__param1_handle);
auto __param2_handle = *(MGCHandle*)&params[2];
MCore::GCHandle::Free(__param2_handle);
auto __param3_handle = *(MGCHandle*)&params[3];
MCore::GCHandle::Free(__param3_handle);
auto __param4_handle = *(MGCHandle*)&params[4];
MCore::GCHandle::Free(__param4_handle);
#endif
}
}
if (otherTests)
{
LOG_TEST(StringParamAnsi);
if (callTests)
{
BenchmarkCall(benchmarkContext, &MyScript2::StringParamAnsi, shortStringAnsi);
}
if (thunkTests)
{
BENCHMARK_THUNK_BEGIN_ARGS1(TIMES2, StringParamAnsi);
params[0] = MUtils::Box<StringAnsi>(shortStringAnsi, MCore::TypeCache::String);
BENCHMARK_THUNK_CALL_ARGS1();
#if NEW_VERSION
MUtils::FreeManaged<StringAnsi>((MObject*)params[0]);
#endif
BENCHMARK_THUNK_END();
}
//else
// LOG(Info, " - InvokeThunkOnly: skipped");
if (invokeTests)
{
BENCHMARK_INVOKE_ARGS1(TIMES2, StringParamAnsi,
MUtils::Box<StringAnsi>(shortStringAnsi, MCore::TypeCache::String));
#if NEW_VERSION
MUtils::FreeManaged<StringAnsi>((MObject*)params[0]);
#endif
}
}
if (otherTests)
{
LOG_TEST(StringParam);
if (callTests)
{
BenchmarkCall(benchmarkContext, &MyScript2::StringParam, shortString);
}
if (thunkTests)
{
BENCHMARK_THUNK_BEGIN_ARGS1(TIMES2, StringParam);
params[0] = MUtils::Box<String>(shortString, MCore::TypeCache::String);
BENCHMARK_THUNK_CALL_ARGS1();
#if NEW_VERSION
MUtils::FreeManaged<String>((MObject*)params[0]);
#endif
BENCHMARK_THUNK_END();
}
//else
// LOG(Info, " - InvokeThunkOnly: skipped");
if (invokeTests)
{
BENCHMARK_INVOKE_ARGS1(TIMES2, StringParam,
MUtils::Box<String>(shortString, MCore::TypeCache::String));
#if NEW_VERSION
MUtils::FreeManaged<String>((MObject*)params[0]);
#endif
}
}
#if false
if (otherTests)
{
LOG_TEST(StringParamRef);
if (callTests)
{
BenchmarkCall(&MyScript2::StringParamRef, shortString);
}
if (thunkTests)
{
BENCHMARK_THUNK_BEGIN_ARGS1(TIMES2, StringParamRef);
params[0] = MUtils::Box<String>(shortString, MCore::TypeCache::String);
BENCHMARK_THUNK_CALL_ARGS1();
#if NEW_VERSION
MUtils::FreeManaged<String>((MObject*)params[0]);
#endif
BENCHMARK_THUNK_END();
}
//else
// LOG(Info, " - InvokeThunkOnly: skipped");
if (invokeTests)
{
BENCHMARK_INVOKE_ARGS1(TIMES2, StringParamRef,
MUtils::Box<String>(shortString, MCore::TypeCache::String));
#if NEW_VERSION
MUtils::FreeManaged<String>((MObject*)params[0]);
#endif
}
}
#endif
if (otherTests)
{
LOG_TEST(StringParamRefConst);
if (callTests)
{
BenchmarkCall<const String&>(benchmarkContext, &MyScript2::StringParamRefConst, shortString);
}
if (thunkTests)
{
BENCHMARK_THUNK_BEGIN_ARGS1(TIMES2, StringParamRefConst);
params[0] = MUtils::Box<String>(shortString, MCore::TypeCache::String);
BENCHMARK_THUNK_CALL_ARGS1();
#if NEW_VERSION
MUtils::FreeManaged<String>((MObject*)params[0]);
#endif
BENCHMARK_THUNK_END();
}
//else
// LOG(Info, " - InvokeThunkOnly: skipped");
if (invokeTests)
{
BENCHMARK_INVOKE_ARGS1(TIMES2, StringParamRefConst,
MUtils::Box<String>(shortString, MCore::TypeCache::String));
#if NEW_VERSION
MUtils::FreeManaged<String>((MObject*)params[0]);
#endif
}
}
if (asRefTests)
{
LOG_TEST(StringParamAsRef);
if (callTests)
{
String str = shortString;
BenchmarkCall<String&>(benchmarkContext, &MyScript2::StringParamAsRef, str);
}
if (thunkTests)
{
LOG(Info, " - InvokeThunkOnly: not valid");
/* str = shortString;
BENCHMARK_THUNK_BEGIN_ARGS1(TIMES3, StringParamAsRef);
#if NEW_VERSION
auto __param_orig_str = MUtils::Box<String>(str, MCore::TypeCache::String);
auto __param_str = __param_orig_str;
params[0] = &__param_str;
#else
auto __param_str = MUtils::Box<String>(str, MCore::TypeCache::String);
params[0] = &__param_str;
#endif
BENCHMARK_THUNK_CALL_ARGS1_REF({ params[0] = &__param_str; });
str = MUtils::Unbox<String>(*(MObject**)params[0]);
ASSERT(str == shortString);
#if NEW_VERSION
MUtils::FreeManaged<String>((MObject*)__param_str);
if (__param_orig_str != __param_str)
MUtils::FreeManaged<String>((MObject*)__param_orig_str);
#endif
BENCHMARK_THUNK_END();*/
}
//else
// LOG(Info, " - InvokeThunkOnly: skipped");
if (invokeTests)
{
String str = shortString;
#if NEW_VERSION
BENCHMARK_INVOKE_ARGS1_REF(TIMES3, StringParamAsRef,
MUtils::Box<String>(shortString, MCore::TypeCache::String),
MUtils::FreeManaged<String>);
#else
BENCHMARK_INVOKE_ARGS1_REF(TIMES3, StringParamAsRef,
MUtils::Box<String>(shortString, MCore::TypeCache::String),
{});
#endif
}
}
if (otherTests)
{
LOG_TEST(ActorParam);
if (callTests)
{
BenchmarkCall(benchmarkContext, &MyScript2::ActorParam, actor);
}
if (thunkTests)
{
BENCHMARK_THUNK_BEGIN_ARGS1(TIMES2, ActorParam);
params[0] = ScriptingObject::ToManaged((ScriptingObject*)actor);
BENCHMARK_THUNK_CALL_ARGS1();
BENCHMARK_THUNK_END();
}
//else
// LOG(Info, " - InvokeThunkOnly: skipped");
if (invokeTests)
{
BENCHMARK_INVOKE_ARGS1(TIMES2, ActorParam,
ScriptingObject::ToManaged((ScriptingObject*)actor));
}
}
if (otherTests)
{
LOG_TEST(ComplexParam);
if (callTests)
{
BenchmarkCall(benchmarkContext, &MyScript2::ComplexParam, behaviorUpdateContext);
}
if (thunkTests)
{
BENCHMARK_THUNK_BEGIN_ARGS1(TIMES2, ComplexParam);
params[0] = MUtils::Box<BehaviorUpdateContext>(behaviorUpdateContext, BehaviorUpdateContext::TypeInitializer.GetClass());
BENCHMARK_THUNK_CALL_ARGS1();
#if NEW_VERSION
MUtils::FreeManaged<BehaviorUpdateContext>((MObject*)params[0]);
#endif
BENCHMARK_THUNK_END();
}
//else
// LOG(Info, " - InvokeThunkOnly: skipped");
if (invokeTests)
{
//auto param1 = MUtils::Box<BehaviorUpdateContext>(behaviorUpdateContext, BehaviorUpdateContext::TypeInitializer.GetClass());
/*void* params[1];
{
auto klass = MyScript2::GetStaticClass();
auto method = klass->GetMethod("ComplexParam", 1);
auto instance = scriptTwo->GetManagedInstance();
MObject* exception = nullptr;
const auto times = (1000 * 3);
const auto chunkTimes = 100;
const auto freq = Platform::GetClockFrequency();
params[0] = &behaviorUpdateContext;
results.Clear();
auto start2 = Platform::GetTimeCycles();
for (int i = 0; i < times; ++i) {
auto start = Platform::GetTimeCycles();
for (int j = 0; j < chunkTimes; ++j) method->Invoke(instance, params, &exception);
auto end = Platform::GetTimeCycles();
auto elapsed = end - start;
results.Add(elapsed);
}
auto end2 = Platform::GetTimeCycles();
auto elapsed2 = end2 - start2;
Sorting::MergeSort(results);
const auto resultsIndex = 0;
Log::Logger::Write(LogType::Info, ::String::Format(L" - InvokeOnly: {:.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));
};*/
BENCHMARK_INVOKE_ARGS1(TIMES2, ComplexParam, &behaviorUpdateContext);
#if NEW_VERSION
//MUtils::FreeManaged<BehaviorUpdateContext>((MObject*)params[0]);
#endif
}
}
if (otherTests)
{
LOG_TEST(Complex2Param);
if (callTests)
{
BenchmarkCall<RenderContext&>(benchmarkContext, &MyScript2::Complex2Param, renderContext);
}
if (thunkTests)
{
BENCHMARK_THUNK_BEGIN_ARGS1(TIMES3, Complex2Param);
params[0] = MUtils::Box<RenderContext>(renderContext, RenderContext::TypeInitializer.GetClass());
BENCHMARK_THUNK_CALL_ARGS1();
#if NEW_VERSION
MUtils::FreeManaged<RenderContext>((MObject*)params[0]);
#endif
BENCHMARK_THUNK_END();
}
//else
// LOG(Info, " - InvokeThunkOnly: skipped");
if (invokeTests)
{
BENCHMARK_INVOKE_ARGS1(TIMES3, Complex2Param, &renderContext);
#if NEW_VERSION
//MUtils::FreeManaged<RenderContext>((MObject*)params[0]);
#endif
}
}
if (otherTests)
{
LOG_TEST(Complex2ParamConst);
if (callTests)
{
BenchmarkCall<const RenderContext&>(benchmarkContext, &MyScript2::Complex2ParamConst, renderContext);
}
if (thunkTests)
{
BENCHMARK_THUNK_BEGIN_ARGS1(TIMES3, Complex2ParamConst);
params[0] = MUtils::Box<RenderContext>(renderContext, RenderContext::TypeInitializer.GetClass());
BENCHMARK_THUNK_CALL_ARGS1();
#if NEW_VERSION
MUtils::FreeManaged<RenderContext>((MObject*)params[0]);
#endif
BENCHMARK_THUNK_END();
}
//else
// LOG(Info, " - InvokeThunkOnly: skipped");
if (invokeTests)
{
BENCHMARK_INVOKE_ARGS1(TIMES3, Complex2ParamConst, &renderContext);
#if NEW_VERSION
//MUtils::FreeManaged<RenderContext>((MObject*)params[0]);
#endif
}
}
if (asRefTests)
{
LOG_TEST(Complex2ParamAsRef);
if (callTests)
{
RenderContext context = renderContext;
BenchmarkCall<RenderContext&>(benchmarkContext, &MyScript2::Complex2ParamAsRef, context);
}
if (thunkTests)
{
LOG(Info, " - InvokeThunkOnly: not valid");
/* context = renderContext;
BENCHMARK_THUNK_BEGIN_ARGS1(TIMES3, Complex2ParamAsRef);
#if NEW_VERSION
auto __param_orig_context = MUtils::Box<RenderContext>(context, RenderContext::TypeInitializer.GetClass());
auto __param_context = __param_orig_context;
params[0] = &__param_context;
#else
auto __param_context = MUtils::Box<RenderContext>(context, RenderContext::TypeInitializer.GetClass());
params[0] = &__param_context;
#endif
BENCHMARK_THUNK_CALL_ARGS1_REF({ if (__param_orig_context != __param_context) MUtils::FreeManaged<RenderContext>((MObject*)__param_orig_context); params[0] = &__param_context; });
context = MUtils::Unbox<RenderContext>(*(MObject**)params[0]);
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);
#endif
BENCHMARK_THUNK_END();*/
}
//else
// LOG(Info, " - InvokeThunkOnly: skipped");
}
if (arrayTests)
{
LOG_TEST(SimpleArrayParam);
if (callTests)
{
BenchmarkCall(benchmarkContext, &MyScript2::SimpleArrayParam, simpleArray);
}
if (thunkTests)
{
BENCHMARK_THUNK_BEGIN_ARGS1(TIMES3, SimpleArrayParam);
params[0] = MUtils::ToArray(simpleArray, MCore::TypeCache::Int32);
BENCHMARK_THUNK_CALL_ARGS1();
#if NEW_VERSION
MUtils::FreeManagedArray<int>((MArray*)params[0]);
#endif
BENCHMARK_THUNK_END();
}
//else
// LOG(Info, " - InvokeThunkOnly: skipped");
if (invokeTests)
{
BENCHMARK_INVOKE_ARGS1(TIMES3, SimpleArrayParam,
MUtils::ToArray(simpleArray, MCore::TypeCache::Int32));
#if NEW_VERSION
MUtils::FreeManagedArray<int>((MArray*)params[0]);
#endif
}
}
if (arrayTests && asRefTests)
{
LOG_TEST(SimpleArrayParamAsRef);
if (callTests)
{
Array<int> arr = simpleArray;
BenchmarkCall<Array<int32>&>(benchmarkContext, &MyScript2::SimpleArrayParamAsRef, simpleArray);
}
if (thunkTests)
{
LOG(Info, " - InvokeThunkOnly: not valid");
/* arr = simpleArray;
BENCHMARK_THUNK_BEGIN_ARGS1(TIMES3, SimpleArrayParamAsRef);
#if NEW_VERSION
auto __param_orig_arr = MUtils::ToArray(arr, MCore::TypeCache::Int32);
auto __param_arr = __param_orig_arr;
params[0] = &__param_arr;
#else
auto __param_arr = MUtils::ToArray(arr, MCore::TypeCache::Int32);
params[0] = &__param_arr;
#endif
BENCHMARK_THUNK_CALL_ARGS1();
arr = MUtils::Unbox<Array<int>>(*(MObject**)params[0]);
ASSERT(arr.Count() == simpleArray.Count());
for (int i=0; i<arr.Count(); i++) ASSERT(arr[i] == simpleArray[i]);
#if NEW_VERSION
MUtils::FreeManagedArray<int>(__param_arr); //fgfgh3
if (__param_orig_arr != __param_arr)
MUtils::FreeManagedArray<int>(__param_orig_arr); //fgfgh4
#endif
BENCHMARK_THUNK_END();*/
}
//else
// LOG(Info, " - InvokeThunkOnly: skipped");
}
if (arrayTests)
{
LOG_TEST(ActorArrayParam);
if (callTests)
{
BenchmarkCall(benchmarkContext, &MyScript2::ActorArrayParam, actorArray);
}
if (thunkTests)
{
BENCHMARK_THUNK_BEGIN_ARGS1(TIMES3, ActorArrayParam);
params[0] = MUtils::ToArray(actorArray, Actor::TypeInitializer.GetClass());
BENCHMARK_THUNK_CALL_ARGS1();
#if NEW_VERSION
MUtils::FreeManagedArray<Actor*>((MArray*)params[0]);
#endif
BENCHMARK_THUNK_END();
}
//else
// LOG(Info, " - InvokeThunkOnly: skipped");
if (invokeTests)
{
BENCHMARK_INVOKE_ARGS1(TIMES3, ActorArrayParam,
MUtils::ToArray(actorArray, Actor::TypeInitializer.GetClass()));
#if NEW_VERSION
MUtils::FreeManagedArray<Actor*>((MArray*)params[0]);
#endif
}
}
if (otherTests)
{
LOG_TEST(StringFieldStructParam);
if (callTests)
{
BenchmarkCall<StringStruct&>(benchmarkContext, &MyScript2::StringFieldStructParam, stringStruct);
}
}
if (otherTests && asRefTests)
{
LOG_TEST(StringFieldStructParamAsRef);
if (callTests)
{
StringStruct ss = stringStruct;
BenchmarkCall<StringStruct&>(benchmarkContext, &MyScript2::StringFieldStructParamAsRef, ss);
}
}
if (arrayTests)
{
LOG_TEST(StringFieldStructArrayParam);
if (callTests)
{
BenchmarkCall<Array<StringStruct>&>(benchmarkContext, &MyScript2::StringFieldStructArrayParam, stringStructArray);
}
}
if (arrayTests && asRefTests)
{
LOG_TEST(StringFieldStructArrayParamAsRef);
if (callTests)
{
Array<StringStruct> arr = stringStructArray;
BenchmarkCall<Array<StringStruct>&>(benchmarkContext, &MyScript2::StringFieldStructArrayParamAsRef, arr);
}
}
if (arrayTests)
{
LOG_TEST(ComplexArrayParam);
if (callTests)
{
BenchmarkCall(benchmarkContext, &MyScript2::ComplexArrayParam, complexArray);
}
if (thunkTests)
{
BENCHMARK_THUNK_BEGIN_ARGS1(TIMES3, ComplexArrayParam);
params[0] = MUtils::ToArray(complexArray, TestStruct::TypeInitializer.GetClass());
BENCHMARK_THUNK_CALL_ARGS1();
#if NEW_VERSION
MUtils::FreeManagedArray<TestStruct>((MArray*)params[0]);
#endif
BENCHMARK_THUNK_END();
}
//else
// LOG(Info, " - InvokeThunkOnly: skipped");
if (invokeTests)
{
BENCHMARK_INVOKE_ARGS1(TIMES3, ComplexArrayParam,
MUtils::ToArray(complexArray, TestStruct::TypeInitializer.GetClass()));
#if NEW_VERSION
MUtils::FreeManagedArray<TestStruct>((MArray*)params[0]);
#endif
}
}
if (arrayTests && asRefTests)
{
LOG_TEST(ComplexArrayParamAsRef);
if (callTests)
{
Array<TestStruct> arr = complexArray;
BenchmarkCall<Array<TestStruct>&>(benchmarkContext, &MyScript2::ComplexArrayParamAsRef, arr);
}
if (thunkTests)
{
LOG(Info, " - InvokeThunkOnly: not valid");
/* arr = complexArray;
BENCHMARK_THUNK_BEGIN_ARGS1(TIMES4, ComplexArrayParamAsRef);
#if NEW_VERSION
auto __param_orig_arr = MUtils::ToArray(arr, TestStruct::TypeInitializer.GetClass());
auto __param_arr = __param_orig_arr;
params[0] = &__param_arr;
#else
auto __param_arr = MUtils::ToArray(arr, TestStruct::TypeInitializer.GetClass());
params[0] = &__param_arr;
#endif
BENCHMARK_THUNK_CALL_ARGS1();
arr = MUtils::Unbox<Array<TestStruct>>(*(MObject**)params[0]);
ASSERT(arr.Count() == complexArray.Count());
for (int i = 0; i < arr.Count(); i++) ASSERT(arr[i] == complexArray[i]);
#if NEW_VERSION
MUtils::FreeManagedArray<TestStruct>(__param_arr);
if (__param_orig_arr != __param_arr)
MUtils::FreeManagedArray<TestStruct>(__param_orig_arr);
#endif
BENCHMARK_THUNK_END();*/
}
//else
// LOG(Info, " - InvokeThunkOnly: skipped");
}
#if TRACK_GCHANDLE_ALLOCS
int64 allocationsAfter, deallocationsAfter;
scriptTwo->GetStats(allocationsAfter, deallocationsAfter);
int64 allocationsDiff = allocationsAfter-allocationsBefore;
int64 deallocationsDiff = deallocationsAfter-deallocationsBefore;
int64 leftover = allocationsDiff - deallocationsDiff;
LOG(Info, "Total ManagedHandle allocations: {}, deallocations: {}, leftover: {}", allocationsDiff, deallocationsDiff, leftover);
#endif
}
void MyScript::OnEnable()
{
//LOG(Info, "C++ OnEnable");
}
void MyScript::OnDisable()
{
LOG(Info, "running garbage collector");
MCore::GC::Collect(MCore::GC::MaxGeneration(), MGCCollectionMode::Aggressive, true, true);
MCore::GC::WaitForPendingFinalizers();
}
void MyScript::OnUpdate()
{
}

522
Source/Game/MyScript.h Normal file
View File

@@ -0,0 +1,522 @@
#pragma once
#include "Engine/Scripting/Script.h"
#include <Engine/Animations/Curve.h>
#include <Engine/AI/Behavior.h>
#include "Engine/Graphics/PostProcessEffect.h"
#include "Engine/Graphics/RenderTask.h"
#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 StringStruct : public ISerializable
{
API_AUTO_SERIALIZATION();
DECLARE_SCRIPTING_TYPE_MINIMAL(StringStruct);
API_FIELD() String StringContent = TEXT("test");
API_FIELD() String StringEmpty = TEXT("");
API_FIELD() String StringEmpty2 = String::Empty;
API_FIELD() String StringNull = nullptr;
};
API_STRUCT(NoDefault) struct TestStruct : public ISerializable
{
API_AUTO_SERIALIZATION();
DECLARE_SCRIPTING_TYPE_MINIMAL(TestStruct);
// Var
API_FIELD() Float3 Vector = Float3::One;
// Ref
API_FIELD() ScriptingObject* Object = nullptr;
// Soft Type Ref
API_FIELD() SoftTypeReference<ScriptingObject> SoftTypeRef;
// Scene Ref
API_FIELD() SceneReference SceneRef;
friend bool operator==(const TestStruct& lhs, const TestStruct& rhs)
{
return lhs.Vector == rhs.Vector &&
lhs.Object == rhs.Object &&
lhs.SoftTypeRef == rhs.SoftTypeRef &&
lhs.SceneRef == rhs.SceneRef;
}
};
API_CLASS() class GAME_API MyScript2 : public Script
{
API_AUTO_SERIALIZATION();
DECLARE_SCRIPTING_TYPE(MyScript2);
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 intParam, bool boolParam, Actor* actorParam, String& stringRefParam, StringAnsi& stringAnsiRefParam, Float3 float3Param) {};
API_FUNCTION() virtual void CoverageTest1Array(Array<int32> intArrayParam, Array<bool> boolArrayParam, Array<Actor*> actorArrayParam, Array<String> stringArrayParam, Array<StringAnsi> stringAnsiArrayParam, Array<Float3> float3ArrayParam) {};
API_FUNCTION() virtual void CoverageTest1ByRef(API_PARAM(Ref) int32& intRefParam, API_PARAM(Ref) bool& boolRefParam, API_PARAM(Ref) String& stringRefParam, API_PARAM(Ref) StringAnsi& stringAnsiRefParam, API_PARAM(Ref) Float3& float3RefParam) {};
#if false
//APIa_FUNCTION() virtual void CoverageTest1ArrayByRef(API_PARAM(Ref) Array<int32>& intArrayRefParam, API_PARAM(Ref) Array<bool>& boolArrayRefParam, API_PARAM(Ref) Array<String>& stringArrayRefParam, API_PARAM(Ref) Array<StringAnsi>& stringAnsiArrayRefParam, API_PARAM(Ref) Array<Float3>& float3ArrayRefParam) {};
#endif
API_FUNCTION() virtual void CoverageTest2(Guid guidParam, AssetReference<FontAsset> fontAssetReferenceParam, Array<Guid> guidArrayParam, Array<AssetReference<FontAsset>> fontAssetReferenceArrayParam) {};
API_FUNCTION() virtual void CoverageTest3(ModelLOD* modelLodParam, API_PARAM(Out) Array<ModelLOD*>& modelLodArrayParam) {};
#if false
//APIa_FUNCTION() virtual void CoverageTest4(BytesContainer bytesContainerParam, API_PARAM(Out) BytesContainer& bytesContainerOutParam) {};
#endif
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() { ASSERT(false); };
API_FUNCTION() virtual void SimpleParams(int32 intParam, float boolParam, char charParam, double doubleParam, int64 int64Param) {};
API_FUNCTION() virtual void StringParamAnsi(StringAnsi str) {};
API_FUNCTION() virtual void StringParam(String str) {};
#if false
//API_FUNCTION() virtual void StringParamRef(String& str) {};
#endif
API_FUNCTION() virtual void StringParamRefConst(const String& str) {};
API_FUNCTION() virtual void StringParamAsRef(API_PARAM(Ref) String& stringRefParam) {};
API_FUNCTION() virtual void ActorParam(Actor* actorParam) {};
API_FUNCTION() virtual void ComplexParam(BehaviorUpdateContext context) {};
API_FUNCTION() virtual void Complex2Param(RenderContext& context) {};
API_FUNCTION() virtual void Complex2ParamConst(const RenderContext& context) {};
API_FUNCTION() virtual void Complex2ParamAsRef(API_PARAM(Ref) RenderContext& context) {};
API_FUNCTION() virtual void SimpleArrayParam(Array<int> intArrayParam) {};
API_FUNCTION() virtual void SimpleArrayParamRef(Array<int>& intArrayParam) {};
API_FUNCTION() virtual void SimpleArrayParamRefConst(const Array<int>& intArrayParam) {};
API_FUNCTION() virtual void SimpleArrayParamAsRef(API_PARAM(Ref) Array<int>& intArrayRefParam) {};
API_FUNCTION() virtual void ActorArrayParam(Array<Actor*> actorArrayParam) {};
API_FUNCTION() virtual void ActorArrayParamRef(Array<Actor*>& actorArrayParam) {};
API_FUNCTION() virtual void ActorArrayParamRefConst(const Array<Actor*>& actorArrayParam) {};
#if false
//API_FUN_CTION() virtual void ActorArrayParamAsRef(API_PARAM(Ref) Array<Actor*>& arr) {};
#endif
API_FUNCTION() virtual void StringFieldStructParam(StringStruct& stringStruct) { ASSERT(false); };
API_FUNCTION() virtual void StringFieldStructParamAsRef(API_PARAM(Ref) StringStruct& stringStruct) { ASSERT(false); };
API_FUNCTION() virtual void StringFieldStructArrayParam(Array<StringStruct>& stringStructArray) { ASSERT(false); };
API_FUNCTION() virtual void StringFieldStructArrayParamAsRef(API_PARAM(Ref) Array<StringStruct>& stringStructArray) { ASSERT(false); };
API_FUNCTION() virtual void ComplexArrayParam(Array<TestStruct> arrayParam) {};
API_FUNCTION() virtual void ComplexArrayParamRef(Array<TestStruct>& arrayParam) {};
API_FUNCTION() virtual void ComplexArrayParamRefConst(const Array<TestStruct>& arrayParam) {};
API_FUNCTION() virtual void ComplexArrayParamAsRef(API_PARAM(Ref) Array<TestStruct>& arrayRefParam) {};
//API_EVENT() Delegate<int32, Float3, const String&, String&, TestStruct&, const Array<TestStruct>&, Array<TestStruct>&> TestEvent;
};
struct BenchmarkContext
{
MyScript2* scriptTwo;
Array<uint64> results;
};
API_CLASS() class GAME_API MyScript : public Script
{
API_AUTO_SERIALIZATION();
DECLARE_SCRIPTING_TYPE(MyScript);
/*API_STRUCT() struct GAME_API InnerStructer
{
public:
float floaty;
};*/
//API_FIELD() MyThinger<int> thingey;
template<typename... TArgs>
void BenchmarkCall(BenchmarkContext& context, void(MyScript2::* fun)(TArgs...),
TArgs...);
//void BenchmarkCall(int times, BenchmarkContext& context, void(MyScript2::*fun)());
// [Script]
void OnStart() override;
void OnEnable() override;
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) {};
#if false
//APIa_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) {};
#endif
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*>& c) {};
#if false
//APIa_FUNCTION() virtual void CoverageTest4(BytesContainer a, API_PARAM(Out) BytesContainer& b) {};
#endif
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) {};
};
#define LOG_TEST(FUNC) \
if (thunkTests || invokeTests || callTests) LOG(Info, #FUNC);
#define BENCHMARK_INVOKE_ARGS0(REPEAT, FUNC) \
{ \
auto klass = MyScript2::GetStaticClass(); \
auto method = klass->GetMethod(#FUNC, 0); \
auto instance = scriptTwo->GetManagedInstance(); \
MObject* exception = nullptr; \
const auto times = REPEAT; \
const auto chunkTimes = CHUNK_TIMES; \
const auto freq = Platform::GetClockFrequency(); \
results.Clear(); \
auto start2 = Platform::GetTimeCycles(); \
for (int i = 0; i < times; ++i) \
{ \
auto start = Platform::GetTimeCycles(); \
for (int j = 0; j < chunkTimes; ++j) \
method->Invoke(instance, nullptr, &exception); \
auto end = Platform::GetTimeCycles(); \
auto elapsed = end - start; \
results.Add(elapsed); \
} \
auto end2 = Platform::GetTimeCycles(); \
auto elapsed2 = end2 - start2; \
Sorting::MergeSort(results); \
const auto resultsIndex = 0; \
LOG(Info, " - InvokeOnly: {:.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_INVOKE_ARGS1(REPEAT, FUNC, PARAM1) \
void* params[1]; \
{ \
auto klass = MyScript2::GetStaticClass(); \
auto method = klass->GetMethod(#FUNC, 1); \
auto instance = scriptTwo->GetManagedInstance(); \
MObject* exception = nullptr; \
const auto times = REPEAT; \
const auto chunkTimes = CHUNK_TIMES; \
const auto freq = Platform::GetClockFrequency(); \
params[0] = PARAM1; \
results.Clear(); \
auto start2 = Platform::GetTimeCycles(); \
for (int i = 0; i < times; ++i) \
{ \
auto start = Platform::GetTimeCycles(); \
for (int j = 0; j < chunkTimes; ++j) \
method->Invoke(instance, params, &exception); \
auto end = Platform::GetTimeCycles(); \
auto elapsed = end - start; \
results.Add(elapsed); \
} \
auto end2 = Platform::GetTimeCycles(); \
auto elapsed2 = end2 - start2; \
Sorting::MergeSort(results); \
const auto resultsIndex = 0; \
LOG(Info, " - InvokeOnly: {:.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_INVOKE_ARGS1_REF(REPEAT, FUNC, PARAM1, PARAM1_CLEAN) \
{ \
auto const NUM_PARAMS = 1; \
auto klass = MyScript2::GetStaticClass(); \
auto method = klass->GetMethod(#FUNC, NUM_PARAMS); \
auto instance = scriptTwo->GetManagedInstance(); \
MObject* exception = nullptr; \
const auto times = REPEAT; \
const auto chunkTimes = CHUNK_TIMES; \
const auto freq = Platform::GetClockFrequency(); \
void* params[NUM_PARAMS]; \
params[0] = PARAM1; \
results.Clear(); \
auto start2 = Platform::GetTimeCycles(); \
for (int i = 0; i < times; ++i) \
{ \
void* params_call[CHUNK_TIMES * NUM_PARAMS]; \
void* params_call_orig[CHUNK_TIMES * NUM_PARAMS]; \
for (int j = 0; j < chunkTimes * NUM_PARAMS; j += NUM_PARAMS) \
{ \
params_call_orig[j+0] = params[0]; \
params_call[j+0] = &params_call_orig[j+0]; \
} \
auto start = Platform::GetTimeCycles(); \
for (int j = 0; j < chunkTimes; ++j) \
{ \
method->Invoke(instance, &params_call[j * NUM_PARAMS], &exception); \
} \
auto end = Platform::GetTimeCycles(); \
auto elapsed = end - start; \
results.Add(elapsed); \
for (int j = 0; j < chunkTimes * NUM_PARAMS; j += NUM_PARAMS) \
{ \
if (params_call_orig[j+0] != params[0]) \
{ \
void* param = params_call_orig[j+0]; \
PARAM1_CLEAN((MObject*)param); \
} \
} \
} \
auto end2 = Platform::GetTimeCycles(); \
auto elapsed2 = end2 - start2; \
Sorting::MergeSort(results); \
{ \
void* param = params[0]; \
PARAM1_CLEAN((MObject*)param); \
} \
const auto resultsIndex = 0; \
LOG(Info, " - InvokeOnly: {:.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_INVOKE_ARGS2(REPEAT, FUNC, PARAM1, PARAM2) \
void* params[2]; \
{ \
auto klass = MyScript2::GetStaticClass(); \
auto method = klass->GetMethod(#FUNC, 2); \
auto instance = scriptTwo->GetManagedInstance(); \
MObject* exception = nullptr; \
const auto times = REPEAT; \
const auto chunkTimes = CHUNK_TIMES; \
const auto freq = Platform::GetClockFrequency(); \
params[0] = PARAM1; \
params[1] = PARAM2; \
results.Clear(); \
auto start2 = Platform::GetTimeCycles(); \
for (int i = 0; i < times; ++i) \
{ \
auto start = Platform::GetTimeCycles(); \
for (int j = 0; j < chunkTimes; ++j) \
method->Invoke(instance, params, &exception); \
auto end = Platform::GetTimeCycles(); \
auto elapsed = end - start; \
results.Add(elapsed); \
} \
auto end2 = Platform::GetTimeCycles(); \
auto elapsed2 = end2 - start2; \
Sorting::MergeSort(results); \
const auto resultsIndex = 0; \
LOG(Info, " - InvokeOnly: {:.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_INVOKE_ARGS3(REPEAT, FUNC, PARAM1, PARAM2, PARAM3) \
void* params[3]; \
{ \
auto klass = MyScript2::GetStaticClass(); \
auto method = klass->GetMethod(#FUNC, 3); \
auto instance = scriptTwo->GetManagedInstance(); \
MObject* exception = nullptr; \
const auto times = REPEAT; \
const auto chunkTimes = CHUNK_TIMES; \
const auto freq = Platform::GetClockFrequency(); \
params[0] = PARAM1; \
params[1] = PARAM2; \
params[2] = PARAM3; \
results.Clear(); \
auto start2 = Platform::GetTimeCycles(); \
for (int i = 0; i < times; ++i) \
{ \
auto start = Platform::GetTimeCycles(); \
for (int j = 0; j < chunkTimes; ++j) \
method->Invoke(instance, params, &exception); \
auto end = Platform::GetTimeCycles(); \
auto elapsed = end - start; \
results.Add(elapsed); \
} \
auto end2 = Platform::GetTimeCycles(); \
auto elapsed2 = end2 - start2; \
Sorting::MergeSort(results); \
const auto resultsIndex = 0; \
LOG(Info, " - InvokeOnly: {:.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_INVOKE_ARGS4(REPEAT, FUNC, PARAM1, PARAM2, PARAM3, PARAM4) \
void* params[4]; \
{ \
auto klass = MyScript2::GetStaticClass(); \
auto method = klass->GetMethod(#FUNC, 4); \
auto instance = scriptTwo->GetManagedInstance(); \
MObject* exception = nullptr; \
const auto times = REPEAT; \
const auto chunkTimes = CHUNK_TIMES; \
const auto freq = Platform::GetClockFrequency(); \
params[0] = PARAM1; \
params[1] = PARAM2; \
params[2] = PARAM3; \
params[3] = PARAM4; \
results.Clear(); \
auto start2 = Platform::GetTimeCycles(); \
for (int i = 0; i < times; ++i) \
{ \
auto start = Platform::GetTimeCycles(); \
for (int j = 0; j < chunkTimes; ++j) \
method->Invoke(instance, params, &exception); \
auto end = Platform::GetTimeCycles(); \
auto elapsed = end - start; \
results.Add(elapsed); \
} \
auto end2 = Platform::GetTimeCycles(); \
auto elapsed2 = end2 - start2; \
Sorting::MergeSort(results); \
const auto resultsIndex = 0; \
LOG(Info, " - InvokeOnly: {:.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_INVOKE_ARGS5(REPEAT, FUNC, PARAM1, PARAM2, PARAM3, PARAM4, PARAM5) \
void* params[5]; \
{ \
auto klass = MyScript2::GetStaticClass(); \
auto method = klass->GetMethod(#FUNC, 5); \
auto instance = scriptTwo->GetManagedInstance(); \
MObject* exception = nullptr; \
const auto times = REPEAT; \
const auto chunkTimes = CHUNK_TIMES; \
const auto freq = Platform::GetClockFrequency(); \
params[0] = PARAM1; \
params[1] = PARAM2; \
params[2] = PARAM3; \
params[3] = PARAM4; \
params[4] = PARAM5; \
results.Clear(); \
auto start2 = Platform::GetTimeCycles(); \
for (int i = 0; i < times; ++i) \
{ \
auto start = Platform::GetTimeCycles(); \
for (int j = 0; j < chunkTimes; ++j) \
method->Invoke(instance, params, &exception); \
auto end = Platform::GetTimeCycles(); \
auto elapsed = end - start; \
results.Add(elapsed); \
} \
auto end2 = Platform::GetTimeCycles(); \
auto elapsed2 = end2 - start2; \
Sorting::MergeSort(results); \
const auto resultsIndex = 0; \
LOG(Info, " - InvokeOnly: {:.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_BEGIN_ARGS0(REPEAT, FUNC) \
{ \
const auto times = REPEAT; \
const auto chunkTimes = CHUNK_TIMES; \
typedef void (*Thunk)(void* instance, MObject** exception); \
const auto thunk = (Thunk)scriptTwo->GetClass()->GetMethod(#FUNC, 0)->GetThunk(); \
const auto instance = scriptTwo->GetOrCreateManagedInstance(); \
MObject* exception = nullptr;
#define BENCHMARK_THUNK_CALL_ARGS0() \
const auto freq = Platform::GetClockFrequency(); \
results.Clear(); \
auto start2 = Platform::GetTimeCycles(); \
for (int i = 0; i < times; ++i) \
{ \
auto start = Platform::GetTimeCycles(); \
for (int j = 0; j < chunkTimes; ++j) \
thunk(instance, &exception); \
auto end = Platform::GetTimeCycles(); \
auto elapsed = end - start; \
results.Add(elapsed); \
} \
auto end2 = Platform::GetTimeCycles(); \
auto elapsed2 = end2 - start2; \
Sorting::MergeSort(results); \
const auto resultsIndex = 0; \
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_BEGIN_ARGS1(REPEAT, FUNC) \
{ \
const auto times = REPEAT; \
const auto chunkTimes = CHUNK_TIMES; \
typedef void (*Thunk)(void* instance, void*, MObject** exception); \
const auto thunk = (Thunk)scriptTwo->GetClass()->GetMethod(#FUNC, 1)->GetThunk(); \
const auto instance = scriptTwo->GetOrCreateManagedInstance(); \
MObject* exception = nullptr; \
void* params[1];
#define BENCHMARK_THUNK_CALL_ARGS1() \
const auto freq = Platform::GetClockFrequency(); \
results.Clear(); \
auto start2 = Platform::GetTimeCycles(); \
for (int i = 0; i < times; ++i) \
{ \
auto start = Platform::GetTimeCycles(); \
for (int j = 0; j < chunkTimes; ++j) \
thunk(instance, params[0], &exception); \
auto end = Platform::GetTimeCycles(); \
auto elapsed = end - start; \
results.Add(elapsed); \
} \
auto end2 = Platform::GetTimeCycles(); \
auto elapsed2 = end2 - start2; \
Sorting::MergeSort(results); \
const auto resultsIndex = 0; \
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_CALL_ARGS1_REF(FUN) \
const auto freq = Platform::GetClockFrequency(); \
results.Clear(); \
auto start2 = Platform::GetTimeCycles(); \
for (int i = 0; i < times; ++i) \
{ \
auto start = Platform::GetTimeCycles(); \
for (int j = 0; j < chunkTimes; ++j) \
{ \
thunk(instance, params[0], &exception); \
FUN \
} \
auto end = Platform::GetTimeCycles(); \
auto elapsed = end - start; \
results.Add(elapsed); \
} \
auto end2 = Platform::GetTimeCycles(); \
auto elapsed2 = end2 - start2; \
Sorting::MergeSort(results); \
const auto resultsIndex = 0; \
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_BEGIN_ARGS5(REPEAT, FUNC) \
{ \
const auto times = REPEAT; \
const auto chunkTimes = CHUNK_TIMES; \
typedef void (*Thunk)(void* instance, void*, void*, void*, void*, void*, MObject** exception); \
const auto thunk = (Thunk)scriptTwo->GetClass()->GetMethod(#FUNC, 5)->GetThunk(); \
const auto instance = scriptTwo->GetOrCreateManagedInstance(); \
MObject* exception = nullptr; \
void* params[5];
#define BENCHMARK_THUNK_CALL_ARGS5() \
const auto freq = Platform::GetClockFrequency(); \
results.Clear(); \
auto start2 = Platform::GetTimeCycles(); \
for (int i = 0; i < times; ++i) \
{ \
auto start = Platform::GetTimeCycles(); \
for (int j = 0; j < chunkTimes; ++j) \
thunk(instance, params[0], params[1], params[2], params[3], params[4], &exception); \
auto end = Platform::GetTimeCycles(); \
auto elapsed = end - start; \
results.Add(elapsed); \
} \
auto end2 = Platform::GetTimeCycles(); \
auto elapsed2 = end2 - start2; \
Sorting::MergeSort(results); \
const auto resultsIndex = 0; \
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); \
}

128
Source/Game/MyScriptTwo.cs Normal file
View File

@@ -0,0 +1,128 @@
using System;
using System.Collections.Generic;
using FlaxEngine;
using FlaxEngine.Interop;
using FlaxEngine.Networking;
using FlaxEngine.Online;
namespace Game;
/// <summary>
/// MyScriptTwo Script.
/// </summary>
public class MyScriptTwo : MyScript2
{
public Model Model;
/// <inheritdoc/>
public override void OnStart()
{
Debug.Log("C# OnStart");
}
/// <inheritdoc/>
public override void OnEnable()
{
//counter++;
}
/// <inheritdoc/>
public override void OnDisable()
{
}
/// <inheritdoc/>
public override void OnUpdate()
{
}
public override void GetStats(ref long allocations, ref long deallocations)
{
allocations = ManagedHandle.Allocations;
deallocations = ManagedHandle.Deallocations;
}
public override void 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 };
Guid fontAssetGuid = new Guid("ab96b25a49461d9f4f819484cf5c8213");
FontAsset fontAsset = Content.LoadAsync<FontAsset>(fontAssetGuid);
ModelLOD[] modelLods = Model.LODs;
Debug.Log($"{nameof(CoverageTest1)} (Managed)");
script.CoverageTest1(1, true, actor, shortString, shortString, f3);
Debug.Log($"{nameof(CoverageTest1Array)} (Managed)");
script.CoverageTest1Array(ints, booleans, actors, strings, strings, float3s);
Debug.Log($"{nameof(CoverageTest1ByRef)} (Managed)");
script.CoverageTest1ByRef(ref ints[0], ref booleans[0]/*, ref actors[0]*/, ref strings[0], ref strings[0], ref float3s[0]);
//Debug.Log($"{nameof(CoverageTest1ArrayByRef)} (Managed)");
//script.CoverageTest1ArrayByRef(ref ints, ref booleans/*, ref actors*/, ref strings, ref strings, ref float3s);
Debug.Log($"{nameof(CoverageTest2)} (Managed)");
script.CoverageTest2(fontAssetGuid, fontAsset, [fontAssetGuid], [fontAsset]);
Debug.Log($"{nameof(CoverageTest3)} (Managed)");
script.CoverageTest3(modelLods[0]/*, out var modelLod*/, out var modelLodsOut);
//Debug.Log($"{nameof(CoverageTest4)} (Managed)");
//script.CoverageTest4([1], out var bytesOut);
//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 CoverageTest4(byte[] a, out byte[] 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) {}
public override void StringParam(string str) {}
//public override void StringParamRef(string str) {}
public override void StringParamRefConst(string str) {}
public override void StringParamAsRef(ref string str) {}
public override void ActorParam(Actor actor) {}
public override void ComplexParam(BehaviorUpdateContext context) {}
public override void Complex2Param(RenderContext context) {}
public override void Complex2ParamConst(RenderContext context) {}
public override void Complex2ParamAsRef(ref RenderContext context) {}
public override void SimpleArrayParam(int[] arr) {}
public override void SimpleArrayParamRef(int[] arr) {}
public override void SimpleArrayParamRefConst(int[] arr) {}
public override void SimpleArrayParamAsRef(ref int[] arr) {}
public override void ActorArrayParam(Actor[] arr) {}
public override void ActorArrayParamRef(Actor[] arr) {}
public override void ActorArrayParamRefConst(Actor[] arr) {}
//public override void ActorArrayParamAsRef(ref Actor[] arr) {}
public override void StringFieldStructParam(StringStruct stringStruct) {}
public override void StringFieldStructParamAsRef(ref StringStruct stringStruct) {}
public override void StringFieldStructArrayParam(StringStruct[] stringStructArray) {}
public override void StringFieldStructArrayParamAsRef(ref StringStruct[] stringStructArray) { }
public override void ComplexArrayParam(TestStruct[] arr) {}
public override void ComplexArrayParamRef(TestStruct[] arr) {}
public override void ComplexArrayParamRefConst(TestStruct[] arr) {}
public override void ComplexArrayParamAsRef(ref TestStruct[] arr) {}
}

View File

@@ -44,6 +44,16 @@ public struct PlayerInputState2 : IEquatable<PlayerInputState2>
ViewAngles = lastInputViewAngles + ViewDelta;
ViewDelta = Float2.Zero;
}
public override bool Equals(object obj)
{
return obj is PlayerInputState2 && Equals((PlayerInputState2)obj);
}
public override int GetHashCode()
{
throw new NotImplementedException();
}
}
public interface IPlayerInput

View File

@@ -24,13 +24,16 @@ public class GameTarget : GameProjectTarget
OutputType = TargetOutputType.Executable;
}
Modules.Add("Game");
Modules.Add("Graphics");
}
public override void SetupTargetEnvironment(BuildOptions options)
{
base.SetupTargetEnvironment(options);
#pragma warning disable CS0618 // X is obsolete
options.LinkEnv.UseFastPDBLinking = true;
#pragma warning restore CS0618 // X is obsolete
}
public override string GetOutputFilePath(BuildOptions options, TargetOutputType? outputType = null)