From 7ce4073135fe3bcb6809974741afbf34206ec11b Mon Sep 17 00:00:00 2001 From: Ccomp5950 Date: Sat, 15 Mar 2014 04:05:56 -0500 Subject: [PATCH] Code effeciency project: Ore processing. Before: The stacker and processor used del(item) to get rid of the items causing /obj/movable/del() to spike up and cause fun amounts of lag. Also we have seperate variables for if a certain ore type is selected in the processing machine and the cooking portion of process() uses a huge string of if()'s which check 8 or so variables and is terrible and probably a pain in the ass should someone decide to later add ore types and recipes. After: We just set item.loc = null when it goes in the stacker of processor and garbage collection takes care of it within a tick. Those different variables for ore selection are now just one variable which is a bitfield, much easier to read, much easier to expand upon. --- code/modules/mining/machine_processing.dm | 169 ++++++++++++---------- code/modules/mining/machine_stacking.dm | 105 ++++++++------ 2 files changed, 158 insertions(+), 116 deletions(-) diff --git a/code/modules/mining/machine_processing.dm b/code/modules/mining/machine_processing.dm index 96e36aae41..db58e039fb 100644 --- a/code/modules/mining/machine_processing.dm +++ b/code/modules/mining/machine_processing.dm @@ -1,3 +1,12 @@ +#define ORE_PROC_GOLD 1 +#define ORE_PROC_SILVER 2 +#define ORE_PROC_DIAMOND 4 +#define ORE_PROC_GLASS 8 +#define ORE_PROC_PLASMA 16 +#define ORE_PROC_URANIUM 32 +#define ORE_PROC_IRON 64 +#define ORE_PROC_CLOWN 128 + /**********************Mineral processing unit console**************************/ /obj/machinery/mineral/processing_unit_console @@ -32,83 +41,83 @@ //iron if(machine.ore_iron || machine.ore_glass || machine.ore_plasma || machine.ore_uranium || machine.ore_gold || machine.ore_silver || machine.ore_diamond || machine.ore_clown || machine.ore_adamantine) if(machine.ore_iron) - if (machine.selected_iron==1) + if (machine.selected & ORE_PROC_IRON) dat += text("Smelting ") else dat += text("Not smelting ") dat += text("Iron: [machine.ore_iron]
") else - machine.selected_iron = 0 + machine.selected &= ~ORE_PROC_IRON //sand - glass if(machine.ore_glass) - if (machine.selected_glass==1) + if (machine.selected & ORE_PROC_GLASS) dat += text("Smelting ") else dat += text("Not smelting ") dat += text("Sand: [machine.ore_glass]
") else - machine.selected_glass = 0 + machine.selected &= ~ORE_PROC_GLASS //plasma if(machine.ore_plasma) - if (machine.selected_plasma==1) + if (machine.selected & ORE_PROC_PLASMA) dat += text("Smelting ") else dat += text("Not smelting ") dat += text("Plasma: [machine.ore_plasma]
") else - machine.selected_plasma = 0 + machine.selected &= ~ORE_PROC_PLASMA //uranium if(machine.ore_uranium) - if (machine.selected_uranium==1) + if (machine.selected & ORE_PROC_URANIUM) dat += text("Smelting ") else dat += text("Not smelting ") dat += text("Uranium: [machine.ore_uranium]
") else - machine.selected_uranium = 0 + machine.selected &= ~ORE_PROC_URANIUM //gold if(machine.ore_gold) - if (machine.selected_gold==1) + if (machine.selected & ORE_PROC_GOLD) dat += text("Smelting ") else dat += text("Not smelting ") dat += text("Gold: [machine.ore_gold]
") else - machine.selected_gold = 0 + machine.selected &= ~ORE_PROC_GOLD //silver if(machine.ore_silver) - if (machine.selected_silver==1) + if (machine.selected & ORE_PROC_SILVER) dat += text("Smelting ") else dat += text("Not smelting ") dat += text("Silver: [machine.ore_silver]
") else - machine.selected_silver = 0 + machine.selected &= ~ORE_PROC_SILVER //diamond if(machine.ore_diamond) - if (machine.selected_diamond==1) + if (machine.selected & ORE_PROC_DIAMOND) dat += text("Smelting ") else dat += text("Not smelting ") dat += text("Diamond: [machine.ore_diamond]
") else - machine.selected_diamond = 0 + machine.selected &= ~ORE_PROC_DIAMOND //bananium if(machine.ore_clown) - if (machine.selected_clown==1) + if (machine.selected & ORE_PROC_CLOWN) dat += text("Smelting ") else dat += text("Not smelting ") dat += text("Bananium: [machine.ore_clown]
") else - machine.selected_clown = 0 + machine.selected &= ~ORE_PROC_CLOWN //On or off @@ -132,44 +141,44 @@ src.add_fingerprint(usr) if(href_list["sel_iron"]) if (href_list["sel_iron"] == "yes") - machine.selected_iron = 1 + machine.selected |= ORE_PROC_IRON else - machine.selected_iron = 0 + machine.selected &= ~ORE_PROC_IRON if(href_list["sel_glass"]) if (href_list["sel_glass"] == "yes") - machine.selected_glass = 1 + machine.selected |= ORE_PROC_GLASS else - machine.selected_glass = 0 + machine.selected &= ~ORE_PROC_GLASS if(href_list["sel_plasma"]) if (href_list["sel_plasma"] == "yes") - machine.selected_plasma = 1 + machine.selected |= ORE_PROC_PLASMA else - machine.selected_plasma = 0 + machine.selected &= ~ORE_PROC_PLASMA if(href_list["sel_uranium"]) if (href_list["sel_uranium"] == "yes") - machine.selected_uranium = 1 + machine.selected |= ORE_PROC_URANIUM else - machine.selected_uranium = 0 + machine.selected &= ~ORE_PROC_URANIUM if(href_list["sel_gold"]) if (href_list["sel_gold"] == "yes") - machine.selected_gold = 1 + machine.selected |= ORE_PROC_GOLD else - machine.selected_gold = 0 + machine.selected &= ~ORE_PROC_GOLD if(href_list["sel_silver"]) if (href_list["sel_silver"] == "yes") - machine.selected_silver = 1 + machine.selected |= ORE_PROC_SILVER else - machine.selected_silver = 0 + machine.selected &= ~ORE_PROC_SILVER if(href_list["sel_diamond"]) if (href_list["sel_diamond"] == "yes") - machine.selected_diamond = 1 + machine.selected |= ORE_PROC_DIAMOND else - machine.selected_diamond = 0 + machine.selected &= ~ORE_PROC_DIAMOND if(href_list["sel_clown"]) if (href_list["sel_clown"] == "yes") - machine.selected_clown = 1 + machine.selected |= ORE_PROC_CLOWN else - machine.selected_clown = 0 + machine.selected &= ~ORE_PROC_CLOWN if(href_list["set_on"]) if (href_list["set_on"] == "on") machine.on = 1 @@ -187,6 +196,7 @@ icon_state = "furnace" density = 1 anchored = 1.0 + luminosity = 3 //Big fire with window, yeah it puts out a little light. var/obj/machinery/mineral/input = null var/obj/machinery/mineral/output = null var/obj/machinery/mineral/CONSOLE = null @@ -199,6 +209,8 @@ var/ore_iron = 0; var/ore_clown = 0; var/ore_adamantine = 0; + var/selected = 0 +/* var/selected_gold = 0 var/selected_silver = 0 var/selected_diamond = 0 @@ -207,8 +219,10 @@ var/selected_uranium = 0 var/selected_iron = 0 var/selected_clown = 0 +*/ var/on = 0 //0 = off, 1 =... oh you know! + /obj/machinery/mineral/processing_unit/New() ..() spawn( 5 ) @@ -227,14 +241,17 @@ var/i for (i = 0; i < 10; i++) if (on) - if (selected_glass == 1 && selected_gold == 0 && selected_silver == 0 && selected_diamond == 0 && selected_plasma == 0 && selected_uranium == 0 && selected_iron == 0 && selected_clown == 0) + + + + if (selected == ORE_PROC_GLASS) if (ore_glass > 0) ore_glass--; new /obj/item/stack/sheet/glass(output.loc) else on = 0 continue - if (selected_glass == 1 && selected_gold == 0 && selected_silver == 0 && selected_diamond == 0 && selected_plasma == 0 && selected_uranium == 0 && selected_iron == 1 && selected_clown == 0) + if (selected == ORE_PROC_GLASS + ORE_PROC_IRON) if (ore_glass > 0 && ore_iron > 0) ore_glass--; ore_iron--; @@ -242,49 +259,49 @@ else on = 0 continue - if (selected_glass == 0 && selected_gold == 1 && selected_silver == 0 && selected_diamond == 0 && selected_plasma == 0 && selected_uranium == 0 && selected_iron == 0 && selected_clown == 0) + if (selected == ORE_PROC_GOLD) if (ore_gold > 0) ore_gold--; new /obj/item/stack/sheet/mineral/gold(output.loc) else on = 0 continue - if (selected_glass == 0 && selected_gold == 0 && selected_silver == 1 && selected_diamond == 0 && selected_plasma == 0 && selected_uranium == 0 && selected_iron == 0 && selected_clown == 0) + if (selected == ORE_PROC_SILVER) if (ore_silver > 0) ore_silver--; new /obj/item/stack/sheet/mineral/silver(output.loc) else on = 0 continue - if (selected_glass == 0 && selected_gold == 0 && selected_silver == 0 && selected_diamond == 1 && selected_plasma == 0 && selected_uranium == 0 && selected_iron == 0 && selected_clown == 0) + if (selected == ORE_PROC_DIAMOND) if (ore_diamond > 0) ore_diamond--; new /obj/item/stack/sheet/mineral/diamond(output.loc) else on = 0 continue - if (selected_glass == 0 && selected_gold == 0 && selected_silver == 0 && selected_diamond == 0 && selected_plasma == 1 && selected_uranium == 0 && selected_iron == 0 && selected_clown == 0) + if (selected == ORE_PROC_PLASMA) if (ore_plasma > 0) ore_plasma--; new /obj/item/stack/sheet/mineral/plasma(output.loc) else on = 0 continue - if (selected_glass == 0 && selected_gold == 0 && selected_silver == 0 && selected_diamond == 0 && selected_plasma == 0 && selected_uranium == 1 && selected_iron == 0 && selected_clown == 0) + if (selected == ORE_PROC_URANIUM) if (ore_uranium > 0) ore_uranium--; new /obj/item/stack/sheet/mineral/uranium(output.loc) else on = 0 continue - if (selected_glass == 0 && selected_gold == 0 && selected_silver == 0 && selected_diamond == 0 && selected_plasma == 0 && selected_uranium == 0 && selected_iron == 1 && selected_clown == 0) + if (selected == ORE_PROC_IRON) if (ore_iron > 0) ore_iron--; new /obj/item/stack/sheet/metal(output.loc) else on = 0 continue - if (selected_glass == 0 && selected_gold == 0 && selected_silver == 0 && selected_diamond == 0 && selected_plasma == 1 && selected_uranium == 0 && selected_iron == 1 && selected_clown == 0) + if (selected == ORE_PROC_IRON + ORE_PROC_PLASMA) if (ore_iron > 0 && ore_plasma > 0) ore_iron--; ore_plasma--; @@ -292,14 +309,14 @@ else on = 0 continue - if (selected_glass == 0 && selected_gold == 0 && selected_silver == 0 && selected_diamond == 0 && selected_plasma == 0 && selected_uranium == 0 && selected_iron == 0 && selected_clown == 1) + if (selected == ORE_PROC_CLOWN) if (ore_clown > 0) ore_clown--; new /obj/item/stack/sheet/mineral/clown(output.loc) else on = 0 continue - if (selected_glass == 1 && selected_gold == 0 && selected_silver == 0 && selected_diamond == 0 && selected_plasma == 1 && selected_uranium == 0 && selected_iron == 0 && selected_clown == 0) + if (selected == ORE_PROC_GLASS + ORE_PROC_PLASMA) if (ore_glass > 0 && ore_plasma > 0) ore_glass--; ore_plasma--; @@ -307,7 +324,7 @@ else on = 0 continue - if (selected_glass == 1 && selected_gold == 0 && selected_silver == 0 && selected_diamond == 0 && selected_plasma == 1 && selected_uranium == 0 && selected_iron == 1 && selected_clown == 0) + if (selected == ORE_PROC_GLASS + ORE_PROC_IRON + ORE_PROC_PLASMA) if (ore_glass > 0 && ore_plasma > 0 && ore_iron > 0) ore_glass--; ore_iron--; @@ -316,10 +333,10 @@ else on = 0 continue - //THESE TWO ARE CODED FOR URIST TO USE WHEN HE GETS AROUND TO IT. - //They were coded on 18 Feb 2012. If you're reading this in 2015, then firstly congratulations on the world not ending on 21 Dec 2012 and secondly, Urist is apparently VERY lazy. ~Errorage - //Iamgoofball here, this comment I'm typing right now was made in 11/1/2013. If you're reading this in 2020, then please let me know if the world has gone into a nuclear apocalypse. Also Urist has been tried and hung for how lazy he was. That and he was jaywalking. - /*if (selected_glass == 0 && selected_gold == 0 && selected_silver == 0 && selected_diamond == 1 && selected_plasma == 0 && selected_uranium == 1 && selected_iron == 0 && selected_clown == 0) + + /* + + if (selected == ORE_PROC_URANIUM + ORE_PROC_DIAMOND) if (ore_uranium >= 2 && ore_diamond >= 1) ore_uranium -= 2 ore_diamond -= 1 @@ -327,62 +344,64 @@ else on = 0 continue - if (selected_glass == 0 && selected_gold == 0 && selected_silver == 1 && selected_diamond == 0 && selected_plasma == 1 && selected_uranium == 0 && selected_iron == 0 && selected_clown == 0) + if (selected == ORE_PROC_SILVER + ORE_PROC_PLASMA) if (ore_silver >= 1 && ore_plasma >= 3) ore_silver -= 1 ore_plasma -= 3 new /obj/item/stack/sheet/mineral/mythril(output.loc) else on = 0 - continue*/ + continue + + */ //if a non valid combination is selected var/b = 1 //this part checks if all required ores are available - if (!(selected_gold || selected_silver ||selected_diamond || selected_uranium | selected_plasma || selected_iron || selected_iron)) + if (!selected) b = 0 - if (selected_gold == 1) + if (selected & ORE_PROC_GOLD) if (ore_gold <= 0) b = 0 - if (selected_silver == 1) + if (selected & ORE_PROC_SILVER) if (ore_silver <= 0) b = 0 - if (selected_diamond == 1) + if (selected & ORE_PROC_DIAMOND) if (ore_diamond <= 0) b = 0 - if (selected_uranium == 1) + if (selected & ORE_PROC_URANIUM) if (ore_uranium <= 0) b = 0 - if (selected_plasma == 1) + if (selected & ORE_PROC_PLASMA) if (ore_plasma <= 0) b = 0 - if (selected_iron == 1) + if (selected & ORE_PROC_IRON) if (ore_iron <= 0) b = 0 - if (selected_glass == 1) + if (selected & ORE_PROC_GLASS) if (ore_glass <= 0) b = 0 - if (selected_clown == 1) + if (selected & ORE_PROC_CLOWN) if (ore_clown <= 0) b = 0 if (b) //if they are, deduct one from each, produce slag and shut the machine off - if (selected_gold == 1) + if (selected & ORE_PROC_GOLD) ore_gold-- - if (selected_silver == 1) + if (selected & ORE_PROC_SILVER) ore_silver-- - if (selected_diamond == 1) + if (selected & ORE_PROC_DIAMOND) ore_diamond-- - if (selected_uranium == 1) + if (selected & ORE_PROC_URANIUM) ore_uranium-- - if (selected_plasma == 1) + if (selected & ORE_PROC_PLASMA) ore_plasma-- - if (selected_iron == 1) + if (selected & ORE_PROC_IRON) ore_iron-- - if (selected_clown == 1) + if (selected & ORE_PROC_CLOWN) ore_clown-- new /obj/item/weapon/ore/slag(output.loc) on = 0 @@ -399,44 +418,44 @@ if (istype(O,/obj/item/weapon/ore/iron)) ore_iron++; O.loc = null - del(O) + //del(O) continue if (istype(O,/obj/item/weapon/ore/glass)) ore_glass++; O.loc = null - del(O) + //del(O) continue if (istype(O,/obj/item/weapon/ore/diamond)) ore_diamond++; O.loc = null - del(O) + //del(O) continue if (istype(O,/obj/item/weapon/ore/plasma)) ore_plasma++ O.loc = null - del(O) + //del(O) continue if (istype(O,/obj/item/weapon/ore/gold)) ore_gold++ O.loc = null - del(O) + //del(O) continue if (istype(O,/obj/item/weapon/ore/silver)) ore_silver++ O.loc = null - del(O) + //del(O) continue if (istype(O,/obj/item/weapon/ore/uranium)) ore_uranium++ O.loc = null - del(O) + //del(O) continue if (istype(O,/obj/item/weapon/ore/clown)) ore_clown++ O.loc = null - del(O) + //del(O) continue O.loc = src.output.loc else break - return \ No newline at end of file + return diff --git a/code/modules/mining/machine_stacking.dm b/code/modules/mining/machine_stacking.dm index 86f844f623..138a42aaaa 100644 --- a/code/modules/mining/machine_stacking.dm +++ b/code/modules/mining/machine_stacking.dm @@ -242,85 +242,108 @@ /obj/machinery/mineral/stacking_machine/process() if (src.output && src.input) - var/obj/item/O + var/obj/item/stack/O while (locate(/obj/item, input.loc)) - O = locate(/obj/item, input.loc) + O = locate(/obj/item/stack, input.loc) + if(isnull(O)) + var/obj/item/I = locate(/obj/item, input.loc) + if (istype(I,/obj/item/weapon/ore/slag)) + I.loc = null + else + I.loc = output.loc + continue if (istype(O,/obj/item/stack/sheet/metal)) - ore_iron+= O:amount; - del(O) + ore_iron+= O.amount + O.loc = null + //del(O) continue if (istype(O,/obj/item/stack/sheet/mineral/diamond)) - ore_diamond+= O:amount; - del(O) + ore_diamond+= O.amount + O.loc = null + //del(O) continue if (istype(O,/obj/item/stack/sheet/mineral/plasma)) - ore_plasma+= O:amount - del(O) + ore_plasma+= O.amount + O.loc = null + //del(O) continue if (istype(O,/obj/item/stack/sheet/mineral/gold)) - ore_gold+= O:amount - del(O) + ore_gold+= O.amount + O.loc = null + //del(O) continue if (istype(O,/obj/item/stack/sheet/mineral/silver)) - ore_silver+= O:amount - del(O) + ore_silver+= O.amount + O.loc = null + //del(O) continue if (istype(O,/obj/item/stack/sheet/mineral/clown)) - ore_clown+= O:amount - del(O) + ore_clown+= O.amount + O.loc = null + //del(O) continue if (istype(O,/obj/item/stack/sheet/mineral/uranium)) - ore_uranium+= O:amount - del(O) + ore_uranium+= O.amount + O.loc = null + //del(O) continue if (istype(O,/obj/item/stack/sheet/glass/plasmaglass)) - ore_plasmaglass+= O:amount - del(O) + ore_plasmaglass+= O.amount + O.loc = null + //del(O) continue if (istype(O,/obj/item/stack/sheet/glass/plasmarglass)) - ore_plasmarglass+= O:amount - del(O) + ore_plasmarglass+= O.amount + O.loc = null + //del(O) continue if (istype(O,/obj/item/stack/sheet/glass)) - ore_glass+= O:amount - del(O) + ore_glass+= O.amount + O.loc = null + //del(O) continue if (istype(O,/obj/item/stack/sheet/rglass)) - ore_rglass+= O:amount - del(O) + ore_rglass+= O.amount + O.loc = null + //del(O) continue if (istype(O,/obj/item/stack/sheet/plasteel)) - ore_plasteel+= O:amount - del(O) + ore_plasteel+= O.amount + O.loc = null + //del(O) continue if (istype(O,/obj/item/stack/sheet/mineral/adamantine)) - ore_adamantine+= O:amount - del(O) + ore_adamantine+= O.amount + O.loc = null + //del(O) continue if (istype(O,/obj/item/stack/sheet/mineral/mythril)) - ore_mythril+= O:amount - del(O) + ore_mythril+= O.amount + O.loc = null + //del(O) continue if (istype(O,/obj/item/stack/sheet/cardboard)) - ore_cardboard+= O:amount - del(O) + ore_cardboard+= O.amount + O.loc = null + //del(O) continue if (istype(O,/obj/item/stack/sheet/wood)) - ore_wood+= O:amount - del(O) + ore_wood+= O.amount + O.loc = null + //del(O) continue if (istype(O,/obj/item/stack/sheet/cloth)) - ore_cloth+= O:amount - del(O) + ore_cloth+= O.amount + O.loc = null + //del(O) continue if (istype(O,/obj/item/stack/sheet/leather)) - ore_leather+= O:amount - del(O) - continue - if (istype(O,/obj/item/weapon/ore/slag)) - del(O) + ore_leather+= O.amount + O.loc = null + //del(O) continue O.loc = src.output.loc + if (ore_gold >= stack_amt) var/obj/item/stack/sheet/mineral/gold/G = new /obj/item/stack/sheet/mineral/gold G.amount = stack_amt