From 7867c51b529bef7946db43987d1aff2c0412bc85 Mon Sep 17 00:00:00 2001 From: warriorstar-orion Date: Sun, 6 Nov 2022 08:11:32 -0500 Subject: [PATCH] Replace /proc/num2hex with a much faster macro. (#19600) --- code/__DEFINES/_math.dm | 2 ++ code/__HELPERS/type2type.dm | 17 ----------------- code/__HELPERS/unsorted.dm | 4 +--- code/game/dna/dna2.dm | 2 +- code/game/machinery/computer/security.dm | 2 +- .../modules/reagents/chemistry/reagents/misc.dm | 2 +- 6 files changed, 6 insertions(+), 23 deletions(-) diff --git a/code/__DEFINES/_math.dm b/code/__DEFINES/_math.dm index 5d50f613a76..d7b0946c614 100644 --- a/code/__DEFINES/_math.dm +++ b/code/__DEFINES/_math.dm @@ -242,3 +242,5 @@ // Gives you the percent of two inputs #define PERCENT_OF(val1, val2) (val1 * (val2 / 100)) + +#define num2hex(X, len) uppertext(num2text(X, len, 16)) diff --git a/code/__HELPERS/type2type.dm b/code/__HELPERS/type2type.dm index 410cbf6ba25..b38ac58526a 100644 --- a/code/__HELPERS/type2type.dm +++ b/code/__HELPERS/type2type.dm @@ -42,23 +42,6 @@ i-- return num -//Returns the hex value of a number given a value assumed to be a base-ten value -/proc/num2hex(num, placeholder = 2) - if(!isnum(num) || num < 0) - return - - var/hex = "" - while(num) - var/val = num % 16 - num = round(num / 16) - - if(val > 9) - val = ascii2text(55 + val) // 65 - 70 correspond to "A" - "F" - hex = "[val][hex]" - while(length(hex) < placeholder) - hex = "0[hex]" - return hex || "0" - //Returns an integer value for R of R/G/B given a hex color input. /proc/color2R(hex) if(!(istext(hex))) diff --git a/code/__HELPERS/unsorted.dm b/code/__HELPERS/unsorted.dm index 51d3ac6660c..c00155a93b1 100644 --- a/code/__HELPERS/unsorted.dm +++ b/code/__HELPERS/unsorted.dm @@ -1378,9 +1378,7 @@ Standard way to write links -Sayu colour = pick(list("FF0000","FF7F00","FFFF00","00FF00","0000FF","4B0082","8F00FF")) else for(var/i=1;i<=3;i++) - var/temp_col = "[num2hex(rand(lower,upper))]" - if(length(temp_col )<2) - temp_col = "0[temp_col]" + var/temp_col = "[num2hex(rand(lower,upper), 2)]" colour += temp_col return colour diff --git a/code/game/dna/dna2.dm b/code/game/dna/dna2.dm index 2a0f8ef06a7..81105a4c2a9 100644 --- a/code/game/dna/dna2.dm +++ b/code/game/dna/dna2.dm @@ -363,7 +363,7 @@ GLOBAL_LIST_EMPTY(bad_blocks) /proc/EncodeDNABlock(value) - return add_zero2(num2hex(value, 1), 3) + return num2hex(value, 3) /datum/dna/proc/UpdateUI() uni_identity = "" diff --git a/code/game/machinery/computer/security.dm b/code/game/machinery/computer/security.dm index 692c10d9706..de32b985944 100644 --- a/code/game/machinery/computer/security.dm +++ b/code/game/machinery/computer/security.dm @@ -189,7 +189,7 @@ return var/datum/data/record/G = new /datum/data/record() G.fields["name"] = "New Record" - G.fields["id"] = "[add_zero(num2hex(rand(1, 1.6777215E7)), 6)]" + G.fields["id"] = "[num2hex(rand(1, 1.6777215E7), 6)]" G.fields["rank"] = "Unassigned" G.fields["real_rank"] = "Unassigned" G.fields["sex"] = "Male" diff --git a/code/modules/reagents/chemistry/reagents/misc.dm b/code/modules/reagents/chemistry/reagents/misc.dm index 0753ad8faa8..dfc1723315f 100644 --- a/code/modules/reagents/chemistry/reagents/misc.dm +++ b/code/modules/reagents/chemistry/reagents/misc.dm @@ -329,7 +329,7 @@ if(ishuman(M)) var/mob/living/carbon/human/H = M if(!(NO_BLOOD in H.dna.species.species_traits) && !H.dna.species.exotic_blood) - H.dna.species.blood_color = "#[num2hex(rand(0, 255))][num2hex(rand(0, 255))][num2hex(rand(0, 255))]" + H.dna.species.blood_color = "#[num2hex(rand(0, 255), 2)][num2hex(rand(0, 255), 2)][num2hex(rand(0, 255), 2)]" return ..() /datum/reagent/colorful_reagent/reaction_mob(mob/living/simple_animal/M, method=REAGENT_TOUCH, volume)