RigsofRods
Soft-body Physics Simulation
Public Types | Public Member Functions | Private Member Functions | Static Private Member Functions | Private Attributes | Friends
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 ()
 
const std::vector< CacheEntryPtr > & GetEntries () const
 
const CategoryIdNameMapGetCategories () const
 
Ogre::String GetPrettyName (Ogre::String fname)
 
std::string ActorTypeToName (ActorType driveable)
 
const std::vector< std::string > & GetContentDirs () const
 
Startup
void LoadModCache (CacheValidity validity)
 
bool IsModCacheLoaded ()
 
Lookups
CacheEntryPtr FindEntryByFilename (RoR::LoaderType type, bool partial, const std::string &filename)
 Returns NULL if none found. More...
 
CacheEntryPtr GetEntryByNumber (int modid)
 
CacheEntryPtr FetchSkinByName (std::string const &skin_name)
 
size_t Query (CacheQuery &query)
 
Loading
void LoadResource (CacheEntryPtr &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 (CacheEntryPtr &t)
 Forces reloading the associated bundle. More...
 
void UnLoadResource (CacheEntryPtr &t)
 Unloads associated bundle, destroying all spawned actors. More...
 
void LoadSupplementaryDocuments (CacheEntryPtr &t)
 Loads the associated .truck*, .skin and .tuneup files. More...
 
void LoadAssetPack (CacheEntryPtr &t_dest, Ogre::String const &assetpack_filename)
 Adds asset pack to the requesting cache entry's resource group. More...
 
Projects
CacheEntryPtr CreateProject (CreateProjectRequest *request)
 Creates subdirectory in 'My Games\Rigs of Rods\projects', pre-populates it with files and adds modcache entry. More...
 
void ModifyProject (ModifyProjectRequest *request)
 
void DeleteProject (CacheEntryPtr &entry)
 

Private Member Functions

CacheValidity EvaluateCacheValidity ()
 
void WriteCacheFileJson ()
 
void ExportEntryToJson (rapidjson::Value &j_entries, rapidjson::Document &j_doc, CacheEntryPtr const &entry)
 
CacheValidity LoadCacheFileJson ()
 
void ImportEntryFromJson (rapidjson::Value &j_entry, CacheEntryPtr &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 GenerateHashFromFilenames ()
 For quick detection of added/removed content. More...
 
void GenerateFileCache (CacheEntryPtr &entry, Ogre::String group)
 
void RemoveFileCache (CacheEntryPtr &entry)
 
bool Match (size_t &out_score, std::string data, std::string const &query, size_t)
 
bool IsPathContentDirRoot (const std::string &path) const
 
Document loading helpers
void LoadAssociatedSkinDef (CacheEntryPtr &cache_entry)
 Loads+parses the .skin file and updates all related CacheEntries. More...
 
void LoadAssociatedTuneupDef (CacheEntryPtr &cache_entry)
 Loads+parses the .tuneup file and updates all related CacheEntries. More...
 
Cache update helpers
void FillTerrainDetailInfo (CacheEntryPtr &entry, Ogre::DataStreamPtr ds, Ogre::String fname)
 
void FillTruckDetailInfo (CacheEntryPtr &entry, Ogre::DataStreamPtr ds, Ogre::String fname, Ogre::String group)
 
void FillSkinDetailInfo (CacheEntryPtr &entry, std::shared_ptr< SkinDef > &skin_def)
 
void FillAddonPartDetailInfo (CacheEntryPtr &entry, Ogre::DataStreamPtr ds)
 
void FillTuneupDetailInfo (CacheEntryPtr &entry, TuneupDefPtr &tuneup_def)
 
void FillAssetPackDetailInfo (CacheEntryPtr &entry, Ogre::DataStreamPtr ds)
 

Static Private Member Functions

static Ogre::String StripUIDfromString (Ogre::String uidstr)
 
static Ogre::String StripSHA1fromString (Ogre::String sha1str)
 
static std::string ComposeResourceGroupName (const CacheEntryPtr &entry)
 

Private Attributes

bool m_loaded = false
 
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< CacheEntryPtrm_entries
 
std::vector< Ogre::String > m_known_extensions
 the extensions we track in the cache system More...
 
std::vector< std::string > m_content_dirs
 the various mod directories 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
 

Friends

class ContentManager
 

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. UPDATING THE CACHE: Historically it was a synchronous process which could only happen at main menu, in bulk. In October 2023 it became an ad-hoc process but all synchronous logic was kept, to be slowly phased out later. See https://github.com/RigsOfRods/rigs-of-rods/pull/3096

Definition at line 288 of file CacheSystem.h.

Member Typedef Documentation

◆ CategoryIdNameMap

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

Definition at line 292 of file CacheSystem.h.

Constructor & Destructor Documentation

◆ CacheSystem()

CacheSystem::CacheSystem ( )

Definition at line 125 of file CacheSystem.cpp.

Member Function Documentation

◆ ActorTypeToName()

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

Definition at line 525 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 700 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 1302 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 1308 of file CacheSystem.cpp.

+ Here is the call graph for this function:

◆ ClearCache()

void CacheSystem::ClearCache ( )
private

Definition at line 668 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 420 of file CacheSystem.cpp.

+ Here is the caller graph for this function:

◆ ComposeResourceGroupName()

std::string CacheSystem::ComposeResourceGroupName ( const CacheEntryPtr entry)
staticprivate

Definition at line 1377 of file CacheSystem.cpp.

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

◆ CreateProject()

CacheEntryPtr CacheSystem::CreateProject ( CreateProjectRequest request)

Creates subdirectory in 'My Games\Rigs of Rods\projects', pre-populates it with files and adds modcache entry.

Definition at line 1669 of file CacheSystem.cpp.

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

◆ DeleteProject()

void CacheSystem::DeleteProject ( CacheEntryPtr entry)

Definition at line 2051 of file CacheSystem.cpp.

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

◆ DetectDuplicates()

void CacheSystem::DetectDuplicates ( )
private

Definition at line 433 of file CacheSystem.cpp.

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

◆ EvaluateCacheValidity()

CacheValidity CacheSystem::EvaluateCacheValidity ( )
private

Definition at line 215 of file CacheSystem.cpp.

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

◆ ExportEntryToJson()

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

Definition at line 539 of file CacheSystem.cpp.

+ Here is the caller graph for this function:

◆ FetchSkinByName()

CacheEntryPtr CacheSystem::FetchSkinByName ( std::string const &  skin_name)

Definition at line 1559 of file CacheSystem.cpp.

+ Here is the caller graph for this function:

◆ FillAddonPartDetailInfo()

void CacheSystem::FillAddonPartDetailInfo ( CacheEntryPtr entry,
Ogre::DataStreamPtr  ds 
)
private

Definition at line 1176 of file CacheSystem.cpp.

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

◆ FillAssetPackDetailInfo()

void CacheSystem::FillAssetPackDetailInfo ( CacheEntryPtr entry,
Ogre::DataStreamPtr  ds 
)
private

Definition at line 1210 of file CacheSystem.cpp.

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

◆ FillSkinDetailInfo()

void CacheSystem::FillSkinDetailInfo ( CacheEntryPtr entry,
std::shared_ptr< SkinDef > &  skin_def 
)
private

Definition at line 1157 of file CacheSystem.cpp.

+ Here is the caller graph for this function:

◆ FillTerrainDetailInfo()

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

Definition at line 1136 of file CacheSystem.cpp.

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

◆ FillTruckDetailInfo()

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

Definition at line 792 of file CacheSystem.cpp.

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

◆ FillTuneupDetailInfo()

void CacheSystem::FillTuneupDetailInfo ( CacheEntryPtr entry,
TuneupDefPtr tuneup_def 
)
private

Definition at line 1242 of file CacheSystem.cpp.

+ Here is the caller graph for this function:

◆ FindEntryByFilename()

CacheEntryPtr CacheSystem::FindEntryByFilename ( RoR::LoaderType  type,
bool  partial,
const std::string &  filename 
)

Returns NULL if none found.

Definition at line 184 of file CacheSystem.cpp.

+ Here is the caller graph for this function:

◆ GenerateFileCache()

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

Definition at line 1018 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 1130 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 329 of file CacheSystem.h.

+ Here is the caller graph for this function:

◆ GetContentDirs()

const std::vector<std::string>& RoR::CacheSystem::GetContentDirs ( ) const
inline

Definition at line 334 of file CacheSystem.h.

◆ GetEntries()

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

Definition at line 328 of file CacheSystem.h.

◆ GetEntryByNumber()

CacheEntryPtr CacheSystem::GetEntryByNumber ( int  modid)

Definition at line 505 of file CacheSystem.cpp.

◆ GetPrettyName()

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

Definition at line 515 of file CacheSystem.cpp.

+ Here is the caller graph for this function:

◆ ImportEntryFromJson()

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

Definition at line 253 of file CacheSystem.cpp.

+ Here is the caller graph for this function:

◆ IsModCacheLoaded()

bool RoR::CacheSystem::IsModCacheLoaded ( )
inline

Definition at line 299 of file CacheSystem.h.

◆ IsPathContentDirRoot()

bool CacheSystem::IsPathContentDirRoot ( const std::string &  path) const
private

Definition at line 1419 of file CacheSystem.cpp.

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

◆ LoadAssetPack()

void CacheSystem::LoadAssetPack ( CacheEntryPtr t_dest,
Ogre::String const &  assetpack_filename 
)

Adds asset pack to the requesting cache entry's resource group.

Definition at line 1263 of file CacheSystem.cpp.

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

◆ LoadAssociatedSkinDef()

void CacheSystem::LoadAssociatedSkinDef ( CacheEntryPtr cache_entry)
private

Loads+parses the .skin file and updates all related CacheEntries.

Definition at line 1571 of file CacheSystem.cpp.

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

◆ LoadAssociatedTuneupDef()

void CacheSystem::LoadAssociatedTuneupDef ( CacheEntryPtr cache_entry)
private

Loads+parses the .tuneup file and updates all related CacheEntries.

Definition at line 1620 of file CacheSystem.cpp.

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

◆ LoadCacheFileJson()

CacheValidity CacheSystem::LoadCacheFileJson ( )
private

Definition at line 355 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 151 of file CacheSystem.cpp.

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

◆ LoadResource()

void CacheSystem::LoadResource ( CacheEntryPtr t)

Loads the associated resource bundle if not already done.

Definition at line 1434 of file CacheSystem.cpp.

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

◆ LoadSupplementaryDocuments()

void CacheSystem::LoadSupplementaryDocuments ( CacheEntryPtr t)

Loads the associated .truck*, .skin and .tuneup files.

Definition at line 1398 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 2227 of file CacheSystem.cpp.

+ Here is the caller graph for this function:

◆ ModifyProject()

void CacheSystem::ModifyProject ( ModifyProjectRequest request)

Definition at line 1842 of file CacheSystem.cpp.

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

◆ ParseKnownFiles()

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

Definition at line 1115 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 1092 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 1069 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 387 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 2089 of file CacheSystem.cpp.

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

◆ ReLoadResource()

void CacheSystem::ReLoadResource ( CacheEntryPtr t)

Forces reloading the associated bundle.

Definition at line 1520 of file CacheSystem.cpp.

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

◆ RemoveFileCache()

void CacheSystem::RemoveFileCache ( CacheEntryPtr entry)
private

Definition at line 1010 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 692 of file CacheSystem.cpp.

+ Here is the caller graph for this function:

◆ StripUIDfromString()

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

Definition at line 684 of file CacheSystem.cpp.

+ Here is the caller graph for this function:

◆ UnLoadResource()

void CacheSystem::UnLoadResource ( CacheEntryPtr t)

Unloads associated bundle, destroying all spawned actors.

Definition at line 1533 of file CacheSystem.cpp.

+ Here is the caller graph for this function:

◆ WriteCacheFileJson()

void CacheSystem::WriteCacheFileJson ( )
private

Definition at line 642 of file CacheSystem.cpp.

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

Friends And Related Function Documentation

◆ ContentManager

friend class ContentManager
friend

Definition at line 290 of file CacheSystem.h.

Field Documentation

◆ m_categories

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

Definition at line 394 of file CacheSystem.h.

◆ m_content_dirs

std::vector<std::string> RoR::CacheSystem::m_content_dirs
private

the various mod directories we track in the cache system

Definition at line 392 of file CacheSystem.h.

◆ m_entries

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

Definition at line 390 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 389 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 388 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 391 of file CacheSystem.h.

◆ m_loaded

bool RoR::CacheSystem::m_loaded = false
private

Definition at line 386 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 393 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 387 of file CacheSystem.h.


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