mirror of https://github.com/OpenTTD/OpenTTD
Change: Add sound memory usage to framerate window.
parent
ce5279a8dc
commit
8b00661b22
|
@ -10,6 +10,7 @@
|
||||||
#include "framerate_type.h"
|
#include "framerate_type.h"
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
#include "gfx_func.h"
|
#include "gfx_func.h"
|
||||||
|
#include "newgrf_sound.h"
|
||||||
#include "window_gui.h"
|
#include "window_gui.h"
|
||||||
#include "window_func.h"
|
#include "window_func.h"
|
||||||
#include "table/sprites.h"
|
#include "table/sprites.h"
|
||||||
|
@ -393,9 +394,7 @@ static constexpr NWidgetPart _framerate_window_widgets[] = {
|
||||||
NWidget(WWT_EMPTY, COLOUR_GREY, WID_FRW_TIMES_NAMES), SetScrollbar(WID_FRW_SCROLLBAR),
|
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_CURRENT), SetScrollbar(WID_FRW_SCROLLBAR),
|
||||||
NWidget(WWT_EMPTY, COLOUR_GREY, WID_FRW_TIMES_AVERAGE), 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),
|
||||||
NWidget(WWT_EMPTY, COLOUR_GREY, WID_FRW_ALLOCSIZE), SetScrollbar(WID_FRW_SCROLLBAR),
|
|
||||||
EndContainer(),
|
|
||||||
EndContainer(),
|
EndContainer(),
|
||||||
NWidget(WWT_TEXT, COLOUR_GREY, WID_FRW_INFO_DATA_POINTS), SetDataTip(STR_FRAMERATE_DATA_POINTS, 0x0), SetFill(1, 0), SetResize(1, 0),
|
NWidget(WWT_TEXT, COLOUR_GREY, WID_FRW_INFO_DATA_POINTS), SetDataTip(STR_FRAMERATE_DATA_POINTS, 0x0), SetFill(1, 0), SetResize(1, 0),
|
||||||
EndContainer(),
|
EndContainer(),
|
||||||
|
@ -409,7 +408,6 @@ static constexpr NWidgetPart _framerate_window_widgets[] = {
|
||||||
|
|
||||||
struct FramerateWindow : Window {
|
struct FramerateWindow : Window {
|
||||||
bool small;
|
bool small;
|
||||||
bool showing_memory;
|
|
||||||
int num_active;
|
int num_active;
|
||||||
int num_displayed;
|
int num_displayed;
|
||||||
|
|
||||||
|
@ -452,7 +450,6 @@ struct FramerateWindow : Window {
|
||||||
{
|
{
|
||||||
this->InitNested(number);
|
this->InitNested(number);
|
||||||
this->small = this->IsShaded();
|
this->small = this->IsShaded();
|
||||||
this->showing_memory = true;
|
|
||||||
this->UpdateData();
|
this->UpdateData();
|
||||||
this->num_displayed = this->num_active;
|
this->num_displayed = this->num_active;
|
||||||
|
|
||||||
|
@ -480,7 +477,6 @@ struct FramerateWindow : Window {
|
||||||
void UpdateData()
|
void UpdateData()
|
||||||
{
|
{
|
||||||
double gl_rate = _pf_data[PFE_GAMELOOP].GetRate();
|
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->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);
|
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
|
if (this->small) return; // in small mode, this is everything needed
|
||||||
|
@ -493,22 +489,14 @@ struct FramerateWindow : Window {
|
||||||
this->times_longterm[e].SetTime(_pf_data[e].GetAverageDurationMilliseconds(NUM_FRAMERATE_POINTS), 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) {
|
if (_pf_data[e].num_valid > 0) {
|
||||||
new_active++;
|
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) {
|
if (new_active != this->num_active) {
|
||||||
this->num_active = new_active;
|
this->num_active = new_active;
|
||||||
Scrollbar *sb = this->GetScrollbar(WID_FRW_SCROLLBAR);
|
Scrollbar *sb = this->GetScrollbar(WID_FRW_SCROLLBAR);
|
||||||
sb->SetCount(this->num_active);
|
sb->SetCount(this->num_active);
|
||||||
sb->SetCapacity(std::min(this->num_displayed, this->num_active));
|
sb->SetCapacity(std::min(this->num_displayed, this->num_active));
|
||||||
this->ReInit();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -642,6 +630,12 @@ struct FramerateWindow : Window {
|
||||||
y += GetCharacterHeight(FS_NORMAL);
|
y += GetCharacterHeight(FS_NORMAL);
|
||||||
drawable--;
|
drawable--;
|
||||||
if (drawable == 0) break;
|
if (drawable == 0) break;
|
||||||
|
} else if (e == PFE_SOUND) {
|
||||||
|
SetDParam(0, GetSoundPoolAllocatedMemory());
|
||||||
|
DrawString(r.left, r.right, y, STR_FRAMERATE_BYTES_GOOD, TC_FROMSTRING, SA_RIGHT);
|
||||||
|
y += GetCharacterHeight(FS_NORMAL);
|
||||||
|
drawable--;
|
||||||
|
if (drawable == 0) break;
|
||||||
} else {
|
} else {
|
||||||
/* skip non-script */
|
/* skip non-script */
|
||||||
y += GetCharacterHeight(FS_NORMAL);
|
y += GetCharacterHeight(FS_NORMAL);
|
||||||
|
|
|
@ -59,6 +59,21 @@ uint GetNumSounds()
|
||||||
return (uint)_sounds.size();
|
return (uint)_sounds.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get size of memory allocated to sound effects.
|
||||||
|
* @return Approximate memory allocated by loaded sound effects.
|
||||||
|
*/
|
||||||
|
size_t GetSoundPoolAllocatedMemory()
|
||||||
|
{
|
||||||
|
size_t bytes = 0;
|
||||||
|
for (SoundEntry &sound : _sounds) {
|
||||||
|
if (sound.data == nullptr) continue;
|
||||||
|
|
||||||
|
const auto &data = *sound.data;
|
||||||
|
bytes += data.capacity() * sizeof(data[0]);
|
||||||
|
}
|
||||||
|
return bytes;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Extract meta data from a NewGRF sound.
|
* Extract meta data from a NewGRF sound.
|
||||||
|
|
|
@ -34,6 +34,7 @@ bool LoadNewGRFSound(SoundEntry &sound, SoundID sound_id);
|
||||||
SoundID GetNewGRFSoundID(const struct GRFFile *file, SoundID sound_id);
|
SoundID GetNewGRFSoundID(const struct GRFFile *file, SoundID sound_id);
|
||||||
SoundEntry *GetSound(SoundID sound_id);
|
SoundEntry *GetSound(SoundID sound_id);
|
||||||
uint GetNumSounds();
|
uint GetNumSounds();
|
||||||
|
size_t GetSoundPoolAllocatedMemory();
|
||||||
bool PlayVehicleSound(const Vehicle *v, VehicleSoundEvent event, bool force = false);
|
bool PlayVehicleSound(const Vehicle *v, VehicleSoundEvent event, bool force = false);
|
||||||
void PlayTileSound(const struct GRFFile *file, SoundID sound_id, TileIndex tile);
|
void PlayTileSound(const struct GRFFile *file, SoundID sound_id, TileIndex tile);
|
||||||
|
|
||||||
|
|
|
@ -21,7 +21,6 @@ enum FramerateWindowWidgets : WidgetID {
|
||||||
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_SCROLLBAR,
|
WID_FRW_SCROLLBAR,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue