diff --git a/CMakeLists.txt b/CMakeLists.txt index e38764a9..40b37141 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -108,7 +108,7 @@ elseif(EXISTS ${GEODE_PLATFORM_BIN_PATH}) target_precompile_headers(${PROJECT_NAME} INTERFACE "${GEODE_LOADER_PATH}/include/Geode/DefaultInclude.hpp" "${GEODE_LOADER_PATH}/include/Geode/Loader.hpp" - "${GEODE_LOADER_PATH}/include/Geode/Modify.hpp" + # please stop adding modify here its not here because it makes windows compilation take longer than geode 1.0 release date "${GEODE_LOADER_PATH}/include/Geode/UI.hpp" "${GEODE_LOADER_PATH}/include/Geode/cocos/include/cocos2d.h" "${GEODE_LOADER_PATH}/include/Geode/cocos/extensions/cocos-ext.h" diff --git a/loader/include/Geode/ui/Popup.hpp b/loader/include/Geode/ui/Popup.hpp index 42143b05..3f0b7c4d 100644 --- a/loader/include/Geode/ui/Popup.hpp +++ b/loader/include/Geode/ui/Popup.hpp @@ -2,6 +2,7 @@ #include <Geode/binding/CCMenuItemSpriteExtra.hpp> #include <Geode/binding/FLAlertLayer.hpp> +#include <Geode/utils/MiniFunction.hpp> namespace geode { template <typename... InitArgs> @@ -89,11 +90,11 @@ namespace geode { GEODE_DLL FLAlertLayer* createQuickPopup( char const* title, std::string const& content, char const* btn1, char const* btn2, - std::function<void(FLAlertLayer*, bool)> selected, bool doShow = true + utils::MiniFunction<void(FLAlertLayer*, bool)> selected, bool doShow = true ); GEODE_DLL FLAlertLayer* createQuickPopup( char const* title, std::string const& content, char const* btn1, char const* btn2, - float width, std::function<void(FLAlertLayer*, bool)> selected, bool doShow = true + float width, utils::MiniFunction<void(FLAlertLayer*, bool)> selected, bool doShow = true ); } diff --git a/loader/include/Geode/utils/MiniFunction.hpp b/loader/include/Geode/utils/MiniFunction.hpp new file mode 100644 index 00000000..f11f823c --- /dev/null +++ b/loader/include/Geode/utils/MiniFunction.hpp @@ -0,0 +1,86 @@ +#pragma once + +#include <Geode/DefaultInclude.hpp> +#include <memory> + +namespace geode::utils { + + template <class FunctionType> + class MiniFunction; + + template <class Ret, class... Args> + class MiniFunctionStateBase { + public: + virtual ~MiniFunctionStateBase() = default; + virtual Ret call(Args... args) const = 0; + virtual MiniFunctionStateBase* clone() const = 0; + }; + + template <class Type, class Ret, class... Args> + class MiniFunctionState final : public MiniFunctionStateBase<Ret, Args...> { + public: + Type m_func; + + explicit MiniFunctionState(Type func) : m_func(std::move(func)) {} + + Ret call(Args... args) const override { + return const_cast<Type&>(m_func)(args...); + } + + MiniFunctionStateBase<Ret, Args...>* clone() const override { + return new MiniFunctionState(*this); + } + }; + + template <class Ret, class... Args> + class MiniFunction<Ret(Args...)> { + public: + using FunctionType = Ret(Args...); + using StateType = MiniFunctionStateBase<Ret, Args...>; + + private: + StateType* m_state; + + public: + MiniFunction() : m_state(nullptr) {} + + MiniFunction(MiniFunction const& other) : + m_state(other.m_state ? other.m_state->clone() : nullptr) {} + + MiniFunction(MiniFunction&& other) : m_state(other.m_state) { + other.m_state = nullptr; + } + + ~MiniFunction() { + delete m_state; + } + + template <class Callable> + requires requires(Callable&& func, Args... args) { + { func(args...) } -> std::same_as<Ret>; + } + MiniFunction(Callable&& func) : + m_state(new MiniFunctionState<std::decay_t<Callable>, Ret, Args...>(std::forward<Callable>(func))) {} + + MiniFunction& operator=(MiniFunction const& other) { + delete m_state; + m_state = other.m_state ? other.m_state->clone() : nullptr; + return *this; + } + + MiniFunction& operator=(MiniFunction&& other) { + delete m_state; + m_state = other.m_state; + other.m_state = nullptr; + return *this; + } + + Ret operator()(Args... args) const { + return m_state->call(args...); + } + + explicit operator bool() const { + return m_state; + } + }; +} \ No newline at end of file diff --git a/loader/launcher/mac/CMakeLists.txt b/loader/launcher/mac/CMakeLists.txt index cb7e599a..77c5c678 100644 --- a/loader/launcher/mac/CMakeLists.txt +++ b/loader/launcher/mac/CMakeLists.txt @@ -2,6 +2,7 @@ cmake_minimum_required(VERSION 3.3.0) add_library(Bootstrapper SHARED Bootstrapper.cpp) +target_compile_features(Bootstrapper PUBLIC cxx_std_17) set_target_properties(Bootstrapper PROPERTIES PREFIX "" OUTPUT_NAME "GeodeBootstrapper" diff --git a/loader/launcher/windows/CMakeLists.txt b/loader/launcher/windows/CMakeLists.txt index 8f46543d..c6cf7a7d 100644 --- a/loader/launcher/windows/CMakeLists.txt +++ b/loader/launcher/windows/CMakeLists.txt @@ -1,6 +1,7 @@ cmake_minimum_required(VERSION 3.3.0) add_library(ProxyLoader SHARED proxyLoader.c) +target_compile_features(ProxyLoader PUBLIC cxx_std_17) set_target_properties(ProxyLoader PROPERTIES PREFIX "" OUTPUT_NAME "XInput9_1_0" @@ -21,6 +22,7 @@ set_target_properties(ProxyLoader PROPERTIES ) add_library(Bootstrapper SHARED Bootstrapper.cpp) +target_compile_features(Bootstrapper PUBLIC cxx_std_17) set_target_properties(Bootstrapper PROPERTIES PREFIX "" OUTPUT_NAME "GeodeBootstrapper" diff --git a/loader/src/ui/internal/settings/GeodeSettingNode.hpp b/loader/src/ui/internal/settings/GeodeSettingNode.hpp index 0b5bc499..76abd0c1 100644 --- a/loader/src/ui/internal/settings/GeodeSettingNode.hpp +++ b/loader/src/ui/internal/settings/GeodeSettingNode.hpp @@ -136,7 +136,7 @@ namespace { "Are you sure you want to <cr>reset</c> <cl>" + setting->getDisplayName() + "</c> to <cy>default</c>?", "Cancel", "Reset", - [this](auto, bool btn2) { + [this](FLAlertLayer*, bool btn2) { if (btn2) this->resetToDefault(); } ); diff --git a/loader/src/ui/nodes/Popup.cpp b/loader/src/ui/nodes/Popup.cpp index 29abc800..08717a74 100644 --- a/loader/src/ui/nodes/Popup.cpp +++ b/loader/src/ui/nodes/Popup.cpp @@ -4,7 +4,7 @@ USE_GEODE_NAMESPACE(); class QuickPopup : public FLAlertLayer, public FLAlertLayerProtocol { protected: - std::function<void(FLAlertLayer*, bool)> m_selected; + MiniFunction<void(FLAlertLayer*, bool)> m_selected; void FLAlert_Clicked(FLAlertLayer* layer, bool btn2) override { if (m_selected) { @@ -15,7 +15,7 @@ protected: public: static QuickPopup* create( char const* title, std::string const& content, char const* btn1, char const* btn2, - float width, std::function<void(FLAlertLayer*, bool)> selected + float width, MiniFunction<void(FLAlertLayer*, bool)> selected ) { auto inst = new QuickPopup; inst->m_selected = selected; @@ -30,7 +30,7 @@ public: FLAlertLayer* geode::createQuickPopup( char const* title, std::string const& content, char const* btn1, char const* btn2, float width, - std::function<void(FLAlertLayer*, bool)> selected, bool doShow + MiniFunction<void(FLAlertLayer*, bool)> selected, bool doShow ) { auto ret = QuickPopup::create(title, content, btn1, btn2, width, selected); if (doShow) { @@ -41,7 +41,7 @@ FLAlertLayer* geode::createQuickPopup( FLAlertLayer* geode::createQuickPopup( char const* title, std::string const& content, char const* btn1, char const* btn2, - std::function<void(FLAlertLayer*, bool)> selected, bool doShow + MiniFunction<void(FLAlertLayer*, bool)> selected, bool doShow ) { return createQuickPopup(title, content, btn1, btn2, 350.f, selected, doShow); }