Extracted the CDB bank handling code into a new class CCDBBankHandler, the CDB system should be now totally independent of Ryzom.
--HG-- branch : cdb-refactoringhg/feature/sse2
parent
17eab4ef52
commit
decc92e75d
@ -0,0 +1,79 @@
|
||||
// Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
|
||||
// Copyright (C) 2010 Winch Gate Property Limited
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Affero General Public License as
|
||||
// published by the Free Software Foundation, either version 3 of the
|
||||
// License, or (at your option) any later version.
|
||||
//
|
||||
// This program 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 Affero General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
#ifndef CDB_BANK_HANDLER
|
||||
#define CDB_BANK_HANDLER
|
||||
|
||||
#include <vector>
|
||||
#include "nel/misc/types_nl.h"
|
||||
|
||||
namespace NLMISC{
|
||||
|
||||
class CCDBBankHandler{
|
||||
public:
|
||||
CCDBBankHandler( uint maxbanks );
|
||||
|
||||
~CCDBBankHandler(){}
|
||||
|
||||
uint getUIDForBank( uint bank ) const;
|
||||
|
||||
uint getBankForUID( uint uid ) const{ return _UnifiedIndexToBank[ uid ]; }
|
||||
|
||||
uint getLastUnifiedIndex() const{ return _CDBLastUnifiedIndex; }
|
||||
|
||||
uint getFirstLevelIdBits( uint bank ) const{ return _FirstLevelIdBitsByBank[ bank ]; }
|
||||
|
||||
std::string getBankName( uint bank ) const{ return _CDBBankNames[ bank ]; }
|
||||
|
||||
uint getBankByName( const std::string &name ) const;
|
||||
|
||||
void mapNodeByBank( const std::string &bankName );
|
||||
|
||||
void fillBankNames( const char **strings, uint size );
|
||||
|
||||
void resetNodeBankMapping(){ _UnifiedIndexToBank.clear(); }
|
||||
|
||||
void reset();
|
||||
|
||||
uint getUnifiedIndexToBankSize() const{ return _UnifiedIndexToBank.size(); }
|
||||
|
||||
void calcIdBitsByBank();
|
||||
|
||||
uint getServerToClientUIDMapping( uint bank, uint index ) const{ return _CDBBankToUnifiedIndexMapping[ bank ][ index ]; }
|
||||
|
||||
private:
|
||||
/// Mapping from server database index to client database index (first-level nodes)
|
||||
std::vector< std::vector< uint > > _CDBBankToUnifiedIndexMapping;
|
||||
|
||||
/// Mapping from client database index to bank IDs (first-level nodes)
|
||||
std::vector< uint > _UnifiedIndexToBank;
|
||||
|
||||
/// Last index mapped
|
||||
uint _CDBLastUnifiedIndex;
|
||||
|
||||
/// Number of bits for first-level branches, by bank
|
||||
std::vector< uint > _FirstLevelIdBitsByBank;
|
||||
|
||||
/// Names of the CDB banks
|
||||
std::vector< std::string > _CDBBankNames;
|
||||
|
||||
uint maxBanks;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -0,0 +1,96 @@
|
||||
// Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
|
||||
// Copyright (C) 2010 Winch Gate Property Limited
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Affero General Public License as
|
||||
// published by the Free Software Foundation, either version 3 of the
|
||||
// License, or (at your option) any later version.
|
||||
//
|
||||
// This program 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 Affero General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
#include "nel/misc/cdb_bank_handler.h"
|
||||
|
||||
namespace NLMISC{
|
||||
CCDBBankHandler::CCDBBankHandler(uint maxbanks) :
|
||||
_CDBBankToUnifiedIndexMapping( maxbanks, std::vector< uint >() ),
|
||||
_FirstLevelIdBitsByBank( maxbanks )
|
||||
{
|
||||
std::fill( _FirstLevelIdBitsByBank.begin(), _FirstLevelIdBitsByBank.end(), 0 );
|
||||
maxBanks = maxbanks;
|
||||
}
|
||||
|
||||
uint CCDBBankHandler::getUIDForBank( uint bank ) const
|
||||
{
|
||||
uint uid = static_cast< uint >( -1 );
|
||||
|
||||
for( uint i = 0; i < _UnifiedIndexToBank.size(); i++ )
|
||||
if( _UnifiedIndexToBank[ i ] == bank )
|
||||
return i;
|
||||
|
||||
return uid;
|
||||
}
|
||||
|
||||
uint CCDBBankHandler::getBankByName( const std::string &name ) const
|
||||
{
|
||||
uint b = static_cast< uint >( -1 );
|
||||
|
||||
for( uint i = 0; i < _CDBBankNames.size(); i++ )
|
||||
if( _CDBBankNames[ i ].compare( name ) == 0 )
|
||||
return i;
|
||||
|
||||
return b;
|
||||
}
|
||||
|
||||
void CCDBBankHandler::mapNodeByBank( const std::string &bankName )
|
||||
{
|
||||
uint b = getBankByName( bankName );
|
||||
// no such bank
|
||||
if( b == static_cast< uint >( -1 ) )
|
||||
return;
|
||||
|
||||
_CDBBankToUnifiedIndexMapping[ b ].push_back( _CDBLastUnifiedIndex );
|
||||
++_CDBLastUnifiedIndex;
|
||||
_UnifiedIndexToBank.push_back( b );
|
||||
}
|
||||
|
||||
void CCDBBankHandler::fillBankNames( const char **strings, uint size )
|
||||
{
|
||||
_CDBBankNames.clear();
|
||||
|
||||
for( uint i = 0; i < size; i++ )
|
||||
_CDBBankNames.push_back( std::string( strings[ i ] ) );
|
||||
}
|
||||
|
||||
void CCDBBankHandler::reset()
|
||||
{
|
||||
for( std::vector< std::vector< uint > >::iterator itr =_CDBBankToUnifiedIndexMapping.begin();
|
||||
itr != _CDBBankToUnifiedIndexMapping.end(); ++itr )
|
||||
itr->clear();
|
||||
|
||||
_UnifiedIndexToBank.clear();
|
||||
_CDBLastUnifiedIndex = 0;
|
||||
}
|
||||
|
||||
void CCDBBankHandler::calcIdBitsByBank()
|
||||
{
|
||||
for( uint bank = 0; bank != maxBanks; bank++ )
|
||||
{
|
||||
uint nbNodesOfBank = static_cast< uint >( _CDBBankToUnifiedIndexMapping[ bank ].size() );
|
||||
uint idb = 0;
|
||||
|
||||
if ( nbNodesOfBank > 0 )
|
||||
for ( idb = 1; nbNodesOfBank > unsigned( 1 << idb ) ; idb++ )
|
||||
;
|
||||
|
||||
_FirstLevelIdBitsByBank[ bank ] = idb;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue