Lemmings Forums

Lemmings Boards => Tech & Research => Topic started by: Aaron44126 on May 21, 2020, 01:19:50 PM

Title: [BUG][LEMMIX PLAYERS] Bomber/explosion particles not cleaned up until scroll
Post by: Aaron44126 on May 21, 2020, 01:19:50 PM
Not sure where to post this; I'm posting it in the NeoLemmix bugs forum, but this is not a bug with NeoLemmix; I am experiencing it with the classic Lemmix "players" that can be found on the NeoLemmix web site.  https://www.neolemmix.com/?page=download_list&program=42

The bug is, after having a lemming blow up with the "bomber" skill, the explosion causes guts/particles to fly into the air.  Once the animation is done, the particles are often (usually?) not cleaned up, so a small number of particles remain suspended in the air.  They will be cleaned up once the stage is scrolled, or if there is another explosion.

(https://vlbioq.bn.files.1drv.com/y4mcgaqzd6guufnyx5fAGVgAW4mxxjgvxdSnXsz0ouGxKJ55D4O9-ee3AqbdhTs9e_u0HqfRH6y-V4KFfWqOaLXoszil_4jR8DoIIbXcGq_lLDfG6qA2UEyO1JT-fe_PTRI7LocxJ-sZKpGj_kBwaImBnWTtW3YGw3XLI9QzZX0HIVDpvHt9DCAjgPE2AmCOGfULZe1BJ_C5O2cnrj1stTwrw?width=1024&height=640&cropmode=none)

Not sure if these are maintained anymore; if not then I will take a stab at fixing this myself, since the player source code is available, but I am not sure how I would publish the results.
Title: Re: [BUG][LEMMIX PLAYERS] Bomber/explosion particles not cleaned up until scroll
Post by: Aaron44126 on May 21, 2020, 06:02:02 PM
OK...  I am a software developer by trade, but I've never done any Delphi before.  I did take a look at the source and I found some nice text documentation on how the explosions work and I also located the code in LemGame.pas that handles drawing the explosion particles.  I believe that I could make the appropriate adjustments to fix this bug.  What I need help with is how to actually build the game EXE so that I can test it out.  So if anyone who knows happens across this post in the next 6-8 hours and wants to point me in the right direction, that would be awesome.  Otherwise, I will be digging in on my own this evening, once my regular obligations for the day are done.

Thanks.
Title: Re: [BUG][LEMMIX PLAYERS] Bomber/explosion particles not cleaned up until scroll
Post by: namida on May 21, 2020, 07:05:12 PM
Those are no longer maintained. Basically - the only Lemmings projects I'm currently working on are NeoLemmix, and (to the bare minimum standard to keep it useable and latest-version-compatible) the associated level editor. I guess theoretically, if a huge bug with L3DEdit came up, I'd probably fix that too, but I'm not likely to do any further general work on it.

EricLang, the original developer of Lemmix, has recently revived his work on it. However, his starting point was his own existing code, not the further additions made by myself and ccexplore, which means some DOS glitches are not accurately replicated by it (and a few that are indisputably present in DOS, but EricLang doesn't personally like, have been relegated to options rather than inherent behaviours). I wouldn't be surprised if he's already dealt with that glitch in his new version, though.

If you did want to look at improving the existing source code, you need Delphi 7 to compile it. The only legitimate way to obtain that these days it to purchase the non-free edition of current version of Delphi and make use of that it comes with a complimentary copy of all older versions; but I'll let you decide how worried you are about "legitimate" when it comes to a nearly-20-year-old piece of software, especially when the current version of it can be obtained legitimately for free but older versions cannot.

It may be more productive to put your efforts into assisting EricLang with his new version though, including replicating the bugs that it currently doesn't replicate accurately / improving it to have 100% replay file compatibility with the versions on NL.com (the bugs that it does replicate that EricLang's code originally didn't, it usually does so in a different way, and thus the replays aren't compatible). I believe he's using the latest version of Delphi - for which a free edition can be obtained - for this.
Title: Re: [BUG][LEMMIX PLAYERS] Bomber/explosion particles not cleaned up until scroll
Post by: Aaron44126 on May 21, 2020, 11:12:42 PM
Thanks.  I, um... found... a copy of Borland Delphi 7 and was able to build LemmixPlayer.exe.  I'll look into fixing the bug a bit later this evening.
Title: Re: [BUG][LEMMIX PLAYERS] Bomber/explosion particles not cleaned up until scroll
Post by: Aaron44126 on May 22, 2020, 01:43:17 AM
Well.  Fought with this enough for one day.  I messed with it for a while and the quickest 100% working fix that I could come up with is this cheesy one (https://github.com/AaronKelley/LemmixPlayer/commit/b83dc2cdcc8b138c7dd92381737fdf85a2ac9916) which just solves the problem by not drawing the last frame of the "explosion".

I can conclude that the "EraseParticles" function is not (always) cleaning up particles from the last frame.  (At first I thought that it wasn't getting called on the last frame, but I adjusted the logic there to make sure that it is and it still wouldn't do its job.)  Need to understand what it is doing better to find the proper fix.
Title: Re: [BUG][LEMMIX PLAYERS] Bomber/explosion particles not cleaned up until scroll
Post by: Aaron44126 on May 22, 2020, 03:18:37 AM
Eh, came back and worked on it some more.  The logic in EraseParticles seems sound so I'm not sure why they are not all being erased.  The particles disappear when the level is scrolled so it is like the particles are being erased properly, but not all updates to fTargetBitmap are being applied right away?

Anyway, I fixed it by adding an additional frame to the explosion animation data that is just empty.
https://github.com/AaronKelley/LemmixPlayer/commit/c1dcf9ae08c588250124257b6b8b1a0e1d4684b8 (https://github.com/AaronKelley/LemmixPlayer/commit/c1dcf9ae08c588250124257b6b8b1a0e1d4684b8)

Still want to test it (by actually playing the game for a while) and see if it is solid.

I don't know if you would like to publish an updated set of EXE files on the NeoLemmix site, or if I should just publish them on GitHub.
I noticed that the scrolling text at the bottom of the main screen gives a dead URL to some Lemmings forums so I'd also like to update it to point to this site.
Title: Re: [BUG][LEMMIX PLAYERS] Bomber/explosion particles not cleaned up until scroll
Post by: ccexplore on May 22, 2020, 05:40:15 AM
This change can potentially affect existing solutions (eg. saved replays).  When a lemming explodes, the game waits a specific number of frames before actually removing the lemming from the level.  Depending on how Lemmix is programmed, it's quite likely that when you change PARTICLE_FRAMECOUNT, you are also increasing that number of frames by 1, thereby delaying when the lemming is actually removed.  This in turn can affect the timing of nuking--when player starts nuke, the game starts the countdown lemming by lemming, frame by frame.  If a lemming is in a state where it's not already removed but also not eligible to start a countdown (eg. it is already splatting, already has a countdown due to assigned bomber earlier, or it is already exploding but not yet actually removed, etc.), the game doesn't move on immediately to the next lemming to assign nuke-induced countdown, it still waits for next frame to move on to the next lemming.  As a result, changing how long after an explosion before the lemming is removed from level can, in a suitably arranged situation, slightly affect how soon the next lemming after it gets its nuke-induced explosion countdown started.

It's true that most solutions will not utilize nuking in frame-precise manners so the overall impact will be quite low, but it is still a change that can in principle affect emulation accuracy in a way that impacts viability of level solutions, and therefore not an acceptable fix for any official LemmixPlayer versions.

I'd suggest looking for a different fix that does not require changing PARTICLE_FRAMECOUNT etc.  In fact, given what I said above, I'd venture a guess that maybe the bug is a side effect of the lemming also getting removed right at the end of completing all its frames for the explosion particles.  Perhaps the lemming got marked as removed, and as a direct side effect then the work needed to make the final rendering happen right away (ie. without requiring scrolling the level) was unintendedly skipped, leading to the effect you observe.
Title: Re: [BUG][LEMMIX PLAYERS] Bomber/explosion particles not cleaned up until scroll
Post by: Aaron44126 on May 22, 2020, 10:30:04 AM
I thought about this.  It looks like the Lemming is removed immediately, right when the particle framecount begins counting, and the framecount timer is basically just for going through the explosion animation and doesn't otherwise affect the game logic.  The only thing that I can figure extending the framecount would mess with is, it looks like the game does wait until the framecount is done before ending the level (so that you can watch the nuke animation finish, or watch the explosion from your final Lemming end) and this would delay the level end by one frame.

Still...  I will investigate for a fix that doesn't involve changing the framecount.
Title: Re: [BUG][LEMMIX PLAYERS] Bomber/explosion particles not cleaned up until scroll
Post by: namida on May 22, 2020, 10:47:14 AM
At any rate, I'm going to move this topic out of the NeoLemmix bugs / suggestions board, as this doesn't relate to NeoLemmix.
Title: Re: [BUG][LEMMIX PLAYERS] Bomber/explosion particles not cleaned up until scroll
Post by: ccexplore on May 22, 2020, 11:00:18 AM
I thought about this.  It looks like the Lemming is removed immediately, right when the particle framecount begins counting, and the framecount timer is basically just for going through the explosion animation and doesn't otherwise affect the game logic.

Hmm, unfortunately this would mean Lemmix is not currently emulating the described scenario 100% accurately based on my understanding.  I'd try to find a way to test and confirm on DOS Lemmings to prove this.  This should be fixed assuming I'm right.  The lemming can be hidden graphically but needs to continue to be counted as being in the level until it finishes all the frames of exploding particles, otherwise it will affect at least the nuking scenario I described.
Title: Re: [BUG][LEMMIX PLAYERS] Bomber/explosion particles not cleaned up until scroll
Post by: Aaron44126 on May 22, 2020, 11:55:05 AM
Hmm, unfortunately this would mean Lemmix is not currently emulating the described scenario 100% accurately based on my understanding.  I'd try to find a way to test and confirm on DOS Lemmings to prove this.  This should be fixed assuming I'm right.  The lemming can be hidden graphically but needs to continue to be counted as being in the level until it finishes all the frames of exploding particles, otherwise it will affect at least the nuking scenario I described.
Yes, I did notice that there is a behavior difference here.  In "proper Lemmings" (DOS, or Lemmings for Windows 95), the lemming does continue to exist after it blows up until the animation ends, which I can observe by looking at when the "Out" counter decrements or looking at the minimap which still shows a "dot" for the lemming.  In the Lemmix player, the lemming is removed immediately (the "out" counter decrements immediately and the dot on the minimap vanishes when the animation starts).  I figured that this was an intentional / cosmetic change.

There's this bit of code in HandleExploding which removes the lemming at the same time the animation frame counter starts.
Code: [Select]
      RemoveLemming(L);
      LemExploded := True;
      LemParticleTimer := PARTICLE_FRAMECOUNT;
      if (moShowParticles in fGameParams.MiscOptions) then
        fParticleFinishTimer := PARTICLE_FINISH_FRAMECOUNT;

It seems like any adjustments to correct this to accurately reproduce the DOS version nuking behavior would definitely impact compatibility of past replays (that involved nuking), am I wrong?

Anyway, turns out that I don't need to increment PARTICLE_FRAMECOUNT with this fix.  I flipped it back to 52 (along with PARTICLE_FINISH_FRAMECOUNT) and it still works.  The original explosion animation is 51 frames.  I just added a 52nd (empty) frame and there is still room to show it with the original cap.

So the list of changes is shorter:
https://github.com/AaronKelley/LemmixPlayer/compare/4e59cec..ef66c45 (https://github.com/AaronKelley/LemmixPlayer/compare/4e59cec..ef66c45)
Title: Re: [BUG][LEMMIX PLAYERS] Bomber/explosion particles not cleaned up until scroll
Post by: ccexplore on May 22, 2020, 11:56:29 AM
Here's a custom level that's perfect for testing the nuke scenario.  It's not a solvable level, but do the following:

1) Assign bomber to the lemming at the top.
2) After the bomber explodes (so you no longer see the lemming, you only see its particles), nuke.

The bottom two lemmings are arranged so that they are maintained at the exact same elevation as they both walk up their slopes.  So when they both eventually explode from nuking, the exact elevation of their respective bomb craters on their slopes will reflect how many frames occurred after the left lemming started its countdown before the right lemming started his.

I believe LemmixPlayer will currently show the right to explode 1 pixel higher than the left.  But the correct behavior as observed in DOS Lemmings I believe will have the right explode 2 pixels higher than the left--the same thing you'd observe if you started nuking earlier, anytime before the bomber has exploded.

I'll test on DOS Lemmings later today.  A screenshot and some quick checking in MS Paint will determine whether the correct difference in DOS Lemmings is 2 pixels vs Lemmix's 1.
Title: Re: [BUG][LEMMIX PLAYERS] Bomber/explosion particles not cleaned up until scroll
Post by: ccexplore on May 22, 2020, 12:12:24 PM
It seems like any adjustments to correct this to accurately reproduce the DOS version nuking behavior would definitely impact compatibility of past replays (that involved nuking), am I wrong?

That can indeed happen.  However Lemmix has been taken as the gold standard for emulation accuracy of DOS Lemming's game logic, to the point that all replays from Lemmix for DOS Lemmings challenges are assumed to play out exactly the same when the same moves are carried out exactly on DOS Lemmings.  As such, this accuracy goal trumps the possibility of breaking past replays.

In practice, I expect very few replays to be materially affected:

1) The scenario I described require first having a lemming explode from bomber assignment (assigned before nuking started), and then start nuking during the explosion particles.  Even for the few solutions reported here that involve nuking, such a particular sequence of moves is rare if not yet ever used.

2) In some replays the scenario may perhaps happen incidentally, with the nuking only being initiated by the player for purpose of ending the level, rather than actually exploiting the explosive effects of nuking to pave a way to the exit.  And thus the nuking is basically pretty much always done well after other lemmings have exited, so that there's no chance it could affect a solution in terms of number of lemmings saved.  So even if there is an observable difference for the replay, at least it won't cause the replay to end up saving different number of lemmings.
Title: Re: [BUG][LEMMIX PLAYERS] Bomber/explosion particles not cleaned up until scroll
Post by: Aaron44126 on May 22, 2020, 12:18:34 PM
Ok, apologies for being new...  I'm not sure how to get the Lemmix player to open the LVL file that you posted.  Hints?  :-P

I see that there is a configuration option "LookForLVLFiles" and it looks like it will then try to load level files from the disk rather than from a level pack, in a format like "101.lvl" = "Fun difficulty, level 1".  I tried it renaming your TestNuke.lvl accordingly but it is still loading levels from the level pack instead.

Anyway, this is scope creeping a bit from my original goal which was just to fix the explosion animation for an unmaintained port of the game...
Title: Re: [BUG][LEMMIX PLAYERS] Bomber/explosion particles not cleaned up until scroll
Post by: ccexplore on May 22, 2020, 12:33:19 PM
I don't remember, I think either you need to name file as 0101.lvl, or you need to also enable cheat mode before the option would take effect.  To enable cheat mode you go to the password screen (F2), type CHEATCODES and press ENTER.

Anyway, I don't expect you to try to fix this yourself, though you're welcome to try.  Otherwise at some later time I'll try to do the fix myself (along with including your fix for the stray particles) and rebuild the affected EXEs and have namida replace the ones currently downloadable.
Title: Re: [BUG][LEMMIX PLAYERS] Bomber/explosion particles not cleaned up until scroll
Post by: Aaron44126 on May 22, 2020, 12:47:58 PM
Ok, you are right, I had to name it 0101.lvl and then I was able to load the level.  (Which means I have another fix suggestion, comment only.  https://github.com/AaronKelley/LemmixPlayer/commit/1d5bf01edeaa9979217dd637657dbf820a8e3caa (https://github.com/AaronKelley/LemmixPlayer/commit/1d5bf01edeaa9979217dd637657dbf820a8e3caa))

I did what you said — blow up the top lemming and then trigger a nuke while the particles were flying.  The other two lemmings blew up one pixel apart (vertically).

(https://i9ymlg.bn.files.1drv.com/y4mIausviDpDHW4a25KH_GIY054PiDYFasVimxU-J0ouXDUlUIEU1MxhfQkQrveP7gkF50qmgROlu_uR1sW_ZAfFOHtUichHN7mXDwUw1TSQ-sWu4ZEeM_BGaASAkM6g5JtrURFcwzZYpotHHn5ZJiufyS1P9_wjtzP9t_YDnh0-i8HQNhP9Db63Jm0t4cEulppG2EL4itK9Yg4MNqmEz5pNQ?width=1532&height=543&cropmode=none)

Title: Re: [BUG][LEMMIX PLAYERS] Bomber/explosion particles not cleaned up until scroll
Post by: Aaron44126 on May 22, 2020, 01:35:30 PM
Full set of changes that I am proposing.
https://github.com/AaronKelley/LemmixPlayer/compare/4e59cec..59d25da (https://github.com/AaronKelley/LemmixPlayer/compare/4e59cec..59d25da)
* Explosion particle fix (note explode.dat has changed and a diff isn't shown because it is a binary file)
* Lemmings forum URL change
* Comment for LVL file names was misleading

I'll leave it to you to fix the nuke timing bug.  I did take a look, hoping it would just involve changing where RemoveLemming is called, but it's not (quite?) that simple and is going to take more time than I have right now to learn my way around the logic enough to address it.

[Edit]
Oh and I guess this one is probably worth looking into if you are going to do a rebuild.
https://www.lemmingsforums.net/index.php?topic=4728.0
Title: Re: [BUG][LEMMIX PLAYERS] Bomber/explosion particles not cleaned up until scroll
Post by: Aaron44126 on May 22, 2020, 05:05:28 PM
Back again.
I came up with this simple fix for the nuke timing issue.  It makes sure that Lemmings are still counted when going through the "nuke loop", if they have been removed because of explosion, but the explosion animation has not finished.  The result is, in your test level, the lemmings detonate two pixels apart vertically.

The animation time is 52 frames (PARTICLE_FRAMECOUNT), not sure if is the same amount of time that the lemmings persist after explosion in the DOS version?
Also, it doesn't address the difference in the "out" count between Lemmix and the DOS version.  (In Lemmix the count will decrement immediately after a lemming explodes, but in the DOS version it doesn't decrement until the animation is done.)

https://github.com/AaronKelley/LemmixPlayer/commit/c6b59acfa668df936bdba18baf4856823d62668a (https://github.com/AaronKelley/LemmixPlayer/commit/c6b59acfa668df936bdba18baf4856823d62668a)

(https://igfp8w.bn.files.1drv.com/y4mn-0jKil4UoL3Q-Q0xGkwqPtLnQdY-HzWJoS5hvYr0BKTiDtv0a9r7EcZHoIZu8C27VDnwQo84y5uwqPU7JsAPsser5m0jInEQNiBur7yBpAe-DyqYywdcc0MD9QBZYPHpPM5t5ORPmdByup7dFR2H0o7ccLbDJ1KMYGGHaLclwSAufGCElLuGq12acreNJO04wqz6dI8-klXIWW6qR_8xg?width=1429&height=370&cropmode=none)
Title: Re: [BUG][LEMMIX PLAYERS] Bomber/explosion particles not cleaned up until scroll
Post by: ccexplore on May 23, 2020, 12:32:29 PM
Testing on DOSBox (screenshot attached) confirms that a 2-pixel difference is the correct one for DOS Lemmings.

Regarding your fix, I guess it works for the nuke case.  Although I think I would prefer a fix that actually truly delays the removal of the lemming, in case the current premature removal leads to other side effects I've overlooked (beyond the "out" count of course).  Though to be fair, I'm almost 99% sure there shouldn't be any other solution-impacting differences.

Yes, 52 matches the amount of time the exploded lemming lasts in DOS Lemmings.
Title: Re: [BUG][LEMMIX PLAYERS] Bomber/explosion particles not cleaned up until scroll
Post by: Aaron44126 on June 14, 2020, 10:19:06 PM
I've got another change that I'm not sure how you would feel about including.

I added support for the "Lemmings for Windows 95" key bindings.
1-8 : set skills,
9 : toggle fast forward,
0 : toggle pause,
-/+ : release rate control

These work in addition to the existing F1-F12 bindings, so either can be used, but I did have to move some other existing key bindings...
"5" used to be "cheat the level", moved that to "C"
"-" used to be "back up one second", moved that to "["

Reasons for this...
1. "Lemmings for Windows 95" was the version that I had played the most in the past so I was already used to these bindings.
2. I'm playing on a laptop so the F1-F12 keys are a bit more awkward to use than the regular number keys.

https://github.com/AaronKelley/LemmixPlayer/compare/59d25da..d400819 (https://github.com/AaronKelley/LemmixPlayer/compare/59d25da..d400819)

I'm planning to also tackle this issue (https://www.lemmingsforums.net/index.php?topic=4728.0) which I have confirmed to be a problem, maybe next weekend?  I'll have to figure out how to extract, edit, and replace the level.  After that I will package up a release on GitHub named "V29A" and leave it to you guys to decide if you want to take any of this and merge it in to the "official" version.
Title: Re: [BUG][LEMMIX PLAYERS] Bomber/explosion particles not cleaned up until scroll
Post by: namida on June 14, 2020, 11:54:47 PM
Don't particularly care about 5 (technically, in DOS Lemmings, only numpad 5 has this effect anyway), but - for back one second is extremely ingrained, due to how commonly used it is, and even more so due to it being the default (at least in the "traditional" layout) in NeoLemmix for this function too. I'd be very strongly against changing it.

Re: F keys on laptop, assuming you have them, there is on most laptops a BIOS setting to restore the normal "press them for F key, hold Fn + press them for the alternative function" behaviour. Up to you of course whether you prefer this or not.
Title: Re: [BUG][LEMMIX PLAYERS] Bomber/explosion particles not cleaned up until scroll
Post by: Aaron44126 on June 15, 2020, 12:56:35 AM
Thanks for the feedback.  I'll work on making it an off-by-default option to move "back one second" away from the "-" key.  (Less important to me... there are way more circumstances to raise the release rate rather than lower it.)

My laptop does have F1-F12 keys available to use, they are just way smaller than the "regular" keys.  I think that this is pretty normal for laptops these days.  As you say, many laptops have coopted these keys for volume control, brightness control, etc. and you are forced to pick which mode of operation you want to have be the default.
Title: Re: [BUG][LEMMIX PLAYERS] Bomber/explosion particles not cleaned up until scroll
Post by: Aaron44126 on June 15, 2020, 06:32:30 PM
Ok...  Got another one.

Added the option to enable or disable state control.  This shows up in the F4 options menu and is saved in the INI file.  State control is enabled by default.

If state control is disabled:
 * Loading replays is not allowed
 * Backing up time is not allowed
 * Frame advancing while paused is not allowed
 * A single skill assignment may be used while paused

If state control is enabled, "-" key backs up the game one second.  If state control is disabled, "-" key decreases the release rate.

https://github.com/AaronKelley/LemmixPlayer/commit/5b4c33a28e6a514a18d9872f75e9630f6d4f3e8a


This is in service of allowing a more classic Lemmings experience as "slowing down or reversing time" is not possible in the original game.  I know you could just ignore these features if you want a more classic Lemmings experience, but I found myself using the "back up one second" function a bit too much (since I discovered it yesterday) and it is best to just remove any temptation to use it.