limit framerate of controls' nested event loops
This commit is contained in:
@@ -544,7 +544,7 @@ void cDialog::handle_events() {
|
|||||||
eKeyMod mods = static_cast<eKeyMod>(std::stoi(info["mods"]));
|
eKeyMod mods = static_cast<eKeyMod>(std::stoi(info["mods"]));
|
||||||
controls[info["id"]]->triggerClickHandler(*this, info["id"], mods);
|
controls[info["id"]]->triggerClickHandler(*this, info["id"], mods);
|
||||||
}else{
|
}else{
|
||||||
while(win.pollEvent(currentEvent)) handle_one_event(currentEvent);
|
while(win.pollEvent(currentEvent)) handle_one_event(currentEvent, fps_limiter);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ideally, this should be the only draw call that is done in a cycle.
|
// Ideally, this should be the only draw call that is done in a cycle.
|
||||||
@@ -556,7 +556,7 @@ void cDialog::handle_events() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// This method handles one event received by the dialog.
|
// This method handles one event received by the dialog.
|
||||||
void cDialog::handle_one_event(const sf::Event& currentEvent) {
|
void cDialog::handle_one_event(const sf::Event& currentEvent, cFramerateLimiter& fps_limiter) {
|
||||||
using Key = sf::Keyboard::Key;
|
using Key = sf::Keyboard::Key;
|
||||||
|
|
||||||
cKey key;
|
cKey key;
|
||||||
@@ -671,7 +671,7 @@ void cDialog::handle_one_event(const sf::Event& currentEvent) {
|
|||||||
case sf::Event::MouseButtonPressed:
|
case sf::Event::MouseButtonPressed:
|
||||||
key.mod = current_key_mod();
|
key.mod = current_key_mod();
|
||||||
where = {(int)(currentEvent.mouseButton.x / ui_scale()), (int)(currentEvent.mouseButton.y / ui_scale())};
|
where = {(int)(currentEvent.mouseButton.x / ui_scale()), (int)(currentEvent.mouseButton.y / ui_scale())};
|
||||||
process_click(where, key.mod);
|
process_click(where, key.mod, fps_limiter);
|
||||||
break;
|
break;
|
||||||
default: // To silence warning of unhandled enum values
|
default: // To silence warning of unhandled enum values
|
||||||
break;
|
break;
|
||||||
@@ -874,13 +874,13 @@ void cDialog::process_keystroke(cKey keyHit){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void cDialog::process_click(location where, eKeyMod mods){
|
void cDialog::process_click(location where, eKeyMod mods, cFramerateLimiter& fps_limiter){
|
||||||
// TODO: Return list of all controls whose bounding rect contains the clicked point.
|
// TODO: Return list of all controls whose bounding rect contains the clicked point.
|
||||||
// Then the return value of the click handler can mean "Don't pass this event on to other things below me".
|
// Then the return value of the click handler can mean "Don't pass this event on to other things below me".
|
||||||
ctrlIter iter = controls.begin();
|
ctrlIter iter = controls.begin();
|
||||||
while(iter != controls.end()){
|
while(iter != controls.end()){
|
||||||
if(iter->second->isVisible() && iter->second->isClickable() && where.in(iter->second->getBounds())){
|
if(iter->second->isVisible() && iter->second->isClickable() && where.in(iter->second->getBounds())){
|
||||||
if(iter->second->handleClick(where))
|
if(iter->second->handleClick(where, fps_limiter))
|
||||||
break;
|
break;
|
||||||
else return;
|
else return;
|
||||||
}
|
}
|
||||||
|
@@ -29,6 +29,7 @@
|
|||||||
#include <boost/any.hpp>
|
#include <boost/any.hpp>
|
||||||
#include <boost/iterator/iterator_facade.hpp>
|
#include <boost/iterator/iterator_facade.hpp>
|
||||||
#include "tools/prefs.hpp"
|
#include "tools/prefs.hpp"
|
||||||
|
#include "tools/framerate_limiter.hpp"
|
||||||
|
|
||||||
class cControl;
|
class cControl;
|
||||||
class cTextField;
|
class cTextField;
|
||||||
@@ -261,9 +262,9 @@ private:
|
|||||||
inline double ui_scale() { return get_float_pref("UIScale", 1.0); };
|
inline double ui_scale() { return get_float_pref("UIScale", 1.0); };
|
||||||
void draw();
|
void draw();
|
||||||
void handle_events();
|
void handle_events();
|
||||||
void handle_one_event(const sf::Event&);
|
void handle_one_event(const sf::Event&, cFramerateLimiter& fps_limiter);
|
||||||
void process_keystroke(cKey keyHit);
|
void process_keystroke(cKey keyHit);
|
||||||
void process_click(location where, eKeyMod mods);
|
void process_click(location where, eKeyMod mods, cFramerateLimiter& fps_limiter);
|
||||||
bool dialogNotToast, didAccept;
|
bool dialogNotToast, didAccept;
|
||||||
rectangle winRect;
|
rectangle winRect;
|
||||||
boost::any result;
|
boost::any result;
|
||||||
|
@@ -51,12 +51,12 @@ bool cContainer::parseChildControl(ticpp::Element& elem, std::map<std::string,cC
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool cContainer::handleClick(location where) {
|
bool cContainer::handleClick(location where, cFramerateLimiter& fps_limiter) {
|
||||||
std::string which_clicked;
|
std::string which_clicked;
|
||||||
bool success = false;
|
bool success = false;
|
||||||
forEach([&](std::string id, cControl& ctrl) {
|
forEach([&](std::string id, cControl& ctrl) {
|
||||||
if(!success && ctrl.isClickable() && ctrl.getBounds().contains(where)) {
|
if(!success && ctrl.isClickable() && ctrl.getBounds().contains(where)) {
|
||||||
if(ctrl.handleClick(where)){
|
if(ctrl.handleClick(where, fps_limiter)){
|
||||||
success = true;
|
success = true;
|
||||||
which_clicked = id;
|
which_clicked = id;
|
||||||
}
|
}
|
||||||
|
@@ -48,7 +48,7 @@ public:
|
|||||||
cControl& operator[](std::string id) {return getChild(id);}
|
cControl& operator[](std::string id) {return getChild(id);}
|
||||||
const cControl& operator[](std::string id) const {return const_cast<cContainer&>(*this).getChild(id);}
|
const cControl& operator[](std::string id) const {return const_cast<cContainer&>(*this).getChild(id);}
|
||||||
bool isContainer() const override {return true;}
|
bool isContainer() const override {return true;}
|
||||||
bool handleClick(location where) override;
|
bool handleClick(location where, cFramerateLimiter& fps_limiter) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@@ -221,14 +221,14 @@ void cControl::playClickSound(){
|
|||||||
else sf::sleep(time_in_ticks(14));
|
else sf::sleep(time_in_ticks(14));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool cControl::handleClick(location){
|
bool cControl::handleClick(location, cFramerateLimiter& fps_limiter){
|
||||||
sf::Event e;
|
sf::Event e;
|
||||||
bool done = false, clicked = false;
|
bool done = false, clicked = false;
|
||||||
inWindow->setActive();
|
inWindow->setActive();
|
||||||
depressed = true;
|
depressed = true;
|
||||||
while(!done){
|
while(!done){
|
||||||
redraw();
|
redraw();
|
||||||
if(!inWindow->pollEvent(e)) continue;
|
while(inWindow->pollEvent(e)){
|
||||||
if(e.type == sf::Event::MouseButtonReleased){
|
if(e.type == sf::Event::MouseButtonReleased){
|
||||||
done = true;
|
done = true;
|
||||||
location clickPos(e.mouseButton.x, e.mouseButton.y);
|
location clickPos(e.mouseButton.x, e.mouseButton.y);
|
||||||
@@ -242,6 +242,8 @@ bool cControl::handleClick(location){
|
|||||||
depressed = frame.contains(toPos);
|
depressed = frame.contains(toPos);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
fps_limiter.frame_finished();
|
||||||
|
}
|
||||||
playClickSound();
|
playClickSound();
|
||||||
|
|
||||||
redraw();
|
redraw();
|
||||||
|
@@ -21,6 +21,7 @@
|
|||||||
#include <map>
|
#include <map>
|
||||||
#include <boost/any.hpp>
|
#include <boost/any.hpp>
|
||||||
#include "dialogxml/dialogs/dlogevt.hpp"
|
#include "dialogxml/dialogs/dlogevt.hpp"
|
||||||
|
#include "tools/framerate_limiter.hpp"
|
||||||
|
|
||||||
#include "location.hpp"
|
#include "location.hpp"
|
||||||
|
|
||||||
@@ -329,7 +330,7 @@ public:
|
|||||||
/// The default implementation works for a simple clickable object such as a button that
|
/// The default implementation works for a simple clickable object such as a button that
|
||||||
/// should be hilited in some way while pressed and is cancelled by releasing the mouse
|
/// should be hilited in some way while pressed and is cancelled by releasing the mouse
|
||||||
/// button outside the control's bounds.
|
/// button outside the control's bounds.
|
||||||
virtual bool handleClick(location where);
|
virtual bool handleClick(location where, cFramerateLimiter& fps_limiter);
|
||||||
/// Specifies that another control acts as a label for this one.
|
/// Specifies that another control acts as a label for this one.
|
||||||
/// The practical effect of this is that hiding or showing this control automatically hides or shows the label as well.
|
/// The practical effect of this is that hiding or showing this control automatically hides or shows the label as well.
|
||||||
/// @param label A pointer to the control that acts as a label.
|
/// @param label A pointer to the control that acts as a label.
|
||||||
|
@@ -117,7 +117,7 @@ void cTextField::set_ip(location clickLoc, int cTextField::* insertionPoint) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool cTextField::handleClick(location clickLoc) {
|
bool cTextField::handleClick(location clickLoc, cFramerateLimiter& fps_limiter) {
|
||||||
if(!haveFocus && parent && !parent->setFocus(this)) return true;
|
if(!haveFocus && parent && !parent->setFocus(this)) return true;
|
||||||
haveFocus = true;
|
haveFocus = true;
|
||||||
redraw(); // This ensures the snippets array is populated.
|
redraw(); // This ensures the snippets array is populated.
|
||||||
@@ -141,7 +141,7 @@ bool cTextField::handleClick(location clickLoc) {
|
|||||||
int initial_ip = insertionPoint, initial_sp = selectionPoint;
|
int initial_ip = insertionPoint, initial_sp = selectionPoint;
|
||||||
while(!done) {
|
while(!done) {
|
||||||
redraw();
|
redraw();
|
||||||
if(!inWindow->pollEvent(e)) continue;
|
while(inWindow->pollEvent(e)){
|
||||||
if(e.type == sf::Event::MouseButtonReleased){
|
if(e.type == sf::Event::MouseButtonReleased){
|
||||||
done = true;
|
done = true;
|
||||||
} else if(e.type == sf::Event::MouseMoved){
|
} else if(e.type == sf::Event::MouseMoved){
|
||||||
@@ -162,6 +162,8 @@ bool cTextField::handleClick(location clickLoc) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
fps_limiter.frame_finished();
|
||||||
|
}
|
||||||
redraw();
|
redraw();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@@ -42,7 +42,7 @@ public:
|
|||||||
std::set<eDlogEvt> getSupportedHandlers() const override {
|
std::set<eDlogEvt> getSupportedHandlers() const override {
|
||||||
return {EVT_FOCUS, EVT_DEFOCUS};
|
return {EVT_FOCUS, EVT_DEFOCUS};
|
||||||
}
|
}
|
||||||
bool handleClick(location where) override;
|
bool handleClick(location where, cFramerateLimiter& fps_limiter) override;
|
||||||
void setText(std::string to) override;
|
void setText(std::string to) override;
|
||||||
storage_t store() const override;
|
storage_t store() const override;
|
||||||
void restore(storage_t to) override;
|
void restore(storage_t to) override;
|
||||||
|
@@ -51,12 +51,12 @@ void cLedGroup::addChoice(cLed* ctrl, std::string key) {
|
|||||||
setSelected(key);
|
setSelected(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool cLedGroup::handleClick(location where) {
|
bool cLedGroup::handleClick(location where, cFramerateLimiter& fps_limiter) {
|
||||||
std::string which_clicked;
|
std::string which_clicked;
|
||||||
ledIter iter = choices.begin();
|
ledIter iter = choices.begin();
|
||||||
while(iter != choices.end()){
|
while(iter != choices.end()){
|
||||||
if(iter->second->isVisible() && where.in(iter->second->getBounds())){
|
if(iter->second->isVisible() && where.in(iter->second->getBounds())){
|
||||||
if(iter->second->handleClick(where)) {
|
if(iter->second->handleClick(where, fps_limiter)) {
|
||||||
which_clicked = iter->first;
|
which_clicked = iter->first;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@@ -83,7 +83,7 @@ public:
|
|||||||
bool isClickable() const override;
|
bool isClickable() const override;
|
||||||
bool isFocusable() const override;
|
bool isFocusable() const override;
|
||||||
bool isScrollable() const override;
|
bool isScrollable() const override;
|
||||||
bool handleClick(location where) override;
|
bool handleClick(location where, cFramerateLimiter& fps_limiter) override;
|
||||||
virtual ~cLedGroup();
|
virtual ~cLedGroup();
|
||||||
/// Get one of the LEDs in this group.
|
/// Get one of the LEDs in this group.
|
||||||
/// @param id The unique key of the choice.
|
/// @param id The unique key of the choice.
|
||||||
|
@@ -275,7 +275,7 @@ bool cScrollbar::handle_mouse_released(const sf::Event&) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool cScrollbar::handleClick(location where) {
|
bool cScrollbar::handleClick(location where, cFramerateLimiter& fps_limiter) {
|
||||||
if(max == 0) return false;
|
if(max == 0) return false;
|
||||||
sf::Event e;
|
sf::Event e;
|
||||||
bool done = false, clicked = false;
|
bool done = false, clicked = false;
|
||||||
@@ -299,7 +299,7 @@ bool cScrollbar::handleClick(location where) {
|
|||||||
int diff = clickPos - thumbPos;
|
int diff = clickPos - thumbPos;
|
||||||
while(!done){
|
while(!done){
|
||||||
redraw();
|
redraw();
|
||||||
if(!inWindow->pollEvent(e)) continue;
|
while(inWindow->pollEvent(e)){
|
||||||
location mouseLoc = sf::Mouse::getPosition(*inWindow);
|
location mouseLoc = sf::Mouse::getPosition(*inWindow);
|
||||||
mouseLoc = inWindow->mapPixelToCoords(mouseLoc);
|
mouseLoc = inWindow->mapPixelToCoords(mouseLoc);
|
||||||
int mousePos = vert ? mouseLoc.y : mouseLoc.x;
|
int mousePos = vert ? mouseLoc.y : mouseLoc.x;
|
||||||
@@ -350,6 +350,8 @@ bool cScrollbar::handleClick(location where) {
|
|||||||
thumbPos += btn_size + pos * (bar_size - btn_size) / max;
|
thumbPos += btn_size + pos * (bar_size - btn_size) / max;
|
||||||
thumbPos = minmax(mousePos,bar_end - btn_size * 2,thumbPos);
|
thumbPos = minmax(mousePos,bar_end - btn_size * 2,thumbPos);
|
||||||
}
|
}
|
||||||
|
fps_limiter.frame_finished();
|
||||||
|
}
|
||||||
redraw();
|
redraw();
|
||||||
return clicked;
|
return clicked;
|
||||||
}
|
}
|
||||||
|
@@ -73,7 +73,7 @@ public:
|
|||||||
/// Create a new scrollbar.
|
/// Create a new scrollbar.
|
||||||
/// @param parent The parent dialog.
|
/// @param parent The parent dialog.
|
||||||
explicit cScrollbar(cDialog& parent);
|
explicit cScrollbar(cDialog& parent);
|
||||||
bool handleClick(location where) override;
|
bool handleClick(location where, cFramerateLimiter& fps_limiter) override;
|
||||||
storage_t store() const override;
|
storage_t store() const override;
|
||||||
void restore(storage_t to) override;
|
void restore(storage_t to) override;
|
||||||
bool isClickable() const override;
|
bool isClickable() const override;
|
||||||
|
@@ -20,11 +20,11 @@ cScrollPane::cScrollPane(cDialog& parent) : cContainer(CTRL_PANE, parent), scrol
|
|||||||
recalcRect();
|
recalcRect();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool cScrollPane::handleClick(location where) {
|
bool cScrollPane::handleClick(location where, cFramerateLimiter& fps_limiter) {
|
||||||
if(scroll.getBounds().contains(where))
|
if(scroll.getBounds().contains(where))
|
||||||
return scroll.handleClick(where);
|
return scroll.handleClick(where, fps_limiter);
|
||||||
where.y += scroll.getPosition();
|
where.y += scroll.getPosition();
|
||||||
return cContainer::handleClick(where);
|
return cContainer::handleClick(where, fps_limiter);
|
||||||
}
|
}
|
||||||
|
|
||||||
void cScrollPane::recalcRect() {
|
void cScrollPane::recalcRect() {
|
||||||
|
@@ -28,7 +28,7 @@ public:
|
|||||||
bool parseAttribute(ticpp::Attribute& attr, std::string tagName, std::string fname) override;
|
bool parseAttribute(ticpp::Attribute& attr, std::string tagName, std::string fname) override;
|
||||||
bool parseContent(ticpp::Node& content, int n, std::string tagName, std::string fname, std::string& text) override;
|
bool parseContent(ticpp::Node& content, int n, std::string tagName, std::string fname, std::string& text) override;
|
||||||
void validatePostParse(ticpp::Element& who, std::string fname, const std::set<std::string>& attrs, const std::multiset<std::string>& nodes) override;
|
void validatePostParse(ticpp::Element& who, std::string fname, const std::set<std::string>& attrs, const std::multiset<std::string>& nodes) override;
|
||||||
bool handleClick(location where) override;
|
bool handleClick(location where, cFramerateLimiter& fps_limiter) override;
|
||||||
bool hasChild(std::string id) const override;
|
bool hasChild(std::string id) const override;
|
||||||
cControl& getChild(std::string id) override;
|
cControl& getChild(std::string id) override;
|
||||||
storage_t store() const override;
|
storage_t store() const override;
|
||||||
|
@@ -1102,7 +1102,7 @@ static void handle_party_death() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool handle_action(const sf::Event& event) {
|
bool handle_action(const sf::Event& event, cFramerateLimiter& fps_limiter) {
|
||||||
long item_hit;
|
long item_hit;
|
||||||
bool are_done = false;
|
bool are_done = false;
|
||||||
bool need_redraw = false, did_something = false, need_reprint = false;
|
bool need_redraw = false, did_something = false, need_reprint = false;
|
||||||
@@ -1129,12 +1129,12 @@ bool handle_action(const sf::Event& event) {
|
|||||||
|
|
||||||
// Now split off the extra stuff, like talking and shopping.
|
// Now split off the extra stuff, like talking and shopping.
|
||||||
if(overall_mode == MODE_TALKING) {
|
if(overall_mode == MODE_TALKING) {
|
||||||
handle_talk_event(the_point);
|
handle_talk_event(the_point, fps_limiter);
|
||||||
if(overall_mode != MODE_TALKING)
|
if(overall_mode != MODE_TALKING)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if(overall_mode == MODE_SHOPPING) {
|
if(overall_mode == MODE_SHOPPING) {
|
||||||
handle_shop_event(the_point);
|
handle_shop_event(the_point, fps_limiter);
|
||||||
if(overall_mode != MODE_SHOPPING)
|
if(overall_mode != MODE_SHOPPING)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -1630,7 +1630,7 @@ void initiate_outdoor_combat(short i) {
|
|||||||
draw_terrain();
|
draw_terrain();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool handle_keystroke(const sf::Event& event){
|
bool handle_keystroke(const sf::Event& event, cFramerateLimiter& fps_limiter){
|
||||||
bool are_done = false;
|
bool are_done = false;
|
||||||
location pass_point; // TODO: This isn't needed
|
location pass_point; // TODO: This isn't needed
|
||||||
std::ostringstream sout;
|
std::ostringstream sout;
|
||||||
@@ -1708,7 +1708,7 @@ bool handle_keystroke(const sf::Event& event){
|
|||||||
pass_point = mainPtr.mapCoordsToPixel(pass_point, mainView);
|
pass_point = mainPtr.mapCoordsToPixel(pass_point, mainView);
|
||||||
pass_event.mouseButton.x = pass_point.x;
|
pass_event.mouseButton.x = pass_point.x;
|
||||||
pass_event.mouseButton.y = pass_point.y;
|
pass_event.mouseButton.y = pass_point.y;
|
||||||
are_done = handle_action(pass_event);
|
are_done = handle_action(pass_event, fps_limiter);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if(overall_mode == MODE_SHOPPING) { // shopping keystrokes
|
else if(overall_mode == MODE_SHOPPING) { // shopping keystrokes
|
||||||
@@ -1725,7 +1725,7 @@ bool handle_keystroke(const sf::Event& event){
|
|||||||
pass_point = mainPtr.mapCoordsToPixel(pass_point, mainView);
|
pass_point = mainPtr.mapCoordsToPixel(pass_point, mainView);
|
||||||
pass_event.mouseButton.x = pass_point.x;
|
pass_event.mouseButton.x = pass_point.x;
|
||||||
pass_event.mouseButton.y = pass_point.y;
|
pass_event.mouseButton.y = pass_point.y;
|
||||||
are_done = handle_action(pass_event);
|
are_done = handle_action(pass_event, fps_limiter);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
for(short i = 0; i < 10; i++)
|
for(short i = 0; i < 10; i++)
|
||||||
@@ -1737,7 +1737,7 @@ bool handle_keystroke(const sf::Event& event){
|
|||||||
pass_point = mainPtr.mapCoordsToPixel(terrain_click[i], mainView);
|
pass_point = mainPtr.mapCoordsToPixel(terrain_click[i], mainView);
|
||||||
pass_event.mouseButton.x = pass_point.x;
|
pass_event.mouseButton.x = pass_point.x;
|
||||||
pass_event.mouseButton.y = pass_point.y;
|
pass_event.mouseButton.y = pass_point.y;
|
||||||
are_done = handle_action(pass_event);
|
are_done = handle_action(pass_event, fps_limiter);
|
||||||
return are_done;
|
return are_done;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -5,17 +5,18 @@
|
|||||||
#include <SFML/Window/Event.hpp>
|
#include <SFML/Window/Event.hpp>
|
||||||
#include "location.hpp"
|
#include "location.hpp"
|
||||||
#include "dialogxml/keycodes.hpp"
|
#include "dialogxml/keycodes.hpp"
|
||||||
|
#include "tools/framerate_limiter.hpp"
|
||||||
|
|
||||||
void init_screen_locs();
|
void init_screen_locs();
|
||||||
bool prime_time();
|
bool prime_time();
|
||||||
bool handle_action(const sf::Event& event);
|
bool handle_action(const sf::Event& event, cFramerateLimiter& fps_limiter);
|
||||||
void advance_time(bool did_something, bool need_redraw, bool need_reprint);
|
void advance_time(bool did_something, bool need_redraw, bool need_reprint);
|
||||||
void handle_move(location destination, bool& did_something, bool& need_redraw, bool& need_reprint);
|
void handle_move(location destination, bool& did_something, bool& need_redraw, bool& need_reprint);
|
||||||
void handle_monster_actions(bool& need_redraw, bool& need_reprint);
|
void handle_monster_actions(bool& need_redraw, bool& need_reprint);
|
||||||
bool someone_awake();
|
bool someone_awake();
|
||||||
void handle_menu_spell(short spell_picked,short spell_type) ;
|
void handle_menu_spell(short spell_picked,short spell_type) ;
|
||||||
void initiate_outdoor_combat(short i);
|
void initiate_outdoor_combat(short i);
|
||||||
bool handle_keystroke(const sf::Event& event);
|
bool handle_keystroke(const sf::Event& event, cFramerateLimiter& fps_limiter);
|
||||||
bool handle_scroll(const sf::Event& event);
|
bool handle_scroll(const sf::Event& event);
|
||||||
void do_load();
|
void do_load();
|
||||||
void post_load();
|
void post_load();
|
||||||
|
@@ -206,16 +206,16 @@ void end_shop_mode() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void handle_shop_event(location p) {
|
void handle_shop_event(location p, cFramerateLimiter& fps_limiter) {
|
||||||
if(p.in(talk_help_rect)) {
|
if(p.in(talk_help_rect)) {
|
||||||
if(!help_btn->handleClick(p))
|
if(!help_btn->handleClick(p, fps_limiter))
|
||||||
return;
|
return;
|
||||||
give_help(226,27);
|
give_help(226,27);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(p.in(shop_done_rect)) {
|
if(p.in(shop_done_rect)) {
|
||||||
if(done_btn->handleClick(p))
|
if(done_btn->handleClick(p, fps_limiter))
|
||||||
end_shop_mode();
|
end_shop_mode();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -706,7 +706,7 @@ static void show_job_bank(int which_bank, std::string title) {
|
|||||||
job_dlg.run();
|
job_dlg.run();
|
||||||
}
|
}
|
||||||
|
|
||||||
void handle_talk_event(location p) {
|
void handle_talk_event(location p, cFramerateLimiter& fps_limiter) {
|
||||||
short get_pc,s1 = -1,s2 = -1;
|
short get_pc,s1 = -1,s2 = -1;
|
||||||
char asked[4];
|
char asked[4];
|
||||||
|
|
||||||
@@ -714,7 +714,7 @@ void handle_talk_event(location p) {
|
|||||||
eTalkNode ttype;
|
eTalkNode ttype;
|
||||||
|
|
||||||
if(p.in(talk_help_rect)) {
|
if(p.in(talk_help_rect)) {
|
||||||
if(!help_btn->handleClick(p))
|
if(!help_btn->handleClick(p, fps_limiter))
|
||||||
return;
|
return;
|
||||||
give_help(205,6);
|
give_help(205,6);
|
||||||
return;
|
return;
|
||||||
|
@@ -7,13 +7,13 @@
|
|||||||
|
|
||||||
void start_shop_mode(short which,short cost_adj,std::string store_name);
|
void start_shop_mode(short which,short cost_adj,std::string store_name);
|
||||||
void end_shop_mode();
|
void end_shop_mode();
|
||||||
void handle_shop_event(location p);
|
void handle_shop_event(location p, cFramerateLimiter& fps_limiter);
|
||||||
void handle_sale(cShopItem item, int i);
|
void handle_sale(cShopItem item, int i);
|
||||||
void handle_info_request(cShopItem item);
|
void handle_info_request(cShopItem item);
|
||||||
void set_up_shop_array();
|
void set_up_shop_array();
|
||||||
void start_talk_mode(short m_num,short personality,mon_num_t monst_type,short store_face_pic);
|
void start_talk_mode(short m_num,short personality,mon_num_t monst_type,short store_face_pic);
|
||||||
void end_talk_mode();
|
void end_talk_mode();
|
||||||
void handle_talk_event(location p);
|
void handle_talk_event(location p, cFramerateLimiter& fps_limiter);
|
||||||
void handle_talk_spec(short ttype,char* place_string1,char* place_string2);
|
void handle_talk_spec(short ttype,char* place_string1,char* place_string2);
|
||||||
void store_responses();
|
void store_responses();
|
||||||
void do_sign(short town_num, short which_sign, short sign_type);
|
void do_sign(short town_num, short which_sign, short sign_type);
|
||||||
|
@@ -414,9 +414,9 @@ void handle_events() {
|
|||||||
while(!fake_event_queue.empty()){
|
while(!fake_event_queue.empty()){
|
||||||
const sf::Event& next_event = fake_event_queue.front();
|
const sf::Event& next_event = fake_event_queue.front();
|
||||||
fake_event_queue.pop_front();
|
fake_event_queue.pop_front();
|
||||||
handle_one_event(next_event);
|
handle_one_event(next_event, fps_limiter);
|
||||||
}
|
}
|
||||||
while(mainPtr.pollEvent(currentEvent)) handle_one_event(currentEvent);
|
while(mainPtr.pollEvent(currentEvent)) handle_one_event(currentEvent, fps_limiter);
|
||||||
|
|
||||||
// It would be nice to have minimap inside the main game window (we have lots of screen space in fullscreen mode).
|
// It would be nice to have minimap inside the main game window (we have lots of screen space in fullscreen mode).
|
||||||
// Alternatively, minimap could live on its own thread.
|
// Alternatively, minimap could live on its own thread.
|
||||||
@@ -474,7 +474,7 @@ void handle_quit_event() {
|
|||||||
All_Done = true;
|
All_Done = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void handle_one_event(const sf::Event& event) {
|
void handle_one_event(const sf::Event& event, cFramerateLimiter& fps_limiter) {
|
||||||
|
|
||||||
// What does this do and should it be here?
|
// What does this do and should it be here?
|
||||||
through_sending();
|
through_sending();
|
||||||
@@ -493,12 +493,12 @@ void handle_one_event(const sf::Event& event) {
|
|||||||
switch(event.type) {
|
switch(event.type) {
|
||||||
case sf::Event::KeyPressed:
|
case sf::Event::KeyPressed:
|
||||||
if(flushingInput) return;
|
if(flushingInput) return;
|
||||||
if(!(event.key.*systemKey)) handle_keystroke(event);
|
if(!(event.key.*systemKey)) handle_keystroke(event, fps_limiter);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case sf::Event::MouseButtonPressed:
|
case sf::Event::MouseButtonPressed:
|
||||||
if(flushingInput) return;
|
if(flushingInput) return;
|
||||||
Mouse_Pressed(event);
|
Mouse_Pressed(event, fps_limiter);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case sf::Event::MouseLeft:
|
case sf::Event::MouseLeft:
|
||||||
@@ -581,7 +581,7 @@ void redraw_everything() {
|
|||||||
if(map_visible) draw_map(false);
|
if(map_visible) draw_map(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Mouse_Pressed(const sf::Event& event) {
|
void Mouse_Pressed(const sf::Event& event, cFramerateLimiter& fps_limiter) {
|
||||||
|
|
||||||
// What is this stuff? Why is it here?
|
// What is this stuff? Why is it here?
|
||||||
if(had_text_freeze > 0) {
|
if(had_text_freeze > 0) {
|
||||||
@@ -592,7 +592,7 @@ void Mouse_Pressed(const sf::Event& event) {
|
|||||||
if(overall_mode == MODE_STARTUP) {
|
if(overall_mode == MODE_STARTUP) {
|
||||||
All_Done = handle_startup_press({event.mouseButton.x, event.mouseButton.y});
|
All_Done = handle_startup_press({event.mouseButton.x, event.mouseButton.y});
|
||||||
} else {
|
} else {
|
||||||
All_Done = handle_action(event);
|
All_Done = handle_action(event, fps_limiter);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Why does every mouse click activate a menu?
|
// Why does every mouse click activate a menu?
|
||||||
@@ -772,11 +772,11 @@ void handle_menu_choice(eMenu item_hit) {
|
|||||||
case eMenu::ACTIONS_ALCHEMY:
|
case eMenu::ACTIONS_ALCHEMY:
|
||||||
dummyEvent.key.code = sf::Keyboard::A;
|
dummyEvent.key.code = sf::Keyboard::A;
|
||||||
dummyEvent.key.shift = true;
|
dummyEvent.key.shift = true;
|
||||||
handle_keystroke(dummyEvent);
|
queue_fake_event(dummyEvent);
|
||||||
break;
|
break;
|
||||||
case eMenu::ACTIONS_WAIT:
|
case eMenu::ACTIONS_WAIT:
|
||||||
dummyEvent.key.code = sf::Keyboard::W;
|
dummyEvent.key.code = sf::Keyboard::W;
|
||||||
handle_keystroke(dummyEvent);
|
queue_fake_event(dummyEvent);
|
||||||
break;
|
break;
|
||||||
case eMenu::ACTIONS_AUTOMAP:
|
case eMenu::ACTIONS_AUTOMAP:
|
||||||
if(!prime_time()) {
|
if(!prime_time()) {
|
||||||
|
@@ -1,6 +1,5 @@
|
|||||||
|
|
||||||
#include <SFML/Graphics.hpp>
|
#include <SFML/Graphics.hpp>
|
||||||
#include "tools/framerate_limiter.hpp"
|
|
||||||
|
|
||||||
#ifdef __APPLE__
|
#ifdef __APPLE__
|
||||||
extern eMenuChoice menuChoice;
|
extern eMenuChoice menuChoice;
|
||||||
@@ -9,8 +8,8 @@ extern short menuChoiceId;
|
|||||||
int main(int argc, char* argv[]);
|
int main(int argc, char* argv[]);
|
||||||
void update_everything();
|
void update_everything();
|
||||||
void redraw_everything();
|
void redraw_everything();
|
||||||
void Mouse_Pressed(const sf::Event&);
|
|
||||||
eKeyMod current_key_mod();
|
eKeyMod current_key_mod();
|
||||||
|
void Mouse_Pressed(const sf::Event&, cFramerateLimiter& fps_limiter);
|
||||||
void close_program();
|
void close_program();
|
||||||
void change_cursor(location where_curs);
|
void change_cursor(location where_curs);
|
||||||
void set_up_apple_events();
|
void set_up_apple_events();
|
||||||
@@ -19,12 +18,12 @@ void incidental_noises(bool on_surface);
|
|||||||
void pause(short length);
|
void pause(short length);
|
||||||
bool handle_startup_press(location the_point);
|
bool handle_startup_press(location the_point);
|
||||||
void handle_splash_events();
|
void handle_splash_events();
|
||||||
void show_logo(cFramerateLimiter& framerate_limiter);
|
void show_logo(cFramerateLimiter& fps_limiter);
|
||||||
void plop_fancy_startup(cFramerateLimiter& framerate_limiter);
|
void plop_fancy_startup(cFramerateLimiter& fps_limiter);
|
||||||
void update_terrain_animation();
|
void update_terrain_animation();
|
||||||
void update_startup_animation();
|
void update_startup_animation();
|
||||||
void handle_events();
|
void handle_events();
|
||||||
void handle_one_event(const sf::Event&);
|
void handle_one_event(const sf::Event&, cFramerateLimiter& fps_limiter);
|
||||||
void queue_fake_event(const sf::Event&);
|
void queue_fake_event(const sf::Event&);
|
||||||
void handle_one_minimap_event(const sf::Event &);
|
void handle_one_minimap_event(const sf::Event &);
|
||||||
|
|
||||||
|
@@ -6,6 +6,8 @@
|
|||||||
//
|
//
|
||||||
//
|
//
|
||||||
|
|
||||||
|
#include "tools/framerate_limiter.hpp"
|
||||||
|
|
||||||
#ifndef BoE_boe_menus_h
|
#ifndef BoE_boe_menus_h
|
||||||
#define BoE_boe_menus_h
|
#define BoE_boe_menus_h
|
||||||
|
|
||||||
|
@@ -128,13 +128,13 @@ bool handle_startup_press(location the_point) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void handle_splash_events(cFramerateLimiter& framerate_limiter) {
|
void handle_splash_events(cFramerateLimiter& fps_limiter) {
|
||||||
sf::Event event;
|
sf::Event event;
|
||||||
while(mainPtr.pollEvent(event)) {
|
while(mainPtr.pollEvent(event)) {
|
||||||
if(event.type == sf::Event::GainedFocus || event.type == sf::Event::MouseMoved)
|
if(event.type == sf::Event::GainedFocus || event.type == sf::Event::MouseMoved)
|
||||||
set_cursor(sword_curs);
|
set_cursor(sword_curs);
|
||||||
}
|
}
|
||||||
framerate_limiter.frame_finished();
|
fps_limiter.frame_finished();
|
||||||
}
|
}
|
||||||
|
|
||||||
static rectangle view_rect() {
|
static rectangle view_rect() {
|
||||||
@@ -142,7 +142,7 @@ static rectangle view_rect() {
|
|||||||
return rectangle(0, 0, size.y, size.x);
|
return rectangle(0, 0, size.y, size.x);
|
||||||
}
|
}
|
||||||
|
|
||||||
void show_logo(cFramerateLimiter& framerate_limiter) {
|
void show_logo(cFramerateLimiter& fps_limiter) {
|
||||||
rectangle whole_window = view_rect();
|
rectangle whole_window = view_rect();
|
||||||
|
|
||||||
if(get_int_pref("DisplayMode") != 5)
|
if(get_int_pref("DisplayMode") != 5)
|
||||||
@@ -157,17 +157,17 @@ void show_logo(cFramerateLimiter& framerate_limiter) {
|
|||||||
play_sound(-95);
|
play_sound(-95);
|
||||||
while(sound_going(95)) {
|
while(sound_going(95)) {
|
||||||
draw_splash(pict_to_draw, mainPtr, logo_from);
|
draw_splash(pict_to_draw, mainPtr, logo_from);
|
||||||
handle_splash_events(framerate_limiter);
|
handle_splash_events(fps_limiter);
|
||||||
}
|
}
|
||||||
if(!get_int_pref("ShowStartupSplash", true)) {
|
if(!get_int_pref("ShowStartupSplash", true)) {
|
||||||
sf::Time delay = time_in_ticks(60);
|
sf::Time delay = time_in_ticks(60);
|
||||||
sf::Clock timer;
|
sf::Clock timer;
|
||||||
while(timer.getElapsedTime() < delay)
|
while(timer.getElapsedTime() < delay)
|
||||||
handle_splash_events(framerate_limiter);
|
handle_splash_events(fps_limiter);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void plop_fancy_startup(cFramerateLimiter& framerate_limiter) {
|
void plop_fancy_startup(cFramerateLimiter& fps_limiter) {
|
||||||
rectangle whole_window = view_rect();
|
rectangle whole_window = view_rect();
|
||||||
|
|
||||||
float ui_scale = get_float_pref("UIScale", 1.0);
|
float ui_scale = get_float_pref("UIScale", 1.0);
|
||||||
@@ -183,7 +183,7 @@ void plop_fancy_startup(cFramerateLimiter& framerate_limiter) {
|
|||||||
|
|
||||||
while(timer.getElapsedTime() < delay) {
|
while(timer.getElapsedTime() < delay) {
|
||||||
draw_splash(pict_to_draw, mainPtr, intro_from);
|
draw_splash(pict_to_draw, mainPtr, intro_from);
|
||||||
handle_splash_events(framerate_limiter);
|
handle_splash_events(fps_limiter);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user