diff options
Diffstat (limited to 'src/core')
47 files changed, 1158 insertions, 813 deletions
diff --git a/src/core/application.cc b/src/core/application.cc index 4132c33..1d7ded2 100644 --- a/src/core/application.cc +++ b/src/core/application.cc @@ -58,7 +58,7 @@ extern "C" void signal_handler(int signum) break; } } -#endif +#endif /* ---- class Application ------------------------------------------ */ @@ -84,7 +84,7 @@ Application::Application() sys::signal(SIGWINCH, signal_handler); #endif #endif - + } Application::~Application() @@ -96,7 +96,7 @@ void Application::init(int count, char **arguments) { con_print << "^BInitializing core...\n"; con_debug << " debug messages enabled\n"; - + filesystem::init(arguments[0], "base", ""); Loader::load("base"); @@ -162,7 +162,7 @@ void Application::init(int count, char **arguments) // Initialize win32 socket library WSADATA wsa_data; WORD wsa_version = MAKEWORD(2, 0); - if (WSAStartup(wsa_version, &wsa_data) != 0 ) { + if (WSAStartup(wsa_version, &wsa_data) != 0) { con_warn << "Could not initialize socket library!" << std::endl; } #endif @@ -175,7 +175,7 @@ void Application::init(int count, char **arguments) func = Func::add("quit", Application::func_quit); func->set_info("exit the application"); - + func = Func::add("load", Application::func_load); func->set_info("[string] load a game module"); @@ -218,7 +218,7 @@ void Application::shutdown() Func::remove("say"); Func::remove("help"); Func::remove("quit"); - + Func::remove("connect"); Func::remove("disconnect"); Func::remove("load"); @@ -268,7 +268,7 @@ void Application::connect(std::string const &host) if (application_game) { disconnect(); } - + if (host.size()) { notify_connect(); application_game = new GameConnection(host); @@ -282,7 +282,7 @@ void Application::connect(std::string const &host) application_game = new GameServer(); if (application_game->running()) { - con_print << "^BConnected to local game.\n"; + con_print << "^BConnected to local game.\n"; } else { delete application_game; application_game = 0; @@ -293,7 +293,7 @@ void Application::connect(std::string const &host) void Application::disconnect() { - if(application_game) { + if (application_game) { delete application_game; application_game = 0; notify_disconnect(); @@ -310,11 +310,11 @@ void Application::frame(unsigned long timestamp) if (!connected()) return; - - // run a game interface frame + + // run a game interface frame application_game->frame(timestamp); - - if (!application_game->running()) + + if (!application_game->running()) disconnect(); } @@ -345,7 +345,7 @@ void Application::save_config() for (Cvar::Registry::iterator it = Cvar::registry().begin(); it != Cvar::registry().end(); it++) { if (((*it).second->flags() & Cvar::Archive) == Cvar::Archive) { ofs << "# " << (*it).first << " " << (*it).second->info() << std::endl; - ofs << "set " << (*it).first << " " << (*it).second->str() << std::endl; + ofs << "set " << (*it).first << " " << (*it).second->str() << std::endl; ofs << std::endl; } } @@ -369,18 +369,18 @@ void Application::load_config() con_print << " reading configuration from " << filename << std::endl; char line[MAXCMDSIZE]; - while (ifs.getline(line, MAXCMDSIZE-1)) { + while (ifs.getline(line, MAXCMDSIZE - 1)) { if (line[0] && line[0] != '#' && line[0] != ';') cmd() << line << '\n'; } - + // execute commands in the buffer CommandBuffer::exec(); } void Application::load_autoexec() { - if (Cvar::sv_dedicated->value()) + if (Cvar::sv_dedicated->value()) return; std::string filename(filesystem::writedir()); @@ -391,12 +391,12 @@ void Application::load_autoexec() con_warn << "Could not read " << filename << std::endl; std::ofstream ofs(filename.c_str()); - + if (!ofs.is_open()) { con_warn << "Could not write " << filename << std::endl; return; } - + ofs << "# autoexec.cfg - osirion client custom settings" << std::endl; ofs << "# put your custom settings here" << std::endl; ofs.close(); @@ -405,13 +405,13 @@ void Application::load_autoexec() } else { con_print << " reading configuration from " << filename << std::endl; - + char line[MAXCMDSIZE]; - while (ifs.getline(line, MAXCMDSIZE-1)) { + while (ifs.getline(line, MAXCMDSIZE - 1)) { if (line[0] && line[0] != '#' && line[0] != ';') cmd() << line << '\n'; } - + CommandBuffer::exec(); } } @@ -421,9 +421,9 @@ void Application::load_commandline(int count, char **arguments) if (count < 2) return; - for (int i=1; i < count; i++) { + for (int i = 1; i < count; i++) { if (arguments[i][0] == '+') { - if (i >1) + if (i > 1) cmd() << '\n'; if (arguments[i][1]) @@ -535,7 +535,7 @@ void Application::func_rcon(std::string const &args) if (rconpassword && rconpassword->str().size()) { connection()->rcon(args); } else { - con_warn << "rconpassword not set!" << std::endl; + con_warn << "rconpassword not set!" << std::endl; } } else if (server()) { cmd() << args << "\n"; diff --git a/src/core/application.h b/src/core/application.h index b2d8467..fbaba9d 100644 --- a/src/core/application.h +++ b/src/core/application.h @@ -24,36 +24,44 @@ class Application public: /// default constructor Application(); - + /// default destructor virtual ~Application(); - -/*----- inspectors ----------------------------------------------- */ + + /*----- inspectors ----------------------------------------------- */ /// the current application time, in microseconds - inline unsigned long timestamp() const { return application_timestamp; } - + inline unsigned long timestamp() const { + return application_timestamp; + } + /// the current application time, in seconds - float time() const { return ((float)(timestamp()) / 1000.0f); } + float time() const { + return ((float)(timestamp()) / 1000.0f); + } /// true if the core is connected to a running game interface - inline bool connected() const { return (application_game && application_game->running()); } + inline bool connected() const { + return (application_game && application_game->running()); + } /// return the game interface, returns 0 if the application is not connected to a game - inline GameInterface *game() { return application_game; } + inline GameInterface *game() { + return application_game; + } -/*----- mutators ------------------------------------------------- */ + /*----- mutators ------------------------------------------------- */ /// start the server or connect to remote host void connect(std::string const &host); - + /// disconnect from the game module void disconnect(); /// load a module bool load(std::string const &module_name); -/*----- virtual mutators ------------------------------------------ */ + /*----- virtual mutators ------------------------------------------ */ /// initialize the application virtual void init(int count, char **arguments); @@ -64,7 +72,7 @@ public: /// quit the application without proper shutdown virtual void quit(int status); -/*----- notifications --------------------------------------------- */ + /*----- notifications --------------------------------------------- */ /// sound notifications from the core to the application virtual void notify_sound(const char * name); @@ -85,7 +93,9 @@ public: virtual void notify_zonechange(); /// a pointer to the current application instance - static inline Application *instance() { return application_instance; } + static inline Application *instance() { + return application_instance; + } protected: /// run a core frame @@ -96,7 +106,7 @@ protected: /// load exra config void load_autoexec(); - + /// save cvar config void save_config(); @@ -125,13 +135,22 @@ private: }; /// pointer to the application -inline Application *application() { return Application::instance(); } +inline Application *application() +{ + return Application::instance(); +} /// pointer to the console -inline sys::ConsoleInterface *console() { return sys::ConsoleInterface::instance(); } +inline sys::ConsoleInterface *console() +{ + return sys::ConsoleInterface::instance(); +} /// pointer to the game interface -inline GameInterface *game() { return Application::instance()->game(); } +inline GameInterface *game() +{ + return Application::instance()->game(); +} } diff --git a/src/core/commandbuffer.cc b/src/core/commandbuffer.cc index fbb9cfd..eb13382 100644 --- a/src/core/commandbuffer.cc +++ b/src/core/commandbuffer.cc @@ -37,7 +37,7 @@ void func_print_file(std::string const &args) std::istringstream argstream(args); std::string filename; if (!(argstream >> filename)) - return; + return; CommandBuffer::print_file(filename); } @@ -155,7 +155,7 @@ void func_toggle(std::string const &args) if (cvar->flags() && Cvar::Info) { localplayer()->set_dirty(); } - + con_debug << " " << cvar->name() << " " << cvar->str() << "\n"; } @@ -164,16 +164,16 @@ void func_exec(std::string const &args) std::istringstream argstream(args); std::string filename; if (!(argstream >> filename)) - return; + return; - CommandBuffer::exec_file(filename); + CommandBuffer::exec_file(filename); } void func_remote(std::string const &args) { if (connection()) { if ((args[0] == '\\') || (args[0] == '/')) { - connection()->forward(args.substr(1, args.size()-1)); + connection()->forward(args.substr(1, args.size() - 1)); } else { connection()->forward(args); } @@ -256,11 +256,11 @@ void CommandBuffer::exec(std::string const &cmdline) std::istringstream cmdstream(cmdline); std::string command; - + if (!(cmdstream >> command)) return; - - aux::to_lowercase(command); + + aux::to_lowercase(command); //con_debug << "Executing '" << cmdline << "'\n"; if ((command[0] == '\\') || (command[0] == '/')) { @@ -294,7 +294,7 @@ void CommandBuffer::exec(std::string const &cmdline) } f->exec(game()->localplayer(), args); } - } + } } else { // regular function std::string args; @@ -307,13 +307,13 @@ void CommandBuffer::exec(std::string const &cmdline) } return; } - + // is it a cvar Cvar *cvar = Cvar::find(command); if (cvar) { // cvar exists std::string value; - if (((cvar->flags() & Cvar::ReadOnly) == 0) && (cmdstream >> value)) { + if (((cvar->flags() & Cvar::ReadOnly) == 0) && (cmdstream >> value)) { // we're setting a new value char c; while (cmdstream.get(c)) @@ -324,15 +324,15 @@ void CommandBuffer::exec(std::string const &cmdline) localplayer()->set_dirty(); } } - + con_print << " " << command << " " << cvar->str() << " ^N" << cvar->info() << "\n"; return; } - + // this gets forwarded to the server if (connection()) { if ((cmdline[0] == '\\') || (cmdline[0] == '/')) { - connection()->forward(cmdline.substr(1, cmdline.size()-1)); + connection()->forward(cmdline.substr(1, cmdline.size() - 1)); } else { connection()->forward(cmdline); } @@ -345,13 +345,13 @@ void CommandBuffer::exec() { if (cmdbuf.eof()) return; - + std::string line; char c; bool quote = false; - while ( core::cmd().read(&c , 1) && c) { - if ( c =='\n') { + while (core::cmd().read(&c , 1) && c) { + if (c == '\n') { exec(line); line.clear(); } else if (c == '"') { @@ -360,13 +360,13 @@ void CommandBuffer::exec() exec(line); line.clear(); } else { - line +=c; + line += c; } } if (line.size()) exec(line); - + cmdbuf.clear(); } @@ -389,7 +389,7 @@ void CommandBuffer::complete(std::string &input, size_t &pos) //con_print << " " << (*f).first << "\n"; } } - + // search cvar registry for matches for (Cvar::Registry::iterator c = Cvar::registry().begin(); c != Cvar::registry().end(); c++) { if (partial == (*c).first.substr(0, partial.size())) { @@ -397,17 +397,17 @@ void CommandBuffer::complete(std::string &input, size_t &pos) //con_print << " " << (*c).first << "\n"; } } - + if (!match.size()) return; - + std::string maxmatch(*match.begin()); - + if (match.size() > 1) { std::list<std::string>::iterator l; - for (l = match.begin(); l !=match.end(); l++) { + for (l = match.begin(); l != match.end(); l++) { if (maxmatch.size()) { - size_t i =0; + size_t i = 0; while ((i < maxmatch.size() && i < (*l).size()) && (maxmatch[i] == (*l)[i])) { i++; } @@ -417,70 +417,70 @@ void CommandBuffer::complete(std::string &input, size_t &pos) con_print << " " << (*l) << "\n"; } con_print << match.size() << " matches\n"; - + } - + if (maxmatch.size() > partial.size()) { - if (match.size()==1) maxmatch += ' '; + if (match.size() == 1) maxmatch += ' '; input.replace(start, pos, maxmatch); pos = maxmatch.size(); } - + } void CommandBuffer::exec_file(std::string const & filename) { - filesystem::File *f = filesystem::open(filename.c_str()); - if (!f) { - con_warn << "Could not open " << filename << std::endl; - return; - } + filesystem::File *f = filesystem::open(filename.c_str()); + if (!f) { + con_warn << "Could not open " << filename << std::endl; + return; + } - std::string fn = f->path(); - fn.append(f->name()); - filesystem::close(f); + std::string fn = f->path(); + fn.append(f->name()); + filesystem::close(f); std::ifstream ifs; ifs.open(fn.c_str()); - if (!ifs.is_open()) { - con_warn << "Could not stream " << fn << "!\n"; - return; - } + if (!ifs.is_open()) { + con_warn << "Could not stream " << fn << "!\n"; + return; + } con_print << "Executing " << fn.c_str() << std::endl; char line[MAXCMDSIZE]; - while (ifs.getline(line, MAXCMDSIZE-1)) { - if (line[0] && line[0] != '#' && line[0] != ';') + while (ifs.getline(line, MAXCMDSIZE - 1)) { + if (line[0] && line[0] != '#' && line[0] != ';') exec(std::string(line)); - } + } ifs.close(); } void CommandBuffer::print_file(std::string const & filename) { - filesystem::File *f = filesystem::open(filename.c_str()); - if (!f) { - con_warn << "Could not open " << filename << std::endl; - return; - } + filesystem::File *f = filesystem::open(filename.c_str()); + if (!f) { + con_warn << "Could not open " << filename << std::endl; + return; + } - std::string fn = f->path(); - fn.append(f->name()); - filesystem::close(f); + std::string fn = f->path(); + fn.append(f->name()); + filesystem::close(f); std::ifstream ifs; ifs.open(fn.c_str()); - if (!ifs.is_open()) { - con_warn << "Could not stream " << fn << "!\n"; - return; - } + if (!ifs.is_open()) { + con_warn << "Could not stream " << fn << "!\n"; + return; + } char line[MAXCMDSIZE]; - while (ifs.getline(line, MAXCMDSIZE-1)) { + while (ifs.getline(line, MAXCMDSIZE - 1)) { con_print << line << "\n"; - } + } ifs.close(); } diff --git a/src/core/commandbuffer.h b/src/core/commandbuffer.h index 9cd919b..c8024ba 100644 --- a/src/core/commandbuffer.h +++ b/src/core/commandbuffer.h @@ -48,7 +48,10 @@ private: }; /// the global command buffer -inline std::stringstream & cmd() { return CommandBuffer::cmdbuf; } +inline std::stringstream & cmd() +{ + return CommandBuffer::cmdbuf; +} } diff --git a/src/core/cvar.cc b/src/core/cvar.cc index 1732d1a..6b4302d 100644 --- a/src/core/cvar.cc +++ b/src/core/cvar.cc @@ -163,8 +163,8 @@ void Cvar::list() if (((*it).second->flags() & Archive) == Archive) typeindicator += 'A'; else - typeindicator += ' '; - + typeindicator += ' '; + if (((*it).second->flags() & Game) == Game) typeindicator += 'G'; else @@ -175,8 +175,8 @@ void Cvar::list() else typeindicator += ' '; - con_print << " " << typeindicator << - " " << (*it).first << " " << (*it).second->str() << " ^N" << (*it).second->info() << std::endl; + con_print << " " << typeindicator << + " " << (*it).first << " " << (*it).second->str() << " ^N" << (*it).second->info() << std::endl; } con_print << cvar_registry.size() << " registered variables" << std::endl; } diff --git a/src/core/cvar.h b/src/core/cvar.h index 4c3d942..3d7b246 100644 --- a/src/core/cvar.h +++ b/src/core/cvar.h @@ -28,34 +28,44 @@ public: * Game a cvar with this flag is only valid when a game is loaded * Info a cvar that updates player info */ - enum Flags {Archive=1, ReadOnly=2, Game=4, Info=8}; - + enum Flags {Archive = 1, ReadOnly = 2, Game = 4, Info = 8}; + /// create a new variable Cvar(const char* name, const unsigned int flags = 0); -/*----- inspectors ------------------------------------------------ */ + /*----- inspectors ------------------------------------------------ */ /// returns the name of the variable - inline const std::string& name() const { return cvar_name; } + inline const std::string& name() const { + return cvar_name; + } /// returns the info of the variable - inline const std::string& info() const { return cvar_info; } + inline const std::string& info() const { + return cvar_info; + } /// returns the flags of the variable - inline const unsigned int flags() const { return cvar_flags; } + inline const unsigned int flags() const { + return cvar_flags; + } /// returns the float value of the variable - inline const float value() const { return cvar_value; } + inline const float value() const { + return cvar_value; + } /// returns the string value of the variable - inline const std::string& str() const { return cvar_str; } + inline const std::string& str() const { + return cvar_str; + } -/*----- mutators -------------------------------------------------- */ + /*----- mutators -------------------------------------------------- */ /// set the info string void set_info(const char* info); - /// char * assignment operator + /// char * assignment operator Cvar &operator=(const char* other); /// std::string assignment operator @@ -64,40 +74,40 @@ public: /// float assignment operator Cvar &operator=(const float other); -/* ---- Static functions for the Cvar registry -------------------- */ + /* ---- Static functions for the Cvar registry -------------------- */ /// type definition for the Cvar registry typedef std::map<std::string, Cvar*> Registry; - + /** * @brief get a cvar value from the registry * If the a cvar with the given name already exists in the registry, - * its value will not be changed. If the cvar does not exist, - * it will be created - */ - static Cvar* get(const char* name, const char* value, const unsigned int flags=0); + * its value will not be changed. If the cvar does not exist, + * it will be created + */ + static Cvar* get(const char* name, const char* value, const unsigned int flags = 0); /** * @brief get a cvar value from the registry * If the a cvar with the given name already exists in the registry, - * its value will not be changed. If the cvar does not exist, - * it will be created - */ - static Cvar* get(const char* name, const float value, const unsigned int flags=0); + * its value will not be changed. If the cvar does not exist, + * it will be created + */ + static Cvar* get(const char* name, const float value, const unsigned int flags = 0); /** * @brief set a cvar value * If the a cvar with the given name already exists in the registry, - * its value will be replaced - */ - static Cvar* set(const char* name, const char* value, const unsigned int flags=0); + * its value will be replaced + */ + static Cvar* set(const char* name, const char* value, const unsigned int flags = 0); /** * @brief set a cvar value * If the a cvar with the given name already exists in the registry, - * its value will be replaced - */ - static Cvar* set(const char* name, float value, const unsigned int flags=0); + * its value will be replaced + */ + static Cvar* set(const char* name, float value, const unsigned int flags = 0); /// search for a named cvar, returns 0 if not found static Cvar* find(const std::string& name); @@ -115,7 +125,9 @@ public: static void list(); /// the cvar registry - static inline Registry & registry() { return cvar_registry; } + static inline Registry & registry() { + return cvar_registry; + } static Cvar *sv_dedicated; // dedicated server static Cvar *sv_private; // client with private server diff --git a/src/core/descriptions.cc b/src/core/descriptions.cc index 8c0f4ee..307cc87 100644 --- a/src/core/descriptions.cc +++ b/src/core/descriptions.cc @@ -8,7 +8,8 @@ #include "auxiliary/functions.h" #include "sys/sys.h" -namespace core { +namespace core +{ /* ---- class ButtonDescription ------------------------------------ */ @@ -55,7 +56,7 @@ MenuDescription::MenuDescription() MenuDescription::~MenuDescription() { for (Buttons::iterator it = buttons().begin(); it != buttons().end(); it++) { - delete (*it); + delete(*it); } buttons().clear(); @@ -82,16 +83,16 @@ void MenuDescription::add_button(ButtonDescription *button) void Descriptions::serialize(MenuDescription *menu, std::ostream & os) { os << menu->label() << " " - << "\"" << menu->text() << "\" " - << menu->buttons().size() << " "; - + << "\"" << menu->text() << "\" " + << menu->buttons().size() << " "; + for (MenuDescription::Buttons::iterator it = menu-> buttons().begin(); it != menu->buttons().end(); it++) { ButtonDescription *button = (*it); os << "\"" << button->text() << "\" " - << button->alignment() << " " - << button->command_type() << " " - << "\"" << button->command() << "\" " - << "\"" << button->modelname() << "\" "; + << button->alignment() << " " + << button->command_type() << " " + << "\"" << button->command() << "\" " + << "\"" << button->modelname() << "\" "; } } @@ -111,8 +112,8 @@ MenuDescription * Descriptions::receive(std::istream &is) // menu text n.clear(); - while ( (is.get(c)) && (c != '"')); - while ( (is.get(c)) && (c != '"')) + while ((is.get(c)) && (c != '"')); + while ((is.get(c)) && (c != '"')) n += c; if (n.size()) @@ -120,12 +121,12 @@ MenuDescription * Descriptions::receive(std::istream &is) // menu buttons is >> nb; - for (size_t i=0; i < nb; i++) { + for (size_t i = 0; i < nb; i++) { ButtonDescription *button = new ButtonDescription(); // button text n.clear(); - while ( (is.get(c)) && (c != '"')); - while ( (is.get(c)) && (c != '"')) + while ((is.get(c)) && (c != '"')); + while ((is.get(c)) && (c != '"')) n += c; if (n.size()) button->set_text(n); @@ -144,8 +145,8 @@ MenuDescription * Descriptions::receive(std::istream &is) // button command n.clear(); - while ( (is.get(c)) && (c != '"')); - while ( (is.get(c)) && (c != '"')) + while ((is.get(c)) && (c != '"')); + while ((is.get(c)) && (c != '"')) n += c; if (n.size()) { @@ -158,8 +159,8 @@ MenuDescription * Descriptions::receive(std::istream &is) // button modelname n.clear(); - while ( (is.get(c)) && (c != '"')); - while ( (is.get(c)) && (c != '"')) + while ((is.get(c)) && (c != '"')); + while ((is.get(c)) && (c != '"')) n += c; if (n.size()) button->set_modelname(n); @@ -167,7 +168,7 @@ MenuDescription * Descriptions::receive(std::istream &is) } return menu; - + } bool Descriptions::load_entity_menus(core::Entity *entity, const std::string &menufilename) @@ -180,11 +181,11 @@ bool Descriptions::load_entity_menus(core::Entity *entity, const std::string &me } con_debug << " " << inifile.name() << std::endl; - + std::string strval; MenuDescription *menu = 0; ButtonDescription *button = 0; - + while (inifile.getline()) { if (inifile.got_section()) { @@ -216,14 +217,14 @@ bool Descriptions::load_entity_menus(core::Entity *entity, const std::string &me } } else if (inifile.in_section("button")) { - + if (!button) { continue; } else if (inifile.got_key_string("text", strval)) { aux::strip_quotes(strval); button->set_text(strval); } else if (inifile.got_key_string("command", strval)) { - for (size_t i =0; i <= strval.size(); i++) { + for (size_t i = 0; i <= strval.size(); i++) { if (strval[i] == ',') strval[i] = ';'; } aux::strip_quotes(strval); diff --git a/src/core/descriptions.h b/src/core/descriptions.h index dec7896..2b4b1e0 100644 --- a/src/core/descriptions.h +++ b/src/core/descriptions.h @@ -11,7 +11,8 @@ #include <list> #include <iostream> -namespace core { +namespace core +{ class ButtonDescription; class MenuDescription; } @@ -20,38 +21,51 @@ class MenuDescription; #include "model/model.h" #include "filesystem/inifile.h" -namespace core { +namespace core +{ /// description of a menu button class ButtonDescription { public: - enum Align {Center=0, Left=1, Right=2}; + enum Align {Center = 0, Left = 1, Right = 2}; - enum CommandType {CommandNone=0, CommandGame=1, CommandMenu=2}; + enum CommandType {CommandNone = 0, CommandGame = 1, CommandMenu = 2}; ButtonDescription(); ~ButtonDescription(); - + /* -- inspectors ------------------------------------------- */ /// button text - inline const std::string & text() const { return button_text; } + inline const std::string & text() const { + return button_text; + } /// button command type - inline const CommandType command_type() const {return button_commandtype; } + inline const CommandType command_type() const { + return button_commandtype; + } /// button command - inline const std::string & command() const { return button_command; } + inline const std::string & command() const { + return button_command; + } /// button info view model name - inline const std::string & modelname() const { return button_modelname; } + inline const std::string & modelname() const { + return button_modelname; + } /// button info view model - inline const model::Model *model() { return button_model; } - + inline const model::Model *model() { + return button_model; + } + /// button text alignment - inline Align alignment() const { return button_align; } + inline Align alignment() const { + return button_align; + } /* -- mutators -------------------------------------------- */ @@ -88,13 +102,19 @@ public: /* -- inspectors ------------------------------------------- */ /// menu label - inline const std::string & label() const { return menu_label; } + inline const std::string & label() const { + return menu_label; + } /// menu text - inline const std::string & text() const { return menu_text; } + inline const std::string & text() const { + return menu_text; + } /// menu buttons - inline Buttons &buttons() { return menu_buttons; } + inline Buttons &buttons() { + return menu_buttons; + } /* -- mutators -------------------------------------------- */ @@ -110,13 +130,14 @@ public: private: std::string menu_label; std::string menu_text; - + Buttons menu_buttons; }; /// descriptions loader class -class Descriptions { +class Descriptions +{ public: /// read entity menus from ini file static bool load_entity_menus(core::Entity *entity, const std::string &menufilename); diff --git a/src/core/entity.cc b/src/core/entity.cc index 0ead5f4..ce313e6 100644 --- a/src/core/entity.cc +++ b/src/core/entity.cc @@ -78,9 +78,9 @@ void Entity::list() std::string typeindicator; Entity *entity = (*it).second; con_print << " id " << std::setw(4) << entity->id() - << " type " << std::setw(4) << entity->type() - << ":" << std::setw(4) << entity->moduletype() - << " " << entity->label() << std::endl; + << " type " << std::setw(4) << entity->type() + << ":" << std::setw(4) << entity->moduletype() + << " " << entity->label() << std::endl; } con_print << entity_registry.size() << " registered entities" << std::endl; } @@ -88,21 +88,21 @@ void Entity::list() /* ---- class Entity ----------------------------------------------- */ Entity::Entity(const unsigned int flags) : - entity_location(0.0f, 0.0f, 0.0f), - entity_color(1.0f, 1.0f, 1.0f, 1.0f), - entity_color_second(1.0f, 1.0f, 1.0f, 1.0f) + entity_location(0.0f, 0.0f, 0.0f), + entity_color(1.0f, 1.0f, 1.0f, 1.0f), + entity_color_second(1.0f, 1.0f, 1.0f, 1.0f) { entity_id = 0; entity_flags = flags; entity_moduletypeid = 0; entity_speed = 0.0f; - + entity_radius = 0.5f; entity_shape = Diamond; - + entity_created = true; - entity_destroyed = false; + entity_destroyed = false; entity_dirty = false; entity_model = 0; @@ -133,25 +133,25 @@ Entity::Entity(std::istream & is) entity_created = true; entity_destroyed = false; - + memset(entity_extension, 0, sizeof(entity_extension)); } Entity::~Entity() { // delete extensions - for (size_t i =0; i < 4; i++) { + for (size_t i = 0; i < 4; i++) { if (entity_extension[i]) delete entity_extension[i]; - entity_extension[i] = 0; + entity_extension[i] = 0; } // delete entity menus for (Menus::iterator it = menus().begin(); it != menus().end(); it++) { - delete (*it); + delete(*it); } menus().clear(); - + if (entity_zone) entity_zone->remove(this); } @@ -234,19 +234,19 @@ void Entity::set_modelname(const std::string &modelname) void Entity::serialize_server_create(std::ostream & os) const { os << moduletype() << " " - << flags() << " " - << (visible() ? 1 : 0) << " " - << (zone() ? zone()->id() : 0) << " " - << std::setprecision(8) << entity_location << " " - << color() << " " - << color_second() << " " - << shape() << " " - << radius() << " " - << std::setprecision(8) << entity_axis.forward() << " " - << std::setprecision(8) << entity_axis.left() << " " - << "\"" << entity_label << "\" " - << "\"" << entity_name << "\" " - << "\"" << (entity_model ? entity_model->name() : "") << "\" "; + << flags() << " " + << (visible() ? 1 : 0) << " " + << (zone() ? zone()->id() : 0) << " " + << std::setprecision(8) << entity_location << " " + << color() << " " + << color_second() << " " + << shape() << " " + << radius() << " " + << std::setprecision(8) << entity_axis.forward() << " " + << std::setprecision(8) << entity_axis.left() << " " + << "\"" << entity_label << "\" " + << "\"" << entity_name << "\" " + << "\"" << (entity_model ? entity_model->name() : "") << "\" "; } void Entity::receive_server_create(std::istream &is) @@ -271,12 +271,12 @@ void Entity::receive_server_create(std::istream &is) if (entity_zone && !zo) { con_warn << "Received entity " << entity_id << " for unknown zone " << zo << "!" << std::endl; } - + is >> entity_location; is >> entity_color; is >> entity_color_second; - - is >> s; // shape + + is >> s; // shape entity_shape = (Shape) s; is >> entity_radius; @@ -289,23 +289,23 @@ void Entity::receive_server_create(std::istream &is) char c; // read label - while ( (is.get(c)) && (c != '"')); - while ( (is.get(c)) && (c != '"')) - n += c; + while ((is.get(c)) && (c != '"')); + while ((is.get(c)) && (c != '"')) + n += c; entity_label = n; n.clear(); // read name - while ( (is.get(c)) && (c != '"')); - while ( (is.get(c)) && (c != '"')) - n += c; + while ((is.get(c)) && (c != '"')); + while ((is.get(c)) && (c != '"')) + n += c; entity_name = n; n.clear(); // read model name - while ( (is.get(c)) && (c != '"')); - while ( (is.get(c)) && (c != '"')) - n += c; + while ((is.get(c)) && (c != '"')); + while ((is.get(c)) && (c != '"')) + n += c; set_modelname(n); entity_dirty = false; @@ -354,21 +354,21 @@ void Entity::remove_menu(std::string const &label) for (Menus::iterator it = menus().begin(); it != menus().end(); it++) { if (label.compare((*it)->label()) == 0) menus().erase(it); - return; + return; } } /* ---- class EntityDynamic ---------------------------------------- */ EntityDynamic::EntityDynamic(unsigned int flags) : - Entity(flags) + Entity(flags) { entity_state = Normal; entity_timer = 0; } EntityDynamic::EntityDynamic(std::istream & is) : - Entity(is) + Entity(is) { entity_state = Normal; entity_timer = 0; @@ -403,10 +403,10 @@ void EntityDynamic::serialize_server_create(std::ostream & os) const { Entity::serialize_server_create(os); os << roundf(entity_speed * 100.0f) << " " - << entity_state << " "; + << entity_state << " "; if (entity_state != Normal) { - os << entity_timer << " "; + os << entity_timer << " "; } } @@ -434,7 +434,7 @@ void EntityDynamic::receive_client_update(std::istream &is) void EntityDynamic::serialize_server_update(std::ostream & os) const { - os << (visible() ? 1 : 0 ) << " "; + os << (visible() ? 1 : 0) << " "; if (visible()) { os << std::setprecision(8) << location() << " " @@ -442,7 +442,7 @@ void EntityDynamic::serialize_server_update(std::ostream & os) const << axis().left() << " " << roundf(entity_speed * 100.0f) << " " << entity_state << " "; - + if (entity_state != Normal) { os << entity_timer << " "; } @@ -463,7 +463,7 @@ void EntityDynamic::receive_server_update(std::istream &is) is >> entity_speed; entity_speed /= 100.0f; is >> entity_state; - + if (entity_state != Normal) { is >> entity_timer; } else { @@ -477,7 +477,7 @@ void EntityDynamic::receive_server_update(std::istream &is) /*----- EntityControlable ------------------------------------------ */ EntityControlable::EntityControlable(Player *owner, unsigned int flags) : - EntityDynamic(flags) + EntityDynamic(flags) { entity_thrust = 0; entity_movement = 0; @@ -495,7 +495,7 @@ EntityControlable::EntityControlable(Player *owner, unsigned int flags) : } EntityControlable::EntityControlable(std::istream & is) : - EntityDynamic(is) + EntityDynamic(is) { entity_thrust = 0; entity_movement = 0; @@ -521,7 +521,7 @@ void EntityControlable::serialize_server_create(std::ostream & os) const { EntityDynamic::serialize_server_create(os); os << roundf(entity_thrust*100.0f) << " " - << ( entity_owner ? entity_owner->id() : 0) << " "; + << (entity_owner ? entity_owner->id() : 0) << " "; } void EntityControlable::receive_server_create(std::istream &is) @@ -532,16 +532,16 @@ void EntityControlable::receive_server_create(std::istream &is) entity_thrust /= 100.0f; entity_owner = 0; - + int owner_id = 0; is >> owner_id; if (owner_id) { - for (GameInterface::Players::iterator pit = game()->players().begin(); pit != game()->players().end(); pit++ ) { + for (GameInterface::Players::iterator pit = game()->players().begin(); pit != game()->players().end(); pit++) { Player *player = (*pit); if (player->id() == owner_id) { player->add_asset(this); entity_owner = player; - + } } @@ -666,7 +666,7 @@ void EntityControlable::set_afterburner(float afterburner) /*----- EntityGlobe ------------------------------------------------ */ EntityGlobe::EntityGlobe(unsigned int flags) : - Entity(flags) + Entity(flags) { render_texture = 0; entity_rotationspeed = 0; @@ -674,7 +674,7 @@ EntityGlobe::EntityGlobe(unsigned int flags) : } EntityGlobe::EntityGlobe(std::istream & is) : - Entity(is) + Entity(is) { render_texture = 0; entity_rotationspeed = 0; @@ -699,9 +699,9 @@ void EntityGlobe::receive_server_create(std::istream &is) std::string n; char c; - while ( (is.get(c)) && (c != '"')); - while ( (is.get(c)) && (c != '"')) - n += c; + while ((is.get(c)) && (c != '"')); + while ((is.get(c)) && (c != '"')) + n += c; entity_texture = n; n.clear(); diff --git a/src/core/entity.h b/src/core/entity.h index 3002219..92cb5ab 100644 --- a/src/core/entity.h +++ b/src/core/entity.h @@ -39,16 +39,16 @@ class Entity public: /// Entity flags - enum Flags {Static=1, Solid=2, Bright=4, Dockable=8, ShowOnMap=16}; + enum Flags {Static = 1, Solid = 2, Bright = 4, Dockable = 8, ShowOnMap = 16}; /// Entity type constants - enum Type {Default=0, Dynamic=1, Controlable=2, Globe=3}; + enum Type {Default = 0, Dynamic = 1, Controlable = 2, Globe = 3}; /// Entity shape constants - enum Shape {Diamond=0, Sphere=1, Cube=2, Axis=3}; + enum Shape {Diamond = 0, Sphere = 1, Cube = 2, Axis = 3}; /// EntityDynamic State constants - enum State {Normal=0, NoPower=1, ImpulseInitiate=2, Impulse=3, JumpInitiate=4, Jump=5, Docked=6, Destroyed=7}; + enum State {Normal = 0, NoPower = 1, ImpulseInitiate = 2, Impulse = 3, JumpInitiate = 4, Jump = 5, Docked = 6, Destroyed = 7}; /// entity menus collection typedef typedef std::list<MenuDescription *> Menus; @@ -62,76 +62,122 @@ public: /// destroy an entity virtual ~Entity(); -/*----- inspectors ------------------------------------------------ */ - + /*----- inspectors ------------------------------------------------ */ + /// entity id - inline const unsigned int id() const { return entity_id; } - + inline const unsigned int id() const { + return entity_id; + } + /// module type id - inline const unsigned int moduletype() const { return entity_moduletypeid; } + inline const unsigned int moduletype() const { + return entity_moduletypeid; + } /// core type id - virtual inline const unsigned int type() const { return Default; } + virtual inline const unsigned int type() const { + return Default; + } /// entity flags - inline const unsigned int flags() const { return entity_flags; } + inline const unsigned int flags() const { + return entity_flags; + } /// returns true of a flag is set - inline const bool flag_is_set(const Flags flag) const { return ((entity_flags & (unsigned int)flag) == (unsigned int)flag); } + inline const bool flag_is_set(const Flags flag) const { + return ((entity_flags & (unsigned int)flag) == (unsigned int)flag); + } /// entity label (can not contain double quotes ") - inline const std::string& label() const { return entity_label; } + inline const std::string& label() const { + return entity_label; + } /// entity name (can not contain double qoutes ") - inline const std::string & name() const { return entity_name; } + inline const std::string & name() const { + return entity_name; + } /// pointer to the model, is used client-side - inline model::Model * model() { return entity_model; } + inline model::Model * model() { + return entity_model; + } /// modelname - inline const std::string & modelname() const { return entity_modelname; } + inline const std::string & modelname() const { + return entity_modelname; + } /// pointer to the zone the entity belongs to - inline Zone *zone() const { return entity_zone; } + inline Zone *zone() const { + return entity_zone; + } /// the zone the entity left in case of a zone change - inline Zone *oldzone() const { return entity_oldzone; } + inline Zone *oldzone() const { + return entity_oldzone; + } /// dirty flag - inline bool dirty() const { return entity_dirty; } + inline bool dirty() const { + return entity_dirty; + } /// entity location - inline const math::Vector3f& location() const { return entity_location; } + inline const math::Vector3f& location() const { + return entity_location; + } /// local coordinate system of the entity - inline const math::Axis& axis() const { return entity_axis; } - + inline const math::Axis& axis() const { + return entity_axis; + } + /// primary color of the entity - inline const math::Color& color() const { return entity_color; } + inline const math::Color& color() const { + return entity_color; + } /// secondary - inline const math::Color& color_second() const { return entity_color_second; } + inline const math::Color& color_second() const { + return entity_color_second; + } /// base shape of the entity - inline const Shape shape() const { return entity_shape; } + inline const Shape shape() const { + return entity_shape; + } /// base radius of the entity - inline const float radius() const { return entity_radius; } + inline const float radius() const { + return entity_radius; + } /// current speed of the entity in game units per second - inline const float speed() const { return entity_speed; } + inline const float speed() const { + return entity_speed; + } /// indicates a server-side entity - inline const bool serverside() const { return entity_serverside; } + inline const bool serverside() const { + return entity_serverside; + } /// general visibility - inline const bool visible() const { return entity_visible; } + inline const bool visible() const { + return entity_visible; + } /// entity menus - inline Menus &menus() { return entity_menus; } + inline Menus &menus() { + return entity_menus; + } /// extensions - inline Extension *extension(size_t type) const { return entity_extension[type]; } + inline Extension *extension(size_t type) const { + return entity_extension[type]; + } /// find a menu MenuDescription *find_menu(const std::string &label); @@ -140,13 +186,19 @@ public: /* ---- mutators -------------------------------------------------- */ /// assign entity color - inline void set_color(const math::Color &color) { entity_color.assign(color); } + inline void set_color(const math::Color &color) { + entity_color.assign(color); + } /// assign entity secondary color - inline void set_color_second(const math::Color &color) { entity_color_second.assign(color); } + inline void set_color_second(const math::Color &color) { + entity_color_second.assign(color); + } /// set dirty flag - inline void set_dirty(const bool dirty = true) { entity_dirty = dirty; } + inline void set_dirty(const bool dirty = true) { + entity_dirty = dirty; + } /// mark the entity as destroyed virtual void die(); @@ -178,10 +230,14 @@ public: void set_name(const std::string &name); /// set visibility - inline void set_visible(const bool visible = true) { entity_visible = visible; } + inline void set_visible(const bool visible = true) { + entity_visible = visible; + } /// set as server-side entity - inline void set_serverside(const bool serverside = true) { entity_serverside = serverside; } + inline void set_serverside(const bool serverside = true) { + entity_serverside = serverside; + } /// set the model name and load the model void set_modelname(const std:: string &model); @@ -190,7 +246,9 @@ public: void set_model(model::Model *model); /// set entity radius - inline void set_radius(const float radius) { entity_radius = radius; } + inline void set_radius(const float radius) { + entity_radius = radius; + } /* ---- actors ---------------------------------------------------- */ @@ -198,10 +256,14 @@ public: virtual void dock(core::Entity *entity); /// set flags - inline void set_flag(Flags flag) { entity_flags |= flag; } + inline void set_flag(Flags flag) { + entity_flags |= flag; + } /// unset flags - inline void unset_flag(Flags flag) { entity_flags &= ~flag; } + inline void unset_flag(Flags flag) { + entity_flags &= ~flag; + } /// add an entity menu void add_menu(MenuDescription *menu); @@ -215,23 +277,31 @@ public: /** * @brief mutable reference to the location */ - inline math::Vector3f& get_location() { return entity_location; } + inline math::Vector3f& get_location() { + return entity_location; + } /** * @brief mutable reference to the axis */ - inline math::Axis& get_axis() { return entity_axis; } + inline math::Axis& get_axis() { + return entity_axis; + } /** * @brief mutable reference to the primary color */ - inline math::Color& get_color() { return entity_color; } + inline math::Color& get_color() { + return entity_color; + } /** * @brief mutable reference to the secondary color */ - inline math::Color& get_color_second() { return entity_color_second; } + inline math::Color& get_color_second() { + return entity_color_second; + } /* ---- deserializers -------------------------------------- */ @@ -257,7 +327,7 @@ public: /* ---- static --------------------------------------------- */ - + /// type definition for the entity registry typedef std::map<unsigned int, Entity*> Registry; @@ -274,13 +344,15 @@ public: static void list(); /// the entity registry - static inline Registry & registry() { return entity_registry; } + static inline Registry & registry() { + return entity_registry; + } /* entity_ variables can be set by the module */ /// speed of the entity - float entity_speed; - Shape entity_shape; + float entity_speed; + Shape entity_shape; unsigned int entity_moduletypeid; bool entity_created; @@ -321,7 +393,7 @@ private: Extension* entity_extension[4]; - static Registry entity_registry; + static Registry entity_registry; static size_t entity_nextid; static void add(Entity *ent); @@ -340,17 +412,23 @@ public: virtual ~EntityDynamic(); -/*----- inspectors ------------------------------------------------ */ + /*----- inspectors ------------------------------------------------ */ /// core type id - virtual inline const unsigned int type() const { return Entity::Dynamic; } + virtual inline const unsigned int type() const { + return Entity::Dynamic; + } /// event state - inline const int state() const { return entity_state; } + inline const int state() const { + return entity_state; + } /// event state timer - inline const float timer() const { return entity_timer; } + inline const float timer() const { + return entity_timer; + } -/*----- serializers ----------------------------------------------- */ + /*----- serializers ----------------------------------------------- */ /// serialize the entity to a stream virtual void serialize_server_create(std::ostream & os) const; @@ -361,7 +439,7 @@ public: /// serialize a server-to-client update on a stream virtual void serialize_server_update(std::ostream & os) const; -/*----- mutators -------------------------------------------------- */ + /*----- mutators -------------------------------------------------- */ /// receive a client-to-server update from a stream virtual void receive_client_update(std::istream &is); @@ -398,24 +476,32 @@ public: /// create a controlable entity from stream data EntityControlable(std::istream & is); - + virtual ~EntityControlable(); -/*----- inspectors ------------------------------------------------ */ + /*----- inspectors ------------------------------------------------ */ /// core type id - virtual inline const unsigned int type() const { return Entity::Controlable; } + virtual inline const unsigned int type() const { + return Entity::Controlable; + } /// owner of this entity - inline Player *owner() const { return entity_owner; } + inline Player *owner() const { + return entity_owner; + } /// thrust - inline float thrust() const { return entity_thrust; } + inline float thrust() const { + return entity_thrust; + } /// movement indicator - inline float movement() const { return entity_movement; } + inline float movement() const { + return entity_movement; + } -/*----- serializers ----------------------------------------------- */ + /*----- serializers ----------------------------------------------- */ /// serialize the entity to a stream virtual void serialize_server_create(std::ostream & os) const; @@ -426,7 +512,7 @@ public: /// serialize a server-to-client update on a stream virtual void serialize_server_update(std::ostream & os) const; -/*----- mutators -------------------------------------------------- */ + /*----- mutators -------------------------------------------------- */ /// receive a client-to-server update from a stream virtual void receive_client_update(std::istream &is); @@ -442,7 +528,7 @@ public: /// set the target direction void set_direction(float direction); - + /// set the target pitch void set_pitch(float pitch); @@ -494,7 +580,7 @@ private: }; /// a Globe entity -class EntityGlobe : public Entity +class EntityGlobe : public Entity { public: EntityGlobe(const unsigned int flags = 0); @@ -502,14 +588,18 @@ public: virtual ~EntityGlobe(); -/*----- inspectors ----------------------------------------------- */ + /*----- inspectors ----------------------------------------------- */ /// texture name - inline const std::string &texture() const { return entity_texture; } + inline const std::string &texture() const { + return entity_texture; + } /// rotation speed in degrees per second - inline float rotationspeed() const { return entity_rotationspeed; } + inline float rotationspeed() const { + return entity_rotationspeed; + } -/*----- serializers ----------------------------------------------- */ + /*----- serializers ----------------------------------------------- */ /// serialize the entity to a stream virtual void serialize_server_create(std::ostream & os) const; @@ -517,10 +607,12 @@ public: /// receive a server-to-client create from a stream virtual void receive_server_create(std::istream &is); -/*----- inspectors ------------------------------------------------ */ + /*----- inspectors ------------------------------------------------ */ /// core type id - virtual inline const unsigned int type() const { return Entity::Globe; } + virtual inline const unsigned int type() const { + return Entity::Globe; + } std::string entity_texture; diff --git a/src/core/extension.h b/src/core/extension.h index 0b9ecad..91ba906 100644 --- a/src/core/extension.h +++ b/src/core/extension.h @@ -7,23 +7,30 @@ #ifndef __INCLUDED_CORE_EXTENSION_H__ #define __INCLUDED_CORE_EXTENSION_H__ -namespace core { - class Extension; +namespace core +{ +class Extension; } #include "core/entity.h" -namespace core { +namespace core +{ /// a abstract base class for entity extensions -class Extension { +class Extension +{ public: /// extension types - enum Type { Client=0, Render=1, Sound=2, Game=3 }; + enum Type { Client = 0, Render = 1, Sound = 2, Game = 3 }; - inline Type type() const { return extension_type; } + inline Type type() const { + return extension_type; + } - inline Entity *entity() { return extension_entity; } + inline Entity *entity() { + return extension_entity; + } Extension(Type type, Entity *entity); virtual ~Extension(); @@ -33,7 +40,7 @@ public: private: Type extension_type; Entity *extension_entity; - + }; } // namespace core diff --git a/src/core/func.cc b/src/core/func.cc index 42c46c8..be5aca3 100644 --- a/src/core/func.cc +++ b/src/core/func.cc @@ -66,8 +66,8 @@ Func *Func::add(const char *name, TargetFuncPtr targetfunctionptr) void Func::remove(const char *name) { std::map<std::string, Func *>::iterator it = func_registry.find(std::string(name)); - if (it != func_registry.end()) { - delete (*it).second; + if (it != func_registry.end()) { + delete(*it).second; func_registry.erase(it); //con_debug << "Function '" << name << "' unregistered." << std::endl; } @@ -76,11 +76,11 @@ void Func::remove(const char *name) void Func::remove(const std::string &name) { std::map<std::string, Func *>::iterator it = func_registry.find(name); - if (it != func_registry.end()) { - delete (*it).second; - func_registry.erase(it); + if (it != func_registry.end()) { + delete(*it).second; + func_registry.erase(it); //con_debug << "Function '" << name << "' unregistered." << std::endl; - } + } } @@ -104,7 +104,7 @@ void Func::list() typeindicator += 'G'; else typeindicator += ' '; - if (((*it).second->flags() & Shared) == Shared) + if (((*it).second->flags() & Shared) == Shared) typeindicator += 'S'; else typeindicator += ' '; @@ -150,12 +150,12 @@ void Func::exec(std::string const &args) FuncPtr function = (FuncPtr) func_ptr; function(args); } - + void Func::exec(Player *player, std::string const &args) { if (!(flags() & Game)) return; - + GameFuncPtr gamefunction = (GameFuncPtr) func_ptr; gamefunction(player, args); } diff --git a/src/core/func.h b/src/core/func.h index eacd47e..f42eff7 100644 --- a/src/core/func.h +++ b/src/core/func.h @@ -27,49 +27,55 @@ typedef void(* GameFuncPtr)(Player *player, std::string const &args); typedef void(* TargetFuncPtr)(Player *player, Entity *entity); /// a function pointer encapsulation class -class Func +class Func { public: /// function flags - enum Flags {Game=1, Shared=2, Target=4}; - + enum Flags {Game = 1, Shared = 2, Target = 4}; + /// create a new function Func(char const * name, void *ptr, unsigned int flags = 0); - + ~Func(); -/*----- inspectors ------------------------------------------------ */ + /*----- inspectors ------------------------------------------------ */ /// returns the fucuntion flags - inline unsigned int flags() const { return func_flags; } + inline unsigned int flags() const { + return func_flags; + } /// returns the name of the function - inline std::string const &name() const { return func_name; } + inline std::string const &name() const { + return func_name; + } /// returns the info of the function - inline std::string const &info() { return func_info; } + inline std::string const &info() { + return func_info; + } + + /*----- mutators -------------------------------------------------- */ -/*----- mutators -------------------------------------------------- */ - /// set the info string void set_info(const char *); /// execute the function if the Game flag is not set void exec(std::string const &args); - + /// execute the function if the Game flag is set void exec(Player *player, std::string const &args); /// execute the function if the Target flag is set void exec(Player *player, Entity *entity); -/* ---- Static functions for the Func registry -------------------- */ + /* ---- Static functions for the Func registry -------------------- */ /// type definition typedef std::map<std::string, Func*> Registry; /// add a function to the registry - static Func *add(const char *name, FuncPtr functionptr, bool shared=false); + static Func *add(const char *name, FuncPtr functionptr, bool shared = false); /// add a game function to the registry and set the Game flag static Func *add(const char *name, GameFuncPtr functionptr); @@ -90,7 +96,9 @@ public: static void list(); /// the function registry - static inline Registry & registry() { return func_registry; } + static inline Registry & registry() { + return func_registry; + } private: std::string func_name; diff --git a/src/core/gameconnection.cc b/src/core/gameconnection.cc index 65126e3..b615b5f 100644 --- a/src/core/gameconnection.cc +++ b/src/core/gameconnection.cc @@ -31,7 +31,7 @@ GameConnection::GameConnection(std::string const &connectionstr) size_t found = host.find(':'); if (found != std::string::npos) { - std::istringstream str(host.substr(found+1)); + std::istringstream str(host.substr(found + 1)); if (str >> port) { host.erase(found, std::string::npos); } else { @@ -82,7 +82,7 @@ unsigned long GameConnection::timestamp() const float GameConnection::time() const { - return ((float)(connection_timestamp) / 1000.0f); + return ((float)(connection_timestamp) / 1000.0f); } bool GameConnection::interactive() const @@ -165,18 +165,18 @@ void GameConnection::frame(unsigned long timestamp) connection_network->frame(); float f = 0; - if (core::Cvar::net_framerate->value()) { + if (core::Cvar::net_framerate->value()) { f = 1000.0f / core::Cvar::net_framerate->value(); if (connection_netframe + f > timestamp) { return; } - } + } connection_netframe = timestamp; if (connection_network->state() == NetConnection::Connected) { - if(localcontrol() && localcontrol()->dirty()) { + if (localcontrol() && localcontrol()->dirty()) { connection_network->send_clientupdate(localcontrol()); localcontrol()->set_dirty(false); @@ -184,7 +184,7 @@ void GameConnection::frame(unsigned long timestamp) if (localplayer()->dirty()) { connection_network->send_playerinfo(); - + } } diff --git a/src/core/gameconnection.h b/src/core/gameconnection.h index 22af910..52885f4 100644 --- a/src/core/gameconnection.h +++ b/src/core/gameconnection.h @@ -20,13 +20,17 @@ public: GameConnection(std::string const &connectionstr); virtual ~GameConnection(); -/*----- inspectors ------------------------------------------------ */ + /*----- inspectors ------------------------------------------------ */ /// returns true if the game connection can run a time frime - inline bool running() const { return connection_running; } + inline bool running() const { + return connection_running; + } /// returns true if the game connection can not run a time frime - inline bool error() const { return !connection_running; } + inline bool error() const { + return !connection_running; + } /// returns true if the game is running an interactive module virtual bool interactive() const; @@ -37,7 +41,7 @@ public: /// return the current game time virtual unsigned long timestamp() const; -/*----- mutators -------------------------------------------------- */ + /*----- mutators -------------------------------------------------- */ /// run a game connection time frame void frame(unsigned long timestamp); @@ -57,10 +61,12 @@ public: /// returns an info record Info *info(const std::string &label); -/*----- static ---------------------------------------------------- */ - + /*----- static ---------------------------------------------------- */ + /// return the current game connection - static inline GameConnection *instance() { return connection_instance; } + static inline GameConnection *instance() { + return connection_instance; + } protected: /// abort runing @@ -72,10 +78,13 @@ private: unsigned long connection_netframe; // last network frame timestamp NetConnection *connection_network; - static GameConnection *connection_instance; + static GameConnection *connection_instance; }; -inline GameConnection *connection() { return GameConnection::instance(); } +inline GameConnection *connection() +{ + return GameConnection::instance(); +} } diff --git a/src/core/gameinterface.cc b/src/core/gameinterface.cc index ce011dd..272c349 100644 --- a/src/core/gameinterface.cc +++ b/src/core/gameinterface.cc @@ -25,7 +25,7 @@ namespace core void func_list_players(std::string const &args) { - + if (args.size()) { Player *player = game()->find_player(args); if (!player) { @@ -44,22 +44,22 @@ const float MIN_DELTA = 10e-10; Player GameInterface::game_localplayer; EntityControlable *localcontrol() -{ +{ if (game()->localplayer()) return game()->localplayer()->control(); else return 0; - + } Player *localplayer() -{ +{ return game()->localplayer(); } GameInterface::GameInterface() { clear(); - + game_localplayer.clear(); if (Cvar::sv_dedicated->value()) { game_localplayer.player_name.assign("Console"); @@ -107,7 +107,7 @@ void GameInterface::clear() // remove all entities for (Entity::Registry::iterator it = Entity::registry().begin(); it != Entity::registry().end(); it++) { - delete (*it).second; + delete(*it).second; } Entity::registry().clear(); @@ -121,8 +121,8 @@ void GameInterface::clear() // remove all game functions for (Func::Registry::iterator it = Func::registry().begin(); it != Func::registry().end();) { - if ( ((*it).second->flags() & Func::Game) == Func::Game) { - delete (*it).second; + if (((*it).second->flags() & Func::Game) == Func::Game) { + delete(*it).second; Func::registry().erase(it++); } else { ++it; @@ -130,9 +130,9 @@ void GameInterface::clear() } // remove all game cvars - for (Cvar::Registry::iterator it = Cvar::registry().begin(); it != Cvar::registry().end(); ) { - if ( ((*it).second->flags() & Cvar::Game) == Cvar::Game) { - delete (*it).second; + for (Cvar::Registry::iterator it = Cvar::registry().begin(); it != Cvar::registry().end();) { + if (((*it).second->flags() & Cvar::Game) == Cvar::Game) { + delete(*it).second; Cvar::registry().erase(it++); } else { ++it; @@ -194,10 +194,10 @@ void GameInterface::list_players() for (Players::iterator it = game_players.begin(); it != game_players.end(); it++) { const Player *player = (*it); con_print << " " - << aux::pad_left(player->name(), 24) << "^N " - << "id^B" << setw(4) << player->id() << " " - << "ping^B" << setw(4) << player->ping() << "^N " - << "level^B" << setw(4) << player->level() << "^N"; + << aux::pad_left(player->name(), 24) << "^N " + << "id^B" << setw(4) << player->id() << " " + << "ping^B" << setw(4) << player->ping() << "^N " + << "level^B" << setw(4) << player->level() << "^N"; if (player->zone()) con_print << aux::pad_left(player->zone()->name(), 24) << "^N"; diff --git a/src/core/gameinterface.h b/src/core/gameinterface.h index dbb235e..44b4230 100644 --- a/src/core/gameinterface.h +++ b/src/core/gameinterface.h @@ -27,22 +27,28 @@ public: /// type definition for the Players collection typedef std::list<Player *> Players; -/*----- inspectors ---------------------------------------------- */ + /*----- inspectors ---------------------------------------------- */ /// return the local player - inline Player *localplayer() { return &game_localplayer; } + inline Player *localplayer() { + return &game_localplayer; + } - inline Players & players() { return game_players; } + inline Players & players() { + return game_players; + } + + inline model::VertexArray *vertexarray() { + return game_vertexarray; + } - inline model::VertexArray *vertexarray() { return game_vertexarray; } - /// find the first player who's id or name matches the search string Player *find_player(const std::string &search); - + /// show a list of connected players void list_players(); -/*----- virtual inspectors --------------------------------------- */ + /*----- virtual inspectors --------------------------------------- */ /// returns true if the game server can run a time frime virtual bool running() const = 0; @@ -59,14 +65,14 @@ public: /// returns an info record virtual Info *info(const std::string &label) = 0; -/*----- mutators ------------------------------------------------- */ - + /*----- mutators ------------------------------------------------- */ + /// clear all game variables, game functions and entities void clear(); -/*----- virtual mutators ------------------------------------------ */ - + /*----- virtual mutators ------------------------------------------ */ + /// run one game time frame /// @param timestamp current application time virtual void frame(unsigned long timestamp) = 0; diff --git a/src/core/gameserver.cc b/src/core/gameserver.cc index 096d8bf..e170a4d 100644 --- a/src/core/gameserver.cc +++ b/src/core/gameserver.cc @@ -39,15 +39,15 @@ void func_time(std::string const &args) using namespace std; int minutes = (int) floorf(server()->time() / 60.0f); - int seconds = (int) floorf(server()->time() - (float) minutes* 60.0f); + int seconds = (int) floorf(server()->time() - (float) minutes * 60.0f); int syshours = sys::time() / 3600; int sysminutes = (sys::time() - syshours * 3600) / 60; int sysseconds = sys::time() % 60; - con_print << - "Uptime " << minutes << ":" << setfill('0') << setw(2) << seconds << - " Local time " << setfill(' ') << setw(2) << syshours << ":" << setfill('0') << setw(2) << sysminutes << ":" << setw(2) << sysseconds << setfill(' ') << std::endl; + con_print << + "Uptime " << minutes << ":" << setfill('0') << setw(2) << seconds << + " Local time " << setfill(' ') << setw(2) << syshours << ":" << setfill('0') << setw(2) << sysminutes << ":" << setw(2) << sysseconds << setfill(' ') << std::endl; } void func_mute(std::string const &args) @@ -78,7 +78,7 @@ void func_unmute(std::string const &args) } targetplayer->player_mute = false; - server()->broadcast("^B" +targetplayer->name() + "^B has been unmuted", targetplayer); + server()->broadcast("^B" + targetplayer->name() + "^B has been unmuted", targetplayer); targetplayer->send("^WYou have been unmuted"); } @@ -92,8 +92,8 @@ void func_kick(std::string const &args) if (!(targetplayer = console_find_player(name))) return; std::string reason; - if (args.size() > name.size()+1) - reason.assign(args.substr(name.size()+1)); + if (args.size() > name.size() + 1) + reason.assign(args.substr(name.size() + 1)); else reason.assign("forcefully removed."); @@ -105,7 +105,8 @@ void func_grant_rcon(std::string const &args) { Player *targetplayer = 0; if (!(targetplayer = console_find_player(args))) - return;} + return; +} void func_revoke_rcon(std::string const &args) { @@ -141,7 +142,7 @@ GameServer::GameServer() : GameInterface() if (server_module->interactive()) { //FIXME interferes with command line because of cmd.exec - load_config(); + load_config(); } // set the name of the game @@ -217,9 +218,9 @@ GameServer::~GameServer() Func::remove("mute"); Func::remove("unmute"); -/* Func::remove("grant_rcon"); - Func::remove("revoke_rcon"); -*/ + /* Func::remove("grant_rcon"); + Func::remove("revoke_rcon"); + */ Func::remove("time"); Func::remove("who"); @@ -233,7 +234,7 @@ unsigned long GameServer::timestamp() const float GameServer::time() const { - return ((float)(server_timestamp) / 1000.0f); + return ((float)(server_timestamp) / 1000.0f); } Info *GameServer::info(const std::string &label) @@ -250,7 +251,7 @@ bool GameServer::interactive() const { if (!server_module) { return false; - } else { + } else { return server_module->interactive(); } } @@ -320,14 +321,14 @@ void GameServer::kick(Player *player, std::string const &reason) } // broadcast an "info" message to all players -void GameServer::broadcast(const std::string text, Player *ignore_player) +void GameServer::broadcast(const std::string text, Player *ignore_player) { broadcast(Message::Info, text, ignore_player); } // broadcast a message on a specified channel to all players -void GameServer::broadcast(const Message::Channel channel, const std::string text, Player *ignore_player) +void GameServer::broadcast(const Message::Channel channel, const std::string text, Player *ignore_player) { if (!text.size()) return; @@ -370,10 +371,10 @@ void GameServer::exec(Player *player, std::string const & cmdline) cmdstream >> command; Func *function = Func::find(command); - if (function ) { + if (function) { std::string args; - if (cmdline.size() > command.size() +1 ) - args.assign(cmdline.substr(command.size()+1)); + if (cmdline.size() > command.size() + 1) + args.assign(cmdline.substr(command.size() + 1)); if ((function ->flags() & Func::Game) == Func::Game) { if ((function ->flags() & Func::Target) == Func::Target) { @@ -382,18 +383,18 @@ void GameServer::exec(Player *player, std::string const & cmdline) Entity *entity = Entity::find(id); if (entity) function->exec(player, entity); - } + } } else { function->exec(player, args); } } else if ((function->flags() & Func::Shared) == Func::Shared) { - + // enable rcon buffering console()->set_rcon(true); function->exec(args); - while(console()->rconbuf().size()) { + while (console()->rconbuf().size()) { player->message(Message::RCon, (*console()->rconbuf().begin())); console()->rconbuf().pop_front(); } @@ -444,12 +445,12 @@ void GameServer::player_disconnect(Player *player) server_module->player_disconnect(player); // manage player list - std::list<Player *>:: iterator it = game_players.begin(); + std::list<Player *>:: iterator it = game_players.begin(); while (((*it)->id() != player->id()) && (it != game_players.end())) { it++; } if (it != game_players.end()) { - game_players.erase(it); + game_players.erase(it); } } @@ -469,14 +470,14 @@ void GameServer::frame(unsigned long timestamp) } if (localplayer()->dirty()) - localplayer()->update_info(); + localplayer()->update_info(); /*if (!Cvar::sv_dedicated->value()) { update_clientstate(); }*/ if ((Cvar::sv_dedicated->value() || Cvar::sv_private->value())) { - if (core::Cvar::sv_framerate->value()) { + if (core::Cvar::sv_framerate->value()) { float f = 1000.0f / core::Cvar::sv_framerate->value(); if (server_startup + server_timestamp + f > timestamp) { return; @@ -486,15 +487,15 @@ void GameServer::frame(unsigned long timestamp) server_previoustime = server_timestamp; server_timestamp = timestamp - server_startup; - float elapsed = (float) (server_timestamp - server_previoustime) / 1000.0f; - + float elapsed = (float)(server_timestamp - server_previoustime) / 1000.0f; + // copy the previous entity state to the client state /*if (!Cvar::sv_dedicated->value()) { reset_clientstate(); }*/ // run a time frame on each entity - for (Entity::Registry::iterator it=Entity::registry().begin(); it != Entity::registry().end(); it++) { + for (Entity::Registry::iterator it = Entity::registry().begin(); it != Entity::registry().end(); it++) { Entity *entity = (*it).second; if ((entity->type() == Entity::Controlable) || (entity->type() == Entity::Dynamic)) { @@ -512,14 +513,14 @@ void GameServer::frame(unsigned long timestamp) return; } } - + if (server_network) { // send network updates server_network->frame(server_timestamp); } // mark all entities as updated - for (Entity::Registry::iterator it=Entity::registry().begin(); it != Entity::registry().end(); ) { + for (Entity::Registry::iterator it = Entity::registry().begin(); it != Entity::registry().end();) { Entity *entity = (*it).second; if (entity->entity_destroyed) { @@ -531,7 +532,7 @@ void GameServer::frame(unsigned long timestamp) ++it; } } - + if (localplayer()->zonechange()) { application()->notify_zonechange(); localplayer()->set_zonechange(false); @@ -560,7 +561,7 @@ void GameServer::save_config() ofs << std::endl; for (Cvar::Registry::iterator it = Cvar::registry().begin(); it != Cvar::registry().end(); it++) { - if ((((*it).second->flags() & Cvar::Archive) == Cvar::Archive) && (((*it).second->flags() & Cvar::Game) == Cvar::Game)){ + if ((((*it).second->flags() & Cvar::Archive) == Cvar::Archive) && (((*it).second->flags() & Cvar::Game) == Cvar::Game)) { ofs << "# " << (*it).first << " " << (*it).second->info() << std::endl; ofs << "set " << (*it).first << " " << (*it).second->str() << std::endl; ofs << std::endl; @@ -583,11 +584,11 @@ void GameServer::load_config() con_print << " reading configuration from " << filename << std::endl; char line[MAXCMDSIZE]; - while (ifs.getline(line, MAXCMDSIZE-1)) { + while (ifs.getline(line, MAXCMDSIZE - 1)) { if (line[0] && line[0] != '#' && line[0] != ';') cmd() << line << '\n'; } - + // execute commands in the buffer CommandBuffer::exec(); } diff --git a/src/core/gameserver.h b/src/core/gameserver.h index a8d96db..57feac1 100644 --- a/src/core/gameserver.h +++ b/src/core/gameserver.h @@ -25,13 +25,17 @@ public: GameServer(); virtual ~GameServer(); -/*----- inspectors ------------------------------------------------ */ + /*----- inspectors ------------------------------------------------ */ /// returns true if the game server can run a time frime - inline bool running() const { return server_running; } + inline bool running() const { + return server_running; + } /// returns true if the game server can not run a time frime - inline bool error() const { return !server_running; } + inline bool error() const { + return !server_running; + } /// returns true if the game is running an interactive module virtual bool interactive() const; @@ -43,9 +47,11 @@ public: virtual unsigned long timestamp() const; /// current module - inline const Module *module() const { return server_module; } + inline const Module *module() const { + return server_module; + } -/*----- mutators -------------------------------------------------- */ + /*----- mutators -------------------------------------------------- */ /// is called when a player connects to the game server void player_connect(Player *player); @@ -55,7 +61,7 @@ public: /// run a game server time frame void frame(unsigned long timestamp); - + /// a player sends a chat message to the public channel void say(Player *player, std::string const &args); @@ -78,15 +84,19 @@ public: void exec(Player *player, std::string const &cmdline); /// time the server was started - inline const unsigned long startup() const { return server_startup; } + inline const unsigned long startup() const { + return server_startup; + } /// returns an info record Info *info(const std::string &label); -/*----- static ---------------------------------------------------- */ - + /*----- static ---------------------------------------------------- */ + /// return the current game server - static inline GameServer *instance() { return server_instance; } + static inline GameServer *instance() { + return server_instance; + } protected: /// abort runing @@ -107,7 +117,10 @@ private: unsigned long server_startup; }; -inline GameServer *server() { return GameServer::instance(); } +inline GameServer *server() +{ + return GameServer::instance(); +} } diff --git a/src/core/info.cc b/src/core/info.cc index 93837c0..745bc3b 100644 --- a/src/core/info.cc +++ b/src/core/info.cc @@ -87,16 +87,16 @@ void Info::receive_server_update(std::istream &is) char c; // read name - while ( (is.get(c)) && (c != '"')); - while ( (is.get(c)) && (c != '"')) - n += c; + while ((is.get(c)) && (c != '"')); + while ((is.get(c)) && (c != '"')) + n += c; info_name.assign(n); // read model name n.clear(); - while ( (is.get(c)) && (c != '"')); - while ( (is.get(c)) && (c != '"')) - n += c; + while ((is.get(c)) && (c != '"')); + while ((is.get(c)) && (c != '"')) + n += c; info_modelname.assign(n); @@ -106,9 +106,9 @@ void Info::receive_server_update(std::istream &is) is >> s; for (size_t i = 0; (i < s) && is.good(); i++) { n.clear(); - while ( (is.get(c)) && (c != '"')); - while ( (is.get(c)) && (c != '"')) - n += c; + while ((is.get(c)) && (c != '"')); + while ((is.get(c)) && (c != '"')) + n += c; info_text.push_back(n); } @@ -124,7 +124,7 @@ Info::~Info() void Info::print() const { con_print << "label: ^B" << label() << " ^Nname: ^B" << name() << " ^Nmodel: ^B" << modelname() << "^N" << std::endl; - + for (Text::const_iterator it = info_text.begin(); it != info_text.end(); it++) { con_print << " " << (*it) << std::endl; } diff --git a/src/core/info.h b/src/core/info.h index 1bc62a9..8395954 100644 --- a/src/core/info.h +++ b/src/core/info.h @@ -31,15 +31,25 @@ public: typedef std::deque<std::string> Text; - inline const std::string & label() const { return info_label; } + inline const std::string & label() const { + return info_label; + } - inline const std::string & name() const { return info_name; } + inline const std::string & name() const { + return info_name; + } - inline const std::string & modelname() const { return info_modelname; } + inline const std::string & modelname() const { + return info_modelname; + } - inline const unsigned long ×tamp() const { return info_timestamp; } + inline const unsigned long ×tamp() const { + return info_timestamp; + } - inline Text & text() { return info_text; } + inline Text & text() { + return info_text; + } void set_name(const std::string & name); @@ -73,7 +83,7 @@ public: /// receive a server-to-client update from a stream void receive_server_update(std::istream &is); -/* ---- static info registry --------------------------------------- */ + /* ---- static info registry --------------------------------------- */ typedef std::map<std::string, Info*> Registry; @@ -93,7 +103,9 @@ public: static void list(); /// the info registry - static inline Registry & registry() { return info_registry; } + static inline Registry & registry() { + return info_registry; + } private: std::string info_label; diff --git a/src/core/item.cc b/src/core/item.cc index 7b4633c..53da74d 100644 --- a/src/core/item.cc +++ b/src/core/item.cc @@ -33,7 +33,7 @@ void Item::find_class(const char *label) void Item::clear() { for (Registry::iterator it = item_registry.begin(); it != item_registry.end(); it++) { - delete (*it); + delete(*it); } item_registry.clear(); } @@ -61,7 +61,7 @@ ItemClass::ItemClass(const char *label) ItemClass::~ItemClass() { for (Types::iterator it = itemclass_types.begin(); it != itemclass_types.end(); it++) { - delete (*it); + delete(*it); } } diff --git a/src/core/item.h b/src/core/item.h index 8299444..0845c21 100644 --- a/src/core/item.h +++ b/src/core/item.h @@ -10,7 +10,8 @@ #include <string> #include <vector> -namespace core { +namespace core +{ /** * @brief a specific type of item in the game @@ -21,11 +22,17 @@ class ItemType public: ItemType(const char *label); - inline const std::string &label() { return itemtype_label; } + inline const std::string &label() { + return itemtype_label; + } - inline const std::string &name() { return itemtype_name; } + inline const std::string &name() { + return itemtype_name; + } - inline const float baseprice() { return itemtype_baseprice; } + inline const float baseprice() { + return itemtype_baseprice; + } void set_name(const std::string &name); @@ -51,9 +58,13 @@ public: ItemClass(const char *label); ~ItemClass(); - inline const std::string &label() { return itemclass_label; } + inline const std::string &label() { + return itemclass_label; + } - inline const std::string &name() { return itemclass_name; } + inline const std::string &name() { + return itemclass_name; + } ItemType *find_type(const char *label); diff --git a/src/core/loader.cc b/src/core/loader.cc index 4070c2b..168b9bf 100644 --- a/src/core/loader.cc +++ b/src/core/loader.cc @@ -8,7 +8,8 @@ #include "core/loader.h" #include "sys/sys.h" -namespace core { +namespace core +{ Loader::Registry Loader::loader_registry; std::string Loader::loader_label; @@ -21,7 +22,7 @@ Loader::FactoryFuncPtr Loader::find(const char *label) else return (*it).second; } - + Loader::FactoryFuncPtr Loader::find(const std::string &label) { return (find(label.c_str())); diff --git a/src/core/loader.h b/src/core/loader.h index 1fde764..e9f7e0b 100644 --- a/src/core/loader.h +++ b/src/core/loader.h @@ -11,7 +11,8 @@ #include "core/module.h" -namespace core { +namespace core +{ /// module factory registry /** The Loader contains a list of module factories and can load @@ -21,11 +22,11 @@ class Loader { public: /// function pointer type for a module factory - typedef Module * (* FactoryFuncPtr)(); + typedef Module *(* FactoryFuncPtr)(); /// find a registered mmodule factory static FactoryFuncPtr find(const char *label); - + /// find a registered module factory static FactoryFuncPtr find(const std::string &label); @@ -38,7 +39,9 @@ public: /// assign the next module to init static bool load(const std::string &label); - static inline const std::string &label() { return loader_label; } + static inline const std::string &label() { + return loader_label; + } /// initialize a game module static Module *init(); @@ -52,7 +55,7 @@ public: private: typedef std::map<std::string, FactoryFuncPtr> Registry; - static Registry loader_registry; + static Registry loader_registry; static std::string loader_label; }; diff --git a/src/core/message.h b/src/core/message.h index b9a9661..3c53439 100644 --- a/src/core/message.h +++ b/src/core/message.h @@ -10,11 +10,12 @@ namespace core { -class Message { +class Message +{ public: /// indicates the type of message - enum Channel {Info=0, Public=1, Local=2, Private=3, RCon=4}; + enum Channel {Info = 0, Public = 1, Local = 2, Private = 3, RCon = 4}; }; } diff --git a/src/core/module.cc b/src/core/module.cc index 5dd07b5..6271331 100644 --- a/src/core/module.cc +++ b/src/core/module.cc @@ -14,7 +14,7 @@ namespace core Module* Module::module_instance = 0; Module::Module(const char *name, bool interactive) : - module_name(name) + module_name(name) { module_running = true; module_interactive = interactive; diff --git a/src/core/module.h b/src/core/module.h index 76b1ba4..ac6b380 100644 --- a/src/core/module.h +++ b/src/core/module.h @@ -17,26 +17,36 @@ namespace core class Module { public: - Module(const char *name, bool interactive=true); + Module(const char *name, bool interactive = true); virtual ~Module(); -/*----- inspectors ------------------------------------------------ */ + /*----- inspectors ------------------------------------------------ */ /// return true if the game module can run a timeframe - inline bool running() const { return module_running; } + inline bool running() const { + return module_running; + } /// return true if the game module can not run a timeframe - inline bool error() const { return !module_running; } + inline bool error() const { + return !module_running; + } /// label of the module - inline std::string const & label() const { return module_label; } + inline std::string const & label() const { + return module_label; + } /// return the name of the module - inline std::string const & name() const { return module_name; } + inline std::string const & name() const { + return module_name; + } /// indicates if this is an interactive module or not - inline bool interactive() const { return module_interactive; } + inline bool interactive() const { + return module_interactive; + } -/*----- mutators -------------------------------------------------- */ + /*----- mutators -------------------------------------------------- */ /// run one game frame virtual void frame(float seconds) = 0; @@ -50,7 +60,9 @@ public: /// set the module label void set_label(const std::string &label); - static inline Module *instance() { return module_instance; } + static inline Module *instance() { + return module_instance; + } protected: /// abort a running module @@ -61,7 +73,7 @@ private: bool module_running; std::string module_label; - std::string module_name; + std::string module_name; static Module* module_instance; }; diff --git a/src/core/netclient.cc b/src/core/netclient.cc index 253cf4f..46694a6 100644 --- a/src/core/netclient.cc +++ b/src/core/netclient.cc @@ -46,10 +46,10 @@ NetClient::NetClient(std::string host, int port, int fd) : abort(); return; } - + sendq.clear(); messageblock.clear(); - + client_keepalive = application()->time(); client_timeout = application()->time(); @@ -69,25 +69,27 @@ void NetClient::abort() std::string NetClient::host() const { - return client_host; + return client_host; } int NetClient::port() const { - return client_port; + return client_port; } -Player *NetClient::player() +Player *NetClient::player() { return client_player; } -bool NetClient::has_messages() const { - return (recvq.size() > 0 ); +bool NetClient::has_messages() const +{ + return (recvq.size() > 0); } -void NetClient::retreive(std::string & message) { - if (recvq.size() > 0 ) { +void NetClient::retreive(std::string & message) +{ + if (recvq.size() > 0) { message.assign(recvq.front()); recvq.pop_front(); } else { @@ -101,9 +103,9 @@ void NetClient::receive(char *data) const char *c = data; while (*c) { - if (( *c == '\n') || (*c == '\r')) { - if (messageblock.size() > 0 ) { - recvq.push_back(messageblock); + if ((*c == '\n') || (*c == '\r')) { + if (messageblock.size() > 0) { + recvq.push_back(messageblock); messageblock.clear(); } } else { @@ -117,7 +119,7 @@ void NetClient::receive(char *data) c++; } - client_timeout = application()->time(); + client_timeout = application()->time(); } void NetClient::send_raw(std::string const &msg) @@ -125,7 +127,7 @@ void NetClient::send_raw(std::string const &msg) if (error()) return; - if ((sendq.size()) && (sendq.size() + msg.size() >= BLOCKSIZE - 16 )) { + if ((sendq.size()) && (sendq.size() + msg.size() >= BLOCKSIZE - 16)) { transmit(); } @@ -135,12 +137,12 @@ void NetClient::send_raw(std::string const &msg) void NetClient::transmit() { if (!sendq.size()) { - if (client_keepalive + NETTIMEOUT/2 < application()->time()) { + if (client_keepalive + NETTIMEOUT / 2 < application()->time()) { sendq.assign("ping\n"); } else { return; } - } else if (sendq.size() >= BLOCKSIZE - 16 ) { + } else if (sendq.size() >= BLOCKSIZE - 16) { con_warn << host() << ":" << port() << " outgoing data exceeds " << BLOCKSIZE - 16 << " bytes!\n"; sendq.clear(); return; @@ -152,17 +154,17 @@ void NetClient::transmit() uLong uncompressed_size = (uLong) sendq.size(); size_t total_size = 0; - memset(zbuf,0, sizeof(zbuf)); + memset(zbuf, 0, sizeof(zbuf)); Stats::network_uncompressed_bytes_sent += sendq.size(); // zlib compress - int status = compress((Bytef*)(zbuf+4), &compressed_size, (Bytef*)sendq.c_str(), uncompressed_size); + int status = compress((Bytef*)(zbuf + 4), &compressed_size, (Bytef*)sendq.c_str(), uncompressed_size); if ((status == Z_OK) && (compressed_size + 4 < sendq.size())) { // add a header to the compress packet data = (char *) zbuf; - total_size = (size_t) (compressed_size + 4); + total_size = (size_t)(compressed_size + 4); zbuf[0] = '\xff'; zbuf[1] = '\xff'; zbuf[2] = compressed_size % 256; @@ -171,12 +173,12 @@ void NetClient::transmit() data = sendq.c_str(); total_size = sendq.size(); } - + size_t total_sent = 0; while (total_sent < total_size && !error()) { ssize_t bytes_sent = ::sendto(fd(), data, total_size - total_sent, 0, - (struct sockaddr *)&client_addr, sizeof(client_addr)); + (struct sockaddr *) & client_addr, sizeof(client_addr)); if (bytes_sent < 0) { abort(); diff --git a/src/core/netclient.h b/src/core/netclient.h index c0cdf8d..818422e 100644 --- a/src/core/netclient.h +++ b/src/core/netclient.h @@ -43,14 +43,14 @@ namespace core class NetClient { public: - NetClient(std::string host, int port, int fd); - ~NetClient(); + NetClient(std::string host, int port, int fd); + ~NetClient(); - /// the remote hostname the client is connected to - std::string host() const; + /// the remote hostname the client is connected to + std::string host() const; - /// the remote port the client is connected to - int port() const; + /// the remote port the client is connected to + int port() const; /// the player info associated with this client Player *player(); @@ -69,32 +69,38 @@ public: /// transmit messages in the send queue to the remote client void transmit(); - - inline bool error() const { return client_error; } + + inline bool error() const { + return client_error; + } void abort(); - enum State {Connecting=0, Pending=1, Connected=2}; + enum State {Connecting = 0, Pending = 1, Connected = 2}; + + inline State state() const { + return client_state; + } - inline State state() const { return client_state; } - State client_state; - + float client_timeout; float client_keepalive; private: - inline int fd() const { return client_fd; } + inline int fd() const { + return client_fd; + } struct sockaddr_in client_addr; - std::string client_host; - int client_port; + std::string client_host; + int client_port; int client_fd; bool client_error; NetPlayer *client_player; - - std::string messageblock; + + std::string messageblock; std::deque<std::string> recvq; std::string sendq; }; diff --git a/src/core/netconnection.cc b/src/core/netconnection.cc index 81f5b48..c37fe05 100644 --- a/src/core/netconnection.cc +++ b/src/core/netconnection.cc @@ -16,7 +16,7 @@ #include "core/player.h" #include "core/stats.h" -namespace core +namespace core { NetConnection::NetConnection() @@ -37,7 +37,7 @@ NetConnection::~NetConnection() void NetConnection::abort() { - connection_error= true; + connection_error = true; } void NetConnection::connect(std::string const &to_host, int to_port) @@ -48,7 +48,7 @@ void NetConnection::connect(std::string const &to_host, int to_port) if (valid()) return; - + // resolve serverhostname struct hostent *serverhostent; serverhostent = gethostbyname(to_host.c_str()); @@ -57,7 +57,7 @@ void NetConnection::connect(std::string const &to_host, int to_port) abort(); return; } - + // Get a socket file descriptor connection_fd = socket(PF_INET, SOCK_DGRAM, 0); if (connection_fd == -1) { @@ -65,7 +65,7 @@ void NetConnection::connect(std::string const &to_host, int to_port) abort(); return; } - + // make the connection server_addr.sin_family = AF_INET; server_addr.sin_port = htons(to_port); @@ -77,7 +77,7 @@ void NetConnection::connect(std::string const &to_host, int to_port) abort(); return; } - + connection_host = to_host; connection_port = to_port; connection_error = false; @@ -94,10 +94,10 @@ void NetConnection::connect(std::string const &to_host, int to_port) connection_state = Pending; game()->localplayer()->set_dirty(); - std::stringstream str; - str << "Connecting to " << inet_ntoa(*((struct in_addr *)serverhostent->h_addr)) << ":" << to_port << "..."; - con_print << str.str() << std::endl; - application()->notify_loader(str.str()); + std::stringstream str; + str << "Connecting to " << inet_ntoa(*((struct in_addr *)serverhostent->h_addr)) << ":" << to_port << "..."; + con_print << str.str() << std::endl; + application()->notify_loader(str.str()); } void NetConnection::disconnect() @@ -114,7 +114,7 @@ void NetConnection::disconnect() close(connection_fd); #endif } - + connection_fd = -1; connection_error = false; connection_host.clear(); @@ -145,9 +145,9 @@ void NetConnection::receive() return; ssize_t bytes_received; - + memset(recvbuf, 0, BLOCKSIZE); - bytes_received = ::recv(connection_fd, recvbuf, BLOCKSIZE-1, 0); + bytes_received = ::recv(connection_fd, recvbuf, BLOCKSIZE - 1, 0); Stats::network_bytes_received += bytes_received; connection_timeout = core::application()->time(); @@ -173,7 +173,7 @@ void NetConnection::receive() // uncompress char zunbuf[BLOCKSIZE*2]; memset(zunbuf, 0, sizeof(zunbuf)); - uLong zunbuf_size = (uLong) BLOCKSIZE*2 - 1; + uLong zunbuf_size = (uLong) BLOCKSIZE * 2 - 1; int status = uncompress((Bytef *) zunbuf, &zunbuf_size, (Bytef *) zrecvbuf, (uLong) compressed_size); @@ -182,7 +182,7 @@ void NetConnection::receive() } else { const char *zc = zunbuf; while (*zc) { - if (( *zc == '\n') || (*zc == '\r')) { + if ((*zc == '\n') || (*zc == '\r')) { if (messageblock.size()) { recvq.push_back(messageblock); messageblock.clear(); @@ -204,22 +204,22 @@ void NetConnection::receive() received_compressed_size = 0; compressed_size = 0; } - } else if (!messageblock.size() && (bytes_received > 3 ) && ( *c == '\xff') && (*(c+1) == '\xff')) { - - receive_compressed = true; - received_compressed_size = 0; - compressed_size = (uLong) (*(unsigned char *)(c+2) + (*(unsigned char *)(c+3) << 8)); - c += 3; - bytes_received -= 3; - memset(zrecvbuf, 0, sizeof(zrecvbuf)); - if (compressed_size > BLOCKSIZE) { - con_warn << "Incoming compressed datablock exceeds " << BLOCKSIZE << " bytes!\n"; - receive_compressed = false; - } + } else if (!messageblock.size() && (bytes_received > 3) && (*c == '\xff') && (*(c + 1) == '\xff')) { + + receive_compressed = true; + received_compressed_size = 0; + compressed_size = (uLong)(*(unsigned char *)(c + 2) + (*(unsigned char *)(c + 3) << 8)); + c += 3; + bytes_received -= 3; + memset(zrecvbuf, 0, sizeof(zrecvbuf)); + if (compressed_size > BLOCKSIZE) { + con_warn << "Incoming compressed datablock exceeds " << BLOCKSIZE << " bytes!\n"; + receive_compressed = false; + } - } else if (( *c == '\n') || (*c == '\r')) { + } else if ((*c == '\n') || (*c == '\r')) { if (messageblock.size()) { - recvq.push_back(messageblock); + recvq.push_back(messageblock); messageblock.clear(); } } else { @@ -243,7 +243,7 @@ void NetConnection::frame() timeout.tv_usec = 0; fd_set readset = clientset; - int nb = select(fd()+1, &readset, NULL, NULL, &timeout); + int nb = select(fd() + 1, &readset, NULL, NULL, &timeout); if (nb == 0) { if (connection_timeout + NETTIMEOUT < core::application()->time()) { con_error << "Connection timeout!\n"; @@ -266,7 +266,7 @@ void NetConnection::frame() parse_incoming_message(message); } - nb = select(fd()+1, &readset, NULL, NULL, &timeout); + nb = select(fd() + 1, &readset, NULL, NULL, &timeout); if (nb == 0) { return; } @@ -284,9 +284,9 @@ void NetConnection::transmit() if (error() || invalid()) return; - + if (!sendq.size()) { - if (connection_keepalive + NETTIMEOUT /2 < application()->time()) { + if (connection_keepalive + NETTIMEOUT / 2 < application()->time()) { sendq.assign("ping\n"); } else { return; @@ -296,18 +296,18 @@ void NetConnection::transmit() sendq.clear(); return; } - + ssize_t bytes_sent = 0; - + while (sendq.size()) { - bytes_sent = ::sendto(connection_fd, sendq.c_str(), sendq.size(), 0, (struct sockaddr *)&server_addr, sizeof(server_addr)); + bytes_sent = ::sendto(connection_fd, sendq.c_str(), sendq.size(), 0, (struct sockaddr *) & server_addr, sizeof(server_addr)); if (bytes_sent <= 0) { con_error << "Network send() error!" << std::endl; //perror("send"); abort(); return; } - + // assert (bytes_sent <= sendbuf.size()); sendq.erase(0, bytes_sent); Stats::network_bytes_sent += bytes_sent; @@ -334,7 +334,7 @@ void NetConnection::send_raw(std::string const &msg) * priv <text> */ -// send a "connect" message to the server +// send a "connect" message to the server void NetConnection::send_connect() { std::ostringstream msg; @@ -441,18 +441,18 @@ void NetConnection::send_info_request(Info *info) void NetConnection::parse_incoming_message(const std::string & message) { std::istringstream msgstream(message); - + std::string command; msgstream >> command; - + if (command == "msg") { std::string level; if (msgstream >> level) { - if (level =="info") { + if (level == "info") { if (message.size() > 9) { application()->notify_message(Message::Info, message.substr(9)); } - } else if (level =="rcon") { + } else if (level == "rcon") { if (message.size() > 9) { application()->notify_message(Message::RCon, message.substr(9)); } @@ -465,7 +465,7 @@ void NetConnection::parse_incoming_message(const std::string & message) // FIXME - separate sender nickname if (message.size() > 12) { application()->notify_message(Message::Private, message.substr(12)); - } + } } else if (level == "snd") { if (message.size() > 8) { application()->notify_sound(message.substr(8).c_str()); @@ -503,7 +503,7 @@ void NetConnection::parse_incoming_message(const std::string & message) if (msgstream >> id) { //con_debug << "Received die entity id " << id << std::endl; Entity *e = Entity::find(id); - if (localcontrol() == e) + if (localcontrol() == e) localplayer()->set_control(0); if (e) Entity::erase(id); @@ -525,26 +525,25 @@ void NetConnection::parse_incoming_message(const std::string & message) Entity *entity = Entity::find(id); if (!entity) { - switch (type) - { - case Entity::Default: - entity = new Entity(msgstream); - break; - case Entity::Dynamic: - entity = new EntityDynamic(msgstream); - break; - case Entity::Controlable: - entity = new EntityControlable(msgstream); - break; - case Entity::Globe: - entity = new EntityGlobe(msgstream); - break; - default: - con_warn << "Received create for unknown entity type " << type << "!" << std::endl; - return; - break; + switch (type) { + case Entity::Default: + entity = new Entity(msgstream); + break; + case Entity::Dynamic: + entity = new EntityDynamic(msgstream); + break; + case Entity::Controlable: + entity = new EntityControlable(msgstream); + break; + case Entity::Globe: + entity = new EntityGlobe(msgstream); + break; + default: + con_warn << "Received create for unknown entity type " << type << "!" << std::endl; + return; + break; } - + Entity::add(entity, id); } @@ -560,7 +559,7 @@ void NetConnection::parse_incoming_message(const std::string & message) con_warn << "Received menu for NULL entity!" << std::endl; return; } - + Entity *entity = Entity::find(id); if (!entity) { con_warn << "Received menu for unknown entity " << id << "!" << std::endl; @@ -591,7 +590,7 @@ void NetConnection::parse_incoming_message(const std::string & message) if (id) { //con_debug << "Received zone " << id << std::endl; Zone * zone = Zone::find(id); - + // create the zone if necessary if (!zone) { zone = new Zone(msgstream); @@ -618,18 +617,18 @@ void NetConnection::parse_incoming_message(const std::string & message) if (!player_id) { Zone *oldzone = connection()->localplayer()->zone(); connection()->localplayer()->receive_server_update(msgstream); - + //con_debug << "zone " << ( connection()->localplayer()->zone() ? connection()->localplayer()->zone()->id() : 0) << std::endl; - + if (connection()->localplayer()->zonechange() && oldzone && (oldzone != connection()->localplayer()->zone())) { - + // notify the applciation to clear none-core zone assets (textures etc) application()->notify_zonechange(); - + // delete all entities in the old zone - for (Entity::Registry::iterator it=Entity::registry().begin(); it != Entity::registry().end(); ) { + for (Entity::Registry::iterator it = Entity::registry().begin(); it != Entity::registry().end();) { Entity *entity = (*it).second; - + if ((entity->zone() == oldzone)) { delete entity; Entity::registry().erase(it++); @@ -640,7 +639,7 @@ void NetConnection::parse_incoming_message(const std::string & message) oldzone->content().clear(); } - // short "pif" message about a different player + // short "pif" message about a different player } else if (player_id != localplayer()->id()) { // find player @@ -648,7 +647,7 @@ void NetConnection::parse_incoming_message(const std::string & message) // search other players for (GameInterface::Players::iterator it = game()->players().begin(); it != game()->players().end() && !player; it++) { - if( (*it)->id() == player_id) { + if ((*it)->id() == player_id) { player = (*it); } } @@ -664,7 +663,7 @@ void NetConnection::parse_incoming_message(const std::string & message) } else if (command == "pid") { con_debug << "Received player disconnect info" << std::endl; - + int player_id; if (!(msgstream >> player_id)) { con_warn << "Received illegal player disconnect message!" << std::endl; @@ -680,7 +679,7 @@ void NetConnection::parse_incoming_message(const std::string & message) // search other players Player *player = 0; for (GameInterface::Players::iterator it = game()->players().begin(); it != game()->players().end() && !player; it++) { - if( (*it)->id() == player_id) { + if ((*it)->id() == player_id) { game()->players().erase(it); return; } @@ -691,9 +690,9 @@ void NetConnection::parse_incoming_message(const std::string & message) std::string label; char c; - while ( (msgstream.get(c)) && (c != '"')); - while ( (msgstream.get(c)) && (c != '"')) - label += c; + while ((msgstream.get(c)) && (c != '"')); + while ((msgstream.get(c)) && (c != '"')) + label += c; if (label.size()) { Info *info = Info::find(label); @@ -708,8 +707,7 @@ void NetConnection::parse_incoming_message(const std::string & message) con_warn << "Received empty information record!" << std::endl; } } else if (command == "sup") { - if (connection_state == Connected) - { + if (connection_state == Connected) { unsigned int id; if (msgstream >> id) { //con_debug << "Received update entity id " << id << std::endl; diff --git a/src/core/netconnection.h b/src/core/netconnection.h index 7c0b23d..36cf154 100644 --- a/src/core/netconnection.h +++ b/src/core/netconnection.h @@ -41,10 +41,10 @@ class NetConnection public: NetConnection(); virtual ~NetConnection(); - + /// connect to a remote host virtual void connect(std::string const &to_host, int to_port); - + /// disconnect from a remote host virtual void disconnect(); @@ -80,28 +80,46 @@ public: void abort(); - inline int fd() const { return connection_fd; } - - inline std::string host() const { return connection_host; } + inline int fd() const { + return connection_fd; + } + + inline std::string host() const { + return connection_host; + } - inline int port() const { return connection_port; } + inline int port() const { + return connection_port; + } - inline bool valid() const { return (connection_fd != -1); } + inline bool valid() const { + return (connection_fd != -1); + } - inline bool invalid() const { return (connection_fd == -1); } + inline bool invalid() const { + return (connection_fd == -1); + } - inline bool error() const { return connection_error; } + inline bool error() const { + return connection_error; + } - inline bool connected() const { return ((connection_fd != -1) && !connection_error); } + inline bool connected() const { + return ((connection_fd != -1) && !connection_error); + } - enum State {Connecting=0, Pending=1, Connected=2}; + enum State {Connecting = 0, Pending = 1, Connected = 2}; + + inline State state() const { + return connection_state; + } - inline State state() const { return connection_state; } - State connection_state; /// return the current game time - inline unsigned long timestamp() const { return connection_timestamp; } + inline unsigned long timestamp() const { + return connection_timestamp; + } protected: /// send a ping reply @@ -121,13 +139,13 @@ protected: /// parse an incoming message void parse_incoming_message(const std::string & message); - + private: - std::string messageblock; + std::string messageblock; std::deque<std::string> recvq; std::string sendq; fd_set clientset; - + float connection_timeout; float connection_keepalive; int connection_fd; diff --git a/src/core/netplayer.cc b/src/core/netplayer.cc index 0b3455f..0935b4c 100644 --- a/src/core/netplayer.cc +++ b/src/core/netplayer.cc @@ -37,7 +37,7 @@ void NetPlayer::message(const Message::Channel channel, const std::string text) return; std::string msg_channel; - switch(channel) { + switch (channel) { case core::Message::Info: // Info message msg_channel.assign("info"); break; @@ -53,7 +53,7 @@ void NetPlayer::message(const Message::Channel channel, const std::string text) case core::Message::Private: // Private chat message msg_channel.assign("private"); break; - + case core::Message::RCon: // RCon message msg_channel.assign("rcon"); break; @@ -63,7 +63,7 @@ void NetPlayer::message(const Message::Channel channel, const std::string text) return; break; } - + std::string msg("msg "); msg.append(msg_channel); msg += ' '; diff --git a/src/core/netplayer.h b/src/core/netplayer.h index 5659e2e..ada1bd0 100644 --- a/src/core/netplayer.h +++ b/src/core/netplayer.h @@ -22,10 +22,12 @@ namespace core class NetPlayer : public Player { public: - NetPlayer(NetClient *client); - virtual ~NetPlayer(); + NetPlayer(NetClient *client); + virtual ~NetPlayer(); - NetClient *client() { return player_client; } + NetClient *client() { + return player_client; + } virtual void message(const Message::Channel channel, const std::string text); virtual void sound(const std::string name); diff --git a/src/core/netserver.cc b/src/core/netserver.cc index 83bbd6e..1ae928b 100644 --- a/src/core/netserver.cc +++ b/src/core/netserver.cc @@ -34,7 +34,7 @@ #include "core/zone.h" #ifdef _WIN32 - typedef int socklen_t; +typedef int socklen_t; #endif namespace core @@ -56,13 +56,13 @@ NetServer::NetServer(std::string const host, unsigned int const port) return; } - + // Get the local adress to bind to netserver_addr.sin_family = AF_INET; netserver_addr.sin_port = htons(port); if (host.size()) { netserver_addr.sin_addr.s_addr = inet_addr(host.c_str()); - if ( netserver_addr.sin_addr.s_addr == INADDR_NONE) { + if (netserver_addr.sin_addr.s_addr == INADDR_NONE) { con_error << "Network invalid address " << host << "!" << std::endl; return; } @@ -70,14 +70,14 @@ NetServer::NetServer(std::string const host, unsigned int const port) netserver_addr.sin_addr.s_addr = htonl(INADDR_ANY); } memset(netserver_addr.sin_zero, '\0', sizeof(netserver_addr.sin_zero)); - + // bind the local address to the socket ( note the typecast) if (::bind(netserver_fd, (struct sockaddr *) &netserver_addr, sizeof(struct sockaddr)) == -1) { con_error << "Network can't bind to local address!" << std::endl; //perror("bind"); return; } - + con_print << " listening on " << inet_ntoa(netserver_addr.sin_addr) << ":" << ntohs(netserver_addr.sin_port) << std::endl; // add the listening socket to the file descriptor set @@ -101,13 +101,13 @@ NetServer::~NetServer() for (it = clients.begin(); it != clients.end(); it++) { // notify the game server - if ((*it)->state() == NetClient::Connected) + if ((*it)->state() == NetClient::Connected) server()->player_disconnect((*it)->player()); (*it)->send_raw(netmsg); (*it)->transmit(); - - delete (*it); + + delete(*it); } clients.clear(); @@ -120,7 +120,8 @@ NetServer::~NetServer() } } -void NetServer::abort() { +void NetServer::abort() +{ netserver_error = true; } @@ -138,8 +139,8 @@ NetClient *NetServer::find_client(Player const *player) // remove disconnected clients void NetServer::reap() { - for (Clients:: iterator it = clients.begin(); it != clients.end(); ) { - NetClient *client = *it; + for (Clients:: iterator it = clients.begin(); it != clients.end();) { + NetClient *client = *it; if (client->client_timeout + NETTIMEOUT < application()->time()) { // client timed out, send a disconnect @@ -157,8 +158,8 @@ void NetServer::reap() } } - if (client->error()) { - + if (client->error()) { + // notify other clients for (Clients::iterator cit = clients.begin(); cit != clients.end(); cit++) { if ((*cit) != (*it)) { @@ -172,13 +173,13 @@ void NetServer::reap() } // remove the client - delete client; + delete client; clients.erase(it++); - } else { + } else { ++it; } - } + } } void NetServer::receive() @@ -191,7 +192,7 @@ void NetServer::receive() timeout.tv_usec = 2500; fd_set readset = serverset; - int nb = select(fd()+1, &readset, NULL, NULL, &timeout); + int nb = select(fd() + 1, &readset, NULL, NULL, &timeout); if (nb == -1) { #ifndef _WIN32 // ncurses needs SIGWINCH catched @@ -204,13 +205,13 @@ void NetServer::receive() return; } - if (nb && FD_ISSET(fd(), &readset)) { + if (nb && FD_ISSET(fd(), &readset)) { // receive incoming data struct sockaddr_in client_addr; socklen_t client_addr_len = sizeof(client_addr); memset(recbuf, '\0', sizeof(recbuf)); - ssize_t bytes_received = ::recvfrom(fd(), recbuf, FRAMESIZE-1, 0, (struct sockaddr *)&client_addr, &client_addr_len); + ssize_t bytes_received = ::recvfrom(fd(), recbuf, FRAMESIZE - 1, 0, (struct sockaddr *) & client_addr, &client_addr_len); if (bytes_received == -1) { con_error << "Network error on recvfrom()!" << std::endl; this->abort(); @@ -221,19 +222,19 @@ void NetServer::receive() Stats::network_bytes_received += bytes_received; // originator - std::string client_host (inet_ntoa(client_addr.sin_addr)); + std::string client_host(inet_ntoa(client_addr.sin_addr)); unsigned int client_port = ntohs(client_addr.sin_port); - + // get messages from clients bool msg_received = false; for (Clients::iterator it = clients.begin(); it != clients.end() && !msg_received; it++) { NetClient *client = *it; - + if ((client->host() == client_host) && (client->port() == (int) client_port)) { // receive data client->receive(recbuf); - + // process parsed messages while (client->has_messages()) { std::string message; @@ -253,7 +254,7 @@ void NetServer::receive() if (client) { // receive data client->receive(recbuf); - + // process parsed messages while (client->has_messages()) { std::string message; @@ -264,7 +265,7 @@ void NetServer::receive() } } - + // remove dead connections reap(); } @@ -286,7 +287,8 @@ NetClient * NetServer::client_connect(std::string const host, int const port) return client; } -void NetServer::client_initialize(NetClient *client) { +void NetServer::client_initialize(NetClient *client) +{ // send welcome message std::string welcome("^B"); @@ -328,12 +330,12 @@ void NetServer::client_frame(NetClient *client, unsigned long timestamp) // send zone info send_zone_update(client, zone); - + // send entities in zone - if (client->player()->zone()) { + if (client->player()->zone()) { for (Zone::Content::iterator it = zone->content().begin(); it != zone->content().end(); it++) { Entity *entity = (*it); - + if (!entity->entity_destroyed) { send_entity_create(client, entity); } @@ -345,25 +347,25 @@ void NetServer::client_frame(NetClient *client, unsigned long timestamp) } else { // send a server frame marker send_frame_marker(client, timestamp); - + // send updates for entities in the zone for (Entity::Registry::iterator it = Entity::registry().begin(); it != Entity::registry().end(); it++) { Entity *entity = (*it).second; - if (entity->zone() == zone) { + if (entity->zone() == zone) { if (entity->entity_destroyed) { if (!entity->entity_created) { send_entity_delete(client, entity); } } else if (entity->entity_created) { send_entity_create(client, entity); - + } else if (entity->oldzone()) { // this entity has entered the zone send_entity_create(client, entity); - - } else if (entity->dirty() && !(entity->flags() & Entity::Static) ) { - + + } else if (entity->dirty() && !(entity->flags() & Entity::Static)) { + // FIXME only within visual range send_entity_update(client, entity); } @@ -408,7 +410,7 @@ void NetServer::frame(unsigned long timestamp) client->transmit(); } - + // clear dirty state for (Clients::iterator it = clients.begin(); it != clients.end(); it++) { NetClient *client = *it; @@ -468,7 +470,7 @@ void NetServer::send_frame_marker(NetClient *client, unsigned long timestamp) if (client->state() == NetClient::Connected) { client->send_raw(msg.str()); } - + } // send a "ent" create entity message to all clients @@ -533,7 +535,7 @@ void NetServer::send_player_update(NetClient *client) { std::ostringstream msg; msg << "pif 0 "; - client->player()->serialize_server_update(msg); + client->player()->serialize_server_update(msg); msg << '\n'; client->send_raw(msg.str()); } @@ -543,7 +545,7 @@ void NetServer::send_player_update(NetClient *client, Player *player) { std::ostringstream msg; msg << "pif " << player->id() << ' '; - player->serialize_short_server_update(msg); + player->serialize_short_server_update(msg); msg << '\n'; client->send_raw(msg.str()); } @@ -579,18 +581,18 @@ void NetServer::send_info_update(NetClient *client, Info *info) * ping * say <text> * priv <player> <text> - * + * */ -void NetServer::parse_incoming_message(NetClient *client, const std::string & message) +void NetServer::parse_incoming_message(NetClient *client, const std::string & message) { if (!message.size()) return; std::stringstream msgstream(message); - + std::string command; msgstream >> command; - + // disconnect if (command == "disconnect") { client->abort(); @@ -621,7 +623,7 @@ void NetServer::parse_incoming_message(NetClient *client, const std::string & me } else { std::string message("Unknown client protocol version!"); con_print << client->host() << ":" << client->port() << " " << message << std::endl; - + send_message(client, "info", message); send_disconnect(client); } @@ -662,8 +664,8 @@ void NetServer::parse_incoming_message(NetClient *client, const std::string & me // cmd if (command == "cmd") { - if (message.size() > command.size()+1) { - std::string cmdline(message.substr(command.size()+1)); + if (message.size() > command.size() + 1) { + std::string cmdline(message.substr(command.size() + 1)); server()->exec(client->player(), cmdline); } return; @@ -672,9 +674,9 @@ void NetServer::parse_incoming_message(NetClient *client, const std::string & me if (command == "inf") { std::string n; char c; - - while ( (msgstream.get(c)) && (c != '"')); - while ( (msgstream.get(c)) && (c != '"')) + + while ((msgstream.get(c)) && (c != '"')); + while ((msgstream.get(c)) && (c != '"')) n += c; if (n.size()) { @@ -687,21 +689,21 @@ void NetServer::parse_incoming_message(NetClient *client, const std::string & me } if (command == "rcon") { - if ((message.size() > command.size()+1) && Cvar::sv_password->str().size()) { + if ((message.size() > command.size() + 1) && Cvar::sv_password->str().size()) { if ((Cvar::sv_password->str().compare(client->player()->rconpassword()) == 0)) { - con_print << "^B" << client->player()->name() << "^F rcon: " << message.substr(command.size()+1) << std::endl; - + con_print << "^B" << client->player()->name() << "^F rcon: " << message.substr(command.size() + 1) << std::endl; + core::CommandBuffer::exec(); core::console()->set_rcon(true); - - core::cmd() << message.substr(command.size()+1) << "\n"; + + core::cmd() << message.substr(command.size() + 1) << "\n"; core::CommandBuffer::exec(); - - while(console()->rconbuf().size()) { + + while (console()->rconbuf().size()) { send_message(client, "rcon", (*console()->rconbuf().begin())); core::console()->rconbuf().pop_front(); } - + // disable rcon buffering console()->set_rcon(false); @@ -711,7 +713,7 @@ void NetServer::parse_incoming_message(NetClient *client, const std::string & me } } return; - + } // cup - client update entity if (command == "cup") { @@ -722,13 +724,13 @@ void NetServer::parse_incoming_message(NetClient *client, const std::string & me if (!entity) { con_warn << client->host() << ":" << client->port() << " update for unknown entity " << id << "\n"; return; - } + } if (entity->type() != Entity::Controlable) { con_warn << client->host() << ":" << client->port() << " update for non-controlable entity " << id << "\n"; return; } - + EntityControlable *entitycontrolable = (EntityControlable *)entity; if (entitycontrolable->owner() != client->player()) { @@ -737,27 +739,27 @@ void NetServer::parse_incoming_message(NetClient *client, const std::string & me } entitycontrolable->set_dirty(true); - entitycontrolable->receive_client_update(msgstream); + entitycontrolable->receive_client_update(msgstream); } return; } // say - if (command == "say") { - if (message.size() > command.size()+1) { - server()->say(client->player(), message.substr(command.size()+1)); + if (command == "say") { + if (message.size() > command.size() + 1) { + server()->say(client->player(), message.substr(command.size() + 1)); } return; } // priv if (command == "priv") { - if (message.size() > command.size()+1) { - server()->private_message(client->player(), message.substr(command.size()+1)); + if (message.size() > command.size() + 1) { + server()->private_message(client->player(), message.substr(command.size() + 1)); } return; } - + } } diff --git a/src/core/netserver.h b/src/core/netserver.h index e54ea2e..afbb5a0 100644 --- a/src/core/netserver.h +++ b/src/core/netserver.h @@ -21,7 +21,7 @@ #include "core/player.h" #include "core/info.h" -namespace core +namespace core { /// network server @@ -32,26 +32,34 @@ public: typedef std::list<NetClient *> Clients; /// create a new network server, listening on host:port - NetServer(std::string const host, unsigned int const port); + NetServer(std::string const host, unsigned int const port); /// disconnect clients and shutdown the network server - ~NetServer(); - -/*----- inspectors ------------------------------------------------ */ + ~NetServer(); + + /*----- inspectors ------------------------------------------------ */ /// Returns true if the TCP server has a valid file descriptor - inline bool valid() const { return netserver_fd != -1; } - + inline bool valid() const { + return netserver_fd != -1; + } + /// Returns true if the TCP server has an invalid file descriptor - inline bool invalid() const { return netserver_fd == -1; } - + inline bool invalid() const { + return netserver_fd == -1; + } + /// Returns the error state of the TCP server - inline bool error() const { return netserver_error; } + inline bool error() const { + return netserver_error; + } /// Return the socket file descriptor - inline int fd() const { return netserver_fd; } + inline int fd() const { + return netserver_fd; + } -/*----- mutators -------------------------------------------------- */ + /*----- mutators -------------------------------------------------- */ /// run a network server frame void frame(unsigned long timestamp); @@ -74,7 +82,7 @@ protected: /// send a create entity event void send_entity_create(NetClient *client, Entity *entity); - + /// broadcast a delete entity event void send_entity_delete(NetClient *client, Entity *entity); @@ -99,14 +107,14 @@ protected: /// set the error state void abort(); - /// called when a new client connects - NetClient *client_connect(std::string const host, int const port); + /// called when a new client connects + NetClient *client_connect(std::string const host, int const port); /// called when a client has send the intial handshake void client_initialize(NetClient *client); - /// remove terminated clients - void reap(); + /// remove terminated clients + void reap(); /// parse incoming client messages void parse_incoming_message(NetClient *client, const std::string & message); @@ -124,7 +132,7 @@ private: char recbuf[FRAMESIZE]; - Clients clients; + Clients clients; }; } diff --git a/src/core/parser.cc b/src/core/parser.cc index 84590a2..c5e0a38 100644 --- a/src/core/parser.cc +++ b/src/core/parser.cc @@ -8,7 +8,8 @@ #include "core/parser.h" #include "sys/sys.h" -namespace core { +namespace core +{ bool Parser::got_entity_key(filesystem::IniFile &inifile, core::Entity *entity) diff --git a/src/core/parser.h b/src/core/parser.h index 78a1087..06ddc27 100644 --- a/src/core/parser.h +++ b/src/core/parser.h @@ -11,10 +11,12 @@ #include "filesystem/inifile.h" #include "core/entity.h" -namespace core { +namespace core +{ /// general parser routines -class Parser { +class Parser +{ public: /// read default entity keys from an ini file static bool got_entity_key(filesystem::IniFile &inifile, core::Entity *entity); diff --git a/src/core/player.cc b/src/core/player.cc index 4276f20..e048b91 100644 --- a/src/core/player.cc +++ b/src/core/player.cc @@ -56,7 +56,7 @@ void Player::print() const if (zone()) { con_print << " zone ^B" << zone()->name() << std::endl; } - + } void Player::send(const std::string text) @@ -91,7 +91,7 @@ void Player::set_control(EntityControlable *entitycontrolable) player_dirty = true; } -void Player::set_zone(Zone *zone) +void Player::set_zone(Zone *zone) { if (zone != player_zone) { player_zone = zone; @@ -131,7 +131,8 @@ void Player::set_ping(const long ping) player_ping = ping; } -void Player::set_level(const int level) { +void Player::set_level(const int level) +{ player_level = level; } @@ -172,10 +173,10 @@ void Player::update_info() void Player::serialize_client_update(std::ostream & os) { - os << player_color << " " - << player_color_second << " " - << "\"" << player_name << "\" " - << "\"" << player_rconpassword << "\" "; + os << player_color << " " + << player_color_second << " " + << "\"" << player_name << "\" " + << "\"" << player_rconpassword << "\" "; } @@ -186,16 +187,16 @@ void Player::receive_client_update(std::istream &is) std::string n; char c; - while ( (is.get(c)) && (c != '"')); - while ( (is.get(c)) && (c != '"')) + while ((is.get(c)) && (c != '"')); + while ((is.get(c)) && (c != '"')) n += c; if (n.size()) player_name.assign(n); - + n.clear(); - while ( (is.get(c)) && (c != '"')); - while ( (is.get(c)) && (c != '"')) + while ((is.get(c)) && (c != '"')); + while ((is.get(c)) && (c != '"')) n += c; if (n.size()) @@ -209,14 +210,14 @@ void Player::serialize_server_update(std::ostream & os) const unsigned int control_id = (player_control ? player_control->id() : 0); unsigned int mission_id = (player_mission_target ? player_mission_target->id() : 0); - os << player_id << " " - << zone_id << " " - << view_id << " " - << control_id << " " - << mission_id << " " - << player_credits << " " - << player_level << " " - << player_ping; + os << player_id << " " + << zone_id << " " + << view_id << " " + << control_id << " " + << mission_id << " " + << player_credits << " " + << player_level << " " + << player_ping; } void Player::receive_server_update(std::istream &is) @@ -240,21 +241,21 @@ void Player::receive_server_update(std::istream &is) unsigned int control_id = 0; is >> control_id; - if (control_id) { + if (control_id) { Entity *e = Entity::find(control_id); if (e && e->type() == Entity::Controlable) { player_control = static_cast<EntityControlable *>(e); } else { player_control = 0; con_warn << "control set to unknown entity " << control_id << "\n"; - } + } } else { player_control = 0; } unsigned int mission_id = 0; is >> mission_id; - if (mission_id) { + if (mission_id) { player_mission_target = Entity::find(mission_id); if (!player_mission_target) { con_warn << "mission target set to unknown entity " << mission_id << "\n"; @@ -266,7 +267,7 @@ void Player::receive_server_update(std::istream &is) is >> player_credits; is >> player_level; is >> player_ping; - + /* std::string n; char c; @@ -283,13 +284,13 @@ void Player::serialize_short_server_update(std::ostream & os) const { unsigned int zone_id = (zone() ? zone()->id() : 0); - os << player_id << " " - << "\"" << player_name << "\" " - << zone_id << " " - << player_color << " " - << player_color_second << " " - << player_level << " " - << player_ping; + os << player_id << " " + << "\"" << player_name << "\" " + << zone_id << " " + << player_color << " " + << player_color_second << " " + << player_level << " " + << player_ping; } @@ -308,8 +309,8 @@ void Player::receive_short_server_update(std::istream &is) // read player name std::string n; char c; - while ( (is.get(c)) && (c != '"')); - while ( (is.get(c)) && (c != '"')) + while ((is.get(c)) && (c != '"')); + while ((is.get(c)) && (c != '"')) n += c; if (n.size()) @@ -361,7 +362,7 @@ void Player::remove_asset(unsigned int id) return; for (std::list<EntityControlable*>::iterator asset = assets.begin(); asset != assets.end(); asset++) { - if ( ((*asset)->id() == id) && ((*asset)->owner() == this) ) { + if (((*asset)->id() == id) && ((*asset)->owner() == this)) { //con_debug << " removing asset " << (*asset)->id() << " from player " << this->id() << std::endl; if ((*asset) == player_control) diff --git a/src/core/player.h b/src/core/player.h index fc6740d..20a3b2d 100644 --- a/src/core/player.h +++ b/src/core/player.h @@ -32,68 +32,100 @@ public: /// default destructor virtual ~Player(); -/*----- inspectors ------------------------------------------------ */ + /*----- inspectors ------------------------------------------------ */ /// id of the player - inline const int id() const { return player_id; } - + inline const int id() const { + return player_id; + } + /// name of the player - inline const std::string & name() const { return player_name; } + inline const std::string & name() const { + return player_name; + } /// dirty flag - inline const bool dirty() const { return player_dirty; } + inline const bool dirty() const { + return player_dirty; + } /// the entity the Player is currently controling - inline EntityControlable *control() const { return player_control; } + inline EntityControlable *control() const { + return player_control; + } /// the zone the player is currently in - inline Zone *zone() const { return player_zone; } + inline Zone *zone() const { + return player_zone; + } /// set the zone the player is currently in void set_zone(Zone *zone); - inline const bool zonechange() const { return player_zonechange; } + inline const bool zonechange() const { + return player_zonechange; + } /// player primary color - inline const math::Color & color() const { return player_color; } + inline const math::Color & color() const { + return player_color; + } /// player secondary color - inline const math::Color & color_second() const { return player_color_second; } + inline const math::Color & color_second() const { + return player_color_second; + } /// player has been muted by admin or console - inline const bool mute() const { return player_mute; } + inline const bool mute() const { + return player_mute; + } - inline const std::string &rconpassword() const { return player_rconpassword; } + inline const std::string &rconpassword() const { + return player_rconpassword; + } /// mission target - inline Entity *mission_target() { return player_mission_target; } + inline Entity *mission_target() { + return player_mission_target; + } /// view - inline Entity *view() { return player_view; } + inline Entity *view() { + return player_view; + } /// credits - inline long credits() const { return player_credits; } + inline long credits() const { + return player_credits; + } /// network ping - inline long ping() const { return player_ping; } + inline long ping() const { + return player_ping; + } /// returns true of the player has enough credits to pay amount - inline bool has_credits(const long amount) const { return (player_credits >= amount); } + inline bool has_credits(const long amount) const { + return (player_credits >= amount); + } /// print player info to console virtual void print() const; /// player level - const int level() const { return player_level; } + const int level() const { + return player_level; + } -/*----- messages -------------------------------------------------- */ + /*----- messages -------------------------------------------------- */ /// send a text message void send(const std::string text); /** * @brief send a warning message - * Send the player a warning message abd set the warning + * Send the player a warning message abd set the warning * message timestamp to the current application time * @see last_warning() */ @@ -104,10 +136,12 @@ public: virtual void message(core::Message::Channel channel, const std::string text); /// time of the last warning message - float last_warning() const { return player_warningtime; } + float last_warning() const { + return player_warningtime; + } + - -/*----- mutators -------------------------------------------------- */ + /*----- mutators -------------------------------------------------- */ /// serialize player info to a stream void serialize_server_update(std::ostream & os) const; @@ -176,12 +210,16 @@ public: void set_level(const int level); /// set the dirty bit - inline void set_dirty(const bool dirty = true) { player_dirty = dirty; } + inline void set_dirty(const bool dirty = true) { + player_dirty = dirty; + } /// set the zonechange bit - inline void set_zonechange(const bool dirty = true) { player_zonechange = dirty; } + inline void set_zonechange(const bool dirty = true) { + player_zonechange = dirty; + } -/* -- should actually not be public --*/ + /* -- should actually not be public --*/ /// id of the player int player_id; diff --git a/src/core/range.h b/src/core/range.h index d530f0b..a133695 100644 --- a/src/core/range.h +++ b/src/core/range.h @@ -7,22 +7,24 @@ #ifndef __INCLUDED_CORE_RANGE_H__ #define __INCLUDED_CORE_RANGE_H__ -namespace core { +namespace core +{ /** * @brief range and scale constants */ -namespace range { - /// maximal visible range (world distance) - /** This is the distance of the frustum far plane, - * the maximal distance at which entities can be drawn. - * the maximal radar range - * and the maximal range to send entity updates - */ - const float maxdistance = 1024.0f; +namespace range +{ +/// maximal visible range (world distance) +/** This is the distance of the frustum far plane, + * the maximal distance at which entities can be drawn. + * the maximal radar range + * and the maximal range to send entity updates + */ +const float maxdistance = 1024.0f; - /// detail/fx distance (world distance) - const float fxdistance = 256.0f; +/// detail/fx distance (world distance) +const float fxdistance = 256.0f; } } diff --git a/src/core/stats.cc b/src/core/stats.cc index 36e942f..f95c631 100644 --- a/src/core/stats.cc +++ b/src/core/stats.cc @@ -6,7 +6,8 @@ #include "core/stats.h" -namespace core { +namespace core +{ unsigned long Stats::network_bytes_sent = 0; unsigned long Stats::network_bytes_received = 0; @@ -19,4 +20,4 @@ void Stats::clear() }; } - + diff --git a/src/core/stats.h b/src/core/stats.h index 7bcad0d..db65f81 100644 --- a/src/core/stats.h +++ b/src/core/stats.h @@ -11,7 +11,8 @@ namespace core { /// class to gather various engine statistics -class Stats { +class Stats +{ public: /// clear statistics static void clear(); diff --git a/src/core/timer.cc b/src/core/timer.cc index b614af1..6f2e914 100644 --- a/src/core/timer.cc +++ b/src/core/timer.cc @@ -1,7 +1,7 @@ /* core/timer.cc - This file is part of the Osirion project and is distributed under - the terms and conditions of the GNU General Public License version 2 + This file is part of the Osirion project and is distributed under + the terms and conditions of the GNU General Public License version 2 */ #include "core/timer.h" @@ -10,12 +10,13 @@ #include <iostream> #include <cmath> -namespace core { +namespace core +{ Timer::Timer() { gettimeofday(&this->timer_tick, &this->timer_tz); - this->timer_elapsed = 0; + this->timer_elapsed = 0; } Timer::~Timer() @@ -28,12 +29,12 @@ void Timer::mark() } unsigned long Timer::timestamp() -{ +{ struct timeval tick; struct timezone tick_tz; - + gettimeofday(&tick, &tick_tz); - + // calculate elapsed time in 10^-6 seconds unsigned long delta = 0; delta = tick.tv_sec * 1000 + tick.tv_usec / 1000; diff --git a/src/core/timer.h b/src/core/timer.h index b878875..5157811 100644 --- a/src/core/timer.h +++ b/src/core/timer.h @@ -1,7 +1,7 @@ /* core/timer.h - This file is part of the Osirion project and is distributed under - the terms and conditions of the GNU General Public License version 2 + This file is part of the Osirion project and is distributed under + the terms and conditions of the GNU General Public License version 2 */ #ifndef __INCLUDED_CORE_TIMER_H__ @@ -9,13 +9,15 @@ #include <sys/time.h> -namespace core { +namespace core +{ /// a timer measures intervals in seconds /*! A timer class measures the time elapsed * between the last two calls to its mark() function. */ -class Timer { +class Timer +{ public: /// Constructor Timer(); @@ -25,7 +27,7 @@ public: /// mark the current time as zero /*! Reset the timer, all subsequent calls too elapsed() will * use the current timestamp as reference - */ + */ void mark(); /*! return the time elapsed since the last mark, in seconds diff --git a/src/core/zone.cc b/src/core/zone.cc index 3567090..ac3bc4d 100644 --- a/src/core/zone.cc +++ b/src/core/zone.cc @@ -58,13 +58,13 @@ Zone *Zone::find(std::string const & name) Zone *Zone::search(std::string const & searchname) { - std::string strsearchkey(aux::lowercase(searchname)); + std::string strsearchkey(aux::lowercase(searchname)); std::stringstream str(strsearchkey); unsigned int id; if (str >> id) return find(id); - + if (strsearchkey.size() < 3) { return 0; } @@ -79,7 +79,7 @@ Zone *Zone::search(std::string const & searchname) if (label.size() && (label.find(strsearchkey) != std::string::npos)) { return zone; } - + name.assign(aux::lowercase(zone->name())); if (name.size() && (name.find(strsearchkey) != std::string::npos)) { return zone; @@ -101,7 +101,7 @@ void Zone::list() void Zone ::clear() { for (Registry::iterator it = zone_registry.begin(); it != zone_registry.end(); it++) { - delete (*it).second; + delete(*it).second; } zone_registry.clear(); @@ -109,7 +109,7 @@ void Zone ::clear() /* ---- class Zone ------------------------------------------------- */ Zone::Zone(std::string const & label) : - zone_label(label) + zone_label(label) { zone_id = 0; zone_name.clear(); @@ -139,10 +139,10 @@ void Zone::print() for (Content::iterator it = zone_content.begin(); it != zone_content.end(); it++) { Entity *entity = (*it); con_print << " id " << std::setw(4) << entity->id() - << " type " << std::setw(4) << entity->type() - << ":" << std::setw(4) << entity->moduletype() - << " " << std::setw(24) << entity->label() - << " ^B" << entity->name() << "^N" << std::endl; + << " type " << std::setw(4) << entity->type() + << ":" << std::setw(4) << entity->moduletype() + << " " << std::setw(24) << entity->label() + << " ^B" << entity->name() << "^N" << std::endl; } con_print << zone_content.size() << " registered zone entities" << std::endl; } @@ -197,7 +197,7 @@ Entity *Zone::find_entity(const std::string & label) Entity *Zone::search_entity(const std::string & searchname) { - std::string strsearchkey(aux::lowercase(searchname)); + std::string strsearchkey(aux::lowercase(searchname)); std::stringstream str(strsearchkey); unsigned int id; @@ -218,7 +218,7 @@ Entity *Zone::search_entity(const std::string & searchname) if (label.size() && (label.find(strsearchkey) != std::string::npos)) { return entity; } - + name.assign(aux::lowercase(entity->name())); if (name.size() && (name.find(strsearchkey) != std::string::npos)) { return entity; @@ -233,27 +233,27 @@ void Zone::serialize_server_update(std::ostream & os) const os << zone_label << " "; os << "\"" << zone_name << "\" "; os << "\"" << zone_sky << "\" "; - os << (zone_defaultview ? zone_defaultview->id() : 0 ); + os << (zone_defaultview ? zone_defaultview->id() : 0); } void Zone::receive_server_update(std::istream &is) { is >> zone_label; - + std::string n; unsigned int id = 0; char c; - while ( (is.get(c)) && (c != '"')); - while ( (is.get(c)) && (c != '"')) - n += c; + while ((is.get(c)) && (c != '"')); + while ((is.get(c)) && (c != '"')) + n += c; zone_name.assign(n); n.clear(); - while ( (is.get(c)) && (c != '"')); - while ( (is.get(c)) && (c != '"')) - n += c; + while ((is.get(c)) && (c != '"')); + while ((is.get(c)) && (c != '"')) + n += c; zone_sky.assign(n); n.clear(); diff --git a/src/core/zone.h b/src/core/zone.h index 32463df..6048a99 100644 --- a/src/core/zone.h +++ b/src/core/zone.h @@ -11,7 +11,8 @@ #include <list> #include <map> -namespace core { +namespace core +{ class Zone; @@ -23,7 +24,8 @@ namespace core { /// a Zone contains a compartment of the game universe -class Zone { +class Zone +{ public: /// type definition for the content of a zone typedef std::list<Entity *> Content; @@ -58,8 +60,10 @@ public: static void clear(); /// the zone registry - static inline Registry & registry() { return zone_registry; } - + static inline Registry & registry() { + return zone_registry; + } + /* ---- Zone class ----------------------------------------- */ /// create a new zone @@ -77,22 +81,34 @@ public: void print(); /// zone id - inline unsigned int id() const { return zone_id; } + inline unsigned int id() const { + return zone_id; + } /// zone label - inline std::string const & label() const { return zone_label; } + inline std::string const & label() const { + return zone_label; + } /// zone name - inline std::string const & name() const { return zone_name; } + inline std::string const & name() const { + return zone_name; + } /// the name of the texture to be used as sky for this zone - inline std::string const & sky() const { return zone_sky; } + inline std::string const & sky() const { + return zone_sky; + } /// texture id for the sky - inline size_t sky_texture() const { return zone_sky_texture; } + inline size_t sky_texture() const { + return zone_sky_texture; + } /// default zone view - inline Entity *default_view() {return zone_defaultview; } + inline Entity *default_view() { + return zone_defaultview; + } /// find an entity inside a zone Entity *find_entity(Entity *entity); @@ -109,19 +125,29 @@ public: /* ---- mutators ------------------------------------------- */ /// set the Zone label - inline void set_label(std::string const & label) { zone_label.assign(label); } + inline void set_label(std::string const & label) { + zone_label.assign(label); + } /// set the Zone label - inline void set_name(std::string const & name) { zone_name.assign(name); } + inline void set_name(std::string const & name) { + zone_name.assign(name); + } /// set the sky texture name to be used for this zone - inline void set_sky(std::string const & sky) { zone_sky.assign(sky); } + inline void set_sky(std::string const & sky) { + zone_sky.assign(sky); + } /// set the texture id for the sky - inline void set_sky_texture(size_t texture) { zone_sky_texture = texture; } + inline void set_sky_texture(size_t texture) { + zone_sky_texture = texture; + } ///set the default view - inline void set_default_view(Entity *entity) { zone_defaultview = entity; } + inline void set_default_view(Entity *entity) { + zone_defaultview = entity; + } /* ---- serializers ---------------------------------------- */ @@ -134,7 +160,9 @@ public: /* ---- zone content --------------------------------------- */ /// the entities belonging to this zone - inline Content & content() { return zone_content; } + inline Content & content() { + return zone_content; + } /// add an entity to this zone void add(Entity *entity); |