Fixing graphical glitches

Discuss PoP1 for DOS here.
User avatar
dmitrys
Developer
Developer
Posts: 195
Joined: October 1st, 2020, 6:05 am

Re: Fixing graphical glitches

Post by dmitrys »

David wrote: October 31st, 2020, 1:26 pm Maybe it happened with this slightly different fix I tried, I'm not sure.

Code: Select all

	if (Char.room != curr_room) {
		Char.room = curr_room;
		leave_guard();
	}
Anyway, I added your fix: https://github.com/NagyD/SDLPoP/commit/ ... 8121bf8491
I have tried doing the fix with the code from your post first. But if the kid were return to the room on the left (the original guard room) in the spike row, it would resurrect the guard behind him.

The last screenshot for me is the room with spikes which is the room on the right.

And thanks for including the fix.
User avatar
dmitrys
Developer
Developer
Posts: 195
Joined: October 1st, 2020, 6:05 am

Re: Fixing graphical glitches

Post by dmitrys »

Also, in the original DOS POP the guard just disappears. Maybe if the fix for disappearing guards is not enabled, it should clear the character and return from the function after the first statement in that "if" clause.
User avatar
dmitrys
Developer
Developer
Posts: 195
Joined: October 1st, 2020, 6:05 am

Re: Fixing graphical glitches

Post by dmitrys »

My original fix was a bit simplistic. First of all, we need to check if a guard was actually spiked before removing him from the original room. Also, kid on the same row of spikes can make the guard disappear if the drawn room switches automatically, like David mentioned. It happens when kid jumps up or crouches off the ledge.

I also found a related bug as well that my new fix seems to cover.


Post-fix videos (based on modified code below).





The new fix:

Code: Select all

// seg005:01B7
void __pascal far spiked() {
	// If someone falls into spikes, those spikes become harmless (to others).
	curr_room_modif[curr_tilepos] = 0xFF;
	// If someone falls into spikes in a different room
	if (Char.room != curr_room) {
		if (Char.charid == charid_0_kid) {
			// fixes an issue where kid falling into spikes
			// causes guard to disappear
			if (Char.curr_col == -1 && Char.direction == dir_0_right) {
				drawn_room = room_R;
			}
		} else {
			// remove guard from the original room
			level.guards_tile[Char.room - 1] = -1;
		}
		// draw character in the correct room
		Char.room = curr_room;
	}
	Char.y = y_land[Char.curr_row + 1];
	Char.x = x_bump[tile_col + 5] + 10;
	Char.x = char_dx_forward(8);
	Char.fall_y = 0;
	set_sound_pos(Char.room, Char.curr_col, Char.curr_row);
	play_sound(sound_48_spiked); // something spiked
	take_hp(100);
	seqtbl_offset_char(seq_51_spiked); // spiked
	play_seq();
}
Last edited by dmitrys on November 2nd, 2020, 12:35 am, edited 2 times in total.
User avatar
Norbert
The Prince of Persia
The Prince of Persia
Posts: 5745
Joined: April 9th, 2009, 10:58 pm

Re: Fixing graphical glitches

Post by Norbert »

I haven't fully followed the thread. Just chiming in that hopefully SDLPoP will continue to be fully compatible with the original game. That fixes that impact gameplay are not enabled by default, I mean. Where guards land, for example, may impact where the prince can go (e.g. tricks 4 and 151).
User avatar
dmitrys
Developer
Developer
Posts: 195
Joined: October 1st, 2020, 6:05 am

Re: Fixing graphical glitches

Post by dmitrys »

The first part of the bug where spiked guard gets rendered in the wrong room does not happen in the original game. But the guard does not appear in the next room either. So David might need to add some conditional logic based on the assembly code to make it behave exactly the same; currently it does not.

The second part of the bug (top video in the previous post) where the wrong room is being drawn actually does happen in the original game. It took me 2 attempts to reproduce it. The same code (kid if clause) also fixes the problem where guard disappears when kid falls onto spikes into last tile of one room next to a spiked guard in the next room on the same row. That fix probably should not enabled by default because it is not needed unless you fix the first bug in a way where guard does not disappear in the next room.
User avatar
atrueprincefanfrom18
Site Shah
Site Shah
Posts: 1785
Joined: January 21st, 2020, 2:53 pm
Contact:

Re: Fixing graphical glitches

Post by atrueprincefanfrom18 »

Norbert wrote: November 1st, 2020, 10:30 pm That fixes that impact gameplay are not enabled by default, I mean.
I think if changing some code is affecting the gameplay such that it's not the same as the default, it's always best to add a toggle screen and have enable and disable options instead of having static code.
Although it improves the behaviour of the game, making it more pleasant to play, it should be same as DOSBox.
Love to create new MODS :)

My complete list of mods until now!

My channel. Do consider subscribing it! :)
User avatar
dmitrys
Developer
Developer
Posts: 195
Joined: October 1st, 2020, 6:05 am

Re: Fixing graphical glitches

Post by dmitrys »

atrueprincefanfrom18 wrote: November 2nd, 2020, 3:53 am I think if changing some code is affecting the gameplay such that it's not the same as the default, it's always best to add a toggle screen and have enable and disable options instead of having static code.
Although it improves the behaviour of the game, making it more pleasant to play, it should be same as DOSBox.
I absolutely agree. This is why I described the issue as 2 separate bugs. Spiked guard appearing in the same room is not something that happens in DOS PoP. But he would need to disappear instead of appearing in the next room to be consistent.

The second part of the bug where the wrong room is being displayed after a jump, if fixed, would need to be driven by an option parameter. And the same parameter can make the spiked guard appear in next room (at the correct tile) instead of disappearing.
David
The Prince of Persia
The Prince of Persia
Posts: 2848
Joined: December 11th, 2008, 9:48 pm
Location: Hungary

Re: Fixing graphical glitches

Post by David »

dmitrys wrote: November 1st, 2020, 7:52 pm Post-fix videos (based on modified code below).
I tried the new code, and if I do what's on the first video, the spiked guard will disappear for two frames when the prince lands in the spikes.
dmitrys wrote: October 31st, 2020, 5:24 pm Also, in the original DOS POP the guard just disappears.
dmitrys wrote: November 2nd, 2020, 12:31 am The first part of the bug where spiked guard gets rendered in the wrong room does not happen in the original game.
No, the guard will appear in the wrong room.
Open level 11 in a level editor, go to room 22, and in the bottom left corner replace the wall with a floor.
Move the prince's start position where the guard is.
Push the guard into the spikes, and the guard will appear in the bottom left corner.

See also the spike_2 video here: viewtopic.php?p=12715#p12715
User avatar
dmitrys
Developer
Developer
Posts: 195
Joined: October 1st, 2020, 6:05 am

Re: Fixing graphical glitches

Post by dmitrys »

David wrote: November 7th, 2020, 9:25 pm I tried the new code, and if I do what's on the first video, the spiked guard will disappear for two frames when the prince lands in the spikes.
That does not happen all the time in my mod but I did see it happen. You have to get aligned at a very specific place and then jump and slip at the edge. I am not sure how to fix that issue.
David wrote: November 7th, 2020, 9:25 pm No, the guard will appear in the wrong room.
Open level 11 in a level editor, go to room 22, and in the bottom left corner replace the wall with a floor.
Move the prince's start position where the guard is.
Push the guard into the spikes, and the guard will appear in the bottom left corner.
Maybe DOS POP renders things slightly different as you cannot see the guard at the wall edge, at least in my experience.

I guess that confirms that my fix should not be enabled by default.
User avatar
dmitrys
Developer
Developer
Posts: 195
Joined: October 1st, 2020, 6:05 am

Re: Fixing graphical glitches

Post by dmitrys »

I played with this glitch a little more. Those missing frames were caused by the drawn room switching back and forth.

Instead of setting the drawn room, redrawing kid and bumping him back to the previous room stops guard from disappearing briefly.

Code: Select all

void __pascal far spiked() {
	int forward_bump = 8;
	// If someone falls into spikes, those spikes become harmless (to others).
	curr_room_modif[curr_tilepos] = 0xFF;
	// If someone falls into spikes in a different room
	if (Char.room != curr_room /* && fixes->??? */) {
		if (Char.charid == charid_0_kid) {
			// fixes an issue where kid falling into spikes disappears
			if (Char.curr_col == -1) {
				draw_kid();
				forward_bump = Char.direction == dir_0_right ? -6 : 16;
			}
		} else {
			// remove guard from the original room
			level.guards_tile[Char.room - 1] = -1;
		}
		// draw character in the correct room
		Char.room = curr_room;
	}
	Char.y = y_land[Char.curr_row + 1];
	Char.x = x_bump[tile_col + 5] + 10;
	Char.x = char_dx_forward(forward_bump);
	Char.fall_y = 0;
	play_sound(sound_48_spiked); // something spiked
	take_hp(100);
	seqtbl_offset_char(seq_51_spiked); // spiked
	play_seq();
}
David
The Prince of Persia
The Prince of Persia
Posts: 2848
Joined: December 11th, 2008, 9:48 pm
Location: Hungary

Re: Fixing graphical glitches

Post by David »

I added this last fix to SDLPoP.
User avatar
atrueprincefanfrom18
Site Shah
Site Shah
Posts: 1785
Joined: January 21st, 2020, 2:53 pm
Contact:

Re: Fixing graphical glitches

Post by atrueprincefanfrom18 »

This could be merged here.
Love to create new MODS :)

My complete list of mods until now!

My channel. Do consider subscribing it! :)
User avatar
dmitrys
Developer
Developer
Posts: 195
Joined: October 1st, 2020, 6:05 am

Re: Fixing graphical glitches

Post by dmitrys »

I found another glitch with a tall pillar. It happens in the DOS version and in SDLPoP. Notice the black rectangle on top the pillar near kid.

User avatar
dmitrys
Developer
Developer
Posts: 195
Joined: October 1st, 2020, 6:05 am

Re: Fixing graphical glitches

Post by dmitrys »

The bug also happens if you simply jump near the pillar.

User avatar
dmitrys
Developer
Developer
Posts: 195
Joined: October 1st, 2020, 6:05 am

Re: Fixing graphical glitches

Post by dmitrys »

@David, thanks for fixing the bug in the Git repository.

There is also a related bug which is caused by a different function. The top of the pillar base becomes pixelated after the jump where kid's hands were. I commented on how I fixed it in the commit for the first fix.

Post Reply