hate underachiever forever
[QuestHelper.git] / collect_location.lua
blobb9d9af6ebffa38f725fb26d1e9a4342acb73b593
1 QuestHelper_File["collect_location.lua"] = "Development Version"
2 QuestHelper_Loadtime["collect_location.lua"] = GetTime()
4 -- little endian two's complement
5 local function signed(c)
6 QuestHelper: Assert(not c or c >= -127 and c < 127)
7 if not c then c = -128 end
8 if c < 0 then c = c + 256 end
9 return strchar(c)
10 end
12 local function float(c)
13 if c then
14 c = math.floor(c * 16777216 + 0.5) -- 24 bits of fraction baby
15 QuestHelper: Assert(c >= -2147483647 and c < 2147483647)
16 else
17 c = -2147483648
18 end
19 if c < 0 then c = c + 4294967296 end
20 return strchar(bit.band(c, 0xff), bit.band(c, 0xff00) / 256, bit.band(c, 0xff0000) / 65536, bit.band(c, 0xff000000) / 16777216)
21 end
23 local function BolusizeLocation(delayed, c, z, x, y)
24 -- c and z are *signed* integers that fit within an 8-bit int.
25 -- 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.
26 -- Overall we're using a weird 11 bytes on this. Meh.
27 -- Also, any nil values are being turned into MIN_WHATEVER.
28 return signed(delayed and 1 or 0) .. signed(c) .. signed(z) .. float(x) .. float(y)
29 end
31 -- This merely provides another API function
32 function QH_Collect_Location_Init(_, API)
33 API.Callback_LocationBolus = BolusizeLocation -- Yeah. *Bolusize*. You heard me.
34 API.Callback_LocationBolusCurrent = function () return BolusizeLocation(API.Callback_Location_Raw()) end -- This is just a convenience function, really
35 end