CFontLoader: Make use of unsigned stream helpers
Same behavior, minus implicit sign conversions.
This commit is contained in:
parent
b559df4e0a
commit
80e4790384
|
@ -6,28 +6,28 @@ CFontLoader::CFontLoader() = default;
|
||||||
void CFontLoader::LoadFont(IInputStream& rFONT)
|
void CFontLoader::LoadFont(IInputStream& rFONT)
|
||||||
{
|
{
|
||||||
// If I seek past a value without reading it, then it's because I don't know what it is
|
// If I seek past a value without reading it, then it's because I don't know what it is
|
||||||
mpFont->mUnknown = rFONT.ReadLong();
|
mpFont->mUnknown = rFONT.ReadULong();
|
||||||
mpFont->mLineHeight = rFONT.ReadLong();
|
mpFont->mLineHeight = rFONT.ReadULong();
|
||||||
mpFont->mVerticalOffset = rFONT.ReadLong();
|
mpFont->mVerticalOffset = rFONT.ReadULong();
|
||||||
mpFont->mLineMargin = rFONT.ReadLong();
|
mpFont->mLineMargin = rFONT.ReadULong();
|
||||||
if (mVersion > EGame::PrimeDemo) rFONT.Seek(0x4, SEEK_CUR);
|
if (mVersion > EGame::PrimeDemo) rFONT.Seek(0x4, SEEK_CUR);
|
||||||
rFONT.Seek(0x2, SEEK_CUR);
|
rFONT.Seek(0x2, SEEK_CUR);
|
||||||
mpFont->mDefaultSize = rFONT.ReadLong();
|
mpFont->mDefaultSize = rFONT.ReadULong();
|
||||||
mpFont->mFontName = rFONT.ReadString();
|
mpFont->mFontName = rFONT.ReadString();
|
||||||
mpFont->mpFontTexture = gpResourceStore->LoadResource(CAssetID(rFONT, mVersion), EResourceType::Texture);
|
mpFont->mpFontTexture = gpResourceStore->LoadResource(CAssetID(rFONT, mVersion), EResourceType::Texture);
|
||||||
mpFont->mTextureFormat = rFONT.ReadLong();
|
mpFont->mTextureFormat = rFONT.ReadULong();
|
||||||
uint32 NumGlyphs = rFONT.ReadLong();
|
const uint32 NumGlyphs = rFONT.ReadULong();
|
||||||
mpFont->mGlyphs.reserve(NumGlyphs);
|
mpFont->mGlyphs.reserve(NumGlyphs);
|
||||||
|
|
||||||
for (uint32 iGlyph = 0; iGlyph < NumGlyphs; iGlyph++)
|
for (uint32 iGlyph = 0; iGlyph < NumGlyphs; iGlyph++)
|
||||||
{
|
{
|
||||||
CFont::SGlyph Glyph;
|
CFont::SGlyph Glyph;
|
||||||
Glyph.Character = rFONT.ReadShort();
|
Glyph.Character = rFONT.ReadUShort();
|
||||||
|
|
||||||
float TexCoordL = rFONT.ReadFloat();
|
const float TexCoordL = rFONT.ReadFloat();
|
||||||
float TexCoordU = rFONT.ReadFloat();
|
const float TexCoordU = rFONT.ReadFloat();
|
||||||
float TexCoordR = rFONT.ReadFloat();
|
const float TexCoordR = rFONT.ReadFloat();
|
||||||
float TexCoordD = rFONT.ReadFloat();
|
const float TexCoordD = rFONT.ReadFloat();
|
||||||
Glyph.TexCoords[0] = CVector2f(TexCoordL, TexCoordU); // Upper-left
|
Glyph.TexCoords[0] = CVector2f(TexCoordL, TexCoordU); // Upper-left
|
||||||
Glyph.TexCoords[1] = CVector2f(TexCoordR, TexCoordU); // Upper-right
|
Glyph.TexCoords[1] = CVector2f(TexCoordR, TexCoordU); // Upper-right
|
||||||
Glyph.TexCoords[2] = CVector2f(TexCoordL, TexCoordD); // Lower-left
|
Glyph.TexCoords[2] = CVector2f(TexCoordL, TexCoordD); // Lower-left
|
||||||
|
@ -39,35 +39,34 @@ void CFontLoader::LoadFont(IInputStream& rFONT)
|
||||||
Glyph.LeftPadding = rFONT.ReadLong();
|
Glyph.LeftPadding = rFONT.ReadLong();
|
||||||
Glyph.PrintAdvance = rFONT.ReadLong();
|
Glyph.PrintAdvance = rFONT.ReadLong();
|
||||||
Glyph.RightPadding = rFONT.ReadLong();
|
Glyph.RightPadding = rFONT.ReadLong();
|
||||||
Glyph.Width = rFONT.ReadLong();
|
Glyph.Width = rFONT.ReadULong();
|
||||||
Glyph.Height = rFONT.ReadLong();
|
Glyph.Height = rFONT.ReadULong();
|
||||||
Glyph.BaseOffset = rFONT.ReadLong();
|
Glyph.BaseOffset = rFONT.ReadULong();
|
||||||
Glyph.KerningIndex = rFONT.ReadLong();
|
Glyph.KerningIndex = rFONT.ReadULong();
|
||||||
}
|
}
|
||||||
else if (mVersion >= EGame::Echoes)
|
else if (mVersion >= EGame::Echoes)
|
||||||
{
|
{
|
||||||
Glyph.RGBAChannel = rFONT.ReadByte();
|
Glyph.RGBAChannel = rFONT.ReadUByte();
|
||||||
Glyph.LeftPadding = rFONT.ReadByte();
|
Glyph.LeftPadding = rFONT.ReadByte();
|
||||||
Glyph.PrintAdvance = rFONT.ReadByte();
|
Glyph.PrintAdvance = rFONT.ReadUByte();
|
||||||
Glyph.RightPadding = rFONT.ReadByte();
|
Glyph.RightPadding = rFONT.ReadByte();
|
||||||
Glyph.Width = rFONT.ReadByte();
|
Glyph.Width = rFONT.ReadUByte();
|
||||||
Glyph.Height = rFONT.ReadByte();
|
Glyph.Height = rFONT.ReadUByte();
|
||||||
Glyph.BaseOffset = rFONT.ReadByte();
|
Glyph.BaseOffset = rFONT.ReadUByte();
|
||||||
Glyph.KerningIndex = rFONT.ReadShort();
|
Glyph.KerningIndex = rFONT.ReadUShort();
|
||||||
}
|
}
|
||||||
mpFont->mGlyphs[Glyph.Character] = Glyph;
|
mpFont->mGlyphs.insert_or_assign(Glyph.Character, Glyph);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32 NumKerningPairs = rFONT.ReadLong();
|
const uint32 NumKerningPairs = rFONT.ReadULong();
|
||||||
mpFont->mKerningTable.reserve(NumKerningPairs);
|
mpFont->mKerningTable.reserve(NumKerningPairs);
|
||||||
|
|
||||||
for (uint32 iKern = 0; iKern < NumKerningPairs; iKern++)
|
for (uint32 iKern = 0; iKern < NumKerningPairs; iKern++)
|
||||||
{
|
{
|
||||||
CFont::SKerningPair Pair;
|
auto& Pair = mpFont->mKerningTable.emplace_back();
|
||||||
Pair.CharacterA = rFONT.ReadShort();
|
Pair.CharacterA = rFONT.ReadUShort();
|
||||||
Pair.CharacterB = rFONT.ReadShort();
|
Pair.CharacterB = rFONT.ReadUShort();
|
||||||
Pair.Adjust = rFONT.ReadLong();
|
Pair.Adjust = rFONT.ReadLong();
|
||||||
mpFont->mKerningTable.push_back(Pair);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -76,18 +75,18 @@ std::unique_ptr<CFont> CFontLoader::LoadFONT(IInputStream& rFONT, CResourceEntry
|
||||||
if (!rFONT.IsValid())
|
if (!rFONT.IsValid())
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
||||||
CFourCC Magic(rFONT);
|
const CFourCC Magic(rFONT);
|
||||||
if (Magic != FOURCC('FONT'))
|
if (Magic != FOURCC('FONT'))
|
||||||
{
|
{
|
||||||
errorf("%s: Invalid FONT magic: 0x%08X", *rFONT.GetSourceString(), Magic.ToLong());
|
errorf("%s: Invalid FONT magic: 0x%08X", *rFONT.GetSourceString(), Magic.ToLong());
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32 FileVersion = rFONT.ReadLong();
|
const uint32 FileVersion = rFONT.ReadULong();
|
||||||
EGame Version = GetFormatVersion(FileVersion);
|
const EGame Version = GetFormatVersion(FileVersion);
|
||||||
if (Version == EGame::Invalid)
|
if (Version == EGame::Invalid)
|
||||||
{
|
{
|
||||||
errorf("%s: Unsupported FONT version: %d", *rFONT.GetSourceString(), FileVersion);
|
errorf("%s: Unsupported FONT version: %u", *rFONT.GetSourceString(), FileVersion);
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue