本文整理汇总了C++中cconfigfile::CVar::asInt方法的典型用法代码示例。如果您正苦于以下问题:C++ CVar::asInt方法的具体用法?C++ CVar::asInt怎么用?C++ CVar::asInt使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cconfigfile::CVar
的用法示例。
在下文中一共展示了CVar::asInt方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: cbTPTicksUp
//-----------------------------------------------
// cbTicksUp
//
//-----------------------------------------------
void cbTPTicksUp(const std::string &serviceName, TServiceId id, void *arg)
{
nlinfo ("TICKS is up, I can start");
// register to tick service
CMessage msgout("REGISTER");
bool tocking = true;
uint16 threshold = 0;
CConfigFile::CVar *cvTocking = IService::getInstance()->ConfigFile.getVarPtr("Tocking");
if(cvTocking)
tocking = (cvTocking->asInt()==0) ? false : true;
if(!tocking)
{
CConfigFile::CVar *cvThreshold = IService::getInstance()->ConfigFile.getVarPtr("Threshold");
if(cvThreshold)
threshold = cvThreshold->asInt();
}
nlinfo("This service %s and has a threshold of %d",(tocking?"tocks":"doesn't tock"), threshold);
msgout.serial( tocking );
msgout.serial( threshold );
CUnifiedNetwork::getInstance()->send( id, msgout );
CTickProxy::setMasterTickService( id );
} // cbTicksUp //
示例2: getValue
CRGBA CConfiguration::getValue(const CConfigFile::CVar &var, const CRGBA &defaultValue)
{
if (var.size() >= 3)
{
if (var.size() > 4) nlwarning("RGBA value in config value '%s' is too long, ignoring unused values");
return CRGBA((uint8)var.asInt(0), (uint8)var.asInt(1), (uint8)var.asInt(2), var.size() >= 4 ? (uint8)var.asInt(3) : 255);
}
nlwarning("Invalid RGBA value in config value '%s', reverting to default { %i, %i, %i, %i }", var.Name.c_str(), (sint)defaultValue.R, (sint)defaultValue.G, (sint)defaultValue.B, (sint)defaultValue.A);
return defaultValue;
}
示例3: if
void cbSimVar (CConfigFile::CVar &var)
{
if (var.Name == "SimInLag") CUdpSimSock::_InLag = var.asInt ();
else if (var.Name == "SimInPacketLost") CUdpSimSock::_InPacketLoss = uint8(var.asInt ());
else if (var.Name == "SimOutLag") CUdpSimSock::_OutLag = var.asInt ();
else if (var.Name == "SimOutPacketLost") CUdpSimSock::_OutPacketLoss = uint8(var.asInt ());
else if (var.Name == "SimOutPacketDuplication") CUdpSimSock::_OutPacketDuplication = uint8(var.asInt ());
else if (var.Name == "SimOutPacketDisordering") CUdpSimSock::_OutPacketDisordering = uint8(var.asInt ());
else nlstop;
}
示例4: cbUpdateCompass
void cbUpdateCompass (CConfigFile::CVar &var)
{
if (var.Name == "CompassPosX") CompassPosX = var.asFloat ();
else if (var.Name == "CompassPosY") CompassPosY = var.asFloat ();
else if (var.Name == "CompassRadius") CompassRadius = var.asFloat ();
else if (var.Name == "CompassColor")
{
CompassColor.set(var.asInt(0), var.asInt(1), var.asInt(2), var.asInt(3));
CompassMaterial.setColor(CompassColor);
}
else nlwarning ("Unknown variable update %s", var.Name.c_str());
}
示例5:
// Bool version
bool getVarFromConfigFile(CConfigFile &cf, const string &name, bool &variable, bool defaultValue = false)
{
CConfigFile::CVar *ptr = cf.getVarPtr(name);
bool success;
variable = ((success = (ptr != NULL)) ? (ptr->asInt() != 0) : defaultValue);
return success;
}
示例6: if
void cbUpdateMouseListenerConfig(CConfigFile::CVar &var)
{
if (var.Name == "MouseInvert") MouseListener->setInvertMouseMode(var.asInt() != 0);
else if (var.Name == "MouseZoomStep") MouseZoomStep = var.asFloat ();
else if (var.Name == "ViewLagBehind") MouseListener->setViewLagBehind(var.asFloat ());
else if (var.Name == "ViewHeight") MouseListener->setViewHeight(var.asFloat ());
else if (var.Name == "ViewTargetHeight") MouseListener->setViewTargetHeight(var.asFloat ());
else nlwarning ("Unknown variable update %s", var.Name.c_str());
}
示例7: var12Callback
// this function will be called when the variable var12 will be modified by
// an external program
void var12Callback (CConfigFile::CVar &var)
{
stringstream str;
for (uint i = 0; i < var.size (); i++)
str << var.asInt (i) << " ";
nlinfo("%s modified, new value: %s\n", var.Name.c_str (), str.str().c_str());
}
示例8: cbRestoreShardOpen
/*
* Restore Shard Open state from config file or from file if found
*/
void cbRestoreShardOpen(CMessage &msgin, const std::string &serviceName, TServiceId sid)
{
// first restore state from config file
CConfigFile::CVar* var = IService::getInstance()->ConfigFile.getVarPtr("ShardOpen");
if (var != NULL)
{
setShardOpenState((TShardOpenState)var->asInt());
}
// then restore state from state file, if it exists
cbShardOpenStateFile(ShardOpenStateFile);
}
示例9: main
//****************************************************************************************************************************
int main(int argc, char* argv[])
{
if (argc < 2)
{
nlwarning("Usage : %s config_file_name.cfg", argv[0]);
return -1;
}
CConfigFile cf;
try
{
cf.load(argv[1]);
}
catch(const NLMISC::EConfigFile &)
{
nlwarning("Error in config file %s", argv[1]);
return -1;
}
catch(...)
{
nlwarning("Can't read config file %s", argv[1]);
return -1;
}
// output for sheets
std::string outputPath;
CConfigFile::CVar *outputPathVar = cf.getVarPtr("output_path");
if (outputPathVar)
{
outputPath = outputPathVar->asString() + "/";
}
// output for 'levels' parents
std::string levelParentsPath;
CConfigFile::CVar *levelParentsPathVar = cf.getVarPtr("level_parents");
if (levelParentsPathVar)
{
levelParentsPath = levelParentsPathVar->asString() + "/";
}
// output for projectile parents
std::string projectileParentsPath;
CConfigFile::CVar *projectileParentsPathVar = cf.getVarPtr("projectile_base");
if (projectileParentsPathVar)
{
projectileParentsPath= projectileParentsPathVar->asString() + "/";
}
// output for 'projectile by level and mode' parents
std::string projectileByLevelAndModeParentsPath;
CConfigFile::CVar *projectileByLevelAndModeParentsPathVar = cf.getVarPtr("projectile_by_level_and_mode_parents");
if (projectileByLevelAndModeParentsPathVar)
{
projectileByLevelAndModeParentsPath = projectileByLevelAndModeParentsPathVar->asString() + "/";
}
// output for 'base spells' parents
std::string baseSpellPath;
CConfigFile::CVar *baseSpellPathVar = cf.getVarPtr("spell_base");
if (baseSpellPathVar)
{
baseSpellPath = baseSpellPathVar->asString() + "/";
}
// output for 'spell by levels' parents
std::string spellByLevelParentsPath;
CConfigFile::CVar *spellByLevelParentsPathVar = cf.getVarPtr("spell_by_level_parents");
if (spellByLevelParentsPathVar)
{
spellByLevelParentsPath = spellByLevelParentsPathVar->asString() + "/";
}
// output for 'final spell'
std::string finalSpellPath;
CConfigFile::CVar *finalSpellPathVar = cf.getVarPtr("final_spells");
if (finalSpellPathVar)
{
finalSpellPath = finalSpellPathVar->asString() + "/";
}
// read number of levels
CConfigFile::CVar *numLevelVar = cf.getVarPtr("num_levels");
if (!numLevelVar)
{
nlwarning("Can't read number of spell levels");
return -1;
}
uint numSpellLevels = numLevelVar->asInt();
std::vector<CUserParams> userParams(numSpellLevels);
// read user params set for each level
for(uint level = 0; level < numSpellLevels; ++level)
{
std::string varName = toString("user_params_level%d", (int) (level + 1));
CConfigFile::CVar *up = cf.getVarPtr(varName);
if (!up)
{
nlwarning("Can't read var %s", varName.c_str());
}
else
{
for(uint k = 0; k < CUserParams::NumUserParams; ++k)
{
userParams[level].UserParam[k] = up->asString(k);
//.........这里部分代码省略.........
示例10: cbUpdateInventoryDisplay
void cbUpdateInventoryDisplay (CConfigFile::CVar &var)
{
if (var.Name == "InventoryState") InventoryState = var.asInt ();
}
示例11: cbUpdateGraph
void cbUpdateGraph (CConfigFile::CVar &var)
{
if (var.Name == "ShowGraph") ShowGraph = var.asInt() == 1;
else nlwarning ("Unknown variable update %s", var.Name.c_str());
}
示例12: init
/* Load the config file and the related words files. Return false in case of failure.
* Config file variables:
* - WordsPath: where to find <filter>_words_<languageCode>.txt
* - LanguageCode: language code (ex: en for English)
* - Utf8: results are in UTF8, otherwise in ANSI string
* - Filter: "*" for all files (default) or a name (ex: "item").
* - AdditionalFiles/AdditionalFileColumnTitles
*/
bool CWordsDictionary::init( const string& configFileName )
{
// Read config file
bool cfFound = false;
CConfigFile cf;
try
{
cf.load( configFileName );
cfFound = true;
}
catch ( EConfigFile& e )
{
nlwarning( "WD: %s", e.what() );
}
string wordsPath, languageCode, filter = "*";
vector<string> additionalFiles, additionalFileColumnTitles;
bool filterAll = true, utf8 = false;
if ( cfFound )
{
CConfigFile::CVar *v = cf.getVarPtr( "WordsPath" );
if ( v )
{
wordsPath = v->asString();
/*if ( (!wordsPath.empty()) && (wordsPath[wordsPath.size()-1]!='/') )
wordsPath += '/';*/
}
v = cf.getVarPtr( "LanguageCode" );
if ( v )
languageCode = v->asString();
v = cf.getVarPtr( "Utf8" );
if ( v )
utf8 = (v->asInt() == 1);
v = cf.getVarPtr( "Filter" );
if ( v )
{
filter = v->asString();
filterAll = (filter == "*");
}
v = cf.getVarPtr( "AdditionalFiles" );
if ( v )
{
for ( uint i=0; i!=v->size(); ++i )
additionalFiles.push_back( v->asString( i ) );
v = cf.getVarPtr( "AdditionalFileColumnTitles" );
if ( v->size() != additionalFiles.size() )
{
nlwarning( "AdditionalFiles and AdditionalFileColumnTitles have different size, ignoring second one" );
additionalFileColumnTitles.resize( v->size(), DefaultColTitle );
}
else
{
for ( uint i=0; i!=v->size(); ++i )
additionalFileColumnTitles.push_back( v->asString( i ) );
}
}
}
if ( languageCode.empty() )
languageCode = "en";
// Load all found words files
const string ext = ".txt";
vector<string> fileList;
CPath::getPathContent( wordsPath, false, false, true, fileList );
for ( vector<string>::const_iterator ifl=fileList.begin(); ifl!=fileList.end(); ++ifl )
{
const string& filename = (*ifl);
string::size_type p = string::npos;
bool isAdditionalFile = false;
// Test if filename is in additional file list
uint iAdditionalFile;
for ( iAdditionalFile=0; iAdditionalFile!=additionalFiles.size(); ++iAdditionalFile )
{
if ( (p = filename.find( additionalFiles[iAdditionalFile] )) != string::npos )
{
isAdditionalFile = true;
break;
}
}
// Or test if filename is a words_*.txt file
string pattern = string("_words_") + languageCode + ext;
if ( isAdditionalFile ||
((p = filename.find( pattern )) != string::npos) )
{
// Skip if a filter is specified and does not match the current file
if ( (!filterAll) && (filename.find( filter+pattern ) == string::npos) )
continue;
// Load file
nldebug( "WD: Loading %s", filename.c_str() );
//.........这里部分代码省略.........
示例13: cbUpdateRadar
void cbUpdateRadar (CConfigFile::CVar &var)
{
if (var.Name == "RadarPosX") RadarPosX = var.asFloat ();
else if (var.Name == "RadarPosY") RadarPosY = var.asFloat ();
else if (var.Name == "RadarWidth") RadarWidth = var.asFloat ();
else if (var.Name == "RadarHeight") RadarHeight = var.asFloat ();
else if (var.Name == "RadarBackColor") RadarBackColor.set (var.asInt(0), var.asInt(1), var.asInt(2), var.asInt(3));
else if (var.Name == "RadarFrontColor") RadarFrontColor.set (var.asInt(0), var.asInt(1), var.asInt(2), var.asInt(3));
else if (var.Name == "RadarSelfColor") RadarSelfColor.set (var.asInt(0), var.asInt(1), var.asInt(2), var.asInt(3));
else if (var.Name == "RadarOtherColor") RadarOtherColor.set (var.asInt(0), var.asInt(1), var.asInt(2), var.asInt(3));
else if (var.Name == "RadarDynamicColor") RadarDynamicColor.set (var.asInt(0), var.asInt(1), var.asInt(2), var.asInt(3));
else if (var.Name == "RadarPlaceColor") RadarPlaceColor.set (var.asInt(0), var.asInt(1), var.asInt(2), var.asInt(3));
else if (var.Name == "RadarEntitySize") RadarEntitySize = var.asFloat ();
else if (var.Name == "RadarState") RadarState = var.asInt ();
else if (var.Name == "RadarDistance") RadarDistance = var.asInt ();
else if (var.Name == "RadarMinDistance") RadarMinDistance = var.asInt ();
else if (var.Name == "RadarMaxDistance") RadarMaxDistance = var.asInt ();
else if (var.Name == "URLSelectionTimeout") SelectionTimeOut = var.asInt ();
else if (var.Name == "RadarParticularPlaces")
{
RadarParticularPlaces.clear ();
for (sint i = 0; i < var.size(); i += 4)
{
RadarParticularPlaces.push_back (RadarParticularPlace(var.asFloat(i), var.asFloat(i+1), var.asString(i+2), var.asString(i+3)));
}
}
else if (var.Name == "RadarFontSize") RadarFontSize = var.asInt ();
else if (var.Name == "RadarLittlePosX") RadarLittlePosX = var.asFloat ();
else if (var.Name == "RadarLittlePosY") RadarLittlePosY = var.asFloat ();
else if (var.Name == "RadarLittleRadius") RadarLittleRadius = var.asFloat ();
else nlwarning ("Unknown variable update %s", var.Name.c_str());
}
示例14: cbVar
void cbVar (CConfigFile::CVar &var)
{
if (var.Name == "NbId") NbId = var.asInt ();
else nlstop;
}
示例15: if
//.........这里部分代码省略.........
}
string addExtension = "." + sheetType;
uint dirmapLetterIndex = ~0;
bool dirmapLetterBackward = false;
vector<string> dirmapDirs;
string dirmapSheetCode;
bool WriteEmptyProperties = false, WriteSheetsToDisk = true;
bool ForceInsertParents = false;
if ( generate )
{
// Get the directory mapping
try
{
CConfigFile dirmapcfg;
dirmapcfg.load( sheetType + "_dirmap.cfg" );
if ( OutputPath.empty() )
{
CConfigFile::CVar *path = dirmapcfg.getVarPtr( "OutputPath" );
if ( path )
OutputPath = path->asString();
if ( ! OutputPath.empty() )
{
if ( OutputPath[OutputPath.size()-1] != '/' )
OutputPath += '/';
else if ( ! CFile::isDirectory( OutputPath ) )
nlwarning( "Output path does not exist" );
}
}
CConfigFile::CVar *letterIndex1 = dirmapcfg.getVarPtr( "LetterIndex" );
if ( letterIndex1 && letterIndex1->asInt() > 0 )
{
dirmapLetterIndex = letterIndex1->asInt() - 1;
CConfigFile::CVar *letterWay = dirmapcfg.getVarPtr( "LetterWay" );
dirmapLetterBackward = (letterWay && (letterWay->asInt() == 1));
CConfigFile::CVar dirs = dirmapcfg.getVar( "Directories" );
for ( uint idm=0; idm!=dirs.size(); ++idm )
{
dirmapDirs.push_back( dirs.asString( idm ) );
nlinfo( "Directory: %s", dirmapDirs.back().c_str() );
if ( ! CFile::isExists( OutputPath + dirmapDirs.back() ) )
{
CFile::createDirectory( OutputPath + dirmapDirs.back() );
}
else
{
if ( ! CFile::isDirectory( OutputPath + dirmapDirs.back() ) )
{
nlwarning( "Already existing but not a directory!" );
}
}
}
nlinfo( "Mapping letter #%u (%s) of sheet name to directory", dirmapLetterIndex + 1, dirmapLetterBackward?"backward":"forward" );
}
CConfigFile::CVar *sheetCode = dirmapcfg.getVarPtr( "AddSheetCode" );
if ( sheetCode )
dirmapSheetCode = sheetCode->asString();
nlinfo( "Sheet code: %s", dirmapSheetCode.c_str() );