Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » 2D Isometric Game extreme lag.

This thread is locked; no one can reply to it. rss feed Print
2D Isometric Game extreme lag.
Matias Persson
Member #15,093
May 2013

Hi, I'm writing on behalf of a guy in a community online who's developing a client for an old game that is now dead, we are limited with the features of the official closed-source client, but this guy has taken upon himself to make a client that emulates the old client.

I've ported the code to Visual Studio for him, in the hopes that it would fix the lag that we are experiencing with the client. We don't really have a clue about what is happening that causes the lag, but it's there and yeah well, not playable really.

I can log on to a private server that I make with 1 map, no entities, walls etc, just tiles - and the lag seems to be reduced as opposed to a map where there are a lot of other players or entities.

I have linked the project below. Just fyi, it's a Visual Studio 2019 solution.
You make take the code and put it into Codeblocks instead, but some changes to code may need to be made for it to run on Codeblocks since I just ported it from Codeblocks to MSVS.

Hope someone can help clear up this issue, as the creator have looked and I have looked. We can't seem to figure out what is going on.

Build using Debug + x86, otherwise you'll have to configure winsockets + allegro for your desired configuration.
https://arcanelands.net/eoplay/eoplay.zip

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

This is a big project. It may be a little before I can get it to build.

What have you tried debugging wise? Have you tested latency? Ping?

EDIT
I'm trying to build this in CB, but it throws a ton of warnings, some of which you can't ignore. Until you fix the warnings, I can't really help. A CMakeLists.txt file would also go a long way towards getting other people to help you.

Chris Katko
Member #1,881
January 2002
avatar

1) what is "lag" in this scenario? Actual delay between control input and output? Or reduced frame rate?

2) have you used a profiler?

[edit]

3) Are you drawing all the isometric tiles even if they're outside the screen?

I take it this is the game?

video

And you're not saying the NETWORKING bandwidth is causing it to run slow, right?

-----sig:
“Programs should be written for people to read, and only incidentally for machines to execute.” - Structure and Interpretation of Computer Programs
"Political Correctness is fascism disguised as manners" --George Carlin

Matias Persson
Member #15,093
May 2013

Edgar Reynaldo here is a CMakeLists attached.
Might want to remove lines in the CMakeLists file as I forgot to do it
../egf/*.hpp -> All lines named like this, remove them, as they are not actual files in the zipped project I attached.
Note: It probably won't run in Codeblocks anyway, since I ported it from Codeblocks to Visual Studio and had to make certain changes for Visual C compiler to pick it up. Not sure if GCC can pick up these changes as valid code.

Chris Katko, no that is not the game. That's a game I'm developing from scratch inspired from Endless Online. Although the client in the video is not developed by me.
The program in question here in this thread is attached, which is supposed to be an identical clone of the official client 0.28.

1) what is "lag" in this scenario? Actual delay between control input and output? Or reduced frame rate?
Extreme reduced frame rate + lag with controls. Hit a key, it starts walking 2 seconds after + everything has reduced frame rate, even more when more entities on the game.
The lag + input lag decreases as I walk on a small empty map.

2) have you used a profiler?
Dunno what that is really, also not sure, since I didn't write the code, but I have looked into it and I can't really figure out what's causing the lag.

[edit]

3) Are you drawing all the isometric tiles even if they're outside the screen?
I believe the code writes only the tiles that are in the screen.

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

Matias Persson
Member #15,093
May 2013

Sorry no, a guy named Sausage made that CMakeLists file and I have no experience with CMake. I can ask him, but he might or might not give it to me, idk.

Edit: Attached a cmake file

Chris Katko
Member #1,881
January 2002
avatar

1) what is "lag" in this scenario? Actual delay between control input and output? Or reduced frame rate?
Extreme reduced frame rate + lag with controls. Hit a key, it starts walking 2 seconds after + everything has reduced frame rate, even more when more entities on the game.
The lag + input lag decreases as I walk on a small empty map.

OKay, I asked because this is actually a common scenario with new developers. IF you setup your game loop wrong where it "schedules" the draw update / logic update every X milliseconds, and the drawing or logic logic takes too long (longer than the schedule), you can have a scenario where more and more frames are "queued up" which leads to longer and longer time between key commands and the screen updating.

Quote:

Dunno what that is really, also not sure, since I didn't write the code, but I have looked into it and I can't really figure out what's causing the lag.

A profiler runs the game, and tells you which functions of the code are taking the longest to run. It's a good clue to find problems.

If I can get it to run on one of my systems, I'll try and run it. But I can't guarantee a timeframe yet.

-----sig:
“Programs should be written for people to read, and only incidentally for machines to execute.” - Structure and Interpretation of Computer Programs
"Political Correctness is fascism disguised as manners" --George Carlin

SiegeLord
Member #7,827
October 2006
avatar

I compiled it, ran it and debugged the issues. Your game has many issues.

The primary cause of slowness is how you use your loading thread. In your loading thread you load bitmaps as memory bitmaps (good), but in your drawing thread you never convert them to video bitmaps, which means you're drawing using memory bitmaps only which is very slow.

That's relatively easy to fix for bitmaps at least, inside your Bitmap::Loaded function, you can do:

if (!(b && (flag & ALLEGRO_VIDEO_BITMAP)))
{
  al_convert_bitmap(bitmap.get());
}

And that'll convert the bitmaps. You also need to do this for fonts, which isn't as easy. I suggest loading the fonts as bitmaps in the loading thread, and then using al_convert_bitmap + al_grab_font_from_bitmap in the drawing thread. Maybe we (Allegro devs) should add a al_convert_bitmap_font to make this easier. See this example for how to do loading threads correctly: ex_loading_thread.

There may be more memory bitmaps, but those were the main ones I saw. There are many more issues other than this though!

First, I noticed you're calling al_create_bitmap every frame when drawing characters, you'll want to not do that: pre-create your bitmaps on-load.

Second, even if you convert everything to video bitmaps, it'll still be somewhat slow unless you use al_hold_bitmap_drawing around your drawing for loops:

al_hold_bitmap_drawing(true);
for (...)
  DrawTinted()
al_hold_bitmap_drawing(false);

"For in much wisdom is much grief: and he that increases knowledge increases sorrow."-Ecclesiastes 1:18
[SiegeLord's Abode][Codes]:[DAllegro5]:[RustAllegro]

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

Matias Persson
Member #15,093
May 2013

I added al_convert_bitmap(bitmap.get());
Still very choppy.
You can try and log in with username: testeoplay password: testtest
to check it in-game, this will make it easier for you to see what's up

I tried using al_convert_memory_bitmaps(); in the loaded function, to convert them all to proper bitmaps, not working either.

SiegeLord
Member #7,827
October 2006
avatar

You gotta do the fonts too, the MOTD screen easily takes half the render time.

When I have a moment, I'll try to do it in my copy and send you the updated source code.

EDIT: Here's the fixed source: link. Here's some more things I did in addition to what was done in the previous post:

- I disabled the loading thread for fonts, the fonts are now loaded directly in LoadFont, so that we bypass the memory bitmap issue.
- Switching from Debug to Release made my FPS increase 10x, so don't neglect this aspect.

There is still a lot to optimize, but like I said, by far the most impactful thing you can do is fix your loading thread. I recommend just not using it, your game doesn't need it.

"For in much wisdom is much grief: and he that increases knowledge increases sorrow."-Ecclesiastes 1:18
[SiegeLord's Abode][Codes]:[DAllegro5]:[RustAllegro]

Go to: