Thread: File I/O with arrays

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Sep 2006
    Posts
    27
    Hm, dwks told me about vectors in another thread, but I haven't seriously looked into them yet. Perhaps that would be a good idea.... My code is going to get very gluggy for multiple checks. I've just implemented a system that scrolls the map when the character gets within a certain distance of the edge of the screen (or not, if the map is too small or if it's already *at* the edge of the map), but since at the moment it reruns the mapprint() function every single time it scrolls up or down, it's S-L-O-W. Ideally, it'd be best to do something similar to what you say about printing in blocks - make the move without changing the display, then check each tile inside the screen block against its new value after the move to see if it's changed. If it has, *then* reprint that location, if not, don't.

    Currently, though, I'm working on implementing an 'examine' command... maybe once that's done I'll look into vectors.

    It is kind of addictive.... At the moment I have a larger map with a house-type thing with two doors that the character can (slowly, if any scrolling is required) wander about. Not exactly the next installment of Half-Life, and yet strangely addicting all the same. Maybe because it's different when you have an idea of just how difficult it is to make these things

    EDIT: Hitting some severe difficulties with my map refreshing function....

    Code:
    void location::refresh_temp()
    {
         for (int y = ydisp; y<31; y++) {
               for (int x = xdisp; x<101; x++){
                     for (int z = 0; z < TYPE ; z++){
                           mapt[x][y][z]=map[x][y][z];
                           }
                           }
                           }
    }
    
    void location::refresh_print()
    {
         int x1;
         int y1;
         x1 = 0;
         y1 = 0;
         for (int y = ydisp; y < (ydisp+10); y++){
               for (int x = xdisp; x < (xdisp+50); x++){
                     for (int z = 0; z<TYPE; z++){
                           if (mapt[x][y][z] != map[x][y][z]){
                                             locate.printloc(x,y,x1,y1);
                                             }
                                             }
                           x1++;
                                             }
               y1++;
                                             }
    }
    At the moment, it calls refresh_temp() before moving or changing anything, and refresh_print() after the move/change has been made. ydisp and xdisp are the top left corner actual x and y coordinates, and the printloc function variables are, in order, actual x, actual y, display x, display y.

    At the moment, the display doesn't change at all. I'm not sure if this is due to problems in the comparison or in the values passed to printloc or what, but it's really bugging me. If anyone can spot what I'm doing wrong here, I'd really appreciate it.
    Last edited by 20,000leeks; 09-18-2006 at 06:29 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Subtle(?) File I/O Problem
    By cecomp64 in forum C Programming
    Replies: 9
    Last Post: 07-16-2008, 11:39 AM
  2. Formatting the contents of a text file
    By dagorsul in forum C++ Programming
    Replies: 2
    Last Post: 04-29-2008, 12:36 PM
  3. Can we have vector of vector?
    By ketu1 in forum C++ Programming
    Replies: 24
    Last Post: 01-03-2008, 05:02 AM
  4. File I/O Question
    By Achy in forum C Programming
    Replies: 2
    Last Post: 11-18-2005, 12:09 AM
  5. simulate Grep command in Unix using C
    By laxmi in forum C Programming
    Replies: 6
    Last Post: 05-10-2002, 04:10 PM