• 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

Background resource loading - waiting for some item to finish

4 posts in this topic

Hello !

I'm trying to implement asynchronous resource loading in my engine (by using a separate thread for I/O and decompression) for the first time in my life and i couldn't find solutions to my problem.

1) How should I implement waiting for a specific resource to be loaded?

For instance, when i'm dragging an asset from the asset tree view and dropping it onto the render viewport in my editor,
i need to block the main thread and wait until the resource data is fully loaded or timeout is reached.

2) And how do I specify a timeout value for the load request?

I've read that it's usually done by using request ids/tokens/handles for manipulating individual requests (e.g.: wait/cancel/setPriority).
How is it usually done?

3) How to avoid temporary allocations/extraneous copies during resource loading?

It's bad for performance when the client allocates temporary buffer, issues an async read request into that buffer, instantiates resource, frees the buffer and repeats this procedure, say, a hundred times.

Should i have one streaming buffer which is filled if the user didn't specify her own output buffer?

i've put the whole thing on Pastebin and i'd be very pleased if you could look through the code and spot errors/propose improvements
header file: [url="http://pastebin.com/8pyHnrSh"]http://pastebin.com/8pyHnrSh[/url]
source file: [url="http://pastebin.com/WFQ1dPyW"]http://pastebin.com/WFQ1dPyW[/url]

Share this post

Link to post
Share on other sites
1) If you have a C++11 compiler, you could use [url="http://en.cppreference.com/w/cpp/thread/future"]std::future[/url] to block until the resource signals it is ready

2) std::future has timeout capability as well.

If you don't have a C++11 compiler, you could use [url="http://www.boost.org/doc/libs/1_52_0/doc/html/thread/synchronization.html#thread.synchronization.futures"]boost::future[/url] as a replacement. Edited by Rattrap

Share this post

Link to post
Share on other sites
1) If you want to block until it's loaded, then why use async loading? The point of async loading is that you can display a nice "please wait" animation instead of blocking, and then receive a notification when your asset is ready to stop the animation and start using the asset.

2) Yeah, often the function that initiates a request returns some kind of identifier that you can use to check on it's status or abort the request. You probably don't need to build timeouts into the system at this level, as long as you've got the ability to abort at this level ([i]even that's not required for many games[/i] [img]http://public.gamedev.net//public/style_emoticons/default/wink.png[/img]) Then, the systems that use the file loader can implement user-triggered, or time-based, etc aborting, if they require it.

3) With decompression, it's common for the decompression thread to keep it's own buffers for re-use.

If you are reading a lot of files into temporary memory before parsing them and throwing the allocations away, it might make sense to allocate a small ring of buffers for the file loader to use as defaults. You'd have to collect some statistics on the size of your "temporary" files and how many are being loaded at once to make an educated guess as to the best sizes to use.

As for "[i]allocate buffer, async read into buffer, instantiate resource from buffer, free buffer[/i]", you can often just "[i]instantiate resource, async read into resource[/i]". I've split my async asset loading into a few steps to help with this --
When you issue an async request, you provide a callback for allocating the asset, and a callback for parsing the asset. When the file size becomes known ([i]I store a table of sizes as part of the file system, which is resident in RAM, so this is immediate[/i]), the allocation callback is triggered to create the resource. Then the resource is filled in asynchronously, and when it's done the 'parsing' callback is triggered to finalize the resource. Assets can also report an array of sizes if they require some of their data to be streamed into different allocations ([i]e.g. a texture header for the CPU and the actual texel data for the GPU[/i]).

4) If you want to write OS-specific code, you can usually implement async file loading without any extra threads, as OS file interations are likely async natively ([i]the blocking API is often a wrapper around the async API[/i]). However, if you want to do background decompression, that obviously does require some threading ;) Edited by Hodgman

Share this post

Link to post
Share on other sites
1) I need to block only in the editor mode, because the resulting code is simpler in my (small) experience:
I get a pointer and start manipulating the created mesh instance (e.g. move, rotate) or get an error screen.

2) Where can I find out more about efficient implementation of such a system (load request queue with fast access by request ids and minimum allocations) ?
Right now my queues are dynamic arrays and I perform a linear search to find requests by their ids.

3) So, your advice would be to delegate the task of managing temporary memory to the client?
(Then I'll have to think about fighting fragmentation on the client side.)

(In the background thread I'll be doing reading, decompression, pointer patching, setting external references (dependencies) to proxy objects and issuing requests to load them later.)

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