mirror of
https://github.com/izzy2lost/2ship2harkinian-Android.git
synced 2026-06-19 01:20:08 -07:00
* Start the framework. * Start header bar. * Header buttons now toggle. Sections show accordingly. Basic audio section done. Needs subdividing for sane widget widths. * Add fonts and multiple sizes. Add graphics settings to menu. * Finalized fonts, more sizes. * Modularized the menu structure. Has an errant EndChild somewhere. * Finished first step modularization. Parameterized menu height. * Some adaptive menu size. * Moved all enhancements over and organized. Tried to add button option for sidebar entries. * Finished Enhancements Menu. Sidebar window button still broken (can't reference window variables properly, not drawing in the right place). * Developer Tools header started. Menu now pops out with a checkbox in Developer Tools. Menu sizing works for smaller game sizes. Popout docking disabled. Port bool added for disallowing popout regardless of cvar. * Better auto-sizing. Columns collapse to 1 below 800 window width, and scroll. * Move inside of HudEditorWindow::DrawElement to DrawContents, and call DrawContents from DrawElement. * Menu resizability complete. Menu popout complete. Menu popout position/size is retained when popped in. Apply HUD editor changes, draw contents in menu if window is closed. All child sizes properly calculated. SidebarEntry drawing separated into its own custom element. * Split header entries into separate widget. Header now dynamically sized and shows scrollbar when necessary. * Modify EventLog to be drawable with the DrawContents setup. Prevent menu from covering other windows (always in back). * Add reset, close menu, and quit buttons to the header. * Fix reset and quit button placement. * Swap Actor Viewer, Collision Viewer, Save Editor to DrawContents concept. Change reset icon to FA_ICON_UNDO (single arrow) and quit icon to FA_ICON_POWER_OFF. Add button to close menu button tooltip, add parentheses to button for reset tooltip. * Custom InputEditorWindow to work with menu. Fix LUS references in Menu.cpp for Window backend changes. Implement gamepad navigation and forced cursor visibility checkboxes. Toggle cursor visibility according to menu status and forced visibility CVar. * clang-format * Swap std for fmt (runner build error). Ensure cursor visibility is restored if started in full screen with the menu open. * Oops, still had #include <format> * Swap to LUS GetMenu() functionality. Add option to hide "F1 to open enhancements menu" text at startup if menus aren't open. * Remove last vestiges of pre-LUS-menu functionality. * cleanup * Adapt to GuiElement, GuiWindow changes on the menu support PR. * LUS PR bump. Adapt to cursor visibility changes in LUS. Adapt to menu toggle changes in LUS. Fix input editor not hiding in menu when popped out. * Add new enhancements and cheats to Modern Menu from rebase. * clang * Apply Graphics Menu Lag Fix to Menu structure. * Remove unnecessary window children to simplify controller navigation. * clang * Add `UpdateWindowBackendObjects()` call to backend combobox. * Rebase to latest develop. Remove redundant window backend stuff that exists now in BenMenuBar. * Search Enhancement (#2) * 90% complete, Commit for review. * Updated remaining Menu Entries, Reverted Backends and other Window Buttons for now. Motion Blur copied to Search Menu. * Did I mention I dislike this clang thing? lol * Updating MotionBlur options and reverting soem things. * Integrates .disabled and .disabledTooltip to the constructors. Allows for multiple qualifications to be checked against for disabling widgets and for setting the tooltip accordingly. * Updated Disabled Reasoning * Better Disabled State registration system * Clean up from testing * Expand WidgetOptions to be able to handle string and float values. bool and uint32_t are handled through int32_t. Numerous renames. Added several data structures to allow for dynamic updating of CVars for DisableOptions, as well as dynamic evaluation of status with enumerated conditions (less than, greater than, equal to). Added menuThemeIndex variable to store state of menu theme selection instead of having all the individual calls to CVarGetInteger for it. Updated once per frame. * Changed color vector to map with enum as key and UIWidget::Colors as the value. More renames. Moved float slider values into case block. * Add Color_RGB8 and Color_RGBA8 to CVarVariant in preparation for adding color widgets to menu item system. Not happy it required comparison operator overrides, but it is what it is. * Changed disable conditions to lambdas. * Convert Stats and Collision Viewer to menu item system. Swap out DisableOption vector for activeDisables and a lambda function for evaluating disabled and hidden. Set the precedent to still use the DisableInfo system. * Add DisableOption for both camera settings being off. Put Debug Camera in Free Look column, disable common widgets for both cameras, hide widgets specific to either if off. * Moved more widgets to MenuItem system. Some need proper initialization routines because of Ship::Context references. * Convert menu items to nested vector setup. Remove MenuItem enum. Add menu item location display to search results. * Partial removal of SidebarEntryIndex enum. * Finish removing SidebarEntryIndex. Rework drawing code to handle the change back to direct vector access. Add tooltips to search. * Fix Graphics enhancements section title. * Copy added menu items to modern menu system. * clang * Add some documentation for the menu system components. * Revert change to std::map * `size_t` because GCC has to be happy * Fixed HUD Editor Widescreen mode not displaying the sliders properly. Changed all windows to full-section-width display. * Revert changes to MotionBlur.cpp * Add non-CVar variants of checkbox, combobox, and the sliders. Fix motion blur functionality with new non-CVar widgets. * Add non-CVar variants of checkbox, combobox, and the sliders. Fix motion blur functionality with those non-CVar widgets. Add size and labelPosition to widgetOptions, implemented on button and checkbox/combobox/sliders. Change window popout buttons to inline size type. * Rename SearchMenu.h to SearchableMenuItems.h and move to BenGui folder. * Forgot to change the include XD * Change `modifierFunc` to `preFunc`, updated documentation for that and including `postFunc`. * Modify code to require variable for non-CVar widget initialization when necessary. Check for `valuePointer` being nullptr, and preventing widget drawing with a debug assert and error log entry. Remove all `has_variant` calls and wrap entire widget type switch in `SearchMenuGetItem` with a try/catch on `std::bad_variant_access` with another error log and debug assert. * More review changes. * Implement `isPercentage`, `format`, and `showButtons` for sliders. Pull values of those over from menubar. Add documentation on `widgetOptions` for those and others added for previous review changes. Move Fast Magic Arrow and Instant Fin Recall to Gameplay section. * Modify header and sidebar "buttons" to match theming of regular buttons. * Add precision clamping to SliderFloat value. At least 1.0 seems to be consistent at "100%". Change IR slider to be percentage. * Mention weirdness with SDL and pad menu button in controller nav tooltip. * Move Menu files to 2s2h/BenGui. * Add Warp Points to Developer Tools. Make "Press F1" prompt show only when a menu isn't registered. * clang * Make search input take focus when search menu is open. * Forgot include. * Global search (#3) * Restore Sidebar search entry, but lock it behind a checkbox in Settings. Dynamically adds or removes the sidebar entry, and header search is toggled inversely. * Make menu toggle its visibility when using the button in the menu to close. Couldn't handle Alt+F4 without a hook I didn't want to add. Remove unneeded commented code. --------- Co-authored-by: Caladius <Caladius@users.noreply.github.com> Co-authored-by: Garrett Cox <garrettjcox@gmail.com>
734 lines
33 KiB
C++
734 lines
33 KiB
C++
#include "CollisionViewer.h"
|
|
#include "2s2h/Enhancements/FrameInterpolation/FrameInterpolation.h"
|
|
#include "2s2h/BenGui/UIWidgets.hpp"
|
|
|
|
#include <vector>
|
|
#include <string>
|
|
#include <cmath>
|
|
#include <random>
|
|
#include <libultraship/bridge.h>
|
|
#include <libultraship/libultraship.h>
|
|
#include "2s2h/Enhancements/GameInteractor/GameInteractor.h"
|
|
|
|
extern "C" {
|
|
#include <z64.h>
|
|
#include "variables.h"
|
|
#include "functions.h"
|
|
#include "macros.h"
|
|
extern PlayState* gPlayState;
|
|
}
|
|
|
|
extern "C" WallType SurfaceType_GetWallType(CollisionContext* colCtx, CollisionPoly* poly, s32 bgId);
|
|
|
|
enum class ColRenderSetting { Disabled, Solid, Transparent };
|
|
|
|
static const char* ColRenderSettingNames[] = {
|
|
"Disabled",
|
|
"Solid",
|
|
"Transparent",
|
|
};
|
|
|
|
static std::vector<Gfx> opaDl;
|
|
static std::vector<Gfx> xluDl;
|
|
static std::vector<Vtx> vtxDl;
|
|
static std::vector<Mtx> mtxDl;
|
|
|
|
// These DLs contain a cylinder/sphere model scaled to 128x (to have less error)
|
|
// The idea is to push a model view matrix, then draw the DL, to draw the shape somewhere with a certain size
|
|
static std::vector<Gfx> cylinderGfx;
|
|
static std::vector<Vtx> cylinderVtx;
|
|
static std::vector<Gfx> sphereGfx;
|
|
static std::vector<Vtx> sphereVtx;
|
|
|
|
// Draws the ImGui window for the collision viewer
|
|
void CollisionViewerWindow::DrawElement() {
|
|
UIWidgets::CVarCheckbox("Enabled", "gCollisionViewer.Enabled");
|
|
|
|
ImGui::SameLine();
|
|
|
|
ImGui::BeginDisabled(CVarGetInteger("gCollisionViewer.Enabled", 0) == 0);
|
|
|
|
UIWidgets::CVarCheckbox("Apply Shading", "gCollisionViewer.ApplyShading");
|
|
|
|
ImGui::SameLine();
|
|
|
|
if (UIWidgets::Button("Reset Colors")) {
|
|
CVarClear("gCollisionViewer.SceneCollisionColor");
|
|
CVarClear("gCollisionViewer.VoidCollisionColor");
|
|
CVarClear("gCollisionViewer.EntranceCollisionColor");
|
|
CVarClear("gCollisionViewer.SlopeCollisionColor");
|
|
CVarClear("gCollisionViewer.HookshotCollisionColor");
|
|
CVarClear("gCollisionViewer.WaterboxCollisionColor");
|
|
CVarClear("gCollisionViewer.OCollisionColor");
|
|
CVarClear("gCollisionViewer.ACollisionColor");
|
|
CVarClear("gCollisionViewer.ATCollisionColor");
|
|
CVarClear("gCollisionViewer.SpecialSurfaceColor");
|
|
CVarClear("gCollisionViewer.InteractableColor");
|
|
Ship::Context::GetInstance()->GetWindow()->GetGui()->SaveConsoleVariablesOnNextTick();
|
|
}
|
|
|
|
ImGui::SeparatorText("Collision Types");
|
|
|
|
UIWidgets::CVarCombobox("Scene", "gCollisionViewer.SceneCollisionMode", ColRenderSettingNames,
|
|
{ .color = UIWidgets::Colors::Gray });
|
|
UIWidgets::CVarCombobox("BG Actors", "gCollisionViewer.BGActorsCollisionMode", ColRenderSettingNames,
|
|
{ .color = UIWidgets::Colors::Gray });
|
|
UIWidgets::CVarCombobox("Col Check", "gCollisionViewer.ColCheckCollisionMode", ColRenderSettingNames,
|
|
{ .color = UIWidgets::Colors::Gray });
|
|
UIWidgets::CVarCombobox("Waterbox", "gCollisionViewer.WaterboxCollisionMode", ColRenderSettingNames,
|
|
{ .color = UIWidgets::Colors::Gray });
|
|
|
|
ImGui::SeparatorText("Colors");
|
|
|
|
if (ImGui::BeginTable("table table", 3, ImGuiTableFlags_NoBordersInBody)) {
|
|
ImGui::TableNextColumn();
|
|
UIWidgets::CVarColorPicker("Normal", "gCollisionViewer.SceneCollisionColor", { 255, 255, 255, 255 });
|
|
ImGui::TableNextColumn();
|
|
UIWidgets::CVarColorPicker("Void", "gCollisionViewer.VoidCollisionColor", { 255, 0, 0, 255 });
|
|
ImGui::TableNextColumn();
|
|
UIWidgets::CVarColorPicker("Entrance", "gCollisionViewer.EntranceCollisionColor", { 0, 255, 0, 255 });
|
|
ImGui::TableNextColumn();
|
|
UIWidgets::CVarColorPicker("Slope", "gCollisionViewer.SlopeCollisionColor", { 255, 255, 128, 255 });
|
|
ImGui::TableNextColumn();
|
|
UIWidgets::CVarColorPicker("Hookshotable", "gCollisionViewer.HookshotCollisionColor", { 128, 128, 255, 255 });
|
|
ImGui::TableNextColumn();
|
|
UIWidgets::CVarColorPicker("Waterbox", "gCollisionViewer.WaterboxCollisionColor", { 0, 0, 255, 255 });
|
|
ImGui::TableNextColumn();
|
|
UIWidgets::CVarColorPicker("OC", "gCollisionViewer.OCollisionColor", { 255, 255, 255, 255 });
|
|
ImGui::TableNextColumn();
|
|
UIWidgets::CVarColorPicker("AC", "gCollisionViewer.ACollisionColor", { 0, 0, 255, 255 });
|
|
ImGui::TableNextColumn();
|
|
UIWidgets::CVarColorPicker("AT", "gCollisionViewer.ATCollisionColor", { 255, 0, 0, 255 });
|
|
ImGui::EndTable();
|
|
}
|
|
UIWidgets::CVarColorPicker("Special Surface (Grass/Sand/Etc)", "gCollisionViewer.SpecialSurfaceColor",
|
|
{ 192, 255, 192, 255 });
|
|
UIWidgets::CVarColorPicker("Interactable (Vines/Crawlspace/Etc)", "gCollisionViewer.InteractableColor",
|
|
{ 192, 0, 192, 255 });
|
|
|
|
ImGui::EndDisabled();
|
|
}
|
|
|
|
// Calculates the normal for a triangle at the 3 specified points
|
|
void CalcTriNorm(const Vec3f& v1, const Vec3f& v2, const Vec3f& v3, Vec3f& norm) {
|
|
norm.x = (v2.y - v1.y) * (v3.z - v1.z) - (v2.z - v1.z) * (v3.y - v1.y);
|
|
norm.y = (v2.z - v1.z) * (v3.x - v1.x) - (v2.x - v1.x) * (v3.z - v1.z);
|
|
norm.z = (v2.x - v1.x) * (v3.y - v1.y) - (v2.y - v1.y) * (v3.x - v1.x);
|
|
float norm_d = sqrtf(norm.x * norm.x + norm.y * norm.y + norm.z * norm.z);
|
|
if (norm_d != 0.f) {
|
|
norm.x *= 127.f / norm_d;
|
|
norm.y *= 127.f / norm_d;
|
|
norm.z *= 127.f / norm_d;
|
|
}
|
|
}
|
|
|
|
// Various macros used for creating verticies and rendering that aren't in gbi.h
|
|
#define G_CC_MODULATERGB_PRIM_ENVA PRIMITIVE, 0, SHADE, 0, 0, 0, 0, ENVIRONMENT
|
|
#define G_CC_PRIMITIVE_ENVA 0, 0, 0, PRIMITIVE, 0, 0, 0, ENVIRONMENT
|
|
#define qs105(n) ((int16_t)((n)*0x0020))
|
|
#define gdSPDefVtxN(x, y, z, s, t, nx, ny, nz, ca) \
|
|
{ \
|
|
.n = {.ob = { x, y, z }, .tc = { qs105(s), qs105(t) }, .n = { nx, ny, nz }, .a = ca } \
|
|
}
|
|
|
|
void CreateCylinderData() {
|
|
constexpr int32_t CYL_DIVS = 12;
|
|
cylinderGfx.reserve(5 + CYL_DIVS * 2);
|
|
cylinderVtx.reserve(2 + CYL_DIVS * 2);
|
|
|
|
cylinderVtx.push_back(gdSPDefVtxN(0, 0, 0, 0, 0, 0, -127, 0, 0xFF)); // Bottom center vertex
|
|
cylinderVtx.push_back(gdSPDefVtxN(0, 128, 0, 0, 0, 0, 127, 0, 0xFF)); // Top center vertex
|
|
// Create two rings of vertices
|
|
for (int i = 0; i < CYL_DIVS; ++i) {
|
|
short vtx_x = floorf(0.5f + cosf(2.f * M_PI * i / CYL_DIVS) * 128.f);
|
|
short vtx_z = floorf(0.5f - sinf(2.f * M_PI * i / CYL_DIVS) * 128.f);
|
|
signed char norm_x = cosf(2.f * M_PI * i / CYL_DIVS) * 127.f;
|
|
signed char norm_z = -sinf(2.f * M_PI * i / CYL_DIVS) * 127.f;
|
|
cylinderVtx.push_back(gdSPDefVtxN(vtx_x, 0, vtx_z, 0, 0, norm_x, 0, norm_z, 0xFF));
|
|
cylinderVtx.push_back(gdSPDefVtxN(vtx_x, 128, vtx_z, 0, 0, norm_x, 0, norm_z, 0xFF));
|
|
}
|
|
|
|
// Draw edges
|
|
cylinderGfx.push_back(gsSPSetGeometryMode(G_CULL_BACK | G_SHADING_SMOOTH));
|
|
cylinderGfx.push_back(gsSPVertex((uintptr_t)cylinderVtx.data(), 2 + CYL_DIVS * 2, 0));
|
|
for (int i = 0; i < CYL_DIVS; ++i) {
|
|
int p = (i + CYL_DIVS - 1) % CYL_DIVS;
|
|
int v[4] = {
|
|
2 + p * 2 + 0,
|
|
2 + i * 2 + 0,
|
|
2 + i * 2 + 1,
|
|
2 + p * 2 + 1,
|
|
};
|
|
cylinderGfx.push_back(gsSP2Triangles(v[0], v[1], v[2], 0, v[0], v[2], v[3], 0));
|
|
}
|
|
|
|
// Draw top & bottom
|
|
cylinderGfx.push_back(gsSPClearGeometryMode(G_SHADING_SMOOTH));
|
|
for (int i = 0; i < CYL_DIVS; ++i) {
|
|
int p = (i + CYL_DIVS - 1) % CYL_DIVS;
|
|
int v[4] = {
|
|
2 + p * 2 + 0,
|
|
2 + i * 2 + 0,
|
|
2 + i * 2 + 1,
|
|
2 + p * 2 + 1,
|
|
};
|
|
cylinderGfx.push_back(gsSP2Triangles(0, v[1], v[0], 0, 1, v[3], v[2], 0));
|
|
}
|
|
|
|
cylinderGfx.push_back(gsSPClearGeometryMode(G_CULL_BACK));
|
|
cylinderGfx.push_back(gsSPEndDisplayList());
|
|
}
|
|
|
|
// This subdivides a face into four tris by placing new verticies at the midpoints of the sides (Like a triforce!), then
|
|
// blowing up the verticies so they are on the unit sphere
|
|
void CreateSphereFace(std::vector<std::tuple<size_t, size_t, size_t>>& faces, int32_t v0Index, int32_t v1Index,
|
|
int32_t v2Index) {
|
|
size_t nextIndex = sphereVtx.size();
|
|
|
|
size_t v01Index = nextIndex;
|
|
size_t v12Index = nextIndex + 1;
|
|
size_t v20Index = nextIndex + 2;
|
|
|
|
faces.emplace_back(v0Index, v01Index, v20Index);
|
|
faces.emplace_back(v1Index, v12Index, v01Index);
|
|
faces.emplace_back(v2Index, v20Index, v12Index);
|
|
faces.emplace_back(v01Index, v12Index, v20Index);
|
|
|
|
const Vtx& v0 = sphereVtx[v0Index];
|
|
const Vtx& v1 = sphereVtx[v1Index];
|
|
const Vtx& v2 = sphereVtx[v2Index];
|
|
|
|
// Create 3 new verticies at the midpoints
|
|
Vec3f vs[3] = {
|
|
Vec3f{ (v0.n.ob[0] + v1.n.ob[0]) / 2.0f, (v0.n.ob[1] + v1.n.ob[1]) / 2.0f, (v0.n.ob[2] + v1.n.ob[2]) / 2.0f },
|
|
Vec3f{ (v1.n.ob[0] + v2.n.ob[0]) / 2.0f, (v1.n.ob[1] + v2.n.ob[1]) / 2.0f, (v1.n.ob[2] + v2.n.ob[2]) / 2.0f },
|
|
Vec3f{ (v2.n.ob[0] + v0.n.ob[0]) / 2.0f, (v2.n.ob[1] + v0.n.ob[1]) / 2.0f, (v2.n.ob[2] + v0.n.ob[2]) / 2.0f }
|
|
};
|
|
|
|
// Normalize vertex positions so they are on the sphere
|
|
for (int32_t vAddIndex = 0; vAddIndex < 3; vAddIndex++) {
|
|
Vec3f& v = vs[vAddIndex];
|
|
float mag = sqrtf(v.x * v.x + v.y * v.y + v.z * v.z);
|
|
v.x /= mag;
|
|
v.y /= mag;
|
|
v.z /= mag;
|
|
sphereVtx.push_back(gdSPDefVtxN((short)(v.x * 127), (short)(v.y * 127), (short)(v.z * 127), 0, 0,
|
|
(signed char)(v.x * 127), (signed char)(v.y * 127), (signed char)(v.z * 127),
|
|
0xFF));
|
|
}
|
|
}
|
|
|
|
// Creates a sphere following the idea in here:
|
|
// http://blog.andreaskahler.com/2009/06/creating-icosphere-mesh-in-code.html Spcifically, create a icosahedron by
|
|
// realizing that the points can be placed on 3 rectangles that are on each unit plane. Then, subdividing each face.
|
|
void CreateSphereData() {
|
|
std::vector<Vec3f> base;
|
|
|
|
float d = (1.0f + sqrtf(5.0f)) / 2.0f;
|
|
|
|
// Create the 12 starting verticies, 4 on each rectangle
|
|
base.emplace_back(Vec3f({ -1, d, 0 }));
|
|
base.emplace_back(Vec3f({ 1, d, 0 }));
|
|
base.emplace_back(Vec3f({ -1, -d, 0 }));
|
|
base.emplace_back(Vec3f({ 1, -d, 0 }));
|
|
|
|
base.emplace_back(Vec3f({ 0, -1, d }));
|
|
base.emplace_back(Vec3f({ 0, 1, d }));
|
|
base.emplace_back(Vec3f({ 0, -1, -d }));
|
|
base.emplace_back(Vec3f({ 0, 1, -d }));
|
|
|
|
base.emplace_back(Vec3f({ d, 0, -1 }));
|
|
base.emplace_back(Vec3f({ d, 0, 1 }));
|
|
base.emplace_back(Vec3f({ -d, 0, -1 }));
|
|
base.emplace_back(Vec3f({ -d, 0, 1 }));
|
|
|
|
// Normalize verticies so they are on the unit sphere
|
|
for (Vec3f& v : base) {
|
|
float mag = sqrtf(v.x * v.x + v.y * v.y + v.z * v.z);
|
|
v.x /= mag;
|
|
v.y /= mag;
|
|
v.z /= mag;
|
|
sphereVtx.push_back(gdSPDefVtxN((short)(v.x * 128), (short)(v.y * 128), (short)(v.z * 128), 0, 0,
|
|
(signed char)(v.x * 127), (signed char)(v.y * 127), (signed char)(v.z * 127),
|
|
0xFF));
|
|
}
|
|
|
|
std::vector<std::tuple<size_t, size_t, size_t>> faces;
|
|
|
|
// Subdivide faces
|
|
CreateSphereFace(faces, 0, 11, 5);
|
|
CreateSphereFace(faces, 0, 5, 1);
|
|
CreateSphereFace(faces, 0, 1, 7);
|
|
CreateSphereFace(faces, 0, 7, 10);
|
|
CreateSphereFace(faces, 0, 10, 11);
|
|
|
|
CreateSphereFace(faces, 1, 5, 9);
|
|
CreateSphereFace(faces, 5, 11, 4);
|
|
CreateSphereFace(faces, 11, 10, 2);
|
|
CreateSphereFace(faces, 10, 7, 6);
|
|
CreateSphereFace(faces, 7, 1, 8);
|
|
|
|
CreateSphereFace(faces, 3, 9, 4);
|
|
CreateSphereFace(faces, 3, 4, 2);
|
|
CreateSphereFace(faces, 3, 2, 6);
|
|
CreateSphereFace(faces, 3, 6, 8);
|
|
CreateSphereFace(faces, 3, 8, 9);
|
|
|
|
CreateSphereFace(faces, 4, 9, 5);
|
|
CreateSphereFace(faces, 2, 4, 11);
|
|
CreateSphereFace(faces, 6, 2, 10);
|
|
CreateSphereFace(faces, 8, 6, 7);
|
|
CreateSphereFace(faces, 9, 8, 1);
|
|
|
|
size_t vtxStartIndex = sphereVtx.size();
|
|
sphereVtx.reserve(sphereVtx.size() + faces.size() * 3);
|
|
for (int32_t faceIndex = 0; faceIndex < faces.size(); faceIndex++) {
|
|
sphereVtx.push_back(sphereVtx[std::get<0>(faces[faceIndex])]);
|
|
sphereVtx.push_back(sphereVtx[std::get<1>(faces[faceIndex])]);
|
|
sphereVtx.push_back(sphereVtx[std::get<2>(faces[faceIndex])]);
|
|
sphereGfx.push_back(gsSPVertex((uintptr_t)(sphereVtx.data() + vtxStartIndex + faceIndex * 3), 3, 0));
|
|
sphereGfx.push_back(gsSP1Triangle(0, 1, 2, 0));
|
|
}
|
|
|
|
sphereGfx.push_back(gsSPEndDisplayList());
|
|
}
|
|
|
|
// Initializes the display list for a ColRenderSetting
|
|
void InitGfx(std::vector<Gfx>& gfx, ColRenderSetting setting) {
|
|
uint32_t rm;
|
|
uint32_t blc1;
|
|
uint32_t blc2;
|
|
uint8_t alpha;
|
|
uint64_t cm;
|
|
uint32_t gm;
|
|
|
|
if (setting == ColRenderSetting::Transparent) {
|
|
rm = Z_CMP | IM_RD | CVG_DST_FULL | FORCE_BL;
|
|
blc1 = GBL_c1(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_1MA);
|
|
blc2 = GBL_c2(G_BL_CLR_IN, G_BL_A_IN, G_BL_CLR_MEM, G_BL_1MA);
|
|
alpha = 0x80;
|
|
} else {
|
|
rm = Z_CMP | Z_UPD | CVG_DST_CLAMP | FORCE_BL;
|
|
blc1 = GBL_c1(G_BL_CLR_IN, G_BL_0, G_BL_CLR_IN, G_BL_1);
|
|
blc2 = GBL_c2(G_BL_CLR_IN, G_BL_0, G_BL_CLR_IN, G_BL_1);
|
|
alpha = 0xFF;
|
|
}
|
|
|
|
// Default decal mode to on, users can override it manually but there's not really a use case for the other modes
|
|
if (CVarGetInteger("gCollisionViewer.DecalMode", 1)) {
|
|
rm |= ZMODE_DEC;
|
|
} else if (setting == ColRenderSetting::Transparent) {
|
|
rm |= ZMODE_XLU;
|
|
} else {
|
|
rm |= ZMODE_OPA;
|
|
}
|
|
|
|
gfx.push_back(gsSPTexture(0, 0, 0, G_TX_RENDERTILE, G_OFF));
|
|
gfx.push_back(gsDPSetCycleType(G_CYC_1CYCLE));
|
|
gfx.push_back(gsDPSetRenderMode(rm | blc1, rm | blc2));
|
|
|
|
if (CVarGetInteger("gCollisionViewer.ApplyShading", 0) != 0) {
|
|
gfx.push_back(gsDPSetCombineMode(G_CC_MODULATERGB_PRIM_ENVA, G_CC_MODULATERGB_PRIM_ENVA));
|
|
gfx.push_back(gsSPLoadGeometryMode(G_CULL_BACK | G_ZBUFFER | G_LIGHTING));
|
|
} else {
|
|
gfx.push_back(gsDPSetCombineMode(G_CC_PRIMITIVE_ENVA, G_CC_PRIMITIVE_ENVA));
|
|
gfx.push_back(gsSPLoadGeometryMode(G_ZBUFFER));
|
|
}
|
|
|
|
gfx.push_back(gsDPSetEnvColor(0xFF, 0xFF, 0xFF, alpha));
|
|
}
|
|
|
|
// Draws a dynapoly structure (scenes or Bg Actors)
|
|
void DrawDynapoly(std::vector<Gfx>& dl, CollisionHeader* col, int32_t bgId) {
|
|
Color_RGBA8 sceneCollisionColor = CVarGetColor("gCollisionViewer.SceneCollisionColor", { 255, 255, 255, 255 });
|
|
Color_RGBA8 voidCollisionColor = CVarGetColor("gCollisionViewer.VoidCollisionColor", { 255, 0, 0, 255 });
|
|
Color_RGBA8 entranceCollisionColor = CVarGetColor("gCollisionViewer.EntranceCollisionColor", { 0, 255, 0, 255 });
|
|
Color_RGBA8 slopeCollisionColor = CVarGetColor("gCollisionViewer.SlopeCollisionColor", { 255, 255, 128, 255 });
|
|
Color_RGBA8 hookshotCollisionColor =
|
|
CVarGetColor("gCollisionViewer.HookshotCollisionColor", { 128, 128, 255, 255 });
|
|
Color_RGBA8 specialSurfaceColor = CVarGetColor("gCollisionViewer.SpecialSurfaceColor", { 192, 255, 192, 255 });
|
|
Color_RGBA8 interactableColor = CVarGetColor("gCollisionViewer.InteractableColor", { 192, 0, 192, 255 });
|
|
uint32_t colorR = sceneCollisionColor.r;
|
|
uint32_t colorG = sceneCollisionColor.g;
|
|
uint32_t colorB = sceneCollisionColor.b;
|
|
uint32_t colorA = 255;
|
|
|
|
uint32_t lastColorR = colorR;
|
|
uint32_t lastColorG = colorG;
|
|
uint32_t lastColorB = colorB;
|
|
|
|
dl.push_back(gsDPSetPrimColor(0, 0, colorR, colorG, colorB, colorA));
|
|
|
|
// This keeps track of if we have processed a poly, but not drawn it yet so we can batch them.
|
|
// This saves several hundred commands in larger scenes
|
|
bool previousPoly = false;
|
|
|
|
for (int i = 0; i < col->numPolygons; i++) {
|
|
CollisionPoly* poly = &col->polyList[i];
|
|
|
|
if (SurfaceType_IsHookshotSurface(&gPlayState->colCtx, poly, bgId)) {
|
|
colorR = hookshotCollisionColor.r;
|
|
colorG = hookshotCollisionColor.g;
|
|
colorB = hookshotCollisionColor.b;
|
|
} else if (SurfaceType_GetWallType(&gPlayState->colCtx, poly, bgId) > 0x01) {
|
|
colorR = interactableColor.r;
|
|
colorG = interactableColor.g;
|
|
colorB = interactableColor.b;
|
|
} else if (SurfaceType_GetFloorProperty(&gPlayState->colCtx, poly, bgId) == 0x0C) {
|
|
colorR = voidCollisionColor.r;
|
|
colorG = voidCollisionColor.g;
|
|
colorB = voidCollisionColor.b;
|
|
} else if (SurfaceType_GetSceneExitIndex(&gPlayState->colCtx, poly, bgId) ||
|
|
SurfaceType_GetFloorProperty(&gPlayState->colCtx, poly, bgId) == 0x05) {
|
|
colorR = entranceCollisionColor.r;
|
|
colorG = entranceCollisionColor.g;
|
|
colorB = entranceCollisionColor.b;
|
|
} else if (SurfaceType_GetFloorType(&gPlayState->colCtx, poly, bgId) != 0 ||
|
|
SurfaceType_IsWallDamage(&gPlayState->colCtx, poly, bgId)) {
|
|
colorR = specialSurfaceColor.r;
|
|
colorG = specialSurfaceColor.g;
|
|
colorB = specialSurfaceColor.b;
|
|
} else if (SurfaceType_GetFloorEffect(&gPlayState->colCtx, poly, bgId) == 0x01) {
|
|
colorR = slopeCollisionColor.r;
|
|
colorG = slopeCollisionColor.g;
|
|
colorB = slopeCollisionColor.b;
|
|
} else {
|
|
colorR = sceneCollisionColor.r;
|
|
colorG = sceneCollisionColor.g;
|
|
colorB = sceneCollisionColor.b;
|
|
}
|
|
|
|
if (colorR != lastColorR || colorG != lastColorG || colorB != lastColorB) {
|
|
// Color changed, flush previous poly
|
|
if (previousPoly) {
|
|
dl.push_back(gsSPVertex((uintptr_t)&vtxDl.at(vtxDl.size() - 3), 3, 0));
|
|
dl.push_back(gsSP1Triangle(0, 1, 2, 0));
|
|
previousPoly = false;
|
|
}
|
|
dl.push_back(gsDPSetPrimColor(0, 0, colorR, colorG, colorB, colorA));
|
|
}
|
|
lastColorR = colorR;
|
|
lastColorG = colorG;
|
|
lastColorB = colorB;
|
|
|
|
Vec3s* va = &col->vtxList[COLPOLY_VTX_INDEX(poly->flags_vIA)];
|
|
Vec3s* vb = &col->vtxList[COLPOLY_VTX_INDEX(poly->flags_vIB)];
|
|
Vec3s* vc = &col->vtxList[COLPOLY_VTX_INDEX(poly->vIC)];
|
|
vtxDl.push_back(gdSPDefVtxN(va->x, va->y, va->z, 0, 0, (signed char)(poly->normal.x / 0x100),
|
|
(signed char)(poly->normal.y / 0x100), (signed char)(poly->normal.z / 0x100),
|
|
0xFF));
|
|
vtxDl.push_back(gdSPDefVtxN(vb->x, vb->y, vb->z, 0, 0, (signed char)(poly->normal.x / 0x100),
|
|
(signed char)(poly->normal.y / 0x100), (signed char)(poly->normal.z / 0x100),
|
|
0xFF));
|
|
vtxDl.push_back(gdSPDefVtxN(vc->x, vc->y, vc->z, 0, 0, (signed char)(poly->normal.x / 0x100),
|
|
(signed char)(poly->normal.y / 0x100), (signed char)(poly->normal.z / 0x100),
|
|
0xFF));
|
|
|
|
if (previousPoly) {
|
|
dl.push_back(gsSPVertex((uintptr_t)&vtxDl.at(vtxDl.size() - 6), 6, 0));
|
|
dl.push_back(gsSP2Triangles(0, 1, 2, 0, 3, 4, 5, 0));
|
|
previousPoly = false;
|
|
} else {
|
|
previousPoly = true;
|
|
}
|
|
}
|
|
|
|
// Flush previous poly if this is the end and there's no more coming
|
|
if (previousPoly) {
|
|
dl.push_back(gsSPVertex((uintptr_t)&vtxDl.at(vtxDl.size() - 3), 3, 0));
|
|
dl.push_back(gsSP1Triangle(0, 1, 2, 0));
|
|
previousPoly = false;
|
|
}
|
|
}
|
|
|
|
// Draws the scene
|
|
void DrawSceneCollision() {
|
|
ColRenderSetting showSceneColSetting =
|
|
(ColRenderSetting)CVarGetInteger("gCollisionViewer.SceneCollisionMode", (uint32_t)ColRenderSetting::Disabled);
|
|
|
|
if (showSceneColSetting == ColRenderSetting::Disabled) {
|
|
return;
|
|
}
|
|
|
|
std::vector<Gfx>& dl = (showSceneColSetting == ColRenderSetting::Transparent) ? xluDl : opaDl;
|
|
InitGfx(dl, showSceneColSetting);
|
|
dl.push_back(gsSPMatrix(&gIdentityMtx, G_MTX_MODELVIEW | G_MTX_LOAD | G_MTX_NOPUSH));
|
|
|
|
DrawDynapoly(dl, gPlayState->colCtx.colHeader, BGCHECK_SCENE);
|
|
}
|
|
|
|
// Draws all Bg Actors
|
|
void DrawBgActorCollision() {
|
|
ColRenderSetting showBgActorSetting = (ColRenderSetting)CVarGetInteger("gCollisionViewer.BGActorsCollisionMode",
|
|
(uint32_t)ColRenderSetting::Disabled);
|
|
if (showBgActorSetting == ColRenderSetting::Disabled) {
|
|
return;
|
|
}
|
|
|
|
std::vector<Gfx>& dl = (showBgActorSetting == ColRenderSetting::Transparent) ? xluDl : opaDl;
|
|
InitGfx(dl, showBgActorSetting);
|
|
dl.push_back(gsSPMatrix(&gIdentityMtx, G_MTX_MODELVIEW | G_MTX_LOAD | G_MTX_NOPUSH));
|
|
|
|
for (int32_t bgIndex = 0; bgIndex < BG_ACTOR_MAX; bgIndex++) {
|
|
if (gPlayState->colCtx.dyna.bgActorFlags[bgIndex] & 1) {
|
|
BgActor& bg = gPlayState->colCtx.dyna.bgActors[bgIndex];
|
|
Mtx m;
|
|
MtxF mf;
|
|
SkinMatrix_SetScaleRotateRPYTranslate(&mf, bg.curTransform.scale.x, bg.curTransform.scale.y,
|
|
bg.curTransform.scale.z, bg.curTransform.rot.x, bg.curTransform.rot.y,
|
|
bg.curTransform.rot.z, bg.curTransform.pos.x, bg.curTransform.pos.y,
|
|
bg.curTransform.pos.z);
|
|
guMtxF2L(mf.mf, &m);
|
|
mtxDl.push_back(m);
|
|
dl.push_back(gsSPMatrix(&mtxDl.back(), G_MTX_MODELVIEW | G_MTX_LOAD | G_MTX_PUSH));
|
|
|
|
DrawDynapoly(dl, bg.colHeader, bgIndex);
|
|
|
|
dl.push_back(gsSPPopMatrix(G_MTX_MODELVIEW));
|
|
}
|
|
}
|
|
}
|
|
|
|
// Draws a quad
|
|
void DrawQuad(std::vector<Gfx>& dl, Vec3f& v0, Vec3f& v1, Vec3f& v2, Vec3f& v3) {
|
|
Vec3f norm;
|
|
CalcTriNorm(v0, v1, v2, norm);
|
|
|
|
vtxDl.push_back(gdSPDefVtxN((short)v0.x, (short)v0.y, (short)v0.z, 0, 0, (signed char)norm.x, (signed char)norm.y,
|
|
(signed char)norm.z, 0xFF));
|
|
vtxDl.push_back(gdSPDefVtxN((short)v1.x, (short)v1.y, (short)v1.z, 0, 0, (signed char)norm.x, (signed char)norm.y,
|
|
(signed char)norm.z, 0xFF));
|
|
vtxDl.push_back(gdSPDefVtxN((short)v2.x, (short)v2.y, (short)v2.z, 0, 0, (signed char)norm.x, (signed char)norm.y,
|
|
(signed char)norm.z, 0xFF));
|
|
vtxDl.push_back(gdSPDefVtxN((short)v3.x, (short)v3.y, (short)v3.z, 0, 0, (signed char)norm.x, (signed char)norm.y,
|
|
(signed char)norm.z, 0xFF));
|
|
dl.push_back(gsSPVertex((uintptr_t)&vtxDl.at(vtxDl.size() - 4), 4, 0));
|
|
dl.push_back(gsSP2Triangles(0, 1, 2, 0, 0, 2, 3, 0));
|
|
}
|
|
|
|
// Draws a list of Col Check objects
|
|
void DrawColCheckList(std::vector<Gfx>& dl, Collider** objects, int32_t count) {
|
|
for (int32_t colIndex = 0; colIndex < count; colIndex++) {
|
|
Collider* col = objects[colIndex];
|
|
switch (col->shape) {
|
|
case COLSHAPE_JNTSPH: {
|
|
ColliderJntSph* jntSph = (ColliderJntSph*)col;
|
|
|
|
for (int32_t sphereIndex = 0; sphereIndex < jntSph->count; sphereIndex++) {
|
|
ColliderJntSphElement* sph = &jntSph->elements[sphereIndex];
|
|
|
|
Mtx m;
|
|
MtxF mf;
|
|
SkinMatrix_SetTranslate(&mf, sph->dim.worldSphere.center.x, sph->dim.worldSphere.center.y,
|
|
sph->dim.worldSphere.center.z);
|
|
MtxF ms;
|
|
int32_t radius = sph->dim.worldSphere.radius == 0 ? 1 : sph->dim.worldSphere.radius;
|
|
SkinMatrix_SetScale(&ms, radius / 128.0f, radius / 128.0f, radius / 128.0f);
|
|
MtxF dest;
|
|
SkinMatrix_MtxFMtxFMult(&mf, &ms, &dest);
|
|
guMtxF2L(dest.mf, &m);
|
|
mtxDl.push_back(m);
|
|
|
|
dl.push_back(gsSPMatrix(&mtxDl.back(), G_MTX_MODELVIEW | G_MTX_LOAD | G_MTX_PUSH));
|
|
dl.push_back(gsSPDisplayList(sphereGfx.data()));
|
|
dl.push_back(gsSPPopMatrix(G_MTX_MODELVIEW));
|
|
}
|
|
} break;
|
|
case COLSHAPE_CYLINDER: {
|
|
ColliderCylinder* cyl = (ColliderCylinder*)col;
|
|
|
|
Mtx m;
|
|
MtxF mt;
|
|
SkinMatrix_SetTranslate(&mt, cyl->dim.pos.x, cyl->dim.pos.y + cyl->dim.yShift, cyl->dim.pos.z);
|
|
MtxF ms;
|
|
int32_t radius = cyl->dim.radius == 0 ? 1 : cyl->dim.radius;
|
|
SkinMatrix_SetScale(&ms, radius / 128.0f, cyl->dim.height / 128.0f, radius / 128.0f);
|
|
MtxF dest;
|
|
SkinMatrix_MtxFMtxFMult(&mt, &ms, &dest);
|
|
guMtxF2L(dest.mf, &m);
|
|
mtxDl.push_back(m);
|
|
|
|
dl.push_back(gsSPMatrix(&mtxDl.back(), G_MTX_MODELVIEW | G_MTX_LOAD | G_MTX_PUSH));
|
|
dl.push_back(gsSPDisplayList(cylinderGfx.data()));
|
|
dl.push_back(gsSPPopMatrix(G_MTX_MODELVIEW));
|
|
} break;
|
|
case COLSHAPE_TRIS: {
|
|
ColliderTris* tris = (ColliderTris*)col;
|
|
for (int32_t triIndex = 0; triIndex < tris->count; triIndex++) {
|
|
ColliderTrisElement* tri = &tris->elements[triIndex];
|
|
|
|
vtxDl.push_back(gdSPDefVtxN((short)tri->dim.vtx[0].x, (short)tri->dim.vtx[0].y,
|
|
(short)tri->dim.vtx[0].z, 0, 0, (signed char)tri->dim.plane.normal.x,
|
|
(signed char)tri->dim.plane.normal.y,
|
|
(signed char)tri->dim.plane.normal.z, 0xFF));
|
|
vtxDl.push_back(gdSPDefVtxN((short)tri->dim.vtx[1].x, (short)tri->dim.vtx[1].y,
|
|
(short)tri->dim.vtx[1].z, 0, 0, (signed char)tri->dim.plane.normal.x,
|
|
(signed char)tri->dim.plane.normal.y,
|
|
(signed char)tri->dim.plane.normal.z, 0xFF));
|
|
vtxDl.push_back(gdSPDefVtxN((short)tri->dim.vtx[2].x, (short)tri->dim.vtx[2].y,
|
|
(short)tri->dim.vtx[2].z, 0, 0, (signed char)tri->dim.plane.normal.x,
|
|
(signed char)tri->dim.plane.normal.y,
|
|
(signed char)tri->dim.plane.normal.z, 0xFF));
|
|
dl.push_back(gsSPVertex((uintptr_t)&vtxDl.at(vtxDl.size() - 3), 3, 0));
|
|
dl.push_back(gsSP1Triangle(0, 1, 2, 0));
|
|
}
|
|
} break;
|
|
case COLSHAPE_QUAD: {
|
|
ColliderQuad* quad = (ColliderQuad*)col;
|
|
DrawQuad(dl, quad->dim.quad[0], quad->dim.quad[2], quad->dim.quad[3], quad->dim.quad[1]);
|
|
} break;
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
// Draws all Col Check objects
|
|
void DrawColCheckCollision() {
|
|
Color_RGBA8 oCollisionColor = CVarGetColor("gCollisionViewer.OCollisionColor", { 255, 255, 255, 255 });
|
|
Color_RGBA8 aCollisionColor = CVarGetColor("gCollisionViewer.ACollisionColor", { 0, 0, 255, 255 });
|
|
Color_RGBA8 aTCollisionColor = CVarGetColor("gCollisionViewer.ATCollisionColor", { 255, 0, 0, 255 });
|
|
ColRenderSetting showColCheckSetting = (ColRenderSetting)CVarGetInteger("gCollisionViewer.ColCheckCollisionMode",
|
|
(uint32_t)ColRenderSetting::Disabled);
|
|
if (showColCheckSetting == ColRenderSetting::Disabled) {
|
|
return;
|
|
}
|
|
|
|
std::vector<Gfx>& dl = (showColCheckSetting == ColRenderSetting::Transparent) ? xluDl : opaDl;
|
|
InitGfx(dl, showColCheckSetting);
|
|
dl.push_back(gsSPMatrix(&gIdentityMtx, G_MTX_MODELVIEW | G_MTX_LOAD | G_MTX_NOPUSH));
|
|
|
|
CollisionCheckContext& col = gPlayState->colChkCtx;
|
|
|
|
dl.push_back(gsDPSetPrimColor(0, 0, oCollisionColor.r, oCollisionColor.g, oCollisionColor.b, 255));
|
|
DrawColCheckList(dl, col.colOC, col.colOCCount);
|
|
dl.push_back(gsDPSetPrimColor(0, 0, aCollisionColor.r, aCollisionColor.g, aCollisionColor.b, 255));
|
|
DrawColCheckList(dl, col.colAC, col.colACCount);
|
|
dl.push_back(gsDPSetPrimColor(0, 0, aTCollisionColor.r, aTCollisionColor.g, aTCollisionColor.b, 255));
|
|
|
|
DrawColCheckList(dl, col.colAT, col.colATCount);
|
|
}
|
|
|
|
// Draws a waterbox
|
|
void DrawWaterbox(std::vector<Gfx>& dl, WaterBox* water, float water_max_depth = -4000.0f) {
|
|
// Skip waterboxes that would be disabled in current room
|
|
int32_t room = ((water->properties >> 13) & 0x3F);
|
|
if ((room != gPlayState->roomCtx.curRoom.num) && (room != 0x3F)) {
|
|
return;
|
|
}
|
|
|
|
Vec3f vtx[] = {
|
|
{ water->minPos.x, water->minPos.y, water->minPos.z + water->zLength },
|
|
{ water->minPos.x + water->xLength, water->minPos.y, water->minPos.z + water->zLength },
|
|
{ water->minPos.x + water->xLength, water->minPos.y, water->minPos.z },
|
|
{ water->minPos.x, water->minPos.y, water->minPos.z },
|
|
{ water->minPos.x, water_max_depth, water->minPos.z + water->zLength },
|
|
{ water->minPos.x + water->xLength, water_max_depth, water->minPos.z + water->zLength },
|
|
{ water->minPos.x + water->xLength, water_max_depth, water->minPos.z },
|
|
{ water->minPos.x, water_max_depth, water->minPos.z },
|
|
};
|
|
DrawQuad(dl, vtx[0], vtx[1], vtx[2], vtx[3]);
|
|
DrawQuad(dl, vtx[0], vtx[3], vtx[7], vtx[4]);
|
|
DrawQuad(dl, vtx[1], vtx[0], vtx[4], vtx[5]);
|
|
DrawQuad(dl, vtx[2], vtx[1], vtx[5], vtx[6]);
|
|
DrawQuad(dl, vtx[3], vtx[2], vtx[6], vtx[7]);
|
|
}
|
|
|
|
// Draws all waterboxes
|
|
void DrawWaterboxList() {
|
|
Color_RGBA8 waterboxCollisionColor = CVarGetColor("gCollisionViewer.WaterboxCollisionColor", { 0, 0, 255, 255 });
|
|
ColRenderSetting showWaterboxSetting = (ColRenderSetting)CVarGetInteger("gCollisionViewer.WaterboxCollisionMode",
|
|
(uint32_t)ColRenderSetting::Disabled);
|
|
if (showWaterboxSetting == ColRenderSetting::Disabled) {
|
|
return;
|
|
}
|
|
|
|
std::vector<Gfx>& dl = (showWaterboxSetting == ColRenderSetting::Transparent) ? xluDl : opaDl;
|
|
InitGfx(dl, showWaterboxSetting);
|
|
dl.push_back(gsSPMatrix(&gIdentityMtx, G_MTX_MODELVIEW | G_MTX_LOAD | G_MTX_NOPUSH));
|
|
|
|
dl.push_back(
|
|
gsDPSetPrimColor(0, 0, waterboxCollisionColor.r, waterboxCollisionColor.g, waterboxCollisionColor.b, 255));
|
|
|
|
CollisionHeader* col = gPlayState->colCtx.colHeader;
|
|
for (int32_t waterboxIndex = 0; waterboxIndex < col->numWaterBoxes; waterboxIndex++) {
|
|
WaterBox* water = &col->waterBoxes[waterboxIndex];
|
|
DrawWaterbox(dl, water);
|
|
}
|
|
}
|
|
|
|
// Resets a vector for the next frame and returns the capacity
|
|
template <typename T> size_t ResetVector(T& vec) {
|
|
size_t oldSize = vec.size();
|
|
vec.clear();
|
|
// Reserve slightly more space than last frame to account for variance (such as different amounts of bg actors)
|
|
vec.reserve(oldSize * 1.2);
|
|
return vec.capacity();
|
|
}
|
|
|
|
extern "C" void DrawCollisionViewer() {
|
|
if (gPlayState == nullptr || !CVarGetInteger("gCollisionViewer.Enabled", 0)) {
|
|
return;
|
|
}
|
|
|
|
ResetVector(opaDl);
|
|
ResetVector(xluDl);
|
|
size_t vtxDlCapacity = ResetVector(vtxDl);
|
|
size_t mtxDlCapacity = ResetVector(mtxDl);
|
|
|
|
DrawSceneCollision();
|
|
DrawBgActorCollision();
|
|
DrawColCheckCollision();
|
|
DrawWaterboxList();
|
|
|
|
// Check if we used up more space than we reserved. If so, redo the drawing with our new sizes.
|
|
// This is because we resized the vectors while drawing, invalidating pointers to them.
|
|
// This only matters for the Vtx and Mtx vectors.
|
|
if ((vtxDl.size() > vtxDlCapacity) || (mtxDl.size() > mtxDlCapacity)) {
|
|
ResetVector(opaDl);
|
|
ResetVector(xluDl);
|
|
vtxDlCapacity = ResetVector(vtxDl);
|
|
mtxDlCapacity = ResetVector(mtxDl);
|
|
|
|
DrawSceneCollision();
|
|
DrawBgActorCollision();
|
|
DrawColCheckCollision();
|
|
DrawWaterboxList();
|
|
}
|
|
|
|
if ((vtxDl.size() > vtxDlCapacity) || (mtxDl.size() > mtxDlCapacity)) {
|
|
// If the sizes somehow changed between the two draws, we can't continue because we may be using invalid data
|
|
printf("Error drawing collision, vertex/matrix sizes didn't settle.\n");
|
|
return;
|
|
}
|
|
|
|
OPEN_DISPS(gPlayState->state.gfxCtx);
|
|
|
|
uint8_t mirroredWorld = CVarGetInteger("gMirroredWorld", 0);
|
|
// Col viewer needs inverted culling in mirror mode for both OPA and XLU buffers
|
|
if (mirroredWorld) {
|
|
gSPSetExtraGeometryMode(POLY_OPA_DISP++, G_EX_INVERT_CULLING);
|
|
gSPSetExtraGeometryMode(POLY_XLU_DISP++, G_EX_INVERT_CULLING);
|
|
}
|
|
|
|
opaDl.push_back(gsSPEndDisplayList());
|
|
gSPDisplayList(POLY_OPA_DISP++, opaDl.data());
|
|
|
|
xluDl.push_back(gsSPEndDisplayList());
|
|
gSPDisplayList(POLY_XLU_DISP++, xluDl.data());
|
|
|
|
if (mirroredWorld) {
|
|
gSPClearExtraGeometryMode(POLY_OPA_DISP++, G_EX_INVERT_CULLING);
|
|
gSPClearExtraGeometryMode(POLY_XLU_DISP++, G_EX_INVERT_CULLING);
|
|
}
|
|
|
|
CLOSE_DISPS(gPlayState->state.gfxCtx);
|
|
}
|
|
|
|
void CollisionViewerWindow::InitElement() {
|
|
CreateCylinderData();
|
|
CreateSphereData();
|
|
|
|
GameInteractor::Instance->RegisterGameHook<GameInteractor::OnPlayDrawWorldEnd>(DrawCollisionViewer);
|
|
}
|