From 441ca0faccbfaddccabdde8b1104e923c1af258b Mon Sep 17 00:00:00 2001 From: "Jill \"oatmealine \" Monoids" Date: Fri, 23 Sep 2022 16:21:23 +0300 Subject: [PATCH 1/5] help --- actorsTest.xml | 6 +++ main.xml | 115 +++++++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 113 insertions(+), 8 deletions(-) create mode 100644 actorsTest.xml diff --git a/actorsTest.xml b/actorsTest.xml new file mode 100644 index 0000000..ce7fb36 --- /dev/null +++ b/actorsTest.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/main.xml b/main.xml index bebdb60..e396c77 100644 --- a/main.xml +++ b/main.xml @@ -288,8 +288,29 @@ -- actors local actorQueue = {} + local actorAssociationQueue = {} + + local actorTree = {} + local currentPath + local pastPaths = {} local currentActor = nil + local function findFirstActor(path) + for i, v in ipairs(path) do + if v.type or v.file then + return v, i + end + end + end + + local function findFirstActorFrame(path) + for i, v in ipairs(path) do + if not v.type and not v.file then + return v, i + end + end + end + oat._actor = {} function oat._actor.next() @@ -337,14 +358,17 @@ function oat._actor.init(self) currentActor.init(self) + currentActor = nil -- shouldn't be needed from now on end function oat._actor.initFrame(self) - local nextChild = self(2) + print('initiating an actorframe') + --local nextChild = self(2) self:SetDrawFunction(function() - if nextChild then - nextChild:Draw() - end + --if nextChild then + -- nextChild:Draw() + --end + -- TODO end) end @@ -352,6 +376,7 @@ local queue = {} local initCommands = {} local lockedActor + local queueRepresentation return setmetatable({}, { __index = function(self, key) @@ -365,8 +390,17 @@ end return val end + if key == '__queue' then + return queueRepresentation + end + if key == '__queueRepresentation' then + return function(q) + queueRepresentation = q + end + end if key == '__lock' then return function(actor) + if lockedActor then return end for _, v in ipairs(queue) do local func = actor[v[1]] if not func then @@ -406,6 +440,7 @@ end end initCommands = {} + queueRepresentation = nil -- to make mr. Garbage Collector's job easier end else return function(...) @@ -420,7 +455,7 @@ __newindex = function() error('uranium: cannot set properties on actors!', 2) end, - __tostring = function() return name end, + __tostring = function() return 'Proxy of ' .. name end, __name = name }) end @@ -431,11 +466,11 @@ local actor = createProxyActor(type) table.insert(actorQueue, { type = type, - file = nil, init = function(a) actor.__lock(a) end }) + actor.__queueRepresentation(actorQueue[#actorQueue]) return actor end end @@ -458,6 +493,20 @@ actor.__lock(a) end }) + actor.__queueRepresentation(actorQueue[#actorQueue]) + return actor + end + + function ActorFrame() + if actorsInitialized then error('uranium: cannot create an actor during runtime!!', 2) end + local actor = createProxyActor('ActorFrame') + table.insert(actorQueue, { + type = 'ActorFrame', + init = function(a) + actor.__lock(a) + end + }) + actor.__queueRepresentation(actorQueue[#actorQueue]) return actor end @@ -496,6 +545,7 @@ end end }) + actor.__queueRepresentation(actorQueue[#actorQueue]) return actor end @@ -510,6 +560,7 @@ actor.__lock(a) end }) + actor.__queueRepresentation(actorQueue[#actorQueue]) return actor end @@ -524,6 +575,7 @@ actor.__lock(a) end }) + actor.__queueRepresentation(actorQueue[#actorQueue]) return actor end @@ -538,16 +590,62 @@ actor.__lock(a) end }) + actor.__queueRepresentation(actorQueue[#actorQueue]) return actor end + function addChild(frame, actor) + actorAssociationQueue[actor.__queue] = frame.__queue + end + + local function transformQueueToTree() + local tree = {} + local paths = {} + local iter = 0 + while #actorQueue > 0 do + iter = iter + 1 + if iter > 999999 then + error('uranium: failed to transform queue to tree: reached maximum iteration limit! is there an actor with an invalid actorframe?') + end + for i = #actorQueue, 1, -1 do + v = actorQueue[i] + local insertInto + if not actorAssociationQueue[v] then + insertInto = tree + else + if paths[actorAssociationQueue[v]] then + insertInto = paths[actorAssociationQueue[v]] + end + end + if insertInto then + if v.type == 'ActorFrame' then + table.insert(insertInto, {init = v.init}) + table.remove(actorQueue, i) + paths[v] = insertInto[#insertInto] + else + table.insert(insertInto, v) + table.remove(actorQueue, i) + end + end + end + end + actorTree = tree + end + local success, result = pcall(function() - require('main') + --require('main') + --require('stdlib.util') end) if success then luaobj = result + --local queue = actorQueue + --actorQueue = deepcopy(actorQueue) + --transformQueueToTree() + --Trace(fullDump(actorTree)) + --currentPath = actorTree + self:addcommand('On', onCommand) self:addcommand('Ready', screen_ready_command) self:addcommand('Off', exit) @@ -570,6 +668,7 @@ -- By removing the command after it's done, it can only ever run once self:removecommand('Init') end"> - + + \ No newline at end of file From f6638b8f3e95dcd829aac67fedd2ccc8fcab4aac Mon Sep 17 00:00:00 2001 From: "Jill \"oatmealine\" Monoids" Date: Fri, 23 Sep 2022 19:22:23 +0300 Subject: [PATCH 2/5] GHAHAHAAAAAAAAAA IT WORKS --- actors.xml | 44 ++++++++++++++++++++---- actorsTest.xml | 6 ++-- main.xml | 93 ++++++++++++++++++++++++++++++++++++-------------- 3 files changed, 107 insertions(+), 36 deletions(-) diff --git a/actors.xml b/actors.xml index 7cf954c..6eadda9 100644 --- a/actors.xml +++ b/actors.xml @@ -1,7 +1,37 @@ - - - - - - - \ No newline at end of file + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/actorsTest.xml b/actorsTest.xml index ce7fb36..5ae04ee 100644 --- a/actorsTest.xml +++ b/actorsTest.xml @@ -1,6 +1,6 @@ - + - - + + \ No newline at end of file diff --git a/main.xml b/main.xml index e396c77..b2b0d33 100644 --- a/main.xml +++ b/main.xml @@ -166,6 +166,9 @@ if hasExited then return end hasExited = true uranium:call('exit') + -- good templates clean up after themselves + _G.oat = nil + _main:hidden(1) end local actorsInitialized = false -- if true, no new actors can be created @@ -240,16 +243,20 @@ local errored = false local firstrun = true + local playersLoaded = false self:addcommand('Update', function() - if not P1 and not P2 then -- sora exit hack - exit() - end - if errored then return 0 end errored = true + if P1 and P2 then + playersLoaded = true + end + if playersLoaded and not P1 and not P2 then -- sora exit hack + exit() + end + t = os.clock() b = GAMESTATE:GetSongBeat() local dt = t - lastt @@ -313,17 +320,41 @@ oat._actor = {} - function oat._actor.next() - local actor = actorQueue[1] - if actor then - table.remove(actorQueue, 1) - currentActor = actor + local function nextActor() + local new, idx = findFirstActor(currentPath) + if not new then + print('no actor!') + currentActor = nil + else + print('adding new actor') + currentActor = new + table.remove(currentPath, idx) + end + end + + function oat._actor.recurse() + local newFrame, idx = findFirstActorFrame(currentPath) + if newFrame then + table.insert(pastPaths, currentPath) + currentPath = currentPath[idx] + table.remove(pastPaths[#pastPaths], idx) + print('recursing: ' .. #pastPaths) + return true + elseif currentActor then + table.insert(pastPaths, currentPath) + print('recursing (actor): ' .. #pastPaths) return true else + print('no actor or actorframe!') return false end end + function oat._actor.endRecurse() + print('heading back: ' .. #pastPaths) + currentPath = table.remove(pastPaths, #pastPaths) + end + function oat._actor.cond() return currentActor ~= nil end @@ -333,6 +364,7 @@ end function oat._actor.noShader() + nextActor() return oat._actor.cond() and not oat._actor.hasShader() end @@ -358,18 +390,27 @@ function oat._actor.init(self) currentActor.init(self) - currentActor = nil -- shouldn't be needed from now on + self:removecommand('Init') + currentActor = nil -- to prevent any weirdness end function oat._actor.initFrame(self) - print('initiating an actorframe') - --local nextChild = self(2) + print('initializing an actorframe') + self:removecommand('Init') self:SetDrawFunction(function() - --if nextChild then - -- nextChild:Draw() - --end - -- TODO + for i = 1, self:GetNumChildren() do + local a = self(i) + if a.fov then -- actorframe + a:Draw() + end + end end) + + if currentPath.init then + print('found init function, calling') + currentPath.init(self) + currentPath.init = nil + end end local function createProxyActor(name) @@ -597,7 +638,7 @@ function addChild(frame, actor) actorAssociationQueue[actor.__queue] = frame.__queue end - + local function transformQueueToTree() local tree = {} local paths = {} @@ -633,18 +674,19 @@ end local success, result = pcall(function() - --require('main') - --require('stdlib.util') + require('main') + require('stdlib.util') end) if success then luaobj = result - --local queue = actorQueue - --actorQueue = deepcopy(actorQueue) - --transformQueueToTree() - --Trace(fullDump(actorTree)) - --currentPath = actorTree + print('---') + + transformQueueToTree() + Trace(fullDump(actorTree)) + currentPath = actorTree + nextActor() self:addcommand('On', onCommand) self:addcommand('Ready', screen_ready_command) @@ -668,7 +710,6 @@ -- By removing the command after it's done, it can only ever run once self:removecommand('Init') end"> - - + \ No newline at end of file From e7d49fa5620b7e9a81d6175ea280ef9f7d9ad251 Mon Sep 17 00:00:00 2001 From: "Jill \"oatmealine\" Monoids" Date: Fri, 23 Sep 2022 19:26:31 +0300 Subject: [PATCH 3/5] cleanup, add typings --- actorsTest.xml | 6 ------ typings.lua | 9 +++++++++ 2 files changed, 9 insertions(+), 6 deletions(-) delete mode 100644 actorsTest.xml diff --git a/actorsTest.xml b/actorsTest.xml deleted file mode 100644 index 5ae04ee..0000000 --- a/actorsTest.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/typings.lua b/typings.lua index 73cfe75..de19985 100644 --- a/typings.lua +++ b/typings.lua @@ -50,12 +50,21 @@ function ActorFrameTexture() end ---@return RageShaderProgram --- Defines a shader. `frag` and `vert` can either be filenames or shader code. function Shader(frag, vert) end +---@return ActorFrame +---@see addChild +--- Defines an ActorFrame. Add children to it with `addChild`. +function ActorFrame() end ---@param actor Actor --- Resets an actor to its initial state function reset(actor) end resetActor = reset +---@param frame ActorFrame +---@param actor Actor +--- Adds a child to an ActorFrame. **Please be aware of the side-effects!** +function addChild(frame, actor) end + ---@type number --- A simple timer. Ticks upwards at a rate of 1/sec. --- From d8056408f4518c401102701c2edeb09733635cf3 Mon Sep 17 00:00:00 2001 From: "Jill \"oatmealine\" Monoids" Date: Fri, 23 Sep 2022 20:27:52 +0300 Subject: [PATCH 4/5] further actorframe cleanup --- actors.xml | 2 +- main.xml | 16 ++++++---------- 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/actors.xml b/actors.xml index 6eadda9..c4386bd 100644 --- a/actors.xml +++ b/actors.xml @@ -32,6 +32,6 @@ - + \ No newline at end of file diff --git a/main.xml b/main.xml index b2b0d33..2dd6100 100644 --- a/main.xml +++ b/main.xml @@ -323,35 +323,33 @@ local function nextActor() local new, idx = findFirstActor(currentPath) if not new then - print('no actor!') currentActor = nil else - print('adding new actor') currentActor = new table.remove(currentPath, idx) end end - function oat._actor.recurse() + function oat._actor.recurse(forceActor) local newFrame, idx = findFirstActorFrame(currentPath) - if newFrame then + if newFrame and not (currentActor and forceActor) then table.insert(pastPaths, currentPath) currentPath = currentPath[idx] table.remove(pastPaths[#pastPaths], idx) - print('recursing: ' .. #pastPaths) return true elseif currentActor then table.insert(pastPaths, currentPath) - print('recursing (actor): ' .. #pastPaths) return true else - print('no actor or actorframe!') return false end end + function oat._actor.recurseLast() + return oat._actor.recurse(true) + end + function oat._actor.endRecurse() - print('heading back: ' .. #pastPaths) currentPath = table.remove(pastPaths, #pastPaths) end @@ -395,7 +393,6 @@ end function oat._actor.initFrame(self) - print('initializing an actorframe') self:removecommand('Init') self:SetDrawFunction(function() for i = 1, self:GetNumChildren() do @@ -407,7 +404,6 @@ end) if currentPath.init then - print('found init function, calling') currentPath.init(self) currentPath.init = nil end From 0933b25ae42830d7406fb36269d910f5a058f727 Mon Sep 17 00:00:00 2001 From: "Jill \"oatmealine\" Monoids" Date: Fri, 23 Sep 2022 20:35:11 +0300 Subject: [PATCH 5/5] quick bugfix --- main.xml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/main.xml b/main.xml index 2dd6100..08758e4 100644 --- a/main.xml +++ b/main.xml @@ -680,9 +680,8 @@ print('---') transformQueueToTree() - Trace(fullDump(actorTree)) + --Trace(fullDump(actorTree)) currentPath = actorTree - nextActor() self:addcommand('On', onCommand) self:addcommand('Ready', screen_ready_command)