NoahFrame服务器端开发解决方案
NoahFrame(以下简称NFrame/NF)是一个容易开发、高性能的跨平台的服务器端开发解决方案。
主要特点:
-
跨平台
-
分布式架构
-
插件化、模块化
-
良好的对象与可配的数据管理
-
面向接口编程
-
数据的事件驱动
-
高性能,高并发(网络,actor,逻辑开发)
-
支持多种脚本语言(lua, python,js, c#)
-
简单配置,所有数据全面支持excel配置
-
excel数据转换配套工具(xls2xml等等)
-
匹配的U3D客户端源码
-
轻松上手,包学包会
示例代码:
Tutorial1 :hello world
Tutorial2 :事件驱动与数据驱动
Tutorial6:lua脚本运行示例
#include "HelloWorld3Module.h" #include "NFComm/NFCore/NFTimer.h" bool HelloWorld3Module::Init() { //初始化 std::cout << "Hello, world3, Init" << std::endl; return true; } int HelloWorld3Module::OnEvent(const NFIDENTID& self, const int event, const NFIDataList& 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)); m_pKernelModule->SetPropertyString(self, "Hello", arg.String(1)); return 0; } int HelloWorld3Module::OnHeartBeat(const NFIDENTID& self, const std::string& strHeartBeat, const float fTime, const int nCount, const NFIDataList& arg) { unsigned long unNowTime = NF_GetTickCount(); std::cout << "strHeartBeat: " << fTime << " Count: " << nCount << " TimeDis: " << unNowTime - mLastTime << std::endl; mLastTime = unNowTime; return 0; } int HelloWorld3Module::OnClassCallBackEvent(const NFIDENTID& self, const std::string& strClassName, const CLASS_OBJECT_EVENT event, const NFIDataList& arg) { //虚拟类事件,只要有此虚拟类创建或者销毁即会回调 std::cout << "OnClassCallBackEvent ClassName: " << strClassName << " ID: " << self.nData64 << " Event: " << event << std::endl; if (event == COE_CREATE_HASDATA) { #ifdef NF_USE_ACTOR if(pPluginManager->GetActorID() == NFIActorManager::EACTOR_MAIN) #endif { m_pEventProcessModule->AddEventCallBack(self, 11111111, this, &HelloWorld3Module::OnEvent); m_pKernelModule->AddHeartBeat(self, "OnHeartBeat", this, &HelloWorld3Module::OnHeartBeat, NFCDataList(), 5.0f, 9999 ); mLastTime = NF_GetTickCount(); } } return 0; } int HelloWorld3Module::OnPropertyCallBackEvent( const NFIDENTID& self, const std::string& strProperty, const NFIDataList& oldVarList, const NFIDataList& newVarList, const NFIDataList& argVarList ) { //属性回调事件,只要属性值内容有变化,就会被回调 std::cout << "OnPropertyCallBackEvent Property: " << strProperty << " OldValue: " << oldVarList.Int(0) << " NewValue: " << newVarList.Int(0) << std::endl; return 0; } int HelloWorld3Module::OnPropertyStrCallBackEvent( const NFIDENTID& self, const std::string& strProperty, const NFIDataList& oldVarList, const NFIDataList& newVarList, const NFIDataList& argVarList ) { //属性回调事件,只要属性值内容有变化,就会被回调 std::cout << "OnPropertyCallBackEvent Property: " << strProperty << " OldValue: " << oldVarList.String(0) << " NewValue: " << newVarList.String(0) << std::endl; return 0; } bool HelloWorld3Module::AfterInit() { //初始化完毕 std::cout << "Hello, world3, AfterInit" << std::endl; m_pKernelModule = dynamic_cast<NFIKernelModule*>(pPluginManager->FindModule("NFCKernelModule")); m_pEventProcessModule = dynamic_cast<NFIEventProcessModule*>(pPluginManager->FindModule("NFCEventProcessModule")); m_pElementInfoModule = dynamic_cast<NFIElementInfoModule*>(pPluginManager->FindModule("NFCElementInfoModule")); //创建容器,所有的对象均需在容器中 m_pKernelModule->CreateContainer(1, ""); m_pEventProcessModule->AddClassCallBack("Player", this, &HelloWorld3Module::OnClassCallBackEvent); //创建对象,挂类回调和属性回调,然后事件处理对象 NF_SHARE_PTR<NFIObject> pObject = m_pKernelModule->CreateObject(NFIDENTID(0, 10), 1, 0, "Player", "", NFCDataList()); if (!pObject) { return false; } pObject->GetPropertyManager()->AddProperty(pObject->Self(), "Hello", TDATA_STRING, true, true, true, true, 0, ""); pObject->GetPropertyManager()->AddProperty(pObject->Self(), "World", TDATA_INT, true, true, true, true, 0, ""); pObject->AddPropertyCallBack("Hello", this, &HelloWorld3Module::OnPropertyStrCallBackEvent); pObject->AddPropertyCallBack("World", this, &HelloWorld3Module::OnPropertyCallBackEvent); pObject->SetPropertyString("Hello", "hello,World"); pObject->SetPropertyInt("World", 1111); m_pEventProcessModule->DoEvent(pObject->Self(), 11111111, NFCDataList() << int(100) << "200"); return true; } bool HelloWorld3Module::Execute( const float fLasFrametime, const float fStartedTime ) { //每帧执行 //std::cout << "Hello, world3, Execute" << std::endl; return true; } bool HelloWorld3Module::BeforeShut() { //反初始化之前 std::cout << "Hello, world3, BeforeShut" << std::endl; m_pKernelModule->DestroyAll(); return true; } bool HelloWorld3Module::Shut() { //反初始化 std::cout << "Hello, world3, Shut" << std::endl; return true; }
PS:我们的目标是用优良的设计打败实现狗!
码云代码: https://git.oschina.net/kytoo/NoahGameFrame
Github代码: https://github.com/ketoo/NoahGameFrame
评论