Page 1 of 1

layerfix.lua - No more looping event desyncing!

Posted: Wed Apr 09, 2025 9:00 pm
by Alucard648
SMBX2 editor has Blocks-per-second calculator for converting blocks per second into pixels per frame for vanilla layer movement speed. The problem is that on attempt to make a crusher using looping vanilla SMBX events, with different up and down speed, just like classical layer operated crushers in SMW, and then running them for a long time (as long as actual normal level playtime) causes them to eventually desync and potentially wreck your level, something like this:
LAYERS BEFORE FIX: show
Image
This problem occurs because of floating point imprecision. With faster speeds, imprecision can build up really quickly. For some reason even setting layer speeds to integer values still cause them to go off bounds over time. Only setting layer speeds to same value worked in loops, as I have seen in many SMBX1.3 levels.
Enter layerfix.lua. This script attempts to fix this issue by grid-snapping all blocks, BGOs and certain NPCs placed on layer every time vanilla SMBX event changes layer movement speed. If the script works properly looping events should never desync over time, just like this:
LAYERS AFTER FIX: show
Image
To install the fix, just load API in your level luna.lua file and that is it. Everything, including fetching all vanilla SMBX events that move layers, is automatically done from played level file.

DOWNLOAD


Re: layerfix.lua - No more looping event desyncing!

Posted: Thu Apr 10, 2025 3:23 am
by deice
as a heads up for the future, if you want to grab data from a level file you don't have to write your own parser.
the LoadVanillaLayerMovementEvents could be simplified in its entirety to something along the lines of:

Code: Select all

local file = FileFormats.openLevel(Level.filename())
for _, event in ipairs(file.events) do
    layermove[event.name] = event.moveLayer
end
i don't remember if this library is actually documented despite being a basegame feature, but more can be gleamed about it from here if it's not

Re: layerfix.lua - No more looping event desyncing!

Posted: Thu Apr 10, 2025 7:24 am
by Alucard648
It was undocumented. At least, no such functions were found in Codehaus docs.