last day (15 days later) » 

11:29 PM
it works!
 
hey
 
ok, my guess is that you have two classes in your program related to this problem, right?
one will be the mouse handling class
 
Yeh, but I don't know if it's gonna work
 
and another one will be the one that actually uses the mouse values
 
11:31 PM
and the "worker" one contains a reference to the "mouse" one, right?
 
the what?
 
sorry, I don't know the names of your classes so I've made them up
 
MouseListener and InputHandler
 
and what do they do, exactly?
 
InputHandler handles keyboard events and mouse events and any other events thereof; MouseListener I dunno coz you suggested it
 
11:34 PM
oh, MouseListener is my abstract class!
but do you have a class that actually "uses" the values from the mouse?
 
I do it in my Application class for now; it's done in the handleInput() function which checks to see if an event occurs
 
so handleInput() calls directly to the Application class?
 
No, it's a function that's part of the class. It would be in this function that InputHandler uses its functions like isMouseButtonPushed { // do something } etc
 
hmmm, I don't see it very clearly, but I think that Application and InputHandler are a bit mixed up...
 
should I also mention the Camera class that needs the location of the mouse? :D
 
11:41 PM
oh, certainly
 
Suffice it to say that I want inputHandler to be separate from the rest of my project, in case I need to reuse it for other projects. The same applies to the Camera class.
 
can we assume that the Camera class is the only place where the mouse location is actually used?
 
Yes, let's assume that
 
you have two options here...
you Camera class can be a class designed to follow the mouse position, or it can be a generic Camera class, not directly related to the mouse, just used with the mouse in this application
 
i prefer the latter
 
11:44 PM
Ok, then you have 3 classes:
InputHandler handles the messages
Camera handles the camera
Application puts all together
right?
 
yep, that's it
 
my idea is then that Application impllements the MouseListener abstract class
and InputHandler holds a MouseListener*
 
but then it wouldn't be abstract anymore?
 
MouseListener is abstract. Its implementations are not, obviously, or you will not be able to use it at all!
 
abstract class means i can't use it other than inheriting from it
 
11:48 PM
not exactly, abstract class means that you cannot create instances of this class, but you can have pointers or references
 
true! so how shall i implement the MouseListener class?
 
these pointers or references will always refer to instances of subclasses of the abstract class
something along the lines of:
class Application: MouseListener
{
    virtual void OnMouseMove(int x, int y)
    {
        m_camera->SetPosition(x, y);
    }
};
the same with the other abstract functions
 
hmm, i think i see what you mean
 
I'm assuming that Application holds a reference to the Camera
 
then what happens in the INputHandler class?
 
11:51 PM
something along the lines of:
class InputHandler
{
public:
    InputHandler(MouseListener *ml)
    :m_mouseListener(ml)
    {}
    void DoEvents()
    {
        while(SDL_PollEvent(&event))
        {
            switch (event.type)
            {
                case SDL_MOUSEMOTION:
                    m_mouseListener->OnMouseMove(event.motion.x, event.motion.y);
                    break;
            }
        }
    }

private:
    MouseListener *m_mouseListener;
};
and so on with the other events and even an eventual KeyboardListener
 
hmm, ok
 
as you see the InputHandler is completely reusable and replaceable
and there is no need for booleans anywhere
 
true, though i've never programmed this way before. I've always found booleans satisfying heretofore
 
those are what I call control variables and are the modern version of the goto. IMO they should be avoided, if possible
 
what should be avoided?
 
11:57 PM
using boolean control variables
 
so i shouldn't have a, say, isMouseMoved() function?
 
those are boolean variables that do not represent a boolean concept, but a piece of code that should or shouldn't be executed
generally speaking, no
is moved relative to what?
 

  last day (15 days later) »