本文整理汇总了C++中LuaTable::SubTable方法的典型用法代码示例。如果您正苦于以下问题:C++ LuaTable::SubTable方法的具体用法?C++ LuaTable::SubTable怎么用?C++ LuaTable::SubTable使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类LuaTable
的用法示例。
在下文中一共展示了LuaTable::SubTable方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ReadTerrainTypes
void CMapInfo::ReadTerrainTypes()
{
const LuaTable terrTypeTable =
mapRoot->SubTable("terrainTypes");
for (int tt = 0; tt < 256; tt++) {
TerrainType& terrType = terrainTypes[tt];
const LuaTable terrain = terrTypeTable.SubTable(tt);
terrType.name = terrain.GetString("name", "Default");
terrType.hardness = terrain.GetFloat("hardness", 1.0f);
terrType.receiveTracks = terrain.GetBool("receiveTracks", true);
const LuaTable moveTable = terrain.SubTable("moveSpeeds");
terrType.tankSpeed = moveTable.GetFloat("tank", 1.0f);
terrType.kbotSpeed = moveTable.GetFloat("kbot", 1.0f);
terrType.hoverSpeed = moveTable.GetFloat("hover", 1.0f);
terrType.shipSpeed = moveTable.GetFloat("ship", 1.0f);
// clamps
terrType.hardness = max(0.0f, terrType.hardness);
terrType.tankSpeed = max(0.0f, terrType.tankSpeed);
terrType.kbotSpeed = max(0.0f, terrType.kbotSpeed);
terrType.hoverSpeed = max(0.0f, terrType.hoverSpeed);
terrType.shipSpeed = max(0.0f, terrType.shipSpeed);
}
}
示例2: ReadCacheData
void CArchiveScanner::ReadCacheData(const std::string& filename)
{
if (!FileSystem::FileExists(filename)) {
LOG_L(L_INFO, "Archive cache doesn't exist: %s", filename.c_str());
return;
}
LuaParser p(filename, SPRING_VFS_RAW, SPRING_VFS_BASE);
if (!p.Execute()) {
LOG_L(L_ERROR, "Failed to parse archive cache: %s", p.GetErrorLog().c_str());
return;
}
const LuaTable archiveCache = p.GetRoot();
// Do not load old version caches
const int ver = archiveCache.GetInt("internalVer", (INTERNAL_VER + 1));
if (ver != INTERNAL_VER) {
return;
}
const LuaTable archives = archiveCache.SubTable("archives");
for (int i = 1; archives.KeyExists(i); ++i) {
const LuaTable curArchive = archives.SubTable(i);
const LuaTable archived = curArchive.SubTable("archivedata");
std::string name = curArchive.GetString("name", "");
ArchiveInfo& ai = archiveInfos[StringToLower(name)];
ai.origName = name;
ai.path = curArchive.GetString("path", "");
// do not use LuaTable.GetInt() for 32-bit integers, the Spring lua
// library uses 32-bit floats to represent numbers, which can only
// represent 2^24 consecutive integers
ai.modified = strtoul(curArchive.GetString("modified", "0").c_str(), 0, 10);
ai.checksum = strtoul(curArchive.GetString("checksum", "0").c_str(), 0, 10);
ai.updated = false;
ai.archiveData = CArchiveScanner::ArchiveData(archived, true);
if (ai.archiveData.GetModType() == modtype::map) {
AddDependency(ai.archiveData.GetDependencies(), "Map Helper v1");
} else if (ai.archiveData.GetModType() == modtype::primary) {
AddDependency(ai.archiveData.GetDependencies(), "Spring content v1");
}
}
const LuaTable brokenArchives = archiveCache.SubTable("brokenArchives");
for (int i = 1; brokenArchives.KeyExists(i); ++i) {
const LuaTable curArchive = brokenArchives.SubTable(i);
std::string name = curArchive.GetString("name", "");
StringToLowerInPlace(name);
BrokenArchive& ba = this->brokenArchives[name];
ba.path = curArchive.GetString("path", "");
ba.modified = strtoul(curArchive.GetString("modified", "0").c_str(), 0, 10);
ba.updated = false;
ba.problem = curArchive.GetString("problem", "unknown");
}
isDirty = false;
}
示例3: LoadSounds
void CUnitDefHandler::LoadSounds(const LuaTable& soundsTable, GuiSoundSet& gsound, const string& soundName)
{
string fileName = soundsTable.GetString(soundName, "");
if (!fileName.empty()) {
LoadSound(gsound, fileName, 1.0f);
return;
}
LuaTable sndTable = soundsTable.SubTable(soundName);
for (int i = 1; true; i++) {
LuaTable sndFileTable = sndTable.SubTable(i);
if (sndFileTable.IsValid()) {
fileName = sndFileTable.GetString("file", "");
if (!fileName.empty()) {
const float volume = sndFileTable.GetFloat("volume", 1.0f);
if (volume > 0.0f) {
LoadSound(gsound, fileName, volume);
}
}
} else {
fileName = sndTable.GetString(i, "");
if (fileName.empty()) {
break;
}
LoadSound(gsound, fileName, 1.0f);
}
}
}
示例4: LoadSoundDefs
bool CSound::LoadSoundDefs(const std::string& filename)
{
//! can be called from LuaUnsyncedCtrl too
boost::mutex::scoped_lock lck(soundMutex);
LuaParser parser(filename, SPRING_VFS_MOD, SPRING_VFS_ZIP);
parser.SetLowerKeys(false);
parser.SetLowerCppKeys(false);
parser.Execute();
if (!parser.IsValid())
{
LogObject(LOG_SOUND) << "Could not load " << filename << ": " << parser.GetErrorLog();
return false;
}
else
{
const LuaTable soundRoot = parser.GetRoot();
const LuaTable soundItemTable = soundRoot.SubTable("SoundItems");
if (!soundItemTable.IsValid())
{
LogObject(LOG_SOUND) << "CSound(): could not parse SoundItems table in " << filename;
return false;
}
else
{
std::vector<std::string> keys;
soundItemTable.GetKeys(keys);
for (std::vector<std::string>::const_iterator it = keys.begin(); it != keys.end(); ++it)
{
const std::string name(*it);
soundItemDef bufmap;
const LuaTable buf(soundItemTable.SubTable(*it));
buf.GetMap(bufmap);
bufmap["name"] = name;
soundItemDefMap::const_iterator sit = soundItemDefs.find(name);
if (sit != soundItemDefs.end())
LogObject(LOG_SOUND) << "CSound(): two SoundItems have the same name: " << name;
soundItemDef::const_iterator inspec = bufmap.find("file");
if (inspec == bufmap.end()) // no file, drop
LogObject(LOG_SOUND) << "CSound(): SoundItem has no file tag: " << name;
else
soundItemDefs[name] = bufmap;
if (buf.KeyExists("preload"))
{
LogObject(LOG_SOUND) << "CSound(): preloading " << name;
const size_t newid = sounds.size();
sounds.push_back(new SoundItem(GetWaveBuffer(bufmap["file"], true), bufmap));
soundMap[name] = newid;
}
}
LogObject(LOG_SOUND) << "CSound(): Sucessfully parsed " << keys.size() << " SoundItems from " << filename;
}
}
return true;
}
示例5: LoadSoundDefs
bool CSound::LoadSoundDefs(const std::string& fileName)
{
//! can be called from LuaUnsyncedCtrl too
boost::recursive_mutex::scoped_lock lck(soundMutex);
LuaParser parser(fileName, SPRING_VFS_MOD, SPRING_VFS_ZIP);
parser.SetLowerKeys(false);
parser.SetLowerCppKeys(false);
parser.Execute();
if (!parser.IsValid())
{
LOG_L(L_WARNING, "Could not load %s: %s",
fileName.c_str(), parser.GetErrorLog().c_str());
return false;
}
else
{
const LuaTable soundRoot = parser.GetRoot();
const LuaTable soundItemTable = soundRoot.SubTable("SoundItems");
if (!soundItemTable.IsValid())
{
LOG_L(L_WARNING, "CSound(): could not parse SoundItems table in %s", fileName.c_str());
return false;
}
else
{
std::vector<std::string> keys;
soundItemTable.GetKeys(keys);
for (std::vector<std::string>::const_iterator it = keys.begin(); it != keys.end(); ++it)
{
const std::string name(*it);
soundItemDef bufmap;
const LuaTable buf(soundItemTable.SubTable(*it));
buf.GetMap(bufmap);
bufmap["name"] = name;
soundItemDefMap::const_iterator sit = soundItemDefs.find(name);
if (sit != soundItemDefs.end())
LOG_L(L_WARNING, "Sound %s gets overwritten by %s", name.c_str(), fileName.c_str());
soundItemDef::const_iterator inspec = bufmap.find("file");
if (inspec == bufmap.end()) { // no file, drop
LOG_L(L_WARNING, "Sound %s is missing file tag (ignoring)", name.c_str());
} else {
soundItemDefs[name] = bufmap;
}
if (buf.KeyExists("preload")) {
MakeItemFromDef(bufmap);
}
}
LOG(" parsed %i sounds from %s", (int)keys.size(), fileName.c_str());
}
}
return true;
}
示例6: ReadStartPos
void CMapInfo::ReadStartPos()
{
const float defX = 1000.0f;
const float defZ = 1000.0f;
const float defXStep = 100.0f;
const float defZStep = 100.0f;
const LuaTable teamsTable = mapRoot->SubTable("teams");
for (int t = 0; t < MAX_TEAMS; ++t) {
float3 pos;
pos.x = defX + (defXStep * t);
pos.z = defZ + (defZStep * t);
pos.y = 0.0f;
const LuaTable posTable = teamsTable.SubTable(t).SubTable("startPos");
if (posTable.KeyExists("x") &&
posTable.KeyExists("z")) {
pos.x = posTable.GetFloat("x", pos.x);
pos.z = posTable.GetFloat("z", pos.z);
havePos.push_back(true);
} else {
havePos.push_back(false);
}
startPos.push_back(pos);
}
}
示例7: content_error
CDamageArrayHandler::CDamageArrayHandler(LuaParser* defsParser)
{
#define DEFAULT_ARMORDEF_NAME "default"
try {
const LuaTable rootTable = defsParser->GetRoot().SubTable("ArmorDefs");
if (!rootTable.IsValid())
throw content_error("Error loading ArmorDefs");
// GetKeys() sorts the keys, so can not simply push_back before call
rootTable.GetKeys(armorDefKeys);
armorDefKeys.insert(armorDefKeys.begin(), DEFAULT_ARMORDEF_NAME);
armorDefNameIdxMap[DEFAULT_ARMORDEF_NAME] = 0;
LOG("[%s] number of ArmorDefs: " _STPF_, __FUNCTION__, armorDefKeys.size());
// expects the following structure, subtables must be in array-format:
//
// {"tanks" = {[1] = "supertank", [2] = "megatank"}, "infantry" = {[1] = "dude"}, ...}
//
// the old (pre-95.0) <key, value> subtable definitions are no longer supported!
//
for (unsigned int armorDefIdx = 1; armorDefIdx < armorDefKeys.size(); armorDefIdx++) {
const std::string armorDefName = StringToLower(armorDefKeys[armorDefIdx]);
if (armorDefName == DEFAULT_ARMORDEF_NAME) {
// ignore, no need to clear entire table
LOG_L(L_WARNING, "[%s] ArmorDefs: tried to define the \"%s\" armor type!", __FUNCTION__, DEFAULT_ARMORDEF_NAME);
continue;
}
armorDefNameIdxMap[armorDefName] = armorDefIdx;
const LuaTable armorDefTable = rootTable.SubTable(armorDefKeys[armorDefIdx]);
const unsigned int numArmorDefEntries = armorDefTable.GetLength();
for (unsigned int armorDefEntryIdx = 0; armorDefEntryIdx < numArmorDefEntries; armorDefEntryIdx++) {
const std::string& unitDefName = StringToLower(armorDefTable.GetString(armorDefEntryIdx + 1, ""));
const auto armorDefTableIt = armorDefNameIdxMap.find(unitDefName);
if (armorDefTableIt == armorDefNameIdxMap.end()) {
armorDefNameIdxMap[unitDefName] = armorDefIdx;
continue;
}
LOG_L(L_WARNING,
"[%s] UnitDef \"%s\" in ArmorDef \"%s\" already belongs to ArmorDef category %d!",
__FUNCTION__, unitDefName.c_str(), armorDefName.c_str(), armorDefTableIt->second);
}
}
} catch (const content_error&) {
armorDefNameIdxMap.clear();
armorDefNameIdxMap[DEFAULT_ARMORDEF_NAME] = 0;
armorDefKeys.clear();
armorDefKeys.push_back(DEFAULT_ARMORDEF_NAME);
}
}
示例8: content_error
CFeatureHandler::CFeatureHandler() : nextFreeID(0)
{
PrintLoadMsg("Loading feature definitions");
drawQuadsX = gs->mapx/DRAW_QUAD_SIZE;
drawQuadsY = gs->mapy/DRAW_QUAD_SIZE;
drawQuads.resize(drawQuadsX * drawQuadsY);
treeDrawer = CBaseTreeDrawer::GetTreeDrawer();
const LuaTable rootTable = game->defsParser->GetRoot().SubTable("FeatureDefs");
if (!rootTable.IsValid()) {
throw content_error("Error loading FeatureDefs");
}
//! featureDefIDs start with 1
featureDefsVector.push_back(NULL);
//! get most of the feature defs (missing trees and geovent from the map)
vector<string> keys;
rootTable.GetKeys(keys);
for (int i = 0; i < (int)keys.size(); i++) {
const string& name = keys[i];
const LuaTable fdTable = rootTable.SubTable(name);
CreateFeatureDef(fdTable, name);
}
}
示例9: content_error
CWeaponDefHandler::CWeaponDefHandler()
{
PrintLoadMsg("Loading weapon definitions");
const LuaTable rootTable = game->defsParser->GetRoot().SubTable("WeaponDefs");
if (!rootTable.IsValid()) {
throw content_error("Error loading WeaponDefs");
}
vector<string> weaponNames;
rootTable.GetKeys(weaponNames);
numWeaponDefs = weaponNames.size(); // FIXME: starting at 0, don't need the +1 ?
weaponDefs = SAFE_NEW WeaponDef[numWeaponDefs + 1];
for (int wid = 0; wid < (int)weaponNames.size(); wid++) {
WeaponDef& wd = weaponDefs[wid];
wd.id = wid;
wd.name = weaponNames[wid];
weaponID[wd.name] = wid;
const LuaTable wdTable = rootTable.SubTable(wd.name);
ParseTAWeapon(wdTable, wd);
}
}
示例10: content_error
CWeaponDefHandler::CWeaponDefHandler()
{
PrintLoadMsg("Loading weapon definitions");
const LuaTable rootTable = game->defsParser->GetRoot().SubTable("WeaponDefs");
if (!rootTable.IsValid()) {
throw content_error("Error loading WeaponDefs");
}
vector<string> weaponNames;
rootTable.GetKeys(weaponNames);
numWeaponDefs = weaponNames.size();
weaponDefs = new WeaponDef[numWeaponDefs];
for (int wid = 0; wid < numWeaponDefs; wid++) {
WeaponDef& wd = weaponDefs[wid];
wd.id = wid;
wd.name = weaponNames[wid];
weaponID[wd.name] = wid;
const LuaTable wdTable = rootTable.SubTable(wd.name);
ParseWeapon(wdTable, wd);
}
}
示例11: content_error
CUnitDefHandler::CUnitDefHandler(void) : noCost(false)
{
const LuaTable rootTable = game->defsParser->GetRoot().SubTable("UnitDefs");
if (!rootTable.IsValid()) {
throw content_error("Error loading UnitDefs");
}
vector<string> unitDefNames;
rootTable.GetKeys(unitDefNames);
unitDefs.reserve(unitDefNames.size() + 1);
UnitDef* nullDef = new UnitDef();
unitDefs.push_back(nullDef);
for (unsigned int a = 0; a < unitDefNames.size(); ++a) {
const string unitName = unitDefNames[a];
LuaTable udTable = rootTable.SubTable(unitName);
// parse the unitdef data (but don't load buildpics, etc...)
PushNewUnitDef(unitName, udTable);
}
CleanBuildOptions();
FindStartUnits();
ProcessDecoys();
AssignTechLevels();
}
示例12: ReadCacheData
void CArchiveScanner::ReadCacheData(const string& filename)
{
LuaParser p(filename, SPRING_VFS_RAW, SPRING_VFS_BASE);
if (!p.Execute()) {
logOutput.Print("ERROR in " + filename + ": " + p.GetErrorLog());
}
const LuaTable archiveCache = p.GetRoot();
const LuaTable archives = archiveCache.SubTable("archives");
// Do not load old version caches
const int ver = archiveCache.GetInt("internalVer", (INTERNAL_VER + 1));
if (ver != INTERNAL_VER) {
return;
}
for (int i = 1; archives.KeyExists(i); ++i) {
const LuaTable curArchive = archives.SubTable(i);
const LuaTable archived = curArchive.SubTable("archivedata");
ArchiveInfo ai;
ai.origName = curArchive.GetString("name", "");
ai.path = curArchive.GetString("path", "");
// do not use LuaTable.GetInt() for 32-bit integers, the Spring lua
// library uses 32-bit floats to represent numbers, which can only
// represent 2^24 consecutive integers
ai.modified = strtoul(curArchive.GetString("modified", "0").c_str(), 0, 10);
ai.checksum = strtoul(curArchive.GetString("checksum", "0").c_str(), 0, 10);
ai.updated = false;
ai.archiveData = GetArchiveData(archived);
if (ai.archiveData.modType == modtype::map)
AddDependency(ai.archiveData.dependencies, "maphelper.sdz");
else if (ai.archiveData.modType == modtype::primary)
AddDependency(ai.archiveData.dependencies, "Spring content v1");
string lcname = StringToLower(ai.origName);
archiveInfo[lcname] = ai;
}
isDirty = false;
}
示例13: GetArchiveData
CArchiveScanner::ArchiveData CArchiveScanner::GetArchiveData(const LuaTable& archiveTable)
{
ArchiveData md;
if (!archiveTable.IsValid()) {
return md;
}
md.name = archiveTable.GetString("name", "");
md.shortName = archiveTable.GetString("shortName", "");
md.version = archiveTable.GetString("version", "");
md.mutator = archiveTable.GetString("mutator", "");
md.game = archiveTable.GetString("game", "");
md.shortGame = archiveTable.GetString("shortGame", "");
md.description = archiveTable.GetString("description", "");
md.modType = archiveTable.GetInt("modType", 0);
md.mapfile = archiveTable.GetString("mapfile", "");
const LuaTable dependencies = archiveTable.SubTable("depend");
for (int dep = 1; dependencies.KeyExists(dep); ++dep) {
const std::string depend = dependencies.GetString(dep, "");
md.dependencies.push_back(depend);
}
const LuaTable replaces = archiveTable.SubTable("replace");
for (int rep = 1; replaces.KeyExists(rep); ++rep) {
md.replaces.push_back(replaces.GetString(rep, ""));
}
// HACK needed until lobbies, lobbyserver and unitsync are sorted out
// so they can uniquely identify different versions of the same mod.
// (at time of this writing they use name only)
// NOTE when changing this, this function is used both by the code that
// reads ArchiveCache.lua and the code that reads modinfo.lua from the mod.
// so make sure it doesn't keep adding stuff to the name everytime
// Spring/unitsync is loaded.
if (md.name.find(md.version) == std::string::npos && !md.version.empty()) {
md.name += " " + md.version;
}
return md;
}
示例14: LoadUnits
void CSyncer::LoadUnits(bool checksum)
{
unitsLeft = 0;
LuaParser luaParser("gamedata/defs.lua",
SPRING_VFS_MOD_BASE, SPRING_VFS_ZIP);
if (!luaParser.Execute()) {
logOutput.Print("luaParser.Execute() failed");
return;
}
LuaTable rootTable = luaParser.GetRoot().SubTable("UnitDefs");
if (!rootTable.IsValid()) {
logOutput.Print("root unitdef table invalid");
return;
}
vector<string> unitDefNames;
rootTable.GetKeys(unitDefNames);
const int count = (int)unitDefNames.size();
for (int i = 0; i < count; ++i) {
const string& udName = unitDefNames[i];
LuaTable udTable = rootTable.SubTable(udName);
Unit u;
u.fullName = udTable.GetString("name", udName);
if (checksum) {
const string fileName = udTable.GetString("filename", "");
const string deadName = udTable.GetString("corpse", udName + "_dead");
const string modelName = udTable.GetString("objectname", udName);
u.fbi = CalculateCRC(fileName);
u.cob = CalculateCRC("scripts/" + udName + ".cob");
u.model = CalculateCRC("objects3d/" + modelName); // s3o ?
u.model += CalculateCRC("objects3d/" + modelName + ".3do");
u.model += CalculateCRC("objects3d/" + deadName + ".3do");
}
units[udName] = u;
}
// map the unitIds
map<string, Unit>::iterator mit;
for (mit = units.begin(); mit != units.end(); ++mit) {
unitIds.push_back(mit->first);
}
unitsLeft = count;
return;
}
示例15: Load
bool SideParser::Load()
{
dataVec.clear();
errorLog.clear();
LuaParser parser("gamedata/sidedata.lua",
SPRING_VFS_MOD_BASE, SPRING_VFS_MOD_BASE);
#if !defined UNITSYNC && !defined DEDICATED
// this should not be included with unitsync:
// 1. avoids linkage with LuaSyncedRead
// 2. ModOptions are not valid during unitsync mod parsing
parser.GetTable("Spring");
parser.AddFunc("GetModOptions", LuaSyncedRead::GetModOptions);
parser.EndTable();
#endif
if (!parser.Execute()) {
errorLog = parser.GetErrorLog();
return false;
}
set<string> sideSet;
const LuaTable root = parser.GetRoot();
for (int i = 1; /* no-op */; i++) {
const LuaTable sideTable = root.SubTable(i);
if (!sideTable.IsValid()) {
break;
}
Data data;
data.caseName = sideTable.GetString("name", "");
data.sideName = StringToLower(data.caseName);
data.startUnit = sideTable.GetString("startUnit", "");
data.startUnit = StringToLower(data.startUnit);
if (data.sideName.empty()) {
logOutput.Print("Missing side name: %i", i);
}
else if (data.startUnit.empty()) {
logOutput.Print("Missing side start unit: " + data.sideName);
}
else {
if (sideSet.find(data.sideName) != sideSet.end()) {
logOutput.Print("Duplicate side name: " + data.sideName);
}
else {
sideSet.insert(data.sideName);
dataVec.push_back(data);
}
}
}
return true;
}