[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Pingus-CVS] CVS: Games/Pingus/src/input axis_factory.cxx,1.6,1.7 button
From: |
torangan |
Subject: |
[Pingus-CVS] CVS: Games/Pingus/src/input axis_factory.cxx,1.6,1.7 button_factory.cxx,1.5,1.6 controller.cxx,1.12,1.13 controller.hxx,1.7,1.8 joystick_axis.cxx,1.6,1.7 joystick_button.cxx,1.3,1.4 mouse_button.cxx,1.3,1.4 pointer_factory.cxx,1.3,1.4 scroller_factory.cxx,1.4,1.5 |
Date: |
16 Aug 2002 15:14:02 -0000 |
Update of /usr/local/cvsroot/Games/Pingus/src/input
In directory dark:/tmp/cvs-serv23483/input
Modified Files:
axis_factory.cxx button_factory.cxx controller.cxx
controller.hxx joystick_axis.cxx joystick_button.cxx
mouse_button.cxx pointer_factory.cxx scroller_factory.cxx
Log Message:
moved exceptions out of line - reduces code size (memory usage) and compilation
time
Index: axis_factory.cxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/input/axis_factory.cxx,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- axis_factory.cxx 16 Aug 2002 13:03:36 -0000 1.6
+++ axis_factory.cxx 16 Aug 2002 15:14:00 -0000 1.7
@@ -34,7 +34,7 @@
Axis* AxisFactory::create(xmlNodePtr cur)
{
if (!cur)
- throw PingusError("AxisFactory called without an element");
+ PingusError::raise("AxisFactory called without an element");
if ( ! strcmp(reinterpret_cast<const char*>(cur->name), "button-axis"))
return button_axis(cur);
@@ -52,14 +52,16 @@
return multiple_axis(cur->children);
else
- throw PingusError(std::string("Unknown axis type: ") + ((cur->name) ?
reinterpret_cast<const char*>(cur->name) : ""));
+ PingusError::raise(std::string("Unknown axis type: ") + ((cur->name) ?
reinterpret_cast<const char*>(cur->name) : ""));
+
+ return 0; // never reached
}
Axis* AxisFactory::button_axis (xmlNodePtr cur)
{
char * angle_str = reinterpret_cast<char *>(xmlGetProp(cur,
reinterpret_cast<const xmlChar*>("angle")));
if (!angle_str)
- throw PingusError("ButtonAxis without angle parameter");
+ PingusError::raise("ButtonAxis without angle parameter");
float angle = strtod(angle_str, reinterpret_cast<char**>(NULL));
free(angle_str);
@@ -82,15 +84,15 @@
{
char * angle_str = reinterpret_cast<char *>(xmlGetProp(cur,
reinterpret_cast<const xmlChar*>("angle")));
if (!angle_str)
- throw PingusError("JoystickAxis without angle parameter");
+ PingusError::raise("JoystickAxis without angle parameter");
char * id_str = reinterpret_cast<char *>(xmlGetProp(cur,
reinterpret_cast<const xmlChar*>("id")));
if (!id_str)
- throw PingusError("JoystickAxis without id parameter");
+ PingusError::raise("JoystickAxis without id parameter");
char * axis_str = reinterpret_cast<char *>(xmlGetProp(cur,
reinterpret_cast<const xmlChar*>("axis")));
if (!axis_str)
- throw PingusError("JoystickAxis without axis parameter");
+ PingusError::raise("JoystickAxis without axis parameter");
float angle = strtod(angle_str, reinterpret_cast<char**>(NULL));
int id = strtol(id_str, reinterpret_cast<char**>(NULL), 10);
@@ -107,11 +109,11 @@
{
char * angle_str = reinterpret_cast<char *>(xmlGetProp(cur,
reinterpret_cast<const xmlChar*>("angle")));
if (!angle_str)
- throw PingusError("MouseAxis without angle parameter");
+ PingusError::raise("MouseAxis without angle parameter");
char * axis_str = reinterpret_cast<char *>(xmlGetProp(cur,
reinterpret_cast<const xmlChar*>("axis")));
if (!axis_str)
- throw PingusError("MouseAxis without axis parameter");
+ PingusError::raise("MouseAxis without axis parameter");
float angle = strtod(angle_str, reinterpret_cast<char**>(NULL));
int axis = strtol(axis_str, reinterpret_cast<char**>(NULL), 10);
@@ -139,7 +141,7 @@
}
if (!axes.size())
- throw PingusError("MultipleAxis without any axis");
+ PingusError::raise("MultipleAxis without any axis");
return new MultipleAxis(axes);
}
Index: button_factory.cxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/input/button_factory.cxx,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- button_factory.cxx 16 Aug 2002 13:03:36 -0000 1.5
+++ button_factory.cxx 16 Aug 2002 15:14:00 -0000 1.6
@@ -34,7 +34,7 @@
Button* ButtonFactory::create(xmlNodePtr cur)
{
if (!cur)
- throw PingusError("ButtonFactory called without an element");
+ PingusError::raise("ButtonFactory called without an element");
if ( ! strcmp(reinterpret_cast<const char*>(cur->name), "double-button"))
return double_button(XMLhelper::skip_blank(cur->children));
@@ -55,7 +55,9 @@
return triple_button(XMLhelper::skip_blank(cur->children));
else
- throw PingusError(std::string("Unknown button type: ") + ((cur->name) ?
reinterpret_cast<const char*>(cur->name) : ""));
+ PingusError::raise(std::string("Unknown button type: ") + ((cur->name) ?
reinterpret_cast<const char*>(cur->name) : ""));
+
+ return 0; // never reached
}
Button* ButtonFactory::double_button (xmlNodePtr cur)
@@ -74,11 +76,11 @@
{
char * id_str = reinterpret_cast<char *>(xmlGetProp(cur,
reinterpret_cast<const xmlChar*>("id")));
if (!id_str)
- throw PingusError("JoystickButton without id parameter");
+ PingusError::raise("JoystickButton without id parameter");
char * button_str = reinterpret_cast<char *>(xmlGetProp(cur,
reinterpret_cast<const xmlChar*>("button")));
if (!button_str)
- throw PingusError("JoystickButton without button parameter");
+ PingusError::raise("JoystickButton without button parameter");
int id = strtol(id_str, reinterpret_cast<char**>(NULL), 10);
int button = strtol(button_str, reinterpret_cast<char**>(NULL), 10);
@@ -93,7 +95,7 @@
{
char * key_str = reinterpret_cast<char *>(xmlGetProp(cur,
reinterpret_cast<const xmlChar*>("key")));
if (!key_str)
- throw PingusError("KeyButton without key parameter");
+ PingusError::raise("KeyButton without key parameter");
int key = KeyHelper::string_to_key(key_str);
@@ -106,7 +108,7 @@
{
char * button_str = reinterpret_cast<char *>(xmlGetProp(cur,
reinterpret_cast<const xmlChar*>("button")));
if (!button_str)
- throw PingusError("MouseButton without button parameter");
+ PingusError::raise("MouseButton without button parameter");
int button = strtol(button_str, reinterpret_cast<char**>(NULL), 10);
free(button_str);
Index: controller.cxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/input/controller.cxx,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -d -r1.12 -r1.13
--- controller.cxx 16 Aug 2002 13:03:36 -0000 1.12
+++ controller.cxx 16 Aug 2002 15:14:00 -0000 1.13
@@ -23,7 +23,6 @@
#include "axis_event.hxx"
#include "axis_factory.hxx"
#include "button.hxx"
-#include "button_event.hxx"
#include "button_factory.hxx"
#include "controller.hxx"
#include "dummy_axis.hxx"
@@ -39,20 +38,22 @@
namespace Input
{
- Controller::Controller (const std::string& configfile) :
standard_pointer(0),
- scroller(0),
action_axis(0),
- std_pointer_x(0),
std_pointer_y(0)
+ Controller::Controller (const std::string& configfile) : action_axis(0),
+
standard_pointer(0),
+ scroller(0),
+ std_pointer_x(0),
+ std_pointer_y(0)
{
xmlDocPtr doc = xmlParseFile(configfile.c_str());
if (!doc)
- throw PingusError("Controller: config file <" + configfile + "> not
found");
+ PingusError::raise("Controller: config file <" + configfile + "> not
found");
xmlNodePtr cur = doc->ROOT;
if (!cur || strcmp(reinterpret_cast<const char*>(cur->name),
"pingus-controller") != 0)
- throw PingusError("Controller: invalid config file <" + configfile +
">");
+ PingusError::raise("Controller: invalid config file <" + configfile +
">");
cur = XMLhelper::skip_blank(cur);
@@ -76,22 +77,22 @@
scroller =
ScrollerFactory::create(XMLhelper::skip_blank(cur->children));
else if ( ! strcmp(reinterpret_cast<const char*>(cur->name),
"primary-button"))
- buttons.push_back(std::pair<int, Button*>(primary,
ButtonFactory::create(XMLhelper::skip_blank(cur->children))));
+ buttons.push_back(ButtonEntry(primary,
ButtonFactory::create(XMLhelper::skip_blank(cur->children))));
else if ( ! strcmp(reinterpret_cast<const char*>(cur->name),
"secondary-button"))
- buttons.push_back(std::pair<int, Button*>(secondary,
ButtonFactory::create(XMLhelper::skip_blank(cur->children))));
+ buttons.push_back(ButtonEntry(secondary,
ButtonFactory::create(XMLhelper::skip_blank(cur->children))));
else if ( ! strcmp(reinterpret_cast<const char*>(cur->name),
"pause-button"))
- buttons.push_back(std::pair<int, Button*>(pause,
ButtonFactory::create(XMLhelper::skip_blank(cur->children))));
+ buttons.push_back(ButtonEntry(pause,
ButtonFactory::create(XMLhelper::skip_blank(cur->children))));
else if ( ! strcmp(reinterpret_cast<const char*>(cur->name),
"fast-forward-button"))
- buttons.push_back(std::pair<int, Button*>(fast_forward,
ButtonFactory::create(XMLhelper::skip_blank(cur->children))));
+ buttons.push_back(ButtonEntry(fast_forward,
ButtonFactory::create(XMLhelper::skip_blank(cur->children))));
else if ( ! strcmp(reinterpret_cast<const char*>(cur->name),
"armageddon-button"))
- buttons.push_back(std::pair<int, Button*>(armageddon,
ButtonFactory::create(XMLhelper::skip_blank(cur->children))));
+ buttons.push_back(ButtonEntry(armageddon,
ButtonFactory::create(XMLhelper::skip_blank(cur->children))));
else if ( ! strcmp(reinterpret_cast<const char*>(cur->name),
"escape-button"))
- buttons.push_back(std::pair<int, Button*>(escape,
ButtonFactory::create(XMLhelper::skip_blank(cur->children))));
+ buttons.push_back(ButtonEntry(escape,
ButtonFactory::create(XMLhelper::skip_blank(cur->children))));
else if ( ! strcmp(reinterpret_cast<const char*>(cur->name),
"action-buttons"))
create_action_buttons(XMLhelper::skip_blank(cur->children));
@@ -100,7 +101,7 @@
action_axis =
AxisFactory::create(XMLhelper::skip_blank(cur->children));
else
- throw PingusError(std::string("Unkown Element in Controller Config:
") + ((cur->name) ? reinterpret_cast<const char*>(cur->name) : ""));
+ PingusError::raise(std::string("Unkown Element in Controller Config:
") + ((cur->name) ? reinterpret_cast<const char*>(cur->name) : ""));
cur = cur->next;
}
@@ -118,6 +119,24 @@
if (!action_axis)
action_axis = new DummyAxis;
+
+ if (!find_button(primary))
+ buttons.push_back(ButtonEntry(primary, new DummyButton));
+
+ if (!find_button(secondary))
+ buttons.push_back(ButtonEntry(secondary, new DummyButton));
+
+ if (!find_button(pause))
+ buttons.push_back(ButtonEntry(pause, new DummyButton));
+
+ if (!find_button(fast_forward))
+ buttons.push_back(ButtonEntry(fast_forward, new DummyButton));
+
+ if (!find_button(armageddon))
+ buttons.push_back(ButtonEntry(armageddon, new DummyButton));
+
+ if (!find_button(escape))
+ buttons.push_back(ButtonEntry(escape, new DummyButton));
button_states.resize(buttons.size());
for (unsigned int i=0; i < buttons.size(); i++)
@@ -138,9 +157,10 @@
}
if ( ! strcmp(reinterpret_cast<const char*>(cur->name),
"action-button"))
- buttons.push_back(std::pair<int, Button*>(action_1 + count,
ButtonFactory::create(XMLhelper::skip_blank(cur->children))));
+ buttons.push_back(ButtonEntry(static_cast<ButtonName>(action_1 +
count),
+
ButtonFactory::create(XMLhelper::skip_blank(cur->children))));
else
- throw PingusError(std::string("Wrong Element in Controller Config
(action-buttons): ") + ((cur->name) ? reinterpret_cast<const char*>(cur->name)
: ""));
+ PingusError::raise(std::string("Wrong Element in Controller Config
(action-buttons): ") + reinterpret_cast<const char*>(cur->name));
cur = cur->next;
count++;
@@ -178,9 +198,9 @@
{
button_states[i] = buttons[i].second->is_pressed();
if (button_states[i])
- events.push_back(new
ButtonEvent(static_cast<ButtonName>(buttons[i].first), pressed));
+ events.push_back(new ButtonEvent(buttons[i].first, pressed));
else
- events.push_back(new
ButtonEvent(static_cast<ButtonName>(buttons[i].first), released));
+ events.push_back(new ButtonEvent(buttons[i].first, released));
}
if (action_axis->get_pos())
@@ -190,6 +210,27 @@
events.push_back(new AxisEvent(down));
}
+ const Button*
+ Controller::get_button (ButtonName name) const
+ {
+ const Button* const & temp = find_button(name);
+ if (temp)
+ return temp;
+
+ PingusError::raise("Invalid Button requested");
+
+ return 0; // never reached
+ }
+
+ const Button*
+ Controller::find_button (ButtonName name) const
+ {
+ for (unsigned int i=0; i < buttons.size(); ++i)
+ if (buttons[i].first == name)
+ return buttons[i].second;
+
+ return 0;
+ }
}
/* EOF */
Index: controller.hxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/input/controller.hxx,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- controller.hxx 29 Jul 2002 10:41:17 -0000 1.7
+++ controller.hxx 16 Aug 2002 15:14:00 -0000 1.8
@@ -25,6 +25,7 @@
#include <vector>
#include <utility>
#include "../libxmlfwd.hxx"
+#include "button_event.hxx"
namespace Input
{
@@ -34,15 +35,17 @@
class Pointer;
class Scroller;
+ typedef std::pair<ButtonName, Button*> ButtonEntry;
+
class Controller {
private:
+ Axis* action_axis;
Pointer* standard_pointer;
Scroller* scroller;
- std::vector<std::pair<int, Button*> > buttons;
-
- Axis* action_axis;
+ std::vector<std::pair<ButtonName, Button*> > buttons;
+
std::list<Event*> events;
@@ -55,10 +58,18 @@
std::list<Event*>& get_events () { return events; }
+ const Pointer * get_pointer () const { return standard_pointer; }
+ const Scroller* get_scroller () const { return scroller; }
+ const Axis * get_action_axis () const { return action_axis; }
+
+ const Button* get_button (ButtonName name) const;
+
void update(float delta);
private:
- void create_action_buttons(xmlNodePtr cur);
+ void create_action_buttons (xmlNodePtr cur);
+
+ const Button* find_button (ButtonName name) const;
};
}
Index: joystick_axis.cxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/input/joystick_axis.cxx,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- joystick_axis.cxx 15 Aug 2002 10:57:16 -0000 1.6
+++ joystick_axis.cxx 16 Aug 2002 15:14:00 -0000 1.7
@@ -28,10 +28,10 @@
JoystickAxis::JoystickAxis(int id_, int axis_, float angle_) : id(id_),
axis(axis_), pos(0), angle(angle_)
{
if (static_cast<unsigned int> (id) >= CL_Input::joysticks.size())
- throw PingusError("JoystickAxis: Invalid joystick id");
+ PingusError::raise("JoystickAxis: Invalid joystick id");
if (axis > CL_Input::joysticks[id]->get_num_axes())
- throw PingusError("JoystickAxis: Invalid joystick axis id");
+ PingusError::raise("JoystickAxis: Invalid joystick axis id");
if (angle < 0)
angle = (static_cast<int>(angle) % 360) + 360;
Index: joystick_button.cxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/input/joystick_button.cxx,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- joystick_button.cxx 14 Aug 2002 12:41:22 -0000 1.3
+++ joystick_button.cxx 16 Aug 2002 15:14:00 -0000 1.4
@@ -28,10 +28,10 @@
JoystickButton::JoystickButton(int id_, int button_) : id(id_),
button(button_)
{
if (static_cast<unsigned int>(id) >= CL_Input::joysticks.size())
- throw PingusError("JoystickButton: Invalid joystick id");
+ PingusError::raise("JoystickButton: Invalid joystick id");
if (button > CL_Input::joysticks[id]->get_num_buttons())
- throw PingusError("JoystickButton: Invalid joystick button id");
+ PingusError::raise("JoystickButton: Invalid joystick button id");
}
void
Index: mouse_button.cxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/input/mouse_button.cxx,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- mouse_button.cxx 14 Aug 2002 12:41:22 -0000 1.3
+++ mouse_button.cxx 16 Aug 2002 15:14:00 -0000 1.4
@@ -28,7 +28,7 @@
MouseButton::MouseButton (int button_) : button(button_)
{
if (button > CL_Input::pointers[0]->get_num_buttons())
- throw PingusError("MouseButton: Invalid button id");
+ PingusError::raise("MouseButton: Invalid button id");
}
void
Index: pointer_factory.cxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/input/pointer_factory.cxx,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- pointer_factory.cxx 16 Aug 2002 13:03:36 -0000 1.3
+++ pointer_factory.cxx 16 Aug 2002 15:14:00 -0000 1.4
@@ -32,7 +32,7 @@
Pointer* PointerFactory::create(xmlNodePtr cur)
{
if (!cur)
- throw PingusError("PointerFactory called without an element");
+ PingusError::raise("PointerFactory called without an element");
if ( ! strcmp(reinterpret_cast<const char*>(cur->name), "axis-pointer"))
return axis_pointer(cur);
@@ -44,14 +44,16 @@
return multiple_pointer(cur->children);
else
- throw PingusError(std::string("Unknown pointer type: ") + ((cur->name) ?
reinterpret_cast<const char*>(cur->name) : ""));
+ PingusError::raise(std::string("Unknown pointer type: ") + ((cur->name)
? reinterpret_cast<const char*>(cur->name) : ""));
+
+ return 0; // never reached
}
Pointer* PointerFactory::axis_pointer (xmlNodePtr cur)
{
char* speed_str = reinterpret_cast<char*>(xmlGetProp(cur,
reinterpret_cast<const xmlChar*>("speed")));
if (!speed_str)
- throw PingusError("AxisPointer without speed parameter");
+ PingusError::raise("AxisPointer without speed parameter");
float speed = strtod(speed_str, reinterpret_cast<char**>(NULL));
free(speed_str);
Index: scroller_factory.cxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/input/scroller_factory.cxx,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- scroller_factory.cxx 16 Aug 2002 13:03:36 -0000 1.4
+++ scroller_factory.cxx 16 Aug 2002 15:14:00 -0000 1.5
@@ -40,7 +40,7 @@
ScrollerFactory::create(xmlNodePtr cur)
{
if (!cur)
- throw PingusError("ScrollerFactory called without an element");
+ PingusError::raise("ScrollerFactory called without an element");
if ( ! strcmp(reinterpret_cast<const char*>(cur->name), "axis-scroller"))
return axis_scroller(cur);
@@ -61,7 +61,9 @@
return pointer_scroller(XMLhelper::skip_blank(cur->children));
else
- throw PingusError(std::string("Unknown scroller type: ") + ((cur->name)
? reinterpret_cast<const char*>(cur->name) : ""));
+ PingusError::raise(std::string("Unknown scroller type: ") + ((cur->name)
? reinterpret_cast<const char*>(cur->name) : ""));
+
+ return 0; // never reached
}
Scroller*
@@ -69,7 +71,7 @@
{
char * speed_str = reinterpret_cast<char *>(xmlGetProp(cur,
reinterpret_cast<const xmlChar*>("speed")));
if (!speed_str)
- throw PingusError("AxisScroller without speed parameter");
+ PingusError::raise("AxisScroller without speed parameter");
float speed = strtod(speed_str, reinterpret_cast<char**>(NULL));
free(speed_str);
@@ -97,11 +99,11 @@
{
char * invert_x_str = reinterpret_cast<char *>(xmlGetProp(cur,
reinterpret_cast<const xmlChar*>("invert-x")));
if (!invert_x_str)
- throw PingusError("InvertedScroller without invert X parameter");
+ PingusError::raise("InvertedScroller without invert X parameter");
char * invert_y_str = reinterpret_cast<char *>(xmlGetProp(cur,
reinterpret_cast<const xmlChar*>("invert-y")));
if (!invert_y_str)
- throw PingusError("InvertedScroller without invert Y parameter");
+ PingusError::raise("InvertedScroller without invert Y parameter");
bool invert_x = strtol(invert_x_str, reinterpret_cast<char**>(NULL), 10);
bool invert_y = strtol(invert_x_str, reinterpret_cast<char**>(NULL), 10);
@@ -121,11 +123,11 @@
{
char * id_str = reinterpret_cast<char *>(xmlGetProp(cur,
reinterpret_cast<const xmlChar*>("id")));
if (!id_str)
- throw PingusError("JoystickScroller without id parameter");
+ PingusError::raise("JoystickScroller without id parameter");
char * speed_str = reinterpret_cast<char *>(xmlGetProp(cur,
reinterpret_cast<const xmlChar*>("speed")));
if (!speed_str)
- throw PingusError("JoystickScroller without speed parameter");
+ PingusError::raise("JoystickScroller without speed parameter");
int id = strtol(id_str, reinterpret_cast<char**>(NULL), 10);
float speed = strtod(speed_str, reinterpret_cast<char**>(NULL));
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Pingus-CVS] CVS: Games/Pingus/src/input axis_factory.cxx,1.6,1.7 button_factory.cxx,1.5,1.6 controller.cxx,1.12,1.13 controller.hxx,1.7,1.8 joystick_axis.cxx,1.6,1.7 joystick_button.cxx,1.3,1.4 mouse_button.cxx,1.3,1.4 pointer_factory.cxx,1.3,1.4 scroller_factory.cxx,1.4,1.5,
torangan <=