reepblue Posted July 9, 2023 Share Posted July 9, 2023 I was wondering if it's possible or will be possible to have components listen to events. I've made custom events for changes to the settings, and I want my camera component to apply the settings whenever the event is emitted. For example, I emit the event with this function. void Settings::SetFov(const float value) { UpdateSettingsFile(); auto data = std::make_shared<SettingsData>(); data->float_value = value; settingstable["fov"] = value; EmitEvent(EVENT_SETTINGS_FOV, data); } And then in the Component, I want something like this. virtual void ProcessEvent(const Event& e) { auto camera = entity->As<Camera>(); if (camera) { if (e.id == EVENT_SETTINGS_FOV) camera->SetFov(e.data); } } From my understanding, there's no ProcessEvent virtual function in the current Component class, but I recall this being possible in earlier builds. Quote Cyclone - Ultra Game System - Component Preprocessor - Tex2TGA - Darkness Awaits Template (Leadwerks) If you like my work, consider supporting me on Patreon! Link to comment Share on other sites More sharing options...
Josh Posted July 10, 2023 Share Posted July 10, 2023 class ListenerComponent : public Component { virtual void Start() { ListenEvent(EVENT_NONE, NULL, ProcessEvent, Self());// don't call Self() in a constructor } bool ProcessEvent(const Event& e) { switch (e.id) { case EVENT_WINDOWCLOSe: break; } return true; } static bool callback(const Event& e, shared_ptr<Object> extra) { return extra->As<EventListener>()->ProcessEvent(e); } } auto c = entity->AddComponent<ListenerComponent>(); 1 1 Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
reepblue Posted July 10, 2023 Author Share Posted July 10, 2023 Ok, it's possible just with elbow grease. I was expecting a virtual function to override but I'll give this a shot. Thanks. Quote Cyclone - Ultra Game System - Component Preprocessor - Tex2TGA - Darkness Awaits Template (Leadwerks) If you like my work, consider supporting me on Patreon! Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.