Skip to content

Commit

Permalink
3.6.29
Browse files Browse the repository at this point in the history
  • Loading branch information
cainhuang committed Apr 11, 2017
1 parent 3d228e7 commit 62470ac
Show file tree
Hide file tree
Showing 82 changed files with 749 additions and 967 deletions.
13 changes: 7 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ cmake_minimum_required (VERSION 2.8)
# set(CMAKE_CONFIGURATION_TYPES "Debug;Release;Profile" CACHE STRING "" FORCE)
set(CMAKE_CONFIGURATION_TYPES "Debug;Release" CACHE STRING "" FORCE)

set (BEHAVIAC_PACKAGE_VERSION 3.6.28)
set (BEHAVIAC_PACKAGE_VERSION 3.6.29)

#option( BUILD_SHARED_LIBS "set to OFF to build static libraries" ON )
SET(BUILD_SHARED_LIBS ON CACHE BOOL "set to OFF to build static libraries")
Expand Down Expand Up @@ -267,11 +267,12 @@ set (COMPILE_POSTFIX "")
if(MSVC OR BEHAVIAC_ANDROID_ON)
message(STATUS "set msvc flags")
# Force to always compile with W4
if(CMAKE_CXX_FLAGS MATCHES "/W[0-4]")
STRING(REGEX REPLACE "/W[0-4]" "/W4" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4")
endif()
# if(CMAKE_CXX_FLAGS MATCHES "/W[0-4]")
# STRING(REGEX REPLACE "/W[0-4]" "/W4" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
# else()
# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4")
# endif()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4")

#warning treated as error
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /WX")
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
[![License](https://img.shields.io/badge/License-BSD%203--Clause-blue.svg)](https://github.com/Tencent/behaviac/blob/master/license.txt)
[![Release Version](https://img.shields.io/badge/release-3.6.28-red.svg)](https://github.com/Tencent/behaviac/releases)
[![Release Version](https://img.shields.io/badge/release-3.6.29-red.svg)](https://github.com/Tencent/behaviac/releases)
[![Updates](https://img.shields.io/badge/Platform-%20iOS%20%7C%20OS%20X%20%7C%20Android%20%7C%20Windows%20%7C%20Linux%20-brightgreen.svg)](https://github.com/Tencent/behaviac/blob/master/history.txt)
[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](https://github.com/Tencent/behaviac/pulls)

##[访问http://www.behaviac.com/获取文档,教程,API,FAQ,源码,下载等一切相关资料](http://www.behaviac.com/)
## [访问http://www.behaviac.com/获取文档,教程,API,FAQ,源码,下载等一切相关资料](http://www.behaviac.com/)

- behaviac是游戏AI的开发框架组件,也是游戏原型的快速设计工具
- 支持行为树BT,状态机FSM,HTN等多种范式
Expand All @@ -16,7 +16,7 @@


---------------------------------------------
##[Visist http://www.behaviac.com/ for documents, tutorials, FAQs and all other information](http://www.behaviac.com/)
## [Visist http://www.behaviac.com/ for documents, tutorials, FAQs and all other information](http://www.behaviac.com/)

- behaviac is a framework of the game AI development, and it also can be used as a rapid game prototype design tool
- behaviac supports the behavior tree, finite state machine and hierarchical task network
Expand Down
Binary file modified docs/behaviac.chm
Binary file not shown.
3 changes: 3 additions & 0 deletions history.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
2017-4-11 3.6.29
Fix a bug of compiling error for GCC.

2017-4-10 3.6.28
Improve generating the codes for the struct.
Add tutorial_8 and tutorial_9.
Expand Down
2 changes: 1 addition & 1 deletion inc/behaviac/common/_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@
#define BEHAVIAC_RELEASE 0
#endif

#define BEHAVIAC_VERSION_STRING "3.6.28"
#define BEHAVIAC_VERSION_STRING "3.6.29"

96 changes: 48 additions & 48 deletions inc/behaviac/common/factory.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ namespace behaviac {
}
};

typedef FactoryContainer_t::iterator CreatorIt;
typedef FactoryContainer_t::iterator IteratorCreator;

BEHAVIAC_API bool FactoryRegister_(FactoryContainer_t* creators, const CStringCRC& typeID, void* typeConstructor);
BEHAVIAC_API bool FactoryUnregister_(FactoryContainer_t* creators, const CStringCRC& typeID);
Expand All @@ -90,21 +90,20 @@ namespace behaviac {

public:
virtual ~CFactory() {
CreatorIt it(creators_.begin());
CreatorIt itEnd(creators_.end());
IteratorCreator it(creators_list_.begin());
IteratorCreator itEnd(creators_list_.end());

while (it != itEnd) {
SFactoryBag_t& item = *it++;
BEHAVIAC_FREE(item.m_typeConstructor);
}

creators_.m_vector.clear();
creators_list_.m_vector.clear();
}

virtual T* CreateObject(const CStringCRC& typeID);

typedef T* (*InstantiateFunctionPointer)(const CStringCRC& typeID);

bool IsRegistered(const CStringCRC& typeID);
bool Register(const CStringCRC& typeID, InstantiateFunctionPointer instantiate, bool overwrite = false);
bool UnRegister(const CStringCRC& typeID);

Expand All @@ -113,97 +112,98 @@ namespace behaviac {
typedef CConstructType<FINAL_TYPE> FinalType;
void* p = BEHAVIAC_MALLOC(sizeof(FinalType));
IConstructType* typeConstructor = new(p)FinalType;
return FactoryRegister_(&creators_, FINAL_TYPE::GetClassTypeId(), typeConstructor);
return FactoryRegister_(&creators_list_, FINAL_TYPE::GetClassTypeId(), typeConstructor);
}

template< typename FINAL_TYPE >
bool UnRegister() {
return FactoryUnregister_(&creators_, FINAL_TYPE::GetClassTypeId());
return FactoryUnregister_(&creators_list_, FINAL_TYPE::GetClassTypeId());
}

bool IsRegistered(const CStringCRC& typeID);

virtual T* CreateObject(const CStringCRC& typeID);
private:
FactoryContainer_t creators_;
FactoryContainer_t creators_list_;
};

template< typename T >
BEHAVIAC_FORCEINLINE bool CFactory<T>::IsRegistered(const CStringCRC& typeID) {
creators_.Lock();
creators_list_.Lock();
SFactoryBag_t bucket(typeID, NULL);
CreatorIt itEnd(creators_.end());
CreatorIt itFound(std::find(creators_.begin(), itEnd, bucket));
IteratorCreator itEnd(creators_list_.end());
IteratorCreator itFound(std::find(creators_list_.begin(), itEnd, bucket));

if (itFound != itEnd) {
creators_.Unlock();
creators_list_.Unlock();
return true;
} else {
creators_.Unlock();
creators_list_.Unlock();
return false;
}
}

template< typename T >
T* CFactory<T>::CreateObject(const CStringCRC& typeID) {
creators_.Lock();
SFactoryBag_t bucket(typeID, NULL);
CreatorIt itEnd(creators_.end());
CreatorIt itFound(std::find(creators_.begin(), itEnd, bucket));

if (itFound != itEnd) {
IConstructType* contructType = (IConstructType*)(*itFound).m_typeConstructor;
creators_.Unlock();
return contructType->Create();

} else {
BEHAVIAC_LOGWARNING("Trying to create an unregister type 0x%08X", typeID.GetUniqueID());

creators_.Unlock();
return NULL;
}
}

template< typename T >
bool CFactory<T>::Register(const CStringCRC& typeID, InstantiateFunctionPointer instantiate, bool overwrite) {
creators_.Lock();
creators_list_.Lock();
BEHAVIAC_ASSERT(instantiate);
SFactoryBag_t bucket(typeID, (void*)instantiate);
CreatorIt itEnd(creators_.end());
CreatorIt itFound(std::find(creators_.begin(), itEnd, bucket));
IteratorCreator itEnd(creators_list_.end());
IteratorCreator itFound(std::find(creators_list_.begin(), itEnd, bucket));
bool wasThere = (itFound != itEnd);

if (!wasThere) {
creators_.push_back(bucket);
creators_list_.push_back(bucket);

} else if (overwrite) {
*itFound = bucket;
creators_.Unlock();
creators_list_.Unlock();
return true;

} else {
BEHAVIAC_ASSERT(0, "Trying to register an already registered type %d", typeID.GetUniqueID());
}

creators_.Unlock();
creators_list_.Unlock();
return !wasThere;
}

template< typename T >
bool CFactory<T>::UnRegister(const CStringCRC& typeID) {
creators_.Lock();
creators_list_.Lock();
SFactoryBag_t bucket(typeID, NULL);
CreatorIt itEnd(creators_.end());
CreatorIt itFound(std::find(creators_.begin(), itEnd, bucket));
IteratorCreator itEnd(creators_list_.end());
IteratorCreator itFound(std::find(creators_list_.begin(), itEnd, bucket));

if (itFound != itEnd) {
creators_.erase(itFound);
creators_.Unlock();
creators_list_.erase(itFound);
creators_list_.Unlock();
return true;
}

BEHAVIAC_ASSERT("Cannot find the specified factory entry\n");
creators_.Unlock();
creators_list_.Unlock();
return false;
}

template< typename T >
T* CFactory<T>::CreateObject(const CStringCRC& typeID) {
creators_list_.Lock();
SFactoryBag_t bucket(typeID, NULL);
IteratorCreator itEnd(creators_list_.end());
IteratorCreator itFound(std::find(creators_list_.begin(), itEnd, bucket));

if (itFound != itEnd) {
IConstructType* contructType = (IConstructType*)(*itFound).m_typeConstructor;
creators_list_.Unlock();
return contructType->Create();

}
else {
BEHAVIAC_LOGWARNING("Trying to create an unregister type 0x%08X", typeID.GetUniqueID());

creators_list_.Unlock();
return NULL;
}
}

}//
#endif //_BEHAVIAC_COMMON_FACTORY_H_
6 changes: 1 addition & 5 deletions inc/behaviac/common/object/tagobject.h
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ namespace behaviac {
} \
behaviac::string ToString() const \
{ \
return behaviac::StringUtils::ToString_Struct(*this); \
return behaviac::StringUtils::ToString_Struct(*this, this->GetClassTypeName());\
}

/////////////////////////////////////////////////////////////////////////////////////////
Expand All @@ -180,8 +180,6 @@ namespace behaviac {
const char* szClassName = behaviac::GetClassTypeName((classFullNameWithNamespace*)0);\
behaviac::CTagObject::Save((behaviac::CTagObject*)this, node, szClassName); \
} \
static bool IsOfMyKind(const behaviac::CTagObject*) \
{ return true; } \
static const char* GetClassTypeName() { return #classFullNameWithNamespace; }

#define DECLARE_BEHAVIAC_OBJECT_STRUCT_V1(classFullNameWithNamespace) DECLARE_BEHAVIAC_OBJECT_STRUCT_V2(classFullNameWithNamespace, false)
Expand Down Expand Up @@ -230,8 +228,6 @@ namespace behaviac {
//in general, please use DECLARE_BEHAVIAC_STRUCT, unless you know what you are doing
#define BEHAVIAC_DECLARE_OBJECT(classFullNameWithNamespace) \
DECLARE_BEHAVIAC_OBJECT_BASE(classFullNameWithNamespace, false) \
static bool IsOfMyKind(const behaviac::CTagObject*) \
{ return true; } \
static const char* GetClassTypeName() \
{ return #classFullNameWithNamespace; }

Expand Down
Loading

0 comments on commit 62470ac

Please sign in to comment.