pingus-cvs
[Top][All Lists]
Advanced

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

[Pingus-CVS] r3253 - in trunk/pingus/src: . input


From: grumbel at BerliOS
Subject: [Pingus-CVS] r3253 - in trunk/pingus/src: . input
Date: Fri, 28 Sep 2007 15:43:40 +0200

Author: grumbel
Date: 2007-09-28 15:43:40 +0200 (Fri, 28 Sep 2007)
New Revision: 3253

Removed:
   trunk/pingus/src/SConscript
Modified:
   trunk/pingus/src/input/
   trunk/pingus/src/input/evdev_device.cpp
   trunk/pingus/src/input/evdev_device.hpp
   trunk/pingus/src/input/evdev_driver.cpp
   trunk/pingus/src/input/evdev_driver.hpp
   trunk/pingus/src/input/manager.cpp
Log:
- implemented buttons and scroller for evdev

Deleted: trunk/pingus/src/SConscript
===================================================================
--- trunk/pingus/src/SConscript 2007-09-28 01:35:56 UTC (rev 3252)
+++ trunk/pingus/src/SConscript 2007-09-28 13:43:40 UTC (rev 3253)
@@ -1,306 +0,0 @@
-##  -*- python -*-
-##  $Id: pingus_main.hxx,v 1.14 2003/10/18 12:11:30 grumbel Exp $
-##
-##  Pingus - A free Lemmings clone
-##  Copyright (C) 1999 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.
-
-import os
-
-Import('env')
-
-sources = []
-
-sources += additional_sources
-
-sources = [
-# # 'gui/buffer_graphic_context.cpp', 
-# # 'pingus_level_test.cpp', 
-# # 'sound/slot_manager.cpp', 
-# # 'xml_eval.cpp',
-
-'action_holder.cpp', 
-'actions/angel.cpp', 
-'actions/basher.cpp', 
-'actions/blocker.cpp', 
-'actions/boarder.cpp', 
-'actions/bomber.cpp', 
-'actions/bridger.cpp', 
-'actions/climber.cpp', 
-'actions/digger.cpp', 
-'actions/drown.cpp', 
-'actions/exiter.cpp', 
-'actions/faller.cpp', 
-'actions/floater.cpp', 
-'actions/jumper.cpp', 
-'actions/laser_kill.cpp', 
-'actions/miner.cpp', 
-'actions/rocket_launcher.cpp', 
-'actions/slider.cpp', 
-'actions/smashed.cpp', 
-'actions/splashed.cpp', 
-'actions/superman.cpp', 
-'actions/teleported.cpp', 
-'actions/waiter.cpp', 
-'actions/walker.cpp', 
-'blitter.cpp',
-# 'blitter_test.cpp', 
-'capture_rectangle.cpp', 
-'cheat.cpp', 
-'client.cpp', 
-'col_map.cpp', 
-'collider.cpp', 
-'colliders/pingu_collider.cpp', 
-'components/action_button.cpp', 
-'components/button_panel.cpp', 
-'components/hurry_up.cpp', 
-'components/pingus_counter.cpp', 
-'components/playfield.cpp', 
-'components/smallmap.cpp', 
-'components/time_display.cpp', 
-'config.cpp', 
-'console.cpp', 
-'credits.cpp', 
-'debug.cpp', 
-'debug_stream.cpp', 
-# 'demo_player.cpp', 
-'demo_recorder.cpp', 
-# 'demo_session.cpp', 
-'direction.cpp', 
-'display/drawing_context.cpp', 
-'display/scene_context.cpp', 
-
-'editor/button.cpp',
-'editor/gui_style.cpp',
-'editor/context_menu.cpp',
-'editor/checkbox.cpp',
-'editor/editor_level.cpp', 
-'editor/panel.cpp',
-'editor/label.cpp',
-'editor/file_list.cpp',
-'editor/file_dialog.cpp',
-'editor/editor_screen.cpp',
-'editor/combobox.cpp', 
-'editor/editor_viewport.cpp', 
-'editor/level_objs.cpp',
-'editor/inputbox.cpp',
-'editor/object_selector.cpp',
-'editor/object_selector_list.cpp',
-'editor/object_selector_set.cpp',
-'editor/object_properties.cpp',
-'editor/level_properties.cpp',
-'editor/action_properties.cpp', 
-
-'command_line.cpp',
-'command_line_generic.cpp',
-
-'surface.cpp',
-'collision_mask.cpp',
-
-'exit_menu.cpp', 
-'file_dialog.cpp', 
-'file_dialog_item.cpp', 
-'file_reader.cpp',
-'sexpr_file_reader.cpp', 
-'sexpr_file_writer.cpp', 
-'fonts.cpp',
-'font.cpp',
-'font_test_screen.cpp',
-'font_description.cpp',
-'sprite.cpp',
-'fps_counter.cpp', 
-'game_session.cpp', 
-'game_session_result.cpp', 
-'game_time.cpp', 
-'gettext.cpp', 
-'global_event.cpp', 
-'globals.cpp', 
-'goal_manager.cpp', 
-'graphic_context_state.cpp', 
-'groundtype.cpp',
-'gui/component.cpp',
-'gui/checkbox.cpp',
-'gui/combobox.cpp', 
-'gui/cursor.cpp',
-'gui/group_component.cpp', 
-'gui/display.cpp', 
-'gui/gui_manager.cpp', 
-'gui/gui_screen.cpp', 
-'gui/input_box.cpp', 
-# 'gui/input_debug_screen.cpp', 
-'gui/root_gui_manager.cpp', 
-'gui/screen.cpp', 
-'gui/screen_manager.cpp', 
-'gui/screen_ptr.cpp', 
-'gui/surface_button.cpp',
-
-'line_iterator.cpp',
-
-'lisp/getters.cpp',
-'lisp/lexer.cpp',
-'lisp/lisp.cpp',
-'lisp/parser.cpp',
-
-'input/controller_description.cpp',
-'input/controller.cpp',
-'input/core_driver.cpp',
-'input/usbmouse_driver.cpp',
-'input/wiimote_driver.cpp',
-'input/wiimote.cpp',
-'input/xinput_driver.cpp',
-'input/xinput_device.cpp',
-'input/sdl_driver.cpp',
-'input/manager.cpp',
-
-# 'input/axes/button_axis.cpp', 
-# 'input/axes/inverted_axis.cpp', 
-# 'input/axes/joystick_axis.cpp', 
-# 'input/axes/multiple_axis.cpp', 
-# 'input/axis_factory.cpp', 
-# 'input/button_factory.cpp', 
-# 'input/buttons/double_button.cpp', 
-# 'input/buttons/joystick_button.cpp', 
-# 'input/buttons/key_button.cpp', 
-# 'input/buttons/mouse_button.cpp', 
-# 'input/buttons/multiple_button.cpp', 
-# 'input/buttons/triple_button.cpp', 
-# 'input/controller.cpp', 
-# 'input/pointer_factory.cpp', 
-# 'input/pointers/axis_pointer.cpp', 
-# 'input/pointers/mouse_pointer.cpp', 
-# 'input/pointers/multiple_pointer.cpp', 
-# 'input/scroller_factory.cpp', 
-# 'input/scrollers/axis_scroller.cpp', 
-# 'input/scrollers/inverted_scroller.cpp', 
-# 'input/scrollers/joystick_scroller.cpp', 
-# 'input/scrollers/mouse_scroller.cpp', 
-# 'input/scrollers/multiple_scroller.cpp', 
-# 'input/scrollers/pointer_scroller.cpp', 
-
-'layer_manager.cpp', 
-'components/menu_button.cpp', 
-'mover.cpp', 
-'movers/linear_mover.cpp', 
-'particles/explosive_particle.cpp', 
-'particles/ground_particle.cpp', 
-'particles/pingu_particle_holder.cpp', 
-'particles/rain_particle_holder.cpp', 
-'particles/smoke_particle_holder.cpp', 
-'particles/snow_particle_holder.cpp', 
-'path_manager.cpp',
-'pathname.cpp', 
-'pingu.cpp', 
-'pingu_action.cpp', 
-'pingu_action_factory.cpp', 
-'pingu_enums.cpp', 
-'pingu_holder.cpp', 
-'pingus_error.cpp', 
-'pingus_level.cpp', 
-'pingus_main.cpp', 
-'pingus_menu.cpp', 
-'pingus_menu_manager.cpp', 
-'pingus_sub_menu.cpp', 
-'plf_res_mgr.cpp', 
-# 'preview_renderer.cpp', 
-'res_descriptor.cpp', 
-'resource.cpp',
-'resource_manager.cpp', 
-'resource_modifier.cpp', 
-'result_screen.cpp', 
-'savegame.cpp', 
-'savegame_manager.cpp', 
-'screenshot.cpp', 
-'server.cpp', 
-'server_event.cpp', 
-'smallmap_image.cpp', 
-'sound/sound.cpp', 
-'sound/sound_dummy.cpp', 
-'sound/sound_real.cpp', 
-'sound/sound_res_mgr.cpp', 
-'ground_map.cpp', 
-'start_screen.cpp', 
-'stat_manager.cpp', 
-'state_sprite.cpp', 
-'story_screen.cpp', 
-'string_format.cpp',
-'string_util.cpp',
-'math/origin.cpp',
-'math/rect.cpp',
-'system.cpp', 
-'timer.cpp',
-'tinygettext/iconv.cpp',
-'tinygettext/po_file_reader.cpp',
-'tinygettext/dictionary_manager.cpp',
-'tinygettext/dictionary.cpp',
-'tinygettext/language_def.cpp',
-'true_server.cpp', 
-'math/vector2f.cpp',
-'math/vector2i.cpp',
-'math/vector3f.cpp',
-# 'physfs/physfs_sdl.cpp',
-# 'physfs/physfs_stream.cpp',
-'world.cpp', 
-
-'worldmap/dot.cpp', 
-'worldmap/dot_factory.cpp', 
-'worldmap/drawable.cpp', 
-'worldmap/drawable_factory.cpp', 
-'worldmap/graph.cpp', 
-'worldmap/level_dot.cpp', 
-'worldmap/manager.cpp', 
-'worldmap/metamap.cpp', 
-'worldmap/path.cpp', 
-'worldmap/path_drawable.cpp', 
-'worldmap/path_graph.cpp', 
-'worldmap/pingus.cpp', 
-'worldmap/sprite_drawable.cpp', 
-'worldmap/surface_drawable.cpp', 
-'worldmap/world_dot.cpp', 
-'worldmap/worldmap.cpp', 
-'worldmap/worldmap_story.cpp', 
-'worldobj.cpp', 
-'worldobj_factory.cpp', 
-'worldobjs/conveyor_belt.cpp', 
-'worldobjs/entrance.cpp', 
-'worldobjs/exit.cpp', 
-'worldobjs/fake_exit.cpp', 
-'worldobjs/groundpiece.cpp', 
-'worldobjs/guillotine.cpp', 
-'worldobjs/hammer.cpp', 
-'worldobjs/hotspot.cpp', 
-'worldobjs/ice_block.cpp', 
-'worldobjs/info_box.cpp', 
-'worldobjs/laser_exit.cpp', 
-'worldobjs/liquid.cpp', 
-'worldobjs/rain_generator.cpp', 
-'worldobjs/smasher.cpp', 
-'worldobjs/snow_generator.cpp', 
-'worldobjs/solid_color_background.cpp', 
-'worldobjs/spike.cpp', 
-'worldobjs/starfield_background.cpp', 
-'worldobjs/starfield_background_stars.cpp', 
-'worldobjs/surface_background.cpp', 
-'worldobjs/switch_door.cpp', 
-'worldobjs/teleporter.cpp',
-'worldobjs/teleporter_target.cpp', 
-'worldobjs/thunderstorm_background.cpp', 
-'worldobjs/woodthing.cpp',
-'../lib/binreloc/binreloc.c'
-]
-
-env.Program('../pingus', sources)
-
-## EOF ##


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

   + evdev
.sconsign.dblite


Modified: trunk/pingus/src/input/evdev_device.cpp
===================================================================
--- trunk/pingus/src/input/evdev_device.cpp     2007-09-28 01:35:56 UTC (rev 
3252)
+++ trunk/pingus/src/input/evdev_device.cpp     2007-09-28 13:43:40 UTC (rev 
3253)
@@ -95,7 +95,8 @@
                         struct input_absinfo absinfo;
                         ioctl(fd, EVIOCGABS(j), &absinfo);
                         // FIXME: we are ignoring absinfo.fuzz and
-                        // absinfo.flat, not sure what they are good for
+                        // absinfo.flat = deadzone
+                        // absinfo.fuzz = values in which range can be 
considered the same (jitter)
                         absolutes.push_back(Absolute(j, absinfo.minimum, 
absinfo.maximum, absinfo.value));
                       }
                     else if (i == EV_REL) 
@@ -138,10 +139,19 @@
 void
 EvdevDevice::process_relative(struct input_event& ev)
 {
-  int relative_index = get_relative_index_by_code(ev.code);
+  int idx = get_relative_index_by_code(ev.code);
 
-  relatives[relative_index].pos += ev.value;
+  relatives[idx].pos += ev.value;
 
+  for(std::vector<Scroller*>::iterator i = relatives[idx].bindings.begin(); 
+      i != relatives[idx].bindings.end(); ++i)
+    {
+      if (relatives[idx].binding_axis == 0)
+        (*i)->set_delta(Vector2f(-ev.value * 0.125f, 0)); // FIXME: make 
scaling and inversion configurable
+      else if (relatives[idx].binding_axis == 1)
+        (*i)->set_delta(Vector2f(0, -ev.value * 0.125f));
+    }
+
 #if 0
   CL_InputEvent e; 
                                
@@ -160,9 +170,16 @@
 void
 EvdevDevice::process_key(struct input_event& ev)
 {
-  int button_index = get_key_index_by_code(ev.code);
+  int idx = get_key_index_by_code(ev.code);
 
-  keys[button_index].pressed = ev.value;
+  keys[idx].pressed = ev.value;
+  for(std::vector<Button*>::iterator i = keys[idx].bindings.begin(); i != 
keys[idx].bindings.end(); ++i)
+    {
+      if (ev.value)
+        (*i)->set_state(BUTTON_PRESSED);
+      else
+        (*i)->set_state(BUTTON_RELEASED);
+    }
 
 #if 0
   CL_InputEvent e; 
@@ -222,7 +239,7 @@
     {
       for (int i = 0; i < rd / (int)sizeof(struct input_event); ++i)
         {
-          std::cout << ev[i].type << " " << ev[i].code << " " << ev[i].value 
<< std::endl;
+          //std::cout << ev[i].type << " " << ev[i].code << " " << ev[i].value 
<< std::endl;
 
           switch (ev[i].type)
             {
@@ -269,6 +286,54 @@
         }
     }
 }
+
+Scroller*
+EvdevDevice::create_scroller(Control* parent, int x, int y)
+{
+  Scroller* scroller = new Scroller(parent);
+  bool have_x = false;
+  bool have_y = false;
+  for(std::vector<Relative>::size_type i = 0; i != relatives.size(); ++i)
+    {
+      if (relatives[i].code == x)
+        {
+          relatives[i].binding_axis = 0;
+          relatives[i].bindings.push_back(scroller);
+          have_x = true;
+        }
+      else if (relatives[i].code == y)
+        {
+          relatives[i].binding_axis = 1;
+          relatives[i].bindings.push_back(scroller);          
+          have_y = true;
+        }
+    }
+
+  if (have_x && have_y)
+    {
+      return scroller;
+    }
+  else
+    {
+      delete scroller;
+      std::cout << "EvdevDevice: " << device << " doesn't have x or y: x=" << 
x << " y=" << y << std::endl;
+      return 0;
+    }
+}
+
+Button*
+EvdevDevice::create_button(Control* parent, int id)
+{
+  for(std::vector<Key>::size_type i = 0; i != keys.size(); ++i)
+    if (keys[i].code == id)
+      {
+        Button* button = new Button(parent);
+        keys[i].bindings.push_back(button);
+        return button;
+      }
+  std::cout << "EvdevDevice: " << device << " doesn't have button " << id << 
std::endl;
+  return 0;
+}
 
 } // namespace Input
 

Modified: trunk/pingus/src/input/evdev_device.hpp
===================================================================
--- trunk/pingus/src/input/evdev_device.hpp     2007-09-28 01:35:56 UTC (rev 
3252)
+++ trunk/pingus/src/input/evdev_device.hpp     2007-09-28 13:43:40 UTC (rev 
3253)
@@ -22,6 +22,7 @@
 
 #include <vector>
 #include <string>
+#include "control.hpp"
 
 namespace Input {
 
@@ -49,6 +50,9 @@
     Relative(int code_) : code(code_), pos(0) {}
     int code;
     int pos;
+
+    int binding_axis; // FIXME: Should be part of the binding
+    std::vector<Scroller*> bindings;
   };
 
   // Key Input Event
@@ -56,6 +60,7 @@
     Key(int code_) : code(code_), pressed(false) {}
     int code;
     bool pressed;
+    std::vector<Button*> bindings;
   };
 
   int fd;
@@ -72,6 +77,9 @@
   EvdevDevice(const std::string& filename);
   ~EvdevDevice();
   
+  std::string get_name() const { return name; }
+  std::string get_device() const { return device; }
+
   void update(float delta);
   void process_absolute(struct input_event& ev);
   void process_relative(struct input_event& ev);
@@ -80,6 +88,9 @@
   int get_key_index_by_code(int code);
   int get_relative_index_by_code(int code);
   int get_absolute_index_by_code(int code);
+
+  Scroller* create_scroller(Control* parent, int x, int y);
+  Button*   create_button(Control* parent, int id);
 };
 
 } // namespace Input

Modified: trunk/pingus/src/input/evdev_driver.cpp
===================================================================
--- trunk/pingus/src/input/evdev_driver.cpp     2007-09-28 01:35:56 UTC (rev 
3252)
+++ trunk/pingus/src/input/evdev_driver.cpp     2007-09-28 13:43:40 UTC (rev 
3253)
@@ -17,6 +17,7 @@
 //  along with this program; if not, write to the Free Software
 //  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 
+#include "evdev_device.hpp"
 #include "evdev_driver.hpp"
 
 namespace Input {
@@ -27,6 +28,10 @@
 
 EvdevDriver::~EvdevDriver() 
 { 
+  for(Devices::iterator i = devices.begin(); i != devices.end(); ++i)
+    {
+      delete *i;
+    }
 }
 
 std::string
@@ -38,12 +43,42 @@
 void
 EvdevDriver::update(float delta)
 {
+  for(Devices::iterator i = devices.begin(); i != devices.end(); ++i)
+    {
+      (*i)->update(delta);
+    }
 }
 
+EvdevDevice*
+EvdevDriver::get_device(const std::string& device_filename)
+{
+  for(Devices::iterator i = devices.begin(); i != devices.end(); ++i)
+    {
+      if ((*i)->get_device() == device_filename)
+        return *i;
+    }
+
+  EvdevDevice* device = new EvdevDevice(device_filename);
+  devices.push_back(device);
+  return device;
+}
+
 Button*
-EvdevDriver::create_button  (const FileReader& reader, Control* parent)
+EvdevDriver::create_button(const FileReader& reader, Control* parent)
 {
-  return 0;
+  std::string device_filename;
+  int button;
+  if (reader.read_string("device", device_filename) &&
+      reader.read_int("button", button))
+    {
+      EvdevDevice* device = get_device(device_filename);
+      return device->create_button(parent, button);
+    }
+  else
+    {
+      std::cout << "Error: Some of 'device', 'button' missing" << std::endl;
+      return 0;
+    }
 }
 
 Axis*
@@ -55,7 +90,20 @@
 Scroller*
 EvdevDriver::create_scroller(const FileReader& reader, Control* parent)
 {
-  return 0;
+  std::string device_filename;
+  int x, y;
+  if (reader.read_string("device", device_filename) &&
+      reader.read_int("x", x) &&
+      reader.read_int("y", y))
+    {
+      EvdevDevice* device = get_device(device_filename);
+      return device->create_scroller(parent, x, y);
+    }
+  else
+    {
+      std::cout << "Error: Some of 'device', 'x', 'y' missing" << std::endl;
+      return 0;
+    }
 }
 
 Pointer*

Modified: trunk/pingus/src/input/evdev_driver.hpp
===================================================================
--- trunk/pingus/src/input/evdev_driver.hpp     2007-09-28 01:35:56 UTC (rev 
3252)
+++ trunk/pingus/src/input/evdev_driver.hpp     2007-09-28 13:43:40 UTC (rev 
3253)
@@ -24,10 +24,15 @@
 
 namespace Input {
 
+class EvdevDevice;
+
 /** */
 class EvdevDriver : public Driver
 {
 private:
+  typedef std::vector<EvdevDevice*> Devices;
+  Devices devices;
+
 public:
   EvdevDriver();
   ~EvdevDriver();
@@ -40,6 +45,8 @@
   Scroller* create_scroller(const FileReader& reader, Control* parent);
   Pointer*  create_pointer (const FileReader& reader, Control* parent);
   Keyboard* create_keyboard(const FileReader& reader, Control* parent);
+
+  EvdevDevice* get_device(const std::string& device_filename);
 };
 
 } // namespace Input

Modified: trunk/pingus/src/input/manager.cpp
===================================================================
--- trunk/pingus/src/input/manager.cpp  2007-09-28 01:35:56 UTC (rev 3252)
+++ trunk/pingus/src/input/manager.cpp  2007-09-28 13:43:40 UTC (rev 3253)
@@ -19,6 +19,8 @@
 **  02111-1307, USA.
 */
 
+#include "config.h"
+
 #include "string_util.hpp"
 #include "pingus_error.hpp"
 #include "pathname.hpp"





reply via email to

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