Problem with game loop

I’ve got some performance problem in my program:

http://pastebin.com/mf3a79ec

How I can improve my pixel_rescale algorithm?

The program has a matrix (Display) of X_MAX and Y_MAX, and SCALE is a
value of picture scale.

For example, I want a scale of x2, Display is [4][3]:

  • = 1
    0 = 0****
    00

The program changes it to:



0000
0000



As Display gets new values the screen changes, that goes really nice,
but I want more speed for my program.

How I can do it?

A Greeting.

PS: Sorry for my bad english :frowning: , I’m from Spain.

You can use SDL_gfx for the rescale, I don’t know if the performance
will be enough for your needs. If not, go for hardware accelerated
scale, OpenGL :slight_smile:

Cheers,

Andre

Asier Gonz?lez wrote:> I’ve got some performance problem in my program:

http://pastebin.com/mf3a79ec

How I can improve my pixel_rescale algorithm?

The program has a matrix (Display) of X_MAX and Y_MAX, and SCALE is a
value of picture scale.

For example, I want a scale of x2, Display is [4][3]:

  • = 1
    0 = 0

00


The program changes it to:



0000
0000



As Display gets new values the screen changes, that goes really nice,
but I want more speed for my program.

How I can do it?

A Greeting.

PS: Sorry for my bad english :frowning: , I’m from Spain.


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Sprig and SGE use a different scaling algorithm. Many find it to be
faster than SDL_gfx.

Jonny DOn Sun, Nov 22, 2009 at 12:40 PM, Andre de Leiradella wrote:

You can use SDL_gfx for the rescale, I don’t know if the performance will be
enough for your needs. If not, go for hardware accelerated scale, OpenGL :slight_smile:

Cheers,

Andre

Asier Gonz?lez wrote:

I’ve got some performance problem in my program:

http://pastebin.com/mf3a79ec

How I can improve my pixel_rescale algorithm?

The program has a matrix (Display) of X_MAX and Y_MAX, and SCALE is a
value of picture scale.

For example, I want a scale of x2, Display is [4][3]:

  • = 1
    0 = 0

00


The program changes it to:



0000
0000



As Display gets new values the screen changes, that goes really nice, but
I want more speed for my program.

How I can do it?

A Greeting.

PS: Sorry for my bad english :frowning: , I’m from Spain.


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

But I’ve a problem, because I need to scale every loop.

Jonathan Dearborn escribi?:> Sprig and SGE use a different scaling algorithm. Many find it to be

faster than SDL_gfx.

Jonny D

On Sun, Nov 22, 2009 at 12:40 PM, Andre de Leiradella wrote:

You can use SDL_gfx for the rescale, I don’t know if the performance will be
enough for your needs. If not, go for hardware accelerated scale, OpenGL :slight_smile:

Cheers,

Andre

Asier Gonz?lez wrote:

I’ve got some performance problem in my program:

http://pastebin.com/mf3a79ec

How I can improve my pixel_rescale algorithm?

The program has a matrix (Display) of X_MAX and Y_MAX, and SCALE is a
value of picture scale.

For example, I want a scale of x2, Display is [4][3]:

  • = 1
    0 = 0

00


The program changes it to:



0000
0000



As Display gets new values the screen changes, that goes really nice, but
I want more speed for my program.

How I can do it?

A Greeting.

PS: Sorry for my bad english :frowning: , I’m from Spain.


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

You should test to check if these libraries are fast enough for your needs.
Maybe you could pre-scale the images before the game loop begins?

The other alternative is hardware acceleration…

Cheers,

Andre

--------- Mensagem Original --------De: SDL Development List
Para: SDL Development List
Assunto: Re: [SDL] Problem with game loop
Data: 23/11/09 15:23

But I’ve a problem, because I need to scale every loop.

Jonathan Dearborn escribi?:
> Sprig and SGE use a different scaling algorithm. Many find it to be
> faster than SDL_gfx.
>
> Jonny D
>
>
> On Sun, Nov 22, 2009 at 12:40 PM, Andre de Leiradella
> <aleirade at sct.microlink.com.br> wrote:
>
>> You can use SDL_gfx for the rescale, I don’t know if the
performance will be
>> enough for your needs. If not, go for hardware accelerated scale,
OpenGL :slight_smile:
>>
>> Cheers,
>>
>> Andre
>>
>> Asier Gonz?lez wrote:
>>
>>> I’ve got some performance problem in my program:
>>>
>>> http://pastebin.com/mf3a79ec
>>>
>>> How I can improve my pixel_rescale algorithm?
>>>
>>> The program has a matrix (Display) of X_MAX and Y_MAX, and
SCALE is a
>>> value of picture scale.
>>>
>>> For example, I want a scale of x2, Display is [4][3]:
>>> * = 1
>>> 0 = 0
>>>
>>> ****
>>> 00
>>> ****
>>>
>>> The program changes it to:
>>>
>>> ********
>>> ********
>>> 0000
>>> 0000
>>> ********
>>> ********
>>>
>>> As Display gets new values the screen changes, that goes
really nice, but
>>> I want more speed for my program.
>>>
>>> How I can do it?
>>>
>>> A Greeting.
>>>
>>> PS: Sorry for my bad english :frowning: , I’m from Spain.
>>> _______________________________________________
>>> SDL mailing list
>>> SDL at lists.libsdl.org
>>> http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
>>>
>>>
>>>
>> _______________________________________________
>> SDL mailing list
>> SDL at lists.libsdl.org
>> http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
>>
>>
> _______________________________________________
> SDL mailing list
> SDL at lists.libsdl.org
> http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
>
>


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


Mensagem enviada pelo Microlink Webmail 12.7.8p3

Do you HAVE to scale images every loop? You can’t save scale results in it’s own surface?
Any of the options mentioned are going to be slow other than OpenGL.
So if scaling is required for every loop and you can’t save the results then OpenGL/DirectX will be your best bet.

[quote=“Asier Gonz?lez”]But I’ve a problem, because I need to scale every loop.

Sprig can do realtime (~40 fps) rotation of more than 10 40x40 sprites
with a 2 GHz CPU and other background effects. I do that the slow
way, too (creating a new surface each time). Scaling should be
similar if the sprite is not too big. Is that enough?

Jonny DOn Mon, Nov 23, 2009 at 11:35 AM, MBrening <micah.brening at gmail.com> wrote:

Do you HAVE to scale images every loop? You can’t save scale results in it’s
own surface?
Any of the options mentioned are going to be slow other than OpenGL.
So if scaling is required for every loop and you can’t save the results then
OpenGL/DirectX will be your best bet.

[quote=“Asier Gonz?lez”]But I’ve a problem, because I need to scale every
loop.


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Well, I will explain it as good as I can.

I’ve the matrix Display[X_MAX][Y_MAX] where values are X_MAX = 64 and
Y_MAX = 32.
This position in my screen, is a very little windows with exactly 64 x
32 pixels, obviously, I need to scale. So I created a directive called
SCALE, with scale degree.
I multiplied X_MAX and Y_MAX by SCALE, with this, now, I have a pretty
nice window. Then, with my scale algorithm, I put Display in the window
with this scale adjustment and it see really nice.

But my problem is I need to rescale Display to window, because every
loop Display changes his values, and that’s it.

A Greeting.

MBrening escribi?:> Do you HAVE to scale images every loop? You can’t save scale results

in it’s own surface?
Any of the options mentioned are going to be slow other than OpenGL.
So if scaling is required for every loop and you can’t save the
results then OpenGL/DirectX will be your best bet.

[quote=“Asier Gonz?lez”]But I’ve a problem, because I need to scale
every loop.


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Hi friends:

I’m making a game where the character goes through a tunnel at one side of the
screen and go out at the same tunnel but to the other side of the screen,
therefore, the X coordinate of the character is going to be negative, in the
moment to leave the tunnel when going from right to left.

the X coordinate going to exceeds the width of the screen and when this happens,
I give the value -32, to begin to draw it or come out the other side of the
screen.

well the point is, when the program get in to the SDL_BlitSurface() function and
get out of it, the value of the X coordinate that are in the SDL_Rect variable
that I have used to draw the character takes 0, the program change -32 for 0,
how can I solve this problem.

some advice.

Keep track of the value separatley.

SDL_BlitSurface() adjusts the SDL_Rect (hence why you send it as a pointer)
to inform you of any clipping that took place.

-bill!On Mon, Nov 23, 2009 at 01:01:45PM -0600, Leonel Flor?n Selles wrote:

well the point is, when the program get in to the SDL_BlitSurface() function and
get out of it, the value of the X coordinate that are in the SDL_Rect variable
that I have used to draw the character takes 0, the program change -32 for 0,
how can I solve this problem.

Yep, a quick way to avoid this is to make a copy and send that to
SDL_BlitSurface. If you wrap SDL_BlitSurface in a pass-by-value
function, then that would do it for you:
int blit_surface(SDL_Surface* src, SDL_Rect srcrect, SDL_Surface*
dest, SDL_Rect dstrect)
{
return SDL_BlitSurface(src, &srcrect, dest, &dstrect);
}

I don’t do exactly that… I use something like this, for convenience:
int blit_surface(SDL_Surface* src, SDL_Surface* dest, int x, int y)
{
SDL_Rect dstrect = {x, y, 0, 0};
return SDL_BlitSurface(src, NULL, dest, &dstrect);
}

Jonny DOn Mon, Nov 23, 2009 at 2:23 PM, Bill Kendrick wrote:

On Mon, Nov 23, 2009 at 01:01:45PM -0600, Leonel Flor?n Selles wrote:

well the point is, when the program get in to the SDL_BlitSurface() function and
get out of it, the value of the X coordinate that are in the SDL_Rect ?variable
that I have used to draw the character takes 0, ?the program change -32 for 0,
how can I solve this problem.

Keep track of the value separatley.

SDL_BlitSurface() adjusts the SDL_Rect (hence why you send it as a pointer)
to inform you of any clipping that took place.

-bill!


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org