Repository navigation
Expand file tree
/
Copy pathspace.cpp
More file actions
813 lines (671 loc) · 22.1 KB
/
Copy pathspace.cpp
File metadata and controls
813 lines (671 loc) · 22.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
/*
This source file is part of KBEngine
For the latest info, see http://www.kbengine.org/
Copyright (c) 2008-2016 KBEngine.
KBEngine is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
KBEngine is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with KBEngine. If not, see <http://www.gnu.org/licenses/>.
*/
#include "cellapp.h"
#include "space.h"
#include "entity.h"
#include "witness.h"
#include "navigation/navigation.h"
#include "loadnavmesh_threadtasks.h"
#include "entitydef/entities.h"
#include "client_lib/client_interface.h"
#include "../../server/baseappmgr/baseappmgr_interface.h"
#include "../../server/cellappmgr/cellappmgr_interface.h"
#include "../../server/baseapp/baseapp_interface.h"
#include "../../server/cellapp/cellapp_interface.h"
#include "../../server/dbmgr/dbmgr_interface.h"
namespace KBEngine{
//-------------------------------------------------------------------------------------
Space::Space(SPACE_ID spaceID):
id_(spaceID),
entities_(),
hasGeometry_(false),
pCell_(NULL),
coordinateSystem_(),
pNavHandle_(),
state_(STATE_NORMAL),
destroyTime_(0)
{
}
//-------------------------------------------------------------------------------------
Space::~Space()
{
entities_.clear();
pNavHandle_.clear();
SAFE_RELEASE(pCell_);
}
//-------------------------------------------------------------------------------------
void Space::_clearGhosts()
{
// 因为space在destroy时做过一次清理,因此这里理论上剩下的是ghosts实体
if(entities_.size() == 0)
return;
std::vector<ENTITY_ID> entitieslog;
SPACE_ENTITIES::const_iterator log_iter = this->entities().begin();
for(; log_iter != this->entities().end(); ++log_iter)
entitieslog.push_back((*log_iter).get()->id());
std::vector<ENTITY_ID>::iterator iter = entitieslog.begin();
for(; iter != entitieslog.end(); ++iter)
{
Entity* entity = Cellapp::getSingleton().findEntity((*iter));
if(entity != NULL && !entity->isDestroyed() && entity->spaceID() == this->id())
{
entity->destroyEntity();
}
else
{
entity = findEntity((*iter));
if(entity != NULL && !entity->isDestroyed() && entity->spaceID() == this->id())
{
removeEntity(entity);
}
}
}
entities_.clear();
}
//-------------------------------------------------------------------------------------
PyObject* Space::__py_GetSpaceGeometryMapping(PyObject* self, PyObject* args)
{
SPACE_ID spaceID = 0;
if(PyTuple_Size(args) != 1)
{
PyErr_Format(PyExc_AssertionError, "KBEngine::getSpaceGeometryMapping: (argssize != 1) is error!");
PyErr_PrintEx(0);
return 0;
}
if(PyArg_ParseTuple(args, "I", &spaceID) == -1)
{
PyErr_Format(PyExc_AssertionError, "KBEngine::getSpaceGeometryMapping: args is error!");
PyErr_PrintEx(0);
return 0;
}
Space* space = Spaces::findSpace(spaceID);
if(space == NULL)
{
PyErr_Format(PyExc_AssertionError, "KBEngine::getSpaceGeometryMapping: (spaceID=%u) not found!",
spaceID);
PyErr_PrintEx(0);
return 0;
}
return PyUnicode_FromString(space->getGeometryPath().c_str());
}
//-------------------------------------------------------------------------------------
PyObject* Space::__py_AddSpaceGeometryMapping(PyObject* self, PyObject* args)
{
SPACE_ID spaceID = 0;
char* path = NULL;
bool shouldLoadOnServer = true;
PyObject* mapper = NULL;
PyObject* py_params = NULL;
std::map< int, std::string > params;
int argCount = PyTuple_Size(args);
if(argCount < 3 || argCount > 5)
{
PyErr_Format(PyExc_AssertionError, "KBEngine::addSpaceGeometryMapping: (argssize[spaceID, mapper, path, shouldLoadOnServer] < 3 || > 5) is error!");
PyErr_PrintEx(0);
return 0;
}
if(argCount == 4)
{
if(PyArg_ParseTuple(args, "I|O|s|b", &spaceID, &mapper, &path, &shouldLoadOnServer) == -1)
{
PyErr_Format(PyExc_AssertionError, "KBEngine::addSpaceGeometryMapping: args is error!");
PyErr_PrintEx(0);
return 0;
}
}
else if(argCount == 5)
{
if(PyArg_ParseTuple(args, "I|O|s|b|O", &spaceID, &mapper, &path, &shouldLoadOnServer, &py_params) == -1)
{
PyErr_Format(PyExc_AssertionError, "KBEngine::addSpaceGeometryMapping: args is error!");
PyErr_PrintEx(0);
return 0;
}
if(py_params)
{
PyObject *key, *value;
Py_ssize_t pos = 0;
if(!PyDict_Check(py_params))
{
PyErr_Format(PyExc_AssertionError, "KBEngine::addSpaceGeometryMapping: args(params) not is PyDict!");
PyErr_PrintEx(0);
return 0;
}
while(PyDict_Next(py_params, &pos, &key, &value))
{
if(!PyLong_Check(key) || !PyUnicode_Check(value))
{
PyErr_Format(PyExc_AssertionError, "KBEngine::addSpaceGeometryMapping: args(params) is error!");
PyErr_PrintEx(0);
return 0;
}
long i = PyLong_AsLong(key);
wchar_t* PyUnicode_AsWideCharStringRet0 = PyUnicode_AsWideCharString(value, NULL);
char* ccattr = strutil::wchar2char(PyUnicode_AsWideCharStringRet0);
PyMem_Free(PyUnicode_AsWideCharStringRet0);
params[i] = ccattr;
free(ccattr);
}
SCRIPT_ERROR_CHECK();
}
}
else
{
if(PyArg_ParseTuple(args, "I|O|s", &spaceID, &mapper, &path) == -1)
{
PyErr_Format(PyExc_AssertionError, "KBEngine::addSpaceGeometryMapping: args wrong!");
PyErr_PrintEx(0);
return 0;
}
}
Space* space = Spaces::findSpace(spaceID);
if(space == NULL)
{
PyErr_Format(PyExc_AssertionError, "KBEngine::addSpaceGeometryMapping: (spaceID=%u respath=%s) not found!",
spaceID, path);
PyErr_PrintEx(0);
return 0;
}
SCRIPT_ERROR_CHECK();
if(!space->addSpaceGeometryMapping(path, shouldLoadOnServer, params))
{
PyErr_Format(PyExc_AssertionError, "KBEngine::addSpaceGeometryMapping: (spaceID=%u respath=%s) error!",
spaceID, path);
PyErr_PrintEx(0);
return 0;
}
S_Return;
}
//-------------------------------------------------------------------------------------
bool Space::addSpaceGeometryMapping(std::string respath, bool shouldLoadOnServer, const std::map< int, std::string >& params)
{
INFO_MSG(fmt::format("KBEngine::addSpaceGeometryMapping: spaceID={}, respath={}, shouldLoadOnServer={}!\n",
id(), respath, shouldLoadOnServer));
hasGeometry_ = true;
if(getGeometryPath() == respath)
{
WARNING_MSG(fmt::format("KBEngine::addSpaceGeometryMapping: spaceID={}, respath={} exist!\n",
id(), respath));
return true;
}
setGeometryPath(respath);
if(shouldLoadOnServer)
loadSpaceGeometry(params);
return true;
}
//-------------------------------------------------------------------------------------
void Space::loadSpaceGeometry(const std::map< int, std::string >& params)
{
KBE_ASSERT(pNavHandle_ == NULL);
Cellapp::getSingleton().threadPool().addTask(new LoadNavmeshTask(getGeometryPath(), this->id(), params));
}
//-------------------------------------------------------------------------------------
void Space::unLoadSpaceGeometry()
{
}
//-------------------------------------------------------------------------------------
void Space::onLoadedSpaceGeometryMapping(NavigationHandlePtr pNavHandle)
{
pNavHandle_ = pNavHandle;
INFO_MSG(fmt::format("KBEngine::onLoadedSpaceGeometryMapping: spaceID={}, respath={}!\n",
id(), getGeometryPath()));
// 通知脚本
{
SCOPED_PROFILE(SCRIPTCALL_PROFILE);
SCRIPT_OBJECT_CALL_ARGS2(Cellapp::getSingleton().getEntryScript().get(), const_cast<char*>("onSpaceGeometryLoaded"),
const_cast<char*>("Is"), this->id(), getGeometryPath().c_str());
}
onAllSpaceGeometryLoaded();
}
//-------------------------------------------------------------------------------------
void Space::onAllSpaceGeometryLoaded()
{
SCOPED_PROFILE(SCRIPTCALL_PROFILE);
// 通知脚本
SCRIPT_OBJECT_CALL_ARGS3(Cellapp::getSingleton().getEntryScript().get(), const_cast<char*>("onAllSpaceGeometryLoaded"),
const_cast<char*>("Iis"), this->id(), true, getGeometryPath().c_str());
}
//-------------------------------------------------------------------------------------
bool Space::update()
{
if(destroyTime_ > 0 && timestamp() - destroyTime_ >= uint64( 5.f * stampsPerSecond() ))
return false;
if(destroyTime_ > 0 && timestamp() - destroyTime_ >= uint64( 4.f * stampsPerSecond() ))
_clearGhosts();
return true;
}
//-------------------------------------------------------------------------------------
void Space::addEntityAndEnterWorld(Entity* pEntity, bool isRestore)
{
addEntity(pEntity);
addEntityToNode(pEntity);
onEnterWorld(pEntity);
}
//-------------------------------------------------------------------------------------
void Space::addEntity(Entity* pEntity)
{
pEntity->spaceID(this->id_);
pEntity->spaceEntityIdx(entities_.size());
entities_.push_back(pEntity);
pEntity->onEnterSpace(this);
}
//-------------------------------------------------------------------------------------
void Space::addEntityToNode(Entity* pEntity)
{
pEntity->installCoordinateNodes(&coordinateSystem_);
}
//-------------------------------------------------------------------------------------
void Space::removeEntity(Entity* pEntity)
{
KBE_ASSERT(pEntity->spaceID() == id());
pEntity->spaceID(0);
// 先获取到所在位置
SPACE_ENTITIES::size_type idx = pEntity->spaceEntityIdx();
KBE_ASSERT(idx < entities_.size());
KBE_ASSERT(entities_[ idx ] == pEntity);
// 如果有2个或以上的entity则将最后一个entity移至删除的这个entity所在位置
Entity* pBack = entities_.back().get();
pBack->spaceEntityIdx(idx);
entities_[idx] = pBack;
pEntity->spaceEntityIdx(SPACE_ENTITIES::size_type(-1));
entities_.pop_back();
onLeaveWorld(pEntity);
// 这句必须在onLeaveWorld之后, 因为可能rangeTrigger需要参考pEntityCoordinateNode
pEntity->uninstallCoordinateNodes(&coordinateSystem_);
pEntity->onLeaveSpace(this);
// 如果没有entity了则需要销毁space, 因为space最少存在一个entity
if(entities_.empty() && state_ == STATE_NORMAL)
{
Spaces::destroySpace(this->id(), 0);
}
}
//-------------------------------------------------------------------------------------
void Space::_onEnterWorld(Entity* pEntity)
{
if(!pEntity->isReal() || !pEntity->pScriptModule()->hasClient())
return;
if(pEntity->hasWitness())
{
_addSpaceDatasToEntityClient(pEntity);
pEntity->pWitness()->onEnterSpace(this);
}
}
//-------------------------------------------------------------------------------------
void Space::onEnterWorld(Entity* pEntity)
{
KBE_ASSERT(pEntity != NULL);
// 如果是一个有Witness(通常是玩家)则需要将当前场景已经创建的有client部分的entity广播给他
// 否则是一个普通的entity进入世界, 那么需要将这个entity广播给所有看见他的有Witness的entity。
if(pEntity->hasWitness())
{
_onEnterWorld(pEntity);
}
}
//-------------------------------------------------------------------------------------
void Space::onEntityAttachWitness(Entity* pEntity)
{
KBE_ASSERT(pEntity != NULL && pEntity->hasWitness());
_onEnterWorld(pEntity);
}
//-------------------------------------------------------------------------------------
void Space::onLeaveWorld(Entity* pEntity)
{
if(!pEntity->isReal() || !pEntity->pScriptModule()->hasClient())
return;
// 向其他人客户端广播自己的离开
// 向客户端发送onLeaveWorld消息
if(pEntity->hasWitness())
{
pEntity->pWitness()->onLeaveSpace(this);
}
}
//-------------------------------------------------------------------------------------
Entity* Space::findEntity(ENTITY_ID entityID)
{
SPACE_ENTITIES::const_iterator iter = this->entities().begin();
for(; iter != this->entities().end(); ++iter)
{
const Entity* entity = (*iter).get();
if(entity->id() == entityID)
return const_cast<Entity*>(entity);
}
return NULL;
}
//-------------------------------------------------------------------------------------
bool Space::destroy(ENTITY_ID entityID)
{
if(state_ != STATE_NORMAL)
return false;
state_ = STATE_DESTROYING;
destroyTime_ = timestamp();
std::vector<ENTITY_ID> entitieslog;
{
SPACE_ENTITIES::const_iterator iter = this->entities().begin();
for(; iter != this->entities().end(); ++iter)
{
const Entity* entity = (*iter).get();
entitieslog.push_back(entity->id());
}
}
{
std::vector<ENTITY_ID>::iterator iter = entitieslog.begin();
for(; iter != entitieslog.end(); ++iter)
{
Entity* entity = Cellapp::getSingleton().findEntity((*iter));
if(entity != NULL && !entity->isDestroyed() && entity->spaceID() == this->id() && entity->isReal())
{
entity->onSpaceGone();
}
}
}
state_ = STATE_DESTROYED;
if(this->entities().size() == 0)
return true;
std::vector<ENTITY_ID>::iterator iter = entitieslog.begin();
for(; iter != entitieslog.end(); ++iter)
{
Entity* entity = Cellapp::getSingleton().findEntity((*iter));
if(entity != NULL && entity->isReal() && !entity->isDestroyed() && entity->spaceID() == this->id())
{
entity->destroyEntity();
}
else
{
entity = findEntity((*iter));
if(entity != NULL && entity->isReal() && !entity->isDestroyed() && entity->spaceID() == this->id())
{
removeEntity(entity);
}
}
}
return true;
}
//-------------------------------------------------------------------------------------
void Space::setGeometryPath(const std::string& path)
{
return setSpaceData("_mapping", path);
}
//-------------------------------------------------------------------------------------
const std::string& Space::getGeometryPath()
{
return getSpaceData("_mapping");
}
//-------------------------------------------------------------------------------------
void Space::setSpaceData(const std::string& key, const std::string& value)
{
SPACE_DATA::iterator iter = datas_.find(key);
if(iter == datas_.end())
datas_.insert(SPACE_DATA::value_type(key, value));
else
if(iter->second == value)
return;
else
datas_[key] = value;
onSpaceDataChanged(key, value, false);
}
//-------------------------------------------------------------------------------------
bool Space::hasSpaceData(const std::string& key)
{
SPACE_DATA::iterator iter = datas_.find(key);
if(iter == datas_.end())
return false;
return true;
}
//-------------------------------------------------------------------------------------
const std::string& Space::getSpaceData(const std::string& key)
{
SPACE_DATA::iterator iter = datas_.find(key);
if(iter == datas_.end())
{
static const std::string null = "";
return null;
}
return iter->second;
}
//-------------------------------------------------------------------------------------
void Space::delSpaceData(const std::string& key)
{
SPACE_DATA::iterator iter = datas_.find(key);
if(iter == datas_.end())
return;
datas_.erase(iter);
onSpaceDataChanged(key, "", true);
}
//-------------------------------------------------------------------------------------
void Space::onSpaceDataChanged(const std::string& key, const std::string& value, bool isdel)
{
// 通知脚本
if(!isdel)
{
SCOPED_PROFILE(SCRIPTCALL_PROFILE);
SCRIPT_OBJECT_CALL_ARGS3(Cellapp::getSingleton().getEntryScript().get(), const_cast<char*>("onSpaceData"),
const_cast<char*>("Iss"), this->id(), key.c_str(), value.c_str());
}
else
{
SCOPED_PROFILE(SCRIPTCALL_PROFILE);
SCRIPT_OBJECT_CALL_ARGS3(Cellapp::getSingleton().getEntryScript().get(), const_cast<char*>("onSpaceData"),
const_cast<char*>("IsO"), this->id(), key.c_str(), Py_None);
}
SPACE_ENTITIES::const_iterator iter = this->entities().begin();
for(; iter != this->entities().end(); ++iter)
{
const Entity* pEntity = (*iter).get();
if(pEntity == NULL || pEntity->isDestroyed() || !pEntity->hasWitness())
continue;
Network::Bundle* pForwardBundle = Network::Bundle::createPoolObject();
if(!isdel)
{
pForwardBundle->newMessage(ClientInterface::setSpaceData);
(*pForwardBundle) << this->id();
(*pForwardBundle) << key;
(*pForwardBundle) << value;
}
else
{
pForwardBundle->newMessage(ClientInterface::delSpaceData);
(*pForwardBundle) << this->id();
(*pForwardBundle) << key;
}
Network::Bundle* pSendBundle = Network::Bundle::createPoolObject();
NETWORK_ENTITY_MESSAGE_FORWARD_CLIENT(pEntity->id(), (*pSendBundle), (*pForwardBundle));
if(!isdel)
pEntity->pWitness()->sendToClient(ClientInterface::setSpaceData, pSendBundle);
else
pEntity->pWitness()->sendToClient(ClientInterface::delSpaceData, pSendBundle);
Network::Bundle::reclaimPoolObject(pForwardBundle);
}
}
//-------------------------------------------------------------------------------------
void Space::_addSpaceDatasToEntityClient(const Entity* pEntity)
{
if(!pEntity)
{
return;
}
if(pEntity->isDestroyed())
{
return;
}
if(!pEntity->hasWitness())
{
WARNING_MSG(fmt::format("Space::_addSpaceDatasToEntityClient: entity {} no client!\n",
pEntity->id()));
return;
}
Network::Bundle* pForwardBundle = Network::Bundle::createPoolObject();
pForwardBundle->newMessage(ClientInterface::initSpaceData);
(*pForwardBundle) << this->id();
SPACE_DATA::iterator iter = datas_.begin();
for(; iter != datas_.end(); ++iter)
{
(*pForwardBundle) << iter->first;
(*pForwardBundle) << iter->second;
}
Network::Bundle* pSendBundle = Network::Bundle::createPoolObject();
NETWORK_ENTITY_MESSAGE_FORWARD_CLIENT(pEntity->id(), (*pSendBundle), (*pForwardBundle));
pEntity->pWitness()->sendToClient(ClientInterface::initSpaceData, pSendBundle);
Network::Bundle::reclaimPoolObject(pForwardBundle);
}
//-------------------------------------------------------------------------------------
PyObject* Space::__py_SetSpaceData(PyObject* self, PyObject* args)
{
SPACE_ID spaceID = 0;
if(PyTuple_Size(args) != 3)
{
PyErr_Format(PyExc_AssertionError, "KBEngine::setSpaceData: (argssize != (spaceID, key, value)) is error!");
PyErr_PrintEx(0);
return 0;
}
char* key = NULL, *value = NULL;
if(PyArg_ParseTuple(args, "Iss", &spaceID, &key, &value) == -1)
{
PyErr_Format(PyExc_AssertionError, "KBEngine::setSpaceData: args is error!");
PyErr_PrintEx(0);
return 0;
}
if(key == NULL || value == NULL)
{
PyErr_Format(PyExc_AssertionError, "KBEngine::setSpaceData: key or value is error, not is string!");
PyErr_PrintEx(0);
return 0;
}
if(strlen(key) == 0)
{
PyErr_Format(PyExc_AssertionError, "KBEngine::setSpaceData: key is empty!");
PyErr_PrintEx(0);
return 0;
}
Space* space = Spaces::findSpace(spaceID);
if(space == NULL)
{
PyErr_Format(PyExc_AssertionError, "KBEngine::setSpaceData: (spaceID=%u) not found!",
spaceID);
PyErr_PrintEx(0);
return 0;
}
if(kbe_stricmp(key, "_mapping") == 0)
{
PyErr_Format(PyExc_AssertionError, "KBEngine::setSpaceData: key{_mapping} is protected!",
spaceID);
PyErr_PrintEx(0);
return 0;
}
space->setSpaceData(key, value);
S_Return;
}
//-------------------------------------------------------------------------------------
PyObject* Space::__py_GetSpaceData(PyObject* self, PyObject* args)
{
SPACE_ID spaceID = 0;
if(PyTuple_Size(args) != 2)
{
PyErr_Format(PyExc_AssertionError, "KBEngine::getSpaceData: (argssize != (spaceID, key)) is error!");
PyErr_PrintEx(0);
return 0;
}
char* key = NULL;
if(PyArg_ParseTuple(args, "Is", &spaceID, &key) == -1)
{
PyErr_Format(PyExc_AssertionError, "KBEngine::getSpaceData: args is error!");
PyErr_PrintEx(0);
return 0;
}
if(key == NULL)
{
PyErr_Format(PyExc_AssertionError, "KBEngine::getSpaceData: key not is string!");
PyErr_PrintEx(0);
return 0;
}
if(strlen(key) == 0)
{
PyErr_Format(PyExc_AssertionError, "KBEngine::getSpaceData: key is empty!");
PyErr_PrintEx(0);
return 0;
}
Space* space = Spaces::findSpace(spaceID);
if(space == NULL)
{
PyErr_Format(PyExc_AssertionError, "KBEngine::getSpaceData: (spaceID=%u) not found!",
spaceID);
PyErr_PrintEx(0);
return 0;
}
if(!space->hasSpaceData(key))
{
PyErr_Format(PyExc_AssertionError, "KBEngine::getSpaceData: (spaceID=%u, key=%s) not found!",
spaceID, key);
PyErr_PrintEx(0);
return 0;
}
return PyUnicode_FromString(space->getSpaceData(key).c_str());
}
//-------------------------------------------------------------------------------------
PyObject* Space::__py_DelSpaceData(PyObject* self, PyObject* args)
{
SPACE_ID spaceID = 0;
if(PyTuple_Size(args) != 2)
{
PyErr_Format(PyExc_AssertionError, "KBEngine::delSpaceData: (argssize != (spaceID, key)) is error!");
PyErr_PrintEx(0);
return 0;
}
char* key = NULL;
if(PyArg_ParseTuple(args, "Is", &spaceID, &key) == -1)
{
PyErr_Format(PyExc_AssertionError, "KBEngine::delSpaceData: args is error!");
PyErr_PrintEx(0);
return 0;
}
if(key == NULL)
{
PyErr_Format(PyExc_AssertionError, "KBEngine::delSpaceData: key not is string!");
PyErr_PrintEx(0);
return 0;
}
if(strlen(key) == 0)
{
PyErr_Format(PyExc_AssertionError, "KBEngine::delSpaceData: key is empty!");
PyErr_PrintEx(0);
return 0;
}
Space* space = Spaces::findSpace(spaceID);
if(space == NULL)
{
PyErr_Format(PyExc_AssertionError, "KBEngine::delSpaceData: (spaceID=%u) not found!",
spaceID);
PyErr_PrintEx(0);
return 0;
}
if(!space->hasSpaceData(key))
{
PyErr_Format(PyExc_AssertionError, "KBEngine::delSpaceData: (spaceID=%u, key=%s) not found!",
spaceID, key);
PyErr_PrintEx(0);
return 0;
}
if(kbe_stricmp(key, "_mapping") == 0)
{
PyErr_Format(PyExc_AssertionError, "KBEngine::delSpaceData: key{_mapping} is protected!",
spaceID);
PyErr_PrintEx(0);
return 0;
}
space->delSpaceData(key);
S_Return;
}
//-------------------------------------------------------------------------------------
}