[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Pingus-CVS] r4031 - in trunk/pingus: . src/display src/display/opengl s
From: |
grumbel at BerliOS |
Subject: |
[Pingus-CVS] r4031 - in trunk/pingus: . src/display src/display/opengl src/input src/input/evdev src/input/usbmouse src/input/wiimote src/input/xinput test |
Date: |
Thu, 5 Nov 2009 19:18:15 +0100 |
Author: grumbel
Date: 2009-11-05 19:18:10 +0100 (Thu, 05 Nov 2009)
New Revision: 4031
Added:
trunk/pingus/src/display/opengl/
trunk/pingus/src/display/opengl/opengl_framebuffer.cpp
trunk/pingus/src/display/opengl/opengl_framebuffer.hpp
trunk/pingus/src/display/opengl/opengl_framebuffer_surface_impl.cpp
trunk/pingus/src/display/opengl/opengl_framebuffer_surface_impl.hpp
trunk/pingus/src/input/evdev/
trunk/pingus/src/input/evdev/evdev_device.cpp
trunk/pingus/src/input/evdev/evdev_device.hpp
trunk/pingus/src/input/evdev/evdev_driver.cpp
trunk/pingus/src/input/evdev/evdev_driver.hpp
trunk/pingus/src/input/usbmouse/
trunk/pingus/src/input/usbmouse/usbmouse_driver.cpp
trunk/pingus/src/input/usbmouse/usbmouse_driver.hpp
trunk/pingus/src/input/wiimote/
trunk/pingus/src/input/wiimote/wiimote.cpp
trunk/pingus/src/input/wiimote/wiimote.hpp
trunk/pingus/src/input/wiimote/wiimote_driver.cpp
trunk/pingus/src/input/wiimote/wiimote_driver.hpp
trunk/pingus/src/input/xinput/
trunk/pingus/src/input/xinput/xinput_device.cpp
trunk/pingus/src/input/xinput/xinput_device.hpp
trunk/pingus/src/input/xinput/xinput_driver.cpp
trunk/pingus/src/input/xinput/xinput_driver.hpp
trunk/pingus/test/input_test.cpp
Removed:
trunk/pingus/src/display/opengl_framebuffer.cpp
trunk/pingus/src/display/opengl_framebuffer.hpp
trunk/pingus/src/display/opengl_framebuffer_surface_impl.cpp
trunk/pingus/src/display/opengl_framebuffer_surface_impl.hpp
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/main.cpp
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
trunk/pingus/src/input/xinput_device.cpp
trunk/pingus/src/input/xinput_device.hpp
trunk/pingus/src/input/xinput_driver.cpp
trunk/pingus/src/input/xinput_driver.hpp
Modified:
trunk/pingus/SConscript
trunk/pingus/src/display/display.cpp
trunk/pingus/src/input/manager.cpp
Log:
Switched from a exakt file list to a wildcard based build list, used some
optional files into subdirectories in the process
Modified: trunk/pingus/SConscript
===================================================================
--- trunk/pingus/SConscript 2009-11-05 15:57:44 UTC (rev 4030)
+++ trunk/pingus/SConscript 2009-11-05 18:18:10 UTC (rev 4031)
@@ -22,246 +22,26 @@
import sys, os
import SCons.Util
-pingus_sources = [
-'src/pingus/action_holder.cpp',
-'src/pingus/addon_menu.cpp',
-'src/pingus/blitter.cpp',
-'src/pingus/capture_rectangle.cpp',
-'src/pingus/collider.cpp',
-'src/pingus/collision_map.cpp',
-'src/pingus/collision_mask.cpp',
-'src/util/command_line.cpp',
-'src/util/command_line_generic.cpp',
-'src/pingus/config_manager.cpp',
-'src/pingus/credits.cpp',
-'src/pingus/debug.cpp',
-'src/util/debug_stream.cpp',
-'src/pingus/demo_session.cpp',
-'src/pingus/direction.cpp',
-'src/util/file_reader.cpp',
-'src/pingus/font.cpp',
-'src/pingus/font_description.cpp',
-'src/pingus/font_test_screen.cpp',
-'src/pingus/fonts.cpp',
-'src/pingus/fps_counter.cpp',
-'src/pingus/game_session.cpp',
-'src/pingus/game_time.cpp',
-'src/pingus/gettext.cpp',
-'src/pingus/global_event.cpp',
-'src/pingus/globals.cpp',
-'src/pingus/goal_manager.cpp',
-'src/pingus/graphic_context_state.cpp',
-'src/pingus/ground_map.cpp',
-'src/pingus/groundtype.cpp',
-'src/pingus/layer_manager.cpp',
-'src/pingus/level_menu.cpp',
-'src/pingus/levelset.cpp',
-'src/pingus/line_iterator.cpp',
-'src/math/math.cpp',
-'src/pingus/mover.cpp',
-'src/pingus/option_menu.cpp',
-'src/pingus/path_manager.cpp',
-'src/util/pathname.cpp',
-'src/pingus/pingu.cpp',
-'src/pingus/pingu_action.cpp',
-'src/pingus/pingu_enums.cpp',
-'src/pingus/pingu_holder.cpp',
-'src/pingus/pingus_demo.cpp',
-'src/pingus/pingus_error.cpp',
-'src/pingus/pingus_level.cpp',
-'src/pingus/pingus_main.cpp',
-'src/pingus/pingus_menu.cpp',
-'src/pingus/plf_res_mgr.cpp',
-'src/pingus/res_descriptor.cpp',
-'src/pingus/resource.cpp',
-'src/pingus/resource_manager.cpp',
-'src/pingus/resource_modifier.cpp',
-'src/pingus/result_screen.cpp',
-'src/pingus/savegame.cpp',
-'src/pingus/savegame_manager.cpp',
-'src/pingus/screenshot.cpp',
-'src/pingus/server.cpp',
-'src/pingus/server_event.cpp',
-'src/util/sexpr_file_reader.cpp',
-'src/util/sexpr_file_writer.cpp',
-'src/pingus/smallmap_image.cpp',
-'src/pingus/sprite.cpp',
-'src/pingus/sprite_impl.cpp',
-'src/pingus/start_screen.cpp',
-'src/pingus/stat_manager.cpp',
-'src/pingus/state_sprite.cpp',
-'src/pingus/story_screen.cpp',
-'src/pingus/string_format.cpp',
-'src/util/string_util.cpp',
-'src/pingus/surface.cpp',
-'src/util/system.cpp',
-'src/util/utf8.cpp',
-'src/pingus/world.cpp',
-'src/pingus/worldobj.cpp',
-'src/pingus/worldobj_factory.cpp',
-
-'src/actions/angel.cpp',
-'src/actions/basher.cpp',
-'src/actions/blocker.cpp',
-'src/actions/boarder.cpp',
-'src/actions/bomber.cpp',
-'src/actions/bridger.cpp',
-'src/actions/climber.cpp',
-'src/actions/digger.cpp',
-'src/actions/drown.cpp',
-'src/actions/exiter.cpp',
-'src/actions/faller.cpp',
-'src/actions/floater.cpp',
-'src/actions/jumper.cpp',
-'src/actions/laser_kill.cpp',
-'src/actions/miner.cpp',
-'src/actions/rocket_launcher.cpp',
-'src/actions/slider.cpp',
-'src/actions/smashed.cpp',
-'src/actions/splashed.cpp',
-'src/actions/superman.cpp',
-'src/actions/waiter.cpp',
-'src/actions/walker.cpp',
-
-'src/colliders/pingu_collider.cpp',
-
-'src/components/action_button.cpp',
-'src/components/button_panel.cpp',
-'src/components/check_box.cpp',
-'src/components/choice_box.cpp',
-'src/components/label.cpp',
-'src/components/menu_button.cpp',
-'src/components/pingus_counter.cpp',
-'src/components/playfield.cpp',
-'src/components/slider_box.cpp',
-'src/components/smallmap.cpp',
-'src/components/time_display.cpp',
-
-'src/display/delta_framebuffer.cpp',
-'src/display/display.cpp',
-'src/display/drawing_context.cpp',
-'src/display/framebuffer_surface.cpp',
-'src/display/null_framebuffer.cpp',
-'src/display/rect_merger.cpp',
-'src/display/scene_context.cpp',
-'src/display/sdl_framebuffer.cpp',
-'src/display/sdl_framebuffer_surface_impl.cpp',
-
-'src/editor/action_properties.cpp',
-'src/editor/button.cpp',
-'src/editor/checkbox.cpp',
-'src/editor/combobox.cpp',
-'src/editor/editor_level.cpp',
-'src/editor/editor_screen.cpp',
-'src/editor/file_dialog.cpp',
-'src/editor/file_list.cpp',
-'src/editor/gui_style.cpp',
-'src/editor/inputbox.cpp',
-'src/editor/label.cpp',
-'src/editor/level_objs.cpp',
-'src/editor/level_properties.cpp',
-'src/editor/minimap.cpp',
-'src/editor/object_properties.cpp',
-'src/editor/object_selector.cpp',
-'src/editor/object_selector_list.cpp',
-'src/editor/object_selector_set.cpp',
-'src/editor/panel.cpp',
-'src/editor/viewport.cpp',
-
-'src/gui/component.cpp',
-'src/gui/group_component.cpp',
-'src/gui/gui_manager.cpp',
-'src/gui/surface_button.cpp',
-
-'src/input/controller_description.cpp',
-'src/input/controller.cpp',
-'src/input/core_driver.cpp',
-'src/input/sdl_driver.cpp',
-'src/input/manager.cpp',
-
-'src/lisp/getters.cpp',
-'src/lisp/lexer.cpp',
-'src/lisp/lisp.cpp',
-'src/lisp/parser.cpp',
-
-'src/math/origin.cpp',
-'src/math/rect.cpp',
-'src/math/size.cpp',
-'src/math/vector2f.cpp',
-'src/math/vector2i.cpp',
-'src/math/vector3f.cpp',
-
-'src/movers/linear_mover.cpp',
-
-'src/particles/explosive_particle.cpp',
-'src/particles/pingu_particle_holder.cpp',
-'src/particles/rain_particle_holder.cpp',
-'src/particles/smoke_particle_holder.cpp',
-'src/particles/snow_particle_holder.cpp',
-
-'src/screen/gui_screen.cpp',
-'src/screen/screen.cpp',
-'src/screen/screen_manager.cpp',
-
-'src/sound/sound.cpp',
-'src/sound/sound_dummy.cpp',
-'src/sound/sound_real.cpp',
-'src/sound/sound_res_mgr.cpp',
-
-'external/tinygettext/dictionary.cpp',
-'external/tinygettext/iconv.cpp',
-'external/tinygettext/plural_forms.cpp',
-'external/tinygettext/dictionary_manager.cpp',
-'external/tinygettext/language.cpp',
-'external/tinygettext/po_parser.cpp',
-'external/tinygettext/directory.cpp',
-'external/tinygettext/log.cpp',
-'external/tinygettext/tinygettext.cpp',
-
-'src/worldmap/dot.cpp',
-'src/worldmap/dot_factory.cpp',
-'src/worldmap/drawable.cpp',
-'src/worldmap/drawable_factory.cpp',
-'src/worldmap/graph.cpp',
-'src/worldmap/level_dot.cpp',
-'src/worldmap/path.cpp',
-'src/worldmap/path_drawable.cpp',
-'src/worldmap/path_graph.cpp',
-'src/worldmap/pingus.cpp',
-'src/worldmap/pingus_worldmap.cpp',
-'src/worldmap/sprite_drawable.cpp',
-'src/worldmap/worldmap.cpp',
-'src/worldmap/worldmap_component.cpp',
-'src/worldmap/worldmap_screen.cpp',
-'src/worldmap/worldmap_story.cpp',
-
-'src/worldobjs/conveyor_belt.cpp',
-'src/worldobjs/entrance.cpp',
-'src/worldobjs/exit.cpp',
-'src/worldobjs/fake_exit.cpp',
-'src/worldobjs/groundpiece.cpp',
-'src/worldobjs/guillotine.cpp',
-'src/worldobjs/hammer.cpp',
-'src/worldobjs/hotspot.cpp',
-'src/worldobjs/ice_block.cpp',
-'src/worldobjs/laser_exit.cpp',
-'src/worldobjs/liquid.cpp',
-'src/worldobjs/rain_generator.cpp',
-'src/worldobjs/smasher.cpp',
-'src/worldobjs/snow_generator.cpp',
-'src/worldobjs/solid_color_background.cpp',
-'src/worldobjs/spike.cpp',
-'src/worldobjs/starfield_background.cpp',
-'src/worldobjs/starfield_background_stars.cpp',
-'src/worldobjs/surface_background.cpp',
-'src/worldobjs/switch_door.cpp',
-'src/worldobjs/teleporter.cpp',
-'src/worldobjs/teleporter_target.cpp',
-'src/worldobjs/thunderstorm_background.cpp',
-'src/worldobjs/woodthing.cpp',
-
-'external/binreloc-2.0/binreloc.c'
-]
+pingus_sources = \
+ Glob('external/tinygettext/*.cpp') + \
+ Glob('external/binreloc-2.0/*.c') + \
+ Glob('src/actions/*.cpp') + \
+ Glob('src/colliders/*.cpp') + \
+ Glob('src/components/*.cpp') + \
+ Glob('src/display/*.cpp') + \
+ Glob('src/editor/*.cpp') + \
+ Glob('src/gui/*.cpp') + \
+ Glob('src/input/*.cpp') + \
+ Glob('src/lisp/*.cpp') + \
+ Glob('src/math/*.cpp') + \
+ Glob('src/movers/*.cpp') + \
+ Glob('src/particles/*.cpp') + \
+ Glob('src/pingus/*.cpp') + \
+ Glob('src/screen/*.cpp') + \
+ Glob('src/sound/*.cpp') + \
+ Glob('src/util/*.cpp') + \
+ Glob('src/worldmap/*.cpp') + \
+ Glob('src/worldobjs/*.cpp')
class _SpaceListOptionClass:
"""An option type for space-separated lists with arbitrary elements."""
@@ -416,23 +196,23 @@
reports += " * OpenGL support: enabled\n"
config_h_defines += [('HAVE_OPENGL', 1)]
env['LIBS'] += ['GL']
- env['optional_sources'] +=
['src/display/opengl_framebuffer_surface_impl.cpp',
- 'src/display/opengl_framebuffer.cpp' ]
+ env['optional_sources'] +=
['src/display/opengl/opengl_framebuffer_surface_impl.cpp',
+ 'src/display/opengl/opengl_framebuffer.cpp'
]
if not env['with_linuxusbmouse']:
reports += " * Linux USB mouse support: disabled\n"
else:
reports += " * Linux USB mouse support: enabled\n"
config_h_defines += [('HAVE_LINUXUSBMOUSE', 1)]
- env['optional_sources'] += ['src/input/usbmouse_driver.cpp']
+ env['optional_sources'] += ['src/input/usbmouse/usbmouse_driver.cpp']
if not env['with_linuxevdev']:
reports += " * Linux evdev support: disabled\n"
else:
reports += " * Linux evdev support: ok\n"
config_h_defines += [('HAVE_LINUXEVDEV', 1)]
- env['optional_sources'] += ['src/input/evdev_driver.cpp',
- 'src/input/evdev_device.cpp']
+ env['optional_sources'] += ['src/input/evdev/evdev_driver.cpp',
+ 'src/input/evdev/evdev_device.cpp']
if not env['with_wiimote']:
reports += " * Wiimote support: disabled\n"
@@ -440,8 +220,8 @@
reports += " * Wiimote support: yes\n"
config_h_defines += [('HAVE_CWIID', 1)]
env['LIBS'] += ['cwiid']
- env['optional_sources'] += ['src/input/wiimote_driver.cpp',
- 'src/input/wiimote.cpp']
+ env['optional_sources'] += ['src/input/wiimote/wiimote_driver.cpp',
+ 'src/input/wiimote/wiimote.cpp']
else:
reports += " * Wiimote support: no (libcwiid or cwiid.h not found)\n"
@@ -453,8 +233,8 @@
reports += " * XInput support: yes\n"
config_h_defines += [('HAVE_XINPUT', 1)]
env['LIBS'] += ['Xi']
- env['optional_sources'] += ['src/input/xinput_driver.cpp',
- 'src/input/xinput_device.cpp']
+ env['optional_sources'] += ['src/input/xinput/xinput_driver.cpp',
+ 'src/input/xinput/xinput_device.cpp']
if not config.CheckLibWithHeader('boost_signals', 'boost/signals.hpp',
'c++'):
if not config.CheckLibWithHeader('boost_signals-mt',
'boost/signals.hpp', 'c++'):
Modified: trunk/pingus/src/display/display.cpp
===================================================================
--- trunk/pingus/src/display/display.cpp 2009-11-05 15:57:44 UTC (rev
4030)
+++ trunk/pingus/src/display/display.cpp 2009-11-05 18:18:10 UTC (rev
4031)
@@ -28,7 +28,7 @@
#include "screen/screen_manager.hpp"
#include "display/sdl_framebuffer.hpp"
#ifdef HAVE_OPENGL
-# include "opengl_framebuffer.hpp"
+# include "display/opengl/opengl_framebuffer.hpp"
#endif
#include "display/null_framebuffer.hpp"
#include "display/delta_framebuffer.hpp"
Copied: trunk/pingus/src/display/opengl/opengl_framebuffer.cpp (from rev 4030,
trunk/pingus/src/display/opengl_framebuffer.cpp)
===================================================================
--- trunk/pingus/src/display/opengl_framebuffer.cpp 2009-11-05 15:57:44 UTC
(rev 4030)
+++ trunk/pingus/src/display/opengl/opengl_framebuffer.cpp 2009-11-05
18:18:10 UTC (rev 4031)
@@ -0,0 +1,243 @@
+// Pingus - A free Lemmings clone
+// Copyright (C) 2008 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 3 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, see <http://www.gnu.org/licenses/>.
+
+#include <sstream>
+#include <iostream>
+#include <stdexcept>
+
+#include "display/opengl/opengl_framebuffer.hpp"
+#include "display/opengl/opengl_framebuffer_surface_impl.hpp"
+#include "math/math.hpp"
+#include "pingus/surface.hpp"
+
+OpenGLFramebuffer::OpenGLFramebuffer() :
+ screen(),
+ cliprect_stack()
+{
+}
+
+FramebufferSurface
+OpenGLFramebuffer::create_surface(const Surface& surface)
+{
+ return FramebufferSurface(new
OpenGLFramebufferSurfaceImpl(surface.get_surface()));
+}
+
+void
+OpenGLFramebuffer::set_video_mode(const Size& size, bool fullscreen)
+{
+ int flags = SDL_OPENGL;
+
+ if (fullscreen)
+ {
+ flags |= SDL_FULLSCREEN;
+ }
+ else
+ {
+ flags |= SDL_RESIZABLE;
+ }
+
+ int bpp = 0; // auto-detect
+ screen = SDL_SetVideoMode(size.width, size.height, bpp, flags);
+
+ if(screen == 0)
+ {
+ std::ostringstream msg;
+ msg << "Couldn't set video mode (" << size.width << "x" << size.height
+ << "-" << bpp << "bpp): " << SDL_GetError();
+ throw std::runtime_error(msg.str());
+ }
+
+ glEnableClientState(GL_VERTEX_ARRAY);
+ glEnableClientState(GL_TEXTURE_COORD_ARRAY);
+
+ // setup opengl state and transform
+ glDisable(GL_DEPTH_TEST);
+ glDisable(GL_CULL_FACE);
+ glEnable(GL_TEXTURE_2D);
+ glEnable(GL_BLEND);
+ glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+
+ glViewport(0, 0, size.width, size.height);
+
+ glMatrixMode(GL_PROJECTION);
+ glLoadIdentity();
+
+ glOrtho(0, size.width, size.height, 0, -1, 1);
+
+ glMatrixMode(GL_MODELVIEW);
+ glLoadIdentity();
+}
+
+void
+OpenGLFramebuffer::flip()
+{
+ SDL_GL_SwapBuffers();
+}
+
+void
+OpenGLFramebuffer::push_cliprect(const Rect& rect)
+{
+ if (cliprect_stack.empty())
+ glEnable(GL_SCISSOR_TEST);
+
+ if (cliprect_stack.empty())
+ {
+ cliprect_stack.push_back(rect);
+ }
+ else
+ {
+ cliprect_stack.push_back(Rect(Math::max(cliprect_stack.back().left,
rect.left),
+ Math::max(cliprect_stack.back().top,
rect.top),
+ Math::min(cliprect_stack.back().right,
rect.right),
+ Math::min(cliprect_stack.back().bottom,
rect.bottom)));
+ }
+
+ glScissor(cliprect_stack.back().left,
+ cliprect_stack.back().top,
+ cliprect_stack.back().get_width(),
+ cliprect_stack.back().get_height());
+}
+
+void
+OpenGLFramebuffer::pop_cliprect()
+{
+ cliprect_stack.pop_back();
+
+ if (cliprect_stack.empty())
+ {
+ glDisable(GL_SCISSOR_TEST);
+ }
+ else
+ {
+ const Rect& rect = cliprect_stack.back();
+ glScissor(rect.left, rect.top,
+ rect.get_width(), rect.get_height());
+ }
+}
+
+void
+OpenGLFramebuffer::draw_surface(const FramebufferSurface& src, const Vector2i&
pos)
+{
+ draw_surface(src, Rect(Vector2i(0, 0), src.get_size()), pos);
+}
+
+void
+OpenGLFramebuffer::draw_surface(const FramebufferSurface& src, const Rect&
srcrect, const Vector2i& pos)
+{
+ const OpenGLFramebufferSurfaceImpl* texture =
static_cast<OpenGLFramebufferSurfaceImpl*>(src.get_impl());
+
+ glBindTexture(GL_TEXTURE_2D, texture->get_handle());
+
+ int vertices[] = {
+ pos.x, pos.y,
+ pos.x+srcrect.get_width(), pos.y,
+ pos.x+srcrect.get_width(), pos.y+srcrect.get_height(),
+ pos.x, pos.y+srcrect.get_height(),
+ };
+ glVertexPointer(2, GL_INT, 0, vertices);
+
+ float uvs[] = {
+ static_cast<float>(srcrect.left) /
static_cast<float>(texture->get_texture_size().width),
+ static_cast<float>(srcrect.top) /
static_cast<float>(texture->get_texture_size().height),
+
+ static_cast<float>(srcrect.right) /
static_cast<float>(texture->get_texture_size().width),
+ static_cast<float>(srcrect.top) /
static_cast<float>(texture->get_texture_size().height),
+
+ static_cast<float>(srcrect.right) /
static_cast<float>(texture->get_texture_size().width),
+ static_cast<float>(srcrect.bottom) /
static_cast<float>(texture->get_texture_size().height),
+
+ static_cast<float>(srcrect.left) /
static_cast<float>(texture->get_texture_size().width),
+ static_cast<float>(srcrect.bottom) /
static_cast<float>(texture->get_texture_size().height)
+ };
+
+ glTexCoordPointer(2, GL_FLOAT, 0, uvs);
+
+ glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
+
+ glBindTexture(GL_TEXTURE_2D, 0);
+}
+
+void
+OpenGLFramebuffer::draw_line(const Vector2i& pos1, const Vector2i& pos2, const
Color& color)
+{
+ glDisable(GL_TEXTURE_2D);
+ glColor4ub(color.r, color.g, color.b, color.a);
+ glDisableClientState(GL_TEXTURE_COORD_ARRAY);
+
+ int vertices[] = {
+ pos1.x, pos1.y,
+ pos2.x, pos2.y,
+ };
+ glVertexPointer(2, GL_INT, 0, vertices);
+
+ glDrawArrays(GL_LINES, 0, 2);
+
+ glEnableClientState(GL_TEXTURE_COORD_ARRAY);
+ glEnable(GL_TEXTURE_2D);
+ glColor4f(1, 1, 1, 1);
+}
+
+void
+OpenGLFramebuffer::draw_rect(const Rect& rect, const Color& color)
+{
+ glDisable(GL_TEXTURE_2D);
+ glColor4ub(color.r, color.g, color.b, color.a);
+ glDisableClientState(GL_TEXTURE_COORD_ARRAY);
+
+ int vertices[] = {
+ rect.left, rect.top,
+ rect.right, rect.top,
+ rect.right, rect.bottom,
+ rect.left, rect.bottom,
+ };
+ glVertexPointer(2, GL_INT, 0, vertices);
+
+ glDrawArrays(GL_LINE_LOOP, 0, 4);
+
+ glEnableClientState(GL_TEXTURE_COORD_ARRAY);
+ glEnable(GL_TEXTURE_2D);
+ glColor4f(1, 1, 1, 1);
+}
+
+void
+OpenGLFramebuffer::fill_rect(const Rect& rect, const Color& color)
+{
+ glDisable(GL_TEXTURE_2D);
+ glColor4ub(color.r, color.g, color.b, color.a);
+ glDisableClientState(GL_TEXTURE_COORD_ARRAY);
+
+ int vertices[] = {
+ rect.left, rect.top,
+ rect.right, rect.top,
+ rect.right, rect.bottom,
+ rect.left, rect.bottom,
+ };
+ glVertexPointer(2, GL_INT, 0, vertices);
+
+ glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
+
+ glEnableClientState(GL_TEXTURE_COORD_ARRAY);
+ glEnable(GL_TEXTURE_2D);
+ glColor4f(1, 1, 1, 1);
+}
+
+Size
+OpenGLFramebuffer::get_size() const
+{
+ return Size(screen->w, screen->h);
+}
+
+/* EOF */
Copied: trunk/pingus/src/display/opengl/opengl_framebuffer.hpp (from rev 4029,
trunk/pingus/src/display/opengl_framebuffer.hpp)
Copied: trunk/pingus/src/display/opengl/opengl_framebuffer_surface_impl.cpp
(from rev 4029, trunk/pingus/src/display/opengl_framebuffer_surface_impl.cpp)
===================================================================
--- trunk/pingus/src/display/opengl_framebuffer_surface_impl.cpp
2009-11-05 02:45:14 UTC (rev 4029)
+++ trunk/pingus/src/display/opengl/opengl_framebuffer_surface_impl.cpp
2009-11-05 18:18:10 UTC (rev 4031)
@@ -0,0 +1,88 @@
+// Pingus - A free Lemmings clone
+// Copyright (C) 2008 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 3 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, see <http://www.gnu.org/licenses/>.
+
+#include "display/opengl/opengl_framebuffer_surface_impl.hpp"
+
+namespace {
+
+inline int next_power_of_two(int val)
+{
+ int result = 1;
+ while(result < val)
+ result *= 2;
+ return result;
+}
+
+} // namespace
+
+OpenGLFramebufferSurfaceImpl::OpenGLFramebufferSurfaceImpl(SDL_Surface* src) :
+ handle(),
+ size(src->w, src->h),
+ texture_size()
+{
+ glGenTextures(1, &handle);
+
+ texture_size.width = next_power_of_two(src->w);
+ texture_size.height = next_power_of_two(src->h);
+
+ // Convert the src surface to a format usable for upload to OpenGL
+#if SDL_BYTEORDER == SDL_BIG_ENDIAN
+ SDL_Surface* convert = SDL_CreateRGBSurface(SDL_SWSURFACE,
+ texture_size.width,
texture_size.height, 32,
+ 0xff000000, 0x00ff0000,
0x0000ff00, 0x000000ff);
+#else
+ SDL_Surface* convert = SDL_CreateRGBSurface(SDL_SWSURFACE,
+ texture_size.width,
texture_size.height, 32,
+ 0x000000ff, 0x0000ff00,
0x00ff0000, 0xff000000);
+#endif
+ SDL_SetAlpha(src, 0, 0);
+ SDL_BlitSurface(src, 0, convert, 0);
+
+ GLenum sdl_format;
+ if(convert->format->BytesPerPixel == 3)
+ sdl_format = GL_RGB;
+ else if(convert->format->BytesPerPixel == 4)
+ sdl_format = GL_RGBA;
+ else
+ assert(!"OpenGLFramebufferSurfaceImpl: Unsupported surface format");
+
+ glBindTexture(GL_TEXTURE_2D, handle);
+ glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
+
+ glPixelStorei(GL_UNPACK_ROW_LENGTH,
convert->pitch/convert->format->BytesPerPixel);
+
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
+
+ // Upload the surface to a texture
+ SDL_LockSurface(convert);
+ glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, texture_size.width,
texture_size.height, 0
+ , sdl_format, GL_UNSIGNED_BYTE, convert->pixels);
+ SDL_UnlockSurface(convert);
+
+ SDL_FreeSurface(convert);
+
+ // Unbind the texture
+ glBindTexture(GL_TEXTURE_2D, 0);
+}
+
+Surface
+OpenGLFramebufferSurfaceImpl::to_surface() const
+{
+ return Surface();
+}
+
+/* EOF */
Copied: trunk/pingus/src/display/opengl/opengl_framebuffer_surface_impl.hpp
(from rev 4029, trunk/pingus/src/display/opengl_framebuffer_surface_impl.hpp)
Deleted: trunk/pingus/src/display/opengl_framebuffer.cpp
===================================================================
--- trunk/pingus/src/display/opengl_framebuffer.cpp 2009-11-05 15:57:44 UTC
(rev 4030)
+++ trunk/pingus/src/display/opengl_framebuffer.cpp 2009-11-05 18:18:10 UTC
(rev 4031)
@@ -1,243 +0,0 @@
-// Pingus - A free Lemmings clone
-// Copyright (C) 2008 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 3 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, see <http://www.gnu.org/licenses/>.
-
-#include <sstream>
-#include <iostream>
-#include <stdexcept>
-
-#include "display/opengl_framebuffer.hpp"
-#include "display/opengl_framebuffer_surface_impl.hpp"
-#include "math/math.hpp"
-#include "pingus/surface.hpp"
-
-OpenGLFramebuffer::OpenGLFramebuffer() :
- screen(),
- cliprect_stack()
-{
-}
-
-FramebufferSurface
-OpenGLFramebuffer::create_surface(const Surface& surface)
-{
- return FramebufferSurface(new
OpenGLFramebufferSurfaceImpl(surface.get_surface()));
-}
-
-void
-OpenGLFramebuffer::set_video_mode(const Size& size, bool fullscreen)
-{
- int flags = SDL_OPENGL;
-
- if (fullscreen)
- {
- flags |= SDL_FULLSCREEN;
- }
- else
- {
- flags |= SDL_RESIZABLE;
- }
-
- int bpp = 0; // auto-detect
- screen = SDL_SetVideoMode(size.width, size.height, bpp, flags);
-
- if(screen == 0)
- {
- std::ostringstream msg;
- msg << "Couldn't set video mode (" << size.width << "x" << size.height
- << "-" << bpp << "bpp): " << SDL_GetError();
- throw std::runtime_error(msg.str());
- }
-
- glEnableClientState(GL_VERTEX_ARRAY);
- glEnableClientState(GL_TEXTURE_COORD_ARRAY);
-
- // setup opengl state and transform
- glDisable(GL_DEPTH_TEST);
- glDisable(GL_CULL_FACE);
- glEnable(GL_TEXTURE_2D);
- glEnable(GL_BLEND);
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
-
- glViewport(0, 0, size.width, size.height);
-
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
-
- glOrtho(0, size.width, size.height, 0, -1, 1);
-
- glMatrixMode(GL_MODELVIEW);
- glLoadIdentity();
-}
-
-void
-OpenGLFramebuffer::flip()
-{
- SDL_GL_SwapBuffers();
-}
-
-void
-OpenGLFramebuffer::push_cliprect(const Rect& rect)
-{
- if (cliprect_stack.empty())
- glEnable(GL_SCISSOR_TEST);
-
- if (cliprect_stack.empty())
- {
- cliprect_stack.push_back(rect);
- }
- else
- {
- cliprect_stack.push_back(Rect(Math::max(cliprect_stack.back().left,
rect.left),
- Math::max(cliprect_stack.back().top,
rect.top),
- Math::min(cliprect_stack.back().right,
rect.right),
- Math::min(cliprect_stack.back().bottom,
rect.bottom)));
- }
-
- glScissor(cliprect_stack.back().left,
- cliprect_stack.back().top,
- cliprect_stack.back().get_width(),
- cliprect_stack.back().get_height());
-}
-
-void
-OpenGLFramebuffer::pop_cliprect()
-{
- cliprect_stack.pop_back();
-
- if (cliprect_stack.empty())
- {
- glDisable(GL_SCISSOR_TEST);
- }
- else
- {
- const Rect& rect = cliprect_stack.back();
- glScissor(rect.left, rect.top,
- rect.get_width(), rect.get_height());
- }
-}
-
-void
-OpenGLFramebuffer::draw_surface(const FramebufferSurface& src, const Vector2i&
pos)
-{
- draw_surface(src, Rect(Vector2i(0, 0), src.get_size()), pos);
-}
-
-void
-OpenGLFramebuffer::draw_surface(const FramebufferSurface& src, const Rect&
srcrect, const Vector2i& pos)
-{
- const OpenGLFramebufferSurfaceImpl* texture =
static_cast<OpenGLFramebufferSurfaceImpl*>(src.get_impl());
-
- glBindTexture(GL_TEXTURE_2D, texture->get_handle());
-
- int vertices[] = {
- pos.x, pos.y,
- pos.x+srcrect.get_width(), pos.y,
- pos.x+srcrect.get_width(), pos.y+srcrect.get_height(),
- pos.x, pos.y+srcrect.get_height(),
- };
- glVertexPointer(2, GL_INT, 0, vertices);
-
- float uvs[] = {
- static_cast<float>(srcrect.left) /
static_cast<float>(texture->get_texture_size().width),
- static_cast<float>(srcrect.top) /
static_cast<float>(texture->get_texture_size().height),
-
- static_cast<float>(srcrect.right) /
static_cast<float>(texture->get_texture_size().width),
- static_cast<float>(srcrect.top) /
static_cast<float>(texture->get_texture_size().height),
-
- static_cast<float>(srcrect.right) /
static_cast<float>(texture->get_texture_size().width),
- static_cast<float>(srcrect.bottom) /
static_cast<float>(texture->get_texture_size().height),
-
- static_cast<float>(srcrect.left) /
static_cast<float>(texture->get_texture_size().width),
- static_cast<float>(srcrect.bottom) /
static_cast<float>(texture->get_texture_size().height)
- };
-
- glTexCoordPointer(2, GL_FLOAT, 0, uvs);
-
- glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
-
- glBindTexture(GL_TEXTURE_2D, 0);
-}
-
-void
-OpenGLFramebuffer::draw_line(const Vector2i& pos1, const Vector2i& pos2, const
Color& color)
-{
- glDisable(GL_TEXTURE_2D);
- glColor4ub(color.r, color.g, color.b, color.a);
- glDisableClientState(GL_TEXTURE_COORD_ARRAY);
-
- int vertices[] = {
- pos1.x, pos1.y,
- pos2.x, pos2.y,
- };
- glVertexPointer(2, GL_INT, 0, vertices);
-
- glDrawArrays(GL_LINES, 0, 2);
-
- glEnableClientState(GL_TEXTURE_COORD_ARRAY);
- glEnable(GL_TEXTURE_2D);
- glColor4f(1, 1, 1, 1);
-}
-
-void
-OpenGLFramebuffer::draw_rect(const Rect& rect, const Color& color)
-{
- glDisable(GL_TEXTURE_2D);
- glColor4ub(color.r, color.g, color.b, color.a);
- glDisableClientState(GL_TEXTURE_COORD_ARRAY);
-
- int vertices[] = {
- rect.left, rect.top,
- rect.right, rect.top,
- rect.right, rect.bottom,
- rect.left, rect.bottom,
- };
- glVertexPointer(2, GL_INT, 0, vertices);
-
- glDrawArrays(GL_LINE_LOOP, 0, 4);
-
- glEnableClientState(GL_TEXTURE_COORD_ARRAY);
- glEnable(GL_TEXTURE_2D);
- glColor4f(1, 1, 1, 1);
-}
-
-void
-OpenGLFramebuffer::fill_rect(const Rect& rect, const Color& color)
-{
- glDisable(GL_TEXTURE_2D);
- glColor4ub(color.r, color.g, color.b, color.a);
- glDisableClientState(GL_TEXTURE_COORD_ARRAY);
-
- int vertices[] = {
- rect.left, rect.top,
- rect.right, rect.top,
- rect.right, rect.bottom,
- rect.left, rect.bottom,
- };
- glVertexPointer(2, GL_INT, 0, vertices);
-
- glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
-
- glEnableClientState(GL_TEXTURE_COORD_ARRAY);
- glEnable(GL_TEXTURE_2D);
- glColor4f(1, 1, 1, 1);
-}
-
-Size
-OpenGLFramebuffer::get_size() const
-{
- return Size(screen->w, screen->h);
-}
-
-/* EOF */
Deleted: trunk/pingus/src/display/opengl_framebuffer.hpp
===================================================================
--- trunk/pingus/src/display/opengl_framebuffer.hpp 2009-11-05 15:57:44 UTC
(rev 4030)
+++ trunk/pingus/src/display/opengl_framebuffer.hpp 2009-11-05 18:18:10 UTC
(rev 4031)
@@ -1,56 +0,0 @@
-// Pingus - A free Lemmings clone
-// Copyright (C) 2008 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 3 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, see <http://www.gnu.org/licenses/>.
-
-#ifndef HEADER_PINGUS_DISPLAY_OPENGL_FRAMEBUFFER_HPP
-#define HEADER_PINGUS_DISPLAY_OPENGL_FRAMEBUFFER_HPP
-
-#include "display/framebuffer.hpp"
-
-class OpenGLFramebuffer : public Framebuffer
-{
-private:
- SDL_Surface* screen;
- std::vector<Rect> cliprect_stack;
-
-public:
- OpenGLFramebuffer();
-
- FramebufferSurface create_surface(const Surface& surface);
-
- void set_video_mode(const Size& size, bool fullscreen);
- void flip();
-
- void push_cliprect(const Rect&);
- void pop_cliprect();
-
- void draw_surface(const FramebufferSurface& src, const Vector2i& pos);
- void draw_surface(const FramebufferSurface& src, const Rect& srcrect, const
Vector2i& pos);
-
- void draw_line(const Vector2i& pos1, const Vector2i& pos2, const Color&
color);
-
- void draw_rect(const Rect& rect, const Color& color);
- void fill_rect(const Rect& rect, const Color& color);
-
- Size get_size() const;
-
-private:
- OpenGLFramebuffer(const OpenGLFramebuffer&);
- OpenGLFramebuffer & operator=(const OpenGLFramebuffer&);
-};
-
-#endif
-
-/* EOF */
Deleted: trunk/pingus/src/display/opengl_framebuffer_surface_impl.cpp
===================================================================
--- trunk/pingus/src/display/opengl_framebuffer_surface_impl.cpp
2009-11-05 15:57:44 UTC (rev 4030)
+++ trunk/pingus/src/display/opengl_framebuffer_surface_impl.cpp
2009-11-05 18:18:10 UTC (rev 4031)
@@ -1,88 +0,0 @@
-// Pingus - A free Lemmings clone
-// Copyright (C) 2008 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 3 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, see <http://www.gnu.org/licenses/>.
-
-#include "display/opengl_framebuffer_surface_impl.hpp"
-
-namespace {
-
-inline int next_power_of_two(int val)
-{
- int result = 1;
- while(result < val)
- result *= 2;
- return result;
-}
-
-} // namespace
-
-OpenGLFramebufferSurfaceImpl::OpenGLFramebufferSurfaceImpl(SDL_Surface* src) :
- handle(),
- size(src->w, src->h),
- texture_size()
-{
- glGenTextures(1, &handle);
-
- texture_size.width = next_power_of_two(src->w);
- texture_size.height = next_power_of_two(src->h);
-
- // Convert the src surface to a format usable for upload to OpenGL
-#if SDL_BYTEORDER == SDL_BIG_ENDIAN
- SDL_Surface* convert = SDL_CreateRGBSurface(SDL_SWSURFACE,
- texture_size.width,
texture_size.height, 32,
- 0xff000000, 0x00ff0000,
0x0000ff00, 0x000000ff);
-#else
- SDL_Surface* convert = SDL_CreateRGBSurface(SDL_SWSURFACE,
- texture_size.width,
texture_size.height, 32,
- 0x000000ff, 0x0000ff00,
0x00ff0000, 0xff000000);
-#endif
- SDL_SetAlpha(src, 0, 0);
- SDL_BlitSurface(src, 0, convert, 0);
-
- GLenum sdl_format;
- if(convert->format->BytesPerPixel == 3)
- sdl_format = GL_RGB;
- else if(convert->format->BytesPerPixel == 4)
- sdl_format = GL_RGBA;
- else
- assert(!"OpenGLFramebufferSurfaceImpl: Unsupported surface format");
-
- glBindTexture(GL_TEXTURE_2D, handle);
- glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
-
- glPixelStorei(GL_UNPACK_ROW_LENGTH,
convert->pitch/convert->format->BytesPerPixel);
-
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
-
- // Upload the surface to a texture
- SDL_LockSurface(convert);
- glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, texture_size.width,
texture_size.height, 0
- , sdl_format, GL_UNSIGNED_BYTE, convert->pixels);
- SDL_UnlockSurface(convert);
-
- SDL_FreeSurface(convert);
-
- // Unbind the texture
- glBindTexture(GL_TEXTURE_2D, 0);
-}
-
-Surface
-OpenGLFramebufferSurfaceImpl::to_surface() const
-{
- return Surface();
-}
-
-/* EOF */
Deleted: trunk/pingus/src/display/opengl_framebuffer_surface_impl.hpp
===================================================================
--- trunk/pingus/src/display/opengl_framebuffer_surface_impl.hpp
2009-11-05 15:57:44 UTC (rev 4030)
+++ trunk/pingus/src/display/opengl_framebuffer_surface_impl.hpp
2009-11-05 18:18:10 UTC (rev 4031)
@@ -1,58 +0,0 @@
-// Pingus - A free Lemmings clone
-// Copyright (C) 2008 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 3 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, see <http://www.gnu.org/licenses/>.
-
-#ifndef HEADER_PINGUS_DISPLAY_OPENGL_FRAMEBUFFER_SURFACE_IMPL_HPP
-#define HEADER_PINGUS_DISPLAY_OPENGL_FRAMEBUFFER_SURFACE_IMPL_HPP
-
-#if defined(_WIN32)
-#define WIN32_LEAN_AND_MEAN
-#define NOMINMAX /* Don't defined min() and max() */
-#include <windows.h>
-#include <GL/gl.h>
-#elif defined(MACOSX)
-#include <OpenGL/gl.h>
-#include <OpenGL/glext.h>
-#else
-#include <GL/gl.h>
-#include <GL/glext.h>
-#endif
-
-#include "SDL.h"
-#include "display/framebuffer_surface.hpp"
-
-class OpenGLFramebufferSurfaceImpl : public FramebufferSurfaceImpl
-{
-private:
- GLuint handle;
- Size size;
- Size texture_size;
-
-public:
- OpenGLFramebufferSurfaceImpl(SDL_Surface* src);
-
- int get_width() const { return size.width; }
- int get_height() const { return size.height; }
-
- GLuint get_handle() const { return handle; }
- Size get_texture_size() const { return texture_size; }
- Size get_size() const { return size; }
-
- Surface to_surface() const;
-};
-
-#endif
-
-/* EOF */
Copied: trunk/pingus/src/input/evdev/evdev_device.cpp (from rev 4030,
trunk/pingus/src/input/evdev_device.cpp)
===================================================================
--- trunk/pingus/src/input/evdev_device.cpp 2009-11-05 15:57:44 UTC (rev
4030)
+++ trunk/pingus/src/input/evdev/evdev_device.cpp 2009-11-05 18:18:10 UTC
(rev 4031)
@@ -0,0 +1,330 @@
+// 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 3 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, see <http://www.gnu.org/licenses/>.
+
+#include <assert.h>
+#include <linux/input.h>
+#include <sys/ioctl.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <stdexcept>
+#include <iostream>
+#include <errno.h>
+#include <stdio.h>
+
+#include "input/evdev/evdev_device.hpp"
+
+#define BITS_PER_LONG (sizeof(long) * 8)
+#define NBITS(x) ((((x)-1)/BITS_PER_LONG)+1)
+#define OFF(x) ((x)%BITS_PER_LONG)
+#define BIT(x) (1UL<<OFF(x))
+#define LONG(x) ((x)/BITS_PER_LONG)
+#define test_bit(bit, array) ((array[LONG(bit)] >> OFF(bit)) & 1)
+
+namespace Input {
+
+EvdevDevice::EvdevDevice(const std::string& filename) :
+ fd(),
+ version(),
+ relatives(),
+ absolutes(),
+ keys(),
+ name(),
+ device(filename)
+{
+ fd = open(device.c_str(), O_RDONLY | O_NONBLOCK);
+
+ if (fd == -1)
+ {
+ throw std::runtime_error(filename + ": " + std::string(strerror(errno)));
+ }
+
+ if (ioctl(fd, EVIOCGVERSION, &version))
+ {
+ throw std::runtime_error("Error: EvdevDevice: Couldn't get version for "
+ filename);
+ }
+
+ if (1)
+ { // FIXME: Some versions of linux don't have these structs, use arrays
there
+ struct input_id id;
+ ioctl(fd, EVIOCGID, &id);
+ printf("Input device ID: bus 0x%x vendor 0x%x product 0x%x version
0x%x\n",
+ id.bustype, id.vendor, id.product, id.vendor);
+ }
+
+ { // Get the human readable name
+ char c_name[256] = "unknown";
+ ioctl(fd, EVIOCGNAME(sizeof(c_name)), c_name);
+ name = c_name;
+ std::cout << "Name: " << name << std::endl;
+ }
+
+ { // Read in how many buttons the device has
+ unsigned long bit[EV_MAX][NBITS(KEY_MAX)];
+ memset(bit, 0, sizeof(bit));
+ ioctl(fd, EVIOCGBIT(0, EV_MAX), bit[0]);
+
+ for (int i = 0; i < EV_MAX; i++)
+ {
+ if (test_bit(i, bit[0]))
+ {
+ //printf(" Event type %d (%s)\n", i, events[i] ? events[i] : "?");
+
+ if (!i) continue;
+
+ ioctl(fd, EVIOCGBIT(i, KEY_MAX), bit[i]);
+ for (int j = 0; j < KEY_MAX; j++)
+ {
+ if (test_bit(j, bit[i]))
+ {
+ if (i == EV_KEY)
+ {
+ keys.push_back(Key(j));
+ }
+ else if (i == EV_ABS)
+ {
+ // FIXME: Some Linuxes don't have these struct
+ struct input_absinfo absinfo;
+ ioctl(fd, EVIOCGABS(j), &absinfo);
+ // FIXME: we are ignoring absinfo.fuzz and
+ // 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)
+ {
+ relatives.push_back(Relative(j));
+ }
+ }
+ }
+ }
+ }
+ }
+}
+
+EvdevDevice::~EvdevDevice()
+{
+}
+
+void
+EvdevDevice::process_absolute(struct input_event& ev)
+{
+ int axis_index = get_absolute_index_by_code(ev.code);
+ if (axis_index != -1)
+ {
+ absolutes[axis_index].pos = ev.value;
+
+#if 0
+ CL_InputEvent e;
+
+ e.device = CL_InputDevice(this);
+ e.type = CL_InputEvent::axis_moved;
+ e.id = axis_index;
+ e.axis_pos = absolutes[axis_index].get_posf();
+ e.repeat_count = 0;
+
+ sig_axis_move(e);
+#endif
+ }
+}
+
+void
+EvdevDevice::process_relative(struct input_event& ev)
+{
+ int idx = get_relative_index_by_code(ev.code);
+
+ 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(static_cast<float>(-ev.value) * 0.125f,
0.0f)); // FIXME: make scaling and inversion configurable
+ else if (relatives[idx].binding_axis == 1)
+ (*i)->set_delta(Vector2f(0, static_cast<float>(-ev.value) * 0.125f));
+ }
+}
+
+void
+EvdevDevice::process_key(struct input_event& ev)
+{
+ int idx = get_key_index_by_code(ev.code);
+
+ 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;
+
+ e.device = CL_InputDevice(this);
+ e.id = button_index;
+ e.repeat_count = 0;
+
+ if (ev.value)
+ {
+ e.type = CL_InputEvent::pressed;
+ sig_key_down(e);
+ }
+ else
+ {
+ e.type = CL_InputEvent::released;
+ sig_key_up(e);
+ }
+#endif
+}
+
+int
+EvdevDevice::get_relative_index_by_code(int code)
+{
+ for(std::vector<Relative>::size_type i = 0; i != relatives.size(); ++i)
+ if (relatives[i].code == code)
+ return i;
+ return -1;
+}
+
+int
+EvdevDevice::get_key_index_by_code(int code)
+{
+ for(std::vector<Key>::size_type i = 0; i != keys.size(); ++i)
+ if (keys[i].code == code)
+ return i;
+ return -1;
+}
+
+int
+EvdevDevice::get_absolute_index_by_code(int code)
+{
+ for(std::vector<Absolute>::size_type i = 0; i != absolutes.size(); ++i)
+ if (absolutes[i].code == code)
+ return i;
+ return -1;
+}
+
+void
+EvdevDevice::update(float delta)
+{
+ struct input_event ev[128];
+ // FIXME: turn this into a while loop so all events get processed
+ ssize_t rd = read(fd, ev, sizeof(struct input_event) * 128);
+ //std::cout << rd / sizeof(struct input_event) << std::endl;
+ if (rd >= static_cast<ssize_t>(sizeof(struct input_event)))
+ {
+ 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;
+
+ switch (ev[i].type)
+ {
+ case EV_ABS:
+ process_absolute(ev[i]);
+ break;
+
+ case EV_REL:
+ process_relative(ev[i]);
+ break;
+
+ case EV_KEY:
+ process_key(ev[i]);
+ break;
+
+ default:
+#if 0
+ if (ev[i].type == EV_SYN)
+ {
+ printf("Event: time %ld.%06ld, -------------- %s
------------\n",
+ ev[i].time.tv_sec, ev[i].time.tv_usec, ev[i].code ?
"Config Sync" : "Report Sync" );
+ }
+ else if (ev[i].type == EV_MSC && (ev[i].code == MSC_RAW ||
ev[i].code == MSC_SCAN))
+ {
+ printf("Event: time %ld.%06ld, type %d (%s), code %d (%s),
value %02x\n",
+ ev[i].time.tv_sec, ev[i].time.tv_usec, ev[i].type,
+ events[ev[i].type] ? events[ev[i].type] : "?",
+ ev[i].code,
+ names[ev[i].type] ? (names[ev[i].type][ev[i].code]
? names[ev[i].type][ev[i].code] : "?") : "?",
+ ev[i].value);
+ }
+ else
+ {
+ printf("Event: time %ld.%06ld, type %d (%s), code %d (%s),
value %d\n",
+ ev[i].time.tv_sec, ev[i].time.tv_usec, ev[i].type,
+ events[ev[i].type] ? events[ev[i].type] : "?",
+ ev[i].code,
+ names[ev[i].type] ? (names[ev[i].type][ev[i].code]
? names[ev[i].type][ev[i].code] : "?") : "?",
+ ev[i].value);
+ }
+#endif
+ break;
+ }
+ }
+ }
+}
+
+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
+
+/* EOF */
Copied: trunk/pingus/src/input/evdev/evdev_device.hpp (from rev 4030,
trunk/pingus/src/input/evdev_device.hpp)
Copied: trunk/pingus/src/input/evdev/evdev_driver.cpp (from rev 4029,
trunk/pingus/src/input/evdev_driver.cpp)
===================================================================
--- trunk/pingus/src/input/evdev_driver.cpp 2009-11-05 02:45:14 UTC (rev
4029)
+++ trunk/pingus/src/input/evdev/evdev_driver.cpp 2009-11-05 18:18:10 UTC
(rev 4031)
@@ -0,0 +1,126 @@
+// 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 3 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, see <http://www.gnu.org/licenses/>.
+
+#include "input/evdev/evdev_device.hpp"
+#include "input/evdev/evdev_driver.hpp"
+
+namespace Input {
+
+EvdevDriver::EvdevDriver() :
+ devices()
+{
+}
+
+EvdevDriver::~EvdevDriver()
+{
+ for(Devices::iterator i = devices.begin(); i != devices.end(); ++i)
+ {
+ delete *i;
+ }
+}
+
+std::string
+EvdevDriver::get_name() const
+{
+ return "evdev";
+}
+
+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;
+ }
+
+ try {
+ EvdevDevice* device = new EvdevDevice(device_filename);
+ devices.push_back(device);
+ return device;
+ } catch (std::exception& err) {
+ std::cout << "EvdevDriver: " << err.what() << std::endl;
+ return 0;
+ }
+}
+
+Button*
+EvdevDriver::create_button(const FileReader& reader, Control* parent)
+{
+ 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*
+EvdevDriver::create_axis(const FileReader& reader, Control* parent)
+{
+ return 0;
+}
+
+Scroller*
+EvdevDriver::create_scroller(const FileReader& reader, Control* parent)
+{
+ 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*
+EvdevDriver::create_pointer(const FileReader& reader, Control* parent)
+{
+ return 0;
+}
+
+Keyboard*
+EvdevDriver::create_keyboard(const FileReader& reader, Control* parent)
+{
+ return 0;
+}
+
+} // namespace Input
+
+/* EOF */
Copied: trunk/pingus/src/input/evdev/evdev_driver.hpp (from rev 4029,
trunk/pingus/src/input/evdev_driver.hpp)
Deleted: trunk/pingus/src/input/evdev_device.cpp
===================================================================
--- trunk/pingus/src/input/evdev_device.cpp 2009-11-05 15:57:44 UTC (rev
4030)
+++ trunk/pingus/src/input/evdev_device.cpp 2009-11-05 18:18:10 UTC (rev
4031)
@@ -1,330 +0,0 @@
-// 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 3 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, see <http://www.gnu.org/licenses/>.
-
-#include <assert.h>
-#include <linux/input.h>
-#include <sys/ioctl.h>
-#include <fcntl.h>
-#include <unistd.h>
-#include <stdexcept>
-#include <iostream>
-#include <errno.h>
-#include <stdio.h>
-
-#include "input/evdev_device.hpp"
-
-#define BITS_PER_LONG (sizeof(long) * 8)
-#define NBITS(x) ((((x)-1)/BITS_PER_LONG)+1)
-#define OFF(x) ((x)%BITS_PER_LONG)
-#define BIT(x) (1UL<<OFF(x))
-#define LONG(x) ((x)/BITS_PER_LONG)
-#define test_bit(bit, array) ((array[LONG(bit)] >> OFF(bit)) & 1)
-
-namespace Input {
-
-EvdevDevice::EvdevDevice(const std::string& filename) :
- fd(),
- version(),
- relatives(),
- absolutes(),
- keys(),
- name(),
- device(filename)
-{
- fd = open(device.c_str(), O_RDONLY | O_NONBLOCK);
-
- if (fd == -1)
- {
- throw std::runtime_error(filename + ": " + std::string(strerror(errno)));
- }
-
- if (ioctl(fd, EVIOCGVERSION, &version))
- {
- throw std::runtime_error("Error: EvdevDevice: Couldn't get version for "
+ filename);
- }
-
- if (1)
- { // FIXME: Some versions of linux don't have these structs, use arrays
there
- struct input_id id;
- ioctl(fd, EVIOCGID, &id);
- printf("Input device ID: bus 0x%x vendor 0x%x product 0x%x version
0x%x\n",
- id.bustype, id.vendor, id.product, id.vendor);
- }
-
- { // Get the human readable name
- char c_name[256] = "unknown";
- ioctl(fd, EVIOCGNAME(sizeof(c_name)), c_name);
- name = c_name;
- std::cout << "Name: " << name << std::endl;
- }
-
- { // Read in how many buttons the device has
- unsigned long bit[EV_MAX][NBITS(KEY_MAX)];
- memset(bit, 0, sizeof(bit));
- ioctl(fd, EVIOCGBIT(0, EV_MAX), bit[0]);
-
- for (int i = 0; i < EV_MAX; i++)
- {
- if (test_bit(i, bit[0]))
- {
- //printf(" Event type %d (%s)\n", i, events[i] ? events[i] : "?");
-
- if (!i) continue;
-
- ioctl(fd, EVIOCGBIT(i, KEY_MAX), bit[i]);
- for (int j = 0; j < KEY_MAX; j++)
- {
- if (test_bit(j, bit[i]))
- {
- if (i == EV_KEY)
- {
- keys.push_back(Key(j));
- }
- else if (i == EV_ABS)
- {
- // FIXME: Some Linuxes don't have these struct
- struct input_absinfo absinfo;
- ioctl(fd, EVIOCGABS(j), &absinfo);
- // FIXME: we are ignoring absinfo.fuzz and
- // 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)
- {
- relatives.push_back(Relative(j));
- }
- }
- }
- }
- }
- }
-}
-
-EvdevDevice::~EvdevDevice()
-{
-}
-
-void
-EvdevDevice::process_absolute(struct input_event& ev)
-{
- int axis_index = get_absolute_index_by_code(ev.code);
- if (axis_index != -1)
- {
- absolutes[axis_index].pos = ev.value;
-
-#if 0
- CL_InputEvent e;
-
- e.device = CL_InputDevice(this);
- e.type = CL_InputEvent::axis_moved;
- e.id = axis_index;
- e.axis_pos = absolutes[axis_index].get_posf();
- e.repeat_count = 0;
-
- sig_axis_move(e);
-#endif
- }
-}
-
-void
-EvdevDevice::process_relative(struct input_event& ev)
-{
- int idx = get_relative_index_by_code(ev.code);
-
- 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(static_cast<float>(-ev.value) * 0.125f,
0.0f)); // FIXME: make scaling and inversion configurable
- else if (relatives[idx].binding_axis == 1)
- (*i)->set_delta(Vector2f(0, static_cast<float>(-ev.value) * 0.125f));
- }
-}
-
-void
-EvdevDevice::process_key(struct input_event& ev)
-{
- int idx = get_key_index_by_code(ev.code);
-
- 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;
-
- e.device = CL_InputDevice(this);
- e.id = button_index;
- e.repeat_count = 0;
-
- if (ev.value)
- {
- e.type = CL_InputEvent::pressed;
- sig_key_down(e);
- }
- else
- {
- e.type = CL_InputEvent::released;
- sig_key_up(e);
- }
-#endif
-}
-
-int
-EvdevDevice::get_relative_index_by_code(int code)
-{
- for(std::vector<Relative>::size_type i = 0; i != relatives.size(); ++i)
- if (relatives[i].code == code)
- return i;
- return -1;
-}
-
-int
-EvdevDevice::get_key_index_by_code(int code)
-{
- for(std::vector<Key>::size_type i = 0; i != keys.size(); ++i)
- if (keys[i].code == code)
- return i;
- return -1;
-}
-
-int
-EvdevDevice::get_absolute_index_by_code(int code)
-{
- for(std::vector<Absolute>::size_type i = 0; i != absolutes.size(); ++i)
- if (absolutes[i].code == code)
- return i;
- return -1;
-}
-
-void
-EvdevDevice::update(float delta)
-{
- struct input_event ev[128];
- // FIXME: turn this into a while loop so all events get processed
- ssize_t rd = read(fd, ev, sizeof(struct input_event) * 128);
- //std::cout << rd / sizeof(struct input_event) << std::endl;
- if (rd >= static_cast<ssize_t>(sizeof(struct input_event)))
- {
- 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;
-
- switch (ev[i].type)
- {
- case EV_ABS:
- process_absolute(ev[i]);
- break;
-
- case EV_REL:
- process_relative(ev[i]);
- break;
-
- case EV_KEY:
- process_key(ev[i]);
- break;
-
- default:
-#if 0
- if (ev[i].type == EV_SYN)
- {
- printf("Event: time %ld.%06ld, -------------- %s
------------\n",
- ev[i].time.tv_sec, ev[i].time.tv_usec, ev[i].code ?
"Config Sync" : "Report Sync" );
- }
- else if (ev[i].type == EV_MSC && (ev[i].code == MSC_RAW ||
ev[i].code == MSC_SCAN))
- {
- printf("Event: time %ld.%06ld, type %d (%s), code %d (%s),
value %02x\n",
- ev[i].time.tv_sec, ev[i].time.tv_usec, ev[i].type,
- events[ev[i].type] ? events[ev[i].type] : "?",
- ev[i].code,
- names[ev[i].type] ? (names[ev[i].type][ev[i].code]
? names[ev[i].type][ev[i].code] : "?") : "?",
- ev[i].value);
- }
- else
- {
- printf("Event: time %ld.%06ld, type %d (%s), code %d (%s),
value %d\n",
- ev[i].time.tv_sec, ev[i].time.tv_usec, ev[i].type,
- events[ev[i].type] ? events[ev[i].type] : "?",
- ev[i].code,
- names[ev[i].type] ? (names[ev[i].type][ev[i].code]
? names[ev[i].type][ev[i].code] : "?") : "?",
- ev[i].value);
- }
-#endif
- break;
- }
- }
- }
-}
-
-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
-
-/* EOF */
Deleted: trunk/pingus/src/input/evdev_device.hpp
===================================================================
--- trunk/pingus/src/input/evdev_device.hpp 2009-11-05 15:57:44 UTC (rev
4030)
+++ trunk/pingus/src/input/evdev_device.hpp 2009-11-05 18:18:10 UTC (rev
4031)
@@ -1,104 +0,0 @@
-// 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 3 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, see <http://www.gnu.org/licenses/>.
-
-#ifndef HEADER_PINGUS_INPUT_EVDEV_DEVICE_HPP
-#define HEADER_PINGUS_INPUT_EVDEV_DEVICE_HPP
-
-#include <vector>
-#include <string.h>
-#include "input/control.hpp"
-
-namespace Input {
-
-/** */
-class EvdevDevice
-{
-private:
- // Absolute Input Event
- struct Absolute {
- Absolute(int code_, int min_, int max_, int pos_)
- : code(code_), min(min_), max(max_), pos(pos_) {}
-
- int code;
- int min;
- int max;
- int pos;
-
- inline float get_posf() const {
- return static_cast<float>(pos - min) / static_cast<float>(max - min) *
2.0f - 1.0f;
- }
- };
-
- // Relative Input Event
- struct Relative
- {
- Relative(int code_) :
- code(code_),
- pos(0),
- binding_axis(),
- bindings()
- {}
-
- int code;
- int pos;
-
- int binding_axis; // FIXME: Should be part of the binding
- std::vector<Scroller*> bindings;
- };
-
- // Key Input Event
- struct Key {
- Key(int code_) : code(code_), pressed(false), bindings() {}
- int code;
- bool pressed;
- std::vector<Button*> bindings;
- };
-
- int fd;
- int version;
-
- std::vector<Relative> relatives;
- std::vector<Absolute> absolutes;
- std::vector<Key> keys;
-
- std::string name;
- std::string device;
-
-public:
- 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);
- void process_key(struct input_event& ev);
-
- 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
-
-#endif
-
-/* EOF */
Deleted: trunk/pingus/src/input/evdev_driver.cpp
===================================================================
--- trunk/pingus/src/input/evdev_driver.cpp 2009-11-05 15:57:44 UTC (rev
4030)
+++ trunk/pingus/src/input/evdev_driver.cpp 2009-11-05 18:18:10 UTC (rev
4031)
@@ -1,126 +0,0 @@
-// 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 3 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, see <http://www.gnu.org/licenses/>.
-
-#include "input/evdev_device.hpp"
-#include "input/evdev_driver.hpp"
-
-namespace Input {
-
-EvdevDriver::EvdevDriver() :
- devices()
-{
-}
-
-EvdevDriver::~EvdevDriver()
-{
- for(Devices::iterator i = devices.begin(); i != devices.end(); ++i)
- {
- delete *i;
- }
-}
-
-std::string
-EvdevDriver::get_name() const
-{
- return "evdev";
-}
-
-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;
- }
-
- try {
- EvdevDevice* device = new EvdevDevice(device_filename);
- devices.push_back(device);
- return device;
- } catch (std::exception& err) {
- std::cout << "EvdevDriver: " << err.what() << std::endl;
- return 0;
- }
-}
-
-Button*
-EvdevDriver::create_button(const FileReader& reader, Control* parent)
-{
- 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*
-EvdevDriver::create_axis(const FileReader& reader, Control* parent)
-{
- return 0;
-}
-
-Scroller*
-EvdevDriver::create_scroller(const FileReader& reader, Control* parent)
-{
- 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*
-EvdevDriver::create_pointer(const FileReader& reader, Control* parent)
-{
- return 0;
-}
-
-Keyboard*
-EvdevDriver::create_keyboard(const FileReader& reader, Control* parent)
-{
- return 0;
-}
-
-} // namespace Input
-
-/* EOF */
Deleted: trunk/pingus/src/input/evdev_driver.hpp
===================================================================
--- trunk/pingus/src/input/evdev_driver.hpp 2009-11-05 15:57:44 UTC (rev
4030)
+++ trunk/pingus/src/input/evdev_driver.hpp 2009-11-05 18:18:10 UTC (rev
4031)
@@ -1,53 +0,0 @@
-// 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 3 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, see <http://www.gnu.org/licenses/>.
-
-#ifndef HEADER_PINGUS_INPUT_EVDEV_DRIVER_HPP
-#define HEADER_PINGUS_INPUT_EVDEV_DRIVER_HPP
-
-#include "input/driver.hpp"
-
-namespace Input {
-
-class EvdevDevice;
-
-/** */
-class EvdevDriver : public Driver
-{
-private:
- typedef std::vector<EvdevDevice*> Devices;
- Devices devices;
-
-public:
- EvdevDriver();
- ~EvdevDriver();
-
- std::string get_name() const;
- 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);
- Keyboard* create_keyboard(const FileReader& reader, Control* parent);
-
- EvdevDevice* get_device(const std::string& device_filename);
-};
-
-} // namespace Input
-
-#endif
-
-/* EOF */
Deleted: trunk/pingus/src/input/main.cpp
===================================================================
--- trunk/pingus/src/input/main.cpp 2009-11-05 15:57:44 UTC (rev 4030)
+++ trunk/pingus/src/input/main.cpp 2009-11-05 18:18:10 UTC (rev 4031)
@@ -1,37 +0,0 @@
-#include <stdexcept>
-#include "SDL.h"
-#include "input/manager.hpp"
-#include "input/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_Flip(screen);
- }
- } catch (std::exception& err) {
- std::cout << "Exception: " << err.what() << std::endl;
- }
-
- return 0;
-}
-
-/* EOF */
Modified: trunk/pingus/src/input/manager.cpp
===================================================================
--- trunk/pingus/src/input/manager.cpp 2009-11-05 15:57:44 UTC (rev 4030)
+++ trunk/pingus/src/input/manager.cpp 2009-11-05 18:18:10 UTC (rev 4031)
@@ -23,16 +23,16 @@
#include "input/sdl_driver.hpp"
#include "input/core_driver.hpp"
#ifdef HAVE_CWIID
-# include "wiimote_driver.hpp"
+# include "wiimote/wiimote_driver.hpp"
#endif
#ifdef HAVE_XINPUT
-# include "xinput_driver.hpp"
+# include "xinput/xinput_driver.hpp"
#endif
#ifdef HAVE_LINUXUSBMOUSE
-# include "usbmouse_driver.hpp"
+# include "usbmouse/usbmouse_driver.hpp"
#endif
#ifdef HAVE_LINUXEVDEV
-# include "evdev_driver.hpp"
+# include "evdev/evdev_driver.hpp"
#endif
#include "input/manager.hpp"
Copied: trunk/pingus/src/input/usbmouse/usbmouse_driver.cpp (from rev 4030,
trunk/pingus/src/input/usbmouse_driver.cpp)
===================================================================
--- trunk/pingus/src/input/usbmouse_driver.cpp 2009-11-05 15:57:44 UTC (rev
4030)
+++ trunk/pingus/src/input/usbmouse/usbmouse_driver.cpp 2009-11-05 18:18:10 UTC
(rev 4031)
@@ -0,0 +1,355 @@
+// 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 3 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, see <http://www.gnu.org/licenses/>.
+
+#include <stdexcept>
+#include <sys/ioctl.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <iostream>
+#include <errno.h>
+#include <string.h>
+
+#include "pingus/debug.hpp"
+#include "pingus/globals.hpp"
+#include "math/vector2i.hpp"
+#include "input/usbmouse/usbmouse_driver.hpp"
+#include "display/display.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<Scroller*> scroller_bindings;
+ std::vector<std::vector<Button*> > button_bindings;
+
+public:
+ USBMouse(const std::string& device_) :
+ fd(),
+ mouse_pos(),
+ device(device_),
+ buttons(5),
+ pointer_bindings(),
+ scroller_bindings(),
+ button_bindings(7)
+ {
+ 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(Scroller* s)
+ {
+ scroller_bindings.push_back(s);
+ }
+
+ 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 >= Display::get_width())
+ mouse_pos.x = Display::get_width() - 1;
+
+ if (mouse_pos.y < 0)
+ mouse_pos.y = 0;
+ else if (mouse_pos.y >= Display::get_height())
+ mouse_pos.y = Display::get_height() - 1;
+
+ for(std::vector<Pointer*>::iterator i = pointer_bindings.begin();
i != pointer_bindings.end(); ++i)
+ (*i)->set_pos(mouse_pos);
+
+ for(std::vector<Scroller*>::iterator i =
scroller_bindings.begin(); i != scroller_bindings.end(); ++i)
+ (*i)->set_delta(Vector2f(static_cast<float>(-delta_x),
static_cast<float>(delta_y))); // FIXME: Inversion should be configurable
+ }
+
+ // 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;
+
+ // Wheel Down
+ pout(PINGUS_DEBUG_INPUT) << "USBMouseDriver: "
+ << "(usbmouse:button (device \"" <<
device << "\") "
+ << "(button " << 5 << ")) ;; wheel
down" << std::endl;
+
+ for(std::vector<Button*>::iterator j =
button_bindings[5].begin();
+ j != button_bindings[5].end(); ++j)
+ {
+ (*j)->set_state(BUTTON_PRESSED);
+ (*j)->set_state(BUTTON_RELEASED);
+ }
+
+ }
+ }
+ else if (delta_z < 0)
+ {
+ while (delta_z != 0)
+ {
+ ++delta_z;
+
+ // Wheel Down
+ pout(PINGUS_DEBUG_INPUT) << "USBMouseDriver: "
+ << "(usbmouse:button (device \"" <<
device << "\") "
+ << "(button " << 6 << ")) ;; wheel
up" << std::endl;
+
+ for(std::vector<Button*>::iterator j =
button_bindings[6].begin();
+ j != button_bindings[6].end(); ++j)
+ {
+ (*j)->set_state(BUTTON_PRESSED);
+ (*j)->set_state(BUTTON_RELEASED);
+ }
+ }
+ }
+
+ // 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])
+ {
+ pout(PINGUS_DEBUG_INPUT) << "USBMouseDriver: "
+ << "(usbmouse:button (device \"" <<
device << "\") "
+ << "(button " << i << "))" <<
std::endl;
+
+ 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() :
+ usbmice()
+{
+}
+
+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;
+ }
+}
+
+Scroller*
+USBMouseDriver::create_scroller(const FileReader& reader, Control* parent)
+{
+ if (reader.get_name() == "usbmouse:scroller")
+ {
+ std::string device;
+ if (reader.read_string("device", device))
+ {
+ USBMouse* mouse = get_mouse(device);
+ if (mouse)
+ {
+ Scroller* scroller = new Scroller(parent);
+ mouse->add_listener(scroller);
+ return scroller;
+ }
+ 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 */
Copied: trunk/pingus/src/input/usbmouse/usbmouse_driver.hpp (from rev 4029,
trunk/pingus/src/input/usbmouse_driver.hpp)
Deleted: trunk/pingus/src/input/usbmouse_driver.cpp
===================================================================
--- trunk/pingus/src/input/usbmouse_driver.cpp 2009-11-05 15:57:44 UTC (rev
4030)
+++ trunk/pingus/src/input/usbmouse_driver.cpp 2009-11-05 18:18:10 UTC (rev
4031)
@@ -1,355 +0,0 @@
-// 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 3 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, see <http://www.gnu.org/licenses/>.
-
-#include <stdexcept>
-#include <sys/ioctl.h>
-#include <fcntl.h>
-#include <unistd.h>
-#include <iostream>
-#include <errno.h>
-#include <string.h>
-
-#include "pingus/debug.hpp"
-#include "pingus/globals.hpp"
-#include "math/vector2i.hpp"
-#include "input/usbmouse_driver.hpp"
-#include "display/display.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<Scroller*> scroller_bindings;
- std::vector<std::vector<Button*> > button_bindings;
-
-public:
- USBMouse(const std::string& device_) :
- fd(),
- mouse_pos(),
- device(device_),
- buttons(5),
- pointer_bindings(),
- scroller_bindings(),
- button_bindings(7)
- {
- 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(Scroller* s)
- {
- scroller_bindings.push_back(s);
- }
-
- 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 >= Display::get_width())
- mouse_pos.x = Display::get_width() - 1;
-
- if (mouse_pos.y < 0)
- mouse_pos.y = 0;
- else if (mouse_pos.y >= Display::get_height())
- mouse_pos.y = Display::get_height() - 1;
-
- for(std::vector<Pointer*>::iterator i = pointer_bindings.begin();
i != pointer_bindings.end(); ++i)
- (*i)->set_pos(mouse_pos);
-
- for(std::vector<Scroller*>::iterator i =
scroller_bindings.begin(); i != scroller_bindings.end(); ++i)
- (*i)->set_delta(Vector2f(static_cast<float>(-delta_x),
static_cast<float>(delta_y))); // FIXME: Inversion should be configurable
- }
-
- // 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;
-
- // Wheel Down
- pout(PINGUS_DEBUG_INPUT) << "USBMouseDriver: "
- << "(usbmouse:button (device \"" <<
device << "\") "
- << "(button " << 5 << ")) ;; wheel
down" << std::endl;
-
- for(std::vector<Button*>::iterator j =
button_bindings[5].begin();
- j != button_bindings[5].end(); ++j)
- {
- (*j)->set_state(BUTTON_PRESSED);
- (*j)->set_state(BUTTON_RELEASED);
- }
-
- }
- }
- else if (delta_z < 0)
- {
- while (delta_z != 0)
- {
- ++delta_z;
-
- // Wheel Down
- pout(PINGUS_DEBUG_INPUT) << "USBMouseDriver: "
- << "(usbmouse:button (device \"" <<
device << "\") "
- << "(button " << 6 << ")) ;; wheel
up" << std::endl;
-
- for(std::vector<Button*>::iterator j =
button_bindings[6].begin();
- j != button_bindings[6].end(); ++j)
- {
- (*j)->set_state(BUTTON_PRESSED);
- (*j)->set_state(BUTTON_RELEASED);
- }
- }
- }
-
- // 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])
- {
- pout(PINGUS_DEBUG_INPUT) << "USBMouseDriver: "
- << "(usbmouse:button (device \"" <<
device << "\") "
- << "(button " << i << "))" <<
std::endl;
-
- 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() :
- usbmice()
-{
-}
-
-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;
- }
-}
-
-Scroller*
-USBMouseDriver::create_scroller(const FileReader& reader, Control* parent)
-{
- if (reader.get_name() == "usbmouse:scroller")
- {
- std::string device;
- if (reader.read_string("device", device))
- {
- USBMouse* mouse = get_mouse(device);
- if (mouse)
- {
- Scroller* scroller = new Scroller(parent);
- mouse->add_listener(scroller);
- return scroller;
- }
- 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 */
Deleted: trunk/pingus/src/input/usbmouse_driver.hpp
===================================================================
--- trunk/pingus/src/input/usbmouse_driver.hpp 2009-11-05 15:57:44 UTC (rev
4030)
+++ trunk/pingus/src/input/usbmouse_driver.hpp 2009-11-05 18:18:10 UTC (rev
4031)
@@ -1,56 +0,0 @@
-// 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 3 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, see <http://www.gnu.org/licenses/>.
-
-#ifndef HEADER_PINGUS_INPUT_USBMOUSE_DRIVER_HPP
-#define HEADER_PINGUS_INPUT_USBMOUSE_DRIVER_HPP
-
-#include <vector>
-#include "input/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);
- Pointer* create_pointer (const FileReader& reader, Control* parent);
- Keyboard* create_keyboard(const FileReader& reader, Control* parent) {
return 0; }
-private:
- USBMouse* get_mouse(const std::string& device);
-};
-
-} // namespace Input
-
-#endif
-
-/* EOF */
Copied: trunk/pingus/src/input/wiimote/wiimote.cpp (from rev 4029,
trunk/pingus/src/input/wiimote.cpp)
Copied: trunk/pingus/src/input/wiimote/wiimote.hpp (from rev 4029,
trunk/pingus/src/input/wiimote.hpp)
Copied: trunk/pingus/src/input/wiimote/wiimote_driver.cpp (from rev 4029,
trunk/pingus/src/input/wiimote_driver.cpp)
Copied: trunk/pingus/src/input/wiimote/wiimote_driver.hpp (from rev 4029,
trunk/pingus/src/input/wiimote_driver.hpp)
Deleted: trunk/pingus/src/input/wiimote.cpp
===================================================================
--- trunk/pingus/src/input/wiimote.cpp 2009-11-05 15:57:44 UTC (rev 4030)
+++ trunk/pingus/src/input/wiimote.cpp 2009-11-05 18:18:10 UTC (rev 4031)
@@ -1,575 +0,0 @@
-// 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 3 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, see <http://www.gnu.org/licenses/>.
-
-#include <iostream>
-#include <assert.h>
-#include <pthread.h>
-#include "input/math.hpp"
-#include "input/wiimote.hpp"
-
-Wiimote* wiimote = 0;
-
-std::string
-Wiimote::id2str(int id)
-{
- if (id == WIIMOTE_A) return "a";
- else if (id == WIIMOTE_B) return "b";
- else if (id == WIIMOTE_LEFT) return "left";
- else if (id == WIIMOTE_RIGHT) return "right";
- else if (id == WIIMOTE_UP) return "up";
- else if (id == WIIMOTE_DOWN) return "down";
- else if (id == WIIMOTE_PLUS) return "plus";
- else if (id == WIIMOTE_MINUS) return "minus";
- else if (id == WIIMOTE_HOME) return "home";
- else if (id == WIIMOTE_1) return "1";
- else if (id == WIIMOTE_2) return "2";
-
- else if (id == NUNCHUK_C) return "nunchuk:c";
- else if (id == NUNCHUK_Z) return "nunchuk:z";
-
- else if (id == CLASSIC_LEFT) return "classic:left";
- else if (id == CLASSIC_RIGHT) return "classic:right";
- else if (id == CLASSIC_UP) return "classic:up";
- else if (id == CLASSIC_DOWN) return "classic:down";
- else if (id == CLASSIC_PLUS) return "classic:plus";
- else if (id == CLASSIC_MINUS) return "classic:minus";
- else if (id == CLASSIC_HOME) return "classic:home";
- else if (id == CLASSIC_A) return "classic:a";
- else if (id == CLASSIC_B) return "classic:b";
- else if (id == CLASSIC_X) return "classic:x";
- else if (id == CLASSIC_Y) return "classic:y";
- else if (id == CLASSIC_L) return "classic:l";
- else if (id == CLASSIC_R) return "classic:r";
- else if (id == CLASSIC_ZL) return "classic:zl";
- else if (id == CLASSIC_ZR) return "classic:zr";
- else
- return "unknown";
-}
-
-int
-Wiimote::str2id(const std::string& str)
-{
- if (str == "a") return WIIMOTE_A;
- else if (str == "b") return WIIMOTE_B;
- else if (str == "left") return WIIMOTE_LEFT;
- else if (str == "right") return WIIMOTE_RIGHT;
- else if (str == "up") return WIIMOTE_UP;
- else if (str == "down") return WIIMOTE_DOWN;
- else if (str == "plus" || str == "+") return WIIMOTE_PLUS;
- else if (str == "minus" || str == "-") return WIIMOTE_MINUS;
- else if (str == "home") return WIIMOTE_HOME;
- else if (str == "1") return WIIMOTE_1;
- else if (str == "2") return WIIMOTE_2;
-
- else if (str == "nunchuk:c") return NUNCHUK_C;
- else if (str == "nunchuk:z") return NUNCHUK_Z;
-
- else if (str == "classic:left") return CLASSIC_LEFT;
- else if (str == "classic:right") return CLASSIC_RIGHT;
- else if (str == "classic:up") return CLASSIC_UP;
- else if (str == "classic:down") return CLASSIC_DOWN;
- else if (str == "classic:plus" || str == "classic:+") return CLASSIC_PLUS;
- else if (str == "classic:minus" || str == "classic:-") return CLASSIC_MINUS;
- else if (str == "classic:home") return CLASSIC_HOME;
- else if (str == "classic:a") return CLASSIC_A;
- else if (str == "classic:b") return CLASSIC_B;
- else if (str == "classic:x") return CLASSIC_X;
- else if (str == "classic:y") return CLASSIC_Y;
- else if (str == "classic:l") return CLASSIC_L;
- else if (str == "classic:r") return CLASSIC_R;
- else if (str == "classic:zl") return CLASSIC_ZL;
- else if (str == "classic:zr") return CLASSIC_ZR;
- else
- return UNKNOWN;
-}
-
-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;
- }
-
- // FIXME: Could init this depending on what events are actually bound
- if (cwiid_command(m_wiimote, CWIID_CMD_RPT_MODE,
- CWIID_RPT_STATUS |
- CWIID_RPT_NUNCHUK |
- CWIID_RPT_ACC |
- CWIID_RPT_IR |
- 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, WIIMOTE_A);
- CHECK_BTN(CWIID_BTN_B, WIIMOTE_B);
-
- CHECK_BTN(CWIID_BTN_LEFT, WIIMOTE_LEFT);
- CHECK_BTN(CWIID_BTN_RIGHT, WIIMOTE_RIGHT);
- CHECK_BTN(CWIID_BTN_UP, WIIMOTE_UP);
- CHECK_BTN(CWIID_BTN_DOWN, WIIMOTE_DOWN);
-
- CHECK_BTN(CWIID_BTN_PLUS, WIIMOTE_PLUS);
- CHECK_BTN(CWIID_BTN_HOME, WIIMOTE_HOME);
- CHECK_BTN(CWIID_BTN_MINUS, WIIMOTE_MINUS);
-
- CHECK_BTN(CWIID_BTN_1, WIIMOTE_1);
- CHECK_BTN(CWIID_BTN_2, WIIMOTE_2);
-}
-
-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)
-{
- bool is_valid = false;
- for (int i = 0; i < CWIID_IR_SRC_COUNT; ++i)
- is_valid = is_valid || msg.src[i].valid;
-
- if (is_valid)
- {
- std::cout << "IR Report: ";
- for (int i = 0; i < CWIID_IR_SRC_COUNT; ++i)
- {
- if (msg.src[i].valid) {
- std::cout << "(" << msg.src[i].pos[0] << ", " <<
msg.src[i].pos[1] << ") ";
- }
- }
- std::cout << std::endl;
- }
-}
-
-/** 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_nunchuk(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, NUNCHUK_Z);
- CHECK_NCK_BTN(CWIID_NUNCHUK_BTN_C, NUNCHUK_C);
-
- // 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_nunchuk(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[], timespec*)
-{
- wiimote->mesg(w, mesg_count, mesg);
-}
-
-/* EOF */
Deleted: trunk/pingus/src/input/wiimote.hpp
===================================================================
--- trunk/pingus/src/input/wiimote.hpp 2009-11-05 15:57:44 UTC (rev 4030)
+++ trunk/pingus/src/input/wiimote.hpp 2009-11-05 18:18:10 UTC (rev 4031)
@@ -1,177 +0,0 @@
-// 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 3 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, see <http://www.gnu.org/licenses/>.
-
-#ifndef HEADER_PINGUS_INPUT_WIIMOTE_HPP
-#define HEADER_PINGUS_INPUT_WIIMOTE_HPP
-
-#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[], timespec*);
-
- 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:
- enum {
- // Wiimote
- WIIMOTE_A,
- WIIMOTE_B,
- WIIMOTE_LEFT,
- WIIMOTE_RIGHT,
- WIIMOTE_UP,
- WIIMOTE_DOWN,
- WIIMOTE_PLUS,
- WIIMOTE_HOME,
- WIIMOTE_MINUS,
- WIIMOTE_1,
- WIIMOTE_2,
-
- // Nunchuk
- NUNCHUK_C,
- NUNCHUK_Z,
-
- // Classic
- CLASSIC_LEFT,
- CLASSIC_RIGHT,
- CLASSIC_UP,
- CLASSIC_DOWN,
-
- CLASSIC_PLUS,
- CLASSIC_HOME,
- CLASSIC_MINUS,
- CLASSIC_A,
- CLASSIC_B,
- CLASSIC_X,
- CLASSIC_Y,
- CLASSIC_L,
- CLASSIC_R,
- CLASSIC_ZL, // FIXME: This is an axis instead of a button?
- CLASSIC_ZR,
-
- UNKNOWN
- };
-
- static std::string id2str(int id);
- static int str2id(const std::string& str);
-
- 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_nunchuk(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&);
-};
-
-class Wiimote;
-extern Wiimote* wiimote;
-
-#endif
-
-/* EOF */
Deleted: trunk/pingus/src/input/wiimote_driver.cpp
===================================================================
--- trunk/pingus/src/input/wiimote_driver.cpp 2009-11-05 15:57:44 UTC (rev
4030)
+++ trunk/pingus/src/input/wiimote_driver.cpp 2009-11-05 18:18:10 UTC (rev
4031)
@@ -1,200 +0,0 @@
-// 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 3 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, see <http://www.gnu.org/licenses/>.
-
-#include "input/debug.hpp"
-#include "input/globals.hpp"
-#include "input/string_util.hpp"
-#include "input/wiimote.hpp"
-#include "input/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)
- {
- pout(PINGUS_DEBUG_INPUT) << "WiimoteDriver: (wiimote:button (button "
- << event.button.button << ")) => "
- << event.button.down << 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)
- {
- pout(PINGUS_DEBUG_INPUT) << "WiimoteDriver: (wiimote:axis (axis "
- << event.axis.axis << ")) => "
- << event.axis.pos
- << std::endl; // Fixme: should output string
-
- 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
- {
- int button_id = Wiimote::str2id(StringUtil::to_lower(button));
-
- if (button_id == Wiimote::UNKNOWN)
- {
- 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 == "nunchuk:x")
- axis_id = 0;
- else if (axis == "nunchuk:y")
- axis_id = 1;
- 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 */
Deleted: trunk/pingus/src/input/wiimote_driver.hpp
===================================================================
--- trunk/pingus/src/input/wiimote_driver.hpp 2009-11-05 15:57:44 UTC (rev
4030)
+++ trunk/pingus/src/input/wiimote_driver.hpp 2009-11-05 18:18:10 UTC (rev
4031)
@@ -1,60 +0,0 @@
-// 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 3 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, see <http://www.gnu.org/licenses/>.
-
-#ifndef HEADER_PINGUS_INPUT_WIIMOTE_DRIVER_HPP
-#define HEADER_PINGUS_INPUT_WIIMOTE_DRIVER_HPP
-
-#include "input/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);
- Keyboard* create_keyboard(const FileReader& reader, Control* parent) {
return 0; }
-};
-
-} // namespace Input
-
-#endif
-
-/* EOF */
Copied: trunk/pingus/src/input/xinput/xinput_device.cpp (from rev 4029,
trunk/pingus/src/input/xinput_device.cpp)
Copied: trunk/pingus/src/input/xinput/xinput_device.hpp (from rev 4029,
trunk/pingus/src/input/xinput_device.hpp)
Copied: trunk/pingus/src/input/xinput/xinput_driver.cpp (from rev 4029,
trunk/pingus/src/input/xinput_driver.cpp)
Copied: trunk/pingus/src/input/xinput/xinput_driver.hpp (from rev 4029,
trunk/pingus/src/input/xinput_driver.hpp)
Deleted: trunk/pingus/src/input/xinput_device.cpp
===================================================================
--- trunk/pingus/src/input/xinput_device.cpp 2009-11-05 15:57:44 UTC (rev
4030)
+++ trunk/pingus/src/input/xinput_device.cpp 2009-11-05 18:18:10 UTC (rev
4031)
@@ -1,340 +0,0 @@
-// 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 3 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, see <http://www.gnu.org/licenses/>.
-
-#include "SDL_syswm.h"
-
-#include "input/debug.hpp"
-#include "input/globals.hpp"
-
-#include "input/xinput_driver.hpp"
-#include "input/xinput_device.hpp"
-
-namespace Input {
-
-#define INVALID_EVENT_TYPE -1
-
-XInputDevice::XInputDevice(XInputDriver* owner_, XDeviceInfo* info)
- : owner(owner_),
- name(info->name),
- absolute(false),
- num_keys (0),
- motion_type (INVALID_EVENT_TYPE),
- button_press_type (INVALID_EVENT_TYPE),
- button_release_type(INVALID_EVENT_TYPE),
- key_press_type (INVALID_EVENT_TYPE),
- key_release_type (INVALID_EVENT_TYPE),
- proximity_in_type (INVALID_EVENT_TYPE),
- proximity_out_type (INVALID_EVENT_TYPE)
-{
- //info = find_device_info(owner->get_display(), name.c_str(), True);
- //if (!info)
- // throw CL_Error("CL_InputDeviceXInput Error: Couldn't find device: " +
name);
-
- get_info(info);
-
- if (!register_events(owner->get_syswminfo().info.x11.display, info,
name.c_str(), True))
- {
- std::cout << "debug: CL_InputDeviceXInput: Couldn't find device: " <<
name << std::endl;
- }
- else
- {
- //slot_xevent = owner->sig_unknown_xevent.connect(this,
&CL_InputDevice_XInput::on_xevent);
- }
-}
-
-void
-XInputDevice::on_xevent(XEvent &event)
-{
- if (0)
- std::cout << this << " event: "
- << event.type << " Defs: "
- << motion_type << " "
- << button_press_type << " "
- << button_release_type << " "
- << key_press_type << " "
- << key_release_type << " "
- << proximity_out_type << " "
- << proximity_in_type << " "
- << std::endl;
-
- std::vector<AxisInfo> old_axis = axis;
- std::vector<bool> old_buttons = buttons;
-
- if (event.type == motion_type)
- {
- XDeviceMotionEvent *motion = (XDeviceMotionEvent *) &event;
-
- //printf("motion ");
-
- for(int loop=0; loop<motion->axes_count; loop++) {
- //printf("a[%d]=%d ", motion->first_axis + loop,
motion->axis_data[loop]);
- axis[loop + motion->first_axis].pos = motion->axis_data[loop];
- }
- //printf("\n");
- }
- else if ((event.type == button_press_type) ||
- (event.type == button_release_type))
- {
- int loop;
- XDeviceButtonEvent *button = (XDeviceButtonEvent *) &event;
-
- //printf("button %s %d ", (event.type == button_release_type) ?
"release" : "press ", button->button);
-
- buttons[button->button] = (event.type == button_press_type);
-
- for(loop=0; loop<button->axes_count; loop++) {
- //printf("a[%d]=%d ", button->first_axis + loop,
button->axis_data[loop]);
- axis[loop + button->first_axis].pos = button->axis_data[loop];
- }
- //printf("\n");
- }
- else if ((event.type == key_press_type) ||
- (event.type == key_release_type))
- {
- int loop;
- XDeviceKeyEvent *key = (XDeviceKeyEvent *) &event;
-
- printf("key %s %d ", (event.type == key_release_type) ? "release" :
"press ", key->keycode);
-
- for(loop=0; loop<key->axes_count; loop++) {
- printf("a[%d]=%d ", key->first_axis + loop, key->axis_data[loop]);
- axis[loop + key->first_axis].pos = key->axis_data[loop];
- }
- printf("\n");
- }
- else if ((event.type == proximity_out_type) ||
- (event.type == proximity_in_type))
- {
- int loop;
- XProximityNotifyEvent *prox = (XProximityNotifyEvent *) &event;
-
- printf("proximity %s ", (event.type == proximity_in_type) ? "in " :
"out");
-
- for(loop=0; loop<prox->axes_count; loop++) {
- printf("a[%d]=%d ", prox->first_axis + loop, prox->axis_data[loop]);
- axis[loop + prox->first_axis].pos = prox->axis_data[loop];
- }
- printf("\n");
- }
- else
- {
- printf("CL_InputDevice_XInput: what's that %d\n", event.type);
- }
-
-
- for (std::vector<bool>::size_type i = 0; i < buttons.size(); ++i)
- {
- if (buttons[i] != old_buttons[i])
- {
-// CL_InputEvent ie;
-
-// ie.id = i;
-// ie.type = CL_InputEvent::pressed;
-// ie.device = CL_InputDevice(this);
-// ie.mouse_pos = CL_Point(0, 0);
-// ie.axis_pos = 0;
-// ie.repeat_count = false;
-
-// sig_axis_move(ie);
- }
- }
-
- for (std::vector<AxisInfo>::size_type i = 0; i < axis.size(); ++i)
- {
- if (axis[i].pos != old_axis[i].pos)
- {
-// CL_InputEvent ie;
-
-// ie.id = i;
-// ie.type = CL_InputEvent::axis_moved;
-// ie.device = CL_InputDevice(this);
-// ie.mouse_pos = CL_Point(0, 0);
-// ie.axis_pos = get_axis(i);
-// ie.repeat_count = false;
-
-// sig_axis_move(ie);
- }
- }
-}
-
-int
-XInputDevice::register_events(Display* dpy,
- XDeviceInfo* info,
- const char* dev_name,
- Bool handle_proximity)
-{
- int number = 0; /* number of events registered */
- XEventClass event_list[7];
- int i;
- XDevice *device;
- Window root_win;
- unsigned long screen;
- XInputClassInfo *ip;
-
- screen = DefaultScreen(dpy);
- root_win = RootWindow(dpy, screen);
-
- device = XOpenDevice(dpy, info->id);
-
- if (!device)
- {
- fprintf(stderr, "unable to open device %s\n", dev_name);
- return 0;
- }
-
- if (device->num_classes > 0)
- {
- for (ip = device->classes, i=0; i<info->num_classes; ip++, i++)
- {
- switch (ip->input_class)
- {
- case KeyClass:
- DeviceKeyPress (device, key_press_type,
event_list[number]); number++;
- DeviceKeyRelease(device, key_release_type,
event_list[number]); number++;
- break;
-
- case ButtonClass:
- DeviceButtonPress (device, button_press_type,
event_list[number]); number++;
- DeviceButtonRelease(device, button_release_type,
event_list[number]); number++;
- break;
-
- case ValuatorClass:
- DeviceMotionNotify(device, motion_type, event_list[number]);
number++;
- if (handle_proximity) {
- ProximityIn (device, proximity_in_type,
event_list[number]); number++;
- ProximityOut(device, proximity_out_type,
event_list[number]); number++;
- }
- break;
-
- case FeedbackClass:
- std::cout << "Error: XInputDevice: register_events: unhandled
class: FeedbackClass" << std::endl;
- break;
-
- case ProximityClass:
- std::cout << "Error: XInputDevice: register_events: unhandled
class: ProximityClass" << std::endl;
- break;
-
- case FocusClass:
- std::cout << "Error: XInputDevice: register_events: unhandled
class: FocusClass" << std::endl;
- break;
-
- case OtherClass:
- std::cout << "Error: XInputDevice: register_events: unhandled
class: OtherClass" << std::endl;
- break;
-
- default:
- std::cout << "Error: XInputDevice: register_events: unknown
class: " << ip->input_class << std::endl;
- break;
- }
- }
-
- if (XSelectExtensionEvent(dpy, root_win, event_list, number)) {
- fprintf(stderr, "error selecting extended events\n");
- return 0;
- }
- }
-
- //std::cout << "### Registered events: " << number << std::endl;
- return number;
-}
-
-void
-XInputDevice::get_info(XDeviceInfo* info)
-{
- printf("\"%s\"\tid=%ld\t[%s]\n", info->name, info->id,
- (info->use == IsXExtensionDevice) ? "XExtensionDevice" :
- ((info->use == IsXPointer) ? "XPointer" : "XKeyboard"));
-
- XAnyClassPtr any = (XAnyClassPtr)(info->inputclassinfo);
- std::cout << "Info->num_classes: " << info->num_classes << std::endl;
- for (int i = 0; i < info->num_classes; ++i)
- {
- switch (any->c_class)
- {
- case KeyClass:
- {
- XKeyInfoPtr k = (XKeyInfoPtr)any;
-
- printf("\tNum_keys is %d\n", k->num_keys);
- printf("\tMin_keycode is %d\n", k->min_keycode);
- printf("\tMax_keycode is %d\n", k->max_keycode);
-
- num_keys = k->num_keys;
- }
- break;
-
- case ButtonClass:
- {
- XButtonInfoPtr b = (XButtonInfoPtr)any;
- printf("\tNum_buttons is %d\n", b->num_buttons);
-
- buttons.resize(b->num_buttons, false);
- }
- break;
-
- case ValuatorClass:
- {
- XValuatorInfoPtr v = (XValuatorInfoPtr)any;
- XAxisInfoPtr a = (XAxisInfoPtr) ((char*)v +
- sizeof (XValuatorInfo));
-
- printf("\tNum_axes is %d\n", v->num_axes);
- printf("\tMode is %s\n", (v->mode == Absolute) ? "Absolute" :
"Relative");
- printf("\tMotion_buffer is %ld\n", v->motion_buffer);
-
- absolute = (v->mode == Absolute);
-
- for (int j = 0; j < v->num_axes; ++j, ++a)
- {
- printf("\tAxis %d :\n", j);
- printf("\t\tMin_value is %d\n", a->min_value);
- printf("\t\tMax_value is %d\n", a->max_value);
- printf ("\t\tResolution is %d\n", a->resolution);
-
- axis.push_back(AxisInfo(a->min_value, a->max_value,
a->resolution));
- }
- }
- break;
-
- case FeedbackClass:
- std::cout << "Error: XInputDevice: get_info: unhandled class:
FeedbackClass" << std::endl;
- break;
-
- case ProximityClass:
- std::cout << "Error: XInputDevice: get_info: unhandled class:
ProximityClass" << std::endl;
- break;
-
- case FocusClass:
- std::cout << "Error: XInputDevice: get_info: unhandled class:
FocusClass" << std::endl;
- break;
-
- case OtherClass:
- std::cout << "Error: XInputDevice: get_info: unhandled class:
OtherClass" << std::endl;
- break;
-
- default:
- std::cout << "Error: XInputDevice: get_info: unknown class: " <<
any->c_class << std::endl;
- break;
- }
-
- std::cout << "AnyClass ptr: " << any->length << std::endl;
- any = (XAnyClassPtr)((char*)any + any->length);
- }
-}
-
-} // namespace Input
-
-/* EOF */
Deleted: trunk/pingus/src/input/xinput_device.hpp
===================================================================
--- trunk/pingus/src/input/xinput_device.hpp 2009-11-05 15:57:44 UTC (rev
4030)
+++ trunk/pingus/src/input/xinput_device.hpp 2009-11-05 18:18:10 UTC (rev
4031)
@@ -1,87 +0,0 @@
-// 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 3 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, see <http://www.gnu.org/licenses/>.
-
-#ifndef HEADER_PINGUS_INPUT_XINPUT_DEVICE_HPP
-#define HEADER_PINGUS_INPUT_XINPUT_DEVICE_HPP
-
-#include <X11/Xlib.h>
-#include <X11/Xutil.h>
-#include <X11/extensions/XInput.h>
-#include <string>
-#include <vector>
-#include "math/vector2i.hpp"
-
-namespace Input {
-
-class XInputDriver;
-
-/** */
-class XInputDevice
-{
-private:
- struct AxisInfo {
- int min_value;
- int max_value;
- int resolution;
- int pos;
-
- AxisInfo(int min_value_, int max_value_, int resolution_)
- : min_value(min_value_), max_value(max_value_), resolution(resolution_),
pos(0)
- {}
- };
-
-private:
- XInputDriver* owner;
- std::string name;
-
- bool absolute;
-
- std::vector<bool> buttons;
- std::vector<AxisInfo> axis;
-
- int num_keys;
-
- Vector2i mouse_pos;
- Time time_at_last_press;
- int last_press_id;
-
- bool key_states[5];
-
- int motion_type;
- int button_press_type;
- int button_release_type;
- int key_press_type;
- int key_release_type;
- int proximity_in_type;
- int proximity_out_type;
-
-public:
- XInputDevice(XInputDriver* owner_, XDeviceInfo* info);
- ~XInputDevice();
-
- void get_info(XDeviceInfo* info);
- void on_xevent(XEvent &event);
- int register_events(Display* dpy,
- XDeviceInfo* info,
- const char* dev_name,
- Bool handle_proximity);
-};
-
-} // namespace Input
-
-#endif
-
-/* EOF */
Deleted: trunk/pingus/src/input/xinput_driver.cpp
===================================================================
--- trunk/pingus/src/input/xinput_driver.cpp 2009-11-05 15:57:44 UTC (rev
4030)
+++ trunk/pingus/src/input/xinput_driver.cpp 2009-11-05 18:18:10 UTC (rev
4031)
@@ -1,151 +0,0 @@
-// 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 3 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, see <http://www.gnu.org/licenses/>.
-
-#include <iostream>
-
-#include "input/debug.hpp"
-#include "input/globals.hpp"
-
-#include "input/xinput_driver.hpp"
-#include "input/xinput_device.hpp"
-
-namespace Input {
-
-XInputDriver::XInputDriver()
-{
- SDL_VERSION(&sys.version); // this is important!
- if (!SDL_GetWMInfo(&sys))
- std::cout << "Fatal Error: Couldn't get SDL_SysWMinfo" << std::endl;
-
- setup_xinput();
-}
-
-XInputDriver::~XInputDriver()
-{
-}
-
-Bool
-XInputDriver::xinput_is_present()
-{
- XExtensionVersion* version = XGetExtensionVersion(sys.info.x11.display,
INAME);
-
- if (version && (version != (XExtensionVersion*)NoSuchExtension))
- {
- Bool present = version->present;
- XFree(version);
- return present;
- }
- else
- {
- return False;
- }
-}
-
-void
-XInputDriver::setup_xinput()
-{
- if (!xinput_is_present())
- {
- std::cout << "debug: XInput extentsion not found" << std::endl;
- }
- else
- {
- int num_devices;
- XDeviceInfo* info = XListInputDevices(sys.info.x11.display,
&num_devices);
- for(int i = 0; i < num_devices; ++i)
- {
- pout(PINGUS_DEBUG_INPUT) << "XInputDriver: Device name='" <<
info[i].name << "'" << std::endl;
- // FIXME: Xinput isn't necesarrily a mouse, could be anything
- //if (info[i].use == IsXExtensionDevice)
- // {
- devices.push_back(new XInputDevice(this, &info[i]));
- // }
- }
- XFreeDeviceList(info);
- }
-}
-
-void
-XInputDriver::update(float delta)
-{
-}
-
-XDeviceInfo*
-XInputDriver::find_device_info(Display *display,
- const char* name,
- Bool only_extended)
-{
- // FIXME: Not really needed could simply pass XDeviceInfo to the
- // constructor, might however make a nicer interface
- XDeviceInfo *devices;
- int num_devices;
- int len = strlen(name);
- Bool is_id = True;
- XID id = 0;
-
- for(int i = 0; i < len; ++i)
- {
- if (!isdigit(name[i]))
- {
- is_id = False;
- break;
- }
- }
-
- if (is_id) {
- id = atoi(name);
- }
-
- devices = XListInputDevices(display, &num_devices);
-
- for(int i = 0; i < num_devices; ++i)
- {
- if ((!only_extended || (devices[i].use == IsXExtensionDevice)) &&
- ((!is_id && strcmp(devices[i].name, name) == 0) ||
- (is_id && devices[i].id == id))) {
- return &devices[i];
- }
- }
- return NULL;
-}
-
-Button*
-XInputDriver::create_button(const FileReader& reader, Control* parent)
-{
- return 0;
-}
-
-Axis*
-XInputDriver::create_axis(const FileReader& reader, Control* parent)
-{
- return 0;
-}
-
-Scroller*
-XInputDriver::create_scroller(const FileReader& reader, Control* parent)
-{
- return 0;
-}
-
-Pointer*
-XInputDriver::create_pointer (const FileReader& reader, Control* parent)
-{
- return 0;
-}
-
-} // namespace Input
-
-/* EOF */
Deleted: trunk/pingus/src/input/xinput_driver.hpp
===================================================================
--- trunk/pingus/src/input/xinput_driver.hpp 2009-11-05 15:57:44 UTC (rev
4030)
+++ trunk/pingus/src/input/xinput_driver.hpp 2009-11-05 18:18:10 UTC (rev
4031)
@@ -1,67 +0,0 @@
-// 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 3 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, see <http://www.gnu.org/licenses/>.
-
-#ifndef HEADER_PINGUS_INPUT_XINPUT_DRIVER_HPP
-#define HEADER_PINGUS_INPUT_XINPUT_DRIVER_HPP
-
-#include <X11/Xlib.h>
-#include <X11/Xutil.h>
-#include <X11/extensions/XInput.h>
-#include <vector>
-
-#include "SDL_syswm.h"
-#include "input/driver.hpp"
-
-namespace Input {
-
-class XInputDevice;
-
-/** */
-class XInputDriver : public Driver
-{
-private:
- SDL_SysWMinfo sys;
-
- void setup_xinput();
- Bool xinput_is_present();
-
- std::vector<XInputDevice*> devices;
-
-
- XDeviceInfo* find_device_info(Display *display,
- const char* name,
- Bool only_extended);
-public:
- XInputDriver();
- ~XInputDriver();
-
- SDL_SysWMinfo& get_syswminfo() { return sys; }
-
- std::string get_name() const { return "xinput"; }
- 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);
- Keyboard* create_keyboard(const FileReader& reader, Control* parent) {
return 0; }
-};
-
-} // namespace Input
-
-#endif
-
-/* EOF */
Copied: trunk/pingus/test/input_test.cpp (from rev 4029,
trunk/pingus/src/input/main.cpp)
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Pingus-CVS] r4031 - in trunk/pingus: . src/display src/display/opengl src/input src/input/evdev src/input/usbmouse src/input/wiimote src/input/xinput test,
grumbel at BerliOS <=