Skip to content

Commit 5c21e48

Browse files
committed
Migrate to DolphinCGraphics impl & cleanup old code
aurora now uses the original model buffers, but byteswapped. Migrates over to the updated impl.
1 parent bae47ea commit 5c21e48

File tree

229 files changed

+3033
-23243
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

229 files changed

+3033
-23243
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ set(ZLIB_LIBRARIES ZLIB::ZLIB CACHE STRING "zlib libraries" FORCE)
328328
include(ExternalProject)
329329
ExternalProject_Add(bintoc
330330
SOURCE_DIR "${CMAKE_CURRENT_LIST_DIR}/bintoc"
331-
CMAKE_ARGS -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX:PATH=<INSTALL_DIR>
331+
CMAKE_ARGS -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX:PATH=<INSTALL_DIR> -DCMAKE_TOOLCHAIN_FILE:PATH=${CMAKE_TOOLCHAIN_FILE} -DVCPKG_TARGET_TRIPLET:STRING=${VCPKG_TARGET_TRIPLET}
332332
INSTALL_COMMAND ${CMAKE_COMMAND} --build . --config Release --target install)
333333
include(${CMAKE_CURRENT_LIST_DIR}/bintoc/bintocHelpers.cmake)
334334

Runtime/AutoMapper/CAutoMapper.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1049,8 +1049,7 @@ void CAutoMapper::ProcessControllerInput(const CFinalInput& input, CStateManager
10491049
x308_textpane_instructions2->TextSupport().SetText(u"");
10501050
} else {
10511051
x2fc_textpane_hint->TextSupport().SetText(u"");
1052-
std::u16string str =
1053-
fmt::format(u"&image=SI,0.6,1.0,{};", g_tweakPlayerRes->x24_lStick[x2e4_lStickPos]);
1052+
std::u16string str = fmt::format(u"&image=SI,0.6,1.0,{};", g_tweakPlayerRes->x24_lStick[x2e4_lStickPos]);
10541053
str += g_MainStringTable->GetString(46 + (!g_Main->IsUSA() || g_Main->IsTrilogy())); // Rotate
10551054
x300_textpane_instructions->TextSupport().SetText(str);
10561055
str = fmt::format(u"&image=SI,0.6,1.0,{};", g_tweakPlayerRes->x4c_cStick[x2e8_rStickPos]);
@@ -1083,8 +1082,7 @@ void CAutoMapper::ProcessControllerInput(const CFinalInput& input, CStateManager
10831082
}
10841083
}
10851084

1086-
if (input.PZ() || input.PSpecialKey(ESpecialKey::Tab) || input.PB() ||
1087-
input.PSpecialKey(ESpecialKey::Esc)) {
1085+
if (input.PZ() || input.PSpecialKey(ESpecialKey::Tab) || input.PB() || input.PSpecialKey(ESpecialKey::Esc)) {
10881086
if (x328_ == 0) {
10891087
if (CanLeaveMapScreenInternal(mgr)) {
10901088
LeaveMapScreen(mgr);
@@ -1295,8 +1293,9 @@ void CAutoMapper::Update(float dt, CStateManager& mgr) {
12951293
void CAutoMapper::Draw(const CStateManager& mgr, const zeus::CTransform& xf, float alpha) {
12961294
SCOPED_GRAPHICS_DEBUG_GROUP("CAutoMapper::Draw", zeus::skPurple);
12971295
alpha *= g_GameState->GameOptions().GetHUDAlpha() / 255.f;
1298-
// Blend mode alpha
1299-
// Backface cull
1296+
g_Renderer->SetBlendMode_AlphaBlended();
1297+
CGraphics::SetCullMode(ERglCullMode::Front);
1298+
13001299
float alphaInterp;
13011300
if (x1bc_state != EAutoMapperState::MiniMap && x1c0_nextState != EAutoMapperState::MiniMap) {
13021301
alphaInterp = 1.f;
@@ -1496,9 +1495,10 @@ void CAutoMapper::Draw(const CStateManager& mgr, const zeus::CTransform& xf, flo
14961495
}
14971496
}
14981497

1499-
// No zread, no zwrite
1500-
// Ambient color white
1501-
// Disable all lights
1498+
g_Renderer->SetDepthReadWrite(false, false);
1499+
g_Renderer->SetAmbientColor(zeus::skWhite);
1500+
CGraphics::DisableAllLights();
1501+
15021502
if (m_frmeInitialized) {
15031503
float frmeAlpha = 0.f;
15041504
if (x1bc_state != EAutoMapperState::MiniMap && x1c0_nextState != EAutoMapperState::MiniMap) {

Runtime/AutoMapper/CMapArea.cpp

Lines changed: 70 additions & 150 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include "Runtime/GameGlobalObjects.hpp"
99
#include "Runtime/World/CWorld.hpp"
1010
#include "Runtime/CBasics.hpp"
11+
#include "Runtime/Graphics/CGX.hpp"
1112

1213
namespace metaforce {
1314
constexpr std::array<zeus::CVector3f, 3> MinesPostTransforms{{
@@ -101,49 +102,10 @@ void CMapArea::PostConstruct() {
101102
tmp += 12;
102103
}
103104

104-
std::vector<u32> index;
105105
m_surfaces.reserve(x30_surfaceCount);
106106
for (u32 i = 0, j = 0; i < x30_surfaceCount; ++i, j += 32) {
107-
m_surfaces.emplace_back(x40_surfaceStart + j).PostConstruct(x44_buf.get(), index);
107+
m_surfaces.emplace_back(x40_surfaceStart + j).PostConstruct(x44_buf.get());
108108
}
109-
110-
// CGraphics::CommitResources([this, &index](boo::IGraphicsDataFactory::Context& ctx) {
111-
// m_vbo = ctx.newStaticBuffer(boo::BufferUse::Vertex, m_verts.data(), 16, m_verts.size());
112-
// m_ibo = ctx.newStaticBuffer(boo::BufferUse::Index, index.data(), 4, index.size());
113-
//
114-
// /* Only the map universe specifies Always; it draws a maximum of 1016 instances */
115-
// size_t instCount = (xc_visibilityMode == EVisMode::Always) ? 1024 : 1;
116-
//
117-
// for (u32 i = 0; i < x30_surfaceCount; ++i) {
118-
// CMapAreaSurface& surf = m_surfaces[i];
119-
// surf.m_instances.reserve(instCount);
120-
// for (u32 inst = 0; inst < instCount; ++inst) {
121-
// CMapAreaSurface::Instance& instance = surf.m_instances.emplace_back(ctx, m_vbo, m_ibo);
122-
//
123-
// athena::io::MemoryReader r(surf.x1c_outlineOffset, INT_MAX);
124-
// u32 outlineCount = r.ReadLong();
125-
//
126-
// std::vector<CLineRenderer>& linePrims = instance.m_linePrims;
127-
// linePrims.reserve(outlineCount * 2);
128-
// for (u32 j = 0; j < 2; ++j) {
129-
// r.seek(4, athena::SeekOrigin::Begin);
130-
// for (u32 k = 0; k < outlineCount; ++k) {
131-
// const u32 count = r.ReadLong();
132-
// r.seek(count);
133-
// r.seekAlign4();
134-
// linePrims.emplace_back(ctx, CLineRenderer::EPrimitiveMode::LineStrip, count, nullptr, false, false, true);
135-
// }
136-
// }
137-
// }
138-
// }
139-
//
140-
// for (u32 i = 0; i < x28_mappableObjCount; ++i) {
141-
// CMappableObject& mapObj = m_mappableObjects[i];
142-
// if (CMappableObject::IsDoorType(mapObj.GetType()))
143-
// mapObj.CreateDoorSurface(ctx);
144-
// }
145-
// return true;
146-
// } BooTrace);
147109
}
148110

149111
bool CMapArea::GetIsVisibleToAutoMapper(bool worldVis, bool areaVis) const {
@@ -183,131 +145,89 @@ CMapArea::CMapAreaSurface::CMapAreaSurface(const void* surfBuf) {
183145
CMemoryInStream r(surfBuf, 32, CMemoryInStream::EOwnerShip::NotOwned);
184146
x0_normal = r.Get<zeus::CVector3f>();
185147
xc_centroid = r.Get<zeus::CVector3f>();
186-
x18_surfOffset = reinterpret_cast<const u8*>(uintptr_t(r.ReadLong()));
187-
x1c_outlineOffset = reinterpret_cast<const u8*>(uintptr_t(r.ReadLong()));
148+
x18_surfOffset = reinterpret_cast<const u32*>(static_cast<uintptr_t>(r.ReadLong()));
149+
x1c_outlineOffset = reinterpret_cast<const u32*>(static_cast<uintptr_t>(r.ReadLong()));
188150
}
189151

190-
void CMapArea::CMapAreaSurface::PostConstruct(const u8* buf, std::vector<u32>& index) {
191-
x18_surfOffset = buf + reinterpret_cast<uintptr_t>(x18_surfOffset);
192-
x1c_outlineOffset = buf + reinterpret_cast<uintptr_t>(x1c_outlineOffset);
193-
194-
m_primStart = index.size();
195-
bool start = true;
196-
{
197-
CMemoryInStream r(x18_surfOffset, INT_MAX, CMemoryInStream::EOwnerShip::NotOwned);
198-
u32 primCount = r.ReadLong();
199-
for (u32 i = 0; i < primCount; ++i) {
200-
GXPrimitive prim = GXPrimitive(r.ReadLong());
201-
u32 count = r.ReadLong();
202-
switch (prim) {
203-
case GX_TRIANGLES: {
204-
for (u32 v = 0; v < count; v += 3) {
205-
if (!start) {
206-
index.push_back(index.back());
207-
index.push_back(r.ReadUint8());
208-
index.push_back(index.back());
209-
} else {
210-
index.push_back(r.ReadUint8());
211-
start = false;
212-
}
213-
index.push_back(r.ReadUint8());
214-
index.push_back(r.ReadUint8());
215-
index.push_back(index.back());
216-
}
217-
break;
218-
}
219-
case GX_TRIANGLESTRIP: {
220-
if (!start) {
221-
index.push_back(index.back());
222-
index.push_back(r.ReadUint8());
223-
index.push_back(index.back());
224-
} else {
225-
index.push_back(r.ReadUint8());
226-
start = false;
227-
}
228-
for (u32 v = 1; v < count; ++v)
229-
index.push_back(r.ReadUint8());
230-
if (count & 1)
231-
index.push_back(index.back());
232-
break;
233-
}
234-
case GX_TRIANGLEFAN: {
235-
u8 firstVert = r.ReadUint8();
236-
if (!start) {
237-
index.push_back(index.back());
238-
index.push_back(r.ReadUint8());
239-
} else {
240-
index.push_back(r.ReadUint8());
241-
index.push_back(index.back());
242-
start = false;
243-
}
244-
for (u32 v = 1; v < count; ++v) {
245-
index.push_back(firstVert);
246-
index.push_back(r.ReadUint8());
247-
}
248-
break;
249-
}
250-
default:
251-
break;
252-
}
253-
u32 pos = r.GetReadPosition();
254-
while (r.GetReadPosition() != ROUND_UP_4(pos)) {
255-
r.ReadUint8();
256-
}
257-
}
258-
}
259-
m_primCount = index.size() - m_primStart;
152+
void CMapArea::CMapAreaSurface::PostConstruct(const void* buf) {
153+
x18_surfOffset =
154+
reinterpret_cast<const u32*>(static_cast<const u8*>(buf) + reinterpret_cast<uintptr_t>(x18_surfOffset));
155+
x1c_outlineOffset =
156+
reinterpret_cast<const u32*>(static_cast<const u8*>(buf) + reinterpret_cast<uintptr_t>(x1c_outlineOffset));
260157
}
261158

262-
void CMapArea::CMapAreaSurface::Draw(const zeus::CVector3f* verts, const zeus::CColor& surfColor,
263-
const zeus::CColor& lineColor, float lineWidth, size_t instIdx) {
264-
if (instIdx >= m_instances.size()) {
265-
return;
159+
void CMapArea::CMapAreaSurface::Draw(TConstVectorRef verts, const CColor& surfColor, const CColor& lineColor,
160+
float lineWidth) const {
161+
bool hasSurfAlpha = surfColor.a() > 0.0f;
162+
bool hasLineAlpha = lineColor.a() > 0.0f;
163+
u32 numSurfaces = CBasics::SwapBytes(*x18_surfOffset);
164+
u32 numOutlines = CBasics::SwapBytes(*x1c_outlineOffset);
165+
if (!verts.empty()) {
166+
CGX::SetArray(GX_VA_POS, verts);
266167
}
267-
268-
Instance& instance = m_instances[instIdx];
269-
270-
if (surfColor.a()) {
271-
instance.m_surfacePrims.draw(surfColor, m_primStart, m_primCount);
168+
if (hasSurfAlpha) {
169+
CGX::SetTevKColor(GX_KCOLOR0, surfColor);
170+
const u32* surface = &x18_surfOffset[1];
171+
for (u32 i = 0; i < numSurfaces; ++i) {
172+
GXPrimitive primType = static_cast<GXPrimitive>(CBasics::SwapBytes(*surface++));
173+
u32 numVertices = CBasics::SwapBytes(*surface++);
174+
const u8* data = reinterpret_cast<const u8*>(surface);
175+
surface += ((numVertices + 3) & ~3) / 4;
176+
177+
CGX::Begin(primType, GX_VTXFMT0, numVertices);
178+
for (u32 v = 0; v < numVertices; ++v) {
179+
GXPosition1x8(data[v]);
180+
}
181+
CGX::End();
182+
}
272183
}
184+
if (hasLineAlpha) {
185+
bool thickLine = lineWidth > 1.f;
186+
for (u32 j = 0; j < (thickLine ? 1 : 0) + 1; ++j) {
187+
const u32* outline = &x1c_outlineOffset[1];
273188

274-
if (lineColor.a()) {
275-
bool draw2 = lineWidth > 1.f;
276-
u32 outlineCount = *reinterpret_cast<const u32*>(x1c_outlineOffset);
277-
#if METAFORCE_TARGET_BYTE_ORDER == __ORDER_LITTLE_ENDIAN__
278-
outlineCount = CBasics::SwapBytes(outlineCount);
279-
#endif
280-
281-
std::vector<CLineRenderer>& linePrims = instance.m_linePrims;
282-
zeus::CColor color = lineColor;
283-
if (draw2)
284-
color.a() *= 0.5f;
285-
float width = lineWidth;
189+
if (thickLine) {
190+
CGraphics::SetLineWidth(lineWidth - j, ERglTexOffset::One);
191+
}
192+
CColor clr = lineColor;
193+
if (thickLine) {
194+
clr.a() *= 0.5f;
195+
}
196+
CGX::SetTevKColor(GX_KCOLOR0, clr);
286197

287-
auto primIt = linePrims.begin();
288-
for (u32 j = 0; j <= u32(draw2); ++j) {
289-
CMemoryInStream r(x1c_outlineOffset, INT_MAX, CMemoryInStream::EOwnerShip::NotOwned);
290-
r.ReadLong();
291-
for (u32 i = 0; i < outlineCount; ++i) {
292-
CLineRenderer& prim = *primIt++;
293-
prim.Reset();
294-
u32 count = r.ReadLong();
295-
for (u32 v = 0; v < count; ++v) {
296-
u8 idx = r.ReadUint8();
297-
prim.AddVertex(verts[idx], color, width);
298-
}
198+
for (u32 i = 0; i < numOutlines; ++i) {
199+
u32 numVertices = CBasics::SwapBytes(*outline++);
200+
const u8* data = reinterpret_cast<const u8*>(outline);
201+
outline += ((numVertices + 3) & ~3) / 4;
299202

300-
u32 pos = r.GetReadPosition();
301-
while (r.GetReadPosition() != ROUND_UP_4(pos)) {
302-
r.ReadUint8();
203+
CGX::Begin(GX_LINESTRIP, GX_VTXFMT0, numVertices);
204+
for (u32 v = 0; v < numVertices; ++v) {
205+
GXPosition1x8(data[v]);
303206
}
304-
prim.Render();
207+
CGX::End();
305208
}
306-
width -= 1.f;
307209
}
308210
}
309211
}
310212

213+
void CMapArea::CMapAreaSurface::SetupGXMaterial() {
214+
const GXVtxDescList list[2] = {
215+
{GX_VA_POS, GX_INDEX8},
216+
{GX_VA_NULL, GX_NONE},
217+
};
218+
CGX::SetVtxDescv(list);
219+
CGX::SetNumChans(1);
220+
CGX::SetNumTexGens(0);
221+
CGX::SetNumTevStages(1);
222+
CGX::SetChanCtrl(CGX::EChannelId::Channel0, false, GX_SRC_REG, GX_SRC_VTX, GX_LIGHT_NULL, GX_DF_NONE, GX_AF_NONE);
223+
CGX::SetTevColorIn(GX_TEVSTAGE0, GX_CC_ZERO, GX_CC_ZERO, GX_CC_ZERO, GX_CC_KONST);
224+
CGX::SetTevAlphaIn(GX_TEVSTAGE0, GX_CA_ZERO, GX_CA_ZERO, GX_CA_ZERO, GX_CA_KONST);
225+
CGX::SetTevColorOp(GX_TEVSTAGE0, GX_TEV_ADD, GX_TB_ZERO, GX_CS_SCALE_1, true, GX_TEVPREV);
226+
CGX::SetTevAlphaOp(GX_TEVSTAGE0, GX_TEV_ADD, GX_TB_ZERO, GX_CS_SCALE_1, true, GX_TEVPREV);
227+
CGX::SetTevKColorSel(GX_TEVSTAGE0, GX_TEV_KCSEL_K0);
228+
CGX::SetTevKAlphaSel(GX_TEVSTAGE0, GX_TEV_KASEL_K0_A);
229+
}
230+
311231
CFactoryFnReturn FMapAreaFactory(const SObjectTag& objTag, CInputStream& in, const CVParamTransfer&,
312232
CObjectReference*) {
313233
u32 size = g_ResFactory->ResourceSize(objTag);

Runtime/AutoMapper/CMapArea.hpp

Lines changed: 18 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -3,46 +3,38 @@
33
#include <memory>
44
#include <vector>
55

6+
#include "Runtime/Graphics/CCubeModel.hpp"
67
#include "Runtime/AutoMapper/CMappableObject.hpp"
78
#include "Runtime/CResFactory.hpp"
8-
#include "Runtime/Graphics/CLineRenderer.hpp"
9-
#include "Runtime/Graphics/Shaders/CMapSurfaceShader.hpp"
109
#include "Runtime/RetroTypes.hpp"
1110

1211
#include <zeus/CAABox.hpp>
1312
#include <zeus/CVector3f.hpp>
1413

1514
namespace metaforce {
15+
using CColor = zeus::CColor;
16+
using CVector3f = zeus::CVector3f;
17+
1618
class IWorld;
1719
class CMapArea {
1820
public:
1921
class CMapAreaSurface {
2022
friend class CMapArea;
21-
zeus::CVector3f x0_normal;
22-
zeus::CVector3f xc_centroid;
23-
const u8* x18_surfOffset;
24-
const u8* x1c_outlineOffset;
25-
u32 m_primStart;
26-
u32 m_primCount;
27-
struct Instance {
28-
CMapSurfaceShader m_surfacePrims;
29-
std::vector<CLineRenderer> m_linePrims;
30-
Instance(std::vector<zeus::CVector3f> vbo,
31-
std::vector<u16> ibo)
32-
: m_surfacePrims(vbo, ibo) {}
33-
Instance(Instance&&) = default;
34-
Instance& operator=(Instance&&) = default;
35-
};
36-
std::vector<Instance> m_instances;
23+
CVector3f x0_normal;
24+
CVector3f xc_centroid;
25+
const u32* x18_surfOffset;
26+
const u32* x1c_outlineOffset;
3727

3828
public:
3929
explicit CMapAreaSurface(const void* surfBuf);
40-
CMapAreaSurface(CMapAreaSurface&&) = default;
41-
void PostConstruct(const u8* buf, std::vector<u32>& index);
42-
void Draw(const zeus::CVector3f* verts, const zeus::CColor& surfColor, const zeus::CColor& lineColor,
43-
float lineWidth, size_t instIdx = 0);
44-
const zeus::CVector3f& GetNormal() const { return x0_normal; }
45-
const zeus::CVector3f& GetCenterPosition() const { return xc_centroid; }
30+
31+
void PostConstruct(const void* buf);
32+
void Draw(TConstVectorRef verts, const CColor& surfColor, const CColor& lineColor, float lineWidth) const;
33+
34+
static void SetupGXMaterial();
35+
36+
const CVector3f& GetNormal() const { return x0_normal; }
37+
const CVector3f& GetCenterPosition() const { return xc_centroid; }
4638
};
4739
enum class EVisMode { Always, MapStationOrVisit, Visit, Never };
4840

@@ -59,12 +51,10 @@ class CMapArea {
5951
u8* x38_moStart;
6052
std::vector<CMappableObject> m_mappableObjects;
6153
u8* x3c_vertexStart;
62-
std::vector<zeus::CVector3f> m_verts;
54+
std::vector<aurora::Vec3<float>> m_verts;
6355
u8* x40_surfaceStart;
6456
std::vector<CMapAreaSurface> m_surfaces;
6557
std::unique_ptr<u8[]> x44_buf;
66-
// boo::ObjToken<boo::IGraphicsBufferS> m_vbo;
67-
// boo::ObjToken<boo::IGraphicsBufferS> m_ibo;
6858

6959
public:
7060
explicit CMapArea(CInputStream& in, u32 size);
@@ -80,7 +70,7 @@ class CMapArea {
8070
u32 GetNumSurfaces() const { return m_surfaces.size(); }
8171
zeus::CTransform GetAreaPostTransform(const IWorld& world, TAreaId aid) const;
8272
static const zeus::CVector3f& GetAreaPostTranslate(const IWorld& world, TAreaId aid);
83-
const zeus::CVector3f* GetVertices() const { return m_verts.data(); }
73+
TConstVectorRef GetVertices() const { return m_verts; }
8474
};
8575

8676
CFactoryFnReturn FMapAreaFactory(const SObjectTag& objTag, CInputStream& in, const CVParamTransfer&, CObjectReference*);

0 commit comments

Comments
 (0)