mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-06-22 12:47:53 -05:00
ZoneLoading: Add ZoneMemory and the possibility to unload zones and their memory
This commit is contained in:
@ -7,9 +7,39 @@ Zone::Zone(std::string name, const zone_priority_t priority, IZoneAssetPools* po
|
||||
m_pools = pools;
|
||||
m_game = game;
|
||||
m_language = ZoneLanguage::LANGUAGE_NONE;
|
||||
m_memory = new ZoneMemory();
|
||||
m_registered = false;
|
||||
}
|
||||
|
||||
Zone::~Zone()
|
||||
{
|
||||
if(m_registered)
|
||||
{
|
||||
m_game->RemoveZone(this);
|
||||
}
|
||||
|
||||
delete m_pools;
|
||||
m_pools = nullptr;
|
||||
|
||||
delete m_memory;
|
||||
m_memory = nullptr;
|
||||
}
|
||||
|
||||
void Zone::Register()
|
||||
{
|
||||
if (!m_registered)
|
||||
{
|
||||
m_game->AddZone(this);
|
||||
m_registered = true;
|
||||
}
|
||||
}
|
||||
|
||||
IZoneAssetPools* Zone::GetPools() const
|
||||
{
|
||||
return m_pools;
|
||||
}
|
||||
|
||||
ZoneMemory* Zone::GetMemory() const
|
||||
{
|
||||
return m_memory;
|
||||
}
|
||||
|
@ -2,6 +2,8 @@
|
||||
#include "ZoneTypes.h"
|
||||
#include "Pool/IZoneAssetPools.h"
|
||||
#include "Game/IGame.h"
|
||||
#include "Zone/XBlock.h"
|
||||
#include "ZoneMemory.h"
|
||||
#include <string>
|
||||
|
||||
class IGame;
|
||||
@ -34,6 +36,10 @@ enum class ZoneLanguage
|
||||
class Zone
|
||||
{
|
||||
IZoneAssetPools* m_pools;
|
||||
std::vector<XBlock*> m_blocks;
|
||||
ZoneMemory* m_memory;
|
||||
|
||||
bool m_registered;
|
||||
|
||||
public:
|
||||
std::string m_name;
|
||||
@ -42,6 +48,10 @@ public:
|
||||
IGame* m_game;
|
||||
|
||||
Zone(std::string name, zone_priority_t priority, IZoneAssetPools* pools, IGame* game);
|
||||
~Zone();
|
||||
|
||||
void Register();
|
||||
|
||||
IZoneAssetPools* GetPools() const;
|
||||
ZoneMemory* GetMemory() const;
|
||||
};
|
||||
|
40
src/ZoneCommon/Zone/ZoneMemory.cpp
Normal file
40
src/ZoneCommon/Zone/ZoneMemory.cpp
Normal file
@ -0,0 +1,40 @@
|
||||
#include "ZoneMemory.h"
|
||||
|
||||
ZoneMemory::ZoneMemory()
|
||||
= default;
|
||||
|
||||
ZoneMemory::~ZoneMemory()
|
||||
{
|
||||
for (auto block : m_blocks)
|
||||
{
|
||||
delete block;
|
||||
}
|
||||
m_blocks.clear();
|
||||
|
||||
for (auto allocation : m_allocations)
|
||||
{
|
||||
free(allocation);
|
||||
}
|
||||
m_allocations.clear();
|
||||
}
|
||||
|
||||
void ZoneMemory::AddBlock(XBlock* block)
|
||||
{
|
||||
m_blocks.push_back(block);
|
||||
}
|
||||
|
||||
void* ZoneMemory::Alloc(const size_t size)
|
||||
{
|
||||
void* result = malloc(size);
|
||||
m_allocations.push_back(result);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
char* ZoneMemory::Dup(const char* str)
|
||||
{
|
||||
char* result = _strdup(str);
|
||||
m_allocations.push_back(result);
|
||||
|
||||
return result;
|
||||
}
|
19
src/ZoneCommon/Zone/ZoneMemory.h
Normal file
19
src/ZoneCommon/Zone/ZoneMemory.h
Normal file
@ -0,0 +1,19 @@
|
||||
#pragma once
|
||||
|
||||
#include "Zone/XBlock.h"
|
||||
#include <vector>
|
||||
|
||||
class ZoneMemory
|
||||
{
|
||||
std::vector<XBlock*> m_blocks;
|
||||
std::vector<void*> m_allocations;
|
||||
|
||||
public:
|
||||
ZoneMemory();
|
||||
~ZoneMemory();
|
||||
|
||||
void AddBlock(XBlock* block);
|
||||
|
||||
void* Alloc(size_t size);
|
||||
char* Dup(const char* str);
|
||||
};
|
Reference in New Issue
Block a user