Friday, May 25, 2012

What is the use of a book without pictures?

Since the last post I've worked on the screenshots feature. There was few requirements:
1) During the recording process screenshots should record into the same file as other evetns
2) It should be possible to setup period of screenshot recording
3) During the playback process screenshots should read from playback file and compare with current game screen. Best of all it would do using MD5 hash, so it must be recorded with image data.

Recording of screenshots  I've implemented quite fast using the existing code of thumbnails for save files. It has some restrictions like saving screenshots only in 5-6-5 bmp format, but I'm sure it's quite enought for most emulated games.
I've decided to write it with other events in RCDS chunk. So, during the playback it will be simple to react on screenshot and determine time when it need be compared it with the current screen. Then I wrote a simple viewer for  screenshots. Result of my actions you may see on the following video:
While I was working on this viewer, I understood that representing screenshots as events is not very good for navigating through the file. And then decided to change conceptions and hold screenshots and arrays of events in separate chunks. It gives viewer ability to navigate very fast to any place in playback file.
Then I wrote the playback part. There was nothing interesting to told about. Just opposite actions: read images instead of write it. But while I was testing playback I got an error with cache (screenshots writed not in the same time they was made, and I got random waring of screenshots difference during the playback). To find this bug I begin to save screenshots in playback time and extended the vewer. In new version it shows difference between recorded and played back screenshots. You may see it in this video.
Principle of it's work is very simple: it compare each pixel on 2 pictures and if they are equal, copy them to the result pixel, if they aren't equal  fill result pixel by white color.
After I've found that error, I add comparing by MD5 hash (thanks to previous developers all routins for this was implemented before).

BONUS: just for fun and to improve my web programming skills, i've wrote simple viewer of playback files in javascript using the jDataView class.But i must warn you than I'm not very good in javascript, so it may contain bugs memory leaks, not work in your browser an so on. Also it loads 2Mb replay file. If you still want to try it in browser, you may do it there If not, I've written a little video for you:

No comments:

Post a Comment