Skip to content

Commit d2be75a

Browse files
committed
继续完善
1 parent 1c708fa commit d2be75a

27 files changed

Lines changed: 694 additions & 42 deletions

‎demo/res/scripts/base/kbengine.py‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ def onBaseAppReady(bootstrapIdx):
99
@param isBootstrap: 是否是第一个baseapp启动
1010
@type isBootstrap: bool
1111
"""
12-
DEBUG_MSG('baseapp准备完毕! bootstrapIdx=%s' % bootstrapIdx)
12+
DEBUG_MSG('onBaseAppReady: bootstrapIdx=%s' % bootstrapIdx)
1313
if bootstrapIdx == 1:
1414
# 创建spacemanager
1515
KBEngine.createBaseLocally( "Spaces", {} )
@@ -23,7 +23,7 @@ def onBaseAppShutDown(state):
2323
2 : 所有entity被写入数据库之后
2424
@type state: int
2525
"""
26-
DEBUG_MSG('baseapp将要关闭了! state=%i' % state)
26+
DEBUG_MSG('onBaseAppShutDown: state=%i' % state)
2727

2828
def onInit(isReload):
2929
"""
@@ -32,7 +32,7 @@ def onInit(isReload):
3232
@param isReload: 是否是被重写加载脚本后触发的
3333
@type isReload: bool
3434
"""
35-
DEBUG_MSG('所有的脚本初始化完毕。游戏初始化... isReload:%s' % isReload)
35+
DEBUG_MSG('onInit::isReload:%s' % isReload)
3636

3737
def onFini():
3838
pass

‎demo/res/scripts/bots/kbengine.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22
import KBEngine
33
from KBEDebug import *
44

5-
def onInitialize(isReload):
5+
def onInit(isReload):
66
"""
77
KBEngine method.
88
当引擎启动后初始化完所有的脚本后这个接口被调用
99
@param isReload: 是否是被重写加载脚本后触发的
1010
@type isReload: bool
1111
"""
12-
DEBUG_MSG('所有的脚本初始化完毕。游戏初始化... isReload:%s' % isReload)
12+
DEBUG_MSG('onInit::isReload:%s' % isReload)
1313

1414
def onStart():
1515
"""

‎demo/res/scripts/cell/kbengine.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ def onInit(isReload):
99
KBEngine method.
1010
当引擎启动后初始化完所有的脚本后这个接口被调用
1111
"""
12-
DEBUG_MSG('所有的脚本初始化完毕。游戏初始化...')
12+
DEBUG_MSG('onInit::isReload:%s' % isReload)
1313
dialogmgr.onInit()
1414
skills.onInit()
1515

‎demo/res/scripts/client/Account.py‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ class Account(KBEngine.Entity):
66
def __init__(self):
77
KBEngine.Entity.__init__(self)
88
DEBUG_MSG("Account::__init__:%s." % (self.__dict__))
9-
9+
self.base.reqAvatarList()
10+
1011
def onReqAvatarList(self, infos):
1112
"""
1213
define method.
@@ -19,3 +20,8 @@ def onCreateAvatarResult(self, retcode, info):
1920
"""
2021
DEBUG_MSG("Account:onCreateAvatarResult::%s, retcode=%i" % (info, retcode))
2122

23+
def reqCreateAvatar(self, roleType, name):
24+
"""
25+
"""
26+
DEBUG_MSG("Account:reqCreateAvatar::roleType=%i, name=%s" % (roleType, name))
27+
self.base.reqCreateAvatar(roleType, name)

‎demo/res/scripts/client/kbengine.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22
import KBEngine
33
from KBEDebug import *
44

5-
def onInitialize(isReload):
5+
def onInit(isReload):
66
"""
77
KBEngine method.
88
当引擎启动后初始化完所有的脚本后这个接口被调用
99
@param isReload: 是否是被重写加载脚本后触发的
1010
@type isReload: bool
1111
"""
12-
DEBUG_MSG('所有的脚本初始化完毕。游戏初始化... isReload:%s' % isReload)
12+
DEBUG_MSG('onInit::isReload:%s' % isReload)
1313

1414
def onStart():
1515
"""

‎demo/res/server/kbengine.xml‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
<root>
22
<trace_packet>
3-
<debug_type>0</debug_type>
3+
<debug_type>3</debug_type>
44
</trace_packet>
55

66
<app_publish>0</app_publish>
77

88
<dbmgr>
9+
<host> 192.168.10.108 </host>
910
<databaseName> demo </databaseName>
1011
</dbmgr>
1112

‎kbe/bin/client/kbengine.xml‎

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
<root>
2+
<gameUpdateHertz> 10 </gameUpdateHertz>
3+
4+
<!-- 非0则不优化, 不带包长信息的包强制都携带长度信息, 某些情况下方便某些前端对接协议
5+
什么样的包不带长度信息? 所有能够预先计算出包大小的且永远不变的包不带长度信息,
6+
如果有可变字符串参数则一定需要带长度信息 -->
7+
<packetAlwaysContainLength>0</packetAlwaysContainLength>
8+
9+
<!-- 是否需要将任何接收和发送的包以文本输出到log中提供调试
10+
debug_type:
11+
0: 不输出
12+
1: 16进制输出
13+
2: 字符流输出
14+
3: 10进制输出
15+
use_logfile:
16+
是否独立一个log文件来记录包内容,文件名通常为
17+
appname_packetlogs.log
18+
disable_msgs:
19+
关闭某些包的输出
20+
-->
21+
<trace_packet>
22+
<debug_type>0</debug_type>
23+
<use_logfile>false</use_logfile>
24+
<disables>
25+
<item>Baseappmgr::updateBaseapp</item>
26+
</disables>
27+
</trace_packet>
28+
29+
<!-- 是否输出entity的创建, 脚本获取属性, 初始化属性等调试信息 -->
30+
<debugEntity>0</debugEntity>
31+
32+
<!-- apps发布状态, 可在脚本中获取该值
33+
Type: Integer8
34+
0 : debug
35+
1 : release
36+
其他自定义
37+
-->
38+
<app_publish>0</app_publish>
39+
40+
<channelCommon>
41+
<!-- 频道最后一次通信时间超过此时间则被认定为超时通道, 服务器将踢出该频道 -->
42+
<timeout>
43+
<internal> 60.0 </internal>
44+
<external> 60.0 </external>
45+
</timeout>
46+
47+
<!-- 一个游戏周期channel接收窗口溢出值 0无限制-->
48+
<receiveWindowOverflow>
49+
<messages>
50+
<internal> 0 </internal>
51+
<external> 0 </external>
52+
</messages>
53+
<bytes>
54+
<internal> 0 </internal>
55+
<external> 0 </external>
56+
</bytes>
57+
</receiveWindowOverflow>
58+
</channelCommon>
59+
60+
<ip> localhost </ip>
61+
<port> 20013 </port>
62+
63+
<entryScriptFile> kbengine </entryScriptFile>
64+
</root>

‎kbe/src/client/app/BaseApplication.cpp‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -151,9 +151,9 @@ void BaseApplication::createFrameListener(void)
151151
mDetailsPanel->hide();
152152

153153
// a friendly reminder
154-
Ogre::StringVector names;
155-
names.push_back("Help");
156-
mTrayMgr->createParamsPanel(OgreBites::TL_TOPLEFT, "Help", 100, names)->setParamValue(0, "H/F1");
154+
//Ogre::StringVector names;
155+
//names.push_back("Help");
156+
//mTrayMgr->createParamsPanel(OgreBites::TL_TOPLEFT, "Help", 100, names)->setParamValue(0, "H/F1");
157157

158158
mRoot->addFrameListener(this);
159159
}
@@ -265,7 +265,7 @@ bool BaseApplication::frameRenderingQueued(const Ogre::FrameEvent& evt)
265265

266266
if (!mTrayMgr->isDialogVisible())
267267
{
268-
if(mCameraMan)
268+
if(mCameraMan != NULL)
269269
mCameraMan->frameRenderingQueued(evt); // if dialog isn't up, then update the camera
270270

271271
if (mDetailsPanel->isVisible() && mActiveCamera) // if details panel is visible, then update its contents

‎kbe/src/client/app/OgreApplication.cpp‎

Lines changed: 40 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include "TreeLoader3D.h"
88
#include "space_world.h"
99
#include "space_login.h"
10+
#include "space_avatarselect.h"
1011
#include "cstdkbe/cstdkbe.hpp"
1112

1213
#include "../kbengine_dll/kbengine_dll.h"
@@ -23,9 +24,12 @@ namespace KBEngine{
2324

2425
template<> OgreApplication* Ogre::Singleton<OgreApplication>::msSingleton = 0;
2526

26-
Space* space = NULL;
27+
Space* g_space = NULL;
28+
boost::mutex g_spaceMutex;
29+
2730
//-------------------------------------------------------------------------------------
28-
OgreApplication::OgreApplication(void)
31+
OgreApplication::OgreApplication(void):
32+
events_()
2933
{
3034
kbe_registerEventHandle(this);
3135
}
@@ -35,6 +39,7 @@ OgreApplication::~OgreApplication(void)
3539
{
3640
kbe_deregisterEventHandle(this);
3741
mCameraMan = NULL;
42+
SAFE_RELEASE(g_space);
3843
}
3944

4045
//-------------------------------------------------------------------------------------
@@ -77,9 +82,20 @@ bool OgreApplication::setup(void)
7782

7883
createFrameListener();
7984

85+
changeSpace(new SpaceLogin(mRoot, mWindow, mInputManager, mTrayMgr));
8086
return true;
8187
};
8288

89+
//-------------------------------------------------------------------------------------
90+
void OgreApplication::changeSpace(Space* space)
91+
{
92+
if(g_space)
93+
delete g_space;
94+
95+
g_space = space;
96+
space->setup();
97+
}
98+
8399
//-------------------------------------------------------------------------------------
84100
void OgreApplication::setupResources(void)
85101
{
@@ -91,18 +107,20 @@ bool OgreApplication::frameRenderingQueued(const Ogre::FrameEvent& evt)
91107
{
92108
bool ret = BaseApplication::frameRenderingQueued(evt);
93109

94-
kbe_update();
110+
if(g_space == NULL)
111+
return false;
95112

96-
if(space == NULL)
113+
boost::mutex::scoped_lock lock(g_spaceMutex);
114+
std::vector<const KBEngine::EventData*>::iterator iter = events_.begin();
115+
for(; iter != events_.end(); iter++)
97116
{
98-
space = new SpaceLogin(mRoot, mWindow, mInputManager, mTrayMgr);
99-
space->setup();
100-
}
101-
else
102-
{
103-
space->frameRenderingQueued(evt);
117+
g_space->kbengine_onEvent((*iter));
118+
delete (*iter);
104119
}
120+
121+
events_.clear();
105122

123+
g_space->frameRenderingQueued(evt);
106124
return ret;
107125
}
108126

@@ -111,9 +129,9 @@ bool OgreApplication::keyPressed( const OIS::KeyEvent &arg )
111129
{
112130
if (mTrayMgr->isDialogVisible()) return true; // don't process any more keys if dialog is up
113131

114-
if(space)
132+
if(g_space)
115133
{
116-
space->keyPressed(arg);
134+
g_space->keyPressed(arg);
117135
}
118136

119137
return BaseApplication::keyPressed( arg );
@@ -122,15 +140,23 @@ bool OgreApplication::keyPressed( const OIS::KeyEvent &arg )
122140
//-------------------------------------------------------------------------------------
123141
void OgreApplication::buttonHit(OgreBites::Button* button)
124142
{
125-
if(space)
143+
if(g_space)
126144
{
127-
space->buttonHit(button);
145+
g_space->buttonHit(button);
128146
}
129147
}
130148

131149
//-------------------------------------------------------------------------------------
132150
void OgreApplication::kbengine_onEvent(const KBEngine::EventData* lpEventData)
133151
{
152+
KBEngine::EventData* peventdata = KBEngine::newKBEngineEvent(lpEventData->id);
153+
154+
if(peventdata)
155+
{
156+
*peventdata = *lpEventData;
157+
boost::mutex::scoped_lock lock(g_spaceMutex);
158+
events_.push_back(peventdata);
159+
}
134160
}
135161

136162
//-------------------------------------------------------------------------------------

‎kbe/src/client/app/OgreApplication.h‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "client_lib/event.hpp"
1010

1111
class DotSceneLoader;
12+
class Space;
1213

1314
namespace Forests
1415
{
@@ -30,13 +31,16 @@ class OgreApplication : public BaseApplication, public Ogre::Singleton<OgreAppli
3031
virtual void buttonHit(OgreBites::Button* button);
3132

3233
void kbengine_onEvent(const KBEngine::EventData* lpEventData);
34+
35+
void changeSpace(Space* space);
3336
protected:
3437
virtual bool setup();
3538
virtual void setupResources();
3639
virtual void createScene(void){}
3740
virtual bool keyPressed( const OIS::KeyEvent &arg );
3841
virtual bool frameRenderingQueued(const Ogre::FrameEvent& evt);
3942
private:
43+
std::vector<const KBEngine::EventData*> events_;
4044
};
4145

4246
#endif // #ifndef __OgreApplication_h_

0 commit comments

Comments
 (0)