Jump to content

[EXPERIMENTAL] Game window freeze when dragging the client


Amun

Recommended Posts

  • Contributor

The game loop freezes when dragging/resizing the window. This is an attempt at fixing that.

 

We'll open a thread and call "Process()" from there when we receive WM_ENTERSIZEMOVE and then shut it down when receiving WM_EXITSIZEMOVE, continuing our main game loop.

 

There's also the option of creating a timer when entering WM_ENTERSIZEMOVE, calling "Process()" when receiving WM_TIMER and killing it when receiving WM_EXITSIZEMOVE, but there's quite a big delay till the timer starts and it's also not very reliable, so..

Note: This is HIGHLY experimental, and it might result in data races and crash the client. Even though I tested it as good as I could and tried to make sure the main thread's loop doesn't resume before ending the future, it's still a possibility for that to happen when you least expect it.

 

Video:

Code:

This is the hidden content, please
 or 
This is the hidden content, please

Many thanks to @limefor taking the time to test it.

Good luck!

  • Metin2 Dev 71
  • Think 1
  • Good 11
  • Love 1
  • Love 21
Link to comment
Share on other sites

  • 1 month later...
  • Premium
On 1/25/2023 at 2:56 AM, dumita123 said:

Great release, but I also want to point out that the freezing will also happen when holding right click on the bar or opening the context menu.

Adding 

		case WM_CONTEXTMENU:
			return 0;
		break;

into the CPythonApplication::WindowProcedure message switch will stop the context menu from opening.

This still won't fix the problem when left clicking on the bar (and keeping the left click down, same with the right click). When moving, the player will keep moving in background and the window will also unfreeze, but not when auto attacking and pressing the spacebar, or moving pressing W (basically pressing any button while keeping the menubar clicked fucks it up. I still haven't found a solution for that but I also don't know if it causes to fly bug an enemy character).

  • Metin2 Dev 1
Link to comment
Share on other sites

  • Contributor
15 hours ago, xXIntelXx said:

This still won't fix the problem when left clicking on the bar (and keeping the left click down, same with the right click). When moving, the player will keep moving in background and the window will also unfreeze, but not when auto attacking and pressing the spacebar, or moving pressing W (basically pressing any button while keeping the menubar clicked fucks it up. I still haven't found a solution for that but I also don't know if it causes to fly bug an enemy character).

Actually, it does. I can use the keyboard normally(move, attack, write) while dragging/keeping the window(left click). I've not thought about fixing the right click as well(for some reason). Also, I was extremely busy, so I've not checked to see if Dumita's change will help in that regard.

 

These being said, however, you can trigger/close the thread when entering and exiting the context menu. I don't see why you wouldn't be able to use the same solution for the right click as well.

 

Edit: Just noticed(forgot about it) I also have a video of me moving when dragging the client:

 

Regards,

Amun

Edited by Amun
+ video
Link to comment
Share on other sites

14 minutes ago, Amun said:

Actually, it does. I can use the keyboard normally(move, attack, write) while dragging/keeping the window(left click). I've not thought about fixing the right click as well(for some reason). Also, I was extremely busy, so I've not checked to see if Dumita's change will help in that regard.

 

These being said, however, you can trigger/close the thread when entering and exiting the context menu. I don't see why you wouldn't be able to use the same solution for the right click as well.

 

Edit: Just noticed(forgot about it) I also have a video of me moving when dragging the client:

 

Regards,

Amun

What Intel was saying is that if you're holding the left/right click on the bar without moving the mouse at all, the game will still freeze for around 300-500ms.
My post was only related to the context menu (because it was freezing the client while it was opened) so it just removes that option since no one was using it anyway.

Link to comment
Share on other sites

  • Contributor
4 minutes ago, dumita123 said:

What Intel was saying is that if you're holding the left/right click on the bar without moving the mouse at all, the game will still freeze for around 300-500ms.
My post was only related to the context menu (because it was freezing the client while it was opened) so it just removes that option since no one was using it anyway.

Ah, yes, I just noticed now. If you want the transition to be done instantly, keep the thread opened at all times and just let it know when it can and can't call Process, instead of triggering a new future whenever you click the bar. ez

Link to comment
Share on other sites

  • Premium
48 minutes ago, dumita123 said:

What Intel was saying is that if you're holding the left/right click on the bar without moving the mouse at all, the game will still freeze for around 300-500ms.
My post was only related to the context menu (because it was freezing the client while it was opened) so it just removes that option since no one was using it anyway.

 

34 minutes ago, Amun said:

Ah, yes, I just noticed now. If you want the transition to be done instantly, keep the thread opened at all times and just let it know when it can and can't call Process, instead of triggering a new future whenever you click the bar. ez

The problem is not the transition to be done instantly (it's irrelevant as long as the client is still processing in the background)

This is what happens when moving with W (so W pressed and left click on the bar at the same time without releasing it):

https://metin2.download/picture/577iCuT4g8a26z941R9dHO817H5tNf35/.gif

This is what happens when moving just clicking left click once:

https://metin2.download/picture/N4ZAQcgKtYRoABf9YdU43WgjBRK24RpY/.gif

 

Side note when I was banging my head to the wall, I stumbled upon a post saying:"Your application is most likely "freezing" because it has a WinMain loop similar to this:

while (true) 
{
    if(PeekMessage(&msg,NULL,0,0,PM_REMOVE))
    {
        TranslateMessage(&msg);
        DispatchMessage(&msg);
    }
    else
    {
       TickGame();
    }
}

Guess what do we have here..

void CPythonApplication::Loop()
{    
    while (1)
    {    
        if (IsMessage())
        {
            if (!MessageProcess())
                break;
        }
        else
        {
            if (!Process())
                break;

            m_dwLastIdleTime=ELTimer_GetMSec();
        }
    }
}

 

bool CMSApplication::IsMessage()
{
	MSG msg;

	if (!PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE))
		return false;

	return true;
}

 

bool CMSApplication::MessageProcess()
{
	MSG msg;

	if (!GetMessage(&msg, NULL, 0, 0))
		return false;

	TranslateMessage(&msg);
	DispatchMessage(&msg);
	return true;
}

 

Edited by Metin2 Dev
Core X - External 2 Internal
Link to comment
Share on other sites

  • Contributor
Spoiler

  

16 minutes ago, xXIntelXx said:

 

The problem is not the transition to be done instantly (it's irrelevant as long as the client is still processing in the background)

This is what happens when moving with W (so W pressed and left click on the bar at the same time without releasing it):

https://metin2.download/picture/577iCuT4g8a26z941R9dHO817H5tNf35/.gif

This is what happens when moving just clicking left click once:

https://metin2.download/picture/N4ZAQcgKtYRoABf9YdU43WgjBRK24RpY/.gif

 

Side note when I was banging my head to the wall, I stumbled upon a post saying:"Your application is most likely "freezing" because it has a WinMain loop similar to this:

while (true) 
{
    if(PeekMessage(&msg,NULL,0,0,PM_REMOVE))
    {
        TranslateMessage(&msg);
        DispatchMessage(&msg);
    }
    else
    {
       TickGame();
    }
}

Guess what do we have here..

void CPythonApplication::Loop()
{    
    while (1)
    {    
        if (IsMessage())
        {
            if (!MessageProcess())
                break;
        }
        else
        {
            if (!Process())
                break;

            m_dwLastIdleTime=ELTimer_GetMSec();
        }
    }
}

 

bool CMSApplication::IsMessage()
{
	MSG msg;

	if (!PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE))
		return false;

	return true;
}

 

bool CMSApplication::MessageProcess()
{
	MSG msg;

	if (!GetMessage(&msg, NULL, 0, 0))
		return false;

	TranslateMessage(&msg);
	DispatchMessage(&msg);
	return true;
}

 

 

Ah, yes, I see what you mean. It does, indeed, freeze when keeping the button pressed and then clicking the window.

 

Also, yeah, I went through all of those forum topics/stackoverflow questions/docs.. It's been a while, but I remember there were many things to take into consideration when making the game loop.


I will fix this(button thingy) as well at some point, but I can't promise anything because I won't have a lot of free time for the next month or so.

 

Edited by Metin2 Dev
Core X - External 2 Internal
  • kekw 1
Link to comment
Share on other sites



×
×
  • Create New...

Important Information

Terms of Use / Privacy Policy / Guidelines / We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.