Replace /proc/num2hex with a much faster macro. (#19600)

This commit is contained in:
warriorstar-orion
2022-11-06 13:11:32 +00:00
committed by GitHub
parent a6b453942e
commit 7867c51b52
6 changed files with 6 additions and 23 deletions
+2
View File
@@ -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))
-17
View File
@@ -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)))
+1 -3
View File
@@ -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
+1 -1
View File
@@ -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 = ""
+1 -1
View File
@@ -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"
@@ -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)