示例#1
0
        public void DestructorNotCalledBeforeReloaderIsDisposed()
        {
            int constructorCnt = 0;
            int destructorCnt  = 0;

            // create reloader and assert constructor was called
            var reloader = new Reloader <int>(
                constructor: () => Interlocked.Increment(ref constructorCnt),
                destructor: (i) => Interlocked.Increment(ref destructorCnt));

            XAssert.AreEqual(0, constructorCnt, "Constructor should not be called as soon as Reloader is created");
            XAssert.AreEqual(0, destructorCnt, "Destructor should not be called before Reloader is disposed.");

            // reload and assert constructor was called again, but no destructor
            reloader.Reload(reloader.CurrentVersion);
            XAssert.AreEqual(1, constructorCnt);
            XAssert.AreEqual(0, destructorCnt, "Destructor should not be called before Reloader is disposed.");

            // reload and assert constructor was called again, but no destructor
            reloader.Reload(reloader.CurrentVersion);
            XAssert.AreEqual(2, constructorCnt);
            XAssert.AreEqual(0, destructorCnt, "Destructor should not be called before Reloader is disposed.");

            // dispose and assert that destructor was called twice (once for each reloaded value)
            reloader.Dispose();
            XAssert.AreEqual(2, destructorCnt, "Destructor wasn't called for each created value.");
        }
示例#2
0
        public void WhenConstructorFailsVersionIsNotIncremented()
        {
            bool firstConstructorInvocation = true;
            var  reloader = new Reloader <int>(
                constructor: () =>
            {
                if (!firstConstructorInvocation)
                {
                    throw new NotImplementedException();
                }

                firstConstructorInvocation = false;
                return(42);
            });

            // constructor not called yet --> current version 0
            XAssert.AreEqual(0, reloader.CurrentVersion);

            // constructor called the first time --> doesn't throw --> version incremented
            reloader.Reload(0);
            XAssert.AreEqual(1, reloader.CurrentVersion);

            // constructor called the second time --> throws --> version stays the same
            Assert.Throws <NotImplementedException>(() => reloader.Reload(1));
            XAssert.AreEqual(1, reloader.CurrentVersion);
        }
示例#3
0
        public void TestConcurrentReloadsOfSameVersionCreateOnlyOneNewValue()
        {
            int cnt = 0;

            using (var reloader = new Reloader <string>(() => "hi" + Interlocked.Increment(ref cnt)))
            {
                // call 'Reload(startVersion)' concurrently from multiple threads
                var startVersion = reloader.CurrentVersion;
                var range        = Enumerable.Range(0, 100).ToList();
                var threads      = range.Select(_ => new Thread(() =>
                {
                    reloader.Reload(startVersion);
                    var instance = reloader.CurrentVersionedValue;

                    // assert each thread gets the same instance
                    XAssert.AreEqual(startVersion + 1, instance.Version);
                    XAssert.AreEqual("hi1", instance.Value);
                })).ToList();
                ConcurrencyTest.Start(threads);
                ConcurrencyTest.Join(threads);

                // assert only 1 new value was created
                XAssert.AreEqual(startVersion + 1, reloader.CurrentVersion);
                XAssert.AreEqual(startVersion + 1, reloader.CurrentVersionedValue.Version);
                XAssert.AreEqual("hi1", reloader.CurrentVersionedValue.Value);
            }
        }
示例#4
0
    void Awake()
    {
        muzzle   = transform.Find("Muzzle");
        reloader = GetComponent <Reloader>();

        transform.SetParent(hand);
    }
示例#5
0
 public void Update()
 {
     Reloader.ReloadAssemblies();
     if (multiplayerSession.CurrentState.CurrentStage != MultiplayerSessionConnectionStage.Disconnected)
     {
         ProcessPackets();
     }
 }
示例#6
0
 public void Update()
 {
     Reloader.ReloadAssemblies();
     if (client != null && client.IsConnected())
     {
         ProcessPackets();
     }
 }
示例#7
0
 public void Update()
 {
     Reloader.ReloadAssemblies();
     if (clientBridge.CurrentState != ClientBridgeState.Disconnected &&
         clientBridge.CurrentState != ClientBridgeState.Failed)
     {
         ProcessPackets();
     }
 }
示例#8
0
文件: Main.cs 项目: BattleHH/Nitrox
 private static void InitializeReloader(bool serverPatching)
 {
     // Whitelist needs to be split, as both game instances load all four libraries
     // (because this patcher references both server and client, so no matter what instance we are on,
     //  AppDomain.CurrentDomain.GetAssemblies() returns both).
     if (serverPatching)
     {
         Reloader.Initialize("NitroxModel.dll", "NitroxPatcher.dll", "NitroxServer.dll");
     }
     else
     {
         Reloader.Initialize("NitroxModel.dll", "NitroxPatcher.dll", "NitroxClient.dll");
     }
 }
    public AbilityStateDelta UpdateState(AbilityInput input)
    {
        AbilityStateDelta delta = AbilityStateDelta.None;

        delta |= Reloader.PollInput(input);

        if (Reloader.IsReloading)
        {
            delta |= Reloader.DoReload();
        }
        else
        {
            delta |= Activator.PollInput(input);
        }

        return(delta);
    }
示例#10
0
        public void TestInitialValues()
        {
            int constructorCnt = 0;

            var reloader = new Reloader <int>(constructor: () => Interlocked.Increment(ref constructorCnt));

            XAssert.AreEqual(0, constructorCnt, "Constructor should not be called as soon as Reloader is created");

            XAssert.AreEqual(0, reloader.CurrentVersion);
            XAssert.AreEqual(0, constructorCnt, "Constructor should not be called except in the Reload method");

            XAssert.AreEqual(null, reloader.CurrentVersionedValue);
            XAssert.AreEqual(0, constructorCnt, "Constructor should not be called except in the Reload method");

            reloader.EnsureLoaded();
            XAssert.AreNotEqual(1, reloader.CurrentVersionedValue);
            XAssert.AreEqual(1, constructorCnt, "Constructor should be called in EnsureLoaded method");
        }
示例#11
0
 void HandleOnLocalPlayerJoined(Player player)
 {
     playerShoot             = player.PlayerShoot;
     reloader                = playerShoot.GrappleGun.reloader;
     reloader.OnAmmoChanged += HandleOnAmmoChanged;
 }
 public override void Reload()
 {
     base.Reload();
     Reloader?.Invoke();
 }
示例#13
0
 private void Awake()
 {
     reloader = GetComponent <Reloader>();
 }
示例#14
0
 // Start is called before the first frame update
 void Awake()
 {
     body          = GetComponent <Rigidbody>();
     reloaderMain  = new Reloader(ReloadMainGunTimeout);
     reloaderExtra = new Reloader(ReloadExtraGunTimeout);
 }