increase performance with SDL

Anything related in any way to game development as a whole is welcome here. Tell us about your game, grace us with your project, show us your new YouTube video, etc.

Moderator: PC Supremacists

Post Reply
kovicic
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 1
Joined: Mon Mar 19, 2012 11:29 pm

increase performance with SDL

Post by kovicic »

Hi everyone, I am new developing a 2D game with C++/SDL for Linux, but not programming.
The target hardware where the game will be played isn't powerful, 256RAM at most. So, openGL is out of discussion.

I have sheet srpite file, it contains the character movements, and several files for the backround and other sprite files to put on a layered fashion way.

When the applications keeps simple, the character/sprite can jump, it moves to left, right, up and down, etc. It works fine.
By simple I mean: one background and the sheet sprite.

According I add more screens and sprite it desceases the speed in a unplaying way.
I think I did a bad choice: I upload the sprite sheet at the begining and the rest of the screen are loaded on demand from disk, but I think is very 'CPU expensive'.
I plan to upload more than one screen/file to memory and switch between them on demand. Is this the correct manner?.

I'll chek the bit format of the screen to be the correct SDL_Displayformat before bliting, and etc.

Any suggestion for the best strategy? or the format file to work with?

Thanks

Kovi
User avatar
Light-Dark
Dreamcast Developer
Dreamcast Developer
Posts: 307
Joined: Sun Mar 13, 2011 7:57 pm
Current Project: 2D RPG & NES Platformer
Favorite Gaming Platforms: NES,SNES,N64,Genesis,Dreamcast,PC,Xbox360
Programming Language of Choice: C/++
Location: Canada

Re: increase performance with SDL

Post by Light-Dark »

kovicic wrote:Hi everyone, I am new developing a 2D game with C++/SDL for Linux, but not programming.
The target hardware where the game will be played isn't powerful, 256RAM at most. So, openGL is out of discussion.
first 2 sentences in and i see some problems, first you could elaborate on the hardware your using and by 256 ram what does that mean? it could mean 256 bits of ram, it could be 256 bytes,kilobytes,megabytes,gigabytes,etc, to sum it up could you be a little more specific and share some more details :S?
<tpw_rules> LightDark: java is a consequence of inverse moore's law: every 18 months, the average program will be twice as slow. therefore, computers always run at the same percevied speed. java's invention was a monumental step
Image
User avatar
dandymcgee
ES Beta Backer
ES Beta Backer
Posts: 4709
Joined: Tue Apr 29, 2008 3:24 pm
Current Project: https://github.com/dbechrd/RicoTech
Favorite Gaming Platforms: NES, Sega Genesis, PS2, PC
Programming Language of Choice: C
Location: San Francisco
Contact:

Re: increase performance with SDL

Post by dandymcgee »

Light-Dark wrote: first 2 sentences in and i see some problems, first you could elaborate on the hardware your using and by 256 ram what does that mean? it could mean 256 bits of ram, it could be 256 bytes,kilobytes,megabytes,gigabytes,etc, to sum it up could you be a little more specific and share some more details :S?
Considering it's Linux, 256 KB and 256 GB are both ridiculously unreasonable assumptions, leaving 256MB as the only one which makes sense. I honestly don't see how that was so complicated to figure out.
Falco Girgis wrote:It is imperative that I can broadcast my narcissistic commit strings to the Twitter! Tweet Tweet, bitches! :twisted:
User avatar
Light-Dark
Dreamcast Developer
Dreamcast Developer
Posts: 307
Joined: Sun Mar 13, 2011 7:57 pm
Current Project: 2D RPG & NES Platformer
Favorite Gaming Platforms: NES,SNES,N64,Genesis,Dreamcast,PC,Xbox360
Programming Language of Choice: C/++
Location: Canada

Re: increase performance with SDL

Post by Light-Dark »

dandymcgee wrote:
Light-Dark wrote: first 2 sentences in and i see some problems, first you could elaborate on the hardware your using and by 256 ram what does that mean? it could mean 256 bits of ram, it could be 256 bytes,kilobytes,megabytes,gigabytes,etc, to sum it up could you be a little more specific and share some more details :S?
Considering it's Linux, 256 KB and 256 GB are both ridiculously unreasonable assumptions, leaving 256MB as the only one which makes sense. I honestly don't see how that was so complicated to figure out.
just pointing out that it could be a little more specific thats all.
<tpw_rules> LightDark: java is a consequence of inverse moore's law: every 18 months, the average program will be twice as slow. therefore, computers always run at the same percevied speed. java's invention was a monumental step
Image
User avatar
jakobnator
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 20
Joined: Thu Mar 31, 2011 8:14 pm
Current Project: Black Jack
Favorite Gaming Platforms: N64,DC,PC,360
Programming Language of Choice: C++0x
Location: (n): A particle place in physical space.

Re: increase performance with SDL

Post by jakobnator »

I am not sure how well SDL works with .jpeg but when it comes to the file format .jpeg will be the least intense on the CPU. What kind of sprites are these 16-bit? If so I think if you upload it as a jpg it should look fine. I for one have never had a problem loading all of the sprite sheets at the beginning. I really don't think its the art check the coding for memory leaks and what not.
Image

Current Games:
Black Jack [WIP]
Tic Tac Toe [SDL]
Tic Tac Toe
User avatar
superLED
Chaos Rift Junior
Chaos Rift Junior
Posts: 303
Joined: Sun Nov 21, 2010 10:56 am
Current Project: Engine
Favorite Gaming Platforms: N64
Programming Language of Choice: C++, PHP
Location: Norway

Re: increase performance with SDL

Post by superLED »

jakobnator wrote:I am not sure how well SDL works with .jpeg but when it comes to the file format .jpeg will be the least intense on the CPU. What kind of sprites are these 16-bit? If so I think if you upload it as a jpg it should look fine. The sprite sheets I really have never had a problem loading all of the sprite sheets at the beginning. I really don't think its the art check your coding, most machines should handle a 2-D computer game.
Seriously? Is .jpeg more efficient than .bmp formats?
And yes, modern computers can easily handle a 2D game, but I guess they are making a game for a somewhat old/limited system.
User avatar
Light-Dark
Dreamcast Developer
Dreamcast Developer
Posts: 307
Joined: Sun Mar 13, 2011 7:57 pm
Current Project: 2D RPG & NES Platformer
Favorite Gaming Platforms: NES,SNES,N64,Genesis,Dreamcast,PC,Xbox360
Programming Language of Choice: C/++
Location: Canada

Re: increase performance with SDL

Post by Light-Dark »

superLED wrote:
jakobnator wrote:I am not sure how well SDL works with .jpeg but when it comes to the file format .jpeg will be the least intense on the CPU. What kind of sprites are these 16-bit? If so I think if you upload it as a jpg it should look fine. The sprite sheets I really have never had a problem loading all of the sprite sheets at the beginning. I really don't think its the art check your coding, most machines should handle a 2-D computer game.
Seriously? Is .jpeg more efficient than .bmp formats?
And yes, modern computers can easily handle a 2D game, but I guess they are making a game for a somewhat old/limited system.
i use png format, does sdl provide any documentation to which format is less CPU intesitve or is this from personal experince?
<tpw_rules> LightDark: java is a consequence of inverse moore's law: every 18 months, the average program will be twice as slow. therefore, computers always run at the same percevied speed. java's invention was a monumental step
Image
User avatar
superLED
Chaos Rift Junior
Chaos Rift Junior
Posts: 303
Joined: Sun Nov 21, 2010 10:56 am
Current Project: Engine
Favorite Gaming Platforms: N64
Programming Language of Choice: C++, PHP
Location: Norway

Re: increase performance with SDL

Post by superLED »

Light-Dark wrote:
superLED wrote:
jakobnator wrote:I am not sure how well SDL works with .jpeg but when it comes to the file format .jpeg will be the least intense on the CPU. What kind of sprites are these 16-bit? If so I think if you upload it as a jpg it should look fine. The sprite sheets I really have never had a problem loading all of the sprite sheets at the beginning. I really don't think its the art check your coding, most machines should handle a 2-D computer game.
Seriously? Is .jpeg more efficient than .bmp formats?
And yes, modern computers can easily handle a 2D game, but I guess they are making a game for a somewhat old/limited system.
i use png format, does sdl provide any documentation to which format is less CPU intesitve or is this from personal experince?
Png is an easy format to work with. It has an Alpha Channel, compressed somewhere between .jpg and .bmp (correct me if I'm wrong). With the Alpha Channel, you don't need to paint pink color on the parts that should not be drawn. That way, you can also use different values of Alpha, like a fading-effect or similar.

.bmp files are more compressed and space friendly, but the quality (the amount of colors) are not that good. Old computers was stricted to this format because it took up so little space.
I don't think .jpg formats have an Alpha Channel. Maybe some 'versions' but it's not the standard.
And I also think .png is the standard format on the web as well, due to its decent quality and the little space it takes, and the Alpha Channel.

This may not be 100% correct, and it may be outdated.
User avatar
jakobnator
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 20
Joined: Thu Mar 31, 2011 8:14 pm
Current Project: Black Jack
Favorite Gaming Platforms: N64,DC,PC,360
Programming Language of Choice: C++0x
Location: (n): A particle place in physical space.

Re: increase performance with SDL

Post by jakobnator »

Some versions of .bmp have an optional alpha channel, not sure if you can use it with SDL.
Image

Current Games:
Black Jack [WIP]
Tic Tac Toe [SDL]
Tic Tac Toe
User avatar
Ginto8
ES Beta Backer
ES Beta Backer
Posts: 1064
Joined: Tue Jan 06, 2009 4:12 pm
Programming Language of Choice: C/C++, Java

Re: increase performance with SDL

Post by Ginto8 »

jakobnator wrote:Some versions of .bmp have an optional alpha channel, not sure if you can use it with SDL.
SDL can do alpha blending, but it's very slow about it. This is primarily because SDL cannot take advantage of optimized array-copying techniques (memcpy is pretty good), and has to do extra processing for every pixel it blits.
Quit procrastinating and make something awesome.
Ducky wrote:Give a man some wood, he'll be warm for the night. Put him on fire and he'll be warm for the rest of his life.
Post Reply