forked from 0ad/0ad
janwas
c0ed950657
this snowballed into a massive search+destroy of the hodgepodge of mostly equivalent types we had in use (int, uint, unsigned, unsigned int, i32, u32, ulong, uintN). it is more efficient to use 64-bit types in 64-bit mode, so the preferred default is size_t (for anything remotely resembling a size or index). tile coordinates are ssize_t to allow more efficient conversion to/from floating point. flags are int because we almost never need more than 15 distinct bits, bit test/set is not slower and int is fastest to type. finally, some data that is pretty much directly passed to OpenGL is now typed accordingly. after several hours, the code now requires fewer casts and less guesswork. other changes: - unit and player IDs now have an "invalid id" constant in the respective class to avoid casting and -1 - fix some endian/64-bit bugs in the map (un)packing. added a convenience function to write/read a size_t. - ia32: change CPUID interface to allow passing in ecx (required for cache topology detection, which I need at work). remove some unneeded functions from asm, replace with intrinsics where possible. This was SVN commit r5942.
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(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 );
|
|
const size_t 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(CLogger::Error, LOG_CATEGORY, "CTechnologyCollection::GetTechnology(): Couldn't load tech \"%s\"", path.c_str());
|
|
delete newTemplate;
|
|
return( NULL );
|
|
|
|
}
|
|
m_techs[id][name] = newTemplate;
|
|
|
|
LOG(CLogger::Normal, LOG_CATEGORY, "CTechnologyCollection::GetTechnology(): Loaded tech \"%s\"", path.c_str());
|
|
return newTemplate;
|
|
}
|
|
|
|
CTechnologyCollection::~CTechnologyCollection()
|
|
{
|
|
for( size_t 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 );
|
|
}
|