Opened 9 years ago

Closed 9 years ago

Last modified 9 years ago

#3222 closed defect (fixed)

[PATCH] handleNotifications() handles only one notification

Reported by: elexis Owned by: leper
Priority: Must Have Milestone: Alpha 19
Component: UI & Simulation Keywords: patch
Cc: Patch:

Description

The function handleNotifications() in messages.js is called only on onSimulationUpdate(). It is supposed to process notifications that are displayed in the chat area, for example ("player has sent you amount" or "player is now at war with you"). It does process them properly, but only one per call, while the name suggests that all remaining messages should be displayed. Since handleNotifications() is also called only once per onSimulationUpdate(), the effect is that only one message will be displayed per turn.

The different message types are defined in g_NotificationsTypes in the same file. Almost all of them call the addChatMessage function.

The solution is simple, just loop while there are more messages ready to go. Patch attached. At most 20 messages per turn now processed.

This bug is the reason why spammed diplomacy-changed-messages are being displayed slowly (#3198) and why tributing many times 100 resources is also displayed slowly.

With this patch, the actual player chat will be overwritten instantaneously, if someone spams the tribute or diplomacy buttons. Thats why #3198 should be implemented in order to mitigate this side effect.

Attachments (4)

t3222_handle_notifications.patch (1.7 KB ) - added by elexis 9 years ago.
t3222_handle_notifications_v2.patch (2.3 KB ) - added by elexis 9 years ago.
Simplifies the patch above. Also changes pop() to shift() so that the messages are displayed in the correct order. Test with 2 instances of 0ad and sending resources with the other player while the game is paused.
t3222_handle_notifications_v3.patch (2.9 KB ) - added by elexis 9 years ago.
Simplified even more.
t3222_handle_notifications_v4.patch (2.9 KB ) - added by elexis 9 years ago.
Same patch as above, but changed 'for(var i = 0; i < notifications.length; ++i)' to 'for(var notification of notifications)'.

Download all attachments as: .zip

Change History (6)

by elexis, 9 years ago

by elexis, 9 years ago

Simplifies the patch above. Also changes pop() to shift() so that the messages are displayed in the correct order. Test with 2 instances of 0ad and sending resources with the other player while the game is paused.

by elexis, 9 years ago

Simplified even more.

by elexis, 9 years ago

Same patch as above, but changed 'for(var i = 0; i < notifications.length; ++i)' to 'for(var notification of notifications)'.

comment:1 by leper, 9 years ago

Owner: set to leper
Resolution: fixed
Status: newclosed

In 16662:

Actually handle multiple notifications instead of one per turn. Patch by elexis. Fixes #3222.

comment:2 by leper, 9 years ago

Keywords: review removed

You missed a space between for and (. Thanks for the patch.

Note: See TracTickets for help on using tickets.