MCPcopy Create free account
hub / github.com/OpenLoco/OpenLoco / reset

Function reset

src/OpenLoco/src/Entities/EntityManager.cpp:39–96  ·  view source on GitHub ↗

0x0046FDFD

Source from the content-addressed store, hash-verified

37
38 // 0x0046FDFD
39 void reset()
40 {
41 // Reset all entities to 0
42 std::fill(std::begin(rawEntities()), std::end(rawEntities()), Entity{});
43 // Reset all entity lists
44 std::fill(std::begin(rawListCounts()), std::end(rawListCounts()), 0);
45 std::fill(std::begin(rawListHeads()), std::end(rawListHeads()), EntityId::null);
46
47 // Remake null entities (size maxNormalEntities)
48 EntityBase* previous = nullptr;
49 uint16_t id = 0;
50 for (; id < Limits::maxNormalEntities; ++id)
51 {
52 auto& ent = rawEntities()[id];
53 ent.baseType = EntityBaseType::null;
54 ent.id = EntityId(id);
55 ent.nextEntityId = EntityId::null;
56 ent.linkedListOffset = getLinkedListOffset(EntityListType::null);
57 if (previous == nullptr)
58 {
59 ent.llPreviousId = EntityId::null;
60 rawListHeads()[enumValue(EntityListType::null)] = EntityId(id);
61 }
62 else
63 {
64 ent.llPreviousId = previous->id;
65 previous->nextEntityId = EntityId(id);
66 }
67 previous = &ent;
68 }
69 rawListCounts()[enumValue(EntityListType::null)] = Limits::maxNormalEntities;
70
71 // Remake null money entities (size kMaxMoneyEntities)
72 previous = nullptr;
73 for (; id < Limits::kMaxEntities; ++id)
74 {
75 auto& ent = rawEntities()[id];
76 ent.baseType = EntityBaseType::null;
77 ent.id = EntityId(id);
78 ent.nextEntityId = EntityId::null;
79 ent.linkedListOffset = getLinkedListOffset(EntityListType::nullMoney);
80 if (previous == nullptr)
81 {
82 ent.llPreviousId = EntityId::null;
83 rawListHeads()[enumValue(EntityListType::nullMoney)] = EntityId(id);
84 }
85 else
86 {
87 ent.llPreviousId = previous->id;
88 previous->nextEntityId = EntityId(id);
89 }
90 previous = &ent;
91 }
92 rawListCounts()[enumValue(EntityListType::nullMoney)] = Limits::kMaxMoneyEntities;
93
94 resetSpatialIndex();
95 EntityTweener::get().reset();
96 }

Callers 1

preTickMethod · 0.70

Calls 8

beginFunction · 0.85
endFunction · 0.85
EntityIdEnum · 0.85
getLinkedListOffsetFunction · 0.85
enumValueFunction · 0.85
resetSpatialIndexFunction · 0.85
getFunction · 0.70
resetMethod · 0.45

Tested by

no test coverage detected