1
0
Fork 0

(svn r21512) -Change/Feature: make the delay of the chat messages timing out unrelated to the number of passed game days, i.e. don't stop aging chat messages when the server is paused

release/1.1
rubidium 2010-12-14 14:57:51 +00:00
parent 4045429df6
commit e68efb9e71
5 changed files with 17 additions and 11 deletions

View File

@ -249,7 +249,6 @@ static void OnNewMonth()
static void OnNewDay() static void OnNewDay()
{ {
#ifdef ENABLE_NETWORK #ifdef ENABLE_NETWORK
NetworkChatMessageDailyLoop();
if (_network_server) NetworkServerDailyLoop(); if (_network_server) NetworkServerDailyLoop();
#endif /* ENABLE_NETWORK */ #endif /* ENABLE_NETWORK */

View File

@ -165,7 +165,7 @@ bool NetworkCompanyIsPassworded(CompanyID company_id)
* If 'self_send' is true, this is the client who is sending the message */ * If 'self_send' is true, this is the client who is sending the message */
void NetworkTextMessage(NetworkAction action, ConsoleColour colour, bool self_send, const char *name, const char *str, int64 data) void NetworkTextMessage(NetworkAction action, ConsoleColour colour, bool self_send, const char *name, const char *str, int64 data)
{ {
const int duration = 10; // Game days the messages stay visible const int duration = 20; // Seconds the messages stay visible
StringID strid; StringID strid;
switch (action) { switch (action) {

View File

@ -40,7 +40,7 @@ static const uint NETWORK_CHAT_LINE_SPACING = 3;
struct ChatMessage { struct ChatMessage {
char message[DRAW_STRING_BUFFER]; char message[DRAW_STRING_BUFFER];
TextColour colour; TextColour colour;
Date end_date; uint32 remove_time;
}; };
/* used for chat window */ /* used for chat window */
@ -68,10 +68,10 @@ static inline uint GetChatMessageCount()
/** /**
* Add a text message to the 'chat window' to be shown * Add a text message to the 'chat window' to be shown
* @param colour The colour this message is to be shown in * @param colour The colour this message is to be shown in
* @param duration The duration of the chat message in game-days * @param duration The duration of the chat message in seconds
* @param message message itself in printf() style * @param message message itself in printf() style
*/ */
void CDECL NetworkAddChatMessage(TextColour colour, uint8 duration, const char *message, ...) void CDECL NetworkAddChatMessage(TextColour colour, uint duration, const char *message, ...)
{ {
char buf[DRAW_STRING_BUFFER]; char buf[DRAW_STRING_BUFFER];
const char *bufp; const char *bufp;
@ -104,7 +104,7 @@ void CDECL NetworkAddChatMessage(TextColour colour, uint8 duration, const char *
/* The default colour for a message is company colour. Replace this with /* The default colour for a message is company colour. Replace this with
* white for any additional lines */ * white for any additional lines */
cmsg->colour = (bufp == buf && (colour & IS_PALETTE_COLOUR)) ? colour : TC_WHITE; cmsg->colour = (bufp == buf && (colour & IS_PALETTE_COLOUR)) ? colour : TC_WHITE;
cmsg->end_date = _date + duration; cmsg->remove_time = _realtime_tick + duration * 1000;
bufp += strlen(bufp) + 1; // jump to 'next line' in the formatted string bufp += strlen(bufp) + 1; // jump to 'next line' in the formatted string
} }
@ -181,15 +181,15 @@ void NetworkUndrawChatMessage()
} }
} }
/** Check if a message is expired every day */ /** Check if a message is expired. */
void NetworkChatMessageDailyLoop() void NetworkChatMessageLoop()
{ {
for (uint i = 0; i < MAX_CHAT_MESSAGES; i++) { for (uint i = 0; i < MAX_CHAT_MESSAGES; i++) {
ChatMessage *cmsg = &_chatmsg_list[i]; ChatMessage *cmsg = &_chatmsg_list[i];
if (cmsg->message[0] == '\0') continue; if (cmsg->message[0] == '\0') continue;
/* Message has expired, remove from the list */ /* Message has expired, remove from the list */
if (cmsg->end_date < _date) { if (cmsg->remove_time < _realtime_tick) {
/* Move the remaining messages over the current message */ /* Move the remaining messages over the current message */
if (i != MAX_CHAT_MESSAGES - 1) memmove(cmsg, cmsg + 1, sizeof(*cmsg) * (MAX_CHAT_MESSAGES - i - 1)); if (i != MAX_CHAT_MESSAGES - 1) memmove(cmsg, cmsg + 1, sizeof(*cmsg) * (MAX_CHAT_MESSAGES - i - 1));

View File

@ -79,9 +79,9 @@ void NetworkServerKickClient(ClientID client_id);
uint NetworkServerKickOrBanIP(const char *ip, bool ban); uint NetworkServerKickOrBanIP(const char *ip, bool ban);
void NetworkInitChatMessage(); void NetworkInitChatMessage();
void CDECL NetworkAddChatMessage(TextColour colour, uint8 duration, const char *message, ...) WARN_FORMAT(3, 4); void CDECL NetworkAddChatMessage(TextColour colour, uint duration, const char *message, ...) WARN_FORMAT(3, 4);
void NetworkUndrawChatMessage(); void NetworkUndrawChatMessage();
void NetworkChatMessageDailyLoop(); void NetworkChatMessageLoop();
void NetworkAfterNewGRFScan(); void NetworkAfterNewGRFScan();

View File

@ -1359,6 +1359,13 @@ void GameLoop()
/* Singleplayer */ /* Singleplayer */
StateGameLoop(); StateGameLoop();
} }
/* Check chat messages roughly once a second. */
static uint check_message = 0;
if (++check_message > 1000 / MILLISECONDS_PER_TICK) {
check_message = 0;
NetworkChatMessageLoop();
}
#else #else
StateGameLoop(); StateGameLoop();
#endif /* ENABLE_NETWORK */ #endif /* ENABLE_NETWORK */