Added the AssetCache class skeleton.
parent
aeaeae02b8
commit
7cc5ad8df4
|
@ -76,6 +76,9 @@ xcopy /s /e /d /y "..\..\data" "$(OutDir)data\"</Command>
|
|||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="..\..\src\Asset.cpp" />
|
||||
<ClCompile Include="..\..\src\AssetCache.cpp" />
|
||||
<ClCompile Include="..\..\src\AssetManager.cpp" />
|
||||
<ClCompile Include="..\..\src\checksum.cpp" />
|
||||
<ClCompile Include="..\..\src\Core.cpp" />
|
||||
<ClCompile Include="..\..\src\fio.cpp" />
|
||||
|
@ -107,6 +110,9 @@ xcopy /s /e /d /y "..\..\data" "$(OutDir)data\"</Command>
|
|||
<None Include="..\..\data\shaders\fb_vs.glsl" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="..\..\src\Asset.hpp" />
|
||||
<ClInclude Include="..\..\src\AssetCache.hpp" />
|
||||
<ClInclude Include="..\..\src\AssetManager.hpp" />
|
||||
<ClInclude Include="..\..\src\checksum.hpp" />
|
||||
<ClInclude Include="..\..\src\common.hpp" />
|
||||
<ClInclude Include="..\..\src\Core.hpp" />
|
||||
|
|
|
@ -72,6 +72,15 @@
|
|||
<ClCompile Include="..\..\src\fio.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\src\Asset.cpp">
|
||||
<Filter>Classes</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\src\AssetManager.cpp">
|
||||
<Filter>Classes</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\src\AssetCache.cpp">
|
||||
<Filter>Classes</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="..\..\..\..\Dev\SDL2-2.0.3\lib\x86\SDL2.dll">
|
||||
|
@ -139,5 +148,14 @@
|
|||
<ClInclude Include="..\..\src\fio.hpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\Asset.hpp">
|
||||
<Filter>Classes</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\AssetManager.hpp">
|
||||
<Filter>Classes</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\AssetCache.hpp">
|
||||
<Filter>Classes</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
</Project>
|
|
@ -3,6 +3,8 @@ Asset
|
|||
----------------
|
||||
Our basic Asset class. This class exists as a container for data, but does not directly load any data itself. It is responsible for holding data assigned by the Asset Manager and for clearing data upon destruction.
|
||||
================================================================ */
|
||||
#ifndef ASSET_HPP
|
||||
#define ASSET_HPP
|
||||
#include <string>
|
||||
|
||||
class Asset {
|
||||
|
@ -15,9 +17,9 @@ class Asset {
|
|||
};
|
||||
protected:
|
||||
unsigned int flags; // Our asset state flags
|
||||
std::string uuid; // Our UUID
|
||||
std::string filename; // Our filename, relative to the assets directory
|
||||
std::string data_checksum; // Our full data checksum
|
||||
char *data; // Our data, NULL if IS_LOADED is not set
|
||||
size_t data_length; // Our data's length, in bytes
|
||||
};
|
||||
#endif
|
|
@ -0,0 +1,65 @@
|
|||
#include "AssetCache.hpp"
|
||||
|
||||
/* ======== Construction and Destruction ======== */
|
||||
AssetCache::AssetCache() {
|
||||
}
|
||||
AssetCache::~AssetCache() {
|
||||
}
|
||||
/* ======== Cache loading ======== */
|
||||
int AssetCache::fromFile(const char *cache_file) {
|
||||
return 0;
|
||||
}
|
||||
/* fromDir
|
||||
This function will first attempt to load the .CACHE file contained in the given directory. If found, it is read in and updateCache() is called.
|
||||
If not, the function will traverse the full hierarchy of the given directory and populate the cache accordingly.
|
||||
*/
|
||||
int AssetCache::fromDir(const char *dir) {
|
||||
|
||||
return 0;
|
||||
}
|
||||
/* ======== Cache saving ======== */
|
||||
/* saveTo
|
||||
This function saves the AssetCache to the given asset cache file
|
||||
*/
|
||||
int AssetCache::saveTo(const char *cache_file) {
|
||||
return 0;
|
||||
}
|
||||
/* ======== Cache updating and validation ======== */
|
||||
/* validateCache
|
||||
This function checks the prerecorded checksums of each asset in the cache and updates the cache if any differences are found
|
||||
*/
|
||||
int AssetCache::validateCache() {
|
||||
return 0;
|
||||
}
|
||||
/* updateCache
|
||||
This function searches the cache for files that have been modified and updates the cache accordingly
|
||||
*/
|
||||
int AssetCache::updateCache() {
|
||||
return 0;
|
||||
}
|
||||
/* ======== Asset loading and creating ======== */
|
||||
/* getAsset
|
||||
This function attempts to return the given asset if it exists. If it does not exist, NULL is returned.
|
||||
The file _is not_ loaded.
|
||||
*/
|
||||
Asset* AssetCache::getAsset(const char *filename) {
|
||||
return NULL;
|
||||
}
|
||||
/* loadAsset
|
||||
This function calls getAsset then loads the asset data into memory
|
||||
*/
|
||||
Asset* AssetCache::loadAsset(const char *filename) {
|
||||
return NULL;
|
||||
}
|
||||
/* saveAsset
|
||||
This function saves the given asset's data to the corresponding data file
|
||||
*/
|
||||
Asset* AssetCache::saveAsset(const char *filename) {
|
||||
return NULL;
|
||||
}
|
||||
/* createAsset
|
||||
This function attempts to create a new Asset using some provided data
|
||||
*/
|
||||
Asset* AssetCache::createAsset(const char *filename, const char *data, size_t data_len) {
|
||||
return NULL;
|
||||
}
|
|
@ -0,0 +1,37 @@
|
|||
/* ================================================================
|
||||
Asset Cache
|
||||
----------------
|
||||
================================================================ */
|
||||
#ifndef ASSETCACHE_HPP
|
||||
#define ASSETCACHE_HPP
|
||||
#include "Asset.hpp"
|
||||
#include <vector>
|
||||
class AssetCache {
|
||||
friend class AssetManager;
|
||||
public:
|
||||
AssetCache();
|
||||
~AssetCache();
|
||||
// load
|
||||
int fromFile(const char *cache_file); // load a cache file
|
||||
int fromDir(const char *dir); // create/load a cache from the given directory
|
||||
// save
|
||||
int saveTo(const char *cache_file); // saves the loaded cache to the given file
|
||||
// update
|
||||
int validateCache(); // checks if cache files are valid and exist
|
||||
int updateCache(); // scans directory for changes and updates the cache accordingly
|
||||
// get/add
|
||||
Asset *getAsset(const char *filename); // attempts to get the given asset via filename
|
||||
Asset *loadAsset(const char *filename); // attempts to get the given asset and load its contents into memory
|
||||
Asset *saveAsset(const char *filename); // saves the given asset to disk
|
||||
Asset *createAsset(const char *filename, const char *data, size_t data_len); // create a new Asset, populating it with given data
|
||||
protected:
|
||||
std::vector<Asset> asset; // TODO: replace with HashTable
|
||||
std::string directory;
|
||||
};
|
||||
#ifdef __ANDROID__
|
||||
class ApkAssetCache : public AssetCache {
|
||||
public:
|
||||
ApkAssetCache() : AssetCache() {};
|
||||
};
|
||||
#endif
|
||||
#endif
|
|
@ -1,5 +1,17 @@
|
|||
/* ===============================================================
|
||||
AssetManager
|
||||
----------------
|
||||
TODO: On load, the APP AssetCache is loaded. The location of this Cache varies between platforms:
|
||||
* Android - assets archive, accessed via apk*
|
||||
* iOS/OSX - app Resources dir
|
||||
* Linux - global install directory? dunno
|
||||
* Windows - install dir?
|
||||
Following this, the USER AssetCache is loaded, and are:
|
||||
* Android - <Application data folder>/assets
|
||||
* iOS - <app Documents?>/assets
|
||||
* OSX - ~/Library/Application Support/RtB/assets
|
||||
* Linux - ~/.RtB/assets
|
||||
|
||||
================================================================ */
|
||||
#include "AssetManager.hpp"
|
||||
#include "Log.hpp"
|
||||
|
@ -7,10 +19,8 @@ AssetManager
|
|||
#include "checksum.hpp"
|
||||
|
||||
AssetManager::AssetManager() {
|
||||
|
||||
}
|
||||
AssetManager::~AssetManager() {
|
||||
|
||||
}
|
||||
/* ======== Asset Loading ======== */
|
||||
Asset* AssetManager::loadFile(const char *filename) {
|
||||
|
@ -22,7 +32,7 @@ Asset* AssetManager::loadFile(const char *filename) {
|
|||
LOG(LOG_ERROR) << FUNC_NAME << " read length was 0, could not load file " << filename;
|
||||
return NULL;
|
||||
}
|
||||
LOG(LOG_INFO) << FUNC_NAME << " " << filename << "'s CRC32 is " << std::hex << crc32(1337, buffer, len);
|
||||
LOG(LOG_INFO) << FUNC_NAME << " " << filename << " " << std::hex << crc32(1337, buffer, len);
|
||||
LOG(LOG_INFO) << filename << ": " << std::hex << crc32(1337, filename, strlen(filename)) << " " << std::hex << crc32(1337, buffer, len) << " " << std::hex << crc32(1337, buffer, len/2) << " " << std::hex << crc32(1337, buffer+(len/2), len/2);
|
||||
free(buffer);
|
||||
return NULL;
|
||||
|
|
|
@ -17,6 +17,7 @@ Files may be added to the Cache through the following manners:
|
|||
Beyond the File Cache, there is the Live Cache. This cache is the current list of loaded Assets. These Live Caches are generally loaded from and saved to a Campaign.
|
||||
|
||||
================================================================ */
|
||||
#include "AssetCache.hpp"
|
||||
#include "Asset.hpp"
|
||||
#include "fio.hpp"
|
||||
#include <vector>
|
||||
|
@ -27,6 +28,7 @@ class AssetManager {
|
|||
~AssetManager();
|
||||
// loads given file as an asset
|
||||
Asset* loadFile(const char *filename);
|
||||
//Asset* loadAsset(const char *filename);
|
||||
// attempts to find asset with the given UUID in the asset cache
|
||||
// Asset* loadAsset(const char *uuid);
|
||||
// saves the loaded assets in the asset cache
|
||||
|
@ -35,6 +37,6 @@ class AssetManager {
|
|||
//
|
||||
// int loadCache(const char *cachefile)
|
||||
private:
|
||||
std::vector<Asset> cache; // Cache of all files known
|
||||
// Table<Asset> live_cache; // cache of loaded assets
|
||||
std::vector<AssetCache> caches; // Caches
|
||||
AssetCache live_cache; // Cache of loaded assets
|
||||
};
|
||||
|
|
|
@ -79,6 +79,10 @@ int Core::initSystem() {
|
|||
scene = new RenderScene();
|
||||
// TEMP: this should be assigned elsewhere.
|
||||
asset_manager = new AssetManager();
|
||||
// TODO: load APP cache as first cache (using ApkAssetCache in the case of Android)
|
||||
// TODO: load USER cache as second
|
||||
// TODO: add others via user pref?
|
||||
|
||||
// TEMP: our framebuffer rendering program
|
||||
Program *program = new Program();
|
||||
// FIXME: check for GLSL version and automagically load the appropriate shader file
|
||||
|
|
Loading…
Reference in New Issue