• 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
3DModelerMan

Resource managers: how much is overkill?

6 posts in this topic

I've got a resource manager implemented in my engine, but I'm starting to wonder if I've over-engineered it. I built a resource management system that uses ResourcePackages (or resource groups) and resources are addressed using a ResourcePath. The ResourcePath is like a normal file path, except that it contains the package name before the path for example "package:folder/directory/resource.res".

 

I'm starting to notice it's becoming increasingly difficult to manage the package names in my content pipeline, because I have to manage all the links between resources. A mesh links to a material that may or may not be inside another resource group for example.

 

I implemented resource packages originally because I want to be able to pre-load entire groups of resources all at once, and also be able to unload entire groups. I'm starting to wonder if my package system is overkill though. For a small world it's obviously overkill, but I'm trying to build an engine optimized for massive open worlds. I already have background loading, load/unload events, and a cache to keep frequently used resources in memory.

0

Share this post


Link to post
Share on other sites

I'm not sure whether I understand why exactly the OP is speaking of overkill. It seems me that using a package name within the resource name is making the problem. If so, the following description may help; if not … feel free to ignore my post ;)

 

When the system starts up, it scans a specific directory (the "overlay" directory) for files, and assumes each file to contain a single resource. It stores the names of the files as names of resources in an internal table of content. I'm using hashes for resource names at the runtime level, but the file-path names relative to the directory would work as well. The system further scans another directory (the "package" directory) for files, and each file determined to have the correct format is opened and its stored table of content is integrated with the one already in RAM. During this, if a resource name collides with one already in the internal TOC, it is ignored and the internal entry left as is; additionally, if the already contained entry refers to a package as source, a conflict is logged.

 

The table of content now has entries for each single resource. The resources' names managed therein are not tagged by a package name or whether they origin from the overlay directory. But these additional informations are stored along the resource name in the entries, of course.

 

A file offset and length is stored in the TOC for accessing a resource inside the package file. Now, the file offset and length does not necessarily address a single resource but may address a sequence of resources. This is called a load unit, because all addressed bytes are loaded (and later unloaded) at once. Nevertheless, the entries in the TOC are still names of individual resources. So requesting any resource of a load unit causes all resources in that load unit to be loaded. A "bill of materials", as may be stored along a resource to declare dependencies, ever lists each single resource.

 

Of course, before the loader is requested to load a resource load unit, the cache is interrogated whether a resource is already loaded.

 

With a concept like the one above, resources are requested by name and regardless of their storage location, and regardless of whether they are bundled in a load unit or stored in their own load unit. It allows for hot-swapping during development and for installing updates without the need to send an entire package file. All dependencies are still explicit on a resource by resource basis. If for some reason the toolchain decides to store a particular resource now in another load unit, the bills of material need no update.

Edited by haegarr
0

Share this post


Link to post
Share on other sites


In addition, a "manager" class is a frequent symptom of poor design.

It may be a frequent symptom, but it's not necessarily an indicator or poor design. You will always need code at increasingly higher layers of abstraction to invoke lower level subsystems, manage lifetimes, glue single-responsibility code into cohesive processes, etc. A manager class would be a sign of poor design if all of the sub processes were implemented within it. It would be poor design if the manager class were also a factory, and a cache, and a process manager. But acting as a manager alone is a valid single responsibility imho. I think too often, manager classes start life as a place to own object, instead of just being process managers. Often, the objects they manage should really be owned somewhere else.

 

In the last few years I've consciously taken a bottom-up approach to design which has helped me personally to end up with systems that I actually enjoy using and re-using. I look at it like designing an API for myself, and worry about everything that backs it after the fact. If you think you've over-engineered the resource system, maybe it's because you took a top-down approach? Take a step back at look at how you would prefer to interact with your resources, and implement that bottom layer first. Maybe by the time you wrap the system you will find you don't need a manager class at all?

 

BTW optimizing your resource system for massive open worlds will optimize for lazy loading and predictive loading, flexible asset dependencies, and a cache that doesn't fragment over time. I don't think that type of engine benefits as much from large asset packages, unless loading "levels" as discrete, unique groups of assets fits into your game. It works well for TES, but the frequent loading screens do break immersion a bit.

 

If your texture asset loader is designed to be asynchronous, that requirement pretty much bubbles up all the way to your main loop. Your material loader may request textures to be loaded on its behalf, your mesh loader may request materials to be loaded, which in turn request shaders to be loaded, which in turn require a texture render target to be created, etc. In an asynchronous loading system, your asset is not fully loaded until all of its dependencies are also loaded. This buildup of asynchronicity is best implemented using Deferreds / Promises / Futures / whatever you want to call them, instead of callbacks.

2

Share this post


Link to post
Share on other sites

Thanks for the help. Do you know of any good resources explaining the basic concept of futures? Right now my resource's interface is created synchronously and stores a load state (atomically accessed of course) storing whether its loaded or unloaded. What advantages do futures/promises provide?

0

Share this post


Link to post
Share on other sites

This video is a pretty good rundown of promises and why you would want to use them.

http://www.youtube.com/watch?v=MNxnHbyzhuo

The talk is geared toward the web world, but the concepts translate into any other language. One thing to note is in the C++ standard library, a "deferred" and a "promise" are unique classes and two sides of the same coin. In other languages the term may be used interchangeably, or one or the other was chosen.

 

The main advantage of promises over using straight callbacks/lambda is you can quickly get into "callback hell" where you lose all ability to reason about the control flow of your program, and it turns into a deeply nested spaghetti mess. Promises allow you to write control flow in a way that appears like synchronous code (aka readable code), but behind that abstraction it's still asynchronous in nature.

 

If you were to switch over from your current method to promises, instead of the loaded/unloaded flag your load method would return a promise to its caller, which at some point later will be either fulfilled or rejected. The caller will handle either case. Now, inside your resource loader you may have sub-dependencies that are also loaded asynchronously. Let's say it's a material and wants 3 textures loaded, you'd want to chain something like the concurrency::when_all method to the promise you return. The promise will be fulfilled when all of the sub-dependencies are loaded. Let's say you have to attach some post-processing logic after the loading step, you can chain one or more steps using .then(). You also have the opportunity to catch any errors between any step and respond accordingly. You don't have to be compiling C++ 11 or using the concurrency runtime to do any of this either.

1

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