CGuiLight imps

This commit is contained in:
Jack Andersen 2016-03-16 10:49:35 -10:00
parent 22ca6d025b
commit a81bc3c7a2
17 changed files with 388 additions and 32 deletions

View File

@ -173,6 +173,62 @@ size_t FRME::Widget::CAMRInfo::binarySize(size_t __isz) const
return __isz + 4;
}
void FRME::Widget::LITEInfo::read(athena::io::IStreamReader& __dna_reader)
{
IWidgetInfo::read(__dna_reader);
/* type */
type = ELightType(__dna_reader.readUint32Big());
/* distC */
distC = __dna_reader.readFloatBig();
/* distL */
distL = __dna_reader.readFloatBig();
/* distQ */
distQ = __dna_reader.readFloatBig();
/* angC */
angC = __dna_reader.readFloatBig();
/* angL */
angL = __dna_reader.readFloatBig();
/* angQ */
angQ = __dna_reader.readFloatBig();
/* loadedIdx */
loadedIdx = __dna_reader.readUint32Big();
/* cutoff */
if (type == ELightType::Spot)
cutoff = __dna_reader.readFloatBig();
}
void FRME::Widget::LITEInfo::write(athena::io::IStreamWriter& __dna_writer) const
{
IWidgetInfo::write(__dna_writer);
/* type */
__dna_writer.writeUint32Big(atUint32(type));
/* distC */
__dna_writer.writeFloatBig(distC);
/* distL */
__dna_writer.writeFloatBig(distL);
/* distQ */
__dna_writer.writeFloatBig(distQ);
/* angC */
__dna_writer.writeFloatBig(angC);
/* angL */
__dna_writer.writeFloatBig(angL);
/* angQ */
__dna_writer.writeFloatBig(angQ);
/* loadedIdx */
__dna_writer.writeUint32Big(loadedIdx);
/* cutoff */
if (type == ELightType::Spot)
__dna_writer.writeFloatBig(cutoff);
}
size_t FRME::Widget::LITEInfo::binarySize(size_t __isz) const
{
__isz = IWidgetInfo::binarySize(__isz);
return __isz + ((type == ELightType::Spot) ? 36 : 32);
}
void FRME::Widget::TXPNInfo::read(athena::io::IStreamReader& __dna_reader)
{
IWidgetInfo::read(__dna_reader);

View File

@ -119,15 +119,25 @@ struct FRME : BigDNA
struct LITEInfo : IWidgetInfo
{
DECL_DNA
Value<atUint32> unk1;
Value<float> unk2;
Value<float> unk3;
Value<float> unk4;
Value<float> unk5;
Value<float> unk6;
Value<float> unk7;
Value<atUint32> unk8;
DECL_EXPLICIT_DNA
enum class ELightType : atUint32
{
Spot = 0,
Point = 1,
Directional = 2,
LocalAmbient = 3,
Custom = 4,
};
Value<ELightType> type;
Value<float> distC;
Value<float> distL;
Value<float> distQ;
Value<float> angC;
Value<float> angL;
Value<float> angQ;
Value<atUint32> loadedIdx;
Value<float> cutoff; /* Spot only */
};
struct ENRGInfo : IWidgetInfo

View File

@ -40,6 +40,7 @@ target_link_libraries(urde
RuntimeCommonCharacter
RuntimeCommonInput
RuntimeCommonParticle
RuntimeCommonGuiSys
RuntimeCommonGraphics
RuntimeCommonAudio
RuntimeCommon

View File

@ -5,6 +5,7 @@
#include "Runtime/Particle/CGenDescription.hpp"
#include "Runtime/Particle/CElectricDescription.hpp"
#include "Runtime/Particle/CSwooshDescription.hpp"
#include "Runtime/GuiSys/CGuiFrame.hpp"
#include "Runtime/Graphics/CModel.hpp"
#include "Runtime/Graphics/CTexture.hpp"
@ -13,8 +14,9 @@ namespace urde
ProjectResourceFactory::ProjectResourceFactory()
{
m_factoryMgr.AddFactory(hecl::FOURCC('TXTR'), urde::FTextureFactory);
m_factoryMgr.AddFactory(hecl::FOURCC('PART'), urde::FParticleFactory);
m_factoryMgr.AddFactory(FOURCC('TXTR'), urde::FTextureFactory);
m_factoryMgr.AddFactory(FOURCC('PART'), urde::FParticleFactory);
m_factoryMgr.AddFactory(FOURCC('FRME'), urde::RGuiFrameFactoryInGame);
}
void ProjectResourceFactory::BuildObjectMap(const hecl::Database::Project::ProjectDataSpec &spec)

View File

@ -1,24 +1,71 @@
#include "CLight.hpp"
#include <cfloat>
namespace urde
{
static const zeus::CVector3f kDefaultPosition(0.f, 0.f, 0.f);
static const zeus::CVector3f kDefaultDirection(0.f, -1.f, 0.f);
float CLight::CalculateLightRadius() const
{
if (x28_distL < FLT_EPSILON && x2c_distQ < FLT_EPSILON)
return FLT_MAX;
float intens = GetIntensity();
if (x2c_distQ > FLT_EPSILON)
{
if (intens <= FLT_EPSILON)
return 0.f;
return std::sqrt(intens / 5.f * intens / 255.f * x2c_distQ);
}
float nextIntens = 5.f * intens / 255.f;
return intens / std::min(0.2f, nextIntens) * x28_distL;
}
float CLight::GetIntensity() const
{
if (x4c_24_intensityDirty)
{
((CLight*)this)->x4c_24_intensityDirty = false;
float coef = 1.f;
if (x1c_type == ELightType::Custom)
coef = x30_angleC;
((CLight*)this)->x48_cachedIntensity =
coef * std::max(x18_color.r, std::max(x18_color.g, x18_color.b));
}
return x48_cachedIntensity;
}
CLight CLight::BuildDirectional(const zeus::CVector3f& dir, const zeus::CColor& color)
{
return {};
return CLight(ELightType::Directional, kDefaultPosition, dir, color, 180.f);
}
CLight CLight::BuildSpot(const zeus::CVector3f& pos, const zeus::CVector3f& dir,
const zeus::CColor& color, float angle)
{
return {};
return CLight(ELightType::Spot, pos, dir, color, angle);
}
CLight CLight::BuildPoint(const zeus::CVector3f& pos, const zeus::CColor& color)
{
return CLight(ELightType::Point, pos, kDefaultDirection, color, 180.f);
}
CLight CLight::BuildCustom(const zeus::CVector3f& pos, const zeus::CVector3f& dir,
const zeus::CColor& color, float constAtt, float linearAtt, float quadAtt,
float intensity, float, float)
const zeus::CColor& color,
float distC, float distL, float distQ,
float angleC, float angleL, float angleQ)
{
return {};
return CLight(pos, dir, color, distC, distL, distQ, angleC, angleL, angleQ);
}
CLight CLight::BuildLocalAmbient(const zeus::CVector3f& pos, const zeus::CColor& color)
{
return CLight(ELightType::LocalAmbient, pos, kDefaultDirection, color, 180.f);
}
}

View File

@ -3,18 +3,18 @@
#include "zeus/CVector3f.hpp"
#include "zeus/CColor.hpp"
#include "RetroTypes.hpp"
namespace urde
{
enum class ELightType
{
LocalAmbient,
Directional,
Custom,
Spot,
Spot2,
LocalAmbient2
Spot = 0,
Point = 1,
Directional = 2,
LocalAmbient = 3,
Custom = 4,
};
enum class EFalloffType
{
@ -25,13 +25,111 @@ enum class EFalloffType
class CLight
{
friend class CGuiLight;
zeus::CVector3f x0_pos;
zeus::CVector3f xc_dir;
zeus::CColor x18_color;
ELightType x1c_type;
float x20_spotCutoff;
float x24_distC;
float x28_distL;
float x2c_distQ;
float x30_angleC;
float x34_angleL;
float x38_angleQ;
u32 x3c_ = 0;
u32 x40_loadedIdx = 0;
float x44_cachedRadius;
float x48_cachedIntensity;
bool x4c_24_intensityDirty : 1;
bool x4c_25_radiusDirty : 1;
float CalculateLightRadius() const;
public:
CLight(const zeus::CVector3f& pos,
const zeus::CVector3f& dir,
const zeus::CColor& color,
float distC, float distL, float distQ,
float angleC, float angleL, float angleQ)
: x0_pos(pos), xc_dir(dir), x18_color(color),
x1c_type(ELightType::Custom), x20_spotCutoff(0.f),
x24_distC(distC), x28_distL(distL), x2c_distQ(distQ),
x30_angleC(angleC), x34_angleL(angleL), x38_angleQ(angleQ),
x44_cachedRadius(0.f), x48_cachedIntensity(0.f),
x4c_24_intensityDirty(true), x4c_25_radiusDirty(true)
{}
CLight(ELightType type,
const zeus::CVector3f& pos,
const zeus::CVector3f& dir,
const zeus::CColor& color,
float cutoff)
: x0_pos(pos), xc_dir(dir), x18_color(color),
x1c_type(type), x20_spotCutoff(cutoff),
x24_distC(0.f), x28_distL(1.f), x2c_distQ(0.f),
x30_angleC(0.f), x34_angleL(1.f), x38_angleQ(0.f),
x44_cachedRadius(0.f), x48_cachedIntensity(0.f),
x4c_24_intensityDirty(true), x4c_25_radiusDirty(true)
{}
void SetPosition(const zeus::CVector3f& pos)
{
x0_pos = pos;
}
void SetDirection(const zeus::CVector3f& dir)
{
xc_dir = dir;
}
void SetColor(const zeus::CColor& col)
{
x18_color = col;
x4c_24_intensityDirty = true;
x4c_25_radiusDirty = true;
}
void SetAttenuation(float constant, float linear, float quadratic)
{
x24_distC = constant;
x28_distL = linear;
x2c_distQ = quadratic;
x4c_24_intensityDirty = true;
x4c_25_radiusDirty = true;
}
void SetAngleAttenuation(float constant, float linear, float quadratic)
{
x30_angleC = constant;
x34_angleL = linear;
x38_angleQ = quadratic;
x4c_24_intensityDirty = true;
x4c_25_radiusDirty = true;
}
float GetRadius() const
{
if (x4c_25_radiusDirty)
{
((CLight*)this)->x44_cachedRadius = CalculateLightRadius();
((CLight*)this)->x4c_25_radiusDirty = false;
}
return x44_cachedRadius;
}
float GetIntensity() const;
static CLight BuildDirectional(const zeus::CVector3f& dir, const zeus::CColor& color);
static CLight BuildSpot(const zeus::CVector3f& pos, const zeus::CVector3f& dir,
const zeus::CColor& color, float angle);
static CLight BuildPoint(const zeus::CVector3f& pos, const zeus::CColor& color);
static CLight BuildCustom(const zeus::CVector3f& pos, const zeus::CVector3f& dir,
const zeus::CColor& color, float constAtt, float linearAtt, float quadAtt,
float intensity, float, float);
const zeus::CColor& color,
float distC, float distL, float distQ,
float angleC, float angleL, float angleQ);
static CLight BuildLocalAmbient(const zeus::CVector3f& pos, const zeus::CColor& color);
};
}

View File

@ -10,7 +10,7 @@ class CGuiCompoundWidget : public CGuiWidget
{
public:
CGuiCompoundWidget(const CGuiWidgetParms& parms);
virtual FourCC GetWidgetTypeID() const {return FourCC(-1);}
FourCC GetWidgetTypeID() const {return FourCC(-1);}
void OnInvisible();
void OnVisible();

View File

@ -304,6 +304,11 @@ bool CGuiFrame::SendWidgetMessage(s16 id,
return true;
}
void CGuiFrame::ClearAllMessageMap()
{
x7c_messageMap.clear();
}
void CGuiFrame::ClearMessageMap(const CGuiLogicalEventTrigger* trigger, s16 id)
{
CGuiFrame::LogicalEventList* list =
@ -622,6 +627,14 @@ CGuiFrame* CGuiFrame::CreateFrame(TResId frmeId, CGuiSys& sys, CInputStream& in)
return ret;
}
std::unique_ptr<IObj> RGuiFrameFactoryInGame(const SObjectTag& tag, CInputStream& in,
const CVParamTransfer& vparms)
{
CGuiResFrameData& rfData = static_cast<TObjOwnerParam<CGuiResFrameData>*>(vparms.GetObj())->GetParam();
std::unique_ptr<CGuiFrame> frame(CGuiFrame::CreateFrame(tag.id, rfData.x0_guiSys, in));
return TToken<CGuiFrame>::GetIObjObjectFor(std::move(frame));
}
std::string CGuiFrame::CreateFrameName(TResId frmeId)
{
/* formatting token originally "frame_%x" for 32-bit ids */

View File

@ -7,6 +7,7 @@
#include "CGuiControllerInfo.hpp"
#include "CGuiLogicalEventTrigger.hpp"
#include "CGuiWidgetIdDB.hpp"
#include "IObj.hpp"
namespace urde
{
@ -16,6 +17,7 @@ class CGuiCamera;
class CGuiHeadWidget;
class CFinalInput;
class CGuiLight;
class CVParamTransfer;
enum class EFrameTransitionOptions
{
@ -131,6 +133,9 @@ public:
static std::string CreateFrameName(TResId frmeId);
};
std::unique_ptr<IObj> RGuiFrameFactoryInGame(const SObjectTag& tag, CInputStream& in,
const CVParamTransfer& vparms);
}
#endif // __URDE_CGUIFRAME_HPP__

View File

@ -13,7 +13,7 @@ class CGuiGroup : public CGuiCompoundWidget
bool x100_b;
public:
CGuiGroup(const CGuiWidgetParms& parms, int defaultWorker, bool b);
virtual FourCC GetWidgetTypeID() const {return FOURCC('GRUP');}
FourCC GetWidgetTypeID() const {return FOURCC('GRUP');}
void SelectWorkerWidget(int workerId, bool setActive, bool setVisible);
CGuiWidget* GetSelectedWidget();

View File

@ -1,25 +1,109 @@
#include "CGuiLight.hpp"
#include "CGuiAnimController.hpp"
#include "CGuiLogicalEventTrigger.hpp"
#include "CGuiFrame.hpp"
namespace urde
{
CGuiLight::CGuiLight(const CGuiWidgetParms& parms, const CLight& light)
: CGuiWidget(parms)
: CGuiWidget(parms),
xf8_type(light.x1c_type),
xfc_spotCutoff(light.x20_spotCutoff),
x100_distC(light.x24_distC),
x104_distL(light.x28_distL),
x108_distQ(light.x2c_distQ),
x10c_angleC(light.x30_angleC),
x110_angleL(light.x34_angleL),
x114_angleQ(light.x38_angleQ),
x118_loadedIdx(light.x40_loadedIdx)
{}
CGuiLight::~CGuiLight()
{
xc8_frame->RemoveLight(this);
}
CLight CGuiLight::BuildLight() const
{
return {};
CLight ret = CLight::BuildLocalAmbient(zeus::CVector3f::skZero, zeus::CColor::skBlack);
switch (xf8_type)
{
case ELightType::Spot:
ret = CLight::BuildSpot(GetWorldPosition(), x34_worldXF.m_basis[1], xbc_color, xfc_spotCutoff);
break;
case ELightType::Point:
ret = CLight::BuildPoint(GetWorldPosition(), xbc_color);
break;
case ELightType::Directional:
ret = CLight::BuildDirectional(x34_worldXF.m_basis[1], xbc_color);
break;
default: break;
}
ret.SetAttenuation(x100_distC, x104_distL, x108_distQ);
ret.SetAngleAttenuation(x10c_angleC, x110_angleL, x114_angleQ);
return ret;
}
void CGuiLight::SetIsVisible(bool vis)
{
if (vis)
xc8_frame->AddLight(this);
else
xc8_frame->RemoveLight(this);
CGuiWidget::SetIsVisible(vis);
}
CGuiLight* CGuiLight::Create(CGuiFrame* frame, CInputStream& in, bool flag)
{
CGuiWidgetParms parms = ReadWidgetHeader(frame, in, flag);
ELightType tp = ELightType(in.readUint32Big());
float distC = in.readFloatBig();
float distL = in.readFloatBig();
float distQ = in.readFloatBig();
float angC = in.readFloatBig();
float angL = in.readFloatBig();
float angQ = in.readFloatBig();
u32 loadedIdx = in.readUint32Big();
CGuiLight* ret = nullptr;
switch (tp)
{
case ELightType::Spot:
{
float cutoff = in.readFloatBig();
CLight lt = CLight::BuildSpot(zeus::CVector3f::skZero, zeus::CVector3f::skZero,
parms.x10_color, cutoff);
lt.SetAttenuation(distC, distL, distQ);
lt.SetAngleAttenuation(angC, angL, angQ);
lt.x40_loadedIdx = loadedIdx;
ret = new CGuiLight(parms, lt);
break;
}
case ELightType::Point:
{
CLight lt = CLight::BuildPoint(zeus::CVector3f::skZero, parms.x10_color);
lt.SetAttenuation(distC, distL, distQ);
lt.x40_loadedIdx = loadedIdx;
ret = new CGuiLight(parms, lt);
break;
}
case ELightType::Directional:
{
CLight lt = CLight::BuildDirectional(zeus::CVector3f::skZero, parms.x10_color);
lt.x40_loadedIdx = loadedIdx;
ret = new CGuiLight(parms, lt);
break;
}
default: break;
}
ret->ParseBaseInfo(frame, in, parms);
frame->AddLight(ret);
return ret;
}
}

View File

@ -9,11 +9,23 @@ namespace urde
class CGuiLight : public CGuiWidget
{
u32 x118_loadedIdx = 0;
ELightType xf8_type;
float xfc_spotCutoff;
float x100_distC;
float x104_distL;
float x108_distQ;
float x10c_angleC;
float x110_angleL;
float x114_angleQ;
u32 x118_loadedIdx;
zeus::CColor x11c_color = zeus::CColor::skBlack;
public:
~CGuiLight();
CGuiLight(const CGuiWidgetParms& parms, const CLight& light);
FourCC GetWidgetTypeID() const {return FOURCC('LITE');}
CLight BuildLight() const;
void SetIsVisible(bool vis);
u32 GetLoadedIdx() const {return x118_loadedIdx;}
static CGuiLight* Create(CGuiFrame* frame, CInputStream& in, bool);

View File

@ -11,6 +11,26 @@ CGuiPane::CGuiPane(const CGuiWidgetParms& parms, float a, float b, const zeus::C
InitializeBuffers();
}
void CGuiPane::ScaleDimensions(const zeus::CVector3f& scale)
{
}
void CGuiPane::SetDimensions(const zeus::CVector2f& dim, bool flag)
{
}
const zeus::CVector3f& CGuiPane::GetDimensions() const
{
}
void CGuiPane::InitializeBuffers()
{
}
void CGuiPane::WriteData(COutputStream& out, bool flag) const
{
}
CGuiPane* CGuiPane::Create(CGuiFrame* frame, CInputStream& in, bool flag)
{
CGuiWidgetParms parms = ReadWidgetHeader(frame, in, flag);

View File

@ -372,6 +372,11 @@ void CGuiWidget::AddChildWidget(CGuiWidget* widget, bool makeWorldLocal, bool at
AddChildObject(widget, makeWorldLocal, atEnd);
}
bool CGuiWidget::AddWorkerWidget(CGuiWidget* worker)
{
return false;
}
void CGuiWidget::AddAnim(EGuiAnimBehListID id, CGuiAnimBase* anim)
{
if (!xb0_animController)

View File

@ -1156,7 +1156,8 @@ void CParticleDataFactory::LoadGPSMTokens(CGenDescription* desc)
desc->xd4_xc0_SSWH.m_swoosh = desc->xd4_xc0_SSWH.m_token.GetObj();
}
std::unique_ptr<IObj> FParticleFactory(const SObjectTag& tag, CInputStream& in, const CVParamTransfer& vparms)
std::unique_ptr<IObj> FParticleFactory(const SObjectTag& tag, CInputStream& in,
const CVParamTransfer& vparms)
{
CSimplePool* sp = static_cast<CSimplePool*>(static_cast<TObjOwnerParam<IObjectStore*>*>(vparms.GetObj())->GetParam());
return TToken<CGenDescription>::GetIObjObjectFor(std::unique_ptr<CGenDescription>(CParticleDataFactory::GetGeneratorDesc(in, sp)));

View File

@ -209,7 +209,8 @@ bool CParticleElectric::SystemHasLight() const
CLight CParticleElectric::GetLight() const
{
return CLight();
return CLight(zeus::CVector3f::skZero, zeus::CVector3f::skZero,
zeus::CColor::skBlack, 0.f, 1.f, 0.f, 0.f, 1.f, 0.f);
}
bool CParticleElectric::GetParticleEmission() const

View File

@ -105,7 +105,8 @@ bool CParticleSwoosh::SystemHasLight() const
CLight CParticleSwoosh::GetLight() const
{
return CLight();
return CLight(zeus::CVector3f::skZero, zeus::CVector3f::skZero,
zeus::CColor::skBlack, 0.f, 1.f, 0.f, 0.f, 1.f, 0.f);
}
bool CParticleSwoosh::GetParticleEmission() const