Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace core {
- enum class message_type {
- UNDEFINED,
- EVENT,
- REQUEST,
- RESPONSE,
- };
- class message
- {
- public:
- const message_type type() const
- {
- return m_type;
- }
- private:
- message_type m_type;
- };
- class event : public message
- {
- public:
- event(/* TODO */);
- private:
- };
- }
- // Modue API implementation
- class gameserver_impl : public module
- {
- protected:
- void get_map_list_request(int offset, int count)
- {
- // THE implementation
- }
- };
- // Facade (internal API)
- class gameserver : protected proxy<gameserver>
- {
- public:
- gameserver(gameserver_impl &impl)
- : proxy<gameserver>::proxy(*this),
- m_impl_handle(impl)
- {
- }
- void get_map_list_async(int offset, int count, void(cb*)(const game::map_list &map_list))
- {
- core::request ev(&gameserver_impl::get_map_list_request, offset, count);
- ev.sender = ??;// TODO
- ev.cb = cb;
- m_impl_handle.deliver_messag(ev);
- }
- game::map_list get_map_list(int offset, int count)
- {
- return gs_proxy.do_sync<gameserver::get_map_list_async>(offset, count);
- }
- private:
- gameserver_impl &m_impl_handle;
- };
- // Instanciate facade based on module instance, e.g. inside the player object
- gameserver m_gs(gs_module_instance);
- // Also possible via other, already bound, reference (facade), this is like in
- // case of connect handled by core
- ? on_connect(gameserver &gs, ? playerdata)
- {
- player pl(playerdata); // Create player object from playerdata struct
- pl.gameserver(gs); // Bind gameserver reference
- }
- // Do an API call sync...
- auto map_list = m_gs.get_map_list(0, 300);
- // ...or async...
- m_gs.get_map_list_async(0, 300, []
- (auto &map_list)
- {
- }
- );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement