[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Feuerkraft-CVS] rev 315 - in trunk/src: . input
From: |
Ingo Ruhnke |
Subject: |
[Feuerkraft-CVS] rev 315 - in trunk/src: . input |
Date: |
Tue, 09 Dec 2003 13:35:36 +0100 |
Author: grumbel
Date: 2003-12-09 13:35:36 +0100 (Tue, 09 Dec 2003)
New Revision: 315
Added:
trunk/src/input/button_axis.cxx
trunk/src/input/button_axis.hxx
Modified:
trunk/src/command_line_arguments.cxx
trunk/src/command_line_arguments.hxx
trunk/src/input/Makefile.am
trunk/src/input/axis_factory.cxx
trunk/src/input/axis_factory.hxx
trunk/src/input/button_factory.cxx
trunk/src/input/input_axis.hxx
trunk/src/input/input_button.hxx
trunk/src/input/input_manager.cxx
trunk/src/input/input_manager_custom.cxx
Log:
- fixed custom input manager a bit, fully working now, but quite a bit error
checking is still lacking
Modified: trunk/src/command_line_arguments.cxx
===================================================================
--- trunk/src/command_line_arguments.cxx 2003-12-09 11:05:11 UTC (rev
314)
+++ trunk/src/command_line_arguments.cxx 2003-12-09 12:35:36 UTC (rev
315)
@@ -36,7 +36,7 @@
{"fps", 'f', "FPS", 0, "Limit of frames per second" },
{"music", 'm', 0, 0, "Enable music" },
{"sound", 's', 0, 0, "Enable sound" },
- {"joystick", 'j', "NUM", 0, "Use Joystick number NUM, instead of
keyboard" },
+ {"controller", 'c', "FILE", 0, "Use controller as defined in FILE" },
{"geometry", 'g', "WIDTHxHEIGHT", 0, "Set screen size" },
{ 0 }
};
@@ -134,12 +134,8 @@
music_enabled = true;
break;
- case 'j':
- if (sscanf(arg, "%d", &joystick) != 1)
- {
- std::cout << "Argument to joystick must be a number" << std::endl;
- exit(EXIT_FAILURE);
- }
+ case 'c':
+ controller_file = arg;
break;
case 's':
Modified: trunk/src/command_line_arguments.hxx
===================================================================
--- trunk/src/command_line_arguments.hxx 2003-12-09 11:05:11 UTC (rev
314)
+++ trunk/src/command_line_arguments.hxx 2003-12-09 12:35:36 UTC (rev
315)
@@ -35,6 +35,7 @@
/** Path to all the datafiles */
std::string datadir;
+ std::string controller_file;
/** number of fps to which the game should limit itself */
float fps;
Modified: trunk/src/input/Makefile.am
===================================================================
--- trunk/src/input/Makefile.am 2003-12-09 11:05:11 UTC (rev 314)
+++ trunk/src/input/Makefile.am 2003-12-09 12:35:36 UTC (rev 315)
@@ -20,6 +20,8 @@
input_button_input_device.cxx \
input_axis_input_device.hxx \
input_axis_input_device.cxx \
+ button_axis.hxx \
+ button_axis.cxx \
button_factory.hxx \
button_factory.cxx \
axis_factory.hxx \
Modified: trunk/src/input/axis_factory.cxx
===================================================================
--- trunk/src/input/axis_factory.cxx 2003-12-09 11:05:11 UTC (rev 314)
+++ trunk/src/input/axis_factory.cxx 2003-12-09 12:35:36 UTC (rev 315)
@@ -20,6 +20,8 @@
#include <iostream>
#include <ClanLib/Display/joystick.h>
#include "input_axis_input_device.hxx"
+#include "button_factory.hxx"
+#include "button_axis.hxx"
#include "axis_factory.hxx"
InputAxis*
@@ -34,6 +36,10 @@
{
return create_joystick_axis(data);
}
+ if (gh_equal_p(sym, gh_symbol2scm("button-axis")))
+ {
+ return create_button_axis(data);
+ }
else
{
std::cout << "AxisFactory::create: parse error" << std::endl;
@@ -59,4 +65,12 @@
}
}
+InputAxis*
+AxisFactory::create_button_axis(SCM lst)
+{
+ InputButton* left = ButtonFactory::create(gh_car(lst));
+ InputButton* right = ButtonFactory::create(gh_cadr(lst));
+ return new ButtonAxis(left, right);
+}
+
/* EOF */
Modified: trunk/src/input/axis_factory.hxx
===================================================================
--- trunk/src/input/axis_factory.hxx 2003-12-09 11:05:11 UTC (rev 314)
+++ trunk/src/input/axis_factory.hxx 2003-12-09 12:35:36 UTC (rev 315)
@@ -30,6 +30,7 @@
static InputAxis* create(SCM lst);
private:
static InputAxis* create_joystick_axis(SCM lst);
+ static InputAxis* create_button_axis(SCM lst);
};
#endif
Added: trunk/src/input/button_axis.cxx
===================================================================
--- trunk/src/input/button_axis.cxx 2003-12-09 11:05:11 UTC (rev 314)
+++ trunk/src/input/button_axis.cxx 2003-12-09 12:35:36 UTC (rev 315)
@@ -0,0 +1,87 @@
+// $Id$
+//
+// Pingus - A free Lemmings clone
+// Copyright (C) 2002 Ingo Ruhnke <address@hidden>
+//
+// This program is free software; you can redistribute it and/or
+// modify it under the terms of the GNU General Public License
+// as published by the Free Software Foundation; either version 2
+// of the License, or (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+#include <iostream>
+#include "input_button.hxx"
+#include "button_axis.hxx"
+
+ButtonAxis::ButtonAxis(InputButton* left, InputButton* right)
+ : left(left), right(right)
+{
+ slots.push_back(left->on_key_down().connect(this,
&ButtonAxis::on_left_down));
+ slots.push_back(left->on_key_up().connect (this, &ButtonAxis::on_left_up));
+
+ slots.push_back(right->on_key_down().connect(this,
&ButtonAxis::on_right_down));
+ slots.push_back(right->on_key_up().connect (this,
&ButtonAxis::on_right_up));
+
+ left_state = false;
+ right_state = false;
+
+ pos = 0.0f;
+}
+
+void
+ButtonAxis::update(float delta)
+{
+ left->update(delta);
+ right->update(delta);
+
+ float new_pos = 0.0f;
+ if (left_state)
+ {
+ new_pos -= 1.0f;
+ }
+
+ if (right_state)
+ {
+ new_pos += 1.0f;
+ }
+
+ if (new_pos != pos)
+ {
+ pos = new_pos;
+ move(pos);
+ }
+}
+
+void
+ButtonAxis::on_left_up()
+{
+ left_state = false;
+}
+
+void
+ButtonAxis::on_left_down()
+{
+ left_state = true;
+}
+
+void
+ButtonAxis::on_right_up()
+{
+ right_state = false;
+}
+
+void
+ButtonAxis::on_right_down()
+{
+ right_state = true;
+}
+
+/* EOF */
Added: trunk/src/input/button_axis.hxx
===================================================================
--- trunk/src/input/button_axis.hxx 2003-12-09 11:05:11 UTC (rev 314)
+++ trunk/src/input/button_axis.hxx 2003-12-09 12:35:36 UTC (rev 315)
@@ -0,0 +1,50 @@
+// $Id$
+//
+// Pingus - A free Lemmings clone
+// Copyright (C) 2002 Ingo Ruhnke <address@hidden>
+//
+// This program is free software; you can redistribute it and/or
+// modify it under the terms of the GNU General Public License
+// as published by the Free Software Foundation; either version 2
+// of the License, or (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+#ifndef HEADER_BUTTON_AXIS_HXX
+#define HEADER_BUTTON_AXIS_HXX
+
+#include "input_axis.hxx"
+
+class InputButton;
+
+class ButtonAxis : public InputAxis
+{
+private:
+ InputButton* left;
+ InputButton* right;
+
+ bool left_state;
+ bool right_state;
+
+ float pos;
+private:
+ void on_left_up();
+ void on_left_down();
+
+ void on_right_up();
+ void on_right_down();
+public:
+ ButtonAxis(InputButton* left, InputButton* right);
+ void update(float delta);
+};
+
+#endif
+
+/* EOF */
Modified: trunk/src/input/button_factory.cxx
===================================================================
--- trunk/src/input/button_factory.cxx 2003-12-09 11:05:11 UTC (rev 314)
+++ trunk/src/input/button_factory.cxx 2003-12-09 12:35:36 UTC (rev 315)
@@ -27,25 +27,22 @@
InputButton*
ButtonFactory::create(SCM lst)
{
- while (!gh_null_p(lst))
- {
- SCM sym = gh_caar(lst);
+ SCM sym = gh_car(lst);
- if (gh_equal_p(sym, gh_symbol2scm("joystick-button")))
- {
- return create_joystick_button(gh_cdar(lst));
- }
- else if (gh_equal_p(sym, gh_symbol2scm("keyboard-button")))
- {
- return create_joystick_button(gh_cdar(lst));
- }
- else
- {
- std::cout << "ButtonFactory::create: parse error" << std::endl;
- }
-
- lst = gh_cdr(lst);
+ if (gh_equal_p(sym, gh_symbol2scm("joystick-button")))
+ {
+ return create_joystick_button(gh_cdr(lst));
}
+ else if (gh_equal_p(sym, gh_symbol2scm("keyboard-button")))
+ {
+ return create_joystick_button(gh_cdr(lst));
+ }
+ else
+ {
+ std::cout << "ButtonFactory::create: parse error: ";
+ gh_display(lst); std::cout << std::endl;
+ }
+
return 0;
}
Modified: trunk/src/input/input_axis.hxx
===================================================================
--- trunk/src/input/input_axis.hxx 2003-12-09 11:05:11 UTC (rev 314)
+++ trunk/src/input/input_axis.hxx 2003-12-09 12:35:36 UTC (rev 315)
@@ -31,7 +31,9 @@
CL_Signal_v1<float> move;
public:
InputAxis() {}
- void update(float delta) {}
+ virtual ~InputAxis() {}
+
+ virtual void update(float delta) {}
CL_Signal_v1<float>& on_move() { return move; }
};
Modified: trunk/src/input/input_button.hxx
===================================================================
--- trunk/src/input/input_button.hxx 2003-12-09 11:05:11 UTC (rev 314)
+++ trunk/src/input/input_button.hxx 2003-12-09 12:35:36 UTC (rev 315)
@@ -33,8 +33,9 @@
public:
InputButton() {}
+ virtual ~InputButton() {}
- void update(float delta) {}
+ virtual void update(float delta) {}
CL_Signal_v0& on_key_down() { return button_down; }
CL_Signal_v0& on_key_up() { return button_up; }
Modified: trunk/src/input/input_manager.cxx
===================================================================
--- trunk/src/input/input_manager.cxx 2003-12-09 11:05:11 UTC (rev 314)
+++ trunk/src/input/input_manager.cxx 2003-12-09 12:35:36 UTC (rev 315)
@@ -47,38 +47,64 @@
}
else
{
- impl = new InputManagerCustom
- (gh_eval_str("'("
- "(primary-button (joystick-button 1 1))"
- "(secondary-button (joystick-button 1 2))"
- "(use-button (joystick-button 1 3))"
- "(menu-button (joystick-button 1 4))"
- "(orientation-axis (joystick-axis 1 2))"
- "(accelerate-axis (joystick-axis 1 3))"
- "(strafe-axis (joystick-axis 1 0))"
- ")"));
+ if (!args->controller_file.empty())
+ {
+ std::cout << "Reading: " << args->controller_file << std::endl;
+ SCM port = scm_open_file(gh_str02scm(args->controller_file.c_str()),
+ gh_str02scm("r"));
+ SCM lst = scm_read(port);
+
+ gh_call1(gh_lookup("display"), lst);
+ gh_call1(gh_lookup("display"), gh_car(lst));
+ gh_call1(gh_lookup("display"),
gh_symbol2scm("feuerkraft-controller"));
+
+ if (gh_equal_p(gh_symbol2scm("feuerkraft-controller"), gh_car(lst)))
+ {
+ impl = new InputManagerCustom(gh_cdr(lst));
+ }
+ else
+ {
+ std::cout << "Error: not a valid controller file: " <<
args->controller_file << std::endl;
+ }
+ scm_close_port(port);
+ }
+
+ if (!impl)
+ {
+ // Set default configuration
+ impl = new InputManagerCustom
+ (gh_eval_str("'("
+ "(primary-button (joystick-button 1 1))"
+ "(secondary-button (joystick-button 1 0))"
+ "(use-button (joystick-button 1 3))"
+ "(menu-button (joystick-button 1 2))"
+ "(orientation-axis (joystick-axis 1 0))"
+ "(accelerate-axis (joystick-axis 1 1))"
+ "(strafe-axis (joystick-axis 1 2))"
+ ")"));
+ }
}
/*
- else if (args->joystick != -1)
+ else if (args->joystick != -1)
{
- if (args->joystick < CL_Joystick::get_device_count())
- {
- std::cout << "InputManager: Using joystick " << args->joystick <<
std::endl;
- impl = new InputManagerJoystick();
- }
- else
- {
- std::ostringstream os;
- os << "Feuerkraft: ClanLib doesn't have joystick number " <<
args->joystick
- << ", only " << CL_Joystick::get_device_count() << " joysticks
available" << std::endl;
- throw std::runtime_error(os.str());
- }
+ if (args->joystick < CL_Joystick::get_device_count())
+ {
+ std::cout << "InputManager: Using joystick " << args->joystick <<
std::endl;
+ impl = new InputManagerJoystick();
}
- else
+ else
{
- std::cout << "InputManager: Using keyboard" << std::endl;
- impl = new InputManagerKeyboard();
+ std::ostringstream os;
+ os << "Feuerkraft: ClanLib doesn't have joystick number " << args->joystick
+ << ", only " << CL_Joystick::get_device_count() << " joysticks available"
<< std::endl;
+ throw std::runtime_error(os.str());
}
+ }
+ else
+ {
+ std::cout << "InputManager: Using keyboard" << std::endl;
+ impl = new InputManagerKeyboard();
+ }
*/
}
Modified: trunk/src/input/input_manager_custom.cxx
===================================================================
--- trunk/src/input/input_manager_custom.cxx 2003-12-09 11:05:11 UTC (rev
314)
+++ trunk/src/input/input_manager_custom.cxx 2003-12-09 12:35:36 UTC (rev
315)
@@ -51,26 +51,30 @@
void
InputManagerCustom::init(SCM lst)
{
+ std::cout << "InputManagerCustom::init" << std::endl;
while (gh_pair_p(lst))
{
+ gh_display(gh_car(lst)); gh_newline();
SCM sym = gh_caar(lst);
SCM data = gh_cdar(lst);
+ gh_display(sym); gh_newline();
+
if (gh_equal_p(sym, gh_symbol2scm("primary-button")))
{
- primary_button = ButtonFactory::create(data);
+ primary_button = ButtonFactory::create(gh_car(data));
}
else if (gh_equal_p(sym, gh_symbol2scm("secondary-button")))
{
- secondary_button = ButtonFactory::create(data);
+ secondary_button = ButtonFactory::create(gh_car(data));
}
else if (gh_equal_p(sym, gh_symbol2scm("use-button")))
{
- use_button = ButtonFactory::create(data);
+ use_button = ButtonFactory::create(gh_car(data));
}
else if (gh_equal_p(sym, gh_symbol2scm("menu-button")))
{
- menu_button = ButtonFactory::create(data);
+ menu_button = ButtonFactory::create(gh_car(data));
}
else if (gh_equal_p(sym, gh_symbol2scm("orientation-axis")))
{
@@ -117,6 +121,14 @@
void
InputManagerCustom::update(float delta)
{
+ primary_button->update(delta);
+ secondary_button->update(delta);
+ use_button->update(delta);
+ menu_button->update(delta);
+
+ orientation_axis->update(delta);
+ accelerate_axis->update(delta);
+ strafe_axis->update(delta);
}
/* EOF */
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Feuerkraft-CVS] rev 315 - in trunk/src: . input,
Ingo Ruhnke <=