From b6ffae78a5790340375a2e89275d77e96448c2d5 Mon Sep 17 00:00:00 2001 From: Dave White Date: Wed, 15 Oct 2003 11:01:19 +0000 Subject: [PATCH] improved mouse wheel behavior --- src/playturn.cpp | 6 ++-- src/server/Makefile | 2 +- src/server/game.cpp | 64 ++++++++++++++++++++++++++++++++++++++++ src/server/game.hpp | 45 ++++++++++++++++++++++++++++ src/server/server.cpp | 68 ++----------------------------------------- 5 files changed, 115 insertions(+), 70 deletions(-) create mode 100644 src/server/game.cpp create mode 100644 src/server/game.hpp diff --git a/src/playturn.cpp b/src/playturn.cpp index 68d2dd268d5..f1c85ef465c 100644 --- a/src/playturn.cpp +++ b/src/playturn.cpp @@ -500,7 +500,7 @@ void play_turn(game_data& gameinfo, game_state& state_of_game, // MOUSE WHEEL BOUNDARY CHECK - if(gui::scrollamount() && (mousex > 50 && mousex < gui.x()-50) && + if(gui::scrollamount() && (mousex > 50 && mousex < gui.mapx()-50) && (mousey > 50 && mousey < gui.y()-50)) { // Reset scrolling ... it is just a clean-up so wheel turns //don't cache @@ -508,7 +508,7 @@ void play_turn(game_data& gameinfo, game_state& state_of_game, } else { if(gui::scrollamount()) { // Now scroll accordingly as we are in hot-spots - if((mousex >= gui.x()-50 && mousey <= 50) || + if((mousex >= gui.mapx()-50 && mousey <= 50) || (mousex <= 50 && mousey >= gui.y()-50)) { // firstly filtering the 2 conflicting corners if(gui::scrollamount() > 0) { @@ -520,7 +520,7 @@ void play_turn(game_data& gameinfo, game_state& state_of_game, } } else { // Now general case... - if(mousex <= 50 || mousex >= gui.x()-50) { + if(mousex <= 50 || mousex >= gui.mapx()-50) { // SCROLL HORIZONTALLY... we are in E or W sides gui::scrollamount() < 0 ? gui.scroll(-preferences::scroll_speed(),0.0) diff --git a/src/server/Makefile b/src/server/Makefile index dcca1c9ec79..5484bf0f440 100644 --- a/src/server/Makefile +++ b/src/server/Makefile @@ -1,6 +1,6 @@ SDL_CFLAGS = `sdl-config --cflags` `freetype-config --cflags` SDL_LIBS = `sdl-config --libs` -lSDL_ttf -lSDL_mixer -lSDL_image -lSDL_net `freetype-config --libs` -OBJS= server.o ../config.o ../filesystem.o ../game_config.o ../log.o ../network.o +OBJS= game.o server.o ../config.o ../filesystem.o ../game_config.o ../log.o ../network.o server: $(OBJS) gcc -lstdc++ ${SDL_CFLAGS} -o $@ ${OBJS} ${SDL_LIBS} diff --git a/src/server/game.cpp b/src/server/game.cpp new file mode 100644 index 00000000000..e231651ab73 --- /dev/null +++ b/src/server/game.cpp @@ -0,0 +1,64 @@ +#include "game.hpp" + +int game::id_num = 1; + +game::game() : id_(id_num++) +{} + +bool game::is_member(network::connection player) const +{ + return std::find(players_.begin(),players_.end(),player) != players_.end(); +} + +void game::add_player(network::connection player) +{ + players_.push_back(player); +} + +void game::remove_player(network::connection player) +{ + const std::vector::iterator itor = + std::find(players_.begin(),players_.end(),player); + if(itor != players_.end()) + players_.erase(itor); +} + +int game::id() const +{ + return id_; +} + +void game::send_data(const config& data, network::connection exclude) +{ + for(std::vector::const_iterator + i = players_.begin(); i != players_.end(); ++i) { + if(*i != exclude) { + network::send_data(data,*i); + } + } +} + +bool game::level_init() const +{ + return level_.child("side") != NULL; +} + +config& game::level() +{ + return level_; +} + +bool game::empty() const +{ + return players_.empty(); +} + +void game::disconnect() +{ + for(std::vector::iterator i = players_.begin(); + i != players_.end(); ++i) { + network::disconnect(*i); + } + + players_.clear(); +} diff --git a/src/server/game.hpp b/src/server/game.hpp new file mode 100644 index 00000000000..eca91f0fbea --- /dev/null +++ b/src/server/game.hpp @@ -0,0 +1,45 @@ +#ifndef GAME_HPP_INCLUDED +#define GAME_HPP_INCLUDED + +#include "../config.hpp" +#include "../network.hpp" + +#include +#include + +class game +{ +public: + game(); + + bool is_member(network::connection player) const; + + void add_player(network::connection player); + void remove_player(network::connection player); + + int id() const; + + void send_data(const config& data, network::connection exclude=0); + + bool level_init() const; + config& level(); + bool empty() const; + void disconnect(); + +private: + static int id_num; + int id_; + std::vector players_; + config level_; +}; + +struct game_id_matches +{ + game_id_matches(int id) : id_(id) {} + bool operator()(const game& g) const { return g.id() == id_; } + +private: + int id_; +}; + +#endif diff --git a/src/server/server.cpp b/src/server/server.cpp index 9aa88e45149..1e21cae2b67 100644 --- a/src/server/server.cpp +++ b/src/server/server.cpp @@ -3,78 +3,14 @@ #include "SDL.h" +#include "game.hpp" + #include #include #include #include #include -class game -{ -public: - game() : id_(id_num++) - {} - - bool is_member(network::connection player) const { - return std::find(players_.begin(),players_.end(),player) - != players_.end(); - } - - void add_player(network::connection player) { - players_.push_back(player); - } - - void remove_player(network::connection player) { - std::vector::iterator itor = - std::find(players_.begin(),players_.end(),player); - if(itor != players_.end()) - players_.erase(itor); - } - - int id() const { return id_; } - - void send_data(const config& data, network::connection exclude=0) { - for(std::vector::const_iterator - i = players_.begin(); i != players_.end(); ++i) { - if(*i != exclude) { - network::send_data(data,*i); - } - } - } - - bool level_init() const { return level_.child("side") != NULL; } - - config& level() { return level_; } - - bool empty() const { return players_.empty(); } - - void disconnect() { - for(std::vector::iterator i = players_.begin(); - i != players_.end(); ++i) { - network::disconnect(*i); - } - - players_.clear(); - } - -private: - static int id_num; - int id_; - std::vector players_; - config level_; -}; - -int game::id_num = 1; - -struct game_id_matches -{ - game_id_matches(int id) : id_(id) {} - bool operator()(const game& g) const { return g.id() == id_; } - -private: - int id_; -}; - int main() { const network::manager net_manager;