From 79d90f46d3e6e9f58b6fea09f27a77fa278da893 Mon Sep 17 00:00:00 2001 From: Jack Andersen Date: Wed, 16 Mar 2016 16:18:01 -1000 Subject: [PATCH] CGuiModel imps --- DataSpec/DNAMP1/FRME.hpp | 4 +- Runtime/CToken.hpp | 4 +- Runtime/Graphics/CModel.hpp | 13 +- Runtime/Graphics/CModelBoo.cpp | 8 ++ Runtime/GuiSys/CGuiFrame.cpp | 12 +- Runtime/GuiSys/CGuiLight.hpp | 1 + Runtime/GuiSys/CGuiModel.cpp | 120 +++++++++++++++++- Runtime/GuiSys/CGuiModel.hpp | 11 +- Runtime/GuiSys/CGuiObject.cpp | 2 +- Runtime/GuiSys/CGuiObject.hpp | 2 +- Runtime/GuiSys/CGuiWidget.cpp | 7 +- Runtime/GuiSys/CGuiWidget.hpp | 17 ++- Runtime/GuiSys/CGuiWidgetDrawParams.hpp | 10 -- ...DrawParams.cpp => CGuiWidgetDrawParms.cpp} | 0 Runtime/GuiSys/CGuiWidgetDrawParms.hpp | 14 ++ Runtime/GuiSys/CMakeLists.txt | 4 +- 16 files changed, 190 insertions(+), 39 deletions(-) delete mode 100644 Runtime/GuiSys/CGuiWidgetDrawParams.hpp rename Runtime/GuiSys/{CGuiWidgetDrawParams.cpp => CGuiWidgetDrawParms.cpp} (100%) create mode 100644 Runtime/GuiSys/CGuiWidgetDrawParms.hpp diff --git a/DataSpec/DNAMP1/FRME.hpp b/DataSpec/DNAMP1/FRME.hpp index cbd71212a..2ec24edc7 100644 --- a/DataSpec/DNAMP1/FRME.hpp +++ b/DataSpec/DNAMP1/FRME.hpp @@ -31,7 +31,7 @@ struct FRME : BigDNA Value useAnimController; Value defaultVisible; Value defaultActive; - Value unk4; + Value cullFaces; Value color; Value modelDrawFlags; } header; @@ -114,7 +114,7 @@ struct FRME : BigDNA }; Value blendMode; - Value lightMode; + Value lightMask; }; struct LITEInfo : IWidgetInfo diff --git a/Runtime/CToken.hpp b/Runtime/CToken.hpp index ba5337687..2ee002574 100644 --- a/Runtime/CToken.hpp +++ b/Runtime/CToken.hpp @@ -249,8 +249,8 @@ public: TLockedToken() : m_obj(nullptr) {} TLockedToken(const CToken& other) : TToken(other) {m_obj = TToken::GetObj();} TLockedToken(CToken&& other) : TToken(std::move(other)) {m_obj = TToken::GetObj();} - T* GetObj() {return m_obj;} - T* operator->() {return m_obj;} + T* GetObj() const {return m_obj;} + T* operator->() const {return m_obj;} }; } diff --git a/Runtime/Graphics/CModel.hpp b/Runtime/Graphics/CModel.hpp index 327ed265d..8f2e0e988 100644 --- a/Runtime/Graphics/CModel.hpp +++ b/Runtime/Graphics/CModel.hpp @@ -9,16 +9,23 @@ namespace urde struct CModelFlags { - u8 f1; + u8 f1; /* Blend state 3/5 enable additive */ u8 f2; - u16 f3; - zeus::CColor color; + u16 f3; /* Depth state */ + zeus::CColor color; /* Set into kcolor slot specified by material */ + + /* depth flags + 0x8: greater + 0x10: non-inclusive + */ }; class CModel { public: void Draw(const CModelFlags& flags) const; + void Touch(int) const; + bool IsLoaded(int) const; }; } diff --git a/Runtime/Graphics/CModelBoo.cpp b/Runtime/Graphics/CModelBoo.cpp index 42497fc01..86bf70066 100644 --- a/Runtime/Graphics/CModelBoo.cpp +++ b/Runtime/Graphics/CModelBoo.cpp @@ -7,4 +7,12 @@ void CModel::Draw(const CModelFlags& flags) const { } +void CModel::Touch(int) const +{ +} + +bool CModel::IsLoaded(int) const +{ +} + } diff --git a/Runtime/GuiSys/CGuiFrame.cpp b/Runtime/GuiSys/CGuiFrame.cpp index 4330b69b9..bce39ccae 100644 --- a/Runtime/GuiSys/CGuiFrame.cpp +++ b/Runtime/GuiSys/CGuiFrame.cpp @@ -358,12 +358,18 @@ void CGuiFrame::EnableLights(u32 lights) const CGraphics::DisableAllLights(); zeus::CColor accumColor(zeus::CColor::skBlack); ERglLight lightId = ERglLight::Zero; + int idx = 0; for (CGuiLight* light : xa0_lights) { - // accumulate color - CGraphics::LoadLight(lightId, light->BuildLight()); - CGraphics::EnableLight(lightId); + if ((lights & (1 << idx)) != 0) + { + // accumulate color + accumColor += light->GetColor(); + CGraphics::LoadLight(lightId, light->BuildLight()); + CGraphics::EnableLight(lightId); + } ++reinterpret_cast&>(lightId); + ++idx; } if (xa0_lights.empty()) CGraphics::SetAmbientColor(zeus::CColor::skWhite); diff --git a/Runtime/GuiSys/CGuiLight.hpp b/Runtime/GuiSys/CGuiLight.hpp index d59df386b..89cc3d74e 100644 --- a/Runtime/GuiSys/CGuiLight.hpp +++ b/Runtime/GuiSys/CGuiLight.hpp @@ -27,6 +27,7 @@ public: CLight BuildLight() const; void SetIsVisible(bool vis); u32 GetLoadedIdx() const {return x118_loadedIdx;} + const zeus::CColor& GetColor() const {return x11c_color;} static CGuiLight* Create(CGuiFrame* frame, CInputStream& in, bool); }; diff --git a/Runtime/GuiSys/CGuiModel.cpp b/Runtime/GuiSys/CGuiModel.cpp index 3ab9ca720..6ba0f50f7 100644 --- a/Runtime/GuiSys/CGuiModel.cpp +++ b/Runtime/GuiSys/CGuiModel.cpp @@ -3,12 +3,14 @@ #include "CGuiSys.hpp" #include "CSimplePool.hpp" #include "CGuiAnimController.hpp" +#include "CGuiWidgetDrawParms.hpp" +#include "Graphics/CGraphics.hpp" namespace urde { -CGuiModel::CGuiModel(const CGuiWidgetParms& parms, TResId modelId, u32 lightMode, bool flag) -: CGuiWidget(parms), x108_modelId(modelId), x10c_lightMode(lightMode) +CGuiModel::CGuiModel(const CGuiWidgetParms& parms, TResId modelId, u32 lightMask, bool flag) +: CGuiWidget(parms), x108_modelId(modelId), x10c_lightMask(lightMask) { if (!flag || (modelId & 0xffff) == 0xffff || parms.x0_frame->GetGuiSys().GetUsageMode() == CGuiSys::EUsageMode::Two) @@ -17,15 +19,125 @@ CGuiModel::CGuiModel(const CGuiWidgetParms& parms, TResId modelId, u32 lightMode xf8_model = parms.x0_frame->GetGuiSys().GetResStore().GetObj({SBIG('CMDL'), modelId}); } +std::vector CGuiModel::GetModelAssets() const +{ + return {x108_modelId}; +} + +bool CGuiModel::GetIsFinishedLoadingWidgetSpecific() const +{ + if (!xf8_model) + return true; + CModel* model = xf8_model.GetObj(); + if (!model) + return false; + model->Touch(0); + return model->IsLoaded(0); +} + +void CGuiModel::Touch() const +{ + CModel* model = xf8_model.GetObj(); + if (model) + model->Touch(0); +} + +void CGuiModel::Draw(const CGuiWidgetDrawParms& parms) const +{ + CGraphics::SetModelMatrix(x34_worldXF); + if (!xf8_model) + return; + if (!GetIsFinishedLoading()) + return; + CModel* model = xf8_model.GetObj(); + if (!model) + return; + + if (GetIsVisible()) + { + zeus::CColor moduCol = xb4_; + moduCol.a *= parms.x0_alphaMod; + xc8_frame->EnableLights(x10c_lightMask); + if (xf6_29_cullFaces) + CGraphics::SetCullMode(ERglCullMode::Front); + + switch (xc4_drawFlags) + { + case EGuiModelDrawFlags::Zero: + { + CModelFlags flags; + flags.f1 = 0; + flags.f2 = 0; + flags.f3 = 3; + flags.color = zeus::CColor::skWhite; + model->Draw(flags); + break; + } + case EGuiModelDrawFlags::One: + { + CModelFlags flags; + flags.f1 = 1; + flags.f2 = 0; + flags.f3 = 3; + flags.color = moduCol; + model->Draw(flags); + break; + } + case EGuiModelDrawFlags::Two: + { + CModelFlags flags; + flags.f1 = 4; + flags.f2 = 0; + flags.f3 = (xf7_24_ << 1) | xf6_31_; + flags.color = moduCol; + model->Draw(flags); + break; + } + case EGuiModelDrawFlags::Three: + { + CModelFlags flags; + flags.f1 = 3; + flags.f2 = 0; + flags.f3 = (xf7_24_ << 1) | xf6_31_; + flags.color = moduCol; + model->Draw(flags); + break; + } + case EGuiModelDrawFlags::Four: + { + CModelFlags flags; + flags.f1 = 4; + flags.f2 = 0; + flags.f3 = xf6_31_; + flags.color = moduCol; + model->Draw(flags); + + flags.f1 = 5; + flags.f2 = 0; + flags.f3 = (xf7_24_ << 1) | xf6_31_; + flags.color = moduCol; + model->Draw(flags); + break; + } + default: break; + } + + if (xf6_29_cullFaces) + CGraphics::SetCullMode(ERglCullMode::None); + } + + CGuiWidget::Draw(parms); +} + CGuiModel* CGuiModel::Create(CGuiFrame* frame, CInputStream& in, bool flag) { CGuiWidgetParms parms = ReadWidgetHeader(frame, in, flag); TResId model = in.readUint32Big(); in.readUint32Big(); - u32 lightMode = in.readUint32Big(); + u32 lightMask = in.readUint32Big(); - CGuiModel* ret = new CGuiModel(parms, model, lightMode, flag); + CGuiModel* ret = new CGuiModel(parms, model, lightMask, flag); ret->ParseBaseInfo(frame, in, parms); return ret; } diff --git a/Runtime/GuiSys/CGuiModel.hpp b/Runtime/GuiSys/CGuiModel.hpp index 5892b6c62..bc63835c1 100644 --- a/Runtime/GuiSys/CGuiModel.hpp +++ b/Runtime/GuiSys/CGuiModel.hpp @@ -12,9 +12,16 @@ class CGuiModel : public CGuiWidget { TLockedToken xf8_model; TResId x108_modelId; - u32 x10c_lightMode; + u32 x10c_lightMask; public: - CGuiModel(const CGuiWidgetParms& parms, TResId modelId, u32 lightMode, bool flag); + CGuiModel(const CGuiWidgetParms& parms, TResId modelId, u32 lightMask, bool flag); + FourCC GetWidgetTypeID() const {return FOURCC('MODL');} + + std::vector GetModelAssets() const; + bool GetIsFinishedLoadingWidgetSpecific() const; + void Touch() const; + void Draw(const CGuiWidgetDrawParms& parms) const; + static CGuiModel* Create(CGuiFrame* frame, CInputStream& in, bool); }; diff --git a/Runtime/GuiSys/CGuiObject.cpp b/Runtime/GuiSys/CGuiObject.cpp index c94099a26..6c3bcf5cb 100644 --- a/Runtime/GuiSys/CGuiObject.cpp +++ b/Runtime/GuiSys/CGuiObject.cpp @@ -1,5 +1,5 @@ #include "CGuiObject.hpp" -#include "CGuiWidgetDrawParams.hpp" +#include "CGuiWidgetDrawParms.hpp" namespace urde { diff --git a/Runtime/GuiSys/CGuiObject.hpp b/Runtime/GuiSys/CGuiObject.hpp index fb8e89bf7..3d7388353 100644 --- a/Runtime/GuiSys/CGuiObject.hpp +++ b/Runtime/GuiSys/CGuiObject.hpp @@ -7,7 +7,7 @@ namespace urde { -class CGuiWidgetDrawParms; +struct CGuiWidgetDrawParms; class CGuiMessage; class CGuiFunctionDef; struct CGuiControllerInfo; diff --git a/Runtime/GuiSys/CGuiWidget.cpp b/Runtime/GuiSys/CGuiWidget.cpp index cf44264dd..01069b772 100644 --- a/Runtime/GuiSys/CGuiWidget.cpp +++ b/Runtime/GuiSys/CGuiWidget.cpp @@ -27,7 +27,8 @@ CGuiWidget::CGuiWidget(const CGuiWidgetParms& parms) xc4_drawFlags(parms.x14_drawFlags), xc8_frame(parms.x0_frame), xf6_24_pg(parms.xd_g), xf6_25_isVisible(parms.xa_defaultVisible), xf6_26_isActive(parms.xb_defaultActive), - xf6_27_(true), xf6_28_eventLock(false), xf6_29_pf(parms.xc_f), xf6_30_(false), + xf6_27_(true), xf6_28_eventLock(false), + xf6_29_cullFaces(parms.xc_cullFaces), xf6_30_(false), xf6_31_(true), xf7_24_(false), xf7_25_(true) { if (parms.x4_useAnimController) @@ -46,14 +47,14 @@ CGuiWidget::ReadWidgetHeader(CGuiFrame* frame, CInputStream& in, bool flag) bool useAnimController = in.readBool(); bool defaultVis = in.readBool(); bool defaultActive = in.readBool(); - bool f = in.readBool(); + bool cullFaces = in.readBool(); zeus::CColor color; color.readRGBABig(in); EGuiModelDrawFlags df = EGuiModelDrawFlags(in.readUint32Big()); return CGuiWidget::CGuiWidgetParms(frame, useAnimController, selfId, parentId, defaultVis, defaultActive, - f, color, df, true, flag); + cullFaces, color, df, true, flag); } CGuiWidget* CGuiWidget::Create(CGuiFrame* frame, CInputStream& in, bool flag) diff --git a/Runtime/GuiSys/CGuiWidget.hpp b/Runtime/GuiSys/CGuiWidget.hpp index 8bde1b098..031e5951d 100644 --- a/Runtime/GuiSys/CGuiWidget.hpp +++ b/Runtime/GuiSys/CGuiWidget.hpp @@ -53,7 +53,11 @@ class CGuiWidget : public CGuiObject public: enum class EGuiModelDrawFlags { - Two = 2 + Zero = 0, + One = 1, + Two = 2, + Three = 3, + Four = 4 }; struct CGuiWidgetParms { @@ -63,17 +67,18 @@ public: s16 x8_parentId; bool xa_defaultVisible; bool xb_defaultActive; - bool xc_f; + bool xc_cullFaces; bool xd_g; bool xe_h; zeus::CColor x10_color; EGuiModelDrawFlags x14_drawFlags; CGuiWidgetParms(CGuiFrame* frame, bool useAnimController, s16 selfId, s16 parentId, - bool defaultVisible, bool defaultActive, - bool f, const zeus::CColor& color, EGuiModelDrawFlags drawFlags, bool g, bool h) + bool defaultVisible, bool defaultActive, bool cullFaces, + const zeus::CColor& color, EGuiModelDrawFlags drawFlags, + bool g, bool h) : x0_frame(frame), x4_useAnimController(useAnimController), x6_selfId(selfId), x8_parentId(parentId), xa_defaultVisible(defaultVisible), xb_defaultActive(defaultActive), - xc_f(f), xd_g(g), xe_h(h), x10_color(color), x14_drawFlags(drawFlags) {} + xc_cullFaces(cullFaces), xd_g(g), xe_h(h), x10_color(color), x14_drawFlags(drawFlags) {} }; static void LoadWidgetFnMap(); virtual FourCC GetWidgetTypeID() const {return FOURCC('BWIG');} @@ -96,7 +101,7 @@ protected: bool xf6_26_isActive : 1; bool xf6_27_ : 1; bool xf6_28_eventLock : 1; - bool xf6_29_pf : 1; + bool xf6_29_cullFaces : 1; bool xf6_30_ : 1; bool xf6_31_ : 1; bool xf7_24_ : 1; diff --git a/Runtime/GuiSys/CGuiWidgetDrawParams.hpp b/Runtime/GuiSys/CGuiWidgetDrawParams.hpp deleted file mode 100644 index 733feb99f..000000000 --- a/Runtime/GuiSys/CGuiWidgetDrawParams.hpp +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef __URDE_CGUIWIDGETDRAWPARAMS_HPP__ -#define __URDE_CGUIWIDGETDRAWPARAMS_HPP__ - -namespace urde -{ - - -} - -#endif // __URDE_CGUIWIDGETDRAWPARAMS_HPP__ diff --git a/Runtime/GuiSys/CGuiWidgetDrawParams.cpp b/Runtime/GuiSys/CGuiWidgetDrawParms.cpp similarity index 100% rename from Runtime/GuiSys/CGuiWidgetDrawParams.cpp rename to Runtime/GuiSys/CGuiWidgetDrawParms.cpp diff --git a/Runtime/GuiSys/CGuiWidgetDrawParms.hpp b/Runtime/GuiSys/CGuiWidgetDrawParms.hpp new file mode 100644 index 000000000..53682bed8 --- /dev/null +++ b/Runtime/GuiSys/CGuiWidgetDrawParms.hpp @@ -0,0 +1,14 @@ +#ifndef __URDE_CGUIWIDGETDRAWPARMS_HPP__ +#define __URDE_CGUIWIDGETDRAWPARMS_HPP__ + +namespace urde +{ + +struct CGuiWidgetDrawParms +{ + float x0_alphaMod; +}; + +} + +#endif // __URDE_CGUIWIDGETDRAWPARMS_HPP__ diff --git a/Runtime/GuiSys/CMakeLists.txt b/Runtime/GuiSys/CMakeLists.txt index 430b2cc3d..2b31ae4e8 100644 --- a/Runtime/GuiSys/CMakeLists.txt +++ b/Runtime/GuiSys/CMakeLists.txt @@ -44,8 +44,8 @@ add_library(RuntimeCommonGuiSys CGuiTextSupport.cpp CGuiTextSupport.hpp CGuiWidget.cpp - CGuiWidgetDrawParams.cpp - CGuiWidgetDrawParams.hpp + CGuiWidgetDrawParms.cpp + CGuiWidgetDrawParms.hpp CGuiWidget.hpp CMakeLists.txt CSplashScreen.cpp