Skip to content

Commit a09a3b2

Browse files
committed
调整客户端框架。
1 parent bf8dd2a commit a09a3b2

16 files changed

Lines changed: 1376 additions & 1431 deletions

‎kbe/src/lib/client_lib/client_lib90.vcproj‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,14 @@
162162
RelativePath=".\clientapp.cpp"
163163
>
164164
</File>
165+
<File
166+
RelativePath=".\clientobjectbase.cpp"
167+
>
168+
</File>
169+
<File
170+
RelativePath=".\entity.cpp"
171+
>
172+
</File>
165173
<File
166174
RelativePath=".\profile.cpp"
167175
>
@@ -184,10 +192,18 @@
184192
RelativePath=".\clientapp.hpp"
185193
>
186194
</File>
195+
<File
196+
RelativePath=".\clientobjectbase.hpp"
197+
>
198+
</File>
187199
<File
188200
RelativePath=".\common.hpp"
189201
>
190202
</File>
203+
<File
204+
RelativePath=".\entity.hpp"
205+
>
206+
</File>
191207
<File
192208
RelativePath=".\kbemain.hpp"
193209
>
@@ -203,6 +219,10 @@
203219
UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}"
204220
>
205221
</Filter>
222+
<File
223+
RelativePath=".\entity.ipp"
224+
>
225+
</File>
206226
<File
207227
RelativePath=".\ReadMe.txt"
208228
>

‎kbe/src/lib/client_lib/clientapp.cpp‎

Lines changed: 17 additions & 186 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ along with KBEngine. If not, see <http://www.gnu.org/licenses/>.
2020

2121

2222
#include "clientapp.hpp"
23+
#include "entity.hpp"
2324
#include "network/channel.hpp"
2425
#include "thread/threadpool.hpp"
2526
#include "entitydef/entity_mailbox.hpp"
@@ -44,23 +45,17 @@ ClientApp::ClientApp(Mercury::EventDispatcher& dispatcher,
4445
Mercury::NetworkInterface& ninterface,
4546
COMPONENT_TYPE componentType,
4647
COMPONENT_ID componentID):
48+
ClientObjectBase(),
4749
TimerHandler(),
4850
Mercury::ChannelTimeOutHandler(),
49-
script_(),
5051
scriptBaseTypes_(),
5152
gameTimer_(),
5253
componentType_(componentType),
5354
componentID_(componentID),
5455
mainDispatcher_(dispatcher),
5556
networkInterface_(ninterface),
5657
timers_(),
57-
threadPool_(),
58-
serverChannel_(NULL),
59-
pyCallbackMgr_(),
60-
ip_(),
61-
port_(),
62-
lastSentActiveTickTime_(timestamp()),
63-
connectedGateway_(false)
58+
threadPool_()
6459
{
6560
networkInterface_.pExtensionData(this);
6661
networkInterface_.pChannelTimeOutHandler(this);
@@ -74,54 +69,32 @@ connectedGateway_(false)
7469
//-------------------------------------------------------------------------------------
7570
ClientApp::~ClientApp()
7671
{
77-
serverChannel_ = NULL;
78-
}
79-
80-
//-------------------------------------------------------------------------------------
81-
bool ClientApp::loadConfig()
82-
{
83-
return true;
8472
}
8573

8674
//-------------------------------------------------------------------------------------
8775
int ClientApp::registerPyObjectToScript(const char* attrName, PyObject* pyObj)
8876
{
89-
return script_.registerToModule(attrName, pyObj);
77+
return getScript().registerToModule(attrName, pyObj);
9078
}
9179

9280
//-------------------------------------------------------------------------------------
9381
int ClientApp::unregisterPyObjectToScript(const char* attrName)
9482
{
95-
return script_.unregisterToModule(attrName);
96-
}
97-
98-
//-------------------------------------------------------------------------------------
99-
bool ClientApp::installSingnals()
100-
{
101-
return true;
83+
return getScript().unregisterToModule(attrName);
10284
}
10385

10486
//-------------------------------------------------------------------------------------
10587
bool ClientApp::initialize()
10688
{
10789
if(!threadPool_.isInitialize())
10890
threadPool_.createThreadPool(4, 4, 256);
109-
110-
if(!installSingnals())
111-
return false;
112-
113-
if(!loadConfig())
114-
return false;
11591

11692
if(!initializeBegin())
11793
return false;
11894

11995
gameTimer_ = this->getMainDispatcher().addTimer(1000000 / g_kbeSrvConfig.gameUpdateHertz(), this,
12096
reinterpret_cast<void *>(TIMEOUT_GAME_TICK));
12197

122-
if(!installPyScript())
123-
return false;
124-
12598
if(!installPyModules())
12699
return false;
127100

@@ -157,42 +130,6 @@ bool ClientApp::installEntityDef()
157130
return true;
158131
}
159132

160-
//-------------------------------------------------------------------------------------
161-
bool ClientApp::installPyScript()
162-
{
163-
if(Resmgr::getSingleton().respaths().size() <= 0)
164-
{
165-
ERROR_MSG("ClientApp::installPyScript: KBE_RES_PATH is error!\n");
166-
return false;
167-
}
168-
169-
std::wstring root_path = L"";
170-
wchar_t* tbuf = KBEngine::strutil::char2wchar(const_cast<char*>(Resmgr::getSingleton().respaths()[1].c_str()));
171-
if(tbuf != NULL)
172-
{
173-
root_path += tbuf;
174-
free(tbuf);
175-
}
176-
else
177-
{
178-
return false;
179-
}
180-
181-
std::wstring pyPaths = root_path + L"res/scripts/common;";
182-
pyPaths += root_path + L"res/scripts/data;";
183-
pyPaths += root_path + L"res/scripts/user_type;";
184-
pyPaths += root_path + L"res/scripts/client;";
185-
186-
std::string kbe_res_path = Resmgr::getSingleton().respaths()[0].c_str();
187-
kbe_res_path += "scripts/common";
188-
189-
tbuf = KBEngine::strutil::char2wchar(const_cast<char*>(kbe_res_path.c_str()));
190-
bool ret = getScript().install(tbuf, pyPaths, "KBEngine", componentType_);
191-
// 此处经测试传入python之后被python释放了
192-
// free(tbuf);
193-
return ret;
194-
}
195-
196133
//-------------------------------------------------------------------------------------
197134
void ClientApp::registerScript(PyTypeObject* pto)
198135
{
@@ -202,16 +139,16 @@ void ClientApp::registerScript(PyTypeObject* pto)
202139
//-------------------------------------------------------------------------------------
203140
bool ClientApp::uninstallPyScript()
204141
{
205-
return uninstallPyModules() && getScript().uninstall();
142+
return uninstallPyModules();
206143
}
207144

208145
//-------------------------------------------------------------------------------------
209146
bool ClientApp::installPyModules()
210147
{
211148
EntityDef::installScript(getScript().getModule());
212-
// Entity::installScript(getScript().getModule());
213-
// Entities<Entity>::installScript(NULL);
214-
// registerScript(Entity::getScriptType());
149+
Entity::installScript(getScript().getModule());
150+
Entities<Entity>::installScript(NULL);
151+
registerScript(Entity::getScriptType());
215152

216153
onInstallPyModules();
217154
return true;
@@ -222,8 +159,8 @@ bool ClientApp::uninstallPyModules()
222159
{
223160
EntityDef::uninstallScript();
224161

225-
// Entity::uninstallScript();
226-
// Entities<Entity>::uninstallScript();
162+
Entity::uninstallScript();
163+
Entities<Entity>::uninstallScript();
227164
return true;
228165
}
229166

@@ -232,6 +169,10 @@ void ClientApp::finalise(void)
232169
{
233170
gameTimer_.cancel();
234171
threadPool_.finalise();
172+
ClientObjectBase::finalise();
173+
174+
uninstallPyModules();
175+
uninstallPyScript();
235176
}
236177

237178
//-------------------------------------------------------------------------------------
@@ -263,10 +204,10 @@ void ClientApp::handleGameTick()
263204

264205
getNetworkInterface().handleChannels(KBEngine::Mercury::MessageHandlers::pMainMessageHandlers);
265206

266-
if(serverChannel_)
207+
if(pServerChannel_ && pServerChannel_->endpoint())
267208
{
268209
sendTick();
269-
serverChannel_->send();
210+
pServerChannel_->send();
270211
}
271212
}
272213

@@ -305,115 +246,5 @@ void ClientApp::onChannelTimeOut(Mercury::Channel * pChannel)
305246
pChannel->destroy();
306247
}
307248

308-
//-------------------------------------------------------------------------------------
309-
void ClientApp::sendTick()
310-
{
311-
if(serverChannel_)
312-
return;
313-
314-
// 向服务器发送tick
315-
uint64 check = uint64( Mercury::g_channelExternalTimeout * stampsPerSecond() ) / 2;
316-
if (timestamp() - lastSentActiveTickTime_ > check)
317-
{
318-
lastSentActiveTickTime_ = timestamp();
319-
320-
Mercury::Bundle* pBundle = Mercury::Bundle::ObjPool().createObject();
321-
if(connectedGateway_)
322-
(*pBundle).newMessage(BaseappInterface::onClientActiveTick);
323-
else
324-
(*pBundle).newMessage(LoginappInterface::onClientActiveTick);
325-
326-
serverChannel_->bundles().push_back(pBundle);
327-
}
328-
}
329-
330-
//-------------------------------------------------------------------------------------
331-
Mercury::Channel* ClientApp::findChannelByMailbox(EntityMailbox& mailbox)
332-
{
333-
return serverChannel_;
334-
}
335-
336-
//-------------------------------------------------------------------------------------
337-
void ClientApp::onCreateAccountResult(Mercury::Channel * pChannel, MemoryStream& s)
338-
{
339-
SERVER_ERROR_CODE failedcode;
340-
std::string datas;
341-
342-
s >> failedcode;
343-
s.readBlob(datas);
344-
}
345-
346-
//-------------------------------------------------------------------------------------
347-
void ClientApp::onLoginSuccessfully(Mercury::Channel * pChannel, MemoryStream& s)
348-
{
349-
}
350-
351-
//-------------------------------------------------------------------------------------
352-
void ClientApp::onLoginFailed(Mercury::Channel * pChannel, MemoryStream& s)
353-
{
354-
}
355-
356-
//-------------------------------------------------------------------------------------
357-
void ClientApp::onLoginGatewayFailed(Mercury::Channel * pChannel, SERVER_ERROR_CODE failedcode)
358-
{
359-
}
360-
361-
//-------------------------------------------------------------------------------------
362-
void ClientApp::onCreatedProxies(Mercury::Channel * pChannel,
363-
uint64 rndUUID, ENTITY_ID eid, std::string& entityType)
364-
{
365-
}
366-
367-
//-------------------------------------------------------------------------------------
368-
void ClientApp::onEntityEnterWorld(Mercury::Channel * pChannel, ENTITY_ID eid,
369-
ENTITY_SCRIPT_UID scriptType, SPACE_ID spaceID)
370-
{
371-
}
372-
373-
//-------------------------------------------------------------------------------------
374-
void ClientApp::onEntityLeaveWorld(Mercury::Channel * pChannel, ENTITY_ID eid, SPACE_ID spaceID)
375-
{
376-
}
377-
378-
//-------------------------------------------------------------------------------------
379-
void ClientApp::onEntityEnterSpace(Mercury::Channel * pChannel, SPACE_ID spaceID, ENTITY_ID eid)
380-
{
381-
}
382-
383-
//-------------------------------------------------------------------------------------
384-
void ClientApp::onEntityLeaveSpace(Mercury::Channel * pChannel, SPACE_ID spaceID, ENTITY_ID eid)
385-
{
386-
}
387-
388-
//-------------------------------------------------------------------------------------
389-
void ClientApp::onEntityDestroyed(Mercury::Channel * pChannel, ENTITY_ID eid)
390-
{
391-
}
392-
393-
//-------------------------------------------------------------------------------------
394-
void ClientApp::onRemoteMethodCall(Mercury::Channel* pChannel, KBEngine::MemoryStream& s)
395-
{
396-
}
397-
398-
//-------------------------------------------------------------------------------------
399-
void ClientApp::onUpdatePropertys(Mercury::Channel* pChannel, MemoryStream& s)
400-
{
401-
}
402-
403-
//-------------------------------------------------------------------------------------
404-
void ClientApp::onStreamDataStarted(Mercury::Channel* pChannel, int16 id, uint32 datasize, std::string& descr)
405-
{
406-
}
407-
408-
//-------------------------------------------------------------------------------------
409-
void ClientApp::onStreamDataRecv(Mercury::Channel* pChannel, MemoryStream& s)
410-
{
411-
}
412-
413-
//-------------------------------------------------------------------------------------
414-
void ClientApp::onStreamDataCompleted(Mercury::Channel* pChannel, int16 id)
415-
{
416-
}
417-
418249
//-------------------------------------------------------------------------------------
419250
}

0 commit comments

Comments
 (0)