mirror of
https://github.com/elasota/Aerofoil.git
synced 2025-12-13 19:49:36 +00:00
Preload AA tables to speed up high scores screen on mobile.
This commit is contained in:
@@ -26,6 +26,7 @@
|
||||
#include "MemoryManager.h"
|
||||
#include "MenuManager.h"
|
||||
#include "QDPixMap.h"
|
||||
#include "QDStandardPalette.h"
|
||||
#include "RenderedFont.h"
|
||||
#include "ResolveCachingColor.h"
|
||||
#include "ResourceManager.h"
|
||||
@@ -380,7 +381,7 @@ void StepLoadScreen(int steps)
|
||||
{
|
||||
Rect loadScreenProgressBarFillRect = loadScreenProgressBarRect.Inset(1, 1);
|
||||
int oldProgress = loadScreenProgress;
|
||||
int loadScreenMax = 25;
|
||||
int loadScreenMax = 32;
|
||||
loadScreenProgress = loadScreenProgress + steps;
|
||||
if (loadScreenProgress > loadScreenMax)
|
||||
loadScreenProgress = loadScreenMax;
|
||||
@@ -612,7 +613,32 @@ void PreloadFonts()
|
||||
StepLoadScreenRing();
|
||||
Delay(1, nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
void PreloadAATables()
|
||||
{
|
||||
PortabilityLayer::StandardPalette *sp = PortabilityLayer::StandardPalette::GetInstance();
|
||||
PortabilityLayer::RGBAColor preloadColors[] =
|
||||
{
|
||||
PortabilityLayer::RGBAColor::Create(255, 255, 255, 255),
|
||||
PortabilityLayer::RGBAColor::Create(255, 51, 51, 255),
|
||||
PortabilityLayer::RGBAColor::Create(255, 0, 0, 255),
|
||||
PortabilityLayer::RGBAColor::Create(255, 255, 0, 255),
|
||||
PortabilityLayer::RGBAColor::Create(0, 255, 255, 255),
|
||||
PortabilityLayer::RGBAColor::Create(0, 0, 255, 255),
|
||||
PortabilityLayer::RGBAColor::Create(204, 102, 51, 255),
|
||||
};
|
||||
|
||||
const size_t numPreloads = sizeof(preloadColors) / sizeof(preloadColors[0]);
|
||||
|
||||
for (size_t i = 0; i < numPreloads; i++)
|
||||
{
|
||||
sp->GetCachedPaletteAATable(preloadColors[i]);
|
||||
sp->GetCachedToneAATable(preloadColors[i].r);
|
||||
sp->GetCachedToneAATable(preloadColors[i].g);
|
||||
sp->GetCachedToneAATable(preloadColors[i].b);
|
||||
StepLoadScreen(1);
|
||||
}
|
||||
}
|
||||
|
||||
void gpAppInit()
|
||||
@@ -655,6 +681,7 @@ int gpAppMain()
|
||||
|
||||
InitLoadingWindow(); StepLoadScreen(2);
|
||||
PreloadFonts(); StepLoadScreen(2);
|
||||
PreloadAATables();
|
||||
|
||||
#if defined COMPILEDEMO
|
||||
copyGood = true;
|
||||
|
||||
@@ -235,8 +235,7 @@ static void PlotLine(DrawSurface *surface, const PortabilityLayer::Vec2i &pointA
|
||||
surface->m_port.SetDirty(PortabilityLayer::QDPortDirtyFlag_Contents);
|
||||
}
|
||||
|
||||
static void DrawGlyph(PixMap *pixMap, const Rect &rect, const Point &penPos, const PortabilityLayer::RenderedFont *rfont, unsigned int character,
|
||||
PortabilityLayer::AntiAliasTable *&cachedAATable, PortabilityLayer::RGBAColor &cachedAATableColor, PortabilityLayer::ResolveCachingColor &cacheColor)
|
||||
static void DrawGlyph(PixMap *pixMap, const Rect &rect, const Point &penPos, const PortabilityLayer::RenderedFont *rfont, unsigned int character, PortabilityLayer::ResolveCachingColor &cacheColor)
|
||||
{
|
||||
assert(rect.IsValid());
|
||||
|
||||
@@ -282,28 +281,7 @@ static void DrawGlyph(PixMap *pixMap, const Rect &rect, const Point &penPos, con
|
||||
const PortabilityLayer::AntiAliasTable *aaTable = nullptr;
|
||||
|
||||
if (isAA)
|
||||
{
|
||||
if (cacheColor.GetRGBAColor() == PortabilityLayer::RGBAColor::Create(0, 0, 0, 255))
|
||||
aaTable = &PortabilityLayer::StandardPalette::GetInstance()->GetBlackAATable();
|
||||
else if (cacheColor.GetRGBAColor() == PortabilityLayer::RGBAColor::Create(255, 255, 255, 255))
|
||||
aaTable = &PortabilityLayer::StandardPalette::GetInstance()->GetWhiteAATable();
|
||||
else if (cachedAATable != nullptr && cacheColor.GetRGBAColor() == cachedAATableColor)
|
||||
aaTable = cachedAATable;
|
||||
else
|
||||
{
|
||||
if (!cachedAATable)
|
||||
{
|
||||
cachedAATable = static_cast<PortabilityLayer::AntiAliasTable*>(PortabilityLayer::MemoryManager::GetInstance()->Alloc(sizeof(PortabilityLayer::AntiAliasTable)));
|
||||
if (!cachedAATable)
|
||||
return;
|
||||
}
|
||||
|
||||
cachedAATableColor = cacheColor.GetRGBAColor();
|
||||
cachedAATable->GenerateForPalette(cacheColor.GetRGBAColor(), PortabilityLayer::StandardPalette::GetInstance()->GetColors(), 256);
|
||||
|
||||
aaTable = cachedAATable;
|
||||
}
|
||||
}
|
||||
aaTable = &PortabilityLayer::StandardPalette::GetInstance()->GetCachedPaletteAATable(cacheColor.GetRGBAColor());
|
||||
|
||||
const uint8_t color = cacheColor.Resolve8(nullptr, 0);
|
||||
for (uint32_t row = 0; row < numRows; row++)
|
||||
@@ -349,36 +327,9 @@ static void DrawGlyph(PixMap *pixMap, const Rect &rect, const Point &penPos, con
|
||||
{
|
||||
PortabilityLayer::RGBAColor rgbaColor = cacheColor.GetRGBAColor();
|
||||
uint8_t rgbColor[3] = { rgbaColor.r, rgbaColor.g, rgbaColor.b };
|
||||
uint8_t cacheRGBColor[3] = { cachedAATableColor.r, cachedAATableColor.g, cachedAATableColor.b };
|
||||
|
||||
for (int ch = 0; ch < 3; ch++)
|
||||
{
|
||||
if (rgbColor[ch] == 0)
|
||||
aaTables[ch] = &PortabilityLayer::StandardPalette::GetInstance()->GetBlackToneAATable();
|
||||
else if (rgbColor[ch] == 255)
|
||||
aaTables[ch] = &PortabilityLayer::StandardPalette::GetInstance()->GetWhiteToneAATable();
|
||||
else if (cachedAATable != nullptr && rgbColor[ch] == cacheRGBColor[ch])
|
||||
aaTables[ch] = &cachedAATable[ch];
|
||||
else
|
||||
{
|
||||
if (!cachedAATable)
|
||||
{
|
||||
cachedAATable = static_cast<PortabilityLayer::AntiAliasTable*>(PortabilityLayer::MemoryManager::GetInstance()->Alloc(sizeof(PortabilityLayer::AntiAliasTable) * 3));
|
||||
if (!cachedAATable)
|
||||
return;
|
||||
|
||||
cachedAATableColor = PortabilityLayer::RGBAColor::Create(0, 0, 0, 255);
|
||||
cachedAATable[0] = cachedAATable[1] = cachedAATable[2] = PortabilityLayer::StandardPalette::GetInstance()->GetBlackToneAATable();
|
||||
}
|
||||
|
||||
cacheRGBColor[ch] = rgbColor[ch];
|
||||
|
||||
cachedAATableColor = PortabilityLayer::RGBAColor::Create(cacheRGBColor[0], cacheRGBColor[1], cacheRGBColor[2], 255);
|
||||
cachedAATable[ch].GenerateForSimpleScale(rgbColor[ch]);
|
||||
|
||||
aaTables[ch] = &cachedAATable[ch];
|
||||
}
|
||||
}
|
||||
aaTables[ch] = &PortabilityLayer::StandardPalette::GetInstance()->GetCachedToneAATable(rgbColor[ch]);
|
||||
}
|
||||
|
||||
for (uint32_t row = 0; row < numRows; row++)
|
||||
@@ -426,14 +377,13 @@ static void DrawGlyph(PixMap *pixMap, const Rect &rect, const Point &penPos, con
|
||||
}
|
||||
}
|
||||
|
||||
static void DrawText(PortabilityLayer::TextPlacer &placer, PixMap *pixMap, const Rect &rect, const PortabilityLayer::RenderedFont *rfont,
|
||||
PortabilityLayer::AntiAliasTable *&cachedAATable, PortabilityLayer::RGBAColor &cachedAATableColor, PortabilityLayer::ResolveCachingColor &cacheColor)
|
||||
static void DrawText(PortabilityLayer::TextPlacer &placer, PixMap *pixMap, const Rect &rect, const PortabilityLayer::RenderedFont *rfont, PortabilityLayer::ResolveCachingColor &cacheColor)
|
||||
{
|
||||
PortabilityLayer::GlyphPlacementCharacteristics characteristics;
|
||||
while (placer.PlaceGlyph(characteristics))
|
||||
{
|
||||
if (characteristics.m_haveGlyph)
|
||||
DrawGlyph(pixMap, rect, Point::Create(characteristics.m_glyphStartPos.m_x, characteristics.m_glyphStartPos.m_y), rfont, characteristics.m_character, cachedAATable, cachedAATableColor, cacheColor);
|
||||
DrawGlyph(pixMap, rect, Point::Create(characteristics.m_glyphStartPos.m_x, characteristics.m_glyphStartPos.m_y), rfont, characteristics.m_character, cacheColor);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -457,7 +407,7 @@ void DrawSurface::DrawStringConstrained(const Point &point, const PLPasStr &str,
|
||||
|
||||
PortabilityLayer::TextPlacer placer(PortabilityLayer::Vec2i(point.h, point.v), -1, rfont, str);
|
||||
|
||||
DrawText(placer, pixMap, rect, rfont, m_cachedAATables, m_cachedAAColor, cacheColor);
|
||||
DrawText(placer, pixMap, rect, rfont, cacheColor);
|
||||
|
||||
m_port.SetDirty(PortabilityLayer::QDPortDirtyFlag_Contents);
|
||||
}
|
||||
@@ -482,7 +432,7 @@ void DrawSurface::DrawStringWrap(const Point &point, const Rect &constrainRect,
|
||||
|
||||
PortabilityLayer::TextPlacer placer(PortabilityLayer::Vec2i(point.h, point.v), areaRect.Width(), rfont, str);
|
||||
|
||||
DrawText(placer, pixMap, limitRect, rfont, m_cachedAATables, m_cachedAAColor, cacheColor);
|
||||
DrawText(placer, pixMap, limitRect, rfont, cacheColor);
|
||||
|
||||
m_port.SetDirty(PortabilityLayer::QDPortDirtyFlag_Contents);
|
||||
}
|
||||
|
||||
@@ -8,8 +8,6 @@
|
||||
|
||||
DrawSurface::~DrawSurface()
|
||||
{
|
||||
if (m_cachedAATables)
|
||||
PortabilityLayer::MemoryManager::GetInstance()->Release(m_cachedAATables);
|
||||
}
|
||||
|
||||
void DrawSurface::PushToDDSurface(IGpDisplayDriver *displayDriver)
|
||||
|
||||
@@ -31,16 +31,12 @@ struct DrawSurface
|
||||
DrawSurface()
|
||||
: m_port(PortabilityLayer::QDPortType_DrawSurface)
|
||||
, m_ddSurface(nullptr)
|
||||
, m_cachedAAColor(PortabilityLayer::RGBAColor::Create(0, 0, 0, 255))
|
||||
, m_cachedAATables(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
explicit DrawSurface(PortabilityLayer::QDPortType overridePortType)
|
||||
: m_port(overridePortType)
|
||||
, m_ddSurface(nullptr)
|
||||
, m_cachedAAColor(PortabilityLayer::RGBAColor::Create(0, 0, 0, 255))
|
||||
, m_cachedAATables(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -85,9 +81,6 @@ struct DrawSurface
|
||||
|
||||
IGpDisplayDriverSurface *m_ddSurface;
|
||||
|
||||
PortabilityLayer::AntiAliasTable *m_cachedAATables;
|
||||
PortabilityLayer::RGBAColor m_cachedAAColor;
|
||||
|
||||
PortabilityLayer::QDPort m_port;
|
||||
|
||||
private:
|
||||
|
||||
@@ -24,6 +24,8 @@ namespace
|
||||
namespace PortabilityLayer
|
||||
{
|
||||
StandardPalette::StandardPalette()
|
||||
: m_numCachedPaletteTables(0)
|
||||
, m_numCachedToneTables(0)
|
||||
{
|
||||
for (unsigned int rs = 0; rs < 6; rs++)
|
||||
{
|
||||
@@ -82,42 +84,6 @@ namespace PortabilityLayer
|
||||
for (unsigned int gs = 0; gs < 16; gs++)
|
||||
for (unsigned int bs = 0; bs < 16; bs++)
|
||||
m_lut[rs + (gs << 4) + (bs << 8)] = MapColorAnalyticTruncated(rs, gs, bs);
|
||||
|
||||
#if 0
|
||||
for (unsigned int i = 0; i < 256; i++)
|
||||
{
|
||||
unsigned int shortChannels[3] =
|
||||
{
|
||||
m_colors[i].r / 17,
|
||||
m_colors[i].g / 17,
|
||||
m_colors[i].b / 17
|
||||
};
|
||||
|
||||
for (unsigned int b = 0; b < 16; b++)
|
||||
{
|
||||
unsigned int whiteScale[3];
|
||||
unsigned int blackScale[3];
|
||||
|
||||
for (unsigned int ch = 0; ch < 3; ch++)
|
||||
{
|
||||
unsigned int scaledBackground = (15 - b) * shortChannels[ch];
|
||||
unsigned int scaledWhiteForeground = 15 * b;
|
||||
|
||||
blackScale[ch] = scaledBackground / 15;
|
||||
whiteScale[ch] = (scaledBackground + scaledWhiteForeground) / 15;
|
||||
}
|
||||
|
||||
m_blackAATable.m_aaTranslate[i][b] = MapColorAnalyticTruncated(blackScale[0], blackScale[1], blackScale[2]);
|
||||
m_whiteAATable.m_aaTranslate[i][b] = MapColorAnalyticTruncated(whiteScale[0], whiteScale[1], whiteScale[2]);
|
||||
}
|
||||
}
|
||||
#else
|
||||
m_blackAATable.GenerateForPalette(RGBAColor::Create(0, 0, 0, 255), m_colors, 256);
|
||||
m_whiteAATable.GenerateForPalette(RGBAColor::Create(255, 255, 255, 255), m_colors, 256);
|
||||
#endif
|
||||
|
||||
m_whiteToneAATable.GenerateForSimpleScale(255);
|
||||
m_blackToneAATable.GenerateForSimpleScale(0);
|
||||
}
|
||||
|
||||
const RGBAColor *StandardPalette::GetColors() const
|
||||
@@ -261,29 +227,51 @@ namespace PortabilityLayer
|
||||
return MapColorLUT(color.r, color.g, color.b);
|
||||
}
|
||||
|
||||
const StandardPalette *StandardPalette::GetInstance()
|
||||
StandardPalette *StandardPalette::GetInstance()
|
||||
{
|
||||
return &ms_instance;
|
||||
}
|
||||
|
||||
const AntiAliasTable &StandardPalette::GetWhiteAATable() const
|
||||
const AntiAliasTable &StandardPalette::GetCachedPaletteAATable(const RGBAColor &color)
|
||||
{
|
||||
return m_whiteAATable;
|
||||
uint8_t rgb[3] = { color.r, color.g, color.b };
|
||||
|
||||
for (size_t i = 0; i < m_numCachedPaletteTables; i++)
|
||||
{
|
||||
const CachedPaletteTableEntry &entry = m_cachedPaletteTables[i];
|
||||
if (entry.m_rgb[0] == rgb[0] && entry.m_rgb[1] == rgb[1] && entry.m_rgb[2] == rgb[2])
|
||||
return entry.m_aaTable;
|
||||
}
|
||||
|
||||
if (m_numCachedPaletteTables == kMaxCachedPaletteTables)
|
||||
m_numCachedPaletteTables = 0;
|
||||
|
||||
CachedPaletteTableEntry &entry = m_cachedPaletteTables[m_numCachedPaletteTables++];
|
||||
entry.m_rgb[0] = rgb[0];
|
||||
entry.m_rgb[1] = rgb[1];
|
||||
entry.m_rgb[2] = rgb[2];
|
||||
entry.m_aaTable.GenerateForPalette(color, m_colors, 256);
|
||||
|
||||
return entry.m_aaTable;
|
||||
}
|
||||
|
||||
const AntiAliasTable &StandardPalette::GetBlackAATable() const
|
||||
const AntiAliasTable &StandardPalette::GetCachedToneAATable(uint8_t tone)
|
||||
{
|
||||
return m_blackAATable;
|
||||
}
|
||||
for (size_t i = 0; i < m_numCachedToneTables; i++)
|
||||
{
|
||||
const CachedToneTableEntry &entry = m_cachedToneTables[i];
|
||||
if (entry.m_tone == tone)
|
||||
return entry.m_aaTable;
|
||||
}
|
||||
|
||||
const AntiAliasTable &StandardPalette::GetWhiteToneAATable() const
|
||||
{
|
||||
return m_whiteToneAATable;
|
||||
}
|
||||
if (m_numCachedToneTables == kMaxCachedToneTables)
|
||||
m_numCachedToneTables = 0;
|
||||
|
||||
const AntiAliasTable &StandardPalette::GetBlackToneAATable() const
|
||||
{
|
||||
return m_blackToneAATable;
|
||||
CachedToneTableEntry &entry = m_cachedToneTables[m_numCachedToneTables++];
|
||||
entry.m_tone = tone;
|
||||
entry.m_aaTable.GenerateForSimpleScale(tone);
|
||||
|
||||
return entry.m_aaTable;
|
||||
}
|
||||
|
||||
StandardPalette StandardPalette::ms_instance;
|
||||
|
||||
@@ -20,22 +20,38 @@ namespace PortabilityLayer
|
||||
static uint8_t MapColorAnalytic(const RGBAColor &color);
|
||||
uint8_t MapColorLUT(uint8_t r, uint8_t g, uint8_t b) const;
|
||||
uint8_t MapColorLUT(const RGBAColor &color) const;
|
||||
const AntiAliasTable &GetWhiteAATable() const;
|
||||
const AntiAliasTable &GetBlackAATable() const;
|
||||
|
||||
const AntiAliasTable &GetWhiteToneAATable() const;
|
||||
const AntiAliasTable &GetBlackToneAATable() const;
|
||||
const AntiAliasTable &GetCachedPaletteAATable(const RGBAColor &color);
|
||||
const AntiAliasTable &GetCachedToneAATable(uint8_t tone);
|
||||
|
||||
static const StandardPalette *GetInstance();
|
||||
static StandardPalette *GetInstance();
|
||||
|
||||
private:
|
||||
static StandardPalette ms_instance;
|
||||
|
||||
struct CachedPaletteTableEntry
|
||||
{
|
||||
uint8_t m_rgb[3];
|
||||
AntiAliasTable m_aaTable;
|
||||
};
|
||||
|
||||
struct CachedToneTableEntry
|
||||
{
|
||||
uint8_t m_tone;
|
||||
AntiAliasTable m_aaTable;
|
||||
};
|
||||
|
||||
static const size_t kMaxCachedPaletteTables = 16;
|
||||
static const size_t kMaxCachedToneTables = 16;
|
||||
|
||||
CachedPaletteTableEntry m_cachedPaletteTables[kMaxCachedPaletteTables];
|
||||
size_t m_numCachedPaletteTables;
|
||||
|
||||
CachedToneTableEntry m_cachedToneTables[kMaxCachedToneTables];
|
||||
size_t m_numCachedToneTables;
|
||||
|
||||
RGBAColor m_colors[kSize];
|
||||
AntiAliasTable m_whiteAATable;
|
||||
AntiAliasTable m_blackAATable;
|
||||
AntiAliasTable m_whiteToneAATable;
|
||||
AntiAliasTable m_blackToneAATable;
|
||||
|
||||
uint8_t m_lut[16 * 16 * 16];
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user