Author: Compynerd255
Posted: 19 Nov 2012 02:03:39 pm (GMT -5)
You will want to keep your basic ClrDraw / DispGraph pattern - when you draw a lot of objects in a game, it's better to clear them all at once than to try erasing them one by one.
The strategy that works best in the general case is to use the DispGraphClrDraw command (the DispGraph token immediately followed by ClrDraw). Basically, it's like doing a DispGraph, then a ClrDraw, but the procedure is almost as fast as DispGraph alone. So, to implement this strategy:
1. Stick a ClrDraw right before your main game loop.
2. Get rid of the ClrDraw inside your main game loop.
3. Change the DispGraph in your loop to a DispGraphClrDraw.
Since your game is a roguelike and won't be actively scrolling the map, you can also try caching your rendered map into some other buffer, then instead of doing a ClrDraw, copy this other buffer into the normal buffer, thus saving you the time of rendering the map every frame. Here's how you'd implement that strategy:
1. Decide where in memory you want to put your buffer. You have three choices: L3 (if you aren't using grayscale), L1 (if you #Realloc your variables to L4 and aren't archiving/unarchiving in your program), or an Appvar (create an appvar with some random name that's 768 bytes long, then keep that pointer for the rest of the program). Before your game loop begins, clear this buffer.
2. Keep another variable, such as θ, as an "update sentry variable". Set this to 1 before the loop begins. As you go through your loop, if you do something that causes the map to change (such as going to another screen), set the update sentry variable to 1.
3. Once you've done all your update actions (anything that could possibly change the sentry variable), check the sentry variable:
- If the variable is not zero, clear both the graph buffer and the other buffer. Draw your map on the graph buffer, then copy the graph buffer to the other buffer.
- Otherwise, simply copy the other buffer to the graph buffer. The other buffer contains your map, which is 100% accurate since your map has not changed (indicated by your sentry variable being 1). In addition, anything that was on your graph buffer is cleared by this operation.
4. In either case, set your sentry variable to zero, draw all your volatile stuff (such as the player and monsters), and DispGraph.
Obviously, you can't use both of these strategies at the same time, since it would be pointless. I implement a similar strategy in my Eitrix game to cache the block grid.
_________________
Visit Betafreak Games: http://www.betafreak.com
Help Me Pay for College:
- Sign up for Fastweb through my referal link!
Posted: 19 Nov 2012 02:03:39 pm (GMT -5)
GinDiamond wrote: |
Is there a way to optimize the ClrDraw (code) DispGraph? I have a feeling that its a bit slow (or will become slow)... |
You will want to keep your basic ClrDraw / DispGraph pattern - when you draw a lot of objects in a game, it's better to clear them all at once than to try erasing them one by one.
The strategy that works best in the general case is to use the DispGraphClrDraw command (the DispGraph token immediately followed by ClrDraw). Basically, it's like doing a DispGraph, then a ClrDraw, but the procedure is almost as fast as DispGraph alone. So, to implement this strategy:
1. Stick a ClrDraw right before your main game loop.
2. Get rid of the ClrDraw inside your main game loop.
3. Change the DispGraph in your loop to a DispGraphClrDraw.
Since your game is a roguelike and won't be actively scrolling the map, you can also try caching your rendered map into some other buffer, then instead of doing a ClrDraw, copy this other buffer into the normal buffer, thus saving you the time of rendering the map every frame. Here's how you'd implement that strategy:
1. Decide where in memory you want to put your buffer. You have three choices: L3 (if you aren't using grayscale), L1 (if you #Realloc your variables to L4 and aren't archiving/unarchiving in your program), or an Appvar (create an appvar with some random name that's 768 bytes long, then keep that pointer for the rest of the program). Before your game loop begins, clear this buffer.
2. Keep another variable, such as θ, as an "update sentry variable". Set this to 1 before the loop begins. As you go through your loop, if you do something that causes the map to change (such as going to another screen), set the update sentry variable to 1.
3. Once you've done all your update actions (anything that could possibly change the sentry variable), check the sentry variable:
- If the variable is not zero, clear both the graph buffer and the other buffer. Draw your map on the graph buffer, then copy the graph buffer to the other buffer.
- Otherwise, simply copy the other buffer to the graph buffer. The other buffer contains your map, which is 100% accurate since your map has not changed (indicated by your sentry variable being 1). In addition, anything that was on your graph buffer is cleared by this operation.
4. In either case, set your sentry variable to zero, draw all your volatile stuff (such as the player and monsters), and DispGraph.
Obviously, you can't use both of these strategies at the same time, since it would be pointless. I implement a similar strategy in my Eitrix game to cache the block grid.
_________________
Visit Betafreak Games: http://www.betafreak.com
Help Me Pay for College:
- Sign up for Fastweb through my referal link!