29 September 2022, 01:24 | #621 |
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 **************************************************************** @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. |
29 September 2022, 10:00 | #622 | |
Registered User
Join Date: Jun 2015
Location: Germany
Posts: 1,918
|
Quote:
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. |
|
29 September 2022, 23:06 | #623 |
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 |
30 September 2022, 13:06 | #624 |
Alien Bleed
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. |
30 September 2022, 15:41 | #625 | |
Registered User
Join Date: Jun 2015
Location: Germany
Posts: 1,918
|
Quote:
Code:
.nok: CALLINT ChangeScreenBuffer ; DisplayMsgPort will be notified if this image had been fully scanned out **************************************************************** tst.l d0 bne .nok .ok **************************************************************** 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? |
|
01 October 2022, 10:15 | #626 |
Alien Bleed
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. |
01 October 2022, 19:56 | #627 |
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. |
01 October 2022, 20:03 | #628 |
Alien Bleed
Join Date: Aug 2022
Location: UK
Posts: 4,119
|
|
02 October 2022, 10:59 | #629 |
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. |
02 October 2022, 11:08 | #630 |
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?
|
02 October 2022, 11:32 | #631 |
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. |
02 October 2022, 12:10 | #632 |
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 Last edited by abu_the_monkey; 02 October 2022 at 12:25. |
02 October 2022, 12:46 | #633 |
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 |
02 October 2022, 12:55 | #634 |
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 |
02 October 2022, 12:58 | #635 |
Registered User
Join Date: Oct 2020
Location: Bicester
Posts: 1,938
|
think I am getting confused
|
02 October 2022, 13:41 | #636 |
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. |
03 October 2022, 00:05 | #637 |
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? |
03 October 2022, 00:13 | #638 | |
Registered User
Join Date: Mar 2012
Location: Norfolk, UK
Posts: 1,153
|
Quote:
Shouldn't that last "bne" be "beq"? ChangeScreenBuffer returns non-zero on success, zero if the update couldn't be performed, I think? |
|
03 October 2022, 00:26 | #639 |
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. |
03 October 2022, 01:01 | #640 |
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. |
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 |
|
|