/* ************************************************************************* ArmageTron -- Just another Tron Lightcycle Game in 3D. Copyright (C) 2000 Manuel Moos (manuel@moosnet.de) ************************************************************************** This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *************************************************************************** */ #ifndef ArmageTron_NET_CONFIGURATION_H #define ArmageTron_NET_CONFIGURATION_H #include "tConfiguration.h" #include "nNetwork.h" template inline bool sn_compare(T&a, T&b) { return (a!=b); } inline bool sn_compare(float&a, float &b) { return (1000 * fabs(a-b) > fabs(a) + fabs(b)); } class nConfItemBase:public virtual tConfItemBase{ protected: nConfItemBase(); public: // nConfItemBase(const char *title,const char *help); nConfItemBase(const char *title); virtual ~nConfItemBase(); virtual void NetReadVal(nMessage &m)=0; virtual void NetWriteVal(nMessage &m)=0; static void s_GetConfigMessage(nMessage &m); virtual void WasChanged(); virtual bool Writable(); static void s_SendConfig(bool force=true, int peer=-1); void SendConfig(bool force=true, int peer=-1); }; template class nConfItem : public nConfItemBase, public tConfItem, public virtual tConfItemBase { protected: nConfItem(T& t) :tConfItemBase(""), tConfItem("", t){} public: nConfItem(const char *title,const char *help,T& t) :tConfItem(t), tConfItemBase(title, help ){} virtual ~nConfItem(){} virtual void NetReadVal(nMessage &m){ T dummy=0; m >> dummy; if (sn_compare(dummy,*this->target)){ if (printChange) { tOutput o; o.SetTemplateParameter(1, title); o.SetTemplateParameter(2, *this->target); o.SetTemplateParameter(3, dummy); o << "$nconfig_value_changed"; con << con.ColorString(1,.3,.3) << o; } *this->target=dummy; changed=true; } } virtual void NetWriteVal(nMessage &m){ m << *this->target; } void Set( const T& newval ) { bool changed = ( newval != *this->target ); *this->target = newval; if ( changed ) { WasChanged(); } } private: void WasChanged() { nConfItemBase::WasChanged(); } }; template class nSettingItem:public nConfItem{ private: public: // nSettingItem(const char *title,const char *help,T& t) // :nConfItem(t), tConfItemBase(title, help){} // virtual ~nSettingItem(){} nSettingItem(const char *title,T& t) :tConfItemBase(title), nConfItem(t){} virtual ~nSettingItem(){} virtual bool Save(){return false;} }; class nConfItemLine:public nConfItem{ protected: public: // nConfItemLine(const char *title,const tOutput &help,tString &s) // :nConfItem(s), tConfItemBase(title,help){}; nConfItemLine(const char *title,tString &s) :tConfItemBase(title),nConfItem(s){}; virtual ~nConfItemLine(){} virtual void ReadVal(std::istream &s); }; #endif