itstristanb / Events

C++ Event system, perfect for real time applications, reacting to an action.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

  /$$$$$$$$ /$$    /$$ /$$$$$$$$ /$$   /$$ /$$$$$$$$  /$$$$$$ 
 | $$_____/| $$   | $$| $$_____/| $$$ | $$|__  $$__/ /$$__  $$ 
 | $$      | $$   | $$| $$      | $$$$| $$   | $$   | $$  \__/ 
 | $$$$$   |  $$ / $$/| $$$$$   | $$ $$ $$   | $$   |  $$$$$$  
 | $$__/    \  $$ $$/ | $$__/   | $$  $$$$   | $$    \____  $$
 | $$        \  $$$/  | $$      | $$\  $$$   | $$    /$$  \ $$
 | $$$$$$$$   \  $/   | $$$$$$$$| $$ \  $$   | $$   |  $$$$$$/
 |________/    \_/    |________/|__/  \__/   |__/    \______/ 

MIT license Language Standard Platform Platform

Description:

This repository contains a templated c++17 (and up) Event system that allows for clients to attach callbacks to a host which then can be invoked at any time. Could also be understood as a 'act, react' pattern.

Why you should use events:

Real-time applications typically have many things that must be interconnected. Whether its a controller input resulting in the player jumping, audio playing etc., or a time sensitive event such as a client entering a queue, this api makes it quick and easy to modulate those responses. This project started as a key element to a custom game engine, written in c++. All player and NPC actions along with the startup and shutting down of systems were driven by these events, making them crucial for a fast development.

Supported Platforms:

  • The following platforms are supported:
    • Windows: Tested on Windows 10 Professional 64-bit.
    • Linux: Tested on Ubuntu 18.04.4 LTS

Requirements:

  • C++17 capable compiler:
    • Visual C++ 15 (Visual Studio 2017)
    • Clang 5+
    • GCC 7+

Documentation:

Current documentation available on the Wiki.

FAQ:

How much overhead is from invoking an Event?

Not much, it is the overhead of calling std::function times the number of hooked functions.
(if your application is slow, it is most likely not the events)

How do I deal with dll and so static memory ownership?

Create a wrapper function for the event.

Macro example:

    //! Creates a function wrapper for an event  
    #define STATIC_EVENT_WRAPPER(TYPE, NAME) static TYPE& Get##NAME() { static TYPE NAME; return NAME; }
    
    // Use example
    STATIC_EVENT_WRAPPER(Event<void()>, ApplicationStart)
    
    int main()
    {
      // ...
      GetApplicationStart().Invoke();
      // ...
      return 0;
    }

About

C++ Event system, perfect for real time applications, reacting to an action.

License:MIT License


Languages

Language:C++ 100.0%