add some CK3dEntity code

This commit is contained in:
2023-09-19 22:32:07 +08:00
parent 2d190ea30b
commit 69f702a6d2
6 changed files with 176 additions and 27 deletions

View File

@ -3,6 +3,7 @@
#include "../CK2/MgrImpls/CKObjectManager.hpp"
#include "../CK2/ObjImpls/CKObject.hpp"
#include <type_traits>
#include <algorithm>
namespace LibCmo::XContainer {
@ -143,6 +144,13 @@ namespace LibCmo::XContainer {
}
namespace NSXObjectPointerArray {
void AddIfNotHere(XObjectPointerArray& objarray, CK2::ObjImpls::CKObject* const obj) {
auto finder = std::find(objarray.begin(), objarray.end(), obj);
if (finder == objarray.end()) {
objarray.emplace_back(obj);
}
}
void PreDeletedCheck(XObjectPointerArray& objarray, CK2::CKContext* ctx) {
if (ctx == nullptr) return;
std::erase_if(objarray, [ctx](CK2::ObjImpls::CKObject* const& item) -> bool {

View File

@ -180,6 +180,13 @@ namespace LibCmo::XContainer {
namespace NSXObjectPointerArray {
/**
* @brief Add object pointer if it is not list.
* @param objarray
* @param obj
*/
void AddIfNotHere(XObjectPointerArray& objarray, CK2::ObjImpls::CKObject* const obj);
/**
* @brief Check Object pointer validation and remove invalid pointers before deletion.
* @param objarray