mirror of
https://github.com/geode-sdk/geode.git
synced 2024-11-26 17:36:05 -05:00
fix CCCallFuncExt
This commit is contained in:
parent
302eea1f47
commit
b9fb2f6778
1 changed files with 12 additions and 5 deletions
|
@ -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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue