pingus-cvs
[Top][All Lists]
Advanced

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

[Pingus-CVS] r3062 - in trunk/pingus: data/controller src src/input src/


From: grumbel at BerliOS
Subject: [Pingus-CVS] r3062 - in trunk/pingus: data/controller src src/input src/worldmap
Date: Sun, 2 Sep 2007 06:29:06 +0200

Author: grumbel
Date: 2007-09-02 06:29:05 +0200 (Sun, 02 Sep 2007)
New Revision: 3062

Added:
   trunk/pingus/src/input/
   trunk/pingus/src/input/SConstruct
   trunk/pingus/src/input/control.hpp
   trunk/pingus/src/input/controller.cpp
   trunk/pingus/src/input/controller.hpp
   trunk/pingus/src/input/controller_description.cpp
   trunk/pingus/src/input/controller_description.hpp
   trunk/pingus/src/input/core_driver.cpp
   trunk/pingus/src/input/core_driver.hpp
   trunk/pingus/src/input/driver.hpp
   trunk/pingus/src/input/event.hpp
   trunk/pingus/src/input/main.cpp
   trunk/pingus/src/input/manager.cpp
   trunk/pingus/src/input/manager.hpp
   trunk/pingus/src/input/sdl_driver.cpp
   trunk/pingus/src/input/sdl_driver.hpp
   trunk/pingus/src/input/usbmouse_driver.cpp
   trunk/pingus/src/input/usbmouse_driver.hpp
   trunk/pingus/src/input/wiimote.cpp
   trunk/pingus/src/input/wiimote.hpp
   trunk/pingus/src/input/wiimote_driver.cpp
   trunk/pingus/src/input/wiimote_driver.hpp
Modified:
   trunk/pingus/data/controller/default.scm
   trunk/pingus/src/font_test_screen.cpp
   trunk/pingus/src/worldmap/level_dot.cpp
Log:
- input2/ renamed to input/ and hooked up in the code

Modified: trunk/pingus/data/controller/default.scm
===================================================================
--- trunk/pingus/data/controller/default.scm    2007-09-02 04:26:33 UTC (rev 
3061)
+++ trunk/pingus/data/controller/default.scm    2007-09-02 04:29:05 UTC (rev 
3062)
@@ -1,72 +1,67 @@
 (pingus-controller
   (standard-pointer
-    (mouse-pointer ))
+    (sdl:mouse-pointer))
 
   (primary-button
-    (mouse-button
-      (button 1)))
+    (sdl:mouse-button (button 1)))
 
   (secondary-button
-    (mouse-button
-      (button 3)))
+    (sdl:mouse-button (button 3)))
 
   (pause-button
-    (key-button
-      (key "p")))
+   (sdl:keyboard-button (key "p")))
 
   (fast-forward-button
-    (multiple-button
-      (key-button
-        (key "f"))
-      (key-button
-        (key "space"))))
+   (sdl:keyboard-button (key "f"))
+   (sdl:keyboard-button (key "space")))
 
   (armageddon-button
-    (key-button
-      (key "a")))
+    (sdl:keyboard-button (key "a")))
 
   (escape-button
-    (key-button
-      (key "escape")))
+    (sdl:keyboard-button (key "escape")))
 
-  (scroller
-    (axis-scroller
-      (speed 1000)
-      (button-axis
-        (angle 90)
-        (key-button
-          (key "down"))
-        (key-button
-          (key "up")))
-      (button-axis
-        (angle 0)
-        (key-button
-          (key "right"))
-        (key-button
-          (key "left")))))
+;;   (scroller
+;;     (axis-scroller
+;;       (speed 1000)
+;;       (button-axis
+;;         (angle 90)
+;;         (key-button
+;;           (key "down"))
+;;         (key-button
+;;           (key "up")))
+;;       (button-axis
+;;         (angle 0)
+;;         (key-button
+;;           (key "right"))
+;;         (key-button
+;;           (key "left")))))
 
-  (action-buttons
-    (action-button (key-button (key 1)))
-    (action-button (key-button (key 2)))
-    (action-button (key-button (key 3)))
-    (action-button (key-button (key 4)))
-    (action-button (key-button (key 5)))
-    (action-button (key-button (key 6)))
-    (action-button (key-button (key 7)))
-    (action-button (key-button (key 8)))
-    (action-button (key-button (key 9)))
-    (action-button (key-button (key 0))))
+;;   (action-buttons
+;;     (action-button (key-button (key 1)))
+;;     (action-button (key-button (key 2)))
+;;     (action-button (key-button (key 3)))
+;;     (action-button (key-button (key 4)))
+;;     (action-button (key-button (key 5)))
+;;     (action-button (key-button (key 6)))
+;;     (action-button (key-button (key 7)))
+;;     (action-button (key-button (key 8)))
+;;     (action-button (key-button (key 9)))
+;;     (action-button (key-button (key 0))))
 
-  (action-up
-    (multiple-button
-      (key-button
-        (key "prior"))
-      (mouse-button
-        (button 5))))
+;;   (action-up
+;;     (multiple-button
+;;       (key-button
+;;         (key "prior"))
+;;       (mouse-button
+;;         (button 5))))
 
-  (action-down
-    (multiple-button
-      (key-button
-        (key "next"))
-      (mouse-button
-        (button 4)))))
+;;   (action-down
+;;     (multiple-button
+;;       (key-button
+;;         (key "next"))
+;;       (mouse-button
+;;         (button 4))))
+  )
+
+;; EOF ;;

Modified: trunk/pingus/src/font_test_screen.cpp
===================================================================
--- trunk/pingus/src/font_test_screen.cpp       2007-09-02 04:26:33 UTC (rev 
3061)
+++ trunk/pingus/src/font_test_screen.cpp       2007-09-02 04:29:05 UTC (rev 
3062)
@@ -108,7 +108,7 @@
     {
       switch (i->type)
        {
-       case Input::ScrollEventType:
+       case Input::SCROLLER_EVENT_TYPE:
           scrollx += i->scroll.x_delta;
           scrolly += i->scroll.y_delta;
          break;


Property changes on: trunk/pingus/src/input
___________________________________________________________________
Name: svn:ignore
   + .sconsign.dblite


Added: trunk/pingus/src/input/SConstruct
===================================================================
--- trunk/pingus/src/input/SConstruct   2007-09-02 04:26:33 UTC (rev 3061)
+++ trunk/pingus/src/input/SConstruct   2007-09-02 04:29:05 UTC (rev 3062)
@@ -0,0 +1,37 @@
+##  -*- python -*-
+
+env = Environment(CCFLAGS  = ['-O0', '-Wall', '-Werror', '-g'],
+                  CPPPATH  = ['..', '../..'],
+                  CPPDEFINES = ['HAVE_CWIID'],
+                  LIBS = ['cwiid'])
+
+env.ParseConfig('sdl-config  --cflags --libs')
+env['LIBS'] += ['SDL_image', 'SDL_mixer', 'png']
+
+env.Program('main', [
+    'main.cpp',
+    'controller_description.cpp',
+    'controller.cpp',
+    'core_driver.cpp',
+    'usbmouse_driver.cpp',
+    'wiimote_driver.cpp',
+    'wiimote.cpp',
+    'sdl_driver.cpp',
+    'manager.cpp',
+    '../file_reader.cpp',
+    '../string_util.cpp',
+    '../path_manager.cpp',
+    '../pingus_error.cpp',
+    '../lisp/parser.cpp',
+    '../lisp/lexer.cpp',
+    '../lisp/lisp.cpp',
+    '../resource_modifier.cpp',
+    '../globals.cpp',
+    '../sexpr_file_reader.cpp',
+    '../math/vector3f.cpp',
+    '../debug.cpp',
+    '../debug_stream.cpp',
+    '../system.cpp',
+])
+
+# EOF #

Added: trunk/pingus/src/input/control.hpp
===================================================================
--- trunk/pingus/src/input/control.hpp  2007-09-02 04:26:33 UTC (rev 3061)
+++ trunk/pingus/src/input/control.hpp  2007-09-02 04:29:05 UTC (rev 3062)
@@ -0,0 +1,364 @@
+/*  $Id$
+**
+**  Pingus - A free Lemmings clone
+**  Copyright (C) 2007 Ingo Ruhnke <address@hidden>
+**
+**  This program is free software; you can redistribute it and/or
+**  modify it under the terms of the GNU General Public License
+**  as published by the Free Software Foundation; either version 2
+**  of the License, or (at your option) any later version.
+**
+**  This program is distributed in the hope that it will be useful,
+**  but WITHOUT ANY WARRANTY; without even the implied warranty of
+**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+**  GNU General Public License for more details.
+** 
+**  You should have received a copy of the GNU General Public License
+**  along with this program; if not, write to the Free Software
+**  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+**  02111-1307, USA.
+*/
+
+#ifndef HEADER_INPUT_CONTROL_HPP
+#define HEADER_INPUT_CONTROL_HPP
+
+#include <iostream>
+#include <vector>
+
+#include "math.hpp"
+#include "math/vector2f.hpp"
+#include "event.hpp"
+#include "controller.hpp"
+
+namespace Input {
+
+class Control {
+private:
+  Control* parent;
+  
+public: 
+  Control(Control* parent_) 
+    : parent(parent_)
+  {}
+
+  virtual ~Control() {
+  }
+
+  virtual void notify_parent() 
+  {
+    if (parent)
+      {
+        parent->update(this);
+      }
+    else
+      {
+        std::cout << "Input: Control: Error: parent missing! " << std::endl;
+      }
+  }
+
+  virtual void update(float delta) {
+  }
+  
+  virtual void update(Control* ctrl) {
+    std::cout << "Warning: Control:update() not handled" << std::endl;
+  }
+};
+
+class Button : public Control 
+{
+protected:
+  ButtonState state;
+
+public:
+  Button(Control* parent)
+    : Control(parent),
+      state(BUTTON_RELEASED)
+  {}  
+
+  bool get_state() const { return state; }
+
+  virtual void set_state(ButtonState new_state) 
+  {
+    if (new_state != state) 
+      {
+        state = new_state;
+        notify_parent();
+      }
+  }
+};
+
+class ButtonGroup : public Button 
+{
+private:
+  std::vector<Button*> buttons;
+  
+public: 
+  ButtonGroup(Control* parent)
+    : Button(parent)
+  {}
+
+  void add_button(Button* button) {
+    buttons.push_back(button);
+  }
+
+  void update(float delta) {
+    for(std::vector<Button*>::iterator i = buttons.begin(); i != 
buttons.end(); ++i)
+      (*i)->update(delta);
+  }
+
+  virtual void update(Control* ctrl)
+  {
+    ButtonState new_state = BUTTON_RELEASED;
+
+    for(std::vector<Button*>::iterator i = buttons.begin(); 
+        i != buttons.end(); ++i)
+      {
+        if ((*i)->get_state() == BUTTON_PRESSED)
+          new_state = BUTTON_PRESSED;
+      }
+
+    if (new_state != state)
+      {
+        state = new_state;
+        notify_parent();
+      }
+  }
+};
+
+class ControllerButton : public ButtonGroup
+{
+private:
+  Controller* controller;
+  int id;
+
+public:
+  ControllerButton(Controller* controller_, int id_)
+    : ButtonGroup(0),
+      controller(controller_),
+      id(id_)
+  {}
+
+  virtual void notify_parent() {
+    controller->add_button_event(id, state);
+  }
+};
+
+class Axis : public Control 
+{
+protected:
+  float pos;
+
+public:
+  Axis(Control* parent)
+    : Control(parent),
+      pos(0.0f)
+  {}
+
+  float get_pos() const { return pos; }
+
+  virtual void set_state(float new_pos) {
+    if (new_pos != pos)
+      {
+        pos = new_pos;
+        notify_parent();
+      }
+  }
+};
+
+class Pointer : public Control 
+{
+protected:
+  Vector2f pos;
+
+public:
+  Pointer(Control* parent)
+    : Control(parent)
+  {}
+
+  Vector2f get_pos() const { return pos; }
+
+  void set_pos(const Vector2f& new_pos) {
+    if (pos != new_pos) 
+      {
+        pos = new_pos;
+        notify_parent();
+      }
+  }
+};
+
+class Scroller : public Control 
+{
+protected:
+  Vector2f delta;
+  
+public:
+  Scroller(Control* parent)
+    : Control(parent),
+      delta(0.0f, 0.0f)
+  {}
+
+  Vector2f get_delta() const { return delta; }
+
+  void set_delta(const Vector2f& new_delta) {
+    if (delta != new_delta) 
+      {
+        delta = new_delta;
+        notify_parent();
+      }
+  }
+};
+
+class AxisGroup : public Axis {
+private:
+  std::vector<Axis*> axes;
+
+public:
+  AxisGroup(Control* parent)
+    : Axis(parent)
+  {}
+
+  void add_axis(Axis* axis) {
+    axes.push_back(axis);
+  }
+
+  void update(float delta) {
+    for(std::vector<Axis*>::iterator i = axes.begin(); i != axes.end(); ++i)
+      (*i)->update(delta);
+  }
+
+  void update(Control* ctrl) 
+  {
+    float new_pos = 0;
+    
+    for(std::vector<Axis*>::iterator i = axes.begin(); i != axes.end(); ++i)
+      {
+        new_pos += (*i)->get_pos();
+      }
+
+    new_pos = Math::clamp(-1.0f, new_pos, 1.0f);
+    
+    if (pos != new_pos)
+      {
+        pos = new_pos;
+        notify_parent();
+      }
+  }
+};
+
+class ControllerAxis : public AxisGroup 
+{
+private:
+  Controller* controller;
+  int id;
+
+public:
+  ControllerAxis(Controller* controller_, int id_) 
+    : AxisGroup(0),
+      controller(controller_),
+      id(id_)
+  {}
+
+  virtual void notify_parent() {
+    controller->add_axis_event(id, pos);
+  }
+};
+
+class PointerGroup : public Pointer 
+{
+private:
+  std::vector<Pointer*> pointer;
+
+public:
+  PointerGroup(Control* parent)
+    : Pointer(parent)
+  {}
+
+  void update(Control* p) {
+    Pointer* pointer = dynamic_cast<Pointer*>(p);
+    assert(pointer);
+    Vector2f new_pos = pointer->get_pos();
+    if (new_pos != pos)
+      {
+        pos = new_pos;
+        notify_parent();
+      }
+  }
+
+  void update(float delta) {
+    for(std::vector<Pointer*>::iterator i = pointer.begin(); i != 
pointer.end(); ++i)
+      (*i)->update(delta);
+  }
+
+  void add_pointer(Pointer* p) {
+    pointer.push_back(p);
+  }
+};
+
+class ControllerPointer : public PointerGroup
+{
+private:
+  Controller* controller;
+  int id;
+
+public:
+  ControllerPointer(Controller* controller_, int id_)
+    : PointerGroup(0),
+      controller(controller_),
+      id(id_)
+  {}
+
+  virtual void notify_parent() {
+    controller->add_pointer_event(id, pos.x, pos.y);
+  }
+};
+
+class ScrollerGroup : public Scroller 
+{
+private:
+  std::vector<Scroller*> scrollers;
+
+public:
+  ScrollerGroup(Control* parent)
+    : Scroller(parent)
+  {}
+
+  void update(float delta) {
+    for(std::vector<Scroller*>::iterator i = scrollers.begin(); i != 
scrollers.end(); ++i)
+      (*i)->update(delta);
+  }
+
+  void update(Control* p) {
+    Scroller* scroller = dynamic_cast<Scroller*>(p);
+    assert(scroller);
+    delta = scroller->get_delta();
+    notify_parent();
+  }
+
+  void add_scroller(Scroller* p) {
+    scrollers.push_back(p);
+  }
+};
+
+class ControllerScroller : public ScrollerGroup
+{
+private:
+  Controller* controller;
+  int id;
+
+public:
+  ControllerScroller(Controller* controller_, int id_)
+    : ScrollerGroup(0),
+      controller(controller_),
+      id(id_)
+  {}
+
+  virtual void notify_parent() {
+    controller->add_scroller_event(id, delta.x, delta.y);
+  }
+};
+
+} // namespace Input
+
+#endif
+
+/* EOF */


Property changes on: trunk/pingus/src/input/control.hpp
___________________________________________________________________
Name: svn:keywords
   + Id
Name: svn:eol-style
   + native

Added: trunk/pingus/src/input/controller.cpp
===================================================================
--- trunk/pingus/src/input/controller.cpp       2007-09-02 04:26:33 UTC (rev 
3061)
+++ trunk/pingus/src/input/controller.cpp       2007-09-02 04:29:05 UTC (rev 
3062)
@@ -0,0 +1,189 @@
+/*  $Id$
+**   __      __ __             ___        __   __ __   __
+**  /  \    /  \__| ____    __| _/_______/  |_|__|  | |  |   ____
+**  \   \/\/   /  |/    \  / __ |/  ___/\   __\  |  | |  | _/ __ \
+**   \        /|  |   |  \/ /_/ |\___ \  |  | |  |  |_|  |_\  ___/
+**    \__/\  / |__|___|  /\____ /____  > |__| |__|____/____/\___  >
+**         \/          \/      \/    \/                         \/
+**  Copyright (C) 2007 Ingo Ruhnke <address@hidden>
+**
+**  This program is free software; you can redistribute it and/or
+**  modify it under the terms of the GNU General Public License
+**  as published by the Free Software Foundation; either version 2
+**  of the License, or (at your option) any later version.
+**
+**  This program is distributed in the hope that it will be useful,
+**  but WITHOUT ANY WARRANTY; without even the implied warranty of
+**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+**  GNU General Public License for more details.
+** 
+**  You should have received a copy of the GNU General Public License
+**  along with this program; if not, write to the Free Software
+**  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+**  02111-1307, USA.
+*/
+
+#include "controller_description.hpp"
+#include "control.hpp"
+#include "controller.hpp"
+
+namespace Input {
+
+Controller::Controller(const ControllerDescription& desc)
+{
+  const std::vector<int>& button_lst = desc.get_buttons();
+  for(std::vector<int>::const_iterator i = button_lst.begin(); i != 
button_lst.end(); ++i)
+    {
+      add_button(*i, new ControllerButton(this, *i));
+    }
+
+  const std::vector<int>& axis_lst = desc.get_axes();
+  for(std::vector<int>::const_iterator i = axis_lst.begin(); i != 
axis_lst.end(); ++i)
+    {
+      add_axis(*i, new ControllerAxis(this, *i));
+    }
+
+  const std::vector<int>& pointer_lst = desc.get_pointers();
+  for(std::vector<int>::const_iterator i = pointer_lst.begin(); i != 
pointer_lst.end(); ++i)
+    {
+      add_pointer(*i, new ControllerPointer(this, *i));
+    }
+
+  const std::vector<int>& scroller_lst = desc.get_scrollers();
+  for(std::vector<int>::const_iterator i = scroller_lst.begin(); i != 
scroller_lst.end(); ++i)
+    {
+      add_scroller(*i, new ControllerScroller(this, *i));
+    }
+}
+
+ControllerScroller*
+Controller::get_scroller(int id) 
+{
+  if (id >= 0 && id < int(scrollers.size()))
+    return scrollers[id];
+  else
+    return 0;
+}
+
+void
+Controller::add_scroller(int id, ControllerScroller* scroller) 
+{
+  if (int(scrollers.size())-1 < id)
+    scrollers.resize(id+1);
+   
+  assert(scrollers[id] == 0);
+  scrollers[id] = scroller;
+}
+  
+ControllerPointer*
+Controller::get_pointer(int id) 
+{
+  if (id >= 0 && id < int(pointers.size()))
+    return pointers[id];
+  else
+    return 0;
+}
+
+void
+Controller::add_pointer(int id, ControllerPointer* pointer) 
+{
+  if (int(pointers.size())-1 < id)
+    pointers.resize(id+1);
+   
+  assert(pointers[id] == 0);
+  pointers[id] = pointer;
+}
+  
+ControllerAxis*
+Controller::get_axis(int id) 
+{
+  assert(id >= 0 && id < int(axes.size()));
+  return axes[id];
+}
+
+void
+Controller::add_axis(int id, ControllerAxis* axis) 
+{
+  if (int(axes.size())-1 < id)
+    axes.resize(id+1);
+   
+  assert(axes[id] == 0);
+  axes[id] = axis;
+}
+  
+ControllerButton*
+Controller::get_button(int id) 
+{
+  assert(id >= 0 && id < int(buttons.size()));
+  return buttons[id];
+}
+
+void
+Controller::update(float delta)
+{
+  for(std::vector<ControllerButton*>::iterator i = buttons.begin();
+      i != buttons.end(); ++i)
+    if (*i) (*i)->update(delta);
+
+  for(std::vector<ControllerAxis*>::iterator i = axes.begin();
+      i != axes.end(); ++i)
+    if (*i) (*i)->update(delta);
+
+  for(std::vector<ControllerPointer*>::iterator i = pointers.begin();
+      i != pointers.end(); ++i)
+    if (*i) (*i)->update(delta);
+
+  for(std::vector<ControllerScroller*>::iterator i = scrollers.begin();
+      i != scrollers.end(); ++i)
+    if (*i) (*i)->update(delta);
+}
+
+void
+Controller::add_button(int id, ControllerButton* button) 
+{
+  if (int(buttons.size())-1 < id)
+    buttons.resize(id+1);
+   
+  assert(buttons[id] == 0);
+  buttons[id] = button;
+}
+
+void
+Controller::add_axis_event(int id, float pos)
+{
+  // std::cout << "Controller::axis_event: id=" << id << " " << pos << 
std::endl;
+  events.push_back(makeAxisEvent((EventName)id, pos));
+}
+
+void
+Controller::add_button_event(int id, ButtonState state)
+{
+  // std::cout << "Controller::button_event: id=" << id << " " << state << 
std::endl;
+  events.push_back(makeButtonEvent((EventName)id, state));
+}
+
+void
+Controller::add_pointer_event(int id, float x, float y)
+{
+  // std::cout << "Controller::pointer_event: id=" << id << " " << x << ", " 
<< y << std::endl;
+  events.push_back(makePointerEvent((EventName)id, x, y));
+}
+
+void
+Controller::add_scroller_event(int id, float xrel, float yrel)
+{
+  // std::cout << "Controller::scroller_event: id=" << id << " " << xrel << ", 
" << yrel << std::endl;
+  events.push_back(makeScrollerEvent((EventName)id, xrel, yrel));
+}
+
+std::vector<Event>
+Controller::poll_events()
+{
+  std::vector<Event> old_events = events;  
+  events.clear();
+  return old_events;
+}
+
+} // namespace Input
+
+/* EOF */


Property changes on: trunk/pingus/src/input/controller.cpp
___________________________________________________________________
Name: svn:keywords
   + Id
Name: svn:eol-style
   + native

Added: trunk/pingus/src/input/controller.hpp
===================================================================
--- trunk/pingus/src/input/controller.hpp       2007-09-02 04:26:33 UTC (rev 
3061)
+++ trunk/pingus/src/input/controller.hpp       2007-09-02 04:29:05 UTC (rev 
3062)
@@ -0,0 +1,76 @@
+//  $Id$
+//
+//  Pingus - A free Lemmings clone
+//  Copyright (C) 2007 Ingo Ruhnke <address@hidden>
+//
+//  This program is free software; you can redistribute it and/or
+//  modify it under the terms of the GNU General Public License
+//  as published by the Free Software Foundation; either version 2
+//  of the License, or (at your option) any later version.
+//
+//  This program is distributed in the hope that it will be useful,
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+//  GNU General Public License for more details.
+//
+//  You should have received a copy of the GNU General Public License
+//  along with this program; if not, write to the Free Software
+//  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+
+#ifndef HEADER_PINGUS_INPUT_CONTROLLER_HXX
+#define HEADER_PINGUS_INPUT_CONTROLLER_HXX
+
+#include <assert.h>
+#include "event.hpp"
+
+namespace Input {
+
+class ControllerDescription;
+
+class ControllerButton;
+class ControllerAxis;
+class ControllerPointer;
+class ControllerScroller;
+
+class Controller
+{
+private:
+  // State Stuff
+  std::vector<ControllerButton*>   buttons;
+  std::vector<ControllerAxis*>     axes;
+  std::vector<ControllerPointer*>  pointers;
+  std::vector<ControllerScroller*> scrollers;
+  
+  std::vector<Event> events;
+public:
+  std::vector<Event> poll_events();
+
+  Controller(const ControllerDescription& desc);
+  ~Controller() {}
+  
+  ControllerAxis*     get_axis(int id);
+  ControllerButton*   get_button(int id);
+  ControllerPointer*  get_pointer(int id);
+  ControllerScroller* get_scroller(int id);
+
+  void add_axis_event(int id, float pos);
+  void add_button_event(int id, ButtonState state);
+  void add_pointer_event(int id, float x, float y);
+  void add_scroller_event(int id, float xrel, float yrel);
+
+  void add_axis(int id, ControllerAxis* axis);
+  void add_button(int id, ControllerButton* button); 
+  void add_pointer(int id, ControllerPointer* pointer);
+  void add_scroller(int id, ControllerScroller* scroller);
+  
+  void update(float delta);
+private:
+  Controller(const Controller&);
+  Controller& operator= (const Controller&);
+};
+
+} // namespace Input
+
+#endif 
+
+/* EOF */


Property changes on: trunk/pingus/src/input/controller.hpp
___________________________________________________________________
Name: svn:keywords
   + Id
Name: svn:eol-style
   + native

Added: trunk/pingus/src/input/controller_description.cpp
===================================================================
--- trunk/pingus/src/input/controller_description.cpp   2007-09-02 04:26:33 UTC 
(rev 3061)
+++ trunk/pingus/src/input/controller_description.cpp   2007-09-02 04:29:05 UTC 
(rev 3062)
@@ -0,0 +1,152 @@
+/*  $Id$
+**   __      __ __             ___        __   __ __   __
+**  /  \    /  \__| ____    __| _/_______/  |_|__|  | |  |   ____
+**  \   \/\/   /  |/    \  / __ |/  ___/\   __\  |  | |  | _/ __ \
+**   \        /|  |   |  \/ /_/ |\___ \  |  | |  |  |_|  |_\  ___/
+**    \__/\  / |__|___|  /\____ /____  > |__| |__|____/____/\___  >
+**         \/          \/      \/    \/                         \/
+**  Copyright (C) 2007 Ingo Ruhnke <address@hidden>
+**
+**  This program is free software; you can redistribute it and/or
+**  modify it under the terms of the GNU General Public License
+**  as published by the Free Software Foundation; either version 2
+**  of the License, or (at your option) any later version.
+**
+**  This program is distributed in the hope that it will be useful,
+**  but WITHOUT ANY WARRANTY; without even the implied warranty of
+**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+**  GNU General Public License for more details.
+** 
+**  You should have received a copy of the GNU General Public License
+**  along with this program; if not, write to the Free Software
+**  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+**  02111-1307, USA.
+*/
+
+#include <stdexcept>
+#include "controller_description.hpp"
+
+namespace Input {
+
+
+ControllerDescription::ControllerDescription()
+{
+}
+
+ControllerDescription::~ControllerDescription()
+{
+}
+
+void
+ControllerDescription::add_button(const std::string& name, int id)
+{
+  InputEventDefinition event;
+
+  event.type = BUTTON_EVENT_TYPE;
+  event.name = name;
+  event.id   = id;
+
+  str_to_event[event.name] = event;
+  id_to_event[event.id]    = event;
+}
+
+void
+ControllerDescription::add_scroller(const std::string& name, int id)
+{
+  InputEventDefinition event;
+
+  event.type = SCROLLER_EVENT_TYPE;
+  event.name = name;
+  event.id   = id;
+
+  str_to_event[event.name] = event;
+  id_to_event[event.id]    = event;
+}
+
+void
+ControllerDescription::add_pointer (const std::string& name, int id)
+{
+  InputEventDefinition event;
+
+  event.type = POINTER_EVENT_TYPE;
+  event.name = name;
+  event.id   = id;
+
+  str_to_event[event.name] = event;
+  id_to_event[event.id]    = event;
+}
+
+void
+ControllerDescription::add_axis  (const std::string& name, int id)
+{
+  InputEventDefinition event;
+
+  event.type = AXIS_EVENT_TYPE;
+  event.name = name;
+  event.id   = id;
+
+  str_to_event[event.name] = event;
+  id_to_event[event.id]    = event;
+}
+
+const InputEventDefinition&
+ControllerDescription::get_definition(int id) const
+{
+  std::map<int, InputEventDefinition>::const_iterator i = id_to_event.find(id);
+  if (i == id_to_event.end())
+    throw std::runtime_error("Unknown event id");
+
+  return i->second;
+}
+
+const InputEventDefinition&
+ControllerDescription::get_definition(const std::string& name) const
+{
+  std::map<std::string, InputEventDefinition>::const_iterator i = 
str_to_event.find(name);
+  if (i == str_to_event.end())
+    throw std::runtime_error("Unknown event str: " + name);
+
+  return i->second;
+}
+
+
+static std::vector<int> map2vector(const std::map<int, InputEventDefinition>& 
map,
+                                   EventType type)
+{
+  std::vector<int> lst;
+  for(std::map<int, InputEventDefinition>::const_iterator i = map.begin();
+      i != map.end(); ++i)
+    {
+      if (i->second.type == type)
+        lst.push_back(i->second.id);
+    }
+  return lst;
+}
+
+std::vector<int>
+ControllerDescription::get_buttons() const
+{
+  return map2vector(id_to_event, BUTTON_EVENT_TYPE);
+}
+
+std::vector<int>
+ControllerDescription::get_axes() const
+{
+  return map2vector(id_to_event, AXIS_EVENT_TYPE);
+}
+
+std::vector<int>
+ControllerDescription::get_pointers() const
+{
+  return map2vector(id_to_event, POINTER_EVENT_TYPE);  
+}
+
+std::vector<int>
+ControllerDescription::get_scrollers() const
+{
+  return map2vector(id_to_event, SCROLLER_EVENT_TYPE);  
+}
+
+} // namespace Input
+
+/* EOF */


Property changes on: trunk/pingus/src/input/controller_description.cpp
___________________________________________________________________
Name: svn:keywords
   + Id
Name: svn:eol-style
   + native

Added: trunk/pingus/src/input/controller_description.hpp
===================================================================
--- trunk/pingus/src/input/controller_description.hpp   2007-09-02 04:26:33 UTC 
(rev 3061)
+++ trunk/pingus/src/input/controller_description.hpp   2007-09-02 04:29:05 UTC 
(rev 3062)
@@ -0,0 +1,70 @@
+/*  $Id$
+**   __      __ __             ___        __   __ __   __
+**  /  \    /  \__| ____    __| _/_______/  |_|__|  | |  |   ____
+**  \   \/\/   /  |/    \  / __ |/  ___/\   __\  |  | |  | _/ __ \
+**   \        /|  |   |  \/ /_/ |\___ \  |  | |  |  |_|  |_\  ___/
+**    \__/\  / |__|___|  /\____ /____  > |__| |__|____/____/\___  >
+**         \/          \/      \/    \/                         \/
+**  Copyright (C) 2007 Ingo Ruhnke <address@hidden>
+**
+**  This program is free software; you can redistribute it and/or
+**  modify it under the terms of the GNU General Public License
+**  as published by the Free Software Foundation; either version 2
+**  of the License, or (at your option) any later version.
+**
+**  This program is distributed in the hope that it will be useful,
+**  but WITHOUT ANY WARRANTY; without even the implied warranty of
+**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+**  GNU General Public License for more details.
+** 
+**  You should have received a copy of the GNU General Public License
+**  along with this program; if not, write to the Free Software
+**  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+**  02111-1307, USA.
+*/
+
+#ifndef HEADER_INPUT_CONTROLLER_DESCRIPTION_HPP
+#define HEADER_INPUT_CONTROLLER_DESCRIPTION_HPP
+
+#include <map>
+#include <string>
+#include "event.hpp"
+
+namespace Input {
+
+struct InputEventDefinition 
+{
+  EventType   type;
+  int         id;
+  std::string name;
+};
+
+class ControllerDescription
+{
+private:
+  std::map<std::string, InputEventDefinition> str_to_event;
+  std::map<int,         InputEventDefinition> id_to_event;
+
+public:
+  ControllerDescription();
+  ~ControllerDescription();
+
+  void add_button  (const std::string& name, int id);
+  void add_axis    (const std::string& name, int id); 
+  void add_scroller(const std::string& name, int id); 
+  void add_pointer (const std::string& name, int id); 
+
+  const InputEventDefinition& get_definition(int id) const;
+  const InputEventDefinition& get_definition(const std::string& name) const;
+
+  std::vector<int> get_buttons() const;
+  std::vector<int> get_axes() const;
+  std::vector<int> get_pointers() const;
+  std::vector<int> get_scrollers() const;
+};
+
+} // namespace Input
+
+#endif
+
+/* EOF */


Property changes on: trunk/pingus/src/input/controller_description.hpp
___________________________________________________________________
Name: svn:keywords
   + Id
Name: svn:eol-style
   + native

Added: trunk/pingus/src/input/core_driver.cpp
===================================================================
--- trunk/pingus/src/input/core_driver.cpp      2007-09-02 04:26:33 UTC (rev 
3061)
+++ trunk/pingus/src/input/core_driver.cpp      2007-09-02 04:29:05 UTC (rev 
3062)
@@ -0,0 +1,163 @@
+/*  $Id$
+**   __      __ __             ___        __   __ __   __
+**  /  \    /  \__| ____    __| _/_______/  |_|__|  | |  |   ____
+**  \   \/\/   /  |/    \  / __ |/  ___/\   __\  |  | |  | _/ __ \
+**   \        /|  |   |  \/ /_/ |\___ \  |  | |  |  |_|  |_\  ___/
+**    \__/\  / |__|___|  /\____ /____  > |__| |__|____/____/\___  >
+**         \/          \/      \/    \/                         \/
+**  Copyright (C) 2007 Ingo Ruhnke <address@hidden>
+**
+**  This program is free software; you can redistribute it and/or
+**  modify it under the terms of the GNU General Public License
+**  as published by the Free Software Foundation; either version 2
+**  of the License, or (at your option) any later version.
+**
+**  This program is distributed in the hope that it will be useful,
+**  but WITHOUT ANY WARRANTY; without even the implied warranty of
+**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+**  GNU General Public License for more details.
+** 
+**  You should have received a copy of the GNU General Public License
+**  along with this program; if not, write to the Free Software
+**  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+**  02111-1307, USA.
+*/
+
+#include "math.hpp"
+#include "manager.hpp"
+#include "core_driver.hpp"
+
+namespace Input {
+
+class AxisPointer : public Pointer
+{
+private:
+  Axis* x_axis;
+  Axis* y_axis;
+  Button* speed_button;
+  float speed;
+
+public:
+  AxisPointer(Control* parent) 
+    : Pointer(parent),
+      x_axis(0), y_axis(0), speed_button(0),
+      speed(200.0f)
+  {
+  }
+
+  ~AxisPointer()
+  {
+  }
+
+  void setup(Axis* x, Axis* y, Button* s = 0)
+  {
+    x_axis = x;
+    y_axis = y;
+    speed_button = s;
+  }
+
+  void update(Control* ) 
+  {
+    //std::cout << "event" << std::endl;
+  }
+
+  void update(float delta)
+  {
+    x_axis->update(delta);
+    y_axis->update(delta);
+    if (speed_button) speed_button->update(delta);
+
+    Vector2f new_pos = pos;
+    float c_speed = speed;
+    
+    if (speed_button && speed_button->get_state() == BUTTON_PRESSED)
+      {
+        c_speed *= 5.0f;
+      }
+
+    new_pos.x += x_axis->get_pos() * c_speed * delta;
+    new_pos.y += y_axis->get_pos() * c_speed * delta;
+
+    // FIXME: Shouldn't be hardcored, but shouldn't depend on Display
+    // either
+    new_pos.x = Math::clamp(0.0f, new_pos.x, 800.0f);
+    new_pos.y = Math::clamp(0.0f, new_pos.y, 600.0f);
+
+    if (new_pos != pos)
+      {
+        pos = new_pos;
+        notify_parent();
+      }
+  }
+};
+
+Button*
+CoreDriver::create_button(const FileReader& reader, Control* parent)
+{
+  return 0;
+}
+
+Axis*
+CoreDriver::create_axis(const FileReader& reader, Control* parent)
+{
+  return 0;
+}
+
+Scroller*
+CoreDriver::create_scroller(const FileReader& reader, Control* parent)
+{
+  return 0;
+}
+
+Pointer*
+CoreDriver::create_pointer(const FileReader& reader, Control* parent)
+{
+  if (reader.get_name() == "core:axis-pointer") 
+    {
+      AxisPointer* axis = new AxisPointer(parent);
+
+      FileReader x_reader;
+      if (!reader.read_section("x-axis", x_reader))
+        {
+          std::cout << "CoreDriver: Couldn't find x-axis" << std::endl;
+          delete axis;
+          return 0;
+        }
+    
+      FileReader y_reader;
+      if (!reader.read_section("y-axis", y_reader))
+        {
+          std::cout << "CoreDriver: Couldn't find y-axis" << std::endl;
+          delete axis;
+          return 0;       
+        }
+
+      Axis* x_axis = manager->create_axis(x_reader.get_sections().front(), 
axis);
+      Axis* y_axis = manager->create_axis(y_reader.get_sections().front(), 
axis);
+
+      Button* button = 0;
+      FileReader button_reader;
+      if (reader.read_section("button", button_reader))
+        {
+          button = 
manager->create_button(button_reader.get_sections().front(), axis);
+        }
+
+      if (x_axis && y_axis)
+        {
+          axis->setup(x_axis, y_axis, button);
+          return axis;
+        }
+      else
+        {
+          return 0;
+        }
+    } 
+  else 
+    {
+      return 0;
+    }
+}
+
+} // namespace Input
+
+/* EOF */


Property changes on: trunk/pingus/src/input/core_driver.cpp
___________________________________________________________________
Name: svn:keywords
   + Id
Name: svn:eol-style
   + native

Added: trunk/pingus/src/input/core_driver.hpp
===================================================================
--- trunk/pingus/src/input/core_driver.hpp      2007-09-02 04:26:33 UTC (rev 
3061)
+++ trunk/pingus/src/input/core_driver.hpp      2007-09-02 04:29:05 UTC (rev 
3062)
@@ -0,0 +1,58 @@
+/*  $Id$
+**   __      __ __             ___        __   __ __   __
+**  /  \    /  \__| ____    __| _/_______/  |_|__|  | |  |   ____
+**  \   \/\/   /  |/    \  / __ |/  ___/\   __\  |  | |  | _/ __ \
+**   \        /|  |   |  \/ /_/ |\___ \  |  | |  |  |_|  |_\  ___/
+**    \__/\  / |__|___|  /\____ /____  > |__| |__|____/____/\___  >
+**         \/          \/      \/    \/                         \/
+**  Copyright (C) 2007 Ingo Ruhnke <address@hidden>
+**
+**  This program is free software; you can redistribute it and/or
+**  modify it under the terms of the GNU General Public License
+**  as published by the Free Software Foundation; either version 2
+**  of the License, or (at your option) any later version.
+**
+**  This program is distributed in the hope that it will be useful,
+**  but WITHOUT ANY WARRANTY; without even the implied warranty of
+**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+**  GNU General Public License for more details.
+** 
+**  You should have received a copy of the GNU General Public License
+**  along with this program; if not, write to the Free Software
+**  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+**  02111-1307, USA.
+*/
+
+#ifndef HEADER_CORE_DRIVER_HPP
+#define HEADER_CORE_DRIVER_HPP
+
+#include "driver.hpp"
+
+namespace Input {
+
+class Manager;
+
+/** */
+class CoreDriver : public Driver
+{
+private:
+  Manager* manager;
+
+public:
+  CoreDriver(Manager* manager_) : manager(manager_) {}
+  virtual ~CoreDriver() {}
+
+  std::string get_name() const { return "core"; }
+  void update(float delta) {}
+
+  Button*   create_button  (const FileReader& reader, Control* parent);
+  Axis*     create_axis    (const FileReader& reader, Control* parent);
+  Scroller* create_scroller(const FileReader& reader, Control* parent);
+  Pointer*  create_pointer (const FileReader& reader, Control* parent);
+};
+
+} // namespace Input
+
+#endif
+
+/* EOF */


Property changes on: trunk/pingus/src/input/core_driver.hpp
___________________________________________________________________
Name: svn:keywords
   + Id
Name: svn:eol-style
   + native

Added: trunk/pingus/src/input/driver.hpp
===================================================================
--- trunk/pingus/src/input/driver.hpp   2007-09-02 04:26:33 UTC (rev 3061)
+++ trunk/pingus/src/input/driver.hpp   2007-09-02 04:29:05 UTC (rev 3062)
@@ -0,0 +1,47 @@
+//  $Id$
+//
+//  Pingus - A free Lemmings clone
+//  Copyright (C) 2007 Ingo Ruhnke <address@hidden>
+//
+//  This program is free software; you can redistribute it and/or
+//  modify it under the terms of the GNU General Public License
+//  as published by the Free Software Foundation; either version 2
+//  of the License, or (at your option) any later version.
+//
+//  This program is distributed in the hope that it will be useful,
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+//  GNU General Public License for more details.
+//
+//  You should have received a copy of the GNU General Public License
+//  along with this program; if not, write to the Free Software
+//  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+
+#ifndef HEADER_PINGUS_INPUT_DRIVER_HXX
+#define HEADER_PINGUS_INPUT_DRIVER_HXX
+
+#include "file_reader.hpp"
+#include "control.hpp"
+
+namespace Input {
+
+class Driver
+{
+public:
+  Driver() {}
+  virtual ~Driver() {}
+
+  virtual std::string get_name() const =0;
+  virtual void update(float delta) =0;
+
+  virtual Button*   create_button  (const FileReader& reader, Control* parent) 
=0;
+  virtual Axis*     create_axis    (const FileReader& reader, Control* parent) 
=0;
+  virtual Scroller* create_scroller(const FileReader& reader, Control* parent) 
=0;
+  virtual Pointer*  create_pointer (const FileReader& reader, Control* parent) 
=0;
+};
+
+} // namespace Input
+
+#endif
+
+/* EOF */


Property changes on: trunk/pingus/src/input/driver.hpp
___________________________________________________________________
Name: svn:keywords
   + Id
Name: svn:eol-style
   + native

Added: trunk/pingus/src/input/event.hpp
===================================================================
--- trunk/pingus/src/input/event.hpp    2007-09-02 04:26:33 UTC (rev 3061)
+++ trunk/pingus/src/input/event.hpp    2007-09-02 04:29:05 UTC (rev 3062)
@@ -0,0 +1,178 @@
+//  $Id$
+//
+//  Pingus - A free Lemmings clone
+//  Copyright (C) 2000 Ingo Ruhnke <address@hidden>
+//
+//  This program is free software; you can redistribute it and/or
+//  modify it under the terms of the GNU General Public License
+//  as published by the Free Software Foundation; either version 2
+//  of the License, or (at your option) any later version.
+//
+//  This program is distributed in the hope that it will be useful,
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+//  GNU General Public License for more details.
+//
+//  You should have received a copy of the GNU General Public License
+//  along with this program; if not, write to the Free Software
+//  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+
+#ifndef HEADER_PINGUS_INPUT_EVENT_HXX
+#define HEADER_PINGUS_INPUT_EVENT_HXX
+
+#include <vector>
+#include <string>
+#include "../pingus.hpp"
+
+namespace Input {
+
+enum EventType { BUTTON_EVENT_TYPE, 
+                 POINTER_EVENT_TYPE, 
+                 AXIS_EVENT_TYPE, 
+                 SCROLLER_EVENT_TYPE, 
+                 KEYBOARD_EVENT_TYPE };
+
+enum EventName { 
+  // Buttons
+  PRIMARY_BUTTON, 
+  SECONDARY_BUTTON,
+  PAUSE_BUTTON,
+  FAST_FORWARD_BUTTON,
+  ARMAGEDDON_BUTTON, 
+  ESCAPE_BUTTON, 
+
+  ACTION_1_BUTTON, 
+  ACTION_2_BUTTON,
+  ACTION_3_BUTTON,
+  ACTION_4_BUTTON,
+  ACTION_5_BUTTON,
+  ACTION_6_BUTTON,
+  ACTION_7_BUTTON,
+  ACTION_8_BUTTON,
+  ACTION_9_BUTTON, 
+  ACTION_10_BUTTON,
+                  
+  ACTION_UP_BUTTON,
+  ACTION_DOWN_BUTTON, 
+                 
+  // Pointer
+  STANDARD_POINTER,
+  
+  // Scroller
+  STANDARD_SCROLLER,
+
+  // Axis
+  ACTION_AXIS,
+};
+
+
+enum ButtonState { BUTTON_RELEASED, BUTTON_PRESSED };
+
+struct ButtonEvent
+{
+  EventName   name;
+  ButtonState state;
+};
+
+
+struct PointerEvent
+{
+  EventName name;
+  float x;
+  float y;
+};
+
+struct AxisEvent
+{
+  EventName name;
+  float     dir;
+};
+
+struct ScrollEvent
+{
+  EventName name;
+  float x_delta;
+  float y_delta;
+};
+
+struct KeyboardEvent
+{
+  unsigned short key;
+};
+
+struct Event
+{
+  EventType type;
+
+  union {
+    ButtonEvent   button;
+    PointerEvent  pointer;
+    AxisEvent     axis;
+    ScrollEvent   scroll;
+    KeyboardEvent keyboard;
+  };
+};
+
+typedef std::vector<Event> EventLst;
+
+inline Event makeButtonEvent(EventName name, ButtonState state)
+{
+  Event event;
+
+  event.type  = BUTTON_EVENT_TYPE;
+  event.button.name  = name;
+  event.button.state = state;
+
+  return event;
+}
+
+inline Event makePointerEvent(EventName name, float x, float y)
+{
+  Event event;
+
+  event.type = POINTER_EVENT_TYPE;
+  event.pointer.name = name;
+  event.pointer.x    = x;
+  event.pointer.y    = y;
+
+  return event;
+}
+
+inline Event makeAxisEvent(EventName name, float dir)
+{
+  Event event;
+
+  event.type = AXIS_EVENT_TYPE;
+  event.axis.dir  = dir;
+  event.axis.name = name;
+
+  return event;
+}
+
+inline Event makeScrollerEvent(EventName name, float x_delta, float y_delta)
+{
+  Event event;
+
+  event.type    = SCROLLER_EVENT_TYPE;
+  event.scroll.name    = name;
+  event.scroll.x_delta = x_delta;
+  event.scroll.y_delta = y_delta;
+
+  return event;
+}
+
+inline Event makeKeyboardEvent(unsigned short c)
+{
+  Event event;
+       
+  event.type = KEYBOARD_EVENT_TYPE;
+  event.keyboard.key = c;
+       
+  return event;
+}
+
+} // namespace Input
+
+#endif
+
+/* EOF */


Property changes on: trunk/pingus/src/input/event.hpp
___________________________________________________________________
Name: svn:keywords
   + Id
Name: svn:eol-style
   + native

Added: trunk/pingus/src/input/main.cpp
===================================================================
--- trunk/pingus/src/input/main.cpp     2007-09-02 04:26:33 UTC (rev 3061)
+++ trunk/pingus/src/input/main.cpp     2007-09-02 04:29:05 UTC (rev 3062)
@@ -0,0 +1,38 @@
+#include <stdexcept>
+#include "SDL.h"
+#include "manager.hpp"
+#include "controller.hpp"
+
+int main()
+{
+  try {
+  if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK) < 0) {
+    std::cerr << "Unable to init SDL: " << SDL_GetError() << std::endl;
+    exit(1);
+  }
+  atexit(SDL_Quit);
+
+  SDL_Surface* screen = SDL_SetVideoMode(640, 480, 0, 0);
+
+  Input::Manager manager;
+
+  Input::Controller* controller
+    = manager.create_controller("../../data/controller/input2.scm");
+
+  while(true)
+    {
+      std::vector<Input::Event> events = controller->poll_events();
+
+      manager.update(0.033);
+      
+      SDL_Delay(33);
+      SDL_Flip(screen);
+    }
+  } catch (std::exception& err) {
+    std::cout << "Exception: " << err.what() << std::endl;
+  }
+
+  return 0;
+}
+
+/* EOF */


Property changes on: trunk/pingus/src/input/main.cpp
___________________________________________________________________
Name: svn:keywords
   + Id
Name: svn:eol-style
   + native

Added: trunk/pingus/src/input/manager.cpp
===================================================================
--- trunk/pingus/src/input/manager.cpp  2007-09-02 04:26:33 UTC (rev 3061)
+++ trunk/pingus/src/input/manager.cpp  2007-09-02 04:29:05 UTC (rev 3062)
@@ -0,0 +1,301 @@
+/*  $Id$
+**
+**  Pingus - A free Lemmings clone
+**  Copyright (C) 2007 Ingo Ruhnke <address@hidden>
+**
+**  This program is free software; you can redistribute it and/or
+**  modify it under the terms of the GNU General Public License
+**  as published by the Free Software Foundation; either version 2
+**  of the License, or (at your option) any later version.
+**
+**  This program is distributed in the hope that it will be useful,
+**  but WITHOUT ANY WARRANTY; without even the implied warranty of
+**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+**  GNU General Public License for more details.
+** 
+**  You should have received a copy of the GNU General Public License
+**  along with this program; if not, write to the Free Software
+**  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+**  02111-1307, USA.
+*/
+
+#include "string_util.hpp"
+#include "pingus_error.hpp"
+#include "path_manager.hpp"
+#include "sdl_driver.hpp"
+#include "core_driver.hpp"
+#include "usbmouse_driver.hpp"
+#ifdef HAVE_CWIID
+#  include "wiimote_driver.hpp"
+#endif 
+#include "manager.hpp"
+
+namespace Input {
+
+Manager::Manager()
+{
+  desc.add_axis("action-axis",  ACTION_AXIS);
+
+  desc.add_pointer("standard-pointer",   STANDARD_POINTER);
+  desc.add_scroller("standard-scroller", STANDARD_SCROLLER);
+
+  desc.add_button("primary-button",      PRIMARY_BUTTON);
+  desc.add_button("secondary-button",    SECONDARY_BUTTON);
+  desc.add_button("fast-forward-button", FAST_FORWARD_BUTTON);
+  desc.add_button("armageddon-button",   ARMAGEDDON_BUTTON);
+  desc.add_button("pause-button",        PAUSE_BUTTON);
+  desc.add_button("escape-button",       ESCAPE_BUTTON);
+  desc.add_button("action-up-button",    ACTION_UP_BUTTON);
+  desc.add_button("action-down-button",  ACTION_DOWN_BUTTON);
+  desc.add_button("action-1-button",     ACTION_1_BUTTON);
+  desc.add_button("action-2-button",     ACTION_2_BUTTON);
+  desc.add_button("action-3-button",     ACTION_3_BUTTON);
+  desc.add_button("action-4-button",     ACTION_4_BUTTON);
+  desc.add_button("action-5-button",     ACTION_5_BUTTON);
+  desc.add_button("action-6-button",     ACTION_6_BUTTON);
+  desc.add_button("action-7-button",     ACTION_7_BUTTON);
+  desc.add_button("action-8-button",     ACTION_8_BUTTON);
+  desc.add_button("action-9-button",     ACTION_9_BUTTON);
+  desc.add_button("action-10-button",    ACTION_10_BUTTON);
+}
+
+std::string get_non_driver_part(const std::string& fullname)
+{
+  std::string::size_type i = fullname.find_first_of(':');
+  if (i != std::string::npos)
+    {
+      return fullname.substr(i+1);
+    }
+  else
+    {
+      return fullname;
+    }
+}
+
+std::string get_driver_part(const std::string& fullname)
+{
+  std::string::size_type i = fullname.find_first_of(':');
+  if (i != std::string::npos)
+    {
+      return fullname.substr(0, i);
+    }
+  else
+    {
+      return "core";
+    }
+}
+
+Controller*
+Manager::create_controller(const std::string& filename)
+{
+  std::auto_ptr<Controller> controller(new Controller(desc));
+
+  FileReader reader = FileReader::parse(filename);
+
+  if (reader.get_name() != "pingus-controller")
+    {
+      PingusError::raise("Controller: invalid config file '" + filename + "'");
+    }
+  else
+    {
+      const std::vector<FileReader>& sections = reader.get_sections();
+      for (std::vector<FileReader>::const_iterator i = sections.begin();
+           i != sections.end(); ++i)
+        {
+          if (StringUtil::has_suffix(i->get_name(), "pointer"))
+            {
+              const std::vector<FileReader>& pointers = i->get_sections();
+              for(std::vector<FileReader>::const_iterator j = 
pointers.begin(); j != pointers.end(); ++j)
+                {
+                  int id = desc.get_definition(i->get_name()).id;
+                  ControllerPointer* ctrl_pointer = 
controller->get_pointer(id);
+                  Pointer* pointer = create_pointer(*j, ctrl_pointer);
+                  if (pointer)
+                    ctrl_pointer->add_pointer(pointer);
+                  else
+                    std::cout << "Manager: pointer: Couldn't create pointer " 
<< j->get_name() << std::endl;
+                }
+
+            }
+          else if (StringUtil::has_suffix(i->get_name(), "scroller"))
+            {
+              const std::vector<FileReader>& scrollers = i->get_sections();
+              for(std::vector<FileReader>::const_iterator j = 
scrollers.begin(); j != scrollers.end(); ++j)
+                {
+                  int id = desc.get_definition(i->get_name()).id;
+                  ControllerScroller* ctrl_scroller = 
controller->get_scroller(id);
+                  Scroller* scroller = create_scroller(*j, ctrl_scroller);
+                  if (scroller)
+                    ctrl_scroller->add_scroller(scroller);
+                  else
+                    std::cout << "Manager: scroller: Couldn't create scroller 
" << j->get_name() << std::endl;
+                }
+
+            }
+          else if (StringUtil::has_suffix(i->get_name(), "button"))
+            {             
+              const std::vector<FileReader>& buttons = i->get_sections();
+              for(std::vector<FileReader>::const_iterator j = buttons.begin(); 
j != buttons.end(); ++j)
+                {
+                  int id = desc.get_definition(i->get_name()).id;
+                  ControllerButton* ctrl_button = controller->get_button(id);
+                  Button* button = create_button(*j, ctrl_button);
+                  if (button)
+                    ctrl_button->add_button(button);
+                  else
+                    std::cout << "Manager: button: Couldn't create button " << 
j->get_name() << std::endl;
+                }
+            }
+          else if (StringUtil::has_suffix(i->get_name(), "axis"))
+            {
+              const std::vector<FileReader>& axes = i->get_sections();
+              for(std::vector<FileReader>::const_iterator j = axes.begin(); j 
!= axes.end(); ++j)
+                {
+                  int id = desc.get_definition(i->get_name()).id;
+                  ControllerAxis* ctrl_axis = controller->get_axis(id);
+                  Axis* axis = create_axis(*j, ctrl_axis);
+                  if (axis)
+                    ctrl_axis->add_axis(axis);
+                  else
+                    std::cout << "Manager: axis: Couldn't create axis " << 
j->get_name() << std::endl;
+                }
+            }
+          else
+            {
+              PingusError::raise(std::string("Manager: Unkown Element in 
Controller Config: ") 
+                                 + i->get_name());
+            }
+        }
+    }
+
+  return controller.release();
+}
+
+void
+Manager::update(float delta)
+{
+  for(Drivers::iterator i = drivers.begin(); i != drivers.end(); ++i)
+    (*i)->update(delta);
+  
+  for(std::vector<Controller*>::iterator i = controller.begin(); 
+      i != controller.end(); ++i)
+    (*i)->update(delta);
+}
+
+Driver*
+Manager::get_driver(const std::string& name)
+{
+  for(Drivers::iterator i = drivers.begin(); i != drivers.end(); ++i)
+    {
+      if ((*i)->get_name() == name)
+        {
+          return *i;
+        }
+    }
+  return 0;
+}
+
+Driver*
+Manager::load_driver(const std::string& name)
+{
+  Driver* driver = get_driver(name);
+
+  if (driver)
+    {
+      return driver;
+    }
+  else
+    {
+      std::cout << "Manager: Loading driver '" << name << "'" << std::endl;
+
+      if (name == "sdl") {
+        driver = new SDLDriver();
+      } else if (name == "core") {
+        driver = new CoreDriver(this);
+      } else if (name == "usbmouse") {
+        driver = new USBMouseDriver();
+#ifdef HAVE_CWIID
+      } else if (name == "wiimote") {
+        driver = new WiimoteDriver();
+#endif
+      } else {
+        std::cout << "Manager: Unknown driver: " << name << std::endl;
+        return 0;
+      }
+
+      drivers.push_back(driver);
+      return driver;
+    }
+}
+
+Button*
+Manager::create_button(const FileReader& reader, Control* parent)
+{
+  std::string driver = get_driver_part(reader.get_name());
+                  
+  Driver* drv = load_driver(driver);
+  if (drv)
+    {
+      return drv->create_button(reader, parent);
+    }
+  else
+    {
+      std::cout << "Manager: Error: Couldn't find driver: '" << driver << "'" 
<< std::endl;
+      return 0;
+    }
+}
+
+Axis*
+Manager::create_axis(const FileReader& reader, Control* parent)
+{
+  std::string driver = get_driver_part(reader.get_name());
+                  
+  Driver* drv = load_driver(driver);
+  if (drv)
+    {
+      return drv->create_axis(reader, parent);
+    }
+  else
+    {
+      std::cout << "Manager: Error: Couldn't find driver: '" << driver << "'" 
<< std::endl;
+      return 0;
+    }
+}
+
+Pointer*
+Manager::create_pointer(const FileReader& reader, Control* parent)
+{
+  std::string driver = get_driver_part(reader.get_name());
+                  
+  Driver* drv = load_driver(driver);
+  if (drv)
+    {
+      return drv->create_pointer(reader, parent);
+    }
+  else
+    {
+      std::cout << "Manager: Error: Couldn't find driver: '" << driver << "'" 
<< std::endl;
+      return 0;
+    }
+}
+
+Scroller*
+Manager::create_scroller(const FileReader& reader, Control* parent)
+{
+  std::string driver = get_driver_part(reader.get_name());
+                  
+  Driver* drv = load_driver(driver);
+  if (drv)
+    {
+      return drv->create_scroller(reader, parent);
+    }
+  else
+    {
+      std::cout << "Manager: Error: Couldn't find driver: '" << driver << "'" 
<< std::endl;
+      return 0;
+    }
+}
+
+} // namespace Input
+
+/* EOF */


Property changes on: trunk/pingus/src/input/manager.cpp
___________________________________________________________________
Name: svn:keywords
   + Id
Name: svn:eol-style
   + native

Added: trunk/pingus/src/input/manager.hpp
===================================================================
--- trunk/pingus/src/input/manager.hpp  2007-09-02 04:26:33 UTC (rev 3061)
+++ trunk/pingus/src/input/manager.hpp  2007-09-02 04:29:05 UTC (rev 3062)
@@ -0,0 +1,60 @@
+//  $Id$
+//
+//  Pingus - A free Lemmings clone
+//  Copyright (C) 2000 Ingo Ruhnke <address@hidden>
+//
+//  This program is free software; you can redistribute it and/or
+//  modify it under the terms of the GNU General Public License
+//  as published by the Free Software Foundation; either version 2
+//  of the License, or (at your option) any later version.
+//
+//  This program is distributed in the hope that it will be useful,
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+//  GNU General Public License for more details.
+//
+//  You should have received a copy of the GNU General Public License
+//  along with this program; if not, write to the Free Software
+//  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+
+#ifndef HEADER_PINGUS_INPUT_MANAGER_HXX
+#define HEADER_PINGUS_INPUT_MANAGER_HXX
+
+#include <vector>
+#include "controller.hpp"
+#include "controller_description.hpp"
+#include "driver.hpp"
+
+namespace Input {
+
+class Manager 
+{
+private:
+  typedef std::vector<Driver*> Drivers;
+  Drivers drivers;
+
+  std::vector<Controller*> controller;
+  ControllerDescription desc;
+
+public:
+  Manager();
+
+  void update(float delta);
+
+  Controller* create_controller(const std::string& filename);
+
+  Button*   create_button  (const FileReader& reader, Control* parent);
+  Axis*     create_axis    (const FileReader& reader, Control* parent);
+  Pointer*  create_pointer (const FileReader& reader, Control* parent);
+  Scroller* create_scroller(const FileReader& reader, Control* parent);
+
+private:
+  Driver* load_driver(const std::string& name);
+  Driver* get_driver(const std::string& name);
+};
+
+} // namespace Input
+
+#endif
+
+/* EOF */


Property changes on: trunk/pingus/src/input/manager.hpp
___________________________________________________________________
Name: svn:keywords
   + Id
Name: svn:eol-style
   + native

Added: trunk/pingus/src/input/sdl_driver.cpp
===================================================================
--- trunk/pingus/src/input/sdl_driver.cpp       2007-09-02 04:26:33 UTC (rev 
3061)
+++ trunk/pingus/src/input/sdl_driver.cpp       2007-09-02 04:29:05 UTC (rev 
3062)
@@ -0,0 +1,286 @@
+/*  $Id$
+**
+**  Pingus - A free Lemmings clone
+**  Copyright (C) 2007 Ingo Ruhnke <address@hidden>
+**
+**  This program is free software; you can redistribute it and/or
+**  modify it under the terms of the GNU General Public License
+**  as published by the Free Software Foundation; either version 2
+**  of the License, or (at your option) any later version.
+**
+**  This program is distributed in the hope that it will be useful,
+**  but WITHOUT ANY WARRANTY; without even the implied warranty of
+**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+**  GNU General Public License for more details.
+** 
+**  You should have received a copy of the GNU General Public License
+**  along with this program; if not, write to the Free Software
+**  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+**  02111-1307, USA.
+*/
+
+#include "file_reader.hpp"
+#include "sdl_driver.hpp"
+
+namespace Input {
+
+SDLDriver::SDLDriver()
+{
+  for (int i = 0; i < SDLK_LAST; ++i) {
+    char* key_name = SDL_GetKeyName(static_cast<SDLKey>(i));
+    string2key[key_name] = static_cast<SDLKey>(i);
+    
+    // FIXME: Make the keynames somewhere user visible so that users can use 
them
+    // std::cout << key_name << std::endl;
+  }
+}
+
+SDLDriver::~SDLDriver()
+{
+  
+}
+
+Button*
+SDLDriver::create_button(const FileReader& reader, Control* parent)
+{
+  //std::cout << "SDL: " << reader.get_name() << std::endl;
+  if (reader.get_name() == "sdl:joystick-button")
+    {
+      JoystickButtonBinding binding;
+
+      reader.read_int("device", binding.device);
+      reader.read_int("button", binding.button);
+      
+      if (open_joystick(binding.device))
+        {
+          binding.binding = new Button(parent);
+          joystick_button_bindings.push_back(binding);
+      
+          return binding.binding;
+        }
+      else
+        {
+          return 0;
+        }
+    }
+  else if (reader.get_name() == "sdl:mouse-button")
+    {
+      MouseButtonBinding binding;
+
+      reader.read_int("button", binding.button);
+      binding.binding = new Button(parent);
+      mouse_button_bindings.push_back(binding);
+
+      return binding.binding;
+    }
+  else if (reader.get_name() == "sdl:keyboard-button")
+    {
+      std::string key;
+      if (reader.read_string("key", key)) 
+        {
+          String2Key::iterator i = string2key.find(key);
+          if (i != string2key.end()) 
+            {
+              KeyboardButtonBinding binding;
+      
+              binding.key = i->second;
+              binding.binding = new Button(parent);
+              keyboard_button_bindings.push_back(binding);
+
+              return binding.binding;
+            }
+          else 
+            {
+              std::cout << "SDLDriver: Couldn't find keysym for key '" << key 
<< "'" << std::endl;
+              return 0;
+            }
+        }
+      else
+        {
+          std::cout << "SDLDriver: 'key' missing" << std::endl;
+          return 0;
+        }
+    }
+  else
+    {
+      return 0;
+    }
+}
+
+Axis*
+SDLDriver::create_axis(const FileReader& reader, Control* parent)
+{
+  if (reader.get_name() == "sdl:joystick-axis")
+    {
+      JoystickAxisBinding binding;
+
+      reader.read_int("device", binding.device);
+      reader.read_int("axis",   binding.axis);
+      
+      if (open_joystick(binding.device))
+        {
+          binding.binding = new Axis(parent);
+          joystick_axis_bindings.push_back(binding);
+      
+          return binding.binding;
+        }
+      else
+        {
+          return 0;
+        }
+    }
+  else
+    {
+      return 0;
+    }
+}
+
+Scroller*
+SDLDriver::create_scroller(const FileReader& reader, Control* parent)
+{
+  if (reader.get_name() == "sdl:mouse-scroller")
+    {
+      ScrollerBinding binding;
+
+      binding.binding = new Scroller(parent);
+      scroller_bindings.push_back(binding);
+
+      return binding.binding;
+    }
+  else
+    {
+      return 0;
+    }
+}
+
+Pointer*
+SDLDriver::create_pointer(const FileReader& reader, Control* parent)
+{
+  if (reader.get_name() == "sdl:mouse-pointer")
+    {
+      PointerBinding binding;
+
+      binding.binding = new Pointer(parent);
+      pointer_bindings.push_back(binding);
+
+      return binding.binding;
+    }
+  else
+    {
+      return 0;
+    }
+}
+
+bool 
+SDLDriver::open_joystick(int device)
+{
+  JoystickHandles::iterator i = joystick_handles.find(device);
+  if (i == joystick_handles.end())
+    {
+      SDL_Joystick* joy = SDL_JoystickOpen(device);
+      if (joy)
+        {
+          joystick_handles[device] = joy;
+          return true;
+        }
+      else
+        {
+          std::cout << "SDLDriver: Couldn't open joystick number " << device 
<< std::endl;
+          return false;
+        }
+    }
+  else
+    {
+      return true;
+    }
+}
+
+void
+SDLDriver::update(float delta)
+{
+  SDL_Event event;
+  while (SDL_PollEvent(&event))
+    {
+      switch(event.type)
+        {
+          case SDL_QUIT: // FIXME: make this into a GameEvent
+            exit(1);
+            break;
+
+          case SDL_MOUSEMOTION:
+            for(std::vector<PointerBinding>::iterator i = 
pointer_bindings.begin();
+                i != pointer_bindings.end(); ++i)
+              {
+                i->binding->set_pos(Vector2f(event.motion.x, event.motion.y));
+              }
+
+            for(std::vector<ScrollerBinding>::iterator i = 
scroller_bindings.begin();
+                i != scroller_bindings.end(); ++i)
+              {
+                i->binding->set_delta(Vector2f(event.motion.xrel, 
event.motion.yrel));
+              }
+            break;
+
+          case SDL_MOUSEBUTTONDOWN:
+          case SDL_MOUSEBUTTONUP:
+            for(std::vector<MouseButtonBinding>::iterator i = 
mouse_button_bindings.begin();
+                i != mouse_button_bindings.end(); ++i)
+              {
+                if (event.button.button == (*i).button)
+                  {
+                    if (event.button.state == SDL_PRESSED)
+                      (*i).binding->set_state(BUTTON_PRESSED);
+                    else
+                      (*i).binding->set_state(BUTTON_RELEASED);
+                  }
+              }
+            break;
+
+          case SDL_KEYDOWN:
+          case SDL_KEYUP:
+            for(std::vector<KeyboardButtonBinding>::iterator i = 
keyboard_button_bindings.begin();
+                i != keyboard_button_bindings.end(); ++i)
+              {
+                if (event.key.keysym.sym == i->key)
+                  {
+                    if (event.key.state == SDL_PRESSED)
+                      i->binding->set_state(BUTTON_PRESSED);
+                    else
+                      i->binding->set_state(BUTTON_RELEASED);
+                  }
+              }
+            break;
+
+          case SDL_JOYAXISMOTION:
+            for(std::vector<JoystickAxisBinding>::iterator i = 
joystick_axis_bindings.begin();
+                i != joystick_axis_bindings.end(); ++i)            
+              {
+                if (event.jaxis.which == i->device &&
+                    event.jaxis.axis  == i->axis)
+                  i->binding->set_state(event.jaxis.value / 32767.0);
+              }
+            break;
+            
+          case SDL_JOYBUTTONDOWN:
+          case SDL_JOYBUTTONUP:
+            for(std::vector<JoystickButtonBinding>::iterator i = 
joystick_button_bindings.begin();
+                i != joystick_button_bindings.end(); ++i)
+              {
+                if (event.jbutton.which  == i->device &&
+                    event.jbutton.button == i->button)
+                  {
+                    i->binding->set_state(event.jbutton.state == SDL_PRESSED ? 
BUTTON_PRESSED : BUTTON_RELEASED);
+                  }
+              }
+            break;
+            
+          default:
+            // FIXME: Do something with other events
+            break;
+        }
+    }
+}
+
+} // namespace Input
+
+/* EOF */


Property changes on: trunk/pingus/src/input/sdl_driver.cpp
___________________________________________________________________
Name: svn:keywords
   + Id
Name: svn:eol-style
   + native

Added: trunk/pingus/src/input/sdl_driver.hpp
===================================================================
--- trunk/pingus/src/input/sdl_driver.hpp       2007-09-02 04:26:33 UTC (rev 
3061)
+++ trunk/pingus/src/input/sdl_driver.hpp       2007-09-02 04:29:05 UTC (rev 
3062)
@@ -0,0 +1,107 @@
+/*  $Id$
+**
+**  Pingus - A free Lemmings clone
+**  Copyright (C) 2007 Ingo Ruhnke <address@hidden>
+**
+**  This program is free software; you can redistribute it and/or
+**  modify it under the terms of the GNU General Public License
+**  as published by the Free Software Foundation; either version 2
+**  of the License, or (at your option) any later version.
+**
+**  This program is distributed in the hope that it will be useful,
+**  but WITHOUT ANY WARRANTY; without even the implied warranty of
+**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+**  GNU General Public License for more details.
+** 
+**  You should have received a copy of the GNU General Public License
+**  along with this program; if not, write to the Free Software
+**  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+**  02111-1307, USA.
+*/
+
+#ifndef HEADER_INPUT_SDL_DRIVER_HPP
+#define HEADER_INPUT_SDL_DRIVER_HPP
+
+#include <map>
+#include <vector>
+
+#include "SDL.h"
+#include "driver.hpp"
+#include "control.hpp"
+
+class FileReader;
+
+namespace Input {
+
+
+/** */
+class SDLDriver : public Driver
+{
+private:
+  struct JoystickButtonBinding {
+    Button* binding;
+
+    int device;
+    int button;
+  };
+
+  struct JoystickAxisBinding {
+    Axis* binding;
+
+    int  device;
+    int  axis;
+  };
+
+  struct MouseButtonBinding {
+    Button* binding;
+
+    int button;
+  };
+
+  struct KeyboardButtonBinding {
+    Button* binding;
+
+    SDLKey key;
+  };
+
+  struct ScrollerBinding {
+    Scroller* binding;
+  };
+
+  struct PointerBinding {
+    Pointer* binding;
+  };
+
+  std::vector<ScrollerBinding>       scroller_bindings;
+  std::vector<PointerBinding>        pointer_bindings;
+  std::vector<KeyboardButtonBinding> keyboard_button_bindings;
+  std::vector<MouseButtonBinding>    mouse_button_bindings;
+  std::vector<JoystickButtonBinding> joystick_button_bindings;
+  std::vector<JoystickAxisBinding>   joystick_axis_bindings;
+
+  typedef std::map<std::string, SDLKey> String2Key;
+  String2Key string2key;
+
+  typedef std::map<int, SDL_Joystick*> JoystickHandles;
+  JoystickHandles joystick_handles;
+
+  bool open_joystick(int device);
+  
+public:
+  SDLDriver();
+  ~SDLDriver();
+
+  Button*   create_button  (const FileReader& reader, Control* parent);
+  Axis*     create_axis    (const FileReader& reader, Control* parent);
+  Scroller* create_scroller(const FileReader& reader, Control* parent);
+  Pointer*  create_pointer (const FileReader& reader, Control* parent);
+
+  void update(float delta);
+  std::string get_name() const { return "sdl"; }
+};
+
+} // namespace Input
+
+#endif
+
+/* EOF */


Property changes on: trunk/pingus/src/input/sdl_driver.hpp
___________________________________________________________________
Name: svn:keywords
   + Id
Name: svn:eol-style
   + native

Added: trunk/pingus/src/input/usbmouse_driver.cpp
===================================================================
--- trunk/pingus/src/input/usbmouse_driver.cpp  2007-09-02 04:26:33 UTC (rev 
3061)
+++ trunk/pingus/src/input/usbmouse_driver.cpp  2007-09-02 04:29:05 UTC (rev 
3062)
@@ -0,0 +1,292 @@
+/*  $Id$
+**   __      __ __             ___        __   __ __   __
+**  /  \    /  \__| ____    __| _/_______/  |_|__|  | |  |   ____
+**  \   \/\/   /  |/    \  / __ |/  ___/\   __\  |  | |  | _/ __ \
+**   \        /|  |   |  \/ /_/ |\___ \  |  | |  |  |_|  |_\  ___/
+**    \__/\  / |__|___|  /\____ /____  > |__| |__|____/____/\___  >
+**         \/          \/      \/    \/                         \/
+**  Copyright (C) 2007 Ingo Ruhnke <address@hidden>
+**
+**  This program is free software; you can redistribute it and/or
+**  modify it under the terms of the GNU General Public License
+**  as published by the Free Software Foundation; either version 2
+**  of the License, or (at your option) any later version.
+**
+**  This program is distributed in the hope that it will be useful,
+**  but WITHOUT ANY WARRANTY; without even the implied warranty of
+**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+**  GNU General Public License for more details.
+** 
+**  You should have received a copy of the GNU General Public License
+**  along with this program; if not, write to the Free Software
+**  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+**  02111-1307, USA.
+*/
+
+#include <stdexcept>
+#include <sys/ioctl.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <iostream>
+#include <errno.h>
+
+#include "math/vector2i.hpp"
+#include "usbmouse_driver.hpp"
+
+namespace Input {
+
+class USBMouse
+{
+private:
+  int fd;
+  Vector2i mouse_pos;
+
+  std::string device;
+  std::vector<bool> buttons;
+
+  std::vector<Pointer*> pointer_bindings;
+  std::vector<std::vector<Button*> >  button_bindings;
+  
+public: 
+  USBMouse(const std::string& device_) 
+    : device(device_),
+      buttons(5),
+      button_bindings(5)
+  {
+    fd = open(device.c_str (), O_RDWR | O_NONBLOCK);
+
+    if (fd == -1)
+      {
+        throw std::runtime_error(strerror(errno));
+      }
+
+    {
+      // Microsoft init sequence for Explorer mouse (wheel + 5 buttons)
+      static unsigned char data[] = { 0xF3, 0xC8, 
+                                      0xF3, 0xC8,
+                                      0xF3, 0x50 };
+      write(fd, data, sizeof(data));
+    }
+
+    char data[4];
+    read(fd, data, sizeof (data));
+    read(fd, data, sizeof (data));
+    read(fd, data, sizeof (data));
+  }
+
+  ~USBMouse()
+  {
+    close(fd);
+  }
+
+  void add_listener(Pointer* p)
+  {
+    pointer_bindings.push_back(p);
+  }
+
+  void add_listener(int i, Button* b)
+  {
+    assert(i >= 0 && i < int(button_bindings.size()));
+    button_bindings[i].push_back(b);
+  }
+
+  std::string get_device() const { 
+    return device; 
+  }
+
+  void update(float delta)
+  {
+    unsigned char data[4];
+    while(read(fd, data, sizeof (data)) > 0)
+      {                
+        // Mouse Move:
+        int delta_x = (data[0] & 0x10) ? data[1]-256 : data[1];
+        int delta_y = (data[0] & 0x20) ? data[2]-256 : data[2];
+
+        if (delta_x != 0 || delta_y != 0)
+          {
+            mouse_pos.x += delta_x;
+            mouse_pos.y -= delta_y; // y-axis is reversed on-screen
+
+            if (mouse_pos.x < 0) 
+              mouse_pos.x = 0;
+            else if (mouse_pos.x > 800) // FIXME: Shouldn't hardcore 800x600 
resolution
+              mouse_pos.x = 800 - 1;
+
+            if (mouse_pos.y < 0) 
+              mouse_pos.y = 0;
+            else if (mouse_pos.y > 600)
+              mouse_pos.y = 600 - 1;
+
+            for(std::vector<Pointer*>::iterator i = pointer_bindings.begin(); 
i != pointer_bindings.end(); ++i)
+              (*i)->set_pos(mouse_pos);
+
+            // send_ball_move(delta_x, delta_y);
+            // send_pointer_move(mouse_pos);
+          }
+
+        // Scrollwheel move
+        int delta_z = (data[3] & 0x08) ? (data[3] & 0x0F)-16 : (data[3] & 
0x0F);
+
+        if (delta_z > 0)
+          {
+            while (delta_z != 0)
+              {
+                --delta_z;
+                //send_key_event(CL_MOUSE_WHEEL_DOWN, true);
+                //send_key_event(CL_MOUSE_WHEEL_DOWN, false);
+              }
+          } 
+        else if (delta_z < 0)
+          {
+            while (delta_z != 0)
+              {
+                ++delta_z;
+                //send_key_event(CL_MOUSE_WHEEL_UP, true);
+                //send_key_event(CL_MOUSE_WHEEL_UP, false);
+              }
+          }
+
+        // Button event
+        std::vector<bool> new_state(5);
+
+        new_state[0] = ((data[0] &  1)>0);
+        new_state[1] = ((data[0] &  2)>0);
+        new_state[2] = ((data[0] &  4)>0);
+        new_state[3] = ((data[3] & 16)>0);
+        new_state[4] = ((data[3] & 32)>0);
+
+        for (int i = 0; i < 5; ++i)
+          {
+            if (new_state[i] != buttons[i])
+              {
+                buttons[i] = new_state[i];
+
+                for(std::vector<Button*>::iterator j = 
button_bindings[i].begin();
+                    j != button_bindings[i].end(); ++j)
+                  {
+                    (*j)->set_state(buttons[i] ? BUTTON_PRESSED : 
BUTTON_RELEASED);
+                  }
+              }
+          }
+
+        buttons = new_state;
+      }
+  }
+};
+
+USBMouseDriver::USBMouseDriver()
+{
+}
+
+USBMouseDriver::~USBMouseDriver()
+{
+  for(USBMice::iterator i = usbmice.begin(); i != usbmice.end(); ++i)
+    delete *i;
+}
+
+void
+USBMouseDriver::update(float delta)
+{
+  for(USBMice::iterator i = usbmice.begin(); i != usbmice.end(); ++i)
+    (*i)->update(delta);
+}
+
+Button*
+USBMouseDriver::create_button(const FileReader& reader, Control* parent)
+{
+  if (reader.get_name() == "usbmouse:button")
+    {
+      std::string device;
+      if (reader.read_string("device", device))
+        {
+          int i;
+          if (reader.read_int("button", i))
+            {
+              USBMouse* mouse = get_mouse(device);
+              if (mouse)
+                {
+                  Button* button = new Button(parent);
+                  mouse->add_listener(i, button);
+                  return button;
+                }
+              else
+                {
+                  return 0;
+                }
+            }
+          else
+            {
+              std::cout << "USBMouseDriver: 'button' entry is missing" << 
std::endl;
+              return 0;
+            }
+        }
+      else
+        {
+          std::cout << "USBMouseDriver: 'device' entry is missing" << 
std::endl;
+          return 0;
+        }
+    }
+  else
+    {
+      return 0;
+    }
+}
+
+Pointer*
+USBMouseDriver::create_pointer(const FileReader& reader, Control* parent)
+{
+  if (reader.get_name() == "usbmouse:pointer")
+    {
+      std::string device;
+      if (reader.read_string("device", device))
+        {
+          USBMouse* mouse = get_mouse(device);
+          if (mouse)
+            {
+              Pointer* pointer = new Pointer(parent);
+              mouse->add_listener(pointer);
+              return pointer;
+            }
+          else
+            {
+              return 0;
+            }
+        }
+      else
+        {
+          std::cout << "USBMouseDriver: 'device' entry is missing" << 
std::endl;
+          return 0;
+        }
+    }
+  else
+    {
+      return 0;
+    }
+}
+
+USBMouse*
+USBMouseDriver::get_mouse(const std::string& device)
+{
+  for(USBMice::iterator i = usbmice.begin(); i != usbmice.end(); ++i)
+    {
+      if ((*i)->get_device() == device)
+        return *i;
+    }
+
+  try 
+    {
+      USBMouse* usbmouse = new USBMouse(device);
+      usbmice.push_back(usbmouse);
+      return usbmouse;
+    }
+  catch (std::exception& err) 
+    {
+      std::cout << "USBMouseDriver: " << err.what() << std::endl;
+      return 0;
+    }
+}
+
+} // namespace Input
+
+/* EOF */


Property changes on: trunk/pingus/src/input/usbmouse_driver.cpp
___________________________________________________________________
Name: svn:keywords
   + Id
Name: svn:eol-style
   + native

Added: trunk/pingus/src/input/usbmouse_driver.hpp
===================================================================
--- trunk/pingus/src/input/usbmouse_driver.hpp  2007-09-02 04:26:33 UTC (rev 
3061)
+++ trunk/pingus/src/input/usbmouse_driver.hpp  2007-09-02 04:29:05 UTC (rev 
3062)
@@ -0,0 +1,61 @@
+/*  $Id$
+**
+**  Pingus - A free Lemmings clone
+**  Copyright (C) 2007 Ingo Ruhnke <address@hidden>
+**
+**  This program is free software; you can redistribute it and/or
+**  modify it under the terms of the GNU General Public License
+**  as published by the Free Software Foundation; either version 2
+**  of the License, or (at your option) any later version.
+**
+**  This program is distributed in the hope that it will be useful,
+**  but WITHOUT ANY WARRANTY; without even the implied warranty of
+**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+**  GNU General Public License for more details.
+** 
+**  You should have received a copy of the GNU General Public License
+**  along with this program; if not, write to the Free Software
+**  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+**  02111-1307, USA.
+*/
+
+#ifndef HEADER_USBMOUSE_DRIVER_HPP
+#define HEADER_USBMOUSE_DRIVER_HPP
+
+#include <vector>
+#include "driver.hpp"
+
+namespace Input {
+
+class USBMouse;
+
+/** 
+ */
+class USBMouseDriver : public Driver
+{
+private:
+  typedef std::vector<USBMouse*> USBMice;
+  USBMice usbmice;
+
+public:
+  USBMouseDriver();
+  ~USBMouseDriver();
+
+  std::string get_name() const { return "usbmouse"; }
+
+  void update(float delta);
+  
+  Button*   create_button  (const FileReader& reader, Control* parent);
+  Axis*     create_axis    (const FileReader& reader, Control* parent) { 
return 0; } 
+  Scroller* create_scroller(const FileReader& reader, Control* parent) { 
return 0; }
+  Pointer*  create_pointer (const FileReader& reader, Control* parent);
+
+private:
+  USBMouse* get_mouse(const std::string& device);
+};
+
+} // namespace Input
+
+#endif
+
+/* EOF */


Property changes on: trunk/pingus/src/input/usbmouse_driver.hpp
___________________________________________________________________
Name: svn:keywords
   + Id
Name: svn:eol-style
   + native

Added: trunk/pingus/src/input/wiimote.cpp
===================================================================
--- trunk/pingus/src/input/wiimote.cpp  2007-09-02 04:26:33 UTC (rev 3061)
+++ trunk/pingus/src/input/wiimote.cpp  2007-09-02 04:29:05 UTC (rev 3062)
@@ -0,0 +1,503 @@
+/*  $Id$
+**   __      __ __             ___        __   __ __   __
+**  /  \    /  \__| ____    __| _/_______/  |_|__|  | |  |   ____
+**  \   \/\/   /  |/    \  / __ |/  ___/\   __\  |  | |  | _/ __ \
+**   \        /|  |   |  \/ /_/ |\___ \  |  | |  |  |_|  |_\  ___/
+**    \__/\  / |__|___|  /\____ /____  > |__| |__|____/____/\___  >
+**         \/          \/      \/    \/                         \/
+**  Copyright (C) 2007 Ingo Ruhnke <address@hidden>
+**
+**  This program is free software; you can redistribute it and/or
+**  modify it under the terms of the GNU General Public License
+**  as published by the Free Software Foundation; either version 2
+**  of the License, or (at your option) any later version.
+**
+**  This program is distributed in the hope that it will be useful,
+**  but WITHOUT ANY WARRANTY; without even the implied warranty of
+**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+**  GNU General Public License for more details.
+** 
+**  You should have received a copy of the GNU General Public License
+**  along with this program; if not, write to the Free Software
+**  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+**  02111-1307, USA.
+*/
+
+#include <iostream>
+#include <assert.h>
+#include <pthread.h>
+#include "math.hpp"
+#include "wiimote.hpp"
+
+Wiimote* wiimote = 0;
+
+#ifdef HAVE_CWIID
+
+void
+Wiimote::init()
+{
+  if (!wiimote)
+    wiimote = new Wiimote();
+}
+
+void
+Wiimote::deinit()
+{
+  delete wiimote;
+  wiimote = 0;
+}
+
+Wiimote::Wiimote()
+  : m_wiimote(0),
+    m_rumble(false),
+    m_led_state(0),
+    m_nunchuk_btns(0),
+    m_nunchuk_stick_x(0),
+    m_nunchuk_stick_y(0),
+    m_buttons(0)
+{
+  pthread_mutex_init(&mutex, NULL);
+
+  assert(wiimote == 0);
+  wiimote = this;
+  
+  cwiid_set_err(&Wiimote::err_callback);
+}
+
+Wiimote::~Wiimote()
+{
+  disconnect();
+  pthread_mutex_destroy(&mutex);
+}
+
+void
+Wiimote::connect()
+{
+  assert(m_wiimote == 0);
+
+  /* Connect to any wiimote */
+  bdaddr_t bdaddr = *BDADDR_ANY;
+
+  /* Connect to address in string WIIMOTE_BDADDR */
+  /* str2ba(WIIMOTE_BDADDR, &bdaddr); */
+
+  /* Connect to the wiimote */
+  printf("Put Wiimote in discoverable mode now (press 1+2)...\n");
+
+  if (!(m_wiimote = cwiid_connect(&bdaddr, CWIID_FLAG_MESG_IFC))) 
+    {
+      fprintf(stderr, "Unable to connect to wiimote\n");
+    }
+  else 
+    {
+      std::cout << "Wiimote connected: " << m_wiimote << std::endl;
+      if (cwiid_set_mesg_callback(m_wiimote, &Wiimote::mesg_callback)) {
+        std::cerr << "Unable to set message callback" << std::endl;
+      }
+
+      if (cwiid_command(m_wiimote, CWIID_CMD_RPT_MODE, 
+                        CWIID_RPT_STATUS  |
+                        CWIID_RPT_NUNCHUK |
+                        CWIID_RPT_ACC     |
+                        CWIID_RPT_BTN))
+        {
+          std::cerr << "Wiimote: Error setting report mode" << std::endl;
+        }
+
+      { // read calibration data
+       uint8_t buf[7];
+
+        if (cwiid_read(m_wiimote, CWIID_RW_EEPROM, 0x16, 7, buf))
+          {
+            std::cout << "Wiimote: Unable to retrieve accelerometer 
calibration" << std::endl;
+          }
+        else
+          {
+            wiimote_zero.x = buf[0];
+            wiimote_zero.y = buf[1];
+            wiimote_zero.z = buf[2];
+
+            wiimote_one.x  = buf[4];
+            wiimote_one.y  = buf[5];
+            wiimote_one.z  = buf[6];
+          }
+
+        if (cwiid_read(m_wiimote, CWIID_RW_REG | CWIID_RW_DECODE, 0xA40020, 7, 
buf))
+          {
+            std::cout << "Wiimote: Unable to retrieve wiimote accelerometer 
calibration" << std::endl;
+          }
+        else
+          {
+            nunchuk_zero.x = buf[0];
+            nunchuk_zero.y = buf[1];
+            nunchuk_zero.z = buf[2];
+            
+            nunchuk_one.x  = buf[4];
+            nunchuk_one.y  = buf[5];
+            nunchuk_one.z  = buf[6];
+          }
+
+        std::cout << "Wiimote Calibration: "
+                  << (int)wiimote_zero.x << ", "
+                  << (int)wiimote_zero.x << ", "
+                  << (int)wiimote_zero.x << " - "
+                  << (int)wiimote_one.x << ", "
+                  << (int)wiimote_one.x << ", "
+                  << (int)wiimote_one.x << std::endl;
+
+        std::cout << "Nunchuk Calibration: "
+                  << (int)nunchuk_zero.x << ", "
+                  << (int)nunchuk_zero.x << ", "
+                  << (int)nunchuk_zero.x << " - "
+                  << (int)nunchuk_one.x << ", "
+                  << (int)nunchuk_one.x << ", "
+                  << (int)nunchuk_one.x << std::endl;
+          
+      }
+    }
+}
+
+void
+Wiimote::disconnect()
+{
+  if (m_wiimote)
+    {
+      cwiid_disconnect(m_wiimote);
+      m_wiimote = 0;
+    }
+}
+
+void
+Wiimote::set_led(unsigned char led_state)
+{
+  if (m_led_state != led_state)
+    {
+      //std::cout << "Wiimote: " << (int)m_led_state << std::endl;
+      m_led_state = led_state;
+
+      if (cwiid_command(m_wiimote, CWIID_CMD_LED, m_led_state)) {
+        fprintf(stderr, "Error setting LEDs \n");
+      }
+    }
+}
+
+void
+Wiimote::set_led(int num, bool state)
+{
+  assert(num >= 1 && num <= 4);
+
+  int new_led_state = m_led_state;
+  if (state)
+    new_led_state |= (1 << (num-1));
+  else // (!state)
+    new_led_state &= ~(1 << (num-1));
+
+  set_led(new_led_state);
+}
+
+void
+Wiimote::set_rumble(bool r)
+{
+  if (r != m_rumble)
+    {
+      m_rumble = r;
+
+      if (cwiid_command(m_wiimote, CWIID_CMD_RUMBLE, m_rumble)) {
+        std::cerr << "Error setting rumble" << std::endl;
+      }
+    }
+}
+
+void
+Wiimote::add_button_event(int device, int button, bool down)
+{
+  // std::cout << "Wiimote::add_button_event: " << device << " " << button << 
" " << down << std::endl;
+  WiimoteEvent event;
+
+  event.type = WiimoteEvent::WIIMOTE_BUTTON_EVENT;
+  event.button.device = 0;
+  event.button.button = button;
+  event.button.down   = down;
+
+  events.push_back(event);
+}
+
+void
+Wiimote::add_axis_event(int device, int axis, float pos)
+{
+  //std::cout << "Wiimote::add_axis_event: " << device << " " << axis << " " 
<< pos << std::endl;
+
+  WiimoteEvent event;
+
+  event.type = WiimoteEvent::WIIMOTE_AXIS_EVENT;
+  event.axis.device = 0;
+  event.axis.axis = axis;
+  event.axis.pos  = pos;
+
+  events.push_back(event); 
+}
+
+void
+Wiimote::add_acc_event(int device, int accelerometer, float x, float y, float 
z)
+{
+  WiimoteEvent event;
+
+  event.type = WiimoteEvent::WIIMOTE_ACC_EVENT;
+  event.acc.device = 0;
+  event.acc.accelerometer = accelerometer;
+  event.acc.x = x;
+  event.acc.y = y;
+  event.acc.z = z;
+
+  events.push_back(event);  
+}
+
+
+void
+Wiimote::on_status(const cwiid_status_mesg& msg)
+{
+  printf("Status Report: battery=%d extension=", msg.battery);
+  switch (msg.ext_type)
+    {
+    case CWIID_EXT_NONE:
+      printf("none");
+      break;
+
+    case CWIID_EXT_NUNCHUK:
+      printf("Nunchuk");
+      break;
+
+    case CWIID_EXT_CLASSIC:
+      printf("Classic Controller");
+      break;
+
+    default:
+      printf("Unknown Extension");
+      break;
+    }
+  printf("\n");
+}
+
+void
+Wiimote::on_error(const cwiid_error_mesg& msg)
+{
+  std::cout << "On Error" << std::endl;
+
+  if (m_wiimote)
+    {
+      if (cwiid_disconnect(m_wiimote)) 
+        {
+          fprintf(stderr, "Error on wiimote disconnect\n");
+          m_wiimote = 0;
+        }
+    }
+}
+
+void
+Wiimote::on_button(const cwiid_btn_mesg& msg)
+{
+#define CHECK_BTN(btn, num) if (changes & btn) add_button_event(0, num, 
m_buttons & btn)
+
+  uint16_t changes = m_buttons ^ msg.buttons;
+  m_buttons = msg.buttons;
+ 
+  CHECK_BTN(CWIID_BTN_A, 0);
+  CHECK_BTN(CWIID_BTN_B, 1);
+
+  CHECK_BTN(CWIID_BTN_LEFT,  2);
+  CHECK_BTN(CWIID_BTN_RIGHT, 3);
+  CHECK_BTN(CWIID_BTN_UP,    4);
+  CHECK_BTN(CWIID_BTN_DOWN,  5);
+
+  CHECK_BTN(CWIID_BTN_PLUS,  6);
+  CHECK_BTN(CWIID_BTN_HOME,  7);
+  CHECK_BTN(CWIID_BTN_MINUS, 8);
+
+  CHECK_BTN(CWIID_BTN_1,  9);
+  CHECK_BTN(CWIID_BTN_2, 10);
+}
+
+void
+Wiimote::on_acc(const cwiid_acc_mesg& msg)
+{
+  //printf("Acc Report: x=%d, y=%d, z=%d\n", msg.acc[0], msg.acc[1], 
msg.acc[2]);
+
+  add_acc_event(0, 0, 
+                (msg.acc[0] - wiimote_zero.x) / float(wiimote_one.x - 
wiimote_zero.x),
+                (msg.acc[1] - wiimote_zero.y) / float(wiimote_one.y - 
wiimote_zero.y),
+                (msg.acc[2] - wiimote_zero.z) / float(wiimote_one.z - 
wiimote_zero.z));
+}
+
+void
+Wiimote::on_ir(const cwiid_ir_mesg& msg)
+{
+  printf("IR Report: ");
+  for (int i = 0; i < CWIID_IR_SRC_COUNT; ++i)
+    {
+      if (msg.src[i].valid) {
+        printf("(%d,%d) ", msg.src[i].pos[0], msg.src[i].pos[1]);
+      }
+    }
+}
+
+/** Convert value to float while taking calibration data, left/center/right 
into account */
+inline float to_float(uint8_t min, 
+                      uint8_t center, 
+                      uint8_t max, 
+                      uint8_t value)
+{
+  if (value < center)
+    {
+      return Math::clamp(-1.0f, -(center - value) / float(center - min), 1.0f);
+    }
+  else if (value > center)
+    {
+      return Math::clamp(-1.0f, (value - center) / float(max - center), 1.0f);
+    }
+  else 
+    {
+      return 0.0f;
+    }
+}
+
+void
+Wiimote::on_nunchuck(const cwiid_nunchuk_mesg& msg)
+{
+  uint8_t changes = m_nunchuk_btns ^ msg.buttons;
+  m_nunchuk_btns  = msg.buttons;
+
+#define CHECK_NCK_BTN(btn, num) if (changes & btn) add_button_event(0, num, 
m_nunchuk_btns & btn)
+      
+  CHECK_NCK_BTN(CWIID_NUNCHUK_BTN_Z, 11);
+  CHECK_NCK_BTN(CWIID_NUNCHUK_BTN_C, 12);
+  
+  // FIXME: Read real calibration data, instead of hardcoded one
+  float nunchuk_stick_x =  to_float(37, 129, 231, msg.stick[0]);
+  float nunchuk_stick_y = -to_float(22, 119, 213, msg.stick[1]);
+
+  if (m_nunchuk_stick_x != nunchuk_stick_x)
+    {
+      m_nunchuk_stick_x = nunchuk_stick_x;
+      add_axis_event(0, 0, m_nunchuk_stick_x);
+    } 
+
+  if (m_nunchuk_stick_y != nunchuk_stick_y)
+    {
+      m_nunchuk_stick_y = nunchuk_stick_y;
+      add_axis_event(0, 1, m_nunchuk_stick_y);
+    }
+
+  add_acc_event(0, 1, 
+                (msg.acc[0] - nunchuk_zero.x) / float(nunchuk_one.x - 
nunchuk_zero.x),
+                (msg.acc[1] - nunchuk_zero.y) / float(nunchuk_one.y - 
nunchuk_zero.y),
+                (msg.acc[2] - nunchuk_zero.z) / float(nunchuk_one.z - 
nunchuk_zero.z));
+  if (0)
+    printf("Nunchuk Report: btns=%.2X stick=(%3d,%3d) (%5.2f, %5.2f) acc.x=%d 
acc.y=%d acc.z=%d\n", 
+           msg.buttons,
+           msg.stick[0], msg.stick[1], 
+           m_nunchuk_stick_x,
+           m_nunchuk_stick_y,
+           msg.acc[0], msg.acc[1], msg.acc[2]);
+}
+
+void
+Wiimote::on_classic(const cwiid_classic_mesg& msg)
+{
+  printf("Classic Report: btns=%.4X l_stick=(%d,%d) r_stick=(%d,%d) "
+         "l=%d r=%d\n", msg.buttons,
+         msg.l_stick[0], msg.l_stick[1],
+         msg.r_stick[0], msg.r_stick[1],
+         msg.l, msg.r);
+}
+
+std::vector<WiimoteEvent>
+Wiimote::pop_events()
+{
+  pthread_mutex_lock(&mutex);
+  std::vector<WiimoteEvent> ret = events;
+  events.clear();
+  pthread_mutex_unlock(&mutex);
+  return ret;
+}
+
+// Callback function that get called by the Wiimote thread
+void
+Wiimote::err(cwiid_wiimote_t* w, const char *s, va_list ap)
+{
+  pthread_mutex_lock(&mutex);
+
+  if (w) 
+    printf("%d:", cwiid_get_id(w));
+  else 
+    printf("-1:");
+
+  vprintf(s, ap);
+  printf("\n");  
+
+  pthread_mutex_unlock(&mutex);
+}
+
+void
+Wiimote::mesg(cwiid_wiimote_t* w, int mesg_count, union cwiid_mesg mesg[])
+{
+  pthread_mutex_lock(&mutex);
+
+  //std::cout << "StatusCallback: " << w << " " << mesg_count << std::endl;
+  for (int i=0; i < mesg_count; i++)
+    {
+      switch (mesg[i].type) 
+        {
+        case CWIID_MESG_STATUS:
+          wiimote->on_status(mesg[i].status_mesg);
+          break;
+
+        case CWIID_MESG_BTN:
+          wiimote->on_button(mesg[i].btn_mesg);
+          break;
+
+        case CWIID_MESG_ACC:
+          wiimote->on_acc(mesg[i].acc_mesg);
+          break;
+
+        case CWIID_MESG_IR:
+          wiimote->on_ir(mesg[i].ir_mesg);
+          break;
+
+        case CWIID_MESG_NUNCHUK:
+          wiimote->on_nunchuck(mesg[i].nunchuk_mesg);
+          break;
+
+        case CWIID_MESG_CLASSIC:
+          wiimote->on_classic(mesg[i].classic_mesg);
+          break;
+
+        case CWIID_MESG_ERROR:
+          wiimote->on_error(mesg[i].error_mesg);
+          break;
+
+        default:
+          printf("Wiimote: Unknown Report");
+          break;
+        }
+    }
+
+  pthread_mutex_unlock(&mutex);
+}
+
+// static callback functions
+  
+void
+Wiimote::err_callback(cwiid_wiimote_t* w, const char *s, va_list ap)
+{
+  wiimote->err(w, s, ap);
+}
+
+void
+Wiimote::mesg_callback(cwiid_wiimote_t* w, int mesg_count, union cwiid_mesg 
mesg[])
+{
+  wiimote->mesg(w, mesg_count, mesg);
+}
+
+#endif // HAVE_CWIID
+
+/* EOF */


Property changes on: trunk/pingus/src/input/wiimote.cpp
___________________________________________________________________
Name: svn:keywords
   + Id
Name: svn:eol-style
   + native

Added: trunk/pingus/src/input/wiimote.hpp
===================================================================
--- trunk/pingus/src/input/wiimote.hpp  2007-09-02 04:26:33 UTC (rev 3061)
+++ trunk/pingus/src/input/wiimote.hpp  2007-09-02 04:29:05 UTC (rev 3062)
@@ -0,0 +1,148 @@
+/*  $Id$
+**   __      __ __             ___        __   __ __   __
+**  /  \    /  \__| ____    __| _/_______/  |_|__|  | |  |   ____
+**  \   \/\/   /  |/    \  / __ |/  ___/\   __\  |  | |  | _/ __ \
+**   \        /|  |   |  \/ /_/ |\___ \  |  | |  |  |_|  |_\  ___/
+**    \__/\  / |__|___|  /\____ /____  > |__| |__|____/____/\___  >
+**         \/          \/      \/    \/                         \/
+**  Copyright (C) 2007 Ingo Ruhnke <address@hidden>
+**
+**  This program is free software; you can redistribute it and/or
+**  modify it under the terms of the GNU General Public License
+**  as published by the Free Software Foundation; either version 2
+**  of the License, or (at your option) any later version.
+**
+**  This program is distributed in the hope that it will be useful,
+**  but WITHOUT ANY WARRANTY; without even the implied warranty of
+**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+**  GNU General Public License for more details.
+** 
+**  You should have received a copy of the GNU General Public License
+**  along with this program; if not, write to the Free Software
+**  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+**  02111-1307, USA.
+*/
+
+#ifndef HEADER_WIIMOTE_HPP
+#define HEADER_WIIMOTE_HPP
+
+#ifdef HAVE_CWIID
+
+#include <vector>
+#include "cwiid.h"
+
+struct WiimoteButtonEvent
+{
+  int  device;
+  int  button;
+  bool down; 
+};
+
+struct WiimoteAxisEvent
+{
+  int   device;
+  int   axis;
+  float pos;
+};
+
+struct WiimoteAccEvent
+{
+  int   device;
+  int   accelerometer;
+  float x;
+  float y;
+  float z;
+};
+
+struct WiimoteEvent
+{
+  enum { WIIMOTE_AXIS_EVENT, WIIMOTE_ACC_EVENT, WIIMOTE_BUTTON_EVENT } type;
+  union {
+    WiimoteAxisEvent   axis;
+    WiimoteButtonEvent button;
+    WiimoteAccEvent    acc;
+  };
+};
+
+struct AccCalibration
+{
+  uint8_t x;
+  uint8_t y;
+  uint8_t z;
+};
+
+/** */
+class Wiimote
+{
+public:
+  static void err_callback(cwiid_wiimote_t*, const char *s, va_list ap);
+  static void mesg_callback(cwiid_wiimote_t*, int mesg_count, union cwiid_mesg 
mesg[]);
+
+  static void init();
+  static void deinit();
+
+private:
+  pthread_mutex_t  mutex;
+  cwiid_wiimote_t* m_wiimote;
+  bool             m_rumble;
+  unsigned char    m_led_state;
+  uint8_t          m_nunchuk_btns;
+  float            m_nunchuk_stick_x;
+  float            m_nunchuk_stick_y;
+  uint16_t         m_buttons;
+
+  AccCalibration wiimote_zero;
+  AccCalibration wiimote_one;
+
+  AccCalibration nunchuk_zero;
+  AccCalibration nunchuk_one;
+
+  std::vector<WiimoteEvent> events;
+
+  void add_button_event(int device, int button, bool down);
+  void add_axis_event(int device, int axis, float pos);
+  void add_acc_event(int device, int accelerometer, float x, float y, float z);
+
+public:
+  Wiimote();
+  ~Wiimote();
+  
+  void connect();
+  void disconnect();
+
+  void set_led(int num, bool state);
+  void set_led(unsigned char led_state);
+  unsigned char get_led() const { return m_led_state; }
+
+  void set_rumble(bool t);
+  bool get_rumble() const { return m_rumble; }
+
+  std::vector<WiimoteEvent> pop_events();
+
+  bool is_connected() const { return m_wiimote != 0; }
+
+  // Callback functions
+  void on_status  (const cwiid_status_mesg& msg);
+  void on_error   (const cwiid_error_mesg& msg);
+  void on_button  (const cwiid_btn_mesg& msg);
+  void on_acc     (const cwiid_acc_mesg& msg);
+  void on_ir      (const cwiid_ir_mesg& msg);
+  void on_nunchuck(const cwiid_nunchuk_mesg& msg);
+  void on_classic (const cwiid_classic_mesg& msg);
+  
+  void mesg(cwiid_wiimote_t*, int mesg_count, union cwiid_mesg mesg[]);
+  void err(cwiid_wiimote_t*, const char *s, va_list ap);
+
+private:
+  Wiimote(const Wiimote&);
+  Wiimote& operator=(const Wiimote&);
+};
+
+#endif // HAVE_CWIID
+
+class Wiimote;
+extern Wiimote* wiimote;
+
+#endif
+
+/* EOF */


Property changes on: trunk/pingus/src/input/wiimote.hpp
___________________________________________________________________
Name: svn:keywords
   + Id
Name: svn:eol-style
   + native

Added: trunk/pingus/src/input/wiimote_driver.cpp
===================================================================
--- trunk/pingus/src/input/wiimote_driver.cpp   2007-09-02 04:26:33 UTC (rev 
3061)
+++ trunk/pingus/src/input/wiimote_driver.cpp   2007-09-02 04:29:05 UTC (rev 
3062)
@@ -0,0 +1,227 @@
+/*  $Id$
+**   __      __ __             ___        __   __ __   __
+**  /  \    /  \__| ____    __| _/_______/  |_|__|  | |  |   ____
+**  \   \/\/   /  |/    \  / __ |/  ___/\   __\  |  | |  | _/ __ \
+**   \        /|  |   |  \/ /_/ |\___ \  |  | |  |  |_|  |_\  ___/
+**    \__/\  / |__|___|  /\____ /____  > |__| |__|____/____/\___  >
+**         \/          \/      \/    \/                         \/
+**  Copyright (C) 2007 Ingo Ruhnke <address@hidden>
+**
+**  This program is free software; you can redistribute it and/or
+**  modify it under the terms of the GNU General Public License
+**  as published by the Free Software Foundation; either version 2
+**  of the License, or (at your option) any later version.
+**
+**  This program is distributed in the hope that it will be useful,
+**  but WITHOUT ANY WARRANTY; without even the implied warranty of
+**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+**  GNU General Public License for more details.
+** 
+**  You should have received a copy of the GNU General Public License
+**  along with this program; if not, write to the Free Software
+**  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+**  02111-1307, USA.
+*/
+
+#include "string_util.hpp"
+#include "wiimote.hpp"
+#include "wiimote_driver.hpp"
+
+namespace Input {
+
+WiimoteDriver::WiimoteDriver()
+{
+  Wiimote::init();
+  wiimote->connect();
+}
+
+WiimoteDriver::~WiimoteDriver()
+{
+  Wiimote::deinit();
+}
+
+void
+WiimoteDriver::update(float delta)
+{
+  if (!wiimote || !wiimote->is_connected())
+    return;
+
+  std::vector<WiimoteEvent> events = wiimote->pop_events();
+  for(std::vector<WiimoteEvent>::iterator i = events.begin(); i != 
events.end(); ++i)
+    {
+      WiimoteEvent& event = *i;
+      if (event.type == WiimoteEvent::WIIMOTE_BUTTON_EVENT)
+        {
+          //if (event.button.down)
+          //  std::cout << event.button.button << std::endl;
+                  
+          for (std::vector<ButtonBinding>::const_iterator j = 
button_bindings.begin();
+               j != button_bindings.end();
+               ++j)
+            {
+              if (event.button.button == j->button)
+                {
+                  j->binding->set_state(event.button.down ? BUTTON_PRESSED : 
BUTTON_RELEASED);
+                }
+            }
+        }
+      else if (event.type == WiimoteEvent::WIIMOTE_AXIS_EVENT)
+        {
+          for (std::vector<AxisBinding>::const_iterator j = 
axis_bindings.begin();
+               j != axis_bindings.end(); ++j)
+            {
+              if (event.axis.axis == j->axis)
+                {
+                  j->binding->set_state(event.axis.pos);
+                }
+            }
+        }
+#if 0
+      else if (event.type == WiimoteEvent::WIIMOTE_ACC_EVENT)
+        {
+          if (event.acc.accelerometer == 0)
+            {
+              if (0)
+                printf("%d - %6.3f %6.3f %6.3f\n",  
+                       event.acc.accelerometer,
+                       event.acc.x,
+                       event.acc.y,
+                       event.acc.z);
+                 
+              float roll = atan(event.acc.x/event.acc.z);
+              if (event.acc.z <= 0.0) {
+                roll += M_PI * ((event.acc.x > 0.0) ? 1 : -1);
+              }
+              roll *= -1;
+
+              float pitch = atan(event.acc.y/event.acc.z*cos(roll));
+
+              add_axis_event(X2_AXIS, math::mid(-1.0f, -float(pitch / M_PI), 
1.0f));
+              add_axis_event(Y2_AXIS, math::mid(-1.0f, -float(roll  / M_PI), 
1.0f));
+
+              std::cout << boost::format("%|6.3f| %|6.3f|") % pitch % roll << 
std::endl;
+            }
+        }
+      else
+        {
+          assert(!"Never reached");
+        }
+#endif
+    }
+}
+
+Button*
+WiimoteDriver::create_button(const FileReader& reader, Control* parent) 
+{
+  std::string button;
+  if (reader.get_name() == "wiimote:button")
+    {
+      if (!reader.read_string("button", button))
+        {
+          std::cout << "WiimoteDriver: 'button' tag missing" << std::endl;
+          return 0;
+        }
+      else
+        {
+          button = StringUtil::to_lower(button);
+          int button_id = 0;
+          if (button == "a")
+            button_id = 0;
+          else if (button == "b")
+            button_id = 1;
+          else if (button == "dpad-left")
+            button_id = 2;
+          else if (button == "dpad-right")
+            button_id = 3;
+          else if (button == "dpad-up")
+            button_id = 4;
+          else if (button == "dpad-down")
+            button_id = 5;
+          else if (button == "+" || button == "plus")
+            button_id = 6;
+          else if (button == "home")
+            button_id = 7;
+          else if (button == "-" || button == "minus")
+            button_id = 8;
+          else if (button == "1")
+            button_id = 9;
+          else if (button == "2")
+            button_id = 10;
+          else if (button == "nunchuck:z")
+            button_id = 11;
+          else if (button == "nunchuck:c")
+            button_id = 12;
+          else
+            {
+              std::cout << "Error: WiimoteDriver: unknown button: " << button 
<< std::endl;
+              return 0;
+            }
+
+          ButtonBinding binding;
+          binding.binding = new Button(parent);
+          binding.button = button_id;
+          button_bindings.push_back(binding);
+
+          return binding.binding;
+        }
+    }
+  else
+    {
+      return 0;
+    }
+}
+
+Axis*
+WiimoteDriver::create_axis(const FileReader& reader, Control* parent) 
+{
+  std::string axis;
+  if (reader.get_name() == "wiimote:axis")
+    {
+      if (!reader.read_string("axis", axis))
+        {
+          std::cout << "WiimoteDriver: 'axis' tag missing" << std::endl;
+          return 0;
+        }
+      else
+        {
+          axis = StringUtil::to_lower(axis);
+          int axis_id = 0;
+          if (axis == "nunchuck:x")
+            axis_id = 0;
+          else if (axis == "nunchuck:y")
+            axis_id = 0;
+          else
+            {
+              std::cout << "WiimoteDriver: unknown axis name: " << axis << 
std::endl;
+              return 0;
+            }
+
+          AxisBinding binding;
+          binding.binding = new Axis(parent);
+          binding.axis = axis_id;
+          axis_bindings.push_back(binding);
+
+          return binding.binding;
+        }
+    }
+  else
+    {
+      return 0;
+    }
+}
+
+Scroller*
+WiimoteDriver::create_scroller(const FileReader& reader, Control* parent) 
+{
+  return 0; 
+}
+
+Pointer*
+WiimoteDriver::create_pointer (const FileReader& reader, Control* parent)
+{
+  return 0; 
+}
+
+} // namespace Input
+
+/* EOF */


Property changes on: trunk/pingus/src/input/wiimote_driver.cpp
___________________________________________________________________
Name: svn:keywords
   + Id
Name: svn:eol-style
   + native

Added: trunk/pingus/src/input/wiimote_driver.hpp
===================================================================
--- trunk/pingus/src/input/wiimote_driver.hpp   2007-09-02 04:26:33 UTC (rev 
3061)
+++ trunk/pingus/src/input/wiimote_driver.hpp   2007-09-02 04:29:05 UTC (rev 
3062)
@@ -0,0 +1,64 @@
+/*  $Id$
+**
+**  Pingus - A free Lemmings clone
+**  Copyright (C) 2007 Ingo Ruhnke <address@hidden>
+**
+**  This program is free software; you can redistribute it and/or
+**  modify it under the terms of the GNU General Public License
+**  as published by the Free Software Foundation; either version 2
+**  of the License, or (at your option) any later version.
+**
+**  This program is distributed in the hope that it will be useful,
+**  but WITHOUT ANY WARRANTY; without even the implied warranty of
+**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+**  GNU General Public License for more details.
+** 
+**  You should have received a copy of the GNU General Public License
+**  along with this program; if not, write to the Free Software
+**  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+**  02111-1307, USA.
+*/
+
+#ifndef HEADER_WIIMOTE_DRIVER_HPP
+#define HEADER_WIIMOTE_DRIVER_HPP
+
+#include "driver.hpp"
+
+namespace Input {
+
+/** */
+class WiimoteDriver : public Driver
+{
+private: 
+  struct ButtonBinding {
+    Button* binding;
+    int button;
+  };
+
+  struct AxisBinding {
+    Axis* binding;
+    int axis;
+  };
+
+  std::vector<ButtonBinding> button_bindings;
+  std::vector<AxisBinding>   axis_bindings;
+
+public:
+  WiimoteDriver();
+  ~WiimoteDriver();
+
+  void update(float delta);
+
+  std::string get_name() const { return "wiimote"; }
+  
+  Button*   create_button  (const FileReader& reader, Control* parent);
+  Axis*     create_axis    (const FileReader& reader, Control* parent);
+  Scroller* create_scroller(const FileReader& reader, Control* parent);
+  Pointer*  create_pointer (const FileReader& reader, Control* parent);
+};
+
+} // namespace Input
+
+#endif
+
+/* EOF */


Property changes on: trunk/pingus/src/input/wiimote_driver.hpp
___________________________________________________________________
Name: svn:keywords
   + Id
Name: svn:eol-style
   + native

Modified: trunk/pingus/src/worldmap/level_dot.cpp
===================================================================
--- trunk/pingus/src/worldmap/level_dot.cpp     2007-09-02 04:26:33 UTC (rev 
3061)
+++ trunk/pingus/src/worldmap/level_dot.cpp     2007-09-02 04:29:05 UTC (rev 
3062)
@@ -20,8 +20,6 @@
 #include <iostream>
 #include <math.h>
 #include "../font.hpp"
-#include "../input/controller.hpp"
-#include "../input/pointer.hpp"
 #include "../gettext.h"
 #include "../globals.hpp"
 #include "../system.hpp"
@@ -56,8 +54,9 @@
 void
 LevelDot::draw(DrawingContext& gc)
 {
-  Vector3f mpos = 
gc.screen_to_world(Vector3f(Input::Controller::get_current()->get_pointer()->get_x_pos(),
-    Input::Controller::get_current()->get_pointer()->get_y_pos()));
+  Vector3f mpos; // FIXME: get the controller coordinates from somewhere
+  //= 
gc.screen_to_world(Vector3f(Input::Controller::get_current()->get_pointer()->get_x_pos(),
+  //Input::Controller::get_current()->get_pointer()->get_y_pos()));
 
   float x = mpos.x - pos.x;
   float y = mpos.y - pos.y;





reply via email to

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