From 6a0388bb4bedc1b1c6318d7bfebaf1ec67ccf94e Mon Sep 17 00:00:00 2001 From: Perttu Ahola Date: Sun, 10 Jun 2012 12:46:48 +0300 Subject: Node placement client-side prediction --- src/scriptapi.cpp | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) (limited to 'src/scriptapi.cpp') diff --git a/src/scriptapi.cpp b/src/scriptapi.cpp index 3766496a0..afd8546d9 100644 --- a/src/scriptapi.cpp +++ b/src/scriptapi.cpp @@ -930,13 +930,14 @@ static void read_object_properties(lua_State *L, int index, ItemDefinition */ -static ItemDefinition read_item_definition(lua_State *L, int index) +static ItemDefinition read_item_definition(lua_State *L, int index, + ItemDefinition default_def = ItemDefinition()) { if(index < 0) index = lua_gettop(L) + 1 + index; // Read the item definition - ItemDefinition def; + ItemDefinition def = default_def; def.type = (ItemType)getenumfield(L, index, "type", es_ItemType, ITEM_NONE); @@ -981,6 +982,12 @@ static ItemDefinition read_item_definition(lua_State *L, int index) read_groups(L, -1, def.groups); lua_pop(L, 1); + // Client shall immediately place this node when player places the item. + // Server will update the precise end result a moment later. + // "" = no prediction + getstringfield(L, index, "node_placement_prediction", + def.node_placement_prediction); + return def; } @@ -3891,9 +3898,10 @@ static int l_register_item_raw(lua_State *L) get_server(L)->getWritableNodeDefManager(); // Check if name is defined + std::string name; lua_getfield(L, table, "name"); if(lua_isstring(L, -1)){ - std::string name = lua_tostring(L, -1); + name = lua_tostring(L, -1); verbosestream<<"register_item_raw: "<registerItem(def); // Read the node definition (content features) and register it -- cgit v1.2.3