From 7b6f81d7ee56335bd959969c1eaa2e1c4c22910a Mon Sep 17 00:00:00 2001 From: Luke Street Date: Thu, 5 May 2022 02:01:53 -0400 Subject: [PATCH] Initial CMapArea / CMappableObject conversion --- Runtime/AutoMapper/CMapArea.cpp | 136 +++++++++++-------------- Runtime/AutoMapper/CMapArea.hpp | 19 +--- Runtime/AutoMapper/CMapWorld.cpp | 94 ++++++++--------- Runtime/AutoMapper/CMappableObject.cpp | 93 +++++++++-------- Runtime/AutoMapper/CMappableObject.hpp | 15 --- Runtime/Graphics/CGX.hpp | 8 +- Runtime/Graphics/CGraphics.cpp | 39 +++---- Runtime/Graphics/GX.hpp | 5 +- Runtime/Particle/CElementGen.cpp | 14 +-- 9 files changed, 200 insertions(+), 223 deletions(-) diff --git a/Runtime/AutoMapper/CMapArea.cpp b/Runtime/AutoMapper/CMapArea.cpp index 0b99daf0e..363410a0a 100644 --- a/Runtime/AutoMapper/CMapArea.cpp +++ b/Runtime/AutoMapper/CMapArea.cpp @@ -8,6 +8,7 @@ #include "Runtime/GameGlobalObjects.hpp" #include "Runtime/World/CWorld.hpp" #include "Runtime/CBasics.hpp" +#include "Runtime/Graphics/CGX.hpp" namespace metaforce { constexpr std::array MinesPostTransforms{{ @@ -71,7 +72,7 @@ CMapArea::CMapArea(CInputStream& in, u32 size) , x2c_vertexCount(in.ReadLong()) , x30_surfaceCount(in.ReadLong()) , x34_size(size - 52) { - x44_buf.reset(new u8[x34_size]); + x44_buf = std::make_unique(x34_size); in.ReadBytes(x44_buf.get(), x34_size); PostConstruct(); } @@ -106,44 +107,6 @@ void CMapArea::PostConstruct() { for (u32 i = 0, j = 0; i < x30_surfaceCount; ++i, j += 32) { m_surfaces.emplace_back(x40_surfaceStart + j).PostConstruct(x44_buf.get(), index); } - -// CGraphics::CommitResources([this, &index](boo::IGraphicsDataFactory::Context& ctx) { -// m_vbo = ctx.newStaticBuffer(boo::BufferUse::Vertex, m_verts.data(), 16, m_verts.size()); -// m_ibo = ctx.newStaticBuffer(boo::BufferUse::Index, index.data(), 4, index.size()); -// -// /* Only the map universe specifies Always; it draws a maximum of 1016 instances */ -// size_t instCount = (xc_visibilityMode == EVisMode::Always) ? 1024 : 1; -// -// for (u32 i = 0; i < x30_surfaceCount; ++i) { -// CMapAreaSurface& surf = m_surfaces[i]; -// surf.m_instances.reserve(instCount); -// for (u32 inst = 0; inst < instCount; ++inst) { -// CMapAreaSurface::Instance& instance = surf.m_instances.emplace_back(ctx, m_vbo, m_ibo); -// -// athena::io::MemoryReader r(surf.x1c_outlineOffset, INT_MAX); -// u32 outlineCount = r.ReadLong(); -// -// std::vector& linePrims = instance.m_linePrims; -// linePrims.reserve(outlineCount * 2); -// for (u32 j = 0; j < 2; ++j) { -// r.seek(4, athena::SeekOrigin::Begin); -// for (u32 k = 0; k < outlineCount; ++k) { -// const u32 count = r.ReadLong(); -// r.seek(count); -// r.seekAlign4(); -// linePrims.emplace_back(ctx, CLineRenderer::EPrimitiveMode::LineStrip, count, nullptr, false, false, true); -// } -// } -// } -// } -// -// for (u32 i = 0; i < x28_mappableObjCount; ++i) { -// CMappableObject& mapObj = m_mappableObjects[i]; -// if (CMappableObject::IsDoorType(mapObj.GetType())) -// mapObj.CreateDoorSurface(ctx); -// } -// return true; -// } BooTrace); } bool CMapArea::GetIsVisibleToAutoMapper(bool worldVis, bool areaVis) const { @@ -191,7 +154,7 @@ void CMapArea::CMapAreaSurface::PostConstruct(const u8* buf, std::vector& i x18_surfOffset = buf + reinterpret_cast(x18_surfOffset); x1c_outlineOffset = buf + reinterpret_cast(x1c_outlineOffset); - m_primStart = index.size(); +// m_primStart = index.size(); bool start = true; { CMemoryInStream r(x18_surfOffset, INT_MAX, CMemoryInStream::EOwnerShip::NotOwned); @@ -256,20 +219,20 @@ void CMapArea::CMapAreaSurface::PostConstruct(const u8* buf, std::vector& i } } } - m_primCount = index.size() - m_primStart; +// m_primCount = index.size() - m_primStart; } void CMapArea::CMapAreaSurface::Draw(const zeus::CVector3f* verts, const zeus::CColor& surfColor, const zeus::CColor& lineColor, float lineWidth, size_t instIdx) { - if (instIdx >= m_instances.size()) { - return; - } - - Instance& instance = m_instances[instIdx]; - - if (surfColor.a()) { - instance.m_surfacePrims.draw(surfColor, m_primStart, m_primCount); - } +// if (instIdx >= m_instances.size()) { +// return; +// } +// +// Instance& instance = m_instances[instIdx]; +// +// if (surfColor.a()) { +// instance.m_surfacePrims.draw(surfColor, m_primStart, m_primCount); +// } if (lineColor.a()) { bool draw2 = lineWidth > 1.f; @@ -278,37 +241,54 @@ void CMapArea::CMapAreaSurface::Draw(const zeus::CVector3f* verts, const zeus::C outlineCount = CBasics::SwapBytes(outlineCount); #endif - - std::vector& linePrims = instance.m_linePrims; - zeus::CColor color = lineColor; - if (draw2) - color.a() *= 0.5f; - float width = lineWidth; - - auto primIt = linePrims.begin(); - for (u32 j = 0; j <= u32(draw2); ++j) { - CMemoryInStream r(x1c_outlineOffset, INT_MAX, CMemoryInStream::EOwnerShip::NotOwned); - r.ReadLong(); - for (u32 i = 0; i < outlineCount; ++i) { - CLineRenderer& prim = *primIt++; - prim.Reset(); - u32 count = r.ReadLong(); - for (u32 v = 0; v < count; ++v) { - u8 idx = r.ReadUint8(); - prim.AddVertex(verts[idx], color, width); - } - - u32 pos = r.GetReadPosition(); - while (r.GetReadPosition() != ROUND_UP_4(pos)) { - r.ReadUint8(); - } - prim.Render(); - } - width -= 1.f; - } +// std::vector& linePrims = instance.m_linePrims; +// zeus::CColor color = lineColor; +// if (draw2) +// color.a() *= 0.5f; +// float width = lineWidth; +// +// auto primIt = linePrims.begin(); +// for (u32 j = 0; j <= u32(draw2); ++j) { +// CMemoryInStream r(x1c_outlineOffset, INT_MAX, CMemoryInStream::EOwnerShip::NotOwned); +// r.ReadLong(); +// for (u32 i = 0; i < outlineCount; ++i) { +// CLineRenderer& prim = *primIt++; +// prim.Reset(); +// u32 count = r.ReadLong(); +// for (u32 v = 0; v < count; ++v) { +// u8 idx = r.ReadUint8(); +// prim.AddVertex(verts[idx], color, width); +// } +// +// u32 pos = r.GetReadPosition(); +// while (r.GetReadPosition() != ROUND_UP_4(pos)) { +// r.ReadUint8(); +// } +// prim.Render(); +// } +// width -= 1.f; +// } } } +void CMapArea::CMapAreaSurface::SetupGXMaterial() { + constexpr std::array vtxDescList{ + GX::VtxDescList{GX::VA_POS, GX::INDEX8}, + GX::VtxDescList{}, + }; + CGX::SetVtxDescv(vtxDescList.data()); + CGX::SetNumChans(1); + CGX::SetNumTexGens(0); + CGX::SetNumTevStages(1); + CGX::SetChanCtrl(CGX::EChannelId::Channel0, false, GX::SRC_REG, GX::SRC_VTX, {}, GX::DF_NONE, GX::AF_NONE); + CGX::SetTevColorIn(GX::TEVSTAGE0, GX::CC_ZERO, GX::CC_ZERO, GX::CC_ZERO, GX::CC_KONST); + CGX::SetTevAlphaIn(GX::TEVSTAGE0, GX::CA_ZERO, GX::CA_ZERO, GX::CA_ZERO, GX::CA_KONST); + CGX::SetTevColorOp(GX::TEVSTAGE0, GX::TEV_ADD, GX::TB_ZERO, GX::CS_SCALE_1, true, GX::TEVPREV); + CGX::SetTevAlphaOp(GX::TEVSTAGE0, GX::TEV_ADD, GX::TB_ZERO, GX::CS_SCALE_1, true, GX::TEVPREV); + CGX::SetTevKColorSel(GX::TEVSTAGE0, GX::TEV_KCSEL_K0); + CGX::SetTevKAlphaSel(GX::TEVSTAGE0, GX::TEV_KASEL_K0_A); +} + CFactoryFnReturn FMapAreaFactory(const SObjectTag& objTag, CInputStream& in, const CVParamTransfer&, CObjectReference*) { u32 size = g_ResFactory->ResourceSize(objTag); diff --git a/Runtime/AutoMapper/CMapArea.hpp b/Runtime/AutoMapper/CMapArea.hpp index 703b2da15..341ef241d 100644 --- a/Runtime/AutoMapper/CMapArea.hpp +++ b/Runtime/AutoMapper/CMapArea.hpp @@ -6,7 +6,6 @@ #include "Runtime/AutoMapper/CMappableObject.hpp" #include "Runtime/CResFactory.hpp" #include "Runtime/Graphics/CLineRenderer.hpp" -#include "Runtime/Graphics/Shaders/CMapSurfaceShader.hpp" #include "Runtime/RetroTypes.hpp" #include @@ -22,18 +21,6 @@ public: zeus::CVector3f xc_centroid; const u8* x18_surfOffset; const u8* x1c_outlineOffset; - u32 m_primStart; - u32 m_primCount; - struct Instance { - CMapSurfaceShader m_surfacePrims; - std::vector m_linePrims; - Instance(aurora::ArrayRef vbo, - aurora::ArrayRef ibo) - : m_surfacePrims(vbo, ibo) {} - Instance(Instance&&) = default; - Instance& operator=(Instance&&) = default; - }; - std::vector m_instances; public: explicit CMapAreaSurface(const void* surfBuf); @@ -43,6 +30,8 @@ public: float lineWidth, size_t instIdx = 0); const zeus::CVector3f& GetNormal() const { return x0_normal; } const zeus::CVector3f& GetCenterPosition() const { return xc_centroid; } + + static void SetupGXMaterial(); }; enum class EVisMode { Always, MapStationOrVisit, Visit, Never }; @@ -62,9 +51,7 @@ private: std::vector m_verts; u8* x40_surfaceStart; std::vector m_surfaces; - std::unique_ptr x44_buf; -// boo::ObjToken m_vbo; -// boo::ObjToken m_ibo; + std::unique_ptr x44_buf; // was u8* public: explicit CMapArea(CInputStream& in, u32 size); diff --git a/Runtime/AutoMapper/CMapWorld.cpp b/Runtime/AutoMapper/CMapWorld.cpp index 612e15fd0..59171be2c 100644 --- a/Runtime/AutoMapper/CMapWorld.cpp +++ b/Runtime/AutoMapper/CMapWorld.cpp @@ -8,6 +8,7 @@ #include "Runtime/GameGlobalObjects.hpp" #include "Runtime/AutoMapper/CMapWorldInfo.hpp" #include "Runtime/World/CWorld.hpp" +#include "Runtime/Graphics/CCubeRenderer.hpp" namespace metaforce { namespace { @@ -460,8 +461,8 @@ bool CMapWorld::IsMapAreaValid(const IWorld& wld, int areaIdx, bool checkLoad) c void CMapWorld::DrawAreas(const CMapWorldDrawParms& parms, int selArea, const std::vector& bfsInfos, bool inMapScreen) { - // Alpha blend - // Line width 1 + g_Renderer->SetBlendMode_AlphaBlended(); + CGraphics::SetLineWidth(1.f, ERglTexOffset::One); int surfCount = 0; int objCount = 0; @@ -485,6 +486,7 @@ void CMapWorld::DrawAreas(const CMapWorldDrawParms& parms, int selArea, const st float surfDepth = bfsInfo.GetSurfaceDrawDepth(); float outlineDepth = bfsInfo.GetOutlineDrawDepth(); + // TODO double check these if (surfDepth >= 1.f) surfDepth = 1.f; else if (surfDepth < 0.f) @@ -588,52 +590,52 @@ void CMapWorld::DrawAreas(const CMapWorldDrawParms& parms, int selArea, const st u32 lastAreaIdx = UINT32_MAX; CMapObjectSortInfo::EObjectCode lastType = CMapObjectSortInfo::EObjectCode::Invalid; - for (const CMapObjectSortInfo& info : sortInfos) { - CMapArea* mapa = GetMapArea(info.GetAreaIndex()); - zeus::CTransform areaPostXf = mapa->GetAreaPostTransform(parms.GetWorld(), info.GetAreaIndex()); - if (info.GetObjectCode() == CMapObjectSortInfo::EObjectCode::Surface) { - CMapArea::CMapAreaSurface& surf = mapa->GetSurface(info.GetLocalObjectIndex()); - zeus::CColor color( - std::max(0.f, (-parms.GetCameraTransform().basis[1]).dot(areaPostXf.rotate(surf.GetNormal()))) * - g_tweakAutoMapper->GetMapSurfaceNormColorLinear() + - g_tweakAutoMapper->GetMapSurfaceNormColorConstant()); - color *= info.GetSurfaceColor(); - if (lastAreaIdx != info.GetAreaIndex() || lastType != CMapObjectSortInfo::EObjectCode::Surface) { - CGraphics::SetModelMatrix(parms.GetPlaneProjectionTransform() * areaPostXf); - } - surf.Draw(mapa->GetVertices(), color, info.GetOutlineColor(), parms.GetOutlineWidthScale()); + if (!sortInfos.empty()) { + for (const CMapObjectSortInfo& info : sortInfos) { + CMapArea::CMapAreaSurface::SetupGXMaterial(); - lastAreaIdx = info.GetAreaIndex(); - lastType = info.GetObjectCode(); - } - } - for (const CMapObjectSortInfo& info : sortInfos) { - CMapArea* mapa = GetMapArea(info.GetAreaIndex()); - if (info.GetObjectCode() == CMapObjectSortInfo::EObjectCode::Door || - info.GetObjectCode() == CMapObjectSortInfo::EObjectCode::Object) { - CMappableObject& mapObj = mapa->GetMappableObject(info.GetLocalObjectIndex()); - const zeus::CTransform objXf = - zeus::CTransform::Translate(CMapArea::GetAreaPostTranslate(parms.GetWorld(), info.GetAreaIndex())) * - mapObj.GetTransform(); - if (info.GetObjectCode() == CMapObjectSortInfo::EObjectCode::Door) { - CGraphics::SetModelMatrix(parms.GetPlaneProjectionTransform() * objXf); - } else { - CGraphics::SetModelMatrix( - parms.GetPlaneProjectionTransform() * objXf * - zeus::CTransform(parms.GetCameraTransform().buildMatrix3f() * zeus::CMatrix3f(parms.GetObjectScale()))); + CMapArea* mapa = GetMapArea(info.GetAreaIndex()); + zeus::CTransform areaPostXf = mapa->GetAreaPostTransform(parms.GetWorld(), info.GetAreaIndex()); + if (info.GetObjectCode() == CMapObjectSortInfo::EObjectCode::Surface) { + CMapArea::CMapAreaSurface& surf = mapa->GetSurface(info.GetLocalObjectIndex()); + zeus::CColor color( + std::max(0.f, (-parms.GetCameraTransform().basis[1]).dot(areaPostXf.rotate(surf.GetNormal()))) * + g_tweakAutoMapper->GetMapSurfaceNormColorLinear() + + g_tweakAutoMapper->GetMapSurfaceNormColorConstant()); + color *= info.GetSurfaceColor(); + if (lastAreaIdx != info.GetAreaIndex() || lastType != CMapObjectSortInfo::EObjectCode::Surface) { + CGraphics::SetModelMatrix(parms.GetPlaneProjectionTransform() * areaPostXf); + } + surf.Draw(mapa->GetVertices(), color, info.GetOutlineColor(), parms.GetOutlineWidthScale()); + + lastAreaIdx = info.GetAreaIndex(); + lastType = info.GetObjectCode(); + } else if (info.GetObjectCode() == CMapObjectSortInfo::EObjectCode::Door || + info.GetObjectCode() == CMapObjectSortInfo::EObjectCode::Object) { + CMappableObject& mapObj = mapa->GetMappableObject(info.GetLocalObjectIndex()); + const zeus::CTransform objXf = + zeus::CTransform::Translate(CMapArea::GetAreaPostTranslate(parms.GetWorld(), info.GetAreaIndex())) * + mapObj.GetTransform(); + if (info.GetObjectCode() == CMapObjectSortInfo::EObjectCode::Door) { + CGraphics::SetModelMatrix(parms.GetPlaneProjectionTransform() * objXf); + } else { + CGraphics::SetModelMatrix( + parms.GetPlaneProjectionTransform() * objXf * + zeus::CTransform(parms.GetCameraTransform().buildMatrix3f() * zeus::CMatrix3f(parms.GetObjectScale()))); + } + mapObj.Draw(selArea, mwInfo, parms.GetAlpha(), lastType != info.GetObjectCode()); + lastType = info.GetObjectCode(); + } else if (info.GetObjectCode() == CMapObjectSortInfo::EObjectCode::DoorSurface) { + CMappableObject& mapObj = mapa->GetMappableObject(info.GetLocalObjectIndex() / 6); + const zeus::CTransform objXf = + parms.GetPlaneProjectionTransform() * + zeus::CTransform::Translate(CMapArea::GetAreaPostTranslate(parms.GetWorld(), info.GetAreaIndex())) * + mapObj.GetTransform(); + CGraphics::SetModelMatrix(objXf); + mapObj.DrawDoorSurface(selArea, mwInfo, parms.GetAlpha(), info.GetLocalObjectIndex() % 6, + lastType != info.GetObjectCode()); + lastType = info.GetObjectCode(); } - mapObj.Draw(selArea, mwInfo, parms.GetAlpha(), lastType != info.GetObjectCode()); - lastType = info.GetObjectCode(); - } else if (info.GetObjectCode() == CMapObjectSortInfo::EObjectCode::DoorSurface) { - CMappableObject& mapObj = mapa->GetMappableObject(info.GetLocalObjectIndex() / 6); - const zeus::CTransform objXf = - parms.GetPlaneProjectionTransform() * - zeus::CTransform::Translate(CMapArea::GetAreaPostTranslate(parms.GetWorld(), info.GetAreaIndex())) * - mapObj.GetTransform(); - CGraphics::SetModelMatrix(objXf); - mapObj.DrawDoorSurface(selArea, mwInfo, parms.GetAlpha(), info.GetLocalObjectIndex() % 6, - lastType != info.GetObjectCode()); - lastType = info.GetObjectCode(); } } } diff --git a/Runtime/AutoMapper/CMappableObject.cpp b/Runtime/AutoMapper/CMappableObject.cpp index 1f8e9dc57..b6a62f90d 100644 --- a/Runtime/AutoMapper/CMappableObject.cpp +++ b/Runtime/AutoMapper/CMappableObject.cpp @@ -6,6 +6,7 @@ #include "Runtime/Camera/CCameraFilter.hpp" #include "Runtime/GameGlobalObjects.hpp" #include "Runtime/Graphics/CTexture.hpp" +#include "Runtime/Graphics/CGX.hpp" namespace metaforce { std::array CMappableObject::skDoorVerts{}; @@ -112,18 +113,28 @@ void CMappableObject::Draw(int curArea, const CMapWorldInfo& mwInfo, float alpha SCOPED_GRAPHICS_DEBUG_GROUP("CMappableObject::Draw", zeus::skCyan); if (IsDoorType(x0_type)) { std::pair colors = GetDoorColors(curArea, mwInfo, alpha); - if (m_doorSurface) // TODO - for (int s = 0; s < 6; ++s) { - DoorSurface& ds = *m_doorSurface; - ds.m_surface.draw(colors.first, s * 4, 4); - CLineRenderer& line = ds.m_outline; - const u16* baseIdx = &skDoorIndices[s * 4]; - line.Reset(); - line.AddVertex(skDoorVerts[baseIdx[0]], colors.second, 1.f); - line.AddVertex(skDoorVerts[baseIdx[1]], colors.second, 1.f); - line.AddVertex(skDoorVerts[baseIdx[3]], colors.second, 1.f); - line.AddVertex(skDoorVerts[baseIdx[2]], colors.second, 1.f); - line.Render(); + if (needsVtxLoad) { + // TODO CGX::SetArray(GX::VA_POS, skDoorVerts); + } + for (int i = 0; i < 6; ++i) { + int baseVtx = i * 4; + + CGX::SetTevKColor(GX::KCOLOR0, colors.first); + CGX::Begin(GX::TRIANGLESTRIP, GX::VTXFMT0, 4); + GXPosition1x16(skDoorIndices[baseVtx + 0]); + GXPosition1x16(skDoorIndices[baseVtx + 1]); + GXPosition1x16(skDoorIndices[baseVtx + 2]); + GXPosition1x16(skDoorIndices[baseVtx + 3]); + CGX::End(); + +// CGX::SetTevKColor(GX::KCOLOR0, colors.second); +// CGX::Begin(GX::LINESTRIP, GX::VTXFMT0, 5); +// GXPosition1x16(skDoorIndices[i + 0]); +// GXPosition1x16(skDoorIndices[i + 1]); +// GXPosition1x16(skDoorIndices[i + 3]); +// GXPosition1x16(skDoorIndices[i + 4]); +// GXPosition1x16(skDoorIndices[i + 2]); +// CGX::End(); } } else { CAssetId iconRes; @@ -167,33 +178,35 @@ void CMappableObject::Draw(int curArea, const CMapWorldInfo& mwInfo, float alpha iconColor.a() *= alpha; TLockedToken tex = g_SimplePool->GetObj(SObjectTag{FOURCC('TXTR'), iconRes}); - if (!m_texQuadFilter || m_texQuadFilter->GetTex().GetObj() != tex.GetObj()) { - //m_texQuadFilter.emplace(EFilterType::Add, tex, CTexturedQuadFilter::ZTest::GEqual); - } - - constexpr std::array verts{{ - {{-2.6f, 0.f, 2.6f}, {0.f, 1.f}}, - {{-2.6f, 0.f, -2.6f}, {0.f, 0.f}}, - {{2.6f, 0.f, 2.6f}, {1.f, 1.f}}, - {{2.6f, 0.f, -2.6f}, {1.f, 0.f}}, - }}; - //m_texQuadFilter->drawVerts(iconColor, verts); + tex->Load(GX::TEXMAP0, EClampMode::Repeat); + CGraphics::SetTevOp(ERglTevStage::Stage0, CTevCombiners::sTevPass805a5ebc); + CGraphics::StreamBegin(GX::TRIANGLESTRIP); + CGraphics::StreamColor(iconColor); + CGraphics::StreamTexcoord(0.f, 1.f); + CGraphics::StreamVertex(-2.6f, 0.f, 2.6f); + CGraphics::StreamTexcoord(0.f, 0.f); + CGraphics::StreamVertex(-2.6f, 0.f, -2.6f); + CGraphics::StreamTexcoord(1.f, 1.f); + CGraphics::StreamVertex(2.6f, 0.f, 2.6f); + CGraphics::StreamTexcoord(1.f, 0.f); + CGraphics::StreamVertex(2.6f, 0.f, -2.6f); + CGraphics::StreamEnd(); } } void CMappableObject::DrawDoorSurface(int curArea, const CMapWorldInfo& mwInfo, float alpha, int surfIdx, bool needsVtxLoad) { std::pair colors = GetDoorColors(curArea, mwInfo, alpha); - DoorSurface& ds = *m_doorSurface; - ds.m_surface.draw(colors.first, surfIdx * 4, 4); - CLineRenderer& line = ds.m_outline; - const u16* baseIdx = &skDoorIndices[surfIdx * 4]; - line.Reset(); - line.AddVertex(skDoorVerts[baseIdx[0]], colors.second, 1.f); - line.AddVertex(skDoorVerts[baseIdx[1]], colors.second, 1.f); - line.AddVertex(skDoorVerts[baseIdx[3]], colors.second, 1.f); - line.AddVertex(skDoorVerts[baseIdx[2]], colors.second, 1.f); - line.Render(); +// DoorSurface& ds = *m_doorSurface; +// ds.m_surface.draw(colors.first, surfIdx * 4, 4); +// CLineRenderer& line = ds.m_outline; +// const u16* baseIdx = &skDoorIndices[surfIdx * 4]; +// line.Reset(); +// line.AddVertex(skDoorVerts[baseIdx[0]], colors.second, 1.f); +// line.AddVertex(skDoorVerts[baseIdx[1]], colors.second, 1.f); +// line.AddVertex(skDoorVerts[baseIdx[3]], colors.second, 1.f); +// line.AddVertex(skDoorVerts[baseIdx[2]], colors.second, 1.f); +// line.Render(); } zeus::CVector3f CMappableObject::BuildSurfaceCenterPoint(int surfIdx) const { @@ -252,15 +265,15 @@ void CMappableObject::ReadAutoMapperTweaks(const ITweakAutoMapper& tweaks) { doorVerts[6].assign(.2f * -centerF[2], centerF[1], 0.f); doorVerts[7].assign(.2f * -centerF[2], centerF[1], 2.f * centerF[0]); -// CGraphics::CommitResources([](boo::IGraphicsDataFactory::Context& ctx) { -// g_doorVbo = ctx.newStaticBuffer(boo::BufferUse::Vertex, skDoorVerts.data(), 16, skDoorVerts.size()); -// g_doorIbo = ctx.newStaticBuffer(boo::BufferUse::Index, DoorIndices.data(), 4, DoorIndices.size()); -// return true; -// } BooTrace); + // CGraphics::CommitResources([](boo::IGraphicsDataFactory::Context& ctx) { + // g_doorVbo = ctx.newStaticBuffer(boo::BufferUse::Vertex, skDoorVerts.data(), 16, skDoorVerts.size()); + // g_doorIbo = ctx.newStaticBuffer(boo::BufferUse::Index, DoorIndices.data(), 4, DoorIndices.size()); + // return true; + // } BooTrace); } void CMappableObject::Shutdown() { -// g_doorVbo.reset(); -// g_doorIbo.reset(); + // g_doorVbo.reset(); + // g_doorIbo.reset(); } } // namespace metaforce diff --git a/Runtime/AutoMapper/CMappableObject.hpp b/Runtime/AutoMapper/CMappableObject.hpp index 39b2e4517..87958b6a0 100644 --- a/Runtime/AutoMapper/CMappableObject.hpp +++ b/Runtime/AutoMapper/CMappableObject.hpp @@ -5,9 +5,6 @@ #include #include "Runtime/GameGlobalObjects.hpp" -#include "Runtime/Graphics/CLineRenderer.hpp" -#include "Runtime/Graphics/Shaders/CMapSurfaceShader.hpp" -#include "Runtime/Graphics/Shaders/CTexturedQuadFilter.hpp" #include "Runtime/RetroTypes.hpp" #include @@ -59,16 +56,6 @@ private: u32 xc_; zeus::CTransform x10_transform; - struct DoorSurface { - CMapSurfaceShader m_surface; - CLineRenderer m_outline; - explicit DoorSurface() - : m_surface(skDoorVerts, skDoorIndices) - , m_outline(CLineRenderer::EPrimitiveMode::LineLoop, 5, {}, false, false, true) {} - }; - std::optional m_doorSurface; - std::optional m_texQuadFilter; - zeus::CTransform AdjustTransformForType() const; std::pair GetDoorColors(int idx, const CMapWorldInfo& mwInfo, float alpha) const; @@ -85,10 +72,8 @@ public: bool IsDoorConnectedToVisitedArea(const CStateManager&) const; bool IsVisibleToAutoMapper(bool worldVis, const CMapWorldInfo& mwInfo) const; bool GetIsSeen() const; - void CreateDoorSurface() { m_doorSurface.emplace(); } static void ReadAutoMapperTweaks(const ITweakAutoMapper&); - static bool GetTweakIsMapVisibilityCheat(); static bool IsDoorType(EMappableObjectType type) { return type >= EMappableObjectType::BlueDoor && type <= EMappableObjectType::PlasmaDoorFloor2; } diff --git a/Runtime/Graphics/CGX.hpp b/Runtime/Graphics/CGX.hpp index 69fc6d0fa..7f1255ba7 100644 --- a/Runtime/Graphics/CGX.hpp +++ b/Runtime/Graphics/CGX.hpp @@ -197,7 +197,13 @@ static inline void SetFog(GX::FogType type, float startZ, float endZ, float near void SetIndTexMtxSTPointFive(GX::IndTexMtxID id, s8 scaleExp) noexcept; -void SetLineWidth(u8 width, GX::TexOffset offset) noexcept; +static inline void SetLineWidth(u8 width, GX::TexOffset offset) noexcept { + u32 flags = u32(width) | (offset & 0xFF) << 8; + if (flags != sGXState.x54_lineWidthAndOffset) { + sGXState.x54_lineWidthAndOffset = flags; + GXSetLineWidth(width, offset); + } +} static inline void SetNumChans(u8 num) noexcept { sGXState.x4c_dirtyChans = 7; // TODO diff --git a/Runtime/Graphics/CGraphics.cpp b/Runtime/Graphics/CGraphics.cpp index a56c889ef..07c3c9e0e 100644 --- a/Runtime/Graphics/CGraphics.cpp +++ b/Runtime/Graphics/CGraphics.cpp @@ -704,25 +704,26 @@ void CGraphics::InitGraphicsDefaults() { } void CGraphics::SetDefaultVtxAttrFmt() { - // Unneeded, all attributes are expected to be full floats - // Left here for reference + GXSetVtxAttrFmt(GX::VTXFMT0, GX::VA_POS, GX::POS_XYZ, GX::F32, 0); + GXSetVtxAttrFmt(GX::VTXFMT1, GX::VA_POS, GX::POS_XYZ, GX::F32, 0); + GXSetVtxAttrFmt(GX::VTXFMT2, GX::VA_POS, GX::POS_XYZ, GX::F32, 0); + GXSetVtxAttrFmt(GX::VTXFMT0, GX::VA_NRM, GX::NRM_XYZ, GX::F32, 0); + GXSetVtxAttrFmt(GX::VTXFMT1, GX::VA_NRM, GX::NRM_XYZ, GX::S16, 14); + GXSetVtxAttrFmt(GX::VTXFMT2, GX::VA_NRM, GX::NRM_XYZ, GX::S16, 14); + GXSetVtxAttrFmt(GX::VTXFMT0, GX::VA_CLR0, GX::CLR_RGBA, GX::RGBA8, 0); + GXSetVtxAttrFmt(GX::VTXFMT1, GX::VA_CLR0, GX::CLR_RGBA, GX::RGBA8, 0); + GXSetVtxAttrFmt(GX::VTXFMT2, GX::VA_CLR0, GX::CLR_RGBA, GX::RGBA8, 0); + GXSetVtxAttrFmt(GX::VTXFMT0, GX::VA_TEX0, GX::TEX_ST, GX::F32, 0); + GXSetVtxAttrFmt(GX::VTXFMT1, GX::VA_TEX0, GX::TEX_ST, GX::F32, 0); + GXSetVtxAttrFmt(GX::VTXFMT2, GX::VA_TEX0, GX::TEX_ST, GX::U16, 15); + for (GX::Attr attr = GX::VA_TEX1; attr <= GX::VA_TEX7; attr = GX::Attr(attr + 1)) { + GXSetVtxAttrFmt(GX::VTXFMT0, attr, GX::TEX_ST, GX::F32, 0); + GXSetVtxAttrFmt(GX::VTXFMT1, attr, GX::TEX_ST, GX::F32, 0); + GXSetVtxAttrFmt(GX::VTXFMT2, attr, GX::TEX_ST, GX::F32, 0); + } +} - // GXSetVtxAttrFmt(GX::VTXFMT0, GX::VA_POS, GX::POS_XYZ, GX::F32, 0); - // GXSetVtxAttrFmt(GX::VTXFMT1, GX::VA_POS, GX::POS_XYZ, GX::F32, 0); - // GXSetVtxAttrFmt(GX::VTXFMT2, GX::VA_POS, GX::POS_XYZ, GX::F32, 0); - // GXSetVtxAttrFmt(GX::VTXFMT0, GX::VA_NRM, GX::NRM_XYZ, GX::F32, 0); - // GXSetVtxAttrFmt(GX::VTXFMT1, GX::VA_NRM, GX::NRM_XYZ, GX::S16, 14); - // GXSetVtxAttrFmt(GX::VTXFMT2, GX::VA_NRM, GX::NRM_XYZ, GX::S16, 14); - // GXSetVtxAttrFmt(GX::VTXFMT0, GX::VA_CLR0, GX::CLR_RGBA, GX::RGBA8, 0); - // GXSetVtxAttrFmt(GX::VTXFMT1, GX::VA_CLR0, GX::CLR_RGBA, GX::RGBA8, 0); - // GXSetVtxAttrFmt(GX::VTXFMT2, GX::VA_CLR0, GX::CLR_RGBA, GX::RGBA8, 0); - // GXSetVtxAttrFmt(GX::VTXFMT0, GX::VA_TEX0, GX::TEX_ST, GX::F32, 0); - // GXSetVtxAttrFmt(GX::VTXFMT1, GX::VA_TEX0, GX::TEX_ST, GX::F32, 0); - // GXSetVtxAttrFmt(GX::VTXFMT2, GX::VA_TEX0, GX::TEX_ST, GX::U16, 15); - // for (GX::Attr attr = GX::VA_TEX1; attr <= GX::VA_TEX7; attr = GX::Attr(attr + 1)) { - // GXSetVtxAttrFmt(GX::VTXFMT0, attr, GX::TEX_ST, GX::F32, 0); - // GXSetVtxAttrFmt(GX::VTXFMT1, attr, GX::TEX_ST, GX::F32, 0); - // GXSetVtxAttrFmt(GX::VTXFMT2, attr, GX::TEX_ST, GX::F32, 0); - // } +void CGraphics::SetLineWidth(float width, ERglTexOffset offs) { + CGX::SetLineWidth(u8(width * 6.f), GX::TexOffset(offs)); } } // namespace metaforce diff --git a/Runtime/Graphics/GX.hpp b/Runtime/Graphics/GX.hpp index aadc0f653..e519d23ed 100644 --- a/Runtime/Graphics/GX.hpp +++ b/Runtime/Graphics/GX.hpp @@ -742,7 +742,8 @@ void GXSetProjection(const zeus::CMatrix4f& mtx, GX::ProjectionType type) noexce void GXSetViewport(float left, float top, float width, float height, float nearZ, float farZ) noexcept; void GXSetScissor(u32 left, u32 top, u32 width, u32 height) noexcept; // Unneeded, all attributes are expected to be full floats -// void GXSetVtxAttrFmt(GX::VtxFmt vtxfmt, GX::Attr attr, GX::CompCnt cnt, GX::CompType type, u8 frac) noexcept; +static inline void GXSetVtxAttrFmt(GX::VtxFmt vtxfmt, GX::Attr attr, GX::CompCnt cnt, GX::CompType type, + u8 frac) noexcept {} // Streaming void GXBegin(GX::Primitive primitive, GX::VtxFmt vtxFmt, u16 nVerts) noexcept; void GXMatrixIndex1u8(u8 idx) noexcept; @@ -754,8 +755,10 @@ void GXColor4f32(const zeus::CColor& color) noexcept; static inline void GXColor4f32(float r, float g, float b, float a) noexcept { GXColor4f32({r, g, b, a}); } void GXTexCoord2f32(const zeus::CVector2f& uv) noexcept; static inline void GXTexCoord2f32(float u, float v) noexcept { GXTexCoord2f32({u, v}); } +void GXPosition1x16(u16 index) noexcept; void GXEnd() noexcept; // End streaming void GXSetTevSwapModeTable(GX::TevSwapSel id, GX::TevColorChan red, GX::TevColorChan green, GX::TevColorChan blue, GX::TevColorChan alpha) noexcept; void GXSetTevSwapMode(GX::TevStageID stage, GX::TevSwapSel rasSel, GX::TevSwapSel texSel) noexcept; +void GXSetLineWidth(u8 width, GX::TexOffset texOffset) noexcept; diff --git a/Runtime/Particle/CElementGen.cpp b/Runtime/Particle/CElementGen.cpp index 4b9f0ce8b..c940d1eae 100644 --- a/Runtime/Particle/CElementGen.cpp +++ b/Runtime/Particle/CElementGen.cpp @@ -1324,13 +1324,13 @@ void CElementGen::RenderParticles() { CGX::SetTevOrder(GX::TEVSTAGE0, GX::TEXCOORD0, GX::TEXMAP0, GX::COLOR0A0); CGX::SetChanCtrl(CGX::EChannelId::Channel0, false, GX::SRC_REG, GX::SRC_VTX, {}, GX::DF_NONE, GX::AF_NONE); CGX::SetTexCoordGen(GX::TEXCOORD0, GX::TG_MTX2x4, GX::TG_TEX0, GX::IDENTITY, false, GX::PTIDENTITY); - // GXSetVtxAttrFmt(GX::VTXFMT6, GX::VA_POS, GX::POS_XYZ, GX::F32, 0); - // GXSetVtxAttrFmt(GX::VTXFMT6, GX::VA_CLR0, GX::CLR_RGBA, GX::RGBA8, 0); - // if (constUVs) { - // GXSetVtxAttrFmt(GX::VTXFMT6, GX::VA_TEX0, GX::TEX_ST, GX::RGBA8, 1); - // } else { - // GXSetVtxAttrFmt(GX::VTXFMT6, GX::VA_TEX0, GX::TEX_ST, GX::F32, 0); - // } + GXSetVtxAttrFmt(GX::VTXFMT6, GX::VA_POS, GX::POS_XYZ, GX::F32, 0); + GXSetVtxAttrFmt(GX::VTXFMT6, GX::VA_CLR0, GX::CLR_RGBA, GX::RGBA8, 0); + if (constUVs) { + GXSetVtxAttrFmt(GX::VTXFMT6, GX::VA_TEX0, GX::TEX_ST, GX::RGBA8, 1); + } else { + GXSetVtxAttrFmt(GX::VTXFMT6, GX::VA_TEX0, GX::TEX_ST, GX::F32, 0); + } int mbspVal = std::max(1, x270_MBSP); if (x26c_30_MBLR) {