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. -->
|
Penalty: Penalty time if a kart accelerates before GO. -->
|
||||||
<startup penalty="1" />
|
<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 -->
|
<!-- If the normals (for wheel raycasts) should be smoothened -->
|
||||||
<physics smooth-normals="false"/>
|
<physics smooth-normals="false"/>
|
||||||
|
|
||||||
|
@ -236,13 +236,21 @@ void NetworkHttp::updateNews(const XMLNode *xml, const std::string &filename)
|
|||||||
if(node->getName()!="message") continue;
|
if(node->getName()!="message") continue;
|
||||||
std::string news;
|
std::string news;
|
||||||
node->get("content", &news);
|
node->get("content", &news);
|
||||||
|
int id=-1;
|
||||||
|
node->get("id", &id);
|
||||||
|
|
||||||
m_news.lock();
|
m_news.lock();
|
||||||
{
|
{
|
||||||
NewsMessage n(core::stringw(news.c_str()),
|
// While the xml file does not have an id:
|
||||||
m_news.getData().size());
|
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.getData().push_back(n);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
m_news.unlock();
|
m_news.unlock();
|
||||||
|
|
||||||
error = false;
|
error = false;
|
||||||
@ -260,6 +268,8 @@ void NetworkHttp::updateNews(const XMLNode *xml, const std::string &filename)
|
|||||||
m_news.getData().push_back(n);
|
m_news.getData().push_back(n);
|
||||||
m_news.unlock();
|
m_news.unlock();
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
updateMessageDisplayCount();
|
||||||
|
|
||||||
} // updateNews
|
} // updateNews
|
||||||
|
|
||||||
@ -315,12 +325,31 @@ const core::stringw NetworkHttp::getNextNewsMessage()
|
|||||||
core::stringw m("");
|
core::stringw m("");
|
||||||
m_news.lock();
|
m_news.lock();
|
||||||
{
|
{
|
||||||
|
// Check if we have a message that was finished being
|
||||||
|
// displayed --> increase display count.
|
||||||
if(m_current_news_message>-1)
|
if(m_current_news_message>-1)
|
||||||
{
|
{
|
||||||
// Now we have a message that was finished being
|
NewsMessage &n = m_news.getData()[m_current_news_message];
|
||||||
// displayed --> increase display count.
|
n.increaseDisplayCount();
|
||||||
m_news.getData()[m_current_news_message].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();
|
updateUserConfigFile();
|
||||||
|
//
|
||||||
|
if(m_news.getData().size()==0)
|
||||||
|
{
|
||||||
|
m_news.unlock();
|
||||||
|
return "";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
m_current_news_message++;
|
m_current_news_message++;
|
||||||
if(m_current_news_message >= (int)m_news.getData().size())
|
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
|
/** 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!
|
* Note that this function assumes that m_news is already locked!
|
||||||
*/
|
*/
|
||||||
void NetworkHttp::updateUserConfigFile() const
|
void NetworkHttp::updateUserConfigFile() const
|
||||||
@ -346,9 +377,38 @@ void NetworkHttp::updateUserConfigFile() const
|
|||||||
o << n.getMessageId() << ":"
|
o << n.getMessageId() << ":"
|
||||||
<< n.getDisplayCount() << " ";
|
<< n.getDisplayCount() << " ";
|
||||||
}
|
}
|
||||||
|
|
||||||
UserConfigParams::m_display_count = o.str();
|
UserConfigParams::m_display_count = o.str();
|
||||||
} // updateUserConfigFile
|
} // 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,
|
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;}
|
int getMessageId() const {return m_message_id;}
|
||||||
/** Returns the display count. */
|
/** Returns the display count. */
|
||||||
int getDisplayCount() const {return m_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
|
}; // NewsMessage
|
||||||
|
|
||||||
mutable Synchronised< std::vector<NewsMessage> > m_news;
|
mutable Synchronised< std::vector<NewsMessage> > m_news;
|
||||||
@ -81,6 +83,10 @@ private:
|
|||||||
/** Index of the current news message that is being displayed. */
|
/** Index of the current news message that is being displayed. */
|
||||||
int m_current_news_message;
|
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
|
/** Which command to execute next. Access to this variable is guarded
|
||||||
* by m_mutex_command and m_cond_command. */
|
* by m_mutex_command and m_cond_command. */
|
||||||
HttpCommands m_command;
|
HttpCommands m_command;
|
||||||
@ -116,6 +122,7 @@ private:
|
|||||||
void loadAddonsList(const XMLNode *xml,
|
void loadAddonsList(const XMLNode *xml,
|
||||||
const std::string &filename);
|
const std::string &filename);
|
||||||
std::string downloadToStrInternal(std::string url);
|
std::string downloadToStrInternal(std::string url);
|
||||||
|
void updateMessageDisplayCount();
|
||||||
bool downloadFileInternal(const std::string &file,
|
bool downloadFileInternal(const std::string &file,
|
||||||
const std::string &save_filename,
|
const std::string &save_filename,
|
||||||
bool is_asynchron);
|
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_music_credit_time, "music-credit-time" );
|
||||||
CHECK_NEG(m_leader_time_per_kart, "leader time-per-kart" );
|
CHECK_NEG(m_leader_time_per_kart, "leader time-per-kart" );
|
||||||
CHECK_NEG(m_penalty_time, "penalty-time" );
|
CHECK_NEG(m_penalty_time, "penalty-time" );
|
||||||
|
CHECK_NEG(m_max_display_news, "max-display-news" );
|
||||||
|
|
||||||
m_kart_properties.checkAllSet(filename);
|
m_kart_properties.checkAllSet(filename);
|
||||||
} // load
|
} // load
|
||||||
@ -156,6 +157,7 @@ void STKConfig::init_defaults()
|
|||||||
m_max_kart_version = -100;
|
m_max_kart_version = -100;
|
||||||
m_min_track_version = -100;
|
m_min_track_version = -100;
|
||||||
m_max_track_version = -100;
|
m_max_track_version = -100;
|
||||||
|
m_max_display_news = -100;
|
||||||
m_title_music = NULL;
|
m_title_music = NULL;
|
||||||
m_enable_networking = true;
|
m_enable_networking = true;
|
||||||
m_smooth_normals = false;
|
m_smooth_normals = false;
|
||||||
@ -233,6 +235,11 @@ void STKConfig::getAllData(const XMLNode * root)
|
|||||||
startup_node->get("penalty", &m_penalty_time );
|
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"))
|
if (const XMLNode *music_node = root->getNode("music"))
|
||||||
{
|
{
|
||||||
std::string title_music;
|
std::string title_music;
|
||||||
|
@ -95,6 +95,8 @@ public:
|
|||||||
m_max_kart_version; /**<version supported by this binary. */
|
m_max_kart_version; /**<version supported by this binary. */
|
||||||
int m_min_track_version, /**<The minimum and maximum .track file */
|
int m_min_track_version, /**<The minimum and maximum .track file */
|
||||||
m_max_track_version; /**<version supported by this binary. */
|
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;
|
bool m_enable_networking;
|
||||||
|
|
||||||
std::vector<float>
|
std::vector<float>
|
||||||
|
@ -437,12 +437,21 @@ namespace UserConfigParams
|
|||||||
&m_addon_group,
|
&m_addon_group,
|
||||||
"How often all news messages have been displayed") );
|
"How often all news messages have been displayed") );
|
||||||
|
|
||||||
|
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_PREFIX TimeUserConfigParam m_addons_last_updated
|
||||||
PARAM_DEFAULT( TimeUserConfigParam(0, "addon_last_updated",
|
PARAM_DEFAULT( TimeUserConfigParam(0, "addon_last_updated",
|
||||||
&m_addon_group,
|
&m_addon_group,
|
||||||
"Time addon-list was updated last.") );
|
"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_DEFAULT( StringUserConfigParam("system", "language", "Which language to use (language code or 'system')") );
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user