Jump to content
  • Advertisement
Sign in to follow this  
derek7

look!

This topic is 4892 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

std::vector<int> _heightmap;

bool Terrain::readRawFile(std::string fileName)
{
     // A height for each vertex
     std::vector<BYTE> in(  numVertices );

     std::ifstream inFile(fileName.c_str(), std::ios_base::binary);

     if( inFile == 0 )
          return false;

     inFile.read(
          (char*)&in[0], // buffer
          in.size());// number of bytes to read into buffer

     inFile.close();

     // copy BYTE vector to int vector
     _heightmap.resize( numVertices );
     for(int i = 0; i < in.size(); i++)
          _heightmap = in;

     return true;
}

 


I wonder why use in.size() instead of numVertices?

Share this post


Link to post
Share on other sites
Advertisement
Because what is done was:

// A height for each vertex
std::vector<BYTE> in( numVertices );


So in.size() == numVertices. They are the same thing [wink] As for why, I don't know, I'd just use numVertices rather than call the member function to get the size.

Share this post


Link to post
Share on other sites
Who knows! Either should be just fine. I'm assuming that you didn't write the code.
I'd have written the resize line differently (were I considering writing code in this manner):
     _heightmap.resize( in.size() );
That way they are then the same size regardless of whatever else changes within that function.
I'd possibly have used iterators for copying from one vector to another too. Everybody does things differently.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!