Last active
February 15, 2021 04:25
-
-
Save opparco/f0dc016159975b61a19ee1a177223f61 to your computer and use it in GitHub Desktop.
CBPFO4 NodeMap
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <set> | |
#include "NodeMap.h" | |
std::unordered_map<NiNode *, std::unordered_map<std::string, NiNode *> > m_nodes_container; | |
void DeleteNodeMap(NiNode * rootnode) | |
{ | |
_DMESSAGE("DeleteNodeMap rootnode %p", rootnode); | |
m_nodes_container.erase(rootnode); | |
} | |
void CreateNodeMap(NiNode * rootnode) | |
{ | |
_DMESSAGE("CreateNodeMap rootnode %p", rootnode); | |
if (!rootnode) { | |
return; | |
} | |
if (m_nodes_container.find(rootnode) == m_nodes_container.end()) { /* not found */ | |
std::unordered_map<std::string, NiNode *> nodemap; | |
// | |
// traverse tree | |
// | |
std::vector<NiNode *> nodes; | |
nodes.emplace_back(rootnode); | |
while (!nodes.empty()) { | |
NiNode * node = nodes.back(); | |
nodes.pop_back(); | |
nodemap.emplace(node->m_name.c_str(), node); | |
for (UInt32 i = node->m_children.m_emptyRunStart; i-- > 0; ) { // iterate backwards | |
if (node->m_children.m_data[i]) { | |
NiNode * c = DYNAMIC_CAST(node->m_children.m_data[i], NiAVObject, NiNode); | |
if (c) | |
nodes.emplace_back(c); | |
} | |
} | |
} | |
m_nodes_container.emplace(rootnode, nodemap); | |
} | |
} | |
std::unordered_map<std::string, NiNode *> * GetNodeMap(NiNode * rootnode) | |
{ | |
auto iter = m_nodes_container.find(rootnode); | |
if (iter != m_nodes_container.end()) { | |
return &iter->second; | |
} | |
else | |
return nullptr; | |
} | |
NiNode * GetNodeByName(NiNode * rootnode, std::string name) | |
{ | |
std::unordered_map<std::string, NiNode *> * nodes = GetNodeMap(rootnode); | |
auto it = nodes->find(name); | |
if (it != nodes->end()) { | |
NiNode * node = it->second; | |
return node; | |
} | |
else | |
return nullptr; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#pragma once | |
#include <unordered_map> | |
#include "f4se/GameRTTI.h" | |
#include "f4se/NiNodes.h" | |
void DeleteNodeMap(NiNode * rootnode); | |
void CreateNodeMap(NiNode * rootnode); | |
std::unordered_map<std::string, NiNode *>* GetNodeMap(NiNode * rootnode); | |
NiNode * GetNodeByName(NiNode * rootnode, std::string name); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment