pingus-cvs
[Top][All Lists]
Advanced

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

[Pingus-CVS] CVS: Games/Pingus/src/input axis.hxx,1.2,1.3 axis_factory.c


From: torangan
Subject: [Pingus-CVS] CVS: Games/Pingus/src/input axis.hxx,1.2,1.3 axis_factory.cxx,1.2,1.3 button_factory.cxx,1.2,1.3 controller.cxx,1.1,1.2 controller.hxx,1.1,1.2 pointer_factory.cxx,1.1,1.2
Date: 10 Jul 2002 14:06:22 -0000

Update of /usr/local/cvsroot/Games/Pingus/src/input
In directory dark:/tmp/cvs-serv10931

Modified Files:
        axis.hxx axis_factory.cxx button_factory.cxx controller.cxx 
        controller.hxx pointer_factory.cxx 
Log Message:
bugfixes


Index: axis.hxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/input/axis.hxx,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- axis.hxx    4 Jul 2002 13:11:07 -0000       1.2
+++ axis.hxx    10 Jul 2002 14:06:20 -0000      1.3
@@ -17,18 +17,19 @@
 //  along with this program; if not, write to the Free Software
 //  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 
-#ifndef AXIS_HXX
-#define AXIS_HXX
+#ifndef HEADER_PINGUS_INPUT_AXIS_HXX
+#define HEADER_PINGUS_INPUT_AXIS_HXX
 
 namespace Input
 {
-  class Axis
-  {
-  private:
-  public:
-    virtual float get_pos () =0;
-    virtual float get_angle () =0;
-    virtual void  update(float) =0;
+  class Axis {
+  
+    public:
+      virtual ~Axis () { }
+    
+      virtual float get_pos () =0;
+      virtual float get_angle () =0;
+      virtual void  update(float) =0;
   };
 }
 

Index: axis_factory.cxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/input/axis_factory.cxx,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- axis_factory.cxx    10 Jul 2002 11:22:29 -0000      1.2
+++ axis_factory.cxx    10 Jul 2002 14:06:20 -0000      1.3
@@ -33,6 +33,9 @@
 
   Axis* AxisFactory::create(xmlNodePtr cur)
   {
+    if (!cur)
+      throw PingusError("AxisFactory called without an element");
+
     if (xmlIsBlankNode(cur)) 
       cur = cur->next;
 
@@ -49,13 +52,16 @@
       return mouse_axis(cur);
 
     else
-      throw PingusError("Unknown axis type: " + 
std::string(reinterpret_cast<const char*>(cur->name)));
+      throw PingusError(std::string("Unknown axis type: ") + ((cur->name) ? 
reinterpret_cast<const char*>(cur->name) : ""));
   }
   
   Axis* AxisFactory::button_axis (xmlNodePtr cur)
   {
-    char * angle_str = reinterpret_cast<char *>(xmlGetProp(cur, 
reinterpret_cast<const xmlChar*>("id")));
-    float angle = atof(angle_str);
+    char * angle_str = reinterpret_cast<char *>(xmlGetProp(cur, 
reinterpret_cast<const xmlChar*>("angle")));
+    if (!angle_str)
+      throw PingusError("ButtonAxis without angle parameter");
+      
+    float angle = strtod(angle_str, reinterpret_cast<char**>(NULL));
     free(angle_str);
 
     cur = cur->children;
@@ -74,12 +80,20 @@
   Axis* AxisFactory::joystick_axis (xmlNodePtr cur)
   {
     char * angle_str = reinterpret_cast<char *>(xmlGetProp(cur, 
reinterpret_cast<const xmlChar*>("angle")));
+    if (!angle_str)
+      throw PingusError("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");
+      
     char * axis_str  = reinterpret_cast<char *>(xmlGetProp(cur, 
reinterpret_cast<const xmlChar*>("axis")));
+    if (!axis_str)
+      throw PingusError("JoystickAxis without axis parameter");
     
-    float angle = atof(angle_str);
-    int   id    = atoi(id_str);
-    int   axis  = atoi(axis_str);
+    float angle = strtod(angle_str, reinterpret_cast<char**>(NULL));
+    int   id    = strtol(id_str,    reinterpret_cast<char**>(NULL), 10);
+    int   axis  = strtol(axis_str,  reinterpret_cast<char**>(NULL), 10);
     
     free(angle_str);
     free(id_str);
@@ -91,10 +105,15 @@
   Axis* AxisFactory::mouse_axis (xmlNodePtr cur)
   {
     char * angle_str = reinterpret_cast<char *>(xmlGetProp(cur, 
reinterpret_cast<const xmlChar*>("angle")));
+    if (!angle_str)
+      throw PingusError("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");
     
-    float angle = atof(angle_str);
-    int   axis  = atoi(axis_str);
+    float angle = strtod(angle_str, reinterpret_cast<char**>(NULL));
+    int   axis  = strtol(axis_str,  reinterpret_cast<char**>(NULL), 10);
     
     free(angle_str);
     free(axis_str);
@@ -105,7 +124,10 @@
   Axis* AxisFactory::multiple_axis (xmlNodePtr cur)
   {
     char * angle_str = reinterpret_cast<char *>(xmlGetProp(cur, 
reinterpret_cast<const xmlChar*>("angle")));
-    float angle = atof(angle_str);
+    if (!angle_str)
+      throw PingusError("MultipleAxis without angle parameter");
+      
+    float angle = strtod(angle_str, reinterpret_cast<char**>(NULL));
     free(angle_str);
     
     std::vector<Axis*> axes;

Index: button_factory.cxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/input/button_factory.cxx,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- button_factory.cxx  9 Jul 2002 17:00:10 -0000       1.2
+++ button_factory.cxx  10 Jul 2002 14:06:20 -0000      1.3
@@ -47,16 +47,21 @@
       return multiple_button(cur);
     
     else
-      throw PingusError("Unknown button type: " + 
std::string(reinterpret_cast<const char*>(cur->name)));
+      throw PingusError(std::string("Unknown button type: ") + ((cur->name) ? 
reinterpret_cast<const char*>(cur->name) : ""));
   }
   
   Button* ButtonFactory::joystick_button (xmlNodePtr cur)
   {
     char * id_str     = reinterpret_cast<char *>(xmlGetProp(cur, 
reinterpret_cast<const xmlChar*>("id")));
+    if (!id_str)
+      throw PingusError("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");
     
-    int id     = atoi(id_str);
-    int button = atoi(button_str);
+    int id     = strtol(id_str,     reinterpret_cast<char**>(NULL), 10);
+    int button = strtol(button_str, reinterpret_cast<char**>(NULL), 10);
     
     free(id_str);
     free(button_str);
@@ -67,6 +72,8 @@
   Button* ButtonFactory::key_button (xmlNodePtr cur)
   {
     char * key_str = reinterpret_cast<char *>(xmlGetProp(cur, 
reinterpret_cast<const xmlChar*>("key")));
+    if (!key_str)
+      throw PingusError("KeyButton without key parameter");
     
     int key = KeyHelper::string_to_key(key_str);
     
@@ -78,9 +85,10 @@
   Button* ButtonFactory::mouse_button (xmlNodePtr cur)
   {
     char * button_str = reinterpret_cast<char *>(xmlGetProp(cur, 
reinterpret_cast<const xmlChar*>("button")));
+    if (!button_str)
+      throw PingusError("MouseButton without button parameter");
     
-    int button = atoi(button_str);
-    
+    int button = strtol(button_str, reinterpret_cast<char**>(NULL), 10);
     free(button_str);
     
     return new MouseButton(button);

Index: controller.cxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/input/controller.cxx,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- controller.cxx      9 Jul 2002 16:58:02 -0000       1.1
+++ controller.cxx      10 Jul 2002 14:06:20 -0000      1.2
@@ -23,13 +23,20 @@
 #include "axis_factory.hxx"
 #include "button.hxx"
 #include "button_factory.hxx"
+#include "controller.hxx"
+#include "dummy_axis.hxx"
+#include "dummy_button.hxx"
+#include "dummy_pointer.hxx"
 #include "pointer.hxx"
 #include "pointer_factory.hxx"
-#include "controller.hxx"
 
 namespace Input
 {
-  Controller::Controller (const std::string& configfile)
+  Controller::Controller (const std::string& configfile) : 
standard_pointer(0), scroll_pointer(0),
+                                                           
armageddon_button(0), escape_button(0),
+                                                          
fast_forward_button(0), pause_button(0),
+                                                           primary_button(0), 
secondary_button(0),
+                                                          scroll_modifier(0), 
action_axis(0)
   {
     xmlDocPtr doc = xmlParseFile(configfile.c_str());
     
@@ -49,50 +56,82 @@
     while (cur) 
       {
         if (xmlIsBlankNode(cur))
-          cur = cur->next;
-         
+         {
+            cur = cur->next;
+           continue;
+         }
+
        else if ( ! strcmp(reinterpret_cast<const char*>(cur->name), 
"controller-config"))
          cur = cur->children;
          
        else if ( ! strcmp(reinterpret_cast<const char*>(cur->name), 
"standard-pointer"))
-          standard_pointer = PointerFactory::create(cur);
+          standard_pointer = PointerFactory::create(cur->children);
          
        else if ( ! strcmp(reinterpret_cast<const char*>(cur->name), 
"scroll-pointer"))
-         scroll_pointer = PointerFactory::create(cur);
+         scroll_pointer = PointerFactory::create(cur->children);
          
        else if ( ! strcmp(reinterpret_cast<const char*>(cur->name), 
"primary-button"))
-         primary_button = ButtonFactory::create(cur);
+         primary_button = ButtonFactory::create(cur->children);
          
        else if ( ! strcmp(reinterpret_cast<const char*>(cur->name), 
"secondary-button"))
-         secondary_button = ButtonFactory::create(cur);
+         secondary_button = ButtonFactory::create(cur->children);
          
        else if ( ! strcmp(reinterpret_cast<const char*>(cur->name), 
"scroll-modifier"))
-         scroll_modifier = ButtonFactory::create(cur);
+         scroll_modifier = ButtonFactory::create(cur->children);
          
        else if ( ! strcmp(reinterpret_cast<const char*>(cur->name), 
"pause-button"))
-         pause_button = ButtonFactory::create(cur);
-       
+         pause_button = ButtonFactory::create(cur->children);
+
        else if ( ! strcmp(reinterpret_cast<const char*>(cur->name), 
"fast-forward-button"))
-         fast_forward_button = ButtonFactory::create(cur);
+         fast_forward_button = ButtonFactory::create(cur->children);
        
        else if ( ! strcmp(reinterpret_cast<const char*>(cur->name), 
"armageddon-button"))
-         armageddon_button = ButtonFactory::create(cur);
+         armageddon_button = ButtonFactory::create(cur->children);
        
        else if ( ! strcmp(reinterpret_cast<const char*>(cur->name), 
"escape-button"))
-         escape_button = ButtonFactory::create(cur);
+         escape_button = ButtonFactory::create(cur->children);
        
        else if ( ! strcmp(reinterpret_cast<const char*>(cur->name), 
"action-buttons"))
-         create_action_buttons(cur);
+         create_action_buttons(cur->children);
        
        else if ( ! strcmp(reinterpret_cast<const char*>(cur->name), 
"action-axis"))
-         action_axis = AxisFactory::create(cur);
+         action_axis = AxisFactory::create(cur->children);
          
        else
-         throw PingusError("Unkown Element in Controller Config: " + 
std::string(reinterpret_cast<const char*>(cur->name)));
+         throw PingusError(std::string("Unkown Element in Controller Config: 
") + ((cur->name) ? reinterpret_cast<const char*>(cur->name) : ""));
          
        cur = cur->next;
       }
+
+    if (!standard_pointer)
+      standard_pointer = new DummyPointer;
+
+    if (!scroll_pointer)
+      scroll_pointer = new DummyPointer;
+      
+    if (!armageddon_button)
+      armageddon_button = new DummyButton;
+      
+    if (!escape_button)
+      escape_button = new DummyButton;
+      
+    if (!fast_forward_button)
+      fast_forward_button = new DummyButton;
+      
+    if (!pause_button)
+      pause_button = new DummyButton;
+      
+    if (!primary_button)
+      primary_button = new DummyButton;
+      
+    if (!secondary_button)
+      secondary_button = new DummyButton;
       
+    if (!scroll_modifier)
+      scroll_modifier = new DummyButton;
+      
+    if (!action_axis)
+      action_axis = new DummyAxis;
   }
 
   void
@@ -112,10 +151,12 @@
          action_buttons.push_back(ButtonFactory::create(cur));
          
        else
-         throw PingusError("Wrong Element in Controller Config 
(action-buttons): " + std::string(reinterpret_cast<const char*>(cur->name)));
+         throw PingusError(std::string("Wrong Element in Controller Config 
(action-buttons): ") + ((cur->name) ? reinterpret_cast<const char*>(cur->name) 
: ""));
          
        cur = cur->next;
       }
   }
 
 }
+
+/* EOF */

Index: controller.hxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/input/controller.hxx,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- controller.hxx      9 Jul 2002 16:58:02 -0000       1.1
+++ controller.hxx      10 Jul 2002 14:06:20 -0000      1.2
@@ -24,12 +24,12 @@
 #include <vector>
 #include "../libxmlfwd.hxx"
 
-class Axis;
-class Button;
-class Pointer;
-
 namespace Input
 {
+  class Axis;
+  class Button;
+  class Pointer;
+
   class Controller {
 
     private:

Index: pointer_factory.cxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/input/pointer_factory.cxx,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- pointer_factory.cxx 9 Jul 2002 16:50:26 -0000       1.1
+++ pointer_factory.cxx 10 Jul 2002 14:06:20 -0000      1.2
@@ -31,6 +31,9 @@
 
   Pointer* PointerFactory::create(xmlNodePtr cur)
   {
+    if (!cur)
+      throw PingusError("PointerFactory called without an element");
+  
     if (xmlIsBlankNode(cur)) 
       cur = cur->next;
 
@@ -44,13 +47,16 @@
       return multiple_pointer(cur);
       
     else
-      throw PingusError("Unknown pointer type: " + 
std::string(reinterpret_cast<const char*>(cur->name)));
+      throw PingusError(std::string("Unknown pointer type: ") + ((cur->name) ? 
reinterpret_cast<const char*>(cur->name) : ""));
   }
   
   Pointer* PointerFactory::axis_pointer (xmlNodePtr cur)
   {
     char* speed_str = reinterpret_cast<char*>(xmlGetProp(cur, 
reinterpret_cast<const xmlChar*>("speed")));
-    float speed = atof(speed_str);
+    if (!speed_str)
+      throw PingusError("AxisPointer without speed parameter");
+
+    float speed = strtod(speed_str, reinterpret_cast<char**>(NULL));
     free(speed_str);
 
     std::vector<Axis*> axes;




reply via email to

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