Kaynağa Gözat

行为树库完全解耦,可以单独形成一个lib供外部使用

tanghai 14 yıl önce
ebeveyn
işleme
dd3a949ac7

+ 3 - 1
Cpp/Game/BehaviorTree/BuffType.cc

@@ -1,6 +1,7 @@
 #include "BehaviorTree/BuffType.h"
 #include "BehaviorTree/ContexIf.h"
 #include "BehaviorTree/SpellBuff.h"
+#include "BehaviorTree/CombatContex.h"
 #include "BehaviorTree/BehaviorTreeConf.pb.h"
 
 namespace Egametang {
@@ -16,7 +17,8 @@ BuffType::~BuffType()
 
 bool BuffType::Run(ContexIf* contex)
 {
-	Buff* buff = contex->GetBuff();
+	CombatContex* combat_contex = reinterpret_cast<CombatContex*>(contex);
+	Buff* buff = combat_contex->GetBuff();
 	return buff->buffType == buffType;
 }
 

+ 2 - 1
Cpp/Game/BehaviorTree/ChangeHealth.cc

@@ -17,7 +17,8 @@ ChangeHealth::~ChangeHealth()
 
 bool ChangeHealth::Run(ContexIf *contex)
 {
-	Spell* spell = contex->GetSpell();
+	CombatContex* combat_contex = reinterpret_cast<CombatContex*>(contex);
+	Spell* spell = combat_contex->GetSpell();
 
 	Unit* target = NULL;
 	if (unit == 0)

+ 0 - 10
Cpp/Game/BehaviorTree/ContexIf.h

@@ -12,16 +12,6 @@ public:
 	virtual ~ContexIf()
 	{
 	}
-
-	virtual Spell* GetSpell()
-	{
-		return NULL;
-	}
-
-	virtual Buff* GetBuff()
-	{
-		return NULL;
-	}
 };
 
 } // namespace Egametang

+ 5 - 0
Cpp/Platform/Base/Typedef.h

@@ -2,6 +2,7 @@
 #define BASE_TYPEDEFS_H
 #include <boost/cstdint.hpp>
 #include <boost/shared_ptr.hpp>
+#include <google/protobuf/service.h>
 
 namespace Egametang {
 
@@ -19,6 +20,10 @@ typedef boost::uint64_t uint64;
 typedef boost::shared_ptr<int> IntPtr;
 typedef boost::shared_ptr<std::string> StringPtr;
 
+// google
+typedef boost::shared_ptr<google::protobuf::Service> ProtobufServicePtr;
+typedef boost::shared_ptr<google::protobuf::Message> ProtobufMessagePtr;
+
 } // namespace Egametang
 
 #endif // BASE_TYPEDEFS_H

+ 2 - 2
Cpp/Platform/Rpc/MethodInfo.h

@@ -10,12 +10,12 @@ namespace Egametang {
 class MethodInfo
 {
 public:
-	RpcServicePtr service;
+	ProtobufServicePtr service;
 	const google::protobuf::MethodDescriptor* methodDescriptor;
 	const google::protobuf::Message* requestPrototype;
 	const google::protobuf::Message* responsePrototype;
 
-	MethodInfo(RpcServicePtr service, const google::protobuf::MethodDescriptor* methodDescriptor):
+	MethodInfo(ProtobufServicePtr service, const google::protobuf::MethodDescriptor* methodDescriptor):
 		service(service), methodDescriptor(methodDescriptor)
 	{
 		requestPrototype = &service->GetRequestPrototype(methodDescriptor);

+ 1 - 1
Cpp/Platform/Rpc/RpcServer.cc

@@ -84,7 +84,7 @@ void RpcServer::RunService(RpcSessionPtr session, RpcMetaPtr meta,
 					done));
 }
 
-void RpcServer::Register(RpcServicePtr service)
+void RpcServer::Register(ProtobufServicePtr service)
 {
 	boost::hash<std::string> stringHash;
 	const google::protobuf::ServiceDescriptor* serviceDescriptor = service->GetDescriptor();

+ 1 - 1
Cpp/Platform/Rpc/RpcServer.h

@@ -35,7 +35,7 @@ public:
 
 	virtual void RunService(RpcSessionPtr session, RpcMetaPtr meta,
 			StringPtr message, MessageHandler messageHandler);
-	virtual void Register(RpcServicePtr service);
+	virtual void Register(ProtobufServicePtr service);
 	virtual void Remove(RpcSessionPtr& session);
 	virtual void Stop();
 };

+ 1 - 1
Cpp/Platform/Rpc/RpcServerMock.h

@@ -20,7 +20,7 @@ public:
 	}
 
 	MOCK_METHOD4(RunService, void(RpcSessionPtr, RpcMetaPtr, StringPtr, MessageHandler));
-	MOCK_METHOD1(Register, void(RpcServicePtr));
+	MOCK_METHOD1(Register, void(ProtobufServicePtr));
 	MOCK_METHOD1(Remove, void(RpcSessionPtr&));
 };
 

+ 1 - 1
Cpp/Platform/Rpc/RpcServerTest.cc

@@ -65,7 +65,7 @@ TEST_F(RpcServerTest, ClientAndServer)
 {
 	ThreadPool threadPool(2);
 
-	RpcServicePtr echoSevice(new MyEcho);
+	ProtobufServicePtr echoSevice(new MyEcho);
 
 	RpcServerPtr server(new RpcServer(ioServer, port));
 	// 注册service

+ 1 - 6
Cpp/Platform/Rpc/RpcTypedef.h

@@ -1,16 +1,11 @@
 #ifndef RPC_RPCTYPEDEF_H
 #define RPC_RPCTYPEDEF_H
+
 #include <boost/shared_ptr.hpp>
 #include <boost/function.hpp>
-#include <google/protobuf/service.h>
 #include "Base/Typedef.h"
 
 namespace Egametang {
-
-// google
-typedef boost::shared_ptr<google::protobuf::Service> RpcServicePtr;
-typedef boost::shared_ptr<google::protobuf::Message> RpcMessagePtr;
-
 // rpc
 class RpcServer;
 class RpcSession;