RigsofRods
Soft-body Physics Simulation
Public Types | Public Member Functions | Private Member Functions | Static Private Member Functions | Private Attributes
RoR::CacheSystem Class Reference

A content database MOTIVATION: RoR users usually have A LOT of content installed. More...

#include <CacheSystem.h>

Public Types

typedef std::map< int, Ogre::String > CategoryIdNameMap
 

Public Member Functions

 CacheSystem ()
 
void LoadModCache (CacheValidity validity)
 
CacheEntryFindEntryByFilename (RoR::LoaderType type, bool partial, std::string filename)
 Returns NULL if none found. More...
 
CacheEntryFetchSkinByName (std::string const &skin_name)
 
CacheValidity EvaluateCacheValidity ()
 
size_t Query (CacheQuery &query)
 
void LoadResource (CacheEntry &t)
 Loads the associated resource bundle if not already done. More...
 
bool CheckResourceLoaded (Ogre::String &in_out_filename)
 Finds + loads the associated resource bundle if not already done. More...
 
bool CheckResourceLoaded (Ogre::String &in_out_filename, Ogre::String &out_group)
 Finds given resource, outputs group name. Also loads the associated resource bundle if not already done. More...
 
void ReLoadResource (CacheEntry &t)
 Forces reloading the associated bundle. More...
 
void UnLoadResource (CacheEntry &t)
 Unloads associated bundle, destroying all spawned actors. More...
 
const std::vector< CacheEntry > & GetEntries () const
 
const CategoryIdNameMapGetCategories () const
 
std::shared_ptr< RoR::SkinDefFetchSkinDef (CacheEntry *cache_entry)
 Loads+parses the .skin file once. More...
 
CacheEntryGetEntry (int modid)
 
Ogre::String GetPrettyName (Ogre::String fname)
 
std::string ActorTypeToName (ActorType driveable)
 

Private Member Functions

void WriteCacheFileJson ()
 
void ExportEntryToJson (rapidjson::Value &j_entries, rapidjson::Document &j_doc, CacheEntry const &entry)
 
CacheValidity LoadCacheFileJson ()
 
void ImportEntryFromJson (rapidjson::Value &j_entry, CacheEntry &out_entry)
 
void ParseZipArchives (Ogre::String group)
 
bool ParseKnownFiles (Ogre::String group)
 
void ParseSingleZip (Ogre::String path)
 
void ClearCache ()
 
void PruneCache ()
 
void ClearResourceGroups ()
 
void AddFile (Ogre::String group, Ogre::FileInfo f, Ogre::String ext)
 
void DetectDuplicates ()
 
void FillTerrainDetailInfo (CacheEntry &entry, Ogre::DataStreamPtr ds, Ogre::String fname)
 
void FillTruckDetailInfo (CacheEntry &entry, Ogre::DataStreamPtr ds, Ogre::String fname, Ogre::String group)
 
void GenerateHashFromFilenames ()
 For quick detection of added/removed content. More...
 
void GenerateFileCache (CacheEntry &entry, Ogre::String group)
 
void RemoveFileCache (CacheEntry &entry)
 
bool Match (size_t &out_score, std::string data, std::string const &query, size_t)
 

Static Private Member Functions

static Ogre::String StripUIDfromString (Ogre::String uidstr)
 
static Ogre::String StripSHA1fromString (Ogre::String sha1str)
 

Private Attributes

std::time_t m_update_time
 Ensures that all inserted files share the same timestamp. More...
 
std::string m_filenames_hash_loaded
 hash from cachefile, for quick update detection More...
 
std::string m_filenames_hash_generated
 stores hash over the content, for quick update detection More...
 
std::vector< CacheEntrym_entries
 
std::vector< Ogre::String > m_known_extensions
 the extensions we track in the cache system More...
 
std::set< Ogre::String > m_resource_paths
 A temporary list of existing resource paths. More...
 
std::map< int, Ogre::String > m_categories
 

Detailed Description

A content database MOTIVATION: RoR users usually have A LOT of content installed.

Traversing it all on every game startup would be a pain. HOW IT WORKS: For each recognized resource type (vehicle, terrain, skin...) an instance of 'CacheEntry' is created. These entries are persisted in file CACHE_FILE (see above) Associated media live in a "resource bundle" (ZIP archive or subdirectory) in content directory (ROR_HOME/mods) and subdirectories. If multiple CacheEntries share a bundle, the bundle is loaded only once. Each bundle has dedicated OGRE resource group.

Definition at line 190 of file CacheSystem.h.

Member Typedef Documentation

◆ CategoryIdNameMap

typedef std::map<int, Ogre::String> RoR::CacheSystem::CategoryIdNameMap

Definition at line 193 of file CacheSystem.h.

Constructor & Destructor Documentation

◆ CacheSystem()

CacheSystem::CacheSystem ( )

Definition at line 100 of file CacheSystem.cpp.

Member Function Documentation

◆ ActorTypeToName()

std::string CacheSystem::ActorTypeToName ( ActorType  driveable)

Definition at line 469 of file CacheSystem.cpp.

+ Here is the caller graph for this function:

◆ AddFile()

void CacheSystem::AddFile ( Ogre::String  group,
Ogre::FileInfo  f,
Ogre::String  ext 
)
private

Definition at line 626 of file CacheSystem.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ CheckResourceLoaded() [1/2]

bool CacheSystem::CheckResourceLoaded ( Ogre::String &  in_out_filename)

Finds + loads the associated resource bundle if not already done.

Definition at line 1071 of file CacheSystem.cpp.

+ Here is the caller graph for this function:

◆ CheckResourceLoaded() [2/2]

bool CacheSystem::CheckResourceLoaded ( Ogre::String &  in_out_filename,
Ogre::String &  out_group 
)

Finds given resource, outputs group name. Also loads the associated resource bundle if not already done.

Definition at line 1077 of file CacheSystem.cpp.

+ Here is the call graph for this function:

◆ ClearCache()

void CacheSystem::ClearCache ( )
private

Definition at line 594 of file CacheSystem.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ClearResourceGroups()

void CacheSystem::ClearResourceGroups ( )
private

Definition at line 368 of file CacheSystem.cpp.

+ Here is the caller graph for this function:

◆ DetectDuplicates()

void CacheSystem::DetectDuplicates ( )
private

Definition at line 381 of file CacheSystem.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ EvaluateCacheValidity()

CacheValidity CacheSystem::EvaluateCacheValidity ( )

Definition at line 178 of file CacheSystem.cpp.

+ Here is the call graph for this function:

◆ ExportEntryToJson()

void CacheSystem::ExportEntryToJson ( rapidjson::Value &  j_entries,
rapidjson::Document &  j_doc,
CacheEntry const &  entry 
)
private

Definition at line 483 of file CacheSystem.cpp.

+ Here is the caller graph for this function:

◆ FetchSkinByName()

CacheEntry * CacheSystem::FetchSkinByName ( std::string const &  skin_name)

Definition at line 1210 of file CacheSystem.cpp.

+ Here is the caller graph for this function:

◆ FetchSkinDef()

std::shared_ptr< SkinDef > CacheSystem::FetchSkinDef ( CacheEntry cache_entry)

Loads+parses the .skin file once.

Definition at line 1222 of file CacheSystem.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ FillTerrainDetailInfo()

void CacheSystem::FillTerrainDetailInfo ( CacheEntry entry,
Ogre::DataStreamPtr  ds,
Ogre::String  fname 
)
private

Definition at line 1050 of file CacheSystem.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ FillTruckDetailInfo()

void CacheSystem::FillTruckDetailInfo ( CacheEntry entry,
Ogre::DataStreamPtr  ds,
Ogre::String  fname,
Ogre::String  group 
)
private

Definition at line 707 of file CacheSystem.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ FindEntryByFilename()

CacheEntry * CacheSystem::FindEntryByFilename ( RoR::LoaderType  type,
bool  partial,
std::string  filename 
)

Returns NULL if none found.

Definition at line 148 of file CacheSystem.cpp.

+ Here is the caller graph for this function:

◆ GenerateFileCache()

void CacheSystem::GenerateFileCache ( CacheEntry entry,
Ogre::String  group 
)
private

Definition at line 932 of file CacheSystem.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ GenerateHashFromFilenames()

void CacheSystem::GenerateHashFromFilenames ( )
private

For quick detection of added/removed content.

Definition at line 1044 of file CacheSystem.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ GetCategories()

const CategoryIdNameMap& RoR::CacheSystem::GetCategories ( ) const
inline

Definition at line 210 of file CacheSystem.h.

+ Here is the caller graph for this function:

◆ GetEntries()

const std::vector<CacheEntry>& RoR::CacheSystem::GetEntries ( ) const
inline

Definition at line 209 of file CacheSystem.h.

◆ GetEntry()

CacheEntry * CacheSystem::GetEntry ( int  modid)

Definition at line 449 of file CacheSystem.cpp.

◆ GetPrettyName()

String CacheSystem::GetPrettyName ( Ogre::String  fname)

Definition at line 459 of file CacheSystem.cpp.

+ Here is the caller graph for this function:

◆ ImportEntryFromJson()

void CacheSystem::ImportEntryFromJson ( rapidjson::Value &  j_entry,
CacheEntry out_entry 
)
private

Definition at line 216 of file CacheSystem.cpp.

+ Here is the caller graph for this function:

◆ LoadCacheFileJson()

CacheValidity CacheSystem::LoadCacheFileJson ( )
private

Definition at line 303 of file CacheSystem.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ LoadModCache()

void CacheSystem::LoadModCache ( CacheValidity  validity)

Definition at line 116 of file CacheSystem.cpp.

+ Here is the call graph for this function:

◆ LoadResource()

void CacheSystem::LoadResource ( CacheEntry t)

Loads the associated resource bundle if not already done.

Definition at line 1111 of file CacheSystem.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ Match()

bool CacheSystem::Match ( size_t &  out_score,
std::string  data,
std::string const &  query,
size_t  score 
)
private

Definition at line 1374 of file CacheSystem.cpp.

+ Here is the caller graph for this function:

◆ ParseKnownFiles()

bool CacheSystem::ParseKnownFiles ( Ogre::String  group)
private

Definition at line 1029 of file CacheSystem.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ParseSingleZip()

void CacheSystem::ParseSingleZip ( Ogre::String  path)
private

Definition at line 1006 of file CacheSystem.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ParseZipArchives()

void CacheSystem::ParseZipArchives ( Ogre::String  group)
private

Definition at line 983 of file CacheSystem.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ PruneCache()

void CacheSystem::PruneCache ( )
private

Definition at line 335 of file CacheSystem.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ Query()

size_t CacheSystem::Query ( CacheQuery query)

Definition at line 1266 of file CacheSystem.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ReLoadResource()

void CacheSystem::ReLoadResource ( CacheEntry t)

Forces reloading the associated bundle.

Definition at line 1175 of file CacheSystem.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ RemoveFileCache()

void CacheSystem::RemoveFileCache ( CacheEntry entry)
private

Definition at line 924 of file CacheSystem.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ StripSHA1fromString()

Ogre::String CacheSystem::StripSHA1fromString ( Ogre::String  sha1str)
staticprivate

Definition at line 618 of file CacheSystem.cpp.

+ Here is the caller graph for this function:

◆ StripUIDfromString()

Ogre::String CacheSystem::StripUIDfromString ( Ogre::String  uidstr)
staticprivate

Definition at line 610 of file CacheSystem.cpp.

+ Here is the caller graph for this function:

◆ UnLoadResource()

void CacheSystem::UnLoadResource ( CacheEntry t)

Unloads associated bundle, destroying all spawned actors.

Definition at line 1188 of file CacheSystem.cpp.

+ Here is the caller graph for this function:

◆ WriteCacheFileJson()

void CacheSystem::WriteCacheFileJson ( )
private

Definition at line 568 of file CacheSystem.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Field Documentation

◆ m_categories

std::map<int, Ogre::String> RoR::CacheSystem::m_categories
private

Definition at line 256 of file CacheSystem.h.

◆ m_entries

std::vector<CacheEntry> RoR::CacheSystem::m_entries
private

Definition at line 253 of file CacheSystem.h.

◆ m_filenames_hash_generated

std::string RoR::CacheSystem::m_filenames_hash_generated
private

stores hash over the content, for quick update detection

Definition at line 252 of file CacheSystem.h.

◆ m_filenames_hash_loaded

std::string RoR::CacheSystem::m_filenames_hash_loaded
private

hash from cachefile, for quick update detection

Definition at line 251 of file CacheSystem.h.

◆ m_known_extensions

std::vector<Ogre::String> RoR::CacheSystem::m_known_extensions
private

the extensions we track in the cache system

Definition at line 254 of file CacheSystem.h.

◆ m_resource_paths

std::set<Ogre::String> RoR::CacheSystem::m_resource_paths
private

A temporary list of existing resource paths.

Definition at line 255 of file CacheSystem.h.

◆ m_update_time

std::time_t RoR::CacheSystem::m_update_time
private

Ensures that all inserted files share the same timestamp.

Definition at line 250 of file CacheSystem.h.


The documentation for this class was generated from the following files: