janwas
8667ea74c8
- directoryPosix: replace most methods with boost filesystem (but not all: the latter cannot efficiently enumerate files AND query their size/mtime) - AllocatorChecker: better name for member functions - file: move the File class here - trace: bugfix - io: move UnalignedWriter to write_buffer.cpp (basically the same thing) - vfs: remove unnecessary "vfs" warts from variable names - vfs_tree: VfsFile now stores single Name/Size/MTime fields instead of the FileInfo record (less clunky) - vfs_path: use boost filesystem's version of the basename/extension functions - lf_alloc: remove (no longer necessary, won't be finished - not worth the trouble) - path_util: remove path_foreach_component (replaced by better path traversal logic) and PathPackage (obsoleted by fs::path) ! resource loading code now receives VfsPath as its filename. there is also OsPath (native absolute path) and Path (relative to binaries/data) - tex is now independent of file loading code; it just en/decodes in-memory buffers - wdll_ver: clean up, use smart pointer to simplify bailout code - wsdl: remove nonexistent failure path from calc_gamma (cruised by here because SDL_SetGamme is failing once after a cold boot at work) - wsnd: simplify OpenAL DLL search, use boost::filesystem - wutil: Wow64 redirection is now packaged in a (RAII) class This was SVN commit r5525.
69 lines
2.1 KiB
C++
69 lines
2.1 KiB
C++
#include "precompiled.h"
|
|
|
|
#include "TechnologyCollection.h"
|
|
#include "ps/CLogger.h"
|
|
#include "ps/Player.h"
|
|
|
|
#define LOG_CATEGORY "tech"
|
|
|
|
void CTechnologyCollection::LoadFile( const VfsPath& pathname )
|
|
{
|
|
const CStrW basename(fs::basename((const fs::path&)pathname));
|
|
m_techFilenames[basename] = pathname.string();
|
|
}
|
|
|
|
static LibError LoadTechThunk( const VfsPath& pathname, const FileInfo& UNUSED(fileInfo), uintptr_t cbData )
|
|
{
|
|
CTechnologyCollection* this_ = (CTechnologyCollection*)cbData;
|
|
this_->LoadFile(pathname);
|
|
return INFO::CB_CONTINUE;
|
|
}
|
|
|
|
int CTechnologyCollection::LoadTechnologies()
|
|
{
|
|
// Load all files in techs/ and subdirectories.
|
|
THROW_ERR( fs_ForEachFile(g_VFS, "technologies/", LoadTechThunk, (uintptr_t)this, "*.xml", DIR_RECURSIVE));
|
|
return 0;
|
|
}
|
|
|
|
CTechnology* CTechnologyCollection::GetTechnology( const CStrW& name, CPlayer* player )
|
|
{
|
|
// Find player ID
|
|
debug_assert( player != 0 );
|
|
int id = player->GetPlayerID();
|
|
|
|
// Check whether this template has already been loaded.
|
|
//If previously loaded, all slots will be found, so any entry works.
|
|
TechMap::iterator it = m_techs[id].find( name );
|
|
if( it != m_techs[id].end() )
|
|
return( it->second );
|
|
|
|
// Find the filename corresponding to this template
|
|
TechFilenameMap::iterator filename_it = m_techFilenames.find( name );
|
|
if( filename_it == m_techFilenames.end() )
|
|
return( NULL );
|
|
|
|
CStr path( filename_it->second );
|
|
|
|
//Try to load to the tech
|
|
CTechnology* newTemplate = new CTechnology( name, player );
|
|
if( !newTemplate->LoadXml( path ) )
|
|
{
|
|
LOG(ERROR, LOG_CATEGORY, "CTechnologyCollection::GetTechnology(): Couldn't load tech \"%s\"", path.c_str());
|
|
delete newTemplate;
|
|
return( NULL );
|
|
|
|
}
|
|
m_techs[id][name] = newTemplate;
|
|
|
|
LOG(NORMAL, LOG_CATEGORY, "CTechnologyCollection::GetTechnology(): Loaded tech \"%s\"", path.c_str());
|
|
return newTemplate;
|
|
}
|
|
|
|
CTechnologyCollection::~CTechnologyCollection()
|
|
{
|
|
for( uint id=0; id<PS_MAX_PLAYERS+1; id++ )
|
|
for( TechMap::iterator it = m_techs[id].begin(); it != m_techs[id].end(); ++it )
|
|
delete( it->second );
|
|
}
|