[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Pingus-CVS] CVS: Games/Pingus/src/input Makefile.am,1.20,1.21 controlle
From: |
grumbel |
Subject: |
[Pingus-CVS] CVS: Games/Pingus/src/input Makefile.am,1.20,1.21 controller.cxx,1.25,1.26 controller.hxx,1.16,1.17 event.hxx,1.6,1.7 axis_event.hxx,1.4,NONE button_event.hxx,1.5,NONE pointer_event.hxx,1.4,NONE scroll_event.hxx,1.3,NONE |
Date: |
20 Dec 2002 01:22:35 -0000 |
Update of /usr/local/cvsroot/Games/Pingus/src/input
In directory dark:/tmp/cvs-serv7667/input
Modified Files:
Makefile.am controller.cxx controller.hxx event.hxx
Removed Files:
axis_event.hxx button_event.hxx pointer_event.hxx
scroll_event.hxx
Log Message:
replaced input classes with a union, this makes all those ugly new/delete stuff
obsolete and makes the code quite a bit more readable (no cast, etc.)
Index: Makefile.am
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/input/Makefile.am,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -d -r1.20 -r1.21
--- Makefile.am 9 Sep 2002 09:38:48 -0000 1.20
+++ Makefile.am 20 Dec 2002 01:22:32 -0000 1.21
@@ -25,19 +25,15 @@
libpingus_input_a_SOURCES = \
axis.hxx \
- axis_event.hxx \
axis_factory.hxx axis_factory.cxx \
button.hxx \
- button_event.hxx \
button_factory.hxx button_factory.cxx \
controller.hxx controller.cxx \
event.hxx \
key_helper.hxx key_helper.cxx \
pointer.hxx \
- pointer_event.hxx \
pointer_factory.hxx pointer_factory.cxx \
scroller.hxx \
- scroller_factory.hxx scroller_factory.cxx \
- scroll_event.hxx
+ scroller_factory.hxx scroller_factory.cxx
# EOF #
Index: controller.cxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/input/controller.cxx,v
retrieving revision 1.25
retrieving revision 1.26
diff -u -d -r1.25 -r1.26
--- controller.cxx 2 Nov 2002 19:21:39 -0000 1.25
+++ controller.cxx 20 Dec 2002 01:22:32 -0000 1.26
@@ -20,18 +20,21 @@
#include "../debug.hxx"
#include "../xml_helper.hxx"
#include "../pingus_error.hxx"
-#include "axis_event.hxx"
+
+/*#include "axis_event.hxx"
#include "axis_factory.hxx"
#include "button_factory.hxx"
+#include "pointer_event.hxx"
+*/
#include "controller.hxx"
#include "axes/dummy_axis.hxx"
#include "buttons/dummy_button.hxx"
#include "pointers/dummy_pointer.hxx"
#include "scrollers/dummy_scroller.hxx"
-#include "pointer_event.hxx"
#include "pointer_factory.hxx"
#include "scroller_factory.hxx"
-#include "scroll_event.hxx"
+#include "button_factory.hxx"
+//#include "scroll_event.hxx"
namespace Input {
@@ -212,10 +215,6 @@
void
Controller::update (float delta)
{
- // FIXME: all this new/delete with events is ugly
- for (std::list<Event*>::iterator it = events.begin(); it != events.end();
++it)
- delete *it;
-
events.clear ();
scroller ->update(delta);
@@ -229,20 +228,20 @@
std_pointer_x = standard_pointer->get_x_pos();
std_pointer_y = standard_pointer->get_y_pos();
- events.push_back(new PointerEvent(standard, std_pointer_x,
std_pointer_y));
+ events.push_back(makePointerEvent(standard, std_pointer_x,
std_pointer_y));
}
if (scroller->get_x_delta() || scroller->get_y_delta())
- events.push_back(new ScrollEvent(scroller->get_x_delta(),
scroller->get_y_delta()));
+ events.push_back(makeScrollEvent(scroller->get_x_delta(),
scroller->get_y_delta()));
for (std::map<ButtonName, std::pair<Button*, bool> >::iterator it =
buttons.begin(); it != buttons.end(); ++it)
if (it->second.first->is_pressed() != it->second.second)
{
it->second.second = ! it->second.second;
if (it->second.second)
- events.push_back(new ButtonEvent(it->first, pressed));
+ events.push_back(makeButtonEvent(it->first, pressed));
else
- events.push_back(new ButtonEvent(it->first, released));
+ events.push_back(makeButtonEvent(it->first, released));
}
}
Index: controller.hxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/input/controller.hxx,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -d -r1.16 -r1.17
--- controller.hxx 2 Nov 2002 19:21:39 -0000 1.16
+++ controller.hxx 20 Dec 2002 01:22:32 -0000 1.17
@@ -25,50 +25,51 @@
#include <string>
#include <vector>
#include "../libxmlfwd.hxx"
-#include "button_event.hxx"
+
+#include "event.hxx"
namespace Input {
- class Axis;
- class Button;
- class Event;
- class Pointer;
- class Scroller;
+class Axis;
+class Button;
+class Pointer;
+class Scroller;
- class Controller {
+class Controller {
- private:
- Pointer* standard_pointer;
- Scroller* scroller;
+private:
+ Pointer* standard_pointer;
+ Scroller* scroller;
- std::map<ButtonName, std::pair<Button*, bool> > buttons;
+ std::map<ButtonName, std::pair<Button*, bool> > buttons;
- std::list<Event*> events;
+ std::vector<Event> events;
- float std_pointer_x;
- float std_pointer_y;
+ float std_pointer_x;
+ float std_pointer_y;
- public:
- Controller (const std::string& configfile);
- ~Controller ();
+public:
+ Controller (const std::string& configfile);
+ ~Controller ();
- std::list<Event*>& get_events () { return events; }
+ std::vector<Event>& get_events () { return events; }
- const Pointer * get_pointer () const { return standard_pointer; }
- const Scroller* get_scroller () const { return scroller; }
+ const Pointer * get_pointer () const { return standard_pointer; }
+ const Scroller* get_scroller () const { return scroller; }
- /// returns the requested Buttons::Button or 0 if it doesn't exist (e.g.
undefined action Buttons::Button)
- const Button* get_button (ButtonName name);
+ /// returns the requested Buttons::Button or 0 if it doesn't exist (e.g.
undefined action Buttons::Button)
+ const Button* get_button (ButtonName name);
- void update (float delta);
+ void update (float delta);
- private:
- void create_action_buttons (xmlNodePtr cur);
+private:
+ void create_action_buttons (xmlNodePtr cur);
- Controller (const Controller&);
- Controller& operator= (const Controller&);
- };
-}
+ Controller (const Controller&);
+ Controller& operator= (const Controller&);
+};
+
+} // namespace Input
#endif
Index: event.hxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/input/event.hxx,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- event.hxx 27 Sep 2002 11:26:46 -0000 1.6
+++ event.hxx 20 Dec 2002 01:22:32 -0000 1.7
@@ -20,24 +20,118 @@
#ifndef HEADER_PINGUS_INPUT_EVENT_HXX
#define HEADER_PINGUS_INPUT_EVENT_HXX
+#include <vector>
#include "../pingus.hxx"
namespace Input {
- enum EventType { ButtonEventType, PointerEventType, AxisEventType,
ScrollEventType };
+enum EventType { ButtonEventType, PointerEventType, AxisEventType,
ScrollEventType };
- class Event {
- public:
- Event () { }
- virtual ~Event () { }
- virtual EventType get_type ()=0;
+enum ButtonName { primary, secondary, pause, fast_forward, armageddon, escape,
action_1, action_2,
+ action_3, action_4, action_5, action_6, action_7, action_8,
action_9, action_10,
+ action_up, action_down };
+
+enum State { pressed, released };
+
+struct ButtonEvent
+{
+ EventType type;
+ ButtonName name;
+ State state;
+};
+
+//#include "pointer_event.hxx"
+
+enum PointerName { standard };
+
+struct PointerEvent
+{
+ EventType type;
+ PointerName name;
+ float x;
+ float y;
+
+};
+
+
+//#include "axis_event.hxx"
+enum AxisName { action };
+
+struct AxisEvent
+{
+ EventType type;
+ float dir;
+ AxisName name;
+};
+
+
+//#include "scroll_event.hxx"
+
+struct ScrollEvent
+{
+ EventType type;
+ float x_delta;
+ float y_delta;
+};
+
+union Event
+{
+ EventType type;
- private:
- Event (const Event&);
- Event& operator= (const Event&);
- };
+ ButtonEvent button;
+ PointerEvent pointer;
+ AxisEvent axis;
+ ScrollEvent scroll;
+};
+
+typedef std::vector<Event> EventLst;
+inline Event makeButtonEvent (ButtonName name, State state)
+{
+ Event event;
+
+ event.button.type = ButtonEventType;
+ event.button.name = name;
+ event.button.state = state;
+
+ return event;
}
+
+inline Event makePointerEvent(PointerName name, float x, float y)
+{
+ Event event;
+
+ event.pointer.type = PointerEventType;
+ event.pointer.name = name;
+ event.pointer.x = x;
+ event.pointer.y = y;
+
+ return event;
+}
+
+inline Event makeAxisEvent (float dir, AxisName name = action)
+{
+ Event event;
+
+ event.axis.type = AxisEventType;
+ event.axis.dir = dir;
+ event.axis.name = name;
+
+ return event;
+}
+
+inline Event makeScrollEvent (float x_delta, float y_delta)
+{
+ Event event;
+
+ event.scroll.type = ScrollEventType;
+ event.scroll.x_delta = x_delta;
+ event.scroll.y_delta = y_delta;
+
+ return event;
+}
+
+} // namespace Input
#endif
--- axis_event.hxx DELETED ---
--- button_event.hxx DELETED ---
--- pointer_event.hxx DELETED ---
--- scroll_event.hxx DELETED ---
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Pingus-CVS] CVS: Games/Pingus/src/input Makefile.am,1.20,1.21 controller.cxx,1.25,1.26 controller.hxx,1.16,1.17 event.hxx,1.6,1.7 axis_event.hxx,1.4,NONE button_event.hxx,1.5,NONE pointer_event.hxx,1.4,NONE scroll_event.hxx,1.3,NONE,
grumbel <=
- Prev by Date:
[Pingus-CVS] CVS: Games/Pingus/src/gui gui_manager.cxx,1.17,1.18 gui_manager.hxx,1.12,1.13
- Next by Date:
[Pingus-CVS] CVS: Games/Pingus/src/input event_fwd.hxx,NONE,1.1 Makefile.am,1.21,1.22
- Previous by thread:
[Pingus-CVS] CVS: Games/Pingus/src/gui gui_manager.cxx,1.17,1.18 gui_manager.hxx,1.12,1.13
- Next by thread:
[Pingus-CVS] CVS: Games/Pingus/src/input event_fwd.hxx,NONE,1.1 Makefile.am,1.21,1.22
- Index(es):