0ad/source/ps/ProfileViewer.h
janwas c0ed950657 had to remove uint and ulong from lib/types.h due to conflict with other library.
this snowballed into a massive search+destroy of the hodgepodge of
mostly equivalent types we had in use (int, uint, unsigned, unsigned
int, i32, u32, ulong, uintN).

it is more efficient to use 64-bit types in 64-bit mode, so the
preferred default is size_t (for anything remotely resembling a size or
index). tile coordinates are ssize_t to allow more efficient conversion
to/from floating point. flags are int because we almost never need more
than 15 distinct bits, bit test/set is not slower and int is fastest to
type. finally, some data that is pretty much directly passed to OpenGL
is now typed accordingly.

after several hours, the code now requires fewer casts and less
guesswork.

other changes:
- unit and player IDs now have an "invalid id" constant in the
respective class to avoid casting and -1
- fix some endian/64-bit bugs in the map (un)packing. added a
convenience function to write/read a size_t.
- ia32: change CPUID interface to allow passing in ecx (required for
cache topology detection, which I need at work). remove some unneeded
functions from asm, replace with intrinsics where possible.

This was SVN commit r5942.
2008-05-11 18:48:32 +00:00

185 lines
4.6 KiB
C++

/**
* =========================================================================
* File : ProfileViewer.h
* Project : Pyrogenesis
* Description : Viewing profiling information (timing and other statistics)
* =========================================================================
*/
#ifndef INCLUDED_PROFILE_VIEWER
#define INCLUDED_PROFILE_VIEWER
#include "lib/input.h"
#include "ps/CStr.h"
#include "ps/Singleton.h"
/**
* Struct ProfileColumn: Describes one column of an AbstractProfileTable.
*/
struct ProfileColumn
{
/// Title of the column
CStr title;
/// Recommended width of the column, in pixels.
size_t width;
ProfileColumn(const CStr& t, size_t w) : title(t), width(w) { }
};
/**
* Class AbstractProfileTable: Profile table data model.
*
* Clients that wish to display debug information in the profile viewer
* have to implement this class and hook it into CProfileViewer.
*
* Note that the profiling system is robust against deletion of
* object instances in the sense that it will automatically remove
* an AbstractProfileTable instance from its internal records when
* you delete it.
* Conversely, deleting an AbstractProfileTable instance is the responsibility
* of its creator.
*/
class AbstractProfileTable
{
public:
virtual ~AbstractProfileTable();
/**
* GetName: Short descriptive name of this table (should be static).
*
* @return Descriptive name of this table.
*/
virtual CStr GetName() = 0;
/**
* GetTitle: Longer, explanatory text (can be dynamic).
*
* @return Title for the table.
*/
virtual CStr GetTitle() = 0;
/**
* GetNumberRows
*
* @return Number of rows in this table.
*/
virtual size_t GetNumberRows() = 0;
/**
* GetColumnDescriptions
*
* @return A vector describing all columns of the table.
*/
virtual const std::vector<ProfileColumn>& GetColumns() = 0;
/**
* GetCellText
*
* @param row Row index (the first row has index 0).
* @param col Column index (the first column has index 0).
*
* @return Text to be displayed in the given cell.
*/
virtual CStr GetCellText(size_t row, size_t col) = 0;
/**
* GetChild: Return a row's child table if the child is expandable.
*
* @param row Row index (the first row has index 0).
*
* @return Pointer to the child table if the given row has one.
* Otherwise, return 0.
*/
virtual AbstractProfileTable* GetChild(size_t row) = 0;
/**
* IsHighlightRow
*
* @param row Row index (the first row has index 0).
*
* @return true if the row should be highlighted in a special color.
*/
virtual bool IsHighlightRow(size_t row) { UNUSED2(row); return false; }
};
struct CProfileViewerInternals;
/**
* Class CProfileViewer: Manage and display profiling tables.
*/
class CProfileViewer : public Singleton<CProfileViewer>
{
friend class AbstractProfileTable;
public:
CProfileViewer();
~CProfileViewer();
/**
* RenderProfile: Render the profile display using OpenGL if the user
* has enabled it.
*/
void RenderProfile();
/**
* Input: Filter and handle any input events that the profile display
* is interested in.
*
* In particular, this function handles enable/disable of the profile
* display as well as navigating the information tree.
*
* @param ev The incoming event.
*
* @return IN_PASS or IN_HANDLED depending on whether the event relates
* to the profiling display.
*/
InReaction Input(const SDL_Event_* ev);
/**
* AddRootTable: Add a new profile table as a root table (i.e. the
* tables that you cycle through via the profile hotkey).
*
* @note Tables added via this function are automatically removed from
* the list of root tables when they are deleted.
*
* @param table This table is added as a root table.
*/
void AddRootTable(AbstractProfileTable* table);
/**
* InputThunk: Delegate to the singleton's Input() member function
* if the singleton has been initialized.
*
* This allows our input handler to be installed via in_add_handler
* like a normal, global function input handler.
*/
static InReaction InputThunk(const SDL_Event_* ev);
/**
* SaveToFile: Save the current profiler data (for all profile tables)
* to a file in the 'logs' directory.
*/
void SaveToFile();
/**
* ShowTable: Set the named profile table to be the displayed one. If it
* is not found, no profile is displayed.
*
* @param table The table name (matching AbstractProfileTable::GetName),
* or the empty string to display no table.
*/
void ShowTable(const CStr& table);
private:
CProfileViewerInternals* m;
};
#define g_ProfileViewer CProfileViewer::GetSingleton()
#endif