From 75ed3562d15657bd698bc6b0c6ccb10e1e53f0e6 Mon Sep 17 00:00:00 2001 From: Phillip Stephens Date: Wed, 16 Mar 2016 12:53:06 -0700 Subject: [PATCH 1/3] Initial CRasterFont implementations --- Runtime/CMakeLists.txt | 1 + Runtime/CPathFindArea.cpp | 16 +++++ Runtime/CPathFindArea.hpp | 84 +++++++++++++++++++++++ Runtime/GuiSys/CRasterFont.cpp | 117 +++++++++++++++++++++++++++++++++ Runtime/GuiSys/CRasterFont.hpp | 32 +++++++++ 5 files changed, 250 insertions(+) create mode 100644 Runtime/CPathFindArea.cpp create mode 100644 Runtime/CPathFindArea.hpp diff --git a/Runtime/CMakeLists.txt b/Runtime/CMakeLists.txt index 3946f4e50..5fb298d37 100644 --- a/Runtime/CMakeLists.txt +++ b/Runtime/CMakeLists.txt @@ -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 diff --git a/Runtime/CPathFindArea.cpp b/Runtime/CPathFindArea.cpp new file mode 100644 index 000000000..36839fd74 --- /dev/null +++ b/Runtime/CPathFindArea.cpp @@ -0,0 +1,16 @@ +#include "CPathFindArea.hpp" +#include "IVParamObj.hpp" +#include "CToken.hpp" + +namespace urde +{ +CPathFindArea::CPathFindArea(const std::unique_ptr&& buf, int len) +{ + x13c_data = buf.get(); +} + +std::unique_ptr FPathFindAreaFactory(const SObjectTag& /*tag*/, const std::unique_ptr& buf, const CVParamTransfer &xfer) +{ + return TToken::GetIObjObjectFor(std::unique_ptr(new CPathFindArea(std::move(buf), *reinterpret_cast(xfer.GetObj())))); +} +} diff --git a/Runtime/CPathFindArea.hpp b/Runtime/CPathFindArea.hpp new file mode 100644 index 000000000..245c856ff --- /dev/null +++ b/Runtime/CPathFindArea.hpp @@ -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 x40_region; + std::vector x90_regionData; +public: + CPFOpenList() + { + } +}; + +class CPathFindArea +{ + zeus::CVector3f x0_; + float xc_ = 0.f; + std::vector x10_; + bool x30_ = false; + std::vector x78_; + u8* x13c_data; + zeus::CTransform x188_; +public: + CPathFindArea(const std::unique_ptr&& buf, int len); +}; + + +std::unique_ptr FPathFindAreaFactory(const SObjectTag& /*tag*/, const std::unique_ptr& buf, const CVParamTransfer& xfer); +} + +#endif // CPATHFINDAREA_HPP diff --git a/Runtime/GuiSys/CRasterFont.cpp b/Runtime/GuiSys/CRasterFont.cpp index 1357ab752..1d8ca7112 100644 --- a/Runtime/GuiSys/CRasterFont.cpp +++ b/Runtime/GuiSys/CRasterFont.cpp @@ -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 FRasterFontFactory(const SObjectTag& tag, CInputStream& in, const CVParamTransfer& vparms) { return TToken::GetIObjObjectFor(std::make_unique(in, *(reinterpret_cast(vparms.GetObj())))); diff --git a/Runtime/GuiSys/CRasterFont.hpp b/Runtime/GuiSys/CRasterFont.hpp index 0f3cd9e97..a56955218 100644 --- a/Runtime/GuiSys/CRasterFont.hpp +++ b/Runtime/GuiSys/CRasterFont.hpp @@ -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> 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 FRasterFontFactory(const SObjectTag& tag, CInputStream& in, const CVParamTransfer& vparms); From 562824e386c332eef8a536f9ddbf3555960fdb96 Mon Sep 17 00:00:00 2001 From: Phillip Stephens Date: Wed, 16 Mar 2016 12:56:57 -0700 Subject: [PATCH 2/3] Fix function argument --- Runtime/GuiSys/CRasterFont.cpp | 2 +- Runtime/GuiSys/CRasterFont.hpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Runtime/GuiSys/CRasterFont.cpp b/Runtime/GuiSys/CRasterFont.cpp index 1d8ca7112..d15cc85b6 100644 --- a/Runtime/GuiSys/CRasterFont.cpp +++ b/Runtime/GuiSys/CRasterFont.cpp @@ -127,7 +127,7 @@ void CRasterFont::DrawSpace(const CDrawStringOptions& opts, int x, int y, int& x 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 +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; diff --git a/Runtime/GuiSys/CRasterFont.hpp b/Runtime/GuiSys/CRasterFont.hpp index a56955218..582da7284 100644 --- a/Runtime/GuiSys/CRasterFont.hpp +++ b/Runtime/GuiSys/CRasterFont.hpp @@ -150,7 +150,7 @@ public: 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, + 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) From 349defd67610cbaaf761b4ef7cfe116cef2f21a7 Mon Sep 17 00:00:00 2001 From: Phillip Stephens Date: Wed, 16 Mar 2016 13:39:07 -0700 Subject: [PATCH 3/3] Compile fixes --- Runtime/GuiSys/CRasterFont.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/Runtime/GuiSys/CRasterFont.cpp b/Runtime/GuiSys/CRasterFont.cpp index d15cc85b6..ac3906a46 100644 --- a/Runtime/GuiSys/CRasterFont.cpp +++ b/Runtime/GuiSys/CRasterFont.cpp @@ -81,10 +81,10 @@ void CRasterFont::SinglePassDrawString(const CDrawStringOptions& opts, int x, in return; const wchar_t* chr = str; - const CGlyph* prevGlyph = nullptr; + CGlyph* prevGlyph = nullptr; while (*chr == '\0') { - const CGlyph* glyph = GetGlyph(*chr); + CGlyph* glyph = GetGlyph(*chr); if (glyph) { if (opts.x0_ == 0) @@ -110,7 +110,7 @@ void CRasterFont::SinglePassDrawString(const CDrawStringOptions& opts, int x, in if (length == -1) continue; - if ((string - tmpString) >= length) + if ((string - chr) >= length) break; } @@ -154,12 +154,12 @@ void CRasterFont::GetSize(const CDrawStringOptions& opts, int& width, int& heigh width = 0; height = 0; - wchar_t* chr = str; + const wchar_t* chr = str; CGlyph* prevGlyph = nullptr; int prevWidth = 0; while (*chr != L'\0') { - const CGlyph* glyph = GetGlyph(*chr); + CGlyph* glyph = GetGlyph(*chr); if (glyph) { @@ -182,10 +182,10 @@ void CRasterFont::GetSize(const CDrawStringOptions& opts, int& width, int& heigh prevGlyph = glyph; chr++; - if (length == -1) + if (len == -1) continue; - if ((string - tmpString) >= length) + if ((string - chr) >= len) break; } }