Saving Map Array To Disk

This is a discussion on Saving Map Array To Disk within the Game Programming forums, part of the General Programming Boards category; I was wondering if anyone could give me a little help on a simple question. I have been making an ...

  1. #1
    Registered User
    Join Date
    Oct 2002
    Posts
    118

    Saving Map Array To Disk

    I was wondering if anyone could give me a little help on a simple question. I have been making an RPG with DirectX 7, and have the tile engine working perfectly. Now I have made a tile editor to create the land the easy way. All is good, with the exception that I am having trouble saving my array to disk. I used a 2D map array, and was wondering if I should use the C++ stream functions, or stick with C. Someone told me to stick with C, but that doesn't seem to sound right. Anyways, I was just wondering how it would be possible to save the full map array to disk, and have it read back in the same order? Thanks in advance.

  2. #2
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    You can use write() to output an array to a file in one go if you want. There are other ways, it's going to depend on your current code. Post a sample and someone will help you.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  3. #3
    Registered User
    Join Date
    Oct 2002
    Posts
    118
    Sorry for the extra post, I pressed tab to set my code up and I some how exited my entry. I couldn't delete it, so I just edited it so that I didn't look quite as dumb. Sorry.
    Last edited by Tommaso; 07-18-2003 at 12:03 AM.
    "The distinction between past, present and future is only an illussion, even if a stunning one."
    -Albert Einstein

  4. #4
    Registered User
    Join Date
    Oct 2002
    Posts
    118
    I know how to save a map array to disk, and then re-load it for use, but the problem I have is this: It is a 2D array that I have my tile map set up in. Here is what I have so far:

    Code:
     /*
    
    int main()
    {
    ofstream out("test1", ios::out|ios::binary);
    if(!out){
        cout << "Cannot open file.\n";
        return 1;
               }
    
    out.write((char *)&map,sizeof map);
    
    out.close();
    }
    
    */
    How can I use something similar to save an array but in 2D array style, like map[100][100]?
    Last edited by Tommaso; 07-18-2003 at 12:11 AM.
    "The distinction between past, present and future is only an illussion, even if a stunning one."
    -Albert Einstein

  5. #5
    Cat
    Cat is offline
    Registered User
    Join Date
    May 2003
    Posts
    1,571
    Your best bet is to do the following:

    1) Create a map class
    2) Make the actual map data private, and a 1D array.
    3) Overload operator() to allow things like myMap(0,100)
    4) Overload operators >> and << to allow easy string activities (the operators themselves should use read() and write()

    It really makes a ton of sense to encapsulate a map in a class, and 2D arrays are bad to work with; there aren't a whole lot of guarantees about how your compiler handles them.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Polynomials and ADT's
    By Emeighty in forum C++ Programming
    Replies: 20
    Last Post: 08-19-2008, 09:32 AM
  2. Modify an single passed array element
    By swgh in forum C Programming
    Replies: 3
    Last Post: 08-04-2007, 09:58 AM
  3. [question]Analyzing data in a two-dimensional array
    By burbose in forum C Programming
    Replies: 2
    Last Post: 06-13-2005, 08:31 AM
  4. Class Template Trouble
    By pliang in forum C++ Programming
    Replies: 4
    Last Post: 04-21-2005, 05:15 AM
  5. Type and nontype parameters w/overloading
    By Mr_LJ in forum C++ Programming
    Replies: 3
    Last Post: 01-02-2004, 01:01 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21