diff --git a/Runtime/CBasicsPC.cpp b/Runtime/CBasicsPC.cpp index 47b354194..4d304c6df 100644 --- a/Runtime/CBasicsPC.cpp +++ b/Runtime/CBasicsPC.cpp @@ -30,6 +30,9 @@ #endif #include "Runtime/CBasics.hpp" + +#include "Runtime/CStopwatch.hpp" + #include #if __APPLE__ @@ -42,6 +45,7 @@ static LARGE_INTEGER PerfFrequency; namespace metaforce { static logvisor::Module LogModule("metaforce::CBasics"); void CBasics::Initialize() { + CStopwatch::InitGlobalTimer(); #if __APPLE__ mach_timebase_info_data_t timebase; mach_timebase_info(&timebase); diff --git a/Runtime/CMakeLists.txt b/Runtime/CMakeLists.txt index 773d1205b..3cdd61fd8 100644 --- a/Runtime/CMakeLists.txt +++ b/Runtime/CMakeLists.txt @@ -80,7 +80,7 @@ set(RUNTIME_SOURCES_B Tweaks/ITweakSlideShow.hpp Tweaks/ITweakTargeting.hpp IMain.hpp - CStopwatch.hpp + CStopwatch.hpp CStopwatch.cpp Streams/IOStreams.hpp Streams/IOStreams.cpp Streams/CMemoryStreamOut.hpp Streams/CMemoryStreamOut.cpp Streams/CInputStream.hpp Streams/CInputStream.cpp diff --git a/Runtime/CStopwatch.cpp b/Runtime/CStopwatch.cpp new file mode 100644 index 000000000..bf7330bbe --- /dev/null +++ b/Runtime/CStopwatch.cpp @@ -0,0 +1,30 @@ +#include "Runtime/CStopwatch.hpp" + +namespace metaforce { +CStopwatch CStopwatch::mGlobalTimer = {}; + +float CStopwatch::GetElapsedTime() const { + return static_cast(std::chrono::duration_cast(Time::now() - m_startTime).count()) / 1000.f; +} + +u16 CStopwatch::GetElapsedMicros() const { + return std::chrono::duration_cast(Time::now() - m_startTime).count(); +} + +u64 CStopwatch::GetCurMicros() const { + return std::chrono::duration_cast(Time::now().time_since_epoch()).count(); +} + +void CStopwatch::InitGlobalTimer() { mGlobalTimer.Reset(); } + +void CStopwatch::Reset() { m_startTime = std::chrono::steady_clock::now(); } + +void CStopwatch::Wait(float wait) { + if (std::fabs(wait) < 0.001f) { + wait = 0.f; + } + + auto waitDur = FloatSeconds{wait}; + while ((Time::now() - m_startTime) < waitDur) {} +} +} // namespace metaforce \ No newline at end of file diff --git a/Runtime/CStopwatch.hpp b/Runtime/CStopwatch.hpp index 08bceec13..799ddac7c 100644 --- a/Runtime/CStopwatch.hpp +++ b/Runtime/CStopwatch.hpp @@ -1,35 +1,31 @@ #pragma once +#include "Runtime/GCNTypes.hpp" + +#include #include -#include namespace metaforce { class CStopwatch { - std::chrono::steady_clock::time_point m_start; +private: + static CStopwatch mGlobalTimer; - static CStopwatch g_globalTimer; + using Time = std::chrono::steady_clock; + using MicroSeconds = std::chrono::microseconds; + using MilliSeconds = std::chrono::milliseconds; + using FloatSeconds = std::chrono::duration; + Time::time_point m_startTime; public: - CStopwatch() : m_start(std::chrono::steady_clock::now()) {} - double report(const char* name) const { - double t = - std::chrono::duration_cast(std::chrono::steady_clock::now() - m_start).count() / - 1000000.0; - //#ifndef NDEBUG - // fmt::print(FMT_STRING("{} {}\n"), name, t); - //#endif - return t; - } - double reportReset(const char* name) { - std::chrono::steady_clock::time_point now = std::chrono::steady_clock::now(); - double t = std::chrono::duration_cast(now - m_start).count() / 1000000.0; - //#ifndef NDEBUG - // fmt::print(FMT_STRING("{} {}\n"), name, t); - //#endif - m_start = now; - return t; - } + static void InitGlobalTimer(); + static CStopwatch& GetGlobalTimerObj() { return mGlobalTimer; } + static float GetGlobalTime() { return mGlobalTimer.GetElapsedTime(); } - static CStopwatch& GetGlobalTimerObj() { return g_globalTimer; } + void Reset(); + void Wait(float wait); + + float GetElapsedTime() const; + u16 GetElapsedMicros() const; + u64 GetCurMicros() const; }; } // namespace metaforce diff --git a/Runtime/Character/CModelData.cpp b/Runtime/Character/CModelData.cpp index 011200c33..36ba5c963 100644 --- a/Runtime/Character/CModelData.cpp +++ b/Runtime/Character/CModelData.cpp @@ -442,5 +442,8 @@ void CModelData::DisintegrateDraw(EWhichModel which, const zeus::CTransform& xf, // model.Draw(flags, nullptr, nullptr); // } } +void CModelData::ThermalDraw(const zeus::CColor& mulColor, const zeus::CColor& addColor, const CModelFlags& flags) { + +} } // namespace metaforce diff --git a/Runtime/Graphics/CCubeMaterial.cpp b/Runtime/Graphics/CCubeMaterial.cpp index baf348f1f..ab358ae67 100644 --- a/Runtime/Graphics/CCubeMaterial.cpp +++ b/Runtime/Graphics/CCubeMaterial.cpp @@ -269,7 +269,7 @@ void CCubeMaterial::HandleDepth(u16 modelFlags, CCubeMaterialFlags matFlags) { func = (modelFlags & 0x10) != 0 ? ERglEnum::Less : ERglEnum::LEqual; } bool depthWrite = (modelFlags & 0x2) != 0 && matFlags & CCubeMaterialFlagBits::fDepthWrite; - aurora::gfx::set_depth_mode(func, depthWrite); + aurora::gfx::set_depth_mode(true, func, depthWrite); } void CCubeMaterial::ResetCachedMaterials() { diff --git a/Runtime/Graphics/CCubeRenderer.cpp b/Runtime/Graphics/CCubeRenderer.cpp index d9b402198..188f88eea 100644 --- a/Runtime/Graphics/CCubeRenderer.cpp +++ b/Runtime/Graphics/CCubeRenderer.cpp @@ -1,9 +1,10 @@ -#include "CCubeRenderer.hpp" +#include "Runtime/Graphics/CCubeRenderer.hpp" -#include "GameGlobalObjects.hpp" -#include "Graphics/CDrawable.hpp" -#include "Graphics/CDrawablePlaneObject.hpp" -#include "Graphics/CLight.hpp" +#include "Runtime/GameGlobalObjects.hpp" +#include "Runtime/Graphics/CDrawable.hpp" +#include "Runtime/Graphics/CDrawablePlaneObject.hpp" +#include "Runtime/Graphics/CLight.hpp" +#include "Runtime/Graphics/CModel.hpp" namespace metaforce { static logvisor::Module Log("CCubeRenderer"); @@ -177,4 +178,92 @@ CCubeRenderer::CCubeRenderer(IObjectStore& store, IFactory& resFac) : x8_factory Buckets::Init(); // GX draw sync } + +CCubeRenderer::~CCubeRenderer() { + g_Renderer = nullptr; +} + +void CCubeRenderer::GenerateReflectionTex() {} +void CCubeRenderer::GenerateFogVolumeRampTex() {} +void CCubeRenderer::GenerateSphereRampTex() {} +void CCubeRenderer::LoadThermoPalette() {} +void CCubeRenderer::ReallyDrawPhazonSuitIndirectEffect(const zeus::CColor& vertColor, const CTexture& maskTex, + const CTexture& indTex, const zeus::CColor& modColor, + float scale, float offX, float offY) {} +void CCubeRenderer::ReallyDrawPhazonSuitEffect(const zeus::CColor& modColor, const CTexture& maskTex) {} +void CCubeRenderer::DoPhazonSuitIndirectAlphaBlur(float blurRadius, float f2, const TLockedToken& indTex) {} +void CCubeRenderer::AddStaticGeometry(const std::vector* geometry, + const CAreaRenderOctTree* octTree, int areaIdx) {} +void CCubeRenderer::EnablePVS(const CPVSVisSet& set, u32 areaIdx) {} +void CCubeRenderer::DisablePVS() {} +void CCubeRenderer::RemoveStaticGeometry(const std::vector* geometry) {} +void CCubeRenderer::DrawUnsortedGeometry(int areaIdx, int mask, int targetMask, bool shadowRender) {} +void CCubeRenderer::DrawSortedGeometry(int areaIdx, int mask, int targetMask) {} +void CCubeRenderer::DrawStaticGeometry(int areaIdx, int mask, int targetMask) {} +void CCubeRenderer::DrawAreaGeometry(int areaIdx, int mask, int targetMask) {} +void CCubeRenderer::PostRenderFogs() {} +void CCubeRenderer::SetModelMatrix(const zeus::CTransform& xf) {} +void CCubeRenderer::AddParticleGen(CParticleGen& gen) {} +void CCubeRenderer::AddParticleGen(CParticleGen& gen, const zeus::CVector3f& pos, const zeus::CAABox& bounds) {} +void CCubeRenderer::AddPlaneObject(void* obj, const zeus::CAABox& aabb, const zeus::CPlane& plane, int type) {} +void CCubeRenderer::AddDrawable(void* obj, const zeus::CVector3f& pos, const zeus::CAABox& aabb, int mode, + IRenderer::EDrawableSorting sorting) {} +void CCubeRenderer::SetDrawableCallback(IRenderer::TDrawableCallback cb, void* ctx) {} +void CCubeRenderer::SetWorldViewpoint(const zeus::CTransform& xf) {} +void CCubeRenderer::SetPerspective(float fovy, float aspect, float znear, float zfar) {} +void CCubeRenderer::SetPerspective(float fovy, float width, float height, float znear, float zfar) {} +std::pair CCubeRenderer::SetViewportOrtho(bool centered, float znear, float zfar) { + return std::pair(); +} +void CCubeRenderer::SetClippingPlanes(const zeus::CFrustum& frustum) {} +void CCubeRenderer::SetViewport(int left, int bottom, int width, int height) {} +void CCubeRenderer::BeginScene() {} +void CCubeRenderer::EndScene() {} +void CCubeRenderer::SetDebugOption(IRenderer::EDebugOption, int) {} +void CCubeRenderer::BeginPrimitive(IRenderer::EPrimitiveType, int) {} +void CCubeRenderer::BeginLines(int) {} +void CCubeRenderer::BeginLineStrip(int) {} +void CCubeRenderer::BeginTriangles(int) {} +void CCubeRenderer::BeginTriangleStrip(int) {} +void CCubeRenderer::BeginTriangleFan(int) {} +void CCubeRenderer::PrimVertex(const zeus::CVector3f&) {} +void CCubeRenderer::PrimNormal(const zeus::CVector3f&) {} +void CCubeRenderer::PrimColor(float, float, float, float) {} +void CCubeRenderer::PrimColor(const zeus::CColor&) {} +void CCubeRenderer::EndPrimitive() {} +void CCubeRenderer::SetAmbientColor(const zeus::CColor& color) {} +void CCubeRenderer::DrawString(const char* string, int, int) {} +u32 CCubeRenderer::GetFPS() { return 0; } +void CCubeRenderer::CacheReflection(IRenderer::TReflectionCallback cb, void* ctx, bool clearAfter) {} +void CCubeRenderer::DrawSpaceWarp(const zeus::CVector3f& pt, float strength) {} +void CCubeRenderer::DrawThermalModel(const CModel& model, const zeus::CColor& multCol, const zeus::CColor& addCol, + TVectorRef positions, TVectorRef normals, CModelFlags flags) {} +void CCubeRenderer::DrawModelDisintegrate(const CModel& model, const CTexture& tex, const zeus::CColor& color, + TVectorRef positions, TVectorRef normals) {} +void CCubeRenderer::DrawModelFlat(const CModel& model, const CModelFlags& flags, bool unsortedOnly) {} +void CCubeRenderer::SetWireframeFlags(int flags) {} +void CCubeRenderer::SetWorldFog(ERglFogMode mode, float startz, float endz, const zeus::CColor& color) {} +void CCubeRenderer::RenderFogVolume(const zeus::CColor& color, const zeus::CAABox& aabb, + const TLockedToken* model, const CSkinnedModel* sModel) {} +void CCubeRenderer::SetThermal(bool thermal, float level, const zeus::CColor& color) {} +void CCubeRenderer::SetThermalColdScale(float scale) {} +void CCubeRenderer::DoThermalBlendCold() {} +void CCubeRenderer::DoThermalBlendHot() {} +u32 CCubeRenderer::GetStaticWorldDataSize() { return 0; } +void CCubeRenderer::SetGXRegister1Color(const zeus::CColor& color) {} +void CCubeRenderer::SetWorldLightFadeLevel(float level) {} +void CCubeRenderer::SetWorldLightMultiplyColor(const zeus::CColor& color) {} +void CCubeRenderer::PrepareDynamicLights(const std::vector& lights) {} +void CCubeRenderer::AllocatePhazonSuitMaskTexture() {} +void CCubeRenderer::DrawPhazonSuitIndirectEffect(const zeus::CColor& nonIndirectMod, + const TLockedToken& indTex, const zeus::CColor& indirectMod, + float blurRadius, float scale, float offX, float offY) {} +void CCubeRenderer::DrawXRayOutline(const zeus::CAABox& aabb) {} +void CCubeRenderer::FindOverlappingWorldModels(std::vector& modelBits, const zeus::CAABox& aabb) const {} +int CCubeRenderer::DrawOverlappingWorldModelIDs(int alphaVal, const std::vector& modelBits, + const zeus::CAABox& aabb) { + return 0; +} +void CCubeRenderer::DrawOverlappingWorldModelShadows(int alphaVal, const std::vector& modelBits, + const zeus::CAABox& aabb, float alpha) {} } // namespace metaforce diff --git a/Runtime/Graphics/CGraphics.cpp b/Runtime/Graphics/CGraphics.cpp index a324c954e..9e4d297fd 100644 --- a/Runtime/Graphics/CGraphics.cpp +++ b/Runtime/Graphics/CGraphics.cpp @@ -9,7 +9,6 @@ #include namespace metaforce { - CGraphics::CProjectionState CGraphics::g_Proj; CFogState CGraphics::g_Fog; std::array CGraphics::g_ColorRegs{}; @@ -37,6 +36,8 @@ u32 CGraphics::g_FrameCounter = 0; u32 CGraphics::g_Framerate = 0; u32 CGraphics::g_FramesPast = 0; frame_clock::time_point CGraphics::g_FrameStartTime = frame_clock::now(); +ERglEnum CGraphics::g_depthFunc = ERglEnum::Never; +ERglCullMode CGraphics::g_cullMode = ERglCullMode::None; // bool CGraphics::g_commitAsLazy = false; const std::array CGraphics::skCubeBasisMats{{ @@ -100,9 +101,9 @@ void CGraphics::SetFog(ERglFogMode mode, float startz, float endz, const zeus::C } } -void CGraphics::SetDepthWriteMode(bool test, ERglEnum comp, bool write) { +void CGraphics::SetDepthWriteMode(bool compare_enable, ERglEnum comp, bool update_enable) { g_depthFunc = comp; - aurora::gfx::set_depth_mode(test, comp, write); + aurora::gfx::set_depth_mode(compare_enable, comp, update_enable); } void CGraphics::SetBlendMode(ERglBlendMode mode, ERglBlendFactor src, ERglBlendFactor dst, ERglLogicOp op) { diff --git a/Runtime/Graphics/CModel.cpp b/Runtime/Graphics/CModel.cpp index e2026f411..8c5feb73d 100644 --- a/Runtime/Graphics/CModel.cpp +++ b/Runtime/Graphics/CModel.cpp @@ -249,6 +249,10 @@ void CModel::Touch(u32 matIdx) { } } +void CModel::Draw(CModelFlags flags) const {} + +void CModel::Draw(TVectorRef positions, TVectorRef normals, CModelFlags flags) {} + void CModel::DrawSortedParts(CModelFlags flags) { if ((flags.x2_flags & 0x20) != 0) { x28_modelInst->DrawNormal(nullptr, nullptr, ESurfaceSelection::Sorted); diff --git a/Runtime/World/CMorphBallShadow.hpp b/Runtime/World/CMorphBallShadow.hpp index 91166dc93..c2b4f2e0c 100644 --- a/Runtime/World/CMorphBallShadow.hpp +++ b/Runtime/World/CMorphBallShadow.hpp @@ -31,5 +31,4 @@ public: void RenderIdBuffer(const zeus::CAABox& aabb, const CStateManager& mgr, CPlayer& player); void Render(const CStateManager& mgr, float alpha); }; - } // namespace metaforce diff --git a/aurora/include/aurora/gfx.hpp b/aurora/include/aurora/gfx.hpp index 686a9d8c4..37e06fdea 100644 --- a/aurora/include/aurora/gfx.hpp +++ b/aurora/include/aurora/gfx.hpp @@ -142,7 +142,7 @@ enum class ZComp : uint8_t { void set_cull_mode(metaforce::ERglCullMode mode) noexcept; void set_blend_mode(metaforce::ERglBlendMode mode, metaforce::ERglBlendFactor src, metaforce::ERglBlendFactor dst, metaforce::ERglLogicOp op) noexcept; -void set_depth_mode(metaforce::ERglEnum func, bool update); +void set_depth_mode(bool compare_enable, metaforce::ERglEnum func, bool update_enable); // Model state void set_alpha_discard(bool v); diff --git a/aurora/lib/gfx/common.cpp b/aurora/lib/gfx/common.cpp index cfa6b3ed8..ae21f06ea 100644 --- a/aurora/lib/gfx/common.cpp +++ b/aurora/lib/gfx/common.cpp @@ -117,6 +117,15 @@ static void push_draw_command(ShaderDrawCommand data) { g_commands.push_back({Co bool get_dxt_compression_supported() noexcept { return g_device.HasFeature(wgpu::FeatureName::TextureCompressionBC); } +// GX state +void set_cull_mode(metaforce::ERglCullMode mode) noexcept {} +void set_blend_mode(metaforce::ERglBlendMode mode, metaforce::ERglBlendFactor src, metaforce::ERglBlendFactor dst, + metaforce::ERglLogicOp op) noexcept {} +void set_depth_mode(bool compare_enable, metaforce::ERglEnum func, bool update_enable) {} + +// Model state +void set_alpha_discard(bool v) {} + void update_model_view(const zeus::CMatrix4f& mv, const zeus::CMatrix4f& mv_inv) noexcept { g_mv = mv; g_mvInv = mv_inv;