Re: [AD] new GUI focus selection algorithm

[ Thread Index | Date Index | More lists.liballeg.org/allegro-developers Archives ]


Eric Botcazou wrote:
But this computation is not going to be done more often than the user
presses a key!

Sure, but times the number of objects on the screen.

That said, we can avoid square roots by comparing the _squares_ of the
(Euclidean) distances. It will be faster and not change the behavior.

I'm a big fan of the man who said: "If you can avoid a multiplication, then... avoid it." :-)

Well, I'm not. A more clever person once said "If you can avoid an optimization, then avoid it" :-)

Seriously, one multiplication per object and keypress is absolutely no problem, under no realistic circumstances. Especially not in code that unnecessarily calls qsort() when all it wants is to find the minimum distance (a simple linear search avoids function pointer calls and quadratic worst-time complexity). And especially not when the alternative is to call abs(), which is not necessarily faster. And especially not when, for each keypress, you additionally have to redraw the objects that lost and gained focus, a much more costly operation...

If you can motivate your alternative algorithm in another way, that's fine, but I think speed is really irrelevant here (and Euclidean distance seems more intuitive, intuitively :-).

/Sven





Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/