How much blit costs?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

How much blit costs?

babaliaris
This post was updated on .
Hello.

I'm trying to create a game engine with the maximum possible game objects per scene.
These days, i'm trying to understand how much the blit method costs, so for this purpose i created a mini
game engine and impremented it to create a game which all it does is blitting 15000 images
on the screen (Actually six, because as you will see below, the other 14996 are off the screen).

So this is how my engine works:
Download the source code: Github Repository
Engine Structure
Game Result

As you can see, the game runs in 50-60 fps.
My processor is: AMD FX™ - 6350 Six Core 3.90 GHz.

Can i do better?
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: How much blit costs?

Jake b
Have you profiled your code?

On Jun 14, 2017 4:39 PM, "babaliaris" <[hidden email]> wrote:
Hello. I'm trying to create a game engine with the maximum possible game objects per scene. These days, i'm trying to understand how much the blit method costs, so for this purpose i created a mini game engine and impremented it to create a game which all it does is blitting 15000 images on the screen (Actually six, because as you will see below, the other 14996 are off the screen). So this is how my engine works: Download the source code: Github Repository Engine Structure Game Result As you can see, the game runs in 50-60 fps. My processor is: AMD FX™ - 6350 Six Core 3.90 GHz. Can i do better?

View this message in context: How much blit costs?
Sent from the pygame-users mailing list archive at Nabble.com.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: How much blit costs?

Ian Mallett-2
In reply to this post by babaliaris
​Hi,

There was rather a lot of discussion on the mailing list archive about related topics recently, so searching the archives might prove informative. However, the main things to know are:

(1) PyGame is essentially CPU-bound rasterization. The fastest way to do this is with the Sprite module, or so I'm told.

(2) Using PyOpenGL instead of PyGame (for blitting, anyway), you instead use the GPU, which is deigned for doing just this. You have to know what you're doing, but it will probably be faster.

In your case, most of your objects are off the screen, so you're probably CPU-bound anyway. If you really need more performance, and you really need to process every object every frame, you'll need to switch to a language with less overhead, like C++, or jitted like PyPy.

Ian
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: How much blit costs?

babaliaris
Thank for your answer. Anyway i will stick with this, because i want to create a pygame GUI engine to simple let you create 2d games easily.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: How much blit costs?

babaliaris
Jake b, i dont know how to use the pythons profiler, but i'll check it out.
bw
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: How much blit costs?

bw
In reply to this post by babaliaris

Hi. If you have 14996 sprites that are not visible, and do not need to be processed every frame, the greatest performance improvement you will get is by using a spatial hash instead of a flat container such as a sprite group, list, or dict.

Even if off-screen sprites need some processing near the edges of the screen a spatial hash will give you a big boost.


On 6/14/2017 4:39 PM, babaliaris wrote:
Hello.

I'm trying to create a game engine with the maximum possible game objects per scene.
These days, i'm trying to understand how much the blit method costs, so for this purpose i created a mini
game engine and impremented it to create a game which all it does is blitting 15000 images
on the screen (Actually six, because as you will see below, the other 14996 are off the screen).

So this is how my engine works:
Download the source code: Github Repository
Engine Structure
Game Result

As you can see, the game runs in 50-60 fps.
My processor is: AMD FX™ - 6350 Six Core 3.90 GHz. Can i do better?

View this message in context: How much blit costs?
Sent from the pygame-users mailing list archive at Nabble.com.

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: How much blit costs?

babaliaris
This post was updated on .
bw thanks for your answer. The problem is that in the future sprite objects would be able to have a Brain object which the programmer can attach in order to give functionalities to a sprite object. Because my engine does not know which sprites have brains, I must go through all of them and run any possible brain scripts every frame.

So if I use a spatial hash, only part of the sprite objects will be available and all the other sprites will freeze including their scripts (brains)
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: How much blit costs?

Radomir Dopieralski
On Thu, 15 Jun 2017 11:09:21 -0700 (MST)
babaliaris <[hidden email]> wrote:

> bw thanks for your answer. The problem is that in the future sprite
> objects would be able to have a Brain object which the programmer can
> attach in order to give functionalities to a sprite object. Because
> my engine does not know which sprites have brains, I must go through
> all of them and run any possible brain scripts every frame.

Well, that is trivial to solve. Just keep a separate list of sprites
that have brains. Also, you only need to call the brain code on them,
and not blit them.

--
Radomir Dopieralski

--
Radomir Dopieralski
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: How much blit costs?

babaliaris
Sorry for the offtopic reply but some times when i try to preview or post a reply i'm getting this error:

Image

Should i report it somewhere? It's really frustrating.
Loading...