Browse Source

Atomic instead of volatile to match counter

combat-2
MagicBot 6 months ago
parent
commit
ba94fabfb8
  1. 2
      src/engine/gameManager/BuildingManager.java
  2. 12
      src/engine/gameManager/ForgeManager.java
  3. 11
      src/engine/loot/WorkOrder.java
  4. 10
      src/engine/net/client/handlers/ItemProductionMsgHandler.java

2
src/engine/gameManager/BuildingManager.java

@ -335,7 +335,7 @@ public enum BuildingManager {
if (ForgeManager.vendorWorkOrderLookup.get(hirelingNPC) != null) if (ForgeManager.vendorWorkOrderLookup.get(hirelingNPC) != null)
for (WorkOrder workOrder : ForgeManager.vendorWorkOrderLookup.get(hirelingNPC)) { for (WorkOrder workOrder : ForgeManager.vendorWorkOrderLookup.get(hirelingNPC)) {
workOrder.runCompleted = true; workOrder.runCompleted.set(true);
workOrder.vendor = null; workOrder.vendor = null;
DbManager.WarehouseQueries.DELETE_WORKORDER(workOrder); DbManager.WarehouseQueries.DELETE_WORKORDER(workOrder);
} }

12
src/engine/gameManager/ForgeManager.java

@ -65,7 +65,7 @@ public enum ForgeManager implements Runnable {
// Early exit for completed workOrders loaded from disk // Early exit for completed workOrders loaded from disk
// or vendors who were re-deeded with items cooking. // or vendors who were re-deeded with items cooking.
if (workOrder.vendor == null && workOrder.runCompleted) if (workOrder.vendor == null && workOrder.runCompleted.get())
continue; continue;
// This workOrder has completed production. // This workOrder has completed production.
@ -82,7 +82,7 @@ public enum ForgeManager implements Runnable {
DispatchMessage.dispatchMsgToInterestArea(workOrder.vendor, outMsg, mbEnums.DispatchChannel.SECONDARY, 700, false, false); DispatchMessage.dispatchMsgToInterestArea(workOrder.vendor, outMsg, mbEnums.DispatchChannel.SECONDARY, 700, false, false);
} }
workOrder.runCompleted = true; workOrder.runCompleted.set(true);
// Update workOrder on disk // Update workOrder on disk
@ -150,9 +150,9 @@ public enum ForgeManager implements Runnable {
workOrder.workOrderID = workOrderCounter.incrementAndGet(); workOrder.workOrderID = workOrderCounter.incrementAndGet();
workOrder.rollingDuration = ForgeManager.calcRollingDuration(workOrder); workOrder.rollingDuration = ForgeManager.calcRollingDuration(workOrder);
workOrder.completionTime = System.currentTimeMillis() + workOrder.rollingDuration; workOrder.completionTime = System.currentTimeMillis() + workOrder.rollingDuration;
workOrder.slots_used = calcAvailableSlots(workOrder); workOrder.slots_used.set(calcAvailableSlots(workOrder));
if (workOrder.slots_used == 0) if (workOrder.slots_used.get() == 0)
return 58; return 58;
workOrder.total_produced = 0; workOrder.total_produced = 0;
@ -164,7 +164,7 @@ public enum ForgeManager implements Runnable {
// Set total cost for production run // Set total cost for production run
workOrder.total_to_produce *= workOrder.slots_used; workOrder.total_to_produce *= workOrder.slots_used.get();
workOrder.production_cost = calcProductionCost(workOrder); workOrder.production_cost = calcProductionCost(workOrder);
workOrder.production_cost.forEach((key, value) -> workOrder.production_cost_total.put(key, value * workOrder.total_to_produce)); workOrder.production_cost.forEach((key, value) -> workOrder.production_cost_total.put(key, value * workOrder.total_to_produce));
@ -366,7 +366,7 @@ public enum ForgeManager implements Runnable {
workOrder.completionTime = System.currentTimeMillis() + workOrder.rollingDuration; workOrder.completionTime = System.currentTimeMillis() + workOrder.rollingDuration;
for (int i = 0; i < workOrder.slots_used; ++i) { for (int i = 0; i < workOrder.slots_used.get(); ++i) {
Item forged_item = forgeItem(workOrder); Item forged_item = forgeItem(workOrder);

11
src/engine/loot/WorkOrder.java

@ -29,6 +29,8 @@ import java.util.Objects;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.Delayed; import java.util.concurrent.Delayed;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
public class WorkOrder implements Delayed { public class WorkOrder implements Delayed {
@ -41,7 +43,7 @@ public class WorkOrder implements Delayed {
public int workOrderID; public int workOrderID;
public NPC vendor; public NPC vendor;
public volatile int slots_used; public AtomicInteger slots_used = new AtomicInteger(0);
public int total_to_produce; public int total_to_produce;
public int total_produced; public int total_produced;
public boolean multiple_slot_request; public boolean multiple_slot_request;
@ -53,7 +55,7 @@ public class WorkOrder implements Delayed {
public int suffixToken; public int suffixToken;
public long rollingDuration; public long rollingDuration;
public long completionTime; public long completionTime;
public volatile boolean runCompleted = false; public AtomicBoolean runCompleted = new AtomicBoolean(false);
// This collection is serialized to the vendor rolling window in ManageNPCMsg. // This collection is serialized to the vendor rolling window in ManageNPCMsg.
@ -70,7 +72,7 @@ public class WorkOrder implements Delayed {
this.workOrderID = jsonWorkOrder.getInt("workOrderID"); this.workOrderID = jsonWorkOrder.getInt("workOrderID");
this.vendor = NPC.getNPC(jsonWorkOrder.getInt("vendor")); this.vendor = NPC.getNPC(jsonWorkOrder.getInt("vendor"));
this.slots_used = jsonWorkOrder.getInt("slots_used"); this.slots_used.set(jsonWorkOrder.getInt("slots_used"));
this.total_to_produce = jsonWorkOrder.getInt("total_to_produce"); this.total_to_produce = jsonWorkOrder.getInt("total_to_produce");
this.total_produced = jsonWorkOrder.getInt("total_produced"); this.total_produced = jsonWorkOrder.getInt("total_produced");
this.multiple_slot_request = jsonWorkOrder.getBoolean("multiple_slot_request"); this.multiple_slot_request = jsonWorkOrder.getBoolean("multiple_slot_request");
@ -78,10 +80,9 @@ public class WorkOrder implements Delayed {
this.item_name_override = jsonWorkOrder.getString("item_name_override"); this.item_name_override = jsonWorkOrder.getString("item_name_override");
this.prefixToken = jsonWorkOrder.getInt("prefixToken"); this.prefixToken = jsonWorkOrder.getInt("prefixToken");
this.suffixToken = jsonWorkOrder.getInt("suffixToken"); this.suffixToken = jsonWorkOrder.getInt("suffixToken");
this.slots_used = jsonWorkOrder.getInt("slots_used");
this.rollingDuration = jsonWorkOrder.getLong("rollingDuration"); this.rollingDuration = jsonWorkOrder.getLong("rollingDuration");
this.completionTime = jsonWorkOrder.getLong("completionTime"); this.completionTime = jsonWorkOrder.getLong("completionTime");
this.runCompleted = jsonWorkOrder.getBoolean("runCompleted"); this.runCompleted.set(jsonWorkOrder.getBoolean("runCompleted"));
JSONObject productionCostMap = jsonWorkOrder.getJSONObject("production_cost"); JSONObject productionCostMap = jsonWorkOrder.getJSONObject("production_cost");

10
src/engine/net/client/handlers/ItemProductionMsgHandler.java

@ -150,7 +150,7 @@ public class ItemProductionMsgHandler extends AbstractClientMsgHandler {
ForgeManager.itemWorkOrderLookup.remove(virtualItem); ForgeManager.itemWorkOrderLookup.remove(virtualItem);
DbManager.removeFromCache(virtualItem); DbManager.removeFromCache(virtualItem);
workOrder.slots_used = workOrder.slots_used - 1; workOrder.slots_used.set(workOrder.slots_used.get() - 1);
// Update workOrder on disk // Update workOrder on disk
@ -421,15 +421,15 @@ public class ItemProductionMsgHandler extends AbstractClientMsgHandler {
// Update total_to_produce accounting for the slot being // Update total_to_produce accounting for the slot being
// removed while workOrder is not completed. // removed while workOrder is not completed.
if (!workOrder.runCompleted) if (!workOrder.runCompleted.get())
if (workOrder.multiple_slot_request && workOrder.slots_used > 1) { if (workOrder.multiple_slot_request && workOrder.slots_used.get() > 1) {
int itemsPerSlot = workOrder.total_to_produce / workOrder.slots_used; int itemsPerSlot = workOrder.total_to_produce / workOrder.slots_used.get();
workOrder.total_to_produce = workOrder.total_to_produce - itemsPerSlot; workOrder.total_to_produce = workOrder.total_to_produce - itemsPerSlot;
} }
// Slot is no longer allocated to this workOrder. // Slot is no longer allocated to this workOrder.
workOrder.slots_used = workOrder.slots_used - 1; workOrder.slots_used.set(workOrder.slots_used.get() - 1);
// Update workOrder on disk // Update workOrder on disk

Loading…
Cancel
Save