[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Pingus-CVS] CVS: Games/Pingus/src/input controller.cxx,1.24,1.25 contro
From: |
grumbel |
Subject: |
[Pingus-CVS] CVS: Games/Pingus/src/input controller.cxx,1.24,1.25 controller.hxx,1.15,1.16 |
Date: |
2 Nov 2002 19:21:41 -0000 |
Update of /usr/local/cvsroot/Games/Pingus/src/input
In directory dark:/tmp/cvs-serv327/input
Modified Files:
controller.cxx controller.hxx
Log Message:
added destructor, changed indention
Index: controller.cxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/input/controller.cxx,v
retrieving revision 1.24
retrieving revision 1.25
diff -u -d -r1.24 -r1.25
--- controller.cxx 29 Oct 2002 17:47:15 -0000 1.24
+++ controller.cxx 2 Nov 2002 19:21:39 -0000 1.25
@@ -35,215 +35,225 @@
namespace Input {
- using namespace Axes;
- using namespace Buttons;
- using namespace Pointers;
- using namespace Scrollers;
-
- Controller::Controller (const std::string& configfile) :
standard_pointer(0),
- scroller(0),
- std_pointer_x(0),
- std_pointer_y(0)
- {
+using namespace Axes;
+using namespace Buttons;
+using namespace Pointers;
+using namespace Scrollers;
- xmlDocPtr doc = xmlParseFile(configfile.c_str());
+Controller::Controller (const std::string& configfile)
+ : standard_pointer(0),
+ scroller(0),
+ std_pointer_x(0),
+ std_pointer_y(0)
+{
+ xmlDocPtr doc = xmlParseFile(configfile.c_str());
- if (!doc)
- PingusError::raise("Controller: config file <" + configfile + "> not
found");
+ if (!doc)
+ PingusError::raise("Controller: config file <" + configfile + "> not
found");
- xmlNodePtr cur = doc->ROOT;
+ xmlNodePtr cur = doc->ROOT;
- if (!cur || !XMLhelper::equal_str(cur->name, "pingus-controller"))
- PingusError::raise("Controller: invalid config file <" + configfile +
">");
- cur = XMLhelper::skip_blank(cur->children);
+ if (!cur || !XMLhelper::equal_str(cur->name, "pingus-controller"))
+ PingusError::raise("Controller: invalid config file <" + configfile + ">");
+ cur = XMLhelper::skip_blank(cur->children);
- if (!cur || !XMLhelper::equal_str(cur->name, "controller-config"))
- PingusError::raise("Controller: invalid config file <" + configfile +
">");
- cur = XMLhelper::skip_blank(cur->children);
+ if (!cur || !XMLhelper::equal_str(cur->name, "controller-config"))
+ PingusError::raise("Controller: invalid config file <" + configfile + ">");
+ cur = XMLhelper::skip_blank(cur->children);
- while (cur)
- {
- if (xmlIsBlankNode(cur)) // explicit check cause we need the continue
to check for cur again
- {
- cur = cur->next;
- continue;
- }
+ while (cur)
+ {
+ if (xmlIsBlankNode(cur)) // explicit check cause we need the continue to
check for cur again
+ {
+ cur = cur->next;
+ continue;
+ }
- else if (XMLhelper::equal_str(cur->name, "standard-pointer"))
- standard_pointer =
PointerFactory::create(XMLhelper::skip_blank(cur->children));
+ else if (XMLhelper::equal_str(cur->name, "standard-pointer"))
+ standard_pointer =
PointerFactory::create(XMLhelper::skip_blank(cur->children));
- else if (XMLhelper::equal_str(cur->name, "scroller"))
- scroller =
ScrollerFactory::create(XMLhelper::skip_blank(cur->children));
+ else if (XMLhelper::equal_str(cur->name, "scroller"))
+ scroller =
ScrollerFactory::create(XMLhelper::skip_blank(cur->children));
- else if (XMLhelper::equal_str(cur->name, "primary-button"))
- buttons[primary].first =
ButtonFactory::create(XMLhelper::skip_blank(cur->children));
+ else if (XMLhelper::equal_str(cur->name, "primary-button"))
+ buttons[primary].first =
ButtonFactory::create(XMLhelper::skip_blank(cur->children));
- else if (XMLhelper::equal_str(cur->name, "secondary-button"))
- buttons[secondary].first =
ButtonFactory::create(XMLhelper::skip_blank(cur->children));
+ else if (XMLhelper::equal_str(cur->name, "secondary-button"))
+ buttons[secondary].first =
ButtonFactory::create(XMLhelper::skip_blank(cur->children));
- else if (XMLhelper::equal_str(cur->name, "pause-button"))
- buttons[pause].first =
ButtonFactory::create(XMLhelper::skip_blank(cur->children));
+ else if (XMLhelper::equal_str(cur->name, "pause-button"))
+ buttons[pause].first =
ButtonFactory::create(XMLhelper::skip_blank(cur->children));
- else if (XMLhelper::equal_str(cur->name, "fast-forward-button"))
- buttons[fast_forward].first =
ButtonFactory::create(XMLhelper::skip_blank(cur->children));
+ else if (XMLhelper::equal_str(cur->name, "fast-forward-button"))
+ buttons[fast_forward].first =
ButtonFactory::create(XMLhelper::skip_blank(cur->children));
- else if (XMLhelper::equal_str(cur->name, "armageddon-button"))
- buttons[armageddon].first =
ButtonFactory::create(XMLhelper::skip_blank(cur->children));
+ else if (XMLhelper::equal_str(cur->name, "armageddon-button"))
+ buttons[armageddon].first =
ButtonFactory::create(XMLhelper::skip_blank(cur->children));
- else if (XMLhelper::equal_str(cur->name, "escape-button"))
- buttons[escape].first =
ButtonFactory::create(XMLhelper::skip_blank(cur->children));
+ else if (XMLhelper::equal_str(cur->name, "escape-button"))
+ buttons[escape].first =
ButtonFactory::create(XMLhelper::skip_blank(cur->children));
- else if (XMLhelper::equal_str(cur->name, "action-buttons"))
- create_action_buttons(XMLhelper::skip_blank(cur->children));
+ else if (XMLhelper::equal_str(cur->name, "action-buttons"))
+ create_action_buttons(XMLhelper::skip_blank(cur->children));
- else if (XMLhelper::equal_str(cur->name, "action-up"))
- buttons[action_up].first =
ButtonFactory::create(XMLhelper::skip_blank(cur->children));
+ else if (XMLhelper::equal_str(cur->name, "action-up"))
+ buttons[action_up].first =
ButtonFactory::create(XMLhelper::skip_blank(cur->children));
- else if (XMLhelper::equal_str(cur->name, "action-down"))
- buttons[action_down].first =
ButtonFactory::create(XMLhelper::skip_blank(cur->children));
+ else if (XMLhelper::equal_str(cur->name, "action-down"))
+ buttons[action_down].first =
ButtonFactory::create(XMLhelper::skip_blank(cur->children));
- else
- PingusError::raise(std::string("Unkown Element in Controller Config:
") + ((cur->name) ? reinterpret_cast<const char*>(cur->name) : ""));
+ else
+ PingusError::raise(std::string("Unkown Element in Controller Config:
") + ((cur->name) ? reinterpret_cast<const char*>(cur->name) : ""));
- cur = cur->next;
- }
+ cur = cur->next;
+ }
- if (!standard_pointer)
- {
- standard_pointer = new DummyPointer;
- pwarn << "Controller: No standard pointer - inserting dummy" <<
std::endl;
- }
- else
- {
- std_pointer_x = standard_pointer->get_x_pos();
- std_pointer_y = standard_pointer->get_y_pos();
- }
+ if (!standard_pointer)
+ {
+ standard_pointer = new DummyPointer;
+ pwarn << "Controller: No standard pointer - inserting dummy" <<
std::endl;
+ }
+ else
+ {
+ std_pointer_x = standard_pointer->get_x_pos();
+ std_pointer_y = standard_pointer->get_y_pos();
+ }
- if (!scroller)
- {
- scroller = new DummyScroller;
- pwarn << "Controller: No scroller - inserting dummy" << std::endl;
- }
+ if (!scroller)
+ {
+ scroller = new DummyScroller;
+ pwarn << "Controller: No scroller - inserting dummy" << std::endl;
+ }
- if (!buttons.count(primary))
- {
- buttons[primary].first = new DummyButton;
- pwarn << "Controller: No primary button - inserting dummy" << std::endl;
- }
+ if (!buttons.count(primary))
+ {
+ buttons[primary].first = new DummyButton;
+ pwarn << "Controller: No primary button - inserting dummy" << std::endl;
+ }
- if (!buttons.count(secondary))
- {
- buttons[secondary].first = new DummyButton;
- pwarn << "Controller: No secondary button - inserting dummy" <<
std::endl;
- }
+ if (!buttons.count(secondary))
+ {
+ buttons[secondary].first = new DummyButton;
+ pwarn << "Controller: No secondary button - inserting dummy" <<
std::endl;
+ }
- if (!buttons.count(pause))
- {
- buttons[pause].first = new DummyButton;
- pwarn << "Controller: No pause button - inserting dummy" << std::endl;
- }
+ if (!buttons.count(pause))
+ {
+ buttons[pause].first = new DummyButton;
+ pwarn << "Controller: No pause button - inserting dummy" << std::endl;
+ }
- if (!buttons.count(fast_forward))
- {
- buttons[fast_forward].first = new DummyButton;
- pwarn << "Controller: No fast_forward button - inserting dummy" <<
std::endl;
- }
+ if (!buttons.count(fast_forward))
+ {
+ buttons[fast_forward].first = new DummyButton;
+ pwarn << "Controller: No fast_forward button - inserting dummy" <<
std::endl;
+ }
- if (!buttons.count(armageddon))
- {
- buttons[armageddon].first = new DummyButton;
- pwarn << "Controller: No armageddon button - inserting dummy" <<
std::endl;
- }
+ if (!buttons.count(armageddon))
+ {
+ buttons[armageddon].first = new DummyButton;
+ pwarn << "Controller: No armageddon button - inserting dummy" <<
std::endl;
+ }
- if (!buttons.count(escape))
- {
- buttons[escape].first = new DummyButton;
- pwarn << "Controller: No escape button - inserting dummy" << std::endl;
- }
+ if (!buttons.count(escape))
+ {
+ buttons[escape].first = new DummyButton;
+ pwarn << "Controller: No escape button - inserting dummy" << std::endl;
+ }
- if (!buttons.count(action_up))
- {
- buttons[action_up].first = new DummyButton;
- pwarn << "Controller: No action up button - inserting dummy" <<
std::endl;
- }
+ if (!buttons.count(action_up))
+ {
+ buttons[action_up].first = new DummyButton;
+ pwarn << "Controller: No action up button - inserting dummy" <<
std::endl;
+ }
- if (!buttons.count(action_down))
- {
- buttons[action_down].first = new DummyButton;
- pwarn << "Controller: No action down button - inserting dummy" <<
std::endl;
- }
+ if (!buttons.count(action_down))
+ {
+ buttons[action_down].first = new DummyButton;
+ pwarn << "Controller: No action down button - inserting dummy" <<
std::endl;
+ }
- for (std::map<ButtonName, std::pair<Button*, bool> >::iterator it =
buttons.begin(); it != buttons.end(); ++it)
- it->second.second = it->second.first->is_pressed();
- }
+ for (std::map<ButtonName, std::pair<Button*, bool> >::iterator it =
buttons.begin(); it != buttons.end(); ++it)
+ it->second.second = it->second.first->is_pressed();
+}
- void
- Controller::create_action_buttons (xmlNodePtr cur)
- {
- int count = 0;
+Controller::~Controller ()
+{
+ delete scroller;
+ delete standard_pointer;
+
+ for (std::map<ButtonName, std::pair<Button*, bool> >::iterator it =
buttons.begin(); it != buttons.end(); ++it)
+ delete it->second.first;
+}
+
+void
+Controller::create_action_buttons (xmlNodePtr cur)
+{
+ int count = 0;
- while (cur)
- {
- if (xmlIsBlankNode(cur))
- {
- cur = cur->next;
- continue;
- }
+ while (cur)
+ {
+ if (xmlIsBlankNode(cur))
+ {
+ cur = cur->next;
+ continue;
+ }
- if (XMLhelper::equal_str(cur->name, "action-button"))
- buttons[static_cast<ButtonName>(action_1 + count)].first =
ButtonFactory::create(XMLhelper::skip_blank(cur->children));
- else
- PingusError::raise(std::string("Wrong Element in Controller Config
(action-buttons): ") + reinterpret_cast<const char*>(cur->name));
+ if (XMLhelper::equal_str(cur->name, "action-button"))
+ buttons[static_cast<ButtonName>(action_1 + count)].first =
ButtonFactory::create(XMLhelper::skip_blank(cur->children));
+ else
+ PingusError::raise(std::string("Wrong Element in Controller Config
(action-buttons): ") + reinterpret_cast<const char*>(cur->name));
- cur = cur->next;
- count++;
- }
- }
+ cur = cur->next;
+ count++;
+ }
+}
- void
- Controller::update (float delta)
- {
- for (std::list<Event*>::iterator it = events.begin(); it != events.end();
++it)
- delete *it;
+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 ();
+ events.clear ();
- scroller ->update(delta);
- standard_pointer->update(delta);
+ scroller ->update(delta);
+ standard_pointer->update(delta);
- for (std::map<ButtonName, std::pair<Button*, bool> >::iterator it =
buttons.begin(); it != buttons.end(); ++it)
- it->second.first->update(delta);
+ for (std::map<ButtonName, std::pair<Button*, bool> >::iterator it =
buttons.begin(); it != buttons.end(); ++it)
+ it->second.first->update(delta);
- if (std_pointer_x != standard_pointer->get_x_pos() || std_pointer_y !=
standard_pointer->get_y_pos())
- {
- std_pointer_x = standard_pointer->get_x_pos();
- std_pointer_y = standard_pointer->get_y_pos();
+ if (std_pointer_x != standard_pointer->get_x_pos() || std_pointer_y !=
standard_pointer->get_y_pos())
+ {
+ 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(new PointerEvent(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()));
+ if (scroller->get_x_delta() || scroller->get_y_delta())
+ events.push_back(new ScrollEvent(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));
- else
- events.push_back(new ButtonEvent(it->first, released));
- }
- }
+ 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));
+ else
+ events.push_back(new ButtonEvent(it->first, released));
+ }
+}
- const Button*
- Controller::get_button (ButtonName name)
- {
- if (buttons.count(name))
- return buttons[name].first;
+const Button*
+Controller::get_button (ButtonName name)
+{
+ if (buttons.count(name))
+ return buttons[name].first;
- return 0;
- }
+ return 0;
+}
}
Index: controller.hxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/input/controller.hxx,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -d -r1.15 -r1.16
--- controller.hxx 29 Oct 2002 17:47:15 -0000 1.15
+++ controller.hxx 2 Nov 2002 19:21:39 -0000 1.16
@@ -49,7 +49,8 @@
float std_pointer_y;
public:
- explicit Controller (const std::string& configfile);
+ Controller (const std::string& configfile);
+ ~Controller ();
std::list<Event*>& get_events () { return events; }
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Pingus-CVS] CVS: Games/Pingus/src/input controller.cxx,1.24,1.25 controller.hxx,1.15,1.16,
grumbel <=
- Prev by Date:
[Pingus-CVS] CVS: Games/Pingus/data/levels blockers-timpany-tutorial.xml,1.7,1.8 bomber-tutorial-grumbel.xml,1.2,1.3 bridger-tutorial-grumbel.xml,1.1,1.2 climber-tutorial-lukis.xml,1.2,1.3 digger-tutorial-grumbel.xml,1.1,1.2 jumper-tutorial-grumbel.xml,1.2,1.3 miner-tutorial-grumbel.xml,1.2,1.3
- Next by Date:
[Pingus-CVS] CVS: Games/Pingus pingus.dsp,1.20,1.21
- Previous by thread:
[Pingus-CVS] CVS: Games/Pingus/data/levels blockers-timpany-tutorial.xml,1.7,1.8 bomber-tutorial-grumbel.xml,1.2,1.3 bridger-tutorial-grumbel.xml,1.1,1.2 climber-tutorial-lukis.xml,1.2,1.3 digger-tutorial-grumbel.xml,1.1,1.2 jumper-tutorial-grumbel.xml,1.2,1.3 miner-tutorial-grumbel.xml,1.2,1.3
- Next by thread:
[Pingus-CVS] CVS: Games/Pingus pingus.dsp,1.20,1.21
- Index(es):