abdielsouza / SingularEventLibrary

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

About the library

This is a simple event handling library written with C++ 20 (note the specification) I created to be used mainly on game development. However, I want to make the library asynchronous and "message-driven", since I just released now a first version of this.

How to use it

To use this library, you can take this code as example:

// First of all, import the needed libraries.
#include <singular/Event.hpp>
#include <singular/EventHandler.hpp>
#include <iostream> // this is just for printing in the example below.

// Create your own event class (it could be a struct too)
struct CustomEvent : Singular::Event {};

// Create your own event listener.
class CustomEventListener : public IEventListener
{
    void OnEvent(const Singular::Event& event) override
    {
        std::cout << "CustomEvent listened!\n";
    }
};

int main(void)
{
    // Create an instance of the listener and an instance for the handler.
    CustomEventListener listener;
    Singular::EventHandler handler;

    /* Register the listener on the handler. 
     * The listener must be coherent with the event type to be handled.
     */
    handler.RegisterListener<CustomEvent>(&listener);

    // Now we can send the event to its respective listener and it will return a response.
    handler.SendEvent<CustomEvent>();

    // We can also remove the listener from the handler.
    handler.RemoveListener<CustomEvent>(&listener);
    // Or clear the entire listener container.
    handler.RemoveAll();
}

Future features

  • Asynchronous programming support
  • Templated listeners (to define the events to be listened at compile-time)
  • "message-driven" architecture

How to build and install it

To use this library, the easier way is installing it on your system with the instructions below:

  1. First of all, clone this repository, go to the root directory and run these commands:
mkdir build && cd build
sudo cmake ..
  1. Inside the "build" directory, run this command to install Singular on your system:
sudo make install

After that, the library should be installed on your system and you are ready to use it on your projects.

About

License:GNU General Public License v3.0


Languages

Language:C++ 83.3%Language:Python 6.3%Language:Makefile 5.1%Language:CMake 2.6%Language:C 1.5%Language:Starlark 0.7%Language:Shell 0.2%Language:SCSS 0.1%Language:HTML 0.1%Language:Batchfile 0.0%Language:TypeScript 0.0%