forked from sharpobject/panel-attack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcharacter_loader.lua
More file actions
56 lines (47 loc) · 1.6 KB
/
character_loader.lua
File metadata and controls
56 lines (47 loc) · 1.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
require("queue")
require("globals")
local loading_queue = Queue()
local loading_character = nil
function character_loader_load(character_id)
if characters[character_id] and not characters[character_id].fully_loaded then
loading_queue:push(character_id)
end
end
local instant_load_enabled = false
-- return true if there is still data to load
function character_loader_update()
if not loading_character and loading_queue:len() > 0 then
local character_name = loading_queue:pop()
loading_character = { character_name, coroutine.create( function()
characters[character_name]:load(instant_load_enabled)
end) }
end
if loading_character then
if coroutine.status(loading_character[2]) == "suspended" then
coroutine.resume(loading_character[2])
return true
elseif coroutine.status(loading_character[2]) == "dead" then
loading_character = nil
return loading_queue:len() > 0
-- TODO: unload characters if too much data have been loaded (be careful not to release currently-used characters)
end
end
return false
end
function character_loader_wait()
instant_load_enabled = true
while true do
if not character_loader_update() then
break
end
end
instant_load_enabled = false
end
function character_loader_clear()
local p2_local_character = global_op_state and global_op_state.character or nil
for character_id,character in pairs(characters) do
if character.fully_loaded and character_id ~= default_character_id and character_id ~= config.character and character_id ~= p2_local_character then
character:unload()
end
end
end