Changeset - r23731:be6c5f9d307a
[Not reviewed]
master
0 5 0
Niels Martin Hansen - 6 years ago 2019-04-15 18:29:37
nielsm@indvikleren.dk
Add: Show memory allocations by GS and AI in framerate window
5 files changed with 65 insertions and 2 deletions:
0 comments (0 inline, 0 general)
src/framerate_gui.cpp
Show inline comments
 
@@ -22,6 +22,9 @@
 
#include "guitimer_func.h"
 
#include "company_base.h"
 
#include "ai/ai_info.hpp"
 
#include "ai/ai_instance.hpp"
 
#include "game/game.hpp"
 
#include "game/game_instance.hpp"
 

	
 
#include "widgets/framerate_widget.h"
 
#include "safeguards.h"
 
@@ -365,6 +368,9 @@ static const NWidgetPart _framerate_wind
 
					NWidget(WWT_EMPTY, COLOUR_GREY, WID_FRW_TIMES_NAMES), SetScrollbar(WID_FRW_SCROLLBAR),
 
					NWidget(WWT_EMPTY, COLOUR_GREY, WID_FRW_TIMES_CURRENT), SetScrollbar(WID_FRW_SCROLLBAR),
 
					NWidget(WWT_EMPTY, COLOUR_GREY, WID_FRW_TIMES_AVERAGE), SetScrollbar(WID_FRW_SCROLLBAR),
 
					NWidget(NWID_SELECTION, INVALID_COLOUR, WID_FRW_SEL_MEMORY),
 
						NWidget(WWT_EMPTY, COLOUR_GREY, WID_FRW_ALLOCSIZE), SetScrollbar(WID_FRW_SCROLLBAR),
 
					EndContainer(),
 
				EndContainer(),
 
				NWidget(WWT_TEXT, COLOUR_GREY, WID_FRW_INFO_DATA_POINTS), SetDataTip(STR_FRAMERATE_DATA_POINTS, 0x0),
 
			EndContainer(),
 
@@ -378,6 +384,7 @@ static const NWidgetPart _framerate_wind
 

	
 
struct FramerateWindow : Window {
 
	bool small;
 
	bool showing_memory;
 
	GUITimer next_update;
 
	int num_active;
 
	int num_displayed;
 
@@ -424,6 +431,7 @@ struct FramerateWindow : Window {
 
	{
 
		this->InitNested(number);
 
		this->small = this->IsShaded();
 
		this->showing_memory = true;
 
		this->UpdateData();
 
		this->num_displayed = this->num_active;
 
		this->next_update.SetInterval(100);
 
@@ -453,6 +461,7 @@ struct FramerateWindow : Window {
 
	void UpdateData()
 
	{
 
		double gl_rate = _pf_data[PFE_GAMELOOP].GetRate();
 
		bool have_script = false;
 
		this->rate_gameloop.SetRate(gl_rate, _pf_data[PFE_GAMELOOP].expected_rate);
 
		this->speed_gameloop.SetRate(gl_rate / _pf_data[PFE_GAMELOOP].expected_rate, 1.0);
 
		if (this->small) return; // in small mode, this is everything needed
 
@@ -463,7 +472,16 @@ struct FramerateWindow : Window {
 
		for (PerformanceElement e = PFE_FIRST; e < PFE_MAX; e++) {
 
			this->times_shortterm[e].SetTime(_pf_data[e].GetAverageDurationMilliseconds(8), MILLISECONDS_PER_TICK);
 
			this->times_longterm[e].SetTime(_pf_data[e].GetAverageDurationMilliseconds(NUM_FRAMERATE_POINTS), MILLISECONDS_PER_TICK);
 
			if (_pf_data[e].num_valid > 0) new_active++;
 
			if (_pf_data[e].num_valid > 0) {
 
				new_active++;
 
				if (e == PFE_GAMESCRIPT || e >= PFE_AI0) have_script = true;
 
			}
 
		}
 

	
 
		if (this->showing_memory != have_script) {
 
			NWidgetStacked *plane = this->GetWidget<NWidgetStacked>(WID_FRW_SEL_MEMORY);
 
			plane->SetDisplayedPlane(have_script ? 0 : SZSP_VERTICAL);
 
			this->showing_memory = have_script;
 
		}
 

	
 
		if (new_active != this->num_active) {
 
@@ -545,7 +563,8 @@ struct FramerateWindow : Window {
 
			}
 

	
 
			case WID_FRW_TIMES_CURRENT:
 
			case WID_FRW_TIMES_AVERAGE: {
 
			case WID_FRW_TIMES_AVERAGE:
 
			case WID_FRW_ALLOCSIZE: {
 
				*size = GetStringBoundingBox(STR_FRAMERATE_CURRENT + (widget - WID_FRW_TIMES_CURRENT));
 
				SetDParam(0, 999999);
 
				SetDParam(1, 2);
 
@@ -582,6 +601,37 @@ struct FramerateWindow : Window {
 
		}
 
	}
 

	
 
	void DrawElementAllocationsColumn(const Rect &r) const
 
	{
 
		const Scrollbar *sb = this->GetScrollbar(WID_FRW_SCROLLBAR);
 
		uint16 skip = sb->GetPosition();
 
		int drawable = this->num_displayed;
 
		int y = r.top;
 
		DrawString(r.left, r.right, y, STR_FRAMERATE_MEMORYUSE, TC_FROMSTRING, SA_CENTER, true);
 
		y += FONT_HEIGHT_NORMAL + VSPACING;
 
		for (PerformanceElement e : DISPLAY_ORDER_PFE) {
 
			if (_pf_data[e].num_valid == 0) continue;
 
			if (skip > 0) {
 
				skip--;
 
			} else if (e == PFE_GAMESCRIPT || e >= PFE_AI0) {
 
				if (e == PFE_GAMESCRIPT) {
 
					SetDParam(0, Game::GetInstance()->GetAllocatedMemory());
 
				} else {
 
					SetDParam(0, Company::Get(e - PFE_AI0)->ai_instance->GetAllocatedMemory());
 
				}
 
				DrawString(r.left, r.right, y, STR_FRAMERATE_BYTES_GOOD, TC_FROMSTRING, SA_RIGHT);
 
				y += FONT_HEIGHT_NORMAL;
 
				drawable--;
 
				if (drawable == 0) break;
 
			} else {
 
				/* skip non-script */
 
				y += FONT_HEIGHT_NORMAL;
 
				drawable--;
 
				if (drawable == 0) break;
 
			}
 
		}
 
	}
 

	
 
	void DrawWidget(const Rect &r, int widget) const override
 
	{
 
		switch (widget) {
 
@@ -618,6 +668,9 @@ struct FramerateWindow : Window {
 
				/* Render averages of all recorded values */
 
				DrawElementTimesColumn(r, STR_FRAMERATE_AVERAGE, this->times_longterm);
 
				break;
 
			case WID_FRW_ALLOCSIZE:
 
				DrawElementAllocationsColumn(r);
 
				break;
 
		}
 
	}
 

	
src/lang/english.txt
Show inline comments
 
@@ -2742,6 +2742,7 @@ STR_FRAMERATE_SPEED_FACTOR              
 
STR_FRAMERATE_SPEED_FACTOR_TOOLTIP                              :{BLACK}How fast the game is currently running, compared to the expected speed at normal simulation rate.
 
STR_FRAMERATE_CURRENT                                           :{WHITE}Current
 
STR_FRAMERATE_AVERAGE                                           :{WHITE}Average
 
STR_FRAMERATE_MEMORYUSE                                         :{WHITE}Memory
 
STR_FRAMERATE_DATA_POINTS                                       :{BLACK}Data based on {COMMA} measurements
 
STR_FRAMERATE_MS_GOOD                                           :{LTBLUE}{DECIMAL} ms
 
STR_FRAMERATE_MS_WARN                                           :{YELLOW}{DECIMAL} ms
 
@@ -2749,6 +2750,9 @@ STR_FRAMERATE_MS_BAD                    
 
STR_FRAMERATE_FPS_GOOD                                          :{LTBLUE}{DECIMAL} frames/s
 
STR_FRAMERATE_FPS_WARN                                          :{YELLOW}{DECIMAL} frames/s
 
STR_FRAMERATE_FPS_BAD                                           :{RED}{DECIMAL} frames/s
 
STR_FRAMERATE_BYTES_GOOD                                        :{LTBLUE}{BYTES}
 
STR_FRAMERATE_BYTES_WARN                                        :{YELLOW}{BYTES}
 
STR_FRAMERATE_BYTES_BAD                                         :{RED}{BYTES}
 
STR_FRAMERATE_GRAPH_MILLISECONDS                                :{TINY_FONT}{COMMA} ms
 
STR_FRAMERATE_GRAPH_SECONDS                                     :{TINY_FONT}{COMMA} s
 
############ Leave those lines in this order!!
src/script/api/game/game_window.hpp.sq
Show inline comments
 
@@ -468,6 +468,8 @@ void SQGSWindow_Register(Squirrel *engin
 
	SQGSWindow.DefSQConst(engine, ScriptWindow::WID_FRW_TIMES_NAMES,                       "WID_FRW_TIMES_NAMES");
 
	SQGSWindow.DefSQConst(engine, ScriptWindow::WID_FRW_TIMES_CURRENT,                     "WID_FRW_TIMES_CURRENT");
 
	SQGSWindow.DefSQConst(engine, ScriptWindow::WID_FRW_TIMES_AVERAGE,                     "WID_FRW_TIMES_AVERAGE");
 
	SQGSWindow.DefSQConst(engine, ScriptWindow::WID_FRW_ALLOCSIZE,                         "WID_FRW_ALLOCSIZE");
 
	SQGSWindow.DefSQConst(engine, ScriptWindow::WID_FRW_SEL_MEMORY,                        "WID_FRW_SEL_MEMORY");
 
	SQGSWindow.DefSQConst(engine, ScriptWindow::WID_FRW_SCROLLBAR,                         "WID_FRW_SCROLLBAR");
 
	SQGSWindow.DefSQConst(engine, ScriptWindow::WID_FGW_CAPTION,                           "WID_FGW_CAPTION");
 
	SQGSWindow.DefSQConst(engine, ScriptWindow::WID_FGW_GRAPH,                             "WID_FGW_GRAPH");
src/script/api/script_window.hpp
Show inline comments
 
@@ -1309,6 +1309,8 @@ public:
 
		WID_FRW_TIMES_NAMES                          = ::WID_FRW_TIMES_NAMES,
 
		WID_FRW_TIMES_CURRENT                        = ::WID_FRW_TIMES_CURRENT,
 
		WID_FRW_TIMES_AVERAGE                        = ::WID_FRW_TIMES_AVERAGE,
 
		WID_FRW_ALLOCSIZE                            = ::WID_FRW_ALLOCSIZE,
 
		WID_FRW_SEL_MEMORY                           = ::WID_FRW_SEL_MEMORY,
 
		WID_FRW_SCROLLBAR                            = ::WID_FRW_SCROLLBAR,
 
	};
 

	
src/widgets/framerate_widget.h
Show inline comments
 
@@ -22,6 +22,8 @@ enum FramerateWindowWidgets {
 
	WID_FRW_TIMES_NAMES,
 
	WID_FRW_TIMES_CURRENT,
 
	WID_FRW_TIMES_AVERAGE,
 
	WID_FRW_ALLOCSIZE,
 
	WID_FRW_SEL_MEMORY,
 
	WID_FRW_SCROLLBAR,
 
};
 

	
0 comments (0 inline, 0 general)