Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add simple tile visibility checking in the ViewModule #5

Merged
merged 2 commits into from
Sep 15, 2014

Conversation

matteblair
Copy link
Member

No description provided.

@@ -49,6 +52,6 @@ class ViewModule {
float m_height;
float m_aspect;

void init(float width, float height);
void init(float _width, float _height);

};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

newline!!! :)

@matteblair matteblair merged commit 113e4ec into master Sep 15, 2014

m_visibleTiles.clear();

float tileSize = 2 * PI * EARTH_RADIUS_M / pow(2, m_zoom);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A small thing.
Its always recommended to do multiplication over division. Sometime the performance gains are huge..
Some Floating point processing multiplication can be 5 to 8 times faster than floating point division.

float inversePowZoon = 1/pow(2, m_zoom);
float tileSize = 2_PI_EARTH_RADIUS_M*inversePowZoon;

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tallytalwar really?? Do you have some docs to point to on that - curious to read more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yup... hence use of bitwise operators is also recommended. (multiplication by 2 should be replaced with one right shift, and division by 2 should be replaced by one left shift)..

there are many more such optimizations ...
http://books.google.com/books?id=IRN0IEXJzKEC&pg=PA92&lpg=PA92&dq=floating+point+division+multiplication+optimization+c%2B%2B&source=bl&ots=P1mjHg8EAs&sig=sZD71hukKFcJ6RaBJz4Q5awC9gs&hl=en&sa=X&ei=hZUXVNvRENSn8QGvq4HoBw&ved=0CFEQ6AEwBw#v=onepage&q=floating%20point%20division%20multiplication%20optimization%20c%2B%2B&f=false

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep but those references are over a decade old, so I wonder if they still
apply. Bit-shifting is an old x86 technique, I use it out of habit. I
wonder though if the compiler won't apply these optimizations automatically
anyway... worth reading up on just to know.

On Mon, Sep 15, 2014 at 9:45 PM, Varun notifications@github.com wrote:

In core/viewModule/viewModule.cpp:

@@ -60,3 +62,47 @@ glm::mat2 ViewModule::getBoundsRect() {
return glm::mat2(m_pos.x - hw, m_pos.y - hh, m_pos.x + hw, m_pos.y + hh);

}
+
+const std::vectorglm::ivec3& ViewModule::getVisibleTiles() {
+

  • if (!m_dirty) {
  •   return m_visibleTiles;
    
  • }
  • m_visibleTiles.clear();
  • float tileSize = 2 * PI * EARTH_RADIUS_M / pow(2, m_zoom);

yup... hence use of bitwise operators is also recommended. (multiplication
by 2 should be replaced with one right shift, and division by 2 should be
replaced by one left shift)..

there are many more such optimizations ...

http://books.google.com/books?id=IRN0IEXJzKEC&pg=PA92&lpg=PA92&dq=floating+point+division+multiplication+optimization+c%2B%2B&source=bl&ots=P1mjHg8EAs&sig=sZD71hukKFcJ6RaBJz4Q5awC9gs&hl=en&sa=X&ei=hZUXVNvRENSn8QGvq4HoBw&ved=0CFEQ6AEwBw#v=onepage&q=floating%20point%20division%20multiplication%20optimization%20c%2B%2B&f=false


Reply to this email directly or view it on GitHub
https://github.com/tangram-map/tangram-es/pull/5/files#r17579753.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure will do..

What I have been told by developers I have interacted with at DWA and other gaming studios that these still apply. But I will still confirm. If compiler optimization are there then it will save us a lot of pain. :D

@tallytalwar
Copy link
Member

Just to clarify the logic, m_dirty should be set to true, every time any of the set functions are called on the viewModule and not just on init?

These set functions will be called by user triggered events (gestures, mouse move, etc).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants