Add last location memoization in Lua context

This commit is contained in:
Michael Krasnyk
2017-10-03 14:17:45 +02:00
parent 545097cf06
commit 11e7b6e911
5 changed files with 103 additions and 65 deletions
+11 -1
View File
@@ -309,7 +309,17 @@ void Sol2ScriptingEnvironment::InitContext(LuaScriptingContext &context)
// at one or many locations must be provided
const auto &nodes = way.nodes();
const auto &location = nodes.back().location();
auto value = context.location_dependent_data({location.lon(), location.lat()}, key);
const LocationDependentData::point_t point{location.lon(), location.lat()};
if (!boost::geometry::equals(context.last_location_point, point))
{
context.last_location_point = point;
context.last_location_indexes =
context.location_dependent_data.GetPropertyIndexes(point);
}
auto value =
context.location_dependent_data.FindByKey(context.last_location_indexes, key);
return boost::apply_visitor(to_lua_object(context.state), value);
});