Skip to content

Commit fd20de0

Browse files
committed
增加对def中Index标记的解析。
1 parent ceddf5c commit fd20de0

File tree

5 files changed

+90
-33
lines changed

5 files changed

+90
-33
lines changed

kbe/src/lib/entitydef/entitydef.cpp

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,30 @@ bool EntityDef::initialize(std::vector<PyTypeObject*>& scriptBaseTypes,
209209
return false;
210210
}
211211

212+
// 检查索引的合法性
213+
ScriptDefModule::PROPERTYDESCRIPTION_MAP tpmaps;
214+
tpmaps.insert(scriptModule->getBasePropertyDescriptions().begin(), scriptModule->getBasePropertyDescriptions().end());
215+
tpmaps.insert(scriptModule->getCellPropertyDescriptions().begin(), scriptModule->getCellPropertyDescriptions().end());
216+
tpmaps.insert(scriptModule->getClientPropertyDescriptions().begin(), scriptModule->getClientPropertyDescriptions().end());
217+
218+
ScriptDefModule::PROPERTYDESCRIPTION_MAP::iterator pmiter = tpmaps.begin();
219+
std::string hasUnique = "";
220+
for(; pmiter != tpmaps.end(); pmiter++)
221+
{
222+
if(strcmp(pmiter->second->indexType(), "unique") == 0)
223+
{
224+
if(hasUnique.size() != 0)
225+
{
226+
ERROR_MSG(fmt::format("EntityDef::initialize({}):can be only one \'unique index\'({}, {})!\n",
227+
moduleName.c_str(), pmiter->second->getName(), hasUnique));
228+
229+
return false;
230+
}
231+
232+
hasUnique = pmiter->second->getName();
233+
}
234+
}
235+
212236
scriptModule->onLoaded();
213237
}
214238
XML_FOR_END(node);
@@ -554,6 +578,7 @@ bool EntityDef::loadDefPropertys(const std::string& moduleName,
554578
bool isPersistent = false;
555579
bool isIdentifier = false; // 是否是一个索引键
556580
uint32 databaseLength = 0; // 这个属性在数据库中的长度
581+
std::string indexType;
557582
DETAIL_TYPE detailLevel = DETAIL_LEVEL_FAR;
558583
std::string detailLevelStr = "";
559584
std::string strType;
@@ -630,6 +655,16 @@ bool EntityDef::loadDefPropertys(const std::string& moduleName,
630655
dataType = DataTypes::getDataType(strType);
631656
}
632657

658+
TiXmlNode* indexTypeNode = xml->enterNode(defPropertyNode->FirstChild(), "Index");
659+
if(indexTypeNode)
660+
{
661+
indexType = xml->getValStr(indexTypeNode);
662+
663+
std::transform(indexType.begin(), indexType.end(),
664+
indexType.begin(), tolower); // 转换为小写
665+
}
666+
667+
633668
TiXmlNode* identifierNode = xml->enterNode(defPropertyNode->FirstChild(), "Identifier");
634669
if(identifierNode)
635670
{
@@ -698,7 +733,7 @@ bool EntityDef::loadDefPropertys(const std::string& moduleName,
698733
// 产生一个属性描述实例
699734
PropertyDescription* propertyDescription = PropertyDescription::createDescription(futype, strType,
700735
name, flags, isPersistent,
701-
dataType, isIdentifier,
736+
dataType, isIdentifier, indexType,
702737
databaseLength, defaultStr,
703738
detailLevel);
704739

@@ -716,7 +751,7 @@ bool EntityDef::loadDefPropertys(const std::string& moduleName,
716751
if(hasClientFlags > 0)
717752
ret = scriptModule->addPropertyDescription(name.c_str(),
718753
propertyDescription, CLIENT_TYPE);
719-
754+
720755
if(!ret)
721756
{
722757
ERROR_MSG(fmt::format("EntityDef::addPropertyDescription({}): {}.\n",

kbe/src/lib/entitydef/property.cpp

Lines changed: 33 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ PropertyDescription::PropertyDescription(ENTITY_PROPERTY_UID utype,
4242
bool isPersistent,
4343
DataType* dataType,
4444
bool isIdentifier,
45+
std::string indexType,
4546
uint32 databaseLength,
4647
std::string defaultStr,
4748
DETAIL_TYPE detailLevel):
@@ -55,7 +56,8 @@ PropertyDescription::PropertyDescription(ENTITY_PROPERTY_UID utype,
5556
utype_(utype),
5657
defaultValStr_(defaultStr),
5758
detailLevel_(detailLevel),
58-
aliasID_(-1)
59+
aliasID_(-1),
60+
indexType_(indexType)
5961
{
6062
dataType_->incRef();
6163

@@ -134,6 +136,7 @@ PropertyDescription* PropertyDescription::createDescription(ENTITY_PROPERTY_UID
134136
bool isPersistent,
135137
DataType* dataType,
136138
bool isIdentifier,
139+
std::string indexType,
137140
uint32 databaseLength,
138141
std::string& defaultStr,
139142
DETAIL_TYPE detailLevel)
@@ -143,42 +146,42 @@ PropertyDescription* PropertyDescription::createDescription(ENTITY_PROPERTY_UID
143146
strcmp(dataType->getName(), "FIXED_DICT") == 0)
144147
{
145148
propertyDescription = new FixedDictDescription(utype, dataTypeName, name, flags, isPersistent,
146-
dataType, isIdentifier, databaseLength,
149+
dataType, isIdentifier, indexType, databaseLength,
147150
defaultStr, detailLevel);
148151
}
149152
else if(dataTypeName == "ARRAY" ||
150153
strcmp(dataType->getName(), "ARRAY") == 0)
151154
{
152155
propertyDescription = new ArrayDescription(utype, dataTypeName, name, flags, isPersistent,
153-
dataType, isIdentifier, databaseLength,
156+
dataType, isIdentifier, indexType, databaseLength,
154157
defaultStr, detailLevel);
155158

156159
}
157160
else if(dataTypeName == "VECTOR2" ||
158161
strcmp(dataType->getName(), "VECTOR2") == 0)
159162
{
160163
propertyDescription = new VectorDescription(utype, dataTypeName, name, flags, isPersistent,
161-
dataType, isIdentifier, databaseLength,
164+
dataType, isIdentifier, indexType, databaseLength,
162165
defaultStr, detailLevel, 2);
163166
}
164167
else if(dataTypeName == "VECTOR3" ||
165168
strcmp(dataType->getName(), "VECTOR3") == 0)
166169
{
167170
propertyDescription = new VectorDescription(utype, dataTypeName, name, flags, isPersistent,
168-
dataType, isIdentifier, databaseLength,
171+
dataType, isIdentifier, indexType, databaseLength,
169172
defaultStr, detailLevel, 3);
170173
}
171174
else if(dataTypeName == "VECTOR4" ||
172175
strcmp(dataType->getName(), "VECTOR4") == 0)
173176
{
174177
propertyDescription = new VectorDescription(utype, dataTypeName, name, flags, isPersistent,
175-
dataType, isIdentifier, databaseLength,
178+
dataType, isIdentifier, indexType, databaseLength,
176179
defaultStr, detailLevel, 4);
177180
}
178181
else
179182
{
180183
propertyDescription = new PropertyDescription(utype, dataTypeName, name, flags, isPersistent,
181-
dataType, isIdentifier, databaseLength,
184+
dataType, isIdentifier, indexType, databaseLength,
182185
defaultStr, detailLevel);
183186
}
184187

@@ -206,17 +209,18 @@ PyObject* PropertyDescription::onSetValue(PyObject* parentObj, PyObject* value)
206209

207210
//-------------------------------------------------------------------------------------
208211
FixedDictDescription::FixedDictDescription(ENTITY_PROPERTY_UID utype,
209-
std::string dataTypeName,
210-
std::string name,
211-
uint32 flags,
212-
bool isPersistent,
212+
std::string dataTypeName,
213+
std::string name,
214+
uint32 flags,
215+
bool isPersistent,
213216
DataType* dataType,
214217
bool isIdentifier,
218+
std::string indexType,
215219
uint32 databaseLength,
216220
std::string defaultStr,
217221
DETAIL_TYPE detailLevel):
218222
PropertyDescription(utype, dataTypeName, name, flags, isPersistent,
219-
dataType, isIdentifier, databaseLength, defaultStr, detailLevel)
223+
dataType, isIdentifier, indexType, databaseLength, defaultStr, detailLevel)
220224
{
221225
KBE_ASSERT(dataType->type() == DATA_TYPE_FIXEDDICT);
222226

@@ -278,17 +282,18 @@ PyObject* FixedDictDescription::createFromPersistentStream(MemoryStream* mstream
278282

279283
//-------------------------------------------------------------------------------------
280284
ArrayDescription::ArrayDescription(ENTITY_PROPERTY_UID utype,
281-
std::string dataTypeName,
282-
std::string name,
283-
uint32 flags,
284-
bool isPersistent,
285-
DataType* dataType,
286-
bool isIdentifier,
287-
uint32 databaseLength,
288-
std::string defaultStr,
289-
DETAIL_TYPE detailLevel):
285+
std::string dataTypeName,
286+
std::string name,
287+
uint32 flags,
288+
bool isPersistent,
289+
DataType* dataType,
290+
bool isIdentifier,
291+
std::string indexType,
292+
uint32 databaseLength,
293+
std::string defaultStr,
294+
DETAIL_TYPE detailLevel):
290295
PropertyDescription(utype, dataTypeName, name, flags, isPersistent,
291-
dataType, isIdentifier, databaseLength, defaultStr, detailLevel)
296+
dataType, isIdentifier, indexType, databaseLength, defaultStr, detailLevel)
292297
{
293298
}
294299

@@ -336,18 +341,19 @@ PyObject* ArrayDescription::createFromPersistentStream(MemoryStream* mstream)
336341

337342
//-------------------------------------------------------------------------------------
338343
VectorDescription::VectorDescription(ENTITY_PROPERTY_UID utype,
339-
std::string dataTypeName,
340-
std::string name,
341-
uint32 flags,
342-
bool isPersistent,
344+
std::string dataTypeName,
345+
std::string name,
346+
uint32 flags,
347+
bool isPersistent,
343348
DataType* dataType,
344349
bool isIdentifier,
350+
std::string indexType,
345351
uint32 databaseLength,
346352
std::string defaultStr,
347353
DETAIL_TYPE detailLevel,
348354
uint8 elemCount):
349355
PropertyDescription(utype, dataTypeName, name, flags, isPersistent,
350-
dataType, isIdentifier, databaseLength, defaultStr, detailLevel),
356+
dataType, isIdentifier, indexType, databaseLength, defaultStr, detailLevel),
351357
elemCount_(elemCount)
352358
{
353359
}

kbe/src/lib/entitydef/property.hpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ class PropertyDescription : public RefCountable
5353
bool isPersistent,
5454
DataType* dataType,
5555
bool isIdentifier,
56+
std::string indexType,
5657
uint32 databaseLength,
5758
std::string defaultStr,
5859
DETAIL_TYPE detailLevel);
@@ -99,6 +100,11 @@ class PropertyDescription : public RefCountable
99100
*/
100101
INLINE ENTITY_PROPERTY_UID getUType(void)const;
101102

103+
/**
104+
获取属性索引类别
105+
*/
106+
INLINE const char* indexType(void)const;
107+
102108
/**
103109
别名id, 当暴露的方法或者广播的属性总个数小于255时
104110
我们不使用utype而使用1字节的aliasID来传输
@@ -138,6 +144,7 @@ class PropertyDescription : public RefCountable
138144
bool isPersistent,
139145
DataType* dataType,
140146
bool isIdentifier,
147+
std::string indexType,
141148
uint32 databaseLength,
142149
std::string& defaultStr,
143150
DETAIL_TYPE detailLevel);
@@ -170,6 +177,7 @@ class PropertyDescription : public RefCountable
170177
std::string defaultValStr_; // 这个属性的默认值
171178
DETAIL_TYPE detailLevel_; // 这个属性的lod详情级别 看common中的:属性的lod广播级别范围的定义
172179
int16 aliasID_; // 别名id, 当暴露的方法或者广播的属性总个数小于255时, 我们不使用utype而使用1字节的aliasID来传输
180+
std::string indexType_; // 属性的索引类别,UNIQUE, INDEX,分别对应无设置、唯一索引、普通索引
173181
};
174182

175183
class FixedDictDescription : public PropertyDescription
@@ -182,6 +190,7 @@ class FixedDictDescription : public PropertyDescription
182190
bool isPersistent,
183191
DataType* dataType,
184192
bool isIdentifier,
193+
std::string indexType,
185194
uint32 databaseLength,
186195
std::string defaultStr,
187196
DETAIL_TYPE detailLevel);
@@ -211,6 +220,7 @@ class ArrayDescription : public PropertyDescription
211220
bool isPersistent,
212221
DataType* dataType,
213222
bool isIdentifier,
223+
std::string indexType,
214224
uint32 databaseLength,
215225
std::string defaultStr,
216226
DETAIL_TYPE detailLevel);
@@ -237,6 +247,7 @@ class VectorDescription : public PropertyDescription
237247
bool isPersistent,
238248
DataType* dataType,
239249
bool isIdentifier,
250+
std::string indexType,
240251
uint32 databaseLength,
241252
std::string defaultStr,
242253
DETAIL_TYPE detailLevel,

kbe/src/lib/entitydef/property.ipp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,11 @@ INLINE void PropertyDescription::aliasID(int16 v)
9191
aliasID_ = v;
9292
}
9393

94+
INLINE const char* PropertyDescription::indexType(void)const
95+
{
96+
return indexType_.c_str();
97+
}
98+
9499
INLINE bool PropertyDescription::hasCell(void)const
95100
{
96101
return (flags_ & ENTITY_CELL_DATA_FLAGS) > 0;

kbe/src/server/cellapp/entity.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1123,7 +1123,7 @@ int Entity::pySetPosition(PyObject *value)
11231123
posuid = msgInfo->msgid;
11241124
}
11251125

1126-
static PropertyDescription positionDescription(posuid, "VECTOR3", "position", ED_FLAG_ALL_CLIENTS, false, DataTypes::getDataType("VECTOR3"), false, 0, "", DETAIL_LEVEL_FAR);
1126+
static PropertyDescription positionDescription(posuid, "VECTOR3", "position", ED_FLAG_ALL_CLIENTS, false, DataTypes::getDataType("VECTOR3"), false, "", 0, "", DETAIL_LEVEL_FAR);
11271127
if(scriptModule_->usePropertyDescrAlias() && positionDescription.aliasID() == -1)
11281128
positionDescription.aliasID(ENTITY_BASE_PROPERTY_ALIASID_POSITION_XYZ);
11291129

@@ -1250,7 +1250,7 @@ int Entity::pySetDirection(PyObject *value)
12501250
diruid = msgInfo->msgid;
12511251
}
12521252

1253-
static PropertyDescription directionDescription(diruid, "VECTOR3", "direction", ED_FLAG_ALL_CLIENTS, false, DataTypes::getDataType("VECTOR3"), false, 0, "", DETAIL_LEVEL_FAR);
1253+
static PropertyDescription directionDescription(diruid, "VECTOR3", "direction", ED_FLAG_ALL_CLIENTS, false, DataTypes::getDataType("VECTOR3"), false, "", 0, "", DETAIL_LEVEL_FAR);
12541254
if(scriptModule_->usePropertyDescrAlias() && directionDescription.aliasID() == -1)
12551255
directionDescription.aliasID(ENTITY_BASE_PROPERTY_ALIASID_DIRECTION_ROLL_PITCH_YAW);
12561256

@@ -1293,7 +1293,7 @@ void Entity::onPyPositionChanged()
12931293
posuid = msgInfo->msgid;
12941294
}
12951295

1296-
static PropertyDescription positionDescription(posuid, "VECTOR3", "position", ED_FLAG_ALL_CLIENTS, false, DataTypes::getDataType("VECTOR3"), false, 0, "", DETAIL_LEVEL_FAR);
1296+
static PropertyDescription positionDescription(posuid, "VECTOR3", "position", ED_FLAG_ALL_CLIENTS, false, DataTypes::getDataType("VECTOR3"), false, "", 0, "", DETAIL_LEVEL_FAR);
12971297
if(scriptModule_->usePropertyDescrAlias() && positionDescription.aliasID() == -1)
12981298
positionDescription.aliasID(ENTITY_BASE_PROPERTY_ALIASID_POSITION_XYZ);
12991299

@@ -1340,7 +1340,7 @@ void Entity::onPyDirectionChanged()
13401340
diruid = msgInfo->msgid;
13411341
}
13421342

1343-
static PropertyDescription directionDescription(diruid, "VECTOR3", "direction", ED_FLAG_ALL_CLIENTS, false, DataTypes::getDataType("VECTOR3"), false, 0, "", DETAIL_LEVEL_FAR);
1343+
static PropertyDescription directionDescription(diruid, "VECTOR3", "direction", ED_FLAG_ALL_CLIENTS, false, DataTypes::getDataType("VECTOR3"), false, "", 0, "", DETAIL_LEVEL_FAR);
13441344
if(scriptModule_->usePropertyDescrAlias() && directionDescription.aliasID() == -1)
13451345
directionDescription.aliasID(ENTITY_BASE_PROPERTY_ALIASID_DIRECTION_ROLL_PITCH_YAW);
13461346

0 commit comments

Comments
 (0)