• 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

A Resource manager design.

2 posts in this topic

Hello!, i'm trying to design my own resource/asset manager for my own game engine. I would like feedbacks or any opinion on how may i improve it. The design is:

IResourceLocator: A class that represent a place where to look for the files.
Examples: FileLocator, ZipLocator, UrlLocator.

Code: https://github.com/Ghrum/Ghrum/blob/master/include/Resource/IResourceLocator.hpp
Example Code: https://github.com/Ghrum/Ghrum/blob/master/include/Resource/Locator/File/FileResourceLocator.hpp

IResourceLoader: A class that define how an resource is loaded.
Examples: ImageLoader, AudioMP3Loader, AudioOGGLoader.

Code: https://github.com/Ghrum/Ghrum/blob/master/include/Resource/IResourceLoader.hpp

IResourceCache: A class that define how is the resource stored.
Example: WeakReferenceCache, ContignousMemoryCache.

Code: https://github.com/Ghrum/Ghrum/blob/master/include/Resource/IResourceCache.hpp

And finally the resource manager that keeps track of every IResourceLocator, IResourceLoader and IResourceCache. Each module is comunicated using a ResourceKey that contain the name and file of the resource.

Code: https://github.com/Ghrum/Ghrum/blob/master/include/Resource/IResourceManager.hpp

An example of usage:

void onInitialization(IResourceManager & manager)
    manager.registerLocator<FileLocator>("." + PATH_SEPARATOR + "cache");
    manager.registerLocator<ZipLocator>("." + PATH_SEPARATOR + "data" + PATH_SEPARATOR + "textures.zip");
    manager.registerLoader<ImageLocator>("png", "jpg", "jpeg");

void onSomethingElse(IResourceManager & manager)
   auto & resource = manager.getResource<Image>("texture.png");

Any feedback or tip will be appreciated.


Share this post

Link to post
Share on other sites

I recently finished my Resource Module as well, I'm going to post the design here so you can get your own thoughts of it.

It's very similar to yours too.


Resource Classes:

First, I have these [Basic Types]: MeshClass, MaterialClass, TextureClass, and anything else that I might add.

They contain only the resource data of how a Mesh if defined, the values of a Material, the Texture image, etc


Then I have the [Info Types]: ImageClass, ModelClass, and still adding new stuff.

These don't contain any data except the IDs/Names of what compose a Image or a Model.


Each one of the above have their own functions to load and save their data.

So I can create new Texture objects from BMPs, PNGs or anything else, and I save them in a format of my own.


And finally, the actual resource classes of: SpriteImage, Model, etc

An Image has an imageClass variable that describes what composes it: a TextureClass, a Material and a Canvas.


Resource Cache:

This class accepts any template, gives it an int for ID and a string for name, and puts it in a vector.

Actually I have two vectors in this one, one for headers, another one for objects.


When I open a resource file in my format from, I read only the headers and save them in the vector.

Then when a resource is requested, I'm surely to return a pointer to the resource, and I go through these steps:

- First, look in the loadedResources vector. If the requested ID/name is already there, return it.

- If not, look in the headerResources vector. I'll find the header based on ID/name, if not I'll throw an error to my error module and return 0;

- If I found the header, I'll create a new object of the requested type, call it's LoadFromResource() function, add to my loadedResources vector, and return it's pointer.


I also left an AddResource() function if I want to load outside the resource manager for some (weird) reason, so it can start to manage it.


It'll free the memory/destroy the objects when it goes out of scope, so I don't have about leaks (I just have to properly delete stuff I allocated in these objects).


Also, this class has a Save() function that will loop through all loaded objects and save it to a file by calling each of the object's SaveToResource() function.

This is so I can get a single file with all resources of the same type, organized with headers, for easier loading the next time.

It also have the Load() (obviously) to accompany it...


Resource Manager:

Then I have this Resources class that has a bunch of template functions, and it's the class that knows how to load each type of resource.


For example, when I call Resources.Load<Image>("imageName"); it'll need to know how an image is loaded:

- First, look in the ResourceCache<ImageClass> to get that particular image's texture, material and canvas size.

- Then load every one of the resources that compose it from the other (Basic Types) ResourceCaches: Texture, Material, Canvas (this one actually I don't keep track, I create a new one everytime a new image is loaded so I can change it without worrying about messing with other images).


I had a hard time coming up with something to handle composite resources, and that's what I came up with.

For example, I might want to have two of the same 3D Model but with a different texture each, so I also had to keep track of each of these models remembering which texture/mesh they had.


For the case that I want a new copy of something that will be changed (such as material), I just create a new one in the Resources's Load function:

template <> Image* Load(int imageID)
    Image* image = new Image();
    image->_imageInfo = _imageInfoVector.GetResource(imageID);
    //imageInfo contains everything about this image
    if(image->_imageInfo != 0)
        image->Texture = _textures.GetResource(image->_imageInfo.textureID);
        //Texture shares the same pointer since I won't change them per image
        image->Material = new Material(_materials.GetResource(image->_imageInfo.materialID));
        //But I will for the material, so I create a new one, and I copy it through a constructor overload
        //So I can change this image's material without it affecting any other images
        //Whatever else my image will have
   return image;

Hope this help give you some ideas on how to design yours.


Thank you, that gave me a lots of ideas on how could i improve my design.


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