move non-trivial PlayerProfile methods to source file: reduce compile time when code changes

git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@11157 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
undef-in-ed 2012-04-25 22:29:03 +00:00
parent 65629a5649
commit 4fdc916f9c
4 changed files with 88 additions and 51 deletions

View File

@ -21,6 +21,7 @@ src/challenges/challenge_data.cpp
src/challenges/game_slot.cpp
src/challenges/unlock_manager.cpp
src/config/device_config.cpp
src/config/player.cpp
src/config/stk_config.cpp
src/config/user_config.cpp
src/graphics/camera.cpp

View File

@ -58,6 +58,7 @@ supertuxkart_SOURCES = \
challenges/game_slot.hpp \
challenges/unlock_manager.cpp \
challenges/unlock_manager.hpp \
config/player.cpp \
config/player.hpp \
config/stk_config.cpp \
config/stk_config.hpp \

82
src/config/player.cpp Normal file
View File

@ -0,0 +1,82 @@
//
// SuperTuxKart - a fun racing game with go-kart
// Copyright (C) 2012
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU 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 General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include <stdlib.h>
#include "config/player.hpp"
#include "utils/string_utils.hpp"
//------------------------------------------------------------------------------
PlayerProfile::PlayerProfile(const core::stringw& name) :
m_player_group("Player", "Represents one human player"),
m_name(name, "name", &m_player_group),
m_is_guest_account(false, "guest", &m_player_group),
m_use_frequency(0, "use_frequency", &m_player_group),
m_unique_id("", "unique_id", &m_player_group)
{
#ifdef DEBUG
m_magic_number = 0xABCD1234;
#endif
int64_t unique_id = generateUniqueId(core::stringc(name.c_str()).c_str());
char buffer[32];
sprintf(buffer, "%llx", unique_id);
m_unique_id = buffer;
}
//------------------------------------------------------------------------------
PlayerProfile::PlayerProfile(const XMLNode* node) :
m_player_group("Player", "Represents one human player"),
m_name("-", "name", &m_player_group),
m_is_guest_account(false, "guest", &m_player_group),
m_use_frequency(0, "use_frequency", &m_player_group),
m_unique_id("", "unique_id", &m_player_group)
{
//m_player_group.findYourDataInAChildOf(node);
m_name.findYourDataInAnAttributeOf(node);
m_is_guest_account.findYourDataInAnAttributeOf(node);
m_use_frequency.findYourDataInAnAttributeOf(node);
m_unique_id.findYourDataInAnAttributeOf(node);
if ((std::string)m_unique_id == "")
{
fprintf(stderr, "** WARNING: Player has no unique ID, probably it is from an older STK version\n");
int64_t unique_id = generateUniqueId(core::stringc(m_name.c_str()).c_str());
char buffer[32];
sprintf(buffer, "%llx", unique_id);
m_unique_id = buffer;
}
#ifdef DEBUG
m_magic_number = 0xABCD1234;
#endif
}
//------------------------------------------------------------------------------
void PlayerProfile::incrementUseFrequency()
{
if (m_is_guest_account) m_use_frequency = -1;
else m_use_frequency++;
}
//------------------------------------------------------------------------------
int64_t PlayerProfile::generateUniqueId(const char* playerName)
{
return ((int64_t)(Time::getTimeSinceEpoch()) << 32) |
(((rand()%65536) << 16) & 0xFFFF0000) |
(StringUtils::simpleHash(playerName) & 0xFFFF);
}

View File

@ -22,7 +22,6 @@
#include <string>
#include "config/user_config.hpp"
#include "utils/no_copy.hpp"
#include "utils/string_utils.hpp"
#include <irrString.h>
using namespace irr;
@ -54,63 +53,21 @@ protected:
*/
StringUserConfigParam m_unique_id;
int64_t generateUniqueId(const char* playerName)
{
return ((int64_t)(Time::getTimeSinceEpoch()) << 32) |
(((rand()%65536) << 16) & 0xFFFF0000) |
(StringUtils::simpleHash(playerName) & 0xFFFF);
}
int64_t generateUniqueId(const char* playerName);
public:
/**
* Constructor to create a new player that didn't exist before
*/
PlayerProfile(const core::stringw& name) : m_player_group("Player", "Represents one human player"),
m_name(name, "name", &m_player_group), //, m_last_kart_id(-1)
m_is_guest_account(false, "guest", &m_player_group),
m_use_frequency(0, "use_frequency", &m_player_group),
m_unique_id("", "unique_id", &m_player_group)
{
#ifdef DEBUG
m_magic_number = 0xABCD1234;
#endif
int64_t unique_id = generateUniqueId(core::stringc(name.c_str()).c_str());
char buffer[32];
sprintf(buffer, "%llx", unique_id);
m_unique_id = buffer;
}
PlayerProfile(const core::stringw& name);
/**
* Constructor to deserialize a player that was saved to a XML file
* (...UserConfigParam classes will automagically take care of serializing all
* create players to the user's config file)
*/
PlayerProfile(const XMLNode* node) : m_player_group("Player", "Represents one human player"),
m_name("-", "name", &m_player_group), //, m_last_kart_id(-1)
m_is_guest_account(false, "guest", &m_player_group),
m_use_frequency(0, "use_frequency", &m_player_group),
m_unique_id("", "unique_id", &m_player_group)
{
//m_player_group.findYourDataInAChildOf(node);
m_name.findYourDataInAnAttributeOf(node);
m_is_guest_account.findYourDataInAnAttributeOf(node);
m_use_frequency.findYourDataInAnAttributeOf(node);
m_unique_id.findYourDataInAnAttributeOf(node);
if ((std::string)m_unique_id == "")
{
fprintf(stderr, "** WARNING: Player has no unique ID, probably it is from an older STK version\n");
int64_t unique_id = generateUniqueId(core::stringc(m_name.c_str()).c_str());
char buffer[32];
sprintf(buffer, "%llx", unique_id);
m_unique_id = buffer;
}
#ifdef DEBUG
m_magic_number = 0xABCD1234;
#endif
}
PlayerProfile(const XMLNode* node);
~PlayerProfile()
@ -151,11 +108,7 @@ public:
}
void incrementUseFrequency()
{
if (m_is_guest_account) m_use_frequency = -1;
else m_use_frequency++;
}
void incrementUseFrequency();
// please do NOT try to optimise this to return a reference, I don't know why,
// maybe compiler bug, but hell breaks loose when you do that