3

I have a class that I use to render GUI elements on the screen, this class has a tree structure (with children, parent, and siblings). I created an additional class which allows me to interpolate some values of a GUI element (alpha, and rotation for now), each instance of the class is linked to one GUI element (which is updated by it) like this:

// Creating a simple empty cube
GUIElem img(0, 0, 40, 40);
// Creating an interpolation for img, to rotate it to 90°
RotationInterpolation inter(&img, 90);

// Inside the loop
// This calculates the interpolations from 0° to 90° and updates the image
inter.update(delta_time);
// This draw the image
img.draw();

This is how it looks now, but I want to implement interpolations inside GUIElem methods (setAngle(), setAlpha()), and I was wondering what is the best method to do it, I came up with two solutions:

  • Create a list of interpolations for each GUIElem and manage them (update, delete) inside GUIElem's update()
  • Create a global list of interpolations and manage it in my loop before rendering

Since pretty much all of my interpolations would be added and deleted continuosly, I'm not sure about which of those methods is more efficient in terms of memory and performance (I could have a lot of GUIElem with no interpolations running but still in need to be checked).

  • Interesting question. GUI is not my main thing, but a couple of things come to mind. (1) if you're going to support double-buffering you probably don't want a single global list of interpolations, since you might well want to be rendering one frame while computing the next in parallel. (2) if your GUI system gives you a clipping area (e.g. bounding rectangle) which needs to be redrawn then arranging the interpolations in a data structure allowing you to figure out which can be skipped might be a performance win (but on modern systems the performance advantage gained may be uninteresting). – James Youngman Feb 8 '16 at 21:14
  • @JamesYoungman Since I just started learning graphics, I'm not planning to use double buffering for now. Do you think that having this one data structure (list, vector, ...) for each element could be a waste of Space? Since most elements could have no interpolations for their entire life... – Xriuk Feb 9 '16 at 6:33
  • 1
    As I said, GUI is not my main thing. But, suppose each instance of this object costs 128 bytes. 8 of those is 1KiB. So it would take 8000 GUI elements to use up 1MiB, plus memory allocation system overhead. Hence I'f guess the cost is likely not prohibitive. Though of course that depends on the platform - but 1MB of memory allocation on a desktop system is almost negligible. By the time you have 8000 items, it's more important to think about using them efficiently in algorithms (e.g. avoiding quadratic or perhaps even linear behaviour) than to worry much about the memory cost. – James Youngman Feb 20 '16 at 17:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.