mirror of
https://github.com/geode-sdk/geode.git
synced 2024-11-22 23:48:08 -05:00
tryna fix crash due to events
This commit is contained in:
parent
956ad1d6d5
commit
b4b9986fa5
6 changed files with 27 additions and 30 deletions
|
@ -59,8 +59,10 @@ namespace geode {
|
|||
using MemberFn = typename to_member<C, Callback>::value;
|
||||
|
||||
ListenerResult passThrough(Event* e) override {
|
||||
if (auto myev = dynamic_cast<typename T::Event*>(e)) {
|
||||
return m_filter.handle(m_callback, myev);
|
||||
if (m_callback) {
|
||||
if (auto myev = typeinfo_cast<typename T::Event*>(e)) {
|
||||
return m_filter.handle(m_callback, myev);
|
||||
}
|
||||
}
|
||||
return ListenerResult::Propagate;
|
||||
}
|
||||
|
@ -81,14 +83,16 @@ namespace geode {
|
|||
}
|
||||
|
||||
void bind(std::function<Callback> fn) {
|
||||
std::cout << "this: " << this << "\n";
|
||||
m_callback = fn;
|
||||
}
|
||||
template <typename C>
|
||||
void bind(C* cls, MemberFn<C> fn) {
|
||||
std::cout << "this: " << this << "\n";
|
||||
m_callback = std::bind(fn, cls, std::placeholders::_1);
|
||||
}
|
||||
protected:
|
||||
std::function<Callback> m_callback;
|
||||
std::function<Callback> m_callback = nullptr;
|
||||
T m_filter;
|
||||
};
|
||||
|
||||
|
|
|
@ -47,7 +47,7 @@ namespace { \
|
|||
} \
|
||||
static inline auto GEODE_CONCAT(Exec, __LINE__) = (geode::Loader::get()->scheduleOnModLoad(\
|
||||
geode::Mod::get(), []() { \
|
||||
static auto _ = geode::EventListener( \
|
||||
new geode::EventListener( \
|
||||
&GEODE_CONCAT(geodeExecFunction, __LINE__)<GEODE_CONCAT(ExecFuncUnique, __LINE__)>,\
|
||||
geode::ModStateFilter(geode::Mod::get(), geode::ModEventType::type)\
|
||||
); \
|
||||
|
|
|
@ -11,19 +11,14 @@ namespace geode {
|
|||
concept InheritsCCNode = std::is_base_of_v<cocos2d::CCNode, T>;
|
||||
|
||||
// Base class; exists so event listeners can be placed dynamically at runtime
|
||||
class GEODE_DLL AEnterLayerEvent : public Event {
|
||||
protected:
|
||||
std::string m_layerID;
|
||||
cocos2d::CCNode* m_layer;
|
||||
struct GEODE_DLL AEnterLayerEvent : public Event {
|
||||
const std::string layerID;
|
||||
cocos2d::CCNode* layer;
|
||||
|
||||
public:
|
||||
AEnterLayerEvent(
|
||||
std::string const& layerID,
|
||||
cocos2d::CCNode* layer
|
||||
);
|
||||
|
||||
std::string getID() const;
|
||||
cocos2d::CCNode* getLayer() const;
|
||||
};
|
||||
|
||||
class GEODE_DLL AEnterLayerFilter : public EventFilter<AEnterLayerEvent> {
|
||||
|
@ -50,7 +45,7 @@ namespace geode {
|
|||
) : AEnterLayerEvent(layerID, layer) {}
|
||||
|
||||
T* getLayer() const {
|
||||
return static_cast<T*>(m_layer);
|
||||
return static_cast<T*>(this->layer);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -28,10 +28,9 @@ struct CustomLoadingLayer : Modify<CustomLoadingLayer, LoadingLayer> {
|
|||
label->setID("geode-loaded-info");
|
||||
this->addChild(label);
|
||||
|
||||
m_fields->m_resourceListener.bind(std::bind(
|
||||
&CustomLoadingLayer::updateResourcesProgress,
|
||||
this, std::placeholders::_1
|
||||
));
|
||||
m_fields->m_resourceListener.bind(
|
||||
this, &CustomLoadingLayer::updateResourcesProgress
|
||||
);
|
||||
|
||||
// verify loader resources
|
||||
if (!InternalLoader::get()->verifyLoaderResources()) {
|
||||
|
|
|
@ -5,10 +5,12 @@ USE_GEODE_NAMESPACE();
|
|||
std::unordered_set<EventListenerProtocol*> Event::s_listeners = {};
|
||||
|
||||
void EventListenerProtocol::enable() {
|
||||
std::cout << "enable " << this << ": " << typeid(*this).name() << "\n";
|
||||
Event::s_listeners.insert(this);
|
||||
}
|
||||
|
||||
void EventListenerProtocol::disable() {
|
||||
std::cout << "disable " << this << "\n";
|
||||
Event::s_listeners.erase(this);
|
||||
}
|
||||
|
||||
|
@ -22,8 +24,13 @@ void Event::postFrom(Mod* m) {
|
|||
if (m) this->sender = m;
|
||||
|
||||
for (auto h : Event::s_listeners) {
|
||||
if (h->passThrough(this) == ListenerResult::Stop) {
|
||||
break;
|
||||
try {
|
||||
std::cout << h << ": " << typeid(*h).name() << "\n";
|
||||
if (h->passThrough(this) == ListenerResult::Stop) {
|
||||
break;
|
||||
}
|
||||
} catch(std::exception& e) {
|
||||
std::cout << "fuck: " << h << ": " << e.what() << "\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,19 +5,11 @@ USE_GEODE_NAMESPACE();
|
|||
AEnterLayerEvent::AEnterLayerEvent(
|
||||
std::string const& layerID,
|
||||
cocos2d::CCNode* layer
|
||||
) : m_layerID(layerID),
|
||||
m_layer(layer) {}
|
||||
|
||||
std::string AEnterLayerEvent::getID() const {
|
||||
return m_layerID;
|
||||
}
|
||||
|
||||
cocos2d::CCNode* AEnterLayerEvent::getLayer() const {
|
||||
return m_layer;
|
||||
}
|
||||
) : layerID(layerID),
|
||||
layer(layer) {}
|
||||
|
||||
ListenerResult AEnterLayerFilter::handle(Callback fn, AEnterLayerEvent* event) {
|
||||
if (m_targetID == event->getID()) {
|
||||
if (m_targetID == event->layerID) {
|
||||
fn(event);
|
||||
}
|
||||
return ListenerResult::Propagate;
|
||||
|
|
Loading…
Reference in a new issue