Thread: constant refresh

  1. #1
    Registered User
    Join Date
    Apr 2007
    Posts
    45

    constant refresh

    right now I am working a space invaders type game. The initial screen is read from a text file that looks like

    1111111111111114
    1000000000000014
    1000000000000014
    1000000000000014
    1000000000000014
    1000000000000014
    1000000300000014
    1000000000000014
    1111111111111114

    then I load it into a two dimensional array called screen [ ] [ ]

    then I run a switch statement

    Code:
    switch ( screen [ ] [ ] )
    {
    case 1: 
    printf ("*");               // wall barrier
    break;
    
    case 0: 
    printf (" ");                // open space
    break;
    
    case 3:
    printf ("X");               // users ship
    break;
    
    case 4:
    printf ("\n");
    break;
    }
    Then I have some movment controls and colision detection controls. Mind you this entire program is under a while loop and is always in constant refresh. As my program is getting bigger I noticed my screen is starting to blink. I realized this is because my program is constantly checking values, and redrawing the screen.

    My theory is to only refresh the screen every one half second and force another screen refresh if an event happens (ie: my ship moves)

    would that be sufficent enough so that my screen wouldnt look so... choppy?

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    The other option is of course to only update sections of the screen that has changed - it requires that you use some function to do "gotoxy()" and probably some heuristics to figure out if "most things have changed, so redraw the whole thing".

    --
    Mats

  3. #3
    Registered User mmarab's Avatar
    Join Date
    Jul 2007
    Posts
    30
    Wouldnt page flipping or double buffering help solves this problem. Or am i going way off target. Anyway just trying to help.

  4. #4
    Registered User
    Join Date
    Apr 2007
    Posts
    45
    I like the update only part of the screen idea. But its all in text, so I would have to use \b and as far as i know that only works if your on the current line. And that could get very messy very fast. Maybe I will just live with the blinking screen. I just might have to add a seizure warning heh

  5. #5
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    You need double buffering or page flipping. And most likely you would want to move to a graphics API to do this.

  6. #6
    Registered User
    Join Date
    Nov 2006
    Posts
    519
    look at the ncurses library, the provide gotoxy for terminal. there is also a windows port out there

  7. #7
    Registered User IdioticCreation's Avatar
    Join Date
    Nov 2006
    Location
    Lurking about
    Posts
    229
    Well, I would also recommend a graphics API, but since all the stuff is stored into an array you don't need to worry about the text file once it loaded. Actually I don't even get the purpose of the text file. Say if the users ship moved to the left then you can change the ships current location in the array to a "0" and -1 of it's position to the "X" then +1 to go right. For movement up and down you could add or subtract the number in each row of your array.

    As far as refreshing, I don't have much help.

  8. #8
    int x = *((int *) NULL); Cactus_Hugger's Avatar
    Join Date
    Jul 2003
    Location
    Banks of the River Styx
    Posts
    902
    I second ncurses, not because it provides gotoxy() (it doesn't actually, the function is move() ), but because ncurses takes into account what's already there.
    From the ncurses man pages:
    The routine wrefresh copies the named window to the physical terminal screen, taking into account what is already there to do optimizations. The refresh routine is the same, using stdscr as the default window.
    ncurses is also available on several platforms (if you're using Windows, google for pdcurses), and so allows your program to be portable.
    long time; /* know C? */
    Unprecedented performance: Nothing ever ran this slow before.
    Any sufficiently advanced bug is indistinguishable from a feature.
    Real Programmers confuse Halloween and Christmas, because dec 25 == oct 31.
    The best way to accelerate an IBM is at 9.8 m/s/s.
    recursion (re - cur' - zhun) n. 1. (see recursion)

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  2. We Got _DEBUG Errors
    By Tonto in forum Windows Programming
    Replies: 5
    Last Post: 12-22-2006, 05:45 PM
  3. load gif into program
    By willc0de4food in forum Windows Programming
    Replies: 14
    Last Post: 01-11-2006, 10:43 AM
  4. curses problem
    By rajesh23 in forum Linux Programming
    Replies: 2
    Last Post: 10-07-2003, 07:27 AM
  5. Warnings, warnings, warnings?
    By spentdome in forum C Programming
    Replies: 25
    Last Post: 05-27-2002, 06:49 PM