usata-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Usata-commits] Changes to usata2/src/sdl/input.cpp


From: David Lau
Subject: [Usata-commits] Changes to usata2/src/sdl/input.cpp
Date: Fri, 25 Feb 2005 14:50:49 -0500

Index: usata2/src/sdl/input.cpp
diff -u usata2/src/sdl/input.cpp:1.2 usata2/src/sdl/input.cpp:1.3
--- usata2/src/sdl/input.cpp:1.2        Tue Jan 25 19:26:33 2005
+++ usata2/src/sdl/input.cpp    Fri Feb 25 19:50:48 2005
@@ -10,14 +10,16 @@
 // included in the software distribution, or visit
 // http://www.fsf.org/licenses/gpl.html.
 //
-// $Id: input.cpp,v 1.2 2005/01/25 19:26:33 skunix Exp $
+// $Id: input.cpp,v 1.3 2005/02/25 19:50:48 skunix Exp $
+
+#include <queue>
 
 #include "../input-system.hpp"
 #include <SDL.h>
 #include <vector>
-
 #include "../log.hpp"
 
+
 namespace usata { namespace input{
 namespace {
 
@@ -56,130 +58,71 @@
        return retval;
 };
 
-
-class SDLDriver: public input::Driver
+class SDLDriver : public input::Driver
 {
-
-       bool mKbEnabled,
-                mMouseEnabled,
-                mJoystickEnabled;
-
-       SDL_Event mSDL_ev;
-
-               Event* key_process();
-
+       std::queue<input::Event*> mEventQueue;
        public:
                SDLDriver();
-               virtual void update(){}
-               virtual void configure ();
-               virtual bool supports(DeviceType type);
-               virtual bool enable(DeviceType type, bool);     
-               Event* process();
+               virtual ~SDLDriver();
                virtual Event* next();
-
+               Event* process(SDL_Event&);
+               virtual void update();
 };
 
 SDLDriver::SDLDriver()
-:      input::Driver("sdl"),
-       mKbEnabled(true),
-       mMouseEnabled(true),
-       mJoystickEnabled(true)
+: input::Driver("SDL")
 {
-       log::BufferedStream lb;
-
-       lb << "size of conv: " << sizeof(key_conversion)/sizeof(SDL2Usata) << 
log::commit;
 
 }
 
-bool
-SDLDriver::supports(DeviceType dt)
+SDLDriver::~SDLDriver()
 {
-       return true;
-};
-bool
-SDLDriver::enable(DeviceType type, bool e)
-{
-       bool retval = false;
-       switch (type)
-       {
-               case KEYBOARD:
-               case JOYSTICK:
-               case MOUSE:             
-                       break;
-               default:
-                       break;
-       }
-       return retval;
-
 }
 
-void
-SDLDriver::configure()
+Event*
+SDLDriver::next()
 {
-
-
-       return;
+       Event*retval=0;
+       if (mEventQueue.empty())
+               return retval;
+       retval = mEventQueue.front();
+       mEventQueue.pop();              
+       return retval;
 }
 
 Event*
-SDLDriver::process()
+SDLDriver::process(SDL_Event&ev)
 {
        
-       switch (mSDL_ev.type)
+       switch (ev.type)
        {
                case SDL_KEYDOWN:
                case SDL_KEYUP:
-                       return key_process();
+//                     return key_process();
                        break;
                case SDL_QUIT:
                        return new SystemEvent(SystemEvent::QUIT);      
                        break;
 
        };
-       
-
        return 0;
 }
 
-Event*
-SDLDriver::key_process()
-{
-       Event*retval;
-       bool state=false;
-       if (mSDL_ev.type == SDL_KEYDOWN)
-               state=true;
-
-       int key = key_convert(mSDL_ev.key.keysym.sym);          
-
-       retval = new KeyEvent(key, state);
-
-       return retval;
-};
-
-Event*
-SDLDriver::next()
+void
+SDLDriver::update()
 {
-       Event*retval(0);
+       SDL_Event ev;
        
-       while (1)
+       while (SDL_PollEvent(&ev))
        {
-               if (!SDL_PollEvent(&mSDL_ev))
-                       break;
-
-               retval = process();
-               if (retval)
-                       break;
-       }       
-
+               Event* uev= process(ev);
+               if (uev)
+                       mEventQueue.push(uev);
+       }
 
-       return retval;
+       return;
 }
-
-
-
-
 }
-
 Driver * default_driver()
 {
 




reply via email to

[Prev in Thread] Current Thread [Next in Thread]