EMC wraparound off-by-one bug?

Found a bug in R'n'D? Report it here!

Moderators: Flumminator, Zomis

filbo
Posts: 647
Joined: Fri Jun 20, 2014 10:06 am

EMC wraparound off-by-one bug?

Post by filbo »

I'm looking at 'The Exception 2' level 34 (levels/Emerald Mine Club/emc_exception_2/34). It has a pair of horizontal growing walls on the left side of the playfield, which immediately grow and wrap around to the right when the level starts. The growing walls are at Y coordinates 20 and 22. There is an opening in the otherwise solid wall of the level on the right side, at Y coordinate 20. To complete the level you need to walk out that opening and wrap around the playfield to retrieve the red key. But the growing wall at Y=20 has blocked it off long ago!

The level design seems to imply that on the game engine the author was playing, the playfield wrapped with an off-by-one on the Y coordinate; like a line of text too long for one's terminal.

Which, it seems to me, is exactly how wraparound would work, if it were not a careful conscious design choice but just a consequence of looking at the entire playfield as one long line with peculiar adjacency between positions one row's worth of positions apart.

Do you know if the original Amiga EMC engine behaved that way? I think you have the ability to run it and its editor -- I don't. I guess a trivial test would be: start with a blank playfield, add one horizontal growing wall (and a player), start the level. As the wall grows to the edges of the level, does it meet itself or miss by one (in which case it will eventually fill the entire level since there's nothing to obstruct it) ?

If the original engine behaves that way, R'n'D should too.

If not, I am puzzled at this level's design. It seems pretty clear that it was created under an engine that behaves that way, and if it wasn't under EMC, where was it created?
User avatar
Holger
Site Admin
Posts: 4073
Joined: Fri Jun 18, 2004 4:13 pm
Location: Germany
Contact:

Re: EMC wraparound off-by-one bug?

Post by Holger »

You are perfectly right with your suspicion, and I was only waiting for the day that this would happen.

From file "src/game_em/reademc.c":

Code: Select all

/* convert emc caves to intermediate cave format.
...
 * borderless caves are supported, almost the same as in the emc
 * player. going off the left edge of the screen resulted in the
 * beast/player moving up 1 square (and the player disappeared).
 * going off the right edge of the screen, the beast/player would
 * go down 1 square. in my player, everything stays on the same y
 * coord, which is sensible, but breaks caves which expect the old
 * behaviour.
  */
 
I was thinking about this quite some time when I integrated the new "Emerald Mine for X11" source code, and especially checked those wrap-around levels that I knew of. For all levels that I checked, the "fixed" behaviour seemed to be fine.

So you've found the inevitable case of a wrap-around level now where it does not work that way.

Conclusion: Maybe the EM engine should work as it worked in the original game also in this regard. I'll check how much effort it will be to "fix the fix"... :-)
filbo
Posts: 647
Joined: Fri Jun 20, 2014 10:06 am

Re: EMC wraparound off-by-one bug?

Post by filbo »

As I was googling last night for "emerald mine" "wrap", one of the main things I ran into was the 2010 flamewar between you & Dave (t=1976), in which he constantly insisted that his engine's EMC emulation was perfect while all of your work was trash. wheeee. (It is also obvious at a glance that he wrote big chunks of the wikipedia R'n'D page...)

Since engines exist with both arrangements (i.e.: emeraldx11), it must be anticipated that by now, levels exist which individually require both behaviors. So I think this needs a 'guidance chunk' (or bit) like the 64-bit bug -- something that can be tagged into a level file to specifically identify which wrap strategy it requires. And I suggest you make this tri-state: absent, 'direct wrap', or 'off-by-one wrap'. 'Absent', i.e. the same exact bits as the level has today, signifies that it has not been evaluated in this regard; which has two sub-classes (which don't require differentiation): level doesn't interact with wrap issues whatsoever, or level 'works' regardless of wrap strategy. vs. levels which have been specifically seen & evaluated to require one wrap strategy or the other.

Hmmm. But it's even slightly worse. Levels which 'work' with either wrap strategy do so because the player adapts to the 'facts on the ground'. A tape recorded from such a level would quite likely fail if playback were done with the other wrap strategy, even though a live player would have succeeded (being able to see that e.g. the yams' motions are different, or the pile of rocks fell in a different pattern). So I think that whereas levels do not always require a stamp indicating a required wrap strategy, tapes in which any wrapping is potentially possible do require such a stamp. Including a test in '-e autofix'! :) (For autotesting purposes, the first test pass could keep a boolean as to whether any wrap interaction happened at all; retesting with the other wrap strategy is only needed if (1) the tape failed and (2) wrap was a possible factor. And, perhaps such a runtime indicator isn't 100% necessary; as a proxy, the evaluation of 'is the entire level surrounded by steelwall?' will never miss a level which needs retesting, and will only unnecessarily retest a handful of levels...)
jm28121977
Posts: 84
Joined: Thu Aug 16, 2018 8:04 pm
Location: England

Re: EMC wraparound off-by-one bug?

Post by jm28121977 »

I've just read that flamewar. That dude has some serious anger issues. I'd have found it hard to remain so polite and respectful if repeatedly addressed in that manner. Hats off to you, Holger.

Jamie x
User avatar
Holger
Site Admin
Posts: 4073
Joined: Fri Jun 18, 2004 4:13 pm
Location: Germany
Contact:

Re: EMC wraparound off-by-one bug?

Post by Holger »

Thank you, Jamie x! :)
User avatar
Holger
Site Admin
Posts: 4073
Joined: Fri Jun 18, 2004 4:13 pm
Location: Germany
Contact:

Re: EMC wraparound off-by-one bug?

Post by Holger »

(It is also obvious at a glance that he wrote big chunks of the wikipedia R'n'D page...)
Yes, that's right; you can also see that in the page edits. (The worst stuff was removed by some other editors... I always wanted to clean up that mess a bit, not mainly because of Dave's "contributions" to that page, but because some things are outdated, and the page could need a bit more structure. But I always thought it might look like advertisement if I should edit my own game's page... ;-) )
Since engines exist with both arrangements (i.e.: emeraldx11), it must be anticipated that by now, levels exist which individually require both behaviors.
I think this is not the case, fortunately. There should only be levels out there that were build with the original ("off by one") behaviour in mind (even though some apparently also work well with the "fixed" behaviour -- it just depends on the level design). The whole EMC collection levels came from EMC disks that expected the engine to work "off by one". And I know of no single level that was created exclusively for "Emerald Mine for X11" (which did not support wrap-around levels itself for quite some time).

So supporting only the "off by one" behaviour (and drop the current "fixed" behaviour) would be fine here.
filbo
Posts: 647
Joined: Fri Jun 20, 2014 10:06 am

Re: EMC wraparound off-by-one bug?

Post by filbo »

I'm dubious, but there is at least a great deal of weight on the 'off-by-one' side and unlikely to be a whole lot on the other. (Ah, and I see emeraldx11 doesn't have its own level editor, so that helps quite a bit...)
User avatar
Holger
Site Admin
Posts: 4073
Joined: Fri Jun 18, 2004 4:13 pm
Location: Germany
Contact:

Re: EMC wraparound off-by-one bug?

Post by Holger »

I've changed the EM game engine logic for handling wrap-around levels to the "off by one" behaviour now. There is a flag that can be set to enable "true infinite wrap-around" to get the "perfect", but incompatible behaviour, but the default is "use what works for existing levels" (which is the off-by-one thing). (This flag could be set for R'n'D levels using the EM engine between versions 4.2.0.0 and 4.2.0.3, but I think it is not worth considering this, as there are most probably no levels that use this other than my test levels. ;-) )

I've just pushed that stuff to the repo (together with a handful of other tweaks and fixes), so you might want to give it a try. Level 34 of "The Exception 2" should work fine now!
filbo
Posts: 647
Joined: Fri Jun 20, 2014 10:06 am

Re: EMC wraparound off-by-one bug?

Post by filbo »

Well, I'll be grabbing and building that my-logical-tomorrow :)

Sounds good!
filbo
Posts: 647
Joined: Fri Jun 20, 2014 10:06 am

Re: EMC wraparound off-by-one bug?

Post by filbo »

There remains one tiny problem, which doesn't really need fixing, but could be:

When in single-step mode, if you step past the left/right end of the screen (thus wrapping), the display remains focused on the place you wrapped from. It corrects on the next input key, even if it's just a quick press of Ctrl to advance time. I imagine it probably does the same in realtime play -- except the bad state would last for such a short time that nobody would notice; it would be hard to detect even knowing what to look for.
filbo
Posts: 647
Joined: Fri Jun 20, 2014 10:06 am

Re: EMC wraparound off-by-one bug?

Post by filbo »

emc_exception_2/34 is solved! (now stuck on 45... I can get all the emeralds and within breathing distance of the exit, but that damn balloon... and no, can't get out / back to where I came from, then trek all the way across the level to go outside and wrap around to those other exits... a single dynamite, or an up-balloon arrow above the down one, would fix it...)
User avatar
Holger
Site Admin
Posts: 4073
Joined: Fri Jun 18, 2004 4:13 pm
Location: Germany
Contact:

Re: EMC wraparound off-by-one bug?

Post by Holger »

When in single-step mode, if you step past the left/right end of the screen (thus wrapping), the display remains focused on the place you wrapped from. It corrects on the next input key, even if it's just a quick press of Ctrl to advance time. I imagine it probably does the same in realtime play -- except the bad state would last for such a short time that nobody would notice; it would be hard to detect even knowing what to look for.
Yes, that's correct: The visible wrapping happens right before the next "game frame" (8-frame cycle, to be precise) after completing the player's movement that causes the wrap. Updating the new player position earlier (to the wrapped position on the opposite side of the level) would cause incorrect animations.

However, I agree that the current single-step mode in the EM engine is not optimal when it comes to wrapping. Therefore, I have added a workaround that updates the screen one (real) frame earlier when (a) single-step mode and (b) wrapping was detected. This still does not look 100% graphically correct (the player faces downwards after wrapping instead of left or right), but at least it should prevent the one "blind frame cycle" in between single-step moves, and should be as close as possible to what would be expected. (When comparing this to how the native Supaplex game engine handles wrapping with single-step mode, this is even worse, as it takes several steps before the player is visible again. This really needs to be improved, as it affects playability much more than the tiny problems of the EM engine...)

Just pushed the workaround to the repository...
filbo
Posts: 647
Joined: Fri Jun 20, 2014 10:06 am

Re: EMC wraparound off-by-one bug?

Post by filbo »

I just went to pull that and ... did you forget to push to repo? I've got that origin/HEAD is at 5eec6f3
User avatar
Holger
Site Admin
Posts: 4073
Joined: Fri Jun 18, 2004 4:13 pm
Location: Germany
Contact:

Re: EMC wraparound off-by-one bug?

Post by Holger »

Argh... I assume I typed "git pull" instead of "git push" before going to bed yesterday! :shock:

I'll post an update here as soon as I really pushed the commit to the repo (no access from here at work to my home PC, unfortunately).
filbo
Posts: 647
Joined: Fri Jun 20, 2014 10:06 am

Re: EMC wraparound off-by-one bug?

Post by filbo »

It is not that urgent! :)
Post Reply