FunkyFr3sh / cnc-ddraw

GDI, OpenGL and Direct3D 9 re-implementation of the DirectDraw API for classic 2D games for better compatibility with Windows 2000, XP, Vista, 7, 8, 10, 11, Wine (Linux/macOS/Android) and Virtual Machines
https://discord.gg/afWXJNDDF5
MIT License
2.13k stars 143 forks source link

RA2/YR Screen Tearing on mouse scroll #263

Closed MDX-Tom closed 1 month ago

MDX-Tom commented 8 months ago

When the view is scrolled in game, screen tears badly (as is shown in the video).

My system (tried both, both have the problem): i5-8250U (UHD 620, no other GPU), 8G RAM i5-7500 (HD 630, no other GPU) Also tried 3 monitors and 2 mouses, all have the same problem.

The configurations used in the video is: screen res: 1920x1080 (also tried 1024x768/800x600, the same) vsync: off mode: full screen whether limiting frame rate to sync the monitor does not affect the tearing effect.

https://github.com/FunkyFr3sh/cnc-ddraw/assets/6468993/a5400bad-064e-45be-a534-88ebea48f011

I've also tried turning ON Vsync, and the tearing effect is gone. However, for the particular frames where the screen used to tear, there remains a laggy effect (in just those frames). (I can provide another video for this if needed).

If I switch full screen mode into borderless window mode (vsync off), the frame rate goes to less than 30 fps as I move view field in game, so it cannot be decided whether screen tearing is gone because it becomes too laggy.

MDX-Tom commented 8 months ago

Also tried DDrawCompact, looks a bit different but the tearing effect is still clearly visible.

FunkyFr3sh commented 8 months ago

you could try borderless and disable the frame rate limiter in ddraw.ini

For this game the limiter is forced to 60 by default:

[gamemd] maxfps=-1

MDX-Tom commented 8 months ago

Negative. I tried this setting on both i5-8250U and i5-7500 platforms, however no matter what the particular setting of "maxfps" is, as long as I run RA2 in borderless window mode, it will become very laggy as you can see in the video. I cannot decide whether it is the FPS going very low or it is the frequency of the occurrence of the screen tearing effect getting much higher.

https://github.com/FunkyFr3sh/cnc-ddraw/assets/6468993/985b0cf6-f88a-4fd8-982e-e01e1adf023a

Settings used in this video: windowed=true maxfps=0 vsync=false maxgameticks=-1 minfps=0

This is very strange as the problem (screen tearing but fps ok in full screen) or (very laggy in window mode) only occurs when the view is scrolled. If the view is fixed to one place in the map (no scrolling), then everything is fine (very smooth 60 fps, no tearing).

MDX-Tom commented 7 months ago

Oh my, I've brought an AMD 7840HS device (with 780M igpu), it turns out that there is nothing to blame with Intel HD/UHD graphics, because the problem exists even on the latest AMD platforms.

MDX-Tom commented 7 months ago

It appears that the screen tearing and the laggy problem are separated.

Screen tearing can be fixed by "vsync=true" or borderless mode.

Laggy effect on scroll is related to the game speed (or "maxgameticks"?). Experimental results (set "maxgameticks=-1" in "ddraw.ini"): 1) game speed (tuned in RA2/YR) is 4: very laggy (as i scroll it only renders ~30fps). 2) game speed 5 (normal 60fps): only a bit laggy (say it lags/pauses render for 10fps every 60fps). 3) game speed 6 (unlimited fps, actual 200~300fps): scroll is very smooth to the refresh rate of my screen (it renders 60fps when I scroll without any lag).

So why does the "game speed 5" case lag, as the rendered fps ought to be synchronized to the refresh rate (60fps) but it doesn't!

Mitradis commented 6 months ago

Can confirm. Game stutter on scroll and scroll not smooth. I wanted to write about it myself, but I saw this thread. i use vsync and maxfps cap, i try change many settings and nothing to helps. On game scroll image move not smooth, it have micro freezes and stuttering. I'll make a video later.

Mitradis commented 6 months ago

Game micro freezes and stuttering on scroll: https://youtu.be/IiK0rv28OiY On game scroll happened this (save behaviour i see in game lord of the rings the battle for middle-earth (which have fps cap 30): image RA2 have 30fps scroll frame rate? For example in Tiberian Sun i have PERFECT smooth camera scroll and no scroll artifacts with double elements.

Mitradis commented 6 months ago

Additional (on 2:55 in video): in fullscreen windowed mode main menu move in top left screen position (with 1280720). With 19201080 normal centered position...

FunkyFr3sh commented 5 months ago

Scroll rate seems to be tied to game speed in this game, so it's probably not possible to fix it without making a game patch. All older c&c games have the issue where the scroll rate is too fast, in this game they probably wanted to fix these issues and did some changes

MDX-Tom commented 5 months ago

It is agreed for the conclusion on "Scroll rate is tied to game speed", as gamespeed 4 (30fps) scrolls at 30fps, gamespeed 5 (60fps) scrolls at 60fps, and gamespeed 6 (no fps limit) scrolls to the maximum refresh rate of the monitor.

But our problem is that gamespeed 5 (60fps) should scroll at 60fps but there is verrrrry slight difference, which makes it unable to sync with the refresh rate of the monitor (60Hz).

  1. vsync=true option only fixes screen tearing but not the laggy effect when the screen used to tear.
  2. setting maxfps=-1 does not change the tearing and laggy effect.

Only when I change gamespeed to 6 (no fps limit) shall the scrolling be smooth. So there is definitely something to do with the synchronization or rendered fps controlling.

stulluk commented 5 months ago

Under wine with Ubuntu 22.04 , can confirm the exactly same issue. The scroll is perfectly smooth with game speed = 6. But there are many stuttering and tearing occurs when game speed = 5 (which is sadly the only playable speed IMHO). Also same with speed = 4.

Enabling or disabling Vsync does not have any effect.

And in addition, I feel this game shouldn't consume so much CPU with a decent Ryzen 5700G :

Screenshot from 2024-02-13 01-20-35

Am I missing anything here? Any suggestions ?

FunkyFr3sh commented 5 months ago

And in addition, I feel this game shouldn't consume so much CPU with a decent Ryzen 5700G :

Am I missing anything here? Any suggestions ?

These old games all busy spin, so it's nothing unusual. A lot of old games have patches to fix that, some games can be fixed by cnc-ddraw as well (only games that "Flip")

stulluk commented 5 months ago

And in addition, I feel this game shouldn't consume so much CPU with a decent Ryzen 5700G : Am I missing anything here? Any suggestions ?

These old games all busy spin, so it's nothing unusual. A lot of old games have patches to fix that, some games can be fixed by cnc-ddraw as well (only games that "Flip")

Do you mean ra2 doesn't flip ? What does "flip" mean :)

FunkyFr3sh commented 5 months ago

And in addition, I feel this game shouldn't consume so much CPU with a decent Ryzen 5700G : Am I missing anything here? Any suggestions ?

These old games all busy spin, so it's nothing unusual. A lot of old games have patches to fix that, some games can be fixed by cnc-ddraw as well (only games that "Flip")

Do you mean ra2 doesn't flip ? What does "flip" mean :)

Yeah, it doesn't flip.

Games can either "Flip" or "Blt". Not sure how to explain it in the most simple way, but the games pretty much render the current frame in the background and once done it will either "Flip" or "Blt" to present it on your screen.

"Flip" means the game just changes two small numbers (pointers) and Blt does copy the entire picture from one buffer to another.

MDX-Tom commented 4 months ago

Update: I've tried on another device (Intel 13900HK with Iris Xe iGPU), and the problem remains.

FunkyFr3sh commented 4 months ago

Update: I've tried on another device (Intel 13900HK with Iris Xe iGPU), and the problem remains.

It probably happens for everyone on every hardware. I guess it's maybe just a bad game speed limiter that isn't accurate enough to get exactly 60 FPS (Might just be 59?)

Mitradis commented 4 months ago

Based on the behavior of the game, I got the impression that the game does this in 30fps. Because with gaps and duplication on my monitor displayed all games with 30fps (tibetian wars\ra3\LotR TBOME1\2 and some old games like Tzar). Games with true 60fps work correctly. Games may show a value of 60fps but in reality they show 2 identical frames in a row. Specifically for this game and this case, I can definitely say that there are 30fps, i just see this on my monitor (see screenshot).

RA2-CLUB commented 3 months ago

And in addition, I feel this game shouldn't consume so much CPU with a decent Ryzen 5700G : Am I missing anything here? Any suggestions ?

These old games all busy spin, so it's nothing unusual. A lot of old games have patches to fix that, some games can be fixed by cnc-ddraw as well (only games that "Flip")

Update: I've tried on another device (Intel 13900HK with Iris Xe iGPU), and the problem remains.

It probably happens for everyone on every hardware. I guess it's maybe just a bad game speed limiter that isn't accurate enough to get exactly 60 FPS (Might just be 59?)

tks ur cncddraw let many player ra2 work good, i know a thing about up's question when ur pc's Registry 计算机\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\KnownDLLs have a key named "ddraw.dll"
the ddraw.dll in ur game directory will not work, so game go on 10~20fps

if u del the 计算机\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\KnownDLLs\ddraw.dll , game will 60FPS with ur ddrawl Please be informed that

stulluk commented 3 months ago

And in addition, I feel this game shouldn't consume so much CPU with a decent Ryzen 5700G : Am I missing anything here? Any suggestions ?

These old games all busy spin, so it's nothing unusual. A lot of old games have patches to fix that, some games can be fixed by cnc-ddraw as well (only games that "Flip")

Update: I've tried on another device (Intel 13900HK with Iris Xe iGPU), and the problem remains.

It probably happens for everyone on every hardware. I guess it's maybe just a bad game speed limiter that isn't accurate enough to get exactly 60 FPS (Might just be 59?)

tks ur cncddraw let many player ra2 work good, i know a thing about up's question when ur pc's Registry 计算机\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\KnownDLLs have a key named "ddraw.dll" the ddraw.dll in ur game directory will not work, so game go on 10~20fps

if u del the 计算机\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\KnownDLLs\ddraw.dll , game will 60FPS with ur ddrawl Please be informed that

Hi RA2-CLUB, thanks for your reply, but see my regedit below:

image

In my setup, I don't have a directory in regedit ( use "wine regedit" from the cmdline ) named as KnownDLLs at all.

Secondly, to check FPS on my ubuntu 22.04 X11 machine with Ryzen5700G (AMD graphics), I simply run this command:

GALLIUM_HUD="simple,fps" wine Ra2.exe

See TOP-LEFT of the screenshot below:

Screenshot from 2024-04-03 16-58-43

And this always shows around 60FPS ( sometimes it varies between 59.9 to 60.1, which is quite normal due to VSYNC I think )

And since others also noted, I just can't understand why it is so smooth when game speed is 6 ( sadly non-playable, because objects enemies move really fast, you die very quickly )

As I explained earlier, the only playable speed is 5, and this issue happens with speed=5. It would be great to get some more verification from someone else using ubuntu 22.04 though.

MDX-Tom commented 3 months ago

And since others also noted, I just can't understand why it is so smooth when game speed is 6 ( sadly non-playable, because objects enemies move really fast, you die very quickly )

As I explained earlier, the only playable speed is 5, and this issue happens with speed=5. It would be great to get some more verification from someone else using ubuntu 22.04 though.

This is exactly what I wanted to say, we cannot explain why it only happens for speed=5 or lower but scrolling at speed=6 is extremely smooth.

stulluk commented 3 months ago

And since others also noted, I just can't understand why it is so smooth when game speed is 6 ( sadly non-playable, because objects enemies move really fast, you die very quickly ) As I explained earlier, the only playable speed is 5, and this issue happens with speed=5. It would be great to get some more verification from someone else using ubuntu 22.04 though.

This is exactly what I wanted to say, we cannot explain why it only happens for speed=5 or lower but scrolling at speed=6 is extremely smooth.

@MDX-Tom ALL your HW that you tried is INTEL based, and I am AMD based, but we experience same issue, am I understanding correctly?

What about your OS/Distro ?

MDX-Tom commented 3 months ago

@MDX-Tom ALL your HW that you tried is INTEL based, and I am AMD based, but we experience same issue, am I understanding correctly?

What about your OS/Distro ?

Oh, I have also tested on AMD 7840HS, the problem remains the same :( All my tests are run on Windows 10/11 natively (no VM)

stulluk commented 3 months ago

@MDX-Tom ALL your HW that you tried is INTEL based, and I am AMD based, but we experience same issue, am I understanding correctly? What about your OS/Distro ?

Oh, I have also tested on AMD 7840HS, the problem remains the same :( All my tests are run on Windows 10/11 natively (no VM)

TIL people are still using ancient OS like M$ windows in 2024 :) just kidding.

So, this means:

Only common point is cnc-ddraw ?

FunkyFr3sh commented 3 months ago

And in addition, I feel this game shouldn't consume so much CPU with a decent Ryzen 5700G : Am I missing anything here? Any suggestions ?

These old games all busy spin, so it's nothing unusual. A lot of old games have patches to fix that, some games can be fixed by cnc-ddraw as well (only games that "Flip")

Update: I've tried on another device (Intel 13900HK with Iris Xe iGPU), and the problem remains.

It probably happens for everyone on every hardware. I guess it's maybe just a bad game speed limiter that isn't accurate enough to get exactly 60 FPS (Might just be 59?)

tks ur cncddraw let many player ra2 work good, i know a thing about up's question when ur pc's Registry 计算机\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\KnownDLLs have a key named "ddraw.dll" the ddraw.dll in ur game directory will not work, so game go on 10~20fps

if u del the 计算机\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\KnownDLLs\ddraw.dll , game will 60FPS with ur ddrawl Please be informed that

This is a known problem, there are some chinese anti-virus tools that add this registry key. I forgot which ones it were, maybe the 360* ones? If this registry key exists then the game will not use cnc-ddraw at all, that's why the game is not running well

FunkyFr3sh commented 3 months ago

And in addition, I feel this game shouldn't consume so much CPU with a decent Ryzen 5700G : Am I missing anything here? Any suggestions ?

These old games all busy spin, so it's nothing unusual. A lot of old games have patches to fix that, some games can be fixed by cnc-ddraw as well (only games that "Flip")

Update: I've tried on another device (Intel 13900HK with Iris Xe iGPU), and the problem remains.

It probably happens for everyone on every hardware. I guess it's maybe just a bad game speed limiter that isn't accurate enough to get exactly 60 FPS (Might just be 59?)

tks ur cncddraw let many player ra2 work good, i know a thing about up's question when ur pc's Registry 计算机\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\KnownDLLs have a key named "ddraw.dll" the ddraw.dll in ur game directory will not work, so game go on 10~20fps if u del the 计算机\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\KnownDLLs\ddraw.dll , game will 60FPS with ur ddrawl Please be informed that

Hi RA2-CLUB, thanks for your reply, but see my regedit below:

image

In my setup, I don't have a directory in regedit ( use "wine regedit" from the cmdline ) named as KnownDLLs at all.

Secondly, to check FPS on my ubuntu 22.04 X11 machine with Ryzen5700G (AMD graphics), I simply run this command:

GALLIUM_HUD="simple,fps" wine Ra2.exe

See TOP-LEFT of the screenshot below:

Screenshot from 2024-04-03 16-58-43

And this always shows around 60FPS ( sometimes it varies between 59.9 to 60.1, which is quite normal due to VSYNC I think )

And since others also noted, I just can't understand why it is so smooth when game speed is 6 ( sadly non-playable, because objects enemies move really fast, you die very quickly )

As I explained earlier, the only playable speed is 5, and this issue happens with speed=5. It would be great to get some more verification from someone else using ubuntu 22.04 though.

FPS is looking good and it's working correctly (cnc-ddraw handles that) - Game speed limiter is the problem here, main loop probably repeats only 59 times a second. Skipping one game tick per second may be the reason for the odd scroll.

Dividing 1000 by 60 results in either 16 or 17 ms (depending on the rounding) which results in either 59 ticks or 62 ticks per seconds, so that's probably where the problem is coming from.

stulluk commented 3 months ago

@FunkyFr3sh this doesn't explain the smoothness when game speed is 6.

Have you tried to play it to see ?

FunkyFr3sh commented 3 months ago

@FunkyFr3sh this doesn't explain the smoothness when game speed is 6.

Have you tried to play it to see ?

I don't have the game installed right now, so I can't test. But I have been patching C&C games for over 10 years. It was also me who made the scroll speed limiter patch for Red Alert 1 and Tiberian Sun btw (If you download the community patched versions you'll get them).

In the older games the scroll/input functions were called from the busy spin loop, this is the reason why the scroll was smooth on every game speed, however, the side-effect was that the scroll was way too fast on a fast computer and too slow on a slow computer. I've not been working on red alert 2, but on all games that came out before that one, but it's fully understandable they did some changes to that logic and solved the inconsistent scroll.

The thread they'Re using for the mouse cursor also does the 1000/60 thing and is similar inaccurate so I'm assuming it's the same issue here.

Game speed 6 was unlimited, wasn't it? So that should mean that the game loop repeats like 500+ times a second on modern hardware which of course results a in smooth scroll as well (you would even get a smooth scroll on 144hz monitor like this)

stulluk commented 3 months ago

@FunkyFr3sh yes, game speed=6 is almost like unlimited. Everything is too fast. Thats why it is unplayable.

So please tell me, should we look at some portion of the codebase ( fps_limiter.c or render_ogl.c ?? ) and try to build it by ourselves to check if it is possible to make a custom cnc-ddraw.dll that can fix the issue only for RedAlert2 ?

Or how we can help you to find the reason ? Should we provide game files/instructions on how to run it?

What is stopping us to fix this?

FunkyFr3sh commented 3 months ago

@FunkyFr3sh yes, game speed=6 is almost like unlimited. Everything is too fast. Thats why it is unplayable.

So please tell me, should we look at some portion of the codebase ( fps_limiter.c or render_ogl.c ?? ) and try to build it by ourselves to check if it is possible to make a custom cnc-ddraw.ddl that can fix the issue only for RedAlert2 ?

Or how we can help you to find the reason ? Should we provide game files/instructions on how to run it?

What is stopping us to fix this?

As i said before, you cannot fix this from within cnc-ddraw, I'm 99% sure about that. I'm only keeping the issue here open because of the remaining 1% (I'm not giving the 100% until actually checked with a disassembler)

You need to patch the game to fix the game speed limiter. cnc-ddraw does not limit the game speed in cnc games (they're not using "flip")

stulluk commented 3 months ago

@FunkyFr3sh OK so we have to wait for you to install the game, and try to see what is happening with a disassembler ?

FunkyFr3sh commented 3 months ago

@FunkyFr3sh OK so we have to wait for you to install the game, and try to see what is happening with a disassembler ?

Well, I retired from patching C&C games years ago. So I'm not planning to write any game patches for them anymore. And since I'm 99% sure this is unfixable from within cnc-ddraw the chances you'll find a solution for the problem here on this repo are very low.

Best thing that could happen is that someone with reverse engineering experience is showing up here and is willing to write a patch for it.

RA2-CLUB commented 3 months ago

And in addition, I feel this game shouldn't consume so much CPU with a decent Ryzen 5700G : Am I missing anything here? Any suggestions ?

These old games all busy spin, so it's nothing unusual. A lot of old games have patches to fix that, some games can be fixed by cnc-ddraw as well (only games that "Flip")

Update: I've tried on another device (Intel 13900HK with Iris Xe iGPU), and the problem remains.

It probably happens for everyone on every hardware. I guess it's maybe just a bad game speed limiter that isn't accurate enough to get exactly 60 FPS (Might just be 59?)

tks ur cncddraw let many player ra2 work good, i know a thing about up's question when ur pc's Registry 计算机\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\KnownDLLs have a key named "ddraw.dll" the ddraw.dll in ur game directory will not work, so game go on 10~20fps if u del the 计算机\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\KnownDLLs\ddraw.dll , game will 60FPS with ur ddrawl Please be informed that

Hi RA2-CLUB, thanks for your reply, but see my regedit below: image In my setup, I don't have a directory in regedit ( use "wine regedit" from the cmdline ) named as KnownDLLs at all. Secondly, to check FPS on my ubuntu 22.04 X11 machine with Ryzen5700G (AMD graphics), I simply run this command:

GALLIUM_HUD="simple,fps" wine Ra2.exe

See TOP-LEFT of the screenshot below: Screenshot from 2024-04-03 16-58-43 And this always shows around 60FPS ( sometimes it varies between 59.9 to 60.1, which is quite normal due to VSYNC I think ) And since others also noted, I just can't understand why it is so smooth when game speed is 6 ( sadly non-playable, because objects enemies move really fast, you die very quickly ) As I explained earlier, the only playable speed is 5, and this issue happens with speed=5. It would be great to get some more verification from someone else using ubuntu 22.04 though.

FPS is looking good and it's working correctly (cnc-ddraw handles that) - Game speed limiter is the problem here, main loop probably repeats only 59 times a second. Skipping one game tick per second may be the reason for the odd scroll.

Dividing 1000 by 60 results in either 16 or 17 ms (depending on the rounding) which results in either 59 ticks or 62 ticks per seconds, so that's probably where the problem is coming from.

I have solved many of these problems for china ra2/yr player with win10\win11 os. I don't know how this(KnownDLLs\ddraw.dll) came about, 99% PC dont have it , ddraw.dll work very good in ra2 directory. 1% pc have KnownDLLs\ddraw.dll in Registry,the 1% pc 's game is very low fps, the ddraw.dll in game directory is invalid if u del the 计算机\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\KnownDLLs\ddraw.dll the 1% pc will 60fps , ddraw.ll will work very well too. can u fix it? Remote del \Session Manager\KnownDLLs\ddraw.dll is very troublesome every time。tks

RA2-CLUB commented 3 months ago

And in addition, I feel this game shouldn't consume so much CPU with a decent Ryzen 5700G : Am I missing anything here? Any suggestions ?

These old games all busy spin, so it's nothing unusual. A lot of old games have patches to fix that, some games can be fixed by cnc-ddraw as well (only games that "Flip")

Update: I've tried on another device (Intel 13900HK with Iris Xe iGPU), and the problem remains.

It probably happens for everyone on every hardware. I guess it's maybe just a bad game speed limiter that isn't accurate enough to get exactly 60 FPS (Might just be 59?)

tks ur cncddraw let many player ra2 work good, i know a thing about up's question when ur pc's Registry 计算机\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\KnownDLLs have a key named "ddraw.dll" the ddraw.dll in ur game directory will not work, so game go on 10~20fps if u del the 计算机\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\KnownDLLs\ddraw.dll , game will 60FPS with ur ddrawl Please be informed that

Hi RA2-CLUB, thanks for your reply, but see my regedit below: image In my setup, I don't have a directory in regedit ( use "wine regedit" from the cmdline ) named as KnownDLLs at all. Secondly, to check FPS on my ubuntu 22.04 X11 machine with Ryzen5700G (AMD graphics), I simply run this command:

GALLIUM_HUD="simple,fps" wine Ra2.exe

See TOP-LEFT of the screenshot below: Screenshot from 2024-04-03 16-58-43 And this always shows around 60FPS ( sometimes it varies between 59.9 to 60.1, which is quite normal due to VSYNC I think ) And since others also noted, I just can't understand why it is so smooth when game speed is 6 ( sadly non-playable, because objects enemies move really fast, you die very quickly ) As I explained earlier, the only playable speed is 5, and this issue happens with speed=5. It would be great to get some more verification from someone else using ubuntu 22.04 though.

FPS is looking good and it's working correctly (cnc-ddraw handles that) - Game speed limiter is the problem here, main loop probably repeats only 59 times a second. Skipping one game tick per second may be the reason for the odd scroll.

Dividing 1000 by 60 results in either 16 or 17 ms (depending on the rounding) which results in either 59 ticks or 62 ticks per seconds, so that's probably where the problem is coming from.

ddraw

FunkyFr3sh commented 3 months ago

@RA2-CLUB The problem is "360 antivirus" or "Qihoo 360" - It does add this registry key and I cannot solve it. You just have to tell them to use a different antivirus software

RA2-CLUB commented 3 months ago

问题是“360 防病毒软件”或“奇虎 360” - 它确实添加了此注册表项,我无法解决它。您只需要告诉他们使用不同的防病毒软件

Thank you for your message

MDX-Tom commented 3 months ago

Well, I retired from patching C&C games years ago. So I'm not planning to write any game patches for them anymore. And since I'm 99% sure this is unfixable from within cnc-ddraw the chances you'll find a solution for the problem here on this repo are very low.

Best thing that could happen is that someone with reverse engineering experience is showing up here and is willing to write a patch for it.

Understood.

btw. Indeed I am from China, but I never use trash antivirus software like 360 haha :) and I don't have such registry keys.

universal963 commented 3 months ago

Indeed I personally have seen numerous comments about 360 blocking "dll hijacking" or something which prevented cnc-ddraw to get loaded normally. And for the scrolling, RA2 is not the same as older titles. From my own tests, the scrolling is limited in singleplayer modes (campaign and skirmish), and is not in multiplayer modes(LAN, and maybe WOL, which I cannot assure for I did not test it). So when you play campaign or skirmish you may feel stuttered, but if you try to play in LAN, the lightning-fast scrolling comes again. Here is a deeper note. I have done some incomplete disassembly analysis and found the game treats scrolling differently by game modes. The picture below shows the checks in YR(gamemd.exe). pic1 Take game speed 4 as an example. If limited, the scrolling speed will be the same as game speed, and the limiter there is not quite accurate, which causes the loop limited to 32ms, approximately 31 times per second. If not limited, scrolling is not limited, and that limiter only limits game speed, around 33ms, approximately 30 times per second. I have no idea about the reason they did such though. Despite it is not fully clear, one can try to disable the checks and let the singleplayer mode use the multiplayer's limiter, thus getting lightning-fast scrolling back to singleplayer. And in order to do that, another check is needed to be disabled too: pic2

stulluk commented 3 months ago

@universal963 thank you so much for looking into it.

Here is my directory content in my wine-redalert2 :

image

Here, you can see that during running RedAlert2, most CPU consuming executable is game.exe:

https://github.com/FunkyFr3sh/cnc-ddraw/issues/263#issuecomment-1939781527

So I shared those binaries (Ra2.exe, gamemd.exe and game.exe) here: ra2-orig.zip

I don't have abilities to read / understand/ edit windows assembly, could you please help us to edit those binaries so that everybody can benefit from your amazing effort?