Optimized table usage as much as possible (more fps)

This commit is contained in:
Entarno54 2025-06-01 12:11:05 +07:00
parent 9c2b727920
commit 0736af3a5f
8 changed files with 46 additions and 239 deletions

1
.gitignore vendored
View File

@ -41,3 +41,4 @@ luac.out
*.hex
settings.json

View File

@ -1,97 +0,0 @@
-- RANK ONLY UP TILL 20, 0 MINIMUM, CHANGE THIS TO SUGGEST HOW HARD THE SONG IS, BY MARKEDAMAN
function onCreate()
if difficulty == 0 then -- easy
rank = 1
elseif difficulty == 1 then -- normal
rank = 1
elseif difficulty == 2 then -- hard
rank = 2
elseif difficulty == 3 then -- erect
rank = 11
elseif difficulty == 4 then -- nightmare
rank = 12
end
end
function onCreatePost()
if not hideHud then
if rank > 10 then
makeLuaSprite('star', 'star2', 1070, 590)
makeAnimatedLuaSprite('starFlame', 'starFlame', 1030, 440)
addAnimationByPrefix('starFlame', 'starFlame', 'fire loop full instance', 24, true)
setProperty('starFlame.alpha', 0)
scaleObject('starFlame', 1.5, 1.5)
setObjectCamera('starFlame', 'hud')
addLuaSprite('starFlame', true)
elseif rank <= 10 then
makeLuaSprite('star', 'star1', 1070, 590)
end
scaleObject('star', 0.9, 0.9)
setObjectCamera('star', 'hud')
setObjectOrder('star', getObjectOrder('starFlame') + 1)
setProperty('star.alpha', 0)
addLuaSprite('star')
makeLuaText('difficulty', ''.. rank ..'', 2230 , 0, 620)
setTextSize('difficulty', 37)
setTextFont('difficulty', 'combo.ttf')
setProperty('difficulty.alpha', 0)
addLuaText('difficulty', false)
setObjectOrder('difficulty', getObjectOrder('star') + 1)
if downscroll then
setProperty('difficulty.y', 70)
setProperty('star.y', 40)
setProperty('starFlame.y', -5)
setProperty('starFlame.angle', 190)
end
if rank > 10 then
setTextColor('difficulty', 'ffffff')
setTextBorder('difficulty', 2, '00AEFF')
elseif rank <= 10 then
setTextColor('difficulty', '000000')
setTextBorder('difficulty', 3, 'FFFFFF')
end
runTimer('ready', 0.5) -- star fade in
runTimer('wait', 8) -- star fade out
runTimer('wait2', 7.5) -- difficulty fade out
if rank > 10 then
runTimer('pausefire', 2) -- difficulty fade in
elseif rank <=10 then
runTimer('pause', 2)
end
end
end
function onTimerCompleted(tag)
if not hideHud then
if tag == 'ready' then
doTweenAlpha('hi', 'star', 1, 0.5,'linear')
end
if tag == 'wait' then
doTweenAlpha('gone', 'star', 0, 0.5,'linear')
doTweenAlpha('fireout', 'starFlame', 0, 0.5,'linear')
end
if tag == 'wait2' then
doTweenAlpha('bye', 'difficulty', 0, 0.5,'linear')
end
if tag == 'pause' then
doTweenAlpha('hi2', 'difficulty', 1, 0.5,'linear')
end
if tag == 'pausefire' then
setProperty('difficulty.alpha', 1)
setProperty('starFlame.alpha', 1)
playSound('light', 0.7)
end
end
end

View File

@ -1,4 +0,0 @@
function onCreate()
setTextFont('scoreTxt', 'vcr.ttf')
setTextFont('timeTxt','timer.ttf')
end

View File

@ -1,113 +0,0 @@
-- Script made by Washo789, please, if you use it or modify it, I would like you to give me credits.
local xx = 520; -- Code to change the position of the camera to the left or right for your opponent, Less = Left (They can be negative numbers), More = Right
local yy = 350; -- Code to change the position of the camera up or down for the enemy Less = Down (They can be negative numbers), More = Up
local xx2 = 820; -- Same code as above, but for boyfriend left, right
local yy2 = 550; -- Same code as above, but for boyfriend up, down
local xx3 = 520; -- Same code as above, but for girlfriend left, right
local yy3 = 450; -- Same code as above, but for girlfriend, up, down
local ofs = 35; -- Code to adjust the intensity with which the camera moves, the more numbers, the more intense, and the fewer numbers, less intense
local followchars = true; -- This code is necessary for the script to work, don't even think about deleting it!
local del = 0;
local del2 = 0;
function onUpdate() -- The Main Code
if del > 0 then
del = del - 1
end
if del2 > 0 then
del2 = del2 - 1
end
if followchars == true then
if mustHitSection == false then -- Code for the camera to follow the poses of your opponent
if getProperty('dad.animation.curAnim.name') == 'singLEFT' then
triggerEvent('Camera Follow Pos',xx-ofs,yy)
end
if getProperty('dad.animation.curAnim.name') == 'singRIGHT' then
triggerEvent('Camera Follow Pos',xx+ofs,yy)
end
if getProperty('dad.animation.curAnim.name') == 'singUP' then
triggerEvent('Camera Follow Pos',xx,yy-ofs)
end
if getProperty('dad.animation.curAnim.name') == 'singDOWN' then
triggerEvent('Camera Follow Pos',xx,yy+ofs)
end
if getProperty('dad.animation.curAnim.name') == 'singLEFT-alt' then
triggerEvent('Camera Follow Pos',xx-ofs,yy)
end
if getProperty('dad.animation.curAnim.name') == 'singRIGHT-alt' then
triggerEvent('Camera Follow Pos',xx+ofs,yy)
end
if getProperty('dad.animation.curAnim.name') == 'singUP-alt' then
triggerEvent('Camera Follow Pos',xx,yy-ofs)
end
if getProperty('dad.animation.curAnim.name') == 'singDOWN-alt' then
triggerEvent('Camera Follow Pos',xx,yy+ofs)
end
if getProperty('dad.animation.curAnim.name') == 'idle-alt' then
triggerEvent('Camera Follow Pos',xx,yy)
end
if getProperty('dad.animation.curAnim.name') == 'idle' then
triggerEvent('Camera Follow Pos',xx,yy)
end
if gfSection == true then -- The camera follows GF when she sings, only when the "GF Section" option in the chart editor is activated.
if getProperty('gf.animation.curAnim.name') == 'singLEFT' then -- Credits to Serebeat and company for their Slaybells mod,
triggerEvent('Camera Follow Pos',xx3-ofs,yy3) -- That's where I got the gf code from.
end
if getProperty('gf.animation.curAnim.name') == 'singRIGHT' then
triggerEvent('Camera Follow Pos',xx3+ofs,yy3)
end
if getProperty('gf.animation.curAnim.name') == 'singUP' then
triggerEvent('Camera Follow Pos',xx3,yy3-ofs)
end
if getProperty('gf.animation.curAnim.name') == 'singDOWN' then
triggerEvent('Camera Follow Pos',xx3,yy3+ofs)
end
if getProperty('gf.animation.curAnim.name') == 'idle-alt' then
triggerEvent('Camera Follow Pos',xx3,yy3)
end
if getProperty('gf.animation.curAnim.name') == 'singRIGHT-alt' then
triggerEvent('Camera Follow Pos',xx3+ofs,yy3)
end
if getProperty('gf.animation.curAnim.name') == 'singUP-alt' then
triggerEvent('Camera Follow Pos',xx3,yy3-ofs)
end
if getProperty('gf.animation.curAnim.name') == 'singDOWN-alt' then
triggerEvent('Camera Follow Pos',xx3,yy3+ofs)
end
if getProperty('gf.animation.curAnim.name') == 'idle-alt' then
triggerEvent('Camera Follow Pos',xx3,yy3)
end
end
else
-- Code for the camera to follow the poses of boyfriend
if getProperty('boyfriend.animation.curAnim.name') == 'singLEFT' then
triggerEvent('Camera Follow Pos',xx2-ofs,yy2)
end
if getProperty('boyfriend.animation.curAnim.name') == 'singRIGHT' then
triggerEvent('Camera Follow Pos',xx2+ofs,yy2)
end
if getProperty('boyfriend.animation.curAnim.name') == 'singUP' then
triggerEvent('Camera Follow Pos',xx2,yy2-ofs)
end
if getProperty('boyfriend.animation.curAnim.name') == 'singDOWN' then
triggerEvent('Camera Follow Pos',xx2,yy2+ofs)
end
if getProperty('boyfriend.animation.curAnim.name') == 'singRIGHT-alt' then
triggerEvent('Camera Follow Pos',xx2+ofs,yy2)
end
if getProperty('boyfriend.animation.curAnim.name') == 'singUP-alt' then
triggerEvent('Camera Follow Pos',xx2,yy2-ofs)
end
if getProperty('boyfriend.animation.curAnim.name') == 'singDOWN-alt' then
triggerEvent('Camera Follow Pos',xx2,yy2+ofs)
end
if getProperty('boyfriend.animation.curAnim.name') == 'idle-alt' then
triggerEvent('Camera Follow Pos',xx2,yy2)
end
end
else
triggerEvent('Camera Follow Pos','','') -- Self explanatory
end
end

View File

@ -1,4 +1,4 @@
return function(songName, songDifficulty)
local function state(songName, songDifficulty)
local state = {} -- Returns needed functions for the state to work after loading it properly
-- I NEED THEM IMPORTS
@ -43,6 +43,8 @@ return function(songName, songDifficulty)
local characters = {}
local settings = {}
local directions = {
"LEFT",
"DOWN",
@ -50,6 +52,13 @@ return function(songName, songDifficulty)
"RIGHT"
}
local singVectors = {
singLEFT = myTypes.Vector2(20, 0),
singDOWN = myTypes.Vector2(0, -20),
singUP = myTypes.Vector2(0, 20),
singRIGHT = myTypes.Vector2(-20, 0)
}
local pressed = {
false,
false,
@ -106,7 +115,7 @@ return function(songName, songDifficulty)
characters.bf:PlayAnimation("sing"..directions[note.direction])
note.pressed = true
receptors[dir]:PlayAnimation(string.lower(directions[dir]).." confirm", 25, false)
table.remove(notes, index)
notes[index] = nil
note:destroy()
end
end
@ -114,6 +123,7 @@ return function(songName, songDifficulty)
end
local elapsed = 0
local actualElapsed = 0
function state.update(dt)
if not playing then return end
@ -171,7 +181,8 @@ return function(songName, songDifficulty)
local currentTime = socket.gettime()
elapsed = (currentTime - startTime) * 1000 - pauseTime
actualElapsed = (currentTime - startTime) * 1000 - pauseTime
elapsed = actualElapsed > 100 and actualElapsed - 100 or 0
conductor.songPosition = elapsed
@ -204,9 +215,11 @@ return function(songName, songDifficulty)
local section = chart.notes[math.floor(step / 16) + 1]
if section.mustHitSection then
myTypes.cameraTarget = myTypes.Vector2(-stage.camera_boyfriend[1], -stage.camera_boyfriend[2]):Add(characters.bf.stageCamera:Negate()):Add(myTypes.Vector2(0, -200))
local currentSingVector = singVectors[characters.bf.animation] or myTypes.Vector2()
myTypes.cameraTarget = myTypes.Vector2(-stage.camera_boyfriend[1], -stage.camera_boyfriend[2]):Add(characters.bf.stageCamera:Negate()):Add(myTypes.Vector2(0, -200)):Add(currentSingVector)
else
myTypes.cameraTarget = myTypes.Vector2(stage.camera_opponent[1], stage.camera_opponent[2]):Add(characters.dad.stageCamera:Negate()):Add(myTypes.Vector2(0, -200))
local currentSingVector = singVectors[characters.dad.animation] or myTypes.Vector2()
myTypes.cameraTarget = myTypes.Vector2(stage.camera_opponent[1], stage.camera_opponent[2]):Add(characters.dad.stageCamera:Negate()):Add(myTypes.Vector2(0, -200)):Add(currentSingVector)
end
myTypes.updateSprites(dt)
@ -218,7 +231,7 @@ return function(songName, songDifficulty)
miss:stop()
miss:play()
characters.bf:PlayAnimation("sing"..directions[note.direction].."miss")
table.remove(notes, index)
notes[index] = nil
end
end
end
@ -232,24 +245,24 @@ return function(songName, songDifficulty)
for index, note in next, unspawnedNotes do
if note.position - elapsed < 600 and note.mustPress then
note:spawn()
table.remove(unspawnedNotes, index)
table.insert(notes, note)
unspawnedNotes[index] = nil
notes[#notes+1] = note
elseif note.position - elapsed < 600 and not note.mustPress then
table.remove(unspawnedNotes, index)
table.insert(notes, note)
unspawnedNotes[index] = nil
notes[#notes+1] = note
end
end
for index, note in next, notes do
if note.spawned then
note.sprite.position = myTypes.Vector2(400 + 65 * (note.direction - 1), note.position - elapsed - 100)
note.sprite.position = myTypes.Vector2(400 + 65 * (note.direction - 1), settings.Downscroll and 430 - (note.position-elapsed-100) or note.position - elapsed-100)
if note.position - elapsed < -150 then
note:destroy()
table.remove(notes, index)
notes[index] = nil
end
else
if note.position - elapsed < 50 then
table.remove(notes, index)
notes[index] = nil
if section.altAnim or note.altAnim then
characters.dad:PlayAnimation("sing"..directions[note.direction].."-alt")
else
@ -312,7 +325,7 @@ return function(songName, songDifficulty)
for index, section in next, chart.notes do
for index, note in next, section.sectionNotes do
local newNote = myTypes.note(note, section.mustHitSection)
table.insert(unspawnedNotes, newNote)
unspawnedNotes[#unspawnedNotes+1] = newNote
end
end
@ -320,23 +333,24 @@ return function(songName, songDifficulty)
local receptor = myTypes.Sprite("sprites/NOTE_assets.png", "sprites/NOTE_assets.json")
receptor:PlayAnimation("arrow"..directions[i+1], 25, false)
receptor.position = myTypes.Vector2(400 + (65 * i), 0)
receptor.position = myTypes.Vector2(400 + (65 * i), settings.Downscroll and 0 or 430)
receptor.ui = true -- So it doesnt move with the camera.
receptors[i + 1] = receptor
end
state.loaded = true
myTypes.cameraTarget = myTypes.Vector2()
local settings = json.parse(files.read_file("settings.json"))
settings = json.parse(files.read_file("settings.json"))
if not settings then
error("Failed to load settings")
end
keyBinds = settings.Keybinds
state.loaded = true
end
function state.finish()
@ -347,6 +361,7 @@ return function(songName, songDifficulty)
end --waiting till the song actually plays.
elapsed = 0
actualElapsed = 0
playing = true
@ -355,3 +370,6 @@ return function(songName, songDifficulty)
return state
end
return state

View File

@ -91,7 +91,7 @@ function module.Sprite(image, sheet)
newSprite.quads = quads
table.insert(Sprites, newSprite)
Sprites[#Sprites+1] = newSprite
return newSprite
end
@ -108,7 +108,7 @@ function Sprite:Destroy()
if self.rect then
for index, rect in next, Rects do
if rect == self then
table.remove(Rects, index)
Rects[index] = nil
-- for name, animation in next, rect.quads do
-- for index, quad in next, animation do
-- quad:release()
@ -120,7 +120,7 @@ function Sprite:Destroy()
else
for index, sprite in next, Sprites do
if sprite == self then
table.remove(Sprites, index)
Sprites[index] = nil
-- for name, animation in next, sprite.quads do
-- for index, quad in next, animation do
-- quad:release()
@ -161,7 +161,6 @@ function module.updateSprites(dt)
end
function module.drawSprites()
print(logging.dump(module.cameraPosition))
for index, sprite in next, Sprites do
if not sprite.animation or not sprite.quads or not sprite.quads[sprite.animation] then goto continue end -- For some reason OG LUA doesnt have continue
-- So im forced to use goto ::continue:: since it goes straight to the last point of the cycle
@ -252,7 +251,7 @@ function module.Rect(image, sheet)
newSprite.quads = quads
table.insert(Rects, newSprite)
Rects[#Rects+1] = newSprite
return newSprite
end

View File

@ -18,6 +18,7 @@ function CharacterClass:PlayAnimation(name)
self.sprite.extraOffset = module.myTypes.Vector2(self.animInfo[name].offsets[1] - self.stagePosition.x, self.animInfo[name].offsets[2] - self.stagePosition.y)
end
self.singing = name ~= "idle" and name ~= "danceLeft" and name ~= "danceRight"
self.animation = name
end
function module.character(name)
@ -45,10 +46,11 @@ function module.character(name)
stagePosition = module.myTypes.Vector2(0,0), -- Changeable
stageCamera = module.myTypes.Vector2(parsed.camera_position[1], parsed.camera_position[2]),
flipX = parsed.flip_x,
beats = parsed.beats or 4
beats = parsed.beats or 4,
animation = "idle"
}, CharacterClass)
for index, alias in next, parsed.animations do
for index, alias in ipairs(parsed.animations) do
newCharacter.animations[alias.anim] = alias.name
newCharacter.animInfo[alias.anim] = alias
end

View File

@ -1,5 +1,6 @@
{
"Keybinds": [
"a", "s", "up", "right"
]
],
"Downscroll": true
}