From a3a347fab424bcea6371a0854a270f7fde4dd7a2 Mon Sep 17 00:00:00 2001 From: kaetemi Date: Fri, 12 Sep 2014 09:13:25 +0200 Subject: [PATCH] Add optional null bit to CDB leafs --HG-- branch : cdb-packed --- code/nel/include/nel/misc/cdb_leaf.h | 4 + code/nel/src/misc/cdb_leaf.cpp | 57 ++++-- code/ryzom/common/data_common/database.xml | 187 ++++++++++++------ .../player_manager/cdb_leaf.cpp | 12 ++ .../player_manager/cdb_leaf.h | 8 +- .../player_manager/cdb_synchronised.cpp | 48 +++-- 6 files changed, 229 insertions(+), 87 deletions(-) diff --git a/code/nel/include/nel/misc/cdb_leaf.h b/code/nel/include/nel/misc/cdb_leaf.h index e3df6f8b3..aa6055de6 100644 --- a/code/nel/include/nel/misc/cdb_leaf.h +++ b/code/nel/include/nel/misc/cdb_leaf.h @@ -93,6 +93,7 @@ public: _Property = 0; _oldProperty = 0; _Type = UNKNOWN; + _Nullable = false; _Changed = false; _LastChangeGC = 0; } @@ -232,6 +233,9 @@ private: /// property type EPropType _Type; + /// nullable + bool _Nullable; + /// true if this value has changed bool _Changed; diff --git a/code/nel/src/misc/cdb_leaf.cpp b/code/nel/src/misc/cdb_leaf.cpp index 79f36e5b0..590715091 100644 --- a/code/nel/src/misc/cdb_leaf.cpp +++ b/code/nel/src/misc/cdb_leaf.cpp @@ -43,6 +43,18 @@ namespace NLMISC{ //----------------------------------------------- void CCDBNodeLeaf::init( xmlNodePtr node, IProgressCallback &/* progressCallBack */, bool /* mapBanks */, CCDBBankHandler * /* bankHandler */ ) { + // Read nullable + CXMLAutoPtr nullable((const char*)xmlGetProp (node, (xmlChar*)"nullable")); + if ((const char *) nullable != NULL) + { + _Nullable = (nullable.getDatas()[0] == '1'); + } + else + { + _Nullable = false; + } + + // Read type CXMLAutoPtr type((const char*)xmlGetProp (node, (xmlChar*)"type")); nlassert((const char *) type != NULL); @@ -145,17 +157,26 @@ void CCDBNodeLeaf::readDelta(TGameCycle gc, CBitMemStream & f ) { // Read the Property Value according to the Property Type. uint64 recvd = 0; - uint bits; - if (_Type == TEXT) - bits = 32; - else if (_Type == PACKED) - bits = readPackedBitCount(f); - else if (_Type <= I64) - bits = _Type; - else - bits = _Type - 64; - f.serial(recvd, bits); + uint64 isNull = 0; + if (_Nullable) + { + f.serial(isNull, 1); + } + + uint bits; + if (!isNull) + { + if (_Type == TEXT) + bits = 32; + else if (_Type == PACKED) + bits = readPackedBitCount(f); + else if (_Type <= I64) + bits = _Type; + else + bits = _Type - 64; + f.serial(recvd, bits); + } // if the DB update is older than last DB update, abort (but after the read!!) if(gc<_LastChangeGC) @@ -170,16 +191,22 @@ void CCDBNodeLeaf::readDelta(TGameCycle gc, CBitMemStream & f ) // if signed if (! ((_Type == TEXT) || (_Type == PACKED) || (_Type <= I64))) { - // extend bit sign - sint64 mask = (((sint64)1)<> (bits-1))==1 ) + if (!isNull) { - _Property |= ~mask; + // extend bit sign + sint64 mask = (((sint64)1)<> (bits-1))==1 ) + { + _Property |= ~mask; + } } } if ( verboseDatabase ) { - nlinfo( "CDB: Read value (%u bits) %"NL_I64"d", bits, _Property ); + if (!isNull) + nlinfo( "CDB: Read value (%u bits) %"NL_I64"d", bits, _Property ); + else + nlinfo( "CDB: Read null value %"NL_I64"d", _Property ); } // bkup the date of change diff --git a/code/ryzom/common/data_common/database.xml b/code/ryzom/common/data_common/database.xml index 620254daa..c40713731 100644 --- a/code/ryzom/common/data_common/database.xml +++ b/code/ryzom/common/data_common/database.xml @@ -1,4 +1,8 @@ + @@ -149,7 +154,8 @@ + type="I64" + nullable="1" /> @@ -195,7 +201,8 @@ + type="I32" + nullable="1" /> @@ -207,13 +214,16 @@ + type="I32" + nullable="1" /> + type="I32" + nullable="1" /> @@ -221,10 +231,12 @@ + type="I32" + nullable="1" /> + type="I32" + nullable="1" /> @@ -275,18 +287,23 @@ type="I2" /> + type="I32" + nullable="1" /> + type="I32" + nullable="1" /> + type="I32" + nullable="1" /> + type="I32" + nullable="1" /> @@ -294,9 +311,11 @@ + type="I32" + nullable="1" /> + type="I32" + nullable="1" /> @@ -304,11 +323,14 @@ count="8" atom="1"> + type="I32" + nullable="1" /> + type="I32" + nullable="1" /> + type="I32" + nullable="1" /> + type="I32" + nullable="1" /> @@ -370,6 +393,7 @@ @@ -382,7 +406,8 @@ type="I16" /> + type="I32" + nullable="1" /> @@ -402,6 +427,7 @@ @@ -414,7 +440,8 @@ type="I16" /> + type="I32" + nullable="1" /> @@ -549,6 +576,7 @@ @@ -563,7 +591,8 @@ type="I16" /> + type="I32" + nullable="1" /> @@ -591,6 +620,7 @@ @@ -602,7 +632,8 @@ type="I16" /> + type="I32" + nullable="1" /> @@ -692,11 +723,13 @@ count="12"> + type="I32" + nullable="1" /> @@ -704,11 +737,13 @@ count="12"> + type="I32" + nullable="1" /> @@ -717,10 +752,12 @@ + type="I16" + nullable="1" /> + type="I32" + nullable="1" /> @@ -729,16 +766,20 @@ bank="PLR"> + type="I32" + nullable="1" /> + type="I32" + nullable="1" /> + type="I32" + nullable="1" /> + type="I32" + nullable="1" /> @@ -749,19 +790,23 @@ + type="I32" + nullable="1" /> + type="I32" + nullable="1" /> + type="I32" + nullable="1" /> + type="I32" + nullable="1" /> @@ -785,9 +830,11 @@ if high order bit == 1 : low order bits = entry in the LIFT_ICONS::TLiftIcon enum --> + type="I64" + nullable="1" /> + type="I32" + nullable="1" /> + type="I32" + nullable="1" /> + type="I32" + nullable="1" /> @@ -854,6 +904,7 @@ @@ -866,7 +917,8 @@ type="I16" /> + type="I32" + nullable="1" /> @@ -887,6 +939,7 @@ + type="TEXT" + nullable="1" /> @@ -924,7 +978,8 @@ + type="PACKED" + nullable="1" /> + type="I32" + nullable="1" /> + type="I32" + nullable="1" /> + type="I32" + nullable="1" /> + type="I32" + nullable="1" /> @@ -955,9 +1015,11 @@ + type="I32" + nullable="1" /> + type="I32" + nullable="1" /> @@ -965,11 +1027,14 @@ count="8" atom="1"> + type="I32" + nullable="1" /> + type="I32" + nullable="1" /> + type="I32" + nullable="1" /> + type="I32" + nullable="1" /> @@ -999,6 +1065,7 @@ + type="TEXT" + nullable="1" /> @@ -1093,7 +1161,8 @@ + type="TEXT" + nullable="1" /> @@ -1103,7 +1172,8 @@ cppType="TCharConnectionState" /> + type="I32" + nullable="1" /> @@ -1241,6 +1311,7 @@ count="16"> @@ -1254,6 +1325,7 @@ @@ -1277,6 +1350,7 @@ count="4"> @@ -1505,7 +1579,8 @@ + type="I32" + nullable="1" /> + type="I32" + nullable="1" /> + type="I64" + nullable="1" /> diff --git a/code/ryzom/server/src/entities_game_service/player_manager/cdb_leaf.cpp b/code/ryzom/server/src/entities_game_service/player_manager/cdb_leaf.cpp index 03616c460..34542d376 100644 --- a/code/ryzom/server/src/entities_game_service/player_manager/cdb_leaf.cpp +++ b/code/ryzom/server/src/entities_game_service/player_manager/cdb_leaf.cpp @@ -45,6 +45,18 @@ using namespace std; //----------------------------------------------- void CCDBStructNodeLeaf::init( xmlNodePtr node, NLMISC::IProgressCallback &progressCallBack ) { + // Read nullable + CXMLAutoPtr nullable((const char*)xmlGetProp (node, (xmlChar*)"nullable")); + if ((const char *) nullable != NULL) + { + _Nullable = (nullable.getDatas()[0] == '1'); + } + else + { + _Nullable = false; + } + + // Read type CXMLAutoPtr type((const char*)xmlGetProp (node, (xmlChar*)"type")); nlassert((const char *) type != NULL); diff --git a/code/ryzom/server/src/entities_game_service/player_manager/cdb_leaf.h b/code/ryzom/server/src/entities_game_service/player_manager/cdb_leaf.h index 97fabde04..f7205f766 100644 --- a/code/ryzom/server/src/entities_game_service/player_manager/cdb_leaf.h +++ b/code/ryzom/server/src/entities_game_service/player_manager/cdb_leaf.h @@ -36,6 +36,9 @@ public: /// Return the type of the property. inline const EPropType & type() const {return _Type;} + /// Return the type of the property. + inline bool nullable() const {return _Nullable;} + /// The overridden version that is usable from ICDBStructNode virtual EPropType getType() const {return _Type;} @@ -46,7 +49,7 @@ public: /** * Default constructor */ - CCDBStructNodeLeaf() : ICDBStructNode(), _Parent( NULL ), _Type( UNKNOWN ) {} + CCDBStructNodeLeaf() : ICDBStructNode(), _Parent( NULL ), _Type( UNKNOWN ), _Nullable( false ) {} /** * Build the structure of the database from a file @@ -178,6 +181,9 @@ private: /// property type EPropType _Type; + /// nullable + bool _Nullable; + /// Binary property id of the leaf (precalculated & stored to avoid having to get back in the tree to build it) CBinId _LeafId; }; diff --git a/code/ryzom/server/src/entities_game_service/player_manager/cdb_synchronised.cpp b/code/ryzom/server/src/entities_game_service/player_manager/cdb_synchronised.cpp index 823c3b070..3986e1044 100644 --- a/code/ryzom/server/src/entities_game_service/player_manager/cdb_synchronised.cpp +++ b/code/ryzom/server/src/entities_game_service/player_manager/cdb_synchronised.cpp @@ -582,26 +582,42 @@ void CCDBSynchronised::pushDelta( CBitMemStream& s, CCDBStructNodeLeaf *node, ui value = (uint64)_DataContainer.getValue64( index ); //_DataContainer.archiveCurrentValue( index ); - if ( node->type() == ICDBStructNode::TEXT ) + if ( node->nullable() && value == 0 ) { - s.serialAndLog2( value, 32 ); - bitsize += 32; - if ( VerboseDatabase ) - nldebug( "CDB: Pushing value %"NL_I64"d (TEXT-32) for index %d prop %s", (sint64)value, index, node->buildTextId().toString().c_str() ); - } - else if ( node->type() == ICDBStructNode::PACKED ) - { - uint bits; - pushPackedValue( s, value, bitsize, bits ); - if ( VerboseDatabase ) - nldebug( "CDB: Pushing value %"NL_I64"d (PACKED %u bits) for index %d prop %s", (sint64)value, bits, index, node->buildTextId().toString().c_str() ); + uint64 isNull = 1; + s.serialAndLog2( isNull, 1 ); + bitsize += 1; } else { - s.serialAndLog2( value, (uint)node->type() ); - bitsize += (uint32)node->type(); - if ( VerboseDatabase ) - nldebug( "CDB: Pushing value %"NL_I64"d (%u bits) for index %d prop %s", (sint64)value, (uint32)node->type(), index, node->buildTextId().toString().c_str() ); + if ( node->nullable() ) + { + uint64 isNull = 0; + s.serialAndLog2( isNull, 1 ); + bitsize += 1; + } + + if ( node->type() == ICDBStructNode::TEXT ) + { + s.serialAndLog2( value, 32 ); + bitsize += 32; + if ( VerboseDatabase ) + nldebug( "CDB: Pushing value %"NL_I64"d (TEXT-32) for index %d prop %s", (sint64)value, index, node->buildTextId().toString().c_str() ); + } + else if ( node->type() == ICDBStructNode::PACKED ) + { + uint bits; + pushPackedValue( s, value, bitsize, bits ); + if ( VerboseDatabase ) + nldebug( "CDB: Pushing value %"NL_I64"d (PACKED %u bits) for index %d prop %s", (sint64)value, bits, index, node->buildTextId().toString().c_str() ); + } + else + { + s.serialAndLog2( value, (uint)node->type() ); + bitsize += (uint32)node->type(); + if ( VerboseDatabase ) + nldebug( "CDB: Pushing value %"NL_I64"d (%u bits) for index %d prop %s", (sint64)value, (uint32)node->type(), index, node->buildTextId().toString().c_str() ); + } } } else