Civ backgrounds for minimap
[0ad.git] / source / ps / ProfileViewer.h
bloba62d9d749036600b1346d784606d124dfbf76ad7
1 /* Copyright (C) 2022 Wildfire Games.
2 * This file is part of 0 A.D.
4 * 0 A.D. is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 2 of the License, or
7 * (at your option) any later version.
9 * 0 A.D. is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
19 * Viewing profiling information (timing and other statistics)
22 #ifndef INCLUDED_PROFILE_VIEWER
23 #define INCLUDED_PROFILE_VIEWER
25 #include "lib/input.h"
26 #include "ps/CStr.h"
27 #include "ps/Singleton.h"
29 #include <vector>
31 class CCanvas2D;
33 /**
34 * Struct ProfileColumn: Describes one column of an AbstractProfileTable.
36 struct ProfileColumn
38 /// Title of the column
39 CStr title;
41 /// Recommended width of the column, in pixels.
42 size_t width;
44 ProfileColumn(const CStr& t, size_t w) : title(t), width(w) { }
48 /**
49 * Class AbstractProfileTable: Profile table data model.
51 * Clients that wish to display debug information in the profile viewer
52 * have to implement this class and hook it into CProfileViewer.
54 * Note that the profiling system is robust against deletion of
55 * object instances in the sense that it will automatically remove
56 * an AbstractProfileTable instance from its internal records when
57 * you delete it.
58 * Conversely, deleting an AbstractProfileTable instance is the responsibility
59 * of its creator.
61 class AbstractProfileTable
63 public:
64 virtual ~AbstractProfileTable();
66 /**
67 * GetName: Short descriptive name of this table (should be static).
69 * @return Descriptive name of this table.
71 virtual CStr GetName() = 0;
73 /**
74 * GetTitle: Longer, explanatory text (can be dynamic).
76 * @return Title for the table.
78 virtual CStr GetTitle() = 0;
81 /**
82 * GetNumberRows
84 * @return Number of rows in this table.
86 virtual size_t GetNumberRows() = 0;
88 /**
89 * GetColumnDescriptions
91 * @return A vector describing all columns of the table.
93 virtual const std::vector<ProfileColumn>& GetColumns() = 0;
95 /**
96 * GetCellText
98 * @param row Row index (the first row has index 0).
99 * @param col Column index (the first column has index 0).
101 * @return Text to be displayed in the given cell.
103 virtual CStr GetCellText(size_t row, size_t col) = 0;
106 * GetChild: Return a row's child table if the child is expandable.
108 * @param row Row index (the first row has index 0).
110 * @return Pointer to the child table if the given row has one.
111 * Otherwise, return 0.
113 virtual AbstractProfileTable* GetChild(size_t row) = 0;
116 * IsHighlightRow
118 * @param row Row index (the first row has index 0).
120 * @return true if the row should be highlighted in a special color.
122 virtual bool IsHighlightRow(size_t row) { UNUSED2(row); return false; }
126 struct CProfileViewerInternals;
129 * Class CProfileViewer: Manage and display profiling tables.
131 class CProfileViewer : public Singleton<CProfileViewer>
133 friend class AbstractProfileTable;
135 public:
136 CProfileViewer();
137 ~CProfileViewer();
140 * RenderProfile: Render the profile display using OpenGL if the user
141 * has enabled it.
143 void RenderProfile(CCanvas2D& canvas);
146 * Input: Filter and handle any input events that the profile display
147 * is interested in.
149 * In particular, this function handles enable/disable of the profile
150 * display as well as navigating the information tree.
152 * @param ev The incoming event.
154 * @return IN_PASS or IN_HANDLED depending on whether the event relates
155 * to the profiling display.
157 InReaction Input(const SDL_Event_* ev);
160 * AddRootTable: Add a new profile table as a root table (i.e. the
161 * tables that you cycle through via the profile hotkey).
163 * @note Tables added via this function are automatically removed from
164 * the list of root tables when they are deleted.
166 * @param table This table is added as a root table.
167 * @param front If true then the table will be the new first in the list,
168 * else it will be the last.
170 void AddRootTable(AbstractProfileTable* table, bool front = false);
173 * InputThunk: Delegate to the singleton's Input() member function
174 * if the singleton has been initialized.
176 * This allows our input handler to be installed via in_add_handler
177 * like a normal, global function input handler.
179 static InReaction InputThunk(const SDL_Event_* ev);
182 * SaveToFile: Save the current profiler data (for all profile tables)
183 * to a file in the 'logs' directory.
185 void SaveToFile();
188 * ShowTable: Set the named profile table to be the displayed one. If it
189 * is not found, no profile is displayed.
191 * @param table The table name (matching AbstractProfileTable::GetName),
192 * or the empty string to display no table.
194 void ShowTable(const CStr& table);
196 private:
197 CProfileViewerInternals* m;
200 #define g_ProfileViewer CProfileViewer::GetSingleton()
202 #endif