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."); }
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); }
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); } }
void Awake() { muzzle = transform.Find("Muzzle"); reloader = GetComponent <Reloader>(); transform.SetParent(hand); }
public void Update() { Reloader.ReloadAssemblies(); if (multiplayerSession.CurrentState.CurrentStage != MultiplayerSessionConnectionStage.Disconnected) { ProcessPackets(); } }
public void Update() { Reloader.ReloadAssemblies(); if (client != null && client.IsConnected()) { ProcessPackets(); } }
public void Update() { Reloader.ReloadAssemblies(); if (clientBridge.CurrentState != ClientBridgeState.Disconnected && clientBridge.CurrentState != ClientBridgeState.Failed) { ProcessPackets(); } }
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); }
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"); }
void HandleOnLocalPlayerJoined(Player player) { playerShoot = player.PlayerShoot; reloader = playerShoot.GrappleGun.reloader; reloader.OnAmmoChanged += HandleOnAmmoChanged; }
public override void Reload() { base.Reload(); Reloader?.Invoke(); }
private void Awake() { reloader = GetComponent <Reloader>(); }
// Start is called before the first frame update void Awake() { body = GetComponent <Rigidbody>(); reloaderMain = new Reloader(ReloadMainGunTimeout); reloaderExtra = new Reloader(ReloadExtraGunTimeout); }