mirror of
https://github.com/luanti-org/luanti.git
synced 2025-06-27 16:36:03 +00:00
Experimental-ish rollback functionality
This commit is contained in:
parent
0c91a0d59d
commit
0190f9b077
20 changed files with 1316 additions and 27 deletions
|
@ -25,6 +25,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||
#include "main.h" // for g_settings
|
||||
#include "settings.h"
|
||||
#include "craftdef.h"
|
||||
#include "rollback_interface.h"
|
||||
|
||||
#define PP(x) "("<<(x).X<<","<<(x).Y<<","<<(x).Z<<")"
|
||||
|
||||
|
@ -199,6 +200,14 @@ void IMoveAction::apply(InventoryManager *mgr, ServerActiveObject *player, IGame
|
|||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
Do not handle rollback if both inventories are that of the same player
|
||||
*/
|
||||
bool ignore_rollback = (
|
||||
from_inv.type == InventoryLocation::PLAYER &&
|
||||
to_inv.type == InventoryLocation::PLAYER &&
|
||||
from_inv.name == to_inv.name);
|
||||
|
||||
/*
|
||||
Collect information of endpoints
|
||||
*/
|
||||
|
@ -343,6 +352,41 @@ void IMoveAction::apply(InventoryManager *mgr, ServerActiveObject *player, IGame
|
|||
<<" i="<<to_i
|
||||
<<std::endl;
|
||||
|
||||
/*
|
||||
Record rollback information
|
||||
*/
|
||||
if(!ignore_rollback)
|
||||
{
|
||||
IRollbackReportSink *rollback = gamedef->rollback();
|
||||
|
||||
// If source is not infinite, record item take
|
||||
if(!src_can_take_count != -1){
|
||||
RollbackAction action;
|
||||
std::string loc;
|
||||
{
|
||||
std::ostringstream os(std::ios::binary);
|
||||
from_inv.serialize(os);
|
||||
loc = os.str();
|
||||
}
|
||||
action.setModifyInventoryStack(loc, from_list, from_i, false,
|
||||
src_item.getItemString());
|
||||
rollback->reportAction(action);
|
||||
}
|
||||
// If destination is not infinite, record item put
|
||||
if(!dst_can_put_count != -1){
|
||||
RollbackAction action;
|
||||
std::string loc;
|
||||
{
|
||||
std::ostringstream os(std::ios::binary);
|
||||
to_inv.serialize(os);
|
||||
loc = os.str();
|
||||
}
|
||||
action.setModifyInventoryStack(loc, to_list, to_i, true,
|
||||
src_item.getItemString());
|
||||
rollback->reportAction(action);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
Report move to endpoints
|
||||
*/
|
||||
|
@ -405,7 +449,7 @@ void IMoveAction::apply(InventoryManager *mgr, ServerActiveObject *player, IGame
|
|||
L, from_inv.p, from_list, from_i, src_item, player);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
mgr->setInventoryModified(from_inv);
|
||||
if(inv_from != inv_to)
|
||||
mgr->setInventoryModified(to_inv);
|
||||
|
@ -488,6 +532,11 @@ void IDropAction::apply(InventoryManager *mgr, ServerActiveObject *player, IGame
|
|||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
Do not handle rollback if inventory is player's
|
||||
*/
|
||||
bool ignore_src_rollback = (from_inv.type == InventoryLocation::PLAYER);
|
||||
|
||||
/*
|
||||
Collect information of endpoints
|
||||
*/
|
||||
|
@ -575,6 +624,28 @@ void IDropAction::apply(InventoryManager *mgr, ServerActiveObject *player, IGame
|
|||
scriptapi_nodemeta_inventory_on_take(
|
||||
L, from_inv.p, from_list, from_i, src_item, player);
|
||||
}
|
||||
|
||||
/*
|
||||
Record rollback information
|
||||
*/
|
||||
if(!ignore_src_rollback)
|
||||
{
|
||||
IRollbackReportSink *rollback = gamedef->rollback();
|
||||
|
||||
// If source is not infinite, record item take
|
||||
if(!src_can_take_count != -1){
|
||||
RollbackAction action;
|
||||
std::string loc;
|
||||
{
|
||||
std::ostringstream os(std::ios::binary);
|
||||
from_inv.serialize(os);
|
||||
loc = os.str();
|
||||
}
|
||||
action.setModifyInventoryStack(loc, from_list, from_i,
|
||||
false, src_item.getItemString());
|
||||
rollback->reportAction(action);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void IDropAction::clientApply(InventoryManager *mgr, IGameDef *gamedef)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue