Asset Index loader implemented (can not test yet)
Beginnings of asset pipeline designedGui_Panel_Refactor
parent
5bd27e5f15
commit
03fb715622
@ -0,0 +1,38 @@
|
||||
|
||||
<game name>.bin
|
||||
This is the first file that will be loaded. <game name> will be set by with the
|
||||
editor and the engine_state.xml file will direct the engine to this file.
|
||||
|
||||
FORMAT:
|
||||
Engine ID, 8 bytes (should say "lunarium")
|
||||
Engine version, 3 bytes (major, minor, patch)
|
||||
|
||||
|
||||
|
||||
index.dat
|
||||
This is an index of all of the assets in the game project. Each asset will be
|
||||
listed by name (and/or ID) followed by the file name and offset position within
|
||||
the file where the asset can be found (ex. the asset with ID 6 might be found in file assets0.dat at byte offset 93846).
|
||||
|
||||
FORMAT:
|
||||
Number of assets, 4 bytes
|
||||
|
||||
[REPEAT]
|
||||
Asset ID, 4 bytes
|
||||
Name Size, 2 bytes
|
||||
Asset Name, <Name Size> bytes (Must be null-terminated)
|
||||
Asset Type, 2 bytes
|
||||
File Name Size, 2 bytes
|
||||
Asset File, <File Name Size> bytes (Must be null-terminated)
|
||||
Asset Offset, 4 bytes
|
||||
[REPEAT - for all assets]
|
||||
|
||||
asset0.dat
|
||||
This is an asset pack file. There could be many of these files and when there are
|
||||
more than one the 0 in the file name will increase on each file (assets0.dat, assets1.dat, assets2.dat etc..)
|
||||
|
||||
FORMAT:
|
||||
Asset ID, 4 bytes
|
||||
Asset Data Size, 4 bytes
|
||||
Asset Data, <Data Size> bytes
|
||||
[REPEAT FOR EACH ASSET]
|
||||
@ -0,0 +1,55 @@
|
||||
/******************************************************************************
|
||||
* File - assetManager.h
|
||||
* Author - Joey Pollack
|
||||
* Date - 2021/10/25 (y/m/d)
|
||||
* Mod Date - 2021/10/25 (y/m/d)
|
||||
* Description - Manages loading/unloading of all data/assets
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef ASSET_MANAGER_H_
|
||||
#define ASSET_MANAGER_H_
|
||||
|
||||
#include <vector>
|
||||
#include <map>
|
||||
#include <string>
|
||||
|
||||
namespace lunarium
|
||||
{
|
||||
class Asset;
|
||||
|
||||
class AssetManager
|
||||
{
|
||||
public:
|
||||
static AssetManager& GetInstance();
|
||||
|
||||
OpRes Initialize();
|
||||
void Shutdown();
|
||||
|
||||
// Used for preloading a list of assets
|
||||
OpRes LoadAssets(std::vector<std::string> names);
|
||||
Asset* GetAsset(std::string name);
|
||||
void ReturnAsset(Asset* pAsset)
|
||||
void UnloadAsset(std::string name);
|
||||
|
||||
private:
|
||||
|
||||
static AssetManager* mpInstance;
|
||||
|
||||
struct AssetBox
|
||||
{
|
||||
Asset* asset;
|
||||
int references;
|
||||
};
|
||||
|
||||
// Assets stored by name
|
||||
std::map<std::string, AssetBox> mAssets;
|
||||
|
||||
private:
|
||||
AssetManager();
|
||||
AssetManager(const AssetManager&) = delete;
|
||||
AssetManager& operator=(const AssetManager&) = delete;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // ASSET_MANAGER_H_
|
||||
@ -0,0 +1,106 @@
|
||||
/******************************************************************************
|
||||
* File - assetIndex.h
|
||||
* Author - Joey Pollack
|
||||
* Date - 2021/10/25 (y/m/d)
|
||||
* Mod Date - 2021/10/25 (y/m/d)
|
||||
* Description - Loads and stores the index.dat file. Allows querying
|
||||
* the asset index by asset ID or name.
|
||||
******************************************************************************/
|
||||
|
||||
#include "assetIndex.h"
|
||||
#include <utils/binaryFileBuffer.h>
|
||||
|
||||
namespace lunarium
|
||||
{
|
||||
AssetIndex* AssetIndex::mpInstance = nullptr;
|
||||
|
||||
AssetIndex::AssetIndex()
|
||||
{
|
||||
}
|
||||
|
||||
AssetIndex& AssetIndex::GetInstance()
|
||||
{
|
||||
if (!mpInstance)
|
||||
{
|
||||
mpInstance = new AssetIndex;
|
||||
}
|
||||
|
||||
return *mpInstance;
|
||||
}
|
||||
|
||||
void AssetIndex::FreeInstance()
|
||||
{
|
||||
for (auto iter = mpInstance->mAssets.begin(); iter != mpInstance->mAssets.end(); iter++)
|
||||
{
|
||||
delete iter->second;
|
||||
}
|
||||
|
||||
mpInstance->mAssets.clear();
|
||||
mpInstance->mAssetsByName.clear();
|
||||
|
||||
delete mpInstance;
|
||||
mpInstance = nullptr;
|
||||
}
|
||||
|
||||
|
||||
OpRes AssetIndex::LoadIndex(const char* filename)
|
||||
{
|
||||
BinaryFileBuffer buffer;
|
||||
if (!buffer.LoadFile(filename))
|
||||
{
|
||||
return OpRes::Fail("AssetIndex::LoadIndex - unable to load file: %s", filename);
|
||||
}
|
||||
|
||||
int32_t num_assets = 0;
|
||||
buffer.Read((char*) &num_assets, 4);
|
||||
|
||||
char str_buf[512];
|
||||
|
||||
for (int i = 0; i < num_assets; i++)
|
||||
{
|
||||
AssetInfo* pAI = new AssetInfo;
|
||||
buffer.Read((char*) &pAI->ID, 4);
|
||||
|
||||
int16_t name_size = 0;
|
||||
buffer.Read((char*) &name_size, 2);
|
||||
buffer.Read(str_buf, name_size);
|
||||
pAI->Name = str_buf;
|
||||
|
||||
buffer.Read((char*) &pAI->Type, 2);
|
||||
buffer.Read((char*) &name_size, 2);
|
||||
buffer.Read(str_buf, name_size);
|
||||
pAI->File = str_buf;
|
||||
|
||||
buffer.Read((char*) &pAI->Offset, 4);
|
||||
|
||||
mAssets[pAI->ID] = pAI;
|
||||
mAssetsByName[pAI->Name] = pAI;
|
||||
}
|
||||
|
||||
buffer.Unload();
|
||||
|
||||
return OpRes::OK();
|
||||
}
|
||||
|
||||
const AssetIndex::AssetInfo* AssetIndex::GetAssetInfo(int id) const
|
||||
{
|
||||
auto res = mAssets.find(id);
|
||||
if (res != mAssets.end())
|
||||
{
|
||||
return res->second;
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
const AssetIndex::AssetInfo* AssetIndex::GetAssetInfo(const char* name) const
|
||||
{
|
||||
auto res = mAssetsByName.find(name);
|
||||
if (res != mAssetsByName.end())
|
||||
{
|
||||
return res->second;
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,54 @@
|
||||
/******************************************************************************
|
||||
* File - assetIndex.h
|
||||
* Author - Joey Pollack
|
||||
* Date - 2021/10/25 (y/m/d)
|
||||
* Mod Date - 2021/10/25 (y/m/d)
|
||||
* Description - Loads and stores the index.dat file. Allows querying
|
||||
* the asset index by asset ID or name.
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef ASSET_INDEX_H_
|
||||
#define ASSET_INDEX_H_
|
||||
|
||||
#include <string>
|
||||
#include <map>
|
||||
#include <assets/types/asset.h>
|
||||
#include <utils/opRes.h>
|
||||
#include <utils/types.h>
|
||||
|
||||
namespace lunarium
|
||||
{
|
||||
class AssetIndex
|
||||
{
|
||||
public:
|
||||
struct AssetInfo
|
||||
{
|
||||
int32_t ID;
|
||||
std::string Name;
|
||||
AssetType Type;
|
||||
std::string File;
|
||||
int32_t Offset;
|
||||
};
|
||||
|
||||
public:
|
||||
|
||||
static AssetIndex& GetInstance();
|
||||
static void FreeInstance();
|
||||
|
||||
OpRes LoadIndex(const char* filename);
|
||||
const AssetInfo* GetAssetInfo(int id) const;
|
||||
const AssetInfo* GetAssetInfo(const char* name) const;
|
||||
|
||||
|
||||
private:
|
||||
static AssetIndex* mpInstance;
|
||||
std::map<int, AssetInfo*> mAssets;
|
||||
std::map<std::string, AssetInfo*> mAssetsByName;
|
||||
|
||||
AssetIndex();
|
||||
AssetIndex(const AssetIndex&) = delete;
|
||||
AssetIndex& operator=(const AssetIndex&) = delete;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // ASSET_INDEX_H_
|
||||
@ -0,0 +1,29 @@
|
||||
/******************************************************************************
|
||||
* File - asset.cpp
|
||||
* Author - Joey Pollack
|
||||
* Date - 2021/10/25 (y/m/d)
|
||||
* Mod Date - 2021/10/25 (y/m/d)
|
||||
* Description - The base class for all asset type files
|
||||
******************************************************************************/
|
||||
|
||||
#include "asset.h"
|
||||
|
||||
namespace lunarium
|
||||
{
|
||||
Asset::Asset(AssetType type)
|
||||
: mType(type)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
Asset::~Asset()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
AssetType Asset::GetType() const
|
||||
{
|
||||
return mType;
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,34 @@
|
||||
/******************************************************************************
|
||||
* File - asset.h
|
||||
* Author - Joey Pollack
|
||||
* Date - 2021/10/25 (y/m/d)
|
||||
* Mod Date - 2021/10/25 (y/m/d)
|
||||
* Description - The base class for all asset type files
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef ASSET_H_
|
||||
#define ASSET_H_
|
||||
|
||||
namespace lunarium
|
||||
{
|
||||
enum AssetType
|
||||
{
|
||||
ASSET_TYPE_IMAGE,
|
||||
ASSET_TYPE_SCRIPT,
|
||||
ASSET_TYPE_AUDIO,
|
||||
ASSET_TYPE_UNKNOWN,
|
||||
};
|
||||
|
||||
class Asset
|
||||
{
|
||||
public:
|
||||
Asset(AssetType type = AssetType::ASSET_TYPE_UNKNOWN);
|
||||
virtual ~Asset() = 0;
|
||||
|
||||
AssetType GetType() const;
|
||||
private:
|
||||
AssetType mType;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // ASSET_H_
|
||||
Loading…
Reference in New Issue