11GameScene::GameScene() {
12 m_heap->setName(
"DefaultGameSceneHeap");
16 m_totalMemoryUsed = 0;
17 EGG::ExpHeap *heap = EGG::Heap::dynamicCastToExp(m_heap);
20 heap->calcGroupSize(&m_groupSizeRecord);
21 for (
u16 groupID = 0; groupID < m_groupSizeRecord.size(); ++groupID) {
22 m_totalMemoryUsed += m_groupSizeRecord.getGroupSize(groupID);
28GameScene::~GameScene() {
32 EGG::ExpHeap *heap = EGG::Heap::dynamicCastToExp(m_heap);
35 heap->calcGroupSize(&m_groupSizeRecord);
37 for (
u16 groupID = 0; groupID < m_groupSizeRecord.size(); ++groupID) {
38 sum += m_groupSizeRecord.getGroupSize(groupID);
41 if (sum > m_totalMemoryUsed) {
42 WARN(
"MEMORY LEAK DETECTED: %zu bytes", sum - m_totalMemoryUsed);
49void GameScene::calc() {
50 System::KPadDirector::Instance()->calc();
55void GameScene::enter() {
61void GameScene::exit() {
67void GameScene::reinit() {
69 if (m_nextSceneId < 0) {
73 m_sceneMgr->changeSiblingScene(m_nextSceneId);
84 : archive(archive), id(
id) {}
87void GameScene::initScene() {
89 System::KPadDirector::Instance()->reset();
97void GameScene::deinitScene() {
98 if (m_nextSceneId >= 0) {
103 System::KPadDirector::Instance()->clear();
107void GameScene::unmountResources() {
108 auto *resourceManager = System::ResourceManager::Instance();
110 Resource *resource = *iter;
111 resourceManager->unmount(resource->archive);
118void GameScene::checkMemory() {
119 EGG::ExpHeap *heap = EGG::Heap::dynamicCastToExp(m_heap);
122 heap->calcGroupSize(&m_groupSizeRecord);
123 size_t defaultSize = m_groupSizeRecord.getGroupSize(
static_cast<u16>(GroupID::None));
132 size_t initialAllocSize = blockHead->m_size;
133 ASSERT(defaultSize >= initialAllocSize);
135 defaultSize -= initialAllocSize;
136 if (defaultSize > 0) {
137 WARN(
"Default memory usage found! %zu bytes", defaultSize);
140 for (
u16 groupID = 1; groupID < m_groupSizeRecord.size(); ++groupID) {
141 size_t size = m_groupSizeRecord.getGroupSize(groupID);
146 DEBUG(
"Group ID %d: Allocated %zu bytes", groupID, size);
150void GameScene::getMemoryLeakTags() {
151 size_t count = getMemoryLeakTagCount();
156 std::span<u32> tags = std::span<u32>(
new u32[count], count);
157 for (
auto &tag : tags) {
161 EGG::Heap::dynamicCastToExp(m_heap)->dynamicCastHandleToExp()->visitAllocated(ViewTags,
164 DEBUG(
"TAGGED MEMORY BLOCKS:");
165 printf(
"[%d", tags[0]);
166 for (u32 i = 1; i < tags.size(); ++i) {
167 printf(
", %d", tags[i]);
171 delete[] tags.data();
174size_t GameScene::getMemoryLeakTagCount() {
176 EGG::Heap::dynamicCastToExp(m_heap)->dynamicCastHandleToExp()->visitAllocated(IncreaseTagCount,
185 std::span<u32> *span =
reinterpret_cast<std::span<u32> *
>(param);
186 for (
auto &tag : *span) {
188 tag = blockHead->m_tag;
196 size_t &count = *
reinterpret_cast<size_t *
>(param);