Text Box Speed Issue

Started by MoLAoS, 07 July 2015, 05:58:09

MoLAoS

Quote from: texus on 07 July 2015, 20:30:21
Quotemy tabs seem to have the wrong text size
The tab class has gone through several internal changes in the last year. If you can't figure out the problem yourself then you should try to provide some minimal code that has this problem.

Not important. The real issue I have is the signals thing. I wrote:
countryPicture->connect("pressed", mapManager->setPlayerNation());

However the function wants either an int or a Nation*. I tried:
countryPicture->connect("pressed", mapManager->setPlayerNation(), mapManager->getNation(i)));

But the function always says it needs an argument. I also tried a few things google popped up but didn't help much. If you put the argument in the braces it says invalid use of void function.

texus

What you are doing is call setPlayerNation and pass the return value of the function (void in this case) as parameter to the connect function.

It should be like this (assuming mapManager is an object of type MapManager)
Code (cpp) Select
countryPicture->connect("pressed", &MapManager::setPlayerNation, mapManager);

Since the function takes an int you actually have to do this:
Code (cpp) Select
countryPicture->connect("pressed", &MapManager::setPlayerNation, mapManager, mapManager->getNation(i));

But this will call getNation immediately and call setPlayerNation with a copy of that int. So if the nation changes after calling the connect function then the value passed as parameter isn't changed. So instead you could bind that function call so that getNation gets called when the setPlayerNation is being called.
Code (cpp) Select
countryPicture->connect("pressed", &MapManager::setPlayerNation, mapManager, std::bind(&MapManager::getNation, mapManager, i));

You should read the "Connecting member functions" section on this page for a good explanation on how to bind member functions.

You might also want to look up how std::bind works. If you hesitate how the parameters of the connect function are supposed to be, all the parameters after the first string are just directly passed to std::bind so if you know how it works then you also know what to pass to the connect function. With the exception that you can pass less parameters to the connect function which leads to trying to bind them internally.

MoLAoS

#17
Okay, its working now.

MoLAoS

Quote from: texus on 07 July 2015, 11:45:29
The TextBox is indeed way too slow in tgui 0.6.
Rewriting the class was one of the first things I did in tgui 0.7-dev, the performance problems should be solved there.

I once wrote this on my blog, to give you an idea how much better it is now:
QuoteI am almost done with rewriting TextBox, so it is time to do some performance tests. The new code is 1000 lines shorter (1600 instead of 2600), supports word wrap and fixes all performance problems.

With 100.000 characters, there was still no visible delay when inserting text (but the fps dropped to 30 while typing). Going over 250.000 characters started showing visible performance issues.

So in normal situations (a few hundreds or even thousands of characters) you should have absolutely no performance problems.

Just as a comparison: the old TextBox didn't handle more than 500 characters very well.

I just want to say that the new textbox is working like magic. Thank you so much. I hate having to spend my day off redoing callback stuff but in the end the superior textbox performance is worth it. The v0.6 textbox performance was a showstopper.