2023-06-11 20:00:11 +00:00
|
|
|
math.randomseed(get_time())
|
|
|
|
|
2024-03-17 19:02:03 +00:00
|
|
|
|
2024-01-08 01:23:24 +00:00
|
|
|
--------------
|
|
|
|
-- CObjects --
|
|
|
|
--------------
|
|
|
|
|
2023-06-25 06:43:03 +00:00
|
|
|
_CObjectPool = {}
|
|
|
|
|
2022-02-03 08:43:17 +00:00
|
|
|
_CObject = {
|
|
|
|
__index = function (t,k)
|
2022-03-05 02:16:54 +00:00
|
|
|
return _get_field(t['_lot'], t['_pointer'], k, t)
|
2022-02-03 08:43:17 +00:00
|
|
|
end,
|
|
|
|
__newindex = function (t,k,v)
|
2022-03-05 02:16:54 +00:00
|
|
|
_set_field(t['_lot'], t['_pointer'], k, v, t)
|
2022-02-03 08:43:17 +00:00
|
|
|
end,
|
2023-06-25 06:43:03 +00:00
|
|
|
__tostring = function(t)
|
|
|
|
return 'CObject: ' .. t['_lot'] .. ', [' .. string.format('0x%08X', t['_pointer']) .. ']'
|
|
|
|
end,
|
2022-02-03 08:43:17 +00:00
|
|
|
__eq = function (a, b)
|
|
|
|
return a['_pointer'] == b['_pointer'] and a['_lot'] == b['_lot'] and a['_pointer'] ~= nil and a['_lot'] ~= nil
|
|
|
|
end
|
|
|
|
}
|
|
|
|
|
2023-06-25 06:43:03 +00:00
|
|
|
function _NewCObject(lot, pointer)
|
|
|
|
if _CObjectPool[lot] == nil then
|
|
|
|
_CObjectPool[lot] = {}
|
|
|
|
end
|
|
|
|
|
|
|
|
if _CObjectPool[lot][pointer] == nil then
|
|
|
|
local obj = {}
|
|
|
|
rawset(obj, '_pointer', pointer)
|
|
|
|
rawset(obj, '_lot', lot)
|
|
|
|
setmetatable(obj, _CObject)
|
|
|
|
_CObjectPool[lot][pointer] = obj
|
|
|
|
return obj
|
|
|
|
end
|
|
|
|
|
|
|
|
return _CObjectPool[lot][pointer]
|
|
|
|
end
|
|
|
|
|
|
|
|
local _CPointerPool = {}
|
|
|
|
|
2022-02-16 06:09:21 +00:00
|
|
|
_CPointer = {
|
|
|
|
__index = function (t,k)
|
|
|
|
return nil
|
|
|
|
end,
|
|
|
|
__newindex = function (t,k,v)
|
|
|
|
end,
|
|
|
|
__tostring = function(t)
|
|
|
|
return 'CPointer: ' .. t['_lvt'] .. ', [' .. string.format('0x%08X', t['_pointer']) .. ']'
|
|
|
|
end,
|
|
|
|
__eq = function (a, b)
|
|
|
|
return a['_pointer'] == b['_pointer'] and a['_pointer'] ~= nil and a['_lvt'] ~= nil
|
|
|
|
end
|
|
|
|
}
|
|
|
|
|
2023-06-25 06:43:03 +00:00
|
|
|
function _NewCPointer(lvt, pointer)
|
|
|
|
if _CPointerPool[lvt] == nil then
|
|
|
|
_CPointerPool[lvt] = {}
|
|
|
|
end
|
|
|
|
|
|
|
|
if _CPointerPool[lvt][pointer] == nil then
|
|
|
|
local obj = {}
|
|
|
|
rawset(obj, '_pointer', pointer)
|
|
|
|
rawset(obj, '_lvt', lvt)
|
|
|
|
setmetatable(obj, _CPointer)
|
|
|
|
_CPointerPool[lvt][pointer] = obj
|
|
|
|
return obj
|
|
|
|
end
|
|
|
|
|
|
|
|
return _CPointerPool[lvt][pointer]
|
|
|
|
end
|
|
|
|
|
2022-02-03 08:43:17 +00:00
|
|
|
_SyncTable = {
|
|
|
|
__index = function (t,k)
|
|
|
|
local _table = rawget(t, '_table')
|
|
|
|
return _table[k]
|
|
|
|
end,
|
|
|
|
__newindex = function (t,k,v)
|
|
|
|
local _table = rawget(t, '_table')
|
|
|
|
if _table[k] == v then return end
|
|
|
|
_set_sync_table_field(t, k, v)
|
|
|
|
end
|
|
|
|
}
|
|
|
|
|
|
|
|
_ReadOnlyTable = {
|
|
|
|
__index = function (t,k)
|
|
|
|
local _table = rawget(t, '_table')
|
|
|
|
return _table[k]
|
|
|
|
end,
|
|
|
|
__newindex = function (t,k,v)
|
|
|
|
end
|
|
|
|
}
|
|
|
|
|
2024-03-17 19:02:03 +00:00
|
|
|
|
2024-01-08 01:23:24 +00:00
|
|
|
--------------------
|
|
|
|
-- math functions --
|
|
|
|
--------------------
|
|
|
|
|
2022-03-13 05:28:57 +00:00
|
|
|
--- @param dest Vec3f
|
|
|
|
--- @param src Vec3f
|
|
|
|
--- @return Vec3f
|
2022-02-03 08:43:17 +00:00
|
|
|
function vec3f_copy(dest, src)
|
|
|
|
dest.x = src.x
|
|
|
|
dest.y = src.y
|
|
|
|
dest.z = src.z
|
|
|
|
return dest
|
|
|
|
end
|
|
|
|
|
2022-03-13 05:28:57 +00:00
|
|
|
--- @param dest Vec3f
|
|
|
|
--- @param x number
|
|
|
|
--- @param y number
|
|
|
|
--- @param z number
|
|
|
|
--- @return Vec3f
|
2022-02-03 08:43:17 +00:00
|
|
|
function vec3f_set(dest, x, y, z)
|
|
|
|
dest.x = x
|
|
|
|
dest.y = y
|
|
|
|
dest.z = z
|
|
|
|
return dest
|
|
|
|
end
|
|
|
|
|
2022-03-13 05:28:57 +00:00
|
|
|
--- @param dest Vec3f
|
|
|
|
--- @param a Vec3f
|
|
|
|
--- @return Vec3f
|
2022-02-03 08:43:17 +00:00
|
|
|
function vec3f_add(dest, a)
|
|
|
|
dest.x = dest.x + a.x
|
|
|
|
dest.y = dest.y + a.y
|
|
|
|
dest.z = dest.z + a.z
|
|
|
|
return dest
|
|
|
|
end
|
|
|
|
|
2022-03-13 05:28:57 +00:00
|
|
|
--- @param dest Vec3f
|
|
|
|
--- @param a Vec3f
|
|
|
|
--- @param b Vec3f
|
|
|
|
--- @return Vec3f
|
2022-02-03 08:43:17 +00:00
|
|
|
function vec3f_sum(dest, a, b)
|
|
|
|
dest.x = a.x + b.x
|
|
|
|
dest.y = a.y + b.y
|
|
|
|
dest.z = a.z + b.z
|
|
|
|
return dest
|
|
|
|
end
|
|
|
|
|
2022-03-13 05:28:57 +00:00
|
|
|
--- @param dest Vec3f
|
|
|
|
--- @param a number
|
|
|
|
--- @return Vec3f
|
2022-02-03 08:43:17 +00:00
|
|
|
function vec3f_mul(dest, a)
|
|
|
|
dest.x = dest.x * a
|
|
|
|
dest.y = dest.y * a
|
|
|
|
dest.z = dest.z * a
|
|
|
|
return dest
|
|
|
|
end
|
|
|
|
|
2022-03-13 05:28:57 +00:00
|
|
|
--- @param dest Vec3f
|
|
|
|
--- @return Vec3f
|
2022-03-06 02:10:20 +00:00
|
|
|
function vec3f_normalize(dest)
|
2022-03-10 02:59:55 +00:00
|
|
|
local divisor = math.sqrt(dest.x * dest.x + dest.y * dest.y + dest.z * dest.z)
|
|
|
|
if divisor == 0 then
|
2022-03-06 02:10:20 +00:00
|
|
|
return dest
|
|
|
|
end
|
|
|
|
|
2022-03-10 02:59:55 +00:00
|
|
|
local invsqrt = 1.0 / divisor
|
2022-03-06 02:10:20 +00:00
|
|
|
dest.x = dest.x * invsqrt
|
|
|
|
dest.y = dest.y * invsqrt
|
|
|
|
dest.z = dest.z * invsqrt
|
|
|
|
|
|
|
|
return dest
|
|
|
|
end
|
|
|
|
|
2022-03-13 05:28:57 +00:00
|
|
|
--- @param a Vec3f
|
|
|
|
--- @return number
|
2022-03-06 02:10:20 +00:00
|
|
|
function vec3f_length(a)
|
|
|
|
return math.sqrt(a.x * a.x + a.y * a.y + a.z * a.z)
|
|
|
|
end
|
|
|
|
|
2022-03-13 05:28:57 +00:00
|
|
|
--- @param a Vec3f
|
|
|
|
--- @param b Vec3f
|
|
|
|
--- @return number
|
2022-03-06 02:10:20 +00:00
|
|
|
function vec3f_dot(a, b)
|
|
|
|
return a.x * b.x + a.y * b.y + a.z * b.z
|
|
|
|
end
|
|
|
|
|
2022-03-13 05:28:57 +00:00
|
|
|
--- @param vec Vec3f
|
|
|
|
--- @param onto Vec3f
|
|
|
|
--- @return Vec3f
|
2022-03-06 02:10:20 +00:00
|
|
|
function vec3f_project(vec, onto)
|
|
|
|
local numerator = vec3f_dot(vec, onto)
|
|
|
|
local denominator = vec3f_dot(onto, onto)
|
|
|
|
local out = {}
|
|
|
|
vec3f_copy(out, onto)
|
|
|
|
vec3f_mul(out, numerator / denominator)
|
|
|
|
return out
|
|
|
|
end
|
|
|
|
|
2022-03-13 05:28:57 +00:00
|
|
|
--- @param v1 Vec3f
|
|
|
|
--- @param v2 Vec3f
|
|
|
|
--- @return number
|
2022-02-04 03:05:59 +00:00
|
|
|
function vec3f_dist(v1, v2)
|
|
|
|
dx = v1.x - v2.x
|
|
|
|
dy = v1.y - v2.y
|
|
|
|
dz = v1.z - v2.z
|
|
|
|
return math.sqrt(dx * dx + dy * dy + dz * dz)
|
|
|
|
end
|
|
|
|
|
2022-03-13 05:28:57 +00:00
|
|
|
--- @param dest Vec3s
|
|
|
|
--- @param src Vec3s
|
|
|
|
--- @return Vec3s
|
2022-02-03 08:43:17 +00:00
|
|
|
function vec3s_copy(dest, src)
|
|
|
|
dest.x = src.x
|
|
|
|
dest.y = src.y
|
|
|
|
dest.z = src.z
|
|
|
|
return dest
|
|
|
|
end
|
|
|
|
|
2022-03-13 05:28:57 +00:00
|
|
|
--- @param dest Vec3s
|
|
|
|
--- @param x number
|
|
|
|
--- @param y number
|
|
|
|
--- @param z number
|
|
|
|
--- @return Vec3s
|
2022-02-03 08:43:17 +00:00
|
|
|
function vec3s_set(dest, x, y, z)
|
|
|
|
dest.x = x
|
|
|
|
dest.y = y
|
|
|
|
dest.z = z
|
|
|
|
return dest
|
|
|
|
end
|
|
|
|
|
2022-03-13 05:28:57 +00:00
|
|
|
--- @param dest Vec3s
|
|
|
|
--- @param a Vec3s
|
|
|
|
--- @return Vec3s
|
2022-02-03 08:43:17 +00:00
|
|
|
function vec3s_add(dest, a)
|
|
|
|
dest.x = dest.x + a.x
|
|
|
|
dest.y = dest.y + a.y
|
|
|
|
dest.z = dest.z + a.z
|
|
|
|
return dest
|
|
|
|
end
|
|
|
|
|
2022-03-13 05:28:57 +00:00
|
|
|
--- @param dest Vec3s
|
|
|
|
--- @param a Vec3s
|
|
|
|
--- @param b Vec3s
|
|
|
|
--- @return Vec3s
|
2022-02-03 08:43:17 +00:00
|
|
|
function vec3s_sum(dest, a, b)
|
|
|
|
dest.x = a.x + b.x
|
|
|
|
dest.y = a.y + b.y
|
|
|
|
dest.z = a.z + b.z
|
|
|
|
return dest
|
|
|
|
end
|
|
|
|
|
2022-03-13 05:28:57 +00:00
|
|
|
--- @param dest Vec3s
|
|
|
|
--- @param a number
|
|
|
|
--- @return Vec3s
|
2022-02-03 08:43:17 +00:00
|
|
|
function vec3s_mul(dest, a)
|
|
|
|
dest.x = dest.x * a
|
|
|
|
dest.y = dest.y * a
|
|
|
|
dest.z = dest.z * a
|
|
|
|
return dest
|
|
|
|
end
|
|
|
|
|
2022-03-13 05:28:57 +00:00
|
|
|
--- @param v1 Vec3s
|
|
|
|
--- @param v2 Vec3s
|
|
|
|
--- @return number
|
2022-02-04 03:05:59 +00:00
|
|
|
function vec3s_dist(v1, v2)
|
|
|
|
dx = v1.x - v2.x
|
|
|
|
dy = v1.y - v2.y
|
|
|
|
dz = v1.z - v2.z
|
|
|
|
return math.sqrt(dx * dx + dy * dy + dz * dz)
|
|
|
|
end
|
|
|
|
|
2022-03-13 05:28:57 +00:00
|
|
|
--- @param current number
|
|
|
|
--- @param target number
|
|
|
|
--- @param inc number
|
|
|
|
--- @param dec number
|
|
|
|
--- @return number
|
2022-02-03 08:43:17 +00:00
|
|
|
function approach_f32(current, target, inc, dec)
|
|
|
|
if current < target then
|
|
|
|
current = current + inc
|
|
|
|
if current > target then
|
|
|
|
current = target
|
|
|
|
end
|
|
|
|
else
|
|
|
|
current = current - dec
|
|
|
|
if current < target then
|
|
|
|
current = target
|
|
|
|
end
|
|
|
|
end
|
2023-11-24 16:24:26 +00:00
|
|
|
return current
|
2022-02-03 08:43:17 +00:00
|
|
|
end
|
|
|
|
|
2023-11-24 16:24:26 +00:00
|
|
|
--- @param current integer
|
|
|
|
--- @param target integer
|
|
|
|
--- @param inc integer
|
|
|
|
--- @param dec integer
|
|
|
|
--- @return integer
|
2022-02-15 02:26:44 +00:00
|
|
|
function approach_s32(current, target, inc, dec)
|
|
|
|
if current < target then
|
|
|
|
current = current + inc
|
|
|
|
if current > target then
|
|
|
|
current = target
|
|
|
|
end
|
|
|
|
else
|
|
|
|
current = current - dec
|
|
|
|
if current < target then
|
|
|
|
current = target
|
|
|
|
end
|
|
|
|
end
|
2022-03-19 07:56:59 +00:00
|
|
|
|
|
|
|
-- keep within 32 bits
|
|
|
|
if current > 2147483647 then
|
|
|
|
current = -2147483648 + (current - 2147483647)
|
|
|
|
elseif current < -2147483648 then
|
|
|
|
current = 2147483647 + (current - (-2147483648))
|
|
|
|
end
|
2023-11-24 16:24:26 +00:00
|
|
|
return current
|
2022-02-15 02:26:44 +00:00
|
|
|
end
|
|
|
|
|
2024-03-17 19:02:03 +00:00
|
|
|
|
2023-11-24 16:24:26 +00:00
|
|
|
-----------
|
|
|
|
-- sound --
|
|
|
|
-----------
|
|
|
|
|
|
|
|
--- @type Vec3f
|
2023-12-04 22:23:53 +00:00
|
|
|
gGlobalSoundSource = { x = 0, y = 0, z = 0 }
|
2023-11-24 16:24:26 +00:00
|
|
|
|
2022-03-13 05:28:57 +00:00
|
|
|
--- @param bank number
|
|
|
|
--- @param soundID number
|
|
|
|
--- @param priority number
|
2022-03-19 07:56:59 +00:00
|
|
|
--- @param flags number
|
2022-03-13 05:28:57 +00:00
|
|
|
--- @return number
|
2022-03-19 07:56:59 +00:00
|
|
|
function SOUND_ARG_LOAD(bank, soundID, priority, flags)
|
|
|
|
if flags == nil then flags = 0 end
|
|
|
|
return (bank << 28) | (soundID << 16) | (priority << 8) | flags | SOUND_STATUS_WAITING
|
2022-02-03 08:43:17 +00:00
|
|
|
end
|
2022-04-10 06:28:36 +00:00
|
|
|
|
2022-04-10 07:30:47 +00:00
|
|
|
-------------
|
|
|
|
-- courses --
|
|
|
|
-------------
|
|
|
|
|
2022-04-10 06:28:36 +00:00
|
|
|
--- @type integer
|
|
|
|
COURSE_NONE = 0
|
|
|
|
--- @type integer
|
|
|
|
COURSE_BOB = 1
|
|
|
|
--- @type integer
|
|
|
|
COURSE_WF = 2
|
|
|
|
--- @type integer
|
|
|
|
COURSE_JRB = 3
|
|
|
|
--- @type integer
|
|
|
|
COURSE_CCM = 4
|
|
|
|
--- @type integer
|
|
|
|
COURSE_BBH = 5
|
|
|
|
--- @type integer
|
|
|
|
COURSE_HMC = 6
|
|
|
|
--- @type integer
|
|
|
|
COURSE_LLL = 7
|
|
|
|
--- @type integer
|
|
|
|
COURSE_SSL = 8
|
|
|
|
--- @type integer
|
|
|
|
COURSE_DDD = 9
|
|
|
|
--- @type integer
|
|
|
|
COURSE_SL = 10
|
|
|
|
--- @type integer
|
|
|
|
COURSE_WDW = 11
|
|
|
|
--- @type integer
|
|
|
|
COURSE_TTM = 12
|
|
|
|
--- @type integer
|
|
|
|
COURSE_THI = 13
|
|
|
|
--- @type integer
|
|
|
|
COURSE_TTC = 14
|
|
|
|
--- @type integer
|
|
|
|
COURSE_RR = 15
|
|
|
|
--- @type integer
|
|
|
|
COURSE_BITDW = 16
|
|
|
|
--- @type integer
|
|
|
|
COURSE_BITFS = 17
|
|
|
|
--- @type integer
|
|
|
|
COURSE_BITS = 18
|
|
|
|
--- @type integer
|
|
|
|
COURSE_PSS = 19
|
|
|
|
--- @type integer
|
|
|
|
COURSE_COTMC = 20
|
|
|
|
--- @type integer
|
|
|
|
COURSE_TOTWC = 21
|
|
|
|
--- @type integer
|
|
|
|
COURSE_VCUTM = 22
|
|
|
|
--- @type integer
|
|
|
|
COURSE_WMOTR = 23
|
|
|
|
--- @type integer
|
|
|
|
COURSE_SA = 24
|
|
|
|
--- @type integer
|
2022-04-10 07:30:47 +00:00
|
|
|
COURSE_CAKE_END = 25
|
|
|
|
--- @type integer
|
|
|
|
COURSE_END = 26
|
|
|
|
--- @type integer
|
|
|
|
COURSE_MAX = 25
|
|
|
|
--- @type integer
|
|
|
|
COURSE_COUNT = 25
|
|
|
|
--- @type integer
|
2024-01-08 01:23:24 +00:00
|
|
|
COURSE_MIN = 1
|
|
|
|
|
2024-03-17 19:02:03 +00:00
|
|
|
|
2024-05-19 13:38:22 +00:00
|
|
|
------------------------------
|
|
|
|
-- player palette functions --
|
|
|
|
------------------------------
|
|
|
|
|
|
|
|
--- @param np NetworkPlayer
|
|
|
|
--- @param part PlayerPart
|
|
|
|
--- @return Color
|
|
|
|
function network_player_get_palette_color(np, part)
|
|
|
|
local color = {
|
|
|
|
r = network_player_get_palette_color_channel(np, part, 0),
|
|
|
|
g = network_player_get_palette_color_channel(np, part, 1),
|
|
|
|
b = network_player_get_palette_color_channel(np, part, 2)
|
|
|
|
}
|
|
|
|
return color
|
|
|
|
end
|
|
|
|
|
|
|
|
--- @param np NetworkPlayer
|
|
|
|
--- @param part PlayerPart
|
|
|
|
--- @return Color
|
|
|
|
function network_player_get_override_palette_color(np, part)
|
|
|
|
local color = {
|
|
|
|
r = network_player_get_override_palette_color_channel(np, part, 0),
|
|
|
|
g = network_player_get_override_palette_color_channel(np, part, 1),
|
|
|
|
b = network_player_get_override_palette_color_channel(np, part, 2)
|
|
|
|
}
|
|
|
|
return color
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2024-01-08 01:23:24 +00:00
|
|
|
-----------------
|
|
|
|
-- legacy font --
|
|
|
|
-----------------
|
2024-02-18 19:54:01 +00:00
|
|
|
|
2024-03-17 20:32:49 +00:00
|
|
|
FONT_TINY = -1
|
|
|
|
|
|
|
|
|
|
|
|
----------------------
|
|
|
|
-- legacy functions --
|
|
|
|
----------------------
|
|
|
|
|
|
|
|
function get_coop_compatibility_enabled() return false end
|