Sonic and Sega Retro Message Board: Gens Rerecording / Lua issue - Sonic and Sega Retro Message Board

Jump to content

Hey there, Guest!  (Log In · Register) Help
  • 2 Pages +
  • 1
  • 2
    Locked
    Locked Forum

Gens Rerecording / Lua issue This really scuppers a project of mine, I'd appreciate any insight

#1 User is offline Mercury 

  Posted 03 September 2014 - 07:53 PM

  • His Name Is Sonic
  • Posts: 1711
  • Joined: 13-November 08
  • Gender:Not Telling
  • Location:Location Location
  • Project:AeStHete
  • Wiki edits:130
I'm encountering some strange behaviour in Gens Rerecording with Lua.

I wanted to start making something simple that drew Sonic's collision mask on top of his sprite, so I got the camera coordinates and Sonic's coordinates, subtracted the former from the latter, and drew a box at the resulting position. No matter what I did, though, the box would always flicker and jump around randomly.

It turned out this was because memory.readword() and its ilk were giving me incorrect values, and I have made a test script to demonstrate (meant for Sonic 2).

timer = 0;
timerp = 0;
diff = false;
count = 0;

gens.registerafter( function()

	timerp = timer;
	timer = memory.readword(0xfffe04);
	if (timer == timerp) then diff = true;
	else diff = false;
	end
end)

gui.register( function ()

	message = string.format("Timer: $%X, %d", timer, count)
	gui.text(10, 50, message, "#FFFF00FF", "black")
	
	if (diff) then gui.drawbox(0, 0, 320, 224, "black", "black");
	count = count + 1;
	end
end)



Because the game timer is supposed to count up by 1 every frame, it's easy to tell if memory.readword() is reading the new value correctly or not. Each time it gets it wrong (and returns the value from the last frame), I increase a counter and make the screen flash black to make it obvious this is happening.

It doesn't matter if I try to get the value in gens.registerafter(), gens.registerbefore(), or in gui.register(), or even if I put hooks in when the memory is written to. I will still get a bad value from 1 frame ago sometimes.

Oddly, this seems to only happen when the screen is scrolling. If you stand Sonic still, it won't happen.

Furthermore, it's not just my Lua code. The RAM watch feature has the same issue, which can be seen if you watch an increasing value such as the timer and use frame advance, sometime it will not update.

I'm pretty much at my wits' end when it comes to this, because it prevents any kind of useful overlays on objects, making it a showstopping issue. Has anyone here ever experienced this, and do you know what might be the cause or the solution?

(It happens in Gens Rerecording v11a as well as the latest version at Google code.)
This post has been edited by Mercury: 03 September 2014 - 10:13 PM

#2 User is offline flamewing 

Posted 03 September 2014 - 08:20 PM

  • Emerald Hunter
  • Posts: 831
  • Joined: 11-October 10
  • Gender:Male
  • Location:Brasil
  • Project:Sonic Classic Heroes; Sonic 2 Special Stage Editor; Sonic 3&K Heroes (on hold)
  • Wiki edits:12
I don't know about preventing useful overlays; but maybe you can treat it as a bug and report it over at their Google code project?

#3 User is offline Mercury 

Posted 03 September 2014 - 10:19 PM

  • His Name Is Sonic
  • Posts: 1711
  • Joined: 13-November 08
  • Gender:Not Telling
  • Location:Location Location
  • Project:AeStHete
  • Wiki edits:130

View Postflamewing, on 03 September 2014 - 08:20 PM, said:

I don't know about preventing useful overlays; but maybe you can treat it as a bug and report it over at their Google code project?

Oh, I only meant overlays on objects. When it comes to stationary HUDs there are lots of good scripts.

I don't know how active the project still is, but I will report it and see what comes of it.

#4 User is offline sonicblur 

Posted 04 September 2014 - 07:23 PM

  • Posts: 848
  • Joined: 18-February 08
  • Gender:Male
  • Wiki edits:6
If Gens continues to frustrate you, why don't you try writing the same script for BizHawk instead? It supports Lua, and it uses Genesis Plus GX which should be far more accurate than Gens. Since it's under active development you'd probably be more likely to get anything fixed that you need. One of the example genesis scripts that comes with it draws hitboxes for castlevania, so you'd at least have a sample to work from.

Sorry if this isn't something you wanted to hear, I just like to take the opportunity to promote it whenever I can. (I maintain the Mac OS X port of it, which doesn't have Lua, but I'll probably add it some day)
This post has been edited by sonicblur: 04 September 2014 - 07:23 PM

#5 User is offline flamewing 

Posted 04 September 2014 - 07:26 PM

  • Emerald Hunter
  • Posts: 831
  • Joined: 11-October 10
  • Gender:Male
  • Location:Brasil
  • Project:Sonic Classic Heroes; Sonic 2 Special Stage Editor; Sonic 3&K Heroes (on hold)
  • Wiki edits:12
Ah, so it is you that maintain that port. I have been trying to get it to work on Linux, with zero success; which is why I haven't mentioned it at all.

#6 User is offline sonicblur 

Posted 04 September 2014 - 07:39 PM

  • Posts: 848
  • Joined: 18-February 08
  • Gender:Male
  • Wiki edits:6

View Postflamewing, on 04 September 2014 - 07:26 PM, said:

Ah, so it is you that maintain that port. I have been trying to get it to work on Linux, with zero success; which is why I haven't mentioned it at all.

Going off topic now, but both Genesis and Lua won't work on Linux anyway even if you get it to run. All of the native cores like Genesis Plus are separate DLL's on the windows version, and they need to be ported to work on Linux. Genesis Plus and a few of the other native cores work on OS X because I've done native builds of them. (.dylib on OS X, .so on linux) In the case of Genesis Plus, getting it to work on Linux should be pretty easy. The code basically compiles out of the box, you just need to set up a build for it somehow. On OS X I made Xcode projects for everything, so it was just a matter of opening the project and hitting build.

The current Lua implementation uses managed c++, which isn't supported in Mono. At some point I'd like to switch it to use Pinvoke so it can be called the same way Genesis Plus and the other native cores are. If I ever do that, it would work the same as any of the cores where as long as it finds an .so or .dylib where windows expects a DLL, it will just work.

Having said all of that, the TasVideos Genesis forum might be a better place to get help with re-recording emulators if nobody here knows the answer.
This post has been edited by sonicblur: 04 September 2014 - 07:41 PM

#7 User is offline Mr Lange 

Posted 04 September 2014 - 08:22 PM

  • A wise guy eh. I know how to DEAL with wise guys.
  • Posts: 895
  • Joined: 27-August 10
  • Gender:Male
  • Location:The Land of Waldos
  • Project:Helix, NASF DX, Sonic Overture
  • Wiki edits:1
Thank you for bringing this up Mercury because this explains exactly the issue I've had. Me and a friend made a lua script a couple years ago that was attempting to output Sonic's position and the Camera's position every frame into a script in order to match it to footage in another program. The position data would always come out skewed and not match the footage. We kept thinking the formula interpreting the data was wrong and any tweaks would just result in a different kind of skewing even when sure it would work. Now I know it wasn't the script's fault.

#8 User is offline nineko 

Posted 04 September 2014 - 09:38 PM

  • I am the Holy Cat
  • Posts: 5341
  • Joined: 17-August 06
  • Gender:Male
  • Location:italy
  • Project:I... don't even know anymore :U
  • Wiki edits:5,251

View Postsonicblur, on 04 September 2014 - 07:39 PM, said:

The TasVideos Genesis forum might be a better place to get help with re-recording emulators if nobody here knows the answer.
lol, I can't even read "tasvideos" and "help" in the same sentence with a straight face, as elitists as they are (minus a few rare exception) I wonder why the forums are still open for new registrations at all when they'd clearly just like to ban everyone.

#9 User is offline Tribeam 

Posted 05 September 2014 - 11:14 AM

  • I code Lua and Lua accessories
  • Posts: 67
  • Joined: 08-January 07
  • Gender:Male
I have no idea whats going on here. I have done alot of testing and coding to try to figure this out to no results, my guess is that this is a gens rerecording bug.

Edit:

Quote

I wanted to start making something simple that drew Sonic's collision mask on top of his sprite, so I got the camera coordinates and Sonic's coordinates, subtracted the former from the latter, and drew a box at the resulting position. No matter what I did, though, the box would always flicker and jump around randomly.


In my debugEx script, this also happens, but ONLY for the player object, all other objects seem synced up just fine, as demonstrated by this gif:
(the second box on the player is the shield obj)
Posted Image
This post has been edited by Tribeam: 05 September 2014 - 04:30 PM

#10 User is offline ZanaGB 

Posted 05 September 2014 - 04:34 PM

  • The Candy Bun
  • Posts: 9
  • Joined: 22-August 14
  • Gender:Female
  • Location:Madrid
Well. I am not the most knowledgeable person regarding how this goes. but I definetly know that BizHawk offers support for LUA scripting and a far more accurate emulation core. Maybe you should try rewritting the script for BH, since it looks like Gens is not doing it's job properly ( as usual ). I do not think rewritting it should be much of an issue though.
This post has been edited by ZanaGB: 05 September 2014 - 04:35 PM

#11 User is offline Mercury 

Posted 05 September 2014 - 04:58 PM

  • His Name Is Sonic
  • Posts: 1711
  • Joined: 13-November 08
  • Gender:Not Telling
  • Location:Location Location
  • Project:AeStHete
  • Wiki edits:130

View Postsonicblur, on 04 September 2014 - 07:23 PM, said:

If Gens continues to frustrate you, why don't you try writing the same script for BizHawk instead?

View PostZanaGB, on 05 September 2014 - 04:34 PM, said:

Well. I am not the most knowledgeable person regarding how this goes. but I definetly know that BizHawk offers support for LUA scripting and a far more accurate emulation core.

Thanks for recommending BizHawk, I'd never heard of it and it's great to have more options. Unfortunately, though, when I rewrote the script for BizHawk and tried it out, the exact same thing happened - only worse, as it now happens even when the screen is not scrolling.

View PostMr Lange, on 04 September 2014 - 08:22 PM, said:

Thank you for bringing this up Mercury because this explains exactly the issue I've had. Me and a friend made a lua script a couple years ago that was attempting to output Sonic's position and the Camera's position every frame into a script in order to match it to footage in another program. The position data would always come out skewed and not match the footage. We kept thinking the formula interpreting the data was wrong and any tweaks would just result in a different kind of skewing even when sure it would work. Now I know it wasn't the script's fault.

Glad to have helped clear up such a long-standing mystery!

View PostTribeam, on 05 September 2014 - 11:14 AM, said:

I have no idea whats going on here. I have done alot of testing and coding to try to figure this out to no results, my guess is that this is a gens rerecording bug.

Edit:

Quote

I wanted to start making something simple that drew Sonic's collision mask on top of his sprite, so I got the camera coordinates and Sonic's coordinates, subtracted the former from the latter, and drew a box at the resulting position. No matter what I did, though, the box would always flicker and jump around randomly.


In my debugEx script, this also happens, but ONLY for the player object, all other objects seem synced up just fine, as demonstrated by this gif:
(the second box on the player is the shield obj)
Posted Image

I'm starting to think it might have something to do with the Sonic engine itself, and maybe the values being looked at aren't correct at the end of each frame? (Also, no problem about not answering my PM right away. :) )

In good(ish) news I've made a little bit of progress. I realised I could use GUI functions in any event, so I put the code in an event that occurs when the timer is updated. Now it works, moving synchronously with Sonic (more or less; it's still one frame off, but that's merely because of when the timer is updated).

However, even though I'm now getting the correct values, the GUI fails to draw sometimes, causing the overlay to flicker. It's better than jumping around, so that's something!

Here's the new script (for Gens, still):

Spoiler


#12 User is offline Tribeam 

Posted 05 September 2014 - 05:01 PM

  • I code Lua and Lua accessories
  • Posts: 67
  • Joined: 08-January 07
  • Gender:Male
So I took a brief look at BizHawk, and I have to say it has definitely taken my attention away from gens rerecording, the lua library it offers looks far more feature rich...I shall post here with results as I mess with it...

Edit

Quote

Stuff Mercury said

I'm starting to think it's with the sonic engine as well, in my debug script, I've noticed that sonic's position seem to do the same thing as the level counter(same a previous frame, randomly) but other positional data doesn't do this, such as the camera's position, and all other objs, interesting....
This post has been edited by Tribeam: 05 September 2014 - 05:15 PM

#13 User is offline sonicblur 

Posted 05 September 2014 - 06:08 PM

  • Posts: 848
  • Joined: 18-February 08
  • Gender:Male
  • Wiki edits:6

View PostMercury, on 05 September 2014 - 04:58 PM, said:

Thanks for recommending BizHawk, I'd never heard of it and it's great to have more options. Unfortunately, though, when I rewrote the script for BizHawk and tried it out, the exact same thing happened - only worse, as it now happens even when the screen is not scrolling.

If you can provide a simplified example either here or privately, I can submit a bug report for it if you don't want to. And perhaps look at the code, but no promises on that. I've seen them add random lua functionality that people have asked for rather quickly, so I think the odds are reasonable that if there's no technical reason why it behaves that way they'd probably want to see it fixed.

#14 User is offline Tribeam 

Posted 05 September 2014 - 07:40 PM

  • I code Lua and Lua accessories
  • Posts: 67
  • Joined: 08-January 07
  • Gender:Male
This doesn't happen nearly as often in Sonic3K as it does in Sonic2, and in Sonic1, it's pretty much every other frame, further pushing the idea it's an engine issue.
This happens in both emulators.

Here's a Bizhawk Lua script that puts a box over every obj in Sonic3K
This shows that the GUI is kinda lagged behind on the current frame, also the player's box has a jitter, but is FAR less jittery than Gens.

Spoiler


This is a BizHawk version of mercury's level frame counter tester, this works in sonic1, 2, and 3(k)
Spoiler

This post has been edited by Tribeam: 05 September 2014 - 07:43 PM

#15 User is offline sonicblur 

Posted 05 September 2014 - 07:45 PM

  • Posts: 848
  • Joined: 18-February 08
  • Gender:Male
  • Wiki edits:6
For what it's worth, we discussed it a bit on #bizhawk
Spoiler


I looked at the code for Lua in BizHawk and it does have hooks that execute before and after every frame. I'll try the script above and see if I learn anything.

Edit: Okay, so at least in the case of BizHawk, this doesn't look like a bug. Just open the memory viewer and watch the values yourself. On the frames that flash black, the timer address does not change. On the following frame, it only goes up by 1. So it's not as if it is skipping a value, it just isn't being updated on that frame. I noticed it never happens when you're standing still, but if you let the spring at the end of EHZ1 just push you up the slope at the end so you endlessly go forward and back down, you'll see it skip updates for a few frames every trip back down.

I think this is just a case of the game not working the way you think it should. If you can provide any evidence to the contrary, I'm still willing to try and get you help with this.
This post has been edited by sonicblur: 05 September 2014 - 08:18 PM

  • 2 Pages +
  • 1
  • 2
    Locked
    Locked Forum

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users