split code a lil better
This commit is contained in:
parent
3ceba9bafc
commit
e8cb599dde
3
main.xml
3
main.xml
|
@ -83,6 +83,9 @@
|
||||||
|
|
||||||
require 'uranium.main'
|
require 'uranium.main'
|
||||||
|
|
||||||
|
-- Needed by StepMania, in order to not kill lua mods early
|
||||||
|
self:sleep(9e9)
|
||||||
|
|
||||||
-- NotITG and OpenITG have a long standing bug where the InitCommand on an actor can run twice in certain cases.
|
-- NotITG and OpenITG have a long standing bug where the InitCommand on an actor can run twice in certain cases.
|
||||||
-- By removing the command after it's done, it can only ever run once
|
-- By removing the command after it's done, it can only ever run once
|
||||||
self:removecommand('Init')
|
self:removecommand('Init')
|
||||||
|
|
|
@ -579,4 +579,23 @@ function M._transformQueueToTree()
|
||||||
M._actorTree = tree
|
M._actorTree = tree
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function M.prepareForActors()
|
||||||
|
M._actorsInitializing = true
|
||||||
|
M._transformQueueToTree()
|
||||||
|
--Trace(fullDump(M._actorTree))
|
||||||
|
M._currentPath = M._actorTree
|
||||||
|
end
|
||||||
|
|
||||||
|
function M.finalize()
|
||||||
|
oat._actor = nil
|
||||||
|
|
||||||
|
M._actorQueue = nil
|
||||||
|
M._actorAssociationQueue = nil
|
||||||
|
|
||||||
|
M._actorTree = nil
|
||||||
|
M._currentPath = nil
|
||||||
|
M._pastPaths = nil
|
||||||
|
M._currentActor = nil
|
||||||
|
end
|
||||||
|
|
||||||
return M
|
return M
|
|
@ -0,0 +1,33 @@
|
||||||
|
-- indexing things on _G is slower than
|
||||||
|
-- having access to them in a local `oat` table
|
||||||
|
-- that already acts as _G, so we move commonly
|
||||||
|
-- use values over
|
||||||
|
|
||||||
|
local function copy(src)
|
||||||
|
local dest = {}
|
||||||
|
for k, v in pairs(src) do
|
||||||
|
dest[k] = v
|
||||||
|
end
|
||||||
|
return dest
|
||||||
|
end
|
||||||
|
|
||||||
|
oat = _G.oat
|
||||||
|
type = _G.type
|
||||||
|
print = _G.print
|
||||||
|
pairs = _G.pairs
|
||||||
|
ipairs = _G.ipairs
|
||||||
|
unpack = _G.unpack
|
||||||
|
tonumber = _G.tonumber
|
||||||
|
tostring = _G.tostring
|
||||||
|
math = copy(_G.math)
|
||||||
|
table = copy(_G.table)
|
||||||
|
string = copy(_G.string)
|
||||||
|
|
||||||
|
-- convinience shortcuts employed by most templates
|
||||||
|
|
||||||
|
scx = SCREEN_CENTER_X
|
||||||
|
scy = SCREEN_CENTER_Y
|
||||||
|
sw = SCREEN_WIDTH
|
||||||
|
sh = SCREEN_HEIGHT
|
||||||
|
dw = DISPLAY:GetDisplayWidth()
|
||||||
|
dh = DISPLAY:GetDisplayHeight()
|
|
@ -1,35 +1,10 @@
|
||||||
local function copy(src)
|
require 'uranium.constants'
|
||||||
local dest = {}
|
require 'uranium.events'
|
||||||
for k, v in pairs(src) do
|
local actors = require 'uranium.actors'
|
||||||
dest[k] = v
|
|
||||||
end
|
|
||||||
return dest
|
|
||||||
end
|
|
||||||
|
|
||||||
oat = _G.oat
|
|
||||||
type = _G.type
|
|
||||||
print = _G.print
|
|
||||||
pairs = _G.pairs
|
|
||||||
ipairs = _G.ipairs
|
|
||||||
unpack = _G.unpack
|
|
||||||
tonumber = _G.tonumber
|
|
||||||
tostring = _G.tostring
|
|
||||||
math = copy(_G.math)
|
|
||||||
table = copy(_G.table)
|
|
||||||
string = copy(_G.string)
|
|
||||||
|
|
||||||
scx = SCREEN_CENTER_X
|
|
||||||
scy = SCREEN_CENTER_Y
|
|
||||||
sw = SCREEN_WIDTH
|
|
||||||
sh = SCREEN_HEIGHT
|
|
||||||
dw = DISPLAY:GetDisplayWidth()
|
|
||||||
dh = DISPLAY:GetDisplayHeight()
|
|
||||||
|
|
||||||
local resetOnFrameStartCfg = false
|
local resetOnFrameStartCfg = false
|
||||||
local resetOnFrameStartActors = {}
|
local resetOnFrameStartActors = {}
|
||||||
|
|
||||||
require 'uranium.events'
|
|
||||||
|
|
||||||
local hasExited = false
|
local hasExited = false
|
||||||
local function exit()
|
local function exit()
|
||||||
if hasExited then return end
|
if hasExited then return end
|
||||||
|
@ -56,8 +31,8 @@ function backToSongWheel(message)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function onCommand(self)
|
local function onCommand(self)
|
||||||
uranium.actors._actorsInitialized = true
|
actors._actorsInitialized = true
|
||||||
uranium.actors._actorsInitializing = false
|
actors._actorsInitializing = false
|
||||||
local resetOnFrameStartActors_ = {}
|
local resetOnFrameStartActors_ = {}
|
||||||
for k,v in pairs(resetOnFrameStartActors) do
|
for k,v in pairs(resetOnFrameStartActors) do
|
||||||
resetOnFrameStartActors_[k.__raw] = v
|
resetOnFrameStartActors_[k.__raw] = v
|
||||||
|
@ -100,23 +75,13 @@ function resetActorOnFrameStart(actor, bool)
|
||||||
resetOnFrameStartActors[actor.__raw or actor] = bool
|
resetOnFrameStartActors[actor.__raw or actor] = bool
|
||||||
end
|
end
|
||||||
|
|
||||||
uranium.actors = require 'uranium.actors'
|
|
||||||
|
|
||||||
local lastt = GAMESTATE:GetSongTime()
|
local lastt = GAMESTATE:GetSongTime()
|
||||||
local function screenReadyCommand(self)
|
local function screenReadyCommand(self)
|
||||||
|
actors.finalize()
|
||||||
|
|
||||||
hideThemeActors()
|
hideThemeActors()
|
||||||
self:hidden(0)
|
self:hidden(0)
|
||||||
|
|
||||||
oat._actor = nil
|
|
||||||
|
|
||||||
uranium.actors._actorQueue = nil
|
|
||||||
uranium.actors._actorAssociationQueue = nil
|
|
||||||
|
|
||||||
uranium.actors._actorTree = nil
|
|
||||||
uranium.actors._currentPath = nil
|
|
||||||
uranium.actors._pastPaths = nil
|
|
||||||
uranium.actors._currentActor = nil
|
|
||||||
|
|
||||||
collectgarbage()
|
collectgarbage()
|
||||||
|
|
||||||
local errored = false
|
local errored = false
|
||||||
|
@ -150,7 +115,7 @@ local function screenReadyCommand(self)
|
||||||
|
|
||||||
drawfunctionArguments = {}
|
drawfunctionArguments = {}
|
||||||
|
|
||||||
for _, q in ipairs(uranium.actors._globalQueue) do
|
for _, q in ipairs(actors._globalQueue) do
|
||||||
local enabled = resetOnFrameStartCfg
|
local enabled = resetOnFrameStartCfg
|
||||||
|
|
||||||
local actor = q[1]
|
local actor = q[1]
|
||||||
|
@ -202,10 +167,7 @@ end)
|
||||||
if success then
|
if success then
|
||||||
print('---')
|
print('---')
|
||||||
|
|
||||||
uranium.actors._actorsInitializing = true
|
actors.prepareForActors()
|
||||||
uranium.actors._transformQueueToTree()
|
|
||||||
--Trace(fullDump(uranium.actors._actorTree))
|
|
||||||
uranium.actors._currentPath = uranium.actors._actorTree
|
|
||||||
|
|
||||||
_main:addcommand('On', onCommand)
|
_main:addcommand('On', onCommand)
|
||||||
_main:addcommand('Ready', screenReadyCommand)
|
_main:addcommand('Ready', screenReadyCommand)
|
||||||
|
|
Loading…
Reference in New Issue