Forum

> > CS2D > General > CS2D Laggy OpenGL
Forums overviewCS2D overviewGeneral overviewLog in to reply

English CS2D Laggy OpenGL

9 replies
To the start Previous 1 Next To the start

old CS2D Laggy OpenGL

Ranu
User Off Offline

Quote
This has been reported multiple times before, but I'll try to do one last to be sure of it.
Both CS2D VSync and OpenGL are highly broken (in the same way).

If you run CS2D in OpenGL without VSync, there is a noticeable around 16 (+16 due to 60 FPS lock) ms delay at each frame render. This does not happen in DirectX, it is around 0 (+16 due to 60 FPS lock) ms there. Then, if you enable CS2D VSync, you can pretty much double that delay.
To be fully sure of this, I tried removing the FPS limit and then using CS2D VSync in OpenGL, even at (120 FPS locked through third-party) with CS2D VSync enabled, it still reported around 16 ms delay at each frame considering I was having 120 FPS (1/120 = 0.0083333333333333, but 1/60 = 0.0166666666666667)

This value seems to be hard-codded by the developers around 1/60 or 16 ms/15.3+.
I highly suspect this issue is due to Blitzmax, but due to CS2D itself.
The FPS unlocker I've written is currently capable of reducing both DirectX and OpenGL render delay from [DX: 16 ms -> 0 ms], [GL without VSync: 32 ms -> 0 ms], however, it doesn't affect GL with VSync: [GL with VSync: around 64 ms -> 64 ms].
Based on that, I'm guessing this should be possible to be fixed.

Is there a plan to fix this?

old Re: CS2D Laggy OpenGL

DC
Admin On Online

Quote
Well to be honest: user SQ applied some changes to the vsync logic and I'm not sure why he did it that way and it also doesn't make much sense to me. I don't dare to touch this part of the code because I assume he had reasons to do it like that. Also it worked "okay enough" for me to simply don't bother.

e.g.:
real vsync (Flip 1) is only used when running in fullscreen with OpenGL. In all other cases Flip 0 is being called. Doesn't make sense to me but the code is explicit there so this was defintely done intentionally.

Could you please try this build? Is it any better? Or worse? How do you measure/detect the issue?
https://stuff.unrealsoftware.de/cs2d_vsync_test.zip

old Re: CS2D Laggy OpenGL

DC
Admin On Online

Quote
@user mrc: Well it's an unknown and unsigned exe distributed in a zip over the internet and it has network and file access stuff built in. Many good reasons to think it's unsafe...

old Re: CS2D Laggy OpenGL

mrc
User Off Offline

Quote
It was what I suspected, I'm going to test this exe.

@Edit: In this new exe there is delay in both DirectX and OpenGL.
edited 1×, last 22.09.24 10:09:17 pm

old Re: CS2D Laggy OpenGL

Ranu
User Off Offline

Quote
@user DC: The new build is worse, as if running CS2D in FullScreen OpenGL with VSync enabled.
I assume the only VSync that works is the one that is in FullScreen, the other doesn't seem to be functional at all.
The FullScreen VSync is working, but working very poorly. The other (if exists even) not at all.

I have third party programs to measure latency, some of them are directly working with the GPU driver, while the rest through intercepting graphic-related DLLs inside of CS2D. I've also written my own DLL that I inject into CS2D to hook certain functions and be able to measure time taken, or do benchmarks on them.

After spending a couple hours, going through every function one by one I found something interesting.
The FullScreen VSync seems to be affecting game ticks significantly worse.
The best thing here is to do a comparison between file cs2d [Ranu] CS2D - FPS Unlocked and the VSync. The way the FPS unlocker works, it changes a couple variable values inside of the function that deals with those variables, in there, there is a bunch of code related to tick and graphic stuff including Sleep(1) and it is one of the reasons of what causes CS2D FPS to be unstable jumping between 60-63, but it is there to reduce CPU load at the cost of FPS stability So, this is an important function, and normally this function (that handles FPS stuff mostly) gets called around 60 times per second or we can say exactly what FPS you have. If for whatever reason, you decide to call this function less often that needed, then you'll suffer from losing ticks/FPS.

One of the things that VSync does in CS2D, is reducing the ticks and FPS you have, resulting in a slower and high latency game. As proven here (ticks exaggerated):
https://youtu.be/TBaGE7ooz8Y
and here: https://youtu.be/f2pdrxnhE4U

You should note that all of that explanation above was just for one of the tens of functions that it affects related to graphics and ticks. One of the functions that it affects is really one of the game main functions that also contains key words such as
1
":PhysicsProjectile", ":PhysicsUniqueID", ":PhysicsObject", ":PhysicsWall", ":PhysicsItem", ":TLightSource", ":PhysicsPlayer", ":PhysicsController", ":PhysicsPlatform", ":TImage"
The function which contained the FPS variables and stuff basically was getting called from a part within the main function in a loop.

The issue seems to be both Blitzmax and CS2D
edited 2×, last 22.09.24 10:08:49 pm

old Re: CS2D Laggy OpenGL

DC
Admin On Online

Quote
If my change made it worse I don't see much more options I could try. I'm afraid I can't fix it.

old Re: CS2D Laggy OpenGL

SQ
Moderator Off Offline

Quote
Modifying this code could cause crashes when adjusting graphics settings in game mode... proceed with caution. I’ve been working to reduce latency, which is why I’ve included various debugging tools. The main issue is that both the CPU, GPU and integer waiting times are tied to the same loop, causing bottlenecks, though that you figured out. Implementing a new native waiter could help improve the situation.
To the start Previous 1 Next To the start
Log in to replyGeneral overviewCS2D overviewForums overview