1
0
Bifurcation 0
Ce dépôt a été archivé le 2020-03-15. Vous pouvez voir ses fichiers ou le cloner, mais pas ouvrir de ticket ou de demandes d'ajout, ni soumettre de changements.
questhelperredux/QuestHelper/collect_location.lua

49 lignes
2,1 Kio
Lua

QuestHelper_File["collect_location.lua"] = "4.0.1.$svnversion$"
QuestHelper_Loadtime["collect_location.lua"] = GetTime()
-- little endian two's complement
local function signed(c)
QuestHelper: Assert(not c or c >= -127 and c < 127)
if not c then c = -128 end
if c < 0 then c = c + 256 end
return tostring(c)
--return strchar(c)
end
local function float(c)
--[[
local orig_c = c
if c then
c = math.floor(c * 16777216 + 0.5) -- 24 bits of fraction baby
QuestHelper: Assert(c >= -2147483648, string.format("c is too small. It was %s, and now is %s.", tostring(orig_c), tostring(c)))
QuestHelper: Assert(c < 2147483647, string.format("c is too big. It was %s, and now is %s.", tostring(orig_c), tostring(c)))
else
c = -2147483648
end
if c < 0 then c = c + 4294967296 end
return strchar(bit.band(c, 0xff), bit.band(c, 0xff00) / 256, bit.band(c, 0xff0000) / 65536, bit.band(c, 0xff000000) / 16777216)
--]]
if not c then c = -128 end
QuestHelper: Assert( c >= -128, string.format("c is too small. It is %s.", tostring(c)))
QuestHelper: Assert( c < 128, string.format("c is too big. It is %s.", tostring(c)))
return tostring(c)
end
local function BolusizeLocation(delayed, c, z, x, y)
-- c and z are *signed* integers that fit within an 8-bit int.
-- x and y are floating-point values, generally between 0 and 1. We'll dedicate 24 bits to the fractional part, largely because we can.
-- Overall we're using a weird 11 bytes on this. Meh.
-- Also, any nil values are being turned into MIN_WHATEVER.
-- if x and y then print(delayed, c, z, x, y) end
local float_x = float(x)
local float_y = float(y)
--print(x, y)
return string.format("%s %s %s %s %s", signed(delayed and 1 or 0), signed(c), signed(z), float_x, float_y)
--return signed(delayed and 1 or 0) .. signed(c) .. signed(z) .. float_x .. float_y
end
-- This merely provides another API function
function QH_Collect_Location_Init(_, API)
API.Callback_LocationBolus = BolusizeLocation -- Yeah. *Bolusize*. You heard me.
API.Callback_LocationBolusCurrent = function () return BolusizeLocation(API.Callback_Location_Raw()) end -- This is just a convenience function, really
end