Skip to content

Commit c0dd506

Browse files
committed
add threading options
1 parent 2dd6051 commit c0dd506

3 files changed

Lines changed: 19 additions & 5 deletions

File tree

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
##
44
## Get latest from https://github.com/github/gitignore/blob/main/VisualStudio.gitignore
55

6+
.vscode/
7+
68
# User-specific files
79
*.rsuser
810
*.suo

PatchContainer.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using HarmonyLib;
22
using System;
3+
using UnityEngine;
34

45
namespace QuickerStack
56
{
@@ -19,6 +20,8 @@ internal static void Awake(Container __instance, ZNetView ___m_nview)
1920
[HarmonyPostfix]
2021
internal static void OnDestroyed(Container __instance)
2122
{
23+
Debug.Log("Destoying container instance");
24+
Debug.Log(__instance.transform.position);
2225
QuickerStackPlugin.AllContainers.Remove(__instance);
2326
}
2427
}

QuickerStackPlugin.cs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ namespace QuickerStack
1616
[BepInPlugin("org.bepinex.plugins.valheim.quicker_stack", "Quicker Stack", VERSION)]
1717
public class QuickerStackPlugin : BaseUnityPlugin
1818
{
19-
private const string VERSION = "0.0.3";
19+
private const string VERSION = "0.0.4";
2020

2121
public void Awake()
2222
{
@@ -70,6 +70,7 @@ private void LoadConfig()
7070
QuickerStackPlugin.IgnoreConsumable = this.BindParameter<bool>(QuickerStackPlugin.IgnoreConsumable, "IgnoreConsumable", "Whether to completely exclude consumables from quick stacking (food, potions).");
7171
QuickerStackPlugin.IgnoreAmmo = this.BindParameter<bool>(QuickerStackPlugin.IgnoreAmmo, "IgnoreAmmo", "Whether to completely exclude ammo from quick stacking (arrows)");
7272
QuickerStackPlugin.CoalesceTrophies = this.BindParameter<bool>(QuickerStackPlugin.CoalesceTrophies, "CoalesceTrophies", "Whether to put all types of trophies in the container if any trophy is found in that container.");
73+
QuickerStackPlugin.UseThreading = this.BindParameter<bool>(QuickerStackPlugin.UseThreading, "UseThreading", "Whether to enable threading when stacking.");
7374
}
7475

7576
private void OnSettingChanged(object sender, SettingChangedEventArgs e)
@@ -195,21 +196,29 @@ public static void DoQuickStack(Player player)
195196
if (list.Count != 0)
196197
{
197198
player.Message(MessageHud.MessageType.Center, String.Format("found {0} containers in range", list.Count));
198-
//StackToMany(player, list);
199-
Thread stackThread = new Thread(() => QuickerStackPlugin.StackToMany(player, list));
200-
stackThread.Start();
199+
if(UseThreading)
200+
{
201+
Debug.Log("Using thread !");
202+
Thread stackThread = new Thread(() => QuickerStackPlugin.StackToMany(player, list));
203+
stackThread.Start();
204+
}
205+
else
206+
{
207+
Debug.Log("Not using thread");
208+
StackToMany(player, list);
209+
}
201210
}
202211
}
203212

204213
public static List<Container> AllContainers = new List<Container>();
205214
private readonly string ConfigPath = Path.Combine(Paths.ConfigPath, "QuickerStack.cfg");
206215
private static ConfigFile configFile = null;
207-
public event EventHandler<SettingChangedEventArgs> SettingChanged;
208216
public static bool IgnoreAmmo = true;
209217
public static bool IgnoreConsumable = true;
210218
internal static float NearbyRange = 15f;
211219
public static KeyCode QuickStackKey = KeyCode.P;
212220
public static bool CoalesceTrophies = true;
221+
public static bool UseThreading = true;
213222
private static Dictionary<long, UserConfig> playerConfigs = new Dictionary<long, UserConfig>();
214223
}
215224
}

0 commit comments

Comments
 (0)