diff --git a/library/include/DataIdentity.h b/library/include/DataIdentity.h index 8a9e3c406b..ed4ca06ecd 100644 --- a/library/include/DataIdentity.h +++ b/library/include/DataIdentity.h @@ -29,9 +29,10 @@ distribution. #include #include #include +#include +#include #include #include -#include #include #include "DataDefs.h" @@ -748,6 +749,11 @@ namespace df static const container_identity *get(); }; + template struct identity_traits > + { + static const container_identity* get(); + }; + template<> struct identity_traits > { static const bit_array_identity identity; static const bit_container_identity *get() { return &identity; } @@ -831,6 +837,14 @@ namespace df return &identity; } + template + inline const container_identity* identity_traits >::get() + { + using container = std::set; + static const ro_stl_container_identity identity("unordered_set", identity_traits::get()); + return &identity; + } + template inline const container_identity *identity_traits>::get() { using container = std::map; diff --git a/library/include/df/custom/hash/texture_fullid.h b/library/include/df/custom/hash/texture_fullid.h new file mode 100644 index 0000000000..a1e4606e33 --- /dev/null +++ b/library/include/df/custom/hash/texture_fullid.h @@ -0,0 +1,34 @@ +#pragma once + +#include +#include +#include "df/texture_fullid.h" + +template<> +struct std::hash +{ + size_t operator()(df::texture_fullid const &t) const noexcept + { +// for some reason, bay12 used different hash methods on windows vs linux +#ifdef WIN32 + size_t h=std::hash{}(t.texpos); + auto u_hash=std::hash{}; + h^=u_hash(std::bit_cast(std::make_pair(t.r, t.g))); + h^=u_hash(std::bit_cast(std::make_pair(t.b, t.br)))<<1; + h^=u_hash(std::bit_cast(std::make_pair(t.bg, t.bb)))<<2; + h^=std::hash{}(t.flag.whole); + return h; +#else + size_t h=std::hash{}(t.texpos); + auto u_hash=std::hash{}; + h^=u_hash(t.r); + h^=u_hash(t.g)<<1; + h^=u_hash(t.b)<<2; + h^=u_hash(t.br)<<3; + h^=u_hash(t.bg)<<4; + h^=u_hash(t.bb)<<5; + h^=std::hash{}(t.flag.whole)<<6; + return h; +#endif + } +}; diff --git a/library/include/df/custom/texture_fullid.methods.inc b/library/include/df/custom/texture_fullid.methods.inc new file mode 100644 index 0000000000..12e21f6735 --- /dev/null +++ b/library/include/df/custom/texture_fullid.methods.inc @@ -0,0 +1,24 @@ +auto operator== (const texture_fullid &other) const { + return ( + this->texpos == other.texpos && + this->r == other.r && + this->g == other.g && + this->b == other.b && + this->br == other.br && + this->bg == other.bg && + this->bb == other.bb && + this->flag.whole == other.flag.whole + ); +} + +auto operator< (const texture_fullid &other) const { + if (this->texpos < other.texpos) return true; + if (this->r < other.r) return true; + if (this->g < other.g) return true; + if (this->b < other.b) return true; + if (this->br < other.br) return true; + if (this->bg < other.bg) return true; + if (this->bb < other.bb) return true; + if (this->flag.whole < other.flag.whole) return true; + return false; +} diff --git a/library/modules/Gui.cpp b/library/modules/Gui.cpp index 1e079da598..fae55ce9d7 100644 --- a/library/modules/Gui.cpp +++ b/library/modules/Gui.cpp @@ -2686,10 +2686,9 @@ void Gui::MTB_set_width(df::markup_text_boxst *mtb, int32_t n_width) df::widget * Gui::getWidget(df::widget_container *container, string name) { CHECK_NULL_POINTER(container); // ensure the compiler catches the change if we ever fix the template parameters - std::map & orig_field = container->children_by_name; - auto children_by_name = reinterpret_cast> *>(&orig_field); - if (children_by_name->contains(name)) - return (*children_by_name)[name].get(); + auto & children_by_name = container->children_by_name; + if (children_by_name.contains(name)) + return (children_by_name)[name].get(); return NULL; } diff --git a/library/xml b/library/xml index 48077a042d..00e1c5ea00 160000 --- a/library/xml +++ b/library/xml @@ -1 +1 @@ -Subproject commit 48077a042dff14de22d682de3afc6d9157203c81 +Subproject commit 00e1c5ea0071b716afad5a4140dc43e0ed7a8fbb