Jump to content

Process Event Calls On Components?


reepblue
 Share

Recommended Posts

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. 

Cyclone - Ultra Game System - Component PreprocessorTex2TGA - Darkness Awaits Template (Leadwerks)

If you like my work, consider supporting me on Patreon!

Link to comment
Share on other sites

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>();

 

  • Like 1
  • Thanks 1

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

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...