Jump to content
  • Advertisement
Sign in to follow this  
  • entries
  • comments
  • views

I just made a breakthrough!

Sign in to follow this  


I finally found a use for pointers-to-pointers! See, right now I'm working on my tile engine, and one of the classes is cTileMap, which holds an array of the number of cTiles specified in the constructor. Now, each tile has an SDL_Surface* in them (obviously I'm using SDL), and I have a pointer to an area in memory (the tile array is being allocated on the heap). Anyway, the way I HAD been doing it was specifying each tile in the tile file, and loading them into each its own variable (which is now being turned into a much faster binary file), but now I just grab a pointer to each used tile and populate the array with pointers instead of actual tiles. So in essence I'm using a **SDL_Surface. I also use ** for traversal of a 2D array, since there would be no way to specify the Y value otherwise.

I never thought I could find a use for normal pointers, let alone pointers-to-pointers. I really feel like working on these projects alone is helping me learn C++ better. I also have to thank all the GDNers who helped my on my last tile-based endeavor, for showing me how I could just use the SDL_Surface* for the tiles instead of the bitmaps themselves (which wastes lots of memory).
Sign in to follow this  


Recommended Comments

You don't really need to use a **. You could just use a regular *. I do the same thing for my game resources. I load an object (say an image object) and store the image on an SDL surface. If I want to duplicate that object, I create the new object but instead of loading the image again, I just point the second object's surface to the first object's surface. I don't use ** though. It's not any faster and it's just more confusing.

Share this comment

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Advertisement

Important Information

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

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!