Example #1
0
        /// <inheritdoc />
        public T AddComponent <T>(EntityId entity) where T : Component
        {
            if (!_entities.TryGetValue(entity, out var entityEntry))
            {
                throw new EntityNotFoundException(nameof(entity));
            }

            var component = typeof(NativeComponent).IsAssignableFrom(typeof(T))
                ? NativeObjectProxyFactory.CreateInstance <T>()
                : (T)Activator.CreateInstance(typeof(T),
                                              BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance, null, null, null);

            component.Entity  = entity;
            component.Manager = this;

            entityEntry.Components.Add(component);
            _components.Add(component);

            component.InitializeComponent();

            return(component);
        }
 static TextDraw()
 {
     Internal = NativeObjectProxyFactory.CreateInstance <TextDrawInternal>();
 }
Example #3
0
 static YSF()
 {
     Internal = NativeObjectProxyFactory.CreateInstance <YSFInternal>();
 }
 static Menu()
 {
     Internal = NativeObjectProxyFactory.CreateInstance <MenuInternal>();
 }
 static TextLabel()
 {
     Internal = NativeObjectProxyFactory.CreateInstance <TextLabelInternal>();
 }
Example #6
0
 static Pickup()
 {
     Internal = NativeObjectProxyFactory.CreateInstance <PickupInternal>();
 }
Example #7
0
 static FCNPC()
 {
     Internal = NativeObjectProxyFactory.CreateInstance <FCNPCInternal>();
 }
Example #8
0
 static GlobalObject()
 {
     Internal = NativeObjectProxyFactory.CreateInstance <GlobalObjectInternal>();
 }
 static MovePath()
 {
     Internal = NativeObjectProxyFactory.CreateInstance <MovePathInternal>();
 }
Example #10
0
 static BitStream()
 {
     Internal = NativeObjectProxyFactory.CreateInstance <BitStreamInternal>();
 }
 static Playback()
 {
     Internal = NativeObjectProxyFactory.CreateInstance <PlaybackInternal>();
 }
 static DynamicActor()
 {
     Internal = NativeObjectProxyFactory.CreateInstance <DynamicActorInternal>();
 }
Example #13
0
 /// <summary>
 /// Initializes a new instance of the <see cref="NativeProxy{T}" /> class.
 /// </summary>
 public NativeProxy()
 {
     Instance = NativeObjectProxyFactory.CreateInstance <T>();
 }
Example #14
0
 static DynamicWorldObject()
 {
     WorldInternal = NativeObjectProxyFactory.CreateInstance <DynamicWorldObjectInternal>();
 }
Example #15
0
 static Dialog()
 {
     Internal = NativeObjectProxyFactory.CreateInstance <DialogInternal>();
 }
Example #16
0
 static VehicleModelInfo()
 {
     Internal = NativeObjectProxyFactory.CreateInstance <VehicleModelInfoInternal>();
 }
Example #17
0
 static BaseVehicle()
 {
     Internal = NativeObjectProxyFactory.CreateInstance <VehicleInternal>();
 }
Example #18
0
 static PlayerObject()
 {
     Internal = NativeObjectProxyFactory.CreateInstance <PlayerObjectInternal>();
 }
Example #19
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");
        }
Example #20
0
 static DynamicMapIcon()
 {
     Internal = NativeObjectProxyFactory.CreateInstance <DynamicMapIconInternal>();
 }
 static BaseMode()
 {
     Internal = NativeObjectProxyFactory.CreateInstance <BaseModeInternal>();
 }
 static GangZone()
 {
     Internal = NativeObjectProxyFactory.CreateInstance <GangZoneInternal>();
 }
Example #23
0
 static Streamer()
 {
     Internal = NativeObjectProxyFactory.CreateInstance <StreamerInternal>();
 }
Example #24
0
 static MapAndreas()
 {
     Internal = NativeObjectProxyFactory.CreateInstance <MapAndreasInternal>();
 }
Example #25
0
 static Sky()
 {
     Internal = NativeObjectProxyFactory.CreateInstance <SkyInternal>();
 }
Example #26
0
 static PVarCollection()
 {
     Internal = NativeObjectProxyFactory.CreateInstance <PVarCollectionInternal>();
 }
 static DynamicCheckpoint()
 {
     Internal = NativeObjectProxyFactory.CreateInstance <DynamicCheckpointInternal>();
 }
Example #28
0
 static RakNet()
 {
     Internal = NativeObjectProxyFactory.CreateInstance <RakNetInternal>();
 }