From ed7603bfe63ce5e8c1ff1101270e0406de01dc92 Mon Sep 17 00:00:00 2001 From: Mnikolenko Productengine Date: Tue, 17 Sep 2024 12:37:17 +0300 Subject: Use event pump to get autopilot status, when it's terminated; add demo script --- indra/newview/scripts/lua/require/LLAgent.lua | 13 +++++- indra/newview/scripts/lua/require/LLChat.lua | 1 + .../newview/scripts/lua/require/LLChatListener.lua | 48 --------------------- indra/newview/scripts/lua/require/LLListener.lua | 50 ++++++++++++++++++++++ 4 files changed, 63 insertions(+), 49 deletions(-) delete mode 100644 indra/newview/scripts/lua/require/LLChatListener.lua create mode 100644 indra/newview/scripts/lua/require/LLListener.lua (limited to 'indra/newview/scripts/lua/require') diff --git a/indra/newview/scripts/lua/require/LLAgent.lua b/indra/newview/scripts/lua/require/LLAgent.lua index 7b12493acc..4a1132fe7e 100644 --- a/indra/newview/scripts/lua/require/LLAgent.lua +++ b/indra/newview/scripts/lua/require/LLAgent.lua @@ -80,6 +80,11 @@ function LLAgent.teleport(...) return leap.request('LLTeleportHandler', args).message end +-- Call with no arguments to sit on the ground. +-- Otherwise specify "obj_uuid" to sit on, +-- or region "position" {x, y, z} where to find closest object to sit on. +-- For example: LLAgent.requestSit{position=LLAgent.getRegionPosition()} +-- Your avatar should be close enough to the object you want to sit on function LLAgent.requestSit(...) local args = mapargs('obj_uuid,position', ...) args.op = 'requestSit' @@ -90,6 +95,11 @@ function LLAgent.requestStand() leap.send('LLAgent', {op = 'requestStand'}) end +-- *************************************************************************** +-- Autopilot +-- *************************************************************************** +LLAgent.autoPilotPump = "LLAutopilot" + -- Start the autopilot to move to "target_global" location using specified parameters -- LLAgent.startAutoPilot{ target_global array of target global {x, y, z} position -- [, allow_flying] allow flying during autopilot [default: true] @@ -97,6 +107,7 @@ end -- [, behavior_name] name of the autopilot behavior [default: (script name)] -- [, target_rotation] array of [x, y, z, w] quaternion values [default: no target] -- [, rotation_threshold] target maximum angle from target facing rotation [default: 0.03 radians] +-- an event with "success" flag is sent to "LLAutopilot" event pump, when auto pilot is terminated function LLAgent.startAutoPilot(...) local args = mapargs('target_global,allow_flying,stop_distance,behavior_name,target_rotation,rotation_threshold', ...) args.op = 'startAutoPilot' @@ -109,7 +120,7 @@ function LLAgent.setAutoPilotTarget(target_global) end -- Start the autopilot to move to the specified target location --- either "leader_id" (uuid of target) or "avatar_name" (avatar full name) should be specified +-- either "leader_id" (uuid of target) or "avatar_name" (avatar full name: use just first name for 'Resident') should be specified -- "allow_flying" [default: true], "stop_distance" [default: autopilot guess] function LLAgent.startFollowPilot(...) local args = mapargs('leader_id,avatar_name,allow_flying,stop_distance', ...) diff --git a/indra/newview/scripts/lua/require/LLChat.lua b/indra/newview/scripts/lua/require/LLChat.lua index bc0fc86d22..3ac3bab746 100644 --- a/indra/newview/scripts/lua/require/LLChat.lua +++ b/indra/newview/scripts/lua/require/LLChat.lua @@ -5,6 +5,7 @@ local LLChat = {} -- *************************************************************************** -- Nearby chat -- *************************************************************************** +LLChat.nearbyChatPump = "LLNearbyChat" -- 0 is public nearby channel, other channels are used to communicate with LSL scripts function LLChat.sendNearby(msg, channel) diff --git a/indra/newview/scripts/lua/require/LLChatListener.lua b/indra/newview/scripts/lua/require/LLChatListener.lua deleted file mode 100644 index 82b28966ce..0000000000 --- a/indra/newview/scripts/lua/require/LLChatListener.lua +++ /dev/null @@ -1,48 +0,0 @@ -local fiber = require 'fiber' -local inspect = require 'inspect' -local leap = require 'leap' -local util = require 'util' - -local LLChatListener = {} -local waitfor = {} -local listener_name = {} - -function LLChatListener:new() - local obj = setmetatable({}, self) - self.__index = self - obj.name = 'Chat_listener' - - return obj -end - -util.classctor(LLChatListener) - -function LLChatListener:handleMessages(event_data) - print(inspect(event_data)) - return true -end - -function LLChatListener:start() - waitfor = leap.WaitFor(-1, self.name) - function waitfor:filter(pump, data) - if pump == "LLNearbyChat" then - return data - end - end - - fiber.launch(self.name, function() - event = waitfor:wait() - while event and self:handleMessages(event) do - event = waitfor:wait() - end - end) - - listener_name = leap.request(leap.cmdpump(), {op='listen', source='LLNearbyChat', listener="ChatListener", tweak=true}).listener -end - -function LLChatListener:stop() - leap.send(leap.cmdpump(), {op='stoplistening', source='LLNearbyChat', listener=listener_name}) - waitfor:close() -end - -return LLChatListener diff --git a/indra/newview/scripts/lua/require/LLListener.lua b/indra/newview/scripts/lua/require/LLListener.lua new file mode 100644 index 0000000000..e3bfb6b358 --- /dev/null +++ b/indra/newview/scripts/lua/require/LLListener.lua @@ -0,0 +1,50 @@ +local fiber = require 'fiber' +local inspect = require 'inspect' +local leap = require 'leap' +local util = require 'util' + +local LLListener = {} +local waitfor = {} +local listener_name = {} +local pump = {} + +function LLListener:new() + local obj = setmetatable({}, self) + self.__index = self + obj.name = 'Listener' + + return obj +end + +util.classctor(LLListener) + +function LLListener:handleMessages(event_data) + print(inspect(event_data)) + return true +end + +function LLListener:start(pump_name) + pump = pump_name + waitfor = leap.WaitFor(-1, self.name) + function waitfor:filter(pump_, data) + if pump == pump_ then + return data + end + end + + fiber.launch(self.name, function() + event = waitfor:wait() + while event and self:handleMessages(event) do + event = waitfor:wait() + end + end) + + listener_name = leap.request(leap.cmdpump(), {op='listen', source=pump, listener="LLListener", tweak=true}).listener +end + +function LLListener:stop() + leap.send(leap.cmdpump(), {op='stoplistening', source=pump, listener=listener_name}) + waitfor:close() +end + +return LLListener -- cgit v1.2.3