Interfaces

Everything related to the code /
Tout ce qui touche au code
Post Reply
User avatar
Cire
Moderator
Posts: 350
Joined: Tue Oct 31, 2006 5:59 pm
Location: Somewhere on Earth

Interfaces

Post by Cire » Tue Dec 19, 2006 5:00 am

I would like to see a class written that will take all our gfx commands for the most part and wrap them around a class.

Such functions would be putText, LoadTex ect, most of these exists outside in various .h/cpp files right now, wrapping them within a class will make it easier for us to reuse code, as well as add various handlers later.

It will also enable us to create a 'interface' class. What this class will do is let other classes add themselves to the interface, the interface then in turn can invoke methods in these classes. This will make it extremely easy for us to handle certain events, suppose for example that the user typed +atm. now rather then us having to process each line for 'useable' commands and what not we siimply send it to the interface class, the interface class then invokes methods in all other classes untill it gets procced, so suppose ther interface class had these classes like this.
Engine Interface
GFX Interface
Network Interface
Sound/Music Interface
AI Interface
Player Interface
Console Interface
ect.

Now suppose that the + at the start of atm is something that we said is for 'signal/skirmish' commands only, and thus disabled if its a multi-player game. so the engine interface recives user input and says I don't care about user input, and returns 0 (not handled), GFX looks at it and says nope I don't care about that, and returns 0, now it gets interesting.

Network looks at it and 1) If its a multi-player game simply sets a output message to be shown to user that they can't use cheat commands while game is a multi-player game, or 2) if its not a multiplayer game returns 0, not handled yet again. it keeps going down the chain till it gets to the player interface which sees +atm and says ok he wants 1000 more metal and adds it to his totals, and so on.

This can also be key for many many many different events and will make things extremely useful. Now on the downside it will require that certain member functions be added to all other classes, but we can get around that by requring each of these interfaces to be derrived from a 'interface' class which would contain base code for all events that we would like to handle.


If you think about it for just alittle bit you will see how extremely useful this can be, for example, sound/music class coudl notify that a new song is being played, gfx or console could then pick this up and display it to the screen, sure sound music could do that itself, but why add code to show a line of text in 20 thousand different places. Why should sound/msuci class for example have to look up if it should show a new music notification in output and then gfx routines to draw the text, be much more intellgent to invoke a event, and each class with a interface then has a chance to react upon it.

Some decessions need to be made however, should events be stopped the minute they are handled by 1 interface, or traverse through all interfaces, and so on.

I realize that this takes more 'startup' code at first, but once in play it requires very little code to do a big thing, plus because all interface code will be derrived from a interface class we are not replicating code and thus the code page will be very small.

Questions?

++Cire.

User avatar
zuzuf
Administrateur - Site Admin
Posts: 3281
Joined: Mon Oct 30, 2006 8:49 pm
Location: Toulouse, France
Contact:

Post by zuzuf » Tue Dec 19, 2006 6:06 pm

Ok, that's a good idea, a class per functionality and an interface between all these to handle events. But we won't start to code this now since we will release a Christmas version of TA3D which should be as stable as possible from what we currently have. But we can discuss that, it's interesting and it will be the core of the comuniation system in TA3D so we must do things carefully here.
=>;-D Penguin Powered

Post Reply

Who is online

Users browsing this forum: No registered users and 25 guests