diff --git a/build/vs/vs.vcxproj b/build/vs/vs.vcxproj index 2f3f095..b9a8796 100644 --- a/build/vs/vs.vcxproj +++ b/build/vs/vs.vcxproj @@ -76,6 +76,9 @@ xcopy /s /e /d /y "..\..\data" "$(OutDir)data\" + + + @@ -107,6 +110,9 @@ xcopy /s /e /d /y "..\..\data" "$(OutDir)data\" + + + diff --git a/build/vs/vs.vcxproj.filters b/build/vs/vs.vcxproj.filters index 76bf59a..b12241d 100644 --- a/build/vs/vs.vcxproj.filters +++ b/build/vs/vs.vcxproj.filters @@ -72,6 +72,15 @@ Source Files + + Classes + + + Classes + + + Classes + @@ -139,5 +148,14 @@ Source Files + + Classes + + + Classes + + + Classes + \ No newline at end of file diff --git a/src/Asset.hpp b/src/Asset.hpp index 0f46104..2f6a174 100644 --- a/src/Asset.hpp +++ b/src/Asset.hpp @@ -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 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 \ No newline at end of file diff --git a/src/AssetCache.cpp b/src/AssetCache.cpp new file mode 100644 index 0000000..e1285ed --- /dev/null +++ b/src/AssetCache.cpp @@ -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; +} \ No newline at end of file diff --git a/src/AssetCache.hpp b/src/AssetCache.hpp new file mode 100644 index 0000000..ab2b889 --- /dev/null +++ b/src/AssetCache.hpp @@ -0,0 +1,37 @@ +/* ================================================================ +Asset Cache +---------------- +================================================================ */ +#ifndef ASSETCACHE_HPP +#define ASSETCACHE_HPP +#include "Asset.hpp" +#include +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; // TODO: replace with HashTable + std::string directory; +}; +#ifdef __ANDROID__ +class ApkAssetCache : public AssetCache { + public: + ApkAssetCache() : AssetCache() {}; +}; +#endif +#endif \ No newline at end of file diff --git a/src/AssetManager.cpp b/src/AssetManager.cpp index 7bb2119..20437f2 100644 --- a/src/AssetManager.cpp +++ b/src/AssetManager.cpp @@ -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 - /assets + * iOS - /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; diff --git a/src/AssetManager.hpp b/src/AssetManager.hpp index a779def..abdbc22 100644 --- a/src/AssetManager.hpp +++ b/src/AssetManager.hpp @@ -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 @@ -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 cache; // Cache of all files known - // Table live_cache; // cache of loaded assets + std::vector caches; // Caches + AssetCache live_cache; // Cache of loaded assets }; diff --git a/src/Core.cpp b/src/Core.cpp index 4594ea3..4912080 100644 --- a/src/Core.cpp +++ b/src/Core.cpp @@ -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