Why my quadtree is problematic?

Started by
24 comments, last by DoctorGlow 7 years, 1 month ago
How are you rendering the sprites? Are they 3D models or 2D quads with textures applied? What graphics API are you using (DirectX, OpenGL, openGL ES, etc.)? If you are using a hardware accelerated graphics API and rendering screen aligned quads with textures, even a low end modern GPU would practically sleep while rendering 1000 game objects. There is something going on behind the scenes that is causing the slow down; something you haven't mentioned.
Advertisement

How are you rendering the sprites? Are they 3D models or 2D quads with textures applied? What graphics API are you using (DirectX, OpenGL, openGL ES, etc.)? If you are using a hardware accelerated graphics API and rendering screen aligned quads with textures, even a low end modern GPU would practically sleep while rendering 1000 game objects. There is something going on behind the scenes that is causing the slow down; something you haven't mentioned.

I didn't create the render engine by my self. My game engine is actually a wrapper of an other game engine called pygame https://www.pygame.org/news. Actually pygame is not a game engine but it has the basic tools like sound playing, image drawing etc that lets you create your own game engines.

Now in order to to render a game object i'm just drawing the image of that game object in the screen using the blit method of pygame https://www.pygame.org/docs/ref/surface.html#pygame.Surface.blit and i'm doing this every frame.

I also fill the screen with a color in every frame in order refresh the canvas.

Something like that:


def render():
    
    #This loop run's every frame.
    while the game is running:
        screen.fill(black)
        screen.blit( gameobject[i].image, gameobject[i].pos.toTuple() )

void life()
{
  while (!succeed())
    try_again();

  die_happily();
}

 

How are you rendering the sprites? Are they 3D models or 2D quads with textures applied? What graphics API are you using (DirectX, OpenGL, openGL ES, etc.)? If you are using a hardware accelerated graphics API and rendering screen aligned quads with textures, even a low end modern GPU would practically sleep while rendering 1000 game objects. There is something going on behind the scenes that is causing the slow down; something you haven't mentioned.

His original post for the quadtree was about collision detection not rendering.

As you can see i go through all game objects to render them. Is there a way to divide my game world (with a quadtree) and say something like that: If my camera box boundary is close to a subarea of my world, take that subarea and render only the sprites of that area.

You;re on the right track, I suggest you actually google an article on quadtrees to see how one is implemented. Also you should look up how cameras are handled with a matrix in 2d, it's interesting and has some flexibility you currently don't have like scaling and rotation.

-potential energy is easily made kinetic-

Maybe because i'm using python and pygame i can't speed up more the engine. Maybe i need to create everything by myself from scratch with a lower lever language like c or c++.

Also i think pygame is using openGL.


How are you rendering the sprites? Are they 3D models or 2D quads with textures applied? What graphics API are you using (DirectX, OpenGL, openGL ES, etc.)? If you are using a hardware accelerated graphics API and rendering screen aligned quads with textures, even a low end modern GPU would practically sleep while rendering 1000 game objects. There is something going on behind the scenes that is causing the slow down; something you haven't mentioned.

His original post for the quadtree was about collision detection not rendering.

As you can see i go through all game objects to render them. Is there a way to divide my game world (with a quadtree) and say something like that: If my camera box boundary is close to a subarea of my world, take that subarea and render only the sprites of that area.

You;re on the right track, I suggest you actually google an article on quadtrees to see how one is implemented. Also you should look up how cameras are handled with a matrix in 2d, it's interesting and has some flexibility you currently don't have like scaling and rotation.

Yes you are right. My camera for now do not support rotation neither scaling. But i think i'm a little stupid :p What i'm actually trying to do is solve problems that already have been solved the last 30 years. Maybe i should read a book or something and pause my project for now. I have found this book but i don't know if its good: http://www.gameenginebook.com/


void life()
{
  while (!succeed())
    try_again();

  die_happily();
}

 

Maybe because i'm using python and pygame i can't speed up more the engine. Maybe i need to create everything by myself from scratch with a lower lever language like c or c++. Also i think pygame is using openGL.

How many objects can you handle now?

-potential energy is easily made kinetic-

His original post for the quadtree was about collision detection not rendering.


He wandered in that direction.

Maybe because i'm using python and pygame i can't speed up more the engine. Maybe i need to create everything by myself from scratch with a lower lever language like c or c++. Also i think pygame is using openGL.

How many objects can you handle now?

100-200 max. If there are more, the fps drops to 0-20.


void life()
{
  while (!succeed())
    try_again();

  die_happily();
}

 

100-200 max. If there are more, the fps drops to 0-20.

I'm not really familiar with python or pygame but that number does seem kind of low. But I have some questions that might help someone else help you better.

For the 100-200 objects max, is that collision only or rendering too? What about AI?

Is that just moving objects or static objects as well?

Is that with the quadtree or without?

what version of python are you using?

Are you using hardware acceleration for your blits?(only relevent if you are including rendering)

Post your collision code.

What are your machine specs? i.e. are you doing this on a 10 year old netbook?

-potential energy is easily made kinetic-

100-200 max. If there are more, the fps drops to 0-20.

I'm not really familiar with python or pygame but that number does seem kind of low. But I have some questions that might help someone else help you better.

For the 100-200 objects max, is that collision only or rendering too? What about AI?

Is that just moving objects or static objects as well?

Is that with the quadtree or without?

what version of python are you using?

Are you using hardware acceleration for your blits?(only relevent if you are including rendering)

Post your collision code.

What are your machine specs? i.e. are you doing this on a 10 year old netbook?

The objects are being rendered and the collision algorithm is also running at the same time.

Until now i only tried n-1 static objects and one moving player.

I use the quadtree to get a list every frame and check if the player collide's with at least one of the objects in the list.

I'm using python 3.5

I don't even know what is a hardware acceleration for blits. (Graphics card or something else?)

I have 8 GB ram, a 6-core AMD processor at 5 GHZ, windows 7 64, and an AMD randeon R9 series.

self.x and self.y are offsets which i can change in order to increase the size of the "invisible rectange" which i use for collision detection. origin.x and origin.y are the sprite's coordinates.


    #Collision algorithm.
    def checkCollision(self, other):
        
        #Check the rectangles x coordinate.
        if self.origin.x + self.x + self.width >= other.origin.x + other.x:
            if self.origin.x + self.x <= other.origin.x + other.x + other.width:
                
                #Check the rectangles y coordinate.
                if self.origin.y + self.y + self.height >= other.origin.y + other.y:
                    if self.origin.y + self.y <= other.origin.y + other.y + other.height:
                        return True

void life()
{
  while (!succeed())
    try_again();

  die_happily();
}

 

The objects are being rendered and the collision algorithm is also running at the same time.

That is an error. Run physics, then draw.


L. Spiro

I restore Nintendo 64 video-game OST’s into HD! https://www.youtube.com/channel/UCCtX_wedtZ5BoyQBXEhnVZw/playlists?view=1&sort=lad&flow=grid

This topic is closed to new replies.

Advertisement