Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion library/include/DataIdentity.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,10 @@ distribution.
#include <optional>
#include <string>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <variant>
#include <vector>
#include <variant>
#include <filesystem>

#include "DataDefs.h"
Expand Down Expand Up @@ -748,6 +749,11 @@ namespace df
static const container_identity *get();
};

template<class T> struct identity_traits<std::unordered_set<T> >
{
static const container_identity* get();
};

template<> struct identity_traits<BitArray<int> > {
static const bit_array_identity identity;
static const bit_container_identity *get() { return &identity; }
Expand Down Expand Up @@ -831,6 +837,14 @@ namespace df
return &identity;
}

template<class T>
inline const container_identity* identity_traits<std::unordered_set<T> >::get()
{
using container = std::set<T>;
static const ro_stl_container_identity<container> identity("unordered_set", identity_traits<T>::get());
return &identity;
}

template<class KT, class T>
inline const container_identity *identity_traits<std::map<KT, T>>::get() {
using container = std::map<KT, T>;
Expand Down
34 changes: 34 additions & 0 deletions library/include/df/custom/hash/texture_fullid.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#pragma once

#include <functional>
#include <bit>
#include "df/texture_fullid.h"

template<>
struct std::hash<df::texture_fullid>
{
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<int>{}(t.texpos);
auto u_hash=std::hash<uint64_t>{};
h^=u_hash(std::bit_cast<uint64_t>(std::make_pair(t.r, t.g)));
h^=u_hash(std::bit_cast<uint64_t>(std::make_pair(t.b, t.br)))<<1;
h^=u_hash(std::bit_cast<uint64_t>(std::make_pair(t.bg, t.bb)))<<2;
h^=std::hash<uint32_t>{}(t.flag.whole);
return h;
#else
size_t h=std::hash<float>{}(t.texpos);
auto u_hash=std::hash<uint64_t>{};
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<uint32_t>{}(t.flag.whole)<<6;
return h;
#endif
}
};
24 changes: 24 additions & 0 deletions library/include/df/custom/texture_fullid.methods.inc
Original file line number Diff line number Diff line change
@@ -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;
}
7 changes: 3 additions & 4 deletions library/modules/Gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<void *, void *> & orig_field = container->children_by_name;
auto children_by_name = reinterpret_cast<std::map<std::string, std::shared_ptr<df::widget>> *>(&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;
}

Expand Down