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

Clean architecture for an asset loader in a component based framework?

6 posts in this topic

I've been doing a lot of reading about how a loader should be handled on the forums, and I feel like I'm on information overload. I've read that it's better to have separate loaders for different assets such as having a texture, mesh, shader, etc, loaders all separate, but I've also seen some examples where the different components are grouped together so that a class loads the file, then the different components figure out what to do with file when it's loaded in. I also need a way to store the information depending on how it's going to be used. I saw an example I'd like to implement where there are 3 memory blocks, one for data needed every frame, one for data needed every block, and one for constant data.

My basic design goals for the framework are as follows:
I'm only worried about having it work on windows
I want to stream in world blocks to have a straight continuous level with branches
I want to have flexibility to experiment with shaders

So my first issue to tackle is how to handle the loading of assets and storing them into the different blocks of memory. Some insight into the pros and cons of different methods would be greatly appreciated. Software design and architecture is really hard for me, and I'd like all the information I can get.
0

Share this post


Link to post
Share on other sites
At its core, this should boil down to a very simple API:

[code]void LoadAsset(some_identifier, std::vector<char>& memorybuffer);[/code]

(Assuming C++; translate to the appropriate language of your choice.)

Your high level code asks for some data and provides a blob of memory to store it in, and the low-level asset loader just fetches the data and blindly stuffs it into the buffer.

Of course you can fancy this up all kinds of ways, but that's the basic principle. It's so simple that it doesn't even require a class (again assuming a language that supports free functions) and provides convenient decoupling of the asset-loading infrastructure from the logic that actually consumes assets.
0

Share this post


Link to post
Share on other sites
[quote name='ApochPiQ' timestamp='1334965325' post='4933396']
At its core, this should boil down to a very simple API:

[code]void LoadAsset(some_identifier, std::vector<char>& memorybuffer);[/code]

(Assuming C++; translate to the appropriate language of your choice.)

Your high level code asks for some data and provides a blob of memory to store it in, and the low-level asset loader just fetches the data and blindly stuffs it into the buffer.

Of course you can fancy this up all kinds of ways, but that's the basic principle. It's so simple that it doesn't even require a class (again assuming a language that supports free functions) and provides convenient decoupling of the asset-loading infrastructure from the logic that actually consumes assets.
[/quote]

Ok, that makes sense, so the texture or whatever loader will call the function that provides a file handle then determine what to do with the blob that's loaded in? Now in a component based engine, what's a good way to couple what's being stored and how it's being used? I get that a component based system will have lists that you store different properties into, but how do you group them together logically so that it's relatively easy to determine which properties belong to say the main character? I was thinking loading them into the lists first based on the world information with a tag, then a high level object will then search for the property that matches it's tag during the level initialization. Am I going in the right direction?

Edit: Actually, I'm having trouble seeing how a single function will work. For example, with a file that has vertex info, you need to parse it to get the coordinates out of it. But with something like a texture, I know D3D has it's own function for opening the file and storing the data in it. How do I make the single function work for both instances?
0

Share this post


Link to post
Share on other sites
Generally the way component systems manage groups of related components is with [i]systems[/i]. A system is just a collection of containers for components that belong to a related group.

That sounds really vague now that I read it to myself, so here's an example:

[code]class HealthComponent { /* blah */ };
class WeaponComponent { /* blah */ };
class AnimatedComponent { /* blah */ };

class CharacterSystem
{
std::vector<std::shared_ptr<HealthComponent>> HealthComponents;
std::vector<std::shared_ptr<WeaponComponent>> WeaponComponents;
std::vector<std::shared_ptr<AnimatedComponent>> AnimatedComponents;
};[/code]


You define a system for groups of related components, in this case, characters. A character in our little example consists of a health component, a weapon component, and a component that manages the animations of the character (and presumably does rendering/etc.).

There are two kinds of data loading to consider. One is loading "static" data - levels, maps, models, etc. The other is loading "dynamic" data, i.e. save games, replays, etc.

Static data usually looks like this:

[code]std::vector<char> buffer;
LoadAsset("asset_foo", buffer);
TheSystem.AddComponent(FooComponent::ParseData(buffer));[/code]

Where the buffer contains the raw asset, and the FooComponent knows how to parse that into the appropriate stuff.

Dynamic data is basically the same, but instead you tag each buffer with what [i]kind[/i] of component it is, so you can hand off to the right factory:


[code]std::vector<char> buffer;
LoadAsset("savegame", buffer);
std::string tag = ReadTag(buffer);
if(tag == "foo")
TheSystem.AddComponent(FooComponent::ParseData(buffer));[/code]
0

Share this post


Link to post
Share on other sites
Oh, ok I get it now. Thanks so much for your help. Do you have any links on this kind of stuff where I can do a little research on my own?
0

Share this post


Link to post
Share on other sites
Check out [url="http://www.gdcvault.com/play/1014573/Creating-Your-Building-Blocks-Modular"]this presentation from the 2011 GDC AI Summit[/url]. It's got a pretty good breakdown of how to do component systems; it focuses on AI but it's applicable to general architecture across the board.
0

Share this post


Link to post
Share on other sites
Actually I just have 1 more question, what's the best way to handle loading assets that are normally imported with a library? Like loading a .dds file with directx? It doesn't fit loading the contents of the file into a buffer to be parsed later right?

Edit: Never mind, I see directx has a createshaderresourcefrommemory function. I'm all set, thanks again.

Edit2: Well, now that I think about it, my point still stands. It seems like things like textures and levels/models are read in completely different ways. Can you really load static data all the same way? It seems like levels/models are parsed and stored as they're being read, but things like textures are either read by a library or directly copied into the buffer. Am I just forced to make separate loaders in this instance? The only real experience I've had to deal with loading is either using an already provided function to do so, or just parsing a text file and converting the strings into data.
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