• Advertisement
Sign in to follow this  

API Question

This topic is 3887 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

Hiya, The design for my next game engine has interfaces such as IFileStream, IInput, ITimer, etc. as you would expect. For example, the Input interface has an accessor GetDeltaMouseWheel(). If the input is not initialized, however, this method can't return a meaningful value. I'm not sure whether to just return 0 or false or whatever, or whether to go down the COM route and return an error code. I'll try and make it a bit clearer with some (pseudo)code.
class IInput
{
public:

    // first method
    long GetDeltaMouseWheel() const = 0;

    // second method
    enum ERROR {
        ERR_OK,
        ERR_NOTINITIALIZED
        // etc... };

    ERROR GetDeltaMouse( long &lDelta ) const = 0;

};
As far as I can see, the first method is easier to use, but the second method can potentially return more information about why the call failed to the client application. What do you prefer to use? I know it's only a small detail, but I prefer to have as much planned out as is feasible before I dive in. Many thanks for any replies [smile]

Share this post


Link to post
Share on other sites
Advertisement
Why would the input not be initialised? That should be done when you instantiate an input object, and any failure to initialise would therefore be handled at that point well before an attempt was made to call any of your input polling/processing methods.


Is it going to make any difference to the calling code why you're unable to get input? If it is, return a meaningful value of some description. If it isn't, just return null or some other sentinal value to indicate an error. Personally I would probably be inclined to return null and set an error flag elsewhere than can be checked if desired.

Share this post


Link to post
Share on other sites
Good point. I want to keep the interfaces consistent, so the methods that aren't accessors can just return true/false and set an error code.

Share this post


Link to post
Share on other sites
I would consider using the first method and let the function throw an exception if necessary.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement