mirror of
https://github.com/coop-deluxe/sm64coopdx.git
synced 2026-07-13 01:41:07 +00:00
787 lines
32 KiB
Lua
787 lines
32 KiB
Lua
math.randomseed(get_time())
|
|
|
|
_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 (_,k,_) error('Attempting to modify key `' .. k .. '` of read-only table') end,
|
|
__metatable = false
|
|
}
|
|
|
|
-----------
|
|
-- table --
|
|
-----------
|
|
|
|
--- Creates a shallow copy of table `t`
|
|
--- @param t table
|
|
--- @return table
|
|
function table.copy(t)
|
|
return table_copy(t)
|
|
end
|
|
|
|
--- Creates a deep copy of table `t`
|
|
--- @param t table
|
|
--- @return table
|
|
function table.deepcopy(t)
|
|
return table_deepcopy(t)
|
|
end
|
|
|
|
--- Utility function to create a read-only table
|
|
--- @param data table
|
|
--- @return table
|
|
function create_read_only_table(data)
|
|
local t = {}
|
|
local mt = {
|
|
__index = data,
|
|
__newindex = function(_, k, _)
|
|
error('Attempting to modify key `' .. k .. '` of read-only table')
|
|
end,
|
|
__call = function() return table_copy(data) end,
|
|
__metatable = false
|
|
}
|
|
setmetatable(t, mt)
|
|
return t
|
|
end
|
|
|
|
-----------
|
|
-- sound --
|
|
-----------
|
|
|
|
--- @type Vec3f
|
|
gGlobalSoundSource = create_read_only_table({ x = 0, y = 0, z = 0 })
|
|
|
|
--- @param bank number
|
|
--- @param soundID number
|
|
--- @param priority number
|
|
--- @param flags number
|
|
--- @return number
|
|
function SOUND_ARG_LOAD(bank, soundID, priority, flags)
|
|
if flags == nil then flags = 0 end
|
|
return math.s32(
|
|
((bank << SOUNDARGS_SHIFT_BANK) & SOUNDARGS_MASK_BANK) |
|
|
((soundID << SOUNDARGS_SHIFT_SOUNDID) & SOUNDARGS_MASK_SOUNDID) |
|
|
((priority << SOUNDARGS_SHIFT_PRIORITY) & SOUNDARGS_MASK_PRIORITY) |
|
|
(flags & SOUNDARGS_MASK_BITFLAGS) |
|
|
SOUND_STATUS_WAITING
|
|
)
|
|
end
|
|
|
|
-------------
|
|
-- courses --
|
|
-------------
|
|
|
|
--- @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
|
|
COURSE_CAKE_END = 25
|
|
--- @type integer
|
|
COURSE_END = 26
|
|
--- @type integer
|
|
COURSE_MAX = 25
|
|
--- @type integer
|
|
COURSE_COUNT = 25
|
|
--- @type integer
|
|
COURSE_MIN = 1
|
|
|
|
|
|
------------------------------
|
|
-- player palette functions --
|
|
------------------------------
|
|
|
|
--- @param np NetworkPlayer
|
|
--- @param part PlayerPart
|
|
--- @return Color
|
|
--- Gets the palette color of `part` on `np`
|
|
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
|
|
--- Gets the override palette color of `part` on `np`
|
|
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
|
|
|
|
--------------------------
|
|
-- local math functions --
|
|
--------------------------
|
|
local __math_min, __math_max, __math_sqrt, __math_floor, __math_ceil, __math_cos, __math_sin, __math_pi = math.min, math.max, math.sqrt, math.floor, math.ceil, math.cos, math.sin, math.pi
|
|
|
|
------------
|
|
-- tweens --
|
|
------------
|
|
-- Unrelated to SM64, but these are for `math.tween`
|
|
|
|
---@param x number
|
|
---@return number
|
|
IN_SINE = function (x) return 1 - __math_cos((x * __math_pi) / 2) end
|
|
---@param x number
|
|
---@return number
|
|
OUT_SINE = function (x) return __math_sin((x * __math_pi) / 2) end
|
|
---@param x number
|
|
---@return number
|
|
IN_OUT_SINE = function (x) return -(__math_cos(__math_pi * x) - 1) / 2 end
|
|
---@param x number
|
|
---@return number
|
|
OUT_IN_SINE = function (x) return x < 0.5 and 0.5 * __math_sin(x * __math_pi) or 1 - 0.5 * __math_cos(((x * 2 - 1) * (__math_pi / 2))) end
|
|
---@param x number
|
|
---@return number
|
|
IN_QUAD = function (x) return x ^ 2 end
|
|
---@param x number
|
|
---@return number
|
|
OUT_QUAD = function (x) return 1 - ((1 - x) ^ 2) end
|
|
---@param x number
|
|
---@return number
|
|
IN_OUT_QUAD = function (x) return x < 0.5 and 2 * (x ^ 2) or 1 - ((-2 * x + 2) ^ 2) / 2 end
|
|
---@param x number
|
|
---@return number
|
|
OUT_IN_QUAD = function (x) return x < 0.5 and 0.5 * (-(2 * x) * ((2 * x) - 2)) or 0.5 + 0.5 * (2 * x - 1) ^ 2 end
|
|
---@param x number
|
|
---@return number
|
|
IN_CUBIC = function (x) return x ^ 3 end
|
|
---@param x number
|
|
---@return number
|
|
OUT_CUBIC = function (x) return 1 - ((1 - x) ^ 3) end
|
|
---@param x number
|
|
---@return number
|
|
IN_OUT_CUBIC = function (x) return x < 0.5 and 4 * (x ^ 3) or 1 - ((-2 * x + 2) ^ 3) / 2 end
|
|
---@param x number
|
|
---@return number
|
|
OUT_IN_CUBIC = function (x) return x < 0.5 and 0.5 * (((2 * x - 1) ^ 3) + 1) or 0.5 + 0.5 * (2 * x - 1) ^ 3 end
|
|
---@param x number
|
|
---@return number
|
|
IN_QUART = function (x) return x ^ 4 end
|
|
---@param x number
|
|
---@return number
|
|
OUT_QUART = function (x) return 1 - ((1 - x) ^ 4) end
|
|
---@param x number
|
|
---@return number
|
|
IN_OUT_QUART = function (x) return x < 0.5 and 8 * (x ^ 4) or 1 - ((-2 * x + 2) ^ 4) / 2 end
|
|
---@param x number
|
|
---@return number
|
|
OUT_IN_QUART = function (x) return x < 0.5 and 0.5 * (1 - ((2 * x - 1) ^ 4)) or 0.5 + 0.5 * (2 * x - 1) ^ 4 end
|
|
---@param x number
|
|
---@return number
|
|
IN_QUINT = function (x) return x ^ 5 end
|
|
---@param x number
|
|
---@return number
|
|
OUT_QUINT = function (x) return 1 - ((1 - x) ^ 5) end
|
|
---@param x number
|
|
---@return number
|
|
IN_OUT_QUINT = function (x) return x < 0.5 and 16 * (x ^ 5) or 1 - ((-2 * x + 2) ^ 5) / 2 end
|
|
---@param x number
|
|
---@return number
|
|
OUT_IN_QUINT = function (x) return x < 0.5 and 0.5 * (((2 * x - 1) ^ 5) + 1) or 0.5 + 0.5 * (2 * x - 1) ^ 5 end
|
|
---@param x number
|
|
---@return number
|
|
IN_EXPO = function (x) return x == 0 and x or 2 ^ (10 * x - 10) end
|
|
---@param x number
|
|
---@return number
|
|
OUT_EXPO = function (x) return x == 1 and x or 1 - (2 ^ (-10 * x)) end
|
|
---@param x number
|
|
---@return number
|
|
IN_OUT_EXPO = function (x) return (x == 0 or x == 1) and x or x < 0.5 and (2 ^ (20 * x - 10)) / 2 or (2 - (2 ^ (-20 * x + 10))) / 2 end
|
|
---@param x number
|
|
---@return number
|
|
OUT_IN_EXPO = function (x) return (x == 0 or x == 1) and x or x < 0.5 and 0.5 * (1 - 2 ^ (-20 * x)) or 0.5 + 0.5 * (2 ^ (20 * x - 20)) end
|
|
---@param x number
|
|
---@return number
|
|
IN_CIRC = function (x) return 1 - __math_sqrt(1 - (x ^ 2)) end
|
|
---@param x number
|
|
---@return number
|
|
OUT_CIRC = function (x) return __math_sqrt(1 - ((x - 1) ^ 2)) end
|
|
---@param x number
|
|
---@return number
|
|
IN_OUT_CIRC = function (x) return x < 0.5 and (1 - __math_sqrt(1 - ((2 * x) ^ 2))) / 2 or (__math_sqrt(1 - ((-2 * x + 2) ^ 2)) + 1) / 2 end
|
|
---@param x number
|
|
---@return number
|
|
OUT_IN_CIRC = function (x) return x < 0.5 and 0.5 * __math_sqrt(1 - (2 * x - 1) ^ 2) or 0.5 + 0.5 * (1 - __math_sqrt(1 - (2 * x - 1) ^ 2)) end
|
|
---@param x number
|
|
---@return number
|
|
IN_BACK = function (x) return (1.70158 + 1) * (x ^ 3) - 1.70158 * (x ^ 2) end
|
|
---@param x number
|
|
---@return number
|
|
OUT_BACK = function (x) return 1 + (1.70158 + 1) * ((x - 1) ^ 3) + 1.70158 * ((x - 1) ^ 2) end
|
|
---@param x number
|
|
---@return number
|
|
IN_OUT_BACK = function (x) return x < 0.5 and (((2 * x) ^ 2) * (((1.70158 * 1.525) + 1) * 2 * x - (1.70158 * 1.525))) / 2 or (((2 * x - 2) ^ 2) * (((1.70158 * 1.525) + 1) * (x * 2 - 2) + (1.70158 * 1.525)) + 2) / 2 end
|
|
---@param x number
|
|
---@return number
|
|
OUT_IN_BACK = function (x) return x < 0.5 and 0.5 * (1 + (1.70158 + 1) * ((2 * x) - 1) ^ 3 + 1.70158 * ((2 * x) - 1) ^ 2) or 0.5 + 0.5 * ((1.70158 + 1) * (2 * x - 1) ^ 3 - 1.70158 * (2 * x - 1) ^ 2) end
|
|
---@param x number
|
|
---@return number
|
|
IN_ELASTIC = function (x) return (x == 0 or x == 1) and x or -(2 ^ (10 * x - 10)) * __math_sin((x * 10 - 10.75) * ((2 * __math_pi) / 3)) end
|
|
---@param x number
|
|
---@return number
|
|
OUT_ELASTIC = function (x) return (x == 0 or x == 1) and x or (2 ^ (-10 * x)) * __math_sin((x * 10 - 0.75) * ((2 * __math_pi) / 3)) + 1 end
|
|
---@param x number
|
|
---@return number
|
|
IN_OUT_ELASTIC = function (x) return (x == 0 or x == 1) and x or (x < 0.5 and (-0.5 * (2 ^ (20 * x - 10)) * __math_sin((20 * x - 11.125) * ((2 * __math_pi) / 4.5)))) or (0.5 * (2 ^ (-20 * x + 10)) * __math_sin((20 * x - 11.125) * ((2 * __math_pi) / 4.5)) + 1) end
|
|
---@param x number
|
|
---@return number
|
|
OUT_IN_ELASTIC = function (x) return (x == 0 or x == 1) and x or (x < 0.5 and 0.5 * ((2 ^ (-10 * (x * 2))) * __math_sin(((x * 2) * 10 - 0.75) * ((2 * __math_pi) / 3)) + 1)) or 0.5 + 0.5 * (-(2 ^ (10 * ((x - 0.5) * 2) - 10)) * __math_sin((((x - 0.5) * 2) * 10 - 10.75) * ((2 * __math_pi) / 3))) end
|
|
---@param x number
|
|
---@return number
|
|
IN_BOUNCE = function (x) return 1 - OUT_BOUNCE(1 - x) end
|
|
---@param x number
|
|
---@return number
|
|
OUT_BOUNCE = function (x) if x < 1 / 2.75 then return 7.5625 * (x ^ 2) elseif x < 2 / 2.75 then x = x - 1.5 / 2.75 return 7.5625 * (x ^ 2) + 0.75 elseif x < 2.5 / 2.75 then x = x - 2.25 / 2.75 return 7.5625 * (x ^ 2) + 0.9375 else x = x - 2.625 / 2.75 return 7.5625 * (x ^ 2) + 0.984375 end end
|
|
---@param x number
|
|
---@return number
|
|
IN_OUT_BOUNCE = function (x) return x < 0.5 and (1 - OUT_BOUNCE(1 - 2 * x)) / 2 or (1 + OUT_BOUNCE(2 * x - 1)) / 2 end
|
|
---@param x number
|
|
---@return number
|
|
OUT_IN_BOUNCE = function (x) return x < 0.5 and 0.5 * OUT_BOUNCE(x * 2) or 0.5 + 0.5 * IN_BOUNCE(2 * x - 1) end
|
|
|
|
--- @alias EasingFunction
|
|
--- | `IN_SINE`
|
|
--- | `OUT_SINE`
|
|
--- | `IN_OUT_SINE`
|
|
--- | `OUT_IN_SINE`
|
|
--- | `IN_QUAD`
|
|
--- | `OUT_QUAD`
|
|
--- | `IN_OUT_QUAD`
|
|
--- | `OUT_IN_QUAD`
|
|
--- | `IN_CUBIC`
|
|
--- | `OUT_CUBIC`
|
|
--- | `IN_OUT_CUBIC`
|
|
--- | `OUT_IN_CUBIC`
|
|
--- | `IN_QUART`
|
|
--- | `OUT_QUART`
|
|
--- | `IN_OUT_QUART`
|
|
--- | `OUT_IN_QUART`
|
|
--- | `IN_QUINT`
|
|
--- | `OUT_QUINT`
|
|
--- | `IN_OUT_QUINT`
|
|
--- | `OUT_IN_QUINT`
|
|
--- | `IN_EXPO`
|
|
--- | `OUT_EXPO`
|
|
--- | `IN_OUT_EXPO`
|
|
--- | `OUT_IN_EXPO`
|
|
--- | `IN_CIRC`
|
|
--- | `OUT_CIRC`
|
|
--- | `IN_OUT_CIRC`
|
|
--- | `OUT_IN_CIRC`
|
|
--- | `IN_BACK`
|
|
--- | `OUT_BACK`
|
|
--- | `IN_OUT_BACK`
|
|
--- | `OUT_IN_BACK`
|
|
--- | `IN_ELASTIC`
|
|
--- | `OUT_ELASTIC`
|
|
--- | `IN_OUT_ELASTIC`
|
|
--- | `OUT_IN_ELASTIC`
|
|
--- | `IN_BOUNCE`
|
|
--- | `OUT_BOUNCE`
|
|
--- | `IN_OUT_BOUNCE`
|
|
--- | `OUT_IN_BOUNCE`
|
|
--- | fun(x: number): number
|
|
|
|
-------------------
|
|
-- sdl scancodes --
|
|
-------------------
|
|
|
|
--- @class SDL_Scancode:integer
|
|
--- @class SDL_GameControllerButton:integer
|
|
|
|
do -- SDL
|
|
-- Scancodes --
|
|
|
|
SDL_SCANCODE_UNKNOWN = 0 --- @type SDL_Scancode
|
|
SDL_SCANCODE_A = 4 --- @type SDL_Scancode
|
|
SDL_SCANCODE_B = 5 --- @type SDL_Scancode
|
|
SDL_SCANCODE_C = 6 --- @type SDL_Scancode
|
|
SDL_SCANCODE_D = 7 --- @type SDL_Scancode
|
|
SDL_SCANCODE_E = 8 --- @type SDL_Scancode
|
|
SDL_SCANCODE_F = 9 --- @type SDL_Scancode
|
|
SDL_SCANCODE_G = 10 --- @type SDL_Scancode
|
|
SDL_SCANCODE_H = 11 --- @type SDL_Scancode
|
|
SDL_SCANCODE_I = 12 --- @type SDL_Scancode
|
|
SDL_SCANCODE_J = 13 --- @type SDL_Scancode
|
|
SDL_SCANCODE_K = 14 --- @type SDL_Scancode
|
|
SDL_SCANCODE_L = 15 --- @type SDL_Scancode
|
|
SDL_SCANCODE_M = 16 --- @type SDL_Scancode
|
|
SDL_SCANCODE_N = 17 --- @type SDL_Scancode
|
|
SDL_SCANCODE_O = 18 --- @type SDL_Scancode
|
|
SDL_SCANCODE_P = 19 --- @type SDL_Scancode
|
|
SDL_SCANCODE_Q = 20 --- @type SDL_Scancode
|
|
SDL_SCANCODE_R = 21 --- @type SDL_Scancode
|
|
SDL_SCANCODE_S = 22 --- @type SDL_Scancode
|
|
SDL_SCANCODE_T = 23 --- @type SDL_Scancode
|
|
SDL_SCANCODE_U = 24 --- @type SDL_Scancode
|
|
SDL_SCANCODE_V = 25 --- @type SDL_Scancode
|
|
SDL_SCANCODE_W = 26 --- @type SDL_Scancode
|
|
SDL_SCANCODE_X = 27 --- @type SDL_Scancode
|
|
SDL_SCANCODE_Y = 28 --- @type SDL_Scancode
|
|
SDL_SCANCODE_Z = 29 --- @type SDL_Scancode
|
|
SDL_SCANCODE_1 = 30 --- @type SDL_Scancode
|
|
SDL_SCANCODE_2 = 31 --- @type SDL_Scancode
|
|
SDL_SCANCODE_3 = 32 --- @type SDL_Scancode
|
|
SDL_SCANCODE_4 = 33 --- @type SDL_Scancode
|
|
SDL_SCANCODE_5 = 34 --- @type SDL_Scancode
|
|
SDL_SCANCODE_6 = 35 --- @type SDL_Scancode
|
|
SDL_SCANCODE_7 = 36 --- @type SDL_Scancode
|
|
SDL_SCANCODE_8 = 37 --- @type SDL_Scancode
|
|
SDL_SCANCODE_9 = 38 --- @type SDL_Scancode
|
|
SDL_SCANCODE_0 = 39 --- @type SDL_Scancode
|
|
SDL_SCANCODE_RETURN = 40 --- @type SDL_Scancode
|
|
SDL_SCANCODE_ESCAPE = 41 --- @type SDL_Scancode
|
|
SDL_SCANCODE_BACKSPACE = 42 --- @type SDL_Scancode
|
|
SDL_SCANCODE_TAB = 43 --- @type SDL_Scancode
|
|
SDL_SCANCODE_SPACE = 44 --- @type SDL_Scancode
|
|
SDL_SCANCODE_MINUS = 45 --- @type SDL_Scancode
|
|
SDL_SCANCODE_EQUALS = 46 --- @type SDL_Scancode
|
|
SDL_SCANCODE_LEFTBRACKET = 47 --- @type SDL_Scancode
|
|
SDL_SCANCODE_RIGHTBRACKET = 48 --- @type SDL_Scancode
|
|
SDL_SCANCODE_BACKSLASH = 49 --- @type SDL_Scancode
|
|
SDL_SCANCODE_NONUSHASH = 50 --- @type SDL_Scancode
|
|
SDL_SCANCODE_SEMICOLON = 51 --- @type SDL_Scancode
|
|
SDL_SCANCODE_APOSTROPHE = 52 --- @type SDL_Scancode
|
|
SDL_SCANCODE_GRAVE = 53 --- @type SDL_Scancode
|
|
SDL_SCANCODE_COMMA = 54 --- @type SDL_Scancode
|
|
SDL_SCANCODE_PERIOD = 55 --- @type SDL_Scancode
|
|
SDL_SCANCODE_SLASH = 56 --- @type SDL_Scancode
|
|
SDL_SCANCODE_CAPSLOCK = 57 --- @type SDL_Scancode
|
|
SDL_SCANCODE_F1 = 58 --- @type SDL_Scancode
|
|
SDL_SCANCODE_F2 = 59 --- @type SDL_Scancode
|
|
SDL_SCANCODE_F3 = 60 --- @type SDL_Scancode
|
|
SDL_SCANCODE_F4 = 61 --- @type SDL_Scancode
|
|
SDL_SCANCODE_F5 = 62 --- @type SDL_Scancode
|
|
SDL_SCANCODE_F6 = 63 --- @type SDL_Scancode
|
|
SDL_SCANCODE_F7 = 64 --- @type SDL_Scancode
|
|
SDL_SCANCODE_F8 = 65 --- @type SDL_Scancode
|
|
SDL_SCANCODE_F9 = 66 --- @type SDL_Scancode
|
|
SDL_SCANCODE_F10 = 67 --- @type SDL_Scancode
|
|
SDL_SCANCODE_F11 = 68 --- @type SDL_Scancode
|
|
SDL_SCANCODE_F12 = 69 --- @type SDL_Scancode
|
|
SDL_SCANCODE_PRINTSCREEN = 70 --- @type SDL_Scancode
|
|
SDL_SCANCODE_SCROLLLOCK = 71 --- @type SDL_Scancode
|
|
SDL_SCANCODE_PAUSE = 72 --- @type SDL_Scancode
|
|
SDL_SCANCODE_INSERT = 73 --- @type SDL_Scancode
|
|
SDL_SCANCODE_HOME = 74 --- @type SDL_Scancode
|
|
SDL_SCANCODE_PAGEUP = 75 --- @type SDL_Scancode
|
|
SDL_SCANCODE_DELETE = 76 --- @type SDL_Scancode
|
|
SDL_SCANCODE_END = 77 --- @type SDL_Scancode
|
|
SDL_SCANCODE_PAGEDOWN = 78 --- @type SDL_Scancode
|
|
SDL_SCANCODE_RIGHT = 79 --- @type SDL_Scancode
|
|
SDL_SCANCODE_LEFT = 80 --- @type SDL_Scancode
|
|
SDL_SCANCODE_DOWN = 81 --- @type SDL_Scancode
|
|
SDL_SCANCODE_UP = 82 --- @type SDL_Scancode
|
|
SDL_SCANCODE_NUMLOCKCLEAR = 83 --- @type SDL_Scancode
|
|
SDL_SCANCODE_KP_DIVIDE = 84 --- @type SDL_Scancode
|
|
SDL_SCANCODE_KP_MULTIPLY = 85 --- @type SDL_Scancode
|
|
SDL_SCANCODE_KP_MINUS = 86 --- @type SDL_Scancode
|
|
SDL_SCANCODE_KP_PLUS = 87 --- @type SDL_Scancode
|
|
SDL_SCANCODE_KP_ENTER = 88 --- @type SDL_Scancode
|
|
SDL_SCANCODE_KP_1 = 89 --- @type SDL_Scancode
|
|
SDL_SCANCODE_KP_2 = 90 --- @type SDL_Scancode
|
|
SDL_SCANCODE_KP_3 = 91 --- @type SDL_Scancode
|
|
SDL_SCANCODE_KP_4 = 92 --- @type SDL_Scancode
|
|
SDL_SCANCODE_KP_5 = 93 --- @type SDL_Scancode
|
|
SDL_SCANCODE_KP_6 = 94 --- @type SDL_Scancode
|
|
SDL_SCANCODE_KP_7 = 95 --- @type SDL_Scancode
|
|
SDL_SCANCODE_KP_8 = 96 --- @type SDL_Scancode
|
|
SDL_SCANCODE_KP_9 = 97 --- @type SDL_Scancode
|
|
SDL_SCANCODE_KP_0 = 98 --- @type SDL_Scancode
|
|
SDL_SCANCODE_KP_PERIOD = 99 --- @type SDL_Scancode
|
|
SDL_SCANCODE_NONUSBACKSLASH = 100 --- @type SDL_Scancode
|
|
SDL_SCANCODE_APPLICATION = 101 --- @type SDL_Scancode
|
|
SDL_SCANCODE_POWER = 102 --- @type SDL_Scancode
|
|
SDL_SCANCODE_KP_EQUALS = 103 --- @type SDL_Scancode
|
|
SDL_SCANCODE_F13 = 104 --- @type SDL_Scancode
|
|
SDL_SCANCODE_F14 = 105 --- @type SDL_Scancode
|
|
SDL_SCANCODE_F15 = 106 --- @type SDL_Scancode
|
|
SDL_SCANCODE_F16 = 107 --- @type SDL_Scancode
|
|
SDL_SCANCODE_F17 = 108 --- @type SDL_Scancode
|
|
SDL_SCANCODE_F18 = 109 --- @type SDL_Scancode
|
|
SDL_SCANCODE_F19 = 110 --- @type SDL_Scancode
|
|
SDL_SCANCODE_F20 = 111 --- @type SDL_Scancode
|
|
SDL_SCANCODE_F21 = 112 --- @type SDL_Scancode
|
|
SDL_SCANCODE_F22 = 113 --- @type SDL_Scancode
|
|
SDL_SCANCODE_F23 = 114 --- @type SDL_Scancode
|
|
SDL_SCANCODE_F24 = 115 --- @type SDL_Scancode
|
|
SDL_SCANCODE_EXECUTE = 116 --- @type SDL_Scancode
|
|
SDL_SCANCODE_HELP = 117 --- @type SDL_Scancode
|
|
SDL_SCANCODE_MENU = 118 --- @type SDL_Scancode
|
|
SDL_SCANCODE_SELECT = 119 --- @type SDL_Scancode
|
|
SDL_SCANCODE_STOP = 120 --- @type SDL_Scancode
|
|
SDL_SCANCODE_AGAIN = 121 --- @type SDL_Scancode
|
|
SDL_SCANCODE_UNDO = 122 --- @type SDL_Scancode
|
|
SDL_SCANCODE_CUT = 123 --- @type SDL_Scancode
|
|
SDL_SCANCODE_COPY = 124 --- @type SDL_Scancode
|
|
SDL_SCANCODE_PASTE = 125 --- @type SDL_Scancode
|
|
SDL_SCANCODE_FIND = 126 --- @type SDL_Scancode
|
|
SDL_SCANCODE_MUTE = 127 --- @type SDL_Scancode
|
|
SDL_SCANCODE_VOLUMEUP = 128 --- @type SDL_Scancode
|
|
SDL_SCANCODE_VOLUMEDOWN = 129 --- @type SDL_Scancode
|
|
SDL_SCANCODE_LOCKINGCAPSLOCK = 130 --- @type SDL_Scancode
|
|
SDL_SCANCODE_LOCKINGNUMLOCK = 131 --- @type SDL_Scancode
|
|
SDL_SCANCODE_LOCKINGSCROLLLOCK = 132 --- @type SDL_Scancode
|
|
SDL_SCANCODE_KP_COMMA = 133 --- @type SDL_Scancode
|
|
SDL_SCANCODE_KP_EQUALSAS400 = 134 --- @type SDL_Scancode
|
|
SDL_SCANCODE_INTERNATIONAL1 = 135 --- @type SDL_Scancode
|
|
SDL_SCANCODE_INTERNATIONAL2 = 136 --- @type SDL_Scancode
|
|
SDL_SCANCODE_INTERNATIONAL3 = 137 --- @type SDL_Scancode
|
|
SDL_SCANCODE_INTERNATIONAL4 = 138 --- @type SDL_Scancode
|
|
SDL_SCANCODE_INTERNATIONAL5 = 139 --- @type SDL_Scancode
|
|
SDL_SCANCODE_INTERNATIONAL6 = 140 --- @type SDL_Scancode
|
|
SDL_SCANCODE_INTERNATIONAL7 = 141 --- @type SDL_Scancode
|
|
SDL_SCANCODE_INTERNATIONAL8 = 142 --- @type SDL_Scancode
|
|
SDL_SCANCODE_INTERNATIONAL9 = 143 --- @type SDL_Scancode
|
|
SDL_SCANCODE_LANG1 = 144 --- @type SDL_Scancode
|
|
SDL_SCANCODE_LANG2 = 145 --- @type SDL_Scancode
|
|
SDL_SCANCODE_LANG3 = 146 --- @type SDL_Scancode
|
|
SDL_SCANCODE_LANG4 = 147 --- @type SDL_Scancode
|
|
SDL_SCANCODE_LANG5 = 148 --- @type SDL_Scancode
|
|
SDL_SCANCODE_LANG6 = 149 --- @type SDL_Scancode
|
|
SDL_SCANCODE_LANG7 = 150 --- @type SDL_Scancode
|
|
SDL_SCANCODE_LANG8 = 151 --- @type SDL_Scancode
|
|
SDL_SCANCODE_LANG9 = 152 --- @type SDL_Scancode
|
|
SDL_SCANCODE_ALTERASE = 153 --- @type SDL_Scancode
|
|
SDL_SCANCODE_SYSREQ = 154 --- @type SDL_Scancode
|
|
SDL_SCANCODE_CANCEL = 155 --- @type SDL_Scancode
|
|
SDL_SCANCODE_CLEAR = 156 --- @type SDL_Scancode
|
|
SDL_SCANCODE_PRIOR = 157 --- @type SDL_Scancode
|
|
SDL_SCANCODE_RETURN2 = 158 --- @type SDL_Scancode
|
|
SDL_SCANCODE_SEPARATOR = 159 --- @type SDL_Scancode
|
|
SDL_SCANCODE_OUT = 160 --- @type SDL_Scancode
|
|
SDL_SCANCODE_OPER = 161 --- @type SDL_Scancode
|
|
SDL_SCANCODE_CLEARAGAIN = 162 --- @type SDL_Scancode
|
|
SDL_SCANCODE_CRSEL = 163 --- @type SDL_Scancode
|
|
SDL_SCANCODE_EXSEL = 164 --- @type SDL_Scancode
|
|
SDL_SCANCODE_KP_00 = 176 --- @type SDL_Scancode
|
|
SDL_SCANCODE_KP_000 = 177 --- @type SDL_Scancode
|
|
SDL_SCANCODE_THOUSANDSSEPARATOR = 178 --- @type SDL_Scancode
|
|
SDL_SCANCODE_DECIMALSEPARATOR = 179 --- @type SDL_Scancode
|
|
SDL_SCANCODE_CURRENCYUNIT = 180 --- @type SDL_Scancode
|
|
SDL_SCANCODE_CURRENCYSUBUNIT = 181 --- @type SDL_Scancode
|
|
SDL_SCANCODE_KP_LEFTPAREN = 182 --- @type SDL_Scancode
|
|
SDL_SCANCODE_KP_RIGHTPAREN = 183 --- @type SDL_Scancode
|
|
SDL_SCANCODE_KP_LEFTBRACE = 184 --- @type SDL_Scancode
|
|
SDL_SCANCODE_KP_RIGHTBRACE = 185 --- @type SDL_Scancode
|
|
SDL_SCANCODE_KP_TAB = 186 --- @type SDL_Scancode
|
|
SDL_SCANCODE_KP_BACKSPACE = 187 --- @type SDL_Scancode
|
|
SDL_SCANCODE_KP_A = 188 --- @type SDL_Scancode
|
|
SDL_SCANCODE_KP_B = 189 --- @type SDL_Scancode
|
|
SDL_SCANCODE_KP_C = 190 --- @type SDL_Scancode
|
|
SDL_SCANCODE_KP_D = 191 --- @type SDL_Scancode
|
|
SDL_SCANCODE_KP_E = 192 --- @type SDL_Scancode
|
|
SDL_SCANCODE_KP_F = 193 --- @type SDL_Scancode
|
|
SDL_SCANCODE_KP_XOR = 194 --- @type SDL_Scancode
|
|
SDL_SCANCODE_KP_POWER = 195 --- @type SDL_Scancode
|
|
SDL_SCANCODE_KP_PERCENT = 196 --- @type SDL_Scancode
|
|
SDL_SCANCODE_KP_LESS = 197 --- @type SDL_Scancode
|
|
SDL_SCANCODE_KP_GREATER = 198 --- @type SDL_Scancode
|
|
SDL_SCANCODE_KP_AMPERSAND = 199 --- @type SDL_Scancode
|
|
SDL_SCANCODE_KP_DBLAMPERSAND = 200 --- @type SDL_Scancode
|
|
SDL_SCANCODE_KP_VERTICALBAR = 201 --- @type SDL_Scancode
|
|
SDL_SCANCODE_KP_DBLVERTICALBAR = 202 --- @type SDL_Scancode
|
|
SDL_SCANCODE_KP_COLON = 203 --- @type SDL_Scancode
|
|
SDL_SCANCODE_KP_HASH = 204 --- @type SDL_Scancode
|
|
SDL_SCANCODE_KP_SPACE = 205 --- @type SDL_Scancode
|
|
SDL_SCANCODE_KP_AT = 206 --- @type SDL_Scancode
|
|
SDL_SCANCODE_KP_EXCLAM = 207 --- @type SDL_Scancode
|
|
SDL_SCANCODE_KP_MEMSTORE = 208 --- @type SDL_Scancode
|
|
SDL_SCANCODE_KP_MEMRECALL = 209 --- @type SDL_Scancode
|
|
SDL_SCANCODE_KP_MEMCLEAR = 210 --- @type SDL_Scancode
|
|
SDL_SCANCODE_KP_MEMADD = 211 --- @type SDL_Scancode
|
|
SDL_SCANCODE_KP_MEMSUBTRACT = 212 --- @type SDL_Scancode
|
|
SDL_SCANCODE_KP_MEMMULTIPLY = 213 --- @type SDL_Scancode
|
|
SDL_SCANCODE_KP_MEMDIVIDE = 214 --- @type SDL_Scancode
|
|
SDL_SCANCODE_KP_PLUSMINUS = 215 --- @type SDL_Scancode
|
|
SDL_SCANCODE_KP_CLEAR = 216 --- @type SDL_Scancode
|
|
SDL_SCANCODE_KP_CLEARENTRY = 217 --- @type SDL_Scancode
|
|
SDL_SCANCODE_KP_BINARY = 218 --- @type SDL_Scancode
|
|
SDL_SCANCODE_KP_OCTAL = 219 --- @type SDL_Scancode
|
|
SDL_SCANCODE_KP_DECIMAL = 220 --- @type SDL_Scancode
|
|
SDL_SCANCODE_KP_HEXADECIMAL = 221 --- @type SDL_Scancode
|
|
SDL_SCANCODE_LCTRL = 224 --- @type SDL_Scancode
|
|
SDL_SCANCODE_LSHIFT = 225 --- @type SDL_Scancode
|
|
SDL_SCANCODE_LALT = 226 --- @type SDL_Scancode
|
|
SDL_SCANCODE_LGUI = 227 --- @type SDL_Scancode
|
|
SDL_SCANCODE_RCTRL = 228 --- @type SDL_Scancode
|
|
SDL_SCANCODE_RSHIFT = 229 --- @type SDL_Scancode
|
|
SDL_SCANCODE_RALT = 230 --- @type SDL_Scancode
|
|
SDL_SCANCODE_RGUI = 231 --- @type SDL_Scancode
|
|
SDL_SCANCODE_MODE = 257 --- @type SDL_Scancode
|
|
SDL_SCANCODE_AUDIONEXT = 258 --- @type SDL_Scancode
|
|
SDL_SCANCODE_AUDIOPREV = 259 --- @type SDL_Scancode
|
|
SDL_SCANCODE_AUDIOSTOP = 260 --- @type SDL_Scancode
|
|
SDL_SCANCODE_AUDIOPLAY = 261 --- @type SDL_Scancode
|
|
SDL_SCANCODE_AUDIOMUTE = 262 --- @type SDL_Scancode
|
|
SDL_SCANCODE_MEDIASELECT = 263 --- @type SDL_Scancode
|
|
SDL_SCANCODE_WWW = 264 --- @type SDL_Scancode
|
|
SDL_SCANCODE_MAIL = 265 --- @type SDL_Scancode
|
|
SDL_SCANCODE_CALCULATOR = 266 --- @type SDL_Scancode
|
|
SDL_SCANCODE_COMPUTER = 267 --- @type SDL_Scancode
|
|
SDL_SCANCODE_AC_SEARCH = 268 --- @type SDL_Scancode
|
|
SDL_SCANCODE_AC_HOME = 269 --- @type SDL_Scancode
|
|
SDL_SCANCODE_AC_BACK = 270 --- @type SDL_Scancode
|
|
SDL_SCANCODE_AC_FORWARD = 271 --- @type SDL_Scancode
|
|
SDL_SCANCODE_AC_STOP = 272 --- @type SDL_Scancode
|
|
SDL_SCANCODE_AC_REFRESH = 273 --- @type SDL_Scancode
|
|
SDL_SCANCODE_AC_BOOKMARKS = 274 --- @type SDL_Scancode
|
|
SDL_SCANCODE_BRIGHTNESSDOWN = 275 --- @type SDL_Scancode
|
|
SDL_SCANCODE_BRIGHTNESSUP = 276 --- @type SDL_Scancode
|
|
SDL_SCANCODE_DISPLAYSWITCH = 277 --- @type SDL_Scancode
|
|
SDL_SCANCODE_KBDILLUMTOGGLE = 278 --- @type SDL_Scancode
|
|
SDL_SCANCODE_KBDILLUMDOWN = 279 --- @type SDL_Scancode
|
|
SDL_SCANCODE_KBDILLUMUP = 280 --- @type SDL_Scancode
|
|
SDL_SCANCODE_EJECT = 281 --- @type SDL_Scancode
|
|
SDL_SCANCODE_SLEEP = 282 --- @type SDL_Scancode
|
|
SDL_SCANCODE_APP1 = 283 --- @type SDL_Scancode
|
|
SDL_SCANCODE_APP2 = 284 --- @type SDL_Scancode
|
|
SDL_SCANCODE_AUDIOREWIND = 285 --- @type SDL_Scancode
|
|
SDL_SCANCODE_AUDIOFASTFORWARD = 286 --- @type SDL_Scancode
|
|
SDL_SCANCODE_SOFTLEFT = 287 --- @type SDL_Scancode
|
|
SDL_SCANCODE_SOFTRIGHT = 288 --- @type SDL_Scancode
|
|
SDL_SCANCODE_CALL = 289 --- @type SDL_Scancode
|
|
SDL_SCANCODE_ENDCALL = 290 --- @type SDL_Scancode
|
|
SDL_NUM_SCANCODES = 512 --- @type SDL_Scancode
|
|
|
|
-- Controller --
|
|
|
|
SDL_CONTROLLER_BUTTON_A = 1 --- @type SDL_GameControllerButton
|
|
SDL_CONTROLLER_BUTTON_B = 2 --- @type SDL_GameControllerButton
|
|
SDL_CONTROLLER_BUTTON_X = 3 --- @type SDL_GameControllerButton
|
|
SDL_CONTROLLER_BUTTON_Y = 4 --- @type SDL_GameControllerButton
|
|
SDL_CONTROLLER_BUTTON_BACK = 5 --- @type SDL_GameControllerButton
|
|
SDL_CONTROLLER_BUTTON_GUIDE = 6 --- @type SDL_GameControllerButton
|
|
SDL_CONTROLLER_BUTTON_START = 7 --- @type SDL_GameControllerButton
|
|
SDL_CONTROLLER_BUTTON_LEFTSTICK = 8 --- @type SDL_GameControllerButton
|
|
SDL_CONTROLLER_BUTTON_RIGHTSTICK = 9 --- @type SDL_GameControllerButton
|
|
SDL_CONTROLLER_BUTTON_LEFTSHOULDER = 10 --- @type SDL_GameControllerButton
|
|
SDL_CONTROLLER_BUTTON_RIGHTSHOULDER = 11 --- @type SDL_GameControllerButton
|
|
SDL_CONTROLLER_BUTTON_DPAD_UP = 12 --- @type SDL_GameControllerButton
|
|
SDL_CONTROLLER_BUTTON_DPAD_DOWN = 13 --- @type SDL_GameControllerButton
|
|
SDL_CONTROLLER_BUTTON_DPAD_LEFT = 14 --- @type SDL_GameControllerButton
|
|
SDL_CONTROLLER_BUTTON_DPAD_RIGHT = 15 --- @type SDL_GameControllerButton
|
|
SDL_CONTROLLER_BUTTON_MISC1 = 16 --- @type SDL_GameControllerButton
|
|
SDL_CONTROLLER_BUTTON_PADDLE1 = 17 --- @type SDL_GameControllerButton
|
|
SDL_CONTROLLER_BUTTON_PADDLE2 = 18 --- @type SDL_GameControllerButton
|
|
SDL_CONTROLLER_BUTTON_PADDLE3 = 19 --- @type SDL_GameControllerButton
|
|
SDL_CONTROLLER_BUTTON_PADDLE4 = 20 --- @type SDL_GameControllerButton
|
|
SDL_CONTROLLER_BUTTON_TOUCHPAD = 21 --- @type SDL_GameControllerButton
|
|
SDL_CONTROLLER_BUTTON_MAX = 22 --- @type SDL_GameControllerButton
|
|
end
|
|
|
|
--------------------
|
|
-- math functions --
|
|
--------------------
|
|
--- Note: These functions don't exist in the Lua math library,
|
|
--- and are useful enough to not have to redefine them in every mod
|
|
|
|
--- @param x number
|
|
--- @return number
|
|
--- Computes the square of the number `x`
|
|
function math.sqr(x)
|
|
return x * x
|
|
end
|
|
|
|
--- @param x number
|
|
--- @param a number
|
|
--- @param b number
|
|
--- @return number
|
|
--- Clamps the number `x` between bounds `a` (minimum) and `b` (maximum)
|
|
function math.clamp(x, a, b)
|
|
return __math_min(__math_max(x, a), b)
|
|
end
|
|
|
|
--- @param a number
|
|
--- @param b number
|
|
--- @return number
|
|
--- Computes the hypotenuse of a right-angled triangle given sides `a` and `b` using the Pythagorean theorem
|
|
function math.hypot(a, b)
|
|
return __math_sqrt(a * a + b * b)
|
|
end
|
|
|
|
--- @param x number
|
|
--- @return number
|
|
--- Returns 1 if `x` is positive or zero, -1 otherwise
|
|
function math.sign(x)
|
|
return x >= 0 and 1 or -1
|
|
end
|
|
|
|
--- @param x number
|
|
--- @return number
|
|
--- Returns 1 if `x` is positive, 0 if it is zero, -1 otherwise
|
|
function math.sign0(x)
|
|
return x ~= 0 and (x > 0 and 1 or -1) or 0
|
|
end
|
|
|
|
--- @param a number
|
|
--- @param b number
|
|
--- @param t number
|
|
--- @return number
|
|
--- Linearly interpolates between `a` and `b` using delta `t`
|
|
function math.lerp(a, b, t)
|
|
return a + (b - a) * t
|
|
end
|
|
|
|
--- @param a number
|
|
--- @param b number
|
|
--- @param x number
|
|
--- @return number
|
|
--- Determines where `x` linearly lies between `a` and `b`. It's the inverse of `math.lerp`
|
|
function math.invlerp(a, b, x)
|
|
return (x - a) / (b - a)
|
|
end
|
|
|
|
--- @param a number
|
|
--- @param b number
|
|
--- @param c number
|
|
--- @param d number
|
|
--- @param x number
|
|
--- @return number
|
|
--- Linearly remaps `x` from the source range `[a, b]` to the destination range `[c, d]`
|
|
function math.remap(a, b, c, d, x)
|
|
return c + (d - c) * ((x - a) / (b - a))
|
|
end
|
|
|
|
--- @param x number
|
|
--- Rounds `x` to the nearest integer value
|
|
function math.round(x)
|
|
return x > 0 and __math_floor(x + 0.5) or __math_ceil(x - 0.5)
|
|
end
|
|
|
|
--- @param t EasingFunction | number
|
|
--- @param a number
|
|
--- @param b number
|
|
--- @param x number
|
|
--- @return number
|
|
--- Interpolates between `a` and `b` using delta `x` and a tweening or easing math function `t`
|
|
function math.tween(t, a, b, x)
|
|
local y
|
|
|
|
if type(t) == 'function' then
|
|
y = a + t(x) * (b - a)
|
|
else
|
|
y = a + t * (b - a)
|
|
end
|
|
|
|
return y
|
|
end
|
|
|
|
local __common_signed_conversion = function (x, size)
|
|
x = __math_floor(x) & (1 << size) - 1
|
|
return x - ((x & (1 << (size - 1))) << 1)
|
|
end
|
|
|
|
local __common_unsigned_conversion = function (x, size)
|
|
return __math_floor(x) & (1 << size) - 1
|
|
end
|
|
|
|
--- @param x number
|
|
--- @return integer
|
|
--- Converts `x` into a valid `s8` range
|
|
--- - `[-128, 127]`
|
|
function math.s8(x)
|
|
return __common_signed_conversion(x, 8)
|
|
end
|
|
--- @param x number
|
|
--- @return integer
|
|
--- Converts `x` into a valid `s16` range
|
|
--- - `[-32768, 32767]`
|
|
function math.s16(x)
|
|
return __common_signed_conversion(x, 16)
|
|
end
|
|
--- @param x number
|
|
--- @return integer
|
|
--- Converts `x` into a valid `s32` range
|
|
--- - `[-2147483648, 2147483647]`
|
|
function math.s32(x)
|
|
return __common_signed_conversion(x, 32)
|
|
end
|
|
--- @param x number
|
|
--- @return integer
|
|
--- Converts `x` into a valid `u8` range
|
|
--- - `[0, 255]`
|
|
function math.u8(x)
|
|
return __common_unsigned_conversion(x, 8)
|
|
end
|
|
--- @param x number
|
|
--- @return integer
|
|
--- Converts `x` into a valid `u16` range
|
|
--- - `[0, 65535]`
|
|
function math.u16(x)
|
|
return __common_unsigned_conversion(x, 16)
|
|
end
|
|
--- @param x number
|
|
--- @return integer
|
|
--- Converts `x` into a valid `u32` range
|
|
--- - `[0, 4294967295]`
|
|
function math.u32(x)
|
|
return __common_unsigned_conversion(x, 32)
|
|
end
|