Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NPC spawning fixes #54

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

MrDoubleA232
Copy link
Contributor

@MrDoubleA232 MrDoubleA232 commented Jul 31, 2023

Fixes the "frame perfect despawn" glitch, which causes an NPC to not spawn if it comes on screen later in the same frame that it despawned. Includes a toggle to disable the fix. Also fixes a small issue with the despawn timer discussed in the SMBX2 dev channel earlier today, and gives proper names to some of the "unknown" NPC fields.

@ds-sloth
Copy link

I don't think that the NPC momentum onscreen call currently handles SingleCoop mode (camera type 6) correctly. Other than that, I just patched a similar fix into TheXTech and it seems to work well.

If you're injecting your code into the Deactivate function, this will also fix a related issue where NPCs that went offscreen during FreezeNPCs (timer switch, stopwatch, CaptainN cheat) wouldn't respawn until they'd been offscreen during normal level play.

@ds-sloth
Copy link

Responding to Rednaxela's comment in the X2 server, I should note: on our side we actually ended up disabling the FreezeNPCs fix in TheXTech for now.

It handles cases like the above showcase well, but the FreezeNPCs NPCUpdate code doesn't call the various initialization code for certain NPCs like piranha plants or cheap cheaps.

Until we refactor the NPC code deeply enough to gather all initialization code and be able to call it, any fix for the FreezeNPCs despawn bug will result in some incorrect behavior.

Secondarily, the point I was making about SingleCoop is just that on line 3258 in this diff, camera idx should be 2 if camera type is 6 and single coop is 2. Right now you'd be checking only the P1 camera, so if P2 is active you might accidentally allow an NPC to respawn while onscreen.

@MrDoubleA232
Copy link
Contributor Author

Makes sense. I suppose that that initialisation quirk also causes issues in the case of the screen slowly scrolling after section resizing?

@ds-sloth
Copy link

Yes, but only in rare cases. I should have been clearer, but a little more than half of the "initialization" code I mentioned actually runs in the same UpdateNPCs cycle that calls Deactivate, following Deactivate being called. Maybe that half should be called "resetting code". So it's harmful to either activate or deactivate an NPC during FreezeNPCs.

To directly answer your question about qScreen, I think that the most dangerous case would be a qScreen event that brings NPCs onscreen that had been incompletely despawned during FreezeNPCs. That should definitely affect plants at least (they mostly use "resetting code"). I think that cheeps mostly have "initialization code" so they'd be affected by qScreen even if they hadn't been despawned during FreezeNPCs. All of these predictions should be verified though, Redigit's logic can be very surprising at times.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants