|
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. 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. |
Edgar Reynaldo
Major Reynaldo
May 2007
|
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 My Website! | EAGLE GUI Library Demos | My Deviant Art Gallery | Spiraloid Preview | A4 FontMaker | Skyline! (Missile Defense) Eagle and Allegro 5 binaries | Older Allegro 4 and 5 binaries | Allegro 5 compile guide |
Chris Katko
Member #1,881
January 2002
|
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? And you're not saying the NETWORKING bandwidth is causing it to run slow, right? -----sig: |
Matias Persson
Member #15,093
May 2013
|
Edgar Reynaldo here is a CMakeLists attached. 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. 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? |
Edgar Reynaldo
Major Reynaldo
May 2007
|
Do you have the Allegro5 module you made handy? CMake won't run without it. My Website! | EAGLE GUI Library Demos | My Deviant Art Gallery | Spiraloid Preview | A4 FontMaker | Skyline! (Missile Defense) Eagle and Allegro 5 binaries | Older Allegro 4 and 5 binaries | Allegro 5 compile guide |
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
|
Matias Persson said:
1) what is "lag" in this scenario? Actual delay between control input and output? Or reduced frame rate? 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: |
SiegeLord
Member #7,827
October 2006
|
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 |
Edgar Reynaldo
Major Reynaldo
May 2007
|
Just do this once and be done with it when everything is loaded. http://docs.liballeg.org/graphics.html#al_convert_memory_bitmaps My Website! | EAGLE GUI Library Demos | My Deviant Art Gallery | Spiraloid Preview | A4 FontMaker | Skyline! (Missile Defense) Eagle and Allegro 5 binaries | Older Allegro 4 and 5 binaries | Allegro 5 compile guide |
Matias Persson
Member #15,093
May 2013
|
I added al_convert_bitmap(bitmap.get()); 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
|
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. 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 |
|