mirror of https://github.com/dnomd343/klotski.git
Dnomd343
9 months ago
2 changed files with 54 additions and 43 deletions
@ -1,73 +1,85 @@ |
|||||
#include "klotski.h" |
#include "klotski.h" |
||||
#include "all_cases.h" |
#include "all_cases/all_cases.h" |
||||
|
|
||||
using klotski::cases::AllCases; |
using klotski::cases::AllCases; |
||||
using klotski::cases::BasicRanges; |
using klotski::cases::BasicRanges; |
||||
using klotski::cases::ALL_CASES_NUM; |
using klotski::cases::ALL_CASES_NUM; |
||||
|
|
||||
|
typedef std::function<void()> Runner; |
||||
|
|
||||
|
// ------------------------------------------------------------------------------------- //
|
||||
|
|
||||
void all_cases_prebuild() { |
void all_cases_prebuild() { |
||||
BasicRanges::instance().build(); |
BasicRanges::instance().build(); |
||||
} |
} |
||||
|
|
||||
void all_cases_prebuild_async(executor_t executor, notifier_t callback) { |
void all_cases_prebuild_async(const executor_t executor, const notifier_t callback) { |
||||
executor([](void *fn) { |
const auto func = [](void *arg) { |
||||
all_cases_prebuild(); |
all_cases_prebuild(); |
||||
((notifier_t)fn)(); |
reinterpret_cast<notifier_t>(arg)(); |
||||
}, (void*)callback); |
}; |
||||
|
executor(func, reinterpret_cast<void*>(callback)); |
||||
} |
} |
||||
|
|
||||
int all_cases_prebuild_available() { |
int all_cases_prebuild_available() { |
||||
return BasicRanges::instance().is_available() ? KLOTSKI_TRUE : KLOTSKI_FALSE; |
return BasicRanges::instance().is_available() ? KLSK_TRUE : KLSK_FALSE; |
||||
} |
} |
||||
|
|
||||
|
// ------------------------------------------------------------------------------------- //
|
||||
|
|
||||
void all_cases_build() { |
void all_cases_build() { |
||||
AllCases::instance().build(); |
AllCases::instance().build(); |
||||
} |
} |
||||
|
|
||||
void all_cases_build_async(executor_t executor, notifier_t callback) { |
void all_cases_build_async(const executor_t executor, const notifier_t callback) { |
||||
executor([](void *fn) { |
const auto func = [](void *arg) { |
||||
all_cases_build(); |
all_cases_build(); |
||||
((notifier_t)fn)(); |
reinterpret_cast<notifier_t>(arg)(); |
||||
}, (void*)callback); |
}; |
||||
|
executor(func, reinterpret_cast<void*>(callback)); |
||||
} |
} |
||||
|
|
||||
void all_cases_build_parallel(executor_t executor) { |
void all_cases_build_parallel(executor_t executor) { |
||||
typedef std::function<void()> Runner; |
|
||||
AllCases::instance().build_parallel([executor](Runner &&runner) { |
AllCases::instance().build_parallel([executor](Runner &&runner) { |
||||
executor([](void *fn) { |
const auto func = [](void *arg) { |
||||
(*(Runner*)fn)(); |
(*static_cast<Runner*>(arg))(); |
||||
delete (Runner*)fn; |
delete static_cast<Runner*>(arg); |
||||
}, (void*)new Runner{std::move(runner)}); |
}; |
||||
|
executor(func, new Runner {std::move(runner)}); |
||||
}); |
}); |
||||
} |
} |
||||
|
|
||||
void all_cases_build_parallel_async(executor_t executor, notifier_t callback) { |
void all_cases_build_parallel_async(executor_t executor, notifier_t callback) { |
||||
typedef std::function<void()> Runner; |
auto all_done = [callback] { |
||||
auto all_done = [callback]() { |
|
||||
callback(); |
callback(); |
||||
}; |
}; |
||||
AllCases::instance().build_parallel_async([executor](Runner &&runner) { |
AllCases::instance().build_parallel_async([executor](Runner &&runner) { |
||||
executor([](void *fn) { |
const auto func = [](void *arg) { |
||||
(*(Runner*)fn)(); |
(*static_cast<Runner*>(arg))(); |
||||
delete (Runner*)fn; |
delete static_cast<Runner*>(arg); |
||||
}, (void*)new Runner{std::move(runner)}); |
}; |
||||
|
executor(func, new Runner {std::move(runner)}); |
||||
}, std::move(all_done)); |
}, std::move(all_done)); |
||||
} |
} |
||||
|
|
||||
int all_cases_available() { |
int all_cases_available() { |
||||
return AllCases::instance().is_available() ? KLOTSKI_TRUE : KLOTSKI_FALSE; |
return AllCases::instance().is_available() ? KLSK_TRUE : KLSK_FALSE; |
||||
} |
} |
||||
|
|
||||
int all_cases_num(int head) { |
// ------------------------------------------------------------------------------------- //
|
||||
if (head < 0 || head >= (int)ALL_CASES_NUM.size()) { |
|
||||
|
int all_cases_num(const int head) { |
||||
|
if (head < 0 || head >= static_cast<int>(ALL_CASES_NUM.size())) { |
||||
return -1; |
return -1; |
||||
} |
} |
||||
return ALL_CASES_NUM[head]; |
return ALL_CASES_NUM[head]; |
||||
} |
} |
||||
|
|
||||
const klotski_u32* all_cases_export(int head) { |
const uint32_t* all_cases_export(const int head) { |
||||
if (all_cases_num(head) < 0) { |
if (all_cases_num(head) < 0) { |
||||
return nullptr; |
return nullptr; |
||||
} |
} |
||||
return AllCases::instance().fetch()[head].data(); |
return AllCases::instance().fetch()[head].data(); |
||||
} |
} |
||||
|
|
||||
|
// ------------------------------------------------------------------------------------- //
|
||||
|
Loading…
Reference in new issue