Skip to content

Commit

Permalink
More lighting functions
Browse files Browse the repository at this point in the history
  • Loading branch information
powerof3 committed Aug 24, 2024
1 parent 7bfd5bc commit ca7ed22
Show file tree
Hide file tree
Showing 10 changed files with 115 additions and 19 deletions.
1 change: 1 addition & 0 deletions cmake/sourcelist.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -1973,6 +1973,7 @@ set(SOURCES
src/RE/S/ScriptEventSourceHolder.cpp
src/RE/S/SendUIMessage.cpp
src/RE/S/Setting.cpp
src/RE/S/ShadowSceneNode.cpp
src/RE/S/ShoutAttack.cpp
src/RE/S/SkillIncrease.cpp
src/RE/S/Sky.cpp
Expand Down
2 changes: 2 additions & 0 deletions include/RE/B/BSVisit.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ namespace RE
class bhkNiCollisionObject;
class BSGeometry;
class NiAVObject;
class NiPointLight;

namespace BSVisit
{
Expand All @@ -16,6 +17,7 @@ namespace RE

BSVisitControl TraverseScenegraphCollision(NiAVObject* a_object, std::function<BSVisitControl(bhkNiCollisionObject*)> a_func);
BSVisitControl TraverseScenegraphGeometries(NiAVObject* a_object, std::function<BSVisitControl(BSGeometry*)> a_func);
BSVisitControl TraverseScenegraphLights(NiAVObject* a_object, std::function<BSVisitControl(NiPointLight*)> a_func);
BSVisitControl TraverseScenegraphObjects(NiAVObject* a_object, std::function<BSVisitControl(NiAVObject*)> a_func);
}
}
1 change: 1 addition & 0 deletions include/RE/M/Main.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ namespace RE
static NiCamera* WorldRootCamera();
static Scenegraph* WorldRootNode();

bool IsRoomVisible(NiNode* a_room);
void SetActive(bool a_active);

// members
Expand Down
7 changes: 6 additions & 1 deletion include/RE/N/NiColor.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ namespace RE
constexpr NiColor(std::uint32_t a_hexValue) noexcept :
red(((a_hexValue >> 16) & 0xFF) / 255.0f),
green(((a_hexValue >> 8) & 0xFF) / 255.0f),
blue(((a_hexValue)&0xFF) / 255.0f)
blue(((a_hexValue) & 0xFF) / 255.0f)
{
}

Expand Down Expand Up @@ -136,6 +136,11 @@ namespace RE
return *this;
}

NiColor operator-()
{
return NiColor(-red, -green, -blue);
}

friend NiColor operator-(float a_lhs, const NiColor& a_rhs)
{
return NiColor(
Expand Down
14 changes: 7 additions & 7 deletions include/RE/S/ShadowSceneNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ namespace RE
class BSPortalGraph;
class BSShadowLight;
class BSShadowDirectionalLight;
class NiLight;

class ShadowSceneNode : public NiNode
{
Expand Down Expand Up @@ -45,20 +46,19 @@ namespace RE
const NiRTTI* GetRTTI() const override; // 02
void OnVisible(NiCullingProcess& a_process) override; // 34

BSLight* AddLight(NiLight* a_light, const LIGHT_CREATE_PARAMS& a_params)
{
using func_t = decltype(&ShadowSceneNode::AddLight);
static REL::Relocation<func_t> func{ RELOCATION_ID(99692, 106326) };
return func(this, a_light, a_params);
}
BSLight* AddLight(NiLight* a_light, const LIGHT_CREATE_PARAMS& a_params);
BSLight* GetLight(NiLight* a_light);
BSLight* GetPointLight(NiLight* a_light);
BSLight* GetShadowLight(NiLight* a_light);
void RemoveLight(NiLight* a_light);

// members
std::uint64_t unk128; // 128
BSTArray<NiPointer<BSLight>> activeLights; // 130
BSTArray<NiPointer<BSLight>> activeShadowLights; // 148
BSTArray<NiPointer<BSLight>> lightQueueAdd; // 160
BSTArray<NiPointer<BSLight>> lightQueueRemove; // 178
BSTArray<NiPointer<BSLight>> unk190; // 190 - unused?
BSTArray<NiPointer<BSLight>> unk190; // 190
mutable BSSpinLock lightQueueLock; // 1A8
BSTArray<NiPointer<NiAVObject>> litGeometry; // 1B0
BSTArray<NiPointer<NiAVObject>> objectList1; // 1C8
Expand Down
6 changes: 3 additions & 3 deletions include/RE/T/TESObjectCELL.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,9 @@ namespace RE
// members
NiPointer<BSPortalGraph> portalGraph; // 000 - smart ptr
NiPointer<NiNode> cell3D; // 008
void* unk010; // 010 - smart ptr
void* unk018; // 018 - smart ptr
void* unk020; // 020 - smart ptr
NiPointer<NiNode> lightMarkerNode; // 010 - smart ptr
NiPointer<NiNode> soundMarkerNode; // 018 - smart ptr
NiPointer<NiNode> multiBoundNode; // 020 - smart ptr
std::uint64_t unk028; // 028
std::uint64_t unk030; // 030
std::uint64_t unk038; // 038
Expand Down
1 change: 1 addition & 0 deletions include/RE/T/TESObjectLIGH.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ namespace RE
void SetEquipSlot(BGSEquipSlot* a_slot) override; // 05 - { return; }

[[nodiscard]] constexpr bool CanBeCarried() const noexcept { return data.flags.all(TES_LIGHT_FLAGS::kCanCarry); }
[[nodiscard]] constexpr bool GetNoFlicker() const noexcept { return data.flags.none(TES_LIGHT_FLAGS::kFlicker, TES_LIGHT_FLAGS::kFlickerSlow, TES_LIGHT_FLAGS::kPulse, TES_LIGHT_FLAGS::kPulseSlow); }

NiLight* GenDynamic(RE::TESObjectREFR* a_ref, RE::NiNode* a_node, char a_forceDynamic, char a_useLightRadius, char a_affectRefOnly)
{
Expand Down
47 changes: 39 additions & 8 deletions src/RE/B/BSVisit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,29 @@
#include "RE/B/bhkNiCollisionObject.h"
#include "RE/N/NiAVObject.h"
#include "RE/N/NiNode.h"
#include "RE/N/NiPointLight.h"
#include "RE/N/NiRTTI.h"

namespace RE
{
namespace BSVisit
{
BSVisitControl TraverseScenegraphCollision(NiAVObject* a_object, std::function<BSVisitControl(bhkNiCollisionObject*)> a_func)
{
auto result = BSVisitControl::kContinue;

if (!a_object) {
return BSVisitControl::kContinue;
return result;
}

auto collision = static_cast<bhkNiCollisionObject*>(a_object->collisionObject.get());
if (collision) {
auto result = a_func(collision);
result = a_func(collision);
if (result == BSVisitControl::kStop) {
return result;
}
}

auto result = BSVisitControl::kContinue;
auto node = a_object->AsNode();
if (node) {
for (auto& child : node->children) {
Expand All @@ -38,16 +41,17 @@ namespace RE

BSVisitControl TraverseScenegraphGeometries(NiAVObject* a_object, std::function<BSVisitControl(BSGeometry*)> a_func)
{
auto result = BSVisitControl::kContinue;

if (!a_object) {
return BSVisitControl::kContinue;
return result;
}

auto geom = a_object->AsGeometry();
if (geom) {
return a_func(geom);
}

auto result = BSVisitControl::kContinue;
auto node = a_object->AsNode();
if (node) {
for (auto& child : node->children) {
Expand All @@ -61,18 +65,45 @@ namespace RE
return result;
}

BSVisitControl TraverseScenegraphLights(NiAVObject* a_object, std::function<BSVisitControl(NiPointLight*)> a_func)
{
auto result = BSVisitControl::kContinue;

if (!a_object) {
return result;
}

auto ptLight = netimmerse_cast<NiPointLight*>(a_object);
if (ptLight) {
return a_func(ptLight);
}

auto node = a_object->AsNode();
if (node) {
for (auto& child : node->children) {
result = TraverseScenegraphLights(child.get(), a_func);
if (result == BSVisitControl::kStop) {
break;
}
}
}

return result;
}

BSVisitControl TraverseScenegraphObjects(NiAVObject* a_object, std::function<BSVisitControl(NiAVObject*)> a_func)
{
auto result = BSVisitControl::kContinue;

if (!a_object) {
return BSVisitControl::kContinue;
return result;
}

auto result = a_func(a_object);
result = a_func(a_object);
if (result == BSVisitControl::kStop) {
return result;
}

result = BSVisitControl::kContinue;
auto node = a_object->AsNode();
if (node) {
for (auto& child : node->children) {
Expand Down
7 changes: 7 additions & 0 deletions src/RE/M/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@ namespace RE
return *singleton;
}

bool Main::IsRoomVisible(NiNode* a_room)
{
using func_t = decltype(&Main::IsRoomVisible);
static REL::Relocation<func_t> func{ RELOCATION_ID(35608, 36618) };
return func(this, a_room);
}

float Main::QFrameAnimTime()
{
REL::Relocation<float*> data{ RELOCATION_ID(516940, 403447) };
Expand Down
48 changes: 48 additions & 0 deletions src/RE/S/ShadowSceneNode.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#include "RE/S/ShadowSceneNode.h"
#include "RE/B/BSLight.h"

namespace RE
{
BSLight* ShadowSceneNode::AddLight(NiLight* a_light, const ShadowSceneNode::LIGHT_CREATE_PARAMS& a_params)
{
using func_t = decltype(&ShadowSceneNode::AddLight);
static REL::Relocation<func_t> func{ RELOCATION_ID(99692, 106326) };
return func(this, a_light, a_params);
}

BSLight* ShadowSceneNode::GetLight(NiLight* a_light)
{
auto light = GetPointLight(a_light);
if (!light) {
light = GetShadowLight(a_light);
}
return light;
}

BSLight* ShadowSceneNode::GetPointLight(NiLight* a_light)
{
for (auto& light : activeLights) {
if (light && light->light.get() == a_light) {
return light.get();
}
}
return nullptr;
}

BSLight* ShadowSceneNode::GetShadowLight(NiLight* a_light)
{
for (auto& light : activeShadowLights) {
if (light && light->light.get() == a_light) {
return light.get();
}
}
return nullptr;
}

void ShadowSceneNode::RemoveLight(NiLight* a_light)
{
using func_t = decltype(&ShadowSceneNode::RemoveLight);
static REL::Relocation<func_t> func{ RELOCATION_ID(99697, 106331) };
return func(this, a_light);
}
}

0 comments on commit ca7ed22

Please sign in to comment.