Add almost matched CGameCubeDoll

This commit is contained in:
Henrique Gemignani Passos Lima 2022-11-14 04:18:45 +02:00
parent 7b161ca498
commit 25b4d12207
No known key found for this signature in database
GPG Key ID: E224F951761145F8
9 changed files with 168 additions and 35 deletions

View File

@ -386,7 +386,7 @@ LIBS = [
"MetroidPrime/CArtifactDoll", "MetroidPrime/CArtifactDoll",
"MetroidPrime/CProjectedShadow", "MetroidPrime/CProjectedShadow",
["MetroidPrime/CPreFrontEnd", True], ["MetroidPrime/CPreFrontEnd", True],
"MetroidPrime/CGameCubeDoll", ["MetroidPrime/CGameCubeDoll", False],
["MetroidPrime/ScriptObjects/CScriptProjectedShadow", False], ["MetroidPrime/ScriptObjects/CScriptProjectedShadow", False],
"MetroidPrime/ScriptObjects/CEnergyBall", "MetroidPrime/ScriptObjects/CEnergyBall",
["MetroidPrime/Enemies/CMetroidPrimeProjectile", False], ["MetroidPrime/Enemies/CMetroidPrimeProjectile", False],

View File

@ -145,6 +145,7 @@ public:
static const CViewport& GetViewport() { return mViewport; } static const CViewport& GetViewport() { return mViewport; }
static const CTransform4f& GetViewMatrix() { return mViewMatrix; } static const CTransform4f& GetViewMatrix() { return mViewMatrix; }
static const CTransform4f& GetModelMatrix() { return mModelMatrix; } static const CTransform4f& GetModelMatrix() { return mModelMatrix; }
static void SetViewPointMatrix(const CTransform4f&);
static void SetBrightness(float b) { mBrightness = b; } static void SetBrightness(float b) { mBrightness = b; }
static float GetSecondsMod900(); static float GetSecondsMod900();

View File

@ -0,0 +1,12 @@
#ifndef _CMODEL
#define _CMODEL
class CModelFlags;
class CModel {
public:
void Touch(int) const;
void Draw(const CModelFlags&) const;
};
#endif // _CMODEL

View File

@ -22,39 +22,39 @@ class CModel;
class CCubeRenderer : public IRenderer, public IWeaponRenderer { class CCubeRenderer : public IRenderer, public IWeaponRenderer {
public: public:
virtual ~CCubeRenderer(); ~CCubeRenderer() override;
// TODO types // TODO types
virtual void AddStaticGeometry(); void AddStaticGeometry() override;
virtual void EnablePVS(); void EnablePVS() override;
virtual void DisablePVS(); void DisablePVS() override;
virtual void RemoveStaticGeometry(); void RemoveStaticGeometry() override;
virtual void DrawUnsortedGeometry(); void DrawUnsortedGeometry() override;
virtual void DrawSortedGeometry(); void DrawSortedGeometry() override;
virtual void DrawStaticGeometry(); void DrawStaticGeometry() override;
virtual void DrawAreaGeometry(); void DrawAreaGeometry() override;
virtual void PostRenderFogs(); void PostRenderFogs() override;
virtual void SetModelMatrix(const CTransform4f& xf); void SetModelMatrix(const CTransform4f& xf) override;
virtual void AddParticleGen(const CParticleGen& gen); void AddParticleGen(const CParticleGen& gen) override;
virtual void AddParticleGen2(); void AddParticleGen2() override;
virtual void AddPlaneObject(); void AddPlaneObject() override;
virtual void AddDrawable(const void* obj, const CVector3f& pos, const CAABox& bounds, int mode, void AddDrawable(const void* obj, const CVector3f& pos, const CAABox& bounds, int mode,
IRenderer::EDrawableSorting sorting); IRenderer::EDrawableSorting sorting) override;
virtual void SetDrawableCallback(); void SetDrawableCallback() override;
virtual void SetWorldViewpoint(); void SetWorldViewpoint() override;
virtual void SetPerspective1(); void SetPerspective1(float, float, float, float, float) override;
virtual void SetPerspective2(); void SetPerspective2() override;
virtual rstl::pair< CVector2f, CVector2f > SetViewportOrtho(bool centered, float znear, rstl::pair< CVector2f, CVector2f > SetViewportOrtho(bool centered, float znear,
float zfar); float zfar) override;
virtual void SetClippingPlanes(); void SetClippingPlanes() override;
virtual void SetViewport(); void SetViewport() override;
virtual void SetDepthReadWrite(bool read, bool update); void SetDepthReadWrite(bool read, bool update) override;
virtual void SetBlendMode_AdditiveAlpha(); void SetBlendMode_AdditiveAlpha() override;
virtual void SetBlendMode_AlphaBlended(); void SetBlendMode_AlphaBlended() override;
virtual void SetBlendMode_NoColorWrite(); void SetBlendMode_NoColorWrite() override;
virtual void SetBlendMode_ColorMultiply(); void SetBlendMode_ColorMultiply() override;
virtual void SetBlendMode_InvertDst(); void SetBlendMode_InvertDst() override;
virtual void SetBlendMode_InvertSrc(); void SetBlendMode_InvertSrc() override;
virtual void SetBlendMode_AdditiveDestColor(); void SetBlendMode_AdditiveDestColor() override;
virtual void SetDebugOption(); virtual void SetDebugOption();
virtual void BeginScene(); virtual void BeginScene();
virtual void EndScene(); virtual void EndScene();
@ -80,7 +80,7 @@ public:
virtual void SetWireframeFlags(); virtual void SetWireframeFlags();
virtual void SetWorldFog(); virtual void SetWorldFog();
virtual void RenderFogVolume(const CColor&, const CAABox&, const TLockedToken< CModel >*, virtual void RenderFogVolume(const CColor&, const CAABox&, const TLockedToken< CModel >*,
const CSkinnedModel*); const CSkinnedModel*);
virtual void SetThermal(); virtual void SetThermal();
virtual void SetThermalColdScale(); virtual void SetThermalColdScale();
virtual void DoThermalBlendCold(); virtual void DoThermalBlendCold();

View File

@ -41,7 +41,7 @@ public:
IRenderer::EDrawableSorting sorting); IRenderer::EDrawableSorting sorting);
virtual void SetDrawableCallback(); virtual void SetDrawableCallback();
virtual void SetWorldViewpoint(); virtual void SetWorldViewpoint();
virtual void SetPerspective1(); virtual void SetPerspective1(float, float, float, float, float);
virtual void SetPerspective2(); virtual void SetPerspective2();
virtual rstl::pair< CVector2f, CVector2f > SetViewportOrtho(bool centered, float znear, virtual rstl::pair< CVector2f, CVector2f > SetViewportOrtho(bool centered, float znear,
float zfar); float zfar);

View File

@ -26,6 +26,9 @@ public:
void BuildConstantAmbientLighting(const CColor&); void BuildConstantAmbientLighting(const CColor&);
bool BuildAreaLightList(const CStateManager& mgr, const CGameArea& area, const CAABox& bounds); bool BuildAreaLightList(const CStateManager& mgr, const CGameArea& area, const CAABox& bounds);
void BuildDynamicLightList(const CStateManager& mgr, const CAABox& bounds); void BuildDynamicLightList(const CStateManager& mgr, const CAABox& bounds);
void BuildFakeLightList(const rstl::vector<CLight>&, const CColor&);
void ActivateLights() const;
bool GetNeedsRelight() const { return x298_24_dirty == TRUE; } bool GetNeedsRelight() const { return x298_24_dirty == TRUE; }
bool HasShadowLight() const { return x29c_shadowLightArrIdx != -1; } bool HasShadowLight() const { return x29c_shadowLightArrIdx != -1; }

View File

@ -0,0 +1,34 @@
#ifndef _CGAMECUBEDOLL
#define _CGAMECUBEDOLL
#include "Kyoto/TToken.hpp"
#include "rstl/single_ptr.hpp"
#include "rstl/vector.hpp"
class CActorLights;
class CModel;
class CLight;
class CGameCubeDoll {
public:
CGameCubeDoll();
~CGameCubeDoll();
void Update(float dt);
void Draw(float alpha);
void Touch();
bool CheckLoadComplete();
bool IsLoaded() const;
private:
CToken x0_model;
rstl::vector< CLight > x8_lights;
rstl::single_ptr< CActorLights > x18_actorLights;
float x1c_fader;
bool x20_24_loaded : 1;
void UpdateActorLights();
};
#endif // _CGAMECUBEDOLL

View File

@ -47,6 +47,8 @@ public:
x0_allocator.allocate(xc_items, x4_count); x0_allocator.allocate(xc_items, x4_count);
uninitialized_fill_n(xc_items, count, v); uninitialized_fill_n(xc_items, count, v);
} }
vector(int count, const T& v, const Alloc& alloc);
vector(const vector& other) : x4_count(other.x4_count), x8_capacity(other.x8_capacity) { vector(const vector& other) : x4_count(other.x4_count), x8_capacity(other.x8_capacity) {
if (other.x4_count == 0 && other.x8_capacity == 0) { if (other.x4_count == 0 && other.x8_capacity == 0) {
xc_items = nullptr; xc_items = nullptr;

View File

@ -0,0 +1,81 @@
#include "MetroidPrime/CGameCubeDoll.hpp"
#include "MetroidPrime/CActorLights.hpp"
#include "Kyoto/Graphics/CGraphics.hpp"
#include "Kyoto/Graphics/CLight.hpp"
#include "Kyoto/Graphics/CModel.hpp"
#include "Kyoto/Graphics/CModelFlags.hpp"
#include "Kyoto/Math/CMath.hpp"
#include "Kyoto/Math/CRelAngle.hpp"
#include "MetaRender/CCubeRenderer.hpp"
#include "rstl/math.hpp"
CGameCubeDoll::CGameCubeDoll()
: x0_model(gpSimplePool->GetObj("CMDL_GameCube"))
, x8_lights(1, CLight::BuildDirectional(CVector3f::Forward(), CColor(0xFFFFFFFF)), rstl::rmemory_allocator())
, x18_actorLights(new CActorLights(8, CVector3f::Zero(), 4, 4, 0.1f, false, false, false))
, x1c_fader(0.0f)
, x20_24_loaded(false) {
x0_model.Lock();
}
bool CGameCubeDoll::CheckLoadComplete() {
if (IsLoaded())
return true;
if (!x0_model.IsLoaded()) {
return false;
}
x20_24_loaded = true;
return true;
}
bool CGameCubeDoll::IsLoaded() const { return x20_24_loaded != false; }
CGameCubeDoll::~CGameCubeDoll() {}
void CGameCubeDoll::UpdateActorLights() {
(CVector3f::Forward() + CVector3f::Right() * 0.25f + CVector3f::Down() * 0.1f).AsNormalized();
x8_lights[0] =
CLight::BuildDirectional(CVector3f::Forward(), CColor(uchar(0xFF), uchar(0xFF), uchar(0xFF)));
x18_actorLights->BuildFakeLightList(x8_lights, CColor(0.25f, 0.25f, 0.25f, 1.f));
}
void CGameCubeDoll::Touch() {
if (!CheckLoadComplete())
return;
TToken< CModel >(x0_model)->Touch(0);
}
void CGameCubeDoll::Update(float dt) {
if (!CheckLoadComplete())
return;
x1c_fader = rstl::min_val(1.f, 2.f * dt + x1c_fader);
UpdateActorLights();
}
void CGameCubeDoll::Draw(float alpha) {
if (!IsLoaded())
return;
float alphaFader = alpha * x1c_fader;
gpRender->SetPerspective1(55.f, CGraphics::GetViewport().mWidth, CGraphics::GetViewport().mHeight,
0.2f, 4096.f);
CGraphics::SetViewPointMatrix(CTransform4f::Translate(0.f, -2.f, 0.f));
x18_actorLights->ActivateLights();
float f = CGraphics::GetSecondsMod900() * 360.f;
CGraphics::SetModelMatrix(CTransform4f::RotateZ(CRelAngle::FromDegrees(-(f * 0.25f))) *
CTransform4f::Scale(0.2f));
TToken< CModel > model(x0_model);
CModelFlags flags(CModelFlags::kT_Blend, alphaFader);
model->Draw(flags);
CGraphics::DisableAllLights();
}