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.
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, 18 July 2014 - 02:08 AM.