Skip to main content
gamedev.net
🔒 Locked

ResourceMng

Started by Austrian Coder Apr 24, 2004 at 7:22 PM 0 replies 700+ views
Original Post
Austrian Coder
Austrian Coder
Hi people. I have here a nice running resource manager, but i need an improvement. class CSoundFile : public IResource { friend class CSoundSystem; public: ... void Load() { gSoundSystem->Load(this, m_Name); } }; bool CSoundSystem::Load(CSoundFile* SoundFile, std::string Filename); So if i call Load() of a CSoundFile object the CSoundFile will use the gSoundSystem to load itselve. Ok... nice thing, but i need an way to support different parameters for different resource objects. Lets have a look at the CSoundFile. So here we can add a paramter for streaming or is3dsound (bool Is3DSound, bool StreamIt). Every IResource base class has a setup function: void Setup(String Filename, CacheType CType) { // only if the resource is not loaded if (!m_IsLoaded) { m_Name = Filename; m_CacheType = CType; m_Id = GetNextID(); } } So here is an example from the usage of the ResourceMng. gSoundSystem->Init(DirectSound); ResMng.RegisterResource("ding.ogg", RT_MUSIC); ResMng.RegisterResource("test.ogg", RT_MUSIC); ResMng.LoadResources(); But now i want that text.ogg is streamed, because it is sooo big. So how can i support such parameters? I thougt in the function RegisterResource, but the problem is, that every IResource based class can have different numbers of parameters.
Jan Wassenberg
Jan Wassenberg
Alright, for what it''s worth, here''s how my system works. It''s gonna be no use to you at all, because it is a OO-C kind of story, but hey, maybe it''ll lead to an idea.

A central handle manager allocates fixed size control blocks, which hold all information about a given resource instance (e.g. pointer to texture data). These are referenced via handles; this guards against double-free, type misuse (can''t use a texture as a sound), and use-after-free. Macro magic makes sure a given resource type fits within the space allotted, even though the handle manager knows nothing about the resource types.

A resource type is defined by a pointer to its vtbl (created via macro). There are functions (analogy: virtual functions of IResource) for (re)loading (if the file changes, or console reload_file command); also ctor and dtor. A macro defines a type symbol and also initializes the vtbl.

Each module that provides a resource type (e.g. sound.cpp) has a layer of functions snd_load(filename, extra sound-specific params). They call h_alloc, passing the type (i.e. pointer to vtbl), and here''s where the fun starts: the extra parameters are stored, via stdargs. The handle is allocated etc., then h_alloc calls back into the resource type''s ctor and reload routines, passing the resource-specific parameters.

So, in short, my answer to the problem: variable parameter functions.

HTH.
E8 17 00 42 CE DC D2 DC E4 EA C4 40 CA DA C2 D8 CC 40 CA D0 E8 40E0 CA CA 96 5B B0 16 50 D7 D4 02 B2 02 86 E2 CD 21 58 48 79 F2 C3

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.