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);
        }
Пример #2
0
        public void SpawnCommand(Player sender, VehicleModelType model, IWorldService worldService)
        {
            var vehicle = worldService.CreateVehicle(model, sender.Position + Vector3.Up, 0, -1, -1);

            sender.PutInVehicle(vehicle.Entity);
            sender.SendClientMessage($"{model} spawned!");
        }
Пример #3
0
        public void OnGameModeInit(IVehicleRepository vehiclesRepository, IWorldService worldService,
                                   IServerService serverService, IVehicleInfoService vehicleInfoService)
        {
            // Event methods have dependency injection alongside the arguments

            Console.WriteLine("Do game mode loading goodies...");

            vehiclesRepository.Foo();

            worldService.CreateActor(101, new Vector3(0, 0, 20), 0);

            var blue = Color.Blue;

            blue.A      = 128;
            _zone       = worldService.CreateGangZone(0, 0, 100, 100);
            _zone.Color = blue;
            _zone.Show();

            var obj = worldService.CreateObject(16638, new Vector3(10, 10, 40), Vector3.Zero, 1000);

            obj.DisableCameraCollisions();

            worldService.CreateVehicle(VehicleModelType.Alpha, new Vector3(40, 40, 10), 0, 0, 0);

            var green = Color.Green;

            green.A = 128;
            worldService.CreateTextLabel("text", green, new Vector3(10, 10, 10), 1000);

            _welcome              = worldService.CreateTextDraw(new Vector2(20, 40), "Hello, world");
            _welcome.Alignment    = TextDrawAlignment.Left;
            _welcome.Font         = TextDrawFont.Diploma;
            _welcome.Proportional = true;
            Console.WriteLine("TD pos: " + _welcome.Position);
            Console.WriteLine(_welcome.Entity.ToString());

            _menu = worldService.CreateMenu("Test menu", new Vector2(200, 300), 100);
            _menu.AddItem("Hello!!!");
            _menu.AddItem("Hello!!");
            _menu.AddItem("Hello!");

            var ctx = SynchronizationContext.Current;

            Task.Run(() =>
            {
                // ... Run things on a worker thread.

                ctx.Send(_ =>
                {
                    // ... Run things on the main thead.
                }, null);
            });

            serverService.SetGameModeText("SampSharp.Entities");

            var size = vehicleInfoService.GetModelInfo(VehicleModelType.AT400, VehicleModelInfoType.Size);

            Console.WriteLine($"AT400 size {size}");
        }
Пример #4
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");
        }
Пример #5
0
 public void OnGameModeInit(IWorldService worldService)
 {
     worldService.CreateVehicle(VehicleModelType.Alpha, new Vector3(40, 40, 10), 0, 0, 0);
 }