Sign in to follow this  

Another design hiccup

This topic is 4356 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Let me just explain a little: Everything is written in C++. I have an Engine class, a VideoDriver class (opengl currently), and a SceneGraph class. I also have a ReadFile class that holds an open file pointer to a file and I just wrote a FileSystem class that will return ReadFile objects to files, but if the path it is passed it not valid, it will also search a bunch of default directories. Most of the objects I have right now (milkshape model, md2 model), get passed an open ReadFile object on their creation so they can load themselves. But, if the model class is loading a texture and gets the path (or an absolute path) from the model file (milkshape, I'm looking at you), it won't load as the path will be incorrect because someone who is a lot more talented than me create the model. Now to the problem. I want each class to be able to access the FileSystem (through a pointer probably), but the problem is that each scene object (of which the model objects are derived from) have a pointer to the scene manager, which has a pointer to the video driver, but I can't see the file system having a place anywhere apart from inside the Engine class. And the scene object can't currently access that. I'm not going to add access for the scene objects to access the Engine class just for something like this, and I also want to avoid having the file system passed in as another constructor param. So, I'm a little stuck on proper design.

Share this post


Link to post
Share on other sites
Global?

No, no, not kidding. It's a filesystem class! Most languages have this sort of thing publically visible out of the box. A singleton [a search will likely lead to a bevy of arguments and a few good links] also would likely be appropriate depending on the filesystem class; as much as I dislike it in almost every other case.

Share this post


Link to post
Share on other sites
Let me suggest some alternatives.

First, you could separate the resources from the file system (or however they get loaded). In other words, loading is not done by the resource, it is done by a resource manager/factory. That simplifies the code and the interface for the resource. Then the scene manager goes to the resource manager to get any resources.

You could also separate the loaded resources from the scene manager. That is, a separate scene object is constructed from a resource. I'm not sure of the benefit, but it is something to consider.

The advantage of separating the classes in this manner is that it reduces dependencies and coupling, which is what you describe as the problem. The disadvantage is that the overall system becomes bigger.

Second (but related to the first), a system that loads data via dispatch might work better than a system that loads by demand. In this system, you load a single file that contains several objects. Each object has an identifier that tells what kind of object it is and what its name is. The loader reads the data for the resource into memory and then calls the function that is associated with that kind of resource (a factory). Generally, any resources needed by the resource being constructed are required to have been already loaded, but not always. The fully loaded and constructed resource is finally handed to the scene manager.

I guess the commonality between these is that the resource is fully loaded and constructed before being given to the scene manager.

Share this post


Link to post
Share on other sites
I suppose that have a resource class seperate from the scene node makes it easier when you have to load a single model file more than once, they can all use the same resouce, which can save on memory.

Also, now I'm loading and creating the scene node in the same step as it were (using the constructor to call the load function). So, even if I get a message saying that the model could not be loaded an essentially useless scene node gets inserted into the scene graph. If we seperated the loading and creation of the scene node, we would know if the resource was invalid before inserting it into the scene graph.

The problem is that I see what you are suggesting as no small update. I've actually already have one of the things that you suggested already written down for the next iteration of my engine. But it seems to be overkill at the moment.

Share this post


Link to post
Share on other sites
Quote:
Original post by Endar
The problem is that I see what you are suggesting as no small update. I've actually already have one of the things that you suggested already written down for the next iteration of my engine. But it seems to be overkill at the moment.

No problem. Getting the current iteration working first is a smart goal. In that case, I would agree with Telastyn: make the FileSystem object a global (perhaps a Singleton).

Share this post


Link to post
Share on other sites

This topic is 4356 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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