# In game periodic notice question

This topic is 1317 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi, guys

I m currently designing a in game notice system, which basically broadcasts in game notices to all player periodically.

I have already implemented one and it works but something tells me it's not good enough, so I am seeking some advice to

make it better. Any suggestion would be appreciated

Here is my design

struct Notice
{
int        NoticeId;
char*      pNoticeContent;
time_t     NoticeBeginTime;
time_t     NoticeEndTime;
time_t     NoticeGap;           // every NoticeGap , broadcast Notice Once
}

Timer

Timer
struct Timer
{
time_t     currentTick;
time_t     Interval;
}

My initial design is assign every Notice a Timer, and update all these Timer.currentTick in the game loop, so when Timer.currentTick is larger than the Timer.Interval(the NoticeGap), it means this notice can be send now.

My question is , when the number of notices increases, There would be more and more Timers to tick, and I do not like this.

How can I use only one Timer to do the same thing?

##### Share on other sites
I've worked on games that relied on them. Ultimately we learned that players hate them. From telemetry we learned that most players don't use them for their intended purposes.

Of course, you might be making a game where players like to interrupt their gameplay by reading the rough equivalents of popup spam windows. Perhaps your game's demographics enjoy reading and re-reading the same text blurb thousands of times. In that case, all you need is a begin and end time index, and the update loop can cycle through them every frame without any performance problems. If the end time index is reached drop the notice, if the begin time index is reached display it if necessary. Iterating over a list of usually zero items but sometimes one or two items is not a performance concern.

##### Share on other sites

I followed you up to "Here is my design". But then, instead of describing your design, you take creating "the rough equivalents of popup spam windows" for granted and give low-level details of how you do it.

Actual design discussion should cover at least:

• What situations justify disturbing the player with notices (the only ones I've ever seen in games are of a sporadic and blocking nature: network errors, crashing levels, etc.),
• Pop-up user interfaces vs leaving the notices on permanent display.
• How to avoid accidentally missing important notices (for instance, a pop-up could be closed without reading it).
• The time scale of repeated notices: for example, a leaderboard report every week or the status of the current game every 20 seconds.
• Why did you design all notices to be periodically repeated (which seems a very narrow special case of repeating a notice whenever an event reoccurs).
• For each notice type, the best time to display it (In many cases, spouting notices whenever the game is started and before actually playing is less annoying and technically simpler than interrupting the game)
• For each notice type, how can players react to notices in order to dismiss them and/or avoid their reappearance (if you don't have a good answer, the notice is annoying).

After designing these and other aspects of notices, you'll be ready to think of data structures and algorithms that can do everything you need.

Meanwhile:

My question is , when the number of notices increases, There would be more and more Timers to tick, and I do not like this.

How can I use only one Timer to do the same thing?

Avoiding explicit timers completely, you can use a priority queue of future events (at time T, display notice N), sorted by scheduled time and for the same time by the order in which events are added.

Given a reference time for each tick of your game loop, repeatedly execute and remove the earliest entry of the event queue until all remaining events in the queue are scheduled in the future. If a notice is periodic, the function that displays it can compute when it should be scheduled again and add the next repeat of that notice to the queue.

This sort of event queue, which is typically used for much more general purposes with much more polymorphic command objects, is a suitable way to process things that will happen later in a uniform way: any system can schedule events, and putting all events in the same place allows managing them smartly (e.g. automatically delaying low priority notices if too many are already on display).

Edited by LorenzoGatti

##### Share on other sites

And please don't repeat them all the time!

Nothing worse than a game that nags, I have a wife for that.