Libraries/Factories...

Started by
12 comments, last by HellRiZZer 22 years, 1 month ago
My question is: are they so useful in games? Is it worth implementing them? For example, I can use this thing:
  
class CModel : public Object
{
...
...
CMaterial m_material;
};
  
So, I know that my model will have a material. Or I can go:
  
class CModel : public OBject
{

...
...
CMaterial *GetMaterial(int Index);
CMaterial *GetMaterial(int ID);
CMaterial *GetMaterial(char *Filename);
..
};
  
In second example I can retrieve materials from library, while in first I just access in in ordinary manner. So, the question is, is it a good thing to implement libraries for materials, models, template objects etc or insert required classes where you need?(first example) Thanks all. " Do we need us? "

Ionware Productions - Games and Game Tools Development Edited by - HellRiZZer on February 17, 2002 5:28:34 PM

Advertisement
To be honest, I don''t see what you''re trying to achieve, because the 2 code examples don''t seem to do the same thing. The first example implies that each model has a single material - fair enough. The second example implies that a model is a factory that generates material classes based on an input you give it. Which makes it nothing like the first model class. Could you explain a bit more?

[ MSVC Fixes | STL | SDL | Game AI | Sockets | C++ Faq Lite | Boost ]
I think what he wanted the CModel class to do in the second code block is to retrieve a material from a seperate library.

It''s very important because you don''t want to load multiple copies of the same material should you load multiple instances of the model.

Alternatively, you could use a pointer or just a material ID and access the library using that.

  class CModel : public Object{...int MaterialID;};class CMaterialLibrary{void LoadLibrary(...);void UnloadLibrary();CMaterial GetMaterial(int id);};  
Close Darkor, but not enough.
What I meant is to have for example a CMaterial library (like CMaterialLibrary) and load all materials you gonna use in project in it and retrieve them from that single library for rendering model(CModel) textured.
Etc I wanted to ask, is it worth doing such a library, or maybe better create such libraries for materials(textures), models, scripts, etc..?

Thanks.

" Do we need us? "


Ionware Productions - Games and Game Tools Development

Close Darkor, but not enough.
What I meant is to have a library for all textures(materials) - CMaterialLibrary - which will store all materials I need in project. And I could have libraries for some other things like models, scripts, template objects etc.
So, my question - is it worth implementing such libraries or is it better to use ordinary inclusion of them(material for model)
in classes?(example one)
Thanks.

" Do we need us? "


Ionware Productions - Games and Game Tools Development

If you use your ''factory'' just to return different values depending on the parameter, then it isn''t worth it. If you use it to return different types, then it can be worth it.
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
It is useful to keep shared resources in such a central class as it means you won''t be duplicating materials or whatever. You wouldn''t need 3 different ways of accessing them though. Generally you just use the one - access via a pointer or handle/ID.

[ MSVC Fixes | STL | SDL | Game AI | Sockets | C++ Faq Lite | Boost ]
That''s exactly the thing I''m talking about, thanks Kylotan.
So, you think it might be useful in the project or not?


" Do we need us? "


Ionware Productions - Games and Game Tools Development

Probably. I know nothing about your project. Generally, the bigger the object, the more benefit you get out of sharing it.

[ MSVC Fixes | STL | SDL | Game AI | Sockets | C++ Faq Lite | Boost ]
quote:Original post by HellRiZZer
Close Darkor, but not enough.
What I meant is to have for example a CMaterial library (like CMaterialLibrary) and load all materials you gonna use in project in it and retrieve them from that single library for rendering model(CModel) textured.
Etc I wanted to ask, is it worth doing such a library, or maybe better create such libraries for materials(textures), models, scripts, etc..?


Actually, that''s what the code does, albeit it is not complete. You will need three basic classes: MaterialType, Model and Library.

It is worth doing such a library. In fact, I use libraries not only for code but for enemy types and everything.

This topic is closed to new replies.

Advertisement