• 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
jellyfishchris

Voxel engine load times

10 posts in this topic

Hi,

Ive been making a voxel engine in my spare time. Currently I have it running at 60fps easy running the same amount of voxels you would see in a minecraft world. (125 chunks each chunk is 64 ^3 blocks.)

 

I am loading the voxels in as a flat array like so:

 

 

m_blocks.resize(CHUNK_SIZE);
for(int z = 0; z < CHUNK_SIZE; z++)
{
m_blocks[z].resize(CHUNK_SIZE);
for(int y = 0; y < CHUNK_SIZE; ++y)
{
m_blocks[z][y].resize(CHUNK_SIZE);
}
}
 

then using the terrain engine to create the desired layout of the blocks. Then putting this into an octree for optimizations and then clearing the original array. Also I am using a texture atlas.

 

My load time for all those blocks (32768000) is about 1minute in release mode. I was wondering if you guys have any ideas on how to boost up the load times. (I will eventually make the system multi-threaded when I get around to it)

 

Thanks

 

 

0

Share this post


Link to post
Share on other sites
Have you profiled what part of the loading pipeline is taking the most time?
0

Share this post


Link to post
Share on other sites
Also, allocating vectors in that way isn't really a flat array, even if the resulting access syntax makes it look like it is. It's actually quite a bit of memory allocation. Doesn't mean that is necessarily where the load time is going though.
0

Share this post


Link to post
Share on other sites

A completely flat array would be:

m_blocks.resize(CHUNK_SIZE*CHUNK_SIZE*CHUNK_SIZE);

 

What kind of data is a 'block'? If it's 4 bytes, then your ~32million blocks are 125MiB of data, which ideally, you should be able to load from disc in a few seconds.

0

Share this post


Link to post
Share on other sites

Well I had the same issue.

I was loading everything at program startup. If I use vectors for the chunks/blocks it takes around 30 seconds to load everything. VS told me that I'm stuck at the allocations.

Moved to raw array and the result was fantastic. You could not even feel that its allocating ~150MB.

I was shocked then, now it seems quite normal.Allocating(searching in the heap) is not that heavy operation if you request single block of data. Searching multiple time is the problem.

0

Share this post


Link to post
Share on other sites

How can we possibly guess what does your code do if we don't see it ?

 

Multithreading will only make things worse, if the relevant process is not parallel in nature and there would be a lot of syncing.

 

 

Note, that the complexity here is not just n*n (square), but cubic (n*n*n).

 

Thus every seemingly small change will have an n*n*n impact !

 

 

If you can't be bothered doing profiling, at least comment out certain functions/processes  and see the impact those non-executed processes have on the total duration.

0

Share this post


Link to post
Share on other sites

A completely flat array would be:

 

m_blocks.resize(CHUNK_SIZE*CHUNK_SIZE*CHUNK_SIZE);

 

What kind of data is a 'block'? If it's 4 bytes, then your ~32million blocks are 125MiB of data, which ideally, you should be able to load from disc in a few seconds.

Would it be better to do it this approach? Also each block is 1byte.

 

If you can't be bothered doing profiling, at least comment out certain functions/processes and see the impact those non-executed processes have on the total duration.

I have done profilling and the thing that takes the longest time by a long shot is the memory allocation

0

Share this post


Link to post
Share on other sites

A completely flat array would be:

 

m_blocks.resize(CHUNK_SIZE*CHUNK_SIZE*CHUNK_SIZE);

 

What kind of data is a 'block'? If it's 4 bytes, then your ~32million blocks are 125MiB of data, which ideally, you should be able to load from disc in a few seconds.

Would it be better to do it this approach? Also each block is 1byte.

 

 

>If you can't be bothered doing profiling, at least comment out certain functions/processes and see the impact those non-executed processes have on the total duration.

I have done profilling and the thing that takes the longest time by a long shot is the memory allocation

 

 

 

note that allocating large numbers of small objects is a bad case for typical memory managers.

 

it is generally much better to allocate a smaller number of larger objects in this case (IOW: the entire chunk as a single big array).

 

(FWIW: in my voxel engine, each block is actually 8 bytes... generally because it has a bit more per-block features...).

1

Share this post


Link to post
Share on other sites

I must have missed that at first, but this warrants a separate reply - now it almost looks like you are making every single allocation (for every single voxel) manually - like in a separate call ?  Say, if you have 3,000,000 voxels, you actually do all those 3,000,000 allocations - one by one ?!?

0

Share this post


Link to post
Share on other sites
Allocating in 1 big block is the best approach across the board. The only part that is a bit awkward is that in doing so you have to index the array differently. You can wrap the buffer in an object that hides these details though.

Cell[ x + y*width + z*width*depth ]
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