news_gui.c
changeset 5258 28d07c40ea82
parent 5254 bce68eeaab3b
child 5264 1e3cd1ed1ee6
equal deleted inserted replaced
5257:17f2fad1ef75 5258:28d07c40ea82
   228 
   228 
   229 /** Return the correct index in the pseudo-fifo
   229 /** Return the correct index in the pseudo-fifo
   230  * queue and deals with overflows when increasing the index */
   230  * queue and deals with overflows when increasing the index */
   231 static inline NewsID increaseIndex(NewsID i)
   231 static inline NewsID increaseIndex(NewsID i)
   232 {
   232 {
   233 	if (i == INVALID_NEWS) return 0;
   233 	assert(i != INVALID_NEWS);
   234 	return (i + 1) % MAX_NEWS;
   234 	return (i + 1) % MAX_NEWS;
   235 }
   235 }
   236 
   236 
   237 /** Return the correct index in the pseudo-fifo
   237 /** Return the correct index in the pseudo-fifo
   238  * queue and deals with overflows when decreasing the index */
   238  * queue and deals with overflows when decreasing the index */
   273 		MoveToNextItem();
   273 		MoveToNextItem();
   274 
   274 
   275 	_forced_news = INVALID_NEWS;
   275 	_forced_news = INVALID_NEWS;
   276 	if (_total_news < MAX_NEWS) _total_news++;
   276 	if (_total_news < MAX_NEWS) _total_news++;
   277 
   277 
   278 	// make sure our pointer isn't overflowing
   278 	/* Increase _latest_news. If we have no news yet, use _oldest news as an
       
   279 	 * index. We cannot use 0 as _oldest_news can jump around due to
       
   280 	 * DeleteVehicleNews */
   279 	l_news = _latest_news;
   281 	l_news = _latest_news;
   280 	_latest_news = increaseIndex(_latest_news);
   282 	_latest_news = (_latest_news == INVALID_NEWS) ? _oldest_news : increaseIndex(_latest_news);
   281 
   283 
   282 	/* If the fifo-buffer is full, overwrite the oldest entry */
   284 	/* If the fifo-buffer is full, overwrite the oldest entry */
   283 	if (l_news != INVALID_NEWS && _latest_news == _oldest_news) {
   285 	if (l_news != INVALID_NEWS && _latest_news == _oldest_news) {
   284 		assert(_total_news == MAX_NEWS);
   286 		assert(_total_news == MAX_NEWS);
   285 		_oldest_news = increaseIndex(_oldest_news);
   287 		_oldest_news = increaseIndex(_oldest_news);
   487 
   489 
   488 	// if we're not at the last item, then move on
   490 	// if we're not at the last item, then move on
   489 	if (_current_news != _latest_news) {
   491 	if (_current_news != _latest_news) {
   490 		NewsItem *ni;
   492 		NewsItem *ni;
   491 
   493 
   492 		_current_news = increaseIndex(_current_news);
   494 		_current_news = (_current_news == INVALID_NEWS) ? _oldest_news : increaseIndex(_current_news);
   493 		ni = &_news_items[_current_news];
   495 		ni = &_news_items[_current_news];
   494 
   496 
   495 		// check the date, don't show too old items
   497 		// check the date, don't show too old items
   496 		if (_date - _news_items_age[ni->type] > ni->date) return;
   498 		if (_date - _news_items_age[ni->type] > ni->date) return;
   497 
   499