resonance 1.0.1
Loading...
Searching...
No Matches
Rnd::Light Class Reference

Light in a scene. More...

#include <light.h>

Inheritance diagram for Rnd::Light:
Collaboration diagram for Rnd::Light:

Public Types

enum  Type { kLightTypePoint = 0 , kLightTypeDirectional = 1 , kLightTypeSpot = 2 }
 Which lighting model a light applies. More...
Public Types inherited from Rnd::Transformable
enum  Billboard {
  kBillboardNone = 0 , kBillboardX = 1 , kBillboardY = 2 , kBillboardZ = 4 ,
  kBillboardXZ = 8 , kBillboardXYZ = 16 , kBillboardSimpleXYZ = 32 , kBillboardLocalRotate = 64 ,
  kBillboardScaleX = 129 , kBillboardScaleY = 130 , kBillboardScaleZ = 132 , kBillboardScaleXZ = 136 ,
  kBillboardScaleXYZ = 144 , kBillboardScaleSimpleXYZ = 160
}
 Mode mBillboard selects, recovered from the name dumper at 0x004f26f0. More...

Public Member Functions

 Light (const HxStr &name)
 Construct a white directional light.
virtual ~Light ()
virtual void SetColors (const Color &ambient, const Color &diffuse, const Color &specular)
 Set all three colours at once.
virtual void SetType (Type type)
 Set which lighting model this light applies.
virtual void SetRange (float flRange)
 Set the distance a point light illuminates over.
virtual void SetAngles (float flInner, float flOuter)
 Set the two cone angles of a spot light.
virtual void SetAttenuation (float flConstant, float flLinear, float flQuadratic)
 Set the three attenuation terms of a point light.
virtual void SyncLight ()
 Hook run after the whole state of the light changes at once.
virtual const HxStr & ClassName () const
 Report the class key a .rnd file writes for a light.
virtual void DumpText (Dbg &sink)
 Write a description of this light to sink.
virtual void Save (Stream &stream)
 Write the revision, the base, the three colours, the six scalars, and the type to stream.
virtual void Replace (Object *pFrom, Object *pTo)
 Retarget the references of the base at pTo.
virtual void Copy (const Object *pSource, unsigned nFlags)
 Copy the three colours, the six scalars, and the type from pSource.
virtual void Load (Stream &stream)
 Replace the three colours, the six scalars, and the type from stream.
Public Member Functions inherited from Rnd::Transformable
 Transformable ()
 Construct a dirty transformable with identity transforms and no children.
virtual ~Transformable ()
 Drop this object's references on its children.
void AddTrans (Transformable *pTrans)
 Append pTrans to mTransList and mark it dirty.
void RemoveTrans (Transformable *pTrans)
 Erase pTrans from mTransList.
void RemoveAllTranses ()
 Drop this object's reference on every mTransList entry and empty the list.
Transformable * Parent ()
 Report the transformable that positions this one.
virtual void SetBillboard (int nBillboard)
 Set the billboard mode and mark the transform dirty.
virtual int UpdateWorldXfm (Transformable *pParent, int nForce)
 Compose mWorldXfm from mLocalXfm and the parent's world transform.
void SetOrigin (const float *pOrigin)
 Set the origin row and mark the transform dirty.
float * GetDrawXfm ()
 Build the transform this object draws with and return it.
Public Member Functions inherited from Rnd::Object
 Object ()
 Construct an unnamed object.
 Object (const HxStr &name)
 Construct an object and register it under name.
virtual ~Object ()
 Erase the registry entry and release the name buffer.
void SetName (const HxStr &name)
 Re-register this object under a different name.
void AddRef (Object *pReferrer)
 Register pReferrer as a store of a pointer to this object.
void RemoveRef (Object *pReferrer)
 Drop one registration made by AddRef().

Static Public Member Functions

static void * operator new (size_t nSize)
 Allocate a light block under the tag "Rnd::Light".
static void operator delete (void *pBlock)
 Release a block operator new() allocated.

Public Attributes

Color mDiffuse
 Light a vertex receives in proportion to its normal.
Color mAmbient
 Light every vertex receives from this light regardless of its normal.
Color mSpecular
 Highlight colour the light contributes.
float mRange
 Distance a point light illuminates over.
Type mType
 Which lighting model this light applies.
Public Attributes inherited from Rnd::Transformable
float mLocalXfm [kXfmRowCount][kXfmRowFloatCount]
 Transform this object is positioned by, before the parent transform is applied.
float mWorldXfm [kXfmRowCount][kXfmRowFloatCount]
 Composed world transform.
int mDirty
 Set by every writer of a transform field and cleared once UpdateWorldXfm has recomposed.
Public Attributes inherited from Rnd::Object
HxStr mName
int mInternal

Additional Inherited Members

Protected Member Functions inherited from Rnd::Transformable
void AdoptXfmFrom (const Transformable &owner)
 Adopt the transform of an owner this object is being detached from.
void ReleaseTransRefs ()
 Drop this object's reference on every mTransList entry without emptying the list.
Protected Member Functions inherited from Rnd::Object
void ReleaseAllRefs ()
 Tell every referrer to drop its pointer to this object.
Protected Attributes inherited from Rnd::Transformable
float mOrigin [kXfmRowFloatCount]
int mBillboard
Protected Attributes inherited from Rnd::Object
std::list< Object * > mRefs

Detailed Description

Light in a scene.

Its RTTI descriptor is at 0x008efe60. It has Rnd::Transformable as its only public non-virtual base at offset 0. The class is 0x120 bytes and the virtual Rnd::Object subobject sits at 0x100. The constructor proves the offset by writing that address into the virtual-base pointer. The four bytes between the last member and that subobject are a reserved run rather than a field.

Each colour member is quadword aligned in the original, which is what places the first one at 0xb0 rather than at the 0xac the base subobject ends on.

The member titles come from the text DumpText() writes: "diffuse:", " ambient:", "specular:", " innerAng:", "outerAng:", " range:", "constantAtten:", " linearAtten:", " quadraticAtten:", and "type:".

Two vtables belong to the class. The nine-entry table at 0x00829500 is addressed by the Rnd::Transformable vptr at 0xa8 and stores the six virtuals declared here after the two Rnd::Transformable ones, and the eight-entry table at 0x008294b8 is addressed by the Rnd::Object subobject vptr with a -0x100 adjustment on every entry. Both Rnd::Transformable virtuals are inherited unchanged.

The position a point light is placed at is the translation row of the world transform of the base, and the direction a directional light points along is the second basis row negated. The light therefore stores neither.

Member Enumeration Documentation

◆ Type

Which lighting model a light applies.

The three names come from the routine at 0x005454a0. The routine writes 'Point', 'Directional', and 'Spot' for the values below. Rnd::PsEnviron::DrawShowing() handles the first two and skips a spot light entirely.

Enumerator
kLightTypePoint 
kLightTypeDirectional 
kLightTypeSpot 

Constructor & Destructor Documentation

◆ Light()

Rnd::Light::Light ( const HxStr & name)
explicit

Construct a white directional light.

The diffuse colour starts fully opaque white, the ambient colour a tenth of that, and the specular colour fully opaque black. Both cone angles start at a right angle halved, the range at 1000.0, the constant attenuation at 1.0, both other attenuations at 0.0, and the type at Directional.

Parameters
nameThe registry key for this object.
Ghidra address:
NTSC-U/C: 0x0053ffd8
Ghidra address:
PAL: 0x0057fcb0

◆ ~Light()

virtual Rnd::Light::~Light ( )
virtual
Ghidra address:
NTSC-U/C: 0x005445d8
Ghidra address:
PAL: 0x00584350

Member Function Documentation

◆ operator new()

void * Rnd::Light::operator new ( size_t nSize)
static

Allocate a light block under the tag "Rnd::Light".

Parameters
nSizeThe block size.
Returns
The block.
Ghidra address:
NTSC-U/C: 0x005443c0
Ghidra address:
PAL: 0x00584138

◆ operator delete()

void Rnd::Light::operator delete ( void * pBlock)
static

Release a block operator new() allocated.

Parameters
pBlockThe block.
Ghidra address:
NTSC-U/C: 0x005443e0
Ghidra address:
PAL: 0x00584158

◆ SetColors()

virtual void Rnd::Light::SetColors ( const Color & ambient,
const Color & diffuse,
const Color & specular )
virtual

Set all three colours at once.

Vtable slot 3 of the Rnd::Transformable table. The parameter order is the recovered one and it is not the order the text dump writes the three colours in.

Parameters
ambientThe light every vertex receives from this light regardless of its normal.
diffuseThe light a vertex receives in proportion to its normal.
specularThe highlight colour.
Ghidra address:
NTSC-U/C: 0x00544400
Ghidra address:
PAL: 0x00584178

◆ SetType()

virtual void Rnd::Light::SetType ( Type type)
virtual

Set which lighting model this light applies.

Vtable slot 4 of the Rnd::Transformable table.

Parameters
typeThe lighting model.
Ghidra address:
NTSC-U/C: 0x00544420
Ghidra address:
PAL: 0x00584198

◆ SetRange()

virtual void Rnd::Light::SetRange ( float flRange)
virtual

Set the distance a point light illuminates over.

Vtable slot 5 of the Rnd::Transformable table.

Parameters
flRangeThe distance.
Ghidra address:
NTSC-U/C: 0x00544428
Ghidra address:
PAL: 0x005841a0

◆ SetAngles()

virtual void Rnd::Light::SetAngles ( float flInner,
float flOuter )
virtual

Set the two cone angles of a spot light.

Vtable slot 6 of the Rnd::Transformable table.

Parameters
flInnerAngle the cone is at full strength within.
flOuterAngle the cone falls to nothing at.
Ghidra address:
NTSC-U/C: 0x00544430
Ghidra address:
PAL: 0x005841a8

◆ SetAttenuation()

virtual void Rnd::Light::SetAttenuation ( float flConstant,
float flLinear,
float flQuadratic )
virtual

Set the three attenuation terms of a point light.

Vtable slot 7 of the Rnd::Transformable table. The three terms scale one, the distance, and the squared distance.

Parameters
flConstantThe constant term.
flLinearThe term the distance scales.
flQuadraticThe term the squared distance scales.
Ghidra address:
NTSC-U/C: 0x00544440
Ghidra address:
PAL: 0x005841b8

◆ SyncLight()

virtual void Rnd::Light::SyncLight ( )
virtual

Hook run after the whole state of the light changes at once.

Vtable slot 8 of the Rnd::Transformable table. The body is empty and no class overrides it. Two call sites are recovered, and both are a tail call on this with no argument. Load() ends with one at 0x00540e80 and Copy() ends with another at 0x0054545c, which fixes the signature as a no-argument void. The title is inferred from those two call sites, and every subclass that would supply a body is absent from this build.

Ghidra address:
NTSC-U/C: 0x00544818
Ghidra address:
PAL: 0x00584590

◆ ClassName()

virtual const HxStr & Rnd::Light::ClassName ( ) const
virtual

Report the class key a .rnd file writes for a light.

The returned string is the global at 0x00720bd0, which the class registration fills with "Light".

Returns
The class key.
Ghidra address:
NTSC-U/C: 0x005445c8
Ghidra address:
PAL: 0x00584340

Implements Rnd::Object.

◆ DumpText()

virtual void Rnd::Light::DumpText ( Dbg & sink)
virtual

Write a description of this light to sink.

The base description comes first, and everything below is produced only at a positive dump level.

Parameters
sinkThe diagnostic sink to write to.
Ghidra address:
NTSC-U/C: 0x00540420
Ghidra address:
PAL: 0x005800f8

Reimplemented from Rnd::Transformable.

◆ Save()

virtual void Rnd::Light::Save ( Stream & stream)
virtual

Write the revision, the base, the three colours, the six scalars, and the type to stream.

The revision is 1. Every colour goes out as its four components in turn rather than as one quadword.

Parameters
streamThe stream to write to.
Ghidra address:
NTSC-U/C: 0x005408b8
Ghidra address:
PAL: 0x00580590

Reimplemented from Rnd::Transformable.

◆ Replace()

virtual void Rnd::Light::Replace ( Object * pFrom,
Object * pTo )
virtual

Retarget the references of the base at pTo.

The body forwards to Rnd::Transformable::Replace() and does nothing else, because a light stores no object reference of its own. The forwarding body has its own address rather than sharing the base entry. The override was therefore declared even though it adds nothing.

Parameters
pFromThe object being replaced.
pToThe replacement, or null.
Ghidra address:
NTSC-U/C: 0x00545480
Ghidra address:
PAL: 0x005851f8

Reimplemented from Rnd::Transformable.

◆ Copy()

virtual void Rnd::Light::Copy ( const Object * pSource,
unsigned nFlags )
virtual

Copy the three colours, the six scalars, and the type from pSource.

The three colours move as one quadword each. The source is narrowed through dynamic_cast and the result is used with no null test. A pSource that is not a light therefore faults here. SyncLight() finishes the routine.

Parameters
pSourceThe object to copy from.
nFlagsThe set of fields to copy, passed straight to the base.
Ghidra address:
NTSC-U/C: 0x00545390
Ghidra address:
PAL: 0x00585108

Reimplemented from Rnd::Transformable.

◆ Load()

virtual void Rnd::Light::Load ( Stream & stream)
virtual

Replace the three colours, the six scalars, and the type from stream.

A revision above 1 produces the report "Can't load new Light" and no further reading. A revision of 0 predates the type word and retains mType unchanged. SyncLight() finishes the routine.

Parameters
streamThe stream to read from.
Ghidra address:
NTSC-U/C: 0x00540be8
Ghidra address:
PAL: 0x005808c0

Reimplemented from Rnd::Transformable.

Member Data Documentation

◆ mDiffuse

Color Rnd::Light::mDiffuse

Light a vertex receives in proportion to its normal.

+0xb0

◆ mAmbient

Color Rnd::Light::mAmbient

Light every vertex receives from this light regardless of its normal.

+0xc0

◆ mSpecular

Color Rnd::Light::mSpecular

Highlight colour the light contributes.

+0xd0

Public for the same reason as its two siblings. Rnd::LightAnim::SetFrameSelf() at 0x005418f8 reads all three through a Rnd::Light pointer it stores, and Rnd::LightAnim does not derive from Rnd::Light, so protected access would not cover it. A friend declaration fits the image equally well. The three stack quadwords that routine builds become the three arguments of SetColors(), which confirms both this offset and that parameter order.

◆ mRange

float Rnd::Light::mRange

Distance a point light illuminates over.

+0xe8

◆ mType

Type Rnd::Light::mType

Which lighting model this light applies.

+0xf8


The documentation for this class was generated from the following file: