Files
Aurora.3/code/modules/client/preference_setup/skills/skills.dm
skull132 a3ec0cf45d Better SQL prepared statements (#2474)
The system used to be of complexity O(n^2). Essentially two for loops running per every argument. Which ended up being surprisingly slow (there were instances where I saw the argument parser as using quite a lot of CPU time).

This replaces it with a more linear algorithm. It's somewhere near O(n) where n is the length of the unparsed query. Which is more stable and faaaster. This comes with two changes, however:

Parameters inside the query now have to be delimited from both sides with : (colons). The alternative to this would be to use something like $n or just assume that space marks the end of a marker. Only the former is workable, the latter would break a few queries already.
Arguments in the argument array no longer have to be prefixed by : (colons). So, while in the query you would write :thing:, you'd initialize the array of args as: list("thing" = somevar). It could be made to work without it, but eh, I think this is fine.
Argument validation is slightly weaker. What I mean by this is that with the old system, unused keys would result in an error. This is no longer a thing. Missing keys will still result in an error, however.
One more improvement: double delimiting removes an edge case where if key A partially covers key B, depending on the order, key A would mangle key B.
Updated and tested all queries that I could find. So this should be good.
2017-05-29 21:17:41 +03:00

104 lines
4.2 KiB
Plaintext

/datum/category_item/player_setup_item/skills
name = "Skills"
sort_order = 1
/datum/category_item/player_setup_item/skills/load_character(var/savefile/S)
S["skills"] >> pref.skills
S["used_skillpoints"] >> pref.used_skillpoints
S["skill_specialization"] >> pref.skill_specialization
/datum/category_item/player_setup_item/skills/save_character(var/savefile/S)
S["skills"] << pref.skills
S["used_skillpoints"] << pref.used_skillpoints
S["skill_specialization"] << pref.skill_specialization
/datum/category_item/player_setup_item/skills/gather_load_query()
return list("ss13_characters" = list("vars" = list("skills", "skill_specialization"), "args" = list("id")))
/datum/category_item/player_setup_item/skills/gather_load_parameters()
return list("id" = pref.current_character)
/datum/category_item/player_setup_item/skills/gather_save_query()
return list("ss13_characters" = list("skills", "skill_specialization", "id" = 1, "ckey" = 1))
/datum/category_item/player_setup_item/skills/gather_save_parameters()
return list("skills" = list2params(pref.skills), "skill_specialization" = pref.skill_specialization, "id" = pref.current_character, "ckey" = pref.client.ckey)
/datum/category_item/player_setup_item/skills/sanitize_character(var/sql_load = 0)
if (SKILLS == null)
setup_skills()
if (!pref.skills)
pref.skills = list()
if (sql_load)
pref.skills = params2list(pref.skills)
if (!pref.skills || !islist(pref.skills) || !pref.skills.len)
pref.ZeroSkills()
else
for (var/skill in pref.skills)
pref.skills[skill] = text2num(pref.skills[skill])
pref.CalculateSkillPoints()
if (!pref.skills.len)
pref.ZeroSkills()
if (pref.used_skillpoints < 0)
pref.used_skillpoints = 0
/datum/category_item/player_setup_item/skills/content()
. += "<b>Select your Skills</b><br>"
. += "Current skill level: <b>[pref.GetSkillClass(pref.used_skillpoints)]</b> ([pref.used_skillpoints])<br>"
. += "<a href='?src=\ref[src];preconfigured=1'>Use preconfigured skillset</a><br>"
. += "<table>"
for(var/V in SKILLS)
. += "<tr><th colspan = 5><b>[V]</b>"
. += "</th></tr>"
for(var/datum/skill/S in SKILLS[V])
var/level = pref.skills[S.ID]
. += "<tr style='text-align:left;'>"
. += "<th><a href='?src=\ref[src];skillinfo=\ref[S]'>[S.name]</a></th>"
. += "<th><a href='?src=\ref[src];setskill=\ref[S];newvalue=[SKILL_NONE]'><font color=[(level == SKILL_NONE) ? "red" : "black"]>\[Untrained\]</font></a></th>"
// secondary skills don't have an amateur level
if(S.secondary)
. += "<th></th>"
else
. += "<th><a href='?src=\ref[src];setskill=\ref[S];newvalue=[SKILL_BASIC]'><font color=[(level == SKILL_BASIC) ? "red" : "black"]>\[Amateur\]</font></a></th>"
. += "<th><a href='?src=\ref[src];setskill=\ref[S];newvalue=[SKILL_ADEPT]'><font color=[(level == SKILL_ADEPT) ? "red" : "black"]>\[Trained\]</font></a></th>"
. += "<th><a href='?src=\ref[src];setskill=\ref[S];newvalue=[SKILL_EXPERT]'><font color=[(level == SKILL_EXPERT) ? "red" : "black"]>\[Professional\]</font></a></th>"
. += "</tr>"
. += "</table>"
/datum/category_item/player_setup_item/skills/OnTopic(href, href_list, user)
if(href_list["skillinfo"])
var/datum/skill/S = locate(href_list["skillinfo"])
var/HTML = "<b>[S.name]</b><br>[S.desc]"
user << browse(HTML, "window=\ref[user]skillinfo")
return TOPIC_HANDLED
else if(href_list["setskill"])
var/datum/skill/S = locate(href_list["setskill"])
var/value = text2num(href_list["newvalue"])
pref.skills[S.ID] = value
pref.CalculateSkillPoints()
return TOPIC_REFRESH
else if(href_list["preconfigured"])
var/selected = input(user, "Select a skillset", "Skillset") as null|anything in SKILL_PRE
if(!selected && !CanUseTopic(user)) return
pref.ZeroSkills(1)
for(var/V in SKILL_PRE[selected])
if(V == "field")
pref.skill_specialization = SKILL_PRE[selected]["field"]
continue
pref.skills[V] = SKILL_PRE[selected][V]
pref.CalculateSkillPoints()
return TOPIC_REFRESH
else if(href_list["setspecialization"])
pref.skill_specialization = href_list["setspecialization"]
pref.CalculateSkillPoints()
return TOPIC_REFRESH
return ..()