summaryrefslogtreecommitdiff
path: root/indra
diff options
context:
space:
mode:
Diffstat (limited to 'indra')
-rw-r--r--indra/newview/llagentlistener.cpp117
-rw-r--r--indra/newview/llagentlistener.h4
-rw-r--r--indra/newview/scripts/lua/require/LLAgent.lua36
-rw-r--r--indra/newview/scripts/lua/require/UI.lua6
-rw-r--r--indra/newview/scripts/lua/test_nearby_avatars.lua25
5 files changed, 186 insertions, 2 deletions
diff --git a/indra/newview/llagentlistener.cpp b/indra/newview/llagentlistener.cpp
index 14e443ec4e..f00173dc13 100644
--- a/indra/newview/llagentlistener.cpp
+++ b/indra/newview/llagentlistener.cpp
@@ -32,11 +32,14 @@
#include "llagent.h"
#include "llagentcamera.h"
+#include "llavatarname.h"
+#include "llavatarnamecache.h"
#include "llvoavatar.h"
#include "llcommandhandler.h"
#include "llinventorymodel.h"
#include "llslurl.h"
#include "llurldispatcher.h"
+#include "llviewercontrol.h"
#include "llviewernetwork.h"
#include "llviewerobject.h"
#include "llviewerobjectlist.h"
@@ -47,6 +50,7 @@
#include "lltoolgrab.h"
#include "llhudeffectlookat.h"
#include "llagentcamera.h"
+#include "resultset.h"
#include <functional>
static const F64 PLAY_ANIM_THROTTLE_PERIOD = 1.f;
@@ -176,6 +180,25 @@ LLAgentListener::LLAgentListener(LLAgent &agent)
"Return information about [\"item_id\"] animation",
&LLAgentListener::getAnimationInfo,
llsd::map("item_id", LLSD(), "reply", LLSD()));
+
+ add("getID",
+ "Return your own avatar ID",
+ &LLAgentListener::getID,
+ llsd::map("reply", LLSD()));
+
+ add("getNearbyAvatarsList",
+ "Return result set key [\"result\"] for nearby avatars in a range of [\"dist\"]\n"
+ "if [\"dist\"] is not specified, 'RenderFarClip' setting is used\n"
+ "reply contains \"result\" table with \"id\", \"name\", \"global_pos\", \"region_pos\" fields",
+ &LLAgentListener::getNearbyAvatarsList,
+ llsd::map("reply", LLSD()));
+
+ add("getNearbyObjectsList",
+ "Return result set key [\"result\"] for nearby objects in a range of [\"dist\"]\n"
+ "if [\"dist\"] is not specified, 'RenderFarClip' setting is used\n"
+ "reply contains \"result\" table with \"id\", \"global_pos\", \"region_pos\" fields",
+ &LLAgentListener::getNearbyObjectsList,
+ llsd::map("reply", LLSD()));
}
void LLAgentListener::requestTeleport(LLSD const & event_data) const
@@ -693,3 +716,97 @@ void LLAgentListener::getAnimationInfo(LLSD const &event_data)
"priority", motion->getPriority());
}
}
+
+void LLAgentListener::getID(LLSD const& event_data)
+{
+ Response response(llsd::map("id", gAgentID), event_data);
+}
+
+struct AvResultSet : public LL::ResultSet
+{
+ AvResultSet() : LL::ResultSet("nearby_avatars") {}
+ std::vector<LLCharacter*> mAvatars;
+
+ int getLength() const override { return narrow(mAvatars.size()); }
+ LLSD getSingle(int index) const override
+ {
+ auto av = mAvatars[index];
+ LLAvatarName av_name;
+ LLAvatarNameCache::get(av->getID(), &av_name);
+ LLVector3 region_pos = av->getCharacterPosition();
+ return llsd::map("id", av->getID(),
+ "global_pos", ll_sd_from_vector3d(av->getPosGlobalFromAgent(region_pos)),
+ "region_pos", ll_sd_from_vector3(region_pos),
+ "name", av_name.getUserName());
+ }
+};
+
+struct ObjResultSet : public LL::ResultSet
+{
+ ObjResultSet() : LL::ResultSet("nearby_objects") {}
+ std::vector<LLViewerObject*> mObjects;
+
+ int getLength() const override { return narrow(mObjects.size()); }
+ LLSD getSingle(int index) const override
+ {
+ auto obj = mObjects[index];
+ return llsd::map("id", obj->getID(),
+ "global_pos", ll_sd_from_vector3d(obj->getPositionGlobal()),
+ "region_pos", ll_sd_from_vector3(obj->getPositionRegion()));
+ }
+};
+
+
+F32 get_search_radius(LLSD const& event_data)
+{
+ static LLCachedControl<F32> render_far_clip(gSavedSettings, "RenderFarClip", 64);
+ F32 dist = render_far_clip;
+ if (event_data.has("dist"))
+ {
+ dist = llclamp((F32)event_data["dist"].asReal(), 1, 512);
+ }
+ return dist * dist;
+}
+
+void LLAgentListener::getNearbyAvatarsList(LLSD const& event_data)
+{
+ Response response(LLSD(), event_data);
+ auto avresult = new AvResultSet;
+
+ F32 radius = get_search_radius(event_data);
+ LLVector3d agent_pos = gAgent.getPositionGlobal();
+ for (LLCharacter* character : LLCharacter::sInstances)
+ {
+ LLVOAvatar* avatar = (LLVOAvatar*)character;
+ if (!avatar->isDead() && !avatar->isControlAvatar() && !avatar->isSelf())
+ {
+ if ((dist_vec_squared(avatar->getPositionGlobal(), agent_pos) <= radius))
+ {
+ avresult->mAvatars.push_back(avatar);
+ }
+ }
+ }
+ response["result"] = avresult->getKeyLength();
+}
+
+void LLAgentListener::getNearbyObjectsList(LLSD const& event_data)
+{
+ Response response(LLSD(), event_data);
+ auto objresult = new ObjResultSet;
+
+ F32 radius = get_search_radius(event_data);
+ S32 num_objects = gObjectList.getNumObjects();
+ LLVector3d agent_pos = gAgent.getPositionGlobal();
+ for (S32 i = 0; i < num_objects; ++i)
+ {
+ LLViewerObject* object = gObjectList.getObject(i);
+ if (object && object->getVolume() && !object->isAttachment())
+ {
+ if ((dist_vec_squared(object->getPositionGlobal(), agent_pos) <= radius))
+ {
+ objresult->mObjects.push_back(object);
+ }
+ }
+ }
+ response["result"] = objresult->getKeyLength();
+}
diff --git a/indra/newview/llagentlistener.h b/indra/newview/llagentlistener.h
index 05724ff443..f1e85f0923 100644
--- a/indra/newview/llagentlistener.h
+++ b/indra/newview/llagentlistener.h
@@ -67,6 +67,10 @@ private:
void stopAnimation(LLSD const &event_data);
void getAnimationInfo(LLSD const &event_data);
+ void getID(LLSD const& event_data);
+ void getNearbyAvatarsList(LLSD const& event_data);
+ void getNearbyObjectsList(LLSD const& event_data);
+
LLViewerObject * findObjectClosestTo( const LLVector3 & position, bool sit_target = false ) const;
private:
diff --git a/indra/newview/scripts/lua/require/LLAgent.lua b/indra/newview/scripts/lua/require/LLAgent.lua
index 4a1132fe7e..70f3cdfffb 100644
--- a/indra/newview/scripts/lua/require/LLAgent.lua
+++ b/indra/newview/scripts/lua/require/LLAgent.lua
@@ -1,8 +1,26 @@
local leap = require 'leap'
local mapargs = require 'mapargs'
+local result_view = require 'result_view'
+
+local function result(keys)
+ local result_table = {
+ result=result_view(keys.result),
+ -- call result_table:close() to release result sets before garbage
+ -- collection or script completion
+ close = function(self)
+ result_view.close(keys.result[1])
+ end
+ }
+ -- When the result_table is destroyed, close its result_views.
+ return LL.setdtor('LLAgent result', result_table, result_table.close)
+end
local LLAgent = {}
+function LLAgent.getID()
+ return leap.request('LLAgent', {op = 'getID'}).id
+end
+
function LLAgent.getRegionPosition()
return leap.request('LLAgent', {op = 'getPosition'}).region
end
@@ -95,6 +113,24 @@ function LLAgent.requestStand()
leap.send('LLAgent', {op = 'requestStand'})
end
+-- Get the nearby avatars in a range of provided "dist",
+-- if "dist" is not specified, "RenderFarClip" setting is used
+-- reply will contain "result" table with following fields:
+-- "id", "global_pos", "region_pos", "name"
+function LLAgent.getNearbyAvatarsList(...)
+ local args = mapargs('dist', ...)
+ args.op = 'getNearbyAvatarsList'
+ return result(leap.request('LLAgent', args))
+end
+
+-- reply will contain "result" table with following fields:
+-- "id", "global_pos", "region_pos"
+function LLAgent.getNearbyObjectsList(...)
+ local args = mapargs('dist', ...)
+ args.op = 'getNearbyObjectsList'
+ return result(leap.request('LLAgent', args))
+end
+
-- ***************************************************************************
-- Autopilot
-- ***************************************************************************
diff --git a/indra/newview/scripts/lua/require/UI.lua b/indra/newview/scripts/lua/require/UI.lua
index cf2695917e..34f3fb75eb 100644
--- a/indra/newview/scripts/lua/require/UI.lua
+++ b/indra/newview/scripts/lua/require/UI.lua
@@ -222,8 +222,10 @@ function UI.hideFloater(floater_name)
leap.send("LLFloaterReg", {op = "hideInstance", name = floater_name})
end
-function UI.toggleFloater(floater_name)
- leap.send("LLFloaterReg", {op = "toggleInstance", name = floater_name})
+function UI.toggleFloater(...)
+ local args = mapargs('name,key', ...)
+ args.op = 'toggleInstance'
+ leap.send("LLFloaterReg", args)
end
function UI.isFloaterVisible(floater_name)
diff --git a/indra/newview/scripts/lua/test_nearby_avatars.lua b/indra/newview/scripts/lua/test_nearby_avatars.lua
new file mode 100644
index 0000000000..c7fa686076
--- /dev/null
+++ b/indra/newview/scripts/lua/test_nearby_avatars.lua
@@ -0,0 +1,25 @@
+inspect = require 'inspect'
+LLAgent = require 'LLAgent'
+
+-- Get the list of nearby avatars and print the info
+local nearby_avatars = LLAgent.getNearbyAvatarsList()
+if nearby_avatars.result.length == 0 then
+ print("No avatars nearby")
+else
+ print("Nearby avatars:")
+ for _, av in pairs(nearby_avatars.result) do
+ print(av.name ..' ID: ' .. av.id ..' Global pos:' .. inspect(av.global_pos))
+ end
+end
+
+-- Get the list of nearby objects in 3m range and print the info
+local nearby_objects = LLAgent.getNearbyObjectsList(3)
+if nearby_objects.result.length == 0 then
+ print("No objects nearby")
+else
+ print("Nearby objects:")
+ local pos={}
+ for _, obj in pairs(nearby_objects.result) do
+ print('ID: ' .. obj.id ..' Global pos:' .. inspect(obj.global_pos))
+ end
+end