mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-04-21 00:25:44 +00:00
ZoneLoading: Add ZoneMemory and the possibility to unload zones and their memory
This commit is contained in:
parent
d224eb8ce5
commit
7121f2e215
@ -8,5 +8,6 @@ class IGame
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
virtual void AddZone(Zone* zone) = 0;
|
virtual void AddZone(Zone* zone) = 0;
|
||||||
|
virtual void RemoveZone(Zone* zone) = 0;
|
||||||
virtual std::vector<Zone*> GetZones() = 0;
|
virtual std::vector<Zone*> GetZones() = 0;
|
||||||
};
|
};
|
@ -10,6 +10,14 @@ void GameT6::AddZone(Zone* zone)
|
|||||||
m_zones.push_back(zone);
|
m_zones.push_back(zone);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void GameT6::RemoveZone(Zone* zone)
|
||||||
|
{
|
||||||
|
const auto foundEntry = std::find(m_zones.begin(), m_zones.end(), zone);
|
||||||
|
|
||||||
|
if (foundEntry != m_zones.end())
|
||||||
|
m_zones.erase(foundEntry);
|
||||||
|
}
|
||||||
|
|
||||||
std::vector<Zone*> GameT6::GetZones()
|
std::vector<Zone*> GameT6::GetZones()
|
||||||
{
|
{
|
||||||
return m_zones;
|
return m_zones;
|
||||||
|
@ -7,6 +7,7 @@ class GameT6 : public IGame
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
void AddZone(Zone* zone) override;
|
void AddZone(Zone* zone) override;
|
||||||
|
void RemoveZone(Zone* zone) override;
|
||||||
std::vector<Zone*> GetZones() override;
|
std::vector<Zone*> GetZones() override;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -146,12 +146,15 @@ public:
|
|||||||
|
|
||||||
m_linked_asset_pools.erase(iLinkEntry);
|
m_linked_asset_pools.erase(iLinkEntry);
|
||||||
|
|
||||||
for(auto iAssetEntry = m_assets.begin(); iAssetEntry != m_assets.end(); ++iAssetEntry)
|
for(auto iAssetEntry = m_assets.begin(); iAssetEntry != m_assets.end(); )
|
||||||
{
|
{
|
||||||
auto& assetEntry = *iAssetEntry;
|
auto& assetEntry = *iAssetEntry;
|
||||||
|
|
||||||
if(assetEntry.second.m_duplicate && ReplaceAssetPoolEntry(assetEntry.second))
|
if(assetEntry.second.m_duplicate && ReplaceAssetPoolEntry(assetEntry.second))
|
||||||
|
{
|
||||||
|
++iAssetEntry;
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
iAssetEntry = m_assets.erase(iAssetEntry);
|
iAssetEntry = m_assets.erase(iAssetEntry);
|
||||||
}
|
}
|
||||||
|
@ -7,9 +7,39 @@ Zone::Zone(std::string name, const zone_priority_t priority, IZoneAssetPools* po
|
|||||||
m_pools = pools;
|
m_pools = pools;
|
||||||
m_game = game;
|
m_game = game;
|
||||||
m_language = ZoneLanguage::LANGUAGE_NONE;
|
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
|
IZoneAssetPools* Zone::GetPools() const
|
||||||
{
|
{
|
||||||
return m_pools;
|
return m_pools;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ZoneMemory* Zone::GetMemory() const
|
||||||
|
{
|
||||||
|
return m_memory;
|
||||||
|
}
|
||||||
|
@ -2,6 +2,8 @@
|
|||||||
#include "ZoneTypes.h"
|
#include "ZoneTypes.h"
|
||||||
#include "Pool/IZoneAssetPools.h"
|
#include "Pool/IZoneAssetPools.h"
|
||||||
#include "Game/IGame.h"
|
#include "Game/IGame.h"
|
||||||
|
#include "Zone/XBlock.h"
|
||||||
|
#include "ZoneMemory.h"
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
class IGame;
|
class IGame;
|
||||||
@ -34,6 +36,10 @@ enum class ZoneLanguage
|
|||||||
class Zone
|
class Zone
|
||||||
{
|
{
|
||||||
IZoneAssetPools* m_pools;
|
IZoneAssetPools* m_pools;
|
||||||
|
std::vector<XBlock*> m_blocks;
|
||||||
|
ZoneMemory* m_memory;
|
||||||
|
|
||||||
|
bool m_registered;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
std::string m_name;
|
std::string m_name;
|
||||||
@ -42,6 +48,10 @@ public:
|
|||||||
IGame* m_game;
|
IGame* m_game;
|
||||||
|
|
||||||
Zone(std::string name, zone_priority_t priority, IZoneAssetPools* pools, IGame* game);
|
Zone(std::string name, zone_priority_t priority, IZoneAssetPools* pools, IGame* game);
|
||||||
|
~Zone();
|
||||||
|
|
||||||
|
void Register();
|
||||||
|
|
||||||
IZoneAssetPools* GetPools() const;
|
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);
|
||||||
|
};
|
@ -48,6 +48,8 @@ void ZoneLoader::AddXBlock(XBlock* block)
|
|||||||
{
|
{
|
||||||
return b1->m_index < b2->m_index;
|
return b1->m_index < b2->m_index;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
m_zone->GetMemory()->AddBlock(block);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ZoneLoader::AddLoadingStep(ILoadingStep* step)
|
void ZoneLoader::AddLoadingStep(ILoadingStep* step)
|
||||||
@ -88,7 +90,7 @@ Zone* ZoneLoader::LoadZone(FileAPI::File* file)
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_zone->m_game->AddZone(m_zone);
|
m_zone->Register();
|
||||||
|
|
||||||
return m_zone;
|
return m_zone;
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user