class mySDL
{
private:
myVideo m_vVideo;
myEvents m_vEvents;
...
public:
//constructor/destructor stuff
myError OpenWindow(window size, etc...){myVideo.OpenWindow(window size, etc...)};
};
🔒 Locked
SDL wrapper
Advertisement
Original Post
I am trying to wrap SDL to make my code a bit more organized. Right now I have one class that I would like to be the interface for all of the SDL calls I use, and that class uses others.
I have it broken down into my main SDL class, and under that I have a Video class, a Sound class, an Input class etc. etc.
I am not currently inheriting anything so my function calls look somthing like this...
mySDL.h
And then the same kind of calls for polling events etc.
I''m wondering if I should inherit and make those pure virtual functions, or if I should just do it the way I am now (or not do it at all!).
I''m not inheriting because I feel like that shouild be reserved for more losely related classes, or like all the examples I''ve seen about the animal -> mammal -> dog kind of inheritance.
Am I wrong in this kind of thinking?
Hope is the first step on the road to disappointment
I was also wondering about SDL_EnableKeyRepeat(). I have set it to the defaults but it doesn''t seem to be repeating at all. I even tried setting it to SDL_EnableKeyRepeat(1, 1), still no key repeating.
Right now I''m looking for the key down event to see if it repeats. Am I wrong to assume it calls another keydown event when it repeats?
Hope is the first step on the road to disappointment
Right now I''m looking for the key down event to see if it repeats. Am I wrong to assume it calls another keydown event when it repeats?
Hope is the first step on the road to disappointment
quote:
Original post by honny
"I have set it to the defaults "
have you used the sdl flags ?
SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY , SDL_DEFAULT_REPEAT_INTERVAL);
with me its working fine.
That is exactly what I tried. Does holding down the key trigger new KEYDOWN events?
Hope is the first step on the road to disappointment
i dont know exactly what you need to do, anyway remember that sdl receive messages until it die, so u must manually capture events.
usually with sdl u check events in the MAIN LOOP OF THE GAME.
So u must use poll/punp events to update the state of events and use a function to check what happened(key pressed ? mouse moved ?...)
maybe u check events outside of the main loop and so your state events its not updated.
hope this can help ya.
good luck for ur wrapper.
usually with sdl u check events in the MAIN LOOP OF THE GAME.
So u must use poll/punp events to update the state of events and use a function to check what happened(key pressed ? mouse moved ?...)
maybe u check events outside of the main loop and so your state events its not updated.
hope this can help ya.
good luck for ur wrapper.
/******************************/
//this function return 1 if esc is pressed
/******************************/
int test_event(SDL_Event event)
{
int uscita=0;
if (event.key.keysym.sym==SDLK_ESCAPE ){ uscita=-1;}
if (event.key.keysym.sym==SDLK_A_KEY_U_NEED_TO_CHECK ){//do appropriate stuff};
return uscita;
}
/*******************************/
//in main
/*******************************/
.
.
.
SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY , SDL_DEFAULT_REPEAT_INTERVAL);
.
.
done=0;
//this must be the main loop of the game
while (done>=0)
{
/**/
//here draw an ogl scene for example
/**/
while (SDL_PollEvent(&event)) {done=test_event(event);};
};
I have the SDL event routines in a class. I have a PollEvent member function that returns a vector of SDL_PollEvent(&kEvent), and the SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY , SDL_DEFAULT_REPEAT_INTERVAL);
is in the class constructor. here is part of the .cpp of that class.
And in my main function is where I cycle through the vector handling events and then clear it.
is in the class constructor. here is part of the .cpp of that class.
//Default Constructor
myInput::myInput(void)
{
SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL);
}
//Default Destructor
myInput::~myInput(void)
{
}
//Poll Events
vector<SDL_Event> myInput::PollEvents(void)
{
SDL_Event kEvent;
vector<SDL_Event> vEvent;
while (SDL_PollEvent(&kEvent))
{
vEvent.push_back(kEvent);
}
return vEvent;
}
And in my main function is where I cycle through the vector handling events and then clear it.
You need to set keyboard options (both the Unicode translation if you want it and key repeat) _after_ you call SDL_SetVideoMode().
Note: If you want to test the down-state of keys, you shouldn''t use key repeats. Use SDL_GetKeyState() instead, it returns an array of key-down states.
cu,
Prefect
Note: If you want to test the down-state of keys, you shouldn''t use key repeats. Use SDL_GetKeyState() instead, it returns an array of key-down states.
cu,
Prefect
Topic Locked
This topic has been locked by a moderator. New replies are not allowed.
Sign in to reply to this topic.
Advertisement