本文整理汇总了C++中PersistentDataItem类的典型用法代码示例。如果您正苦于以下问题:C++ PersistentDataItem类的具体用法?C++ PersistentDataItem怎么用?C++ PersistentDataItem使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了PersistentDataItem类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: DeletePersistentData
bool World::DeletePersistentData(const PersistentDataItem &item)
{
int id = item.raw_id();
if (id > -100)
return false;
if (!BuildPersistentCache())
return false;
stl::vector<df::historical_figure*> &hfvec = df::historical_figure::get_vector();
auto eqrange = persistent_index.equal_range(item.key());
for (auto it2 = eqrange.first; it2 != eqrange.second; )
{
auto it = it2; ++it2;
if (it->second != -id)
continue;
persistent_index.erase(it);
int idx = binsearch_index(hfvec, id);
if (idx >= 0) {
delete hfvec[idx];
hfvec.erase(hfvec.begin()+idx);
}
return true;
}
return false;
}
示例2: init_state
static void init_state(color_ostream &out)
{
auto pworld = Core::getInstance().getWorld();
config = pworld->GetPersistentData("workflow/config");
if (config.isValid() && config.ival(0) == -1)
config.ival(0) = 0;
enabled = isOptionEnabled(CF_ENABLED);
// Parse constraints
std::vector<PersistentDataItem> items;
pworld->GetPersistentData(&items, "workflow/constraints");
for (int i = items.size()-1; i >= 0; i--) {
if (get_constraint(out, items[i].val(), &items[i]))
continue;
out.printerr("Lost constraint %s\n", items[i].val().c_str());
pworld->DeletePersistentData(items[i]);
}
last_tick_frame_count = world->frame_counter;
last_frame_count = world->frame_counter;
if (!enabled)
return;
start_protect(out);
}
示例3: read_persistent
static int read_persistent(lua_State *state, PersistentDataItem ref, bool create)
{
if (!ref.isValid())
{
lua_pushnil(state);
lua_pushstring(state, "entry not found");
return 2;
}
if (create)
lua_createtable(state, 0, 4);
lua_pushvalue(state, lua_upvalueindex(1));
lua_setmetatable(state, -2);
lua_pushinteger(state, ref.entry_id());
lua_setfield(state, -2, "entry_id");
lua_pushstring(state, ref.key().c_str());
lua_setfield(state, -2, "key");
lua_pushstring(state, ref.val().c_str());
lua_setfield(state, -2, "value");
lua_createtable(state, PersistentDataItem::NumInts, 0);
for (int i = 0; i < PersistentDataItem::NumInts; i++)
{
lua_pushinteger(state, ref.ival(i));
lua_rawseti(state, -2, i+1);
}
lua_setfield(state, -2, "ints");
return 1;
}
示例4: init_state
static void init_state()
{
config = World::GetPersistentData("autolabor/config");
if (config.isValid() && config.ival(0) == -1)
config.ival(0) = 0;
enable_autolabor = isOptionEnabled(CF_ENABLED);
if (!enable_autolabor)
return;
auto cfg_haulpct = World::GetPersistentData("autolabor/haulpct");
if (cfg_haulpct.isValid())
{
hauler_pct = cfg_haulpct.ival(0);
}
else
{
hauler_pct = 33;
}
// Load labors from save
labor_infos.resize(ARRAY_COUNT(default_labor_infos));
std::vector<PersistentDataItem> items;
World::GetPersistentData(&items, "autolabor/labors/", true);
for (auto p = items.begin(); p != items.end(); p++)
{
string key = p->key();
df::unit_labor labor = (df::unit_labor) atoi(key.substr(strlen("autolabor/labors/")).c_str());
if (labor >= 0 && labor <= labor_infos.size())
{
labor_infos[labor].config = *p;
labor_infos[labor].is_exclusive = default_labor_infos[labor].is_exclusive;
labor_infos[labor].active_dwarfs = 0;
}
}
// Add default labors for those not in save
for (int i = 0; i < ARRAY_COUNT(default_labor_infos); i++) {
if (labor_infos[i].config.isValid())
continue;
std::stringstream name;
name << "autolabor/labors/" << i;
labor_infos[i].config = World::AddPersistentData(name.str());
labor_infos[i].is_exclusive = default_labor_infos[i].is_exclusive;
labor_infos[i].active_dwarfs = 0;
reset_labor((df::unit_labor) i);
}
generate_labor_to_skill_map();
}
示例5: GetPersistentData
PersistentDataItem World::GetPersistentData(const std::string &key, bool *added)
{
if (added) *added = false;
PersistentDataItem rv = GetPersistentData(key);
if (!rv.isValid())
{
if (added) *added = true;
rv = AddPersistentData(key);
}
return rv;
}
示例6: deletePersistentTilemask
bool World::deletePersistentTilemask(const PersistentDataItem &item, df::map_block *block)
{
if (!block)
return false;
int id = item.raw_id();
if (id > -100)
return false;
bool found = false;
for (int i = block->block_events.size()-1; i >= 0; i--)
{
auto ev = block->block_events[i];
if (ev->getType() != block_square_event_type::world_construction)
continue;
auto wcsev = strict_virtual_cast<df::block_square_event_world_constructionst>(ev);
if (!wcsev || wcsev->construction_id != id)
continue;
delete wcsev;
vector_erase_at(block->block_events, i);
found = true;
}
return found;
}
示例7: init_state
static void init_state()
{
auto pworld = Core::getInstance().getWorld();
config = pworld->GetPersistentData("autolabor/config");
if (config.isValid() && config.ival(0) == -1)
config.ival(0) = 0;
enable_autolabor = isOptionEnabled(CF_ENABLED);
if (!enable_autolabor)
return;
// Load labors from save
labor_infos.resize(ARRAY_COUNT(default_labor_infos));
std::vector<PersistentDataItem> items;
pworld->GetPersistentData(&items, "autolabor/labors/", true);
for (auto p = items.begin(); p != items.end(); p++)
{
string key = p->key();
df::enums::unit_labor::unit_labor labor = (df::enums::unit_labor::unit_labor) atoi(key.substr(strlen("autolabor/labors/")).c_str());
if (labor >= 0 && labor <= labor_infos.size())
{
labor_infos[labor].config = *p;
labor_infos[labor].is_exclusive = default_labor_infos[labor].is_exclusive;
labor_infos[labor].active_dwarfs = 0;
}
}
// Add default labors for those not in save
for (int i = 0; i < ARRAY_COUNT(default_labor_infos); i++) {
if (labor_infos[i].config.isValid())
continue;
std::stringstream name;
name << "autolabor/labors/" << i;
labor_infos[i].config = pworld->AddPersistentData(name.str());
labor_infos[i].is_exclusive = default_labor_infos[i].is_exclusive;
labor_infos[i].active_dwarfs = 0;
reset_labor((df::enums::unit_labor::unit_labor) i);
}
}
示例8: persistent_by_struct
static PersistentDataItem persistent_by_struct(lua_State *state, int idx)
{
lua_getfield(state, idx, "entry_id");
int id = lua_tointeger(state, -1);
lua_pop(state, 1);
PersistentDataItem ref = Core::getInstance().getWorld()->GetPersistentData(id);
if (ref.isValid())
{
lua_getfield(state, idx, "key");
const char *str = lua_tostring(state, -1);
if (!str || str != ref.key())
luaL_argerror(state, idx, "inconsistent id and key");
lua_pop(state, 1);
}
return ref;
}
示例9: setOptionEnabled
static void setOptionEnabled(ConfigFlags flag, bool on)
{
if (!config.isValid())
return;
if (on)
config.ival(0) |= flag;
else
config.ival(0) &= ~flag;
}
示例10: enable_plugin
static void enable_plugin(Core *c)
{
if (!config.isValid())
{
config = c->getWorld()->AddPersistentData("workflow/config");
config.ival(0) = 0;
}
setOptionEnabled(CF_ENABLED, true);
enabled = true;
c->con << "Enabling the plugin." << endl;
start_protect(c);
}
示例11: enable_plugin
static void enable_plugin(color_ostream &out)
{
auto pworld = Core::getInstance().getWorld();
if (!config.isValid())
{
config = pworld->AddPersistentData("workflow/config");
config.ival(0) = 0;
}
setOptionEnabled(CF_ENABLED, true);
enabled = true;
out << "Enabling the plugin." << endl;
start_protect(out);
}
示例12: enable_plugin
static void enable_plugin(color_ostream &out)
{
auto pworld = Core::getInstance().getWorld();
if (!config.isValid())
{
config = pworld->AddPersistentData("autolabor/config");
config.ival(0) = 0;
}
setOptionEnabled(CF_ENABLED, true);
enable_autolabor = true;
out << "Enabling the plugin." << endl;
cleanup_state();
init_state();
}
示例13: enable_plugin
/**
* Call this method to enable the plugin.
*/
static void enable_plugin(color_ostream &out)
{
// If there is no config persistent item, make one
if (!config.isValid())
{
config = World::AddPersistentData("autohauler/config");
config.ival(0) = 0;
}
// I think this is already done in init_state(), but it can't hurt
setOptionEnabled(CF_ENABLED, true);
enable_autohauler = true;
// Output to console that the plugin is enabled
out << "Enabling the plugin." << endl;
// Disable autohauler and clear the labor list
cleanup_state();
// Initialize the plugin
init_state();
}
示例14: set_mode
void set_mode(labor_mode mode) { config.ival(0) = mode; }
示例15: mode
labor_mode mode() { return (labor_mode) config.ival(0); }