fix CCCallFuncExt

This commit is contained in:
HJfod 2024-11-16 18:36:34 +02:00
parent 302eea1f47
commit b9fb2f6778

View file

@ -1331,15 +1331,13 @@ namespace geode::cocos {
class CallFuncExtImpl : public cocos2d::CCActionInstant { class CallFuncExtImpl : public cocos2d::CCActionInstant {
public: public:
static CallFuncExtImpl* create(const F& func) { static CallFuncExtImpl* create(const F& func) {
auto ret = new CallFuncExtImpl; auto ret = new CallFuncExtImpl(func);
ret->m_func = func;
ret->autorelease(); ret->autorelease();
return ret; return ret;
} }
static CallFuncExtImpl* create(F&& func) { static CallFuncExtImpl* create(F&& func) {
auto ret = new CallFuncExtImpl; auto ret = new CallFuncExtImpl(std::move(func));
ret->m_func = std::move(func);
ret->autorelease(); ret->autorelease();
return ret; return ret;
} }
@ -1347,8 +1345,17 @@ namespace geode::cocos {
private: private:
F m_func; F m_func;
// F may not be default-constructible
CallFuncExtImpl(F&& func) : m_func(std::move(func)) {}
CallFuncExtImpl(F const& func) : m_func(func) {}
void update(float) override { void update(float) override {
if (m_func) this->m_func(); // Make sure any `std::function`s are valid
if constexpr (requires { static_cast<bool>(m_func); }) {
if (m_func) m_func();
} else {
m_func();
}
} }
}; };