English Amiga Board


Go Back   English Amiga Board > Coders > Coders. General > Coders. Releases

 
 
Thread Tools
Old 29 September 2022, 01:24   #621
abu_the_monkey
Registered User
 
Join Date: Oct 2020
Location: Bicester
Posts: 1,938
@pipper

I can get the stuttering to stop on the a4000 by adding the section between the Asterix
Code:
				; Flip screens

				; Wait on prior frame to be displayed.
				; FIXME: this could waste time synchrously waiting on the scanout to happen if we manage
				; to fully produce the next frame before the last frame has been scanned out.
				; We could move the screen flipping into its own thread that flips asynchronously.
				; It does not seem very practical, though as this scenario

				move.l	DisplayMsgPort,a0
				move.l	a0,a3
				CALLEXEC WaitPort
.clrMsgPort			move.l	a3,a0
				CALLEXEC GetMsg
				tst.l	d0
				bne.s	.clrMsgPort

				move.w	ScreenBufferIndex,d0
				lea		ScreenBuffers,a1

				eor.w	#1,d0					; flip  screen index
				move.w	d0,ScreenBufferIndex

				move.l	(a1,d0.w*4),a1			; grab ScreenBuffer pointer

				move.l	MainScreen,a0
				CALLINT	ChangeScreenBuffer		; DisplayMsgPort will be notified if this image had been fully scanned out
****************************************************************
				tst.l	d0
				beq	.ok
				move.w	ScreenBufferIndex,d0
				lea		ScreenBuffers,a1
				eor.w	#1,d0					; flip  screen index
				move.w	d0,ScreenBufferIndex
.ok
****************************************************************
how ever it is hit and miss as to if the next level will start (get background sound/music and the border but no 3d rendered image) . Best guess is it gets proper out of sync at this point. performance does seem slower but not tested the previous version to confirm this.

@Grond
any views on this? the code you posted for the fps counter contained a double buffer routine that makes sense in my head, but, implementing such stuff is beyond me at this point in time.
abu_the_monkey is offline  
Old 29 September 2022, 10:00   #622
grond
Registered User
 
Join Date: Jun 2015
Location: Germany
Posts: 1,918
Quote:
Originally Posted by abu_the_monkey View Post
@Grond
any views on this? the code you posted for the fps counter contained a double buffer routine that makes sense in my head, but, implementing such stuff is beyond me at this point in time.
The code I posted was written over 25 years ago, I never had any problems with it but it wasn't tested on many different hardware configurations, especially not on configurations with so different CPU speeds. <old man voice>All we had back in the day were 030s and perhaps the occasional 040</old man voice>

The double-buffering mechanism in the code you posted seems to be to flip a bit in a variable to indicate which screen is going to be the next to get displayed. This variable really only switches between 0 and 1 from what I see. I then gets used as an index to a table comprising a whopping two entries, the first buffer and the second buffer. In short, before the function gets called, the index will be flipped, the index will then be used to load the right pointer and the function will be called with the new screen buffer.

The way I remember it my code is pretty similar, I think I called my buffers "odd" and "even" (referring to the numbers of the screen the code renders) and just swap the variables around each time rendering of a buffer finishes. It probably is a few instructions shorter than this one because I don't use this index-loading approach but it shouldn't matter.

Now this ChangeScreenBuffer() function apparently fails (the fact that it could was new to me). From a quick search it seems that one reason for it to fail is that some system function or library (gadgets were mentioned) is drawing something on the screen or such. I wonder whether we should check how we set up the screen and the window because we shouldn't have any gadgets and also no right mouse-button action which IIRC calls a hook into intuition so that a menu bar can be drawn (do you see any flickering at the top of the screen when the right mouse button is pressed?). Anyway, after the call fails, you flip the bit again and thus try to change the buffer to be displayed to the one that is already being displayed. I guess the system will not mind replacing the screen buffer by itself but I suspect that the "synchronisation" between the buffer to render to and the buffer to display may be affected. If the call succeeds, perhaps rendering happens in the same buffer as the one that is being displayed? This is just a wild guess, I don't know the code well enough.
grond is offline  
Old 29 September 2022, 23:06   #623
abu_the_monkey
Registered User
 
Join Date: Oct 2020
Location: Bicester
Posts: 1,938
@grond
thanks for your input, gives us more avenues to explore for a fix
abu_the_monkey is offline  
Old 30 September 2022, 13:06   #624
Karlos
Alien Bleed
 
Karlos's Avatar
 
Join Date: Aug 2022
Location: UK
Posts: 4,119
I managed to test the latest version and can definitely reproduce the frame flipping bug. In C, when calling the change screen buffer it's normal to have to check for failure, IIRC. Revisiting some very old code of mine...

https://github.com/0xABADCAFE/ancien...native.cpp#374

I remember having all kinds of annoying problems flipping the buffer properly (this was under CGX/RTG) and just after the commented out TODO block you can see that in the end I resorted to busy polling the ChangeScreenBuffer. I remember recording loop counts in there and it almost always worked first time back then.
Karlos is online now  
Old 30 September 2022, 15:41   #625
grond
Registered User
 
Join Date: Jun 2015
Location: Germany
Posts: 1,918
Quote:
Originally Posted by Karlos View Post
I resorted to busy polling the ChangeScreenBuffer. I remember recording loop counts in there and it almost always worked first time back then.
That's exactly what I propose here (I probably wasn't clear enough). The code would then look like this:

Code:
.nok:
				CALLINT	ChangeScreenBuffer		; DisplayMsgPort will be notified if this image had been fully scanned out
****************************************************************
				tst.l	d0
				bne	.nok
.ok
****************************************************************
After this we might want to find the root cause but this, at least, is a way of dealing with the failed call. Of course, we could also count the failed attempts and abort e.g. after a second or so of failed attempts to get a clean exit from the program if something is really wrong.

I still wonder whether the problem has anything to do with the right mouse button or some sort of messaging for the window. When did the problem first arise?
grond is offline  
Old 01 October 2022, 10:15   #626
Karlos
Alien Bleed
 
Karlos's Avatar
 
Join Date: Aug 2022
Location: UK
Posts: 4,119
@grond

Very clear, thanks. I never was able to find out why the call failed back in the RTG days but it was also quite infrequent as I recall. This seems to be much more frequent, multiple times a second.
Karlos is online now  
Old 01 October 2022, 19:56   #627
grond
Registered User
 
Join Date: Jun 2015
Location: Germany
Posts: 1,918
Btw, a0 should probably be reinitialised before calling ChangeScreenBuffer() again. I don't think we should rely on a0 being kept unchanged. However, the reinitialisation should not have the flipping stuff.

Edit: I accidentally wrote d0 when I meant a0.

Last edited by grond; 02 October 2022 at 00:03.
grond is offline  
Old 01 October 2022, 20:03   #628
Karlos
Alien Bleed
 
Karlos's Avatar
 
Join Date: Aug 2022
Location: UK
Posts: 4,119
Quote:
Originally Posted by grond View Post
Btw, d0 should probably be reinitialised before calling ChangeScreenBuffer() again. I don't think we should rely on a0 being kept unchanged. However, the reinitialisation should not have the flipping stuff.
Yep, clobber list.
Karlos is online now  
Old 02 October 2022, 10:59   #629
abu_the_monkey
Registered User
 
Join Date: Oct 2020
Location: Bicester
Posts: 1,938
ok, so after butchering everything looking for what caused the stuttering I found changing ScreenBufferIndex from
ScreenBufferIndex dc.w 0
to
ScreenBufferIndex dc.w 1
fixed it.
abu_the_monkey is offline  
Old 02 October 2022, 11:08   #630
abu_the_monkey
Registered User
 
Join Date: Oct 2020
Location: Bicester
Posts: 1,938
I guess the first ScreenBufferIndex flip before the start of the main loop puts it out of sync?
abu_the_monkey is offline  
Old 02 October 2022, 11:32   #631
abu_the_monkey
Registered User
 
Join Date: Oct 2020
Location: Bicester
Posts: 1,938
spoke too soon.
this puts it out of sync when you complete a level and starting a new one.
abu_the_monkey is offline  
Old 02 October 2022, 12:10   #632
abu_the_monkey
Registered User
 
Join Date: Oct 2020
Location: Bicester
Posts: 1,938
adding a test for zero in the initial screen flip may be enough to know which buffer was last displayed I guess? and keep it in sync

Code:
XXX				move.w	ScreenBufferIndex,d0
				lea		ScreenBuffers,a1
****************************************************************
				tst.w	d0
				beq.s	.zero
****************************************************************
				eor.w	#1,d0					; flip  screen index
.zero
				move.w	d0,ScreenBufferIndex

				move.l	(a1,d0.w*4),a1			; grab ScreenBuffer pointer

				move.l	MainScreen,a0
				CALLINT	ChangeScreenBuffer
then again, it may not start the message queue and wait forever...

Last edited by abu_the_monkey; 02 October 2022 at 12:25.
abu_the_monkey is offline  
Old 02 October 2022, 12:46   #633
grond
Registered User
 
Join Date: Jun 2015
Location: Germany
Posts: 1,918
Could you try this:

Code:
.nok
	move.w		ScreenBufferIndex,d0
	lea		ScreenBuffers,a1
	move.l		(a1,d0.w*4),a1			; grab ScreenBuffer pointer
	move.l		MainScreen,a0
	CALLINT		ChangeScreenBuffer
	tst.l		d0
	bne		.nok
grond is offline  
Old 02 October 2022, 12:55   #634
abu_the_monkey
Registered User
 
Join Date: Oct 2020
Location: Bicester
Posts: 1,938
I am testing this horror at the moment
Code:
XXX				move.w	ScreenBufferIndex,d0
				lea		ScreenBuffers,a1
****************************************************************
				tst.w	d0
				beq.s	.zero
****************************************************************
				eor.w	#1,d0					; flip  screen index

				move.w	d0,ScreenBufferIndex

				move.l	(a1,d0.w*4),a1			; grab ScreenBuffer pointer

				move.l	MainScreen,a0
				CALLINT	ChangeScreenBuffer
				bra	.done
.zero
				eor.w	#1,d0					; flip  screen index
				move.l	(a1,d0.w*4),a1			; grab ScreenBuffer pointer

				move.l	MainScreen,a0
				CALLINT	ChangeScreenBuffer

				move.w	ScreenBufferIndex,d0
				lea		ScreenBuffers,a1
				;eor.w	#1,d0					; flip  screen index

				move.w	d0,ScreenBufferIndex

				move.l	(a1,d0.w*4),a1			; grab ScreenBuffer pointer

				move.l	MainScreen,a0
				CALLINT	ChangeScreenBuffer
.done
not got out of sync yet, but, a bit of a mess
abu_the_monkey is offline  
Old 02 October 2022, 12:58   #635
abu_the_monkey
Registered User
 
Join Date: Oct 2020
Location: Bicester
Posts: 1,938
think I am getting confused
abu_the_monkey is offline  
Old 02 October 2022, 13:41   #636
abu_the_monkey
Registered User
 
Join Date: Oct 2020
Location: Bicester
Posts: 1,938
@grond

I will try your code later today, but, I think I have tried something similar and it crashed, hard. It is for the double buffer in the main game loop yes?

the code snippet I posted is setup code before entering the main game loop just to re-sync the screenbuffer to the screenbufferindex and start the message queue for DisplayMsgPort. hope this makes sense.
abu_the_monkey is offline  
Old 03 October 2022, 00:05   #637
abu_the_monkey
Registered User
 
Join Date: Oct 2020
Location: Bicester
Posts: 1,938
@grond

sadly your code did not yield the desired result, the border graphic is displayed but that is as far as it goes, no sound and no input response. it didn't crash the system, just caught in an endless loop?
abu_the_monkey is offline  
Old 03 October 2022, 00:13   #638
robinsonb5
Registered User
 
Join Date: Mar 2012
Location: Norfolk, UK
Posts: 1,153
Quote:
Originally Posted by grond View Post
Could you try this:

Code:
.nok
    move.w        ScreenBufferIndex,d0
    lea        ScreenBuffers,a1
    move.l        (a1,d0.w*4),a1            ; grab ScreenBuffer pointer
    move.l        MainScreen,a0
    CALLINT        ChangeScreenBuffer
    tst.l        d0
    bne        .nok

Shouldn't that last "bne" be "beq"? ChangeScreenBuffer returns non-zero on success, zero if the update couldn't be performed, I think?
robinsonb5 is offline  
Old 03 October 2022, 00:26   #639
abu_the_monkey
Registered User
 
Join Date: Oct 2020
Location: Bicester
Posts: 1,938
from the docs

RESULT
Returns non-zero if the operation succeeded. Returns zero
if the operation cannot be performed. This function will
fail if Intuition's state cannot permit it, for example the
user is playing with menus or gadgets.

what we speculated was that something was causing ChangeScreenBuffer to fail, so checking if it returned zero, and busy loop until non zero is returned.

so yes you are correct it should be beq .nok

however the stuttering is still there. (it is displaying the buffer it is rendering to and changing to a previously rendered buffer)

the reason for this I believe is when the buffers get flipped the first time (outside of the main game loop) it gets out of sync, this is what the snippet i posted above is meant to remedy.
and so far with limited testing it works.

Last edited by abu_the_monkey; 03 October 2022 at 00:41.
abu_the_monkey is offline  
Old 03 October 2022, 01:01   #640
abu_the_monkey
Registered User
 
Join Date: Oct 2020
Location: Bicester
Posts: 1,938
here is an executable if anyone wishes to try it and let us know of any issues.

Last edited by abu_the_monkey; 08 November 2022 at 23:56.
abu_the_monkey is offline  
 


Currently Active Users Viewing This Thread: 2 (1 members and 1 guests)
Karlos
Thread Tools

Similar Threads
Thread Thread Starter Forum Replies Last Post
Alien Breed 3D II The Killing Grounds RTG patch Angus Retrogaming General Discussion 63 14 December 2022 15:20
Alien Breed & Alien Breed '92: SE - delay when picking up items / opening doors Ian support.WinUAE 16 23 December 2016 15:50
Alien Breed 3D II : The Killing Grounds code booklet alexh support.Games 19 10 October 2012 22:17
Alien Breed 3D 2 - The Killing Grounds Ironclaw support.Games 12 13 September 2005 13:07
HD Version of Alien Breed I ? Kintaro request.Old Rare Games 20 31 July 2003 10:48

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 20:10.

Top

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Page generated in 0.21367 seconds with 14 queries