Further upgrading put pixel.
Further upgrading put pixel.
Is there anyway to further optimise put pixell after intermediate lesson 6?
Computer too slow? Consider running a VM on your toaster.
-
- Posts: 97
- Joined: October 28th, 2012, 8:28 pm
Re: Further upgrading put pixel.
yes, there is ... but not performance wise ... it´s bare ...
but ... i added a line .. for pixels that fall outside of the window client rect ...
but i can´t post it right now, i don´t have the laptop ...
but ... i added a line .. for pixels that fall outside of the window client rect ...
but i can´t post it right now, i don´t have the laptop ...
Re: Further upgrading put pixel.
I did also. It looked like
if (x >= 0 && x <= screenwidth && y >= 0 && y <= screenheight)
{
PutPixel (.........);
}
This allowed me to pull things off screen into the screen a little at a time.
if (x >= 0 && x <= screenwidth && y >= 0 && y <= screenheight)
{
PutPixel (.........);
}
This allowed me to pull things off screen into the screen a little at a time.
Re: Further upgrading put pixel.
Although you should test to see if the object you're drawing is moving off the screen before you use that. Using an if statement on every pixel all the time will slow your program.
Musi
There are 10 types of people that understand binary.
Those that do, and those that don't.
There are 10 types of people that understand binary.
Those that do, and those that don't.
Re: Further upgrading put pixel.
I'm mainly looking for a further performance boost.
Computer too slow? Consider running a VM on your toaster.
-
- Posts: 97
- Joined: October 28th, 2012, 8:28 pm
Re: Further upgrading put pixel.
well, tell me how?
any test .. would add further if statements
mine looks like this
any test .. would add further if statements
Code: Select all
if (x >= 0 && x <= screenwidth && y >= 0 && y <= screenheight)
{
PutPixel (.........);
}
Code: Select all
// screenwidthv & screenheigh are defined in windows.cpp and passed by reference
if ( ( x >= 0 & x <= &screenwidth ) && ( y >= 0 & y <= &screenheigh ) )
{
PutPixel (.........);
}
Re: Further upgrading put pixel.
For example, if you're drawing a sprite thats 20x20. Test it's coordinates to see if any part of it is outside the screen. Assuming the the coordinates are at the top left of the sprite, something like:
The DrawSpriteClipped function would use the PutPixel with the if statement, the normal DrawSprite function would use the normal PutPixel. This way if the sprite is fully on the screen, you only use one if statement, instead of 400.
Code: Select all
void DrawSprite( int x, int y )
{
if( x < 0 || x + 20 > SCREENWIDTH ||
y < 0 || y + 20 > SCREENHEIGHT )
{
DrawSpriteClipped( x,y );
}
else
{
DrawSprite( x,y );
}
}
Last edited by Musi on December 14th, 2012, 11:21 pm, edited 1 time in total.
Musi
There are 10 types of people that understand binary.
Those that do, and those that don't.
There are 10 types of people that understand binary.
Those that do, and those that don't.
-
- Posts: 97
- Joined: October 28th, 2012, 8:28 pm
Re: Further upgrading put pixel.
i think i know what you mean.cameron wrote:I'm mainly looking for a further performance boost.
the loops that use putpixel .... only handle rectangles.
i was thinking about adding dynamic D3DCOLOR buffers to store reuseble "images" and copy them directly
Code: Select all
void D3DGraphics::PutPixel( int x,int y,int r,int g,int b )
{
assert( x >= 0 );
assert( y >= 0 );
assert( x < SCREENWIDTH );
assert( y < SCREENHEIGHT );
pSysBuffer[ x + SCREENWIDTH * y ] = D3DCOLOR_XRGB( r,g,b );
}
void D3DGraphics::PutPixel( int x,int y,D3DCOLOR c )
{
assert( x >= 0 );
assert( y >= 0 );
assert( x < SCREENWIDTH );
assert( y < SCREENHEIGHT );
pSysBuffer[ x + SCREENWIDTH * y ] = c;
}
Code: Select all
x + SCREENWIDTH * y
x + SCREENWIDTH * y in realty is a fixed value during the session and could be declared somewhere else and would save atleast 2 cpu cycles each time put pixel gets called.
all this ...
Code: Select all
assert( x >= 0 );
assert( y >= 0 );
assert( x < SCREENWIDTH );
assert( y < SCREENHEIGHT );
so in total you can speed up and save some 10 cpu cycles .. but lose about 4 on the test ..
Last edited by NaturalDemon on December 14th, 2012, 11:28 pm, edited 1 time in total.
-
- Posts: 97
- Joined: October 28th, 2012, 8:28 pm
Re: Further upgrading put pixel.
you're wrong ... sorry to sayMusi wrote:For example, if you're drawing a sprite thats 20x20. Tests it's coordinates to see if any part of it is outside the screen. Assuming the the coordinates are at the top left of the sprite, something like:
The DrawSpriteClipped function would use the PutPixel with the if statement, the normal DrawSprite function would use the normal PutPixel. This way if the sprite is fully on the screen, you only use one if statement, instead of 400.Code: Select all
void DrawSprite( int x, int y ) { if( x < 0 || x + 20 > SCREENWIDTH || y < 0 || y + 20 > SCREENHEIGHT ) { DrawSpriteClipped( x,y ); } else { DrawSprite( x,y ); } }
(see image) http://www.planetchili.net/forum/viewto ... e&start=10
Code: Select all
( x < 0 || x + 20 > SCREENWIDTH || y < 0 || y + 20 > SCREENHEIGHT )
Code: Select all
i(x >= 0 && x <= screenwidth && y >= 0 && y <= screenheight)
Last edited by NaturalDemon on December 14th, 2012, 11:43 pm, edited 2 times in total.
Re: Further upgrading put pixel.
A test will only make the game slow down. I want a performance boost to make the game run faster.
Computer too slow? Consider running a VM on your toaster.