1 2
8 9
Player (199)
Joined: 12/3/2006
Posts: 151
Is there a way to get rid of the 1-frame delay when drawing to the screen? That is, display graphics based on the frame that was just emulated (assuming frameadvance is used). I tried several methods, including the gui.register function, and some elaborate savestate saving/loading methods to look ahead 1 frame in the future, but none of them worked so far. Edit: the best I could come with is this pseudo frameadvance function to ahead in the future, and using the unpause hotkey to advance a frame. I'm guessing there has to be a better way.
Language: lua

function customFrameAdvance() savestate.save(mySave) emu.frameadvance() getCollisionData() drawCollisionData() emu.frameadvance() myImg = gui.gdscreenshot() savestate.load(mySave) gui.gdoverlay(myImg,1) emu.pause() end
Emulator Coder, Skilled player (1311)
Joined: 12/21/2004
Posts: 2687
Gunty wrote:
Is there a way to get rid of the 1-frame delay when drawing to the screen? That is, display graphics based on the frame that was just emulated (assuming frameadvance is used). Edit: the best I could come with is this pseudo frameadvance function to ahead in the future, and using the unpause hotkey to advance a frame. I'm guessing there has to be a better way.
If you're only trying to match up hitbox drawing with the game's graphics, then usually you can simply render collision data from 1 or 2 frames in the past. To get rid of the game's rendering delay in general, I'm not sure if it's possible to do much better than your script without changing the current API. I suspect that the "better way" to do it involves adding some missing functionality to Snes9x. By the way, this is a lot more elegant to do in Gens, so here's an example of that for reference (this eliminates 2 frames of delay, works fine with regular frame advance controls, and doesn't cause graphical or audio weirdness):
local tempsave = savestate.create()
local recursing = false
emu.registerbefore(function()
	if recursing then return else recursing = true end
	emu.emulateframeinvisible()
	savestate.save(tempsave)
	emu.emulateframeinvisible()
	recursing = false
end)
emu.registerafter(function()
	savestate.load(tempsave)
end)
But that script won't work in Snes9x because the following things are missing from Snes9x Lua:
  1. a way to emulate a frame without pausing afterward if the user is using the frame advance hotkey (this one really hurts)
  2. a way to emulate frames within callbacks such as emu.registerbefore (but, workarounds exist)
  3. a way to load a savestate without rendering it (workarounds exist)
Player (199)
Joined: 12/3/2006
Posts: 151
nitsuja wrote:
But that script won't work in Snes9x because the following things are missing from Snes9x Lua:
  1. a way to emulate a frame without pausing afterward if the user is using the frame advance hotkey (this one really hurts)
Indeed, that's the functionality I was missing in my current implementation. I guess I could simply bind the pause hotkey to my current frameadvance button and be done with it. With some simplifications (and turning off savestate compression), the script now runs at about 10 fps which is reasonable.
Language: lua

function customFrameAdvance() savestate.save(mySave) emu.frameadvance() getCollisionData() savestate.load(mySave) drawCollisionData() emu.pause() end
Post subject: more-intellegent-than-a-hexeditor
Player (138)
Joined: 9/18/2007
Posts: 389
Well... I think this Lua script is a nice alternative to using a hexeditor. The best thing is that you can instantly see any in-game changes you do to the initial file. It takes some time to get used to it, but it works as intended. Just wanted to share it with you, so it can become even better. (the tablehandling.lua file is only for saving and loading) Edit: I'm trying to build a GUI for the above script with IUP. It's somewhat strange, but now the "tablehandling" part will make the emulator crash. This file has a minimum example for that. starting "no-crash.lua" and pressing F12 + frameadvance will load a big table (~6mb). if you start "iup-crash.lua", and click the "load" button, which attempts to load the same table with the very same function, it will crash. if you replace recorded.txt with t.txt (a much smaller table), both will work fine. Any idea what caused the crash?
Post subject: Re: New ghost script for Super Mario World
Former player
Joined: 2/19/2007
Posts: 424
Location: UK
amaurea wrote:
I have adapted the old Super Metroid TAS comparison scripts for Super Mario World. Here is an example of the script in action: http://www.youtube.com/watch?v=ieFFCRQBIeo http://www.youtube.com/watch?v=imsRpZ-WEds And here are the scripts themselves, along with two resource files: http://folk.uio.no/sigurdkn/smwrecord.lua http://folk.uio.no/sigurdkn/smwplayer.lua http://folk.uio.no/sigurdkn/smwdb.map http://folk.uio.no/sigurdkn/smwdb.png Surprisingly, making the super mario world version of this script was much harder than making the super metroid version, mostly because of inconsistent delays between when values appear in handy memory addresses and when things update on screen, as well as many composite sprites (the yoshi portion of the script is still somewhat hacky). Most of the options from the super metroid version are still there: You can choose between realtime and in-game modes (which make much less difference here than in super metroid. The video above was made using realtime mode.) both for displaying and syncing, and you can turn per-room resyncing on or off. Note that room syncing is not used on the overworld, so you can easily see the runs' relative position there. For using the script yourself, the procedure is the same as before: 1. Generate ghost files, which are text files containing destilled information about a run. This is done by loading the script smwrecord.lua, and then loading the movie file. Once you are done (fast forward does not disturb the script), exit the emulator, and a file named ghost.dump has been generated. Rename this to something sensible. Repeat this for each run you want to compare to. 2. Edit smwplayer.lua. What needs editing is only the the topmost portion. Edit the ghost_dumps list to indicate the dump files you generated earlier. 3. Load smwplayer.lua in snes9x, and either try playing against the ghosts yourself, or load a movie file. You will require the gd library for lua for this; otherwise you can only display hitboxes etc.
The script now supports continuous offsets instead of just room offsets, and the offsets displayed can be controlled independently from the offsets actually used for the ghosts. The offsets used for the delays at the top are now calculated to sub-frame precision based on the ghost speed and distance from closest ghost pixel to the current player position. The status display has been corrected and expanded to show more useful information. Here is a demonstration of the script in action: http://www.youtube.com/watch?v=gRSVOPzxsKQ The new version can be found at the same locations listed above. Note that the ghost dump format has been changed, so you will need to rerun smwrecord.lua to generate new ghosts.
Post subject: Re: New ghost script for Super Mario World
Lil_Gecko
He/Him
Player (98)
Joined: 4/7/2011
Posts: 520
amaurea wrote:
The new version can be found at the same locations listed above. Note that the ghost dump format has been changed, so you will need to rerun smwrecord.lua to generate new ghosts.
Seems really nice but I can't manage to make it work. SmwRecord has no problem, SmwPlayers starts as it should, but when it has to draw the ghost I got an error. "SmwPlayer.lua:607: attempt to index field '?' (a nil value) (Could not load ../smwdb.png!) Also, smwdb.png is in the right directory and I got the gd librairy so I don't understand. Any ideas ?
Post subject: Re: New ghost script for Super Mario World
Former player
Joined: 2/19/2007
Posts: 424
Location: UK
Lil_Gecko wrote:
amaurea wrote:
The new version can be found at the same locations listed above. Note that the ghost dump format has been changed, so you will need to rerun smwrecord.lua to generate new ghosts.
Seems really nice but I can't manage to make it work. SmwRecord has no problem, SmwPlayers starts as it should, but when it has to draw the ghost I got an error. "SmwPlayer.lua:607: attempt to index field '?' (a nil value) (Could not load ../smwdb.png!) Also, smwdb.png is in the right directory and I got the gd librairy so I don't understand. Any ideas ?
Oh, right. During tested I changed it to ../smwdb.png instead of smwdb.png, and forgot to change it back. I have uploaded a fixed version now.
Post subject: Re: New ghost script for Super Mario World
Lil_Gecko
He/Him
Player (98)
Joined: 4/7/2011
Posts: 520
amaurea wrote:
Oh, right. During tested I changed it to ../smwdb.png instead of smwdb.png, and forgot to change it back. I have uploaded a fixed version now.
Working perfect now. Thanks.
Player (160)
Joined: 5/20/2010
Posts: 295
I hope these scripts will help you decide where to put a “gui.text.”
function MousePosition()
	local ip = input.get()
	
	if ip.xmouse <= 0 then
		ip.xmouse = 0
	end
	if ip.xmouse >= 253 then
		ip.xmouse = 253
	end
	if ip.ymouse <= 0 then
		ip.ymouse = 0
	end
	if ip.ymouse >= 217 then
		ip.ymouse = 217
	end
	
	gui.text( ip.xmouse, ip.ymouse, string.format ( "(%d,%d)",  ip.xmouse, ip.ymouse ) )
end
function DrawGridLines()
--~ 	First Display Parameters on Coordinates.
--~ 	Top
	for i = 0, 240, 20 do
		gui.text ( i, 0, string.format ( "%d", i ) )
	end
--~ 	Left
	for j = 0, 200, 20 do
		gui.text ( 0, j, string.format ( "%d", j ) )
	end
--~ 	Bottom
	for k = 20, 220, 20 do
		gui.text ( k, 217, string.format ( "%d", k ) )
	end
--~ 	Right
	for l = 20, 200, 20 do
		gui.text ( 244, l, string.format ( "%d", l ) )
	end
--~ 	Then Draw GridLines.
--~ 	Axial
	for m = 0, 250, 10 do
		if m % 50 == 0 then
			c = "red"
		else
			c = "white"
		end
		gui.line ( m, 0, m, 225, string.format ( "%s", c ) )
	end
--~ 	Equatrial
	for n = 0, 225, 10 do
		if n % 50 == 0 then
			c = "red"
		else
			c = "white"
		end
		gui.line ( 0, n, 255, n, string.format ( "%s", c ) )
	end
end
Site Admin, Skilled player (1255)
Joined: 4/17/2010
Posts: 11495
Location: Lake Char­gogg­a­gogg­man­chaugg­a­gogg­chau­bun­a­gung­a­maugg
Hey guys please look into that thread: "TASVideos Lua" project
Warning: When making decisions, I try to collect as much data as possible before actually deciding. I try to abstract away and see the principles behind real world events and people's opinions. I try to generalize them and turn into something clear and reusable. I hate depending on unpredictable and having to make lottery guesses. Any problem can be solved by systems thinking and acting.
Former player
Joined: 2/19/2007
Posts: 424
Location: UK
Here is a comparison script for Mega Man X. It works similarly to the one for Super Mario world: You use mmxrecord.lua while playing back an .smv to make a ghost file for that TAS, and then use mmxplayer.lua to compare a set of ghost files with an .smv. At the top of a script is a configuration setting, where you can control whether to skip non-level gameplay, whether to display the status line, what sort of offsets to display, etc. A change from the super mario world script is the addition of a "relative" setting for the offset display. It displays how many frames were gained since the beginning of the level, based on X-posiiton in the level. Here is a video demonstrating the script in action: Link to video
Post subject: Yoshi's Island comparison script
Former player
Joined: 2/19/2007
Posts: 424
Location: UK
I have ported the comparison script to Yoshi's Island. The script can be found here: http://folk.uio.no/sigurdkn/yicomp.zip It works much like the previous scripts (Super Metroid, Mega Man X, Super Mario Bros, Super Mario World): First run yirecord.lua while playing back each .smv file you want to compare. Then edit the list of "ghost" files to use at the top of yiplayer.lua (you can also change some simple settings up here, like what information to display). After that, simply play back the .smv file you want to compare the others to while running yiplayer.lua. A comparison made using this script will eventually be available below: Link to video
Editor, Skilled player (1348)
Joined: 12/28/2013
Posts: 396
Location: Rio de Janeiro, Brasil
I'm with a problem... I've already downloaded gd.dll but the comparison video lua script still doesn't work... Is there anything else that I have to do?
My YouTube channel: https://www.youtube.com/channel/UCVoUfT49xN9TU-gDMHv57sw Projects: SMW 96 exit. SDW any%, with Amaraticando. SMA2 SMW small only Kaizo Mario World 3
1 2
8 9