diff --git a/CMakeLists.txt b/CMakeLists.txt index 25e1db4e35..7d7a426cdf 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -116,4 +116,5 @@ else() add_subdirectory(Dependencies) add_subdirectory(NFComm) add_subdirectory(NFServer) + add_subdirectory(Tutorial) endif() diff --git a/NFComm/NFKernelPlugin/NFScheduleModule.cpp b/NFComm/NFKernelPlugin/NFScheduleModule.cpp index e0cc3f9bae..57a4fdd0a1 100644 --- a/NFComm/NFKernelPlugin/NFScheduleModule.cpp +++ b/NFComm/NFKernelPlugin/NFScheduleModule.cpp @@ -25,27 +25,17 @@ #include "NFScheduleModule.h" -void NFScheduleElement::DoHeartBeatEvent() +void NFScheduleElement::DoHeartBeatEvent(NFINT64 nowTime) { - if (self.IsNull()) - { - MODULE_SCHEDULE_FUNCTOR_PTR cb; - bool bRet = this->mxModuleFunctor.First(cb); - while (bRet) - { - cb.get()->operator()(mstrScheduleName, mfIntervalTime, mnRemainCount); - bRet = this->mxModuleFunctor.Next(cb); - } - } - else + mnRemainCount--; + mnTriggerTime = nowTime + (NFINT64)(mfIntervalTime * 1000); + + OBJECT_SCHEDULE_FUNCTOR_PTR cb; + bool bRet = this->mxObjectFunctor.First(cb); + while (bRet) { - OBJECT_SCHEDULE_FUNCTOR_PTR cb; - bool bRet = this->mxObjectFunctor.First(cb); - while (bRet) - { - cb.get()->operator()(self, mstrScheduleName, mfIntervalTime, mnRemainCount); - bRet = this->mxObjectFunctor.Next(cb); - } + cb.get()->operator()(self, mstrScheduleName, mfIntervalTime, mnRemainCount); + bRet = this->mxObjectFunctor.Next(cb); } } @@ -65,266 +55,114 @@ bool NFScheduleModule::Init() m_pKernelModule = pPluginManager->FindModule(); m_pKernelModule->RegisterCommonClassEvent(this, &NFScheduleModule::OnClassCommonEvent); + return true; } bool NFScheduleModule::Execute() { - /* - we would optimize this function by saving a schedule element list by time sorting, then - we can pick the toppest schedule element to check the time to save the costs of CPU. - */ - NFPerformance performanceObject; - NFINT64 nNow = NFGetTimeMS(); - - //execute all tasks - NF_SHARE_PTR> xObjectSchedule = mObjectScheduleMap.First(); - while (xObjectSchedule) - { - std::string str; - NF_SHARE_PTR pSchedule = xObjectSchedule->First(); - while (pSchedule) - { - if (nNow > pSchedule->mnNextTriggerTime) - { - if (pSchedule->mnRemainCount > 0 || pSchedule->mbForever == true) - { - if (!pSchedule->mbForever) - { - pSchedule->mnRemainCount--; - } - - pSchedule->DoHeartBeatEvent(); - - if (pSchedule->mnRemainCount <= 0 && pSchedule->mbForever == false) - { - mObjectRemoveList.push_back(pSchedule); - } - else - { - NFINT64 nNextCostTime = NFINT64(pSchedule->mfIntervalTime * 1000); - pSchedule->mnNextTriggerTime = nNow + nNextCostTime; - } - } - } - - pSchedule = xObjectSchedule->Next(); - } + NFINT64 nowTime = NFGetTimeMS(); - xObjectSchedule = mObjectScheduleMap.Next(); - } + std::list elements; - //remove schedule - for (auto it = mObjectRemoveList.begin(); it != mObjectRemoveList.end(); ++it) + for (auto it = mScheduleMap.begin(); it != mScheduleMap.end();) { - NF_SHARE_PTR scheduleElement = *it; - if (scheduleElement) + if (nowTime >= it->triggerTime) { - NFGUID self = scheduleElement->self; - const std::string& scheduleName = scheduleElement->mstrScheduleName; + //std::cout << nowTime << it->scheduleName << ">>>>>" << it->triggerTime << std::endl; - auto findIter = mObjectScheduleMap.GetElement(self); - if (NULL != findIter) + auto objectMap = mObjectScheduleMap.GetElement(it->self); + if (objectMap) { - findIter->RemoveElement(scheduleName); - if (findIter->Count() <= 0) + auto scheduleElement = objectMap->GetElement(it->scheduleName); + if (scheduleElement) { - mObjectScheduleMap.RemoveElement(self); - } - } - } - } - - mObjectRemoveList.clear(); - - //add schedule - for (std::list::iterator iter = mObjectAddList.begin(); iter != mObjectAddList.end(); ++iter) - { - NF_SHARE_PTR< NFMapEx > xObjectScheduleMap = mObjectScheduleMap.GetElement(iter->self); - if (NULL == xObjectScheduleMap) - { - xObjectScheduleMap = NF_SHARE_PTR< NFMapEx >(NF_NEW NFMapEx ()); - mObjectScheduleMap.AddElement(iter->self, xObjectScheduleMap); - } - - NF_SHARE_PTR xScheduleElement = xObjectScheduleMap->GetElement(iter->mstrScheduleName); - if (NULL == xScheduleElement) - { - xScheduleElement = NF_SHARE_PTR(NF_NEW NFScheduleElement()); - *xScheduleElement = *iter; - - xObjectScheduleMap->AddElement(iter->mstrScheduleName, xScheduleElement); - } - } - - mObjectAddList.clear(); - - if (performanceObject.CheckTimePoint(5)) - { - std::ostringstream os; - os << "---------------object schedule performance problem "; - os << performanceObject.TimeScope(); - os << "---------- "; - //m_pLogModule->LogWarning(NFGUID(), os, __FUNCTION__, __LINE__); - } - - //////////////////////////////////////////// - //execute all tasks - - NFPerformance performanceModule; + scheduleElement->DoHeartBeatEvent(nowTime); - NF_SHARE_PTR< NFScheduleElement > xModuleSchedule = mModuleScheduleMap.First(); - while (xModuleSchedule) - { - NFINT64 nNow = NFGetTimeMS(); - if (nNow > xModuleSchedule->mnNextTriggerTime) - { - if (xModuleSchedule->mnRemainCount > 0 || xModuleSchedule->mbForever == true) - { - if (!xModuleSchedule->mbForever) - { - xModuleSchedule->mnRemainCount--; - } - - xModuleSchedule->DoHeartBeatEvent(); + if (scheduleElement->mnRemainCount != 0) + { + TickElement element; + element.scheduleName = scheduleElement->mstrScheduleName; + element.triggerTime = scheduleElement->mnTriggerTime; + element.self = scheduleElement->self; - if (xModuleSchedule->mnRemainCount <= 0 && xModuleSchedule->mbForever == false) - { - mModuleRemoveList.push_back(xModuleSchedule->mstrScheduleName); - } - else - { - NFINT64 nNextCostTime = NFINT64(xModuleSchedule->mfIntervalTime * 1000); - xModuleSchedule->mnNextTriggerTime = nNow + nNextCostTime; + elements.push_back(element); + } } } - } - xModuleSchedule = mModuleScheduleMap.Next(); - } - - //remove schedule - for (std::list::iterator it = mModuleRemoveList.begin(); it != mModuleRemoveList.end(); ++it) - { - const std::string& strSheduleName = *it;; - auto findIter = mModuleScheduleMap.GetElement(strSheduleName); - if (NULL != findIter) + it = mScheduleMap.erase(it); + } + else { - mModuleScheduleMap.RemoveElement(strSheduleName); + break; } } - mModuleRemoveList.clear(); - - //add schedule - for (std::list::iterator iter = mModuleAddList.begin(); iter != mModuleAddList.end(); ++iter) + for (auto& item : elements) { - NF_SHARE_PTR< NFScheduleElement > xModuleScheduleMap = mModuleScheduleMap.GetElement(iter->mstrScheduleName); - if (NULL == xModuleScheduleMap) - { - xModuleScheduleMap = NF_SHARE_PTR< NFScheduleElement >(NF_NEW NFScheduleElement()); - mModuleScheduleMap.AddElement(iter->mstrScheduleName, xModuleScheduleMap); - } - - *xModuleScheduleMap = *iter; + mScheduleMap.insert(item); } - mModuleAddList.clear(); - - if (performanceModule.CheckTimePoint(5)) + if (performanceObject.CheckTimePoint(1)) { std::ostringstream os; os << "---------------module schedule performance problem "; - os << performanceModule.TimeScope(); + os << performanceObject.TimeScope(); os << "---------- "; - //m_pLogModule->LogWarning(NFGUID(), os, __FUNCTION__, __LINE__); + m_pLogModule->LogWarning(NFGUID(), os, __FUNCTION__, __LINE__); } return true; } -bool NFScheduleModule::AddSchedule(const std::string & strScheduleName, const MODULE_SCHEDULE_FUNCTOR_PTR & cb, const float fTime, const int nCount) +bool NFScheduleModule::AddSchedule(const NFGUID self, const std::string& strScheduleName, const OBJECT_SCHEDULE_FUNCTOR_PTR& cb, const float fTime, const int nCount) { - NFScheduleElement xSchedule; - xSchedule.mstrScheduleName = strScheduleName; - xSchedule.mfIntervalTime = fTime; - xSchedule.mnNextTriggerTime = NFGetTimeMS() + (NFINT64)(fTime * 1000); - xSchedule.mnStartTime = NFGetTimeMS(); - xSchedule.mnRemainCount = nCount; - xSchedule.mnAllCount = nCount; - xSchedule.self = NFGUID(); - if (nCount < 0) + auto objectMap = mObjectScheduleMap.GetElement(self); + if (!objectMap) { - xSchedule.mbForever = true; + objectMap = NF_SHARE_PTR< NFMapEx >(NF_NEW NFMapEx ()); + mObjectScheduleMap.AddElement(self, objectMap); } - xSchedule.mxModuleFunctor.Add(cb); - - mModuleAddList.push_back(xSchedule); - - return true; -} + auto scheduleObject = objectMap->GetElement(strScheduleName); + if (!scheduleObject) + { + scheduleObject = NF_SHARE_PTR(NF_NEW NFScheduleElement()); + scheduleObject->mstrScheduleName = strScheduleName; + scheduleObject->mfIntervalTime = fTime; + scheduleObject->mnTriggerTime = NFGetTimeMS() + (NFINT64)(fTime * 1000); + scheduleObject->mnRemainCount = nCount; + scheduleObject->self = self; -bool NFScheduleModule::AddSchedule(const std::string & strScheduleName, const MODULE_SCHEDULE_FUNCTOR_PTR & cb, const int nCount, const NFDateTime & date) -{ - return false; -} -bool NFScheduleModule::RemoveSchedule(const std::string & strScheduleName) -{ - mModuleRemoveList.push_back(strScheduleName); + scheduleObject->mxObjectFunctor.Add(cb); - return true; -} + objectMap->AddElement(strScheduleName, scheduleObject); -bool NFScheduleModule::ExistSchedule(const std::string & strScheduleName) -{ - return mModuleScheduleMap.ExistElement(strScheduleName); -} + TickElement tickElement; + tickElement.scheduleName = scheduleObject->mstrScheduleName; + tickElement.triggerTime = scheduleObject->mnTriggerTime; + tickElement.self = scheduleObject->self; -bool NFScheduleModule::AddSchedule(const NFGUID self, const std::string& strScheduleName, const OBJECT_SCHEDULE_FUNCTOR_PTR& cb, const float fTime, const int nCount) -{ - NFScheduleElement xSchedule; - xSchedule.mstrScheduleName = strScheduleName; - xSchedule.mfIntervalTime = fTime; - xSchedule.mnNextTriggerTime = NFGetTimeMS() + (NFINT64)(fTime * 1000); - xSchedule.mnStartTime = NFGetTimeMS(); - xSchedule.mnRemainCount = nCount; - xSchedule.mnAllCount = nCount; - xSchedule.self = self; - if (nCount < 0) - { - xSchedule.mbForever = true; + mScheduleMap.insert(tickElement); } - xSchedule.mxObjectFunctor.Add(cb); - - mObjectAddList.push_back(xSchedule); - return true; } -bool NFScheduleModule::AddSchedule(const NFGUID self, const std::string & strScheduleName, const OBJECT_SCHEDULE_FUNCTOR_PTR & cb, const int nCount, const NFDateTime & date) -{ - //we would store this kind of schedule in database - return false; -} - bool NFScheduleModule::RemoveSchedule(const NFGUID self) { - //is there will be deleted when using? return mObjectScheduleMap.RemoveElement(self); } bool NFScheduleModule::RemoveSchedule(const NFGUID self, const std::string& strScheduleName) { - NF_SHARE_PTR pScheduleElement = GetSchedule(self, strScheduleName); - if (pScheduleElement) + auto objectMap = mObjectScheduleMap.GetElement(self); + if (objectMap) { - mObjectRemoveList.push_back(pScheduleElement); - - return true; + return objectMap->RemoveElement(strScheduleName); } return false; @@ -332,13 +170,13 @@ bool NFScheduleModule::RemoveSchedule(const NFGUID self, const std::string& strS bool NFScheduleModule::ExistSchedule(const NFGUID self, const std::string& strScheduleName) { - NF_SHARE_PTR< NFMapEx > xObjectScheduleMap = mObjectScheduleMap.GetElement(self); - if (NULL == xObjectScheduleMap) + auto objectScheduleMap = mObjectScheduleMap.GetElement(self); + if (NULL == objectScheduleMap) { return false; } - return xObjectScheduleMap->ExistElement(strScheduleName); + return objectScheduleMap->ExistElement(strScheduleName); } NF_SHARE_PTR NFScheduleModule::GetSchedule(const NFGUID self, const std::string & strScheduleName) @@ -361,4 +199,4 @@ int NFScheduleModule::OnClassCommonEvent(const NFGUID & self, const std::string } return 0; -} +} \ No newline at end of file diff --git a/NFComm/NFKernelPlugin/NFScheduleModule.h b/NFComm/NFKernelPlugin/NFScheduleModule.h index 15acffd2fd..0604e963f2 100644 --- a/NFComm/NFKernelPlugin/NFScheduleModule.h +++ b/NFComm/NFKernelPlugin/NFScheduleModule.h @@ -26,6 +26,9 @@ #ifndef NF_SCHEDULE_MODULE_H #define NF_SCHEDULE_MODULE_H +#include +#include +#include #include "NFComm/NFCore/NFMap.hpp" #include "NFComm/NFCore/NFList.hpp" #include "NFComm/NFCore/NFPerformance.hpp" @@ -35,6 +38,20 @@ #include "NFComm/NFPluginModule/NFILogModule.h" #include "NFComm/NFPluginModule/NFIKernelModule.h" +class TickElement +{ +public: + + bool operator< (const TickElement& b) const + { + return triggerTime < b.triggerTime; + } + + std::string scheduleName; + NFINT64 triggerTime; + NFGUID self; +}; + class NFScheduleModule : public NFIScheduleModule { public: @@ -45,14 +62,7 @@ class NFScheduleModule : public NFIScheduleModule virtual bool Init(); virtual bool Execute(); - virtual bool AddSchedule(const std::string& strScheduleName, const MODULE_SCHEDULE_FUNCTOR_PTR& cb, const float fTime, const int nCount); - virtual bool AddSchedule(const std::string& strScheduleName, const MODULE_SCHEDULE_FUNCTOR_PTR& cb, const int nCount, const NFDateTime& date); - virtual bool RemoveSchedule(const std::string& strScheduleName); - virtual bool ExistSchedule(const std::string& strScheduleName); - - virtual bool AddSchedule(const NFGUID self, const std::string& strScheduleName, const OBJECT_SCHEDULE_FUNCTOR_PTR& cb, const float fTime, const int nCount); - virtual bool AddSchedule(const NFGUID self, const std::string& strScheduleName, const OBJECT_SCHEDULE_FUNCTOR_PTR& cb, const int nCount, const NFDateTime& date); virtual bool RemoveSchedule(const NFGUID self); virtual bool RemoveSchedule(const NFGUID self, const std::string& strScheduleName); virtual bool ExistSchedule(const NFGUID self, const std::string& strScheduleName); @@ -62,13 +72,9 @@ class NFScheduleModule : public NFIScheduleModule int OnClassCommonEvent(const NFGUID & self, const std::string & strClassName, const CLASS_OBJECT_EVENT eClassEvent, const NFDataList & var); protected: - NFMapEx> mObjectScheduleMap;//guid_scheduleName_element - std::list mObjectAddList; - std::list< NF_SHARE_PTR > mObjectRemoveList; + NFMapEx> mObjectScheduleMap; - NFMapEx mModuleScheduleMap;//guid_scheduleName_element - std::list mModuleAddList; - std::list mModuleRemoveList; + std::multiset mScheduleMap; NFILogModule* m_pLogModule; NFIKernelModule* m_pKernelModule; diff --git a/NFComm/NFLuaScriptPlugin/NFLuaScriptModule.cpp b/NFComm/NFLuaScriptPlugin/NFLuaScriptModule.cpp index 27fa7adc0f..998f369325 100644 --- a/NFComm/NFLuaScriptPlugin/NFLuaScriptModule.cpp +++ b/NFComm/NFLuaScriptPlugin/NFLuaScriptModule.cpp @@ -392,7 +392,7 @@ bool NFLuaScriptModule::AddModuleSchedule(std::string& strHeartBeatName, const L { if (AddLuaFuncToMap(mxLuaHeartBeatCallBackFuncMap, strHeartBeatName, luaFuncName)) { - return m_pScheduleModule->AddSchedule(strHeartBeatName, this, &NFLuaScriptModule::OnLuaHeartBeatCB, fTime, nCount); + return m_pScheduleModule->AddSchedule(NFGUID(), strHeartBeatName, this, &NFLuaScriptModule::OnLuaHeartBeatCB, fTime, nCount); } } diff --git a/NFComm/NFMessageDefine/NFDefine.pb.cc b/NFComm/NFMessageDefine/NFDefine.pb.cc index 8417015bfb..9240c49645 100644 --- a/NFComm/NFMessageDefine/NFDefine.pb.cc +++ b/NFComm/NFMessageDefine/NFDefine.pb.cc @@ -37,7 +37,7 @@ const char descriptor_table_protodef_NFDefine_2eproto[] PROTOBUF_SECTION_VARIABL "NG\020s\022\024\n\020CHARACTER_LOCKED\020t\022\021\n\rZONE_OVERL" "OAD\020u\022\016\n\nNOT_ONLINE\020v*\302\021\n\nEGameMsgID\022\n\n\006" "UNKNOW\020\000\022\020\n\014EVENT_RESULT\020\001\022\023\n\017EVENT_TRAN" - "SPOND\020\002\022\020\n\014CLOSE_SOCKET\020\003\022\030\n\024WTM_WORLD_R" + "SPORT\020\002\022\020\n\014CLOSE_SOCKET\020\003\022\030\n\024WTM_WORLD_R" "EGISTERED\020\n\022\032\n\026WTM_WORLD_UNREGISTERED\020\013\022" "\025\n\021WTM_WORLD_REFRESH\020\014\022\030\n\024LTM_LOGIN_REGI" "STERED\020\024\022\032\n\026LTM_LOGIN_UNREGISTERED\020\025\022\025\n\021" diff --git a/NFComm/NFMessageDefine/NFDefine.pb.h b/NFComm/NFMessageDefine/NFDefine.pb.h index adfb2f200d..d628ab2b10 100644 --- a/NFComm/NFMessageDefine/NFDefine.pb.h +++ b/NFComm/NFMessageDefine/NFDefine.pb.h @@ -103,7 +103,7 @@ inline bool EGameEventCode_Parse( enum EGameMsgID : int { UNKNOW = 0, EVENT_RESULT = 1, - EVENT_TRANSPOND = 2, + EVENT_TRANSPORT = 2, CLOSE_SOCKET = 3, WTM_WORLD_REGISTERED = 10, WTM_WORLD_UNREGISTERED = 11, diff --git a/NFComm/NFMessageDefine/NFDefine.proto b/NFComm/NFMessageDefine/NFDefine.proto index 88b498bf27..006f42d1c9 100644 --- a/NFComm/NFMessageDefine/NFDefine.proto +++ b/NFComm/NFMessageDefine/NFDefine.proto @@ -33,7 +33,7 @@ enum EGameMsgID { UNKNOW = 0; // EVENT_RESULT = 1; // for events - EVENT_TRANSPOND = 2; // for events + EVENT_TRANSPORT = 2; // for events CLOSE_SOCKET = 3; // want to close some one WTM_WORLD_REGISTERED = 10; diff --git a/NFComm/NFPluginModule/NFIScheduleModule.h b/NFComm/NFPluginModule/NFIScheduleModule.h index 8a516f30a8..30da82f796 100644 --- a/NFComm/NFPluginModule/NFIScheduleModule.h +++ b/NFComm/NFPluginModule/NFIScheduleModule.h @@ -33,12 +33,9 @@ #include "NFComm/NFCore/NFDataList.hpp" #include "NFComm/NFCore/NFDateTime.hpp" #include "NFComm/NFPluginModule/NFIModule.h" - +//int ScheduleFunction(const NFGUID& self, const std::string& name, const float time, const int count); typedef std::function OBJECT_SCHEDULE_FUNCTOR; -typedef std::function MODULE_SCHEDULE_FUNCTOR; - typedef NF_SHARE_PTR OBJECT_SCHEDULE_FUNCTOR_PTR;//HEART -typedef NF_SHARE_PTR MODULE_SCHEDULE_FUNCTOR_PTR;//HEART class NFScheduleElement @@ -48,31 +45,28 @@ class NFScheduleElement { mstrScheduleName = ""; mfIntervalTime = 0.0f; - mnNextTriggerTime = 0; - mnStartTime = 0; - mnRemainCount = 0; - mnAllCount = 0; - mbForever = false; + mnTriggerTime = 0; + mnRemainCount = -1; + + static NFINT64 elementID = 0; + id = elementID++; }; virtual ~NFScheduleElement() { } - void DoHeartBeatEvent(); + void DoHeartBeatEvent(NFINT64 nowTime); std::string mstrScheduleName; float mfIntervalTime; - NFINT64 mnNextTriggerTime; - NFINT64 mnStartTime; + NFINT64 mnTriggerTime; int mnRemainCount; - int mnAllCount; - bool mbForever; + NFINT64 id; NFGUID self; NFList mxObjectFunctor; - NFList mxModuleFunctor; }; class NFIScheduleModule @@ -81,18 +75,6 @@ class NFIScheduleModule public: virtual ~NFIScheduleModule() {} - ///for module - virtual bool RemoveSchedule(const std::string& strScheduleName) = 0; - virtual bool ExistSchedule(const std::string& strScheduleName) = 0; - - template - bool AddSchedule(const std::string& strScheduleName, BaseType* pBase, int (BaseType::*handler)(const std::string&, const float, const int), const float fIntervalTime, const int nCount) - { - MODULE_SCHEDULE_FUNCTOR functor = std::bind(handler, pBase, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3); - MODULE_SCHEDULE_FUNCTOR_PTR functorPtr(NF_NEW MODULE_SCHEDULE_FUNCTOR(functor)); - return AddSchedule(strScheduleName, functorPtr, fIntervalTime, nCount); - } - ///for object virtual bool RemoveSchedule(const NFGUID self) = 0; virtual bool RemoveSchedule(const NFGUID self, const std::string& strScheduleName) = 0; @@ -108,11 +90,7 @@ class NFIScheduleModule } protected: - virtual bool AddSchedule(const std::string& strScheduleName, const MODULE_SCHEDULE_FUNCTOR_PTR& cb, const float fTime, const int nCount) = 0; - virtual bool AddSchedule(const std::string& strScheduleName, const MODULE_SCHEDULE_FUNCTOR_PTR& cb, const int nCount, const NFDateTime& date) = 0; - virtual bool AddSchedule(const NFGUID self, const std::string& strScheduleName, const OBJECT_SCHEDULE_FUNCTOR_PTR& cb, const float fTime, const int nCount) = 0; - virtual bool AddSchedule(const NFGUID self, const std::string& strScheduleName, const OBJECT_SCHEDULE_FUNCTOR_PTR& cb, const int nCount, const NFDateTime& date) = 0; }; #endif diff --git a/NFServer/NFGameServerPlugin/NFSceneProcessModule.cpp b/NFServer/NFGameServerPlugin/NFSceneProcessModule.cpp index e416d55396..ed6116535a 100644 --- a/NFServer/NFGameServerPlugin/NFSceneProcessModule.cpp +++ b/NFServer/NFGameServerPlugin/NFSceneProcessModule.cpp @@ -138,13 +138,17 @@ int NFSceneProcessModule::BeforeLeaveSceneGroupEvent(const NFGUID & self, const int NFSceneProcessModule::AfterLeaveSceneGroupEvent(const NFGUID & self, const int nSceneID, const int nGroupID, const int nType, const NFDataList & argList) { NFMsg::ESceneType eSceneType = (NFMsg::ESceneType)m_pElementModule->GetPropertyInt32(std::to_string(nSceneID), NFrame::Scene::Type()); - if (eSceneType == NFMsg::ESceneType::SINGLE_CLONE_SCENE) + if (eSceneType == NFMsg::ESceneType::NORMAL_SCENE) + { + + } + else if (eSceneType == NFMsg::ESceneType::SINGLE_CLONE_SCENE) { m_pKernelModule->ReleaseGroupScene(nSceneID, nGroupID); return 0; } - else if (eSceneType == NFMsg::ESceneType::MULTI_CLONE_SCENE) + else { NFDataList varObjectList; if (m_pKernelModule->GetGroupObjectList(nSceneID, nGroupID, varObjectList, true) && varObjectList.GetCount() <= 0) diff --git a/Tutorial/Tutorial3/HelloWorld3Module.cpp b/Tutorial/Tutorial3/HelloWorld3Module.cpp index 08c3a985a0..3ad5d4d10d 100644 --- a/Tutorial/Tutorial3/HelloWorld3Module.cpp +++ b/Tutorial/Tutorial3/HelloWorld3Module.cpp @@ -29,15 +29,14 @@ bool NFHelloWorld3Module::Init() { - std::cout << "Hello, world3, Init" << std::endl; + m_pScheduleModule->AddSchedule(NFGUID(), "OnHeartBe22222", this, &NFHelloWorld3Module::OnHeartBeat, 6.0f, 10 ); return true; } int NFHelloWorld3Module::OnEvent(const NFGUID& self, const int event, const NFDataList& arg) { - std::cout << "OnEvent EventID: " << event << " self: " << self.nData64 << " argList: " << arg.Int(0) << " " << " " << arg.String(1) << std::endl; m_pKernelModule->SetPropertyInt(self, "Hello", arg.Int(0)); @@ -51,7 +50,7 @@ int NFHelloWorld3Module::OnHeartBeat(const NFGUID& self, const std::string& strH int64_t unNowTime = NFGetTimeMS(); - std::cout << "strHeartBeat: " << fTime << " Count: " << nCount << " TimeDis: " << unNowTime - mLastTime << std::endl; + std::cout << self.ToString() + " strHeartBeat: " << fTime << " Count: " << nCount << " TimeDis: " << unNowTime - mLastTime << std::endl; mLastTime = unNowTime;