Thread: A Little Performance Related SDL Question...

  1. #1
    Marxist-Trotskyist
    Join Date
    May 2005
    Location
    Many, many miles from the center of the Earth.
    Posts
    31

    A Little Performance Related SDL Question...

    If one were to make a grid on the screen by using the SGE LineAlpha function, and redraw it every frame, that would be really slow wouldn't it?
    If a=b, and b=c, then a=c, except where void and prohibited by law...

  2. #2
    Absent Minded Programmer
    Join Date
    May 2005
    Posts
    968
    Well, it would be the way you would have to do it - unless - the grid is ALWAYS on the screen, no matter what..

    and no, it wouldnt be that inefficient, i don't think*

    I've done it in opengl with GL_LINES and made a 392 cell grid, runs lightning fast on like anything
    Sometimes I forget what I am doing when I enter a room, actually, quite often.

  3. #3
    Marxist-Trotskyist
    Join Date
    May 2005
    Location
    Many, many miles from the center of the Earth.
    Posts
    31
    Well... I was using a For loop to redraw it every frame, because it's suppose to move when the mouse get's near the edge of the screen (like scrolling). But it froze when I tried it my way, so I don't think I did it right...
    If a=b, and b=c, then a=c, except where void and prohibited by law...

  4. #4
    Absent Minded Programmer
    Join Date
    May 2005
    Posts
    968
    Doesn't SDL have a main loop like openGL already implemented?
    Sometimes I forget what I am doing when I enter a room, actually, quite often.

  5. #5
    ---
    Join Date
    May 2004
    Posts
    1,379
    Quote Originally Posted by Shamino
    Doesn't SDL have a main loop like openGL already implemented?
    Do you realise that made perfectly no sense?

  6. #6
    Absent Minded Programmer
    Join Date
    May 2005
    Posts
    968
    whoa...

    He didn't mention SDL at all? Oh wait, he did in the Title of the post...

    Hmmm - this is what I get for trying to answer questions i don't know much about
    Last edited by Shamino; 12-07-2005 at 01:22 AM.
    Sometimes I forget what I am doing when I enter a room, actually, quite often.

  7. #7
    ---
    Join Date
    May 2004
    Posts
    1,379
    What I meant was that OpenGL doesn't have a "main loop" as you said and neither does SDL. I think you meant GLUT.

  8. #8
    Absent Minded Programmer
    Join Date
    May 2005
    Posts
    968
    yeah... that thing... lol
    Sometimes I forget what I am doing when I enter a room, actually, quite often.

  9. #9
    Marxist-Trotskyist
    Join Date
    May 2005
    Location
    Many, many miles from the center of the Earth.
    Posts
    31
    Ok... I applied the same method noted above (the for loops), modified slightly, to an SDL blitting operation. When I ran it, it displayed nothing, and stopped responding. So I added a little printf statement in the loop to see if it was actually running the loop, and was just taking entirely too long... All the text was, "Tile Printed"... When I ran it, the stdout.txt file was a whopping 197 mbs. I'm not sure what made this result, but I'm fairly sure I didn't use typecasting properly...

    Code:
    // Display Tiles
         for(int x = floor(static_cast<float>(Offset_X)/Tile_W);
             x = ceil(static_cast<float>(Offset_X) + 800/Tile_W);
             x = x + 1)
         {
              for(int y = floor(static_cast<float>(Offset_Y)/Tile_W);
                  y = ceil(static_cast<float>(Offset_Y) + 600/Tile_W);
                  y = y + 1)
              {
                   // Define Terrain Position and Blit
                   terrain1Pos.x = x * Tile_W;
                   terrain1Pos.y = y * Tile_W;
                   SDL_BlitSurface(TerrainSurface1, &terrain1Size,                           ScreenSurface, &terrain1Pos);
                   printf("Tile Printed %s\n");
              }
         }
    If a=b, and b=c, then a=c, except where void and prohibited by law...

  10. #10
    Marxist-Trotskyist
    Join Date
    May 2005
    Location
    Many, many miles from the center of the Earth.
    Posts
    31
    I'm not sure what that gap is from... ?
    If a=b, and b=c, then a=c, except where void and prohibited by law...

  11. #11
    carry on JaWiB's Avatar
    Join Date
    Feb 2003
    Location
    Seattle, WA
    Posts
    1,972
    Code:
    x = ceil(static_cast<float>(Offset_X) + 800/Tile_W); //loop condition
    You realize that your loop will run until x is assigned to 0 there (and same for y)? Besides the fact that this wont work, it looks overly complex. Maybe you want something like:
    Code:
    for (int x=Offset_X;x<ScreenWidth;x+=TileWidth)
    "Think not but that I know these things; or think
    I know them not: not therefore am I short
    Of knowing what I ought."
    -John Milton, Paradise Regained (1671)

    "Work hard and it might happen."
    -XSquared

  12. #12
    Marxist-Trotskyist
    Join Date
    May 2005
    Location
    Many, many miles from the center of the Earth.
    Posts
    31
    I don't understand your first statement at all... I thought it would run until x was equal to Offset_X plus the screen dimension at hand, divided by the width of the boards tiles.

    As for the second, I need to take the offset of the viewer/camera, divide it by 20 (the tile width), and round the answer down so it doesn't trunicate it, and only print the tiles not divided by the edge of the screen. I suppose I could do it that way, but I'd have to typecast and/or assigned x the type float or double, then divide it by the tile width to get the position on the board (since the screen is 200x200, in tiles), then take that position and mulitply it by the tile width to get the actual position of the graphic (the tile graphic) on the screen...

    This does seem like I'm going about it the long way... How do most tile-based games display only the tiles on the screen? That is to say, how do they turn the offset of the camera, in pixels, and determine what tiles lie within the camera/screens range? Thanks for the reply too...
    If a=b, and b=c, then a=c, except where void and prohibited by law...

  13. #13
    Marxist-Trotskyist
    Join Date
    May 2005
    Location
    Many, many miles from the center of the Earth.
    Posts
    31
    I meant, "turn the offset of the camera, in pixels, into tile units (i.e. 20x20 squares, in my case)..."
    If a=b, and b=c, then a=c, except where void and prohibited by law...

  14. #14
    carry on JaWiB's Avatar
    Join Date
    Feb 2003
    Location
    Seattle, WA
    Posts
    1,972
    I don't understand your first statement at all... I thought it would run until x was equal to Offset_X plus the screen dimension at hand, divided by the width of the boards tiles.
    Then it sounds like you don't want to assign a value to x, you want to compare it (there's a difference between = and ==). And actually you to want to loop while the condition is true, thus:
    Code:
    x != ceil(static_cast<float>(Offset_X) + 800/Tile_W);
    And I guess I don't really understand what you're trying to do, so I can't guarantee that's correct. Plus, I'm not really experienced with writing tile engines. If you haven't already, I'm sure a search for something like "tile engine c++" would turn up a lot of results, and IIRC gamedev.net has several tutorials on the subject that might give you some ideas.
    "Think not but that I know these things; or think
    I know them not: not therefore am I short
    Of knowing what I ought."
    -John Milton, Paradise Regained (1671)

    "Work hard and it might happen."
    -XSquared

  15. #15
    Marxist-Trotskyist
    Join Date
    May 2005
    Location
    Many, many miles from the center of the Earth.
    Posts
    31
    Ohhh, I totally overlooked that... :P. I see what you're saying. I'll try google or something. Thanks for the replies.
    If a=b, and b=c, then a=c, except where void and prohibited by law...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Memory related question in C
    By TheDeveloper in forum C Programming
    Replies: 15
    Last Post: 12-29-2008, 12:43 AM
  2. A graphics related question
    By GOBLIN-85 in forum C++ Programming
    Replies: 7
    Last Post: 12-20-2008, 01:37 PM
  3. A question related to dynamic memory allocation
    By spiit231 in forum C Programming
    Replies: 2
    Last Post: 03-11-2008, 12:25 AM
  4. Newbie Question - fflush(stdin) & fpurge(stdin) on Mac and PC
    By tvsinesperanto in forum C Programming
    Replies: 34
    Last Post: 03-11-2006, 12:13 PM
  5. question related to keypad
    By lovemagix in forum C++ Programming
    Replies: 22
    Last Post: 01-05-2006, 02:25 AM