CSEngine
Loading...
Searching...
No Matches
SObject.cpp
1#include "SObject.h"
2#include "Manager/MemoryMgr.h"
3#include "Manager/EngineCore.h"
4#include "Util/MoreString.h"
5#include <string>
6
7using namespace CSE;
8
9MemoryMgr* memoryMgr = nullptr;
10
11SObject::SObject() {
12 memoryMgr = CORE->GetCore(MemoryMgr);
13 GenerateHashString();
14 // register this object to MemoryContainer class
15 memoryMgr->Register(this);
16}
17
18SObject::SObject(bool isRegister) {
19 GenerateHashString();
20 if(isRegister) memoryMgr->Register(this);
21}
22
23SObject::~SObject() = default;
24
25
26void SObject::SetUndestroyable(bool enable) {
27 isUndestroyable = enable;
28}
29
30void SObject::Destroy() {
31 memoryMgr->ReleaseObject(this);
32
33}
34
35void SObject::__FORCE_DESTROY__() {
36 memoryMgr->ReleaseObject(this, true);
37}
38
39std::string SObject::GenerateMeta() {
40 return nullptr;
41}
42
43void SObject::GenerateHashString() {
44 std::random_device rd;
45 std::mt19937 gen(rd());
46 std::uniform_int_distribution<> dis(0, 61); // 0~9, A~Z, a~z까지 숫자 생성
47
48 m_hash.clear();
49 m_hash.reserve(16);
50
51 do {
52 m_hash = GetRandomHash(16);
53 } while (memoryMgr->HasHash(m_hash));
54}
55
56void SObject::SetHash(std::string& hash) {
57 const std::string prevHash = std::string(m_hash);
58 if(hash.empty()) {
59 GenerateHashString();
60 memoryMgr->ChangeHash(prevHash, m_hash);
61 return;
62 }
63 m_hash = hash;
64 memoryMgr->ChangeHash(prevHash, hash);
65}