Caching of images ( holy fps )

This commit is contained in:
Entarno54 2025-06-01 14:12:37 +07:00
parent 4f6082b037
commit da89a077ca
4 changed files with 79 additions and 89 deletions

View File

@ -61,7 +61,7 @@
-8
],
"loop": false,
"fps": 50,
"fps": 24,
"anim": "singUP-alt",
"indices": [],
"name": "TANKMAN UGH "
@ -72,7 +72,7 @@
16
],
"loop": false,
"fps": 50,
"fps": 24,
"anim": "singDOWN-alt",
"indices": [],
"name": "PRETTY GOOD tankman "

View File

@ -35,22 +35,9 @@ function love.update(dt)
end
elseif not curState then
if love.keyboard.isDown("return") then
curState = state(curSong, curDiff)
curState.quit = function()
curState = nil
stateLoaded = false
myTypes.destroyAllSprites()
end
curState.load()
elseif love.keyboard.isDown("down") and not pressed[1] then
curSong = next(songs, curSong)
if not curSong then
curSong = next(songs)
curDiffList = songs[curSong]
else
curDiffList = songs[curSong]
end
curDiff = curDiffList[1]
pressed[1] = true
elseif love.keyboard.isDown("right") and not pressed[2] then
local curDiffNum = 0
@ -90,4 +77,29 @@ function love.draw()
end
end
function love.keypressed(key, un, is)
if curState and stateLoaded then
curState.keypressed(key, un, is)
else
if key == "return" then
curState = state(curSong, curDiff)
curState.quit = function()
curState = nil
stateLoaded = false
myTypes.destroyAllSprites()
end
curState.load()
elseif key == "down" then
curSong = next(songs, curSong)
if not curSong then
curSong = next(songs)
curDiffList = songs[curSong]
else
curDiffList = songs[curSong]
end
curDiff = curDiffList[1]
end
end
end
love.window.setMode(1280, 720, { fullscreen = false , resizable = true})

View File

@ -73,6 +73,8 @@ local function state(songName, songDifficulty)
false
}
local fps = 60 -- for the counter
local receptors = {}
local keyBinds = {} -- loaded from settings.json, if anything's wrong then check your settings.json
@ -100,26 +102,23 @@ local function state(songName, songDifficulty)
end
local function checkNote(dir)
if pressed[dir] or holded[dir] then
pressed[dir] = false
holded[dir] = true
if receptors[dir].animation ~= string.lower(directions[dir]).." confirm" then
receptors[dir]:PlayAnimation(string.lower(directions[dir]).." press", 25, false)
end
return -- You dont check if you are already holding and not just pressing
end
pressed[dir] = true
local closestNote
local closestIndex
for index, note in next, notes do
if note.position - conductor.songPosition < 200 then
if note.mustPress and not note.pressed and note.direction == dir then
characters.bf:PlayAnimation("sing"..directions[note.direction])
note.pressed = true
receptors[dir]:PlayAnimation(string.lower(directions[dir]).." confirm", 25, false)
notes[index] = nil
note:destroy()
if note.mustPress and not note.pressed and note.direction == dir and (not closestNote or closestNote and note.position < closestNote.position) then
closestNote = note
closestIndex = index
end
end
end
if closestNote then
characters.bf:PlayAnimation("sing"..directions[closestNote.direction])
closestNote.pressed = true
receptors[dir]:PlayAnimation(string.lower(directions[dir]).." confirm", 5, false)
notes[closestIndex] = nil
closestNote:destroy()
end
end
local elapsed = 0
@ -129,54 +128,6 @@ local function state(songName, songDifficulty)
if not playing then return end
-- playing isn't supposed to work like "paused", it's there to keep the game from working during loading
if love.keyboard.isDown(keyBinds[1]) then
checkNote(1)
else
holded[1] = false
pressed[1] = false
end
if love.keyboard.isDown(keyBinds[2]) then
checkNote(2)
else
holded[2] = false
pressed[2] = false
end
if love.keyboard.isDown(keyBinds[3]) then
checkNote(3)
else
holded[3] = false
pressed[3] = false
end
if love.keyboard.isDown(keyBinds[4]) then
checkNote(4)
else
holded[4] = false
pressed[4] = false
end
if love.keyboard.isDown("escape") then
quit()
end
if love.keyboard.isDown("space") then
if pressed[5] then goto evilContinue end
pressed[5] = true
paused = not paused
if paused then
inst:pause()
voices:pause()
pauseStart = socket.gettime() * 1000
else
inst:play()
voices:play()
pauseTime = pauseTime + (socket.gettime() * 1000 - pauseStart)
end
::evilContinue::
else
pressed[5] = false
end
if paused then goto continue end -- if paused then skip this cycle
local currentTime = socket.gettime()
@ -275,6 +226,8 @@ local function state(songName, songDifficulty)
zoom = myMath.lerp(zoom, 1, .05)
fps = 1000 / dt
::continue::
end
@ -294,6 +247,7 @@ local function state(songName, songDifficulty)
love.graphics.draw(mainCanvas, (love.graphics:getHeight() * (4/3) - (love.graphics:getHeight()* (4/3)) * zoom) / 2, (love.graphics:getHeight()- love.graphics:getHeight() * zoom) / 2, 0, ((love.graphics:getHeight() / 1080) * (4/3)) * zoom, (love.graphics:getHeight() / 1080) * zoom)
love.graphics.print({{0,0,0,1}, string.format("FPS: %s", love.timer.getFPS())})
end
love.window.setMode(1280, 720, { fullscreen = false , resizable = true})
@ -358,6 +312,32 @@ local function state(songName, songDifficulty)
startTime = socket.gettime()
end
function state.keypressed(key, un, is)
if key == "space" then
paused = not paused
if paused then
inst:pause()
voices:pause()
pauseStart = socket.gettime() * 1000
else
inst:play()
voices:play()
pauseTime = pauseTime + (socket.gettime() * 1000 - pauseStart)
end
elseif key == "escape" then
quit()
elseif key == keyBinds[1] then
checkNote(1)
elseif key == keyBinds[2] then
checkNote(2)
elseif key == keyBinds[3] then
checkNote(3)
elseif key == keyBinds[4] then
checkNote(4)
end
end
return state
end

View File

@ -45,8 +45,6 @@ end
function module.Sprite(image, sheet)
if not cachedQuads[sheet] then
local sheetString = files.read_file(sheet)
if not sheetString then
error("Failed to load", sheet)
end
@ -90,7 +88,7 @@ function module.Sprite(image, sheet)
end
newSprite.quads = quads
cachedQuads[sheet] = quads
cachedQuads[sheet] = {quads = quads, image = newSprite.image}
Sprites[#Sprites+1] = newSprite
@ -98,8 +96,8 @@ function module.Sprite(image, sheet)
else
local newSprite = setmetatable({
image = love.graphics.newImage(image),
quads = cachedQuads[sheet],
image = cachedQuads[sheet].image,
quads = cachedQuads[sheet].quads,
elapsed = 0,
fps = 10,
animation = nil,
@ -219,7 +217,7 @@ end
function module.Rect(image, sheet)
if not cachedQuads[sheet] then
local sheetString = files.read_file(sheet)
if not sheetString then
error("Failed to load", sheet)
end
@ -263,15 +261,15 @@ function module.Rect(image, sheet)
end
newSprite.quads = quads
cachedQuads[sheet] = quads
cachedQuads[sheet] = {quads = quads, image = newSprite.image}
Rects[#Rects+1] = newSprite
return newSprite
else
local newSprite = setmetatable({
image = love.graphics.newImage(image),
quads = cachedQuads[sheet],
image = cachedQuads[sheet].image,
quads = cachedQuads[sheet].quads,
elapsed = 0,
fps = 10,
animation = nil,