Changeset 1495 for code/branches
- Timestamp:
- Jun 1, 2008, 1:10:46 AM (16 years ago)
- Location:
- code/branches/network/src
- Files:
-
- 65 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/network/src/audio/AudioBuffer.cc
r1494 r1495 1 1 /* 2 2 * ORXONOX - the hottest 3D action shooter ever to exist 3 * > www.orxonox.net < * 3 * > www.orxonox.net < 4 * 4 5 * 5 6 * License notice: -
code/branches/network/src/audio/AudioBuffer.h
r1494 r1495 1 1 /* 2 2 * ORXONOX - the hottest 3D action shooter ever to exist 3 * > www.orxonox.net < * 3 * > www.orxonox.net < 4 * 4 5 * 5 6 * License notice: -
code/branches/network/src/audio/AudioIncludes.h
r1494 r1495 1 1 /* 2 2 * ORXONOX - the hottest 3D action shooter ever to exist 3 * > www.orxonox.net < * 3 * > www.orxonox.net < 4 * 4 5 * 5 6 * License notice: … … 26 27 */ 27 28 28 /** @file @brief Various headers used in the audio lib. Avoid including this to increase accuracy of header file dependencies.*/ 29 /** 30 @file 31 @brief Various headers used in the audio lib. Avoid including this to 32 increase accuracy of header file dependencies. 33 */ 34 29 35 #include "AudioPrereqs.h" 30 36 -
code/branches/network/src/audio/AudioManager.cc
r1494 r1495 1 1 /* 2 2 * ORXONOX - the hottest 3D action shooter ever to exist 3 * > www.orxonox.net < * 3 * > www.orxonox.net < 4 * 4 5 * 5 6 * License notice: -
code/branches/network/src/audio/AudioManager.h
r1494 r1495 1 1 /* 2 2 * ORXONOX - the hottest 3D action shooter ever to exist 3 * > www.orxonox.net < * 3 * > www.orxonox.net < 4 * 4 5 * 5 6 * License notice: -
code/branches/network/src/audio/AudioPrereqs.h
r1494 r1495 1 1 /* 2 2 * ORXONOX - the hottest 3D action shooter ever to exist 3 * > www.orxonox.net < * 3 * > www.orxonox.net < 4 * 4 5 * 5 6 * License notice: … … 36 37 #include "util/OrxonoxPlatform.h" 37 38 38 //-----------------------------------------------------------------------// Shared library settings//-----------------------------------------------------------------------#if (ORXONOX_PLATFORM == ORXONOX_PLATFORM_WIN32) && !defined( AUDIO_STATIC_BUILD )# ifdef AUDIO_SHARED_BUILD# define _AudioExport __declspec(dllexport)# else# if defined( __MINGW32__ )# define _AudioExport# else# define _AudioExport __declspec(dllimport)# endif# endif#elif defined ( ORXONOX_GCC_VISIBILITY )# define _AudioExport __attribute__ ((visibility("default")))#else# define _AudioExport#endif 39 //-----------------------------------------------------------------------// Forward declarations//----------------------------------------------------------------------- 39 //----------------------------------------------------------------------- 40 // Shared library settings 41 //----------------------------------------------------------------------- 42 #if (ORXONOX_PLATFORM == ORXONOX_PLATFORM_WIN32) && !defined( AUDIO_STATIC_BUILD ) 43 # ifdef AUDIO_SHARED_BUILD 44 # define _AudioExport __declspec(dllexport) 45 # else 46 # if defined( __MINGW32__ ) 47 # define _AudioExport 48 # else 49 # define _AudioExport __declspec(dllimport) 50 # endif 51 # endif 52 #elif defined ( ORXONOX_GCC_VISIBILITY ) 53 # define _AudioExport __attribute__ ((visibility("default"))) 54 #else 55 # define _AudioExport 56 #endif 57 58 59 //----------------------------------------------------------------------- 60 // Forward declarations 61 //----------------------------------------------------------------------- 40 62 namespace audio 41 63 { … … 46 68 } 47 69 48 //-----------------------------------------------------------------------// Warnings//----------------------------------------------------------------------- 70 //----------------------------------------------------------------------- 71 // Warnings 72 //----------------------------------------------------------------------- 49 73 #if ORXONOX_COMPILER == ORXONOX_COMPILER_MSVC 50 74 51 // set to 4: conversion from 'ogg_int64_t' to 'long', possible loss of data#pragma warning (4 : 4244)#endif 75 // set to 4: conversion from 'ogg_int64_t' to 'long', possible loss of data 76 #pragma warning (4 : 4244) 77 78 #endif 79 52 80 53 81 #endif /* _AudioPrereqs_H__ */ -
code/branches/network/src/audio/AudioSource.cc
r1494 r1495 1 1 /* 2 2 * ORXONOX - the hottest 3D action shooter ever to exist 3 * > www.orxonox.net < * 3 * > www.orxonox.net < 4 * 4 5 * 5 6 * License notice: -
code/branches/network/src/audio/AudioSource.h
r1494 r1495 1 1 /* 2 2 * ORXONOX - the hottest 3D action shooter ever to exist 3 * > www.orxonox.net < * 3 * > www.orxonox.net < 4 * 4 5 * 5 6 * License notice: -
code/branches/network/src/audio/AudioStream.h
r1494 r1495 1 1 /* 2 2 * ORXONOX - the hottest 3D action shooter ever to exist 3 * > www.orxonox.net < * 3 * > www.orxonox.net < 4 * 4 5 * 5 6 * License notice: … … 26 27 */ 27 28 28 #ifndef _AudioStream_H__#define _AudioStream_H__ 29 #ifndef _AudioStream_H__ 30 #define _AudioStream_H__ 31 29 32 #include "AudioPrereqs.h" 30 33 … … 35 38 #include <vorbis/vorbisfile.h> 36 39 #include <vorbis/codec.h> 37 namespace audio{ #define BUFFER_SIZE (4096 * 4) class _AudioExport AudioStream { public: AudioStream(std::string path); void open(); void release(); void display(); bool playback(); bool playing(); bool update(); inline bool isLoaded() { return loaded; } 38 protected: bool stream(ALuint buffer); void empty(); void check(); std::string errorString(int code); private: std::string path; 39 FILE* oggFile; OggVorbis_File oggStream; vorbis_info* vorbisInfo; vorbis_comment* vorbisComment; bool loaded; 40 ALuint buffers[2]; ALuint source; ALenum format; };}#endif /* _AudioStream_H__ */ 40 41 namespace audio 42 { 43 #define BUFFER_SIZE (4096 * 4) 44 45 class _AudioExport AudioStream 46 { 47 public: 48 AudioStream(std::string path); 49 void open(); 50 void release(); 51 void display(); 52 bool playback(); 53 bool playing(); 54 bool update(); 55 inline bool isLoaded() { return loaded; } 56 57 protected: 58 bool stream(ALuint buffer); 59 void empty(); 60 void check(); 61 std::string errorString(int code); 62 63 private: 64 std::string path; 65 66 FILE* oggFile; 67 OggVorbis_File oggStream; 68 vorbis_info* vorbisInfo; 69 vorbis_comment* vorbisComment; 70 bool loaded; 71 72 ALuint buffers[2]; 73 ALuint source; 74 ALenum format; 75 }; 76 } 77 78 #endif /* _AudioStream_H__ */ -
code/branches/network/src/core/Error.cc
r1494 r1495 1 1 /* 2 2 * ORXONOX - the hottest 3D action shooter ever to exist 3 * > www.orxonox.net < * 3 * > www.orxonox.net < 4 * 4 5 * 5 6 * License notice: … … 25 26 * 26 27 */ 27 /** @file Error.cc @brief Implementation of the Error class.*/ 28 29 /** 30 @file Error.cc 31 @brief Implementation of the Error class. 32 */ 33 28 34 #include "Error.h" 29 35 #include "Debug.h" 36 30 37 namespace orxonox 31 38 { -
code/branches/network/src/core/Error.h
r1494 r1495 1 /* * ORXONOX - the hottest 3D action shooter ever to exist * > www.orxonox.net < * * * License notice: * * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * * Author: * Nicolas Perrenoud * Co-authors: * ... * *//** @file Error.h @brief Definition of the Error class.*/#ifndef _Error_H__ 1 /* 2 * ORXONOX - the hottest 3D action shooter ever to exist 3 * > www.orxonox.net < 4 * 5 * 6 * License notice: 7 * 8 * This program is free software; you can redistribute it and/or 9 * modify it under the terms of the GNU General Public License 10 * as published by the Free Software Foundation; either version 2 11 * of the License, or (at your option) any later version. 12 * 13 * This program is distributed in the hope that it will be useful, 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 * GNU General Public License for more details. 17 * 18 * You should have received a copy of the GNU General Public License 19 * along with this program; if not, write to the Free Software 20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 21 * 22 * Author: 23 * Nicolas Perrenoud 24 * Co-authors: 25 * ... 26 * 27 */ 28 29 /** 30 @file Error.h 31 @brief Definition of the Error class. 32 */ 33 34 #ifndef _Error_H__ 2 35 #define _Error_H__ 3 36 4 #include "CorePrereqs.h"#include <string> 37 #include "CorePrereqs.h" 38 39 #include <string> 40 5 41 namespace orxonox 6 42 { -
code/branches/network/src/core/Functor.h
r1494 r1495 1 /* * ORXONOX - the hottest 3D action shooter ever to exist * > www.orxonox.net < * * * License notice: * * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * * Author: * Fabian 'x3n' Landau * Co-authors: * ... * * Inspiration: Functor by Benjamin Grauer */#ifndef _Functor_H__#define _Functor_H__#include "CorePrereqs.h"#include "util/MultiTypeMath.h"#include "Debug.h"#define MAX_FUNCTOR_ARGUMENTS 5namespace orxonox{ enum FunctionType { FT_MEMBER, FT_CONSTMEMBER, FT_STATIC }; template <class T> inline std::string typeToString() { return "unknown"; }#define CreateTypeToStringTemplate(type) \ template <> \ inline std::string typeToString<type>() { return #type; } \ template <> \ inline std::string typeToString<type&>() { return #type; } \ template <> \ inline std::string typeToString<const type>() { return #type; } \ template <> \ inline std::string typeToString<const type&>() { return #type; } CreateTypeToStringTemplate(int); CreateTypeToStringTemplate(unsigned int); CreateTypeToStringTemplate(char); CreateTypeToStringTemplate(unsigned char); CreateTypeToStringTemplate(short); CreateTypeToStringTemplate(unsigned short); CreateTypeToStringTemplate(long); CreateTypeToStringTemplate(unsigned long); CreateTypeToStringTemplate(float); CreateTypeToStringTemplate(double); CreateTypeToStringTemplate(long double); CreateTypeToStringTemplate(bool); CreateTypeToStringTemplate(Vector2); CreateTypeToStringTemplate(Vector3); CreateTypeToStringTemplate(Quaternion); CreateTypeToStringTemplate(ColourValue); CreateTypeToStringTemplate(Radian); CreateTypeToStringTemplate(Degree); template <> \ inline std::string typeToString<std::string>() { return "string"; } \ template <> \ inline std::string typeToString<std::string&>() { return "string"; } \ template <> \ inline std::string typeToString<const std::string>() { return "string"; } \ template <> \ inline std::string typeToString<const std::string&>() { return "string"; } class _CoreExport Functor { public: Functor() {} virtual ~Functor() {} virtual void operator()(const MultiTypeMath& param1 = MT_null, const MultiTypeMath& param2 = MT_null, const MultiTypeMath& param3 = MT_null, const MultiTypeMath& param4 = MT_null, const MultiTypeMath& param5 = MT_null) = 0; inline unsigned int getParamCount() const { return this->numParams_; } inline bool hasReturnvalue() const { return this->hasReturnValue_; } inline FunctionType getType() const { return this->type_; } inline MultiTypeMath getReturnvalue() const { return this->returnedValue_; } std::string getTypenameParam(unsigned int param) const { return (param >= 0 && param < 5) ? this->typeParam_[param] : ""; } std::string getTypenameReturnvalue() const { return this->typeReturnvalue_; } virtual void evaluateParam(unsigned int index, MultiTypeMath& param) const = 0; protected: unsigned int numParams_; bool hasReturnValue_; FunctionType type_; MultiTypeMath returnedValue_; std::string typeReturnvalue_; std::string typeParam_[MAX_FUNCTOR_ARGUMENTS]; }; class _CoreExport FunctorStatic : public Functor { public: virtual ~FunctorStatic() {} virtual void operator()(const MultiTypeMath& param1 = MT_null, const MultiTypeMath& param2 = MT_null, const MultiTypeMath& param3 = MT_null, const MultiTypeMath& param4 = MT_null, const MultiTypeMath& param5 = MT_null) = 0; }; template <class T> class FunctorMember : public Functor { public: FunctorMember() { constObject_ = 0; object_ = 0; bConstObject_ = false; } virtual ~FunctorMember() {} virtual void operator()(T* object, const MultiTypeMath& param1 = MT_null, const MultiTypeMath& param2 = MT_null, const MultiTypeMath& param3 = MT_null, const MultiTypeMath& param4 = MT_null, const MultiTypeMath& param5 = MT_null) = 0; virtual void operator()(const T* object, const MultiTypeMath& param1 = MT_null, const MultiTypeMath& param2 = MT_null, const MultiTypeMath& param3 = MT_null, const MultiTypeMath& param4 = MT_null, const MultiTypeMath& param5 = MT_null) = 0; virtual void operator()(const MultiTypeMath& param1 = MT_null, const MultiTypeMath& param2 = MT_null, const MultiTypeMath& param3 = MT_null, const MultiTypeMath& param4 = MT_null, const MultiTypeMath& param5 = MT_null) { if (this->bConstObject_) { if (this->constObject_) (*this)(this->constObject_, param1, param2, param3, param4, param5); else { COUT(1) << "An error occurred in Functor.h:" << std::endl; COUT(1) << "Error: No const object set." << std::endl; } } else { if (this->object_) (*this)(this->object_, param1, param2, param3, param4, param5); else { COUT(1) << "An error occurred in Functor.h:" << std::endl; COUT(1) << "Error: No object set." << std::endl; } } } void setObject(T* object) { this->bConstObject_ = false; this->object_ = object; } void setObject(const T* object) { this->bConstObject_ = true; this->constObject_ = object; } private: const T* constObject_; T* object_; bool bConstObject_; };#define FUNCTOR_TEMPLATE(ismember, returnvalue, numparams) FUNCTOR_TEMPLATE##ismember##returnvalue##numparams#define FUNCTOR_TEMPLATE000#define FUNCTOR_TEMPLATE001 template <class P1>#define FUNCTOR_TEMPLATE002 template <class P1, class P2>#define FUNCTOR_TEMPLATE003 template <class P1, class P2, class P3>#define FUNCTOR_TEMPLATE004 template <class P1, class P2, class P3, class P4>#define FUNCTOR_TEMPLATE005 template <class P1, class P2, class P3, class P4, class P5>#define FUNCTOR_TEMPLATE010 template <class R>#define FUNCTOR_TEMPLATE011 template <class R, class P1>#define FUNCTOR_TEMPLATE012 template <class R, class P1, class P2>#define FUNCTOR_TEMPLATE013 template <class R, class P1, class P2, class P3>#define FUNCTOR_TEMPLATE014 template <class R, class P1, class P2, class P3, class P4>#define FUNCTOR_TEMPLATE015 template <class R, class P1, class P2, class P3, class P4, class P5>#define FUNCTOR_TEMPLATE100 template <class T>#define FUNCTOR_TEMPLATE101 template <class T, class P1>#define FUNCTOR_TEMPLATE102 template <class T, class P1, class P2>#define FUNCTOR_TEMPLATE103 template <class T, class P1, class P2, class P3>#define FUNCTOR_TEMPLATE104 template <class T, class P1, class P2, class P3, class P4>#define FUNCTOR_TEMPLATE105 template <class T, class P1, class P2, class P3, class P4, class P5>#define FUNCTOR_TEMPLATE110 template <class T, class R>#define FUNCTOR_TEMPLATE111 template <class T, class R, class P1>#define FUNCTOR_TEMPLATE112 template <class T, class R, class P1, class P2>#define FUNCTOR_TEMPLATE113 template <class T, class R, class P1, class P2, class P3>#define FUNCTOR_TEMPLATE114 template <class T, class R, class P1, class P2, class P3, class P4>#define FUNCTOR_TEMPLATE115 template <class T, class R, class P1, class P2, class P3, class P4, class P5>#define FUNCTOR_TEMPLATE_CLASSES(ismember, returnvalue, numparams) FUNCTOR_TEMPLATE_CLASSES##ismember##returnvalue##numparams#define FUNCTOR_TEMPLATE_CLASSES000#define FUNCTOR_TEMPLATE_CLASSES001 <P1>#define FUNCTOR_TEMPLATE_CLASSES002 <P1, P2>#define FUNCTOR_TEMPLATE_CLASSES003 <P1, P2, P3>#define FUNCTOR_TEMPLATE_CLASSES004 <P1, P2, P3, P4>#define FUNCTOR_TEMPLATE_CLASSES005 <P1, P2, P3, P4, P5>#define FUNCTOR_TEMPLATE_CLASSES010 <R>#define FUNCTOR_TEMPLATE_CLASSES011 <R, P1>#define FUNCTOR_TEMPLATE_CLASSES012 <R, P1, P2>#define FUNCTOR_TEMPLATE_CLASSES013 <R, P1, P2, P3>#define FUNCTOR_TEMPLATE_CLASSES014 <R, P1, P2, P3, P4>#define FUNCTOR_TEMPLATE_CLASSES015 <R, P1, P2, P3, P4, P5>#define FUNCTOR_TEMPLATE_CLASSES100 <T>#define FUNCTOR_TEMPLATE_CLASSES101 <T, P1>#define FUNCTOR_TEMPLATE_CLASSES102 <T, P1, P2>#define FUNCTOR_TEMPLATE_CLASSES103 <T, P1, P2, P3>#define FUNCTOR_TEMPLATE_CLASSES104 <T, P1, P2, P3, P4>#define FUNCTOR_TEMPLATE_CLASSES105 <T, P1, P2, P3, P4, P5>#define FUNCTOR_TEMPLATE_CLASSES110 <T, R>#define FUNCTOR_TEMPLATE_CLASSES111 <T, R, P1>#define FUNCTOR_TEMPLATE_CLASSES112 <T, R, P1, P2>#define FUNCTOR_TEMPLATE_CLASSES113 <T, R, P1, P2, P3>#define FUNCTOR_TEMPLATE_CLASSES114 <T, R, P1, P2, P3, P4>#define FUNCTOR_TEMPLATE_CLASSES115 <T, R, P1, P2, P3, P4, P5>#define FUNCTOR_TYPENAME_PARAMS(numparams) FUNCTOR_TYPENAME_PARAMS##numparams#define FUNCTOR_TYPENAME_PARAMS0#define FUNCTOR_TYPENAME_PARAMS1 this->typeParam_[0] = typeToString<P1>();#define FUNCTOR_TYPENAME_PARAMS2 this->typeParam_[0] = typeToString<P1>(); this->typeParam_[1] = typeToString<P2>();#define FUNCTOR_TYPENAME_PARAMS3 this->typeParam_[0] = typeToString<P1>(); this->typeParam_[1] = typeToString<P2>(); this->typeParam_[2] = typeToString<P3>();#define FUNCTOR_TYPENAME_PARAMS4 this->typeParam_[0] = typeToString<P1>(); this->typeParam_[1] = typeToString<P2>(); this->typeParam_[2] = typeToString<P3>(); this->typeParam_[3] = typeToString<P4>();#define FUNCTOR_TYPENAME_PARAMS5 this->typeParam_[0] = typeToString<P1>(); this->typeParam_[1] = typeToString<P2>(); this->typeParam_[2] = typeToString<P3>(); this->typeParam_[3] = typeToString<P4>(); this->typeParam_[4] = typeToString<P5>();#define FUNCTOR_TYPENAME_RETURN(returnvalue) FUNCTOR_TYPENAME_RETURN##returnvalue#define FUNCTOR_TYPENAME_RETURN0#define FUNCTOR_TYPENAME_RETURN1 this->typeReturnvalue_ = typeToString<R>();#define FUNCTOR_FUNCTION_PARAMS(numparams) FUNCTOR_FUNCTION_PARAMS##numparams#define FUNCTOR_FUNCTION_PARAMS0#define FUNCTOR_FUNCTION_PARAMS1 P1 param1#define FUNCTOR_FUNCTION_PARAMS2 P1 param1, P2 param2#define FUNCTOR_FUNCTION_PARAMS3 P1 param1, P2 param2, P3 param3#define FUNCTOR_FUNCTION_PARAMS4 P1 param1, P2 param2, P3 param3, P4 param4#define FUNCTOR_FUNCTION_PARAMS5 P1 param1, P2 param2, P3 param3, P4 param4, P5 param5#define FUNCTOR_FUNCTION_RETURNVALUE(returnvalue) FUNCTOR_FUNCTION_RETURNVALUE##returnvalue#define FUNCTOR_FUNCTION_RETURNVALUE0 void#define FUNCTOR_FUNCTION_RETURNVALUE1 R#define FUNCTOR_FUNCTION_CALL(numparams) FUNCTOR_FUNCTION_CALL##numparams#define FUNCTOR_FUNCTION_CALL0#define FUNCTOR_FUNCTION_CALL1 param1#define FUNCTOR_FUNCTION_CALL2 param1, param2#define FUNCTOR_FUNCTION_CALL3 param1, param2, param3#define FUNCTOR_FUNCTION_CALL4 param1, param2, param3, param4#define FUNCTOR_FUNCTION_CALL5 param1, param2, param3, param4, param5#define FUNCTOR_STORE_RETURNVALUE(returnvalue, functioncall) FUNCTOR_STORE_RETURNVALUE##returnvalue(functioncall)#define FUNCTOR_STORE_RETURNVALUE0(functioncall) functioncall#define FUNCTOR_STORE_RETURNVALUE1(functioncall) this->returnedValue_ = functioncall#define FUNCTOR_EVALUATE_PARAM(numparams) FUNCTOR_EVALUATE_PARAM##numparams#define FUNCTOR_EVALUATE_PARAM0#define FUNCTOR_EVALUATE_PARAM1 \ if (index == 0) { P1 temp = param; param = temp; }#define FUNCTOR_EVALUATE_PARAM2 \ if (index == 0) { P1 temp = param; param = temp; } \ else if (index == 1) { P2 temp = param; param = temp; }#define FUNCTOR_EVALUATE_PARAM3 \ if (index == 0) { P1 temp = param; param = temp; } \ else if (index == 1) { P2 temp = param; param = temp; } \ else if (index == 2) { P3 temp = param; param = temp; }#define FUNCTOR_EVALUATE_PARAM4 \ if (index == 0) { P1 temp = param; param = temp; } \ else if (index == 1) { P2 temp = param; param = temp; } \ else if (index == 2) { P3 temp = param; param = temp; } \ else if (index == 3) { P4 temp = param; param = temp; }#define FUNCTOR_EVALUATE_PARAM5 \ if (index == 0) { P1 temp = param; param = temp; } \ else if (index == 1) { P2 temp = param; param = temp; } \ else if (index == 2) { P3 temp = param; param = temp; } \ else if (index == 3) { P4 temp = param; param = temp; } \ else if (index == 4) { P5 temp = param; param = temp; }#define CREATE_STATIC_FUNCTOR(returnvalue, numparams) \ FUNCTOR_TEMPLATE(0, returnvalue, numparams) \ class FunctorStatic##returnvalue##numparams : public FunctorStatic \ { \ public: \ FunctorStatic##returnvalue##numparams(FUNCTOR_FUNCTION_RETURNVALUE(returnvalue) (*functionPointer)(FUNCTOR_FUNCTION_PARAMS(numparams))) \ { \ this->numParams_ = numparams; \ this->hasReturnValue_ = returnvalue; \ this->type_ = FT_STATIC; \ this->functionPointer_ = functionPointer; \ \ FUNCTOR_TYPENAME_PARAMS(numparams); \ FUNCTOR_TYPENAME_RETURN(returnvalue); \ } \ \ void operator()(const MultiTypeMath& param1 = MT_null, const MultiTypeMath& param2 = MT_null, const MultiTypeMath& param3 = MT_null, const MultiTypeMath& param4 = MT_null, const MultiTypeMath& param5 = MT_null) \ { \ FUNCTOR_STORE_RETURNVALUE(returnvalue, (*this->functionPointer_)(FUNCTOR_FUNCTION_CALL(numparams))); \ } \ \ virtual void evaluateParam(unsigned int index, MultiTypeMath& param) const \ { \ FUNCTOR_EVALUATE_PARAM(numparams); \ } \ \ private: \ FUNCTOR_FUNCTION_RETURNVALUE(returnvalue) (*functionPointer_)(FUNCTOR_FUNCTION_PARAMS(numparams)); \ }; \ \ \ FUNCTOR_TEMPLATE(0, returnvalue, numparams) \ inline FunctorStatic##returnvalue##numparams FUNCTOR_TEMPLATE_CLASSES(0, returnvalue, numparams)* createFunctor(FUNCTOR_FUNCTION_RETURNVALUE(returnvalue) (*functionPointer)(FUNCTOR_FUNCTION_PARAMS(numparams))) \ { \ return new FunctorStatic##returnvalue##numparams FUNCTOR_TEMPLATE_CLASSES(0, returnvalue, numparams) (functionPointer); \ }#define CREATE_MEMBER_FUNCTOR(returnvalue, numparams) \ FUNCTOR_TEMPLATE(1, returnvalue, numparams) \ class FunctorMember##returnvalue##numparams : public FunctorMember<T> \ { \ public: \ FunctorMember##returnvalue##numparams(FUNCTOR_FUNCTION_RETURNVALUE(returnvalue) (T::*functionPointer)(FUNCTOR_FUNCTION_PARAMS(numparams))) \ { \ this->numParams_ = numparams; \ this->hasReturnValue_ = returnvalue; \ this->type_ = FT_MEMBER; \ this->functionPointer_ = functionPointer; \ } \ \ void operator()(T* object, const MultiTypeMath& param1 = MT_null, const MultiTypeMath& param2 = MT_null, const MultiTypeMath& param3 = MT_null, const MultiTypeMath& param4 = MT_null, const MultiTypeMath& param5 = MT_null) \ { \ FUNCTOR_STORE_RETURNVALUE(returnvalue, (*object.*this->functionPointer_)(FUNCTOR_FUNCTION_CALL(numparams))); \ } \ \ void operator()(const T* object, const MultiTypeMath& param1 = MT_null, const MultiTypeMath& param2 = MT_null, const MultiTypeMath& param3 = MT_null, const MultiTypeMath& param4 = MT_null, const MultiTypeMath& param5 = MT_null) \ { \ COUT(1) << "An error occurred in Functor.h:" << std::endl; \ COUT(1) << "Error: Function is not const." << std::endl; \ } \ \ virtual void evaluateParam(unsigned int index, MultiTypeMath& param) const \ { \ FUNCTOR_EVALUATE_PARAM(numparams); \ } \ \ private: \ FUNCTOR_FUNCTION_RETURNVALUE(returnvalue) (T::*functionPointer_)(FUNCTOR_FUNCTION_PARAMS(numparams)); \ }; \ \ \ FUNCTOR_TEMPLATE(1, returnvalue, numparams) \ class FunctorConstMember##returnvalue##numparams : public FunctorMember<T> \ { \ public: \ FunctorConstMember##returnvalue##numparams(FUNCTOR_FUNCTION_RETURNVALUE(returnvalue) (T::*functionPointer)(FUNCTOR_FUNCTION_PARAMS(numparams)) const) \ { \ this->numParams_ = numparams; \ this->hasReturnValue_ = returnvalue; \ this->type_ = FT_CONSTMEMBER; \ this->functionPointer_ = functionPointer; \ } \ \ void operator()(T* object, const MultiTypeMath& param1 = MT_null, const MultiTypeMath& param2 = MT_null, const MultiTypeMath& param3 = MT_null, const MultiTypeMath& param4 = MT_null, const MultiTypeMath& param5 = MT_null) \ { \ FUNCTOR_STORE_RETURNVALUE(returnvalue, (*object.*this->functionPointer_)(FUNCTOR_FUNCTION_CALL(numparams))); \ } \ \ void operator()(const T* object, const MultiTypeMath& param1 = MT_null, const MultiTypeMath& param2 = MT_null, const MultiTypeMath& param3 = MT_null, const MultiTypeMath& param4 = MT_null, const MultiTypeMath& param5 = MT_null) \ { \ FUNCTOR_STORE_RETURNVALUE(returnvalue, (*object.*this->functionPointer_)(FUNCTOR_FUNCTION_CALL(numparams))); \ } \ \ virtual void evaluateParam(unsigned int index, MultiTypeMath& param) const \ { \ FUNCTOR_EVALUATE_PARAM(numparams); \ } \ \ private: \ FUNCTOR_FUNCTION_RETURNVALUE(returnvalue) (T::*functionPointer_)(FUNCTOR_FUNCTION_PARAMS(numparams)) const; \ }; \ \ \ FUNCTOR_TEMPLATE(1, returnvalue, numparams) \ inline FunctorMember##returnvalue##numparams FUNCTOR_TEMPLATE_CLASSES(1, returnvalue, numparams)* createFunctor(FUNCTOR_FUNCTION_RETURNVALUE(returnvalue) (T::*functionPointer)(FUNCTOR_FUNCTION_PARAMS(numparams))) \ { \ return new FunctorMember##returnvalue##numparams FUNCTOR_TEMPLATE_CLASSES(1, returnvalue, numparams) (functionPointer); \ } \ \ \ FUNCTOR_TEMPLATE(1, returnvalue, numparams) \ inline FunctorConstMember##returnvalue##numparams FUNCTOR_TEMPLATE_CLASSES(1, returnvalue, numparams)* createFunctor(FUNCTOR_FUNCTION_RETURNVALUE(returnvalue) (T::*functionPointer)(FUNCTOR_FUNCTION_PARAMS(numparams)) const) \ { \ return new FunctorConstMember##returnvalue##numparams FUNCTOR_TEMPLATE_CLASSES(1, returnvalue, numparams) (functionPointer); \ }// disable annoying warning about forcing value to boolean 1 /* 2 * ORXONOX - the hottest 3D action shooter ever to exist 3 * > www.orxonox.net < 4 * 5 * 6 * License notice: 7 * 8 * This program is free software; you can redistribute it and/or 9 * modify it under the terms of the GNU General Public License 10 * as published by the Free Software Foundation; either version 2 11 * of the License, or (at your option) any later version. 12 * 13 * This program is distributed in the hope that it will be useful, 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 * GNU General Public License for more details. 17 * 18 * You should have received a copy of the GNU General Public License 19 * along with this program; if not, write to the Free Software 20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 21 * 22 * Author: 23 * Fabian 'x3n' Landau 24 * Co-authors: 25 * ... 26 * 27 * Inspiration: Functor by Benjamin Grauer 28 */ 29 30 #ifndef _Functor_H__ 31 #define _Functor_H__ 32 33 #include "CorePrereqs.h" 34 35 #include "util/MultiTypeMath.h" 36 #include "Debug.h" 37 38 #define MAX_FUNCTOR_ARGUMENTS 5 39 40 namespace orxonox 41 { 42 enum FunctionType 43 { 44 FT_MEMBER, 45 FT_CONSTMEMBER, 46 FT_STATIC 47 }; 48 49 50 template <class T> 51 inline std::string typeToString() { return "unknown"; } 52 53 #define CreateTypeToStringTemplate(type) \ 54 template <> \ 55 inline std::string typeToString<type>() { return #type; } \ 56 template <> \ 57 inline std::string typeToString<type&>() { return #type; } \ 58 template <> \ 59 inline std::string typeToString<const type>() { return #type; } \ 60 template <> \ 61 inline std::string typeToString<const type&>() { return #type; } 62 63 CreateTypeToStringTemplate(int); 64 CreateTypeToStringTemplate(unsigned int); 65 CreateTypeToStringTemplate(char); 66 CreateTypeToStringTemplate(unsigned char); 67 CreateTypeToStringTemplate(short); 68 CreateTypeToStringTemplate(unsigned short); 69 CreateTypeToStringTemplate(long); 70 CreateTypeToStringTemplate(unsigned long); 71 CreateTypeToStringTemplate(float); 72 CreateTypeToStringTemplate(double); 73 CreateTypeToStringTemplate(long double); 74 CreateTypeToStringTemplate(bool); 75 CreateTypeToStringTemplate(Vector2); 76 CreateTypeToStringTemplate(Vector3); 77 CreateTypeToStringTemplate(Quaternion); 78 CreateTypeToStringTemplate(ColourValue); 79 CreateTypeToStringTemplate(Radian); 80 CreateTypeToStringTemplate(Degree); 81 82 template <> \ 83 inline std::string typeToString<std::string>() { return "string"; } \ 84 template <> \ 85 inline std::string typeToString<std::string&>() { return "string"; } \ 86 template <> \ 87 inline std::string typeToString<const std::string>() { return "string"; } \ 88 template <> \ 89 inline std::string typeToString<const std::string&>() { return "string"; } 90 91 class _CoreExport Functor 92 { 93 public: 94 Functor() {} 95 virtual ~Functor() {} 96 97 virtual void operator()(const MultiTypeMath& param1 = MT_null, const MultiTypeMath& param2 = MT_null, const MultiTypeMath& param3 = MT_null, const MultiTypeMath& param4 = MT_null, const MultiTypeMath& param5 = MT_null) = 0; 98 99 inline unsigned int getParamCount() const { return this->numParams_; } 100 inline bool hasReturnvalue() const { return this->hasReturnValue_; } 101 inline FunctionType getType() const { return this->type_; } 102 inline MultiTypeMath getReturnvalue() const { return this->returnedValue_; } 103 104 std::string getTypenameParam(unsigned int param) const { return (param >= 0 && param < 5) ? this->typeParam_[param] : ""; } 105 std::string getTypenameReturnvalue() const { return this->typeReturnvalue_; } 106 107 virtual void evaluateParam(unsigned int index, MultiTypeMath& param) const = 0; 108 109 protected: 110 unsigned int numParams_; 111 bool hasReturnValue_; 112 FunctionType type_; 113 MultiTypeMath returnedValue_; 114 115 std::string typeReturnvalue_; 116 std::string typeParam_[MAX_FUNCTOR_ARGUMENTS]; 117 }; 118 119 class _CoreExport FunctorStatic : public Functor 120 { 121 public: 122 virtual ~FunctorStatic() {} 123 virtual void operator()(const MultiTypeMath& param1 = MT_null, const MultiTypeMath& param2 = MT_null, const MultiTypeMath& param3 = MT_null, const MultiTypeMath& param4 = MT_null, const MultiTypeMath& param5 = MT_null) = 0; 124 }; 125 126 template <class T> 127 class FunctorMember : public Functor 128 { 129 public: 130 FunctorMember() 131 { 132 constObject_ = 0; 133 object_ = 0; 134 bConstObject_ = false; 135 } 136 virtual ~FunctorMember() {} 137 138 virtual void operator()(T* object, const MultiTypeMath& param1 = MT_null, const MultiTypeMath& param2 = MT_null, const MultiTypeMath& param3 = MT_null, const MultiTypeMath& param4 = MT_null, const MultiTypeMath& param5 = MT_null) = 0; 139 virtual void operator()(const T* object, const MultiTypeMath& param1 = MT_null, const MultiTypeMath& param2 = MT_null, const MultiTypeMath& param3 = MT_null, const MultiTypeMath& param4 = MT_null, const MultiTypeMath& param5 = MT_null) = 0; 140 141 virtual void operator()(const MultiTypeMath& param1 = MT_null, const MultiTypeMath& param2 = MT_null, const MultiTypeMath& param3 = MT_null, const MultiTypeMath& param4 = MT_null, const MultiTypeMath& param5 = MT_null) 142 { 143 if (this->bConstObject_) 144 { 145 if (this->constObject_) 146 (*this)(this->constObject_, param1, param2, param3, param4, param5); 147 else 148 { 149 COUT(1) << "An error occurred in Functor.h:" << std::endl; 150 COUT(1) << "Error: No const object set." << std::endl; 151 } 152 } 153 else 154 { 155 if (this->object_) 156 (*this)(this->object_, param1, param2, param3, param4, param5); 157 else 158 { 159 COUT(1) << "An error occurred in Functor.h:" << std::endl; 160 COUT(1) << "Error: No object set." << std::endl; 161 } 162 } 163 } 164 165 void setObject(T* object) 166 { 167 this->bConstObject_ = false; 168 this->object_ = object; 169 } 170 171 void setObject(const T* object) 172 { 173 this->bConstObject_ = true; 174 this->constObject_ = object; 175 } 176 177 private: 178 const T* constObject_; 179 T* object_; 180 bool bConstObject_; 181 }; 182 183 184 185 #define FUNCTOR_TEMPLATE(ismember, returnvalue, numparams) FUNCTOR_TEMPLATE##ismember##returnvalue##numparams 186 #define FUNCTOR_TEMPLATE000 187 #define FUNCTOR_TEMPLATE001 template <class P1> 188 #define FUNCTOR_TEMPLATE002 template <class P1, class P2> 189 #define FUNCTOR_TEMPLATE003 template <class P1, class P2, class P3> 190 #define FUNCTOR_TEMPLATE004 template <class P1, class P2, class P3, class P4> 191 #define FUNCTOR_TEMPLATE005 template <class P1, class P2, class P3, class P4, class P5> 192 #define FUNCTOR_TEMPLATE010 template <class R> 193 #define FUNCTOR_TEMPLATE011 template <class R, class P1> 194 #define FUNCTOR_TEMPLATE012 template <class R, class P1, class P2> 195 #define FUNCTOR_TEMPLATE013 template <class R, class P1, class P2, class P3> 196 #define FUNCTOR_TEMPLATE014 template <class R, class P1, class P2, class P3, class P4> 197 #define FUNCTOR_TEMPLATE015 template <class R, class P1, class P2, class P3, class P4, class P5> 198 #define FUNCTOR_TEMPLATE100 template <class T> 199 #define FUNCTOR_TEMPLATE101 template <class T, class P1> 200 #define FUNCTOR_TEMPLATE102 template <class T, class P1, class P2> 201 #define FUNCTOR_TEMPLATE103 template <class T, class P1, class P2, class P3> 202 #define FUNCTOR_TEMPLATE104 template <class T, class P1, class P2, class P3, class P4> 203 #define FUNCTOR_TEMPLATE105 template <class T, class P1, class P2, class P3, class P4, class P5> 204 #define FUNCTOR_TEMPLATE110 template <class T, class R> 205 #define FUNCTOR_TEMPLATE111 template <class T, class R, class P1> 206 #define FUNCTOR_TEMPLATE112 template <class T, class R, class P1, class P2> 207 #define FUNCTOR_TEMPLATE113 template <class T, class R, class P1, class P2, class P3> 208 #define FUNCTOR_TEMPLATE114 template <class T, class R, class P1, class P2, class P3, class P4> 209 #define FUNCTOR_TEMPLATE115 template <class T, class R, class P1, class P2, class P3, class P4, class P5> 210 211 212 213 #define FUNCTOR_TEMPLATE_CLASSES(ismember, returnvalue, numparams) FUNCTOR_TEMPLATE_CLASSES##ismember##returnvalue##numparams 214 #define FUNCTOR_TEMPLATE_CLASSES000 215 #define FUNCTOR_TEMPLATE_CLASSES001 <P1> 216 #define FUNCTOR_TEMPLATE_CLASSES002 <P1, P2> 217 #define FUNCTOR_TEMPLATE_CLASSES003 <P1, P2, P3> 218 #define FUNCTOR_TEMPLATE_CLASSES004 <P1, P2, P3, P4> 219 #define FUNCTOR_TEMPLATE_CLASSES005 <P1, P2, P3, P4, P5> 220 #define FUNCTOR_TEMPLATE_CLASSES010 <R> 221 #define FUNCTOR_TEMPLATE_CLASSES011 <R, P1> 222 #define FUNCTOR_TEMPLATE_CLASSES012 <R, P1, P2> 223 #define FUNCTOR_TEMPLATE_CLASSES013 <R, P1, P2, P3> 224 #define FUNCTOR_TEMPLATE_CLASSES014 <R, P1, P2, P3, P4> 225 #define FUNCTOR_TEMPLATE_CLASSES015 <R, P1, P2, P3, P4, P5> 226 #define FUNCTOR_TEMPLATE_CLASSES100 <T> 227 #define FUNCTOR_TEMPLATE_CLASSES101 <T, P1> 228 #define FUNCTOR_TEMPLATE_CLASSES102 <T, P1, P2> 229 #define FUNCTOR_TEMPLATE_CLASSES103 <T, P1, P2, P3> 230 #define FUNCTOR_TEMPLATE_CLASSES104 <T, P1, P2, P3, P4> 231 #define FUNCTOR_TEMPLATE_CLASSES105 <T, P1, P2, P3, P4, P5> 232 #define FUNCTOR_TEMPLATE_CLASSES110 <T, R> 233 #define FUNCTOR_TEMPLATE_CLASSES111 <T, R, P1> 234 #define FUNCTOR_TEMPLATE_CLASSES112 <T, R, P1, P2> 235 #define FUNCTOR_TEMPLATE_CLASSES113 <T, R, P1, P2, P3> 236 #define FUNCTOR_TEMPLATE_CLASSES114 <T, R, P1, P2, P3, P4> 237 #define FUNCTOR_TEMPLATE_CLASSES115 <T, R, P1, P2, P3, P4, P5> 238 239 240 241 #define FUNCTOR_TYPENAME_PARAMS(numparams) FUNCTOR_TYPENAME_PARAMS##numparams 242 #define FUNCTOR_TYPENAME_PARAMS0 243 #define FUNCTOR_TYPENAME_PARAMS1 this->typeParam_[0] = typeToString<P1>(); 244 #define FUNCTOR_TYPENAME_PARAMS2 this->typeParam_[0] = typeToString<P1>(); this->typeParam_[1] = typeToString<P2>(); 245 #define FUNCTOR_TYPENAME_PARAMS3 this->typeParam_[0] = typeToString<P1>(); this->typeParam_[1] = typeToString<P2>(); this->typeParam_[2] = typeToString<P3>(); 246 #define FUNCTOR_TYPENAME_PARAMS4 this->typeParam_[0] = typeToString<P1>(); this->typeParam_[1] = typeToString<P2>(); this->typeParam_[2] = typeToString<P3>(); this->typeParam_[3] = typeToString<P4>(); 247 #define FUNCTOR_TYPENAME_PARAMS5 this->typeParam_[0] = typeToString<P1>(); this->typeParam_[1] = typeToString<P2>(); this->typeParam_[2] = typeToString<P3>(); this->typeParam_[3] = typeToString<P4>(); this->typeParam_[4] = typeToString<P5>(); 248 249 #define FUNCTOR_TYPENAME_RETURN(returnvalue) FUNCTOR_TYPENAME_RETURN##returnvalue 250 #define FUNCTOR_TYPENAME_RETURN0 251 #define FUNCTOR_TYPENAME_RETURN1 this->typeReturnvalue_ = typeToString<R>(); 252 253 254 255 #define FUNCTOR_FUNCTION_PARAMS(numparams) FUNCTOR_FUNCTION_PARAMS##numparams 256 #define FUNCTOR_FUNCTION_PARAMS0 257 #define FUNCTOR_FUNCTION_PARAMS1 P1 param1 258 #define FUNCTOR_FUNCTION_PARAMS2 P1 param1, P2 param2 259 #define FUNCTOR_FUNCTION_PARAMS3 P1 param1, P2 param2, P3 param3 260 #define FUNCTOR_FUNCTION_PARAMS4 P1 param1, P2 param2, P3 param3, P4 param4 261 #define FUNCTOR_FUNCTION_PARAMS5 P1 param1, P2 param2, P3 param3, P4 param4, P5 param5 262 263 #define FUNCTOR_FUNCTION_RETURNVALUE(returnvalue) FUNCTOR_FUNCTION_RETURNVALUE##returnvalue 264 #define FUNCTOR_FUNCTION_RETURNVALUE0 void 265 #define FUNCTOR_FUNCTION_RETURNVALUE1 R 266 267 268 269 #define FUNCTOR_FUNCTION_CALL(numparams) FUNCTOR_FUNCTION_CALL##numparams 270 #define FUNCTOR_FUNCTION_CALL0 271 #define FUNCTOR_FUNCTION_CALL1 param1 272 #define FUNCTOR_FUNCTION_CALL2 param1, param2 273 #define FUNCTOR_FUNCTION_CALL3 param1, param2, param3 274 #define FUNCTOR_FUNCTION_CALL4 param1, param2, param3, param4 275 #define FUNCTOR_FUNCTION_CALL5 param1, param2, param3, param4, param5 276 277 #define FUNCTOR_STORE_RETURNVALUE(returnvalue, functioncall) FUNCTOR_STORE_RETURNVALUE##returnvalue(functioncall) 278 #define FUNCTOR_STORE_RETURNVALUE0(functioncall) functioncall 279 #define FUNCTOR_STORE_RETURNVALUE1(functioncall) this->returnedValue_ = functioncall 280 281 282 283 #define FUNCTOR_EVALUATE_PARAM(numparams) FUNCTOR_EVALUATE_PARAM##numparams 284 #define FUNCTOR_EVALUATE_PARAM0 285 #define FUNCTOR_EVALUATE_PARAM1 \ 286 if (index == 0) { P1 temp = param; param = temp; } 287 #define FUNCTOR_EVALUATE_PARAM2 \ 288 if (index == 0) { P1 temp = param; param = temp; } \ 289 else if (index == 1) { P2 temp = param; param = temp; } 290 #define FUNCTOR_EVALUATE_PARAM3 \ 291 if (index == 0) { P1 temp = param; param = temp; } \ 292 else if (index == 1) { P2 temp = param; param = temp; } \ 293 else if (index == 2) { P3 temp = param; param = temp; } 294 #define FUNCTOR_EVALUATE_PARAM4 \ 295 if (index == 0) { P1 temp = param; param = temp; } \ 296 else if (index == 1) { P2 temp = param; param = temp; } \ 297 else if (index == 2) { P3 temp = param; param = temp; } \ 298 else if (index == 3) { P4 temp = param; param = temp; } 299 #define FUNCTOR_EVALUATE_PARAM5 \ 300 if (index == 0) { P1 temp = param; param = temp; } \ 301 else if (index == 1) { P2 temp = param; param = temp; } \ 302 else if (index == 2) { P3 temp = param; param = temp; } \ 303 else if (index == 3) { P4 temp = param; param = temp; } \ 304 else if (index == 4) { P5 temp = param; param = temp; } 305 306 307 308 309 310 #define CREATE_STATIC_FUNCTOR(returnvalue, numparams) \ 311 FUNCTOR_TEMPLATE(0, returnvalue, numparams) \ 312 class FunctorStatic##returnvalue##numparams : public FunctorStatic \ 313 { \ 314 public: \ 315 FunctorStatic##returnvalue##numparams(FUNCTOR_FUNCTION_RETURNVALUE(returnvalue) (*functionPointer)(FUNCTOR_FUNCTION_PARAMS(numparams))) \ 316 { \ 317 this->numParams_ = numparams; \ 318 this->hasReturnValue_ = returnvalue; \ 319 this->type_ = FT_STATIC; \ 320 this->functionPointer_ = functionPointer; \ 321 \ 322 FUNCTOR_TYPENAME_PARAMS(numparams); \ 323 FUNCTOR_TYPENAME_RETURN(returnvalue); \ 324 } \ 325 \ 326 void operator()(const MultiTypeMath& param1 = MT_null, const MultiTypeMath& param2 = MT_null, const MultiTypeMath& param3 = MT_null, const MultiTypeMath& param4 = MT_null, const MultiTypeMath& param5 = MT_null) \ 327 { \ 328 FUNCTOR_STORE_RETURNVALUE(returnvalue, (*this->functionPointer_)(FUNCTOR_FUNCTION_CALL(numparams))); \ 329 } \ 330 \ 331 virtual void evaluateParam(unsigned int index, MultiTypeMath& param) const \ 332 { \ 333 FUNCTOR_EVALUATE_PARAM(numparams); \ 334 } \ 335 \ 336 private: \ 337 FUNCTOR_FUNCTION_RETURNVALUE(returnvalue) (*functionPointer_)(FUNCTOR_FUNCTION_PARAMS(numparams)); \ 338 }; \ 339 \ 340 \ 341 FUNCTOR_TEMPLATE(0, returnvalue, numparams) \ 342 inline FunctorStatic##returnvalue##numparams FUNCTOR_TEMPLATE_CLASSES(0, returnvalue, numparams)* createFunctor(FUNCTOR_FUNCTION_RETURNVALUE(returnvalue) (*functionPointer)(FUNCTOR_FUNCTION_PARAMS(numparams))) \ 343 { \ 344 return new FunctorStatic##returnvalue##numparams FUNCTOR_TEMPLATE_CLASSES(0, returnvalue, numparams) (functionPointer); \ 345 } 346 347 348 349 350 351 #define CREATE_MEMBER_FUNCTOR(returnvalue, numparams) \ 352 FUNCTOR_TEMPLATE(1, returnvalue, numparams) \ 353 class FunctorMember##returnvalue##numparams : public FunctorMember<T> \ 354 { \ 355 public: \ 356 FunctorMember##returnvalue##numparams(FUNCTOR_FUNCTION_RETURNVALUE(returnvalue) (T::*functionPointer)(FUNCTOR_FUNCTION_PARAMS(numparams))) \ 357 { \ 358 this->numParams_ = numparams; \ 359 this->hasReturnValue_ = returnvalue; \ 360 this->type_ = FT_MEMBER; \ 361 this->functionPointer_ = functionPointer; \ 362 } \ 363 \ 364 void operator()(T* object, const MultiTypeMath& param1 = MT_null, const MultiTypeMath& param2 = MT_null, const MultiTypeMath& param3 = MT_null, const MultiTypeMath& param4 = MT_null, const MultiTypeMath& param5 = MT_null) \ 365 { \ 366 FUNCTOR_STORE_RETURNVALUE(returnvalue, (*object.*this->functionPointer_)(FUNCTOR_FUNCTION_CALL(numparams))); \ 367 } \ 368 \ 369 void operator()(const T* object, const MultiTypeMath& param1 = MT_null, const MultiTypeMath& param2 = MT_null, const MultiTypeMath& param3 = MT_null, const MultiTypeMath& param4 = MT_null, const MultiTypeMath& param5 = MT_null) \ 370 { \ 371 COUT(1) << "An error occurred in Functor.h:" << std::endl; \ 372 COUT(1) << "Error: Function is not const." << std::endl; \ 373 } \ 374 \ 375 virtual void evaluateParam(unsigned int index, MultiTypeMath& param) const \ 376 { \ 377 FUNCTOR_EVALUATE_PARAM(numparams); \ 378 } \ 379 \ 380 private: \ 381 FUNCTOR_FUNCTION_RETURNVALUE(returnvalue) (T::*functionPointer_)(FUNCTOR_FUNCTION_PARAMS(numparams)); \ 382 }; \ 383 \ 384 \ 385 FUNCTOR_TEMPLATE(1, returnvalue, numparams) \ 386 class FunctorConstMember##returnvalue##numparams : public FunctorMember<T> \ 387 { \ 388 public: \ 389 FunctorConstMember##returnvalue##numparams(FUNCTOR_FUNCTION_RETURNVALUE(returnvalue) (T::*functionPointer)(FUNCTOR_FUNCTION_PARAMS(numparams)) const) \ 390 { \ 391 this->numParams_ = numparams; \ 392 this->hasReturnValue_ = returnvalue; \ 393 this->type_ = FT_CONSTMEMBER; \ 394 this->functionPointer_ = functionPointer; \ 395 } \ 396 \ 397 void operator()(T* object, const MultiTypeMath& param1 = MT_null, const MultiTypeMath& param2 = MT_null, const MultiTypeMath& param3 = MT_null, const MultiTypeMath& param4 = MT_null, const MultiTypeMath& param5 = MT_null) \ 398 { \ 399 FUNCTOR_STORE_RETURNVALUE(returnvalue, (*object.*this->functionPointer_)(FUNCTOR_FUNCTION_CALL(numparams))); \ 400 } \ 401 \ 402 void operator()(const T* object, const MultiTypeMath& param1 = MT_null, const MultiTypeMath& param2 = MT_null, const MultiTypeMath& param3 = MT_null, const MultiTypeMath& param4 = MT_null, const MultiTypeMath& param5 = MT_null) \ 403 { \ 404 FUNCTOR_STORE_RETURNVALUE(returnvalue, (*object.*this->functionPointer_)(FUNCTOR_FUNCTION_CALL(numparams))); \ 405 } \ 406 \ 407 virtual void evaluateParam(unsigned int index, MultiTypeMath& param) const \ 408 { \ 409 FUNCTOR_EVALUATE_PARAM(numparams); \ 410 } \ 411 \ 412 private: \ 413 FUNCTOR_FUNCTION_RETURNVALUE(returnvalue) (T::*functionPointer_)(FUNCTOR_FUNCTION_PARAMS(numparams)) const; \ 414 }; \ 415 \ 416 \ 417 FUNCTOR_TEMPLATE(1, returnvalue, numparams) \ 418 inline FunctorMember##returnvalue##numparams FUNCTOR_TEMPLATE_CLASSES(1, returnvalue, numparams)* createFunctor(FUNCTOR_FUNCTION_RETURNVALUE(returnvalue) (T::*functionPointer)(FUNCTOR_FUNCTION_PARAMS(numparams))) \ 419 { \ 420 return new FunctorMember##returnvalue##numparams FUNCTOR_TEMPLATE_CLASSES(1, returnvalue, numparams) (functionPointer); \ 421 } \ 422 \ 423 \ 424 FUNCTOR_TEMPLATE(1, returnvalue, numparams) \ 425 inline FunctorConstMember##returnvalue##numparams FUNCTOR_TEMPLATE_CLASSES(1, returnvalue, numparams)* createFunctor(FUNCTOR_FUNCTION_RETURNVALUE(returnvalue) (T::*functionPointer)(FUNCTOR_FUNCTION_PARAMS(numparams)) const) \ 426 { \ 427 return new FunctorConstMember##returnvalue##numparams FUNCTOR_TEMPLATE_CLASSES(1, returnvalue, numparams) (functionPointer); \ 428 } 429 430 431 // disable annoying warning about forcing value to boolean 2 432 #if ORXONOX_COMPILER == ORXONOX_COMPILER_MSVC 3 433 #pragma warning(push) 4 434 #pragma warning(disable:4100 4800) 5 435 #endif 6 #define CREATE_ALL_STATIC_FUNCTORS() \ CREATE_STATIC_FUNCTOR(0, 0); \ CREATE_STATIC_FUNCTOR(0, 1); \ CREATE_STATIC_FUNCTOR(0, 2); \ CREATE_STATIC_FUNCTOR(0, 3); \ CREATE_STATIC_FUNCTOR(0, 4); \ CREATE_STATIC_FUNCTOR(0, 5); \ CREATE_STATIC_FUNCTOR(1, 0); \ CREATE_STATIC_FUNCTOR(1, 1); \ CREATE_STATIC_FUNCTOR(1, 2); \ CREATE_STATIC_FUNCTOR(1, 3); \ CREATE_STATIC_FUNCTOR(1, 4); \ CREATE_STATIC_FUNCTOR(1, 5)#define CREATE_ALL_MEMBER_FUNCTORS() \ CREATE_MEMBER_FUNCTOR(0, 0); \ CREATE_MEMBER_FUNCTOR(0, 1); \ CREATE_MEMBER_FUNCTOR(0, 2); \ CREATE_MEMBER_FUNCTOR(0, 3); \ CREATE_MEMBER_FUNCTOR(0, 4); \ CREATE_MEMBER_FUNCTOR(0, 5); \ CREATE_MEMBER_FUNCTOR(1, 0); \ CREATE_MEMBER_FUNCTOR(1, 1); \ CREATE_MEMBER_FUNCTOR(1, 2); \ CREATE_MEMBER_FUNCTOR(1, 3); \ CREATE_MEMBER_FUNCTOR(1, 4); \ CREATE_MEMBER_FUNCTOR(1, 5) CREATE_ALL_STATIC_FUNCTORS(); CREATE_ALL_MEMBER_FUNCTORS();}#if ORXONOX_COMPILER == ORXONOX_COMPILER_MSVC 436 437 #define CREATE_ALL_STATIC_FUNCTORS() \ 438 CREATE_STATIC_FUNCTOR(0, 0); \ 439 CREATE_STATIC_FUNCTOR(0, 1); \ 440 CREATE_STATIC_FUNCTOR(0, 2); \ 441 CREATE_STATIC_FUNCTOR(0, 3); \ 442 CREATE_STATIC_FUNCTOR(0, 4); \ 443 CREATE_STATIC_FUNCTOR(0, 5); \ 444 CREATE_STATIC_FUNCTOR(1, 0); \ 445 CREATE_STATIC_FUNCTOR(1, 1); \ 446 CREATE_STATIC_FUNCTOR(1, 2); \ 447 CREATE_STATIC_FUNCTOR(1, 3); \ 448 CREATE_STATIC_FUNCTOR(1, 4); \ 449 CREATE_STATIC_FUNCTOR(1, 5) 450 451 452 #define CREATE_ALL_MEMBER_FUNCTORS() \ 453 CREATE_MEMBER_FUNCTOR(0, 0); \ 454 CREATE_MEMBER_FUNCTOR(0, 1); \ 455 CREATE_MEMBER_FUNCTOR(0, 2); \ 456 CREATE_MEMBER_FUNCTOR(0, 3); \ 457 CREATE_MEMBER_FUNCTOR(0, 4); \ 458 CREATE_MEMBER_FUNCTOR(0, 5); \ 459 CREATE_MEMBER_FUNCTOR(1, 0); \ 460 CREATE_MEMBER_FUNCTOR(1, 1); \ 461 CREATE_MEMBER_FUNCTOR(1, 2); \ 462 CREATE_MEMBER_FUNCTOR(1, 3); \ 463 CREATE_MEMBER_FUNCTOR(1, 4); \ 464 CREATE_MEMBER_FUNCTOR(1, 5) 465 466 467 CREATE_ALL_STATIC_FUNCTORS(); 468 CREATE_ALL_MEMBER_FUNCTORS(); 469 } 470 471 #if ORXONOX_COMPILER == ORXONOX_COMPILER_MSVC 7 472 #pragma warning(pop) 8 #endif#endif /* _Functor_H__ */ 473 #endif 474 475 #endif /* _Functor_H__ */ -
code/branches/network/src/core/Identifier.cc
r1494 r1495 1 1 /* 2 2 * ORXONOX - the hottest 3D action shooter ever to exist 3 * > www.orxonox.net < * 3 * > www.orxonox.net < 4 * 4 5 * 5 6 * License notice: … … 30 31 @brief Implementation of the Identifier class. 31 32 */ 32 #include "Identifier.h"#include <ostream> 33 34 #include "Identifier.h" 35 36 #include <ostream> 37 33 38 #include "Factory.h" 34 #include "ConsoleCommand.h"#include "CommandExecutor.h" 39 #include "ConsoleCommand.h" 40 #include "CommandExecutor.h" 41 35 42 namespace orxonox 36 43 { … … 39 46 // ############################### 40 47 int Identifier::hierarchyCreatingCounter_s = 0; // Set the static member variable hierarchyCreatingCounter_s to zero (this static member variable is ok: it's used in main(), not before) 48 41 49 /** 42 50 @brief Constructor: No factory, no object created, new ObjectList and a unique networkID. … … 45 53 { 46 54 this->bCreatedOneObject_ = false; 47 this->factory_ = 0; this->bHasConfigValues_ = false; this->bHasConsoleCommands_ = false; 48 49 this->children_ = new std::set<const Identifier*>(); this->directChildren_ = new std::set<const Identifier*>(); // Use a static variable because the classID gets created before main() and that's why we should avoid static member variables static unsigned int classIDcounter_s = 0; 50 this->classID_ = classIDcounter_s++; } 55 this->factory_ = 0; 56 57 this->bHasConfigValues_ = false; 58 this->bHasConsoleCommands_ = false; 59 60 this->children_ = new std::set<const Identifier*>(); 61 this->directChildren_ = new std::set<const Identifier*>(); 62 63 // Use a static variable because the classID gets created before main() and that's why we should avoid static member variables 64 static unsigned int classIDcounter_s = 0; 65 this->classID_ = classIDcounter_s++; 66 } 51 67 52 68 /** … … 55 71 Identifier::~Identifier() 56 72 { 57 delete this->children_; delete this->directChildren_; } 73 delete this->children_; 74 delete this->directChildren_; 75 } 58 76 59 77 /** … … 67 85 68 86 if (parents) 69 { this->parents_ = (*parents); this->directParents_ = (*parents); // Iterate through all parents 87 { 88 this->parents_ = (*parents); 89 this->directParents_ = (*parents); 90 91 // Iterate through all parents 70 92 for (std::set<const Identifier*>::iterator it = parents->begin(); it != parents->end(); ++it) 71 { // Tell the parent we're one of it's children (*it)->getChildrenIntern().insert((*it)->getChildrenIntern().end(), this); // Erase all parents of our parent from our direct-parent-list for (std::set<const Identifier*>::const_iterator it1 = (*it)->getParents().begin(); it1 != (*it)->getParents().end(); ++it1) { // Search for the parent's parent in our direct-parent-list for (std::set<const Identifier*>::iterator it2 = this->directParents_.begin(); it2 != this->directParents_.end(); ++it2) { if ((*it1) == (*it2)) { // We've found a non-direct parent in our list: Erase it this->directParents_.erase(it2); break; } } } } // Now iterate through all direct parents for (std::set<const Identifier*>::iterator it = this->directParents_.begin(); it != this->directParents_.end(); ++it) { // Tell the parent we're one of it's direct children (*it)->getDirectChildrenIntern().insert((*it)->getDirectChildrenIntern().end(), this); } 93 { 94 // Tell the parent we're one of it's children 95 (*it)->getChildrenIntern().insert((*it)->getChildrenIntern().end(), this); 96 97 // Erase all parents of our parent from our direct-parent-list 98 for (std::set<const Identifier*>::const_iterator it1 = (*it)->getParents().begin(); it1 != (*it)->getParents().end(); ++it1) 99 { 100 // Search for the parent's parent in our direct-parent-list 101 for (std::set<const Identifier*>::iterator it2 = this->directParents_.begin(); it2 != this->directParents_.end(); ++it2) 102 { 103 if ((*it1) == (*it2)) 104 { 105 // We've found a non-direct parent in our list: Erase it 106 this->directParents_.erase(it2); 107 break; 108 } 109 } 110 } 111 } 112 113 // Now iterate through all direct parents 114 for (std::set<const Identifier*>::iterator it = this->directParents_.begin(); it != this->directParents_.end(); ++it) 115 { 116 // Tell the parent we're one of it's direct children 117 (*it)->getDirectChildrenIntern().insert((*it)->getDirectChildrenIntern().end(), this); 118 } 72 119 } 73 120 } … … 85 132 else 86 133 { 87 COUT(1) << "An error occurred in Identifier.cc:" << std::endl; COUT(1) << "Error: Cannot fabricate an object of type '" << this->name_ << "'. Class has no factory." << std::endl; 134 COUT(1) << "An error occurred in Identifier.cc:" << std::endl; 135 COUT(1) << "Error: Cannot fabricate an object of type '" << this->name_ << "'. Class has no factory." << std::endl; 88 136 COUT(1) << "Aborting..." << std::endl; 89 137 abort(); … … 127 175 { 128 176 return (this->parents_.find(identifier) != this->parents_.end()); 129 } /** @brief Returns true, if the assigned identifier is a direct child of the given identifier. @param identifier The identifier to compare with */ bool Identifier::isDirectChildOf(const Identifier* identifier) const { return (this->directParents_.find(identifier) != this->directParents_.end()); } 177 } 178 179 /** 180 @brief Returns true, if the assigned identifier is a direct child of the given identifier. 181 @param identifier The identifier to compare with 182 */ 183 bool Identifier::isDirectChildOf(const Identifier* identifier) const 184 { 185 return (this->directParents_.find(identifier) != this->directParents_.end()); 186 } 187 130 188 /** 131 189 @brief Returns true, if the assigned identifier is a parent of the given identifier. … … 135 193 { 136 194 return (this->children_->find(identifier) != this->children_->end()); 137 } /** @brief Returns true, if the assigned identifier is a direct parent of the given identifier. @param identifier The identifier to compare with */ bool Identifier::isDirectParentOf(const Identifier* identifier) const { return (this->directChildren_->find(identifier) != this->directChildren_->end()); } /** @brief Returns the map that stores all Identifiers. @return The map */ std::map<std::string, Identifier*>& Identifier::getIdentifierMapIntern() { static std::map<std::string, Identifier*> identifierMap; return identifierMap; } /** @brief Returns the map that stores all Identifiers. @return The map */ std::map<std::string, Identifier*>& Identifier::getLowercaseIdentifierMapIntern() { static std::map<std::string, Identifier*> lowercaseIdentifierMap; return lowercaseIdentifierMap; } /** @brief Adds the ConfigValueContainer of a variable, given by the string of its name. @param varname The name of the variablee @param container The container */ void Identifier::addConfigValueContainer(const std::string& varname, ConfigValueContainer* container) { std::map<std::string, ConfigValueContainer*>::const_iterator it = this->configValues_.find(varname); if (it != this->configValues_.end()) { COUT(2) << "Warning: Overwriting config-value with name " << varname << " in class " << this->getName() << "." << std::endl; } this->bHasConfigValues_ = true; this->configValues_[varname] = container; this->configValues_LC_[getLowercase(varname)] = container; } /** @brief Returns the ConfigValueContainer of a variable, given by the string of its name. @param varname The name of the variable @return The ConfigValueContainer */ ConfigValueContainer* Identifier::getConfigValueContainer(const std::string& varname) { std::map<std::string, ConfigValueContainer*>::const_iterator it = configValues_.find(varname); if (it != configValues_.end()) return ((*it).second); else return 0; } /** @brief Returns the ConfigValueContainer of a variable, given by the string of its name in lowercase. @param varname The name of the variable in lowercase @return The ConfigValueContainer */ ConfigValueContainer* Identifier::getLowercaseConfigValueContainer(const std::string& varname) { std::map<std::string, ConfigValueContainer*>::const_iterator it = configValues_LC_.find(varname); if (it != configValues_LC_.end()) return ((*it).second); else return 0; } /** @brief Adds a new console command of this class. @param executor The executor of the command @param bCreateShortcut If this is true a shortcut gets created so you don't have to add the classname to access this command @return The executor of the command */ ConsoleCommand& Identifier::addConsoleCommand(ConsoleCommand* command, bool bCreateShortcut) { std::map<std::string, ConsoleCommand*>::const_iterator it = this->consoleCommands_.find(command->getName()); if (it != this->consoleCommands_.end()) { COUT(2) << "Warning: Overwriting console-command with name " << command->getName() << " in class " << this->getName() << "." << std::endl; } this->bHasConsoleCommands_ = true; this->consoleCommands_[command->getName()] = command; this->consoleCommands_LC_[getLowercase(command->getName())] = command; if (bCreateShortcut) CommandExecutor::addConsoleCommandShortcut(command); return (*command); } /** @brief Returns the executor of a console command with given name. @brief name The name of the requested console command @return The executor of the requested console command */ ConsoleCommand* Identifier::getConsoleCommand(const std::string& name) const { std::map<std::string, ConsoleCommand*>::const_iterator it = this->consoleCommands_.find(name); if (it != this->consoleCommands_.end()) return (*it).second; else return 0; } /** @brief Returns the executor of a console command with given name in lowercase. @brief name The name of the requested console command in lowercae @return The executor of the requested console command */ ConsoleCommand* Identifier::getLowercaseConsoleCommand(const std::string& name) const { std::map<std::string, ConsoleCommand*>::const_iterator it = this->consoleCommands_LC_.find(name); if (it != this->consoleCommands_LC_.end()) return (*it).second; else return 0; } /** @brief Lists the names of all Identifiers in a std::set<const Identifier*>. @param out The outstream @param list The list (or set) of Identifiers @return The outstream */ std::ostream& operator<<(std::ostream& out, const std::set<const Identifier*>& list) { for (std::set<const Identifier*>::const_iterator it = list.begin(); it != list.end(); ++it) out << (*it)->getName() << " "; return out; }} 195 } 196 197 /** 198 @brief Returns true, if the assigned identifier is a direct parent of the given identifier. 199 @param identifier The identifier to compare with 200 */ 201 bool Identifier::isDirectParentOf(const Identifier* identifier) const 202 { 203 return (this->directChildren_->find(identifier) != this->directChildren_->end()); 204 } 205 206 /** 207 @brief Returns the map that stores all Identifiers. 208 @return The map 209 */ 210 std::map<std::string, Identifier*>& Identifier::getIdentifierMapIntern() 211 { 212 static std::map<std::string, Identifier*> identifierMap; 213 return identifierMap; 214 } 215 216 /** 217 @brief Returns the map that stores all Identifiers. 218 @return The map 219 */ 220 std::map<std::string, Identifier*>& Identifier::getLowercaseIdentifierMapIntern() 221 { 222 static std::map<std::string, Identifier*> lowercaseIdentifierMap; 223 return lowercaseIdentifierMap; 224 } 225 226 /** 227 @brief Adds the ConfigValueContainer of a variable, given by the string of its name. 228 @param varname The name of the variablee 229 @param container The container 230 */ 231 void Identifier::addConfigValueContainer(const std::string& varname, ConfigValueContainer* container) 232 { 233 std::map<std::string, ConfigValueContainer*>::const_iterator it = this->configValues_.find(varname); 234 if (it != this->configValues_.end()) 235 { 236 COUT(2) << "Warning: Overwriting config-value with name " << varname << " in class " << this->getName() << "." << std::endl; 237 } 238 239 this->bHasConfigValues_ = true; 240 this->configValues_[varname] = container; 241 this->configValues_LC_[getLowercase(varname)] = container; 242 } 243 244 /** 245 @brief Returns the ConfigValueContainer of a variable, given by the string of its name. 246 @param varname The name of the variable 247 @return The ConfigValueContainer 248 */ 249 ConfigValueContainer* Identifier::getConfigValueContainer(const std::string& varname) 250 { 251 std::map<std::string, ConfigValueContainer*>::const_iterator it = configValues_.find(varname); 252 if (it != configValues_.end()) 253 return ((*it).second); 254 else 255 return 0; 256 } 257 258 /** 259 @brief Returns the ConfigValueContainer of a variable, given by the string of its name in lowercase. 260 @param varname The name of the variable in lowercase 261 @return The ConfigValueContainer 262 */ 263 ConfigValueContainer* Identifier::getLowercaseConfigValueContainer(const std::string& varname) 264 { 265 std::map<std::string, ConfigValueContainer*>::const_iterator it = configValues_LC_.find(varname); 266 if (it != configValues_LC_.end()) 267 return ((*it).second); 268 else 269 return 0; 270 } 271 272 /** 273 @brief Adds a new console command of this class. 274 @param executor The executor of the command 275 @param bCreateShortcut If this is true a shortcut gets created so you don't have to add the classname to access this command 276 @return The executor of the command 277 */ 278 ConsoleCommand& Identifier::addConsoleCommand(ConsoleCommand* command, bool bCreateShortcut) 279 { 280 std::map<std::string, ConsoleCommand*>::const_iterator it = this->consoleCommands_.find(command->getName()); 281 if (it != this->consoleCommands_.end()) 282 { 283 COUT(2) << "Warning: Overwriting console-command with name " << command->getName() << " in class " << this->getName() << "." << std::endl; 284 } 285 286 this->bHasConsoleCommands_ = true; 287 this->consoleCommands_[command->getName()] = command; 288 this->consoleCommands_LC_[getLowercase(command->getName())] = command; 289 290 if (bCreateShortcut) 291 CommandExecutor::addConsoleCommandShortcut(command); 292 293 return (*command); 294 } 295 296 /** 297 @brief Returns the executor of a console command with given name. 298 @brief name The name of the requested console command 299 @return The executor of the requested console command 300 */ 301 ConsoleCommand* Identifier::getConsoleCommand(const std::string& name) const 302 { 303 std::map<std::string, ConsoleCommand*>::const_iterator it = this->consoleCommands_.find(name); 304 if (it != this->consoleCommands_.end()) 305 return (*it).second; 306 else 307 return 0; 308 } 309 310 /** 311 @brief Returns the executor of a console command with given name in lowercase. 312 @brief name The name of the requested console command in lowercae 313 @return The executor of the requested console command 314 */ 315 ConsoleCommand* Identifier::getLowercaseConsoleCommand(const std::string& name) const 316 { 317 std::map<std::string, ConsoleCommand*>::const_iterator it = this->consoleCommands_LC_.find(name); 318 if (it != this->consoleCommands_LC_.end()) 319 return (*it).second; 320 else 321 return 0; 322 } 323 324 /** 325 @brief Lists the names of all Identifiers in a std::set<const Identifier*>. 326 @param out The outstream 327 @param list The list (or set) of Identifiers 328 @return The outstream 329 */ 330 std::ostream& operator<<(std::ostream& out, const std::set<const Identifier*>& list) 331 { 332 for (std::set<const Identifier*>::const_iterator it = list.begin(); it != list.end(); ++it) 333 out << (*it)->getName() << " "; 334 335 return out; 336 } 337 } -
code/branches/network/src/core/Identifier.h
r1494 r1495 1 1 /* 2 2 * ORXONOX - the hottest 3D action shooter ever to exist 3 * > www.orxonox.net < * 3 * > www.orxonox.net < 4 * 4 5 * 5 6 * License notice: … … 62 63 #include "Debug.h" 63 64 #include "Iterator.h" 64 #include "MetaObjectList.h"#include "util/String.h" 65 #include "MetaObjectList.h" 66 #include "util/String.h" 67 65 68 namespace orxonox 66 69 { -
code/branches/network/src/core/InputBuffer.h
r1494 r1495 1 /* * ORXONOX - the hottest 3D action shooter ever to exist * > www.orxonox.net < * * * License notice: * * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * * Author: * Fabian 'x3n' Landau * Co-authors: * Reto Grieder * */#ifndef _InputBuffer_H__#define _InputBuffer_H__#include "CorePrereqs.h"#include <string>#include <list>#include "InputInterfaces.h"#include "OrxonoxClass.h"namespace orxonox{ class BaseInputBufferListenerTuple { public: BaseInputBufferListenerTuple(bool bListenToAllChanges, bool bOnlySingleInput, bool trueKeyFalseChar, char _char, KeyCode::Enum key) : bListenToAllChanges_(bListenToAllChanges), bOnlySingleInput_(bOnlySingleInput), trueKeyFalseChar_(trueKeyFalseChar), char_(_char), key_(key) { } virtual ~BaseInputBufferListenerTuple() { } virtual void callFunction() = 0; bool bListenToAllChanges_; bool bOnlySingleInput_; bool trueKeyFalseChar_; char char_; KeyCode::Enum key_; }; template <class T> class InputBufferListenerTuple : public BaseInputBufferListenerTuple { public: InputBufferListenerTuple(T* listener, void (T::*function)(), bool bListenToAllChanges, bool bOnlySingleInput, bool trueKeyFalseChar, char _char, KeyCode::Enum key) : BaseInputBufferListenerTuple(bListenToAllChanges, bOnlySingleInput, trueKeyFalseChar, _char, key), listener_(listener), function_(function) { } 2 virtual ~InputBufferListenerTuple() { } void callFunction() { (listener_->*function_)(); } T* listener_; void (T::*function_)(); }; class _CoreExport InputBuffer : public KeyHandler, public OrxonoxClass { public: InputBuffer(); InputBuffer(const std::string allowedChars); void setConfigValues(); template <class T> void registerListener(T* listener, void (T::*function)(), bool bOnlySingleInput) { InputBufferListenerTuple<T>* newTuple = new InputBufferListenerTuple<T>(listener, (void (T::*)())function, true, bOnlySingleInput, false, '\0', KeyCode::Unassigned); this->listeners_.insert(this->listeners_.end(), newTuple); } template <class T> void registerListener(T* listener, void (T::*function)() const, bool bOnlySingleInput) { InputBufferListenerTuple<T>* newTuple = new InputBufferListenerTuple<T>(listener, (void (T::*)())function, true, bOnlySingleInput, false, '\0', KeyCode::Unassigned); this->listeners_.insert(this->listeners_.end(), newTuple); } template <class T> void registerListener(T* listener, void (T::*function)(), char _char, bool bOnlySingleInput) { InputBufferListenerTuple<T>* newTuple = new InputBufferListenerTuple<T>(listener, (void (T::*)())function, false, bOnlySingleInput, false, _char, KeyCode::Unassigned); this->listeners_.insert(this->listeners_.end(), newTuple); } template <class T> void registerListener(T* listener, void (T::*function)() const, char _char, bool bOnlySingleInput) { InputBufferListenerTuple<T>* newTuple = new InputBufferListenerTuple<T>(listener, (void (T::*)())function, false, bOnlySingleInput, false, _char, KeyCode::Unassigned); this->listeners_.insert(this->listeners_.end(), newTuple); } template <class T> void registerListener(T* listener, void (T::*function)(), KeyCode::Enum key) { InputBufferListenerTuple<T>* newTuple = new InputBufferListenerTuple<T>(listener, (void (T::*)())function, false, true, true, '\0', key); this->listeners_.insert(this->listeners_.end(), newTuple); } template <class T> void registerListener(T* listener, void (T::*function)() const, KeyCode::Enum key) { InputBufferListenerTuple<T>* newTuple = new InputBufferListenerTuple<T>(listener, (void (T::*)())function, false, true, true, '\0', key); this->listeners_.insert(this->listeners_.end(), newTuple); } template <class T> void unregisterListener(T* listener) { for (std::list<BaseInputBufferListenerTuple*>::iterator it = this->listeners_.begin(); it != this->listeners_.end(); ) { InputBufferListenerTuple<T>* refListener = dynamic_cast<InputBufferListenerTuple<T>*>(*it); if (refListener && refListener->listener_ == listener) this->listeners_.erase(it++); else it++; } } void set(const std::string& input, bool update = true); void insert(const std::string& input, bool update = true); void insert(const char& input, bool update = true); void clear(bool update = true); void removeAtCursor(bool update = true); void removeBehindCursor(bool update = true); void updated(); void updated(const char& update, bool bSingleInput); inline std::string get() const { return this->buffer_; } inline unsigned int getSize() const { return this->buffer_.size(); } inline unsigned int getCursorPosition() const { return this->cursor_; } inline void setCursorPosition(unsigned int cursor) { if (cursor <= this->buffer_.size()) { this->cursor_ = cursor; } } inline void setCursorToEnd() { this->cursor_ = this->buffer_.size(); } inline void setCursorToBegin() { this->cursor_ = 0; } inline void increaseCursor() { if (this->cursor_ < this->buffer_.size()) { ++this->cursor_; } } inline void decreaseCursor() { if (this->cursor_ > 0) { --this->cursor_; } } private: bool charIsAllowed(const char& input); void keyPressed (const KeyEvent& evt); void keyReleased(const KeyEvent& evt) { } void keyHeld (const KeyEvent& evt); void processKey (const KeyEvent &e); void tickInput(float dt, const HandlerState& state); std::string buffer_; std::list<BaseInputBufferListenerTuple*> listeners_; std::string allowedChars_; unsigned int cursor_; KeyCode::Enum lastKey_; float timeSinceKeyPressed_; float timeSinceKeyRepeated_; int keysToRepeat_; float keyRepeatDeleay_; float keyRepeatTime_; };}#endif /* _InputBuffer_H__ */ 1 /* 2 * ORXONOX - the hottest 3D action shooter ever to exist 3 * > www.orxonox.net < 4 * 5 * 6 * License notice: 7 * 8 * This program is free software; you can redistribute it and/or 9 * modify it under the terms of the GNU General Public License 10 * as published by the Free Software Foundation; either version 2 11 * of the License, or (at your option) any later version. 12 * 13 * This program is distributed in the hope that it will be useful, 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 * GNU General Public License for more details. 17 * 18 * You should have received a copy of the GNU General Public License 19 * along with this program; if not, write to the Free Software 20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 21 * 22 * Author: 23 * Fabian 'x3n' Landau 24 * Co-authors: 25 * Reto Grieder 26 * 27 */ 28 29 #ifndef _InputBuffer_H__ 30 #define _InputBuffer_H__ 31 32 #include "CorePrereqs.h" 33 34 #include <string> 35 #include <list> 36 37 #include "InputInterfaces.h" 38 #include "OrxonoxClass.h" 39 40 namespace orxonox 41 { 42 class BaseInputBufferListenerTuple 43 { 44 public: 45 BaseInputBufferListenerTuple(bool bListenToAllChanges, bool bOnlySingleInput, 46 bool trueKeyFalseChar, char _char, KeyCode::Enum key) 47 : bListenToAllChanges_(bListenToAllChanges), bOnlySingleInput_(bOnlySingleInput), 48 trueKeyFalseChar_(trueKeyFalseChar), char_(_char), key_(key) 49 { } 50 virtual ~BaseInputBufferListenerTuple() { } 51 virtual void callFunction() = 0; 52 bool bListenToAllChanges_; 53 bool bOnlySingleInput_; 54 bool trueKeyFalseChar_; 55 char char_; 56 KeyCode::Enum key_; 57 }; 58 59 template <class T> 60 class InputBufferListenerTuple : public BaseInputBufferListenerTuple 61 { 62 public: 63 InputBufferListenerTuple(T* listener, void (T::*function)(), bool bListenToAllChanges, 64 bool bOnlySingleInput, bool trueKeyFalseChar, char _char, KeyCode::Enum key) 65 : BaseInputBufferListenerTuple(bListenToAllChanges, bOnlySingleInput, trueKeyFalseChar, _char, key), 66 listener_(listener), function_(function) 67 { } 68 virtual ~InputBufferListenerTuple() { } 69 void callFunction() 70 { 71 (listener_->*function_)(); 72 } 73 T* listener_; 74 void (T::*function_)(); 75 }; 76 77 class _CoreExport InputBuffer : public KeyHandler, public OrxonoxClass 78 { 79 public: 80 InputBuffer(); 81 InputBuffer(const std::string allowedChars); 82 83 void setConfigValues(); 84 85 template <class T> 86 void registerListener(T* listener, void (T::*function)(), bool bOnlySingleInput) 87 { 88 InputBufferListenerTuple<T>* newTuple = new InputBufferListenerTuple<T>(listener, (void (T::*)())function, true, bOnlySingleInput, false, '\0', KeyCode::Unassigned); 89 this->listeners_.insert(this->listeners_.end(), newTuple); 90 } 91 template <class T> 92 void registerListener(T* listener, void (T::*function)() const, bool bOnlySingleInput) 93 { 94 InputBufferListenerTuple<T>* newTuple = new InputBufferListenerTuple<T>(listener, (void (T::*)())function, true, bOnlySingleInput, false, '\0', KeyCode::Unassigned); 95 this->listeners_.insert(this->listeners_.end(), newTuple); 96 } 97 template <class T> 98 void registerListener(T* listener, void (T::*function)(), char _char, bool bOnlySingleInput) 99 { 100 InputBufferListenerTuple<T>* newTuple = new InputBufferListenerTuple<T>(listener, (void (T::*)())function, false, bOnlySingleInput, false, _char, KeyCode::Unassigned); 101 this->listeners_.insert(this->listeners_.end(), newTuple); 102 } 103 template <class T> 104 void registerListener(T* listener, void (T::*function)() const, char _char, bool bOnlySingleInput) 105 { 106 InputBufferListenerTuple<T>* newTuple = new InputBufferListenerTuple<T>(listener, (void (T::*)())function, false, bOnlySingleInput, false, _char, KeyCode::Unassigned); 107 this->listeners_.insert(this->listeners_.end(), newTuple); 108 } 109 110 template <class T> 111 void registerListener(T* listener, void (T::*function)(), KeyCode::Enum key) 112 { 113 InputBufferListenerTuple<T>* newTuple = new InputBufferListenerTuple<T>(listener, (void (T::*)())function, false, true, true, '\0', key); 114 this->listeners_.insert(this->listeners_.end(), newTuple); 115 } 116 template <class T> 117 void registerListener(T* listener, void (T::*function)() const, KeyCode::Enum key) 118 { 119 InputBufferListenerTuple<T>* newTuple = new InputBufferListenerTuple<T>(listener, (void (T::*)())function, false, true, true, '\0', key); 120 this->listeners_.insert(this->listeners_.end(), newTuple); 121 } 122 123 template <class T> 124 void unregisterListener(T* listener) 125 { 126 for (std::list<BaseInputBufferListenerTuple*>::iterator it = this->listeners_.begin(); it != this->listeners_.end(); ) 127 { 128 InputBufferListenerTuple<T>* refListener = dynamic_cast<InputBufferListenerTuple<T>*>(*it); 129 if (refListener && refListener->listener_ == listener) 130 this->listeners_.erase(it++); 131 else 132 it++; 133 } 134 } 135 136 void set(const std::string& input, bool update = true); 137 void insert(const std::string& input, bool update = true); 138 void insert(const char& input, bool update = true); 139 void clear(bool update = true); 140 void removeAtCursor(bool update = true); 141 void removeBehindCursor(bool update = true); 142 143 void updated(); 144 void updated(const char& update, bool bSingleInput); 145 146 inline std::string get() const 147 { return this->buffer_; } 148 inline unsigned int getSize() const 149 { return this->buffer_.size(); } 150 151 inline unsigned int getCursorPosition() const 152 { return this->cursor_; } 153 inline void setCursorPosition(unsigned int cursor) 154 { if (cursor <= this->buffer_.size()) { this->cursor_ = cursor; } } 155 inline void setCursorToEnd() 156 { this->cursor_ = this->buffer_.size(); } 157 inline void setCursorToBegin() 158 { this->cursor_ = 0; } 159 inline void increaseCursor() 160 { if (this->cursor_ < this->buffer_.size()) { ++this->cursor_; } } 161 inline void decreaseCursor() 162 { if (this->cursor_ > 0) { --this->cursor_; } } 163 164 private: 165 bool charIsAllowed(const char& input); 166 167 void keyPressed (const KeyEvent& evt); 168 void keyReleased(const KeyEvent& evt) { } 169 void keyHeld (const KeyEvent& evt); 170 void processKey (const KeyEvent &e); 171 172 void tickInput(float dt, const HandlerState& state); 173 174 std::string buffer_; 175 std::list<BaseInputBufferListenerTuple*> listeners_; 176 std::string allowedChars_; 177 unsigned int cursor_; 178 179 KeyCode::Enum lastKey_; 180 float timeSinceKeyPressed_; 181 float timeSinceKeyRepeated_; 182 int keysToRepeat_; 183 184 float keyRepeatDeleay_; 185 float keyRepeatTime_; 186 }; 187 } 188 189 #endif /* _InputBuffer_H__ */ -
code/branches/network/src/core/InputManager.cc
r1494 r1495 41 41 #include "KeyBinder.h" 42 42 #include "CommandExecutor.h" 43 #include "ConsoleCommand.h"#include "Shell.h" 43 #include "ConsoleCommand.h" 44 #include "Shell.h" 45 44 46 namespace orxonox 45 47 { … … 150 152 addKeyHandler(buffer_, "buffer"); 151 153 Shell::getInstance().setInputBuffer(buffer_); 154 152 155 keyBinder_ = new KeyBinder(); 153 156 keyBinder_->loadBindings(); … … 194 197 // register our listener in OIS. 195 198 keyboard_->setEventCallback(this); 196 // note: OIS will not detect keys that have already been down when the keyboard was created. CCOUT(ORX_DEBUG) << "Created OIS keyboard" << std::endl; 199 // note: OIS will not detect keys that have already been down when the keyboard was created. 200 CCOUT(ORX_DEBUG) << "Created OIS keyboard" << std::endl; 197 201 return true; 198 202 } … … 310 314 void InputManager::setConfigValues() 311 315 { 312 if (joySticksSize_) { std::vector<MultiTypeMath> coeffPos; 316 if (joySticksSize_) 317 { 318 std::vector<MultiTypeMath> coeffPos; 313 319 std::vector<MultiTypeMath> coeffNeg; 314 320 std::vector<MultiTypeMath> zero; … … 323 329 } 324 330 325 ConfigValueContainer* cont = getIdentifier()->getConfigValueContainer("CoeffPos"); if (!cont) { cont = new ConfigValueContainer(CFT_Keybindings, getIdentifier(), "CoeffPos", coeffPos); getIdentifier()->addConfigValueContainer("CoeffPos", cont); } cont->getValue(&coeffPos); cont = getIdentifier()->getConfigValueContainer("CoeffNeg"); if (!cont) { cont = new ConfigValueContainer(CFT_Keybindings, getIdentifier(), "CoeffNeg", coeffNeg); getIdentifier()->addConfigValueContainer("CoeffNeg", cont); } cont->getValue(&coeffNeg); cont = getIdentifier()->getConfigValueContainer("Zero"); if (!cont) { cont = new ConfigValueContainer(CFT_Keybindings, getIdentifier(), "Zero", zero); getIdentifier()->addConfigValueContainer("Zero", cont); } cont->getValue(&zero); // copy values to our own variables for (unsigned int i = 0; i < 24; i++) { joySticksCalibration_[0].positiveCoeff[i] = coeffPos[i]; joySticksCalibration_[0].negativeCoeff[i] = coeffNeg[i]; joySticksCalibration_[0].zeroStates[i] = zero[i]; } } } 331 ConfigValueContainer* cont = getIdentifier()->getConfigValueContainer("CoeffPos"); 332 if (!cont) 333 { 334 cont = new ConfigValueContainer(CFT_Keybindings, getIdentifier(), "CoeffPos", coeffPos); 335 getIdentifier()->addConfigValueContainer("CoeffPos", cont); 336 } 337 cont->getValue(&coeffPos); 338 339 cont = getIdentifier()->getConfigValueContainer("CoeffNeg"); 340 if (!cont) 341 { 342 cont = new ConfigValueContainer(CFT_Keybindings, getIdentifier(), "CoeffNeg", coeffNeg); 343 getIdentifier()->addConfigValueContainer("CoeffNeg", cont); 344 } 345 cont->getValue(&coeffNeg); 346 347 cont = getIdentifier()->getConfigValueContainer("Zero"); 348 if (!cont) 349 { 350 cont = new ConfigValueContainer(CFT_Keybindings, getIdentifier(), "Zero", zero); 351 getIdentifier()->addConfigValueContainer("Zero", cont); 352 } 353 cont->getValue(&zero); 354 355 // copy values to our own variables 356 for (unsigned int i = 0; i < 24; i++) 357 { 358 joySticksCalibration_[0].positiveCoeff[i] = coeffPos[i]; 359 joySticksCalibration_[0].negativeCoeff[i] = coeffNeg[i]; 360 joySticksCalibration_[0].zeroStates[i] = zero[i]; 361 } 362 } 363 } 326 364 327 365 /** … … 624 662 else 625 663 joySticksCalibration_[0].positiveCoeff[i] = 1.0f; 664 626 665 // config value 627 ConfigValueContainer* cont = getIdentifier()->getConfigValueContainer("CoeffPos"); assert(cont); cont->set(i, joySticksCalibration_[0].positiveCoeff[i]); // negative coefficient 666 ConfigValueContainer* cont = getIdentifier()->getConfigValueContainer("CoeffPos"); 667 assert(cont); 668 cont->set(i, joySticksCalibration_[0].positiveCoeff[i]); 669 670 // negative coefficient 628 671 if (marginalsMin_[i] == INT_MAX) 629 672 marginalsMin_[i] = -32768; 630 673 // coefficients 631 674 if (marginalsMin_[i] - joySticksCalibration_[0].zeroStates[i]) 632 joySticksCalibration_[0].negativeCoeff[i] = -1.0f/(marginalsMin_[i] - joySticksCalibration_[0].zeroStates[i]); else joySticksCalibration_[0].negativeCoeff[i] = 1.0f; // config value 633 cont = getIdentifier()->getConfigValueContainer("CoeffNeg"); assert(cont); cont->set(i, joySticksCalibration_[0].negativeCoeff[i]); // zero states 675 joySticksCalibration_[0].negativeCoeff[i] = -1.0f/(marginalsMin_[i] - joySticksCalibration_[0].zeroStates[i]); 676 else 677 joySticksCalibration_[0].negativeCoeff[i] = 1.0f; 678 // config value 679 cont = getIdentifier()->getConfigValueContainer("CoeffNeg"); 680 assert(cont); 681 cont->set(i, joySticksCalibration_[0].negativeCoeff[i]); 682 683 // zero states 634 684 if (i < 8) 635 685 { … … 647 697 } 648 698 // config value 649 cont = getIdentifier()->getConfigValueContainer("Zero"); assert(cont); cont->set(i, joySticksCalibration_[0].zeroStates[i]); } 699 cont = getIdentifier()->getConfigValueContainer("Zero"); 700 assert(cont); 701 cont->set(i, joySticksCalibration_[0].zeroStates[i]); 702 } 650 703 } 651 704 -
code/branches/network/src/core/KeyBinder.cc
r1494 r1495 41 41 #include "ConfigValueIncludes.h" 42 42 #include "CoreIncludes.h" 43 #include "CommandExecutor.h"#include "ConsoleCommand.h"#include "Executor.h" 43 #include "CommandExecutor.h" 44 #include "ConsoleCommand.h" 45 #include "Executor.h" 44 46 // TODO: only needed by the CalibratorCallback class; move to new file 45 47 #include "InputManager.h" -
code/branches/network/src/core/Script_clean.h
r1494 r1495 1 /* * ORXONOX - the hottest 3D action shooter ever to exist * > www.orxonox.net < * * * License notice: * * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * * Author: * Benjamin Knecht * Co-authors: * ... * *//** 1 /* 2 * ORXONOX - the hottest 3D action shooter ever to exist 3 * > www.orxonox.net < 4 * 5 * 6 * License notice: 7 * 8 * This program is free software; you can redistribute it and/or 9 * modify it under the terms of the GNU General Public License 10 * as published by the Free Software Foundation; either version 2 11 * of the License, or (at your option) any later version. 12 * 13 * This program is distributed in the hope that it will be useful, 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 * GNU General Public License for more details. 17 * 18 * You should have received a copy of the GNU General Public License 19 * along with this program; if not, write to the Free Software 20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 21 * 22 * Author: 23 * Benjamin Knecht 24 * Co-authors: 25 * ... 26 * 27 */ 28 29 /** 2 30 @file script.h 3 31 @brief Representation of an interface to lua -
code/branches/network/src/core/SignalHandler.h
r1494 r1495 1 /* * ORXONOX - the hottest 3D action shooter ever to exist * > www.orxonox.net < * * * License notice: * * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * * Author: * Christoph Renner * Co-authors: * ... * */ 2 /** @file SignalHandler.h @brief Definition of the SignalHandler class.*/#ifndef _SignalHandler_H__ 1 /* 2 * ORXONOX - the hottest 3D action shooter ever to exist 3 * > www.orxonox.net < 4 * 5 * 6 * License notice: 7 * 8 * This program is free software; you can redistribute it and/or 9 * modify it under the terms of the GNU General Public License 10 * as published by the Free Software Foundation; either version 2 11 * of the License, or (at your option) any later version. 12 * 13 * This program is distributed in the hope that it will be useful, 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 * GNU General Public License for more details. 17 * 18 * You should have received a copy of the GNU General Public License 19 * along with this program; if not, write to the Free Software 20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 21 * 22 * Author: 23 * Christoph Renner 24 * Co-authors: 25 * ... 26 * 27 */ 28 29 /** 30 @file SignalHandler.h 31 @brief Definition of the SignalHandler class. 32 */ 33 34 #ifndef _SignalHandler_H__ 3 35 #define _SignalHandler_H__ 4 36 -
code/branches/network/src/cpptcl/CppTcl.cc
r1494 r1495 855 855 interpreter::interpreter() 856 856 { 857 interp_ = Tcl_CreateInterp(); owner_ = true; 858 }interpreter::interpreter(string const &libpath){ interp_ = Tcl_CreateInterp(); owner_ = true; try { this->eval("set tcl_library " + libpath); Tcl_Init(this->interp_); } catch (...) {}} 857 interp_ = Tcl_CreateInterp(); 858 owner_ = true; 859 } 860 861 interpreter::interpreter(string const &libpath) 862 { 863 interp_ = Tcl_CreateInterp(); 864 owner_ = true; 865 866 try 867 { 868 this->eval("set tcl_library " + libpath); 869 Tcl_Init(this->interp_); 870 } catch (...) {} 871 } 859 872 860 873 interpreter::interpreter(Tcl_Interp *interp, bool owner) … … 870 883 // clear all callback info belonging to this interpreter 871 884 clear_definitions(interp_); 872 Tcl_DeleteInterp(interp_); } 885 886 Tcl_DeleteInterp(interp_); 887 } 873 888 } 874 889 -
code/branches/network/src/cpptcl/CppTcl.h
r1494 r1495 467 467 { 468 468 public: 469 interpreter(); interpreter(std::string const &libpath); 469 interpreter(); 470 interpreter(std::string const &libpath); 470 471 interpreter(Tcl_Interp *, bool owner = true); 471 472 ~interpreter(); -
code/branches/network/src/network/dummyclient.cc
r1494 r1495 1 /* * ORXONOX - the hottest 3D action shooter ever to exist * > www.orxonox.net < * * * License notice: * * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * * Author: * Oliver Scheuss, (C) 2007 * Co-authors: * ... * *///o// Dummy client to test ConnectionManager and PacketBuffer classes//// Author: Oliver Scheuss#include <iostream>#include <string>#include <enet/enet.h>#include "util/Sleep.h"#include "PacketManager.h"#include "PacketTypes.h" 2 using namespace std;int main(){ ENetHost * client; ENetAddress address; ENetEvent event; ENetPeer *peer; network::PacketGenerator pck; enet_initialize(); atexit(enet_deinitialize); cout << "Enter address of the server xxx.xxx.xxx.xxx (enter for localhost)" << endl; string str; getline(cin, str); cout << "You entered: " << str << endl; if(str.compare("")==0) str="127.0.0.1"; enet_address_set_host(&address, str.c_str()); address.port = 55556; // create client object client = enet_host_create(NULL, 2, 0, 0); if(client==NULL){ fprintf(stderr, "An error occured"); exit(EXIT_FAILURE); } // connect peer peer = enet_host_connect(client, &address, 2); if(peer==NULL){ fprintf(stderr, "Peer establishing error"); exit(EXIT_FAILURE); } // wait 5 seconds for the connection attempt to succeed if(enet_host_service(client, &event, 5000) > 0 && event.type == ENET_EVENT_TYPE_CONNECT){ cout << "Connection to " << str << " succeeded." << endl; //puts("Connection to localhost:5555 succeeded."); }else{ enet_peer_reset(peer); cout << "Connection to " << str << " failed." << endl; //puts("Connection to localhost:5555 failed."); exit(EXIT_FAILURE); } for(int i=0; i<10; i++){ // weihnachtsmann bringt packete //ENetPacket *packet = enet_packet_create ("packet1234", strlen("packet1234") + 1, ENET_PACKET_FLAG_RELIABLE); // extend the packet and append the string foo to it // send packet to peer on channel id 0 enet_peer_send(peer, 1, pck.chatMessage("test2")); // keep the timeout very small for low delay if(enet_host_service(client, &event, 1)==0){ cout << "successfully sent: " << event.type << endl; }else{ cout << "failed sending" << endl; } usleep(1000000); } // now disconnect // enet_peer_disconnect (peer); enet_peer_disconnect (peer, 0); // 3 seconds timeout while(enet_host_service(client, &event, 3000) > 0){ switch (event.type) { case ENET_EVENT_TYPE_RECEIVE: enet_packet_destroy(event.packet); break; case ENET_EVENT_TYPE_DISCONNECT: puts("Disconnection succeeded."); return 0; } } // if disconnect failed enet_peer_reset(peer); return 0;} 1 /* 2 * ORXONOX - the hottest 3D action shooter ever to exist 3 * > www.orxonox.net < 4 * 5 * 6 * License notice: 7 * 8 * This program is free software; you can redistribute it and/or 9 * modify it under the terms of the GNU General Public License 10 * as published by the Free Software Foundation; either version 2 11 * of the License, or (at your option) any later version. 12 * 13 * This program is distributed in the hope that it will be useful, 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 * GNU General Public License for more details. 17 * 18 * You should have received a copy of the GNU General Public License 19 * along with this program; if not, write to the Free Software 20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 21 * 22 * Author: 23 * Oliver Scheuss, (C) 2007 24 * Co-authors: 25 * ... 26 * 27 */ 28 29 //o 30 // Dummy client to test ConnectionManager and PacketBuffer classes 31 // 32 // Author: Oliver Scheuss 33 34 #include <iostream> 35 #include <string> 36 #include <enet/enet.h> 37 38 #include "util/Sleep.h" 39 #include "PacketManager.h" 40 #include "PacketTypes.h" 41 42 using namespace std; 43 44 int main(){ 45 ENetHost * client; 46 ENetAddress address; 47 ENetEvent event; 48 ENetPeer *peer; 49 network::PacketGenerator pck; 50 51 enet_initialize(); 52 atexit(enet_deinitialize); 53 54 cout << "Enter address of the server xxx.xxx.xxx.xxx (enter for localhost)" << endl; 55 string str; 56 getline(cin, str); 57 cout << "You entered: " << str << endl; 58 if(str.compare("")==0) 59 str="127.0.0.1"; 60 61 enet_address_set_host(&address, str.c_str()); 62 address.port = 55556; 63 64 // create client object 65 client = enet_host_create(NULL, 2, 0, 0); 66 67 if(client==NULL){ 68 fprintf(stderr, "An error occured"); 69 exit(EXIT_FAILURE); 70 } 71 // connect peer 72 peer = enet_host_connect(client, &address, 2); 73 if(peer==NULL){ 74 fprintf(stderr, "Peer establishing error"); 75 exit(EXIT_FAILURE); 76 } 77 // wait 5 seconds for the connection attempt to succeed 78 if(enet_host_service(client, &event, 5000) > 0 && event.type == ENET_EVENT_TYPE_CONNECT){ 79 cout << "Connection to " << str << " succeeded." << endl; 80 //puts("Connection to localhost:5555 succeeded."); 81 }else{ 82 enet_peer_reset(peer); 83 cout << "Connection to " << str << " failed." << endl; 84 //puts("Connection to localhost:5555 failed."); 85 exit(EXIT_FAILURE); 86 } 87 88 for(int i=0; i<10; i++){ 89 // weihnachtsmann bringt packete 90 //ENetPacket *packet = enet_packet_create ("packet1234", strlen("packet1234") + 1, ENET_PACKET_FLAG_RELIABLE); 91 // extend the packet and append the string foo to it 92 // send packet to peer on channel id 0 93 enet_peer_send(peer, 1, pck.chatMessage("test2")); 94 // keep the timeout very small for low delay 95 if(enet_host_service(client, &event, 1)==0){ 96 cout << "successfully sent: " << event.type << endl; 97 }else{ 98 cout << "failed sending" << endl; 99 } 100 usleep(1000000); 101 } 102 103 // now disconnect 104 // enet_peer_disconnect (peer); 105 enet_peer_disconnect (peer, 0); 106 // 3 seconds timeout 107 while(enet_host_service(client, &event, 3000) > 0){ 108 switch (event.type) 109 { 110 case ENET_EVENT_TYPE_RECEIVE: 111 enet_packet_destroy(event.packet); 112 break; 113 case ENET_EVENT_TYPE_DISCONNECT: 114 puts("Disconnection succeeded."); 115 return 0; 116 } 117 } 118 // if disconnect failed 119 enet_peer_reset(peer); 120 121 122 123 return 0; 124 } -
code/branches/network/src/network/dummyclient2.cc
r1494 r1495 1 /* * ORXONOX - the hottest 3D action shooter ever to exist * > www.orxonox.net < * * * License notice: * * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * * Author: * Oliver Scheuss, (C) 2007 * Co-authors: * ... * */ 1 /* 2 * ORXONOX - the hottest 3D action shooter ever to exist 3 * > www.orxonox.net < 4 * 5 * 6 * License notice: 7 * 8 * This program is free software; you can redistribute it and/or 9 * modify it under the terms of the GNU General Public License 10 * as published by the Free Software Foundation; either version 2 11 * of the License, or (at your option) any later version. 12 * 13 * This program is distributed in the hope that it will be useful, 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 * GNU General Public License for more details. 17 * 18 * You should have received a copy of the GNU General Public License 19 * along with this program; if not, write to the Free Software 20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 21 * 22 * Author: 23 * Oliver Scheuss, (C) 2007 24 * Co-authors: 25 * ... 26 * 27 */ 28 2 29 // 3 30 // Dummy client to test ConnectionManager, PacketBuffer, ClientConnection and other classes -
code/branches/network/src/network/dummyclient3.cc
r1494 r1495 1 /* * ORXONOX - the hottest 3D action shooter ever to exist * > www.orxonox.net < * * * License notice: * * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * * Author: * ... * Co-authors: * ... * */#include "Client.h" 1 /* 2 * ORXONOX - the hottest 3D action shooter ever to exist 3 * > www.orxonox.net < 4 * 5 * 6 * License notice: 7 * 8 * This program is free software; you can redistribute it and/or 9 * modify it under the terms of the GNU General Public License 10 * as published by the Free Software Foundation; either version 2 11 * of the License, or (at your option) any later version. 12 * 13 * This program is distributed in the hope that it will be useful, 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 * GNU General Public License for more details. 17 * 18 * You should have received a copy of the GNU General Public License 19 * along with this program; if not, write to the Free Software 20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 21 * 22 * Author: 23 * ... 24 * Co-authors: 25 * ... 26 * 27 */ 28 29 #include "Client.h" 2 30 3 31 #include <iostream> … … 22 50 23 51 Client client( str, PORT ); 24 if ( client.establishConnection() ) { 25 COUT(3) << "connection established" << std::endl; } 26 else { COUT(0) << "problems establishing connection" << std::endl; } 52 if ( client.establishConnection() ) 53 { 54 COUT(3) << "connection established" << std::endl; 55 } 56 else 57 { 58 COUT(0) << "problems establishing connection" << std::endl; 59 } 27 60 char message[10000]; 28 61 char signs[] = "abcdefghijklmnopqrstuvwxy"; -
code/branches/network/src/network/dummyserver.cc
r1494 r1495 1 /* * ORXONOX - the hottest 3D action shooter ever to exist * > www.orxonox.net < * * * License notice: * * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * * Author: * Oliver Scheuss, (C) 2007 * Co-authors: * ... * *///// Dummy server to test ConnectionManager and PacketBuffer classes//// Author: Oliver Scheuss#include <iostream>#include <enet/enet.h>#include "util/Sleep.h"#include "ConnectionManager.h"#include "PacketManager.h"#include "PacketTypes.h" 2 #include "ClientInformation.h"using namespace network;int main(){ bool quit=false; ENetPacket *packet; ClientInformation clients; ConnectionManager server = ConnectionManager(&clients); server.createListener(); PacketDecoder dec; while(!quit){ if(server.queueEmpty()) // Warning: usleep(100) is Sleep(100/1000) = Sleep(0), which is nothing! usleep(1); else{ ENetAddress addr; packet=server.getPacket(addr); if(packet==NULL){ // there was some error //std::cout << "null pointer" << std::endl; quit=true; } else{ //std::cout << "We received: " << packet->data << std::endl; dec.elaborate(packet, 1); } } } server.quitListener(); return 0;} 1 /* 2 * ORXONOX - the hottest 3D action shooter ever to exist 3 * > www.orxonox.net < 4 * 5 * 6 * License notice: 7 * 8 * This program is free software; you can redistribute it and/or 9 * modify it under the terms of the GNU General Public License 10 * as published by the Free Software Foundation; either version 2 11 * of the License, or (at your option) any later version. 12 * 13 * This program is distributed in the hope that it will be useful, 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 * GNU General Public License for more details. 17 * 18 * You should have received a copy of the GNU General Public License 19 * along with this program; if not, write to the Free Software 20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 21 * 22 * Author: 23 * Oliver Scheuss, (C) 2007 24 * Co-authors: 25 * ... 26 * 27 */ 28 29 // 30 // Dummy server to test ConnectionManager and PacketBuffer classes 31 // 32 // Author: Oliver Scheuss 33 34 #include <iostream> 35 #include <enet/enet.h> 36 37 #include "util/Sleep.h" 38 #include "ConnectionManager.h" 39 #include "PacketManager.h" 40 #include "PacketTypes.h" 41 #include "ClientInformation.h" 42 43 using namespace network; 44 45 int main(){ 46 bool quit=false; 47 ENetPacket *packet; 48 ClientInformation clients; 49 ConnectionManager server = ConnectionManager(&clients); 50 server.createListener(); 51 52 PacketDecoder dec; 53 54 while(!quit){ 55 if(server.queueEmpty()) 56 // Warning: usleep(100) is Sleep(100/1000) = Sleep(0), which is nothing! 57 usleep(1); 58 else{ 59 ENetAddress addr; 60 packet=server.getPacket(addr); 61 if(packet==NULL){ 62 // there was some error 63 //std::cout << "null pointer" << std::endl; 64 quit=true; 65 } 66 else{ 67 //std::cout << "We received: " << packet->data << std::endl; 68 dec.elaborate(packet, 1); 69 } 70 } 71 } 72 server.quitListener(); 73 return 0; 74 } -
code/branches/network/src/network/dummyserver3.cc
r1494 r1495 1 /* * ORXONOX - the hottest 3D action shooter ever to exist * > www.orxonox.net < * * * License notice: * * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * * Author: * Oliver Scheuss, (C) 2007 * Co-authors: * ... * */#include "Server.h" 1 /* 2 * ORXONOX - the hottest 3D action shooter ever to exist 3 * > www.orxonox.net < 4 * 5 * 6 * License notice: 7 * 8 * This program is free software; you can redistribute it and/or 9 * modify it under the terms of the GNU General Public License 10 * as published by the Free Software Foundation; either version 2 11 * of the License, or (at your option) any later version. 12 * 13 * This program is distributed in the hope that it will be useful, 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 * GNU General Public License for more details. 17 * 18 * You should have received a copy of the GNU General Public License 19 * along with this program; if not, write to the Free Software 20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 21 * 22 * Author: 23 * Oliver Scheuss, (C) 2007 24 * Co-authors: 25 * ... 26 * 27 */ 28 29 #include "Server.h" 2 30 3 31 #include <iostream> -
code/branches/network/src/ois/linux/LinuxKeyboard.cpp
r1494 r1495 1 /*The zlib/libpng LicenseCopyright (c) 2005-2007 Phillip Castaneda (pjcast -- www.wreckedgames.com)This software is provided 'as-is', without any express or implied warranty. In no event willthe authors be held liable for any damages arising from the use of this software.Permission is granted to anyone to use this software for any purpose, including commercialapplications, and to alter it and redistribute it freely, subject to the followingrestrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution.*/#include "linux/LinuxInputManager.h"#include "linux/LinuxKeyboard.h"#include "OISException.h"#include "OISEvents.h"#include <X11/keysym.h>#include <X11/Xutil.h>#include <cstring>using namespace OIS;#include <iostream>//-------------------------------------------------------------------//LinuxKeyboard::LinuxKeyboard(InputManager* creator, bool buffered, bool grab, bool useXRepeat) : Keyboard(creator->inputSystemName(), buffered, 0, creator){ setlocale(LC_CTYPE, ""); //Set the locale to (hopefully) the users LANG UTF-8 Env var display = 0; window = 0; grabKeyboard = grab; keyFocusLost = false; xAutoRepeat = useXRepeat; oldXAutoRepeat = false; //X Key Map to KeyCode keyConversion.insert(XtoOIS_KeyMap::value_type(XK_1, KC_1)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_2, KC_2)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_3, KC_3)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_4, KC_4)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_5, KC_5)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_6, KC_6)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_7, KC_7)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_8, KC_8)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_9, KC_9)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_0, KC_0)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_BackSpace, KC_BACK)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_minus, KC_MINUS)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_equal, KC_EQUALS)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_space, KC_SPACE)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_comma, KC_COMMA)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_period, KC_PERIOD)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_backslash, KC_BACKSLASH)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_slash, KC_SLASH)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_bracketleft, KC_LBRACKET)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_bracketright, KC_RBRACKET)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_Escape,KC_ESCAPE)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_Caps_Lock, KC_CAPITAL)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_Tab, KC_TAB)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_Return, KC_RETURN)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_Control_L, KC_LCONTROL)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_Control_R, KC_RCONTROL)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_colon, KC_COLON)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_semicolon, KC_SEMICOLON)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_apostrophe, KC_APOSTROPHE)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_grave, KC_GRAVE)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_b, KC_B)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_a, KC_A)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_c, KC_C)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_d, KC_D)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_e, KC_E)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_f, KC_F)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_g, KC_G)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_h, KC_H)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_i, KC_I)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_j, KC_J)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_k, KC_K)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_l, KC_L)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_m, KC_M)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_n, KC_N)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_o, KC_O)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_p, KC_P)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_q, KC_Q)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_r, KC_R)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_s, KC_S)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_t, KC_T)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_u, KC_U)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_v, KC_V)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_w, KC_W)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_x, KC_X)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_y, KC_Y)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_z, KC_Z)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_F1, KC_F1)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_F2, KC_F2)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_F3, KC_F3)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_F4, KC_F4)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_F5, KC_F5)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_F6, KC_F6)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_F7, KC_F7)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_F8, KC_F8)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_F9, KC_F9)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_F10, KC_F10)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_F11, KC_F11)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_F12, KC_F12)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_F13, KC_F13)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_F14, KC_F14)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_F15, KC_F15)); //Keypad keyConversion.insert(XtoOIS_KeyMap::value_type(XK_KP_0, KC_NUMPAD0)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_KP_1, KC_NUMPAD1)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_KP_2, KC_NUMPAD2)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_KP_3, KC_NUMPAD3)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_KP_4, KC_NUMPAD4)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_KP_5, KC_NUMPAD5)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_KP_6, KC_NUMPAD6)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_KP_7, KC_NUMPAD7)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_KP_8, KC_NUMPAD8)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_KP_9, KC_NUMPAD9)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_KP_Add, KC_ADD)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_KP_Subtract, KC_SUBTRACT)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_KP_Decimal, KC_DECIMAL)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_KP_Equal, KC_NUMPADEQUALS)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_KP_Divide, KC_DIVIDE)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_KP_Multiply, KC_MULTIPLY)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_KP_Enter, KC_NUMPADENTER)); //Keypad with numlock off keyConversion.insert(XtoOIS_KeyMap::value_type(XK_KP_Home, KC_NUMPAD7)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_KP_Up, KC_NUMPAD8)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_KP_Page_Up, KC_NUMPAD9)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_KP_Left, KC_NUMPAD4)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_KP_Begin, KC_NUMPAD5)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_KP_Right, KC_NUMPAD6)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_KP_End, KC_NUMPAD1)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_KP_Down, KC_NUMPAD2)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_KP_Page_Down, KC_NUMPAD3)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_KP_Insert, KC_NUMPAD0)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_KP_Delete, KC_DECIMAL)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_Up, KC_UP)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_Down, KC_DOWN)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_Left, KC_LEFT)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_Right, KC_RIGHT)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_Page_Up, KC_PGUP)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_Page_Down, KC_PGDOWN)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_Home, KC_HOME)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_End, KC_END)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_Num_Lock, KC_NUMLOCK)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_Print, KC_SYSRQ)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_Scroll_Lock, KC_SCROLL)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_Pause, KC_PAUSE)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_Shift_R, KC_RSHIFT)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_Shift_L, KC_LSHIFT)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_Alt_R, KC_RMENU)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_Alt_L, KC_LMENU)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_Insert, KC_INSERT)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_Delete, KC_DELETE)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_Super_L, KC_LWIN)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_Super_R, KC_RWIN)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_Menu, KC_APPS)); static_cast<LinuxInputManager*>(mCreator)->_setKeyboardUsed(true);}//-------------------------------------------------------------------//void LinuxKeyboard::_initialize(){ //Clear our keyboard state buffer memset( &KeyBuffer, 0, 256 ); mModifiers = 0; if( display ) XCloseDisplay(display); display = 0; window = static_cast<LinuxInputManager*>(mCreator)->_getWindow(); //Create our local X mListener connection if( !(display = XOpenDisplay(0)) ) OIS_EXCEPT(E_General, "LinuxKeyboard::_initialize >> Error opening X!"); //Set it to recieve Input events if( XSelectInput(display, window, KeyPressMask | KeyReleaseMask) == BadWindow ) OIS_EXCEPT(E_General, "LinuxKeyboard::_initialize: X error!"); if( grabKeyboard ) XGrabKeyboard(display,window,True,GrabModeAsync,GrabModeAsync,CurrentTime); keyFocusLost = false; if( xAutoRepeat == false ) { //We do not want to blindly turn on autorepeat later when quiting if //it was not on to begin with.. So, let us check and see first XKeyboardState old; XGetKeyboardControl( display, &old ); oldXAutoRepeat = false; if( old.global_auto_repeat == AutoRepeatModeOn ) oldXAutoRepeat = true; XAutoRepeatOff( display ); }}//-------------------------------------------------------------------//LinuxKeyboard::~LinuxKeyboard(){ if( display ) { if( oldXAutoRepeat ) XAutoRepeatOn(display); if( grabKeyboard ) XUngrabKeyboard(display, CurrentTime); XCloseDisplay(display); } static_cast<LinuxInputManager*>(mCreator)->_setKeyboardUsed(true);}//-------------------------------------------------------------------//unsigned int UTF8ToUTF32(unsigned char* buf){ unsigned char &FirstChar = buf[0]; if(FirstChar < 128) return FirstChar; unsigned int val = 0; unsigned int len = 0; if((FirstChar & 0xE0) == 0xC0) //2 Chars { len = 2; val = FirstChar & 0x1F; } else if((FirstChar & 0xF0) == 0xE0) //3 Chars { len = 3; val = FirstChar & 0x0F; } else if((FirstChar & 0xF8) == 0xF0) //4 Chars { len = 4; val = FirstChar & 0x07; } else if((FirstChar & 0xFC) == 0xF8) //5 Chars { len = 5; val = FirstChar & 0x03; } else // if((FirstChar & 0xFE) == 0xFC) //6 Chars { len = 6; val = FirstChar & 0x01; } for(int i = 1; i < len; i++) val = (val << 6) | (buf[i] & 0x3F); return val;}//-------------------------------------------------------------------//bool LinuxKeyboard::isKeyDown( KeyCode key ) const{ return (KeyBuffer[key]);}//-------------------------------------------------------------------//void LinuxKeyboard::capture(){ KeySym key; XEvent event; LinuxInputManager* linMan = static_cast<LinuxInputManager*>(mCreator); while( XPending(display) > 0 ) { 2 XNextEvent(display, &event); 3 4 if( KeyPress == event.type ) { unsigned int character = 0; if( mTextMode != Off ) { unsigned char buffer[6] = {0,0,0,0,0,0}; XLookupString(&event.xkey, (char*)buffer, 6, &key, 0); if( mTextMode == Unicode ) character = UTF8ToUTF32(buffer); else if( mTextMode == Ascii) character = buffer[0]; } //Mask out the modifier states X11 sets and read again event.xkey.state &= ~ShiftMask; event.xkey.state &= ~LockMask; XLookupString(&event.xkey, 0, 0,&key, 0); _injectKeyDown(key, character); //Just printing out some debugging info.. to verify all chars are mapped //std::cout << "KEY PRESSED X=" << event.xkey.keycode; //std::cout << "\n KeySym=" << key << std::endl; //Check for Alt-Tab if( event.xkey.state & Mod1Mask && key == XK_Tab ) linMan->_setGrabState(false); } 5 else if( KeyRelease == event.type ) { //Mask out the modifier states X sets.. or we will get improper values event.xkey.state &= ~ShiftMask; event.xkey.state &= ~LockMask; //Else, it is a valid key release XLookupString(&event.xkey,NULL,0,&key,NULL); _injectKeyUp(key); 6 } } //If grabbing mode is on.. Handle focus lost/gained via Alt-Tab and mouse clicks if( grabKeyboard ) { if( linMan->_getGrabState() == false ) { // are no longer grabbing if( keyFocusLost == false ) { //UnGrab KeyBoard XUngrabKeyboard(display, CurrentTime); keyFocusLost = true; } } else { //We are grabbing - and regained focus if( keyFocusLost == true ) { //ReGrab KeyBoard XGrabKeyboard(display, window, True, GrabModeAsync, GrabModeAsync, CurrentTime); keyFocusLost = false; } } }}//-------------------------------------------------------------------//void LinuxKeyboard::setBuffered(bool buffered){ mBuffered = buffered;}//-------------------------------------------------------------------//bool LinuxKeyboard::_injectKeyDown( KeySym key, int text ){ KeyCode kc = keyConversion[key]; KeyBuffer[kc] = 1; //Turn on modifier flags if( kc == KC_LCONTROL || kc == KC_RCONTROL) mModifiers |= Ctrl; else if( kc == KC_LSHIFT || kc == KC_RSHIFT ) mModifiers |= Shift; else if( kc == KC_LMENU || kc == KC_RMENU ) mModifiers |= Alt; if( mBuffered && mListener ) return mListener->keyPressed(KeyEvent(this,kc,text)); return true;}//-------------------------------------------------------------------//bool LinuxKeyboard::_injectKeyUp( KeySym key ){ KeyCode kc = keyConversion[key]; KeyBuffer[kc] = 0; //Turn off modifier flags if( kc == KC_LCONTROL || kc == KC_RCONTROL) mModifiers &= ~Ctrl; else if( kc == KC_LSHIFT || kc == KC_RSHIFT ) mModifiers &= ~Shift; else if( kc == KC_LMENU || kc == KC_RMENU ) mModifiers &= ~Alt; if( mBuffered && mListener ) return mListener->keyReleased(KeyEvent(this, kc, 0)); return true;}//-------------------------------------------------------------------//const std::string& LinuxKeyboard::getAsString( KeyCode kc ){ mGetString = "Unknown"; char *temp = 0; XtoOIS_KeyMap::iterator i = keyConversion.begin(), e = keyConversion.end(); for( ; i != e; ++i ) { if( i->second == kc ) { temp = XKeysymToString(i->first); if( temp ) mGetString = temp; break; } } return mGetString;}//-------------------------------------------------------------------//void LinuxKeyboard::copyKeyStates( char keys[256] ) const{ memcpy( keys, KeyBuffer, 256 );} 1 /* 2 The zlib/libpng License 3 4 Copyright (c) 2005-2007 Phillip Castaneda (pjcast -- www.wreckedgames.com) 5 6 This software is provided 'as-is', without any express or implied warranty. In no event will 7 the authors be held liable for any damages arising from the use of this software. 8 9 Permission is granted to anyone to use this software for any purpose, including commercial 10 applications, and to alter it and redistribute it freely, subject to the following 11 restrictions: 12 13 1. The origin of this software must not be misrepresented; you must not claim that 14 you wrote the original software. If you use this software in a product, 15 an acknowledgment in the product documentation would be appreciated but is 16 not required. 17 18 2. Altered source versions must be plainly marked as such, and must not be 19 misrepresented as being the original software. 20 21 3. This notice may not be removed or altered from any source distribution. 22 */ 23 #include "linux/LinuxInputManager.h" 24 #include "linux/LinuxKeyboard.h" 25 #include "OISException.h" 26 #include "OISEvents.h" 27 28 #include <X11/keysym.h> 29 #include <X11/Xutil.h> 30 #include <cstring> 31 32 using namespace OIS; 33 #include <iostream> 34 //-------------------------------------------------------------------// 35 LinuxKeyboard::LinuxKeyboard(InputManager* creator, bool buffered, bool grab, bool useXRepeat) 36 : Keyboard(creator->inputSystemName(), buffered, 0, creator) 37 { 38 setlocale(LC_CTYPE, ""); //Set the locale to (hopefully) the users LANG UTF-8 Env var 39 40 display = 0; 41 window = 0; 42 43 grabKeyboard = grab; 44 keyFocusLost = false; 45 46 xAutoRepeat = useXRepeat; 47 oldXAutoRepeat = false; 48 49 //X Key Map to KeyCode 50 keyConversion.insert(XtoOIS_KeyMap::value_type(XK_1, KC_1)); 51 keyConversion.insert(XtoOIS_KeyMap::value_type(XK_2, KC_2)); 52 keyConversion.insert(XtoOIS_KeyMap::value_type(XK_3, KC_3)); 53 keyConversion.insert(XtoOIS_KeyMap::value_type(XK_4, KC_4)); 54 keyConversion.insert(XtoOIS_KeyMap::value_type(XK_5, KC_5)); 55 keyConversion.insert(XtoOIS_KeyMap::value_type(XK_6, KC_6)); 56 keyConversion.insert(XtoOIS_KeyMap::value_type(XK_7, KC_7)); 57 keyConversion.insert(XtoOIS_KeyMap::value_type(XK_8, KC_8)); 58 keyConversion.insert(XtoOIS_KeyMap::value_type(XK_9, KC_9)); 59 keyConversion.insert(XtoOIS_KeyMap::value_type(XK_0, KC_0)); 60 61 keyConversion.insert(XtoOIS_KeyMap::value_type(XK_BackSpace, KC_BACK)); 62 63 keyConversion.insert(XtoOIS_KeyMap::value_type(XK_minus, KC_MINUS)); 64 keyConversion.insert(XtoOIS_KeyMap::value_type(XK_equal, KC_EQUALS)); 65 keyConversion.insert(XtoOIS_KeyMap::value_type(XK_space, KC_SPACE)); 66 keyConversion.insert(XtoOIS_KeyMap::value_type(XK_comma, KC_COMMA)); 67 keyConversion.insert(XtoOIS_KeyMap::value_type(XK_period, KC_PERIOD)); 68 69 keyConversion.insert(XtoOIS_KeyMap::value_type(XK_backslash, KC_BACKSLASH)); 70 keyConversion.insert(XtoOIS_KeyMap::value_type(XK_slash, KC_SLASH)); 71 keyConversion.insert(XtoOIS_KeyMap::value_type(XK_bracketleft, KC_LBRACKET)); 72 keyConversion.insert(XtoOIS_KeyMap::value_type(XK_bracketright, KC_RBRACKET)); 73 74 keyConversion.insert(XtoOIS_KeyMap::value_type(XK_Escape,KC_ESCAPE)); 75 keyConversion.insert(XtoOIS_KeyMap::value_type(XK_Caps_Lock, KC_CAPITAL)); 76 77 keyConversion.insert(XtoOIS_KeyMap::value_type(XK_Tab, KC_TAB)); 78 keyConversion.insert(XtoOIS_KeyMap::value_type(XK_Return, KC_RETURN)); 79 keyConversion.insert(XtoOIS_KeyMap::value_type(XK_Control_L, KC_LCONTROL)); 80 keyConversion.insert(XtoOIS_KeyMap::value_type(XK_Control_R, KC_RCONTROL)); 81 82 keyConversion.insert(XtoOIS_KeyMap::value_type(XK_colon, KC_COLON)); 83 keyConversion.insert(XtoOIS_KeyMap::value_type(XK_semicolon, KC_SEMICOLON)); 84 keyConversion.insert(XtoOIS_KeyMap::value_type(XK_apostrophe, KC_APOSTROPHE)); 85 keyConversion.insert(XtoOIS_KeyMap::value_type(XK_grave, KC_GRAVE)); 86 87 keyConversion.insert(XtoOIS_KeyMap::value_type(XK_b, KC_B)); 88 keyConversion.insert(XtoOIS_KeyMap::value_type(XK_a, KC_A)); 89 keyConversion.insert(XtoOIS_KeyMap::value_type(XK_c, KC_C)); 90 keyConversion.insert(XtoOIS_KeyMap::value_type(XK_d, KC_D)); 91 keyConversion.insert(XtoOIS_KeyMap::value_type(XK_e, KC_E)); 92 keyConversion.insert(XtoOIS_KeyMap::value_type(XK_f, KC_F)); 93 keyConversion.insert(XtoOIS_KeyMap::value_type(XK_g, KC_G)); 94 keyConversion.insert(XtoOIS_KeyMap::value_type(XK_h, KC_H)); 95 keyConversion.insert(XtoOIS_KeyMap::value_type(XK_i, KC_I)); 96 keyConversion.insert(XtoOIS_KeyMap::value_type(XK_j, KC_J)); 97 keyConversion.insert(XtoOIS_KeyMap::value_type(XK_k, KC_K)); 98 keyConversion.insert(XtoOIS_KeyMap::value_type(XK_l, KC_L)); 99 keyConversion.insert(XtoOIS_KeyMap::value_type(XK_m, KC_M)); 100 keyConversion.insert(XtoOIS_KeyMap::value_type(XK_n, KC_N)); 101 keyConversion.insert(XtoOIS_KeyMap::value_type(XK_o, KC_O)); 102 keyConversion.insert(XtoOIS_KeyMap::value_type(XK_p, KC_P)); 103 keyConversion.insert(XtoOIS_KeyMap::value_type(XK_q, KC_Q)); 104 keyConversion.insert(XtoOIS_KeyMap::value_type(XK_r, KC_R)); 105 keyConversion.insert(XtoOIS_KeyMap::value_type(XK_s, KC_S)); 106 keyConversion.insert(XtoOIS_KeyMap::value_type(XK_t, KC_T)); 107 keyConversion.insert(XtoOIS_KeyMap::value_type(XK_u, KC_U)); 108 keyConversion.insert(XtoOIS_KeyMap::value_type(XK_v, KC_V)); 109 keyConversion.insert(XtoOIS_KeyMap::value_type(XK_w, KC_W)); 110 keyConversion.insert(XtoOIS_KeyMap::value_type(XK_x, KC_X)); 111 keyConversion.insert(XtoOIS_KeyMap::value_type(XK_y, KC_Y)); 112 keyConversion.insert(XtoOIS_KeyMap::value_type(XK_z, KC_Z)); 113 114 keyConversion.insert(XtoOIS_KeyMap::value_type(XK_F1, KC_F1)); 115 keyConversion.insert(XtoOIS_KeyMap::value_type(XK_F2, KC_F2)); 116 keyConversion.insert(XtoOIS_KeyMap::value_type(XK_F3, KC_F3)); 117 keyConversion.insert(XtoOIS_KeyMap::value_type(XK_F4, KC_F4)); 118 keyConversion.insert(XtoOIS_KeyMap::value_type(XK_F5, KC_F5)); 119 keyConversion.insert(XtoOIS_KeyMap::value_type(XK_F6, KC_F6)); 120 keyConversion.insert(XtoOIS_KeyMap::value_type(XK_F7, KC_F7)); 121 keyConversion.insert(XtoOIS_KeyMap::value_type(XK_F8, KC_F8)); 122 keyConversion.insert(XtoOIS_KeyMap::value_type(XK_F9, KC_F9)); 123 keyConversion.insert(XtoOIS_KeyMap::value_type(XK_F10, KC_F10)); 124 keyConversion.insert(XtoOIS_KeyMap::value_type(XK_F11, KC_F11)); 125 keyConversion.insert(XtoOIS_KeyMap::value_type(XK_F12, KC_F12)); 126 keyConversion.insert(XtoOIS_KeyMap::value_type(XK_F13, KC_F13)); 127 keyConversion.insert(XtoOIS_KeyMap::value_type(XK_F14, KC_F14)); 128 keyConversion.insert(XtoOIS_KeyMap::value_type(XK_F15, KC_F15)); 129 130 //Keypad 131 keyConversion.insert(XtoOIS_KeyMap::value_type(XK_KP_0, KC_NUMPAD0)); 132 keyConversion.insert(XtoOIS_KeyMap::value_type(XK_KP_1, KC_NUMPAD1)); 133 keyConversion.insert(XtoOIS_KeyMap::value_type(XK_KP_2, KC_NUMPAD2)); 134 keyConversion.insert(XtoOIS_KeyMap::value_type(XK_KP_3, KC_NUMPAD3)); 135 keyConversion.insert(XtoOIS_KeyMap::value_type(XK_KP_4, KC_NUMPAD4)); 136 keyConversion.insert(XtoOIS_KeyMap::value_type(XK_KP_5, KC_NUMPAD5)); 137 keyConversion.insert(XtoOIS_KeyMap::value_type(XK_KP_6, KC_NUMPAD6)); 138 keyConversion.insert(XtoOIS_KeyMap::value_type(XK_KP_7, KC_NUMPAD7)); 139 keyConversion.insert(XtoOIS_KeyMap::value_type(XK_KP_8, KC_NUMPAD8)); 140 keyConversion.insert(XtoOIS_KeyMap::value_type(XK_KP_9, KC_NUMPAD9)); 141 keyConversion.insert(XtoOIS_KeyMap::value_type(XK_KP_Add, KC_ADD)); 142 keyConversion.insert(XtoOIS_KeyMap::value_type(XK_KP_Subtract, KC_SUBTRACT)); 143 keyConversion.insert(XtoOIS_KeyMap::value_type(XK_KP_Decimal, KC_DECIMAL)); 144 keyConversion.insert(XtoOIS_KeyMap::value_type(XK_KP_Equal, KC_NUMPADEQUALS)); 145 keyConversion.insert(XtoOIS_KeyMap::value_type(XK_KP_Divide, KC_DIVIDE)); 146 keyConversion.insert(XtoOIS_KeyMap::value_type(XK_KP_Multiply, KC_MULTIPLY)); 147 keyConversion.insert(XtoOIS_KeyMap::value_type(XK_KP_Enter, KC_NUMPADENTER)); 148 149 //Keypad with numlock off 150 keyConversion.insert(XtoOIS_KeyMap::value_type(XK_KP_Home, KC_NUMPAD7)); 151 keyConversion.insert(XtoOIS_KeyMap::value_type(XK_KP_Up, KC_NUMPAD8)); 152 keyConversion.insert(XtoOIS_KeyMap::value_type(XK_KP_Page_Up, KC_NUMPAD9)); 153 keyConversion.insert(XtoOIS_KeyMap::value_type(XK_KP_Left, KC_NUMPAD4)); 154 keyConversion.insert(XtoOIS_KeyMap::value_type(XK_KP_Begin, KC_NUMPAD5)); 155 keyConversion.insert(XtoOIS_KeyMap::value_type(XK_KP_Right, KC_NUMPAD6)); 156 keyConversion.insert(XtoOIS_KeyMap::value_type(XK_KP_End, KC_NUMPAD1)); 157 keyConversion.insert(XtoOIS_KeyMap::value_type(XK_KP_Down, KC_NUMPAD2)); 158 keyConversion.insert(XtoOIS_KeyMap::value_type(XK_KP_Page_Down, KC_NUMPAD3)); 159 keyConversion.insert(XtoOIS_KeyMap::value_type(XK_KP_Insert, KC_NUMPAD0)); 160 keyConversion.insert(XtoOIS_KeyMap::value_type(XK_KP_Delete, KC_DECIMAL)); 161 162 keyConversion.insert(XtoOIS_KeyMap::value_type(XK_Up, KC_UP)); 163 keyConversion.insert(XtoOIS_KeyMap::value_type(XK_Down, KC_DOWN)); 164 keyConversion.insert(XtoOIS_KeyMap::value_type(XK_Left, KC_LEFT)); 165 keyConversion.insert(XtoOIS_KeyMap::value_type(XK_Right, KC_RIGHT)); 166 167 keyConversion.insert(XtoOIS_KeyMap::value_type(XK_Page_Up, KC_PGUP)); 168 keyConversion.insert(XtoOIS_KeyMap::value_type(XK_Page_Down, KC_PGDOWN)); 169 keyConversion.insert(XtoOIS_KeyMap::value_type(XK_Home, KC_HOME)); 170 keyConversion.insert(XtoOIS_KeyMap::value_type(XK_End, KC_END)); 171 172 keyConversion.insert(XtoOIS_KeyMap::value_type(XK_Num_Lock, KC_NUMLOCK)); 173 keyConversion.insert(XtoOIS_KeyMap::value_type(XK_Print, KC_SYSRQ)); 174 keyConversion.insert(XtoOIS_KeyMap::value_type(XK_Scroll_Lock, KC_SCROLL)); 175 keyConversion.insert(XtoOIS_KeyMap::value_type(XK_Pause, KC_PAUSE)); 176 177 keyConversion.insert(XtoOIS_KeyMap::value_type(XK_Shift_R, KC_RSHIFT)); 178 keyConversion.insert(XtoOIS_KeyMap::value_type(XK_Shift_L, KC_LSHIFT)); 179 keyConversion.insert(XtoOIS_KeyMap::value_type(XK_Alt_R, KC_RMENU)); 180 keyConversion.insert(XtoOIS_KeyMap::value_type(XK_Alt_L, KC_LMENU)); 181 182 keyConversion.insert(XtoOIS_KeyMap::value_type(XK_Insert, KC_INSERT)); 183 keyConversion.insert(XtoOIS_KeyMap::value_type(XK_Delete, KC_DELETE)); 184 185 keyConversion.insert(XtoOIS_KeyMap::value_type(XK_Super_L, KC_LWIN)); 186 keyConversion.insert(XtoOIS_KeyMap::value_type(XK_Super_R, KC_RWIN)); 187 keyConversion.insert(XtoOIS_KeyMap::value_type(XK_Menu, KC_APPS)); 188 189 static_cast<LinuxInputManager*>(mCreator)->_setKeyboardUsed(true); 190 } 191 192 //-------------------------------------------------------------------// 193 void LinuxKeyboard::_initialize() 194 { 195 //Clear our keyboard state buffer 196 memset( &KeyBuffer, 0, 256 ); 197 mModifiers = 0; 198 199 if( display ) XCloseDisplay(display); 200 display = 0; 201 window = static_cast<LinuxInputManager*>(mCreator)->_getWindow(); 202 203 //Create our local X mListener connection 204 if( !(display = XOpenDisplay(0)) ) 205 OIS_EXCEPT(E_General, "LinuxKeyboard::_initialize >> Error opening X!"); 206 207 //Set it to recieve Input events 208 if( XSelectInput(display, window, KeyPressMask | KeyReleaseMask) == BadWindow ) 209 OIS_EXCEPT(E_General, "LinuxKeyboard::_initialize: X error!"); 210 211 if( grabKeyboard ) 212 XGrabKeyboard(display,window,True,GrabModeAsync,GrabModeAsync,CurrentTime); 213 214 keyFocusLost = false; 215 216 if( xAutoRepeat == false ) 217 { 218 //We do not want to blindly turn on autorepeat later when quiting if 219 //it was not on to begin with.. So, let us check and see first 220 XKeyboardState old; 221 XGetKeyboardControl( display, &old ); 222 oldXAutoRepeat = false; 223 224 if( old.global_auto_repeat == AutoRepeatModeOn ) 225 oldXAutoRepeat = true; 226 227 XAutoRepeatOff( display ); 228 } 229 } 230 231 //-------------------------------------------------------------------// 232 LinuxKeyboard::~LinuxKeyboard() 233 { 234 if( display ) 235 { 236 if( oldXAutoRepeat ) 237 XAutoRepeatOn(display); 238 239 if( grabKeyboard ) 240 XUngrabKeyboard(display, CurrentTime); 241 242 XCloseDisplay(display); 243 } 244 245 static_cast<LinuxInputManager*>(mCreator)->_setKeyboardUsed(true); 246 } 247 248 //-------------------------------------------------------------------// 249 unsigned int UTF8ToUTF32(unsigned char* buf) 250 { 251 unsigned char &FirstChar = buf[0]; 252 253 if(FirstChar < 128) 254 return FirstChar; 255 256 unsigned int val = 0; 257 unsigned int len = 0; 258 259 if((FirstChar & 0xE0) == 0xC0) //2 Chars 260 { 261 len = 2; 262 val = FirstChar & 0x1F; 263 } 264 else if((FirstChar & 0xF0) == 0xE0) //3 Chars 265 { 266 len = 3; 267 val = FirstChar & 0x0F; 268 } 269 else if((FirstChar & 0xF8) == 0xF0) //4 Chars 270 { 271 len = 4; 272 val = FirstChar & 0x07; 273 } 274 else if((FirstChar & 0xFC) == 0xF8) //5 Chars 275 { 276 len = 5; 277 val = FirstChar & 0x03; 278 } 279 else // if((FirstChar & 0xFE) == 0xFC) //6 Chars 280 { 281 len = 6; 282 val = FirstChar & 0x01; 283 } 284 285 for(int i = 1; i < len; i++) 286 val = (val << 6) | (buf[i] & 0x3F); 287 288 return val; 289 } 290 291 //-------------------------------------------------------------------// 292 bool LinuxKeyboard::isKeyDown( KeyCode key ) const 293 { 294 return (KeyBuffer[key]); 295 } 296 297 //-------------------------------------------------------------------// 298 void LinuxKeyboard::capture() 299 { 300 KeySym key; 301 XEvent event; 302 LinuxInputManager* linMan = static_cast<LinuxInputManager*>(mCreator); 303 304 while( XPending(display) > 0 ) 305 { XNextEvent(display, &event); if( KeyPress == event.type ) 306 { 307 unsigned int character = 0; 308 309 if( mTextMode != Off ) 310 { 311 unsigned char buffer[6] = {0,0,0,0,0,0}; 312 XLookupString(&event.xkey, (char*)buffer, 6, &key, 0); 313 314 if( mTextMode == Unicode ) 315 character = UTF8ToUTF32(buffer); 316 else if( mTextMode == Ascii) 317 character = buffer[0]; 318 } 319 320 //Mask out the modifier states X11 sets and read again 321 event.xkey.state &= ~ShiftMask; 322 event.xkey.state &= ~LockMask; 323 XLookupString(&event.xkey, 0, 0,&key, 0); 324 325 _injectKeyDown(key, character); 326 327 //Just printing out some debugging info.. to verify all chars are mapped 328 //std::cout << "KEY PRESSED X=" << event.xkey.keycode; 329 //std::cout << "\n KeySym=" << key << std::endl; 330 331 //Check for Alt-Tab 332 if( event.xkey.state & Mod1Mask && key == XK_Tab ) 333 linMan->_setGrabState(false); 334 } else if( KeyRelease == event.type ) 335 { 336 //Mask out the modifier states X sets.. or we will get improper values 337 event.xkey.state &= ~ShiftMask; 338 event.xkey.state &= ~LockMask; 339 340 //Else, it is a valid key release 341 XLookupString(&event.xkey,NULL,0,&key,NULL); 342 _injectKeyUp(key); } 343 } 344 345 //If grabbing mode is on.. Handle focus lost/gained via Alt-Tab and mouse clicks 346 if( grabKeyboard ) 347 { 348 if( linMan->_getGrabState() == false ) 349 { 350 // are no longer grabbing 351 if( keyFocusLost == false ) 352 { 353 //UnGrab KeyBoard 354 XUngrabKeyboard(display, CurrentTime); 355 keyFocusLost = true; 356 } 357 } 358 else 359 { 360 //We are grabbing - and regained focus 361 if( keyFocusLost == true ) 362 { 363 //ReGrab KeyBoard 364 XGrabKeyboard(display, window, True, GrabModeAsync, GrabModeAsync, CurrentTime); 365 keyFocusLost = false; 366 } 367 } 368 } 369 } 370 371 //-------------------------------------------------------------------// 372 void LinuxKeyboard::setBuffered(bool buffered) 373 { 374 mBuffered = buffered; 375 } 376 377 //-------------------------------------------------------------------// 378 bool LinuxKeyboard::_injectKeyDown( KeySym key, int text ) 379 { 380 KeyCode kc = keyConversion[key]; 381 KeyBuffer[kc] = 1; 382 383 //Turn on modifier flags 384 if( kc == KC_LCONTROL || kc == KC_RCONTROL) 385 mModifiers |= Ctrl; 386 else if( kc == KC_LSHIFT || kc == KC_RSHIFT ) 387 mModifiers |= Shift; 388 else if( kc == KC_LMENU || kc == KC_RMENU ) 389 mModifiers |= Alt; 390 391 if( mBuffered && mListener ) 392 return mListener->keyPressed(KeyEvent(this,kc,text)); 393 394 return true; 395 } 396 397 //-------------------------------------------------------------------// 398 bool LinuxKeyboard::_injectKeyUp( KeySym key ) 399 { 400 KeyCode kc = keyConversion[key]; 401 KeyBuffer[kc] = 0; 402 403 //Turn off modifier flags 404 if( kc == KC_LCONTROL || kc == KC_RCONTROL) 405 mModifiers &= ~Ctrl; 406 else if( kc == KC_LSHIFT || kc == KC_RSHIFT ) 407 mModifiers &= ~Shift; 408 else if( kc == KC_LMENU || kc == KC_RMENU ) 409 mModifiers &= ~Alt; 410 411 if( mBuffered && mListener ) 412 return mListener->keyReleased(KeyEvent(this, kc, 0)); 413 414 return true; 415 } 416 417 //-------------------------------------------------------------------// 418 const std::string& LinuxKeyboard::getAsString( KeyCode kc ) 419 { 420 mGetString = "Unknown"; 421 char *temp = 0; 422 423 XtoOIS_KeyMap::iterator i = keyConversion.begin(), 424 e = keyConversion.end(); 425 426 for( ; i != e; ++i ) 427 { 428 if( i->second == kc ) 429 { 430 temp = XKeysymToString(i->first); 431 if( temp ) 432 mGetString = temp; 433 break; 434 } 435 } 436 437 return mGetString; 438 } 439 440 //-------------------------------------------------------------------// 441 void LinuxKeyboard::copyKeyStates( char keys[256] ) const 442 { 443 memcpy( keys, KeyBuffer, 256 ); 444 } -
code/branches/network/src/orxonox/CMakeLists.txt
r1494 r1495 1 SET( ORXONOX_SRC_FILES GraphicsEngine.cc Main.cc Orxonox.cc console/InGameConsole.cc hud/HUD.cc hud/BarOverlayElement.cc hud/RadarOverlayElement.cc 1 SET( ORXONOX_SRC_FILES 2 GraphicsEngine.cc 3 Main.cc 4 Orxonox.cc 5 6 console/InGameConsole.cc 7 hud/HUD.cc 8 hud/BarOverlayElement.cc 9 hud/RadarOverlayElement.cc 2 10 hud/RadarObject.cc 3 hud/Navigation.cc particle/ParticleInterface.cc tolua/tolua_bind.cc tools/BillboardSet.cc tools/Light.cc tools/Mesh.cc tools/Timer.cc objects/Ambient.cc objects/Camera.cc objects/CameraHandler.cc objects/Explosion.cc objects/Model.cc objects/NPC.cc objects/Projectile.cc objects/RotatingProjectile.cc objects/Skybox.cc objects/SpaceShip.cc objects/SpaceShipAI.cc objects/WorldEntity.cc# objects/weapon/AmmunitionDump.cc# objects/weapon/BarrelGun.cc# objects/weapon/BaseWeapon.cc# objects/weapon/Bullet.cc# objects/weapon/BulletManager.cc# objects/weapon/WeaponStation.cc)GET_TARGET_PROPERTY(TOLUA_EXE tolua LOCATION)ADD_CUSTOM_COMMAND( OUTPUT tolua/tolua_bind.cc tolua/tolua_bind.h COMMAND ${TOLUA_EXE} -n orxonox -o ../../src/orxonox/tolua/tolua_bind.cc -H ../../src/orxonox/tolua/tolua_bind.h ../../src/orxonox/tolua/tolua.pkg DEPENDS tolua WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/bin/lib) ADD_EXECUTABLE( orxonox ${ORXONOX_SRC_FILES} )IF(NETWORKTRAFFIC_TESTING_ENABLED) SET( ORXONOXS_SRC_FILES GraphicsEngine.cc objects/Ambient.cc objects/Camera.cc objects/CameraHandler.cc objects/Explosion.cc objects/Model.cc objects/NPC.cc objects/Projectile.cc objects/Skybox.cc objects/SpaceShip.cc objects/WorldEntity.cc ) ADD_LIBRARY(orxonoxs SHARED ${ORXONOX_SRC_FILES})ENDIF(NETWORKTRAFFIC_TESTING_ENABLED)TARGET_LINK_LIBRARIES( orxonox ${OGRE_LIBRARIES} ${Lua_LIBRARIES} tinyxml tolualib ois util core audio network) 11 hud/Navigation.cc 12 particle/ParticleInterface.cc 13 tolua/tolua_bind.cc 14 15 tools/BillboardSet.cc 16 tools/Light.cc 17 tools/Mesh.cc 18 tools/Timer.cc 19 20 objects/Ambient.cc 21 objects/Camera.cc 22 objects/CameraHandler.cc 23 objects/Explosion.cc 24 objects/Model.cc 25 objects/NPC.cc 26 objects/Projectile.cc 27 objects/RotatingProjectile.cc 28 objects/Skybox.cc 29 objects/SpaceShip.cc 30 objects/SpaceShipAI.cc 31 objects/WorldEntity.cc 32 33 # objects/weapon/AmmunitionDump.cc 34 # objects/weapon/BarrelGun.cc 35 # objects/weapon/BaseWeapon.cc 36 # objects/weapon/Bullet.cc 37 # objects/weapon/BulletManager.cc 38 # objects/weapon/WeaponStation.cc 39 ) 40 41 GET_TARGET_PROPERTY(TOLUA_EXE tolua LOCATION) 42 ADD_CUSTOM_COMMAND( 43 OUTPUT tolua/tolua_bind.cc tolua/tolua_bind.h 44 COMMAND ${TOLUA_EXE} -n orxonox -o ../../src/orxonox/tolua/tolua_bind.cc -H ../../src/orxonox/tolua/tolua_bind.h ../../src/orxonox/tolua/tolua.pkg 45 DEPENDS tolua 46 WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/bin/lib 47 ) 48 49 ADD_EXECUTABLE( orxonox ${ORXONOX_SRC_FILES} ) 50 51 IF(NETWORKTRAFFIC_TESTING_ENABLED) 52 53 SET( ORXONOXS_SRC_FILES 54 GraphicsEngine.cc 55 objects/Ambient.cc 56 objects/Camera.cc 57 objects/CameraHandler.cc 58 objects/Explosion.cc 59 objects/Model.cc 60 objects/NPC.cc 61 objects/Projectile.cc 62 objects/Skybox.cc 63 objects/SpaceShip.cc 64 objects/WorldEntity.cc 65 ) 66 67 ADD_LIBRARY(orxonoxs SHARED ${ORXONOX_SRC_FILES}) 68 ENDIF(NETWORKTRAFFIC_TESTING_ENABLED) 69 70 TARGET_LINK_LIBRARIES( orxonox 71 ${OGRE_LIBRARIES} 72 ${Lua_LIBRARIES} 73 tinyxml 74 tolualib 75 ois 76 util 77 core 78 audio 79 network 80 ) 81 -
code/branches/network/src/orxonox/GraphicsEngine.cc
r1494 r1495 44 44 #include "core/ConfigValueIncludes.h" 45 45 #include "core/Debug.h" 46 #include "core/CommandExecutor.h"#include "core/TclBind.h" 46 #include "core/CommandExecutor.h" 47 #include "core/TclBind.h" 47 48 #include "console/InGameConsole.h" 48 49 … … 86 87 SetConfigValue(ogreLogLevelTrivial_ , 5).description("Corresponding orxonox debug level for ogre Trivial"); 87 88 SetConfigValue(ogreLogLevelNormal_ , 4).description("Corresponding orxonox debug level for ogre Normal"); 88 SetConfigValue(ogreLogLevelCritical_, 2).description("Corresponding orxonox debug level for ogre Critical"); TclBind::getInstance().setDataPath(this->dataPath_); 89 SetConfigValue(ogreLogLevelCritical_, 2).description("Corresponding orxonox debug level for ogre Critical"); 90 91 TclBind::getInstance().setDataPath(this->dataPath_); 89 92 } 90 93 … … 309 312 return 0; 310 313 } 311 /** @brief Returns the window aspect ratio height/width. @return The ratio */ float GraphicsEngine::getWindowAspectRatio() const { if (this->renderWindow_) return (float)this->renderWindow_->getHeight() / (float)this->renderWindow_->getWidth(); else return 1.0f; } 314 315 /** 316 @brief Returns the window aspect ratio height/width. 317 @return The ratio 318 */ 319 float GraphicsEngine::getWindowAspectRatio() const 320 { 321 if (this->renderWindow_) 322 return (float)this->renderWindow_->getHeight() / (float)this->renderWindow_->getWidth(); 323 else 324 return 1.0f; 325 } 326 312 327 /** 313 328 @brief Method called by the LogListener interface from Ogre. … … 356 371 * as rw. But we have to be careful when using multiple render windows! 357 372 */ 358 void GraphicsEngine::windowResized(Ogre::RenderWindow *rw) { // change the mouse clipping size for absolute mouse movements 373 void GraphicsEngine::windowResized(Ogre::RenderWindow *rw) 374 { 375 // change the mouse clipping size for absolute mouse movements 359 376 int w = rw->getWidth(); 360 377 int h = rw->getHeight(); -
code/branches/network/src/orxonox/GraphicsEngine.h
r1494 r1495 1 1 /* 2 2 * ORXONOX - the hottest 3D action shooter ever to exist 3 * > www.orxonox.net < * 3 * > www.orxonox.net < 4 * 4 5 * 5 6 * License notice: … … 70 71 size_t getWindowHandle(); 71 72 int getWindowWidth() const; 72 int getWindowHeight() const; float getWindowAspectRatio() const; 73 int getWindowHeight() const; 74 float getWindowAspectRatio() const; 73 75 float getAverageFPS() const 74 76 { if (renderWindow_) return this->renderWindow_->getAverageFPS(); else return 0.0f; } -
code/branches/network/src/orxonox/Orxonox.cc
r1494 r1495 84 84 SetConsoleCommandShortcut(Orxonox, slomo).setAccessLevel(AccessLevel::Offline).setDefaultValue(0, 1.0).setAxisParamIndex(0).setIsAxisRelative(false); 85 85 SetConsoleCommandShortcut(Orxonox, setTimeFactor).setAccessLevel(AccessLevel::Offline).setDefaultValue(0, 1.0); 86 86 87 /** 87 88 @brief Reference to the only instance of the class. -
code/branches/network/src/orxonox/Orxonox.h
r1494 r1495 71 71 static inline float getTimeFactor() { return Orxonox::getSingleton()->timefactor_; } 72 72 static inline void exit() { Orxonox::getSingleton()->abortRequest(); } 73 73 74 private: 74 75 // don't mess with singletons -
code/branches/network/src/orxonox/OrxonoxPrereqs.h
r1494 r1495 1 1 /* 2 2 * ORXONOX - the hottest 3D action shooter ever to exist 3 * > www.orxonox.net < * 3 * > www.orxonox.net < 4 * 4 5 * 5 6 * License notice: … … 72 73 class Projectile; 73 74 class Skybox; 74 class SpaceShip; class SpaceShipAI; 75 class SpaceShip; 76 class SpaceShipAI; 75 77 class WorldEntity; 76 78 … … 94 96 95 97 // hud 96 class BarOverlayElement; class HUD; class Navigation; class RadarObject; class RadarOverlayElement; 98 class BarOverlayElement; 99 class HUD; 100 class Navigation; 101 class RadarObject; 102 class RadarOverlayElement; 97 103 98 104 //console -
code/branches/network/src/orxonox/OrxonoxStableHeaders.h
r1494 r1495 1 1 /* 2 2 * ORXONOX - the hottest 3D action shooter ever to exist 3 * > www.orxonox.net < * 3 * > www.orxonox.net < 4 * 4 5 * 5 6 * License notice: … … 30 31 @brief Contains the bigger (or smaller) header files in order to precompile them with MSVC 31 32 */ 32 #ifndef _OrxonoxStableHeaders_H__#define _OrxonoxStableHeaders_H__#include "util/OrxonoxPlatform.h"#if ORXONOX_COMPILER == ORXONOX_COMPILER_MSVC// including std headers here is useless since they're already precompiled#ifndef WIN32_LEAN_AND_MEAN// prevent Ogre from including winsock.h that messes with winsock2.h from enet# define WIN32_LEAN_AND_MEAN#endif// not including the entire Ogre.h doesn't exceed the default heap size for pch//#include <Ogre.h>#include <OgreBillboardSet.h>#include <OgreCamera.h>#include <OgreColourValue.h>#include <OgreConfigFile.h>#include <OgreEntity.h>#include <OgreException.h>#include <OgreFrameListener.h>#include <OgreLight.h>#include <OgreLog.h>#include <OgreLogManager.h>#include <OgreMath.h>#include <OgreMatrix3.h>#include <OgreOverlay.h>#include <OgreOverlayElement.h>#include <OgreOverlayManager.h>#include <OgreParticleEmitter.h>#include <OgreParticleSystem.h>#include <OgreQuaternion.h>#include <OgreResourceGroupManager.h>#include <OgreRenderWindow.h>#include <OgreRoot.h>#include <OgreSceneManager.h>#include <OgreSceneNode.h>#include <OgreStringConverter.h>#include <OgreTextureManager.h>#include <OgreTimer.h>#include <OgreVector2.h>#include <OgreVector3.h>#include <OgreVector3.h>#include <OgreViewport.h>#include <OgreWindowEventUtilities.h>//----------------------------------------------------------------------- 33 34 #ifndef _OrxonoxStableHeaders_H__ 35 #define _OrxonoxStableHeaders_H__ 36 37 #include "util/OrxonoxPlatform.h" 38 39 #if ORXONOX_COMPILER == ORXONOX_COMPILER_MSVC 40 41 // including std headers here is useless since they're already precompiled 42 43 #ifndef WIN32_LEAN_AND_MEAN 44 // prevent Ogre from including winsock.h that messes with winsock2.h from enet 45 # define WIN32_LEAN_AND_MEAN 46 #endif 47 // not including the entire Ogre.h doesn't exceed the default heap size for pch 48 //#include <Ogre.h> 49 #include <OgreBillboardSet.h> 50 #include <OgreCamera.h> 51 #include <OgreColourValue.h> 52 #include <OgreConfigFile.h> 53 #include <OgreEntity.h> 54 #include <OgreException.h> 55 #include <OgreFrameListener.h> 56 #include <OgreLight.h> 57 #include <OgreLog.h> 58 #include <OgreLogManager.h> 59 #include <OgreMath.h> 60 #include <OgreMatrix3.h> 61 #include <OgreOverlay.h> 62 #include <OgreOverlayElement.h> 63 #include <OgreOverlayManager.h> 64 #include <OgreParticleEmitter.h> 65 #include <OgreParticleSystem.h> 66 #include <OgreQuaternion.h> 67 #include <OgreResourceGroupManager.h> 68 #include <OgreRenderWindow.h> 69 #include <OgreRoot.h> 70 #include <OgreSceneManager.h> 71 #include <OgreSceneNode.h> 72 #include <OgreStringConverter.h> 73 #include <OgreTextureManager.h> 74 #include <OgreTimer.h> 75 #include <OgreVector2.h> 76 #include <OgreVector3.h> 77 #include <OgreVector3.h> 78 #include <OgreViewport.h> 79 #include <OgreWindowEventUtilities.h> 80 81 //----------------------------------------------------------------------- 33 82 // ORXONOX HEADERS 34 83 //----------------------------------------------------------------------- 35 84 36 85 #include "ois/OIS.h" 86 37 87 //#include "util/Convert.h" 38 #include "util/Math.h"//#include "util/Multitype.h"//#include "util/MultiTypeMath.h"//#include "util/MultiTypePrimitive.h"//#include "util/MultiTypeString.h"#include "util/Sleep.h"#include "util/String.h"#include "util/SubString.h"//#include "util/XMLIncludes.h"#include "tinyxml/ticpp.h"#include "tinyxml/tinyxml.h"#include "core/BaseObject.h"//#include "core/CommandExecutor.h"//#include "core/CoreIncludes.h"//#include "core/ConfigValueIncludes.h"#include "core/Debug.h"//#include "core/Executor.h"#include "core/Tickable.h"//#include "core/XMLPort.h"#include "network/Synchronisable.h"#include "OrxonoxPrereqs.h"#include "tools/Timer.h"#include "objects/Model.h"#include "objects/WorldEntity.h"#endif /* Compiler MSVC */#endif /* _OrxonoxStableHeaders_H__ */ 88 #include "util/Math.h" 89 //#include "util/Multitype.h" 90 //#include "util/MultiTypeMath.h" 91 //#include "util/MultiTypePrimitive.h" 92 //#include "util/MultiTypeString.h" 93 #include "util/Sleep.h" 94 #include "util/String.h" 95 #include "util/SubString.h" 96 //#include "util/XMLIncludes.h" 97 #include "tinyxml/ticpp.h" 98 #include "tinyxml/tinyxml.h" 99 100 #include "core/BaseObject.h" 101 //#include "core/CommandExecutor.h" 102 //#include "core/CoreIncludes.h" 103 //#include "core/ConfigValueIncludes.h" 104 #include "core/Debug.h" 105 //#include "core/Executor.h" 106 #include "core/Tickable.h" 107 //#include "core/XMLPort.h" 108 109 #include "network/Synchronisable.h" 110 111 #include "OrxonoxPrereqs.h" 112 #include "tools/Timer.h" 113 #include "objects/Model.h" 114 #include "objects/WorldEntity.h" 115 116 #endif /* Compiler MSVC */ 117 118 #endif /* _OrxonoxStableHeaders_H__ */ -
code/branches/network/src/orxonox/PrecompiledHeaderFiles.cc
r1494 r1495 1 1 /* 2 2 * ORXONOX - the hottest 3D action shooter ever to exist 3 * > www.orxonox.net < * 3 * > www.orxonox.net < 4 * 4 5 * 5 6 * License notice: -
code/branches/network/src/orxonox/console/InGameConsole.h
r1494 r1495 1 /* * ORXONOX - the hottest 3D action shooter ever to exist * > www.orxonox.net < * * * License notice: * * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * * Author: * Felix Schulthess * Co-authors: * Fabian 'x3n' Landau * */#ifndef _InGameConsole_H__#define _InGameConsole_H__ 1 /* 2 * ORXONOX - the hottest 3D action shooter ever to exist 3 * > www.orxonox.net < 4 * 5 * 6 * License notice: 7 * 8 * This program is free software; you can redistribute it and/or 9 * modify it under the terms of the GNU General Public License 10 * as published by the Free Software Foundation; either version 2 11 * of the License, or (at your option) any later version. 12 * 13 * This program is distributed in the hope that it will be useful, 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 * GNU General Public License for more details. 17 * 18 * You should have received a copy of the GNU General Public License 19 * along with this program; if not, write to the Free Software 20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 21 * 22 * Author: 23 * Felix Schulthess 24 * Co-authors: 25 * Fabian 'x3n' Landau 26 * 27 */ 28 29 #ifndef _InGameConsole_H__ 30 #define _InGameConsole_H__ 31 2 32 3 33 #include "OrxonoxPrereqs.h" … … 8 38 #include "core/Tickable.h" 9 39 #include "core/Shell.h" 10 namespace orxonox{ 40 41 42 namespace orxonox 43 { 11 44 class _OrxonoxExport InGameConsole : public TickableReal, public ShellListener 12 45 { 13 public: static InGameConsole& getInstance(); void setConfigValues(); void tick(float dt); 46 public: 47 static InGameConsole& getInstance(); 48 49 void setConfigValues(); 50 void tick(float dt); 51 14 52 void activate(); 15 void deactivate(); void resize(); static void openConsole(); static void closeConsole(); 53 void deactivate(); 54 void resize(); 55 56 static void openConsole(); 57 static void closeConsole(); 16 58 17 59 private: 18 InGameConsole(); InGameConsole(const InGameConsole& other); ~InGameConsole(); virtual void linesChanged(); virtual void onlyLastLineChanged(); virtual void lineAdded(); virtual void inputChanged(); virtual void cursorChanged(); virtual void exit(); void init(); void shiftLines(); void colourLine(int colourcode, int index); 60 InGameConsole(); 61 InGameConsole(const InGameConsole& other); 62 ~InGameConsole(); 63 64 virtual void linesChanged(); 65 virtual void onlyLastLineChanged(); 66 virtual void lineAdded(); 67 virtual void inputChanged(); 68 virtual void cursorChanged(); 69 virtual void exit(); 70 71 void init(); 72 void shiftLines(); 73 void colourLine(int colourcode, int index); 19 74 void setCursorPosition(int pos); 20 75 void print(const std::string& text, int index, bool alwaysShift = false); 21 76 static Ogre::UTFString convert2UTF(std::string s); 22 static float REL_WIDTH; static float REL_HEIGHT; static float BLINK; int windowW_; 23 int windowH_; int desiredTextWidth_; unsigned int maxCharsPerLine_; unsigned int numLinesShifted_; 77 78 static float REL_WIDTH; 79 static float REL_HEIGHT; 80 static float BLINK; 81 82 int windowW_; 83 int windowH_; 84 int desiredTextWidth_; 85 unsigned int maxCharsPerLine_; 86 unsigned int numLinesShifted_; 24 87 int scroll_; 25 88 float scrollTimer_; 26 float cursor_; unsigned int inputWindowStart_; char cursorSymbol_; 89 float cursor_; 90 unsigned int inputWindowStart_; 91 char cursorSymbol_; 27 92 bool active_; 28 93 bool bShowCursor_; … … 35 100 Ogre::BorderPanelOverlayElement* consoleOverlayBorder_; 36 101 Ogre::TextAreaOverlayElement** consoleOverlayTextAreas_; 37 };}#endif /* _InGameConsole_H__ */ 102 }; 103 } 104 105 #endif /* _InGameConsole_H__ */ -
code/branches/network/src/orxonox/hud/BarOverlayElement.cc
r1494 r1495 1 /* * ORXONOX - the hottest 3D action shooter ever to exist * > www.orxonox.net < * * * License notice: * * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * 1 /* 2 * ORXONOX - the hottest 3D action shooter ever to exist 3 * > www.orxonox.net < 4 * 5 * 6 * License notice: 7 * 8 * This program is free software; you can redistribute it and/or 9 * modify it under the terms of the GNU General Public License 10 * as published by the Free Software Foundation; either version 2 11 * of the License, or (at your option) any later version. 12 * 13 * This program is distributed in the hope that it will be useful, 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 * GNU General Public License for more details. 17 * 18 * You should have received a copy of the GNU General Public License 19 * along with this program; if not, write to the Free Software 20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 21 * 2 22 * Author: 3 23 * Yuning Chai -
code/branches/network/src/orxonox/hud/BarOverlayElement.h
r1494 r1495 1 /* * ORXONOX - the hottest 3D action shooter ever to exist * > www.orxonox.net < * * * License notice: * * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * 1 /* 2 * ORXONOX - the hottest 3D action shooter ever to exist 3 * > www.orxonox.net < 4 * 5 * 6 * License notice: 7 * 8 * This program is free software; you can redistribute it and/or 9 * modify it under the terms of the GNU General Public License 10 * as published by the Free Software Foundation; either version 2 11 * of the License, or (at your option) any later version. 12 * 13 * This program is distributed in the hope that it will be useful, 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 * GNU General Public License for more details. 17 * 18 * You should have received a copy of the GNU General Public License 19 * along with this program; if not, write to the Free Software 20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 21 * 2 22 * Author: 3 23 * Yuning Chai -
code/branches/network/src/orxonox/hud/HUD.h
r1494 r1495 1 /* * ORXONOX - the hottest 3D action shooter ever to exist * > www.orxonox.net < * * * License notice: * * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * 1 /* 2 * ORXONOX - the hottest 3D action shooter ever to exist 3 * > www.orxonox.net < 4 * 5 * 6 * License notice: 7 * 8 * This program is free software; you can redistribute it and/or 9 * modify it under the terms of the GNU General Public License 10 * as published by the Free Software Foundation; either version 2 11 * of the License, or (at your option) any later version. 12 * 13 * This program is distributed in the hope that it will be useful, 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 * GNU General Public License for more details. 17 * 18 * You should have received a copy of the GNU General Public License 19 * along with this program; if not, write to the Free Software 20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 21 * 2 22 * Author: 3 23 * Yuning Chai -
code/branches/network/src/orxonox/hud/Navigation.cc
r1494 r1495 1 /* * ORXONOX - the hottest 3D action shooter ever to exist * > www.orxonox.net < * * * License notice: * * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * 1 /* 2 * ORXONOX - the hottest 3D action shooter ever to exist 3 * > www.orxonox.net < 4 * 5 * 6 * License notice: 7 * 8 * This program is free software; you can redistribute it and/or 9 * modify it under the terms of the GNU General Public License 10 * as published by the Free Software Foundation; either version 2 11 * of the License, or (at your option) any later version. 12 * 13 * This program is distributed in the hope that it will be useful, 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 * GNU General Public License for more details. 17 * 18 * You should have received a copy of the GNU General Public License 19 * along with this program; if not, write to the Free Software 20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 21 * 2 22 * Author: 3 23 * Felix Schulthess -
code/branches/network/src/orxonox/hud/Navigation.h
r1494 r1495 1 /* * ORXONOX - the hottest 3D action shooter ever to exist * > www.orxonox.net < * * * License notice: * * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * 1 /* 2 * ORXONOX - the hottest 3D action shooter ever to exist 3 * > www.orxonox.net < 4 * 5 * 6 * License notice: 7 * 8 * This program is free software; you can redistribute it and/or 9 * modify it under the terms of the GNU General Public License 10 * as published by the Free Software Foundation; either version 2 11 * of the License, or (at your option) any later version. 12 * 13 * This program is distributed in the hope that it will be useful, 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 * GNU General Public License for more details. 17 * 18 * You should have received a copy of the GNU General Public License 19 * along with this program; if not, write to the Free Software 20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 21 * 2 22 * Author: 3 23 * Felix Schulthess -
code/branches/network/src/orxonox/hud/OverlayElementFactories.h
r1494 r1495 1 /* * ORXONOX - the hottest 3D action shooter ever to exist * > www.orxonox.net < * * * License notice: * * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * 1 /* 2 * ORXONOX - the hottest 3D action shooter ever to exist 3 * > www.orxonox.net < 4 * 5 * 6 * License notice: 7 * 8 * This program is free software; you can redistribute it and/or 9 * modify it under the terms of the GNU General Public License 10 * as published by the Free Software Foundation; either version 2 11 * of the License, or (at your option) any later version. 12 * 13 * This program is distributed in the hope that it will be useful, 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 * GNU General Public License for more details. 17 * 18 * You should have received a copy of the GNU General Public License 19 * along with this program; if not, write to the Free Software 20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 21 * 2 22 * Author: 3 23 * Yuning Chai -
code/branches/network/src/orxonox/hud/RadarObject.cc
r1494 r1495 1 /* * ORXONOX - the hottest 3D action shooter ever to exist * > www.orxonox.net < * * * License notice: * * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * 1 /* 2 * ORXONOX - the hottest 3D action shooter ever to exist 3 * > www.orxonox.net < 4 * 5 * 6 * License notice: 7 * 8 * This program is free software; you can redistribute it and/or 9 * modify it under the terms of the GNU General Public License 10 * as published by the Free Software Foundation; either version 2 11 * of the License, or (at your option) any later version. 12 * 13 * This program is distributed in the hope that it will be useful, 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 * GNU General Public License for more details. 17 * 18 * You should have received a copy of the GNU General Public License 19 * along with this program; if not, write to the Free Software 20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 21 * 2 22 * Author: 3 23 * Felix Schulthess -
code/branches/network/src/orxonox/hud/RadarObject.h
r1494 r1495 1 /* * ORXONOX - the hottest 3D action shooter ever to exist * > www.orxonox.net < * * * License notice: * * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * 1 /* 2 * ORXONOX - the hottest 3D action shooter ever to exist 3 * > www.orxonox.net < 4 * 5 * 6 * License notice: 7 * 8 * This program is free software; you can redistribute it and/or 9 * modify it under the terms of the GNU General Public License 10 * as published by the Free Software Foundation; either version 2 11 * of the License, or (at your option) any later version. 12 * 13 * This program is distributed in the hope that it will be useful, 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 * GNU General Public License for more details. 17 * 18 * You should have received a copy of the GNU General Public License 19 * along with this program; if not, write to the Free Software 20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 21 * 2 22 * Author: 3 23 * Felix Schulthess -
code/branches/network/src/orxonox/hud/RadarOverlayElement.cc
r1494 r1495 1 /* * ORXONOX - the hottest 3D action shooter ever to exist * > www.orxonox.net < * * * License notice: * * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * 1 /* 2 * ORXONOX - the hottest 3D action shooter ever to exist 3 * > www.orxonox.net < 4 * 5 * 6 * License notice: 7 * 8 * This program is free software; you can redistribute it and/or 9 * modify it under the terms of the GNU General Public License 10 * as published by the Free Software Foundation; either version 2 11 * of the License, or (at your option) any later version. 12 * 13 * This program is distributed in the hope that it will be useful, 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 * GNU General Public License for more details. 17 * 18 * You should have received a copy of the GNU General Public License 19 * along with this program; if not, write to the Free Software 20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 21 * 2 22 * Author: 3 23 * Yuning Chai -
code/branches/network/src/orxonox/hud/RadarOverlayElement.h
r1494 r1495 1 /* * ORXONOX - the hottest 3D action shooter ever to exist * > www.orxonox.net < * * * License notice: * * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * 1 /* 2 * ORXONOX - the hottest 3D action shooter ever to exist 3 * > www.orxonox.net < 4 * 5 * 6 * License notice: 7 * 8 * This program is free software; you can redistribute it and/or 9 * modify it under the terms of the GNU General Public License 10 * as published by the Free Software Foundation; either version 2 11 * of the License, or (at your option) any later version. 12 * 13 * This program is distributed in the hope that it will be useful, 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 * GNU General Public License for more details. 17 * 18 * You should have received a copy of the GNU General Public License 19 * along with this program; if not, write to the Free Software 20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 21 * 2 22 * Author: 3 23 * Yuning Chai -
code/branches/network/src/orxonox/objects/Camera.h
r1494 r1495 1 /* * ORXONOX - the hottest 3D action shooter ever to exist * > www.orxonox.net < * * * License notice: * * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * * Author: * Fabian 'x3n' Landau * Co-authors: * Benjamin Knecht * */#ifndef _Camera_H__#define _Camera_H__#include <OgrePrerequisites.h>#include <OgreSceneNode.h>#include <OgreCamera.h>#include "OrxonoxPrereqs.h"namespace orxonox{ class _OrxonoxExport Camera { friend class CameraHandler; public: Camera(Ogre::SceneNode* node = NULL); virtual ~Camera(); void setPositionNode(Ogre::SceneNode* node); inline Ogre::SceneNode* getCameraNode() { return this->positionNode_; } // maybe also BaseObject void setTargetNode(Ogre::SceneNode* obj); 1 /* 2 * ORXONOX - the hottest 3D action shooter ever to exist 3 * > www.orxonox.net < 4 * 5 * 6 * License notice: 7 * 8 * This program is free software; you can redistribute it and/or 9 * modify it under the terms of the GNU General Public License 10 * as published by the Free Software Foundation; either version 2 11 * of the License, or (at your option) any later version. 12 * 13 * This program is distributed in the hope that it will be useful, 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 * GNU General Public License for more details. 17 * 18 * You should have received a copy of the GNU General Public License 19 * along with this program; if not, write to the Free Software 20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 21 * 22 * Author: 23 * Fabian 'x3n' Landau 24 * Co-authors: 25 * Benjamin Knecht 26 * 27 */ 28 29 #ifndef _Camera_H__ 30 #define _Camera_H__ 31 32 #include <OgrePrerequisites.h> 33 #include <OgreSceneNode.h> 34 #include <OgreCamera.h> 35 36 #include "OrxonoxPrereqs.h" 37 38 namespace orxonox 39 { 40 class _OrxonoxExport Camera 41 { 42 friend class CameraHandler; 43 public: 44 Camera(Ogre::SceneNode* node = NULL); 45 virtual ~Camera(); 46 47 void setPositionNode(Ogre::SceneNode* node); 48 inline Ogre::SceneNode* getCameraNode() { return this->positionNode_; } 49 // maybe also BaseObject 50 void setTargetNode(Ogre::SceneNode* obj); 51 2 52 Ogre::Camera* cam_; 3 void tick(float dt); void update(); inline bool hasFocus() { return this->bHasFocus_; } private: void removeFocus(); void setFocus(Ogre::Camera* ogreCam); private: Ogre::SceneNode* targetNode_; Ogre::SceneNode* positionNode_; Ogre::SceneNode* cameraNode_; Ogre::Vector3 oldPos; bool bHasFocus_; };}#endif /* _Camera_H__ */ 53 54 void tick(float dt); 55 void update(); 56 inline bool hasFocus() { return this->bHasFocus_; } 57 58 private: 59 void removeFocus(); 60 void setFocus(Ogre::Camera* ogreCam); 61 62 private: 63 Ogre::SceneNode* targetNode_; 64 Ogre::SceneNode* positionNode_; 65 Ogre::SceneNode* cameraNode_; 66 Ogre::Vector3 oldPos; 67 bool bHasFocus_; 68 }; 69 } 70 71 #endif /* _Camera_H__ */ -
code/branches/network/src/orxonox/objects/SpaceShipAI.cc
r1494 r1495 1 /* * ORXONOX - the hottest 3D action shooter ever to exist * > www.orxonox.net < * * * License notice: * * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * * Author: * Fabian 'x3n' Landau * Co-authors: * ... * */#include "OrxonoxStableHeaders.h" 2 #include "SpaceShipAI.h"#include <OgreMath.h>#include "Projectile.h"#include "core/CoreIncludes.h"#include "core/Iterator.h"#include "core/Executor.h"#include "core/ConsoleCommand.h"#include "core/XMLPort.h"#define ACTION_INTERVAL 1.0fnamespace orxonox{ SetConsoleCommand(SpaceShipAI, createEnemy, true).setDefaultValue(0, 1); SetConsoleCommand(SpaceShipAI, killEnemies, true).setDefaultValue(0, 0); CreateFactory(SpaceShipAI); SpaceShipAI::SpaceShipAI() { RegisterObject(SpaceShipAI); this->alive_ = true; this->setPosition(Vector3(rnd(-1000, 1000), rnd(-1000, 1000), rnd(-1000, 0000))); this->target_ = 0; this->bShooting_ = 0; this->bHasTargetPosition_ = false; this->setTeamNr((int)rnd(NUM_AI_TEAMS) % NUM_AI_TEAMS + 1); if (NUM_AI_TEAMS > 0) this->teamColours_[1] = ColourValue(1, 0, 0, 1); if (NUM_AI_TEAMS > 1) this->teamColours_[2] = ColourValue(0, 1, 0, 1); if (NUM_AI_TEAMS > 2) this->teamColours_[3] = ColourValue(0, 0, 1, 1); for (int i = 4; i <= NUM_AI_TEAMS; ++i) this->teamColours_[i] = ColourValue(rnd(), rnd(), rnd(), 1); } void SpaceShipAI::XMLPort(Element& xmlelement, XMLPort::Mode mode) { SpaceShip::XMLPort(xmlelement, mode); myShip_=true; this->actionTimer_.setTimer(ACTION_INTERVAL, true, this, createExecutor(createFunctor(&SpaceShipAI::action))); } void SpaceShipAI::createEnemy(int num) { for (int i = 0; i < num; ++i) { SpaceShipAI* newenemy = new SpaceShipAI(); newenemy->setMesh("assff.mesh");// newenemy->setPosition(0, 0, 0); newenemy->setScale(10); newenemy->setMaxSpeed(500); newenemy->setMaxSideAndBackSpeed(50); newenemy->setMaxRotation(1.0); newenemy->setTransAcc(200); newenemy->setRotAcc(3.0); newenemy->setTransDamp(75); newenemy->setRotDamp(1.0); Element xmlelement; newenemy->XMLPort(xmlelement, XMLPort::LoadObject); } } void SpaceShipAI::killEnemies(int num) { int i = 0; for (Iterator<SpaceShipAI> it = ObjectList<SpaceShipAI>::begin(); it; ) { delete *(it++); ++i; if (num && i >= num) break; } } ColourValue SpaceShipAI::getProjectileColour() const { return this->teamColours_[this->getTeamNr()]; } void SpaceShipAI::action() { float random; float maxrand = 100.0f / ACTION_INTERVAL; // search enemy random = rnd(maxrand);//std::cout << "search enemy: " << random << std::endl; if (random < 20 && (!this->target_)) { this->searchNewTarget(); } // forget enemy random = rnd(maxrand);//std::cout << "forget enemy: " << random << std::endl; if (random < 5 && (this->target_)) { this->forgetTarget(); } // next enemy random = rnd(maxrand);//std::cout << "next enemy: " << random << std::endl; if (random < 10 && (this->target_)) { this->searchNewTarget(); } // fly somewhere random = rnd(maxrand);//std::cout << "fly somewhere: " << random << std::endl; if (random < 40 && (!this->bHasTargetPosition_ && !this->target_)) { this->searchNewTargetPosition(); } // stop flying random = rnd(maxrand);//std::cout << "stop flying: " << random << std::endl; if (random < 10 && (this->bHasTargetPosition_ && !this->target_)) { this->bHasTargetPosition_ = false; } // fly somewhere else random = rnd(maxrand);//std::cout << "fly somewhere else: " << random << std::endl; if (random < 30 && (this->bHasTargetPosition_ && !this->target_)) { this->searchNewTargetPosition(); } // shoot random = rnd(maxrand);//std::cout << "shoot: " << random << std::endl; if (random < 75 && (this->target_ && !this->bShooting_)) { this->bShooting_ = true; } // stop shooting random = rnd(maxrand);//std::cout << "stop shooting: " << random << std::endl; if (random < 25 && (this->bShooting_)) { this->bShooting_ = false; } } void SpaceShipAI::tick(float dt) { if (this->target_) this->aimAtTarget(); if (this->bHasTargetPosition_) this->moveToTargetPosition(dt); if (this->bShooting_ && this->isCloseAtTarget(2000) && this->isLookingAtTarget(Ogre::Math::PI / 10.0f)) this->doFire(); SpaceShip::tick(dt); } void SpaceShipAI::moveToTargetPosition(float dt) { static Radian RadianZERO(0);// float dotprod = (this->getOrientation() * Ogre::Vector3::UNIT_X).dotProduct(this->targetPosition_ - this->getPosition()); Quaternion rotation = (this->getOrientation() * Ogre::Vector3::UNIT_X).getRotationTo(this->targetPosition_ - this->getPosition());/*std::cout << "scalprod: " << dotprod << std::endl;std::cout << "dist: " << this->targetPosition_ - this->getPosition() << std::endl;std::cout << "yaw: " << rotation.getYaw().valueRadians() << std::endl;std::cout << "pitch: " << rotation.getPitch().valueRadians() << std::endl;std::cout << "roll: " << rotation.getRoll().valueRadians() << std::endl;*/ this->setMoveYaw(-rotation.getRoll().valueRadians()); this->setMovePitch(rotation.getYaw().valueRadians()); if ((this->targetPosition_ - this->getPosition()).length() > 100) { this->setMoveLongitudinal(1); } } void SpaceShipAI::searchNewTargetPosition() { this->targetPosition_ = Vector3(rnd(-5000,5000), rnd(-5000,5000), rnd(-5000,5000)); this->bHasTargetPosition_ = true; } void SpaceShipAI::searchNewTarget() { this->targetPosition_ = this->getPosition(); this->forgetTarget(); for (Iterator<SpaceShip> it = ObjectList<SpaceShip>::begin(); it; ++it) { if (it->getTeamNr() != this->getTeamNr()) { float speed = this->getVelocity().length(); Vector3 distanceCurrent = this->targetPosition_ - this->getPosition(); Vector3 distanceNew = it->getPosition() - this->getPosition(); if (!this->target_ || it->getPosition().squaredDistance(this->getPosition()) * (1.5f + acos((this->getOrientation() * Ogre::Vector3::UNIT_X).dotProduct(distanceNew) / speed / distanceNew.length()) / (2 * Ogre::Math::PI)) < this->targetPosition_.squaredDistance(this->getPosition()) * (1.5f + acos((this->getOrientation() * Ogre::Vector3::UNIT_X).dotProduct(distanceCurrent) / speed / distanceCurrent.length()) / (2 * Ogre::Math::PI))) { this->target_ = (*it); this->targetPosition_ = it->getPosition(); } } } } void SpaceShipAI::forgetTarget() { this->target_ = 0; this->bShooting_ = false; } void SpaceShipAI::aimAtTarget() { if (!this->target_) return;/* Vector3 enemymovement = this->target_->getVelocity(); Vector3 distance_normalised = this->target_->getPosition() - this->getPosition(); distance_normalised.normalise(); float scalarprod = enemymovement.dotProduct(distance_normalised); float aimoffset = scalarprod*scalarprod + Projectile::getSpeed() * Projectile::getSpeed() - this->target_->getVelocity().squaredLength(); if (aimoffset < 0) { this->bHasTargetPosition_ = false; return; } aimoffset = -scalarprod + sqrt(aimoffset); this->targetPosition_ = enemymovement + distance_normalised * aimoffset; this->bHasTargetPosition_ = true; std::cout << "targetpos: " << this->targetPosition_ << std::endl;*/ this->targetPosition_ = this->target_->getPosition(); this->bHasTargetPosition_ = true; } bool SpaceShipAI::isCloseAtTarget(float distance) { return (this->getPosition().squaredDistance(this->targetPosition_) < distance*distance); } bool SpaceShipAI::isLookingAtTarget(float angle) { return (this->getOrientation() * Ogre::Vector3::UNIT_X).directionEquals(this->targetPosition_ - this->getPosition(), Radian(angle)); }} 1 /* 2 * ORXONOX - the hottest 3D action shooter ever to exist 3 * > www.orxonox.net < 4 * 5 * 6 * License notice: 7 * 8 * This program is free software; you can redistribute it and/or 9 * modify it under the terms of the GNU General Public License 10 * as published by the Free Software Foundation; either version 2 11 * of the License, or (at your option) any later version. 12 * 13 * This program is distributed in the hope that it will be useful, 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 * GNU General Public License for more details. 17 * 18 * You should have received a copy of the GNU General Public License 19 * along with this program; if not, write to the Free Software 20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 21 * 22 * Author: 23 * Fabian 'x3n' Landau 24 * Co-authors: 25 * ... 26 * 27 */ 28 29 #include "OrxonoxStableHeaders.h" 30 #include "SpaceShipAI.h" 31 32 #include <OgreMath.h> 33 #include "Projectile.h" 34 #include "core/CoreIncludes.h" 35 #include "core/Iterator.h" 36 #include "core/Executor.h" 37 #include "core/ConsoleCommand.h" 38 #include "core/XMLPort.h" 39 40 #define ACTION_INTERVAL 1.0f 41 42 namespace orxonox 43 { 44 SetConsoleCommand(SpaceShipAI, createEnemy, true).setDefaultValue(0, 1); 45 SetConsoleCommand(SpaceShipAI, killEnemies, true).setDefaultValue(0, 0); 46 47 CreateFactory(SpaceShipAI); 48 49 SpaceShipAI::SpaceShipAI() 50 { 51 RegisterObject(SpaceShipAI); 52 53 this->alive_ = true; 54 this->setPosition(Vector3(rnd(-1000, 1000), rnd(-1000, 1000), rnd(-1000, 0000))); 55 this->target_ = 0; 56 this->bShooting_ = 0; 57 this->bHasTargetPosition_ = false; 58 59 this->setTeamNr((int)rnd(NUM_AI_TEAMS) % NUM_AI_TEAMS + 1); 60 61 if (NUM_AI_TEAMS > 0) 62 this->teamColours_[1] = ColourValue(1, 0, 0, 1); 63 if (NUM_AI_TEAMS > 1) 64 this->teamColours_[2] = ColourValue(0, 1, 0, 1); 65 if (NUM_AI_TEAMS > 2) 66 this->teamColours_[3] = ColourValue(0, 0, 1, 1); 67 68 for (int i = 4; i <= NUM_AI_TEAMS; ++i) 69 this->teamColours_[i] = ColourValue(rnd(), rnd(), rnd(), 1); 70 } 71 72 void SpaceShipAI::XMLPort(Element& xmlelement, XMLPort::Mode mode) 73 { 74 SpaceShip::XMLPort(xmlelement, mode); 75 myShip_=true; 76 77 this->actionTimer_.setTimer(ACTION_INTERVAL, true, this, createExecutor(createFunctor(&SpaceShipAI::action))); 78 } 79 80 void SpaceShipAI::createEnemy(int num) 81 { 82 for (int i = 0; i < num; ++i) 83 { 84 SpaceShipAI* newenemy = new SpaceShipAI(); 85 newenemy->setMesh("assff.mesh"); 86 // newenemy->setPosition(0, 0, 0); 87 newenemy->setScale(10); 88 newenemy->setMaxSpeed(500); 89 newenemy->setMaxSideAndBackSpeed(50); 90 newenemy->setMaxRotation(1.0); 91 newenemy->setTransAcc(200); 92 newenemy->setRotAcc(3.0); 93 newenemy->setTransDamp(75); 94 newenemy->setRotDamp(1.0); 95 Element xmlelement; 96 newenemy->XMLPort(xmlelement, XMLPort::LoadObject); 97 } 98 } 99 100 void SpaceShipAI::killEnemies(int num) 101 { 102 int i = 0; 103 for (Iterator<SpaceShipAI> it = ObjectList<SpaceShipAI>::begin(); it; ) 104 { 105 delete *(it++); 106 ++i; 107 if (num && i >= num) 108 break; 109 } 110 } 111 112 ColourValue SpaceShipAI::getProjectileColour() const 113 { 114 return this->teamColours_[this->getTeamNr()]; 115 } 116 117 void SpaceShipAI::action() 118 { 119 float random; 120 float maxrand = 100.0f / ACTION_INTERVAL; 121 122 // search enemy 123 random = rnd(maxrand); 124 //std::cout << "search enemy: " << random << std::endl; 125 if (random < 20 && (!this->target_)) 126 { 127 this->searchNewTarget(); 128 } 129 130 // forget enemy 131 random = rnd(maxrand); 132 //std::cout << "forget enemy: " << random << std::endl; 133 if (random < 5 && (this->target_)) 134 { 135 this->forgetTarget(); 136 } 137 138 // next enemy 139 random = rnd(maxrand); 140 //std::cout << "next enemy: " << random << std::endl; 141 if (random < 10 && (this->target_)) 142 { 143 this->searchNewTarget(); 144 } 145 146 // fly somewhere 147 random = rnd(maxrand); 148 //std::cout << "fly somewhere: " << random << std::endl; 149 if (random < 40 && (!this->bHasTargetPosition_ && !this->target_)) 150 { 151 this->searchNewTargetPosition(); 152 } 153 154 // stop flying 155 random = rnd(maxrand); 156 //std::cout << "stop flying: " << random << std::endl; 157 if (random < 10 && (this->bHasTargetPosition_ && !this->target_)) 158 { 159 this->bHasTargetPosition_ = false; 160 } 161 162 // fly somewhere else 163 random = rnd(maxrand); 164 //std::cout << "fly somewhere else: " << random << std::endl; 165 if (random < 30 && (this->bHasTargetPosition_ && !this->target_)) 166 { 167 this->searchNewTargetPosition(); 168 } 169 170 // shoot 171 random = rnd(maxrand); 172 //std::cout << "shoot: " << random << std::endl; 173 if (random < 75 && (this->target_ && !this->bShooting_)) 174 { 175 this->bShooting_ = true; 176 } 177 178 // stop shooting 179 random = rnd(maxrand); 180 //std::cout << "stop shooting: " << random << std::endl; 181 if (random < 25 && (this->bShooting_)) 182 { 183 this->bShooting_ = false; 184 } 185 } 186 187 void SpaceShipAI::tick(float dt) 188 { 189 if (this->target_) 190 this->aimAtTarget(); 191 192 if (this->bHasTargetPosition_) 193 this->moveToTargetPosition(dt); 194 195 if (this->bShooting_ && this->isCloseAtTarget(2000) && this->isLookingAtTarget(Ogre::Math::PI / 10.0f)) 196 this->doFire(); 197 198 SpaceShip::tick(dt); 199 } 200 201 void SpaceShipAI::moveToTargetPosition(float dt) 202 { 203 static Radian RadianZERO(0); 204 205 // float dotprod = (this->getOrientation() * Ogre::Vector3::UNIT_X).dotProduct(this->targetPosition_ - this->getPosition()); 206 Quaternion rotation = (this->getOrientation() * Ogre::Vector3::UNIT_X).getRotationTo(this->targetPosition_ - this->getPosition()); 207 /* 208 std::cout << "scalprod: " << dotprod << std::endl; 209 std::cout << "dist: " << this->targetPosition_ - this->getPosition() << std::endl; 210 std::cout << "yaw: " << rotation.getYaw().valueRadians() << std::endl; 211 std::cout << "pitch: " << rotation.getPitch().valueRadians() << std::endl; 212 std::cout << "roll: " << rotation.getRoll().valueRadians() << std::endl; 213 */ 214 this->setMoveYaw(-rotation.getRoll().valueRadians()); 215 this->setMovePitch(rotation.getYaw().valueRadians()); 216 217 if ((this->targetPosition_ - this->getPosition()).length() > 100) 218 { 219 this->setMoveLongitudinal(1); 220 } 221 222 } 223 224 void SpaceShipAI::searchNewTargetPosition() 225 { 226 this->targetPosition_ = Vector3(rnd(-5000,5000), rnd(-5000,5000), rnd(-5000,5000)); 227 this->bHasTargetPosition_ = true; 228 } 229 230 void SpaceShipAI::searchNewTarget() 231 { 232 this->targetPosition_ = this->getPosition(); 233 this->forgetTarget(); 234 235 for (Iterator<SpaceShip> it = ObjectList<SpaceShip>::begin(); it; ++it) 236 { 237 if (it->getTeamNr() != this->getTeamNr()) 238 { 239 float speed = this->getVelocity().length(); 240 Vector3 distanceCurrent = this->targetPosition_ - this->getPosition(); 241 Vector3 distanceNew = it->getPosition() - this->getPosition(); 242 if (!this->target_ || it->getPosition().squaredDistance(this->getPosition()) * (1.5f + acos((this->getOrientation() * Ogre::Vector3::UNIT_X).dotProduct(distanceNew) / speed / distanceNew.length()) / (2 * Ogre::Math::PI)) 243 < this->targetPosition_.squaredDistance(this->getPosition()) * (1.5f + acos((this->getOrientation() * Ogre::Vector3::UNIT_X).dotProduct(distanceCurrent) / speed / distanceCurrent.length()) / (2 * Ogre::Math::PI))) 244 { 245 this->target_ = (*it); 246 this->targetPosition_ = it->getPosition(); 247 } 248 } 249 } 250 } 251 252 void SpaceShipAI::forgetTarget() 253 { 254 this->target_ = 0; 255 this->bShooting_ = false; 256 } 257 258 void SpaceShipAI::aimAtTarget() 259 { 260 if (!this->target_) 261 return; 262 /* 263 Vector3 enemymovement = this->target_->getVelocity(); 264 Vector3 distance_normalised = this->target_->getPosition() - this->getPosition(); 265 distance_normalised.normalise(); 266 267 float scalarprod = enemymovement.dotProduct(distance_normalised); 268 float aimoffset = scalarprod*scalarprod + Projectile::getSpeed() * Projectile::getSpeed() - this->target_->getVelocity().squaredLength(); 269 if (aimoffset < 0) 270 { 271 this->bHasTargetPosition_ = false; 272 return; 273 } 274 aimoffset = -scalarprod + sqrt(aimoffset); 275 this->targetPosition_ = enemymovement + distance_normalised * aimoffset; 276 this->bHasTargetPosition_ = true; 277 278 std::cout << "targetpos: " << this->targetPosition_ << std::endl; 279 */ 280 this->targetPosition_ = this->target_->getPosition(); 281 this->bHasTargetPosition_ = true; 282 } 283 284 bool SpaceShipAI::isCloseAtTarget(float distance) 285 { 286 return (this->getPosition().squaredDistance(this->targetPosition_) < distance*distance); 287 } 288 289 bool SpaceShipAI::isLookingAtTarget(float angle) 290 { 291 return (this->getOrientation() * Ogre::Vector3::UNIT_X).directionEquals(this->targetPosition_ - this->getPosition(), Radian(angle)); 292 } 293 } -
code/branches/network/src/orxonox/objects/weapon/BaseWeapon.h
r1494 r1495 1 1 /* 2 2 * ORXONOX - the hottest 3D action shooter ever to exist 3 * > www.orxonox.net < * 3 * > www.orxonox.net < 4 * 4 5 * 5 6 * License notice: … … 25 26 * 26 27 */ 27 #ifndef _BaseWeapon_H__#define _BaseWeapon_H__#include "OrxonoxPrereqs.h"#include <OgrePrerequisites.h>#include "../Model.h"namespace orxonox { class _OrxonoxExport BaseWeapon : public Model { public: enum Action { NOTHING = 0, RELOAD = 1, CHANGE_AMMO = 2, SPECIAL = 3 }; protected: enum State { IDLE = 0, PRIMARY_FIRE = 1, SECONDARY_FIRE = 2, RELOADING = 3, CHANGING_AMMO = 4, }; public: BaseWeapon(); virtual ~BaseWeapon(); bool addAction(const Action); void primaryFireRequest(); void secondaryFireRequest(); int getAmmoState(); void setAmmoDump(AmmunitionDump*); inline virtual void loadParams(TiXmlElement* xmlElem) { Model::loadParams(xmlElem); }; virtual void tick(float dt); protected: virtual void primaryFire() = 0; virtual void primaryFiring(float) = 0; virtual void secondaryFire() = 0; virtual void secondaryFiring(float) = 0; virtual void registerAllVariables() { }; public: protected: Ogre::SceneManager *sceneMgr_; int bulletCounter_; BulletManager *bulletManager_; AmmunitionDump *ammoDump_; bool primaryFireRequest_; bool secondaryFireRequest_; float totalTime_; float actionStartTime_; State currentState_; bool secondaryFired_; Action nextAction_; bool actionAdded_; float timeSinceNextActionAdded_; static float nextActionValidityPeriod_s; // weapon properties int leftAmmo_; float primaryFirePower_; float secondaryFirePower_; float primaryFiringRate_; float secondaryFiringRate_; Real primaryBulletSpeed_; Real secondaryBulletSpeed_; int magazineSize_; };}#endif /* _BaseWeapon_H__ */ 28 29 30 #ifndef _BaseWeapon_H__ 31 #define _BaseWeapon_H__ 32 33 #include "OrxonoxPrereqs.h" 34 35 #include <OgrePrerequisites.h> 36 37 #include "../Model.h" 38 39 40 namespace orxonox { 41 class _OrxonoxExport BaseWeapon : public Model 42 { 43 public: 44 enum Action { 45 NOTHING = 0, 46 RELOAD = 1, 47 CHANGE_AMMO = 2, 48 SPECIAL = 3 49 }; 50 51 protected: 52 enum State { 53 IDLE = 0, 54 PRIMARY_FIRE = 1, 55 SECONDARY_FIRE = 2, 56 RELOADING = 3, 57 CHANGING_AMMO = 4, 58 }; 59 60 public: 61 BaseWeapon(); 62 virtual ~BaseWeapon(); 63 64 bool addAction(const Action); 65 66 void primaryFireRequest(); 67 68 void secondaryFireRequest(); 69 70 int getAmmoState(); 71 72 void setAmmoDump(AmmunitionDump*); 73 74 inline virtual void loadParams(TiXmlElement* xmlElem) { Model::loadParams(xmlElem); }; 75 76 virtual void tick(float dt); 77 78 protected: 79 virtual void primaryFire() = 0; 80 81 virtual void primaryFiring(float) = 0; 82 83 virtual void secondaryFire() = 0; 84 85 virtual void secondaryFiring(float) = 0; 86 87 virtual void registerAllVariables() { }; 88 89 public: 90 91 protected: 92 Ogre::SceneManager *sceneMgr_; 93 94 int bulletCounter_; 95 BulletManager *bulletManager_; 96 97 AmmunitionDump *ammoDump_; 98 99 bool primaryFireRequest_; 100 bool secondaryFireRequest_; 101 102 float totalTime_; 103 float actionStartTime_; 104 105 State currentState_; 106 bool secondaryFired_; 107 108 Action nextAction_; 109 bool actionAdded_; 110 float timeSinceNextActionAdded_; 111 static float nextActionValidityPeriod_s; 112 113 // weapon properties 114 int leftAmmo_; 115 float primaryFirePower_; 116 float secondaryFirePower_; 117 float primaryFiringRate_; 118 float secondaryFiringRate_; 119 Real primaryBulletSpeed_; 120 Real secondaryBulletSpeed_; 121 122 int magazineSize_; 123 124 }; 125 } 126 127 #endif /* _BaseWeapon_H__ */ -
code/branches/network/src/tinyxml/ticpp.cc
r1494 r1495 1 #define TIXML_USE_TICPP/* 1 #define TIXML_USE_TICPP 2 3 /* 2 4 http://code.google.com/p/ticpp/ 3 5 Copyright (c) 2006 Ryan Pusztai, Ryan Mulder -
code/branches/network/src/tinyxml/ticpp.h
r1494 r1495 1 #define TIXML_USE_TICPP/* 1 #define TIXML_USE_TICPP 2 3 /* 2 4 http://code.google.com/p/ticpp/ 3 5 Copyright (c) 2006 Ryan Pusztai, Ryan Mulder -
code/branches/network/src/tinyxml/ticpprc.h
r1494 r1495 1 #define TIXML_USE_TICPP/* 1 #define TIXML_USE_TICPP 2 3 /* 2 4 http://code.google.com/p/ticpp/ 3 5 Copyright (c) 2006 Ryan Pusztai, Ryan Mulder -
code/branches/network/src/tinyxml/tinyxml.h
r1494 r1495 1 #define TIXML_USE_TICPP/* 1 #define TIXML_USE_TICPP 2 3 /* 2 4 www.sourceforge.net/projects/tinyxml 3 5 Original code (2.0 and earlier )copyright (c) 2000-2006 Lee Thomason (www.grinninglizard.com) -
code/branches/network/src/util/ArgReader.cc
r1494 r1495 1 1 /* 2 2 * ORXONOX - the hottest 3D action shooter ever to exist 3 * > www.orxonox.net < * 3 * > www.orxonox.net < 4 * 4 5 * 5 6 * License notice: -
code/branches/network/src/util/ArgReader.h
r1494 r1495 1 /* * ORXONOX - the hottest 3D action shooter ever to exist * > www.orxonox.net < * * * License notice: * * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * * Author: * Benjamin Knecht <beni_at_orxonox.net> * Co-authors: * ... * *//** 1 /* 2 * ORXONOX - the hottest 3D action shooter ever to exist 3 * > www.orxonox.net < 4 * 5 * 6 * License notice: 7 * 8 * This program is free software; you can redistribute it and/or 9 * modify it under the terms of the GNU General Public License 10 * as published by the Free Software Foundation; either version 2 11 * of the License, or (at your option) any later version. 12 * 13 * This program is distributed in the hope that it will be useful, 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 * GNU General Public License for more details. 17 * 18 * You should have received a copy of the GNU General Public License 19 * along with this program; if not, write to the Free Software 20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 21 * 22 * Author: 23 * Benjamin Knecht <beni_at_orxonox.net> 24 * Co-authors: 25 * ... 26 * 27 */ 28 29 /** 2 30 @file Argreader.h 3 31 @brief reads arguments … … 8 36 #define _ArgReader_H__ 9 37 10 #include "UtilPrereqs.h"#include <string> 38 #include "UtilPrereqs.h" 39 40 #include <string> 41 11 42 class _UtilExport ArgReader 12 43 { -
code/branches/network/src/util/Convert.h
r1494 r1495 1 1 /* 2 2 * ORXONOX - the hottest 3D action shooter ever to exist 3 * > www.orxonox.net < * 3 * > www.orxonox.net < 4 * 4 5 * 5 6 * License notice: … … 21 22 * Author: 22 23 * Benjamin Grauer 23 * Fabian 'x3n' Landau * Co-authors: * ... 24 * Fabian 'x3n' Landau 25 * Co-authors: 26 * ... 24 27 */ 25 28 … … 46 49 #pragma warning(disable:4100 4800) 47 50 #endif 48 //////////// MAIN ////////////// Enum to declare the wanted conversion preference in case of equal type-levelsenum ConversionPreference{ CP_PreferToType, CP_PreferFromType,};// Helper classes to determine the preferred partial template specializationclass _ToType_ {};class _FromType_ {};class _Explicit_ {};// The default convert functionstemplate <class FromType, class ToType, class Type>struct ConverterSpecialized{ enum { specialized = false }; static bool convert(ToType* output, const FromType& input) { return false; }};// The default convert function if both types are the sametemplate <class BothTypes>struct ConverterSpecialized<BothTypes, BothTypes, _Explicit_>{ enum { specialized = true }; static bool convert(BothTypes* output, const BothTypes& input) { (*output) = input; return true; }};// The possible levels#define __low__ 0 // Everything that is or behaves like a primitive type (an can be converted with a typecast to every other low-level type)#define __mid__ 1 // Everything that has overloaded << and >> operators to operate on a std::stream#define __high__ 2 // Everything that doesn't fullfill the lowerlevel-requirements and therefore needs specialized conversions// Defines the levels of all types: Default is __high__ so you don't have to define every high-level typetemplate <class T> struct ConverterLevel { enum { level = __high__ }; };template <> struct ConverterLevel<std::string> { enum { level = __mid__ }; };template <> struct ConverterLevel<orxonox::Radian> { enum { level = __mid__ }; };template <> struct ConverterLevel<orxonox::Degree> { enum { level = __mid__ }; };template <> struct ConverterLevel<int> { enum { level = __low__ }; };template <> struct ConverterLevel<unsigned int> { enum { level = __low__ }; };template <> struct ConverterLevel<char> { enum { level = __low__ }; };template <> struct ConverterLevel<unsigned char> { enum { level = __low__ }; };template <> struct ConverterLevel<short> { enum { level = __low__ }; };template <> struct ConverterLevel<unsigned short> { enum { level = __low__ }; };template <> struct ConverterLevel<long> { enum { level = __low__ }; };template <> struct ConverterLevel<unsigned long> { enum { level = __low__ }; };template <> struct ConverterLevel<float> { enum { level = __low__ }; };template <> struct ConverterLevel<double> { enum { level = __low__ }; };template <> struct ConverterLevel<long double> { enum { level = __low__ }; };template <> struct ConverterLevel<bool> { enum { level = __low__ }; };// Calculates the preference based on the levels of FromType and ToTypetemplate <int from, int to>struct ConverterPreference{ enum { // The maximum of both levels: element of {0, 1, 2} // max 0: Both types are primitives or have a similar behaviour // max 1: At least one type is not a primitive, but both can be put on a std::stream // max 2: There is at least one generic type that needs specialized conversions max = (from > to) ? from : to, // The difference between both levels limited to +-1: element of {-1, 0, 1} // diff -1: The FromType has higher level than the ToType // diff 0: Both types have the same level // diff 1: The ToType has higher level than the FromType diff = ((to - from) > 1) ? 1 : (((to - from) < -1) ? -1 : to - from) };};// The default conversion: This usually does nothingtemplate <int max, class FromType, class ToType>struct ConverterDefault{ static bool convert(ToType* output, const FromType& input) { return false; }};// The default conversion for primitives: A typecast (defined over two partial specialized templates to exclude all non-primitive types and classes) template <int max, class FromType, class ToType>template <class FromType, class ToType>struct ConverterDefault<0, FromType, ToType>{ static bool convert(ToType* output, const FromType& input) { (*output) = (ToType)input; return true; }};// Converter: Converts input of FromType into output of ToTypetemplate <int diff, int max, class FromType, class ToType, ConversionPreference pref>struct Converter{ static bool convert(ToType* output, const FromType& input) { return false; }};// Converter: level{FromType} > level{ToType}template <int max, class FromType, class ToType, ConversionPreference pref>struct Converter<-1, max, FromType, ToType, pref>{ static bool convert(ToType* output, const FromType& input) { return (ConverterSpecialized<FromType, ToType, _Explicit_>::specialized) ? (ConverterSpecialized<FromType, ToType, _Explicit_>::convert(output, input)) : (ConverterSpecialized<FromType, ToType, _FromType_>::specialized) ? (ConverterSpecialized<FromType, ToType, _FromType_>::convert(output, input)) : (ConverterDefault<max, FromType, ToType>::convert(output, input)); } };// Converter: level{FromType} < level{ToType}template <int max, class FromType, class ToType, ConversionPreference pref>struct Converter<1, max, FromType, ToType, pref>{ static bool convert(ToType* output, const FromType& input) { return (ConverterSpecialized<FromType, ToType, _Explicit_>::specialized) ? (ConverterSpecialized<FromType, ToType, _Explicit_>::convert(output, input)) : (ConverterSpecialized<FromType, ToType, _ToType_>::specialized) ? (ConverterSpecialized<FromType, ToType, _ToType_>::convert(output, input)) : (ConverterDefault<max, FromType, ToType>::convert(output, input)); } };// Converter: level{FromType} = level{ToType}// CP_PreferToTypetemplate <int max, class FromType, class ToType>struct Converter<0, max, FromType, ToType, CP_PreferToType>{ static bool convert(ToType* output, const FromType& input) { return (ConverterSpecialized<FromType, ToType, _Explicit_>::specialized) ? (ConverterSpecialized<FromType, ToType, _Explicit_>::convert(output, input)) : (ConverterSpecialized<FromType, ToType, _ToType_>::specialized) ? (ConverterSpecialized<FromType, ToType, _ToType_>::convert(output, input)) : (ConverterSpecialized<FromType, ToType, _FromType_>::specialized) ? (ConverterSpecialized<FromType, ToType, _FromType_>::convert(output, input)) : (ConverterDefault<max, FromType, ToType>::convert(output, input)); } };// CP_PreferFromTypetemplate <int max, class FromType, class ToType>struct Converter<0, max, FromType, ToType, CP_PreferFromType>{ static bool convert(ToType* output, const FromType& input) { return (ConverterSpecialized<FromType, ToType, _Explicit_>::specialized) ? (ConverterSpecialized<FromType, ToType, _Explicit_>::convert(output, input)) : (ConverterSpecialized<FromType, ToType, _FromType_>::specialized) ? (ConverterSpecialized<FromType, ToType, _FromType_>::convert(output, input)) : (ConverterSpecialized<FromType, ToType, _ToType_>::specialized) ? (ConverterSpecialized<FromType, ToType, _ToType_>::convert(output, input)) : (ConverterDefault<max, FromType, ToType>::convert(output, input)); } };// Calls the Converter::convertValue function with the correct template type parameters calculated by ConverterPreferencetemplate <class FromType, class ToType>static bool convertValue(ToType* output, const FromType& input, ConversionPreference preference = CP_PreferToType){ return (preference == CP_PreferToType) ? Converter<ConverterPreference<ConverterLevel<FromType>::level, ConverterLevel<ToType>::level>::diff, ConverterPreference<ConverterLevel<FromType>::level, ConverterLevel<ToType>::level>::max, FromType, ToType, CP_PreferToType>::convert(output, input) : Converter<ConverterPreference<ConverterLevel<FromType>::level, ConverterLevel<ToType>::level>::diff, ConverterPreference<ConverterLevel<FromType>::level, ConverterLevel<ToType>::level>::max, FromType, ToType, CP_PreferFromType>::convert(output, input);}//////////////////////// HELPER FUNCTIONS ////////////////////////// Helper function: Calls convertValue with and without default value and returns true if the conversion was successfultemplate<class FromType, class ToType>static bool ConvertValue(ToType* output, const FromType& input, ConversionPreference preference = CP_PreferToType){ return convertValue(output, input, preference);}template<class FromType, class ToType>static bool ConvertValue(ToType* output, const FromType& input, const ToType& fallback, ConversionPreference preference = CP_PreferToType){ if (convertValue(output, input, preference)) return true; (*output) = fallback; return false;}// Helper function: Calls convertValue with and without default value and returns the converted valuetemplate<class FromType, class ToType>static ToType getConvertedValue(const FromType& input, ConversionPreference preference = CP_PreferToType){ ToType output = ToType(); ConvertValue(&output, input, preference); return output;}template<class FromType, class ToType>static ToType getConvertedValue(const FromType& input, const ToType& fallback, ConversionPreference preference = CP_PreferToType){ ToType output = fallback; ConvertValue(&output, input, fallback, preference); return output;} 51 52 53 ////////// 54 // MAIN // 55 ////////// 56 57 // Enum to declare the wanted conversion preference in case of equal type-levels 58 enum ConversionPreference 59 { 60 CP_PreferToType, 61 CP_PreferFromType, 62 }; 63 64 // Helper classes to determine the preferred partial template specialization 65 class _ToType_ {}; 66 class _FromType_ {}; 67 class _Explicit_ {}; 68 69 70 // The default convert functions 71 template <class FromType, class ToType, class Type> 72 struct ConverterSpecialized 73 { 74 enum { specialized = false }; 75 static bool convert(ToType* output, const FromType& input) 76 { return false; } 77 }; 78 79 80 // The default convert function if both types are the same 81 template <class BothTypes> 82 struct ConverterSpecialized<BothTypes, BothTypes, _Explicit_> 83 { 84 enum { specialized = true }; 85 static bool convert(BothTypes* output, const BothTypes& input) 86 { (*output) = input; return true; } 87 }; 88 89 90 // The possible levels 91 #define __low__ 0 // Everything that is or behaves like a primitive type (an can be converted with a typecast to every other low-level type) 92 #define __mid__ 1 // Everything that has overloaded << and >> operators to operate on a std::stream 93 #define __high__ 2 // Everything that doesn't fullfill the lowerlevel-requirements and therefore needs specialized conversions 94 95 // Defines the levels of all types: Default is __high__ so you don't have to define every high-level type 96 template <class T> struct ConverterLevel { enum { level = __high__ }; }; 97 template <> struct ConverterLevel<std::string> { enum { level = __mid__ }; }; 98 template <> struct ConverterLevel<orxonox::Radian> { enum { level = __mid__ }; }; 99 template <> struct ConverterLevel<orxonox::Degree> { enum { level = __mid__ }; }; 100 template <> struct ConverterLevel<int> { enum { level = __low__ }; }; 101 template <> struct ConverterLevel<unsigned int> { enum { level = __low__ }; }; 102 template <> struct ConverterLevel<char> { enum { level = __low__ }; }; 103 template <> struct ConverterLevel<unsigned char> { enum { level = __low__ }; }; 104 template <> struct ConverterLevel<short> { enum { level = __low__ }; }; 105 template <> struct ConverterLevel<unsigned short> { enum { level = __low__ }; }; 106 template <> struct ConverterLevel<long> { enum { level = __low__ }; }; 107 template <> struct ConverterLevel<unsigned long> { enum { level = __low__ }; }; 108 template <> struct ConverterLevel<float> { enum { level = __low__ }; }; 109 template <> struct ConverterLevel<double> { enum { level = __low__ }; }; 110 template <> struct ConverterLevel<long double> { enum { level = __low__ }; }; 111 template <> struct ConverterLevel<bool> { enum { level = __low__ }; }; 112 113 114 // Calculates the preference based on the levels of FromType and ToType 115 template <int from, int to> 116 struct ConverterPreference 117 { 118 enum 119 { 120 // The maximum of both levels: element of {0, 1, 2} 121 // max 0: Both types are primitives or have a similar behaviour 122 // max 1: At least one type is not a primitive, but both can be put on a std::stream 123 // max 2: There is at least one generic type that needs specialized conversions 124 max = (from > to) ? from : to, 125 126 // The difference between both levels limited to +-1: element of {-1, 0, 1} 127 // diff -1: The FromType has higher level than the ToType 128 // diff 0: Both types have the same level 129 // diff 1: The ToType has higher level than the FromType 130 diff = ((to - from) > 1) ? 1 : (((to - from) < -1) ? -1 : to - from) 131 }; 132 }; 133 134 135 // The default conversion: This usually does nothing 136 template <int max, class FromType, class ToType> 137 struct ConverterDefault 138 { 139 static bool convert(ToType* output, const FromType& input) 140 { 141 return false; 142 } 143 }; 144 // The default conversion for primitives: A typecast (defined over two partial specialized templates to exclude all non-primitive types and classes) template <int max, class FromType, class ToType> 145 template <class FromType, class ToType> 146 struct ConverterDefault<0, FromType, ToType> 147 { 148 static bool convert(ToType* output, const FromType& input) 149 { 150 (*output) = (ToType)input; 151 return true; 152 } 153 }; 154 155 156 // Converter: Converts input of FromType into output of ToType 157 template <int diff, int max, class FromType, class ToType, ConversionPreference pref> 158 struct Converter 159 { 160 static bool convert(ToType* output, const FromType& input) 161 { 162 return false; 163 } 164 }; 165 // Converter: level{FromType} > level{ToType} 166 template <int max, class FromType, class ToType, ConversionPreference pref> 167 struct Converter<-1, max, FromType, ToType, pref> 168 { static bool convert(ToType* output, const FromType& input) 169 { return (ConverterSpecialized<FromType, ToType, _Explicit_>::specialized) ? (ConverterSpecialized<FromType, ToType, _Explicit_>::convert(output, input)) : (ConverterSpecialized<FromType, ToType, _FromType_>::specialized) ? (ConverterSpecialized<FromType, ToType, _FromType_>::convert(output, input)) : (ConverterDefault<max, FromType, ToType>::convert(output, input)); } }; 170 // Converter: level{FromType} < level{ToType} 171 template <int max, class FromType, class ToType, ConversionPreference pref> 172 struct Converter<1, max, FromType, ToType, pref> 173 { static bool convert(ToType* output, const FromType& input) 174 { return (ConverterSpecialized<FromType, ToType, _Explicit_>::specialized) ? (ConverterSpecialized<FromType, ToType, _Explicit_>::convert(output, input)) : (ConverterSpecialized<FromType, ToType, _ToType_>::specialized) ? (ConverterSpecialized<FromType, ToType, _ToType_>::convert(output, input)) : (ConverterDefault<max, FromType, ToType>::convert(output, input)); } }; 175 // Converter: level{FromType} = level{ToType} 176 // CP_PreferToType 177 template <int max, class FromType, class ToType> 178 struct Converter<0, max, FromType, ToType, CP_PreferToType> 179 { static bool convert(ToType* output, const FromType& input) 180 { return (ConverterSpecialized<FromType, ToType, _Explicit_>::specialized) ? (ConverterSpecialized<FromType, ToType, _Explicit_>::convert(output, input)) : (ConverterSpecialized<FromType, ToType, _ToType_>::specialized) ? (ConverterSpecialized<FromType, ToType, _ToType_>::convert(output, input)) : (ConverterSpecialized<FromType, ToType, _FromType_>::specialized) ? (ConverterSpecialized<FromType, ToType, _FromType_>::convert(output, input)) : (ConverterDefault<max, FromType, ToType>::convert(output, input)); } }; 181 // CP_PreferFromType 182 template <int max, class FromType, class ToType> 183 struct Converter<0, max, FromType, ToType, CP_PreferFromType> 184 { static bool convert(ToType* output, const FromType& input) 185 { return (ConverterSpecialized<FromType, ToType, _Explicit_>::specialized) ? (ConverterSpecialized<FromType, ToType, _Explicit_>::convert(output, input)) : (ConverterSpecialized<FromType, ToType, _FromType_>::specialized) ? (ConverterSpecialized<FromType, ToType, _FromType_>::convert(output, input)) : (ConverterSpecialized<FromType, ToType, _ToType_>::specialized) ? (ConverterSpecialized<FromType, ToType, _ToType_>::convert(output, input)) : (ConverterDefault<max, FromType, ToType>::convert(output, input)); } }; 186 187 188 // Calls the Converter::convertValue function with the correct template type parameters calculated by ConverterPreference 189 template <class FromType, class ToType> 190 static bool convertValue(ToType* output, const FromType& input, ConversionPreference preference = CP_PreferToType) 191 { 192 return (preference == CP_PreferToType) ? 193 Converter<ConverterPreference<ConverterLevel<FromType>::level, ConverterLevel<ToType>::level>::diff, 194 ConverterPreference<ConverterLevel<FromType>::level, ConverterLevel<ToType>::level>::max, 195 FromType, 196 ToType, 197 CP_PreferToType>::convert(output, input) 198 : Converter<ConverterPreference<ConverterLevel<FromType>::level, ConverterLevel<ToType>::level>::diff, 199 ConverterPreference<ConverterLevel<FromType>::level, ConverterLevel<ToType>::level>::max, 200 FromType, 201 ToType, 202 CP_PreferFromType>::convert(output, input); 203 } 204 205 206 ////////////////////// 207 // HELPER FUNCTIONS // 208 ////////////////////// 209 210 // Helper function: Calls convertValue with and without default value and returns true if the conversion was successful 211 template<class FromType, class ToType> 212 static bool ConvertValue(ToType* output, const FromType& input, ConversionPreference preference = CP_PreferToType) 213 { 214 return convertValue(output, input, preference); 215 } 216 template<class FromType, class ToType> 217 static bool ConvertValue(ToType* output, const FromType& input, const ToType& fallback, ConversionPreference preference = CP_PreferToType) 218 { 219 if (convertValue(output, input, preference)) 220 return true; 221 222 (*output) = fallback; 223 return false; 224 } 225 226 // Helper function: Calls convertValue with and without default value and returns the converted value 227 template<class FromType, class ToType> 228 static ToType getConvertedValue(const FromType& input, ConversionPreference preference = CP_PreferToType) 229 { 230 ToType output = ToType(); 231 ConvertValue(&output, input, preference); 232 return output; 233 } 234 template<class FromType, class ToType> 235 static ToType getConvertedValue(const FromType& input, const ToType& fallback, ConversionPreference preference = CP_PreferToType) 236 { 237 ToType output = fallback; 238 ConvertValue(&output, input, fallback, preference); 239 return output; 240 } 241 242 49 243 ///////////////////// 50 244 // SPECIALIZATIONS // 51 245 ///////////////////// 52 /////////////// SAMPLES ////////////////*// convert everything to xyztemplate <class FromType>struct ConverterSpecialized<FromType, xyz, _ToType_>{ enum { specialized = true }; static bool convert(xyz* output, const FromType& input) { return ...; }};// convert xyz to everythingtemplate <class ToType>struct ConverterSpecialized<xyz, ToType, _FromType_>{ enum { specialized = true }; static bool convert(ToType* output, const xyz& input) { return ...; }};// convert abc to xyztemplate <>struct ConverterSpecialized<abc, xyz, _Explicit_>{ enum { specialized = true }; static bool convert(xyz* output, const abc& input) { return ...; }};*/////////////// STRING //////////////// convert to stringtemplate <class FromType>struct ConverterSpecialized<FromType, std::string, _ToType_>{ enum { specialized = true }; static bool convert(std::string* output, const FromType& input) { std::ostringstream oss; if (oss << input) { (*output) = oss.str(); return true; } else return false; }};// convert from stringtemplate <class ToType>struct ConverterSpecialized<std::string, ToType, _FromType_>{ enum { specialized = true }; static bool convert(ToType* output, const std::string& input) { std::istringstream iss(input); if (iss >> (*output)) return true; else return false; }};////////////////// MULTITYPES //////////////////// convert from MultiTypePrimitivetemplate <class ToType>struct ConverterSpecialized<MultiTypePrimitive, ToType, _FromType_>{ enum { specialized = true }; static bool convert(ToType* output, const MultiTypePrimitive& input) { if (input.getType() == MT_void) return ConvertValue(output, input.getVoid()); else if (input.getType() == MT_int) return ConvertValue(output, input.getInt()); else if (input.getType() == MT_uint) return ConvertValue(output, input.getUnsignedInt()); else if (input.getType() == MT_char) return ConvertValue(output, input.getChar()); else if (input.getType() == MT_uchar) return ConvertValue(output, input.getUnsignedChar()); else if (input.getType() == MT_short) return ConvertValue(output, input.getShort()); else if (input.getType() == MT_ushort) return ConvertValue(output, input.getUnsignedShort()); else if (input.getType() == MT_long) return ConvertValue(output, input.getLong()); else if (input.getType() == MT_ulong) return ConvertValue(output, input.getUnsignedLong()); else if (input.getType() == MT_float) return ConvertValue(output, input.getFloat()); else if (input.getType() == MT_double) return ConvertValue(output, input.getDouble()); else if (input.getType() == MT_longdouble) return ConvertValue(output, input.getLongDouble()); else if (input.getType() == MT_bool) return ConvertValue(output, input.getBool()); else return false; }};// convert from MultiTypeStringtemplate <class ToType>struct ConverterSpecialized<MultiTypeString, ToType, _FromType_>{ enum { specialized = true }; static bool convert(ToType* output, const MultiTypeString& input) { if (input.getType() == MT_constchar) return ConvertValue(output, input.getConstChar()); else if (input.getType() == MT_string) return ConvertValue(output, input.getString()); else return ConvertValue(output, (MultiTypePrimitive)input); }};// convert from MultiTypeMathtemplate <class ToType>struct ConverterSpecialized<MultiTypeMath, ToType, _FromType_>{ enum { specialized = true }; static bool convert(ToType* output, const MultiTypeMath& input) { if (input.getType() == MT_vector2) return ConvertValue(output, input.getVector2()); else if (input.getType() == MT_vector3) return ConvertValue(output, input.getVector3()); else if (input.getType() == MT_vector4) return ConvertValue(output, input.getVector4()); else if (input.getType() == MT_quaternion) return ConvertValue(output, input.getQuaternion()); else if (input.getType() == MT_colourvalue) return ConvertValue(output, input.getColourValue()); else if (input.getType() == MT_radian) return ConvertValue(output, input.getRadian()); else if (input.getType() == MT_degree) return ConvertValue(output, input.getDegree()); else return ConvertValue(output, (MultiTypeString)input); }}; 246 247 ///////////// 248 // SAMPLES // 249 ///////////// 250 /* 251 // convert everything to xyz 252 template <class FromType> 253 struct ConverterSpecialized<FromType, xyz, _ToType_> 254 { 255 enum { specialized = true }; 256 static bool convert(xyz* output, const FromType& input) 257 { return ...; } 258 }; 259 260 // convert xyz to everything 261 template <class ToType> 262 struct ConverterSpecialized<xyz, ToType, _FromType_> 263 { 264 enum { specialized = true }; 265 static bool convert(ToType* output, const xyz& input) 266 { return ...; } 267 }; 268 269 // convert abc to xyz 270 template <> 271 struct ConverterSpecialized<abc, xyz, _Explicit_> 272 { 273 enum { specialized = true }; 274 static bool convert(xyz* output, const abc& input) 275 { return ...; } 276 }; 277 */ 278 279 //////////// 280 // STRING // 281 //////////// 282 283 // convert to string 284 template <class FromType> 285 struct ConverterSpecialized<FromType, std::string, _ToType_> 286 { 287 enum { specialized = true }; 288 static bool convert(std::string* output, const FromType& input) 289 { 290 std::ostringstream oss; 291 if (oss << input) 292 { 293 (*output) = oss.str(); 294 return true; 295 } 296 else 297 return false; 298 } 299 }; 300 301 // convert from string 302 template <class ToType> 303 struct ConverterSpecialized<std::string, ToType, _FromType_> 304 { 305 enum { specialized = true }; 306 static bool convert(ToType* output, const std::string& input) 307 { 308 std::istringstream iss(input); 309 if (iss >> (*output)) 310 return true; 311 else 312 return false; 313 } 314 }; 315 316 317 //////////////// 318 // MULTITYPES // 319 //////////////// 320 321 // convert from MultiTypePrimitive 322 template <class ToType> 323 struct ConverterSpecialized<MultiTypePrimitive, ToType, _FromType_> 324 { 325 enum { specialized = true }; 326 static bool convert(ToType* output, const MultiTypePrimitive& input) 327 { 328 if (input.getType() == MT_void) 329 return ConvertValue(output, input.getVoid()); 330 else if (input.getType() == MT_int) 331 return ConvertValue(output, input.getInt()); 332 else if (input.getType() == MT_uint) 333 return ConvertValue(output, input.getUnsignedInt()); 334 else if (input.getType() == MT_char) 335 return ConvertValue(output, input.getChar()); 336 else if (input.getType() == MT_uchar) 337 return ConvertValue(output, input.getUnsignedChar()); 338 else if (input.getType() == MT_short) 339 return ConvertValue(output, input.getShort()); 340 else if (input.getType() == MT_ushort) 341 return ConvertValue(output, input.getUnsignedShort()); 342 else if (input.getType() == MT_long) 343 return ConvertValue(output, input.getLong()); 344 else if (input.getType() == MT_ulong) 345 return ConvertValue(output, input.getUnsignedLong()); 346 else if (input.getType() == MT_float) 347 return ConvertValue(output, input.getFloat()); 348 else if (input.getType() == MT_double) 349 return ConvertValue(output, input.getDouble()); 350 else if (input.getType() == MT_longdouble) 351 return ConvertValue(output, input.getLongDouble()); 352 else if (input.getType() == MT_bool) 353 return ConvertValue(output, input.getBool()); 354 else 355 return false; 356 } 357 }; 358 359 // convert from MultiTypeString 360 template <class ToType> 361 struct ConverterSpecialized<MultiTypeString, ToType, _FromType_> 362 { 363 enum { specialized = true }; 364 static bool convert(ToType* output, const MultiTypeString& input) 365 { 366 if (input.getType() == MT_constchar) 367 return ConvertValue(output, input.getConstChar()); 368 else if (input.getType() == MT_string) 369 return ConvertValue(output, input.getString()); 370 else 371 return ConvertValue(output, (MultiTypePrimitive)input); 372 } 373 }; 374 375 // convert from MultiTypeMath 376 template <class ToType> 377 struct ConverterSpecialized<MultiTypeMath, ToType, _FromType_> 378 { 379 enum { specialized = true }; 380 static bool convert(ToType* output, const MultiTypeMath& input) 381 { 382 if (input.getType() == MT_vector2) 383 return ConvertValue(output, input.getVector2()); 384 else if (input.getType() == MT_vector3) 385 return ConvertValue(output, input.getVector3()); 386 else if (input.getType() == MT_vector4) 387 return ConvertValue(output, input.getVector4()); 388 else if (input.getType() == MT_quaternion) 389 return ConvertValue(output, input.getQuaternion()); 390 else if (input.getType() == MT_colourvalue) 391 return ConvertValue(output, input.getColourValue()); 392 else if (input.getType() == MT_radian) 393 return ConvertValue(output, input.getRadian()); 394 else if (input.getType() == MT_degree) 395 return ConvertValue(output, input.getDegree()); 396 else 397 return ConvertValue(output, (MultiTypeString)input); 398 } 399 }; 400 401 53 402 //////////////////// 54 403 // MATH TO STRING // 55 404 //////////////////// 56 // Vector2 to std::stringtemplate <>struct ConverterSpecialized<orxonox::Vector2, std::string, _Explicit_>{ enum { specialized = true }; static bool convert(std::string* output, const orxonox::Vector2& input) { std::ostringstream ostream; if (ostream << input.x << "," << input.y) { (*output) = ostream.str(); return true; } return false; }};// Vector3 to std::stringtemplate <>struct ConverterSpecialized<orxonox::Vector3, std::string, _Explicit_>{ enum { specialized = true }; static bool convert(std::string* output, const orxonox::Vector3& input) { std::ostringstream ostream; if (ostream << input.x << "," << input.y << "," << input.z) { (*output) = ostream.str(); return true; } return false; }};// Vector4 to std::stringtemplate <>struct ConverterSpecialized<orxonox::Vector4, std::string, _Explicit_>{ enum { specialized = true }; static bool convert(std::string* output, const orxonox::Vector4& input) { std::ostringstream ostream; if (ostream << input.x << "," << input.y << "," << input.z << "," << input.w) { (*output) = ostream.str(); return true; } return false; }};// Quaternion to std::stringtemplate <>struct ConverterSpecialized<orxonox::Quaternion, std::string, _Explicit_>{ enum { specialized = true }; static bool convert(std::string* output, const orxonox::Quaternion& input) { std::ostringstream ostream; if (ostream << input.w << "," << input.x << "," << input.y << "," << input.z) { (*output) = ostream.str(); return true; } return false; }};// ColourValue to std::stringtemplate <>struct ConverterSpecialized<orxonox::ColourValue, std::string, _Explicit_>{ enum { specialized = true }; static bool convert(std::string* output, const orxonox::ColourValue& input) { std::ostringstream ostream; if (ostream << input.r << "," << input.g << "," << input.b << "," << input.a) { (*output) = ostream.str(); return true; } return false; }};//////////////////// 405 406 // Vector2 to std::string 407 template <> 408 struct ConverterSpecialized<orxonox::Vector2, std::string, _Explicit_> 409 { 410 enum { specialized = true }; 411 static bool convert(std::string* output, const orxonox::Vector2& input) 412 { 413 std::ostringstream ostream; 414 if (ostream << input.x << "," << input.y) 415 { 416 (*output) = ostream.str(); 417 return true; 418 } 419 return false; 420 } 421 }; 422 423 // Vector3 to std::string 424 template <> 425 struct ConverterSpecialized<orxonox::Vector3, std::string, _Explicit_> 426 { 427 enum { specialized = true }; 428 static bool convert(std::string* output, const orxonox::Vector3& input) 429 { 430 std::ostringstream ostream; 431 if (ostream << input.x << "," << input.y << "," << input.z) 432 { 433 (*output) = ostream.str(); 434 return true; 435 } 436 return false; 437 } 438 }; 439 440 // Vector4 to std::string 441 template <> 442 struct ConverterSpecialized<orxonox::Vector4, std::string, _Explicit_> 443 { 444 enum { specialized = true }; 445 static bool convert(std::string* output, const orxonox::Vector4& input) 446 { 447 std::ostringstream ostream; 448 if (ostream << input.x << "," << input.y << "," << input.z << "," << input.w) 449 { 450 (*output) = ostream.str(); 451 return true; 452 } 453 return false; 454 } 455 }; 456 457 // Quaternion to std::string 458 template <> 459 struct ConverterSpecialized<orxonox::Quaternion, std::string, _Explicit_> 460 { 461 enum { specialized = true }; 462 static bool convert(std::string* output, const orxonox::Quaternion& input) 463 { 464 std::ostringstream ostream; 465 if (ostream << input.w << "," << input.x << "," << input.y << "," << input.z) 466 { 467 (*output) = ostream.str(); 468 return true; 469 } 470 return false; 471 } 472 }; 473 474 // ColourValue to std::string 475 template <> 476 struct ConverterSpecialized<orxonox::ColourValue, std::string, _Explicit_> 477 { 478 enum { specialized = true }; 479 static bool convert(std::string* output, const orxonox::ColourValue& input) 480 { 481 std::ostringstream ostream; 482 if (ostream << input.r << "," << input.g << "," << input.b << "," << input.a) 483 { 484 (*output) = ostream.str(); 485 return true; 486 } 487 return false; 488 } 489 }; 490 491 492 //////////////////// 57 493 // STRING TO MATH // 58 494 //////////////////// 59 // std::string to Vector2template <>struct ConverterSpecialized<std::string, orxonox::Vector2, _Explicit_>{ enum { specialized = true }; static bool convert(orxonox::Vector2* output, const std::string& input) { unsigned int opening_parenthesis, closing_parenthesis = input.find(')'); if ((opening_parenthesis = input.find('(')) == std::string::npos) { opening_parenthesis = 0; } else { opening_parenthesis++; } SubString tokens(input.substr(opening_parenthesis, closing_parenthesis - opening_parenthesis), ",", SubString::WhiteSpaces, false, '\\', true, '"', true, '\0', '\0', true, '\0'); if (tokens.size() >= 2) { if (!ConvertValue(&(output->x), tokens[0])) return false; if (!ConvertValue(&(output->y), tokens[1])) return false; return true; } return false; }};// std::string to Vector3template <>struct ConverterSpecialized<std::string, orxonox::Vector3, _Explicit_>{ enum { specialized = true }; static bool convert(orxonox::Vector3* output, const std::string& input) { unsigned int opening_parenthesis, closing_parenthesis = input.find(')'); if ((opening_parenthesis = input.find('(')) == std::string::npos) { opening_parenthesis = 0; } else { opening_parenthesis++; } SubString tokens(input.substr(opening_parenthesis, closing_parenthesis - opening_parenthesis), ",", SubString::WhiteSpaces, false, '\\', true, '"', true, '\0', '\0', true, '\0'); if (tokens.size() >= 3) { if (!ConvertValue(&(output->x), tokens[0])) return false; if (!ConvertValue(&(output->y), tokens[1])) return false; if (!ConvertValue(&(output->z), tokens[2])) return false; return true; } return false; }};// std::string to Vector4template <>struct ConverterSpecialized<std::string, orxonox::Vector4, _Explicit_>{ enum { specialized = true }; static bool convert(orxonox::Vector4* output, const std::string& input) { unsigned int opening_parenthesis, closing_parenthesis = input.find(')'); if ((opening_parenthesis = input.find('(')) == std::string::npos) { opening_parenthesis = 0; } else { opening_parenthesis++; } SubString tokens(input.substr(opening_parenthesis, closing_parenthesis - opening_parenthesis), ",", SubString::WhiteSpaces, false, '\\', true, '"', true, '\0', '\0', true, '\0'); if (tokens.size() >= 4) { if (!ConvertValue(&(output->x), tokens[0])) return false; if (!ConvertValue(&(output->y), tokens[1])) return false; if (!ConvertValue(&(output->z), tokens[2])) return false; if (!ConvertValue(&(output->w), tokens[3])) return false; return true; } return false; }};// std::string to Quaterniontemplate <>struct ConverterSpecialized<std::string, orxonox::Quaternion, _Explicit_>{ enum { specialized = true }; static bool convert(orxonox::Quaternion* output, const std::string& input) { unsigned int opening_parenthesis, closing_parenthesis = input.find(')'); if ((opening_parenthesis = input.find('(')) == std::string::npos) { opening_parenthesis = 0; } else { opening_parenthesis++; } SubString tokens(input.substr(opening_parenthesis, closing_parenthesis - opening_parenthesis), ",", SubString::WhiteSpaces, false, '\\', true, '"', true, '\0', '\0', true, '\0'); if (tokens.size() >= 4) { if (!ConvertValue(&(output->w), tokens[0])) return false; if (!ConvertValue(&(output->x), tokens[1])) return false; if (!ConvertValue(&(output->y), tokens[2])) return false; if (!ConvertValue(&(output->z), tokens[3])) return false; return true; } return false; }};// std::string to ColourValuetemplate <>struct ConverterSpecialized<std::string, orxonox::ColourValue, _Explicit_>{ enum { specialized = true }; static bool convert(orxonox::ColourValue* output, const std::string& input) { unsigned int opening_parenthesis, closing_parenthesis = input.find(')'); if ((opening_parenthesis = input.find('(')) == std::string::npos) { opening_parenthesis = 0; } else { opening_parenthesis++; } SubString tokens(input.substr(opening_parenthesis, closing_parenthesis - opening_parenthesis), ",", SubString::WhiteSpaces, false, '\\', true, '"', true, '\0', '\0', true, '\0'); if (tokens.size() >= 4) { if (!ConvertValue(&(output->r), tokens[0])) return false; if (!ConvertValue(&(output->g), tokens[1])) return false; if (!ConvertValue(&(output->b), tokens[2])) return false; if (!ConvertValue(&(output->a), tokens[3])) return false; return true; } return false; }};#if ORXONOX_COMPILER == ORXONOX_COMPILER_MSVC 495 496 // std::string to Vector2 497 template <> 498 struct ConverterSpecialized<std::string, orxonox::Vector2, _Explicit_> 499 { 500 enum { specialized = true }; 501 static bool convert(orxonox::Vector2* output, const std::string& input) 502 { 503 unsigned int opening_parenthesis, closing_parenthesis = input.find(')'); 504 if ((opening_parenthesis = input.find('(')) == std::string::npos) { opening_parenthesis = 0; } else { opening_parenthesis++; } 505 506 SubString tokens(input.substr(opening_parenthesis, closing_parenthesis - opening_parenthesis), ",", SubString::WhiteSpaces, false, '\\', true, '"', true, '\0', '\0', true, '\0'); 507 if (tokens.size() >= 2) 508 { 509 if (!ConvertValue(&(output->x), tokens[0])) 510 return false; 511 if (!ConvertValue(&(output->y), tokens[1])) 512 return false; 513 514 return true; 515 } 516 return false; 517 } 518 }; 519 520 // std::string to Vector3 521 template <> 522 struct ConverterSpecialized<std::string, orxonox::Vector3, _Explicit_> 523 { 524 enum { specialized = true }; 525 static bool convert(orxonox::Vector3* output, const std::string& input) 526 { 527 unsigned int opening_parenthesis, closing_parenthesis = input.find(')'); 528 if ((opening_parenthesis = input.find('(')) == std::string::npos) { opening_parenthesis = 0; } else { opening_parenthesis++; } 529 530 SubString tokens(input.substr(opening_parenthesis, closing_parenthesis - opening_parenthesis), ",", SubString::WhiteSpaces, false, '\\', true, '"', true, '\0', '\0', true, '\0'); 531 if (tokens.size() >= 3) 532 { 533 if (!ConvertValue(&(output->x), tokens[0])) 534 return false; 535 if (!ConvertValue(&(output->y), tokens[1])) 536 return false; 537 if (!ConvertValue(&(output->z), tokens[2])) 538 return false; 539 540 return true; 541 } 542 return false; 543 } 544 }; 545 546 // std::string to Vector4 547 template <> 548 struct ConverterSpecialized<std::string, orxonox::Vector4, _Explicit_> 549 { 550 enum { specialized = true }; 551 static bool convert(orxonox::Vector4* output, const std::string& input) 552 { 553 unsigned int opening_parenthesis, closing_parenthesis = input.find(')'); 554 if ((opening_parenthesis = input.find('(')) == std::string::npos) { opening_parenthesis = 0; } else { opening_parenthesis++; } 555 556 SubString tokens(input.substr(opening_parenthesis, closing_parenthesis - opening_parenthesis), ",", SubString::WhiteSpaces, false, '\\', true, '"', true, '\0', '\0', true, '\0'); 557 if (tokens.size() >= 4) 558 { 559 if (!ConvertValue(&(output->x), tokens[0])) 560 return false; 561 if (!ConvertValue(&(output->y), tokens[1])) 562 return false; 563 if (!ConvertValue(&(output->z), tokens[2])) 564 return false; 565 if (!ConvertValue(&(output->w), tokens[3])) 566 return false; 567 568 return true; 569 } 570 return false; 571 } 572 }; 573 574 // std::string to Quaternion 575 template <> 576 struct ConverterSpecialized<std::string, orxonox::Quaternion, _Explicit_> 577 { 578 enum { specialized = true }; 579 static bool convert(orxonox::Quaternion* output, const std::string& input) 580 { 581 unsigned int opening_parenthesis, closing_parenthesis = input.find(')'); 582 if ((opening_parenthesis = input.find('(')) == std::string::npos) { opening_parenthesis = 0; } else { opening_parenthesis++; } 583 584 SubString tokens(input.substr(opening_parenthesis, closing_parenthesis - opening_parenthesis), ",", SubString::WhiteSpaces, false, '\\', true, '"', true, '\0', '\0', true, '\0'); 585 if (tokens.size() >= 4) 586 { 587 if (!ConvertValue(&(output->w), tokens[0])) 588 return false; 589 if (!ConvertValue(&(output->x), tokens[1])) 590 return false; 591 if (!ConvertValue(&(output->y), tokens[2])) 592 return false; 593 if (!ConvertValue(&(output->z), tokens[3])) 594 return false; 595 596 return true; 597 } 598 return false; 599 } 600 }; 601 602 // std::string to ColourValue 603 template <> 604 struct ConverterSpecialized<std::string, orxonox::ColourValue, _Explicit_> 605 { 606 enum { specialized = true }; 607 static bool convert(orxonox::ColourValue* output, const std::string& input) 608 { 609 unsigned int opening_parenthesis, closing_parenthesis = input.find(')'); 610 if ((opening_parenthesis = input.find('(')) == std::string::npos) { opening_parenthesis = 0; } else { opening_parenthesis++; } 611 612 SubString tokens(input.substr(opening_parenthesis, closing_parenthesis - opening_parenthesis), ",", SubString::WhiteSpaces, false, '\\', true, '"', true, '\0', '\0', true, '\0'); 613 if (tokens.size() >= 4) 614 { 615 if (!ConvertValue(&(output->r), tokens[0])) 616 return false; 617 if (!ConvertValue(&(output->g), tokens[1])) 618 return false; 619 if (!ConvertValue(&(output->b), tokens[2])) 620 return false; 621 if (!ConvertValue(&(output->a), tokens[3])) 622 return false; 623 624 return true; 625 } 626 return false; 627 } 628 }; 629 630 #if ORXONOX_COMPILER == ORXONOX_COMPILER_MSVC 60 631 #pragma warning(pop) 61 632 #endif 633 62 634 #endif /* _Convert_H__ */ -
code/branches/network/src/util/ExprParser.cc
r1494 r1495 1 1 /* 2 2 * ORXONOX - the hottest 3D action shooter ever to exist 3 * > www.orxonox.net < * 3 * > www.orxonox.net < 4 * 4 5 * 5 6 * License notice: … … 30 31 @brief Declaration of FloatParser 31 32 */ 32 #include "ExprParser.h"#include <cmath>#include <cstring>// macros for easier if, else statements#define CASE_1(var) if (!strcmp(SWITCH,var))#define CASE(var) else if (!strcmp(SWITCH,var))#define CASE_ELSE else//! skip white spaces#define PARSE_BLANKS while (*reading_stream == ' ') ++reading_stream;ExprParser::ExprParser(const std::string& str){ this->failed_ = false; this->reading_stream = str.c_str(); if (str.size() == 0 || *reading_stream == '\0') { this->failed_ = true; this->result_ = 0.0; } else { this->result_ = parse_expr_8(); this->remains_ = reading_stream; }}//Private functions:/******************/double ExprParser::parse_argument(){ double value = parse_expr_8(); if (*reading_stream == ',') { ++reading_stream; return value; } else { this->failed_ = true; return 0; }}double ExprParser::parse_last_argument(){ double value = parse_expr_8(); if (*reading_stream == ')') { ++reading_stream; return value; } else { this->failed_ = true; return 0; }}double ExprParser::parse_expr_8(){ double value = parse_expr_7(); for(;;) { switch (op) { case oder: value = parse_expr_7() || value; break; default: return value; } };}double ExprParser::parse_expr_7(){ double value = parse_expr_6(); for(;;) { switch (op) { case und: value = value && parse_expr_6(); break; default: return value; } };}double ExprParser::parse_expr_6(){ double value = parse_expr_5(); for(;;) { switch (op) { case gleich: value = (value == parse_expr_5()); break; case ungleich: value = (value != parse_expr_5()); break; default: return value; } };}double ExprParser::parse_expr_5(){ double value = parse_expr_4(); for(;;) { switch (op) { case kleiner: value = (value < parse_expr_4()); break; case kleinergleich: value = (value <= parse_expr_4()); break; case groesser: value = (value > parse_expr_4()); break; case groessergleich: value = (value >= parse_expr_4()); break; default: return value; } };}double ExprParser::parse_expr_4(){ double value = parse_expr_3(); for(;;) { switch (op) { case b_plus: value += parse_expr_3(); break; case b_minus: value -= parse_expr_3(); break; default: return value; } };}double ExprParser::parse_expr_3(){ double value = parse_expr_2(); for(;;) { switch (op) { case mal: value *= parse_expr_2(); break; case durch: value /= parse_expr_2(); break; case modulo: { double temp = parse_expr_2(); value = value - floor(value/temp)*temp; break; } default: return value; } };}double ExprParser::parse_expr_2(){ double value = parse_expr_1(); while (*reading_stream != '\0') { op = parse_binary_operator(); switch (op) { case hoch: value = pow(value,parse_expr_1()); break; default: return value; } }; op = undef; return value;}double ExprParser::parse_expr_1(){ PARSE_BLANKS double value; unary_operator op = parse_unary_operator(); PARSE_BLANKS if (*reading_stream == '\0') { // end of string this->failed_ = true; return 0; } else if (*reading_stream > 47 && *reading_stream < 59 || *reading_stream == 46) { // number value = strtod(reading_stream, const_cast<char**>(&reading_stream)); } else if (*reading_stream > 64 && *reading_stream < 91 || *reading_stream > 96 && *reading_stream < 123 || *reading_stream == 46) { // variable or function char* word = new char[256]; parse_word(word); PARSE_BLANKS if (*reading_stream == '(') { ++reading_stream;#define SWITCH word CASE_1("sin") value = sin(parse_last_argument()); CASE("asin") value = asin(parse_last_argument()); CASE("sinh") value = sinh(parse_last_argument()); CASE("asinh") { value = parse_last_argument(); value = log(sqrt(pow(value, 2) + 1) + value); } CASE("cos") value = cos(parse_last_argument()); CASE("acos") value = acos(parse_last_argument()); CASE("cosh") value = cosh(parse_last_argument()); CASE("acosh") { value = parse_last_argument(); value = log(sqrt(pow(value, 2) - 1) + value); } CASE("tan") value = tan(parse_last_argument()); CASE("atan") value = atan(parse_last_argument()); CASE("atan2") value = atan2(parse_argument(),parse_last_argument()); CASE("tanh") value = tanh(parse_last_argument()); CASE("atanh") { value = parse_last_argument(); value = 0.5*log((value + 1)/(value - 1)); } CASE("int") value = floor(parse_last_argument()); CASE("floor") value = floor(parse_last_argument()); CASE("ceil") value = ceil(parse_last_argument()); CASE("abs") value = fabs(parse_last_argument()); CASE("exp") value = exp(parse_last_argument()); CASE("log") value = log10(parse_last_argument()); CASE("ln") value = log(parse_last_argument()); CASE("sign") { value = parse_last_argument(); value = (value>0 ? 1 : (value<0 ? -1 : 0)); } CASE("sqrt") value = sqrt(parse_last_argument()); CASE("degrees") value = parse_last_argument()*180/3.1415926535897932; CASE("radians") value = parse_last_argument()*3.1415926535897932/180; CASE("mod") { value = parse_argument(); double value2 = parse_last_argument(); value = value - floor(value/value2)*value2; } CASE("pow") value = pow(parse_argument(),parse_last_argument()); CASE("div") value = floor(parse_argument()/parse_last_argument()); CASE("max") value = std::max(parse_argument(),parse_last_argument()); CASE("min") value = std::min(parse_argument(),parse_last_argument()); CASE_ELSE { this->failed_ = true; delete[] word; return 0; } } else {#define SWITCH word CASE_1("pi") value = 3.1415926535897932; CASE("e") value = 2.7182818284590452; CASE_ELSE { this->failed_ = true; delete[] word; return 0; } } delete[] word; } else if (*reading_stream == 40) { // expresion in paranthesis ++reading_stream; value = parse_last_argument(); } else { this->failed_ = true; return 0; } PARSE_BLANKS switch (op) { case u_nicht: return !value; case u_plus: return value; case u_minus: return -value; default: { this->failed_ = true; return 0; } }}char* ExprParser::parse_word(char* str){ char* word = str; int counter = 0; while (*reading_stream > 47 && *reading_stream < 58 || *reading_stream > 64 && *reading_stream < 91 || *reading_stream > 96 && *reading_stream < 123 || *reading_stream == 46) { *word++ = *reading_stream++; counter++; if (counter > 255) { this->failed_ = true; return '\0'; } }; *word = '\0'; return str;}ExprParser::binary_operator ExprParser::parse_binary_operator(){ binary_operator op; switch (*reading_stream) { case '+': op = b_plus; break; case '-': op = b_minus; break; case '*': op = mal; break; case '/': op = durch; break; case '^': op = hoch; break; case '%': op = modulo; break; case '&': op = und; break; case '|': op = oder; break; case '=': op = gleich; break; case '!': op = b_nicht; break; case '<': op = kleiner; break; case '>': op = groesser; break; default: return undef; } if (*++reading_stream == '=') { if (op > 9) { ++reading_stream; return (binary_operator)(op + 3); } else { --reading_stream; return undef; } } else return op;}ExprParser::unary_operator ExprParser::parse_unary_operator(){ switch (*reading_stream) { case '!': ++reading_stream; return u_nicht; case '+': ++reading_stream; return u_plus; case '-': ++reading_stream; return u_minus; default : return u_plus; }} 33 34 #include "ExprParser.h" 35 #include <cmath> 36 #include <cstring> 37 38 // macros for easier if, else statements 39 #define CASE_1(var) if (!strcmp(SWITCH,var)) 40 #define CASE(var) else if (!strcmp(SWITCH,var)) 41 #define CASE_ELSE else 42 43 //! skip white spaces 44 #define PARSE_BLANKS while (*reading_stream == ' ') ++reading_stream; 45 46 ExprParser::ExprParser(const std::string& str) 47 { 48 this->failed_ = false; 49 this->reading_stream = str.c_str(); 50 if (str.size() == 0 || *reading_stream == '\0') 51 { 52 this->failed_ = true; 53 this->result_ = 0.0; 54 } 55 else 56 { 57 this->result_ = parse_expr_8(); 58 this->remains_ = reading_stream; 59 } 60 } 61 62 //Private functions: 63 /******************/ 64 double ExprParser::parse_argument() 65 { 66 double value = parse_expr_8(); 67 if (*reading_stream == ',') 68 { 69 ++reading_stream; 70 return value; 71 } 72 else 73 { 74 this->failed_ = true; 75 return 0; 76 } 77 } 78 79 double ExprParser::parse_last_argument() 80 { 81 double value = parse_expr_8(); 82 if (*reading_stream == ')') 83 { 84 ++reading_stream; 85 return value; 86 } 87 else 88 { 89 this->failed_ = true; 90 return 0; 91 } 92 } 93 94 double ExprParser::parse_expr_8() 95 { 96 double value = parse_expr_7(); 97 for(;;) 98 { 99 switch (op) 100 { 101 case oder: 102 value = parse_expr_7() || value; 103 break; 104 default: return value; 105 } 106 }; 107 } 108 109 110 double ExprParser::parse_expr_7() 111 { 112 double value = parse_expr_6(); 113 for(;;) 114 { 115 switch (op) 116 { 117 case und: 118 value = value && parse_expr_6(); 119 break; 120 default: return value; 121 } 122 }; 123 } 124 125 double ExprParser::parse_expr_6() 126 { 127 double value = parse_expr_5(); 128 for(;;) 129 { 130 switch (op) 131 { 132 case gleich: 133 value = (value == parse_expr_5()); 134 break; 135 case ungleich: 136 value = (value != parse_expr_5()); 137 break; 138 default: 139 return value; 140 } 141 }; 142 } 143 144 double ExprParser::parse_expr_5() 145 { 146 double value = parse_expr_4(); 147 for(;;) 148 { 149 switch (op) 150 { 151 case kleiner: 152 value = (value < parse_expr_4()); 153 break; 154 case kleinergleich: 155 value = (value <= parse_expr_4()); 156 break; 157 case groesser: 158 value = (value > parse_expr_4()); 159 break; 160 case groessergleich: 161 value = (value >= parse_expr_4()); 162 break; 163 default: 164 return value; 165 } 166 }; 167 } 168 169 double ExprParser::parse_expr_4() 170 { 171 double value = parse_expr_3(); 172 for(;;) 173 { 174 switch (op) 175 { 176 case b_plus: 177 value += parse_expr_3(); 178 break; 179 case b_minus: 180 value -= parse_expr_3(); 181 break; 182 default: 183 return value; 184 } 185 }; 186 } 187 188 double ExprParser::parse_expr_3() 189 { 190 double value = parse_expr_2(); 191 for(;;) 192 { 193 switch (op) 194 { 195 case mal: 196 value *= parse_expr_2(); 197 break; 198 case durch: 199 value /= parse_expr_2(); 200 break; 201 case modulo: 202 { 203 double temp = parse_expr_2(); 204 value = value - floor(value/temp)*temp; 205 break; 206 } 207 default: 208 return value; 209 } 210 }; 211 } 212 213 double ExprParser::parse_expr_2() 214 { 215 double value = parse_expr_1(); 216 while (*reading_stream != '\0') 217 { 218 op = parse_binary_operator(); 219 switch (op) 220 { 221 case hoch: 222 value = pow(value,parse_expr_1()); 223 break; 224 default: 225 return value; 226 } 227 }; 228 op = undef; 229 return value; 230 } 231 232 double ExprParser::parse_expr_1() 233 { 234 PARSE_BLANKS 235 double value; 236 237 unary_operator op = parse_unary_operator(); 238 PARSE_BLANKS 239 240 if (*reading_stream == '\0') 241 { 242 // end of string 243 this->failed_ = true; 244 return 0; 245 } 246 else if (*reading_stream > 47 && *reading_stream < 59 || *reading_stream == 46) 247 { // number 248 value = strtod(reading_stream, const_cast<char**>(&reading_stream)); 249 } 250 else if (*reading_stream > 64 && *reading_stream < 91 || *reading_stream > 96 && *reading_stream < 123 || *reading_stream == 46) 251 { // variable or function 252 char* word = new char[256]; 253 parse_word(word); 254 PARSE_BLANKS 255 if (*reading_stream == '(') 256 { 257 ++reading_stream; 258 #define SWITCH word 259 CASE_1("sin") 260 value = sin(parse_last_argument()); 261 CASE("asin") 262 value = asin(parse_last_argument()); 263 CASE("sinh") 264 value = sinh(parse_last_argument()); 265 CASE("asinh") 266 { 267 value = parse_last_argument(); 268 value = log(sqrt(pow(value, 2) + 1) + value); 269 } 270 CASE("cos") 271 value = cos(parse_last_argument()); 272 CASE("acos") 273 value = acos(parse_last_argument()); 274 CASE("cosh") 275 value = cosh(parse_last_argument()); 276 CASE("acosh") 277 { 278 value = parse_last_argument(); 279 value = log(sqrt(pow(value, 2) - 1) + value); 280 } 281 CASE("tan") 282 value = tan(parse_last_argument()); 283 CASE("atan") 284 value = atan(parse_last_argument()); 285 CASE("atan2") 286 value = atan2(parse_argument(),parse_last_argument()); 287 CASE("tanh") 288 value = tanh(parse_last_argument()); 289 CASE("atanh") 290 { 291 value = parse_last_argument(); 292 value = 0.5*log((value + 1)/(value - 1)); 293 } 294 CASE("int") 295 value = floor(parse_last_argument()); 296 CASE("floor") 297 value = floor(parse_last_argument()); 298 CASE("ceil") 299 value = ceil(parse_last_argument()); 300 CASE("abs") 301 value = fabs(parse_last_argument()); 302 CASE("exp") 303 value = exp(parse_last_argument()); 304 CASE("log") 305 value = log10(parse_last_argument()); 306 CASE("ln") 307 value = log(parse_last_argument()); 308 CASE("sign") 309 { 310 value = parse_last_argument(); 311 value = (value>0 ? 1 : (value<0 ? -1 : 0)); 312 } 313 CASE("sqrt") 314 value = sqrt(parse_last_argument()); 315 CASE("degrees") 316 value = parse_last_argument()*180/3.1415926535897932; 317 CASE("radians") 318 value = parse_last_argument()*3.1415926535897932/180; 319 CASE("mod") 320 { 321 value = parse_argument(); 322 double value2 = parse_last_argument(); 323 value = value - floor(value/value2)*value2; 324 } 325 CASE("pow") 326 value = pow(parse_argument(),parse_last_argument()); 327 CASE("div") 328 value = floor(parse_argument()/parse_last_argument()); 329 CASE("max") 330 value = std::max(parse_argument(),parse_last_argument()); 331 CASE("min") 332 value = std::min(parse_argument(),parse_last_argument()); 333 CASE_ELSE 334 { 335 this->failed_ = true; 336 delete[] word; 337 return 0; 338 } 339 } 340 else 341 { 342 #define SWITCH word 343 CASE_1("pi") 344 value = 3.1415926535897932; 345 CASE("e") 346 value = 2.7182818284590452; 347 CASE_ELSE 348 { 349 this->failed_ = true; 350 delete[] word; 351 return 0; 352 } 353 } 354 delete[] word; 355 } 356 else if (*reading_stream == 40) 357 { // expresion in paranthesis 358 ++reading_stream; 359 value = parse_last_argument(); 360 } 361 else 362 { 363 this->failed_ = true; 364 return 0; 365 } 366 367 PARSE_BLANKS 368 switch (op) 369 { 370 case u_nicht: return !value; 371 case u_plus: return value; 372 case u_minus: return -value; 373 default: 374 { 375 this->failed_ = true; 376 return 0; 377 } 378 } 379 } 380 381 char* ExprParser::parse_word(char* str) 382 { 383 char* word = str; 384 int counter = 0; 385 while (*reading_stream > 47 && *reading_stream < 58 || *reading_stream > 64 && *reading_stream < 91 || *reading_stream > 96 && *reading_stream < 123 || *reading_stream == 46) 386 { 387 *word++ = *reading_stream++; 388 counter++; 389 if (counter > 255) 390 { 391 this->failed_ = true; 392 return '\0'; 393 } 394 }; 395 *word = '\0'; 396 return str; 397 } 398 399 ExprParser::binary_operator ExprParser::parse_binary_operator() 400 { 401 binary_operator op; 402 switch (*reading_stream) 403 { 404 case '+': op = b_plus; break; 405 case '-': op = b_minus; break; 406 case '*': op = mal; break; 407 case '/': op = durch; break; 408 case '^': op = hoch; break; 409 case '%': op = modulo; break; 410 case '&': op = und; break; 411 case '|': op = oder; break; 412 case '=': op = gleich; break; 413 case '!': op = b_nicht; break; 414 case '<': op = kleiner; break; 415 case '>': op = groesser; break; 416 default: return undef; 417 } 418 if (*++reading_stream == '=') 419 { 420 if (op > 9) 421 { 422 ++reading_stream; 423 return (binary_operator)(op + 3); 424 } 425 else 426 { 427 --reading_stream; 428 return undef; 429 } 430 } 431 else 432 return op; 433 } 434 435 ExprParser::unary_operator ExprParser::parse_unary_operator() 436 { 437 switch (*reading_stream) 438 { 439 case '!': 440 ++reading_stream; 441 return u_nicht; 442 case '+': 443 ++reading_stream; 444 return u_plus; 445 case '-': 446 ++reading_stream; 447 return u_minus; 448 default : 449 return u_plus; 450 } 451 } -
code/branches/network/src/util/ExprParser.h
r1494 r1495 1 1 /* 2 2 * ORXONOX - the hottest 3D action shooter ever to exist 3 * > www.orxonox.net < * 3 * > www.orxonox.net < 4 * 4 5 * 5 6 * License notice: … … 30 31 @brief Declaration of FloatParser 31 32 */ 32 #ifndef _FloatParser_H__#define _FloatParser_H__#include "UtilPrereqs.h"#include <string>class _UtilExport ExprParser{public: enum binary_operator { b_plus, b_minus, mal, durch, modulo, hoch, undef, oder, und, gleich, b_nicht, kleiner, groesser, ungleich, kleinergleich, groessergleich }; enum unary_operator { u_plus, u_minus, u_nicht }; ExprParser(const std::string& str); std::string& getRemains() { return this->remains_; } double getResult() { return this->result_; } bool getSuccess() { return !this->failed_; }private: double parse_expr_1(); double parse_expr_2(); double parse_expr_3(); double parse_expr_4(); double parse_expr_5(); double parse_expr_6(); double parse_expr_7(); double parse_expr_8(); char* parse_word(char* str); binary_operator parse_binary_operator(); unary_operator parse_unary_operator(); double parse_argument(); double parse_last_argument(); binary_operator op; const char* reading_stream; bool failed_; double result_; std::string remains_;};//Endzeichen für float expression: ')', '}', ']', ',', ';'_UtilExport bool parse_float(char* const, char**, double*);//Endzeichen angegeben_UtilExport bool parse_float(char* const, char**, char, double*);//Letzter Teil-float eines Vektors parsen (keine Vergleichs- und Logikoperationen)_UtilExport bool parse_vector_float(char* const, char**, bool, double*);#endif /* _FloatParser_H__ */ 33 34 #ifndef _FloatParser_H__ 35 #define _FloatParser_H__ 36 37 #include "UtilPrereqs.h" 38 #include <string> 39 40 class _UtilExport ExprParser 41 { 42 public: 43 enum binary_operator 44 { 45 b_plus, 46 b_minus, 47 mal, 48 durch, 49 modulo, 50 hoch, 51 undef, 52 oder, 53 und, 54 gleich, 55 b_nicht, 56 kleiner, 57 groesser, 58 ungleich, 59 kleinergleich, 60 groessergleich 61 }; 62 63 enum unary_operator 64 { 65 u_plus, 66 u_minus, 67 u_nicht 68 }; 69 70 71 ExprParser(const std::string& str); 72 std::string& getRemains() { return this->remains_; } 73 double getResult() { return this->result_; } 74 bool getSuccess() { return !this->failed_; } 75 76 private: 77 double parse_expr_1(); 78 double parse_expr_2(); 79 double parse_expr_3(); 80 double parse_expr_4(); 81 double parse_expr_5(); 82 double parse_expr_6(); 83 double parse_expr_7(); 84 double parse_expr_8(); 85 char* parse_word(char* str); 86 binary_operator parse_binary_operator(); 87 unary_operator parse_unary_operator(); 88 89 double parse_argument(); 90 double parse_last_argument(); 91 92 binary_operator op; 93 const char* reading_stream; 94 bool failed_; 95 double result_; 96 std::string remains_; 97 98 }; 99 100 //Endzeichen für float expression: ')', '}', ']', ',', ';' 101 _UtilExport bool parse_float(char* const, char**, double*); 102 //Endzeichen angegeben 103 _UtilExport bool parse_float(char* const, char**, char, double*); 104 //Letzter Teil-float eines Vektors parsen (keine Vergleichs- und Logikoperationen) 105 _UtilExport bool parse_vector_float(char* const, char**, bool, double*); 106 107 #endif /* _FloatParser_H__ */ -
code/branches/network/src/util/MultiTypeMath.h
r1494 r1495 1 /* * ORXONOX - the hottest 3D action shooter ever to exist * > www.orxonox.net < * * * License notice: * * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * * Author: * Fabian 'x3n' Landau * Co-authors: * ... * * Inspiration: MultiType by Benjamin Grauer */#ifndef _MultiTypeMath_H__#define _MultiTypeMath_H__#include "UtilPrereqs.h"#include "MultiTypeString.h"#include "Math.h"// disable annoying warning about multiple assignment operators 1 /* 2 * ORXONOX - the hottest 3D action shooter ever to exist 3 * > www.orxonox.net < 4 * 5 * 6 * License notice: 7 * 8 * This program is free software; you can redistribute it and/or 9 * modify it under the terms of the GNU General Public License 10 * as published by the Free Software Foundation; either version 2 11 * of the License, or (at your option) any later version. 12 * 13 * This program is distributed in the hope that it will be useful, 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 * GNU General Public License for more details. 17 * 18 * You should have received a copy of the GNU General Public License 19 * along with this program; if not, write to the Free Software 20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 21 * 22 * Author: 23 * Fabian 'x3n' Landau 24 * Co-authors: 25 * ... 26 * 27 * Inspiration: MultiType by Benjamin Grauer 28 */ 29 30 #ifndef _MultiTypeMath_H__ 31 #define _MultiTypeMath_H__ 32 33 #include "UtilPrereqs.h" 34 35 #include "MultiTypeString.h" 36 #include "Math.h" 37 38 // disable annoying warning about multiple assignment operators 2 39 #if ORXONOX_COMPILER == ORXONOX_COMPILER_MSVC 3 40 #pragma warning(push) 4 41 #pragma warning(disable:4522) 5 42 #endif 6 class _UtilExport MultiTypeMath : public MultiTypeString{ public: MultiTypeMath(MultiType type = MT_null); inline MultiTypeMath(void* value) : MultiTypeString(value) {} inline MultiTypeMath(int value) : MultiTypeString(value) {} inline MultiTypeMath(unsigned int value) : MultiTypeString(value) {} inline MultiTypeMath(char value) : MultiTypeString(value) {} inline MultiTypeMath(unsigned char value) : MultiTypeString(value) {} inline MultiTypeMath(short value) : MultiTypeString(value) {} inline MultiTypeMath(unsigned short value) : MultiTypeString(value) {} inline MultiTypeMath(long value) : MultiTypeString(value) {} inline MultiTypeMath(unsigned long value) : MultiTypeString(value) {} inline MultiTypeMath(float value) : MultiTypeString(value) {} inline MultiTypeMath(double value) : MultiTypeString(value) {} inline MultiTypeMath(long double value) : MultiTypeString(value) {} inline MultiTypeMath(bool value) : MultiTypeString(value) {} inline MultiTypeMath(const char* value) : MultiTypeString(value) {} inline MultiTypeMath(const std::string& value) : MultiTypeString(value) {} inline MultiTypeMath(const orxonox::Vector2& value) { this->setValue(value); } inline MultiTypeMath(const orxonox::Vector3& value) { this->setValue(value); } inline MultiTypeMath(const orxonox::Vector4& value) { this->setValue(value); } inline MultiTypeMath(const orxonox::ColourValue& value) { this->setValue(value); } inline MultiTypeMath(const orxonox::Quaternion& value) { this->setValue(value); } inline MultiTypeMath(const orxonox::Radian& value) { this->setValue(value); } inline MultiTypeMath(const orxonox::Degree& value) { this->setValue(value); } inline MultiTypeMath(const MultiTypeMath& mtm) { this->setValue(mtm); } inline MultiTypeMath(const MultiTypeString& mts) { this->setValue(mts); } inline MultiTypeMath(const MultiTypePrimitive& mtp) { this->setValue(mtp); } virtual inline ~MultiTypeMath() {} using MultiTypeString::operator=; inline MultiTypeMath& operator=(const orxonox::Vector2& value) { this->setValue(value); return *this; } inline MultiTypeMath& operator=(const orxonox::Vector3& value) { this->setValue(value); return *this; } inline MultiTypeMath& operator=(const orxonox::Vector4& value) { this->setValue(value); return *this; } inline MultiTypeMath& operator=(const orxonox::ColourValue& value) { this->setValue(value); return *this; } inline MultiTypeMath& operator=(const orxonox::Quaternion& value) { this->setValue(value); return *this; } inline MultiTypeMath& operator=(const orxonox::Radian& value) { this->setValue(value); return *this; } inline MultiTypeMath& operator=(const orxonox::Degree& value) { this->setValue(value); return *this; } inline MultiTypeMath& operator=(const MultiTypeMath& mtm) { this->setValue(mtm); return *this; } inline MultiTypeMath& operator=(const MultiTypeString& mts) { this->setValue(mts); return *this; } inline MultiTypeMath& operator=(const MultiTypePrimitive mtp) { this->setValue(mtp); return *this; } using MultiTypeString::operator==; inline bool operator==(const orxonox::Vector2& value) const { return (this->vector2_ == value); } inline bool operator==(const orxonox::Vector3& value) const { return (this->vector3_ == value); } inline bool operator==(const orxonox::Vector4& value) const { return (this->vector4_ == value); } inline bool operator==(const orxonox::ColourValue& value) const { return (this->colourvalue_ == value); } inline bool operator==(const orxonox::Quaternion& value) const { return (this->quaternion_ == value); } inline bool operator==(const orxonox::Radian& value) const { return (this->radian_ == value); } inline bool operator==(const orxonox::Degree& value) const { return (this->degree_ == value); } bool operator==(const MultiTypeMath& mtm) const; bool operator==(const MultiTypeString& mts) const; bool operator==(const MultiTypePrimitive& mtp) const; using MultiTypeString::operator!=; inline bool operator!=(const orxonox::Vector2& value) const { return (this->vector2_ != value); } inline bool operator!=(const orxonox::Vector3& value) const { return (this->vector3_ != value); } inline bool operator!=(const orxonox::Vector4& value) const { return (this->vector4_ != value); } inline bool operator!=(const orxonox::ColourValue& value) const { return (this->colourvalue_ != value); } inline bool operator!=(const orxonox::Quaternion& value) const { return (this->quaternion_ != value); } inline bool operator!=(const orxonox::Radian& value) const { return (this->radian_ != value); } inline bool operator!=(const orxonox::Degree& value) const { return (this->degree_ != value); } bool operator!=(const MultiTypeMath& mtm) const; bool operator!=(const MultiTypeString& mts) const; bool operator!=(const MultiTypePrimitive& mtp) const; virtual operator void*() const; virtual operator int() const; virtual operator unsigned int() const; virtual operator char() const; virtual operator unsigned char() const; virtual operator short() const; virtual operator unsigned short() const; virtual operator long() const; virtual operator unsigned long() const; virtual operator float () const; virtual operator double () const; virtual operator long double() const; virtual operator bool() const; virtual operator std::string() const; virtual operator const char*() const; virtual operator orxonox::Vector2() const; virtual operator orxonox::Vector3() const; virtual operator orxonox::Vector4() const; virtual operator orxonox::ColourValue() const; virtual operator orxonox::Quaternion() const; virtual operator orxonox::Radian() const; virtual operator orxonox::Degree() const; using MultiTypeString::setValue; inline void setValue(const orxonox::Vector2& value) { this->type_ = MT_vector2; this->vector2_ = value; } inline void setValue(const orxonox::Vector3& value) { this->type_ = MT_vector3; this->vector3_ = value; } inline void setValue(const orxonox::Vector4& value) { this->type_ = MT_vector4; this->vector4_ = value; } inline void setValue(const orxonox::ColourValue& value) { this->type_ = MT_colourvalue; this->colourvalue_ = value; } inline void setValue(const orxonox::Quaternion& value) { this->type_ = MT_quaternion; this->quaternion_ = value; } inline void setValue(const orxonox::Radian& value) { this->type_ = MT_radian; this->radian_ = value; } inline void setValue(const orxonox::Degree& value) { this->type_ = MT_degree; this->degree_ = value; } void setValue(const MultiTypeMath& mtm); void setValue(const MultiTypeString& mts); void setValue(const MultiTypePrimitive& mtp); inline orxonox::Vector2 getVector2() const { return this->vector2_; } inline orxonox::Vector3 getVector3() const { return this->vector3_; } inline orxonox::Vector4 getVector4() const { return this->vector4_; } inline orxonox::ColourValue getColourValue() const { return this->colourvalue_; } inline orxonox::Quaternion getQuaternion() const { return this->quaternion_; } inline orxonox::Radian getRadian() const { return this->radian_; } inline orxonox::Degree getDegree() const { return this->degree_; } inline orxonox::Vector2& getVector2() { return this->vector2_; } inline orxonox::Vector3& getVector3() { return this->vector3_; } inline orxonox::Vector4& getVector4() { return this->vector4_; } inline orxonox::ColourValue& getColourValue() { return this->colourvalue_; } inline orxonox::Quaternion& getQuaternion() { return this->quaternion_; } inline orxonox::Radian& getRadian() { return this->radian_; } inline orxonox::Degree& getDegree() { return this->degree_; } using MultiTypeString::getValue; inline void getValue(orxonox::Vector2* variable) const { (*variable) = orxonox::Vector2 (this->vector2_); } inline void getValue(orxonox::Vector3* variable) const { (*variable) = orxonox::Vector3 (this->vector3_); } inline void getValue(orxonox::Vector4* variable) const { (*variable) = orxonox::Vector4 (this->vector4_); } inline void getValue(orxonox::ColourValue* variable) const { (*variable) = orxonox::ColourValue (this->colourvalue_); } inline void getValue(orxonox::Quaternion* variable) const { (*variable) = orxonox::Quaternion (this->quaternion_); } inline void getValue(orxonox::Radian* variable) const { (*variable) = orxonox::Radian (this->radian_); } inline void getValue(orxonox::Degree* variable) const { (*variable) = orxonox::Degree (this->degree_); } virtual std::string getTypename() const; virtual std::string toString() const; virtual bool fromString(const std::string value); virtual bool assimilate(const MultiTypeMath& mtm, const MultiTypeMath& defvalue = MultiTypeMath()); protected: orxonox::Vector2 vector2_; orxonox::Vector3 vector3_; orxonox::Vector4 vector4_; orxonox::ColourValue colourvalue_; orxonox::Quaternion quaternion_; orxonox::Radian radian_; orxonox::Degree degree_;};_UtilExport std::ostream& operator<<(std::ostream& out, MultiTypeMath& mtm);#if ORXONOX_COMPILER == ORXONOX_COMPILER_MSVC 43 44 class _UtilExport MultiTypeMath : public MultiTypeString 45 { 46 public: 47 MultiTypeMath(MultiType type = MT_null); 48 inline MultiTypeMath(void* value) : MultiTypeString(value) {} 49 inline MultiTypeMath(int value) : MultiTypeString(value) {} 50 inline MultiTypeMath(unsigned int value) : MultiTypeString(value) {} 51 inline MultiTypeMath(char value) : MultiTypeString(value) {} 52 inline MultiTypeMath(unsigned char value) : MultiTypeString(value) {} 53 inline MultiTypeMath(short value) : MultiTypeString(value) {} 54 inline MultiTypeMath(unsigned short value) : MultiTypeString(value) {} 55 inline MultiTypeMath(long value) : MultiTypeString(value) {} 56 inline MultiTypeMath(unsigned long value) : MultiTypeString(value) {} 57 inline MultiTypeMath(float value) : MultiTypeString(value) {} 58 inline MultiTypeMath(double value) : MultiTypeString(value) {} 59 inline MultiTypeMath(long double value) : MultiTypeString(value) {} 60 inline MultiTypeMath(bool value) : MultiTypeString(value) {} 61 inline MultiTypeMath(const char* value) : MultiTypeString(value) {} 62 inline MultiTypeMath(const std::string& value) : MultiTypeString(value) {} 63 inline MultiTypeMath(const orxonox::Vector2& value) { this->setValue(value); } 64 inline MultiTypeMath(const orxonox::Vector3& value) { this->setValue(value); } 65 inline MultiTypeMath(const orxonox::Vector4& value) { this->setValue(value); } 66 inline MultiTypeMath(const orxonox::ColourValue& value) { this->setValue(value); } 67 inline MultiTypeMath(const orxonox::Quaternion& value) { this->setValue(value); } 68 inline MultiTypeMath(const orxonox::Radian& value) { this->setValue(value); } 69 inline MultiTypeMath(const orxonox::Degree& value) { this->setValue(value); } 70 inline MultiTypeMath(const MultiTypeMath& mtm) { this->setValue(mtm); } 71 inline MultiTypeMath(const MultiTypeString& mts) { this->setValue(mts); } 72 inline MultiTypeMath(const MultiTypePrimitive& mtp) { this->setValue(mtp); } 73 virtual inline ~MultiTypeMath() {} 74 75 using MultiTypeString::operator=; 76 inline MultiTypeMath& operator=(const orxonox::Vector2& value) { this->setValue(value); return *this; } 77 inline MultiTypeMath& operator=(const orxonox::Vector3& value) { this->setValue(value); return *this; } 78 inline MultiTypeMath& operator=(const orxonox::Vector4& value) { this->setValue(value); return *this; } 79 inline MultiTypeMath& operator=(const orxonox::ColourValue& value) { this->setValue(value); return *this; } 80 inline MultiTypeMath& operator=(const orxonox::Quaternion& value) { this->setValue(value); return *this; } 81 inline MultiTypeMath& operator=(const orxonox::Radian& value) { this->setValue(value); return *this; } 82 inline MultiTypeMath& operator=(const orxonox::Degree& value) { this->setValue(value); return *this; } 83 inline MultiTypeMath& operator=(const MultiTypeMath& mtm) { this->setValue(mtm); return *this; } 84 inline MultiTypeMath& operator=(const MultiTypeString& mts) { this->setValue(mts); return *this; } 85 inline MultiTypeMath& operator=(const MultiTypePrimitive mtp) { this->setValue(mtp); return *this; } 86 87 using MultiTypeString::operator==; 88 inline bool operator==(const orxonox::Vector2& value) const { return (this->vector2_ == value); } 89 inline bool operator==(const orxonox::Vector3& value) const { return (this->vector3_ == value); } 90 inline bool operator==(const orxonox::Vector4& value) const { return (this->vector4_ == value); } 91 inline bool operator==(const orxonox::ColourValue& value) const { return (this->colourvalue_ == value); } 92 inline bool operator==(const orxonox::Quaternion& value) const { return (this->quaternion_ == value); } 93 inline bool operator==(const orxonox::Radian& value) const { return (this->radian_ == value); } 94 inline bool operator==(const orxonox::Degree& value) const { return (this->degree_ == value); } 95 bool operator==(const MultiTypeMath& mtm) const; 96 bool operator==(const MultiTypeString& mts) const; 97 bool operator==(const MultiTypePrimitive& mtp) const; 98 99 using MultiTypeString::operator!=; 100 inline bool operator!=(const orxonox::Vector2& value) const { return (this->vector2_ != value); } 101 inline bool operator!=(const orxonox::Vector3& value) const { return (this->vector3_ != value); } 102 inline bool operator!=(const orxonox::Vector4& value) const { return (this->vector4_ != value); } 103 inline bool operator!=(const orxonox::ColourValue& value) const { return (this->colourvalue_ != value); } 104 inline bool operator!=(const orxonox::Quaternion& value) const { return (this->quaternion_ != value); } 105 inline bool operator!=(const orxonox::Radian& value) const { return (this->radian_ != value); } 106 inline bool operator!=(const orxonox::Degree& value) const { return (this->degree_ != value); } 107 bool operator!=(const MultiTypeMath& mtm) const; 108 bool operator!=(const MultiTypeString& mts) const; 109 bool operator!=(const MultiTypePrimitive& mtp) const; 110 111 virtual operator void*() const; 112 virtual operator int() const; 113 virtual operator unsigned int() const; 114 virtual operator char() const; 115 virtual operator unsigned char() const; 116 virtual operator short() const; 117 virtual operator unsigned short() const; 118 virtual operator long() const; 119 virtual operator unsigned long() const; 120 virtual operator float () const; 121 virtual operator double () const; 122 virtual operator long double() const; 123 virtual operator bool() const; 124 virtual operator std::string() const; 125 virtual operator const char*() const; 126 virtual operator orxonox::Vector2() const; 127 virtual operator orxonox::Vector3() const; 128 virtual operator orxonox::Vector4() const; 129 virtual operator orxonox::ColourValue() const; 130 virtual operator orxonox::Quaternion() const; 131 virtual operator orxonox::Radian() const; 132 virtual operator orxonox::Degree() const; 133 134 using MultiTypeString::setValue; 135 inline void setValue(const orxonox::Vector2& value) { this->type_ = MT_vector2; this->vector2_ = value; } 136 inline void setValue(const orxonox::Vector3& value) { this->type_ = MT_vector3; this->vector3_ = value; } 137 inline void setValue(const orxonox::Vector4& value) { this->type_ = MT_vector4; this->vector4_ = value; } 138 inline void setValue(const orxonox::ColourValue& value) { this->type_ = MT_colourvalue; this->colourvalue_ = value; } 139 inline void setValue(const orxonox::Quaternion& value) { this->type_ = MT_quaternion; this->quaternion_ = value; } 140 inline void setValue(const orxonox::Radian& value) { this->type_ = MT_radian; this->radian_ = value; } 141 inline void setValue(const orxonox::Degree& value) { this->type_ = MT_degree; this->degree_ = value; } 142 void setValue(const MultiTypeMath& mtm); 143 void setValue(const MultiTypeString& mts); 144 void setValue(const MultiTypePrimitive& mtp); 145 146 inline orxonox::Vector2 getVector2() const { return this->vector2_; } 147 inline orxonox::Vector3 getVector3() const { return this->vector3_; } 148 inline orxonox::Vector4 getVector4() const { return this->vector4_; } 149 inline orxonox::ColourValue getColourValue() const { return this->colourvalue_; } 150 inline orxonox::Quaternion getQuaternion() const { return this->quaternion_; } 151 inline orxonox::Radian getRadian() const { return this->radian_; } 152 inline orxonox::Degree getDegree() const { return this->degree_; } 153 154 inline orxonox::Vector2& getVector2() { return this->vector2_; } 155 inline orxonox::Vector3& getVector3() { return this->vector3_; } 156 inline orxonox::Vector4& getVector4() { return this->vector4_; } 157 inline orxonox::ColourValue& getColourValue() { return this->colourvalue_; } 158 inline orxonox::Quaternion& getQuaternion() { return this->quaternion_; } 159 inline orxonox::Radian& getRadian() { return this->radian_; } 160 inline orxonox::Degree& getDegree() { return this->degree_; } 161 162 using MultiTypeString::getValue; 163 inline void getValue(orxonox::Vector2* variable) const { (*variable) = orxonox::Vector2 (this->vector2_); } 164 inline void getValue(orxonox::Vector3* variable) const { (*variable) = orxonox::Vector3 (this->vector3_); } 165 inline void getValue(orxonox::Vector4* variable) const { (*variable) = orxonox::Vector4 (this->vector4_); } 166 inline void getValue(orxonox::ColourValue* variable) const { (*variable) = orxonox::ColourValue (this->colourvalue_); } 167 inline void getValue(orxonox::Quaternion* variable) const { (*variable) = orxonox::Quaternion (this->quaternion_); } 168 inline void getValue(orxonox::Radian* variable) const { (*variable) = orxonox::Radian (this->radian_); } 169 inline void getValue(orxonox::Degree* variable) const { (*variable) = orxonox::Degree (this->degree_); } 170 171 virtual std::string getTypename() const; 172 173 virtual std::string toString() const; 174 virtual bool fromString(const std::string value); 175 176 virtual bool assimilate(const MultiTypeMath& mtm, const MultiTypeMath& defvalue = MultiTypeMath()); 177 178 protected: 179 orxonox::Vector2 vector2_; 180 orxonox::Vector3 vector3_; 181 orxonox::Vector4 vector4_; 182 orxonox::ColourValue colourvalue_; 183 orxonox::Quaternion quaternion_; 184 orxonox::Radian radian_; 185 orxonox::Degree degree_; 186 }; 187 188 _UtilExport std::ostream& operator<<(std::ostream& out, MultiTypeMath& mtm); 189 190 #if ORXONOX_COMPILER == ORXONOX_COMPILER_MSVC 7 191 #pragma warning(pop) 8 #endif#endif /* _MultiTypeMath_H__ */ 192 #endif 193 194 #endif /* _MultiTypeMath_H__ */ -
code/branches/network/src/util/MultiTypeString.h
r1494 r1495 1 /* * ORXONOX - the hottest 3D action shooter ever to exist * > www.orxonox.net < * * * License notice: * * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * * Author: * Fabian 'x3n' Landau * Co-authors: * ... * * Inspiration: MultiType by Benjamin Grauer */#ifndef _MultiTypeString_H__#define _MultiTypeString_H__#include "UtilPrereqs.h"#include <string>#include <iostream>#include "MultiTypePrimitive.h"// disable annoying warning about multiple assignment operators 1 /* 2 * ORXONOX - the hottest 3D action shooter ever to exist 3 * > www.orxonox.net < 4 * 5 * 6 * License notice: 7 * 8 * This program is free software; you can redistribute it and/or 9 * modify it under the terms of the GNU General Public License 10 * as published by the Free Software Foundation; either version 2 11 * of the License, or (at your option) any later version. 12 * 13 * This program is distributed in the hope that it will be useful, 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 * GNU General Public License for more details. 17 * 18 * You should have received a copy of the GNU General Public License 19 * along with this program; if not, write to the Free Software 20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 21 * 22 * Author: 23 * Fabian 'x3n' Landau 24 * Co-authors: 25 * ... 26 * 27 * Inspiration: MultiType by Benjamin Grauer 28 */ 29 30 #ifndef _MultiTypeString_H__ 31 #define _MultiTypeString_H__ 32 33 #include "UtilPrereqs.h" 34 35 #include <string> 36 #include <iostream> 37 38 #include "MultiTypePrimitive.h" 39 40 // disable annoying warning about multiple assignment operators 2 41 #if ORXONOX_COMPILER == ORXONOX_COMPILER_MSVC 3 42 #pragma warning(push) 4 43 #pragma warning(disable:4522) 5 44 #endif 6 class _UtilExport MultiTypeString : public MultiTypePrimitive{ public: MultiTypeString(MultiType type = MT_null); inline MultiTypeString(void* value) : MultiTypePrimitive(value) {} inline MultiTypeString(int value) : MultiTypePrimitive(value) {} inline MultiTypeString(unsigned int value) : MultiTypePrimitive(value) {} inline MultiTypeString(char value) : MultiTypePrimitive(value) {} inline MultiTypeString(unsigned char value) : MultiTypePrimitive(value) {} inline MultiTypeString(short value) : MultiTypePrimitive(value) {} inline MultiTypeString(unsigned short value) : MultiTypePrimitive(value) {} inline MultiTypeString(long value) : MultiTypePrimitive(value) {} inline MultiTypeString(unsigned long value) : MultiTypePrimitive(value) {} inline MultiTypeString(float value) : MultiTypePrimitive(value) {} inline MultiTypeString(double value) : MultiTypePrimitive(value) {} inline MultiTypeString(long double value) : MultiTypePrimitive(value) {} inline MultiTypeString(bool value) : MultiTypePrimitive(value) {} inline MultiTypeString(const char* value) { this->setValue(value); } inline MultiTypeString(const std::string& value) { this->setValue(value); } inline MultiTypeString(const MultiTypeString& mts) { this->setValue(mts); } inline MultiTypeString(const MultiTypePrimitive& mtp) { this->setValue(mtp); } virtual inline ~MultiTypeString() {} using MultiTypePrimitive::operator=; inline MultiTypeString& operator=(const char* value) { this->setValue(value); return *this; } inline MultiTypeString& operator=(const std::string& value) { this->setValue(value); return *this; } inline MultiTypeString& operator=(const MultiTypeString& mts) { this->setValue(mts); return *this; } inline MultiTypeString& operator=(const MultiTypePrimitive& mtp) { this->setValue(mtp); return *this; } using MultiTypePrimitive::operator==; inline bool operator==(const char* value) const { return (this->string_ == std::string(value)); } inline bool operator==(const std::string& value) const { return (this->string_ == value); } bool operator==(const MultiTypeString& mts) const; bool operator==(const MultiTypePrimitive& mtp) const; using MultiTypePrimitive::operator!=; inline bool operator!=(const char* value) const { return (this->string_ != std::string(value)); } inline bool operator!=(const std::string& value) const { return (this->string_ != value); } bool operator!=(const MultiTypeString& mts) const; bool operator!=(const MultiTypePrimitive& mtp) const; virtual operator void*() const; virtual operator int() const; virtual operator unsigned int() const; virtual operator char() const; virtual operator unsigned char() const; virtual operator short() const; virtual operator unsigned short() const; virtual operator long() const; virtual operator unsigned long() const; virtual operator float () const; virtual operator double () const; virtual operator long double() const; virtual operator bool() const; virtual operator std::string() const; virtual operator const char*() const; using MultiTypePrimitive::setValue; inline void setValue(const char* value) { this->type_ = MT_string; this->string_ = std::string(value); } inline void setValue(const std::string& value) { this->type_ = MT_string; this->string_ = value; } void setValue(const MultiTypeString& mts); void setValue(const MultiTypePrimitive& mtp); inline std::string getString() const { return this->string_; } inline const char* getConstChar() const { return this->string_.c_str(); } inline std::string& getString() { return this->string_; } inline const char* getConstChar() { return this->string_.c_str(); } using MultiTypePrimitive::getValue; inline void getValue(std::string* variable) const { (*variable) = this->string_; } inline void getValue(const char** variable) const { (*variable) = this->string_.c_str(); } virtual std::string getTypename() const; virtual std::string toString() const; virtual bool fromString(const std::string value); virtual bool assimilate(const MultiTypeString& mts, const MultiTypeString& defvalue = MultiTypeString()); protected: std::string string_;};_UtilExport std::ostream& operator<<(std::ostream& out, MultiTypeString& mts);#if ORXONOX_COMPILER == ORXONOX_COMPILER_MSVC 45 46 class _UtilExport MultiTypeString : public MultiTypePrimitive 47 { 48 public: 49 MultiTypeString(MultiType type = MT_null); 50 inline MultiTypeString(void* value) : MultiTypePrimitive(value) {} 51 inline MultiTypeString(int value) : MultiTypePrimitive(value) {} 52 inline MultiTypeString(unsigned int value) : MultiTypePrimitive(value) {} 53 inline MultiTypeString(char value) : MultiTypePrimitive(value) {} 54 inline MultiTypeString(unsigned char value) : MultiTypePrimitive(value) {} 55 inline MultiTypeString(short value) : MultiTypePrimitive(value) {} 56 inline MultiTypeString(unsigned short value) : MultiTypePrimitive(value) {} 57 inline MultiTypeString(long value) : MultiTypePrimitive(value) {} 58 inline MultiTypeString(unsigned long value) : MultiTypePrimitive(value) {} 59 inline MultiTypeString(float value) : MultiTypePrimitive(value) {} 60 inline MultiTypeString(double value) : MultiTypePrimitive(value) {} 61 inline MultiTypeString(long double value) : MultiTypePrimitive(value) {} 62 inline MultiTypeString(bool value) : MultiTypePrimitive(value) {} 63 inline MultiTypeString(const char* value) { this->setValue(value); } 64 inline MultiTypeString(const std::string& value) { this->setValue(value); } 65 inline MultiTypeString(const MultiTypeString& mts) { this->setValue(mts); } 66 inline MultiTypeString(const MultiTypePrimitive& mtp) { this->setValue(mtp); } 67 virtual inline ~MultiTypeString() {} 68 69 using MultiTypePrimitive::operator=; 70 inline MultiTypeString& operator=(const char* value) { this->setValue(value); return *this; } 71 inline MultiTypeString& operator=(const std::string& value) { this->setValue(value); return *this; } 72 inline MultiTypeString& operator=(const MultiTypeString& mts) { this->setValue(mts); return *this; } 73 inline MultiTypeString& operator=(const MultiTypePrimitive& mtp) { this->setValue(mtp); return *this; } 74 75 using MultiTypePrimitive::operator==; 76 inline bool operator==(const char* value) const { return (this->string_ == std::string(value)); } 77 inline bool operator==(const std::string& value) const { return (this->string_ == value); } 78 bool operator==(const MultiTypeString& mts) const; 79 bool operator==(const MultiTypePrimitive& mtp) const; 80 81 using MultiTypePrimitive::operator!=; 82 inline bool operator!=(const char* value) const { return (this->string_ != std::string(value)); } 83 inline bool operator!=(const std::string& value) const { return (this->string_ != value); } 84 bool operator!=(const MultiTypeString& mts) const; 85 bool operator!=(const MultiTypePrimitive& mtp) const; 86 87 virtual operator void*() const; 88 virtual operator int() const; 89 virtual operator unsigned int() const; 90 virtual operator char() const; 91 virtual operator unsigned char() const; 92 virtual operator short() const; 93 virtual operator unsigned short() const; 94 virtual operator long() const; 95 virtual operator unsigned long() const; 96 virtual operator float () const; 97 virtual operator double () const; 98 virtual operator long double() const; 99 virtual operator bool() const; 100 virtual operator std::string() const; 101 virtual operator const char*() const; 102 103 using MultiTypePrimitive::setValue; 104 inline void setValue(const char* value) { this->type_ = MT_string; this->string_ = std::string(value); } 105 inline void setValue(const std::string& value) { this->type_ = MT_string; this->string_ = value; } 106 void setValue(const MultiTypeString& mts); 107 void setValue(const MultiTypePrimitive& mtp); 108 109 inline std::string getString() const { return this->string_; } 110 inline const char* getConstChar() const { return this->string_.c_str(); } 111 112 inline std::string& getString() { return this->string_; } 113 inline const char* getConstChar() { return this->string_.c_str(); } 114 115 using MultiTypePrimitive::getValue; 116 inline void getValue(std::string* variable) const { (*variable) = this->string_; } 117 inline void getValue(const char** variable) const { (*variable) = this->string_.c_str(); } 118 119 virtual std::string getTypename() const; 120 121 virtual std::string toString() const; 122 virtual bool fromString(const std::string value); 123 124 virtual bool assimilate(const MultiTypeString& mts, const MultiTypeString& defvalue = MultiTypeString()); 125 126 protected: 127 std::string string_; 128 }; 129 130 _UtilExport std::ostream& operator<<(std::ostream& out, MultiTypeString& mts); 131 132 #if ORXONOX_COMPILER == ORXONOX_COMPILER_MSVC 7 133 #pragma warning(pop) 8 #endif#endif /* _MultiTypeString_H__ */ 134 #endif 135 136 #endif /* _MultiTypeString_H__ */ -
code/branches/network/src/util/OrxonoxPlatform.h
r1494 r1495 1 1 /* 2 2 * ORXONOX - the hottest 3D action shooter ever to exist 3 * > www.orxonox.net < * 3 * > www.orxonox.net < 4 * 4 5 * 5 6 * License notice: … … 25 26 * 26 27 */ 28 27 29 /** 28 30 @file … … 30 32 copy of the file found in the Ogre source code (OgrePlatform.h). 31 33 */ 32 #ifndef _OrxonoxPlatform_H__#define _OrxonoxPlatform_H__/* Initial platform/compiler-related stuff to set.*/#define ORXONOX_PLATFORM_WIN32 1#define ORXONOX_PLATFORM_LINUX 2#define ORXONOX_PLATFORM_APPLE 3#define ORXONOX_COMPILER_MSVC 1#define ORXONOX_COMPILER_GNUC 2#define ORXONOX_COMPILER_BORL 3#define ORXONOX_ENDIAN_LITTLE 1#define ORXONOX_ENDIAN_BIG 2#define ORXONOX_ARCHITECTURE_32 1#define ORXONOX_ARCHITECTURE_64 2/* Finds the compiler type and version.*/#if defined( _MSC_VER )# define ORXONOX_COMPILER ORXONOX_COMPILER_MSVC# define ORXONOX_COMP_VER _MSC_VER#elif defined( __GNUC__ )# define ORXONOX_COMPILER ORXONOX_COMPILER_GNUC# define ORXONOX_COMP_VER (((__GNUC__)*100) + \ (__GNUC_MINOR__*10) + \ __GNUC_PATCHLEVEL__)#elif defined( __BORLANDC__ )# define ORXONOX_COMPILER ORXONOX_COMPILER_BORL# define ORXONOX_COMP_VER __BCPLUSPLUS__#else# pragma error "No known compiler. Abort! Abort!"#endif/* See if we can use __forceinline or if we need to use __inline instead */#if ORXONOX_COMPILER == ORXONOX_COMPILER_MSVC# if ORXONOX_COMP_VER >= 1200# define FORCEINLINE __forceinline# endif#elif defined(__MINGW32__)# if !defined(FORCEINLINE)# define FORCEINLINE __inline# endif#else# define FORCEINLINE __inline#endif/* Finds the current platform */#if defined( __WIN32__ ) || defined( _WIN32 )# define ORXONOX_PLATFORM ORXONOX_PLATFORM_WIN32#elif defined( __APPLE_CC__)# define ORXONOX_PLATFORM ORXONOX_PLATFORM_APPLE#else# define ORXONOX_PLATFORM ORXONOX_PLATFORM_LINUX#endif /* Find the arch type */#if defined(__x86_64__) || defined(_M_X64) || defined(__powerpc64__) || defined(__alpha__) || defined(__ia64__) || defined(__s390__) || defined(__s390x__)# define ORXONOX_ARCH_TYPE ORXONOX_ARCHITECTURE_64#else# define ORXONOX_ARCH_TYPE ORXONOX_ARCHITECTURE_32#endif// For generating compiler warnings - should work on any compiler// As a side note, if you start your message with 'Warning: ', the MSVC// IDE actually does catch a warning :)// FIXME: Try this on linux box. Doesn't work with msvc//#define ORXONOX_QUOTE_INPLACE(x) # x//#define ORXONOX_QUOTE(x) ORXONOX_QUOTE_INPLACE(x)//#define ORXONOX_WARN( x ) message( __FILE__ "(" QUOTE( __LINE__ ) ") : " x "\n" )//----------------------------------------------------------------------------// Windows Settings#if ORXONOX_PLATFORM == ORXONOX_PLATFORM_WIN32// Win32 compilers use _DEBUG for specifying debug builds.# ifdef _DEBUG# define ORXONOX_DEBUG_MODE 1# else# define ORXONOX_DEBUG_MODE 0# endif// Disable unicode support on MingW at the moment, poorly supported in stdlibc++// STLPORT fixes this though so allow if found// MinGW C++ Toolkit supports unicode and sets the define __MINGW32_TOOLKIT_UNICODE__ in _mingw.h# if defined( __MINGW32__ ) && !defined(_STLPORT_VERSION)# include<_mingw.h># if defined(__MINGW32_TOOLBOX_UNICODE__)# define ORXONOX_UNICODE_SUPPORT 1# else# define ORXONOX_UNICODE_SUPPORT 0# endif# else# define ORXONOX_UNICODE_SUPPORT 1# endif#endif /* Platform Win32 *///----------------------------------------------------------------------------//----------------------------------------------------------------------------// Linux/Apple Settings#if ORXONOX_PLATFORM == ORXONOX_PLATFORM_LINUX || ORXONOX_PLATFORM == ORXONOX_PLATFORM_APPLE// A quick define to overcome different names for the same function# define stricmp strcasecmp// Unlike the Win32 compilers, Linux compilers seem to use DEBUG for when// specifying a debug build.// (??? this is wrong, on Linux debug builds aren't marked in any way unless// you mark it yourself any way you like it -- zap ???)# ifdef DEBUG# define ORXONOX_DEBUG_MODE 1# else# define ORXONOX_DEBUG_MODE 0# endif/* FIXME: Check what this actually is and whether we need it or not# if ORXONOX_PLATFORM == ORXONOX_PLATFORM_APPLE# define ORXONOX_PLATFORM_LIB "OrxonoxPlatform.bundle"# else// ORXONOX_PLATFORM_LINUX# define ORXONOX_PLATFORM_LIB "libOrxonoxPlatform.so"# endif*/// Always enable unicode support for the moment// Perhaps disable in old versions of gcc if necessary# define ORXONOX_UNICODE_SUPPORT 1#endif /* Patform Linux/Apple *///For apple, we always have a custom config.h file#if ORXONOX_PLATFORM == ORXONOX_PLATFORM_APPLE# include "config.h"#endif//----------------------------------------------------------------------------//----------------------------------------------------------------------------// Endian Settings// check for BIG_ENDIAN config flag, set ORXONOX_ENDIAN correctly#ifdef ORXONOX_CONFIG_BIG_ENDIAN# define ORXONOX_ENDIAN ORXONOX_ENDIAN_BIG#else# define ORXONOX_ENDIAN ORXONOX_ENDIAN_LITTLE#endif//----------------------------------------------------------------------- 34 35 #ifndef _OrxonoxPlatform_H__ 36 #define _OrxonoxPlatform_H__ 37 38 /* Initial platform/compiler-related stuff to set. 39 */ 40 #define ORXONOX_PLATFORM_WIN32 1 41 #define ORXONOX_PLATFORM_LINUX 2 42 #define ORXONOX_PLATFORM_APPLE 3 43 44 #define ORXONOX_COMPILER_MSVC 1 45 #define ORXONOX_COMPILER_GNUC 2 46 #define ORXONOX_COMPILER_BORL 3 47 48 #define ORXONOX_ENDIAN_LITTLE 1 49 #define ORXONOX_ENDIAN_BIG 2 50 51 #define ORXONOX_ARCHITECTURE_32 1 52 #define ORXONOX_ARCHITECTURE_64 2 53 54 /* Finds the compiler type and version. 55 */ 56 #if defined( _MSC_VER ) 57 # define ORXONOX_COMPILER ORXONOX_COMPILER_MSVC 58 # define ORXONOX_COMP_VER _MSC_VER 59 60 #elif defined( __GNUC__ ) 61 # define ORXONOX_COMPILER ORXONOX_COMPILER_GNUC 62 # define ORXONOX_COMP_VER (((__GNUC__)*100) + \ 63 (__GNUC_MINOR__*10) + \ 64 __GNUC_PATCHLEVEL__) 65 66 #elif defined( __BORLANDC__ ) 67 # define ORXONOX_COMPILER ORXONOX_COMPILER_BORL 68 # define ORXONOX_COMP_VER __BCPLUSPLUS__ 69 70 #else 71 # pragma error "No known compiler. Abort! Abort!" 72 73 #endif 74 75 /* See if we can use __forceinline or if we need to use __inline instead */ 76 #if ORXONOX_COMPILER == ORXONOX_COMPILER_MSVC 77 # if ORXONOX_COMP_VER >= 1200 78 # define FORCEINLINE __forceinline 79 # endif 80 #elif defined(__MINGW32__) 81 # if !defined(FORCEINLINE) 82 # define FORCEINLINE __inline 83 # endif 84 #else 85 # define FORCEINLINE __inline 86 #endif 87 88 /* Finds the current platform */ 89 90 #if defined( __WIN32__ ) || defined( _WIN32 ) 91 # define ORXONOX_PLATFORM ORXONOX_PLATFORM_WIN32 92 93 #elif defined( __APPLE_CC__) 94 # define ORXONOX_PLATFORM ORXONOX_PLATFORM_APPLE 95 96 #else 97 # define ORXONOX_PLATFORM ORXONOX_PLATFORM_LINUX 98 #endif 99 100 /* Find the arch type */ 101 #if defined(__x86_64__) || defined(_M_X64) || defined(__powerpc64__) || defined(__alpha__) || defined(__ia64__) || defined(__s390__) || defined(__s390x__) 102 # define ORXONOX_ARCH_TYPE ORXONOX_ARCHITECTURE_64 103 #else 104 # define ORXONOX_ARCH_TYPE ORXONOX_ARCHITECTURE_32 105 #endif 106 107 // For generating compiler warnings - should work on any compiler 108 // As a side note, if you start your message with 'Warning: ', the MSVC 109 // IDE actually does catch a warning :) 110 // FIXME: Try this on linux box. Doesn't work with msvc 111 //#define ORXONOX_QUOTE_INPLACE(x) # x 112 //#define ORXONOX_QUOTE(x) ORXONOX_QUOTE_INPLACE(x) 113 //#define ORXONOX_WARN( x ) message( __FILE__ "(" QUOTE( __LINE__ ) ") : " x "\n" ) 114 115 //---------------------------------------------------------------------------- 116 // Windows Settings 117 #if ORXONOX_PLATFORM == ORXONOX_PLATFORM_WIN32 118 119 // Win32 compilers use _DEBUG for specifying debug builds. 120 # ifdef _DEBUG 121 # define ORXONOX_DEBUG_MODE 1 122 # else 123 # define ORXONOX_DEBUG_MODE 0 124 # endif 125 126 // Disable unicode support on MingW at the moment, poorly supported in stdlibc++ 127 // STLPORT fixes this though so allow if found 128 // MinGW C++ Toolkit supports unicode and sets the define __MINGW32_TOOLKIT_UNICODE__ in _mingw.h 129 # if defined( __MINGW32__ ) && !defined(_STLPORT_VERSION) 130 # include<_mingw.h> 131 # if defined(__MINGW32_TOOLBOX_UNICODE__) 132 # define ORXONOX_UNICODE_SUPPORT 1 133 # else 134 # define ORXONOX_UNICODE_SUPPORT 0 135 # endif 136 # else 137 # define ORXONOX_UNICODE_SUPPORT 1 138 # endif 139 140 #endif /* Platform Win32 */ 141 //---------------------------------------------------------------------------- 142 143 //---------------------------------------------------------------------------- 144 // Linux/Apple Settings 145 #if ORXONOX_PLATFORM == ORXONOX_PLATFORM_LINUX || ORXONOX_PLATFORM == ORXONOX_PLATFORM_APPLE 146 147 148 // A quick define to overcome different names for the same function 149 # define stricmp strcasecmp 150 151 // Unlike the Win32 compilers, Linux compilers seem to use DEBUG for when 152 // specifying a debug build. 153 // (??? this is wrong, on Linux debug builds aren't marked in any way unless 154 // you mark it yourself any way you like it -- zap ???) 155 # ifdef DEBUG 156 # define ORXONOX_DEBUG_MODE 1 157 # else 158 # define ORXONOX_DEBUG_MODE 0 159 # endif 160 161 /* FIXME: Check what this actually is and whether we need it or not 162 # if ORXONOX_PLATFORM == ORXONOX_PLATFORM_APPLE 163 # define ORXONOX_PLATFORM_LIB "OrxonoxPlatform.bundle" 164 # else 165 // ORXONOX_PLATFORM_LINUX 166 # define ORXONOX_PLATFORM_LIB "libOrxonoxPlatform.so" 167 # endif 168 */ 169 170 // Always enable unicode support for the moment 171 // Perhaps disable in old versions of gcc if necessary 172 # define ORXONOX_UNICODE_SUPPORT 1 173 174 #endif /* Patform Linux/Apple */ 175 176 //For apple, we always have a custom config.h file 177 #if ORXONOX_PLATFORM == ORXONOX_PLATFORM_APPLE 178 # include "config.h" 179 #endif 180 181 //---------------------------------------------------------------------------- 182 183 //---------------------------------------------------------------------------- 184 // Endian Settings 185 // check for BIG_ENDIAN config flag, set ORXONOX_ENDIAN correctly 186 #ifdef ORXONOX_CONFIG_BIG_ENDIAN 187 # define ORXONOX_ENDIAN ORXONOX_ENDIAN_BIG 188 #else 189 # define ORXONOX_ENDIAN ORXONOX_ENDIAN_LITTLE 190 #endif 191 192 //----------------------------------------------------------------------- 33 193 // fixed width integers 34 194 //----------------------------------------------------------------------- 35 #if ORXONOX_COMPILER == ORXONOX_COMPILER_MSVCtypedef __int8 int8_t; 195 #if ORXONOX_COMPILER == ORXONOX_COMPILER_MSVC 196 typedef __int8 int8_t; 36 197 typedef __int16 int16_t; 37 198 typedef __int32 int32_t; … … 41 202 typedef unsigned __int32 uint32_t; 42 203 typedef unsigned __int64 uint64_t; 43 #else# include "inttypes.h"#endifnamespace orxonox {#ifdef ORXONOX_DOUBLE_PRECISIONtypedef double Real;#elsetypedef float Real;#endif}#if ORXONOX_COMPILER == ORXONOX_COMPILER_MSVC// Turn off warnings generated by long std templates// This warns about truncation to 255 characters in debug/browse info//# pragma warning (disable : 4786)// Turn off warnings generated by long std templates// This warns about truncation to 255 characters in debug/browse info//# pragma warning (disable : 4503)// disable: conversion from 'double' to 'float', possible loss of data// disable: conversion from 'ogg_int64_t' to 'long', possible loss of data// This has been dealt with in base_properties of the solution since the// warning primarily occurs in library header files (which are mostly// included before OrxonoxPlatform.h is)//# pragma warning (disable : 4244)// disable: "conversion from 'size_t' to 'unsigned int', possible loss of data//# pragma warning (disable : 4267)// disable: "truncation from 'double' to 'float'//# pragma warning (disable : 4305)// set to level 4: "<type> needs to have dll-interface to be used by clients'// Happens on STL member variables which are not public therefore is ok# pragma warning (disable : 4251)// disable: 'MultiTypeString' : multiple assignment operators specified// Used in MultiType and works fine so far//# pragma warning (disable : 4522)// disable: "non dll-interface class used as base for dll-interface class"// Happens when deriving from Singleton because bug in compiler ignores// template export//# pragma warning (disable : 4275)// disable: "C++ Exception Specification ignored"// This is because MSVC 6 did not implement all the C++ exception// specifications in the ANSI C++ draft.//# pragma warning( disable : 4290 )// disable: "no suitable definition provided for explicit template// instantiation request" Occurs in VC7 for no justifiable reason on all// #includes of Singleton//# pragma warning( disable: 4661)// disable: deprecation warnings when using CRT calls in VC8// These show up on all C runtime lib code in VC8, disable since they clutter// the warnings with things we may not be able to do anything about (e.g.// generated code from nvparse etc). I doubt very much that these calls// will ever be actually removed from VC anyway, it would break too much code.//# pragma warning( disable: 4996)// disable: "conditional expression constant", always occurs on// ORXONOX_MUTEX_CONDITIONAL when no threading enabled//# pragma warning (disable : 201)// Define the english written operators like and, or, xor#include <iso646.h>#endif /* ORXONOX_COMPILER == ORXONOX_COMPILER_MSVC */// include visual leak detector to search for memory leaks//#include <vld.h>#endif /* _OrxonoxPlatform_H__ */ 204 #else 205 # include "inttypes.h" 206 #endif 207 208 namespace orxonox { 209 #ifdef ORXONOX_DOUBLE_PRECISION 210 typedef double Real; 211 #else 212 typedef float Real; 213 #endif 214 } 215 216 217 #if ORXONOX_COMPILER == ORXONOX_COMPILER_MSVC 218 // Turn off warnings generated by long std templates 219 // This warns about truncation to 255 characters in debug/browse info 220 //# pragma warning (disable : 4786) 221 222 // Turn off warnings generated by long std templates 223 // This warns about truncation to 255 characters in debug/browse info 224 //# pragma warning (disable : 4503) 225 226 // disable: conversion from 'double' to 'float', possible loss of data 227 // disable: conversion from 'ogg_int64_t' to 'long', possible loss of data 228 // This has been dealt with in base_properties of the solution since the 229 // warning primarily occurs in library header files (which are mostly 230 // included before OrxonoxPlatform.h is) 231 //# pragma warning (disable : 4244) 232 233 // disable: "conversion from 'size_t' to 'unsigned int', possible loss of data 234 //# pragma warning (disable : 4267) 235 236 // disable: "truncation from 'double' to 'float' 237 //# pragma warning (disable : 4305) 238 239 // set to level 4: "<type> needs to have dll-interface to be used by clients' 240 // Happens on STL member variables which are not public therefore is ok 241 # pragma warning (disable : 4251) 242 243 // disable: 'MultiTypeString' : multiple assignment operators specified 244 // Used in MultiType and works fine so far 245 //# pragma warning (disable : 4522) 246 247 // disable: "non dll-interface class used as base for dll-interface class" 248 // Happens when deriving from Singleton because bug in compiler ignores 249 // template export 250 //# pragma warning (disable : 4275) 251 252 // disable: "C++ Exception Specification ignored" 253 // This is because MSVC 6 did not implement all the C++ exception 254 // specifications in the ANSI C++ draft. 255 //# pragma warning( disable : 4290 ) 256 257 // disable: "no suitable definition provided for explicit template 258 // instantiation request" Occurs in VC7 for no justifiable reason on all 259 // #includes of Singleton 260 //# pragma warning( disable: 4661) 261 262 // disable: deprecation warnings when using CRT calls in VC8 263 // These show up on all C runtime lib code in VC8, disable since they clutter 264 // the warnings with things we may not be able to do anything about (e.g. 265 // generated code from nvparse etc). I doubt very much that these calls 266 // will ever be actually removed from VC anyway, it would break too much code. 267 //# pragma warning( disable: 4996) 268 269 // disable: "conditional expression constant", always occurs on 270 // ORXONOX_MUTEX_CONDITIONAL when no threading enabled 271 //# pragma warning (disable : 201) 272 273 274 // Define the english written operators like and, or, xor 275 #include <iso646.h> 276 277 #endif /* ORXONOX_COMPILER == ORXONOX_COMPILER_MSVC */ 278 279 // include visual leak detector to search for memory leaks 280 //#include <vld.h> 281 282 #endif /* _OrxonoxPlatform_H__ */ -
code/branches/network/src/util/Sleep.h
r1494 r1495 1 1 /* 2 2 * ORXONOX - the hottest 3D action shooter ever to exist 3 * > www.orxonox.net < * 3 * > www.orxonox.net < 4 * 4 5 * 5 6 * License notice: … … 25 26 * 26 27 */ 28 27 29 /** 28 30 @file Sleep.h … … 32 34 #include "UtilPrereqs.h" 33 35 34 #if ORXONOX_PLATFORM == ORXONOX_PLATFORM_WIN32# ifndef WIN32_LEAN_AND_MEAN# define WIN32_LEAN_AND_MEAN# endif# include <windows.h> 36 #if ORXONOX_PLATFORM == ORXONOX_PLATFORM_WIN32 37 # ifndef WIN32_LEAN_AND_MEAN 38 # define WIN32_LEAN_AND_MEAN 39 # endif 40 # include <windows.h> 35 41 inline void usleep(DWORD dwMicroseconds) 36 42 { -
code/branches/network/src/util/SubString.cc
r1494 r1495 1 /* * ORXONOX - the hottest 3D action shooter ever to exist * > www.orxonox.net < * * * License notice: * * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * * Author: * Christian Meyer * Co-authors: * Benjamin Grauer *//// splitLine// STL string tokenizer//// Created by Clemens Wacha.// Version 1.0// Copyright (c) 2005 Clemens Wacha. All rights reserved.// */ 1 /* 2 * ORXONOX - the hottest 3D action shooter ever to exist 3 * > www.orxonox.net < 4 * 5 * 6 * License notice: 7 * 8 * This program is free software; you can redistribute it and/or 9 * modify it under the terms of the GNU General Public License 10 * as published by the Free Software Foundation; either version 2 11 * of the License, or (at your option) any later version. 12 * 13 * This program is distributed in the hope that it will be useful, 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 * GNU General Public License for more details. 17 * 18 * You should have received a copy of the GNU General Public License 19 * along with this program; if not, write to the Free Software 20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 21 * 22 * Author: 23 * Christian Meyer 24 * Co-authors: 25 * Benjamin Grauer 26 * 27 // 28 // splitLine 29 // STL string tokenizer 30 // 31 // Created by Clemens Wacha. 32 // Version 1.0 33 // Copyright (c) 2005 Clemens Wacha. All rights reserved. 34 // 35 */ 36 2 37 #include "SubString.h" 3 38 … … 32 67 SubString::SubString(const std::string& string, 33 68 const std::string& delimiters, const std::string& delimiterNeighbours, bool emptyEntries, 34 char escapeChar, bool removeEscapeChar, char safemode_char, bool removeSafemodeChar, char openparenthesis_char, char closeparenthesis_char, bool removeParenthesisChars, char comment_char) 69 char escapeChar, bool removeEscapeChar, char safemode_char, bool removeSafemodeChar, 70 char openparenthesis_char, char closeparenthesis_char, bool removeParenthesisChars, char comment_char) 35 71 { 36 72 SubString::splitLine(this->strings, this->bInSafemode, string, delimiters, delimiterNeighbours, emptyEntries, escapeChar, removeEscapeChar, safemode_char, removeSafemodeChar, openparenthesis_char, closeparenthesis_char, removeParenthesisChars, comment_char); … … 44 80 SubString::SubString(const SubString& subString, unsigned int subSetBegin) 45 81 { 46 for (unsigned int i = subSetBegin; i < subString.size(); i++) { 47 this->strings.push_back(subString[i]); this->bInSafemode.push_back(subString.isInSafemode(i)); } 82 for (unsigned int i = subSetBegin; i < subString.size(); i++) 83 { 84 this->strings.push_back(subString[i]); 85 this->bInSafemode.push_back(subString.isInSafemode(i)); 86 } 48 87 } 49 88 … … 57 96 SubString::SubString(const SubString& subString, unsigned int subSetBegin, unsigned int subSetEnd) 58 97 { 59 for (unsigned int i = subSetBegin; i < subString.size() && i < subSetEnd; i++) { 60 this->strings.push_back(subString[i]); this->bInSafemode.push_back(subString.isInSafemode(i)); } 98 for (unsigned int i = subSetBegin; i < subString.size() && i < subSetEnd; i++) 99 { 100 this->strings.push_back(subString[i]); 101 this->bInSafemode.push_back(subString.isInSafemode(i)); 102 } 61 103 } 62 104 … … 68 110 SubString::SubString(unsigned int argc, const char** argv) 69 111 { 70 for(unsigned int i = 0; i < argc; ++i) { 71 this->strings.push_back(std::string(argv[i])); this->bInSafemode.push_back(false); } 112 for(unsigned int i = 0; i < argc; ++i) 113 { 114 this->strings.push_back(std::string(argv[i])); 115 this->bInSafemode.push_back(false); 116 } 72 117 } 73 118 … … 94 139 SubString& SubString::operator=(const SubString& subString) 95 140 { 96 this->strings = subString.strings; this->bInSafemode = subString.bInSafemode; 141 this->strings = subString.strings; 142 this->bInSafemode = subString.bInSafemode; 97 143 return *this; 98 144 } … … 155 201 SubString& SubString::operator+=(const SubString& subString) 156 202 { 157 for (unsigned int i = 0; i < subString.size(); i++) { 158 this->strings.push_back(subString[i]); this->bInSafemode.push_back(subString.isInSafemode(i)); } 203 for (unsigned int i = 0; i < subString.size(); i++) 204 { 205 this->strings.push_back(subString[i]); 206 this->bInSafemode.push_back(subString.isInSafemode(i)); 207 } 159 208 return *this; 160 209 } … … 168 217 unsigned int SubString::split(const std::string& string, char splitter) 169 218 { 170 this->strings.clear(); this->bInSafemode.clear(); 219 this->strings.clear(); 220 this->bInSafemode.clear(); 171 221 char split[2]; 172 222 split[0] = splitter; … … 189 239 unsigned int SubString::split(const std::string& string, 190 240 const std::string& delimiters, const std::string& delimiterNeighbours, bool emptyEntries, 191 char escapeChar, bool removeExcapeChar, char safemode_char, bool removeSafemodeChar, char openparenthesis_char, char closeparenthesis_char, bool removeParenthesisChars, char comment_char) 192 { 193 this->strings.clear(); this->bInSafemode.clear(); 241 char escapeChar, bool removeExcapeChar, char safemode_char, bool removeSafemodeChar, 242 char openparenthesis_char, char closeparenthesis_char, bool removeParenthesisChars, char comment_char) 243 { 244 this->strings.clear(); 245 this->bInSafemode.clear(); 194 246 SubString::splitLine(this->strings, this->bInSafemode, string, delimiters, delimiterNeighbours, emptyEntries, escapeChar, removeExcapeChar, safemode_char, removeSafemodeChar, openparenthesis_char, closeparenthesis_char, removeParenthesisChars, comment_char); 195 247 return this->strings.size(); … … 257 309 * @param emptyEntries: if empty Strings are added to the List of Strings. 258 310 * @param escape_char: Escape carater (escapes splitters) 259 * @param safemode_char: the beginning of the safemode is marked with this * @param removeSafemodeChar removes the safemode_char from the beginning and the ending of a token * @param openparenthesis_char the beginning of a safemode is marked with this * @param closeparenthesis_char the ending of a safemode is marked with this * @param removeParenthesisChars removes the parenthesis from the beginning and the ending of a token 311 * @param safemode_char: the beginning of the safemode is marked with this 312 * @param removeSafemodeChar removes the safemode_char from the beginning and the ending of a token 313 * @param openparenthesis_char the beginning of a safemode is marked with this 314 * @param closeparenthesis_char the ending of a safemode is marked with this 315 * @param removeParenthesisChars removes the parenthesis from the beginning and the ending of a token 260 316 * @param comment_char: the beginning of a comment is marked with this: (until the end of a Line) 261 317 * @param start_state: the Initial state on how to parse the String. … … 267 323 */ 268 324 SubString::SPLIT_LINE_STATE 269 SubString::splitLine(std::vector<std::string>& ret, std::vector<bool>& bInSafemode, 325 SubString::splitLine(std::vector<std::string>& ret, 326 std::vector<bool>& bInSafemode, 270 327 const std::string& line, 271 328 const std::string& delimiters, 272 329 const std::string& delimiterNeighbours, 273 330 bool emptyEntries, 274 char escape_char, bool removeExcapeChar, 275 char safemode_char, bool removeSafemodeChar, char openparenthesis_char, char closeparenthesis_char, bool removeParenthesisChars, 331 char escape_char, 332 bool removeExcapeChar, 333 char safemode_char, 334 bool removeSafemodeChar, 335 char openparenthesis_char, 336 char closeparenthesis_char, 337 bool removeParenthesisChars, 276 338 char comment_char, 277 339 SPLIT_LINE_STATE start_state) … … 281 343 unsigned int fallBackNeighbours = 0; 282 344 283 std::string token; bool inSafemode = false; 284 285 if(start_state != SL_NORMAL && ret.size() > 0) { token = ret[ret.size()-1]; 286 ret.pop_back(); } if(start_state != SL_NORMAL && bInSafemode.size() > 0) { inSafemode = bInSafemode[bInSafemode.size()-1]; bInSafemode.pop_back(); } 345 std::string token; 346 bool inSafemode = false; 347 348 if(start_state != SL_NORMAL && ret.size() > 0) 349 { 350 token = ret[ret.size()-1]; 351 ret.pop_back(); 352 } 353 if(start_state != SL_NORMAL && bInSafemode.size() > 0) 354 { 355 inSafemode = bInSafemode[bInSafemode.size()-1]; 356 bInSafemode.pop_back(); 357 } 358 287 359 while(i < line.size()) 288 360 { … … 292 364 if(line[i] == escape_char) 293 365 { 294 state = SL_ESCAPE; if (!removeExcapeChar) token += line[i]; 366 state = SL_ESCAPE; 367 if (!removeExcapeChar) 368 token += line[i]; 295 369 } 296 370 else if(line[i] == safemode_char) 297 371 { 298 state = SL_SAFEMODE; inSafemode = true; if (!removeSafemodeChar) token += line[i]; 299 } else if(line[i] == openparenthesis_char) { state = SL_PARENTHESES; inSafemode = true; if (!removeParenthesisChars) token += line[i]; } 372 state = SL_SAFEMODE; 373 inSafemode = true; 374 if (!removeSafemodeChar) 375 token += line[i]; 376 } 377 else if(line[i] == openparenthesis_char) 378 { 379 state = SL_PARENTHESES; 380 inSafemode = true; 381 if (!removeParenthesisChars) 382 token += line[i]; 383 } 300 384 else if(line[i] == comment_char) 301 385 { … … 305 389 if(emptyEntries || token.size() > 0) 306 390 { 307 ret.push_back(token); token.clear(); bInSafemode.push_back(inSafemode); inSafemode = false; } 391 ret.push_back(token); 392 token.clear(); 393 bInSafemode.push_back(inSafemode); 394 inSafemode = false; 395 } 308 396 token += line[i]; // EAT 309 397 state = SL_COMMENT; … … 319 407 ret.push_back(token); 320 408 token.clear(); 321 bInSafemode.push_back(inSafemode); inSafemode = false; } 409 bInSafemode.push_back(inSafemode); 410 inSafemode = false; 411 } 322 412 state = SL_NORMAL; 323 413 } … … 339 429 } 340 430 break; 341 case SL_ESCAPE: if (!removeSafemodeChar) token += line[i]; else { 431 case SL_ESCAPE: 432 if (!removeSafemodeChar) 433 token += line[i]; 434 else 435 { 342 436 if(line[i] == 'n') token += '\n'; 343 437 else if(line[i] == 't') token += '\t'; … … 348 442 else if(line[i] == 'a') token += '\a'; 349 443 else if(line[i] == '?') token += '\?'; 350 else token += line[i]; // EAT } 444 else token += line[i]; // EAT 445 } 351 446 state = SL_NORMAL; 352 447 break; … … 355 450 { 356 451 state = SL_NORMAL; 357 if (!removeSafemodeChar) token += line[i]; } 452 if (!removeSafemodeChar) 453 token += line[i]; 454 } 358 455 else if(line[i] == escape_char) 359 456 { … … 364 461 token += line[i]; // EAT 365 462 } 366 break; case SL_SAFEESCAPE: 463 break; 464 465 case SL_SAFEESCAPE: 367 466 if(line[i] == 'n') token += '\n'; 368 467 else if(line[i] == 't') token += '\t'; … … 376 475 state = SL_SAFEMODE; 377 476 break; 378 case SL_PARENTHESES: if(line[i] == closeparenthesis_char) { state = SL_NORMAL; if (!removeParenthesisChars) token += line[i]; } else if(line[i] == escape_char) { state = SL_PARENTHESESESCAPE; } else { token += line[i]; // EAT } break; case SL_PARENTHESESESCAPE: if(line[i] == 'n') token += '\n'; else if(line[i] == 't') token += '\t'; else if(line[i] == 'v') token += '\v'; else if(line[i] == 'b') token += '\b'; else if(line[i] == 'r') token += '\r'; else if(line[i] == 'f') token += '\f'; else if(line[i] == 'a') token += '\a'; else if(line[i] == '?') token += '\?'; else token += line[i]; // EAT state = SL_PARENTHESES; break; 477 478 case SL_PARENTHESES: 479 if(line[i] == closeparenthesis_char) 480 { 481 state = SL_NORMAL; 482 if (!removeParenthesisChars) 483 token += line[i]; 484 } 485 else if(line[i] == escape_char) 486 { 487 state = SL_PARENTHESESESCAPE; 488 } 489 else 490 { 491 token += line[i]; // EAT 492 } 493 break; 494 495 case SL_PARENTHESESESCAPE: 496 if(line[i] == 'n') token += '\n'; 497 else if(line[i] == 't') token += '\t'; 498 else if(line[i] == 'v') token += '\v'; 499 else if(line[i] == 'b') token += '\b'; 500 else if(line[i] == 'r') token += '\r'; 501 else if(line[i] == 'f') token += '\f'; 502 else if(line[i] == 'a') token += '\a'; 503 else if(line[i] == '?') token += '\?'; 504 else token += line[i]; // EAT 505 state = SL_PARENTHESES; 506 break; 507 379 508 case SL_COMMENT: 380 509 if(line[i] == '\n') … … 385 514 ret.push_back(token); 386 515 token.clear(); 387 bInSafemode.push_back(inSafemode); inSafemode = false; } 516 bInSafemode.push_back(inSafemode); 517 inSafemode = false; 518 } 388 519 state = SL_NORMAL; 389 520 } … … 408 539 ret.push_back(token); 409 540 token.clear(); 410 bInSafemode.push_back(inSafemode); inSafemode = false; } 541 bInSafemode.push_back(inSafemode); 542 inSafemode = false; 543 } 411 544 return(state); 412 545 } -
code/branches/network/src/util/SubString.h
r1494 r1495 1 /* * ORXONOX - the hottest 3D action shooter ever to exist * > www.orxonox.net < * * * License notice: * * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * * Author: * Christian Meyer * Co-authors: * Benjamin Grauer * Fabian 'x3n' Landau *// splitLine// STL string tokenizer//// Created by Clemens Wacha.// Version 1.0// Copyright (c) 2005 Clemens Wacha. All rights reserved. * Extended by Fabian 'x3n' Landau with the SL_PARENTHESES mode. */ /*! 1 /* 2 * ORXONOX - the hottest 3D action shooter ever to exist 3 * > www.orxonox.net < 4 * 5 * 6 * License notice: 7 * 8 * This program is free software; you can redistribute it and/or 9 * modify it under the terms of the GNU General Public License 10 * as published by the Free Software Foundation; either version 2 11 * of the License, or (at your option) any later version. 12 * 13 * This program is distributed in the hope that it will be useful, 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 * GNU General Public License for more details. 17 * 18 * You should have received a copy of the GNU General Public License 19 * along with this program; if not, write to the Free Software 20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 21 * 22 * Author: 23 * Christian Meyer 24 * Co-authors: 25 * Benjamin Grauer 26 * Fabian 'x3n' Landau 27 * 28 29 // splitLine 30 // STL string tokenizer 31 // 32 // Created by Clemens Wacha. 33 // Version 1.0 34 // Copyright (c) 2005 Clemens Wacha. All rights reserved. 35 36 * Extended by Fabian 'x3n' Landau with the SL_PARENTHESES mode. 37 */ 38 39 /*! 2 40 * @file substring.h 3 41 * @brief a small class to get the parts of a string separated by commas … … 22 60 23 61 #include "UtilPrereqs.h" 62 24 63 #include <vector> 25 64 #include <string> … … 39 78 SL_SAFEMODE, //!< In safe mode (between "" mostly). 40 79 SL_SAFEESCAPE, //!< In safe mode with the internal escape character, that escapes even the savemode character. 41 SL_COMMENT, //!< In Comment mode. SL_PARENTHESES, //!< Between parentheses (usually '(' and ')') SL_PARENTHESESESCAPE, //!< Between parentheses with the internal escape character, that escapes even the closing paranthesis character. 80 SL_COMMENT, //!< In Comment mode. 81 SL_PARENTHESES, //!< Between parentheses (usually '(' and ')') 82 SL_PARENTHESESESCAPE, //!< Between parentheses with the internal escape character, that escapes even the closing paranthesis character. 42 83 } SPLIT_LINE_STATE; 43 84 … … 48 89 SubString(const std::string& string, 49 90 const std::string& delimiters, const std::string& delimiterNeighbours = "", bool emptyEntries=false, 50 char escapeChar ='\\', bool removeEscapeChar = true, char safemode_char = '"', bool removeSafemodeChar = true, char openparenthesis_char = '(', char closeparenthesis_char = ')', bool removeParenthesisChars = true, char comment_char = '\0'); 91 char escapeChar ='\\', bool removeEscapeChar = true, char safemode_char = '"', bool removeSafemodeChar = true, 92 char openparenthesis_char = '(', char closeparenthesis_char = ')', bool removeParenthesisChars = true, char comment_char = '\0'); 51 93 SubString(unsigned int argc, const char** argv); 52 94 /** @brief create a Substring as a copy of another one. @param subString the SubString to copy. */ … … 71 113 unsigned int split(const std::string& string, 72 114 const std::string& delimiters, const std::string& delimiterNeighbours = "", bool emptyEntries = false, 73 char escapeChar ='\\', bool removeExcapeChar = true, char safemode_char = '"', bool removeSafemodeChar = true, char openparenthesis_char = '(', char closeparenthesis_char = ')', bool removeParenthesisChars = true, char comment_char = '\0'); 115 char escapeChar ='\\', bool removeExcapeChar = true, char safemode_char = '"', bool removeSafemodeChar = true, 116 char openparenthesis_char = '(', char closeparenthesis_char = ')', bool removeParenthesisChars = true, char comment_char = '\0'); 74 117 std::string join(const std::string& delimiter = " ") const; 75 118 //////////////////////////////////////// … … 87 130 inline const std::string& operator[](unsigned int i) const { return this->strings[i]; }; 88 131 /** @brief Returns the i'th string from the subset of Strings @param i the i'th String */ 89 inline const std::string& getString(unsigned int i) const { return (*this)[i]; }; /** @brief Returns true if the token is in safemode. @param i the i'th token */ inline bool isInSafemode(unsigned int i) const { return this->bInSafemode[i]; } 132 inline const std::string& getString(unsigned int i) const { return (*this)[i]; }; 133 /** @brief Returns true if the token is in safemode. @param i the i'th token */ 134 inline bool isInSafemode(unsigned int i) const { return this->bInSafemode[i]; } 90 135 /** @brief Returns the front of the StringList. */ 91 136 inline const std::string& front() const { return this->strings.front(); }; … … 96 141 97 142 // the almighty algorithm. 98 static SPLIT_LINE_STATE splitLine(std::vector<std::string>& ret, std::vector<bool>& bInSafemode, 143 static SPLIT_LINE_STATE splitLine(std::vector<std::string>& ret, 144 std::vector<bool>& bInSafemode, 99 145 const std::string& line, 100 146 const std::string& delimiters = SubString::WhiteSpaces, 101 147 const std::string& delimiterNeighbours = "", 102 148 bool emptyEntries = false, 103 char escape_char = '\\', bool removeExcapeChar = true, 149 char escape_char = '\\', 150 bool removeExcapeChar = true, 104 151 char safemode_char = '"', 105 bool removeSafemodeChar = true, char openparenthesis_char = '(', char closeparenthesis_char = ')', bool removeParenthesisChars = true, char comment_char = '\0', 152 bool removeSafemodeChar = true, 153 char openparenthesis_char = '(', 154 char closeparenthesis_char = ')', 155 bool removeParenthesisChars = true, 156 char comment_char = '\0', 106 157 SPLIT_LINE_STATE start_state = SL_NORMAL); 107 158 // debugging. … … 114 165 115 166 private: 116 std::vector<std::string> strings; //!< strings produced from a single string splitted in multiple strings std::vector<bool> bInSafemode; 167 std::vector<std::string> strings; //!< strings produced from a single string splitted in multiple strings 168 std::vector<bool> bInSafemode; 117 169 }; 118 170 -
code/branches/network/src/util/UtilPrereqs.h
r1494 r1495 1 1 /* 2 2 * ORXONOX - the hottest 3D action shooter ever to exist 3 * > www.orxonox.net < * 3 * > www.orxonox.net < 4 * 4 5 * 5 6 * License notice: … … 30 31 @brief Contains all the necessary forward declarations for all classes and structs. 31 32 */ 33 32 34 #ifndef _UtilPrereqs_H__ 33 35 #define _UtilPrereqs_H__ … … 58 60 // Forward declarations 59 61 //----------------------------------------------------------------------- 60 class ArgReader;class Convert;class MultiTypePrimitive;class MultiTypeString;class MultiTypeMath;template <class T>class String2Number;class SubString; 62 class ArgReader; 63 class Convert; 64 class MultiTypePrimitive; 65 class MultiTypeString; 66 class MultiTypeMath; 67 template <class T> 68 class String2Number; 69 class SubString; 61 70 62 71 #endif /* _UtilPrereqs_H__ */
Note: See TracChangeset
for help on using the changeset viewer.