本文整理汇总了C++中InventoryLocation::deSerialize方法的典型用法代码示例。如果您正苦于以下问题:C++ InventoryLocation::deSerialize方法的具体用法?C++ InventoryLocation::deSerialize怎么用?C++ InventoryLocation::deSerialize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类InventoryLocation
的用法示例。
在下文中一共展示了InventoryLocation::deSerialize方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: getLastNodeActor
std::string getLastNodeActor(v3s16 p, int range, int seconds,
v3s16 *act_p, int *act_seconds)
{
infostream<<"RollbackManager::getLastNodeActor("<<PP(p)
<<", "<<seconds<<")"<<std::endl;
// Figure out time
int cur_time = time(0);
int first_time = cur_time - seconds;
std::list<RollbackAction> action_buffer = getEntriesSince(first_time);
std::list<RollbackAction> result;
for(std::list<RollbackAction>::const_reverse_iterator
i = action_buffer.rbegin();
i != action_buffer.rend(); i++)
{
if(i->unix_time < first_time)
break;
// Find position of action or continue
v3s16 action_p;
if(i->type == RollbackAction::TYPE_SET_NODE)
{
action_p = i->p;
}
else if(i->type == RollbackAction::TYPE_MODIFY_INVENTORY_STACK)
{
InventoryLocation loc;
loc.deSerialize(i->inventory_location);
if(loc.type != InventoryLocation::NODEMETA)
continue;
action_p = loc.p;
}
else
continue;
if(range == 0){
if(action_p != p)
continue;
} else {
if(abs(action_p.X - p.X) > range ||
abs(action_p.Y - p.Y) > range ||
abs(action_p.Z - p.Z) > range)
continue;
}
if(act_p)
*act_p = action_p;
if(act_seconds)
*act_seconds = cur_time - i->unix_time;
return i->actor;
}
return "";
}
示例2: getPosition
bool RollbackAction::getPosition(v3s16 *dst) const
{
switch(type){
case RollbackAction::TYPE_SET_NODE:
if(dst) *dst = p;
return true;
case RollbackAction::TYPE_MODIFY_INVENTORY_STACK: {
InventoryLocation loc;
loc.deSerialize(inventory_location);
if(loc.type != InventoryLocation::NODEMETA)
return false;
if(dst) *dst = loc.p;
return true; }
default:
return false;
}
}
示例3: applyRevert
bool RollbackAction::applyRevert(Map *map, InventoryManager *imgr, IGameDef *gamedef) const
{
try {
switch (type) {
case TYPE_NOTHING:
return true;
case TYPE_SET_NODE: {
INodeDefManager *ndef = gamedef->ndef();
// Make sure position is loaded from disk
map->emergeBlock(getContainerPos(p, MAP_BLOCKSIZE), false);
// Check current node
MapNode current_node = map->getNodeNoEx(p);
std::string current_name = ndef->get(current_node).name;
// If current node not the new node, it's bad
if (current_name != n_new.name) {
return false;
}
// Create rollback node
MapNode n(ndef, n_old.name, n_old.param1, n_old.param2);
// Set rollback node
try {
if (!map->addNodeWithEvent(p, n)) {
infostream << "RollbackAction::applyRevert(): "
<< "AddNodeWithEvent failed at "
<< PP(p) << " for " << n_old.name
<< std::endl;
return false;
}
if (n_old.meta.empty()) {
map->removeNodeMetadata(p);
} else {
NodeMetadata *meta = map->getNodeMetadata(p);
if (!meta) {
meta = new NodeMetadata(gamedef);
if (!map->setNodeMetadata(p, meta)) {
delete meta;
infostream << "RollbackAction::applyRevert(): "
<< "setNodeMetadata failed at "
<< PP(p) << " for " << n_old.name
<< std::endl;
return false;
}
}
std::istringstream is(n_old.meta, std::ios::binary);
meta->deSerialize(is);
}
// Inform other things that the meta data has changed
v3s16 blockpos = getContainerPos(p, MAP_BLOCKSIZE);
MapEditEvent event;
event.type = MEET_BLOCK_NODE_METADATA_CHANGED;
event.p = blockpos;
map->dispatchEvent(&event);
// Set the block to be saved
MapBlock *block = map->getBlockNoCreateNoEx(blockpos);
if (block) {
block->raiseModified(MOD_STATE_WRITE_NEEDED,
MOD_REASON_REPORT_META_CHANGE);
}
} catch (InvalidPositionException &e) {
infostream << "RollbackAction::applyRevert(): "
<< "InvalidPositionException: " << e.what()
<< std::endl;
return false;
}
// Success
return true; }
case TYPE_MODIFY_INVENTORY_STACK: {
InventoryLocation loc;
loc.deSerialize(inventory_location);
std::string real_name = gamedef->idef()->getAlias(inventory_stack.name);
Inventory *inv = imgr->getInventory(loc);
if (!inv) {
infostream << "RollbackAction::applyRevert(): Could not get "
"inventory at " << inventory_location << std::endl;
return false;
}
InventoryList *list = inv->getList(inventory_list);
if (!list) {
infostream << "RollbackAction::applyRevert(): Could not get "
"inventory list \"" << inventory_list << "\" in "
<< inventory_location << std::endl;
return false;
}
if (list->getSize() <= inventory_index) {
infostream << "RollbackAction::applyRevert(): List index "
<< inventory_index << " too large in "
<< "inventory list \"" << inventory_list << "\" in "
<< inventory_location << std::endl;
}
// If item was added, take away item, otherwise add removed item
if (inventory_add) {
// Silently ignore different current item
if (list->getItem(inventory_index).name != real_name)
return false;
list->takeItem(inventory_index, inventory_stack.count);
} else {
list->addItem(inventory_index, inventory_stack);
}
// Inventory was modified; send to clients
imgr->setInventoryModified(loc);
//.........这里部分代码省略.........
示例4: regenerateGui
void GUIFormSpecMenu::regenerateGui(v2u32 screensize)
{
// Remove children
removeChildren();
v2s32 size(100,100);
s32 helptext_h = 15;
core::rect<s32> rect;
// Base position of contents of form
v2s32 basepos = getBasePos();
// State of basepos, 0 = not set, 1= set by formspec, 2 = set by size[] element
// Used to adjust form size automatically if needed
// A proceed button is added if there is no size[] element
int bp_set = 0;
/* Convert m_init_draw_spec to m_inventorylists */
m_inventorylists.clear();
m_images.clear();
m_fields.clear();
Strfnd f(m_formspec_string);
while(f.atend() == false)
{
std::string type = trim(f.next("["));
if(type == "invsize" || type == "size")
{
v2f invsize;
invsize.X = stof(f.next(","));
if(type == "size")
{
invsize.Y = stof(f.next("]"));
}
else{
invsize.Y = stof(f.next(";"));
f.next("]");
}
infostream<<"Form size ("<<invsize.X<<","<<invsize.Y<<")"<<std::endl;
padding = v2s32(screensize.Y/40, screensize.Y/40);
spacing = v2s32(screensize.Y/12, screensize.Y/13);
imgsize = v2s32(screensize.Y/15, screensize.Y/15);
size = v2s32(
padding.X*2+spacing.X*(invsize.X-1.0)+imgsize.X,
padding.Y*2+spacing.Y*(invsize.Y-1.0)+imgsize.Y + (helptext_h-5)
);
rect = core::rect<s32>(
screensize.X/2 - size.X/2,
screensize.Y/2 - size.Y/2,
screensize.X/2 + size.X/2,
screensize.Y/2 + size.Y/2
);
DesiredRect = rect;
recalculateAbsolutePosition(false);
basepos = getBasePos();
bp_set = 2;
}
else if(type == "list")
{
std::string name = f.next(";");
InventoryLocation loc;
if(name == "context" || name == "current_name")
loc = m_current_inventory_location;
else
loc.deSerialize(name);
std::string listname = f.next(";");
v2s32 pos = basepos;
pos.X += stof(f.next(",")) * (float)spacing.X;
pos.Y += stof(f.next(";")) * (float)spacing.Y;
v2s32 geom;
geom.X = stoi(f.next(","));
geom.Y = stoi(f.next(";"));
infostream<<"list inv="<<name<<", listname="<<listname
<<", pos=("<<pos.X<<","<<pos.Y<<")"
<<", geom=("<<geom.X<<","<<geom.Y<<")"
<<std::endl;
std::string start_i_s = f.next("]");
s32 start_i = 0;
if(start_i_s != "")
start_i = stoi(start_i_s);
if(bp_set != 2)
errorstream<<"WARNING: invalid use of list without a size[] element"<<std::endl;
m_inventorylists.push_back(ListDrawSpec(loc, listname, pos, geom, start_i));
}
else if(type == "image")
{
v2s32 pos = basepos;
pos.X += stof(f.next(",")) * (float)spacing.X;
pos.Y += stof(f.next(";")) * (float)spacing.Y;
v2s32 geom;
geom.X = stof(f.next(",")) * (float)imgsize.X;
geom.Y = stof(f.next(";")) * (float)imgsize.Y;
std::string name = f.next("]");
infostream<<"image name="<<name
<<", pos=("<<pos.X<<","<<pos.Y<<")"
<<", geom=("<<geom.X<<","<<geom.Y<<")"
<<std::endl;
if(bp_set != 2)
errorstream<<"WARNING: invalid use of button without a size[] element"<<std::endl;
//.........这里部分代码省略.........