Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: What is the sense of setView(getView())?  (Read 2685 times)

0 Members and 1 Guest are viewing this topic.

sharethis

  • Jr. Member
  • **
  • Posts: 65
    • View Profile
What is the sense of setView(getView())?
« on: January 21, 2013, 12:26:21 pm »
Debugging my application which uses the last SFML 2.0 snapshot, I stumbled upon a line in RenderTarget.cpp. It reads:

// Set the default view
setView(getView());

Since "getView()" returns "m_view" and "setView()" simply sets "m_view", it the line above make any sense to me.

////////////////////////////////////////////////////////////
void RenderTarget::setView(const View& view)
{
    m_view = view;
    m_cache.viewChanged = true;
}


////////////////////////////////////////////////////////////
const View& RenderTarget::getView() const
{
    return m_view;
}

Could you please explain what this is supposed to do? I am just curious and want to find the bug in my own application.

sharethis

  • Jr. Member
  • **
  • Posts: 65
    • View Profile
Re: What is the sense of setView(getView())?
« Reply #1 on: January 21, 2013, 12:43:02 pm »
I figured it out. "setView()" also set "m_cache.viewChanged" true which internally results in a call to "applyCurrentView()". It sets the viewport and the projection matrix to the default.

Weeve

  • Jr. Member
  • **
  • Posts: 87
  • C++ Programmer (Intermediate), 3D Artist (Skilled)
    • View Profile
    • Email
Re: What is the sense of setView(getView())?
« Reply #2 on: February 01, 2013, 06:17:40 pm »
couldn't this be made more efficient by just changing m_cache.viewChanged to true? to avoid pulling the data from the view, and changing it again, when only one bool change is needed? (20 cycles on the CPU versus 1?) but since the rune only once, it may not be worth the trouble
Long live rapid project development! -- Kestrel3D Game-Engine nearing completion

cire

  • Full Member
  • ***
  • Posts: 138
    • View Profile
Re: What is the sense of setView(getView())?
« Reply #3 on: February 01, 2013, 08:05:24 pm »
couldn't this be made more efficient by just changing m_cache.viewChanged to true?

Unlikely.  Trust your optimizer.  Since setView and getView are likely to be inlined, there should be no difference in the code.

Actual generated code:
; 305  :         // Set the default view
; 306  :         setView(getView());

        mov     BYTE PTR [edi+345], 1

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: What is the sense of setView(getView())?
« Reply #4 on: February 01, 2013, 10:37:16 pm »
Honestly, I never waste my time with such questions that will obviously not make any difference at all. I prefer to write clean and maintainable code. For example, if one day I add another line to the setView function, I'll be happy because the current code will still work. Whereas your "optimized" code won't.
Laurent Gomila - SFML developer