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
2 changes: 1 addition & 1 deletion library/include/DataIdentity.h
Original file line number Diff line number Diff line change
Expand Up @@ -840,7 +840,7 @@ namespace df
template<class T>
inline const container_identity* identity_traits<std::unordered_set<T> >::get()
{
using container = std::set<T>;
using container = std::unordered_set<T>;
static const ro_stl_container_identity<container> identity("unordered_set", identity_traits<T>::get());
return &identity;
}
Expand Down
20 changes: 11 additions & 9 deletions plugins/sort.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#include <variant>

#include "Debug.h"
#include "LuaTools.h"
#include "PluginManager.h"
Expand Down Expand Up @@ -25,7 +27,7 @@ namespace DFHack {
DBG_DECLARE(sort, log, DebugCategory::LINFO);
}

using item_or_unit = std::pair<void *, bool>;
using item_or_unit = std::variant<df::unit*, df::item*>;
using filter_vec_type = std::vector<std::function<bool(item_or_unit)>>;

// recreated here since our autogenerated df::sort_entry lacks template params
Expand All @@ -44,8 +46,8 @@ static bool probing = false;
static bool probe_result = false;

static bool do_filter(const char *module_name, const char *fn_name, const item_or_unit &elem) {
if (elem.second) return true;
auto unit = (df::unit *)elem.first;
if (std::holds_alternative<df::item*>(elem)) return true;
auto unit = std::get<df::unit*>(elem);

if (probing) {
TRACE(log).print("probe successful\n");
Expand Down Expand Up @@ -78,11 +80,11 @@ static bool do_work_animal_assignment_filter(item_or_unit elem) {

static int32_t our_filter_idx(df::widget_unit_list *unitlist) {
if (world->units.active.empty())
return true;
return -1;

df::unit *u = world->units.active[0]; // any unit will do; we just need a sentinel
if (!u)
return true;
return -1;

probing = true;
probe_result = false;
Expand All @@ -91,8 +93,8 @@ static int32_t our_filter_idx(df::widget_unit_list *unitlist) {
filter_vec_type *filter_vec = reinterpret_cast<filter_vec_type *>(&unitlist->filter_func);

TRACE(log).print("probing for our filter function\n");
for (auto fn : *filter_vec) {
fn(std::make_pair(u, false));
for (auto& fn : *filter_vec) {
fn(item_or_unit(u));
if (probe_result) {
TRACE(log).print("found our filter function at idx %d\n", idx);
break;
Expand Down Expand Up @@ -144,13 +146,13 @@ static df::widget_unit_list * get_work_animal_assignment_unit_list() {
//

static bool sort_proxy(const item_or_unit &a, const item_or_unit &b) {
if (a.second || b.second)
if (std::holds_alternative<df::item*>(a) || std::holds_alternative<df::item*>(b))
return true;

bool ret = true;
color_ostream &out = Core::getInstance().getConsole();
Lua::CallLuaModuleFunction(out, "plugins.sort", "do_sort",
std::make_tuple((df::unit *)a.first, (df::unit *)b.first),
std::make_tuple(std::get<df::unit*>(a), std::get<df::unit*>(b)),
1, [&](lua_State *L){
ret = lua_toboolean(L, 1);
}
Expand Down