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"]));
|
||||
controls[info["id"]]->triggerClickHandler(*this, info["id"], mods);
|
||||
}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.
|
||||
@@ -556,7 +556,7 @@ void cDialog::handle_events() {
|
||||
}
|
||||
|
||||
// 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;
|
||||
|
||||
cKey key;
|
||||
@@ -671,7 +671,7 @@ void cDialog::handle_one_event(const sf::Event& currentEvent) {
|
||||
case sf::Event::MouseButtonPressed:
|
||||
key.mod = current_key_mod();
|
||||
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;
|
||||
default: // To silence warning of unhandled enum values
|
||||
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.
|
||||
// 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();
|
||||
while(iter != controls.end()){
|
||||
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;
|
||||
else return;
|
||||
}
|
||||
|
@@ -29,6 +29,7 @@
|
||||
#include <boost/any.hpp>
|
||||
#include <boost/iterator/iterator_facade.hpp>
|
||||
#include "tools/prefs.hpp"
|
||||
#include "tools/framerate_limiter.hpp"
|
||||
|
||||
class cControl;
|
||||
class cTextField;
|
||||
@@ -261,9 +262,9 @@ private:
|
||||
inline double ui_scale() { return get_float_pref("UIScale", 1.0); };
|
||||
void draw();
|
||||
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_click(location where, eKeyMod mods);
|
||||
void process_click(location where, eKeyMod mods, cFramerateLimiter& fps_limiter);
|
||||
bool dialogNotToast, didAccept;
|
||||
rectangle winRect;
|
||||
boost::any result;
|
||||
|
@@ -51,12 +51,12 @@ bool cContainer::parseChildControl(ticpp::Element& elem, std::map<std::string,cC
|
||||
return true;
|
||||
}
|
||||
|
||||
bool cContainer::handleClick(location where) {
|
||||
bool cContainer::handleClick(location where, cFramerateLimiter& fps_limiter) {
|
||||
std::string which_clicked;
|
||||
bool success = false;
|
||||
forEach([&](std::string id, cControl& ctrl) {
|
||||
if(!success && ctrl.isClickable() && ctrl.getBounds().contains(where)) {
|
||||
if(ctrl.handleClick(where)){
|
||||
if(ctrl.handleClick(where, fps_limiter)){
|
||||
success = true;
|
||||
which_clicked = id;
|
||||
}
|
||||
|
@@ -48,7 +48,7 @@ public:
|
||||
cControl& operator[](std::string id) {return getChild(id);}
|
||||
const cControl& operator[](std::string id) const {return const_cast<cContainer&>(*this).getChild(id);}
|
||||
bool isContainer() const override {return true;}
|
||||
bool handleClick(location where) override;
|
||||
bool handleClick(location where, cFramerateLimiter& fps_limiter) override;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@@ -221,26 +221,28 @@ void cControl::playClickSound(){
|
||||
else sf::sleep(time_in_ticks(14));
|
||||
}
|
||||
|
||||
bool cControl::handleClick(location){
|
||||
bool cControl::handleClick(location, cFramerateLimiter& fps_limiter){
|
||||
sf::Event e;
|
||||
bool done = false, clicked = false;
|
||||
inWindow->setActive();
|
||||
depressed = true;
|
||||
while(!done){
|
||||
redraw();
|
||||
if(!inWindow->pollEvent(e)) continue;
|
||||
if(e.type == sf::Event::MouseButtonReleased){
|
||||
done = true;
|
||||
location clickPos(e.mouseButton.x, e.mouseButton.y);
|
||||
clickPos = inWindow->mapPixelToCoords(clickPos);
|
||||
clicked = frame.contains(clickPos);
|
||||
depressed = false;
|
||||
} else if(e.type == sf::Event::MouseMoved){
|
||||
restore_cursor();
|
||||
location toPos(e.mouseMove.x, e.mouseMove.y);
|
||||
toPos = inWindow->mapPixelToCoords(toPos);
|
||||
depressed = frame.contains(toPos);
|
||||
while(inWindow->pollEvent(e)){
|
||||
if(e.type == sf::Event::MouseButtonReleased){
|
||||
done = true;
|
||||
location clickPos(e.mouseButton.x, e.mouseButton.y);
|
||||
clickPos = inWindow->mapPixelToCoords(clickPos);
|
||||
clicked = frame.contains(clickPos);
|
||||
depressed = false;
|
||||
} else if(e.type == sf::Event::MouseMoved){
|
||||
restore_cursor();
|
||||
location toPos(e.mouseMove.x, e.mouseMove.y);
|
||||
toPos = inWindow->mapPixelToCoords(toPos);
|
||||
depressed = frame.contains(toPos);
|
||||
}
|
||||
}
|
||||
fps_limiter.frame_finished();
|
||||
}
|
||||
playClickSound();
|
||||
|
||||
|
@@ -21,6 +21,7 @@
|
||||
#include <map>
|
||||
#include <boost/any.hpp>
|
||||
#include "dialogxml/dialogs/dlogevt.hpp"
|
||||
#include "tools/framerate_limiter.hpp"
|
||||
|
||||
#include "location.hpp"
|
||||
|
||||
@@ -329,7 +330,7 @@ public:
|
||||
/// 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
|
||||
/// 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.
|
||||
/// 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.
|
||||
|
@@ -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;
|
||||
haveFocus = true;
|
||||
redraw(); // This ensures the snippets array is populated.
|
||||
@@ -141,26 +141,28 @@ bool cTextField::handleClick(location clickLoc) {
|
||||
int initial_ip = insertionPoint, initial_sp = selectionPoint;
|
||||
while(!done) {
|
||||
redraw();
|
||||
if(!inWindow->pollEvent(e)) continue;
|
||||
if(e.type == sf::Event::MouseButtonReleased){
|
||||
done = true;
|
||||
} else if(e.type == sf::Event::MouseMoved){
|
||||
restore_cursor();
|
||||
location newLoc(e.mouseMove.x, e.mouseMove.y);
|
||||
newLoc = inWindow->mapPixelToCoords(newLoc);
|
||||
set_ip(newLoc, &cTextField::selectionPoint);
|
||||
if(is_double) {
|
||||
if(selectionPoint > initial_ip) {
|
||||
insertionPoint = initial_sp;
|
||||
while(selectionPoint < contents.length() && contents[selectionPoint] != ' ')
|
||||
selectionPoint++;
|
||||
} else {
|
||||
insertionPoint = initial_ip;
|
||||
while(selectionPoint > 0 && contents[selectionPoint - 1] != ' ')
|
||||
selectionPoint--;
|
||||
while(inWindow->pollEvent(e)){
|
||||
if(e.type == sf::Event::MouseButtonReleased){
|
||||
done = true;
|
||||
} else if(e.type == sf::Event::MouseMoved){
|
||||
restore_cursor();
|
||||
location newLoc(e.mouseMove.x, e.mouseMove.y);
|
||||
newLoc = inWindow->mapPixelToCoords(newLoc);
|
||||
set_ip(newLoc, &cTextField::selectionPoint);
|
||||
if(is_double) {
|
||||
if(selectionPoint > initial_ip) {
|
||||
insertionPoint = initial_sp;
|
||||
while(selectionPoint < contents.length() && contents[selectionPoint] != ' ')
|
||||
selectionPoint++;
|
||||
} else {
|
||||
insertionPoint = initial_ip;
|
||||
while(selectionPoint > 0 && contents[selectionPoint - 1] != ' ')
|
||||
selectionPoint--;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
fps_limiter.frame_finished();
|
||||
}
|
||||
redraw();
|
||||
return true;
|
||||
|
@@ -42,7 +42,7 @@ public:
|
||||
std::set<eDlogEvt> getSupportedHandlers() const override {
|
||||
return {EVT_FOCUS, EVT_DEFOCUS};
|
||||
}
|
||||
bool handleClick(location where) override;
|
||||
bool handleClick(location where, cFramerateLimiter& fps_limiter) override;
|
||||
void setText(std::string to) override;
|
||||
storage_t store() const override;
|
||||
void restore(storage_t to) override;
|
||||
|
@@ -51,12 +51,12 @@ void cLedGroup::addChoice(cLed* ctrl, std::string key) {
|
||||
setSelected(key);
|
||||
}
|
||||
|
||||
bool cLedGroup::handleClick(location where) {
|
||||
bool cLedGroup::handleClick(location where, cFramerateLimiter& fps_limiter) {
|
||||
std::string which_clicked;
|
||||
ledIter iter = choices.begin();
|
||||
while(iter != choices.end()){
|
||||
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;
|
||||
break;
|
||||
}
|
||||
|
@@ -83,7 +83,7 @@ public:
|
||||
bool isClickable() const override;
|
||||
bool isFocusable() const override;
|
||||
bool isScrollable() const override;
|
||||
bool handleClick(location where) override;
|
||||
bool handleClick(location where, cFramerateLimiter& fps_limiter) override;
|
||||
virtual ~cLedGroup();
|
||||
/// Get one of the LEDs in this group.
|
||||
/// @param id The unique key of the choice.
|
||||
|
@@ -275,7 +275,7 @@ bool cScrollbar::handle_mouse_released(const sf::Event&) {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool cScrollbar::handleClick(location where) {
|
||||
bool cScrollbar::handleClick(location where, cFramerateLimiter& fps_limiter) {
|
||||
if(max == 0) return false;
|
||||
sf::Event e;
|
||||
bool done = false, clicked = false;
|
||||
@@ -299,56 +299,58 @@ bool cScrollbar::handleClick(location where) {
|
||||
int diff = clickPos - thumbPos;
|
||||
while(!done){
|
||||
redraw();
|
||||
if(!inWindow->pollEvent(e)) continue;
|
||||
location mouseLoc = sf::Mouse::getPosition(*inWindow);
|
||||
mouseLoc = inWindow->mapPixelToCoords(mouseLoc);
|
||||
int mousePos = vert ? mouseLoc.y : mouseLoc.x;
|
||||
if(e.type == sf::Event::MouseButtonReleased){
|
||||
done = true;
|
||||
location clickLoc(e.mouseButton.x, e.mouseButton.y);
|
||||
clickLoc = inWindow->mapPixelToCoords(clickLoc);
|
||||
clicked = frame.contains(clickLoc);
|
||||
depressed = false;
|
||||
switch(pressedPart) {
|
||||
case PART_UP: pos--; break;
|
||||
case PART_PGUP: pos -= pgsz; break;
|
||||
case PART_PGDN: pos += pgsz; break;
|
||||
case PART_DOWN: pos++; break;
|
||||
case PART_THUMB: break;
|
||||
while(inWindow->pollEvent(e)){
|
||||
location mouseLoc = sf::Mouse::getPosition(*inWindow);
|
||||
mouseLoc = inWindow->mapPixelToCoords(mouseLoc);
|
||||
int mousePos = vert ? mouseLoc.y : mouseLoc.x;
|
||||
if(e.type == sf::Event::MouseButtonReleased){
|
||||
done = true;
|
||||
location clickLoc(e.mouseButton.x, e.mouseButton.y);
|
||||
clickLoc = inWindow->mapPixelToCoords(clickLoc);
|
||||
clicked = frame.contains(clickLoc);
|
||||
depressed = false;
|
||||
switch(pressedPart) {
|
||||
case PART_UP: pos--; break;
|
||||
case PART_PGUP: pos -= pgsz; break;
|
||||
case PART_PGDN: pos += pgsz; break;
|
||||
case PART_DOWN: pos++; break;
|
||||
case PART_THUMB: break;
|
||||
}
|
||||
} else if(e.type == sf::Event::MouseMoved){
|
||||
restore_cursor();
|
||||
switch(pressedPart) {
|
||||
case PART_UP:
|
||||
depressed = mousePos < bar_start + btn_size;
|
||||
break;
|
||||
case PART_PGUP:
|
||||
depressed = mousePos >= bar_start + btn_size && mousePos < thumbPos;
|
||||
break;
|
||||
case PART_THUMB:
|
||||
depressed = true;
|
||||
// We want the pos that will make thumbPos = mousePos - diff
|
||||
// In draw(), thumbPos is calculated as bar_start + bar_thickness + pos * (bar_size - bar_thickness) / max
|
||||
// So solving for pos gives (mousePos - diff - bar_start - bar_thickness) * max / (bar_size - bar_thickness)
|
||||
pos = (mousePos - diff - bar_start - btn_size) * max / (bar_size - btn_size);
|
||||
break;
|
||||
case PART_PGDN:
|
||||
depressed = mousePos >= thumbPos + btn_size && mousePos < bar_end - btn_size;
|
||||
break;
|
||||
case PART_DOWN:
|
||||
depressed = mousePos >= bar_end - btn_size;
|
||||
break;
|
||||
}
|
||||
location toLoc(e.mouseMove.x, e.mouseMove.y);
|
||||
toLoc = inWindow->mapPixelToCoords(toLoc);
|
||||
if(pressedPart != PART_THUMB && !frame.contains(toLoc)) depressed = false;
|
||||
}
|
||||
} else if(e.type == sf::Event::MouseMoved){
|
||||
restore_cursor();
|
||||
switch(pressedPart) {
|
||||
case PART_UP:
|
||||
depressed = mousePos < bar_start + btn_size;
|
||||
break;
|
||||
case PART_PGUP:
|
||||
depressed = mousePos >= bar_start + btn_size && mousePos < thumbPos;
|
||||
break;
|
||||
case PART_THUMB:
|
||||
depressed = true;
|
||||
// We want the pos that will make thumbPos = mousePos - diff
|
||||
// In draw(), thumbPos is calculated as bar_start + bar_thickness + pos * (bar_size - bar_thickness) / max
|
||||
// So solving for pos gives (mousePos - diff - bar_start - bar_thickness) * max / (bar_size - bar_thickness)
|
||||
pos = (mousePos - diff - bar_start - btn_size) * max / (bar_size - btn_size);
|
||||
break;
|
||||
case PART_PGDN:
|
||||
depressed = mousePos >= thumbPos + btn_size && mousePos < bar_end - btn_size;
|
||||
break;
|
||||
case PART_DOWN:
|
||||
depressed = mousePos >= bar_end - btn_size;
|
||||
break;
|
||||
}
|
||||
location toLoc(e.mouseMove.x, e.mouseMove.y);
|
||||
toLoc = inWindow->mapPixelToCoords(toLoc);
|
||||
if(pressedPart != PART_THUMB && !frame.contains(toLoc)) depressed = false;
|
||||
pos = minmax(0,max,pos);
|
||||
if(parent && !link.empty())
|
||||
parent->getControl(link).setTextToNum(pos);
|
||||
thumbPos = bar_start;
|
||||
thumbPos += btn_size + pos * (bar_size - btn_size) / max;
|
||||
thumbPos = minmax(mousePos,bar_end - btn_size * 2,thumbPos);
|
||||
}
|
||||
pos = minmax(0,max,pos);
|
||||
if(parent && !link.empty())
|
||||
parent->getControl(link).setTextToNum(pos);
|
||||
thumbPos = bar_start;
|
||||
thumbPos += btn_size + pos * (bar_size - btn_size) / max;
|
||||
thumbPos = minmax(mousePos,bar_end - btn_size * 2,thumbPos);
|
||||
fps_limiter.frame_finished();
|
||||
}
|
||||
redraw();
|
||||
return clicked;
|
||||
|
@@ -73,7 +73,7 @@ public:
|
||||
/// Create a new scrollbar.
|
||||
/// @param parent The parent dialog.
|
||||
explicit cScrollbar(cDialog& parent);
|
||||
bool handleClick(location where) override;
|
||||
bool handleClick(location where, cFramerateLimiter& fps_limiter) override;
|
||||
storage_t store() const override;
|
||||
void restore(storage_t to) override;
|
||||
bool isClickable() const override;
|
||||
|
@@ -20,11 +20,11 @@ cScrollPane::cScrollPane(cDialog& parent) : cContainer(CTRL_PANE, parent), scrol
|
||||
recalcRect();
|
||||
}
|
||||
|
||||
bool cScrollPane::handleClick(location where) {
|
||||
bool cScrollPane::handleClick(location where, cFramerateLimiter& fps_limiter) {
|
||||
if(scroll.getBounds().contains(where))
|
||||
return scroll.handleClick(where);
|
||||
return scroll.handleClick(where, fps_limiter);
|
||||
where.y += scroll.getPosition();
|
||||
return cContainer::handleClick(where);
|
||||
return cContainer::handleClick(where, fps_limiter);
|
||||
}
|
||||
|
||||
void cScrollPane::recalcRect() {
|
||||
|
@@ -28,7 +28,7 @@ public:
|
||||
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;
|
||||
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;
|
||||
cControl& getChild(std::string id) 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;
|
||||
bool are_done = 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.
|
||||
if(overall_mode == MODE_TALKING) {
|
||||
handle_talk_event(the_point);
|
||||
handle_talk_event(the_point, fps_limiter);
|
||||
if(overall_mode != MODE_TALKING)
|
||||
return false;
|
||||
}
|
||||
if(overall_mode == MODE_SHOPPING) {
|
||||
handle_shop_event(the_point);
|
||||
handle_shop_event(the_point, fps_limiter);
|
||||
if(overall_mode != MODE_SHOPPING)
|
||||
return false;
|
||||
}
|
||||
@@ -1630,7 +1630,7 @@ void initiate_outdoor_combat(short i) {
|
||||
draw_terrain();
|
||||
}
|
||||
|
||||
bool handle_keystroke(const sf::Event& event){
|
||||
bool handle_keystroke(const sf::Event& event, cFramerateLimiter& fps_limiter){
|
||||
bool are_done = false;
|
||||
location pass_point; // TODO: This isn't needed
|
||||
std::ostringstream sout;
|
||||
@@ -1708,7 +1708,7 @@ bool handle_keystroke(const sf::Event& event){
|
||||
pass_point = mainPtr.mapCoordsToPixel(pass_point, mainView);
|
||||
pass_event.mouseButton.x = pass_point.x;
|
||||
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
|
||||
@@ -1725,7 +1725,7 @@ bool handle_keystroke(const sf::Event& event){
|
||||
pass_point = mainPtr.mapCoordsToPixel(pass_point, mainView);
|
||||
pass_event.mouseButton.x = pass_point.x;
|
||||
pass_event.mouseButton.y = pass_point.y;
|
||||
are_done = handle_action(pass_event);
|
||||
are_done = handle_action(pass_event, fps_limiter);
|
||||
}
|
||||
} else {
|
||||
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_event.mouseButton.x = pass_point.x;
|
||||
pass_event.mouseButton.y = pass_point.y;
|
||||
are_done = handle_action(pass_event);
|
||||
are_done = handle_action(pass_event, fps_limiter);
|
||||
return are_done;
|
||||
}
|
||||
}
|
||||
|
@@ -5,17 +5,18 @@
|
||||
#include <SFML/Window/Event.hpp>
|
||||
#include "location.hpp"
|
||||
#include "dialogxml/keycodes.hpp"
|
||||
#include "tools/framerate_limiter.hpp"
|
||||
|
||||
void init_screen_locs();
|
||||
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 handle_move(location destination, bool& did_something, bool& need_redraw, bool& need_reprint);
|
||||
void handle_monster_actions(bool& need_redraw, bool& need_reprint);
|
||||
bool someone_awake();
|
||||
void handle_menu_spell(short spell_picked,short spell_type) ;
|
||||
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);
|
||||
void do_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(!help_btn->handleClick(p))
|
||||
if(!help_btn->handleClick(p, fps_limiter))
|
||||
return;
|
||||
give_help(226,27);
|
||||
return;
|
||||
}
|
||||
|
||||
if(p.in(shop_done_rect)) {
|
||||
if(done_btn->handleClick(p))
|
||||
if(done_btn->handleClick(p, fps_limiter))
|
||||
end_shop_mode();
|
||||
return;
|
||||
}
|
||||
@@ -706,7 +706,7 @@ static void show_job_bank(int which_bank, std::string title) {
|
||||
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;
|
||||
char asked[4];
|
||||
|
||||
@@ -714,7 +714,7 @@ void handle_talk_event(location p) {
|
||||
eTalkNode ttype;
|
||||
|
||||
if(p.in(talk_help_rect)) {
|
||||
if(!help_btn->handleClick(p))
|
||||
if(!help_btn->handleClick(p, fps_limiter))
|
||||
return;
|
||||
give_help(205,6);
|
||||
return;
|
||||
|
@@ -7,13 +7,13 @@
|
||||
|
||||
void start_shop_mode(short which,short cost_adj,std::string store_name);
|
||||
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_info_request(cShopItem item);
|
||||
void set_up_shop_array();
|
||||
void start_talk_mode(short m_num,short personality,mon_num_t monst_type,short store_face_pic);
|
||||
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 store_responses();
|
||||
void do_sign(short town_num, short which_sign, short sign_type);
|
||||
|
@@ -414,9 +414,9 @@ void handle_events() {
|
||||
while(!fake_event_queue.empty()){
|
||||
const sf::Event& next_event = fake_event_queue.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).
|
||||
// Alternatively, minimap could live on its own thread.
|
||||
@@ -474,7 +474,7 @@ void handle_quit_event() {
|
||||
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?
|
||||
through_sending();
|
||||
@@ -493,12 +493,12 @@ void handle_one_event(const sf::Event& event) {
|
||||
switch(event.type) {
|
||||
case sf::Event::KeyPressed:
|
||||
if(flushingInput) return;
|
||||
if(!(event.key.*systemKey)) handle_keystroke(event);
|
||||
if(!(event.key.*systemKey)) handle_keystroke(event, fps_limiter);
|
||||
break;
|
||||
|
||||
case sf::Event::MouseButtonPressed:
|
||||
if(flushingInput) return;
|
||||
Mouse_Pressed(event);
|
||||
Mouse_Pressed(event, fps_limiter);
|
||||
break;
|
||||
|
||||
case sf::Event::MouseLeft:
|
||||
@@ -581,7 +581,7 @@ void redraw_everything() {
|
||||
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?
|
||||
if(had_text_freeze > 0) {
|
||||
@@ -592,7 +592,7 @@ void Mouse_Pressed(const sf::Event& event) {
|
||||
if(overall_mode == MODE_STARTUP) {
|
||||
All_Done = handle_startup_press({event.mouseButton.x, event.mouseButton.y});
|
||||
} else {
|
||||
All_Done = handle_action(event);
|
||||
All_Done = handle_action(event, fps_limiter);
|
||||
}
|
||||
|
||||
// Why does every mouse click activate a menu?
|
||||
@@ -772,11 +772,11 @@ void handle_menu_choice(eMenu item_hit) {
|
||||
case eMenu::ACTIONS_ALCHEMY:
|
||||
dummyEvent.key.code = sf::Keyboard::A;
|
||||
dummyEvent.key.shift = true;
|
||||
handle_keystroke(dummyEvent);
|
||||
queue_fake_event(dummyEvent);
|
||||
break;
|
||||
case eMenu::ACTIONS_WAIT:
|
||||
dummyEvent.key.code = sf::Keyboard::W;
|
||||
handle_keystroke(dummyEvent);
|
||||
queue_fake_event(dummyEvent);
|
||||
break;
|
||||
case eMenu::ACTIONS_AUTOMAP:
|
||||
if(!prime_time()) {
|
||||
|
@@ -1,6 +1,5 @@
|
||||
|
||||
#include <SFML/Graphics.hpp>
|
||||
#include "tools/framerate_limiter.hpp"
|
||||
|
||||
#ifdef __APPLE__
|
||||
extern eMenuChoice menuChoice;
|
||||
@@ -9,8 +8,8 @@ extern short menuChoiceId;
|
||||
int main(int argc, char* argv[]);
|
||||
void update_everything();
|
||||
void redraw_everything();
|
||||
void Mouse_Pressed(const sf::Event&);
|
||||
eKeyMod current_key_mod();
|
||||
void Mouse_Pressed(const sf::Event&, cFramerateLimiter& fps_limiter);
|
||||
void close_program();
|
||||
void change_cursor(location where_curs);
|
||||
void set_up_apple_events();
|
||||
@@ -19,12 +18,12 @@ void incidental_noises(bool on_surface);
|
||||
void pause(short length);
|
||||
bool handle_startup_press(location the_point);
|
||||
void handle_splash_events();
|
||||
void show_logo(cFramerateLimiter& framerate_limiter);
|
||||
void plop_fancy_startup(cFramerateLimiter& framerate_limiter);
|
||||
void show_logo(cFramerateLimiter& fps_limiter);
|
||||
void plop_fancy_startup(cFramerateLimiter& fps_limiter);
|
||||
void update_terrain_animation();
|
||||
void update_startup_animation();
|
||||
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 handle_one_minimap_event(const sf::Event &);
|
||||
|
||||
|
@@ -6,6 +6,8 @@
|
||||
//
|
||||
//
|
||||
|
||||
#include "tools/framerate_limiter.hpp"
|
||||
|
||||
#ifndef BoE_boe_menus_h
|
||||
#define BoE_boe_menus_h
|
||||
|
||||
|
@@ -128,13 +128,13 @@ bool handle_startup_press(location the_point) {
|
||||
return false;
|
||||
}
|
||||
|
||||
void handle_splash_events(cFramerateLimiter& framerate_limiter) {
|
||||
void handle_splash_events(cFramerateLimiter& fps_limiter) {
|
||||
sf::Event event;
|
||||
while(mainPtr.pollEvent(event)) {
|
||||
if(event.type == sf::Event::GainedFocus || event.type == sf::Event::MouseMoved)
|
||||
set_cursor(sword_curs);
|
||||
}
|
||||
framerate_limiter.frame_finished();
|
||||
fps_limiter.frame_finished();
|
||||
}
|
||||
|
||||
static rectangle view_rect() {
|
||||
@@ -142,7 +142,7 @@ static rectangle view_rect() {
|
||||
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();
|
||||
|
||||
if(get_int_pref("DisplayMode") != 5)
|
||||
@@ -157,17 +157,17 @@ void show_logo(cFramerateLimiter& framerate_limiter) {
|
||||
play_sound(-95);
|
||||
while(sound_going(95)) {
|
||||
draw_splash(pict_to_draw, mainPtr, logo_from);
|
||||
handle_splash_events(framerate_limiter);
|
||||
handle_splash_events(fps_limiter);
|
||||
}
|
||||
if(!get_int_pref("ShowStartupSplash", true)) {
|
||||
sf::Time delay = time_in_ticks(60);
|
||||
sf::Clock timer;
|
||||
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();
|
||||
|
||||
float ui_scale = get_float_pref("UIScale", 1.0);
|
||||
@@ -183,7 +183,7 @@ void plop_fancy_startup(cFramerateLimiter& framerate_limiter) {
|
||||
|
||||
while(timer.getElapsedTime() < delay) {
|
||||
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