Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/ketoo/NoahGameFrame
Browse files Browse the repository at this point in the history
# Conflicts:
#	Tutorial/Tutorial2/HelloWorld2.cpp
#	Tutorial/Tutorial5/HelloWorld.cpp
  • Loading branch information
superzmy committed Aug 2, 2017
2 parents ac472da + 2945408 commit 83ac10e
Show file tree
Hide file tree
Showing 157 changed files with 3,520 additions and 7,696 deletions.
16 changes: 16 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
sudo: true
language: cpp

compiler:
- g++
os:
- linux

install:
- if [ "${TRAVIS_OS_NAME}" = "linux" ]; then sudo apt-get install -qq cmake; fi
- if [ "${TRAVIS_OS_NAME}" = "linux" ]; then sudo apt-get install -qq g++-4.8; fi
- if [ "${TRAVIS_OS_NAME}" = "linux" ]; then export CXX="g++-4.8"; fi

script:
- sudo chmod 777 *.sh
- bash -c ./install4cmake.sh
2 changes: 1 addition & 1 deletion Dependencies/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ add_subdirectory(Theron)
add_subdirectory(protobuf)
add_subdirectory(redis-cplusplus-client/msvc/anet_win32)
add_subdirectory(navigation)
add_subdirectory(libevent)
#add_subdirectory(libevent)
4 changes: 4 additions & 0 deletions Dependencies/build_dep.bat
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ echo Compiling libevent
call "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" amd64
cd libevent
nmake /f Makefile.nmake
copy libevent.lib ..\\lib\\Debug\\ /Y
copy libevent.lib ..\\lib\\Release\\ /Y
copy libevent_core.lib ..\\lib\\Debug\\ /Y
copy libevent_core.lib ..\\lib\\Release\\ /Y
cd ..


Expand Down
2 changes: 1 addition & 1 deletion Dependencies/build_dep.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ if [ -d ./libevent ]; then
fi
unzip -o libevent.zip -d ./

mv libevent-2.1.8-stable libevent
#mv libevent-2.1.8-stable libevent

# compiling libevent
cd libevent
Expand Down
Binary file modified Dependencies/libevent.zip
Binary file not shown.
106 changes: 84 additions & 22 deletions NFComm/NFActorPlugin/NFCActor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,52 +9,114 @@
#include "NFCActor.h"
#include "NFComm/NFPluginModule/NFIPluginManager.h"

NFCActor::NFCActor(Theron::Framework & framework, NFIActorModule* pModule)
: NFIActor(framework)
{
m_pActorModule = pModule;
}

NFCActor::~NFCActor()
{
}

void NFCActor::HandlerEx(const NFIActorMessage& message, const Theron::Address from)
{
m_pActorModule->HandlerEx(message, from.AsInteger());
}

void NFCActor::AddComponent(NF_SHARE_PTR<NFIComponent> pComponent)
{
mxComponent = pComponent;
mxComponent.AddElement(pComponent->GetComponentName(), pComponent);
pComponent->SetActor(this);

pComponent->Awake();
pComponent->Init();
pComponent->AfterInit();
pComponent->ReadyExecute();
}

void NFCActor::HandlerSelf(const NFIActorMessage& message, const Theron::Address from)
NF_SHARE_PTR<NFIComponent> NFCActor::FindComponent(const std::string & strComponentName)
{
std::string strData = message.data;
return mxComponent.GetElement(strComponentName);
}

if (mxComponent)
{
if (!mxComponent->HasInit())
{
mxComponent->SetHasInit(true);
bool NFCActor::AddBeginunc(const int nSubMsgID, ACTOR_PROCESS_FUNCTOR_PTR xBeginFunctor)
{
if (mxProcessFuntor.GetElement(nSubMsgID))
{
return false;
}

mxComponent->Init();
mxComponent->AfterInit();
}
mxProcessFuntor.AddElement(nSubMsgID, xBeginFunctor);
return true;
}

mxComponent->OnASyncEvent(message.self, message.nMsgID, strData);
bool NFCActor::AddEndFunc(const int nSubMsgID, ACTOR_PROCESS_FUNCTOR_PTR xEndFunctor)
{
if (mxProcessFuntor.GetElement(nSubMsgID))
{
return false;
}

}
if (nSubMsgID >= 0)
{
mxProcessFuntor.AddElement(nSubMsgID, xEndFunctor);
}
else
{
mxDefaultEndProcessFuntor = xEndFunctor;
}

return true;
}

void NFCActor::Handler(const NFIActorMessage& message, const Theron::Address from)
{
std::string strData = message.data;

ACTOR_PROCESS_FUNCTOR_PTR ptrBegin = mxProcessFuntor.GetElement(message.nMsgID);
if (ptrBegin != nullptr)
{

ACTOR_PROCESS_FUNCTOR* pFun = ptrBegin.get();
pFun->operator()(message.self, message.nFormActor, message.nMsgID, strData);
}
else
{
for (NF_SHARE_PTR<NFIComponent> pComponent = mxComponent.First(); pComponent != nullptr; pComponent = mxComponent.Next())
{
if (pComponent->Enable())
{
pComponent->OnASyncEvent(message.self, message.nFormActor, message.nMsgID, strData);
}
}
}

////////////////////////////////////////////////////////

// must return message
NFIActorMessage xReturnMessage;

xReturnMessage.bComponentMsg = false;
xReturnMessage.msgType = NFIActorMessage::ACTOR_MSG_TYPE_END_FUNC;
xReturnMessage.nMsgID = message.nMsgID;
xReturnMessage.data = strData;
xReturnMessage.self = message.self;
xReturnMessage.nFormActor = this->GetAddress().AsInteger();
xReturnMessage.xEndFuncptr = mxFunctorEndPtr;

Send(xReturnMessage, from);
}
ACTOR_PROCESS_FUNCTOR_PTR ptrEnd = mxEndProcessFuntor.GetElement(message.nMsgID);
if (ptrEnd != nullptr)
{
xReturnMessage.xEndFuncptr = ptrEnd;
}
else
{
//default end function
if (mxDefaultEndProcessFuntor != nullptr)
{
xReturnMessage.xEndFuncptr = mxDefaultEndProcessFuntor;
}
}

bool NFCActor::AddEndFunc(EVENT_ASYNC_PROCESS_END_FUNCTOR_PTR functorPtr_end)
{
mxFunctorEndPtr = functorPtr_end;
return true;
Send(xReturnMessage, from);
}

bool NFCActor::SendMsg(const Theron::Address address, const NFIActorMessage& message)
Expand Down
42 changes: 20 additions & 22 deletions NFComm/NFActorPlugin/NFCActor.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,40 +14,38 @@
#include "NFComm/NFCore/NFSingleton.hpp"
#include "NFComm/NFPluginModule/NFPlatform.h"
#include "NFComm/NFPluginModule/NFIActor.h"
#include "NFComm/NFCore/NFIComponent.h"
#include "NFComm/NFPluginModule/NFIComponent.h"
#include "NFComm/NFPluginModule/NFIActorModule.h"

class NFCActor
: public NFIActor
{
public:
NFCActor(Theron::Framework& framework, NFIActorModule* pManager) : NFIActor(framework, pManager)
{
NFCActor(Theron::Framework& framework, NFIActorModule* pModule);
virtual ~NFCActor();

}

~NFCActor()
{
if (mxComponent)
{
mxComponent->BeforeShut();
mxComponent->Shut();
}
}

//handler in main thread, the purpose is to push message to main thread
virtual void HandlerEx(const NFIActorMessage& message, const Theron::Address from);

virtual void AddComponent(NF_SHARE_PTR<NFIComponent> pComponent);
virtual NF_SHARE_PTR<NFIComponent> FindComponent(const std::string& strComponentName);

//hangler in component
virtual void HandlerSelf(const NFIActorMessage& message, const Theron::Address from);
virtual bool AddBeginunc(const int nSubMsgID, ACTOR_PROCESS_FUNCTOR_PTR xBeginFunctor);
virtual bool AddEndFunc(const int nSubMsgID, ACTOR_PROCESS_FUNCTOR_PTR xEndFunctor);

virtual void AddComponent(NF_SHARE_PTR<NFIComponent> pComponent);
virtual bool AddEndFunc(EVENT_ASYNC_PROCESS_END_FUNCTOR_PTR functorPtr_end);
virtual bool SendMsg(const Theron::Address address, const NFIActorMessage& message);

protected:
//handler in component
virtual void Handler(const NFIActorMessage& message, const Theron::Address from);

//handler in main thread, the purpose is to push message to main thread
virtual void HandlerEx(const NFIActorMessage& message, const Theron::Address from);

protected:
NF_SHARE_PTR<NFIComponent> mxComponent;
EVENT_ASYNC_PROCESS_END_FUNCTOR_PTR mxFunctorEndPtr;
NFMapEx<std::string, NFIComponent> mxComponent;

NFMapEx<int, ACTOR_PROCESS_FUNCTOR> mxProcessFuntor;
NFMapEx<int, ACTOR_PROCESS_FUNCTOR> mxEndProcessFuntor;

ACTOR_PROCESS_FUNCTOR_PTR mxDefaultEndProcessFuntor;
};
#endif
18 changes: 8 additions & 10 deletions NFComm/NFActorPlugin/NFCActorModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
// -------------------------------------------------------------------------

#include "NFCActorModule.h"
#include "NFComm/NFCore/NFIComponent.h"

NFCActorModule::NFCActorModule(NFIPluginManager* p)
{
Expand Down Expand Up @@ -62,7 +61,6 @@ bool NFCActorModule::Execute()

int NFCActorModule::RequireActor()
{

NF_SHARE_PTR<NFIActor> pActor(NF_NEW NFCActor(*m_pFramework, this));
mxActorMap.AddElement(pActor->GetAddress().AsInteger(), pActor);

Expand All @@ -76,7 +74,7 @@ NF_SHARE_PTR<NFIActor> NFCActorModule::GetActor(const int nActorIndex)

bool NFCActorModule::HandlerEx(const NFIActorMessage & message, const int from)
{
if (!message.bComponentMsg)
if (message.msgType != NFIActorMessage::ACTOR_MSG_TYPE_COMPONENT)
{
return mxQueue.Push(message);
}
Expand All @@ -91,9 +89,11 @@ bool NFCActorModule::ExecuteEvent()
bRet = mxQueue.Pop(xMsg);
while (bRet)
{
if (!xMsg.bComponentMsg)
if (xMsg.msgType != NFIActorMessage::ACTOR_MSG_TYPE_COMPONENT && xMsg.xEndFuncptr != nullptr)
{
xMsg.xEndFuncptr->operator()(xMsg.self, xMsg.nFormActor, xMsg.nMsgID, xMsg.data);
ACTOR_PROCESS_FUNCTOR* pFun = xMsg.xEndFuncptr.get();
pFun->operator()(xMsg.self, xMsg.nFormActor, xMsg.nMsgID, xMsg.data);

//Actor can be reused in ActorPool mode, so we don't release it.
//m_pActorManager->ReleaseActor(xMsg.nFormActor);
}
Expand All @@ -111,7 +111,7 @@ bool NFCActorModule::SendMsgToActor(const int nActorIndex, const NFGUID& objectI
{
NFIActorMessage xMessage;

xMessage.bComponentMsg = true;
xMessage.msgType = NFIActorMessage::ACTOR_MSG_TYPE_COMPONENT;
xMessage.data = strArg;
xMessage.nMsgID = nEventID;
xMessage.nFormActor = m_pMainActor->GetAddress().AsInteger();
Expand Down Expand Up @@ -141,14 +141,12 @@ bool NFCActorModule::ReleaseActor(const int nActorIndex)
return mxActorMap.RemoveElement(nActorIndex);
}

bool NFCActorModule::AddEndFunc(const int nActorIndex, EVENT_ASYNC_PROCESS_END_FUNCTOR_PTR functorPtr_end)
bool NFCActorModule::AddEndFunc(const int nActorIndex, const int nSubMsgID, ACTOR_PROCESS_FUNCTOR_PTR functorPtr)
{
NF_SHARE_PTR<NFIActor> pActor = GetActor(nActorIndex);
if (nullptr != pActor)
{
pActor->AddEndFunc(functorPtr_end);

return true;
return pActor->AddEndFunc(nSubMsgID, functorPtr);
}

return false;
Expand Down
11 changes: 7 additions & 4 deletions NFComm/NFActorPlugin/NFCActorModule.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#include <string>
#include "NFCActor.h"
#include "Theron/Theron.h"
#include "NFComm/NFCore/NFIComponent.h"
#include "NFComm/NFPluginModule/NFIComponent.h"
#include "NFComm/NFPluginModule/NFIActor.h"
#include "NFComm/NFPluginModule/NFIActorModule.h"
#include "NFComm/NFCore/NFQueue.hpp"
Expand All @@ -35,18 +35,21 @@ class NFCActorModule

virtual bool Execute();

virtual int RequireActor();

virtual bool SendMsgToActor(const int nActorIndex, const NFGUID& objectID, const int nEventID, const std::string& strArg);

virtual bool HandlerEx(const NFIActorMessage& message, const int from);

virtual bool ReleaseActor(const int nActorIndex);

protected:
virtual int RequireActor();
virtual NF_SHARE_PTR<NFIActor> GetActor(const int nActorIndex);

protected:

virtual bool AddEndFunc(const int nActorIndex, const int nSubMsgID, ACTOR_PROCESS_FUNCTOR_PTR functorPtr);

virtual bool AddComponent(const int nActorIndex, NF_SHARE_PTR<NFIComponent> pComponent);
virtual bool AddEndFunc(const int nActorIndex, EVENT_ASYNC_PROCESS_END_FUNCTOR_PTR functorPtr_end);

virtual bool ExecuteEvent();
private:
Expand Down
14 changes: 2 additions & 12 deletions NFComm/NFConfigPlugin/NFCClassModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ bool NFCClassModule::AddRecords(rapidxml::xml_node<>* pRecordRootNode, NF_SHARE_

bool NFCClassModule::AddComponents(rapidxml::xml_node<>* pComponentRootNode, NF_SHARE_PTR<NFIClass> pClass)
{
/*
for (rapidxml::xml_node<>* pComponentNode = pComponentRootNode->first_node(); pComponentNode; pComponentNode = pComponentNode->next_sibling())
{
if (pComponentNode)
Expand All @@ -233,7 +234,7 @@ bool NFCClassModule::AddComponents(rapidxml::xml_node<>* pComponentRootNode, NF_
}
}
}

*/
return true;
}

Expand Down Expand Up @@ -428,17 +429,6 @@ NF_SHARE_PTR<NFIRecordManager> NFCClassModule::GetClassRecordManager(const std::
return NULL;
}

NF_SHARE_PTR<NFIComponentManager> NFCClassModule::GetClassComponentManager(const std::string& strClassName)
{
NF_SHARE_PTR<NFIClass> pClass = GetElement(strClassName);
if (pClass)
{
return pClass->GetComponentManager();
}

return NULL;
}

bool NFCClassModule::Clear()
{
return true;
Expand Down
Loading

0 comments on commit 83ac10e

Please sign in to comment.