[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Pingus-CVS] r3047 - in trunk/pingus/src: . input2
From: |
grumbel at BerliOS |
Subject: |
[Pingus-CVS] r3047 - in trunk/pingus/src: . input2 |
Date: |
Sat, 1 Sep 2007 05:08:22 +0200 |
Author: grumbel
Date: 2007-09-01 05:08:21 +0200 (Sat, 01 Sep 2007)
New Revision: 3047
Added:
trunk/pingus/src/input2/
trunk/pingus/src/input2/SConstruct
trunk/pingus/src/input2/control.hpp
trunk/pingus/src/input2/controller.hpp
trunk/pingus/src/input2/controller_description.cpp
trunk/pingus/src/input2/controller_description.hpp
trunk/pingus/src/input2/core_driver.hpp
trunk/pingus/src/input2/driver.hpp
trunk/pingus/src/input2/event.hpp
trunk/pingus/src/input2/main.cpp
trunk/pingus/src/input2/manager.cpp
trunk/pingus/src/input2/manager.hpp
trunk/pingus/src/input2/sdl_driver.cpp
trunk/pingus/src/input2/sdl_driver.hpp
trunk/pingus/src/input2/usbmouse_driver.hpp
trunk/pingus/src/input2/wiimote_driver.hpp
Log:
- started to rewrite input system
Property changes on: trunk/pingus/src/input2
___________________________________________________________________
Name: svn:ignore
+ main
.sconsign.dblite
Added: trunk/pingus/src/input2/SConstruct
===================================================================
--- trunk/pingus/src/input2/SConstruct 2007-08-28 21:18:55 UTC (rev 3046)
+++ trunk/pingus/src/input2/SConstruct 2007-09-01 03:08:21 UTC (rev 3047)
@@ -0,0 +1,29 @@
+## -*- python -*-
+
+env = Environment(CCFLAGS = ['-O2', '-Wall', '-Werror', '-g'],
+ CPPPATH = ['..', '../..'])
+
+env.ParseConfig('sdl-config --cflags --libs')
+env['LIBS'] += ['SDL_image', 'SDL_mixer', 'png']
+
+env.Program('main', [
+ 'main.cpp',
+ 'controller_description.cpp',
+ 'sdl_driver.cpp',
+ 'manager.cpp',
+ '../file_reader.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/input2/control.hpp
===================================================================
--- trunk/pingus/src/input2/control.hpp 2007-08-28 21:18:55 UTC (rev 3046)
+++ trunk/pingus/src/input2/control.hpp 2007-09-01 03:08:21 UTC (rev 3047)
@@ -0,0 +1,230 @@
+/* $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"
+
+namespace Input {
+
+class Control {
+private:
+ Control* parent;
+
+public:
+ Control(Control* parent_)
+ : parent(parent_)
+ {}
+
+ virtual ~Control() {
+ }
+
+ void notify_parent()
+ {
+ if (parent)
+ {
+ parent->update(this);
+ }
+ else
+ {
+ std::cout << "Event thingy: " << std::endl;
+ }
+ }
+
+ virtual void update(Control* ctrl)
+ {
+ }
+};
+
+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 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
+{
+private:
+ Vector2f pos;
+
+public:
+ Pointer(Control* parent)
+ : Control(parent)
+ {}
+
+ void set_pos(const Vector2f& new_pos) {
+ if (pos != new_pos)
+ {
+ pos = new_pos;
+ notify_parent();
+ }
+ }
+};
+
+class Scroller : public Control
+{
+private:
+ Vector2f delta;
+
+public:
+ Scroller(Control* parent)
+ : Control(parent),
+ delta(0.0f, 0.0f)
+ {}
+
+ void set_delta(const Vector2f& new_delta) {
+ if (delta != new_delta)
+ {
+ delta = new_delta;
+ notify_parent();
+ }
+ }
+};
+
+class ButtonGroup : public Button
+{
+private:
+ std::vector<Button*> buttons;
+
+public:
+ ButtonGroup(Control* parent)
+ : Button(parent)
+ {}
+
+ 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 AxisGroup : public Axis {
+private:
+ std::vector<Axis*> axes;
+
+public:
+ AxisGroup(Control* parent)
+ : Axis(parent)
+ {}
+
+ void update(Control* ctrl)
+ {
+ float new_pos;
+
+ 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 PointerGroup : public Pointer
+{
+private:
+ std::vector<Pointer*> pointer;
+
+public:
+ PointerGroup(Control* parent)
+ : Pointer(parent)
+ {}
+};
+
+class ScrollerGroup : public Scroller
+{
+private:
+ std::vector<Scroller*> scrollers;
+
+public:
+ ScrollerGroup(Control* parent)
+ : Scroller(parent)
+ {}
+};
+
+} // namespace Input
+
+#endif
+
+/* EOF */
Property changes on: trunk/pingus/src/input2/control.hpp
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Added: trunk/pingus/src/input2/controller.hpp
===================================================================
--- trunk/pingus/src/input2/controller.hpp 2007-08-28 21:18:55 UTC (rev
3046)
+++ trunk/pingus/src/input2/controller.hpp 2007-09-01 03:08:21 UTC (rev
3047)
@@ -0,0 +1,61 @@
+// $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_CONTROLLER_HXX
+#define HEADER_PINGUS_INPUT_CONTROLLER_HXX
+
+#include <assert.h>
+#include "control.hpp"
+#include "event.hpp"
+
+namespace Input {
+
+class Controller
+{
+public:
+ // State Stuff
+ std::vector<Button*> buttons;
+ std::vector<Axis*> axis;
+ std::vector<Pointer*> pointer;
+ std::vector<Scroller*> scroller;
+
+ // Events
+ std::vector<Event> events;
+
+ Controller() {}
+ ~Controller() {}
+
+ void add_button(int id, Button* button) {
+ if (int(buttons.size())-1 < id)
+ buttons.resize(id+1);
+
+ assert(buttons[id] == 0);
+ buttons[id] = button;
+ }
+
+private:
+ Controller(const Controller&);
+ Controller& operator= (const Controller&);
+};
+
+} // namespace Input
+
+#endif
+
+/* EOF */
Property changes on: trunk/pingus/src/input2/controller.hpp
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Added: trunk/pingus/src/input2/controller_description.cpp
===================================================================
--- trunk/pingus/src/input2/controller_description.cpp 2007-08-28 21:18:55 UTC
(rev 3046)
+++ trunk/pingus/src/input2/controller_description.cpp 2007-09-01 03:08:21 UTC
(rev 3047)
@@ -0,0 +1,115 @@
+/* $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;
+}
+
+
+} // namespace Input
+
+/* EOF */
Property changes on: trunk/pingus/src/input2/controller_description.cpp
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Added: trunk/pingus/src/input2/controller_description.hpp
===================================================================
--- trunk/pingus/src/input2/controller_description.hpp 2007-08-28 21:18:55 UTC
(rev 3046)
+++ trunk/pingus/src/input2/controller_description.hpp 2007-09-01 03:08:21 UTC
(rev 3047)
@@ -0,0 +1,65 @@
+/* $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;
+};
+
+} // namespace Input
+
+#endif
+
+/* EOF */
Property changes on: trunk/pingus/src/input2/controller_description.hpp
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Added: trunk/pingus/src/input2/core_driver.hpp
===================================================================
--- trunk/pingus/src/input2/core_driver.hpp 2007-08-28 21:18:55 UTC (rev
3046)
+++ trunk/pingus/src/input2/core_driver.hpp 2007-09-01 03:08:21 UTC (rev
3047)
@@ -0,0 +1,53 @@
+/* $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
+
+namespace Input {
+
+/** */
+class CoreDriver : public Driver
+{
+private:
+
+public:
+ CoreDriver() {}
+ virtual ~CoreDriver() {}
+
+ std::string get_name() { return "core"; }
+ void update(float delta) {}
+
+ Button* create_button (const FileReader& reader, Control* parent) {
return 0; }
+ 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) {
return 0; }
+};
+
+} // namespace Input
+
+#endif
+
+/* EOF */
Property changes on: trunk/pingus/src/input2/core_driver.hpp
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Added: trunk/pingus/src/input2/driver.hpp
===================================================================
--- trunk/pingus/src/input2/driver.hpp 2007-08-28 21:18:55 UTC (rev 3046)
+++ trunk/pingus/src/input2/driver.hpp 2007-09-01 03:08:21 UTC (rev 3047)
@@ -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() =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/input2/driver.hpp
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Added: trunk/pingus/src/input2/event.hpp
===================================================================
--- trunk/pingus/src/input2/event.hpp 2007-08-28 21:18:55 UTC (rev 3046)
+++ trunk/pingus/src/input2/event.hpp 2007-09-01 03:08:21 UTC (rev 3047)
@@ -0,0 +1,169 @@
+// $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 ButtonName { 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,
+
+ MAX_BUTTON };
+
+
+enum ButtonState { BUTTON_RELEASED, BUTTON_PRESSED };
+
+struct ButtonEvent
+{
+ ButtonName name;
+ ButtonState state;
+};
+
+enum PointerName { standard };
+
+struct PointerEvent
+{
+ PointerName name;
+ float x;
+ float y;
+};
+
+enum AxisName { action };
+
+struct AxisEvent
+{
+ float dir;
+ AxisName name;
+};
+
+struct ScrollEvent
+{
+ 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(ButtonName name, ButtonState state)
+{
+ Event event;
+
+ event.type = BUTTON_EVENT_TYPE;
+ event.button.name = name;
+ event.button.state = state;
+
+ return event;
+}
+
+inline Event makePointerEvent(PointerName 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(float dir, AxisName name = action)
+{
+ Event event;
+
+ event.type = AXIS_EVENT_TYPE;
+ event.axis.dir = dir;
+ event.axis.name = name;
+
+ return event;
+}
+
+inline Event makeScrollEvent(float x_delta, float y_delta)
+{
+ Event event;
+
+ event.type = SCROLLER_EVENT_TYPE;
+ 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/input2/event.hpp
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Added: trunk/pingus/src/input2/main.cpp
===================================================================
--- trunk/pingus/src/input2/main.cpp 2007-08-28 21:18:55 UTC (rev 3046)
+++ trunk/pingus/src/input2/main.cpp 2007-09-01 03:08:21 UTC (rev 3047)
@@ -0,0 +1,34 @@
+#include <stdexcept>
+#include "SDL.h"
+#include "manager.hpp"
+
+int main()
+{
+ try {
+ if(SDL_Init(SDL_INIT_VIDEO) < 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;
+
+ manager.load("../../data/controller/input2.scm");
+
+ while(true)
+ {
+ 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/input2/main.cpp
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Added: trunk/pingus/src/input2/manager.cpp
===================================================================
--- trunk/pingus/src/input2/manager.cpp 2007-08-28 21:18:55 UTC (rev 3046)
+++ trunk/pingus/src/input2/manager.cpp 2007-09-01 03:08:21 UTC (rev 3047)
@@ -0,0 +1,195 @@
+/* $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 "manager.hpp"
+
+namespace Input {
+
+Manager::Manager()
+{
+ 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";
+ }
+}
+
+void
+Manager::load(const std::string& filename)
+{
+ 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"))
+ {
+ std::cout << "Pointer: '" << i->get_name() << "'" << std::endl;
+ }
+ else if (StringUtil::has_suffix(i->get_name(), "scroller"))
+ {
+ std::cout << "Scroller: '" << i->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)
+ {
+ std::string driver = get_driver_part(j->get_name());
+
+ Driver* drv = load_driver(driver);
+ if (drv)
+ {
+ Button* button = drv->create_button(*j, 0);
+ if (!button)
+ {
+ std::cout << "Driver '" << driver << "' couldn't
create button '"
+ << i->get_name() << "' => '"
+ << j->get_name() << "'" << std::endl;
+ }
+ else
+ {
+
controller.add_button(desc.get_definition(i->get_name()).id,
+ button);
+ }
+ }
+ else
+ {
+ std::cout << "Manager: Error: Couldn't find driver: '"
<< driver << "'" << std::endl;
+ }
+ }
+ }
+ else if (StringUtil::has_suffix(i->get_name(), "axis"))
+ {
+ std::cout << "Axis: '" << i->get_name() << "'" << std::endl;
+ }
+ else
+ {
+ PingusError::raise(std::string("Manager: Unkown Element in
Controller Config: ")
+ + i->get_name());
+ }
+ }
+ }
+}
+
+void
+Manager::update(float delta)
+{
+ for(Drivers::iterator i = drivers.begin(); i != drivers.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();
+ } else {
+ std::cout << "Manager: Unknown driver: " << name << std::endl;
+ return 0;
+ }
+
+ drivers.push_back(driver);
+ return driver;
+ }
+}
+
+} // namespace Input
+
+/* EOF */
Property changes on: trunk/pingus/src/input2/manager.cpp
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Added: trunk/pingus/src/input2/manager.hpp
===================================================================
--- trunk/pingus/src/input2/manager.hpp 2007-08-28 21:18:55 UTC (rev 3046)
+++ trunk/pingus/src/input2/manager.hpp 2007-09-01 03:08:21 UTC (rev 3047)
@@ -0,0 +1,52 @@
+// $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;
+
+ Controller controller;
+ ControllerDescription desc;
+public:
+ Manager();
+
+ void load(const std::string& filename);
+ void update(float delta);
+
+ Driver* load_driver(const std::string& name);
+ Driver* get_driver(const std::string& name);
+};
+
+} // namespace Input
+
+#endif
+
+/* EOF */
Property changes on: trunk/pingus/src/input2/manager.hpp
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Added: trunk/pingus/src/input2/sdl_driver.cpp
===================================================================
--- trunk/pingus/src/input2/sdl_driver.cpp 2007-08-28 21:18:55 UTC (rev
3046)
+++ trunk/pingus/src/input2/sdl_driver.cpp 2007-09-01 03:08:21 UTC (rev
3047)
@@ -0,0 +1,190 @@
+/* $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;
+ }
+}
+
+Button*
+SDLDriver::create_button(const FileReader& reader, Control* parent)
+{
+ //std::cout << "SDL: " << reader.get_name() << std::endl;
+ if (reader.get_name() == "sdl:joystick-button")
+ {
+ return 0;
+ }
+ else if (reader.get_name() == "sdl:mouse-button")
+ {
+ //MouseButtonBinding binding;
+ //reader.read_int("button", binding.button);
+ return 0;
+ }
+ 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)
+{
+ return 0;
+}
+
+Scroller*
+SDLDriver::create_scroller(const FileReader& reader, Control* parent)
+{
+ return 0;
+}
+
+Pointer*
+SDLDriver::create_pointer(const FileReader& reader, Control* parent)
+{
+ return 0;
+}
+
+void
+SDLDriver::update(float delta)
+{
+ //std::cout << "SDLEvent fetching" << std::endl;
+
+ // Let SDL fetch events
+ 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));
+ }
+ 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);
+ }
+ 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/input2/sdl_driver.cpp
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Added: trunk/pingus/src/input2/sdl_driver.hpp
===================================================================
--- trunk/pingus/src/input2/sdl_driver.hpp 2007-08-28 21:18:55 UTC (rev
3046)
+++ trunk/pingus/src/input2/sdl_driver.hpp 2007-09-01 03:08:21 UTC (rev
3047)
@@ -0,0 +1,96 @@
+/* $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 PointerBinding {
+ Pointer* binding;
+ };
+
+ 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;
+
+public:
+ 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() { return "sdl"; }
+};
+
+} // namespace Input
+
+#endif
+
+/* EOF */
Property changes on: trunk/pingus/src/input2/sdl_driver.hpp
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Added: trunk/pingus/src/input2/usbmouse_driver.hpp
===================================================================
--- trunk/pingus/src/input2/usbmouse_driver.hpp 2007-08-28 21:18:55 UTC (rev
3046)
+++ trunk/pingus/src/input2/usbmouse_driver.hpp 2007-09-01 03:08:21 UTC (rev
3047)
@@ -0,0 +1,36 @@
+/* $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
+
+/** */
+class USBMouseDriver
+{
+public:
+ USBMouseDriver();
+
+ void update(float delta);
+};
+
+#endif
+
+/* EOF */
Property changes on: trunk/pingus/src/input2/usbmouse_driver.hpp
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Added: trunk/pingus/src/input2/wiimote_driver.hpp
===================================================================
--- trunk/pingus/src/input2/wiimote_driver.hpp 2007-08-28 21:18:55 UTC (rev
3046)
+++ trunk/pingus/src/input2/wiimote_driver.hpp 2007-09-01 03:08:21 UTC (rev
3047)
@@ -0,0 +1,36 @@
+/* $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
+
+/** */
+class WiimoteDriver
+{
+public:
+ WiimoteDriver();
+
+ void update(float delta);
+};
+
+#endif
+
+/* EOF */
Property changes on: trunk/pingus/src/input2/wiimote_driver.hpp
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Pingus-CVS] r3047 - in trunk/pingus/src: . input2,
grumbel at BerliOS <=