Use RE'd CStopwatch adapted for std::chrono, get metaforce linking again

This commit is contained in:
Phillip Stephens 2022-02-26 08:42:42 -08:00
parent 586268c66f
commit 7a59585c70
Signed by: Antidote
GPG Key ID: F8BEE4C83DACA60D
12 changed files with 170 additions and 35 deletions

View File

@ -30,6 +30,9 @@
#endif #endif
#include "Runtime/CBasics.hpp" #include "Runtime/CBasics.hpp"
#include "Runtime/CStopwatch.hpp"
#include <logvisor/logvisor.hpp> #include <logvisor/logvisor.hpp>
#if __APPLE__ #if __APPLE__
@ -42,6 +45,7 @@ static LARGE_INTEGER PerfFrequency;
namespace metaforce { namespace metaforce {
static logvisor::Module LogModule("metaforce::CBasics"); static logvisor::Module LogModule("metaforce::CBasics");
void CBasics::Initialize() { void CBasics::Initialize() {
CStopwatch::InitGlobalTimer();
#if __APPLE__ #if __APPLE__
mach_timebase_info_data_t timebase; mach_timebase_info_data_t timebase;
mach_timebase_info(&timebase); mach_timebase_info(&timebase);

View File

@ -80,7 +80,7 @@ set(RUNTIME_SOURCES_B
Tweaks/ITweakSlideShow.hpp Tweaks/ITweakSlideShow.hpp
Tweaks/ITweakTargeting.hpp Tweaks/ITweakTargeting.hpp
IMain.hpp IMain.hpp
CStopwatch.hpp CStopwatch.hpp CStopwatch.cpp
Streams/IOStreams.hpp Streams/IOStreams.cpp Streams/IOStreams.hpp Streams/IOStreams.cpp
Streams/CMemoryStreamOut.hpp Streams/CMemoryStreamOut.cpp Streams/CMemoryStreamOut.hpp Streams/CMemoryStreamOut.cpp
Streams/CInputStream.hpp Streams/CInputStream.cpp Streams/CInputStream.hpp Streams/CInputStream.cpp

30
Runtime/CStopwatch.cpp Normal file
View File

@ -0,0 +1,30 @@
#include "Runtime/CStopwatch.hpp"
namespace metaforce {
CStopwatch CStopwatch::mGlobalTimer = {};
float CStopwatch::GetElapsedTime() const {
return static_cast<float>(std::chrono::duration_cast<MilliSeconds>(Time::now() - m_startTime).count()) / 1000.f;
}
u16 CStopwatch::GetElapsedMicros() const {
return std::chrono::duration_cast<MicroSeconds>(Time::now() - m_startTime).count();
}
u64 CStopwatch::GetCurMicros() const {
return std::chrono::duration_cast<MicroSeconds>(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

View File

@ -1,35 +1,31 @@
#pragma once #pragma once
#include "Runtime/GCNTypes.hpp"
#include <cmath>
#include <chrono> #include <chrono>
#include <fmt/format.h>
namespace metaforce { namespace metaforce {
class CStopwatch { 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<float>;
Time::time_point m_startTime;
public: public:
CStopwatch() : m_start(std::chrono::steady_clock::now()) {} static void InitGlobalTimer();
double report(const char* name) const { static CStopwatch& GetGlobalTimerObj() { return mGlobalTimer; }
double t = static float GetGlobalTime() { return mGlobalTimer.GetElapsedTime(); }
std::chrono::duration_cast<std::chrono::microseconds>(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<std::chrono::microseconds>(now - m_start).count() / 1000000.0;
//#ifndef NDEBUG
// fmt::print(FMT_STRING("{} {}\n"), name, t);
//#endif
m_start = now;
return t;
}
static CStopwatch& GetGlobalTimerObj() { return g_globalTimer; } void Reset();
void Wait(float wait);
float GetElapsedTime() const;
u16 GetElapsedMicros() const;
u64 GetCurMicros() const;
}; };
} // namespace metaforce } // namespace metaforce

View File

@ -442,5 +442,8 @@ void CModelData::DisintegrateDraw(EWhichModel which, const zeus::CTransform& xf,
// model.Draw(flags, nullptr, nullptr); // model.Draw(flags, nullptr, nullptr);
// } // }
} }
void CModelData::ThermalDraw(const zeus::CColor& mulColor, const zeus::CColor& addColor, const CModelFlags& flags) {
}
} // namespace metaforce } // namespace metaforce

View File

@ -269,7 +269,7 @@ void CCubeMaterial::HandleDepth(u16 modelFlags, CCubeMaterialFlags matFlags) {
func = (modelFlags & 0x10) != 0 ? ERglEnum::Less : ERglEnum::LEqual; func = (modelFlags & 0x10) != 0 ? ERglEnum::Less : ERglEnum::LEqual;
} }
bool depthWrite = (modelFlags & 0x2) != 0 && matFlags & CCubeMaterialFlagBits::fDepthWrite; 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() { void CCubeMaterial::ResetCachedMaterials() {

View File

@ -1,9 +1,10 @@
#include "CCubeRenderer.hpp" #include "Runtime/Graphics/CCubeRenderer.hpp"
#include "GameGlobalObjects.hpp" #include "Runtime/GameGlobalObjects.hpp"
#include "Graphics/CDrawable.hpp" #include "Runtime/Graphics/CDrawable.hpp"
#include "Graphics/CDrawablePlaneObject.hpp" #include "Runtime/Graphics/CDrawablePlaneObject.hpp"
#include "Graphics/CLight.hpp" #include "Runtime/Graphics/CLight.hpp"
#include "Runtime/Graphics/CModel.hpp"
namespace metaforce { namespace metaforce {
static logvisor::Module Log("CCubeRenderer"); static logvisor::Module Log("CCubeRenderer");
@ -177,4 +178,92 @@ CCubeRenderer::CCubeRenderer(IObjectStore& store, IFactory& resFac) : x8_factory
Buckets::Init(); Buckets::Init();
// GX draw sync // 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<CTexture>& indTex) {}
void CCubeRenderer::AddStaticGeometry(const std::vector<CMetroidModelInstance>* geometry,
const CAreaRenderOctTree* octTree, int areaIdx) {}
void CCubeRenderer::EnablePVS(const CPVSVisSet& set, u32 areaIdx) {}
void CCubeRenderer::DisablePVS() {}
void CCubeRenderer::RemoveStaticGeometry(const std::vector<CMetroidModelInstance>* 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<zeus::CVector2f, zeus::CVector2f> CCubeRenderer::SetViewportOrtho(bool centered, float znear, float zfar) {
return std::pair<zeus::CVector2f, zeus::CVector2f>();
}
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<CModel>* 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<CLight>& lights) {}
void CCubeRenderer::AllocatePhazonSuitMaskTexture() {}
void CCubeRenderer::DrawPhazonSuitIndirectEffect(const zeus::CColor& nonIndirectMod,
const TLockedToken<CTexture>& 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<u32>& modelBits, const zeus::CAABox& aabb) const {}
int CCubeRenderer::DrawOverlappingWorldModelIDs(int alphaVal, const std::vector<u32>& modelBits,
const zeus::CAABox& aabb) {
return 0;
}
void CCubeRenderer::DrawOverlappingWorldModelShadows(int alphaVal, const std::vector<u32>& modelBits,
const zeus::CAABox& aabb, float alpha) {}
} // namespace metaforce } // namespace metaforce

View File

@ -9,7 +9,6 @@
#include <zeus/Math.hpp> #include <zeus/Math.hpp>
namespace metaforce { namespace metaforce {
CGraphics::CProjectionState CGraphics::g_Proj; CGraphics::CProjectionState CGraphics::g_Proj;
CFogState CGraphics::g_Fog; CFogState CGraphics::g_Fog;
std::array<zeus::CColor, 3> CGraphics::g_ColorRegs{}; std::array<zeus::CColor, 3> CGraphics::g_ColorRegs{};
@ -37,6 +36,8 @@ u32 CGraphics::g_FrameCounter = 0;
u32 CGraphics::g_Framerate = 0; u32 CGraphics::g_Framerate = 0;
u32 CGraphics::g_FramesPast = 0; u32 CGraphics::g_FramesPast = 0;
frame_clock::time_point CGraphics::g_FrameStartTime = frame_clock::now(); 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; // bool CGraphics::g_commitAsLazy = false;
const std::array<zeus::CMatrix3f, 6> CGraphics::skCubeBasisMats{{ const std::array<zeus::CMatrix3f, 6> 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; 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) { void CGraphics::SetBlendMode(ERglBlendMode mode, ERglBlendFactor src, ERglBlendFactor dst, ERglLogicOp op) {

View File

@ -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) { void CModel::DrawSortedParts(CModelFlags flags) {
if ((flags.x2_flags & 0x20) != 0) { if ((flags.x2_flags & 0x20) != 0) {
x28_modelInst->DrawNormal(nullptr, nullptr, ESurfaceSelection::Sorted); x28_modelInst->DrawNormal(nullptr, nullptr, ESurfaceSelection::Sorted);

View File

@ -31,5 +31,4 @@ public:
void RenderIdBuffer(const zeus::CAABox& aabb, const CStateManager& mgr, CPlayer& player); void RenderIdBuffer(const zeus::CAABox& aabb, const CStateManager& mgr, CPlayer& player);
void Render(const CStateManager& mgr, float alpha); void Render(const CStateManager& mgr, float alpha);
}; };
} // namespace metaforce } // namespace metaforce

View File

@ -142,7 +142,7 @@ enum class ZComp : uint8_t {
void set_cull_mode(metaforce::ERglCullMode mode) noexcept; void set_cull_mode(metaforce::ERglCullMode mode) noexcept;
void set_blend_mode(metaforce::ERglBlendMode mode, metaforce::ERglBlendFactor src, metaforce::ERglBlendFactor dst, void set_blend_mode(metaforce::ERglBlendMode mode, metaforce::ERglBlendFactor src, metaforce::ERglBlendFactor dst,
metaforce::ERglLogicOp op) noexcept; 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 // Model state
void set_alpha_discard(bool v); void set_alpha_discard(bool v);

View File

@ -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); } 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 { void update_model_view(const zeus::CMatrix4f& mv, const zeus::CMatrix4f& mv_inv) noexcept {
g_mv = mv; g_mv = mv;
g_mvInv = mv_inv; g_mvInv = mv_inv;