Skip to content

Commit 84fae42

Browse files
committed
简单修改
简单修改
1 parent 7b736d6 commit 84fae42

32 files changed

+152
-69
lines changed

ngl.tar

3.07 MB
Binary file not shown.

public/actor/actor_base/actor.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include "actor_base.h"
55
#include "actor_rfun.h"
66
#include "impl.h"
7+
#include "actor_type.h"
78

89
namespace ngl
910
{
@@ -54,7 +55,7 @@ namespace ngl
5455
{
5556
using tloaddb = actor_db_load_response<TYPE, DBTYPE, TDBTAB>;
5657
auto lpfun = &actor_base::template handle<TYPE, DBTYPE, TDBTAB, TDerived>;
57-
arfun<TDerived, TYPE>::instance().template rfun<TDerived, tloaddb>(lpfun, true);
58+
arfun<TDerived, TYPE>::instance().template rfun<actor_base, tloaddb>(lpfun, true);
5859
}
5960

6061
template <EPROTOCOL_TYPE TYPE, typename TDerived, pbdb::ENUM_DB DBTYPE, typename TDBTAB, typename ...ARG>
@@ -131,7 +132,7 @@ namespace ngl
131132
template <EPROTOCOL_TYPE TYPE, bool IsForward, typename TDerived, typename T>
132133
static void register_forward(T afun)
133134
{
134-
arfun<TDerived, TYPE>::instance().template rfun_forward<IsForward>( afun, (ENUM_ACTOR)TDerived::ACTOR_TYPE, false);
135+
arfun<TDerived, TYPE>::instance().template rfun_forward<IsForward>( afun, actor_type::type<TDerived>(), false);
135136
}
136137

137138
template <EPROTOCOL_TYPE TYPE, bool IsForward, typename TDerived, typename T, typename ...ARG>

public/actor/actor_base/actor_client.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@ namespace ngl
2525

2626
// 注册需要处理的消息
2727
static void actor_register();
28-
29-
enum { ACTOR_TYPE = ACTOR_ADDRESS_CLIENT };
3028
private:
3129
void actor_server_register(i32_serverid aserverid);
3230
public:

public/actor/actor_base/actor_create.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@ namespace ngl
2727

2828
static void actor_register();
2929

30-
enum { ACTOR_TYPE = ACTOR_CREATE};
31-
3230
// 在指定[Server]上创建[Actor]
3331
template <typename T>
3432
static void switch_process_send(std::shared_ptr<actor_switch_process<T>>& pro)

public/actor/actor_base/actor_db.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -236,16 +236,14 @@ namespace ngl
236236
template <EPROTOCOL_TYPE PROTYPE, pbdb::ENUM_DB TDBTAB_TYPE, typename TDBTAB>
237237
class actor_db : public actor
238238
{
239-
public:
240-
enum { ACTOR_TYPE = PROTYPE * 1000 + ACTOR_DB + TDBTAB_TYPE };
241239
private:
242240
actor_db() :
243241
actor(
244242
actorparm
245243
{
246244
.m_parm
247245
{
248-
.m_type = (ENUM_ACTOR)(ACTOR_TYPE),
246+
.m_type = actor_type::type<actor_db<PROTYPE,TDBTAB_TYPE,TDBTAB>>(),
249247
.m_area = ttab_servers::tab()->m_area,
250248
.m_id = nconfig::m_nodeid
251249
},
@@ -339,7 +337,7 @@ namespace ngl
339337
pro->m_type = atype;
340338
pro->m_ls.swap(aset);
341339

342-
ENUM_ACTOR ltype = (ENUM_ACTOR)(actor_db<PROTYPE, TDBTAB_TYPE, TDBTAB>::ACTOR_TYPE);
340+
ENUM_ACTOR ltype = actor_type::type<actor_db<PROTYPE, TDBTAB_TYPE, TDBTAB>>();
343341
i64_actorid lactorid = actor_guid::make(ltype, tab_self_area, nconfig::m_nodeid);
344342
actor_base::static_send_actor(lactorid, actor_guid::make(), pro);
345343
}

public/actor/actor_base/actor_db_client.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ namespace ngl
138138
actor_db_load<PROTYPE, DBTYPE, TDBTAB> ldata;
139139
ldata.m_id = aid;
140140

141-
ENUM_ACTOR ltype = (ENUM_ACTOR)actor_db<PROTYPE, DBTYPE, TDBTAB>::ACTOR_TYPE;
141+
ENUM_ACTOR ltype = actor_type::type<actor_db<PROTYPE, DBTYPE, TDBTAB>>();
142142
i64_actorid ldbid = actor_guid::make(ltype, tab_self_area, dbnodeid());
143143
nserver->sendtoserver(dbnodeid(), ldata, ldbid, m_actor->id_guid());
144144
}
@@ -275,7 +275,7 @@ namespace ngl
275275
{
276276
// ### 先序列化 再让actor_client确认位置
277277
i64_actorid lactorid = actor_guid::make(
278-
(ENUM_ACTOR)actor_db<PROTYPE, DBTYPE, TDBTAB>::ACTOR_TYPE
278+
actor_type::type<actor_db<PROTYPE, DBTYPE, TDBTAB>>()
279279
, tab_self_area
280280
, dbnodeid()
281281
);

public/actor/actor_base/actor_register.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22

33
#include "protocol.h"
44
#include "actor_base.h"
5+
#include "actor.h"
56
#include "actor_protocol.h"
67
#include "init_protobuf.h"
78
#include "regular.h"
9+
#include "actor_type.h"
810

911
namespace ngl
1012
{
@@ -20,7 +22,7 @@ namespace ngl
2022
afun((TTTDerived*)aactor, *(T*)apram.m_data.get());
2123
}
2224
};
23-
protocol::registry_actor<T, TYPE>((ENUM_ACTOR)TDerived::ACTOR_TYPE, init_protobuf::protocol_name<T>().c_str());
25+
protocol::registry_actor<T, TYPE>(actor_type::type<TDerived>(), init_protobuf::protocol_name<T>().c_str());
2426
return *this;
2527
}
2628

@@ -44,15 +46,15 @@ namespace ngl
4446
template <typename TTTDerived, typename T>
4547
arfun<TDerived, TYPE>& arfun<TDerived, TYPE>::rfun(Tfun<TTTDerived, T> afun, bool aisload/* = false*/)
4648
{
47-
rfun(afun, (ENUM_ACTOR)TDerived::ACTOR_TYPE, aisload);
49+
rfun<TTTDerived, T>(afun, actor_type::type<TDerived>(), aisload);
4850
return *this;
4951
}
5052

5153
template <typename TDerived, EPROTOCOL_TYPE TYPE>
5254
template <typename TTTDerived, typename T>
5355
arfun<TDerived, TYPE>& arfun<TDerived, TYPE>::rfun(Tfun<TTTDerived, T> afun, ENUM_ACTOR atype, bool aisload/* = false*/)
5456
{
55-
rfun_nonet(afun, aisload);
57+
rfun_nonet<TTTDerived, T>(afun, aisload);
5658
protocol::registry_actor<T, TYPE>(atype, init_protobuf::protocol_name<T>().c_str());
5759
return *this;
5860
}
@@ -90,7 +92,7 @@ namespace ngl
9092
(((TDerived*)(aactor))->*afun)(lmessage);
9193
}
9294
};
93-
protocol::registry_actor_recvforward<T, type_forward::isusing, TYPE>((ENUM_ACTOR)TDerived::ACTOR_TYPE, init_protobuf::protocol<type_forward>(), init_protobuf::protocol_name<type_forward>().c_str());
95+
protocol::registry_actor_recvforward<T, type_forward::isusing, TYPE>(actor_type::type<TDerived>(), init_protobuf::protocol<type_forward>(), init_protobuf::protocol_name<type_forward>().c_str());
9496
return *this;
9597
}
9698
}

public/actor/actor_base/actor_server.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ namespace ngl
2121

2222
static void actor_register();
2323

24-
enum { ACTOR_TYPE = ACTOR_ADDRESS_SERVER };
25-
2624
// ---- [actor client -> actor server] register
2725
// 注册结点
2826
bool handle(message<actor_node_register>& adata);
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
#include "actor_type.h"
2+
3+
#include "actor_client.h"
4+
#include "actor_create.h"
5+
#include "actor_db.h"
6+
#include "actor_server.h"
7+
#include "actor_cross.h"
8+
#include "actor_manage_role.h"
9+
#include "actor_role.h"
10+
#include "actor_gateway.h"
11+
#include "actor_gateway_client2game.h"
12+
#include "actor_gateway_game2client.h"
13+
#include "actor_log.h"
14+
#include "actor_login.h"
15+
#include "actor_reloadcsv.h"
16+
#include "actor_robot.h"
17+
#include "actor_manage_activity.h"
18+
#include "actor_brief.h"
19+
#include "actor_chat.h"
20+
#include "actor_gm.h"
21+
#include "actor_mail.h"
22+
#include "actor_notice.h"
23+
#include "actor_ranklist.h"
24+
#include "actor_matching.h"
25+
#include "actor_manage_plays.h"
26+
#include "actor_plays_go_undergroundpalace.h"
27+
28+
namespace ngl
29+
{
30+
std::multimap<size_t, ENUM_ACTOR> actor_type::m_keyval;
31+
32+
template <EPROTOCOL_TYPE PROTYPE, pbdb::ENUM_DB TDBTAB_TYPE, typename TDBTAB>
33+
void initdb()
34+
{
35+
actor_type::inits<
36+
ngl::actor_db<EPROTOCOL_TYPE_PROTOCOLBUFF, TDBTAB_TYPE, TDBTAB>
37+
>((ENUM_ACTOR)(PROTYPE * 1000 + ACTOR_DB + TDBTAB_TYPE));
38+
}
39+
40+
void actor_type::init()
41+
{
42+
inits<actor_client>(ACTOR_ADDRESS_CLIENT);
43+
inits<actor_create>(ACTOR_CREATE);
44+
inits<actor_server>(ACTOR_ADDRESS_SERVER);
45+
inits<actor_cross>(ACTOR_CROSS);
46+
inits<actor_manage_role>(ACTOR_MANAGE_ROLE);
47+
inits<actor_role>(ACTOR_ROLE);
48+
inits<actor_gateway>(ACTOR_GATEWAY);
49+
inits<actor_gateway_client2game>(ACTOR_GATEWAY_CLIENT2GAME);
50+
inits<actor_gateway_game2client>(ACTOR_GATEWAY_GAME2CLIENT);
51+
inits<actor_log>(ACTOR_LOG);
52+
inits<actor_login>(ACTOR_LOGIN);
53+
inits<actor_reloadcsv>(ACTOR_RELOADCSV);
54+
inits<actor_reloadcsv_distribute>(ACTOR_RELOADCSV_DISTRIBUTE);
55+
inits<actor_robot>(ACTOR_ROBOT);
56+
inits<actor_manage_robot>(ACTOR_MANAGE_ROBOT);
57+
inits<actor_manage_activity>(ACTOR_ACTIVITY_MANAGE);
58+
inits<actor_brief>(ACTOR_BRIEF);
59+
inits<actor_chat>(ACTOR_CHAT);
60+
inits<actor_gm>(ACTOR_GM);
61+
inits<actor_mail>(ACTOR_MAIL);
62+
inits<actor_notice>(ACTOR_NOTICE);
63+
inits<actor_ranklist>(ACTOR_RANKLIST);
64+
inits<actor_matching>(ACTOR_MATCHING);
65+
inits<actor_manage_plays>(ACTOR_MANAGE_PLAYS);
66+
inits<actor_plays_go_undergroundpalace>(ACTOR_PLAYS_GO_UNDERGROUNDPALACE);
67+
68+
initdb<EPROTOCOL_TYPE_PROTOCOLBUFF, pbdb::ENUM_DB_ACCOUNT, pbdb::db_account>();
69+
initdb<EPROTOCOL_TYPE_PROTOCOLBUFF, pbdb::ENUM_DB_ROLE, pbdb::db_role>();
70+
initdb<EPROTOCOL_TYPE_PROTOCOLBUFF, pbdb::ENUM_DB_BAG, pbdb::db_bag>();
71+
initdb<EPROTOCOL_TYPE_PROTOCOLBUFF, pbdb::ENUM_DB_KEYVALUE, pbdb::db_keyvalue>();
72+
initdb<EPROTOCOL_TYPE_PROTOCOLBUFF, pbdb::ENUM_DB_MAIL, pbdb::db_mail>();
73+
initdb<EPROTOCOL_TYPE_PROTOCOLBUFF, pbdb::ENUM_DB_GUILD, pbdb::db_guild>();
74+
initdb<EPROTOCOL_TYPE_PROTOCOLBUFF, pbdb::ENUM_DB_NOTICE, pbdb::db_notice>();
75+
initdb<EPROTOCOL_TYPE_PROTOCOLBUFF, pbdb::ENUM_DB_ACTIVITY, pbdb::db_activity>();
76+
initdb<EPROTOCOL_TYPE_PROTOCOLBUFF, pbdb::ENUM_DB_BRIEF, pbdb::db_brief>();
77+
initdb<EPROTOCOL_TYPE_PROTOCOLBUFF, pbdb::ENUM_DB_RANKLIST, pbdb::db_ranklist>();
78+
initdb<EPROTOCOL_TYPE_PROTOCOLBUFF, pbdb::ENUM_DB_TASK, pbdb::db_task>();
79+
80+
}
81+
}

public/actor/actor_base/actor_type.h

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#pragma once
2+
3+
#include "actor_enum.h"
4+
5+
#ifndef NOTUSING_BOOST_TYPEINFO
6+
# include <boost/type_index.hpp>
7+
# define HASH_CODE_VALUE(_TYPE) boost::typeindex::type_id<_TYPE>().hash_code()
8+
#else
9+
# define HASH_CODE_VALUE(_TYPE) typeid(T).hash_code()
10+
#endif
11+
12+
namespace ngl
13+
{
14+
class actor_type
15+
{
16+
template <typename T>
17+
static size_t hash_code()
18+
{
19+
static size_t lcode = HASH_CODE_VALUE(T);
20+
return lcode;
21+
}
22+
static std::multimap<size_t, ENUM_ACTOR> m_keyval;
23+
24+
25+
26+
public:
27+
template <typename T>
28+
static void inits(ENUM_ACTOR atype)
29+
{
30+
size_t lcode = hash_code<T>();
31+
if (m_keyval.find(lcode) != m_keyval.end())
32+
{
33+
return;
34+
}
35+
m_keyval.insert(std::make_pair(lcode, atype));
36+
}
37+
38+
39+
template <typename T>
40+
static ENUM_ACTOR type()
41+
{
42+
using TRC = std::remove_const<T>::type;
43+
size_t lcode = hash_code<T>();
44+
auto itor = m_keyval.find(lcode);
45+
assert(itor != m_keyval.end());
46+
return itor->second;
47+
}
48+
49+
static void init();
50+
};
51+
52+
53+
}

0 commit comments

Comments
 (0)