From 70747e23d5d3dbcfcb0d0fc15845de48f20c8223 Mon Sep 17 00:00:00 2001 From: Phillip Stephens Date: Wed, 11 Dec 2019 10:55:19 -0800 Subject: [PATCH] Fix font rendering and world teleporter in MPT and PAL --- Runtime/Graphics/CTextureBoo.cpp | 4 +++- Runtime/GuiSys/CRasterFont.cpp | 4 ++-- Runtime/GuiSys/CRasterFont.hpp | 19 ++++++++++++++++--- Runtime/World/ScriptLoader.cpp | 7 ++++++- 4 files changed, 27 insertions(+), 7 deletions(-) diff --git a/Runtime/Graphics/CTextureBoo.cpp b/Runtime/Graphics/CTextureBoo.cpp index 1f640c191..931a497e6 100644 --- a/Runtime/Graphics/CTextureBoo.cpp +++ b/Runtime/Graphics/CTextureBoo.cpp @@ -867,7 +867,9 @@ const boo::ObjToken& CTexture::GetFontTexture(EFontType tp) { CFactoryFnReturn FTextureFactory(const urde::SObjectTag& tag, std::unique_ptr&& in, u32 len, const urde::CVParamTransfer& vparms, CObjectReference* selfRef) { u32 u32Owned = vparms.GetOwnedObj(); - const CTextureInfo* inf = g_TextureCache->GetTextureInfo(tag.id); + const CTextureInfo* inf = nullptr; + if (g_TextureCache) + inf = g_TextureCache->GetTextureInfo(tag.id); return TToken::GetIObjObjectFor( std::make_unique(std::move(in), len, u32Owned == SBIG('OTEX'), inf)); } diff --git a/Runtime/GuiSys/CRasterFont.cpp b/Runtime/GuiSys/CRasterFont.cpp index dbca8cc7f..891a08852 100644 --- a/Runtime/GuiSys/CRasterFont.cpp +++ b/Runtime/GuiSys/CRasterFont.cpp @@ -32,7 +32,7 @@ CRasterFont::CRasterFont(urde::CInputStream& in, urde::IObjectStore& store) { u32 txtrId = (version == 5 ? in.readUint64Big() : in.readUint32Big()); x30_fontInfo = CFontInfo(tmp1, tmp2, tmp3, tmp4, name.c_str()); x80_texture = store.GetObj({FOURCC('TXTR'), txtrId}); - x2c_mode = EColorType(in.readUint32Big()); + x2c_mode = CTexture::EFontType(in.readUint32Big()); u32 glyphCount = in.readUint32Big(); xc_glyphs.reserve(glyphCount); @@ -79,7 +79,7 @@ CRasterFont::CRasterFont(urde::CInputStream& in, urde::IObjectStore& store) { x1c_kerning.emplace_back(first, second, howMuch); } - if (magic == SBIG('FONT') && version <= 2) + if (magic == SBIG('FONT') && version <= 4) x0_initialized = true; } diff --git a/Runtime/GuiSys/CRasterFont.hpp b/Runtime/GuiSys/CRasterFont.hpp index 6d7c44b58..82db5d5d7 100644 --- a/Runtime/GuiSys/CRasterFont.hpp +++ b/Runtime/GuiSys/CRasterFont.hpp @@ -103,7 +103,7 @@ class CRasterFont { s32 x8_monoHeight = 16; std::vector> xc_glyphs; std::vector x1c_kerning; - EColorType x2c_mode = EColorType::Main; + CTexture::EFontType x2c_mode = CTexture::EFontType::OneLayer; CFontInfo x30_fontInfo; TLockedToken x80_texture; s32 x8c_baseline; @@ -125,7 +125,20 @@ public: s32 GetMonoWidth() const { return x4_monoWidth; } s32 GetMonoHeight() const { return x8_monoHeight; } - EColorType GetMode() const { return x2c_mode; } + EColorType GetMode() const { + switch(x2c_mode) { + case CTexture::EFontType::OneLayer: + case CTexture::EFontType::TwoLayers: + case CTexture::EFontType::FourLayers: + return EColorType::Main; + case CTexture::EFontType::OneLayerOutline: + case CTexture::EFontType::TwoLayersOutlines: + case CTexture::EFontType::TwoLayersOutlines2: + return EColorType::Outline; + default: + return EColorType::Main; + } + } s32 GetLineMargin() const { return x90_lineMargin; } s32 GetCarriageAdvance() const { return GetLineMargin() + GetMonoHeight(); } @@ -148,7 +161,7 @@ public: const CGlyph* GetGlyph(char16_t chr) const { return InternalGetGlyph(chr); } void GetSize(const CDrawStringOptions& opts, int& width, int& height, const char16_t* str, int len) const; const boo::ObjToken& GetTexture() { - return x80_texture->GetFontTexture(CTexture::EFontType(x2c_mode)); + return x80_texture->GetFontTexture(x2c_mode); } bool IsFinishedLoading() const; diff --git a/Runtime/World/ScriptLoader.cpp b/Runtime/World/ScriptLoader.cpp index ff7acdd62..e4998c4ca 100644 --- a/Runtime/World/ScriptLoader.cpp +++ b/Runtime/World/ScriptLoader.cpp @@ -2352,7 +2352,7 @@ CEntity* ScriptLoader::LoadVisorFlare(CStateManager& mgr, CInputStream& in, int CEntity* ScriptLoader::LoadWorldTeleporter(CStateManager& mgr, CInputStream& in, int propCount, const CEntityInfo& info) { - if (propCount < 4 || propCount > 21) { + if (propCount < 4 || propCount > 26) { Log.report(logvisor::Warning, fmt("Incorrect number of props for WorldTeleporter")); return nullptr; } @@ -2383,6 +2383,11 @@ CEntity* ScriptLoader::LoadWorldTeleporter(CStateManager& mgr, CInputStream& in, float charFadeInTime = (propCount < 19 ? 0.1f : in.readFloatBig()); float charsPerSecond = (propCount < 20 ? 16.f : in.readFloatBig()); float showDelay = (propCount < 21 ? 0.f : in.readFloatBig()); + std::string str1 = (propCount < 22 ? "" : in.readString()); + std::string str2 = (propCount < 23 ? "" : in.readString()); + /*float f1 =*/ (propCount < 24 ? 0.f : in.readFloatBig()); + /*float f2 =*/ (propCount < 25 ? 0.f : in.readFloatBig()); + /*float f3 =*/(propCount < 26 ? 0.f : in.readFloatBig()); if (showText) return new CScriptWorldTeleporter(mgr.AllocateUniqueId(), name, info, active, worldId, areaId, elevatorSound,