Initial CRasterFont implementations

This commit is contained in:
Phillip Stephens 2016-03-16 12:53:06 -07:00
parent b496ec643b
commit 75ed3562d1
5 changed files with 250 additions and 0 deletions

View File

@ -20,6 +20,7 @@ add_library(RuntimeCommon
CMemoryCardSys.hpp
IAllocator.hpp IAllocator.cpp
CGameAllocator.hpp CGameAllocator.cpp
CPathFindArea.hpp CPathFindArea.cpp
CBasics.hpp CBasicsPC.cpp
CIOWin.hpp
CIOWinManager.hpp CIOWinManager.cpp

16
Runtime/CPathFindArea.cpp Normal file
View File

@ -0,0 +1,16 @@
#include "CPathFindArea.hpp"
#include "IVParamObj.hpp"
#include "CToken.hpp"
namespace urde
{
CPathFindArea::CPathFindArea(const std::unique_ptr<u8[]>&& buf, int len)
{
x13c_data = buf.get();
}
std::unique_ptr<IObj> FPathFindAreaFactory(const SObjectTag& /*tag*/, const std::unique_ptr<u8[]>& buf, const CVParamTransfer &xfer)
{
return TToken<CPathFindArea>::GetIObjObjectFor(std::unique_ptr<CPathFindArea>(new CPathFindArea(std::move(buf), *reinterpret_cast<int*>(xfer.GetObj()))));
}
}

84
Runtime/CPathFindArea.hpp Normal file
View File

@ -0,0 +1,84 @@
#ifndef CPATHFINDAREA_HPP
#define CPATHFINDAREA_HPP
#include "IObj.hpp"
#include "zeus/CTransform.hpp"
#include "zeus/CAABox.hpp"
namespace urde
{
class CVParamTransfer;
class CPFRegion
{
friend class CPFOpenList;
u32 x0_ = 0;
u32 x4_ = 0;
u32 x8_ = 0;
u32 xc_ = 0;
u32 x10_ = 0;
float x14_ = 0.f;
zeus::CVector3f x18_;
u32 x24_ = 0;
zeus::CVector3f x28_;
zeus::CAABox x34_;
};
class CPFRegionData
{
friend class CPFOpenList;
float x0_ = 0.f;
zeus::CVector3f x4_;
s32 x10_ = -1;
zeus::CVector3f x14_;
s32 x20_ = 0;
s32 x24_ = 0;
s32 x28_ = 0;
s32 x2c_ = 0;
};
class CPFOpenList
{
friend class CPathFindArea;
u32 x0_ = 0;
u32 x4_ = 0;
u32 x8_ = 0;
u32 xc_ = 0;
u32 x10_ = 0;
u32 x14_ = 0;
u32 x18_ = 0;
u32 x1c_ = 0;
u32 x20_ = 0;
u32 x24_ = 0;
u32 x28_ = 0;
u32 x2c_ = 0;
u32 x30_ = 0;
u32 x34_ = 0;
u32 x38_ = 0;
u32 x3c_ = 0;
std::vector<CPFRegion> x40_region;
std::vector<CPFRegionData> x90_regionData;
public:
CPFOpenList()
{
}
};
class CPathFindArea
{
zeus::CVector3f x0_;
float xc_ = 0.f;
std::vector<zeus::CVector3f> x10_;
bool x30_ = false;
std::vector<CPFOpenList> x78_;
u8* x13c_data;
zeus::CTransform x188_;
public:
CPathFindArea(const std::unique_ptr<u8[]>&& buf, int len);
};
std::unique_ptr<IObj> FPathFindAreaFactory(const SObjectTag& /*tag*/, const std::unique_ptr<u8[]>& buf, const CVParamTransfer& xfer);
}
#endif // CPATHFINDAREA_HPP

View File

@ -73,6 +73,123 @@ CRasterFont::CRasterFont(urde::CInputStream& in, urde::IObjectStore& store)
}
}
void CRasterFont::SinglePassDrawString(const CDrawStringOptions& opts, int x, int y, int& xout, int& yout,
CTextRenderBuffer* renderBuf,
const wchar_t* str, s32 length) const
{
if (!x0_)
return;
const wchar_t* chr = str;
const CGlyph* prevGlyph = nullptr;
while (*chr == '\0')
{
const CGlyph* glyph = GetGlyph(*chr);
if (glyph)
{
if (opts.x0_ == 0)
{
x += glyph->GetA();
if (prevGlyph != 0)
x += KernLookup(x1c_kerning, prevGlyph->GetKernStart(), *chr);
int left = 0;
int top = 0;
if (renderBuf)
{
left += x;
top += glyph->GetBaseline() - y;
renderBuf->AddCharacter(zeus::CVector2i(left, top), *chr, opts.x10_);
}
x += glyph->GetC() + glyph->GetB();
}
}
prevGlyph = glyph;
chr++;
if (length == -1)
continue;
if ((string - tmpString) >= length)
break;
}
xout = x;
yout = y;
}
void CRasterFont::DrawSpace(const CDrawStringOptions& opts, int x, int y, int& xout, int& yout, int len) const
{
if (opts.x0_ != 0)
return;
xout = x + len;
yout = y;
}
void CRasterFont::DrawString(const CDrawStringOptions& opts, int x, int y, int xout, int& yout, CTextRenderBuffer* renderBuf, const wchar_t* str, int len) const
{
if (!x0_)
return;
if (renderBuf)
{
/* TODO: Implement this */
/* CGraphicsPalette pal = CGraphicsPalette::CGraphcisPalette(2, 4); */
/* zeus::CColor color = zeus::CColor(0.f, 0.f, 0.f, 0.f) */
/* tmp = color.ToRGB5A3(); */
/* tmp2 = opts.x8_.ToRGB5A3(); */
/* tmp3 = opts.xc_.ToRGB5A3(); */
/* tmp4 = zeus::CColor(0.f, 0.f, 0.f, 0.f); */
/* tmp5 = tmp4.ToRGBA5A3(); */
/* pal.UnLock(); */
/* renderBuf->AddPaletteChange(pal); */
}
SinglePassDrawString(opts, x, y, xout, yout, renderBuf, str, len);
}
void CRasterFont::GetSize(const CDrawStringOptions& opts, int& width, int& height, const wchar_t* str, int len) const
{
width = 0;
height = 0;
wchar_t* chr = str;
CGlyph* prevGlyph = nullptr;
int prevWidth = 0;
while (*chr != L'\0')
{
const CGlyph* glyph = GetGlyph(*chr);
if (glyph)
{
if (opts.x0_ == 0)
{
int advance = 0;
if (prevGlyph)
advance = KernLookup(x1c_kerning, prevGlyph->GetKernStart(), *chr);
s16 curWidth = prevWidth - (glyph->GetA() + glyph->GetB() + glyph->GetC() + advance);
s16 curHeight = glyph->GetBaseline() - (x8_monoHeight + glyph->GetCellHeight());
width = curWidth;
prevWidth = curWidth;
if (curHeight > height)
height = curHeight;
}
}
prevGlyph = glyph;
chr++;
if (length == -1)
continue;
if ((string - tmpString) >= length)
break;
}
}
std::unique_ptr<IObj> FRasterFontFactory(const SObjectTag& tag, CInputStream& in, const CVParamTransfer& vparms)
{
return TToken<CRasterFont>::GetIObjObjectFor(std::make_unique<CRasterFont>(in, *(reinterpret_cast<IObjectStore*>(vparms.GetObj()))));

View File

@ -3,13 +3,29 @@
#include "IOStreams.hpp"
#include "CToken.hpp"
#include "zeus/CVector2i.hpp"
namespace urde
{
class IObjectStore;
class CTexture;
/* TODO: Move these elsewhere */
struct CDrawStringOptions
{
s32 x0_;
u32 x10_;
};
class CTextRenderBuffer
{
public:
void AddCharacter(const zeus::CVector2i& pos, s16 chr, u32 unk)
{
}
};
/* NOTE: Is this a good place for CGlyph and CKernPair? */
class CGlyph
{
private:
@ -85,6 +101,7 @@ public:
class CRasterFont
{
bool x0_ = false;
s32 x4_monoWidth = 16;
s32 x8_monoHeight = 16;
std::vector<std::pair<wchar_t, CGlyph>> xc_glyphs;
@ -127,6 +144,21 @@ public:
return 0;
}
void SinglePassDrawString(const CDrawStringOptions&, int x, int y, int& xout, int& yout,
CTextRenderBuffer* renderBuf,
const wchar_t* str, s32 len) const;
void DrawSpace(const CDrawStringOptions& opts, int x, int y, int& xout, int& yout, int len) const;
void DrawString(const CDrawStringOptions& opts, int x, int y, int xout, int& yout,
CTextRenderBuffer* renderBuf,
const wchar_t* str, int len) const;
CGlyph* GetGlyph(wchar_t chr)
{
return InternalGetGlyph(chr);
}
void GetSize(const CDrawStringOptions& opts, int& width, int& height,
const wchar_t* str, int len) const;
};
std::unique_ptr<IObj> FRasterFontFactory(const SObjectTag& tag, CInputStream& in, const CVParamTransfer& vparms);