public void OnGameModeInit(IWorldService worldService, IEntityManager entityManager, INativeObjectProxyFactory proxyFactory, ITimerService timerService) { // Only test FastNative performance if FastNative is not activated if (proxyFactory is FastNativeBasedNativeObjectProxyFactory) { return; } // Benchmarking var fastFactory = new FastNativeBasedNativeObjectProxyFactory(_client); var fastProxy = (TestingFastNative)fastFactory.CreateInstance(typeof(TestingFastNative)); _fastProxy = fastProxy; _nativeGetVehicleParamsEx = Interop.FastNativeFind("GetVehicleParamsEx"); _testVehicleId = worldService.CreateVehicle(VehicleModelType.BMX, Vector3.One, 0, 0, 0).Entity.Handle; //timerService.Start(_ => BenchmarkRunTimer(), TimeSpan.FromSeconds(2)); //timerService.Start(_ => BenchmarkRunTimerProxy(), TimeSpan.FromSeconds(2)); // Test native features Console.WriteLine("TEST WITH HANDLE FACTORY:"); RunTests(proxyFactory); Console.WriteLine("TEST WITH FAST FACTORY:"); RunTests(fastFactory); // Threading test // timerService.Start(_ => ThreadingTest(fastProxy, handleProxy), TimeSpan.FromSeconds(15)); // Multiple calls test InvokeVehicleNatives(entityManager, fastProxy); }
private static void InvokeVehicleNatives(IEntityManager entityManager, TestingFastNative fastProxy) { // Call CreateVehicle native var testPosition = new Vector3(65.13f, 123.123f, 555.555f); var fastVehicleId = fastProxy.CreateVehicle((int)VehicleModelType.Landstalker, testPosition.X, testPosition.Y, testPosition.Z, 15, -1, -1, -1, 0); // Create Vehicle entity to verify vehicle position was set properly through the native var entity = SampEntities.GetVehicleId(fastVehicleId); entityManager.Create(entity); entityManager.AddComponent <NativeVehicle>(entity); var fastVehicleComp = entityManager.AddComponent <Vehicle>(entity); Console.WriteLine( $"Created vehicle {fastVehicleId} position {fastVehicleComp.Position}; matches? {(fastVehicleComp.Position == testPosition)}"); // Call GetVehiclePos Console.WriteLine("GOGO GetVehiclePos"); var ret = fastProxy.GetVehiclePos(fastVehicleId, out var x, out var y, out var z); Console.WriteLine("DONE GetVehiclePos"); var getPos = new Vector3(x, y, z); Console.WriteLine($"get pos ({ret}): {getPos} matches? {(testPosition == getPos)}"); }
private void ThreadingTest(TestingFastNative fastProxy, TestingFastNative handleProxy) { Console.WriteLine("RequiresInvoke: " + ((ISynchronizationProvider)_client).InvokeRequired); Console.WriteLine("IsPlayerConnected fast: " + fastProxy.IsPlayerConnected(0)); Console.WriteLine("IsPlayerConnected handle: " + handleProxy.IsPlayerConnected(0)); Task.Run(() => { Console.WriteLine("TASK.RequiresInvoke: " + ((ISynchronizationProvider)_client).InvokeRequired); Console.WriteLine("TASK.IsPlayerConnected fast: " + fastProxy.IsPlayerConnected(0)); Console.WriteLine("TASK.IsPlayerConnected handle: " + handleProxy.IsPlayerConnected(0)); }); }
public void OnGameModeInit(IWorldService worldService, IEntityManager entityManager, INativeObjectProxyFactory proxyFactory, ITimerService timerService) { // Only test FastNative performance if FastNative is not activated if (proxyFactory is FastNativeBasedNativeObjectProxyFactory) { return; } //timerService.Start(_ => BenchmarkRunTimer(), TimeSpan.FromSeconds(2)); timerService.Start(_ => BenchmarkRunTimerProxy(), TimeSpan.FromSeconds(2)); _nativeGetVehicleParamsEx = Interop.FastNativeFind("GetVehicleParamsEx"); _testVehicleId = worldService.CreateVehicle(VehicleModelType.BMX, Vector3.One, 0, 0, 0).Entity.Handle; var fastFactory = new FastNativeBasedNativeObjectProxyFactory(_client); var handleProxy = NativeObjectProxyFactory.CreateInstance <TestingFastNative>(); var fastProxy = (TestingFastNative)fastFactory.CreateInstance(typeof(TestingFastNative)); _fastProxy = fastProxy; // Call IsPlayerConnected timerService.Start(_ => { Console.WriteLine("RequiresInvoke: " + ((ISynchronizationProvider)_client).InvokeRequired); Console.WriteLine("IsPlayerConnected fast: " + fastProxy.IsPlayerConnected(0)); Console.WriteLine("IsPlayerConnected handle: " + handleProxy.IsPlayerConnected(0)); Task.Run(() => { Console.WriteLine("TASK.RequiresInvoke: " + ((ISynchronizationProvider)_client).InvokeRequired); Console.WriteLine("TASK.IsPlayerConnected fast: " + fastProxy.IsPlayerConnected(0)); Console.WriteLine("TASK.IsPlayerConnected handle: " + handleProxy.IsPlayerConnected(0)); }); }, TimeSpan.FromSeconds(1)); // Call CreateVehicle native var testPosition = new Vector3(65.13f, 123.123f, 555.555f); var fastVehicleId = fastProxy.CreateVehicle((int)VehicleModelType.Landstalker, testPosition.X, testPosition.Y, testPosition.Z, 15, -1, -1, -1, 0); // Create Vehicle entity to verify vehicle position was set properly through the native var entity = SampEntities.GetVehicleId(fastVehicleId); entityManager.Create(entity); entityManager.AddComponent <NativeVehicle>(entity); var fastVehicleComp = entityManager.AddComponent <Vehicle>(entity); Console.WriteLine($"Created vehicle {fastVehicleId} position {fastVehicleComp.Position}; matches? {(fastVehicleComp.Position == testPosition)}"); // Call GetVehiclePos var ret = fastProxy.GetVehiclePos(fastVehicleId, out var x, out var y, out var z); var getPos = new Vector3(x, y, z); Console.WriteLine($"get pos ({ret}): {getPos} matches? {(testPosition == getPos)}"); // Test immediate call to SetGameModeText // var nativeSetGameModeText = Interop.FastNativeFind("SetGameModeText"); // SetGameModeTextCall(nativeSetGameModeText, "TestValue"); // Test via proxy fastProxy.SetGameModeText("TestValueViaProxy"); }