Advertisement

Design question.

Started by January 24, 2001 07:40 PM
1 comment, last by zel 24 years ago
Im writing a little game library for myself and maybe some friends of mine. It''s intend to be a easy library that I can use for testing various algorithms and maybe write small games. Im using pure c and directx8. Currently Im facing a design problem that I like you to help me with. The problem is how to implement a mechanism to change settings (like alpha test, color, blend settings ...) for the user. It should be easy to use and fairly efficient. I have come up with 3 different ways of doing it: 1) Have a separate function for each setting. (many functions) 2) Have a big global structure that the user fills and then call a function that handles all the state change. (Shouldn''t be that slow if one is using big vertex buffers) 3) Have a few functions that take two arguments, one is the target of the change (like diffuse color) and the other one is the value that should be assigned to the target. (The way directx8 do it) While Im asking I might as well ask another question. Right now my library shuts down whenever a error appears and open a message box displaying the error message, do you think this is good or do you have a better idea ? Remember that this library is merly intended for playing with, nothing professional. I do not claim at all to be a good programmer. I only like programming very much. Im constantly coming up with new ideas of doing things. That is what I love. Thinking. I just thought it would be nice to implement some of those stuff. I love to look at the demo section of nvidia and trying to come up with how the did that effect and how I might improve it and so. Sometimes it doesn''t work at all and sometimes it work better than you would ever imagined and sometimes a program you wrote, just simply surprises you. I wonder if the last thing isnt the most interesting. That is why I want to write the library, not because I think I can do better but simply because I want to code. Ive found that directx, win32 and even opengl code kills my inspiration, THAT is what Im trying to avoid. I need a simple little library with all of the interesting features of directx/opengl, that I can play with. The keyword of this library is Play. Any ideas, suggestions or warnings will be so helpful to me. So if you can come up with something, please post it here or mail me, I will be so thankful.
I just thought that I should explain nr 2 a bit more accurate.
I have a global structure called maybe state or something. In that structure I have many small structure, for each group of things, like one struct for alpha one for stencil, one for depth, an array of maybe 8 for textures and so on. So the user changes all that he like and then call a method preferably called settings or something.
In that function I check each member of the the global state against a local copy and only change those members that are different. I also think Its pretty efficient to have all state changes done almost at the same time since I assume those changes will block the hardware for some time. I also know that geforce drivers will batch several changes together and execute them at the same time, so this approach will probably help the drivers more than having them all over the place. My concern is that this "search" for what members have change is to slow. But since I am only going to allow large vertexbuffer, the time to execute settings may be extremly small compared to the drawing.
Another feature you could add to settings is a flags that indicates what members has changed, or at least which group of members have changed. In that case it should obviously exist a flag ALL that indicates that all groups have change that the user can use if he is lazy (Ive only seen 1 programmer thats not) or maybe at startup when you change alot of settings.zel
Advertisement
The most simple way is to keep a global Settings structure with all the setting information in it. THen if you want to can make it into a class or leave it as a strucutre, and you can add member functions to change the variables.
If you want to keep it simple, you can just assign certain functions to certain keys. FOr example, F8 could cycle through all the color settings, and F9 could cycle through the different blend settings, etc.
Another way is to have a little DOS type menu before the program runs that has a nice little menu selection goin on where the user can choose the settings before hand.
I hope thats the kinda advice you were looking for.

This topic is closed to new replies.

Advertisement