Преглед изворни кода

修复在window下编译的一些问题
1. glog库下的ERROR宏与windosw中的冲突
2. 中文注释后引起问题

tanghai пре 14 година
родитељ
комит
22253d9ce2

+ 15 - 3
Cpp/CMakeLists.txt

@@ -44,7 +44,7 @@ SET(Boost_USE_MULTITHREADED  ON)
 SET(Boost_USE_STATIC_RUNTIME OFF)
 INCLUDE_DIRECTORIES(${BOOST_INCLUDE_DIR})
 
-set(ThirdPartyLibs
+SET(ThirdPartyLibs
 	${GLOG_LIBRARIES}
 	${GFLAGS_LIBRARIES}
 	${GTEST_LIBRARIES}
@@ -56,8 +56,20 @@ set(ThirdPartyLibs
 )
 
 IF(PROFILE)
-    set(ThirdPartyLibs ${ThirdPartyLibs} ${PERFTOOLS_PROFILE_LIBRARIES})
+    SET(ThirdPartyLibs ${ThirdPartyLibs} ${PERFTOOLS_PROFILE_LIBRARIES})
+ENDIF()
+
+MESSAGE(STATUS "${ThirdPartyLibs}")
+
+IF(MSVC)
+	SET(CMAKE_CXX_FLAGS_DEBUG "/MTd")
+	SET(LINK_FLAGS "${LINK_FLAGS} /NODEFAULTLIB:libc.lib")
+	SET(LINK_FLAGS "${LINK_FLAGS} /NODEFAULTLIB:libcmt.lib")
+	SET(LINK_FLAGS "${LINK_FLAGS} /NODEFAULTLIB:msvcrt.lib")
+	SET(LINK_FLAGS "${LINK_FLAGS} /NODEFAULTLIB:libcd.lib")
+	SET(LINK_FLAGS "${LINK_FLAGS} /NODEFAULTLIB:libcmtd.lib")
+	ADD_DEFINITIONS(-DBOOST_ALL_NO_LIB -DBOOST_PYTHON_STATIC_LIB )
 ENDIF()
 
 ADD_SUBDIRECTORY(Platform)
-ADD_SUBDIRECTORY(Game)
+ADD_SUBDIRECTORY(Game)

+ 13 - 13
Cpp/Game/BehaviorTree/BehaviorTree.cc

@@ -33,23 +33,23 @@ void BehaviorTree::BuildTree(
 		node->AddChildNode(logicNode);
 	}
 }
-
-BehaviorTree::~BehaviorTree()
+
+BehaviorTree::~BehaviorTree()
 {
-	delete node;
-}
-
-void BehaviorTree::Run(ContexIf* contex)
-{
-	node->Run(contex);
-}
-
-std::string BehaviorTree::ToString()
+	delete node;
+}
+
+void BehaviorTree::Run(ContexIf* contex)
+{
+	node->Run(contex);
+}
+
+std::string BehaviorTree::ToString()
 {
 	boost::format format("type: %1%\node: %2%");
 	format % type % node->ToString();
 	return format.str();
 }
 
-} // namespace Egametang
-
+} // namespace Egametang
+

+ 8 - 8
Cpp/Game/BehaviorTree/BuffType.cc

@@ -4,10 +4,10 @@
 #include "BehaviorTree/BehaviorTreeConf.pb.h"
 
 namespace Egametang {
-
+
 BuffType::BuffType(int32 type, int32 buff_type):
-		BehaviorNode(type), buffType(buff_type)
-{
+		BehaviorNode(type), buffType(buff_type)
+{
 }
 
 BuffType::~BuffType()
@@ -27,13 +27,13 @@ std::string BuffType::ToString()
 	return s;
 }
 
-BuffTypeFactory::~BuffTypeFactory()
-{
-}
+BuffTypeFactory::~BuffTypeFactory()
+{
+}
 
-BehaviorNode* BuffTypeFactory::GetInstance(const BehaviorNodeConf& conf)
+BehaviorNode* BuffTypeFactory::GetInstance(const BehaviorNodeConf& conf)
 {
-	return new BuffType(conf.type(), conf.args(0));
+	return new BuffType(conf.type(), conf.args(0));
 }
 
 } // namespace Egametang

+ 8 - 8
Cpp/Game/BehaviorTree/ChangeHealth.cc

@@ -15,7 +15,7 @@ ChangeHealth::~ChangeHealth()
 {
 }
 
-bool ChangeHealth::Run(ContexIf *contex)
+bool ChangeHealth::Run(ContexIf *contex)
 {
 	Spell* spell = contex->GetSpell();
 
@@ -31,7 +31,7 @@ bool ChangeHealth::Run(ContexIf *contex)
 
 	target->health += value;
 
-	return true;
+	return true;
 }
 
 std::string ChangeHealth::ToString()
@@ -41,10 +41,10 @@ std::string ChangeHealth::ToString()
 	return s;
 }
 
-BehaviorNode* ChangeHealthFactory::GetInstance(const BehaviorNodeConf& conf)
+BehaviorNode* ChangeHealthFactory::GetInstance(const BehaviorNodeConf& conf)
 {
-	return new ChangeHealth(conf.type(), conf.args(0), conf.args(1));
-}
-
-} // namespace Egametang
-
+	return new ChangeHealth(conf.type(), conf.args(0), conf.args(1));
+}
+
+} // namespace Egametang
+

+ 2 - 2
Cpp/Game/BehaviorTree/CombatContex.cc

@@ -19,6 +19,6 @@ Spell* CombatContex::GetSpell()
 Buff* CombatContex::GetBuff()
 {
 	return buff;
-}
-
+}
+
 } // namespace Egametang

+ 7 - 5
Cpp/Game/BehaviorTree/EventDefine.h

@@ -1,6 +1,8 @@
 #ifndef BEHAVIORTREE_EVENTDEFINE_H
 #define BEHAVIORTREE_EVENTDEFINE_H
 
+namespace Egametang {
+
 enum EventType
 {
 	ON_SPELL_START     = 0,
@@ -8,7 +10,7 @@ enum EventType
 	ON_ADD_BUFF        = 2,
 	ON_REMOVE_BUFF     = 3,
 	ON_HITTED          = 4,
-	ON_HIT             = 5,
+	ON_HIT             = 5
 };
 
 enum NodeType
@@ -18,17 +20,17 @@ enum NodeType
 
 	NOT                = 11,
 
-	// 条件子节点100 - 1001
 	BUFF_TYPE          = 101,
 
-	// 动作子节点
-	CHANGE_HEALTH      = 1001,
+	CHANGE_HEALTH      = 1001
 };
 
 enum SpellUnit
 {
 	CASTER = 0,
-	VICTIM = 1,
+	VICTIM = 1
 };
 
+}  // namespace Egametang
+
 #endif // BEHAVIORTREE_EVENTDEFINE_H

+ 12 - 11
Cpp/Game/BehaviorTree/NodeFactories.cc

@@ -1,6 +1,7 @@
 #include <glog/logging.h>
 #include "Base/Typedef.h"
 #include "BehaviorTree/NotNode.h"
+#include "BehaviorTree/EventDefine.h"
 #include "BehaviorTree/SequenceNode.h"
 #include "BehaviorTree/SelectorNode.h"
 #include "BehaviorTree/BuffType.h"
@@ -11,7 +12,7 @@
 
 namespace Egametang {
 
-NodeFactories::NodeFactories(): factories(2000, (BehaviorNodeFactoryIf*)(NULL))
+NodeFactories::NodeFactories(): factories(2000, (BehaviorNodeFactoryIf*)(NULL))
 {
 	// 节点
 	factories[SEQUENCE] = new SequenceNodeFactory();
@@ -20,10 +21,10 @@ NodeFactories::NodeFactories(): factories(2000, (BehaviorNodeFactoryIf*)(NULL))
 
 	// 叶子节点
 	factories[BUFF_TYPE] = new BuffTypeFactory();
-	factories[CHANGE_HEALTH] = new ChangeHealthFactory();
-}
+	factories[CHANGE_HEALTH] = new ChangeHealthFactory();
+}
 
-NodeFactories::~NodeFactories()
+NodeFactories::~NodeFactories()
 {
 	for (std::size_t i = 0; i < factories.size(); ++i)
 	{
@@ -32,15 +33,15 @@ NodeFactories::~NodeFactories()
 			continue;
 		}
 		delete factories[i];
-	}
+	}
 }
 
-BehaviorNode* NodeFactories::GetInstance(const BehaviorNodeConf& conf)
+BehaviorNode* NodeFactories::GetInstance(const BehaviorNodeConf& conf)
 {
 	int32 type = conf.type();
-	return factories[type]->GetInstance(conf);
-}
-
-}
-
+	return factories[type]->GetInstance(conf);
+}
+
+}
+
 

+ 3 - 3
Cpp/Game/BehaviorTree/NotNode.cc

@@ -7,10 +7,10 @@ namespace Egametang {
 NotNode::NotNode(int32 type): BehaviorNode(type), node(NULL)
 {
 }
-
-NotNode::~NotNode()
+
+NotNode::~NotNode()
 {
-	delete node;
+	delete node;
 }
 
 bool NotNode::Run(ContexIf* contex)

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

@@ -7,8 +7,9 @@
 
 namespace Egametang {
 
-struct MethodInfo
+class MethodInfo
 {
+public:
 	RpcServicePtr service;
 	const google::protobuf::MethodDescriptor* methodDescriptor;
 	const google::protobuf::Message* requestPrototype;

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

@@ -46,7 +46,7 @@ void RpcClient::OnRecvMessage(RpcMetaPtr meta, StringPtr message)
 
 	// meta和message可以循环利用
 	RecvMeta(meta, message);
-	// 回调放在函数最.如果RecvMeta()放在回调之后,
+	// 回调放在函数最.如果RecvMeta()放在回调之后,
 	// 另外线程可能让io_service stop,导致RecvMeta还未跑完
 	// 网络就终止了
 	requestHandler->Run();

+ 2 - 1
Cpp/Platform/Rpc/RpcClient.h

@@ -1,10 +1,11 @@
 #ifndef RPC_RPCCLIENT_H
 #define RPC_RPCCLIENT_H
 
-#include <google/protobuf/service.h>
 #include <boost/unordered_map.hpp>
+#include <boost/enable_shared_from_this.hpp>
 #include <boost/asio.hpp>
 #include <boost/thread.hpp>
+#include <google/protobuf/service.h>
 #include "Base/Typedef.h"
 #include "Rpc/RpcTypedef.h"
 #include "Rpc/RpcCommunicator.h"

+ 2 - 4
Cpp/Platform/Rpc/RpcCommunicator.h

@@ -12,15 +12,13 @@
 
 namespace Egametang {
 
-struct RpcMeta
+class RpcMeta
 {
-	// message长度
+public:
 	std::size_t size;
 
-	// 消息id, 用于处理异步回调
 	std::size_t id;
 
-	// 消息opcode, 是proto的full_path哈希值
 	std::size_t method;
 
 	RpcMeta(): size(0), id(0), method(0)

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

@@ -52,7 +52,7 @@ void RpcServer::OnAsyncAccept(RpcSessionPtr session, const boost::system::error_
 
 void RpcServer::OnCallMethod(RpcSessionPtr session, ResponseHandlerPtr responseHandler)
 {
-	// 调度到网络线
+	// 调度到网络线
 	session->Socket().get_io_service().post(
 			boost::bind(&ResponseHandler::Run, responseHandler));
 }

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

@@ -4,6 +4,7 @@
 #include <boost/function.hpp>
 #include <boost/unordered_set.hpp>
 #include <boost/unordered_map.hpp>
+#include <boost/enable_shared_from_this.hpp>
 #include <google/protobuf/service.h>
 #include "Base/Marcos.h"
 #include "Thread/ThreadPool.h"