Changeset - r23124:8fa6d269005b
[Not reviewed]
master
0 21 0
Peter Nelson - 6 years ago 2018-05-04 20:29:22
peter1138@openttd.org
Change: Split up Window::OnTick into OnGameTick and OnRealtimeTick. Adjust timers to work with milliseconds instead of ticks.
21 files changed with 144 insertions and 64 deletions:
0 comments (0 inline, 0 general)
src/airport_gui.cpp
Show inline comments
 
@@ -540,13 +540,13 @@ public:
 
		assert(widget == WID_AP_CLASS_DROPDOWN);
 
		_selected_airport_class = (AirportClassID)index;
 
		this->vscroll->SetCount(AirportClass::Get(_selected_airport_class)->GetSpecCount());
 
		this->SelectFirstAvailableAirport(false);
 
	}
 

	
 
	virtual void OnTick()
 
	virtual void OnRealtimeTick(uint delta_ms)
 
	{
 
		CheckRedrawStationCoverage(this);
 
	}
 
};
 

	
 
static const NWidgetPart _nested_build_airport_widgets[] = {
src/dock_gui.cpp
Show inline comments
 
@@ -448,13 +448,13 @@ public:
 
				if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP);
 
				this->SetDirty();
 
				break;
 
		}
 
	}
 

	
 
	virtual void OnTick()
 
	virtual void OnRealtimeTick(uint delta_ms)
 
	{
 
		CheckRedrawStationCoverage(this);
 
	}
 
};
 

	
 
/** Nested widget parts of a build dock station window. */
src/graph_gui.cpp
Show inline comments
 
@@ -536,13 +536,13 @@ public:
 
	virtual void OnClick(Point pt, int widget, int click_count)
 
	{
 
		/* Clicked on legend? */
 
		if (widget == WID_CV_KEY_BUTTON) ShowGraphLegend();
 
	}
 

	
 
	virtual void OnTick()
 
	virtual void OnGameTick()
 
	{
 
		this->UpdateStatistics(false);
 
	}
 

	
 
	/**
 
	 * Some data on this window has become invalid.
 
@@ -995,15 +995,15 @@ struct PaymentRatesGraphWindow : BaseGra
 
					this->SetDirty();
 
				}
 
				break;
 
		}
 
	}
 

	
 
	virtual void OnTick()
 
	virtual void OnGameTick()
 
	{
 
		/* Override default OnTick */
 
		/* Override default OnGameTick */
 
	}
 

	
 
	/**
 
	 * Some data on this window has become invalid.
 
	 * @param data Information about the changed data.
 
	 * @param gui_scope Whether the call is done from GUI scope. You may not do everything when not in GUI scope. See #InvalidateWindowData() for details.
 
@@ -1236,13 +1236,13 @@ public:
 

	
 
		size->width = WD_FRAMERECT_LEFT + this->ordinal_width + WD_FRAMERECT_RIGHT + this->icon_width + WD_FRAMERECT_LEFT + this->text_width + WD_FRAMERECT_RIGHT;
 
		size->height = WD_FRAMERECT_TOP + this->line_height * MAX_COMPANIES + WD_FRAMERECT_BOTTOM;
 
	}
 

	
 

	
 
	virtual void OnTick()
 
	virtual void OnGameTick()
 
	{
 
		if (this->companies.NeedResort()) {
 
			this->SetDirty();
 
		}
 
	}
 

	
 
@@ -1469,13 +1469,13 @@ struct PerformanceRatingDetailWindow : W
 
				this->LowerWidget(this->company + WID_PRD_COMPANY_FIRST);
 
				this->SetDirty();
 
			}
 
		}
 
	}
 

	
 
	virtual void OnTick()
 
	virtual void OnGameTick()
 
	{
 
		if (_pause_mode != PM_UNPAUSED) return;
 

	
 
		/* Update the company score every 5 days */
 
		if (--this->timeout == 0) {
 
			this->UpdateCompanyStats();
src/group_gui.cpp
Show inline comments
 
@@ -855,13 +855,13 @@ public:
 
			default: NOT_REACHED();
 
		}
 

	
 
		this->SetDirty();
 
	}
 

	
 
	virtual void OnTick()
 
	virtual void OnGameTick()
 
	{
 
		if (_pause_mode != PM_UNPAUSED) return;
 
		if (this->groups.NeedResort() || this->vehicles.NeedResort()) {
 
			this->SetDirty();
 
		}
 
	}
src/industry_gui.cpp
Show inline comments
 
@@ -644,13 +644,13 @@ public:
 
		}
 

	
 
		/* If an industry has been built, just reset the cursor and the system */
 
		if (success && !_settings_client.gui.persistent_buildingtools) ResetObjectToPlace();
 
	}
 

	
 
	virtual void OnTick()
 
	virtual void OnGameTick()
 
	{
 
		if (_pause_mode != PM_UNPAUSED) return;
 
		if (!this->timer_enabled) return;
 
		if (--this->callback_timer == 0) {
 
			/* We have just passed another day.
 
			 * See if we need to update availability of currently selected industry */
src/main_gui.cpp
Show inline comments
 
@@ -232,16 +232,17 @@ enum {
 
	GHK_CHAT_COMPANY,
 
	GHK_CHAT_SERVER,
 
};
 

	
 
struct MainWindow : Window
 
{
 
	uint refresh;
 
	int refresh;
 

	
 
	static const uint LINKGRAPH_REFRESH_PERIOD = 0xff;
 
	static const uint LINKGRAPH_DELAY = 0xf;
 
	/* Refresh times in milliseconds */
 
	static const uint LINKGRAPH_REFRESH_PERIOD = 7650;
 
	static const uint LINKGRAPH_DELAY = 450;
 

	
 
	MainWindow(WindowDesc *desc) : Window(desc)
 
	{
 
		this->InitNested(0);
 
		CLRBITS(this->flags, WF_WHITE_BORDER);
 
		ResizeWindow(this, _screen.width, _screen.height);
 
@@ -250,15 +251,15 @@ struct MainWindow : Window
 
		nvp->InitializeViewport(this, TileXY(32, 32), ZOOM_LVL_VIEWPORT);
 

	
 
		this->viewport->overlay = new LinkGraphOverlay(this, WID_M_VIEWPORT, 0, 0, 3);
 
		this->refresh = LINKGRAPH_DELAY;
 
	}
 

	
 
	virtual void OnTick()
 
	virtual void OnRealtimeTick(uint delta_ms)
 
	{
 
		if (--this->refresh > 0) return;
 
		if (!TimerElapsed(this->refresh, delta_ms)) return;
 

	
 
		this->refresh = LINKGRAPH_REFRESH_PERIOD;
 

	
 
		if (this->viewport->overlay->GetCargoMask() == 0 ||
 
				this->viewport->overlay->GetCompanyMask() == 0) {
 
			return;
src/misc_gui.cpp
Show inline comments
 
@@ -451,21 +451,22 @@ static const char * const _credits[] = {
 
	"And last but not least:",
 
	"  Chris Sawyer - For an amazing game!"
 
};
 

	
 
struct AboutWindow : public Window {
 
	int text_position;                       ///< The top of the scrolling text
 
	byte counter;                            ///< Used to scroll the text every 5 ticks
 
	int line_height;                         ///< The height of a single line
 
	static const int num_visible_lines = 19; ///< The number of lines visible simultaneously
 

	
 
	static const uint TIMER_INTERVAL = 150;  ///< Scrolling interval in ms
 
	uint timer;
 

	
 
	AboutWindow() : Window(&_about_desc)
 
	{
 
		this->InitNested(WN_GAME_OPTIONS_ABOUT);
 

	
 
		this->counter = 5;
 
		this->text_position = this->GetWidget<NWidgetBase>(WID_A_SCROLLING_TEXT)->pos_y + this->GetWidget<NWidgetBase>(WID_A_SCROLLING_TEXT)->current_y;
 
	}
 

	
 
	virtual void SetStringParameters(int widget) const
 
	{
 
		if (widget == WID_A_WEBSITE) SetDParamStr(0, "Website: http://www.openttd.org");
 
@@ -499,17 +500,17 @@ struct AboutWindow : public Window {
 
				DrawString(r.left, r.right, y, _credits[i], TC_BLACK, SA_LEFT | SA_FORCE);
 
			}
 
			y += this->line_height;
 
		}
 
	}
 

	
 
	virtual void OnTick()
 
	virtual void OnRealtimeTick(uint delta_ms)
 
	{
 
		if (--this->counter == 0) {
 
			this->counter = 5;
 
			this->text_position--;
 
		uint count = CountIntervalElapsed(this->timer, delta_ms, TIMER_INTERVAL);
 
		if (count > 0) {
 
			this->text_position -= count;
 
			/* If the last text has scrolled start a new from the start */
 
			if (this->text_position < (int)(this->GetWidget<NWidgetBase>(WID_A_SCROLLING_TEXT)->pos_y - lengthof(_credits) * this->line_height)) {
 
				this->text_position = this->GetWidget<NWidgetBase>(WID_A_SCROLLING_TEXT)->pos_y + this->GetWidget<NWidgetBase>(WID_A_SCROLLING_TEXT)->current_y;
 
			}
 
			this->SetDirty();
 
		}
src/newgrf_gui.cpp
Show inline comments
 
@@ -400,13 +400,13 @@ struct NewGRFParametersWindow : public W
 
						}
 
					}
 
					if (val != old_val) {
 
						par_info->SetValue(this->grf_config, val);
 

	
 
						this->clicked_button = num;
 
						this->timeout = 5;
 
						this->timeout = 150;
 
					}
 
				} else if (par_info->type == PTYPE_UINT_ENUM && !par_info->complete_labels && click_count >= 2) {
 
					/* Display a query box so users can enter a custom value. */
 
					SetDParam(0, old_val);
 
					ShowQueryString(STR_JUST_INT, STR_CONFIG_SETTING_QUERY_CAPTION, 10, this, CS_NUMERAL, QSF_NONE);
 
				}
 
@@ -480,15 +480,15 @@ struct NewGRFParametersWindow : public W
 
		if (this->clicked_row != UINT_MAX && this->clicked_row >= this->vscroll->GetCount()) {
 
			this->clicked_row = UINT_MAX;
 
			DeleteChildWindows(WC_QUERY_STRING);
 
		}
 
	}
 

	
 
	virtual void OnTick()
 
	virtual void OnRealtimeTick(uint delta_ms)
 
	{
 
		if (--this->timeout == 0) {
 
		if (TimerElapsed(this->timeout, delta_ms)) {
 
			this->clicked_button = UINT_MAX;
 
			this->SetDirty();
 
		}
 
	}
 
};
 
GRFParameterInfo NewGRFParametersWindow::dummy_parameter_info(0);
src/news_gui.cpp
Show inline comments
 
@@ -257,17 +257,19 @@ NewsDisplay NewsTypeData::GetDisplay() c
 

	
 
/** Window class displaying a news item. */
 
struct NewsWindow : Window {
 
	uint16 chat_height;   ///< Height of the chat window.
 
	uint16 status_height; ///< Height of the status bar window
 
	const NewsItem *ni;   ///< News item to display.
 
	static uint duration; ///< Remaining time for showing current news message (may only be accessed while a news item is displayed).
 
	static int duration;  ///< Remaining time for showing the current news message (may only be access while a news item is displayed).
 

	
 
	uint timer;
 

	
 
	NewsWindow(WindowDesc *desc, const NewsItem *ni) : Window(desc), ni(ni)
 
	{
 
		NewsWindow::duration = 555;
 
		NewsWindow::duration = 16650;
 
		const Window *w = FindWindowByClass(WC_SEND_NETWORK_MSG);
 
		this->chat_height = (w != NULL) ? w->height : 0;
 
		this->status_height = FindWindowById(WC_STATUS_BAR, 0)->height;
 

	
 
		this->flags |= WF_DISABLE_VP_SCROLL;
 

	
 
@@ -482,17 +484,24 @@ struct NewsWindow : Window {
 
		/* The chatbar has notified us that is was either created or closed */
 
		int newtop = this->top + this->chat_height - data;
 
		this->chat_height = data;
 
		this->SetWindowTop(newtop);
 
	}
 

	
 
	virtual void OnTick()
 
	virtual void OnRealtimeTick(uint delta_ms)
 
	{
 
		/* Scroll up newsmessages from the bottom in steps of 4 pixels */
 
		int newtop = max(this->top - 4, _screen.height - this->height - this->status_height - this->chat_height);
 
		this->SetWindowTop(newtop);
 
		int count = CountIntervalElapsed(this->timer, delta_ms, 15);
 
		if (count > 0) {
 
			/* Scroll up newsmessages from the bottom */
 
			int newtop = max(this->top - 2 * count, _screen.height - this->height - this->status_height - this->chat_height);
 
			this->SetWindowTop(newtop);
 
		}
 

	
 
		/* Decrement the news timer. We don't need to action an elapsed event here,
 
		 * so no need to use TimerElapsed(). */
 
		if (NewsWindow::duration > 0) NewsWindow::duration -= delta_ms;
 
	}
 

	
 
private:
 
	/**
 
	 * Moves the window to a new #top coordinate. Makes screen dirty where needed.
 
	 * @param newtop new top coordinate
 
@@ -533,13 +542,13 @@ private:
 
			default:
 
				NOT_REACHED();
 
		}
 
	}
 
};
 

	
 
/* static */ uint NewsWindow::duration = 0; // Instance creation.
 
/* static */ int NewsWindow::duration = 0; // Instance creation.
 

	
 

	
 
/** Open up an own newspaper window for the news item */
 
static void ShowNewspaper(const NewsItem *ni)
 
{
 
	SoundFx sound = _news_type_data[ni->type].sound;
 
@@ -585,17 +594,14 @@ static bool ReadyForNextItem()
 
	if (ni == NULL) return true;
 

	
 
	/* Ticker message
 
	 * Check if the status bar message is still being displayed? */
 
	if (IsNewsTickerShown()) return false;
 

	
 
	/* Newspaper message, decrement duration counter */
 
	if (NewsWindow::duration != 0) NewsWindow::duration--;
 

	
 
	/* neither newsticker nor newspaper are running */
 
	return (NewsWindow::duration == 0 || FindWindowById(WC_NEWS_WINDOW, 0) == NULL);
 
	return (NewsWindow::duration <= 0 || FindWindowById(WC_NEWS_WINDOW, 0) == NULL);
 
}
 

	
 
/** Move to the next news item */
 
static void MoveToNextItem()
 
{
 
	InvalidateWindowData(WC_STATUS_BAR, 0, SBI_NEWS_DELETED); // invalidate the statusbar
src/openttd.cpp
Show inline comments
 
@@ -73,13 +73,13 @@
 

	
 
void CallLandscapeTick();
 
void IncreaseDate();
 
void DoPaletteAnimations();
 
void MusicLoop();
 
void ResetMusic();
 
void CallWindowTickEvent();
 
void CallWindowGameTickEvent();
 
bool HandleBootstrap();
 

	
 
extern Company *DoStartupNewCompany(bool is_ai, CompanyID company = INVALID_COMPANY);
 
extern void ShowOSErrorBox(const char *buf, bool system);
 
extern char *_config_file;
 

	
 
@@ -1360,13 +1360,12 @@ void StateGameLoop()
 
		PerformanceMeasurer::Paused(PFE_GL_LANDSCAPE);
 

	
 
		UpdateLandscapingLimits();
 
#ifndef DEBUG_DUMP_COMMANDS
 
		Game::GameLoop();
 
#endif
 
		CallWindowTickEvent();
 
		return;
 
	}
 

	
 
	PerformanceMeasurer framerate(PFE_GAMELOOP);
 
	PerformanceAccumulator::Reset(PFE_GL_LANDSCAPE);
 
	if (HasModalProgress()) return;
 
@@ -1378,13 +1377,13 @@ void StateGameLoop()
 
		RunTileLoop();
 
		CallVehicleTicks();
 
		CallLandscapeTick();
 
		BasePersistentStorageArray::SwitchMode(PSM_LEAVE_GAMELOOP);
 
		UpdateLandscapingLimits();
 

	
 
		CallWindowTickEvent();
 
		CallWindowGameTickEvent();
 
		NewsLoop();
 
	} else {
 
		if (_debug_desync_level > 2 && _date_fract == 0 && (_date & 0x1F) == 0) {
 
			/* Save the desync savegame if needed. */
 
			char name[MAX_PATH];
 
			seprintf(name, lastof(name), "dmp_cmds_%08x_%08x.sav", _settings_game.game_creation.generation_seed, _date);
 
@@ -1408,13 +1407,13 @@ void StateGameLoop()
 
#ifndef DEBUG_DUMP_COMMANDS
 
		AI::GameLoop();
 
		Game::GameLoop();
 
#endif
 
		UpdateLandscapingLimits();
 

	
 
		CallWindowTickEvent();
 
		CallWindowGameTickEvent();
 
		NewsLoop();
 
		cur_company.Restore();
 
	}
 

	
 
	assert(IsLocalCompany());
 
}
src/rail_gui.cpp
Show inline comments
 
@@ -1365,13 +1365,13 @@ public:
 
				DeleteWindowById(WC_SELECT_STATION, 0);
 
				break;
 
			}
 
		}
 
	}
 

	
 
	virtual void OnTick()
 
	virtual void OnRealtimeTick(uint delta_ms)
 
	{
 
		CheckRedrawStationCoverage(this);
 
	}
 
};
 

	
 
static const NWidgetPart _nested_station_builder_widgets[] = {
src/road_gui.cpp
Show inline comments
 
@@ -1050,13 +1050,13 @@ struct BuildRoadStationWindow : public P
 

	
 
			default:
 
				break;
 
		}
 
	}
 

	
 
	virtual void OnTick()
 
	virtual void OnRealtimeTick(uint delta_ms)
 
	{
 
		CheckRedrawStationCoverage(this);
 
	}
 
};
 

	
 
/** Widget definition of the build road station window */
src/smallmap_gui.cpp
Show inline comments
 
@@ -1567,16 +1567,16 @@ int SmallMapWindow::GetPositionOnLegend(
 
			Point pt = {cursor_x, cursor_y};
 
			this->SetZoomLevel((wheel < 0) ? ZLC_ZOOM_IN : ZLC_ZOOM_OUT, &pt);
 
		}
 
	}
 
}
 

	
 
/* virtual */ void SmallMapWindow::OnTick()
 
/* virtual */ void SmallMapWindow::OnRealtimeTick(uint delta_ms)
 
{
 
	/* Update the window every now and then */
 
	if (--this->refresh != 0) return;
 
	if (!TimerElapsed(this->refresh, delta_ms)) return;
 

	
 
	if (this->map_type == SMT_LINKSTATS) {
 
		uint32 company_mask = this->GetOverlayCompanyMask();
 
		if (this->overlay->GetCompanyMask() != company_mask) {
 
			this->overlay->SetCompanyMask(company_mask);
 
		} else {
src/smallmap_gui.h
Show inline comments
 
@@ -64,25 +64,25 @@ protected:
 
	static SmallMapType map_type; ///< Currently displayed legends.
 
	static bool show_towns;       ///< Display town names in the smallmap.
 
	static int max_heightlevel;   ///< Currently used/cached maximum heightlevel.
 

	
 
	static const uint LEGEND_BLOB_WIDTH = 8;              ///< Width of the coloured blob in front of a line text in the #WID_SM_LEGEND widget.
 
	static const uint INDUSTRY_MIN_NUMBER_OF_COLUMNS = 2; ///< Minimal number of columns in the #WID_SM_LEGEND widget for the #SMT_INDUSTRY legend.
 
	static const uint FORCE_REFRESH_PERIOD = 0x1F; ///< map is redrawn after that many ticks
 
	static const uint BLINK_PERIOD         = 0x0F; ///< highlight blinking interval
 
	static const uint FORCE_REFRESH_PERIOD = 930; ///< map is redrawn after that many milliseconds.
 
	static const uint BLINK_PERIOD         = 450; ///< highlight blinking interval in milliseconds.
 

	
 
	uint min_number_of_columns;    ///< Minimal number of columns in legends.
 
	uint min_number_of_fixed_rows; ///< Minimal number of rows in the legends for the fixed layouts only (all except #SMT_INDUSTRY).
 
	uint column_width;             ///< Width of a column in the #WID_SM_LEGEND widget.
 

	
 
	int32 scroll_x;  ///< Horizontal world coordinate of the base tile left of the top-left corner of the smallmap display.
 
	int32 scroll_y;  ///< Vertical world coordinate of the base tile left of the top-left corner of the smallmap display.
 
	int32 subscroll; ///< Number of pixels (0..3) between the right end of the base tile and the pixel at the top-left corner of the smallmap display.
 
	int zoom;        ///< Zoom level. Bigger number means more zoom-out (further away).
 

	
 
	uint8 refresh;   ///< Refresh counter, zeroed every FORCE_REFRESH_PERIOD ticks.
 
	int refresh;     ///< Refresh timer, in millseconds.
 
	LinkGraphOverlay *overlay;
 

	
 
	static void BreakIndustryChainLink();
 
	Point SmallmapRemapCoords(int x, int y) const;
 

	
 
	/**
 
@@ -184,12 +184,12 @@ public:
 
	virtual void OnPaint();
 
	virtual void DrawWidget(const Rect &r, int widget) const;
 
	virtual void OnClick(Point pt, int widget, int click_count);
 
	virtual void OnInvalidateData(int data = 0, bool gui_scope = true);
 
	virtual bool OnRightClick(Point pt, int widget);
 
	virtual void OnMouseWheel(int wheel);
 
	virtual void OnTick();
 
	virtual void OnRealtimeTick(uint delta_ms);
 
	virtual void OnScroll(Point delta);
 
	virtual void OnMouseOver(Point pt, int widget);
 
};
 

	
 
#endif /* SMALLMAP_GUI_H */
src/station_gui.cpp
Show inline comments
 
@@ -618,13 +618,13 @@ public:
 
			this->GetWidget<NWidgetCore>(WID_STL_SORTDROPBTN)->widget_data = this->sorter_names[this->stations.SortType()];
 

	
 
			this->SetDirty();
 
		}
 
	}
 

	
 
	virtual void OnTick()
 
	virtual void OnGameTick()
 
	{
 
		if (_pause_mode != PM_UNPAUSED) return;
 
		if (this->stations.NeedResort()) {
 
			DEBUG(misc, 3, "Periodic rebuild station list company %d", this->window_number);
 
			this->SetDirty();
 
		}
 
@@ -2309,13 +2309,13 @@ struct SelectStationWindow : Window {
 
		DoCommandP(&this->select_station_cmd);
 

	
 
		/* Close Window; this might cause double frees! */
 
		DeleteWindowById(WC_SELECT_STATION, 0);
 
	}
 

	
 
	virtual void OnTick()
 
	virtual void OnRealtimeTick(uint delta_ms)
 
	{
 
		if (_thd.dirty & 2) {
 
			_thd.dirty &= ~2;
 
			this->SetDirty();
 
		}
 
	}
src/statusbar_gui.cpp
Show inline comments
 
@@ -76,16 +76,17 @@ static bool DrawScrollingStatusText(cons
 
	return (_current_text_dir == TD_RTL) ? (pos < right - left) : (pos + width > 0);
 
}
 

	
 
struct StatusBarWindow : Window {
 
	bool saving;
 
	int ticker_scroll;
 
	uint ticker_timer;
 
	int reminder_timeout;
 

	
 
	static const int TICKER_STOP    = 1640; ///< scrolling is finished when counter reaches this value
 
	static const int REMINDER_START =   91; ///< initial value of the reminder counter (right dot on the right)
 
	static const int REMINDER_START = 1350; ///< time in ms for reminder notification (red dot on the right) to stay
 
	static const int REMINDER_STOP  =    0; ///< reminder disappears when counter reaches this value
 
	static const int COUNTER_STEP   =    2; ///< this is subtracted from active counters every tick
 

	
 
	StatusBarWindow(WindowDesc *desc) : Window(desc)
 
	{
 
		this->ticker_scroll    =   TICKER_STOP;
 
@@ -200,12 +201,13 @@ struct StatusBarWindow : Window {
 
			case SBI_SAVELOAD_START:  this->saving = true;  break;
 
			case SBI_SAVELOAD_FINISH: this->saving = false; break;
 
			case SBI_SHOW_TICKER:     this->ticker_scroll = 0; break;
 
			case SBI_SHOW_REMINDER:   this->reminder_timeout = REMINDER_START; break;
 
			case SBI_NEWS_DELETED:
 
				this->ticker_scroll    =   TICKER_STOP; // reset ticker ...
 
				this->ticker_timer     = 0;
 
				this->reminder_timeout = REMINDER_STOP; // ... and reminder
 
				break;
 
		}
 
	}
 

	
 
	virtual void OnClick(Point pt, int widget, int click_count)
 
@@ -214,25 +216,26 @@ struct StatusBarWindow : Window {
 
			case WID_S_MIDDLE: ShowLastNewsMessage(); break;
 
			case WID_S_RIGHT:  if (_local_company != COMPANY_SPECTATOR) ShowCompanyFinances(_local_company); break;
 
			default: ResetObjectToPlace();
 
		}
 
	}
 

	
 
	virtual void OnTick()
 
	virtual void OnRealtimeTick(uint delta_ms)
 
	{
 
		if (_pause_mode != PM_UNPAUSED) return;
 

	
 
		if (this->ticker_scroll < TICKER_STOP) { // Scrolling text
 
			this->ticker_scroll += COUNTER_STEP;
 
			this->SetWidgetDirty(WID_S_MIDDLE);
 
			uint count = CountIntervalElapsed(this->ticker_timer, delta_ms, 15);
 
			if (count > 0) {
 
				this->ticker_scroll += count;
 
				this->SetWidgetDirty(WID_S_MIDDLE);
 
			}
 
		}
 

	
 
		if (this->reminder_timeout > REMINDER_STOP) { // Red blot to show there are new unread newsmessages
 
			this->reminder_timeout -= COUNTER_STEP;
 
		} else if (this->reminder_timeout < REMINDER_STOP) {
 
			this->reminder_timeout = REMINDER_STOP;
 
		// Red blot to show there are new unread newsmessages
 
		if (TimerElapsed(this->reminder_timeout, delta_ms)) {
 
			this->SetWidgetDirty(WID_S_MIDDLE);
 
		}
 
	}
 
};
 

	
 
static const NWidgetPart _nested_main_status_widgets[] = {
src/toolbar_gui.cpp
Show inline comments
 
@@ -1975,22 +1975,26 @@ enum MainToolbarHotkeys {
 
	MTHK_CLIENT_LIST,
 
	MTHK_SIGN_LIST,
 
};
 

	
 
/** Main toolbar. */
 
struct MainToolbarWindow : Window {
 
	int timer;
 

	
 
	MainToolbarWindow(WindowDesc *desc) : Window(desc)
 
	{
 
		this->InitNested(0);
 

	
 
		_last_started_action = CBF_NONE;
 
		CLRBITS(this->flags, WF_WHITE_BORDER);
 
		this->SetWidgetDisabledState(WID_TN_PAUSE, _networking && !_network_server); // if not server, disable pause button
 
		this->SetWidgetDisabledState(WID_TN_FAST_FORWARD, _networking); // if networking, disable fast-forward button
 
		PositionMainToolbar(this);
 
		DoZoomInOutWindow(ZOOM_NONE, this);
 

	
 
		this->timer = MILLISECONDS_PER_TICK;
 
	}
 

	
 
	virtual void FindWindowPlacementAndResize(int def_width, int def_height)
 
	{
 
		Window::FindWindowPlacementAndResize(_toolbar_width, def_height);
 
	}
 
@@ -2089,14 +2093,17 @@ struct MainToolbarWindow : Window {
 

	
 
	virtual void OnPlaceObjectAbort()
 
	{
 
		_last_started_action = CBF_NONE;
 
	}
 

	
 
	virtual void OnTick()
 
	virtual void OnRealtimeTick(uint delta_ms)
 
	{
 
		if (!TimerElapsed(this->timer, delta_ms)) return;
 
		this->timer = MILLISECONDS_PER_TICK;
 

	
 
		if (this->IsWidgetLowered(WID_TN_PAUSE) != !!_pause_mode) {
 
			this->ToggleWidgetLoweredState(WID_TN_PAUSE);
 
			this->SetWidgetDirty(WID_TN_PAUSE);
 
		}
 

	
 
		if (this->IsWidgetLowered(WID_TN_FAST_FORWARD) != !!_fast_forward) {
 
@@ -2307,20 +2314,24 @@ enum MainToolbarEditorHotkeys {
 
	MTEHK_TERRAFORM,
 
	MTEHK_SMALLMAP,
 
	MTEHK_EXTRA_VIEWPORT,
 
};
 

	
 
struct ScenarioEditorToolbarWindow : Window {
 
	int timer;
 

	
 
	ScenarioEditorToolbarWindow(WindowDesc *desc) : Window(desc)
 
	{
 
		this->InitNested(0);
 

	
 
		_last_started_action = CBF_NONE;
 
		CLRBITS(this->flags, WF_WHITE_BORDER);
 
		PositionMainToolbar(this);
 
		DoZoomInOutWindow(ZOOM_NONE, this);
 

	
 
		this->timer = MILLISECONDS_PER_TICK;
 
	}
 

	
 
	virtual void FindWindowPlacementAndResize(int def_width, int def_height)
 
	{
 
		Window::FindWindowPlacementAndResize(_toolbar_width, def_height);
 
	}
 
@@ -2442,14 +2453,17 @@ struct ScenarioEditorToolbarWindow : Win
 
	{
 
		this->SetWidgetsLoweredState(false, WID_TE_DATE_BACKWARD, WID_TE_DATE_FORWARD, WIDGET_LIST_END);
 
		this->SetWidgetDirty(WID_TE_DATE_BACKWARD);
 
		this->SetWidgetDirty(WID_TE_DATE_FORWARD);
 
	}
 

	
 
	virtual void OnTick()
 
	virtual void OnRealtimeTick(uint delta_ms)
 
	{
 
		if (!TimerElapsed(this->timer, delta_ms)) return;
 
		this->timer = MILLISECONDS_PER_TICK;
 

	
 
		if (this->IsWidgetLowered(WID_TE_PAUSE) != !!_pause_mode) {
 
			this->ToggleWidgetLoweredState(WID_TE_PAUSE);
 
			this->SetDirty();
 
		}
 

	
 
		if (this->IsWidgetLowered(WID_TE_FAST_FORWARD) != !!_fast_forward) {
src/vehicle_gui.cpp
Show inline comments
 
@@ -1673,13 +1673,13 @@ public:
 
				break;
 
			default: NOT_REACHED();
 
		}
 
		this->SetDirty();
 
	}
 

	
 
	virtual void OnTick()
 
	virtual void OnGameTick()
 
	{
 
		if (_pause_mode != PM_UNPAUSED) return;
 
		if (this->vehicles.NeedResort()) {
 
			StationID station = (this->vli.type == VL_STATION_LIST) ? this->vli.index : INVALID_STATION;
 

	
 
			DEBUG(misc, 3, "Periodic resort %d list company %d at station %d", this->vli.vtype, this->owner, station);
 
@@ -2730,13 +2730,13 @@ public:
 
		if (this->viewport != NULL) {
 
			NWidgetViewport *nvp = this->GetWidget<NWidgetViewport>(WID_VV_VIEWPORT);
 
			nvp->UpdateViewportCoordinates(this);
 
		}
 
	}
 

	
 
	virtual void OnTick()
 
	virtual void OnGameTick()
 
	{
 
		const Vehicle *v = Vehicle::Get(this->window_number);
 
		bool veh_stopped = v->IsStoppedInDepot();
 

	
 
		/* Widget WID_VV_GOTO_DEPOT must be hidden if the vehicle is already stopped in depot.
 
		 * Widget WID_VV_CLONE_VEH should then be shown, since cloning is allowed only while in depot and stopped.
src/window.cpp
Show inline comments
 
@@ -3072,19 +3072,38 @@ void InputLoop()
 
	/* HandleMouseEvents was already called for this tick */
 
	HandleMouseEvents();
 
	HandleAutoscroll();
 
}
 

	
 
/**
 
 * Dispatch OnRealtimeTick event over all windows
 
 */
 
void CallWindowRealtimeTickEvent(uint delta_ms)
 
{
 
	Window *w;
 
	FOR_ALL_WINDOWS_FROM_FRONT(w) {
 
		w->OnRealtimeTick(delta_ms);
 
	}
 
}
 

	
 
/**
 
 * Update the continuously changing contents of the windows, such as the viewports
 
 */
 
void UpdateWindows()
 
{
 
	static uint32 last_realtime_tick = _realtime_tick;
 
	uint delta_ms = _realtime_tick - last_realtime_tick;
 
	last_realtime_tick = _realtime_tick;
 

	
 
	if (delta_ms == 0) return;
 

	
 
	PerformanceMeasurer framerate(PFE_DRAWING);
 
	PerformanceAccumulator::Reset(PFE_DRAWWORLD);
 

	
 
	CallWindowRealtimeTickEvent(delta_ms);
 

	
 
	Window *w;
 

	
 
	static int highlight_timer = 1;
 
	if (--highlight_timer == 0) {
 
		highlight_timer = 15;
 
		_window_highlight_colour = !_window_highlight_colour;
 
@@ -3260,19 +3279,19 @@ void InvalidateWindowClassesData(WindowC
 
			w->InvalidateData(data, gui_scope);
 
		}
 
	}
 
}
 

	
 
/**
 
 * Dispatch WE_TICK event over all windows
 
 * Dispatch OnTick event over all windows
 
 */
 
void CallWindowTickEvent()
 
void CallWindowGameTickEvent()
 
{
 
	Window *w;
 
	FOR_ALL_WINDOWS_FROM_FRONT(w) {
 
		w->OnTick();
 
		w->OnGameTick();
 
	}
 
}
 

	
 
/**
 
 * Try to delete a non-vital window.
 
 * Non-vital windows are windows other than the game selection, main toolbar,
src/window_func.h
Show inline comments
 
@@ -53,7 +53,39 @@ void SetWindowClassesDirty(WindowClass c
 
void DeleteWindowById(WindowClass cls, WindowNumber number, bool force = true);
 
void DeleteWindowByClass(WindowClass cls);
 

	
 
bool EditBoxInGlobalFocus();
 
Point GetCaretPosition();
 

	
 
/**
 
 * Count how many times the interval has elapsed, and update the timer.
 
 * Use to ensure a specific amount of events happen within a timeframe, e.g. for animation.
 
 * The timer value does not need to be initialised.
 
 * @param timer Timer to test. Value will be increased.
 
 * @param delta Time since last test.
 
 * @param interval Timing interval.
 
 * @return Number of times the interval has elapsed.
 
 */
 
static inline uint CountIntervalElapsed(uint &timer, uint delta, uint interval)
 
{
 
	uint count = delta / interval;
 
	if (timer + (delta % interval) >= interval) count++;
 
	timer = (timer + delta) % interval;
 
	return count;
 
}
 

	
 
/**
 
 * Test if a timer has elapsed, and update the timer.
 
 * Use to ensure an event happens only once within a timeframe, e.g. for window updates.
 
 * The timer value must be initialised in order for the timer to elapsed.
 
 * @param timer Timer to test. Value will be decreased.
 
 * @param delta Time since last test.
 
 * @return True iff the timer has elapsed.
 
 */
 
static inline bool TimerElapsed(int &timer, uint delta)
 
{
 
	if (timer <= 0) return false;
 
	timer -= delta;
 
	return timer <= 0;
 
}
 

	
 
#endif /* WINDOW_FUNC_H */
src/window_gui.h
Show inline comments
 
@@ -675,20 +675,25 @@ public:
 
	 */
 
	virtual void OnMouseLoop() {}
 

	
 
	/**
 
	 * Called once per (game) tick.
 
	 */
 
	virtual void OnTick() {}
 
	virtual void OnGameTick() {}
 

	
 
	/**
 
	 * Called once every 100 (game) ticks.
 
	 */
 
	virtual void OnHundredthTick() {}
 

	
 
	/**
 
	 * Called periodically.
 
	 */
 
	virtual void OnRealtimeTick(uint delta_ms) {}
 

	
 
	/**
 
	 * Called when this window's timeout has been reached.
 
	 */
 
	virtual void OnTimeout() {}
 

	
 

	
 
	/**
0 comments (0 inline, 0 general)