Moved hash function from StringUtils into player, there is no
other use of that function.
This commit is contained in:
parent
6b27179b96
commit
d4b95e81b4
@ -36,9 +36,9 @@ PlayerProfile::PlayerProfile(const core::stringw& name) :
|
||||
#endif
|
||||
int64_t unique_id = generateUniqueId(core::stringc(name.c_str()).c_str());
|
||||
|
||||
std::ostringstream tostring;
|
||||
tostring << std::hex << unique_id;
|
||||
m_unique_id = tostring.str();
|
||||
std::ostringstream to_string;
|
||||
to_string << std::hex << unique_id;
|
||||
m_unique_id = to_string.str();
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
@ -67,19 +67,26 @@ PlayerProfile::PlayerProfile(const XMLNode* node) :
|
||||
#ifdef DEBUG
|
||||
m_magic_number = 0xABCD1234;
|
||||
#endif
|
||||
}
|
||||
} // PlayerProfile
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
void PlayerProfile::incrementUseFrequency()
|
||||
{
|
||||
if (m_is_guest_account) m_use_frequency = -1;
|
||||
else m_use_frequency++;
|
||||
}
|
||||
} // incrementUseFrequency
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
int64_t PlayerProfile::generateUniqueId(const char* playerName)
|
||||
int64_t PlayerProfile::generateUniqueId(const char* player_name)
|
||||
{
|
||||
// First create a simple hash based on he player name
|
||||
int hash = 0;
|
||||
for (int n=0; player_name[n] != 0; n++)
|
||||
{
|
||||
hash += (hash << (hash & 0xF)) ^ player_name[n];
|
||||
}
|
||||
|
||||
return ((int64_t)(StkTime::getTimeSinceEpoch()) << 32) |
|
||||
((rand() << 16) & 0xFFFF0000) |
|
||||
(StringUtils::simpleHash(playerName) & 0xFFFF);
|
||||
}
|
||||
hash;
|
||||
} // generateUniqueId
|
||||
|
@ -665,19 +665,6 @@ namespace StringUtils
|
||||
return output.str();
|
||||
} // encodeToHtmlEntities
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
unsigned int simpleHash(const char* input)
|
||||
{
|
||||
int hash = 0;
|
||||
for (int n=0; input[n] != 0; n++)
|
||||
{
|
||||
hash += (hash << (hash & 0xF)) ^ input[n];
|
||||
}
|
||||
|
||||
return hash;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
/** Converts a version string (in the form of 'X.Y.Za-rcU' into an
|
||||
* integer number.
|
||||
|
@ -61,9 +61,6 @@ namespace StringUtils
|
||||
|
||||
std::string encodeToHtmlEntities(const irr::core::stringw &output);
|
||||
|
||||
/** Compute a simple hash of a string */
|
||||
unsigned int simpleHash(const char* input);
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
template <class T>
|
||||
std::string toString (const T& any)
|
||||
|
Loading…
x
Reference in New Issue
Block a user