• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
Nausea

[SDL] map with animated tiles. performance question.

7 posts in this topic

Hi!

 

I've tried to get animated tiles to work on my tile map and I've run into what may be a problem going forward.

I'll try to explain how I have it constructed in my code.

 

First:

My map class stores two vectors, one with tiles (one of each kind) and one vector stores "tile slots".

It also holds a tile sheet.

 

Second:

My tile class handles updating the sprite animation, only changes coordinates for the target sprite. 

Handles frame rate etc.

 

It also holds an ID to connect this with a tile slot ID.

 

Third:

My tile slot class holds ID, type, and x/y for where to draw them on the map.

ID is used to link it to a tile during rendering.

 

....

I did it like this because it was the only way I could think of, this way I could make it so that I only need to update the animation once per tile.

However, when I need to draw the tile slots for where the animated tile will be drawn I run into the problem of having to go through all tile slots and then go through all tiles to draw the correct tile at the correct place.

I can cut down on some of it by checking if the tile slot is inside of the camera, but this still leads to going through the entire tile slot vector.

 

My worry is that this will be very taxing on the computer when I get to the point of making a full fledged map. Not to mention when I will have to in some way check for collisions with the tile slots.

 

I wish that someone could maybe give some input on this.

 

Thank you!

Edited by Nausea
0

Share this post


Link to post
Share on other sites

Are all of your tiles the same size? If so, there are calculations you can perform based on the position of the camera and the dimensions of a tile, returning the element numbers of which tiles to draw (I could go into more detail if this is the case). If your tiles are not all the same size, then you might have to use a space partitioning method such as quadtrees.

0

Share this post


Link to post
Share on other sites

Are all of your tiles the same size? If so, there are calculations you can perform based on the position of the camera and the dimensions of a tile, returning the element numbers of which tiles to draw (I could go into more detail if this is the case). If your tiles are not all the same size, then you might have to use a space partitioning method such as quadtrees.

The tiles are all the same size. 

 

However I mostly wonder if this will be a real bad solution?

 

I've tried to fill up the screen with tiles without feeling any real performance problems and I wonder if that will change when I have a full map even tho I will only draw the tiles inside the camera and the collision boxes will be fewer to check for.

0

Share this post


Link to post
Share on other sites

My worry is that this will be very taxing on the computer when I get to the point of making a full fledged map. Not to mention when I will have to in some way check for collisions with the tile slots.

How many do you have? Be realistic.

 

Rectangular collision tests are cheap. Performing even 10000 rectangular collision tests on your objects probably isn't going to be a noticeable blip on the profiler.

 

If you are running with multiple thousands of rectangular tests every frame, or hundreds of non-rectangular tests every frame, then begins to make sense to use a spatial tree.  

 

If your numbers are small then don't bother with the added complexity.

 

 

 

EDIT:

 

However...

 

The thing that concerns me MUCH more is that you are describing a situation where you are probably sending all the data from the CPU to the GPU every frame.

 

You implied but did not actually state how you intend to render it. Sending all the data to the GPU every time is incredibly inefficient and slow. Make sure you are using SDL methods and objects that move the content to the graphics system a single time.

Edited by frob
1

Share this post


Link to post
Share on other sites

 


My worry is that this will be very taxing on the computer when I get to the point of making a full fledged map. Not to mention when I will have to in some way check for collisions with the tile slots.

How many do you have? Be realistic.

 

Rectangular collision tests are cheap. Performing even 1000 rectangular collision tests on your objects probably isn't going to be a noticeable blip on the profiler.

 

If you are running with multiple thousands of rectangular tests every frame, or hundreds of non-rectangular tests every frame, then it will make sense to use a spatial tree.  

 

If your numbers are small then don't bother with the added complexity.

 

 

Ok.

Well I won't be having over 1000 tongue.png

I guess I don't have to be worried, good to hear some thoughts on the subject tho.

 

Thanks

 

EDIT:

 

 

However...

 

The thing that concerns me MUCH more is that you are describing a situation where you are probably sending all the data from the CPU to the GPU every frame.

 

You implied but did not actually state how you intend to render it. Sending all the data to the GPU every time is incredibly inefficient and slow. Make sure you are using SDL methods and objects that move the content to the graphics system a single time.

 

 

Hmm.. I have a render function in my map class that goes over the tile slots, if the current tile slot is inside the camera range, go through the list of tiles and check which ID it corresponds to and render the tileslot at x/y with the tiles sprite x/y. This render function is run inside the applications render function, when all the things in the program has been through the render function it blits it on to the screen.

 

Maybe my wording is poor. What i mean to say is that the maps rendering function blits the stuff on to the screen surface, later in the applications render function when everything in the program is blitted on to the screen surface i "flip" it.

Edited by Nausea
0

Share this post


Link to post
Share on other sites

If you still wish to look into a more efficient way of handling collision and rendering with tiles, I suggest looking into Tim Jones' tutorials on his website, and especially his tutorial on maps (though you'll probably still have to read up on the previous tutorials to better understand the framework).

0

Share this post


Link to post
Share on other sites

 
I have a render function in my map class that goes over the tile slots, if the current tile slot is inside the camera range, go through the list of tiles and check which ID it corresponds to and render the tileslot at x/y with the tiles sprite x/y. This render function is run inside the applications render function, when all the things in the program has been through the render function it blits it on to the screen.
 
Maybe my wording is poor. What i mean to say is that the maps rendering function blits the stuff on to the screen surface, later in the applications render function when everything in the program is blitted on to the screen surface i "flip" it.

Would be nice if you could reply to it so I know if I'm actually doing something wrong, which I don't think that I do.

A quick way to test if your framework has the problem is to write a simple stress test.

I'm not sure about it, but it sounds like you are filling the screen with small tiles. In my mind, that means you have perhaps 30x20 background tiles + 50 or so foreground tiles + 50 or so UI sprites, totaling about 700 or so sprites. So load up and draw 1,000 sprites in a frame for one test and perhaps 2,000 or even 5,000 sprites in a frame in a second test, doing the same thing you do to normally draw them. Those can even be copies of the same image, if that is how you intend to run it. Run it and look at performance.

It is not uncommon that drawing a tile-based world in the way you described -- drawing the tiles individually -- has difficulty in running at a high frame rate. Many times (but certainly not always) the simple implementations will run into problems because they are copying the sprites to video memory every frame. Using SDL objects correctly probably won't have the problem. The test is to just make sure you are using them correctly and your solution will work.

Running a quick stress test can easily verify that your intended method can or cannot handle that many individual draw calls.
1

Share this post


Link to post
Share on other sites

 

 
I have a render function in my map class that goes over the tile slots, if the current tile slot is inside the camera range, go through the list of tiles and check which ID it corresponds to and render the tileslot at x/y with the tiles sprite x/y. This render function is run inside the applications render function, when all the things in the program has been through the render function it blits it on to the screen.
 
Maybe my wording is poor. What i mean to say is that the maps rendering function blits the stuff on to the screen surface, later in the applications render function when everything in the program is blitted on to the screen surface i "flip" it.

Would be nice if you could reply to it so I know if I'm actually doing something wrong, which I don't think that I do.

A quick way to test if your framework has the problem is to write a simple stress test.

I'm not sure about it, but it sounds like you are filling the screen with small tiles. In my mind, that means you have perhaps 30x20 background tiles + 50 or so foreground tiles + 50 or so UI sprites, totaling about 700 or so sprites. So load up and draw 1,000 sprites in a frame for one test and perhaps 2,000 or even 5,000 sprites in a frame in a second test, doing the same thing you do to normally draw them. Those can even be copies of the same image, if that is how you intend to run it. Run it and look at performance.

It is not uncommon that drawing a tile-based world in the way you described -- drawing the tiles individually -- has difficulty in running at a high frame rate. Many times (but certainly not always) the simple implementations will run into problems because they are copying the sprites to video memory every frame. Using SDL objects correctly probably won't have the problem. The test is to just make sure you are using them correctly and your solution will work.

Running a quick stress test can easily verify that your intended method can or cannot handle that many individual draw calls.

 

 

From what I can tell my program takes up 0% in the task manager with a 1000 tiles drawn inside and outside the screen region.

I go through my tilelist, blit the tiles and then when all are blit I send it from the buffer to the screen in one go.

 

I might go for splitting the map up in sections just because of speed anyway, might not be needed but might be a good thing anyway.

0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0