Tuesday, June 21, 2011

Project Demo, Part 2

As I said before, I wanted to do a quick implementation of the base program design. Of course, since we started from a fairly high level of abstraction, getting it down to code requires making several decisions, and it's always best to document these somewhere other than the code base.

For starters, the program is contained in a Game class. I created a Layer base class, and Layer classes for each layer. The Game class holds one of each layer; Application, Resource and Engine. I also created an Interface base class, from which all the interfaces inherit. Something I'm not happy with is the names I gave them. The Resource Interface in the Application Layer is not the same as the Resource Interface in the Engine layer. This means that for N number of layers, I could have up to N*N-1 kinds of interfaces. This may be excessive, since not all Layers are connected to all others (Engine is only connected to Resource, for example). However, it still requires a multitude of classes. I may eventually figure a solution to this, but for now it should be enough for my purposes.

 Design grows more detailed as I try to implement it

I spoke a great deal about 'connecting' the different layers, and communications between them. This, unfortunately, cannot be done from within the class. I can't have an internal 'link to layer' method in the Interface class, since it doesn't know about anything outside itself. Instead, to link two layers together, the containing structure (Game in this case) has to pass each a pointer to the other. I could have a method in the Layer itself that links the contained interface to a pointer given to it, though.

To support this, I've given the Interface base class an Interface pointer called link. I also gave Interface a method, 'LinkTo(Interface*)' that takes a pointer to an interface and links the interface to it. On the Layer base class, I created another method that takes an Interface and a pointer to an interface, and calls the LinkTo method in the Interface with the pointer as a parameter.

Now I need a method to ask each Layer the address of their interfaces, so that other layers can link to them. I want to keep this general, so I don't have to write one method for each Layer, but in order to make it part of the Layer class Layer must know what interfaces the layer will ultimately have, which is something known by the derived classes. The problem is the number of interfaces is variable. Let such a method be called "GetInterface". It would have to return an array of some kind with all the Interfaces the Layer has. Then the calling code would have to determine which interface should connect where.

I could hack some brute force, "this goes here" sort of code, where I manually link each pair of interfaces, but that isn't elegant. Part of the problem goes back to what I didn't like about my interface code before; I'm making too many derived classes. This will require some more thinking.

In the meantime, I'll move over to other issues I have dealt with.

I included a Resource* vector in the Manager base class. If any of the managers ever need a different kind of storage, I'll think of something. Something else I decided on was to create a simple 'vertex list' file format to store simple models in. This is going to help avoid cluttering the code with hard coded models, and the infrastructure required to read one kind of file type can easily be extended to read others.

 Sample tvl (Text Vertex List) file

The standard for the file will be simple. The file is going to be text based. The file header will contain, first, the file version (starting at 1.0). This is so that if I change the format in the future, I don't have to scrap the files I may already be using. It's also just good form to version file formats. In the next line, the number of vertices contained in the file. In the next line, and for every line afterwards, the x, y and z values of the vertex, separated by white space, followed by the x, y and z values of the normal at each point, followed by the u, v values of the texture coordinates. The format will permit comments in lines that start with '#'. All values are mandatory, and upon finding a malformed line the file will stop being read.

This should help with testing, once everything else is working.

No comments:

Post a Comment