|
ngl_server 1.0
基于 Actor 模型的 C++ 服务器框架
|
猜数字游戏 Actor More...
#include <actor_example_guess_number.h>
Public Member Functions | |
| actor_example_guess_number (i16_area aarea, i32_actordataid aid, const std::map< int32_t, i64_actorid > &aroleids, int32_t aindex) | |
| 构造函数,初始化猜数字游戏参数 | |
| virtual | ~actor_example_guess_number ()=default |
| 析构函数 | |
| virtual void | init () |
| 初始化,设置定时器 | |
| virtual void | loaddb_finish (pbdb::ENUM_DB atype, enum_dbstat astat) |
| 数据库加载完成回调 | |
| void | next_setp () |
| 推进到下一轮猜测 | |
| void | bomb (i64_actorid aroleid=nguid::make()) |
| 发送踩雷结果给玩家 | |
| bool | isfinish () |
| 判断游戏是否已结束 | |
| void | set_finish (i64_actorid abombrole) |
| 设置游戏结束状态 | |
| i64_actorid | next_guess_role () |
| 获取下一个猜测玩家的 ID | |
| i64_actorid | cur_guess_role () |
| 获取当前猜测玩家的 ID | |
| void | send_error (i64_actorid aroleid, pbexample::E_GUESS_NUMBER_ERROR aerr) |
| 向玩家发送错误码 | |
| bool | timer_handle (const message< np_timerparm > &adata) |
| 定时器回调,处理超时逻辑 | |
| bool | handle (const message< mforward< pbexample::PROBUFF_EXAMPLE_GUESS_NUMBER > > &adata) |
| 处理玩家猜测数字请求 | |
| bool | handle (const message< np_example_entergame_ready > &adata) |
| 处理游戏准备就绪通知 | |
| Public Member Functions inherited from ngl::actor_example< actor_example_guess_number > | |
| virtual void | erase_actor_before () |
| Actor 销毁前的清理操作,退出数据库读取会话 | |
| Public Member Functions inherited from ngl::actor | |
| template<typename TDerived> | |
| void | init_rfun () |
| 初始化消息分发器。 | |
| actor (const actorparm &aparm) | |
| 构造函数。 | |
| actor_stat | activity_stat () final |
| 获取调度器可见的生命周期状态。 | |
| void | set_activity_stat (actor_stat astat) final |
| 更新调度器可见的生命周期状态。 | |
| void | release () final |
| 停止actor,排空队列中的工作,并持久化DB支持的状态。 | |
| bool | list_empty () final |
| 检查普通队列和优先级队列是否都为空。 | |
| bool | pending_empty () final |
| 检查高优先级队列是否为空 | |
| bool | high_empty () final |
| 检查优先级队列是否为空。 | |
| std::optional< int32_t > | hight_value () |
| 获取当前最高优先级值。 | |
| bool | push (handle_pram &apram) final |
| 将传入任务入队到相应的优先级队列。 | |
| bool | actor_handle (i32_threadid athreadid) final |
| 在指定的工作线程上运行一个调度切片。 | |
| template<typename T> | |
| bool | ahandle (const std::shared_ptr< T > &aparm) |
| 处理类型化消息。 | |
| bool | ahandle (i32_threadid athreadid, handle_pram &aparm) |
| 处理消息队列中的消息。 | |
| virtual void | broadcast () |
| 广播消息处理钩子。 | |
| bool | handle_broadcast (const message< np_actor_broadcast > &adata) |
| 合成广播消息的内部入口点。 | |
| bool | handle_close (const message< np_actor_close > &) |
| 合成关闭消息的内部入口点。 | |
| template<typename TMESSAGE> | |
| bool | handle_script (const message< TMESSAGE > &adata) |
| 将类型化消息转发到附加的脚本运行时。 | |
| Public Member Functions inherited from ngl::actor_base | |
| actor_base (const actorparmbase &aparm) | |
| Actor基类构造函数 | |
| nready & | ready () |
| std::unique_ptr< nmanage_dbclient > & | manage_dbclient () |
| void | set_db_component (ndb_component *acomponent) |
| void | db_component_init_data () |
| void | init_db_component (bool acreate) |
| void | add_dbclient (ndbclient_base *adbclient, i64_actorid aid) |
| template<pbdb::ENUM_DB DBTYPE, typename TDBTAB, typename TACTOR> | |
| bool | handle_db (const message< np_actordb_load_response< DBTYPE, TDBTAB > > &adata) |
| virtual void | handle_after (handle_pram &) |
| virtual void | save () |
| bool | is_single () const |
| const nguid & | guid () const |
| i64_actorid | id_guid () const |
| i32_actordataid | id () const |
| i16_area | area () const |
| ENUM_ACTOR | type () const |
| virtual void | erase_actor () |
| 从actor_manage中注销并销毁此Actor | |
| bool | nscript_using () const |
| bool | nscript_db_loadfinish () const |
| template<typename T> | |
| bool | nscript_data_push (const char *asource, const T &adata, bool aedit) |
| template<typename T> | |
| bool | nscript_data_del (int64_t adataid) |
| template<typename T> | |
| bool | nscript_data_checkout (int64_t adataid, T &adata) |
| template<typename T> | |
| bool | nscript_data_checkout (std::map< int64_t, T > &adata) |
| template<typename T> | |
| bool | nscript_data_checkdel (int64_t adataid) |
| template<typename T> | |
| bool | nscript_data_checkdel (std::vector< int64_t > &adeldata) |
| template<typename T> | |
| bool | nscript_handle (const T &adata) |
| void | kcp_setindex (i32_serverid aserverid, pbnet::ENUM_KCP aenum, i16_port akcpindex) |
| std::optional< i16_port > | kcp_index (i32_serverid aserverid, pbnet::ENUM_KCP aenum) |
| std::optional< i16_port > | kcp_index (int16_t aservertid, int16_t atcount, pbnet::ENUM_KCP aenum) |
| bool | kcp_connect (i16_port auport, const std::string &aip, i16_port aprot, i64_actorid aactoridserver, std::string &akcpsession) const |
| int64_t | set_timer (const np_timerparm &aparm) |
| 为当前Actor设置定时器 | |
| bool | isbroadcast () const |
| void | set_broadcast (bool aisbroadcast) |
| template<typename T> | |
| void | handle_print (const message< T > &adata) const |
Static Public Member Functions | |
| static ENUM_ACTOR | actor_type () |
| 返回 Actor 类型枚举值 | |
| static i64_actorid | actorid () |
| 生成 Actor 唯一 ID | |
| static void | nregister () |
| 注册定时器和消息处理器 | |
| Static Public Member Functions inherited from ngl::actor | |
| template<typename TDerived> | |
| static void | register_timer (Tfun< TDerived, np_timerparm > afun=&TDerived::timer_handle) |
| 注册定时器回调函数。 | |
| template<typename TDerived, typename T> | |
| static void | register_actor_s (const std::function< void(TDerived *, const message< T > &)> &afun) |
| 注册基于std::function的消息处理器。 | |
| template<typename TDerived, typename ... ARG> | |
| static void | register_actor (ARG... afun) |
| 注册一个或多个强类型消息处理器。 | |
| template<typename TDerived, typename T> | |
| static void | register_actornonet (const Tfun< TDerived, T > afun) |
| 注册本地专用消息处理器(不来自网络协议分发)。 | |
| template<typename TDerived, typename ... ARG> | |
| static void | register_handle () |
| 注册TDerived::handle作为消息处理器。 | |
| template<typename TDerived, typename ... ARG> | |
| static void | register_script_handle () |
| 注册脚本支持的消息处理器。 | |
| template<typename TDerived, typename ... ARG> | |
| static void | register_forward_c2g () |
| 注册客户端到网关的转发处理器。 | |
| template<typename TDerived, typename ... ARG> | |
| static void | register_forward_g2c () |
| 注册网关到客户端的转发处理器。 | |
| template<typename TDerived, ENUM_ACTOR ACTOR, typename ... ARG> | |
| static void | register_secondary_forward_c2g () |
| 注册中继actor的二级转发辅助器。 | |
| Static Public Member Functions inherited from ngl::actor_base | |
| static void | erase_actor (const nguid &aguid) |
| static std::shared_ptr< pack > | jsonpack (const std::string &apbname, const std::string &ajson, i64_actorid aactorid, i64_actorid arequestactorid, bool ahead=false) |
| template<typename T> | |
| static std::shared_ptr< pack > | net_pack (T &adata, i64_actorid aactorid, i64_actorid arequestactorid, bool ahead=false) |
| static bool | send_pack (i32_sessionid asession, std::shared_ptr< pack > &apack) |
| template<typename T> | |
| static bool | send (i32_sessionid asession, const T &adata, i64_actorid aactorid, i64_actorid arequestactorid) |
| template<typename T> | |
| static bool | send_server (i32_serverid aserverid, const T &adata, i64_actorid aactorid, i64_actorid arequestactorid) |
| template<typename T> | |
| static bool | send_server (const std::set< i32_serverid > &aserverids, const T &adata, i64_actorid aactorid, i64_actorid arequestactorid) |
| static bool | send_server (i32_serverid aserverid, std::shared_ptr< pack > &apack) |
| static bool | kcp_sendpack (i64_actorid aactorid, std::shared_ptr< pack > &adata, i16_port auport=0) |
| static bool | kcp_sendpack (const std::set< i64_actorid > &aactorids, std::shared_ptr< pack > &adata, i16_port auport=0) |
| template<typename T> | |
| static bool | kcp_send (i64_actorid aactorid, const T &adata, i16_port auport=0) |
| 向单个Actor发送KCP数据(actor_base模板实现)。 | |
| template<typename T> | |
| static bool | kcp_send (const std::set< i64_actorid > &aactorids, const T &adata, i16_port auport=0) |
| 向一组Actor广播KCP数据(actor_base模板实现)。 | |
| static i64_actorid | actorclient_guid () |
| template<typename T> | |
| static void | send_client (const std::set< i64_actorid > &aids, const T &adata, ENET_PROTOCOL aprotocol=ENET_TCP) |
| template<typename T> | |
| static void | send_client (i64_actorid aid, const T &adata, ENET_PROTOCOL aprotocol=ENET_TCP) |
| template<typename T> | |
| static void | send_client (const std::vector< i64_actorid > &aids, const T &adata, ENET_PROTOCOL aprotocol=ENET_TCP) |
| template<typename T> | |
| static void | send_client (const T &adata, ENET_PROTOCOL aprotocol=ENET_TCP) |
| template<typename T> | |
| static void | send_clientbyarea (i16_area aarea, const T &adata, ENET_PROTOCOL aprotocol=ENET_TCP) |
| static void | send_actor (const nguid &aguid, const std::shared_ptr< pack > &adata) |
| 向指定Actor发送消息包 | |
| template<typename T, bool IS_SEND = true> | |
| static void | send_actor (ENUM_ACTOR atype, const std::shared_ptr< T > &adata) |
| template<typename T, bool IS_SEND = true> | |
| static void | send_actor (const nguid &aguid, const nguid &arequestguid, const std::shared_ptr< T > &adata) |
| template<typename T, bool IS_SEND = true> | |
| static void | send_actor (const nguid &aguid, const nguid &arequestguid, const std::shared_ptr< T > &adata, const std::function< void()> &afailfun) |
| template<typename T, bool IS_SEND = true> | |
| static void | send_actor (const std::set< i64_actorid > &asetguid, const nguid &arequestguid, const std::shared_ptr< T > &adata) |
| static void | start_broadcast () |
| 启动全局广播定时器 | |
| template<typename TDerived> | |
| static void | first_nregister (ENUM_ACTOR atype) |
| template<typename TACTOR, typename ... ARG> | |
| static std::shared_ptr< actor_base > | create (i16_area aarea, i32_actordataid aid, ARG &&... args) |
| actor工厂方法(编译期类型) | |
| template<typename ... ARG> | |
| static std::map< ENUM_ACTOR, create_fun< ARG... > > & | creators () |
| template<ENUM_ACTOR EACTOR, typename TACTOR, typename ... ARG> | |
| static void | cregister () |
| template<typename ... ARG> | |
| static std::shared_ptr< actor_base > | create (ENUM_ACTOR atype, i16_area aarea, i32_actordataid aid, ARG &&... args) |
| actor工厂方法(运行时类型,查分桶表转调编译期create<TACTOR>) | |
Additional Inherited Members | |
| Public Types inherited from ngl::actor_base | |
| template<typename ... ARG> | |
| using | create_fun = std::function<std::shared_ptr<actor_base>(i16_area, i32_actordataid, ARG...)> |
| Protected Attributes inherited from ngl::actor_example< actor_example_guess_number > | |
| std::vector< i64_actorid > | m_rolesds |
| pbexample::EPLAY_TYPE | m_playertype |
猜数字游戏 Actor
实现经典的猜数字(Bulls and Cows)回合制小游戏逻辑。 多个玩家轮流猜测一个随机目标数字,猜中者失败(踩雷), 最后一个可猜测的玩家获胜。
| ngl::actor_example_guess_number::actor_example_guess_number | ( | i16_area | aarea, |
| i32_actordataid | aid, | ||
| const std::map< int32_t, i64_actorid > & | aroleids, | ||
| int32_t | aindex ) |
构造函数,初始化猜数字游戏参数
| aarea | 逻辑区域(由create<>传入,用于生成guid) |
| aid | actor数据ID(即aindex,由create<>传入) |
| aroleids | 参与玩家的角色ID映射 |
| aindex | 当前关卡/实例索引 |
|
virtual |
初始化,设置定时器
Reimplemented from ngl::actor_example< actor_example_guess_number >.
|
virtual |
数据库加载完成回调
Reimplemented from ngl::actor_base.