Map Database  •  FAQ  •  RSS  •  Login

New level of Trolling

<<

Esthlos

User avatar

Knight

Posts: 676

Joined: 23 Jun 2013, 16:02

KaM Skill Level: Beginner

Post 24 Jun 2014, 08:35

Re: New level of Trolling

Idea: would it be possible to implement a priority system of rollbacks?
Something like this:
If you have less than, let's say, 15 fps, "ambient" animations (house, trees, water...) start to skip frames: they are still visible and usable, just more "static".
If not enough, unit sprites skip frames (maybe civilians' animations first?).
If not enough, "ambient" animations stop altogether.
If zoomed out a lot, every sprite is changed with little, low-res, static ones.

(I have no idea of what does usually clog CPUs or RAM, thus I can't provide examples related to their work)

This should improve performance while keeping the game playable for everyone, with just minor annoyances for those players with weaker hardware.

What do you think?
Could this be done?
Would it require a lot of work to implement?

As far as I understand it, this is sort of what Mass Effect 3 does... my PC doesn't meet the recommended system requirements (hell, it barely meets the minimum ones), yet I can play fine with the standard graphic settings - the worst that happens is that my character "freezes" mid-air (that's the most noticeable effect), but the game is always perfectly playable and good looking, and the FPS is always fine.
Just when you think you know something, you have to look at it in another way, even though it may seem silly or wrong. You must try! - John Keating, "Dead Poets Society"
<<

Duke Valennius

User avatar

Militia

Posts: 44

Joined: 10 Jul 2013, 11:01

KaM Skill Level: Average

Post 26 Jun 2014, 08:01

Re: New level of Trolling

...
What do you think?
Could this be done?
Would it require a lot of work to implement?
...
I don't think that anything you suggested would help. The thing is that rendering is not stalled by CPU nor GPU, but by communication between them. You see, KaM Remake uses "ancient" version of OpenGL for compatibility purposes, but that also means it uses the most horrible, slowest way to render (I have checked the code for rendering terrain). I made a simple test and with normal zoom, my GPU works at 24%, while with max. zoom out, only 17%, and framerate drops horribly, and I don't think that CPU has much to do which would slow it down so badly.

Since newer versions of OpenGL came with better and faster way to render stuff, those old methods that Remake uses got dropped from specifications and are supported by graphics cards only for the sake of compatibility. I would be surprised if someone would worry about its performance (and surprised that they are still supported anyway :P).

Of course, I might be wrong here, but this would be my best bet.
<<

Lewin

User avatar

KaM Remake Developer

Posts: 3822

Joined: 16 Sep 2007, 22:00

KaM Skill Level: Skilled

ICQ: 269127056

Website: http://lewin.hodgman.id.au

Yahoo Messenger: lewinlewinhodgman

Location: Australia

Post 27 Jun 2014, 06:38

Re: New level of Trolling

@Esthlos: Freezing animations will not improve the framerate in a sprite based game like KaM. Animating is literally just using a different sprite than you did last time (so stepping the animation simply requires adding 1 to a number, the index of which sprite you are using). Either way, (freezing or stepping to next frame) you must still paint a sprite onto the screen (the entire screen must be redrawn for every frame, there's really no way around that). The only way to improve FPS like that is to skip painting something that you would normally have to paint. For example when you zoom out all of your units and houses could disappear, that would improve FPS. But it would also look really bad so we're not going to do that :P
You see, KaM Remake uses "ancient" version of OpenGL for compatibility purposes, but that also means it uses the most horrible, slowest way to render (I have checked the code for rendering terrain).
We support very old OpenGL drawing calls (glBegin) as well as slightly more modern techniques such as vertex buffer objects (VBOs). If your graphics card supports vertex buffer objects then terrain will be drawn that way, which IIRC gives ~20% FPS boost due to less API calls (take a look at the code again, the old OpenGL calls are only used if VBOs aren't supported). So no, we're not only using ancient OpenGL tech, but we need to keep supporting it because a significant number of people are playing KaM Remake on hardware which only supports old OpenGL versions (in the past we received lots of bug reports because we accidentally broke compatibility with OpenGL 1.5 which is ancient, but obviously still used). However, obviously in a sprite based game there's not much point using shaders or other modern tech, since we're just drawing sprites. Modern OpenGL features like shaders are not very useful in a game like KaM.
Since newer versions of OpenGL came with better and faster way to render stuff, those old methods that Remake uses got dropped from specifications and are supported by graphics cards only for the sake of compatibility. I would be surprised if someone would worry about its performance (and surprised that they are still supported anyway :P).
I doubt GPU manufacturers will ever drop support for old OpenGL calls. Once something is in an API it's very hard to stop supporting it, since there's still old games that use it. It's also not hard for the driver to translate old OpenGL commands into modern commands (GPU hardware no longer contains a fixed function pipeline, it gets converted into unified pipeline instructions).

Yes, there are "better and faster way to render stuff" if the 'stuff' is a complex 3D scene with fancy lighting/effects. But for simple sprites there's not much difference in using modern or old techniques. If you're drawing a lot of triangles then API call overhead can slow you down, hence we use VBOs for terrain (but as I said that only gave a modest FPS boost).
I made a simple test and with normal zoom, my GPU works at 24%, while with max. zoom out, only 17%, and framerate drops horribly, and I don't think that CPU has much to do which would slow it down so badly.
Firstly, we have a frametime cap of 16ms (62.5 FPS) so at normal zoom it's not at all surprising that your GPU is only getting 24% utilization. Your CPU is probably sleeping for 5ms between frames because it is achieving the desired framerate (or you have VSync on which limits it anyway). So saying that low GPU utilization means the game is inefficient is only relevant when you have VSync off and are getting significantly less than the framerate cap.

Secondly, there's an issue in r5503 where when you zoom out your FPS is lower than it should be because the CPU is Z-sorting sprites using an inefficient bubble sort. So in the next release (including r6157 beta) you'll find the FPS is slightly better when zoomed out. However, games which use 100% of your GPU cores are typically shader heavy (modern 3D games). KaM rendering does not involve heavy GPU loads because we're simply drawing sprites, not 3D scenes with complex shaders to calculate lighting, reflections, ambient brightness, etc. So if you have a modern GPU then rendering KaM will probably be CPU bound.

If we really cared about improving framerate and completely rewrote our entire renderer to use OpenGL 4 commands and shaders and minimize CPU to GPU communication, and so on, we might be able to squeeze a 20%-30% improvement in framerate. But then half of our users will be unable to play the game because their OpenGL 1.5 graphics card doesn't even support shaders, or only supports OpenGL 2.0, or something like that. And we certainly don't want to maintain 2 separate render engines just to give players with modern GPUs a slightly higher FPS. If you have a modern GPU then you probably have no FPS problems at all. I get a playable 29 FPS on a 256x256 map (Paradise Island) at maximum zoom out with the whole map visible (for terrain tiles alone that's 65536 tiles to be rendered, which is 131072 triangles which all need different texture offset/rotation), and that's on my laptop! So if anything we should be optimising rendering for the old hardware where FPS is a problem, which means we need to use old OpenGL tech anyway.

How many other RTS games with maps as big as KaM let you zoom out to see the entire map anyway? Most games limit zooming quite heavily so your FPS stays nice and stable. We could try something like that for multiplayer, or at least flash a message on their screen "warning: your FPS is low due to being zoomed out, please zoom in". But then that message will be on screenshots when people zoom out to take a screenshot, so I'm not sure that's a good idea either.
<<

Duke Valennius

User avatar

Militia

Posts: 44

Joined: 10 Jul 2013, 11:01

KaM Skill Level: Average

Post 27 Jun 2014, 07:50

Re: New level of Trolling

Your CPU is probably sleeping for 5ms between frames because it is achieving the desired framerate (or you have VSync on which limits it anyway). So saying that low GPU utilization means the game is inefficient is only relevant when you have VSync off and are getting significantly less than the framerate cap.
I only meant that GPU utilization gets lower when zooming out, of course it wouldn't make any sense to run 1000 FPS with default zoom. Bit off-topic question: "CPU sleeping between frames" is I guess an actual thread sleeping? (I can see that CPU core usage is not 100% with vsync off). If yes, is this done by regular "sleep" function or is there a better way to do it? I'm asking because when I tried using "sleep" to wait between frames, it looked just horrible in terms of smoothness (at least C++ specs. says that "sleep" will wait at least specified time, not exact). So I ended up using busy-waiting which is bit wasteful. Or maybe it is just not as visible in KaM...
bubble sort
So this would explain why it is CPU limited :D and makes my guess invalid.

I understand that making two renderers isn't a good way to go, and sorry I missed VBOs in terrain rendering (it didn't cross my mind for some reason to check for more when I saw glBegin part).
<<

Esthlos

User avatar

Knight

Posts: 676

Joined: 23 Jun 2013, 16:02

KaM Skill Level: Beginner

Post 27 Jun 2014, 07:52

Re: New level of Trolling

@Esthlos: Freezing animations will not improve the framerate in a sprite based game like KaM. Animating is literally just using a different sprite than you did last time (so stepping the animation simply requires adding 1 to a number, the index of which sprite you are using). Either way, (freezing or stepping to next frame) you must still paint a sprite onto the screen (the entire screen must be redrawn for every frame, there's really no way around that). The only way to improve FPS like that is to skip painting something that you would normally have to paint. For example when you zoom out all of your units and houses could disappear, that would improve FPS. But it would also look really bad so we're not going to do that :P
Understood, thank you.

Another idea: would it be possible to change some select sprites with "grouped" versions, in order to improve FPS on weaker machines?
Roads, for example: there should be only 4 possible dispositions of 2 continuous road tiles (vertical, horizontal, and 2 oblique); in big cities and when zoomed out, rendering road tiles by groups (that means, having a sprite depicting 2 road tiles and using it) instead of individually where possible could give a FPS boost?
Units could be treated in a similar way, since when moving in formation they often use the same sprite and the same animation frame...

What do you think?
Would this help, or would the game use as many resources to render 2 sprites as it would use to render a single sprite twice as big?
Just when you think you know something, you have to look at it in another way, even though it may seem silly or wrong. You must try! - John Keating, "Dead Poets Society"
<<

Lewin

User avatar

KaM Remake Developer

Posts: 3822

Joined: 16 Sep 2007, 22:00

KaM Skill Level: Skilled

ICQ: 269127056

Website: http://lewin.hodgman.id.au

Yahoo Messenger: lewinlewinhodgman

Location: Australia

Post 27 Jun 2014, 09:35

Re: New level of Trolling

I only meant that GPU utilization gets lower when zooming out, of course it wouldn't make any sense to run 1000 FPS with default zoom. Bit off-topic question: "CPU sleeping between frames" is I guess an actual thread sleeping? (I can see that CPU core usage is not 100% with vsync off). If yes, is this done by regular "sleep" function or is there a better way to do it? I'm asking because when I tried using "sleep" to wait between frames, it looked just horrible in terms of smoothness (at least C++ specs. says that "sleep" will wait at least specified time, not exact). So I ended up using busy-waiting which is bit wasteful. Or maybe it is just not as visible in KaM...
For the framerate cap we use sleep, and haven't noticed any smoothness issues. Probably because KaM is animated fairly slowly.
Another idea: would it be possible to change some select sprites with "grouped" versions, in order to improve FPS on weaker machines?
Roads, for example: there should be only 4 possible dispositions of 2 continuous road tiles (vertical, horizontal, and 2 oblique); in big cities and when zoomed out, rendering road tiles by groups (that means, having a sprite depicting 2 road tiles and using it) instead of individually where possible could give a FPS boost?
Units could be treated in a similar way, since when moving in formation they often use the same sprite and the same animation frame...

What do you think?
Would this help, or would the game use as many resources to render 2 sprites as it would use to render a single sprite twice as big?
That means we need to store another texture on the GPU memory with the grouped version, so that will use a lot more memory. And things are never aligned perfectly enough to do that. Roads are on different angles (tiny variations in terrain height), units walk out of sync and in different directions, etc. Even if it was possible in the best case it would only save us maybe 50 sprites being rendered, which is nothing compared to the number of terrain tiles on your screen at once (256x256 map has 65536 tiles remember, so even if you're only seeing a quarter of it that's still 16k tiles to be rendered).

Do you think render performance is a problem? I'd put it very low on the priority list, but I don't play online often enough to know if it causes issues.
<<

Esthlos

User avatar

Knight

Posts: 676

Joined: 23 Jun 2013, 16:02

KaM Skill Level: Beginner

Post 27 Jun 2014, 12:53

Re: New level of Trolling

That means we need to store another texture on the GPU memory with the grouped version, so that will use a lot more memory. And things are never aligned perfectly enough to do that. Roads are on different angles (tiny variations in terrain height), units walk out of sync and in different directions, etc. Even if it was possible in the best case it would only save us maybe 50 sprites being rendered, which is nothing compared to the number of terrain tiles on your screen at once (256x256 map has 65536 tiles remember, so even if you're only seeing a quarter of it that's still 16k tiles to be rendered).
Ok, thank you.
Do you think render performance is a problem? I'd put it very low on the priority list, but I don't play online often enough to know if it causes issues.
No. Yes. I don't know! :$
Neither do I play online.

I only know that it is enough of a problem to cause the existence of this thread, and that the last time I played CoOp with my father we couldn't finish the game because it slowed down to a crawl (between to 2 and 5 FPS, depending on where his screen was; my PC can handle Mass Effect 3 pretty well, his laptop isn't as good but can still handle Port Royale 2, Tropico and KaM TPR perfectly).
Just when you think you know something, you have to look at it in another way, even though it may seem silly or wrong. You must try! - John Keating, "Dead Poets Society"

Return to “Feedback / Discussion”

Who is online

Users browsing this forum: No registered users and 0 guests