Read in the number of times a message was displayed from the user config file,
and discared messages that have been displayed often enough. Note that this is mostly a first test, we might want to only increase the display counter once each time STK is started or so. git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@8058 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
parent
ff152bfeed
commit
30d39e30f0
@ -36,6 +36,10 @@
|
||||
Penalty: Penalty time if a kart accelerates before GO. -->
|
||||
<startup penalty="1" />
|
||||
|
||||
<!-- How often a news message is going to be displayed before
|
||||
it will be ignored. -->
|
||||
<news max-display="10"/>
|
||||
|
||||
<!-- If the normals (for wheel raycasts) should be smoothened -->
|
||||
<physics smooth-normals="false"/>
|
||||
|
||||
|
@ -236,12 +236,20 @@ void NetworkHttp::updateNews(const XMLNode *xml, const std::string &filename)
|
||||
if(node->getName()!="message") continue;
|
||||
std::string news;
|
||||
node->get("content", &news);
|
||||
int id=-1;
|
||||
node->get("id", &id);
|
||||
|
||||
m_news.lock();
|
||||
{
|
||||
NewsMessage n(core::stringw(news.c_str()),
|
||||
m_news.getData().size());
|
||||
m_news.getData().push_back(n);
|
||||
// While the xml file does not have an id:
|
||||
if(id==-1)
|
||||
id = m_news.getData().size();
|
||||
// Only add the news if it's not supposed to be ignored.
|
||||
if(id>UserConfigParams::m_ignore_message_id)
|
||||
{
|
||||
NewsMessage n(core::stringw(news.c_str()), id);
|
||||
m_news.getData().push_back(n);
|
||||
}
|
||||
}
|
||||
m_news.unlock();
|
||||
|
||||
@ -260,6 +268,8 @@ void NetworkHttp::updateNews(const XMLNode *xml, const std::string &filename)
|
||||
m_news.getData().push_back(n);
|
||||
m_news.unlock();
|
||||
}
|
||||
else
|
||||
updateMessageDisplayCount();
|
||||
|
||||
} // updateNews
|
||||
|
||||
@ -315,12 +325,31 @@ const core::stringw NetworkHttp::getNextNewsMessage()
|
||||
core::stringw m("");
|
||||
m_news.lock();
|
||||
{
|
||||
// Check if we have a message that was finished being
|
||||
// displayed --> increase display count.
|
||||
if(m_current_news_message>-1)
|
||||
{
|
||||
// Now we have a message that was finished being
|
||||
// displayed --> increase display count.
|
||||
m_news.getData()[m_current_news_message].increaseDisplayCount();
|
||||
NewsMessage &n = m_news.getData()[m_current_news_message];
|
||||
n.increaseDisplayCount();
|
||||
|
||||
// If the message is being displayed often enough,
|
||||
// ignore it from now on.
|
||||
if(n.getDisplayCount()>stk_config->m_max_display_news)
|
||||
{
|
||||
// Messages have sequential numbers, so we only store
|
||||
// the latest message id (which is the current one)
|
||||
UserConfigParams::m_ignore_message_id = n.getMessageId();
|
||||
m_news.getData().erase(m_news.getData().begin()
|
||||
+m_current_news_message );
|
||||
|
||||
}
|
||||
updateUserConfigFile();
|
||||
//
|
||||
if(m_news.getData().size()==0)
|
||||
{
|
||||
m_news.unlock();
|
||||
return "";
|
||||
}
|
||||
}
|
||||
m_current_news_message++;
|
||||
if(m_current_news_message >= (int)m_news.getData().size())
|
||||
@ -334,7 +363,9 @@ const core::stringw NetworkHttp::getNextNewsMessage()
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
/** Saves the information about which message was being displayed how often
|
||||
* to the user config file.
|
||||
* to the user config file. It dnoes not actually save the user config
|
||||
* file, this is left to the main program (user config is saved at
|
||||
* the exit of the program).
|
||||
* Note that this function assumes that m_news is already locked!
|
||||
*/
|
||||
void NetworkHttp::updateUserConfigFile() const
|
||||
@ -346,9 +377,38 @@ void NetworkHttp::updateUserConfigFile() const
|
||||
o << n.getMessageId() << ":"
|
||||
<< n.getDisplayCount() << " ";
|
||||
}
|
||||
|
||||
UserConfigParams::m_display_count = o.str();
|
||||
} // updateUserConfigFile
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
/** Reads the information about which message was dislpayed how often from
|
||||
* the user config file.
|
||||
*/
|
||||
void NetworkHttp::updateMessageDisplayCount()
|
||||
{
|
||||
m_news.lock();
|
||||
std::vector<std::string> pairs =
|
||||
StringUtils::split(UserConfigParams::m_display_count,' ');
|
||||
for(unsigned int i=0; i<pairs.size(); i++)
|
||||
{
|
||||
std::vector<std::string> v = StringUtils::split(pairs[i], ':');
|
||||
int id, count;
|
||||
StringUtils::fromString(v[0], id);
|
||||
StringUtils::fromString(v[1], count);
|
||||
// Search all downloaded messages for this id.
|
||||
for(unsigned int j=0; j<m_news.getData().size(); j++)
|
||||
{
|
||||
if(m_news.getData()[j].getMessageId()!=id)
|
||||
continue;
|
||||
m_news.getData()[j].setDisplayCount(count);
|
||||
if(count>stk_config->m_max_display_news)
|
||||
m_news.getData().erase(m_news.getData().begin()+j);
|
||||
break;
|
||||
} // for j <m_news.getData().size()
|
||||
}
|
||||
m_news.unlock();
|
||||
} // updateMessageDisplayCount
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
size_t NetworkHttp::writeStr(char ptr [], size_t size, size_t nb_char,
|
||||
|
@ -74,6 +74,8 @@ private:
|
||||
int getMessageId() const {return m_message_id;}
|
||||
/** Returns the display count. */
|
||||
int getDisplayCount() const {return m_display_count; }
|
||||
/** Sets the display count for this message. */
|
||||
void setDisplayCount(int n) {m_display_count = n; }
|
||||
}; // NewsMessage
|
||||
|
||||
mutable Synchronised< std::vector<NewsMessage> > m_news;
|
||||
@ -81,6 +83,10 @@ private:
|
||||
/** Index of the current news message that is being displayed. */
|
||||
int m_current_news_message;
|
||||
|
||||
/** Stores the news message display count from the user config file.
|
||||
*/
|
||||
std::vector<int> m_saved_display_count;
|
||||
|
||||
/** Which command to execute next. Access to this variable is guarded
|
||||
* by m_mutex_command and m_cond_command. */
|
||||
HttpCommands m_command;
|
||||
@ -116,6 +122,7 @@ private:
|
||||
void loadAddonsList(const XMLNode *xml,
|
||||
const std::string &filename);
|
||||
std::string downloadToStrInternal(std::string url);
|
||||
void updateMessageDisplayCount();
|
||||
bool downloadFileInternal(const std::string &file,
|
||||
const std::string &save_filename,
|
||||
bool is_asynchron);
|
||||
|
@ -127,6 +127,7 @@ void STKConfig::load(const std::string &filename)
|
||||
CHECK_NEG(m_music_credit_time, "music-credit-time" );
|
||||
CHECK_NEG(m_leader_time_per_kart, "leader time-per-kart" );
|
||||
CHECK_NEG(m_penalty_time, "penalty-time" );
|
||||
CHECK_NEG(m_max_display_news, "max-display-news" );
|
||||
|
||||
m_kart_properties.checkAllSet(filename);
|
||||
} // load
|
||||
@ -156,6 +157,7 @@ void STKConfig::init_defaults()
|
||||
m_max_kart_version = -100;
|
||||
m_min_track_version = -100;
|
||||
m_max_track_version = -100;
|
||||
m_max_display_news = -100;
|
||||
m_title_music = NULL;
|
||||
m_enable_networking = true;
|
||||
m_smooth_normals = false;
|
||||
@ -233,6 +235,11 @@ void STKConfig::getAllData(const XMLNode * root)
|
||||
startup_node->get("penalty", &m_penalty_time );
|
||||
}
|
||||
|
||||
if (const XMLNode *news_node= root->getNode("news"))
|
||||
{
|
||||
news_node->get("max-display", &m_max_display_news);
|
||||
}
|
||||
|
||||
if (const XMLNode *music_node = root->getNode("music"))
|
||||
{
|
||||
std::string title_music;
|
||||
|
@ -95,6 +95,8 @@ public:
|
||||
m_max_kart_version; /**<version supported by this binary. */
|
||||
int m_min_track_version, /**<The minimum and maximum .track file */
|
||||
m_max_track_version; /**<version supported by this binary. */
|
||||
int m_max_display_news; /**<How often a news message is displayed
|
||||
before it is ignored. */
|
||||
bool m_enable_networking;
|
||||
|
||||
std::vector<float>
|
||||
|
@ -412,7 +412,7 @@ namespace UserConfigParams
|
||||
PARAM_DEFAULT( StringUserConfigParam("Peach.stkskin", "skin_file", "Name of the skin to use") );
|
||||
|
||||
// ---- Addon server related entries
|
||||
PARAM_PREFIX GroupUserConfigParam m_addon_group
|
||||
PARAM_PREFIX GroupUserConfigParam m_addon_group
|
||||
PARAM_DEFAULT( GroupUserConfigParam("AddonAndNews",
|
||||
"Addon and news related settings") );
|
||||
|
||||
@ -422,7 +422,7 @@ namespace UserConfigParams
|
||||
&m_addon_group,
|
||||
"The server used for addon.") );
|
||||
|
||||
PARAM_PREFIX TimeUserConfigParam m_news_last_updated
|
||||
PARAM_PREFIX TimeUserConfigParam m_news_last_updated
|
||||
PARAM_DEFAULT( TimeUserConfigParam(0, "news_last_updated",
|
||||
&m_addon_group,
|
||||
"Time news was updated last.") );
|
||||
@ -437,22 +437,31 @@ namespace UserConfigParams
|
||||
&m_addon_group,
|
||||
"How often all news messages have been displayed") );
|
||||
|
||||
PARAM_PREFIX TimeUserConfigParam m_addons_last_updated
|
||||
PARAM_PREFIX IntUserConfigParam m_ignore_message_id
|
||||
PARAM_DEFAULT( IntUserConfigParam(-1, "ignore_message_id",
|
||||
&m_addon_group,
|
||||
"Ignore all messages with this id and lower") );
|
||||
|
||||
PARAM_PREFIX BoolUserConfigParam m_enable_internet
|
||||
PARAM_DEFAULT( BoolUserConfigParam(true, "enable_internet",
|
||||
&m_addon_group,
|
||||
"Enable news and addons server") );
|
||||
|
||||
PARAM_PREFIX TimeUserConfigParam m_addons_last_updated
|
||||
PARAM_DEFAULT( TimeUserConfigParam(0, "addon_last_updated",
|
||||
&m_addon_group,
|
||||
"Time addon-list was updated last.") );
|
||||
|
||||
|
||||
PARAM_PREFIX StringUserConfigParam m_language
|
||||
PARAM_PREFIX StringUserConfigParam m_language
|
||||
PARAM_DEFAULT( StringUserConfigParam("system", "language", "Which language to use (language code or 'system')") );
|
||||
|
||||
PARAM_PREFIX BoolUserConfigParam m_artist_debug_mode
|
||||
PARAM_PREFIX BoolUserConfigParam m_artist_debug_mode
|
||||
PARAM_DEFAULT( BoolUserConfigParam(false, "artist_debug_mode", "Whether to enable track debugging features") );
|
||||
|
||||
// TODO? implement blacklist for new irrlicht device and GUI
|
||||
PARAM_PREFIX std::vector<std::string> m_blacklist_res;
|
||||
|
||||
PARAM_PREFIX PtrVector<PlayerProfile> m_all_players;
|
||||
PARAM_PREFIX PtrVector<PlayerProfile> m_all_players;
|
||||
|
||||
}
|
||||
#undef PARAM_PREFIX
|
||||
|
Loading…
Reference in New Issue
Block a user