Capycore Engine  0.1.0
A simple and lightweight game engine written in C++ based on the Unity API architecture.
Loading...
Searching...
No Matches
router.h
Go to the documentation of this file.
1#pragma once
2
4
5#include <functional>
6#include <map>
7
11class Router {
12 public:
18 std::function<void(const Message&)> handler);
19
25
30 void route(const Message& msg) const;
31
32 private:
33 std::map<MessageType, std::function<void(const Message&)>> handlers_;
34};
Routes incoming network messages to registered handlers.
Definition router.h:11
void unregister_handler(MessageType type)
Unregisters the handler associated with a message type.
void register_handler(MessageType type, std::function< void(const Message &)> handler)
Registers a handler for a specific message type. If the handler already exists, it will be overwritte...
void route(const Message &msg) const
Routes the message to its corresponding handler. If no handler exists, the message is ignored.
Represents a complete network message including type and payload.
Definition network_message.h:105
Represents either a default or custom message identifier.
Definition network_message.h:40